@limo-labs/deity 0.1.0-alpha.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 +519 -0
- package/dist/src/component.d.ts +19 -0
- package/dist/src/component.d.ts.map +1 -0
- package/dist/src/component.js +2 -0
- package/dist/src/component.js.map +1 -0
- package/dist/src/context/context-scope.d.ts +24 -0
- package/dist/src/context/context-scope.d.ts.map +1 -0
- package/dist/src/context/context-scope.js +19 -0
- package/dist/src/context/context-scope.js.map +1 -0
- package/dist/src/context/memory-view.d.ts +62 -0
- package/dist/src/context/memory-view.d.ts.map +1 -0
- package/dist/src/context/memory-view.js +104 -0
- package/dist/src/context/memory-view.js.map +1 -0
- package/dist/src/context/scoped-context.d.ts +51 -0
- package/dist/src/context/scoped-context.d.ts.map +1 -0
- package/dist/src/context/scoped-context.js +74 -0
- package/dist/src/context/scoped-context.js.map +1 -0
- package/dist/src/context/scoped-execution-context.d.ts +55 -0
- package/dist/src/context/scoped-execution-context.d.ts.map +1 -0
- package/dist/src/context/scoped-execution-context.js +78 -0
- package/dist/src/context/scoped-execution-context.js.map +1 -0
- package/dist/src/conversation/conversation-manager.d.ts +272 -0
- package/dist/src/conversation/conversation-manager.d.ts.map +1 -0
- package/dist/src/conversation/conversation-manager.js +11 -0
- package/dist/src/conversation/conversation-manager.js.map +1 -0
- package/dist/src/conversation/conversation-pruner.d.ts +190 -0
- package/dist/src/conversation/conversation-pruner.d.ts.map +1 -0
- package/dist/src/conversation/conversation-pruner.js +274 -0
- package/dist/src/conversation/conversation-pruner.js.map +1 -0
- package/dist/src/conversation/conversation-tree.d.ts +185 -0
- package/dist/src/conversation/conversation-tree.d.ts.map +1 -0
- package/dist/src/conversation/conversation-tree.js +288 -0
- package/dist/src/conversation/conversation-tree.js.map +1 -0
- package/dist/src/conversation/file-conversation-store.d.ts +93 -0
- package/dist/src/conversation/file-conversation-store.d.ts.map +1 -0
- package/dist/src/conversation/file-conversation-store.js +284 -0
- package/dist/src/conversation/file-conversation-store.js.map +1 -0
- package/dist/src/conversation/in-memory-conversation-store.d.ts +36 -0
- package/dist/src/conversation/in-memory-conversation-store.d.ts.map +1 -0
- package/dist/src/conversation/in-memory-conversation-store.js +146 -0
- package/dist/src/conversation/in-memory-conversation-store.js.map +1 -0
- package/dist/src/copilot-adapter.d.ts +33 -0
- package/dist/src/copilot-adapter.d.ts.map +1 -0
- package/dist/src/copilot-adapter.js +119 -0
- package/dist/src/copilot-adapter.js.map +1 -0
- package/dist/src/file-trace-enhanced.d.ts +123 -0
- package/dist/src/file-trace-enhanced.d.ts.map +1 -0
- package/dist/src/file-trace-enhanced.js +177 -0
- package/dist/src/file-trace-enhanced.js.map +1 -0
- package/dist/src/file-trace.d.ts +24 -0
- package/dist/src/file-trace.d.ts.map +1 -0
- package/dist/src/file-trace.js +60 -0
- package/dist/src/file-trace.js.map +1 -0
- package/dist/src/index.d.ts +63 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +40 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/json-store.d.ts +27 -0
- package/dist/src/json-store.d.ts.map +1 -0
- package/dist/src/json-store.js +93 -0
- package/dist/src/json-store.js.map +1 -0
- package/dist/src/llm.d.ts +35 -0
- package/dist/src/llm.d.ts.map +1 -0
- package/dist/src/llm.js +2 -0
- package/dist/src/llm.js.map +1 -0
- package/dist/src/memory/cold-storage.d.ts +60 -0
- package/dist/src/memory/cold-storage.d.ts.map +1 -0
- package/dist/src/memory/cold-storage.js +132 -0
- package/dist/src/memory/cold-storage.js.map +1 -0
- package/dist/src/memory/compression.d.ts +161 -0
- package/dist/src/memory/compression.d.ts.map +1 -0
- package/dist/src/memory/compression.js +193 -0
- package/dist/src/memory/compression.js.map +1 -0
- package/dist/src/memory/hot-memory.d.ts +69 -0
- package/dist/src/memory/hot-memory.d.ts.map +1 -0
- package/dist/src/memory/hot-memory.js +116 -0
- package/dist/src/memory/hot-memory.js.map +1 -0
- package/dist/src/memory/memory-budget.d.ts +162 -0
- package/dist/src/memory/memory-budget.d.ts.map +1 -0
- package/dist/src/memory/memory-budget.js +241 -0
- package/dist/src/memory/memory-budget.js.map +1 -0
- package/dist/src/memory/memory-config.d.ts +419 -0
- package/dist/src/memory/memory-config.d.ts.map +1 -0
- package/dist/src/memory/memory-config.js +297 -0
- package/dist/src/memory/memory-config.js.map +1 -0
- package/dist/src/memory/prefetcher.d.ts +137 -0
- package/dist/src/memory/prefetcher.d.ts.map +1 -0
- package/dist/src/memory/prefetcher.js +186 -0
- package/dist/src/memory/prefetcher.js.map +1 -0
- package/dist/src/memory/tiered-memory.d.ts +116 -0
- package/dist/src/memory/tiered-memory.d.ts.map +1 -0
- package/dist/src/memory/tiered-memory.js +215 -0
- package/dist/src/memory/tiered-memory.js.map +1 -0
- package/dist/src/memory/warm-storage.d.ts +74 -0
- package/dist/src/memory/warm-storage.d.ts.map +1 -0
- package/dist/src/memory/warm-storage.js +207 -0
- package/dist/src/memory/warm-storage.js.map +1 -0
- package/dist/src/openai-adapter.d.ts +20 -0
- package/dist/src/openai-adapter.d.ts.map +1 -0
- package/dist/src/openai-adapter.js +73 -0
- package/dist/src/openai-adapter.js.map +1 -0
- package/dist/src/parser.d.ts +27 -0
- package/dist/src/parser.d.ts.map +1 -0
- package/dist/src/parser.js +76 -0
- package/dist/src/parser.js.map +1 -0
- package/dist/src/runtime.d.ts +172 -0
- package/dist/src/runtime.d.ts.map +1 -0
- package/dist/src/runtime.js +436 -0
- package/dist/src/runtime.js.map +1 -0
- package/dist/src/schema-utils.d.ts +7 -0
- package/dist/src/schema-utils.d.ts.map +1 -0
- package/dist/src/schema-utils.js +71 -0
- package/dist/src/schema-utils.js.map +1 -0
- package/dist/src/stage.d.ts +139 -0
- package/dist/src/stage.d.ts.map +1 -0
- package/dist/src/stage.js +2 -0
- package/dist/src/stage.js.map +1 -0
- package/dist/src/store.d.ts +51 -0
- package/dist/src/store.d.ts.map +1 -0
- package/dist/src/store.js +2 -0
- package/dist/src/store.js.map +1 -0
- package/dist/src/tool.d.ts +12 -0
- package/dist/src/tool.d.ts.map +1 -0
- package/dist/src/tool.js +2 -0
- package/dist/src/tool.js.map +1 -0
- package/dist/src/trace.d.ts +60 -0
- package/dist/src/trace.d.ts.map +1 -0
- package/dist/src/trace.js +2 -0
- package/dist/src/trace.js.map +1 -0
- package/dist/src/validator.d.ts +17 -0
- package/dist/src/validator.d.ts.map +1 -0
- package/dist/src/validator.js +21 -0
- package/dist/src/validator.js.map +1 -0
- package/dist/src/workflow.d.ts +192 -0
- package/dist/src/workflow.d.ts.map +1 -0
- package/dist/src/workflow.js +50 -0
- package/dist/src/workflow.js.map +1 -0
- package/package.json +62 -0
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { isStageVisible, isAccessAllowed } from "./context-scope.js";
|
|
2
|
+
/**
|
|
3
|
+
* Memory view with access control based on context scope.
|
|
4
|
+
* Wraps TieredMemoryManager and enforces visibility rules.
|
|
5
|
+
*/
|
|
6
|
+
export class MemoryView {
|
|
7
|
+
memory;
|
|
8
|
+
scope;
|
|
9
|
+
constructor(memory, scope) {
|
|
10
|
+
this.memory = memory;
|
|
11
|
+
this.scope = scope;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Get a value from memory.
|
|
15
|
+
* Throws if the key's stage is not visible in this scope.
|
|
16
|
+
*/
|
|
17
|
+
async get(key) {
|
|
18
|
+
this.checkAccess(key, "read");
|
|
19
|
+
return this.memory.get(key);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Set a value in memory.
|
|
23
|
+
* Throws if write access is not allowed or key's stage is not visible.
|
|
24
|
+
*/
|
|
25
|
+
async set(key, value) {
|
|
26
|
+
this.checkAccess(key, "write");
|
|
27
|
+
await this.memory.set(key, value);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Check if a key exists in memory.
|
|
31
|
+
* Throws if the key's stage is not visible in this scope.
|
|
32
|
+
*/
|
|
33
|
+
async has(key) {
|
|
34
|
+
this.checkAccess(key, "read");
|
|
35
|
+
return this.memory.has(key);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Delete a value from memory.
|
|
39
|
+
* Throws if write access is not allowed or key's stage is not visible.
|
|
40
|
+
*/
|
|
41
|
+
async delete(key) {
|
|
42
|
+
this.checkAccess(key, "write");
|
|
43
|
+
await this.memory.delete(key);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Pin a key to prevent eviction.
|
|
47
|
+
* Throws if write access is not allowed or key's stage is not visible.
|
|
48
|
+
*/
|
|
49
|
+
async pin(key) {
|
|
50
|
+
this.checkAccess(key, "write");
|
|
51
|
+
await this.memory.pin(key);
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Unpin a key.
|
|
55
|
+
* Throws if write access is not allowed or key's stage is not visible.
|
|
56
|
+
*/
|
|
57
|
+
unpin(key) {
|
|
58
|
+
this.checkAccess(key, "write");
|
|
59
|
+
this.memory.unpin(key);
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Get the current scope.
|
|
63
|
+
*/
|
|
64
|
+
getScope() {
|
|
65
|
+
return this.scope;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Check if access to a key is allowed in this scope.
|
|
69
|
+
* Throws AccessDeniedError if access is not allowed.
|
|
70
|
+
*/
|
|
71
|
+
checkAccess(key, mode) {
|
|
72
|
+
// Extract stage ID from key (assumes format "stage:StageId")
|
|
73
|
+
const stageId = this.extractStageId(key);
|
|
74
|
+
// Check if stage is visible
|
|
75
|
+
if (!isStageVisible(this.scope, stageId)) {
|
|
76
|
+
throw new AccessDeniedError(`Access denied: stage "${stageId}" is not visible in scope "${this.scope.name}"`);
|
|
77
|
+
}
|
|
78
|
+
// Check if access mode is allowed
|
|
79
|
+
if (!isAccessAllowed(this.scope, mode)) {
|
|
80
|
+
throw new AccessDeniedError(`Access denied: ${mode} access not allowed in scope "${this.scope.name}"`);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Extract stage ID from a memory key.
|
|
85
|
+
* Assumes format "stage:StageId" or just "StageId".
|
|
86
|
+
*/
|
|
87
|
+
extractStageId(key) {
|
|
88
|
+
if (key.startsWith("stage:")) {
|
|
89
|
+
return key.substring(6);
|
|
90
|
+
}
|
|
91
|
+
// If no prefix, assume the key itself is the stage ID
|
|
92
|
+
return key.split(":")[0];
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Error thrown when access is denied due to scope restrictions.
|
|
97
|
+
*/
|
|
98
|
+
export class AccessDeniedError extends Error {
|
|
99
|
+
constructor(message) {
|
|
100
|
+
super(message);
|
|
101
|
+
this.name = "AccessDeniedError";
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
//# sourceMappingURL=memory-view.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory-view.js","sourceRoot":"","sources":["../../../src/context/memory-view.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAErE;;;GAGG;AACH,MAAM,OAAO,UAAU;IAEX;IACA;IAFV,YACU,MAA2B,EAC3B,KAAmB;QADnB,WAAM,GAAN,MAAM,CAAqB;QAC3B,UAAK,GAAL,KAAK,CAAc;IAC1B,CAAC;IAEJ;;;OAGG;IACH,KAAK,CAAC,GAAG,CAAI,GAAW;QACtB,IAAI,CAAC,WAAW,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;QAC9B,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAI,GAAG,CAAC,CAAC;IACjC,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,GAAG,CAAI,GAAW,EAAE,KAAQ;QAChC,IAAI,CAAC,WAAW,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;QAC/B,MAAM,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG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I,CAAC,KAAK,EAAE,IAAI,CAAC,EAAE,CAAC;YACvC,MAAM,IAAI,iBAAiB,CACzB,kBAAkB,IAAI,iCAAiC,IAAI,CAAC,KAAK,CAAC,IAAI,GAAG,CAC1E,CAAC;QACJ,CAAC;IACH,CAAC;IAED;;;OAGG;IACK,cAAc,CAAC,GAAW;QAChC,IAAI,GAAG,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC;YAC7B,OAAO,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;QAC1B,CAAC;QACD,sDAAsD;QACtD,OAAO,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IAC3B,CAAC;CACF;AAED;;GAEG;AACH,MAAM,OAAO,iBAAkB,SAAQ,KAAK;IAC1C,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,mBAAmB,CAAC;IAClC,CAAC;CACF"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { ExecutionContext } from "../stage.js";
|
|
2
|
+
import type { StateStore } from "../store.js";
|
|
3
|
+
import type { TraceLogger } from "../trace.js";
|
|
4
|
+
import { MemoryView } from "./memory-view.js";
|
|
5
|
+
import type { ContextScope } from "./context-scope.js";
|
|
6
|
+
/**
|
|
7
|
+
* Scoped execution context with memory access control.
|
|
8
|
+
* Implements the ExecutionContext interface with visibility restrictions.
|
|
9
|
+
*/
|
|
10
|
+
export declare class ScopedExecutionContext<I = unknown> implements ExecutionContext<I> {
|
|
11
|
+
/** Input to the current stage */
|
|
12
|
+
inputs: I;
|
|
13
|
+
/** Memory view with access control */
|
|
14
|
+
memory: MemoryView;
|
|
15
|
+
/** Scope defining visibility rules */
|
|
16
|
+
scope: ContextScope;
|
|
17
|
+
/** Parent context (if this is a child context) */
|
|
18
|
+
parent?: ScopedExecutionContext<any>;
|
|
19
|
+
/** Legacy store access (read-only) */
|
|
20
|
+
store: StateStore;
|
|
21
|
+
/** Legacy trace logger */
|
|
22
|
+
trace: TraceLogger;
|
|
23
|
+
constructor(config: {
|
|
24
|
+
inputs: I;
|
|
25
|
+
memory: MemoryView;
|
|
26
|
+
scope: ContextScope;
|
|
27
|
+
parent?: ScopedExecutionContext<any>;
|
|
28
|
+
store: StateStore;
|
|
29
|
+
trace: TraceLogger;
|
|
30
|
+
});
|
|
31
|
+
/**
|
|
32
|
+
* Get previous outputs (legacy interface).
|
|
33
|
+
* Returns all visible stage outputs.
|
|
34
|
+
*/
|
|
35
|
+
get previousOutputs(): Record<string, unknown>;
|
|
36
|
+
/**
|
|
37
|
+
* Get output from a specific stage (legacy interface).
|
|
38
|
+
* Uses memory view with access control.
|
|
39
|
+
*/
|
|
40
|
+
getOutput<T>(stageId: string): T;
|
|
41
|
+
/**
|
|
42
|
+
* Create a child context with a different scope.
|
|
43
|
+
* Inherits inputs and memory but with restricted visibility.
|
|
44
|
+
*/
|
|
45
|
+
createChild(childScope: ContextScope): ScopedExecutionContext<I>;
|
|
46
|
+
/**
|
|
47
|
+
* Create an isolated child context that can only see specific stages.
|
|
48
|
+
*/
|
|
49
|
+
isolate(visibleStages: string[]): ScopedExecutionContext<I>;
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=scoped-context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scoped-context.d.ts","sourceRoot":"","sources":["../../../src/context/scoped-context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAEvD;;;GAGG;AACH,qBAAa,sBAAsB,CAAC,CAAC,GAAG,OAAO,CAAE,YAAW,gBAAgB,CAAC,CAAC,CAAC;IAC7E,iCAAiC;IACjC,MAAM,EAAE,CAAC,CAAC;IAEV,sCAAsC;IACtC,MAAM,EAAE,UAAU,CAAC;IAEnB,sCAAsC;IACtC,KAAK,EAAE,YAAY,CAAC;IAEpB,kDAAkD;IAClD,MAAM,CAAC,EAAE,sBAAsB,CAAC,GAAG,CAAC,CAAC;IAErC,sCAAsC;IACtC,KAAK,EAAE,UAAU,CAAC;IAElB,0BAA0B;IAC1B,KAAK,EAAE,WAAW,CAAC;gBAEP,MAAM,EAAE;QAClB,MAAM,EAAE,CAAC,CAAC;QACV,MAAM,EAAE,UAAU,CAAC;QACnB,KAAK,EAAE,YAAY,CAAC;QACpB,MAAM,CAAC,EAAE,sBAAsB,CAAC,GAAG,CAAC,CAAC;QACrC,KAAK,EAAE,UAAU,CAAC;QAClB,KAAK,EAAE,WAAW,CAAC;KACpB;IASD;;;OAGG;IACH,IAAI,eAAe,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAI7C;IAED;;;OAGG;IACH,SAAS,CAAC,CAAC,EAAE,OAAO,EAAE,MAAM,GAAG,CAAC;IAQhC;;;OAGG;IACH,WAAW,CAAC,UAAU,EAAE,YAAY,GAAG,sBAAsB,CAAC,CAAC,CAAC;IAiBhE;;OAEG;IACH,OAAO,CAAC,aAAa,EAAE,MAAM,EAAE,GAAG,sBAAsB,CAAC,CAAC,CAAC;CAS5D"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { MemoryView } from "./memory-view.js";
|
|
2
|
+
/**
|
|
3
|
+
* Scoped execution context with memory access control.
|
|
4
|
+
* Implements the ExecutionContext interface with visibility restrictions.
|
|
5
|
+
*/
|
|
6
|
+
export class ScopedExecutionContext {
|
|
7
|
+
/** Input to the current stage */
|
|
8
|
+
inputs;
|
|
9
|
+
/** Memory view with access control */
|
|
10
|
+
memory;
|
|
11
|
+
/** Scope defining visibility rules */
|
|
12
|
+
scope;
|
|
13
|
+
/** Parent context (if this is a child context) */
|
|
14
|
+
parent;
|
|
15
|
+
/** Legacy store access (read-only) */
|
|
16
|
+
store;
|
|
17
|
+
/** Legacy trace logger */
|
|
18
|
+
trace;
|
|
19
|
+
constructor(config) {
|
|
20
|
+
this.inputs = config.inputs;
|
|
21
|
+
this.memory = config.memory;
|
|
22
|
+
this.scope = config.scope;
|
|
23
|
+
this.parent = config.parent;
|
|
24
|
+
this.store = config.store;
|
|
25
|
+
this.trace = config.trace;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Get previous outputs (legacy interface).
|
|
29
|
+
* Returns all visible stage outputs.
|
|
30
|
+
*/
|
|
31
|
+
get previousOutputs() {
|
|
32
|
+
// This would need to be populated from memory
|
|
33
|
+
// For now, return empty object (handled by memory view)
|
|
34
|
+
return {};
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Get output from a specific stage (legacy interface).
|
|
38
|
+
* Uses memory view with access control.
|
|
39
|
+
*/
|
|
40
|
+
getOutput(stageId) {
|
|
41
|
+
// Synchronous wrapper - in real usage, this would need to be async
|
|
42
|
+
// For POC, we'll throw if not found
|
|
43
|
+
throw new Error(`getOutput is synchronous but memory is async. Use memory.get("stage:${stageId}") instead.`);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Create a child context with a different scope.
|
|
47
|
+
* Inherits inputs and memory but with restricted visibility.
|
|
48
|
+
*/
|
|
49
|
+
createChild(childScope) {
|
|
50
|
+
// Create new memory view with child scope
|
|
51
|
+
const childMemory = new MemoryView(this.memory.memory, // Access underlying tiered memory
|
|
52
|
+
childScope);
|
|
53
|
+
return new ScopedExecutionContext({
|
|
54
|
+
inputs: this.inputs,
|
|
55
|
+
memory: childMemory,
|
|
56
|
+
scope: childScope,
|
|
57
|
+
parent: this,
|
|
58
|
+
store: this.store,
|
|
59
|
+
trace: this.trace,
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Create an isolated child context that can only see specific stages.
|
|
64
|
+
*/
|
|
65
|
+
isolate(visibleStages) {
|
|
66
|
+
const isolatedScope = {
|
|
67
|
+
name: `isolated(${visibleStages.join(",")})`,
|
|
68
|
+
visibleStages,
|
|
69
|
+
canWrite: true,
|
|
70
|
+
};
|
|
71
|
+
return this.createChild(isolatedScope);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=scoped-context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scoped-context.js","sourceRoot":"","sources":["../../../src/context/scoped-context.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAG9C;;;GAGG;AACH,MAAM,OAAO,sBAAsB;IACjC,iCAAiC;IACjC,MAAM,CAAI;IAEV,sCAAsC;IACtC,MAAM,CAAa;IAEnB,sCAAsC;IACtC,KAAK,CAAe;IAEpB,kDAAkD;IAClD,MAAM,CAA+B;IAErC,sCAAsC;IACtC,KAAK,CAAa;IAElB,0BAA0B;IAC1B,KAAK,CAAc;IAEnB,YAAY,MAOX;QACC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;QAC5B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;QAC5B,IAAI,CAAC,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC;QAC1B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;QAC5B,IAAI,CAAC,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC;QAC1B,IAAI,CAAC,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC;IAC5B,CAAC;IAED;;;OAGG;IACH,IAAI,eAAe;QACjB,8CAA8C;QAC9C,wDAAwD;QACxD,OAAO,EAAE,CAAC;IACZ,CAAC;IAED;;;OAGG;IACH,SAAS,CAAI,OAAe;QAC1B,mEAAmE;QACnE,oCAAoC;QACpC,MAAM,IAAI,KAAK,CACb,uEAAuE,OAAO,aAAa,CAC5F,CAAC;IACJ,CAAC;IAED;;;OAGG;IACH,WAAW,CAAC,UAAwB;QAClC,0CAA0C;QAC1C,MAAM,WAAW,GAAG,IAAI,UAAU,CAC/B,IAAI,CAAC,MAAc,CAAC,MAAM,EAAE,kCAAkC;QAC/D,UAAU,CACX,CAAC;QAEF,OAAO,IAAI,sBAAsB,CAAC;YAChC,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,MAAM,EAAE,WAAW;YACnB,KAAK,EAAE,UAAU;YACjB,MAAM,EAAE,IAAI;YACZ,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,KAAK,EAAE,IAAI,CAAC,KAAK;SAClB,CAAC,CAAC;IACL,CAAC;IAED;;OAEG;IACH,OAAO,CAAC,aAAuB;QAC7B,MAAM,aAAa,GAAiB;YAClC,IAAI,EAAE,YAAY,aAAa,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG;YAC5C,aAAa;YACb,QAAQ,EAAE,IAAI;SACf,CAAC;QAEF,OAAO,IAAI,CAAC,WAAW,CAAC,aAAa,CAAC,CAAC;IACzC,CAAC;CACF"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { ExecutionContext } from "../stage.js";
|
|
2
|
+
import type { StateStore } from "../store.js";
|
|
3
|
+
import type { TraceLogger } from "../trace.js";
|
|
4
|
+
import type { ConversationManager } from "../conversation/conversation-manager.js";
|
|
5
|
+
import { MemoryView } from "./memory-view.js";
|
|
6
|
+
import type { ContextScope } from "./context-scope.js";
|
|
7
|
+
/**
|
|
8
|
+
* Scoped execution context with memory access control.
|
|
9
|
+
* Implements the ExecutionContext interface with visibility restrictions.
|
|
10
|
+
*/
|
|
11
|
+
export declare class ScopedExecutionContext<I = unknown> implements ExecutionContext<I> {
|
|
12
|
+
/** Input to the current stage */
|
|
13
|
+
inputs: I;
|
|
14
|
+
/** Memory view with access control */
|
|
15
|
+
memory: MemoryView;
|
|
16
|
+
/** Scope defining visibility rules */
|
|
17
|
+
scope: ContextScope;
|
|
18
|
+
/** Parent context (if this is a child context) */
|
|
19
|
+
parent?: ScopedExecutionContext<any>;
|
|
20
|
+
/** Legacy store access (read-only) */
|
|
21
|
+
store: StateStore;
|
|
22
|
+
/** Legacy trace logger */
|
|
23
|
+
trace: TraceLogger;
|
|
24
|
+
/** Conversation history manager */
|
|
25
|
+
conversation: ConversationManager;
|
|
26
|
+
constructor(config: {
|
|
27
|
+
inputs: I;
|
|
28
|
+
memory: MemoryView;
|
|
29
|
+
scope: ContextScope;
|
|
30
|
+
parent?: ScopedExecutionContext<any>;
|
|
31
|
+
store: StateStore;
|
|
32
|
+
trace: TraceLogger;
|
|
33
|
+
conversation: ConversationManager;
|
|
34
|
+
});
|
|
35
|
+
/**
|
|
36
|
+
* Get previous outputs (legacy interface).
|
|
37
|
+
* Returns all visible stage outputs.
|
|
38
|
+
*/
|
|
39
|
+
get previousOutputs(): Record<string, unknown>;
|
|
40
|
+
/**
|
|
41
|
+
* Get output from a specific stage (legacy interface).
|
|
42
|
+
* Uses memory view with access control.
|
|
43
|
+
*/
|
|
44
|
+
getOutput<T>(stageId: string): T;
|
|
45
|
+
/**
|
|
46
|
+
* Create a child context with a different scope.
|
|
47
|
+
* Inherits inputs and memory but with restricted visibility.
|
|
48
|
+
*/
|
|
49
|
+
createChild(childScope: ContextScope): ScopedExecutionContext<I>;
|
|
50
|
+
/**
|
|
51
|
+
* Create an isolated child context that can only see specific stages.
|
|
52
|
+
*/
|
|
53
|
+
isolate(visibleStages: string[]): ScopedExecutionContext<I>;
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=scoped-execution-context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scoped-execution-context.d.ts","sourceRoot":"","sources":["../../../src/context/scoped-execution-context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,KAAK,EAAE,UAAU,E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AAE,MAAM,EAAE,GAAG,sBAAsB,CAAC,CAAC,CAAC;CAS5D"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { MemoryView } from "./memory-view.js";
|
|
2
|
+
/**
|
|
3
|
+
* Scoped execution context with memory access control.
|
|
4
|
+
* Implements the ExecutionContext interface with visibility restrictions.
|
|
5
|
+
*/
|
|
6
|
+
export class ScopedExecutionContext {
|
|
7
|
+
/** Input to the current stage */
|
|
8
|
+
inputs;
|
|
9
|
+
/** Memory view with access control */
|
|
10
|
+
memory;
|
|
11
|
+
/** Scope defining visibility rules */
|
|
12
|
+
scope;
|
|
13
|
+
/** Parent context (if this is a child context) */
|
|
14
|
+
parent;
|
|
15
|
+
/** Legacy store access (read-only) */
|
|
16
|
+
store;
|
|
17
|
+
/** Legacy trace logger */
|
|
18
|
+
trace;
|
|
19
|
+
/** Conversation history manager */
|
|
20
|
+
conversation;
|
|
21
|
+
constructor(config) {
|
|
22
|
+
this.inputs = config.inputs;
|
|
23
|
+
this.memory = config.memory;
|
|
24
|
+
this.scope = config.scope;
|
|
25
|
+
this.parent = config.parent;
|
|
26
|
+
this.store = config.store;
|
|
27
|
+
this.trace = config.trace;
|
|
28
|
+
this.conversation = config.conversation;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Get previous outputs (legacy interface).
|
|
32
|
+
* Returns all visible stage outputs.
|
|
33
|
+
*/
|
|
34
|
+
get previousOutputs() {
|
|
35
|
+
// This would need to be populated from memory
|
|
36
|
+
// For now, return empty object (handled by memory view)
|
|
37
|
+
return {};
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Get output from a specific stage (legacy interface).
|
|
41
|
+
* Uses memory view with access control.
|
|
42
|
+
*/
|
|
43
|
+
getOutput(stageId) {
|
|
44
|
+
// Synchronous wrapper - in real usage, this would need to be async
|
|
45
|
+
// For POC, we'll throw if not found
|
|
46
|
+
throw new Error(`getOutput is synchronous but memory is async. Use memory.get("stage:${stageId}") instead.`);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Create a child context with a different scope.
|
|
50
|
+
* Inherits inputs and memory but with restricted visibility.
|
|
51
|
+
*/
|
|
52
|
+
createChild(childScope) {
|
|
53
|
+
// Create new memory view with child scope
|
|
54
|
+
const childMemory = new MemoryView(this.memory.memory, // Access underlying tiered memory
|
|
55
|
+
childScope);
|
|
56
|
+
return new ScopedExecutionContext({
|
|
57
|
+
inputs: this.inputs,
|
|
58
|
+
memory: childMemory,
|
|
59
|
+
scope: childScope,
|
|
60
|
+
parent: this,
|
|
61
|
+
store: this.store,
|
|
62
|
+
trace: this.trace,
|
|
63
|
+
conversation: this.conversation,
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Create an isolated child context that can only see specific stages.
|
|
68
|
+
*/
|
|
69
|
+
isolate(visibleStages) {
|
|
70
|
+
const isolatedScope = {
|
|
71
|
+
name: `isolated(${visibleStages.join(",")})`,
|
|
72
|
+
visibleStages,
|
|
73
|
+
canWrite: true,
|
|
74
|
+
};
|
|
75
|
+
return this.createChild(isolatedScope);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
//# sourceMappingURL=scoped-execution-context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scoped-execution-context.js","sourceRoot":"","sources":["../../../src/context/scoped-execution-context.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAG9C;;;GAGG;AACH,MAAM,OAAO,sBAAsB;IACjC,iCAAiC;IACjC,MAAM,CAAI;IAEV,sCAAsC;IACtC,MAAM,CAAa;IAEnB,sCAAsC;IACtC,KAAK,CAAe;IAEpB,kDAAkD;IAClD,MAAM,CAA+B;IAErC,sCAAsC;IACtC,KAAK,CAAa;IAElB,0BAA0B;IAC1B,KAAK,CAAc;IAEnB,mCAAmC;IACnC,YAAY,CAAsB;IAElC,YAAY,MAQX;QACC,IAAI,CA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ACf,CAAC;QAEF,OAAO,IAAI,CAAC,WAAW,CAAC,aAAa,CAAC,CAAC;IACzC,CAAC;CACF"}
|
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Conversation history management for long-running AI agents.
|
|
3
|
+
*
|
|
4
|
+
* This module provides interfaces for managing conversation history,
|
|
5
|
+
* including message storage, pruning strategies, and export/import functionality.
|
|
6
|
+
*
|
|
7
|
+
* @module conversation
|
|
8
|
+
* @since 2.0.0
|
|
9
|
+
*/
|
|
10
|
+
import type { Message } from "../component.js";
|
|
11
|
+
/**
|
|
12
|
+
* Metadata attached to each message in the conversation history.
|
|
13
|
+
*
|
|
14
|
+
* @since 2.0.0
|
|
15
|
+
*/
|
|
16
|
+
export interface MessageMetadata {
|
|
17
|
+
/** Unique identifier for this message */
|
|
18
|
+
id: string;
|
|
19
|
+
/** Timestamp when the message was added */
|
|
20
|
+
timestamp: number;
|
|
21
|
+
/** Optional stage ID that generated this message */
|
|
22
|
+
stageId?: string;
|
|
23
|
+
/** Optional token count for the message */
|
|
24
|
+
tokens?: number;
|
|
25
|
+
/** Whether this message is marked as important (won't be pruned easily) */
|
|
26
|
+
important?: boolean;
|
|
27
|
+
/** Custom metadata for application-specific use */
|
|
28
|
+
custom?: Record<string, unknown>;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* A message with its associated metadata.
|
|
32
|
+
*
|
|
33
|
+
* @since 2.0.0
|
|
34
|
+
*/
|
|
35
|
+
export interface ConversationMessage {
|
|
36
|
+
/** The actual message content */
|
|
37
|
+
message: Message;
|
|
38
|
+
/** Metadata about this message */
|
|
39
|
+
metadata: MessageMetadata;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Strategy for pruning old messages from conversation history.
|
|
43
|
+
*
|
|
44
|
+
* Multiple strategies can be combined - messages are kept if they match ANY strategy.
|
|
45
|
+
*
|
|
46
|
+
* @since 2.0.0
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```typescript
|
|
50
|
+
* // Keep last 100 messages
|
|
51
|
+
* const strategy: PruneStrategy = {
|
|
52
|
+
* keepRecent: 100
|
|
53
|
+
* };
|
|
54
|
+
*
|
|
55
|
+
* // Keep messages less than 1 hour old
|
|
56
|
+
* const strategy: PruneStrategy = {
|
|
57
|
+
* maxAge: 60 * 60 * 1000 // 1 hour in milliseconds
|
|
58
|
+
* };
|
|
59
|
+
*
|
|
60
|
+
* // Keep important messages and last 50
|
|
61
|
+
* const strategy: PruneStrategy = {
|
|
62
|
+
* keepRecent: 50,
|
|
63
|
+
* keepImportant: (msg) => msg.metadata.important === true
|
|
64
|
+
* };
|
|
65
|
+
*
|
|
66
|
+
* // Custom strategy based on token count
|
|
67
|
+
* const strategy: PruneStrategy = {
|
|
68
|
+
* keepRecent: 10,
|
|
69
|
+
* keepImportant: (msg) => (msg.metadata.tokens ?? 0) > 1000
|
|
70
|
+
* };
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
export interface PruneStrategy {
|
|
74
|
+
/**
|
|
75
|
+
* Keep the most recent N messages.
|
|
76
|
+
* These messages will never be pruned regardless of age.
|
|
77
|
+
*/
|
|
78
|
+
keepRecent?: number;
|
|
79
|
+
/**
|
|
80
|
+
* Function to determine if a message is important.
|
|
81
|
+
* Important messages are kept regardless of age or position.
|
|
82
|
+
*
|
|
83
|
+
* @param message - The conversation message to check
|
|
84
|
+
* @returns true if the message should be kept, false otherwise
|
|
85
|
+
*/
|
|
86
|
+
keepImportant?: (message: ConversationMessage) => boolean;
|
|
87
|
+
/**
|
|
88
|
+
* Maximum age of messages to keep (in milliseconds).
|
|
89
|
+
* Messages older than this will be pruned unless they match other keep criteria.
|
|
90
|
+
*/
|
|
91
|
+
maxAge?: number;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Statistics about the current conversation state.
|
|
95
|
+
*
|
|
96
|
+
* @since 2.0.0
|
|
97
|
+
*/
|
|
98
|
+
export interface ConversationStats {
|
|
99
|
+
/** Total number of messages in the conversation */
|
|
100
|
+
messageCount: number;
|
|
101
|
+
/** Number of messages by role */
|
|
102
|
+
byRole: Record<string, number>;
|
|
103
|
+
/** Total estimated token count (if available) */
|
|
104
|
+
totalTokens?: number;
|
|
105
|
+
/** Timestamp of oldest message */
|
|
106
|
+
oldestMessage?: number;
|
|
107
|
+
/** Timestamp of newest message */
|
|
108
|
+
newestMessage?: number;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Snapshot of conversation history for export/import.
|
|
112
|
+
*
|
|
113
|
+
* This format is designed to be JSON-serializable for easy persistence.
|
|
114
|
+
*
|
|
115
|
+
* @since 2.0.0
|
|
116
|
+
*/
|
|
117
|
+
export interface ConversationSnapshot {
|
|
118
|
+
/** Version of the snapshot format for future compatibility */
|
|
119
|
+
version: string;
|
|
120
|
+
/** Timestamp when the snapshot was created */
|
|
121
|
+
createdAt: number;
|
|
122
|
+
/** All messages in the conversation */
|
|
123
|
+
messages: ConversationMessage[];
|
|
124
|
+
/** Optional metadata about the conversation */
|
|
125
|
+
metadata?: {
|
|
126
|
+
/** Name or description of the conversation */
|
|
127
|
+
name?: string;
|
|
128
|
+
/** Tags or labels for categorization */
|
|
129
|
+
tags?: string[];
|
|
130
|
+
/** Custom application-specific data */
|
|
131
|
+
custom?: Record<string, unknown>;
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Query parameters for searching conversation history.
|
|
136
|
+
*
|
|
137
|
+
* @since 2.0.0
|
|
138
|
+
*/
|
|
139
|
+
export interface ConversationQuery {
|
|
140
|
+
/** Filter by message role (system, user, assistant, tool) */
|
|
141
|
+
role?: string;
|
|
142
|
+
/** Search for messages containing this text (case-insensitive) */
|
|
143
|
+
content?: string;
|
|
144
|
+
/** Filter by stage ID */
|
|
145
|
+
stageId?: string;
|
|
146
|
+
/** Filter by timestamp range */
|
|
147
|
+
after?: number;
|
|
148
|
+
before?: number;
|
|
149
|
+
/** Filter by importance flag */
|
|
150
|
+
important?: boolean;
|
|
151
|
+
/** Limit number of results */
|
|
152
|
+
limit?: number;
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Main interface for managing conversation history.
|
|
156
|
+
*
|
|
157
|
+
* Implementations should be thread-safe and handle concurrent access.
|
|
158
|
+
*
|
|
159
|
+
* @since 2.0.0
|
|
160
|
+
*
|
|
161
|
+
* @example
|
|
162
|
+
* ```typescript
|
|
163
|
+
* // Create a conversation manager
|
|
164
|
+
* const conversation = new InMemoryConversationManager();
|
|
165
|
+
*
|
|
166
|
+
* // Add messages
|
|
167
|
+
* await conversation.addMessage({
|
|
168
|
+
* role: "user",
|
|
169
|
+
* content: "Hello!"
|
|
170
|
+
* });
|
|
171
|
+
*
|
|
172
|
+
* await conversation.addMessage({
|
|
173
|
+
* role: "assistant",
|
|
174
|
+
* content: "Hi! How can I help?"
|
|
175
|
+
* });
|
|
176
|
+
*
|
|
177
|
+
* // Get recent messages
|
|
178
|
+
* const recent = await conversation.getRecent(10);
|
|
179
|
+
*
|
|
180
|
+
* // Search for specific messages
|
|
181
|
+
* const userMessages = await conversation.search({ role: "user" });
|
|
182
|
+
*
|
|
183
|
+
* // Prune old messages
|
|
184
|
+
* await conversation.prune({
|
|
185
|
+
* keepRecent: 100,
|
|
186
|
+
* maxAge: 24 * 60 * 60 * 1000 // 24 hours
|
|
187
|
+
* });
|
|
188
|
+
*
|
|
189
|
+
* // Export for persistence
|
|
190
|
+
* const snapshot = await conversation.export();
|
|
191
|
+
* await fs.writeFile("conversation.json", JSON.stringify(snapshot));
|
|
192
|
+
*
|
|
193
|
+
* // Import later
|
|
194
|
+
* const loaded = JSON.parse(await fs.readFile("conversation.json"));
|
|
195
|
+
* await conversation.import(loaded);
|
|
196
|
+
* ```
|
|
197
|
+
*/
|
|
198
|
+
export interface ConversationManager {
|
|
199
|
+
/**
|
|
200
|
+
* Add a new message to the conversation history.
|
|
201
|
+
*
|
|
202
|
+
* The message will be assigned a unique ID and timestamp automatically.
|
|
203
|
+
*
|
|
204
|
+
* @param message - The message to add
|
|
205
|
+
* @param metadata - Optional metadata (id and timestamp will be auto-generated if not provided)
|
|
206
|
+
* @returns Promise that resolves when the message is added
|
|
207
|
+
*/
|
|
208
|
+
addMessage(message: Message, metadata?: Partial<Omit<MessageMetadata, "id" | "timestamp">>): Promise<void>;
|
|
209
|
+
/**
|
|
210
|
+
* Get the complete conversation history.
|
|
211
|
+
*
|
|
212
|
+
* @returns Promise that resolves to all messages in chronological order
|
|
213
|
+
*/
|
|
214
|
+
getHistory(): Promise<ConversationMessage[]>;
|
|
215
|
+
/**
|
|
216
|
+
* Get the most recent N messages.
|
|
217
|
+
*
|
|
218
|
+
* @param count - Number of messages to retrieve
|
|
219
|
+
* @returns Promise that resolves to the most recent messages in chronological order
|
|
220
|
+
*/
|
|
221
|
+
getRecent(count: number): Promise<ConversationMessage[]>;
|
|
222
|
+
/**
|
|
223
|
+
* Search for messages matching the query criteria.
|
|
224
|
+
*
|
|
225
|
+
* @param query - Search parameters
|
|
226
|
+
* @returns Promise that resolves to matching messages in chronological order
|
|
227
|
+
*/
|
|
228
|
+
search(query: ConversationQuery): Promise<ConversationMessage[]>;
|
|
229
|
+
/**
|
|
230
|
+
* Remove old or unimportant messages based on the pruning strategy.
|
|
231
|
+
*
|
|
232
|
+
* Messages are kept if they match ANY of the keep criteria:
|
|
233
|
+
* - Among the most recent N messages (keepRecent)
|
|
234
|
+
* - Marked as important (keepImportant returns true)
|
|
235
|
+
* - Within the max age threshold (maxAge)
|
|
236
|
+
*
|
|
237
|
+
* @param strategy - Strategy for determining which messages to keep
|
|
238
|
+
* @returns Promise that resolves to the number of messages pruned
|
|
239
|
+
*/
|
|
240
|
+
prune(strategy: PruneStrategy): Promise<number>;
|
|
241
|
+
/**
|
|
242
|
+
* Clear all messages from the conversation.
|
|
243
|
+
*
|
|
244
|
+
* @returns Promise that resolves when the conversation is cleared
|
|
245
|
+
*/
|
|
246
|
+
clear(): Promise<void>;
|
|
247
|
+
/**
|
|
248
|
+
* Get statistics about the current conversation.
|
|
249
|
+
*
|
|
250
|
+
* @returns Promise that resolves to conversation statistics
|
|
251
|
+
*/
|
|
252
|
+
getStats(): Promise<ConversationStats>;
|
|
253
|
+
/**
|
|
254
|
+
* Export the conversation to a snapshot for persistence.
|
|
255
|
+
*
|
|
256
|
+
* The snapshot is a plain JavaScript object that can be JSON-serialized.
|
|
257
|
+
*
|
|
258
|
+
* @returns Promise that resolves to a conversation snapshot
|
|
259
|
+
*/
|
|
260
|
+
export(): Promise<ConversationSnapshot>;
|
|
261
|
+
/**
|
|
262
|
+
* Import a conversation from a snapshot.
|
|
263
|
+
*
|
|
264
|
+
* This will replace the current conversation with the imported one.
|
|
265
|
+
* Use with caution - consider backing up the current conversation first.
|
|
266
|
+
*
|
|
267
|
+
* @param snapshot - The conversation snapshot to import
|
|
268
|
+
* @returns Promise that resolves when the import is complete
|
|
269
|
+
*/
|
|
270
|
+
import(snapshot: ConversationSnapshot): Promise<void>;
|
|
271
|
+
}
|
|
272
|
+
//# sourceMappingURL=conversation-manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"conversation-manager.d.ts","sourceRoot":"","sources":["../../../src/conversation/conversation-manager.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAE/C;;;;GAIG;AACH,MAAM,WAAW,eAAe;IAC9B,yCAAyC;IACzC,EAAE,EAAE,MAAM,CAAC;IACX,2CAA2C;IAC3C,SAAS,EAAE,MAAM,CAAC;IAClB,oDAAoD;IACpD,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,2CAA2C;IAC3C,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,2EAA2E;IAC3E,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,mDAAmD;IACnD,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,C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C,IAAI,CAAC,CAAC;CACvD"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Conversation history management for long-running AI agents.
|
|
3
|
+
*
|
|
4
|
+
* This module provides interfaces for managing conversation history,
|
|
5
|
+
* including message storage, pruning strategies, and export/import functionality.
|
|
6
|
+
*
|
|
7
|
+
* @module conversation
|
|
8
|
+
* @since 2.0.0
|
|
9
|
+
*/
|
|
10
|
+
export {};
|
|
11
|
+
//# sourceMappingURL=conversation-manager.js.map
|