File size: 1,634 Bytes
6111b2b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/**

 * Memory extraction pipeline verification

 * Creates a test memory, verifies it can be listed, and cleans up.

 */

import { createMemory, listMemories, deleteMemory } from "./store";
import { MemoryType } from "./types";
import { logger } from "../../../open-sse/utils/logger.ts";

const log = logger("MEMORY_VERIFY");

export async function verifyExtractionPipeline(

  apiKeyId: string

): Promise<{ working: boolean; latencyMs: number; error?: string }> {
  const start = Date.now();
  log.info("memory.verify.start", { apiKeyId });

  let createdMemory: { id: string } | null = null;

  try {
    createdMemory = await createMemory({
      key: "__extraction_test__",
      content: "pipeline verification test",
      type: MemoryType.FACTUAL,
      apiKeyId,
      sessionId: "",
      metadata: {},
      expiresAt: null,
    });

    const result = await listMemories({ apiKeyId, page: 1, limit: 100 });
    const found = result.data.some((m) => m.key === "__extraction_test__");

    const latencyMs = Date.now() - start;
    const working = found;

    log.info("memory.verify.complete", { working, latencyMs });

    return { working, latencyMs };
  } catch (err: unknown) {
    const latencyMs = Date.now() - start;
    const error = String(err);

    log.info("memory.verify.complete", { working: false, latencyMs });

    return { working: false, latencyMs, error };
  } finally {
    if (createdMemory) {
      try {
        await deleteMemory(createdMemory.id);
      } catch {
        // Cleanup best-effort — don't mask original error
      }
    }
  }
}