@assistant-ui/react 0.15.18 → 0.15.20
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 +7 -1
- package/dist/context/providers/ThreadViewportProvider.js +2 -2
- package/dist/context/providers/ThreadViewportProvider.js.map +1 -1
- package/dist/context/stores/ThreadViewport.d.ts.map +1 -1
- package/dist/context/stores/ThreadViewport.js +2 -1
- package/dist/context/stores/ThreadViewport.js.map +1 -1
- package/dist/hooks/useToolCallElapsed.js.map +1 -1
- package/dist/index.d.ts +5 -5
- package/dist/index.js +3 -3
- package/dist/legacy-runtime/runtime-cores/external-store/external-message-converter.d.ts +2 -2
- package/dist/legacy-runtime/runtime-cores/external-store/external-message-converter.js +2 -2
- package/dist/mcp-apps/McpAppRenderer.js +1 -1
- package/dist/mcp-apps/app-frame.d.ts.map +1 -1
- package/dist/mcp-apps/app-frame.js +18 -13
- package/dist/mcp-apps/app-frame.js.map +1 -1
- package/dist/mcp-apps/bridge.js +7 -1
- package/dist/mcp-apps/bridge.js.map +1 -1
- package/dist/model-context/frame/useAssistantFrameHost.js +20 -2
- package/dist/model-context/frame/useAssistantFrameHost.js.map +1 -1
- package/dist/primitives/assistantModal/AssistantModalRoot.d.ts.map +1 -1
- package/dist/primitives/assistantModal/AssistantModalRoot.js +47 -79
- package/dist/primitives/assistantModal/AssistantModalRoot.js.map +1 -1
- package/dist/primitives/composer/ComposerAttachmentDropzone.d.ts.map +1 -1
- package/dist/primitives/composer/ComposerAttachmentDropzone.js +61 -138
- package/dist/primitives/composer/ComposerAttachmentDropzone.js.map +1 -1
- package/dist/primitives/composer/ComposerInput.js +3 -8
- package/dist/primitives/composer/ComposerInput.js.map +1 -1
- package/dist/primitives/composer/trigger/triggerKeyboardResource.d.ts.map +1 -1
- package/dist/primitives/composer/trigger/triggerKeyboardResource.js +53 -61
- package/dist/primitives/composer/trigger/triggerKeyboardResource.js.map +1 -1
- package/dist/primitives/composer/trigger/triggerNavigationResource.d.ts.map +1 -1
- package/dist/primitives/composer/trigger/triggerNavigationResource.js +127 -137
- package/dist/primitives/composer/trigger/triggerNavigationResource.js.map +1 -1
- package/dist/primitives/message/MessageParts.js +2 -14
- package/dist/primitives/message/MessageParts.js.map +1 -1
- package/dist/primitives/message/MessagePartsGrouped.d.ts +3 -3
- package/dist/primitives/message/MessagePartsGrouped.js +2 -2
- package/dist/primitives/message/MessagePartsGrouped.js.map +1 -1
- package/dist/primitives/messagePart/MessagePartText.d.ts +2 -0
- package/dist/primitives/messagePart/MessagePartText.d.ts.map +1 -1
- package/dist/primitives/messagePart/MessagePartText.js +13 -36
- package/dist/primitives/messagePart/MessagePartText.js.map +1 -1
- package/dist/primitives/reasoning/useScrollLock.js +3 -1
- package/dist/primitives/reasoning/useScrollLock.js.map +1 -1
- package/dist/sandbox-host/SandboxHost.js +23 -5
- package/dist/sandbox-host/SandboxHost.js.map +1 -1
- package/dist/unstable/useLiveCompletionAdapter.js +24 -2
- package/dist/unstable/useLiveCompletionAdapter.js.map +1 -1
- package/dist/unstable/useMentionAdapter.js +2 -2
- package/dist/unstable/useMentionAdapter.js.map +1 -1
- package/dist/unstable/useMessageStallDetection.d.ts +4 -5
- package/dist/unstable/useMessageStallDetection.d.ts.map +1 -1
- package/dist/unstable/useMessageStallDetection.js +16 -15
- package/dist/unstable/useMessageStallDetection.js.map +1 -1
- package/dist/unstable/webmcp/convertTools.d.ts.map +1 -1
- package/dist/unstable/webmcp/convertTools.js +54 -3
- package/dist/unstable/webmcp/convertTools.js.map +1 -1
- package/dist/unstable/webmcp/useWebMcpProvider.d.ts.map +1 -1
- package/dist/unstable/webmcp/useWebMcpProvider.js +2 -1
- package/dist/unstable/webmcp/useWebMcpProvider.js.map +1 -1
- package/dist/utils/Primitive.d.ts +10 -2
- package/dist/utils/Primitive.d.ts.map +1 -1
- package/dist/utils/Primitive.js +25 -6
- package/dist/utils/Primitive.js.map +1 -1
- package/dist/utils/getSelectionMessageId.d.ts.map +1 -1
- package/dist/utils/getSelectionMessageId.js +17 -3
- package/dist/utils/getSelectionMessageId.js.map +1 -1
- package/package.json +12 -12
- package/src/context/providers/ThreadViewportProvider.tsx +2 -2
- package/src/context/stores/ThreadViewport.test.ts +29 -0
- package/src/context/stores/ThreadViewport.ts +6 -3
- package/src/hooks/useToolCallElapsed.ts +3 -0
- package/src/index.ts +6 -1
- package/src/legacy-runtime/runtime-cores/external-store/external-message-converter.ts +2 -0
- package/src/mcp-apps/app-frame.test.tsx +189 -1
- package/src/mcp-apps/app-frame.tsx +31 -22
- package/src/mcp-apps/bridge.test.ts +98 -0
- package/src/mcp-apps/bridge.ts +7 -1
- package/src/model-context/frame/useAssistantFrameHost.test.tsx +42 -0
- package/src/model-context/frame/useAssistantFrameHost.ts +25 -2
- package/src/primitives/assistantModal/AssistantModalRoot.test.tsx +123 -0
- package/src/primitives/assistantModal/AssistantModalRoot.tsx +11 -31
- package/src/primitives/assistantModal/AssistantModalTrigger.test.tsx +1 -16
- package/src/primitives/composer/ComposerAttachmentDropzone.test.tsx +43 -0
- package/src/primitives/composer/ComposerAttachmentDropzone.tsx +2 -10
- package/src/primitives/composer/ComposerInput.test.tsx +22 -0
- package/src/primitives/composer/ComposerInput.tsx +5 -9
- package/src/primitives/composer/trigger/triggerKeyboardResource.ts +13 -7
- package/src/primitives/composer/trigger/triggerNavigationResource.ts +5 -3
- package/src/primitives/message/MessageParts.tsx +1 -21
- package/src/primitives/message/MessagePartsGrouped.test.tsx +93 -0
- package/src/primitives/message/MessagePartsGrouped.tsx +6 -6
- package/src/primitives/messagePart/MessagePartText.test.tsx +69 -0
- package/src/primitives/messagePart/MessagePartText.tsx +22 -9
- package/src/primitives/reasoning/useScrollLock.test.tsx +129 -0
- package/src/primitives/reasoning/useScrollLock.ts +15 -1
- package/src/primitives/thread/useThreadViewportAutoScroll.test.tsx +38 -1
- package/src/sandbox-host/SandboxHost.test.tsx +40 -0
- package/src/sandbox-host/SandboxHost.tsx +24 -4
- package/src/tests/MessageParts.rendererOptions.test.tsx +117 -0
- package/src/tests/toolCallTiming.test.tsx +55 -1
- package/src/unstable/useLiveCompletionAdapter.test.tsx +202 -1
- package/src/unstable/useLiveCompletionAdapter.ts +38 -8
- package/src/unstable/useMentionAdapter.test.tsx +47 -1
- package/src/unstable/useMentionAdapter.ts +2 -2
- package/src/unstable/useMessageStallDetection.ts +26 -19
- package/src/unstable/webmcp/convertTools.test.ts +181 -21
- package/src/unstable/webmcp/convertTools.ts +87 -7
- package/src/unstable/webmcp/useWebMcpProvider.ts +2 -4
- package/src/utils/Primitive.test.tsx +46 -1
- package/src/utils/Primitive.tsx +37 -7
- package/src/utils/getSelectionMessageId.test.ts +176 -1
- package/src/utils/getSelectionMessageId.ts +21 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bridge.js","names":["SandboxHostFrame","invokeUserCallback","MCP_APP_PROTOCOL_VERSION","McpAppBridgeHandlers","McpAppDisplayMode","McpAppHostContext","McpAppHostInfo","McpAppJsonRpcMessage","McpAppJsonRpcNotification","McpAppJsonRpcRequest","McpAppJsonRpcResponse","isRecord","VALID_DISPLAY_MODES","const","McpAppBridgeFrame","CreateMcpAppBridgeOptions","frame","handlers","hostInfo","hostContext","McpAppBridge","onMessage","event","MessageEvent","dispose","notifyToolInput","input","notifyToolResult","result","notifyHostContextChanged","DEFAULT_HOST_INFO","name","version","METHOD_ALIASES","Record","normalizeMethod","method","JSONRPC_ERROR","parseError","invalidRequest","methodNotFound","invalidParams","internalError","isJsonRpcMessage","value","v","jsonrpc","isRequest","msg","isNotification","createMcpAppBridge","opts","post","sendMessage","respond","id","payload","error","code","message","data","res","errorResponse","undefined","reportError","Error","onError","bind","handleRequest","req","params","requestedProtocolVersion","protocolVersion","host","capabilities","tools","callTool","resources","readResource","listResources","ui","openLink","requestDisplayMode","updateModelContext","hostCapabilities","openLinks","serverTools","serverResources","text","onLog","logging","callParams","arguments","allowedTools","includes","callArgs","Array","isArray","readParams","uri","linkParams","url","linkProtocol","URL","protocol","modeParams","mode","err","String","handleNotification","note","onInitialized","p","width","height","onSizeChange","onRequestTeardown","content","type","ctx"],"sources":["../../src/mcp-apps/bridge.ts"],"sourcesContent":["import type { SandboxHostFrame } from \"../sandbox-host/SandboxHost\";\nimport { invokeUserCallback } from \"@assistant-ui/core/internal\";\nimport {\n MCP_APP_PROTOCOL_VERSION,\n type McpAppBridgeHandlers,\n type McpAppDisplayMode,\n type McpAppHostContext,\n type McpAppHostInfo,\n type McpAppJsonRpcMessage,\n type McpAppJsonRpcNotification,\n type McpAppJsonRpcRequest,\n type McpAppJsonRpcResponse,\n} from \"./types\";\nimport { isRecord } from \"@assistant-ui/core/internal\";\n\nconst VALID_DISPLAY_MODES = [\n \"inline\",\n \"fullscreen\",\n \"pip\",\n] as const satisfies readonly McpAppDisplayMode[];\n\nexport type McpAppBridgeFrame = SandboxHostFrame;\n\nexport type CreateMcpAppBridgeOptions = {\n frame: McpAppBridgeFrame;\n handlers?: McpAppBridgeHandlers | undefined;\n hostInfo?: McpAppHostInfo | undefined;\n hostContext?: McpAppHostContext | undefined;\n};\n\nexport type McpAppBridge = {\n onMessage: (event: MessageEvent) => void;\n dispose: () => void;\n notifyToolInput: (input: unknown) => void;\n notifyToolResult: (result: unknown) => void;\n notifyHostContextChanged: (hostContext: McpAppHostContext) => void;\n};\n\nconst DEFAULT_HOST_INFO: McpAppHostInfo = {\n name: \"assistant-ui\",\n version: \"0.1\",\n};\n\n// Accept both the legacy method names and the MCP-UI 2026-01-26 names that\n// `ui/*` capable widgets (e.g. xmcp's host-bridge) emit. Normalize on input\n// so downstream switch statements only need to know the legacy names.\nconst METHOD_ALIASES: Record<string, string> = {\n \"ui/notifications/initialized\": \"notifications/initialized\",\n \"ui/notifications/size-changed\": \"notifications/size_changed\",\n \"ui/request-display-mode\": \"requestDisplayMode\",\n \"ui/open-link\": \"openLink\",\n \"ui/update-model-context\": \"updateModelContext\",\n \"ui/message\": \"sendMessage\",\n \"notifications/message\": \"notifications/log\",\n};\n\nconst normalizeMethod = (method: string): string =>\n METHOD_ALIASES[method] ?? method;\n\nconst JSONRPC_ERROR = {\n parseError: -32700,\n invalidRequest: -32600,\n methodNotFound: -32601,\n invalidParams: -32602,\n internalError: -32603,\n} as const;\n\nfunction isJsonRpcMessage(value: unknown): value is McpAppJsonRpcMessage {\n if (!value || typeof value !== \"object\") return false;\n const v = value as Record<string, unknown>;\n return v.jsonrpc === \"2.0\" && typeof v.method === \"string\";\n}\n\nfunction isRequest(msg: McpAppJsonRpcMessage): msg is McpAppJsonRpcRequest {\n return \"id\" in msg;\n}\n\nfunction isNotification(\n msg: McpAppJsonRpcMessage,\n): msg is McpAppJsonRpcNotification {\n return !(\"id\" in msg);\n}\n\nexport function createMcpAppBridge(\n opts: CreateMcpAppBridgeOptions,\n): McpAppBridge {\n const {\n frame,\n handlers = {},\n hostInfo = DEFAULT_HOST_INFO,\n hostContext = {},\n } = opts;\n\n const post = (msg: McpAppJsonRpcMessage) => {\n frame.sendMessage(msg);\n };\n\n const respond = (\n id: McpAppJsonRpcRequest[\"id\"],\n payload:\n | { result: unknown }\n | { error: { code: number; message: string; data?: unknown } },\n ) => {\n const res: McpAppJsonRpcResponse = {\n jsonrpc: \"2.0\",\n id,\n ...payload,\n };\n post(res);\n };\n\n const errorResponse = (\n id: McpAppJsonRpcRequest[\"id\"],\n code: number,\n message: string,\n data?: unknown,\n ) => {\n respond(id, {\n error: {\n code,\n message,\n ...(data !== undefined ? { data } : {}),\n },\n });\n };\n\n const reportError = (error: Error) => {\n invokeUserCallback(\n \"assistant-ui\",\n \"MCP App onError\",\n handlers.onError?.bind(handlers),\n error,\n );\n };\n\n const handleRequest = async (req: McpAppJsonRpcRequest) => {\n try {\n const params = req.params;\n\n switch (normalizeMethod(req.method)) {\n case \"ui/initialize\": {\n const requestedProtocolVersion =\n isRecord(params) && typeof params.protocolVersion === \"string\"\n ? params.protocolVersion\n : MCP_APP_PROTOCOL_VERSION;\n respond(req.id, {\n result: {\n protocolVersion: requestedProtocolVersion,\n host: hostInfo,\n hostInfo,\n hostContext,\n capabilities: {\n tools: handlers.callTool ? {} : undefined,\n resources:\n handlers.readResource || handlers.listResources\n ? {}\n : undefined,\n ui: {\n sendMessage: !!handlers.sendMessage,\n openLink: !!handlers.openLink,\n requestDisplayMode: !!handlers.requestDisplayMode,\n updateModelContext: !!handlers.updateModelContext,\n },\n },\n hostCapabilities: {\n ...(handlers.openLink ? { openLinks: {} } : {}),\n ...(handlers.callTool ? { serverTools: {} } : {}),\n ...(handlers.readResource || handlers.listResources\n ? { serverResources: {} }\n : {}),\n ...(handlers.updateModelContext\n ? { updateModelContext: { text: {} } }\n : {}),\n ...(handlers.sendMessage ? { message: { text: {} } } : {}),\n ...(handlers.onLog ? { logging: {} } : {}),\n },\n },\n });\n return;\n }\n\n case \"tools/call\": {\n if (!handlers.callTool) {\n errorResponse(\n req.id,\n JSONRPC_ERROR.methodNotFound,\n \"tools/call is not supported by this host\",\n );\n return;\n }\n const callParams = (params ?? {}) as {\n name?: unknown;\n arguments?: unknown;\n };\n if (typeof callParams.name !== \"string\") {\n errorResponse(\n req.id,\n JSONRPC_ERROR.invalidParams,\n \"tools/call requires a string 'name'\",\n );\n return;\n }\n if (\n handlers.allowedTools &&\n !handlers.allowedTools.includes(callParams.name)\n ) {\n errorResponse(\n req.id,\n JSONRPC_ERROR.invalidParams,\n `tool '${callParams.name}' is not allowed for this app`,\n );\n return;\n }\n let callArgs: Record<string, unknown> | undefined;\n if (callParams.arguments !== undefined) {\n if (\n callParams.arguments === null ||\n typeof callParams.arguments !== \"object\" ||\n Array.isArray(callParams.arguments)\n ) {\n errorResponse(\n req.id,\n JSONRPC_ERROR.invalidParams,\n \"tools/call 'arguments' must be an object\",\n );\n return;\n }\n callArgs = callParams.arguments as Record<string, unknown>;\n }\n const result = await handlers.callTool({\n name: callParams.name,\n ...(callArgs !== undefined ? { arguments: callArgs } : {}),\n });\n respond(req.id, { result });\n return;\n }\n\n case \"resources/read\": {\n if (!handlers.readResource) {\n errorResponse(\n req.id,\n JSONRPC_ERROR.methodNotFound,\n \"resources/read is not supported by this host\",\n );\n return;\n }\n const readParams = (params ?? {}) as { uri?: unknown };\n if (typeof readParams.uri !== \"string\") {\n errorResponse(\n req.id,\n JSONRPC_ERROR.invalidParams,\n \"resources/read requires a string 'uri'\",\n );\n return;\n }\n respond(req.id, {\n result: await handlers.readResource({ uri: readParams.uri }),\n });\n return;\n }\n\n case \"resources/list\": {\n if (!handlers.listResources) {\n errorResponse(\n req.id,\n JSONRPC_ERROR.methodNotFound,\n \"resources/list is not supported by this host\",\n );\n return;\n }\n respond(req.id, {\n result: (await handlers.listResources(params)) ?? null,\n });\n return;\n }\n\n case \"openLink\": {\n if (!handlers.openLink) {\n errorResponse(\n req.id,\n JSONRPC_ERROR.methodNotFound,\n \"openLink is not supported by this host\",\n );\n return;\n }\n const linkParams = (params ?? {}) as { url?: unknown };\n if (typeof linkParams.url !== \"string\") {\n errorResponse(\n req.id,\n JSONRPC_ERROR.invalidParams,\n \"openLink requires a string 'url'\",\n );\n return;\n }\n let linkProtocol: string;\n try {\n linkProtocol = new URL(linkParams.url).protocol;\n } catch {\n errorResponse(\n req.id,\n JSONRPC_ERROR.invalidParams,\n \"openLink requires a valid URL\",\n );\n return;\n }\n if (linkProtocol !== \"https:\" && linkProtocol !== \"http:\") {\n errorResponse(\n req.id,\n JSONRPC_ERROR.invalidParams,\n \"openLink only accepts http(s) URLs\",\n );\n return;\n }\n respond(req.id, {\n result: await handlers.openLink({ url: linkParams.url }),\n });\n return;\n }\n\n case \"sendMessage\": {\n if (!handlers.sendMessage) {\n errorResponse(\n req.id,\n JSONRPC_ERROR.methodNotFound,\n \"sendMessage is not supported by this host\",\n );\n return;\n }\n respond(req.id, {\n result: (await handlers.sendMessage(params)) ?? null,\n });\n return;\n }\n\n case \"updateModelContext\": {\n if (!handlers.updateModelContext) {\n errorResponse(\n req.id,\n JSONRPC_ERROR.methodNotFound,\n \"updateModelContext is not supported by this host\",\n );\n return;\n }\n respond(req.id, {\n result: (await handlers.updateModelContext(params)) ?? null,\n });\n return;\n }\n\n case \"requestDisplayMode\": {\n if (!handlers.requestDisplayMode) {\n errorResponse(\n req.id,\n JSONRPC_ERROR.methodNotFound,\n \"requestDisplayMode is not supported by this host\",\n );\n return;\n }\n const modeParams = (params ?? {}) as { mode?: unknown };\n if (\n typeof modeParams.mode !== \"string\" ||\n !VALID_DISPLAY_MODES.includes(modeParams.mode as McpAppDisplayMode)\n ) {\n errorResponse(\n req.id,\n JSONRPC_ERROR.invalidParams,\n \"requestDisplayMode requires a valid 'mode'\",\n );\n return;\n }\n respond(req.id, {\n result: await handlers.requestDisplayMode({\n mode: modeParams.mode as McpAppDisplayMode,\n }),\n });\n return;\n }\n\n default: {\n errorResponse(\n req.id,\n JSONRPC_ERROR.methodNotFound,\n `Unknown method: ${req.method}`,\n );\n }\n }\n } catch (err) {\n const error = err instanceof Error ? err : new Error(String(err));\n reportError(error);\n errorResponse(req.id, JSONRPC_ERROR.internalError, error.message);\n }\n };\n\n const handleNotification = (note: McpAppJsonRpcNotification) => {\n try {\n switch (normalizeMethod(note.method)) {\n case \"notifications/initialized\": {\n handlers.onInitialized?.();\n return;\n }\n case \"notifications/size_changed\": {\n const p = (note.params ?? {}) as { width?: number; height?: number };\n handlers.onSizeChange?.({\n ...(typeof p.width === \"number\" ? { width: p.width } : {}),\n ...(typeof p.height === \"number\" ? { height: p.height } : {}),\n });\n return;\n }\n case \"notifications/log\": {\n handlers.onLog?.(note.params);\n return;\n }\n case \"notifications/request_teardown\": {\n handlers.onRequestTeardown?.(note.params);\n return;\n }\n case \"notifications/error\": {\n const p = (note.params ?? {}) as { message?: string };\n reportError(\n new Error(\n typeof p.message === \"string\" ? p.message : \"Widget error\",\n ),\n );\n return;\n }\n default:\n return;\n }\n } catch (err) {\n const error = err instanceof Error ? err : new Error(String(err));\n reportError(error);\n }\n };\n\n // The host applies the cross-origin guard before delegating; this only\n // validates the JSON-RPC envelope.\n const onMessage = (event: MessageEvent) => {\n if (!isJsonRpcMessage(event.data)) return;\n\n const msg = event.data;\n if (isRequest(msg)) {\n void handleRequest(msg);\n } else if (isNotification(msg)) {\n handleNotification(msg);\n }\n };\n\n return {\n onMessage,\n dispose: () => {},\n notifyToolInput: (input: unknown) => {\n post({\n jsonrpc: \"2.0\",\n method: \"notifications/tools/call/input\",\n params: { input },\n });\n post({\n jsonrpc: \"2.0\",\n method: \"ui/notifications/tool-input\",\n params: isRecord(input) ? { arguments: input } : {},\n });\n },\n notifyToolResult: (result: unknown) => {\n post({\n jsonrpc: \"2.0\",\n method: \"notifications/tools/call/result\",\n params: { result },\n });\n post({\n jsonrpc: \"2.0\",\n method: \"ui/notifications/tool-result\",\n params: isRecord(result)\n ? result\n : { content: [{ type: \"text\", text: String(result) }] },\n });\n },\n notifyHostContextChanged: (ctx: McpAppHostContext) => {\n post({\n jsonrpc: \"2.0\",\n method: \"notifications/host_context/changed\",\n params: ctx,\n });\n post({\n jsonrpc: \"2.0\",\n method: \"ui/notifications/host-context-changed\",\n params: ctx,\n });\n },\n };\n}\n"],"mappings":";;;AAeA,MAAMY,sBAAsB;CAC1B;CACA;CACA;AAAK;AAoBP,MAAMkB,oBAAoC;CACxCC,MAAM;CACNC,SAAS;AACX;AAKA,MAAMC,iBAAyC;CAC7C,gCAAgC;CAChC,iCAAiC;CACjC,2BAA2B;CAC3B,gBAAgB;CAChB,2BAA2B;CAC3B,cAAc;CACd,yBAAyB;AAC3B;AAEA,MAAME,mBAAmBC,WACvBH,eAAeG,WAAWA;AAE5B,MAAMC,gBAAgB;CACpBC,YAAY;CACZC,gBAAgB;CAChBC,gBAAgB;CAChBC,eAAe;CACfC,eAAe;AACjB;AAEA,SAASC,iBAAiBC,OAA+C;CACvE,IAAI,CAACA,SAAS,OAAOA,UAAU,UAAU,OAAO;CAChD,MAAMC,IAAID;CACV,OAAOC,EAAEC,YAAY,SAAS,OAAOD,EAAET,WAAW;AACpD;AAEA,SAASW,U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IACRkC,QAAQ,EAAE1C,OAAO;GACnB,CAAC;GACDwB,KAAK;IACHN,SAAS;IACTV,QAAQ;IACRkC,QAAQ3D,SAASiB,MAAM,IACnBA,SACA,EAAEyF,SAAS,CAAC;KAAEC,MAAM;KAAQ9B,MAAMoB,OAAOhF,MAAM;IAAE,CAAC,EAAE;GAC1D,CAAC;EACH;EACAC,2BAA2B0F,QAA2B;GACpDnE,KAAK;IACHN,SAAS;IACTV,QAAQ;IACRkC,QAAQiD;GACV,CAAC;GACDnE,KAAK;IACHN,SAAS;IACTV,QAAQ;IACRkC,QAAQiD;GACV,CAAC;EACH;CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"bridge.js","names":["SandboxHostFrame","invokeUserCallback","MCP_APP_PROTOCOL_VERSION","McpAppBridgeHandlers","McpAppDisplayMode","McpAppHostContext","McpAppHostInfo","McpAppJsonRpcMessage","McpAppJsonRpcNotification","McpAppJsonRpcRequest","McpAppJsonRpcResponse","isRecord","VALID_DISPLAY_MODES","const","McpAppBridgeFrame","CreateMcpAppBridgeOptions","frame","handlers","hostInfo","hostContext","McpAppBridge","onMessage","event","MessageEvent","dispose","notifyToolInput","input","notifyToolResult","result","notifyHostContextChanged","DEFAULT_HOST_INFO","name","version","METHOD_ALIASES","Record","normalizeMethod","method","JSONRPC_ERROR","parseError","invalidRequest","methodNotFound","invalidParams","internalError","isJsonRpcMessage","value","v","jsonrpc","isRequest","msg","isNotification","createMcpAppBridge","opts","disposed","post","sendMessage","respond","id","payload","error","code","message","data","res","errorResponse","undefined","reportError","Error","onError","bind","handleRequest","req","params","requestedProtocolVersion","protocolVersion","host","capabilities","tools","callTool","resources","readResource","listResources","ui","openLink","requestDisplayMode","updateModelContext","hostCapabilities","openLinks","serverTools","serverResources","text","onLog","logging","callParams","arguments","allowedTools","includes","callArgs","Array","isArray","readParams","uri","linkParams","url","linkProtocol","URL","protocol","modeParams","mode","err","String","handleNotification","note","onInitialized","p","width","height","onSizeChange","onRequestTeardown","content","type","ctx"],"sources":["../../src/mcp-apps/bridge.ts"],"sourcesContent":["import type { SandboxHostFrame } from \"../sandbox-host/SandboxHost\";\nimport { invokeUserCallback } from \"@assistant-ui/core/internal\";\nimport {\n MCP_APP_PROTOCOL_VERSION,\n type McpAppBridgeHandlers,\n type McpAppDisplayMode,\n type McpAppHostContext,\n type McpAppHostInfo,\n type McpAppJsonRpcMessage,\n type McpAppJsonRpcNotification,\n type McpAppJsonRpcRequest,\n type McpAppJsonRpcResponse,\n} from \"./types\";\nimport { isRecord } from \"@assistant-ui/core/internal\";\n\nconst VALID_DISPLAY_MODES = [\n \"inline\",\n \"fullscreen\",\n \"pip\",\n] as const satisfies readonly McpAppDisplayMode[];\n\nexport type McpAppBridgeFrame = SandboxHostFrame;\n\nexport type CreateMcpAppBridgeOptions = {\n frame: McpAppBridgeFrame;\n handlers?: McpAppBridgeHandlers | undefined;\n hostInfo?: McpAppHostInfo | undefined;\n hostContext?: McpAppHostContext | undefined;\n};\n\nexport type McpAppBridge = {\n onMessage: (event: MessageEvent) => void;\n dispose: () => void;\n notifyToolInput: (input: unknown) => void;\n notifyToolResult: (result: unknown) => void;\n notifyHostContextChanged: (hostContext: McpAppHostContext) => void;\n};\n\nconst DEFAULT_HOST_INFO: McpAppHostInfo = {\n name: \"assistant-ui\",\n version: \"0.1\",\n};\n\n// Accept both the legacy method names and the MCP-UI 2026-01-26 names that\n// `ui/*` capable widgets (e.g. xmcp's host-bridge) emit. Normalize on input\n// so downstream switch statements only need to know the legacy names.\nconst METHOD_ALIASES: Record<string, string> = {\n \"ui/notifications/initialized\": \"notifications/initialized\",\n \"ui/notifications/size-changed\": \"notifications/size_changed\",\n \"ui/request-display-mode\": \"requestDisplayMode\",\n \"ui/open-link\": \"openLink\",\n \"ui/update-model-context\": \"updateModelContext\",\n \"ui/message\": \"sendMessage\",\n \"notifications/message\": \"notifications/log\",\n};\n\nconst normalizeMethod = (method: string): string =>\n METHOD_ALIASES[method] ?? method;\n\nconst JSONRPC_ERROR = {\n parseError: -32700,\n invalidRequest: -32600,\n methodNotFound: -32601,\n invalidParams: -32602,\n internalError: -32603,\n} as const;\n\nfunction isJsonRpcMessage(value: unknown): value is McpAppJsonRpcMessage {\n if (!value || typeof value !== \"object\") return false;\n const v = value as Record<string, unknown>;\n return v.jsonrpc === \"2.0\" && typeof v.method === \"string\";\n}\n\nfunction isRequest(msg: McpAppJsonRpcMessage): msg is McpAppJsonRpcRequest {\n return \"id\" in msg;\n}\n\nfunction isNotification(\n msg: McpAppJsonRpcMessage,\n): msg is McpAppJsonRpcNotification {\n return !(\"id\" in msg);\n}\n\nexport function createMcpAppBridge(\n opts: CreateMcpAppBridgeOptions,\n): McpAppBridge {\n const {\n frame,\n handlers = {},\n hostInfo = DEFAULT_HOST_INFO,\n hostContext = {},\n } = opts;\n let disposed = false;\n\n const post = (msg: McpAppJsonRpcMessage) => {\n if (disposed) return;\n frame.sendMessage(msg);\n };\n\n const respond = (\n id: McpAppJsonRpcRequest[\"id\"],\n payload:\n | { result: unknown }\n | { error: { code: number; message: string; data?: unknown } },\n ) => {\n const res: McpAppJsonRpcResponse = {\n jsonrpc: \"2.0\",\n id,\n ...payload,\n };\n post(res);\n };\n\n const errorResponse = (\n id: McpAppJsonRpcRequest[\"id\"],\n code: number,\n message: string,\n data?: unknown,\n ) => {\n respond(id, {\n error: {\n code,\n message,\n ...(data !== undefined ? { data } : {}),\n },\n });\n };\n\n const reportError = (error: Error) => {\n if (disposed) return;\n invokeUserCallback(\n \"assistant-ui\",\n \"MCP App onError\",\n handlers.onError?.bind(handlers),\n error,\n );\n };\n\n const handleRequest = async (req: McpAppJsonRpcRequest) => {\n try {\n const params = req.params;\n\n switch (normalizeMethod(req.method)) {\n case \"ui/initialize\": {\n const requestedProtocolVersion =\n isRecord(params) && typeof params.protocolVersion === \"string\"\n ? params.protocolVersion\n : MCP_APP_PROTOCOL_VERSION;\n respond(req.id, {\n result: {\n protocolVersion: requestedProtocolVersion,\n host: hostInfo,\n hostInfo,\n hostContext,\n capabilities: {\n tools: handlers.callTool ? {} : undefined,\n resources:\n handlers.readResource || handlers.listResources\n ? {}\n : undefined,\n ui: {\n sendMessage: !!handlers.sendMessage,\n openLink: !!handlers.openLink,\n requestDisplayMode: !!handlers.requestDisplayMode,\n updateModelContext: !!handlers.updateModelContext,\n },\n },\n hostCapabilities: {\n ...(handlers.openLink ? { openLinks: {} } : {}),\n ...(handlers.callTool ? { serverTools: {} } : {}),\n ...(handlers.readResource || handlers.listResources\n ? { serverResources: {} }\n : {}),\n ...(handlers.updateModelContext\n ? { updateModelContext: { text: {} } }\n : {}),\n ...(handlers.sendMessage ? { message: { text: {} } } : {}),\n ...(handlers.onLog ? { logging: {} } : {}),\n },\n },\n });\n return;\n }\n\n case \"tools/call\": {\n if (!handlers.callTool) {\n errorResponse(\n req.id,\n JSONRPC_ERROR.methodNotFound,\n \"tools/call is not supported by this host\",\n );\n return;\n }\n const callParams = (params ?? {}) as {\n name?: unknown;\n arguments?: unknown;\n };\n if (typeof callParams.name !== \"string\") {\n errorResponse(\n req.id,\n JSONRPC_ERROR.invalidParams,\n \"tools/call requires a string 'name'\",\n );\n return;\n }\n if (\n handlers.allowedTools &&\n !handlers.allowedTools.includes(callParams.name)\n ) {\n errorResponse(\n req.id,\n JSONRPC_ERROR.invalidParams,\n `tool '${callParams.name}' is not allowed for this app`,\n );\n return;\n }\n let callArgs: Record<string, unknown> | undefined;\n if (callParams.arguments !== undefined) {\n if (\n callParams.arguments === null ||\n typeof callParams.arguments !== \"object\" ||\n Array.isArray(callParams.arguments)\n ) {\n errorResponse(\n req.id,\n JSONRPC_ERROR.invalidParams,\n \"tools/call 'arguments' must be an object\",\n );\n return;\n }\n callArgs = callParams.arguments as Record<string, unknown>;\n }\n const result = await handlers.callTool({\n name: callParams.name,\n ...(callArgs !== undefined ? { arguments: callArgs } : {}),\n });\n respond(req.id, { result });\n return;\n }\n\n case \"resources/read\": {\n if (!handlers.readResource) {\n errorResponse(\n req.id,\n JSONRPC_ERROR.methodNotFound,\n \"resources/read is not supported by this host\",\n );\n return;\n }\n const readParams = (params ?? {}) as { uri?: unknown };\n if (typeof readParams.uri !== \"string\") {\n errorResponse(\n req.id,\n JSONRPC_ERROR.invalidParams,\n \"resources/read requires a string 'uri'\",\n );\n return;\n }\n respond(req.id, {\n result: await handlers.readResource({ uri: readParams.uri }),\n });\n return;\n }\n\n case \"resources/list\": {\n if (!handlers.listResources) {\n errorResponse(\n req.id,\n JSONRPC_ERROR.methodNotFound,\n \"resources/list is not supported by this host\",\n );\n return;\n }\n respond(req.id, {\n result: (await handlers.listResources(params)) ?? null,\n });\n return;\n }\n\n case \"openLink\": {\n if (!handlers.openLink) {\n errorResponse(\n req.id,\n JSONRPC_ERROR.methodNotFound,\n \"openLink is not supported by this host\",\n );\n return;\n }\n const linkParams = (params ?? {}) as { url?: unknown };\n if (typeof linkParams.url !== \"string\") {\n errorResponse(\n req.id,\n JSONRPC_ERROR.invalidParams,\n \"openLink requires a string 'url'\",\n );\n return;\n }\n let linkProtocol: string;\n try {\n linkProtocol = new URL(linkParams.url).protocol;\n } catch {\n errorResponse(\n req.id,\n JSONRPC_ERROR.invalidParams,\n \"openLink requires a valid URL\",\n );\n return;\n }\n if (linkProtocol !== \"https:\" && linkProtocol !== \"http:\") {\n errorResponse(\n req.id,\n JSONRPC_ERROR.invalidParams,\n \"openLink only accepts http(s) URLs\",\n );\n return;\n }\n respond(req.id, {\n result: await handlers.openLink({ url: linkParams.url }),\n });\n return;\n }\n\n case \"sendMessage\": {\n if (!handlers.sendMessage) {\n errorResponse(\n req.id,\n JSONRPC_ERROR.methodNotFound,\n \"sendMessage is not supported by this host\",\n );\n return;\n }\n respond(req.id, {\n result: (await handlers.sendMessage(params)) ?? null,\n });\n return;\n }\n\n case \"updateModelContext\": {\n if (!handlers.updateModelContext) {\n errorResponse(\n req.id,\n JSONRPC_ERROR.methodNotFound,\n \"updateModelContext is not supported by this host\",\n );\n return;\n }\n respond(req.id, {\n result: (await handlers.updateModelContext(params)) ?? null,\n });\n return;\n }\n\n case \"requestDisplayMode\": {\n if (!handlers.requestDisplayMode) {\n errorResponse(\n req.id,\n JSONRPC_ERROR.methodNotFound,\n \"requestDisplayMode is not supported by this host\",\n );\n return;\n }\n const modeParams = (params ?? {}) as { mode?: unknown };\n if (\n typeof modeParams.mode !== \"string\" ||\n !VALID_DISPLAY_MODES.includes(modeParams.mode as McpAppDisplayMode)\n ) {\n errorResponse(\n req.id,\n JSONRPC_ERROR.invalidParams,\n \"requestDisplayMode requires a valid 'mode'\",\n );\n return;\n }\n respond(req.id, {\n result: await handlers.requestDisplayMode({\n mode: modeParams.mode as McpAppDisplayMode,\n }),\n });\n return;\n }\n\n default: {\n errorResponse(\n req.id,\n JSONRPC_ERROR.methodNotFound,\n `Unknown method: ${req.method}`,\n );\n }\n }\n } catch (err) {\n const error = err instanceof Error ? err : new Error(String(err));\n reportError(error);\n errorResponse(req.id, JSONRPC_ERROR.internalError, error.message);\n }\n };\n\n const handleNotification = (note: McpAppJsonRpcNotification) => {\n try {\n switch (normalizeMethod(note.method)) {\n case \"notifications/initialized\": {\n handlers.onInitialized?.();\n return;\n }\n case \"notifications/size_changed\": {\n const p = (note.params ?? {}) as { width?: number; height?: number };\n handlers.onSizeChange?.({\n ...(typeof p.width === \"number\" ? { width: p.width } : {}),\n ...(typeof p.height === \"number\" ? { height: p.height } : {}),\n });\n return;\n }\n case \"notifications/log\": {\n handlers.onLog?.(note.params);\n return;\n }\n case \"notifications/request_teardown\": {\n handlers.onRequestTeardown?.(note.params);\n return;\n }\n case \"notifications/error\": {\n const p = (note.params ?? {}) as { message?: string };\n reportError(\n new Error(\n typeof p.message === \"string\" ? p.message : \"Widget error\",\n ),\n );\n return;\n }\n default:\n return;\n }\n } catch (err) {\n const error = err instanceof Error ? err : new Error(String(err));\n reportError(error);\n }\n };\n\n // The host applies the cross-origin guard before delegating; this only\n // validates the JSON-RPC envelope.\n const onMessage = (event: MessageEvent) => {\n if (disposed) return;\n if (!isJsonRpcMessage(event.data)) return;\n\n const msg = event.data;\n if (isRequest(msg)) {\n void handleRequest(msg);\n } else if (isNotification(msg)) {\n handleNotification(msg);\n }\n };\n\n return {\n onMessage,\n dispose: () => {\n disposed = true;\n },\n notifyToolInput: (input: unknown) => {\n post({\n jsonrpc: \"2.0\",\n method: \"notifications/tools/call/input\",\n params: { input },\n });\n post({\n jsonrpc: \"2.0\",\n method: \"ui/notifications/tool-input\",\n params: isRecord(input) ? { arguments: input } : {},\n });\n },\n notifyToolResult: (result: unknown) => {\n post({\n jsonrpc: \"2.0\",\n method: \"notifications/tools/call/result\",\n params: { result },\n });\n post({\n jsonrpc: \"2.0\",\n method: \"ui/notifications/tool-result\",\n params: isRecord(result)\n ? result\n : { content: [{ type: \"text\", text: String(result) }] },\n });\n },\n notifyHostContextChanged: (ctx: McpAppHostContext) => {\n post({\n jsonrpc: \"2.0\",\n method: \"notifications/host_context/changed\",\n params: ctx,\n });\n post({\n jsonrpc: \"2.0\",\n method: \"ui/notifications/host-context-changed\",\n params: ctx,\n });\n },\n };\n}\n"],"mappings":";;;AAeA,MAAMY,sBAAsB;CAC1B;CACA;CACA;AAAK;AAoBP,MAAMkB,oBAAoC;CACxCC,MAAM;CACNC,SAAS;AACX;AAKA,MAAMC,iBAAyC;CAC7C,gCAAgC;CAChC,iCAAiC;CACjC,2BAA2B;CAC3B,gBAAgB;CAChB,2BAA2B;CAC3B,cAAc;CACd,yBAAyB;AAC3B;AAEA,MAAME,mBAAmBC,WACvBH,eAAeG,WAAWA;AAE5B,MAAMC,gBAAgB;CACpBC,YAAY;CACZC,gBAAgB;CAChBC,gBAAgB;CAChBC,eAAe;CACfC,eAAe;AACjB;AAEA,SAASC,iBAAiBC,OAA+C;CACvE,IAAI,CAACA,SAAS,OAAOA,UAAU,UAAU,OAAO;CAChD,MAAMC,IAAID;CACV,OAAOC,EAAEC,YAAY,SAAS,OAAOD,EAAET,WAAW;AACpD;AAEA,SAASW,UAAUC,KAAwD;CACzE,O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ACAC,mBAAmBC,WAAoB;GACrCyB,KAAK;IACHP,SAAS;IACTV,QAAQ;IACRmC,QAAQ,EAAE3C,OAAO;GACnB,CAAC;GACDyB,KAAK;IACHP,SAAS;IACTV,QAAQ;IACRmC,QAAQ5D,SAASiB,MAAM,IACnBA,SACA,EAAE0F,SAAS,CAAC;KAAEC,MAAM;KAAQ9B,MAAMoB,OAAOjF,MAAM;IAAE,CAAC,EAAE;GAC1D,CAAC;EACH;EACAC,2BAA2B2F,QAA2B;GACpDnE,KAAK;IACHP,SAAS;IACTV,QAAQ;IACRmC,QAAQiD;GACV,CAAC;GACDnE,KAAK;IACHP,SAAS;IACTV,QAAQ;IACRmC,QAAQiD;GACV,CAAC;EACH;CACF;AACF"}
|
|
@@ -32,8 +32,26 @@ const useAssistantFrameHost = (t0) => {
|
|
|
32
32
|
const frameHost = new AssistantFrameHost(iframeWindow, targetOrigin);
|
|
33
33
|
const unsubscribe = register(frameHost);
|
|
34
34
|
return () => {
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
let cleanupFailed = false;
|
|
36
|
+
let cleanupError;
|
|
37
|
+
try {
|
|
38
|
+
frameHost.dispose();
|
|
39
|
+
} catch (t3) {
|
|
40
|
+
const error = t3;
|
|
41
|
+
cleanupFailed = true;
|
|
42
|
+
cleanupError = error;
|
|
43
|
+
}
|
|
44
|
+
try {
|
|
45
|
+
unsubscribe();
|
|
46
|
+
} catch (t4) {
|
|
47
|
+
const error_0 = t4;
|
|
48
|
+
if (cleanupFailed) console.error("[assistant-ui] AssistantFrameHost unregistration failed.", error_0);
|
|
49
|
+
else {
|
|
50
|
+
cleanupFailed = true;
|
|
51
|
+
cleanupError = error_0;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
if (cleanupFailed) throw cleanupError;
|
|
37
55
|
};
|
|
38
56
|
};
|
|
39
57
|
t2 = [
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useAssistantFrameHost.js","names":["c","_c","Unsubscribe","useEffect","RefObject","AssistantFrameHost","UseAssistantFrameHostOptions","iframeRef","Readonly","HTMLIFrameElement","targetOrigin","register","frameHost","useAssistantFrameHost","t0","$","t1","t2","iframeWindow","current","contentWindow","unsubscribe","dispose"],"sources":["../../../src/model-context/frame/useAssistantFrameHost.ts"],"sourcesContent":["\"use client\";\n\nimport type { Unsubscribe } from \"@assistant-ui/core\";\nimport { useEffect, type RefObject } from \"react\";\nimport { AssistantFrameHost } from \"@assistant-ui/core\";\n\ntype UseAssistantFrameHostOptions = {\n iframeRef: Readonly<RefObject<HTMLIFrameElement | null | undefined>>;\n targetOrigin?: string;\n register: (frameHost: AssistantFrameHost) => Unsubscribe;\n};\n\n/**\n * React hook that manages the lifecycle of an AssistantFrameHost and its binding to the current AssistantRuntime.\n *\n * Usage example:\n * ```typescript\n * function MyComponent() {\n * const iframeRef = useRef<HTMLIFrameElement>(null);\n *\n * useAssistantFrameHost({\n * iframeRef,\n * targetOrigin: \"https://trusted-domain.com\",\n * });\n *\n * return <iframe ref={iframeRef} src=\"...\" />;\n * }\n * ```\n */\nexport const useAssistantFrameHost = ({\n iframeRef,\n targetOrigin,\n register,\n}: UseAssistantFrameHostOptions): void => {\n useEffect(() => {\n const iframeWindow = iframeRef.current?.contentWindow;\n if (!iframeWindow) return;\n\n const frameHost = new AssistantFrameHost(iframeWindow, targetOrigin);\n\n const unsubscribe = register(frameHost);\n\n return () => {\n frameHost.dispose();\n unsubscribe();\n };\n }, [iframeRef, targetOrigin, register]);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AA6BA,MAAaa,yBAAwBC,OAAA;CAAA,MAAAC,IAAAd,EAAA,CAAA;CAAC,MAAA,EAAAM,WAAAG,cAAAC,aAAAG;CAIP,IAAAE;CAAA,IAAAC;CAAA,IAAAF,EAAA,OAAAR,aAAAQ,EAAA,OAAAJ,YAAAI,EAAA,OAAAL,cAAA;EACnBM,WAAA;GACR,MAAAE,eAAqBX,UAASY,SAAuBC;GACrD,IAAI,CAACF,cAAY;GAEjB,MAAAN,YAAkB,IAAIP,mBAAmBa,cAAcR,YAAY;GAEnE,MAAAW,cAAoBV,SAASC,SAAS;GAAE,aAEjC;
|
|
1
|
+
{"version":3,"file":"useAssistantFrameHost.js","names":["c","_c","Unsubscribe","useEffect","RefObject","AssistantFrameHost","UseAssistantFrameHostOptions","iframeRef","Readonly","HTMLIFrameElement","targetOrigin","register","frameHost","useAssistantFrameHost","t0","$","t1","t2","iframeWindow","current","contentWindow","unsubscribe","cleanupFailed","cleanupError","dispose","t3","error","t4","console"],"sources":["../../../src/model-context/frame/useAssistantFrameHost.ts"],"sourcesContent":["\"use client\";\n\nimport type { Unsubscribe } from \"@assistant-ui/core\";\nimport { useEffect, type RefObject } from \"react\";\nimport { AssistantFrameHost } from \"@assistant-ui/core\";\n\ntype UseAssistantFrameHostOptions = {\n iframeRef: Readonly<RefObject<HTMLIFrameElement | null | undefined>>;\n targetOrigin?: string;\n register: (frameHost: AssistantFrameHost) => Unsubscribe;\n};\n\n/**\n * React hook that manages the lifecycle of an AssistantFrameHost and its binding to the current AssistantRuntime.\n *\n * Usage example:\n * ```typescript\n * function MyComponent() {\n * const iframeRef = useRef<HTMLIFrameElement>(null);\n *\n * useAssistantFrameHost({\n * iframeRef,\n * targetOrigin: \"https://trusted-domain.com\",\n * });\n *\n * return <iframe ref={iframeRef} src=\"...\" />;\n * }\n * ```\n */\nexport const useAssistantFrameHost = ({\n iframeRef,\n targetOrigin,\n register,\n}: UseAssistantFrameHostOptions): void => {\n useEffect(() => {\n const iframeWindow = iframeRef.current?.contentWindow;\n if (!iframeWindow) return;\n\n const frameHost = new AssistantFrameHost(iframeWindow, targetOrigin);\n\n const unsubscribe = register(frameHost);\n\n return () => {\n let cleanupFailed = false;\n let cleanupError: unknown;\n\n try {\n frameHost.dispose();\n } catch (error) {\n cleanupFailed = true;\n cleanupError = error;\n }\n\n try {\n unsubscribe();\n } catch (error) {\n if (cleanupFailed) {\n console.error(\n \"[assistant-ui] AssistantFrameHost unregistration failed.\",\n error,\n );\n } else {\n cleanupFailed = true;\n cleanupError = error;\n }\n }\n\n if (cleanupFailed) throw cleanupError;\n };\n }, [iframeRef, targetOrigin, register]);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AA6BA,MAAaa,yBAAwBC,OAAA;CAAA,MAAAC,IAAAd,EAAA,CAAA;CAAC,MAAA,EAAAM,WAAAG,cAAAC,aAAAG;CAIP,IAAAE;CAAA,IAAAC;CAAA,IAAAF,EAAA,OAAAR,aAAAQ,EAAA,OAAAJ,YAAAI,EAAA,OAAAL,cAAA;EACnBM,WAAA;GACR,MAAAE,eAAqBX,UAASY,SAAuBC;GACrD,IAAI,CAACF,cAAY;GAEjB,MAAAN,YAAkB,IAAIP,mBAAmBa,cAAcR,YAAY;GAEnE,MAAAW,cAAoBV,SAASC,SAAS;GAAE,aAEjC;IACL,IAAAU,gBAAoB;IAChBC,IAAAA;IAEJ,IAAA;KACEX,UAASY,QAAS;IAAC,SAAAC,IAAA;KACZC,MAAAA,QAAAA;KACPJ,gBAAgBA;KAChBC,eAAeG;IAAH;IAGd,IAAA;KACEL,YAAY;IAAC,SAAAM,IAAA;KACND,MAAAA,UAAAA;KACP,IAAIJ,eACFM,QAAOF,MACL,4DACAA,OACF;UAAC;MAEDJ,gBAAgBA;MAChBC,eAAeG;KAAH;IACb;IAGH,IAAIJ,eAAe,MAAMC;GAAa;EACvC;EACAN,KAAA;GAACV;GAAWG;GAAcC;EAAQ;EAACI,EAAA,KAAAR;EAAAQ,EAAA,KAAAJ;EAAAI,EAAA,KAAAL;EAAAK,EAAA,KAAAC;EAAAD,EAAA,KAAAE;CAAA,OAAA;EAAAD,KAAAD,EAAA;EAAAE,KAAAF,EAAA;CAAA;CAnCtCZ,UAAUa,IAmCPC,EAAmC;AAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AssistantModalRoot.d.ts","names":[],"sources":["../../../src/primitives/assistantModal/AssistantModalRoot.tsx"],"mappings":";;;kBAOiB;OACH,QAAQ,QAAiB;IACnC;;;
|
|
1
|
+
{"version":3,"file":"AssistantModalRoot.d.ts","names":[],"sources":["../../../src/primitives/assistantModal/AssistantModalRoot.tsx"],"mappings":";;;kBAOiB;OACH,QAAQ,QAAiB;IACnC;;;cAIS,6BAA6B,GACxC,4BAA4B"}
|
|
@@ -1,109 +1,77 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { usePopoverScope } from "./scope.js";
|
|
3
3
|
import { c } from "@assistant-ui/tap/react-shim/compiler-runtime";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
4
|
+
import { useAuiEvent } from "@assistant-ui/store";
|
|
5
|
+
import { useState } from "@assistant-ui/tap/react-shim";
|
|
6
6
|
import { jsx } from "react/jsx-runtime";
|
|
7
7
|
import { Popover } from "radix-ui";
|
|
8
8
|
//#region src/primitives/assistantModal/AssistantModalRoot.tsx
|
|
9
|
-
const useAssistantModalOpenState = (t0) => {
|
|
10
|
-
const $ = c(5);
|
|
11
|
-
const { defaultOpen: t1, unstable_openOnRunStart: t2 } = t0;
|
|
12
|
-
const defaultOpen = t1 === void 0 ? false : t1;
|
|
13
|
-
const unstable_openOnRunStart = t2 === void 0 ? true : t2;
|
|
14
|
-
const state = useState(defaultOpen);
|
|
15
|
-
const [, setOpen] = state;
|
|
16
|
-
const aui = useAui();
|
|
17
|
-
let t3;
|
|
18
|
-
let t4;
|
|
19
|
-
if ($[0] !== aui || $[1] !== setOpen || $[2] !== unstable_openOnRunStart) {
|
|
20
|
-
t3 = () => {
|
|
21
|
-
if (!unstable_openOnRunStart) return;
|
|
22
|
-
return aui.on("thread.runStart", () => {
|
|
23
|
-
setOpen(true);
|
|
24
|
-
});
|
|
25
|
-
};
|
|
26
|
-
t4 = [
|
|
27
|
-
unstable_openOnRunStart,
|
|
28
|
-
aui,
|
|
29
|
-
setOpen
|
|
30
|
-
];
|
|
31
|
-
$[0] = aui;
|
|
32
|
-
$[1] = setOpen;
|
|
33
|
-
$[2] = unstable_openOnRunStart;
|
|
34
|
-
$[3] = t3;
|
|
35
|
-
$[4] = t4;
|
|
36
|
-
} else {
|
|
37
|
-
t3 = $[3];
|
|
38
|
-
t4 = $[4];
|
|
39
|
-
}
|
|
40
|
-
useEffect(t3, t4);
|
|
41
|
-
return state;
|
|
42
|
-
};
|
|
43
9
|
const AssistantModalPrimitiveRoot = (t0) => {
|
|
44
10
|
const $ = c(18);
|
|
45
11
|
let __scopeAssistantModal;
|
|
46
|
-
let defaultOpen;
|
|
47
12
|
let onOpenChange;
|
|
48
13
|
let open;
|
|
49
14
|
let rest;
|
|
50
|
-
let
|
|
15
|
+
let t1;
|
|
16
|
+
let t2;
|
|
51
17
|
if ($[0] !== t0) {
|
|
52
|
-
({__scopeAssistantModal, defaultOpen, unstable_openOnRunStart, open, onOpenChange, ...rest} = t0);
|
|
18
|
+
({__scopeAssistantModal, defaultOpen: t1, unstable_openOnRunStart: t2, open, onOpenChange, ...rest} = t0);
|
|
53
19
|
$[0] = t0;
|
|
54
20
|
$[1] = __scopeAssistantModal;
|
|
55
|
-
$[2] =
|
|
56
|
-
$[3] =
|
|
57
|
-
$[4] =
|
|
58
|
-
$[5] =
|
|
59
|
-
$[6] =
|
|
21
|
+
$[2] = onOpenChange;
|
|
22
|
+
$[3] = open;
|
|
23
|
+
$[4] = rest;
|
|
24
|
+
$[5] = t1;
|
|
25
|
+
$[6] = t2;
|
|
60
26
|
} else {
|
|
61
27
|
__scopeAssistantModal = $[1];
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
28
|
+
onOpenChange = $[2];
|
|
29
|
+
open = $[3];
|
|
30
|
+
rest = $[4];
|
|
31
|
+
t1 = $[5];
|
|
32
|
+
t2 = $[6];
|
|
67
33
|
}
|
|
34
|
+
const defaultOpen = t1 === void 0 ? false : t1;
|
|
35
|
+
const unstable_openOnRunStart = t2 === void 0 ? true : t2;
|
|
68
36
|
const scope = usePopoverScope(__scopeAssistantModal);
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
};
|
|
75
|
-
$[7] = defaultOpen;
|
|
76
|
-
$[8] = unstable_openOnRunStart;
|
|
77
|
-
$[9] = t1;
|
|
78
|
-
} else t1 = $[9];
|
|
79
|
-
const [modalOpen, setOpen] = useAssistantModalOpenState(t1);
|
|
80
|
-
let t2;
|
|
81
|
-
if ($[10] !== onOpenChange || $[11] !== setOpen) {
|
|
82
|
-
t2 = (open_0) => {
|
|
37
|
+
const [modalOpen, setOpen] = useState(defaultOpen);
|
|
38
|
+
const isOpen = open ?? modalOpen;
|
|
39
|
+
let t3;
|
|
40
|
+
if ($[7] !== onOpenChange) {
|
|
41
|
+
t3 = (open_0) => {
|
|
83
42
|
onOpenChange?.(open_0);
|
|
84
43
|
setOpen(open_0);
|
|
85
44
|
};
|
|
86
|
-
$[
|
|
87
|
-
$[
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
const openChangeHandler = t2;
|
|
91
|
-
const t3 = open === void 0 ? modalOpen : open;
|
|
45
|
+
$[7] = onOpenChange;
|
|
46
|
+
$[8] = t3;
|
|
47
|
+
} else t3 = $[8];
|
|
48
|
+
const openChangeHandler = t3;
|
|
92
49
|
let t4;
|
|
93
|
-
if ($[
|
|
94
|
-
t4 =
|
|
50
|
+
if ($[9] !== isOpen || $[10] !== openChangeHandler || $[11] !== unstable_openOnRunStart) {
|
|
51
|
+
t4 = () => {
|
|
52
|
+
if (unstable_openOnRunStart && !isOpen) openChangeHandler(true);
|
|
53
|
+
};
|
|
54
|
+
$[9] = isOpen;
|
|
55
|
+
$[10] = openChangeHandler;
|
|
56
|
+
$[11] = unstable_openOnRunStart;
|
|
57
|
+
$[12] = t4;
|
|
58
|
+
} else t4 = $[12];
|
|
59
|
+
useAuiEvent("thread.runStart", t4);
|
|
60
|
+
let t5;
|
|
61
|
+
if ($[13] !== isOpen || $[14] !== openChangeHandler || $[15] !== rest || $[16] !== scope) {
|
|
62
|
+
t5 = /* @__PURE__ */ jsx(Popover.Root, {
|
|
95
63
|
...scope,
|
|
96
|
-
open:
|
|
64
|
+
open: isOpen,
|
|
97
65
|
onOpenChange: openChangeHandler,
|
|
98
66
|
...rest
|
|
99
67
|
});
|
|
100
|
-
$[13] =
|
|
101
|
-
$[14] =
|
|
102
|
-
$[15] =
|
|
103
|
-
$[16] =
|
|
104
|
-
$[17] =
|
|
105
|
-
} else
|
|
106
|
-
return
|
|
68
|
+
$[13] = isOpen;
|
|
69
|
+
$[14] = openChangeHandler;
|
|
70
|
+
$[15] = rest;
|
|
71
|
+
$[16] = scope;
|
|
72
|
+
$[17] = t5;
|
|
73
|
+
} else t5 = $[17];
|
|
74
|
+
return t5;
|
|
107
75
|
};
|
|
108
76
|
AssistantModalPrimitiveRoot.displayName = "AssistantModalPrimitive.Root";
|
|
109
77
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AssistantModalRoot.js","names":["c","_c","FC","
|
|
1
|
+
{"version":3,"file":"AssistantModalRoot.js","names":["c","_c","FC","useState","Popover","PopoverPrimitive","ScopedProps","usePopoverScope","useAuiEvent","AssistantModalPrimitiveRoot","Props","PopoverProps","unstable_openOnRunStart","t0","$","__scopeAssistantModal","onOpenChange","open","rest","t1","t2","defaultOpen","undefined","scope","modalOpen","setOpen","isOpen","t3","open_0","openChangeHandler","t4","t5","displayName"],"sources":["../../../src/primitives/assistantModal/AssistantModalRoot.tsx"],"sourcesContent":["\"use client\";\n\nimport { type FC, useState } from \"react\";\nimport { Popover as PopoverPrimitive } from \"radix-ui\";\nimport { type ScopedProps, usePopoverScope } from \"./scope\";\nimport { useAuiEvent } from \"@assistant-ui/store\";\n\nexport namespace AssistantModalPrimitiveRoot {\n export type Props = PopoverPrimitive.PopoverProps & {\n unstable_openOnRunStart?: boolean | undefined;\n };\n}\n\nexport const AssistantModalPrimitiveRoot: FC<\n AssistantModalPrimitiveRoot.Props\n> = ({\n __scopeAssistantModal,\n defaultOpen = false,\n unstable_openOnRunStart = true,\n open,\n onOpenChange,\n ...rest\n}: ScopedProps<AssistantModalPrimitiveRoot.Props>) => {\n const scope = usePopoverScope(__scopeAssistantModal);\n\n const [modalOpen, setOpen] = useState(defaultOpen);\n const isOpen = open ?? modalOpen;\n\n const openChangeHandler = (open: boolean) => {\n onOpenChange?.(open);\n setOpen(open);\n };\n\n useAuiEvent(\"thread.runStart\", () => {\n if (unstable_openOnRunStart && !isOpen) openChangeHandler(true);\n });\n\n return (\n <PopoverPrimitive.Root\n {...scope}\n open={isOpen}\n onOpenChange={openChangeHandler}\n {...rest}\n />\n );\n};\n\nAssistantModalPrimitiveRoot.displayName = \"AssistantModalPrimitive.Root\";\n"],"mappings":";;;;;;;;AAaA,MAAaS,+BAETI,OAAA;CAAA,MAAAC,IAAAb,EAAA,EAAA;CAAA,IAAAc;CAAA,IAAAC;CAAA,IAAAC;CAAA,IAAAC;CAAA,IAAAC;CAAA,IAAAC;CAAA,IAAAN,EAAA,OAAAD,IAAA;EAAC,CAAA,CAAAE,uBAAAM,aAAAF,IAAAP,yBAAAQ,IAAAH,MAAAD,cAAA,GAAAE,QAAAL;EAO4CC,EAAA,KAAAD;EAAAC,EAAA,KAAAC;EAAAD,EAAA,KAAAE;EAAAF,EAAA,KAAAG;EAAAH,EAAA,KAAAI;EAAAJ,EAAA,KAAAK;EAAAL,EAAA,KAAAM;CAAA,OAAA;EAAAL,wBAAAD,EAAA;EAAAE,eAAAF,EAAA;EAAAG,OAAAH,EAAA;EAAAI,OAAAJ,EAAA;EAAAK,KAAAL,EAAA;EAAAM,KAAAN,EAAA;CAAA;CAL/C,MAAAO,cAAAF,OAAAG,KAAAA,IAAA,QAAAH;CACA,MAAAP,0BAAAQ,OAAAE,KAAAA,IAAA,OAAAF;CAKA,MAAAG,QAAchB,gBAAgBQ,qBAAqB;CAEnD,MAAA,CAAAS,WAAAC,WAA6BtB,SAASkB,WAAW;CACjD,MAAAK,SAAeT,QAAAO;CAAkB,IAAAG;CAAA,IAAAb,EAAA,OAAAE,cAAA;EAEPW,MAAAC,WAAA;GACxBZ,eAAeC,MAAI;GACnBQ,QAAQR,MAAI;EAAC;EACdH,EAAA,KAAAE;EAAAF,EAAA,KAAAa;CAAA,OAAAA,KAAAb,EAAA;CAHD,MAAAe,oBAA0BF;CAGxB,IAAAG;CAAA,IAAAhB,EAAA,OAAAY,UAAAZ,EAAA,QAAAe,qBAAAf,EAAA,QAAAF,yBAAA;EAE6BkB,WAAA;GAC7B,IAAIlB,2BAAA,CAA4Bc,QAAQG,kBAAkB,IAAI;EAAE;EACjEf,EAAA,KAAAY;EAAAZ,EAAA,MAAAe;EAAAf,EAAA,MAAAF;EAAAE,EAAA,MAAAgB;CAAA,OAAAA,KAAAhB,EAAA;CAFDN,YAAY,mBAAmBsB,EAE9B;CAAC,IAAAC;CAAA,IAAAjB,EAAA,QAAAY,UAAAZ,EAAA,QAAAe,qBAAAf,EAAA,QAAAI,QAAAJ,EAAA,QAAAS,OAAA;EAGAQ,KAAA,oBAAA,QAAA,MAAA;GAAA,GACMR;GACEG,MAAAA;GACQG,cAAAA;GAAiB,GAC3BX;EAAI,CAAA;EACRJ,EAAA,MAAAY;EAAAZ,EAAA,MAAAe;EAAAf,EAAA,MAAAI;EAAAJ,EAAA,MAAAS;EAAAT,EAAA,MAAAiB;CAAA,OAAAA,KAAAjB,EAAA;CAAA,OALFiB;AAKE;AAINtB,4BAA4BuB,cAAc"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ComposerAttachmentDropzone.d.ts","names":[],"sources":["../../../src/primitives/composer/ComposerAttachmentDropzone.tsx"],"mappings":";;kBAgBiB;OACH,UAAU;OACV,QAAQ,MAAM,eAAe;IACvC;IACA,SAAS;IACT;;;cAIS,qCAAmC,MAAA,0BAAA,MAAA,eAAA;EANlC;EACD,SAAA;EACE;
|
|
1
|
+
{"version":3,"file":"ComposerAttachmentDropzone.d.ts","names":[],"sources":["../../../src/primitives/composer/ComposerAttachmentDropzone.tsx"],"mappings":";;kBAgBiB;OACH,UAAU;OACV,QAAQ,MAAM,eAAe;IACvC;IACA,SAAS;IACT;;;cAIS,qCAAmC,MAAA,0BAAA,MAAA,eAAA;EANlC;EACD,SAAA;EACE;IAsGb,MAAA,cAAA"}
|
|
@@ -1,150 +1,73 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import {
|
|
2
|
+
import { renderSlot } from "../../utils/Primitive.js";
|
|
3
3
|
import { useAui } from "@assistant-ui/store";
|
|
4
|
-
import {
|
|
4
|
+
import { forwardRef, isValidElement, useCallback, useState } from "@assistant-ui/tap/react-shim";
|
|
5
5
|
import { jsx } from "react/jsx-runtime";
|
|
6
6
|
import { composeEventHandlers } from "radix-ui/internal";
|
|
7
7
|
import { Slot } from "radix-ui";
|
|
8
8
|
//#region src/primitives/composer/ComposerAttachmentDropzone.tsx
|
|
9
|
-
const ComposerPrimitiveAttachmentDropzone = forwardRef((
|
|
10
|
-
const $ = c(32);
|
|
11
|
-
const { disabled, asChild: t1, render, children, ...rest } = t0;
|
|
12
|
-
const asChild = t1 === void 0 ? false : t1;
|
|
9
|
+
const ComposerPrimitiveAttachmentDropzone = forwardRef(({ disabled, asChild = false, render, children, ...rest }, ref) => {
|
|
13
10
|
const [isDragging, setIsDragging] = useState(false);
|
|
14
11
|
const aui = useAui();
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
e.
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
e_2.preventDefault();
|
|
70
|
-
const files = Array.from(e_2.dataTransfer.files);
|
|
71
|
-
if (!aui.thread.getState().capabilities.attachments || files.length === 0) return;
|
|
72
|
-
await Promise.all(files.map(async (file) => {
|
|
73
|
-
try {
|
|
74
|
-
await aui.composer.addAttachment(file);
|
|
75
|
-
} catch {}
|
|
76
|
-
}));
|
|
77
|
-
};
|
|
78
|
-
$[9] = aui;
|
|
79
|
-
$[10] = disabled;
|
|
80
|
-
$[11] = t5;
|
|
81
|
-
} else t5 = $[11];
|
|
82
|
-
const handleDrop = t5;
|
|
83
|
-
let t6;
|
|
84
|
-
if ($[12] !== isDragging) {
|
|
85
|
-
t6 = isDragging ? { "data-dragging": "true" } : null;
|
|
86
|
-
$[12] = isDragging;
|
|
87
|
-
$[13] = t6;
|
|
88
|
-
} else t6 = $[13];
|
|
89
|
-
const t7 = composeEventHandlers(rest.onDragEnterCapture, handleDragEnterCapture);
|
|
90
|
-
const t8 = composeEventHandlers(rest.onDragOverCapture, handleDragOverCapture);
|
|
91
|
-
const t9 = composeEventHandlers(rest.onDragLeaveCapture, handleDragLeaveCapture);
|
|
92
|
-
const t10 = composeEventHandlers(rest.onDropCapture, handleDrop);
|
|
93
|
-
let t11;
|
|
94
|
-
if ($[14] !== ref || $[15] !== rest || $[16] !== t10 || $[17] !== t6 || $[18] !== t7 || $[19] !== t8 || $[20] !== t9) {
|
|
95
|
-
t11 = {
|
|
96
|
-
...t6,
|
|
97
|
-
...rest,
|
|
98
|
-
onDragEnterCapture: t7,
|
|
99
|
-
onDragOverCapture: t8,
|
|
100
|
-
onDragLeaveCapture: t9,
|
|
101
|
-
onDropCapture: t10,
|
|
102
|
-
ref
|
|
103
|
-
};
|
|
104
|
-
$[14] = ref;
|
|
105
|
-
$[15] = rest;
|
|
106
|
-
$[16] = t10;
|
|
107
|
-
$[17] = t6;
|
|
108
|
-
$[18] = t7;
|
|
109
|
-
$[19] = t8;
|
|
110
|
-
$[20] = t9;
|
|
111
|
-
$[21] = t11;
|
|
112
|
-
} else t11 = $[21];
|
|
113
|
-
const mergedProps = t11;
|
|
114
|
-
if (render && isValidElement(render)) {
|
|
115
|
-
const t12 = children !== void 0 ? children : render.props.children;
|
|
116
|
-
let t13;
|
|
117
|
-
if ($[22] !== render || $[23] !== t12) {
|
|
118
|
-
t13 = cloneElement(render, void 0, t12);
|
|
119
|
-
$[22] = render;
|
|
120
|
-
$[23] = t12;
|
|
121
|
-
$[24] = t13;
|
|
122
|
-
} else t13 = $[24];
|
|
123
|
-
let t14;
|
|
124
|
-
if ($[25] !== mergedProps || $[26] !== t13) {
|
|
125
|
-
t14 = /* @__PURE__ */ jsx(Slot.Root, {
|
|
126
|
-
...mergedProps,
|
|
127
|
-
children: t13
|
|
128
|
-
});
|
|
129
|
-
$[25] = mergedProps;
|
|
130
|
-
$[26] = t13;
|
|
131
|
-
$[27] = t14;
|
|
132
|
-
} else t14 = $[27];
|
|
133
|
-
return t14;
|
|
134
|
-
}
|
|
12
|
+
const handleDragEnterCapture = useCallback((e) => {
|
|
13
|
+
if (disabled) return;
|
|
14
|
+
if (!e.dataTransfer.types.includes("Files")) return;
|
|
15
|
+
e.preventDefault();
|
|
16
|
+
if (!aui.thread.getState().capabilities.attachments) {
|
|
17
|
+
e.dataTransfer.dropEffect = "none";
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
setIsDragging(true);
|
|
21
|
+
}, [disabled, aui]);
|
|
22
|
+
const handleDragOverCapture = useCallback((e_0) => {
|
|
23
|
+
if (disabled) return;
|
|
24
|
+
if (!e_0.dataTransfer.types.includes("Files")) return;
|
|
25
|
+
e_0.preventDefault();
|
|
26
|
+
if (!aui.thread.getState().capabilities.attachments) {
|
|
27
|
+
e_0.dataTransfer.dropEffect = "none";
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
if (!isDragging) setIsDragging(true);
|
|
31
|
+
}, [
|
|
32
|
+
disabled,
|
|
33
|
+
isDragging,
|
|
34
|
+
aui
|
|
35
|
+
]);
|
|
36
|
+
const handleDragLeaveCapture = useCallback((e_1) => {
|
|
37
|
+
if (disabled) return;
|
|
38
|
+
e_1.preventDefault();
|
|
39
|
+
const next = e_1.relatedTarget;
|
|
40
|
+
if (next && e_1.currentTarget.contains(next)) return;
|
|
41
|
+
setIsDragging(false);
|
|
42
|
+
}, [disabled]);
|
|
43
|
+
const handleDrop = useCallback(async (e_2) => {
|
|
44
|
+
if (disabled) return;
|
|
45
|
+
setIsDragging(false);
|
|
46
|
+
if (!e_2.dataTransfer.types.includes("Files")) return;
|
|
47
|
+
e_2.preventDefault();
|
|
48
|
+
const files = Array.from(e_2.dataTransfer.files);
|
|
49
|
+
if (!aui.thread.getState().capabilities.attachments || files.length === 0) return;
|
|
50
|
+
await Promise.all(files.map(async (file) => {
|
|
51
|
+
try {
|
|
52
|
+
await aui.composer.addAttachment(file);
|
|
53
|
+
} catch {}
|
|
54
|
+
}));
|
|
55
|
+
}, [disabled, aui]);
|
|
56
|
+
const mergedProps = {
|
|
57
|
+
...isDragging ? { "data-dragging": "true" } : null,
|
|
58
|
+
...rest,
|
|
59
|
+
onDragEnterCapture: composeEventHandlers(rest.onDragEnterCapture, handleDragEnterCapture),
|
|
60
|
+
onDragOverCapture: composeEventHandlers(rest.onDragOverCapture, handleDragOverCapture),
|
|
61
|
+
onDragLeaveCapture: composeEventHandlers(rest.onDragLeaveCapture, handleDragLeaveCapture),
|
|
62
|
+
onDropCapture: composeEventHandlers(rest.onDropCapture, handleDrop),
|
|
63
|
+
ref
|
|
64
|
+
};
|
|
65
|
+
if (render && isValidElement(render)) return renderSlot(render, children, mergedProps);
|
|
135
66
|
const Comp = asChild ? Slot.Root : "div";
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
children
|
|
141
|
-
});
|
|
142
|
-
$[28] = Comp;
|
|
143
|
-
$[29] = children;
|
|
144
|
-
$[30] = mergedProps;
|
|
145
|
-
$[31] = t12;
|
|
146
|
-
} else t12 = $[31];
|
|
147
|
-
return t12;
|
|
67
|
+
return /* @__PURE__ */ jsx(Comp, {
|
|
68
|
+
...mergedProps,
|
|
69
|
+
children
|
|
70
|
+
});
|
|
148
71
|
});
|
|
149
72
|
ComposerPrimitiveAttachmentDropzone.displayName = "ComposerPrimitive.AttachmentDropzone";
|
|
150
73
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ComposerAttachmentDropzone.js","names":["
|
|
1
|
+
{"version":3,"file":"ComposerAttachmentDropzone.js","names":["forwardRef","useCallback","useState","ReactElement","isValidElement","composeEventHandlers","Slot","React","useAui","renderSlot","ComposerPrimitiveAttachmentDropzone","Element","HTMLDivElement","Props","HTMLAttributes","asChild","render","disabled","children","rest","ref","isDragging","setIsDragging","aui","handleDragEnterCapture","e","DragEvent","dataTransfer","types","includes","preventDefault","thread","getState","capabilities","attachments","dropEffect","handleDragOverCapture","handleDragLeaveCapture","next","relatedTarget","Node","currentTarget","contains","handleDrop","files","Array","from","length","Promise","all","map","file","composer","addAttachment","mergedProps","onDragEnterCapture","onDragOverCapture","onDragLeaveCapture","onDropCapture","Comp","Root","displayName"],"sources":["../../../src/primitives/composer/ComposerAttachmentDropzone.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n forwardRef,\n useCallback,\n useState,\n type ReactElement,\n isValidElement,\n} from \"react\";\n\nimport { composeEventHandlers } from \"radix-ui/internal\";\nimport { Slot } from \"radix-ui\";\nimport type React from \"react\";\nimport { useAui } from \"@assistant-ui/store\";\nimport { renderSlot } from \"../../utils/Primitive\";\n\nexport namespace ComposerPrimitiveAttachmentDropzone {\n export type Element = HTMLDivElement;\n export type Props = React.HTMLAttributes<HTMLDivElement> & {\n asChild?: boolean | undefined;\n render?: ReactElement | undefined;\n disabled?: boolean | undefined;\n };\n}\n\nexport const ComposerPrimitiveAttachmentDropzone = forwardRef<\n HTMLDivElement,\n ComposerPrimitiveAttachmentDropzone.Props\n>(({ disabled, asChild = false, render, children, ...rest }, ref) => {\n const [isDragging, setIsDragging] = useState(false);\n const aui = useAui();\n\n // An unprevented file drop navigates the tab to the file, so file drags are\n // claimed via preventDefault even when the runtime does not support attachments.\n const handleDragEnterCapture = useCallback(\n (e: React.DragEvent) => {\n if (disabled) return;\n if (!e.dataTransfer.types.includes(\"Files\")) return;\n e.preventDefault();\n if (!aui.thread.getState().capabilities.attachments) {\n e.dataTransfer.dropEffect = \"none\";\n return;\n }\n setIsDragging(true);\n },\n [disabled, aui],\n );\n\n const handleDragOverCapture = useCallback(\n (e: React.DragEvent) => {\n if (disabled) return;\n if (!e.dataTransfer.types.includes(\"Files\")) return;\n e.preventDefault();\n if (!aui.thread.getState().capabilities.attachments) {\n e.dataTransfer.dropEffect = \"none\";\n return;\n }\n if (!isDragging) setIsDragging(true);\n },\n [disabled, isDragging, aui],\n );\n\n const handleDragLeaveCapture = useCallback(\n (e: React.DragEvent) => {\n if (disabled) return;\n e.preventDefault();\n const next = e.relatedTarget as Node | null;\n if (next && e.currentTarget.contains(next)) {\n return;\n }\n setIsDragging(false);\n },\n [disabled],\n );\n\n const handleDrop = useCallback(\n async (e: React.DragEvent) => {\n if (disabled) return;\n setIsDragging(false);\n if (!e.dataTransfer.types.includes(\"Files\")) return;\n e.preventDefault();\n const files = Array.from(e.dataTransfer.files);\n if (!aui.thread.getState().capabilities.attachments || files.length === 0)\n return;\n await Promise.all(\n files.map(async (file) => {\n try {\n await aui.composer.addAttachment(file);\n } catch {\n // The composer runtime emits composer.attachmentAddError before rejecting;\n // the readonly and empty-thread stubs only throw.\n }\n }),\n );\n },\n [disabled, aui],\n );\n\n const mergedProps = {\n ...(isDragging ? { \"data-dragging\": \"true\" } : null),\n ...rest,\n onDragEnterCapture: composeEventHandlers(\n rest.onDragEnterCapture,\n handleDragEnterCapture,\n ),\n onDragOverCapture: composeEventHandlers(\n rest.onDragOverCapture,\n handleDragOverCapture,\n ),\n onDragLeaveCapture: composeEventHandlers(\n rest.onDragLeaveCapture,\n handleDragLeaveCapture,\n ),\n onDropCapture: composeEventHandlers(rest.onDropCapture, handleDrop),\n ref,\n };\n\n if (render && isValidElement(render)) {\n return renderSlot(render, children, mergedProps);\n }\n\n const Comp = asChild ? Slot.Root : \"div\";\n return <Comp {...mergedProps}>{children}</Comp>;\n});\n\nComposerPrimitiveAttachmentDropzone.displayName =\n \"ComposerPrimitive.AttachmentDropzone\";\n"],"mappings":";;;;;;;;AAyBA,MAAaU,sCAAsCV,YAGhD,EAAEiB,UAAUF,UAAU,OAAOC,QAAQE,UAAU,GAAGC,QAAQC,QAAQ;CACnE,MAAM,CAACC,YAAYC,iBAAiBpB,SAAS,KAAK;CAClD,MAAMqB,MAAMf,OAAO;CAInB,MAAMgB,yBAAyBvB,aAC5BwB,MAAuB;EACtB,IAAIR,UAAU;EACd,IAAI,CAACQ,EAAEE,aAAaC,MAAMC,SAAS,OAAO,GAAG;EAC7CJ,EAAEK,eAAe;EACjB,IAAI,CAACP,IAAIQ,OAAOC,SAAS,CAAC,CAACC,aAAaC,aAAa;GACnDT,EAAEE,aAAaQ,aAAa;GAC5B;EACF;EACAb,cAAc,IAAI;CACpB,GACA,CAACL,UAAUM,GAAG,CAChB;CAEA,MAAMa,wBAAwBnC,aAC3BwB,QAAuB;EACtB,IAAIR,UAAU;EACd,IAAI,CAACQ,IAAEE,aAAaC,MAAMC,SAAS,OAAO,GAAG;EAC7CJ,IAAEK,eAAe;EACjB,IAAI,CAACP,IAAIQ,OAAOC,SAAS,CAAC,CAACC,aAAaC,aAAa;GACnDT,IAAEE,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