@mcp-use/inspector 20.0.0-beta.5 → 20.0.0-beta.51
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/README.md +31 -78
- package/dist/app/inspector.css.gz +0 -0
- package/dist/app/inspector.js.gz +0 -0
- package/dist/app/providers/anthropic.png +0 -0
- package/dist/app/providers/google.png +0 -0
- package/dist/app/providers/openai.png +0 -0
- package/dist/cli.js +332 -1384
- package/dist/client/index.d.ts +1405 -50
- package/dist/client/index.js +165 -24019
- package/dist/server/index.d.ts +79 -7
- package/dist/server/index.js +370 -22
- package/package.json +77 -35
- package/dist/cdn/AnimatePresence-Dcw-FOy8.js +0 -393
- package/dist/cdn/ChatTab-B255lH5i.js +0 -6744
- package/dist/cdn/CheckboxIndicator-Bt4IICtv.js +0 -251
- package/dist/cdn/ConnectionSettingsForm-DF-NS58d.js +0 -929
- package/dist/cdn/ConnectionSettingsTab-dI-Cqe79.js +0 -150
- package/dist/cdn/ElicitationTab-CL1KJ0bz.js +0 -654
- package/dist/cdn/FormContext-tmgN_Vdr.js +0 -135
- package/dist/cdn/InspectorContext-UjtEbNod.js +0 -123
- package/dist/cdn/JSONDisplay-BFxf5oEu.js +0 -324
- package/dist/cdn/ListTabHeader-Cv-GmtGF.js +0 -88
- package/dist/cdn/ManufactOAuthCallback-B98kSYCj.js +0 -31
- package/dist/cdn/MarkdownRenderer-Ba7nA4Ie.js +0 -3610
- package/dist/cdn/NotificationsTab-CeImSrhx.js +0 -290
- package/dist/cdn/OAuthCallback-Blc2Asxc.js +0 -58
- package/dist/cdn/PromptsTab-BYKnY7Rp.js +0 -901
- package/dist/cdn/ResourcesTab-BGualKW-.js +0 -564
- package/dist/cdn/SamplingTab-BeZBUeni.js +0 -658
- package/dist/cdn/ServerMetadataTab-CvrKX8fz.js +0 -244
- package/dist/cdn/StatusIcon-D0-ARyOh.js +0 -66
- package/dist/cdn/ToolsTab-j6n4O_3s.js +0 -2033
- package/dist/cdn/ViewPreview-DihyG6Qd.js +0 -238
- package/dist/cdn/WidgetDebugContext-D4usL_MA.js +0 -324
- package/dist/cdn/WidgetWrapper-B4H3Fek7.js +0 -2210
- package/dist/cdn/basePath-B8HuhIMu.js +0 -25
- package/dist/cdn/bell-CGjAO_0s.js +0 -10
- package/dist/cdn/browser-CbQIH4w2.js +0 -42
- package/dist/cdn/brush-B_mKhyxG.js +0 -17
- package/dist/cdn/card-DgiYnSg-.js +0 -41
- package/dist/cdn/cfWorker-Bxcs9rNe.js +0 -10799
- package/dist/cdn/checkbox-By0FklhG.js +0 -20
- package/dist/cdn/chunk-QUQL4437-XnDcYQEx.js +0 -1508
- package/dist/cdn/clock-CmUbSx_B.js +0 -12
- package/dist/cdn/code-V_0nf5rg.js +0 -10
- package/dist/cdn/createLucideIcon-C5fZZ6oB.js +0 -38
- package/dist/cdn/dialog-BsDpuJd3.js +0 -1028
- package/dist/cdn/dist-DaMB0Su9.js +0 -616
- package/dist/cdn/dist-DbX5yidW.js +0 -2306
- package/dist/cdn/external-link-CjmfT6rW.js +0 -17
- package/dist/cdn/eye-B7H96av8.js +0 -29
- package/dist/cdn/folder-open-B3lu2rG_.js +0 -7
- package/dist/cdn/hash-BVQnWi7q.js +0 -33
- package/dist/cdn/history-Csw4rb44.js +0 -17
- package/dist/cdn/index-browser-DkQOzkvX.js +0 -1934
- package/dist/cdn/info-CNiOwqkf.js +0 -19
- package/dist/cdn/input-C2OBd4PJ.js +0 -12160
- package/dist/cdn/inspector-settings-layout-0VDsjeqb.js +0 -4
- package/dist/cdn/inspector.css +0 -2
- package/dist/cdn/inspector.js +0 -24523
- package/dist/cdn/jsx-runtime-CIxvMpEo.js +0 -180
- package/dist/cdn/label-B9Jmm9be.js +0 -60
- package/dist/cdn/loader-circle-BLy9A_pp.js +0 -7
- package/dist/cdn/manufact-auth-BQMHhbLV.js +0 -423
- package/dist/cdn/maximize-2-CH5Lq90B.js +0 -21
- package/dist/cdn/maximize-BALCV_ep.js +0 -21
- package/dist/cdn/message-square-BnxdpJxZ.js +0 -7
- package/dist/cdn/not-found-DEtSM_Wd.js +0 -34
- package/dist/cdn/play-vuZ5PLnI.js +0 -7
- package/dist/cdn/providerMeta-BQIfHuNL.js +0 -379
- package/dist/cdn/providers/anthropic.png +0 -0
- package/dist/cdn/providers/google.png +0 -0
- package/dist/cdn/providers/openai.png +0 -0
- package/dist/cdn/react-BIs9pQ3H.js +0 -926
- package/dist/cdn/react-BajV-X4P.js +0 -5425
- package/dist/cdn/refresh-cw-BXY-Pa0U.js +0 -21
- package/dist/cdn/save-Tgil_AJZ.js +0 -34
- package/dist/cdn/schemaHelpers-DTV38jGq.js +0 -16
- package/dist/cdn/select-DDdiIPR2.js +0 -2594
- package/dist/cdn/servers-Dm72iTpY.js +0 -26
- package/dist/cdn/shared-DaILIQPP.js +0 -1700
- package/dist/cdn/sheet-Br_l2kry.js +0 -2077
- package/dist/cdn/sparkles-BntO2rDR.js +0 -23
- package/dist/cdn/spinner-jQtC7EBj.js +0 -15
- package/dist/cdn/square-check-big-BvwQ17Bl.js +0 -10
- package/dist/cdn/switch-C3IyQuid.js +0 -664
- package/dist/cdn/tabs-subtle-CkdI6Mac.js +0 -787
- package/dist/cdn/telemetry-DabTAQ8x.js +0 -240
- package/dist/cdn/textarea-DSbwcFVt.js +0 -14
- package/dist/cdn/trash-2-RwpJY5SL.js +0 -25
- package/dist/cdn/useAriaLabelledBy-DqAdnppm.js +0 -29
- package/dist/cdn/useCompositeItem-BRqEzYh-.js +0 -26
- package/dist/cdn/useConfig-Btmh8wjJ.js +0 -235
- package/dist/cdn/useSavedRequests-Ci2I919u.js +0 -51
- package/dist/cdn/useViewHostProps-B6SKeeH9.js +0 -349
- package/dist/cdn/wrench-DzGmCfnb.js +0 -7
- package/dist/cdn/x-C3vRQIYu.js +0 -10
- package/dist/cdn/zap-Mb-pbw2X.js +0 -10
- package/dist/client/auth/manufact-auth.d.ts +0 -32
- package/dist/client/auth/manufact-auth.d.ts.map +0 -1
- package/dist/client/chat-history/ChatHistoryHeader.d.ts +0 -4
- package/dist/client/chat-history/ChatHistoryHeader.d.ts.map +0 -1
- package/dist/client/chat-history/ChatHistoryPanel.d.ts +0 -28
- package/dist/client/chat-history/ChatHistoryPanel.d.ts.map +0 -1
- package/dist/client/chat-history/ChatHistoryRail.d.ts +0 -5
- package/dist/client/chat-history/ChatHistoryRail.d.ts.map +0 -1
- package/dist/client/chat-history/ChatList.d.ts +0 -18
- package/dist/client/chat-history/ChatList.d.ts.map +0 -1
- package/dist/client/chat-history/ChatTitleReveal.d.ts +0 -10
- package/dist/client/chat-history/ChatTitleReveal.d.ts.map +0 -1
- package/dist/client/chat-history/chat-events-to-inspector-messages.d.ts +0 -13
- package/dist/client/chat-history/chat-events-to-inspector-messages.d.ts.map +0 -1
- package/dist/client/chat-history/chat-title.d.ts +0 -10
- package/dist/client/chat-history/chat-title.d.ts.map +0 -1
- package/dist/client/chat-history/providers/local-storage.d.ts +0 -21
- package/dist/client/chat-history/providers/local-storage.d.ts.map +0 -1
- package/dist/client/chat-history/types.d.ts +0 -39
- package/dist/client/chat-history/types.d.ts.map +0 -1
- package/dist/client/chat-history/useChatHistory.d.ts +0 -20
- package/dist/client/chat-history/useChatHistory.d.ts.map +0 -1
- package/dist/client/chat-history/useChatTitleGeneration.d.ts +0 -17
- package/dist/client/chat-history/useChatTitleGeneration.d.ts.map +0 -1
- package/dist/client/components/AddToClientDropdown.d.ts +0 -52
- package/dist/client/components/AddToClientDropdown.d.ts.map +0 -1
- package/dist/client/components/ChatTab.d.ts +0 -98
- package/dist/client/components/ChatTab.d.ts.map +0 -1
- package/dist/client/components/IframeConsole.d.ts +0 -7
- package/dist/client/components/IframeConsole.d.ts.map +0 -1
- package/dist/client/components/MCPAppsDebugControls.d.ts +0 -19
- package/dist/client/components/MCPAppsDebugControls.d.ts.map +0 -1
- package/dist/client/components/PromptsTab.d.ts +0 -34
- package/dist/client/components/PromptsTab.d.ts.map +0 -1
- package/dist/client/components/ResourcesTab.d.ts +0 -31
- package/dist/client/components/ResourcesTab.d.ts.map +0 -1
- package/dist/client/components/ToolsTab.d.ts +0 -39
- package/dist/client/components/ToolsTab.d.ts.map +0 -1
- package/dist/client/components/chat/AssistantMessage.d.ts +0 -10
- package/dist/client/components/chat/AssistantMessage.d.ts.map +0 -1
- package/dist/client/components/chat/ChatHeader.d.ts +0 -70
- package/dist/client/components/chat/ChatHeader.d.ts.map +0 -1
- package/dist/client/components/chat/ChatInput.d.ts +0 -29
- package/dist/client/components/chat/ChatInput.d.ts.map +0 -1
- package/dist/client/components/chat/ChatInputArea.d.ts +0 -65
- package/dist/client/components/chat/ChatInputArea.d.ts.map +0 -1
- package/dist/client/components/chat/ChatLandingForm.d.ts +0 -15
- package/dist/client/components/chat/ChatLandingForm.d.ts.map +0 -1
- package/dist/client/components/chat/ChatManagedNotice.d.ts +0 -10
- package/dist/client/components/chat/ChatManagedNotice.d.ts.map +0 -1
- package/dist/client/components/chat/ChatScrollToBottomButton.d.ts +0 -7
- package/dist/client/components/chat/ChatScrollToBottomButton.d.ts.map +0 -1
- package/dist/client/components/chat/ChatScrollTopFade.d.ts +0 -7
- package/dist/client/components/chat/ChatScrollTopFade.d.ts.map +0 -1
- package/dist/client/components/chat/ChatTraceView.d.ts +0 -7
- package/dist/client/components/chat/ChatTraceView.d.ts.map +0 -1
- package/dist/client/components/chat/ConfigurationDialog.d.ts +0 -42
- package/dist/client/components/chat/ConfigurationDialog.d.ts.map +0 -1
- package/dist/client/components/chat/ConfigureEmptyState.d.ts +0 -6
- package/dist/client/components/chat/ConfigureEmptyState.d.ts.map +0 -1
- package/dist/client/components/chat/CopyButton.d.ts +0 -10
- package/dist/client/components/chat/CopyButton.d.ts.map +0 -1
- package/dist/client/components/chat/FloatingChatElicitation.d.ts +0 -10
- package/dist/client/components/chat/FloatingChatElicitation.d.ts.map +0 -1
- package/dist/client/components/chat/McpReconnectBanner.d.ts +0 -10
- package/dist/client/components/chat/McpReconnectBanner.d.ts.map +0 -1
- package/dist/client/components/chat/MessageList.d.ts +0 -47
- package/dist/client/components/chat/MessageList.d.ts.map +0 -1
- package/dist/client/components/chat/MessageMetaActions.d.ts +0 -7
- package/dist/client/components/chat/MessageMetaActions.d.ts.map +0 -1
- package/dist/client/components/chat/PromptResultsList.d.ts +0 -8
- package/dist/client/components/chat/PromptResultsList.d.ts.map +0 -1
- package/dist/client/components/chat/PromptsDropdown.d.ts +0 -11
- package/dist/client/components/chat/PromptsDropdown.d.ts.map +0 -1
- package/dist/client/components/chat/StreamingAssistantContent.d.ts +0 -7
- package/dist/client/components/chat/StreamingAssistantContent.d.ts.map +0 -1
- package/dist/client/components/chat/SystemPromptButton.d.ts +0 -11
- package/dist/client/components/chat/SystemPromptButton.d.ts.map +0 -1
- package/dist/client/components/chat/ToolCallDisplay.d.ts +0 -10
- package/dist/client/components/chat/ToolCallDisplay.d.ts.map +0 -1
- package/dist/client/components/chat/ToolResultRenderer.d.ts +0 -15
- package/dist/client/components/chat/ToolResultRenderer.d.ts.map +0 -1
- package/dist/client/components/chat/ToolSelector.d.ts +0 -13
- package/dist/client/components/chat/ToolSelector.d.ts.map +0 -1
- package/dist/client/components/chat/UserMessage.d.ts +0 -10
- package/dist/client/components/chat/UserMessage.d.ts.map +0 -1
- package/dist/client/components/chat/chat-bar-styles.d.ts +0 -6
- package/dist/client/components/chat/chat-bar-styles.d.ts.map +0 -1
- package/dist/client/components/chat/chatModeStorage.d.ts +0 -11
- package/dist/client/components/chat/chatModeStorage.d.ts.map +0 -1
- package/dist/client/components/chat/conversion.d.ts +0 -19
- package/dist/client/components/chat/conversion.d.ts.map +0 -1
- package/dist/client/components/chat/freeTier.d.ts +0 -32
- package/dist/client/components/chat/freeTier.d.ts.map +0 -1
- package/dist/client/components/chat/managedChatNotice.d.ts +0 -16
- package/dist/client/components/chat/managedChatNotice.d.ts.map +0 -1
- package/dist/client/components/chat/providerMeta.d.ts +0 -27
- package/dist/client/components/chat/providerMeta.d.ts.map +0 -1
- package/dist/client/components/chat/system-prompt/local-storage.d.ts +0 -5
- package/dist/client/components/chat/system-prompt/local-storage.d.ts.map +0 -1
- package/dist/client/components/chat/system-prompt/types.d.ts +0 -8
- package/dist/client/components/chat/system-prompt/types.d.ts.map +0 -1
- package/dist/client/components/chat/system-prompt/useLocalSystemPrompt.d.ts +0 -3
- package/dist/client/components/chat/system-prompt/useLocalSystemPrompt.d.ts.map +0 -1
- package/dist/client/components/chat/system-prompt-default.d.ts +0 -2
- package/dist/client/components/chat/system-prompt-default.d.ts.map +0 -1
- package/dist/client/components/chat/trace.d.ts +0 -84
- package/dist/client/components/chat/trace.d.ts.map +0 -1
- package/dist/client/components/chat/types.d.ts +0 -75
- package/dist/client/components/chat/types.d.ts.map +0 -1
- package/dist/client/components/chat/useChatMessages.d.ts +0 -76
- package/dist/client/components/chat/useChatMessages.d.ts.map +0 -1
- package/dist/client/components/chat/useChatMessagesClientSide.d.ts +0 -43
- package/dist/client/components/chat/useChatMessagesClientSide.d.ts.map +0 -1
- package/dist/client/components/chat/useChatScrollToBottom.d.ts +0 -14
- package/dist/client/components/chat/useChatScrollToBottom.d.ts.map +0 -1
- package/dist/client/components/chat/useConfig.d.ts +0 -24
- package/dist/client/components/chat/useConfig.d.ts.map +0 -1
- package/dist/client/components/chat/useHostedChatMode.d.ts +0 -14
- package/dist/client/components/chat/useHostedChatMode.d.ts.map +0 -1
- package/dist/client/components/chat/useManagedCloudModel.d.ts +0 -14
- package/dist/client/components/chat/useManagedCloudModel.d.ts.map +0 -1
- package/dist/client/components/chat/utils.d.ts +0 -11
- package/dist/client/components/chat/utils.d.ts.map +0 -1
- package/dist/client/components/elicitation/shared/ElicitationAskUserPanel.d.ts +0 -12
- package/dist/client/components/elicitation/shared/ElicitationAskUserPanel.d.ts.map +0 -1
- package/dist/client/components/elicitation/shared/elicitationToAskUserQuestions.d.ts +0 -9
- package/dist/client/components/elicitation/shared/elicitationToAskUserQuestions.d.ts.map +0 -1
- package/dist/client/components/elicitation/shared/schemaHelpers.d.ts +0 -8
- package/dist/client/components/elicitation/shared/schemaHelpers.d.ts.map +0 -1
- package/dist/client/components/prompts/PromptExecutionPanel.d.ts +0 -13
- package/dist/client/components/prompts/PromptExecutionPanel.d.ts.map +0 -1
- package/dist/client/components/prompts/PromptInputForm.d.ts +0 -9
- package/dist/client/components/prompts/PromptInputForm.d.ts.map +0 -1
- package/dist/client/components/prompts/PromptMessageCard.d.ts +0 -29
- package/dist/client/components/prompts/PromptMessageCard.d.ts.map +0 -1
- package/dist/client/components/prompts/PromptResultDisplay.d.ts +0 -34
- package/dist/client/components/prompts/PromptResultDisplay.d.ts.map +0 -1
- package/dist/client/components/prompts/PromptsList.d.ts +0 -10
- package/dist/client/components/prompts/PromptsList.d.ts.map +0 -1
- package/dist/client/components/prompts/SavedPromptsList.d.ts +0 -19
- package/dist/client/components/prompts/SavedPromptsList.d.ts.map +0 -1
- package/dist/client/components/resources/PropsConfigDialog.d.ts +0 -16
- package/dist/client/components/resources/PropsConfigDialog.d.ts.map +0 -1
- package/dist/client/components/resources/ResourceResultDisplay.d.ts +0 -30
- package/dist/client/components/resources/ResourceResultDisplay.d.ts.map +0 -1
- package/dist/client/components/resources/ResourcesList.d.ts +0 -10
- package/dist/client/components/resources/ResourcesList.d.ts.map +0 -1
- package/dist/client/components/shared/CollapsibleJSON.d.ts +0 -6
- package/dist/client/components/shared/CollapsibleJSON.d.ts.map +0 -1
- package/dist/client/components/shared/InspectorScrollArea.d.ts +0 -9
- package/dist/client/components/shared/InspectorScrollArea.d.ts.map +0 -1
- package/dist/client/components/shared/JSONDisplay.d.ts +0 -12
- package/dist/client/components/shared/JSONDisplay.d.ts.map +0 -1
- package/dist/client/components/shared/ListItem.d.ts +0 -24
- package/dist/client/components/shared/ListItem.d.ts.map +0 -1
- package/dist/client/components/shared/ListTabHeader.d.ts +0 -47
- package/dist/client/components/shared/ListTabHeader.d.ts.map +0 -1
- package/dist/client/components/shared/MarkdownRenderer.d.ts +0 -15
- package/dist/client/components/shared/MarkdownRenderer.d.ts.map +0 -1
- package/dist/client/components/shared/SchemaFormField.d.ts +0 -12
- package/dist/client/components/shared/SchemaFormField.d.ts.map +0 -1
- package/dist/client/components/shared/SearchTabHeader.d.ts +0 -28
- package/dist/client/components/shared/SearchTabHeader.d.ts.map +0 -1
- package/dist/client/components/shared/StatusIcon.d.ts +0 -12
- package/dist/client/components/shared/StatusIcon.d.ts.map +0 -1
- package/dist/client/components/shared/index.d.ts +0 -7
- package/dist/client/components/shared/index.d.ts.map +0 -1
- package/dist/client/components/tools/SaveRequestDialog.d.ts +0 -11
- package/dist/client/components/tools/SaveRequestDialog.d.ts.map +0 -1
- package/dist/client/components/tools/SavedRequestsList.d.ts +0 -19
- package/dist/client/components/tools/SavedRequestsList.d.ts.map +0 -1
- package/dist/client/components/tools/ToolExecutionPanel.d.ts +0 -20
- package/dist/client/components/tools/ToolExecutionPanel.d.ts.map +0 -1
- package/dist/client/components/tools/ToolInputForm.d.ts +0 -14
- package/dist/client/components/tools/ToolInputForm.d.ts.map +0 -1
- package/dist/client/components/tools/ToolResultDisplay.d.ts +0 -24
- package/dist/client/components/tools/ToolResultDisplay.d.ts.map +0 -1
- package/dist/client/components/tools/ToolsList.d.ts +0 -10
- package/dist/client/components/tools/ToolsList.d.ts.map +0 -1
- package/dist/client/components/tools/schema-utils.d.ts +0 -13
- package/dist/client/components/tools/schema-utils.d.ts.map +0 -1
- package/dist/client/components/tools/useToolExecution.d.ts +0 -26
- package/dist/client/components/tools/useToolExecution.d.ts.map +0 -1
- package/dist/client/components/tools/useToolsTabNavigation.d.ts +0 -35
- package/dist/client/components/tools/useToolsTabNavigation.d.ts.map +0 -1
- package/dist/client/components/ui/MeshGradientCanvas.d.ts +0 -13
- package/dist/client/components/ui/MeshGradientCanvas.d.ts.map +0 -1
- package/dist/client/components/ui/WidgetWrapper.d.ts +0 -12
- package/dist/client/components/ui/WidgetWrapper.d.ts.map +0 -1
- package/dist/client/components/ui/alert-dialog.d.ts +0 -15
- package/dist/client/components/ui/alert-dialog.d.ts.map +0 -1
- package/dist/client/components/ui/ask-user-questions.d.ts +0 -80
- package/dist/client/components/ui/ask-user-questions.d.ts.map +0 -1
- package/dist/client/components/ui/badge.d.ts +0 -34
- package/dist/client/components/ui/badge.d.ts.map +0 -1
- package/dist/client/components/ui/blur-fade.d.ts +0 -25
- package/dist/client/components/ui/blur-fade.d.ts.map +0 -1
- package/dist/client/components/ui/button.d.ts +0 -34
- package/dist/client/components/ui/button.d.ts.map +0 -1
- package/dist/client/components/ui/chat-message.d.ts +0 -23
- package/dist/client/components/ui/chat-message.d.ts.map +0 -1
- package/dist/client/components/ui/checkbox.d.ts +0 -4
- package/dist/client/components/ui/checkbox.d.ts.map +0 -1
- package/dist/client/components/ui/client-icons.d.ts +0 -20
- package/dist/client/components/ui/client-icons.d.ts.map +0 -1
- package/dist/client/components/ui/command.d.ts +0 -17
- package/dist/client/components/ui/command.d.ts.map +0 -1
- package/dist/client/components/ui/dialog.d.ts +0 -37
- package/dist/client/components/ui/dialog.d.ts.map +0 -1
- package/dist/client/components/ui/dropdown-menu.d.ts +0 -25
- package/dist/client/components/ui/dropdown-menu.d.ts.map +0 -1
- package/dist/client/components/ui/dropdown.d.ts +0 -30
- package/dist/client/components/ui/dropdown.d.ts.map +0 -1
- package/dist/client/components/ui/file-thumbnail.d.ts +0 -9
- package/dist/client/components/ui/file-thumbnail.d.ts.map +0 -1
- package/dist/client/components/ui/input.d.ts +0 -4
- package/dist/client/components/ui/input.d.ts.map +0 -1
- package/dist/client/components/ui/kbd.d.ts +0 -3
- package/dist/client/components/ui/kbd.d.ts.map +0 -1
- package/dist/client/components/ui/label.d.ts +0 -4
- package/dist/client/components/ui/label.d.ts.map +0 -1
- package/dist/client/components/ui/menu-item.d.ts +0 -52
- package/dist/client/components/ui/menu-item.d.ts.map +0 -1
- package/dist/client/components/ui/mesh-tab-background.d.ts +0 -12
- package/dist/client/components/ui/mesh-tab-background.d.ts.map +0 -1
- package/dist/client/components/ui/not-found.d.ts +0 -9
- package/dist/client/components/ui/not-found.d.ts.map +0 -1
- package/dist/client/components/ui/popover.d.ts +0 -6
- package/dist/client/components/ui/popover.d.ts.map +0 -1
- package/dist/client/components/ui/resizable.d.ts +0 -10
- package/dist/client/components/ui/resizable.d.ts.map +0 -1
- package/dist/client/components/ui/scroll-area.d.ts +0 -4
- package/dist/client/components/ui/scroll-area.d.ts.map +0 -1
- package/dist/client/components/ui/select.d.ts +0 -52
- package/dist/client/components/ui/select.d.ts.map +0 -1
- package/dist/client/components/ui/sheet.d.ts +0 -14
- package/dist/client/components/ui/sheet.d.ts.map +0 -1
- package/dist/client/components/ui/skeleton.d.ts +0 -4
- package/dist/client/components/ui/skeleton.d.ts.map +0 -1
- package/dist/client/components/ui/spinner.d.ts +0 -3
- package/dist/client/components/ui/spinner.d.ts.map +0 -1
- package/dist/client/components/ui/switch.d.ts +0 -22
- package/dist/client/components/ui/switch.d.ts.map +0 -1
- package/dist/client/components/ui/table.d.ts +0 -9
- package/dist/client/components/ui/table.d.ts.map +0 -1
- package/dist/client/components/ui/tabs-subtle.d.ts +0 -25
- package/dist/client/components/ui/tabs-subtle.d.ts.map +0 -1
- package/dist/client/components/ui/text-shimmer.d.ts +0 -11
- package/dist/client/components/ui/text-shimmer.d.ts.map +0 -1
- package/dist/client/components/ui/textarea.d.ts +0 -4
- package/dist/client/components/ui/textarea.d.ts.map +0 -1
- package/dist/client/components/ui/tooltip.d.ts +0 -43
- package/dist/client/components/ui/tooltip.d.ts.map +0 -1
- package/dist/client/components/ui-playground/shared/SafeAreaInsetsEditor.d.ts +0 -19
- package/dist/client/components/ui-playground/shared/SafeAreaInsetsEditor.d.ts.map +0 -1
- package/dist/client/console-log-bus.d.ts +0 -24
- package/dist/client/console-log-bus.d.ts.map +0 -1
- package/dist/client/constants/debug-options.d.ts +0 -16
- package/dist/client/constants/debug-options.d.ts.map +0 -1
- package/dist/client/context/InspectorContext.d.ts +0 -134
- package/dist/client/context/InspectorContext.d.ts.map +0 -1
- package/dist/client/context/ThemeContext.d.ts +0 -17
- package/dist/client/context/ThemeContext.d.ts.map +0 -1
- package/dist/client/context/WidgetDebugContext.d.ts +0 -121
- package/dist/client/context/WidgetDebugContext.d.ts.map +0 -1
- package/dist/client/hooks/use-merge-split.d.ts +0 -36
- package/dist/client/hooks/use-merge-split.d.ts.map +0 -1
- package/dist/client/hooks/use-proximity-hover-index.d.ts +0 -27
- package/dist/client/hooks/use-proximity-hover-index.d.ts.map +0 -1
- package/dist/client/hooks/use-proximity-hover.d.ts +0 -26
- package/dist/client/hooks/use-proximity-hover.d.ts.map +0 -1
- package/dist/client/hooks/use-touch-primary.d.ts +0 -2
- package/dist/client/hooks/use-touch-primary.d.ts.map +0 -1
- package/dist/client/hooks/useDeviceViewport.d.ts +0 -18
- package/dist/client/hooks/useDeviceViewport.d.ts.map +0 -1
- package/dist/client/hooks/useHostedSession.d.ts +0 -9
- package/dist/client/hooks/useHostedSession.d.ts.map +0 -1
- package/dist/client/hooks/useIframeConsole.d.ts +0 -24
- package/dist/client/hooks/useIframeConsole.d.ts.map +0 -1
- package/dist/client/hooks/useKeyboardShortcuts.d.ts +0 -28
- package/dist/client/hooks/useKeyboardShortcuts.d.ts.map +0 -1
- package/dist/client/hooks/useMCPPrompts.d.ts +0 -94
- package/dist/client/hooks/useMCPPrompts.d.ts.map +0 -1
- package/dist/client/hooks/useMcpAppsHostContext.d.ts +0 -27
- package/dist/client/hooks/useMcpAppsHostContext.d.ts.map +0 -1
- package/dist/client/hooks/usePropsLLM.d.ts +0 -20
- package/dist/client/hooks/usePropsLLM.d.ts.map +0 -1
- package/dist/client/hooks/useResourceProps.d.ts +0 -14
- package/dist/client/hooks/useResourceProps.d.ts.map +0 -1
- package/dist/client/hooks/useSavedRequests.d.ts +0 -6
- package/dist/client/hooks/useSavedRequests.d.ts.map +0 -1
- package/dist/client/hooks/useViewHostProps.d.ts +0 -19
- package/dist/client/hooks/useViewHostProps.d.ts.map +0 -1
- package/dist/client/index.d.ts.map +0 -1
- package/dist/client/lib/elevated.d.ts +0 -28
- package/dist/client/lib/elevated.d.ts.map +0 -1
- package/dist/client/lib/font-weight.d.ts +0 -10
- package/dist/client/lib/font-weight.d.ts.map +0 -1
- package/dist/client/lib/icon-context.d.ts +0 -15
- package/dist/client/lib/icon-context.d.ts.map +0 -1
- package/dist/client/lib/shape-context.d.ts +0 -21
- package/dist/client/lib/shape-context.d.ts.map +0 -1
- package/dist/client/lib/springs.d.ts +0 -32
- package/dist/client/lib/springs.d.ts.map +0 -1
- package/dist/client/lib/surface-classes.d.ts +0 -2
- package/dist/client/lib/surface-classes.d.ts.map +0 -1
- package/dist/client/lib/surface-context.d.ts +0 -7
- package/dist/client/lib/surface-context.d.ts.map +0 -1
- package/dist/client/lib/utils.d.ts +0 -3
- package/dist/client/lib/utils.d.ts.map +0 -1
- package/dist/client/mcp-apps/csp.d.ts +0 -26
- package/dist/client/mcp-apps/csp.d.ts.map +0 -1
- package/dist/client/mcp-apps/debug/csp-suggestions.d.ts +0 -17
- package/dist/client/mcp-apps/debug/csp-suggestions.d.ts.map +0 -1
- package/dist/client/mcp-apps/logging-transport.d.ts +0 -13
- package/dist/client/mcp-apps/logging-transport.d.ts.map +0 -1
- package/dist/client/rpc-traffic-coalesce.d.ts +0 -7
- package/dist/client/rpc-traffic-coalesce.d.ts.map +0 -1
- package/dist/client/rpc-traffic-store.d.ts +0 -37
- package/dist/client/rpc-traffic-store.d.ts.map +0 -1
- package/dist/client/telemetry/capture.d.ts +0 -7
- package/dist/client/telemetry/capture.d.ts.map +0 -1
- package/dist/client/telemetry/events.d.ts +0 -168
- package/dist/client/telemetry/events.d.ts.map +0 -1
- package/dist/client/telemetry/index.d.ts +0 -5
- package/dist/client/telemetry/index.d.ts.map +0 -1
- package/dist/client/telemetry/init.d.ts +0 -2
- package/dist/client/telemetry/init.d.ts.map +0 -1
- package/dist/client/telemetry/utils.d.ts +0 -7
- package/dist/client/telemetry/utils.d.ts.map +0 -1
- package/dist/client/types/message-content-block.d.ts +0 -19
- package/dist/client/types/message-content-block.d.ts.map +0 -1
- package/dist/client/types/pending-requests.d.ts +0 -17
- package/dist/client/types/pending-requests.d.ts.map +0 -1
- package/dist/client/utils/basePath.d.ts +0 -34
- package/dist/client/utils/basePath.d.ts.map +0 -1
- package/dist/client/utils/browser.d.ts +0 -5
- package/dist/client/utils/browser.d.ts.map +0 -1
- package/dist/client/utils/format.d.ts +0 -4
- package/dist/client/utils/format.d.ts.map +0 -1
- package/dist/client/utils/highlightJson.d.ts +0 -11
- package/dist/client/utils/highlightJson.d.ts.map +0 -1
- package/dist/client/utils/jsonUtils.d.ts +0 -24
- package/dist/client/utils/jsonUtils.d.ts.map +0 -1
- package/dist/client/utils/mcpClientUtils.d.ts +0 -131
- package/dist/client/utils/mcpClientUtils.d.ts.map +0 -1
- package/dist/client/utils/servers.d.ts +0 -14
- package/dist/client/utils/servers.d.ts.map +0 -1
- package/dist/server/asset-urls.d.ts +0 -18
- package/dist/server/asset-urls.d.ts.map +0 -1
- package/dist/server/asset-urls.js +0 -17
- package/dist/server/cdn-shell.d.ts +0 -18
- package/dist/server/cdn-shell.d.ts.map +0 -1
- package/dist/server/cdn-shell.js +0 -12
- package/dist/server/chunk-DSTNUYWX.js +0 -148
- package/dist/server/chunk-H6ZCIKBS.js +0 -63
- package/dist/server/chunk-IKTZUWSX.js +0 -0
- package/dist/server/chunk-J4FNYLBF.js +0 -54
- package/dist/server/chunk-K2F2AJOI.js +0 -619
- package/dist/server/chunk-KD7K27XK.js +0 -77
- package/dist/server/chunk-M5TZA42I.js +0 -54
- package/dist/server/chunk-OWR2BIBW.js +0 -40
- package/dist/server/chunk-PKBMQBKP.js +0 -7
- package/dist/server/chunk-SQ4XNMLT.js +0 -72
- package/dist/server/chunk-UJLXHNQP.js +0 -43
- package/dist/server/chunk-WFT4JHYI.js +0 -24
- package/dist/server/chunk-XCNS5CIW.js +0 -199
- package/dist/server/chunk-ZCGLU5T7.js +0 -156
- package/dist/server/cli.d.ts +0 -3
- package/dist/server/cli.d.ts.map +0 -1
- package/dist/server/cli.js +0 -141
- package/dist/server/create-dev-api-app.d.ts +0 -4
- package/dist/server/create-dev-api-app.d.ts.map +0 -1
- package/dist/server/create-dev-api-app.js +0 -11
- package/dist/server/dev-callback-redirect.d.ts +0 -3
- package/dist/server/dev-callback-redirect.d.ts.map +0 -1
- package/dist/server/dev-callback-redirect.js +0 -18
- package/dist/server/favicon-links.d.ts +0 -12
- package/dist/server/favicon-links.d.ts.map +0 -1
- package/dist/server/favicon-links.js +0 -11
- package/dist/server/favicon-static.d.ts +0 -4
- package/dist/server/favicon-static.d.ts.map +0 -1
- package/dist/server/favicon-static.js +0 -8
- package/dist/server/index.d.ts.map +0 -1
- package/dist/server/middleware.d.ts +0 -40
- package/dist/server/middleware.d.ts.map +0 -1
- package/dist/server/middleware.js +0 -17
- package/dist/server/proxy/index.d.ts +0 -3
- package/dist/server/proxy/index.d.ts.map +0 -1
- package/dist/server/proxy/index.js +0 -12
- package/dist/server/proxy/mcp-proxy.d.ts +0 -101
- package/dist/server/proxy/mcp-proxy.d.ts.map +0 -1
- package/dist/server/proxy/mcp-proxy.js +0 -10
- package/dist/server/proxy/oauth-proxy.d.ts +0 -26
- package/dist/server/proxy/oauth-proxy.d.ts.map +0 -1
- package/dist/server/proxy/oauth-proxy.js +0 -9
- package/dist/server/proxy-routes.d.ts +0 -16
- package/dist/server/proxy-routes.d.ts.map +0 -1
- package/dist/server/proxy-routes.js +0 -10
- package/dist/server/rpc-log-bus.d.ts +0 -17
- package/dist/server/rpc-log-bus.d.ts.map +0 -1
- package/dist/server/rpc-log-bus.js +0 -77
- package/dist/server/server.d.ts +0 -15
- package/dist/server/server.d.ts.map +0 -1
- package/dist/server/server.js +0 -66
- package/dist/server/static-assets.d.ts +0 -5
- package/dist/server/static-assets.d.ts.map +0 -1
- package/dist/server/static-assets.js +0 -9
- package/dist/server/utils.d.ts +0 -33
- package/dist/server/utils.d.ts.map +0 -1
- package/dist/server/utils.js +0 -17
- package/dist/server/version.d.ts +0 -7
- package/dist/server/version.d.ts.map +0 -1
- package/dist/server/version.js +0 -9
- package/dist/server/vite-dev-api-plugin.d.ts +0 -4
- package/dist/server/vite-dev-api-plugin.d.ts.map +0 -1
- package/dist/server/vite-dev-api-plugin.js +0 -30
- package/dist/web/apple-touch-icon.png +0 -0
- package/dist/web/assets/AnimatePresence-C5p0yiY1.js +0 -9
- package/dist/web/assets/ChatTab-BCobuZDc.js +0 -18
- package/dist/web/assets/ConnectionSettingsTab-BjGkLwVu.js +0 -1
- package/dist/web/assets/ElicitationTab-D3ZUKHND.js +0 -1
- package/dist/web/assets/FormContext-DH2caWKO.js +0 -1
- package/dist/web/assets/ListTabHeader-R17w_JsB.js +0 -1
- package/dist/web/assets/ManufactOAuthCallback-CS3ydSZg.js +0 -1
- package/dist/web/assets/MarkdownRenderer-BeeBfQhv.js +0 -47
- package/dist/web/assets/NotificationsTab-Uj0_DrmK.js +0 -1
- package/dist/web/assets/OAuthCallback-C0ljgCiw.js +0 -1
- package/dist/web/assets/PromptsTab-Bns2u0G-.js +0 -15
- package/dist/web/assets/ResourcesTab-CO24312V.js +0 -2
- package/dist/web/assets/SamplingTab-7gtN7FwU.js +0 -1
- package/dist/web/assets/ServerMetadataTab-CQwqYSjL.js +0 -1
- package/dist/web/assets/ToolsTab-bDdRxI1b.js +0 -8
- package/dist/web/assets/ViewPreview-Ba1Ec5uA.js +0 -1
- package/dist/web/assets/WidgetWrapper-CYHfzrtb.js +0 -34
- package/dist/web/assets/brush--0LobUi4.js +0 -1
- package/dist/web/assets/checkbox-CzBkaNKa.js +0 -1
- package/dist/web/assets/code-tME-5H6D.js +0 -1
- package/dist/web/assets/createLucideIcon-B3b8EU0b.js +0 -1
- package/dist/web/assets/dist-C5JjLJN9.js +0 -21
- package/dist/web/assets/index-TQ5V7cM9.js +0 -492
- package/dist/web/assets/index-fBX3akc8.css +0 -1
- package/dist/web/assets/input-CLYhA7PK.js +0 -1
- package/dist/web/assets/inspector-settings-layout-yjKRJDai.js +0 -1
- package/dist/web/assets/jsx-runtime-Cjj9sGSy.js +0 -1
- package/dist/web/assets/label-Cdim77Jw.js +0 -1
- package/dist/web/assets/maximize-2-BTT9QQU9.js +0 -1
- package/dist/web/assets/maximize-_O55kFcr.js +0 -1
- package/dist/web/assets/react-CU_d2d5K.js +0 -1
- package/dist/web/assets/refresh-cw-C9wQl8_d.js +0 -1
- package/dist/web/assets/save-B-MsgxX9.js +0 -1
- package/dist/web/assets/schemaHelpers-DLNTQr_6.js +0 -1
- package/dist/web/assets/select-CJ57-Bor.js +0 -1
- package/dist/web/assets/shared-BF0rJNdE.js +0 -1
- package/dist/web/assets/sparkles-2OAsc1aP.js +0 -1
- package/dist/web/assets/tabs-subtle-6D79T1xd.js +0 -1
- package/dist/web/assets/textarea-DLAmNVf_.js +0 -1
- package/dist/web/assets/useConfig-BAgALiZg.js +0 -1
- package/dist/web/assets/useViewHostProps-BYitt_6K.js +0 -1
- package/dist/web/assets/zap-Du2Uc5pa.js +0 -1
- package/dist/web/favicon-96x96.png +0 -0
- package/dist/web/favicon-black.svg +0 -5
- package/dist/web/favicon-white.svg +0 -5
- package/dist/web/favicon.ico +0 -0
- package/dist/web/favicon.svg +0 -5
- package/dist/web/index.html +0 -89
- package/dist/web/providers/anthropic.png +0 -0
- package/dist/web/providers/google.png +0 -0
- package/dist/web/providers/openai.png +0 -0
- package/dist/web/site.webmanifest +0 -21
- package/dist/web/web-app-manifest-192x192.png +0 -0
- package/dist/web/web-app-manifest-512x512.png +0 -0
- /package/dist/{cdn → app}/apple-touch-icon.png +0 -0
- /package/dist/{cdn → app}/favicon-96x96.png +0 -0
- /package/dist/{cdn → app}/favicon-black.svg +0 -0
- /package/dist/{cdn → app}/favicon-white.svg +0 -0
- /package/dist/{cdn → app}/favicon.ico +0 -0
- /package/dist/{cdn → app}/favicon.svg +0 -0
- /package/dist/{cdn → app}/site.webmanifest +0 -0
- /package/dist/{cdn → app}/web-app-manifest-192x192.png +0 -0
- /package/dist/{cdn → app}/web-app-manifest-512x512.png +0 -0
|
@@ -1,2306 +0,0 @@
|
|
|
1
|
-
import { F as e } from "./cfWorker-Bxcs9rNe.js";
|
|
2
|
-
import { a as t } from "./index-browser-DkQOzkvX.js";
|
|
3
|
-
//#region ../agent/dist/index.js
|
|
4
|
-
var n = class {
|
|
5
|
-
disallowedTools;
|
|
6
|
-
connectorToolMap = /* @__PURE__ */ new Map();
|
|
7
|
-
constructor(e) {
|
|
8
|
-
this.disallowedTools = e ?? [];
|
|
9
|
-
}
|
|
10
|
-
static async createTools(e, n) {
|
|
11
|
-
let r = new this(n);
|
|
12
|
-
(!e.activeSessions || Object.keys(e.activeSessions).length === 0) && (t.debug("No active sessions found, creating new ones..."), await e.createAllSessions());
|
|
13
|
-
let i = e.getAllActiveSessions(), a = Object.values(i).map((e) => e.connector);
|
|
14
|
-
return r.createToolsFromConnectors(a);
|
|
15
|
-
}
|
|
16
|
-
async loadToolsForConnector(e) {
|
|
17
|
-
if (this.connectorToolMap.has(e)) {
|
|
18
|
-
let n = this.connectorToolMap.get(e);
|
|
19
|
-
return t.debug(`Returning ${n.length} existing tools for connector`), n;
|
|
20
|
-
}
|
|
21
|
-
let n = [];
|
|
22
|
-
if (!await this.ensureConnectorInitialized(e)) return [];
|
|
23
|
-
for (let t of e.tools) {
|
|
24
|
-
let r = this.convertTool(t, e);
|
|
25
|
-
r && n.push(r);
|
|
26
|
-
}
|
|
27
|
-
return this.connectorToolMap.set(e, n), t.debug(`Loaded ${n.length} new tools for connector: ${n.map((e) => e?.name ?? String(e)).join(", ")}`), n;
|
|
28
|
-
}
|
|
29
|
-
async createToolsFromConnectors(e) {
|
|
30
|
-
let n = [];
|
|
31
|
-
for (let t of e) {
|
|
32
|
-
let e = await this.loadToolsForConnector(t);
|
|
33
|
-
n.push(...e);
|
|
34
|
-
}
|
|
35
|
-
return t.debug(`Available tools: ${n.length}`), n;
|
|
36
|
-
}
|
|
37
|
-
async loadResourcesForConnector(e) {
|
|
38
|
-
let n = [];
|
|
39
|
-
if (!await this.ensureConnectorInitialized(e)) return [];
|
|
40
|
-
try {
|
|
41
|
-
let r = (await e.listAllResources())?.resources || [];
|
|
42
|
-
if (this.convertResource) for (let t of r) {
|
|
43
|
-
let r = this.convertResource(t, e);
|
|
44
|
-
r && n.push(r);
|
|
45
|
-
}
|
|
46
|
-
t.debug(`Loaded ${n.length} new resources for connector: ${n.map((e) => e?.name ?? String(e)).join(", ")}`);
|
|
47
|
-
} catch (e) {
|
|
48
|
-
t.warn(`Error loading resources for connector: ${e}`);
|
|
49
|
-
}
|
|
50
|
-
return n;
|
|
51
|
-
}
|
|
52
|
-
async loadPromptsForConnector(e) {
|
|
53
|
-
let n = [];
|
|
54
|
-
if (!await this.ensureConnectorInitialized(e)) return [];
|
|
55
|
-
try {
|
|
56
|
-
let r = (await e.listPrompts())?.prompts || [];
|
|
57
|
-
if (this.convertPrompt) for (let t of r) {
|
|
58
|
-
let r = this.convertPrompt(t, e);
|
|
59
|
-
r && n.push(r);
|
|
60
|
-
}
|
|
61
|
-
t.debug(`Loaded ${n.length} new prompts for connector: ${n.map((e) => e?.name ?? String(e)).join(", ")}`);
|
|
62
|
-
} catch (e) {
|
|
63
|
-
t.warn(`Error loading prompts for connector: ${e}`);
|
|
64
|
-
}
|
|
65
|
-
return n;
|
|
66
|
-
}
|
|
67
|
-
async createResourcesFromConnectors(e) {
|
|
68
|
-
let n = [];
|
|
69
|
-
for (let t of e) {
|
|
70
|
-
let e = await this.loadResourcesForConnector(t);
|
|
71
|
-
n.push(...e);
|
|
72
|
-
}
|
|
73
|
-
return t.debug(`Available resources: ${n.length}`), n;
|
|
74
|
-
}
|
|
75
|
-
async createPromptsFromConnectors(e) {
|
|
76
|
-
let n = [];
|
|
77
|
-
for (let t of e) {
|
|
78
|
-
let e = await this.loadPromptsForConnector(t);
|
|
79
|
-
n.push(...e);
|
|
80
|
-
}
|
|
81
|
-
return t.debug(`Available prompts: ${n.length}`), n;
|
|
82
|
-
}
|
|
83
|
-
checkConnectorInitialized(e) {
|
|
84
|
-
return !!(e.tools && e.tools.length);
|
|
85
|
-
}
|
|
86
|
-
async ensureConnectorInitialized(e) {
|
|
87
|
-
if (!this.checkConnectorInitialized(e)) {
|
|
88
|
-
t.debug("Connector doesn't have tools, initializing it");
|
|
89
|
-
try {
|
|
90
|
-
return await e.initialize(), !0;
|
|
91
|
-
} catch (e) {
|
|
92
|
-
return t.error(`Error initializing connector: ${e}`), !1;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
return !0;
|
|
96
|
-
}
|
|
97
|
-
};
|
|
98
|
-
function r(e) {
|
|
99
|
-
return e.replace(/[^A-Za-z0-9_]+/g, "_").toLowerCase().replace(/^_+|_+$/g, "");
|
|
100
|
-
}
|
|
101
|
-
var i = class extends n {
|
|
102
|
-
usedToolNames = /* @__PURE__ */ new Set();
|
|
103
|
-
handlers = /* @__PURE__ */ new Map();
|
|
104
|
-
constructor(e = []) {
|
|
105
|
-
super(e);
|
|
106
|
-
}
|
|
107
|
-
async createToolsFromConnectors(e) {
|
|
108
|
-
return this.usedToolNames.clear(), this.handlers.clear(), super.createToolsFromConnectors(e);
|
|
109
|
-
}
|
|
110
|
-
createCallTool() {
|
|
111
|
-
let e = this.handlers;
|
|
112
|
-
return async (n, r) => {
|
|
113
|
-
let i = e.get(n);
|
|
114
|
-
if (!i) throw Error(`Unknown tool: ${n}`);
|
|
115
|
-
try {
|
|
116
|
-
if (i.kind === "tool") return await i.connector.callTool(i.mcpName, r);
|
|
117
|
-
if (i.kind === "resource") {
|
|
118
|
-
let e = i.resourceUri ?? i.mcpName;
|
|
119
|
-
return await i.connector.readResource(e);
|
|
120
|
-
}
|
|
121
|
-
return await i.connector.getPrompt(i.mcpName, r);
|
|
122
|
-
} catch (e) {
|
|
123
|
-
throw t.error(`Error executing native MCP tool ${n}: ${e}`), e;
|
|
124
|
-
}
|
|
125
|
-
};
|
|
126
|
-
}
|
|
127
|
-
toProviderTools(e) {
|
|
128
|
-
return e.map(({ name: e, description: t, inputSchema: n }) => ({
|
|
129
|
-
name: e,
|
|
130
|
-
description: t,
|
|
131
|
-
inputSchema: n
|
|
132
|
-
}));
|
|
133
|
-
}
|
|
134
|
-
reserveName(e, t) {
|
|
135
|
-
if (!this.usedToolNames.has(e)) return this.usedToolNames.add(e), e;
|
|
136
|
-
if (t) {
|
|
137
|
-
let n = `${t}_${e}`;
|
|
138
|
-
if (!this.usedToolNames.has(n)) return this.usedToolNames.add(n), n;
|
|
139
|
-
let r = 2;
|
|
140
|
-
for (; this.usedToolNames.has(`${n}_${r}`);) r++;
|
|
141
|
-
let i = `${n}_${r}`;
|
|
142
|
-
return this.usedToolNames.add(i), i;
|
|
143
|
-
}
|
|
144
|
-
let n = 2;
|
|
145
|
-
for (; this.usedToolNames.has(`${e}_${n}`);) n++;
|
|
146
|
-
let r = `${e}_${n}`;
|
|
147
|
-
return this.usedToolNames.add(r), r;
|
|
148
|
-
}
|
|
149
|
-
register(e, t) {
|
|
150
|
-
return this.handlers.set(e.name, t), e;
|
|
151
|
-
}
|
|
152
|
-
convertTool(e, t) {
|
|
153
|
-
if (this.disallowedTools.includes(e.name)) return null;
|
|
154
|
-
let n = this.reserveName(e.name ?? "tool"), r = {
|
|
155
|
-
name: n,
|
|
156
|
-
dispatchKey: n,
|
|
157
|
-
description: e.description ?? "",
|
|
158
|
-
inputSchema: e.inputSchema ?? {
|
|
159
|
-
type: "object",
|
|
160
|
-
properties: {}
|
|
161
|
-
}
|
|
162
|
-
};
|
|
163
|
-
return this.register(r, {
|
|
164
|
-
connector: t,
|
|
165
|
-
kind: "tool",
|
|
166
|
-
mcpName: e.name
|
|
167
|
-
});
|
|
168
|
-
}
|
|
169
|
-
convertResource(e, t) {
|
|
170
|
-
let n = r(e.name || e.uri) || "resource", i = this.reserveName(n, "resource"), a = {
|
|
171
|
-
name: i,
|
|
172
|
-
dispatchKey: i,
|
|
173
|
-
description: e.description || `Return the content of the resource located at URI ${e.uri}.`,
|
|
174
|
-
inputSchema: {
|
|
175
|
-
type: "object",
|
|
176
|
-
properties: {}
|
|
177
|
-
}
|
|
178
|
-
};
|
|
179
|
-
return this.register(a, {
|
|
180
|
-
connector: t,
|
|
181
|
-
kind: "resource",
|
|
182
|
-
mcpName: e.uri,
|
|
183
|
-
resourceUri: e.uri
|
|
184
|
-
});
|
|
185
|
-
}
|
|
186
|
-
convertPrompt(e, t) {
|
|
187
|
-
let n = {}, i = [];
|
|
188
|
-
if (e.arguments?.length) for (let t of e.arguments) n[t.name] = {
|
|
189
|
-
type: "string",
|
|
190
|
-
description: t.description
|
|
191
|
-
}, t.required !== !1 && i.push(t.name);
|
|
192
|
-
let a = r(e.name || "prompt") || "prompt", o = this.reserveName(a, "prompt"), s = {
|
|
193
|
-
name: o,
|
|
194
|
-
dispatchKey: o,
|
|
195
|
-
description: e.description || "",
|
|
196
|
-
inputSchema: {
|
|
197
|
-
type: "object",
|
|
198
|
-
properties: n,
|
|
199
|
-
...i.length > 0 ? { required: i } : {}
|
|
200
|
-
}
|
|
201
|
-
};
|
|
202
|
-
return this.register(s, {
|
|
203
|
-
connector: t,
|
|
204
|
-
kind: "prompt",
|
|
205
|
-
mcpName: e.name
|
|
206
|
-
});
|
|
207
|
-
}
|
|
208
|
-
};
|
|
209
|
-
function a(e) {
|
|
210
|
-
return {
|
|
211
|
-
type: "text",
|
|
212
|
-
text: e
|
|
213
|
-
};
|
|
214
|
-
}
|
|
215
|
-
function o(e, t) {
|
|
216
|
-
return {
|
|
217
|
-
type: "image",
|
|
218
|
-
url: `data:${t};base64,${e}`,
|
|
219
|
-
mimeType: t,
|
|
220
|
-
data: e
|
|
221
|
-
};
|
|
222
|
-
}
|
|
223
|
-
function s(e) {
|
|
224
|
-
if (!e || typeof e != "object") return !1;
|
|
225
|
-
let t = e;
|
|
226
|
-
return Array.isArray(t.content) ? !0 : "structuredContent" in t;
|
|
227
|
-
}
|
|
228
|
-
function c(e) {
|
|
229
|
-
return typeof e == "object" && !!e && e.isError === !0;
|
|
230
|
-
}
|
|
231
|
-
function l(e) {
|
|
232
|
-
if (!e || typeof e != "object") return null;
|
|
233
|
-
switch (e.type) {
|
|
234
|
-
case "text": {
|
|
235
|
-
let t = e.text;
|
|
236
|
-
return typeof t == "string" && t.length > 0 ? a(t) : null;
|
|
237
|
-
}
|
|
238
|
-
case "image": {
|
|
239
|
-
let t = e;
|
|
240
|
-
if (typeof t.data != "string" || !t.data) return null;
|
|
241
|
-
let n = typeof t.mimeType == "string" && t.mimeType ? t.mimeType : "image/png";
|
|
242
|
-
return o(t.data, n);
|
|
243
|
-
}
|
|
244
|
-
case "audio": {
|
|
245
|
-
let t = e;
|
|
246
|
-
return a(`[audio: ${typeof t.mimeType == "string" && t.mimeType ? t.mimeType : "audio/*"}, base64 omitted (${typeof t.data == "string" ? t.data.length : 0} chars)]`);
|
|
247
|
-
}
|
|
248
|
-
case "resource": {
|
|
249
|
-
let t = e.resource ?? {};
|
|
250
|
-
return typeof t.text == "string" && t.text.length > 0 ? a(t.text) : typeof t.blob == "string" && typeof t.mimeType == "string" && t.mimeType.startsWith("image/") ? o(t.blob, t.mimeType) : a(`[resource: ${typeof t.uri == "string" ? t.uri : "<unknown>"} (${typeof t.mimeType == "string" ? t.mimeType : "unknown"})]`);
|
|
251
|
-
}
|
|
252
|
-
case "resource_link": {
|
|
253
|
-
let t = e, n = typeof t.uri == "string" ? t.uri : "<unknown>";
|
|
254
|
-
return a(`[resource_link${typeof t.name == "string" ? ` "${t.name}"` : ""}: ${n}]`);
|
|
255
|
-
}
|
|
256
|
-
default: return a(`[unsupported tool content block: ${String(e.type)}]`);
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
function u(e) {
|
|
260
|
-
if (e && typeof e == "object" && !Array.isArray(e)) {
|
|
261
|
-
let { _meta: t, ...n } = e;
|
|
262
|
-
return n;
|
|
263
|
-
}
|
|
264
|
-
return e;
|
|
265
|
-
}
|
|
266
|
-
function ee(e) {
|
|
267
|
-
let t = u(e);
|
|
268
|
-
if (typeof t == "string") return t.length > 0 ? [a(t)] : [];
|
|
269
|
-
if (s(t)) {
|
|
270
|
-
let e = t, n = [];
|
|
271
|
-
if (Array.isArray(e.content)) for (let t of e.content) {
|
|
272
|
-
let e = l(t);
|
|
273
|
-
e && n.push(e);
|
|
274
|
-
}
|
|
275
|
-
if (e.structuredContent !== void 0) try {
|
|
276
|
-
n.push(a(`structuredContent: ${JSON.stringify(e.structuredContent)}`));
|
|
277
|
-
} catch {}
|
|
278
|
-
return e.isError && n.unshift(a("[tool reported isError=true]")), n;
|
|
279
|
-
}
|
|
280
|
-
try {
|
|
281
|
-
return [a(JSON.stringify(t))];
|
|
282
|
-
} catch {
|
|
283
|
-
return [a(String(t))];
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
function te(e) {
|
|
287
|
-
return e.length === 0 ? "" : e.every((e) => e.type === "text") ? e.map((e) => e.text).join("\n") : null;
|
|
288
|
-
}
|
|
289
|
-
function d(e) {
|
|
290
|
-
let t = ee(e), n = te(t);
|
|
291
|
-
return n === null ? t : n;
|
|
292
|
-
}
|
|
293
|
-
function f(e) {
|
|
294
|
-
if (typeof e == "string") return {
|
|
295
|
-
text: e,
|
|
296
|
-
imageParts: [],
|
|
297
|
-
isString: !0
|
|
298
|
-
};
|
|
299
|
-
let t = [], n = [];
|
|
300
|
-
for (let r of e) r.type === "text" ? r.text && t.push(r.text) : r.type === "image" && n.push(r);
|
|
301
|
-
return {
|
|
302
|
-
text: t.join("\n"),
|
|
303
|
-
imageParts: n,
|
|
304
|
-
isString: !1
|
|
305
|
-
};
|
|
306
|
-
}
|
|
307
|
-
function p(e, t) {
|
|
308
|
-
return `(Tool "${e ?? "<tool>"}" returned the following image${t === 1 ? "" : "s"}:)`;
|
|
309
|
-
}
|
|
310
|
-
function m(e) {
|
|
311
|
-
let t = typeof e.content == "string" ? e.content : Array.isArray(e.content) ? e.content.map((e) => e?.text ?? "").join("\n") : JSON.stringify(e.content ?? "");
|
|
312
|
-
return t.trim() ? t.trim() : e.parts?.length ? e.parts.filter((e) => e.type === "text" && e.text).map((e) => e.text).join("").trim() : "";
|
|
313
|
-
}
|
|
314
|
-
function ne(e) {
|
|
315
|
-
let t = [];
|
|
316
|
-
return e.forEach((e, n) => {
|
|
317
|
-
if (e.role === "user") {
|
|
318
|
-
let n = m(e) || "[no content]";
|
|
319
|
-
if (e.attachments?.length) {
|
|
320
|
-
let r = [{
|
|
321
|
-
type: "text",
|
|
322
|
-
text: n
|
|
323
|
-
}];
|
|
324
|
-
for (let t of e.attachments) t.type === "image" && r.push({
|
|
325
|
-
type: "image",
|
|
326
|
-
url: `data:${t.mimeType};base64,${t.data}`,
|
|
327
|
-
mimeType: t.mimeType,
|
|
328
|
-
data: t.data
|
|
329
|
-
});
|
|
330
|
-
t.push({
|
|
331
|
-
role: "user",
|
|
332
|
-
content: r
|
|
333
|
-
});
|
|
334
|
-
} else t.push({
|
|
335
|
-
role: "user",
|
|
336
|
-
content: n
|
|
337
|
-
});
|
|
338
|
-
return;
|
|
339
|
-
}
|
|
340
|
-
let r = (e.parts ?? []).filter((e) => e.type === "tool-invocation" && e.toolInvocation && e.toolInvocation.result !== void 0);
|
|
341
|
-
if (r.length === 0) {
|
|
342
|
-
let n = m(e) || "[no content]";
|
|
343
|
-
t.push({
|
|
344
|
-
role: "assistant",
|
|
345
|
-
content: n
|
|
346
|
-
});
|
|
347
|
-
return;
|
|
348
|
-
}
|
|
349
|
-
let i = m(e), a = r.map((e, t) => ({
|
|
350
|
-
id: `call_${n}_${t}_${e.toolInvocation.toolName}`,
|
|
351
|
-
name: e.toolInvocation.toolName,
|
|
352
|
-
args: e.toolInvocation.args
|
|
353
|
-
}));
|
|
354
|
-
t.push({
|
|
355
|
-
role: "assistant",
|
|
356
|
-
content: i,
|
|
357
|
-
toolCalls: a
|
|
358
|
-
}), r.forEach((e, r) => {
|
|
359
|
-
let i = e.toolInvocation.result;
|
|
360
|
-
t.push({
|
|
361
|
-
role: "tool",
|
|
362
|
-
content: d(i),
|
|
363
|
-
toolCallId: `call_${n}_${r}_${e.toolInvocation.toolName}`,
|
|
364
|
-
toolName: e.toolInvocation.toolName,
|
|
365
|
-
toolResult: i,
|
|
366
|
-
toolIsError: c(i)
|
|
367
|
-
});
|
|
368
|
-
});
|
|
369
|
-
}), t;
|
|
370
|
-
}
|
|
371
|
-
function re(e) {
|
|
372
|
-
let t = [], n = [];
|
|
373
|
-
for (let r of e) if (r.role === "system") {
|
|
374
|
-
if (typeof r.content == "string") t.push(r.content);
|
|
375
|
-
else if (Array.isArray(r.content)) for (let e of r.content) e.type === "text" && t.push(e.text);
|
|
376
|
-
} else n.push(r);
|
|
377
|
-
return {
|
|
378
|
-
system: t.length > 0 ? t.join("\n\n") : void 0,
|
|
379
|
-
rest: n
|
|
380
|
-
};
|
|
381
|
-
}
|
|
382
|
-
function h(e) {
|
|
383
|
-
let t = e.match(/^data:([^;,]+);base64,(.+)$/);
|
|
384
|
-
return t ? {
|
|
385
|
-
mimeType: t[1],
|
|
386
|
-
data: t[2]
|
|
387
|
-
} : null;
|
|
388
|
-
}
|
|
389
|
-
async function* g(e, t) {
|
|
390
|
-
let n = e.getReader(), r = new TextDecoder("utf-8"), i = "";
|
|
391
|
-
try {
|
|
392
|
-
for (;;) {
|
|
393
|
-
if (t?.aborted) return;
|
|
394
|
-
let { value: e, done: a } = await n.read();
|
|
395
|
-
if (a) break;
|
|
396
|
-
i += r.decode(e, { stream: !0 });
|
|
397
|
-
let o;
|
|
398
|
-
for (; (o = ie(i)) !== -1;) {
|
|
399
|
-
let e = i.slice(0, o);
|
|
400
|
-
i = i.slice(o).replace(/^(\r\n\r\n|\n\n|\r\r)/, "");
|
|
401
|
-
let t = _(e);
|
|
402
|
-
t && (yield t);
|
|
403
|
-
}
|
|
404
|
-
}
|
|
405
|
-
if (i.trim()) {
|
|
406
|
-
let e = _(i);
|
|
407
|
-
e && (yield e);
|
|
408
|
-
}
|
|
409
|
-
} finally {
|
|
410
|
-
try {
|
|
411
|
-
n.releaseLock();
|
|
412
|
-
} catch {}
|
|
413
|
-
}
|
|
414
|
-
}
|
|
415
|
-
function ie(e) {
|
|
416
|
-
let t = e.indexOf("\n\n"), n = e.indexOf("\r\n\r\n");
|
|
417
|
-
return t === -1 ? n : n === -1 ? t : Math.min(t, n);
|
|
418
|
-
}
|
|
419
|
-
function _(e) {
|
|
420
|
-
let t, n = [];
|
|
421
|
-
for (let r of e.split(/\r?\n/)) {
|
|
422
|
-
if (!r || r.startsWith(":")) continue;
|
|
423
|
-
let e = r.indexOf(":"), i = e === -1 ? r : r.slice(0, e), a = e === -1 ? "" : r.slice(e + 1);
|
|
424
|
-
a.startsWith(" ") && (a = a.slice(1)), i === "event" ? t = a : i === "data" && n.push(a);
|
|
425
|
-
}
|
|
426
|
-
return n.length === 0 ? null : {
|
|
427
|
-
event: t,
|
|
428
|
-
data: n.join("\n")
|
|
429
|
-
};
|
|
430
|
-
}
|
|
431
|
-
function v(e, ...t) {
|
|
432
|
-
for (let n of t) {
|
|
433
|
-
let t = e[n];
|
|
434
|
-
if (typeof t == "number" && Number.isFinite(t)) return t;
|
|
435
|
-
}
|
|
436
|
-
}
|
|
437
|
-
function y(e) {
|
|
438
|
-
if (!e || typeof e != "object") return;
|
|
439
|
-
let t = e, n = v(t, "inputTokens", "input_tokens", "prompt_tokens", "promptTokenCount", "prompt_eval_count"), r = v(t, "outputTokens", "output_tokens", "completion_tokens", "candidatesTokenCount", "eval_count"), i = v(t, "totalTokens", "total_tokens", "totalTokenCount") ?? (n !== void 0 && r !== void 0 ? n + r : void 0), a = t.input_tokens_details && typeof t.input_tokens_details == "object" ? t.input_tokens_details : void 0, o = t.output_tokens_details && typeof t.output_tokens_details == "object" ? t.output_tokens_details : void 0, s = v(t, "cachedInputTokens", "cache_read_input_tokens") ?? (a ? v(a, "cached_tokens") : void 0), c = v(t, "reasoningTokens", "thoughtsTokenCount") ?? (o ? v(o, "reasoning_tokens") : void 0);
|
|
440
|
-
if (!(n === void 0 && r === void 0 && i === void 0 && s === void 0 && c === void 0)) return {
|
|
441
|
-
inputTokens: n,
|
|
442
|
-
outputTokens: r,
|
|
443
|
-
totalTokens: i,
|
|
444
|
-
cachedInputTokens: s,
|
|
445
|
-
reasoningTokens: c
|
|
446
|
-
};
|
|
447
|
-
}
|
|
448
|
-
var ae = "https://api.anthropic.com/v1/messages", oe = "2023-06-01", se = 4096;
|
|
449
|
-
function b(e) {
|
|
450
|
-
if (e.type !== "image") return null;
|
|
451
|
-
if (e.data && e.mimeType) return {
|
|
452
|
-
type: "image",
|
|
453
|
-
source: {
|
|
454
|
-
type: "base64",
|
|
455
|
-
media_type: e.mimeType,
|
|
456
|
-
data: e.data
|
|
457
|
-
}
|
|
458
|
-
};
|
|
459
|
-
let t = h(e.url);
|
|
460
|
-
return t ? {
|
|
461
|
-
type: "image",
|
|
462
|
-
source: {
|
|
463
|
-
type: "base64",
|
|
464
|
-
media_type: t.mimeType,
|
|
465
|
-
data: t.data
|
|
466
|
-
}
|
|
467
|
-
} : {
|
|
468
|
-
type: "image",
|
|
469
|
-
source: {
|
|
470
|
-
type: "url",
|
|
471
|
-
url: e.url
|
|
472
|
-
}
|
|
473
|
-
};
|
|
474
|
-
}
|
|
475
|
-
function ce(e) {
|
|
476
|
-
if (typeof e == "string") return [{
|
|
477
|
-
type: "text",
|
|
478
|
-
text: e || "[no content]"
|
|
479
|
-
}];
|
|
480
|
-
let t = [];
|
|
481
|
-
for (let n of e) if (n.type === "text") n.text && t.push({
|
|
482
|
-
type: "text",
|
|
483
|
-
text: n.text
|
|
484
|
-
});
|
|
485
|
-
else {
|
|
486
|
-
let e = b(n);
|
|
487
|
-
e && t.push(e);
|
|
488
|
-
}
|
|
489
|
-
return t.length === 0 && t.push({
|
|
490
|
-
type: "text",
|
|
491
|
-
text: "[no content]"
|
|
492
|
-
}), t;
|
|
493
|
-
}
|
|
494
|
-
function le(e) {
|
|
495
|
-
if (typeof e == "string") return e;
|
|
496
|
-
let t = [];
|
|
497
|
-
for (let n of e) if (n.type === "text") n.text && t.push({
|
|
498
|
-
type: "text",
|
|
499
|
-
text: n.text
|
|
500
|
-
});
|
|
501
|
-
else if (n.type === "image") {
|
|
502
|
-
let e = b(n);
|
|
503
|
-
e && t.push(e);
|
|
504
|
-
}
|
|
505
|
-
return t.length === 0 ? "[no content]" : t;
|
|
506
|
-
}
|
|
507
|
-
function ue(e) {
|
|
508
|
-
let t = [];
|
|
509
|
-
for (let n of e) {
|
|
510
|
-
if (n.role === "tool") {
|
|
511
|
-
let e = t[t.length - 1], r = {
|
|
512
|
-
type: "tool_result",
|
|
513
|
-
tool_use_id: n.toolCallId,
|
|
514
|
-
content: le(n.content),
|
|
515
|
-
...n.toolIsError ? { is_error: !0 } : {}
|
|
516
|
-
};
|
|
517
|
-
e && e.role === "user" && Array.isArray(e.content) ? e.content.push(r) : t.push({
|
|
518
|
-
role: "user",
|
|
519
|
-
content: [r]
|
|
520
|
-
});
|
|
521
|
-
continue;
|
|
522
|
-
}
|
|
523
|
-
if (n.role === "assistant") {
|
|
524
|
-
let e = [], r = typeof n.content == "string" ? n.content : Array.isArray(n.content) ? n.content.map((e) => e.type === "text" ? e.text : "").join("") : "";
|
|
525
|
-
if (r && e.push({
|
|
526
|
-
type: "text",
|
|
527
|
-
text: r
|
|
528
|
-
}), n.toolCalls?.length) for (let t of n.toolCalls) e.push({
|
|
529
|
-
type: "tool_use",
|
|
530
|
-
id: t.id,
|
|
531
|
-
name: t.name,
|
|
532
|
-
input: t.args ?? {}
|
|
533
|
-
});
|
|
534
|
-
e.length === 0 && e.push({
|
|
535
|
-
type: "text",
|
|
536
|
-
text: "[no content]"
|
|
537
|
-
}), t.push({
|
|
538
|
-
role: "assistant",
|
|
539
|
-
content: e
|
|
540
|
-
});
|
|
541
|
-
continue;
|
|
542
|
-
}
|
|
543
|
-
t.push({
|
|
544
|
-
role: "user",
|
|
545
|
-
content: ce(n.content)
|
|
546
|
-
});
|
|
547
|
-
}
|
|
548
|
-
return t;
|
|
549
|
-
}
|
|
550
|
-
function x(e, t) {
|
|
551
|
-
let { config: n, messages: r, tools: i } = e, { system: a, rest: o } = re(r), s = {
|
|
552
|
-
model: n.model,
|
|
553
|
-
max_tokens: n.maxTokens ?? se,
|
|
554
|
-
messages: ue(o),
|
|
555
|
-
...t ? { stream: !0 } : {}
|
|
556
|
-
};
|
|
557
|
-
return n.temperature !== void 0 && (s.temperature = n.temperature), a && (s.system = a), i && i.length > 0 && (s.tools = i.map((e) => ({
|
|
558
|
-
name: e.name,
|
|
559
|
-
description: e.description,
|
|
560
|
-
input_schema: e.inputSchema
|
|
561
|
-
}))), s;
|
|
562
|
-
}
|
|
563
|
-
async function* de(e) {
|
|
564
|
-
let { config: t, signal: n } = e, r = await fetch(ae, {
|
|
565
|
-
method: "POST",
|
|
566
|
-
headers: {
|
|
567
|
-
"Content-Type": "application/json",
|
|
568
|
-
"x-api-key": t.apiKey,
|
|
569
|
-
"anthropic-version": oe,
|
|
570
|
-
"anthropic-dangerous-direct-browser-access": "true"
|
|
571
|
-
},
|
|
572
|
-
body: JSON.stringify(x(e, !0)),
|
|
573
|
-
signal: n
|
|
574
|
-
});
|
|
575
|
-
if (!r.ok || !r.body) {
|
|
576
|
-
let e = await r.text().catch(() => "");
|
|
577
|
-
throw Error(`Anthropic request failed (${r.status} ${r.statusText}): ${e}`);
|
|
578
|
-
}
|
|
579
|
-
let i = /* @__PURE__ */ new Map(), a;
|
|
580
|
-
for await (let e of g(r.body, n)) {
|
|
581
|
-
let t;
|
|
582
|
-
try {
|
|
583
|
-
t = JSON.parse(e.data);
|
|
584
|
-
} catch {
|
|
585
|
-
continue;
|
|
586
|
-
}
|
|
587
|
-
let n = t?.type;
|
|
588
|
-
if (n === "message_start") a = y(t?.message?.usage);
|
|
589
|
-
else if (n === "message_delta") {
|
|
590
|
-
let e = y(t?.usage);
|
|
591
|
-
e && (a = {
|
|
592
|
-
...a,
|
|
593
|
-
...e
|
|
594
|
-
});
|
|
595
|
-
} else if (n === "content_block_start") {
|
|
596
|
-
let e = t.index, n = t.content_block ?? {};
|
|
597
|
-
if (n.type === "tool_use") {
|
|
598
|
-
i.set(e, {
|
|
599
|
-
kind: "tool_use",
|
|
600
|
-
id: n.id,
|
|
601
|
-
name: n.name,
|
|
602
|
-
argsJson: "",
|
|
603
|
-
emittedStart: !1
|
|
604
|
-
}), yield {
|
|
605
|
-
type: "tool-call-start",
|
|
606
|
-
index: e,
|
|
607
|
-
toolCallId: n.id,
|
|
608
|
-
toolName: n.name
|
|
609
|
-
};
|
|
610
|
-
let t = i.get(e);
|
|
611
|
-
t && (t.emittedStart = !0);
|
|
612
|
-
} else i.set(e, {
|
|
613
|
-
kind: "text",
|
|
614
|
-
argsJson: "",
|
|
615
|
-
emittedStart: !1
|
|
616
|
-
});
|
|
617
|
-
} else if (n === "content_block_delta") {
|
|
618
|
-
let e = t.index, n = t.delta ?? {}, r = i.get(e);
|
|
619
|
-
if (!r) continue;
|
|
620
|
-
n.type === "text_delta" && typeof n.text == "string" ? yield {
|
|
621
|
-
type: "text-delta",
|
|
622
|
-
delta: n.text
|
|
623
|
-
} : n.type === "input_json_delta" && typeof n.partial_json == "string" && r.kind === "tool_use" && (r.argsJson += n.partial_json, yield {
|
|
624
|
-
type: "tool-call-args-delta",
|
|
625
|
-
index: e,
|
|
626
|
-
toolCallId: r.id,
|
|
627
|
-
toolName: r.name,
|
|
628
|
-
argsDelta: n.partial_json
|
|
629
|
-
});
|
|
630
|
-
} else if (n === "content_block_stop") {
|
|
631
|
-
let e = t.index, n = i.get(e);
|
|
632
|
-
if (n && n.kind === "tool_use" && n.id && n.name) {
|
|
633
|
-
let t = {};
|
|
634
|
-
if (n.argsJson) try {
|
|
635
|
-
t = JSON.parse(n.argsJson);
|
|
636
|
-
} catch {
|
|
637
|
-
t = {};
|
|
638
|
-
}
|
|
639
|
-
yield {
|
|
640
|
-
type: "tool-call-ready",
|
|
641
|
-
index: e,
|
|
642
|
-
toolCallId: n.id,
|
|
643
|
-
toolName: n.name,
|
|
644
|
-
args: t
|
|
645
|
-
};
|
|
646
|
-
}
|
|
647
|
-
} else if (n === "message_stop") {
|
|
648
|
-
if (a) {
|
|
649
|
-
let e = a.totalTokens ?? (a.inputTokens !== void 0 && a.outputTokens !== void 0 ? a.inputTokens + a.outputTokens : void 0);
|
|
650
|
-
yield {
|
|
651
|
-
type: "usage",
|
|
652
|
-
usage: {
|
|
653
|
-
...a,
|
|
654
|
-
totalTokens: e
|
|
655
|
-
}
|
|
656
|
-
};
|
|
657
|
-
}
|
|
658
|
-
} else n === "error" && (yield {
|
|
659
|
-
type: "error",
|
|
660
|
-
message: t?.error?.message ?? "Anthropic stream error"
|
|
661
|
-
});
|
|
662
|
-
}
|
|
663
|
-
yield { type: "done" };
|
|
664
|
-
}
|
|
665
|
-
async function fe(e) {
|
|
666
|
-
let { config: t, signal: n } = e, r = await fetch(ae, {
|
|
667
|
-
method: "POST",
|
|
668
|
-
headers: {
|
|
669
|
-
"Content-Type": "application/json",
|
|
670
|
-
"x-api-key": t.apiKey,
|
|
671
|
-
"anthropic-version": oe,
|
|
672
|
-
"anthropic-dangerous-direct-browser-access": "true"
|
|
673
|
-
},
|
|
674
|
-
body: JSON.stringify(x(e, !1)),
|
|
675
|
-
signal: n
|
|
676
|
-
});
|
|
677
|
-
if (!r.ok) {
|
|
678
|
-
let e = await r.text().catch(() => "");
|
|
679
|
-
throw Error(`Anthropic request failed (${r.status} ${r.statusText}): ${e}`);
|
|
680
|
-
}
|
|
681
|
-
let i = await r.json(), a = "", o = [];
|
|
682
|
-
for (let e of i?.content ?? []) e.type === "text" && typeof e.text == "string" ? a += e.text : e.type === "tool_use" && o.push({
|
|
683
|
-
id: e.id,
|
|
684
|
-
name: e.name,
|
|
685
|
-
args: e.input && typeof e.input == "object" ? e.input : {}
|
|
686
|
-
});
|
|
687
|
-
return {
|
|
688
|
-
text: a,
|
|
689
|
-
toolCalls: o
|
|
690
|
-
};
|
|
691
|
-
}
|
|
692
|
-
var pe = /* @__PURE__ */ new Set([
|
|
693
|
-
"type",
|
|
694
|
-
"description",
|
|
695
|
-
"enum",
|
|
696
|
-
"properties",
|
|
697
|
-
"required",
|
|
698
|
-
"items",
|
|
699
|
-
"format",
|
|
700
|
-
"nullable",
|
|
701
|
-
"minimum",
|
|
702
|
-
"maximum",
|
|
703
|
-
"minItems",
|
|
704
|
-
"maxItems",
|
|
705
|
-
"minLength",
|
|
706
|
-
"maxLength",
|
|
707
|
-
"pattern"
|
|
708
|
-
]);
|
|
709
|
-
function me(e) {
|
|
710
|
-
if (!e || typeof e != "object") return { type: "object" };
|
|
711
|
-
let t = S(e);
|
|
712
|
-
if (typeof t != "object" || !t) return { type: "object" };
|
|
713
|
-
let n = t;
|
|
714
|
-
return n.type ||= "object", n;
|
|
715
|
-
}
|
|
716
|
-
function S(e) {
|
|
717
|
-
if (Array.isArray(e)) return e.map(S);
|
|
718
|
-
if (!e || typeof e != "object") return e;
|
|
719
|
-
let t = e;
|
|
720
|
-
for (let e of [
|
|
721
|
-
"oneOf",
|
|
722
|
-
"anyOf",
|
|
723
|
-
"allOf"
|
|
724
|
-
]) {
|
|
725
|
-
let n = t[e];
|
|
726
|
-
if (Array.isArray(n) && n.length === 1) return S(n[0]);
|
|
727
|
-
}
|
|
728
|
-
let n = {};
|
|
729
|
-
for (let [e, r] of Object.entries(t)) if (pe.has(e)) if (e === "properties" && r && typeof r == "object") {
|
|
730
|
-
let t = {};
|
|
731
|
-
for (let [e, n] of Object.entries(r)) t[e] = S(n);
|
|
732
|
-
n[e] = t;
|
|
733
|
-
} else e === "items" ? n[e] = S(r) : n[e] = r;
|
|
734
|
-
return n;
|
|
735
|
-
}
|
|
736
|
-
function he(e) {
|
|
737
|
-
let t = e.trim();
|
|
738
|
-
return t.startsWith("models/") ? t.slice(7) : t;
|
|
739
|
-
}
|
|
740
|
-
function C(e, t) {
|
|
741
|
-
let n = t === "stream" ? "streamGenerateContent?alt=sse" : "generateContent";
|
|
742
|
-
return `https://generativelanguage.googleapis.com/v1beta/models/${encodeURIComponent(he(e))}:${n}`;
|
|
743
|
-
}
|
|
744
|
-
function w(e) {
|
|
745
|
-
if (e.type !== "image") return null;
|
|
746
|
-
if (e.data && e.mimeType) return { inlineData: {
|
|
747
|
-
mimeType: e.mimeType,
|
|
748
|
-
data: e.data
|
|
749
|
-
} };
|
|
750
|
-
let t = h(e.url);
|
|
751
|
-
return t ? { inlineData: {
|
|
752
|
-
mimeType: t.mimeType,
|
|
753
|
-
data: t.data
|
|
754
|
-
} } : null;
|
|
755
|
-
}
|
|
756
|
-
function ge(e) {
|
|
757
|
-
if (typeof e == "string") return [{ text: e || "[no content]" }];
|
|
758
|
-
let t = [];
|
|
759
|
-
for (let n of e) if (n.type === "text") n.text && t.push({ text: n.text });
|
|
760
|
-
else {
|
|
761
|
-
let e = w(n);
|
|
762
|
-
e && t.push(e);
|
|
763
|
-
}
|
|
764
|
-
return t.length === 0 && t.push({ text: "[no content]" }), t;
|
|
765
|
-
}
|
|
766
|
-
function _e(e) {
|
|
767
|
-
if (typeof e == "string") {
|
|
768
|
-
let t;
|
|
769
|
-
try {
|
|
770
|
-
t = JSON.parse(e);
|
|
771
|
-
} catch {
|
|
772
|
-
t = { result: e };
|
|
773
|
-
}
|
|
774
|
-
return (!t || typeof t != "object") && (t = { result: t }), {
|
|
775
|
-
response: t,
|
|
776
|
-
imageParts: []
|
|
777
|
-
};
|
|
778
|
-
}
|
|
779
|
-
let { text: t, imageParts: n } = f(e), r = {};
|
|
780
|
-
return t && (r.text = t), n.length > 0 && (r.images = n.map((e) => ({
|
|
781
|
-
mimeType: e.mimeType ?? "image/*",
|
|
782
|
-
omitted: !0
|
|
783
|
-
})), r.note = "Image bytes were sent in the next user turn as inlineData."), Object.keys(r).length === 0 && (r.result = null), {
|
|
784
|
-
response: r,
|
|
785
|
-
imageParts: n
|
|
786
|
-
};
|
|
787
|
-
}
|
|
788
|
-
function ve(e) {
|
|
789
|
-
let t = [];
|
|
790
|
-
for (let n of e) {
|
|
791
|
-
if (n.role === "tool") {
|
|
792
|
-
let { response: e, imageParts: r } = _e(n.content), i = t[t.length - 1], a = { functionResponse: {
|
|
793
|
-
name: n.toolName,
|
|
794
|
-
response: e
|
|
795
|
-
} };
|
|
796
|
-
if (i && i.role === "function" ? i.parts.push(a) : t.push({
|
|
797
|
-
role: "function",
|
|
798
|
-
parts: [a]
|
|
799
|
-
}), r.length > 0) {
|
|
800
|
-
let e = [{ text: p(n.toolName, r.length) }];
|
|
801
|
-
for (let t of r) {
|
|
802
|
-
let n = w(t);
|
|
803
|
-
n && e.push(n);
|
|
804
|
-
}
|
|
805
|
-
t.push({
|
|
806
|
-
role: "user",
|
|
807
|
-
parts: e
|
|
808
|
-
});
|
|
809
|
-
}
|
|
810
|
-
continue;
|
|
811
|
-
}
|
|
812
|
-
if (n.role === "assistant") {
|
|
813
|
-
let e = [], r = typeof n.content == "string" ? n.content : Array.isArray(n.content) ? n.content.map((e) => e.type === "text" ? e.text : "").join("") : "";
|
|
814
|
-
if (r && e.push({ text: r }), n.toolCalls?.length) for (let t of n.toolCalls) e.push({ functionCall: {
|
|
815
|
-
name: t.name,
|
|
816
|
-
args: t.args ?? {}
|
|
817
|
-
} });
|
|
818
|
-
e.length === 0 && e.push({ text: "[no content]" }), t.push({
|
|
819
|
-
role: "model",
|
|
820
|
-
parts: e
|
|
821
|
-
});
|
|
822
|
-
continue;
|
|
823
|
-
}
|
|
824
|
-
t.push({
|
|
825
|
-
role: "user",
|
|
826
|
-
parts: ge(n.content)
|
|
827
|
-
});
|
|
828
|
-
}
|
|
829
|
-
return t;
|
|
830
|
-
}
|
|
831
|
-
function T(e) {
|
|
832
|
-
let { config: t, messages: n, tools: r } = e, { system: i, rest: a } = re(n), o = { contents: ve(a) };
|
|
833
|
-
i && (o.systemInstruction = { parts: [{ text: i }] });
|
|
834
|
-
let s = {};
|
|
835
|
-
return t.temperature !== void 0 && (s.temperature = t.temperature), t.maxTokens !== void 0 && (s.maxOutputTokens = t.maxTokens), Object.keys(s).length > 0 && (o.generationConfig = s), r && r.length > 0 && (o.tools = [{ functionDeclarations: r.map((e) => ({
|
|
836
|
-
name: e.name,
|
|
837
|
-
description: e.description,
|
|
838
|
-
parameters: me(e.inputSchema)
|
|
839
|
-
})) }]), o;
|
|
840
|
-
}
|
|
841
|
-
async function* ye(e) {
|
|
842
|
-
let { config: t, signal: n } = e, r = `${C(t.model, "stream")}&key=${encodeURIComponent(t.apiKey)}`, i = await fetch(r, {
|
|
843
|
-
method: "POST",
|
|
844
|
-
headers: { "Content-Type": "application/json" },
|
|
845
|
-
body: JSON.stringify(T(e)),
|
|
846
|
-
signal: n
|
|
847
|
-
});
|
|
848
|
-
if (!i.ok || !i.body) {
|
|
849
|
-
let e = await i.text().catch(() => "");
|
|
850
|
-
throw Error(`Google request failed (${i.status} ${i.statusText}): ${e}`);
|
|
851
|
-
}
|
|
852
|
-
let a = 0, o;
|
|
853
|
-
for await (let e of g(i.body, n)) {
|
|
854
|
-
let t;
|
|
855
|
-
try {
|
|
856
|
-
t = JSON.parse(e.data);
|
|
857
|
-
} catch {
|
|
858
|
-
continue;
|
|
859
|
-
}
|
|
860
|
-
o = y(t?.usageMetadata) ?? o;
|
|
861
|
-
let n = t?.candidates?.[0]?.content?.parts ?? [];
|
|
862
|
-
for (let e of n) if (typeof e.text == "string" && e.text.length > 0) yield {
|
|
863
|
-
type: "text-delta",
|
|
864
|
-
delta: e.text
|
|
865
|
-
};
|
|
866
|
-
else if (e.functionCall && typeof e.functionCall == "object") {
|
|
867
|
-
let t = a++, n = `call_${t}_${e.functionCall.name ?? "tool"}`, r = e.functionCall.name ?? "", i = e.functionCall.args && typeof e.functionCall.args == "object" ? e.functionCall.args : {};
|
|
868
|
-
yield {
|
|
869
|
-
type: "tool-call-start",
|
|
870
|
-
index: t,
|
|
871
|
-
toolCallId: n,
|
|
872
|
-
toolName: r
|
|
873
|
-
};
|
|
874
|
-
let o = JSON.stringify(i);
|
|
875
|
-
o && o !== "{}" && (yield {
|
|
876
|
-
type: "tool-call-args-delta",
|
|
877
|
-
index: t,
|
|
878
|
-
toolCallId: n,
|
|
879
|
-
toolName: r,
|
|
880
|
-
argsDelta: o
|
|
881
|
-
}), yield {
|
|
882
|
-
type: "tool-call-ready",
|
|
883
|
-
index: t,
|
|
884
|
-
toolCallId: n,
|
|
885
|
-
toolName: r,
|
|
886
|
-
args: i
|
|
887
|
-
};
|
|
888
|
-
}
|
|
889
|
-
}
|
|
890
|
-
o && (yield {
|
|
891
|
-
type: "usage",
|
|
892
|
-
usage: o
|
|
893
|
-
}), yield { type: "done" };
|
|
894
|
-
}
|
|
895
|
-
async function be(e) {
|
|
896
|
-
let { config: t, signal: n } = e, r = `${C(t.model, "single")}?key=${encodeURIComponent(t.apiKey)}`, i = await fetch(r, {
|
|
897
|
-
method: "POST",
|
|
898
|
-
headers: { "Content-Type": "application/json" },
|
|
899
|
-
body: JSON.stringify(T(e)),
|
|
900
|
-
signal: n
|
|
901
|
-
});
|
|
902
|
-
if (!i.ok) {
|
|
903
|
-
let e = await i.text().catch(() => "");
|
|
904
|
-
throw Error(`Google request failed (${i.status} ${i.statusText}): ${e}`);
|
|
905
|
-
}
|
|
906
|
-
let a = await i.json(), o = "", s = [], c = a?.candidates?.[0]?.content?.parts ?? [];
|
|
907
|
-
for (let e of c) typeof e.text == "string" ? o += e.text : e.functionCall && s.push({
|
|
908
|
-
id: `call_${s.length}_${e.functionCall.name ?? "tool"}`,
|
|
909
|
-
name: e.functionCall.name ?? "",
|
|
910
|
-
args: e.functionCall.args && typeof e.functionCall.args == "object" ? e.functionCall.args : {}
|
|
911
|
-
});
|
|
912
|
-
return {
|
|
913
|
-
text: o,
|
|
914
|
-
toolCalls: s
|
|
915
|
-
};
|
|
916
|
-
}
|
|
917
|
-
async function* xe(e, t) {
|
|
918
|
-
let n = e.getReader(), r = new TextDecoder(), i = "";
|
|
919
|
-
try {
|
|
920
|
-
for (;;) {
|
|
921
|
-
if (t?.aborted) return;
|
|
922
|
-
let { done: e, value: a } = await n.read();
|
|
923
|
-
if (e) break;
|
|
924
|
-
i += r.decode(a, { stream: !0 });
|
|
925
|
-
let o = i.split("\n");
|
|
926
|
-
i = o.pop() ?? "";
|
|
927
|
-
for (let e of o) {
|
|
928
|
-
let t = e.trim();
|
|
929
|
-
if (t) try {
|
|
930
|
-
yield JSON.parse(t);
|
|
931
|
-
} catch {}
|
|
932
|
-
}
|
|
933
|
-
}
|
|
934
|
-
let e = i.trim();
|
|
935
|
-
if (e) try {
|
|
936
|
-
yield JSON.parse(e);
|
|
937
|
-
} catch {}
|
|
938
|
-
} finally {
|
|
939
|
-
n.releaseLock();
|
|
940
|
-
}
|
|
941
|
-
}
|
|
942
|
-
var Se = "http://localhost:11434";
|
|
943
|
-
function E(e) {
|
|
944
|
-
let t = (e || "http://localhost:11434").trim(), n = t.length;
|
|
945
|
-
for (; n > 0 && t.charCodeAt(n - 1) === 47;) n--;
|
|
946
|
-
let r = t.slice(0, n);
|
|
947
|
-
return r.endsWith("/api") ? r.slice(0, -4) : r;
|
|
948
|
-
}
|
|
949
|
-
function D(e, t) {
|
|
950
|
-
return `${E(e)}${t}`;
|
|
951
|
-
}
|
|
952
|
-
var Ce = class extends Error {
|
|
953
|
-
constructor(e) {
|
|
954
|
-
super("Could not reach Ollama. If it's running, allow this origin by starting Ollama with `OLLAMA_ORIGINS=*` (or your inspector origin) and try again."), this.name = "OllamaCorsError", this.cause = e;
|
|
955
|
-
}
|
|
956
|
-
};
|
|
957
|
-
function we(e) {
|
|
958
|
-
let t = [];
|
|
959
|
-
for (let n of e) {
|
|
960
|
-
if (n.type !== "image") continue;
|
|
961
|
-
if (n.data) {
|
|
962
|
-
t.push(n.data);
|
|
963
|
-
continue;
|
|
964
|
-
}
|
|
965
|
-
let e = h(n.url);
|
|
966
|
-
e?.data && t.push(e.data);
|
|
967
|
-
}
|
|
968
|
-
return t;
|
|
969
|
-
}
|
|
970
|
-
function O(e) {
|
|
971
|
-
if (typeof e == "string") return { content: e };
|
|
972
|
-
let t = e.filter((e) => e.type === "text").map((e) => e.text).join(""), n = we(e);
|
|
973
|
-
return {
|
|
974
|
-
content: t,
|
|
975
|
-
...n.length > 0 ? { images: n } : {}
|
|
976
|
-
};
|
|
977
|
-
}
|
|
978
|
-
function Te(e) {
|
|
979
|
-
return e.map((e) => e.role === "tool" ? {
|
|
980
|
-
role: "tool",
|
|
981
|
-
tool_name: e.toolName,
|
|
982
|
-
content: typeof e.content == "string" ? e.content : JSON.stringify(e.toolResult ?? e.content)
|
|
983
|
-
} : e.role === "assistant" ? {
|
|
984
|
-
role: "assistant",
|
|
985
|
-
...typeof e.content == "string" ? { content: e.content } : O(e.content),
|
|
986
|
-
...e.toolCalls?.length ? { tool_calls: e.toolCalls.map((e, t) => ({
|
|
987
|
-
type: "function",
|
|
988
|
-
function: {
|
|
989
|
-
index: t,
|
|
990
|
-
name: e.name,
|
|
991
|
-
arguments: e.args
|
|
992
|
-
}
|
|
993
|
-
})) } : {}
|
|
994
|
-
} : {
|
|
995
|
-
role: e.role,
|
|
996
|
-
...O(e.content)
|
|
997
|
-
});
|
|
998
|
-
}
|
|
999
|
-
function k(e, t) {
|
|
1000
|
-
let { config: n, messages: r, tools: i } = e, a = {
|
|
1001
|
-
model: n.model,
|
|
1002
|
-
messages: Te(r),
|
|
1003
|
-
stream: t
|
|
1004
|
-
}, o = {};
|
|
1005
|
-
return n.temperature !== void 0 && (o.temperature = n.temperature), n.maxTokens !== void 0 && (o.num_predict = n.maxTokens), Object.keys(o).length > 0 && (a.options = o), i && i.length > 0 && (a.tools = i.map((e) => ({
|
|
1006
|
-
type: "function",
|
|
1007
|
-
function: {
|
|
1008
|
-
name: e.name,
|
|
1009
|
-
description: e.description,
|
|
1010
|
-
parameters: e.inputSchema
|
|
1011
|
-
}
|
|
1012
|
-
}))), a;
|
|
1013
|
-
}
|
|
1014
|
-
function A(e) {
|
|
1015
|
-
return {
|
|
1016
|
-
"Content-Type": "application/json",
|
|
1017
|
-
...e.apiKey.trim() ? { Authorization: `Bearer ${e.apiKey.trim()}` } : {}
|
|
1018
|
-
};
|
|
1019
|
-
}
|
|
1020
|
-
function j(e) {
|
|
1021
|
-
return Array.isArray(e) ? e.map((e) => {
|
|
1022
|
-
let t = e && typeof e == "object" ? e.function : void 0, n = typeof t?.name == "string" ? t.name : "", r = t?.arguments;
|
|
1023
|
-
return {
|
|
1024
|
-
name: n,
|
|
1025
|
-
args: r && typeof r == "object" ? r : {}
|
|
1026
|
-
};
|
|
1027
|
-
}).filter((e) => e.name) : [];
|
|
1028
|
-
}
|
|
1029
|
-
async function* Ee(e) {
|
|
1030
|
-
let { config: t, signal: n } = e, r = await fetch(D(t.baseUrl, "/api/chat"), {
|
|
1031
|
-
method: "POST",
|
|
1032
|
-
headers: A(t),
|
|
1033
|
-
body: JSON.stringify(k(e, !0)),
|
|
1034
|
-
signal: n
|
|
1035
|
-
});
|
|
1036
|
-
if (!r.ok || !r.body) {
|
|
1037
|
-
let e = await r.text().catch(() => "");
|
|
1038
|
-
throw Error(`Ollama request failed (${r.status} ${r.statusText}): ${e}`);
|
|
1039
|
-
}
|
|
1040
|
-
let i = !1, a;
|
|
1041
|
-
for await (let e of xe(r.body, n)) {
|
|
1042
|
-
let t = e && typeof e == "object" ? e.message : void 0;
|
|
1043
|
-
if (typeof t?.content == "string" && t.content.length > 0 && (yield {
|
|
1044
|
-
type: "text-delta",
|
|
1045
|
-
delta: t.content
|
|
1046
|
-
}), !i) {
|
|
1047
|
-
let e = j(t?.tool_calls);
|
|
1048
|
-
if (e.length > 0) {
|
|
1049
|
-
for (let [t, n] of e.entries()) {
|
|
1050
|
-
let e = `call_${t}_${n.name || "tool"}`;
|
|
1051
|
-
yield {
|
|
1052
|
-
type: "tool-call-start",
|
|
1053
|
-
index: t,
|
|
1054
|
-
toolCallId: e,
|
|
1055
|
-
toolName: n.name
|
|
1056
|
-
};
|
|
1057
|
-
let r = JSON.stringify(n.args);
|
|
1058
|
-
r && r !== "{}" && (yield {
|
|
1059
|
-
type: "tool-call-args-delta",
|
|
1060
|
-
index: t,
|
|
1061
|
-
toolCallId: e,
|
|
1062
|
-
toolName: n.name,
|
|
1063
|
-
argsDelta: r
|
|
1064
|
-
}), yield {
|
|
1065
|
-
type: "tool-call-ready",
|
|
1066
|
-
index: t,
|
|
1067
|
-
toolCallId: e,
|
|
1068
|
-
toolName: n.name,
|
|
1069
|
-
args: n.args
|
|
1070
|
-
};
|
|
1071
|
-
}
|
|
1072
|
-
i = !0;
|
|
1073
|
-
}
|
|
1074
|
-
}
|
|
1075
|
-
e && typeof e == "object" && e.error && (yield {
|
|
1076
|
-
type: "error",
|
|
1077
|
-
message: String(e.error)
|
|
1078
|
-
}), a = y(e) ?? a;
|
|
1079
|
-
}
|
|
1080
|
-
a && (yield {
|
|
1081
|
-
type: "usage",
|
|
1082
|
-
usage: a
|
|
1083
|
-
}), yield { type: "done" };
|
|
1084
|
-
}
|
|
1085
|
-
async function De(e) {
|
|
1086
|
-
let { config: t, signal: n } = e, r = await fetch(D(t.baseUrl, "/api/chat"), {
|
|
1087
|
-
method: "POST",
|
|
1088
|
-
headers: A(t),
|
|
1089
|
-
body: JSON.stringify(k(e, !1)),
|
|
1090
|
-
signal: n
|
|
1091
|
-
});
|
|
1092
|
-
if (!r.ok) {
|
|
1093
|
-
let e = await r.text().catch(() => "");
|
|
1094
|
-
throw Error(`Ollama request failed (${r.status} ${r.statusText}): ${e}`);
|
|
1095
|
-
}
|
|
1096
|
-
let i = (await r.json())?.message ?? {};
|
|
1097
|
-
return {
|
|
1098
|
-
text: typeof i.content == "string" ? i.content : "",
|
|
1099
|
-
toolCalls: j(i.tool_calls).map((e, t) => ({
|
|
1100
|
-
id: `call_${t}_${e.name || "tool"}`,
|
|
1101
|
-
name: e.name,
|
|
1102
|
-
args: e.args
|
|
1103
|
-
}))
|
|
1104
|
-
};
|
|
1105
|
-
}
|
|
1106
|
-
var M = class extends Error {
|
|
1107
|
-
status;
|
|
1108
|
-
body;
|
|
1109
|
-
constructor(e, t, n) {
|
|
1110
|
-
super(t), this.name = "LlmRequestError", this.status = e, this.body = n;
|
|
1111
|
-
}
|
|
1112
|
-
};
|
|
1113
|
-
async function N(e) {
|
|
1114
|
-
let t = await e.text().catch(() => ""), n = t;
|
|
1115
|
-
if (t) try {
|
|
1116
|
-
n = JSON.parse(t);
|
|
1117
|
-
} catch {}
|
|
1118
|
-
throw new M(e.status, `OpenAI request failed (${e.status} ${e.statusText}): ${t}`, n);
|
|
1119
|
-
}
|
|
1120
|
-
var Oe = "https://api.openai.com/v1";
|
|
1121
|
-
function P(e, t) {
|
|
1122
|
-
return `${e.baseUrl ?? Oe}${t}`;
|
|
1123
|
-
}
|
|
1124
|
-
function F(e) {
|
|
1125
|
-
let t = {
|
|
1126
|
-
"Content-Type": "application/json",
|
|
1127
|
-
...e.extraHeaders
|
|
1128
|
-
};
|
|
1129
|
-
return e.apiKey && (t.Authorization = `Bearer ${e.apiKey}`), t;
|
|
1130
|
-
}
|
|
1131
|
-
function ke(e) {
|
|
1132
|
-
return typeof e == "string" ? e : e.map((e) => e.type === "text" ? {
|
|
1133
|
-
type: "text",
|
|
1134
|
-
text: e.text
|
|
1135
|
-
} : {
|
|
1136
|
-
type: "image_url",
|
|
1137
|
-
image_url: { url: e.url }
|
|
1138
|
-
});
|
|
1139
|
-
}
|
|
1140
|
-
function I(e) {
|
|
1141
|
-
let t = [];
|
|
1142
|
-
for (let n of e) {
|
|
1143
|
-
if (n.role === "tool") {
|
|
1144
|
-
let { text: e, imageParts: r } = f(n.content), i = r.length > 0 ? "[image content; see next message]" : "[no content]";
|
|
1145
|
-
if (t.push({
|
|
1146
|
-
role: "tool",
|
|
1147
|
-
tool_call_id: n.toolCallId,
|
|
1148
|
-
content: e || i
|
|
1149
|
-
}), r.length > 0) {
|
|
1150
|
-
let e = [{
|
|
1151
|
-
type: "text",
|
|
1152
|
-
text: p(n.toolName, r.length)
|
|
1153
|
-
}, ...r.map((e) => ({
|
|
1154
|
-
type: "image_url",
|
|
1155
|
-
image_url: { url: e.url }
|
|
1156
|
-
}))];
|
|
1157
|
-
t.push({
|
|
1158
|
-
role: "user",
|
|
1159
|
-
content: e
|
|
1160
|
-
});
|
|
1161
|
-
}
|
|
1162
|
-
continue;
|
|
1163
|
-
}
|
|
1164
|
-
if (n.role === "assistant") {
|
|
1165
|
-
let e = {
|
|
1166
|
-
role: "assistant",
|
|
1167
|
-
content: typeof n.content == "string" && n.content.length > 0 ? n.content : null
|
|
1168
|
-
};
|
|
1169
|
-
n.toolCalls?.length && (e.tool_calls = n.toolCalls.map((e) => ({
|
|
1170
|
-
id: e.id,
|
|
1171
|
-
type: "function",
|
|
1172
|
-
function: {
|
|
1173
|
-
name: e.name,
|
|
1174
|
-
arguments: JSON.stringify(e.args)
|
|
1175
|
-
}
|
|
1176
|
-
}))), t.push(e);
|
|
1177
|
-
continue;
|
|
1178
|
-
}
|
|
1179
|
-
t.push({
|
|
1180
|
-
role: n.role,
|
|
1181
|
-
content: ke(n.content)
|
|
1182
|
-
});
|
|
1183
|
-
}
|
|
1184
|
-
return t;
|
|
1185
|
-
}
|
|
1186
|
-
async function* L(e) {
|
|
1187
|
-
let { config: t, messages: n, tools: r, signal: i } = e, a = {
|
|
1188
|
-
model: t.model,
|
|
1189
|
-
messages: I(n),
|
|
1190
|
-
stream: !0
|
|
1191
|
-
};
|
|
1192
|
-
t.provider === "openrouter" && (a.stream_options = { include_usage: !0 }), t.temperature !== void 0 && (a.temperature = t.temperature), t.maxTokens !== void 0 && (a.max_tokens = t.maxTokens), r && r.length > 0 && (a.tools = r.map((e) => ({
|
|
1193
|
-
type: "function",
|
|
1194
|
-
function: {
|
|
1195
|
-
name: e.name,
|
|
1196
|
-
description: e.description,
|
|
1197
|
-
parameters: e.inputSchema
|
|
1198
|
-
}
|
|
1199
|
-
})));
|
|
1200
|
-
let o = P(t, "/chat/completions"), s = await fetch(o, {
|
|
1201
|
-
method: "POST",
|
|
1202
|
-
headers: F(t),
|
|
1203
|
-
body: JSON.stringify(a),
|
|
1204
|
-
signal: i,
|
|
1205
|
-
...t.credentials ? { credentials: t.credentials } : {}
|
|
1206
|
-
}), c = s.body;
|
|
1207
|
-
s.ok || await N(s), c || await N(s);
|
|
1208
|
-
let l = c, u = /* @__PURE__ */ new Map();
|
|
1209
|
-
for await (let e of g(l, i)) {
|
|
1210
|
-
if (!e.data || e.data === "[DONE]") continue;
|
|
1211
|
-
let t;
|
|
1212
|
-
try {
|
|
1213
|
-
t = JSON.parse(e.data);
|
|
1214
|
-
} catch {
|
|
1215
|
-
continue;
|
|
1216
|
-
}
|
|
1217
|
-
let n = y(t?.usage);
|
|
1218
|
-
n && (yield {
|
|
1219
|
-
type: "usage",
|
|
1220
|
-
usage: n
|
|
1221
|
-
});
|
|
1222
|
-
let r = t?.choices?.[0];
|
|
1223
|
-
if (!r) continue;
|
|
1224
|
-
let i = r.delta ?? {};
|
|
1225
|
-
if (typeof i.content == "string" && i.content.length > 0 && (yield {
|
|
1226
|
-
type: "text-delta",
|
|
1227
|
-
delta: i.content
|
|
1228
|
-
}), Array.isArray(i.tool_calls)) for (let e of i.tool_calls) {
|
|
1229
|
-
let t = typeof e.index == "number" ? e.index : 0, n = u.get(t);
|
|
1230
|
-
n || (n = {
|
|
1231
|
-
id: e.id ?? `call_${t}`,
|
|
1232
|
-
name: e.function?.name ?? "",
|
|
1233
|
-
argsJson: "",
|
|
1234
|
-
started: !1
|
|
1235
|
-
}, u.set(t, n)), (e.id && !n.id.startsWith("call_") || e.id) && (n.id = e.id), e.function?.name && (n.name = e.function.name), !n.started && n.name && (n.started = !0, yield {
|
|
1236
|
-
type: "tool-call-start",
|
|
1237
|
-
index: t,
|
|
1238
|
-
toolCallId: n.id,
|
|
1239
|
-
toolName: n.name
|
|
1240
|
-
});
|
|
1241
|
-
let r = e.function?.arguments;
|
|
1242
|
-
typeof r == "string" && r.length > 0 && (n.argsJson += r, n.started && (yield {
|
|
1243
|
-
type: "tool-call-args-delta",
|
|
1244
|
-
index: t,
|
|
1245
|
-
toolCallId: n.id,
|
|
1246
|
-
toolName: n.name,
|
|
1247
|
-
argsDelta: r
|
|
1248
|
-
}));
|
|
1249
|
-
}
|
|
1250
|
-
if (r.finish_reason) {
|
|
1251
|
-
for (let [e, t] of u) {
|
|
1252
|
-
let n = {};
|
|
1253
|
-
if (t.argsJson) try {
|
|
1254
|
-
n = JSON.parse(t.argsJson);
|
|
1255
|
-
} catch {
|
|
1256
|
-
n = {};
|
|
1257
|
-
}
|
|
1258
|
-
yield {
|
|
1259
|
-
type: "tool-call-ready",
|
|
1260
|
-
index: e,
|
|
1261
|
-
toolCallId: t.id,
|
|
1262
|
-
toolName: t.name,
|
|
1263
|
-
args: n
|
|
1264
|
-
};
|
|
1265
|
-
}
|
|
1266
|
-
u.clear();
|
|
1267
|
-
}
|
|
1268
|
-
}
|
|
1269
|
-
yield { type: "done" };
|
|
1270
|
-
}
|
|
1271
|
-
async function R(e) {
|
|
1272
|
-
let { config: t, messages: n, tools: r, signal: i } = e, a = {
|
|
1273
|
-
model: t.model,
|
|
1274
|
-
messages: I(n)
|
|
1275
|
-
};
|
|
1276
|
-
t.temperature !== void 0 && (a.temperature = t.temperature), t.maxTokens !== void 0 && (a.max_tokens = t.maxTokens), r && r.length > 0 && (a.tools = r.map((e) => ({
|
|
1277
|
-
type: "function",
|
|
1278
|
-
function: {
|
|
1279
|
-
name: e.name,
|
|
1280
|
-
description: e.description,
|
|
1281
|
-
parameters: e.inputSchema
|
|
1282
|
-
}
|
|
1283
|
-
})));
|
|
1284
|
-
let o = P(t, "/chat/completions"), s = await fetch(o, {
|
|
1285
|
-
method: "POST",
|
|
1286
|
-
headers: F(t),
|
|
1287
|
-
body: JSON.stringify(a),
|
|
1288
|
-
signal: i,
|
|
1289
|
-
...t.credentials ? { credentials: t.credentials } : {}
|
|
1290
|
-
});
|
|
1291
|
-
s.ok || await N(s);
|
|
1292
|
-
let c = (await s.json())?.choices?.[0]?.message;
|
|
1293
|
-
return {
|
|
1294
|
-
text: typeof c?.content == "string" ? c.content : "",
|
|
1295
|
-
toolCalls: Array.isArray(c?.tool_calls) ? c.tool_calls.map((e) => {
|
|
1296
|
-
let t = {};
|
|
1297
|
-
try {
|
|
1298
|
-
t = JSON.parse(e?.function?.arguments ?? "{}");
|
|
1299
|
-
} catch {
|
|
1300
|
-
t = {};
|
|
1301
|
-
}
|
|
1302
|
-
return {
|
|
1303
|
-
id: e.id,
|
|
1304
|
-
name: e.function?.name ?? "",
|
|
1305
|
-
args: t
|
|
1306
|
-
};
|
|
1307
|
-
}) : []
|
|
1308
|
-
};
|
|
1309
|
-
}
|
|
1310
|
-
function z(e) {
|
|
1311
|
-
return {
|
|
1312
|
-
...e,
|
|
1313
|
-
config: {
|
|
1314
|
-
...e.config,
|
|
1315
|
-
baseUrl: "https://openrouter.ai/api/v1",
|
|
1316
|
-
extraHeaders: {
|
|
1317
|
-
"HTTP-Referer": "https://inspector.mcp-use.com",
|
|
1318
|
-
"X-Title": "mcp-use Inspector"
|
|
1319
|
-
}
|
|
1320
|
-
}
|
|
1321
|
-
};
|
|
1322
|
-
}
|
|
1323
|
-
function Ae(e) {
|
|
1324
|
-
switch (e.config.provider) {
|
|
1325
|
-
case "openai": throw Error("provider 'openai' uses the Responses API via OpenAIResponsesDriver, not streamChat");
|
|
1326
|
-
case "openai-compatible": return L(e);
|
|
1327
|
-
case "anthropic": return de(e);
|
|
1328
|
-
case "google": return ye(e);
|
|
1329
|
-
case "openrouter": return L(z(e));
|
|
1330
|
-
case "ollama": return Ee(e);
|
|
1331
|
-
default: throw Error(`Unsupported LLM provider: ${e.config.provider}`);
|
|
1332
|
-
}
|
|
1333
|
-
}
|
|
1334
|
-
function je(e) {
|
|
1335
|
-
switch (e.config.provider) {
|
|
1336
|
-
case "openai": throw Error("provider 'openai' uses the Responses API via OpenAIResponsesDriver, not chat");
|
|
1337
|
-
case "openai-compatible": return R(e);
|
|
1338
|
-
case "anthropic": return fe(e);
|
|
1339
|
-
case "google": return be(e);
|
|
1340
|
-
case "openrouter": return R(z(e));
|
|
1341
|
-
case "ollama": return De(e);
|
|
1342
|
-
default: throw Error(`Unsupported LLM provider: ${e.config.provider}`);
|
|
1343
|
-
}
|
|
1344
|
-
}
|
|
1345
|
-
var Me = "https://api.openai.com/v1";
|
|
1346
|
-
function B(e, t) {
|
|
1347
|
-
return `${(e.baseUrl ?? Me).replace(/\/$/, "")}${t}`;
|
|
1348
|
-
}
|
|
1349
|
-
function V(e) {
|
|
1350
|
-
let t = {
|
|
1351
|
-
"Content-Type": "application/json",
|
|
1352
|
-
...e.extraHeaders
|
|
1353
|
-
};
|
|
1354
|
-
return e.apiKey && (t.Authorization = `Bearer ${e.apiKey}`), t;
|
|
1355
|
-
}
|
|
1356
|
-
async function H(e) {
|
|
1357
|
-
let t = await e.text().catch(() => "");
|
|
1358
|
-
return `OpenAI request failed (${e.status} ${e.statusText}): ${t}`;
|
|
1359
|
-
}
|
|
1360
|
-
function Ne(e) {
|
|
1361
|
-
return typeof e == "string" ? e : e.map((e) => e.type === "text" ? {
|
|
1362
|
-
type: "input_text",
|
|
1363
|
-
text: e.text
|
|
1364
|
-
} : {
|
|
1365
|
-
type: "input_image",
|
|
1366
|
-
image_url: e.url
|
|
1367
|
-
});
|
|
1368
|
-
}
|
|
1369
|
-
function U(e) {
|
|
1370
|
-
let t = [], n = [];
|
|
1371
|
-
for (let r of e) {
|
|
1372
|
-
if (r.role === "system") {
|
|
1373
|
-
let e = typeof r.content == "string" ? r.content : r.content.filter((e) => e.type === "text").map((e) => e.text).join("\n");
|
|
1374
|
-
e && t.push(e);
|
|
1375
|
-
continue;
|
|
1376
|
-
}
|
|
1377
|
-
if (r.role === "user") {
|
|
1378
|
-
n.push({
|
|
1379
|
-
role: "user",
|
|
1380
|
-
content: Ne(r.content)
|
|
1381
|
-
});
|
|
1382
|
-
continue;
|
|
1383
|
-
}
|
|
1384
|
-
if (r.role === "assistant") {
|
|
1385
|
-
typeof r.content == "string" && r.content.length > 0 && n.push({
|
|
1386
|
-
type: "message",
|
|
1387
|
-
role: "assistant",
|
|
1388
|
-
content: [{
|
|
1389
|
-
type: "output_text",
|
|
1390
|
-
text: r.content
|
|
1391
|
-
}]
|
|
1392
|
-
});
|
|
1393
|
-
for (let e of r.toolCalls ?? []) n.push({
|
|
1394
|
-
type: "function_call",
|
|
1395
|
-
call_id: e.id,
|
|
1396
|
-
name: e.name,
|
|
1397
|
-
arguments: JSON.stringify(e.args)
|
|
1398
|
-
});
|
|
1399
|
-
continue;
|
|
1400
|
-
}
|
|
1401
|
-
if (r.role === "tool") {
|
|
1402
|
-
let { text: e, imageParts: t } = f(r.content), i = t.length > 0 ? "[image content; see next message]" : "[no content]";
|
|
1403
|
-
n.push({
|
|
1404
|
-
type: "function_call_output",
|
|
1405
|
-
call_id: r.toolCallId,
|
|
1406
|
-
output: e || i
|
|
1407
|
-
}), t.length > 0 && n.push({
|
|
1408
|
-
role: "user",
|
|
1409
|
-
content: [{
|
|
1410
|
-
type: "input_text",
|
|
1411
|
-
text: p(r.toolName, t.length)
|
|
1412
|
-
}, ...t.map((e) => ({
|
|
1413
|
-
type: "input_image",
|
|
1414
|
-
image_url: e.url
|
|
1415
|
-
}))]
|
|
1416
|
-
});
|
|
1417
|
-
}
|
|
1418
|
-
}
|
|
1419
|
-
return {
|
|
1420
|
-
instructions: t.length > 0 ? t.join("\n\n") : void 0,
|
|
1421
|
-
input: n
|
|
1422
|
-
};
|
|
1423
|
-
}
|
|
1424
|
-
function Pe(e) {
|
|
1425
|
-
return e.map((e) => ({
|
|
1426
|
-
type: "function",
|
|
1427
|
-
name: e.name,
|
|
1428
|
-
description: e.description,
|
|
1429
|
-
parameters: e.inputSchema,
|
|
1430
|
-
strict: !1
|
|
1431
|
-
}));
|
|
1432
|
-
}
|
|
1433
|
-
function W(e, t, n, r) {
|
|
1434
|
-
let i = d(r);
|
|
1435
|
-
if (typeof i == "string") {
|
|
1436
|
-
e.push({
|
|
1437
|
-
type: "function_call_output",
|
|
1438
|
-
call_id: t,
|
|
1439
|
-
output: i
|
|
1440
|
-
});
|
|
1441
|
-
return;
|
|
1442
|
-
}
|
|
1443
|
-
let { text: a, imageParts: o } = f(i);
|
|
1444
|
-
e.push({
|
|
1445
|
-
type: "function_call_output",
|
|
1446
|
-
call_id: t,
|
|
1447
|
-
output: a || "[image content; see next message]"
|
|
1448
|
-
}), o.length > 0 && e.push({
|
|
1449
|
-
role: "user",
|
|
1450
|
-
content: [{
|
|
1451
|
-
type: "input_text",
|
|
1452
|
-
text: p(n, o.length)
|
|
1453
|
-
}, ...o.map((e) => ({
|
|
1454
|
-
type: "input_image",
|
|
1455
|
-
image_url: e.url
|
|
1456
|
-
}))]
|
|
1457
|
-
});
|
|
1458
|
-
}
|
|
1459
|
-
function G(e, t) {
|
|
1460
|
-
let n = {
|
|
1461
|
-
model: e.config.model,
|
|
1462
|
-
input: e.input,
|
|
1463
|
-
store: !1,
|
|
1464
|
-
include: ["reasoning.encrypted_content"],
|
|
1465
|
-
reasoning: { effort: e.config.reasoningEffort ?? "low" },
|
|
1466
|
-
stream: t
|
|
1467
|
-
};
|
|
1468
|
-
return e.instructions && (n.instructions = e.instructions), e.tools && e.tools.length > 0 && (n.tools = Pe(e.tools)), e.config.maxTokens !== void 0 && (n.max_output_tokens = e.config.maxTokens), n;
|
|
1469
|
-
}
|
|
1470
|
-
function K(e) {
|
|
1471
|
-
let t = [];
|
|
1472
|
-
for (let n of e) {
|
|
1473
|
-
if (!n || typeof n != "object") continue;
|
|
1474
|
-
let e = n;
|
|
1475
|
-
e.type === "function_call" && (typeof e.call_id != "string" || typeof e.name != "string" || t.push({
|
|
1476
|
-
call_id: e.call_id,
|
|
1477
|
-
name: e.name,
|
|
1478
|
-
arguments: typeof e.arguments == "string" ? e.arguments : "{}"
|
|
1479
|
-
}));
|
|
1480
|
-
}
|
|
1481
|
-
return t;
|
|
1482
|
-
}
|
|
1483
|
-
function Fe(e) {
|
|
1484
|
-
let t = [];
|
|
1485
|
-
for (let n of e) {
|
|
1486
|
-
if (!n || typeof n != "object") continue;
|
|
1487
|
-
let e = n;
|
|
1488
|
-
if (e.type !== "message" || e.role !== "assistant") continue;
|
|
1489
|
-
let r = e.content;
|
|
1490
|
-
if (Array.isArray(r)) for (let e of r) {
|
|
1491
|
-
if (!e || typeof e != "object") continue;
|
|
1492
|
-
let n = e;
|
|
1493
|
-
n.type === "output_text" && typeof n.text == "string" && t.push(n.text);
|
|
1494
|
-
}
|
|
1495
|
-
}
|
|
1496
|
-
return t.join("");
|
|
1497
|
-
}
|
|
1498
|
-
function q(e) {
|
|
1499
|
-
if (!e) return {};
|
|
1500
|
-
try {
|
|
1501
|
-
return JSON.parse(e);
|
|
1502
|
-
} catch {
|
|
1503
|
-
return {};
|
|
1504
|
-
}
|
|
1505
|
-
}
|
|
1506
|
-
async function* J(e) {
|
|
1507
|
-
let t = await fetch(B(e.config, "/responses"), {
|
|
1508
|
-
method: "POST",
|
|
1509
|
-
headers: V(e.config),
|
|
1510
|
-
body: JSON.stringify(G(e, !0)),
|
|
1511
|
-
signal: e.signal
|
|
1512
|
-
});
|
|
1513
|
-
if (!t.ok || !t.body) throw Error(await H(t));
|
|
1514
|
-
let n = /* @__PURE__ */ new Map(), r = 0, i = [];
|
|
1515
|
-
for await (let a of g(t.body, e.signal)) {
|
|
1516
|
-
if (!a.data || a.data === "[DONE]") continue;
|
|
1517
|
-
let e;
|
|
1518
|
-
try {
|
|
1519
|
-
e = JSON.parse(a.data);
|
|
1520
|
-
} catch {
|
|
1521
|
-
continue;
|
|
1522
|
-
}
|
|
1523
|
-
let t = typeof e.type == "string" ? e.type : a.event;
|
|
1524
|
-
if (t === "response.output_text.delta") {
|
|
1525
|
-
let t = e.delta;
|
|
1526
|
-
typeof t == "string" && t.length > 0 && (yield {
|
|
1527
|
-
type: "text-delta",
|
|
1528
|
-
delta: t
|
|
1529
|
-
});
|
|
1530
|
-
continue;
|
|
1531
|
-
}
|
|
1532
|
-
if (t === "response.output_item.added") {
|
|
1533
|
-
let t = e.item;
|
|
1534
|
-
if (t?.type === "function_call") {
|
|
1535
|
-
let e = typeof t.call_id == "string" ? t.call_id : `call_${r}`, i = typeof t.name == "string" ? t.name : "", a = r++;
|
|
1536
|
-
n.set(e, {
|
|
1537
|
-
index: a,
|
|
1538
|
-
name: i,
|
|
1539
|
-
argsJson: "",
|
|
1540
|
-
started: !0
|
|
1541
|
-
}), yield {
|
|
1542
|
-
type: "tool-call-start",
|
|
1543
|
-
index: a,
|
|
1544
|
-
toolCallId: e,
|
|
1545
|
-
toolName: i
|
|
1546
|
-
};
|
|
1547
|
-
}
|
|
1548
|
-
continue;
|
|
1549
|
-
}
|
|
1550
|
-
if (t === "response.function_call_arguments.delta") {
|
|
1551
|
-
let t = typeof e.call_id == "string" ? e.call_id : "", r = typeof e.delta == "string" ? e.delta : "", i = n.get(t);
|
|
1552
|
-
i && r.length > 0 && (i.argsJson += r, yield {
|
|
1553
|
-
type: "tool-call-args-delta",
|
|
1554
|
-
index: i.index,
|
|
1555
|
-
toolCallId: t,
|
|
1556
|
-
toolName: i.name,
|
|
1557
|
-
argsDelta: r
|
|
1558
|
-
});
|
|
1559
|
-
continue;
|
|
1560
|
-
}
|
|
1561
|
-
if (t === "response.function_call_arguments.done") {
|
|
1562
|
-
let t = typeof e.call_id == "string" ? e.call_id : "", r = typeof e.arguments == "string" ? e.arguments : "", i = n.get(t);
|
|
1563
|
-
i && (r && (i.argsJson = r), yield {
|
|
1564
|
-
type: "tool-call-ready",
|
|
1565
|
-
index: i.index,
|
|
1566
|
-
toolCallId: t,
|
|
1567
|
-
toolName: i.name,
|
|
1568
|
-
args: q(i.argsJson || r)
|
|
1569
|
-
});
|
|
1570
|
-
continue;
|
|
1571
|
-
}
|
|
1572
|
-
if (t === "response.completed") {
|
|
1573
|
-
let t = e.response;
|
|
1574
|
-
t && Array.isArray(t.output) && (i = t.output);
|
|
1575
|
-
let n = y(t?.usage);
|
|
1576
|
-
n && (yield {
|
|
1577
|
-
type: "usage",
|
|
1578
|
-
usage: n
|
|
1579
|
-
});
|
|
1580
|
-
continue;
|
|
1581
|
-
}
|
|
1582
|
-
if (t === "error") return yield {
|
|
1583
|
-
type: "error",
|
|
1584
|
-
message: typeof e.message == "string" ? e.message : "OpenAI Responses stream error"
|
|
1585
|
-
}, [];
|
|
1586
|
-
}
|
|
1587
|
-
return yield { type: "done" }, i;
|
|
1588
|
-
}
|
|
1589
|
-
async function Y(e) {
|
|
1590
|
-
let t = await fetch(B(e.config, "/responses"), {
|
|
1591
|
-
method: "POST",
|
|
1592
|
-
headers: V(e.config),
|
|
1593
|
-
body: JSON.stringify(G(e, !1)),
|
|
1594
|
-
signal: e.signal
|
|
1595
|
-
});
|
|
1596
|
-
if (!t.ok) throw Error(await H(t));
|
|
1597
|
-
let n = await t.json(), r = n.status;
|
|
1598
|
-
if (r !== "completed" && r !== void 0) throw Error(`OpenAI response ended with status ${String(r)}`);
|
|
1599
|
-
let i = Array.isArray(n.output) ? n.output : [], a = K(i);
|
|
1600
|
-
return {
|
|
1601
|
-
text: typeof n.output_text == "string" ? n.output_text : Fe(i),
|
|
1602
|
-
output: i,
|
|
1603
|
-
toolCalls: a.map((e) => ({
|
|
1604
|
-
id: e.call_id,
|
|
1605
|
-
name: e.name,
|
|
1606
|
-
args: q(e.arguments)
|
|
1607
|
-
}))
|
|
1608
|
-
};
|
|
1609
|
-
}
|
|
1610
|
-
var Ie = class {
|
|
1611
|
-
constructor(e) {
|
|
1612
|
-
this.config = e;
|
|
1613
|
-
}
|
|
1614
|
-
managesToolLoop = !0;
|
|
1615
|
-
stream(e) {
|
|
1616
|
-
return this.streamSingleTurn(e);
|
|
1617
|
-
}
|
|
1618
|
-
async complete(e) {
|
|
1619
|
-
let { instructions: t, input: n } = U(e.messages), r = await Y({
|
|
1620
|
-
config: this.config,
|
|
1621
|
-
instructions: t,
|
|
1622
|
-
input: n,
|
|
1623
|
-
tools: e.tools,
|
|
1624
|
-
signal: e.signal
|
|
1625
|
-
});
|
|
1626
|
-
return {
|
|
1627
|
-
text: r.text,
|
|
1628
|
-
toolCalls: r.toolCalls
|
|
1629
|
-
};
|
|
1630
|
-
}
|
|
1631
|
-
async *streamToolLoop(e) {
|
|
1632
|
-
let { instructions: t, input: n } = U(e.messages), r = [...n], i = e.maxSteps ?? 10;
|
|
1633
|
-
for (let n = 0; n < i; n++) {
|
|
1634
|
-
if (e.signal?.aborted) return;
|
|
1635
|
-
let n = J({
|
|
1636
|
-
config: this.config,
|
|
1637
|
-
instructions: t,
|
|
1638
|
-
input: r,
|
|
1639
|
-
tools: e.tools,
|
|
1640
|
-
signal: e.signal
|
|
1641
|
-
}), i = [];
|
|
1642
|
-
for (;;) {
|
|
1643
|
-
let e = await n.next();
|
|
1644
|
-
if (e.done) {
|
|
1645
|
-
i = e.value ?? [];
|
|
1646
|
-
break;
|
|
1647
|
-
}
|
|
1648
|
-
if (yield e.value, e.value.type === "error") return;
|
|
1649
|
-
}
|
|
1650
|
-
r.push(...i);
|
|
1651
|
-
let a = K(i);
|
|
1652
|
-
if (a.length === 0) return;
|
|
1653
|
-
for (let t of a) {
|
|
1654
|
-
if (e.signal?.aborted) return;
|
|
1655
|
-
let n = {};
|
|
1656
|
-
try {
|
|
1657
|
-
n = JSON.parse(t.arguments);
|
|
1658
|
-
} catch {
|
|
1659
|
-
n = {};
|
|
1660
|
-
}
|
|
1661
|
-
let i, a = !1;
|
|
1662
|
-
try {
|
|
1663
|
-
i = await e.callTool(t.name, n), a = c(i);
|
|
1664
|
-
} catch (e) {
|
|
1665
|
-
a = !0, i = {
|
|
1666
|
-
isError: !0,
|
|
1667
|
-
error: e instanceof Error ? e.message : String(e)
|
|
1668
|
-
};
|
|
1669
|
-
}
|
|
1670
|
-
W(r, t.call_id, t.name, i), yield {
|
|
1671
|
-
type: "tool-result",
|
|
1672
|
-
toolCallId: t.call_id,
|
|
1673
|
-
toolName: t.name,
|
|
1674
|
-
result: i,
|
|
1675
|
-
isError: a
|
|
1676
|
-
};
|
|
1677
|
-
}
|
|
1678
|
-
}
|
|
1679
|
-
}
|
|
1680
|
-
async runToolLoopNonStreaming(e) {
|
|
1681
|
-
let { instructions: t, input: n } = U(e.messages), r = [...n], i = e.maxSteps ?? 10, a = [], o = "";
|
|
1682
|
-
for (let n = 0; n < i && !e.signal?.aborted; n++) {
|
|
1683
|
-
let n = await Y({
|
|
1684
|
-
config: this.config,
|
|
1685
|
-
instructions: t,
|
|
1686
|
-
input: r,
|
|
1687
|
-
tools: e.tools,
|
|
1688
|
-
signal: e.signal
|
|
1689
|
-
});
|
|
1690
|
-
if (r.push(...n.output), n.toolCalls.length === 0) {
|
|
1691
|
-
o = n.text;
|
|
1692
|
-
break;
|
|
1693
|
-
}
|
|
1694
|
-
for (let t of n.toolCalls) {
|
|
1695
|
-
let n;
|
|
1696
|
-
try {
|
|
1697
|
-
n = await e.callTool(t.name, t.args), c(n);
|
|
1698
|
-
} catch (e) {
|
|
1699
|
-
n = {
|
|
1700
|
-
isError: !0,
|
|
1701
|
-
error: e instanceof Error ? e.message : String(e)
|
|
1702
|
-
};
|
|
1703
|
-
}
|
|
1704
|
-
a.push({
|
|
1705
|
-
toolName: t.name,
|
|
1706
|
-
args: t.args,
|
|
1707
|
-
result: n
|
|
1708
|
-
}), W(r, t.id, t.name, n);
|
|
1709
|
-
}
|
|
1710
|
-
}
|
|
1711
|
-
return {
|
|
1712
|
-
content: o,
|
|
1713
|
-
toolCalls: a
|
|
1714
|
-
};
|
|
1715
|
-
}
|
|
1716
|
-
async *streamSingleTurn(e) {
|
|
1717
|
-
let { instructions: t, input: n } = U(e.messages), r = J({
|
|
1718
|
-
config: this.config,
|
|
1719
|
-
instructions: t,
|
|
1720
|
-
input: n,
|
|
1721
|
-
tools: e.tools,
|
|
1722
|
-
signal: e.signal
|
|
1723
|
-
});
|
|
1724
|
-
for (;;) {
|
|
1725
|
-
let e = await r.next();
|
|
1726
|
-
if (e.done || (yield e.value, e.value.type === "error")) return;
|
|
1727
|
-
}
|
|
1728
|
-
}
|
|
1729
|
-
};
|
|
1730
|
-
function X(e) {
|
|
1731
|
-
return e.provider === "openai" ? new Ie(e) : new Le(e);
|
|
1732
|
-
}
|
|
1733
|
-
var Le = class {
|
|
1734
|
-
constructor(e) {
|
|
1735
|
-
this.config = e;
|
|
1736
|
-
}
|
|
1737
|
-
stream(e) {
|
|
1738
|
-
return Ae({
|
|
1739
|
-
config: this.config,
|
|
1740
|
-
messages: e.messages,
|
|
1741
|
-
tools: e.tools,
|
|
1742
|
-
signal: e.signal
|
|
1743
|
-
});
|
|
1744
|
-
}
|
|
1745
|
-
async complete(e) {
|
|
1746
|
-
let t = await je({
|
|
1747
|
-
config: this.config,
|
|
1748
|
-
messages: e.messages,
|
|
1749
|
-
tools: e.tools,
|
|
1750
|
-
signal: e.signal
|
|
1751
|
-
});
|
|
1752
|
-
return {
|
|
1753
|
-
text: t.text,
|
|
1754
|
-
toolCalls: t.toolCalls
|
|
1755
|
-
};
|
|
1756
|
-
}
|
|
1757
|
-
};
|
|
1758
|
-
async function* Re(e) {
|
|
1759
|
-
if (e.driver.managesToolLoop && e.driver.streamToolLoop) {
|
|
1760
|
-
yield* e.driver.streamToolLoop(e);
|
|
1761
|
-
return;
|
|
1762
|
-
}
|
|
1763
|
-
let { driver: t, tools: n, callTool: r, signal: i } = e, a = e.maxSteps ?? 10, o = [...e.messages];
|
|
1764
|
-
for (let e = 0; e < a; e++) {
|
|
1765
|
-
if (i?.aborted) return;
|
|
1766
|
-
let e = [], a = "";
|
|
1767
|
-
try {
|
|
1768
|
-
for await (let r of t.stream({
|
|
1769
|
-
messages: o,
|
|
1770
|
-
tools: n,
|
|
1771
|
-
signal: i
|
|
1772
|
-
})) r.type === "text-delta" ? a += r.delta : r.type === "tool-call-ready" && e.push({
|
|
1773
|
-
id: r.toolCallId,
|
|
1774
|
-
name: r.toolName,
|
|
1775
|
-
args: r.args
|
|
1776
|
-
}), yield r;
|
|
1777
|
-
} catch (e) {
|
|
1778
|
-
if (e instanceof M) throw e;
|
|
1779
|
-
yield {
|
|
1780
|
-
type: "error",
|
|
1781
|
-
message: e instanceof Error ? e.message : String(e)
|
|
1782
|
-
};
|
|
1783
|
-
return;
|
|
1784
|
-
}
|
|
1785
|
-
if (e.length === 0) return;
|
|
1786
|
-
o.push({
|
|
1787
|
-
role: "assistant",
|
|
1788
|
-
content: a,
|
|
1789
|
-
toolCalls: e
|
|
1790
|
-
});
|
|
1791
|
-
for (let t of e) {
|
|
1792
|
-
if (i?.aborted) return;
|
|
1793
|
-
let e, n = !1;
|
|
1794
|
-
try {
|
|
1795
|
-
e = await r(t.name, t.args), n = c(e);
|
|
1796
|
-
} catch (t) {
|
|
1797
|
-
n = !0, e = {
|
|
1798
|
-
isError: !0,
|
|
1799
|
-
error: t instanceof Error ? t.message : String(t)
|
|
1800
|
-
};
|
|
1801
|
-
}
|
|
1802
|
-
o.push({
|
|
1803
|
-
role: "tool",
|
|
1804
|
-
content: d(e),
|
|
1805
|
-
toolCallId: t.id,
|
|
1806
|
-
toolName: t.name,
|
|
1807
|
-
toolResult: e,
|
|
1808
|
-
toolIsError: n
|
|
1809
|
-
}), yield {
|
|
1810
|
-
type: "tool-result",
|
|
1811
|
-
toolCallId: t.id,
|
|
1812
|
-
toolName: t.name,
|
|
1813
|
-
result: e,
|
|
1814
|
-
isError: n
|
|
1815
|
-
};
|
|
1816
|
-
}
|
|
1817
|
-
}
|
|
1818
|
-
}
|
|
1819
|
-
async function ze(e) {
|
|
1820
|
-
if (e.driver.managesToolLoop && e.driver.runToolLoopNonStreaming) return e.driver.runToolLoopNonStreaming(e);
|
|
1821
|
-
let { driver: t, tools: n, callTool: r, signal: i } = e, a = e.maxSteps ?? 10, o = [...e.messages], s = [], l = "";
|
|
1822
|
-
for (let e = 0; e < a && !i?.aborted; e++) {
|
|
1823
|
-
let { text: e, toolCalls: a } = await t.complete({
|
|
1824
|
-
messages: o,
|
|
1825
|
-
tools: n,
|
|
1826
|
-
signal: i
|
|
1827
|
-
});
|
|
1828
|
-
if (a.length === 0) {
|
|
1829
|
-
l = e;
|
|
1830
|
-
break;
|
|
1831
|
-
}
|
|
1832
|
-
o.push({
|
|
1833
|
-
role: "assistant",
|
|
1834
|
-
content: e,
|
|
1835
|
-
toolCalls: a
|
|
1836
|
-
});
|
|
1837
|
-
for (let e of a) {
|
|
1838
|
-
let t, n = !1;
|
|
1839
|
-
try {
|
|
1840
|
-
t = await r(e.name, e.args), n = c(t);
|
|
1841
|
-
} catch (e) {
|
|
1842
|
-
n = !0, t = {
|
|
1843
|
-
isError: !0,
|
|
1844
|
-
error: e instanceof Error ? e.message : String(e)
|
|
1845
|
-
};
|
|
1846
|
-
}
|
|
1847
|
-
s.push({
|
|
1848
|
-
toolName: e.name,
|
|
1849
|
-
args: e.args,
|
|
1850
|
-
result: t
|
|
1851
|
-
}), o.push({
|
|
1852
|
-
role: "tool",
|
|
1853
|
-
content: d(t),
|
|
1854
|
-
toolCallId: e.id,
|
|
1855
|
-
toolName: e.name,
|
|
1856
|
-
toolResult: t,
|
|
1857
|
-
toolIsError: n
|
|
1858
|
-
});
|
|
1859
|
-
}
|
|
1860
|
-
}
|
|
1861
|
-
return {
|
|
1862
|
-
content: l,
|
|
1863
|
-
toolCalls: s
|
|
1864
|
-
};
|
|
1865
|
-
}
|
|
1866
|
-
async function* Z(e, t) {
|
|
1867
|
-
yield* Re({
|
|
1868
|
-
driver: e,
|
|
1869
|
-
messages: t.messages,
|
|
1870
|
-
tools: t.tools,
|
|
1871
|
-
callTool: t.callTool,
|
|
1872
|
-
maxSteps: t.maxSteps,
|
|
1873
|
-
signal: t.signal
|
|
1874
|
-
});
|
|
1875
|
-
}
|
|
1876
|
-
async function* Be(e, t) {
|
|
1877
|
-
let n = "", r = null;
|
|
1878
|
-
for await (let i of Z(e, t)) if (i.type === "text-delta") n += i.delta;
|
|
1879
|
-
else if (i.type === "tool-call-ready") r = {
|
|
1880
|
-
action: {
|
|
1881
|
-
tool: i.toolName,
|
|
1882
|
-
toolInput: i.args,
|
|
1883
|
-
log: `Calling tool ${i.toolName}`
|
|
1884
|
-
},
|
|
1885
|
-
observation: ""
|
|
1886
|
-
}, yield r;
|
|
1887
|
-
else if (i.type === "tool-result" && r) {
|
|
1888
|
-
let e = typeof i.result == "string" ? i.result : JSON.stringify(i.result ?? "");
|
|
1889
|
-
yield {
|
|
1890
|
-
action: r.action,
|
|
1891
|
-
observation: e
|
|
1892
|
-
}, r = null;
|
|
1893
|
-
} else if (i.type === "error") throw Error(i.message);
|
|
1894
|
-
return n;
|
|
1895
|
-
}
|
|
1896
|
-
async function Ve(e, t) {
|
|
1897
|
-
return (await ze({
|
|
1898
|
-
driver: e,
|
|
1899
|
-
messages: t.messages,
|
|
1900
|
-
tools: t.tools,
|
|
1901
|
-
callTool: t.callTool,
|
|
1902
|
-
maxSteps: t.maxSteps,
|
|
1903
|
-
signal: t.signal
|
|
1904
|
-
})).content;
|
|
1905
|
-
}
|
|
1906
|
-
var He = {
|
|
1907
|
-
openai: ["OPENAI_API_KEY"],
|
|
1908
|
-
anthropic: ["ANTHROPIC_API_KEY"],
|
|
1909
|
-
google: ["GOOGLE_API_KEY", "GOOGLE_GENERATIVE_AI_API_KEY"],
|
|
1910
|
-
openrouter: ["OPENROUTER_API_KEY"],
|
|
1911
|
-
ollama: [],
|
|
1912
|
-
"openai-compatible": ["OPENAI_API_KEY"]
|
|
1913
|
-
};
|
|
1914
|
-
function Ue(e, n) {
|
|
1915
|
-
if (n?.apiKey) return n.apiKey;
|
|
1916
|
-
let r = He[e] ?? [];
|
|
1917
|
-
if (typeof process < "u") for (let n of r) {
|
|
1918
|
-
let r = {}[n];
|
|
1919
|
-
if (r) return t.debug(`Using API key from ${n} for ${e}`), r;
|
|
1920
|
-
}
|
|
1921
|
-
if (e === "ollama") return "";
|
|
1922
|
-
let i = r.length > 0 ? r.join(" or ") : "apiKey in llmConfig";
|
|
1923
|
-
throw Error(`API key not found for provider '${e}'. Set ${i}.`);
|
|
1924
|
-
}
|
|
1925
|
-
function Q(e, t) {
|
|
1926
|
-
let n = e.split("/");
|
|
1927
|
-
if (n.length < 2) throw Error(`Invalid LLM string '${e}'. Expected 'provider/model'.`);
|
|
1928
|
-
let r = n[0].toLowerCase(), i = n.slice(1).join("/"), a = [
|
|
1929
|
-
"openai",
|
|
1930
|
-
"anthropic",
|
|
1931
|
-
"google",
|
|
1932
|
-
"openrouter",
|
|
1933
|
-
"ollama",
|
|
1934
|
-
"openai-compatible"
|
|
1935
|
-
];
|
|
1936
|
-
if (!a.includes(r)) throw Error(`Unsupported provider '${r}'. Supported: ${a.join(", ")}`);
|
|
1937
|
-
return {
|
|
1938
|
-
provider: r,
|
|
1939
|
-
model: i,
|
|
1940
|
-
apiKey: Ue(r, t),
|
|
1941
|
-
temperature: t?.temperature,
|
|
1942
|
-
maxTokens: t?.maxTokens,
|
|
1943
|
-
baseUrl: t?.baseUrl,
|
|
1944
|
-
extraHeaders: t?.extraHeaders,
|
|
1945
|
-
credentials: t?.credentials
|
|
1946
|
-
};
|
|
1947
|
-
}
|
|
1948
|
-
function We(e, t, n) {
|
|
1949
|
-
return {
|
|
1950
|
-
provider: e,
|
|
1951
|
-
model: t,
|
|
1952
|
-
apiKey: Ue(e, n),
|
|
1953
|
-
temperature: n?.temperature,
|
|
1954
|
-
maxTokens: n?.maxTokens,
|
|
1955
|
-
baseUrl: n?.baseUrl,
|
|
1956
|
-
extraHeaders: n?.extraHeaders,
|
|
1957
|
-
credentials: n?.credentials
|
|
1958
|
-
};
|
|
1959
|
-
}
|
|
1960
|
-
var Ge = "2.0.0-beta.3";
|
|
1961
|
-
function Ke() {
|
|
1962
|
-
return Ge;
|
|
1963
|
-
}
|
|
1964
|
-
function $(e, t, n, r, i, a) {
|
|
1965
|
-
return typeof e == "object" && e ? {
|
|
1966
|
-
prompt: e.prompt,
|
|
1967
|
-
maxSteps: e.maxSteps,
|
|
1968
|
-
manageConnector: e.manageConnector,
|
|
1969
|
-
messages: e.messages,
|
|
1970
|
-
schema: e.schema,
|
|
1971
|
-
signal: e.signal
|
|
1972
|
-
} : {
|
|
1973
|
-
prompt: e,
|
|
1974
|
-
maxSteps: t,
|
|
1975
|
-
manageConnector: n,
|
|
1976
|
-
schema: i,
|
|
1977
|
-
signal: a
|
|
1978
|
-
};
|
|
1979
|
-
}
|
|
1980
|
-
var qe = "/api/v1/chats", Je = "/api/v1/chats/{chat_id}/execute";
|
|
1981
|
-
function Ye(e, t, n, r, i) {
|
|
1982
|
-
if (typeof e == "object" && e) {
|
|
1983
|
-
let t = e;
|
|
1984
|
-
return {
|
|
1985
|
-
query: t.prompt ?? "",
|
|
1986
|
-
maxSteps: t.maxSteps,
|
|
1987
|
-
manageConnector: t.manageConnector,
|
|
1988
|
-
externalHistory: t.externalHistory,
|
|
1989
|
-
outputSchema: t.schema
|
|
1990
|
-
};
|
|
1991
|
-
}
|
|
1992
|
-
return {
|
|
1993
|
-
query: e,
|
|
1994
|
-
maxSteps: t,
|
|
1995
|
-
manageConnector: n,
|
|
1996
|
-
externalHistory: r,
|
|
1997
|
-
outputSchema: i
|
|
1998
|
-
};
|
|
1999
|
-
}
|
|
2000
|
-
var Xe = class {
|
|
2001
|
-
agentId;
|
|
2002
|
-
apiKey;
|
|
2003
|
-
baseUrl;
|
|
2004
|
-
chatId = null;
|
|
2005
|
-
constructor(e) {
|
|
2006
|
-
this.agentId = e.agentId, this.baseUrl = e.baseUrl ?? "https://cloud.manufact.com";
|
|
2007
|
-
let t = e.apiKey ?? (typeof process < "u" && {}.MCP_USE_API_KEY);
|
|
2008
|
-
if (!t) throw Error("API key is required for remote execution. Please provide it as a parameter or set the MCP_USE_API_KEY environment variable. You can get an API key from https://cloud.manufact.com");
|
|
2009
|
-
this.apiKey = t;
|
|
2010
|
-
}
|
|
2011
|
-
pydanticToJsonSchema(t) {
|
|
2012
|
-
return e(t);
|
|
2013
|
-
}
|
|
2014
|
-
parseStructuredResponse(e, n) {
|
|
2015
|
-
let r;
|
|
2016
|
-
if (typeof e == "object" && e) if ("result" in e) {
|
|
2017
|
-
let t = e.result;
|
|
2018
|
-
r = typeof t == "object" && t && "result" in t ? t.result : t;
|
|
2019
|
-
} else r = e;
|
|
2020
|
-
else if (typeof e == "string") try {
|
|
2021
|
-
r = JSON.parse(e);
|
|
2022
|
-
} catch {
|
|
2023
|
-
r = { content: e };
|
|
2024
|
-
}
|
|
2025
|
-
else r = e;
|
|
2026
|
-
try {
|
|
2027
|
-
return n.parse(r);
|
|
2028
|
-
} catch (e) {
|
|
2029
|
-
t.warn(`Failed to parse structured output: ${e}`);
|
|
2030
|
-
let i = n._def?.shape();
|
|
2031
|
-
if (i && "content" in i) return n.parse({ content: String(r) });
|
|
2032
|
-
throw e;
|
|
2033
|
-
}
|
|
2034
|
-
}
|
|
2035
|
-
async createChatSession() {
|
|
2036
|
-
let e = {
|
|
2037
|
-
title: `Remote Agent Session - ${this.agentId}`,
|
|
2038
|
-
agent_id: this.agentId,
|
|
2039
|
-
type: "agent_execution"
|
|
2040
|
-
}, n = {
|
|
2041
|
-
"Content-Type": "application/json",
|
|
2042
|
-
"x-api-key": this.apiKey
|
|
2043
|
-
}, r = `${this.baseUrl}${qe}`;
|
|
2044
|
-
t.debug(`\u{1F4DD} Creating chat session for agent ${this.agentId}`);
|
|
2045
|
-
try {
|
|
2046
|
-
let i = await fetch(r, {
|
|
2047
|
-
method: "POST",
|
|
2048
|
-
headers: n,
|
|
2049
|
-
body: JSON.stringify(e)
|
|
2050
|
-
});
|
|
2051
|
-
if (!i.ok) {
|
|
2052
|
-
let e = await i.text(), t = i.status;
|
|
2053
|
-
throw Error(t === 404 ? `Agent not found: Agent '${this.agentId}' does not exist or you don't have access to it. Please verify the agent ID and ensure it exists in your account.` : `Failed to create chat session: ${t} - ${e}`);
|
|
2054
|
-
}
|
|
2055
|
-
let a = (await i.json()).id;
|
|
2056
|
-
return t.debug(`\u2705 Chat session created: ${a}`), a;
|
|
2057
|
-
} catch (e) {
|
|
2058
|
-
throw e instanceof Error ? TypeError(`Failed to create chat session: ${e.message}`) : Error(`Failed to create chat session: ${String(e)}`);
|
|
2059
|
-
}
|
|
2060
|
-
}
|
|
2061
|
-
async run(e, n, r, i, a) {
|
|
2062
|
-
let { query: o, maxSteps: s, externalHistory: c, outputSchema: l } = Ye(e, n, r, i, a);
|
|
2063
|
-
c !== void 0 && t.warn("External history is not yet supported for remote execution");
|
|
2064
|
-
try {
|
|
2065
|
-
t.debug(`\u{1F310} Executing query on remote agent ${this.agentId}`), this.chatId === null && (this.chatId = await this.createChatSession());
|
|
2066
|
-
let e = this.chatId, n = {
|
|
2067
|
-
query: o,
|
|
2068
|
-
max_steps: s ?? 10
|
|
2069
|
-
};
|
|
2070
|
-
l && (n.output_schema = this.pydanticToJsonSchema(l), t.debug("🔧 Using structured output with schema"));
|
|
2071
|
-
let r = {
|
|
2072
|
-
"Content-Type": "application/json",
|
|
2073
|
-
"x-api-key": this.apiKey
|
|
2074
|
-
}, i = `${this.baseUrl}${Je.replace("{chat_id}", e)}`;
|
|
2075
|
-
t.debug(`\u{1F680} Executing agent in chat ${e}`);
|
|
2076
|
-
let a = await fetch(i, {
|
|
2077
|
-
method: "POST",
|
|
2078
|
-
headers: r,
|
|
2079
|
-
body: JSON.stringify(n),
|
|
2080
|
-
signal: AbortSignal.timeout(3e5)
|
|
2081
|
-
});
|
|
2082
|
-
if (!a.ok) {
|
|
2083
|
-
let e = await a.text(), n = a.status;
|
|
2084
|
-
throw n === 401 ? (t.error(`\u274C Authentication failed: ${e}`), Error("Authentication failed: Invalid or missing API key. Please check your API key and ensure the MCP_USE_API_KEY environment variable is set correctly.")) : n === 403 ? (t.error(`\u274C Access forbidden: ${e}`), Error(`Access denied: You don't have permission to execute agent '${this.agentId}'. Check if the agent exists and you have the necessary permissions.`)) : n === 404 ? (t.error(`\u274C Agent not found: ${e}`), Error(`Agent not found: Agent '${this.agentId}' does not exist or you don't have access to it. Please verify the agent ID and ensure it exists in your account.`)) : n === 422 ? (t.error(`\u274C Validation error: ${e}`), Error(`Request validation failed: ${e}. Please check your query parameters and output schema format.`)) : n === 500 ? (t.error(`\u274C Server error: ${e}`), Error("Internal server error occurred during agent execution. Please try again later or contact support if the issue persists.")) : (t.error(`\u274C Remote execution failed with status ${n}: ${e}`), Error(`Remote agent execution failed: ${n} - ${e}`));
|
|
2085
|
-
}
|
|
2086
|
-
let c = await a.json();
|
|
2087
|
-
if (t.debug(`\u{1F527} Response: ${JSON.stringify(c)}`), t.debug("✅ Remote execution completed successfully"), typeof c == "object" && c) {
|
|
2088
|
-
if (c.status === "error" || c.error !== null) {
|
|
2089
|
-
let e = c.error ?? String(c);
|
|
2090
|
-
throw t.error(`\u274C Remote agent execution failed: ${e}`), Error(`Remote agent execution failed: ${e}`);
|
|
2091
|
-
}
|
|
2092
|
-
if (String(c).includes("failed to initialize")) throw t.error(`\u274C Agent initialization failed: ${c}`), Error(`Agent initialization failed on remote server. This usually indicates:
|
|
2093
|
-
\u2022 Invalid agent configuration (LLM model, system prompt)
|
|
2094
|
-
\u2022 Missing or invalid MCP server configurations
|
|
2095
|
-
\u2022 Network connectivity issues with MCP servers
|
|
2096
|
-
\u2022 Missing environment variables or credentials
|
|
2097
|
-
Raw error: ${c}`);
|
|
2098
|
-
}
|
|
2099
|
-
return l ? this.parseStructuredResponse(c, l) : typeof c == "object" && c && "result" in c ? c.result : typeof c == "string" ? c : String(c);
|
|
2100
|
-
} catch (e) {
|
|
2101
|
-
throw e instanceof Error ? e.name === "AbortError" ? (t.error(`\u274C Remote execution timed out: ${e}`), Error("Remote agent execution timed out. The server may be overloaded or the query is taking too long to process. Try again or use a simpler query.")) : (t.error(`\u274C Remote execution error: ${e}`), Error(`Remote agent execution failed: ${e.message}`)) : (t.error(`\u274C Remote execution error: ${e}`), Error(`Remote agent execution failed: ${String(e)}`));
|
|
2102
|
-
}
|
|
2103
|
-
}
|
|
2104
|
-
async *stream(e, t, n, r, i) {
|
|
2105
|
-
return await this.run(e, t, n, r, i);
|
|
2106
|
-
}
|
|
2107
|
-
async close() {
|
|
2108
|
-
t.debug("🔌 Remote agent client closed");
|
|
2109
|
-
}
|
|
2110
|
-
}, Ze = class {
|
|
2111
|
-
static getPackageVersion() {
|
|
2112
|
-
return Ke();
|
|
2113
|
-
}
|
|
2114
|
-
driver;
|
|
2115
|
-
client;
|
|
2116
|
-
connectors = [];
|
|
2117
|
-
clientOwnedByAgent = !1;
|
|
2118
|
-
nativeAdapter;
|
|
2119
|
-
providerTools = [];
|
|
2120
|
-
callTool;
|
|
2121
|
-
maxSteps;
|
|
2122
|
-
autoInitialize;
|
|
2123
|
-
systemPrompt;
|
|
2124
|
-
disallowedTools;
|
|
2125
|
-
exposeResourcesAsTools;
|
|
2126
|
-
exposePromptsAsTools;
|
|
2127
|
-
initialized = !1;
|
|
2128
|
-
isRemote = !1;
|
|
2129
|
-
remoteAgent = null;
|
|
2130
|
-
isSimplifiedMode = !1;
|
|
2131
|
-
llmString;
|
|
2132
|
-
llmConfig;
|
|
2133
|
-
mcpServersConfig;
|
|
2134
|
-
explicitProviderConfig;
|
|
2135
|
-
conversationMessages = [];
|
|
2136
|
-
memoryEnabled;
|
|
2137
|
-
boundConnections;
|
|
2138
|
-
constructor(e) {
|
|
2139
|
-
if (e.agentId) {
|
|
2140
|
-
this.isRemote = !0, this.remoteAgent = new Xe({
|
|
2141
|
-
agentId: e.agentId,
|
|
2142
|
-
apiKey: e.apiKey,
|
|
2143
|
-
baseUrl: e.baseUrl
|
|
2144
|
-
}), this.maxSteps = e.maxSteps ?? 10, this.autoInitialize = e.autoInitialize ?? !1, this.nativeAdapter = new i(), this.systemPrompt = e.systemPrompt ?? "You are a helpful assistant with access to MCP tools.", this.disallowedTools = [], this.exposeResourcesAsTools = !0, this.exposePromptsAsTools = !0, this.memoryEnabled = e.memoryEnabled ?? !0;
|
|
2145
|
-
return;
|
|
2146
|
-
}
|
|
2147
|
-
if (this.maxSteps = e.maxSteps ?? 10, this.autoInitialize = e.autoInitialize ?? !1, this.systemPrompt = e.systemPrompt ?? "You are a helpful assistant with access to MCP tools.", this.disallowedTools = e.disallowedTools ?? [], this.exposeResourcesAsTools = e.exposeResourcesAsTools ?? !0, this.exposePromptsAsTools = e.exposePromptsAsTools ?? !0, this.memoryEnabled = e.memoryEnabled ?? !0, this.nativeAdapter = new i(this.disallowedTools), this.llmConfig = e.llmConfig, this.resolveMcpServers(e.mcpServers), typeof e.llm == "string") {
|
|
2148
|
-
if (this.isSimplifiedMode = !0, this.llmString = e.llm, !this.hasLiveConnections() && (!this.mcpServersConfig || Object.keys(this.mcpServersConfig).length === 0) && !e.client && !e.connectors?.length) throw Error("Simplified mode requires mcpServers, or an existing client/connectors.");
|
|
2149
|
-
} else if (this.explicitProviderConfig = e.llm, this.client = e.client, this.connectors = e.connectors ?? [], !this.hasLiveConnections() && !this.client && this.connectors.length === 0 && (!this.mcpServersConfig || Object.keys(this.mcpServersConfig).length === 0)) throw Error("Explicit mode requires mcpServers, client, or connectors.");
|
|
2150
|
-
e.client && (this.client = e.client), e.connectors?.length && (this.connectors = e.connectors), this.hasLiveConnections() && this.explicitProviderConfig ? this.bindConnections(this.boundConnections, this.explicitProviderConfig) : this.hasLiveConnections() && this.llmString && (this.driver = X(Q(this.llmString, this.llmConfig)), this.bindConnections(this.boundConnections, Q(this.llmString, this.llmConfig)));
|
|
2151
|
-
}
|
|
2152
|
-
resolveMcpServers(e) {
|
|
2153
|
-
if (e) {
|
|
2154
|
-
if (Array.isArray(e)) {
|
|
2155
|
-
this.boundConnections = e;
|
|
2156
|
-
return;
|
|
2157
|
-
}
|
|
2158
|
-
this.mcpServersConfig = e;
|
|
2159
|
-
}
|
|
2160
|
-
}
|
|
2161
|
-
hasLiveConnections() {
|
|
2162
|
-
return (this.boundConnections?.length ?? 0) > 0;
|
|
2163
|
-
}
|
|
2164
|
-
async initialize() {
|
|
2165
|
-
if (this.isRemote) {
|
|
2166
|
-
this.initialized = !0;
|
|
2167
|
-
return;
|
|
2168
|
-
}
|
|
2169
|
-
if (!this.initialized) {
|
|
2170
|
-
if (this.isSimplifiedMode) {
|
|
2171
|
-
if (!this.client && this.mcpServersConfig) {
|
|
2172
|
-
let { MCPClient: e } = await import("./index-browser-DkQOzkvX.js").then((e) => e.i);
|
|
2173
|
-
this.client = new e({ mcpServers: this.mcpServersConfig }), this.clientOwnedByAgent = !0;
|
|
2174
|
-
}
|
|
2175
|
-
this.llmString && (this.driver = X(Q(this.llmString, this.llmConfig)));
|
|
2176
|
-
} else this.explicitProviderConfig && (this.driver = X(this.explicitProviderConfig));
|
|
2177
|
-
if (!this.driver) throw Error("LLM driver not configured.");
|
|
2178
|
-
this.hasLiveConnections() || await this.loadTools(), this.initialized = !0, t.debug("MCPAgent initialized");
|
|
2179
|
-
}
|
|
2180
|
-
}
|
|
2181
|
-
async loadTools() {
|
|
2182
|
-
let e = [];
|
|
2183
|
-
if (this.client) {
|
|
2184
|
-
(!this.client.activeSessions || Object.keys(this.client.activeSessions).length === 0) && await this.client.createAllSessions();
|
|
2185
|
-
let t = this.client.getAllActiveSessions(), n = Object.values(t).map((e) => e.connector);
|
|
2186
|
-
e.push(...await this.nativeAdapter.createToolsFromConnectors(n)), this.exposeResourcesAsTools && e.push(...await this.nativeAdapter.createResourcesFromConnectors(n)), this.exposePromptsAsTools && e.push(...await this.nativeAdapter.createPromptsFromConnectors(n));
|
|
2187
|
-
} else {
|
|
2188
|
-
for (let e of this.connectors) e.isClientConnected || await e.connect();
|
|
2189
|
-
e.push(...await this.nativeAdapter.createToolsFromConnectors(this.connectors)), this.exposeResourcesAsTools && e.push(...await this.nativeAdapter.createResourcesFromConnectors(this.connectors)), this.exposePromptsAsTools && e.push(...await this.nativeAdapter.createPromptsFromConnectors(this.connectors));
|
|
2190
|
-
}
|
|
2191
|
-
this.providerTools = this.nativeAdapter.toProviderTools(e), this.callTool = this.nativeAdapter.createCallTool();
|
|
2192
|
-
}
|
|
2193
|
-
bindConnections(e, t) {
|
|
2194
|
-
let n = new Set(this.disallowedTools), r = /* @__PURE__ */ new Set(), i = /* @__PURE__ */ new Map(), a = (e) => {
|
|
2195
|
-
if (!r.has(e)) return r.add(e), e;
|
|
2196
|
-
let t = 2;
|
|
2197
|
-
for (; r.has(`${e}_${t}`);) t++;
|
|
2198
|
-
let n = `${e}_${t}`;
|
|
2199
|
-
return r.add(n), n;
|
|
2200
|
-
}, o = [];
|
|
2201
|
-
for (let t of e) for (let e of t.tools ?? []) {
|
|
2202
|
-
if (n.has(e.name)) continue;
|
|
2203
|
-
let r = a(e.name);
|
|
2204
|
-
i.set(r, {
|
|
2205
|
-
connection: t,
|
|
2206
|
-
mcpName: e.name
|
|
2207
|
-
}), o.push({
|
|
2208
|
-
name: r,
|
|
2209
|
-
description: e.description,
|
|
2210
|
-
inputSchema: e.inputSchema ?? {
|
|
2211
|
-
type: "object",
|
|
2212
|
-
properties: {}
|
|
2213
|
-
}
|
|
2214
|
-
});
|
|
2215
|
-
}
|
|
2216
|
-
this.providerTools = o, this.callTool = async (e, t) => {
|
|
2217
|
-
let n = i.get(e);
|
|
2218
|
-
if (!n) throw Error(`Unknown tool: ${e}`);
|
|
2219
|
-
return n.connection.callTool(n.mcpName, t);
|
|
2220
|
-
}, this.driver = X(t), this.initialized = !0;
|
|
2221
|
-
}
|
|
2222
|
-
buildMessages(e) {
|
|
2223
|
-
let t = [{
|
|
2224
|
-
role: "system",
|
|
2225
|
-
content: this.systemPrompt
|
|
2226
|
-
}];
|
|
2227
|
-
return this.memoryEnabled && this.conversationMessages.length > 0 && t.push(...this.conversationMessages), e.messages?.length && t.push(...e.messages), e.prompt && t.push({
|
|
2228
|
-
role: "user",
|
|
2229
|
-
content: e.prompt
|
|
2230
|
-
}), t;
|
|
2231
|
-
}
|
|
2232
|
-
getConversationHistory() {
|
|
2233
|
-
return [...this.conversationMessages];
|
|
2234
|
-
}
|
|
2235
|
-
clearConversationHistory() {
|
|
2236
|
-
this.conversationMessages = [];
|
|
2237
|
-
}
|
|
2238
|
-
setSystemMessage(e) {
|
|
2239
|
-
this.systemPrompt = e;
|
|
2240
|
-
}
|
|
2241
|
-
async ensureReady(e = !0) {
|
|
2242
|
-
if (e && !this.initialized) if (this.autoInitialize) await this.initialize();
|
|
2243
|
-
else throw Error("MCPAgent not initialized. Call initialize() first.");
|
|
2244
|
-
if (!this.driver || !this.callTool) throw Error("MCPAgent driver or tools not ready.");
|
|
2245
|
-
}
|
|
2246
|
-
nativeRunParams(e) {
|
|
2247
|
-
return {
|
|
2248
|
-
messages: this.buildMessages(e),
|
|
2249
|
-
tools: this.providerTools,
|
|
2250
|
-
callTool: this.callTool,
|
|
2251
|
-
maxSteps: e.maxSteps ?? this.maxSteps,
|
|
2252
|
-
signal: e.signal
|
|
2253
|
-
};
|
|
2254
|
-
}
|
|
2255
|
-
async run(e, t, n, r, i, a) {
|
|
2256
|
-
let o = $(e, t, n, r, i, a);
|
|
2257
|
-
if (o.schema) throw Error("Structured output requires @mcp-use/agent/langchain or pass a JSON schema via prompt.");
|
|
2258
|
-
if (this.isRemote && this.remoteAgent) return this.remoteAgent.run(o.prompt ?? "", o.maxSteps, o.manageConnector);
|
|
2259
|
-
await this.ensureReady(o.manageConnector ?? !0);
|
|
2260
|
-
let s = await Ve(this.driver, this.nativeRunParams(o));
|
|
2261
|
-
return this.memoryEnabled && o.prompt && (this.conversationMessages.push({
|
|
2262
|
-
role: "user",
|
|
2263
|
-
content: o.prompt
|
|
2264
|
-
}), this.conversationMessages.push({
|
|
2265
|
-
role: "assistant",
|
|
2266
|
-
content: s
|
|
2267
|
-
})), s;
|
|
2268
|
-
}
|
|
2269
|
-
async *stream(e, t, n, r, i, a) {
|
|
2270
|
-
let o = $(e, t, n, r, i, a);
|
|
2271
|
-
if (this.isRemote && this.remoteAgent) return await this.remoteAgent.run(o.prompt ?? "", o.maxSteps, o.manageConnector);
|
|
2272
|
-
await this.ensureReady(o.manageConnector ?? !0);
|
|
2273
|
-
let s = yield* Be(this.driver, this.nativeRunParams(o));
|
|
2274
|
-
return this.memoryEnabled && o.prompt && (this.conversationMessages.push({
|
|
2275
|
-
role: "user",
|
|
2276
|
-
content: o.prompt
|
|
2277
|
-
}), this.conversationMessages.push({
|
|
2278
|
-
role: "assistant",
|
|
2279
|
-
content: s
|
|
2280
|
-
})), s;
|
|
2281
|
-
}
|
|
2282
|
-
async *streamEvents(e, t, n, r, i, a) {
|
|
2283
|
-
let o = $(e, t, n, r, i, a);
|
|
2284
|
-
if (this.isRemote && this.remoteAgent) throw Error("streamEvents is not supported for remote agents.");
|
|
2285
|
-
await this.ensureReady(o.manageConnector ?? !0), yield* Z(this.driver, this.nativeRunParams(o));
|
|
2286
|
-
}
|
|
2287
|
-
async chat(e) {
|
|
2288
|
-
return await this.ensureReady(), (await this.driver.complete({
|
|
2289
|
-
messages: e.messages,
|
|
2290
|
-
tools: [],
|
|
2291
|
-
signal: e.signal
|
|
2292
|
-
})).text;
|
|
2293
|
-
}
|
|
2294
|
-
async close() {
|
|
2295
|
-
this.clientOwnedByAgent && this.client && await this.client.closeAllSessions?.(), this.initialized = !1;
|
|
2296
|
-
}
|
|
2297
|
-
};
|
|
2298
|
-
async function Qe(e) {
|
|
2299
|
-
return (await X(e.config).complete({
|
|
2300
|
-
messages: e.messages,
|
|
2301
|
-
tools: [],
|
|
2302
|
-
signal: e.signal
|
|
2303
|
-
})).text;
|
|
2304
|
-
}
|
|
2305
|
-
//#endregion
|
|
2306
|
-
export { Qe as a, We as c, D as i, Ze as n, ne as o, Ce as r, E as s, Se as t };
|