using System;
using System.Threading;
using Convai.RestAPI;
using Convai.RestAPI.Internal;
using UnityEngine;
public class MemoryDiagnostics : MonoBehaviour
{
[SerializeField] private string _characterId;
private ConvaiRestClient _client;
private void Awake()
{
_client = new ConvaiRestClient(ConvaiSettings.Instance.ApiKey);
}
private void OnDestroy()
{
_client?.Dispose();
}
[ContextMenu("转储所有记忆")]
public async void DumpAllMemories()
{
string endUserId = new Convai.Runtime.Identity.DeviceEndUserIdProvider().GetEndUserId();
Debug.Log($"[LTM Diagnostics] end_user_id: {endUserId}");
try
{
int page = 1;
int total = 0;
do
{
MemoryListResponse response = await _client.Memory.ListAsync(
_characterId, endUserId, page, pageSize: 50);
foreach (MemoryRecord record in response.Memories)
{
Debug.Log($" [{record.Id[..8]}...] {record.Memory}");
total++;
}
if (!response.HasMore) break;
page++;
} while (true);
Debug.Log($"[LTM Diagnostics] Total memories: {total}");
}
catch (Exception e)
{
Debug.LogError($"[LTM Diagnostics] {e.Message}");
}
}
}