@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.
Files changed (234) hide show
  1. package/dist/agent-core/host/contracts.d.ts +64 -0
  2. package/dist/{host → agent-core/host}/local-agent-host.d.ts +6 -5
  3. package/dist/{host → agent-core/host}/local-agent-host.js +4 -4
  4. package/dist/{model → agent-core/model}/anthropic-messages.js +24 -13
  5. package/dist/{model → agent-core/model}/contracts.d.ts +6 -16
  6. package/dist/{model → agent-core/model}/openai-responses.js +16 -9
  7. package/dist/agent-core/model/recovery.d.ts +4 -0
  8. package/dist/agent-core/model/recovery.js +71 -0
  9. package/dist/{prompts → agent-core/prompts}/core.d.ts +3 -13
  10. package/dist/{prompts → agent-core/prompts}/index.d.ts +1 -1
  11. package/dist/{prompts → agent-core/prompts}/modes.d.ts +1 -1
  12. package/dist/{prompts → agent-core/prompts}/resources.d.ts +1 -1
  13. package/dist/{runtime/compact.d.ts → agent-core/runtime/compaction/history.d.ts} +2 -23
  14. package/dist/{runtime/compact.js → agent-core/runtime/compaction/history.js} +2 -92
  15. package/dist/agent-core/runtime/compaction/operation.d.ts +22 -0
  16. package/dist/agent-core/runtime/compaction/operation.js +91 -0
  17. package/dist/agent-core/runtime/context/contracts.d.ts +12 -0
  18. package/dist/{runtime/environment-context.d.ts → agent-core/runtime/context/environment.d.ts} +2 -2
  19. package/dist/{runtime/environment-context.js → agent-core/runtime/context/environment.js} +1 -1
  20. package/dist/{runtime/context-gc-runtime.d.ts → agent-core/runtime/context/gc-runtime.d.ts} +4 -4
  21. package/dist/{runtime/context-gc-runtime.js → agent-core/runtime/context/gc-runtime.js} +3 -3
  22. package/dist/{runtime/context-gc-tokens.d.ts → agent-core/runtime/context/gc-tokens.d.ts} +2 -2
  23. package/dist/{runtime/context-gc-tokens.js → agent-core/runtime/context/gc-tokens.js} +7 -5
  24. package/dist/{runtime/context-gc.d.ts → agent-core/runtime/context/gc.d.ts} +3 -3
  25. package/dist/{runtime/context-gc.js → agent-core/runtime/context/gc.js} +152 -19
  26. package/dist/{runtime → agent-core/runtime/context}/instructions.d.ts +1 -1
  27. package/dist/{runtime → agent-core/runtime/context}/instructions.js +1 -1
  28. package/dist/{runtime → agent-core/runtime/context}/normalize.d.ts +1 -1
  29. package/dist/{runtime/context-projection.d.ts → agent-core/runtime/context/projection.d.ts} +3 -3
  30. package/dist/{runtime/context-projection.js → agent-core/runtime/context/projection.js} +35 -4
  31. package/dist/agent-core/runtime/context/request-budget.d.ts +6 -0
  32. package/dist/agent-core/runtime/context/request-budget.js +22 -0
  33. package/dist/agent-core/runtime/context/restore.d.ts +15 -0
  34. package/dist/agent-core/runtime/context/restore.js +85 -0
  35. package/dist/agent-core/runtime/context/usage.d.ts +18 -0
  36. package/dist/agent-core/runtime/context/usage.js +138 -0
  37. package/dist/agent-core/runtime/context/world-state.d.ts +35 -0
  38. package/dist/agent-core/runtime/context/world-state.js +133 -0
  39. package/dist/agent-core/runtime/contracts.d.ts +37 -0
  40. package/dist/agent-core/runtime/event-projection.d.ts +5 -0
  41. package/dist/agent-core/runtime/event-projection.js +17 -0
  42. package/dist/agent-core/runtime/events.d.ts +143 -0
  43. package/dist/agent-core/runtime/execution.d.ts +50 -0
  44. package/dist/agent-core/runtime/execution.js +397 -0
  45. package/dist/{runtime → agent-core/runtime}/rollout-budget.d.ts +1 -1
  46. package/dist/agent-core/sdk/agent.js +209 -0
  47. package/dist/agent-core/sdk/model-runtime.d.ts +13 -0
  48. package/dist/agent-core/sdk/model-runtime.js +63 -0
  49. package/dist/agent-core/sdk/session-title.d.ts +3 -0
  50. package/dist/agent-core/sdk/session-title.js +42 -0
  51. package/dist/agent-core/sdk/session.d.ts +62 -0
  52. package/dist/agent-core/sdk/session.js +1147 -0
  53. package/dist/agent-core/sdk/subagent-backend.d.ts +3 -0
  54. package/dist/agent-core/sdk/subagent-backend.js +46 -0
  55. package/dist/agent-core/sdk/types.d.ts +56 -0
  56. package/dist/{session → agent-core/session}/catalog.d.ts +2 -1
  57. package/dist/{session → agent-core/session}/context-gc-checkpoint.d.ts +3 -0
  58. package/dist/{session → agent-core/session}/context-gc-checkpoint.js +122 -23
  59. package/dist/agent-core/session/context-gc-observations.d.ts +38 -0
  60. package/dist/agent-core/session/context-gc-observations.js +150 -0
  61. package/dist/{session → agent-core/session}/context-gc-replacements.d.ts +1 -1
  62. package/dist/{session → agent-core/session}/context-gc-replacements.js +6 -2
  63. package/dist/{session → agent-core/session}/jsonl-store.d.ts +2 -2
  64. package/dist/{session → agent-core/session}/jsonl-store.js +1 -1
  65. package/dist/agent-core/subagent/contracts.d.ts +91 -0
  66. package/dist/agent-core/subagent/contracts.js +1 -0
  67. package/dist/agent-core/subagent/scheduler.d.ts +117 -0
  68. package/dist/{subagent → agent-core/subagent}/session-controller.d.ts +3 -2
  69. package/dist/agent-core/tools/agent/agent-cancel.d.ts +7 -0
  70. package/dist/{tools → agent-core/tools/agent}/agent-cancel.js +1 -1
  71. package/dist/agent-core/tools/agent/agent-message.d.ts +7 -0
  72. package/dist/{tools → agent-core/tools/agent}/agent-message.js +2 -2
  73. package/dist/{tools → agent-core/tools/agent}/agent-start.d.ts +3 -3
  74. package/dist/{tools → agent-core/tools/agent}/agent-start.js +3 -3
  75. package/dist/agent-core/tools/agent/agent-wait.d.ts +7 -0
  76. package/dist/{tools → agent-core/tools/agent}/agent-wait.js +2 -2
  77. package/dist/{tools → agent-core/tools/agent}/question.d.ts +2 -2
  78. package/dist/{tools → agent-core/tools/agent}/question.js +2 -2
  79. package/dist/{tools → agent-core/tools/agent}/skill.d.ts +2 -2
  80. package/dist/{tools → agent-core/tools/agent}/skill.js +2 -2
  81. package/dist/{tools → agent-core/tools/agent}/todo-read.d.ts +2 -2
  82. package/dist/{tools → agent-core/tools/agent}/todo-write.d.ts +2 -2
  83. package/dist/{tools → agent-core/tools/agent}/todo-write.js +2 -2
  84. package/dist/{tools → agent-core/tools/agent}/todo.d.ts +2 -9
  85. package/dist/{tools → agent-core/tools/agent}/todo.js +1 -1
  86. package/dist/{tools → agent-core/tools}/code-mode/cells.d.ts +4 -1
  87. package/dist/{tools → agent-core/tools}/code-mode/cells.js +60 -6
  88. package/dist/{tools → agent-core/tools}/code-mode/dispatch.d.ts +2 -4
  89. package/dist/{tools → agent-core/tools}/code-mode/dispatch.js +10 -6
  90. package/dist/{tools → agent-core/tools}/code-mode/engine.d.ts +13 -1
  91. package/dist/agent-core/tools/code-mode/engine.js +1 -0
  92. package/dist/{tools/code-mode.d.ts → agent-core/tools/code-mode/index.d.ts} +7 -7
  93. package/dist/{tools/code-mode.js → agent-core/tools/code-mode/index.js} +190 -28
  94. package/dist/agent-core/tools/code-mode/observations.d.ts +103 -0
  95. package/dist/agent-core/tools/code-mode/observations.js +195 -0
  96. package/dist/{tools → agent-core/tools}/code-mode/quickjs-engine.js +91 -17
  97. package/dist/{tools → agent-core/tools}/code-mode/state.d.ts +2 -13
  98. package/dist/agent-core/tools/code-mode/worker.d.ts +1 -0
  99. package/dist/{tools → agent-core/tools}/code-mode/worker.js +8 -1
  100. package/dist/agent-core/tools/contracts.d.ts +172 -0
  101. package/dist/agent-core/tools/contracts.js +1 -0
  102. package/dist/agent-core/tools/execution.d.ts +36 -0
  103. package/dist/agent-core/tools/execution.js +111 -0
  104. package/dist/agent-core/tools/local/apply-patch.d.ts +19 -0
  105. package/dist/{tools → agent-core/tools/local}/apply-patch.js +8 -2
  106. package/dist/{tools → agent-core/tools/local}/exec.d.ts +5 -17
  107. package/dist/{tools → agent-core/tools/local}/exec.js +4 -4
  108. package/dist/{tools → agent-core/tools/local}/read.d.ts +7 -15
  109. package/dist/{tools → agent-core/tools/local}/read.js +185 -2
  110. package/dist/{tools/local-registry.d.ts → agent-core/tools/local/registry.d.ts} +5 -5
  111. package/dist/agent-core/tools/local/registry.js +101 -0
  112. package/dist/{tools → agent-core/tools/local}/view-image.d.ts +4 -9
  113. package/dist/{tools → agent-core/tools/local}/view-image.js +2 -2
  114. package/dist/agent-core/tools/local/web-fetch.d.ts +4 -0
  115. package/dist/agent-core/tools/local/web-fetch.js +85 -0
  116. package/dist/agent-core/tools/local/web-search.d.ts +7 -0
  117. package/dist/agent-core/tools/local/web-search.js +34 -0
  118. package/dist/{tools/local-workspace-tools.js → agent-core/tools/local/workspace-tools.js} +1 -1
  119. package/dist/{sdk/mcp-catalog.d.ts → agent-core/tools/mcp/catalog.d.ts} +1 -2
  120. package/dist/{sdk/mcp-catalog.js → agent-core/tools/mcp/catalog.js} +1 -1
  121. package/dist/agent-core/tools/mcp/history.d.ts +4 -0
  122. package/dist/agent-core/tools/mcp/history.js +33 -0
  123. package/dist/{tools → agent-core/tools/mcp}/tool-search.d.ts +3 -3
  124. package/dist/{tools → agent-core/tools/mcp}/tool-search.js +4 -4
  125. package/dist/agent-core/tools/output-projection.d.ts +14 -0
  126. package/dist/agent-core/tools/output-projection.js +223 -0
  127. package/dist/{tools → agent-core/tools}/registry.d.ts +1 -1
  128. package/dist/agent-core/tools/registry.js +47 -0
  129. package/dist/{tools → agent-core/tools}/runtime-context.d.ts +8 -7
  130. package/dist/agent-core/tools/runtime-context.js +1 -0
  131. package/dist/{tools → agent-core/tools}/runtime.d.ts +1 -1
  132. package/dist/cli/codex-auth-file.d.ts +1 -1
  133. package/dist/cli/codex-auth-file.js +2 -2
  134. package/dist/cli/main.js +9 -9
  135. package/dist/index.d.ts +17 -15
  136. package/dist/index.js +8 -8
  137. package/dist/sandbox/linux/bubblewrap-sandbox-executor.d.ts +1 -1
  138. package/dist/sandbox/linux/bubblewrap-sandbox-executor.js +1 -1
  139. package/package.json +3 -3
  140. package/dist/host/contracts.d.ts +0 -21
  141. package/dist/sdk/agent.js +0 -2548
  142. package/dist/sdk/types.d.ts +0 -349
  143. package/dist/subagent/scheduler.d.ts +0 -206
  144. package/dist/tools/agent-cancel.d.ts +0 -7
  145. package/dist/tools/agent-message.d.ts +0 -7
  146. package/dist/tools/agent-wait.d.ts +0 -7
  147. package/dist/tools/apply-patch.d.ts +0 -32
  148. package/dist/tools/local-registry.js +0 -373
  149. package/dist/tools/registry.js +0 -47
  150. package/dist/tools/web-fetch.d.ts +0 -2
  151. package/dist/tools/web-fetch.js +0 -12
  152. package/dist/tools/web-search.d.ts +0 -2
  153. package/dist/tools/web-search.js +0 -15
  154. /package/dist/{error.d.ts → agent-core/error.d.ts} +0 -0
  155. /package/dist/{error.js → agent-core/error.js} +0 -0
  156. /package/dist/{host → agent-core/host}/contracts.js +0 -0
  157. /package/dist/{host → agent-core/host}/local-process-executor.d.ts +0 -0
  158. /package/dist/{host → agent-core/host}/local-process-executor.js +0 -0
  159. /package/dist/{host → agent-core/host}/network.d.ts +0 -0
  160. /package/dist/{host → agent-core/host}/network.js +0 -0
  161. /package/dist/{model → agent-core/model}/anthropic-messages.d.ts +0 -0
  162. /package/dist/{model → agent-core/model}/anthropic-thinking.d.ts +0 -0
  163. /package/dist/{model → agent-core/model}/anthropic-thinking.js +0 -0
  164. /package/dist/{model → agent-core/model}/catalog-file.d.ts +0 -0
  165. /package/dist/{model → agent-core/model}/catalog-file.js +0 -0
  166. /package/dist/{model → agent-core/model}/configuration.d.ts +0 -0
  167. /package/dist/{model → agent-core/model}/configuration.js +0 -0
  168. /package/dist/{model → agent-core/model}/contracts.js +0 -0
  169. /package/dist/{model → agent-core/model}/http.d.ts +0 -0
  170. /package/dist/{model → agent-core/model}/http.js +0 -0
  171. /package/dist/{model → agent-core/model}/openai-responses.d.ts +0 -0
  172. /package/dist/{model → agent-core/model}/runtime-credential.d.ts +0 -0
  173. /package/dist/{model → agent-core/model}/runtime-credential.js +0 -0
  174. /package/dist/{model → agent-core/model}/sse.d.ts +0 -0
  175. /package/dist/{model → agent-core/model}/sse.js +0 -0
  176. /package/dist/{model → agent-core/model}/transport-test.d.ts +0 -0
  177. /package/dist/{model → agent-core/model}/transport-test.js +0 -0
  178. /package/dist/{prompts → agent-core/prompts}/compact.d.ts +0 -0
  179. /package/dist/{prompts → agent-core/prompts}/compact.js +0 -0
  180. /package/dist/{prompts → agent-core/prompts}/core.js +0 -0
  181. /package/dist/{prompts → agent-core/prompts}/execution-budget.d.ts +0 -0
  182. /package/dist/{prompts → agent-core/prompts}/execution-budget.js +0 -0
  183. /package/dist/{prompts → agent-core/prompts}/index.js +0 -0
  184. /package/dist/{prompts → agent-core/prompts}/modes.js +0 -0
  185. /package/dist/{prompts → agent-core/prompts}/output.d.ts +0 -0
  186. /package/dist/{prompts → agent-core/prompts}/output.js +0 -0
  187. /package/dist/{prompts → agent-core/prompts}/resources.js +0 -0
  188. /package/dist/{prompts → agent-core/prompts}/subagent.d.ts +0 -0
  189. /package/dist/{prompts → agent-core/prompts}/subagent.js +0 -0
  190. /package/dist/{prompts → agent-core/prompts}/title.d.ts +0 -0
  191. /package/dist/{prompts → agent-core/prompts}/title.js +0 -0
  192. /package/dist/{prompts → agent-core/prompts}/workflow.d.ts +0 -0
  193. /package/dist/{prompts → agent-core/prompts}/workflow.js +0 -0
  194. /package/dist/{runtime → agent-core/runtime}/async-queue.d.ts +0 -0
  195. /package/dist/{runtime → agent-core/runtime}/async-queue.js +0 -0
  196. /package/dist/{sdk/types.js → agent-core/runtime/context/contracts.js} +0 -0
  197. /package/dist/{runtime → agent-core/runtime/context}/normalize.js +0 -0
  198. /package/dist/{session/types.js → agent-core/runtime/contracts.js} +0 -0
  199. /package/dist/{tools/code-mode/engine.js → agent-core/runtime/events.js} +0 -0
  200. /package/dist/{runtime → agent-core/runtime}/execution-policy.d.ts +0 -0
  201. /package/dist/{runtime → agent-core/runtime}/execution-policy.js +0 -0
  202. /package/dist/{runtime → agent-core/runtime}/plan-output.d.ts +0 -0
  203. /package/dist/{runtime → agent-core/runtime}/plan-output.js +0 -0
  204. /package/dist/{runtime → agent-core/runtime}/rollout-budget.js +0 -0
  205. /package/dist/{runtime → agent-core/runtime}/token-budget.d.ts +0 -0
  206. /package/dist/{runtime → agent-core/runtime}/token-budget.js +0 -0
  207. /package/dist/{sdk → agent-core/sdk}/agent.d.ts +0 -0
  208. /package/dist/{tools/code-mode/worker.d.ts → agent-core/sdk/types.js} +0 -0
  209. /package/dist/{session → agent-core/session}/catalog.js +0 -0
  210. /package/dist/{session → agent-core/session}/context-gc-subagent.d.ts +0 -0
  211. /package/dist/{session → agent-core/session}/context-gc-subagent.js +0 -0
  212. /package/dist/{session → agent-core/session}/transaction-recovery.d.ts +0 -0
  213. /package/dist/{session → agent-core/session}/transaction-recovery.js +0 -0
  214. /package/dist/{session → agent-core/session}/types.d.ts +0 -0
  215. /package/dist/{tools/runtime-context.js → agent-core/session/types.js} +0 -0
  216. /package/dist/{subagent → agent-core/subagent}/scheduler.js +0 -0
  217. /package/dist/{subagent → agent-core/subagent}/session-controller.js +0 -0
  218. /package/dist/{tools → agent-core/tools/agent}/todo-read.js +0 -0
  219. /package/dist/{tools → agent-core/tools}/callers.d.ts +0 -0
  220. /package/dist/{tools → agent-core/tools}/callers.js +0 -0
  221. /package/dist/{tools → agent-core/tools}/code-mode/quickjs-engine.d.ts +0 -0
  222. /package/dist/{tools → agent-core/tools}/code-mode/state.js +0 -0
  223. /package/dist/{tools → agent-core/tools}/code-mode/text-output.d.ts +0 -0
  224. /package/dist/{tools → agent-core/tools}/code-mode/text-output.js +0 -0
  225. /package/dist/{tools → agent-core/tools}/execution-limits.d.ts +0 -0
  226. /package/dist/{tools → agent-core/tools}/execution-limits.js +0 -0
  227. /package/dist/{tools → agent-core/tools/local}/read-context.d.ts +0 -0
  228. /package/dist/{tools → agent-core/tools/local}/read-context.js +0 -0
  229. /package/dist/{tools/local-workspace-tools.d.ts → agent-core/tools/local/workspace-tools.d.ts} +0 -0
  230. /package/dist/{tools → agent-core/tools}/runtime.js +0 -0
  231. /package/dist/{tools → agent-core/tools}/scheduler.d.ts +0 -0
  232. /package/dist/{tools → agent-core/tools}/scheduler.js +0 -0
  233. /package/dist/{tools → agent-core/tools}/shared/path-resolver.d.ts +0 -0
  234. /package/dist/{tools → agent-core/tools}/shared/path-resolver.js +0 -0
@@ -1,373 +0,0 @@
1
- import { MarAgentError } from '../error.js';
2
- import { AGENT_EXECUTION_POLICY } from '../runtime/execution-policy.js';
3
- import { modelTokenBudgetBytes } from '../runtime/token-budget.js';
4
- import { ApplyPatchTool } from './apply-patch.js';
5
- import { ExecTool, execToolInput } from './exec.js';
6
- import { CodeModeTool } from './code-mode.js';
7
- import { ReadTool } from './read.js';
8
- import { WorkspacePathResolver } from './shared/path-resolver.js';
9
- import { ViewImageTool } from './view-image.js';
10
- import { request as httpRequest } from 'node:http';
11
- import { request as httpsRequest } from 'node:https';
12
- export class LocalToolRegistry {
13
- #exec;
14
- #code;
15
- #handlers;
16
- constructor(workspace, environment = process.env, shell, web = {}) {
17
- const paths = new WorkspacePathResolver(workspace, {
18
- ...(web.restrictPaths === undefined ? {} : { restrictPaths: web.restrictPaths }),
19
- ...(web.workspaceWritable === undefined ? {} : { rootWritable: web.workspaceWritable }),
20
- ...(web.pathMounts === undefined ? {} : { mounts: web.pathMounts })
21
- });
22
- const read = new ReadTool(paths);
23
- const viewImage = new ViewImageTool(paths);
24
- const patch = new ApplyPatchTool(paths);
25
- this.#exec = new ExecTool(paths, undefined, undefined, environment, shell, web.processExecutor);
26
- this.#code = new CodeModeTool(paths, environment, web.processExecutor, web.codeModeEngineFactory);
27
- this.#handlers = new Map([
28
- ['code_exec', (arguments_, context) => this.#code.start(arguments_, context)],
29
- ['code_exec_wait', (arguments_, context) => this.#code.wait(arguments_, context)],
30
- [
31
- 'read',
32
- async (arguments_, context) => {
33
- const result = await read.execute(arguments_, context.signal);
34
- const formatted = formatBatchReadOutput(result.results);
35
- return {
36
- content: formatted.content,
37
- data: result,
38
- truncated: result.truncated || formatted.truncated
39
- };
40
- }
41
- ],
42
- [
43
- 'view_image',
44
- async (arguments_, context) => viewImage.execute(arguments_, context.signal)
45
- ],
46
- [
47
- 'apply_patch',
48
- async (arguments_) => {
49
- const value = typeof arguments_ === 'string'
50
- ? arguments_
51
- : arguments_?.patch;
52
- if (typeof value !== 'string')
53
- throw new MarAgentError('MAR_AGENT_TOOL_INPUT_INVALID', 'Patch is required.');
54
- const result = await patch.execute(value);
55
- return { content: JSON.stringify(result), data: result };
56
- }
57
- ],
58
- ...['exec', 'exec_wait'].map((name) => [
59
- name,
60
- async (arguments_, context) => {
61
- const result = await this.#exec.execute(execToolInput(name, arguments_), context.signal, {
62
- sessionId: context.sessionId,
63
- executionId: context.executionId
64
- });
65
- return { content: JSON.stringify(result), data: result, truncated: result.truncated };
66
- }
67
- ]),
68
- ...(web.webSearch
69
- ? [
70
- [
71
- 'web_search',
72
- async (arguments_, context) => {
73
- const value = arguments_;
74
- if (typeof value?.query !== 'string' || value.query.trim().length === 0)
75
- throw new MarAgentError('MAR_AGENT_TOOL_INPUT_INVALID', 'Search query is required.');
76
- try {
77
- return await web.webSearch({
78
- query: value.query.trim(),
79
- maxResults: typeof value.maxResults === 'number'
80
- ? Math.min(10, Math.max(1, Math.trunc(value.maxResults)))
81
- : 8
82
- }, context.signal);
83
- }
84
- catch (error) {
85
- if (error instanceof MarAgentError)
86
- throw error;
87
- throw new MarAgentError('MAR_AGENT_WEB_SEARCH_FAILED', 'Web search failed.', {
88
- cause: error
89
- });
90
- }
91
- }
92
- ]
93
- ]
94
- : []),
95
- ...(web.webFetch === false
96
- ? []
97
- : [
98
- [
99
- 'web_fetch',
100
- async (arguments_, context) => {
101
- const value = arguments_;
102
- if (typeof value?.url !== 'string')
103
- throw new MarAgentError('MAR_AGENT_TOOL_INPUT_INVALID', 'URL is required.');
104
- let url;
105
- try {
106
- url = new URL(value.url);
107
- }
108
- catch {
109
- throw new MarAgentError('MAR_AGENT_TOOL_INPUT_INVALID', 'URL is invalid.');
110
- }
111
- if (url.protocol !== 'http:' && url.protocol !== 'https:')
112
- throw new MarAgentError('MAR_AGENT_TOOL_INPUT_INVALID', 'Only HTTP and HTTPS URLs are supported.');
113
- return fetchWebUrl(url, context.signal, web.allowUntrustedTls === true);
114
- }
115
- ]
116
- ])
117
- ]);
118
- }
119
- execute(call, context) {
120
- const handler = this.#handlers.get(call.name);
121
- if (!handler)
122
- throw new MarAgentError('MAR_AGENT_TOOL_NOT_AVAILABLE', 'Tool is unavailable.');
123
- return handler(call.arguments, context);
124
- }
125
- listSessionResources(sessionId) {
126
- return this.#exec.listSessionResources(sessionId);
127
- }
128
- listCodeCells(sessionId) {
129
- return this.#code.listSessionResources(sessionId);
130
- }
131
- async disposeSessionResources(sessionId) {
132
- await Promise.all([this.#exec.disposeSession(sessionId), this.#code.dispose(sessionId)]);
133
- }
134
- async dispose() {
135
- await Promise.all([this.#exec.dispose(), this.#code.dispose()]);
136
- }
137
- }
138
- async function fetchWebUrl(url, signal, allowUntrustedTls, redirects = 0) {
139
- if (redirects > 5)
140
- throw new MarAgentError('MAR_AGENT_WEB_FETCH_FAILED', 'Too many redirects.');
141
- return new Promise((resolve, reject) => {
142
- const request = (url.protocol === 'https:' ? httpsRequest : httpRequest)(url, {
143
- signal,
144
- headers: {
145
- accept: 'text/html,application/json,text/plain;q=0.9,*/*;q=0.1',
146
- 'accept-encoding': 'identity',
147
- 'user-agent': 'MyAgentRoam/0.9'
148
- },
149
- ...(url.protocol === 'https:' ? { rejectUnauthorized: !allowUntrustedTls } : {})
150
- }, (response) => {
151
- const status = response.statusCode ?? 0;
152
- if (status >= 300 && status < 400 && response.headers.location) {
153
- response.resume();
154
- void fetchWebUrl(new URL(response.headers.location, url), signal, allowUntrustedTls, redirects + 1).then(resolve, reject);
155
- return;
156
- }
157
- if (status < 200 || status >= 300) {
158
- response.resume();
159
- reject(new MarAgentError('MAR_AGENT_WEB_FETCH_FAILED', `HTTP ${status}.`));
160
- return;
161
- }
162
- const contentType = String(response.headers['content-type'] ?? 'text/plain').toLowerCase();
163
- if (!/^(text\/|application\/(json|xml|xhtml\+xml))/u.test(contentType)) {
164
- response.resume();
165
- reject(new MarAgentError('MAR_AGENT_WEB_FETCH_UNSUPPORTED_CONTENT', 'Response is not readable text.'));
166
- return;
167
- }
168
- const chunks = [];
169
- let bytes = 0;
170
- let truncated = false;
171
- response.on('data', (chunk) => {
172
- if (bytes >= 1_000_000) {
173
- truncated = true;
174
- return;
175
- }
176
- const remaining = 1_000_000 - bytes;
177
- chunks.push(chunk.subarray(0, remaining));
178
- bytes += Math.min(chunk.length, remaining);
179
- if (chunk.length > remaining)
180
- truncated = true;
181
- });
182
- response.on('end', () => resolve({
183
- content: Buffer.concat(chunks).toString('utf8'),
184
- data: { url: url.href, status },
185
- truncated
186
- }));
187
- response.on('error', reject);
188
- });
189
- request.on('error', reject);
190
- request.end();
191
- });
192
- }
193
- function escapeAttribute(value) {
194
- return value.replaceAll('&', '&amp;').replaceAll('"', '&quot;').replaceAll('<', '&lt;');
195
- }
196
- function escapeText(value) {
197
- return value.replaceAll('&', '&amp;').replaceAll('<', '&lt;');
198
- }
199
- function boundedUtf8Prefix(value, maximumBytes) {
200
- if (Buffer.byteLength(value) <= maximumBytes)
201
- return { value, truncated: false };
202
- const marker = '…';
203
- const contentBudget = Math.max(0, maximumBytes - Buffer.byteLength(marker));
204
- let result = '';
205
- let bytes = 0;
206
- for (const character of value) {
207
- const characterBytes = Buffer.byteLength(character);
208
- if (bytes + characterBytes > contentBudget)
209
- break;
210
- result += character;
211
- bytes += characterBytes;
212
- }
213
- return { value: `${result}${marker}`, truncated: true };
214
- }
215
- function oversizedLinePreview(value, retainedBytes, lineNumber) {
216
- const bytes = Buffer.from(value, 'utf8');
217
- if (retainedBytes >= bytes.length)
218
- return { value, shownBytes: bytes.length, omittedBytes: 0 };
219
- const headTarget = Math.floor(retainedBytes / 2);
220
- const tailTarget = retainedBytes - headTarget;
221
- let head = Math.min(headTarget, bytes.length);
222
- while (head > 0 && isUtf8ContinuationByte(bytes[head]))
223
- head--;
224
- let tail = Math.max(head, bytes.length - tailTarget);
225
- while (tail < bytes.length && isUtf8ContinuationByte(bytes[tail]))
226
- tail++;
227
- const shownBytes = head + bytes.length - tail;
228
- const omittedBytes = bytes.length - shownBytes;
229
- const marker = `...[${omittedBytes} bytes omitted from line ${lineNumber}]...`;
230
- return {
231
- value: `${bytes.toString('utf8', 0, head)}${marker}${bytes.toString('utf8', tail)}`,
232
- shownBytes,
233
- omittedBytes
234
- };
235
- }
236
- function isUtf8ContinuationByte(value) {
237
- return value !== undefined && (value & 0xc0) === 0x80;
238
- }
239
- function formatBatchReadResult(result, index, maximumBytes) {
240
- const visiblePath = boundedUtf8Prefix(result.path, 128);
241
- const path = escapeAttribute(visiblePath.value);
242
- const pathTruncatedAttribute = visiblePath.truncated ? ' pathTruncated="true"' : '';
243
- if ('error' in result) {
244
- const message = boundedUtf8Prefix(result.error.message, 256);
245
- const detailsTruncatedAttribute = message.truncated ? ' detailsTruncated="true"' : '';
246
- const content = `<read_error index="${index}" path="${path}"${pathTruncatedAttribute} code="${escapeAttribute(result.error.code)}"${detailsTruncatedAttribute}>${escapeText(message.value)}</read_error>`;
247
- if (Buffer.byteLength(content) <= maximumBytes)
248
- return { content, previewComplete: true };
249
- return {
250
- content: `<read_error index="${index}" code="MAR_AGENT_TOOL_OUTPUT_LIMIT">Model-visible error metadata exceeds this item's output share.</read_error>`,
251
- previewComplete: false
252
- };
253
- }
254
- const lines = result.content ? result.content.split('\n') : [];
255
- const render = (visibleLines) => {
256
- const previewComplete = visibleLines === lines.length;
257
- const endLine = visibleLines === 0 ? undefined : result.startLine + Math.max(0, visibleLines - 1);
258
- const metadata = {
259
- path: visiblePath.value,
260
- ...(visiblePath.truncated ? { pathTruncated: true } : {}),
261
- encoding: result.encoding,
262
- newline: result.newline,
263
- startLine: result.startLine,
264
- ...(endLine === undefined ? {} : { endLine }),
265
- eof: previewComplete ? result.eof : false,
266
- truncated: previewComplete ? result.truncated : true,
267
- ...(previewComplete
268
- ? result.nextOffset === undefined
269
- ? {}
270
- : { nextOffset: result.nextOffset }
271
- : { nextOffset: result.startLine + visibleLines }),
272
- previewComplete
273
- };
274
- return [
275
- `<read_result index="${index}" path="${path}"${pathTruncatedAttribute}>`,
276
- lines.slice(0, visibleLines).join('\n'),
277
- `<read_metadata>${JSON.stringify(metadata)}</read_metadata>`,
278
- '</read_result>'
279
- ]
280
- .filter(Boolean)
281
- .join('\n');
282
- };
283
- const full = render(lines.length);
284
- if (Buffer.byteLength(full) <= maximumBytes)
285
- return { content: full, previewComplete: true };
286
- let low = 0;
287
- let high = lines.length;
288
- while (low < high) {
289
- const middle = Math.ceil((low + high) / 2);
290
- if (Buffer.byteLength(render(middle)) <= maximumBytes)
291
- low = middle;
292
- else
293
- high = middle - 1;
294
- }
295
- const content = render(low);
296
- if (low > 0 && Buffer.byteLength(content) <= maximumBytes)
297
- return { content, previewComplete: low === lines.length };
298
- if (lines.length > 0) {
299
- const lineNumber = result.startLine;
300
- const prefix = `${lineNumber}\t`;
301
- const formattedLine = lines[0];
302
- const sourceLine = formattedLine.startsWith(prefix)
303
- ? formattedLine.slice(prefix.length)
304
- : formattedLine;
305
- const sourceLineBytes = Buffer.byteLength(sourceLine);
306
- const renderOversizedLine = (retainedBytes) => {
307
- const preview = oversizedLinePreview(sourceLine, retainedBytes, lineNumber);
308
- const metadata = {
309
- path: visiblePath.value,
310
- ...(visiblePath.truncated ? { pathTruncated: true } : {}),
311
- encoding: result.encoding,
312
- newline: result.newline,
313
- startLine: lineNumber,
314
- endLine: lineNumber,
315
- eof: false,
316
- truncated: true,
317
- previewComplete: false,
318
- oversizedLine: {
319
- line: lineNumber,
320
- bytes: sourceLineBytes,
321
- shownBytes: preview.shownBytes,
322
- omittedBytes: preview.omittedBytes
323
- }
324
- };
325
- return [
326
- `<read_result index="${index}" path="${path}"${pathTruncatedAttribute}>`,
327
- `${prefix}${preview.value}`,
328
- `<read_metadata>${JSON.stringify(metadata)}</read_metadata>`,
329
- '</read_result>'
330
- ].join('\n');
331
- };
332
- let minimum = renderOversizedLine(0);
333
- if (Buffer.byteLength(minimum) <= maximumBytes) {
334
- let retainedLow = 0;
335
- let retainedHigh = sourceLineBytes;
336
- while (retainedLow < retainedHigh) {
337
- const middle = Math.ceil((retainedLow + retainedHigh) / 2);
338
- const candidate = renderOversizedLine(middle);
339
- if (Buffer.byteLength(candidate) <= maximumBytes) {
340
- retainedLow = middle;
341
- minimum = candidate;
342
- }
343
- else
344
- retainedHigh = middle - 1;
345
- }
346
- return { content: minimum, previewComplete: false };
347
- }
348
- }
349
- return {
350
- content: `<read_error index="${index}" code="MAR_AGENT_TOOL_OUTPUT_LIMIT">Model-visible read metadata exceeds this item's output share.</read_error>`,
351
- previewComplete: false
352
- };
353
- }
354
- function formatBatchReadOutput(results) {
355
- const blocks = [];
356
- let bytes = 0;
357
- let truncated = false;
358
- const maximumBytes = modelTokenBudgetBytes(AGENT_EXECUTION_POLICY.modelToolOutputTokens);
359
- for (const [index, result] of results.entries()) {
360
- const separatorBytes = blocks.length === 0 ? 0 : 1;
361
- const remainingItems = results.length - index;
362
- const itemBudget = Math.floor((maximumBytes - bytes - separatorBytes) / remainingItems);
363
- const block = formatBatchReadResult(result, index, itemBudget);
364
- const blockBytes = Buffer.byteLength(block.content);
365
- if (bytes + separatorBytes + blockBytes > maximumBytes)
366
- break;
367
- blocks.push(block.content);
368
- bytes += separatorBytes + blockBytes;
369
- if (!block.previewComplete)
370
- truncated = true;
371
- }
372
- return { content: blocks.join('\n'), truncated };
373
- }
@@ -1,47 +0,0 @@
1
- import { applyPatchToolDefinition } from './apply-patch.js';
2
- import { execToolDefinition, execWaitToolDefinition } from './exec.js';
3
- import { codeModeToolDefinition, codeExecWaitToolDefinition } from './code-mode.js';
4
- import { executeQuestion, questionToolDefinition } from './question.js';
5
- import { readToolDefinition } from './read.js';
6
- import { viewImageToolDefinition } from './view-image.js';
7
- import { executeAgentStart, agentStartToolDefinition } from './agent-start.js';
8
- import { executeAgentCancel, agentCancelToolDefinition } from './agent-cancel.js';
9
- import { executeAgentWait, agentWaitToolDefinition } from './agent-wait.js';
10
- import { executeAgentMessage, agentMessageToolDefinition } from './agent-message.js';
11
- import { executeTodoRead, todoReadToolDefinition } from './todo-read.js';
12
- import { executeTodoWrite, todoWriteToolDefinition } from './todo-write.js';
13
- import { webFetchToolDefinition } from './web-fetch.js';
14
- import { webSearchToolDefinition } from './web-search.js';
15
- import { executeSkill, skillToolDefinition } from './skill.js';
16
- import { executeToolSearch, toolSearchToolDefinition } from './tool-search.js';
17
- export const BUILTIN_TOOL_DEFINITIONS = [
18
- skillToolDefinition,
19
- toolSearchToolDefinition,
20
- readToolDefinition,
21
- viewImageToolDefinition,
22
- execToolDefinition,
23
- execWaitToolDefinition,
24
- codeModeToolDefinition,
25
- codeExecWaitToolDefinition,
26
- applyPatchToolDefinition,
27
- questionToolDefinition,
28
- todoReadToolDefinition,
29
- todoWriteToolDefinition,
30
- agentStartToolDefinition,
31
- agentWaitToolDefinition,
32
- agentMessageToolDefinition,
33
- agentCancelToolDefinition,
34
- webSearchToolDefinition,
35
- webFetchToolDefinition
36
- ];
37
- export const AGENT_TOOL_HANDLERS = new Map([
38
- ['skill', executeSkill],
39
- ['tool_search', executeToolSearch],
40
- ['question', executeQuestion],
41
- ['todo_read', (_arguments, context) => executeTodoRead(context)],
42
- ['todo_write', executeTodoWrite],
43
- ['agent_start', executeAgentStart],
44
- ['agent_wait', executeAgentWait],
45
- ['agent_message', executeAgentMessage],
46
- ['agent_cancel', executeAgentCancel]
47
- ]);
@@ -1,2 +0,0 @@
1
- import type { ClientToolDefinition } from '../model/contracts.js';
2
- export declare const webFetchToolDefinition: ClientToolDefinition;
@@ -1,12 +0,0 @@
1
- export const webFetchToolDefinition = {
2
- name: 'web_fetch',
3
- allowedCallers: ['direct', 'programmatic'],
4
- parallelSafety: 'safe',
5
- description: 'Fetch a specific HTTP or HTTPS URL, including explicitly permitted intranet URLs.',
6
- inputSchema: {
7
- type: 'object',
8
- properties: { url: { type: 'string' } },
9
- required: ['url'],
10
- additionalProperties: false
11
- }
12
- };
@@ -1,2 +0,0 @@
1
- import type { ClientToolDefinition } from '../model/contracts.js';
2
- export declare const webSearchToolDefinition: ClientToolDefinition;
@@ -1,15 +0,0 @@
1
- export const webSearchToolDefinition = {
2
- name: 'web_search',
3
- allowedCallers: ['direct', 'programmatic'],
4
- parallelSafety: 'safe',
5
- description: 'Search the web for current information. Use web_fetch to open a specific result.',
6
- inputSchema: {
7
- type: 'object',
8
- properties: {
9
- query: { type: 'string', description: 'Search query.' },
10
- maxResults: { type: 'integer', minimum: 1, maximum: 10, default: 8 }
11
- },
12
- required: ['query'],
13
- additionalProperties: false
14
- }
15
- };
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes