@animalabs/agent-framework 0.21.0 → 0.22.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 +43 -0
- package/dist/src/agent.d.ts +17 -4
- package/dist/src/agent.d.ts.map +1 -1
- package/dist/src/agent.js +102 -42
- package/dist/src/agent.js.map +1 -1
- package/dist/src/code-execution/py-runner.d.ts +22 -1
- package/dist/src/code-execution/py-runner.d.ts.map +1 -1
- package/dist/src/code-execution/py-runner.js +64 -9
- package/dist/src/code-execution/py-runner.js.map +1 -1
- package/dist/src/code-execution/runtime-py.d.ts +4 -0
- package/dist/src/code-execution/runtime-py.d.ts.map +1 -1
- package/dist/src/code-execution/runtime-py.js +215 -38
- package/dist/src/code-execution/runtime-py.js.map +1 -1
- package/dist/src/framework.d.ts +250 -39
- package/dist/src/framework.d.ts.map +1 -1
- package/dist/src/framework.js +1602 -371
- package/dist/src/framework.js.map +1 -1
- package/dist/src/gate/event-gate.d.ts +21 -0
- package/dist/src/gate/event-gate.d.ts.map +1 -1
- package/dist/src/gate/event-gate.js +40 -7
- package/dist/src/gate/event-gate.js.map +1 -1
- package/dist/src/index.d.ts +5 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +4 -0
- package/dist/src/index.js.map +1 -1
- package/dist/src/mcpl/channel-registry.d.ts.map +1 -1
- package/dist/src/mcpl/channel-registry.js +26 -3
- package/dist/src/mcpl/channel-registry.js.map +1 -1
- package/dist/src/mcpl/conversation-router.d.ts +28 -1
- package/dist/src/mcpl/conversation-router.d.ts.map +1 -1
- package/dist/src/mcpl/conversation-router.js +17 -0
- package/dist/src/mcpl/conversation-router.js.map +1 -1
- package/dist/src/mcpl/feature-set-manager.d.ts +11 -0
- package/dist/src/mcpl/feature-set-manager.d.ts.map +1 -1
- package/dist/src/mcpl/feature-set-manager.js +31 -7
- package/dist/src/mcpl/feature-set-manager.js.map +1 -1
- package/dist/src/mcpl/index.d.ts +2 -0
- package/dist/src/mcpl/index.d.ts.map +1 -1
- package/dist/src/mcpl/index.js +1 -0
- package/dist/src/mcpl/index.js.map +1 -1
- package/dist/src/mcpl/prose-stream-router.d.ts +27 -6
- package/dist/src/mcpl/prose-stream-router.d.ts.map +1 -1
- package/dist/src/mcpl/prose-stream-router.js +85 -22
- package/dist/src/mcpl/prose-stream-router.js.map +1 -1
- package/dist/src/mcpl/push-coalescer.d.ts +32 -4
- package/dist/src/mcpl/push-coalescer.d.ts.map +1 -1
- package/dist/src/mcpl/push-coalescer.js +46 -13
- package/dist/src/mcpl/push-coalescer.js.map +1 -1
- package/dist/src/mcpl/push-handler.d.ts +5 -3
- package/dist/src/mcpl/push-handler.d.ts.map +1 -1
- package/dist/src/mcpl/push-handler.js +41 -11
- package/dist/src/mcpl/push-handler.js.map +1 -1
- package/dist/src/mcpl/server-connection.d.ts +4 -0
- package/dist/src/mcpl/server-connection.d.ts.map +1 -1
- package/dist/src/mcpl/server-connection.js +45 -8
- package/dist/src/mcpl/server-connection.js.map +1 -1
- package/dist/src/mcpl/server-registry.d.ts +5 -2
- package/dist/src/mcpl/server-registry.d.ts.map +1 -1
- package/dist/src/mcpl/server-registry.js +25 -7
- package/dist/src/mcpl/server-registry.js.map +1 -1
- package/dist/src/mcpl/tool-lifecycle.d.ts +52 -2
- package/dist/src/mcpl/tool-lifecycle.d.ts.map +1 -1
- package/dist/src/mcpl/tool-lifecycle.js +47 -1
- package/dist/src/mcpl/tool-lifecycle.js.map +1 -1
- package/dist/src/mcpl/tool-pattern-check.d.ts +51 -0
- package/dist/src/mcpl/tool-pattern-check.d.ts.map +1 -0
- package/dist/src/mcpl/tool-pattern-check.js +79 -0
- package/dist/src/mcpl/tool-pattern-check.js.map +1 -0
- package/dist/src/mcpl/types.d.ts +15 -5
- package/dist/src/mcpl/types.d.ts.map +1 -1
- package/dist/src/mcpl/types.js.map +1 -1
- package/dist/src/mcpl/visible-content.d.ts +39 -0
- package/dist/src/mcpl/visible-content.d.ts.map +1 -0
- package/dist/src/mcpl/visible-content.js +54 -0
- package/dist/src/mcpl/visible-content.js.map +1 -0
- package/dist/src/module-registry.d.ts +81 -3
- package/dist/src/module-registry.d.ts.map +1 -1
- package/dist/src/module-registry.js +257 -16
- package/dist/src/module-registry.js.map +1 -1
- package/dist/src/modules/workspace/branch-intent.d.ts +72 -0
- package/dist/src/modules/workspace/branch-intent.d.ts.map +1 -0
- package/dist/src/modules/workspace/branch-intent.js +83 -0
- package/dist/src/modules/workspace/branch-intent.js.map +1 -0
- package/dist/src/modules/workspace/disk-agreement.d.ts +167 -0
- package/dist/src/modules/workspace/disk-agreement.d.ts.map +1 -0
- package/dist/src/modules/workspace/disk-agreement.js +259 -0
- package/dist/src/modules/workspace/disk-agreement.js.map +1 -0
- package/dist/src/modules/workspace/effects.d.ts +84 -0
- package/dist/src/modules/workspace/effects.d.ts.map +1 -0
- package/dist/src/modules/workspace/effects.js +368 -0
- package/dist/src/modules/workspace/effects.js.map +1 -0
- package/dist/src/modules/workspace/index.d.ts +155 -17
- package/dist/src/modules/workspace/index.d.ts.map +1 -1
- package/dist/src/modules/workspace/index.js +1059 -424
- package/dist/src/modules/workspace/index.js.map +1 -1
- package/dist/src/modules/workspace/observe.d.ts +278 -0
- package/dist/src/modules/workspace/observe.d.ts.map +1 -0
- package/dist/src/modules/workspace/observe.js +805 -0
- package/dist/src/modules/workspace/observe.js.map +1 -0
- package/dist/src/modules/workspace/reconcile.d.ts +224 -0
- package/dist/src/modules/workspace/reconcile.d.ts.map +1 -0
- package/dist/src/modules/workspace/reconcile.js +901 -0
- package/dist/src/modules/workspace/reconcile.js.map +1 -0
- package/dist/src/modules/workspace/sync.d.ts +6 -59
- package/dist/src/modules/workspace/sync.d.ts.map +1 -1
- package/dist/src/modules/workspace/sync.js +6 -257
- package/dist/src/modules/workspace/sync.js.map +1 -1
- package/dist/src/modules/workspace/types.d.ts +77 -10
- package/dist/src/modules/workspace/types.d.ts.map +1 -1
- package/dist/src/modules/workspace/types.js.map +1 -1
- package/dist/src/record-journal.d.ts +127 -0
- package/dist/src/record-journal.d.ts.map +1 -0
- package/dist/src/record-journal.js +202 -0
- package/dist/src/record-journal.js.map +1 -0
- package/dist/src/shutdown.d.ts +13 -0
- package/dist/src/shutdown.d.ts.map +1 -0
- package/dist/src/shutdown.js +46 -0
- package/dist/src/shutdown.js.map +1 -0
- package/dist/src/silent-heartbeat.d.ts +74 -0
- package/dist/src/silent-heartbeat.d.ts.map +1 -0
- package/dist/src/silent-heartbeat.js +77 -0
- package/dist/src/silent-heartbeat.js.map +1 -0
- package/dist/src/tool-presentation.d.ts +50 -0
- package/dist/src/tool-presentation.d.ts.map +1 -0
- package/dist/src/tool-presentation.js +235 -0
- package/dist/src/tool-presentation.js.map +1 -0
- package/dist/src/tool-result-guard.d.ts +125 -6
- package/dist/src/tool-result-guard.d.ts.map +1 -1
- package/dist/src/tool-result-guard.js +310 -35
- package/dist/src/tool-result-guard.js.map +1 -1
- package/dist/src/tool-result-history.d.ts +13 -0
- package/dist/src/tool-result-history.d.ts.map +1 -1
- package/dist/src/tool-result-history.js +21 -1
- package/dist/src/tool-result-history.js.map +1 -1
- package/dist/src/types/agent.d.ts +18 -2
- package/dist/src/types/agent.d.ts.map +1 -1
- package/dist/src/types/events.d.ts +4 -0
- package/dist/src/types/events.d.ts.map +1 -1
- package/dist/src/types/framework.d.ts +12 -0
- package/dist/src/types/framework.d.ts.map +1 -1
- package/dist/src/types/module.d.ts +14 -0
- package/dist/src/types/module.d.ts.map +1 -1
- package/dist/src/types/trace.d.ts +73 -0
- package/dist/src/types/trace.d.ts.map +1 -1
- package/dist/test/batched-wake-locus.test.d.ts +2 -0
- package/dist/test/batched-wake-locus.test.d.ts.map +1 -0
- package/dist/test/batched-wake-locus.test.js +166 -0
- package/dist/test/batched-wake-locus.test.js.map +1 -0
- package/dist/test/code-execution.test.js +386 -2
- package/dist/test/code-execution.test.js.map +1 -1
- package/dist/test/component-defaults.test.d.ts +2 -0
- package/dist/test/component-defaults.test.d.ts.map +1 -0
- package/dist/test/component-defaults.test.js +54 -0
- package/dist/test/component-defaults.test.js.map +1 -0
- package/dist/test/conversation-routing.test.js +57 -1
- package/dist/test/conversation-routing.test.js.map +1 -1
- package/dist/test/ephemeral-settle.test.js +3 -0
- package/dist/test/ephemeral-settle.test.js.map +1 -1
- package/dist/test/event-gate.test.js +118 -0
- package/dist/test/event-gate.test.js.map +1 -1
- package/dist/test/explicit-prose-routing.test.js +977 -0
- package/dist/test/explicit-prose-routing.test.js.map +1 -1
- package/dist/test/helpers/pytc-stop-rows.d.ts +11 -0
- package/dist/test/helpers/pytc-stop-rows.d.ts.map +1 -0
- package/dist/test/helpers/pytc-stop-rows.js +143 -0
- package/dist/test/helpers/pytc-stop-rows.js.map +1 -0
- package/dist/test/mcpl-coalescing.test.js +19 -6
- package/dist/test/mcpl-coalescing.test.js.map +1 -1
- package/dist/test/mcpl-config-diagnostics.test.d.ts +2 -0
- package/dist/test/mcpl-config-diagnostics.test.d.ts.map +1 -0
- package/dist/test/mcpl-config-diagnostics.test.js +449 -0
- package/dist/test/mcpl-config-diagnostics.test.js.map +1 -0
- package/dist/test/mcpl-empty-content.test.d.ts +2 -0
- package/dist/test/mcpl-empty-content.test.d.ts.map +1 -0
- package/dist/test/mcpl-empty-content.test.js +368 -0
- package/dist/test/mcpl-empty-content.test.js.map +1 -0
- package/dist/test/mcpl-tool-lifecycle-emitter.test.js +106 -1
- package/dist/test/mcpl-tool-lifecycle-emitter.test.js.map +1 -1
- package/dist/test/mcpl-tool-lifecycle-script.test.d.ts +2 -0
- package/dist/test/mcpl-tool-lifecycle-script.test.d.ts.map +1 -0
- package/dist/test/mcpl-tool-lifecycle-script.test.js +288 -0
- package/dist/test/mcpl-tool-lifecycle-script.test.js.map +1 -0
- package/dist/test/prose-stream-router.test.js +41 -0
- package/dist/test/prose-stream-router.test.js.map +1 -1
- package/dist/test/record-journal.test.d.ts +6 -0
- package/dist/test/record-journal.test.d.ts.map +1 -0
- package/dist/test/record-journal.test.js +269 -0
- package/dist/test/record-journal.test.js.map +1 -0
- package/dist/test/save-recent-image.test.js +102 -0
- package/dist/test/save-recent-image.test.js.map +1 -1
- package/dist/test/shutdown-errors.test.d.ts +2 -0
- package/dist/test/shutdown-errors.test.d.ts.map +1 -0
- package/dist/test/shutdown-errors.test.js +662 -0
- package/dist/test/shutdown-errors.test.js.map +1 -0
- package/dist/test/silent-heartbeat-rows.test.d.ts +2 -0
- package/dist/test/silent-heartbeat-rows.test.d.ts.map +1 -0
- package/dist/test/silent-heartbeat-rows.test.js +451 -0
- package/dist/test/silent-heartbeat-rows.test.js.map +1 -0
- package/dist/test/silent-heartbeat.test.js +49 -38
- package/dist/test/silent-heartbeat.test.js.map +1 -1
- package/dist/test/stop-with-work-in-flight.test.d.ts +23 -0
- package/dist/test/stop-with-work-in-flight.test.d.ts.map +1 -0
- package/dist/test/stop-with-work-in-flight.test.js +672 -0
- package/dist/test/stop-with-work-in-flight.test.js.map +1 -0
- package/dist/test/tool-batch-hook.test.d.ts +8 -0
- package/dist/test/tool-batch-hook.test.d.ts.map +1 -0
- package/dist/test/tool-batch-hook.test.js +275 -0
- package/dist/test/tool-batch-hook.test.js.map +1 -0
- package/dist/test/tool-presentation.test.d.ts +2 -0
- package/dist/test/tool-presentation.test.d.ts.map +1 -0
- package/dist/test/tool-presentation.test.js +268 -0
- package/dist/test/tool-presentation.test.js.map +1 -0
- package/dist/test/tool-result-guard.test.js +2330 -18
- package/dist/test/tool-result-guard.test.js.map +1 -1
- package/dist/test/tool-result-history.test.js +2 -1
- package/dist/test/tool-result-history.test.js.map +1 -1
- package/dist/test/turn-trigger-provenance.test.js +35 -0
- package/dist/test/turn-trigger-provenance.test.js.map +1 -1
- package/dist/test/unconvertible-tool-result.test.d.ts +2 -0
- package/dist/test/unconvertible-tool-result.test.d.ts.map +1 -0
- package/dist/test/unconvertible-tool-result.test.js +358 -0
- package/dist/test/unconvertible-tool-result.test.js.map +1 -0
- package/dist/test/workspace-materialize-freshness.test.d.ts +16 -0
- package/dist/test/workspace-materialize-freshness.test.d.ts.map +1 -0
- package/dist/test/workspace-materialize-freshness.test.js +252 -0
- package/dist/test/workspace-materialize-freshness.test.js.map +1 -0
- package/dist/test/workspace-three-way.test.d.ts +12 -0
- package/dist/test/workspace-three-way.test.d.ts.map +1 -0
- package/dist/test/workspace-three-way.test.js +3079 -0
- package/dist/test/workspace-three-way.test.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -3
- package/src/agent.ts +120 -44
- package/src/code-execution/py-runner.ts +66 -9
- package/src/code-execution/runtime-py.ts +215 -38
- package/src/framework.ts +1661 -363
- package/src/gate/event-gate.ts +59 -7
- package/src/index.ts +11 -0
- package/src/mcpl/channel-registry.ts +24 -3
- package/src/mcpl/conversation-router.ts +34 -1
- package/src/mcpl/feature-set-manager.ts +36 -11
- package/src/mcpl/index.ts +2 -0
- package/src/mcpl/prose-stream-router.ts +79 -23
- package/src/mcpl/push-coalescer.ts +62 -13
- package/src/mcpl/push-handler.ts +41 -12
- package/src/mcpl/server-connection.ts +41 -10
- package/src/mcpl/server-registry.ts +24 -7
- package/src/mcpl/tool-lifecycle.ts +77 -2
- package/src/mcpl/tool-pattern-check.ts +106 -0
- package/src/mcpl/types.ts +15 -5
- package/src/mcpl/visible-content.ts +57 -0
- package/src/module-registry.ts +252 -16
- package/src/modules/workspace/branch-intent.ts +123 -0
- package/src/modules/workspace/disk-agreement.ts +325 -0
- package/src/modules/workspace/effects.ts +362 -0
- package/src/modules/workspace/index.ts +1058 -446
- package/src/modules/workspace/observe.ts +839 -0
- package/src/modules/workspace/reconcile.ts +1136 -0
- package/src/modules/workspace/sync.ts +6 -336
- package/src/modules/workspace/types.ts +75 -10
- package/src/record-journal.ts +246 -0
- package/src/shutdown.ts +49 -0
- package/src/silent-heartbeat.ts +141 -0
- package/src/tool-presentation.ts +188 -0
- package/src/tool-result-guard.ts +335 -33
- package/src/tool-result-history.ts +25 -1
- package/src/types/agent.ts +18 -2
- package/src/types/events.ts +4 -0
- package/src/types/framework.ts +12 -0
- package/src/types/module.ts +15 -0
- package/src/types/trace.ts +80 -0
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
import { createHash, randomUUID } from 'node:crypto';
|
|
2
|
+
import { fchmodSync, closeSync, fstatSync, lstatSync, openSync, readSync, renameSync, unlinkSync, writeFileSync } from 'node:fs';
|
|
3
|
+
const MAX_BYTES = 256 * 1024;
|
|
4
|
+
const protectedNames = new Set(['set_tool_visibility', 'set_tool_description', 'workspace--read']);
|
|
5
|
+
export const isPresentationTool = (name) => name === 'set_tool_visibility' || name === 'set_tool_description';
|
|
6
|
+
const hash = (value) => createHash('sha256').update(value).digest('hex');
|
|
7
|
+
export function parsePresentation(raw) {
|
|
8
|
+
const doc = JSON.parse(raw);
|
|
9
|
+
if (!doc || doc.version !== 1 || !doc.tools || typeof doc.tools !== 'object' || Array.isArray(doc.tools)
|
|
10
|
+
|| Object.keys(doc).some(k => !['version', 'tools'].includes(k)))
|
|
11
|
+
throw new Error('Expected {"version":1,"tools":{...}}');
|
|
12
|
+
for (const [name, value] of Object.entries(doc.tools)) {
|
|
13
|
+
if (!name || !value || typeof value !== 'object' || Array.isArray(value))
|
|
14
|
+
throw new Error(`Invalid override: ${name}`);
|
|
15
|
+
const item = value;
|
|
16
|
+
if (Object.keys(item).some(k => !['description', 'visible'].includes(k))
|
|
17
|
+
|| ('description' in item && (typeof item.description !== 'string' || item.description.length > 32768))
|
|
18
|
+
|| ('visible' in item && typeof item.visible !== 'boolean'))
|
|
19
|
+
throw new Error(`Invalid description/visibility for ${name}`);
|
|
20
|
+
if (protectedNames.has(name) && item.visible === false)
|
|
21
|
+
throw new Error(`Cannot hide recovery tool ${name}`);
|
|
22
|
+
}
|
|
23
|
+
return doc;
|
|
24
|
+
}
|
|
25
|
+
export function presentationTools(path) {
|
|
26
|
+
const signpost = ` Read the generated catalogue with workspace--read {"path":${JSON.stringify(path)},"limit":140}. Hidden tools remain available; changes affect the next newly compiled request, not an in-flight stream.`;
|
|
27
|
+
return [
|
|
28
|
+
{ name: 'set_tool_visibility', description: 'Show or hide a tool definition. Hiding does not revoke permission.' + signpost,
|
|
29
|
+
inputSchema: { type: 'object', properties: { name: { type: 'string' }, visible: { type: 'boolean' } }, required: ['name', 'visible'], additionalProperties: false } },
|
|
30
|
+
{ name: 'set_tool_description', description: 'Set a personal tool description; null restores the configured component default, or the installed description when none is configured.' + signpost,
|
|
31
|
+
inputSchema: { type: 'object', properties: { name: { type: 'string' }, description: { type: ['string', 'null'] } }, required: ['name', 'description'], additionalProperties: false } },
|
|
32
|
+
];
|
|
33
|
+
}
|
|
34
|
+
/** Per-agent presentation; files are the sole persistent source, independent of editor identity. */
|
|
35
|
+
export class ToolPresentation {
|
|
36
|
+
config;
|
|
37
|
+
constructor(config) {
|
|
38
|
+
this.config = config;
|
|
39
|
+
}
|
|
40
|
+
read(path = this.config.path, allowMissing = true) {
|
|
41
|
+
let fd;
|
|
42
|
+
try {
|
|
43
|
+
fd = openSync(path, 'r');
|
|
44
|
+
}
|
|
45
|
+
catch (error) {
|
|
46
|
+
if (allowMissing && error.code === 'ENOENT')
|
|
47
|
+
return '{"version":1,"tools":{}}';
|
|
48
|
+
throw error;
|
|
49
|
+
}
|
|
50
|
+
try {
|
|
51
|
+
const stat = fstatSync(fd);
|
|
52
|
+
if (!stat.isFile() || stat.size > MAX_BYTES)
|
|
53
|
+
throw new Error('Presentation must be a regular file under 256 KiB');
|
|
54
|
+
const data = Buffer.alloc(MAX_BYTES + 1);
|
|
55
|
+
let size = 0, count = 0;
|
|
56
|
+
while (size < data.length && (count = readSync(fd, data, size, data.length - size, null)) > 0)
|
|
57
|
+
size += count;
|
|
58
|
+
if (size > MAX_BYTES)
|
|
59
|
+
throw new Error('Presentation exceeds 256 KiB');
|
|
60
|
+
return data.subarray(0, size).toString('utf8');
|
|
61
|
+
}
|
|
62
|
+
finally {
|
|
63
|
+
closeSync(fd);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
resolve(tools, sources = new Map()) {
|
|
67
|
+
let raw = '', doc = { version: 1, tools: {} }, diagnostics = [];
|
|
68
|
+
try {
|
|
69
|
+
raw = this.read();
|
|
70
|
+
doc = parsePresentation(raw);
|
|
71
|
+
}
|
|
72
|
+
catch (error) {
|
|
73
|
+
diagnostics.push(`Overrides not applied: ${String(error)}. Default visibility and component descriptions retained.`);
|
|
74
|
+
}
|
|
75
|
+
const defaults = new Map();
|
|
76
|
+
const configuredSources = new Set();
|
|
77
|
+
for (const profile of this.config.defaults ?? []) {
|
|
78
|
+
if (configuredSources.has(profile.source)) {
|
|
79
|
+
diagnostics.push(`Duplicate defaults source ignored: ${profile.source}`);
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
configuredSources.add(profile.source);
|
|
83
|
+
// Absent components contribute neither tools nor missing-file errors.
|
|
84
|
+
if (!tools.some(t => (sources.get(t.name) ?? 'Unattributed') === profile.source))
|
|
85
|
+
continue;
|
|
86
|
+
try {
|
|
87
|
+
const profileDoc = parsePresentation(this.read(profile.path, false));
|
|
88
|
+
if (Object.values(profileDoc.tools).some(item => Object.keys(item).some(k => k !== 'description')))
|
|
89
|
+
throw new Error('Component defaults may contain descriptions only; visibility belongs to the resident');
|
|
90
|
+
for (const tool of tools) {
|
|
91
|
+
if ((sources.get(tool.name) ?? 'Unattributed') !== profile.source)
|
|
92
|
+
continue;
|
|
93
|
+
const item = Object.hasOwn(profileDoc.tools, tool.name) ? profileDoc.tools[tool.name] : undefined;
|
|
94
|
+
if (item?.description !== undefined)
|
|
95
|
+
defaults.set(tool.name, { description: item.description, path: profile.path });
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
catch (error) {
|
|
99
|
+
diagnostics.push(`Component defaults not applied (${profile.source}): ${String(error)}`);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
const names = new Set(tools.map(t => t.name));
|
|
103
|
+
for (const name of Object.keys(doc.tools))
|
|
104
|
+
if (!names.has(name))
|
|
105
|
+
diagnostics.push(`Not currently available: ${name}`);
|
|
106
|
+
const entries = tools.map(tool => {
|
|
107
|
+
const override = Object.hasOwn(doc.tools, tool.name) ? doc.tools[tool.name] : undefined;
|
|
108
|
+
// Always retain a usable discovery signpost, even when its wording is overridden.
|
|
109
|
+
const componentDefault = defaults.get(tool.name);
|
|
110
|
+
let description = override?.description ?? componentDefault?.description ?? tool.description;
|
|
111
|
+
const descriptionSource = override?.description !== undefined ? this.config.path : componentDefault?.path ?? "installed component";
|
|
112
|
+
if (isPresentationTool(tool.name) && (override?.description !== undefined || componentDefault !== undefined))
|
|
113
|
+
description += `\nCatalogue: workspace--read {"path":${JSON.stringify(this.config.cataloguePath)},"limit":140}. Changes affect the next newly compiled request.`;
|
|
114
|
+
return { name: tool.name, source: sources.get(tool.name) ?? 'Unattributed', visible: override?.visible ?? true, originalDescription: tool.description, description, descriptionSource, inputSchema: structuredClone(tool.inputSchema) };
|
|
115
|
+
});
|
|
116
|
+
const available = tools.map((tool, i) => ({ ...structuredClone(tool), description: entries[i].description }));
|
|
117
|
+
return { revision: hash(JSON.stringify({ raw, entries, diagnostics })), source: this.config.path, cataloguePath: this.config.cataloguePath, diagnostics, available,
|
|
118
|
+
advertised: available.filter((_, i) => entries[i].visible), entries };
|
|
119
|
+
}
|
|
120
|
+
edit(tool, input, available) {
|
|
121
|
+
const lock = this.config.path + '.lock';
|
|
122
|
+
let fd, tempFd, temp;
|
|
123
|
+
try {
|
|
124
|
+
if (!isPresentationTool(tool))
|
|
125
|
+
throw new Error('Unknown editing tool');
|
|
126
|
+
const value = input;
|
|
127
|
+
const field = tool === 'set_tool_visibility' ? 'visible' : 'description';
|
|
128
|
+
if (!value || typeof value !== 'object' || Array.isArray(value) || typeof value.name !== 'string'
|
|
129
|
+
|| Object.keys(value).some(k => !['name', field].includes(k)) || !Object.hasOwn(value, field))
|
|
130
|
+
throw new Error('Invalid editing arguments');
|
|
131
|
+
if (!available.some(t => t.name === value.name))
|
|
132
|
+
throw new Error('Tool is not currently available to this agent');
|
|
133
|
+
if (field === 'visible' ? typeof value.visible !== 'boolean' : value.description !== null && typeof value.description !== 'string')
|
|
134
|
+
throw new Error(`Invalid ${field}`);
|
|
135
|
+
fd = openSync(lock, 'wx', 0o600);
|
|
136
|
+
let mode = 0o600;
|
|
137
|
+
try {
|
|
138
|
+
const stat = lstatSync(this.config.path);
|
|
139
|
+
if (stat.isSymbolicLink())
|
|
140
|
+
throw new Error('Edit the target file directly; tool editing refuses symlinks');
|
|
141
|
+
mode = stat.mode & 0o777;
|
|
142
|
+
}
|
|
143
|
+
catch (error) {
|
|
144
|
+
if (error.code !== 'ENOENT')
|
|
145
|
+
throw error;
|
|
146
|
+
}
|
|
147
|
+
const before = this.read(), doc = parsePresentation(before);
|
|
148
|
+
const old = Object.hasOwn(doc.tools, value.name) ? doc.tools[value.name] : {};
|
|
149
|
+
const updated = { ...old };
|
|
150
|
+
if (field === 'description' && value.description === null)
|
|
151
|
+
delete updated.description;
|
|
152
|
+
else
|
|
153
|
+
Object.assign(updated, { [field]: value[field] });
|
|
154
|
+
Object.defineProperty(doc.tools, value.name, { value: updated, enumerable: true, writable: true, configurable: true });
|
|
155
|
+
const next = JSON.stringify(doc, null, 2) + '\n';
|
|
156
|
+
parsePresentation(next);
|
|
157
|
+
if (Buffer.byteLength(next) > MAX_BYTES)
|
|
158
|
+
throw new Error('Presentation exceeds 256 KiB');
|
|
159
|
+
temp = this.config.path + '.' + randomUUID() + '.tmp';
|
|
160
|
+
tempFd = openSync(temp, 'wx', 0o600);
|
|
161
|
+
writeFileSync(tempFd, next);
|
|
162
|
+
fchmodSync(tempFd, mode); // preserve permissions on the opened inode, never a replacement path
|
|
163
|
+
if (this.read() !== before)
|
|
164
|
+
throw new Error('File changed concurrently; retry after reading it');
|
|
165
|
+
const opened = fstatSync(tempFd), named = lstatSync(temp);
|
|
166
|
+
if (!named.isFile() || named.dev !== opened.dev || named.ino !== opened.ino)
|
|
167
|
+
throw new Error('Temporary file changed concurrently; retry after checking the directory');
|
|
168
|
+
renameSync(temp, this.config.path);
|
|
169
|
+
temp = undefined;
|
|
170
|
+
return { success: true, data: { name: value.name, [field]: value[field], effective: 'next newly compiled request', catalogue: this.config.cataloguePath } };
|
|
171
|
+
}
|
|
172
|
+
catch (error) {
|
|
173
|
+
return { success: false, isError: true, error: String(error) };
|
|
174
|
+
}
|
|
175
|
+
finally {
|
|
176
|
+
if (tempFd !== undefined)
|
|
177
|
+
closeSync(tempFd);
|
|
178
|
+
if (temp)
|
|
179
|
+
try {
|
|
180
|
+
unlinkSync(temp);
|
|
181
|
+
}
|
|
182
|
+
catch { }
|
|
183
|
+
if (fd !== undefined) {
|
|
184
|
+
closeSync(fd);
|
|
185
|
+
unlinkSync(lock);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
export function renderCatalogue(snapshot) {
|
|
191
|
+
const groups = new Map();
|
|
192
|
+
for (const entry of snapshot.entries) {
|
|
193
|
+
const group = groups.get(entry.source) ?? [];
|
|
194
|
+
group.push(entry);
|
|
195
|
+
groups.set(entry.source, group);
|
|
196
|
+
}
|
|
197
|
+
const visible = snapshot.entries.filter(e => e.visible).length;
|
|
198
|
+
const lines = [
|
|
199
|
+
'# Tool catalogue — generated from currently available tools', '',
|
|
200
|
+
`Revision: ${snapshot.revision}`, '',
|
|
201
|
+
`${snapshot.entries.length} tools: ${visible} visible, ${snapshot.entries.length - visible} hidden.`,
|
|
202
|
+
'Visible = supplied in new requests. Hidden = stored away, still available.',
|
|
203
|
+
'These are your visibility choices, not fixed primary/secondary rankings.',
|
|
204
|
+
'Copy exact names from the index; similar-sounding names may not exist.',
|
|
205
|
+
'Show a hidden tool: set_tool_visibility {"name":"EXACT_NAME","visible":true}.',
|
|
206
|
+
`Read details: workspace--read {"path":${JSON.stringify(snapshot.cataloguePath)},"offset":LINE,"limit":LINES}.`,
|
|
207
|
+
'Line references below belong to this revision; reread the index after changes.', '',
|
|
208
|
+
];
|
|
209
|
+
for (const diagnostic of snapshot.diagnostics)
|
|
210
|
+
lines.push('Diagnostic: ' + diagnostic);
|
|
211
|
+
lines.push('## Index by source', '');
|
|
212
|
+
const index = new Map();
|
|
213
|
+
for (const [source, entries] of groups) {
|
|
214
|
+
lines.push(`### ${source} (${entries.length})`);
|
|
215
|
+
for (const entry of entries) {
|
|
216
|
+
index.set(entry.name, lines.length);
|
|
217
|
+
lines.push('');
|
|
218
|
+
}
|
|
219
|
+
lines.push('');
|
|
220
|
+
}
|
|
221
|
+
lines.push('## Full definitions', '');
|
|
222
|
+
for (const [source, entries] of groups) {
|
|
223
|
+
lines.push(`### ${source}`, '');
|
|
224
|
+
for (const entry of entries) {
|
|
225
|
+
const start = lines.length + 1;
|
|
226
|
+
lines.push(`#### ${entry.name} (${entry.visible ? 'visible' : 'hidden'})`, '', ...entry.description.split('\n'), '', `Description from: ${entry.descriptionSource ?? 'installed component'}`, '', `Schema: ${JSON.stringify(entry.inputSchema)}`);
|
|
227
|
+
if (entry.description !== entry.originalDescription)
|
|
228
|
+
lines.push('', 'Original description:', ...entry.originalDescription.split('\n'));
|
|
229
|
+
lines.push('');
|
|
230
|
+
lines[index.get(entry.name)] = `- [${entry.visible ? 'visible' : 'hidden'}] ${entry.name} — details: offset ${start}, limit ${lines.length - start + 1}`;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
return lines.join('\n');
|
|
234
|
+
}
|
|
235
|
+
//# sourceMappingURL=tool-presentation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-presentation.js","sourceRoot":"","sources":["../../src/tool-presentation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,QAAQ,EAAE,QAAQ,EAAE,UAAU,EAAE,UAAU,EAAE,aAA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AAS,CAAC,KAAK,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC;YACrK,IAAG,KAAK,CAAC,WAAW,KAAG,KAAK,CAAC,mBAAmB;gBAAE,KAAK,CAAC,IAAI,CAAC,EAAE,EAAE,uBAAuB,EAAE,GAAG,KAAK,CAAC,mBAAmB,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC;YACpI,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;YACf,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAE,CAAC,GAAG,MAAM,KAAK,CAAC,OAAO,CAAA,CAAC,CAAA,SAAS,CAAA,CAAC,CAAA,QAAQ,KAAK,KAAK,CAAC,IAAI,sBAAsB,KAAK,WAAW,KAAK,CAAC,MAAM,GAAC,KAAK,GAAC,CAAC,EAAE,CAAC;QACpJ,CAAC;IACH,CAAC;IACD,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC"}
|
|
@@ -1,8 +1,64 @@
|
|
|
1
|
-
import type { ContextManager, MessageId } from '@animalabs/context-manager';
|
|
1
|
+
import type { ContextManager, MessageId, MessageMetadata } from '@animalabs/context-manager';
|
|
2
2
|
import type { ContentBlock, NormalizedMessage, ToolResult } from '@animalabs/membrane';
|
|
3
3
|
import type { CompletedToolCall } from './types/index.js';
|
|
4
4
|
export declare const TOOL_RESULT_GUARD_NOTICE = "Tool result withheld by the guard. The tool has already executed.";
|
|
5
5
|
export declare const TOOL_RESULT_GUARD_AUDIT_STATE = "framework/tool-result-guard";
|
|
6
|
+
/** Where a withheld result's original went: a workspace path; the path a
|
|
7
|
+
* write to it failed at (`error`); the path a write was still under way to
|
|
8
|
+
* when the host stopped waiting for it (`unfinished`); no write, because the
|
|
9
|
+
* workspace isn't answering (`workspace_unanswered`: an earlier write is
|
|
10
|
+
* still under way past the host's deadline) or because the workspace had
|
|
11
|
+
* left the stub's branch when the file would have been committed
|
|
12
|
+
* (`branch_changed`), or because the batch used its deadline before this
|
|
13
|
+
* write could start (`batch_deadline`); or null when no file is written at all (no writable
|
|
14
|
+
* workspace, or the host is stopping). */
|
|
15
|
+
export type WithheldSpill = {
|
|
16
|
+
path: string;
|
|
17
|
+
error?: string;
|
|
18
|
+
unfinished?: true;
|
|
19
|
+
} | {
|
|
20
|
+
skipped: 'workspace_unanswered' | 'branch_changed' | 'batch_deadline';
|
|
21
|
+
} | null;
|
|
22
|
+
/**
|
|
23
|
+
* Writes one withheld original as a workspace file, using what remains of
|
|
24
|
+
* the batch's absolute deadline. A write still running then is unfinished.
|
|
25
|
+
* Once a write reaches that deadline, later spills are workspace_unanswered
|
|
26
|
+
* until all overdue writes settle. Other batches can start before that gate
|
|
27
|
+
* closes. An exhausted batch starts no write (batch_deadline).
|
|
28
|
+
* The tree entry lands on branch or the write is declined (branch_changed).
|
|
29
|
+
* The mount's disk directory is shared across branches.
|
|
30
|
+
*/
|
|
31
|
+
export type WithheldSpiller = (label: string, text: string, branch: string, deadline: number) => Promise<WithheldSpill>;
|
|
32
|
+
/** What a host gives a guard for its withheld results: where originals are
|
|
33
|
+
* written, where each annotation is registered, so the host's stop can
|
|
34
|
+
* wait for it even after the agent itself was disposed, and where the
|
|
35
|
+
* guard says whether it has work left. */
|
|
36
|
+
export interface WithheldHost {
|
|
37
|
+
spill: WithheldSpiller;
|
|
38
|
+
/** Absolute deadline for one batch (Date.now() time), taken when the batch is queued. */
|
|
39
|
+
deadline(): number;
|
|
40
|
+
track(annotation: Promise<void>): void;
|
|
41
|
+
/** Whether the guard is idle (see ToolResultGuard.idle), told after each
|
|
42
|
+
* change that can alter it: when an annotation starts or ends, and after
|
|
43
|
+
* each pass over the storage queue. A host keeps a guard that isn't idle
|
|
44
|
+
* within reach for retries, whatever has become of its agent, and lets
|
|
45
|
+
* an idle one go. */
|
|
46
|
+
idle(idle: boolean): void;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* The stub a withheld result settles to: #159's neutral notice, then where
|
|
50
|
+
* the original is. It names no refusal and no category (#159 keeps those in
|
|
51
|
+
* operational logs), only the place, so reading it back is the agent's
|
|
52
|
+
* deliberate choice (agent-framework #277). The place holds the result as
|
|
53
|
+
* stored, which for one over the inline cap is its capped text, whose own
|
|
54
|
+
* note names the file with the whole output; so the stub says "its result",
|
|
55
|
+
* not its full result. A failed write's own error text
|
|
56
|
+
* stays in the audit record and the logs, not here. The audit
|
|
57
|
+
* record is said to keep the original only when it was saved: a staged
|
|
58
|
+
* record whose save failed is still queued in memory, and a restart before
|
|
59
|
+
* its retry loses it.
|
|
60
|
+
*/
|
|
61
|
+
export declare function withheldResultNotice(spill: WithheldSpill, auditDurable: boolean): string;
|
|
6
62
|
/**
|
|
7
63
|
* Admission of newly returned tool output to durable model-facing memory.
|
|
8
64
|
*
|
|
@@ -21,8 +77,43 @@ export declare class ToolResultGuard {
|
|
|
21
77
|
private override;
|
|
22
78
|
/** True until a recovery produces a clean response/new tool round. */
|
|
23
79
|
recovering: boolean;
|
|
80
|
+
/** Writes withheld originals where the agent can read them; without it,
|
|
81
|
+
* a stub names only the audit record. */
|
|
82
|
+
private host;
|
|
83
|
+
/** Annotations of withheld stubs, chained in settlement order. */
|
|
84
|
+
private annotating;
|
|
85
|
+
/** Annotations started so far, so a read can tell one began during it. */
|
|
86
|
+
private annotationsStarted;
|
|
24
87
|
constructor(agentName: string, cm: ContextManager, configured?: boolean);
|
|
25
88
|
get enabled(): boolean;
|
|
89
|
+
setHost(host: WithheldHost | undefined): void;
|
|
90
|
+
/** Settles once every annotation started so far has finished: each of
|
|
91
|
+
* those stubs has been edited to say where its original is, or its edit
|
|
92
|
+
* failed and waits in the storage queue, retried in order until it lands
|
|
93
|
+
* or an operator's change supersedes it (until then the stub is the bare
|
|
94
|
+
* notice, kept out of summaries by its compression hold, and the audit
|
|
95
|
+
* record names the place). It never rejects. Each batch has one deadline
|
|
96
|
+
* for all its workspace writes; queued batches are annotated in order.
|
|
97
|
+
* A request may carry an unfinished-write notice once that deadline passes. */
|
|
98
|
+
whenAnnotated(): Promise<void>;
|
|
99
|
+
/**
|
|
100
|
+
* Runs `read` (a compile of the context) once no withheld stub is still
|
|
101
|
+
* being annotated, and again if an annotation began while it ran, since a
|
|
102
|
+
* settlement can land during the compile's own awaits, such as a previous
|
|
103
|
+
* frame's teardown abandoning its batch. The framework's sent-request
|
|
104
|
+
* compiles go through it: the agent's activations, its direct
|
|
105
|
+
* API calls and their refusal retry, and a conversation fork's seed from its
|
|
106
|
+
* template. A request preview doesn't, so it never waits on a
|
|
107
|
+
* workspace write.
|
|
108
|
+
*
|
|
109
|
+
* Before `read`, a stub edit that failed gets another try with the rest of
|
|
110
|
+
* the storage queue; a store that is still failing then compiles the bare
|
|
111
|
+
* notice, which its hold keeps out of summaries.
|
|
112
|
+
*/
|
|
113
|
+
afterAnnotations<T>(read: () => Promise<T>): Promise<T>;
|
|
114
|
+
/** No annotation is running and no storage work is queued: nothing of this
|
|
115
|
+
* guard is left for a host to wait on or retry. */
|
|
116
|
+
get idle(): boolean;
|
|
26
117
|
setOverride(value: boolean | undefined): void;
|
|
27
118
|
get settingOverride(): boolean | undefined;
|
|
28
119
|
get hasPending(): boolean;
|
|
@@ -37,15 +128,22 @@ export declare class ToolResultGuard {
|
|
|
37
128
|
get pendingWireReserveTokens(): number;
|
|
38
129
|
/** Ordered storage work, separate from batches awaiting a provider verdict.
|
|
39
130
|
* A failed acceptance edit retains both the payload and its compression
|
|
40
|
-
* hold here; it can never re-arm refusal handling or tool submission.
|
|
131
|
+
* hold here; it can never re-arm refusal handling or tool submission.
|
|
132
|
+
* Any failed head, including an audit-only record, blocks later queued
|
|
133
|
+
* edits and their holds until that operation succeeds. */
|
|
41
134
|
private unrecorded;
|
|
42
|
-
/** Retry edits and audit writes before a new activation,
|
|
43
|
-
*
|
|
135
|
+
/** Retry edits and audit writes before a new activation, a compile of a
|
|
136
|
+
* request that is sent (afterAnnotations), an audit write, a maintenance
|
|
137
|
+
* pass, or shutdown. A failed operation stays at the head. */
|
|
44
138
|
flushUnrecorded(): void;
|
|
139
|
+
/** Make an operation's history edit, if it still has one: once it is made,
|
|
140
|
+
* or superseded by an operator's change, only its record is left to
|
|
141
|
+
* write, and its hold can go. */
|
|
142
|
+
private applyEdit;
|
|
45
143
|
private append;
|
|
46
144
|
private write;
|
|
47
145
|
private archive;
|
|
48
|
-
storeResults(content: ContentBlock[], wireResults: ToolResult[], originals: CompletedToolCall[]): MessageId;
|
|
146
|
+
storeResults(content: ContentBlock[], wireResults: ToolResult[], originals: CompletedToolCall[], metadata?: MessageMetadata): MessageId;
|
|
49
147
|
/** Results for a live continuation (provideToolResults). Marks the batch
|
|
50
148
|
* submitted and returns the originals only when the audit is durable;
|
|
51
149
|
* otherwise returns placeholder results and leaves it unsubmitted. */
|
|
@@ -74,8 +172,29 @@ export declare class ToolResultGuard {
|
|
|
74
172
|
withhold(category: string): string[] | null;
|
|
75
173
|
/** Transfer ownership from provider admission to an ordered storage job.
|
|
76
174
|
* Failure retains the accepted payload and its hold until the edit succeeds.
|
|
77
|
-
*
|
|
175
|
+
* A withheld batch's hold passes to its annotation instead, and from there
|
|
176
|
+
* to its stub's edit, so no summary is made of a stub that doesn't yet say
|
|
177
|
+
* where its original went. */
|
|
78
178
|
private settle;
|
|
179
|
+
/**
|
|
180
|
+
* Turn a withheld batch's notices into stubs that say where each original
|
|
181
|
+
* is (agent-framework #277): written to the workspace when a writable mount
|
|
182
|
+
* takes it, else kept in the audit record. Its own unedited placeholder is
|
|
183
|
+
* the only thing it edits: an operator's later edit, removal or rollback
|
|
184
|
+
* stands.
|
|
185
|
+
*
|
|
186
|
+
* Where each original went is queued first, on its own ('annotated'), so
|
|
187
|
+
* a stub edit that fails can't take the record of a written file with it.
|
|
188
|
+
* The edit is then made at once, so no storage work queued ahead of it
|
|
189
|
+
* holds it, not even that record if its write is failing, and its record
|
|
190
|
+
* ('stub_updated') is written in order after the others. An
|
|
191
|
+
* edit that fails joins the ordered storage queue like an admission's, with
|
|
192
|
+
* the batch's compression hold: retried before the next activation, compile,
|
|
193
|
+
* maintenance pass or stop until it lands or an operator's change supersedes
|
|
194
|
+
* it. Until then the stub is the bare notice, which the hold keeps out of
|
|
195
|
+
* summaries, and the audit record names the file.
|
|
196
|
+
*/
|
|
197
|
+
private annotate;
|
|
79
198
|
private releaseOperationHold;
|
|
80
199
|
private releaseHold;
|
|
81
200
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool-result-guard.d.ts","sourceRoot":"","sources":["../../src/tool-result-guard.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;
|
|
1
|
+
{"version":3,"file":"tool-result-guard.d.ts","sourceRoot":"","sources":["../../src/tool-result-guard.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAC7F,OAAO,KAAK,EAAE,YAAY,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACvF,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAG1D,eAAO,MAAM,wBAAwB,sEAAsE,CAAC;AAC5G,eAAO,MAAM,6BAA6B,gCAAgC,CAAC;AAE3E;;;;;;;;2CAQ2C;AAC3C,MAAM,MAAM,aAAa,GACrB;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IAAC,UAAU,CAAC,EAAE,IAAI,CAAA;CAAE,GACnD;IAAE,OAAO,EAAE,sBAAsB,GAAG,gBAAgB,GAAG,gBAAgB,CAAA;CAAE,GACzE,IAAI,CAAC;AAET;;;;;;;;GAQG;AACH,MAAM,MAAM,eAAe,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,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