@ny4n/durable 0.0.0-stage → 1.0.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/LICENSE +21 -0
- package/README.md +711 -2
- package/dist/documents.d.ts +66 -0
- package/dist/documents.d.ts.map +1 -0
- package/dist/documents.js +98 -0
- package/dist/documents.js.map +1 -0
- package/dist/entries.d.ts +31 -0
- package/dist/entries.d.ts.map +1 -0
- package/dist/entries.js +31 -0
- package/dist/entries.js.map +1 -0
- package/dist/env/decode.d.ts +16 -0
- package/dist/env/decode.d.ts.map +1 -0
- package/dist/env/decode.js +28 -0
- package/dist/env/decode.js.map +1 -0
- package/dist/env/index.d.ts +263 -0
- package/dist/env/index.d.ts.map +1 -0
- package/dist/env/index.js +49 -0
- package/dist/env/index.js.map +1 -0
- package/dist/env/line-scan.d.ts +13 -0
- package/dist/env/line-scan.d.ts.map +1 -0
- package/dist/env/line-scan.js +147 -0
- package/dist/env/line-scan.js.map +1 -0
- package/dist/env/node-watch.d.ts +29 -0
- package/dist/env/node-watch.d.ts.map +1 -0
- package/dist/env/node-watch.js +485 -0
- package/dist/env/node-watch.js.map +1 -0
- package/dist/env/node.d.ts +56 -0
- package/dist/env/node.d.ts.map +1 -0
- package/dist/env/node.js +1166 -0
- package/dist/env/node.js.map +1 -0
- package/dist/errors.d.ts +32 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +53 -0
- package/dist/errors.js.map +1 -0
- package/dist/harness/agent.d.ts +33 -0
- package/dist/harness/agent.d.ts.map +1 -0
- package/dist/harness/agent.js +235 -0
- package/dist/harness/agent.js.map +1 -0
- package/dist/harness/assistant.d.ts +15 -0
- package/dist/harness/assistant.d.ts.map +1 -0
- package/dist/harness/assistant.js +23 -0
- package/dist/harness/assistant.js.map +1 -0
- package/dist/harness/compaction.d.ts +56 -0
- package/dist/harness/compaction.d.ts.map +1 -0
- package/dist/harness/compaction.js +384 -0
- package/dist/harness/compaction.js.map +1 -0
- package/dist/harness/context.d.ts +63 -0
- package/dist/harness/context.d.ts.map +1 -0
- package/dist/harness/context.js +221 -0
- package/dist/harness/context.js.map +1 -0
- package/dist/harness/define.d.ts +18 -0
- package/dist/harness/define.d.ts.map +1 -0
- package/dist/harness/define.js +25 -0
- package/dist/harness/define.js.map +1 -0
- package/dist/harness/events.d.ts +180 -0
- package/dist/harness/events.d.ts.map +1 -0
- package/dist/harness/events.js +370 -0
- package/dist/harness/events.js.map +1 -0
- package/dist/harness/generation.d.ts +54 -0
- package/dist/harness/generation.d.ts.map +1 -0
- package/dist/harness/generation.js +514 -0
- package/dist/harness/generation.js.map +1 -0
- package/dist/harness/harness.d.ts +17 -0
- package/dist/harness/harness.d.ts.map +1 -0
- package/dist/harness/harness.js +332 -0
- package/dist/harness/harness.js.map +1 -0
- package/dist/harness/inbox.d.ts +59 -0
- package/dist/harness/inbox.d.ts.map +1 -0
- package/dist/harness/inbox.js +97 -0
- package/dist/harness/inbox.js.map +1 -0
- package/dist/harness/json.d.ts +10 -0
- package/dist/harness/json.d.ts.map +1 -0
- package/dist/harness/json.js +33 -0
- package/dist/harness/json.js.map +1 -0
- package/dist/harness/live.d.ts +142 -0
- package/dist/harness/live.d.ts.map +1 -0
- package/dist/harness/live.js +149 -0
- package/dist/harness/live.js.map +1 -0
- package/dist/harness/output.d.ts +69 -0
- package/dist/harness/output.d.ts.map +1 -0
- package/dist/harness/output.js +318 -0
- package/dist/harness/output.js.map +1 -0
- package/dist/harness/prompt.d.ts +27 -0
- package/dist/harness/prompt.d.ts.map +1 -0
- package/dist/harness/prompt.js +131 -0
- package/dist/harness/prompt.js.map +1 -0
- package/dist/harness/provider.d.ts +14 -0
- package/dist/harness/provider.d.ts.map +1 -0
- package/dist/harness/provider.js +30 -0
- package/dist/harness/provider.js.map +1 -0
- package/dist/harness/registry.d.ts +6 -0
- package/dist/harness/registry.d.ts.map +1 -0
- package/dist/harness/registry.js +101 -0
- package/dist/harness/registry.js.map +1 -0
- package/dist/harness/run.d.ts +17 -0
- package/dist/harness/run.d.ts.map +1 -0
- package/dist/harness/run.js +26 -0
- package/dist/harness/run.js.map +1 -0
- package/dist/harness/scheduler.d.ts +106 -0
- package/dist/harness/scheduler.d.ts.map +1 -0
- package/dist/harness/scheduler.js +1743 -0
- package/dist/harness/scheduler.js.map +1 -0
- package/dist/harness/submissions.d.ts +29 -0
- package/dist/harness/submissions.d.ts.map +1 -0
- package/dist/harness/submissions.js +175 -0
- package/dist/harness/submissions.js.map +1 -0
- package/dist/harness/task-graph.d.ts +49 -0
- package/dist/harness/task-graph.d.ts.map +1 -0
- package/dist/harness/task-graph.js +168 -0
- package/dist/harness/task-graph.js.map +1 -0
- package/dist/harness/tool.d.ts +76 -0
- package/dist/harness/tool.d.ts.map +1 -0
- package/dist/harness/tool.js +736 -0
- package/dist/harness/tool.js.map +1 -0
- package/dist/harness/types.d.ts +713 -0
- package/dist/harness/types.d.ts.map +1 -0
- package/dist/harness/types.js +2 -0
- package/dist/harness/types.js.map +1 -0
- package/dist/harness/usage.d.ts +18 -0
- package/dist/harness/usage.d.ts.map +1 -0
- package/dist/harness/usage.js +57 -0
- package/dist/harness/usage.js.map +1 -0
- package/dist/harness/util.d.ts +19 -0
- package/dist/harness/util.d.ts.map +1 -0
- package/dist/harness/util.js +58 -0
- package/dist/harness/util.js.map +1 -0
- package/dist/harness/view.d.ts +47 -0
- package/dist/harness/view.d.ts.map +1 -0
- package/dist/harness/view.js +206 -0
- package/dist/harness/view.js.map +1 -0
- package/dist/ids.d.ts +6 -0
- package/dist/ids.d.ts.map +1 -0
- package/dist/ids.js +9 -0
- package/dist/ids.js.map +1 -0
- package/dist/images/cloudflare.d.ts +4 -0
- package/dist/images/cloudflare.d.ts.map +1 -0
- package/dist/images/cloudflare.js +9 -0
- package/dist/images/cloudflare.js.map +1 -0
- package/dist/images/exif.d.ts +3 -0
- package/dist/images/exif.d.ts.map +1 -0
- package/dist/images/exif.js +71 -0
- package/dist/images/exif.js.map +1 -0
- package/dist/images/index.d.ts +18 -0
- package/dist/images/index.d.ts.map +1 -0
- package/dist/images/index.js +125 -0
- package/dist/images/index.js.map +1 -0
- package/dist/images/node-worker.d.ts +17 -0
- package/dist/images/node-worker.d.ts.map +1 -0
- package/dist/images/node-worker.js +16 -0
- package/dist/images/node-worker.js.map +1 -0
- package/dist/images/node.d.ts +21 -0
- package/dist/images/node.d.ts.map +1 -0
- package/dist/images/node.js +121 -0
- package/dist/images/node.js.map +1 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +20 -0
- package/dist/index.js.map +1 -0
- package/dist/session/forks.d.ts +10 -0
- package/dist/session/forks.d.ts.map +1 -0
- package/dist/session/forks.js +42 -0
- package/dist/session/forks.js.map +1 -0
- package/dist/session/observation.d.ts +42 -0
- package/dist/session/observation.d.ts.map +1 -0
- package/dist/session/observation.js +281 -0
- package/dist/session/observation.js.map +1 -0
- package/dist/session/session.d.ts +133 -0
- package/dist/session/session.d.ts.map +1 -0
- package/dist/session/session.js +811 -0
- package/dist/session/session.js.map +1 -0
- package/dist/session/transaction.d.ts +119 -0
- package/dist/session/transaction.d.ts.map +1 -0
- package/dist/session/transaction.js +795 -0
- package/dist/session/transaction.js.map +1 -0
- package/dist/storage/jsonl/index.d.ts +2 -0
- package/dist/storage/jsonl/index.d.ts.map +1 -0
- package/dist/storage/jsonl/index.js +2 -0
- package/dist/storage/jsonl/index.js.map +1 -0
- package/dist/storage/jsonl/node.d.ts +6 -0
- package/dist/storage/jsonl/node.d.ts.map +1 -0
- package/dist/storage/jsonl/node.js +8 -0
- package/dist/storage/jsonl/node.js.map +1 -0
- package/dist/storage/jsonl/storage.d.ts +143 -0
- package/dist/storage/jsonl/storage.d.ts.map +1 -0
- package/dist/storage/jsonl/storage.js +682 -0
- package/dist/storage/jsonl/storage.js.map +1 -0
- package/dist/storage/memory.d.ts +62 -0
- package/dist/storage/memory.d.ts.map +1 -0
- package/dist/storage/memory.js +733 -0
- package/dist/storage/memory.js.map +1 -0
- package/dist/storage/scan.d.ts +18 -0
- package/dist/storage/scan.d.ts.map +1 -0
- package/dist/storage/scan.js +29 -0
- package/dist/storage/scan.js.map +1 -0
- package/dist/storage/sqlite/cloudflare.d.ts +46 -0
- package/dist/storage/sqlite/cloudflare.d.ts.map +1 -0
- package/dist/storage/sqlite/cloudflare.js +106 -0
- package/dist/storage/sqlite/cloudflare.js.map +1 -0
- package/dist/storage/sqlite/database.d.ts +37 -0
- package/dist/storage/sqlite/database.d.ts.map +1 -0
- package/dist/storage/sqlite/database.js +2 -0
- package/dist/storage/sqlite/database.js.map +1 -0
- package/dist/storage/sqlite/index.d.ts +4 -0
- package/dist/storage/sqlite/index.d.ts.map +1 -0
- package/dist/storage/sqlite/index.js +3 -0
- package/dist/storage/sqlite/index.js.map +1 -0
- package/dist/storage/sqlite/migrations.d.ts +11 -0
- package/dist/storage/sqlite/migrations.d.ts.map +1 -0
- package/dist/storage/sqlite/migrations.js +111 -0
- package/dist/storage/sqlite/migrations.js.map +1 -0
- package/dist/storage/sqlite/node.d.ts +41 -0
- package/dist/storage/sqlite/node.d.ts.map +1 -0
- package/dist/storage/sqlite/node.js +179 -0
- package/dist/storage/sqlite/node.js.map +1 -0
- package/dist/storage/sqlite/storage.d.ts +65 -0
- package/dist/storage/sqlite/storage.d.ts.map +1 -0
- package/dist/storage/sqlite/storage.js +670 -0
- package/dist/storage/sqlite/storage.js.map +1 -0
- package/dist/tasks.d.ts +6 -0
- package/dist/tasks.d.ts.map +1 -0
- package/dist/tasks.js +5 -0
- package/dist/tasks.js.map +1 -0
- package/dist/testing/assertions.d.ts +5 -0
- package/dist/testing/assertions.d.ts.map +1 -0
- package/dist/testing/assertions.js +25 -0
- package/dist/testing/assertions.js.map +1 -0
- package/dist/testing/env-conformance.d.ts +7 -0
- package/dist/testing/env-conformance.d.ts.map +1 -0
- package/dist/testing/env-conformance.js +431 -0
- package/dist/testing/env-conformance.js.map +1 -0
- package/dist/testing/index.d.ts +7 -0
- package/dist/testing/index.d.ts.map +1 -0
- package/dist/testing/index.js +6 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/testing/runner.d.ts +12 -0
- package/dist/testing/runner.d.ts.map +1 -0
- package/dist/testing/runner.js +23 -0
- package/dist/testing/runner.js.map +1 -0
- package/dist/testing/storage-benchmark.d.ts +41 -0
- package/dist/testing/storage-benchmark.d.ts.map +1 -0
- package/dist/testing/storage-benchmark.js +350 -0
- package/dist/testing/storage-benchmark.js.map +1 -0
- package/dist/testing/storage-conformance.d.ts +4 -0
- package/dist/testing/storage-conformance.d.ts.map +1 -0
- package/dist/testing/storage-conformance.js +1213 -0
- package/dist/testing/storage-conformance.js.map +1 -0
- package/dist/testing/types.d.ts +37 -0
- package/dist/testing/types.d.ts.map +1 -0
- package/dist/testing/types.js +2 -0
- package/dist/testing/types.js.map +1 -0
- package/dist/tools/bash.d.ts +55 -0
- package/dist/tools/bash.d.ts.map +1 -0
- package/dist/tools/bash.js +138 -0
- package/dist/tools/bash.js.map +1 -0
- package/dist/tools/edit-diff.d.ts +89 -0
- package/dist/tools/edit-diff.d.ts.map +1 -0
- package/dist/tools/edit-diff.js +386 -0
- package/dist/tools/edit-diff.js.map +1 -0
- package/dist/tools/edit.d.ts +18 -0
- package/dist/tools/edit.d.ts.map +1 -0
- package/dist/tools/edit.js +117 -0
- package/dist/tools/edit.js.map +1 -0
- package/dist/tools/env.d.ts +5 -0
- package/dist/tools/env.d.ts.map +1 -0
- package/dist/tools/env.js +7 -0
- package/dist/tools/env.js.map +1 -0
- package/dist/tools/file-mutation-queue.d.ts +9 -0
- package/dist/tools/file-mutation-queue.d.ts.map +1 -0
- package/dist/tools/file-mutation-queue.js +52 -0
- package/dist/tools/file-mutation-queue.js.map +1 -0
- package/dist/tools/image-processor.d.ts +47 -0
- package/dist/tools/image-processor.d.ts.map +1 -0
- package/dist/tools/image-processor.js +30 -0
- package/dist/tools/image-processor.js.map +1 -0
- package/dist/tools/image.d.ts +20 -0
- package/dist/tools/image.d.ts.map +1 -0
- package/dist/tools/image.js +178 -0
- package/dist/tools/image.js.map +1 -0
- package/dist/tools/index.d.ts +46 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +23 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/path-utils.d.ts +5 -0
- package/dist/tools/path-utils.d.ts.map +1 -0
- package/dist/tools/path-utils.js +26 -0
- package/dist/tools/path-utils.js.map +1 -0
- package/dist/tools/read.d.ts +25 -0
- package/dist/tools/read.d.ts.map +1 -0
- package/dist/tools/read.js +235 -0
- package/dist/tools/read.js.map +1 -0
- package/dist/tools/write.d.ts +10 -0
- package/dist/tools/write.d.ts.map +1 -0
- package/dist/tools/write.js +31 -0
- package/dist/tools/write.js.map +1 -0
- package/dist/truncate.d.ts +64 -0
- package/dist/truncate.d.ts.map +1 -0
- package/dist/truncate.js +154 -0
- package/dist/truncate.js.map +1 -0
- package/dist/types.d.ts +932 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/package.json +140 -5
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { INSTRUCTIONS_KEY } from "./agent.js";
|
|
2
|
+
import { CompactionTask } from "./compaction.js";
|
|
3
|
+
import { GenerationTask } from "./generation.js";
|
|
4
|
+
import { ToolTask } from "./tool.js";
|
|
5
|
+
const SECTION_KEY = /^[a-z][a-z0-9_-]*$/;
|
|
6
|
+
/** Built-in task definitions every registry holds; they are not an extension and cannot be removed or replaced. */
|
|
7
|
+
export const BUILTIN_TASKS = [GenerationTask, ToolTask, CompactionTask];
|
|
8
|
+
/** Immutable published registry state. */
|
|
9
|
+
class RegistryState {
|
|
10
|
+
#extensions;
|
|
11
|
+
#byName;
|
|
12
|
+
#tasks;
|
|
13
|
+
constructor(extensions) {
|
|
14
|
+
this.#extensions = extensions;
|
|
15
|
+
this.#byName = new Map(extensions.map((extension) => [extension.name, extension]));
|
|
16
|
+
const tasks = new Map();
|
|
17
|
+
for (const task of BUILTIN_TASKS)
|
|
18
|
+
tasks.set(task.definition.name, task);
|
|
19
|
+
for (const extension of extensions) {
|
|
20
|
+
for (const task of extension.tasks ?? []) {
|
|
21
|
+
const name = task.definition.name;
|
|
22
|
+
if (tasks.has(name))
|
|
23
|
+
throw new Error(`Task ${name} of extension ${extension.name} is already installed`);
|
|
24
|
+
tasks.set(name, task);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
this.#tasks = tasks;
|
|
28
|
+
}
|
|
29
|
+
installed() {
|
|
30
|
+
return this.#extensions;
|
|
31
|
+
}
|
|
32
|
+
extension(name) {
|
|
33
|
+
return this.#byName.get(name);
|
|
34
|
+
}
|
|
35
|
+
tools() {
|
|
36
|
+
return this.#extensions.flatMap((extension) => (extension.tools ?? []).map((tool) => ({ extension, tool })));
|
|
37
|
+
}
|
|
38
|
+
sections() {
|
|
39
|
+
return this.#extensions.flatMap((extension) => (extension.sections ?? []).map((section) => ({ extension, section })));
|
|
40
|
+
}
|
|
41
|
+
tasks() {
|
|
42
|
+
return [...this.#tasks.values()];
|
|
43
|
+
}
|
|
44
|
+
task(name) {
|
|
45
|
+
return this.#tasks.get(name);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
class RegistryImpl {
|
|
49
|
+
#current = new RegistryState([]);
|
|
50
|
+
#listeners = new Set();
|
|
51
|
+
snapshot() {
|
|
52
|
+
return this.#current;
|
|
53
|
+
}
|
|
54
|
+
subscribe(listener) {
|
|
55
|
+
this.#listeners.add(listener);
|
|
56
|
+
return () => this.#listeners.delete(listener);
|
|
57
|
+
}
|
|
58
|
+
install(extension) {
|
|
59
|
+
validateExtension(extension);
|
|
60
|
+
const current = this.#current.installed();
|
|
61
|
+
const index = current.findIndex((installed) => installed.name === extension.name);
|
|
62
|
+
const next = index < 0 ? [...current, extension] : current.map((installed, at) => (at === index ? extension : installed));
|
|
63
|
+
this.#publish(next);
|
|
64
|
+
}
|
|
65
|
+
uninstall(extension) {
|
|
66
|
+
const current = this.#current.installed();
|
|
67
|
+
if (!current.some((installed) => installed.name === extension.name))
|
|
68
|
+
return;
|
|
69
|
+
this.#publish(current.filter((installed) => installed.name !== extension.name));
|
|
70
|
+
}
|
|
71
|
+
/** Build and validate the next state, which throws on a task name collision, then publish it synchronously. */
|
|
72
|
+
#publish(extensions) {
|
|
73
|
+
this.#current = new RegistryState(extensions);
|
|
74
|
+
for (const listener of [...this.#listeners])
|
|
75
|
+
listener();
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
/** Unique tool names and section keys within one extension; valid, unreserved section keys. */
|
|
79
|
+
function validateExtension(extension) {
|
|
80
|
+
const tools = new Set();
|
|
81
|
+
for (const tool of extension.tools ?? []) {
|
|
82
|
+
if (tools.has(tool.name))
|
|
83
|
+
throw new Error(`Extension ${extension.name} has two tools named ${tool.name}`);
|
|
84
|
+
tools.add(tool.name);
|
|
85
|
+
}
|
|
86
|
+
const sections = new Set();
|
|
87
|
+
for (const { key } of extension.sections ?? []) {
|
|
88
|
+
if (!SECTION_KEY.test(key))
|
|
89
|
+
throw new TypeError(`Section key ${JSON.stringify(key)} must match ${SECTION_KEY}`);
|
|
90
|
+
if (key === INSTRUCTIONS_KEY)
|
|
91
|
+
throw new Error(`Section key ${key} is reserved for the agent's instructions`);
|
|
92
|
+
if (sections.has(key))
|
|
93
|
+
throw new Error(`Extension ${extension.name} has two sections with key ${key}`);
|
|
94
|
+
sections.add(key);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
/** Create an application-owned registry holding only the built-in tasks. */
|
|
98
|
+
export function createRegistry() {
|
|
99
|
+
return new RegistryImpl();
|
|
100
|
+
}
|
|
101
|
+
//# sourceMappingURL=registry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../../src/harness/registry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,E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,CAAC,SAAoB;IAC9C,MAAM,KAAK,GAAG,IAAI,GAAG,EAAU,CAAC;IAChC,KAAK,MAAM,IAAI,IAAI,SAAS,CAAC,KAAK,IAAI,EAAE,EAAE,CAAC;QAC1C,IAAI,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC;YAAE,MAAM,IAAI,KAAK,CAAC,aAAa,SAAS,CAAC,IAAI,wBAAwB,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;QAC1G,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACtB,CAAC;IACD,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAU,CAAC;IACnC,KAAK,MAAM,EAAE,GAAG,EAAE,IAAI,SAAS,CAAC,QAAQ,IAAI,EAAE,EAAE,CAAC;QAChD,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,GAAG,CAAC;YAAE,MAAM,IAAI,SAAS,CAAC,eAAe,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,eAAe,WAAW,EAAE,CAAC,CAAC;QAChH,IAAI,GAAG,KAAK,gBAAgB;YAAE,MAAM,IAAI,KAAK,CAAC,eAAe,GAAG,2CAA2C,CAAC,CAAC;QAC7G,IAAI,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC;YAAE,MAAM,IAAI,KAAK,CAAC,aAAa,SAAS,CAAC,IAAI,8BAA8B,GAAG,EAAE,CAAC,CAAC;QACvG,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IACnB,CAAC;AACF,CAAC;AAED,4EAA4E;AAC5E,MAAM,UAAU,cAAc;IAC7B,OAAO,IAAI,YAAY,EAAQ,CAAC;AACjC,CAAC","sourcesContent":["import { INSTRUCTIONS_KEY } from \"./agent.ts\";\nimport { CompactionTask } from \"./compaction.ts\";\nimport { GenerationTask } from \"./generation.ts\";\nimport { ToolTask } from \"./tool.ts\";\nimport type { AnyTask, Extension, PromptSection, Registry, RegistrySnapshot, ToolRegistration } from \"./types.ts\";\n\nconst SECTION_KEY = /^[a-z][a-z0-9_-]*$/;\n\n/** Built-in task definitions every registry holds; they are not an extension and cannot be removed or replaced. */\nexport const BUILTIN_TASKS: readonly AnyTask[] = [GenerationTask, ToolTask, CompactionTask];\n\n/** Immutable published registry state. */\nclass RegistryState<Tool extends ToolRegistration> implements RegistrySnapshot<Tool> {\n\treadonly #extensions: readonly Extension<Tool>[];\n\treadonly #byName: ReadonlyMap<string, Extension<Tool>>;\n\treadonly #tasks: ReadonlyMap<string, AnyTask>;\n\n\tconstructor(extensions: readonly Extension<Tool>[]) {\n\t\tthis.#extensions = extensions;\n\t\tthis.#byName = new Map(extensions.map((extension) => [extension.name, extension]));\n\t\tconst tasks = new Map<string, AnyTask>();\n\t\tfor (const task of BUILTIN_TASKS) tasks.set(task.definition.name, task);\n\t\tfor (const extension of extensions) {\n\t\t\tfor (const task of extension.tasks ?? []) {\n\t\t\t\tconst name = task.definition.name;\n\t\t\t\tif (tasks.has(name)) throw new Error(`Task ${name} of extension ${extension.name} is already installed`);\n\t\t\t\ttasks.set(name, task);\n\t\t\t}\n\t\t}\n\t\tthis.#tasks = tasks;\n\t}\n\n\tinstalled(): readonly Extension<Tool>[] {\n\t\treturn this.#extensions;\n\t}\n\n\textension(name: string): Extension<Tool> | undefined {\n\t\treturn this.#byName.get(name);\n\t}\n\n\ttools(): readonly { readonly extension: Extension<Tool>; readonly tool: Tool }[] {\n\t\treturn this.#extensions.flatMap((extension) => (extension.tools ?? []).map((tool) => ({ extension, tool })));\n\t}\n\n\tsections(): readonly { readonly extension: Extension<Tool>; readonly section: PromptSection<Tool> }[] {\n\t\treturn this.#extensions.flatMap((extension) =>\n\t\t\t(extension.sections ?? []).map((section) => ({ extension, section })),\n\t\t);\n\t}\n\n\ttasks(): readonly AnyTask[] {\n\t\treturn [...this.#tasks.values()];\n\t}\n\n\ttask(name: string): AnyTask | undefined {\n\t\treturn this.#tasks.get(name);\n\t}\n}\n\nclass RegistryImpl<Tool extends ToolRegistration> implements Registry<Tool> {\n\t#current = new RegistryState<Tool>([]);\n\treadonly #listeners = new Set<() => void>();\n\n\tsnapshot(): RegistrySnapshot<Tool> {\n\t\treturn this.#current;\n\t}\n\n\tsubscribe(listener: () => void): () => void {\n\t\tthis.#listeners.add(listener);\n\t\treturn () => this.#listeners.delete(listener);\n\t}\n\n\tinstall(extension: Extension<Tool>): void {\n\t\tvalidateExtension(extension);\n\t\tconst current = this.#current.installed();\n\t\tconst index = current.findIndex((installed) => installed.name === extension.name);\n\t\tconst next =\n\t\t\tindex < 0 ? [...current, extension] : current.map((installed, at) => (at === index ? extension : installed));\n\t\tthis.#publish(next);\n\t}\n\n\tuninstall(extension: Extension): void {\n\t\tconst current = this.#current.installed();\n\t\tif (!current.some((installed) => installed.name === extension.name)) return;\n\t\tthis.#publish(current.filter((installed) => installed.name !== extension.name));\n\t}\n\n\t/** Build and validate the next state, which throws on a task name collision, then publish it synchronously. */\n\t#publish(extensions: readonly Extension<Tool>[]): void {\n\t\tthis.#current = new RegistryState(extensions);\n\t\tfor (const listener of [...this.#listeners]) listener();\n\t}\n}\n\n/** Unique tool names and section keys within one extension; valid, unreserved section keys. */\nfunction validateExtension(extension: Extension): void {\n\tconst tools = new Set<string>();\n\tfor (const tool of extension.tools ?? []) {\n\t\tif (tools.has(tool.name)) throw new Error(`Extension ${extension.name} has two tools named ${tool.name}`);\n\t\ttools.add(tool.name);\n\t}\n\tconst sections = new Set<string>();\n\tfor (const { key } of extension.sections ?? []) {\n\t\tif (!SECTION_KEY.test(key)) throw new TypeError(`Section key ${JSON.stringify(key)} must match ${SECTION_KEY}`);\n\t\tif (key === INSTRUCTIONS_KEY) throw new Error(`Section key ${key} is reserved for the agent's instructions`);\n\t\tif (sections.has(key)) throw new Error(`Extension ${extension.name} has two sections with key ${key}`);\n\t\tsections.add(key);\n\t}\n}\n\n/** Create an application-owned registry holding only the built-in tasks. */\nexport function createRegistry<Tool extends ToolRegistration = ToolRegistration>(): Registry<Tool> {\n\treturn new RegistryImpl<Tool>();\n}\n"]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Draft } from "@ny4n/chord";
|
|
2
|
+
import type { ConversationId, SubmissionId, TaskId, TaskReference, Tx } from "../types.ts";
|
|
3
|
+
import type { GenerationCheckpoint, GenerationInput, GenerationResult } from "./generation.ts";
|
|
4
|
+
import type { LiveState } from "./live.ts";
|
|
5
|
+
/**
|
|
6
|
+
* Identity and first checkpoint of the built-in generation task. Run control lives here, below the generation, so
|
|
7
|
+
* admission and live-state code can start a run without importing the generation that owns the run's behavior; the
|
|
8
|
+
* generation takes its `name`, `version` and `initial` from this reference.
|
|
9
|
+
*/
|
|
10
|
+
export declare const generationTaskReference: TaskReference<GenerationInput, GenerationCheckpoint, GenerationResult>;
|
|
11
|
+
/** Start a run for `inputs`, placed input submissions: a new generation takes `nyan.live.run`. */
|
|
12
|
+
export declare function startRun(tx: Tx, conversationId: ConversationId, live: Draft<LiveState>, inputs: SubmissionId[]): Promise<void>;
|
|
13
|
+
/** A generation owned by its conversation. */
|
|
14
|
+
export declare function createGeneration(tx: Tx, conversationId: ConversationId): Promise<TaskId<GenerationResult>>;
|
|
15
|
+
/** Hand run control from `from` to `to`; the run's inputs move with it. */
|
|
16
|
+
export declare function handOver(live: Draft<LiveState>, from: TaskId, to: TaskId): void;
|
|
17
|
+
//# sourceMappingURL=run.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run.d.ts","sourceRoot":"","sources":["../../src/harness/run.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,KAAK,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,EAAE,aAAa,EAAE,EAAE,EAAE,MAAM,aAAa,CAAC;AAC3F,OAAO,KAAK,EAAE,oBAAoB,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAC/F,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAE3C;;;;GAIG;AACH,eAAO,MAAM,uBAAuB,EAAE,aAAa,CAAC,eAAe,EAAE,oBAAoB,EAAE,gBAAgB,CAM1G,CAAC;AAEF,kGAAkG;AAClG,wBAAsB,QAAQ,CAC7B,EAAE,EAAE,EAAE,EACN,cAAc,EAAE,cAAc,EAC9B,IAAI,EAAE,KAAK,CAAC,SAAS,CAAC,EACtB,MAAM,EAAE,YAAY,EAAE,GACpB,OAAO,CAAC,IAAI,CAAC,CAEf;AAED,8CAA8C;AAC9C,wBAAgB,gBAAgB,CAAC,EAAE,EAAE,EAAE,EAAE,cAAc,EAAE,cAAc,GAAG,OAAO,CAAC,MAAM,CAAC,gBAAgB,CAAC,CAAC,CAE1G;AAED,2EAA2E;AAC3E,wBAAgB,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,IAAI,CAE/E"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Identity and first checkpoint of the built-in generation task. Run control lives here, below the generation, so
|
|
3
|
+
* admission and live-state code can start a run without importing the generation that owns the run's behavior; the
|
|
4
|
+
* generation takes its `name`, `version` and `initial` from this reference.
|
|
5
|
+
*/
|
|
6
|
+
export const generationTaskReference = {
|
|
7
|
+
definition: {
|
|
8
|
+
name: "nyan.generation",
|
|
9
|
+
version: 1,
|
|
10
|
+
initial: () => ({ phase: "prepare", attempt: 1 }),
|
|
11
|
+
},
|
|
12
|
+
};
|
|
13
|
+
/** Start a run for `inputs`, placed input submissions: a new generation takes `nyan.live.run`. */
|
|
14
|
+
export async function startRun(tx, conversationId, live, inputs) {
|
|
15
|
+
live.run = { taskId: await createGeneration(tx, conversationId), inputs };
|
|
16
|
+
}
|
|
17
|
+
/** A generation owned by its conversation. */
|
|
18
|
+
export function createGeneration(tx, conversationId) {
|
|
19
|
+
return tx.createTask(generationTaskReference, {}, { ownership: { kind: "conversation" }, conversationId });
|
|
20
|
+
}
|
|
21
|
+
/** Hand run control from `from` to `to`; the run's inputs move with it. */
|
|
22
|
+
export function handOver(live, from, to) {
|
|
23
|
+
if (live.run?.taskId === from)
|
|
24
|
+
live.run.taskId = to;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=run.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run.js","sourceRoot":"","sources":["../../src/harness/run.ts"],"names":[],"mappings":"AAKA;;;;GAIG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAA2E;IAC9G,UAAU,EAAE;QACX,IAAI,EAAE,iBAAiB;QACvB,OAAO,EAAE,CAAC;QACV,OAAO,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC;KACjD;CACD,CAAC;AAEF,kGAAkG;AAClG,MAAM,CAAC,KAAK,UAAU,QAAQ,CAC7B,EAAM,EACN,cAA8B,EAC9B,IAAsB,EACtB,MAAsB;IAEtB,IAAI,CAAC,GAAG,GAAG,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC,EAAE,EAAE,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;AAC3E,CAAC;AAED,8CAA8C;AAC9C,MAAM,UAAU,gBAAgB,CAAC,EAAM,EAAE,cAA8B;IACtE,OAAO,EAAE,CAAC,UAAU,CAAC,uBAAuB,EAAE,EAAE,EAAE,EAAE,SAAS,EAAE,EAAE,IAAI,EAAE,cAAc,EAAE,EAAE,cAAc,EAAE,CAAC,CAAC;AAC5G,CAAC;AAED,2EAA2E;AAC3E,MAAM,UAAU,QAAQ,CAAC,IAAsB,EAAE,IAAY,EAAE,EAAU;IACxE,IAAI,IAAI,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI;QAAE,IAAI,CAAC,GAAG,CAAC,MAAM,GAAG,EAAE,CAAC;AACrD,CAAC","sourcesContent":["import type { Draft } from \"@ny4n/chord\";\nimport type { ConversationId, SubmissionId, TaskId, TaskReference, Tx } from \"../types.ts\";\nimport type { GenerationCheckpoint, GenerationInput, GenerationResult } from \"./generation.ts\";\nimport type { LiveState } from \"./live.ts\";\n\n/**\n * Identity and first checkpoint of the built-in generation task. Run control lives here, below the generation, so\n * admission and live-state code can start a run without importing the generation that owns the run's behavior; the\n * generation takes its `name`, `version` and `initial` from this reference.\n */\nexport const generationTaskReference: TaskReference<GenerationInput, GenerationCheckpoint, GenerationResult> = {\n\tdefinition: {\n\t\tname: \"nyan.generation\",\n\t\tversion: 1,\n\t\tinitial: () => ({ phase: \"prepare\", attempt: 1 }),\n\t},\n};\n\n/** Start a run for `inputs`, placed input submissions: a new generation takes `nyan.live.run`. */\nexport async function startRun(\n\ttx: Tx,\n\tconversationId: ConversationId,\n\tlive: Draft<LiveState>,\n\tinputs: SubmissionId[],\n): Promise<void> {\n\tlive.run = { taskId: await createGeneration(tx, conversationId), inputs };\n}\n\n/** A generation owned by its conversation. */\nexport function createGeneration(tx: Tx, conversationId: ConversationId): Promise<TaskId<GenerationResult>> {\n\treturn tx.createTask(generationTaskReference, {}, { ownership: { kind: \"conversation\" }, conversationId });\n}\n\n/** Hand run control from `from` to `to`; the run's inputs move with it. */\nexport function handOver(live: Draft<LiveState>, from: TaskId, to: TaskId): void {\n\tif (live.run?.taskId === from) live.run.taskId = to;\n}\n"]}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import type { ModelRuntime } from "@ny4n/ai/contracts";
|
|
2
|
+
import { type Context, type JsonValue } from "@ny4n/chord";
|
|
3
|
+
import type { ExecutionEnv } from "../env/index.ts";
|
|
4
|
+
import type { SessionImpl } from "../session/session.ts";
|
|
5
|
+
import type { Transaction } from "../session/transaction.ts";
|
|
6
|
+
import type { ConversationId, Storage, TaskId, TaskOutcome, TaskRecord } from "../types.ts";
|
|
7
|
+
import type { Agent, ConversationHandle, HarnessInspection, RegistryReader, RegistrySnapshot, Settings, SettledTask, TaskInspection } from "./types.ts";
|
|
8
|
+
type AnyTaskRecord = TaskRecord<JsonValue, JsonValue, JsonValue>;
|
|
9
|
+
/** Terminal outcomes the scheduler writes without running task code. */
|
|
10
|
+
export type SchedulerOutcome = Extract<TaskOutcome<JsonValue>, {
|
|
11
|
+
readonly status: "faulted" | "orphaned";
|
|
12
|
+
}>;
|
|
13
|
+
/** An invocation a conversation handle is bound to: its signal, and a check that throws once it ended. */
|
|
14
|
+
export type InvocationBinding = {
|
|
15
|
+
readonly signal: AbortSignal;
|
|
16
|
+
check(): void;
|
|
17
|
+
};
|
|
18
|
+
export type TaskSchedulerOptions = {
|
|
19
|
+
readonly session: SessionImpl;
|
|
20
|
+
readonly storage: Storage;
|
|
21
|
+
readonly registry: RegistryReader;
|
|
22
|
+
readonly models: ModelRuntime;
|
|
23
|
+
/** Resolve a conversation's agent against a snapshot; the runtime calls it at most once per phase. */
|
|
24
|
+
readonly agent: (conversationId: ConversationId, snapshot: RegistrySnapshot, context: Context) => Promise<Agent>;
|
|
25
|
+
/** Resolve the settings; read at each access. */
|
|
26
|
+
readonly settings: () => Settings;
|
|
27
|
+
/** Build a conversation's environment with `HarnessOptions.env`. */
|
|
28
|
+
readonly env: (conversationId: ConversationId, context: Context) => Promise<ExecutionEnv | undefined>;
|
|
29
|
+
readonly now: () => number;
|
|
30
|
+
readonly report: (error: unknown) => void;
|
|
31
|
+
/** Harness cleanup staged in the commit that makes an outcome the scheduler wrote itself terminal. */
|
|
32
|
+
readonly settleOutcome: (tx: Transaction, record: AnyTaskRecord, outcome: SchedulerOutcome) => Promise<void>;
|
|
33
|
+
/** Withdraw a conversation's queued inputs, for conversation abort and abort cascades. */
|
|
34
|
+
readonly withdrawInputs: (tx: Transaction, conversationId: ConversationId) => Promise<void>;
|
|
35
|
+
/** Invocation-bound handle of an existing conversation, for task runtimes and tools. */
|
|
36
|
+
readonly conversation: (id: ConversationId, binding: InvocationBinding, context: Context) => Promise<ConversationHandle | undefined>;
|
|
37
|
+
/** Context for scheduler commits and invocations; carries no caller cancellation. */
|
|
38
|
+
readonly context: Context;
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* Durable task scheduler of one Harness.
|
|
42
|
+
*
|
|
43
|
+
* `#live` mirrors every committed non-terminal task record: pending, running, waiting, and completing. The synchronous
|
|
44
|
+
* commit listener updates it on the Session line, so code running on the line reads exactly the committed state from it.
|
|
45
|
+
*
|
|
46
|
+
* Tasks and conversations form one ownership tree (spec §5.5): a task's parent is its owner task, or its conversation;
|
|
47
|
+
* a conversation's parent is its owner task, if any. Walks up that tree decide what reaches one task: a cancelling
|
|
48
|
+
* owner, a scope. `#below` lists the tree downward around live work, so what lies below one node is a walk down from
|
|
49
|
+
* it: a task's live ordinary owned work, which holds its outcome as `completing` and delays its abort handler, a
|
|
50
|
+
* scope's tasks, a cascade's reach. No pass visits every live task; the sets below hold each pass's candidates.
|
|
51
|
+
*
|
|
52
|
+
* The ownership indexes are bounded by live work: an owner edge and an ended task's ownership fields are kept only while
|
|
53
|
+
* something is listed below them in `#below`, so only the chains above live tasks are known, whole. Work that appears
|
|
54
|
+
* later below a dropped node finds it unknown and loads its chain from storage again.
|
|
55
|
+
*
|
|
56
|
+
* Invariant: every task transition is decided and written by one callback serialized on the Session line. That covers
|
|
57
|
+
* reservation, marks, runtime commits, finalization, and the synchronous step before each phase, which applies the
|
|
58
|
+
* precedence rules and writes a fault or handover. Handlers and joins run off the line. An invocation ends inside the
|
|
59
|
+
* step that decides its end, so a runtime commit it queued either lands before that decision or is rejected.
|
|
60
|
+
*/
|
|
61
|
+
export declare class TaskScheduler {
|
|
62
|
+
#private;
|
|
63
|
+
constructor(options: TaskSchedulerOptions);
|
|
64
|
+
/** Load live tasks and change surviving `running` tasks back to `pending`. Dispatches nothing. */
|
|
65
|
+
open(context: Context): Promise<void>;
|
|
66
|
+
/** Enable scheduling. Idempotent; the kick does nothing once closing. */
|
|
67
|
+
resume(): void;
|
|
68
|
+
/**
|
|
69
|
+
* Signal every invocation and wait for them; writes nothing. Close calls this after every close listener has run, so
|
|
70
|
+
* waits, watches, and streams a task holds end with the Session's reason, not as cancelled by its signal.
|
|
71
|
+
*/
|
|
72
|
+
join(): Promise<void>;
|
|
73
|
+
/**
|
|
74
|
+
* Commit the abort mark, or settle a task that no registered definition can take as `orphaned` when nothing it owns
|
|
75
|
+
* is live, then join the run invocation seen on the line; the commit listener signalled it. The abort invocation
|
|
76
|
+
* starts once the task's ordinary owned work is gone. A `completing` task is only marked. A request replaces a
|
|
77
|
+
* `restart` mark, so a task abandoned after a restart that waits for its definition is orphaned; with `keepRestart`,
|
|
78
|
+
* as for an owner's own cleanup, such a task keeps its mark and waits on.
|
|
79
|
+
*/
|
|
80
|
+
abort(id: TaskId, context: Context, keepRestart?: boolean): Promise<"marked" | "terminal">;
|
|
81
|
+
waitForTask(id: TaskId, context: Context): Promise<SettledTask<JsonValue>>;
|
|
82
|
+
/**
|
|
83
|
+
* Resolve when ordinary traversal from the conversation, or from every ownerless conversation, reaches no live
|
|
84
|
+
* non-background task.
|
|
85
|
+
*/
|
|
86
|
+
waitForIdle(conversationId: ConversationId | undefined, context: Context): Promise<void>;
|
|
87
|
+
/**
|
|
88
|
+
* `Conversation.abort()`: in one commit, withdraw the queued inputs and mark every live non-background task that
|
|
89
|
+
* ordinary traversal from the conversation reaches; resolves once the scope is idle. With `background`, traversal
|
|
90
|
+
* crosses background boundaries, and the wait also covers every task it reached.
|
|
91
|
+
*/
|
|
92
|
+
abortConversation(conversationId: ConversationId, background: boolean, context: Context): Promise<void>;
|
|
93
|
+
/** Sizes of the ownership indexes, for tests that bound the scheduler's memory. */
|
|
94
|
+
get indexSizes(): Readonly<Record<"live" | "settled" | "edges" | "below" | "roots" | "unloaded" | "dropQueue", number>>;
|
|
95
|
+
/**
|
|
96
|
+
* Scheduling state and every live task with its derived state, read on the Session line. Runs no task code: a
|
|
97
|
+
* pending migration shows as `ready` with `migrates`, and only a migration the scheduler already tried, or one that
|
|
98
|
+
* cannot exist, shows as failed.
|
|
99
|
+
*/
|
|
100
|
+
inspect(snapshot: RegistrySnapshot): Promise<{
|
|
101
|
+
scheduling: HarnessInspection["scheduling"];
|
|
102
|
+
tasks: TaskInspection[];
|
|
103
|
+
}>;
|
|
104
|
+
}
|
|
105
|
+
export {};
|
|
106
|
+
//# sourceMappingURL=scheduler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scheduler.d.ts","sourceRoot":"","sources":["../../src/harness/scheduler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,EAAE,KAAK,OAAO,EAAY,KAAK,SAAS,EAAE,MAAM,aAAa,CAAC;AAErE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAEpD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAC7D,OAAO,KAAK,EAEX,cAAc,EAQd,OAAO,EAEP,MAAM,EACN,WAAW,EACX,UAAU,EAGV,MAAM,aAAa,CAAC;AAGrB,OAAO,KAAK,EACX,KAAK,EAEL,kBAAkB,EAClB,iBAAiB,EACjB,cAAc,EACd,gBAAgB,EAChB,QAAQ,EACR,WAAW,EACX,cAAc,EACd,MAAM,YAAY,CAAC;AAGpB,KAAK,aAAa,GAAG,UAAU,CAAC,SAAS,EAAE,SAAS,EAAE,SAAS,CAAC,CAAC;AAiEjE,wEAAwE;AACxE,MAAM,MAAM,gBAAgB,GAAG,OAAO,CAAC,WAAW,CAAC,SAAS,CAAC,EAAE;IAAE,QAAQ,CAAC,MAAM,EAAE,SAAS,GAAG,UAAU,CAAA;CAAE,CAAC,CAAC;AAE5G,0GAA0G;AAC1G,MAAM,MAAM,iBAAiB,GAAG;IAAE,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC;IAAC,KAAK,IA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