@myagentroam/agent 0.9.129 → 0.9.130

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.
@@ -85,6 +85,7 @@ export class AnthropicMessagesAdapter {
85
85
  })
86
86
  }, signal, 1);
87
87
  const blocks = new Map();
88
+ const hostedTools = new Map();
88
89
  // Block completion precedes the stop reason, which determines commentary vs final answer.
89
90
  const pendingTextBlocks = new Set();
90
91
  let responseId = `anthropic-${randomUUID()}`;
@@ -148,14 +149,40 @@ export class AnthropicMessagesAdapter {
148
149
  phase: 'commentary',
149
150
  delta: text(block.text) ?? ''
150
151
  };
151
- else if (blockType === 'server_tool_use')
152
+ else if (blockType === 'server_tool_use') {
153
+ const kind = text(block.name) === 'web_fetch' ? 'WEB_FETCH' : 'WEB_SEARCH';
154
+ const summary = anthropicHostedInputSummary(record(block.input));
155
+ hostedTools.set(id, { kind, summary });
152
156
  yield {
153
157
  type: 'hosted_tool',
154
158
  itemId: id,
155
- kind: text(block.name) === 'web_fetch' ? 'WEB_FETCH' : 'WEB_SEARCH',
159
+ kind,
156
160
  status: 'RUNNING',
157
- summary: {}
161
+ summary
158
162
  };
163
+ }
164
+ else if (blockType === 'web_search_tool_result' ||
165
+ blockType === 'web_fetch_tool_result') {
166
+ const toolId = text(block.tool_use_id);
167
+ const hosted = toolId === undefined ? undefined : hostedTools.get(toolId);
168
+ if (toolId !== undefined && hosted !== undefined) {
169
+ const result = block.content;
170
+ const sources = anthropicHostedSources(result);
171
+ const summary = {
172
+ ...hosted.summary,
173
+ ...(sources.length ? { sources } : {}),
174
+ ...(Array.isArray(result) && result.length > 20 ? { sourcesTruncated: true } : {})
175
+ };
176
+ hostedTools.set(toolId, { ...hosted, summary });
177
+ yield {
178
+ type: 'hosted_tool',
179
+ itemId: toolId,
180
+ kind: hosted.kind,
181
+ status: anthropicHostedResultFailed(result) ? 'FAILED' : 'COMPLETED',
182
+ summary
183
+ };
184
+ }
185
+ }
159
186
  }
160
187
  else if (type === 'content_block_delta') {
161
188
  const delta = record(event.delta);
@@ -205,6 +232,29 @@ export class AnthropicMessagesAdapter {
205
232
  if (block.type === 'thinking' && block.text)
206
233
  yield { type: 'reasoning.summary', itemId: block.id, text: block.text };
207
234
  }
235
+ else if (block?.type === 'server_tool_use') {
236
+ const hosted = hostedTools.get(block.id);
237
+ if (hosted !== undefined) {
238
+ let input;
239
+ try {
240
+ input = JSON.parse(block.json || '{}');
241
+ }
242
+ catch {
243
+ input = undefined;
244
+ }
245
+ const summary = { ...hosted.summary, ...anthropicHostedInputSummary(record(input)) };
246
+ if (summary.query !== hosted.summary.query || summary.url !== hosted.summary.url) {
247
+ hostedTools.set(block.id, { ...hosted, summary });
248
+ yield {
249
+ type: 'hosted_tool',
250
+ itemId: block.id,
251
+ kind: hosted.kind,
252
+ status: 'RUNNING',
253
+ summary
254
+ };
255
+ }
256
+ }
257
+ }
208
258
  else if (block?.type === 'tool_use') {
209
259
  let args = {};
210
260
  let argumentError;
@@ -304,6 +354,36 @@ async function* parseAnthropicSse(response, signal) {
304
354
  throw cause;
305
355
  }
306
356
  }
357
+ function anthropicHostedInputSummary(input) {
358
+ const query = text(input.query);
359
+ const url = text(input.url);
360
+ return {
361
+ ...(query ? { query: query.slice(0, 10_000) } : {}),
362
+ ...(url ? { url: url.slice(0, 2_048) } : {})
363
+ };
364
+ }
365
+ function anthropicHostedSources(result) {
366
+ if (!Array.isArray(result))
367
+ return [];
368
+ return result
369
+ .slice(0, 20)
370
+ .map((entry) => {
371
+ const source = record(entry);
372
+ const url = text(source.url);
373
+ if (!url)
374
+ return undefined;
375
+ const title = text(source.title);
376
+ return {
377
+ url: url.slice(0, 2_048),
378
+ ...(title ? { title: title.slice(0, 256) } : {})
379
+ };
380
+ })
381
+ .filter((source) => source !== undefined);
382
+ }
383
+ function anthropicHostedResultFailed(result) {
384
+ const entries = Array.isArray(result) ? result : [result];
385
+ return entries.some((entry) => text(record(entry).type)?.endsWith('_tool_result_error'));
386
+ }
307
387
  function isSemanticEvent(event) {
308
388
  return event.type !== 'response.started' && event.type !== 'usage';
309
389
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@myagentroam/agent",
3
- "version": "0.9.129",
3
+ "version": "0.9.130",
4
4
  "description": "Embeddable MAR coding agent SDK and CLI.",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",