@myagentroam/agent 0.10.57 → 0.10.58

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.
@@ -235,7 +235,7 @@ export class AnthropicMessagesAdapter {
235
235
  const sources = anthropicHostedSources(result);
236
236
  const summary = {
237
237
  ...hosted.summary,
238
- ...(sources.length ? { sources } : {}),
238
+ ...(Array.isArray(result) ? { sources } : {}),
239
239
  ...(Array.isArray(result) && result.length > 20 ? { sourcesTruncated: true } : {})
240
240
  };
241
241
  hostedTools.set(toolId, { ...hosted, summary });
@@ -466,9 +466,11 @@ function anthropicHostedSources(result) {
466
466
  if (!url)
467
467
  return undefined;
468
468
  const title = text(source.title);
469
+ const snippet = text(source.snippet);
469
470
  return {
470
471
  url: url.slice(0, 2_048),
471
- ...(title ? { title: title.slice(0, 256) } : {})
472
+ ...(title ? { title: title.slice(0, 256) } : {}),
473
+ ...(snippet ? { snippet: snippet.slice(0, 2000) } : {})
472
474
  };
473
475
  })
474
476
  .filter((source) => source !== undefined);
@@ -191,6 +191,7 @@ export type ModelEvent = {
191
191
  sources?: readonly {
192
192
  url: string;
193
193
  title?: string | undefined;
194
+ snippet?: string | undefined;
194
195
  }[] | undefined;
195
196
  sourcesTruncated?: boolean | undefined;
196
197
  };
@@ -1740,9 +1740,11 @@ function hostedWebActionSummary(action) {
1740
1740
  if (!sourceUrl)
1741
1741
  return undefined;
1742
1742
  const sourceTitle = text(value.title);
1743
+ const snippet = text(value.snippet);
1743
1744
  return {
1744
1745
  url: sourceUrl.slice(0, 2048),
1745
- ...(sourceTitle ? { title: sourceTitle.slice(0, 256) } : {})
1746
+ ...(sourceTitle ? { title: sourceTitle.slice(0, 256) } : {}),
1747
+ ...(snippet ? { snippet: snippet.slice(0, 2000) } : {})
1746
1748
  };
1747
1749
  })
1748
1750
  .filter((source) => source !== undefined)
@@ -1751,7 +1753,7 @@ function hostedWebActionSummary(action) {
1751
1753
  ...(query ? { query: query.slice(0, 10_000) } : {}),
1752
1754
  ...(url ? { url: url.slice(0, 2048) } : {}),
1753
1755
  ...(title ? { title: title.slice(0, 256) } : {}),
1754
- ...(sources.length ? { sources } : {}),
1756
+ ...(Array.isArray(action.sources) ? { sources } : {}),
1755
1757
  ...(Array.isArray(action.sources) && action.sources.length > 20
1756
1758
  ? { sourcesTruncated: true }
1757
1759
  : {})
@@ -1,4 +1,5 @@
1
1
  import { AGENT_EXECUTION_POLICY } from './execution-policy.js';
2
+ import { publicToolMetadata } from '../tools/public-metadata.js';
2
3
  /** Mark display-only clipping without changing tool output or model context. */
3
4
  export function toolEventSummary(text) {
4
5
  const limit = AGENT_EXECUTION_POLICY.toolEventSummaryCharacters;
@@ -50,6 +51,10 @@ export function publicHostedToolEvents(event) {
50
51
  type: 'tool.started',
51
52
  toolName,
52
53
  callId: event.itemId,
54
+ data: {
55
+ ...publicToolMetadata(event.kind === 'WEB_SEARCH' ? 'web_search' : 'web_fetch', event.summary),
56
+ hostedToolKind: event.kind
57
+ },
53
58
  ...(input === undefined ? {} : { input }),
54
59
  ...(truncated ? { truncated: true } : {})
55
60
  };
@@ -67,5 +72,15 @@ export function publicHostedToolEvents(event) {
67
72
  truncated
68
73
  }
69
74
  ];
70
- return [started, { type: 'tool.completed', toolName, callId: event.itemId, summary, truncated }];
75
+ return [
76
+ started,
77
+ {
78
+ type: 'tool.completed',
79
+ toolName,
80
+ callId: event.itemId,
81
+ summary,
82
+ truncated,
83
+ data: started.data
84
+ }
85
+ ];
71
86
  }
@@ -68,6 +68,7 @@ export type MarAgentEvent = MarAgentEventBase & ({
68
68
  sources?: readonly {
69
69
  url: string;
70
70
  title?: string | undefined;
71
+ snippet?: string | undefined;
71
72
  }[] | undefined;
72
73
  sourcesTruncated?: boolean | undefined;
73
74
  };
@@ -82,6 +83,7 @@ export type MarAgentEvent = MarAgentEventBase & ({
82
83
  callId: string;
83
84
  parentCallId?: string;
84
85
  input?: unknown;
86
+ data?: import('../tools/public-metadata.js').PublicToolMetadata;
85
87
  truncated?: boolean;
86
88
  } | {
87
89
  type: 'tool.completed';
@@ -92,7 +94,7 @@ export type MarAgentEvent = MarAgentEventBase & ({
92
94
  summary: string;
93
95
  truncated?: boolean;
94
96
  artifacts?: readonly MarAgentToolArtifact[];
95
- data?: CodeCellEventData | import('../tools/contracts.js').ExecResult | Omit<import('../tools/contracts.js').ExecResult, 'stdout' | 'stderr'> | import('../tools/contracts.js').ApplyPatchResult | import('../tools/contracts.js').ReadEventData | import('../tools/contracts.js').ViewImageResult | import('../subagent/contracts.js').SubagentTaskSnapshot | import('../subagent/contracts.js').SubagentManyOutput | import('../tools/agent/sleep.js').SleepResult;
97
+ data?: CodeCellEventData | import('../tools/contracts.js').ExecResult | Omit<import('../tools/contracts.js').ExecResult, 'stdout' | 'stderr'> | import('../tools/contracts.js').ApplyPatchResult | import('../tools/contracts.js').ReadEventData | import('../tools/contracts.js').ViewImageResult | import('../subagent/contracts.js').SubagentTaskSnapshot | import('../subagent/contracts.js').SubagentManyOutput | import('../tools/agent/sleep.js').SleepResult | import('../tools/public-metadata.js').PublicToolMetadata;
96
98
  } | {
97
99
  type: 'tool.failed';
98
100
  resultExtensions?: readonly import('../tools/result-extensions.js').ToolResultExtension[];
@@ -104,6 +106,11 @@ export type MarAgentEvent = MarAgentEventBase & ({
104
106
  message?: string;
105
107
  permissionStop?: import('../tools/permissions.js').PermissionStop;
106
108
  truncated?: boolean;
109
+ } | {
110
+ type: 'sleep.started';
111
+ callId: string;
112
+ durationMs: number;
113
+ startedAt: string;
107
114
  } | {
108
115
  type: 'usage.updated';
109
116
  purpose?: 'compact';
@@ -6,7 +6,7 @@ export interface SleepResult {
6
6
  wakeReason: 'elapsed' | 'steer' | 'subagent_message';
7
7
  }
8
8
  export declare const sleepToolDefinition: ClientToolDefinition;
9
- export declare function executeSleep(arguments_: unknown, context: ToolRuntimeContext): Promise<{
9
+ export declare function executeSleep(arguments_: unknown, context: ToolRuntimeContext, callId: string): Promise<{
10
10
  content: string;
11
11
  data: SleepResult;
12
12
  }>;
@@ -19,7 +19,7 @@ export const sleepToolDefinition = {
19
19
  additionalProperties: false
20
20
  }
21
21
  };
22
- export async function executeSleep(arguments_, context) {
22
+ export async function executeSleep(arguments_, context, callId) {
23
23
  const durationMs = arguments_ && typeof arguments_ === 'object' && !Array.isArray(arguments_)
24
24
  ? arguments_.durationMs
25
25
  : undefined;
@@ -28,12 +28,19 @@ export async function executeSleep(arguments_, context) {
28
28
  durationMs < 1 ||
29
29
  durationMs > TOOL_EXECUTION_LIMITS.sleepMaxDurationMs)
30
30
  throw new MarAgentError('MAR_AGENT_TOOL_INPUT_INVALID', 'Sleep duration is out of range.');
31
+ context.signal.throwIfAborted();
31
32
  const started = performance.now();
33
+ await context.emit({
34
+ type: 'sleep.started',
35
+ callId,
36
+ durationMs,
37
+ startedAt: new Date().toISOString()
38
+ });
32
39
  const messages = context.subagentMessages;
33
40
  const outcome = await waitForToolCondition({
34
41
  ready: () => messages?.pending() ?? false,
35
42
  subscribe: (notify) => messages?.subscribe(notify) ?? (() => { }),
36
- waitMs: durationMs,
43
+ waitMs: Math.max(0, durationMs - (performance.now() - started)),
37
44
  signal: context.signal,
38
45
  interrupt: context.waitInterrupt
39
46
  });
@@ -2,6 +2,7 @@ import type { SubagentTaskSnapshot, SubagentManyOutput } from '../subagent/contr
2
2
  import type { ApplyPatchResult, ApplyPatchPartialResult, CodeCellEventData, ExecResult, MarAgentToolArtifact, ToolExecutionResult, ReadEventData, ViewImageResult } from './contracts.js';
3
3
  import type { ToolRuntimeImage } from './runtime-context.js';
4
4
  import type { SleepResult } from './agent/sleep.js';
5
+ import { type PublicToolMetadata } from './public-metadata.js';
5
6
  export declare function currentExecutionImages(modelInputImages: readonly {
6
7
  readonly mimeType: string;
7
8
  readonly dataBase64: string;
@@ -11,7 +12,7 @@ export declare function boundedModelToolOutput(toolName: string, value: string,
11
12
  truncated: boolean;
12
13
  };
13
14
  /** Project only known, validated tool result shapes into public structured events. */
14
- export declare function structuredToolEventData(toolName: string, value: unknown): CodeCellEventData | ExecResult | ApplyPatchResult | ReadEventData | ViewImageResult | SubagentTaskSnapshot | SubagentManyOutput | SleepResult | undefined;
15
+ export declare function structuredToolEventData(toolName: string, value: unknown): CodeCellEventData | ExecResult | ApplyPatchResult | ReadEventData | ViewImageResult | SubagentTaskSnapshot | SubagentManyOutput | SleepResult | PublicToolMetadata | undefined;
15
16
  /** Partial patch facts are allowlisted; arbitrary error details never become public event data. */
16
17
  export declare function structuredToolFailureData(toolName: string, error: unknown): ApplyPatchPartialResult | undefined;
17
18
  export declare function structuredToolArtifacts(value: readonly MarAgentToolArtifact[] | undefined): readonly MarAgentToolArtifact[] | undefined;
@@ -3,6 +3,7 @@ import { parseApplyPatchResult, parseApplyPatchPartialResult } from './shared/pa
3
3
  import { AGENT_EXECUTION_POLICY } from '../runtime/execution-policy.js';
4
4
  import { countModelTokens, countTextLines, truncateModelText } from '../runtime/token-budget.js';
5
5
  import { TOOL_EXECUTION_LIMITS } from './execution-limits.js';
6
+ import { publicToolMetadata } from './public-metadata.js';
6
7
  export function currentExecutionImages(modelInputImages, toolImages) {
7
8
  return [
8
9
  ...(modelInputImages ?? []).map((image) => ({
@@ -35,6 +36,9 @@ export function boundedModelToolOutput(toolName, value, data) {
35
36
  export function structuredToolEventData(toolName, value) {
36
37
  if (!isRecord(value))
37
38
  return undefined;
39
+ const metadata = publicToolMetadata(toolName, value);
40
+ if (metadata !== undefined)
41
+ return metadata;
38
42
  if (toolName === 'sleep' &&
39
43
  typeof value.durationMs === 'number' &&
40
44
  Number.isInteger(value.durationMs) &&
@@ -0,0 +1,23 @@
1
+ export type PublicToolMetadata = ({
2
+ query?: string;
3
+ sources?: {
4
+ url: string;
5
+ title?: string;
6
+ snippet?: string;
7
+ }[];
8
+ sourceCount?: number;
9
+ } | {
10
+ url?: string;
11
+ title?: string;
12
+ mode?: 'http' | 'browser';
13
+ status?: number;
14
+ contentType?: string;
15
+ } | {
16
+ name: string;
17
+ description?: string;
18
+ source?: string;
19
+ }) & {
20
+ hostedToolKind?: 'WEB_SEARCH' | 'WEB_FETCH';
21
+ };
22
+ /** Public metadata only; page bodies and skill instructions stay in the bounded output. */
23
+ export declare function publicToolMetadata(toolName: string, value: Record<string, unknown>): PublicToolMetadata | undefined;
@@ -0,0 +1,56 @@
1
+ /** Public metadata only; page bodies and skill instructions stay in the bounded output. */
2
+ export function publicToolMetadata(toolName, value) {
3
+ const text = (key, limit) => typeof value[key] === 'string' ? value[key].slice(0, limit) : undefined;
4
+ if (toolName === 'web_search') {
5
+ const entries = Array.isArray(value.results)
6
+ ? value.results
7
+ : Array.isArray(value.sources)
8
+ ? value.sources
9
+ : undefined;
10
+ const sources = entries?.flatMap((entry) => {
11
+ if (!entry || typeof entry !== 'object' || Array.isArray(entry))
12
+ return [];
13
+ const source = entry;
14
+ if (typeof source.url !== 'string' || !source.url)
15
+ return [];
16
+ return [
17
+ {
18
+ url: source.url.slice(0, 8192),
19
+ ...(typeof source.title === 'string' ? { title: source.title.slice(0, 1000) } : {}),
20
+ ...(typeof source.snippet === 'string' ? { snippet: source.snippet.slice(0, 2000) } : {})
21
+ }
22
+ ];
23
+ });
24
+ return {
25
+ ...(text('query', 500) === undefined ? {} : { query: text('query', 500) }),
26
+ ...(sources === undefined
27
+ ? {}
28
+ : {
29
+ sources: sources.slice(0, 20),
30
+ ...(value.sourcesTruncated === true ? {} : { sourceCount: sources.length })
31
+ })
32
+ };
33
+ }
34
+ if (toolName === 'web_fetch')
35
+ return {
36
+ ...(text('url', 8192) === undefined ? {} : { url: text('url', 8192) }),
37
+ ...(text('title', 1000) === undefined ? {} : { title: text('title', 1000) }),
38
+ ...(value.mode === 'http' || value.mode === 'browser' ? { mode: value.mode } : {}),
39
+ ...(typeof value.status === 'number' &&
40
+ Number.isInteger(value.status) &&
41
+ value.status >= 100 &&
42
+ value.status <= 599
43
+ ? { status: value.status }
44
+ : {}),
45
+ ...(text('contentType', 256) === undefined ? {} : { contentType: text('contentType', 256) })
46
+ };
47
+ if (toolName === 'skill' && typeof value.name === 'string')
48
+ return {
49
+ name: value.name.slice(0, 128),
50
+ ...(text('description', 2000) === undefined
51
+ ? {}
52
+ : { description: text('description', 2000) }),
53
+ ...(text('source', 4096) === undefined ? {} : { source: text('source', 4096) })
54
+ };
55
+ return undefined;
56
+ }
@@ -4,6 +4,11 @@ import type { AgentSkill } from '../runtime/context/instructions.js';
4
4
  import type { SubagentController, SubagentLatestMessage } from '../subagent/scheduler.js';
5
5
  import type { TodoStore } from './agent/todo.js';
6
6
  export type ToolRuntimeEvent = {
7
+ type: 'sleep.started';
8
+ callId: string;
9
+ durationMs: number;
10
+ startedAt: string;
11
+ } | {
7
12
  type: 'todo.updated';
8
13
  revision: number;
9
14
  items: readonly import('./agent/todo.js').TodoItem[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@myagentroam/agent",
3
- "version": "0.10.57",
3
+ "version": "0.10.58",
4
4
  "description": "Embeddable MAR coding agent SDK and CLI.",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",