@nexface/chat 0.1.9 → 0.1.10

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.
@@ -5,10 +5,11 @@ export declare function AttachmentTile({ binding, savedPreview }: {
5
5
  binding?: AssistantBinding;
6
6
  savedPreview?: string | undefined;
7
7
  }): import("react").JSX.Element;
8
- export declare function AssistantComposer({ binding, options, placeholder, busy, cancelling, cancel }: {
8
+ export declare function AssistantComposer({ binding, options, placeholder, suggestion, busy, cancelling, cancel }: {
9
9
  binding: AssistantBinding;
10
10
  options: ChatProps["attachments"];
11
11
  placeholder: string;
12
+ suggestion?: string | undefined;
12
13
  busy: boolean;
13
14
  cancelling: boolean;
14
15
  cancel(): void;
@@ -16,21 +16,29 @@ export function AttachmentTile({ binding, savedPreview }) {
16
16
  const preview = binding?.attachments.preview(attachment.id) ?? savedPreview ?? attachment.content?.find((part) => part.type === "image")?.image;
17
17
  return _jsx(AttachmentUI, { preview: preview, children: _jsxs("div", { className: cn("flex max-w-40 flex-col text-xs wrap-anywhere"), children: [_jsx(AttachmentPrimitive.Name, {}), binding && attachment.status.type === "requires-action" ? _jsx("small", { className: cn("text-muted-foreground"), children: "\u5DF2\u5C31\u7EEA" }) : null, attachment.status.type === "running" ? _jsx("small", { className: cn("text-muted-foreground"), children: "\u6B63\u5728\u5904\u7406\u2026" }) : null, attachment.status.type === "incomplete" ? _jsx("small", { className: cn("text-destructive"), role: "alert", children: attachment.status.message ?? "附件处理失败" }) : null] }) });
18
18
  }
19
- export function AssistantComposer({ binding, options, placeholder, busy, cancelling, cancel }) {
19
+ export function AssistantComposer({ binding, options, placeholder, suggestion, busy, cancelling, cancel }) {
20
20
  const input = useRef(null);
21
21
  const sending = binding.sending;
22
+ const empty = useAuiState((state) => state.composer.text.length === 0);
23
+ const nextMessage = !busy && !sending && empty ? suggestion : undefined;
22
24
  const showCancel = useAuiState((state) => busy && (state.thread.isRunning || state.composer.isEmpty));
23
25
  const addFiles = (files) => {
24
26
  for (const file of files)
25
27
  void binding.runtime.thread.composer.addAttachment(file).catch((error) => binding.setNotice(error instanceof Error ? error.message : String(error)));
26
28
  };
27
- return _jsxs(Composer, { onSubmit: (event) => { event.preventDefault(); void binding.send(); }, inputProps: { "aria-label": "输入 Agent 任务", placeholder, disabled: sending, cancelOnEscape: false,
28
- onKeyDown: (event) => { if (event.keyCode === 229)
29
- event.preventDefault();
30
- else if (event.key === "Enter" && !event.shiftKey && !event.nativeEvent.isComposing) {
31
- event.preventDefault();
32
- void binding.send();
33
- } } }, actions: _jsxs(_Fragment, { children: [options !== false ? _jsxs(_Fragment, { children: [_jsx("input", { ref: input, type: "file", multiple: true, disabled: sending, accept: options?.accept ?? attachmentAccept, hidden: true, onChange: (event) => { addFiles(Array.from(event.target.files ?? [])); event.target.value = ""; } }), _jsx("button", { type: "button", className: cn("text-muted-foreground hover:text-foreground rounded-control grid size-7 shrink-0 place-items-center transition-colors"), "aria-label": "\u6DFB\u52A0\u9644\u4EF6", disabled: sending, onClick: () => input.current?.click(), children: _jsx(PlusIcon, { className: cn("size-4") }) })] }) : _jsx("span", {}), _jsx("div", { className: cn("flex shrink-0 items-center gap-1"), children: showCancel ? _jsx("button", { type: "button", "aria-label": "\u53D6\u6D88\u4EFB\u52A1", className: cn("bg-primary text-primary-foreground rounded-control grid size-7 place-items-center"), disabled: cancelling, onClick: cancel, children: _jsx(SquareIcon, { className: cn("size-3 fill-current") }) }) :
29
+ return _jsxs(Composer, { onSubmit: (event) => { event.preventDefault(); void binding.send(); }, inputProps: { "aria-label": "输入 Agent 任务", placeholder: nextMessage ?? placeholder, disabled: sending, cancelOnEscape: false,
30
+ onKeyDown: (event) => {
31
+ if (event.keyCode === 229)
32
+ event.preventDefault();
33
+ else if ((event.key === "ArrowRight" || event.key === "Tab") && nextMessage && !event.nativeEvent.isComposing && !event.shiftKey && !event.ctrlKey && !event.altKey && !event.metaKey && !event.currentTarget.value) {
34
+ event.preventDefault();
35
+ binding.runtime.thread.composer.setText(nextMessage);
36
+ }
37
+ else if (event.key === "Enter" && !event.shiftKey && !event.nativeEvent.isComposing) {
38
+ event.preventDefault();
39
+ void binding.send();
40
+ }
41
+ } }, actions: _jsxs(_Fragment, { children: [options !== false ? _jsxs(_Fragment, { children: [_jsx("input", { ref: input, type: "file", multiple: true, disabled: sending, accept: options?.accept ?? attachmentAccept, hidden: true, onChange: (event) => { addFiles(Array.from(event.target.files ?? [])); event.target.value = ""; } }), _jsx("button", { type: "button", className: cn("text-muted-foreground hover:text-foreground rounded-control grid size-7 shrink-0 place-items-center transition-colors"), "aria-label": "\u6DFB\u52A0\u9644\u4EF6", disabled: sending, onClick: () => input.current?.click(), children: _jsx(PlusIcon, { className: cn("size-4") }) })] }) : _jsx("span", {}), _jsx("div", { className: cn("flex shrink-0 items-center gap-1"), children: showCancel ? _jsx("button", { type: "button", "aria-label": "\u53D6\u6D88\u4EFB\u52A1", className: cn("bg-primary text-primary-foreground rounded-control grid size-7 place-items-center"), disabled: cancelling, onClick: cancel, children: _jsx(SquareIcon, { className: cn("size-3 fill-current") }) }) :
34
42
  _jsx(ComposerPrimitive.Send, { asChild: true, disabled: sending, children: _jsx("button", { type: "button", onClick: (event) => { event.preventDefault(); void binding.send(); }, "aria-label": "\u53D1\u9001\u4EFB\u52A1", className: cn("bg-primary text-primary-foreground rounded-control grid size-7 place-items-center transition-opacity disabled:opacity-40"), children: _jsx(ArrowUpIcon, { className: cn("size-4") }) }) }) })] }), children: [_jsx("div", { className: cn("aui-composer-attachments flex w-full flex-row items-center gap-2 overflow-x-auto empty:hidden"), children: _jsx(ComposerPrimitive.Attachments, { children: () => _jsx(AttachmentTile, { binding: binding }) }) }), sending ? _jsx("small", { role: "status", children: "\u6B63\u5728\u5904\u7406\u9644\u4EF6\u2026" }) : null] });
35
43
  }
36
44
  function ToolGroup({ tools, running, count, children }) {
@@ -1 +1 @@
1
- {"version":3,"file":"assistant-components.js","sourceRoot":"","sources":["../src/assistant-components.tsx"],"names":[],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E,CAAC,IAAI,CAAC,IAAI,KAAK,MAAM,IAAI,IAAI,CAAC,UAAU,KAAK,IAAI,CAAC,UAAU,CAAC,GAAI,CAAC;oBAC1L,KAAK,WAAW,CAAC,CAAC,OAAO,KAAC,SAAS,IAAC,IAAI,QAAC,KAAK,EAAC,UAAU,GAAG,CAAC;oBAC7D,OAAO,CAAC,CAAC,OAAO,IAAI,CAAC;gBACvB,CAAC;YACH,CAAC,GAAgB,GAAG,CAAC;AACvB,CAAC","sourcesContent":["import type { UIMessagePart } from \"./messages.js\";\nimport { AttachmentUI } from \"./ui/attachment.aui.js\";\nimport { useEffect, useRef, useState, type ReactNode, type ComponentType } from \"react\";\nimport { MarkdownText } from \"./ui/markdown-text.js\";\nimport { Composer } from \"./ui/home-demo/composer.js\";\nimport { cn } from \"./ui/utils.js\";\nimport { AttachmentPrimitive, ComposerPrimitive, useAuiState, MessagePrimitive, groupPartByType } from \"@assistant-ui/react\";\nimport { ArrowUpIcon, PlusIcon, SquareIcon } from \"lucide-react\";\nimport { ToolGroupRoot, ToolGroupContent } from \"./ui/tool-group.aui.js\";\nimport { DisclosureTrigger, ToolCall, disclosureContentClass } from \"./ui/home-demo/trace.js\";\nimport { Reasoning, ReasoningRoot, ReasoningContent, ReasoningText } from \"./ui/reasoning.aui.js\";\nimport { TraceLine } from \"./ui/home-demo/trace-line.js\";\nimport type { AssistantBinding } from \"./assistant-runtime.js\";\nimport { attachmentAccept } from \"./attachments.js\";\nimport type { ChatProps } from \"./types.js\";\n\nexport function AttachmentTile({ binding, savedPreview }: { binding?: AssistantBinding; savedPreview?: string | undefined }) {\n const attachment = useAuiState((s) => s.attachment);\n const preview = binding?.attachments.preview(attachment.id) ?? savedPreview ?? attachment.content?.find((part) => part.type === \"image\")?.image;\n return <AttachmentUI preview={preview}>\n <div className={cn(\"flex max-w-40 flex-col text-xs wrap-anywhere\")}><AttachmentPrimitive.Name />\n {binding && attachment.status.type === \"requires-action\" ? <small className={cn(\"text-muted-foreground\")}>已就绪</small> : null}\n {attachment.status.type === \"running\" ? <small className={cn(\"text-muted-foreground\")}>正在处理…</small> : null}\n {attachment.status.type === \"incomplete\" ? <small className={cn(\"text-destructive\")} role=\"alert\">{attachment.status.message ?? \"附件处理失败\"}</small> : null}\n </div>\n </AttachmentUI>;\n}\n\nexport function AssistantComposer({ binding, options, placeholder, busy, cancelling, cancel }: {\n binding: AssistantBinding; options: ChatProps[\"attachments\"]; placeholder: string;\n busy: boolean; cancelling: boolean; cancel(): void;\n}) {\n const input = useRef<HTMLInputElement>(null);\n const sending = binding.sending;\n const showCancel = useAuiState((state) => busy && (state.thread.isRunning || state.composer.isEmpty));\n const addFiles = (files: File[]) => {\n for (const file of files) void binding.runtime.thread.composer.addAttachment(file).catch((error: unknown) => binding.setNotice(error instanceof Error ? error.message : String(error)));\n };\n return <Composer onSubmit={(event) => { event.preventDefault(); void binding.send(); }}\n inputProps={{ \"aria-label\": \"输入 Agent 任务\", placeholder, disabled: sending, cancelOnEscape: false,\n onKeyDown: (event) => { if (event.keyCode === 229) event.preventDefault(); else if (event.key === \"Enter\" && !event.shiftKey && !event.nativeEvent.isComposing) { event.preventDefault(); void binding.send(); } } }}\n actions={<>\n {options !== false ? <><input ref={input} type=\"file\" multiple disabled={sending} accept={options?.accept ?? attachmentAccept} hidden\n onChange={(event) => { addFiles(Array.from(event.target.files ?? [])); event.target.value = \"\"; }} />\n <button type=\"button\" className={cn(\"text-muted-foreground hover:text-foreground rounded-control grid size-7 shrink-0 place-items-center transition-colors\")} aria-label=\"添加附件\" disabled={sending} onClick={() => input.current?.click()}><PlusIcon className={cn(\"size-4\")} /></button></> : <span />}\n <div className={cn(\"flex shrink-0 items-center gap-1\")}>\n {showCancel ? <button type=\"button\" aria-label=\"取消任务\" className={cn(\"bg-primary text-primary-foreground rounded-control grid size-7 place-items-center\")} disabled={cancelling} onClick={cancel}><SquareIcon className={cn(\"size-3 fill-current\")} /></button> :\n <ComposerPrimitive.Send asChild disabled={sending}><button type=\"button\" onClick={(event) => { event.preventDefault(); void binding.send(); }} aria-label=\"发送任务\" className={cn(\"bg-primary text-primary-foreground rounded-control grid size-7 place-items-center transition-opacity disabled:opacity-40\")}><ArrowUpIcon className={cn(\"size-4\")} /></button></ComposerPrimitive.Send>}\n </div>\n </>}>\n <div className={cn(\"aui-composer-attachments flex w-full flex-row items-center gap-2 overflow-x-auto empty:hidden\")}><ComposerPrimitive.Attachments>{() => <AttachmentTile binding={binding} />}</ComposerPrimitive.Attachments></div>\n {sending ? <small role=\"status\">正在处理附件…</small> : null}\n </Composer>;\n}\n\nfunction ToolGroup({ tools, running, count, children }: {\n tools: readonly UIMessagePart[]; running: boolean; count: number; children: ReactNode;\n}) {\n const errors = tools.flatMap((tool) => tool.type === \"tool\" && tool.error ? [tool.error] : []);\n const errorIds = JSON.stringify(errors.map((error) => error.id));\n const hasErrors = errors.length > 0;\n const [open, setOpen] = useState(hasErrors);\n useEffect(() => {\n if (errorIds !== \"[]\") setOpen(true);\n }, [errorIds]);\n const unknown = hasErrors && errors.every((error) => error.scope === \"tool\" && error.execution === \"unknown\");\n return <ToolGroupRoot variant=\"ghost\" className={cn(\"my-1\")} open={open} onOpenChange={setOpen}>\n <DisclosureTrigger live={running && !hasErrors} label={hasErrors ? unknown ? \"Result unknown\" : \"Failed\" : running ? \"running\" : \"ran\"} detail={`${count} tools`} />\n <ToolGroupContent className={cn(disclosureContentClass)}>{children}</ToolGroupContent>\n </ToolGroupRoot>;\n}\n\nconst GroupedParts = MessagePrimitive.GroupedParts as ComponentType<Parameters<typeof MessagePrimitive.GroupedParts>[0]>;\nconst groupAssistantParts = groupPartByType({ reasoning: [\"group-chainOfThought\", \"group-reasoning\"], source: [\"group-chainOfThought\", \"group-source\"], \"tool-call\": [\"group-chainOfThought\", \"group-tool\"], \"standalone-tool-call\": [] });\nexport function AssistantParts({ showDetails, tools = [] }: { showDetails: boolean; tools?: readonly UIMessagePart[] }) {\n return <><GroupedParts groupBy={groupAssistantParts}>{({ part, children }) => {\n switch (part.type) {\n case \"group-chainOfThought\": return <div className={cn(\"mb-3\")}>{children}</div>;\n case \"group-tool\": return part.indices.length === 1 ? <>{children}</> : <ToolGroup\n tools={tools.filter((_, index) => part.indices.includes(index))} running={part.status.type === \"running\"} count={part.indices.length}>\n {children}\n </ToolGroup>;\n case \"group-reasoning\": return <ReasoningRoot variant=\"ghost\" streaming={part.status.type === \"running\"} className={cn(\"my-1 mb-3\")}>\n <DisclosureTrigger live={part.status.type === \"running\"} label={part.status.type === \"running\" ? \"thinking\" : \"reasoning\"} />\n <ReasoningContent aria-busy={part.status.type === \"running\"} className={cn(disclosureContentClass)}><ReasoningText className={cn(\"ps-0\")}>{children}</ReasoningText></ReasoningContent>\n </ReasoningRoot>;\n case \"reasoning\": return <Reasoning {...part} />;\n case \"group-source\":\n case \"source\": return null;\n case \"data\": return part.dataRendererUI;\n case \"text\": return part.text === \"\" && part.status?.type === \"running\" ? <TraceLine live label=\"thinking\" /> : <MarkdownText />;\n case \"tool-call\": return part.toolUI ?? <ToolCall {...part} showDetails={showDetails} presentation={tools.find((tool) => tool.type === \"tool\" && tool.toolCallId === part.toolCallId)} />;\n case \"indicator\": return <TraceLine live label=\"thinking\" />;\n default: return null;\n }\n }}</GroupedParts></>;\n}\n"]}
1
+ {"version":3,"file":"assistant-components.js","sourceRoot":"","sources":["../src/assistant-components.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAsC,MAAM,OAAO,CAAC;AACxF,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AACtD,OAAO,EAAE,EAAE,EAAE,MAAM,eAAe,CAAC;AACnC,OAAO,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,WAAW,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,qBAAqB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O,IAAI,CAAC,IAAI,KAAK,EAAE,IAAI,IAAI,CAAC,MAAM,EAAE,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,KAAC,SAAS,IAAC,IAAI,QAAC,KAAK,EAAC,UAAU,GAAG,CAAC,CAAC,CAAC,KAAC,YAAY,KAAG,CAAC;oBACjI,KAAK,WAAW,CAAC,CAAC,OAAO,IAAI,CAAC,MAAM,IAAI,KAAC,QAAQ,OAAK,IAAI,EAAE,WAAW,EAAE,WAAW,EAAE,YAAY,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,MAAM,IAAI,IAAI,CAAC,UAAU,KAAK,IAAI,CAAC,UAAU,CAAC,GAAI,CAAC;oBAC1L,KAAK,WAAW,CAAC,CAAC,OAAO,KAAC,SAAS,IAAC,IAAI,QAAC,KAAK,EAAC,UAAU,GAAG,CAAC;oBAC7D,OAAO,CAAC,CAAC,OAAO,IAAI,CAAC;gBACvB,CAAC;YACH,CAAC,GAAgB,GAAG,CAAC;AACvB,CAAC","sourcesContent":["import type { UIMessagePart } from \"./messages.js\";\nimport { AttachmentUI } from \"./ui/attachment.aui.js\";\nimport { useEffect, useRef, useState, type ReactNode, type ComponentType } from \"react\";\nimport { MarkdownText } from \"./ui/markdown-text.js\";\nimport { Composer } from \"./ui/home-demo/composer.js\";\nimport { cn } from \"./ui/utils.js\";\nimport { AttachmentPrimitive, ComposerPrimitive, useAuiState, MessagePrimitive, groupPartByType } from \"@assistant-ui/react\";\nimport { ArrowUpIcon, PlusIcon, SquareIcon } from \"lucide-react\";\nimport { ToolGroupRoot, ToolGroupContent } from \"./ui/tool-group.aui.js\";\nimport { DisclosureTrigger, ToolCall, disclosureContentClass } from \"./ui/home-demo/trace.js\";\nimport { Reasoning, ReasoningRoot, ReasoningContent, ReasoningText } from \"./ui/reasoning.aui.js\";\nimport { TraceLine } from \"./ui/home-demo/trace-line.js\";\nimport type { AssistantBinding } from \"./assistant-runtime.js\";\nimport { attachmentAccept } from \"./attachments.js\";\nimport type { ChatProps } from \"./types.js\";\n\nexport function AttachmentTile({ binding, savedPreview }: { binding?: AssistantBinding; savedPreview?: string | undefined }) {\n const attachment = useAuiState((s) => s.attachment);\n const preview = binding?.attachments.preview(attachment.id) ?? savedPreview ?? attachment.content?.find((part) => part.type === \"image\")?.image;\n return <AttachmentUI preview={preview}>\n <div className={cn(\"flex max-w-40 flex-col text-xs wrap-anywhere\")}><AttachmentPrimitive.Name />\n {binding && attachment.status.type === \"requires-action\" ? <small className={cn(\"text-muted-foreground\")}>已就绪</small> : null}\n {attachment.status.type === \"running\" ? <small className={cn(\"text-muted-foreground\")}>正在处理…</small> : null}\n {attachment.status.type === \"incomplete\" ? <small className={cn(\"text-destructive\")} role=\"alert\">{attachment.status.message ?? \"附件处理失败\"}</small> : null}\n </div>\n </AttachmentUI>;\n}\n\nexport function AssistantComposer({ binding, options, placeholder, suggestion, busy, cancelling, cancel }: {\n binding: AssistantBinding; options: ChatProps[\"attachments\"]; placeholder: string;\n suggestion?: string | undefined;\n busy: boolean; cancelling: boolean; cancel(): void;\n}) {\n const input = useRef<HTMLInputElement>(null);\n const sending = binding.sending;\n const empty = useAuiState((state) => state.composer.text.length === 0);\n const nextMessage = !busy && !sending && empty ? suggestion : undefined;\n const showCancel = useAuiState((state) => busy && (state.thread.isRunning || state.composer.isEmpty));\n const addFiles = (files: File[]) => {\n for (const file of files) void binding.runtime.thread.composer.addAttachment(file).catch((error: unknown) => binding.setNotice(error instanceof Error ? error.message : String(error)));\n };\n return <Composer onSubmit={(event) => { event.preventDefault(); void binding.send(); }}\n inputProps={{ \"aria-label\": \"输入 Agent 任务\", placeholder: nextMessage ?? placeholder, disabled: sending, cancelOnEscape: false,\n onKeyDown: (event) => {\n if (event.keyCode === 229) event.preventDefault();\n else if ((event.key === \"ArrowRight\" || event.key === \"Tab\") && nextMessage && !event.nativeEvent.isComposing && !event.shiftKey && !event.ctrlKey && !event.altKey && !event.metaKey && !event.currentTarget.value) {\n event.preventDefault();\n binding.runtime.thread.composer.setText(nextMessage);\n } else if (event.key === \"Enter\" && !event.shiftKey && !event.nativeEvent.isComposing) { event.preventDefault(); void binding.send(); }\n } }}\n actions={<>\n {options !== false ? <><input ref={input} type=\"file\" multiple disabled={sending} accept={options?.accept ?? attachmentAccept} hidden\n onChange={(event) => { addFiles(Array.from(event.target.files ?? [])); event.target.value = \"\"; }} />\n <button type=\"button\" className={cn(\"text-muted-foreground hover:text-foreground rounded-control grid size-7 shrink-0 place-items-center transition-colors\")} aria-label=\"添加附件\" disabled={sending} onClick={() => input.current?.click()}><PlusIcon className={cn(\"size-4\")} /></button></> : <span />}\n <div className={cn(\"flex shrink-0 items-center gap-1\")}>\n {showCancel ? <button type=\"button\" aria-label=\"取消任务\" className={cn(\"bg-primary text-primary-foreground rounded-control grid size-7 place-items-center\")} disabled={cancelling} onClick={cancel}><SquareIcon className={cn(\"size-3 fill-current\")} /></button> :\n <ComposerPrimitive.Send asChild disabled={sending}><button type=\"button\" onClick={(event) => { event.preventDefault(); void binding.send(); }} aria-label=\"发送任务\" className={cn(\"bg-primary text-primary-foreground rounded-control grid size-7 place-items-center transition-opacity disabled:opacity-40\")}><ArrowUpIcon className={cn(\"size-4\")} /></button></ComposerPrimitive.Send>}\n </div>\n </>}>\n <div className={cn(\"aui-composer-attachments flex w-full flex-row items-center gap-2 overflow-x-auto empty:hidden\")}><ComposerPrimitive.Attachments>{() => <AttachmentTile binding={binding} />}</ComposerPrimitive.Attachments></div>\n {sending ? <small role=\"status\">正在处理附件…</small> : null}\n </Composer>;\n}\n\nfunction ToolGroup({ tools, running, count, children }: {\n tools: readonly UIMessagePart[]; running: boolean; count: number; children: ReactNode;\n}) {\n const errors = tools.flatMap((tool) => tool.type === \"tool\" && tool.error ? [tool.error] : []);\n const errorIds = JSON.stringify(errors.map((error) => error.id));\n const hasErrors = errors.length > 0;\n const [open, setOpen] = useState(hasErrors);\n useEffect(() => {\n if (errorIds !== \"[]\") setOpen(true);\n }, [errorIds]);\n const unknown = hasErrors && errors.every((error) => error.scope === \"tool\" && error.execution === \"unknown\");\n return <ToolGroupRoot variant=\"ghost\" className={cn(\"my-1\")} open={open} onOpenChange={setOpen}>\n <DisclosureTrigger live={running && !hasErrors} label={hasErrors ? unknown ? \"Result unknown\" : \"Failed\" : running ? \"running\" : \"ran\"} detail={`${count} tools`} />\n <ToolGroupContent className={cn(disclosureContentClass)}>{children}</ToolGroupContent>\n </ToolGroupRoot>;\n}\n\nconst GroupedParts = MessagePrimitive.GroupedParts as ComponentType<Parameters<typeof MessagePrimitive.GroupedParts>[0]>;\nconst groupAssistantParts = groupPartByType({ reasoning: [\"group-chainOfThought\", \"group-reasoning\"], source: [\"group-chainOfThought\", \"group-source\"], \"tool-call\": [\"group-chainOfThought\", \"group-tool\"], \"standalone-tool-call\": [] });\nexport function AssistantParts({ showDetails, tools = [] }: { showDetails: boolean; tools?: readonly UIMessagePart[] }) {\n return <><GroupedParts groupBy={groupAssistantParts}>{({ part, children }) => {\n switch (part.type) {\n case \"group-chainOfThought\": return <div className={cn(\"mb-3\")}>{children}</div>;\n case \"group-tool\": return part.indices.length === 1 ? <>{children}</> : <ToolGroup\n tools={tools.filter((_, index) => part.indices.includes(index))} running={part.status.type === \"running\"} count={part.indices.length}>\n {children}\n </ToolGroup>;\n case \"group-reasoning\": return <ReasoningRoot variant=\"ghost\" streaming={part.status.type === \"running\"} className={cn(\"my-1 mb-3\")}>\n <DisclosureTrigger live={part.status.type === \"running\"} label={part.status.type === \"running\" ? \"thinking\" : \"reasoning\"} />\n <ReasoningContent aria-busy={part.status.type === \"running\"} className={cn(disclosureContentClass)}><ReasoningText className={cn(\"ps-0\")}>{children}</ReasoningText></ReasoningContent>\n </ReasoningRoot>;\n case \"reasoning\": return <Reasoning {...part} />;\n case \"group-source\":\n case \"source\": return null;\n case \"data\": return part.dataRendererUI;\n case \"text\": return part.text === \"\" && part.status?.type === \"running\" ? <TraceLine live label=\"thinking\" /> : <MarkdownText />;\n case \"tool-call\": return part.toolUI ?? <ToolCall {...part} showDetails={showDetails} presentation={tools.find((tool) => tool.type === \"tool\" && tool.toolCallId === part.toolCallId)} />;\n case \"indicator\": return <TraceLine live label=\"thinking\" />;\n default: return null;\n }\n }}</GroupedParts></>;\n}\n"]}
@@ -1,3 +1,3 @@
1
1
  import { type JSX } from "react";
2
2
  import type { ChatProps } from "./types.js";
3
- export declare function Chat({ title, avatar, welcomeMessage, welcomeDescription, open, onOpenChange, placeholder, layout, side, className, style, suggestions, attachments, sessionSidebar, showToolDetails, onFullscreenChange, onRunResult }: ChatProps): JSX.Element | null;
3
+ export declare function Chat({ title, avatar, welcomeMessage, welcomeDescription, open, onOpenChange, placeholder, layout, side, className, style, suggestions, suggestNextMessage, attachments, sessionSidebar, showToolDetails, onFullscreenChange, onRunResult }: ChatProps): JSX.Element | null;
@@ -28949,6 +28949,54 @@ function Suggestions2({ suggestions, disabled, onSend }) {
28949
28949
  );
28950
28950
  }
28951
28951
 
28952
+ // src/use-next-message.ts
28953
+ import { useEffect as useEffect25, useLayoutEffect as useLayoutEffect10, useRef as useRef28, useState as useState26 } from "react";
28954
+ function suggestionMessages(messages) {
28955
+ const result = [];
28956
+ for (const message of messages) {
28957
+ const parts = message.parts.flatMap((part) => part.type === "text" && part.text.trim() ? [{ type: "text", text: part.text }] : []);
28958
+ if (message.role === "assistant" && !parts.length) continue;
28959
+ const previous3 = result.at(-1);
28960
+ if (message.role === "assistant" && previous3?.role === "assistant") {
28961
+ previous3.parts = [...previous3.parts, ...parts];
28962
+ } else {
28963
+ result.push({ role: message.role, parts });
28964
+ }
28965
+ }
28966
+ return result;
28967
+ }
28968
+ function useNextMessage(chat, suggest, open) {
28969
+ const latest = useRef28({ suggest, messages: chat.messages });
28970
+ useLayoutEffect10(() => {
28971
+ latest.current = { suggest, messages: chat.messages };
28972
+ });
28973
+ const [suggestion, setSuggestion] = useState26();
28974
+ const enabled = Boolean(suggest);
28975
+ const completionKey = chat.completed ? `${chat.activeSessionId}:${chat.completed.id}` : void 0;
28976
+ const key = enabled && chat.status === "idle" && chat.messages.length ? completionKey : void 0;
28977
+ useEffect25(() => {
28978
+ if (!key) {
28979
+ setSuggestion(void 0);
28980
+ return;
28981
+ }
28982
+ if (!open || suggestion?.key === key) return;
28983
+ const controller = new AbortController();
28984
+ void Promise.resolve().then(async () => {
28985
+ if (controller.signal.aborted) return;
28986
+ const text7 = await latest.current.suggest?.({
28987
+ sessionId: chat.activeSessionId,
28988
+ messages: suggestionMessages(latest.current.messages),
28989
+ signal: controller.signal
28990
+ });
28991
+ if (!controller.signal.aborted) setSuggestion({ key, text: text7?.trim() || void 0 });
28992
+ }).catch(() => {
28993
+ if (!controller.signal.aborted) setSuggestion({ key, text: void 0 });
28994
+ });
28995
+ return () => controller.abort();
28996
+ }, [key, completionKey, open, suggestion?.key]);
28997
+ return suggestion?.key === key ? suggestion?.text : void 0;
28998
+ }
28999
+
28952
29000
  // src/ui/home-demo/action-bar.tsx
28953
29001
  import { jsx as jsx72, jsxs as jsxs14 } from "react/jsx-runtime";
28954
29002
  function AssistantActionBar() {
@@ -29138,10 +29186,10 @@ function AvatarFallback3({ className, ...props }) {
29138
29186
  }
29139
29187
 
29140
29188
  // src/default-chat.tsx
29141
- import { forwardRef as forwardRef33, useEffect as useEffect32, useLayoutEffect as useLayoutEffect12, useMemo as useMemo12, useRef as useRef37, useState as useState36 } from "react";
29189
+ import { forwardRef as forwardRef33, useEffect as useEffect33, useLayoutEffect as useLayoutEffect13, useMemo as useMemo12, useRef as useRef38, useState as useState37 } from "react";
29142
29190
 
29143
29191
  // src/assistant-runtime.tsx
29144
- import { useEffect as useEffect25, useLayoutEffect as useLayoutEffect10, useReducer as useReducer5, useRef as useRef28, useState as useState26 } from "react";
29192
+ import { useEffect as useEffect26, useLayoutEffect as useLayoutEffect11, useReducer as useReducer5, useRef as useRef29, useState as useState27 } from "react";
29145
29193
 
29146
29194
  // src/assistant-attachments.ts
29147
29195
  import { ImageInputContentSchema, TextInputContentSchema } from "@ag-ui/core";
@@ -29315,20 +29363,20 @@ function projectMessages(messages) {
29315
29363
  return projected;
29316
29364
  }
29317
29365
  function SessionRuntime({ id, chat, options: options2, blocked, active, onEdit, children }) {
29318
- const latest = useRef28(chat);
29319
- useLayoutEffect10(() => {
29366
+ const latest = useRef29(chat);
29367
+ useLayoutEffect11(() => {
29320
29368
  latest.current = chat;
29321
29369
  });
29322
- const messages = useRef28([]);
29370
+ const messages = useRef29([]);
29323
29371
  if (chat.activeSessionId === id) messages.current = chat.messages;
29324
29372
  const [, refresh] = useReducer5((n) => n + 1, 0);
29325
- const [notice, setNotice] = useState26("");
29326
- const [sending, setSending] = useState26(false);
29327
- const sendLock = useRef28(false);
29328
- const [attachments] = useState26(() => new AssistantAttachments(refresh, setNotice));
29373
+ const [notice, setNotice] = useState27("");
29374
+ const [sending, setSending] = useState27(false);
29375
+ const sendLock = useRef29(false);
29376
+ const [attachments] = useState27(() => new AssistantAttachments(refresh, setNotice));
29329
29377
  attachments.options = options2 ?? {};
29330
- const alive = useRef28(false);
29331
- useEffect25(() => {
29378
+ const alive = useRef29(false);
29379
+ useEffect26(() => {
29332
29380
  alive.current = true;
29333
29381
  return () => {
29334
29382
  alive.current = false;
@@ -29411,13 +29459,13 @@ function SessionRuntime({ id, chat, options: options2, blocked, active, onEdit,
29411
29459
  }
29412
29460
 
29413
29461
  // src/ui/attachment.aui.tsx
29414
- import { useState as useState28, isValidElement as isValidElement3, createContext as createContext6, useContext as useContext7 } from "react";
29462
+ import { useState as useState29, isValidElement as isValidElement3, createContext as createContext6, useContext as useContext7 } from "react";
29415
29463
 
29416
29464
  // src/ui/use-attachment-src.ts
29417
- import { useEffect as useEffect26, useState as useState27 } from "react";
29465
+ import { useEffect as useEffect27, useState as useState28 } from "react";
29418
29466
  var useFileSrc = (file) => {
29419
- const [entry, setEntry] = useState27(void 0);
29420
- useEffect26(() => {
29467
+ const [entry, setEntry] = useState28(void 0);
29468
+ useEffect27(() => {
29421
29469
  if (!file) {
29422
29470
  setEntry(void 0);
29423
29471
  return;
@@ -29444,7 +29492,7 @@ var usePreview = () => {
29444
29492
  return useContext7(PreviewContext) ?? fallback;
29445
29493
  };
29446
29494
  var AttachmentPreview = ({ src }) => {
29447
- const [isLoaded, setIsLoaded] = useState28(false);
29495
+ const [isLoaded, setIsLoaded] = useState29(false);
29448
29496
  return /* @__PURE__ */ jsx79("img", { src, alt: "\u9644\u4EF6\u9884\u89C8", className: cn("block h-auto max-h-[80vh] w-auto max-w-full rounded-sm object-contain transition-opacity duration-300 motion-reduce:transition-none", isLoaded ? "aui-attachment-preview-image-loaded opacity-100" : "aui-attachment-preview-image-loading opacity-0"), onLoad: () => setIsLoaded(true) });
29449
29497
  };
29450
29498
  var AttachmentPreviewDialog = ({ children }) => {
@@ -29520,7 +29568,7 @@ var AttachmentRemove = () => {
29520
29568
  };
29521
29569
 
29522
29570
  // src/assistant-components.tsx
29523
- import { useEffect as useEffect31, useRef as useRef36, useState as useState35 } from "react";
29571
+ import { useEffect as useEffect32, useRef as useRef37, useState as useState36 } from "react";
29524
29572
 
29525
29573
  // ../../node_modules/.pnpm/@assistant-ui+react-markdown@0.14.16_@assistant-ui+react@0.15.21_@opentelemetry+api@1.9_3f906f814c75b5f4b2a277bb379ed72b/node_modules/@assistant-ui/react-markdown/dist/memoization.js
29526
29574
  import { jsx as jsx80 } from "react/jsx-runtime";
@@ -44585,13 +44633,13 @@ function remarkGfm(options2) {
44585
44633
  }
44586
44634
 
44587
44635
  // src/ui/markdown-text.tsx
44588
- import { memo as memo6, useRef as useRef31 } from "react";
44636
+ import { memo as memo6, useRef as useRef32 } from "react";
44589
44637
 
44590
44638
  // src/ui/code-block.tsx
44591
44639
  import {
44592
- useEffect as useEffect28,
44593
- useRef as useRef30,
44594
- useState as useState30
44640
+ useEffect as useEffect29,
44641
+ useRef as useRef31,
44642
+ useState as useState31
44595
44643
  } from "react";
44596
44644
  import { jsx as jsx87, jsxs as jsxs23 } from "react/jsx-runtime";
44597
44645
  function CopyButton({
@@ -44599,12 +44647,12 @@ function CopyButton({
44599
44647
  onCopied,
44600
44648
  className
44601
44649
  }) {
44602
- const [copied, setCopied] = useState30(false);
44603
- const copyTimer = useRef30(
44650
+ const [copied, setCopied] = useState31(false);
44651
+ const copyTimer = useRef31(
44604
44652
  void 0
44605
44653
  );
44606
- const unmounted = useRef30(false);
44607
- useEffect28(() => {
44654
+ const unmounted = useRef31(false);
44655
+ useEffect29(() => {
44608
44656
  unmounted.current = false;
44609
44657
  return () => {
44610
44658
  unmounted.current = true;
@@ -44647,7 +44695,7 @@ function CodeBlock({
44647
44695
  children,
44648
44696
  ...props
44649
44697
  }) {
44650
- const viewportRef = useRef30(null);
44698
+ const viewportRef = useRef31(null);
44651
44699
  const getText = () => copyText ?? viewportRef.current?.querySelector("pre")?.textContent ?? "";
44652
44700
  return /* @__PURE__ */ jsxs23(
44653
44701
  "figure",
@@ -44698,9 +44746,9 @@ function CodeBlock({
44698
44746
  }
44699
44747
 
44700
44748
  // src/ui/use-copy-to-clipboard.ts
44701
- import { useState as useState31 } from "react";
44749
+ import { useState as useState32 } from "react";
44702
44750
  var useCopyToClipboard = ({ copiedDuration = 3e3 } = {}) => {
44703
- const [isCopied, setIsCopied] = useState31(false);
44751
+ const [isCopied, setIsCopied] = useState32(false);
44704
44752
  const copyToClipboard = (value) => {
44705
44753
  if (!value || typeof navigator === "undefined" || !navigator.clipboard) {
44706
44754
  return;
@@ -44723,7 +44771,7 @@ function MarkdownTable({
44723
44771
  children,
44724
44772
  ...props
44725
44773
  }) {
44726
- const ref = useRef31(null);
44774
+ const ref = useRef32(null);
44727
44775
  const { isCopied, copyToClipboard } = useCopyToClipboard();
44728
44776
  const copy = () => {
44729
44777
  const table2 = ref.current;
@@ -44807,8 +44855,8 @@ var defaultComponents2 = memoizeMarkdownComponents({
44807
44855
  // src/ui/tool-group.aui.tsx
44808
44856
  import {
44809
44857
  useCallback as useCallback19,
44810
- useRef as useRef32,
44811
- useState as useState32
44858
+ useRef as useRef33,
44859
+ useState as useState33
44812
44860
  } from "react";
44813
44861
 
44814
44862
  // src/ui/collapsible.tsx
@@ -44846,8 +44894,8 @@ function ToolGroupRoot({
44846
44894
  children,
44847
44895
  ...props
44848
44896
  }) {
44849
- const collapsibleRef = useRef32(null);
44850
- const [uncontrolledOpen, setUncontrolledOpen] = useState32(defaultOpen);
44897
+ const collapsibleRef = useRef33(null);
44898
+ const [uncontrolledOpen, setUncontrolledOpen] = useState33(defaultOpen);
44851
44899
  const lockScroll = useScrollLock(collapsibleRef, ANIMATION_DURATION);
44852
44900
  const isControlled = controlledOpen !== void 0;
44853
44901
  const isOpen = isControlled ? controlledOpen : uncontrolledOpen;
@@ -44931,7 +44979,7 @@ function ShimmerLabel({ active = true, className, ...props }) {
44931
44979
  }
44932
44980
 
44933
44981
  // src/ui/home-demo/trace-line.tsx
44934
- import { useEffect as useEffect29, useRef as useRef33, useState as useState33 } from "react";
44982
+ import { useEffect as useEffect30, useRef as useRef34, useState as useState34 } from "react";
44935
44983
  import { Fragment as Fragment13, jsx as jsx92, jsxs as jsxs25 } from "react/jsx-runtime";
44936
44984
  function TraceMarker({
44937
44985
  live,
@@ -44951,9 +44999,9 @@ function TraceMarker({
44951
44999
  );
44952
45000
  }
44953
45001
  function useToolDuration(isRunning) {
44954
- const startTimeRef = useRef33(null);
44955
- const [duration, setDuration] = useState33(null);
44956
- useEffect29(() => {
45002
+ const startTimeRef = useRef34(null);
45003
+ const [duration, setDuration] = useState34(null);
45004
+ useEffect30(() => {
44957
45005
  if (isRunning && startTimeRef.current === null) {
44958
45006
  startTimeRef.current = Date.now();
44959
45007
  setDuration(null);
@@ -45038,7 +45086,7 @@ function ToolCall({ toolName, args, argsText, result, status, isError, showDetai
45038
45086
  }
45039
45087
 
45040
45088
  // src/ui/reasoning.aui.tsx
45041
- import { memo as memo7, useCallback as useCallback21, useRef as useRef35 } from "react";
45089
+ import { memo as memo7, useCallback as useCallback21, useRef as useRef36 } from "react";
45042
45090
 
45043
45091
  // src/ui/reasoning.tsx
45044
45092
  import {
@@ -45046,10 +45094,10 @@ import {
45046
45094
  createContext as createContext8,
45047
45095
  useCallback as useCallback20,
45048
45096
  useContext as useContext10,
45049
- useEffect as useEffect30,
45050
- useLayoutEffect as useLayoutEffect11,
45051
- useRef as useRef34,
45052
- useState as useState34
45097
+ useEffect as useEffect31,
45098
+ useLayoutEffect as useLayoutEffect12,
45099
+ useRef as useRef35,
45100
+ useState as useState35
45053
45101
  } from "react";
45054
45102
  import { jsx as jsx94, jsxs as jsxs27 } from "react/jsx-runtime";
45055
45103
  var ANIMATION_DURATION2 = 200;
@@ -45077,13 +45125,13 @@ var ReasoningRoot = forwardRef32(function ReasoningRoot2({
45077
45125
  children,
45078
45126
  ...props
45079
45127
  }, ref) {
45080
- const [initialOpen] = useState34(defaultOpen);
45081
- const [userOpen, setUserOpen] = useState34(null);
45128
+ const [initialOpen] = useState35(defaultOpen);
45129
+ const [userOpen, setUserOpen] = useState35(null);
45082
45130
  const isControlled = controlledOpen !== void 0;
45083
45131
  const isOpen = isControlled ? controlledOpen : userOpen ?? (streaming || initialOpen);
45084
45132
  const isPreview = streaming === true && isOpen;
45085
- const prevStreamingRef = useRef34(streaming);
45086
- useLayoutEffect11(() => {
45133
+ const prevStreamingRef = useRef35(streaming);
45134
+ useLayoutEffect12(() => {
45087
45135
  if (prevStreamingRef.current === streaming) return;
45088
45136
  prevStreamingRef.current = streaming;
45089
45137
  if (!isControlled && userOpen === null && !initialOpen) {
@@ -45193,9 +45241,9 @@ function ReasoningText({
45193
45241
  ...props
45194
45242
  }) {
45195
45243
  const isPreview = useContext10(ReasoningPreviewContext);
45196
- const scrollRef = useRef34(null);
45197
- const contentRef = useRef34(null);
45198
- useEffect30(() => {
45244
+ const scrollRef = useRef35(null);
45245
+ const contentRef = useRef35(null);
45246
+ useEffect31(() => {
45199
45247
  if (!isPreview) return;
45200
45248
  const scrollEl = scrollRef.current;
45201
45249
  const contentEl = contentRef.current;
@@ -45262,7 +45310,7 @@ function ReasoningRoot3({
45262
45310
  onAnimationStart,
45263
45311
  ...props
45264
45312
  }) {
45265
- const collapsibleRef = useRef35(null);
45313
+ const collapsibleRef = useRef36(null);
45266
45314
  const lockScroll = useScrollLock(collapsibleRef, ANIMATION_DURATION2);
45267
45315
  const handleAnimationStart = useCallback21(() => {
45268
45316
  lockScroll();
@@ -45305,9 +45353,11 @@ function AttachmentTile({ binding, savedPreview }) {
45305
45353
  attachment.status.type === "incomplete" ? /* @__PURE__ */ jsx96("small", { className: cn("text-destructive"), role: "alert", children: attachment.status.message ?? "\u9644\u4EF6\u5904\u7406\u5931\u8D25" }) : null
45306
45354
  ] }) });
45307
45355
  }
45308
- function AssistantComposer({ binding, options: options2, placeholder, busy, cancelling, cancel }) {
45309
- const input = useRef36(null);
45356
+ function AssistantComposer({ binding, options: options2, placeholder, suggestion, busy, cancelling, cancel }) {
45357
+ const input = useRef37(null);
45310
45358
  const sending = binding.sending;
45359
+ const empty3 = useAuiState((state) => state.composer.text.length === 0);
45360
+ const nextMessage = !busy && !sending && empty3 ? suggestion : void 0;
45311
45361
  const showCancel = useAuiState((state) => busy && (state.thread.isRunning || state.composer.isEmpty));
45312
45362
  const addFiles = (files) => {
45313
45363
  for (const file of files) void binding.runtime.thread.composer.addAttachment(file).catch((error) => binding.setNotice(error instanceof Error ? error.message : String(error)));
@@ -45321,12 +45371,15 @@ function AssistantComposer({ binding, options: options2, placeholder, busy, canc
45321
45371
  },
45322
45372
  inputProps: {
45323
45373
  "aria-label": "\u8F93\u5165 Agent \u4EFB\u52A1",
45324
- placeholder,
45374
+ placeholder: nextMessage ?? placeholder,
45325
45375
  disabled: sending,
45326
45376
  cancelOnEscape: false,
45327
45377
  onKeyDown: (event) => {
45328
45378
  if (event.keyCode === 229) event.preventDefault();
45329
- else if (event.key === "Enter" && !event.shiftKey && !event.nativeEvent.isComposing) {
45379
+ else if ((event.key === "ArrowRight" || event.key === "Tab") && nextMessage && !event.nativeEvent.isComposing && !event.shiftKey && !event.ctrlKey && !event.altKey && !event.metaKey && !event.currentTarget.value) {
45380
+ event.preventDefault();
45381
+ binding.runtime.thread.composer.setText(nextMessage);
45382
+ } else if (event.key === "Enter" && !event.shiftKey && !event.nativeEvent.isComposing) {
45330
45383
  event.preventDefault();
45331
45384
  void binding.send();
45332
45385
  }
@@ -45367,8 +45420,8 @@ function ToolGroup({ tools, running, count: count3, children }) {
45367
45420
  const errors = tools.flatMap((tool2) => tool2.type === "tool" && tool2.error ? [tool2.error] : []);
45368
45421
  const errorIds = JSON.stringify(errors.map((error) => error.id));
45369
45422
  const hasErrors = errors.length > 0;
45370
- const [open, setOpen] = useState35(hasErrors);
45371
- useEffect31(() => {
45423
+ const [open, setOpen] = useState36(hasErrors);
45424
+ useEffect32(() => {
45372
45425
  if (errorIds !== "[]") setOpen(true);
45373
45426
  }, [errorIds]);
45374
45427
  const unknown = hasErrors && errors.every((error) => error.scope === "tool" && error.execution === "unknown");
@@ -45427,8 +45480,8 @@ var Icon2 = forwardRef33(function Icon3({ label, children, className, ...props }
45427
45480
  return /* @__PURE__ */ jsx97("button", { ref, type: "button", "aria-label": label, title: label, className: cn("text-muted-foreground hover:text-foreground rounded-control grid size-7 place-items-center transition-colors [&>svg]:size-4", className), ...props, children });
45428
45481
  });
45429
45482
  function Resize({ label, width, onResize, side = "left", edge = "left", min: min2, max: max2 }) {
45430
- const handle2 = useRef37(null);
45431
- const drag = useRef37(null);
45483
+ const handle2 = useRef38(null);
45484
+ const drag = useRef38(null);
45432
45485
  const readWidth = () => handle2.current?.parentElement?.getBoundingClientRect().width || width;
45433
45486
  const update = () => {
45434
45487
  const element2 = handle2.current;
@@ -45438,8 +45491,8 @@ function Resize({ label, width, onResize, side = "left", edge = "left", min: min
45438
45491
  element2.setAttribute("aria-valuemin", String(Math.min(min2, current)));
45439
45492
  element2.setAttribute("aria-valuemax", String(Math.max(max2, current)));
45440
45493
  };
45441
- useLayoutEffect12(update);
45442
- useLayoutEffect12(() => {
45494
+ useLayoutEffect13(update);
45495
+ useLayoutEffect13(() => {
45443
45496
  const panel = handle2.current?.parentElement;
45444
45497
  if (!panel || typeof ResizeObserver === "undefined") return;
45445
45498
  const observer = new ResizeObserver(update);
@@ -45490,6 +45543,7 @@ function Chat({
45490
45543
  className,
45491
45544
  style,
45492
45545
  suggestions = [],
45546
+ suggestNextMessage,
45493
45547
  attachments = {},
45494
45548
  sessionSidebar = true,
45495
45549
  showToolDetails = false,
@@ -45497,40 +45551,41 @@ function Chat({
45497
45551
  onRunResult
45498
45552
  }) {
45499
45553
  const chat = useChat();
45554
+ const nextMessage = useNextMessage(chat, suggestNextMessage, open);
45500
45555
  const { activeSessionId: sessionId, messages, status, interrupt } = chat;
45501
45556
  const busy = status !== "idle" && status !== "error";
45502
45557
  const sessionBusy = busy && status !== "waiting";
45503
- const [fullscreen, setFullscreen] = useState36(false);
45558
+ const [fullscreen, setFullscreen] = useState37(false);
45504
45559
  const changeFullscreen = (next) => {
45505
45560
  setFullscreen(next);
45506
45561
  onFullscreenChange?.(next);
45507
45562
  };
45508
- useLayoutEffect12(() => {
45563
+ useLayoutEffect13(() => {
45509
45564
  if (!open && fullscreen) {
45510
45565
  setFullscreen(false);
45511
45566
  onFullscreenChange?.(false);
45512
45567
  }
45513
45568
  }, [open, fullscreen, onFullscreenChange]);
45514
- const [sidebar, setSidebar] = useState36(false);
45569
+ const [sidebar, setSidebar] = useState37(false);
45515
45570
  const sidebarEnabled = sessionSidebar !== false;
45516
45571
  const sidebarLayout = layout === "inline" && !fullscreen && typeof sessionSidebar === "object" && sessionSidebar.layout === "outside" ? "outside" : "overlay";
45517
45572
  const sidebarOpen = sidebarEnabled && sidebar;
45518
- useEffect32(() => {
45573
+ useEffect33(() => {
45519
45574
  if (!sidebarEnabled) setSidebar(false);
45520
45575
  }, [sidebarEnabled]);
45521
- const [threadSearch, setThreadSearch] = useState36("");
45522
- const [width, setWidth] = useState36(546);
45523
- const [sidebarWidth, setSidebarWidth] = useState36();
45524
- const submitting = useRef37(void 0);
45525
- const [editing, setEditing] = useState36();
45526
- const [notice, setNotice] = useState36("");
45527
- const dialogReturnFocus = useRef37(null);
45528
- const panel = useRef37(null);
45529
- const sidebarWasOpen = useRef37(false);
45530
- const sidebarNav = useRef37(null);
45531
- const sidebarTrigger = useRef37(null);
45532
- const headerFocusButton = useRef37(null);
45533
- useLayoutEffect12(() => {
45576
+ const [threadSearch, setThreadSearch] = useState37("");
45577
+ const [width, setWidth] = useState37(546);
45578
+ const [sidebarWidth, setSidebarWidth] = useState37();
45579
+ const submitting = useRef38(void 0);
45580
+ const [editing, setEditing] = useState37();
45581
+ const [notice, setNotice] = useState37("");
45582
+ const dialogReturnFocus = useRef38(null);
45583
+ const panel = useRef38(null);
45584
+ const sidebarWasOpen = useRef38(false);
45585
+ const sidebarNav = useRef38(null);
45586
+ const sidebarTrigger = useRef38(null);
45587
+ const headerFocusButton = useRef38(null);
45588
+ useLayoutEffect13(() => {
45534
45589
  if (sidebarOpen) {
45535
45590
  sidebarWasOpen.current = true;
45536
45591
  sidebarNav.current?.querySelector('input[type="search"]')?.focus();
@@ -45539,7 +45594,7 @@ function Chat({
45539
45594
  if (sidebarWasOpen.current) (sidebarTrigger.current ?? headerFocusButton.current)?.focus();
45540
45595
  sidebarWasOpen.current = false;
45541
45596
  }, [sidebarOpen, sidebarLayout]);
45542
- const [dialog, updateDialog] = useState36();
45597
+ const [dialog, updateDialog] = useState37();
45543
45598
  const setDialog = (next) => {
45544
45599
  if (next) {
45545
45600
  const active = document.activeElement;
@@ -45549,20 +45604,20 @@ function Chat({
45549
45604
  updateDialog(next);
45550
45605
  };
45551
45606
  const byId = useMemo12(() => new Map(projectMessages(messages).map((message) => [message.id, message])), [messages]);
45552
- const visited = useRef37(/* @__PURE__ */ new Set());
45607
+ const visited = useRef38(/* @__PURE__ */ new Set());
45553
45608
  visited.current.add(sessionId);
45554
45609
  const activeTitle = messages.length ? chat.sessions.find((session) => session.id === sessionId)?.title || title : title;
45555
45610
  const latestUser = [...messages].reverse().find((message) => message.role === "user");
45556
- useEffect32(() => {
45611
+ useEffect33(() => {
45557
45612
  if (chat.completed && chat.consumeCompletion(chat.completed.id)) onRunResult?.(chat.completed.result);
45558
45613
  }, [chat.completed, chat.consumeCompletion, onRunResult]);
45559
- useLayoutEffect12(() => {
45614
+ useLayoutEffect13(() => {
45560
45615
  dialog?.cancel?.();
45561
45616
  setNotice("");
45562
45617
  setDialog(void 0);
45563
45618
  setEditing(void 0);
45564
45619
  }, [sessionId]);
45565
- useEffect32(() => {
45620
+ useEffect33(() => {
45566
45621
  if (editing && !messages.some((message) => message.id === editing.id)) setEditing(void 0);
45567
45622
  }, [messages, editing]);
45568
45623
  const safe = (action) => {
@@ -45698,7 +45753,7 @@ function Chat({
45698
45753
  /* @__PURE__ */ jsx97("button", { onClick: () => binding.setNotice(""), children: "\u5173\u95ED" })
45699
45754
  ] }) : null
45700
45755
  ] }),
45701
- composer: /* @__PURE__ */ jsx97(AssistantComposer, { binding, options: attachments, placeholder, busy: busy || Boolean(interrupt), cancelling: status === "cancelling", cancel: chat.cancel }),
45756
+ composer: /* @__PURE__ */ jsx97(AssistantComposer, { binding, options: attachments, placeholder, suggestion: nextMessage, busy: busy || Boolean(interrupt), cancelling: status === "cancelling", cancel: chat.cancel }),
45702
45757
  renderMessage: ({ message: rendered }) => {
45703
45758
  const message = byId.get(rendered.id);
45704
45759
  return message ? /* @__PURE__ */ jsx97(Fragment16, { children: editing?.id === message.id ? /* @__PURE__ */ jsx97(