general-agent-runtime 0.0.1
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 +311 -0
- package/dist/agent/agent.d.ts +14 -0
- package/dist/agent/agent.js +25 -0
- package/dist/agent/agent.js.map +1 -0
- package/dist/agent/builder.d.ts +28 -0
- package/dist/agent/builder.js +178 -0
- package/dist/agent/builder.js.map +1 -0
- package/dist/agent/create-agent.d.ts +2 -0
- package/dist/agent/create-agent.js +29 -0
- package/dist/agent/create-agent.js.map +1 -0
- package/dist/agent/index.d.ts +8 -0
- package/dist/agent/index.js +8 -0
- package/dist/agent/index.js.map +1 -0
- package/dist/agent/integrations/session-context-source.d.ts +12 -0
- package/dist/agent/integrations/session-context-source.js +84 -0
- package/dist/agent/integrations/session-context-source.js.map +1 -0
- package/dist/agent/integrations/session-run-recorder.d.ts +17 -0
- package/dist/agent/integrations/session-run-recorder.js +60 -0
- package/dist/agent/integrations/session-run-recorder.js.map +1 -0
- package/dist/agent/loop-factory.d.ts +11 -0
- package/dist/agent/loop-factory.js +16 -0
- package/dist/agent/loop-factory.js.map +1 -0
- package/dist/agent/run-manager.d.ts +38 -0
- package/dist/agent/run-manager.js +96 -0
- package/dist/agent/run-manager.js.map +1 -0
- package/dist/agent/types.d.ts +38 -0
- package/dist/agent/types.js +2 -0
- package/dist/agent/types.js.map +1 -0
- package/dist/cli/main.d.ts +2 -0
- package/dist/cli/main.js +88 -0
- package/dist/cli/main.js.map +1 -0
- package/dist/cli/renderer.d.ts +2 -0
- package/dist/cli/renderer.js +36 -0
- package/dist/cli/renderer.js.map +1 -0
- package/dist/compaction/budget.d.ts +14 -0
- package/dist/compaction/budget.js +28 -0
- package/dist/compaction/budget.js.map +1 -0
- package/dist/compaction/deterministic.d.ts +9 -0
- package/dist/compaction/deterministic.js +106 -0
- package/dist/compaction/deterministic.js.map +1 -0
- package/dist/compaction/index.d.ts +5 -0
- package/dist/compaction/index.js +5 -0
- package/dist/compaction/index.js.map +1 -0
- package/dist/compaction/manager.d.ts +22 -0
- package/dist/compaction/manager.js +111 -0
- package/dist/compaction/manager.js.map +1 -0
- package/dist/compaction/semantic.d.ts +13 -0
- package/dist/compaction/semantic.js +234 -0
- package/dist/compaction/semantic.js.map +1 -0
- package/dist/compaction/strategy.d.ts +1 -0
- package/dist/compaction/strategy.js +2 -0
- package/dist/compaction/strategy.js.map +1 -0
- package/dist/compaction/types.d.ts +40 -0
- package/dist/compaction/types.js +2 -0
- package/dist/compaction/types.js.map +1 -0
- package/dist/context/budget.d.ts +12 -0
- package/dist/context/budget.js +13 -0
- package/dist/context/budget.js.map +1 -0
- package/dist/context/controller.d.ts +17 -0
- package/dist/context/controller.js +78 -0
- package/dist/context/controller.js.map +1 -0
- package/dist/context/index.d.ts +14 -0
- package/dist/context/index.js +13 -0
- package/dist/context/index.js.map +1 -0
- package/dist/context/manager.d.ts +10 -0
- package/dist/context/manager.js +65 -0
- package/dist/context/manager.js.map +1 -0
- package/dist/context/pipeline.d.ts +16 -0
- package/dist/context/pipeline.js +45 -0
- package/dist/context/pipeline.js.map +1 -0
- package/dist/context/projection.d.ts +8 -0
- package/dist/context/projection.js +10 -0
- package/dist/context/projection.js.map +1 -0
- package/dist/context/source.d.ts +6 -0
- package/dist/context/source.js +2 -0
- package/dist/context/source.js.map +1 -0
- package/dist/context/sources/dynamic.d.ts +10 -0
- package/dist/context/sources/dynamic.js +13 -0
- package/dist/context/sources/dynamic.js.map +1 -0
- package/dist/context/sources/project.d.ts +19 -0
- package/dist/context/sources/project.js +75 -0
- package/dist/context/sources/project.js.map +1 -0
- package/dist/context/sources/system.d.ts +14 -0
- package/dist/context/sources/system.js +23 -0
- package/dist/context/sources/system.js.map +1 -0
- package/dist/context/sources/user.d.ts +14 -0
- package/dist/context/sources/user.js +23 -0
- package/dist/context/sources/user.js.map +1 -0
- package/dist/context/stages/deduplicate.d.ts +7 -0
- package/dist/context/stages/deduplicate.js +19 -0
- package/dist/context/stages/deduplicate.js.map +1 -0
- package/dist/context/stages/expiration.d.ts +5 -0
- package/dist/context/stages/expiration.js +14 -0
- package/dist/context/stages/expiration.js.map +1 -0
- package/dist/context/stages/visibility.d.ts +5 -0
- package/dist/context/stages/visibility.js +7 -0
- package/dist/context/stages/visibility.js.map +1 -0
- package/dist/context/types.d.ts +72 -0
- package/dist/context/types.js +2 -0
- package/dist/context/types.js.map +1 -0
- package/dist/errors/codes.d.ts +1 -0
- package/dist/errors/codes.js +2 -0
- package/dist/errors/codes.js.map +1 -0
- package/dist/errors/index.d.ts +4 -0
- package/dist/errors/index.js +4 -0
- package/dist/errors/index.js.map +1 -0
- package/dist/errors/normalize.d.ts +2 -0
- package/dist/errors/normalize.js +32 -0
- package/dist/errors/normalize.js.map +1 -0
- package/dist/errors/runtime-error.d.ts +18 -0
- package/dist/errors/runtime-error.js +21 -0
- package/dist/errors/runtime-error.js.map +1 -0
- package/dist/errors/serialize.d.ts +2 -0
- package/dist/errors/serialize.js +12 -0
- package/dist/errors/serialize.js.map +1 -0
- package/dist/events/bus.d.ts +17 -0
- package/dist/events/bus.js +52 -0
- package/dist/events/bus.js.map +1 -0
- package/dist/events/index.d.ts +6 -0
- package/dist/events/index.js +5 -0
- package/dist/events/index.js.map +1 -0
- package/dist/events/publisher.d.ts +12 -0
- package/dist/events/publisher.js +22 -0
- package/dist/events/publisher.js.map +1 -0
- package/dist/events/sequence.d.ts +6 -0
- package/dist/events/sequence.js +14 -0
- package/dist/events/sequence.js.map +1 -0
- package/dist/events/sink.d.ts +5 -0
- package/dist/events/sink.js +2 -0
- package/dist/events/sink.js.map +1 -0
- package/dist/events/stream.d.ts +12 -0
- package/dist/events/stream.js +46 -0
- package/dist/events/stream.js.map +1 -0
- package/dist/events/types.d.ts +42 -0
- package/dist/events/types.js +2 -0
- package/dist/events/types.js.map +1 -0
- package/dist/hooks/bus.d.ts +14 -0
- package/dist/hooks/bus.js +104 -0
- package/dist/hooks/bus.js.map +1 -0
- package/dist/hooks/index.d.ts +5 -0
- package/dist/hooks/index.js +5 -0
- package/dist/hooks/index.js.map +1 -0
- package/dist/hooks/policy.d.ts +3 -0
- package/dist/hooks/policy.js +33 -0
- package/dist/hooks/policy.js.map +1 -0
- package/dist/hooks/registry.d.ts +13 -0
- package/dist/hooks/registry.js +31 -0
- package/dist/hooks/registry.js.map +1 -0
- package/dist/hooks/timeout.d.ts +2 -0
- package/dist/hooks/timeout.js +63 -0
- package/dist/hooks/timeout.js.map +1 -0
- package/dist/hooks/types.d.ts +40 -0
- package/dist/hooks/types.js +2 -0
- package/dist/hooks/types.js.map +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +14 -0
- package/dist/index.js.map +1 -0
- package/dist/loop/index.d.ts +7 -0
- package/dist/loop/index.js +6 -0
- package/dist/loop/index.js.map +1 -0
- package/dist/loop/loop.d.ts +22 -0
- package/dist/loop/loop.js +623 -0
- package/dist/loop/loop.js.map +1 -0
- package/dist/loop/policy.d.ts +21 -0
- package/dist/loop/policy.js +54 -0
- package/dist/loop/policy.js.map +1 -0
- package/dist/loop/recorder.d.ts +9 -0
- package/dist/loop/recorder.js +2 -0
- package/dist/loop/recorder.js.map +1 -0
- package/dist/loop/state.d.ts +18 -0
- package/dist/loop/state.js +81 -0
- package/dist/loop/state.js.map +1 -0
- package/dist/loop/stream-assembler.d.ts +12 -0
- package/dist/loop/stream-assembler.js +76 -0
- package/dist/loop/stream-assembler.js.map +1 -0
- package/dist/loop/transition.d.ts +2 -0
- package/dist/loop/transition.js +27 -0
- package/dist/loop/transition.js.map +1 -0
- package/dist/loop/types.d.ts +53 -0
- package/dist/loop/types.js +2 -0
- package/dist/loop/types.js.map +1 -0
- package/dist/model/index.d.ts +6 -0
- package/dist/model/index.js +5 -0
- package/dist/model/index.js.map +1 -0
- package/dist/model/provider.d.ts +6 -0
- package/dist/model/provider.js +2 -0
- package/dist/model/provider.js.map +1 -0
- package/dist/model/providers/openai-compatible/adapter.d.ts +3 -0
- package/dist/model/providers/openai-compatible/adapter.js +92 -0
- package/dist/model/providers/openai-compatible/adapter.js.map +1 -0
- package/dist/model/providers/openai-compatible/errors.d.ts +3 -0
- package/dist/model/providers/openai-compatible/errors.js +68 -0
- package/dist/model/providers/openai-compatible/errors.js.map +1 -0
- package/dist/model/providers/openai-compatible/provider.d.ts +18 -0
- package/dist/model/providers/openai-compatible/provider.js +182 -0
- package/dist/model/providers/openai-compatible/provider.js.map +1 -0
- package/dist/model/providers/openai-compatible/stream-parser.d.ts +1 -0
- package/dist/model/providers/openai-compatible/stream-parser.js +45 -0
- package/dist/model/providers/openai-compatible/stream-parser.js.map +1 -0
- package/dist/model/registry.d.ts +9 -0
- package/dist/model/registry.js +35 -0
- package/dist/model/registry.js.map +1 -0
- package/dist/model/types.d.ts +49 -0
- package/dist/model/types.js +2 -0
- package/dist/model/types.js.map +1 -0
- package/dist/session/factory.d.ts +13 -0
- package/dist/session/factory.js +14 -0
- package/dist/session/factory.js.map +1 -0
- package/dist/session/index.d.ts +8 -0
- package/dist/session/index.js +7 -0
- package/dist/session/index.js.map +1 -0
- package/dist/session/jsonl-store.d.ts +20 -0
- package/dist/session/jsonl-store.js +264 -0
- package/dist/session/jsonl-store.js.map +1 -0
- package/dist/session/projector.d.ts +4 -0
- package/dist/session/projector.js +104 -0
- package/dist/session/projector.js.map +1 -0
- package/dist/session/serializer.d.ts +5 -0
- package/dist/session/serializer.js +126 -0
- package/dist/session/serializer.js.map +1 -0
- package/dist/session/session.d.ts +32 -0
- package/dist/session/session.js +129 -0
- package/dist/session/session.js.map +1 -0
- package/dist/session/store.d.ts +9 -0
- package/dist/session/store.js +2 -0
- package/dist/session/store.js.map +1 -0
- package/dist/session/types.d.ts +29 -0
- package/dist/session/types.js +2 -0
- package/dist/session/types.js.map +1 -0
- package/dist/settings/defaults.d.ts +7 -0
- package/dist/settings/defaults.js +40 -0
- package/dist/settings/defaults.js.map +1 -0
- package/dist/settings/env-source.d.ts +8 -0
- package/dist/settings/env-source.js +26 -0
- package/dist/settings/env-source.js.map +1 -0
- package/dist/settings/file-source.d.ts +9 -0
- package/dist/settings/file-source.js +32 -0
- package/dist/settings/file-source.js.map +1 -0
- package/dist/settings/index.d.ts +8 -0
- package/dist/settings/index.js +7 -0
- package/dist/settings/index.js.map +1 -0
- package/dist/settings/resolver.d.ts +5 -0
- package/dist/settings/resolver.js +29 -0
- package/dist/settings/resolver.js.map +1 -0
- package/dist/settings/runtime-source.d.ts +8 -0
- package/dist/settings/runtime-source.js +11 -0
- package/dist/settings/runtime-source.js.map +1 -0
- package/dist/settings/schema.d.ts +37 -0
- package/dist/settings/schema.js +47 -0
- package/dist/settings/schema.js.map +1 -0
- package/dist/settings/source.d.ts +5 -0
- package/dist/settings/source.js +2 -0
- package/dist/settings/source.js.map +1 -0
- package/dist/settings/types.d.ts +46 -0
- package/dist/settings/types.js +2 -0
- package/dist/settings/types.js.map +1 -0
- package/dist/tools/builtin/list-directory.d.ts +17 -0
- package/dist/tools/builtin/list-directory.js +31 -0
- package/dist/tools/builtin/list-directory.js.map +1 -0
- package/dist/tools/builtin/read-file.d.ts +14 -0
- package/dist/tools/builtin/read-file.js +23 -0
- package/dist/tools/builtin/read-file.js.map +1 -0
- package/dist/tools/builtin/run-command.d.ts +19 -0
- package/dist/tools/builtin/run-command.js +46 -0
- package/dist/tools/builtin/run-command.js.map +1 -0
- package/dist/tools/builtin/write-file.d.ts +20 -0
- package/dist/tools/builtin/write-file.js +29 -0
- package/dist/tools/builtin/write-file.js.map +1 -0
- package/dist/tools/executor.d.ts +29 -0
- package/dist/tools/executor.js +212 -0
- package/dist/tools/executor.js.map +1 -0
- package/dist/tools/index.d.ts +10 -0
- package/dist/tools/index.js +9 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/registry.d.ts +19 -0
- package/dist/tools/registry.js +42 -0
- package/dist/tools/registry.js.map +1 -0
- package/dist/tools/result-processor.d.ts +4 -0
- package/dist/tools/result-processor.js +122 -0
- package/dist/tools/result-processor.js.map +1 -0
- package/dist/tools/tool.d.ts +8 -0
- package/dist/tools/tool.js +2 -0
- package/dist/tools/tool.js.map +1 -0
- package/dist/tools/types.d.ts +44 -0
- package/dist/tools/types.js +2 -0
- package/dist/tools/types.js.map +1 -0
- package/dist/tools/validator.d.ts +5 -0
- package/dist/tools/validator.js +112 -0
- package/dist/tools/validator.js.map +1 -0
- package/dist/types/compaction.d.ts +22 -0
- package/dist/types/compaction.js +2 -0
- package/dist/types/compaction.js.map +1 -0
- package/dist/types/error.d.ts +10 -0
- package/dist/types/error.js +2 -0
- package/dist/types/error.js.map +1 -0
- package/dist/types/ids.d.ts +12 -0
- package/dist/types/ids.js +2 -0
- package/dist/types/ids.js.map +1 -0
- package/dist/types/index.d.ts +9 -0
- package/dist/types/index.js +2 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/json.d.ts +7 -0
- package/dist/types/json.js +2 -0
- package/dist/types/json.js.map +1 -0
- package/dist/types/message.d.ts +39 -0
- package/dist/types/message.js +2 -0
- package/dist/types/message.js.map +1 -0
- package/dist/types/metadata.d.ts +2 -0
- package/dist/types/metadata.js +2 -0
- package/dist/types/metadata.js.map +1 -0
- package/dist/types/runtime.d.ts +20 -0
- package/dist/types/runtime.js +2 -0
- package/dist/types/runtime.js.map +1 -0
- package/dist/types/tool.d.ts +12 -0
- package/dist/types/tool.js +2 -0
- package/dist/types/tool.js.map +1 -0
- package/dist/types/usage.d.ts +17 -0
- package/dist/types/usage.js +2 -0
- package/dist/types/usage.js.map +1 -0
- package/dist/utils/deep.d.ts +2 -0
- package/dist/utils/deep.js +34 -0
- package/dist/utils/deep.js.map +1 -0
- package/dist/utils/id.d.ts +10 -0
- package/dist/utils/id.js +14 -0
- package/dist/utils/id.js.map +1 -0
- package/dist/utils/index.d.ts +3 -0
- package/dist/utils/index.js +4 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/message.d.ts +11 -0
- package/dist/utils/message.js +31 -0
- package/dist/utils/message.js.map +1 -0
- package/package.json +59 -0
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { RuntimeError } from "../errors/index.js";
|
|
2
|
+
import { deepFreeze } from "../utils/index.js";
|
|
3
|
+
function contextError(message) {
|
|
4
|
+
return new RuntimeError({
|
|
5
|
+
code: "INTERNAL",
|
|
6
|
+
category: "context",
|
|
7
|
+
message,
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
function cloneItem(item) {
|
|
11
|
+
return deepFreeze(structuredClone(item));
|
|
12
|
+
}
|
|
13
|
+
export class DefaultContextController {
|
|
14
|
+
items = new Map();
|
|
15
|
+
async apply(mutation, signal) {
|
|
16
|
+
await this.applyMany([mutation], signal);
|
|
17
|
+
}
|
|
18
|
+
async applyMany(mutations, signal) {
|
|
19
|
+
signal?.throwIfAborted();
|
|
20
|
+
const next = new Map(this.items);
|
|
21
|
+
for (const mutation of mutations) {
|
|
22
|
+
signal?.throwIfAborted();
|
|
23
|
+
this.applyTo(next, mutation);
|
|
24
|
+
}
|
|
25
|
+
this.items = next;
|
|
26
|
+
}
|
|
27
|
+
get(id) {
|
|
28
|
+
return this.items.get(id);
|
|
29
|
+
}
|
|
30
|
+
list(scope) {
|
|
31
|
+
const values = [...this.items.values()];
|
|
32
|
+
return scope === undefined
|
|
33
|
+
? values
|
|
34
|
+
: values.filter((item) => item.scope === scope);
|
|
35
|
+
}
|
|
36
|
+
applyTo(target, mutation) {
|
|
37
|
+
switch (mutation.type) {
|
|
38
|
+
case "add": {
|
|
39
|
+
this.assertDynamic(mutation.item);
|
|
40
|
+
if (target.has(mutation.item.id)) {
|
|
41
|
+
throw contextError(`Context item already exists: ${mutation.item.id}`);
|
|
42
|
+
}
|
|
43
|
+
target.set(mutation.item.id, cloneItem(mutation.item));
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
case "replace": {
|
|
47
|
+
this.assertDynamic(mutation.item);
|
|
48
|
+
if (mutation.item.id !== mutation.id) {
|
|
49
|
+
throw contextError("Replacement context item id must match mutation id");
|
|
50
|
+
}
|
|
51
|
+
if (!target.has(mutation.id)) {
|
|
52
|
+
throw contextError(`Context item not found: ${mutation.id}`);
|
|
53
|
+
}
|
|
54
|
+
target.set(mutation.id, cloneItem(mutation.item));
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
case "remove":
|
|
58
|
+
target.delete(mutation.id);
|
|
59
|
+
return;
|
|
60
|
+
case "clear_scope":
|
|
61
|
+
if (mutation.scope !== "dynamic") {
|
|
62
|
+
throw contextError("ContextController can only clear dynamic scope");
|
|
63
|
+
}
|
|
64
|
+
for (const [id, item] of target) {
|
|
65
|
+
if (item.scope === mutation.scope) {
|
|
66
|
+
target.delete(id);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
assertDynamic(item) {
|
|
73
|
+
if (item.scope !== "dynamic") {
|
|
74
|
+
throw contextError("ContextController only accepts dynamic context items");
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
//# sourceMappingURL=controller.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"controller.js","sourceRoot":"","sources":["../../src/context/controller.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAQ/C,SAAS,YAAY,CAAC,OAAe;IACnC,OAAO,IAAI,YAAY,CAAC;QACtB,IAAI,EAAE,UAAU;QAChB,QAAQ,EAAE,SAAS;QACnB,OAAO;KACR,CAAC,CAAC;AACL,CAAC;AAED,SAAS,SAAS,CAAC,IAAiB;IAClC,OAAO,UAAU,CAAC,eAAe,CAAC,IAAI,CAAC,CAAgB,CAAC;AAC1D,CAAC;AAkBD,MAAM,OAAO,wBAAwB;IAC3B,KAAK,GAAG,IAAI,GAAG,EAA8B,CAAC;IAEtD,KAAK,CAAC,KAAK,CACT,QAAyB,EACzB,MAAoB;QAEp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AAC,sDAAsD,CAAC,CAAC;QAC7E,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export type * from "./types.js";
|
|
2
|
+
export type * from "./source.js";
|
|
3
|
+
export { DefaultContextController, type ContextController, } from "./controller.js";
|
|
4
|
+
export { CharacterTokenEstimator, type ProjectionPipeline, } from "./projection.js";
|
|
5
|
+
export { DefaultProjectionPipeline, type DefaultProjectionPipelineOptions, } from "./pipeline.js";
|
|
6
|
+
export { DefaultContextManager } from "./manager.js";
|
|
7
|
+
export { DefaultProjectionBudgetPolicy, type ProjectionBudgetPolicy, type ProjectionBudgetRequest, } from "./budget.js";
|
|
8
|
+
export { SystemContextSource, type SystemContextSourceOptions, } from "./sources/system.js";
|
|
9
|
+
export { ProjectContextSource, type ProjectContextSourceOptions, } from "./sources/project.js";
|
|
10
|
+
export { UserContextSource, type UserContextSourceOptions, } from "./sources/user.js";
|
|
11
|
+
export { DynamicContextSource } from "./sources/dynamic.js";
|
|
12
|
+
export { VisibilityFilterStage } from "./stages/visibility.js";
|
|
13
|
+
export { ExpirationFilterStage } from "./stages/expiration.js";
|
|
14
|
+
export { DeduplicateStage } from "./stages/deduplicate.js";
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export { DefaultContextController, } from "./controller.js";
|
|
2
|
+
export { CharacterTokenEstimator, } from "./projection.js";
|
|
3
|
+
export { DefaultProjectionPipeline, } from "./pipeline.js";
|
|
4
|
+
export { DefaultContextManager } from "./manager.js";
|
|
5
|
+
export { DefaultProjectionBudgetPolicy, } from "./budget.js";
|
|
6
|
+
export { SystemContextSource, } from "./sources/system.js";
|
|
7
|
+
export { ProjectContextSource, } from "./sources/project.js";
|
|
8
|
+
export { UserContextSource, } from "./sources/user.js";
|
|
9
|
+
export { DynamicContextSource } from "./sources/dynamic.js";
|
|
10
|
+
export { VisibilityFilterStage } from "./stages/visibility.js";
|
|
11
|
+
export { ExpirationFilterStage } from "./stages/expiration.js";
|
|
12
|
+
export { DeduplicateStage } from "./stages/deduplicate.js";
|
|
13
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/context/index.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,wBAAwB,GAEzB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,uBAAuB,GAExB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,yBAAyB,GAE1B,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AACrD,OAAO,EACL,6BAA6B,GAG9B,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,mBAAmB,GAEpB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,oBAAoB,GAErB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACL,iBAAiB,GAElB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAC5D,OAAO,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAC/D,OAAO,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAC/D,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ProjectionPipeline } from "./projection.js";
|
|
2
|
+
import type { ContextSource } from "./source.js";
|
|
3
|
+
import type { ContextLoadRequest, ContextManager, ContextSnapshot, ProjectionRequest, ProjectionResult } from "./types.js";
|
|
4
|
+
export declare class DefaultContextManager implements ContextManager {
|
|
5
|
+
private readonly sources;
|
|
6
|
+
private readonly pipeline;
|
|
7
|
+
constructor(sources: readonly ContextSource[], pipeline: ProjectionPipeline);
|
|
8
|
+
snapshot(request: ContextLoadRequest, signal?: AbortSignal): Promise<ContextSnapshot>;
|
|
9
|
+
project(request: ProjectionRequest, signal?: AbortSignal): Promise<ProjectionResult>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { RuntimeError } from "../errors/runtime-error.js";
|
|
2
|
+
import { deepFreeze } from "../utils/deep.js";
|
|
3
|
+
const SCOPE_ORDER = {
|
|
4
|
+
system: 0,
|
|
5
|
+
project: 1,
|
|
6
|
+
user: 2,
|
|
7
|
+
dynamic: 3,
|
|
8
|
+
session: 4,
|
|
9
|
+
};
|
|
10
|
+
function contextError(message) {
|
|
11
|
+
return new RuntimeError({
|
|
12
|
+
code: "INTERNAL",
|
|
13
|
+
category: "context",
|
|
14
|
+
message,
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
function compareItems(left, right) {
|
|
18
|
+
const scope = SCOPE_ORDER[left.scope] - SCOPE_ORDER[right.scope];
|
|
19
|
+
if (scope !== 0) {
|
|
20
|
+
return scope;
|
|
21
|
+
}
|
|
22
|
+
const priority = right.priority - left.priority;
|
|
23
|
+
if (priority !== 0) {
|
|
24
|
+
return priority;
|
|
25
|
+
}
|
|
26
|
+
const created = left.createdAt.localeCompare(right.createdAt);
|
|
27
|
+
if (created !== 0) {
|
|
28
|
+
return created;
|
|
29
|
+
}
|
|
30
|
+
return left.id.localeCompare(right.id);
|
|
31
|
+
}
|
|
32
|
+
export class DefaultContextManager {
|
|
33
|
+
sources;
|
|
34
|
+
pipeline;
|
|
35
|
+
constructor(sources, pipeline) {
|
|
36
|
+
this.sources = sources;
|
|
37
|
+
this.pipeline = pipeline;
|
|
38
|
+
}
|
|
39
|
+
async snapshot(request, signal) {
|
|
40
|
+
signal?.throwIfAborted();
|
|
41
|
+
const items = [];
|
|
42
|
+
for (const source of this.sources) {
|
|
43
|
+
signal?.throwIfAborted();
|
|
44
|
+
const loaded = await source.load(request, signal);
|
|
45
|
+
for (const item of loaded) {
|
|
46
|
+
if (item.scope !== source.scope) {
|
|
47
|
+
throw contextError(`Context source ${source.id} returned scope ${item.scope}, expected ${source.scope}`);
|
|
48
|
+
}
|
|
49
|
+
items.push(structuredClone(item));
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
items.sort(compareItems);
|
|
53
|
+
return deepFreeze({
|
|
54
|
+
sessionId: request.sessionId,
|
|
55
|
+
runId: request.runId,
|
|
56
|
+
turnId: request.turnId,
|
|
57
|
+
items,
|
|
58
|
+
createdAt: new Date().toISOString(),
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
project(request, signal) {
|
|
62
|
+
return this.pipeline.project(request, signal);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manager.js","sourceRoot":"","sources":["../../src/context/manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAa9C,MAAM,WAAW,GAAiC;IAChD,MAAM,EAAE,CAAC;IACT,OAAO,EAAE,CAAC;IACV,IAAI,EAAE,CAAC;IACP,OAAO,EAAE,CAAC;IACV,OAAO,EAAE,CAAC;CACX,CAAC;AAEF,SAAS,YAAY,CAAC,OAAe;IACnC,OAAO,IAAI,YAAY,CAAC;QACtB,IAAI,EAAE,UAAU;QAChB,QAAQ,EAAE,SAAS;QACnB,OAAO;KACR,CAAC,CAAC;AACL,CAAC;AAED,SAAS,YAAY,CAAC,IAAiB,EAAE,KAAkB;IACzD,MAAM,KAAK,GAAG,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,WAAW,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IACjE,IAAI,KAAK,KAAK,CAAC,EAAE,CAAC;QAChB,OAAO,KAAK,CAAC;IACf,CAAC;IAED,MAAM,QAAQ,GAAG,KAAK,CAAC,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC;IAChD,IAAI,QAAQ,KAAK,CAAC,EAAE,CAAC;QACnB,OAAO,QAAQ,CAAC;IAClB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O,CAAC,MAAM;YACtB,KAAK;YACL,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;SACpC,CAAoB,CAAC;IACxB,CAAC;IAED,OAAO,CACL,OAA0B,EAC1B,MAAoB;QAEpB,OAAO,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;IAChD,CAAC;CACF"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type ProjectionPipeline } from "./projection.js";
|
|
2
|
+
import type { ProjectionRequest, ProjectionResult, ProjectionStage, TokenEstimator } from "./types.js";
|
|
3
|
+
export interface DefaultProjectionPipelineOptions {
|
|
4
|
+
estimator?: TokenEstimator;
|
|
5
|
+
stages?: readonly ProjectionStage[];
|
|
6
|
+
now?: () => Date;
|
|
7
|
+
}
|
|
8
|
+
export declare class DefaultProjectionPipeline implements ProjectionPipeline {
|
|
9
|
+
private readonly estimator;
|
|
10
|
+
private readonly stages;
|
|
11
|
+
private readonly visibility;
|
|
12
|
+
private readonly expiration;
|
|
13
|
+
private readonly now;
|
|
14
|
+
constructor(options?: DefaultProjectionPipelineOptions);
|
|
15
|
+
project(request: ProjectionRequest, signal?: AbortSignal): Promise<ProjectionResult>;
|
|
16
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { CharacterTokenEstimator, } from "./projection.js";
|
|
2
|
+
import { DeduplicateStage } from "./stages/deduplicate.js";
|
|
3
|
+
import { ExpirationFilterStage } from "./stages/expiration.js";
|
|
4
|
+
import { VisibilityFilterStage } from "./stages/visibility.js";
|
|
5
|
+
export class DefaultProjectionPipeline {
|
|
6
|
+
estimator;
|
|
7
|
+
stages;
|
|
8
|
+
visibility = new VisibilityFilterStage();
|
|
9
|
+
expiration = new ExpirationFilterStage();
|
|
10
|
+
now;
|
|
11
|
+
constructor(options = {}) {
|
|
12
|
+
this.estimator = options.estimator ?? new CharacterTokenEstimator();
|
|
13
|
+
this.stages = [...(options.stages ?? [new DeduplicateStage()])].sort((left, right) => left.order - right.order);
|
|
14
|
+
this.now = options.now ?? (() => new Date());
|
|
15
|
+
}
|
|
16
|
+
async project(request, signal) {
|
|
17
|
+
signal?.throwIfAborted();
|
|
18
|
+
const originalItems = request.snapshot.items;
|
|
19
|
+
const visible = this.visibility.apply(originalItems);
|
|
20
|
+
const active = this.expiration.apply(visible, this.now());
|
|
21
|
+
const initialMessages = active.flatMap((item) => [...item.content]);
|
|
22
|
+
const estimatedTokensBefore = this.estimator.estimate(initialMessages);
|
|
23
|
+
let messages = initialMessages;
|
|
24
|
+
for (const stage of this.stages) {
|
|
25
|
+
signal?.throwIfAborted();
|
|
26
|
+
messages = await stage.apply(messages, {
|
|
27
|
+
model: request.model,
|
|
28
|
+
capabilities: request.capabilities,
|
|
29
|
+
}, signal);
|
|
30
|
+
}
|
|
31
|
+
const estimatedTokensAfter = this.estimator.estimate(messages);
|
|
32
|
+
const filteredItemCount = originalItems.length - active.length;
|
|
33
|
+
const deduplicatedMessages = Math.max(0, initialMessages.length - messages.length);
|
|
34
|
+
return {
|
|
35
|
+
messages: [...messages],
|
|
36
|
+
stats: {
|
|
37
|
+
estimatedTokensBefore,
|
|
38
|
+
estimatedTokensAfter,
|
|
39
|
+
removedItems: filteredItemCount,
|
|
40
|
+
deduplicatedMessages,
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=pipeline.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pipeline.js","sourceRoot":"","sources":["../../src/context/pipeline.ts"],"names":[],"mappings":"AACA,OAAO,EACL,uBAAuB,GAExB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAC/D,OAAO,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAc/D,MAAM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,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;YAChC,MAAM,EAAE,cAAc,EAAE,CAAC;YACzB,QAAQ,GAAG,MAAM,KAAK,CAAC,KAAK,CAC1B,QAAQ,EACR;gBACE,KAAK,EAAE,OAAO,CAAC,KAAK;gBACpB,YAAY,EAAE,OAAO,CAAC,YAAY;aACnC,EACD,MAAM,CACP,CAAC;QACJ,CAAC;QAED,MAAM,oBAAoB,GAAG,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;QAC/D,MAAM,iBAAiB,GAAG,aAAa,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;QAC/D,MAAM,oBAAoB,GAAG,IAAI,CAAC,GAAG,CACnC,CAAC,EACD,eAAe,CAAC,MAAM,GAAG,QAAQ,CAAC,MAAM,CACzC,CAAC;QAEF,OAAO;YACL,QAAQ,EAAE,CAAC,GAAG,QAAQ,CAAC;YACvB,KAAK,EAAE;gBACL,qBAAqB;gBACrB,oBAAoB;gBACpB,YAAY,EAAE,iBAAiB;gBAC/B,oBAAoB;aACrB;SACF,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { AgentMessage } from "../types/index.js";
|
|
2
|
+
import type { ProjectionRequest, ProjectionResult, TokenEstimator } from "./types.js";
|
|
3
|
+
export interface ProjectionPipeline {
|
|
4
|
+
project(request: ProjectionRequest, signal?: AbortSignal): Promise<ProjectionResult>;
|
|
5
|
+
}
|
|
6
|
+
export declare class CharacterTokenEstimator implements TokenEstimator {
|
|
7
|
+
estimate(messages: readonly AgentMessage[]): number;
|
|
8
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"projection.js","sourceRoot":"","sources":["../../src/context/projection.ts"],"names":[],"mappings":"AAcA,MAAM,OAAO,uBAAuB;IAClC,QAAQ,CAAC,QAAiC;QACxC,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC1B,OAAO,CAAC,CAAC;QACX,CAAC;QAED,MAAM,KAAK,GAAG,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC;QAC9C,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,IAAI,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC;IAC3C,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"source.js","sourceRoot":"","sources":["../../src/context/source.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ContextController } from "../controller.js";
|
|
2
|
+
import type { ContextSource } from "../source.js";
|
|
3
|
+
import type { ContextItem, ContextLoadRequest } from "../types.js";
|
|
4
|
+
export declare class DynamicContextSource implements ContextSource {
|
|
5
|
+
private readonly controller;
|
|
6
|
+
readonly id = "dynamic";
|
|
7
|
+
readonly scope: "dynamic";
|
|
8
|
+
constructor(controller: ContextController);
|
|
9
|
+
load(_request: ContextLoadRequest, signal?: AbortSignal): Promise<readonly ContextItem[]>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export class DynamicContextSource {
|
|
2
|
+
controller;
|
|
3
|
+
id = "dynamic";
|
|
4
|
+
scope = "dynamic";
|
|
5
|
+
constructor(controller) {
|
|
6
|
+
this.controller = controller;
|
|
7
|
+
}
|
|
8
|
+
async load(_request, signal) {
|
|
9
|
+
signal?.throwIfAborted();
|
|
10
|
+
return [...this.controller.list("dynamic")];
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=dynamic.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dynamic.js","sourceRoot":"","sources":["../../../src/context/sources/dynamic.ts"],"names":[],"mappings":"AAIA,MAAM,OAAO,oBAAoB;IAIF;IAHpB,EAAE,GAAG,SAAS,CAAC;IACf,KAAK,GAAG,SAAkB,CAAC;IAEpC,YAA6B,UAA6B;QAA7B,eAAU,GAAV,UAAU,CAAmB;IAAG,CAAC;IAE9D,KAAK,CAAC,IAAI,CACR,QAA4B,EAC5B,MAAoB;QAEpB,MAAM,EAAE,cAAc,EAAE,CAAC;QACzB,OAAO,CAAC,GAAG,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC;IAC9C,CAAC;CACF"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { ContextSource } from "../source.js";
|
|
2
|
+
import type { ContextItem, ContextLoadRequest, ContextVisibility } from "../types.js";
|
|
3
|
+
export interface ProjectContextSourceOptions {
|
|
4
|
+
rootDirectory: string;
|
|
5
|
+
files: readonly string[];
|
|
6
|
+
id?: string;
|
|
7
|
+
priority?: number;
|
|
8
|
+
visibility?: ContextVisibility;
|
|
9
|
+
}
|
|
10
|
+
export declare class ProjectContextSource implements ContextSource {
|
|
11
|
+
readonly id: string;
|
|
12
|
+
readonly scope: "project";
|
|
13
|
+
private readonly rootDirectory;
|
|
14
|
+
private readonly files;
|
|
15
|
+
private readonly priority;
|
|
16
|
+
private readonly visibility;
|
|
17
|
+
constructor(options: ProjectContextSourceOptions);
|
|
18
|
+
load(_request: ContextLoadRequest, signal?: AbortSignal): Promise<readonly ContextItem[]>;
|
|
19
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { RuntimeError, normalizeUnknownError } from "../../errors/index.js";
|
|
4
|
+
import { createSystemMessage, newContextItemId } from "../../utils/index.js";
|
|
5
|
+
function isNodeError(error, code) {
|
|
6
|
+
return (error instanceof Error &&
|
|
7
|
+
"code" in error &&
|
|
8
|
+
error.code === code);
|
|
9
|
+
}
|
|
10
|
+
export class ProjectContextSource {
|
|
11
|
+
id;
|
|
12
|
+
scope = "project";
|
|
13
|
+
rootDirectory;
|
|
14
|
+
files;
|
|
15
|
+
priority;
|
|
16
|
+
visibility;
|
|
17
|
+
constructor(options) {
|
|
18
|
+
this.id = options.id ?? "project";
|
|
19
|
+
this.rootDirectory = path.resolve(options.rootDirectory);
|
|
20
|
+
this.files = [...options.files];
|
|
21
|
+
this.priority = options.priority ?? 700;
|
|
22
|
+
this.visibility = options.visibility ?? "model";
|
|
23
|
+
}
|
|
24
|
+
async load(_request, signal) {
|
|
25
|
+
signal?.throwIfAborted();
|
|
26
|
+
const items = [];
|
|
27
|
+
for (const file of this.files) {
|
|
28
|
+
signal?.throwIfAborted();
|
|
29
|
+
const target = path.resolve(this.rootDirectory, file);
|
|
30
|
+
const rootPrefix = this.rootDirectory.endsWith(path.sep)
|
|
31
|
+
? this.rootDirectory
|
|
32
|
+
: this.rootDirectory + path.sep;
|
|
33
|
+
if (target !== this.rootDirectory && !target.startsWith(rootPrefix)) {
|
|
34
|
+
throw new RuntimeError({
|
|
35
|
+
code: "INTERNAL",
|
|
36
|
+
category: "context",
|
|
37
|
+
message: `Project context file escapes root directory: ${file}`,
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
let content;
|
|
41
|
+
try {
|
|
42
|
+
content = await readFile(target, { encoding: "utf8", signal });
|
|
43
|
+
}
|
|
44
|
+
catch (error) {
|
|
45
|
+
const normalized = normalizeUnknownError(error);
|
|
46
|
+
if (normalized.code === "ABORTED") {
|
|
47
|
+
throw normalized;
|
|
48
|
+
}
|
|
49
|
+
if (isNodeError(error, "ENOENT")) {
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
throw new RuntimeError({
|
|
53
|
+
code: "INTERNAL",
|
|
54
|
+
category: "context",
|
|
55
|
+
message: `Failed to read project context file: ${file}`,
|
|
56
|
+
cause: error,
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
const createdAt = new Date().toISOString();
|
|
60
|
+
items.push({
|
|
61
|
+
id: newContextItemId(),
|
|
62
|
+
scope: this.scope,
|
|
63
|
+
source: `${this.id}:${file}`,
|
|
64
|
+
priority: this.priority,
|
|
65
|
+
visibility: this.visibility,
|
|
66
|
+
content: [
|
|
67
|
+
createSystemMessage(`Project context from ${file}:\n\n${content}`),
|
|
68
|
+
],
|
|
69
|
+
createdAt,
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
return items;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=project.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"project.js","sourceRoot":"","sources":["../../../src/context/sources/project.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,YAAY,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAC5E,OAAO,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAgB7E,SAAS,WAAW,CAAC,KAAc,EAAE,IAAY;IAC/C,OAAO,CACL,KAAK,YAAY,KAAK;QACtB,MAAM,IAAI,KAAK;QACd,KAA+B,CAAC,IAAI,KAAK,IAAI,CAC/C,CAAC;AACJ,CAAC;AAED,MAAM,OAAO,oBAAoB;IACtB,EAAE,CAAS;IACX,KAAK,GAAG,SAAkB,CAAC;IAEnB,aAAa,CAAS;IACtB,KAAK,CAAoB;IACzB,QAAQ,CAAS;IACjB,UAAU,CAAoB;IAE/C,YAAY,OAAoC;QAC9C,IAAI,CAAC,EAAE,GAAG,OAAO,CAAC,EAAE,IAAI,SAAS,CAAC;QAClC,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC;QACzD,IAAI,CAAC,KAAK,GAAG,CAAC,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC;QAChC,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,IAAI,GAAG,CAAC;QACxC,IAAI,CAAC,UAAU,GAAG,OAAO,CAAC,UAA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,YAAY,CAAC;oBACrB,IAAI,EAAE,UAAU;oBAChB,QAAQ,EAAE,SAAS;oBACnB,OAAO,EAAE,wCAAwC,IAAI,EAAE;oBACvD,KAAK,EAAE,KAAK;iBACb,CAAC,CAAC;YACL,CAAC;YAED,MAAM,SAAS,GAAG,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;YAC3C,KAAK,CAAC,IAAI,CAAC;gBACT,EAAE,EAAE,gBAAgB,EAAE;gBACtB,KAAK,EAAE,IAAI,CAAC,KAAK;gBACjB,MAAM,EAAE,GAAG,IAAI,CAAC,EAAE,IAAI,IAAI,EAAE;gBAC5B,QAAQ,EAAE,IAAI,CAAC,QAAQ;gBACvB,UAAU,EAAE,IAAI,CAAC,UAAU;gBAC3B,OAAO,EAAE;oBACP,mBAAmB,CACjB,wBAAwB,IAAI,QAAQ,OAAO,EAAE,CAC9C;iBACF;gBACD,SAAS;aACV,CAAC,CAAC;QACL,CAAC;QAED,OAAO,KAAK,CAAC;IACf,CAAC;CACF"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { ContextSource } from "../source.js";
|
|
2
|
+
import type { ContextItem, ContextLoadRequest, ContextVisibility } from "../types.js";
|
|
3
|
+
export interface SystemContextSourceOptions {
|
|
4
|
+
id?: string;
|
|
5
|
+
priority?: number;
|
|
6
|
+
visibility?: ContextVisibility;
|
|
7
|
+
}
|
|
8
|
+
export declare class SystemContextSource implements ContextSource {
|
|
9
|
+
readonly id: string;
|
|
10
|
+
readonly scope: "system";
|
|
11
|
+
private readonly item;
|
|
12
|
+
constructor(instructions: string, options?: SystemContextSourceOptions);
|
|
13
|
+
load(_request: ContextLoadRequest, signal?: AbortSignal): Promise<readonly ContextItem[]>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { deepFreeze, createSystemMessage, newContextItemId } from "../../utils/index.js";
|
|
2
|
+
export class SystemContextSource {
|
|
3
|
+
id;
|
|
4
|
+
scope = "system";
|
|
5
|
+
item;
|
|
6
|
+
constructor(instructions, options = {}) {
|
|
7
|
+
this.id = options.id ?? "system";
|
|
8
|
+
this.item = deepFreeze({
|
|
9
|
+
id: newContextItemId(),
|
|
10
|
+
scope: this.scope,
|
|
11
|
+
source: this.id,
|
|
12
|
+
priority: options.priority ?? 1000,
|
|
13
|
+
visibility: options.visibility ?? "model",
|
|
14
|
+
content: [createSystemMessage(instructions)],
|
|
15
|
+
createdAt: new Date().toISOString(),
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
async load(_request, signal) {
|
|
19
|
+
signal?.throwIfAborted();
|
|
20
|
+
return [this.item];
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=system.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"system.js","sourceRoot":"","sources":["../../../src/context/sources/system.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAUzF,MAAM,OAAO,mBAAmB;IACrB,EAAE,CAAS;IACX,KAAK,GAAG,QAAiB,CAAC;IAClB,IAAI,CAAc;IAEnC,YAAY,YAAoB,EAAE,UAAsC,EAAE;QACxE,IAAI,CAAC,EAAE,GAAG,OAAO,CAAC,EAAE,IAAI,QAAQ,CAAC;QACjC,IAAI,CAAC,IAAI,GAAG,UAAU,CAAC;YACrB,EAAE,EAAE,gBAAgB,EAAE;YACtB,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,MAAM,EAAE,IAAI,CAAC,EAAE;YACf,QAAQ,EAAE,OAAO,CAAC,QAAQ,IAAI,IAAI;YAClC,UAAU,EAAE,OAAO,CAAC,UAAU,IAAI,OAAO;YACzC,OAAO,EAAE,CAAC,mBAAmB,CAAC,YAAY,CAAC,CAAC;YAC5C,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;SACpC,CAAgB,CAAC;IACpB,CAAC;IAED,KAAK,CAAC,IAAI,CACR,QAA4B,EAC5B,MAAoB;QAEpB,MAAM,EAAE,cAAc,EAAE,CAAC;QACzB,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACrB,CAAC;CACF"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { ContextSource } from "../source.js";
|
|
2
|
+
import type { ContextItem, ContextLoadRequest, ContextVisibility } from "../types.js";
|
|
3
|
+
export interface UserContextSourceOptions {
|
|
4
|
+
id?: string;
|
|
5
|
+
priority?: number;
|
|
6
|
+
visibility?: ContextVisibility;
|
|
7
|
+
}
|
|
8
|
+
export declare class UserContextSource implements ContextSource {
|
|
9
|
+
readonly id: string;
|
|
10
|
+
readonly scope: "user";
|
|
11
|
+
private readonly item;
|
|
12
|
+
constructor(content: string, options?: UserContextSourceOptions);
|
|
13
|
+
load(_request: ContextLoadRequest, signal?: AbortSignal): Promise<readonly ContextItem[]>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { deepFreeze, createSystemMessage, newContextItemId } from "../../utils/index.js";
|
|
2
|
+
export class UserContextSource {
|
|
3
|
+
id;
|
|
4
|
+
scope = "user";
|
|
5
|
+
item;
|
|
6
|
+
constructor(content, options = {}) {
|
|
7
|
+
this.id = options.id ?? "user";
|
|
8
|
+
this.item = deepFreeze({
|
|
9
|
+
id: newContextItemId(),
|
|
10
|
+
scope: this.scope,
|
|
11
|
+
source: this.id,
|
|
12
|
+
priority: options.priority ?? 500,
|
|
13
|
+
visibility: options.visibility ?? "model",
|
|
14
|
+
content: [createSystemMessage(content)],
|
|
15
|
+
createdAt: new Date().toISOString(),
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
async load(_request, signal) {
|
|
19
|
+
signal?.throwIfAborted();
|
|
20
|
+
return [this.item];
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=user.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"user.js","sourceRoot":"","sources":["../../../src/context/sources/user.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAUzF,MAAM,OAAO,iBAAiB;IACnB,EAAE,CAAS;IACX,KAAK,GAAG,MAAe,CAAC;IAChB,IAAI,CAAc;IAEnC,YAAY,OAAe,EAAE,UAAoC,EAAE;QACjE,IAAI,CAAC,EAAE,GAAG,OAAO,CAAC,EAAE,IAAI,MAAM,CAAC;QAC/B,IAAI,CAAC,IAAI,GAAG,UAAU,CAAC;YACrB,EAAE,EAAE,gBAAgB,EAAE;YACtB,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,MAAM,EAAE,IAAI,CAAC,EAAE;YACf,QAAQ,EAAE,OAAO,CAAC,QAAQ,IAAI,GAAG;YACjC,UAAU,EAAE,OAAO,CAAC,UAAU,IAAI,OAAO;YACzC,OAAO,EAAE,CAAC,mBAAmB,CAAC,OAAO,CAAC,CAAC;YACvC,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;SACpC,CAAgB,CAAC;IACpB,CAAC;IAED,KAAK,CAAC,IAAI,CACR,QAA4B,EAC5B,MAAoB;QAEpB,MAAM,EAAE,cAAc,EAAE,CAAC;QACzB,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACrB,CAAC;CACF"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { AgentMessage } from "../../types/index.js";
|
|
2
|
+
import type { ProjectionStage, ProjectionStageContext } from "../types.js";
|
|
3
|
+
export declare class DeduplicateStage implements ProjectionStage {
|
|
4
|
+
readonly id = "deduplicate";
|
|
5
|
+
readonly order = 30;
|
|
6
|
+
apply(messages: readonly AgentMessage[], _context: ProjectionStageContext, signal?: AbortSignal): Promise<readonly AgentMessage[]>;
|
|
7
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export class DeduplicateStage {
|
|
2
|
+
id = "deduplicate";
|
|
3
|
+
order = 30;
|
|
4
|
+
async apply(messages, _context, signal) {
|
|
5
|
+
signal?.throwIfAborted();
|
|
6
|
+
const seen = new Set();
|
|
7
|
+
const result = [];
|
|
8
|
+
for (const message of messages) {
|
|
9
|
+
signal?.throwIfAborted();
|
|
10
|
+
if (seen.has(message.id)) {
|
|
11
|
+
continue;
|
|
12
|
+
}
|
|
13
|
+
seen.add(message.id);
|
|
14
|
+
result.push(message);
|
|
15
|
+
}
|
|
16
|
+
return result;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=deduplicate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deduplicate.js","sourceRoot":"","sources":["../../../src/context/stages/deduplicate.ts"],"names":[],"mappings":"AAMA,MAAM,OAAO,gBAAgB;IAClB,EAAE,GAAG,aAAa,CAAC;IACnB,KAAK,GAAG,EAAE,CAAC;IAEpB,KAAK,CAAC,KAAK,CACT,QAAiC,EACjC,QAAgC,EAChC,MAAoB;QAEpB,MAAM,EAAE,cAAc,EAAE,CAAC;QAEzB,MAAM,IAAI,GAAG,IAAI,GAAG,EAAU,CAAC;QAC/B,MAAM,MAAM,GAAmB,EAAE,CAAC;QAElC,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;YAC/B,MAAM,EAAE,cAAc,EAAE,CAAC;YACzB,IAAI,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC,EAAE,CAAC;gBACzB,SAAS;YACX,CAAC;YACD,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;YACrB,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACvB,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;CACF"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export class ExpirationFilterStage {
|
|
2
|
+
id = "expiration";
|
|
3
|
+
apply(items, now = new Date()) {
|
|
4
|
+
const timestamp = now.getTime();
|
|
5
|
+
return items.filter((item) => {
|
|
6
|
+
if (item.expiresAt === undefined) {
|
|
7
|
+
return true;
|
|
8
|
+
}
|
|
9
|
+
const expiresAt = Date.parse(item.expiresAt);
|
|
10
|
+
return Number.isNaN(expiresAt) || expiresAt > timestamp;
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=expiration.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"expiration.js","sourceRoot":"","sources":["../../../src/context/stages/expiration.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,qBAAqB;IACvB,EAAE,GAAG,YAAY,CAAC;IAE3B,KAAK,CACH,KAA6B,EAC7B,GAAG,GAAG,IAAI,IAAI,EAAE;QAEhB,MAAM,SAAS,GAAG,GAAG,CAAC,OAAO,EAAE,CAAC;QAEhC,OAAO,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE;YAC3B,IAAI,IAAI,CAAC,SAAS,KAAK,SAAS,EAAE,CAAC;gBACjC,OAAO,IAAI,CAAC;YACd,CAAC;YAED,MAAM,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;YAC7C,OAAO,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,IAAI,SAAS,GAAG,SAAS,CAAC;QAC1D,CAAC,CAAC,CAAC;IACL,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"visibility.js","sourceRoot":"","sources":["../../../src/context/stages/visibility.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,qBAAqB;IACvB,EAAE,GAAG,YAAY,CAAC;IAE3B,KAAK,CAAC,KAA6B;QACjC,OAAO,KAAK,CAAC,MAAM,CACjB,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,UAAU,KAAK,OAAO,IAAI,IAAI,CAAC,UAAU,KAAK,MAAM,CACpE,CAAC;IACJ,CAAC;CACF"}
|