@hasna/mementos 0.4.39 → 0.6.0
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/dist/cli/index.js +2301 -1545
- package/dist/db/agents.d.ts +1 -1
- package/dist/db/agents.d.ts.map +1 -1
- package/dist/db/database.d.ts.map +1 -1
- package/dist/db/locks.d.ts +52 -0
- package/dist/db/locks.d.ts.map +1 -0
- package/dist/db/memories.d.ts +1 -0
- package/dist/db/memories.d.ts.map +1 -1
- package/dist/index.d.ts +9 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1905 -1003
- package/dist/lib/auto-memory-queue.d.ts +46 -0
- package/dist/lib/auto-memory-queue.d.ts.map +1 -0
- package/dist/lib/auto-memory.d.ts +18 -0
- package/dist/lib/auto-memory.d.ts.map +1 -0
- package/dist/lib/dedup.d.ts +33 -0
- package/dist/lib/dedup.d.ts.map +1 -0
- package/dist/lib/focus.d.ts +58 -0
- package/dist/lib/focus.d.ts.map +1 -0
- package/dist/lib/memory-lock.d.ts +58 -0
- package/dist/lib/memory-lock.d.ts.map +1 -0
- package/dist/lib/providers/anthropic.d.ts +21 -0
- package/dist/lib/providers/anthropic.d.ts.map +1 -0
- package/dist/lib/providers/base.d.ts +96 -0
- package/dist/lib/providers/base.d.ts.map +1 -0
- package/dist/lib/providers/cerebras.d.ts +20 -0
- package/dist/lib/providers/cerebras.d.ts.map +1 -0
- package/dist/lib/providers/grok.d.ts +19 -0
- package/dist/lib/providers/grok.d.ts.map +1 -0
- package/dist/lib/providers/index.d.ts +7 -0
- package/dist/lib/providers/index.d.ts.map +1 -0
- package/dist/lib/providers/openai-compat.d.ts +18 -0
- package/dist/lib/providers/openai-compat.d.ts.map +1 -0
- package/dist/lib/providers/openai.d.ts +20 -0
- package/dist/lib/providers/openai.d.ts.map +1 -0
- package/dist/lib/providers/registry.d.ts +38 -0
- package/dist/lib/providers/registry.d.ts.map +1 -0
- package/dist/lib/search.d.ts.map +1 -1
- package/dist/mcp/index.js +1917 -996
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +1602 -894
- package/dist/types/index.d.ts +24 -0
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fire-and-forget async queue for memory extraction jobs.
|
|
3
|
+
* enqueue() returns void immediately — never blocks the caller.
|
|
4
|
+
* Bounded to MAX_QUEUE_SIZE; oldest job dropped on overflow.
|
|
5
|
+
* All failures are silently logged — never propagate to caller.
|
|
6
|
+
*/
|
|
7
|
+
export interface ExtractionJob {
|
|
8
|
+
agentId?: string;
|
|
9
|
+
projectId?: string;
|
|
10
|
+
sessionId?: string;
|
|
11
|
+
/** The text to extract memories from (conversation turn, session chunk, etc.) */
|
|
12
|
+
turn: string;
|
|
13
|
+
timestamp: number;
|
|
14
|
+
/** Metadata passed through to the extraction pipeline */
|
|
15
|
+
source?: "turn" | "session" | "manual";
|
|
16
|
+
}
|
|
17
|
+
export interface QueueStats {
|
|
18
|
+
pending: number;
|
|
19
|
+
processing: number;
|
|
20
|
+
processed: number;
|
|
21
|
+
failed: number;
|
|
22
|
+
dropped: number;
|
|
23
|
+
}
|
|
24
|
+
type JobHandler = (job: ExtractionJob) => Promise<void>;
|
|
25
|
+
declare class AutoMemoryQueue {
|
|
26
|
+
private queue;
|
|
27
|
+
private handler;
|
|
28
|
+
private running;
|
|
29
|
+
private activeCount;
|
|
30
|
+
private stats;
|
|
31
|
+
/** Register the handler that processes each job */
|
|
32
|
+
setHandler(handler: JobHandler): void;
|
|
33
|
+
/**
|
|
34
|
+
* Enqueue a job. Returns immediately — never awaits.
|
|
35
|
+
* If queue is full, drops the oldest job (FIFO overflow).
|
|
36
|
+
*/
|
|
37
|
+
enqueue(job: ExtractionJob): void;
|
|
38
|
+
getStats(): Readonly<QueueStats>;
|
|
39
|
+
private startLoop;
|
|
40
|
+
private loop;
|
|
41
|
+
private processJob;
|
|
42
|
+
}
|
|
43
|
+
/** Singleton queue — shared across the process */
|
|
44
|
+
export declare const autoMemoryQueue: AutoMemoryQueue;
|
|
45
|
+
export {};
|
|
46
|
+
//# sourceMappingURL=auto-memory-queue.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auto-memory-queue.d.ts","sourceRoot":"","sources":["../../src/lib/auto-memory-queue.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,WAAW,aAAa;IAC5B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,iFAAiF;IACjF,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,yDAAyD;IACzD,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,GAAG,QAAQ,CAAC;CACxC;AAED,MAAM,WAAW,UAAU;IACzB,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,KAAK,UAAU,GAAG,CAAC,GAAG,EAAE,aAAa,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;AAKxD,cAAM,eAAe;IACnB,OAAO,CAAC,KAAK,CAAuB;IACpC,OAAO,CAAC,OAAO,CAA2B;IAC1C,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,WAAW,CAAK;IAExB,OAAO,CAAC,KAAK,CAMX;IAEF,mDAAmD;IACnD,UAAU,CAAC,OAAO,EAAE,UAAU,GAAG,IAAI;IAKrC;;;OAGG;IACH,OAAO,CAAC,GAAG,EAAE,aAAa,GAAG,IAAI;IAYjC,QAAQ,IAAI,QAAQ,CAAC,UAAU,CAAC;IAIhC,OAAO,CAAC,SAAS;YAKH,IAAI;YAiBJ,UAAU;CAiBzB;AAED,kDAAkD;AAClD,eAAO,MAAM,eAAe,iBAAwB,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LLM-based auto-memory formation pipeline.
|
|
3
|
+
* NO REGEX — all extraction is done by LLMs.
|
|
4
|
+
* Main export: processConversationTurn(turn, context) — fire and forget.
|
|
5
|
+
* All failures are silently logged and never propagate.
|
|
6
|
+
*/
|
|
7
|
+
import { providerRegistry } from "./providers/registry.js";
|
|
8
|
+
import { type ExtractionJob } from "./auto-memory-queue.js";
|
|
9
|
+
/**
|
|
10
|
+
* Fire-and-forget: enqueue a conversation turn for async memory extraction.
|
|
11
|
+
* Returns immediately — never blocks. Never throws.
|
|
12
|
+
*/
|
|
13
|
+
export declare function processConversationTurn(turn: string, context: Omit<ExtractionJob, "turn" | "timestamp">, source?: ExtractionJob["source"]): void;
|
|
14
|
+
/** Get current queue stats */
|
|
15
|
+
export declare function getAutoMemoryStats(): Readonly<import("./auto-memory-queue.js").QueueStats>;
|
|
16
|
+
/** Configure the auto-memory pipeline at runtime */
|
|
17
|
+
export declare function configureAutoMemory(config: Parameters<typeof providerRegistry.configure>[0]): void;
|
|
18
|
+
//# sourceMappingURL=auto-memory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auto-memory.d.ts","sourceRoot":"","sources":["../../src/lib/auto-memory.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAOH,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EAAmB,KAAK,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAgO7E;;;GAGG;AACH,wBAAgB,uBAAuB,CACrC,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,IAAI,CAAC,aAAa,EAAE,MAAM,GAAG,WAAW,CAAC,EAClD,MAAM,GAAE,aAAa,CAAC,QAAQ,CAAU,GACvC,IAAI,CAQN;AAED,8BAA8B;AAC9B,wBAAgB,kBAAkB,0DAEjC;AAED,oDAAoD;AACpD,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,UAAU,CAAC,OAAO,gBAAgB,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,GACvD,IAAI,CAEN"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Smart deduplication for auto-extracted memories.
|
|
3
|
+
* FTS5-based similarity check — no LLM needed, pure SQLite.
|
|
4
|
+
* Prevents memory bloat from repeated similar extractions.
|
|
5
|
+
*/
|
|
6
|
+
import type { MemoryFilter } from "../types/index.js";
|
|
7
|
+
export interface DedupConfig {
|
|
8
|
+
/** Jaccard similarity threshold 0-1. Above this = duplicate. Default: 0.8 */
|
|
9
|
+
threshold: number;
|
|
10
|
+
/** If near-duplicate found, keep the longer/more specific one. Default: true */
|
|
11
|
+
keepLonger: boolean;
|
|
12
|
+
}
|
|
13
|
+
export interface DedupStats {
|
|
14
|
+
checked: number;
|
|
15
|
+
skipped: number;
|
|
16
|
+
updated: number;
|
|
17
|
+
}
|
|
18
|
+
export declare function getDedupStats(): Readonly<DedupStats>;
|
|
19
|
+
export declare function resetDedupStats(): void;
|
|
20
|
+
/**
|
|
21
|
+
* Check if content is a near-duplicate of an existing memory.
|
|
22
|
+
* Returns: 'unique' | 'duplicate' | { updateId: string } (update existing with better content)
|
|
23
|
+
*/
|
|
24
|
+
export declare function checkDuplicate(content: string, filter: Pick<MemoryFilter, "agent_id" | "project_id" | "scope">, config?: DedupConfig): "unique" | "duplicate" | {
|
|
25
|
+
updateId: string;
|
|
26
|
+
existingContent: string;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Full dedup pipeline: check and optionally update existing memory.
|
|
30
|
+
* Returns: null = save as new | string = skipped/updated (reason)
|
|
31
|
+
*/
|
|
32
|
+
export declare function dedup(content: string, filter: Pick<MemoryFilter, "agent_id" | "project_id" | "scope">, config?: DedupConfig): "save" | "skip";
|
|
33
|
+
//# sourceMappingURL=dedup.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dedup.d.ts","sourceRoot":"","sources":["../../src/lib/dedup.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEtD,MAAM,WAAW,WAAW;IAC1B,6EAA6E;IAC7E,SAAS,EAAE,MAAM,CAAC;IAClB,gFAAgF;IAChF,UAAU,EAAE,OAAO,CAAC;CACrB;AAED,MAAM,WAAW,UAAU;IACzB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;CACjB;AASD,wBAAgB,aAAa,IAAI,QAAQ,CAAC,UAAU,CAAC,CAEpD;AAED,wBAAgB,eAAe,IAAI,IAAI,CAEtC;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAC5B,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,IAAI,CAAC,YAAY,EAAE,UAAU,GAAG,YAAY,GAAG,OAAO,CAAC,EAC/D,MAAM,GAAE,WAA4B,GACnC,QAAQ,GAAG,WAAW,GAAG;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,eAAe,EAAE,MAAM,CAAA;CAAE,CAwCxE;AAED;;;GAGG;AACH,wBAAgB,KAAK,CACnB,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,IAAI,CAAC,YAAY,EAAE,UAAU,GAAG,YAAY,GAAG,OAAO,CAAC,EAC/D,MAAM,GAAE,WAA4B,GACnC,MAAM,GAAG,MAAM,CAqBjB"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Focus mode — agents can "focus" on a project, which auto-scopes
|
|
3
|
+
* memory operations to that project's shared memories + their own private
|
|
4
|
+
* memories + all global memories.
|
|
5
|
+
*
|
|
6
|
+
* Priority for project_id resolution:
|
|
7
|
+
* 1. Per-call param (explicit override)
|
|
8
|
+
* 2. Session focus (in-memory Map, fastest)
|
|
9
|
+
* 3. DB active_project_id on agent record
|
|
10
|
+
* 4. No filter
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* Set focus for an agent. Persists to DB + sets in-memory session focus.
|
|
14
|
+
* Pass project_id=null to unfocus.
|
|
15
|
+
*/
|
|
16
|
+
export declare function setFocus(agentId: string, projectId: string | null): void;
|
|
17
|
+
/**
|
|
18
|
+
* Get the current focus project_id for an agent.
|
|
19
|
+
* Checks session cache first, then DB.
|
|
20
|
+
*/
|
|
21
|
+
export declare function getFocus(agentId: string): string | null;
|
|
22
|
+
/**
|
|
23
|
+
* Remove focus for an agent (sets to null).
|
|
24
|
+
*/
|
|
25
|
+
export declare function unfocus(agentId: string): void;
|
|
26
|
+
/**
|
|
27
|
+
* Resolve the effective project_id for a memory operation.
|
|
28
|
+
* Priority: explicit per-call param > session/DB focus > null
|
|
29
|
+
*/
|
|
30
|
+
export declare function resolveProjectId(agentId: string | undefined | null, explicitProjectId: string | undefined | null): string | null;
|
|
31
|
+
/**
|
|
32
|
+
* Build the scope filter for memory queries when an agent is focused.
|
|
33
|
+
*
|
|
34
|
+
* When focused on project P:
|
|
35
|
+
* - private memories of this agent (scope=private, agent_id=agentId)
|
|
36
|
+
* - shared memories of project P (scope=shared, project_id=P)
|
|
37
|
+
* - global memories (scope=global)
|
|
38
|
+
*
|
|
39
|
+
* When not focused: no automatic scope restriction (existing behavior).
|
|
40
|
+
*/
|
|
41
|
+
export interface FocusScopeFilter {
|
|
42
|
+
/** If set, apply this multi-scope filter instead of a single scope */
|
|
43
|
+
focusMode: true;
|
|
44
|
+
agentId: string;
|
|
45
|
+
projectId: string;
|
|
46
|
+
}
|
|
47
|
+
export declare function buildFocusFilter(agentId: string | undefined | null, explicitProjectId: string | undefined | null, explicitScope: string | undefined | null): FocusScopeFilter | null;
|
|
48
|
+
/**
|
|
49
|
+
* Apply focus filter to a SQL WHERE clause builder.
|
|
50
|
+
* Returns SQL fragment + params for the focused scope filter.
|
|
51
|
+
*
|
|
52
|
+
* Generates: (scope = 'global') OR (scope = 'private' AND agent_id = ?) OR (scope = 'shared' AND project_id = ?)
|
|
53
|
+
*/
|
|
54
|
+
export declare function focusFilterSQL(agentId: string, projectId: string): {
|
|
55
|
+
sql: string;
|
|
56
|
+
params: string[];
|
|
57
|
+
};
|
|
58
|
+
//# sourceMappingURL=focus.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"focus.d.ts","sourceRoot":"","sources":["../../src/lib/focus.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAOH;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,CAIxE;AAED;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAWvD;AAED;;GAEG;AACH,wBAAgB,OAAO,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAE7C;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,EAClC,iBAAiB,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,GAC3C,MAAM,GAAG,IAAI,CAUf;AAED;;;;;;;;;GASG;AACH,MAAM,WAAW,gBAAgB;IAC/B,sEAAsE;IACtE,SAAS,EAAE,IAAI,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,EAClC,iBAAiB,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,EAC5C,aAAa,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,GACvC,gBAAgB,GAAG,IAAI,CAazB;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAC5B,OAAO,EAAE,MAAM,EACf,SAAS,EAAE,MAAM,GAChB;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,EAAE,CAAA;CAAE,CAKnC"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OPE4-00111: Concurrent memory access coordination
|
|
3
|
+
*
|
|
4
|
+
* Uses the resource_locks table (Migration 8) to provide:
|
|
5
|
+
* - Advisory locks for read-heavy coordination
|
|
6
|
+
* - Exclusive locks to prevent simultaneous writes to the same key
|
|
7
|
+
*
|
|
8
|
+
* Design:
|
|
9
|
+
* - Reads: always parallel, no locking needed
|
|
10
|
+
* - Writes: agents SHOULD acquire an exclusive lock on the memory key before writing
|
|
11
|
+
* The lock resource_id uses format: "{scope}:{key}:{agent_id}:{project_id}"
|
|
12
|
+
* This prevents two agents overwriting the same shared memory simultaneously
|
|
13
|
+
* - Optimistic fallback: if lock can't be acquired, VersionConflictError from
|
|
14
|
+
* updateMemory() provides a second layer of protection
|
|
15
|
+
*/
|
|
16
|
+
import { Database } from "bun:sqlite";
|
|
17
|
+
import { type ResourceLock } from "../db/locks.js";
|
|
18
|
+
/**
|
|
19
|
+
* Compute the lock resource_id for a memory key.
|
|
20
|
+
* Scoped by scope + key + project so different projects don't block each other.
|
|
21
|
+
*/
|
|
22
|
+
export declare function memoryLockId(key: string, scope: string, projectId?: string | null): string;
|
|
23
|
+
/**
|
|
24
|
+
* Acquire an exclusive write lock on a memory key.
|
|
25
|
+
* Returns the lock if acquired, null if another agent is writing.
|
|
26
|
+
*/
|
|
27
|
+
export declare function acquireMemoryWriteLock(agentId: string, key: string, scope: string, projectId?: string | null, ttlSeconds?: number, db?: Database): ResourceLock | null;
|
|
28
|
+
/**
|
|
29
|
+
* Release a memory write lock.
|
|
30
|
+
*/
|
|
31
|
+
export declare function releaseMemoryWriteLock(lockId: string, agentId: string, db?: Database): boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Check if a memory key is currently write-locked.
|
|
34
|
+
* Returns the active lock or null.
|
|
35
|
+
*/
|
|
36
|
+
export declare function checkMemoryWriteLock(key: string, scope: string, projectId?: string | null, db?: Database): ResourceLock | null;
|
|
37
|
+
/**
|
|
38
|
+
* Execute a callback with an exclusive memory write lock.
|
|
39
|
+
* Throws if the lock cannot be acquired (another agent is writing).
|
|
40
|
+
* Automatically releases the lock after the callback completes.
|
|
41
|
+
*
|
|
42
|
+
* Usage:
|
|
43
|
+
* withMemoryLock(agentId, "my-key", "shared", projectId, () => {
|
|
44
|
+
* createMemory({ key: "my-key", ... });
|
|
45
|
+
* });
|
|
46
|
+
*/
|
|
47
|
+
export declare function withMemoryLock<T>(agentId: string, key: string, scope: string, projectId: string | null | undefined, fn: () => T, ttlSeconds?: number, db?: Database): T;
|
|
48
|
+
/**
|
|
49
|
+
* Error thrown when a memory write lock cannot be acquired.
|
|
50
|
+
*/
|
|
51
|
+
export declare class MemoryLockConflictError extends Error {
|
|
52
|
+
readonly conflict: true;
|
|
53
|
+
readonly key: string;
|
|
54
|
+
readonly scope: string;
|
|
55
|
+
readonly blocking_agent_id: string;
|
|
56
|
+
constructor(key: string, scope: string, blockingAgentId: string);
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=memory-lock.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory-lock.d.ts","sourceRoot":"","sources":["../../src/lib/memory-lock.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAuC,KAAK,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAKxF;;;GAGG;AACH,wBAAgB,YAAY,CAC1B,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,MAAM,EACb,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,GACxB,MAAM,CAER;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,CACpC,OAAO,EAAE,MAAM,EACf,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,MAAM,EACb,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,EACzB,UAAU,SAAmB,EAC7B,EAAE,CAAC,EAAE,QAAQ,GACZ,YAAY,GAAG,IAAI,CAGrB;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CACpC,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,MAAM,EACf,EAAE,CAAC,EAAE,QAAQ,GACZ,OAAO,CAGT;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAClC,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,MAAM,EACb,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,EACzB,EAAE,CAAC,EAAE,QAAQ,GACZ,YAAY,GAAG,IAAI,CAIrB;AAED;;;;;;;;;GASG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAC9B,OAAO,EAAE,MAAM,EACf,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,MAAM,EACb,SAAS,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EACpC,EAAE,EAAE,MAAM,CAAC,EACX,UAAU,SAAmB,EAC7B,EAAE,CAAC,EAAE,QAAQ,GACZ,CAAC,CAcH;AAED;;GAEG;AACH,qBAAa,uBAAwB,SAAQ,KAAK;IAChD,SAAgB,QAAQ,EAAG,IAAI,CAAU;IACzC,SAAgB,GAAG,EAAE,MAAM,CAAC;IAC5B,SAAgB,KAAK,EAAE,MAAM,CAAC;IAC9B,SAAgB,iBAAiB,EAAE,MAAM,CAAC;gBAE9B,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM;CAUhE"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Anthropic provider (DEFAULT).
|
|
3
|
+
* Default model: claude-haiku-4-5 — cheap, fast, good quality.
|
|
4
|
+
* Premium option: claude-sonnet-4-5.
|
|
5
|
+
* Never throws — returns [] / empty results on failure.
|
|
6
|
+
*/
|
|
7
|
+
import { BaseProvider, type ProviderConfig, type ProviderName, type MemoryExtractionContext, type ExtractedMemory, type EntityExtractionResult } from "./base.js";
|
|
8
|
+
export declare const ANTHROPIC_MODELS: {
|
|
9
|
+
readonly default: "claude-haiku-4-5";
|
|
10
|
+
readonly premium: "claude-sonnet-4-5";
|
|
11
|
+
};
|
|
12
|
+
export declare class AnthropicProvider extends BaseProvider {
|
|
13
|
+
readonly name: ProviderName;
|
|
14
|
+
private readonly baseUrl;
|
|
15
|
+
constructor(config?: Partial<ProviderConfig>);
|
|
16
|
+
extractMemories(text: string, context: MemoryExtractionContext): Promise<ExtractedMemory[]>;
|
|
17
|
+
extractEntities(text: string): Promise<EntityExtractionResult>;
|
|
18
|
+
scoreImportance(content: string, _context: MemoryExtractionContext): Promise<number>;
|
|
19
|
+
private callAPI;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=anthropic.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"anthropic.d.ts","sourceRoot":"","sources":["../../../src/lib/providers/anthropic.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EACL,YAAY,EACZ,KAAK,cAAc,EACnB,KAAK,YAAY,EACjB,KAAK,uBAAuB,EAC5B,KAAK,eAAe,EACpB,KAAK,sBAAsB,EAK5B,MAAM,WAAW,CAAC;AAEnB,eAAO,MAAM,gBAAgB;;;CAGnB,CAAC;AAEX,qBAAa,iBAAkB,SAAQ,YAAY;IACjD,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAe;IAC1C,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAkC;gBAE9C,MAAM,CAAC,EAAE,OAAO,CAAC,cAAc,CAAC;IAWtC,eAAe,CACnB,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,uBAAuB,GAC/B,OAAO,CAAC,eAAe,EAAE,CAAC;IAkBvB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,sBAAsB,CAAC;IAoB9D,eAAe,CACnB,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,uBAAuB,GAChC,OAAO,CAAC,MAAM,CAAC;YAaJ,OAAO;CAsCtB"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LLM Provider abstraction for auto-memory formation.
|
|
3
|
+
* Any LLM (Anthropic, OpenAI, Cerebras, Grok) implements LLMProvider.
|
|
4
|
+
* All methods return structured data — providers must output valid JSON.
|
|
5
|
+
*/
|
|
6
|
+
import type { MemoryCategory, MemoryScope } from "../../types/index.js";
|
|
7
|
+
export interface ProviderConfig {
|
|
8
|
+
apiKey: string;
|
|
9
|
+
model: string;
|
|
10
|
+
maxTokens?: number;
|
|
11
|
+
temperature?: number;
|
|
12
|
+
timeoutMs?: number;
|
|
13
|
+
}
|
|
14
|
+
export type ProviderName = "anthropic" | "openai" | "cerebras" | "grok";
|
|
15
|
+
export interface AutoMemoryConfig {
|
|
16
|
+
provider: ProviderName;
|
|
17
|
+
model?: string;
|
|
18
|
+
enabled: boolean;
|
|
19
|
+
minImportance: number;
|
|
20
|
+
autoEntityLink: boolean;
|
|
21
|
+
fallback?: ProviderName[];
|
|
22
|
+
}
|
|
23
|
+
export declare const DEFAULT_AUTO_MEMORY_CONFIG: AutoMemoryConfig;
|
|
24
|
+
export interface MemoryExtractionContext {
|
|
25
|
+
agentId?: string;
|
|
26
|
+
projectId?: string;
|
|
27
|
+
sessionId?: string;
|
|
28
|
+
/** Compact summary of existing memories to avoid duplicates */
|
|
29
|
+
existingMemoriesSummary?: string;
|
|
30
|
+
/** Working directory or project name for scope hints */
|
|
31
|
+
projectName?: string;
|
|
32
|
+
}
|
|
33
|
+
export interface ExtractedMemory {
|
|
34
|
+
content: string;
|
|
35
|
+
category: MemoryCategory;
|
|
36
|
+
importance: number;
|
|
37
|
+
tags: string[];
|
|
38
|
+
suggestedScope: MemoryScope;
|
|
39
|
+
/** Why this is worth remembering — used for dedup decisions */
|
|
40
|
+
reasoning?: string;
|
|
41
|
+
}
|
|
42
|
+
export interface ExtractedEntity {
|
|
43
|
+
name: string;
|
|
44
|
+
/** Maps to EntityType in knowledge graph */
|
|
45
|
+
type: "person" | "project" | "tool" | "concept" | "file" | "api" | "pattern" | "organization";
|
|
46
|
+
/** 0-1 confidence score */
|
|
47
|
+
confidence: number;
|
|
48
|
+
}
|
|
49
|
+
export interface ExtractedRelation {
|
|
50
|
+
from: string;
|
|
51
|
+
to: string;
|
|
52
|
+
type: "uses" | "knows" | "depends_on" | "created_by" | "related_to" | "contradicts" | "part_of" | "implements";
|
|
53
|
+
}
|
|
54
|
+
export interface EntityExtractionResult {
|
|
55
|
+
entities: ExtractedEntity[];
|
|
56
|
+
relations: ExtractedRelation[];
|
|
57
|
+
}
|
|
58
|
+
export interface LLMProvider {
|
|
59
|
+
readonly name: ProviderName;
|
|
60
|
+
readonly config: ProviderConfig;
|
|
61
|
+
/**
|
|
62
|
+
* Extract memories worth saving from a conversation turn or session chunk.
|
|
63
|
+
* Must return [] on failure — never throw.
|
|
64
|
+
*/
|
|
65
|
+
extractMemories(text: string, context: MemoryExtractionContext): Promise<ExtractedMemory[]>;
|
|
66
|
+
/**
|
|
67
|
+
* Extract entities and relations from text for knowledge graph linking.
|
|
68
|
+
* Must return empty arrays on failure — never throw.
|
|
69
|
+
*/
|
|
70
|
+
extractEntities(text: string): Promise<EntityExtractionResult>;
|
|
71
|
+
/**
|
|
72
|
+
* Score how important a memory is (0-10).
|
|
73
|
+
* Used when we already have the content but need a quality signal.
|
|
74
|
+
* Must return a number on failure — never throw.
|
|
75
|
+
*/
|
|
76
|
+
scoreImportance(content: string, context: MemoryExtractionContext): Promise<number>;
|
|
77
|
+
}
|
|
78
|
+
export declare abstract class BaseProvider implements LLMProvider {
|
|
79
|
+
abstract readonly name: ProviderName;
|
|
80
|
+
readonly config: ProviderConfig;
|
|
81
|
+
constructor(config: ProviderConfig);
|
|
82
|
+
abstract extractMemories(text: string, context: MemoryExtractionContext): Promise<ExtractedMemory[]>;
|
|
83
|
+
abstract extractEntities(text: string): Promise<EntityExtractionResult>;
|
|
84
|
+
abstract scoreImportance(content: string, context: MemoryExtractionContext): Promise<number>;
|
|
85
|
+
/** Parse JSON from LLM response, stripping markdown code fences if present */
|
|
86
|
+
protected parseJSON<T>(raw: string): T | null;
|
|
87
|
+
/** Clamp a number to 0-10 importance range */
|
|
88
|
+
protected clampImportance(value: unknown): number;
|
|
89
|
+
/** Validate and normalise a single extracted memory */
|
|
90
|
+
protected normaliseMemory(raw: unknown): ExtractedMemory | null;
|
|
91
|
+
}
|
|
92
|
+
export declare const MEMORY_EXTRACTION_SYSTEM_PROMPT = "You are a precise memory extraction engine for an AI agent.\nGiven text, extract facts worth remembering as structured JSON.\nFocus on: decisions made, preferences revealed, corrections, architectural choices, established facts, user preferences.\nIgnore: greetings, filler, questions without answers, temporary states.\nOutput ONLY a JSON array \u2014 no markdown, no explanation.";
|
|
93
|
+
export declare const MEMORY_EXTRACTION_USER_TEMPLATE: (text: string, context: MemoryExtractionContext) => string;
|
|
94
|
+
export declare const ENTITY_EXTRACTION_SYSTEM_PROMPT = "You are a knowledge graph entity extractor.\nGiven text, identify named entities and their relationships.\nOutput ONLY valid JSON \u2014 no markdown, no explanation.";
|
|
95
|
+
export declare const ENTITY_EXTRACTION_USER_TEMPLATE: (text: string) => string;
|
|
96
|
+
//# sourceMappingURL=base.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../../src/lib/providers/base.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAIxE,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,MAAM,YAAY,GAAG,WAAW,GAAG,QAAQ,GAAG,UAAU,GAAG,MAAM,CAAC;AAExE,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,EAAE,YAAY,CAAC;IACvB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,OAAO,CAAC;IACjB,aAAa,EAAE,MAAM,CAAC;IACtB,cAAc,EAAE,OAAO,CAAC;IACxB,QAAQ,CAAC,EAAE,YAAY,EAAE,CAAC;CAC3B;AAED,eAAO,MAAM,0BAA0B,EAAE,gBAOxC,CAAC;AAIF,MAAM,WAAW,uBAAuB;IACtC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,+DAA+D;IAC/D,uBAAuB,CAAC,EAAE,MAAM,CAAC;IACjC,wDAAwD;IACxD,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,cAAc,CAAC;IACzB,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,cAAc,EAAE,WAAW,CAAC;IAC5B,+DAA+D;IAC/D,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,4CAA4C;IAC5C,IAAI,EACA,QAAQ,GACR,SAAS,GACT,MAAM,GACN,SAAS,GACT,MAAM,GACN,KAAK,GACL,SAAS,GACT,cAAc,CAAC;IACnB,2BAA2B;IAC3B,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EACA,MAAM,GACN,OAAO,GACP,YAAY,GACZ,YAAY,GACZ,YAAY,GACZ,aAAa,GACb,SAAS,GACT,YAAY,CAAC;CAClB;AAED,MAAM,WAAW,sBAAsB;IACrC,QAAQ,EAAE,eAAe,EAAE,CAAC;IAC5B,SAAS,EAAE,iBAAiB,EAAE,CAAC;CAChC;AAID,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAC;IAC5B,QAAQ,CAAC,MAAM,EAAE,cAAc,CAAC;IAEhC;;;OAGG;IACH,eAAe,CACb,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,uBAAuB,GAC/B,OAAO,CAAC,eAAe,EAAE,CAAC,CAAC;IAE9B;;;OAGG;IACH,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,sBAAsB,CAAC,CAAC;IAE/D;;;;OAIG;IACH,eAAe,CACb,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,uBAAuB,GAC/B,OAAO,CAAC,MAAM,CAAC,CAAC;CACpB;AAID,8BAAsB,YAAa,YAAW,WAAW;IACvD,QAAQ,CAAC,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAC;IACrC,QAAQ,CAAC,MAAM,EAAE,cAAc,CAAC;gBAEpB,MAAM,EAAE,cAAc;IAIlC,QAAQ,CAAC,eAAe,CACtB,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,uBAAuB,GAC/B,OAAO,CAAC,eAAe,EAAE,CAAC;IAE7B,QAAQ,CAAC,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,sBAAsB,CAAC;IAEvE,QAAQ,CAAC,eAAe,CACtB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,uBAAuB,GAC/B,OAAO,CAAC,MAAM,CAAC;IAElB,8EAA8E;IAC9E,SAAS,CAAC,SAAS,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,GAAG,CAAC,GAAG,IAAI;IAa7C,8CAA8C;IAC9C,SAAS,CAAC,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM;IAMjD,uDAAuD;IACvD,SAAS,CAAC,eAAe,CAAC,GAAG,EAAE,OAAO,GAAG,eAAe,GAAG,IAAI;CA+BhE;AAID,eAAO,MAAM,+BAA+B,kYAIY,CAAC;AAEzD,eAAO,MAAM,+BAA+B,GAC1C,MAAM,MAAM,EACZ,SAAS,uBAAuB,WAgBS,CAAC;AAE5C,eAAO,MAAM,+BAA+B,0KAEU,CAAC;AAEvD,eAAO,MAAM,+BAA+B,GAAI,MAAM,MAAM,WAY1D,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cerebras provider — ultra-fast inference (~2000 tok/sec).
|
|
3
|
+
* OpenAI-compatible API.
|
|
4
|
+
* Default model: llama-3.3-70b.
|
|
5
|
+
* Ideal for real-time non-blocking extraction.
|
|
6
|
+
* Env var: CEREBRAS_API_KEY.
|
|
7
|
+
*/
|
|
8
|
+
import { OpenAICompatProvider } from "./openai-compat.js";
|
|
9
|
+
import type { ProviderConfig, ProviderName } from "./base.js";
|
|
10
|
+
export declare const CEREBRAS_MODELS: {
|
|
11
|
+
readonly default: "llama-3.3-70b";
|
|
12
|
+
readonly fast: "llama3.1-8b";
|
|
13
|
+
};
|
|
14
|
+
export declare class CerebrasProvider extends OpenAICompatProvider {
|
|
15
|
+
readonly name: ProviderName;
|
|
16
|
+
protected readonly baseUrl = "https://api.cerebras.ai/v1";
|
|
17
|
+
protected readonly authHeader = "Authorization";
|
|
18
|
+
constructor(config?: Partial<ProviderConfig>);
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=cerebras.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cerebras.d.ts","sourceRoot":"","sources":["../../../src/lib/providers/cerebras.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,KAAK,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAE9D,eAAO,MAAM,eAAe;;;CAGlB,CAAC;AAEX,qBAAa,gBAAiB,SAAQ,oBAAoB;IACxD,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAc;IACzC,SAAS,CAAC,QAAQ,CAAC,OAAO,gCAAgC;IAC1D,SAAS,CAAC,QAAQ,CAAC,UAAU,mBAAmB;gBAEpC,MAAM,CAAC,EAAE,OAAO,CAAC,cAAc,CAAC;CAS7C"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Grok/xAI provider.
|
|
3
|
+
* OpenAI-compatible API.
|
|
4
|
+
* Default model: grok-3-mini (cheap). Premium: grok-3.
|
|
5
|
+
* Env var: XAI_API_KEY.
|
|
6
|
+
*/
|
|
7
|
+
import { OpenAICompatProvider } from "./openai-compat.js";
|
|
8
|
+
import type { ProviderConfig, ProviderName } from "./base.js";
|
|
9
|
+
export declare const GROK_MODELS: {
|
|
10
|
+
readonly default: "grok-3-mini";
|
|
11
|
+
readonly premium: "grok-3";
|
|
12
|
+
};
|
|
13
|
+
export declare class GrokProvider extends OpenAICompatProvider {
|
|
14
|
+
readonly name: ProviderName;
|
|
15
|
+
protected readonly baseUrl = "https://api.x.ai/v1";
|
|
16
|
+
protected readonly authHeader = "Authorization";
|
|
17
|
+
constructor(config?: Partial<ProviderConfig>);
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=grok.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"grok.d.ts","sourceRoot":"","sources":["../../../src/lib/providers/grok.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,KAAK,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAE9D,eAAO,MAAM,WAAW;;;CAGd,CAAC;AAEX,qBAAa,YAAa,SAAQ,oBAAoB;IACpD,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAU;IACrC,SAAS,CAAC,QAAQ,CAAC,OAAO,yBAAyB;IACnD,SAAS,CAAC,QAAQ,CAAC,UAAU,mBAAmB;gBAEpC,MAAM,CAAC,EAAE,OAAO,CAAC,cAAc,CAAC;CAS7C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/providers/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,WAAW,CAAC;AAC1B,cAAc,eAAe,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared base for all OpenAI-compatible providers.
|
|
3
|
+
* Used by: OpenAI, Cerebras, Grok/xAI.
|
|
4
|
+
* Handles: API calls, exponential backoff on 429, shared JSON parsing.
|
|
5
|
+
*/
|
|
6
|
+
import { BaseProvider, type ProviderConfig, type MemoryExtractionContext, type ExtractedMemory, type EntityExtractionResult } from "./base.js";
|
|
7
|
+
export declare abstract class OpenAICompatProvider extends BaseProvider {
|
|
8
|
+
protected abstract readonly baseUrl: string;
|
|
9
|
+
protected abstract readonly authHeader: string;
|
|
10
|
+
constructor(config: ProviderConfig);
|
|
11
|
+
extractMemories(text: string, context: MemoryExtractionContext): Promise<ExtractedMemory[]>;
|
|
12
|
+
extractEntities(text: string): Promise<EntityExtractionResult>;
|
|
13
|
+
scoreImportance(content: string, _context: MemoryExtractionContext): Promise<number>;
|
|
14
|
+
/** Call with exponential backoff on 429 (rate limit), max 3 retries */
|
|
15
|
+
private callWithRetry;
|
|
16
|
+
private callAPI;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=openai-compat.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openai-compat.d.ts","sourceRoot":"","sources":["../../../src/lib/providers/openai-compat.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EACL,YAAY,EACZ,KAAK,cAAc,EACnB,KAAK,uBAAuB,EAC5B,KAAK,eAAe,EACpB,KAAK,sBAAsB,EAK5B,MAAM,WAAW,CAAC;AAEnB,8BAAsB,oBAAqB,SAAQ,YAAY;IAC7D,SAAS,CAAC,QAAQ,CAAC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IAC5C,SAAS,CAAC,QAAQ,CAAC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;gBAEnC,MAAM,EAAE,cAAc;IAI5B,eAAe,CACnB,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,uBAAuB,GAC/B,OAAO,CAAC,eAAe,EAAE,CAAC;IAkBvB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,sBAAsB,CAAC;IAoB9D,eAAe,CACnB,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,uBAAuB,GAChC,OAAO,CAAC,MAAM,CAAC;IAalB,uEAAuE;YACzD,aAAa;YAsBb,OAAO;CA0CtB"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OpenAI provider.
|
|
3
|
+
* Default model: gpt-4.1-nano (ultra cheap, fast).
|
|
4
|
+
* Premium: gpt-4.1-mini, gpt-4.1.
|
|
5
|
+
* Env var: OPENAI_API_KEY.
|
|
6
|
+
*/
|
|
7
|
+
import { OpenAICompatProvider } from "./openai-compat.js";
|
|
8
|
+
import type { ProviderConfig, ProviderName } from "./base.js";
|
|
9
|
+
export declare const OPENAI_MODELS: {
|
|
10
|
+
readonly default: "gpt-4.1-nano";
|
|
11
|
+
readonly mini: "gpt-4.1-mini";
|
|
12
|
+
readonly full: "gpt-4.1";
|
|
13
|
+
};
|
|
14
|
+
export declare class OpenAIProvider extends OpenAICompatProvider {
|
|
15
|
+
readonly name: ProviderName;
|
|
16
|
+
protected readonly baseUrl = "https://api.openai.com/v1";
|
|
17
|
+
protected readonly authHeader = "Authorization";
|
|
18
|
+
constructor(config?: Partial<ProviderConfig>);
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=openai.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openai.d.ts","sourceRoot":"","sources":["../../../src/lib/providers/openai.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,KAAK,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAE9D,eAAO,MAAM,aAAa;;;;CAIhB,CAAC;AAEX,qBAAa,cAAe,SAAQ,oBAAoB;IACtD,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAY;IACvC,SAAS,CAAC,QAAQ,CAAC,OAAO,+BAA+B;IACzD,SAAS,CAAC,QAAQ,CAAC,UAAU,mBAAmB;gBAEpC,MAAM,CAAC,EAAE,OAAO,CAAC,cAAc,CAAC;CAS7C"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Provider registry — resolves API keys, manages fallback chain,
|
|
3
|
+
* health checks. Works with zero config (just needs one env var set).
|
|
4
|
+
* Default: Anthropic Haiku → Cerebras → OpenAI.
|
|
5
|
+
*/
|
|
6
|
+
import { type AutoMemoryConfig, type LLMProvider, type ProviderName } from "./base.js";
|
|
7
|
+
declare class ProviderRegistry {
|
|
8
|
+
private config;
|
|
9
|
+
private _instances;
|
|
10
|
+
/** Update runtime config without restart */
|
|
11
|
+
configure(partial: Partial<AutoMemoryConfig>): void;
|
|
12
|
+
getConfig(): Readonly<AutoMemoryConfig>;
|
|
13
|
+
/** Get primary provider, or null if no API key available */
|
|
14
|
+
getPrimary(): LLMProvider | null;
|
|
15
|
+
/** Get fallback chain — all available providers excluding primary */
|
|
16
|
+
getFallbacks(): LLMProvider[];
|
|
17
|
+
/**
|
|
18
|
+
* Get the best available provider.
|
|
19
|
+
* Returns primary if available, otherwise first available fallback.
|
|
20
|
+
* Returns null only if no providers have API keys configured.
|
|
21
|
+
*/
|
|
22
|
+
getAvailable(): LLMProvider | null;
|
|
23
|
+
/**
|
|
24
|
+
* Get a specific provider by name.
|
|
25
|
+
* Returns null if no API key is configured for that provider.
|
|
26
|
+
*/
|
|
27
|
+
getProvider(name: ProviderName): LLMProvider | null;
|
|
28
|
+
/** Check which providers have API keys configured */
|
|
29
|
+
health(): Record<ProviderName, {
|
|
30
|
+
available: boolean;
|
|
31
|
+
model: string;
|
|
32
|
+
}>;
|
|
33
|
+
private createProvider;
|
|
34
|
+
}
|
|
35
|
+
/** Singleton registry — shared across the whole process */
|
|
36
|
+
export declare const providerRegistry: ProviderRegistry;
|
|
37
|
+
export {};
|
|
38
|
+
//# sourceMappingURL=registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../../src/lib/providers/registry.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAMH,OAAO,EAEL,KAAK,gBAAgB,EACrB,KAAK,WAAW,EAChB,KAAK,YAAY,EAClB,MAAM,WAAW,CAAC;AAInB,cAAM,gBAAgB;IACpB,OAAO,CAAC,MAAM,CAAuD;IACrE,OAAO,CAAC,UAAU,CAAwC;IAE1D,4CAA4C;IAC5C,SAAS,CAAC,OAAO,EAAE,OAAO,CAAC,gBAAgB,CAAC,GAAG,IAAI;IAMnD,SAAS,IAAI,QAAQ,CAAC,gBAAgB,CAAC;IAIvC,4DAA4D;IAC5D,UAAU,IAAI,WAAW,GAAG,IAAI;IAIhC,qEAAqE;IACrE,YAAY,IAAI,WAAW,EAAE;IAQ7B;;;;OAIG;IACH,YAAY,IAAI,WAAW,GAAG,IAAI;IAOlC;;;OAGG;IACH,WAAW,CAAC,IAAI,EAAE,YAAY,GAAG,WAAW,GAAG,IAAI;IAcnD,qDAAqD;IACrD,MAAM,IAAI,MAAM,CAAC,YAAY,EAAE;QAAE,SAAS,EAAE,OAAO,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;IAarE,OAAO,CAAC,cAAc;CAiBvB;AAED,2DAA2D;AAC3D,eAAO,MAAM,gBAAgB,kBAAyB,CAAC"}
|
package/dist/lib/search.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"search.d.ts","sourceRoot":"","sources":["../../src/lib/search.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAyB,MAAM,YAAY,CAAC;AAC7D,OAAO,KAAK,EAAU,YAAY,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAyoBlF;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAC5B,KAAK,EAAE,MAAM,EACb,MAAM,CAAC,EAAE,YAAY,EACrB,EAAE,CAAC,EAAE,QAAQ,GACZ,kBAAkB,EAAE,
|
|
1
|
+
{"version":3,"file":"search.d.ts","sourceRoot":"","sources":["../../src/lib/search.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAyB,MAAM,YAAY,CAAC;AAC7D,OAAO,KAAK,EAAU,YAAY,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAyoBlF;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAC5B,KAAK,EAAE,MAAM,EACb,MAAM,CAAC,EAAE,YAAY,EACrB,EAAE,CAAC,EAAE,QAAQ,GACZ,kBAAkB,EAAE,CAiEtB;AAMD,wBAAgB,cAAc,CAC5B,KAAK,EAAE,MAAM,EACb,WAAW,EAAE,MAAM,EACnB,OAAO,CAAC,EAAE,MAAM,EAChB,SAAS,CAAC,EAAE,MAAM,EAClB,EAAE,CAAC,EAAE,QAAQ,GACZ,IAAI,CAWN;AAED,wBAAgB,gBAAgB,CAC9B,KAAK,GAAE,MAAW,EAClB,SAAS,CAAC,EAAE,MAAM,EAClB,EAAE,CAAC,EAAE,QAAQ,GACZ;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,YAAY,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,EAAE,CAU/D;AAED,wBAAgB,kBAAkB,CAChC,KAAK,GAAE,MAAW,EAClB,SAAS,CAAC,EAAE,MAAM,EAClB,EAAE,CAAC,EAAE,QAAQ,GACZ;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,EAAE,CAUpC"}
|