veryfront 0.1.479 → 0.1.480

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.
@@ -0,0 +1,561 @@
1
+ import * as dntShim from "../../_dnt.shims.js";
2
+ import type { HostedSandboxToolsOptions, HostedSandboxToolsResult } from "../sandbox/index.js";
3
+ import { createHostedSandboxTools } from "../sandbox/index.js";
4
+ import {
5
+ createRemoteMCPToolSource,
6
+ createToolsFromRemoteDefinitions,
7
+ type HostToolSet,
8
+ type RemoteMCPToolSourceConfig,
9
+ type RemoteToolSource,
10
+ sleepTool,
11
+ type ToolExecutionContext,
12
+ } from "../tool/index.js";
13
+ import { z } from "zod";
14
+ import { buildExecuteToolTraceAttributes } from "./agent-trace-attributes.js";
15
+ import type {
16
+ ChildRunExecutionResult,
17
+ ChildRunExecutionSnapshot,
18
+ } from "./child-run-execution-snapshot.js";
19
+ import { isChildRunAbortError, throwIfChildRunAborted } from "./child-run-execution-support.js";
20
+ import type { ConversationRunEvent } from "./conversation-run-events.js";
21
+ import { createConversationChildLifecycleAdapter } from "./conversation-hosted-lifecycle.js";
22
+ import { bootstrapHostedChildRun } from "./hosted-child-bootstrap.js";
23
+ import { createHostedChildExecutionLogWriter } from "./hosted-child-execution-logging.js";
24
+ import { startHostedChildForkRuntimeWithHostTools } from "./hosted-child-fork-runtime-start.js";
25
+ import {
26
+ prepareDefaultHostedChildForkSandboxToolSources,
27
+ } from "./hosted-child-fork-tool-sources.js";
28
+ import { executeHostedChildForkToolInput } from "./hosted-child-fork-execution-runner.js";
29
+ import { createHostedChildInvokeTool } from "./hosted-child-invoke-tool.js";
30
+ import {
31
+ runHostedChildExecutionLifecycle,
32
+ shouldSkipHostedChildTerminalPersistence,
33
+ } from "./hosted-child-lifecycle.js";
34
+ import { createLiveStudioMcpTools } from "./live-studio-mcp-tools.js";
35
+ import {
36
+ applyAgentProjectContextChange,
37
+ type MutableAgentProjectContext,
38
+ } from "./project-context.js";
39
+ import {
40
+ buildHostedDurableChildInvokeFailureResult,
41
+ createHostedDurableChildInvokeTraceRecorder,
42
+ executeHostedDurableChildFork,
43
+ executeHostedLocalChildInvoke,
44
+ type HostedDurableChildExecutionOptions,
45
+ type HostedDurableChildInvokeResult,
46
+ } from "./hosted-durable-child-fork-execution.js";
47
+ import type { HostedChildRunIdentifiers } from "./hosted-child-status.js";
48
+ import {
49
+ DEFAULT_HOSTED_CHILD_AGENT_ID,
50
+ type HostedChildForkRuntimeConfig,
51
+ type HostedChildForkToolInput,
52
+ hostedChildForkToolInputSchema,
53
+ } from "./hosted-child-tool-input.js";
54
+ import type {
55
+ DefaultHostedChildForkToolAssemblyResult,
56
+ DefaultHostedChildForkToolAssemblySourceResult,
57
+ } from "./hosted-child-requested-tools.js";
58
+ import { prepareDefaultHostedChildForkToolAssembly } from "./hosted-child-requested-tools.js";
59
+ import type { RuntimeClientProfile } from "./runtime-client-profile.js";
60
+ import { withRootOwnedChildResultHint } from "./conversation-delegation-policy.js";
61
+
62
+ export type DefaultHostedInvokeAgentContext = MutableAgentProjectContext & {
63
+ authToken: string;
64
+ clientProfile?: RuntimeClientProfile | null;
65
+ model?: string;
66
+ conversationId?: string;
67
+ parentRunId?: string;
68
+ parentMessageId?: string;
69
+ publishParentRunEvents?: (events: ConversationRunEvent[]) => Promise<void> | void;
70
+ availableToolNames?: string[];
71
+ steeringRevision?: number;
72
+ };
73
+
74
+ export type DefaultHostedInvokeAgentConfig = {
75
+ apiUrl: string;
76
+ apiMcpUrl: string;
77
+ studioMcpUrl?: string | null;
78
+ enableDurableInvokeAgent?: boolean;
79
+ };
80
+
81
+ export type DefaultHostedInvokeAgentLogger = {
82
+ debug(message: string, metadata?: Record<string, unknown>): void;
83
+ info(message: string, metadata?: Record<string, unknown>): void;
84
+ warn(message: string, metadata?: Record<string, unknown>): void;
85
+ error(message: string, metadata?: Record<string, unknown>): void;
86
+ };
87
+
88
+ export type DefaultHostedInvokeAgentTraceAttributes = Record<
89
+ string,
90
+ string | number | boolean | readonly (string | number | boolean)[] | null | undefined
91
+ >;
92
+
93
+ export type DefaultHostedInvokeAgentTrace = <TResult>(
94
+ operationName: string,
95
+ operation: () => TResult,
96
+ ) => TResult;
97
+
98
+ export type DefaultHostedInvokeAgentToolResult =
99
+ | ChildRunExecutionResult
100
+ | HostedDurableChildInvokeResult;
101
+
102
+ export type DefaultHostedInvokeAgentProjectRefresh<
103
+ TContext extends DefaultHostedInvokeAgentContext,
104
+ > = (
105
+ context: TContext,
106
+ ) => Promise<void> | void;
107
+
108
+ export type DefaultHostedInvokeAgentToolOptions<TContext extends DefaultHostedInvokeAgentContext> =
109
+ {
110
+ context: TContext;
111
+ getConfig: () => DefaultHostedInvokeAgentConfig;
112
+ logger: DefaultHostedInvokeAgentLogger;
113
+ trace: DefaultHostedInvokeAgentTrace;
114
+ setTraceAttributes: (attributes: DefaultHostedInvokeAgentTraceAttributes) => void;
115
+ createBashTool: HostedSandboxToolsOptions["createBashTool"];
116
+ resolveModelId: (model: string) => string;
117
+ resolveProvider: (modelId: string) => string;
118
+ resolveProviderOptions?: (
119
+ forkModel: string,
120
+ thinkingConfig: HostedChildForkRuntimeConfig["thinkingConfig"],
121
+ ) => Record<string, unknown> | undefined;
122
+ shouldRethrowError?: (error: unknown) => boolean;
123
+ buildGlobalTools?: (context: TContext) => HostToolSet;
124
+ refreshProjectSkillIds?: DefaultHostedInvokeAgentProjectRefresh<TContext>;
125
+ defaultModel?: string;
126
+ defaultMaxSteps?: number;
127
+ resolveChildAgentId?: (input: DefaultHostedInvokeAgentInput) => string;
128
+ createHostedSandboxTools?: (
129
+ input: HostedSandboxToolsOptions,
130
+ ) => Promise<HostedSandboxToolsResult>;
131
+ createRemoteToolSource?: (config: RemoteMCPToolSourceConfig) => RemoteToolSource;
132
+ createToolsFromRemoteDefinitions?: typeof createToolsFromRemoteDefinitions;
133
+ createLiveStudioTools?: Parameters<typeof prepareDefaultHostedChildForkSandboxToolSources>[0][
134
+ "createLiveStudioTools"
135
+ ];
136
+ };
137
+
138
+ export const defaultHostedInvokeAgentSelectionSchema = z.object({
139
+ agent_id: z.string().optional().describe("Built-in child agent type or user-defined agent id."),
140
+ });
141
+
142
+ export const defaultHostedInvokeAgentInputSchema = hostedChildForkToolInputSchema.extend(
143
+ defaultHostedInvokeAgentSelectionSchema.shape,
144
+ );
145
+
146
+ export type DefaultHostedInvokeAgentInput = z.infer<
147
+ typeof defaultHostedInvokeAgentInputSchema
148
+ >;
149
+
150
+ const DEFAULT_USER_AGENT_MODEL = "opus";
151
+ const DEFAULT_USER_AGENT_MAX_STEPS = 80;
152
+ const DURABLE_INVOKE_CONTEXT_UNAVAILABLE = "DURABLE_INVOKE_CONTEXT_UNAVAILABLE";
153
+ const DURABLE_INVOKE_SETUP_FAILED = "DURABLE_INVOKE_SETUP_FAILED";
154
+
155
+ function resolveDefaultChildAgentId(input: DefaultHostedInvokeAgentInput): string {
156
+ return input.agent_id?.trim() || DEFAULT_HOSTED_CHILD_AGENT_ID;
157
+ }
158
+
159
+ function resolveChildAgentId(
160
+ options: Pick<
161
+ DefaultHostedInvokeAgentToolOptions<DefaultHostedInvokeAgentContext>,
162
+ "resolveChildAgentId"
163
+ >,
164
+ input: DefaultHostedInvokeAgentInput,
165
+ ): string {
166
+ return options.resolveChildAgentId?.(input) ?? resolveDefaultChildAgentId(input);
167
+ }
168
+
169
+ async function refreshProjectSkillIds<TContext extends DefaultHostedInvokeAgentContext>(
170
+ options: Pick<
171
+ DefaultHostedInvokeAgentToolOptions<TContext>,
172
+ "context" | "refreshProjectSkillIds"
173
+ >,
174
+ ): Promise<void> {
175
+ await options.refreshProjectSkillIds?.(options.context);
176
+ }
177
+
178
+ async function applyRequestedProjectId<TContext extends DefaultHostedInvokeAgentContext>(
179
+ options: Pick<
180
+ DefaultHostedInvokeAgentToolOptions<TContext>,
181
+ "context" | "refreshProjectSkillIds"
182
+ >,
183
+ projectId: string,
184
+ ): Promise<void> {
185
+ if (!applyAgentProjectContextChange(options.context, projectId)) {
186
+ return;
187
+ }
188
+
189
+ await refreshProjectSkillIds(options);
190
+ }
191
+
192
+ async function prepareForkToolSources<TContext extends DefaultHostedInvokeAgentContext>(
193
+ options: DefaultHostedInvokeAgentToolOptions<TContext>,
194
+ config: DefaultHostedInvokeAgentConfig,
195
+ abortSignal?: AbortSignal,
196
+ ): Promise<DefaultHostedChildForkToolAssemblySourceResult> {
197
+ throwIfChildRunAborted(abortSignal);
198
+
199
+ const globalTools: HostToolSet = {
200
+ ...(options.buildGlobalTools?.(options.context) ?? {}),
201
+ sleep: sleepTool,
202
+ };
203
+
204
+ return prepareDefaultHostedChildForkSandboxToolSources({
205
+ authToken: options.context.authToken,
206
+ apiUrl: config.apiUrl,
207
+ apiMcpUrl: config.apiMcpUrl,
208
+ studioMcpUrl: config.studioMcpUrl,
209
+ clientProfile: options.context.clientProfile,
210
+ getProjectId: () => options.context.projectId || null,
211
+ conversationId: options.context.conversationId,
212
+ globalTools,
213
+ abortSignal,
214
+ isAbortError: isChildRunAbortError,
215
+ logger: options.logger,
216
+ createBashTool: options.createBashTool,
217
+ createHostedSandboxTools: options.createHostedSandboxTools ?? createHostedSandboxTools,
218
+ createLiveStudioTools: options.createLiveStudioTools ?? createLiveStudioMcpTools,
219
+ createRemoteToolSource: options.createRemoteToolSource ?? createRemoteMCPToolSource,
220
+ createToolsFromRemoteDefinitions: options.createToolsFromRemoteDefinitions ??
221
+ createToolsFromRemoteDefinitions,
222
+ onConfirmedStudioProjectSwitch: (projectId) => applyRequestedProjectId(options, projectId),
223
+ });
224
+ }
225
+
226
+ async function prepareForkToolAssembly<TContext extends DefaultHostedInvokeAgentContext>(
227
+ options: DefaultHostedInvokeAgentToolOptions<TContext>,
228
+ config: DefaultHostedInvokeAgentConfig,
229
+ input: {
230
+ provider: string;
231
+ forkModel: string;
232
+ effectivePrompt: string;
233
+ requestedTools?: HostedChildForkToolInput["tools"];
234
+ abortSignal?: AbortSignal;
235
+ },
236
+ ): Promise<DefaultHostedChildForkToolAssemblyResult> {
237
+ const toolAssembly = await prepareDefaultHostedChildForkToolAssembly({
238
+ prepareToolSources: () => prepareForkToolSources(options, config, input.abortSignal),
239
+ provider: input.provider,
240
+ forkModel: input.forkModel,
241
+ effectivePrompt: input.effectivePrompt,
242
+ requestedTools: input.requestedTools,
243
+ activeProjectId: options.context.projectId || null,
244
+ activeBranchId: options.context.branchId,
245
+ logger: options.logger,
246
+ onSteeringMutation: async (mutation) => {
247
+ if (mutation.instructionsChanged || mutation.skillsChanged) {
248
+ options.context.steeringRevision = (options.context.steeringRevision ?? 0) + 1;
249
+ }
250
+
251
+ if (mutation.skillsChanged) {
252
+ await refreshProjectSkillIds(options);
253
+ }
254
+ },
255
+ });
256
+
257
+ if (toolAssembly.ok) {
258
+ options.context.availableToolNames = toolAssembly.availableToolNames;
259
+ }
260
+
261
+ return toolAssembly;
262
+ }
263
+
264
+ function buildInstrumentation<TContext extends DefaultHostedInvokeAgentContext>(
265
+ options: DefaultHostedInvokeAgentToolOptions<TContext>,
266
+ ) {
267
+ return {
268
+ trace: options.trace,
269
+ setTraceAttributes: options.setTraceAttributes,
270
+ buildToolTraceAttributes: ({ toolName, toolCallId }: {
271
+ toolName: string;
272
+ toolCallId: string | undefined;
273
+ }) =>
274
+ buildExecuteToolTraceAttributes({
275
+ toolName,
276
+ toolCallId,
277
+ }),
278
+ tracePart: async ({ partType }: { partType: string }) => {
279
+ await options.trace("invoke_agent.childStreamPart", async () => {
280
+ options.setTraceAttributes({
281
+ "conversation.id": options.context.conversationId ?? "unknown",
282
+ "run.id": options.context.parentRunId ?? "unknown",
283
+ "stream.part.type": partType,
284
+ });
285
+ });
286
+ },
287
+ debug: (message: string, metadata?: Record<string, unknown>) =>
288
+ options.logger.debug(message, metadata),
289
+ warn: (message: string, metadata?: Record<string, unknown>) =>
290
+ options.logger.warn(message, metadata),
291
+ error: (message: string, metadata?: Record<string, unknown>) =>
292
+ options.logger.error(message, metadata),
293
+ };
294
+ }
295
+
296
+ async function executeForkTask<TContext extends DefaultHostedInvokeAgentContext>(
297
+ options: DefaultHostedInvokeAgentToolOptions<TContext>,
298
+ input: DefaultHostedInvokeAgentInput,
299
+ execution: {
300
+ toolCallId: string;
301
+ abortSignal?: AbortSignal;
302
+ },
303
+ runtimeOptions: {
304
+ onSettled?: (snapshot: ChildRunExecutionSnapshot) => void | Promise<void>;
305
+ durableChildRun?: HostedChildRunIdentifiers;
306
+ } = {},
307
+ ): Promise<ChildRunExecutionResult> {
308
+ const config = options.getConfig();
309
+ const instrumentation = buildInstrumentation(options);
310
+ const writeHostedChildExecutionLog = createHostedChildExecutionLogWriter(options.logger);
311
+
312
+ return executeHostedChildForkToolInput<DefaultHostedInvokeAgentTraceAttributes>({
313
+ apiUrl: config.apiUrl,
314
+ authToken: options.context.authToken,
315
+ projectId: options.context.projectId || null,
316
+ forkInput: input,
317
+ toolCallId: execution.toolCallId,
318
+ contextModel: options.context.model,
319
+ defaultModel: options.defaultModel ?? DEFAULT_USER_AGENT_MODEL,
320
+ defaultMaxSteps: options.defaultMaxSteps ?? DEFAULT_USER_AGENT_MAX_STEPS,
321
+ resolveModelId: options.resolveModelId,
322
+ resolveProvider: options.resolveProvider,
323
+ onRequestedProjectId: (projectId) => applyRequestedProjectId(options, projectId),
324
+ onRuntimeConfig: (runtimeConfig) => {
325
+ options.logger.info("Starting child fork", {
326
+ conversationId: options.context.conversationId,
327
+ parentRunId: options.context.parentRunId,
328
+ description: runtimeConfig.description,
329
+ kind: "invoke_agent",
330
+ model: runtimeConfig.forkModel,
331
+ maxSteps: runtimeConfig.maxSteps,
332
+ requestedTools: runtimeConfig.requestedTools?.length,
333
+ });
334
+ },
335
+ prepareToolAssembly: ({ runtimeConfig, requestedTools, abortSignal }) =>
336
+ prepareForkToolAssembly(options, config, {
337
+ provider: runtimeConfig.provider,
338
+ forkModel: runtimeConfig.forkModel,
339
+ effectivePrompt: runtimeConfig.effectivePrompt,
340
+ requestedTools,
341
+ abortSignal,
342
+ }),
343
+ resolveProviderOptions: options.resolveProviderOptions,
344
+ forkContext: options.context,
345
+ abortSignal: execution.abortSignal,
346
+ durableChildRun: runtimeOptions.durableChildRun,
347
+ conversationId: options.context.conversationId,
348
+ parentRunId: options.context.parentRunId,
349
+ kind: "invoke_agent",
350
+ onSettled: runtimeOptions.onSettled,
351
+ logger: options.logger,
352
+ pendingToolLogWriter: options.logger,
353
+ writeLog: writeHostedChildExecutionLog,
354
+ startRuntime: startHostedChildForkRuntimeWithHostTools,
355
+ shouldRethrowError: options.shouldRethrowError,
356
+ instrumentation,
357
+ });
358
+ }
359
+
360
+ function getToolCallId(executionContext?: ToolExecutionContext): string {
361
+ return typeof executionContext?.toolCallId === "string" && executionContext.toolCallId.length > 0
362
+ ? executionContext.toolCallId
363
+ : `invoke_agent-${dntShim.crypto.randomUUID()}`;
364
+ }
365
+
366
+ function getAbortSignal(executionContext?: ToolExecutionContext): AbortSignal | undefined {
367
+ return executionContext?.abortSignal instanceof AbortSignal
368
+ ? executionContext.abortSignal
369
+ : undefined;
370
+ }
371
+
372
+ export async function executeDefaultHostedInvokeAgentTool<
373
+ TContext extends DefaultHostedInvokeAgentContext,
374
+ >(
375
+ options: DefaultHostedInvokeAgentToolOptions<TContext>,
376
+ input: DefaultHostedInvokeAgentInput,
377
+ childAgentId: string,
378
+ executionContext?: ToolExecutionContext,
379
+ ): Promise<DefaultHostedInvokeAgentToolResult> {
380
+ let executionSnapshot: ChildRunExecutionSnapshot | null = null;
381
+ const config = options.getConfig();
382
+ const toolCallId = getToolCallId(executionContext);
383
+ const abortSignal = getAbortSignal(executionContext);
384
+ const durableInvokeRecorder = createHostedDurableChildInvokeTraceRecorder({
385
+ traceBase: {
386
+ conversationId: options.context.conversationId,
387
+ projectId: options.context.projectId,
388
+ runId: options.context.parentRunId,
389
+ toolCallId,
390
+ childAgentId,
391
+ },
392
+ executionFailedCode: "INVOKE_AGENT_FAILED",
393
+ setTraceAttributes: options.setTraceAttributes,
394
+ });
395
+
396
+ const executeLocalInvoke = (runtimeOptions: HostedDurableChildExecutionOptions = {}) =>
397
+ executeForkTask(
398
+ options,
399
+ input,
400
+ {
401
+ toolCallId,
402
+ abortSignal,
403
+ },
404
+ {
405
+ onSettled: (snapshot) => {
406
+ executionSnapshot = snapshot;
407
+ },
408
+ durableChildRun: runtimeOptions.durableChildRun,
409
+ },
410
+ );
411
+
412
+ durableInvokeRecorder.annotate();
413
+
414
+ if (!config.enableDurableInvokeAgent) {
415
+ return executeHostedLocalChildInvoke({
416
+ forkInput: input,
417
+ abortSignal,
418
+ traceRecorder: durableInvokeRecorder,
419
+ execute: executeLocalInvoke,
420
+ });
421
+ }
422
+
423
+ executionSnapshot = null;
424
+
425
+ try {
426
+ return await executeHostedDurableChildFork<
427
+ HostedDurableChildInvokeResult,
428
+ ChildRunExecutionResult
429
+ >({
430
+ authToken: options.context.authToken,
431
+ apiUrl: config.apiUrl,
432
+ forkInput: input,
433
+ executionOptions: {
434
+ toolCallId,
435
+ abortSignal,
436
+ },
437
+ childAgentId,
438
+ runProjectId: input.project_id ?? options.context.projectId,
439
+ parentConversationId: options.context.conversationId,
440
+ parentRunId: options.context.parentRunId,
441
+ parentMessageId: options.context.parentMessageId,
442
+ getProjectId: () => options.context.projectId,
443
+ getBranchId: () => options.context.branchId,
444
+ getContextModel: () => options.context.model,
445
+ defaultModel: options.defaultModel ?? DEFAULT_USER_AGENT_MODEL,
446
+ resolveModelId: options.resolveModelId,
447
+ resolveProvider: options.resolveProvider,
448
+ onRequestedProjectId: (projectId) => applyRequestedProjectId(options, projectId),
449
+ publishParentRunEvents: options.context.publishParentRunEvents,
450
+ contextUnavailableMessage:
451
+ "invoke_agent requires durable conversation context when durable child runs are enabled.",
452
+ setupFailedCode: DURABLE_INVOKE_SETUP_FAILED,
453
+ executionFailedCode: "INVOKE_AGENT_FAILED",
454
+ executeLocal: executeLocalInvoke,
455
+ getExecutionSnapshot: () => executionSnapshot,
456
+ buildContextUnavailableResult: (message) => {
457
+ durableInvokeRecorder.annotate({
458
+ status: "failed",
459
+ terminalErrorCode: DURABLE_INVOKE_CONTEXT_UNAVAILABLE,
460
+ terminalErrorMessage: message,
461
+ });
462
+
463
+ return buildHostedDurableChildInvokeFailureResult({
464
+ terminalErrorCode: DURABLE_INVOKE_CONTEXT_UNAVAILABLE,
465
+ terminalErrorMessage: message,
466
+ });
467
+ },
468
+ buildSetupFailureResult: (failure) => durableInvokeRecorder.recordSetupFailure(failure),
469
+ buildTerminalFailureResult: (failure) => durableInvokeRecorder.recordTerminalFailure(failure),
470
+ buildSuccessResult: (success) => durableInvokeRecorder.recordSuccess(success),
471
+ runtime: {
472
+ bootstrapChildRun: bootstrapHostedChildRun,
473
+ createLifecycleAdapter: createConversationChildLifecycleAdapter,
474
+ runLifecycle: runHostedChildExecutionLifecycle,
475
+ shouldSkipTerminalPersistence: shouldSkipHostedChildTerminalPersistence,
476
+ },
477
+ bootstrap: {
478
+ runBootstrap: (operation) =>
479
+ options.trace("invoke_agent.durableChildSetup", async () => {
480
+ options.setTraceAttributes({
481
+ "conversation.id": options.context.conversationId,
482
+ "run.id": options.context.parentRunId,
483
+ "tool.call.id": toolCallId,
484
+ });
485
+
486
+ return operation();
487
+ }),
488
+ onBootstrapStart: (bootstrapContext) => {
489
+ options.logger.info("Bootstrapping durable child run", {
490
+ parentConversationId: bootstrapContext.parentConversationId,
491
+ parentRunId: bootstrapContext.parentRunId,
492
+ toolCallId,
493
+ childAgentId,
494
+ description: input.description,
495
+ });
496
+ },
497
+ onBootstrapComplete: (bootstrapContext) => {
498
+ options.logger.info("Durable child bootstrap complete", {
499
+ parentConversationId: bootstrapContext.parentConversationId,
500
+ childConversationId: bootstrapContext.identifiers.childConversationId,
501
+ childRunId: bootstrapContext.identifiers.childRunId,
502
+ childMessageId: bootstrapContext.identifiers.childMessageId,
503
+ toolCallId,
504
+ });
505
+ },
506
+ onBootstrapError: ({ error, parentConversationId }) => {
507
+ options.logger.warn("Durable child-run persistence failed", {
508
+ parentConversationId,
509
+ toolCallId,
510
+ error: error instanceof Error ? error.message : String(error),
511
+ });
512
+ },
513
+ },
514
+ onLifecycleError: (error) => {
515
+ options.logger.warn("Durable child lifecycle adapter failed", {
516
+ toolCallId,
517
+ error: error instanceof Error ? error.message : String(error),
518
+ });
519
+ },
520
+ onLifecycleFinalized: ({ identifiers, status }) =>
521
+ options.trace("invoke_agent.durableChildFinalize", async () => {
522
+ options.setTraceAttributes({
523
+ "child.conversation.id": identifiers.childConversationId,
524
+ "child.run.id": identifiers.childRunId,
525
+ "child.message.id": identifiers.childMessageId,
526
+ "agent.run.final_status": status,
527
+ });
528
+ }),
529
+ });
530
+ } catch (error) {
531
+ durableInvokeRecorder.recordLocalFailure(
532
+ error instanceof Error ? error.message : String(error),
533
+ );
534
+ throw error;
535
+ }
536
+ }
537
+
538
+ export function createDefaultHostedInvokeAgentTool<
539
+ TContext extends DefaultHostedInvokeAgentContext,
540
+ >(
541
+ options: DefaultHostedInvokeAgentToolOptions<TContext>,
542
+ ) {
543
+ return createHostedChildInvokeTool<
544
+ DefaultHostedInvokeAgentInput,
545
+ DefaultHostedInvokeAgentToolResult
546
+ >({
547
+ inputSchema: defaultHostedInvokeAgentInputSchema,
548
+ additionalDescriptionParts: [
549
+ "Use agent_id to target a specific built-in or custom child agent.",
550
+ ],
551
+ buildFailureResult: buildHostedDurableChildInvokeFailureResult,
552
+ decorateResult: withRootOwnedChildResultHint,
553
+ execute: (input, executionOptions) =>
554
+ executeDefaultHostedInvokeAgentTool(
555
+ options,
556
+ input,
557
+ resolveChildAgentId(options, input),
558
+ executionOptions,
559
+ ),
560
+ });
561
+ }
@@ -822,6 +822,21 @@ export {
822
822
  type CreateHostedChildInvokeToolOptions,
823
823
  type HostedChildInvokeFailure,
824
824
  } from "./hosted-child-invoke-tool.js";
825
+ export {
826
+ createDefaultHostedInvokeAgentTool,
827
+ type DefaultHostedInvokeAgentConfig,
828
+ type DefaultHostedInvokeAgentContext,
829
+ type DefaultHostedInvokeAgentInput,
830
+ defaultHostedInvokeAgentInputSchema,
831
+ type DefaultHostedInvokeAgentLogger,
832
+ type DefaultHostedInvokeAgentProjectRefresh,
833
+ defaultHostedInvokeAgentSelectionSchema,
834
+ type DefaultHostedInvokeAgentToolOptions,
835
+ type DefaultHostedInvokeAgentToolResult,
836
+ type DefaultHostedInvokeAgentTrace,
837
+ type DefaultHostedInvokeAgentTraceAttributes,
838
+ executeDefaultHostedInvokeAgentTool,
839
+ } from "./default-hosted-invoke-agent-tool.js";
825
840
  export {
826
841
  buildDefaultHostedChildForkToolSet,
827
842
  buildHostedChildToolDescription,
@@ -1,3 +1,3 @@
1
1
  // Keep in sync with deno.json version.
2
2
  // scripts/release.ts updates this constant during releases.
3
- export const VERSION = "0.1.479";
3
+ export const VERSION = "0.1.480";