@codemem/core 0.0.0 → 0.20.0-alpha.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/dist/address-utils.d.ts +24 -0
- package/dist/address-utils.d.ts.map +1 -0
- package/dist/api-types.d.ts +580 -0
- package/dist/api-types.d.ts.map +1 -0
- package/dist/claude-hooks.d.ts +62 -0
- package/dist/claude-hooks.d.ts.map +1 -0
- package/dist/coordinator-api.d.ts +11 -0
- package/dist/coordinator-api.d.ts.map +1 -0
- package/dist/coordinator-invites.d.ts +28 -0
- package/dist/coordinator-invites.d.ts.map +1 -0
- package/dist/coordinator-store.d.ts +67 -0
- package/dist/coordinator-store.d.ts.map +1 -0
- package/dist/db.d.ts +97 -0
- package/dist/db.d.ts.map +1 -0
- package/dist/embeddings.d.ts +39 -0
- package/dist/embeddings.d.ts.map +1 -0
- package/dist/export-import.d.ts +48 -0
- package/dist/export-import.d.ts.map +1 -0
- package/dist/filters.d.ts +34 -0
- package/dist/filters.d.ts.map +1 -0
- package/dist/index.d.ts +66 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +7287 -0
- package/dist/index.js.map +1 -0
- package/dist/ingest-events.d.ts +34 -0
- package/dist/ingest-events.d.ts.map +1 -0
- package/dist/ingest-filters.d.ts +16 -0
- package/dist/ingest-filters.d.ts.map +1 -0
- package/dist/ingest-pipeline.d.ts +56 -0
- package/dist/ingest-pipeline.d.ts.map +1 -0
- package/dist/ingest-prompts.d.ts +22 -0
- package/dist/ingest-prompts.d.ts.map +1 -0
- package/dist/ingest-sanitize.d.ts +18 -0
- package/dist/ingest-sanitize.d.ts.map +1 -0
- package/dist/ingest-transcript.d.ts +41 -0
- package/dist/ingest-transcript.d.ts.map +1 -0
- package/dist/ingest-types.d.ts +70 -0
- package/dist/ingest-types.d.ts.map +1 -0
- package/dist/ingest-xml-parser.d.ts +20 -0
- package/dist/ingest-xml-parser.d.ts.map +1 -0
- package/dist/integers.d.ts +13 -0
- package/dist/integers.d.ts.map +1 -0
- package/dist/maintenance.d.ts +71 -0
- package/dist/maintenance.d.ts.map +1 -0
- package/dist/observer-auth.d.ts +65 -0
- package/dist/observer-auth.d.ts.map +1 -0
- package/dist/observer-client.d.ts +104 -0
- package/dist/observer-client.d.ts.map +1 -0
- package/dist/observer-config.d.ts +57 -0
- package/dist/observer-config.d.ts.map +1 -0
- package/dist/pack.d.ts +36 -0
- package/dist/pack.d.ts.map +1 -0
- package/dist/project.d.ts +12 -0
- package/dist/project.d.ts.map +1 -0
- package/dist/raw-event-flush.d.ts +43 -0
- package/dist/raw-event-flush.d.ts.map +1 -0
- package/dist/raw-event-sweeper.d.ts +92 -0
- package/dist/raw-event-sweeper.d.ts.map +1 -0
- package/dist/schema.d.ts +7368 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/search.d.ts +76 -0
- package/dist/search.d.ts.map +1 -0
- package/dist/store.d.ts +274 -0
- package/dist/store.d.ts.map +1 -0
- package/dist/sync-auth.d.ts +81 -0
- package/dist/sync-auth.d.ts.map +1 -0
- package/dist/sync-daemon.d.ts +50 -0
- package/dist/sync-daemon.d.ts.map +1 -0
- package/dist/sync-discovery.d.ts +93 -0
- package/dist/sync-discovery.d.ts.map +1 -0
- package/dist/sync-http-client.d.ts +26 -0
- package/dist/sync-http-client.d.ts.map +1 -0
- package/dist/sync-identity.d.ts +38 -0
- package/dist/sync-identity.d.ts.map +1 -0
- package/dist/sync-pass.d.ts +63 -0
- package/dist/sync-pass.d.ts.map +1 -0
- package/dist/sync-replication.d.ts +99 -0
- package/dist/sync-replication.d.ts.map +1 -0
- package/dist/test-utils.d.ts +27 -0
- package/dist/test-utils.d.ts.map +1 -0
- package/dist/types.d.ts +414 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/vectors.d.ts +59 -0
- package/dist/vectors.d.ts.map +1 -0
- package/package.json +42 -1
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Event extraction and budgeting for the ingest pipeline.
|
|
3
|
+
*
|
|
4
|
+
* Ports codemem/ingest/events.py + codemem/ingest_tool_events.py —
|
|
5
|
+
* converts raw plugin events into ToolEvent structs, filters low-signal
|
|
6
|
+
* tools, deduplicates, and budgets the list to fit observer token limits.
|
|
7
|
+
*/
|
|
8
|
+
import type { ToolEvent } from "./ingest-types.js";
|
|
9
|
+
/**
|
|
10
|
+
* Tools whose output is too noisy / low-signal to send to the observer.
|
|
11
|
+
* Matches Python's LOW_SIGNAL_TOOLS set.
|
|
12
|
+
*/
|
|
13
|
+
export declare const LOW_SIGNAL_TOOLS: Set<string>;
|
|
14
|
+
/** Return true for codemem's own MCP tools (avoids feedback loops). */
|
|
15
|
+
export declare function isInternalMemoryTool(tool: string): boolean;
|
|
16
|
+
/** Extract a clean, lowercase tool name from a raw event. */
|
|
17
|
+
export declare function normalizeToolName(event: Record<string, unknown>): string;
|
|
18
|
+
/** Convert a single raw event to a ToolEvent, or null if it should be skipped. */
|
|
19
|
+
export declare function eventToToolEvent(event: Record<string, unknown>, maxChars: number, lowSignalTools?: Set<string>): ToolEvent | null;
|
|
20
|
+
/** Filter and convert all events to ToolEvents. */
|
|
21
|
+
export declare function extractToolEvents(events: Record<string, unknown>[], maxChars: number): ToolEvent[];
|
|
22
|
+
/** Extract validated _adapter event, or null if not a valid v1.0 adapter. */
|
|
23
|
+
export declare function extractAdapterEvent(event: Record<string, unknown>): Record<string, unknown> | null;
|
|
24
|
+
/** Project an adapter tool_result into the flat event format expected by eventToToolEvent. */
|
|
25
|
+
export declare function projectAdapterToolEvent(adapter: Record<string, unknown>, event: Record<string, unknown>): Record<string, unknown> | null;
|
|
26
|
+
/**
|
|
27
|
+
* Deduplicate, rank, and trim tool events to fit within budget.
|
|
28
|
+
*
|
|
29
|
+
* 1. Deduplicates (keeping last occurrence).
|
|
30
|
+
* 2. If over maxEvents, keeps the most important ones.
|
|
31
|
+
* 3. If over maxTotalChars, keeps the most important that fit.
|
|
32
|
+
*/
|
|
33
|
+
export declare function budgetToolEvents(toolEvents: ToolEvent[], maxTotalChars: number, maxEvents: number): ToolEvent[];
|
|
34
|
+
//# sourceMappingURL=ingest-events.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ingest-events.d.ts","sourceRoot":"","sources":["../src/ingest-events.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAMnD;;;GAGG;AACH,eAAO,MAAM,gBAAgB,aAS3B,CAAC;AAMH,uEAAuE;AACvE,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAE1D;AAED,6DAA6D;AAC7D,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAKxE;AA4BD,kFAAkF;AAClF,wBAAgB,gBAAgB,CAC/B,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC9B,QAAQ,EAAE,MAAM,EAChB,cAAc,GAAE,GAAG,CAAC,MAAM,CAAoB,GAC5C,SAAS,GAAG,IAAI,CAgClB;AAED,mDAAmD;AACnD,wBAAgB,iBAAiB,CAChC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,EACjC,QAAQ,EAAE,MAAM,GACd,SAAS,EAAE,CAOb;AAMD,6EAA6E;AAC7E,wBAAgB,mBAAmB,CAClC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC5B,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAmChC;AAED,8FAA8F;AAC9F,wBAAgB,uBAAuB,CACtC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAChC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC5B,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAwBhC;AAgDD;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAC/B,UAAU,EAAE,SAAS,EAAE,EACvB,aAAa,EAAE,MAAM,EACrB,SAAS,EAAE,MAAM,GACf,SAAS,EAAE,CAsDb"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Low-signal observation filtering for the ingest pipeline.
|
|
3
|
+
*
|
|
4
|
+
* Ports the relevant parts of codemem/summarizer.py — detects observations
|
|
5
|
+
* that are too generic or noisy to store as memories.
|
|
6
|
+
*/
|
|
7
|
+
/** Normalize observation text: strip leading bullets/markers, collapse whitespace. */
|
|
8
|
+
export declare function normalizeObservation(text: string): string;
|
|
9
|
+
/**
|
|
10
|
+
* Return true if the observation text is too generic / low-signal to store.
|
|
11
|
+
*
|
|
12
|
+
* Checks against known patterns of empty or self-referential content that
|
|
13
|
+
* the observer LLM sometimes generates.
|
|
14
|
+
*/
|
|
15
|
+
export declare function isLowSignalObservation(text: string): boolean;
|
|
16
|
+
//# sourceMappingURL=ingest-filters.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ingest-filters.d.ts","sourceRoot":"","sources":["../src/ingest-filters.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AA+BH,sFAAsF;AACtF,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAIzD;AAED;;;;;GAKG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAI5D"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Main ingest pipeline — processes raw coding session events, calls the
|
|
3
|
+
* observer LLM, and stores extracted memories.
|
|
4
|
+
*
|
|
5
|
+
* Ports the `ingest()` function from codemem/plugin_ingest.py.
|
|
6
|
+
*
|
|
7
|
+
* Pipeline stages:
|
|
8
|
+
* 1. Extract session context, events, cwd
|
|
9
|
+
* 2. Create/find session in store
|
|
10
|
+
* 3. Extract prompts, tool events, assistant messages
|
|
11
|
+
* 4. Build transcript
|
|
12
|
+
* 5. Budget tool events
|
|
13
|
+
* 6. Build observer context + prompt
|
|
14
|
+
* 7. Call observer LLM via ObserverClient.observe()
|
|
15
|
+
* 8. Parse XML response
|
|
16
|
+
* 9. Filter low-signal observations
|
|
17
|
+
* 10. Persist observations as memories
|
|
18
|
+
* 11. Persist session summary
|
|
19
|
+
* 12. End session
|
|
20
|
+
*/
|
|
21
|
+
import type { IngestPayload } from "./ingest-types.js";
|
|
22
|
+
import type { ObserverClient } from "./observer-client.js";
|
|
23
|
+
import type { MemoryStore } from "./store.js";
|
|
24
|
+
export interface IngestOptions {
|
|
25
|
+
/** Observer LLM client. */
|
|
26
|
+
observer: ObserverClient;
|
|
27
|
+
/** Maximum chars per tool event payload (from config). Default 12000. */
|
|
28
|
+
maxChars?: number;
|
|
29
|
+
/** Maximum chars for observer total budget. Default 12000. */
|
|
30
|
+
observerMaxChars?: number;
|
|
31
|
+
/** Whether to store summaries. Default true. */
|
|
32
|
+
storeSummary?: boolean;
|
|
33
|
+
/** Whether to store typed observations. Default true. */
|
|
34
|
+
storeTyped?: boolean;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Process a batch of raw coding session events through the full ingest pipeline.
|
|
38
|
+
*
|
|
39
|
+
* Extracts prompts, tool events, and assistant messages from the payload,
|
|
40
|
+
* builds a transcript, calls the observer LLM, parses the response,
|
|
41
|
+
* filters low-signal content, and persists observations + summary.
|
|
42
|
+
*/
|
|
43
|
+
export declare function ingest(payload: IngestPayload, store: MemoryStore, options: IngestOptions): Promise<void>;
|
|
44
|
+
/**
|
|
45
|
+
* Close orphan sessions (started but never ended) older than maxAgeHours.
|
|
46
|
+
* Returns the number of sessions closed.
|
|
47
|
+
*/
|
|
48
|
+
export declare function cleanOrphanSessions(store: MemoryStore, maxAgeHours?: number): number;
|
|
49
|
+
/**
|
|
50
|
+
* Read a JSON payload from stdin and run the ingest pipeline.
|
|
51
|
+
*
|
|
52
|
+
* This is the TypeScript equivalent of `codemem ingest` — receives events
|
|
53
|
+
* from the plugin and processes them through the observer LLM.
|
|
54
|
+
*/
|
|
55
|
+
export declare function main(store: MemoryStore, observer: ObserverClient): Promise<void>;
|
|
56
|
+
//# sourceMappingURL=ingest-pipeline.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ingest-pipeline.d.ts","sourceRoot":"","sources":["../src/ingest-pipeline.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAwBH,OAAO,KAAK,EACX,aAAa,EAKb,MAAM,mBAAmB,CAAC;AAE3B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAE3D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AA4F9C,MAAM,WAAW,aAAa;IAC7B,2BAA2B;IAC3B,QAAQ,EAAE,cAAc,CAAC;IACzB,yEAAyE;IACzE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,8DAA8D;IAC9D,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,gDAAgD;IAChD,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,yDAAyD;IACzD,UAAU,CAAC,EAAE,OAAO,CAAC;CACrB;AAED;;;;;;GAMG;AACH,wBAAsB,MAAM,CAC3B,OAAO,EAAE,aAAa,EACtB,KAAK,EAAE,WAAW,EAClB,OAAO,EAAE,aAAa,GACpB,OAAO,CAAC,IAAI,CAAC,CAuRf;AA0BD;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,WAAW,EAAE,WAAW,SAAK,GAAG,MAAM,CAShF;AAMD;;;;;GAKG;AACH,wBAAsB,IAAI,CAAC,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC,CAgBtF"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Observer prompt construction for the ingest pipeline.
|
|
3
|
+
*
|
|
4
|
+
* Ports codemem/observer_prompts.py — builds the system + user prompt
|
|
5
|
+
* sent to the observer LLM that extracts memories from session transcripts.
|
|
6
|
+
*/
|
|
7
|
+
import type { ObserverContext } from "./ingest-types.js";
|
|
8
|
+
/**
|
|
9
|
+
* Build the observer prompt from session context.
|
|
10
|
+
*
|
|
11
|
+
* Returns `{ system, user }` — the system prompt contains identity + schema,
|
|
12
|
+
* the user prompt contains the observed session context.
|
|
13
|
+
*
|
|
14
|
+
* The Python version concatenates everything into one prompt string passed as
|
|
15
|
+
* the user message. We split system/user for cleaner API mapping, but the
|
|
16
|
+
* content is equivalent.
|
|
17
|
+
*/
|
|
18
|
+
export declare function buildObserverPrompt(context: ObserverContext): {
|
|
19
|
+
system: string;
|
|
20
|
+
user: string;
|
|
21
|
+
};
|
|
22
|
+
//# sourceMappingURL=ingest-prompts.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ingest-prompts.d.ts","sourceRoot":"","sources":["../src/ingest-prompts.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAa,MAAM,mBAAmB,CAAC;AAoJpE;;;;;;;;;GASG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,eAAe,GAAG;IAC9D,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;CACb,CA+DA"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Text sanitization for the ingest pipeline.
|
|
3
|
+
*
|
|
4
|
+
* Ports codemem/ingest_sanitize.py — strips <private> blocks and redacts
|
|
5
|
+
* sensitive field names from payloads before they reach the observer LLM.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Remove `<private>…</private>` blocks from text.
|
|
9
|
+
*
|
|
10
|
+
* Handles matched pairs, orphaned opening tags (truncates at the tag),
|
|
11
|
+
* and stray closing tags (removed).
|
|
12
|
+
*/
|
|
13
|
+
export declare function stripPrivate(text: string): string;
|
|
14
|
+
export declare function isSensitiveFieldName(fieldName: string): boolean;
|
|
15
|
+
export declare function stripPrivateObj(value: unknown): unknown;
|
|
16
|
+
export declare function sanitizePayload(value: unknown, maxChars: number): unknown;
|
|
17
|
+
export declare function sanitizeToolOutput(_tool: string, output: unknown, maxChars: number): unknown;
|
|
18
|
+
//# sourceMappingURL=ingest-sanitize.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ingest-sanitize.d.ts","sourceRoot":"","sources":["../src/ingest-sanitize.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAUH;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAYjD;AAWD,wBAAgB,oBAAoB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAI/D;AAMD,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAevD;AAYD,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAkBzE;AA0BD,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAM5F"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Transcript building and request analysis for the ingest pipeline.
|
|
3
|
+
*
|
|
4
|
+
* Ports codemem/ingest/transcript.py + relevant extraction functions
|
|
5
|
+
* from codemem/plugin_ingest.py.
|
|
6
|
+
*/
|
|
7
|
+
import type { ParsedSummary } from "./ingest-types.js";
|
|
8
|
+
export declare const TRIVIAL_REQUESTS: Set<string>;
|
|
9
|
+
/** Normalize request text for comparison: trim, strip quotes, collapse whitespace, lowercase. */
|
|
10
|
+
export declare function normalizeRequestText(text: string | null): string;
|
|
11
|
+
/** Check whether the text is a trivial approval/acknowledgement. */
|
|
12
|
+
export declare function isTrivialRequest(text: string | null): boolean;
|
|
13
|
+
/** Extract the first sentence from text (strip markdown prefixes). */
|
|
14
|
+
export declare function firstSentence(text: string): string;
|
|
15
|
+
/** Derive a meaningful request from summary fields when the original is trivial. */
|
|
16
|
+
export declare function deriveRequest(summary: ParsedSummary): string;
|
|
17
|
+
/**
|
|
18
|
+
* Build a chronological transcript from user prompts and assistant messages.
|
|
19
|
+
* Strips private content before including text.
|
|
20
|
+
*/
|
|
21
|
+
export declare function buildTranscript(events: Record<string, unknown>[]): string;
|
|
22
|
+
/** Extract assistant text messages from raw events. */
|
|
23
|
+
export declare function extractAssistantMessages(events: Record<string, unknown>[]): string[];
|
|
24
|
+
/** Extract token usage events from assistant_usage events. */
|
|
25
|
+
export declare function extractAssistantUsage(events: Record<string, unknown>[]): Record<string, number>[];
|
|
26
|
+
/** Extract user prompts with prompt numbers from raw events. */
|
|
27
|
+
export declare function extractPrompts(events: Record<string, unknown>[]): {
|
|
28
|
+
promptText: string;
|
|
29
|
+
promptNumber: number | null;
|
|
30
|
+
timestamp: string | null;
|
|
31
|
+
}[];
|
|
32
|
+
/**
|
|
33
|
+
* Project adapter events into the flat event format used by transcript building.
|
|
34
|
+
*
|
|
35
|
+
* Adapter events use the `_adapter` envelope (schema v1.0). This function
|
|
36
|
+
* converts prompt and assistant adapter events into the standard
|
|
37
|
+
* `user_prompt` / `assistant_message` shapes so buildTranscript can
|
|
38
|
+
* process them uniformly.
|
|
39
|
+
*/
|
|
40
|
+
export declare function normalizeAdapterEvents(events: Record<string, unknown>[]): Record<string, unknown>[];
|
|
41
|
+
//# sourceMappingURL=ingest-transcript.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ingest-transcript.d.ts","sourceRoot":"","sources":["../src/ingest-transcript.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAE,aAAa,EAAE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2
|
+
* Types for the ingest pipeline.
|
|
3
|
+
*
|
|
4
|
+
* Mirrors the Python dataclasses from codemem/observer_prompts.py and
|
|
5
|
+
* codemem/xml_parser.py.
|
|
6
|
+
*/
|
|
7
|
+
export interface ToolEvent {
|
|
8
|
+
toolName: string;
|
|
9
|
+
toolInput: unknown;
|
|
10
|
+
toolOutput: unknown;
|
|
11
|
+
toolError: unknown;
|
|
12
|
+
timestamp: string | null;
|
|
13
|
+
cwd: string | null;
|
|
14
|
+
}
|
|
15
|
+
export interface ObserverContext {
|
|
16
|
+
project: string | null;
|
|
17
|
+
userPrompt: string;
|
|
18
|
+
promptNumber: number | null;
|
|
19
|
+
toolEvents: ToolEvent[];
|
|
20
|
+
lastAssistantMessage: string | null;
|
|
21
|
+
includeSummary: boolean;
|
|
22
|
+
diffSummary: string;
|
|
23
|
+
recentFiles: string;
|
|
24
|
+
}
|
|
25
|
+
export interface ParsedObservation {
|
|
26
|
+
kind: string;
|
|
27
|
+
title: string;
|
|
28
|
+
narrative: string;
|
|
29
|
+
subtitle: string | null;
|
|
30
|
+
facts: string[];
|
|
31
|
+
concepts: string[];
|
|
32
|
+
filesRead: string[];
|
|
33
|
+
filesModified: string[];
|
|
34
|
+
}
|
|
35
|
+
export interface ParsedSummary {
|
|
36
|
+
request: string;
|
|
37
|
+
investigated: string;
|
|
38
|
+
learned: string;
|
|
39
|
+
completed: string;
|
|
40
|
+
nextSteps: string;
|
|
41
|
+
notes: string;
|
|
42
|
+
filesRead: string[];
|
|
43
|
+
filesModified: string[];
|
|
44
|
+
}
|
|
45
|
+
export interface ParsedOutput {
|
|
46
|
+
observations: ParsedObservation[];
|
|
47
|
+
summary: ParsedSummary | null;
|
|
48
|
+
skipSummaryReason: string | null;
|
|
49
|
+
}
|
|
50
|
+
export interface SessionContext {
|
|
51
|
+
flushBatch?: Record<string, unknown>;
|
|
52
|
+
firstPrompt?: string;
|
|
53
|
+
promptCount?: number;
|
|
54
|
+
toolCount?: number;
|
|
55
|
+
durationMs?: number;
|
|
56
|
+
filesModified?: string[];
|
|
57
|
+
filesRead?: string[];
|
|
58
|
+
source?: string;
|
|
59
|
+
streamId?: string;
|
|
60
|
+
opencodeSessionId?: string;
|
|
61
|
+
flusher?: string;
|
|
62
|
+
}
|
|
63
|
+
export interface IngestPayload {
|
|
64
|
+
cwd?: string;
|
|
65
|
+
events?: Record<string, unknown>[];
|
|
66
|
+
project?: string;
|
|
67
|
+
startedAt?: string;
|
|
68
|
+
sessionContext?: SessionContext;
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=ingest-types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ingest-types.d.ts","sourceRoot":"","sources":["../src/ingest-types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAMH,MAAM,WAAW,SAAS;IACzB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,OAAO,CAAC;IACnB,UAAU,EAAE,OAAO,CAAC;IACpB,SAAS,EAAE,OAAO,CAAC;IACnB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;CACnB;AAMD,MAAM,WAAW,eAAe;IAC/B,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,UAAU,EAAE,SAAS,EAAE,CAAC;IACxB,oBAAoB,EAAE,MAAM,GAAG,IAAI,CAAC;IACpC,cAAc,EAAE,OAAO,CAAC;IACxB,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;CACpB;AAMD,MAAM,WAAW,iBAAiB;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,KAAK,EAAE,MAAM,EAAE,C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AAC;IACnB,cAAc,CAAC,EAAE,cAAc,CAAC;CAChC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* XML response parser for the observer LLM output.
|
|
3
|
+
*
|
|
4
|
+
* Ports codemem/xml_parser.py — uses regex-based parsing to extract
|
|
5
|
+
* observations and session summaries from the observer's XML response.
|
|
6
|
+
*
|
|
7
|
+
* The observer output is structured XML, not arbitrary HTML, so regex
|
|
8
|
+
* is sufficient (no DOM parser needed).
|
|
9
|
+
*/
|
|
10
|
+
import type { ParsedObservation, ParsedOutput } from "./ingest-types.js";
|
|
11
|
+
/**
|
|
12
|
+
* Parse the observer LLM's XML response into structured data.
|
|
13
|
+
*
|
|
14
|
+
* Extracts all `<observation>` blocks and the last `<summary>` block.
|
|
15
|
+
* Handles missing/empty tags gracefully.
|
|
16
|
+
*/
|
|
17
|
+
export declare function parseObserverResponse(raw: string): ParsedOutput;
|
|
18
|
+
/** Return true if at least one observation has a title or narrative. */
|
|
19
|
+
export declare function hasMeaningfulObservation(observations: ParsedObservation[]): boolean;
|
|
20
|
+
//# sourceMappingURL=ingest-xml-parser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ingest-xml-parser.d.ts","sourceRoot":"","sources":["../src/ingest-xml-parser.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,YAAY,EAAiB,MAAM,mBAAmB,CAAC;AAmGxF;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,MAAM,GAAG,YAAY,CAwB/D;AAED,wEAAwE;AACxE,wBAAgB,wBAAwB,CAAC,YAAY,EAAE,iBAAiB,EAAE,GAAG,OAAO,CAEnF"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parse a strict integer string like Python's int(), but reject partial strings
|
|
3
|
+
* like "10abc" that parseInt() would silently truncate.
|
|
4
|
+
*/
|
|
5
|
+
export declare function parseStrictInteger(value: string | undefined): number | null;
|
|
6
|
+
/**
|
|
7
|
+
* Parse a positive memory ID matching Python's stricter semantics:
|
|
8
|
+
* - allow integer numbers
|
|
9
|
+
* - allow digit-only strings
|
|
10
|
+
* - reject bools, floats, scientific notation, whitespacey strings, unsafe ints
|
|
11
|
+
*/
|
|
12
|
+
export declare function parsePositiveMemoryId(value: unknown): number | null;
|
|
13
|
+
//# sourceMappingURL=integers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"integers.d.ts","sourceRoot":"","sources":["../src/integers.ts"],"names":[],"mappings":"AAGA;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,IAAI,CAW3E;AAED;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI,CAiBnE"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
export interface RawEventStatusItem {
|
|
2
|
+
source: string;
|
|
3
|
+
stream_id: string;
|
|
4
|
+
opencode_session_id: string | null;
|
|
5
|
+
cwd: string | null;
|
|
6
|
+
project: string | null;
|
|
7
|
+
started_at: string | null;
|
|
8
|
+
last_seen_ts_wall_ms: number | null;
|
|
9
|
+
last_received_event_seq: number;
|
|
10
|
+
last_flushed_event_seq: number;
|
|
11
|
+
updated_at: string;
|
|
12
|
+
session_stream_id: string;
|
|
13
|
+
session_id: string;
|
|
14
|
+
}
|
|
15
|
+
export interface RawEventStatusResult {
|
|
16
|
+
items: RawEventStatusItem[];
|
|
17
|
+
totals: {
|
|
18
|
+
pending: number;
|
|
19
|
+
sessions: number;
|
|
20
|
+
};
|
|
21
|
+
ingest: {
|
|
22
|
+
available: true;
|
|
23
|
+
mode: "stream_queue";
|
|
24
|
+
max_body_bytes: number;
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
export declare function initDatabase(dbPath?: string): {
|
|
28
|
+
path: string;
|
|
29
|
+
sizeBytes: number;
|
|
30
|
+
};
|
|
31
|
+
export declare function vacuumDatabase(dbPath?: string): {
|
|
32
|
+
path: string;
|
|
33
|
+
sizeBytes: number;
|
|
34
|
+
};
|
|
35
|
+
export declare function getRawEventStatus(dbPath?: string, limit?: number): RawEventStatusResult;
|
|
36
|
+
export interface ReliabilityMetrics {
|
|
37
|
+
counts: {
|
|
38
|
+
inserted_events: number;
|
|
39
|
+
dropped_events: number;
|
|
40
|
+
started_batches: number;
|
|
41
|
+
running_batches: number;
|
|
42
|
+
completed_batches: number;
|
|
43
|
+
errored_batches: number;
|
|
44
|
+
terminal_batches: number;
|
|
45
|
+
sessions_with_events: number;
|
|
46
|
+
sessions_with_started_at: number;
|
|
47
|
+
retry_depth_max: number;
|
|
48
|
+
};
|
|
49
|
+
rates: {
|
|
50
|
+
flush_success_rate: number;
|
|
51
|
+
dropped_event_rate: number;
|
|
52
|
+
session_boundary_accuracy: number;
|
|
53
|
+
};
|
|
54
|
+
window_hours: number | null;
|
|
55
|
+
}
|
|
56
|
+
export declare function getReliabilityMetrics(dbPath?: string, windowHours?: number | null): ReliabilityMetrics;
|
|
57
|
+
export interface GateResult {
|
|
58
|
+
passed: boolean;
|
|
59
|
+
failures: string[];
|
|
60
|
+
metrics: ReliabilityMetrics;
|
|
61
|
+
}
|
|
62
|
+
export declare function rawEventsGate(dbPath?: string, opts?: {
|
|
63
|
+
minFlushSuccessRate?: number;
|
|
64
|
+
maxDroppedEventRate?: number;
|
|
65
|
+
minSessionBoundaryAccuracy?: number;
|
|
66
|
+
windowHours?: number;
|
|
67
|
+
}): GateResult;
|
|
68
|
+
export declare function retryRawEventFailures(dbPath?: string, limit?: number): {
|
|
69
|
+
retried: number;
|
|
70
|
+
};
|
|
71
|
+
//# sourceMappingURL=maintenance.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"maintenance.d.ts","sourceRoot":"","sources":["../src/maintenance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,eAAe,EAAE,MAAM,CAAC;QACxB,eAAe,EAAE,MAAM,CAAC;QACxB,iBAAiB,EAAE,MAAM,CAAC;QAC1B,eAAe,EAAE,MAAM,CAAC;QACxB,gBAAgB,EAAE,MAAM,CAAC;QACzB,oBAAoB,EAAE,MAAM,CAAC;QAC7B,wBAAwB,EAAE,MAAM,CAAC;QACjC,eAAe,EAAE,MAAM,CAAC;KACxB,CAAC;IACF,KAAK,EAAE;QACN,kBAAkB,EAAE,MAAM,CAAC;QAC3B,kBAAkB,EAAE,MAAM,CAAC;QAC3B,yBAAyB,EAAE,MAAM,CAAC;KAClC,CAAC;IACF,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;CAC5B;AAED,wBAAgB,qBAAqB,CACpC,MAAM,CAAC,EAAE,MAAM,EACf,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,GACzB,kBAAkB,CAqGpB;AAED,MAAM,WAAW,UAAU;IAC1B,MAAM,EAAE,OAAO,CAAC;IAChB,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,OAAO,EAAE,kBAAkB,CAAC;CAC5B;AAED,wBAAgB,aAAa,CAC5B,MAAM,CAAC,EAAE,MAAM,EACf,IAAI,CAAC,EAAE;IACN,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,0BAA0B,CAAC,EAAE,MAAM,CAAC;IACpC,WAAW,CAAC,EAAE,MAAM,CAAC;CACrB,GACC,UAAU,CA0BZ;AAMD,wBAAgB,qBAAqB,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,KAAK,SAAK,GAAG;IAAE,OAAO,EAAE,MAAM,CAAA;CAAE,CA0BtF"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Observer authentication: credential resolution, caching, and header rendering.
|
|
3
|
+
*
|
|
4
|
+
* Mirrors codemem/observer_auth.py — resolves auth tokens from explicit values,
|
|
5
|
+
* environment variables, OAuth caches, files, or external commands. Supports
|
|
6
|
+
* template-based header rendering with `${auth.token}` / `${auth.type}` / `${auth.source}`.
|
|
7
|
+
*/
|
|
8
|
+
/** Redact API keys and bearer tokens in text. Truncates at `limit` chars. */
|
|
9
|
+
export declare function redactText(text: string, limit?: number): string;
|
|
10
|
+
export interface ObserverAuthMaterial {
|
|
11
|
+
token: string | null;
|
|
12
|
+
authType: string;
|
|
13
|
+
source: string;
|
|
14
|
+
}
|
|
15
|
+
/** Load the OpenCode OAuth token cache from `~/.local/share/opencode/auth.json`. */
|
|
16
|
+
export declare function loadOpenCodeOAuthCache(): Record<string, unknown>;
|
|
17
|
+
/** Determine OAuth provider from configured provider name or model prefix. */
|
|
18
|
+
export declare function resolveOAuthProvider(configured: string | null | undefined, model: string): string;
|
|
19
|
+
/** Extract access token from OAuth cache for a given provider. */
|
|
20
|
+
export declare function extractOAuthAccess(cache: Record<string, unknown>, provider: string): string | null;
|
|
21
|
+
/** Extract account ID from OAuth cache for a given provider. */
|
|
22
|
+
export declare function extractOAuthAccountId(cache: Record<string, unknown>, provider: string): string | null;
|
|
23
|
+
/** Extract expiry timestamp (ms) from OAuth cache for a given provider. */
|
|
24
|
+
export declare function extractOAuthExpires(cache: Record<string, unknown>, provider: string): number | null;
|
|
25
|
+
/** Build OpenAI Codex transport headers from an OAuth access token. */
|
|
26
|
+
export declare function buildCodexHeaders(accessToken: string, accountId: string | null): Record<string, string>;
|
|
27
|
+
/** Execute an external auth command and return the token (stdout, trimmed). */
|
|
28
|
+
export declare function runAuthCommand(command: string[], timeoutMs: number): string | null;
|
|
29
|
+
/** Read a token from a file path (supports `~` and `$ENV_VAR` expansion). */
|
|
30
|
+
export declare function readAuthFile(filePath: string | null): string | null;
|
|
31
|
+
export interface ObserverAuthResolveOptions {
|
|
32
|
+
explicitToken?: string | null;
|
|
33
|
+
envTokens?: string[];
|
|
34
|
+
oauthToken?: string | null;
|
|
35
|
+
forceRefresh?: boolean;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Resolves auth credentials through a configurable cascade:
|
|
39
|
+
* explicit → env → oauth → file → command.
|
|
40
|
+
*
|
|
41
|
+
* Results from file/command sources are cached for `cacheTtlS` seconds.
|
|
42
|
+
*/
|
|
43
|
+
export declare class ObserverAuthAdapter {
|
|
44
|
+
readonly source: string;
|
|
45
|
+
readonly filePath: string | null;
|
|
46
|
+
readonly command: string[];
|
|
47
|
+
readonly timeoutMs: number;
|
|
48
|
+
readonly cacheTtlS: number;
|
|
49
|
+
private cached;
|
|
50
|
+
private cachedAtMs;
|
|
51
|
+
constructor(opts?: {
|
|
52
|
+
source?: string;
|
|
53
|
+
filePath?: string | null;
|
|
54
|
+
command?: string[];
|
|
55
|
+
timeoutMs?: number;
|
|
56
|
+
cacheTtlS?: number;
|
|
57
|
+
});
|
|
58
|
+
/** Resolve auth material through the credential cascade. */
|
|
59
|
+
resolve(opts?: ObserverAuthResolveOptions): ObserverAuthMaterial;
|
|
60
|
+
/** Clear the cached auth material. */
|
|
61
|
+
invalidateCache(): void;
|
|
62
|
+
}
|
|
63
|
+
/** Render observer headers with `${auth.token}`, `${auth.type}`, `${auth.source}` substitution. */
|
|
64
|
+
export declare function renderObserverHeaders(headers: Record<string, string>, auth: ObserverAuthMaterial): Record<string, string>;
|
|
65
|
+
//# sourceMappingURL=observer-auth.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"observer-auth.d.ts","sourceRoot":"","sources":["../src/observer-auth.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAiBH,6EAA6E;AAC7E,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,SAAM,GAAG,MAAM,CAM5D;AAMD,MAAM,WAAW,oBAAoB;IACpC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;CACf;AAcD,oFAAoF;AACpF,wBAAgB,sBAAsB,IAAI,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;IAC/B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACjC,QAAQ,CAAC,OAAO,EAAE,MAAM,EAAE,CAAC;IAC3B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAE3B,OAAO,CAAC,MAAM,CAAkC;IAChD,OAAO,CAAC,UAAU,CAAK;gBAEX,IAAI,CAAC,EAAE;QAClB,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;QACzB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;QACnB,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,SAAS,CAAC,EAAE,MAAM,CAAC;KACnB;IAQD,4DAA4D;IAC5D,OAAO,CAAC,IAAI,CAAC,EAAE,0BAA0B,GAAG,oBAAoB;IA+DhE,sCAAsC;IACtC,eAAe,IAAI,IAAI;CAIvB;AAUD,mGAAmG;AACnG,wBAAgB,qBAAqB,CACpC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAC/B,IAAI,EAAE,oBAAoB,GACxB,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAmBxB"}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Observer client: LLM caller for analyzing coding session transcripts.
|
|
3
|
+
*
|
|
4
|
+
* Mirrors codemem/observer.py — resolves provider config + auth, then calls
|
|
5
|
+
* an LLM (Anthropic Messages or OpenAI Chat Completions) via fetch to extract
|
|
6
|
+
* memories from session transcripts.
|
|
7
|
+
*
|
|
8
|
+
* Phase 1 scope: api_http runtime only (no claude_sidecar, no opencode_run).
|
|
9
|
+
* Non-streaming responses via fetch (no SDK deps).
|
|
10
|
+
*/
|
|
11
|
+
import { ObserverAuthAdapter, type ObserverAuthMaterial } from "./observer-auth.js";
|
|
12
|
+
export interface ObserverConfig {
|
|
13
|
+
observerProvider: string | null;
|
|
14
|
+
observerModel: string | null;
|
|
15
|
+
observerRuntime: string | null;
|
|
16
|
+
observerApiKey: string | null;
|
|
17
|
+
observerBaseUrl: string | null;
|
|
18
|
+
observerMaxChars: number;
|
|
19
|
+
observerMaxTokens: number;
|
|
20
|
+
observerHeaders: Record<string, string>;
|
|
21
|
+
observerAuthSource: string;
|
|
22
|
+
observerAuthFile: string | null;
|
|
23
|
+
observerAuthCommand: string[];
|
|
24
|
+
observerAuthTimeoutMs: number;
|
|
25
|
+
observerAuthCacheTtlS: number;
|
|
26
|
+
}
|
|
27
|
+
export interface ObserverResponse {
|
|
28
|
+
raw: string | null;
|
|
29
|
+
parsed: Record<string, unknown> | null;
|
|
30
|
+
provider: string;
|
|
31
|
+
model: string;
|
|
32
|
+
}
|
|
33
|
+
export interface ObserverStatus {
|
|
34
|
+
provider: string;
|
|
35
|
+
model: string;
|
|
36
|
+
runtime: string;
|
|
37
|
+
auth: {
|
|
38
|
+
source: string;
|
|
39
|
+
type: string;
|
|
40
|
+
hasToken: boolean;
|
|
41
|
+
};
|
|
42
|
+
lastError?: {
|
|
43
|
+
code: string;
|
|
44
|
+
message: string;
|
|
45
|
+
} | null;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Load observer config from `~/.config/codemem/config.json{c}`.
|
|
49
|
+
*
|
|
50
|
+
* Reads the codemem config file (not OpenCode's) and extracts observer-related
|
|
51
|
+
* fields with environment variable overrides.
|
|
52
|
+
*/
|
|
53
|
+
export declare function loadObserverConfig(): ObserverConfig;
|
|
54
|
+
export declare class ObserverAuthError extends Error {
|
|
55
|
+
constructor(message: string);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* LLM client for analyzing coding session transcripts and extracting memories.
|
|
59
|
+
*
|
|
60
|
+
* Resolves provider + auth from codemem config, then calls the LLM via fetch.
|
|
61
|
+
* Supports Anthropic Messages API, OpenAI Chat Completions, Codex consumer
|
|
62
|
+
* (OpenAI OAuth + SSE), and Anthropic OAuth consumer (SSE).
|
|
63
|
+
*/
|
|
64
|
+
export declare class ObserverClient {
|
|
65
|
+
readonly provider: string;
|
|
66
|
+
model: string;
|
|
67
|
+
readonly runtime: string;
|
|
68
|
+
readonly maxChars: number;
|
|
69
|
+
readonly maxTokens: number;
|
|
70
|
+
/** Resolved auth material — updated on refresh. */
|
|
71
|
+
auth: ObserverAuthMaterial;
|
|
72
|
+
readonly authAdapter: ObserverAuthAdapter;
|
|
73
|
+
private _observerHeaders;
|
|
74
|
+
private _customBaseUrl;
|
|
75
|
+
private readonly _apiKey;
|
|
76
|
+
private _codexAccess;
|
|
77
|
+
private _codexAccountId;
|
|
78
|
+
private _anthropicOAuthAccess;
|
|
79
|
+
private _lastErrorCode;
|
|
80
|
+
private _lastErrorMessage;
|
|
81
|
+
constructor(config?: ObserverConfig);
|
|
82
|
+
/** Return the resolved runtime state of this observer client. */
|
|
83
|
+
getStatus(): ObserverStatus;
|
|
84
|
+
/** Force-refresh auth credentials. */
|
|
85
|
+
refreshAuth(force?: boolean): void;
|
|
86
|
+
/**
|
|
87
|
+
* Call the LLM with a system prompt and user prompt, return the response.
|
|
88
|
+
*
|
|
89
|
+
* This is the main entry point. On auth errors, attempts one refresh + retry.
|
|
90
|
+
*/
|
|
91
|
+
observe(systemPrompt: string, userPrompt: string): Promise<ObserverResponse>;
|
|
92
|
+
private _initProvider;
|
|
93
|
+
private _callOnce;
|
|
94
|
+
private _callAnthropicDirect;
|
|
95
|
+
private _callOpenAIDirect;
|
|
96
|
+
private _callCodexConsumer;
|
|
97
|
+
private _callAnthropicConsumer;
|
|
98
|
+
private _fetchJSON;
|
|
99
|
+
private _fetchSSE;
|
|
100
|
+
private _handleHttpError;
|
|
101
|
+
private _setLastError;
|
|
102
|
+
private _clearLastError;
|
|
103
|
+
}
|
|
104
|
+
//# sourceMappingURL=observer-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
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