@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,49 @@
|
|
|
1
|
+
import type { ActiveMemoryResult } from "./active-memory-types.js";
|
|
2
|
+
/**
|
|
3
|
+
* TTL-bounded cache for `runActiveMemory` results. Keyed by
|
|
4
|
+
* `sha256(userText + queryMode)` so two identical sends within `cacheTtlMs`
|
|
5
|
+
* (default 15s, matching OpenClaw's `DEFAULT_CACHE_TTL_MS`) share a single
|
|
6
|
+
* search.
|
|
7
|
+
*
|
|
8
|
+
* Bounded size; oldest entries evicted first when capacity is exceeded.
|
|
9
|
+
*
|
|
10
|
+
* Iter 51 (Stage 3 source-move #8): hybrid copy from sdk-core's
|
|
11
|
+
* `internal/memory/active-memory-cache.ts`. sdk-core retains its copy
|
|
12
|
+
* for v1.x active-memory back-compat; sdk-memory ships the canonical
|
|
13
|
+
* copy that the future `active-memory.ts` move will target as a
|
|
14
|
+
* sibling. Depends only on `node:crypto` + `./active-memory-types.js`
|
|
15
|
+
* (moved iter 48), so no further dependency chain is required.
|
|
16
|
+
*
|
|
17
|
+
* @internal
|
|
18
|
+
*/
|
|
19
|
+
export interface ActiveMemoryCacheOptions {
|
|
20
|
+
ttlMs?: number;
|
|
21
|
+
capacity?: number;
|
|
22
|
+
now?: () => number;
|
|
23
|
+
}
|
|
24
|
+
export declare class ActiveMemoryCache {
|
|
25
|
+
private readonly opts;
|
|
26
|
+
private readonly map;
|
|
27
|
+
constructor(opts?: ActiveMemoryCacheOptions);
|
|
28
|
+
get(userText: string, queryMode: string, tenantCtx?: TenantContext): ActiveMemoryResult | undefined;
|
|
29
|
+
set(userText: string, queryMode: string, result: ActiveMemoryResult, tenantCtx?: TenantContext): void;
|
|
30
|
+
size(): number;
|
|
31
|
+
private now;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* T4.9 — Tenant isolation context for cache key derivation.
|
|
35
|
+
* Pre-T4.9 the key was `sha256(queryMode + userText)` — two users
|
|
36
|
+
* sharing a process with the same query got each other's results.
|
|
37
|
+
* CRITICAL cross-tenant data leak (DR4 finding #9).
|
|
38
|
+
*
|
|
39
|
+
* Synced from sdk-core's `internal/memory/active-memory-cache.ts`
|
|
40
|
+
* per ADR 0002 Stage 4 routing byte-equivalence invariant (iter 112).
|
|
41
|
+
*
|
|
42
|
+
* @internal
|
|
43
|
+
*/
|
|
44
|
+
export interface TenantContext {
|
|
45
|
+
namespace?: string;
|
|
46
|
+
userId?: string;
|
|
47
|
+
scope?: string;
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=active-memory-cache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"active-memory-cache.d.ts","sourceRoot":"","sources":["../../src/internal/active-memory-cache.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAEnE;;;;;;;;;;;;;;;;GAgBG;AAEH,MAAM,WAAW,wBAAwB;IACvC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,GAAG,CAAC,EAAE,MAAM,MAAM,CAAC;CACpB;AAUD,qBAAa,iBAAiB;IAGhB,OAAO,CAAC,QAAQ,CAAC,IAAI;IAFjC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAiC;gBAExB,IAAI,GAAE,wBAA6B;IAEhE,GAAG,CACD,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,EACjB,SAAS,CAAC,EAAE,aAAa,GACxB,kBAAkB,GAAG,SAAS;IAcjC,GAAG,CACD,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,kBAAkB,EAC1B,SAAS,CAAC,EAAE,aAAa,GACxB,IAAI;IAYP,IAAI,IAAI,MAAM;IAId,OAAO,CAAC,GAAG;CAGZ;AAED;;;;;;;;;;GAUG;AACH,MAAM,WAAW,aAAa;IAC5B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type-leaf — shared types between `active-memory.ts` and
|
|
3
|
+
* `active-memory-cache.ts`. Extracted to break LOW type-only cycle #10
|
|
4
|
+
* (audit `architecture-output/final_report.md`) per plan
|
|
5
|
+
* arch-review-fixes-2026-06-06 § Phase 4 / T4.1 (D438).
|
|
6
|
+
*
|
|
7
|
+
* Internal — `active-memory.ts` re-exports these for in-tree consumers
|
|
8
|
+
* that historically imported from there.
|
|
9
|
+
*
|
|
10
|
+
* **Iter 48 → iter 50 evolution:** the original `MemorySearchHit`
|
|
11
|
+
* import from `./index-manager-contract.js` was temporarily inlined
|
|
12
|
+
* as a duplicate interface because rollup-plugin-dts treeshook it out
|
|
13
|
+
* of sdk-memory's dist (no reachable consumer yet). Iter 50 moved
|
|
14
|
+
* `memory-index.ts` into sdk-memory and the barrel now publicly
|
|
15
|
+
* re-exports `MemorySearchHit` — creating the reachable consumer —
|
|
16
|
+
* so this file restores the canonical import and the inline mirror
|
|
17
|
+
* is gone. Single source of truth is back.
|
|
18
|
+
*
|
|
19
|
+
* @internal
|
|
20
|
+
*/
|
|
21
|
+
import type { MemorySearchHit } from "./index-manager-contract.js";
|
|
22
|
+
export type ActiveMemoryQueryMode = "message" | "recent" | "full";
|
|
23
|
+
export type ActiveMemoryStatus = "ok" | "timeout" | "skipped" | "no-recall" | "error";
|
|
24
|
+
export interface ActiveMemoryResult {
|
|
25
|
+
summary: string | undefined;
|
|
26
|
+
durationMs: number;
|
|
27
|
+
status: ActiveMemoryStatus;
|
|
28
|
+
hits: ReadonlyArray<MemorySearchHit>;
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=active-memory-types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"active-memory-types.d.ts","sourceRoot":"","sources":["../../src/internal/active-memory-types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAEnE,MAAM,MAAM,qBAAqB,GAAG,SAAS,GAAG,QAAQ,GAAG,MAAM,CAAC;AAElE,MAAM,MAAM,kBAAkB,GAAG,IAAI,GAAG,SAAS,GAAG,SAAS,GAAG,WAAW,GAAG,OAAO,CAAC;AAEtF,MAAM,WAAW,kBAAkB;IACjC,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5B,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,kBAAkB,CAAC;IAC3B,IAAI,EAAE,aAAa,CAAC,eAAe,CAAC,CAAC;CACtC"}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Active Memory blocking recall (ADR D6 of memory-system-openclaw-parity).
|
|
3
|
+
*
|
|
4
|
+
* Runs BEFORE `agent.send()` assembles the system prompt. Issues a direct
|
|
5
|
+
* call to `IndexManager.search` with the user message (and optional recent
|
|
6
|
+
* turns per `queryMode`).
|
|
7
|
+
*
|
|
8
|
+
* Returns a `summary` string capped at `maxSummaryChars` (default 220 to
|
|
9
|
+
* match OpenClaw's `DEFAULT_MAX_SUMMARY_CHARS`) which the system-prompt
|
|
10
|
+
* pipeline prepends as a `<active-memory>` block (priority 5).
|
|
11
|
+
*
|
|
12
|
+
* Iter 75 (Stage 3 source-move #38, FINAL move): hybrid copy from
|
|
13
|
+
* sdk-core's `internal/memory/active-memory.ts`. sdk-core retains its
|
|
14
|
+
* copy as the v1.x runtime that `Memory` class delegates to;
|
|
15
|
+
* sdk-memory ships the canonical copy that future Stage 4 port-based
|
|
16
|
+
* composition will consume.
|
|
17
|
+
*
|
|
18
|
+
* **CLOSES the Stage 3 source-move stage in sdk-memory.** Every
|
|
19
|
+
* memory-related concept under sdk-core's internal/memory/ is now
|
|
20
|
+
* canonical in @theokit/sdk-memory (38 source files moved across
|
|
21
|
+
* iter 44-75; 2 inlined adapters added: adapter-http-error iter 73
|
|
22
|
+
* + adapter-catalog renamed iter 74).
|
|
23
|
+
*
|
|
24
|
+
* **Cross-package telemetry contract:** sdk-core's `internal/telemetry/`
|
|
25
|
+
* is not part of the public surface. sdk-memory inlines minimal
|
|
26
|
+
* structural mirrors of `OTelSpan` + `TelemetryHandle` here AND the
|
|
27
|
+
* 2 constant strings the file uses (`memory.recall` span name +
|
|
28
|
+
* `theokit_memory_recall_duration_ms` histogram name). The runtime
|
|
29
|
+
* still receives + emits the canonical types via consumer call sites
|
|
30
|
+
* — the structural mirrors only satisfy this file's local type
|
|
31
|
+
* checking. When sdk-core exposes telemetry types publicly, these
|
|
32
|
+
* mirrors MUST be replaced with the canonical imports.
|
|
33
|
+
*
|
|
34
|
+
* @internal
|
|
35
|
+
*/
|
|
36
|
+
import type { ActiveMemoryCache } from "./active-memory-cache.js";
|
|
37
|
+
import type { ActiveMemoryQueryMode, ActiveMemoryResult, ActiveMemoryStatus } from "./active-memory-types.js";
|
|
38
|
+
import type { CircuitBreaker } from "./circuit-breaker.js";
|
|
39
|
+
import type { MemoryIndex } from "./memory-index.js";
|
|
40
|
+
export type { ActiveMemoryQueryMode, ActiveMemoryResult, ActiveMemoryStatus };
|
|
41
|
+
interface OTelSpan {
|
|
42
|
+
setAttribute(key: string, value: string | number | boolean): void;
|
|
43
|
+
setAttributes(attrs: Record<string, string | number | boolean>): void;
|
|
44
|
+
addEvent(name: string, attrs?: Record<string, string | number | boolean>): void;
|
|
45
|
+
setStatus(status: {
|
|
46
|
+
code: number;
|
|
47
|
+
message?: string;
|
|
48
|
+
}): void;
|
|
49
|
+
recordException(exception: unknown): void;
|
|
50
|
+
end(): void;
|
|
51
|
+
spanContext(): {
|
|
52
|
+
traceId: string;
|
|
53
|
+
spanId: string;
|
|
54
|
+
};
|
|
55
|
+
isRecording(): boolean;
|
|
56
|
+
}
|
|
57
|
+
interface TelemetryHandle {
|
|
58
|
+
startSpan(name: string, attrs?: Record<string, string | number | boolean>): OTelSpan;
|
|
59
|
+
recordHistogram(name: string, value: number, attrs?: Record<string, string | number | boolean>): void;
|
|
60
|
+
}
|
|
61
|
+
export interface ActiveMemoryOptions {
|
|
62
|
+
/** Whether active recall is enabled. Default `false`. */
|
|
63
|
+
enabled?: boolean;
|
|
64
|
+
/** Query construction strategy. Default `"recent"`. */
|
|
65
|
+
queryMode?: ActiveMemoryQueryMode;
|
|
66
|
+
/** Hard timeout in ms. Default `15000`. */
|
|
67
|
+
timeoutMs?: number;
|
|
68
|
+
/** Max chars in the summary. Default `220`. */
|
|
69
|
+
maxSummaryChars?: number;
|
|
70
|
+
/** Number of recent user turns to include in `queryMode === "recent"`. Default `2`. */
|
|
71
|
+
recentUserTurns?: number;
|
|
72
|
+
}
|
|
73
|
+
export interface RunActiveMemoryArgs {
|
|
74
|
+
userText: string;
|
|
75
|
+
priorMessages: ReadonlyArray<{
|
|
76
|
+
role: "user" | "assistant";
|
|
77
|
+
text: string;
|
|
78
|
+
}>;
|
|
79
|
+
index: MemoryIndex | undefined;
|
|
80
|
+
options: ActiveMemoryOptions;
|
|
81
|
+
/** Per-agent circuit breaker (Phase 8). */
|
|
82
|
+
breaker?: CircuitBreaker;
|
|
83
|
+
/** Per-agent result cache (Phase 8). */
|
|
84
|
+
cache?: ActiveMemoryCache;
|
|
85
|
+
/** Workspace root for transcript persistence. */
|
|
86
|
+
cwd?: string;
|
|
87
|
+
/** When true, write transcript JSON under .theokit/memory/transcripts/active-memory/. */
|
|
88
|
+
persistTranscripts?: boolean;
|
|
89
|
+
/** Stable key the breaker + cache key by (default `default`). */
|
|
90
|
+
agentKey?: string;
|
|
91
|
+
/** Run id for transcript file naming. */
|
|
92
|
+
runId?: string;
|
|
93
|
+
/**
|
|
94
|
+
* T0.1 — optional telemetry handle. When provided AND telemetry is enabled,
|
|
95
|
+
* `memory.recall` span is emitted with `{ userId, namespace, scope, queryMode,
|
|
96
|
+
* hits, status }` attrs and `theokit_memory_recall_duration_ms` histogram is
|
|
97
|
+
* recorded with the same dimension keys.
|
|
98
|
+
*/
|
|
99
|
+
telemetry?: TelemetryHandle;
|
|
100
|
+
/** User id surfaced as a memory.recall span attr for cross-tenant tracing. */
|
|
101
|
+
userId?: string;
|
|
102
|
+
/** Memory namespace (e.g. `default`, `<orgId>`) for span/histogram dimensions. */
|
|
103
|
+
namespace?: string;
|
|
104
|
+
/** Memory scope (`session` / `user` / `global`) for span/histogram dimensions. */
|
|
105
|
+
scope?: string;
|
|
106
|
+
}
|
|
107
|
+
export declare function runActiveMemory(args: RunActiveMemoryArgs): Promise<ActiveMemoryResult>;
|
|
108
|
+
//# sourceMappingURL=active-memory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"active-memory.d.ts","sourceRoot":"","sources":["../../src/internal/active-memory.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Memory embedding adapter catalog, indexed by provider id.
|
|
3
|
+
*
|
|
4
|
+
* Only adapters with full, tested implementations are exposed. The
|
|
5
|
+
* `openrouter` provider proxies through OpenRouter to whichever embedding
|
|
6
|
+
* model the caller selects via `model` (e.g.
|
|
7
|
+
* `"openai/text-embedding-3-small"`, `"mistralai/mistral-embed"`).
|
|
8
|
+
*
|
|
9
|
+
* Locked by ADR D11: `openai`, `mistral`, `openrouter`, `voyage`, `deepinfra`
|
|
10
|
+
* ship in v1.0. ADR D183: `ollama` added — first `transport: "local"`
|
|
11
|
+
* adapter, enables 100%-local RAG (no remote API key needed).
|
|
12
|
+
* `lmstudio`, `google`, `bedrock` are deferred to v1.1.
|
|
13
|
+
*
|
|
14
|
+
* Iter 74 (Stage 3 source-move #37): hybrid copy from sdk-core's
|
|
15
|
+
* `internal/memory/adapters/catalog.ts`. Filename renamed to
|
|
16
|
+
* `adapter-catalog.ts` in sdk-memory to disambiguate from the broader
|
|
17
|
+
* "catalog" notion at the package barrel level.
|
|
18
|
+
*
|
|
19
|
+
* **CLOSES the embedding-adapter cluster in sdk-memory.** All 7
|
|
20
|
+
* provider adapters + the shared OpenAI-compatible runtime + the
|
|
21
|
+
* inlined HTTP error mapper are now canonical:
|
|
22
|
+
* - iter 45: embedding-adapter (types)
|
|
23
|
+
* - iter 46: embedding-cache (LRU)
|
|
24
|
+
* - iter 73: openai-compatible (shared factory) + adapter-http-error
|
|
25
|
+
* (inlined mapper)
|
|
26
|
+
* - iter 74: openai-embedding + mistral-embedding + deepinfra-embedding
|
|
27
|
+
* + voyage-embedding + openrouter-embedding + ollama-embedding +
|
|
28
|
+
* adapter-catalog (THIS)
|
|
29
|
+
*
|
|
30
|
+
* @internal
|
|
31
|
+
*/
|
|
32
|
+
export declare const MEMORY_EMBEDDING_ADAPTERS: {
|
|
33
|
+
openai: {
|
|
34
|
+
id: string;
|
|
35
|
+
defaultModel: string;
|
|
36
|
+
transport: "remote";
|
|
37
|
+
authProviderId: string;
|
|
38
|
+
autoSelectPriority: number;
|
|
39
|
+
create: (options: Parameters<typeof import("./openai-compatible.js").createOpenAiCompatibleRuntime>[1]) => Promise<import("./embedding-adapter.js").EmbeddingRuntime>;
|
|
40
|
+
};
|
|
41
|
+
mistral: {
|
|
42
|
+
id: string;
|
|
43
|
+
defaultModel: string;
|
|
44
|
+
transport: "remote";
|
|
45
|
+
authProviderId: string;
|
|
46
|
+
autoSelectPriority: number;
|
|
47
|
+
create: (options: Parameters<typeof import("./openai-compatible.js").createOpenAiCompatibleRuntime>[1]) => Promise<import("./embedding-adapter.js").EmbeddingRuntime>;
|
|
48
|
+
};
|
|
49
|
+
openrouter: {
|
|
50
|
+
id: string;
|
|
51
|
+
defaultModel: string;
|
|
52
|
+
transport: "remote";
|
|
53
|
+
authProviderId: string;
|
|
54
|
+
autoSelectPriority: number;
|
|
55
|
+
create: (options: Parameters<typeof import("./openai-compatible.js").createOpenAiCompatibleRuntime>[1]) => Promise<import("./embedding-adapter.js").EmbeddingRuntime>;
|
|
56
|
+
};
|
|
57
|
+
voyage: {
|
|
58
|
+
id: string;
|
|
59
|
+
defaultModel: string;
|
|
60
|
+
transport: "remote";
|
|
61
|
+
authProviderId: string;
|
|
62
|
+
autoSelectPriority: number;
|
|
63
|
+
create: (options: Parameters<typeof import("./openai-compatible.js").createOpenAiCompatibleRuntime>[1]) => Promise<import("./embedding-adapter.js").EmbeddingRuntime>;
|
|
64
|
+
};
|
|
65
|
+
deepinfra: {
|
|
66
|
+
id: string;
|
|
67
|
+
defaultModel: string;
|
|
68
|
+
transport: "remote";
|
|
69
|
+
authProviderId: string;
|
|
70
|
+
autoSelectPriority: number;
|
|
71
|
+
create: (options: Parameters<typeof import("./openai-compatible.js").createOpenAiCompatibleRuntime>[1]) => Promise<import("./embedding-adapter.js").EmbeddingRuntime>;
|
|
72
|
+
};
|
|
73
|
+
ollama: {
|
|
74
|
+
id: string;
|
|
75
|
+
defaultModel: string;
|
|
76
|
+
transport: "local";
|
|
77
|
+
authProviderId: string;
|
|
78
|
+
autoSelectPriority: number;
|
|
79
|
+
create: (options: Parameters<typeof import("./openai-compatible.js").createOpenAiCompatibleRuntime>[1]) => Promise<import("./embedding-adapter.js").EmbeddingRuntime>;
|
|
80
|
+
};
|
|
81
|
+
};
|
|
82
|
+
//# sourceMappingURL=adapter-catalog.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter-catalog.d.ts","sourceRoot":"","sources":["../../src/internal/adapter-catalog.ts"],"names":[],"mappings":"AAYA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,eAAO,MAAM,yBAAyB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAOrC,CAAC"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OpenAI-compatible HTTP error mapper (ADR D67) — sdk-memory inlined copy.
|
|
3
|
+
*
|
|
4
|
+
* Translates OpenAI-shaped API error responses (covers OpenAI, OpenRouter,
|
|
5
|
+
* DeepSeek, Together, Mistral, Voyage, DeepInfra, etc.) into typed
|
|
6
|
+
* `TheokitAgentError` subclasses with full `ErrorMetadata`.
|
|
7
|
+
*
|
|
8
|
+
* Body inspection: looks at `body.error.code` / `body.error.type` to detect
|
|
9
|
+
* `context_too_long`, `content_filtered`, `model_unavailable` semantics.
|
|
10
|
+
* Falls back to status-based mapping when body doesn't expose `.error`
|
|
11
|
+
* (e.g., HTML server error page, DeepInfra's `{message: "..."}` shape).
|
|
12
|
+
*
|
|
13
|
+
* Never throws — caller is already in an error path.
|
|
14
|
+
*
|
|
15
|
+
* Iter 73 (Stage 3 source-move #30): inlined adaptation of sdk-core's
|
|
16
|
+
* `internal/errors/mappers/openai-compatible.ts` + `shared.ts`. sdk-core's
|
|
17
|
+
* mapper is internal — not part of the public errors surface — so sdk-memory
|
|
18
|
+
* carries its own minimal copy here. Behavior MUST stay byte-equivalent
|
|
19
|
+
* with sdk-core's so consumers consuming hits via either package surface
|
|
20
|
+
* see identical error shape.
|
|
21
|
+
*
|
|
22
|
+
* The 4 helpers (`parseRetryAfter`, `truncateRaw`, `buildErrorMetadata`,
|
|
23
|
+
* `mapOpenAICompatibleError`) are intentionally co-located in this single
|
|
24
|
+
* file so all 8 embedding adapter moves (catalog + 7 providers) share one
|
|
25
|
+
* import target.
|
|
26
|
+
*
|
|
27
|
+
* @internal
|
|
28
|
+
*/
|
|
29
|
+
import { type ErrorCode, type ErrorMetadata, type TheokitAgentError } from "@theokit/sdk/errors";
|
|
30
|
+
/**
|
|
31
|
+
* Parse `retry-after` header in numeric-seconds form. HTTP-date form
|
|
32
|
+
* (RFC 7231) returns `undefined` to avoid NaN propagation downstream.
|
|
33
|
+
*/
|
|
34
|
+
export declare function parseRetryAfter(headers: Headers | undefined): number | undefined;
|
|
35
|
+
/**
|
|
36
|
+
* Truncate raw response body to ~2KB and redact known credential
|
|
37
|
+
* patterns so it can ride inside `ErrorMetadata.raw` without
|
|
38
|
+
* ballooning logs OR leaking tokens. Returns `undefined` for
|
|
39
|
+
* null/undefined input.
|
|
40
|
+
*/
|
|
41
|
+
export declare function truncateRaw(body: unknown): unknown;
|
|
42
|
+
/**
|
|
43
|
+
* Build an `ErrorMetadata` object with all optional fields included
|
|
44
|
+
* conditionally (no `undefined` keys in the output).
|
|
45
|
+
*/
|
|
46
|
+
export declare function buildErrorMetadata(args: {
|
|
47
|
+
provider: string;
|
|
48
|
+
endpoint: string;
|
|
49
|
+
code: ErrorCode;
|
|
50
|
+
status: number;
|
|
51
|
+
headers: Headers | undefined;
|
|
52
|
+
body: unknown;
|
|
53
|
+
}): ErrorMetadata;
|
|
54
|
+
interface MapOpenAiErrorArgs {
|
|
55
|
+
providerId: string;
|
|
56
|
+
status: number;
|
|
57
|
+
body: unknown;
|
|
58
|
+
headers: Headers | undefined;
|
|
59
|
+
endpoint: string;
|
|
60
|
+
}
|
|
61
|
+
export declare function mapOpenAICompatibleError(args: MapOpenAiErrorArgs): TheokitAgentError;
|
|
62
|
+
export {};
|
|
63
|
+
//# sourceMappingURL=adapter-http-error.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter-http-error.d.ts","sourceRoot":"","sources":["../../src/internal/adapter-http-error.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,OAAO,EAGL,KAAK,SAAS,EACd,KAAK,aAAa,EAGlB,KAAK,iBAAiB,EAEvB,MAAM,qBAAqB,CAAC;AAM7B;;;GAGG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,OAAO,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAOhF;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,OAAO,GAAG,OAAO,CAKlD;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE;IACvC,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,SAAS,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,OAAO,GAAG,SAAS,CAAC;IAC7B,IAAI,EAAE,OAAO,CAAC;CACf,GAAG,aAAa,CAWhB;AAED,UAAU,kBAAkB;IAC1B,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,OAAO,CAAC;IACd,OAAO,EAAE,OAAO,GAAG,SAAS,CAAC;IAC7B,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,kBAAkB,GAAG,iBAAiB,CA6BpF"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Batch encoding pipeline — embeds N texts in 1 API call with intra-batch dedup.
|
|
3
|
+
*
|
|
4
|
+
* Inspired by CrewAI's `encoding_flow.py` Stage 1-2: batch embed + cosine dedup.
|
|
5
|
+
* Per ADR D1: new module alongside sync(), not a replacement.
|
|
6
|
+
*
|
|
7
|
+
* @internal
|
|
8
|
+
*/
|
|
9
|
+
import type { EmbeddingRuntime } from "./embedding-adapter.js";
|
|
10
|
+
interface RememberManyOptions {
|
|
11
|
+
scope?: string;
|
|
12
|
+
importance?: number;
|
|
13
|
+
dedupThreshold?: number;
|
|
14
|
+
}
|
|
15
|
+
interface RememberManyResult {
|
|
16
|
+
total: number;
|
|
17
|
+
deduped: number;
|
|
18
|
+
inserted: number;
|
|
19
|
+
}
|
|
20
|
+
interface KeptItem {
|
|
21
|
+
text: string;
|
|
22
|
+
vector: number[];
|
|
23
|
+
}
|
|
24
|
+
declare function cosineSimilarity(a: number[], b: number[]): number;
|
|
25
|
+
export declare function rememberMany(texts: string[], embedding: EmbeddingRuntime, opts?: RememberManyOptions): Promise<{
|
|
26
|
+
result: RememberManyResult;
|
|
27
|
+
items: KeptItem[];
|
|
28
|
+
}>;
|
|
29
|
+
export { cosineSimilarity };
|
|
30
|
+
//# sourceMappingURL=batch-encoder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"batch-encoder.d.ts","sourceRoot":"","sources":["../../src/internal/batch-encoder.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAE/D,UAAU,mBAAmB;IAC3B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,UAAU,kBAAkB;IAC1B,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,UAAU,QAAQ;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB;AAED,iBAAS,gBAAgB,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,MAAM,EAAE,GAAG,MAAM,CAY1D;AAmBD,wBAAsB,YAAY,CAChC,KAAK,EAAE,MAAM,EAAE,EACf,SAAS,EAAE,gBAAgB,EAC3B,IAAI,GAAE,mBAAwB,GAC7B,OAAO,CAAC;IAAE,MAAM,EAAE,kBAAkB,CAAC;IAAC,KAAK,EAAE,QAAQ,EAAE,CAAA;CAAE,CAAC,CAiB5D;AAED,OAAO,EAAE,gBAAgB,EAAE,CAAC"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* **Iter 53 rollup-plugin-dts workaround** (mirrors iter 48
|
|
3
|
+
* MemorySearchHit pattern). The canonical sdk-core copy imports
|
|
4
|
+
* `MemoryChunk` from `../types.js`. In sdk-memory the same type lives
|
|
5
|
+
* in sibling `./memory-types.js` (moved iter 52) but rollup-dts
|
|
6
|
+
* treeshakes it out of the dist .d.ts because no PUBLIC type
|
|
7
|
+
* references it transitively yet — the public `chunkMarkdown(text):
|
|
8
|
+
* MemoryChunk[]` signature would be the first transitive reachable
|
|
9
|
+
* consumer, BUT rollup-dts processes files in an order that asks for
|
|
10
|
+
* the import resolution BEFORE chunk-markdown.ts itself becomes the
|
|
11
|
+
* reachable consumer. Result: "MemoryChunk is not exported by
|
|
12
|
+
* src/internal/memory-types.ts" build error.
|
|
13
|
+
*
|
|
14
|
+
* Fix: declare a byte-identical mirror of MemoryChunk inline. When a
|
|
15
|
+
* future move turns MemoryChunk into a publicly-reachable type
|
|
16
|
+
* through a different path (e.g. `index-db.ts` or `IndexManager`
|
|
17
|
+
* methods that return arrays of it), this mirror MUST be deleted +
|
|
18
|
+
* the canonical import restored to maintain single source of truth.
|
|
19
|
+
*
|
|
20
|
+
* @internal
|
|
21
|
+
*/
|
|
22
|
+
interface MemoryChunk {
|
|
23
|
+
/** 1-indexed starting line in the source file. */
|
|
24
|
+
startLine: number;
|
|
25
|
+
/** 1-indexed ending line (inclusive). */
|
|
26
|
+
endLine: number;
|
|
27
|
+
/** Slice of markdown source text. */
|
|
28
|
+
text: string;
|
|
29
|
+
/** sha256 of `text`; stable across runs for identical inputs. */
|
|
30
|
+
hash: string;
|
|
31
|
+
/** Optional nearest heading text (without the `#` markers). */
|
|
32
|
+
heading?: string;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Split a markdown document into semantically meaningful chunks (ADR D1 of
|
|
36
|
+
* memory-system-openclaw-parity).
|
|
37
|
+
*
|
|
38
|
+
* Algorithm:
|
|
39
|
+
* 1. Walk lines tracking the current heading (latest `^#+ ` line).
|
|
40
|
+
* 2. Split chunks at the next heading boundary AND on blank-line paragraph
|
|
41
|
+
* boundaries.
|
|
42
|
+
* 3. If a single paragraph exceeds `maxChars`, split it at the nearest
|
|
43
|
+
* whitespace ≤ maxChars (word-aligned per edge-case review EC-6) —
|
|
44
|
+
* never mid-word.
|
|
45
|
+
*
|
|
46
|
+
* Mirrors OpenClaw's `chunkMarkdown` from
|
|
47
|
+
* `packages/memory-host-sdk/src/host/chunk-markdown.ts`.
|
|
48
|
+
*
|
|
49
|
+
* Iter 53 (Stage 3 source-move #10): hybrid copy from sdk-core's
|
|
50
|
+
* `internal/memory/storage/chunk-markdown.ts`. sdk-core retains its
|
|
51
|
+
* copy for v1.x back-compat; sdk-memory ships the canonical copy that
|
|
52
|
+
* future `storage/markdown-store`, `migration`, `index-db`, and
|
|
53
|
+
* `index-manager` moves will target as siblings. The `MemoryChunk`
|
|
54
|
+
* type comes from sibling `./memory-types.js` (moved iter 52).
|
|
55
|
+
*
|
|
56
|
+
* @internal
|
|
57
|
+
*/
|
|
58
|
+
export interface ChunkMarkdownOptions {
|
|
59
|
+
/** Maximum chars per chunk. Default 800. */
|
|
60
|
+
maxChars?: number;
|
|
61
|
+
/** Minimum chars per chunk (avoids splintering tiny lines). Default 80. */
|
|
62
|
+
minChars?: number;
|
|
63
|
+
}
|
|
64
|
+
export declare function chunkMarkdown(text: string, options?: ChunkMarkdownOptions): MemoryChunk[];
|
|
65
|
+
export {};
|
|
66
|
+
//# sourceMappingURL=chunk-markdown.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chunk-markdown.d.ts","sourceRoot":"","sources":["../../src/internal/chunk-markdown.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,UAAU,WAAW;IACnB,kDAAkD;IAClD,SAAS,EAAE,MAAM,CAAC;IAClB,yCAAyC;IACzC,OAAO,EAAE,MAAM,CAAC;IAChB,qCAAqC;IACrC,IAAI,EAAE,MAAM,CAAC;IACb,iEAAiE;IACjE,IAAI,EAAE,MAAM,CAAC;IACb,+DAA+D;IAC/D,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,MAAM,WAAW,oBAAoB;IACnC,4CAA4C;IAC5C,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,2EAA2E;IAC3E,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAWD,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,oBAAyB,GAAG,WAAW,EAAE,CAY7F"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Consecutive-timeout circuit breaker for Active Memory recall.
|
|
3
|
+
*
|
|
4
|
+
* Mirrors OpenClaw's `circuitBreakerMaxTimeouts` + `circuitBreakerCooldownMs`
|
|
5
|
+
* config: after N consecutive timeouts the breaker trips and `shouldSkip`
|
|
6
|
+
* returns `true` until `cooldownMs` has elapsed. A successful recall resets
|
|
7
|
+
* the counter immediately.
|
|
8
|
+
*
|
|
9
|
+
* Per-key isolation so two agents in the same process don't share a counter.
|
|
10
|
+
*
|
|
11
|
+
* @internal
|
|
12
|
+
*/
|
|
13
|
+
export interface CircuitBreakerOptions {
|
|
14
|
+
maxTimeouts?: number;
|
|
15
|
+
cooldownMs?: number;
|
|
16
|
+
/** Injectable clock for tests. */
|
|
17
|
+
now?: () => number;
|
|
18
|
+
}
|
|
19
|
+
interface KeyState {
|
|
20
|
+
consecutiveTimeouts: number;
|
|
21
|
+
cooldownUntilMs: number;
|
|
22
|
+
}
|
|
23
|
+
export declare class CircuitBreaker {
|
|
24
|
+
private readonly opts;
|
|
25
|
+
private readonly states;
|
|
26
|
+
constructor(opts?: CircuitBreakerOptions);
|
|
27
|
+
/** @returns true when the breaker is open and the call should be skipped. */
|
|
28
|
+
shouldSkip(key: string): boolean;
|
|
29
|
+
recordSuccess(key: string): void;
|
|
30
|
+
recordTimeout(key: string): void;
|
|
31
|
+
/** @internal — tests inspect counter state. */
|
|
32
|
+
inspect(key: string): Readonly<KeyState>;
|
|
33
|
+
private now;
|
|
34
|
+
}
|
|
35
|
+
export {};
|
|
36
|
+
//# sourceMappingURL=circuit-breaker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"circuit-breaker.d.ts","sourceRoot":"","sources":["../../src/internal/circuit-breaker.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,MAAM,WAAW,qBAAqB;IACpC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,kCAAkC;IAClC,GAAG,CAAC,EAAE,MAAM,MAAM,CAAC;CACpB;AAED,UAAU,QAAQ;IAChB,mBAAmB,EAAE,MAAM,CAAC;IAC5B,eAAe,EAAE,MAAM,CAAC;CACzB;AAKD,qBAAa,cAAc;IAGb,OAAO,CAAC,QAAQ,CAAC,IAAI;IAFjC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA+B;gBAEzB,IAAI,GAAE,qBAA0B;IAE7D,6EAA6E;IAC7E,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO;IAWhC,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;IAOhC,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;IAShC,+CAA+C;IAC/C,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,QAAQ,CAAC,QAAQ,CAAC;IAIxC,OAAO,CAAC,GAAG;CAGZ"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Composite scoring — blends semantic, text, recency, and importance signals.
|
|
3
|
+
*
|
|
4
|
+
* Inspired by CrewAI's `unified_memory.py` composite scoring (lines 345-381).
|
|
5
|
+
* Default weights: semantic 0.5, text 0.2, recency 0.2, importance 0.1.
|
|
6
|
+
* Backward-compatible: old behavior reproduced with {recencyWeight:0, importanceWeight:0}.
|
|
7
|
+
*
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
10
|
+
export interface CompositeScoreConfig {
|
|
11
|
+
semanticWeight: number;
|
|
12
|
+
textWeight: number;
|
|
13
|
+
recencyWeight: number;
|
|
14
|
+
importanceWeight: number;
|
|
15
|
+
recencyHalfLifeMs: number;
|
|
16
|
+
}
|
|
17
|
+
export declare const DEFAULT_COMPOSITE_CONFIG: CompositeScoreConfig;
|
|
18
|
+
export declare function compositeScore(vectorScore: number, textScore: number, createdAt: number | null, importance: number, config?: CompositeScoreConfig): number;
|
|
19
|
+
//# sourceMappingURL=composite-scorer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"composite-scorer.d.ts","sourceRoot":"","sources":["../../src/internal/composite-scorer.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH,MAAM,WAAW,oBAAoB;IACnC,cAAc,EAAE,MAAM,CAAC;IACvB,UAAU,EAAE,MAAM,CAAC;IACnB,aAAa,EAAE,MAAM,CAAC;IACtB,gBAAgB,EAAE,MAAM,CAAC;IACzB,iBAAiB,EAAE,MAAM,CAAC;CAC3B;AAED,eAAO,MAAM,wBAAwB,EAAE,oBAMtC,CAAC;AAEF,wBAAgB,cAAc,CAC5B,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,MAAM,GAAG,IAAI,EACxB,UAAU,EAAE,MAAM,EAClB,MAAM,GAAE,oBAA+C,GACtD,MAAM,CAUR"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { createOpenAiCompatibleRuntime } from "./openai-compatible.js";
|
|
2
|
+
/**
|
|
3
|
+
* DeepInfra embedding adapter — hosts open-source embedding models
|
|
4
|
+
* (BGE, E5, Jina, etc.) at pay-per-token. OpenAI-compatible REST at
|
|
5
|
+
* `POST /v1/openai/embeddings` (note the `/openai` segment; not the
|
|
6
|
+
* canonical `/v1/embeddings`). The `embeddingsPath` override on
|
|
7
|
+
* `OpenAiCompatibleConfig` REPLACES the default suffix (EC-2).
|
|
8
|
+
*
|
|
9
|
+
* Honors `DEEPINFRA_API_KEY` and `DEEPINFRA_API_BASE_URL`.
|
|
10
|
+
*
|
|
11
|
+
* Iter 74 (Stage 3 source-move #33): hybrid copy from sdk-core's
|
|
12
|
+
* `internal/memory/adapters/deepinfra-embedding.ts`.
|
|
13
|
+
*
|
|
14
|
+
* @internal
|
|
15
|
+
*/
|
|
16
|
+
export declare const DEFAULT_DEEPINFRA_EMBEDDING_MODEL = "BAAI/bge-large-en-v1.5";
|
|
17
|
+
export declare const deepinfraMemoryEmbeddingProviderAdapter: {
|
|
18
|
+
id: string;
|
|
19
|
+
defaultModel: string;
|
|
20
|
+
transport: "remote";
|
|
21
|
+
authProviderId: string;
|
|
22
|
+
autoSelectPriority: number;
|
|
23
|
+
create: (options: Parameters<typeof createOpenAiCompatibleRuntime>[1]) => Promise<import("./embedding-adapter.js").EmbeddingRuntime>;
|
|
24
|
+
};
|
|
25
|
+
//# sourceMappingURL=deepinfra-embedding.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deepinfra-embedding.d.ts","sourceRoot":"","sources":["../../src/internal/deepinfra-embedding.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,6BAA6B,EAAE,MAAM,wBAAwB,CAAC;AAIvE;;;;;;;;;;;;;GAaG;AAEH,eAAO,MAAM,iCAAiC,2BAA2B,CAAC;AAe1E,eAAO,MAAM,uCAAuC;;;;;;sBAMhC,UAAU,CAAC,OAAO,6BAA6B,CAAC,CAAC,CAAC,CAAC;CAatE,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dream-diary append (ADR D7).
|
|
3
|
+
*
|
|
4
|
+
* Diary lives at `.theokit/memory/dream-diary.md` and grows with one entry
|
|
5
|
+
* per sweep. Each entry is content-hashed so the same input produces the
|
|
6
|
+
* same entry — idempotency contract.
|
|
7
|
+
*
|
|
8
|
+
* Writes go through `replaceFileAtomic` (EC-3 of edge-case review) so a
|
|
9
|
+
* crash mid-write can never leave a half-written diary.
|
|
10
|
+
*
|
|
11
|
+
* Iter 59 (Stage 3 source-move #16): hybrid copy from sdk-core's
|
|
12
|
+
* `internal/memory/dreaming/diary.ts`. sdk-core retains its copy for
|
|
13
|
+
* v1.x dream-diary back-compat; sdk-memory ships the canonical copy
|
|
14
|
+
* that the future `dreaming-run.ts` move will compose with as a
|
|
15
|
+
* sibling (run.ts imports `appendDiaryEntry` after each dreaming
|
|
16
|
+
* sweep). Dependency chain (both resolved):
|
|
17
|
+
* - `@theokit/sdk/internal/persistence` for `replaceFileAtomic`
|
|
18
|
+
* - sibling `./markdown-store.js` for `memoryDir` (moved iter 56)
|
|
19
|
+
*
|
|
20
|
+
* Flat-naming convention (not `dreaming/diary.ts`): sdk-memory's
|
|
21
|
+
* `internal/` directory stays flat. The `dreaming-` prefix preserves
|
|
22
|
+
* the topical grouping (companion to iter 54's `dreaming-phases`).
|
|
23
|
+
*
|
|
24
|
+
* @internal
|
|
25
|
+
*/
|
|
26
|
+
export interface DiaryEntry {
|
|
27
|
+
timestampMs: number;
|
|
28
|
+
factsBefore: number;
|
|
29
|
+
factsAfter: number;
|
|
30
|
+
duplicatesRemoved: number;
|
|
31
|
+
clustersCreated: number;
|
|
32
|
+
notesWritten: number;
|
|
33
|
+
}
|
|
34
|
+
export declare function diaryPath(cwd: string): string;
|
|
35
|
+
export declare function renderDiaryEntry(entry: DiaryEntry): string;
|
|
36
|
+
export declare function appendDiaryEntry(cwd: string, entry: DiaryEntry): Promise<void>;
|
|
37
|
+
export declare function entryHash(entry: DiaryEntry): string;
|
|
38
|
+
//# sourceMappingURL=dreaming-diary.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dreaming-diary.d.ts","sourceRoot":"","sources":["../../src/internal/dreaming-diary.ts"],"names":[],"mappings":"AAQA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,MAAM,WAAW,UAAU;IACzB,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,eAAe,EAAE,MAAM,CAAC;IACxB,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAE7C;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAc1D;AAED,wBAAsB,gBAAgB,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,CAUpF;AAED,wBAAgB,SAAS,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAYnD"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { EmbeddingRuntime } from "./embedding-adapter.js";
|
|
2
|
+
import type { MemoryFact } from "./memory-types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Dreaming/REM phase logic.
|
|
5
|
+
*
|
|
6
|
+
* Three phases:
|
|
7
|
+
* - **light** — drop near-duplicate facts (cosine similarity > 0.95).
|
|
8
|
+
* - **REM** — cluster thematically related facts (cosine ≥ 0.75).
|
|
9
|
+
* - **deep** — pick a representative bullet per cluster (longest text
|
|
10
|
+
* wins) and emit consolidated markdown notes.
|
|
11
|
+
*
|
|
12
|
+
* Iter 54 (Stage 3 source-move #11): hybrid copy from sdk-core's
|
|
13
|
+
* `internal/memory/dreaming/phases.ts`. sdk-core retains its copy
|
|
14
|
+
* for v1.x dreaming back-compat; sdk-memory ships the canonical copy
|
|
15
|
+
* that future `dreaming/run.ts` move will compose with as a sibling.
|
|
16
|
+
* Dependencies (both moved): `EmbeddingRuntime` (iter 45) +
|
|
17
|
+
* `MemoryFact` (iter 52).
|
|
18
|
+
*
|
|
19
|
+
* Flat-naming convention (not `dreaming/phases.ts`): sdk-memory's
|
|
20
|
+
* `internal/` directory stays flat to keep relative-import paths
|
|
21
|
+
* uniform across iter 44-53. The `dreaming-` prefix preserves the
|
|
22
|
+
* topical grouping without a sub-directory.
|
|
23
|
+
*
|
|
24
|
+
* @internal
|
|
25
|
+
*/
|
|
26
|
+
export interface DedupResult {
|
|
27
|
+
kept: MemoryFact[];
|
|
28
|
+
duplicatesRemoved: number;
|
|
29
|
+
}
|
|
30
|
+
export interface Cluster {
|
|
31
|
+
representativeText: string;
|
|
32
|
+
members: ReadonlyArray<MemoryFact>;
|
|
33
|
+
}
|
|
34
|
+
export interface ClusterResult {
|
|
35
|
+
clusters: Cluster[];
|
|
36
|
+
}
|
|
37
|
+
/** Light phase — drop facts whose embedding is too similar to one already kept. */
|
|
38
|
+
export declare function lightPhase(facts: ReadonlyArray<MemoryFact>, embedding: EmbeddingRuntime, threshold?: number): Promise<DedupResult>;
|
|
39
|
+
/** REM phase — single-link agglomerative clustering by cosine similarity. */
|
|
40
|
+
export declare function remPhase(facts: ReadonlyArray<MemoryFact>, embedding: EmbeddingRuntime, threshold?: number, maxFactsPerSweep?: number): Promise<ClusterResult>;
|
|
41
|
+
/** Deep phase — render consolidated markdown for the dreamed note. */
|
|
42
|
+
export declare function deepPhase(clusters: ReadonlyArray<Cluster>, timestampMs: number): string;
|
|
43
|
+
//# sourceMappingURL=dreaming-phases.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dreaming-phases.d.ts","sourceRoot":"","sources":["../../src/internal/dreaming-phases.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC/D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAEpD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,UAAU,EAAE,CAAC;IACnB,iBAAiB,EAAE,MAAM,CAAC;CAC3B;AAED,MAAM,WAAW,OAAO;IACtB,kBAAkB,EAAE,MAAM,CAAC;IAC3B,OAAO,EAAE,aAAa,CAAC,UAAU,CAAC,CAAC;CACpC;AAED,MAAM,WAAW,aAAa;IAC5B,QAAQ,EAAE,OAAO,EAAE,CAAC;CACrB;AAKD,mFAAmF;AACnF,wBAAsB,UAAU,CAC9B,KAAK,EAAE,aAAa,CAAC,UAAU,CAAC,EAChC,SAAS,EAAE,gBAAgB,EAC3B,SAAS,GAAE,MAAgC,GAC1C,OAAO,CAAC,WAAW,CAAC,CActB;AAQD,6EAA6E;AAC7E,wBAAsB,QAAQ,CAC5B,KAAK,EAAE,aAAa,CAAC,UAAU,CAAC,EAChC,SAAS,EAAE,gBAAgB,EAC3B,SAAS,GAAE,MAAkC,EAC7C,gBAAgB,GAAE,MAAoC,GACrD,OAAO,CAAC,aAAa,CAAC,CASxB;AAoCD,sEAAsE;AACtE,wBAAgB,SAAS,CAAC,QAAQ,EAAE,aAAa,CAAC,OAAO,CAAC,EAAE,WAAW,EAAE,MAAM,GAAG,MAAM,CAavF"}
|