@afaik-lab/weigh 0.0.0-stage → 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/.env.example +49 -0
- package/LICENSE +373 -0
- package/README.md +102 -2
- package/dist/agent.d.ts +83 -0
- package/dist/agent.d.ts.map +1 -0
- package/dist/agent.js +204 -0
- package/dist/agent.js.map +1 -0
- package/dist/ceilings.d.ts +32 -0
- package/dist/ceilings.d.ts.map +1 -0
- package/dist/ceilings.js +61 -0
- package/dist/ceilings.js.map +1 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +530 -0
- package/dist/cli.js.map +1 -0
- package/dist/config-cli.d.ts +15 -0
- package/dist/config-cli.d.ts.map +1 -0
- package/dist/config-cli.js +132 -0
- package/dist/config-cli.js.map +1 -0
- package/dist/config.d.ts +198 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +373 -0
- package/dist/config.js.map +1 -0
- package/dist/context-cli.d.ts +35 -0
- package/dist/context-cli.d.ts.map +1 -0
- package/dist/context-cli.js +251 -0
- package/dist/context-cli.js.map +1 -0
- package/dist/context.d.ts +118 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +159 -0
- package/dist/context.js.map +1 -0
- package/dist/corrections/correction-set.d.ts +67 -0
- package/dist/corrections/correction-set.d.ts.map +1 -0
- package/dist/corrections/correction-set.js +104 -0
- package/dist/corrections/correction-set.js.map +1 -0
- package/dist/corrections/correction.d.ts +74 -0
- package/dist/corrections/correction.d.ts.map +1 -0
- package/dist/corrections/correction.js +154 -0
- package/dist/corrections/correction.js.map +1 -0
- package/dist/corrections/follow-up.d.ts +69 -0
- package/dist/corrections/follow-up.d.ts.map +1 -0
- package/dist/corrections/follow-up.js +217 -0
- package/dist/corrections/follow-up.js.map +1 -0
- package/dist/corrections/index.d.ts +31 -0
- package/dist/corrections/index.d.ts.map +1 -0
- package/dist/corrections/index.js +31 -0
- package/dist/corrections/index.js.map +1 -0
- package/dist/corrections/ledger.d.ts +78 -0
- package/dist/corrections/ledger.d.ts.map +1 -0
- package/dist/corrections/ledger.js +117 -0
- package/dist/corrections/ledger.js.map +1 -0
- package/dist/corrections/promotion.d.ts +119 -0
- package/dist/corrections/promotion.d.ts.map +1 -0
- package/dist/corrections/promotion.js +221 -0
- package/dist/corrections/promotion.js.map +1 -0
- package/dist/corrections/schema.d.ts +125 -0
- package/dist/corrections/schema.d.ts.map +1 -0
- package/dist/corrections/schema.js +100 -0
- package/dist/corrections/schema.js.map +1 -0
- package/dist/corrections-cli.d.ts +28 -0
- package/dist/corrections-cli.d.ts.map +1 -0
- package/dist/corrections-cli.js +157 -0
- package/dist/corrections-cli.js.map +1 -0
- package/dist/diff.d.ts +105 -0
- package/dist/diff.d.ts.map +1 -0
- package/dist/diff.js +202 -0
- package/dist/diff.js.map +1 -0
- package/dist/doctor.d.ts +38 -0
- package/dist/doctor.d.ts.map +1 -0
- package/dist/doctor.js +197 -0
- package/dist/doctor.js.map +1 -0
- package/dist/events.d.ts +21 -0
- package/dist/events.d.ts.map +1 -0
- package/dist/events.js +5 -0
- package/dist/events.js.map +1 -0
- package/dist/findings.d.ts +510 -0
- package/dist/findings.d.ts.map +1 -0
- package/dist/findings.js +645 -0
- package/dist/findings.js.map +1 -0
- package/dist/follow-up-cli.d.ts +88 -0
- package/dist/follow-up-cli.d.ts.map +1 -0
- package/dist/follow-up-cli.js +208 -0
- package/dist/follow-up-cli.js.map +1 -0
- package/dist/harness.d.ts +64 -0
- package/dist/harness.d.ts.map +1 -0
- package/dist/harness.js +71 -0
- package/dist/harness.js.map +1 -0
- package/dist/help/command-help.d.ts +9 -0
- package/dist/help/command-help.d.ts.map +1 -0
- package/dist/help/command-help.js +21 -0
- package/dist/help/command-help.js.map +1 -0
- package/dist/help/commands/answer.d.ts +3 -0
- package/dist/help/commands/answer.d.ts.map +1 -0
- package/dist/help/commands/answer.js +39 -0
- package/dist/help/commands/answer.js.map +1 -0
- package/dist/help/commands/config.d.ts +3 -0
- package/dist/help/commands/config.d.ts.map +1 -0
- package/dist/help/commands/config.js +25 -0
- package/dist/help/commands/config.js.map +1 -0
- package/dist/help/commands/context.d.ts +3 -0
- package/dist/help/commands/context.d.ts.map +1 -0
- package/dist/help/commands/context.js +44 -0
- package/dist/help/commands/context.js.map +1 -0
- package/dist/help/commands/corrections.d.ts +3 -0
- package/dist/help/commands/corrections.d.ts.map +1 -0
- package/dist/help/commands/corrections.js +30 -0
- package/dist/help/commands/corrections.js.map +1 -0
- package/dist/help/commands/doctor.d.ts +3 -0
- package/dist/help/commands/doctor.d.ts.map +1 -0
- package/dist/help/commands/doctor.js +12 -0
- package/dist/help/commands/doctor.js.map +1 -0
- package/dist/help/commands/index.d.ts +4 -0
- package/dist/help/commands/index.d.ts.map +1 -0
- package/dist/help/commands/index.js +27 -0
- package/dist/help/commands/index.js.map +1 -0
- package/dist/help/commands/memory.d.ts +3 -0
- package/dist/help/commands/memory.d.ts.map +1 -0
- package/dist/help/commands/memory.js +33 -0
- package/dist/help/commands/memory.js.map +1 -0
- package/dist/help/commands/models.d.ts +3 -0
- package/dist/help/commands/models.d.ts.map +1 -0
- package/dist/help/commands/models.js +17 -0
- package/dist/help/commands/models.js.map +1 -0
- package/dist/help/commands/options.d.ts +4 -0
- package/dist/help/commands/options.d.ts.map +1 -0
- package/dist/help/commands/options.js +13 -0
- package/dist/help/commands/options.js.map +1 -0
- package/dist/help/commands/review.d.ts +3 -0
- package/dist/help/commands/review.d.ts.map +1 -0
- package/dist/help/commands/review.js +50 -0
- package/dist/help/commands/review.js.map +1 -0
- package/dist/help/commands/sessions.d.ts +3 -0
- package/dist/help/commands/sessions.d.ts.map +1 -0
- package/dist/help/commands/sessions.js +23 -0
- package/dist/help/commands/sessions.js.map +1 -0
- package/dist/help/commands/show.d.ts +3 -0
- package/dist/help/commands/show.d.ts.map +1 -0
- package/dist/help/commands/show.js +18 -0
- package/dist/help/commands/show.js.map +1 -0
- package/dist/help/help.d.ts +16 -0
- package/dist/help/help.d.ts.map +1 -0
- package/dist/help/help.js +68 -0
- package/dist/help/help.js.map +1 -0
- package/dist/help/index.d.ts +4 -0
- package/dist/help/index.d.ts.map +1 -0
- package/dist/help/index.js +7 -0
- package/dist/help/index.js.map +1 -0
- package/dist/index.d.ts +80 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +51 -0
- package/dist/index.js.map +1 -0
- package/dist/knowledge/block.d.ts +65 -0
- package/dist/knowledge/block.d.ts.map +1 -0
- package/dist/knowledge/block.js +89 -0
- package/dist/knowledge/block.js.map +1 -0
- package/dist/knowledge/claim.d.ts +143 -0
- package/dist/knowledge/claim.d.ts.map +1 -0
- package/dist/knowledge/claim.js +297 -0
- package/dist/knowledge/claim.js.map +1 -0
- package/dist/knowledge/index.d.ts +32 -0
- package/dist/knowledge/index.d.ts.map +1 -0
- package/dist/knowledge/index.js +29 -0
- package/dist/knowledge/index.js.map +1 -0
- package/dist/knowledge/novelty.d.ts +65 -0
- package/dist/knowledge/novelty.d.ts.map +1 -0
- package/dist/knowledge/novelty.js +94 -0
- package/dist/knowledge/novelty.js.map +1 -0
- package/dist/knowledge/recall.d.ts +134 -0
- package/dist/knowledge/recall.d.ts.map +1 -0
- package/dist/knowledge/recall.js +229 -0
- package/dist/knowledge/recall.js.map +1 -0
- package/dist/knowledge/recalled-claim.d.ts +35 -0
- package/dist/knowledge/recalled-claim.d.ts.map +1 -0
- package/dist/knowledge/recalled-claim.js +67 -0
- package/dist/knowledge/recalled-claim.js.map +1 -0
- package/dist/knowledge/recalled.d.ts +70 -0
- package/dist/knowledge/recalled.d.ts.map +1 -0
- package/dist/knowledge/recalled.js +149 -0
- package/dist/knowledge/recalled.js.map +1 -0
- package/dist/knowledge/schema.d.ts +83 -0
- package/dist/knowledge/schema.d.ts.map +1 -0
- package/dist/knowledge/schema.js +96 -0
- package/dist/knowledge/schema.js.map +1 -0
- package/dist/knowledge/staleness.d.ts +48 -0
- package/dist/knowledge/staleness.d.ts.map +1 -0
- package/dist/knowledge/staleness.js +85 -0
- package/dist/knowledge/staleness.js.map +1 -0
- package/dist/knowledge/store.d.ts +100 -0
- package/dist/knowledge/store.d.ts.map +1 -0
- package/dist/knowledge/store.js +184 -0
- package/dist/knowledge/store.js.map +1 -0
- package/dist/memory/compose-file.d.ts +14 -0
- package/dist/memory/compose-file.d.ts.map +1 -0
- package/dist/memory/compose-file.js +25 -0
- package/dist/memory/compose-file.js.map +1 -0
- package/dist/memory/index.d.ts +43 -0
- package/dist/memory/index.d.ts.map +1 -0
- package/dist/memory/index.js +119 -0
- package/dist/memory/index.js.map +1 -0
- package/dist/memory/oss.d.ts +62 -0
- package/dist/memory/oss.d.ts.map +1 -0
- package/dist/memory/oss.js +230 -0
- package/dist/memory/oss.js.map +1 -0
- package/dist/memory/platform.d.ts +37 -0
- package/dist/memory/platform.d.ts.map +1 -0
- package/dist/memory/platform.js +131 -0
- package/dist/memory/platform.js.map +1 -0
- package/dist/memory/scope.d.ts +49 -0
- package/dist/memory/scope.d.ts.map +1 -0
- package/dist/memory/scope.js +70 -0
- package/dist/memory/scope.js.map +1 -0
- package/dist/memory/types.d.ts +113 -0
- package/dist/memory/types.d.ts.map +1 -0
- package/dist/memory/types.js +18 -0
- package/dist/memory/types.js.map +1 -0
- package/dist/memory-cli.d.ts +17 -0
- package/dist/memory-cli.d.ts.map +1 -0
- package/dist/memory-cli.js +107 -0
- package/dist/memory-cli.js.map +1 -0
- package/dist/models-cli.d.ts +12 -0
- package/dist/models-cli.d.ts.map +1 -0
- package/dist/models-cli.js +54 -0
- package/dist/models-cli.js.map +1 -0
- package/dist/models.d.ts +111 -0
- package/dist/models.d.ts.map +1 -0
- package/dist/models.js +227 -0
- package/dist/models.js.map +1 -0
- package/dist/paths.d.ts +35 -0
- package/dist/paths.d.ts.map +1 -0
- package/dist/paths.js +65 -0
- package/dist/paths.js.map +1 -0
- package/dist/profile.d.ts +28 -0
- package/dist/profile.d.ts.map +1 -0
- package/dist/profile.js +154 -0
- package/dist/profile.js.map +1 -0
- package/dist/progress.d.ts +70 -0
- package/dist/progress.d.ts.map +1 -0
- package/dist/progress.js +132 -0
- package/dist/progress.js.map +1 -0
- package/dist/quiet.d.ts +2 -0
- package/dist/quiet.d.ts.map +1 -0
- package/dist/quiet.js +21 -0
- package/dist/quiet.js.map +1 -0
- package/dist/reconcile/continuation.d.ts +132 -0
- package/dist/reconcile/continuation.d.ts.map +1 -0
- package/dist/reconcile/continuation.js +306 -0
- package/dist/reconcile/continuation.js.map +1 -0
- package/dist/reconcile/index.d.ts +26 -0
- package/dist/reconcile/index.d.ts.map +1 -0
- package/dist/reconcile/index.js +28 -0
- package/dist/reconcile/index.js.map +1 -0
- package/dist/reconcile/outcome-set.d.ts +53 -0
- package/dist/reconcile/outcome-set.d.ts.map +1 -0
- package/dist/reconcile/outcome-set.js +124 -0
- package/dist/reconcile/outcome-set.js.map +1 -0
- package/dist/reconcile/outcome.d.ts +56 -0
- package/dist/reconcile/outcome.d.ts.map +1 -0
- package/dist/reconcile/outcome.js +60 -0
- package/dist/reconcile/outcome.js.map +1 -0
- package/dist/reconcile/reconciliation.d.ts +49 -0
- package/dist/reconcile/reconciliation.d.ts.map +1 -0
- package/dist/reconcile/reconciliation.js +88 -0
- package/dist/reconcile/reconciliation.js.map +1 -0
- package/dist/reconcile/schema.d.ts +157 -0
- package/dist/reconcile/schema.d.ts.map +1 -0
- package/dist/reconcile/schema.js +97 -0
- package/dist/reconcile/schema.js.map +1 -0
- package/dist/record/index.d.ts +23 -0
- package/dist/record/index.d.ts.map +1 -0
- package/dist/record/index.js +25 -0
- package/dist/record/index.js.map +1 -0
- package/dist/record/review-record.d.ts +28 -0
- package/dist/record/review-record.d.ts.map +1 -0
- package/dist/record/review-record.js +78 -0
- package/dist/record/review-record.js.map +1 -0
- package/dist/record/schema.d.ts +153 -0
- package/dist/record/schema.d.ts.map +1 -0
- package/dist/record/schema.js +87 -0
- package/dist/record/schema.js.map +1 -0
- package/dist/record/store.d.ts +83 -0
- package/dist/record/store.d.ts.map +1 -0
- package/dist/record/store.js +162 -0
- package/dist/record/store.js.map +1 -0
- package/dist/record/stored-review.d.ts +36 -0
- package/dist/record/stored-review.d.ts.map +1 -0
- package/dist/record/stored-review.js +90 -0
- package/dist/record/stored-review.js.map +1 -0
- package/dist/refute.d.ts +318 -0
- package/dist/refute.d.ts.map +1 -0
- package/dist/refute.js +513 -0
- package/dist/refute.js.map +1 -0
- package/dist/render.d.ts +212 -0
- package/dist/render.d.ts.map +1 -0
- package/dist/render.js +544 -0
- package/dist/render.js.map +1 -0
- package/dist/review-cli.d.ts +181 -0
- package/dist/review-cli.d.ts.map +1 -0
- package/dist/review-cli.js +598 -0
- package/dist/review-cli.js.map +1 -0
- package/dist/reviewer.d.ts +297 -0
- package/dist/reviewer.d.ts.map +1 -0
- package/dist/reviewer.js +580 -0
- package/dist/reviewer.js.map +1 -0
- package/dist/session-cli.d.ts +17 -0
- package/dist/session-cli.d.ts.map +1 -0
- package/dist/session-cli.js +62 -0
- package/dist/session-cli.js.map +1 -0
- package/dist/session.d.ts +36 -0
- package/dist/session.d.ts.map +1 -0
- package/dist/session.js +105 -0
- package/dist/session.js.map +1 -0
- package/dist/settings.d.ts +68 -0
- package/dist/settings.d.ts.map +1 -0
- package/dist/settings.js +175 -0
- package/dist/settings.js.map +1 -0
- package/dist/show-cli.d.ts +39 -0
- package/dist/show-cli.d.ts.map +1 -0
- package/dist/show-cli.js +56 -0
- package/dist/show-cli.js.map +1 -0
- package/dist/stdout.d.ts +28 -0
- package/dist/stdout.d.ts.map +1 -0
- package/dist/stdout.js +44 -0
- package/dist/stdout.js.map +1 -0
- package/dist/target.d.ts +58 -0
- package/dist/target.d.ts.map +1 -0
- package/dist/target.js +96 -0
- package/dist/target.js.map +1 -0
- package/dist/tools/index.d.ts +93 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +146 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/root.d.ts +62 -0
- package/dist/tools/root.d.ts.map +1 -0
- package/dist/tools/root.js +51 -0
- package/dist/tools/root.js.map +1 -0
- package/dist/usage.d.ts +75 -0
- package/dist/usage.d.ts.map +1 -0
- package/dist/usage.js +100 -0
- package/dist/usage.js.map +1 -0
- package/dist/version.d.ts +14 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +26 -0
- package/dist/version.js.map +1 -0
- package/dist/workspace.d.ts +48 -0
- package/dist/workspace.d.ts.map +1 -0
- package/dist/workspace.js +126 -0
- package/dist/workspace.js.map +1 -0
- package/docker-compose.yml +61 -0
- package/package.json +70 -4
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { AddOptions, ListOptions, MemoryMessage, MemoryRecord, MemoryScope, MemoryStore, SearchOptions } from './types.js';
|
|
2
|
+
/** Partial mem0ai/oss MemoryConfig — merged last, over everything below. */
|
|
3
|
+
export type OssOverrides = Record<string, any>;
|
|
4
|
+
export interface OssOptions {
|
|
5
|
+
collectionName: string;
|
|
6
|
+
qdrantUrl: string;
|
|
7
|
+
qdrantApiKey?: string;
|
|
8
|
+
/** Reused for fact extraction via OpenRouter. */
|
|
9
|
+
openRouterApiKey?: string;
|
|
10
|
+
extractionModel: string;
|
|
11
|
+
embeddingProvider: 'ollama' | 'openai';
|
|
12
|
+
embeddingModel: string;
|
|
13
|
+
embeddingDims: number;
|
|
14
|
+
ollamaUrl: string;
|
|
15
|
+
/** Only needed when embeddingProvider is 'openai'. */
|
|
16
|
+
openAiApiKey?: string;
|
|
17
|
+
overrides?: OssOverrides;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Self-hosted adapter (mem0ai/oss), backed by Qdrant.
|
|
21
|
+
*
|
|
22
|
+
* Two of mem0's defaults are unusable here and are replaced deliberately:
|
|
23
|
+
*
|
|
24
|
+
* - The default `memory` vector store and `sqlite` history store both load
|
|
25
|
+
* better-sqlite3, a native module Bun cannot dlopen. Qdrant's client is
|
|
26
|
+
* plain HTTP and the `memory` history provider is in-process, so neither
|
|
27
|
+
* needs a native build.
|
|
28
|
+
* - Fact extraction goes through OpenRouter (the OpenAI provider honours
|
|
29
|
+
* `baseURL`), reusing the key the agent already has.
|
|
30
|
+
*
|
|
31
|
+
* Embeddings default to a local Ollama, which keeps the whole store key-free
|
|
32
|
+
* and on-machine; OpenRouter serves no embeddings, so the alternative would be
|
|
33
|
+
* a second vendor credential.
|
|
34
|
+
*/
|
|
35
|
+
export declare class OssMemoryStore implements MemoryStore {
|
|
36
|
+
readonly backend: 'oss';
|
|
37
|
+
readonly enabled = true;
|
|
38
|
+
private options;
|
|
39
|
+
private memory;
|
|
40
|
+
constructor(options: OssOptions);
|
|
41
|
+
/**
|
|
42
|
+
* Built on first use rather than in the constructor: the client probes the
|
|
43
|
+
* embedder and opens a Qdrant connection, and a run that never touches
|
|
44
|
+
* memory should neither pay for that nor fail on it.
|
|
45
|
+
*/
|
|
46
|
+
private client;
|
|
47
|
+
/**
|
|
48
|
+
* Turns transport-level failures into something actionable. A refused
|
|
49
|
+
* connection here means a container is down, not that memory is broken.
|
|
50
|
+
*/
|
|
51
|
+
private guard;
|
|
52
|
+
search(query: string, scope: MemoryScope, options?: SearchOptions): Promise<MemoryRecord[]>;
|
|
53
|
+
add(messages: MemoryMessage[], scope: MemoryScope, options?: AddOptions): Promise<MemoryRecord[]>;
|
|
54
|
+
list(scope: MemoryScope, options?: ListOptions): Promise<MemoryRecord[]>;
|
|
55
|
+
clear(scope: MemoryScope, options?: {
|
|
56
|
+
runId?: string;
|
|
57
|
+
}): Promise<number>;
|
|
58
|
+
get(id: string): Promise<MemoryRecord | undefined>;
|
|
59
|
+
delete(id: string): Promise<void>;
|
|
60
|
+
update(id: string, metadata: Record<string, unknown>): Promise<void>;
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=oss.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"oss.d.ts","sourceRoot":"","sources":["../../src/memory/oss.ts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K,EAAE,WAAW,EAAE,OAAO,GAAE,WAAgB,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC,CAmBjF;IAEK,KAAK,CAAC,KAAK,EAAE,WAAW,EAAE,OAAO,GAAE;QAAE,KAAK,CAAC,EAAE,MAAM,CAAA;KAAO,GAAG,OAAO,CAAC,MAAM,CAAC,CAgBjF;IAEK,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,GAAG,SAAS,CAAC,CASvD;IAEK,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAKtC;IAEK,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAKzE;CACF"}
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
// This Source Code Form is subject to the terms of the Mozilla Public
|
|
2
|
+
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
3
|
+
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
4
|
+
/**
|
|
5
|
+
* Self-hosted adapter (mem0ai/oss), backed by Qdrant.
|
|
6
|
+
*
|
|
7
|
+
* Two of mem0's defaults are unusable here and are replaced deliberately:
|
|
8
|
+
*
|
|
9
|
+
* - The default `memory` vector store and `sqlite` history store both load
|
|
10
|
+
* better-sqlite3, a native module Bun cannot dlopen. Qdrant's client is
|
|
11
|
+
* plain HTTP and the `memory` history provider is in-process, so neither
|
|
12
|
+
* needs a native build.
|
|
13
|
+
* - Fact extraction goes through OpenRouter (the OpenAI provider honours
|
|
14
|
+
* `baseURL`), reusing the key the agent already has.
|
|
15
|
+
*
|
|
16
|
+
* Embeddings default to a local Ollama, which keeps the whole store key-free
|
|
17
|
+
* and on-machine; OpenRouter serves no embeddings, so the alternative would be
|
|
18
|
+
* a second vendor credential.
|
|
19
|
+
*/
|
|
20
|
+
export class OssMemoryStore {
|
|
21
|
+
backend = 'oss';
|
|
22
|
+
enabled = true;
|
|
23
|
+
options;
|
|
24
|
+
memory;
|
|
25
|
+
constructor(options) {
|
|
26
|
+
this.options = options;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Built on first use rather than in the constructor: the client probes the
|
|
30
|
+
* embedder and opens a Qdrant connection, and a run that never touches
|
|
31
|
+
* memory should neither pay for that nor fail on it.
|
|
32
|
+
*/
|
|
33
|
+
async client() {
|
|
34
|
+
if (this.memory)
|
|
35
|
+
return this.memory;
|
|
36
|
+
const { Memory } = await import('mem0ai/oss');
|
|
37
|
+
const o = this.options;
|
|
38
|
+
if (o.embeddingProvider === 'openai' && !o.openAiApiKey && !o.overrides?.embedder) {
|
|
39
|
+
throw new Error('The openai embedder needs OPENAI_API_KEY. Either set it, or switch to the local ' +
|
|
40
|
+
'embedder with WEIGH_EMBEDDER=ollama (weigh memory compose | docker compose -f - up -d ollama).');
|
|
41
|
+
}
|
|
42
|
+
this.memory = new Memory({
|
|
43
|
+
llm: {
|
|
44
|
+
provider: 'openai',
|
|
45
|
+
config: {
|
|
46
|
+
apiKey: o.openRouterApiKey,
|
|
47
|
+
baseURL: 'https://openrouter.ai/api/v1',
|
|
48
|
+
model: o.extractionModel,
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
embedder: o.embeddingProvider === 'ollama'
|
|
52
|
+
? {
|
|
53
|
+
provider: 'ollama',
|
|
54
|
+
// mem0 pulls the model on first use if the daemon does not have it;
|
|
55
|
+
// docker compose pre-pulls so that never lands mid-run.
|
|
56
|
+
config: {
|
|
57
|
+
url: o.ollamaUrl,
|
|
58
|
+
model: o.embeddingModel,
|
|
59
|
+
embeddingDims: o.embeddingDims,
|
|
60
|
+
},
|
|
61
|
+
}
|
|
62
|
+
: {
|
|
63
|
+
provider: 'openai',
|
|
64
|
+
config: { apiKey: o.openAiApiKey, model: o.embeddingModel },
|
|
65
|
+
},
|
|
66
|
+
vectorStore: {
|
|
67
|
+
provider: 'qdrant',
|
|
68
|
+
config: {
|
|
69
|
+
collectionName: o.collectionName,
|
|
70
|
+
url: o.qdrantUrl,
|
|
71
|
+
dimension: o.embeddingDims,
|
|
72
|
+
...(o.qdrantApiKey && { apiKey: o.qdrantApiKey }),
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
// In-process, so no better-sqlite3. History is an audit log of memory
|
|
76
|
+
// edits; the memories themselves live in Qdrant and outlive the process.
|
|
77
|
+
historyStore: { provider: 'memory', config: {} },
|
|
78
|
+
...o.overrides,
|
|
79
|
+
});
|
|
80
|
+
return this.memory;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Turns transport-level failures into something actionable. A refused
|
|
84
|
+
* connection here means a container is down, not that memory is broken.
|
|
85
|
+
*/
|
|
86
|
+
async guard(operation) {
|
|
87
|
+
try {
|
|
88
|
+
return await operation();
|
|
89
|
+
}
|
|
90
|
+
catch (err) {
|
|
91
|
+
const message = String(err?.message ?? err);
|
|
92
|
+
if (/ECONNREFUSED|fetch failed|Failed to fetch|ENOTFOUND|network/i.test(message)) {
|
|
93
|
+
const o = this.options;
|
|
94
|
+
const service = /11434/.test(message) || o.embeddingProvider === 'ollama'
|
|
95
|
+
? `Ollama (${o.ollamaUrl})`
|
|
96
|
+
: `Qdrant (${o.qdrantUrl})`;
|
|
97
|
+
throw new Error(`${service} is not reachable — run: weigh memory compose | docker compose -f - up -d. (${message})`);
|
|
98
|
+
}
|
|
99
|
+
throw err;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
async search(query, scope, options = {}) {
|
|
103
|
+
return this.guard(async () => {
|
|
104
|
+
const memory = await this.client();
|
|
105
|
+
const result = await memory.search(query, {
|
|
106
|
+
filters: scopeFilters(scope, scope.runId),
|
|
107
|
+
...(options.topK !== undefined && { topK: options.topK }),
|
|
108
|
+
...(options.threshold !== undefined && {
|
|
109
|
+
threshold: options.threshold,
|
|
110
|
+
}),
|
|
111
|
+
// The score mem0 returns adds keyword and entity matches to the vector
|
|
112
|
+
// similarity and divides by the most those could sum to, so the same
|
|
113
|
+
// pair scores differently from one store to the next. `explain` hands
|
|
114
|
+
// back the similarity alone, which is what `threshold` filters on.
|
|
115
|
+
explain: true,
|
|
116
|
+
});
|
|
117
|
+
return (result?.results ?? []).map(toRecord);
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
async add(messages, scope, options = {}) {
|
|
121
|
+
return this.guard(async () => {
|
|
122
|
+
const memory = await this.client();
|
|
123
|
+
const result = await memory.add(messages, {
|
|
124
|
+
userId: scope.userId,
|
|
125
|
+
agentId: scope.agentId,
|
|
126
|
+
...(scope.runId && { runId: scope.runId }),
|
|
127
|
+
...(options.metadata && { metadata: options.metadata }),
|
|
128
|
+
...(options.infer !== undefined && { infer: options.infer }),
|
|
129
|
+
});
|
|
130
|
+
return (result?.results ?? []).filter((m) => m.event !== 'NOOP').map(toRecord);
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
async list(scope, options = {}) {
|
|
134
|
+
return this.guard(async () => {
|
|
135
|
+
const memory = await this.client();
|
|
136
|
+
// Without a topK, mem0 returns the first 20 and says nothing, and it has
|
|
137
|
+
// no paging to ask for the rest. So "no limit" is asked for as a ceiling
|
|
138
|
+
// no scope comes near: a list that is quietly short reads as "that is
|
|
139
|
+
// everything", and recall reads a branch's thread through here in full.
|
|
140
|
+
// One past the ceiling, so a scope that reaches it is told apart from
|
|
141
|
+
// one that fits, and refused rather than handed back short.
|
|
142
|
+
const result = await memory.getAll({
|
|
143
|
+
filters: scopeFilters(scope, options.runId ?? scope.runId),
|
|
144
|
+
topK: options.limit ?? EVERYTHING + 1,
|
|
145
|
+
});
|
|
146
|
+
const records = (result?.results ?? []).map(toRecord);
|
|
147
|
+
if (options.limit === undefined && records.length > EVERYTHING) {
|
|
148
|
+
throw new Error(`more than ${EVERYTHING} memories in this scope — too many to list in full`);
|
|
149
|
+
}
|
|
150
|
+
return records;
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
async clear(scope, options = {}) {
|
|
154
|
+
return this.guard(async () => {
|
|
155
|
+
const memory = await this.client();
|
|
156
|
+
// The scope narrows the delete, exactly as it narrows a read. Dropping it
|
|
157
|
+
// here would turn "forget what you know about this repository" into
|
|
158
|
+
// "forget everything about this user", which is the one mistake in this
|
|
159
|
+
// file that cannot be undone.
|
|
160
|
+
const runId = options.runId ?? scope.runId;
|
|
161
|
+
const existing = await this.list(scope, runId ? { runId } : {});
|
|
162
|
+
await memory.deleteAll({
|
|
163
|
+
userId: scope.userId,
|
|
164
|
+
agentId: scope.agentId,
|
|
165
|
+
...(runId && { runId }),
|
|
166
|
+
});
|
|
167
|
+
return existing.length;
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
async get(id) {
|
|
171
|
+
// Qdrant keys a point by UUID or by integer, and answers anything else
|
|
172
|
+
// with a 400 rather than "not found". An id it cannot hold is not in it.
|
|
173
|
+
if (!POINT_ID.test(id))
|
|
174
|
+
return undefined;
|
|
175
|
+
return this.guard(async () => {
|
|
176
|
+
const memory = await this.client();
|
|
177
|
+
const item = await memory.get(id);
|
|
178
|
+
return item ? toRecord(item) : undefined;
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
async delete(id) {
|
|
182
|
+
return this.guard(async () => {
|
|
183
|
+
const memory = await this.client();
|
|
184
|
+
await memory.delete(id);
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
async update(id, metadata) {
|
|
188
|
+
return this.guard(async () => {
|
|
189
|
+
const memory = await this.client();
|
|
190
|
+
await memory.update(id, { metadata });
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
/** What "no limit" asks mem0 for. */
|
|
195
|
+
const EVERYTHING = 10_000;
|
|
196
|
+
/** What Qdrant accepts as a point id: a UUID, or an unsigned integer. */
|
|
197
|
+
const POINT_ID = /^(?:[0-9a-f]{8}-?[0-9a-f]{4}-?[0-9a-f]{4}-?[0-9a-f]{4}-?[0-9a-f]{12}|\d+)$/i;
|
|
198
|
+
/** OSS SearchFilters are snake_case, matching the hosted platform's. */
|
|
199
|
+
function scopeFilters(scope, runId) {
|
|
200
|
+
return {
|
|
201
|
+
user_id: scope.userId,
|
|
202
|
+
agent_id: scope.agentId,
|
|
203
|
+
...(runId && { run_id: runId }),
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
function toRecord(item) {
|
|
207
|
+
// `run_id` is where it actually arrives: mem0's oss `getAll` lifts the
|
|
208
|
+
// identity keys out of the payload in snake case and excludes them from the
|
|
209
|
+
// metadata it hands back. Reading only `runId` meant every record came back
|
|
210
|
+
// without the scope it was stored under, which is the one field that says
|
|
211
|
+
// whether a claim belongs to a repository or holds everywhere.
|
|
212
|
+
const runId = item.run_id ?? item.runId ?? item.metadata?.run_id ?? item.metadata?.runId;
|
|
213
|
+
// Lifted out the same way, and only by `get`: a filtered read leaves them off.
|
|
214
|
+
const userId = item.user_id ?? item.userId;
|
|
215
|
+
const agentId = item.agent_id ?? item.agentId;
|
|
216
|
+
return {
|
|
217
|
+
id: item.id,
|
|
218
|
+
memory: item.memory ?? '',
|
|
219
|
+
...(item.score !== undefined && { score: item.score }),
|
|
220
|
+
...(item.score_details?.semanticScore !== undefined && { similarity: item.score_details.semanticScore }),
|
|
221
|
+
...(item.createdAt && {
|
|
222
|
+
createdAt: new Date(item.createdAt).toISOString(),
|
|
223
|
+
}),
|
|
224
|
+
...(runId && { runId }),
|
|
225
|
+
...(userId && { userId }),
|
|
226
|
+
...(agentId && { agentId }),
|
|
227
|
+
...(item.metadata && { metadata: item.metadata }),
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
//# sourceMappingURL=oss.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"oss.js","sourceRoot":"","sources":["../../src/memory/oss.ts"],"names":[],"mappings":"AAAA,sEAAsE;AACtE,sEAAsE;AACtE,4DAA4D;AA+B5D;;;;;;;;;;;;;;;GAeG;AACH,MAAM,OAA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;QACzB,GAAG,CAAC,IAAI,CAAC,KAAK,KAAK,SAAS,IAAI,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,CAAC;QACtD,GAAG,CAAC,IAAI,CAAC,aAAa,EAAE,aAAa,KAAK,SAAS,IAAI,EAAE,UAAU,EAAE,IAAI,CAAC,aAAa,CAAC,aAAa,EAAE,CAAC;QACxG,GAAG,CAAC,IAAI,CAAC,SAAS,IAAI;YACpB,SAAS,EAAE,IAAI,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,WAAW,EAAE;SAClD,CAAC;QACF,GAAG,CAAC,KAAK,IAAI,EAAE,KAAK,EAAE,CAAC;QACvB,GAAG,CAAC,MAAM,IAAI,EAAE,MAAM,EAAE,CAAC;QACzB,GAAG,CAAC,OAAO,IAAI,EAAE,OAAO,EAAE,CAAC;QAC3B,GAAG,CAAC,IAAI,CAAC,QAAQ,IAAI,EAAE,QAAQ,EAAE,IAAI,CAAC,QAAQ,EAAE,CAAC;KAClD,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { AddOptions, ListOptions, MemoryMessage, MemoryRecord, MemoryScope, MemoryStore, SearchOptions } from './types.js';
|
|
2
|
+
export interface PlatformOptions {
|
|
3
|
+
apiKey: string;
|
|
4
|
+
host?: string;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Hosted Mem0 Platform adapter (api.mem0.ai).
|
|
8
|
+
*
|
|
9
|
+
* Two casing conventions collide in the v3 SDK and it is easy to get wrong:
|
|
10
|
+
* `add()` and `deleteAll()` take camelCase entity fields at the top level
|
|
11
|
+
* (`userId`) and snake_case them for the wire, but `search()` and `getAll()`
|
|
12
|
+
* pass `filters` through VERBATIM and reject top-level entity fields outright.
|
|
13
|
+
* So filters must be written snake_case (`user_id`) by hand.
|
|
14
|
+
*/
|
|
15
|
+
export declare class PlatformMemoryStore implements MemoryStore {
|
|
16
|
+
readonly backend: 'platform';
|
|
17
|
+
readonly enabled = true;
|
|
18
|
+
private client;
|
|
19
|
+
constructor(options: PlatformOptions);
|
|
20
|
+
search(query: string, scope: MemoryScope, options?: SearchOptions): Promise<MemoryRecord[]>;
|
|
21
|
+
add(messages: MemoryMessage[], scope: MemoryScope, options?: AddOptions): Promise<MemoryRecord[]>;
|
|
22
|
+
/**
|
|
23
|
+
* One page when a limit is given, and every page when not.
|
|
24
|
+
*
|
|
25
|
+
* The API pages its answer, so a single call with no page size returns the
|
|
26
|
+
* first page alone. A list that is quietly short reads as "that is
|
|
27
|
+
* everything", and recall reads a branch's thread through here in full.
|
|
28
|
+
*/
|
|
29
|
+
list(scope: MemoryScope, options?: ListOptions): Promise<MemoryRecord[]>;
|
|
30
|
+
clear(scope: MemoryScope, options?: {
|
|
31
|
+
runId?: string;
|
|
32
|
+
}): Promise<number>;
|
|
33
|
+
get(id: string): Promise<MemoryRecord | undefined>;
|
|
34
|
+
delete(id: string): Promise<void>;
|
|
35
|
+
update(id: string, metadata: Record<string, unknown>): Promise<void>;
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=platform.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"platform.d.ts","sourceRoot":"","sources":["../../src/memory/platform.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EACV,UAAU,EACV,WAAW,EACX,aAAa,EACb,YAAY,EACZ,WAAW,EACX,WAAW,EACX,aAAa,EACd,MAAM,YAAY,CAAC;AAEpB,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED;;;;;;;;GAQG;AACH,qBAAa,mBAAoB,YAAW,WAAW;IACrD,QAAQ,CAAC,OAAO,EAAG,UAAU,CAAU;IACvC,QAAQ,CAAC,OAAO,QAAQ;IACxB,OAAO,CAAC,MAAM,CAAe;IAE7B,YAAY,OAAO,EAAE,eAAe,EAMnC;IAEK,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,EAAE,OAAO,GAAE,aAAkB,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC,CAOpG;IAEK,GAAG,CAAC,QAAQ,EAAE,aAAa,EAAE,EAAE,KAAK,EAAE,WAAW,EAAE,OAAO,GAAE,UAAe,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC,CAU1G;IAED;;;;;;OAMG;IACG,IAAI,CAAC,KAAK,EAAE,WAAW,EAAE,OAAO,GAAE,WAAgB,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC,CAejF;IAEK,KAAK,CAAC,KAAK,EAAE,WAAW,EAAE,OAAO,GAAE;QAAE,KAAK,CAAC,EAAE,MAAM,CAAA;KAAO,GAAG,OAAO,CAAC,MAAM,CAAC,CAajF;IAEK,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,GAAG,SAAS,CAAC,CASvD;IAEK,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAEtC;IAEK,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAEzE;CACF"}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
// This Source Code Form is subject to the terms of the Mozilla Public
|
|
2
|
+
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
3
|
+
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
4
|
+
// Named, not default: mem0ai's exports map points the `import` condition at its
|
|
5
|
+
// CJS declarations, where the default export resolves to a namespace rather
|
|
6
|
+
// than a constructable class.
|
|
7
|
+
import { MemoryClient } from 'mem0ai';
|
|
8
|
+
/**
|
|
9
|
+
* Hosted Mem0 Platform adapter (api.mem0.ai).
|
|
10
|
+
*
|
|
11
|
+
* Two casing conventions collide in the v3 SDK and it is easy to get wrong:
|
|
12
|
+
* `add()` and `deleteAll()` take camelCase entity fields at the top level
|
|
13
|
+
* (`userId`) and snake_case them for the wire, but `search()` and `getAll()`
|
|
14
|
+
* pass `filters` through VERBATIM and reject top-level entity fields outright.
|
|
15
|
+
* So filters must be written snake_case (`user_id`) by hand.
|
|
16
|
+
*/
|
|
17
|
+
export class PlatformMemoryStore {
|
|
18
|
+
backend = 'platform';
|
|
19
|
+
enabled = true;
|
|
20
|
+
client;
|
|
21
|
+
constructor(options) {
|
|
22
|
+
if (!options.apiKey)
|
|
23
|
+
throw new Error('MEM0_API_KEY is required for the platform memory backend.');
|
|
24
|
+
this.client = new MemoryClient({
|
|
25
|
+
apiKey: options.apiKey,
|
|
26
|
+
...(options.host && { host: options.host }),
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
async search(query, scope, options = {}) {
|
|
30
|
+
const response = await this.client.search(query, {
|
|
31
|
+
filters: scopeFilters(scope, scope.runId),
|
|
32
|
+
...(options.topK !== undefined && { topK: options.topK }),
|
|
33
|
+
...(options.threshold !== undefined && { threshold: options.threshold }),
|
|
34
|
+
});
|
|
35
|
+
return (response?.results ?? []).map(toRecord);
|
|
36
|
+
}
|
|
37
|
+
async add(messages, scope, options = {}) {
|
|
38
|
+
const written = await this.client.add(messages, {
|
|
39
|
+
userId: scope.userId,
|
|
40
|
+
agentId: scope.agentId,
|
|
41
|
+
...(scope.runId && { runId: scope.runId }),
|
|
42
|
+
...(options.metadata && { metadata: options.metadata }),
|
|
43
|
+
...(options.infer !== undefined && { infer: options.infer }),
|
|
44
|
+
});
|
|
45
|
+
// NOOP events mean Mem0 saw nothing new worth keeping — not a write.
|
|
46
|
+
return (written ?? []).filter((m) => m.event !== 'NOOP').map(toRecord);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* One page when a limit is given, and every page when not.
|
|
50
|
+
*
|
|
51
|
+
* The API pages its answer, so a single call with no page size returns the
|
|
52
|
+
* first page alone. A list that is quietly short reads as "that is
|
|
53
|
+
* everything", and recall reads a branch's thread through here in full.
|
|
54
|
+
*/
|
|
55
|
+
async list(scope, options = {}) {
|
|
56
|
+
const filters = scopeFilters(scope, options.runId ?? scope.runId);
|
|
57
|
+
if (options.limit !== undefined) {
|
|
58
|
+
const response = await this.client.getAll({ filters, pageSize: options.limit });
|
|
59
|
+
return (response?.results ?? []).map(toRecord);
|
|
60
|
+
}
|
|
61
|
+
const records = [];
|
|
62
|
+
for (let page = 1; page <= MAX_PAGES; page++) {
|
|
63
|
+
const response = await this.client.getAll({ filters, page, pageSize: PAGE_SIZE });
|
|
64
|
+
records.push(...(response?.results ?? []).map(toRecord));
|
|
65
|
+
if (!response?.next)
|
|
66
|
+
return records;
|
|
67
|
+
}
|
|
68
|
+
// Still more after the last page. Returning what was read would be the
|
|
69
|
+
// same quiet shortfall, so say it cannot be read whole.
|
|
70
|
+
throw new Error(`more than ${MAX_PAGES * PAGE_SIZE} memories in this scope — too many to list in full`);
|
|
71
|
+
}
|
|
72
|
+
async clear(scope, options = {}) {
|
|
73
|
+
// deleteAll refuses an unfiltered call, so the scope always goes with it —
|
|
74
|
+
// and the scope's own run id narrows it the same way it narrows a read.
|
|
75
|
+
// Without that, "forget what you know about this repository" deletes
|
|
76
|
+
// everything this agent knows about the user.
|
|
77
|
+
const runId = options.runId ?? scope.runId;
|
|
78
|
+
const existing = await this.list(scope, { runId });
|
|
79
|
+
await this.client.deleteAll({
|
|
80
|
+
userId: scope.userId,
|
|
81
|
+
agentId: scope.agentId,
|
|
82
|
+
...(runId && { runId }),
|
|
83
|
+
});
|
|
84
|
+
return existing.length;
|
|
85
|
+
}
|
|
86
|
+
async get(id) {
|
|
87
|
+
try {
|
|
88
|
+
return toRecord(await this.client.get(id));
|
|
89
|
+
}
|
|
90
|
+
catch (err) {
|
|
91
|
+
// A missing id is a 404, and one the API cannot parse a 400. Both mean
|
|
92
|
+
// there is no such memory; anything else is the service failing.
|
|
93
|
+
if (err?.errorCode === 'HTTP_404' || err?.errorCode === 'HTTP_400')
|
|
94
|
+
return undefined;
|
|
95
|
+
throw err;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
async delete(id) {
|
|
99
|
+
await this.client.delete(id);
|
|
100
|
+
}
|
|
101
|
+
async update(id, metadata) {
|
|
102
|
+
await this.client.update(id, { metadata });
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
/** Memories per page when listing everything, and how many pages at most. */
|
|
106
|
+
const PAGE_SIZE = 100;
|
|
107
|
+
const MAX_PAGES = 100;
|
|
108
|
+
/** Search/getAll filters are sent verbatim, so they must be snake_case. */
|
|
109
|
+
function scopeFilters(scope, runId) {
|
|
110
|
+
return {
|
|
111
|
+
user_id: scope.userId,
|
|
112
|
+
agent_id: scope.agentId,
|
|
113
|
+
...(runId && { run_id: runId }),
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
function toRecord(memory) {
|
|
117
|
+
return {
|
|
118
|
+
id: memory.id,
|
|
119
|
+
// v3 returns the text on `memory`; older/add responses nest it under `data`.
|
|
120
|
+
memory: memory.memory ?? memory.data?.memory ?? '',
|
|
121
|
+
...(memory.score !== undefined && { score: memory.score }),
|
|
122
|
+
...(memory.createdAt && { createdAt: new Date(memory.createdAt).toISOString() }),
|
|
123
|
+
// Both spellings: the hosted client returns camelCase on some routes and
|
|
124
|
+
// the API's own snake_case on others.
|
|
125
|
+
...((memory.runId ?? memory.run_id) && { runId: memory.runId ?? memory.run_id }),
|
|
126
|
+
...((memory.userId ?? memory.user_id) && { userId: memory.userId ?? memory.user_id }),
|
|
127
|
+
...((memory.agentId ?? memory.agent_id) && { agentId: memory.agentId ?? memory.agent_id }),
|
|
128
|
+
...(memory.metadata && { metadata: memory.metadata }),
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
//# sourceMappingURL=platform.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"platform.js","sourceRoot":"","sources":["../../src/memory/platform.ts"],"names":[],"mappings":"AAAA,sEAAsE;AACtE,sEAAsE;AACtE,4D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AAC,MAAM,EAAE,CAAC;QAChF,GAAG,CAAC,CAAC,MAAM,CAAC,MAAM,IAAI,MAAM,CAAC,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;QACrF,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,IAAI,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE,OAAO,EAAE,MAAM,CAAC,OAAO,IAAI,MAAM,CAAC,QAAQ,EAAE,CAAC;QAC1F,GAAG,CAAC,MAAM,CAAC,QAAQ,IAAI,EAAE,QAAQ,EAAE,MAAM,CAAC,QAAQ,EAAE,CAAC;KACtD,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { AgentConfig } from '../config.js';
|
|
2
|
+
import type { MemoryScope } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Which of the three scopes a memory belongs to.
|
|
5
|
+
*
|
|
6
|
+
* The axis is `runId`, which is why it stops meaning "one CLI invocation" the
|
|
7
|
+
* moment anything is remembered about code: a thread about a change has to
|
|
8
|
+
* survive across runs, and a transcript's name cannot. Three scopes, told apart
|
|
9
|
+
* by prefix so one filter serves all of them:
|
|
10
|
+
*
|
|
11
|
+
* - **target** — `local:<repo>@<branch>` — one change under review: what was
|
|
12
|
+
* found on it, and what you said back. A PR target is `github:owner/repo#42`,
|
|
13
|
+
* which arrives with the GitHub work.
|
|
14
|
+
* - **repo** — `repo:<repo>` — what this repository is like: its conventions,
|
|
15
|
+
* its invariants, the things that are true of it between changes.
|
|
16
|
+
* - **user** — no id at all — what holds wherever you are reviewing.
|
|
17
|
+
*
|
|
18
|
+
* A class rather than three string templates because the prefixes are a
|
|
19
|
+
* protocol: `Scope.repo(...)` written in one place and parsed in another is how
|
|
20
|
+
* conventions stop being recalled in the wrong repository.
|
|
21
|
+
*/
|
|
22
|
+
export declare class Scope {
|
|
23
|
+
/** The `runId` this scope filters on. Absent is user scope, not "any". */
|
|
24
|
+
readonly id: string | undefined;
|
|
25
|
+
private constructor();
|
|
26
|
+
/** Everything that holds wherever you are reviewing. */
|
|
27
|
+
static user(): Scope;
|
|
28
|
+
/** One repository, by its local identity. */
|
|
29
|
+
static repo(root: string): Scope;
|
|
30
|
+
/**
|
|
31
|
+
* One change under review.
|
|
32
|
+
*
|
|
33
|
+
* Keyed to the branch, since that is what a local change is: a branch is a
|
|
34
|
+
* moving pointer, and the thread is about the work on it rather than about
|
|
35
|
+
* any one commit.
|
|
36
|
+
*/
|
|
37
|
+
static target(root: string, branch: string): Scope;
|
|
38
|
+
get isUser(): boolean;
|
|
39
|
+
/**
|
|
40
|
+
* The scope as the store takes it.
|
|
41
|
+
*
|
|
42
|
+
* `resolveScope` does the same for a raw session id. Both exist because a
|
|
43
|
+
* session is not one of the three — it is a transcript, and the prompt path
|
|
44
|
+
* attributes memories to one without claiming they are about code.
|
|
45
|
+
*/
|
|
46
|
+
for(config: AgentConfig): MemoryScope;
|
|
47
|
+
toString(): string;
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=scope.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scope.d.ts","sourceRoot":"","sources":["../../src/memory/scope.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAEhD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE9C;;;;;;;;;;;;;;;;;;GAkBG;AACH,qBAAa,KAAK;IAEd,0EAA0E;IAC1E,QAAQ,CAAC,EAAE,EAAE,MAAM,GAAG,SAAS;IAFjC,OAAO,eAGH;IAEJ,wDAAwD;IACxD,MAAM,CAAC,IAAI,IAAI,KAAK,CAEnB;IAED,6CAA6C;IAC7C,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,KAAK,CAE/B;IAED;;;;;;OAMG;IACH,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,KAAK,CAEjD;IAED,IAAI,MAAM,IAAI,OAAO,CAEpB;IAED;;;;;;OAMG;IACH,GAAG,CAAC,MAAM,EAAE,WAAW,GAAG,WAAW,CAMpC;IAED,QAAQ,IAAI,MAAM,CAEjB;CACF"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
// This Source Code Form is subject to the terms of the Mozilla Public
|
|
2
|
+
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
3
|
+
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
4
|
+
import { repoSlug } from '../target.js';
|
|
5
|
+
/**
|
|
6
|
+
* Which of the three scopes a memory belongs to.
|
|
7
|
+
*
|
|
8
|
+
* The axis is `runId`, which is why it stops meaning "one CLI invocation" the
|
|
9
|
+
* moment anything is remembered about code: a thread about a change has to
|
|
10
|
+
* survive across runs, and a transcript's name cannot. Three scopes, told apart
|
|
11
|
+
* by prefix so one filter serves all of them:
|
|
12
|
+
*
|
|
13
|
+
* - **target** — `local:<repo>@<branch>` — one change under review: what was
|
|
14
|
+
* found on it, and what you said back. A PR target is `github:owner/repo#42`,
|
|
15
|
+
* which arrives with the GitHub work.
|
|
16
|
+
* - **repo** — `repo:<repo>` — what this repository is like: its conventions,
|
|
17
|
+
* its invariants, the things that are true of it between changes.
|
|
18
|
+
* - **user** — no id at all — what holds wherever you are reviewing.
|
|
19
|
+
*
|
|
20
|
+
* A class rather than three string templates because the prefixes are a
|
|
21
|
+
* protocol: `Scope.repo(...)` written in one place and parsed in another is how
|
|
22
|
+
* conventions stop being recalled in the wrong repository.
|
|
23
|
+
*/
|
|
24
|
+
export class Scope {
|
|
25
|
+
id;
|
|
26
|
+
constructor(
|
|
27
|
+
/** The `runId` this scope filters on. Absent is user scope, not "any". */
|
|
28
|
+
id) {
|
|
29
|
+
this.id = id;
|
|
30
|
+
}
|
|
31
|
+
/** Everything that holds wherever you are reviewing. */
|
|
32
|
+
static user() {
|
|
33
|
+
return new Scope(undefined);
|
|
34
|
+
}
|
|
35
|
+
/** One repository, by its local identity. */
|
|
36
|
+
static repo(root) {
|
|
37
|
+
return new Scope(`repo:${repoSlug(root)}`);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* One change under review.
|
|
41
|
+
*
|
|
42
|
+
* Keyed to the branch, since that is what a local change is: a branch is a
|
|
43
|
+
* moving pointer, and the thread is about the work on it rather than about
|
|
44
|
+
* any one commit.
|
|
45
|
+
*/
|
|
46
|
+
static target(root, branch) {
|
|
47
|
+
return new Scope(`local:${repoSlug(root)}@${branch}`);
|
|
48
|
+
}
|
|
49
|
+
get isUser() {
|
|
50
|
+
return this.id === undefined;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* The scope as the store takes it.
|
|
54
|
+
*
|
|
55
|
+
* `resolveScope` does the same for a raw session id. Both exist because a
|
|
56
|
+
* session is not one of the three — it is a transcript, and the prompt path
|
|
57
|
+
* attributes memories to one without claiming they are about code.
|
|
58
|
+
*/
|
|
59
|
+
for(config) {
|
|
60
|
+
return {
|
|
61
|
+
userId: config.memory.userId,
|
|
62
|
+
agentId: config.memory.agentId,
|
|
63
|
+
...(this.id && { runId: this.id }),
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
toString() {
|
|
67
|
+
return this.id ?? 'user';
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=scope.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scope.js","sourceRoot":"","sources":["../../src/memory/scope.ts"],"names":[],"mappings":"AAAA,sEAAsE;AACtE,sEAAsE;AACtE,4DAA4D;AAG5D,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAGxC;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,OAAO,KAAK;IAGL,EAAE;IAFb;IACE,0EAA0E;IACjE,EAAsB;kBAAtB,EAAE;IACV,CAAC;IAEJ,wDAAwD;IACxD,MAAM,CAAC,IAAI;QACT,OAAO,IAAI,KAAK,CAAC,SAAS,CAAC,CAAC;IAC9B,CAAC;IAED,6CAA6C;IAC7C,MAAM,CAAC,IAAI,CAAC,IAAY;QACtB,OAAO,IAAI,KAAK,CAAC,QAAQ,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAC7C,CAAC;IAED;;;;;;OAMG;IACH,MAAM,CAAC,MAAM,CAAC,IAAY,EAAE,MAAc;QACxC,OAAO,IAAI,KAAK,CAAC,SAAS,QAAQ,CAAC,IAAI,CAAC,IAAI,MAAM,EAAE,CAAC,CAAC;IACxD,CAAC;IAED,IAAI,MAAM;QACR,OAAO,IAAI,CAAC,EAAE,KAAK,SAAS,CAAC;IAC/B,CAAC;IAED;;;;;;OAMG;IACH,GAAG,CAAC,MAAmB;QACrB,OAAO;YACL,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,MAAM;YAC5B,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,OAAO;YAC9B,GAAG,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC;SACnC,CAAC;IACJ,CAAC;IAED,QAAQ;QACN,OAAO,IAAI,CAAC,EAAE,IAAI,MAAM,CAAC;IAC3B,CAAC;CACF"}
|