@yourgpt/copilot-sdk 2.1.5-alpha.1 → 2.1.5-alpha.2
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.
- package/dist/{chunk-4QXY2PBG.js → chunk-3AONOZLY.js} +2 -2
- package/dist/{chunk-4QXY2PBG.js.map → chunk-3AONOZLY.js.map} +1 -1
- package/dist/{chunk-JKGFQUHJ.cjs → chunk-MDS23G2S.cjs} +5 -5
- package/dist/{chunk-JKGFQUHJ.cjs.map → chunk-MDS23G2S.cjs.map} +1 -1
- package/dist/{chunk-5Q72LZ5H.js → chunk-PT2TOHG5.js} +7 -3
- package/dist/chunk-PT2TOHG5.js.map +1 -0
- package/dist/{chunk-ENFWM3EY.js → chunk-RKGRQRZU.js} +3 -3
- package/dist/{chunk-ENFWM3EY.js.map → chunk-RKGRQRZU.js.map} +1 -1
- package/dist/{chunk-IXWNDR7H.cjs → chunk-TCPAT3WG.cjs} +35 -31
- package/dist/chunk-TCPAT3WG.cjs.map +1 -0
- package/dist/{chunk-246B6X5D.cjs → chunk-TPB7XED6.cjs} +2 -2
- package/dist/{chunk-246B6X5D.cjs.map → chunk-TPB7XED6.cjs.map} +1 -1
- package/dist/{chunk-I3SQUNTT.cjs → chunk-WIXFZUEZ.cjs} +23 -23
- package/dist/{chunk-I3SQUNTT.cjs.map → chunk-WIXFZUEZ.cjs.map} +1 -1
- package/dist/{chunk-UXJ6LIZB.js → chunk-WZ2TOZ7M.js} +4 -4
- package/dist/{chunk-UXJ6LIZB.js.map → chunk-WZ2TOZ7M.js.map} +1 -1
- package/dist/core/index.cjs +82 -82
- package/dist/core/index.d.cts +3 -3
- package/dist/core/index.d.ts +3 -3
- package/dist/core/index.js +3 -3
- package/dist/{index-CiExk87c.d.cts → index-CzJB8Ddo.d.cts} +1 -1
- package/dist/{index-Dwrcf-CP.d.ts → index-D7169xuR.d.ts} +1 -1
- package/dist/mcp/index.d.cts +3 -3
- package/dist/mcp/index.d.ts +3 -3
- package/dist/react/index.cjs +65 -65
- package/dist/react/index.d.cts +8 -4
- package/dist/react/index.d.ts +8 -4
- package/dist/react/index.js +4 -4
- package/dist/styles.css +43 -0
- package/dist/tools/anthropic/index.d.cts +1 -1
- package/dist/tools/anthropic/index.d.ts +1 -1
- package/dist/tools/brave/index.cjs +2 -2
- package/dist/tools/brave/index.d.cts +1 -1
- package/dist/tools/brave/index.d.ts +1 -1
- package/dist/tools/brave/index.js +1 -1
- package/dist/tools/exa/index.cjs +2 -2
- package/dist/tools/exa/index.d.cts +1 -1
- package/dist/tools/exa/index.d.ts +1 -1
- package/dist/tools/exa/index.js +1 -1
- package/dist/tools/google/index.cjs +2 -2
- package/dist/tools/google/index.d.cts +1 -1
- package/dist/tools/google/index.d.ts +1 -1
- package/dist/tools/google/index.js +1 -1
- package/dist/tools/openai/index.cjs +2 -2
- package/dist/tools/openai/index.d.cts +1 -1
- package/dist/tools/openai/index.d.ts +1 -1
- package/dist/tools/openai/index.js +1 -1
- package/dist/tools/searxng/index.cjs +2 -2
- package/dist/tools/searxng/index.d.cts +1 -1
- package/dist/tools/searxng/index.d.ts +1 -1
- package/dist/tools/searxng/index.js +1 -1
- package/dist/tools/serper/index.cjs +2 -2
- package/dist/tools/serper/index.d.cts +1 -1
- package/dist/tools/serper/index.d.ts +1 -1
- package/dist/tools/serper/index.js +1 -1
- package/dist/tools/tavily/index.cjs +2 -2
- package/dist/tools/tavily/index.d.cts +1 -1
- package/dist/tools/tavily/index.d.ts +1 -1
- package/dist/tools/tavily/index.js +1 -1
- package/dist/tools/web-search/index.cjs +3 -3
- package/dist/tools/web-search/index.d.cts +2 -2
- package/dist/tools/web-search/index.d.ts +2 -2
- package/dist/tools/web-search/index.js +2 -2
- package/dist/{tools-DHZhF5km.d.cts → tools-tmksfhUo.d.cts} +9 -0
- package/dist/{tools-DHZhF5km.d.ts → tools-tmksfhUo.d.ts} +9 -0
- package/dist/{types-BdX7uPj0.d.cts → types-BLw7mxtW.d.cts} +1 -1
- package/dist/{types-BTyJu0WD.d.ts → types-BqwW3Baj.d.ts} +1 -1
- package/dist/ui/index.cjs +291 -301
- package/dist/ui/index.cjs.map +1 -1
- package/dist/ui/index.d.cts +40 -56
- package/dist/ui/index.d.ts +40 -56
- package/dist/ui/index.js +238 -248
- package/dist/ui/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-5Q72LZ5H.js.map +0 -1
- package/dist/chunk-IXWNDR7H.cjs.map +0 -1
|
@@ -76,5 +76,5 @@ exports.success = success;
|
|
|
76
76
|
exports.tool = tool;
|
|
77
77
|
exports.toolToAnthropicFormat = toolToAnthropicFormat;
|
|
78
78
|
exports.toolToOpenAIFormat = toolToOpenAIFormat;
|
|
79
|
-
//# sourceMappingURL=chunk-
|
|
80
|
-
//# sourceMappingURL=chunk-
|
|
79
|
+
//# sourceMappingURL=chunk-TPB7XED6.cjs.map
|
|
80
|
+
//# sourceMappingURL=chunk-TPB7XED6.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/core/types/tools.ts"],"names":["tool"],"mappings":";;;AAw8BO,SAAS,KACd,MAAA,EACuC;AACvC,EAAA,OAAO;AAAA,IACL,aAAa,MAAA,CAAO,WAAA;AAAA,IACpB,QAAA,EAAU,OAAO,QAAA,IAAY,QAAA;AAAA,IAC7B,UAAU,MAAA,CAAO,QAAA;AAAA,IACjB,OAAO,MAAA,CAAO,KAAA;AAAA,IACd,cAAc,MAAA,CAAO,YAAA;AAAA,IACrB,UAAU,MAAA,CAAO,QAAA;AAAA,IACjB,gBAAgB,MAAA,CAAO,cAAA;AAAA,IACvB,cAAc,MAAA,CAAO,YAAA;AAAA;AAAA,IAErB,OAAO,MAAA,CAAO,KAAA;AAAA,IACd,gBAAgB,MAAA,CAAO,cAAA;AAAA,IACvB,gBAAgB,MAAA,CAAO,cAAA;AAAA;AAAA,IAEvB,WAAA,EAAa,OAAO,WAAA,IAAe;AAAA,MACjC,IAAA,EAAM,QAAA;AAAA,MACN,YAAY,EAAC;AAAA,MACb,UAAU;AAAC,KACb;AAAA,IACA,SAAS,MAAA,CAAO,OAAA;AAAA,IAChB,QAAQ,MAAA,CAAO,MAAA;AAAA,IACf,WAAW,MAAA,CAAO,SAAA;AAAA,IAClB,QAAQ,MAAA,CAAO,MAAA;AAAA,IACf,eAAe,MAAA,CAAO,aAAA;AAAA,IACtB,iBAAiB,MAAA,CAAO,eAAA;AAAA,IACxB,gBAAgB,MAAA,CAAO,cAAA;AAAA,IACvB,WAAW,MAAA,CAAO;AAAA,GACpB;AACF;AASO,SAAS,mBAAmBA,KAAAA,EAA8B;AAC/D,EAAA,OAAO;AAAA,IACL,IAAA,EAAM,UAAA;AAAA,IACN,QAAA,EAAU;AAAA,MACR,MAAMA,KAAAA,CAAK,IAAA;AAAA,MACX,aAAaA,KAAAA,CAAK,WAAA;AAAA,MAClB,YAAYA,KAAAA,CAAK;AAAA;AACnB,GACF;AACF;AAKO,SAAS,sBAAsBA,KAAAA,EAA8B;AAClE,EAAA,OAAO;AAAA,IACL,MAAMA,KAAAA,CAAK,IAAA;AAAA,IACX,aAAaA,KAAAA,CAAK,WAAA;AAAA,IAClB,cAAcA,KAAAA,CAAK;AAAA,GACrB;AACF;AAKO,SAAS,gBAAA,CACd,YACA,QAAA,EACmB;AACnB,EAAA,OAAO;AAAA,IACL,UAAA;AAAA,IACA,OAAA,EAAS,IAAA,CAAK,SAAA,CAAU,QAAQ,CAAA;AAAA,IAChC,SAAS,QAAA,CAAS,OAAA;AAAA,IAClB,OAAO,QAAA,CAAS;AAAA,GAClB;AACF;AAKO,SAAS,OAAA,CACd,MACA,OAAA,EACiB;AACjB,EAAA,OAAO;AAAA,IACL,OAAA,EAAS,IAAA;AAAA,IACT,IAAA;AAAA,IACA;AAAA,GACF;AACF;AAKO,SAAS,QAAQ,KAAA,EAA6B;AACnD,EAAA,OAAO;AAAA,IACL,OAAA,EAAS,KAAA;AAAA,IACT;AAAA,GACF;AACF","file":"chunk-246B6X5D.cjs","sourcesContent":["/**\n * Tool-related types for the agentic loop\n */\n\nimport type { ActionRenderProps } from \"./actions\";\n\n// ============================================\n// Provider Types\n// ============================================\n\n/**\n * Supported AI providers for tool calling\n */\nexport type AIProvider =\n | \"anthropic\"\n | \"openai\"\n | \"xai\"\n | \"grok\"\n | \"gemini\"\n | \"groq\"\n | \"ollama\";\n\n/**\n * Where the tool executes\n */\nexport type ToolLocation = \"server\" | \"client\";\n\n/**\n * Source/origin of the tool\n * - \"mcp\": Tool from an MCP (Model Context Protocol) server\n * - \"native\": Built-in SDK tool\n * - \"custom\": User-defined tool\n */\nexport type ToolSource = \"mcp\" | \"native\" | \"custom\";\n\n// ============================================\n// Tool Definition Types\n// ============================================\n\n/**\n * JSON Schema property definition\n */\nexport interface JSONSchemaProperty {\n type:\n | \"string\"\n | \"number\"\n | \"boolean\"\n | \"object\"\n | \"array\"\n | \"integer\"\n | \"null\";\n description?: string;\n enum?: (string | number | boolean)[];\n items?: JSONSchemaProperty;\n properties?: Record<string, JSONSchemaProperty>;\n required?: string[];\n default?: unknown;\n minLength?: number;\n maxLength?: number;\n minimum?: number;\n maximum?: number;\n pattern?: string;\n}\n\n/**\n * JSON Schema for tool input\n */\nexport interface ToolInputSchema {\n type: \"object\";\n properties: Record<string, JSONSchemaProperty>;\n required?: string[];\n additionalProperties?: boolean;\n}\n\n/**\n * Tool execution context\n *\n * Provides runtime information to tool handlers including cancellation signals,\n * request metadata, and custom context data.\n */\nexport interface ToolContext {\n /** Abort signal for cancellation */\n signal?: AbortSignal;\n /** Thread ID if using threads */\n threadId?: string;\n /** Custom context data passed from runtime config */\n data?: Record<string, unknown>;\n\n // ============================================\n // Rich Context (Vercel AI SDK pattern)\n // ============================================\n\n /**\n * Unique ID for this specific tool call.\n * Useful for logging, tracing, and correlating tool executions.\n */\n toolCallId?: string;\n\n /**\n * Request headers (for auth in server tools).\n * Contains headers from the original HTTP request.\n *\n * @example\n * ```typescript\n * handler: async (params, context) => {\n * const token = context?.headers?.authorization;\n * if (!token) return failure('Authentication required');\n * // ...\n * }\n * ```\n */\n headers?: Record<string, string>;\n\n /**\n * Full request metadata for server-side tools.\n * Provides access to HTTP method, URL, and headers.\n *\n * @example\n * ```typescript\n * handler: async (params, context) => {\n * console.log(`Tool called from: ${context?.request?.url}`);\n * // Forward auth to internal service\n * const authHeader = context?.request?.headers?.authorization;\n * }\n * ```\n */\n request?: {\n /** HTTP method (GET, POST, etc.) */\n method?: string;\n /** Request URL path */\n url?: string;\n /** Request headers */\n headers?: Record<string, string>;\n };\n\n /**\n * Data passed from user's approval action.\n * Only present when tool has `needsApproval: true` and user approved with extra data.\n *\n * @example\n * ```typescript\n * // In render function:\n * approval.onApprove({ supervisor: selectedSupervisor });\n *\n * // In handler:\n * handler: async (params, context) => {\n * const supervisor = context?.approvalData?.supervisor;\n * await assignToSupervisor(params.ticketId, supervisor);\n * }\n * ```\n */\n approvalData?: Record<string, unknown>;\n}\n\n// ============================================\n// AI Response Control Types\n// ============================================\n\n/**\n * AI response behavior for tool results.\n *\n * Controls what the AI sees after a tool executes and renders UI.\n *\n * - `'none'`: AI generates minimal response, UI component handles display\n * - `'brief'`: AI gets summary context (via aiContext), gives brief acknowledgment\n * - `'full'`: AI receives full data and responds accordingly (default)\n */\nexport type AIResponseMode = \"none\" | \"brief\" | \"full\";\n\n/**\n * Multimodal content for AI to analyze\n */\nexport type AIContent =\n | { type: \"image\"; data: string; mediaType: string }\n | { type: \"text\"; text: string };\n\n/**\n * How large tool results should be trimmed before they are sent back to the AI.\n */\nexport type ToolTruncationStrategy = \"head\" | \"head-tail\" | \"smart\";\n\n/**\n * Truncation controls for tool results.\n */\nexport interface ToolResultTruncationConfig {\n enabled?: boolean;\n maxContextShare?: number;\n hardMaxChars?: number;\n minKeepChars?: number;\n strategy?: ToolTruncationStrategy;\n preserveErrors?: boolean;\n}\n\n/**\n * Global or per-tool controls for how tool results are represented in prompts.\n */\nexport interface ToolResultConfig {\n truncation?: ToolResultTruncationConfig;\n}\n\n/**\n * Named tool profile for selective loading.\n */\nexport interface ToolProfile {\n name: string;\n description?: string;\n include?: string[];\n exclude?: string[];\n}\n\n/**\n * Tool profile configuration.\n */\nexport interface ToolProfileConfig {\n enabled?: boolean;\n defaultProfile?: string;\n profiles?: Record<string, ToolProfile>;\n /** When false, active profiles exclude tools that do not declare profile membership. */\n includeUnprofiled?: boolean;\n dynamicSelection?: {\n enabled?: boolean;\n maxTools?: number;\n };\n}\n\n/**\n * History compaction behavior for long-running sessions.\n */\nexport interface ContextHistoryConfig {\n maxMessages?: number;\n maxTokens?: number;\n maxContextShare?: number;\n pruneStrategy?: \"oldest\" | \"least-relevant\" | \"summarize\";\n}\n\n/**\n * Optional summarization controls used during history compaction.\n */\nexport interface ContextSummarizationConfig {\n enabled?: boolean;\n triggerAt?: number;\n chunkSize?: number;\n preserveRecent?: number;\n fallbackBehavior?: \"truncate\" | \"statistical\" | \"error\";\n}\n\n/**\n * Token estimation controls.\n */\nexport interface TokenEstimationConfig {\n safetyMargin?: number;\n charsPerToken?: number;\n}\n\n/**\n * Conversation context management.\n */\nexport interface ContextManagementConfig {\n enabled?: boolean;\n history?: ContextHistoryConfig;\n summarization?: ContextSummarizationConfig;\n tokenEstimation?: TokenEstimationConfig;\n}\n\n/**\n * One budget bucket in the prompt context.\n */\nexport interface ContextUsagePart {\n tokens: number;\n percent: number;\n}\n\n/**\n * Prompt context usage snapshot.\n */\nexport interface ContextUsage {\n total: ContextUsagePart;\n breakdown: {\n systemPrompt: ContextUsagePart;\n history: ContextUsagePart;\n toolResults: ContextUsagePart;\n tools: ContextUsagePart;\n };\n budget: {\n available: number;\n remaining: number;\n };\n warnings: string[];\n}\n\n/**\n * Real-time context budget configuration.\n */\nexport interface ContextBudgetConfig {\n enabled?: boolean;\n budget?: {\n contextWindowTokens?: number;\n inputHeadroomRatio?: number;\n systemPromptShare?: number;\n historyShare?: number;\n toolResultsShare?: number;\n toolDefinitionsShare?: number;\n };\n enforcement?: {\n mode?: \"warn\" | \"truncate\" | \"error\";\n onBudgetExceeded?: (info: ContextUsage) => void;\n };\n monitoring?: {\n enabled?: boolean;\n onUsageUpdate?: (usage: ContextUsage) => void;\n };\n}\n\n/**\n * Framework-agnostic optimization controls for tool-heavy chat sessions.\n */\nexport interface ToolOptimizationConfig {\n toolProfiles?: ToolProfileConfig;\n toolResultConfig?: ToolResultConfig;\n contextManagement?: ContextManagementConfig;\n contextBudget?: ContextBudgetConfig;\n}\n\n/**\n * Tool response format\n */\nexport interface ToolResponse<T = unknown> {\n /** Whether the tool succeeded */\n success: boolean;\n /** Human-readable message */\n message?: string;\n /** Error message if failed */\n error?: string;\n /** Result data */\n data?: T;\n\n // ============================================\n // AI Response Control (result-level overrides)\n // ============================================\n\n /**\n * Override AI context for this specific result.\n * Takes precedence over tool-level aiContext config.\n * If set, this message is sent to AI instead of full result data.\n *\n * @example\n * ```typescript\n * return {\n * success: true,\n * data: sensitiveData,\n * _aiContext: '[Data retrieved - contains sensitive info, displayed to user]'\n * };\n * ```\n */\n _aiContext?: string;\n\n /**\n * Override AI response mode for this specific result.\n * Takes precedence over tool-level aiResponseMode config.\n */\n _aiResponseMode?: AIResponseMode;\n\n /**\n * Content for AI to analyze (images, documents, etc.).\n * When present, these are included as multimodal content for AI analysis.\n *\n * @example\n * ```typescript\n * // Screenshot for AI to analyze\n * return {\n * success: true,\n * message: 'Screenshot captured',\n * _aiContent: [{ type: 'image', data: base64, mediaType: 'image/png' }]\n * };\n * ```\n */\n _aiContent?: AIContent[];\n\n /**\n * MCP-UI resources for rendering interactive UI components.\n * These are extracted from MCP tool results and rendered as iframes.\n * Not sent to the AI - purely for UI rendering.\n *\n * @example\n * ```typescript\n * // MCP tool returning UI\n * return {\n * success: true,\n * message: 'Product displayed',\n * _uiResources: [{\n * uri: 'ui://shop/product/123',\n * mimeType: 'text/html',\n * content: '<div class=\"product\">...</div>',\n * metadata: { height: '300px' }\n * }]\n * };\n * ```\n */\n _uiResources?: Array<{\n uri: string;\n mimeType:\n | \"text/html\"\n | \"text/uri-list\"\n | \"application/vnd.mcp-ui.remote-dom\";\n content?: string;\n blob?: string;\n metadata?: {\n title?: string;\n width?: string;\n height?: string;\n sandbox?: string[];\n className?: string;\n };\n }>;\n}\n\n/**\n * Approval callbacks passed to render when tool requires user action.\n * Only present when status is \"approval-required\".\n */\nexport interface ToolApprovalCallbacks {\n /**\n * Approve execution and optionally pass extra data to the handler.\n * The extraData is available in handler via `context.approvalData`.\n *\n * @example\n * ```tsx\n * // Simple approval\n * approval.onApprove();\n *\n * // Approval with data (e.g., user selection)\n * approval.onApprove({ supervisor: { name: \"John\", role: \"Manager\" } });\n * ```\n */\n onApprove: (extraData?: Record<string, unknown>) => void;\n\n /**\n * Reject the tool execution with optional reason.\n * This stops the tool from executing and returns an error to AI.\n */\n onReject: (reason?: string) => void;\n\n /** Custom message from tool's approvalMessage config */\n message?: string;\n}\n\n/**\n * Props passed to tool render function.\n *\n * The render function is called for every status change, enabling\n * full lifecycle rendering similar to Vercel AI SDK.\n *\n * @example\n * ```tsx\n * render: ({ status, args, approval, result }) => {\n * if (status === \"approval-required\" && approval) {\n * return <ApprovalCard onConfirm={() => approval.onApprove()} />;\n * }\n * if (status === \"executing\") {\n * return <LoadingSkeleton />;\n * }\n * if (status === \"completed\") {\n * return <ResultCard data={result.data} />;\n * }\n * return null;\n * }\n * ```\n */\nexport interface ToolRenderProps<TParams = Record<string, unknown>> {\n /**\n * Current execution status:\n * - `pending`: Tool call received, waiting to start\n * - `approval-required`: Waiting for user approval (when needsApproval is set)\n * - `executing`: Handler is running\n * - `completed`: Handler finished successfully\n * - `error`: Handler failed\n */\n status: \"pending\" | \"approval-required\" | \"executing\" | \"completed\" | \"error\";\n\n /** Arguments passed to the tool */\n args: TParams;\n\n /** Result if completed */\n result?: ToolResponse;\n\n /** Error if failed */\n error?: string;\n\n /** Tool call ID */\n toolCallId: string;\n\n /** Tool name */\n toolName: string;\n\n /**\n * Approval callbacks - only present when status is \"approval-required\".\n * Use these to create custom approval UIs that can pass extra data to the handler.\n */\n approval?: ToolApprovalCallbacks;\n}\n\n/**\n * Tool definition with JSON Schema\n */\nexport interface ToolDefinition<TParams = Record<string, unknown>> {\n /** Unique tool name */\n name: string;\n /** Tool description for LLM */\n description: string;\n /** Where the tool executes (server or client) */\n location: ToolLocation;\n /**\n * Source/origin of the tool.\n * Used to distinguish MCP tools from native/custom tools for UI rendering.\n * @default \"custom\"\n */\n source?: ToolSource;\n /** Optional category for search, filtering, and budgets */\n category?: string;\n /** Optional group for profile-based tool selection */\n group?: string;\n /** Deferred tools are discoverable but need not be sent on every request */\n deferLoading?: boolean;\n /** Profile memberships for selective tool loading */\n profiles?: string[];\n /** Extra keywords for dynamic tool selection */\n searchKeywords?: string[];\n /** Per-tool prompt/result shaping controls */\n resultConfig?: ToolResultConfig;\n\n // ============================================\n // Display Configuration\n // ============================================\n\n /**\n * Human-readable title for UI display.\n * Can be a static string or a function that generates title from args.\n *\n * @example\n * ```typescript\n * title: \"Get order details\"\n * // or dynamic:\n * title: (args) => `Order #${args.orderId}`\n * ```\n */\n title?: string | ((args: TParams) => string);\n\n /**\n * Title shown while executing (present tense with \"...\").\n * If not provided, uses `title` with \"...\" appended.\n *\n * @example\n * ```typescript\n * executingTitle: (args) => `Fetching order #${args.orderId}...`\n * ```\n */\n executingTitle?: string | ((args: TParams) => string);\n\n /**\n * Title shown after completion.\n * If not provided, defaults to `title`.\n *\n * @example\n * ```typescript\n * completedTitle: (args) => `Retrieved order #${args.orderId}`\n * ```\n */\n completedTitle?: string | ((args: TParams) => string);\n /** JSON Schema for input parameters */\n inputSchema: ToolInputSchema;\n /** Handler function (optional for client tools registered on server) */\n handler?: (\n params: TParams,\n context?: ToolContext,\n ) => Promise<ToolResponse> | ToolResponse;\n /** Optional render function for UI */\n render?: (props: ToolRenderProps<TParams>) => unknown;\n /** Whether the tool is available (for conditional registration) */\n available?: boolean;\n\n /**\n * Hide this tool's execution from the chat UI.\n * When true, tool calls and results won't be displayed to the user,\n * but the tool will still execute normally.\n * @default false\n */\n hidden?: boolean;\n\n /**\n * Require user approval before execution.\n * Can be:\n * - `true`: Always require approval\n * - `false` or `undefined`: No approval needed (default)\n * - `(params) => boolean`: Conditional approval based on input\n *\n * Similar to Vercel AI SDK v6's needsApproval pattern.\n */\n needsApproval?: boolean | ((params: TParams) => boolean | Promise<boolean>);\n\n /**\n * Custom message shown in the approval UI.\n * Can be a string or a function that generates a message from params.\n * If not provided, a default message with the tool name is shown.\n */\n approvalMessage?: string | ((params: TParams) => string);\n\n // ============================================\n // AI Response Control\n // ============================================\n\n /**\n * How the AI should respond when this tool's result is rendered as UI.\n *\n * - `'none'`: AI generates minimal response (\"[Result displayed to user]\").\n * Use for tools where UI component fully handles the display (stats cards, etc.)\n *\n * - `'brief'`: AI receives summary context (from aiContext) and gives brief acknowledgment.\n * Use for charts/visualizations where AI should acknowledge but not repeat data.\n *\n * - `'full'`: AI receives complete data and responds accordingly (default).\n * Use for tools where AI should analyze and elaborate on results.\n *\n * @default 'full'\n *\n * @example\n * ```typescript\n * // Chart tool - AI acknowledges without repeating data\n * const chartTool: ToolDefinition = {\n * name: 'get_chart',\n * aiResponseMode: 'brief',\n * aiContext: (result) => `[Chart displayed: ${result.data.title}]`,\n * handler: async () => ({ success: true, data: chartData })\n * };\n * ```\n */\n aiResponseMode?: AIResponseMode;\n\n /**\n * Context/summary sent to AI instead of (or along with) full result.\n *\n * Used when:\n * - `aiResponseMode: 'brief'` - This becomes the only thing AI sees\n * - `aiResponseMode: 'full'` - This is prepended to full data for context\n *\n * Can be:\n * - `string`: Static message (e.g., \"[Weather data displayed]\")\n * - `function`: Dynamic based on result (e.g., (result) => `[Chart: ${result.data.title}]`)\n *\n * @example\n * ```typescript\n * // Static context\n * aiContext: '[Analytics chart displayed to user]'\n *\n * // Dynamic context based on result\n * aiContext: (result, args) => {\n * const { title, currentValue } = result.data;\n * return `[Chart displayed: ${title}, showing ${currentValue}]`;\n * }\n * ```\n */\n aiContext?:\n | string\n | ((result: ToolResponse, args: Record<string, unknown>) => string);\n}\n\n// ============================================\n// Unified Tool Call Types (Provider-Agnostic)\n// ============================================\n\n/**\n * Unified tool call format (internal representation)\n */\nexport interface UnifiedToolCall {\n /** Unique tool call ID */\n id: string;\n /** Tool name */\n name: string;\n /** Tool input arguments */\n input: Record<string, unknown>;\n}\n\n/**\n * Unified tool result format\n */\nexport interface UnifiedToolResult {\n /** Tool call ID this result is for */\n toolCallId: string;\n /** Serialized result content (JSON string) */\n content: string;\n /** Whether the tool succeeded */\n success: boolean;\n /** Error message if failed */\n error?: string;\n}\n\n// ============================================\n// Tool Execution Types\n// ============================================\n\n/**\n * Tool execution status\n */\nexport type ToolExecutionStatus =\n | \"pending\"\n | \"executing\"\n | \"completed\"\n | \"error\";\n\n/**\n * Tool approval status (for human-in-the-loop)\n *\n * Similar to Vercel AI SDK v6's tool approval pattern.\n */\nexport type ToolApprovalStatus =\n | \"none\" // No approval needed (default)\n | \"required\" // Waiting for user decision\n | \"approved\" // User approved, execution can proceed\n | \"rejected\"; // User rejected, execution skipped\n\n// ============================================\n// Permission Persistence Types\n// ============================================\n\n/**\n * Permission level for tool execution\n *\n * Controls whether approval is needed and how the choice is remembered:\n * - \"ask\" - Always prompt user (default)\n * - \"allow_always\" - Auto-approve, persisted to storage\n * - \"deny_always\" - Auto-reject, persisted to storage\n * - \"session\" - Auto-approve for current session only\n */\nexport type PermissionLevel =\n | \"ask\"\n | \"allow_always\"\n | \"deny_always\"\n | \"session\";\n\n/**\n * Stored tool permission record\n */\nexport interface ToolPermission {\n /** Tool name (unique identifier) */\n toolName: string;\n /** Permission level */\n level: PermissionLevel;\n /** When permission was set */\n createdAt: number;\n /** Last time this permission was used */\n lastUsedAt?: number;\n}\n\n/**\n * Permission storage configuration\n */\nexport interface PermissionStorageConfig {\n /**\n * Storage type:\n * - \"localStorage\" - Persists across browser sessions\n * - \"sessionStorage\" - Clears when tab closes\n * - \"memory\" - In-memory only (for SSR or testing)\n */\n type: \"localStorage\" | \"sessionStorage\" | \"memory\";\n /** Storage key prefix (default: \"yourgpt-permissions\") */\n keyPrefix?: string;\n}\n\n/**\n * Permission storage adapter interface (for custom implementations)\n */\nexport interface PermissionStorageAdapter {\n /** Get permission for a tool */\n get(toolName: string): Promise<ToolPermission | null>;\n /** Set permission for a tool */\n set(permission: ToolPermission): Promise<void>;\n /** Remove permission for a tool */\n remove(toolName: string): Promise<void>;\n /** Get all permissions */\n getAll(): Promise<ToolPermission[]>;\n /** Clear all permissions */\n clear(): Promise<void>;\n}\n\n/**\n * Tool execution record (for UI tracking)\n */\nexport interface ToolExecution {\n /** Tool call ID */\n id: string;\n /** Tool name */\n name: string;\n /** Tool arguments */\n args: Record<string, unknown>;\n /** Execution status */\n status: ToolExecutionStatus;\n /** Result if completed */\n result?: ToolResponse;\n /** Error message if failed */\n error?: string;\n /** Timestamp when execution started */\n timestamp: number;\n /** Duration in ms (set when completed) */\n duration?: number;\n\n // Approval fields (for needsApproval tools)\n\n /** Approval status for this execution */\n approvalStatus: ToolApprovalStatus;\n /** Message shown in approval UI (from tool's approvalMessage) */\n approvalMessage?: string;\n /** Timestamp when user responded to approval request */\n approvalTimestamp?: number;\n\n /**\n * Whether this tool execution should be hidden from the UI.\n * Server-side tools can set this to hide internal operations from users.\n */\n hidden?: boolean;\n}\n\n// ============================================\n// Agent Loop Types\n// ============================================\n\n/**\n * Agentic loop configuration\n */\nexport interface AgentLoopConfig {\n /** Maximum iterations before stopping (default: 20) */\n maxIterations?: number;\n /** Enable debug logging */\n debug?: boolean;\n /** Whether to enable the agentic loop (default: true) */\n enabled?: boolean;\n /** Optional prompt/tool optimization controls */\n optimization?: ToolOptimizationConfig;\n}\n\n/**\n * Agent loop state (for tracking)\n */\nexport interface AgentLoopState {\n /** Current iteration number */\n iteration: number;\n /** Maximum iterations allowed */\n maxIterations: number;\n /** Whether the loop is currently running */\n running: boolean;\n /** Whether max iterations was reached */\n maxIterationsReached: boolean;\n /** Whether the loop was aborted */\n aborted: boolean;\n}\n\n// ============================================\n// ToolSet Type (Vercel AI SDK pattern)\n// ============================================\n\n/**\n * A tool definition without the name (name is derived from the key in ToolSet)\n */\nexport type ToolSetEntry<TParams = Record<string, unknown>> = Omit<\n ToolDefinition<TParams>,\n \"name\"\n>;\n\n/**\n * A set of tools, keyed by tool name\n *\n * The key becomes the tool name, so tool definitions don't need a name property.\n * Use with the `tool()` helper for clean syntax.\n *\n * @example\n * ```typescript\n * const myTools: ToolSet = {\n * capture_screenshot: tool({\n * description: 'Capture screenshot',\n * handler: async () => ({ success: true }),\n * }),\n * get_weather: tool({\n * description: 'Get weather',\n * inputSchema: { type: 'object', properties: { city: { type: 'string' } } },\n * handler: async ({ city }) => ({ success: true, data: { temp: 72 } }),\n * }),\n * };\n * ```\n */\nexport type ToolSet = Record<string, ToolSetEntry>;\n\n// ============================================\n// Tool Helper Function (Vercel AI SDK pattern)\n// ============================================\n\n/**\n * Configuration for creating a tool\n */\nexport interface ToolConfig<TParams = Record<string, unknown>> {\n /** Tool description for LLM */\n description: string;\n /** Where the tool executes (default: 'client') */\n location?: ToolLocation;\n /** Optional category for search, filtering, and budgets */\n category?: string;\n /** Optional group for profile-based tool selection */\n group?: string;\n /** Deferred tools are discoverable but omitted from the default prompt */\n deferLoading?: boolean;\n /** Profile memberships for selective tool loading */\n profiles?: string[];\n /** Extra keywords for dynamic tool selection */\n searchKeywords?: string[];\n /** Per-tool prompt/result shaping controls */\n resultConfig?: ToolResultConfig;\n\n // Display Configuration\n /** Human-readable title for UI display */\n title?: string | ((args: TParams) => string);\n /** Title shown while executing */\n executingTitle?: string | ((args: TParams) => string);\n /** Title shown after completion */\n completedTitle?: string | ((args: TParams) => string);\n\n /** JSON Schema for input parameters */\n inputSchema?: ToolInputSchema;\n /** Handler function */\n handler?: (\n params: TParams,\n context?: ToolContext,\n ) => Promise<ToolResponse> | ToolResponse;\n /** Optional render function for UI */\n render?: (props: ToolRenderProps<TParams>) => unknown;\n /** Whether the tool is available */\n available?: boolean;\n /** Hide this tool from chat UI display */\n hidden?: boolean;\n /** Require user approval before execution */\n needsApproval?: boolean | ((params: TParams) => boolean | Promise<boolean>);\n /** Custom message shown in the approval UI */\n approvalMessage?: string | ((params: TParams) => string);\n /** AI response mode for this tool (default: 'full') */\n aiResponseMode?: AIResponseMode;\n /** Context/summary sent to AI instead of full result */\n aiContext?:\n | string\n | ((result: ToolResponse, args: Record<string, unknown>) => string);\n}\n\n/**\n * Create a tool definition (similar to Vercel AI SDK's tool())\n *\n * @example\n * ```typescript\n * const weatherTool = tool({\n * description: 'Get weather for a location',\n * inputSchema: {\n * type: 'object',\n * properties: {\n * location: { type: 'string', description: 'City name' },\n * },\n * required: ['location'],\n * },\n * handler: async ({ location }) => {\n * const weather = await fetchWeather(location);\n * return success(weather);\n * },\n * });\n * ```\n */\nexport function tool<TParams = Record<string, unknown>>(\n config: ToolConfig<TParams>,\n): Omit<ToolDefinition<TParams>, \"name\"> {\n return {\n description: config.description,\n location: config.location ?? \"client\",\n category: config.category,\n group: config.group,\n deferLoading: config.deferLoading,\n profiles: config.profiles,\n searchKeywords: config.searchKeywords,\n resultConfig: config.resultConfig,\n // Display configuration\n title: config.title,\n executingTitle: config.executingTitle,\n completedTitle: config.completedTitle,\n // Schema and handlers\n inputSchema: config.inputSchema ?? {\n type: \"object\",\n properties: {},\n required: [],\n },\n handler: config.handler,\n render: config.render,\n available: config.available,\n hidden: config.hidden,\n needsApproval: config.needsApproval,\n approvalMessage: config.approvalMessage,\n aiResponseMode: config.aiResponseMode,\n aiContext: config.aiContext,\n };\n}\n\n// ============================================\n// Helper Functions\n// ============================================\n\n/**\n * Convert ToolDefinition to OpenAI tool format\n */\nexport function toolToOpenAIFormat(tool: ToolDefinition): object {\n return {\n type: \"function\",\n function: {\n name: tool.name,\n description: tool.description,\n parameters: tool.inputSchema,\n },\n };\n}\n\n/**\n * Convert ToolDefinition to Anthropic tool format\n */\nexport function toolToAnthropicFormat(tool: ToolDefinition): object {\n return {\n name: tool.name,\n description: tool.description,\n input_schema: tool.inputSchema,\n };\n}\n\n/**\n * Create a tool result response\n */\nexport function createToolResult(\n toolCallId: string,\n response: ToolResponse,\n): UnifiedToolResult {\n return {\n toolCallId,\n content: JSON.stringify(response),\n success: response.success,\n error: response.error,\n };\n}\n\n/**\n * Create a successful tool response\n */\nexport function success<T = unknown>(\n data?: T,\n message?: string,\n): ToolResponse<T> {\n return {\n success: true,\n data,\n message,\n };\n}\n\n/**\n * Create a failed tool response\n */\nexport function failure(error: string): ToolResponse {\n return {\n success: false,\n error,\n };\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/core/types/tools.ts"],"names":["tool"],"mappings":";;;AAk9BO,SAAS,KACd,MAAA,EACuC;AACvC,EAAA,OAAO;AAAA,IACL,aAAa,MAAA,CAAO,WAAA;AAAA,IACpB,QAAA,EAAU,OAAO,QAAA,IAAY,QAAA;AAAA,IAC7B,UAAU,MAAA,CAAO,QAAA;AAAA,IACjB,OAAO,MAAA,CAAO,KAAA;AAAA,IACd,cAAc,MAAA,CAAO,YAAA;AAAA,IACrB,UAAU,MAAA,CAAO,QAAA;AAAA,IACjB,gBAAgB,MAAA,CAAO,cAAA;AAAA,IACvB,cAAc,MAAA,CAAO,YAAA;AAAA;AAAA,IAErB,OAAO,MAAA,CAAO,KAAA;AAAA,IACd,gBAAgB,MAAA,CAAO,cAAA;AAAA,IACvB,gBAAgB,MAAA,CAAO,cAAA;AAAA;AAAA,IAEvB,WAAA,EAAa,OAAO,WAAA,IAAe;AAAA,MACjC,IAAA,EAAM,QAAA;AAAA,MACN,YAAY,EAAC;AAAA,MACb,UAAU;AAAC,KACb;AAAA,IACA,SAAS,MAAA,CAAO,OAAA;AAAA,IAChB,QAAQ,MAAA,CAAO,MAAA;AAAA,IACf,WAAW,MAAA,CAAO,SAAA;AAAA,IAClB,QAAQ,MAAA,CAAO,MAAA;AAAA,IACf,eAAe,MAAA,CAAO,aAAA;AAAA,IACtB,iBAAiB,MAAA,CAAO,eAAA;AAAA,IACxB,gBAAgB,MAAA,CAAO,cAAA;AAAA,IACvB,WAAW,MAAA,CAAO;AAAA,GACpB;AACF;AASO,SAAS,mBAAmBA,KAAAA,EAA8B;AAC/D,EAAA,OAAO;AAAA,IACL,IAAA,EAAM,UAAA;AAAA,IACN,QAAA,EAAU;AAAA,MACR,MAAMA,KAAAA,CAAK,IAAA;AAAA,MACX,aAAaA,KAAAA,CAAK,WAAA;AAAA,MAClB,YAAYA,KAAAA,CAAK;AAAA;AACnB,GACF;AACF;AAKO,SAAS,sBAAsBA,KAAAA,EAA8B;AAClE,EAAA,OAAO;AAAA,IACL,MAAMA,KAAAA,CAAK,IAAA;AAAA,IACX,aAAaA,KAAAA,CAAK,WAAA;AAAA,IAClB,cAAcA,KAAAA,CAAK;AAAA,GACrB;AACF;AAKO,SAAS,gBAAA,CACd,YACA,QAAA,EACmB;AACnB,EAAA,OAAO;AAAA,IACL,UAAA;AAAA,IACA,OAAA,EAAS,IAAA,CAAK,SAAA,CAAU,QAAQ,CAAA;AAAA,IAChC,SAAS,QAAA,CAAS,OAAA;AAAA,IAClB,OAAO,QAAA,CAAS;AAAA,GAClB;AACF;AAKO,SAAS,OAAA,CACd,MACA,OAAA,EACiB;AACjB,EAAA,OAAO;AAAA,IACL,OAAA,EAAS,IAAA;AAAA,IACT,IAAA;AAAA,IACA;AAAA,GACF;AACF;AAKO,SAAS,QAAQ,KAAA,EAA6B;AACnD,EAAA,OAAO;AAAA,IACL,OAAA,EAAS,KAAA;AAAA,IACT;AAAA,GACF;AACF","file":"chunk-TPB7XED6.cjs","sourcesContent":["/**\n * Tool-related types for the agentic loop\n */\n\nimport type { ActionRenderProps } from \"./actions\";\n\n// ============================================\n// Provider Types\n// ============================================\n\n/**\n * Supported AI providers for tool calling\n */\nexport type AIProvider =\n | \"anthropic\"\n | \"openai\"\n | \"xai\"\n | \"grok\"\n | \"gemini\"\n | \"groq\"\n | \"ollama\";\n\n/**\n * Where the tool executes\n */\nexport type ToolLocation = \"server\" | \"client\";\n\n/**\n * Source/origin of the tool\n * - \"mcp\": Tool from an MCP (Model Context Protocol) server\n * - \"native\": Built-in SDK tool\n * - \"custom\": User-defined tool\n */\nexport type ToolSource = \"mcp\" | \"native\" | \"custom\";\n\n// ============================================\n// Tool Definition Types\n// ============================================\n\n/**\n * JSON Schema property definition\n */\nexport interface JSONSchemaProperty {\n type:\n | \"string\"\n | \"number\"\n | \"boolean\"\n | \"object\"\n | \"array\"\n | \"integer\"\n | \"null\";\n description?: string;\n enum?: (string | number | boolean)[];\n items?: JSONSchemaProperty;\n properties?: Record<string, JSONSchemaProperty>;\n required?: string[];\n default?: unknown;\n minLength?: number;\n maxLength?: number;\n minimum?: number;\n maximum?: number;\n pattern?: string;\n}\n\n/**\n * JSON Schema for tool input\n */\nexport interface ToolInputSchema {\n type: \"object\";\n properties: Record<string, JSONSchemaProperty>;\n required?: string[];\n additionalProperties?: boolean;\n}\n\n/**\n * Tool execution context\n *\n * Provides runtime information to tool handlers including cancellation signals,\n * request metadata, and custom context data.\n */\nexport interface ToolContext {\n /** Abort signal for cancellation */\n signal?: AbortSignal;\n /** Thread ID if using threads */\n threadId?: string;\n /** Custom context data passed from runtime config */\n data?: Record<string, unknown>;\n\n // ============================================\n // Rich Context (Vercel AI SDK pattern)\n // ============================================\n\n /**\n * Unique ID for this specific tool call.\n * Useful for logging, tracing, and correlating tool executions.\n */\n toolCallId?: string;\n\n /**\n * Request headers (for auth in server tools).\n * Contains headers from the original HTTP request.\n *\n * @example\n * ```typescript\n * handler: async (params, context) => {\n * const token = context?.headers?.authorization;\n * if (!token) return failure('Authentication required');\n * // ...\n * }\n * ```\n */\n headers?: Record<string, string>;\n\n /**\n * Full request metadata for server-side tools.\n * Provides access to HTTP method, URL, and headers.\n *\n * @example\n * ```typescript\n * handler: async (params, context) => {\n * console.log(`Tool called from: ${context?.request?.url}`);\n * // Forward auth to internal service\n * const authHeader = context?.request?.headers?.authorization;\n * }\n * ```\n */\n request?: {\n /** HTTP method (GET, POST, etc.) */\n method?: string;\n /** Request URL path */\n url?: string;\n /** Request headers */\n headers?: Record<string, string>;\n };\n\n /**\n * Data passed from user's approval action.\n * Only present when tool has `needsApproval: true` and user approved with extra data.\n *\n * @example\n * ```typescript\n * // In render function:\n * approval.onApprove({ supervisor: selectedSupervisor });\n *\n * // In handler:\n * handler: async (params, context) => {\n * const supervisor = context?.approvalData?.supervisor;\n * await assignToSupervisor(params.ticketId, supervisor);\n * }\n * ```\n */\n approvalData?: Record<string, unknown>;\n}\n\n// ============================================\n// AI Response Control Types\n// ============================================\n\n/**\n * AI response behavior for tool results.\n *\n * Controls what the AI sees after a tool executes and renders UI.\n *\n * - `'none'`: AI generates minimal response, UI component handles display\n * - `'brief'`: AI gets summary context (via aiContext), gives brief acknowledgment\n * - `'full'`: AI receives full data and responds accordingly (default)\n */\nexport type AIResponseMode = \"none\" | \"brief\" | \"full\";\n\n/**\n * Multimodal content for AI to analyze\n */\nexport type AIContent =\n | { type: \"image\"; data: string; mediaType: string }\n | { type: \"text\"; text: string };\n\n/**\n * How large tool results should be trimmed before they are sent back to the AI.\n */\nexport type ToolTruncationStrategy = \"head\" | \"head-tail\" | \"smart\";\n\n/**\n * Truncation controls for tool results.\n */\nexport interface ToolResultTruncationConfig {\n enabled?: boolean;\n maxContextShare?: number;\n hardMaxChars?: number;\n minKeepChars?: number;\n strategy?: ToolTruncationStrategy;\n preserveErrors?: boolean;\n}\n\n/**\n * Global or per-tool controls for how tool results are represented in prompts.\n */\nexport interface ToolResultConfig {\n truncation?: ToolResultTruncationConfig;\n}\n\n/**\n * Named tool profile for selective loading.\n */\nexport interface ToolProfile {\n name: string;\n description?: string;\n include?: string[];\n exclude?: string[];\n}\n\n/**\n * Tool profile configuration.\n */\nexport interface ToolProfileConfig {\n enabled?: boolean;\n defaultProfile?: string;\n profiles?: Record<string, ToolProfile>;\n /** When false, active profiles exclude tools that do not declare profile membership. */\n includeUnprofiled?: boolean;\n dynamicSelection?: {\n enabled?: boolean;\n maxTools?: number;\n };\n}\n\n/**\n * History compaction behavior for long-running sessions.\n */\nexport interface ContextHistoryConfig {\n maxMessages?: number;\n maxTokens?: number;\n maxContextShare?: number;\n pruneStrategy?: \"oldest\" | \"least-relevant\" | \"summarize\";\n}\n\n/**\n * Optional summarization controls used during history compaction.\n */\nexport interface ContextSummarizationConfig {\n enabled?: boolean;\n triggerAt?: number;\n chunkSize?: number;\n preserveRecent?: number;\n fallbackBehavior?: \"truncate\" | \"statistical\" | \"error\";\n}\n\n/**\n * Token estimation controls.\n */\nexport interface TokenEstimationConfig {\n safetyMargin?: number;\n charsPerToken?: number;\n}\n\n/**\n * Conversation context management.\n */\nexport interface ContextManagementConfig {\n enabled?: boolean;\n history?: ContextHistoryConfig;\n summarization?: ContextSummarizationConfig;\n tokenEstimation?: TokenEstimationConfig;\n}\n\n/**\n * One budget bucket in the prompt context.\n */\nexport interface ContextUsagePart {\n tokens: number;\n percent: number;\n}\n\n/**\n * Prompt context usage snapshot.\n */\nexport interface ContextUsage {\n total: ContextUsagePart;\n breakdown: {\n systemPrompt: ContextUsagePart;\n history: ContextUsagePart;\n toolResults: ContextUsagePart;\n tools: ContextUsagePart;\n };\n budget: {\n available: number;\n remaining: number;\n };\n warnings: string[];\n}\n\n/**\n * Real-time context budget configuration.\n */\nexport interface ContextBudgetConfig {\n enabled?: boolean;\n budget?: {\n contextWindowTokens?: number;\n inputHeadroomRatio?: number;\n systemPromptShare?: number;\n historyShare?: number;\n toolResultsShare?: number;\n toolDefinitionsShare?: number;\n };\n enforcement?: {\n mode?: \"warn\" | \"truncate\" | \"error\";\n onBudgetExceeded?: (info: ContextUsage) => void;\n };\n monitoring?: {\n enabled?: boolean;\n onUsageUpdate?: (usage: ContextUsage) => void;\n };\n}\n\n/**\n * Framework-agnostic optimization controls for tool-heavy chat sessions.\n */\nexport interface ToolOptimizationConfig {\n toolProfiles?: ToolProfileConfig;\n toolResultConfig?: ToolResultConfig;\n contextManagement?: ContextManagementConfig;\n contextBudget?: ContextBudgetConfig;\n}\n\n/**\n * Tool response format\n */\nexport interface ToolResponse<T = unknown> {\n /** Whether the tool succeeded */\n success: boolean;\n /** Human-readable message */\n message?: string;\n /** Error message if failed */\n error?: string;\n /** Result data */\n data?: T;\n\n // ============================================\n // AI Response Control (result-level overrides)\n // ============================================\n\n /**\n * Override AI context for this specific result.\n * Takes precedence over tool-level aiContext config.\n * If set, this message is sent to AI instead of full result data.\n *\n * @example\n * ```typescript\n * return {\n * success: true,\n * data: sensitiveData,\n * _aiContext: '[Data retrieved - contains sensitive info, displayed to user]'\n * };\n * ```\n */\n _aiContext?: string;\n\n /**\n * Override AI response mode for this specific result.\n * Takes precedence over tool-level aiResponseMode config.\n */\n _aiResponseMode?: AIResponseMode;\n\n /**\n * Content for AI to analyze (images, documents, etc.).\n * When present, these are included as multimodal content for AI analysis.\n *\n * @example\n * ```typescript\n * // Screenshot for AI to analyze\n * return {\n * success: true,\n * message: 'Screenshot captured',\n * _aiContent: [{ type: 'image', data: base64, mediaType: 'image/png' }]\n * };\n * ```\n */\n _aiContent?: AIContent[];\n\n /**\n * MCP-UI resources for rendering interactive UI components.\n * These are extracted from MCP tool results and rendered as iframes.\n * Not sent to the AI - purely for UI rendering.\n *\n * @example\n * ```typescript\n * // MCP tool returning UI\n * return {\n * success: true,\n * message: 'Product displayed',\n * _uiResources: [{\n * uri: 'ui://shop/product/123',\n * mimeType: 'text/html',\n * content: '<div class=\"product\">...</div>',\n * metadata: { height: '300px' }\n * }]\n * };\n * ```\n */\n _uiResources?: Array<{\n uri: string;\n mimeType:\n | \"text/html\"\n | \"text/uri-list\"\n | \"application/vnd.mcp-ui.remote-dom\";\n content?: string;\n blob?: string;\n metadata?: {\n title?: string;\n width?: string;\n height?: string;\n sandbox?: string[];\n className?: string;\n };\n }>;\n}\n\n/**\n * Approval callbacks passed to render when tool requires user action.\n * Only present when status is \"approval-required\".\n */\nexport interface ToolApprovalCallbacks {\n /**\n * Approve execution and optionally pass extra data to the handler.\n * The extraData is available in handler via `context.approvalData`.\n *\n * @example\n * ```tsx\n * // Simple approval\n * approval.onApprove();\n *\n * // Approval with data (e.g., user selection)\n * approval.onApprove({ supervisor: { name: \"John\", role: \"Manager\" } });\n * ```\n */\n onApprove: (extraData?: Record<string, unknown>) => void;\n\n /**\n * Reject the tool execution with optional reason.\n * This stops the tool from executing and returns an error to AI.\n */\n onReject: (reason?: string) => void;\n\n /** Custom message from tool's approvalMessage config */\n message?: string;\n}\n\n/**\n * Props passed to tool render function.\n *\n * The render function is called for every status change, enabling\n * full lifecycle rendering similar to Vercel AI SDK.\n *\n * @example\n * ```tsx\n * render: ({ status, args, approval, result }) => {\n * if (status === \"approval-required\" && approval) {\n * return <ApprovalCard onConfirm={() => approval.onApprove()} />;\n * }\n * if (status === \"executing\") {\n * return <LoadingSkeleton />;\n * }\n * if (status === \"completed\") {\n * return <ResultCard data={result.data} />;\n * }\n * return null;\n * }\n * ```\n */\nexport interface ToolRenderProps<TParams = Record<string, unknown>> {\n /**\n * Current execution status:\n * - `pending`: Tool call received, waiting to start\n * - `approval-required`: Waiting for user approval (when needsApproval is set)\n * - `executing`: Handler is running\n * - `completed`: Handler finished successfully\n * - `error`: Handler failed\n */\n status: \"pending\" | \"approval-required\" | \"executing\" | \"completed\" | \"error\";\n\n /** Arguments passed to the tool */\n args: TParams;\n\n /** Result if completed */\n result?: ToolResponse;\n\n /** Error if failed */\n error?: string;\n\n /** Tool call ID */\n toolCallId: string;\n\n /** Tool name */\n toolName: string;\n\n /**\n * Approval callbacks - only present when status is \"approval-required\".\n * Use these to create custom approval UIs that can pass extra data to the handler.\n */\n approval?: ToolApprovalCallbacks;\n}\n\n/**\n * Tool definition with JSON Schema\n */\nexport interface ToolDefinition<TParams = Record<string, unknown>> {\n /** Unique tool name */\n name: string;\n /** Tool description for LLM */\n description: string;\n /** Where the tool executes (server or client) */\n location: ToolLocation;\n /**\n * Source/origin of the tool.\n * Used to distinguish MCP tools from native/custom tools for UI rendering.\n * @default \"custom\"\n */\n source?: ToolSource;\n /** Optional category for search, filtering, and budgets */\n category?: string;\n /** Optional group for profile-based tool selection */\n group?: string;\n /** Deferred tools are discoverable but need not be sent on every request */\n deferLoading?: boolean;\n /** Profile memberships for selective tool loading */\n profiles?: string[];\n /** Extra keywords for dynamic tool selection */\n searchKeywords?: string[];\n /** Per-tool prompt/result shaping controls */\n resultConfig?: ToolResultConfig;\n\n // ============================================\n // Display Configuration\n // ============================================\n\n /**\n * Human-readable title for UI display.\n * Can be a static string or a function that generates title from args.\n *\n * @example\n * ```typescript\n * title: \"Get order details\"\n * // or dynamic:\n * title: (args) => `Order #${args.orderId}`\n * ```\n */\n title?: string | ((args: TParams) => string);\n\n /**\n * Title shown while executing (present tense with \"...\").\n * If not provided, uses `title` with \"...\" appended.\n *\n * @example\n * ```typescript\n * executingTitle: (args) => `Fetching order #${args.orderId}...`\n * ```\n */\n executingTitle?: string | ((args: TParams) => string);\n\n /**\n * Title shown after completion.\n * If not provided, defaults to `title`.\n *\n * @example\n * ```typescript\n * completedTitle: (args) => `Retrieved order #${args.orderId}`\n * ```\n */\n completedTitle?: string | ((args: TParams) => string);\n /** JSON Schema for input parameters */\n inputSchema: ToolInputSchema;\n /** Handler function (optional for client tools registered on server) */\n handler?: (\n params: TParams,\n context?: ToolContext,\n ) => Promise<ToolResponse> | ToolResponse;\n /** Optional render function for UI */\n render?: (props: ToolRenderProps<TParams>) => unknown;\n /** Whether the tool is available (for conditional registration) */\n available?: boolean;\n\n /**\n * Hide this tool's execution from the chat UI.\n * When true, tool calls and results won't be displayed to the user,\n * but the tool will still execute normally.\n * @default false\n */\n hidden?: boolean;\n\n /**\n * Require user approval before execution.\n * Can be:\n * - `true`: Always require approval\n * - `false` or `undefined`: No approval needed (default)\n * - `(params) => boolean`: Conditional approval based on input\n *\n * Similar to Vercel AI SDK v6's needsApproval pattern.\n */\n needsApproval?: boolean | ((params: TParams) => boolean | Promise<boolean>);\n\n /**\n * Custom title shown in the approval UI.\n * If not provided, the tool name is used.\n */\n approvalTitle?: string | ((params: TParams) => string);\n\n /**\n * Custom message shown in the approval UI.\n * Can be a string or a function that generates a message from params.\n * If not provided, a default message with the tool name is shown.\n */\n approvalMessage?: string | ((params: TParams) => string);\n\n // ============================================\n // AI Response Control\n // ============================================\n\n /**\n * How the AI should respond when this tool's result is rendered as UI.\n *\n * - `'none'`: AI generates minimal response (\"[Result displayed to user]\").\n * Use for tools where UI component fully handles the display (stats cards, etc.)\n *\n * - `'brief'`: AI receives summary context (from aiContext) and gives brief acknowledgment.\n * Use for charts/visualizations where AI should acknowledge but not repeat data.\n *\n * - `'full'`: AI receives complete data and responds accordingly (default).\n * Use for tools where AI should analyze and elaborate on results.\n *\n * @default 'full'\n *\n * @example\n * ```typescript\n * // Chart tool - AI acknowledges without repeating data\n * const chartTool: ToolDefinition = {\n * name: 'get_chart',\n * aiResponseMode: 'brief',\n * aiContext: (result) => `[Chart displayed: ${result.data.title}]`,\n * handler: async () => ({ success: true, data: chartData })\n * };\n * ```\n */\n aiResponseMode?: AIResponseMode;\n\n /**\n * Context/summary sent to AI instead of (or along with) full result.\n *\n * Used when:\n * - `aiResponseMode: 'brief'` - This becomes the only thing AI sees\n * - `aiResponseMode: 'full'` - This is prepended to full data for context\n *\n * Can be:\n * - `string`: Static message (e.g., \"[Weather data displayed]\")\n * - `function`: Dynamic based on result (e.g., (result) => `[Chart: ${result.data.title}]`)\n *\n * @example\n * ```typescript\n * // Static context\n * aiContext: '[Analytics chart displayed to user]'\n *\n * // Dynamic context based on result\n * aiContext: (result, args) => {\n * const { title, currentValue } = result.data;\n * return `[Chart displayed: ${title}, showing ${currentValue}]`;\n * }\n * ```\n */\n aiContext?:\n | string\n | ((result: ToolResponse, args: Record<string, unknown>) => string);\n}\n\n// ============================================\n// Unified Tool Call Types (Provider-Agnostic)\n// ============================================\n\n/**\n * Unified tool call format (internal representation)\n */\nexport interface UnifiedToolCall {\n /** Unique tool call ID */\n id: string;\n /** Tool name */\n name: string;\n /** Tool input arguments */\n input: Record<string, unknown>;\n}\n\n/**\n * Unified tool result format\n */\nexport interface UnifiedToolResult {\n /** Tool call ID this result is for */\n toolCallId: string;\n /** Serialized result content (JSON string) */\n content: string;\n /** Whether the tool succeeded */\n success: boolean;\n /** Error message if failed */\n error?: string;\n}\n\n// ============================================\n// Tool Execution Types\n// ============================================\n\n/**\n * Tool execution status\n */\nexport type ToolExecutionStatus =\n | \"pending\"\n | \"executing\"\n | \"completed\"\n | \"error\";\n\n/**\n * Tool approval status (for human-in-the-loop)\n *\n * Similar to Vercel AI SDK v6's tool approval pattern.\n */\nexport type ToolApprovalStatus =\n | \"none\" // No approval needed (default)\n | \"required\" // Waiting for user decision\n | \"approved\" // User approved, execution can proceed\n | \"rejected\"; // User rejected, execution skipped\n\n// ============================================\n// Permission Persistence Types\n// ============================================\n\n/**\n * Permission level for tool execution\n *\n * Controls whether approval is needed and how the choice is remembered:\n * - \"ask\" - Always prompt user (default)\n * - \"allow_always\" - Auto-approve, persisted to storage\n * - \"deny_always\" - Auto-reject, persisted to storage\n * - \"session\" - Auto-approve for current session only\n */\nexport type PermissionLevel =\n | \"ask\"\n | \"allow_always\"\n | \"deny_always\"\n | \"session\";\n\n/**\n * Stored tool permission record\n */\nexport interface ToolPermission {\n /** Tool name (unique identifier) */\n toolName: string;\n /** Permission level */\n level: PermissionLevel;\n /** When permission was set */\n createdAt: number;\n /** Last time this permission was used */\n lastUsedAt?: number;\n}\n\n/**\n * Permission storage configuration\n */\nexport interface PermissionStorageConfig {\n /**\n * Storage type:\n * - \"localStorage\" - Persists across browser sessions\n * - \"sessionStorage\" - Clears when tab closes\n * - \"memory\" - In-memory only (for SSR or testing)\n */\n type: \"localStorage\" | \"sessionStorage\" | \"memory\";\n /** Storage key prefix (default: \"yourgpt-permissions\") */\n keyPrefix?: string;\n}\n\n/**\n * Permission storage adapter interface (for custom implementations)\n */\nexport interface PermissionStorageAdapter {\n /** Get permission for a tool */\n get(toolName: string): Promise<ToolPermission | null>;\n /** Set permission for a tool */\n set(permission: ToolPermission): Promise<void>;\n /** Remove permission for a tool */\n remove(toolName: string): Promise<void>;\n /** Get all permissions */\n getAll(): Promise<ToolPermission[]>;\n /** Clear all permissions */\n clear(): Promise<void>;\n}\n\n/**\n * Tool execution record (for UI tracking)\n */\nexport interface ToolExecution {\n /** Tool call ID */\n id: string;\n /** Tool name */\n name: string;\n /** Tool arguments */\n args: Record<string, unknown>;\n /** Execution status */\n status: ToolExecutionStatus;\n /** Result if completed */\n result?: ToolResponse;\n /** Error message if failed */\n error?: string;\n /** Timestamp when execution started */\n timestamp: number;\n /** Duration in ms (set when completed) */\n duration?: number;\n\n // Approval fields (for needsApproval tools)\n\n /** Approval status for this execution */\n approvalStatus: ToolApprovalStatus;\n /** Title shown in approval UI (from tool's approvalTitle) */\n approvalTitle?: string;\n /** Message shown in approval UI (from tool's approvalMessage) */\n approvalMessage?: string;\n /** Timestamp when user responded to approval request */\n approvalTimestamp?: number;\n\n /**\n * Whether this tool execution should be hidden from the UI.\n * Server-side tools can set this to hide internal operations from users.\n */\n hidden?: boolean;\n}\n\n// ============================================\n// Agent Loop Types\n// ============================================\n\n/**\n * Agentic loop configuration\n */\nexport interface AgentLoopConfig {\n /** Maximum iterations before stopping (default: 20) */\n maxIterations?: number;\n /** Enable debug logging */\n debug?: boolean;\n /** Whether to enable the agentic loop (default: true) */\n enabled?: boolean;\n /** Optional prompt/tool optimization controls */\n optimization?: ToolOptimizationConfig;\n}\n\n/**\n * Agent loop state (for tracking)\n */\nexport interface AgentLoopState {\n /** Current iteration number */\n iteration: number;\n /** Maximum iterations allowed */\n maxIterations: number;\n /** Whether the loop is currently running */\n running: boolean;\n /** Whether max iterations was reached */\n maxIterationsReached: boolean;\n /** Whether the loop was aborted */\n aborted: boolean;\n}\n\n// ============================================\n// ToolSet Type (Vercel AI SDK pattern)\n// ============================================\n\n/**\n * A tool definition without the name (name is derived from the key in ToolSet)\n */\nexport type ToolSetEntry<TParams = Record<string, unknown>> = Omit<\n ToolDefinition<TParams>,\n \"name\"\n>;\n\n/**\n * A set of tools, keyed by tool name\n *\n * The key becomes the tool name, so tool definitions don't need a name property.\n * Use with the `tool()` helper for clean syntax.\n *\n * @example\n * ```typescript\n * const myTools: ToolSet = {\n * capture_screenshot: tool({\n * description: 'Capture screenshot',\n * handler: async () => ({ success: true }),\n * }),\n * get_weather: tool({\n * description: 'Get weather',\n * inputSchema: { type: 'object', properties: { city: { type: 'string' } } },\n * handler: async ({ city }) => ({ success: true, data: { temp: 72 } }),\n * }),\n * };\n * ```\n */\nexport type ToolSet = Record<string, ToolSetEntry>;\n\n// ============================================\n// Tool Helper Function (Vercel AI SDK pattern)\n// ============================================\n\n/**\n * Configuration for creating a tool\n */\nexport interface ToolConfig<TParams = Record<string, unknown>> {\n /** Tool description for LLM */\n description: string;\n /** Where the tool executes (default: 'client') */\n location?: ToolLocation;\n /** Optional category for search, filtering, and budgets */\n category?: string;\n /** Optional group for profile-based tool selection */\n group?: string;\n /** Deferred tools are discoverable but omitted from the default prompt */\n deferLoading?: boolean;\n /** Profile memberships for selective tool loading */\n profiles?: string[];\n /** Extra keywords for dynamic tool selection */\n searchKeywords?: string[];\n /** Per-tool prompt/result shaping controls */\n resultConfig?: ToolResultConfig;\n\n // Display Configuration\n /** Human-readable title for UI display */\n title?: string | ((args: TParams) => string);\n /** Title shown while executing */\n executingTitle?: string | ((args: TParams) => string);\n /** Title shown after completion */\n completedTitle?: string | ((args: TParams) => string);\n\n /** JSON Schema for input parameters */\n inputSchema?: ToolInputSchema;\n /** Handler function */\n handler?: (\n params: TParams,\n context?: ToolContext,\n ) => Promise<ToolResponse> | ToolResponse;\n /** Optional render function for UI */\n render?: (props: ToolRenderProps<TParams>) => unknown;\n /** Whether the tool is available */\n available?: boolean;\n /** Hide this tool from chat UI display */\n hidden?: boolean;\n /** Require user approval before execution */\n needsApproval?: boolean | ((params: TParams) => boolean | Promise<boolean>);\n /** Custom title shown in the approval UI */\n approvalTitle?: string | ((params: TParams) => string);\n /** Custom message shown in the approval UI */\n approvalMessage?: string | ((params: TParams) => string);\n /** AI response mode for this tool (default: 'full') */\n aiResponseMode?: AIResponseMode;\n /** Context/summary sent to AI instead of full result */\n aiContext?:\n | string\n | ((result: ToolResponse, args: Record<string, unknown>) => string);\n}\n\n/**\n * Create a tool definition (similar to Vercel AI SDK's tool())\n *\n * @example\n * ```typescript\n * const weatherTool = tool({\n * description: 'Get weather for a location',\n * inputSchema: {\n * type: 'object',\n * properties: {\n * location: { type: 'string', description: 'City name' },\n * },\n * required: ['location'],\n * },\n * handler: async ({ location }) => {\n * const weather = await fetchWeather(location);\n * return success(weather);\n * },\n * });\n * ```\n */\nexport function tool<TParams = Record<string, unknown>>(\n config: ToolConfig<TParams>,\n): Omit<ToolDefinition<TParams>, \"name\"> {\n return {\n description: config.description,\n location: config.location ?? \"client\",\n category: config.category,\n group: config.group,\n deferLoading: config.deferLoading,\n profiles: config.profiles,\n searchKeywords: config.searchKeywords,\n resultConfig: config.resultConfig,\n // Display configuration\n title: config.title,\n executingTitle: config.executingTitle,\n completedTitle: config.completedTitle,\n // Schema and handlers\n inputSchema: config.inputSchema ?? {\n type: \"object\",\n properties: {},\n required: [],\n },\n handler: config.handler,\n render: config.render,\n available: config.available,\n hidden: config.hidden,\n needsApproval: config.needsApproval,\n approvalMessage: config.approvalMessage,\n aiResponseMode: config.aiResponseMode,\n aiContext: config.aiContext,\n };\n}\n\n// ============================================\n// Helper Functions\n// ============================================\n\n/**\n * Convert ToolDefinition to OpenAI tool format\n */\nexport function toolToOpenAIFormat(tool: ToolDefinition): object {\n return {\n type: \"function\",\n function: {\n name: tool.name,\n description: tool.description,\n parameters: tool.inputSchema,\n },\n };\n}\n\n/**\n * Convert ToolDefinition to Anthropic tool format\n */\nexport function toolToAnthropicFormat(tool: ToolDefinition): object {\n return {\n name: tool.name,\n description: tool.description,\n input_schema: tool.inputSchema,\n };\n}\n\n/**\n * Create a tool result response\n */\nexport function createToolResult(\n toolCallId: string,\n response: ToolResponse,\n): UnifiedToolResult {\n return {\n toolCallId,\n content: JSON.stringify(response),\n success: response.success,\n error: response.error,\n };\n}\n\n/**\n * Create a successful tool response\n */\nexport function success<T = unknown>(\n data?: T,\n message?: string,\n): ToolResponse<T> {\n return {\n success: true,\n data,\n message,\n };\n}\n\n/**\n * Create a failed tool response\n */\nexport function failure(error: string): ToolResponse {\n return {\n success: false,\n error,\n };\n}\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var
|
|
3
|
+
var chunkMDS23G2S_cjs = require('./chunk-MDS23G2S.cjs');
|
|
4
|
+
var chunkTPB7XED6_cjs = require('./chunk-TPB7XED6.cjs');
|
|
5
5
|
|
|
6
6
|
// src/core/tools/screenshot.ts
|
|
7
7
|
var isBrowser = typeof window !== "undefined" && typeof document !== "undefined";
|
|
@@ -1036,7 +1036,7 @@ function createCustomDetector(customKeywords) {
|
|
|
1036
1036
|
}
|
|
1037
1037
|
|
|
1038
1038
|
// src/core/tools/builtin/screenshot.ts
|
|
1039
|
-
var screenshotTool =
|
|
1039
|
+
var screenshotTool = chunkTPB7XED6_cjs.tool({
|
|
1040
1040
|
description: "Capture a screenshot of the user's current screen/viewport. Use this when the user asks you to look at their screen, see what they're seeing, help with visual issues, or debug UI problems.",
|
|
1041
1041
|
location: "client",
|
|
1042
1042
|
inputSchema: {
|
|
@@ -1055,7 +1055,7 @@ var screenshotTool = chunk246B6X5D_cjs.tool({
|
|
|
1055
1055
|
approvalMessage: "Allow AI to capture a screenshot of your screen?",
|
|
1056
1056
|
handler: async (params) => {
|
|
1057
1057
|
if (!isScreenshotSupported()) {
|
|
1058
|
-
return
|
|
1058
|
+
return chunkTPB7XED6_cjs.failure("Screenshot capture is not supported in this environment");
|
|
1059
1059
|
}
|
|
1060
1060
|
try {
|
|
1061
1061
|
const options = {};
|
|
@@ -1081,20 +1081,20 @@ var screenshotTool = chunk246B6X5D_cjs.tool({
|
|
|
1081
1081
|
}
|
|
1082
1082
|
};
|
|
1083
1083
|
} catch (error) {
|
|
1084
|
-
return
|
|
1084
|
+
return chunkTPB7XED6_cjs.failure(
|
|
1085
1085
|
error instanceof Error ? error.message : "Screenshot capture failed"
|
|
1086
1086
|
);
|
|
1087
1087
|
}
|
|
1088
1088
|
}
|
|
1089
1089
|
});
|
|
1090
1090
|
function createScreenshotTool(options) {
|
|
1091
|
-
return
|
|
1091
|
+
return chunkTPB7XED6_cjs.tool({
|
|
1092
1092
|
...screenshotTool,
|
|
1093
1093
|
needsApproval: options?.needsApproval ?? true,
|
|
1094
1094
|
approvalMessage: options?.approvalMessage ?? "Allow AI to capture a screenshot of your screen?",
|
|
1095
1095
|
handler: async (params) => {
|
|
1096
1096
|
if (!isScreenshotSupported()) {
|
|
1097
|
-
return
|
|
1097
|
+
return chunkTPB7XED6_cjs.failure(
|
|
1098
1098
|
"Screenshot capture is not supported in this environment"
|
|
1099
1099
|
);
|
|
1100
1100
|
}
|
|
@@ -1120,7 +1120,7 @@ function createScreenshotTool(options) {
|
|
|
1120
1120
|
}
|
|
1121
1121
|
};
|
|
1122
1122
|
} catch (error) {
|
|
1123
|
-
return
|
|
1123
|
+
return chunkTPB7XED6_cjs.failure(
|
|
1124
1124
|
error instanceof Error ? error.message : "Screenshot capture failed"
|
|
1125
1125
|
);
|
|
1126
1126
|
}
|
|
@@ -1133,7 +1133,7 @@ var isBrowser4 = typeof window !== "undefined" && typeof console !== "undefined"
|
|
|
1133
1133
|
if (isBrowser4 && !isConsoleCaptureActive()) {
|
|
1134
1134
|
startConsoleCapture();
|
|
1135
1135
|
}
|
|
1136
|
-
var consoleLogsTool =
|
|
1136
|
+
var consoleLogsTool = chunkTPB7XED6_cjs.tool({
|
|
1137
1137
|
description: "Get recent console logs from the browser. Use this when debugging JavaScript errors, checking for warnings, or understanding what's happening in the application.",
|
|
1138
1138
|
location: "client",
|
|
1139
1139
|
inputSchema: {
|
|
@@ -1166,7 +1166,7 @@ var consoleLogsTool = chunk246B6X5D_cjs.tool({
|
|
|
1166
1166
|
types: params.types
|
|
1167
1167
|
});
|
|
1168
1168
|
const formattedLogs = formatLogsForAI(logs.logs);
|
|
1169
|
-
return
|
|
1169
|
+
return chunkTPB7XED6_cjs.success(
|
|
1170
1170
|
{
|
|
1171
1171
|
logs: formattedLogs,
|
|
1172
1172
|
count: logs.logs.length,
|
|
@@ -1175,14 +1175,14 @@ var consoleLogsTool = chunk246B6X5D_cjs.tool({
|
|
|
1175
1175
|
`Retrieved ${logs.logs.length} console logs`
|
|
1176
1176
|
);
|
|
1177
1177
|
} catch (error) {
|
|
1178
|
-
return
|
|
1178
|
+
return chunkTPB7XED6_cjs.failure(
|
|
1179
1179
|
error instanceof Error ? error.message : "Failed to get console logs"
|
|
1180
1180
|
);
|
|
1181
1181
|
}
|
|
1182
1182
|
}
|
|
1183
1183
|
});
|
|
1184
1184
|
function createConsoleLogsTool(options) {
|
|
1185
|
-
return
|
|
1185
|
+
return chunkTPB7XED6_cjs.tool({
|
|
1186
1186
|
...consoleLogsTool,
|
|
1187
1187
|
needsApproval: options?.needsApproval ?? true,
|
|
1188
1188
|
approvalMessage: options?.approvalMessage ?? "Allow AI to access browser console logs?",
|
|
@@ -1196,7 +1196,7 @@ function createConsoleLogsTool(options) {
|
|
|
1196
1196
|
types: params.types
|
|
1197
1197
|
});
|
|
1198
1198
|
const formattedLogs = formatLogsForAI(logs.logs);
|
|
1199
|
-
return
|
|
1199
|
+
return chunkTPB7XED6_cjs.success(
|
|
1200
1200
|
{
|
|
1201
1201
|
logs: formattedLogs,
|
|
1202
1202
|
count: logs.logs.length,
|
|
@@ -1205,7 +1205,7 @@ function createConsoleLogsTool(options) {
|
|
|
1205
1205
|
`Retrieved ${logs.logs.length} console logs`
|
|
1206
1206
|
);
|
|
1207
1207
|
} catch (error) {
|
|
1208
|
-
return
|
|
1208
|
+
return chunkTPB7XED6_cjs.failure(
|
|
1209
1209
|
error instanceof Error ? error.message : "Failed to get console logs"
|
|
1210
1210
|
);
|
|
1211
1211
|
}
|
|
@@ -1214,7 +1214,7 @@ function createConsoleLogsTool(options) {
|
|
|
1214
1214
|
}
|
|
1215
1215
|
|
|
1216
1216
|
// src/core/tools/builtin/network.ts
|
|
1217
|
-
var networkRequestsTool =
|
|
1217
|
+
var networkRequestsTool = chunkTPB7XED6_cjs.tool({
|
|
1218
1218
|
description: "Get recent network requests from the browser. Use this when debugging API calls, checking for failed requests, analyzing network activity, or troubleshooting connectivity issues.",
|
|
1219
1219
|
location: "client",
|
|
1220
1220
|
inputSchema: {
|
|
@@ -1243,7 +1243,7 @@ var networkRequestsTool = chunk246B6X5D_cjs.tool({
|
|
|
1243
1243
|
failedOnly: params.failedOnly
|
|
1244
1244
|
});
|
|
1245
1245
|
const formattedRequests = formatRequestsForAI(requests.requests);
|
|
1246
|
-
return
|
|
1246
|
+
return chunkTPB7XED6_cjs.success(
|
|
1247
1247
|
{
|
|
1248
1248
|
requests: formattedRequests,
|
|
1249
1249
|
count: requests.requests.length,
|
|
@@ -1252,14 +1252,14 @@ var networkRequestsTool = chunk246B6X5D_cjs.tool({
|
|
|
1252
1252
|
`Retrieved ${requests.requests.length} network requests`
|
|
1253
1253
|
);
|
|
1254
1254
|
} catch (error) {
|
|
1255
|
-
return
|
|
1255
|
+
return chunkTPB7XED6_cjs.failure(
|
|
1256
1256
|
error instanceof Error ? error.message : "Failed to get network requests"
|
|
1257
1257
|
);
|
|
1258
1258
|
}
|
|
1259
1259
|
}
|
|
1260
1260
|
});
|
|
1261
1261
|
function createNetworkRequestsTool(options) {
|
|
1262
|
-
return
|
|
1262
|
+
return chunkTPB7XED6_cjs.tool({
|
|
1263
1263
|
...networkRequestsTool,
|
|
1264
1264
|
needsApproval: options?.needsApproval ?? true,
|
|
1265
1265
|
approvalMessage: options?.approvalMessage ?? "Allow AI to access network request history?",
|
|
@@ -1273,7 +1273,7 @@ function createNetworkRequestsTool(options) {
|
|
|
1273
1273
|
failedOnly: params.failedOnly
|
|
1274
1274
|
});
|
|
1275
1275
|
const formattedRequests = formatRequestsForAI(requests.requests);
|
|
1276
|
-
return
|
|
1276
|
+
return chunkTPB7XED6_cjs.success(
|
|
1277
1277
|
{
|
|
1278
1278
|
requests: formattedRequests,
|
|
1279
1279
|
count: requests.requests.length,
|
|
@@ -1282,7 +1282,7 @@ function createNetworkRequestsTool(options) {
|
|
|
1282
1282
|
`Retrieved ${requests.requests.length} network requests`
|
|
1283
1283
|
);
|
|
1284
1284
|
} catch (error) {
|
|
1285
|
-
return
|
|
1285
|
+
return chunkTPB7XED6_cjs.failure(
|
|
1286
1286
|
error instanceof Error ? error.message : "Failed to get network requests"
|
|
1287
1287
|
);
|
|
1288
1288
|
}
|
|
@@ -1306,7 +1306,7 @@ var builtinTools = {
|
|
|
1306
1306
|
},
|
|
1307
1307
|
web_search: {
|
|
1308
1308
|
name: "web_search",
|
|
1309
|
-
...
|
|
1309
|
+
...chunkMDS23G2S_cjs.webSearchTool
|
|
1310
1310
|
}
|
|
1311
1311
|
};
|
|
1312
1312
|
|
|
@@ -2939,5 +2939,5 @@ exports.stopNetworkCapture = stopNetworkCapture;
|
|
|
2939
2939
|
exports.streamSSE = streamSSE;
|
|
2940
2940
|
exports.zodObjectToInputSchema = zodObjectToInputSchema;
|
|
2941
2941
|
exports.zodToJsonSchema = zodToJsonSchema;
|
|
2942
|
-
//# sourceMappingURL=chunk-
|
|
2943
|
-
//# sourceMappingURL=chunk-
|
|
2942
|
+
//# sourceMappingURL=chunk-WIXFZUEZ.cjs.map
|
|
2943
|
+
//# sourceMappingURL=chunk-WIXFZUEZ.cjs.map
|