@tomny-dev/uzi 0.17.0 → 0.18.0
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 +9 -0
- package/dist/components/ai-chat/AIChat.d.ts +8 -2
- package/dist/components/ai-chat/AIChat.d.ts.map +1 -1
- package/dist/components/ai-chat/AIChatDock.d.ts +4 -1
- package/dist/components/ai-chat/AIChatDock.d.ts.map +1 -1
- package/dist/index84.js +14 -5
- package/dist/index84.js.map +1 -1
- package/dist/index85.cjs +14 -5
- package/dist/index85.cjs.map +1 -1
- package/dist/index86.js +73 -47
- package/dist/index86.js.map +1 -1
- package/dist/index87.cjs +73 -47
- package/dist/index87.cjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -60,6 +60,15 @@ package. It has its own package name, tests and build and does not change the
|
|
|
60
60
|
published `@tomny-dev/uzi` UI entry points. See
|
|
61
61
|
[AI harness workspace](packages/ai/README.md) for usage and release status.
|
|
62
62
|
|
|
63
|
+
## Cloudflare platform foundation
|
|
64
|
+
|
|
65
|
+
This repository now also contains `packages/cloudflare`, an **unpublished, Worker-only**
|
|
66
|
+
integration workspace for typed D1 bindings and standardized API errors.
|
|
67
|
+
It is independent of `@tomny-dev/uzi` UI and `@tomny-dev/ai`; do not import it
|
|
68
|
+
in browser components. See [Cloudflare integration](packages/cloudflare/README.md)
|
|
69
|
+
and [platform architecture](docs/architecture/cloudflare-platform.md).
|
|
70
|
+
The package is intentionally private until its first consumer and release workflow are validated.
|
|
71
|
+
|
|
63
72
|
## Documentation
|
|
64
73
|
|
|
65
74
|
- [Getting Started](docs/getting-started.md) — Installation, styles, and first components
|
|
@@ -25,6 +25,10 @@ export interface AIChatProps {
|
|
|
25
25
|
readonly components?: AIChatComponents;
|
|
26
26
|
/** Actions displayed beside the native New chat control in one shared toolbar. */
|
|
27
27
|
readonly toolbarActions?: ReactNode;
|
|
28
|
+
/** When false, the enclosing AIChatDock owns the New chat control. */
|
|
29
|
+
readonly showNewChatInToolbar?: boolean;
|
|
30
|
+
/** Increment or replace this stable token to request the native New chat flow externally. */
|
|
31
|
+
readonly newChatRequestKey?: string | number;
|
|
28
32
|
/** Opt-in files, restricted to images/text accepted by the application API. */
|
|
29
33
|
readonly attachments?: AIChatAttachmentOptions;
|
|
30
34
|
/** Optional persistence; implementations must scope storage by user AND resource. */
|
|
@@ -72,6 +76,8 @@ export interface AIChatViewProps {
|
|
|
72
76
|
readonly onStop?: () => void;
|
|
73
77
|
readonly onRetry?: () => void;
|
|
74
78
|
readonly onNewChat?: () => void;
|
|
79
|
+
/** False when AIChatDock owns the new-chat action in its header. */
|
|
80
|
+
readonly showNewChatInToolbar?: boolean;
|
|
75
81
|
/** No limit by default: specialized apps decide their own session policy. */
|
|
76
82
|
readonly messageLimit?: number;
|
|
77
83
|
readonly inputPlaceholder?: string;
|
|
@@ -155,12 +161,12 @@ export interface AIChatMessageBubbleProps {
|
|
|
155
161
|
readonly className?: string;
|
|
156
162
|
}
|
|
157
163
|
export declare function AIChatMessageBubble({ role, label, children, className }: AIChatMessageBubbleProps): import("react/jsx-runtime").JSX.Element;
|
|
158
|
-
export declare function AIChat({ api, scope, scopeLabel, fetch: requestFetch, headers, credentials, prepareSendMessagesRequest, sessionKey, messageLimit, inputPlaceholder, inputAriaLabel, inputMaxLength, components, toolbarActions, attachments, history, sendAutomaticallyWhen, onClose, className, style, }: AIChatProps): import("react/jsx-runtime").JSX.Element;
|
|
164
|
+
export declare function AIChat({ api, scope, scopeLabel, fetch: requestFetch, headers, credentials, prepareSendMessagesRequest, sessionKey, messageLimit, inputPlaceholder, inputAriaLabel, inputMaxLength, components, toolbarActions, showNewChatInToolbar, newChatRequestKey, attachments, history, sendAutomaticallyWhen, onClose, className, style, }: AIChatProps): import("react/jsx-runtime").JSX.Element;
|
|
159
165
|
/**
|
|
160
166
|
* Controlled chat presentation for apps with their own AI SDK/assistant-ui
|
|
161
167
|
* runtime. It does not create providers, transports or chat state. Callbacks
|
|
162
168
|
* are the only way messages/actions leave the view.
|
|
163
169
|
*/
|
|
164
|
-
export declare function AIChatView({ messages, status, error, draft, onDraftChange, onSend, onStop, onRetry, onNewChat, messageLimit, inputPlaceholder, inputAriaLabel, inputMaxLength, components, attachments, onSelectAttachments, onRemoveAttachment, attachmentAccept, attachmentError, onToolApproval, toolbarActions, header, composerLeading, composerTrailing, composer, emptyState, className, style, }: AIChatViewProps): import("react/jsx-runtime").JSX.Element;
|
|
170
|
+
export declare function AIChatView({ messages, status, error, draft, onDraftChange, onSend, onStop, onRetry, onNewChat, showNewChatInToolbar, messageLimit, inputPlaceholder, inputAriaLabel, inputMaxLength, components, attachments, onSelectAttachments, onRemoveAttachment, attachmentAccept, attachmentError, onToolApproval, toolbarActions, header, composerLeading, composerTrailing, composer, emptyState, className, style, }: AIChatViewProps): import("react/jsx-runtime").JSX.Element;
|
|
165
171
|
export {};
|
|
166
172
|
//# sourceMappingURL=AIChat.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AIChat.d.ts","sourceRoot":"","sources":["../../../src/components/ai-chat/AIChat.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,aAAa,EAAE,aAAa,EAA4B,SAAS,EAAE,MAAM,OAAO,CAAC;AAG/F,OAAO,EAAE,SAAS,EAAE,sBAAsB,EAAgB,MAAM,sBAAsB,CAAC;AAIvF,KAAK,sBAAsB,GAAG,WAAW,CAAC,qBAAqB,CAAC,OAAO,sBAAsB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAEnG,MAAM,WAAW,WAAW;IAC1B,yCAAyC;IACzC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,yEAAyE;IACzE,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,+EAA+E;IAC/E,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAC7B,iFAAiF;IACjF,QAAQ,CAAC,KAAK,CAAC,EAAE,OA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AkMjB"}
|
|
@@ -12,6 +12,9 @@ export interface AIChatDockProps {
|
|
|
12
12
|
/** ID of the external launch button to restore keyboard focus after close. */
|
|
13
13
|
readonly externalLauncherId?: string;
|
|
14
14
|
readonly children: ReactNode;
|
|
15
|
+
/** Consumer-owned conversation reset; shown in the dock header beside expand/close. */
|
|
16
|
+
readonly onNewChat?: () => void;
|
|
17
|
+
readonly newChatDisabled?: boolean;
|
|
15
18
|
/** Controlled visibility; when omitted, the dock manages its own state. */
|
|
16
19
|
readonly open?: boolean;
|
|
17
20
|
readonly defaultOpen?: boolean;
|
|
@@ -29,5 +32,5 @@ export interface AIChatDockProps {
|
|
|
29
32
|
* Desktop is deliberately non-modal: Tab can move back into the page.
|
|
30
33
|
* On mobile the full-screen modal sheet traps sequential keyboard focus.
|
|
31
34
|
*/
|
|
32
|
-
export declare function AIChatDock({ title, description, launcherLabel, showLauncher, panelId: controlledPanelId, externalLauncherId, children, open, defaultOpen, onOpenChange, expanded, defaultExpanded, onExpandedChange, className, }: AIChatDockProps): import("react/jsx-runtime").JSX.Element;
|
|
35
|
+
export declare function AIChatDock({ title, description, launcherLabel, showLauncher, panelId: controlledPanelId, externalLauncherId, children, onNewChat, newChatDisabled, open, defaultOpen, onOpenChange, expanded, defaultExpanded, onExpandedChange, className, }: AIChatDockProps): import("react/jsx-runtime").JSX.Element;
|
|
33
36
|
//# sourceMappingURL=AIChatDock.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AIChatDock.d.ts","sourceRoot":"","sources":["../../../src/components/ai-chat/AIChatDock.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAsC,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAI3E,MAAM,WAAW,eAAe;IAC9B,2DAA2D;IAC3D,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B,kFAAkF;IAClF,QAAQ,CAAC,aAAa,CA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, index, components, onToolApproval, pendingApprovalId)
|
|
|
166
166
|
});
|
|
167
167
|
}
|
|
168
168
|
var DEFAULT_MESSAGE_LIMIT = 8;
|
|
169
|
-
function AIChat({ api, scope, scopeLabel, fetch: requestFetch, headers, credentials, prepareSendMessagesRequest, sessionKey, messageLimit = DEFAULT_MESSAGE_LIMIT, inputPlaceholder = "Ask a question...", inputAriaLabel = "Message", inputMaxLength = 2e3, components, toolbarActions, attachments, history, sendAutomaticallyWhen, onClose, className, style }) {
|
|
169
|
+
function AIChat({ api, scope, scopeLabel, fetch: requestFetch, headers, credentials, prepareSendMessagesRequest, sessionKey, messageLimit = DEFAULT_MESSAGE_LIMIT, inputPlaceholder = "Ask a question...", inputAriaLabel = "Message", inputMaxLength = 2e3, components, toolbarActions, showNewChatInToolbar = true, newChatRequestKey, attachments, history, sendAutomaticallyWhen, onClose, className, style }) {
|
|
170
170
|
const [session, setSession] = useState(0);
|
|
171
171
|
const transport = useMemo(() => new AssistantChatTransport({
|
|
172
172
|
api,
|
|
@@ -220,6 +220,8 @@ function AIChat({ api, scope, scopeLabel, fetch: requestFetch, headers, credenti
|
|
|
220
220
|
inputMaxLength,
|
|
221
221
|
components,
|
|
222
222
|
toolbarActions,
|
|
223
|
+
showNewChatInToolbar,
|
|
224
|
+
newChatRequestKey,
|
|
223
225
|
attachmentOptions: attachments,
|
|
224
226
|
history,
|
|
225
227
|
onNewChat: () => setSession((previous) => previous + 1)
|
|
@@ -234,7 +236,7 @@ function AIChat({ api, scope, scopeLabel, fetch: requestFetch, headers, credenti
|
|
|
234
236
|
]
|
|
235
237
|
});
|
|
236
238
|
}
|
|
237
|
-
function ChatViewport({ messageLimit, inputPlaceholder, inputAriaLabel, inputMaxLength, components, toolbarActions, attachmentOptions, history, onNewChat }) {
|
|
239
|
+
function ChatViewport({ messageLimit, inputPlaceholder, inputAriaLabel, inputMaxLength, components, toolbarActions, showNewChatInToolbar, newChatRequestKey, attachmentOptions, history, onNewChat }) {
|
|
238
240
|
const chat = useAISDKChat();
|
|
239
241
|
const [draft, setDraft] = useState("");
|
|
240
242
|
const [selectedFiles, setSelectedFiles] = useState([]);
|
|
@@ -351,6 +353,12 @@ function ChatViewport({ messageLimit, inputPlaceholder, inputAriaLabel, inputMax
|
|
|
351
353
|
onNewChat();
|
|
352
354
|
})();
|
|
353
355
|
};
|
|
356
|
+
const lastNewChatRequestKey = useRef(newChatRequestKey);
|
|
357
|
+
useEffect(() => {
|
|
358
|
+
if (lastNewChatRequestKey.current === newChatRequestKey) return;
|
|
359
|
+
lastNewChatRequestKey.current = newChatRequestKey;
|
|
360
|
+
handleNewChat();
|
|
361
|
+
}, [newChatRequestKey]);
|
|
354
362
|
const handleRetry = () => {
|
|
355
363
|
if (!chat || isBusy) return;
|
|
356
364
|
chat.clearError();
|
|
@@ -373,6 +381,7 @@ function ChatViewport({ messageLimit, inputPlaceholder, inputAriaLabel, inputMax
|
|
|
373
381
|
},
|
|
374
382
|
onRetry: handleRetry,
|
|
375
383
|
onNewChat: handleNewChat,
|
|
384
|
+
showNewChatInToolbar,
|
|
376
385
|
toolbarActions,
|
|
377
386
|
messageLimit,
|
|
378
387
|
attachments: selectedFiles.map((file, index) => ({
|
|
@@ -408,7 +417,7 @@ function ChatViewport({ messageLimit, inputPlaceholder, inputAriaLabel, inputMax
|
|
|
408
417
|
* runtime. It does not create providers, transports or chat state. Callbacks
|
|
409
418
|
* are the only way messages/actions leave the view.
|
|
410
419
|
*/
|
|
411
|
-
function AIChatView({ messages, status = "ready", error, draft = "", onDraftChange, onSend, onStop, onRetry, onNewChat, messageLimit, inputPlaceholder = "Ask a question...", inputAriaLabel = "Message", inputMaxLength = 2e3, components, attachments, onSelectAttachments, onRemoveAttachment, attachmentAccept, attachmentError, onToolApproval, toolbarActions, header, composerLeading, composerTrailing, composer, emptyState, className, style }) {
|
|
420
|
+
function AIChatView({ messages, status = "ready", error, draft = "", onDraftChange, onSend, onStop, onRetry, onNewChat, showNewChatInToolbar = true, messageLimit, inputPlaceholder = "Ask a question...", inputAriaLabel = "Message", inputMaxLength = 2e3, components, attachments, onSelectAttachments, onRemoveAttachment, attachmentAccept, attachmentError, onToolApproval, toolbarActions, header, composerLeading, composerTrailing, composer, emptyState, className, style }) {
|
|
412
421
|
const viewportRef = useRef(null);
|
|
413
422
|
const pinnedToBottom = useRef(true);
|
|
414
423
|
const fileInputRef = useRef(null);
|
|
@@ -453,14 +462,14 @@ function AIChatView({ messages, status = "ready", error, draft = "", onDraftChan
|
|
|
453
462
|
style,
|
|
454
463
|
children: [
|
|
455
464
|
header,
|
|
456
|
-
(
|
|
465
|
+
(toolbarActions || showNewChatInToolbar && onNewChat && messages.length > 0) && /* @__PURE__ */ jsxs("div", {
|
|
457
466
|
className: ai_chat_module_default.chatToolbar,
|
|
458
467
|
role: "toolbar",
|
|
459
468
|
"aria-label": "Conversation actions",
|
|
460
469
|
children: [/* @__PURE__ */ jsx("div", {
|
|
461
470
|
className: ai_chat_module_default.chatToolbarExtras,
|
|
462
471
|
children: toolbarActions
|
|
463
|
-
}), onNewChat && messages.length > 0 && /* @__PURE__ */ jsx("button", {
|
|
472
|
+
}), showNewChatInToolbar && onNewChat && messages.length > 0 && /* @__PURE__ */ jsx("button", {
|
|
464
473
|
type: "button",
|
|
465
474
|
className: ai_chat_module_default.newChatButton,
|
|
466
475
|
onClick: onNewChat,
|
package/dist/index84.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index84.js","names":[],"sources":["../src/components/ai-chat/AIChat.tsx"],"sourcesContent":["'use client';\n\nimport { useEffect, useMemo, useRef, useState } from 'react';\nimport type { CSSProperties, ComponentType, FormEvent, KeyboardEvent, ReactNode } from 'react';\n\nimport { AuiConfig, AuiProvider, ThreadPrimitive } from '@assistant-ui/react';\nimport { AISDKChat, AssistantChatTransport, useAISDKChat } from '@assistant-ui/ai-sdk';\n\nimport styles from './ai-chat.module.css';\n\ntype AIChatTransportOptions = NonNullable<ConstructorParameters<typeof AssistantChatTransport>[0]>;\n\nexport interface AIChatProps {\n /** AI SDK UI-message stream endpoint. */\n readonly api: string;\n /** Opaque scope identifier sent to the API. Server must authorize it. */\n readonly scope?: string;\n /** Human-readable display text; never used as an access-control identifier. */\n readonly scopeLabel?: string;\n /** Fetch adapter for authentication, request instrumentation and local demos. */\n readonly fetch?: typeof globalThis.fetch;\n readonly headers?: Record<string, string>;\n readonly credentials?: RequestCredentials;\n /** Customize serialized requests for APIs with a strict request schema. */\n readonly prepareSendMessagesRequest?: AIChatTransportOptions['prepareSendMessagesRequest'];\n /** Change this when the authenticated identity changes to reset the transcript. */\n readonly sessionKey?: string | number;\n /** Maximum number of user turns (default: 8). */\n readonly messageLimit?: number;\n readonly inputPlaceholder?: string;\n /** Accessible name for the message textarea. */\n readonly inputAriaLabel?: string;\n readonly inputMaxLength?: number;\n readonly components?: AIChatComponents;\n /** Actions displayed beside the native New chat control in one shared toolbar. */\n readonly toolbarActions?: ReactNode;\n /** Opt-in files, restricted to images/text accepted by the application API. */\n readonly attachments?: AIChatAttachmentOptions;\n /** Optional persistence; implementations must scope storage by user AND resource. */\n readonly history?: AIChatHistoryAdapter;\n /** Native SDK continuation predicate for tool approvals. */\n readonly sendAutomaticallyWhen?: NonNullable<Parameters<typeof AISDKChat>[0]>['sendAutomaticallyWhen'];\n readonly onClose?: () => void;\n readonly className?: string;\n readonly style?: CSSProperties;\n}\n\n/**\n * Framework-independent presentation contract. The parent owns the runtime,\n * message identities, approvals, uploads, history and security boundaries.\n * Uzi does not serialize, persist or reinterpret any messages supplied here.\n */\nexport type AIChatMessage = AIChatMessageRendererProps['message'];\n\nexport interface AIChatAttachmentOptions {\n readonly accept: string;\n readonly maxFiles?: number;\n readonly maxBytesPerFile?: number;\n}\n\nexport interface AIChatSelectedAttachment {\n readonly name: string;\n readonly size: number;\n /** Local thumbnail URL for supported image files. */\n readonly previewUrl?: string;\n}\n\nexport interface AIChatHistoryAdapter {\n /** Load only validated UI messages from the authenticated principal's own storage. */\n readonly load: () => Promise<readonly AIChatMessage[]> | readonly AIChatMessage[];\n /** Save after complete turns; the consumer decides what metadata is safe. */\n readonly save: (messages: readonly AIChatMessage[]) => Promise<void> | void;\n readonly clear: () => Promise<void> | void;\n /** Observability for failed history operations; never include message payloads in logs. */\n readonly onError?: (operation: 'load' | 'save' | 'clear', error: unknown) => void;\n}\n\nexport type AIChatToolApprovalHandler = (id: string, approved: boolean) => Promise<void> | void;\n\nexport interface AIChatViewProps {\n readonly messages: readonly AIChatMessage[];\n readonly status?: string;\n readonly error?: Error | null;\n readonly draft?: string;\n readonly onDraftChange?: (draft: string) => void;\n readonly onSend?: () => void;\n readonly onStop?: () => void;\n readonly onRetry?: () => void;\n readonly onNewChat?: () => void;\n /** No limit by default: specialized apps decide their own session policy. */\n readonly messageLimit?: number;\n readonly inputPlaceholder?: string;\n readonly inputAriaLabel?: string;\n readonly inputMaxLength?: number;\n readonly components?: AIChatComponents;\n readonly attachments?: readonly AIChatSelectedAttachment[];\n readonly onSelectAttachments?: (files: FileList) => void;\n readonly onRemoveAttachment?: (index: number) => void;\n readonly attachmentAccept?: string;\n readonly attachmentError?: string | null;\n /** Only invoked from explicit user action on an approval-requested tool part. */\n readonly onToolApproval?: AIChatToolApprovalHandler;\n /** Custom message toolbar controls, e.g. a conversation selector. */\n readonly toolbarActions?: ReactNode;\n /** Context labels or other app-owned notices above the transcript. */\n readonly header?: ReactNode;\n /** Upload actions, attachment previews or context chips before the input. */\n readonly composerLeading?: ReactNode;\n /** Additional buttons beside the Send/Stop control. */\n readonly composerTrailing?: ReactNode;\n /** Completely replace the composer while retaining shared transcript chrome. */\n readonly composer?: ReactNode;\n readonly emptyState?: ReactNode;\n readonly className?: string;\n readonly style?: CSSProperties;\n}\n\nexport interface AIChatComponents {\n readonly MessageRenderer?: ComponentType<AIChatMessageRendererProps>;\n readonly ReasoningRenderer?: ComponentType<AIChatReasoningRendererProps>;\n readonly SourceRenderer?: ComponentType<AIChatSourceRendererProps>;\n readonly DataRenderer?: ComponentType<AIChatDataRendererProps>;\n readonly ToolRenderer?: ComponentType<AIChatToolRendererProps>;\n readonly ErrorRenderer?: ComponentType<AIChatErrorRendererProps>;\n}\n\nexport interface AIChatMessageRendererProps {\n readonly message: {\n readonly id: string;\n readonly role: 'user' | 'assistant';\n readonly parts: readonly unknown[];\n readonly metadata?: Record<string, unknown>;\n };\n readonly renderMessagePart: (part: Record<string, unknown>, index: number) => ReactNode;\n readonly onToolApproval?: AIChatToolApprovalHandler;\n}\n\nexport interface AIChatReasoningRendererProps {\n readonly children: string;\n readonly title?: string;\n}\n\nexport interface AIChatSource {\n readonly id: string;\n readonly title?: string;\n readonly url?: string;\n}\n\nexport interface AIChatSourceRendererProps {\n readonly sources: readonly AIChatSource[];\n readonly renderSource: (source: AIChatSource, index: number) => ReactNode;\n}\n\nexport interface AIChatDataRendererProps {\n readonly data: readonly Record<string, unknown>[];\n readonly renderDataItem: (item: Record<string, unknown>, index: number) => ReactNode;\n}\n\nexport interface AIChatToolRendererProps {\n readonly part: Record<string, unknown>;\n readonly name: string;\n readonly approvalId?: string;\n readonly onApprove?: () => void;\n readonly onDeny?: () => void;\n readonly approvalPending: boolean;\n}\n\nexport interface AIChatErrorRendererProps {\n readonly error: Error;\n readonly onRetry: () => void;\n readonly onClear: () => void;\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n\nfunction asString(value: unknown): string | undefined {\n return typeof value === 'string' ? value : undefined;\n}\n\nfunction safeHttpUrl(value: unknown): string | undefined {\n const url = asString(value);\n return url && /^https?:\\/\\//i.test(url) ? url : undefined;\n}\n\n/** Reusable role-aware message surface for domain renderers. */\nexport interface AIChatMessageBubbleProps {\n readonly role: 'user' | 'assistant';\n readonly label?: string;\n readonly children: ReactNode;\n readonly className?: string;\n}\n\nexport function AIChatMessageBubble({ role, label, children, className }: AIChatMessageBubbleProps) {\n return (\n <div className={[styles.messageBubble, role === 'user' ? styles.userMessage : styles.assistantMessage, className]\n .filter(Boolean).join(' ')} data-role={role}>\n {label && <span className={styles.messageLabel}>{label}</span>}\n {children}\n </div>\n );\n}\n\nfunction DefaultMessageRenderer({ message, renderMessagePart }: AIChatMessageRendererProps) {\n return (\n <AIChatMessageBubble role={message.role}>\n {message.parts.map((part, index) => (\n <div key={isRecord(part) && typeof part.id === 'string' ? part.id : index}>\n {isRecord(part) ? renderMessagePart(part, index) : null}\n </div>\n ))}\n </AIChatMessageBubble>\n );\n}\n\nfunction DefaultReasoningRenderer({ children, title = 'Reasoning' }: AIChatReasoningRendererProps) {\n return (\n <details className={styles.reasoning}>\n <summary className={styles.reasoningSummary}>{title}</summary>\n <p className={styles.reasoningText}>{children}</p>\n </details>\n );\n}\n\nfunction DefaultSourceRenderer({ sources, renderSource }: AIChatSourceRendererProps) {\n return (\n <div className={styles.sources}>\n <span className={styles.sourcesLabel}>Sources</span>\n <ul>\n {sources.map((source, index) => (\n <li key={source.id}>{renderSource(source, index)}</li>\n ))}\n </ul>\n </div>\n );\n}\n\nfunction DefaultDataRenderer({ data, renderDataItem }: AIChatDataRendererProps) {\n return (\n <div className={styles.data}>\n {data.map((item, index) => (\n <div key={index}>{renderDataItem(item, index)}</div>\n ))}\n </div>\n );\n}\n\nfunction DefaultErrorRenderer({ error, onRetry, onClear }: AIChatErrorRendererProps) {\n return (\n <div className={styles.error} role=\"alert\">\n <p>{error.message}</p>\n <div className={styles.errorActions}>\n <button type=\"button\" onClick={onRetry}>Retry response</button>\n <button type=\"button\" onClick={onClear}>Start new chat</button>\n </div>\n </div>\n );\n}\n\nfunction renderPart(\n part: Record<string, unknown>,\n index: number,\n components: AIChatComponents | undefined,\n onToolApproval?: AIChatToolApprovalHandler,\n pendingApprovalId?: string | null,\n): ReactNode {\n const type = asString(part.type) ?? '';\n if (type === 'step-start') return null;\n if (type === 'text') {\n return <span className={styles.textPart}>{asString(part.text) ?? ''}</span>;\n }\n if (type === 'reasoning') {\n const ReasoningRenderer = components?.ReasoningRenderer ?? DefaultReasoningRenderer;\n return <ReasoningRenderer>{asString(part.text) ?? ''}</ReasoningRenderer>;\n }\n if (type === 'source-url' || type === 'source-document') {\n const SourceRenderer = components?.SourceRenderer ?? DefaultSourceRenderer;\n const source: AIChatSource = {\n id: asString(part.sourceId) ?? asString(part.id) ?? `source-${index}`,\n title: asString(part.title) ?? asString(part.filename),\n url: safeHttpUrl(part.url),\n };\n return (\n <SourceRenderer\n sources={[source]}\n renderSource={(item) => item.url ? (\n <a href={item.url} target=\"_blank\" rel=\"noopener noreferrer\">\n {item.title ?? item.url}\n </a>\n ) : <span>{item.title ?? item.id}</span>}\n />\n );\n }\n if (type.startsWith('data-')) {\n const DataRenderer = components?.DataRenderer ?? DefaultDataRenderer;\n return (\n <DataRenderer\n data={[part]}\n renderDataItem={(item) => (\n <pre className={styles.structuredData}>{JSON.stringify(item.data ?? item, null, 2)}</pre>\n )}\n />\n );\n }\n if (type.startsWith('tool-') || type === 'dynamic-tool') {\n const name = asString(part.toolName) ?? type.replace(/^tool-/, '');\n const approval = isRecord(part.approval) ? asString(part.approval.id) : undefined;\n const approvalId = part.state === 'approval-requested' ? approval : undefined;\n const controlsDisabled = pendingApprovalId !== null && pendingApprovalId !== undefined;\n const ToolRenderer = components?.ToolRenderer;\n const props: AIChatToolRendererProps = {\n part, name, approvalId,\n approvalPending: controlsDisabled,\n ...(approvalId && onToolApproval ? {\n onApprove: () => { if (!controlsDisabled) void onToolApproval(approvalId, true); },\n onDeny: () => { if (!controlsDisabled) void onToolApproval(approvalId, false); },\n } : {}),\n };\n if (ToolRenderer) return <ToolRenderer {...props} />;\n return (\n <div className={styles.toolPart}>\n <details>\n <summary>{name}</summary>\n <pre className={styles.structuredData}>\n {JSON.stringify(part.output ?? part.input ?? part, null, 2)}\n </pre>\n </details>\n {approvalId && (\n <div className={styles.approvalActions} aria-label={`Approval required for ${name}`}>\n {props.onApprove && props.onDeny ? (\n <>\n <button type=\"button\" disabled={controlsDisabled} onClick={props.onApprove}>Approve</button>\n <button type=\"button\" disabled={controlsDisabled} onClick={props.onDeny}>Deny</button>\n </>\n ) : <span>Approval required in application</span>}\n </div>\n )}\n </div>\n );\n }\n if (type === 'file' || type === 'image') {\n const url = safeHttpUrl(part.url);\n return url ? (\n <a href={url} target=\"_blank\" rel=\"noopener noreferrer\">\n {asString(part.filename) ?? 'View attachment'}\n </a>\n ) : <span>Attachment</span>;\n }\n // Preserve unsupported part types as inspectable data instead of silently dropping them.\n return <pre className={styles.structuredData}>{JSON.stringify(part, null, 2)}</pre>;\n}\n\nconst DEFAULT_MESSAGE_LIMIT = 8;\n\nexport function AIChat({\n api,\n scope,\n scopeLabel,\n fetch: requestFetch,\n headers,\n credentials,\n prepareSendMessagesRequest,\n sessionKey,\n messageLimit = DEFAULT_MESSAGE_LIMIT,\n inputPlaceholder = 'Ask a question...',\n inputAriaLabel = 'Message',\n inputMaxLength = 2000,\n components,\n toolbarActions,\n attachments,\n history,\n sendAutomaticallyWhen,\n onClose,\n className,\n style,\n}: AIChatProps) {\n // Remounting the provider creates a fresh AI SDK chat id, not merely an empty transcript.\n const [session, setSession] = useState(0);\n const transport = useMemo(\n () => new AssistantChatTransport({\n api,\n // The transport merges this with the AI SDK messages, id, model context and tools.\n // The endpoint, not the presentation component, must enforce the scope.\n ...(scope ? { body: { scope } } : {}),\n ...(requestFetch ? { fetch: requestFetch } : {}),\n ...(headers ? { headers } : {}),\n ...(credentials ? { credentials } : {}),\n ...(prepareSendMessagesRequest ? { prepareSendMessagesRequest } : {}),\n }),\n [api, scope, requestFetch, headers, credentials, prepareSendMessagesRequest],\n );\n const config = useMemo(\n () => AuiConfig({ threads: AISDKChat({ transport, ...(sendAutomaticallyWhen ? { sendAutomaticallyWhen } : {}) }) }),\n [transport, session, sendAutomaticallyWhen],\n );\n\n return (\n <div className={[styles.container, className].filter(Boolean).join(' ')} style={style}>\n {scopeLabel && (\n <div className={styles.scope}>\n <span className={styles.scopeLabel}>Current scope</span>\n <strong>{scopeLabel}</strong>\n </div>\n )}\n {onClose && (\n <button className={styles.closeBtn} type=\"button\" onClick={onClose} aria-label=\"Close chat\">\n ✕\n </button>\n )}\n <AuiProvider key={JSON.stringify([api, scope, sessionKey, session])} config={config}>\n <ThreadPrimitive.Root className={styles.thread}>\n <ChatViewport\n messageLimit={Number.isFinite(messageLimit) ? Math.max(1, Math.floor(messageLimit)) : DEFAULT_MESSAGE_LIMIT}\n inputPlaceholder={inputPlaceholder}\n inputAriaLabel={inputAriaLabel}\n inputMaxLength={inputMaxLength}\n components={components}\n toolbarActions={toolbarActions}\n attachmentOptions={attachments}\n history={history}\n onNewChat={() => setSession((previous) => previous + 1)}\n />\n </ThreadPrimitive.Root>\n </AuiProvider>\n </div>\n );\n}\n\ninterface ChatViewportProps {\n readonly messageLimit: number;\n readonly inputPlaceholder: string;\n readonly inputAriaLabel: string;\n readonly inputMaxLength: number;\n readonly components?: AIChatComponents;\n readonly toolbarActions?: ReactNode;\n readonly attachmentOptions?: AIChatAttachmentOptions;\n readonly history?: AIChatHistoryAdapter;\n readonly onNewChat: () => void;\n}\n\nfunction ChatViewport({\n messageLimit,\n inputPlaceholder,\n inputAriaLabel,\n inputMaxLength,\n components,\n toolbarActions,\n attachmentOptions,\n history,\n onNewChat,\n}: ChatViewportProps) {\n const chat = useAISDKChat();\n const [draft, setDraft] = useState('');\n const [selectedFiles, setSelectedFiles] = useState<File[]>([]);\n const [attachmentError, setAttachmentError] = useState<string | null>(null);\n const [attachmentPreviews, setAttachmentPreviews] = useState<string[]>([]);\n const [hydrated, setHydrated] = useState(!history);\n const expectedRestoredId = useRef<string | null>(null);\n const saveQueue = useRef<Promise<void>>(Promise.resolve());\n const [approvalBusy, setApprovalBusy] = useState(false);\n useEffect(() => {\n const urls = selectedFiles.map((file) => file.type.startsWith('image/') && typeof URL.createObjectURL === 'function' ? URL.createObjectURL(file) : '');\n setAttachmentPreviews(urls);\n return () => urls.forEach((url) => { if (url && typeof URL.revokeObjectURL === 'function') URL.revokeObjectURL(url); });\n }, [selectedFiles]);\n const messages = chat?.messages ?? [];\n const status = chat?.status ?? 'ready';\n const isBusy = status === 'submitted' || status === 'streaming';\n const historyFull = messages.filter((message) => message.role === 'user').length >= messageLimit;\n const reportHistoryError = (operation: 'load' | 'save' | 'clear', error: unknown) => {\n if (history?.onError) history.onError(operation, error);\n else console.warn(`[Uzi AIChat] History ${operation} failed`);\n };\n // Persist only complete turns. Do not save an empty runtime over stored history\n // during hydration or while a response is still streaming.\n useEffect(() => {\n if (!history) return;\n let active = true;\n void Promise.resolve().then(() => history.load()).then((restored) => {\n if (!active) return;\n if (Array.isArray(restored)) {\n const valid = restored.filter((message) =>\n typeof message?.id === 'string' &&\n (message.role === 'user' || message.role === 'assistant') &&\n Array.isArray(message.parts));\n expectedRestoredId.current = valid.length ? valid[0].id : null;\n if (valid.length) chat?.setMessages(valid as Parameters<NonNullable<typeof chat>['setMessages']>[0]);\n }\n setHydrated(true);\n }).catch((error: unknown) => {\n if (active) {\n reportHistoryError('load', error);\n setHydrated(true);\n }\n });\n return () => { active = false; };\n }, [chat?.setMessages, history]);\n\n useEffect(() => {\n if (!history || !hydrated || isBusy) return;\n const snapshot = messages.filter((message) => message.role === 'user' || message.role === 'assistant').map((message) => ({\n id: message.id, role: message.role as 'user' | 'assistant', parts: message.parts,\n ...(isRecord(message.metadata) ? { metadata: message.metadata } : {}),\n }));\n // Guard against the transient empty SDK state between history.load and\n // setMessages propagation; otherwise an old transcript could be erased.\n if (expectedRestoredId.current) {\n if (!snapshot.some((message) => message.id === expectedRestoredId.current)) return;\n expectedRestoredId.current = null;\n }\n // Serialize writes. New Chat waits for in-flight writes before clearing.\n saveQueue.current = saveQueue.current.then(\n () => history.save(snapshot),\n () => history.save(snapshot),\n ).then(\n () => {},\n (error: unknown) => { reportHistoryError('save', error); },\n );\n }, [history, hydrated, isBusy, messages]);\n\n const handleSelectedFiles = (files: FileList) => {\n if (!attachmentOptions) return;\n const selected = Array.from(files);\n if (selected.length + selectedFiles.length > (attachmentOptions.maxFiles ?? 3)) {\n setAttachmentError('Too many attachments.');\n return;\n }\n if (selected.some((file) => file.size > (attachmentOptions.maxBytesPerFile ?? 5 * 1024 * 1024))) {\n setAttachmentError('An attachment exceeds the size limit.');\n return;\n }\n const allowedTypes = attachmentOptions.accept.split(',').map((item) => item.trim());\n if (selected.some((file) => !allowedTypes.some((allow) => (\n allow === file.type || (allow.endsWith('/*') && file.type.startsWith(allow.slice(0, -1)))\n )))) {\n setAttachmentError('Unsupported attachment type.');\n return;\n }\n setAttachmentError(null);\n setSelectedFiles((existing) => [...existing, ...selected]);\n };\n\n const handleSubmit = () => {\n const text = draft.trim();\n if (!chat || (!text && selectedFiles.length === 0) || isBusy || historyFull || chat.error || !hydrated || approvalBusy) return;\n const files = selectedFiles.length ? new DataTransfer() : null;\n selectedFiles.forEach((file) => files?.items.add(file));\n // AI SDK serializes FileList to FileUIParts and sends them through the\n // app-owned transport. The server MUST validate types and sizes again.\n // Clear the composer promptly; restore the draft and files if submission\n // fails, so users do not lose attachments or typed content.\n const previousDraft = draft;\n const previousFiles = selectedFiles;\n setDraft('');\n setSelectedFiles([]);\n setAttachmentError(null);\n void Promise.resolve(chat.sendMessage({ text, ...(files ? { files: files.files } : {}) }))\n .catch(() => {\n setDraft((current) => current || previousDraft);\n setSelectedFiles((current) => current.length ? current : previousFiles);\n });\n };\n\n const handleNewChat = () => {\n void (async () => {\n await chat?.stop();\n if (history) {\n try {\n await saveQueue.current;\n await history.clear();\n } catch (error) {\n reportHistoryError('clear', error);\n return;\n }\n }\n onNewChat();\n })();\n };\n\n const handleRetry = () => {\n if (!chat || isBusy) return;\n chat.clearError();\n void chat.regenerate();\n };\n\n return (\n <AIChatView\n messages={messages.filter((message) => message.role === 'user' || message.role === 'assistant').map((message) => ({\n id: message.id,\n role: message.role as 'user' | 'assistant',\n parts: message.parts,\n ...(isRecord(message.metadata) ? { metadata: message.metadata } : {}),\n }))}\n status={status}\n error={chat?.error}\n draft={draft}\n onDraftChange={setDraft}\n onSend={handleSubmit}\n onStop={() => { void chat?.stop(); }}\n onRetry={handleRetry}\n onNewChat={handleNewChat}\n toolbarActions={toolbarActions}\n messageLimit={messageLimit}\n attachments={selectedFiles.map((file, index) => ({ name: file.name, size: file.size, ...(attachmentPreviews[index] ? { previewUrl: attachmentPreviews[index] } : {}) }))}\n onSelectAttachments={attachmentOptions ? handleSelectedFiles : undefined}\n onRemoveAttachment={attachmentOptions ? (index) => setSelectedFiles((files) => files.filter((_, i) => i !== index)) : undefined}\n attachmentAccept={attachmentOptions?.accept}\n attachmentError={attachmentError}\n onToolApproval={chat ? async (id, approved) => {\n if (approvalBusy) return;\n setApprovalBusy(true);\n try { await chat.addToolApprovalResponse({ id, approved, ...(!approved ? { reason: 'User denied approval' } : {}) }); }\n finally { setApprovalBusy(false); }\n } : undefined}\n inputPlaceholder={inputPlaceholder}\n inputAriaLabel={inputAriaLabel}\n inputMaxLength={inputMaxLength}\n components={components}\n />\n );\n}\n\n/**\n * Controlled chat presentation for apps with their own AI SDK/assistant-ui\n * runtime. It does not create providers, transports or chat state. Callbacks\n * are the only way messages/actions leave the view.\n */\nexport function AIChatView({\n messages,\n status = 'ready',\n error,\n draft = '',\n onDraftChange,\n onSend,\n onStop,\n onRetry,\n onNewChat,\n messageLimit,\n inputPlaceholder = 'Ask a question...',\n inputAriaLabel = 'Message',\n inputMaxLength = 2000,\n components,\n attachments,\n onSelectAttachments,\n onRemoveAttachment,\n attachmentAccept,\n attachmentError,\n onToolApproval,\n toolbarActions,\n header,\n composerLeading,\n composerTrailing,\n composer,\n emptyState,\n className,\n style,\n}: AIChatViewProps) {\n const viewportRef = useRef<HTMLDivElement>(null);\n const pinnedToBottom = useRef(true);\n const fileInputRef = useRef<HTMLInputElement>(null);\n const approvalRef = useRef<string | null>(null);\n const [pendingApprovalId, setPendingApprovalId] = useState<string | null>(null);\n const [approvalError, setApprovalError] = useState<string | null>(null);\n const respondToApproval: AIChatToolApprovalHandler = async (id, approved) => {\n if (!onToolApproval || approvalRef.current) return;\n approvalRef.current = id;\n setPendingApprovalId(id);\n setApprovalError(null);\n try { await onToolApproval(id, approved); }\n catch { setApprovalError('Could not submit approval. Please try again.'); }\n finally { approvalRef.current = null; setPendingApprovalId(null); }\n };\n const isBusy = status === 'submitted' || status === 'streaming';\n const limit = messageLimit != null && Number.isFinite(messageLimit)\n ? Math.max(1, Math.floor(messageLimit)) : null;\n const historyFull = limit !== null && messages.filter((message) => message.role === 'user').length >= limit;\n const MessageRenderer = components?.MessageRenderer ?? DefaultMessageRenderer;\n const ErrorRenderer = components?.ErrorRenderer ?? DefaultErrorRenderer;\n\n // Follow streaming text only if the user is already near the bottom.\n useEffect(() => {\n const viewport = viewportRef.current;\n if (viewport && pinnedToBottom.current) viewport.scrollTop = viewport.scrollHeight;\n });\n\n const handleKeyDown = (event: KeyboardEvent<HTMLTextAreaElement>) => {\n if (event.key === 'Enter' && !event.shiftKey && !event.nativeEvent.isComposing) {\n event.preventDefault();\n if (!isBusy && !historyFull && !error && (draft.trim() || (attachments?.length ?? 0) > 0)) onSend?.();\n }\n };\n\n const handleFormSubmit = (event: FormEvent<HTMLFormElement>) => {\n event.preventDefault();\n if (!isBusy && !historyFull && !error && (draft.trim() || (attachments?.length ?? 0) > 0)) onSend?.();\n };\n\n return (\n <div className={[styles.thread, className].filter(Boolean).join(' ')} style={style}>\n {header}\n {(messages.length > 0 || toolbarActions) && (onNewChat || toolbarActions) && (\n <div className={styles.chatToolbar} role=\"toolbar\" aria-label=\"Conversation actions\">\n <div className={styles.chatToolbarExtras}>{toolbarActions}</div>\n {onNewChat && messages.length > 0 && (\n <button\n type=\"button\"\n className={styles.newChatButton}\n onClick={onNewChat}\n aria-label=\"New chat\"\n title=\"New chat\"\n >\n <svg aria-hidden=\"true\" width=\"18\" height=\"18\" viewBox=\"0 0 24 24\" fill=\"none\"\n stroke=\"currentColor\" strokeWidth=\"1.8\" strokeLinecap=\"round\" strokeLinejoin=\"round\">\n <path d=\"M12 5H6a2 2 0 0 0-2 2v11a2 2 0 0 0 2 2h11a2 2 0 0 0 2-2v-6\" />\n <path d=\"m15 5 4 4M13 11l7-7a2.12 2.12 0 0 1 3 3l-7 7-4 1 1-4Z\" transform=\"translate(-2 -2)\" />\n </svg>\n </button>\n )}\n </div>\n )}\n <div\n ref={viewportRef}\n className={styles.viewport}\n onScroll={(event) => {\n const viewport = event.currentTarget;\n pinnedToBottom.current = viewport.scrollHeight - viewport.scrollTop - viewport.clientHeight < 80;\n }}\n >\n <div className={styles.messageList} role=\"log\" aria-label=\"Chat history\" aria-live=\"polite\">\n {messages.length === 0 && (\n <div className={styles.emptyState}>\n {emptyState ?? <p>Start a conversation</p>}\n </div>\n )}\n {messages.map((message) => (\n <MessageRenderer\n key={message.id}\n message={message}\n renderMessagePart={(part, index) => renderPart(part, index, components, onToolApproval ? respondToApproval : undefined, pendingApprovalId)}\n onToolApproval={onToolApproval ? respondToApproval : undefined}\n />\n ))}\n {isBusy && <p className={styles.status}>Thinking...</p>}\n </div>\n </div>\n <div className={styles.footer}>\n {approvalError && <p role=\"alert\" className={styles.attachmentError}>{approvalError}</p>}\n {attachmentError && <p role=\"alert\" className={styles.attachmentError}>{attachmentError}</p>}\n {error && (\n onRetry && onNewChat ? (\n <ErrorRenderer error={error} onRetry={onRetry} onClear={onNewChat} />\n ) : (\n <div className={styles.error} role=\"alert\">\n <p>{error.message}</p>\n {(onRetry || onNewChat) && (\n <div className={styles.errorActions}>\n {onRetry && <button type=\"button\" onClick={onRetry}>Retry response</button>}\n {onNewChat && <button type=\"button\" onClick={onNewChat}>Start new chat</button>}\n </div>\n )}\n </div>\n )\n )}\n {historyFull && !error && !isBusy && onNewChat && (\n <div className={styles.historyLimit}>\n <span>This chat has reached its {limit}-question limit.</span>\n <button type=\"button\" onClick={onNewChat}>Start new chat</button>\n </div>\n )}\n {(!historyFull || isBusy) && !error && (\n composer !== undefined ? composer : (\n <form className={styles.composerForm} onSubmit={handleFormSubmit}>\n {composerLeading && <div className={styles.composerExtras}>{composerLeading}</div>}\n {onSelectAttachments && (\n <div className={styles.composerExtras}>\n <input\n ref={fileInputRef}\n className={styles.visuallyHidden}\n type=\"file\"\n aria-label=\"Add attachments\"\n accept={attachmentAccept}\n multiple\n disabled={isBusy}\n onChange={(event) => {\n if (event.target.files) onSelectAttachments(event.target.files);\n event.target.value = '';\n }}\n />\n {attachments && attachments.length > 0 && (\n <ul className={styles.attachmentList}>\n {attachments.map((attachment, index) => (\n <li key={index}>\n {attachment.previewUrl ? <img className={styles.attachmentThumbnail} src={attachment.previewUrl} alt={attachment.name} /> : <span className={styles.attachmentFilename}>{attachment.name}</span>}\n {onRemoveAttachment && (\n <button type=\"button\" onClick={() => onRemoveAttachment(index)}\n aria-label={`Remove ${attachment.name}`} title={`Remove ${attachment.name}`}>×</button>\n )}\n </li>\n ))}\n </ul>\n )}\n </div>\n )}\n <div className={styles.composerSurface}>\n <div className={styles.composerRow}>\n {onSelectAttachments && (\n <button type=\"button\" className={styles.composerIconButton}\n aria-label=\"Attach file\" title=\"Attach file\"\n disabled={isBusy} onClick={() => fileInputRef.current?.click()}>\n <svg width=\"20\" height=\"20\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\"\n strokeWidth=\"1.8\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n <path d=\"m21 11-8.5 8.5a6 6 0 0 1-8.5-8.5l9-9a4 4 0 0 1 5.7 5.7l-9 9a2 2 0 0 1-2.8-2.8l8.5-8.5\" />\n </svg>\n </button>\n )}\n <textarea\n className={styles.input}\n aria-label={inputAriaLabel}\n rows={1}\n value={draft}\n onChange={(event) => onDraftChange?.(event.target.value)}\n onKeyDown={handleKeyDown}\n placeholder={inputPlaceholder}\n maxLength={inputMaxLength}\n disabled={isBusy || !onSend || !onDraftChange}\n readOnly={!onDraftChange}\n />\n <div className={styles.composerActions}>\n {composerTrailing}\n {isBusy ? (\n onStop && <button type=\"button\" className={styles.composerIconButton} onClick={onStop}\n aria-label=\"Stop response\" title=\"Stop response\">\n <svg width=\"18\" height=\"18\" viewBox=\"0 0 24 24\" fill=\"currentColor\" aria-hidden=\"true\"><rect x=\"5\" y=\"5\" width=\"14\" height=\"14\" rx=\"2\" /></svg>\n </button>\n ) : (\n <button type=\"submit\" className={styles.sendButton} aria-label=\"Send message\"\n title=\"Send message\" disabled={!onSend || (!draft.trim() && !attachments?.length)}>\n <svg width=\"20\" height=\"20\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\"\n strokeWidth=\"2\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\"><path d=\"M12 19V5m-7 7 7-7 7 7\" /></svg>\n </button>\n )}\n </div>\n </div>\n </div>\n </form>\n )\n )}\n </div>\n </div>\n );\n}\n"],"mappings":";;;;;;;AA6KA,SAAS,SAAS,OAAkD;CAClE,OAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,KAAK;AAC5E;AAEA,SAAS,SAAS,OAAoC;CACpD,OAAO,OAAO,UAAU,WAAW,QAAQ,KAAA;AAC7C;AAEA,SAAS,YAAY,OAAoC;CACvD,MAAM,MAAM,SAAS,KAAK;CAC1B,OAAO,OAAO,gBAAgB,KAAK,GAAG,IAAI,MAAM,KAAA;AAClD;AAUA,SAAgB,oBAAoB,EAAE,MAAM,OAAO,UAAU,aAAuC;CAClG,OACE,qBAAC,OAAD;EAAK,WAAW;GAAC,uBAAO;GAAe,SAAS,SAAS,uBAAO,cAAc,uBAAO;GAAkB;EAAS,CAAC,CAC9G,OAAO,OAAO,CAAC,CAAC,KAAK,GAAG;EAAG,aAAW;YADzC,CAEG,SAAS,oBAAC,QAAD;GAAM,WAAW,uBAAO;aAAe;EAAY,CAAA,GAC5D,QACE;;AAET;AAEA,SAAS,uBAAuB,EAAE,SAAS,qBAAiD;CAC1F,OACE,oBAAC,qBAAD;EAAqB,MAAM,QAAQ;YAChC,QAAQ,MAAM,KAAK,MAAM,UACxB,oBAA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I,eAAc;aAAQ,gBAAe;aAAQ,eAAY;uBAAO,oBAAC,QAAD,EAAM,GAAE,wBAAyB,CAAA;YAAM,CAAA;WACnH,CAAA,CAEP;;SACF;;OACF,CAAA;MACD;;IAGP;;EACF;;AAET"}
|
|
1
|
+
{"version":3,"file":"index84.js","names":[],"sources":["../src/components/ai-chat/AIChat.tsx"],"sourcesContent":["'use client';\n\nimport { useEffect, useMemo, useRef, useState } from 'react';\nimport type { CSSProperties, ComponentType, FormEvent, KeyboardEvent, ReactNode } from 'react';\n\nimport { AuiConfig, AuiProvider, ThreadPrimitive } from '@assistant-ui/react';\nimport { AISDKChat, AssistantChatTransport, useAISDKChat } from '@assistant-ui/ai-sdk';\n\nimport styles from './ai-chat.module.css';\n\ntype AIChatTransportOptions = NonNullable<ConstructorParameters<typeof AssistantChatTransport>[0]>;\n\nexport interface AIChatProps {\n /** AI SDK UI-message stream endpoint. */\n readonly api: string;\n /** Opaque scope identifier sent to the API. Server must authorize it. */\n readonly scope?: string;\n /** Human-readable display text; never used as an access-control identifier. */\n readonly scopeLabel?: string;\n /** Fetch adapter for authentication, request instrumentation and local demos. */\n readonly fetch?: typeof globalThis.fetch;\n readonly headers?: Record<string, string>;\n readonly credentials?: RequestCredentials;\n /** Customize serialized requests for APIs with a strict request schema. */\n readonly prepareSendMessagesRequest?: AIChatTransportOptions['prepareSendMessagesRequest'];\n /** Change this when the authenticated identity changes to reset the transcript. */\n readonly sessionKey?: string | number;\n /** Maximum number of user turns (default: 8). */\n readonly messageLimit?: number;\n readonly inputPlaceholder?: string;\n /** Accessible name for the message textarea. */\n readonly inputAriaLabel?: string;\n readonly inputMaxLength?: number;\n readonly components?: AIChatComponents;\n /** Actions displayed beside the native New chat control in one shared toolbar. */\n readonly toolbarActions?: ReactNode;\n /** When false, the enclosing AIChatDock owns the New chat control. */\n readonly showNewChatInToolbar?: boolean;\n /** Increment or replace this stable token to request the native New chat flow externally. */\n readonly newChatRequestKey?: string | number;\n /** Opt-in files, restricted to images/text accepted by the application API. */\n readonly attachments?: AIChatAttachmentOptions;\n /** Optional persistence; implementations must scope storage by user AND resource. */\n readonly history?: AIChatHistoryAdapter;\n /** Native SDK continuation predicate for tool approvals. */\n readonly sendAutomaticallyWhen?: NonNullable<Parameters<typeof AISDKChat>[0]>['sendAutomaticallyWhen'];\n readonly onClose?: () => void;\n readonly className?: string;\n readonly style?: CSSProperties;\n}\n\n/**\n * Framework-independent presentation contract. The parent owns the runtime,\n * message identities, approvals, uploads, history and security boundaries.\n * Uzi does not serialize, persist or reinterpret any messages supplied here.\n */\nexport type AIChatMessage = AIChatMessageRendererProps['message'];\n\nexport interface AIChatAttachmentOptions {\n readonly accept: string;\n readonly maxFiles?: number;\n readonly maxBytesPerFile?: number;\n}\n\nexport interface AIChatSelectedAttachment {\n readonly name: string;\n readonly size: number;\n /** Local thumbnail URL for supported image files. */\n readonly previewUrl?: string;\n}\n\nexport interface AIChatHistoryAdapter {\n /** Load only validated UI messages from the authenticated principal's own storage. */\n readonly load: () => Promise<readonly AIChatMessage[]> | readonly AIChatMessage[];\n /** Save after complete turns; the consumer decides what metadata is safe. */\n readonly save: (messages: readonly AIChatMessage[]) => Promise<void> | void;\n readonly clear: () => Promise<void> | void;\n /** Observability for failed history operations; never include message payloads in logs. */\n readonly onError?: (operation: 'load' | 'save' | 'clear', error: unknown) => void;\n}\n\nexport type AIChatToolApprovalHandler = (id: string, approved: boolean) => Promise<void> | void;\n\nexport interface AIChatViewProps {\n readonly messages: readonly AIChatMessage[];\n readonly status?: string;\n readonly error?: Error | null;\n readonly draft?: string;\n readonly onDraftChange?: (draft: string) => void;\n readonly onSend?: () => void;\n readonly onStop?: () => void;\n readonly onRetry?: () => void;\n readonly onNewChat?: () => void;\n /** False when AIChatDock owns the new-chat action in its header. */\n readonly showNewChatInToolbar?: boolean;\n /** No limit by default: specialized apps decide their own session policy. */\n readonly messageLimit?: number;\n readonly inputPlaceholder?: string;\n readonly inputAriaLabel?: string;\n readonly inputMaxLength?: number;\n readonly components?: AIChatComponents;\n readonly attachments?: readonly AIChatSelectedAttachment[];\n readonly onSelectAttachments?: (files: FileList) => void;\n readonly onRemoveAttachment?: (index: number) => void;\n readonly attachmentAccept?: string;\n readonly attachmentError?: string | null;\n /** Only invoked from explicit user action on an approval-requested tool part. */\n readonly onToolApproval?: AIChatToolApprovalHandler;\n /** Custom message toolbar controls, e.g. a conversation selector. */\n readonly toolbarActions?: ReactNode;\n /** Context labels or other app-owned notices above the transcript. */\n readonly header?: ReactNode;\n /** Upload actions, attachment previews or context chips before the input. */\n readonly composerLeading?: ReactNode;\n /** Additional buttons beside the Send/Stop control. */\n readonly composerTrailing?: ReactNode;\n /** Completely replace the composer while retaining shared transcript chrome. */\n readonly composer?: ReactNode;\n readonly emptyState?: ReactNode;\n readonly className?: string;\n readonly style?: CSSProperties;\n}\n\nexport interface AIChatComponents {\n readonly MessageRenderer?: ComponentType<AIChatMessageRendererProps>;\n readonly ReasoningRenderer?: ComponentType<AIChatReasoningRendererProps>;\n readonly SourceRenderer?: ComponentType<AIChatSourceRendererProps>;\n readonly DataRenderer?: ComponentType<AIChatDataRendererProps>;\n readonly ToolRenderer?: ComponentType<AIChatToolRendererProps>;\n readonly ErrorRenderer?: ComponentType<AIChatErrorRendererProps>;\n}\n\nexport interface AIChatMessageRendererProps {\n readonly message: {\n readonly id: string;\n readonly role: 'user' | 'assistant';\n readonly parts: readonly unknown[];\n readonly metadata?: Record<string, unknown>;\n };\n readonly renderMessagePart: (part: Record<string, unknown>, index: number) => ReactNode;\n readonly onToolApproval?: AIChatToolApprovalHandler;\n}\n\nexport interface AIChatReasoningRendererProps {\n readonly children: string;\n readonly title?: string;\n}\n\nexport interface AIChatSource {\n readonly id: string;\n readonly title?: string;\n readonly url?: string;\n}\n\nexport interface AIChatSourceRendererProps {\n readonly sources: readonly AIChatSource[];\n readonly renderSource: (source: AIChatSource, index: number) => ReactNode;\n}\n\nexport interface AIChatDataRendererProps {\n readonly data: readonly Record<string, unknown>[];\n readonly renderDataItem: (item: Record<string, unknown>, index: number) => ReactNode;\n}\n\nexport interface AIChatToolRendererProps {\n readonly part: Record<string, unknown>;\n readonly name: string;\n readonly approvalId?: string;\n readonly onApprove?: () => void;\n readonly onDeny?: () => void;\n readonly approvalPending: boolean;\n}\n\nexport interface AIChatErrorRendererProps {\n readonly error: Error;\n readonly onRetry: () => void;\n readonly onClear: () => void;\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n\nfunction asString(value: unknown): string | undefined {\n return typeof value === 'string' ? value : undefined;\n}\n\nfunction safeHttpUrl(value: unknown): string | undefined {\n const url = asString(value);\n return url && /^https?:\\/\\//i.test(url) ? url : undefined;\n}\n\n/** Reusable role-aware message surface for domain renderers. */\nexport interface AIChatMessageBubbleProps {\n readonly role: 'user' | 'assistant';\n readonly label?: string;\n readonly children: ReactNode;\n readonly className?: string;\n}\n\nexport function AIChatMessageBubble({ role, label, children, className }: AIChatMessageBubbleProps) {\n return (\n <div className={[styles.messageBubble, role === 'user' ? styles.userMessage : styles.assistantMessage, className]\n .filter(Boolean).join(' ')} data-role={role}>\n {label && <span className={styles.messageLabel}>{label}</span>}\n {children}\n </div>\n );\n}\n\nfunction DefaultMessageRenderer({ message, renderMessagePart }: AIChatMessageRendererProps) {\n return (\n <AIChatMessageBubble role={message.role}>\n {message.parts.map((part, index) => (\n <div key={isRecord(part) && typeof part.id === 'string' ? part.id : index}>\n {isRecord(part) ? renderMessagePart(part, index) : null}\n </div>\n ))}\n </AIChatMessageBubble>\n );\n}\n\nfunction DefaultReasoningRenderer({ children, title = 'Reasoning' }: AIChatReasoningRendererProps) {\n return (\n <details className={styles.reasoning}>\n <summary className={styles.reasoningSummary}>{title}</summary>\n <p className={styles.reasoningText}>{children}</p>\n </details>\n );\n}\n\nfunction DefaultSourceRenderer({ sources, renderSource }: AIChatSourceRendererProps) {\n return (\n <div className={styles.sources}>\n <span className={styles.sourcesLabel}>Sources</span>\n <ul>\n {sources.map((source, index) => (\n <li key={source.id}>{renderSource(source, index)}</li>\n ))}\n </ul>\n </div>\n );\n}\n\nfunction DefaultDataRenderer({ data, renderDataItem }: AIChatDataRendererProps) {\n return (\n <div className={styles.data}>\n {data.map((item, index) => (\n <div key={index}>{renderDataItem(item, index)}</div>\n ))}\n </div>\n );\n}\n\nfunction DefaultErrorRenderer({ error, onRetry, onClear }: AIChatErrorRendererProps) {\n return (\n <div className={styles.error} role=\"alert\">\n <p>{error.message}</p>\n <div className={styles.errorActions}>\n <button type=\"button\" onClick={onRetry}>Retry response</button>\n <button type=\"button\" onClick={onClear}>Start new chat</button>\n </div>\n </div>\n );\n}\n\nfunction renderPart(\n part: Record<string, unknown>,\n index: number,\n components: AIChatComponents | undefined,\n onToolApproval?: AIChatToolApprovalHandler,\n pendingApprovalId?: string | null,\n): ReactNode {\n const type = asString(part.type) ?? '';\n if (type === 'step-start') return null;\n if (type === 'text') {\n return <span className={styles.textPart}>{asString(part.text) ?? ''}</span>;\n }\n if (type === 'reasoning') {\n const ReasoningRenderer = components?.ReasoningRenderer ?? DefaultReasoningRenderer;\n return <ReasoningRenderer>{asString(part.text) ?? ''}</ReasoningRenderer>;\n }\n if (type === 'source-url' || type === 'source-document') {\n const SourceRenderer = components?.SourceRenderer ?? DefaultSourceRenderer;\n const source: AIChatSource = {\n id: asString(part.sourceId) ?? asString(part.id) ?? `source-${index}`,\n title: asString(part.title) ?? asString(part.filename),\n url: safeHttpUrl(part.url),\n };\n return (\n <SourceRenderer\n sources={[source]}\n renderSource={(item) => item.url ? (\n <a href={item.url} target=\"_blank\" rel=\"noopener noreferrer\">\n {item.title ?? item.url}\n </a>\n ) : <span>{item.title ?? item.id}</span>}\n />\n );\n }\n if (type.startsWith('data-')) {\n const DataRenderer = components?.DataRenderer ?? DefaultDataRenderer;\n return (\n <DataRenderer\n data={[part]}\n renderDataItem={(item) => (\n <pre className={styles.structuredData}>{JSON.stringify(item.data ?? item, null, 2)}</pre>\n )}\n />\n );\n }\n if (type.startsWith('tool-') || type === 'dynamic-tool') {\n const name = asString(part.toolName) ?? type.replace(/^tool-/, '');\n const approval = isRecord(part.approval) ? asString(part.approval.id) : undefined;\n const approvalId = part.state === 'approval-requested' ? approval : undefined;\n const controlsDisabled = pendingApprovalId !== null && pendingApprovalId !== undefined;\n const ToolRenderer = components?.ToolRenderer;\n const props: AIChatToolRendererProps = {\n part, name, approvalId,\n approvalPending: controlsDisabled,\n ...(approvalId && onToolApproval ? {\n onApprove: () => { if (!controlsDisabled) void onToolApproval(approvalId, true); },\n onDeny: () => { if (!controlsDisabled) void onToolApproval(approvalId, false); },\n } : {}),\n };\n if (ToolRenderer) return <ToolRenderer {...props} />;\n return (\n <div className={styles.toolPart}>\n <details>\n <summary>{name}</summary>\n <pre className={styles.structuredData}>\n {JSON.stringify(part.output ?? part.input ?? part, null, 2)}\n </pre>\n </details>\n {approvalId && (\n <div className={styles.approvalActions} aria-label={`Approval required for ${name}`}>\n {props.onApprove && props.onDeny ? (\n <>\n <button type=\"button\" disabled={controlsDisabled} onClick={props.onApprove}>Approve</button>\n <button type=\"button\" disabled={controlsDisabled} onClick={props.onDeny}>Deny</button>\n </>\n ) : <span>Approval required in application</span>}\n </div>\n )}\n </div>\n );\n }\n if (type === 'file' || type === 'image') {\n const url = safeHttpUrl(part.url);\n return url ? (\n <a href={url} target=\"_blank\" rel=\"noopener noreferrer\">\n {asString(part.filename) ?? 'View attachment'}\n </a>\n ) : <span>Attachment</span>;\n }\n // Preserve unsupported part types as inspectable data instead of silently dropping them.\n return <pre className={styles.structuredData}>{JSON.stringify(part, null, 2)}</pre>;\n}\n\nconst DEFAULT_MESSAGE_LIMIT = 8;\n\nexport function AIChat({\n api,\n scope,\n scopeLabel,\n fetch: requestFetch,\n headers,\n credentials,\n prepareSendMessagesRequest,\n sessionKey,\n messageLimit = DEFAULT_MESSAGE_LIMIT,\n inputPlaceholder = 'Ask a question...',\n inputAriaLabel = 'Message',\n inputMaxLength = 2000,\n components,\n toolbarActions,\n showNewChatInToolbar = true,\n newChatRequestKey,\n attachments,\n history,\n sendAutomaticallyWhen,\n onClose,\n className,\n style,\n}: AIChatProps) {\n // Remounting the provider creates a fresh AI SDK chat id, not merely an empty transcript.\n const [session, setSession] = useState(0);\n const transport = useMemo(\n () => new AssistantChatTransport({\n api,\n // The transport merges this with the AI SDK messages, id, model context and tools.\n // The endpoint, not the presentation component, must enforce the scope.\n ...(scope ? { body: { scope } } : {}),\n ...(requestFetch ? { fetch: requestFetch } : {}),\n ...(headers ? { headers } : {}),\n ...(credentials ? { credentials } : {}),\n ...(prepareSendMessagesRequest ? { prepareSendMessagesRequest } : {}),\n }),\n [api, scope, requestFetch, headers, credentials, prepareSendMessagesRequest],\n );\n const config = useMemo(\n () => AuiConfig({ threads: AISDKChat({ transport, ...(sendAutomaticallyWhen ? { sendAutomaticallyWhen } : {}) }) }),\n [transport, session, sendAutomaticallyWhen],\n );\n\n return (\n <div className={[styles.container, className].filter(Boolean).join(' ')} style={style}>\n {scopeLabel && (\n <div className={styles.scope}>\n <span className={styles.scopeLabel}>Current scope</span>\n <strong>{scopeLabel}</strong>\n </div>\n )}\n {onClose && (\n <button className={styles.closeBtn} type=\"button\" onClick={onClose} aria-label=\"Close chat\">\n ✕\n </button>\n )}\n <AuiProvider key={JSON.stringify([api, scope, sessionKey, session])} config={config}>\n <ThreadPrimitive.Root className={styles.thread}>\n <ChatViewport\n messageLimit={Number.isFinite(messageLimit) ? Math.max(1, Math.floor(messageLimit)) : DEFAULT_MESSAGE_LIMIT}\n inputPlaceholder={inputPlaceholder}\n inputAriaLabel={inputAriaLabel}\n inputMaxLength={inputMaxLength}\n components={components}\n toolbarActions={toolbarActions}\n showNewChatInToolbar={showNewChatInToolbar}\n newChatRequestKey={newChatRequestKey}\n attachmentOptions={attachments}\n history={history}\n onNewChat={() => setSession((previous) => previous + 1)}\n />\n </ThreadPrimitive.Root>\n </AuiProvider>\n </div>\n );\n}\n\ninterface ChatViewportProps {\n readonly messageLimit: number;\n readonly inputPlaceholder: string;\n readonly inputAriaLabel: string;\n readonly inputMaxLength: number;\n readonly components?: AIChatComponents;\n readonly toolbarActions?: ReactNode;\n readonly showNewChatInToolbar?: boolean;\n readonly newChatRequestKey?: string | number;\n readonly attachmentOptions?: AIChatAttachmentOptions;\n readonly history?: AIChatHistoryAdapter;\n readonly onNewChat: () => void;\n}\n\nfunction ChatViewport({\n messageLimit,\n inputPlaceholder,\n inputAriaLabel,\n inputMaxLength,\n components,\n toolbarActions,\n showNewChatInToolbar,\n newChatRequestKey,\n attachmentOptions,\n history,\n onNewChat,\n}: ChatViewportProps) {\n const chat = useAISDKChat();\n const [draft, setDraft] = useState('');\n const [selectedFiles, setSelectedFiles] = useState<File[]>([]);\n const [attachmentError, setAttachmentError] = useState<string | null>(null);\n const [attachmentPreviews, setAttachmentPreviews] = useState<string[]>([]);\n const [hydrated, setHydrated] = useState(!history);\n const expectedRestoredId = useRef<string | null>(null);\n const saveQueue = useRef<Promise<void>>(Promise.resolve());\n const [approvalBusy, setApprovalBusy] = useState(false);\n useEffect(() => {\n const urls = selectedFiles.map((file) => file.type.startsWith('image/') && typeof URL.createObjectURL === 'function' ? URL.createObjectURL(file) : '');\n setAttachmentPreviews(urls);\n return () => urls.forEach((url) => { if (url && typeof URL.revokeObjectURL === 'function') URL.revokeObjectURL(url); });\n }, [selectedFiles]);\n const messages = chat?.messages ?? [];\n const status = chat?.status ?? 'ready';\n const isBusy = status === 'submitted' || status === 'streaming';\n const historyFull = messages.filter((message) => message.role === 'user').length >= messageLimit;\n const reportHistoryError = (operation: 'load' | 'save' | 'clear', error: unknown) => {\n if (history?.onError) history.onError(operation, error);\n else console.warn(`[Uzi AIChat] History ${operation} failed`);\n };\n // Persist only complete turns. Do not save an empty runtime over stored history\n // during hydration or while a response is still streaming.\n useEffect(() => {\n if (!history) return;\n let active = true;\n void Promise.resolve().then(() => history.load()).then((restored) => {\n if (!active) return;\n if (Array.isArray(restored)) {\n const valid = restored.filter((message) =>\n typeof message?.id === 'string' &&\n (message.role === 'user' || message.role === 'assistant') &&\n Array.isArray(message.parts));\n expectedRestoredId.current = valid.length ? valid[0].id : null;\n if (valid.length) chat?.setMessages(valid as Parameters<NonNullable<typeof chat>['setMessages']>[0]);\n }\n setHydrated(true);\n }).catch((error: unknown) => {\n if (active) {\n reportHistoryError('load', error);\n setHydrated(true);\n }\n });\n return () => { active = false; };\n }, [chat?.setMessages, history]);\n\n useEffect(() => {\n if (!history || !hydrated || isBusy) return;\n const snapshot = messages.filter((message) => message.role === 'user' || message.role === 'assistant').map((message) => ({\n id: message.id, role: message.role as 'user' | 'assistant', parts: message.parts,\n ...(isRecord(message.metadata) ? { metadata: message.metadata } : {}),\n }));\n // Guard against the transient empty SDK state between history.load and\n // setMessages propagation; otherwise an old transcript could be erased.\n if (expectedRestoredId.current) {\n if (!snapshot.some((message) => message.id === expectedRestoredId.current)) return;\n expectedRestoredId.current = null;\n }\n // Serialize writes. New Chat waits for in-flight writes before clearing.\n saveQueue.current = saveQueue.current.then(\n () => history.save(snapshot),\n () => history.save(snapshot),\n ).then(\n () => {},\n (error: unknown) => { reportHistoryError('save', error); },\n );\n }, [history, hydrated, isBusy, messages]);\n\n const handleSelectedFiles = (files: FileList) => {\n if (!attachmentOptions) return;\n const selected = Array.from(files);\n if (selected.length + selectedFiles.length > (attachmentOptions.maxFiles ?? 3)) {\n setAttachmentError('Too many attachments.');\n return;\n }\n if (selected.some((file) => file.size > (attachmentOptions.maxBytesPerFile ?? 5 * 1024 * 1024))) {\n setAttachmentError('An attachment exceeds the size limit.');\n return;\n }\n const allowedTypes = attachmentOptions.accept.split(',').map((item) => item.trim());\n if (selected.some((file) => !allowedTypes.some((allow) => (\n allow === file.type || (allow.endsWith('/*') && file.type.startsWith(allow.slice(0, -1)))\n )))) {\n setAttachmentError('Unsupported attachment type.');\n return;\n }\n setAttachmentError(null);\n setSelectedFiles((existing) => [...existing, ...selected]);\n };\n\n const handleSubmit = () => {\n const text = draft.trim();\n if (!chat || (!text && selectedFiles.length === 0) || isBusy || historyFull || chat.error || !hydrated || approvalBusy) return;\n const files = selectedFiles.length ? new DataTransfer() : null;\n selectedFiles.forEach((file) => files?.items.add(file));\n // AI SDK serializes FileList to FileUIParts and sends them through the\n // app-owned transport. The server MUST validate types and sizes again.\n // Clear the composer promptly; restore the draft and files if submission\n // fails, so users do not lose attachments or typed content.\n const previousDraft = draft;\n const previousFiles = selectedFiles;\n setDraft('');\n setSelectedFiles([]);\n setAttachmentError(null);\n void Promise.resolve(chat.sendMessage({ text, ...(files ? { files: files.files } : {}) }))\n .catch(() => {\n setDraft((current) => current || previousDraft);\n setSelectedFiles((current) => current.length ? current : previousFiles);\n });\n };\n\n const handleNewChat = () => {\n void (async () => {\n await chat?.stop();\n if (history) {\n try {\n await saveQueue.current;\n await history.clear();\n } catch (error) {\n reportHistoryError('clear', error);\n return;\n }\n }\n onNewChat();\n })();\n };\n\n // An enclosing dock can reuse the native reset path without duplicating\n // history deletion, aborts, or SDK session management in each consumer.\n const lastNewChatRequestKey = useRef(newChatRequestKey);\n useEffect(() => {\n if (lastNewChatRequestKey.current === newChatRequestKey) return;\n lastNewChatRequestKey.current = newChatRequestKey;\n handleNewChat();\n }, [newChatRequestKey]);\n\n const handleRetry = () => {\n if (!chat || isBusy) return;\n chat.clearError();\n void chat.regenerate();\n };\n\n return (\n <AIChatView\n messages={messages.filter((message) => message.role === 'user' || message.role === 'assistant').map((message) => ({\n id: message.id,\n role: message.role as 'user' | 'assistant',\n parts: message.parts,\n ...(isRecord(message.metadata) ? { metadata: message.metadata } : {}),\n }))}\n status={status}\n error={chat?.error}\n draft={draft}\n onDraftChange={setDraft}\n onSend={handleSubmit}\n onStop={() => { void chat?.stop(); }}\n onRetry={handleRetry}\n onNewChat={handleNewChat}\n showNewChatInToolbar={showNewChatInToolbar}\n toolbarActions={toolbarActions}\n messageLimit={messageLimit}\n attachments={selectedFiles.map((file, index) => ({ name: file.name, size: file.size, ...(attachmentPreviews[index] ? { previewUrl: attachmentPreviews[index] } : {}) }))}\n onSelectAttachments={attachmentOptions ? handleSelectedFiles : undefined}\n onRemoveAttachment={attachmentOptions ? (index) => setSelectedFiles((files) => files.filter((_, i) => i !== index)) : undefined}\n attachmentAccept={attachmentOptions?.accept}\n attachmentError={attachmentError}\n onToolApproval={chat ? async (id, approved) => {\n if (approvalBusy) return;\n setApprovalBusy(true);\n try { await chat.addToolApprovalResponse({ id, approved, ...(!approved ? { reason: 'User denied approval' } : {}) }); }\n finally { setApprovalBusy(false); }\n } : undefined}\n inputPlaceholder={inputPlaceholder}\n inputAriaLabel={inputAriaLabel}\n inputMaxLength={inputMaxLength}\n components={components}\n />\n );\n}\n\n/**\n * Controlled chat presentation for apps with their own AI SDK/assistant-ui\n * runtime. It does not create providers, transports or chat state. Callbacks\n * are the only way messages/actions leave the view.\n */\nexport function AIChatView({\n messages,\n status = 'ready',\n error,\n draft = '',\n onDraftChange,\n onSend,\n onStop,\n onRetry,\n onNewChat,\n showNewChatInToolbar = true,\n messageLimit,\n inputPlaceholder = 'Ask a question...',\n inputAriaLabel = 'Message',\n inputMaxLength = 2000,\n components,\n attachments,\n onSelectAttachments,\n onRemoveAttachment,\n attachmentAccept,\n attachmentError,\n onToolApproval,\n toolbarActions,\n header,\n composerLeading,\n composerTrailing,\n composer,\n emptyState,\n className,\n style,\n}: AIChatViewProps) {\n const viewportRef = useRef<HTMLDivElement>(null);\n const pinnedToBottom = useRef(true);\n const fileInputRef = useRef<HTMLInputElement>(null);\n const approvalRef = useRef<string | null>(null);\n const [pendingApprovalId, setPendingApprovalId] = useState<string | null>(null);\n const [approvalError, setApprovalError] = useState<string | null>(null);\n const respondToApproval: AIChatToolApprovalHandler = async (id, approved) => {\n if (!onToolApproval || approvalRef.current) return;\n approvalRef.current = id;\n setPendingApprovalId(id);\n setApprovalError(null);\n try { await onToolApproval(id, approved); }\n catch { setApprovalError('Could not submit approval. Please try again.'); }\n finally { approvalRef.current = null; setPendingApprovalId(null); }\n };\n const isBusy = status === 'submitted' || status === 'streaming';\n const limit = messageLimit != null && Number.isFinite(messageLimit)\n ? Math.max(1, Math.floor(messageLimit)) : null;\n const historyFull = limit !== null && messages.filter((message) => message.role === 'user').length >= limit;\n const MessageRenderer = components?.MessageRenderer ?? DefaultMessageRenderer;\n const ErrorRenderer = components?.ErrorRenderer ?? DefaultErrorRenderer;\n\n // Follow streaming text only if the user is already near the bottom.\n useEffect(() => {\n const viewport = viewportRef.current;\n if (viewport && pinnedToBottom.current) viewport.scrollTop = viewport.scrollHeight;\n });\n\n const handleKeyDown = (event: KeyboardEvent<HTMLTextAreaElement>) => {\n if (event.key === 'Enter' && !event.shiftKey && !event.nativeEvent.isComposing) {\n event.preventDefault();\n if (!isBusy && !historyFull && !error && (draft.trim() || (attachments?.length ?? 0) > 0)) onSend?.();\n }\n };\n\n const handleFormSubmit = (event: FormEvent<HTMLFormElement>) => {\n event.preventDefault();\n if (!isBusy && !historyFull && !error && (draft.trim() || (attachments?.length ?? 0) > 0)) onSend?.();\n };\n\n return (\n <div className={[styles.thread, className].filter(Boolean).join(' ')} style={style}>\n {header}\n {(toolbarActions || (showNewChatInToolbar && onNewChat && messages.length > 0)) && (\n <div className={styles.chatToolbar} role=\"toolbar\" aria-label=\"Conversation actions\">\n <div className={styles.chatToolbarExtras}>{toolbarActions}</div>\n {showNewChatInToolbar && onNewChat && messages.length > 0 && (\n <button\n type=\"button\"\n className={styles.newChatButton}\n onClick={onNewChat}\n aria-label=\"New chat\"\n title=\"New chat\"\n >\n <svg aria-hidden=\"true\" width=\"18\" height=\"18\" viewBox=\"0 0 24 24\" fill=\"none\"\n stroke=\"currentColor\" strokeWidth=\"1.8\" strokeLinecap=\"round\" strokeLinejoin=\"round\">\n <path d=\"M12 5H6a2 2 0 0 0-2 2v11a2 2 0 0 0 2 2h11a2 2 0 0 0 2-2v-6\" />\n <path d=\"m15 5 4 4M13 11l7-7a2.12 2.12 0 0 1 3 3l-7 7-4 1 1-4Z\" transform=\"translate(-2 -2)\" />\n </svg>\n </button>\n )}\n </div>\n )}\n <div\n ref={viewportRef}\n className={styles.viewport}\n onScroll={(event) => {\n const viewport = event.currentTarget;\n pinnedToBottom.current = viewport.scrollHeight - viewport.scrollTop - viewport.clientHeight < 80;\n }}\n >\n <div className={styles.messageList} role=\"log\" aria-label=\"Chat history\" aria-live=\"polite\">\n {messages.length === 0 && (\n <div className={styles.emptyState}>\n {emptyState ?? <p>Start a conversation</p>}\n </div>\n )}\n {messages.map((message) => (\n <MessageRenderer\n key={message.id}\n message={message}\n renderMessagePart={(part, index) => renderPart(part, index, components, onToolApproval ? respondToApproval : undefined, pendingApprovalId)}\n onToolApproval={onToolApproval ? respondToApproval : undefined}\n />\n ))}\n {isBusy && <p className={styles.status}>Thinking...</p>}\n </div>\n </div>\n <div className={styles.footer}>\n {approvalError && <p role=\"alert\" className={styles.attachmentError}>{approvalError}</p>}\n {attachmentError && <p role=\"alert\" className={styles.attachmentError}>{attachmentError}</p>}\n {error && (\n onRetry && onNewChat ? (\n <ErrorRenderer error={error} onRetry={onRetry} onClear={onNewChat} />\n ) : (\n <div className={styles.error} role=\"alert\">\n <p>{error.message}</p>\n {(onRetry || onNewChat) && (\n <div className={styles.errorActions}>\n {onRetry && <button type=\"button\" onClick={onRetry}>Retry response</button>}\n {onNewChat && <button type=\"button\" onClick={onNewChat}>Start new chat</button>}\n </div>\n )}\n </div>\n )\n )}\n {historyFull && !error && !isBusy && onNewChat && (\n <div className={styles.historyLimit}>\n <span>This chat has reached its {limit}-question limit.</span>\n <button type=\"button\" onClick={onNewChat}>Start new chat</button>\n </div>\n )}\n {(!historyFull || isBusy) && !error && (\n composer !== undefined ? composer : (\n <form className={styles.composerForm} onSubmit={handleFormSubmit}>\n {composerLeading && <div className={styles.composerExtras}>{composerLeading}</div>}\n {onSelectAttachments && (\n <div className={styles.composerExtras}>\n <input\n ref={fileInputRef}\n className={styles.visuallyHidden}\n type=\"file\"\n aria-label=\"Add attachments\"\n accept={attachmentAccept}\n multiple\n disabled={isBusy}\n onChange={(event) => {\n if (event.target.files) onSelectAttachments(event.target.files);\n event.target.value = '';\n }}\n />\n {attachments && attachments.length > 0 && (\n <ul className={styles.attachmentList}>\n {attachments.map((attachment, index) => (\n <li key={index}>\n {attachment.previewUrl ? <img className={styles.attachmentThumbnail} src={attachment.previewUrl} alt={attachment.name} /> : <span className={styles.attachmentFilename}>{attachment.name}</span>}\n {onRemoveAttachment && (\n <button type=\"button\" onClick={() => onRemoveAttachment(index)}\n aria-label={`Remove ${attachment.name}`} title={`Remove ${attachment.name}`}>×</button>\n )}\n </li>\n ))}\n </ul>\n )}\n </div>\n )}\n <div className={styles.composerSurface}>\n <div className={styles.composerRow}>\n {onSelectAttachments && (\n <button type=\"button\" className={styles.composerIconButton}\n aria-label=\"Attach file\" title=\"Attach file\"\n disabled={isBusy} onClick={() => fileInputRef.current?.click()}>\n <svg width=\"20\" height=\"20\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\"\n strokeWidth=\"1.8\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n <path d=\"m21 11-8.5 8.5a6 6 0 0 1-8.5-8.5l9-9a4 4 0 0 1 5.7 5.7l-9 9a2 2 0 0 1-2.8-2.8l8.5-8.5\" />\n </svg>\n </button>\n )}\n <textarea\n className={styles.input}\n aria-label={inputAriaLabel}\n rows={1}\n value={draft}\n onChange={(event) => onDraftChange?.(event.target.value)}\n onKeyDown={handleKeyDown}\n placeholder={inputPlaceholder}\n maxLength={inputMaxLength}\n disabled={isBusy || !onSend || !onDraftChange}\n readOnly={!onDraftChange}\n />\n <div className={styles.composerActions}>\n {composerTrailing}\n {isBusy ? (\n onStop && <button type=\"button\" className={styles.composerIconButton} onClick={onStop}\n aria-label=\"Stop response\" title=\"Stop response\">\n <svg width=\"18\" height=\"18\" viewBox=\"0 0 24 24\" fill=\"currentColor\" aria-hidden=\"true\"><rect x=\"5\" y=\"5\" width=\"14\" height=\"14\" rx=\"2\" /></svg>\n </button>\n ) : (\n <button type=\"submit\" className={styles.sendButton} aria-label=\"Send message\"\n title=\"Send message\" disabled={!onSend || (!draft.trim() && !attachments?.length)}>\n <svg width=\"20\" height=\"20\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\"\n strokeWidth=\"2\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\"><path d=\"M12 19V5m-7 7 7-7 7 7\" /></svg>\n </button>\n )}\n </div>\n </div>\n </div>\n </form>\n )\n )}\n </div>\n </div>\n );\n}\n"],"mappings":";;;;;;;AAmLA,SAAS,SAAS,OAAkD;CAClE,OAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,KAAK;AAC5E;AAEA,SAAS,SAAS,OAAoC;CACpD,OAAO,OAAO,UAAU,WAAW,QAAQ,KAAA;AAC7C;AAEA,SAAS,YAAY,OAAoC;CACvD,MAAM,MAAM,SAAS,KAAK;CAC1B,OAAO,OAAO,gBAAgB,KAAK,GAAG,IAAI,MAAM,KAAA;AAClD;AAUA,SAAgB,oBAAoB,EAAE,MAAM,OAAO,UAAU,aAAuC;CAClG,OACE,qBAAC,OAAD;EAAK,WAAW;GAAC,uBAAO;GAAe,SAAS,SAAS,uBAAO,cAAc,uBAAO;GAAkB;EAAS,CAAC,CAC9G,OAAO,OAAO,CAAC,CAAC,KAAK,GAAG;EAAG,aAAW;YADzC,CAEG,SAAS,oBAAC,QAAD;GAAM,WAAW,uBAAO;aAAe;EAAY,CAAA,GAC5D,QACE;;AAET;AAEA,SAAS,uBAAuB,EAAE,SAAS,qBAAiD;CAC1F,OACE,oBAAC,qBAAD;EAAqB,MAAM,QAAQ;YAChC,QAAQ,MAAM,KAAK,MAAM,UACxB,oBAAC,OAAD,EAAA,UACG,SAAS,IAAI,IAAI,kBAAkB,MAAM,KAAK,IAAI,KAChD,GAFK,SAAS,IAAI,KAAK,OAAO,KAAK,OAAO,WAAW,KAAK,KA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BAC1E,oBAAC,OAAD;aAAK,OAAM;aAAK,QAAO;aAAK,SAAQ;aAAY,MAAK;aAAO,QAAO;aACjE,aAAY;aAAI,eAAc;aAAQ,gBAAe;aAAQ,eAAY;uBAAO,oBAAC,QAAD,EAAM,GAAE,wBAAyB,CAAA;YAAM,CAAA;WACnH,CAAA,CAEP;;SACF;;OACF,CAAA;MACD;;IAGP;;EACF;;AAET"}
|
package/dist/index85.cjs
CHANGED
|
@@ -166,7 +166,7 @@ function renderPart(part, index, components, onToolApproval, pendingApprovalId)
|
|
|
166
166
|
});
|
|
167
167
|
}
|
|
168
168
|
var DEFAULT_MESSAGE_LIMIT = 8;
|
|
169
|
-
function AIChat({ api, scope, scopeLabel, fetch: requestFetch, headers, credentials, prepareSendMessagesRequest, sessionKey, messageLimit = DEFAULT_MESSAGE_LIMIT, inputPlaceholder = "Ask a question...", inputAriaLabel = "Message", inputMaxLength = 2e3, components, toolbarActions, attachments, history, sendAutomaticallyWhen, onClose, className, style }) {
|
|
169
|
+
function AIChat({ api, scope, scopeLabel, fetch: requestFetch, headers, credentials, prepareSendMessagesRequest, sessionKey, messageLimit = DEFAULT_MESSAGE_LIMIT, inputPlaceholder = "Ask a question...", inputAriaLabel = "Message", inputMaxLength = 2e3, components, toolbarActions, showNewChatInToolbar = true, newChatRequestKey, attachments, history, sendAutomaticallyWhen, onClose, className, style }) {
|
|
170
170
|
const [session, setSession] = (0, react.useState)(0);
|
|
171
171
|
const transport = (0, react.useMemo)(() => new _assistant_ui_ai_sdk.AssistantChatTransport({
|
|
172
172
|
api,
|
|
@@ -220,6 +220,8 @@ function AIChat({ api, scope, scopeLabel, fetch: requestFetch, headers, credenti
|
|
|
220
220
|
inputMaxLength,
|
|
221
221
|
components,
|
|
222
222
|
toolbarActions,
|
|
223
|
+
showNewChatInToolbar,
|
|
224
|
+
newChatRequestKey,
|
|
223
225
|
attachmentOptions: attachments,
|
|
224
226
|
history,
|
|
225
227
|
onNewChat: () => setSession((previous) => previous + 1)
|
|
@@ -234,7 +236,7 @@ function AIChat({ api, scope, scopeLabel, fetch: requestFetch, headers, credenti
|
|
|
234
236
|
]
|
|
235
237
|
});
|
|
236
238
|
}
|
|
237
|
-
function ChatViewport({ messageLimit, inputPlaceholder, inputAriaLabel, inputMaxLength, components, toolbarActions, attachmentOptions, history, onNewChat }) {
|
|
239
|
+
function ChatViewport({ messageLimit, inputPlaceholder, inputAriaLabel, inputMaxLength, components, toolbarActions, showNewChatInToolbar, newChatRequestKey, attachmentOptions, history, onNewChat }) {
|
|
238
240
|
const chat = (0, _assistant_ui_ai_sdk.useAISDKChat)();
|
|
239
241
|
const [draft, setDraft] = (0, react.useState)("");
|
|
240
242
|
const [selectedFiles, setSelectedFiles] = (0, react.useState)([]);
|
|
@@ -351,6 +353,12 @@ function ChatViewport({ messageLimit, inputPlaceholder, inputAriaLabel, inputMax
|
|
|
351
353
|
onNewChat();
|
|
352
354
|
})();
|
|
353
355
|
};
|
|
356
|
+
const lastNewChatRequestKey = (0, react.useRef)(newChatRequestKey);
|
|
357
|
+
(0, react.useEffect)(() => {
|
|
358
|
+
if (lastNewChatRequestKey.current === newChatRequestKey) return;
|
|
359
|
+
lastNewChatRequestKey.current = newChatRequestKey;
|
|
360
|
+
handleNewChat();
|
|
361
|
+
}, [newChatRequestKey]);
|
|
354
362
|
const handleRetry = () => {
|
|
355
363
|
if (!chat || isBusy) return;
|
|
356
364
|
chat.clearError();
|
|
@@ -373,6 +381,7 @@ function ChatViewport({ messageLimit, inputPlaceholder, inputAriaLabel, inputMax
|
|
|
373
381
|
},
|
|
374
382
|
onRetry: handleRetry,
|
|
375
383
|
onNewChat: handleNewChat,
|
|
384
|
+
showNewChatInToolbar,
|
|
376
385
|
toolbarActions,
|
|
377
386
|
messageLimit,
|
|
378
387
|
attachments: selectedFiles.map((file, index) => ({
|
|
@@ -408,7 +417,7 @@ function ChatViewport({ messageLimit, inputPlaceholder, inputAriaLabel, inputMax
|
|
|
408
417
|
* runtime. It does not create providers, transports or chat state. Callbacks
|
|
409
418
|
* are the only way messages/actions leave the view.
|
|
410
419
|
*/
|
|
411
|
-
function AIChatView({ messages, status = "ready", error, draft = "", onDraftChange, onSend, onStop, onRetry, onNewChat, messageLimit, inputPlaceholder = "Ask a question...", inputAriaLabel = "Message", inputMaxLength = 2e3, components, attachments, onSelectAttachments, onRemoveAttachment, attachmentAccept, attachmentError, onToolApproval, toolbarActions, header, composerLeading, composerTrailing, composer, emptyState, className, style }) {
|
|
420
|
+
function AIChatView({ messages, status = "ready", error, draft = "", onDraftChange, onSend, onStop, onRetry, onNewChat, showNewChatInToolbar = true, messageLimit, inputPlaceholder = "Ask a question...", inputAriaLabel = "Message", inputMaxLength = 2e3, components, attachments, onSelectAttachments, onRemoveAttachment, attachmentAccept, attachmentError, onToolApproval, toolbarActions, header, composerLeading, composerTrailing, composer, emptyState, className, style }) {
|
|
412
421
|
const viewportRef = (0, react.useRef)(null);
|
|
413
422
|
const pinnedToBottom = (0, react.useRef)(true);
|
|
414
423
|
const fileInputRef = (0, react.useRef)(null);
|
|
@@ -453,14 +462,14 @@ function AIChatView({ messages, status = "ready", error, draft = "", onDraftChan
|
|
|
453
462
|
style,
|
|
454
463
|
children: [
|
|
455
464
|
header,
|
|
456
|
-
(
|
|
465
|
+
(toolbarActions || showNewChatInToolbar && onNewChat && messages.length > 0) && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
457
466
|
className: require_ai_chat_module.default.chatToolbar,
|
|
458
467
|
role: "toolbar",
|
|
459
468
|
"aria-label": "Conversation actions",
|
|
460
469
|
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
461
470
|
className: require_ai_chat_module.default.chatToolbarExtras,
|
|
462
471
|
children: toolbarActions
|
|
463
|
-
}), onNewChat && messages.length > 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
472
|
+
}), showNewChatInToolbar && onNewChat && messages.length > 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
464
473
|
type: "button",
|
|
465
474
|
className: require_ai_chat_module.default.newChatButton,
|
|
466
475
|
onClick: onNewChat,
|