@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
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import type { ClientToolDefinition } from '
|
|
2
|
-
import { WorkspacePathResolver } from '
|
|
1
|
+
import type { ClientToolDefinition } from '../../model/contracts.js';
|
|
2
|
+
import { WorkspacePathResolver } from '../shared/path-resolver.js';
|
|
3
|
+
export type { ReadEventData } from '../contracts.js';
|
|
3
4
|
export declare const readToolDefinition: ClientToolDefinition;
|
|
4
5
|
export interface ReadRequest {
|
|
5
6
|
path: string;
|
|
@@ -30,22 +31,13 @@ export interface BatchReadResult {
|
|
|
30
31
|
results: Array<ReadResult | ReadErrorResult>;
|
|
31
32
|
truncated: boolean;
|
|
32
33
|
}
|
|
33
|
-
export interface ReadEventData {
|
|
34
|
-
mode: 'batch';
|
|
35
|
-
results: Array<{
|
|
36
|
-
path: string;
|
|
37
|
-
startLine?: number;
|
|
38
|
-
endLine?: number;
|
|
39
|
-
error?: {
|
|
40
|
-
code: string;
|
|
41
|
-
message: string;
|
|
42
|
-
};
|
|
43
|
-
}>;
|
|
44
|
-
truncated: boolean;
|
|
45
|
-
}
|
|
46
34
|
export declare class ReadTool {
|
|
47
35
|
#private;
|
|
48
36
|
private readonly paths;
|
|
49
37
|
constructor(paths: WorkspacePathResolver);
|
|
50
38
|
execute(arguments_: unknown, signal?: AbortSignal): Promise<BatchReadResult>;
|
|
51
39
|
}
|
|
40
|
+
export declare function formatBatchReadOutput(results: Array<ReadResult | ReadErrorResult>): {
|
|
41
|
+
content: string;
|
|
42
|
+
truncated: boolean;
|
|
43
|
+
};
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
import { AGENT_EXECUTION_POLICY } from '../../runtime/execution-policy.js';
|
|
2
|
+
import { modelTokenBudgetBytes } from '../../runtime/token-budget.js';
|
|
1
3
|
import { createReadStream } from 'node:fs';
|
|
2
4
|
import { lstat, open } from 'node:fs/promises';
|
|
3
5
|
import { TextDecoder } from 'node:util';
|
|
4
|
-
import { MarAgentError } from '
|
|
5
|
-
import { TOOL_EXECUTION_LIMITS } from '
|
|
6
|
+
import { MarAgentError } from '../../error.js';
|
|
7
|
+
import { TOOL_EXECUTION_LIMITS } from '../execution-limits.js';
|
|
6
8
|
export const readToolDefinition = {
|
|
7
9
|
name: 'read',
|
|
8
10
|
allowedCallers: ['direct', 'programmatic'],
|
|
@@ -293,3 +295,184 @@ function readError(path, error) {
|
|
|
293
295
|
function invalidReadInput() {
|
|
294
296
|
throw new MarAgentError('MAR_AGENT_TOOL_INPUT_INVALID', 'Read input is invalid.');
|
|
295
297
|
}
|
|
298
|
+
function escapeAttribute(value) {
|
|
299
|
+
return value.replaceAll('&', '&').replaceAll('"', '"').replaceAll('<', '<');
|
|
300
|
+
}
|
|
301
|
+
function escapeText(value) {
|
|
302
|
+
return value.replaceAll('&', '&').replaceAll('<', '<');
|
|
303
|
+
}
|
|
304
|
+
function boundedUtf8Prefix(value, maximumBytes) {
|
|
305
|
+
if (Buffer.byteLength(value) <= maximumBytes)
|
|
306
|
+
return { value, truncated: false };
|
|
307
|
+
const marker = '…';
|
|
308
|
+
const contentBudget = Math.max(0, maximumBytes - Buffer.byteLength(marker));
|
|
309
|
+
let result = '';
|
|
310
|
+
let bytes = 0;
|
|
311
|
+
for (const character of value) {
|
|
312
|
+
const characterBytes = Buffer.byteLength(character);
|
|
313
|
+
if (bytes + characterBytes > contentBudget)
|
|
314
|
+
break;
|
|
315
|
+
result += character;
|
|
316
|
+
bytes += characterBytes;
|
|
317
|
+
}
|
|
318
|
+
return { value: `${result}${marker}`, truncated: true };
|
|
319
|
+
}
|
|
320
|
+
function oversizedLinePreview(value, retainedBytes, lineNumber) {
|
|
321
|
+
const bytes = Buffer.from(value, 'utf8');
|
|
322
|
+
if (retainedBytes >= bytes.length)
|
|
323
|
+
return { value, shownBytes: bytes.length, omittedBytes: 0 };
|
|
324
|
+
const headTarget = Math.floor(retainedBytes / 2);
|
|
325
|
+
const tailTarget = retainedBytes - headTarget;
|
|
326
|
+
let head = Math.min(headTarget, bytes.length);
|
|
327
|
+
while (head > 0 && isUtf8ContinuationByte(bytes[head]))
|
|
328
|
+
head--;
|
|
329
|
+
let tail = Math.max(head, bytes.length - tailTarget);
|
|
330
|
+
while (tail < bytes.length && isUtf8ContinuationByte(bytes[tail]))
|
|
331
|
+
tail++;
|
|
332
|
+
const shownBytes = head + bytes.length - tail;
|
|
333
|
+
const omittedBytes = bytes.length - shownBytes;
|
|
334
|
+
const marker = `...[${omittedBytes} bytes omitted from line ${lineNumber}]...`;
|
|
335
|
+
return {
|
|
336
|
+
value: `${bytes.toString('utf8', 0, head)}${marker}${bytes.toString('utf8', tail)}`,
|
|
337
|
+
shownBytes,
|
|
338
|
+
omittedBytes
|
|
339
|
+
};
|
|
340
|
+
}
|
|
341
|
+
function isUtf8ContinuationByte(value) {
|
|
342
|
+
return value !== undefined && (value & 0xc0) === 0x80;
|
|
343
|
+
}
|
|
344
|
+
function formatBatchReadResult(result, index, maximumBytes) {
|
|
345
|
+
const visiblePath = boundedUtf8Prefix(result.path, 128);
|
|
346
|
+
const path = escapeAttribute(visiblePath.value);
|
|
347
|
+
const pathTruncatedAttribute = visiblePath.truncated ? ' pathTruncated="true"' : '';
|
|
348
|
+
if ('error' in result) {
|
|
349
|
+
const message = boundedUtf8Prefix(result.error.message, 256);
|
|
350
|
+
const detailsTruncatedAttribute = message.truncated ? ' detailsTruncated="true"' : '';
|
|
351
|
+
const content = `<read_error index="${index}" path="${path}"${pathTruncatedAttribute} code="${escapeAttribute(result.error.code)}"${detailsTruncatedAttribute}>${escapeText(message.value)}</read_error>`;
|
|
352
|
+
if (Buffer.byteLength(content) <= maximumBytes)
|
|
353
|
+
return { content, previewComplete: true };
|
|
354
|
+
return {
|
|
355
|
+
content: `<read_error index="${index}" code="MAR_AGENT_TOOL_OUTPUT_LIMIT">Model-visible error metadata exceeds this item's output share.</read_error>`,
|
|
356
|
+
previewComplete: false
|
|
357
|
+
};
|
|
358
|
+
}
|
|
359
|
+
const lines = result.content ? result.content.split('\n') : [];
|
|
360
|
+
const render = (visibleLines) => {
|
|
361
|
+
const previewComplete = visibleLines === lines.length;
|
|
362
|
+
const endLine = visibleLines === 0 ? undefined : result.startLine + Math.max(0, visibleLines - 1);
|
|
363
|
+
const metadata = {
|
|
364
|
+
path: visiblePath.value,
|
|
365
|
+
...(visiblePath.truncated ? { pathTruncated: true } : {}),
|
|
366
|
+
encoding: result.encoding,
|
|
367
|
+
newline: result.newline,
|
|
368
|
+
startLine: result.startLine,
|
|
369
|
+
...(endLine === undefined ? {} : { endLine }),
|
|
370
|
+
eof: previewComplete ? result.eof : false,
|
|
371
|
+
truncated: previewComplete ? result.truncated : true,
|
|
372
|
+
...(previewComplete
|
|
373
|
+
? result.nextOffset === undefined
|
|
374
|
+
? {}
|
|
375
|
+
: { nextOffset: result.nextOffset }
|
|
376
|
+
: { nextOffset: result.startLine + visibleLines }),
|
|
377
|
+
previewComplete
|
|
378
|
+
};
|
|
379
|
+
return [
|
|
380
|
+
`<read_result index="${index}" path="${path}"${pathTruncatedAttribute}>`,
|
|
381
|
+
lines.slice(0, visibleLines).join('\n'),
|
|
382
|
+
`<read_metadata>${JSON.stringify(metadata)}</read_metadata>`,
|
|
383
|
+
'</read_result>'
|
|
384
|
+
]
|
|
385
|
+
.filter(Boolean)
|
|
386
|
+
.join('\n');
|
|
387
|
+
};
|
|
388
|
+
const full = render(lines.length);
|
|
389
|
+
if (Buffer.byteLength(full) <= maximumBytes)
|
|
390
|
+
return { content: full, previewComplete: true };
|
|
391
|
+
let low = 0;
|
|
392
|
+
let high = lines.length;
|
|
393
|
+
while (low < high) {
|
|
394
|
+
const middle = Math.ceil((low + high) / 2);
|
|
395
|
+
if (Buffer.byteLength(render(middle)) <= maximumBytes)
|
|
396
|
+
low = middle;
|
|
397
|
+
else
|
|
398
|
+
high = middle - 1;
|
|
399
|
+
}
|
|
400
|
+
const content = render(low);
|
|
401
|
+
if (low > 0 && Buffer.byteLength(content) <= maximumBytes)
|
|
402
|
+
return { content, previewComplete: low === lines.length };
|
|
403
|
+
if (lines.length > 0) {
|
|
404
|
+
const lineNumber = result.startLine;
|
|
405
|
+
const prefix = `${lineNumber}\t`;
|
|
406
|
+
const formattedLine = lines[0];
|
|
407
|
+
const sourceLine = formattedLine.startsWith(prefix)
|
|
408
|
+
? formattedLine.slice(prefix.length)
|
|
409
|
+
: formattedLine;
|
|
410
|
+
const sourceLineBytes = Buffer.byteLength(sourceLine);
|
|
411
|
+
const renderOversizedLine = (retainedBytes) => {
|
|
412
|
+
const preview = oversizedLinePreview(sourceLine, retainedBytes, lineNumber);
|
|
413
|
+
const metadata = {
|
|
414
|
+
path: visiblePath.value,
|
|
415
|
+
...(visiblePath.truncated ? { pathTruncated: true } : {}),
|
|
416
|
+
encoding: result.encoding,
|
|
417
|
+
newline: result.newline,
|
|
418
|
+
startLine: lineNumber,
|
|
419
|
+
endLine: lineNumber,
|
|
420
|
+
eof: false,
|
|
421
|
+
truncated: true,
|
|
422
|
+
previewComplete: false,
|
|
423
|
+
oversizedLine: {
|
|
424
|
+
line: lineNumber,
|
|
425
|
+
bytes: sourceLineBytes,
|
|
426
|
+
shownBytes: preview.shownBytes,
|
|
427
|
+
omittedBytes: preview.omittedBytes
|
|
428
|
+
}
|
|
429
|
+
};
|
|
430
|
+
return [
|
|
431
|
+
`<read_result index="${index}" path="${path}"${pathTruncatedAttribute}>`,
|
|
432
|
+
`${prefix}${preview.value}`,
|
|
433
|
+
`<read_metadata>${JSON.stringify(metadata)}</read_metadata>`,
|
|
434
|
+
'</read_result>'
|
|
435
|
+
].join('\n');
|
|
436
|
+
};
|
|
437
|
+
let minimum = renderOversizedLine(0);
|
|
438
|
+
if (Buffer.byteLength(minimum) <= maximumBytes) {
|
|
439
|
+
let retainedLow = 0;
|
|
440
|
+
let retainedHigh = sourceLineBytes;
|
|
441
|
+
while (retainedLow < retainedHigh) {
|
|
442
|
+
const middle = Math.ceil((retainedLow + retainedHigh) / 2);
|
|
443
|
+
const candidate = renderOversizedLine(middle);
|
|
444
|
+
if (Buffer.byteLength(candidate) <= maximumBytes) {
|
|
445
|
+
retainedLow = middle;
|
|
446
|
+
minimum = candidate;
|
|
447
|
+
}
|
|
448
|
+
else
|
|
449
|
+
retainedHigh = middle - 1;
|
|
450
|
+
}
|
|
451
|
+
return { content: minimum, previewComplete: false };
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
return {
|
|
455
|
+
content: `<read_error index="${index}" code="MAR_AGENT_TOOL_OUTPUT_LIMIT">Model-visible read metadata exceeds this item's output share.</read_error>`,
|
|
456
|
+
previewComplete: false
|
|
457
|
+
};
|
|
458
|
+
}
|
|
459
|
+
export function formatBatchReadOutput(results) {
|
|
460
|
+
const blocks = [];
|
|
461
|
+
let bytes = 0;
|
|
462
|
+
let truncated = false;
|
|
463
|
+
const maximumBytes = modelTokenBudgetBytes(AGENT_EXECUTION_POLICY.modelToolOutputTokens);
|
|
464
|
+
for (const [index, result] of results.entries()) {
|
|
465
|
+
const separatorBytes = blocks.length === 0 ? 0 : 1;
|
|
466
|
+
const remainingItems = results.length - index;
|
|
467
|
+
const itemBudget = Math.floor((maximumBytes - bytes - separatorBytes) / remainingItems);
|
|
468
|
+
const block = formatBatchReadResult(result, index, itemBudget);
|
|
469
|
+
const blockBytes = Buffer.byteLength(block.content);
|
|
470
|
+
if (bytes + separatorBytes + blockBytes > maximumBytes)
|
|
471
|
+
break;
|
|
472
|
+
blocks.push(block.content);
|
|
473
|
+
bytes += separatorBytes + blockBytes;
|
|
474
|
+
if (!block.previewComplete)
|
|
475
|
+
truncated = true;
|
|
476
|
+
}
|
|
477
|
+
return { content: blocks.join('\n'), truncated };
|
|
478
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
3
|
-
import type { ToolCall, ToolExecutionContext, ToolExecutionResult } from '../
|
|
4
|
-
import { type WorkspacePathMount } from '
|
|
1
|
+
import type { LocalProcessExecutor } from '../../host/local-process-executor.js';
|
|
2
|
+
import type { CodeModeEngineFactory } from '../code-mode/engine.js';
|
|
3
|
+
import type { ToolCall, ToolExecutionContext, ToolExecutionResult } from '../contracts.js';
|
|
4
|
+
import { type WorkspacePathMount } from '../shared/path-resolver.js';
|
|
5
5
|
export declare class LocalToolRegistry {
|
|
6
6
|
#private;
|
|
7
7
|
constructor(workspace: string, environment?: NodeJS.ProcessEnv, shell?: string, web?: {
|
|
@@ -26,7 +26,7 @@ export declare class LocalToolRegistry {
|
|
|
26
26
|
}[];
|
|
27
27
|
listCodeCells(sessionId: string): {
|
|
28
28
|
cellId: string;
|
|
29
|
-
status: "completed" | "
|
|
29
|
+
status: "completed" | "failed" | "cancelled" | "running";
|
|
30
30
|
executionId: string;
|
|
31
31
|
}[];
|
|
32
32
|
disposeSessionResources(sessionId: string): Promise<void>;
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { MarAgentError } from '../../error.js';
|
|
2
|
+
import { ApplyPatchTool, applyPatchToolInput } from './apply-patch.js';
|
|
3
|
+
import { CodeModeTool } from '../code-mode/index.js';
|
|
4
|
+
import { ExecTool, execToolInput } from './exec.js';
|
|
5
|
+
import { ReadTool, formatBatchReadOutput } from './read.js';
|
|
6
|
+
import { executeWebFetch } from './web-fetch.js';
|
|
7
|
+
import { executeWebSearch } from './web-search.js';
|
|
8
|
+
import { WorkspacePathResolver } from '../shared/path-resolver.js';
|
|
9
|
+
import { ViewImageTool } from './view-image.js';
|
|
10
|
+
export class LocalToolRegistry {
|
|
11
|
+
#exec;
|
|
12
|
+
#code;
|
|
13
|
+
#handlers;
|
|
14
|
+
constructor(workspace, environment = process.env, shell, web = {}) {
|
|
15
|
+
const paths = new WorkspacePathResolver(workspace, {
|
|
16
|
+
...(web.restrictPaths === undefined ? {} : { restrictPaths: web.restrictPaths }),
|
|
17
|
+
...(web.workspaceWritable === undefined ? {} : { rootWritable: web.workspaceWritable }),
|
|
18
|
+
...(web.pathMounts === undefined ? {} : { mounts: web.pathMounts })
|
|
19
|
+
});
|
|
20
|
+
const read = new ReadTool(paths);
|
|
21
|
+
const viewImage = new ViewImageTool(paths);
|
|
22
|
+
const patch = new ApplyPatchTool(paths);
|
|
23
|
+
this.#exec = new ExecTool(paths, undefined, undefined, environment, shell, web.processExecutor);
|
|
24
|
+
this.#code = new CodeModeTool(paths, environment, web.processExecutor, web.codeModeEngineFactory);
|
|
25
|
+
this.#handlers = new Map([
|
|
26
|
+
['code_exec', (arguments_, context) => this.#code.start(arguments_, context)],
|
|
27
|
+
['code_exec_wait', (arguments_, context) => this.#code.wait(arguments_, context)],
|
|
28
|
+
[
|
|
29
|
+
'read',
|
|
30
|
+
async (arguments_, context) => {
|
|
31
|
+
const result = await read.execute(arguments_, context.signal);
|
|
32
|
+
const formatted = formatBatchReadOutput(result.results);
|
|
33
|
+
return {
|
|
34
|
+
content: formatted.content,
|
|
35
|
+
data: result,
|
|
36
|
+
truncated: result.truncated || formatted.truncated
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
],
|
|
40
|
+
[
|
|
41
|
+
'view_image',
|
|
42
|
+
async (arguments_, context) => viewImage.execute(arguments_, context.signal)
|
|
43
|
+
],
|
|
44
|
+
[
|
|
45
|
+
'apply_patch',
|
|
46
|
+
async (arguments_) => {
|
|
47
|
+
const result = await patch.execute(applyPatchToolInput(arguments_));
|
|
48
|
+
return { content: JSON.stringify(result), data: result };
|
|
49
|
+
}
|
|
50
|
+
],
|
|
51
|
+
...['exec', 'exec_wait'].map((name) => [
|
|
52
|
+
name,
|
|
53
|
+
async (arguments_, context) => {
|
|
54
|
+
const result = await this.#exec.execute(execToolInput(name, arguments_), context.signal, {
|
|
55
|
+
sessionId: context.sessionId,
|
|
56
|
+
executionId: context.executionId
|
|
57
|
+
});
|
|
58
|
+
return { content: JSON.stringify(result), data: result, truncated: result.truncated };
|
|
59
|
+
}
|
|
60
|
+
]),
|
|
61
|
+
...(web.webSearch
|
|
62
|
+
? [
|
|
63
|
+
[
|
|
64
|
+
'web_search',
|
|
65
|
+
async (arguments_, context) => {
|
|
66
|
+
return executeWebSearch(arguments_, context.signal, (input, signal) => web.webSearch(input, signal));
|
|
67
|
+
}
|
|
68
|
+
]
|
|
69
|
+
]
|
|
70
|
+
: []),
|
|
71
|
+
...(web.webFetch === false
|
|
72
|
+
? []
|
|
73
|
+
: [
|
|
74
|
+
[
|
|
75
|
+
'web_fetch',
|
|
76
|
+
async (arguments_, context) => {
|
|
77
|
+
return executeWebFetch(arguments_, context.signal, web.allowUntrustedTls === true);
|
|
78
|
+
}
|
|
79
|
+
]
|
|
80
|
+
])
|
|
81
|
+
]);
|
|
82
|
+
}
|
|
83
|
+
execute(call, context) {
|
|
84
|
+
const handler = this.#handlers.get(call.name);
|
|
85
|
+
if (!handler)
|
|
86
|
+
throw new MarAgentError('MAR_AGENT_TOOL_NOT_AVAILABLE', 'Tool is unavailable.');
|
|
87
|
+
return handler(call.arguments, context);
|
|
88
|
+
}
|
|
89
|
+
listSessionResources(sessionId) {
|
|
90
|
+
return this.#exec.listSessionResources(sessionId);
|
|
91
|
+
}
|
|
92
|
+
listCodeCells(sessionId) {
|
|
93
|
+
return this.#code.listSessionResources(sessionId);
|
|
94
|
+
}
|
|
95
|
+
async disposeSessionResources(sessionId) {
|
|
96
|
+
await Promise.all([this.#exec.disposeSession(sessionId), this.#code.dispose(sessionId)]);
|
|
97
|
+
}
|
|
98
|
+
async dispose() {
|
|
99
|
+
await Promise.all([this.#exec.dispose(), this.#code.dispose()]);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
@@ -1,13 +1,8 @@
|
|
|
1
|
-
import type { ClientToolDefinition } from '
|
|
2
|
-
import type { ToolExecutionResult } from '../
|
|
3
|
-
import { WorkspacePathResolver } from '
|
|
1
|
+
import type { ClientToolDefinition } from '../../model/contracts.js';
|
|
2
|
+
import type { ToolExecutionResult, ViewImageResult } from '../contracts.js';
|
|
3
|
+
import { WorkspacePathResolver } from '../shared/path-resolver.js';
|
|
4
|
+
export type { ViewImageResult } from '../contracts.js';
|
|
4
5
|
export declare const viewImageToolDefinition: ClientToolDefinition;
|
|
5
|
-
export interface ViewImageResult {
|
|
6
|
-
path: string;
|
|
7
|
-
mimeType: 'image/png' | 'image/jpeg' | 'image/webp';
|
|
8
|
-
bytes: number;
|
|
9
|
-
sha256: string;
|
|
10
|
-
}
|
|
11
6
|
export declare class ViewImageTool {
|
|
12
7
|
private readonly paths;
|
|
13
8
|
constructor(paths: WorkspacePathResolver);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createHash } from 'node:crypto';
|
|
2
2
|
import { open } from 'node:fs/promises';
|
|
3
|
-
import { MarAgentError } from '
|
|
4
|
-
import { TOOL_EXECUTION_LIMITS } from '
|
|
3
|
+
import { MarAgentError } from '../../error.js';
|
|
4
|
+
import { TOOL_EXECUTION_LIMITS } from '../execution-limits.js';
|
|
5
5
|
export const viewImageToolDefinition = {
|
|
6
6
|
name: 'view_image',
|
|
7
7
|
allowedCallers: ['direct', 'programmatic'],
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { ToolExecutionResult } from '../contracts.js';
|
|
2
|
+
import type { ClientToolDefinition } from '../../model/contracts.js';
|
|
3
|
+
export declare const webFetchToolDefinition: ClientToolDefinition;
|
|
4
|
+
export declare function executeWebFetch(input: unknown, signal: AbortSignal, allowUntrustedTls?: boolean): Promise<ToolExecutionResult>;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { request as httpRequest } from 'node:http';
|
|
2
|
+
import { request as httpsRequest } from 'node:https';
|
|
3
|
+
import { MarAgentError } from '../../error.js';
|
|
4
|
+
export const webFetchToolDefinition = {
|
|
5
|
+
name: 'web_fetch',
|
|
6
|
+
allowedCallers: ['direct', 'programmatic'],
|
|
7
|
+
parallelSafety: 'safe',
|
|
8
|
+
description: 'Fetch a specific HTTP or HTTPS URL, including explicitly permitted intranet URLs.',
|
|
9
|
+
inputSchema: {
|
|
10
|
+
type: 'object',
|
|
11
|
+
properties: { url: { type: 'string' } },
|
|
12
|
+
required: ['url'],
|
|
13
|
+
additionalProperties: false
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
export async function executeWebFetch(input, signal, allowUntrustedTls = false) {
|
|
17
|
+
const value = input;
|
|
18
|
+
if (typeof value?.url !== 'string')
|
|
19
|
+
throw new MarAgentError('MAR_AGENT_TOOL_INPUT_INVALID', 'URL is required.');
|
|
20
|
+
let url;
|
|
21
|
+
try {
|
|
22
|
+
url = new URL(value.url);
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
throw new MarAgentError('MAR_AGENT_TOOL_INPUT_INVALID', 'URL is invalid.');
|
|
26
|
+
}
|
|
27
|
+
if (url.protocol !== 'http:' && url.protocol !== 'https:')
|
|
28
|
+
throw new MarAgentError('MAR_AGENT_TOOL_INPUT_INVALID', 'Only HTTP and HTTPS URLs are supported.');
|
|
29
|
+
return fetchWebUrl(url, signal, allowUntrustedTls);
|
|
30
|
+
}
|
|
31
|
+
async function fetchWebUrl(url, signal, allowUntrustedTls, redirects = 0) {
|
|
32
|
+
if (redirects > 5)
|
|
33
|
+
throw new MarAgentError('MAR_AGENT_WEB_FETCH_FAILED', 'Too many redirects.');
|
|
34
|
+
return new Promise((resolve, reject) => {
|
|
35
|
+
const request = (url.protocol === 'https:' ? httpsRequest : httpRequest)(url, {
|
|
36
|
+
signal,
|
|
37
|
+
headers: {
|
|
38
|
+
accept: 'text/html,application/json,text/plain;q=0.9,*/*;q=0.1',
|
|
39
|
+
'accept-encoding': 'identity',
|
|
40
|
+
'user-agent': 'MyAgentRoam/0.9'
|
|
41
|
+
},
|
|
42
|
+
...(url.protocol === 'https:' ? { rejectUnauthorized: !allowUntrustedTls } : {})
|
|
43
|
+
}, (response) => {
|
|
44
|
+
const status = response.statusCode ?? 0;
|
|
45
|
+
if (status >= 300 && status < 400 && response.headers.location) {
|
|
46
|
+
response.resume();
|
|
47
|
+
void fetchWebUrl(new URL(response.headers.location, url), signal, allowUntrustedTls, redirects + 1).then(resolve, reject);
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
if (status < 200 || status >= 300) {
|
|
51
|
+
response.resume();
|
|
52
|
+
reject(new MarAgentError('MAR_AGENT_WEB_FETCH_FAILED', `HTTP ${status}.`));
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
const contentType = String(response.headers['content-type'] ?? 'text/plain').toLowerCase();
|
|
56
|
+
if (!/^(text\/|application\/(json|xml|xhtml\+xml))/u.test(contentType)) {
|
|
57
|
+
response.resume();
|
|
58
|
+
reject(new MarAgentError('MAR_AGENT_WEB_FETCH_UNSUPPORTED_CONTENT', 'Response is not readable text.'));
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
const chunks = [];
|
|
62
|
+
let bytes = 0;
|
|
63
|
+
let truncated = false;
|
|
64
|
+
response.on('data', (chunk) => {
|
|
65
|
+
if (bytes >= 1_000_000) {
|
|
66
|
+
truncated = true;
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
const remaining = 1_000_000 - bytes;
|
|
70
|
+
chunks.push(chunk.subarray(0, remaining));
|
|
71
|
+
bytes += Math.min(chunk.length, remaining);
|
|
72
|
+
if (chunk.length > remaining)
|
|
73
|
+
truncated = true;
|
|
74
|
+
});
|
|
75
|
+
response.on('end', () => resolve({
|
|
76
|
+
content: Buffer.concat(chunks).toString('utf8'),
|
|
77
|
+
data: { url: url.href, status },
|
|
78
|
+
truncated
|
|
79
|
+
}));
|
|
80
|
+
response.on('error', reject);
|
|
81
|
+
});
|
|
82
|
+
request.on('error', reject);
|
|
83
|
+
request.end();
|
|
84
|
+
});
|
|
85
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ClientToolDefinition } from '../../model/contracts.js';
|
|
2
|
+
import type { ToolExecutionResult } from '../contracts.js';
|
|
3
|
+
export declare const webSearchToolDefinition: ClientToolDefinition;
|
|
4
|
+
export declare function executeWebSearch(input: unknown, signal: AbortSignal, search: (input: {
|
|
5
|
+
query: string;
|
|
6
|
+
maxResults: number;
|
|
7
|
+
}, signal: AbortSignal) => Promise<ToolExecutionResult>): Promise<ToolExecutionResult>;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { MarAgentError } from '../../error.js';
|
|
2
|
+
export const webSearchToolDefinition = {
|
|
3
|
+
name: 'web_search',
|
|
4
|
+
allowedCallers: ['direct', 'programmatic'],
|
|
5
|
+
parallelSafety: 'safe',
|
|
6
|
+
description: 'Search the web for current information. Use web_fetch to open a specific result.',
|
|
7
|
+
inputSchema: {
|
|
8
|
+
type: 'object',
|
|
9
|
+
properties: {
|
|
10
|
+
query: { type: 'string', description: 'Search query.' },
|
|
11
|
+
maxResults: { type: 'integer', minimum: 1, maximum: 10, default: 8 }
|
|
12
|
+
},
|
|
13
|
+
required: ['query'],
|
|
14
|
+
additionalProperties: false
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
export async function executeWebSearch(input, signal, search) {
|
|
18
|
+
const value = input;
|
|
19
|
+
if (typeof value?.query !== 'string' || value.query.trim().length === 0)
|
|
20
|
+
throw new MarAgentError('MAR_AGENT_TOOL_INPUT_INVALID', 'Search query is required.');
|
|
21
|
+
try {
|
|
22
|
+
return await search({
|
|
23
|
+
query: value.query.trim(),
|
|
24
|
+
maxResults: typeof value.maxResults === 'number'
|
|
25
|
+
? Math.min(10, Math.max(1, Math.trunc(value.maxResults)))
|
|
26
|
+
: 8
|
|
27
|
+
}, signal);
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
if (error instanceof MarAgentError)
|
|
31
|
+
throw error;
|
|
32
|
+
throw new MarAgentError('MAR_AGENT_WEB_SEARCH_FAILED', 'Web search failed.', { cause: error });
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ApplyPatchTool } from './apply-patch.js';
|
|
2
2
|
import { ExecTool } from './exec.js';
|
|
3
3
|
import { ReadTool } from './read.js';
|
|
4
|
-
import { WorkspacePathResolver } from '
|
|
4
|
+
import { WorkspacePathResolver } from '../shared/path-resolver.js';
|
|
5
5
|
/** @deprecated Use the individual tool modules or LocalAgentHost. */
|
|
6
6
|
export class LocalWorkspaceTools {
|
|
7
7
|
#read;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import type { ClientToolDefinition } from '../
|
|
2
|
-
import type { McpToolCatalog } from './types.js';
|
|
1
|
+
import type { ClientToolDefinition, McpToolCatalog } from '../contracts.js';
|
|
3
2
|
export declare const MCP_DEFINITION_LIMITS: Readonly<{
|
|
4
3
|
depth: 64;
|
|
5
4
|
nodes: 32768;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { ModelMessage } from '../../model/contracts.js';
|
|
2
|
+
import type { DeferredMcpRegistry } from './tool-search.js';
|
|
3
|
+
export declare function discoveredMcpToolNames(messages: readonly ModelMessage[]): string[];
|
|
4
|
+
export declare function rebindMcpToolSearchOutputs(messages: readonly ModelMessage[], registry: DeferredMcpRegistry): void;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { providerToolCallId, providerToolName } from '../../runtime/context/projection.js';
|
|
2
|
+
export function discoveredMcpToolNames(messages) {
|
|
3
|
+
const calls = toolSearchCallIds(messages);
|
|
4
|
+
const names = new Set();
|
|
5
|
+
for (const message of messages)
|
|
6
|
+
for (const tool of calls.has(message.callId ?? '') ? (message.toolSearchTools ?? []) : [])
|
|
7
|
+
if (tool.name.startsWith('mcp__'))
|
|
8
|
+
names.add(tool.name);
|
|
9
|
+
return [...names];
|
|
10
|
+
}
|
|
11
|
+
export function rebindMcpToolSearchOutputs(messages, registry) {
|
|
12
|
+
const calls = toolSearchCallIds(messages);
|
|
13
|
+
for (const message of messages) {
|
|
14
|
+
if (!message.toolSearchTools)
|
|
15
|
+
continue;
|
|
16
|
+
if (!calls.has(message.callId ?? '')) {
|
|
17
|
+
delete message.toolSearchTools;
|
|
18
|
+
continue;
|
|
19
|
+
}
|
|
20
|
+
const definitions = registry.restoredDefinitions(message.toolSearchTools.map((tool) => tool.name));
|
|
21
|
+
message.toolSearchTools = definitions;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
function toolSearchCallIds(messages) {
|
|
25
|
+
return new Set(messages
|
|
26
|
+
.filter((message) => (message.role === 'tool_call' &&
|
|
27
|
+
message.name === 'tool_search' &&
|
|
28
|
+
typeof message.callId === 'string') ||
|
|
29
|
+
(message.role === 'provider' &&
|
|
30
|
+
providerToolName(message) === 'tool_search' &&
|
|
31
|
+
providerToolCallId(message) !== undefined))
|
|
32
|
+
.map((message) => message.role === 'provider' ? providerToolCallId(message) : message.callId));
|
|
33
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { ClientToolDefinition } from '
|
|
2
|
-
import type { McpCatalogTool, McpToolCatalog, ToolExecutionResult } from '../
|
|
3
|
-
import type { ToolRuntimeContext } from '
|
|
1
|
+
import type { ClientToolDefinition } from '../../model/contracts.js';
|
|
2
|
+
import type { McpCatalogTool, McpToolCatalog, ToolExecutionResult } from '../contracts.js';
|
|
3
|
+
import type { ToolRuntimeContext } from '../runtime-context.js';
|
|
4
4
|
export declare const TOOL_SEARCH_LIMITS: Readonly<{
|
|
5
5
|
defaultLimit: 5;
|
|
6
6
|
maximumLimit: 20;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { MarAgentError } from '
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import { MarAgentError } from '../../error.js';
|
|
2
|
+
import { countModelTokens } from '../../runtime/token-budget.js';
|
|
3
|
+
import { projectCodeModeSearchResult, projectCodeModeTools } from '../code-mode/index.js';
|
|
4
|
+
import { assertMcpToolCatalog } from './catalog.js';
|
|
5
5
|
export const TOOL_SEARCH_LIMITS = Object.freeze({
|
|
6
6
|
defaultLimit: 5,
|
|
7
7
|
maximumLimit: 20,
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { SubagentTaskSnapshot } from '../subagent/contracts.js';
|
|
2
|
+
import type { ApplyPatchResult, CodeCellEventData, ExecResult, MarAgentToolArtifact, ReadEventData, ViewImageResult } from './contracts.js';
|
|
3
|
+
import type { ToolRuntimeImage } from './runtime-context.js';
|
|
4
|
+
export declare function currentExecutionImages(modelInputImages: readonly {
|
|
5
|
+
readonly mimeType: string;
|
|
6
|
+
readonly dataBase64: string;
|
|
7
|
+
}[] | undefined, toolImages: readonly ToolRuntimeImage[]): ToolRuntimeImage[];
|
|
8
|
+
export declare function boundedModelToolOutput(toolName: string, value: string, data: unknown): {
|
|
9
|
+
content: string;
|
|
10
|
+
truncated: boolean;
|
|
11
|
+
};
|
|
12
|
+
/** Project only known, validated tool result shapes into public structured events. */
|
|
13
|
+
export declare function structuredToolEventData(toolName: string, value: unknown): CodeCellEventData | ExecResult | ApplyPatchResult | ReadEventData | ViewImageResult | SubagentTaskSnapshot | undefined;
|
|
14
|
+
export declare function structuredToolArtifacts(value: readonly MarAgentToolArtifact[] | undefined): readonly MarAgentToolArtifact[] | undefined;
|