@assistant-ui/react 0.15.16 → 0.15.17
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 +3 -3
- package/dist/index.d.ts +4 -3
- package/dist/index.js +2 -2
- package/dist/mcp-apps/McpAppRenderer.d.ts +6 -1
- package/dist/mcp-apps/McpAppRenderer.d.ts.map +1 -1
- package/dist/mcp-apps/McpAppRenderer.js +19 -12
- package/dist/mcp-apps/McpAppRenderer.js.map +1 -1
- package/dist/mcp-apps/McpAppsRemoteHost.d.ts.map +1 -1
- package/dist/mcp-apps/McpAppsRemoteHost.js +20 -17
- package/dist/mcp-apps/McpAppsRemoteHost.js.map +1 -1
- package/dist/mcp-apps/app-frame.d.ts.map +1 -1
- package/dist/mcp-apps/app-frame.js +189 -94
- package/dist/mcp-apps/app-frame.js.map +1 -1
- package/dist/mcp-apps/index.d.ts +2 -2
- package/dist/model-context/frame/useAssistantFrameHost.d.ts +1 -1
- package/dist/model-context/frame/useAssistantFrameHost.js +10 -11
- package/dist/model-context/frame/useAssistantFrameHost.js.map +1 -1
- package/dist/model-context/makeAssistantVisible.js +1 -1
- package/dist/model-context/makeAssistantVisible.js.map +1 -1
- package/dist/primitives/actionBar/ActionBarCopy.js +3 -3
- package/dist/primitives/actionBar/ActionBarCopy.js.map +1 -1
- package/dist/primitives/actionBar/ActionBarExportMarkdown.js +3 -3
- package/dist/primitives/actionBar/ActionBarExportMarkdown.js.map +1 -1
- package/dist/primitives/actionBar/ActionBarFeedbackNegative.js +3 -3
- package/dist/primitives/actionBar/ActionBarFeedbackNegative.js.map +1 -1
- package/dist/primitives/actionBar/ActionBarFeedbackPositive.js +3 -3
- package/dist/primitives/actionBar/ActionBarFeedbackPositive.js.map +1 -1
- package/dist/primitives/actionBar/ActionBarRoot.js.map +1 -1
- package/dist/primitives/actionBar/ActionBarStopSpeaking.js +3 -3
- package/dist/primitives/actionBar/ActionBarStopSpeaking.js.map +1 -1
- package/dist/primitives/actionBarMore/ActionBarMoreContent.js.map +1 -1
- package/dist/primitives/actionBarMore/ActionBarMoreItem.js.map +1 -1
- package/dist/primitives/actionBarMore/ActionBarMoreRoot.js.map +1 -1
- package/dist/primitives/actionBarMore/ActionBarMoreSeparator.js.map +1 -1
- package/dist/primitives/actionBarMore/ActionBarMoreTrigger.js.map +1 -1
- package/dist/primitives/actionBarMore/scope.d.ts +2 -2
- package/dist/primitives/actionBarMore/scope.d.ts.map +1 -1
- package/dist/primitives/actionBarMore/scope.js.map +1 -1
- package/dist/primitives/assistantModal/AssistantModalAnchor.js.map +1 -1
- package/dist/primitives/assistantModal/AssistantModalContent.js +1 -1
- package/dist/primitives/assistantModal/AssistantModalContent.js.map +1 -1
- package/dist/primitives/assistantModal/AssistantModalRoot.js.map +1 -1
- package/dist/primitives/assistantModal/AssistantModalTrigger.js.map +1 -1
- package/dist/primitives/assistantModal/scope.d.ts +2 -2
- package/dist/primitives/assistantModal/scope.d.ts.map +1 -1
- package/dist/primitives/assistantModal/scope.js.map +1 -1
- package/dist/primitives/branchPicker/BranchPickerRoot.js.map +1 -1
- package/dist/primitives/composer/ComposerAttachmentDropzone.js +1 -1
- package/dist/primitives/composer/ComposerAttachmentDropzone.js.map +1 -1
- package/dist/primitives/composer/ComposerDictationTranscript.js.map +1 -1
- package/dist/primitives/composer/ComposerInput.js +1 -3
- package/dist/primitives/composer/ComposerInput.js.map +1 -1
- package/dist/primitives/composer/ComposerQuote.js +5 -5
- package/dist/primitives/composer/ComposerQuote.js.map +1 -1
- package/dist/primitives/composer/ComposerRoot.js +3 -3
- package/dist/primitives/composer/ComposerRoot.js.map +1 -1
- package/dist/primitives/composer/trigger/TriggerPopover.d.ts +5 -0
- package/dist/primitives/composer/trigger/TriggerPopover.d.ts.map +1 -1
- package/dist/primitives/composer/trigger/TriggerPopover.js +157 -130
- package/dist/primitives/composer/trigger/TriggerPopover.js.map +1 -1
- package/dist/primitives/composer/trigger/TriggerPopoverBack.js +3 -3
- package/dist/primitives/composer/trigger/TriggerPopoverBack.js.map +1 -1
- package/dist/primitives/composer/trigger/TriggerPopoverCategories.js +4 -4
- package/dist/primitives/composer/trigger/TriggerPopoverCategories.js.map +1 -1
- package/dist/primitives/composer/trigger/TriggerPopoverItems.js +4 -4
- package/dist/primitives/composer/trigger/TriggerPopoverItems.js.map +1 -1
- package/dist/primitives/composer/trigger/TriggerPopoverResource.d.ts +2 -0
- package/dist/primitives/composer/trigger/TriggerPopoverResource.d.ts.map +1 -1
- package/dist/primitives/composer/trigger/TriggerPopoverResource.js +63 -61
- package/dist/primitives/composer/trigger/TriggerPopoverResource.js.map +1 -1
- package/dist/primitives/composer/trigger/TriggerPopoverRootContext.d.ts +2 -0
- package/dist/primitives/composer/trigger/TriggerPopoverRootContext.d.ts.map +1 -1
- package/dist/primitives/composer/trigger/TriggerPopoverRootContext.js.map +1 -1
- package/dist/primitives/composer/trigger/detectTrigger.d.ts +21 -1
- package/dist/primitives/composer/trigger/detectTrigger.d.ts.map +1 -0
- package/dist/primitives/composer/trigger/detectTrigger.js +17 -3
- package/dist/primitives/composer/trigger/detectTrigger.js.map +1 -1
- package/dist/primitives/composer/trigger/index.d.ts +3 -1
- package/dist/primitives/composer/trigger/index.d.ts.map +1 -1
- package/dist/primitives/composer/trigger/index.js.map +1 -1
- package/dist/primitives/composer/trigger/triggerDetectionResource.d.ts +3 -4
- package/dist/primitives/composer/trigger/triggerDetectionResource.d.ts.map +1 -1
- package/dist/primitives/composer/trigger/triggerDetectionResource.js +15 -14
- package/dist/primitives/composer/trigger/triggerDetectionResource.js.map +1 -1
- package/dist/primitives/composer/trigger/triggerSelectionResource.d.ts.map +1 -1
- package/dist/primitives/composer/trigger/triggerSelectionResource.js +18 -19
- package/dist/primitives/composer/trigger/triggerSelectionResource.js.map +1 -1
- package/dist/primitives/composer.d.ts +3 -2
- package/dist/primitives/composer.js.map +1 -1
- package/dist/primitives/error/ErrorMessage.js.map +1 -1
- package/dist/primitives/message/MessageIf.js.map +1 -1
- package/dist/primitives/message/MessageParts.js.map +1 -1
- package/dist/primitives/message/MessagePartsGrouped.js.map +1 -1
- package/dist/primitives/message/MessageRoot.js +4 -4
- package/dist/primitives/message/MessageRoot.js.map +1 -1
- package/dist/primitives/messagePart/MessagePartText.js.map +1 -1
- package/dist/primitives/selectionToolbar/SelectionToolbarQuote.js +3 -3
- package/dist/primitives/selectionToolbar/SelectionToolbarQuote.js.map +1 -1
- package/dist/primitives/selectionToolbar/SelectionToolbarRoot.js +3 -3
- package/dist/primitives/selectionToolbar/SelectionToolbarRoot.js.map +1 -1
- package/dist/primitives/thread/ThreadIf.js.map +1 -1
- package/dist/primitives/thread/ThreadViewport.js +3 -3
- package/dist/primitives/thread/ThreadViewport.js.map +1 -1
- package/dist/primitives/thread/ThreadViewportFooter.js +3 -3
- package/dist/primitives/thread/ThreadViewportFooter.js.map +1 -1
- package/dist/primitives/thread/useThreadViewportAutoScroll.js +1 -1
- package/dist/primitives/thread/useThreadViewportAutoScroll.js.map +1 -1
- package/dist/primitives/threadList/ThreadListNew.js +3 -3
- package/dist/primitives/threadList/ThreadListNew.js.map +1 -1
- package/dist/primitives/threadListFocusGroup.d.ts +2 -1
- package/dist/primitives/threadListFocusGroup.d.ts.map +1 -1
- package/dist/primitives/threadListFocusGroup.js +2 -2
- package/dist/primitives/threadListFocusGroup.js.map +1 -1
- package/dist/primitives/threadListItem/ThreadListItemRoot.js +3 -3
- package/dist/primitives/threadListItem/ThreadListItemRoot.js.map +1 -1
- package/dist/primitives/threadListItem/ThreadListItemTrigger.js +1 -1
- package/dist/primitives/threadListItem/ThreadListItemTrigger.js.map +1 -1
- package/dist/primitives/threadListItemMore/ThreadListItemMoreContent.js +1 -1
- package/dist/primitives/threadListItemMore/ThreadListItemMoreContent.js.map +1 -1
- package/dist/primitives/threadListItemMore/ThreadListItemMoreItem.js.map +1 -1
- package/dist/primitives/threadListItemMore/ThreadListItemMoreRoot.js +1 -1
- package/dist/primitives/threadListItemMore/ThreadListItemMoreRoot.js.map +1 -1
- package/dist/primitives/threadListItemMore/ThreadListItemMoreSeparator.js.map +1 -1
- package/dist/primitives/threadListItemMore/ThreadListItemMoreTrigger.js +1 -2
- package/dist/primitives/threadListItemMore/ThreadListItemMoreTrigger.js.map +1 -1
- package/dist/primitives/threadListItemMore/scope.d.ts +2 -2
- package/dist/primitives/threadListItemMore/scope.d.ts.map +1 -1
- package/dist/primitives/threadListItemMore/scope.js.map +1 -1
- package/dist/sandbox-host/SandboxHost.d.ts.map +1 -1
- package/dist/sandbox-host/SandboxHost.js +137 -70
- package/dist/sandbox-host/SandboxHost.js.map +1 -1
- package/dist/unstable/useLiveCompletionAdapter.js +3 -1
- package/dist/unstable/useLiveCompletionAdapter.js.map +1 -1
- package/dist/unstable/useSlashCommandAdapter.js +41 -27
- package/dist/unstable/useSlashCommandAdapter.js.map +1 -1
- package/dist/utils/Primitive.d.ts +2 -2
- package/dist/utils/Primitive.js +2 -2
- package/dist/utils/Primitive.js.map +1 -1
- package/dist/utils/createActionButton.js +3 -3
- package/dist/utils/createActionButton.js.map +1 -1
- package/dist/utils/hooks/useOnResizeContent.js +1 -1
- package/dist/utils/hooks/useOnResizeContent.js.map +1 -1
- package/dist/utils/hooks/useOnScrollToBottom.js +1 -1
- package/dist/utils/hooks/useOnScrollToBottom.js.map +1 -1
- package/dist/utils/smooth/SmoothContext.d.ts +24 -0
- package/dist/utils/smooth/SmoothContext.d.ts.map +1 -1
- package/dist/utils/smooth/useSmooth.js +1 -1
- package/dist/utils/smooth/useSmooth.js.map +1 -1
- package/dist/utils/useToolArgsFieldStatus.d.ts +5 -1
- package/package.json +11 -19
- package/src/index.ts +9 -1
- package/src/mcp-apps/McpAppRenderer.test.tsx +133 -4
- package/src/mcp-apps/McpAppRenderer.tsx +28 -21
- package/src/mcp-apps/McpAppsRemoteHost.concurrent.test.tsx +215 -0
- package/src/mcp-apps/McpAppsRemoteHost.ts +28 -12
- package/src/mcp-apps/app-frame.test.tsx +102 -0
- package/src/mcp-apps/app-frame.tsx +17 -4
- package/src/mcp-apps/index.ts +1 -0
- package/src/model-context/frame/AssistantFrame.test.ts +3 -3
- package/src/model-context/frame/SPEC_AssistantFrame.md +1 -1
- package/src/model-context/frame/useAssistantFrameHost.ts +2 -2
- package/src/model-context/makeAssistantVisible.tsx +1 -1
- package/src/primitives/actionBar/ActionBarCopy.tsx +1 -1
- package/src/primitives/actionBar/ActionBarExportMarkdown.tsx +1 -1
- package/src/primitives/actionBar/ActionBarFeedbackNegative.tsx +1 -1
- package/src/primitives/actionBar/ActionBarFeedbackPositive.tsx +1 -1
- package/src/primitives/actionBar/ActionBarStopSpeaking.tsx +1 -1
- package/src/primitives/actionBarMore/scope.ts +2 -2
- package/src/primitives/assistantModal/AssistantModalContent.tsx +1 -1
- package/src/primitives/assistantModal/scope.ts +2 -2
- package/src/primitives/composer/ComposerAttachmentDropzone.tsx +1 -1
- package/src/primitives/composer/ComposerInput.test.tsx +2 -1
- package/src/primitives/composer/ComposerInput.tsx +3 -3
- package/src/primitives/composer/ComposerQuote.tsx +1 -1
- package/src/primitives/composer/ComposerRoot.tsx +1 -1
- package/src/primitives/composer/trigger/TriggerPopover.tsx +16 -1
- package/src/primitives/composer/trigger/TriggerPopoverBack.tsx +1 -1
- package/src/primitives/composer/trigger/TriggerPopoverCategories.tsx +1 -1
- package/src/primitives/composer/trigger/TriggerPopoverItems.tsx +1 -1
- package/src/primitives/composer/trigger/TriggerPopoverResource.ts +4 -1
- package/src/primitives/composer/trigger/TriggerPopoverRootContext.tsx +2 -0
- package/src/primitives/composer/trigger/detectTrigger.test.ts +88 -5
- package/src/primitives/composer/trigger/detectTrigger.ts +50 -9
- package/src/primitives/composer/trigger/index.ts +1 -0
- package/src/primitives/composer/trigger/triggerDetectionResource.ts +10 -7
- package/src/primitives/composer/trigger/triggerSelectionResource.test.ts +15 -3
- package/src/primitives/composer/trigger/triggerSelectionResource.ts +1 -4
- package/src/primitives/composer.ts +1 -0
- package/src/primitives/message/MessageRoot.tsx +1 -1
- package/src/primitives/selectionToolbar/SelectionToolbarQuote.tsx +1 -1
- package/src/primitives/selectionToolbar/SelectionToolbarRoot.tsx +1 -1
- package/src/primitives/thread/ThreadViewport.tsx +1 -1
- package/src/primitives/thread/ThreadViewportFooter.tsx +1 -1
- package/src/primitives/thread/useThreadViewportAutoScroll.ts +1 -1
- package/src/primitives/threadList/ThreadListNew.tsx +1 -1
- package/src/primitives/threadListFocusGroup.ts +2 -2
- package/src/primitives/threadListItem/ThreadListItemRoot.tsx +1 -1
- package/src/primitives/threadListItem/ThreadListItemTrigger.tsx +1 -1
- package/src/primitives/threadListItemMore/ThreadListItemMoreContent.tsx +1 -1
- package/src/primitives/threadListItemMore/ThreadListItemMoreRoot.tsx +1 -1
- package/src/primitives/threadListItemMore/ThreadListItemMoreTrigger.tsx +2 -2
- package/src/primitives/threadListItemMore/scope.ts +2 -2
- package/src/sandbox-host/SandboxHost.test.tsx +45 -1
- package/src/sandbox-host/SandboxHost.tsx +16 -3
- package/src/tests/RemoteThreadListRuntime.adapterProvider.test.tsx +31 -1
- package/src/unstable/useLiveCompletionAdapter.test.tsx +60 -1
- package/src/unstable/useLiveCompletionAdapter.ts +4 -1
- package/src/unstable/useSlashCommandAdapter.test.tsx +141 -0
- package/src/unstable/useSlashCommandAdapter.ts +52 -17
- package/src/utils/Primitive.tsx +2 -2
- package/src/utils/createActionButton.tsx +1 -1
- package/src/utils/hooks/useOnResizeContent.ts +1 -1
- package/src/utils/hooks/useOnScrollToBottom.ts +1 -1
- package/src/utils/smooth/useSmooth.ts +1 -1
- package/dist/legacy-runtime/runtime/MessagePartRuntime.d.ts +0 -3
- package/dist/legacy-runtime/runtime/MessagePartRuntime.js +0 -2
- package/dist/legacy-runtime/runtime/MessageRuntime.d.ts +0 -3
- package/dist/legacy-runtime/runtime/MessageRuntime.js +0 -2
- package/dist/legacy-runtime/runtime/ThreadListRuntime.d.ts +0 -3
- package/dist/legacy-runtime/runtime/ThreadListRuntime.js +0 -2
- package/src/legacy-runtime/runtime/MessagePartRuntime.ts +0 -2
- package/src/legacy-runtime/runtime/MessageRuntime.ts +0 -3
- package/src/legacy-runtime/runtime/ThreadListRuntime.ts +0 -4
package/README.md
CHANGED
|
@@ -38,7 +38,7 @@ npx assistant-ui@latest init # add to existing project
|
|
|
38
38
|
Or install the packages directly:
|
|
39
39
|
|
|
40
40
|
```bash
|
|
41
|
-
npm install @assistant-ui/react @assistant-ui/
|
|
41
|
+
npm install @assistant-ui/react @assistant-ui/ai-sdk
|
|
42
42
|
```
|
|
43
43
|
|
|
44
44
|
## Usage
|
|
@@ -47,7 +47,7 @@ npm install @assistant-ui/react @assistant-ui/react-ai-sdk
|
|
|
47
47
|
"use client";
|
|
48
48
|
|
|
49
49
|
import { AssistantRuntimeProvider } from "@assistant-ui/react";
|
|
50
|
-
import { useChatRuntime } from "@assistant-ui/
|
|
50
|
+
import { useChatRuntime } from "@assistant-ui/ai-sdk";
|
|
51
51
|
import { Thread } from "@/components/assistant-ui/thread";
|
|
52
52
|
|
|
53
53
|
export function Chat() {
|
|
@@ -75,7 +75,7 @@ export function Chat() {
|
|
|
75
75
|
|
|
76
76
|
| Integration | Package |
|
|
77
77
|
| -------------------------------------- | ---------------------------------------------------------------- |
|
|
78
|
-
| Vercel AI SDK | `@assistant-ui/
|
|
78
|
+
| Vercel AI SDK | `@assistant-ui/ai-sdk` |
|
|
79
79
|
| LangGraph / LangChain | `@assistant-ui/react-langgraph`, `@assistant-ui/react-langchain` |
|
|
80
80
|
| AG-UI / A2A protocols | `@assistant-ui/react-ag-ui`, `@assistant-ui/react-a2a` |
|
|
81
81
|
| Google ADK / OpenCode | `@assistant-ui/react-google-adk`, `@assistant-ui/react-opencode` |
|
package/dist/index.d.ts
CHANGED
|
@@ -33,6 +33,7 @@ import { assistantModal_d_exports } from "./primitives/assistantModal.js";
|
|
|
33
33
|
import { attachment_d_exports } from "./primitives/attachment.js";
|
|
34
34
|
import { branchPicker_d_exports } from "./primitives/branchPicker.js";
|
|
35
35
|
import { chainOfThought_d_exports } from "./primitives/chainOfThought.js";
|
|
36
|
+
import { TriggerMatch, TriggerMatcher } from "./primitives/composer/trigger/detectTrigger.js";
|
|
36
37
|
import { TriggerBehavior } from "./primitives/composer/trigger/triggerSelectionResource.js";
|
|
37
38
|
import { RegisteredTrigger, useTriggerPopoverRootContext, useTriggerPopoverRootContextOptional, useTriggerPopoverTriggers, useTriggerPopoverTriggersOptional } from "./primitives/composer/trigger/TriggerPopoverRootContext.js";
|
|
38
39
|
import { useTriggerPopoverScopeContext, useTriggerPopoverScopeContextOptional } from "./primitives/composer/trigger/TriggerPopover.js";
|
|
@@ -64,7 +65,7 @@ import { Unstable_SlashCommand, Unstable_SlashCommandAction, Unstable_UseSlashCo
|
|
|
64
65
|
import { Unstable_UseLiveCompletionAdapterOptions, unstable_useLiveCompletionAdapter } from "./unstable/useLiveCompletionAdapter.js";
|
|
65
66
|
import { Unstable_ComposerInputHistory, unstable_useComposerInputHistory } from "./unstable/useComposerInputHistory.js";
|
|
66
67
|
import { Unstable_ComposerInput, Unstable_TriggerPopoverAriaProps, Unstable_UseComposerInputOptions, unstable_useComposerInput, unstable_useTriggerPopoverAriaProps } from "./unstable/useComposerInput.js";
|
|
67
|
-
import { McpAppDisplayMode, McpAppHostContext, McpAppHostInfo, McpAppMetadata, McpAppResource, McpAppResourceCSP, McpAppResourceMeta, McpAppSandboxConfig, McpAppToolCallParams, McpAppsHost, McpAppsRemoteHostOptions, ToolCallMessagePartMcpMetadata } from "./mcp-apps/types.js";
|
|
68
|
+
import { McpAppBridgeHandlers, McpAppDisplayMode, McpAppHostContext, McpAppHostInfo, McpAppMetadata, McpAppResource, McpAppResourceCSP, McpAppResourceMeta, McpAppSandboxConfig, McpAppToolCallParams, McpAppsHost, McpAppsRemoteHostOptions, ToolCallMessagePartMcpMetadata } from "./mcp-apps/types.js";
|
|
68
69
|
import { McpAppRenderer, McpAppRendererOptions } from "./mcp-apps/McpAppRenderer.js";
|
|
69
70
|
import { McpAppsRemoteHost } from "./mcp-apps/McpAppsRemoteHost.js";
|
|
70
71
|
import { getMcpAppFromToolPart } from "./mcp-apps/utils.js";
|
|
@@ -72,7 +73,7 @@ import "./mcp-apps/index.js";
|
|
|
72
73
|
import { AssistantContextConfig, AssistantDataUI, AssistantDataUIProps, AssistantInteractableProps, AssistantTool, AssistantToolProps, AssistantToolUI, AssistantToolUIProps, DataMessagePartComponent, DataMessagePartProps, DataRenderers, EmptyMessagePartComponent, EmptyMessagePartProps, EnrichedPartState, FileMessagePartComponent, FileMessagePartProps, GenerativeUIComponentRegistry, GenerativeUIMessagePartComponent, GenerativeUIMessagePartProps, GenerativeUIRender, GenerativeUIRenderError, GenerativeUIRenderProps, GroupByContext, ImageMessagePartComponent, ImageMessagePartProps, Interactables, McpAppResourceOutput, McpToolkitDefinition, McpToolkitEntry, McpToolkitToolConfig, PartState, ProviderToolConfig, QuoteMessagePartComponent, QuoteMessagePartProps, ReasoningGroupComponent, ReasoningGroupProps, ReasoningMessagePartComponent, ReasoningMessagePartProps, RuntimeAdapterProvider, RuntimeAdapters, SourceMessagePartComponent, SourceMessagePartProps, TextMessagePartComponent, TextMessagePartProps, ToolArgsStatus, ToolCallMessagePartComponent, ToolCallMessagePartProps, ToolCallText, ToolDefinition, Toolkit, ToolkitDefinition, ToolkitDefinitionEntry, Tools, Unstable_AudioMessagePartComponent, Unstable_AudioMessagePartProps, Unstable_InferInteractableState, Unstable_InteractableConfig, Unstable_InteractableDefinition, Unstable_InteractablePersistedState, Unstable_InteractablePersistenceAdapter, Unstable_InteractablePersistenceStatus, Unstable_InteractableRegistration, Unstable_InteractableStateSchema, Unstable_InteractableToolConfig, Unstable_InteractableToolRenderProps, Unstable_InteractableVersionInfo, Unstable_InteractablesClientSchema, Unstable_InteractablesConfig, Unstable_InteractablesMethods, Unstable_InteractablesState, defineMcpToolkit, defineToolkit, externalTool, groupPartByType, hitl, hitlTool, humanTool, makeAssistantDataUI, makeAssistantTool, makeAssistantToolUI, providerTool, stubTool, unstable_Interactables, unstable_interactableTool, unstable_useInteractable, unstable_useInteractableState, unstable_useInteractableVersions, unstable_useThreadMessageIds, useAssistantContext, useAssistantDataUI, useAssistantInstructions, useAssistantInteractable, useAssistantTool, useAssistantToolUI, useAuiToolOverrides, useCloudThreadListRuntime, useExternalStoreSharedOptions, useInlineRender, useInteractableState, useRuntimeAdapters, useToolArgsStatus, useVoiceControls, useVoiceState, useVoiceVolume } from "@assistant-ui/core/react";
|
|
73
74
|
import { AssistantClient, AssistantEventCallback, AssistantEventName, AssistantEventPayload, AssistantEventScope, AssistantEventSelector, AssistantState, AuiConfig, AuiIf, AuiProvider, useAui, useAuiEvent, useAuiState } from "@assistant-ui/store";
|
|
74
75
|
import { AssistantCloud } from "assistant-cloud";
|
|
75
|
-
import { AddToolResultOptions, AppendMessage, AssistantFrameHost, AssistantFrameProvider, AssistantRuntime, Attachment, AttachmentAdapter, AttachmentRuntime, AttachmentState, AttachmentStatus, ChatModelAdapter, ChatModelRunOptions, ChatModelRunResult, ChatModelRunUpdate, CompleteAttachment, ComposerRuntime, ComposerState, CompositeAttachmentAdapter, CreateAppendMessage, CreateAttachment, CreateResumeRunConfig, CreateStartRunConfig, DataMessagePart, DictationAdapter, DictationState, EditComposerRuntime, EditComposerState, ExportedMessageRepository, ExportedMessageRepositoryItem, ExternalStoreAdapter, ExternalStoreBranchChange, ExternalStoreMessageConverter, ExternalStoreSharedOptions, ExternalStoreThreadData, ExternalStoreThreadListAdapter, ExternalThreadBranchAdapter, ExternalThreadQueueAdapter, FRAME_MESSAGE_CHANNEL, FeedbackAdapter, FileMessagePart, FrameMessage, FrameMessageType, GenerativeUIMessagePart, GenerativeUINode, GenerativeUISpec, GenericThreadHistoryAdapter, ImageMessagePart, InMemoryThreadListAdapter, LanguageModelConfig, LanguageModelV1CallSettings, LocalRuntimeOptionsBase, MessageFormatAdapter, MessageFormatItem, MessageFormatRepository, MessageNotSentError, MessagePartRuntime, MessagePartState, MessagePartStatus, MessagePartStreamStatus, MessageQueueController, MessageQueueDriver, MessageRuntime, MessageState, MessageStatus, MessageStorageEntry, MessageTiming, ModelContext, ModelContextProvider, ModelContextRegistry, ModelContextRegistryInstructionHandle, ModelContextRegistryProviderHandle, ModelContextRegistryToolHandle, PartProviderMetadata, PendingAttachment, QuoteInfo, RealtimeVoiceAdapter, ReasoningMessagePart, RemoteThreadListAdapter, RemoteThreadListProviderComponent, RespondToToolApprovalOptions, SerializedModelContext, SerializedTool, SimpleImageAttachmentAdapter, SimpleTextAttachmentAdapter, SourceMessagePart, SourceProviderMetadata, SpeechSynthesisAdapter, SubmitFeedbackOptions, SuggestionAdapter, TextMessagePart, ThreadAssistantMessage, ThreadAssistantMessagePart, ThreadComposerRuntime, ThreadComposerState, ThreadHistoryAdapter, ThreadListItemRuntime, ThreadListItemState, ThreadListItemStatus, ThreadListRuntime, ThreadListState, ThreadMessage, ThreadMessageLike, ThreadRuntime, ThreadState, ThreadSuggestion, ThreadSystemMessage, ThreadUserMessage, ThreadUserMessagePart, ToolApprovalOption, ToolApprovalOptionKind, ToolApprovalResponse, ToolCallMessagePart, ToolCallMessagePartStatus, ToolCallTiming, ToolModelContentPart, Unstable_AudioMessagePart, Unstable_DirectiveFormatter, Unstable_DirectiveSegment, Unstable_InteractableSnapshotEntry, Unstable_InteractableVersion, Unstable_TriggerItem, Unsubscribe, VoiceSessionControls, VoiceSessionHelpers, VoiceSessionState, WebSpeechDictationAdapter, WebSpeechSynthesisAdapter, bindExternalStoreMessage, createMessageQueue, createVoiceSession, fromThreadMessageLike, generateId, getExternalStoreMessages, isMessageNotSentError, mergeModelContexts, pickExternalStoreSharedOptions, tool, unstable_defaultDirectiveFormatter, unstable_formatInteractableSnapshot, unstable_getInteractableSnapshots, unstable_getInteractableVersions } from "@assistant-ui/core";
|
|
76
|
+
import { AddToolResultOptions, AppendMessage, AssistantFrameHost, AssistantFrameProvider, AssistantRuntime, Attachment, AttachmentAdapter, AttachmentRuntime, AttachmentState, AttachmentStatus, ChatModelAdapter, ChatModelRunOptions, ChatModelRunResult, ChatModelRunUpdate, CompleteAttachment, ComposerRuntime, ComposerState, CompositeAttachmentAdapter, CreateAppendMessage, CreateAttachment, CreateResumeRunConfig, CreateStartRunConfig, CreateSuggestionAdapterOptions, DataMessagePart, DictationAdapter, DictationState, EditComposerRuntime, EditComposerState, ExportedMessageRepository, ExportedMessageRepositoryItem, ExternalStoreAdapter, ExternalStoreBranchChange, ExternalStoreMessageConverter, ExternalStoreSharedOptions, ExternalStoreThreadData, ExternalStoreThreadListAdapter, ExternalThreadBranchAdapter, ExternalThreadQueueAdapter, FRAME_MESSAGE_CHANNEL, FeedbackAdapter, FileMessagePart, FrameMessage, FrameMessageType, GenerativeUIMessagePart, GenerativeUINode, GenerativeUISpec, GenericThreadHistoryAdapter, ImageMessagePart, InMemoryThreadListAdapter, LanguageModelConfig, LanguageModelV1CallSettings, LocalRuntimeOptionsBase, MessageFormatAdapter, MessageFormatItem, MessageFormatRepository, MessageNotSentError, MessagePartRuntime, MessagePartState, MessagePartStatus, MessagePartStreamStatus, MessageQueueController, MessageQueueDriver, MessageRuntime, MessageState, MessageStatus, MessageStorageEntry, MessageTiming, ModelContext, ModelContextProvider, ModelContextRegistry, ModelContextRegistryInstructionHandle, ModelContextRegistryProviderHandle, ModelContextRegistryToolHandle, PartProviderMetadata, PendingAttachment, QuoteInfo, RealtimeVoiceAdapter, ReasoningMessagePart, RemoteThreadListAdapter, RemoteThreadListProviderComponent, RespondToToolApprovalOptions, SerializedModelContext, SerializedTool, SimpleImageAttachmentAdapter, SimpleTextAttachmentAdapter, SourceMessagePart, SourceProviderMetadata, SpeechSynthesisAdapter, SubmitFeedbackOptions, SuggestionAdapter, SuggestionAdapterGenerateOptions, TextMessagePart, ThreadAssistantMessage, ThreadAssistantMessagePart, ThreadComposerRuntime, ThreadComposerState, ThreadHistoryAdapter, ThreadListItemRuntime, ThreadListItemState, ThreadListItemStatus, ThreadListRuntime, ThreadListState, ThreadMessage, ThreadMessageLike, ThreadRuntime, ThreadState, ThreadSuggestion, ThreadSystemMessage, ThreadUserMessage, ThreadUserMessagePart, ToolApprovalOption, ToolApprovalOptionKind, ToolApprovalResponse, ToolCallMessagePart, ToolCallMessagePartStatus, ToolCallTiming, ToolModelContentPart, Unstable_AudioMessagePart, Unstable_DirectiveFormatter, Unstable_DirectiveSegment, Unstable_InteractableSnapshotEntry, Unstable_InteractableVersion, Unstable_TriggerItem, Unsubscribe, VoiceSessionControls, VoiceSessionHelpers, VoiceSessionState, WebSpeechDictationAdapter, WebSpeechSynthesisAdapter, bindExternalStoreMessage, createMessageQueue, createSuggestionAdapter, createVoiceSession, fromThreadMessageLike, generateId, getExternalStoreMessages, isMessageNotSentError, mergeModelContexts, pickExternalStoreSharedOptions, tool, unstable_defaultDirectiveFormatter, unstable_formatInteractableSnapshot, unstable_getInteractableSnapshots, unstable_getInteractableVersions } from "@assistant-ui/core";
|
|
76
77
|
import { ChainOfThoughtClient, ComposerSendOptions, ExternalThread, ExternalThreadMessage, ExternalThreadProps, InMemoryThreadList, InMemoryThreadListProps, ModelContext as ModelContextClient, QueueItemMethods, QueueItemState, RemoteThreadList, RemoteThreadListProps, SingleThreadList, SuggestionConfig, Suggestions } from "@assistant-ui/core/store";
|
|
77
78
|
import { Tool } from "assistant-stream";
|
|
78
|
-
export { actionBarMore_d_exports as ActionBarMorePrimitive, actionBar_d_exports as ActionBarPrimitive, type AddToolResultOptions, type AppendMessage, type Assistant, type AssistantClient, AssistantCloud, type AssistantContextConfig, type AssistantDataUI, type AssistantDataUIProps, type AssistantEventCallback, type AssistantEventName, type AssistantEventPayload, type AssistantEventScope, type AssistantEventSelector, AssistantFrameHost, AssistantFrameProvider, type AssistantInteractableProps, assistantModal_d_exports as AssistantModalPrimitive, type AssistantRuntime, AssistantRuntimeProvider, type AssistantState, type AssistantTool, type AssistantToolProps, type AssistantToolUI, type AssistantToolUIProps, type AssistantTransportCommand, type AssistantTransportConnectionMetadata, type AssistantTransportProtocol, type Attachment, type AttachmentAdapter, attachment_d_exports as AttachmentPrimitive, type AttachmentRuntime, type AttachmentState, type AttachmentStatus, AuiConfig, AuiIf, AuiProvider, branchPicker_d_exports as BranchPickerPrimitive, ChainOfThoughtByIndicesProvider, ChainOfThoughtClient, chainOfThought_d_exports as ChainOfThoughtPrimitive, type ChatModelAdapter, type ChatModelRunOptions, type ChatModelRunResult, type ChatModelRunUpdate, CloudFileAttachmentAdapter, type CompleteAttachment, ComposerAttachmentByIndexProvider, composer_d_exports as ComposerPrimitive, type ComposerRuntime, type ComposerSendOptions, type ComposerState, CompositeAttachmentAdapter, type CreateAppendMessage, type CreateAttachment, type CreateResumeRunConfig, type CreateStartRunConfig, type DataMessagePart, type DataMessagePartComponent, type DataMessagePartProps, DataRenderers, DevToolsHooks, DevToolsProviderApi, type DictationAdapter, type DictationState, type EditComposerRuntime, type EditComposerState, type EmptyMessagePartComponent, type EmptyMessagePartProps, type EnrichedPartState, error_d_exports as ErrorPrimitive, ExportedMessageRepository, type ExportedMessageRepositoryItem, type ExternalStoreAdapter, type ExternalStoreBranchChange, type ExternalStoreMessageConverter, type ExternalStoreSharedOptions, type ExternalStoreThreadData, type ExternalStoreThreadListAdapter, ExternalThread, type ExternalThreadBranchAdapter, type ExternalThreadMessage, type ExternalThreadProps, type ExternalThreadQueueAdapter, FRAME_MESSAGE_CHANNEL, type FeedbackAdapter, type FileMessagePart, type FileMessagePartComponent, type FileMessagePartProps, type FrameMessage, type FrameMessageType, type GenerativeUIComponentRegistry, type GenerativeUIMessagePart, type GenerativeUIMessagePartComponent, type GenerativeUIMessagePartProps, type GenerativeUINode, GenerativeUIRender, GenerativeUIRenderError, type GenerativeUIRenderProps, type GenerativeUISpec, type GenericThreadHistoryAdapter, type GroupByContext, internal_d_exports as INTERNAL, type ImageMessagePart, type ImageMessagePartComponent, type ImageMessagePartProps, InMemoryThreadList, InMemoryThreadListAdapter, type InMemoryThreadListProps, Interactables, type LanguageModelConfig, type LanguageModelV1CallSettings, type LocalRuntimeOptions, type LocalRuntimeOptionsBase, type McpAppDisplayMode, type McpAppHostContext, type McpAppHostInfo, type McpAppMetadata, McpAppRenderer, type McpAppRendererOptions, type McpAppResource, type McpAppResourceCSP, type McpAppResourceMeta, type McpAppResourceOutput, type McpAppSandboxConfig, type McpAppToolCallParams, type McpAppsHost, McpAppsRemoteHost, type McpAppsRemoteHostOptions, type McpToolkitDefinition, type McpToolkitEntry, type McpToolkitToolConfig, MessageAttachmentByIndexProvider, MessageByIndexProvider, type MessageFormatAdapter, type MessageFormatItem, type MessageFormatRepository, MessageNotSentError, messagePart_d_exports as MessagePartPrimitive, type MessagePartRuntime, type MessagePartState, type MessagePartStatus, type MessagePartStreamStatus, message_d_exports as MessagePrimitive, MessageProvider, type MessageQueueController, type MessageQueueDriver, type MessageRuntime, type MessageState, type MessageStatus, type MessageStorageEntry, type MessageTiming, type ModelContext, ModelContextClient, type ModelContextProvider, ModelContextRegistry, type ModelContextRegistryInstructionHandle, type ModelContextRegistryProviderHandle, type ModelContextRegistryToolHandle, PartByIndexProvider, type PartProviderMetadata, type PartState, type PendingAttachment, type ProviderToolConfig, type QueueItemMethods, queueItem_d_exports as QueueItemPrimitive, type QueueItemState, type QuoteInfo, type QuoteMessagePartComponent, type QuoteMessagePartProps, ReadonlyThreadProvider, type RealtimeVoiceAdapter, type ReasoningGroupComponent, type ReasoningGroupProps, type ReasoningMessagePart, type ReasoningMessagePartComponent, type ReasoningMessagePartProps, RemoteThreadList, type RemoteThreadListAdapter, type RemoteThreadListProps, type RemoteThreadListProviderComponent, type RespondToToolApprovalOptions, RuntimeAdapterProvider, type RuntimeAdapters, selectionToolbar_d_exports as SelectionToolbarPrimitive, type SendCommandsRequestBody, type SerializedModelContext, type SerializedTool, SimpleImageAttachmentAdapter, SimpleTextAttachmentAdapter, SingleThreadList, type SmoothOptions, type SourceMessagePart, type SourceMessagePartComponent, type SourceMessagePartProps, type SourceProviderMetadata, type SpeechSynthesisAdapter, type SubmitFeedbackOptions, type SuggestionAdapter, SuggestionByIndexProvider, type SuggestionConfig, suggestion_d_exports as SuggestionPrimitive, Suggestions, type TextMessagePart, type TextMessagePartComponent, type TextMessagePartProps, TextMessagePartProvider, type ThreadAssistantMessage, type ThreadAssistantMessagePart, type ThreadComposerRuntime, type ThreadComposerState, type ThreadHistoryAdapter, ThreadListItemByIndexProvider, threadListItemMore_d_exports as ThreadListItemMorePrimitive, threadListItem_d_exports as ThreadListItemPrimitive, type ThreadListItemRuntime, ThreadListItemRuntimeProvider, type ThreadListItemState, type ThreadListItemStatus, threadList_d_exports as ThreadListPrimitive, type ThreadListRuntime, type ThreadListState, type ThreadMessage, type ThreadMessageLike, thread_d_exports as ThreadPrimitive, type ThreadRuntime, type ThreadState, type ThreadSuggestion, type ThreadSystemMessage, type ThreadUserMessage, type ThreadUserMessagePart, type ThreadViewportState, type Tool, type ToolApprovalOption, type ToolApprovalOptionKind, type ToolApprovalResponse, type ToolArgsStatus, type ToolCallMessagePart, type ToolCallMessagePartComponent, type ToolCallMessagePartMcpMetadata, type ToolCallMessagePartProps, type ToolCallMessagePartStatus, type ToolCallText, type ToolCallTiming, type ToolDefinition, type ToolExecutionStatus, type ToolModelContentPart, type Toolkit, type ToolkitDefinition, type ToolkitDefinitionEntry, Tools, type Unstable_AudioMessagePart, type Unstable_AudioMessagePartComponent, type Unstable_AudioMessagePartProps, type Unstable_ComposerInput, type Unstable_ComposerInputHistory, type Unstable_DirectiveFormatter, type Unstable_DirectiveSegment, type Unstable_IconComponent, type Unstable_InferInteractableState, type Unstable_InteractableConfig, type Unstable_InteractableDefinition, type Unstable_InteractablePersistedState, type Unstable_InteractablePersistenceAdapter, type Unstable_InteractablePersistenceStatus, type Unstable_InteractableRegistration, type Unstable_InteractableSnapshotEntry, type Unstable_InteractableStateSchema, type Unstable_InteractableToolConfig, type Unstable_InteractableToolRenderProps, type Unstable_InteractableVersion, type Unstable_InteractableVersionInfo, type Unstable_InteractablesClientSchema, type Unstable_InteractablesConfig, type Unstable_InteractablesMethods, type Unstable_InteractablesState, type Unstable_Mention, type Unstable_MentionCategory, type Unstable_MentionDirective, type Unstable_MessageStallDetection, type Unstable_MessageStallDetectionOptions, type Unstable_ModelContextToolsOptions, type RegisteredTrigger as Unstable_RegisteredTrigger, type Unstable_SlashCommand, type Unstable_SlashCommandAction, type TriggerBehavior as Unstable_TriggerBehavior, type Unstable_TriggerItem, type Unstable_TriggerPopoverAriaProps, type Unstable_UseComposerInputOptions, type Unstable_UseLiveCompletionAdapterOptions, type Unstable_UseMentionAdapterOptions, type Unstable_UseSlashCommandAdapterOptions, type Unsubscribe, type VoiceSessionControls, type VoiceSessionHelpers, type VoiceSessionState, WebSpeechDictationAdapter, WebSpeechSynthesisAdapter, bindExternalStoreMessage, createMessageQueue, createVoiceSession, defineMcpToolkit, defineToolkit, externalTool, fromThreadMessageLike, generateId, getExternalStoreMessages, getMcpAppFromToolPart, groupPartByType, hitl, hitlTool, humanTool, isMessageNotSentError, makeAssistantDataUI, makeAssistantTool, makeAssistantToolUI, makeAssistantVisible, mergeModelContexts, pickExternalStoreSharedOptions, providerTool, stubTool, tool, unstable_Interactables, convertExternalMessages as unstable_convertExternalMessages, createMessageConverter as unstable_createMessageConverter, unstable_defaultDirectiveFormatter, unstable_formatInteractableSnapshot, unstable_getInteractableSnapshots, unstable_getInteractableVersions, unstable_interactableTool, unstable_useComposerInput, unstable_useComposerInputHistory, unstable_useInteractable, unstable_useInteractableState, unstable_useInteractableVersions, unstable_useLiveCompletionAdapter, unstable_useMentionAdapter, unstable_useMessageStallDetection, unstable_useSlashCommandAdapter, unstable_useThreadMessageIds, unstable_useTriggerPopoverAriaProps, useTriggerPopoverRootContext as unstable_useTriggerPopoverRootContext, useTriggerPopoverRootContextOptional as unstable_useTriggerPopoverRootContextOptional, useTriggerPopoverScopeContext as unstable_useTriggerPopoverScopeContext, useTriggerPopoverScopeContextOptional as unstable_useTriggerPopoverScopeContextOptional, useTriggerPopoverTriggers as unstable_useTriggerPopoverTriggers, useTriggerPopoverTriggersOptional as unstable_useTriggerPopoverTriggersOptional, useAssistantContext, useAssistantDataUI, useAssistantFrameHost, useAssistantInstructions, useAssistantInteractable, useAssistantTool, useAssistantToolUI, useAssistantTransportRuntime, useAssistantTransportSendCommand, useAssistantTransportState, useAui, useAuiEvent, useAuiState, useAuiToolOverrides, useCloudThreadListAdapter, useCloudThreadListRuntime, useExternalMessageConverter, useExternalStoreRuntime, useExternalStoreSharedOptions, useInlineRender, useInteractableState, useLocalRuntime, useMessagePartData, useMessagePartFile, useMessagePartImage, useMessagePartReasoning, useMessagePartSource, useMessagePartText, useMessageQuote, useMessageTiming, useRemoteThreadListRuntime, useRuntimeAdapters, useScrollLock, useSmooth, useThreadViewport, useThreadViewportAutoScroll, useThreadViewportStore, useToolArgsStatus, useToolCallElapsed, useVoiceControls, useVoiceState, useVoiceVolume };
|
|
79
|
+
export { actionBarMore_d_exports as ActionBarMorePrimitive, actionBar_d_exports as ActionBarPrimitive, type AddToolResultOptions, type AppendMessage, type Assistant, type AssistantClient, AssistantCloud, type AssistantContextConfig, type AssistantDataUI, type AssistantDataUIProps, type AssistantEventCallback, type AssistantEventName, type AssistantEventPayload, type AssistantEventScope, type AssistantEventSelector, AssistantFrameHost, AssistantFrameProvider, type AssistantInteractableProps, assistantModal_d_exports as AssistantModalPrimitive, type AssistantRuntime, AssistantRuntimeProvider, type AssistantState, type AssistantTool, type AssistantToolProps, type AssistantToolUI, type AssistantToolUIProps, type AssistantTransportCommand, type AssistantTransportConnectionMetadata, type AssistantTransportProtocol, type Attachment, type AttachmentAdapter, attachment_d_exports as AttachmentPrimitive, type AttachmentRuntime, type AttachmentState, type AttachmentStatus, AuiConfig, AuiIf, AuiProvider, branchPicker_d_exports as BranchPickerPrimitive, ChainOfThoughtByIndicesProvider, ChainOfThoughtClient, chainOfThought_d_exports as ChainOfThoughtPrimitive, type ChatModelAdapter, type ChatModelRunOptions, type ChatModelRunResult, type ChatModelRunUpdate, CloudFileAttachmentAdapter, type CompleteAttachment, ComposerAttachmentByIndexProvider, composer_d_exports as ComposerPrimitive, type ComposerRuntime, type ComposerSendOptions, type ComposerState, CompositeAttachmentAdapter, type CreateAppendMessage, type CreateAttachment, type CreateResumeRunConfig, type CreateStartRunConfig, type CreateSuggestionAdapterOptions, type DataMessagePart, type DataMessagePartComponent, type DataMessagePartProps, DataRenderers, DevToolsHooks, DevToolsProviderApi, type DictationAdapter, type DictationState, type EditComposerRuntime, type EditComposerState, type EmptyMessagePartComponent, type EmptyMessagePartProps, type EnrichedPartState, error_d_exports as ErrorPrimitive, ExportedMessageRepository, type ExportedMessageRepositoryItem, type ExternalStoreAdapter, type ExternalStoreBranchChange, type ExternalStoreMessageConverter, type ExternalStoreSharedOptions, type ExternalStoreThreadData, type ExternalStoreThreadListAdapter, ExternalThread, type ExternalThreadBranchAdapter, type ExternalThreadMessage, type ExternalThreadProps, type ExternalThreadQueueAdapter, FRAME_MESSAGE_CHANNEL, type FeedbackAdapter, type FileMessagePart, type FileMessagePartComponent, type FileMessagePartProps, type FrameMessage, type FrameMessageType, type GenerativeUIComponentRegistry, type GenerativeUIMessagePart, type GenerativeUIMessagePartComponent, type GenerativeUIMessagePartProps, type GenerativeUINode, GenerativeUIRender, GenerativeUIRenderError, type GenerativeUIRenderProps, type GenerativeUISpec, type GenericThreadHistoryAdapter, type GroupByContext, internal_d_exports as INTERNAL, type ImageMessagePart, type ImageMessagePartComponent, type ImageMessagePartProps, InMemoryThreadList, InMemoryThreadListAdapter, type InMemoryThreadListProps, Interactables, type LanguageModelConfig, type LanguageModelV1CallSettings, type LocalRuntimeOptions, type LocalRuntimeOptionsBase, type McpAppBridgeHandlers, type McpAppDisplayMode, type McpAppHostContext, type McpAppHostInfo, type McpAppMetadata, McpAppRenderer, type McpAppRendererOptions, type McpAppResource, type McpAppResourceCSP, type McpAppResourceMeta, type McpAppResourceOutput, type McpAppSandboxConfig, type McpAppToolCallParams, type McpAppsHost, McpAppsRemoteHost, type McpAppsRemoteHostOptions, type McpToolkitDefinition, type McpToolkitEntry, type McpToolkitToolConfig, MessageAttachmentByIndexProvider, MessageByIndexProvider, type MessageFormatAdapter, type MessageFormatItem, type MessageFormatRepository, MessageNotSentError, messagePart_d_exports as MessagePartPrimitive, type MessagePartRuntime, type MessagePartState, type MessagePartStatus, type MessagePartStreamStatus, message_d_exports as MessagePrimitive, MessageProvider, type MessageQueueController, type MessageQueueDriver, type MessageRuntime, type MessageState, type MessageStatus, type MessageStorageEntry, type MessageTiming, type ModelContext, ModelContextClient, type ModelContextProvider, ModelContextRegistry, type ModelContextRegistryInstructionHandle, type ModelContextRegistryProviderHandle, type ModelContextRegistryToolHandle, PartByIndexProvider, type PartProviderMetadata, type PartState, type PendingAttachment, type ProviderToolConfig, type QueueItemMethods, queueItem_d_exports as QueueItemPrimitive, type QueueItemState, type QuoteInfo, type QuoteMessagePartComponent, type QuoteMessagePartProps, ReadonlyThreadProvider, type RealtimeVoiceAdapter, type ReasoningGroupComponent, type ReasoningGroupProps, type ReasoningMessagePart, type ReasoningMessagePartComponent, type ReasoningMessagePartProps, RemoteThreadList, type RemoteThreadListAdapter, type RemoteThreadListProps, type RemoteThreadListProviderComponent, type RespondToToolApprovalOptions, RuntimeAdapterProvider, type RuntimeAdapters, selectionToolbar_d_exports as SelectionToolbarPrimitive, type SendCommandsRequestBody, type SerializedModelContext, type SerializedTool, SimpleImageAttachmentAdapter, SimpleTextAttachmentAdapter, SingleThreadList, type SmoothOptions, type SourceMessagePart, type SourceMessagePartComponent, type SourceMessagePartProps, type SourceProviderMetadata, type SpeechSynthesisAdapter, type SubmitFeedbackOptions, type SuggestionAdapter, type SuggestionAdapterGenerateOptions, SuggestionByIndexProvider, type SuggestionConfig, suggestion_d_exports as SuggestionPrimitive, Suggestions, type TextMessagePart, type TextMessagePartComponent, type TextMessagePartProps, TextMessagePartProvider, type ThreadAssistantMessage, type ThreadAssistantMessagePart, type ThreadComposerRuntime, type ThreadComposerState, type ThreadHistoryAdapter, ThreadListItemByIndexProvider, threadListItemMore_d_exports as ThreadListItemMorePrimitive, threadListItem_d_exports as ThreadListItemPrimitive, type ThreadListItemRuntime, ThreadListItemRuntimeProvider, type ThreadListItemState, type ThreadListItemStatus, threadList_d_exports as ThreadListPrimitive, type ThreadListRuntime, type ThreadListState, type ThreadMessage, type ThreadMessageLike, thread_d_exports as ThreadPrimitive, type ThreadRuntime, type ThreadState, type ThreadSuggestion, type ThreadSystemMessage, type ThreadUserMessage, type ThreadUserMessagePart, type ThreadViewportState, type Tool, type ToolApprovalOption, type ToolApprovalOptionKind, type ToolApprovalResponse, type ToolArgsStatus, type ToolCallMessagePart, type ToolCallMessagePartComponent, type ToolCallMessagePartMcpMetadata, type ToolCallMessagePartProps, type ToolCallMessagePartStatus, type ToolCallText, type ToolCallTiming, type ToolDefinition, type ToolExecutionStatus, type ToolModelContentPart, type Toolkit, type ToolkitDefinition, type ToolkitDefinitionEntry, Tools, type Unstable_AudioMessagePart, type Unstable_AudioMessagePartComponent, type Unstable_AudioMessagePartProps, type Unstable_ComposerInput, type Unstable_ComposerInputHistory, type Unstable_DirectiveFormatter, type Unstable_DirectiveSegment, type Unstable_IconComponent, type Unstable_InferInteractableState, type Unstable_InteractableConfig, type Unstable_InteractableDefinition, type Unstable_InteractablePersistedState, type Unstable_InteractablePersistenceAdapter, type Unstable_InteractablePersistenceStatus, type Unstable_InteractableRegistration, type Unstable_InteractableSnapshotEntry, type Unstable_InteractableStateSchema, type Unstable_InteractableToolConfig, type Unstable_InteractableToolRenderProps, type Unstable_InteractableVersion, type Unstable_InteractableVersionInfo, type Unstable_InteractablesClientSchema, type Unstable_InteractablesConfig, type Unstable_InteractablesMethods, type Unstable_InteractablesState, type Unstable_Mention, type Unstable_MentionCategory, type Unstable_MentionDirective, type Unstable_MessageStallDetection, type Unstable_MessageStallDetectionOptions, type Unstable_ModelContextToolsOptions, type RegisteredTrigger as Unstable_RegisteredTrigger, type Unstable_SlashCommand, type Unstable_SlashCommandAction, type TriggerBehavior as Unstable_TriggerBehavior, type Unstable_TriggerItem, type TriggerMatch as Unstable_TriggerMatch, type TriggerMatcher as Unstable_TriggerMatcher, type Unstable_TriggerPopoverAriaProps, type Unstable_UseComposerInputOptions, type Unstable_UseLiveCompletionAdapterOptions, type Unstable_UseMentionAdapterOptions, type Unstable_UseSlashCommandAdapterOptions, type Unsubscribe, type VoiceSessionControls, type VoiceSessionHelpers, type VoiceSessionState, WebSpeechDictationAdapter, WebSpeechSynthesisAdapter, bindExternalStoreMessage, createMessageQueue, createSuggestionAdapter, createVoiceSession, defineMcpToolkit, defineToolkit, externalTool, fromThreadMessageLike, generateId, getExternalStoreMessages, getMcpAppFromToolPart, groupPartByType, hitl, hitlTool, humanTool, isMessageNotSentError, makeAssistantDataUI, makeAssistantTool, makeAssistantToolUI, makeAssistantVisible, mergeModelContexts, pickExternalStoreSharedOptions, providerTool, stubTool, tool, unstable_Interactables, convertExternalMessages as unstable_convertExternalMessages, createMessageConverter as unstable_createMessageConverter, unstable_defaultDirectiveFormatter, unstable_formatInteractableSnapshot, unstable_getInteractableSnapshots, unstable_getInteractableVersions, unstable_interactableTool, unstable_useComposerInput, unstable_useComposerInputHistory, unstable_useInteractable, unstable_useInteractableState, unstable_useInteractableVersions, unstable_useLiveCompletionAdapter, unstable_useMentionAdapter, unstable_useMessageStallDetection, unstable_useSlashCommandAdapter, unstable_useThreadMessageIds, unstable_useTriggerPopoverAriaProps, useTriggerPopoverRootContext as unstable_useTriggerPopoverRootContext, useTriggerPopoverRootContextOptional as unstable_useTriggerPopoverRootContextOptional, useTriggerPopoverScopeContext as unstable_useTriggerPopoverScopeContext, useTriggerPopoverScopeContextOptional as unstable_useTriggerPopoverScopeContextOptional, useTriggerPopoverTriggers as unstable_useTriggerPopoverTriggers, useTriggerPopoverTriggersOptional as unstable_useTriggerPopoverTriggersOptional, useAssistantContext, useAssistantDataUI, useAssistantFrameHost, useAssistantInstructions, useAssistantInteractable, useAssistantTool, useAssistantToolUI, useAssistantTransportRuntime, useAssistantTransportSendCommand, useAssistantTransportState, useAui, useAuiEvent, useAuiState, useAuiToolOverrides, useCloudThreadListAdapter, useCloudThreadListRuntime, useExternalMessageConverter, useExternalStoreRuntime, useExternalStoreSharedOptions, useInlineRender, useInteractableState, useLocalRuntime, useMessagePartData, useMessagePartFile, useMessagePartImage, useMessagePartReasoning, useMessagePartSource, useMessagePartText, useMessageQuote, useMessageTiming, useRemoteThreadListRuntime, useRuntimeAdapters, useScrollLock, useSmooth, useThreadViewport, useThreadViewportAutoScroll, useThreadViewportStore, useToolArgsStatus, useToolCallElapsed, useVoiceControls, useVoiceState, useVoiceVolume };
|
package/dist/index.js
CHANGED
|
@@ -64,6 +64,6 @@ import { McpAppsRemoteHost } from "./mcp-apps/McpAppsRemoteHost.js";
|
|
|
64
64
|
import { DataRenderers, GenerativeUIRender, GenerativeUIRenderError, Interactables, RuntimeAdapterProvider, Tools, defineMcpToolkit, defineToolkit, externalTool, groupPartByType, hitl, hitlTool, humanTool, makeAssistantDataUI, makeAssistantTool, makeAssistantToolUI, providerTool, stubTool, unstable_Interactables, unstable_interactableTool, unstable_useInteractable, unstable_useInteractableState, unstable_useInteractableVersions, unstable_useThreadMessageIds, useAssistantContext, useAssistantDataUI, useAssistantInstructions, useAssistantInteractable, useAssistantTool, useAssistantToolUI, useAuiToolOverrides, useCloudThreadListRuntime, useExternalStoreSharedOptions, useInlineRender, useInteractableState, useRuntimeAdapters, useToolArgsStatus, useVoiceControls, useVoiceState, useVoiceVolume } from "@assistant-ui/core/react";
|
|
65
65
|
import { AuiConfig, AuiIf, AuiProvider, useAui, useAuiEvent, useAuiState } from "@assistant-ui/store";
|
|
66
66
|
import { AssistantCloud } from "assistant-cloud";
|
|
67
|
-
import { AssistantFrameHost, AssistantFrameProvider, CompositeAttachmentAdapter, ExportedMessageRepository, FRAME_MESSAGE_CHANNEL, InMemoryThreadListAdapter, MessageNotSentError, ModelContextRegistry, SimpleImageAttachmentAdapter, SimpleTextAttachmentAdapter, WebSpeechDictationAdapter, WebSpeechSynthesisAdapter, bindExternalStoreMessage, createMessageQueue, createVoiceSession, fromThreadMessageLike, generateId, getExternalStoreMessages, isMessageNotSentError, mergeModelContexts, pickExternalStoreSharedOptions, tool, unstable_defaultDirectiveFormatter, unstable_formatInteractableSnapshot, unstable_getInteractableSnapshots, unstable_getInteractableVersions } from "@assistant-ui/core";
|
|
67
|
+
import { AssistantFrameHost, AssistantFrameProvider, CompositeAttachmentAdapter, ExportedMessageRepository, FRAME_MESSAGE_CHANNEL, InMemoryThreadListAdapter, MessageNotSentError, ModelContextRegistry, SimpleImageAttachmentAdapter, SimpleTextAttachmentAdapter, WebSpeechDictationAdapter, WebSpeechSynthesisAdapter, bindExternalStoreMessage, createMessageQueue, createSuggestionAdapter, createVoiceSession, fromThreadMessageLike, generateId, getExternalStoreMessages, isMessageNotSentError, mergeModelContexts, pickExternalStoreSharedOptions, tool, unstable_defaultDirectiveFormatter, unstable_formatInteractableSnapshot, unstable_getInteractableSnapshots, unstable_getInteractableVersions } from "@assistant-ui/core";
|
|
68
68
|
import { ChainOfThoughtClient, ExternalThread, InMemoryThreadList, ModelContext as ModelContextClient, RemoteThreadList, SingleThreadList, Suggestions } from "@assistant-ui/core/store";
|
|
69
|
-
export { actionBarMore_exports as ActionBarMorePrimitive, actionBar_exports as ActionBarPrimitive, AssistantCloud, AssistantFrameHost, AssistantFrameProvider, assistantModal_exports as AssistantModalPrimitive, AssistantRuntimeProvider, attachment_exports as AttachmentPrimitive, AuiConfig, AuiIf, AuiProvider, branchPicker_exports as BranchPickerPrimitive, ChainOfThoughtByIndicesProvider, ChainOfThoughtClient, chainOfThought_exports as ChainOfThoughtPrimitive, CloudFileAttachmentAdapter, ComposerAttachmentByIndexProvider, composer_exports as ComposerPrimitive, CompositeAttachmentAdapter, DataRenderers, DevToolsHooks, DevToolsProviderApi, error_exports as ErrorPrimitive, ExportedMessageRepository, ExternalThread, FRAME_MESSAGE_CHANNEL, GenerativeUIRender, GenerativeUIRenderError, internal_exports as INTERNAL, InMemoryThreadList, InMemoryThreadListAdapter, Interactables, McpAppRenderer, McpAppsRemoteHost, MessageAttachmentByIndexProvider, MessageByIndexProvider, MessageNotSentError, messagePart_exports as MessagePartPrimitive, message_exports as MessagePrimitive, MessageProvider, ModelContextClient, ModelContextRegistry, PartByIndexProvider, queueItem_exports as QueueItemPrimitive, ReadonlyThreadProvider, RemoteThreadList, RuntimeAdapterProvider, selectionToolbar_exports as SelectionToolbarPrimitive, SimpleImageAttachmentAdapter, SimpleTextAttachmentAdapter, SingleThreadList, SuggestionByIndexProvider, suggestion_exports as SuggestionPrimitive, Suggestions, TextMessagePartProvider, ThreadListItemByIndexProvider, threadListItemMore_exports as ThreadListItemMorePrimitive, threadListItem_exports as ThreadListItemPrimitive, ThreadListItemRuntimeProvider, threadList_exports as ThreadListPrimitive, thread_exports as ThreadPrimitive, Tools, WebSpeechDictationAdapter, WebSpeechSynthesisAdapter, bindExternalStoreMessage, createMessageQueue, createVoiceSession, defineMcpToolkit, defineToolkit, externalTool, fromThreadMessageLike, generateId, getExternalStoreMessages, getMcpAppFromToolPart, groupPartByType, hitl, hitlTool, humanTool, isMessageNotSentError, makeAssistantDataUI, makeAssistantTool, makeAssistantToolUI, makeAssistantVisible, mergeModelContexts, pickExternalStoreSharedOptions, providerTool, stubTool, tool, unstable_Interactables, convertExternalMessages as unstable_convertExternalMessages, createMessageConverter as unstable_createMessageConverter, unstable_defaultDirectiveFormatter, unstable_formatInteractableSnapshot, unstable_getInteractableSnapshots, unstable_getInteractableVersions, unstable_interactableTool, unstable_useComposerInput, unstable_useComposerInputHistory, unstable_useInteractable, unstable_useInteractableState, unstable_useInteractableVersions, unstable_useLiveCompletionAdapter, unstable_useMentionAdapter, unstable_useMessageStallDetection, unstable_useSlashCommandAdapter, unstable_useThreadMessageIds, unstable_useTriggerPopoverAriaProps, useTriggerPopoverRootContext as unstable_useTriggerPopoverRootContext, useTriggerPopoverRootContextOptional as unstable_useTriggerPopoverRootContextOptional, useTriggerPopoverScopeContext as unstable_useTriggerPopoverScopeContext, useTriggerPopoverScopeContextOptional as unstable_useTriggerPopoverScopeContextOptional, useTriggerPopoverTriggers as unstable_useTriggerPopoverTriggers, useTriggerPopoverTriggersOptional as unstable_useTriggerPopoverTriggersOptional, useAssistantContext, useAssistantDataUI, useAssistantFrameHost, useAssistantInstructions, useAssistantInteractable, useAssistantTool, useAssistantToolUI, useAssistantTransportRuntime, useAssistantTransportSendCommand, useAssistantTransportState, useAui, useAuiEvent, useAuiState, useAuiToolOverrides, useCloudThreadListAdapter, useCloudThreadListRuntime, useExternalMessageConverter, useExternalStoreRuntime, useExternalStoreSharedOptions, useInlineRender, useInteractableState, useLocalRuntime, useMessagePartData, useMessagePartFile, useMessagePartImage, useMessagePartReasoning, useMessagePartSource, useMessagePartText, useMessageQuote, useMessageTiming, useRemoteThreadListRuntime, useRuntimeAdapters, useScrollLock, useSmooth, useThreadViewport, useThreadViewportAutoScroll, useThreadViewportStore, useToolArgsStatus, useToolCallElapsed, useVoiceControls, useVoiceState, useVoiceVolume };
|
|
69
|
+
export { actionBarMore_exports as ActionBarMorePrimitive, actionBar_exports as ActionBarPrimitive, AssistantCloud, AssistantFrameHost, AssistantFrameProvider, assistantModal_exports as AssistantModalPrimitive, AssistantRuntimeProvider, attachment_exports as AttachmentPrimitive, AuiConfig, AuiIf, AuiProvider, branchPicker_exports as BranchPickerPrimitive, ChainOfThoughtByIndicesProvider, ChainOfThoughtClient, chainOfThought_exports as ChainOfThoughtPrimitive, CloudFileAttachmentAdapter, ComposerAttachmentByIndexProvider, composer_exports as ComposerPrimitive, CompositeAttachmentAdapter, DataRenderers, DevToolsHooks, DevToolsProviderApi, error_exports as ErrorPrimitive, ExportedMessageRepository, ExternalThread, FRAME_MESSAGE_CHANNEL, GenerativeUIRender, GenerativeUIRenderError, internal_exports as INTERNAL, InMemoryThreadList, InMemoryThreadListAdapter, Interactables, McpAppRenderer, McpAppsRemoteHost, MessageAttachmentByIndexProvider, MessageByIndexProvider, MessageNotSentError, messagePart_exports as MessagePartPrimitive, message_exports as MessagePrimitive, MessageProvider, ModelContextClient, ModelContextRegistry, PartByIndexProvider, queueItem_exports as QueueItemPrimitive, ReadonlyThreadProvider, RemoteThreadList, RuntimeAdapterProvider, selectionToolbar_exports as SelectionToolbarPrimitive, SimpleImageAttachmentAdapter, SimpleTextAttachmentAdapter, SingleThreadList, SuggestionByIndexProvider, suggestion_exports as SuggestionPrimitive, Suggestions, TextMessagePartProvider, ThreadListItemByIndexProvider, threadListItemMore_exports as ThreadListItemMorePrimitive, threadListItem_exports as ThreadListItemPrimitive, ThreadListItemRuntimeProvider, threadList_exports as ThreadListPrimitive, thread_exports as ThreadPrimitive, Tools, WebSpeechDictationAdapter, WebSpeechSynthesisAdapter, bindExternalStoreMessage, createMessageQueue, createSuggestionAdapter, createVoiceSession, defineMcpToolkit, defineToolkit, externalTool, fromThreadMessageLike, generateId, getExternalStoreMessages, getMcpAppFromToolPart, groupPartByType, hitl, hitlTool, humanTool, isMessageNotSentError, makeAssistantDataUI, makeAssistantTool, makeAssistantToolUI, makeAssistantVisible, mergeModelContexts, pickExternalStoreSharedOptions, providerTool, stubTool, tool, unstable_Interactables, convertExternalMessages as unstable_convertExternalMessages, createMessageConverter as unstable_createMessageConverter, unstable_defaultDirectiveFormatter, unstable_formatInteractableSnapshot, unstable_getInteractableSnapshots, unstable_getInteractableVersions, unstable_interactableTool, unstable_useComposerInput, unstable_useComposerInputHistory, unstable_useInteractable, unstable_useInteractableState, unstable_useInteractableVersions, unstable_useLiveCompletionAdapter, unstable_useMentionAdapter, unstable_useMessageStallDetection, unstable_useSlashCommandAdapter, unstable_useThreadMessageIds, unstable_useTriggerPopoverAriaProps, useTriggerPopoverRootContext as unstable_useTriggerPopoverRootContext, useTriggerPopoverRootContextOptional as unstable_useTriggerPopoverRootContextOptional, useTriggerPopoverScopeContext as unstable_useTriggerPopoverScopeContext, useTriggerPopoverScopeContextOptional as unstable_useTriggerPopoverScopeContextOptional, useTriggerPopoverTriggers as unstable_useTriggerPopoverTriggers, useTriggerPopoverTriggersOptional as unstable_useTriggerPopoverTriggersOptional, useAssistantContext, useAssistantDataUI, useAssistantFrameHost, useAssistantInstructions, useAssistantInteractable, useAssistantTool, useAssistantToolUI, useAssistantTransportRuntime, useAssistantTransportSendCommand, useAssistantTransportState, useAui, useAuiEvent, useAuiState, useAuiToolOverrides, useCloudThreadListAdapter, useCloudThreadListRuntime, useExternalMessageConverter, useExternalStoreRuntime, useExternalStoreSharedOptions, useInlineRender, useInteractableState, useLocalRuntime, useMessagePartData, useMessagePartFile, useMessagePartImage, useMessagePartReasoning, useMessagePartSource, useMessagePartText, useMessageQuote, useMessageTiming, useRemoteThreadListRuntime, useRuntimeAdapters, useScrollLock, useSmooth, useThreadViewport, useThreadViewportAutoScroll, useThreadViewportStore, useToolArgsStatus, useToolCallElapsed, useVoiceControls, useVoiceState, useVoiceVolume };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { McpAppHostContext, McpAppHostInfo, McpAppSandboxConfig, McpAppsHost } from "./types.js";
|
|
1
|
+
import { McpAppBridgeHandlers, McpAppHostContext, McpAppHostInfo, McpAppSandboxConfig, McpAppsHost } from "./types.js";
|
|
2
2
|
import { ToolCallMessagePartComponent } from "@assistant-ui/core/react";
|
|
3
3
|
import { ReactNode } from "react";
|
|
4
4
|
import { ResourceElement } from "@assistant-ui/tap";
|
|
@@ -21,6 +21,11 @@ type McpAppRendererOptions = {
|
|
|
21
21
|
hostInfo?: McpAppHostInfo;
|
|
22
22
|
/** Delivered to the widget on initialize and pushed via `notifications/host_context/changed` on change. */
|
|
23
23
|
hostContext?: McpAppHostContext;
|
|
24
|
+
/**
|
|
25
|
+
* Optional widget interaction and lifecycle handlers. Data-plane handlers
|
|
26
|
+
* (`callTool`, `readResource`, `listResources`) always use `host`.
|
|
27
|
+
*/
|
|
28
|
+
handlers?: Omit<McpAppBridgeHandlers, "callTool" | "readResource" | "listResources">;
|
|
24
29
|
/** Rendered when no MCP app is on the part, or while load is in flight / failed (unless overridden). */
|
|
25
30
|
fallback?: ReactNode;
|
|
26
31
|
/** Rendered while the resource is loading. Defaults to `fallback`. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"McpAppRenderer.d.ts","names":[],"sources":["../../src/mcp-apps/McpAppRenderer.tsx"],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"McpAppRenderer.d.ts","names":[],"sources":["../../src/mcp-apps/McpAppRenderer.tsx"],"mappings":";;;;;KAgCY;;;;;;EAMV,MAAM,gBAAgB;;EAEtB,UAAU;;;;;EAKV;;EAEA,WAAW;;EAEX,cAAc;;;;;EAKd,WAAW,KACT;;EAIF,WAAW;;EAEX,kBAAkB;;EAElB,gBAAgB,cAAc,OAAO,UAAU;;cAyNpC,4CAAc;WA5BL,QAAA;IA4BmC,SAAA"}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { McpAppFrame } from "./app-frame.js";
|
|
3
3
|
import { getMcpAppFromToolPart } from "./utils.js";
|
|
4
4
|
import { useAui } from "@assistant-ui/store";
|
|
5
|
-
import { useEffect, useMemo, useRef, useState } from "@assistant-ui/tap/react-shim";
|
|
5
|
+
import { useEffect, useLayoutEffect, useMemo, useRef, useState } from "@assistant-ui/tap/react-shim";
|
|
6
6
|
import { create } from "zustand";
|
|
7
7
|
import { Fragment, jsx } from "react/jsx-runtime";
|
|
8
8
|
import { isRecord } from "@assistant-ui/core/internal";
|
|
@@ -28,14 +28,15 @@ function InlineRenderer({ part, useHostStore, optionsRef }) {
|
|
|
28
28
|
const aui = useAui();
|
|
29
29
|
const app = getMcpAppFromToolPart(part);
|
|
30
30
|
const cachedAppRef = useRef(void 0);
|
|
31
|
-
|
|
31
|
+
useLayoutEffect(() => {
|
|
32
|
+
if (app != null) cachedAppRef.current = app;
|
|
33
|
+
}, [app]);
|
|
32
34
|
const appForRender = app ?? cachedAppRef.current;
|
|
33
35
|
const [loadedResource, setLoadedResource] = useState();
|
|
34
36
|
const host = useHostStore((state) => state.host);
|
|
35
37
|
const resourceUri = appForRender?.resourceUri;
|
|
36
38
|
const serverId = appForRender?.serverId;
|
|
37
|
-
const
|
|
38
|
-
serverIdRef.current = serverId;
|
|
39
|
+
const callerHandlers = opts.handlers;
|
|
39
40
|
useEffect(() => {
|
|
40
41
|
if (resourceUri == null) return;
|
|
41
42
|
let cancelled = false;
|
|
@@ -69,8 +70,9 @@ function InlineRenderer({ part, useHostStore, optionsRef }) {
|
|
|
69
70
|
serverId
|
|
70
71
|
]);
|
|
71
72
|
const bridgeHandlers = useMemo(() => ({
|
|
72
|
-
|
|
73
|
-
|
|
73
|
+
...callerHandlers,
|
|
74
|
+
openLink: callerHandlers?.openLink ?? defaultOpenLink,
|
|
75
|
+
sendMessage: callerHandlers?.sendMessage ?? ((params) => {
|
|
74
76
|
const text = extractSendMessageText(params);
|
|
75
77
|
if (!text) return {
|
|
76
78
|
ok: false,
|
|
@@ -81,23 +83,28 @@ function InlineRenderer({ part, useHostStore, optionsRef }) {
|
|
|
81
83
|
text
|
|
82
84
|
}] });
|
|
83
85
|
return { ok: true };
|
|
84
|
-
},
|
|
86
|
+
}),
|
|
85
87
|
callTool: (params_0) => useHostStore.getState().host.callTool({
|
|
86
88
|
...params_0,
|
|
87
|
-
...
|
|
89
|
+
...serverId ? { serverId } : {}
|
|
88
90
|
}),
|
|
89
91
|
readResource: (params_1) => useHostStore.getState().host.readResource({
|
|
90
92
|
...params_1,
|
|
91
|
-
...
|
|
93
|
+
...serverId ? { serverId } : {}
|
|
92
94
|
}),
|
|
93
95
|
listResources: (params_2) => {
|
|
94
|
-
if (!
|
|
96
|
+
if (!serverId) return useHostStore.getState().host.listResources(params_2);
|
|
95
97
|
return useHostStore.getState().host.listResources({
|
|
96
98
|
...isRecord(params_2) ? params_2 : {},
|
|
97
|
-
serverId
|
|
99
|
+
serverId
|
|
98
100
|
});
|
|
99
101
|
}
|
|
100
|
-
}), [
|
|
102
|
+
}), [
|
|
103
|
+
aui,
|
|
104
|
+
callerHandlers,
|
|
105
|
+
serverId,
|
|
106
|
+
useHostStore
|
|
107
|
+
]);
|
|
101
108
|
const loadedResourceForApp = loadedResource?.host === host && loadedResource?.resourceUri === appForRender?.resourceUri && loadedResource?.serverId === appForRender?.serverId ? loadedResource : void 0;
|
|
102
109
|
const appResource = loadedResourceForApp?.resource;
|
|
103
110
|
const error_0 = loadedResourceForApp?.error;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"McpAppRenderer.js","names":["useEffect","useMemo","useRef","useState","MutableRefObject","ReactNode","McpAppMetadata","ToolCallMessagePartComponent","ToolCallMessagePartProps","useAui","create","StoreApi","UseBoundStore","useResource","resource","ResourceElement","McpAppFrame","McpAppBridgeHandlers","McpAppHostContext","McpAppHostInfo","McpAppResource","McpAppSandboxConfig","McpAppsHost","getMcpAppFromToolPart","isRecord","McpAppRendererOptions","host","sandbox","maxHeight","hostInfo","hostContext","fallback","loadingFallback","errorFallback","error","Error","LoadedResourceState","resourceUri","serverId","UseHostStore","getInput","part","status","type","argsText","args","undefined","defaultOpenLink","url","window","open","extractSendMessageText","params","obj","Record","InlineRenderer","useHostStore","optionsRef","opts","current","aui","app","cachedAppRef","appForRender","loadedResource","setLoadedResource","state","serverIdRef","cancelled","targetHost","targetUri","targetServerId","loadResource","uri","then","res","catch","String","bridgeHandlers","openLink","sendMessage","text","ok","reason","thread","append","content","callTool","getState","readResource","listResources","loadedResourceForApp","appResource","result","useMcpAppRenderer","options","render","setState","Render","props","displayName","McpAppRenderer"],"sources":["../../src/mcp-apps/McpAppRenderer.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n useEffect,\n useMemo,\n useRef,\n useState,\n type MutableRefObject,\n type ReactNode,\n} from \"react\";\nimport type { McpAppMetadata } from \"@assistant-ui/core\";\nimport type {\n ToolCallMessagePartComponent,\n ToolCallMessagePartProps,\n} from \"@assistant-ui/core/react\";\nimport { useAui } from \"@assistant-ui/store\";\nimport { create, type StoreApi, type UseBoundStore } from \"zustand\";\n\nimport { useResource, resource, type ResourceElement } from \"@assistant-ui/tap\";\nimport { McpAppFrame } from \"./app-frame\";\nimport type {\n McpAppBridgeHandlers,\n McpAppHostContext,\n McpAppHostInfo,\n McpAppResource,\n McpAppSandboxConfig,\n McpAppsHost,\n} from \"./types\";\nimport { getMcpAppFromToolPart } from \"./utils\";\nimport { isRecord } from \"@assistant-ui/core/internal\";\n\nexport type McpAppRendererOptions = {\n /**\n * Provides the data-plane operations the widget can request\n * (`loadResource`, `callTool`, `readResource`, `listResources`). Use\n * `McpAppsRemoteHost({ url })` for the default HTTP-route convention.\n */\n host: ResourceElement<McpAppsHost>;\n /** Sandbox + container styling. Passes through to SafeContentFrame. */\n sandbox?: McpAppSandboxConfig;\n /**\n * Upper bound (in pixels) applied to the widget-driven auto-resize height.\n * Defaults to 800.\n */\n maxHeight?: number;\n /** Identifies the host to the widget in the `ui/initialize` response. */\n hostInfo?: McpAppHostInfo;\n /** Delivered to the widget on initialize and pushed via `notifications/host_context/changed` on change. */\n hostContext?: McpAppHostContext;\n /** Rendered when no MCP app is on the part, or while load is in flight / failed (unless overridden). */\n fallback?: ReactNode;\n /** Rendered while the resource is loading. Defaults to `fallback`. */\n loadingFallback?: ReactNode;\n /** Rendered when the resource load rejects. Defaults to `fallback`. */\n errorFallback?: ReactNode | ((error: Error) => ReactNode);\n};\n\ntype LoadedResourceState = {\n host: McpAppsHost;\n resourceUri: string;\n serverId?: string;\n resource?: McpAppResource;\n error?: Error;\n};\n\ntype UseHostStore = UseBoundStore<StoreApi<{ host: McpAppsHost }>>;\n\nfunction getInput(part: {\n status: { type: string };\n argsText: string;\n args: unknown;\n}): unknown {\n if (\n part.status.type === \"running\" &&\n (part.argsText === \"\" || part.argsText === \"{}\")\n ) {\n return undefined;\n }\n return part.args;\n}\n\nconst defaultOpenLink = ({ url }: { url: string }) => {\n window.open(url, \"_blank\", \"noopener,noreferrer\");\n};\n\nfunction extractSendMessageText(params: unknown): string | undefined {\n if (typeof params === \"string\") return params;\n if (!params || typeof params !== \"object\") return undefined;\n const obj = params as Record<string, unknown>;\n if (typeof obj[\"prompt\"] === \"string\") return obj[\"prompt\"];\n if (typeof obj[\"text\"] === \"string\") return obj[\"text\"];\n if (typeof obj[\"message\"] === \"string\") return obj[\"message\"];\n return undefined;\n}\n\nfunction InlineRenderer({\n part,\n useHostStore,\n optionsRef,\n}: {\n part: ToolCallMessagePartProps;\n useHostStore: UseHostStore;\n optionsRef: MutableRefObject<McpAppRendererOptions>;\n}) {\n const opts = optionsRef.current;\n const aui = useAui();\n const app = getMcpAppFromToolPart(part);\n const cachedAppRef = useRef<McpAppMetadata | undefined>(undefined);\n if (\n app != null &&\n (cachedAppRef.current?.resourceUri !== app.resourceUri ||\n cachedAppRef.current?.serverId !== app.serverId)\n ) {\n cachedAppRef.current = app;\n }\n const appForRender = app ?? cachedAppRef.current;\n\n const [loadedResource, setLoadedResource] = useState<LoadedResourceState>();\n\n const host = useHostStore((state) => state.host);\n const resourceUri = appForRender?.resourceUri;\n const serverId = appForRender?.serverId;\n const serverIdRef = useRef<string | undefined>(undefined);\n serverIdRef.current = serverId;\n useEffect(() => {\n if (resourceUri == null) return;\n let cancelled = false;\n const targetHost = host;\n const targetUri = resourceUri;\n const targetServerId = serverId;\n\n targetHost\n .loadResource({\n uri: targetUri,\n ...(targetServerId ? { serverId: targetServerId } : {}),\n })\n .then((res) => {\n if (!cancelled)\n setLoadedResource({\n host: targetHost,\n resourceUri: targetUri,\n ...(targetServerId !== undefined\n ? { serverId: targetServerId }\n : {}),\n resource: res,\n });\n })\n .catch((error: unknown) => {\n if (!cancelled) {\n setLoadedResource({\n host: targetHost,\n resourceUri: targetUri,\n ...(targetServerId !== undefined\n ? { serverId: targetServerId }\n : {}),\n error: error instanceof Error ? error : new Error(String(error)),\n });\n }\n });\n\n return () => {\n cancelled = true;\n };\n }, [host, resourceUri, serverId]);\n\n const bridgeHandlers = useMemo<McpAppBridgeHandlers>(\n () => ({\n openLink: defaultOpenLink,\n sendMessage: (params) => {\n const text = extractSendMessageText(params);\n if (!text) return { ok: false, reason: \"unrecognised params shape\" };\n aui.thread.append({ content: [{ type: \"text\", text }] });\n return { ok: true };\n },\n callTool: (params) =>\n useHostStore.getState().host.callTool({\n ...params,\n ...(serverIdRef.current ? { serverId: serverIdRef.current } : {}),\n }),\n readResource: (params) =>\n useHostStore.getState().host.readResource({\n ...params,\n ...(serverIdRef.current ? { serverId: serverIdRef.current } : {}),\n }),\n listResources: (params) => {\n if (!serverIdRef.current) {\n return useHostStore.getState().host.listResources(params);\n }\n return useHostStore.getState().host.listResources({\n ...(isRecord(params) ? params : {}),\n serverId: serverIdRef.current,\n });\n },\n }),\n [aui, useHostStore],\n );\n\n const loadedResourceForApp =\n loadedResource?.host === host &&\n loadedResource?.resourceUri === appForRender?.resourceUri &&\n loadedResource?.serverId === appForRender?.serverId\n ? loadedResource\n : undefined;\n const appResource = loadedResourceForApp?.resource;\n const error = loadedResourceForApp?.error;\n\n const fallback = opts.fallback ?? null;\n if (appForRender == null) {\n return <>{fallback}</>;\n }\n if (error != null) {\n const errorFallback = opts.errorFallback;\n if (errorFallback === undefined) return <>{fallback}</>;\n if (typeof errorFallback === \"function\") return <>{errorFallback(error)}</>;\n return <>{errorFallback}</>;\n }\n if (appResource == null) {\n return <>{opts.loadingFallback ?? fallback}</>;\n }\n\n return (\n <McpAppFrame\n app={appForRender}\n resource={appResource}\n input={getInput(part)}\n output={part.result}\n sandbox={opts.sandbox}\n handlers={bridgeHandlers}\n hostInfo={opts.hostInfo}\n hostContext={opts.hostContext}\n maxHeight={opts.maxHeight}\n />\n );\n}\n\n/**\n * Creates a tool-call renderer for MCP Apps embedded in assistant messages.\n *\n * Compose this into the `Tools` resource through its `mcpApp` option. When a\n * tool-call part carries `mcp.app` metadata for a `ui://` resource, the\n * renderer loads that resource from the configured host and displays it in a\n * sandboxed frame.\n */\nconst useMcpAppRenderer = (\n options: McpAppRendererOptions,\n): { readonly render: ToolCallMessagePartComponent } => {\n const host = useResource(options.host);\n\n const optionsRef = useRef<McpAppRendererOptions>(options);\n optionsRef.current = options;\n\n const [useHostStore] = useState(() =>\n create<{ host: McpAppsHost }>(() => ({ host })),\n );\n useEffect(() => {\n useHostStore.setState({ host });\n }, [host, useHostStore]);\n\n const render = useMemo((): ToolCallMessagePartComponent => {\n const Render: ToolCallMessagePartComponent = (props) => (\n <InlineRenderer\n part={props}\n useHostStore={useHostStore}\n optionsRef={optionsRef}\n />\n );\n Render.displayName = \"McpAppRenderer\";\n return Render;\n }, [useHostStore]);\n\n return { render };\n};\n\nexport const McpAppRenderer = resource(useMcpAppRenderer);\n"],"mappings":";;;;;;;;;;AAmEA,SAASwC,SAASC,MAIN;CACV,IACEA,KAAKC,OAAOC,SAAS,cACpBF,KAAKG,aAAa,MAAMH,KAAKG,aAAa,OAE3C;CAEF,OAAOH,KAAKI;AACd;AAEA,MAAME,mBAAmB,EAAEC,UAA2B;CACpDC,OAAOC,KAAKF,KAAK,UAAU,qBAAqB;AAClD;AAEA,SAASG,uBAAuBC,QAAqC;CACnE,IAAI,OAAOA,WAAW,UAAU,OAAOA;CACvC,IAAI,CAACA,UAAU,OAAOA,WAAW,UAAU,OAAON,KAAAA;CAClD,MAAMO,MAAMD;CACZ,IAAI,OAAOC,IAAI,cAAc,UAAU,OAAOA,IAAI;CAClD,IAAI,OAAOA,IAAI,YAAY,UAAU,OAAOA,IAAI;CAChD,IAAI,OAAOA,IAAI,eAAe,UAAU,OAAOA,IAAI;AAErD;AAEA,SAASE,eAAe,EACtBd,MACAe,cACAC,cAKC;CACD,MAAMC,OAAOD,WAAWE;CACxB,MAAMC,MAAMnD,OAAO;CACnB,MAAMoD,MAAMtC,sBAAsBkB,IAAI;CACtC,MAAMqB,eAAe5D,OAAmC4C,KAAAA,CAAS;CACjE,IACEe,OAAO,SACNC,aAAaH,SAAStB,gBAAgBwB,IAAIxB,eACzCyB,aAAaH,SAASrB,aAAauB,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YAAY,OAAO,oBAAA,UAAA,EAAA,UAAGA,cAAcC,OAAK,EAAE,CAAA;EACxE,OAAO,oBAAA,UAAA,EAAA,UAAGD,cAAc,CAAA;CAC1B;CACA,IAAI2D,eAAe,MACjB,OAAO,oBAAA,UAAA,EAAA,UAAGlC,KAAK1B,mBAAmBD,SAAS,CAAA;CAG7C,OACE,oBAAC,aAAD;EACE,KAAKgC;EACL,UAAU6B;EACV,OAAOpD,SAASC,IAAI;EACpB,QAAQA,KAAKoD;EACb,SAASnC,KAAK/B;EACd,UAAUmD;EACV,UAAUpB,KAAK7B;EACf,aAAa6B,KAAK5B;EAClB,WAAW4B,KAAK9B;CAAU,CAAA;AAGhC;;;;;;;;;AAUA,MAAMkE,qBACJC,YACsD;CACtD,MAAMrE,OAAOb,YAAYkF,QAAQrE,IAAI;CAErC,MAAM+B,aAAavD,OAA8B6F,OAAO;CACxDtC,WAAWE,UAAUoC;CAErB,MAAM,CAACvC,gBAAgBrD,eACrBO,cAAqC,EAAEgB,KAAK,EAAE,CAChD;CACA1B,gBAAgB;EACdwD,aAAayC,SAAS,EAAEvE,KAAK,CAAC;CAChC,GAAG,CAACA,MAAM8B,YAAY,CAAC;CAcvB,OAAO,EAAEwC,QAZM/F,cAA4C;EACzD,MAAMiG,UAAwCC,UAC5C,oBAAC,gBAAD;GACE,MAAMA;GACQ3C;GACFC;EAAW,CAAA;EAG3ByC,OAAOE,cAAc;EACrB,OAAOF;CACT,GAAG,CAAC1C,YAAY,CAEPwC,EAAO;AAClB;AAEA,MAAaK,iBAAiBvF,SAASgF,iBAAiB"}
|
|
1
|
+
{"version":3,"file":"McpAppRenderer.js","names":["useEffect","useLayoutEffect","useMemo","useRef","useState","MutableRefObject","ReactNode","McpAppMetadata","ToolCallMessagePartComponent","ToolCallMessagePartProps","useAui","create","StoreApi","UseBoundStore","useResource","resource","ResourceElement","McpAppFrame","McpAppBridgeHandlers","McpAppHostContext","McpAppHostInfo","McpAppResource","McpAppSandboxConfig","McpAppsHost","getMcpAppFromToolPart","isRecord","McpAppRendererOptions","host","sandbox","maxHeight","hostInfo","hostContext","handlers","Omit","fallback","loadingFallback","errorFallback","error","Error","LoadedResourceState","resourceUri","serverId","UseHostStore","getInput","part","status","type","argsText","args","undefined","defaultOpenLink","url","window","open","extractSendMessageText","params","obj","Record","InlineRenderer","useHostStore","optionsRef","opts","current","aui","app","cachedAppRef","appForRender","loadedResource","setLoadedResource","state","callerHandlers","cancelled","targetHost","targetUri","targetServerId","loadResource","uri","then","res","catch","String","bridgeHandlers","openLink","sendMessage","text","ok","reason","thread","append","content","callTool","getState","readResource","listResources","loadedResourceForApp","appResource","result","useMcpAppRenderer","options","render","setState","Render","props","displayName","McpAppRenderer"],"sources":["../../src/mcp-apps/McpAppRenderer.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n useEffect,\n useLayoutEffect,\n useMemo,\n useRef,\n useState,\n type MutableRefObject,\n type ReactNode,\n} from \"react\";\nimport type { McpAppMetadata } from \"@assistant-ui/core\";\nimport type {\n ToolCallMessagePartComponent,\n ToolCallMessagePartProps,\n} from \"@assistant-ui/core/react\";\nimport { useAui } from \"@assistant-ui/store\";\nimport { create, type StoreApi, type UseBoundStore } from \"zustand\";\n\nimport { useResource, resource, type ResourceElement } from \"@assistant-ui/tap\";\nimport { McpAppFrame } from \"./app-frame\";\nimport type {\n McpAppBridgeHandlers,\n McpAppHostContext,\n McpAppHostInfo,\n McpAppResource,\n McpAppSandboxConfig,\n McpAppsHost,\n} from \"./types\";\nimport { getMcpAppFromToolPart } from \"./utils\";\nimport { isRecord } from \"@assistant-ui/core/internal\";\n\nexport type McpAppRendererOptions = {\n /**\n * Provides the data-plane operations the widget can request\n * (`loadResource`, `callTool`, `readResource`, `listResources`). Use\n * `McpAppsRemoteHost({ url })` for the default HTTP-route convention.\n */\n host: ResourceElement<McpAppsHost>;\n /** Sandbox + container styling. Passes through to SafeContentFrame. */\n sandbox?: McpAppSandboxConfig;\n /**\n * Upper bound (in pixels) applied to the widget-driven auto-resize height.\n * Defaults to 800.\n */\n maxHeight?: number;\n /** Identifies the host to the widget in the `ui/initialize` response. */\n hostInfo?: McpAppHostInfo;\n /** Delivered to the widget on initialize and pushed via `notifications/host_context/changed` on change. */\n hostContext?: McpAppHostContext;\n /**\n * Optional widget interaction and lifecycle handlers. Data-plane handlers\n * (`callTool`, `readResource`, `listResources`) always use `host`.\n */\n handlers?: Omit<\n McpAppBridgeHandlers,\n \"callTool\" | \"readResource\" | \"listResources\"\n >;\n /** Rendered when no MCP app is on the part, or while load is in flight / failed (unless overridden). */\n fallback?: ReactNode;\n /** Rendered while the resource is loading. Defaults to `fallback`. */\n loadingFallback?: ReactNode;\n /** Rendered when the resource load rejects. Defaults to `fallback`. */\n errorFallback?: ReactNode | ((error: Error) => ReactNode);\n};\n\ntype LoadedResourceState = {\n host: McpAppsHost;\n resourceUri: string;\n serverId?: string;\n resource?: McpAppResource;\n error?: Error;\n};\n\ntype UseHostStore = UseBoundStore<StoreApi<{ host: McpAppsHost }>>;\n\nfunction getInput(part: {\n status: { type: string };\n argsText: string;\n args: unknown;\n}): unknown {\n if (\n part.status.type === \"running\" &&\n (part.argsText === \"\" || part.argsText === \"{}\")\n ) {\n return undefined;\n }\n return part.args;\n}\n\nconst defaultOpenLink = ({ url }: { url: string }) => {\n window.open(url, \"_blank\", \"noopener,noreferrer\");\n};\n\nfunction extractSendMessageText(params: unknown): string | undefined {\n if (typeof params === \"string\") return params;\n if (!params || typeof params !== \"object\") return undefined;\n const obj = params as Record<string, unknown>;\n if (typeof obj[\"prompt\"] === \"string\") return obj[\"prompt\"];\n if (typeof obj[\"text\"] === \"string\") return obj[\"text\"];\n if (typeof obj[\"message\"] === \"string\") return obj[\"message\"];\n return undefined;\n}\n\nfunction InlineRenderer({\n part,\n useHostStore,\n optionsRef,\n}: {\n part: ToolCallMessagePartProps;\n useHostStore: UseHostStore;\n optionsRef: MutableRefObject<McpAppRendererOptions>;\n}) {\n const opts = optionsRef.current;\n const aui = useAui();\n const app = getMcpAppFromToolPart(part);\n const cachedAppRef = useRef<McpAppMetadata | undefined>(undefined);\n useLayoutEffect(() => {\n if (app != null) cachedAppRef.current = app;\n }, [app]);\n const appForRender = app ?? cachedAppRef.current;\n\n const [loadedResource, setLoadedResource] = useState<LoadedResourceState>();\n\n const host = useHostStore((state) => state.host);\n const resourceUri = appForRender?.resourceUri;\n const serverId = appForRender?.serverId;\n const callerHandlers = opts.handlers;\n useEffect(() => {\n if (resourceUri == null) return;\n let cancelled = false;\n const targetHost = host;\n const targetUri = resourceUri;\n const targetServerId = serverId;\n\n targetHost\n .loadResource({\n uri: targetUri,\n ...(targetServerId ? { serverId: targetServerId } : {}),\n })\n .then((res) => {\n if (!cancelled)\n setLoadedResource({\n host: targetHost,\n resourceUri: targetUri,\n ...(targetServerId !== undefined\n ? { serverId: targetServerId }\n : {}),\n resource: res,\n });\n })\n .catch((error: unknown) => {\n if (!cancelled) {\n setLoadedResource({\n host: targetHost,\n resourceUri: targetUri,\n ...(targetServerId !== undefined\n ? { serverId: targetServerId }\n : {}),\n error: error instanceof Error ? error : new Error(String(error)),\n });\n }\n });\n\n return () => {\n cancelled = true;\n };\n }, [host, resourceUri, serverId]);\n\n const bridgeHandlers = useMemo<McpAppBridgeHandlers>(\n () => ({\n ...callerHandlers,\n openLink: callerHandlers?.openLink ?? defaultOpenLink,\n sendMessage:\n callerHandlers?.sendMessage ??\n ((params) => {\n const text = extractSendMessageText(params);\n if (!text) return { ok: false, reason: \"unrecognised params shape\" };\n aui.thread.append({ content: [{ type: \"text\", text }] });\n return { ok: true };\n }),\n callTool: (params) =>\n useHostStore.getState().host.callTool({\n ...params,\n ...(serverId ? { serverId } : {}),\n }),\n readResource: (params) =>\n useHostStore.getState().host.readResource({\n ...params,\n ...(serverId ? { serverId } : {}),\n }),\n listResources: (params) => {\n if (!serverId) {\n return useHostStore.getState().host.listResources(params);\n }\n return useHostStore.getState().host.listResources({\n ...(isRecord(params) ? params : {}),\n serverId,\n });\n },\n }),\n [aui, callerHandlers, serverId, useHostStore],\n );\n\n const loadedResourceForApp =\n loadedResource?.host === host &&\n loadedResource?.resourceUri === appForRender?.resourceUri &&\n loadedResource?.serverId === appForRender?.serverId\n ? loadedResource\n : undefined;\n const appResource = loadedResourceForApp?.resource;\n const error = loadedResourceForApp?.error;\n\n const fallback = opts.fallback ?? null;\n if (appForRender == null) {\n return <>{fallback}</>;\n }\n if (error != null) {\n const errorFallback = opts.errorFallback;\n if (errorFallback === undefined) return <>{fallback}</>;\n if (typeof errorFallback === \"function\") return <>{errorFallback(error)}</>;\n return <>{errorFallback}</>;\n }\n if (appResource == null) {\n return <>{opts.loadingFallback ?? fallback}</>;\n }\n\n return (\n <McpAppFrame\n app={appForRender}\n resource={appResource}\n input={getInput(part)}\n output={part.result}\n sandbox={opts.sandbox}\n handlers={bridgeHandlers}\n hostInfo={opts.hostInfo}\n hostContext={opts.hostContext}\n maxHeight={opts.maxHeight}\n />\n );\n}\n\n/**\n * Creates a tool-call renderer for MCP Apps embedded in assistant messages.\n *\n * Compose this into the `Tools` resource through its `mcpApp` option. When a\n * tool-call part carries `mcp.app` metadata for a `ui://` resource, the\n * renderer loads that resource from the configured host and displays it in a\n * sandboxed frame.\n */\nconst useMcpAppRenderer = (\n options: McpAppRendererOptions,\n): { readonly render: ToolCallMessagePartComponent } => {\n const host = useResource(options.host);\n\n const optionsRef = useRef<McpAppRendererOptions>(options);\n optionsRef.current = options;\n\n const [useHostStore] = useState(() =>\n create<{ host: McpAppsHost }>(() => ({ host })),\n );\n useEffect(() => {\n useHostStore.setState({ host });\n }, [host, useHostStore]);\n\n const render = useMemo((): ToolCallMessagePartComponent => {\n const Render: ToolCallMessagePartComponent = (props) => (\n <InlineRenderer\n part={props}\n useHostStore={useHostStore}\n optionsRef={optionsRef}\n />\n );\n Render.displayName = \"McpAppRenderer\";\n return Render;\n }, [useHostStore]);\n\n return { render };\n};\n\nexport const McpAppRenderer = resource(useMcpAppRenderer);\n"],"mappings":";;;;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AAMiC,aAAazD,OAA8B+F,OAAO;CACxDtC,WAAWE,UAAUoC;CAErB,MAAM,CAACvC,gBAAgBvD,eACrBO,cAAqC,EAAEgB,KAAK,EAAE,CAChD;CACA3B,gBAAgB;EACd2D,aAAayC,SAAS,EAAEzE,KAAK,CAAC;CAChC,GAAG,CAACA,MAAMgC,YAAY,CAAC;CAcvB,OAAO,EAAEwC,QAZMjG,cAA4C;EACzD,MAAMmG,UAAwCC,UAC5C,oBAAC,gBAAD;GACE,MAAMA;GACQ3C;GACFC;EAAW,CAAA;EAG3ByC,OAAOE,cAAc;EACrB,OAAOF;CACT,GAAG,CAAC1C,YAAY,CAEPwC,EAAO;AAClB;AAEA,MAAaK,iBAAiBzF,SAASkF,iBAAiB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"McpAppsRemoteHost.d.ts","names":[],"sources":["../../src/mcp-apps/McpAppsRemoteHost.ts"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"McpAppsRemoteHost.d.ts","names":[],"sources":["../../src/mcp-apps/McpAppsRemoteHost.ts"],"mappings":";;cAgKa,+CAAiB,SAAA,cAAA,SAAA"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useMemo, useRef } from "@assistant-ui/tap/react-shim";
|
|
1
|
+
import { useEffect, useMemo, useRef } from "@assistant-ui/tap/react-shim";
|
|
2
2
|
import { resource } from "@assistant-ui/tap";
|
|
3
3
|
//#region src/mcp-apps/McpAppsRemoteHost.ts
|
|
4
4
|
const truncateBody = (body) => body.length > 500 ? `${body.slice(0, 500)}...` : body;
|
|
@@ -71,27 +71,30 @@ async function postToHost(options, method, params) {
|
|
|
71
71
|
*/
|
|
72
72
|
const useMcpAppsRemoteHost = (options) => {
|
|
73
73
|
const optionsRef = useRef(options);
|
|
74
|
-
|
|
74
|
+
useEffect(() => {
|
|
75
|
+
optionsRef.current = options;
|
|
76
|
+
});
|
|
75
77
|
const url = options.url;
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
return {
|
|
80
|
-
url,
|
|
81
|
-
...current.fetch !== void 0 ? { fetch: current.fetch } : {},
|
|
82
|
-
...current.headers !== void 0 ? { headers: current.headers } : {}
|
|
83
|
-
};
|
|
84
|
-
};
|
|
78
|
+
const hostState = useMemo(() => {
|
|
79
|
+
let pendingOptions = options;
|
|
80
|
+
const getCurrentOptions = () => optionsRef.current.url === url ? optionsRef.current : pendingOptions;
|
|
85
81
|
return {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
82
|
+
host: {
|
|
83
|
+
loadResource: async (params) => {
|
|
84
|
+
const options_0 = getCurrentOptions();
|
|
85
|
+
return parseMcpAppResource(await postToHost(options_0, "mcp-apps/read-resource", params), options_0);
|
|
86
|
+
},
|
|
87
|
+
callTool: (params_0) => postToHost(getCurrentOptions(), "tools/call", params_0),
|
|
88
|
+
readResource: (params_1) => postToHost(getCurrentOptions(), "resources/read", params_1),
|
|
89
|
+
listResources: (params_2) => postToHost(getCurrentOptions(), "resources/list", params_2)
|
|
89
90
|
},
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
91
|
+
updatePendingOptions: (next) => {
|
|
92
|
+
pendingOptions = next;
|
|
93
|
+
}
|
|
93
94
|
};
|
|
94
95
|
}, [url]);
|
|
96
|
+
if (optionsRef.current.url !== url) hostState.updatePendingOptions(options);
|
|
97
|
+
return hostState.host;
|
|
95
98
|
};
|
|
96
99
|
const McpAppsRemoteHost = resource(useMcpAppsRemoteHost);
|
|
97
100
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"McpAppsRemoteHost.js","names":["useMemo","useRef","resource","McpAppResource","McpAppsHost","McpAppsRemoteHostOptions","truncateBody","body","length","slice","extractErrorBody","trimmed","trim","undefined","parsed","JSON","parse","record","Record","message","error","readErrorBody","res","Response","Promise","text","invalidMcpAppResource","options","Error","url","parseMcpAppResource","value","Array","isArray","uri","html","postToHost","method","params","doFetch","fetch","extraHeaders","headers","stringify","ok","status","statusText","json","cause","useMcpAppsRemoteHost","optionsRef","current","getCurrentOptions","loadResource","callTool","readResource","listResources","McpAppsRemoteHost"],"sources":["../../src/mcp-apps/McpAppsRemoteHost.ts"],"sourcesContent":["import { useMemo, useRef } from \"react\";\nimport { resource } from \"@assistant-ui/tap\";\nimport type {\n McpAppResource,\n McpAppsHost,\n McpAppsRemoteHostOptions,\n} from \"./types\";\n\nconst truncateBody = (body: string) =>\n body.length > 500 ? `${body.slice(0, 500)}...` : body;\n\nconst extractErrorBody = (body: string): string | undefined => {\n const trimmed = body.trim();\n if (!trimmed) return undefined;\n\n try {\n const parsed = JSON.parse(trimmed) as unknown;\n if (parsed && typeof parsed === \"object\") {\n const record = parsed as Record<string, unknown>;\n if (typeof record.message === \"string\") return record.message;\n if (typeof record.error === \"string\") return record.error;\n if (record.error && typeof record.error === \"object\") {\n const error = record.error as Record<string, unknown>;\n if (typeof error.message === \"string\") return error.message;\n }\n }\n } catch {\n return truncateBody(trimmed);\n }\n\n return truncateBody(trimmed);\n};\n\nconst readErrorBody = async (res: Response): Promise<string | undefined> => {\n try {\n return extractErrorBody(await res.text());\n } catch {\n return undefined;\n }\n};\n\nconst invalidMcpAppResource = (options: McpAppsRemoteHostOptions): never => {\n throw new Error(\n `Invalid MCP App host response \"mcp-apps/read-resource\" from \"${options.url}\": expected a resource with non-empty string \"uri\" and \"html\" fields`,\n );\n};\n\nconst parseMcpAppResource = (\n value: unknown,\n options: McpAppsRemoteHostOptions,\n): McpAppResource => {\n if (typeof value !== \"object\" || value === null || Array.isArray(value)) {\n return invalidMcpAppResource(options);\n }\n\n const resource = value as Record<string, unknown>;\n if (\n typeof resource.uri !== \"string\" ||\n resource.uri.trim() === \"\" ||\n typeof resource.html !== \"string\" ||\n resource.html.trim() === \"\"\n ) {\n return invalidMcpAppResource(options);\n }\n\n return value as McpAppResource;\n};\n\nasync function postToHost(\n options: McpAppsRemoteHostOptions,\n method: string,\n params: unknown,\n): Promise<unknown> {\n const doFetch = options.fetch ?? fetch;\n const extraHeaders =\n typeof options.headers === \"function\"\n ? await options.headers()\n : (options.headers ?? {});\n const res = await doFetch(options.url, {\n method: \"POST\",\n headers: { \"content-type\": \"application/json\", ...extraHeaders },\n body: JSON.stringify({ method, params }),\n });\n if (!res.ok) {\n const status = res.statusText\n ? `${res.status} ${res.statusText}`\n : `${res.status}`;\n const body = await readErrorBody(res);\n throw new Error(\n `MCP App host request \"${method}\" to \"${options.url}\" failed with ${status}${body ? `: ${body}` : \"\"}`,\n );\n }\n try {\n return await res.json();\n } catch (cause) {\n throw new Error(\n `Invalid MCP App host response \"${method}\" from \"${options.url}\": expected valid JSON`,\n { cause },\n );\n }\n}\n\n/**\n * Creates the default HTTP host for MCP App widgets.\n *\n * The host POSTs widget requests to the configured route as `{ method,\n * params }`, using the method names expected by the assistant-ui MCP Apps\n * guide.\n */\nconst useMcpAppsRemoteHost = (\n options: McpAppsRemoteHostOptions,\n): McpAppsHost => {\n const optionsRef = useRef(options);\n optionsRef.current = options;\n\n const url = options.url;\n\n
|
|
1
|
+
{"version":3,"file":"McpAppsRemoteHost.js","names":["useEffect","useMemo","useRef","resource","McpAppResource","McpAppsHost","McpAppsRemoteHostOptions","truncateBody","body","length","slice","extractErrorBody","trimmed","trim","undefined","parsed","JSON","parse","record","Record","message","error","readErrorBody","res","Response","Promise","text","invalidMcpAppResource","options","Error","url","parseMcpAppResource","value","Array","isArray","uri","html","postToHost","method","params","doFetch","fetch","extraHeaders","headers","stringify","ok","status","statusText","json","cause","useMcpAppsRemoteHost","optionsRef","current","hostState","pendingOptions","getCurrentOptions","host","loadResource","callTool","readResource","listResources","updatePendingOptions","next","McpAppsRemoteHost"],"sources":["../../src/mcp-apps/McpAppsRemoteHost.ts"],"sourcesContent":["import { useEffect, useMemo, useRef } from \"react\";\nimport { resource } from \"@assistant-ui/tap\";\nimport type {\n McpAppResource,\n McpAppsHost,\n McpAppsRemoteHostOptions,\n} from \"./types\";\n\nconst truncateBody = (body: string) =>\n body.length > 500 ? `${body.slice(0, 500)}...` : body;\n\nconst extractErrorBody = (body: string): string | undefined => {\n const trimmed = body.trim();\n if (!trimmed) return undefined;\n\n try {\n const parsed = JSON.parse(trimmed) as unknown;\n if (parsed && typeof parsed === \"object\") {\n const record = parsed as Record<string, unknown>;\n if (typeof record.message === \"string\") return record.message;\n if (typeof record.error === \"string\") return record.error;\n if (record.error && typeof record.error === \"object\") {\n const error = record.error as Record<string, unknown>;\n if (typeof error.message === \"string\") return error.message;\n }\n }\n } catch {\n return truncateBody(trimmed);\n }\n\n return truncateBody(trimmed);\n};\n\nconst readErrorBody = async (res: Response): Promise<string | undefined> => {\n try {\n return extractErrorBody(await res.text());\n } catch {\n return undefined;\n }\n};\n\nconst invalidMcpAppResource = (options: McpAppsRemoteHostOptions): never => {\n throw new Error(\n `Invalid MCP App host response \"mcp-apps/read-resource\" from \"${options.url}\": expected a resource with non-empty string \"uri\" and \"html\" fields`,\n );\n};\n\nconst parseMcpAppResource = (\n value: unknown,\n options: McpAppsRemoteHostOptions,\n): McpAppResource => {\n if (typeof value !== \"object\" || value === null || Array.isArray(value)) {\n return invalidMcpAppResource(options);\n }\n\n const resource = value as Record<string, unknown>;\n if (\n typeof resource.uri !== \"string\" ||\n resource.uri.trim() === \"\" ||\n typeof resource.html !== \"string\" ||\n resource.html.trim() === \"\"\n ) {\n return invalidMcpAppResource(options);\n }\n\n return value as McpAppResource;\n};\n\nasync function postToHost(\n options: McpAppsRemoteHostOptions,\n method: string,\n params: unknown,\n): Promise<unknown> {\n const doFetch = options.fetch ?? fetch;\n const extraHeaders =\n typeof options.headers === \"function\"\n ? await options.headers()\n : (options.headers ?? {});\n const res = await doFetch(options.url, {\n method: \"POST\",\n headers: { \"content-type\": \"application/json\", ...extraHeaders },\n body: JSON.stringify({ method, params }),\n });\n if (!res.ok) {\n const status = res.statusText\n ? `${res.status} ${res.statusText}`\n : `${res.status}`;\n const body = await readErrorBody(res);\n throw new Error(\n `MCP App host request \"${method}\" to \"${options.url}\" failed with ${status}${body ? `: ${body}` : \"\"}`,\n );\n }\n try {\n return await res.json();\n } catch (cause) {\n throw new Error(\n `Invalid MCP App host response \"${method}\" from \"${options.url}\": expected valid JSON`,\n { cause },\n );\n }\n}\n\n/**\n * Creates the default HTTP host for MCP App widgets.\n *\n * The host POSTs widget requests to the configured route as `{ method,\n * params }`, using the method names expected by the assistant-ui MCP Apps\n * guide.\n */\nconst useMcpAppsRemoteHost = (\n options: McpAppsRemoteHostOptions,\n): McpAppsHost => {\n const optionsRef = useRef(options);\n useEffect(() => {\n optionsRef.current = options;\n });\n\n const url = options.url;\n\n const hostState = useMemo(() => {\n let pendingOptions = options;\n const getCurrentOptions = () =>\n optionsRef.current.url === url ? optionsRef.current : pendingOptions;\n const host: McpAppsHost = {\n loadResource: async (params) => {\n const options = getCurrentOptions();\n return parseMcpAppResource(\n await postToHost(options, \"mcp-apps/read-resource\", params),\n options,\n );\n },\n callTool: (params) =>\n postToHost(getCurrentOptions(), \"tools/call\", params),\n readResource: (params) =>\n postToHost(getCurrentOptions(), \"resources/read\", params),\n listResources: (params) =>\n postToHost(getCurrentOptions(), \"resources/list\", params),\n };\n return {\n host,\n updatePendingOptions: (next: McpAppsRemoteHostOptions) => {\n pendingOptions = next;\n },\n };\n // oxlint-disable-next-line react/exhaustive-deps -- URL changes replace the host identity; pending and same-URL options are refreshed outside the memo\n }, [url]);\n\n // The pending snapshot is read only while the committed ref still lags this\n // host's URL, and every write to it carries that same render's options, so\n // no render can pair one URL with another's credentials. A committed host can\n // be written here (a child layout effect re-rendering synchronously runs\n // before passive effects publish the ref), which stays coherent for the same\n // reason.\n if (optionsRef.current.url !== url) {\n hostState.updatePendingOptions(options);\n }\n\n return hostState.host;\n};\n\nexport const McpAppsRemoteHost = resource(useMcpAppsRemoteHost);\n"],"mappings":";;;AAQA,MAAMO,gBAAgBC,SACpBA,KAAKC,SAAS,MAAM,GAAGD,KAAKE,MAAM,GAAG,GAAG,EAAC,OAAQ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B,kBAAkB,GAAG,kBAAkBhB,QAAM;GAG1DiB;GACAK,uBAAuBC,SAAmC;IACxDR,iBAAiBQ;GACnB;EACF;CAEF,GAAG,CAAChC,GAAG,CAAC;CAQR,IAAIqB,WAAWC,QAAQtB,QAAQA,KAC7BuB,UAAUQ,qBAAqBjC,OAAO;CAGxC,OAAOyB,UAAUG;AACnB;AAEA,MAAaO,oBAAoB5D,SAAS+C,oBAAoB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app-frame.d.ts","names":[],"sources":["../../src/mcp-apps/app-frame.tsx"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"app-frame.d.ts","names":[],"sources":["../../src/mcp-apps/app-frame.tsx"],"mappings":";;iBAqGgB,cACd,KACA,UACA,OACA,QACA,SACA,UACA,UACA,aACA,aACC,mCAAgB,IAAA"}
|