Merged via /review-pr -> /prepare-pr -> /merge-pr. Prepared head SHA: 2f02ec94030754a2e2dfeb7d5a80f14747373ab5 Co-authored-by: therk <901920+therk@users.noreply.github.com> Co-authored-by: gumadeiras <5599352+gumadeiras@users.noreply.github.com> Reviewed-by: @gumadeiras
63 lines
1.7 KiB
TypeScript
63 lines
1.7 KiB
TypeScript
import { resolveDefaultAgentId } from "../../agents/agent-scope.js";
|
|
import { loadConfig } from "../../config/config.js";
|
|
import { getMemorySearchManager } from "../../memory/index.js";
|
|
import { formatError } from "../server-utils.js";
|
|
import type { GatewayRequestHandlers } from "./types.js";
|
|
|
|
export type DoctorMemoryStatusPayload = {
|
|
agentId: string;
|
|
provider?: string;
|
|
embedding: {
|
|
ok: boolean;
|
|
error?: string;
|
|
};
|
|
};
|
|
|
|
export const doctorHandlers: GatewayRequestHandlers = {
|
|
"doctor.memory.status": async ({ respond }) => {
|
|
const cfg = loadConfig();
|
|
const agentId = resolveDefaultAgentId(cfg);
|
|
const { manager, error } = await getMemorySearchManager({
|
|
cfg,
|
|
agentId,
|
|
purpose: "status",
|
|
});
|
|
if (!manager) {
|
|
const payload: DoctorMemoryStatusPayload = {
|
|
agentId,
|
|
embedding: {
|
|
ok: false,
|
|
error: error ?? "memory search unavailable",
|
|
},
|
|
};
|
|
respond(true, payload, undefined);
|
|
return;
|
|
}
|
|
|
|
try {
|
|
const status = manager.status();
|
|
let embedding = await manager.probeEmbeddingAvailability();
|
|
if (!embedding.ok && !embedding.error) {
|
|
embedding = { ok: false, error: "memory embeddings unavailable" };
|
|
}
|
|
const payload: DoctorMemoryStatusPayload = {
|
|
agentId,
|
|
provider: status.provider,
|
|
embedding,
|
|
};
|
|
respond(true, payload, undefined);
|
|
} catch (err) {
|
|
const payload: DoctorMemoryStatusPayload = {
|
|
agentId,
|
|
embedding: {
|
|
ok: false,
|
|
error: `gateway memory probe failed: ${formatError(err)}`,
|
|
},
|
|
};
|
|
respond(true, payload, undefined);
|
|
} finally {
|
|
await manager.close?.().catch(() => {});
|
|
}
|
|
},
|
|
};
|