|
| 1 | +/** |
| 2 | + * Adapts runtime AgentTool objects into session ToolDefinition entries. |
| 3 | + * Owns hook execution, client-tool delegation, result coercion, and safe |
| 4 | + * logging for failed tool calls. |
| 5 | + */ |
1 | 6 | import { createHash } from "node:crypto"; |
2 | 7 | import { logDebug, logError } from "../logger.js"; |
3 | 8 | import { redactToolDetail } from "../logging/redact.js"; |
@@ -304,6 +309,7 @@ function finalizeToolParamsBeforeExecute(params: { |
304 | 309 |
|
305 | 310 | export const CLIENT_TOOL_NAME_CONFLICT_PREFIX = "client tool name conflict:"; |
306 | 311 |
|
| 312 | +/** Find client-hosted tool names that collide with runtime or sibling tools. */ |
307 | 313 | export function findClientToolNameConflicts(params: { |
308 | 314 | tools: ClientToolDefinition[]; |
309 | 315 | existingToolNames?: Iterable<string>; |
@@ -338,14 +344,17 @@ export function findClientToolNameConflicts(params: { |
338 | 344 | return Array.from(conflicts); |
339 | 345 | } |
340 | 346 |
|
| 347 | +/** Build a recognizable error for rejecting conflicting client tool names. */ |
341 | 348 | export function createClientToolNameConflictError(conflicts: string[]): Error { |
342 | 349 | return new Error(`${CLIENT_TOOL_NAME_CONFLICT_PREFIX} ${conflicts.join(", ")}`); |
343 | 350 | } |
344 | 351 |
|
| 352 | +/** Detect client tool conflict errors without depending on object identity. */ |
345 | 353 | export function isClientToolNameConflictError(err: unknown): err is Error { |
346 | 354 | return err instanceof Error && err.message.startsWith(CLIENT_TOOL_NAME_CONFLICT_PREFIX); |
347 | 355 | } |
348 | 356 |
|
| 357 | +/** Convert executable agent tools into session definitions with hook handling. */ |
349 | 358 | export function toToolDefinitions( |
350 | 359 | tools: AnyAgentTool[], |
351 | 360 | hookContext?: HookContext, |
@@ -477,8 +486,7 @@ function coerceParamsRecord(value: unknown): Record<string, unknown> { |
477 | 486 | return {}; |
478 | 487 | } |
479 | 488 |
|
480 | | -// Convert client tools (OpenResponses hosted tools) to ToolDefinition format |
481 | | -// These tools are intercepted to return a "pending" result instead of executing |
| 489 | +/** Convert client-hosted tools into pending session definitions. */ |
482 | 490 | export function toClientToolDefinitions( |
483 | 491 | tools: ClientToolDefinition[], |
484 | 492 | onClientToolCall?: ClientToolCallRecorder, |
|
0 commit comments