@ai-agent-forge/plugin-sdk 0.85.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/README.md +27 -0
- package/dist/artifact.d.ts +20 -0
- package/dist/artifact.d.ts.map +1 -0
- package/dist/artifact.js +63 -0
- package/dist/artifact.js.map +1 -0
- package/dist/capability-manifest.d.ts +11 -0
- package/dist/capability-manifest.d.ts.map +1 -0
- package/dist/capability-manifest.js +188 -0
- package/dist/capability-manifest.js.map +1 -0
- package/dist/common.d.ts +24 -0
- package/dist/common.d.ts.map +1 -0
- package/dist/common.js +115 -0
- package/dist/common.js.map +1 -0
- package/dist/context-budget.d.ts +33 -0
- package/dist/context-budget.d.ts.map +1 -0
- package/dist/context-budget.js +124 -0
- package/dist/context-budget.js.map +1 -0
- package/dist/diff.d.ts +38 -0
- package/dist/diff.d.ts.map +1 -0
- package/dist/diff.js +164 -0
- package/dist/diff.js.map +1 -0
- package/dist/durable.d.ts +108 -0
- package/dist/durable.d.ts.map +1 -0
- package/dist/durable.js +15 -0
- package/dist/durable.js.map +1 -0
- package/dist/ecosystem-manifest.d.ts +56 -0
- package/dist/ecosystem-manifest.d.ts.map +1 -0
- package/dist/ecosystem-manifest.js +11 -0
- package/dist/ecosystem-manifest.js.map +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +13 -0
- package/dist/index.js.map +1 -0
- package/dist/memory.d.ts +370 -0
- package/dist/memory.d.ts.map +1 -0
- package/dist/memory.js +26 -0
- package/dist/memory.js.map +1 -0
- package/dist/observability.d.ts +354 -0
- package/dist/observability.d.ts.map +1 -0
- package/dist/observability.js +33 -0
- package/dist/observability.js.map +1 -0
- package/dist/operation.d.ts +60 -0
- package/dist/operation.d.ts.map +1 -0
- package/dist/operation.js +202 -0
- package/dist/operation.js.map +1 -0
- package/dist/public-api.d.ts +1977 -0
- package/dist/public-api.d.ts.map +1 -0
- package/dist/public-api.js +237 -0
- package/dist/public-api.js.map +1 -0
- package/dist/render.d.ts +38 -0
- package/dist/render.d.ts.map +1 -0
- package/dist/render.js +112 -0
- package/dist/render.js.map +1 -0
- package/dist/session-lineage.d.ts +36 -0
- package/dist/session-lineage.d.ts.map +1 -0
- package/dist/session-lineage.js +134 -0
- package/dist/session-lineage.js.map +1 -0
- package/package.json +55 -0
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ecosystem package manifest schema (agent-forge.json), V1.
|
|
3
|
+
*
|
|
4
|
+
* These types describe compatibility facts only. They intentionally do not
|
|
5
|
+
* contain approval, sandbox, credential, or domain-specific policy.
|
|
6
|
+
*
|
|
7
|
+
* Authority: `@agent-forge/plugin-sdk` (D-075 S2); the host re-exports them from
|
|
8
|
+
* its ecosystem contracts module so existing imports keep resolving.
|
|
9
|
+
*/
|
|
10
|
+
export type PluginOperatingSystem = "windows" | "macos" | "linux" | "any";
|
|
11
|
+
export type PluginArchitecture = "x64" | "arm64" | "any";
|
|
12
|
+
export interface CapabilityRefV1 {
|
|
13
|
+
readonly id: string;
|
|
14
|
+
/** Exact capability schema version. A breaking schema change increments it. */
|
|
15
|
+
readonly version: number;
|
|
16
|
+
}
|
|
17
|
+
export interface RuntimeConstraintV1 {
|
|
18
|
+
readonly name: string;
|
|
19
|
+
readonly minVersion?: string;
|
|
20
|
+
readonly maxVersion?: string;
|
|
21
|
+
}
|
|
22
|
+
export interface PluginAdapterManifestV1 {
|
|
23
|
+
readonly id: string;
|
|
24
|
+
readonly version: string;
|
|
25
|
+
readonly os: readonly PluginOperatingSystem[];
|
|
26
|
+
readonly arch?: readonly PluginArchitecture[];
|
|
27
|
+
readonly hostFeatures?: readonly string[];
|
|
28
|
+
}
|
|
29
|
+
export interface PluginPlatformBindingV1 {
|
|
30
|
+
readonly os: readonly PluginOperatingSystem[];
|
|
31
|
+
readonly arch?: readonly PluginArchitecture[];
|
|
32
|
+
readonly runtime?: readonly RuntimeConstraintV1[];
|
|
33
|
+
readonly hostFeatures?: readonly string[];
|
|
34
|
+
readonly adapters?: readonly PluginAdapterManifestV1[];
|
|
35
|
+
}
|
|
36
|
+
export interface CapabilityRequirementV1 extends CapabilityRefV1 {
|
|
37
|
+
readonly optional?: boolean;
|
|
38
|
+
}
|
|
39
|
+
/** Versioned package manifest consumed by the deterministic resolver. */
|
|
40
|
+
export interface PluginManifestV1 {
|
|
41
|
+
readonly id: string;
|
|
42
|
+
/** Package release version (normally MAJOR.MINOR.PATCH). */
|
|
43
|
+
readonly pluginVersion: string;
|
|
44
|
+
/** Public host API version required by this package. */
|
|
45
|
+
readonly apiVersion: string;
|
|
46
|
+
/** Minimum host version required to load this package; the host must be >= this version. */
|
|
47
|
+
readonly minHostVersion?: string;
|
|
48
|
+
/** Maximum host version supported by this package; the host must be <= this version. */
|
|
49
|
+
readonly maxHostVersion?: string;
|
|
50
|
+
readonly capabilityRefs?: readonly CapabilityRefV1[];
|
|
51
|
+
readonly requires?: readonly CapabilityRequirementV1[];
|
|
52
|
+
readonly platform?: PluginPlatformBindingV1;
|
|
53
|
+
/** A contract/mock package that must never be selected for a production Profile. */
|
|
54
|
+
readonly testOnly?: boolean;
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=ecosystem-manifest.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ecosystem-manifest.d.ts","sourceRoot":"","sources":["../src/ecosystem-manifest.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,MAAM,MAAM,qBAAqB,GAAG,SAAS,GAAG,OAAO,GAAG,OAAO,GAAG,KAAK,CAAC;AAC1E,MAAM,MAAM,kBAAkB,GAAG,KAAK,GAAG,OAAO,GAAG,KAAK,CAAC;AAEzD,MAAM,WAAW,eAAe;IAC/B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,+EAA+E;IAC/E,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,WAAW,mBA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C;IACjC,QAAQ,CAAC,cAAc,CAAC,EAAE,SAAS,eAAe,EAAE,CAAC;IACrD,QAAQ,CAAC,QAAQ,CAAC,EAAE,SAAS,uBAAuB,EAAE,CAAC;IACvD,QAAQ,CAAC,QAAQ,CAAC,EAAE,uBAAuB,CAAC;IAC5C,oFAAoF;IACpF,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;CAC5B","sourcesContent":["/**\n * Ecosystem package manifest schema (agent-forge.json), V1.\n *\n * These types describe compatibility facts only. They intentionally do not\n * contain approval, sandbox, credential, or domain-specific policy.\n *\n * Authority: `@agent-forge/plugin-sdk` (D-075 S2); the host re-exports them from\n * its ecosystem contracts module so existing imports keep resolving.\n */\n\nexport type PluginOperatingSystem = \"windows\" | \"macos\" | \"linux\" | \"any\";\nexport type PluginArchitecture = \"x64\" | \"arm64\" | \"any\";\n\nexport interface CapabilityRefV1 {\n\treadonly id: string;\n\t/** Exact capability schema version. A breaking schema change increments it. */\n\treadonly version: number;\n}\n\nexport interface RuntimeConstraintV1 {\n\treadonly name: string;\n\treadonly minVersion?: string;\n\treadonly maxVersion?: string;\n}\n\nexport interface PluginAdapterManifestV1 {\n\treadonly id: string;\n\treadonly version: string;\n\treadonly os: readonly PluginOperatingSystem[];\n\treadonly arch?: readonly PluginArchitecture[];\n\treadonly hostFeatures?: readonly string[];\n}\n\nexport interface PluginPlatformBindingV1 {\n\treadonly os: readonly PluginOperatingSystem[];\n\treadonly arch?: readonly PluginArchitecture[];\n\treadonly runtime?: readonly RuntimeConstraintV1[];\n\treadonly hostFeatures?: readonly string[];\n\treadonly adapters?: readonly PluginAdapterManifestV1[];\n}\n\nexport interface CapabilityRequirementV1 extends CapabilityRefV1 {\n\treadonly optional?: boolean;\n}\n\n/** Versioned package manifest consumed by the deterministic resolver. */\nexport interface PluginManifestV1 {\n\treadonly id: string;\n\t/** Package release version (normally MAJOR.MINOR.PATCH). */\n\treadonly pluginVersion: string;\n\t/** Public host API version required by this package. */\n\treadonly apiVersion: string;\n\t/** Minimum host version required to load this package; the host must be >= this version. */\n\treadonly minHostVersion?: string;\n\t/** Maximum host version supported by this package; the host must be <= this version. */\n\treadonly maxHostVersion?: string;\n\treadonly capabilityRefs?: readonly CapabilityRefV1[];\n\treadonly requires?: readonly CapabilityRequirementV1[];\n\treadonly platform?: PluginPlatformBindingV1;\n\t/** A contract/mock package that must never be selected for a production Profile. */\n\treadonly testOnly?: boolean;\n}\n"]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ecosystem package manifest schema (agent-forge.json), V1.
|
|
3
|
+
*
|
|
4
|
+
* These types describe compatibility facts only. They intentionally do not
|
|
5
|
+
* contain approval, sandbox, credential, or domain-specific policy.
|
|
6
|
+
*
|
|
7
|
+
* Authority: `@agent-forge/plugin-sdk` (D-075 S2); the host re-exports them from
|
|
8
|
+
* its ecosystem contracts module so existing imports keep resolving.
|
|
9
|
+
*/
|
|
10
|
+
export {};
|
|
11
|
+
//# sourceMappingURL=ecosystem-manifest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ecosystem-manifest.js","sourceRoot":"","sources":["../src/ecosystem-manifest.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG","sourcesContent":["/**\n * Ecosystem package manifest schema (agent-forge.json), V1.\n *\n * These types describe compatibility facts only. They intentionally do not\n * contain approval, sandbox, credential, or domain-specific policy.\n *\n * Authority: `@agent-forge/plugin-sdk` (D-075 S2); the host re-exports them from\n * its ecosystem contracts module so existing imports keep resolving.\n */\n\nexport type PluginOperatingSystem = \"windows\" | \"macos\" | \"linux\" | \"any\";\nexport type PluginArchitecture = \"x64\" | \"arm64\" | \"any\";\n\nexport interface CapabilityRefV1 {\n\treadonly id: string;\n\t/** Exact capability schema version. A breaking schema change increments it. */\n\treadonly version: number;\n}\n\nexport interface RuntimeConstraintV1 {\n\treadonly name: string;\n\treadonly minVersion?: string;\n\treadonly maxVersion?: string;\n}\n\nexport interface PluginAdapterManifestV1 {\n\treadonly id: string;\n\treadonly version: string;\n\treadonly os: readonly PluginOperatingSystem[];\n\treadonly arch?: readonly PluginArchitecture[];\n\treadonly hostFeatures?: readonly string[];\n}\n\nexport interface PluginPlatformBindingV1 {\n\treadonly os: readonly PluginOperatingSystem[];\n\treadonly arch?: readonly PluginArchitecture[];\n\treadonly runtime?: readonly RuntimeConstraintV1[];\n\treadonly hostFeatures?: readonly string[];\n\treadonly adapters?: readonly PluginAdapterManifestV1[];\n}\n\nexport interface CapabilityRequirementV1 extends CapabilityRefV1 {\n\treadonly optional?: boolean;\n}\n\n/** Versioned package manifest consumed by the deterministic resolver. */\nexport interface PluginManifestV1 {\n\treadonly id: string;\n\t/** Package release version (normally MAJOR.MINOR.PATCH). */\n\treadonly pluginVersion: string;\n\t/** Public host API version required by this package. */\n\treadonly apiVersion: string;\n\t/** Minimum host version required to load this package; the host must be >= this version. */\n\treadonly minHostVersion?: string;\n\t/** Maximum host version supported by this package; the host must be <= this version. */\n\treadonly maxHostVersion?: string;\n\treadonly capabilityRefs?: readonly CapabilityRefV1[];\n\treadonly requires?: readonly CapabilityRequirementV1[];\n\treadonly platform?: PluginPlatformBindingV1;\n\t/** A contract/mock package that must never be selected for a production Profile. */\n\treadonly testOnly?: boolean;\n}\n"]}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export * from "./artifact.ts";
|
|
2
|
+
export * from "./capability-manifest.ts";
|
|
3
|
+
export * from "./common.ts";
|
|
4
|
+
export * from "./context-budget.ts";
|
|
5
|
+
export * from "./diff.ts";
|
|
6
|
+
export * from "./durable.ts";
|
|
7
|
+
export * from "./ecosystem-manifest.ts";
|
|
8
|
+
export * from "./memory.ts";
|
|
9
|
+
export * from "./observability.ts";
|
|
10
|
+
export * from "./operation.ts";
|
|
11
|
+
export * from "./public-api.ts";
|
|
12
|
+
export * from "./render.ts";
|
|
13
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,0BAA0B,CAAC;AACzC,cAAc,aAAa,CAAC;AAC5B,cAAc,qBAAqB,CAAC;AACpC,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,yBAAyB,CAAC;AACxC,cAAc,aAAa,CAAC;AAC5B,cAAc,oBAAoB,CAAC;AACnC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,aAAa,CAAC","sourcesContent":["export * from \"./artifact.ts\";\nexport * from \"./capability-manifest.ts\";\nexport * from \"./common.ts\";\nexport * from \"./context-budget.ts\";\nexport * from \"./diff.ts\";\nexport * from \"./durable.ts\";\nexport * from \"./ecosystem-manifest.ts\";\nexport * from \"./memory.ts\";\nexport * from \"./observability.ts\";\nexport * from \"./operation.ts\";\nexport * from \"./public-api.ts\";\nexport * from \"./render.ts\";\n"]}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export * from "./artifact.js";
|
|
2
|
+
export * from "./capability-manifest.js";
|
|
3
|
+
export * from "./common.js";
|
|
4
|
+
export * from "./context-budget.js";
|
|
5
|
+
export * from "./diff.js";
|
|
6
|
+
export * from "./durable.js";
|
|
7
|
+
export * from "./ecosystem-manifest.js";
|
|
8
|
+
export * from "./memory.js";
|
|
9
|
+
export * from "./observability.js";
|
|
10
|
+
export * from "./operation.js";
|
|
11
|
+
export * from "./public-api.js";
|
|
12
|
+
export * from "./render.js";
|
|
13
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,0BAA0B,CAAC;AACzC,cAAc,aAAa,CAAC;AAC5B,cAAc,qBAAqB,CAAC;AACpC,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,yBAAyB,CAAC;AACxC,cAAc,aAAa,CAAC;AAC5B,cAAc,oBAAoB,CAAC;AACnC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,aAAa,CAAC","sourcesContent":["export * from \"./artifact.ts\";\nexport * from \"./capability-manifest.ts\";\nexport * from \"./common.ts\";\nexport * from \"./context-budget.ts\";\nexport * from \"./diff.ts\";\nexport * from \"./durable.ts\";\nexport * from \"./ecosystem-manifest.ts\";\nexport * from \"./memory.ts\";\nexport * from \"./observability.ts\";\nexport * from \"./operation.ts\";\nexport * from \"./public-api.ts\";\nexport * from \"./render.ts\";\n"]}
|
package/dist/memory.d.ts
ADDED
|
@@ -0,0 +1,370 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public contracts for the first-party memory capability (M5 Memory
|
|
3
|
+
* Foundation + the builtin memory family). The plugin package
|
|
4
|
+
* (`@agent-forge/plugin-memory`) is the implementation; this module is the
|
|
5
|
+
* single authoring authority for its public types and the host-facing storage
|
|
6
|
+
* injection contract. The host re-exports the surface from its historical
|
|
7
|
+
* module paths so existing imports keep resolving.
|
|
8
|
+
*
|
|
9
|
+
* Types only, plus the `MEMORY_RECALL_TOOL_NAME` contract constant: the
|
|
10
|
+
* recall tool name is pinned here because the host's B1 auto-recall path
|
|
11
|
+
* calls it by name (`runtime.invokeTool`) and replacement memory backends
|
|
12
|
+
* take over the same link by registering the same-named tool.
|
|
13
|
+
*
|
|
14
|
+
* Authority moved from the host's `capabilities/memory.ts` and
|
|
15
|
+
* `src/memory/*` (D-075 S4 fourth batch, first slice): every symbol below is
|
|
16
|
+
* a verbatim structural copy of its host definition; the transitive type
|
|
17
|
+
* chain (canonical atom, store, ledger, vector components) migrated with it
|
|
18
|
+
* so plugin authors never import host internals.
|
|
19
|
+
*/
|
|
20
|
+
import type { JsonValue } from "./common.ts";
|
|
21
|
+
/** Source of one memory: where the fact came from, optionally pinned by revision/digest. */
|
|
22
|
+
export interface MemorySourceRefV1 {
|
|
23
|
+
readonly kind: "session" | "entry" | "artifact" | "tool" | "state";
|
|
24
|
+
readonly id: string;
|
|
25
|
+
readonly revision?: string;
|
|
26
|
+
readonly digest?: string;
|
|
27
|
+
}
|
|
28
|
+
/** Namespace-scoped search facet. Facets are atom facts, never derived. */
|
|
29
|
+
export interface MemoryFacetV1 {
|
|
30
|
+
readonly namespace: string;
|
|
31
|
+
readonly schemaVersion: number;
|
|
32
|
+
readonly key: string;
|
|
33
|
+
readonly value: string;
|
|
34
|
+
}
|
|
35
|
+
/** Typed relation between atoms. Weights/validity belong to projections, not here. */
|
|
36
|
+
export interface MemoryRelationV1 {
|
|
37
|
+
readonly relationId: string;
|
|
38
|
+
readonly namespace: string;
|
|
39
|
+
readonly schemaVersion: number;
|
|
40
|
+
readonly kind: string;
|
|
41
|
+
readonly targetMemoryId?: string;
|
|
42
|
+
readonly targetRef?: MemorySourceRefV1;
|
|
43
|
+
readonly confidence?: number;
|
|
44
|
+
readonly relationRevision: string;
|
|
45
|
+
}
|
|
46
|
+
export interface MemoryTimeRangeV1 {
|
|
47
|
+
readonly from?: string;
|
|
48
|
+
readonly to?: string;
|
|
49
|
+
}
|
|
50
|
+
/** Applicability narrowing; empty means "applies without narrowing". */
|
|
51
|
+
export interface MemoryApplicabilityV1 {
|
|
52
|
+
readonly scenes?: readonly string[];
|
|
53
|
+
readonly projects?: readonly string[];
|
|
54
|
+
readonly tasks?: readonly string[];
|
|
55
|
+
readonly timeRange?: MemoryTimeRangeV1;
|
|
56
|
+
readonly exceptions?: readonly string[];
|
|
57
|
+
}
|
|
58
|
+
/** Preference envelope: the generic schema frozen for 1C; policy semantics come later. */
|
|
59
|
+
export interface MemoryPreferenceEnvelopeV1 {
|
|
60
|
+
readonly subject: "user" | "project" | "task" | "environment";
|
|
61
|
+
readonly key: string;
|
|
62
|
+
readonly preferredValue: JsonValue;
|
|
63
|
+
readonly alternatives?: readonly JsonValue[];
|
|
64
|
+
readonly scope: {
|
|
65
|
+
readonly level: "task" | "project" | "scene" | "timeRange" | "profile-private" | "user-default";
|
|
66
|
+
readonly scenes?: readonly string[];
|
|
67
|
+
readonly projects?: readonly string[];
|
|
68
|
+
readonly tasks?: readonly string[];
|
|
69
|
+
readonly timeRange?: MemoryTimeRangeV1;
|
|
70
|
+
readonly exceptions?: readonly string[];
|
|
71
|
+
};
|
|
72
|
+
readonly evidence: {
|
|
73
|
+
readonly class: "explicit" | "repeated_behavior" | "inferred";
|
|
74
|
+
readonly sourceRefs: readonly MemorySourceRefV1[];
|
|
75
|
+
readonly confidence: number;
|
|
76
|
+
};
|
|
77
|
+
readonly applicabilityConfidence: number;
|
|
78
|
+
readonly confirmedAt?: string;
|
|
79
|
+
}
|
|
80
|
+
/** Provenance for synthesis/compaction memories derived from other atoms. */
|
|
81
|
+
export interface MemoryProvenanceV1 {
|
|
82
|
+
readonly sourceMemoryIds: readonly string[];
|
|
83
|
+
readonly purgeGroupId: string;
|
|
84
|
+
readonly containsSourceContent: boolean;
|
|
85
|
+
}
|
|
86
|
+
export type MemoryScopeV1 = "session" | "cycle" | "long-term";
|
|
87
|
+
export type MemoryKindV1 = "observation" | "preference" | "fact" | "decision" | "constraint" | "inference" | "synthesis";
|
|
88
|
+
export type MemoryEvidenceClassV1 = "explicit" | "repeated_behavior" | "tool_or_test" | "derived";
|
|
89
|
+
/**
|
|
90
|
+
* The immutable canonical atom. Once committed, no field may change in place.
|
|
91
|
+
* Field semantics follow `docs/design/记忆系统设计.md` §4 (记录模型), which is
|
|
92
|
+
* the authoritative source for memory fields.
|
|
93
|
+
*/
|
|
94
|
+
export interface MemoryAtomV1<TPayload = JsonValue> {
|
|
95
|
+
readonly memoryId: string;
|
|
96
|
+
readonly contractVersion: string;
|
|
97
|
+
readonly schemaVersion: number;
|
|
98
|
+
readonly scope: MemoryScopeV1;
|
|
99
|
+
readonly retentionMode: string;
|
|
100
|
+
readonly owner: string;
|
|
101
|
+
readonly profileId: string;
|
|
102
|
+
readonly shareGroupId?: string;
|
|
103
|
+
/**
|
|
104
|
+
* Suite (方案) this atom belongs to. Absent marks a legacy pre-M5 atom:
|
|
105
|
+
* such atoms are fail-safe INVISIBLE to every suite-scoped read and only
|
|
106
|
+
* readable through suite-unscoped queries. The one cross-suite exception
|
|
107
|
+
* is an explicitly promoted user-default preference.
|
|
108
|
+
*/
|
|
109
|
+
readonly suiteId?: string;
|
|
110
|
+
readonly retentionPolicyVersion: string;
|
|
111
|
+
readonly memoryKind: MemoryKindV1;
|
|
112
|
+
readonly payload: TPayload;
|
|
113
|
+
readonly preference?: MemoryPreferenceEnvelopeV1;
|
|
114
|
+
readonly occurredAt: string;
|
|
115
|
+
readonly recordedAt: string;
|
|
116
|
+
readonly sourceRefs: readonly MemorySourceRefV1[];
|
|
117
|
+
readonly observationId: string;
|
|
118
|
+
readonly sessionRefs: readonly string[];
|
|
119
|
+
readonly agentInstanceRefs: readonly string[];
|
|
120
|
+
readonly projectRefs: readonly string[];
|
|
121
|
+
readonly subjectRefs: readonly string[];
|
|
122
|
+
readonly facets: readonly MemoryFacetV1[];
|
|
123
|
+
readonly relations: readonly MemoryRelationV1[];
|
|
124
|
+
readonly provenance?: MemoryProvenanceV1;
|
|
125
|
+
readonly confidence: number;
|
|
126
|
+
readonly importance: number;
|
|
127
|
+
readonly applicability?: MemoryApplicabilityV1;
|
|
128
|
+
readonly evidenceClass: MemoryEvidenceClassV1;
|
|
129
|
+
readonly contentRevision: string;
|
|
130
|
+
readonly writeReason: string;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Skipped-record counters attached to suite-scoped reads. The read boundary is
|
|
134
|
+
* lazy and observable: excluded atoms are counted, never silently dropped.
|
|
135
|
+
*/
|
|
136
|
+
export interface MemorySuiteFilterStatsV1 {
|
|
137
|
+
/** Legacy (suiteId-less) atoms skipped as invisible to any suite. */
|
|
138
|
+
readonly legacySkipped: number;
|
|
139
|
+
/** Atoms bound to a different suiteId that were skipped. */
|
|
140
|
+
readonly foreignSuiteSkipped: number;
|
|
141
|
+
}
|
|
142
|
+
export interface MemoryStoreCommitOptions {
|
|
143
|
+
/** Overrides the atom's retentionMode id at commit time (policy-selected). */
|
|
144
|
+
readonly retentionModeId?: string;
|
|
145
|
+
}
|
|
146
|
+
/** A committed atom plus the store-assigned bookkeeping facts. */
|
|
147
|
+
export interface CommittedMemoryV1<TPayload extends JsonValue = JsonValue> {
|
|
148
|
+
readonly atom: MemoryAtomV1<TPayload>;
|
|
149
|
+
/** Monotonic across the whole store. */
|
|
150
|
+
readonly storeRevision: number;
|
|
151
|
+
/** Monotonic within the atom's scope partition. */
|
|
152
|
+
readonly scopeRevision: number;
|
|
153
|
+
readonly committedAt: number;
|
|
154
|
+
/** Recall deadline computed from the retention registry. Absent = no expiry. */
|
|
155
|
+
readonly purgeAt?: number;
|
|
156
|
+
readonly retentionModeId: string;
|
|
157
|
+
}
|
|
158
|
+
export interface MemoryStoreQuery {
|
|
159
|
+
readonly owner: string;
|
|
160
|
+
/**
|
|
161
|
+
* Suite-scoped read boundary. When set, only atoms whose suiteId equals
|
|
162
|
+
* this value — plus explicitly promoted user-default preferences — are
|
|
163
|
+
* visible; legacy (suiteId-less) atoms are skipped fail-safe. When absent,
|
|
164
|
+
* no suite filtering happens (suite-unscoped read).
|
|
165
|
+
*/
|
|
166
|
+
readonly suiteId?: string;
|
|
167
|
+
}
|
|
168
|
+
export interface MemoryStoreStats {
|
|
169
|
+
readonly active: number;
|
|
170
|
+
readonly expired: number;
|
|
171
|
+
readonly byScope: Readonly<Record<MemoryScopeV1, {
|
|
172
|
+
active: number;
|
|
173
|
+
expired: number;
|
|
174
|
+
}>>;
|
|
175
|
+
}
|
|
176
|
+
/** Result of `MemoryStoreV1.listForSuite`: visible records plus skip counters. */
|
|
177
|
+
export interface MemoryStoreSuitePageV1 {
|
|
178
|
+
readonly records: readonly CommittedMemoryV1[];
|
|
179
|
+
/** Excluded-record counters for the suite read boundary. */
|
|
180
|
+
readonly filter: MemorySuiteFilterStatsV1;
|
|
181
|
+
}
|
|
182
|
+
export interface MemoryStoreV1 {
|
|
183
|
+
commit(atom: MemoryAtomV1, options?: MemoryStoreCommitOptions): CommittedMemoryV1;
|
|
184
|
+
/**
|
|
185
|
+
* Returns the record only when unexpired, owned by `query.owner`, and —
|
|
186
|
+
* when `query.suiteId` is set — visible in that suite (legacy atoms are
|
|
187
|
+
* invisible to every suite).
|
|
188
|
+
*/
|
|
189
|
+
get(memoryId: string, query: MemoryStoreQuery): CommittedMemoryV1 | undefined;
|
|
190
|
+
/** Lists active records owned by `query.owner`, optionally narrowed to one scope. */
|
|
191
|
+
list(query: MemoryStoreQuery, scope?: MemoryScopeV1): readonly CommittedMemoryV1[];
|
|
192
|
+
/**
|
|
193
|
+
* Suite-scoped listing with skip diagnostics: returns the records visible
|
|
194
|
+
* in `query.suiteId` plus how many legacy and foreign-suite records were
|
|
195
|
+
* excluded (expired records are excluded before the suite filter and are
|
|
196
|
+
* not counted here).
|
|
197
|
+
*/
|
|
198
|
+
listForSuite(query: MemoryStoreQuery & {
|
|
199
|
+
readonly suiteId: string;
|
|
200
|
+
}, scope?: MemoryScopeV1): MemoryStoreSuitePageV1;
|
|
201
|
+
stats(): MemoryStoreStats;
|
|
202
|
+
/**
|
|
203
|
+
* Physically removes one record from the canonical in-memory ledger — the
|
|
204
|
+
* store-side arm of the controlled purge gate (only the purge flow may
|
|
205
|
+
* destroy committed atoms). Returns true when the record existed.
|
|
206
|
+
*/
|
|
207
|
+
evict(memoryId: string): boolean;
|
|
208
|
+
}
|
|
209
|
+
/** Result of `DurableMemoryLedgerV1.load`: replayable atoms plus skip diagnostics. */
|
|
210
|
+
export interface DurableMemoryLedgerLoadResultV1 {
|
|
211
|
+
/** Valid atoms in file order — replay these into a fresh store. */
|
|
212
|
+
readonly atoms: readonly MemoryAtomV1[];
|
|
213
|
+
/** Malformed lines (invalid JSON or invalid atoms) skipped during load. */
|
|
214
|
+
readonly corruptedLines: number;
|
|
215
|
+
/** Atoms whose memoryId was already loaded (crash windows can duplicate appends). */
|
|
216
|
+
readonly duplicateSkipped: number;
|
|
217
|
+
/** True when the file existed but could not be read (permissions, IO error). */
|
|
218
|
+
readonly unreadable: boolean;
|
|
219
|
+
}
|
|
220
|
+
export interface DurableMemoryLedgerV1 {
|
|
221
|
+
/**
|
|
222
|
+
* Reads the ledger file and returns the replayable atom set plus skip
|
|
223
|
+
* counters. A missing file is an empty ledger, not an error; malformed or
|
|
224
|
+
* duplicate lines are skipped and counted — load NEVER throws.
|
|
225
|
+
*/
|
|
226
|
+
load(): DurableMemoryLedgerLoadResultV1;
|
|
227
|
+
/**
|
|
228
|
+
* Appends one committed atom as a single JSONL line (strictly validated).
|
|
229
|
+
* The write serializes against other processes through the `.lock` sibling
|
|
230
|
+
* file and is fsynced before close, so an acknowledged append survives a
|
|
231
|
+
* hard crash; a lock timeout or IO failure throws (an append never fails
|
|
232
|
+
* silently).
|
|
233
|
+
*/
|
|
234
|
+
append(atom: MemoryAtomV1): void;
|
|
235
|
+
/**
|
|
236
|
+
* Physically rewrites the whole file with the given atoms (atomic tmp-file
|
|
237
|
+
* + rename). The forget/purge flow calls this after removing atoms so the
|
|
238
|
+
* durable replica matches the surviving canonical set.
|
|
239
|
+
*/
|
|
240
|
+
rewrite(atoms: readonly MemoryAtomV1[]): void;
|
|
241
|
+
/** The ledger's current in-memory atom set (append/rewrite keep it in sync). */
|
|
242
|
+
atomsSnapshot(): readonly MemoryAtomV1[];
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* Batch embedding provider. Implementations must be deterministic for
|
|
246
|
+
* identical input and must not silently degrade: any failure propagates.
|
|
247
|
+
*/
|
|
248
|
+
export interface MemoryEmbeddingProviderV1 {
|
|
249
|
+
readonly modelId: string;
|
|
250
|
+
readonly dimensions: number;
|
|
251
|
+
/**
|
|
252
|
+
* Batch embed. Vectors are L2-normalized float arrays. Deterministic for
|
|
253
|
+
* identical input. Plain text mapping — no instruction prefix is added
|
|
254
|
+
* here; query-side instructions for bge-small-zh family are the caller's
|
|
255
|
+
* responsibility.
|
|
256
|
+
*/
|
|
257
|
+
embed(texts: readonly string[]): Promise<readonly (readonly number[])[]>;
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Minimal structural seam around a transformers.js feature-extraction
|
|
261
|
+
* pipeline, so tests can inject a fake without touching the real loader.
|
|
262
|
+
*/
|
|
263
|
+
export interface TransformersEmbeddingBackendV1 {
|
|
264
|
+
/** Extract features for a batch of texts; one vector per input, input order. */
|
|
265
|
+
extract: (texts: string[]) => Promise<{
|
|
266
|
+
toList: () => number[][];
|
|
267
|
+
}>;
|
|
268
|
+
}
|
|
269
|
+
export type TransformersEmbeddingLoadImpl = (modelId: string, cacheDir: string, remoteHost: string) => Promise<TransformersEmbeddingBackendV1>;
|
|
270
|
+
/**
|
|
271
|
+
* Cross-encoder reranker. Higher score = more relevant; raw logits are only
|
|
272
|
+
* order-preserving, not calibrated probabilities.
|
|
273
|
+
*/
|
|
274
|
+
export interface MemoryRerankerV1 {
|
|
275
|
+
readonly modelId: string;
|
|
276
|
+
/** Score each doc against the query; higher = more relevant (raw logits, order-preserving). */
|
|
277
|
+
rerank(query: string, docs: readonly string[]): Promise<readonly number[]>;
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* Minimal structural seam around a transformers.js sequence-classification
|
|
281
|
+
* pair, so tests can inject a fake without touching the real loader.
|
|
282
|
+
*/
|
|
283
|
+
export interface TransformersRerankerBackendV1 {
|
|
284
|
+
/** Score docs against the query; result[i] corresponds to docs[i]. */
|
|
285
|
+
score: (query: string, docs: string[]) => Promise<number[]>;
|
|
286
|
+
}
|
|
287
|
+
export type TransformersRerankerLoadImpl = (modelId: string, cacheDir: string, remoteHost: string) => Promise<TransformersRerankerBackendV1>;
|
|
288
|
+
/** Stored-row shape for one vector-channel upsert. */
|
|
289
|
+
export interface MemoryVectorIndexEntryV1 {
|
|
290
|
+
readonly memoryId: string;
|
|
291
|
+
readonly owner: string;
|
|
292
|
+
readonly modelId: string;
|
|
293
|
+
readonly statement: string;
|
|
294
|
+
readonly tags: readonly string[];
|
|
295
|
+
readonly vector: readonly number[];
|
|
296
|
+
}
|
|
297
|
+
export interface MemoryVectorIndexQueryV1 {
|
|
298
|
+
readonly owner: string;
|
|
299
|
+
readonly limit: number;
|
|
300
|
+
}
|
|
301
|
+
export interface MemoryVectorHitV1 {
|
|
302
|
+
readonly memoryId: string;
|
|
303
|
+
readonly score: number;
|
|
304
|
+
}
|
|
305
|
+
export interface MemoryVectorIndexV1 {
|
|
306
|
+
readonly replicaId: "memory-vector-index";
|
|
307
|
+
upsert(entries: readonly MemoryVectorIndexEntryV1[]): Promise<void>;
|
|
308
|
+
remove(memoryIds: readonly string[]): Promise<void>;
|
|
309
|
+
queryKnn(vector: readonly number[], query: MemoryVectorIndexQueryV1): Promise<readonly MemoryVectorHitV1[]>;
|
|
310
|
+
queryFts(queryText: string, query: MemoryVectorIndexQueryV1): Promise<readonly MemoryVectorHitV1[]>;
|
|
311
|
+
listMemoryIds(): Promise<ReadonlySet<string>>;
|
|
312
|
+
count(): Promise<number>;
|
|
313
|
+
getStoredModelId(): Promise<string | undefined>;
|
|
314
|
+
close(): Promise<void>;
|
|
315
|
+
}
|
|
316
|
+
/** 全局记忆档位: off = 家族不注册; light/full = 档位 + 开启意图。 */
|
|
317
|
+
export type MemoryModeV1 = "off" | "light" | "full";
|
|
318
|
+
/**
|
|
319
|
+
* 契约常量(扩展位盘点 B3):记忆召回工具名——SDK 的 B1 自动回忆按它调用
|
|
320
|
+
* (`runtime.invokeTool`),替换记忆后端的插件也以同名工具接管该链路
|
|
321
|
+
* (registerTool 可替换 + 同名接管)。改名即破坏该公共链路,故名入契约。
|
|
322
|
+
*/
|
|
323
|
+
export declare const MEMORY_RECALL_TOOL_NAME = "memory_recall";
|
|
324
|
+
/**
|
|
325
|
+
* 测试专用向量组件注入点 (架构宪法: deterministic mock AI 门禁)。注入后召回
|
|
326
|
+
* 直接进入 ready 并完全由注入组件驱动, 跳过 transformers/lancedb 真实装配;
|
|
327
|
+
* `reranker` 缺省 = 精排不可用 (跳过精排, 用 RRF 序)。
|
|
328
|
+
*/
|
|
329
|
+
export interface MemoryVectorComponentsOverrideV1 {
|
|
330
|
+
readonly embedProvider: MemoryEmbeddingProviderV1;
|
|
331
|
+
readonly reranker?: MemoryRerankerV1;
|
|
332
|
+
readonly vectorIndex: MemoryVectorIndexV1;
|
|
333
|
+
readonly queryPrefix?: string;
|
|
334
|
+
}
|
|
335
|
+
/**
|
|
336
|
+
* 真实装配路径的测试缝 (enabling 状态机测试用): 组件工厂照常构建
|
|
337
|
+
* (LanceDB 本地、零网络), 仅 transformers 加载被替换。
|
|
338
|
+
*/
|
|
339
|
+
export interface MemoryEnablingOverrideV1 {
|
|
340
|
+
readonly embeddingLoadImpl?: TransformersEmbeddingLoadImpl;
|
|
341
|
+
readonly rerankerLoadImpl?: TransformersRerankerLoadImpl;
|
|
342
|
+
}
|
|
343
|
+
/** Capability-level override: full vector components, or enabling-path load seams. */
|
|
344
|
+
export type MemoryCapabilityOverrideV1 = MemoryVectorComponentsOverrideV1 | MemoryEnablingOverrideV1;
|
|
345
|
+
/**
|
|
346
|
+
* 记忆底层组件注入契约 (扩展位盘点 A1/A2, D-068 增补 1): 宿主 SDK 经
|
|
347
|
+
* `CreateAgentSessionOptions.memoryCapability.storage`(D-075 S4-4 起经
|
|
348
|
+
* `HostCapabilities.memoryStorage`)替换记忆的持久化后端与向量组件——
|
|
349
|
+
* builtin memory 保持记忆语义的编排者 (原子契约/工具面/ledger 生命周期),
|
|
350
|
+
* 底层实现可换。缺省任一成员 = 内置默认实现, 默认行为零变化。工厂入参只含
|
|
351
|
+
* 作用域事实 (路径域与时钟), 实现不依赖内核内部布局。
|
|
352
|
+
*/
|
|
353
|
+
export interface MemoryStorageComponentsV1 {
|
|
354
|
+
/** A1: 记忆原子存取后端 (默认 = 本地内存 store + JSONL ledger 副本语义由 ledger 承担)。 */
|
|
355
|
+
readonly storeFactory?: (scope: {
|
|
356
|
+
readonly agentDir: string;
|
|
357
|
+
readonly owner: string;
|
|
358
|
+
readonly now: () => number;
|
|
359
|
+
}) => MemoryStoreV1;
|
|
360
|
+
/** A1: 持久化副本后端 (默认 = `<agentDir>/memory/<owner>/ledger-<domain>.jsonl`)。 */
|
|
361
|
+
readonly ledgerFactory?: (scope: {
|
|
362
|
+
readonly agentDir: string;
|
|
363
|
+
readonly owner: string;
|
|
364
|
+
readonly domain: string;
|
|
365
|
+
readonly now: () => number;
|
|
366
|
+
}) => DurableMemoryLedgerV1;
|
|
367
|
+
/** A2: 向量通道组件 (缺省 reranker = 跳过精排, 用 RRF 序)。 */
|
|
368
|
+
readonly vectorComponents?: MemoryVectorComponentsOverrideV1;
|
|
369
|
+
}
|
|
370
|
+
//# sourceMappingURL=memory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory.d.ts","sourceRoot":"","sources":["../src/memory.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAM7C,4FAA4F;AAC5F,MAAM,WAAW,iBAAiB;IACjC,QAAQ,CAAC,IAAI,EAAE,SAAS,GAAG,OAAO,GAAG,UAAU,GAAG,MAAM,GAAG,OAAO,CAAC;IACnE,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,2EAA2E;AAC3E,MAAM,WAAW,aAAa;IAC7B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,GAAG,EAAE,MAAM,CAA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E,MAAM,CAAC;QAC1B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;QACvB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;QACxB,QAAQ,CAAC,GAAG,EAAE,MAAM,MAAM,CAAC;KAC3B,KAAK,qBAAqB,CAAC;IAC5B,8EAAgD;IAChD,QAAQ,CAAC,gBAAgB,CAAC,EAAE,gCAAgC,CAAC;CAC7D","sourcesContent":["/**\n * Public contracts for the first-party memory capability (M5 Memory\n * Foundation + the builtin memory family). The plugin package\n * (`@agent-forge/plugin-memory`) is the implementation; this module is the\n * single authoring authority for its public types and the host-facing storage\n * injection contract. The host re-exports the surface from its historical\n * module paths so existing imports keep resolving.\n *\n * Types only, plus the `MEMORY_RECALL_TOOL_NAME` contract constant: the\n * recall tool name is pinned here because the host's B1 auto-recall path\n * calls it by name (`runtime.invokeTool`) and replacement memory backends\n * take over the same link by registering the same-named tool.\n *\n * Authority moved from the host's `capabilities/memory.ts` and\n * `src/memory/*` (D-075 S4 fourth batch, first slice): every symbol below is\n * a verbatim structural copy of its host definition; the transitive type\n * chain (canonical atom, store, ledger, vector components) migrated with it\n * so plugin authors never import host internals.\n */\n\nimport type { JsonValue } from \"./common.ts\";\n\n// ---------------------------------------------------------------------------\n// Canonical atom (host `src/memory/foundation.ts`)\n// ---------------------------------------------------------------------------\n\n/** Source of one memory: where the fact came from, optionally pinned by revision/digest. */\nexport interface MemorySourceRefV1 {\n\treadonly kind: \"session\" | \"entry\" | \"artifact\" | \"tool\" | \"state\";\n\treadonly id: string;\n\treadonly revision?: string;\n\treadonly digest?: string;\n}\n\n/** Namespace-scoped search facet. Facets are atom facts, never derived. */\nexport interface MemoryFacetV1 {\n\treadonly namespace: string;\n\treadonly schemaVersion: number;\n\treadonly key: string;\n\treadonly value: string;\n}\n\n/** Typed relation between atoms. Weights/validity belong to projections, not here. */\nexport interface MemoryRelationV1 {\n\treadonly relationId: string;\n\treadonly namespace: string;\n\treadonly schemaVersion: number;\n\treadonly kind: string;\n\treadonly targetMemoryId?: string;\n\treadonly targetRef?: MemorySourceRefV1;\n\treadonly confidence?: number;\n\treadonly relationRevision: string;\n}\n\nexport interface MemoryTimeRangeV1 {\n\treadonly from?: string;\n\treadonly to?: string;\n}\n\n/** Applicability narrowing; empty means \"applies without narrowing\". */\nexport interface MemoryApplicabilityV1 {\n\treadonly scenes?: readonly string[];\n\treadonly projects?: readonly string[];\n\treadonly tasks?: readonly string[];\n\treadonly timeRange?: MemoryTimeRangeV1;\n\treadonly exceptions?: readonly string[];\n}\n\n/** Preference envelope: the generic schema frozen for 1C; policy semantics come later. */\nexport interface MemoryPreferenceEnvelopeV1 {\n\treadonly subject: \"user\" | \"project\" | \"task\" | \"environment\";\n\treadonly key: string;\n\treadonly preferredValue: JsonValue;\n\treadonly alternatives?: readonly JsonValue[];\n\treadonly scope: {\n\t\treadonly level: \"task\" | \"project\" | \"scene\" | \"timeRange\" | \"profile-private\" | \"user-default\";\n\t\treadonly scenes?: readonly string[];\n\t\treadonly projects?: readonly string[];\n\t\treadonly tasks?: readonly string[];\n\t\treadonly timeRange?: MemoryTimeRangeV1;\n\t\treadonly exceptions?: readonly string[];\n\t};\n\treadonly evidence: {\n\t\treadonly class: \"explicit\" | \"repeated_behavior\" | \"inferred\";\n\t\treadonly sourceRefs: readonly MemorySourceRefV1[];\n\t\treadonly confidence: number;\n\t};\n\treadonly applicabilityConfidence: number;\n\treadonly confirmedAt?: string;\n}\n\n/** Provenance for synthesis/compaction memories derived from other atoms. */\nexport interface MemoryProvenanceV1 {\n\treadonly sourceMemoryIds: readonly string[];\n\treadonly purgeGroupId: string;\n\treadonly containsSourceContent: boolean;\n}\n\nexport type MemoryScopeV1 = \"session\" | \"cycle\" | \"long-term\";\nexport type MemoryKindV1 =\n\t| \"observation\"\n\t| \"preference\"\n\t| \"fact\"\n\t| \"decision\"\n\t| \"constraint\"\n\t| \"inference\"\n\t| \"synthesis\";\nexport type MemoryEvidenceClassV1 = \"explicit\" | \"repeated_behavior\" | \"tool_or_test\" | \"derived\";\n\n/**\n * The immutable canonical atom. Once committed, no field may change in place.\n * Field semantics follow `docs/design/记忆系统设计.md` §4 (记录模型), which is\n * the authoritative source for memory fields.\n */\nexport interface MemoryAtomV1<TPayload = JsonValue> {\n\treadonly memoryId: string;\n\treadonly contractVersion: string;\n\treadonly schemaVersion: number;\n\treadonly scope: MemoryScopeV1;\n\treadonly retentionMode: string;\n\treadonly owner: string;\n\treadonly profileId: string;\n\treadonly shareGroupId?: string;\n\t/**\n\t * Suite (方案) this atom belongs to. Absent marks a legacy pre-M5 atom:\n\t * such atoms are fail-safe INVISIBLE to every suite-scoped read and only\n\t * readable through suite-unscoped queries. The one cross-suite exception\n\t * is an explicitly promoted user-default preference.\n\t */\n\treadonly suiteId?: string;\n\treadonly retentionPolicyVersion: string;\n\treadonly memoryKind: MemoryKindV1;\n\treadonly payload: TPayload;\n\treadonly preference?: MemoryPreferenceEnvelopeV1;\n\treadonly occurredAt: string;\n\treadonly recordedAt: string;\n\treadonly sourceRefs: readonly MemorySourceRefV1[];\n\treadonly observationId: string;\n\treadonly sessionRefs: readonly string[];\n\treadonly agentInstanceRefs: readonly string[];\n\treadonly projectRefs: readonly string[];\n\treadonly subjectRefs: readonly string[];\n\treadonly facets: readonly MemoryFacetV1[];\n\treadonly relations: readonly MemoryRelationV1[];\n\treadonly provenance?: MemoryProvenanceV1;\n\treadonly confidence: number;\n\treadonly importance: number;\n\treadonly applicability?: MemoryApplicabilityV1;\n\treadonly evidenceClass: MemoryEvidenceClassV1;\n\treadonly contentRevision: string;\n\treadonly writeReason: string;\n}\n\n/**\n * Skipped-record counters attached to suite-scoped reads. The read boundary is\n * lazy and observable: excluded atoms are counted, never silently dropped.\n */\nexport interface MemorySuiteFilterStatsV1 {\n\t/** Legacy (suiteId-less) atoms skipped as invisible to any suite. */\n\treadonly legacySkipped: number;\n\t/** Atoms bound to a different suiteId that were skipped. */\n\treadonly foreignSuiteSkipped: number;\n}\n\n// ---------------------------------------------------------------------------\n// Three-scope store (host `src/memory/store.ts`)\n// ---------------------------------------------------------------------------\n\nexport interface MemoryStoreCommitOptions {\n\t/** Overrides the atom's retentionMode id at commit time (policy-selected). */\n\treadonly retentionModeId?: string;\n}\n\n/** A committed atom plus the store-assigned bookkeeping facts. */\nexport interface CommittedMemoryV1<TPayload extends JsonValue = JsonValue> {\n\treadonly atom: MemoryAtomV1<TPayload>;\n\t/** Monotonic across the whole store. */\n\treadonly storeRevision: number;\n\t/** Monotonic within the atom's scope partition. */\n\treadonly scopeRevision: number;\n\treadonly committedAt: number;\n\t/** Recall deadline computed from the retention registry. Absent = no expiry. */\n\treadonly purgeAt?: number;\n\treadonly retentionModeId: string;\n}\n\nexport interface MemoryStoreQuery {\n\treadonly owner: string;\n\t/**\n\t * Suite-scoped read boundary. When set, only atoms whose suiteId equals\n\t * this value — plus explicitly promoted user-default preferences — are\n\t * visible; legacy (suiteId-less) atoms are skipped fail-safe. When absent,\n\t * no suite filtering happens (suite-unscoped read).\n\t */\n\treadonly suiteId?: string;\n}\n\nexport interface MemoryStoreStats {\n\treadonly active: number;\n\treadonly expired: number;\n\treadonly byScope: Readonly<Record<MemoryScopeV1, { active: number; expired: number }>>;\n}\n\n/** Result of `MemoryStoreV1.listForSuite`: visible records plus skip counters. */\nexport interface MemoryStoreSuitePageV1 {\n\treadonly records: readonly CommittedMemoryV1[];\n\t/** Excluded-record counters for the suite read boundary. */\n\treadonly filter: MemorySuiteFilterStatsV1;\n}\n\nexport interface MemoryStoreV1 {\n\tcommit(atom: MemoryAtomV1, options?: MemoryStoreCommitOptions): CommittedMemoryV1;\n\t/**\n\t * Returns the record only when unexpired, owned by `query.owner`, and —\n\t * when `query.suiteId` is set — visible in that suite (legacy atoms are\n\t * invisible to every suite).\n\t */\n\tget(memoryId: string, query: MemoryStoreQuery): CommittedMemoryV1 | undefined;\n\t/** Lists active records owned by `query.owner`, optionally narrowed to one scope. */\n\tlist(query: MemoryStoreQuery, scope?: MemoryScopeV1): readonly CommittedMemoryV1[];\n\t/**\n\t * Suite-scoped listing with skip diagnostics: returns the records visible\n\t * in `query.suiteId` plus how many legacy and foreign-suite records were\n\t * excluded (expired records are excluded before the suite filter and are\n\t * not counted here).\n\t */\n\tlistForSuite(query: MemoryStoreQuery & { readonly suiteId: string }, scope?: MemoryScopeV1): MemoryStoreSuitePageV1;\n\tstats(): MemoryStoreStats;\n\t/**\n\t * Physically removes one record from the canonical in-memory ledger — the\n\t * store-side arm of the controlled purge gate (only the purge flow may\n\t * destroy committed atoms). Returns true when the record existed.\n\t */\n\tevict(memoryId: string): boolean;\n}\n\n// ---------------------------------------------------------------------------\n// Durable ledger replica (host `src/memory/ledger.ts`)\n// ---------------------------------------------------------------------------\n\n/** Result of `DurableMemoryLedgerV1.load`: replayable atoms plus skip diagnostics. */\nexport interface DurableMemoryLedgerLoadResultV1 {\n\t/** Valid atoms in file order — replay these into a fresh store. */\n\treadonly atoms: readonly MemoryAtomV1[];\n\t/** Malformed lines (invalid JSON or invalid atoms) skipped during load. */\n\treadonly corruptedLines: number;\n\t/** Atoms whose memoryId was already loaded (crash windows can duplicate appends). */\n\treadonly duplicateSkipped: number;\n\t/** True when the file existed but could not be read (permissions, IO error). */\n\treadonly unreadable: boolean;\n}\n\nexport interface DurableMemoryLedgerV1 {\n\t/**\n\t * Reads the ledger file and returns the replayable atom set plus skip\n\t * counters. A missing file is an empty ledger, not an error; malformed or\n\t * duplicate lines are skipped and counted — load NEVER throws.\n\t */\n\tload(): DurableMemoryLedgerLoadResultV1;\n\t/**\n\t * Appends one committed atom as a single JSONL line (strictly validated).\n\t * The write serializes against other processes through the `.lock` sibling\n\t * file and is fsynced before close, so an acknowledged append survives a\n\t * hard crash; a lock timeout or IO failure throws (an append never fails\n\t * silently).\n\t */\n\tappend(atom: MemoryAtomV1): void;\n\t/**\n\t * Physically rewrites the whole file with the given atoms (atomic tmp-file\n\t * + rename). The forget/purge flow calls this after removing atoms so the\n\t * durable replica matches the surviving canonical set.\n\t */\n\trewrite(atoms: readonly MemoryAtomV1[]): void;\n\t/** The ledger's current in-memory atom set (append/rewrite keep it in sync). */\n\tatomsSnapshot(): readonly MemoryAtomV1[];\n}\n\n// ---------------------------------------------------------------------------\n// Vector channel components (host `src/memory/{embedding-provider,embedding-reranker,vector-index}.ts`)\n// ---------------------------------------------------------------------------\n\n/**\n * Batch embedding provider. Implementations must be deterministic for\n * identical input and must not silently degrade: any failure propagates.\n */\nexport interface MemoryEmbeddingProviderV1 {\n\treadonly modelId: string;\n\treadonly dimensions: number;\n\t/**\n\t * Batch embed. Vectors are L2-normalized float arrays. Deterministic for\n\t * identical input. Plain text mapping — no instruction prefix is added\n\t * here; query-side instructions for bge-small-zh family are the caller's\n\t * responsibility.\n\t */\n\tembed(texts: readonly string[]): Promise<readonly (readonly number[])[]>;\n}\n\n/**\n * Minimal structural seam around a transformers.js feature-extraction\n * pipeline, so tests can inject a fake without touching the real loader.\n */\nexport interface TransformersEmbeddingBackendV1 {\n\t/** Extract features for a batch of texts; one vector per input, input order. */\n\textract: (texts: string[]) => Promise<{ toList: () => number[][] }>;\n}\n\nexport type TransformersEmbeddingLoadImpl = (\n\tmodelId: string,\n\tcacheDir: string,\n\tremoteHost: string,\n) => Promise<TransformersEmbeddingBackendV1>;\n\n/**\n * Cross-encoder reranker. Higher score = more relevant; raw logits are only\n * order-preserving, not calibrated probabilities.\n */\nexport interface MemoryRerankerV1 {\n\treadonly modelId: string;\n\t/** Score each doc against the query; higher = more relevant (raw logits, order-preserving). */\n\trerank(query: string, docs: readonly string[]): Promise<readonly number[]>;\n}\n\n/**\n * Minimal structural seam around a transformers.js sequence-classification\n * pair, so tests can inject a fake without touching the real loader.\n */\nexport interface TransformersRerankerBackendV1 {\n\t/** Score docs against the query; result[i] corresponds to docs[i]. */\n\tscore: (query: string, docs: string[]) => Promise<number[]>;\n}\n\nexport type TransformersRerankerLoadImpl = (\n\tmodelId: string,\n\tcacheDir: string,\n\tremoteHost: string,\n) => Promise<TransformersRerankerBackendV1>;\n\n/** Stored-row shape for one vector-channel upsert. */\nexport interface MemoryVectorIndexEntryV1 {\n\treadonly memoryId: string;\n\treadonly owner: string;\n\treadonly modelId: string;\n\treadonly statement: string;\n\treadonly tags: readonly string[];\n\treadonly vector: readonly number[];\n}\n\nexport interface MemoryVectorIndexQueryV1 {\n\treadonly owner: string;\n\treadonly limit: number;\n}\n\nexport interface MemoryVectorHitV1 {\n\treadonly memoryId: string;\n\treadonly score: number;\n}\n\nexport interface MemoryVectorIndexV1 {\n\treadonly replicaId: \"memory-vector-index\";\n\tupsert(entries: readonly MemoryVectorIndexEntryV1[]): Promise<void>;\n\tremove(memoryIds: readonly string[]): Promise<void>;\n\tqueryKnn(vector: readonly number[], query: MemoryVectorIndexQueryV1): Promise<readonly MemoryVectorHitV1[]>;\n\tqueryFts(queryText: string, query: MemoryVectorIndexQueryV1): Promise<readonly MemoryVectorHitV1[]>;\n\tlistMemoryIds(): Promise<ReadonlySet<string>>;\n\tcount(): Promise<number>;\n\tgetStoredModelId(): Promise<string | undefined>;\n\tclose(): Promise<void>;\n}\n\n// ---------------------------------------------------------------------------\n// Capability contracts (host `capabilities/memory.ts`)\n// ---------------------------------------------------------------------------\n\n/** 全局记忆档位: off = 家族不注册; light/full = 档位 + 开启意图。 */\nexport type MemoryModeV1 = \"off\" | \"light\" | \"full\";\n\n/**\n * 契约常量(扩展位盘点 B3):记忆召回工具名——SDK 的 B1 自动回忆按它调用\n * (`runtime.invokeTool`),替换记忆后端的插件也以同名工具接管该链路\n * (registerTool 可替换 + 同名接管)。改名即破坏该公共链路,故名入契约。\n */\nexport const MEMORY_RECALL_TOOL_NAME = \"memory_recall\";\n\n/**\n * 测试专用向量组件注入点 (架构宪法: deterministic mock AI 门禁)。注入后召回\n * 直接进入 ready 并完全由注入组件驱动, 跳过 transformers/lancedb 真实装配;\n * `reranker` 缺省 = 精排不可用 (跳过精排, 用 RRF 序)。\n */\nexport interface MemoryVectorComponentsOverrideV1 {\n\treadonly embedProvider: MemoryEmbeddingProviderV1;\n\treadonly reranker?: MemoryRerankerV1;\n\treadonly vectorIndex: MemoryVectorIndexV1;\n\treadonly queryPrefix?: string;\n}\n\n/**\n * 真实装配路径的测试缝 (enabling 状态机测试用): 组件工厂照常构建\n * (LanceDB 本地、零网络), 仅 transformers 加载被替换。\n */\nexport interface MemoryEnablingOverrideV1 {\n\treadonly embeddingLoadImpl?: TransformersEmbeddingLoadImpl;\n\treadonly rerankerLoadImpl?: TransformersRerankerLoadImpl;\n}\n\n/** Capability-level override: full vector components, or enabling-path load seams. */\nexport type MemoryCapabilityOverrideV1 = MemoryVectorComponentsOverrideV1 | MemoryEnablingOverrideV1;\n\n/**\n * 记忆底层组件注入契约 (扩展位盘点 A1/A2, D-068 增补 1): 宿主 SDK 经\n * `CreateAgentSessionOptions.memoryCapability.storage`(D-075 S4-4 起经\n * `HostCapabilities.memoryStorage`)替换记忆的持久化后端与向量组件——\n * builtin memory 保持记忆语义的编排者 (原子契约/工具面/ledger 生命周期),\n * 底层实现可换。缺省任一成员 = 内置默认实现, 默认行为零变化。工厂入参只含\n * 作用域事实 (路径域与时钟), 实现不依赖内核内部布局。\n */\nexport interface MemoryStorageComponentsV1 {\n\t/** A1: 记忆原子存取后端 (默认 = 本地内存 store + JSONL ledger 副本语义由 ledger 承担)。 */\n\treadonly storeFactory?: (scope: {\n\t\treadonly agentDir: string;\n\t\treadonly owner: string;\n\t\treadonly now: () => number;\n\t}) => MemoryStoreV1;\n\t/** A1: 持久化副本后端 (默认 = `<agentDir>/memory/<owner>/ledger-<domain>.jsonl`)。 */\n\treadonly ledgerFactory?: (scope: {\n\t\treadonly agentDir: string;\n\t\treadonly owner: string;\n\t\treadonly domain: string;\n\t\treadonly now: () => number;\n\t}) => DurableMemoryLedgerV1;\n\t/** A2: 向量通道组件 (缺省 reranker = 跳过精排, 用 RRF 序)。 */\n\treadonly vectorComponents?: MemoryVectorComponentsOverrideV1;\n}\n"]}
|
package/dist/memory.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public contracts for the first-party memory capability (M5 Memory
|
|
3
|
+
* Foundation + the builtin memory family). The plugin package
|
|
4
|
+
* (`@agent-forge/plugin-memory`) is the implementation; this module is the
|
|
5
|
+
* single authoring authority for its public types and the host-facing storage
|
|
6
|
+
* injection contract. The host re-exports the surface from its historical
|
|
7
|
+
* module paths so existing imports keep resolving.
|
|
8
|
+
*
|
|
9
|
+
* Types only, plus the `MEMORY_RECALL_TOOL_NAME` contract constant: the
|
|
10
|
+
* recall tool name is pinned here because the host's B1 auto-recall path
|
|
11
|
+
* calls it by name (`runtime.invokeTool`) and replacement memory backends
|
|
12
|
+
* take over the same link by registering the same-named tool.
|
|
13
|
+
*
|
|
14
|
+
* Authority moved from the host's `capabilities/memory.ts` and
|
|
15
|
+
* `src/memory/*` (D-075 S4 fourth batch, first slice): every symbol below is
|
|
16
|
+
* a verbatim structural copy of its host definition; the transitive type
|
|
17
|
+
* chain (canonical atom, store, ledger, vector components) migrated with it
|
|
18
|
+
* so plugin authors never import host internals.
|
|
19
|
+
*/
|
|
20
|
+
/**
|
|
21
|
+
* 契约常量(扩展位盘点 B3):记忆召回工具名——SDK 的 B1 自动回忆按它调用
|
|
22
|
+
* (`runtime.invokeTool`),替换记忆后端的插件也以同名工具接管该链路
|
|
23
|
+
* (registerTool 可替换 + 同名接管)。改名即破坏该公共链路,故名入契约。
|
|
24
|
+
*/
|
|
25
|
+
export const MEMORY_RECALL_TOOL_NAME = "memory_recall";
|
|
26
|
+
//# sourceMappingURL=memory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory.js","sourceRoot":"","sources":["../src/memory.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAsWH;;;;GAIG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,eAAe,CAAC","sourcesContent":["/**\n * Public contracts for the first-party memory capability (M5 Memory\n * Foundation + the builtin memory family). The plugin package\n * (`@agent-forge/plugin-memory`) is the implementation; this module is the\n * single authoring authority for its public types and the host-facing storage\n * injection contract. The host re-exports the surface from its historical\n * module paths so existing imports keep resolving.\n *\n * Types only, plus the `MEMORY_RECALL_TOOL_NAME` contract constant: the\n * recall tool name is pinned here because the host's B1 auto-recall path\n * calls it by name (`runtime.invokeTool`) and replacement memory backends\n * take over the same link by registering the same-named tool.\n *\n * Authority moved from the host's `capabilities/memory.ts` and\n * `src/memory/*` (D-075 S4 fourth batch, first slice): every symbol below is\n * a verbatim structural copy of its host definition; the transitive type\n * chain (canonical atom, store, ledger, vector components) migrated with it\n * so plugin authors never import host internals.\n */\n\nimport type { JsonValue } from \"./common.ts\";\n\n// ---------------------------------------------------------------------------\n// Canonical atom (host `src/memory/foundation.ts`)\n// ---------------------------------------------------------------------------\n\n/** Source of one memory: where the fact came from, optionally pinned by revision/digest. */\nexport interface MemorySourceRefV1 {\n\treadonly kind: \"session\" | \"entry\" | \"artifact\" | \"tool\" | \"state\";\n\treadonly id: string;\n\treadonly revision?: string;\n\treadonly digest?: string;\n}\n\n/** Namespace-scoped search facet. Facets are atom facts, never derived. */\nexport interface MemoryFacetV1 {\n\treadonly namespace: string;\n\treadonly schemaVersion: number;\n\treadonly key: string;\n\treadonly value: string;\n}\n\n/** Typed relation between atoms. Weights/validity belong to projections, not here. */\nexport interface MemoryRelationV1 {\n\treadonly relationId: string;\n\treadonly namespace: string;\n\treadonly schemaVersion: number;\n\treadonly kind: string;\n\treadonly targetMemoryId?: string;\n\treadonly targetRef?: MemorySourceRefV1;\n\treadonly confidence?: number;\n\treadonly relationRevision: string;\n}\n\nexport interface MemoryTimeRangeV1 {\n\treadonly from?: string;\n\treadonly to?: string;\n}\n\n/** Applicability narrowing; empty means \"applies without narrowing\". */\nexport interface MemoryApplicabilityV1 {\n\treadonly scenes?: readonly string[];\n\treadonly projects?: readonly string[];\n\treadonly tasks?: readonly string[];\n\treadonly timeRange?: MemoryTimeRangeV1;\n\treadonly exceptions?: readonly string[];\n}\n\n/** Preference envelope: the generic schema frozen for 1C; policy semantics come later. */\nexport interface MemoryPreferenceEnvelopeV1 {\n\treadonly subject: \"user\" | \"project\" | \"task\" | \"environment\";\n\treadonly key: string;\n\treadonly preferredValue: JsonValue;\n\treadonly alternatives?: readonly JsonValue[];\n\treadonly scope: {\n\t\treadonly level: \"task\" | \"project\" | \"scene\" | \"timeRange\" | \"profile-private\" | \"user-default\";\n\t\treadonly scenes?: readonly string[];\n\t\treadonly projects?: readonly string[];\n\t\treadonly tasks?: readonly string[];\n\t\treadonly timeRange?: MemoryTimeRangeV1;\n\t\treadonly exceptions?: readonly string[];\n\t};\n\treadonly evidence: {\n\t\treadonly class: \"explicit\" | \"repeated_behavior\" | \"inferred\";\n\t\treadonly sourceRefs: readonly MemorySourceRefV1[];\n\t\treadonly confidence: number;\n\t};\n\treadonly applicabilityConfidence: number;\n\treadonly confirmedAt?: string;\n}\n\n/** Provenance for synthesis/compaction memories derived from other atoms. */\nexport interface MemoryProvenanceV1 {\n\treadonly sourceMemoryIds: readonly string[];\n\treadonly purgeGroupId: string;\n\treadonly containsSourceContent: boolean;\n}\n\nexport type MemoryScopeV1 = \"session\" | \"cycle\" | \"long-term\";\nexport type MemoryKindV1 =\n\t| \"observation\"\n\t| \"preference\"\n\t| \"fact\"\n\t| \"decision\"\n\t| \"constraint\"\n\t| \"inference\"\n\t| \"synthesis\";\nexport type MemoryEvidenceClassV1 = \"explicit\" | \"repeated_behavior\" | \"tool_or_test\" | \"derived\";\n\n/**\n * The immutable canonical atom. Once committed, no field may change in place.\n * Field semantics follow `docs/design/记忆系统设计.md` §4 (记录模型), which is\n * the authoritative source for memory fields.\n */\nexport interface MemoryAtomV1<TPayload = JsonValue> {\n\treadonly memoryId: string;\n\treadonly contractVersion: string;\n\treadonly schemaVersion: number;\n\treadonly scope: MemoryScopeV1;\n\treadonly retentionMode: string;\n\treadonly owner: string;\n\treadonly profileId: string;\n\treadonly shareGroupId?: string;\n\t/**\n\t * Suite (方案) this atom belongs to. Absent marks a legacy pre-M5 atom:\n\t * such atoms are fail-safe INVISIBLE to every suite-scoped read and only\n\t * readable through suite-unscoped queries. The one cross-suite exception\n\t * is an explicitly promoted user-default preference.\n\t */\n\treadonly suiteId?: string;\n\treadonly retentionPolicyVersion: string;\n\treadonly memoryKind: MemoryKindV1;\n\treadonly payload: TPayload;\n\treadonly preference?: MemoryPreferenceEnvelopeV1;\n\treadonly occurredAt: string;\n\treadonly recordedAt: string;\n\treadonly sourceRefs: readonly MemorySourceRefV1[];\n\treadonly observationId: string;\n\treadonly sessionRefs: readonly string[];\n\treadonly agentInstanceRefs: readonly string[];\n\treadonly projectRefs: readonly string[];\n\treadonly subjectRefs: readonly string[];\n\treadonly facets: readonly MemoryFacetV1[];\n\treadonly relations: readonly MemoryRelationV1[];\n\treadonly provenance?: MemoryProvenanceV1;\n\treadonly confidence: number;\n\treadonly importance: number;\n\treadonly applicability?: MemoryApplicabilityV1;\n\treadonly evidenceClass: MemoryEvidenceClassV1;\n\treadonly contentRevision: string;\n\treadonly writeReason: string;\n}\n\n/**\n * Skipped-record counters attached to suite-scoped reads. The read boundary is\n * lazy and observable: excluded atoms are counted, never silently dropped.\n */\nexport interface MemorySuiteFilterStatsV1 {\n\t/** Legacy (suiteId-less) atoms skipped as invisible to any suite. */\n\treadonly legacySkipped: number;\n\t/** Atoms bound to a different suiteId that were skipped. */\n\treadonly foreignSuiteSkipped: number;\n}\n\n// ---------------------------------------------------------------------------\n// Three-scope store (host `src/memory/store.ts`)\n// ---------------------------------------------------------------------------\n\nexport interface MemoryStoreCommitOptions {\n\t/** Overrides the atom's retentionMode id at commit time (policy-selected). */\n\treadonly retentionModeId?: string;\n}\n\n/** A committed atom plus the store-assigned bookkeeping facts. */\nexport interface CommittedMemoryV1<TPayload extends JsonValue = JsonValue> {\n\treadonly atom: MemoryAtomV1<TPayload>;\n\t/** Monotonic across the whole store. */\n\treadonly storeRevision: number;\n\t/** Monotonic within the atom's scope partition. */\n\treadonly scopeRevision: number;\n\treadonly committedAt: number;\n\t/** Recall deadline computed from the retention registry. Absent = no expiry. */\n\treadonly purgeAt?: number;\n\treadonly retentionModeId: string;\n}\n\nexport interface MemoryStoreQuery {\n\treadonly owner: string;\n\t/**\n\t * Suite-scoped read boundary. When set, only atoms whose suiteId equals\n\t * this value — plus explicitly promoted user-default preferences — are\n\t * visible; legacy (suiteId-less) atoms are skipped fail-safe. When absent,\n\t * no suite filtering happens (suite-unscoped read).\n\t */\n\treadonly suiteId?: string;\n}\n\nexport interface MemoryStoreStats {\n\treadonly active: number;\n\treadonly expired: number;\n\treadonly byScope: Readonly<Record<MemoryScopeV1, { active: number; expired: number }>>;\n}\n\n/** Result of `MemoryStoreV1.listForSuite`: visible records plus skip counters. */\nexport interface MemoryStoreSuitePageV1 {\n\treadonly records: readonly CommittedMemoryV1[];\n\t/** Excluded-record counters for the suite read boundary. */\n\treadonly filter: MemorySuiteFilterStatsV1;\n}\n\nexport interface MemoryStoreV1 {\n\tcommit(atom: MemoryAtomV1, options?: MemoryStoreCommitOptions): CommittedMemoryV1;\n\t/**\n\t * Returns the record only when unexpired, owned by `query.owner`, and —\n\t * when `query.suiteId` is set — visible in that suite (legacy atoms are\n\t * invisible to every suite).\n\t */\n\tget(memoryId: string, query: MemoryStoreQuery): CommittedMemoryV1 | undefined;\n\t/** Lists active records owned by `query.owner`, optionally narrowed to one scope. */\n\tlist(query: MemoryStoreQuery, scope?: MemoryScopeV1): readonly CommittedMemoryV1[];\n\t/**\n\t * Suite-scoped listing with skip diagnostics: returns the records visible\n\t * in `query.suiteId` plus how many legacy and foreign-suite records were\n\t * excluded (expired records are excluded before the suite filter and are\n\t * not counted here).\n\t */\n\tlistForSuite(query: MemoryStoreQuery & { readonly suiteId: string }, scope?: MemoryScopeV1): MemoryStoreSuitePageV1;\n\tstats(): MemoryStoreStats;\n\t/**\n\t * Physically removes one record from the canonical in-memory ledger — the\n\t * store-side arm of the controlled purge gate (only the purge flow may\n\t * destroy committed atoms). Returns true when the record existed.\n\t */\n\tevict(memoryId: string): boolean;\n}\n\n// ---------------------------------------------------------------------------\n// Durable ledger replica (host `src/memory/ledger.ts`)\n// ---------------------------------------------------------------------------\n\n/** Result of `DurableMemoryLedgerV1.load`: replayable atoms plus skip diagnostics. */\nexport interface DurableMemoryLedgerLoadResultV1 {\n\t/** Valid atoms in file order — replay these into a fresh store. */\n\treadonly atoms: readonly MemoryAtomV1[];\n\t/** Malformed lines (invalid JSON or invalid atoms) skipped during load. */\n\treadonly corruptedLines: number;\n\t/** Atoms whose memoryId was already loaded (crash windows can duplicate appends). */\n\treadonly duplicateSkipped: number;\n\t/** True when the file existed but could not be read (permissions, IO error). */\n\treadonly unreadable: boolean;\n}\n\nexport interface DurableMemoryLedgerV1 {\n\t/**\n\t * Reads the ledger file and returns the replayable atom set plus skip\n\t * counters. A missing file is an empty ledger, not an error; malformed or\n\t * duplicate lines are skipped and counted — load NEVER throws.\n\t */\n\tload(): DurableMemoryLedgerLoadResultV1;\n\t/**\n\t * Appends one committed atom as a single JSONL line (strictly validated).\n\t * The write serializes against other processes through the `.lock` sibling\n\t * file and is fsynced before close, so an acknowledged append survives a\n\t * hard crash; a lock timeout or IO failure throws (an append never fails\n\t * silently).\n\t */\n\tappend(atom: MemoryAtomV1): void;\n\t/**\n\t * Physically rewrites the whole file with the given atoms (atomic tmp-file\n\t * + rename). The forget/purge flow calls this after removing atoms so the\n\t * durable replica matches the surviving canonical set.\n\t */\n\trewrite(atoms: readonly MemoryAtomV1[]): void;\n\t/** The ledger's current in-memory atom set (append/rewrite keep it in sync). */\n\tatomsSnapshot(): readonly MemoryAtomV1[];\n}\n\n// ---------------------------------------------------------------------------\n// Vector channel components (host `src/memory/{embedding-provider,embedding-reranker,vector-index}.ts`)\n// ---------------------------------------------------------------------------\n\n/**\n * Batch embedding provider. Implementations must be deterministic for\n * identical input and must not silently degrade: any failure propagates.\n */\nexport interface MemoryEmbeddingProviderV1 {\n\treadonly modelId: string;\n\treadonly dimensions: number;\n\t/**\n\t * Batch embed. Vectors are L2-normalized float arrays. Deterministic for\n\t * identical input. Plain text mapping — no instruction prefix is added\n\t * here; query-side instructions for bge-small-zh family are the caller's\n\t * responsibility.\n\t */\n\tembed(texts: readonly string[]): Promise<readonly (readonly number[])[]>;\n}\n\n/**\n * Minimal structural seam around a transformers.js feature-extraction\n * pipeline, so tests can inject a fake without touching the real loader.\n */\nexport interface TransformersEmbeddingBackendV1 {\n\t/** Extract features for a batch of texts; one vector per input, input order. */\n\textract: (texts: string[]) => Promise<{ toList: () => number[][] }>;\n}\n\nexport type TransformersEmbeddingLoadImpl = (\n\tmodelId: string,\n\tcacheDir: string,\n\tremoteHost: string,\n) => Promise<TransformersEmbeddingBackendV1>;\n\n/**\n * Cross-encoder reranker. Higher score = more relevant; raw logits are only\n * order-preserving, not calibrated probabilities.\n */\nexport interface MemoryRerankerV1 {\n\treadonly modelId: string;\n\t/** Score each doc against the query; higher = more relevant (raw logits, order-preserving). */\n\trerank(query: string, docs: readonly string[]): Promise<readonly number[]>;\n}\n\n/**\n * Minimal structural seam around a transformers.js sequence-classification\n * pair, so tests can inject a fake without touching the real loader.\n */\nexport interface TransformersRerankerBackendV1 {\n\t/** Score docs against the query; result[i] corresponds to docs[i]. */\n\tscore: (query: string, docs: string[]) => Promise<number[]>;\n}\n\nexport type TransformersRerankerLoadImpl = (\n\tmodelId: string,\n\tcacheDir: string,\n\tremoteHost: string,\n) => Promise<TransformersRerankerBackendV1>;\n\n/** Stored-row shape for one vector-channel upsert. */\nexport interface MemoryVectorIndexEntryV1 {\n\treadonly memoryId: string;\n\treadonly owner: string;\n\treadonly modelId: string;\n\treadonly statement: string;\n\treadonly tags: readonly string[];\n\treadonly vector: readonly number[];\n}\n\nexport interface MemoryVectorIndexQueryV1 {\n\treadonly owner: string;\n\treadonly limit: number;\n}\n\nexport interface MemoryVectorHitV1 {\n\treadonly memoryId: string;\n\treadonly score: number;\n}\n\nexport interface MemoryVectorIndexV1 {\n\treadonly replicaId: \"memory-vector-index\";\n\tupsert(entries: readonly MemoryVectorIndexEntryV1[]): Promise<void>;\n\tremove(memoryIds: readonly string[]): Promise<void>;\n\tqueryKnn(vector: readonly number[], query: MemoryVectorIndexQueryV1): Promise<readonly MemoryVectorHitV1[]>;\n\tqueryFts(queryText: string, query: MemoryVectorIndexQueryV1): Promise<readonly MemoryVectorHitV1[]>;\n\tlistMemoryIds(): Promise<ReadonlySet<string>>;\n\tcount(): Promise<number>;\n\tgetStoredModelId(): Promise<string | undefined>;\n\tclose(): Promise<void>;\n}\n\n// ---------------------------------------------------------------------------\n// Capability contracts (host `capabilities/memory.ts`)\n// ---------------------------------------------------------------------------\n\n/** 全局记忆档位: off = 家族不注册; light/full = 档位 + 开启意图。 */\nexport type MemoryModeV1 = \"off\" | \"light\" | \"full\";\n\n/**\n * 契约常量(扩展位盘点 B3):记忆召回工具名——SDK 的 B1 自动回忆按它调用\n * (`runtime.invokeTool`),替换记忆后端的插件也以同名工具接管该链路\n * (registerTool 可替换 + 同名接管)。改名即破坏该公共链路,故名入契约。\n */\nexport const MEMORY_RECALL_TOOL_NAME = \"memory_recall\";\n\n/**\n * 测试专用向量组件注入点 (架构宪法: deterministic mock AI 门禁)。注入后召回\n * 直接进入 ready 并完全由注入组件驱动, 跳过 transformers/lancedb 真实装配;\n * `reranker` 缺省 = 精排不可用 (跳过精排, 用 RRF 序)。\n */\nexport interface MemoryVectorComponentsOverrideV1 {\n\treadonly embedProvider: MemoryEmbeddingProviderV1;\n\treadonly reranker?: MemoryRerankerV1;\n\treadonly vectorIndex: MemoryVectorIndexV1;\n\treadonly queryPrefix?: string;\n}\n\n/**\n * 真实装配路径的测试缝 (enabling 状态机测试用): 组件工厂照常构建\n * (LanceDB 本地、零网络), 仅 transformers 加载被替换。\n */\nexport interface MemoryEnablingOverrideV1 {\n\treadonly embeddingLoadImpl?: TransformersEmbeddingLoadImpl;\n\treadonly rerankerLoadImpl?: TransformersRerankerLoadImpl;\n}\n\n/** Capability-level override: full vector components, or enabling-path load seams. */\nexport type MemoryCapabilityOverrideV1 = MemoryVectorComponentsOverrideV1 | MemoryEnablingOverrideV1;\n\n/**\n * 记忆底层组件注入契约 (扩展位盘点 A1/A2, D-068 增补 1): 宿主 SDK 经\n * `CreateAgentSessionOptions.memoryCapability.storage`(D-075 S4-4 起经\n * `HostCapabilities.memoryStorage`)替换记忆的持久化后端与向量组件——\n * builtin memory 保持记忆语义的编排者 (原子契约/工具面/ledger 生命周期),\n * 底层实现可换。缺省任一成员 = 内置默认实现, 默认行为零变化。工厂入参只含\n * 作用域事实 (路径域与时钟), 实现不依赖内核内部布局。\n */\nexport interface MemoryStorageComponentsV1 {\n\t/** A1: 记忆原子存取后端 (默认 = 本地内存 store + JSONL ledger 副本语义由 ledger 承担)。 */\n\treadonly storeFactory?: (scope: {\n\t\treadonly agentDir: string;\n\t\treadonly owner: string;\n\t\treadonly now: () => number;\n\t}) => MemoryStoreV1;\n\t/** A1: 持久化副本后端 (默认 = `<agentDir>/memory/<owner>/ledger-<domain>.jsonl`)。 */\n\treadonly ledgerFactory?: (scope: {\n\t\treadonly agentDir: string;\n\t\treadonly owner: string;\n\t\treadonly domain: string;\n\t\treadonly now: () => number;\n\t}) => DurableMemoryLedgerV1;\n\t/** A2: 向量通道组件 (缺省 reranker = 跳过精排, 用 RRF 序)。 */\n\treadonly vectorComponents?: MemoryVectorComponentsOverrideV1;\n}\n"]}
|