@jini-ai/chat 0.7.2 → 0.7.3-next.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2 -2
- package/README.md +3 -3
- package/dist/contracts/chat-bubble-style.d.ts +1 -1
- package/dist/contracts/chat-bubble-style.js +1 -1
- package/dist/core/ag-ui/event-projection.d.ts +125 -0
- package/dist/core/ag-ui/event-projection.js +275 -0
- package/dist/core/ag-ui/event-reduction.d.ts +39 -0
- package/dist/core/ag-ui/event-reduction.js +99 -0
- package/dist/core/ag-ui/run-input.d.ts +53 -0
- package/dist/core/ag-ui/run-input.js +87 -0
- package/dist/core/agentic/chat-capabilities.d.ts +1 -1
- package/dist/core/agentic/index.d.ts +2 -4
- package/dist/core/agentic/index.js +2 -3
- package/dist/core/agents-port.d.ts +50 -0
- package/dist/core/agents-port.js +2 -0
- package/dist/core/assistant-client/ag-ui-fetch-agent.d.ts +16 -0
- package/dist/core/assistant-client/ag-ui-fetch-agent.js +24 -0
- package/dist/core/assistant-client/ag-ui-transport.d.ts +15 -1
- package/dist/core/assistant-client/ag-ui-transport.js +167 -145
- package/dist/core/assistant-client/attachment-liveness.js +13 -11
- package/dist/core/assistant-client/durable-run-subscription.d.ts +3 -2
- package/dist/core/assistant-client/durable-run-subscription.js +6 -5
- package/dist/core/assistant-client/messages.d.ts +7 -4
- package/dist/core/assistant-client/messages.js +5 -4
- package/dist/core/assistant-client/transport.d.ts +1 -1
- package/dist/core/assistant-client/transport.js +4 -4
- package/dist/core/index.d.ts +2 -0
- package/dist/core/index.js +1 -0
- package/dist/core/page-port.d.ts +15 -0
- package/dist/core/page-port.js +2 -0
- package/dist/core/run-activity.js +1 -1
- package/dist/core/run-events/entry.js +1 -0
- package/dist/core/user-text-redaction.d.ts +1 -3
- package/dist/core/user-text-redaction.js +3 -61
- package/dist/embed-widget/browser/agent-inventory.d.ts +37 -0
- package/dist/embed-widget/browser/agent-inventory.js +36 -0
- package/dist/embed-widget/browser/frontend-session-bridge.d.ts +2 -2
- package/dist/embed-widget/browser/frontend-session-bridge.js +17 -14
- package/dist/embed-widget/react/dialog.hooks.d.ts +16 -0
- package/dist/embed-widget/react/dialog.hooks.js +15 -0
- package/dist/embed-widget/react/embed.d.ts +7 -2
- package/dist/embed-widget/react/embed.js +6 -16
- package/dist/embed-widget/react/header.d.ts +4 -1
- package/dist/embed-widget/react/header.js +2 -2
- package/dist/embed-widget/vanilla/state.js +2 -2
- package/dist/embed-widget/vanilla/style.css +4 -4
- package/dist/react/components/A2uiSurfaceCard.d.ts +18 -4
- package/dist/react/components/A2uiSurfaceCard.hooks.d.ts +36 -0
- package/dist/react/components/A2uiSurfaceCard.hooks.js +174 -0
- package/dist/react/components/A2uiSurfaceCard.js +14 -227
- package/dist/react/components/A2uiSurfaceCard.rules.d.ts +14 -0
- package/dist/react/components/A2uiSurfaceCard.rules.js +24 -0
- package/dist/react/components/AttachmentPreviewModal.d.ts +21 -1
- package/dist/react/components/AttachmentPreviewModal.hooks.js +1 -3
- package/dist/react/components/AttachmentPreviewModal.js +11 -9
- package/dist/react/components/AttachmentTray.d.ts +11 -1
- package/dist/react/components/AttachmentTray.js +12 -8
- package/dist/react/components/ChatFab.d.ts +10 -1
- package/dist/react/components/ChatFab.js +2 -2
- package/dist/react/components/ChatSettingsDialog.d.ts +4 -3
- package/dist/react/components/ChatSettingsDialog.js +9 -6
- package/dist/react/components/ChatSettingsSegmented.d.ts +1 -1
- package/dist/react/components/ChatSettingsSegmented.js +1 -1
- package/dist/react/components/Composer.d.ts +9 -1
- package/dist/react/components/Composer.hooks.d.ts +79 -0
- package/dist/react/components/Composer.hooks.js +336 -0
- package/dist/react/components/Composer.js +40 -341
- package/dist/react/components/ComposerDiscovery.js +1 -1
- package/dist/react/components/ConversationList.d.ts +34 -1
- package/dist/react/components/ConversationList.hooks.d.ts +37 -0
- package/dist/react/components/ConversationList.hooks.js +177 -1
- package/dist/react/components/ConversationList.js +7 -174
- package/dist/react/components/ConversationTitleEditor.d.ts +17 -2
- package/dist/react/components/ConversationTitleEditor.hooks.d.ts +15 -0
- package/dist/react/components/ConversationTitleEditor.hooks.js +36 -0
- package/dist/react/components/ConversationTitleEditor.js +11 -34
- package/dist/react/components/CopyMessageButton.d.ts +6 -1
- package/dist/react/components/CopyMessageButton.js +4 -4
- package/dist/react/components/ExtEventErrorBoundary.d.ts +2 -0
- package/dist/react/components/ExtEventErrorBoundary.js +5 -3
- package/dist/react/components/FolderChips.d.ts +11 -1
- package/dist/react/components/FolderChips.hooks.d.ts +12 -0
- package/dist/react/components/FolderChips.hooks.js +10 -0
- package/dist/react/components/FolderChips.js +9 -9
- package/dist/react/components/Markdown.js +7 -5
- package/dist/react/components/McpUiSurfaceCard.d.ts +29 -5
- package/dist/react/components/McpUiSurfaceCard.js +29 -16
- package/dist/react/components/MessageList.d.ts +10 -1
- package/dist/react/components/MessageList.hooks.js +4 -2
- package/dist/react/components/MessageList.js +12 -8
- package/dist/react/components/MessageRow.d.ts +46 -2
- package/dist/react/components/MessageRow.hooks.d.ts +60 -0
- package/dist/react/components/MessageRow.hooks.js +94 -0
- package/dist/react/components/MessageRow.js +53 -113
- package/dist/react/components/MidRunUserMessage.d.ts +6 -1
- package/dist/react/components/MidRunUserMessage.js +5 -5
- package/dist/react/components/NextStepActions.d.ts +3 -1
- package/dist/react/components/NextStepActions.js +3 -3
- package/dist/react/components/QuestionForm.answers.hooks.d.ts +26 -0
- package/dist/react/components/QuestionForm.answers.hooks.js +89 -0
- package/dist/react/components/QuestionForm.d.ts +6 -0
- package/dist/react/components/QuestionForm.js +23 -261
- package/dist/react/components/QuestionForm.values.d.ts +22 -0
- package/dist/react/components/QuestionForm.values.js +58 -0
- package/dist/react/components/QuestionFormField.d.ts +17 -0
- package/dist/react/components/QuestionFormField.js +114 -0
- package/dist/react/components/QuestionsPanel.d.ts +3 -1
- package/dist/react/components/QuestionsPanel.js +7 -3
- package/dist/react/components/SentAttachment.d.ts +11 -2
- package/dist/react/components/SentAttachment.hooks.d.ts +1 -1
- package/dist/react/components/SentAttachment.hooks.js +6 -5
- package/dist/react/components/SentAttachment.js +5 -3
- package/dist/react/components/TodoCard.d.ts +3 -1
- package/dist/react/components/TodoCard.js +9 -4
- package/dist/react/components/ToolCallGroup.d.ts +11 -1
- package/dist/react/components/ToolCallGroup.js +10 -4
- package/dist/react/components/ToolCard.d.ts +6 -1
- package/dist/react/components/ToolCard.js +79 -69
- package/dist/react/components/mcp-ui-question-input.d.ts +1 -1
- package/dist/react/components/mcp-ui-question-input.js +3 -3
- package/dist/react/components/mcp-ui-surface-state.d.ts +1 -1
- package/dist/react/features/chat-pane/agent-tools.d.ts +1 -1
- package/dist/react/features/chat-pane/antigravity/model-options.d.ts +2 -0
- package/dist/react/features/chat-pane/antigravity/model-options.js +2 -0
- package/dist/react/features/chat-pane/claude/model-options.d.ts +2 -0
- package/dist/react/features/chat-pane/claude/model-options.js +2 -0
- package/dist/react/features/chat-pane/codex/model-options.d.ts +2 -0
- package/dist/react/features/chat-pane/codex/model-options.js +2 -0
- package/dist/react/features/chat-pane/components/AgentPluginUsage.d.ts +4 -1
- package/dist/react/features/chat-pane/components/AgentPluginUsage.js +2 -2
- package/dist/react/features/chat-pane/components/AgentRuntimePicker.d.ts +10 -6
- package/dist/react/features/chat-pane/components/AgentRuntimePicker.js +18 -132
- package/dist/react/features/chat-pane/components/ChatPane.d.ts +24 -2
- package/dist/react/features/chat-pane/components/ChatPane.js +45 -297
- package/dist/react/features/chat-pane/components/ChatPaneComposerArea.d.ts +33 -0
- package/dist/react/features/chat-pane/components/ChatPaneComposerArea.js +119 -0
- package/dist/react/features/chat-pane/components/ChatPaneLayout.d.ts +42 -0
- package/dist/react/features/chat-pane/components/ChatPaneLayout.js +54 -0
- package/dist/react/features/chat-pane/components/ChatPaneStatus.d.ts +27 -0
- package/dist/react/features/chat-pane/components/ChatPaneStatus.js +91 -0
- package/dist/react/features/chat-pane/components/RuntimeDropUp.d.ts +6 -1
- package/dist/react/features/chat-pane/components/RuntimeDropUp.js +20 -19
- package/dist/react/features/chat-pane/components/RuntimePickerSections.d.ts +62 -0
- package/dist/react/features/chat-pane/components/RuntimePickerSections.js +122 -0
- package/dist/react/features/chat-pane/create-mcp-ui-tool-caller.d.ts +1 -1
- package/dist/react/features/chat-pane/hooks/useChatPane.hooks.d.ts +5 -3
- package/dist/react/features/chat-pane/hooks/useChatPane.hooks.js +78 -26
- package/dist/react/features/chat-pane/hooks/useChatPaneAgentControl.hooks.js +6 -6
- package/dist/react/features/chat-pane/hooks/useChatPaneFileDrop.hooks.d.ts +5 -1
- package/dist/react/features/chat-pane/hooks/useChatPaneFileDrop.hooks.js +7 -7
- package/dist/react/features/chat-pane/hooks/useRuntimeDropUp.hooks.d.ts +7 -0
- package/dist/react/features/chat-pane/hooks/useRuntimeDropUp.hooks.js +5 -0
- package/dist/react/features/chat-pane/model-options.js +7 -4
- package/dist/react/features/chat-pane/styles.d.ts +1 -1
- package/dist/react/features/chat-pane/styles.js +14 -14
- package/dist/react/features/chat-pane/types.d.ts +29 -1
- package/dist/react/hooks/assistant-chats-contracts.d.ts +1 -1
- package/dist/react/hooks/attachment-preview-cache.d.ts +1 -1
- package/dist/react/hooks/attachment-preview-cache.js +1 -1
- package/dist/react/hooks/fab-position.js +16 -18
- package/dist/react/hooks/useConversation.d.ts +6 -1
- package/dist/react/hooks/useConversation.js +11 -10
- package/dist/react/hooks/useRunStream.d.ts +3 -0
- package/dist/react/hooks/useRunStream.js +12 -12
- package/dist/react/hooks/useSurfaceRecovery.d.ts +1 -1
- package/dist/react/hooks/useSurfaceRecovery.js +2 -2
- package/dist/react/index.d.ts +6 -3
- package/dist/react/index.js +5 -3
- package/dist/react/styles/chat-settings.css +9 -9
- package/dist/react/surfaces.d.ts +91 -0
- package/dist/react/surfaces.js +28 -0
- package/dist/server/durable-runs/recover.d.ts +4 -3
- package/dist/server/durable-runs/recover.js +4 -3
- package/dist/store/legacy/sqlite/conversations.d.ts +1 -2
- package/dist/store/legacy/sqlite/conversations.js +1 -1
- package/dist/store/legacy/sqlite/messages.d.ts +2 -3
- package/dist/store/legacy/sqlite/messages.js +6 -6
- package/dist/store/pglite/index.d.ts +7 -7
- package/dist/store/pglite/index.js +1 -1
- package/dist/store/ports.d.ts +5 -2
- package/dist/store/postgres/index.d.ts +7 -7
- package/dist/store/postgres/index.js +1 -1
- package/dist/store/runtime/chat-expiry-sweep.js +2 -4
- package/dist/store/runtime/chat-history-store.js +2 -3
- package/dist/store/runtime/durable-run-store.js +16 -2
- package/dist/store/runtime/history-tools.js +33 -11
- package/dist/store/runtime/kernel.d.ts +3 -2
- package/dist/store/runtime/run-ledger.js +2 -2
- package/dist/store/sql/boundary.d.ts +5 -5
- package/dist/store/sql/maintenance.d.ts +3 -2
- package/dist/store/sql/store.d.ts +16 -8
- package/dist/store/sql/store.js +31 -14
- package/dist/store/sqlite/index.d.ts +11 -12
- package/dist/store/sqlite/index.js +5 -5
- package/dist/store/sqlite/schema.d.ts +1 -1
- package/package.json +49 -27
- package/dist/core/ag-ui/entry.d.ts +0 -84
- package/dist/core/ag-ui/entry.js +0 -225
- package/dist/core/browser/page-actions.d.ts +0 -121
- package/dist/core/browser/page-actions.js +0 -113
- package/dist/embed-widget/browser/page-actions.d.ts +0 -2
- package/dist/embed-widget/browser/page-actions.js +0 -3
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useEmbedChatHeader } from './header.hooks.js';
|
|
3
3
|
/** Two-step reset with safe initial focus, Cancel and host-wide Escape. O(1) state and listeners. */
|
|
4
|
-
export function EmbedChatHeader({ title, hasMessages, onReset, copy, keyboard, closeAction }) {
|
|
5
|
-
const { confirming, cancel, requestReset, confirmReset, headerRef, resetButtonRef } =
|
|
4
|
+
export function EmbedChatHeader({ title, hasMessages, onReset, copy, keyboard, closeAction, useEmbedChatHeaderHook = useEmbedChatHeader }) {
|
|
5
|
+
const { confirming, cancel, requestReset, confirmReset, headerRef, resetButtonRef } = useEmbedChatHeaderHook({ hasMessages, onReset, keyboard });
|
|
6
6
|
return _jsxs("div", { className: "jini-chat-pane__header", ref: headerRef, children: [_jsxs("div", { className: "jini-chat-pane__heading", children: [copy.eyebrow && _jsx("span", { className: "jini-chat-pane__eyebrow", children: copy.eyebrow }), _jsx("h2", { className: "jini-chat-pane__title", children: title })] }), confirming ? _jsxs("div", { className: "jini-chat-embed__reset-confirm", children: [_jsx("button", { type: "button", className: "jini-chat-embed__reset-cancel", autoFocus: true, onClick: cancel, children: copy.cancel }), _jsx("button", { type: "button", className: "jini-chat-pane__new-thread", onClick: confirmReset, children: copy.discard })] }) : _jsx("button", { type: "button", className: "jini-chat-pane__new-thread", ref: resetButtonRef, onClick: requestReset, children: copy.newThread }), closeAction] });
|
|
7
7
|
}
|
|
8
8
|
//# sourceMappingURL=header.js.map
|
|
@@ -40,11 +40,11 @@ export function createVanillaChatController(args, _options = {}) {
|
|
|
40
40
|
state = { ...state, messages: state.messages.map(message => message.id === reply.id ? next : message) };
|
|
41
41
|
publish({ persist });
|
|
42
42
|
};
|
|
43
|
-
const fail = (
|
|
43
|
+
const fail = (_error) => {
|
|
44
44
|
if (!current())
|
|
45
45
|
return;
|
|
46
46
|
failed = true;
|
|
47
|
-
state = { ...state, error:
|
|
47
|
+
state = { ...state, error: 'The message could not be sent to the agent; send it again.' };
|
|
48
48
|
updateReply({ ...reply, content: assistantContentFromEvents({ events }), events: [...events], runStatus: 'failed' });
|
|
49
49
|
};
|
|
50
50
|
const done = (final) => {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
.jini-chat-vanilla{display:var(--jini-floating-ui-display,block)}.jini-chat-bubble{position:fixed;right:var(--jini-embed-right,24px);bottom:24px;width:56px;height:56px;border:0;border-radius:50%;background:var(--jini-chat-accent
|
|
1
|
+
.jini-chat-vanilla{display:var(--jini-floating-ui-display,block)}.jini-chat-bubble{position:fixed;right:var(--jini-embed-right,24px);bottom:24px;width:56px;height:56px;border:0;border-radius:50%;background:var(--jini-chat-accent,#2563eb);color:var(--jini-chat-accent-text,#fff);box-shadow:0 4px 16px #0003;cursor:pointer;z-index:var(--jini-embed-z-index,1000);display:var(--jini-floating-ui-display,grid);place-items:center}
|
|
2
2
|
.jini-chat-bubble[hidden]{display:none!important}
|
|
3
3
|
.jini-chat-bubble svg{width:24px;height:24px}
|
|
4
4
|
.jini-chat-bubble:focus-visible{outline:3px solid var(--jini-chat-accent,#2563eb);outline-offset:3px}
|
|
@@ -8,8 +8,8 @@
|
|
|
8
8
|
.jini-chat-vanilla [hidden]{display:none!important}
|
|
9
9
|
.jini-chat-vanilla svg{width:24px;height:24px}
|
|
10
10
|
.jini-chat-vanilla :focus-visible{outline:3px solid var(--jini-chat-accent,#2563eb);outline-offset:3px}
|
|
11
|
-
.jini-chat-vanilla{font:14px/1.5 var(--font-body,system-ui,sans-serif);color:var(--jini-chat-text,
|
|
12
|
-
.jini-chat-vanilla__panel{position:fixed;right:var(--jini-embed-right,24px);bottom:88px;width:min(var(--jini-embed-width,440px),calc(100vw - 32px));height:min(var(--jini-embed-height,620px),calc(100dvh - 120px));z-index:var(--jini-embed-z-index,1000);display:flex;flex-direction:column;background:var(--jini-chat-background,
|
|
11
|
+
.jini-chat-vanilla{font:14px/1.5 var(--jini-chat-font-body,system-ui,sans-serif);color:var(--jini-chat-text,CanvasText)}
|
|
12
|
+
.jini-chat-vanilla__panel{position:fixed;right:var(--jini-embed-right,24px);bottom:88px;width:min(var(--jini-embed-width,440px),calc(100vw - 32px));height:min(var(--jini-embed-height,620px),calc(100dvh - 120px));z-index:var(--jini-embed-z-index,1000);display:flex;flex-direction:column;background:var(--jini-chat-background,Canvas);border:1px solid var(--jini-chat-border,#767676);border-radius:16px;box-shadow:0 12px 48px #0003;overflow:hidden}
|
|
13
13
|
.jini-chat-vanilla__header,.jini-chat-vanilla__composer,.jini-chat-vanilla__confirmation,.jini-chat-vanilla__tool-confirmation{display:flex;align-items:center;gap:8px;padding:12px;border-bottom:1px solid var(--jini-chat-border,#767676)}
|
|
14
14
|
.jini-chat-vanilla__title{flex:1}
|
|
15
15
|
.jini-chat-vanilla__button{font:inherit;color:inherit;background:transparent;border:1px solid var(--jini-chat-border,#767676);border-radius:8px;padding:6px 10px;cursor:pointer}
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
.jini-chat-vanilla__message--user{white-space:pre-wrap;padding:10px;border-radius:8px;background:var(--jini-chat-user-background,#8882)}
|
|
20
20
|
.jini-chat-vanilla__message p{margin:0 0 8px}
|
|
21
21
|
.jini-chat-vanilla__message pre{overflow:auto;padding:8px;background:#8882;border-radius:8px}
|
|
22
|
-
.jini-chat-vanilla__message a{color:var(--jini-chat-accent
|
|
22
|
+
.jini-chat-vanilla__message a{color:var(--jini-chat-accent,#2563eb);text-decoration:underline}
|
|
23
23
|
.jini-chat-vanilla__input{flex:1;min-width:0;resize:none;font:inherit;font-size:16px;color:inherit;background:transparent;border:1px solid var(--jini-chat-border,#767676);border-radius:8px;padding:8px}
|
|
24
24
|
.jini-chat-vanilla__status,.jini-chat-vanilla__error{padding:0 12px}
|
|
25
25
|
.jini-chat-vanilla__error{color:var(--jini-chat-error,#b91c1c)}
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { Clock } from '@jini-ai/core/primitives';
|
|
2
|
+
import { useChatSurfaces, type ChatSurfaceRegistry } from '../surfaces.js';
|
|
2
3
|
import type { ExtEventRenderProps } from '../ext-event-renderer-registry.js';
|
|
4
|
+
import { useT } from '../hooks/context.js';
|
|
5
|
+
import { useA2uiSurfaceCard } from './A2uiSurfaceCard.hooks.js';
|
|
3
6
|
/**
|
|
4
7
|
* What a host reports back after attempting to deliver an agent-directed action. Returned (not
|
|
5
8
|
* thrown) because a delivery failure here is routine, not exceptional — a closed exchange, a
|
|
@@ -13,9 +16,11 @@ export type A2uiAgentActionOutcome = {
|
|
|
13
16
|
readonly reason: string;
|
|
14
17
|
};
|
|
15
18
|
export interface A2uiSurfaceCardProps extends ExtEventRenderProps {
|
|
16
|
-
/** Host
|
|
19
|
+
/** Host clock port; the card derives action ids and interpreter timing from it. */
|
|
20
|
+
clock: Clock;
|
|
21
|
+
/** Host registry used for both wire validation and rendering. Defaults to the host's `surfaces.interactiveUi.defaultRegistry`.
|
|
17
22
|
* Supply a stable registry for the card's lifetime; remount the card to switch catalogs. */
|
|
18
|
-
registry?: Pick<
|
|
23
|
+
registry?: Pick<ChatSurfaceRegistry, 'list' | 'resolveById'>;
|
|
19
24
|
/**
|
|
20
25
|
* Called when a rendered surface produces a `message`-shaped action meant for the agent (as
|
|
21
26
|
* opposed to a `local` client-side function call, which this component already resolves and
|
|
@@ -34,6 +39,15 @@ export interface A2uiSurfaceCardProps extends ExtEventRenderProps {
|
|
|
34
39
|
*/
|
|
35
40
|
onAgentAction?: (runId: string | undefined, message: unknown) => void | Promise<A2uiAgentActionOutcome>;
|
|
36
41
|
}
|
|
42
|
+
/** Hooks A2uiSurfaceCard calls; defaults to the real ones, a test hands in fakes. */
|
|
43
|
+
export declare const defaultA2uiSurfaceCardHooks: {
|
|
44
|
+
useT: typeof useT;
|
|
45
|
+
useChatSurfaces: typeof useChatSurfaces;
|
|
46
|
+
useA2uiSurfaceCard: typeof useA2uiSurfaceCard;
|
|
47
|
+
};
|
|
48
|
+
export type A2uiSurfaceCardHooks = typeof defaultA2uiSurfaceCardHooks;
|
|
37
49
|
/** Registered against `ext-event-renderer-registry.ts`'s `'a2ui'` name — see module doc. */
|
|
38
|
-
export declare function A2uiSurfaceCard({ events, runId, onAgentAction, registry }: A2uiSurfaceCardProps
|
|
50
|
+
export declare function A2uiSurfaceCard({ events, runId, onAgentAction, clock, registry: registryProp, hooks }: A2uiSurfaceCardProps & {
|
|
51
|
+
hooks?: A2uiSurfaceCardHooks | undefined;
|
|
52
|
+
}): import("react").JSX.Element;
|
|
39
53
|
//# sourceMappingURL=A2uiSurfaceCard.d.ts.map
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { type A2uiInterpreter } from '@jini-ai/protocol/a2ui';
|
|
2
|
+
import type { Clock } from '@jini-ai/core/primitives';
|
|
3
|
+
import { type ChatSurfaceRegistry } from '../surfaces.js';
|
|
4
|
+
import type { useT } from '../hooks/context.js';
|
|
5
|
+
import type { A2uiSurfaceCardProps } from './A2uiSurfaceCard.js';
|
|
6
|
+
export interface RenderComponentProps {
|
|
7
|
+
interpreter: A2uiInterpreter;
|
|
8
|
+
surfaceId: string;
|
|
9
|
+
componentId: string;
|
|
10
|
+
ancestors: ReadonlySet<string>;
|
|
11
|
+
onAction: (componentId: string) => void;
|
|
12
|
+
registry: Pick<ChatSurfaceRegistry, 'list' | 'resolveById'>;
|
|
13
|
+
}
|
|
14
|
+
/** Apply streamed surface events and report local or agent action outcomes. */
|
|
15
|
+
export declare function useA2uiSurfaceCard({ events, runId, onAgentAction, registry, t, clock }: {
|
|
16
|
+
clock: Clock;
|
|
17
|
+
events: A2uiSurfaceCardProps['events'];
|
|
18
|
+
runId: A2uiSurfaceCardProps['runId'];
|
|
19
|
+
onAgentAction: A2uiSurfaceCardProps['onAgentAction'];
|
|
20
|
+
registry: NonNullable<A2uiSurfaceCardProps['registry']>;
|
|
21
|
+
t: ReturnType<typeof useT>;
|
|
22
|
+
}, _options?: {}): {
|
|
23
|
+
interpreter: A2uiInterpreter;
|
|
24
|
+
surfaceId: string | undefined;
|
|
25
|
+
root: import("@jini-ai/protocol/a2ui").ComponentInstance | undefined;
|
|
26
|
+
refusalNotice: string | null;
|
|
27
|
+
pendingAgentAction: string | null;
|
|
28
|
+
localActionResult: {
|
|
29
|
+
componentId: string;
|
|
30
|
+
value: unknown;
|
|
31
|
+
} | null;
|
|
32
|
+
deliveryFailureNotice: string | null;
|
|
33
|
+
handleAction: (componentId: string) => void;
|
|
34
|
+
formatLocalActionValue: (value: unknown) => string;
|
|
35
|
+
};
|
|
36
|
+
//# sourceMappingURL=A2uiSurfaceCard.hooks.d.ts.map
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import { useEffect, useMemo, useRef, useState } from 'react';
|
|
2
|
+
import { createA2uiInterpreter, createLabCatalog, } from '@jini-ai/protocol/a2ui';
|
|
3
|
+
import { useChatSurfaces } from '../surfaces.js';
|
|
4
|
+
/** Every agent→renderer message shape carries `surfaceId` under exactly one of these keys. */
|
|
5
|
+
const SURFACE_ID_KEYS = ['createSurface', 'updateComponents', 'updateDataModel', 'deleteSurface'];
|
|
6
|
+
function extractSurfaceId(message) {
|
|
7
|
+
if (typeof message !== 'object' || message === null)
|
|
8
|
+
return undefined;
|
|
9
|
+
for (const key of SURFACE_ID_KEYS) {
|
|
10
|
+
const body = message[key];
|
|
11
|
+
if (body && typeof body === 'object' && typeof body.surfaceId === 'string') {
|
|
12
|
+
return body.surfaceId;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
return undefined;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Duck-types `value` as a thenable rather than checking `instanceof Promise`. `onAgentAction`'s
|
|
19
|
+
* declared return type is `void | Promise<A2uiAgentActionOutcome>`, and TypeScript's structural
|
|
20
|
+
* typing means anything with a spec-shaped `then` — a hand-built thenable, a non-native promise
|
|
21
|
+
* library, a promise crossing a realm boundary (e.g. constructed inside an iframe) — satisfies
|
|
22
|
+
* `Promise<T>` at the call site without being `instanceof Promise` in *this* realm. An `instanceof`
|
|
23
|
+
* check would silently skip the await branch for any of those, dropping the delivery outcome on the
|
|
24
|
+
* floor — reintroducing, inside the fix for it, the exact silent-failure class this feature exists
|
|
25
|
+
* to remove. Do not "simplify" this back to `instanceof`.
|
|
26
|
+
*
|
|
27
|
+
* @complexity O(1).
|
|
28
|
+
* @overallScore 100
|
|
29
|
+
*/
|
|
30
|
+
function isThenable(value) {
|
|
31
|
+
return typeof value === 'object' && value !== null && typeof value.then === 'function';
|
|
32
|
+
}
|
|
33
|
+
/** Apply streamed surface events and report local or agent action outcomes. */
|
|
34
|
+
export function useA2uiSurfaceCard({ events, runId, onAgentAction, registry, t, clock }, _options = {}) {
|
|
35
|
+
const surfaces = useChatSurfaces();
|
|
36
|
+
// Merges the host registry (shadcn/recharts by default) into the lab catalog, keyed under
|
|
37
|
+
// the SAME `catalogId` the lab catalog already uses — so a tool built against
|
|
38
|
+
// `createLabCatalog({}).catalogId` (e.g. `demo-a2ui-tool.ts`) still validates unchanged, and now
|
|
39
|
+
// ALSO gains every registry component as a real, addable/removable catalog entry.
|
|
40
|
+
const catalog = useMemo(() => {
|
|
41
|
+
const base = createLabCatalog({});
|
|
42
|
+
return surfaces.a2ui.catalogFromRegistry({ registry, catalogId: base.catalogId }, { base });
|
|
43
|
+
}, [registry, surfaces]);
|
|
44
|
+
const interpreterRef = useRef(null);
|
|
45
|
+
const actionIdCounterRef = useRef(0); // per-card sequence; the clock suffix keeps the wire format
|
|
46
|
+
if (!interpreterRef.current) {
|
|
47
|
+
interpreterRef.current = createA2uiInterpreter({
|
|
48
|
+
catalog,
|
|
49
|
+
clock,
|
|
50
|
+
ids: {
|
|
51
|
+
next: (_required) => `a2ui-action-${(actionIdCounterRef.current += 1)}-${clock.nowMs().toString(36)}`,
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
const interpreter = interpreterRef.current;
|
|
56
|
+
const [, forceRender] = useState(0);
|
|
57
|
+
const appliedCountRef = useRef(0);
|
|
58
|
+
const surfaceIdRef = useRef(undefined);
|
|
59
|
+
/** Monotonic ticket for `handleAction`'s agent-delivery attempts — see its use for why a host's
|
|
60
|
+
* promises settling out of order would otherwise repaint a superseded failure. */
|
|
61
|
+
const agentActionAttemptRef = useRef(0);
|
|
62
|
+
const [refusalNotice, setRefusalNotice] = useState(null);
|
|
63
|
+
const [pendingAgentAction, setPendingAgentAction] = useState(null);
|
|
64
|
+
const [localActionResult, setLocalActionResult] = useState(null);
|
|
65
|
+
const [deliveryFailureNotice, setDeliveryFailureNotice] = useState(null);
|
|
66
|
+
useEffect(() => {
|
|
67
|
+
const unsubscribe = interpreter.subscribe({ listener: () => forceRender((n) => n + 1) });
|
|
68
|
+
// React invokes cleanup with no arguments; the interpreter's port takes a required bag.
|
|
69
|
+
return () => unsubscribe({});
|
|
70
|
+
}, [interpreter]);
|
|
71
|
+
useEffect(() => {
|
|
72
|
+
while (appliedCountRef.current < events.length) {
|
|
73
|
+
const message = events[appliedCountRef.current];
|
|
74
|
+
appliedCountRef.current += 1;
|
|
75
|
+
const surfaceId = extractSurfaceId(message);
|
|
76
|
+
if (surfaceId)
|
|
77
|
+
surfaceIdRef.current = surfaceId;
|
|
78
|
+
const result = interpreter.applyAgentMessage({ raw: message });
|
|
79
|
+
if (result.unattributedViolation) {
|
|
80
|
+
setRefusalNotice(result.unattributedViolation);
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
// A catalog-validation refusal (e.g. an unrecognized component type, or a known type with a
|
|
84
|
+
// missing/invalid required prop) surfaces as an `error`-shaped entry in `rendererMessages`,
|
|
85
|
+
// not `unattributedViolation`. Shown locally AND relayed through the exact same
|
|
86
|
+
// `onAgentAction` pipe a button click already uses: `errorMessage` is a real
|
|
87
|
+
// `RendererToAgentMessage` carrying `error.surfaceId`, which is all `onAgentAction`'s host
|
|
88
|
+
// implementation needs to address it — no second callback prop, no new wire shape. Without
|
|
89
|
+
// this relay a tool call that opened the surface has no way to learn its render was REFUSED
|
|
90
|
+
// and returns success anyway, which is worse than the silent-"waiting" bug this comment used
|
|
91
|
+
// to describe: it actively tells the agent (and, downstream, the human) that a chart is on
|
|
92
|
+
// screen when it never rendered at all.
|
|
93
|
+
const errorMessage = result.rendererMessages.find((m) => 'error' in m);
|
|
94
|
+
if (errorMessage) {
|
|
95
|
+
setRefusalNotice(errorMessage.error.message);
|
|
96
|
+
void onAgentAction?.(runId, errorMessage);
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
// A message that applies cleanly clears any earlier refusal. `refusalNotice` describes
|
|
100
|
+
// whether the CURRENT surface is broken, not a permanent scar from an earlier mistake this
|
|
101
|
+
// same conversation already recovered from — e.g. a retry that fixed a missing prop, or an
|
|
102
|
+
// unrelated later `updateDataModel`. Without this, a stale "Action refused" banner from an
|
|
103
|
+
// early failed attempt sits underneath a chart that went on to render successfully.
|
|
104
|
+
setRefusalNotice(null);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
// `onAgentAction`/`runId` included: the loop above now calls `onAgentAction` directly (relaying
|
|
109
|
+
// a validation error), not just on a later user click — the effect must see a fresh reference,
|
|
110
|
+
// the same way `handleAction`'s own (non-effect) call site already gets one on every render.
|
|
111
|
+
}, [events, interpreter, onAgentAction, runId]);
|
|
112
|
+
const surfaceId = surfaceIdRef.current;
|
|
113
|
+
const root = surfaceId ? interpreter.getRoot({ surfaceId }) : undefined;
|
|
114
|
+
function handleAction(componentId) {
|
|
115
|
+
// `surfaceId` is non-null here by construction, not by luck: this callback is only ever reached
|
|
116
|
+
// from a `Button` inside the rendered tree, and nothing renders until `root` resolves — which
|
|
117
|
+
// the `!root` early return below only permits when `surfaceId` was already truthy. Asserted
|
|
118
|
+
// rather than re-checked, exactly as the `RenderComponent` call site below already does.
|
|
119
|
+
const built = interpreter.buildAction({ surfaceId: surfaceId, componentId });
|
|
120
|
+
if (!built.ok) {
|
|
121
|
+
setRefusalNotice(built.reason);
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
setRefusalNotice(null);
|
|
125
|
+
if (built.kind === 'local') {
|
|
126
|
+
// `buildAction`'s local branch is a pure computation (`resolveDynamicValue` over a
|
|
127
|
+
// registered catalog function's `impl`) — it never touches interpreter state, so there is
|
|
128
|
+
// nothing for `interpreter.subscribe` to notify and no re-render to "reflect" it. The only
|
|
129
|
+
// honest thing this component can do with the resolved value is show it.
|
|
130
|
+
setPendingAgentAction(null);
|
|
131
|
+
setLocalActionResult({ componentId, value: built.result });
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
setLocalActionResult(null);
|
|
135
|
+
if (onAgentAction) {
|
|
136
|
+
// Clearing here, not just at the top of `handleAction`: a *previous* click's delivery failure
|
|
137
|
+
// must not linger next to a new attempt that has not resolved yet — same "stale notice beside
|
|
138
|
+
// a working control" concern `refusalNotice`'s own clearing already guards against.
|
|
139
|
+
setPendingAgentAction(null);
|
|
140
|
+
setDeliveryFailureNotice(null);
|
|
141
|
+
// Clearing the notice is not enough on its own: `onAgentAction` is host-supplied and its
|
|
142
|
+
// promises are not guaranteed to settle in call order, so an OLDER click's rejection could
|
|
143
|
+
// land after a newer one had already cleared the notice — repainting a failure the human has
|
|
144
|
+
// since superseded, next to a control that just worked. Only the latest attempt may write.
|
|
145
|
+
const attempt = (agentActionAttemptRef.current += 1);
|
|
146
|
+
const isLatestAttempt = () => agentActionAttemptRef.current === attempt;
|
|
147
|
+
const outcome = onAgentAction(runId, built.message);
|
|
148
|
+
// `isThenable`, not `instanceof Promise` — see that helper's own doc for why.
|
|
149
|
+
if (isThenable(outcome)) {
|
|
150
|
+
void outcome.then((result) => {
|
|
151
|
+
if (!result.ok && isLatestAttempt())
|
|
152
|
+
setDeliveryFailureNotice(result.reason);
|
|
153
|
+
}, (error) => {
|
|
154
|
+
// A rejection is the host's transport breaking, not a message the host chose to report —
|
|
155
|
+
// still surfaced, so the human sees *something* rather than a click that silently did
|
|
156
|
+
// nothing.
|
|
157
|
+
if (!isLatestAttempt())
|
|
158
|
+
return;
|
|
159
|
+
setDeliveryFailureNotice(error instanceof Error ? error.message : String(error));
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
else {
|
|
164
|
+
setPendingAgentAction(JSON.stringify(built.message));
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
function formatLocalActionValue(value) {
|
|
168
|
+
if (value === undefined)
|
|
169
|
+
return t('(no return value)');
|
|
170
|
+
return typeof value === 'string' ? value : JSON.stringify(value);
|
|
171
|
+
}
|
|
172
|
+
return { interpreter, surfaceId, root, refusalNotice, pendingAgentAction, localActionResult, deliveryFailureNotice, handleAction, formatLocalActionValue };
|
|
173
|
+
}
|
|
174
|
+
//# sourceMappingURL=A2uiSurfaceCard.hooks.js.map
|
|
@@ -1,58 +1,8 @@
|
|
|
1
1
|
import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
|
|
3
|
-
* @module A2uiSurfaceCard
|
|
4
|
-
*
|
|
5
|
-
* Renders a live A2UI (a2ui-project/a2ui v1.0) surface inline in the chat transcript, fed by a
|
|
6
|
-
* message's `kind: 'ext', name: 'a2ui'` events (see `ext-event-renderer-registry.ts`). A host
|
|
7
|
-
* registers this against `'a2ui'` once, at module scope — mirroring how `McpUiLab.tsx` registers
|
|
8
|
-
* `show_mcpui_widget` via `registerToolRenderer` — and every `ChatPane` that surfaces an `a2ui`
|
|
9
|
-
* event thereafter renders through it.
|
|
10
|
-
*
|
|
11
|
-
* Ported from `examples/reference-web/src/A2uiLab.tsx`'s `RenderComponent` (the same tree-walking
|
|
12
|
-
* approach: degrade sanely — a visible, inert placeholder, never a crash — for a missing child id
|
|
13
|
-
* or a circular reference), generalized to consume a growing `events` array instead of a live SSE
|
|
14
|
-
* callback. `@jini-ai/agentic/a2ui`'s catalog validates all 18 of the real basic catalog's
|
|
15
|
-
* components; this renderer has React cases for 5 of them — `Text`/`Column`/`Row`/`Card`/`Button`
|
|
16
|
-
* — plus, since the catalog this card builds is the lab catalog MERGED with
|
|
17
|
-
* `DEFAULT_INTERACTIVE_UI_REGISTRY` (`buildA2uiCatalogFromRegistry`, `@jini-ai/ui/a2ui`), any
|
|
18
|
-
* registry-sourced component (`shadcn.*`, `recharts.*`) resolves through that registry the same
|
|
19
|
-
* way `@jini-ai/ui`'s own `A2uiSurfaceRenderer` does — see this file's `default` case. The
|
|
20
|
-
* remaining basic types (Image/Icon/Video/AudioPlayer/List/Tabs/Modal/Divider and the input
|
|
21
|
-
* family) still have no case here; a catalog type the interpreter accepts but this switch has no
|
|
22
|
-
* case for, and that the registry does not resolve either, degrades to the same visible
|
|
23
|
-
* placeholder as a genuinely unrenderable one — see the `default` branch's own comment.
|
|
24
|
-
*
|
|
25
|
-
* **Known gap, by design, not oversight:** a `Button`'s click only completes the round trip when
|
|
26
|
-
* `interpreter.buildAction` resolves it as a `local` (client-side) function call. A `message`-shaped
|
|
27
|
-
* action (meant for the agent) has nowhere real to go yet — the only existing relay
|
|
28
|
-
* (`examples/reference-web/src/daemon.ts`'s `/a2ui-action`) is hardwired to that app's fixed,
|
|
29
|
-
* scripted `a2ui-demo` agent, not a real conversational run; sending to it here would silently
|
|
30
|
-
* misrepresent whether a live agent turn can actually receive the action. `onAgentAction` is the
|
|
31
|
-
* seam a host wires up once that backend capability exists — until then, a `message`-shaped action
|
|
32
|
-
* surfaces as a visible, honest notice instead of vanishing or hitting the wrong endpoint.
|
|
33
|
-
*/
|
|
34
|
-
import { useEffect, useMemo, useRef, useState } from 'react';
|
|
35
|
-
import { createA2uiInterpreter, createLabCatalog, DynamicValueSchema } from '@jini-ai/agentic/a2ui';
|
|
36
|
-
import { createSystemClock } from '@jini-ai/core/primitives';
|
|
37
|
-
import { buildA2uiCatalogFromRegistry } from '@jini-ai/ui/a2ui';
|
|
38
|
-
import { DEFAULT_INTERACTIVE_UI_REGISTRY } from '@jini-ai/ui/interactive-ui';
|
|
2
|
+
import { useChatSurfaces } from '../surfaces.js';
|
|
39
3
|
import { useT } from '../hooks/context.js';
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
// Preserve the interpreter's former module-wide sequence so separate cards cannot reuse an
|
|
43
|
-
// action ID in the same millisecond; the wall-clock suffix keeps the existing wire format.
|
|
44
|
-
let actionIdCounter = 0;
|
|
45
|
-
function extractSurfaceId(message) {
|
|
46
|
-
if (typeof message !== 'object' || message === null)
|
|
47
|
-
return undefined;
|
|
48
|
-
for (const key of SURFACE_ID_KEYS) {
|
|
49
|
-
const body = message[key];
|
|
50
|
-
if (body && typeof body === 'object' && typeof body.surfaceId === 'string') {
|
|
51
|
-
return body.surfaceId;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
return undefined;
|
|
55
|
-
}
|
|
4
|
+
import { useA2uiSurfaceCard } from './A2uiSurfaceCard.hooks.js';
|
|
5
|
+
import { createA2uiCardNodeHelpers } from './A2uiSurfaceCard.rules.js';
|
|
56
6
|
/** Renders one component and its children by walking the surface's component map from `componentId` — identical degrade-sanely behavior to `A2uiLab.tsx`'s `RenderComponent`. */
|
|
57
7
|
function RenderComponent({ interpreter, surfaceId, componentId, ancestors, onAction, registry, }) {
|
|
58
8
|
if (ancestors.has(componentId)) {
|
|
@@ -66,20 +16,7 @@ function RenderComponent({ interpreter, surfaceId, componentId, ancestors, onAct
|
|
|
66
16
|
const nextAncestors = new Set(ancestors);
|
|
67
17
|
nextAncestors.add(componentId);
|
|
68
18
|
const childProps = { interpreter, surfaceId, ancestors: nextAncestors, onAction, registry };
|
|
69
|
-
|
|
70
|
-
// Text props already passed the catalog schema. Parsing preserves that wire type at this
|
|
71
|
-
// Record<string, unknown> boundary without asserting a shape the compiler cannot verify.
|
|
72
|
-
const result = interpreter.resolve({ surfaceId, value: DynamicValueSchema.parse(value) });
|
|
73
|
-
if (!result.ok)
|
|
74
|
-
return `⚠ unresolved (${result.reason})`;
|
|
75
|
-
return typeof result.value === 'string' ? result.value : JSON.stringify(result.value);
|
|
76
|
-
}
|
|
77
|
-
function renderChildList(children) {
|
|
78
|
-
if (Array.isArray(children)) {
|
|
79
|
-
return children.map((childId) => _jsx(RenderComponent, { componentId: String(childId), ...childProps }, String(childId)));
|
|
80
|
-
}
|
|
81
|
-
return (_jsx("span", { className: "a2ui-placeholder", "data-a2ui-status": "unimplemented-template-list", children: "\u26A0 dynamic (template) child lists are not implemented by this port" }));
|
|
82
|
-
}
|
|
19
|
+
const { resolveText, renderChildList } = createA2uiCardNodeHelpers({ interpreter, surfaceId, childProps, renderNode: RenderComponent });
|
|
83
20
|
switch (component.component) {
|
|
84
21
|
case 'Text':
|
|
85
22
|
return (
|
|
@@ -122,172 +59,22 @@ function RenderComponent({ interpreter, surfaceId, componentId, ancestors, onAct
|
|
|
122
59
|
}
|
|
123
60
|
}
|
|
124
61
|
}
|
|
125
|
-
/**
|
|
126
|
-
|
|
127
|
-
* declared return type is `void | Promise<A2uiAgentActionOutcome>`, and TypeScript's structural
|
|
128
|
-
* typing means anything with a spec-shaped `then` — a hand-built thenable, a non-native promise
|
|
129
|
-
* library, a promise crossing a realm boundary (e.g. constructed inside an iframe) — satisfies
|
|
130
|
-
* `Promise<T>` at the call site without being `instanceof Promise` in *this* realm. An `instanceof`
|
|
131
|
-
* check would silently skip the await branch for any of those, dropping the delivery outcome on the
|
|
132
|
-
* floor — reintroducing, inside the fix for it, the exact silent-failure class this feature exists
|
|
133
|
-
* to remove. Do not "simplify" this back to `instanceof`.
|
|
134
|
-
*
|
|
135
|
-
* @complexity O(1).
|
|
136
|
-
* @overallScore 100
|
|
137
|
-
*/
|
|
138
|
-
function isThenable(value) {
|
|
139
|
-
return typeof value === 'object' && value !== null && typeof value.then === 'function';
|
|
140
|
-
}
|
|
62
|
+
/** Hooks A2uiSurfaceCard calls; defaults to the real ones, a test hands in fakes. */
|
|
63
|
+
export const defaultA2uiSurfaceCardHooks = { useT, useChatSurfaces, useA2uiSurfaceCard };
|
|
141
64
|
/** Registered against `ext-event-renderer-registry.ts`'s `'a2ui'` name — see module doc. */
|
|
142
|
-
export function A2uiSurfaceCard({ events, runId, onAgentAction, registry =
|
|
143
|
-
const t = useT();
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
// ALSO gains every registry component as a real, addable/removable catalog entry.
|
|
148
|
-
const catalog = useMemo(() => {
|
|
149
|
-
const base = createLabCatalog({});
|
|
150
|
-
return buildA2uiCatalogFromRegistry({ registry, catalogId: base.catalogId }, { base });
|
|
151
|
-
}, [registry]);
|
|
152
|
-
const interpreterRef = useRef(null);
|
|
153
|
-
if (!interpreterRef.current) {
|
|
154
|
-
const clock = createSystemClock();
|
|
155
|
-
interpreterRef.current = createA2uiInterpreter({
|
|
156
|
-
catalog,
|
|
157
|
-
clock,
|
|
158
|
-
ids: {
|
|
159
|
-
next: (_required) => {
|
|
160
|
-
actionIdCounter += 1;
|
|
161
|
-
return `a2ui-action-${actionIdCounter}-${clock.nowMs().toString(36)}`;
|
|
162
|
-
},
|
|
163
|
-
},
|
|
164
|
-
});
|
|
165
|
-
}
|
|
166
|
-
const interpreter = interpreterRef.current;
|
|
167
|
-
const [, forceRender] = useState(0);
|
|
168
|
-
const appliedCountRef = useRef(0);
|
|
169
|
-
const surfaceIdRef = useRef(undefined);
|
|
170
|
-
/** Monotonic ticket for `handleAction`'s agent-delivery attempts — see its use for why a host's
|
|
171
|
-
* promises settling out of order would otherwise repaint a superseded failure. */
|
|
172
|
-
const agentActionAttemptRef = useRef(0);
|
|
173
|
-
const [refusalNotice, setRefusalNotice] = useState(null);
|
|
174
|
-
const [pendingAgentAction, setPendingAgentAction] = useState(null);
|
|
175
|
-
const [localActionResult, setLocalActionResult] = useState(null);
|
|
176
|
-
const [deliveryFailureNotice, setDeliveryFailureNotice] = useState(null);
|
|
177
|
-
useEffect(() => {
|
|
178
|
-
const unsubscribe = interpreter.subscribe({ listener: () => forceRender((n) => n + 1) });
|
|
179
|
-
// React invokes cleanup with no arguments; the interpreter's port takes a required bag.
|
|
180
|
-
return () => unsubscribe({});
|
|
181
|
-
}, [interpreter]);
|
|
182
|
-
useEffect(() => {
|
|
183
|
-
while (appliedCountRef.current < events.length) {
|
|
184
|
-
const message = events[appliedCountRef.current];
|
|
185
|
-
appliedCountRef.current += 1;
|
|
186
|
-
const surfaceId = extractSurfaceId(message);
|
|
187
|
-
if (surfaceId)
|
|
188
|
-
surfaceIdRef.current = surfaceId;
|
|
189
|
-
const result = interpreter.applyAgentMessage({ raw: message });
|
|
190
|
-
if (result.unattributedViolation) {
|
|
191
|
-
setRefusalNotice(result.unattributedViolation);
|
|
192
|
-
}
|
|
193
|
-
else {
|
|
194
|
-
// A catalog-validation refusal (e.g. an unrecognized component type, or a known type with a
|
|
195
|
-
// missing/invalid required prop) surfaces as an `error`-shaped entry in `rendererMessages`,
|
|
196
|
-
// not `unattributedViolation`. Shown locally AND relayed through the exact same
|
|
197
|
-
// `onAgentAction` pipe a button click already uses: `errorMessage` is a real
|
|
198
|
-
// `RendererToAgentMessage` carrying `error.surfaceId`, which is all `onAgentAction`'s host
|
|
199
|
-
// implementation needs to address it — no second callback prop, no new wire shape. Without
|
|
200
|
-
// this relay a tool call that opened the surface has no way to learn its render was REFUSED
|
|
201
|
-
// and returns success anyway, which is worse than the silent-"waiting" bug this comment used
|
|
202
|
-
// to describe: it actively tells the agent (and, downstream, the human) that a chart is on
|
|
203
|
-
// screen when it never rendered at all.
|
|
204
|
-
const errorMessage = result.rendererMessages.find((m) => 'error' in m);
|
|
205
|
-
if (errorMessage) {
|
|
206
|
-
setRefusalNotice(errorMessage.error.message);
|
|
207
|
-
void onAgentAction?.(runId, errorMessage);
|
|
208
|
-
}
|
|
209
|
-
else {
|
|
210
|
-
// A message that applies cleanly clears any earlier refusal. `refusalNotice` describes
|
|
211
|
-
// whether the CURRENT surface is broken, not a permanent scar from an earlier mistake this
|
|
212
|
-
// same conversation already recovered from — e.g. a retry that fixed a missing prop, or an
|
|
213
|
-
// unrelated later `updateDataModel`. Without this, a stale "Action refused" banner from an
|
|
214
|
-
// early failed attempt sits underneath a chart that went on to render successfully.
|
|
215
|
-
setRefusalNotice(null);
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
// `onAgentAction`/`runId` included: the loop above now calls `onAgentAction` directly (relaying
|
|
220
|
-
// a validation error), not just on a later user click — the effect must see a fresh reference,
|
|
221
|
-
// the same way `handleAction`'s own (non-effect) call site already gets one on every render.
|
|
222
|
-
}, [events, interpreter, onAgentAction, runId]);
|
|
223
|
-
const surfaceId = surfaceIdRef.current;
|
|
224
|
-
const root = surfaceId ? interpreter.getRoot({ surfaceId }) : undefined;
|
|
225
|
-
function handleAction(componentId) {
|
|
226
|
-
// `surfaceId` is non-null here by construction, not by luck: this callback is only ever reached
|
|
227
|
-
// from a `Button` inside the rendered tree, and nothing renders until `root` resolves — which
|
|
228
|
-
// the `!root` early return below only permits when `surfaceId` was already truthy. Asserted
|
|
229
|
-
// rather than re-checked, exactly as the `RenderComponent` call site below already does.
|
|
230
|
-
const built = interpreter.buildAction({ surfaceId: surfaceId, componentId });
|
|
231
|
-
if (!built.ok) {
|
|
232
|
-
setRefusalNotice(built.reason);
|
|
233
|
-
return;
|
|
234
|
-
}
|
|
235
|
-
setRefusalNotice(null);
|
|
236
|
-
if (built.kind === 'local') {
|
|
237
|
-
// `buildAction`'s local branch is a pure computation (`resolveDynamicValue` over a
|
|
238
|
-
// registered catalog function's `impl`) — it never touches interpreter state, so there is
|
|
239
|
-
// nothing for `interpreter.subscribe` to notify and no re-render to "reflect" it. The only
|
|
240
|
-
// honest thing this component can do with the resolved value is show it.
|
|
241
|
-
setPendingAgentAction(null);
|
|
242
|
-
setLocalActionResult({ componentId, value: built.result });
|
|
243
|
-
return;
|
|
244
|
-
}
|
|
245
|
-
setLocalActionResult(null);
|
|
246
|
-
if (onAgentAction) {
|
|
247
|
-
// Clearing here, not just at the top of `handleAction`: a *previous* click's delivery failure
|
|
248
|
-
// must not linger next to a new attempt that has not resolved yet — same "stale notice beside
|
|
249
|
-
// a working control" concern `refusalNotice`'s own clearing already guards against.
|
|
250
|
-
setPendingAgentAction(null);
|
|
251
|
-
setDeliveryFailureNotice(null);
|
|
252
|
-
// Clearing the notice is not enough on its own: `onAgentAction` is host-supplied and its
|
|
253
|
-
// promises are not guaranteed to settle in call order, so an OLDER click's rejection could
|
|
254
|
-
// land after a newer one had already cleared the notice — repainting a failure the human has
|
|
255
|
-
// since superseded, next to a control that just worked. Only the latest attempt may write.
|
|
256
|
-
const attempt = (agentActionAttemptRef.current += 1);
|
|
257
|
-
const isLatestAttempt = () => agentActionAttemptRef.current === attempt;
|
|
258
|
-
const outcome = onAgentAction(runId, built.message);
|
|
259
|
-
// `isThenable`, not `instanceof Promise` — see that helper's own doc for why.
|
|
260
|
-
if (isThenable(outcome)) {
|
|
261
|
-
void outcome.then((result) => {
|
|
262
|
-
if (!result.ok && isLatestAttempt())
|
|
263
|
-
setDeliveryFailureNotice(result.reason);
|
|
264
|
-
}, (error) => {
|
|
265
|
-
// A rejection is the host's transport breaking, not a message the host chose to report —
|
|
266
|
-
// still surfaced, so the human sees *something* rather than a click that silently did
|
|
267
|
-
// nothing.
|
|
268
|
-
if (!isLatestAttempt())
|
|
269
|
-
return;
|
|
270
|
-
setDeliveryFailureNotice(error instanceof Error ? error.message : String(error));
|
|
271
|
-
});
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
else {
|
|
275
|
-
setPendingAgentAction(JSON.stringify(built.message));
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
function formatLocalActionValue(value) {
|
|
279
|
-
if (value === undefined)
|
|
280
|
-
return t('(no return value)');
|
|
281
|
-
return typeof value === 'string' ? value : JSON.stringify(value);
|
|
282
|
-
}
|
|
65
|
+
export function A2uiSurfaceCard({ events, runId, onAgentAction, clock, registry: registryProp, hooks = defaultA2uiSurfaceCardHooks }) {
|
|
66
|
+
const t = hooks.useT();
|
|
67
|
+
const surfaces = hooks.useChatSurfaces();
|
|
68
|
+
const registry = registryProp ?? surfaces.interactiveUi.defaultRegistry;
|
|
69
|
+
const { interpreter, surfaceId, root, refusalNotice, pendingAgentAction, localActionResult, deliveryFailureNotice, handleAction, formatLocalActionValue } = hooks.useA2uiSurfaceCard({ events, runId, onAgentAction, registry, t, clock });
|
|
283
70
|
if (!root) {
|
|
284
|
-
return refusalNotice ? (_jsx("div", { className: "a2ui-surface-card a2ui-surface-refused", role: "status", children: t('A2UI surface refused: {reason}', { reason: refusalNotice }) })) : (_jsx("div", { className: "a2ui-surface-card a2ui-surface-waiting", role: "status", children: t('Waiting for the agent to send a root component…') }));
|
|
71
|
+
return refusalNotice ? (_jsx("div", { className: "a2ui-surface-card a2ui-surface-refused", role: "status", children: t('A2UI surface refused: {reason}', { reason: refusalNotice }) })) : (_jsx("div", { className: "a2ui-surface-card jini-a2ui-surface-waiting", role: "status", children: t('Waiting for the agent to send a root component…') }));
|
|
285
72
|
}
|
|
286
|
-
return (_jsxs("div", { className: "a2ui-surface-card", "data-a2ui-surface-id": surfaceId, children: [_jsx(RenderComponent, { interpreter: interpreter, surfaceId: surfaceId, componentId: "root", ancestors: new Set(), onAction: handleAction, registry: registry }), refusalNotice ? (_jsx("div", { className: "a2ui-surface-notice a2ui-surface-notice-refused", role: "status", children: t('Action refused: {reason}', { reason: refusalNotice }) })) : null, pendingAgentAction ? (_jsx("div", { className: "a2ui-surface-notice a2ui-surface-notice-unwired", role: "status", children: t('This action is meant for the agent, but this host has not wired up a live agent-action relay yet.') })) : null, deliveryFailureNotice ? (
|
|
73
|
+
return (_jsxs("div", { className: "a2ui-surface-card", "data-a2ui-surface-id": surfaceId, children: [_jsx(RenderComponent, { interpreter: interpreter, surfaceId: surfaceId, componentId: "root", ancestors: new Set(), onAction: handleAction, registry: registry }), refusalNotice ? (_jsx("div", { className: "jini-a2ui-surface-notice a2ui-surface-notice-refused", role: "status", children: t('Action refused: {reason}', { reason: refusalNotice }) })) : null, pendingAgentAction ? (_jsx("div", { className: "jini-a2ui-surface-notice jini-a2ui-surface-notice-unwired", role: "status", children: t('This action is meant for the agent, but this host has not wired up a live agent-action relay yet.') })) : null, deliveryFailureNotice ? (
|
|
287
74
|
// Deliberately its own notice, not folded into `refusalNotice` above: that one fires
|
|
288
75
|
// *before* anything is sent (the interpreter said no); this one fires *after* — the message
|
|
289
76
|
// left this component but the host reports it never arrived. Conflating them would tell the
|
|
290
77
|
// human the wrong half of the story.
|
|
291
|
-
_jsx("div", { className: "a2ui-surface-notice a2ui-surface-notice-delivery-failed", role: "status", children: t('This action could not be delivered: {reason}', { reason: deliveryFailureNotice }) })) : null, localActionResult ? (_jsx("div", { className: "a2ui-surface-notice a2ui-surface-notice-local-action", role: "status", "data-a2ui-component-id": localActionResult.componentId, children: t('Local action resolved: {value}', { value: formatLocalActionValue(localActionResult.value) }) })) : null] }));
|
|
78
|
+
_jsx("div", { className: "jini-a2ui-surface-notice a2ui-surface-notice-delivery-failed", role: "status", children: t('This action could not be delivered: {reason}', { reason: deliveryFailureNotice }) })) : null, localActionResult ? (_jsx("div", { className: "jini-a2ui-surface-notice jini-a2ui-surface-notice-local-action", role: "status", "data-a2ui-component-id": localActionResult.componentId, children: t('Local action resolved: {value}', { value: formatLocalActionValue(localActionResult.value) }) })) : null] }));
|
|
292
79
|
}
|
|
293
80
|
//# sourceMappingURL=A2uiSurfaceCard.js.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type ComponentType, type ReactNode } from 'react';
|
|
2
|
+
import { type A2uiInterpreter } from '@jini-ai/protocol/a2ui';
|
|
3
|
+
import type { RenderComponentProps } from './A2uiSurfaceCard.hooks.js';
|
|
4
|
+
/** Resolve dynamic text and explicit child IDs for the card's renderer. */
|
|
5
|
+
export declare function createA2uiCardNodeHelpers({ interpreter, surfaceId, childProps, renderNode: Node }: {
|
|
6
|
+
interpreter: A2uiInterpreter;
|
|
7
|
+
surfaceId: string;
|
|
8
|
+
childProps: Omit<RenderComponentProps, 'componentId'>;
|
|
9
|
+
renderNode: ComponentType<RenderComponentProps>;
|
|
10
|
+
}, _options?: {}): {
|
|
11
|
+
resolveText: (value: unknown) => string;
|
|
12
|
+
renderChildList: (children: unknown) => ReactNode;
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=A2uiSurfaceCard.rules.d.ts.map
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { createElement } from 'react';
|
|
2
|
+
import { parseDynamicValue } from '@jini-ai/protocol/a2ui';
|
|
3
|
+
/** Resolve dynamic text and explicit child IDs for the card's renderer. */
|
|
4
|
+
export function createA2uiCardNodeHelpers({ interpreter, surfaceId, childProps, renderNode: Node }, _options = {}) {
|
|
5
|
+
function resolveText(value) {
|
|
6
|
+
// Text props already passed the catalog schema. Parsing preserves that wire type at this
|
|
7
|
+
// Record<string, unknown> boundary without asserting a shape the compiler cannot verify.
|
|
8
|
+
const parsed = parseDynamicValue({ value });
|
|
9
|
+
if (!parsed.ok)
|
|
10
|
+
throw new Error(parsed.error);
|
|
11
|
+
const result = interpreter.resolve({ surfaceId, value: parsed.value });
|
|
12
|
+
if (!result.ok)
|
|
13
|
+
return `⚠ unresolved (${result.reason})`;
|
|
14
|
+
return typeof result.value === 'string' ? result.value : JSON.stringify(result.value);
|
|
15
|
+
}
|
|
16
|
+
function renderChildList(children) {
|
|
17
|
+
if (Array.isArray(children)) {
|
|
18
|
+
return children.map((childId) => createElement(Node, { key: String(childId), componentId: String(childId), ...childProps }));
|
|
19
|
+
}
|
|
20
|
+
return createElement('span', { className: 'a2ui-placeholder', 'data-a2ui-status': 'unimplemented-template-list' }, '⚠ dynamic (template) child lists are not implemented by this port');
|
|
21
|
+
}
|
|
22
|
+
return { resolveText, renderChildList };
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=A2uiSurfaceCard.rules.js.map
|