@theokit/sdk-memory 0.1.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/CHANGELOG.md +112 -0
- package/LICENSE +201 -0
- package/README.md +86 -0
- package/dist/in-memory-provider.d.ts +38 -0
- package/dist/in-memory-provider.d.ts.map +1 -0
- package/dist/index.cjs +2585 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +40 -0
- package/dist/index.d.ts +40 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2500 -0
- package/dist/index.js.map +1 -0
- package/dist/internal/active-memory-cache.d.ts +49 -0
- package/dist/internal/active-memory-cache.d.ts.map +1 -0
- package/dist/internal/active-memory-types.d.ts +30 -0
- package/dist/internal/active-memory-types.d.ts.map +1 -0
- package/dist/internal/active-memory.d.ts +108 -0
- package/dist/internal/active-memory.d.ts.map +1 -0
- package/dist/internal/adapter-catalog.d.ts +82 -0
- package/dist/internal/adapter-catalog.d.ts.map +1 -0
- package/dist/internal/adapter-http-error.d.ts +63 -0
- package/dist/internal/adapter-http-error.d.ts.map +1 -0
- package/dist/internal/batch-encoder.d.ts +30 -0
- package/dist/internal/batch-encoder.d.ts.map +1 -0
- package/dist/internal/chunk-markdown.d.ts +66 -0
- package/dist/internal/chunk-markdown.d.ts.map +1 -0
- package/dist/internal/circuit-breaker.d.ts +36 -0
- package/dist/internal/circuit-breaker.d.ts.map +1 -0
- package/dist/internal/composite-scorer.d.ts +19 -0
- package/dist/internal/composite-scorer.d.ts.map +1 -0
- package/dist/internal/deepinfra-embedding.d.ts +25 -0
- package/dist/internal/deepinfra-embedding.d.ts.map +1 -0
- package/dist/internal/dreaming-diary.d.ts +38 -0
- package/dist/internal/dreaming-diary.d.ts.map +1 -0
- package/dist/internal/dreaming-phases.d.ts +43 -0
- package/dist/internal/dreaming-phases.d.ts.map +1 -0
- package/dist/internal/dreaming-run.d.ts +49 -0
- package/dist/internal/dreaming-run.d.ts.map +1 -0
- package/dist/internal/embedding-adapter.d.ts +57 -0
- package/dist/internal/embedding-adapter.d.ts.map +1 -0
- package/dist/internal/embedding-cache.d.ts +16 -0
- package/dist/internal/embedding-cache.d.ts.map +1 -0
- package/dist/internal/index-db.d.ts +50 -0
- package/dist/internal/index-db.d.ts.map +1 -0
- package/dist/internal/index-manager-contract.d.ts +70 -0
- package/dist/internal/index-manager-contract.d.ts.map +1 -0
- package/dist/internal/index-manager-dispatch.d.ts +36 -0
- package/dist/internal/index-manager-dispatch.d.ts.map +1 -0
- package/dist/internal/index-manager.d.ts +94 -0
- package/dist/internal/index-manager.d.ts.map +1 -0
- package/dist/internal/index-schema.d.ts +35 -0
- package/dist/internal/index-schema.d.ts.map +1 -0
- package/dist/internal/lance-index.d.ts +70 -0
- package/dist/internal/lance-index.d.ts.map +1 -0
- package/dist/internal/lance-memory-adapter.d.ts +102 -0
- package/dist/internal/lance-memory-adapter.d.ts.map +1 -0
- package/dist/internal/markdown-store.d.ts +17 -0
- package/dist/internal/markdown-store.d.ts.map +1 -0
- package/dist/internal/memory-index.d.ts +68 -0
- package/dist/internal/memory-index.d.ts.map +1 -0
- package/dist/internal/memory-scope.d.ts +21 -0
- package/dist/internal/memory-scope.d.ts.map +1 -0
- package/dist/internal/memory-types.d.ts +95 -0
- package/dist/internal/memory-types.d.ts.map +1 -0
- package/dist/internal/migrate-sqlite-to-lance.d.ts +49 -0
- package/dist/internal/migrate-sqlite-to-lance.d.ts.map +1 -0
- package/dist/internal/migration.d.ts +10 -0
- package/dist/internal/migration.d.ts.map +1 -0
- package/dist/internal/mistral-embedding.d.ts +23 -0
- package/dist/internal/mistral-embedding.d.ts.map +1 -0
- package/dist/internal/ollama-embedding.d.ts +48 -0
- package/dist/internal/ollama-embedding.d.ts.map +1 -0
- package/dist/internal/openai-compatible.d.ts +24 -0
- package/dist/internal/openai-compatible.d.ts.map +1 -0
- package/dist/internal/openai-embedding.d.ts +34 -0
- package/dist/internal/openai-embedding.d.ts.map +1 -0
- package/dist/internal/openrouter-embedding.d.ts +25 -0
- package/dist/internal/openrouter-embedding.d.ts.map +1 -0
- package/dist/internal/query-analyzer.d.ts +16 -0
- package/dist/internal/query-analyzer.d.ts.map +1 -0
- package/dist/internal/reader.d.ts +64 -0
- package/dist/internal/reader.d.ts.map +1 -0
- package/dist/internal/session-loader.d.ts +25 -0
- package/dist/internal/session-loader.d.ts.map +1 -0
- package/dist/internal/session-summary-writer.d.ts +43 -0
- package/dist/internal/session-summary-writer.d.ts.map +1 -0
- package/dist/internal/sqlite-vec-loader.d.ts +62 -0
- package/dist/internal/sqlite-vec-loader.d.ts.map +1 -0
- package/dist/internal/tools.d.ts +44 -0
- package/dist/internal/tools.d.ts.map +1 -0
- package/dist/internal/transcript-store.d.ts +36 -0
- package/dist/internal/transcript-store.d.ts.map +1 -0
- package/dist/internal/vec-index.d.ts +81 -0
- package/dist/internal/vec-index.d.ts.map +1 -0
- package/dist/internal/voyage-embedding.d.ts +23 -0
- package/dist/internal/voyage-embedding.d.ts.map +1 -0
- package/dist/internal/wiki-loader.d.ts +24 -0
- package/dist/internal/wiki-loader.d.ts.map +1 -0
- package/package.json +74 -0
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* **Iter 66 rollup-plugin-dts workaround** (mirrors iter 48/53/55 pattern).
|
|
3
|
+
* The canonical sdk-core copy imports `MemoryDb` from `./index-db.js`
|
|
4
|
+
* (sibling). In sdk-memory the same interface lives in sibling
|
|
5
|
+
* `./index-db.js` (moved iter 65) but rollup-plugin-dts treeshakes
|
|
6
|
+
* it out of the bundled .d.ts emit because no PUBLIC type reaches it
|
|
7
|
+
* transitively yet — sqlite-vec-loader's signatures would be the
|
|
8
|
+
* first consumer BUT rollup-dts resolves the import BEFORE the
|
|
9
|
+
* loader's exports are bundled into the public emit. Result:
|
|
10
|
+
* "MemoryDb is not exported by src/internal/index-db.ts" build error.
|
|
11
|
+
*
|
|
12
|
+
* Fix: inline a structural mirror of the minimal MemoryDb shape that
|
|
13
|
+
* sqlite-vec-loader actually needs (just `prepare` for the version
|
|
14
|
+
* probe; everything else delegated via the loader's untyped
|
|
15
|
+
* dynamic-import call to sqlite-vec's native `load`). Mirror is
|
|
16
|
+
* narrower than the canonical contract on purpose — this file's
|
|
17
|
+
* runtime never touches exec/close/pragma/loadExtension directly.
|
|
18
|
+
* When a future move turns MemoryDb into a publicly-reachable type
|
|
19
|
+
* through a different path (e.g. vec-index.ts surfacing the interface
|
|
20
|
+
* from its own typed signatures), this mirror MUST be deleted +
|
|
21
|
+
* the canonical import restored.
|
|
22
|
+
*
|
|
23
|
+
* @internal
|
|
24
|
+
*/
|
|
25
|
+
interface MemoryDb {
|
|
26
|
+
exec(sql: string): void;
|
|
27
|
+
prepare(sql: string): {
|
|
28
|
+
run(...args: unknown[]): {
|
|
29
|
+
changes: number;
|
|
30
|
+
lastInsertRowid: number | bigint;
|
|
31
|
+
};
|
|
32
|
+
get(...args: unknown[]): Record<string, unknown> | undefined;
|
|
33
|
+
all(...args: unknown[]): Array<Record<string, unknown>>;
|
|
34
|
+
};
|
|
35
|
+
pragma(statement: string, options?: {
|
|
36
|
+
simple?: boolean;
|
|
37
|
+
}): unknown;
|
|
38
|
+
close(): void;
|
|
39
|
+
loadExtension(path: string): void;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Load the `sqlite-vec` extension into an opened SQLite connection.
|
|
43
|
+
*
|
|
44
|
+
* Wraps the native `load(db)` call from the `sqlite-vec` npm package with a
|
|
45
|
+
* typed error path (EC-8 of the edge-case review) so callers see a
|
|
46
|
+
* `sqlite_vec_unavailable` ConfigurationError instead of a raw native error.
|
|
47
|
+
*
|
|
48
|
+
* Iter 66 (Stage 3 source-move #23): hybrid copy from sdk-core's
|
|
49
|
+
* `internal/memory/sqlite-vec-loader.ts`. sdk-core retains its copy
|
|
50
|
+
* for v1.x sqlite-vec back-compat; sdk-memory ships the canonical
|
|
51
|
+
* copy that future `vec-index.ts` move will compose with as a
|
|
52
|
+
* sibling. Dependency chain (all resolved):
|
|
53
|
+
* - `@theokit/sdk/errors` for `ConfigurationError` (public)
|
|
54
|
+
* - sibling `./index-db.js` for `MemoryDb` (moved iter 65)
|
|
55
|
+
*
|
|
56
|
+
* @internal
|
|
57
|
+
*/
|
|
58
|
+
export declare function loadSqliteVecExtension(db: MemoryDb): Promise<void>;
|
|
59
|
+
/** Check whether sqlite-vec is loaded by running a tiny version query. */
|
|
60
|
+
export declare function isSqliteVecLoaded(db: MemoryDb): boolean;
|
|
61
|
+
export {};
|
|
62
|
+
//# sourceMappingURL=sqlite-vec-loader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sqlite-vec-loader.d.ts","sourceRoot":"","sources":["../../src/internal/sqlite-vec-loader.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,UAAU,QAAQ;IAChB,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG;QACpB,GAAG,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG;YAAE,OAAO,EAAE,MAAM,CAAC;YAAC,eAAe,EAAE,MAAM,GAAG,MAAM,CAAA;SAAE,CAAC;QAC/E,GAAG,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAAC;QAC7D,GAAG,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;KACzD,CAAC;IACF,MAAM,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,OAAO,CAAC;IACnE,KAAK,IAAI,IAAI,CAAC;IACd,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;CACnC;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAsB,sBAAsB,CAAC,EAAE,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAexE;AAED,0EAA0E;AAC1E,wBAAgB,iBAAiB,CAAC,EAAE,EAAE,QAAQ,GAAG,OAAO,CAOvD"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { MemoryIndex } from "./memory-index.js";
|
|
2
|
+
/**
|
|
3
|
+
* Memory tools (`memory_search` + `memory_get`) — ADR D5 of
|
|
4
|
+
* memory-system-openclaw-parity. Tool schemas mirror OpenClaw
|
|
5
|
+
* (`referencia/openclaw/extensions/memory-core/src/tools.ts:228-475`).
|
|
6
|
+
*
|
|
7
|
+
* Each tool is exposed as a `MemoryTool` (name + description + JSON schema +
|
|
8
|
+
* async execute). The agent-loop integration wires them via the existing
|
|
9
|
+
* `ResolvedTool` interface in `tool-dispatch.ts`.
|
|
10
|
+
*
|
|
11
|
+
* Iter 64 (Stage 3 source-move #21): hybrid copy from sdk-core's
|
|
12
|
+
* `internal/memory/tools.ts`. sdk-core retains its copy for v1.x
|
|
13
|
+
* memory-tools back-compat; sdk-memory ships the canonical copy.
|
|
14
|
+
* Dependency chain (all resolved):
|
|
15
|
+
* - `@theokit/sdk/errors` for `ConfigurationError` (public)
|
|
16
|
+
* - sibling `./index-manager-contract.js` for `MemorySearchHit`
|
|
17
|
+
* (moved iter 47 — note: sdk-core copy imports from
|
|
18
|
+
* `./index-manager.js`; sdk-memory uses the contract leaf
|
|
19
|
+
* directly since the canonical type lives there)
|
|
20
|
+
* - sibling `./memory-index.js` for `MemoryIndex` (moved iter 50)
|
|
21
|
+
* - sibling `./markdown-store.js` for `memoryDir` (moved iter 56)
|
|
22
|
+
* - sibling `./reader.js` for `readMemoryFileBounded` (moved iter 55)
|
|
23
|
+
*
|
|
24
|
+
* @internal
|
|
25
|
+
*/
|
|
26
|
+
export interface MemoryToolJson {
|
|
27
|
+
name: string;
|
|
28
|
+
description: string;
|
|
29
|
+
inputSchema: Record<string, unknown>;
|
|
30
|
+
}
|
|
31
|
+
export interface MemoryTool extends MemoryToolJson {
|
|
32
|
+
execute(input: Record<string, unknown>): Promise<string>;
|
|
33
|
+
}
|
|
34
|
+
export interface MemorySearchToolOptions {
|
|
35
|
+
index: MemoryIndex;
|
|
36
|
+
/** Cap on the JSON response size (EC-10 of edge-case review). Default 16384. */
|
|
37
|
+
maxTotalChars?: number;
|
|
38
|
+
}
|
|
39
|
+
export declare function createMemorySearchTool(opts: MemorySearchToolOptions): MemoryTool;
|
|
40
|
+
export interface MemoryGetToolOptions {
|
|
41
|
+
cwd: string;
|
|
42
|
+
}
|
|
43
|
+
export declare function createMemoryGetTool(opts: MemoryGetToolOptions): MemoryTool;
|
|
44
|
+
//# sourceMappingURL=tools.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../../src/internal/tools.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAGrD;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACtC;AAED,MAAM,WAAW,UAAW,SAAQ,cAAc;IAChD,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;CAC1D;AAiCD,MAAM,WAAW,uBAAuB;IACtC,KAAK,EAAE,WAAW,CAAC;IACnB,gFAAgF;IAChF,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,uBAAuB,GAAG,UAAU,CAqBhF;AAED,MAAM,WAAW,oBAAoB;IACnC,GAAG,EAAE,MAAM,CAAC;CACb;AAED,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,oBAAoB,GAAG,UAAU,CA4B1E"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Optional on-disk persistence for Active Memory recall transcripts (ADR D6).
|
|
3
|
+
*
|
|
4
|
+
* Writes one JSON file per run under
|
|
5
|
+
* `.theokit/memory/transcripts/active-memory/<runId>.json` when the agent
|
|
6
|
+
* passes `persistTranscripts: true`. Failures are swallowed with a stderr
|
|
7
|
+
* warning so transcript IO never crashes the agent run.
|
|
8
|
+
*
|
|
9
|
+
* Iter 58 (Stage 3 source-move #15): hybrid copy from sdk-core's
|
|
10
|
+
* `internal/memory/storage/transcript-store.ts`. sdk-core retains its
|
|
11
|
+
* copy for v1.x active-memory back-compat; sdk-memory ships the
|
|
12
|
+
* canonical copy that the future `active-memory.ts` move will compose
|
|
13
|
+
* with as a sibling. Dependency chain (both resolved):
|
|
14
|
+
* - `@theokit/sdk/internal/persistence` for `atomicWriteJson`
|
|
15
|
+
* - sibling `./markdown-store.js` for `memoryDir` (moved iter 56)
|
|
16
|
+
*
|
|
17
|
+
* @internal
|
|
18
|
+
*/
|
|
19
|
+
export interface ActiveMemoryTranscript {
|
|
20
|
+
runId: string;
|
|
21
|
+
startedAtMs: number;
|
|
22
|
+
userText: string;
|
|
23
|
+
queryMode: string;
|
|
24
|
+
status: string;
|
|
25
|
+
durationMs: number;
|
|
26
|
+
summary: string | undefined;
|
|
27
|
+
hits: ReadonlyArray<{
|
|
28
|
+
path: string;
|
|
29
|
+
startLine: number;
|
|
30
|
+
endLine: number;
|
|
31
|
+
score: number;
|
|
32
|
+
snippet: string;
|
|
33
|
+
}>;
|
|
34
|
+
}
|
|
35
|
+
export declare function persistActiveMemoryTranscript(cwd: string, transcript: ActiveMemoryTranscript): Promise<void>;
|
|
36
|
+
//# sourceMappingURL=transcript-store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transcript-store.d.ts","sourceRoot":"","sources":["../../src/internal/transcript-store.ts"],"names":[],"mappings":"AAMA;;;;;;;;;;;;;;;;;GAiBG;AAEH,MAAM,WAAW,sBAAsB;IACrC,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5B,IAAI,EAAE,aAAa,CAAC;QAClB,IAAI,EAAE,MAAM,CAAC;QACb,SAAS,EAAE,MAAM,CAAC;QAClB,OAAO,EAAE,MAAM,CAAC;QAChB,KAAK,EAAE,MAAM,CAAC;QACd,OAAO,EAAE,MAAM,CAAC;KACjB,CAAC,CAAC;CACJ;AAED,wBAAsB,6BAA6B,CACjD,GAAG,EAAE,MAAM,EACX,UAAU,EAAE,sBAAsB,GACjC,OAAO,CAAC,IAAI,CAAC,CAWf"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import type { EmbeddingRuntime } from "./embedding-adapter.js";
|
|
2
|
+
/**
|
|
3
|
+
* **Iter 67 rollup-plugin-dts workaround** (mirrors iter 48/53/55/66 pattern).
|
|
4
|
+
* The canonical sdk-core copy imports `MemoryDb` from sibling
|
|
5
|
+
* `./index-db.js`. In sdk-memory the same interface lives in sibling
|
|
6
|
+
* `./index-db.js` (moved iter 65) but rollup-dts treeshakes it
|
|
7
|
+
* out of the bundled .d.ts emit because no PUBLIC type reaches it
|
|
8
|
+
* transitively yet. Same pattern as iter 66 with sqlite-vec-loader.
|
|
9
|
+
*
|
|
10
|
+
* Fix: inline a structural mirror of the minimal MemoryDb shape this
|
|
11
|
+
* file actually needs (exec + prepare for SQL emits, plus pragma /
|
|
12
|
+
* close / loadExtension on the canonical surface to stay shape-compatible
|
|
13
|
+
* with consumers passing the real MemoryDb). When a future move
|
|
14
|
+
* surfaces MemoryDb through a different publicly-reachable path,
|
|
15
|
+
* this mirror MUST be deleted + the canonical import restored.
|
|
16
|
+
*
|
|
17
|
+
* @internal
|
|
18
|
+
*/
|
|
19
|
+
interface MemoryDb {
|
|
20
|
+
exec(sql: string): void;
|
|
21
|
+
prepare(sql: string): {
|
|
22
|
+
run(...args: unknown[]): {
|
|
23
|
+
changes: number;
|
|
24
|
+
lastInsertRowid: number | bigint;
|
|
25
|
+
};
|
|
26
|
+
get(...args: unknown[]): Record<string, unknown> | undefined;
|
|
27
|
+
all(...args: unknown[]): Array<Record<string, unknown>>;
|
|
28
|
+
};
|
|
29
|
+
pragma(statement: string, options?: {
|
|
30
|
+
simple?: boolean;
|
|
31
|
+
}): unknown;
|
|
32
|
+
close(): void;
|
|
33
|
+
loadExtension(path: string): void;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Vector index helpers (ADR D2 + D4 of memory-system-openclaw-parity).
|
|
37
|
+
*
|
|
38
|
+
* Embeddings live in `embeddings(chunk_id, vec)` — a `vec0` virtual table
|
|
39
|
+
* provided by the sqlite-vec extension. Embedding identity (providerId +
|
|
40
|
+
* model + dimension) lives in the `meta` table; mismatches force a full
|
|
41
|
+
* re-embed sweep (EC-1).
|
|
42
|
+
*
|
|
43
|
+
* Iter 67 (Stage 3 source-move #24): hybrid copy from sdk-core's
|
|
44
|
+
* `internal/memory/vec-index.ts`. sdk-core retains its copy for v1.x
|
|
45
|
+
* sqlite-vec back-compat; sdk-memory ships the canonical copy that
|
|
46
|
+
* future `index-manager.ts` move will compose with as a sibling.
|
|
47
|
+
* Dependency chain (both sibling, both moved):
|
|
48
|
+
* - `EmbeddingRuntime` from `./embedding-adapter.js` (moved iter 45)
|
|
49
|
+
* - `MemoryDb` from `./index-db.js` (moved iter 65)
|
|
50
|
+
*
|
|
51
|
+
* @internal
|
|
52
|
+
*/
|
|
53
|
+
export declare const META_KEY_PROVIDER_ID = "embedding.providerId";
|
|
54
|
+
export declare const META_KEY_MODEL = "embedding.model";
|
|
55
|
+
export declare const META_KEY_DIMENSION = "embedding.dimension";
|
|
56
|
+
export interface EmbeddingIdentity {
|
|
57
|
+
providerId: string;
|
|
58
|
+
model: string;
|
|
59
|
+
dimension: number;
|
|
60
|
+
}
|
|
61
|
+
export declare function readEmbeddingIdentity(db: MemoryDb): EmbeddingIdentity | undefined;
|
|
62
|
+
export declare function writeEmbeddingIdentity(db: MemoryDb, identity: EmbeddingIdentity): void;
|
|
63
|
+
export declare function identityMatches(a: EmbeddingIdentity, b: EmbeddingIdentity): boolean;
|
|
64
|
+
export declare function dropVectorIndex(db: MemoryDb): void;
|
|
65
|
+
export declare function createVectorIndex(db: MemoryDb, dimension: number): void;
|
|
66
|
+
/** Pack a Float32Array into a Buffer suitable for sqlite-vec BLOB binding. */
|
|
67
|
+
export declare function packVector(vec: ReadonlyArray<number>): Buffer;
|
|
68
|
+
export declare function upsertEmbedding(db: MemoryDb, chunkId: number, vec: ReadonlyArray<number>): void;
|
|
69
|
+
export interface VectorHitRow {
|
|
70
|
+
chunk_id: number;
|
|
71
|
+
distance: number;
|
|
72
|
+
}
|
|
73
|
+
export declare function vectorSearch(db: MemoryDb, query: ReadonlyArray<number>, k: number): VectorHitRow[];
|
|
74
|
+
export interface EmbedAllArgs {
|
|
75
|
+
db: MemoryDb;
|
|
76
|
+
runtime: EmbeddingRuntime;
|
|
77
|
+
}
|
|
78
|
+
/** Embed every chunk that doesn't yet have a vector. */
|
|
79
|
+
export declare function embedMissingChunks(args: EmbedAllArgs): Promise<number>;
|
|
80
|
+
export {};
|
|
81
|
+
//# sourceMappingURL=vec-index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vec-index.d.ts","sourceRoot":"","sources":["../../src/internal/vec-index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAE/D;;;;;;;;;;;;;;;;GAgBG;AACH,UAAU,QAAQ;IAChB,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG;QACpB,GAAG,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG;YAAE,OAAO,EAAE,MAAM,CAAC;YAAC,eAAe,EAAE,MAAM,GAAG,MAAM,CAAA;SAAE,CAAC;QAC/E,GAAG,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAAC;QAC7D,GAAG,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;KACzD,CAAC;IACF,MAAM,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,OAAO,CAAC;IACnE,KAAK,IAAI,IAAI,CAAC;IACd,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;CACnC;AAED;;;;;;;;;;;;;;;;;GAiBG;AAEH,eAAO,MAAM,oBAAoB,yBAAyB,CAAC;AAC3D,eAAO,MAAM,cAAc,oBAAoB,CAAC;AAChD,eAAO,MAAM,kBAAkB,wBAAwB,CAAC;AAExD,MAAM,WAAW,iBAAiB;IAChC,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,wBAAgB,qBAAqB,CAAC,EAAE,EAAE,QAAQ,GAAG,iBAAiB,GAAG,SAAS,CAYjF;AAED,wBAAgB,sBAAsB,CAAC,EAAE,EAAE,QAAQ,EAAE,QAAQ,EAAE,iBAAiB,GAAG,IAAI,CAOtF;AAED,wBAAgB,eAAe,CAAC,CAAC,EAAE,iBAAiB,EAAE,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAEnF;AAED,wBAAgB,eAAe,CAAC,EAAE,EAAE,QAAQ,GAAG,IAAI,CAElD;AAED,wBAAgB,iBAAiB,CAAC,EAAE,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,GAAG,IAAI,CAKvE;AAED,8EAA8E;AAC9E,wBAAgB,UAAU,CAAC,GAAG,EAAE,aAAa,CAAC,MAAM,CAAC,GAAG,MAAM,CAI7D;AAED,wBAAgB,eAAe,CAAC,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,aAAa,CAAC,MAAM,CAAC,GAAG,IAAI,CAO/F;AAED,MAAM,WAAW,YAAY;IAC3B,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,wBAAgB,YAAY,CAC1B,EAAE,EAAE,QAAQ,EACZ,KAAK,EAAE,aAAa,CAAC,MAAM,CAAC,EAC5B,CAAC,EAAE,MAAM,GACR,YAAY,EAAE,CAWhB;AAED,MAAM,WAAW,YAAY;IAC3B,EAAE,EAAE,QAAQ,CAAC;IACb,OAAO,EAAE,gBAAgB,CAAC;CAC3B;AAED,wDAAwD;AACxD,wBAAsB,kBAAkB,CAAC,IAAI,EAAE,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC,CAmB5E"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { createOpenAiCompatibleRuntime } from "./openai-compatible.js";
|
|
2
|
+
/**
|
|
3
|
+
* Voyage AI embedding adapter — `POST /v1/embeddings` at
|
|
4
|
+
* `https://api.voyageai.com` with the OpenAI-compatible `{ model, input }`
|
|
5
|
+
* request shape. Free tier (200M tokens/month) covers most SDK use.
|
|
6
|
+
*
|
|
7
|
+
* Honors `VOYAGE_API_KEY` and `VOYAGE_API_BASE_URL`.
|
|
8
|
+
*
|
|
9
|
+
* Iter 74 (Stage 3 source-move #34): hybrid copy from sdk-core's
|
|
10
|
+
* `internal/memory/adapters/voyage-embedding.ts`.
|
|
11
|
+
*
|
|
12
|
+
* @internal
|
|
13
|
+
*/
|
|
14
|
+
export declare const DEFAULT_VOYAGE_EMBEDDING_MODEL = "voyage-3-lite";
|
|
15
|
+
export declare const voyageMemoryEmbeddingProviderAdapter: {
|
|
16
|
+
id: string;
|
|
17
|
+
defaultModel: string;
|
|
18
|
+
transport: "remote";
|
|
19
|
+
authProviderId: string;
|
|
20
|
+
autoSelectPriority: number;
|
|
21
|
+
create: (options: Parameters<typeof createOpenAiCompatibleRuntime>[1]) => Promise<import("./embedding-adapter.js").EmbeddingRuntime>;
|
|
22
|
+
};
|
|
23
|
+
//# sourceMappingURL=voyage-embedding.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"voyage-embedding.d.ts","sourceRoot":"","sources":["../../src/internal/voyage-embedding.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,6BAA6B,EAAE,MAAM,wBAAwB,CAAC;AAIvE;;;;;;;;;;;GAWG;AAEH,eAAO,MAAM,8BAA8B,kBAAkB,CAAC;AAU9D,eAAO,MAAM,oCAAoC;;;;;;sBAM7B,UAAU,CAAC,OAAO,6BAA6B,CAAC,CAAC,CAAC,CAAC;CAYtE,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wiki supplement discovery (ADR Phase 10 of memory-system-openclaw-parity).
|
|
3
|
+
*
|
|
4
|
+
* Wiki files live under `.theokit/memory/wiki/*.md`. They are READ-ONLY —
|
|
5
|
+
* the SDK never writes here. Each indexed chunk carries `source="wiki"` so
|
|
6
|
+
* `memory_search { corpus: "wiki" }` and `corpus: "all"` can scope hits.
|
|
7
|
+
*
|
|
8
|
+
* Iter 57 (Stage 3 source-move #14): hybrid copy from sdk-core's
|
|
9
|
+
* `internal/memory/storage/wiki-loader.ts`. sdk-core retains its copy
|
|
10
|
+
* for v1.x back-compat; sdk-memory ships the canonical copy that
|
|
11
|
+
* future `index-db` + `index-manager` moves will compose with
|
|
12
|
+
* (memory_search corpus filter scopes wiki hits via this loader's
|
|
13
|
+
* relPath convention). `memoryDir` comes from sibling
|
|
14
|
+
* `./markdown-store.js` (moved iter 56).
|
|
15
|
+
*
|
|
16
|
+
* @internal
|
|
17
|
+
*/
|
|
18
|
+
export interface WikiFile {
|
|
19
|
+
absolutePath: string;
|
|
20
|
+
relPath: string;
|
|
21
|
+
}
|
|
22
|
+
export declare function wikiDir(cwd: string): string;
|
|
23
|
+
export declare function discoverWikiFiles(cwd: string): Promise<WikiFile[]>;
|
|
24
|
+
//# sourceMappingURL=wiki-loader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wiki-loader.d.ts","sourceRoot":"","sources":["../../src/internal/wiki-loader.ts"],"names":[],"mappings":"AAKA;;;;;;;;;;;;;;;;GAgBG;AAEH,MAAM,WAAW,QAAQ;IACvB,YAAY,EAAE,MAAM,CAAC;IACrB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,wBAAgB,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAE3C;AAED,wBAAsB,iBAAiB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC,CAkBxE"}
|
package/package.json
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@theokit/sdk-memory",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Memory subsystem for @theokit/sdk — MemoryProvider impls (markdown file store today; LanceDB + embeddings + circuit breaker next iters). Consumes the kernel-facing port from sdk-core.",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"homepage": "https://github.com/usetheo/theokit-sdk#readme",
|
|
7
|
+
"bugs": "https://github.com/usetheo/theokit-sdk/issues",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/usetheo/theokit-sdk.git",
|
|
11
|
+
"directory": "packages/sdk-memory"
|
|
12
|
+
},
|
|
13
|
+
"type": "module",
|
|
14
|
+
"sideEffects": false,
|
|
15
|
+
"engines": {
|
|
16
|
+
"node": ">=22.12.0"
|
|
17
|
+
},
|
|
18
|
+
"main": "./dist/index.cjs",
|
|
19
|
+
"module": "./dist/index.js",
|
|
20
|
+
"types": "./dist/index.d.ts",
|
|
21
|
+
"exports": {
|
|
22
|
+
".": {
|
|
23
|
+
"import": {
|
|
24
|
+
"types": "./dist/index.d.ts",
|
|
25
|
+
"default": "./dist/index.js"
|
|
26
|
+
},
|
|
27
|
+
"require": {
|
|
28
|
+
"types": "./dist/index.d.cts",
|
|
29
|
+
"default": "./dist/index.cjs"
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
"./package.json": "./package.json"
|
|
33
|
+
},
|
|
34
|
+
"files": [
|
|
35
|
+
"dist",
|
|
36
|
+
"README.md",
|
|
37
|
+
"CHANGELOG.md",
|
|
38
|
+
"LICENSE"
|
|
39
|
+
],
|
|
40
|
+
"scripts": {
|
|
41
|
+
"build": "tsup && tsc -p tsconfig.build.json && cp dist/index.d.ts dist/index.d.cts",
|
|
42
|
+
"test": "vitest run",
|
|
43
|
+
"typecheck": "tsc --noEmit"
|
|
44
|
+
},
|
|
45
|
+
"peerDependencies": {
|
|
46
|
+
"@theokit/sdk": ">=1.7.0",
|
|
47
|
+
"better-sqlite3": "^12.0.0",
|
|
48
|
+
"sqlite-vec": ">=0.1.0",
|
|
49
|
+
"@lancedb/lancedb": ">=0.20.0"
|
|
50
|
+
},
|
|
51
|
+
"peerDependenciesMeta": {
|
|
52
|
+
"better-sqlite3": {
|
|
53
|
+
"optional": true
|
|
54
|
+
},
|
|
55
|
+
"sqlite-vec": {
|
|
56
|
+
"optional": true
|
|
57
|
+
},
|
|
58
|
+
"@lancedb/lancedb": {
|
|
59
|
+
"optional": true
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
"devDependencies": {
|
|
63
|
+
"tsup": "^8.3.5",
|
|
64
|
+
"typescript": "^5.7.2",
|
|
65
|
+
"vitest": "^4.1.8",
|
|
66
|
+
"@theokit/sdk": "workspace:*",
|
|
67
|
+
"@types/better-sqlite3": "^7.6.13",
|
|
68
|
+
"better-sqlite3": "^12.10.0",
|
|
69
|
+
"sqlite-vec": "^0.1.6"
|
|
70
|
+
},
|
|
71
|
+
"publishConfig": {
|
|
72
|
+
"access": "public"
|
|
73
|
+
}
|
|
74
|
+
}
|