@myagentroam/agent 0.9.141 → 0.9.143
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/dist/agent-core/host/contracts.d.ts +64 -0
- package/dist/{host → agent-core/host}/local-agent-host.d.ts +6 -5
- package/dist/{host → agent-core/host}/local-agent-host.js +4 -4
- package/dist/{model → agent-core/model}/anthropic-messages.js +24 -13
- package/dist/{model → agent-core/model}/contracts.d.ts +6 -16
- package/dist/{model → agent-core/model}/openai-responses.js +16 -9
- package/dist/agent-core/model/recovery.d.ts +4 -0
- package/dist/agent-core/model/recovery.js +71 -0
- package/dist/{prompts → agent-core/prompts}/core.d.ts +3 -13
- package/dist/{prompts → agent-core/prompts}/index.d.ts +1 -1
- package/dist/{prompts → agent-core/prompts}/modes.d.ts +1 -1
- package/dist/{prompts → agent-core/prompts}/resources.d.ts +1 -1
- package/dist/{runtime/compact.d.ts → agent-core/runtime/compaction/history.d.ts} +2 -23
- package/dist/{runtime/compact.js → agent-core/runtime/compaction/history.js} +2 -92
- package/dist/agent-core/runtime/compaction/operation.d.ts +22 -0
- package/dist/agent-core/runtime/compaction/operation.js +91 -0
- package/dist/agent-core/runtime/context/contracts.d.ts +12 -0
- package/dist/{runtime/environment-context.d.ts → agent-core/runtime/context/environment.d.ts} +2 -2
- package/dist/{runtime/environment-context.js → agent-core/runtime/context/environment.js} +1 -1
- package/dist/{runtime/context-gc-runtime.d.ts → agent-core/runtime/context/gc-runtime.d.ts} +4 -4
- package/dist/{runtime/context-gc-runtime.js → agent-core/runtime/context/gc-runtime.js} +3 -3
- package/dist/{runtime/context-gc-tokens.d.ts → agent-core/runtime/context/gc-tokens.d.ts} +2 -2
- package/dist/{runtime/context-gc-tokens.js → agent-core/runtime/context/gc-tokens.js} +7 -5
- package/dist/{runtime/context-gc.d.ts → agent-core/runtime/context/gc.d.ts} +3 -3
- package/dist/{runtime/context-gc.js → agent-core/runtime/context/gc.js} +152 -19
- package/dist/{runtime → agent-core/runtime/context}/instructions.d.ts +1 -1
- package/dist/{runtime → agent-core/runtime/context}/instructions.js +1 -1
- package/dist/{runtime → agent-core/runtime/context}/normalize.d.ts +1 -1
- package/dist/{runtime/context-projection.d.ts → agent-core/runtime/context/projection.d.ts} +3 -3
- package/dist/{runtime/context-projection.js → agent-core/runtime/context/projection.js} +35 -4
- package/dist/agent-core/runtime/context/request-budget.d.ts +6 -0
- package/dist/agent-core/runtime/context/request-budget.js +22 -0
- package/dist/agent-core/runtime/context/restore.d.ts +15 -0
- package/dist/agent-core/runtime/context/restore.js +85 -0
- package/dist/agent-core/runtime/context/usage.d.ts +18 -0
- package/dist/agent-core/runtime/context/usage.js +138 -0
- package/dist/agent-core/runtime/context/world-state.d.ts +35 -0
- package/dist/agent-core/runtime/context/world-state.js +133 -0
- package/dist/agent-core/runtime/contracts.d.ts +37 -0
- package/dist/agent-core/runtime/event-projection.d.ts +5 -0
- package/dist/agent-core/runtime/event-projection.js +17 -0
- package/dist/agent-core/runtime/events.d.ts +143 -0
- package/dist/agent-core/runtime/execution.d.ts +50 -0
- package/dist/agent-core/runtime/execution.js +397 -0
- package/dist/{runtime → agent-core/runtime}/rollout-budget.d.ts +1 -1
- package/dist/agent-core/sdk/agent.js +209 -0
- package/dist/agent-core/sdk/model-runtime.d.ts +13 -0
- package/dist/agent-core/sdk/model-runtime.js +63 -0
- package/dist/agent-core/sdk/session-title.d.ts +3 -0
- package/dist/agent-core/sdk/session-title.js +42 -0
- package/dist/agent-core/sdk/session.d.ts +62 -0
- package/dist/agent-core/sdk/session.js +1147 -0
- package/dist/agent-core/sdk/subagent-backend.d.ts +3 -0
- package/dist/agent-core/sdk/subagent-backend.js +46 -0
- package/dist/agent-core/sdk/types.d.ts +56 -0
- package/dist/{session → agent-core/session}/catalog.d.ts +2 -1
- package/dist/{session → agent-core/session}/context-gc-checkpoint.d.ts +3 -0
- package/dist/{session → agent-core/session}/context-gc-checkpoint.js +122 -23
- package/dist/agent-core/session/context-gc-observations.d.ts +38 -0
- package/dist/agent-core/session/context-gc-observations.js +150 -0
- package/dist/{session → agent-core/session}/context-gc-replacements.d.ts +1 -1
- package/dist/{session → agent-core/session}/context-gc-replacements.js +6 -2
- package/dist/{session → agent-core/session}/jsonl-store.d.ts +2 -2
- package/dist/{session → agent-core/session}/jsonl-store.js +1 -1
- package/dist/agent-core/subagent/contracts.d.ts +91 -0
- package/dist/agent-core/subagent/contracts.js +1 -0
- package/dist/agent-core/subagent/scheduler.d.ts +117 -0
- package/dist/{subagent → agent-core/subagent}/session-controller.d.ts +3 -2
- package/dist/agent-core/tools/agent/agent-cancel.d.ts +7 -0
- package/dist/{tools → agent-core/tools/agent}/agent-cancel.js +1 -1
- package/dist/agent-core/tools/agent/agent-message.d.ts +7 -0
- package/dist/{tools → agent-core/tools/agent}/agent-message.js +2 -2
- package/dist/{tools → agent-core/tools/agent}/agent-start.d.ts +3 -3
- package/dist/{tools → agent-core/tools/agent}/agent-start.js +3 -3
- package/dist/agent-core/tools/agent/agent-wait.d.ts +7 -0
- package/dist/{tools → agent-core/tools/agent}/agent-wait.js +2 -2
- package/dist/{tools → agent-core/tools/agent}/question.d.ts +2 -2
- package/dist/{tools → agent-core/tools/agent}/question.js +2 -2
- package/dist/{tools → agent-core/tools/agent}/skill.d.ts +2 -2
- package/dist/{tools → agent-core/tools/agent}/skill.js +2 -2
- package/dist/{tools → agent-core/tools/agent}/todo-read.d.ts +2 -2
- package/dist/{tools → agent-core/tools/agent}/todo-write.d.ts +2 -2
- package/dist/{tools → agent-core/tools/agent}/todo-write.js +2 -2
- package/dist/{tools → agent-core/tools/agent}/todo.d.ts +2 -9
- package/dist/{tools → agent-core/tools/agent}/todo.js +1 -1
- package/dist/{tools → agent-core/tools}/code-mode/cells.d.ts +4 -1
- package/dist/{tools → agent-core/tools}/code-mode/cells.js +60 -6
- package/dist/{tools → agent-core/tools}/code-mode/dispatch.d.ts +2 -4
- package/dist/{tools → agent-core/tools}/code-mode/dispatch.js +10 -6
- package/dist/{tools → agent-core/tools}/code-mode/engine.d.ts +13 -1
- package/dist/agent-core/tools/code-mode/engine.js +1 -0
- package/dist/{tools/code-mode.d.ts → agent-core/tools/code-mode/index.d.ts} +7 -7
- package/dist/{tools/code-mode.js → agent-core/tools/code-mode/index.js} +190 -28
- package/dist/agent-core/tools/code-mode/observations.d.ts +103 -0
- package/dist/agent-core/tools/code-mode/observations.js +195 -0
- package/dist/{tools → agent-core/tools}/code-mode/quickjs-engine.js +91 -17
- package/dist/{tools → agent-core/tools}/code-mode/state.d.ts +2 -13
- package/dist/agent-core/tools/code-mode/worker.d.ts +1 -0
- package/dist/{tools → agent-core/tools}/code-mode/worker.js +8 -1
- package/dist/agent-core/tools/contracts.d.ts +172 -0
- package/dist/agent-core/tools/contracts.js +1 -0
- package/dist/agent-core/tools/execution.d.ts +36 -0
- package/dist/agent-core/tools/execution.js +111 -0
- package/dist/agent-core/tools/local/apply-patch.d.ts +19 -0
- package/dist/{tools → agent-core/tools/local}/apply-patch.js +8 -2
- package/dist/{tools → agent-core/tools/local}/exec.d.ts +5 -17
- package/dist/{tools → agent-core/tools/local}/exec.js +4 -4
- package/dist/{tools → agent-core/tools/local}/read.d.ts +7 -15
- package/dist/{tools → agent-core/tools/local}/read.js +185 -2
- package/dist/{tools/local-registry.d.ts → agent-core/tools/local/registry.d.ts} +5 -5
- package/dist/agent-core/tools/local/registry.js +101 -0
- package/dist/{tools → agent-core/tools/local}/view-image.d.ts +4 -9
- package/dist/{tools → agent-core/tools/local}/view-image.js +2 -2
- package/dist/agent-core/tools/local/web-fetch.d.ts +4 -0
- package/dist/agent-core/tools/local/web-fetch.js +85 -0
- package/dist/agent-core/tools/local/web-search.d.ts +7 -0
- package/dist/agent-core/tools/local/web-search.js +34 -0
- package/dist/{tools/local-workspace-tools.js → agent-core/tools/local/workspace-tools.js} +1 -1
- package/dist/{sdk/mcp-catalog.d.ts → agent-core/tools/mcp/catalog.d.ts} +1 -2
- package/dist/{sdk/mcp-catalog.js → agent-core/tools/mcp/catalog.js} +1 -1
- package/dist/agent-core/tools/mcp/history.d.ts +4 -0
- package/dist/agent-core/tools/mcp/history.js +33 -0
- package/dist/{tools → agent-core/tools/mcp}/tool-search.d.ts +3 -3
- package/dist/{tools → agent-core/tools/mcp}/tool-search.js +4 -4
- package/dist/agent-core/tools/output-projection.d.ts +14 -0
- package/dist/agent-core/tools/output-projection.js +223 -0
- package/dist/{tools → agent-core/tools}/registry.d.ts +1 -1
- package/dist/agent-core/tools/registry.js +47 -0
- package/dist/{tools → agent-core/tools}/runtime-context.d.ts +8 -7
- package/dist/agent-core/tools/runtime-context.js +1 -0
- package/dist/{tools → agent-core/tools}/runtime.d.ts +1 -1
- package/dist/cli/codex-auth-file.d.ts +1 -1
- package/dist/cli/codex-auth-file.js +2 -2
- package/dist/cli/main.js +9 -9
- package/dist/index.d.ts +17 -15
- package/dist/index.js +8 -8
- package/dist/sandbox/linux/bubblewrap-sandbox-executor.d.ts +1 -1
- package/dist/sandbox/linux/bubblewrap-sandbox-executor.js +1 -1
- package/package.json +3 -3
- package/dist/host/contracts.d.ts +0 -21
- package/dist/sdk/agent.js +0 -2548
- package/dist/sdk/types.d.ts +0 -349
- package/dist/subagent/scheduler.d.ts +0 -206
- package/dist/tools/agent-cancel.d.ts +0 -7
- package/dist/tools/agent-message.d.ts +0 -7
- package/dist/tools/agent-wait.d.ts +0 -7
- package/dist/tools/apply-patch.d.ts +0 -32
- package/dist/tools/local-registry.js +0 -373
- package/dist/tools/registry.js +0 -47
- package/dist/tools/web-fetch.d.ts +0 -2
- package/dist/tools/web-fetch.js +0 -12
- package/dist/tools/web-search.d.ts +0 -2
- package/dist/tools/web-search.js +0 -15
- /package/dist/{error.d.ts → agent-core/error.d.ts} +0 -0
- /package/dist/{error.js → agent-core/error.js} +0 -0
- /package/dist/{host → agent-core/host}/contracts.js +0 -0
- /package/dist/{host → agent-core/host}/local-process-executor.d.ts +0 -0
- /package/dist/{host → agent-core/host}/local-process-executor.js +0 -0
- /package/dist/{host → agent-core/host}/network.d.ts +0 -0
- /package/dist/{host → agent-core/host}/network.js +0 -0
- /package/dist/{model → agent-core/model}/anthropic-messages.d.ts +0 -0
- /package/dist/{model → agent-core/model}/anthropic-thinking.d.ts +0 -0
- /package/dist/{model → agent-core/model}/anthropic-thinking.js +0 -0
- /package/dist/{model → agent-core/model}/catalog-file.d.ts +0 -0
- /package/dist/{model → agent-core/model}/catalog-file.js +0 -0
- /package/dist/{model → agent-core/model}/configuration.d.ts +0 -0
- /package/dist/{model → agent-core/model}/configuration.js +0 -0
- /package/dist/{model → agent-core/model}/contracts.js +0 -0
- /package/dist/{model → agent-core/model}/http.d.ts +0 -0
- /package/dist/{model → agent-core/model}/http.js +0 -0
- /package/dist/{model → agent-core/model}/openai-responses.d.ts +0 -0
- /package/dist/{model → agent-core/model}/runtime-credential.d.ts +0 -0
- /package/dist/{model → agent-core/model}/runtime-credential.js +0 -0
- /package/dist/{model → agent-core/model}/sse.d.ts +0 -0
- /package/dist/{model → agent-core/model}/sse.js +0 -0
- /package/dist/{model → agent-core/model}/transport-test.d.ts +0 -0
- /package/dist/{model → agent-core/model}/transport-test.js +0 -0
- /package/dist/{prompts → agent-core/prompts}/compact.d.ts +0 -0
- /package/dist/{prompts → agent-core/prompts}/compact.js +0 -0
- /package/dist/{prompts → agent-core/prompts}/core.js +0 -0
- /package/dist/{prompts → agent-core/prompts}/execution-budget.d.ts +0 -0
- /package/dist/{prompts → agent-core/prompts}/execution-budget.js +0 -0
- /package/dist/{prompts → agent-core/prompts}/index.js +0 -0
- /package/dist/{prompts → agent-core/prompts}/modes.js +0 -0
- /package/dist/{prompts → agent-core/prompts}/output.d.ts +0 -0
- /package/dist/{prompts → agent-core/prompts}/output.js +0 -0
- /package/dist/{prompts → agent-core/prompts}/resources.js +0 -0
- /package/dist/{prompts → agent-core/prompts}/subagent.d.ts +0 -0
- /package/dist/{prompts → agent-core/prompts}/subagent.js +0 -0
- /package/dist/{prompts → agent-core/prompts}/title.d.ts +0 -0
- /package/dist/{prompts → agent-core/prompts}/title.js +0 -0
- /package/dist/{prompts → agent-core/prompts}/workflow.d.ts +0 -0
- /package/dist/{prompts → agent-core/prompts}/workflow.js +0 -0
- /package/dist/{runtime → agent-core/runtime}/async-queue.d.ts +0 -0
- /package/dist/{runtime → agent-core/runtime}/async-queue.js +0 -0
- /package/dist/{sdk/types.js → agent-core/runtime/context/contracts.js} +0 -0
- /package/dist/{runtime → agent-core/runtime/context}/normalize.js +0 -0
- /package/dist/{session/types.js → agent-core/runtime/contracts.js} +0 -0
- /package/dist/{tools/code-mode/engine.js → agent-core/runtime/events.js} +0 -0
- /package/dist/{runtime → agent-core/runtime}/execution-policy.d.ts +0 -0
- /package/dist/{runtime → agent-core/runtime}/execution-policy.js +0 -0
- /package/dist/{runtime → agent-core/runtime}/plan-output.d.ts +0 -0
- /package/dist/{runtime → agent-core/runtime}/plan-output.js +0 -0
- /package/dist/{runtime → agent-core/runtime}/rollout-budget.js +0 -0
- /package/dist/{runtime → agent-core/runtime}/token-budget.d.ts +0 -0
- /package/dist/{runtime → agent-core/runtime}/token-budget.js +0 -0
- /package/dist/{sdk → agent-core/sdk}/agent.d.ts +0 -0
- /package/dist/{tools/code-mode/worker.d.ts → agent-core/sdk/types.js} +0 -0
- /package/dist/{session → agent-core/session}/catalog.js +0 -0
- /package/dist/{session → agent-core/session}/context-gc-subagent.d.ts +0 -0
- /package/dist/{session → agent-core/session}/context-gc-subagent.js +0 -0
- /package/dist/{session → agent-core/session}/transaction-recovery.d.ts +0 -0
- /package/dist/{session → agent-core/session}/transaction-recovery.js +0 -0
- /package/dist/{session → agent-core/session}/types.d.ts +0 -0
- /package/dist/{tools/runtime-context.js → agent-core/session/types.js} +0 -0
- /package/dist/{subagent → agent-core/subagent}/scheduler.js +0 -0
- /package/dist/{subagent → agent-core/subagent}/session-controller.js +0 -0
- /package/dist/{tools → agent-core/tools/agent}/todo-read.js +0 -0
- /package/dist/{tools → agent-core/tools}/callers.d.ts +0 -0
- /package/dist/{tools → agent-core/tools}/callers.js +0 -0
- /package/dist/{tools → agent-core/tools}/code-mode/quickjs-engine.d.ts +0 -0
- /package/dist/{tools → agent-core/tools}/code-mode/state.js +0 -0
- /package/dist/{tools → agent-core/tools}/code-mode/text-output.d.ts +0 -0
- /package/dist/{tools → agent-core/tools}/code-mode/text-output.js +0 -0
- /package/dist/{tools → agent-core/tools}/execution-limits.d.ts +0 -0
- /package/dist/{tools → agent-core/tools}/execution-limits.js +0 -0
- /package/dist/{tools → agent-core/tools/local}/read-context.d.ts +0 -0
- /package/dist/{tools → agent-core/tools/local}/read-context.js +0 -0
- /package/dist/{tools/local-workspace-tools.d.ts → agent-core/tools/local/workspace-tools.d.ts} +0 -0
- /package/dist/{tools → agent-core/tools}/runtime.js +0 -0
- /package/dist/{tools → agent-core/tools}/scheduler.d.ts +0 -0
- /package/dist/{tools → agent-core/tools}/scheduler.js +0 -0
- /package/dist/{tools → agent-core/tools}/shared/path-resolver.d.ts +0 -0
- /package/dist/{tools → agent-core/tools}/shared/path-resolver.js +0 -0
|
@@ -29,6 +29,7 @@ export async function createCodeModeEngine(options) {
|
|
|
29
29
|
const stateMutations = [];
|
|
30
30
|
let outputBytes = 0;
|
|
31
31
|
let textCalls = 0;
|
|
32
|
+
const origins = [];
|
|
32
33
|
const notify = () => {
|
|
33
34
|
wake?.();
|
|
34
35
|
wake = undefined;
|
|
@@ -72,6 +73,28 @@ export async function createCodeModeEngine(options) {
|
|
|
72
73
|
});
|
|
73
74
|
};
|
|
74
75
|
globalThis.__text = ${streamText.toString()};
|
|
76
|
+
globalThis.__snapshot = (() => {
|
|
77
|
+
const keys = Reflect.ownKeys, descriptor = Object.getOwnPropertyDescriptor;
|
|
78
|
+
const create = Object.create, stringify = JSON.stringify;
|
|
79
|
+
return (value, errorSnapshot) => {
|
|
80
|
+
const seen = create(null); let depth = 0;
|
|
81
|
+
function walk(item) {
|
|
82
|
+
if (item === null || typeof item === 'string' || typeof item === 'number' || typeof item === 'boolean') return stringify(item);
|
|
83
|
+
if (typeof item !== 'object') throw new Error('Not an original JSON object.');
|
|
84
|
+
for (let i = 0; i < depth; i++) if (seen[i] === item) throw new Error('Cyclic object.');
|
|
85
|
+
seen[depth++] = item;
|
|
86
|
+
const names = keys(item); let text = '{';
|
|
87
|
+
for (let i = 0; i < names.length; i++) {
|
|
88
|
+
const name = names[i], field = descriptor(item, name);
|
|
89
|
+
if (errorSnapshot && depth === 1 && name !== 'code' && name !== 'message' && name !== 'name') continue;
|
|
90
|
+
if (typeof name !== 'string' || !field || !('value' in field)) throw new Error('Accessor object.');
|
|
91
|
+
text += stringify(name) + ':' + Number(field.enumerable) + Number(field.writable) + Number(field.configurable) + walk(field.value) + ';';
|
|
92
|
+
}
|
|
93
|
+
depth--; return text + '}';
|
|
94
|
+
}
|
|
95
|
+
try { return walk(value); } catch { return ''; }
|
|
96
|
+
};
|
|
97
|
+
})();
|
|
75
98
|
globalThis.__deepFreeze = function deepFreeze(value) {
|
|
76
99
|
if (value && typeof value === 'object' && !Object.isFrozen(value)) {
|
|
77
100
|
for (const item of Object.values(value)) deepFreeze(item);
|
|
@@ -86,6 +109,20 @@ export async function createCodeModeEngine(options) {
|
|
|
86
109
|
const parseJson = vm.getProp(vm.global, '__parseJson');
|
|
87
110
|
const serialize = vm.getProp(vm.global, '__serialize');
|
|
88
111
|
const formatText = vm.getProp(vm.global, '__text');
|
|
112
|
+
const snapshotFunction = vm.getProp(vm.global, '__snapshot');
|
|
113
|
+
const snapshot = (handle, errorSnapshot = false) => {
|
|
114
|
+
const value = vm.callFunction(snapshotFunction, vm.undefined, handle, errorSnapshot ? vm.true : vm.false);
|
|
115
|
+
if (value.error) {
|
|
116
|
+
value.error.dispose();
|
|
117
|
+
return '';
|
|
118
|
+
}
|
|
119
|
+
try {
|
|
120
|
+
return vm.getString(value.value);
|
|
121
|
+
}
|
|
122
|
+
finally {
|
|
123
|
+
value.value.dispose();
|
|
124
|
+
}
|
|
125
|
+
};
|
|
89
126
|
const deepFreeze = vm.getProp(vm.global, '__deepFreeze');
|
|
90
127
|
const parse = (value) => {
|
|
91
128
|
const handle = vm.newString(JSON.stringify(value));
|
|
@@ -142,11 +179,17 @@ export async function createCodeModeEngine(options) {
|
|
|
142
179
|
const deferred = vm.newPromise();
|
|
143
180
|
deferreds.add(deferred);
|
|
144
181
|
const job = Promise.resolve()
|
|
145
|
-
.then(() => input.onToolCall({ name, arguments: parsed.value }))
|
|
182
|
+
.then(() => input.onToolCall({ name, arguments: parsed.value, callId: String(operationId) }))
|
|
146
183
|
.then((output) => {
|
|
147
184
|
if (disposed || input.signal.aborted)
|
|
148
185
|
return;
|
|
149
186
|
const handle = parse(output);
|
|
187
|
+
origins.push({
|
|
188
|
+
handle: handle.dup(),
|
|
189
|
+
snapshot: snapshot(handle),
|
|
190
|
+
errorSnapshot: false,
|
|
191
|
+
operationId: String(operationId)
|
|
192
|
+
});
|
|
150
193
|
try {
|
|
151
194
|
deferred.resolve(handle);
|
|
152
195
|
}
|
|
@@ -163,6 +206,12 @@ export async function createCodeModeEngine(options) {
|
|
|
163
206
|
const code = vm.newString(String(error?.code ?? 'MAR_AGENT_HOST_OPERATION_FAILED'));
|
|
164
207
|
vm.setProp(handle, 'code', code);
|
|
165
208
|
code.dispose();
|
|
209
|
+
origins.push({
|
|
210
|
+
handle: handle.dup(),
|
|
211
|
+
snapshot: snapshot(handle, true),
|
|
212
|
+
errorSnapshot: true,
|
|
213
|
+
operationId: String(operationId)
|
|
214
|
+
});
|
|
166
215
|
try {
|
|
167
216
|
deferred.reject(handle);
|
|
168
217
|
}
|
|
@@ -198,8 +247,28 @@ export async function createCodeModeEngine(options) {
|
|
|
198
247
|
});
|
|
199
248
|
vm.setProp(vm.global, '__consumeToolCall', consumeToolCall);
|
|
200
249
|
consumeToolCall.dispose();
|
|
201
|
-
const
|
|
202
|
-
|
|
250
|
+
const observeValue = (handle, kind) => {
|
|
251
|
+
for (const origin of origins) {
|
|
252
|
+
if (handle &&
|
|
253
|
+
vm.eq(handle, origin.handle) &&
|
|
254
|
+
origin.snapshot &&
|
|
255
|
+
snapshot(handle, origin.errorSnapshot) === origin.snapshot) {
|
|
256
|
+
input.onObserve({ type: 'tool_result', operationId: origin.operationId });
|
|
257
|
+
return vm.undefined;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
if (kind === 'result')
|
|
261
|
+
return {
|
|
262
|
+
error: guestError('MAR_AGENT_TOOL_INPUT_INVALID', 'observe.result requires an unmodified original tool result or error.')
|
|
263
|
+
};
|
|
264
|
+
// A standalone image is a value, never an original tool-result observation.
|
|
265
|
+
if (kind === 'image') {
|
|
266
|
+
const parsed = jsonValue(handle);
|
|
267
|
+
if (parsed.error)
|
|
268
|
+
return parsed;
|
|
269
|
+
input.onObserve({ type: 'image', value: parsed.value });
|
|
270
|
+
return vm.undefined;
|
|
271
|
+
}
|
|
203
272
|
const separatorBytes = textCalls ? 1 : 0;
|
|
204
273
|
const capture = new BoundedTextOutput(Math.max(0, input.limits.outputBytes - outputBytes - separatorBytes), '');
|
|
205
274
|
const emit = vm.newFunction('textChunk', (chunk) => {
|
|
@@ -225,22 +294,23 @@ export async function createCodeModeEngine(options) {
|
|
|
225
294
|
const captured = capture.snapshot();
|
|
226
295
|
outputBytes += captured.retainedBytes + separatorBytes;
|
|
227
296
|
textCalls++;
|
|
228
|
-
input.
|
|
297
|
+
input.onObserve({
|
|
298
|
+
type: 'value',
|
|
299
|
+
format: handle && vm.typeof(handle) === 'object' ? 'json' : 'text',
|
|
300
|
+
value: captured.text,
|
|
301
|
+
originalBytes: captured.originalBytes
|
|
302
|
+
});
|
|
229
303
|
}
|
|
230
304
|
finally {
|
|
231
305
|
result.value.dispose();
|
|
232
306
|
}
|
|
233
307
|
return vm.undefined;
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
return vm.undefined;
|
|
241
|
-
});
|
|
242
|
-
vm.setProp(vm.global, 'out', out);
|
|
243
|
-
out.dispose();
|
|
308
|
+
};
|
|
309
|
+
const observe = vm.newObject();
|
|
310
|
+
for (const kind of ['result', 'text', 'image'])
|
|
311
|
+
method(observe, kind, (handle) => observeValue(handle, kind));
|
|
312
|
+
vm.setProp(vm.global, 'observe', observe);
|
|
313
|
+
observe.dispose();
|
|
244
314
|
const stateObject = vm.newObject();
|
|
245
315
|
method(stateObject, 'get', (keyHandle) => {
|
|
246
316
|
const parsed = key(keyHandle);
|
|
@@ -384,7 +454,7 @@ export async function createCodeModeEngine(options) {
|
|
|
384
454
|
{ code: 'MAR_AGENT_TOOL_NOT_AVAILABLE' }); };
|
|
385
455
|
return target[name];
|
|
386
456
|
}});
|
|
387
|
-
for (const name of ['tools', '
|
|
457
|
+
for (const name of ['tools', 'observe', 'state', 'catalog', 'cell']) {
|
|
388
458
|
const value = globalThis[name];
|
|
389
459
|
Object.freeze(value);
|
|
390
460
|
Object.defineProperty(globalThis, name, {
|
|
@@ -394,6 +464,7 @@ export async function createCodeModeEngine(options) {
|
|
|
394
464
|
delete globalThis.__parseJson;
|
|
395
465
|
delete globalThis.__serialize;
|
|
396
466
|
delete globalThis.__text;
|
|
467
|
+
delete globalThis.__snapshot;
|
|
397
468
|
delete globalThis.__deepFreeze;
|
|
398
469
|
delete globalThis.__consumeToolCall;
|
|
399
470
|
`);
|
|
@@ -449,6 +520,9 @@ export async function createCodeModeEngine(options) {
|
|
|
449
520
|
parseJson.dispose();
|
|
450
521
|
serialize.dispose();
|
|
451
522
|
formatText.dispose();
|
|
523
|
+
snapshotFunction.dispose();
|
|
524
|
+
for (const origin of origins)
|
|
525
|
+
origin.handle.dispose();
|
|
452
526
|
deepFreeze.dispose();
|
|
453
527
|
}
|
|
454
528
|
},
|
|
@@ -528,7 +602,7 @@ function streamText(value, emit) {
|
|
|
528
602
|
emit('{');
|
|
529
603
|
let first = true;
|
|
530
604
|
const names = Object.keys(item);
|
|
531
|
-
// Special-case view_image and native MCP image objects: text omits Base64;
|
|
605
|
+
// Special-case view_image and native MCP image objects: text omits Base64; observe.image keeps pixels.
|
|
532
606
|
const imagePayload = names.includes('mimeType') &&
|
|
533
607
|
typeof item.mimeType === 'string' &&
|
|
534
608
|
item.mimeType.startsWith('image/');
|
|
@@ -542,7 +616,7 @@ function streamText(value, emit) {
|
|
|
542
616
|
write(imagePayload &&
|
|
543
617
|
(name === 'dataBase64' || (name === 'data' && item.type === 'image')) &&
|
|
544
618
|
typeof field === 'string'
|
|
545
|
-
? '[image payload omitted; use
|
|
619
|
+
? '[image payload omitted; use observe.image]'
|
|
546
620
|
: field, name);
|
|
547
621
|
}
|
|
548
622
|
emit('}');
|
|
@@ -1,15 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
readonly value: unknown;
|
|
4
|
-
}
|
|
5
|
-
export type CodeModeStateMutation = {
|
|
6
|
-
readonly operation: 'set';
|
|
7
|
-
readonly key: string;
|
|
8
|
-
readonly value: unknown;
|
|
9
|
-
} | {
|
|
10
|
-
readonly operation: 'delete';
|
|
11
|
-
readonly key: string;
|
|
12
|
-
};
|
|
1
|
+
import type { CodeModeStateEntry, CodeModeStateMutation } from '../contracts.js';
|
|
2
|
+
export type { CodeModeStateEntry, CodeModeStateMutation } from '../contracts.js';
|
|
13
3
|
type StateRecord = {
|
|
14
4
|
readonly type: string;
|
|
15
5
|
readonly payload: unknown;
|
|
@@ -17,4 +7,3 @@ type StateRecord = {
|
|
|
17
7
|
export declare function parseCodeModeStateMutations(value: unknown): CodeModeStateMutation[];
|
|
18
8
|
export declare function restoreCodeModeState(records: readonly StateRecord[]): CodeModeStateEntry[];
|
|
19
9
|
export declare function applyCodeModeStateMutations(entries: readonly CodeModeStateEntry[], mutations: readonly CodeModeStateMutation[]): CodeModeStateEntry[];
|
|
20
|
-
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -34,10 +34,17 @@ lines.on('line', async (line) => {
|
|
|
34
34
|
onText: (value, originalBytes) => send({ kind: 'text', value, originalBytes }),
|
|
35
35
|
onImage: (value) => send({ kind: 'image', value }),
|
|
36
36
|
onYield: () => send({ kind: 'yield' }),
|
|
37
|
+
onObserve: (value) => send({ kind: 'observe', observation: value }),
|
|
37
38
|
onToolCall: (call) => new Promise((resolve, reject) => {
|
|
38
39
|
const id = ++sequence;
|
|
39
40
|
pending.set(id, { resolve, reject });
|
|
40
|
-
send({
|
|
41
|
+
send({
|
|
42
|
+
kind: 'call',
|
|
43
|
+
id,
|
|
44
|
+
operationId: call.callId,
|
|
45
|
+
name: call.name,
|
|
46
|
+
arguments: call.arguments
|
|
47
|
+
});
|
|
41
48
|
})
|
|
42
49
|
});
|
|
43
50
|
if (pending.size)
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import type { ExecutionMode } from '../runtime/contracts.js';
|
|
2
|
+
export type ToolCaller = 'direct' | 'programmatic';
|
|
3
|
+
export interface ClientToolDefinition {
|
|
4
|
+
name: string;
|
|
5
|
+
description: string;
|
|
6
|
+
inputSchema: Record<string, unknown>;
|
|
7
|
+
/** Runtime-only provider lowering hint; unsupported adapters fall back to a normal function tool. */
|
|
8
|
+
nativeType?: 'tool_search';
|
|
9
|
+
/** Runtime-only result contract; never forwarded as an upstream tool field. */
|
|
10
|
+
outputSchema?: Record<string, unknown>;
|
|
11
|
+
/** Runtime-only policy. MCP defaults to both callers; other tools default to direct only. */
|
|
12
|
+
allowedCallers?: readonly ToolCaller[];
|
|
13
|
+
inputMode?: 'json' | 'freeform';
|
|
14
|
+
parallelSafety?: 'safe' | 'serial';
|
|
15
|
+
/** Runtime-only Agent catalog scope; never forwarded as an upstream tool field. */
|
|
16
|
+
agentScope?: 'ROOT_AND_SUBAGENTS' | 'ROOT_ONLY';
|
|
17
|
+
}
|
|
18
|
+
export interface ToolCall {
|
|
19
|
+
name: string;
|
|
20
|
+
arguments: unknown;
|
|
21
|
+
callId?: string;
|
|
22
|
+
}
|
|
23
|
+
export interface ToolExecutionContext {
|
|
24
|
+
mode: ExecutionMode;
|
|
25
|
+
signal: AbortSignal;
|
|
26
|
+
sessionId: string;
|
|
27
|
+
executionId: string;
|
|
28
|
+
recentImages?: readonly {
|
|
29
|
+
readonly mimeType: string;
|
|
30
|
+
readonly data: Buffer;
|
|
31
|
+
}[];
|
|
32
|
+
codeMode?: {
|
|
33
|
+
retainSession?(): Promise<() => Promise<void>>;
|
|
34
|
+
onSettled?(result: CodeCellEventData): Promise<void>;
|
|
35
|
+
supportsImages?: boolean;
|
|
36
|
+
tools: readonly ClientToolDefinition[];
|
|
37
|
+
state?: readonly CodeModeStateEntry[];
|
|
38
|
+
commitState?(mutations: readonly CodeModeStateMutation[]): Promise<readonly CodeModeStateEntry[]>;
|
|
39
|
+
invoke(call: ToolCall, signal: AbortSignal): Promise<ToolExecutionResult>;
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
export interface McpToolCatalogContext extends Pick<ToolExecutionContext, 'sessionId' | 'executionId'> {
|
|
43
|
+
executionScopeId?: string;
|
|
44
|
+
claimExecutionScope?: boolean;
|
|
45
|
+
}
|
|
46
|
+
export interface McpToolCatalog {
|
|
47
|
+
readonly revision: string;
|
|
48
|
+
readonly servers: readonly {
|
|
49
|
+
readonly id: string;
|
|
50
|
+
readonly name: string;
|
|
51
|
+
readonly description?: string;
|
|
52
|
+
readonly instructions?: string;
|
|
53
|
+
}[];
|
|
54
|
+
readonly tools: readonly McpCatalogTool[];
|
|
55
|
+
}
|
|
56
|
+
export interface McpCatalogTool {
|
|
57
|
+
readonly definition: ClientToolDefinition;
|
|
58
|
+
readonly serverId: string;
|
|
59
|
+
readonly rawName: string;
|
|
60
|
+
readonly sourceIdentity: string;
|
|
61
|
+
readonly definitionRevision: string;
|
|
62
|
+
readonly lifetime: 'session' | 'execution';
|
|
63
|
+
readonly exposure: 'direct' | 'deferred';
|
|
64
|
+
/** Untrusted MCP hints; never an authorization or parallel-safety decision. */
|
|
65
|
+
readonly annotations?: Readonly<Record<string, unknown>>;
|
|
66
|
+
}
|
|
67
|
+
export interface McpToolCallContext extends Pick<ToolExecutionContext, 'sessionId' | 'executionId'> {
|
|
68
|
+
readonly mode?: ExecutionMode;
|
|
69
|
+
readonly expectedTool?: {
|
|
70
|
+
readonly sourceIdentity: string;
|
|
71
|
+
readonly definitionRevision: string;
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
export interface MarAgentToolImageArtifact {
|
|
75
|
+
kind: 'image';
|
|
76
|
+
name: string;
|
|
77
|
+
mimeType: 'image/png';
|
|
78
|
+
byteSize: number;
|
|
79
|
+
sha256: string;
|
|
80
|
+
fileName: string;
|
|
81
|
+
}
|
|
82
|
+
export type MarAgentToolArtifact = MarAgentToolImageArtifact;
|
|
83
|
+
export interface ToolExecutionResult {
|
|
84
|
+
calls?: readonly import('./code-mode/observations.js').CodeToolCallRecord[];
|
|
85
|
+
content: string;
|
|
86
|
+
observations?: readonly import('./code-mode/observations.js').CodeObservation[];
|
|
87
|
+
data?: unknown;
|
|
88
|
+
/** Runtime-only definitions used to encode a Tool Search output. */
|
|
89
|
+
toolSearchTools?: readonly ClientToolDefinition[];
|
|
90
|
+
truncated?: boolean;
|
|
91
|
+
images?: readonly {
|
|
92
|
+
mimeType: string;
|
|
93
|
+
dataBase64: string;
|
|
94
|
+
}[];
|
|
95
|
+
artifacts?: readonly MarAgentToolArtifact[];
|
|
96
|
+
}
|
|
97
|
+
export interface CodeCellEventData {
|
|
98
|
+
calls?: readonly import('./code-mode/observations.js').CodeToolCallRecord[];
|
|
99
|
+
cellId: string;
|
|
100
|
+
status: 'running' | 'completed' | 'failed' | 'cancelled';
|
|
101
|
+
cached?: boolean;
|
|
102
|
+
observations?: readonly import('./code-mode/observations.js').CodeObservation[];
|
|
103
|
+
}
|
|
104
|
+
export interface ExecResult {
|
|
105
|
+
status: 'running' | 'completed' | 'cancelled';
|
|
106
|
+
processId?: string;
|
|
107
|
+
stdout: string;
|
|
108
|
+
stderr: string;
|
|
109
|
+
exitCode?: number | null;
|
|
110
|
+
truncated: boolean;
|
|
111
|
+
stdoutBytes: number;
|
|
112
|
+
stderrBytes: number;
|
|
113
|
+
stdoutDroppedBytes: number;
|
|
114
|
+
stderrDroppedBytes: number;
|
|
115
|
+
/** A terminal snapshot replay rather than new process output. */
|
|
116
|
+
cached?: boolean;
|
|
117
|
+
}
|
|
118
|
+
export interface ApplyPatchFileResult {
|
|
119
|
+
path: string;
|
|
120
|
+
targetPath?: string;
|
|
121
|
+
operation: 'added' | 'modified' | 'deleted' | 'moved';
|
|
122
|
+
addedLines: number;
|
|
123
|
+
deletedLines: number;
|
|
124
|
+
}
|
|
125
|
+
export interface ApplyPatchResult {
|
|
126
|
+
files: ApplyPatchFileResult[];
|
|
127
|
+
totals: {
|
|
128
|
+
files: number;
|
|
129
|
+
addedLines: number;
|
|
130
|
+
deletedLines: number;
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
export interface ReadEventData {
|
|
134
|
+
mode: 'batch';
|
|
135
|
+
results: Array<{
|
|
136
|
+
path: string;
|
|
137
|
+
startLine?: number;
|
|
138
|
+
endLine?: number;
|
|
139
|
+
error?: {
|
|
140
|
+
code: string;
|
|
141
|
+
message: string;
|
|
142
|
+
};
|
|
143
|
+
}>;
|
|
144
|
+
truncated: boolean;
|
|
145
|
+
}
|
|
146
|
+
export interface ViewImageResult {
|
|
147
|
+
path: string;
|
|
148
|
+
mimeType: 'image/png' | 'image/jpeg' | 'image/webp';
|
|
149
|
+
bytes: number;
|
|
150
|
+
sha256: string;
|
|
151
|
+
}
|
|
152
|
+
export interface TodoItem {
|
|
153
|
+
id: string;
|
|
154
|
+
step: string;
|
|
155
|
+
status: 'pending' | 'in_progress' | 'completed';
|
|
156
|
+
}
|
|
157
|
+
export interface TodoSnapshot {
|
|
158
|
+
revision: number;
|
|
159
|
+
items: TodoItem[];
|
|
160
|
+
}
|
|
161
|
+
export interface CodeModeStateEntry {
|
|
162
|
+
readonly key: string;
|
|
163
|
+
readonly value: unknown;
|
|
164
|
+
}
|
|
165
|
+
export type CodeModeStateMutation = {
|
|
166
|
+
readonly operation: 'set';
|
|
167
|
+
readonly key: string;
|
|
168
|
+
readonly value: unknown;
|
|
169
|
+
} | {
|
|
170
|
+
readonly operation: 'delete';
|
|
171
|
+
readonly key: string;
|
|
172
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { ModelEvent } from '../model/contracts.js';
|
|
2
|
+
import type { EventPayload } from '../runtime/events.js';
|
|
3
|
+
import type { ClientToolDefinition, McpToolCallContext, ToolExecutionContext, ToolExecutionResult } from './contracts.js';
|
|
4
|
+
import type { ToolRuntimeContext, ToolRuntimeImage } from './runtime-context.js';
|
|
5
|
+
import { type createSessionToolScheduler } from './scheduler.js';
|
|
6
|
+
export type ClientToolCall = Extract<ModelEvent, {
|
|
7
|
+
type: 'client_tool.call';
|
|
8
|
+
}>;
|
|
9
|
+
export type ExecutedToolCall = {
|
|
10
|
+
call: ClientToolCall;
|
|
11
|
+
content: string;
|
|
12
|
+
images?: ToolExecutionResult['images'];
|
|
13
|
+
observations?: ToolExecutionResult['observations'];
|
|
14
|
+
calls?: ToolExecutionResult['calls'];
|
|
15
|
+
} & ({
|
|
16
|
+
failed: false;
|
|
17
|
+
output: ToolExecutionResult;
|
|
18
|
+
} | {
|
|
19
|
+
failed: true;
|
|
20
|
+
error: unknown;
|
|
21
|
+
});
|
|
22
|
+
/** One immutable model round's catalog; execution resources remain owned by the SDK/Host. */
|
|
23
|
+
export interface RoundToolScope {
|
|
24
|
+
readonly context: Omit<ToolRuntimeContext, 'codeMode' | 'expectedMcpTool' | 'searchMcpTools' | 'recentImages'>;
|
|
25
|
+
readonly tools: readonly ClientToolDefinition[];
|
|
26
|
+
readonly expectations: ReadonlyMap<string, McpToolCallContext['expectedTool']>;
|
|
27
|
+
readonly extensionToolNames: ReadonlySet<string>;
|
|
28
|
+
readonly schedule: ReturnType<typeof createSessionToolScheduler>;
|
|
29
|
+
readonly emit: (event: EventPayload) => Promise<void>;
|
|
30
|
+
readonly searchMcpTools: NonNullable<ToolRuntimeContext['searchMcpTools']>;
|
|
31
|
+
readonly recentImages: () => ToolRuntimeImage[];
|
|
32
|
+
readonly captureCodeContext: () => Omit<ToolRuntimeContext, 'signal' | 'codeMode' | 'expectedMcpTool' | 'searchMcpTools'>;
|
|
33
|
+
readonly codeModeContext: (call: ClientToolCall) => Promise<Omit<NonNullable<ToolExecutionContext['codeMode']>, 'invoke'>>;
|
|
34
|
+
}
|
|
35
|
+
/** Complete every call in model order even if individual execution fails. */
|
|
36
|
+
export declare function executeRoundTools(calls: readonly ClientToolCall[], scope: RoundToolScope): Promise<ExecutedToolCall[]>;
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { MarAgentError, describeMarAgentError } from '../error.js';
|
|
2
|
+
import { AGENT_EXECUTION_POLICY } from '../runtime/execution-policy.js';
|
|
3
|
+
import { allowsToolCaller } from './callers.js';
|
|
4
|
+
import { CodeCellExecutionError } from './code-mode/cells.js';
|
|
5
|
+
import { createCodeToolDispatch } from './code-mode/dispatch.js';
|
|
6
|
+
import { boundedModelToolOutput, structuredToolArtifacts, structuredToolEventData } from './output-projection.js';
|
|
7
|
+
import { executeRegisteredTool } from './runtime.js';
|
|
8
|
+
import { scheduleToolCallBatch } from './scheduler.js';
|
|
9
|
+
/** Complete every call in model order even if individual execution fails. */
|
|
10
|
+
export async function executeRoundTools(calls, scope) {
|
|
11
|
+
const executeCall = async (call, signal = scope.context.signal, caller = 'direct', parentCallId) => {
|
|
12
|
+
await scope.emit({
|
|
13
|
+
type: 'tool.started',
|
|
14
|
+
toolName: call.name,
|
|
15
|
+
callId: call.callId,
|
|
16
|
+
...(parentCallId === undefined ? {} : { parentCallId }),
|
|
17
|
+
input: call.arguments
|
|
18
|
+
});
|
|
19
|
+
try {
|
|
20
|
+
if (call.argumentError)
|
|
21
|
+
throw new MarAgentError('MAR_AGENT_TOOL_INPUT_INVALID', call.argumentError);
|
|
22
|
+
if (!scope.tools.some((tool) => tool.name === call.name && allowsToolCaller(tool, caller)))
|
|
23
|
+
throw new MarAgentError('MAR_AGENT_TOOL_NOT_AVAILABLE', 'Tool is unavailable in this execution.');
|
|
24
|
+
const codeMode = await scope.codeModeContext(call);
|
|
25
|
+
const runTool = () => {
|
|
26
|
+
signal.throwIfAborted();
|
|
27
|
+
return executeRegisteredTool(call.name, call.arguments, call.callId, {
|
|
28
|
+
...scope.context,
|
|
29
|
+
...(scope.expectations.get(call.name)
|
|
30
|
+
? { expectedMcpTool: scope.expectations.get(call.name) }
|
|
31
|
+
: {}),
|
|
32
|
+
searchMcpTools: scope.searchMcpTools,
|
|
33
|
+
signal,
|
|
34
|
+
codeMode: {
|
|
35
|
+
...codeMode,
|
|
36
|
+
invoke: createCodeToolDispatch({
|
|
37
|
+
context: scope.captureCodeContext(),
|
|
38
|
+
tools: scope.tools,
|
|
39
|
+
expectations: scope.expectations,
|
|
40
|
+
parentCallId: call.callId,
|
|
41
|
+
schedule: scope.schedule,
|
|
42
|
+
emit: scope.emit
|
|
43
|
+
})
|
|
44
|
+
},
|
|
45
|
+
...(scope.extensionToolNames.has(call.name) ? { recentImages: scope.recentImages() } : {})
|
|
46
|
+
});
|
|
47
|
+
};
|
|
48
|
+
const output = call.name === 'code_exec' || call.name === 'code_exec_wait'
|
|
49
|
+
? await runTool()
|
|
50
|
+
: await scope.schedule(scope.tools.find((tool) => tool.name === call.name), runTool);
|
|
51
|
+
const modelOutput = boundedModelToolOutput(call.name, output.content, output.data);
|
|
52
|
+
const eventSummary = output.content.slice(0, AGENT_EXECUTION_POLICY.toolEventSummaryCharacters);
|
|
53
|
+
const structuredData = structuredToolEventData(call.name, output.data);
|
|
54
|
+
const artifacts = structuredToolArtifacts(output.artifacts);
|
|
55
|
+
await scope.emit({
|
|
56
|
+
type: 'tool.completed',
|
|
57
|
+
toolName: call.name,
|
|
58
|
+
callId: call.callId,
|
|
59
|
+
...(parentCallId === undefined ? {} : { parentCallId }),
|
|
60
|
+
summary: eventSummary,
|
|
61
|
+
truncated: output.truncated === true ||
|
|
62
|
+
modelOutput.truncated ||
|
|
63
|
+
eventSummary.length < output.content.length,
|
|
64
|
+
...(artifacts === undefined ? {} : { artifacts }),
|
|
65
|
+
...(structuredData === undefined ? {} : { data: structuredData })
|
|
66
|
+
});
|
|
67
|
+
return {
|
|
68
|
+
call,
|
|
69
|
+
output,
|
|
70
|
+
content: modelOutput.content,
|
|
71
|
+
...(output.calls ? { calls: output.calls } : {}),
|
|
72
|
+
...(output.observations ? { observations: output.observations } : {}),
|
|
73
|
+
...(output.images?.length ? { images: output.images } : {}),
|
|
74
|
+
failed: false
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
catch (error) {
|
|
78
|
+
const diagnostic = describeMarAgentError(error, 'MAR_AGENT_HOST_OPERATION_FAILED');
|
|
79
|
+
const partial = error instanceof CodeCellExecutionError ? error.result : undefined;
|
|
80
|
+
await scope.emit({
|
|
81
|
+
type: 'tool.failed',
|
|
82
|
+
toolName: call.name,
|
|
83
|
+
callId: call.callId,
|
|
84
|
+
...(parentCallId === undefined ? {} : { parentCallId }),
|
|
85
|
+
code: diagnostic.code,
|
|
86
|
+
message: diagnostic.message,
|
|
87
|
+
...(partial?.data === undefined
|
|
88
|
+
? {}
|
|
89
|
+
: {
|
|
90
|
+
data: structuredToolEventData(call.name, partial.data)
|
|
91
|
+
})
|
|
92
|
+
});
|
|
93
|
+
return {
|
|
94
|
+
call,
|
|
95
|
+
content: partial === undefined
|
|
96
|
+
? JSON.stringify({
|
|
97
|
+
error: diagnostic.code,
|
|
98
|
+
message: diagnostic.message,
|
|
99
|
+
...(error instanceof MarAgentError && error.retryable ? { retryable: true } : {})
|
|
100
|
+
})
|
|
101
|
+
: boundedModelToolOutput(call.name, partial.content, partial.data).content,
|
|
102
|
+
...(partial?.images?.length ? { images: partial.images } : {}),
|
|
103
|
+
failed: true,
|
|
104
|
+
...(partial?.calls ? { calls: partial.calls } : {}),
|
|
105
|
+
...(partial?.observations ? { observations: partial.observations } : {}),
|
|
106
|
+
error
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
return scheduleToolCallBatch(calls, scope.tools, executeCall);
|
|
111
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { ClientToolDefinition } from '../../model/contracts.js';
|
|
2
|
+
import type { ApplyPatchResult } from '../contracts.js';
|
|
3
|
+
import { WorkspacePathResolver } from '../shared/path-resolver.js';
|
|
4
|
+
export type { ApplyPatchFileResult, ApplyPatchResult } from '../contracts.js';
|
|
5
|
+
export declare const applyPatchToolDefinition: ClientToolDefinition;
|
|
6
|
+
export declare function applyPatchToolInput(input: unknown): string;
|
|
7
|
+
interface PatchFileOperations {
|
|
8
|
+
rename(source: string, target: string): Promise<void>;
|
|
9
|
+
rm(path: string, options?: {
|
|
10
|
+
force?: boolean;
|
|
11
|
+
recursive?: boolean;
|
|
12
|
+
}): Promise<void>;
|
|
13
|
+
}
|
|
14
|
+
export declare class ApplyPatchTool {
|
|
15
|
+
#private;
|
|
16
|
+
private readonly paths;
|
|
17
|
+
constructor(paths: WorkspacePathResolver, operations?: Partial<PatchFileOperations>);
|
|
18
|
+
execute(patch: string): Promise<ApplyPatchResult>;
|
|
19
|
+
}
|
|
@@ -2,8 +2,8 @@ import { randomUUID } from 'node:crypto';
|
|
|
2
2
|
import { chmod, lstat, mkdir, readFile, rename, rm, rmdir, writeFile } from 'node:fs/promises';
|
|
3
3
|
import { dirname, isAbsolute, parse, resolve } from 'node:path';
|
|
4
4
|
import { TextDecoder } from 'node:util';
|
|
5
|
-
import { MarAgentError } from '
|
|
6
|
-
import { TOOL_EXECUTION_LIMITS } from '
|
|
5
|
+
import { MarAgentError } from '../../error.js';
|
|
6
|
+
import { TOOL_EXECUTION_LIMITS } from '../execution-limits.js';
|
|
7
7
|
export const applyPatchToolDefinition = {
|
|
8
8
|
name: 'apply_patch',
|
|
9
9
|
allowedCallers: ['direct', 'programmatic'],
|
|
@@ -53,6 +53,12 @@ export const applyPatchToolDefinition = {
|
|
|
53
53
|
additionalProperties: false
|
|
54
54
|
}
|
|
55
55
|
};
|
|
56
|
+
export function applyPatchToolInput(input) {
|
|
57
|
+
const patch = typeof input === 'string' ? input : input?.patch;
|
|
58
|
+
if (typeof patch !== 'string')
|
|
59
|
+
throw new MarAgentError('MAR_AGENT_TOOL_INPUT_INVALID', 'Patch is required.');
|
|
60
|
+
return patch;
|
|
61
|
+
}
|
|
56
62
|
const defaultFileOperations = { rename, rm };
|
|
57
63
|
const utf8Decoder = new TextDecoder('utf-8', { fatal: true });
|
|
58
64
|
export class ApplyPatchTool {
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { type LocalProcessExecutor } from '../../host/local-process-executor.js';
|
|
2
|
+
import type { ClientToolDefinition } from '../../model/contracts.js';
|
|
3
|
+
import type { ExecResult } from '../contracts.js';
|
|
4
|
+
import { WorkspacePathResolver } from '../shared/path-resolver.js';
|
|
5
|
+
export type { ExecResult } from '../contracts.js';
|
|
4
6
|
export type ExecInput = {
|
|
5
7
|
action?: 'start';
|
|
6
8
|
command: string;
|
|
@@ -19,20 +21,6 @@ export type ExecInput = {
|
|
|
19
21
|
action: 'cancel';
|
|
20
22
|
processId: string;
|
|
21
23
|
};
|
|
22
|
-
export interface ExecResult {
|
|
23
|
-
status: 'running' | 'completed' | 'cancelled';
|
|
24
|
-
processId?: string;
|
|
25
|
-
stdout: string;
|
|
26
|
-
stderr: string;
|
|
27
|
-
exitCode?: number | null;
|
|
28
|
-
truncated: boolean;
|
|
29
|
-
stdoutBytes: number;
|
|
30
|
-
stderrBytes: number;
|
|
31
|
-
stdoutDroppedBytes: number;
|
|
32
|
-
stderrDroppedBytes: number;
|
|
33
|
-
/** A terminal snapshot replay rather than new process output. */
|
|
34
|
-
cached?: boolean;
|
|
35
|
-
}
|
|
36
24
|
export declare const execToolDefinition: ClientToolDefinition;
|
|
37
25
|
export declare const execWaitToolDefinition: ClientToolDefinition;
|
|
38
26
|
/** Validate the public entry points before delegating to the single process manager. */
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { directLocalProcessExecutor, signalProcessTree } from '../host/local-process-executor.js';
|
|
2
1
|
import { randomUUID } from 'node:crypto';
|
|
3
2
|
import { StringDecoder } from 'node:string_decoder';
|
|
4
|
-
import { MarAgentError } from '
|
|
5
|
-
import {
|
|
3
|
+
import { MarAgentError } from '../../error.js';
|
|
4
|
+
import { directLocalProcessExecutor, signalProcessTree } from '../../host/local-process-executor.js';
|
|
5
|
+
import { TOOL_EXECUTION_LIMITS } from '../execution-limits.js';
|
|
6
6
|
export const execToolDefinition = {
|
|
7
7
|
name: 'exec',
|
|
8
8
|
allowedCallers: ['direct', 'programmatic'],
|
|
9
9
|
parallelSafety: 'safe',
|
|
10
|
-
description: 'Start a platform-native command, script, or program in workspace/default cwd. Returns a stable processId, status, bounded stdout/stderr, cumulative byte counts, dropped-byte counts, exitCode and truncated. A completed status does not imply exitCode 0; inspect stderr/exitCode. For subsequent waiting, stdin writes or cancellation,
|
|
10
|
+
description: 'Start a platform-native command, script, or program in workspace/default cwd. Returns a stable processId, status, bounded stdout/stderr, cumulative byte counts, dropped-byte counts, exitCode and truncated. A completed status does not imply exitCode 0; inspect stderr/exitCode. For subsequent waiting, stdin writes or cancellation, call exec_wait directly with processId, not exec. Truncation does not stop the process. Cancelling the initial wait does not terminate the process.',
|
|
11
11
|
outputSchema: {
|
|
12
12
|
type: 'object',
|
|
13
13
|
required: ['content', 'data'],
|