@tomny-dev/uzi 0.19.0 → 0.20.0-pr.133.460.1.b643269

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.
Files changed (56) hide show
  1. package/dist/components/ai-chat/AIChat.d.ts +2 -25
  2. package/dist/components/ai-chat/AIChat.d.ts.map +1 -1
  3. package/dist/components/ai-chat/AIChatParts.d.ts +32 -0
  4. package/dist/components/ai-chat/AIChatParts.d.ts.map +1 -0
  5. package/dist/components/ai-chat/activityLabel.d.ts +20 -0
  6. package/dist/components/ai-chat/activityLabel.d.ts.map +1 -0
  7. package/dist/components/ai-chat/activityLabel.test.d.ts +2 -0
  8. package/dist/components/ai-chat/activityLabel.test.d.ts.map +1 -0
  9. package/dist/components/pill/Pill.d.ts +8 -5
  10. package/dist/components/pill/Pill.d.ts.map +1 -1
  11. package/dist/components/pill/Pill.test.d.ts +2 -0
  12. package/dist/components/pill/Pill.test.d.ts.map +1 -0
  13. package/dist/index.cjs +6 -5
  14. package/dist/index.js +4 -3
  15. package/dist/index12.js +4 -2
  16. package/dist/index12.js.map +1 -1
  17. package/dist/index13.cjs +4 -1
  18. package/dist/index13.cjs.map +1 -1
  19. package/dist/index13.js +20 -11
  20. package/dist/index13.js.map +1 -1
  21. package/dist/index14.cjs +19 -10
  22. package/dist/index14.cjs.map +1 -1
  23. package/dist/index83.js +3 -3
  24. package/dist/index83.js.map +1 -1
  25. package/dist/index84.cjs +3 -3
  26. package/dist/index84.cjs.map +1 -1
  27. package/dist/index84.js +5 -559
  28. package/dist/index84.js.map +1 -1
  29. package/dist/index85.cjs +8 -559
  30. package/dist/index85.cjs.map +1 -1
  31. package/dist/index85.js +11 -34
  32. package/dist/index85.js.map +1 -1
  33. package/dist/index86.cjs +11 -49
  34. package/dist/index86.cjs.map +1 -1
  35. package/dist/index86.js +539 -227
  36. package/dist/index86.js.map +1 -1
  37. package/dist/index87.cjs +541 -226
  38. package/dist/index87.cjs.map +1 -1
  39. package/dist/index87.js +33 -15
  40. package/dist/index87.js.map +1 -1
  41. package/dist/index88.cjs +48 -21
  42. package/dist/index88.cjs.map +1 -1
  43. package/dist/index88.js +250 -29
  44. package/dist/index88.js.map +1 -1
  45. package/dist/index89.cjs +250 -30
  46. package/dist/index89.cjs.map +1 -1
  47. package/dist/index89.js +19 -0
  48. package/dist/index89.js.map +1 -0
  49. package/dist/index90.cjs +25 -0
  50. package/dist/index90.cjs.map +1 -0
  51. package/dist/index90.js +36 -0
  52. package/dist/index90.js.map +1 -0
  53. package/dist/index91.cjs +37 -0
  54. package/dist/index91.cjs.map +1 -0
  55. package/dist/style.css +38 -17
  56. package/package.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"index84.cjs","names":[],"sources":["../src/components/ai-chat/ai-chat.module.css"],"sourcesContent":[".container {\n display: flex;\n flex-direction: column;\n height: 100%;\n min-height: 0;\n max-height: none;\n overflow: hidden;\n position: relative;\n}\n\n.scope {\n display: flex;\n flex-direction: column;\n gap: 0.25rem;\n padding: 0.75rem 3rem 0.75rem 1rem;\n background: var(--uzi-surface-1, var(--muted));\n border-bottom: 1px solid var(--border);\n}\n\n.scopeLabel {\n font-size: 0.6875rem;\n font-weight: 650;\n letter-spacing: 0.04em;\n text-transform: uppercase;\n color: var(--muted-foreground);\n}\n\n.scope strong {\n font-size: 0.875rem;\n}\n\n.scopeHelp {\n margin: 0;\n font-size: 0.75rem;\n color: var(--muted-foreground);\n line-height: 1.5;\n}\n\n.closeBtn {\n position: absolute;\n top: 0.5rem;\n right: 0.5rem;\n z-index: 1;\n display: grid;\n place-items: center;\n width: 2rem;\n height: 2rem;\n border: 0;\n border-radius: 50%;\n background: transparent;\n color: var(--muted-foreground);\n cursor: pointer;\n font-size: 0.875rem;\n}\n\n.closeBtn:hover {\n background: var(--uzi-surface-2, var(--muted));\n color: var(--foreground);\n}\n\n.closeBtn:focus-visible,\n.sendButton:focus-visible,\n.errorActions button:focus-visible,\n.historyLimit button:focus-visible {\n outline: 2px solid var(--primary);\n outline-offset: 2px;\n}\n\n.thread {\n display: flex;\n flex: 1;\n flex-direction: column;\n min-height: 0;\n overflow: hidden;\n}\n\n.viewport {\n flex: 1;\n display: flex;\n flex-direction: column;\n min-height: 0;\n overflow-y: auto;\n overflow-x: hidden;\n gap: 0.75rem;\n}\n\n.chatToolbar {\n flex-shrink: 0;\n display: flex;\n align-items: center;\n justify-content: flex-end;\n gap: 0.75rem;\n min-height: 2.75rem;\n padding: 0.375rem 0.75rem;\n background: var(--uzi-surface-1, var(--background));\n border-bottom: 1px solid var(--border);\n}\n\n.chatToolbarExtras {\n display: flex;\n align-items: center;\n gap: 0.5rem;\n min-width: 0;\n margin-right: auto;\n}\n\n.chatToolbar button {\n margin-left: 0;\n flex-shrink: 0;\n border: 0;\n border-radius: 0.375rem;\n padding: 0.35rem 0.5rem;\n background: transparent;\n color: var(--muted-foreground);\n font: inherit;\n font-size: 0.75rem;\n cursor: pointer;\n}\n\n.chatToolbar .newChatButton {\n display: grid;\n place-items: center;\n width: 2rem;\n height: 2rem;\n padding: 0;\n}\n\n.chatToolbar button:hover {\n color: var(--foreground);\n background: var(--uzi-surface-2, var(--muted));\n}\n\n.chatToolbar button:focus-visible {\n outline: 2px solid var(--primary);\n outline-offset: 2px;\n}\n\n.messageList {\n display: flex;\n flex: 1 0 auto;\n flex-direction: column;\n gap: 0.75rem;\n padding: 1rem;\n}\n\n.userMessage,\n.assistantMessage {\n display: flex;\n flex-direction: column;\n gap: 0.5rem;\n padding: 0.75rem 1rem;\n border-radius: 0.75rem;\n color: var(--foreground);\n overflow-wrap: anywhere;\n}\n\n.userMessage {\n background: color-mix(in srgb, var(--primary) 10%, transparent);\n border: 1px solid color-mix(in srgb, var(--primary) 20%, transparent);\n}\n\n.assistantMessage {\n background: var(--muted);\n border: 1px solid var(--border);\n}\n\n.textPart {\n white-space: pre-wrap;\n line-height: 1.6;\n}\n\n.reasoning,\n.toolPart {\n border: 1px solid var(--border);\n border-radius: 0.5rem;\n padding: 0.5rem 0.75rem;\n background: var(--uzi-surface-1, transparent);\n}\n\n.reasoningSummary,\n.toolPart summary {\n cursor: pointer;\n font-size: 0.75rem;\n font-weight: 600;\n color: var(--muted-foreground);\n}\n\n.reasoningText {\n margin: 0.5rem 0 0;\n font-size: 0.8125rem;\n line-height: 1.6;\n color: var(--muted-foreground);\n white-space: pre-wrap;\n}\n\n.sources {\n padding-top: 0.5rem;\n border-top: 1px solid var(--border);\n}\n\n.sourcesLabel {\n display: block;\n font-size: 0.6875rem;\n font-weight: 650;\n color: var(--muted-foreground);\n margin-bottom: 0.25rem;\n}\n\n.sources ul {\n display: flex;\n flex-wrap: wrap;\n gap: 0.5rem;\n margin: 0;\n padding-left: 1.25rem;\n}\n\n.sources li {\n font-size: 0.75rem;\n overflow-wrap: anywhere;\n}\n\n.data {\n padding: 0.5rem;\n background: var(--uzi-surface-2, var(--muted));\n border-radius: 0.5rem;\n overflow-x: auto;\n}\n\n.structuredData {\n margin: 0;\n padding: 0.5rem 0;\n max-width: 100%;\n overflow-x: auto;\n white-space: pre-wrap;\n overflow-wrap: anywhere;\n font-size: 0.75rem;\n line-height: 1.5;\n}\n\n.footer {\n position: sticky;\n bottom: 0;\n z-index: 1;\n flex-shrink: 0;\n background: var(--background);\n border-top: 1px solid var(--border);\n}\n\n.composerForm {\n display: grid;\n grid-template-columns: minmax(0, 1fr) auto;\n align-items: end;\n gap: 0.75rem;\n padding: 0.75rem 1rem;\n}\n\n.input {\n width: 100%;\n min-height: 2.5rem;\n padding: 0.5rem 0.75rem;\n border: 1px solid var(--border);\n border-radius: 0.5rem;\n background: var(--background);\n color: var(--foreground);\n font: inherit;\n font-size: 0.875rem;\n line-height: 1.5;\n resize: vertical;\n}\n\n.input:focus {\n outline: none;\n border-color: var(--primary);\n box-shadow: 0 0 0 2px color-mix(in srgb, var(--primary) 30%, transparent);\n}\n\n.input::placeholder {\n color: var(--muted-foreground);\n}\n\n.input:disabled,\n.sendButton:disabled {\n opacity: 0.5;\n cursor: not-allowed;\n}\n\n.sendButton {\n min-height: 2.5rem;\n padding: 0.5rem 0.875rem;\n border: 1px solid var(--border);\n border-radius: 0.5rem;\n background: var(--primary);\n color: var(--primary-foreground);\n font: inherit;\n font-size: 0.875rem;\n font-weight: 600;\n cursor: pointer;\n}\n\n.sendButton:not(:disabled):hover {\n filter: brightness(0.95);\n}\n\n.activityBubble {\n display: inline-flex;\n align-items: center;\n align-self: flex-start;\n gap: 0.625rem;\n width: fit-content;\n max-width: 100%;\n padding: 0.75rem 0.875rem;\n border: 1px solid var(--border);\n border-radius: 0.875rem;\n background: var(--muted);\n color: var(--muted-foreground);\n font-size: 0.8125rem;\n line-height: 1.4;\n animation: uzi-chat-activity-enter 180ms ease-out 120ms both;\n}\n\n.activityDots { display: flex; align-items: center; gap: 0.2rem; }\n.activityDots i {\n display: block;\n width: 0.35rem;\n height: 0.35rem;\n flex: 0 0 auto;\n border-radius: 50%;\n background: currentColor;\n animation: uzi-chat-dot-pulse 1.2s ease-in-out infinite;\n}\n.activityDots i:nth-child(2) { animation-delay: 150ms; }\n.activityDots i:nth-child(3) { animation-delay: 300ms; }\n\n@keyframes uzi-chat-activity-enter {\n from { opacity: 0; transform: translateY(3px); }\n to { opacity: 1; transform: translateY(0); }\n}\n@keyframes uzi-chat-dot-pulse {\n 0%, 60%, 100% { opacity: 0.35; transform: translateY(0); }\n 30% { opacity: 1; transform: translateY(-3px); }\n}\n\n@media (prefers-reduced-motion: reduce) {\n .activityBubble, .activityDots i { animation: none; }\n}\n\n.error {\n display: flex;\n flex-direction: column;\n gap: 0.5rem;\n padding: 0.75rem 1rem;\n border: 1px solid var(--destructive);\n border-radius: 0.5rem;\n margin: 0.75rem 1rem;\n background: color-mix(in srgb, var(--destructive) 10%, transparent);\n}\n\n.error p {\n margin: 0;\n color: var(--destructive);\n font-size: 0.8125rem;\n}\n\n.errorActions {\n display: flex;\n gap: 0.5rem;\n}\n\n.errorActions button,\n.historyLimit button {\n padding: 0.375rem 0.75rem;\n border: 1px solid var(--border);\n border-radius: 0.375rem;\n background: transparent;\n color: var(--foreground);\n font: inherit;\n font-size: 0.75rem;\n cursor: pointer;\n}\n\n.errorActions button:hover,\n.historyLimit button:hover {\n background: var(--uzi-surface-2, var(--muted));\n}\n\n.historyLimit {\n display: flex;\n flex-direction: column;\n gap: 0.5rem;\n align-items: center;\n padding: 0.75rem 1rem;\n margin: 0.75rem 1rem;\n background: var(--uzi-surface-1, var(--muted));\n border: 1px solid var(--border);\n border-radius: 0.5rem;\n}\n\n.historyLimit span {\n font-size: 0.75rem;\n color: var(--muted-foreground);\n}\n\n.emptyState {\n display: grid;\n place-items: center;\n flex: 1;\n min-height: 12rem;\n color: var(--muted-foreground);\n text-align: center;\n}\n\n.emptyState p {\n margin: 0;\n font-size: 0.875rem;\n}\n\n@media (max-width: 640px) {\n .composerForm {\n grid-template-columns: minmax(0, 1fr) auto;\n }\n\n .errorActions {\n flex-wrap: wrap;\n }\n}\n\n/* Optional integration controls use the same Uzi surface and layout tokens. */\n.composerExtras {\n grid-column: 1 / -1;\n min-width: 0;\n}\n\n.composerActions {\n display: flex;\n align-items: center;\n gap: 0.5rem;\n}\n\n.approvalActions { display: flex; align-items: center; flex-wrap: wrap; gap: 0.5rem; padding-top: 0.5rem; }\n.approvalActions button {\n background: var(--background); color: var(--foreground); border: 1px solid var(--border);\n border-radius: 0.375rem; padding: 0.3rem 0.55rem; cursor: pointer;\n}\n.approvalActions button:disabled { opacity: 0.5; cursor: not-allowed; }\n.attachmentError { color: var(--destructive); padding: 0.5rem 1rem; margin: 0; }\n.attachmentList {\n display: flex;\n flex-wrap: nowrap;\n gap: 0.625rem;\n max-width: 100%;\n padding: 0.125rem 0.125rem 0.5rem;\n margin: 0;\n overflow-x: auto;\n list-style: none;\n scrollbar-width: thin;\n}\n.attachmentList li { display: flex; flex: 0 0 auto; min-width: 0; }\n\n/* Role-aware message layout shared by the default renderer and consumer apps. */\n.messageBubble { width: fit-content; min-width: 0; max-width: 100%; }\n.messageBubble.userMessage { align-self: flex-end; max-width: min(90%, 42rem); }\n.messageBubble.assistantMessage { align-self: flex-start; max-width: 100%; }\n.messageLabel { font-size: 0.6875rem; font-weight: 650; color: var(--muted-foreground); }\n\n/* Shared compact composer: same visual grammar as Betty, without app-owned behavior. */\n.composerSurface {\n grid-column: 1 / -1;\n min-width: 0;\n border: 1px solid var(--border);\n border-radius: 0.875rem;\n background: var(--background);\n}\n.composerSurface:focus-within { outline: 2px solid var(--ring); outline-offset: 2px; }\n.composerRow { display: flex; align-items: end; min-width: 0; gap: 0.375rem; padding: 0.375rem; }\n.composerRow .input {\n display: block; flex: 1; width: 0; min-width: 0; min-height: 2.75rem;\n max-height: 11rem; padding: 0.625rem 0.25rem; border: 0;\n background: transparent; resize: none; font-size: 1rem;\n}\n.composerRow .input:focus { outline: none; box-shadow: none; }\n.composerIconButton, .composerRow .sendButton {\n display: grid; place-items: center; flex-shrink: 0;\n width: 2.75rem; height: 2.75rem; min-height: 2.75rem;\n padding: 0; border-radius: 0.625rem; cursor: pointer;\n}\n.composerIconButton {\n color: var(--foreground); border: 0; background: transparent;\n}\n.composerIconButton:hover:not(:disabled) { background: var(--muted); }\n.composerRow .sendButton { border: 0; background: var(--primary); color: var(--primary-foreground); }\n.composerIconButton:focus-visible, .composerRow .sendButton:focus-visible {\n outline: 2px solid var(--ring); outline-offset: 2px;\n}\n.composerIconButton:disabled { opacity: 0.5; cursor: not-allowed; }\n.visuallyHidden { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }\n\n/* Shared image tiles and file cards for both the composer and message history. */\n.attachmentCard {\n position: relative;\n display: flex;\n flex-direction: column;\n min-width: 0;\n max-width: 100%;\n overflow: hidden;\n border: 1px solid var(--border);\n border-radius: 0.75rem;\n background: var(--uzi-surface-1, var(--muted));\n}\n.stagedAttachment {\n width: 5.75rem;\n height: 5.75rem;\n}\n.stagedFileAttachment { width: min(15rem, 75vw); }\n.sentAttachment {\n width: fit-content;\n max-width: min(16rem, 100%);\n}\n.imageAttachmentButton {\n display: block;\n width: 100%;\n min-width: 0;\n padding: 0;\n border: 0;\n background: transparent;\n cursor: zoom-in;\n}\n.stagedAttachment .imageAttachmentButton { height: 100%; }\n.attachmentThumbnail {\n display: block;\n max-width: 100%;\n object-fit: contain;\n}\n.stagedAttachment .attachmentThumbnail { width: 100%; height: 100%; object-fit: cover; }\n.sentAttachment .attachmentThumbnail {\n width: auto;\n min-width: 6rem;\n max-height: 14rem;\n}\n.sentAttachmentName {\n display: block;\n max-width: 100%;\n padding: 0.375rem 0.5rem;\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n color: var(--muted-foreground);\n font-size: 0.6875rem;\n}\n.fileAttachment {\n display: flex;\n align-items: center;\n gap: 0.625rem;\n min-width: 0;\n min-height: 4rem;\n padding: 0.625rem;\n color: var(--foreground);\n}\n.stagedFileAttachment .fileAttachment { height: 100%; box-sizing: border-box; padding-right: 1.875rem; }\n.fileAttachment svg { flex: 0 0 auto; color: var(--muted-foreground); }\n.fileAttachmentDetails {\n display: flex;\n flex-direction: column;\n gap: 0.125rem;\n min-width: 0;\n font-size: 0.75rem;\n}\n.fileAttachmentDetails a,\n.fileAttachmentDetails > span {\n display: block;\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n color: var(--foreground);\n text-decoration: none;\n}\n.fileAttachmentDetails a:hover { text-decoration: underline; }\n.fileAttachmentDetails small { color: var(--muted-foreground); font-size: 0.6875rem; }\n.removeAttachment {\n position: absolute;\n top: 0.25rem;\n right: 0.25rem;\n display: grid;\n place-items: center;\n width: 1.5rem;\n height: 1.5rem;\n padding: 0;\n border: 1px solid var(--border);\n border-radius: 50%;\n background: var(--background);\n color: var(--foreground);\n font: inherit;\n font-size: 1.125rem;\n line-height: 1;\n cursor: pointer;\n box-shadow: 0 1px 4px rgb(0 0 0 / 20%);\n}\n.removeAttachment:hover { background: var(--muted); }\n.removeAttachmentSlot {\n position: absolute;\n top: 0.25rem;\n right: 0.25rem;\n display: grid;\n place-items: center;\n}\n.removeAttachmentSlot button {\n display: grid;\n place-items: center;\n width: 1.5rem;\n min-width: 1.5rem;\n height: 1.5rem;\n min-height: 1.5rem;\n padding: 0;\n border: 1px solid var(--border);\n border-radius: 50%;\n background: var(--background);\n color: var(--foreground);\n font-size: 1.125rem;\n line-height: 1;\n box-shadow: 0 1px 4px rgb(0 0 0 / 20%);\n}\n.imageAttachmentButton:focus-visible, .removeAttachment:focus-visible,\n.fileAttachmentDetails a:focus-visible, .attachmentDialog button:focus-visible {\n outline: 2px solid var(--ring);\n outline-offset: 2px;\n}\n.attachmentDialog {\n max-width: min(95vw, 60rem);\n max-height: 90dvh;\n padding: 0.75rem;\n border: 1px solid var(--border);\n border-radius: 0.875rem;\n background: var(--background);\n color: var(--foreground);\n box-shadow: 0 16px 60px rgb(0 0 0 / 35%);\n}\n.attachmentDialog::backdrop { background: rgb(0 0 0 / 80%); }\n.attachmentDialogHeader {\n display: flex;\n align-items: center;\n justify-content: space-between;\n gap: 1rem;\n padding-bottom: 0.5rem;\n font-size: 0.8125rem;\n}\n.attachmentDialogHeader span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }\n.attachmentDialogHeader button {\n flex-shrink: 0;\n width: 2rem;\n height: 2rem;\n border: 0;\n border-radius: 50%;\n background: var(--muted);\n color: var(--foreground);\n font: inherit;\n font-size: 1.25rem;\n cursor: pointer;\n}\n.attachmentDialog > img {\n display: block;\n width: auto;\n height: auto;\n max-width: 100%;\n max-height: calc(90dvh - 5rem);\n margin: auto;\n object-fit: contain;\n}\n"],"mappings":""}
1
+ {"version":3,"file":"index84.cjs","names":[],"sources":["../src/components/ai-chat/ai-chat.module.css"],"sourcesContent":[".container {\n display: flex;\n flex-direction: column;\n height: 100%;\n min-height: 0;\n max-height: none;\n overflow: hidden;\n position: relative;\n}\n\n.scope {\n display: flex;\n flex-direction: column;\n gap: 0.25rem;\n padding: 0.75rem 3rem 0.75rem 1rem;\n background: var(--uzi-surface-1, var(--muted));\n border-bottom: 1px solid var(--border);\n}\n\n.scopeLabel {\n font-size: 0.6875rem;\n font-weight: 650;\n letter-spacing: 0.04em;\n text-transform: uppercase;\n color: var(--muted-foreground);\n}\n\n.scope strong {\n font-size: 0.875rem;\n}\n\n.scopeHelp {\n margin: 0;\n font-size: 0.75rem;\n color: var(--muted-foreground);\n line-height: 1.5;\n}\n\n.closeBtn {\n position: absolute;\n top: 0.5rem;\n right: 0.5rem;\n z-index: 1;\n display: grid;\n place-items: center;\n width: 2rem;\n height: 2rem;\n border: 0;\n border-radius: 50%;\n background: transparent;\n color: var(--muted-foreground);\n cursor: pointer;\n font-size: 0.875rem;\n}\n\n.closeBtn:hover {\n background: var(--uzi-surface-2, var(--muted));\n color: var(--foreground);\n}\n\n.closeBtn:focus-visible,\n.sendButton:focus-visible,\n.errorActions button:focus-visible,\n.historyLimit button:focus-visible {\n outline: 2px solid var(--primary);\n outline-offset: 2px;\n}\n\n.thread {\n display: flex;\n flex: 1;\n flex-direction: column;\n min-height: 0;\n overflow: hidden;\n}\n\n.viewport {\n flex: 1;\n display: flex;\n flex-direction: column;\n min-height: 0;\n overflow-y: auto;\n overflow-x: hidden;\n gap: 0.75rem;\n}\n\n.chatToolbar {\n flex-shrink: 0;\n display: flex;\n align-items: center;\n justify-content: flex-end;\n gap: 0.75rem;\n min-height: 2.75rem;\n padding: 0.375rem 0.75rem;\n background: var(--uzi-surface-1, var(--background));\n border-bottom: 1px solid var(--border);\n}\n\n.chatToolbarExtras {\n display: flex;\n align-items: center;\n gap: 0.5rem;\n min-width: 0;\n margin-right: auto;\n}\n\n.chatToolbar button {\n margin-left: 0;\n flex-shrink: 0;\n border: 0;\n border-radius: 0.375rem;\n padding: 0.35rem 0.5rem;\n background: transparent;\n color: var(--muted-foreground);\n font: inherit;\n font-size: 0.75rem;\n cursor: pointer;\n}\n\n.chatToolbar .newChatButton {\n display: grid;\n place-items: center;\n width: 2rem;\n height: 2rem;\n padding: 0;\n}\n\n.chatToolbar button:hover {\n color: var(--foreground);\n background: var(--uzi-surface-2, var(--muted));\n}\n\n.chatToolbar button:focus-visible {\n outline: 2px solid var(--primary);\n outline-offset: 2px;\n}\n\n.messageList {\n display: flex;\n flex: 1 0 auto;\n flex-direction: column;\n gap: 0.75rem;\n padding: 1rem;\n}\n\n.userMessage,\n.assistantMessage {\n display: flex;\n flex-direction: column;\n gap: 0.5rem;\n padding: 0.75rem 1rem;\n border-radius: 0.75rem;\n color: var(--foreground);\n overflow-wrap: anywhere;\n}\n\n.userMessage {\n background: color-mix(in srgb, var(--primary) 10%, transparent);\n border: 1px solid color-mix(in srgb, var(--primary) 20%, transparent);\n}\n\n.assistantMessage {\n background: var(--muted);\n border: 1px solid var(--border);\n}\n\n.textPart {\n white-space: pre-wrap;\n line-height: 1.6;\n}\n\n.reasoning,\n.toolPart {\n border: 1px solid var(--border);\n border-radius: 0.5rem;\n padding: 0.5rem 0.75rem;\n background: var(--uzi-surface-1, transparent);\n}\n\n.reasoningSummary,\n.toolPart summary {\n cursor: pointer;\n font-size: 0.75rem;\n font-weight: 600;\n color: var(--muted-foreground);\n}\n\n.reasoningText {\n margin: 0.5rem 0 0;\n font-size: 0.8125rem;\n line-height: 1.6;\n color: var(--muted-foreground);\n white-space: pre-wrap;\n}\n\n.sources {\n padding-top: 0.5rem;\n border-top: 1px solid var(--border);\n}\n\n.sourcesLabel {\n display: block;\n font-size: 0.6875rem;\n font-weight: 650;\n color: var(--muted-foreground);\n margin-bottom: 0.25rem;\n}\n\n.sources ul {\n display: flex;\n flex-wrap: wrap;\n gap: 0.5rem;\n margin: 0;\n padding-left: 1.25rem;\n}\n\n.sources li {\n font-size: 0.75rem;\n overflow-wrap: anywhere;\n}\n\n.data {\n padding: 0.5rem;\n background: var(--uzi-surface-2, var(--muted));\n border-radius: 0.5rem;\n overflow-x: auto;\n}\n\n.structuredData {\n margin: 0;\n padding: 0.5rem 0;\n max-width: 100%;\n overflow-x: auto;\n white-space: pre-wrap;\n overflow-wrap: anywhere;\n font-size: 0.75rem;\n line-height: 1.5;\n}\n\n.footer {\n position: sticky;\n bottom: 0;\n z-index: 1;\n flex-shrink: 0;\n background: var(--background);\n border-top: 1px solid var(--border);\n}\n\n.composerForm {\n display: grid;\n grid-template-columns: minmax(0, 1fr) auto;\n align-items: end;\n gap: 0.75rem;\n padding: 0.75rem 1rem;\n}\n\n.input {\n width: 100%;\n min-height: 2.5rem;\n padding: 0.5rem 0.75rem;\n border: 1px solid var(--border);\n border-radius: 0.5rem;\n background: var(--background);\n color: var(--foreground);\n font: inherit;\n font-size: 0.875rem;\n line-height: 1.5;\n resize: vertical;\n}\n\n.input:focus {\n outline: none;\n border-color: var(--primary);\n box-shadow: 0 0 0 2px color-mix(in srgb, var(--primary) 30%, transparent);\n}\n\n.input::placeholder {\n color: var(--muted-foreground);\n}\n\n.input:disabled,\n.sendButton:disabled {\n opacity: 0.5;\n cursor: not-allowed;\n}\n\n.sendButton {\n min-height: 2.5rem;\n padding: 0.5rem 0.875rem;\n border: 1px solid var(--border);\n border-radius: 0.5rem;\n background: var(--primary);\n color: var(--primary-foreground);\n font: inherit;\n font-size: 0.875rem;\n font-weight: 600;\n cursor: pointer;\n}\n\n.sendButton:not(:disabled):hover {\n filter: brightness(0.95);\n}\n\n.activityBubble {\n display: inline-flex;\n align-items: center;\n align-self: flex-start;\n gap: 0.625rem;\n width: fit-content;\n max-width: 100%;\n padding: 0.375rem 0.5rem;\n color: var(--muted-foreground);\n font-size: 0.8125rem;\n line-height: 1.4;\n animation: uzi-chat-activity-enter 180ms ease-out 120ms both;\n}\n\n.activityDots { display: flex; align-items: center; gap: 0.2rem; }\n.activityDots i {\n display: block;\n width: 0.35rem;\n height: 0.35rem;\n flex: 0 0 auto;\n border-radius: 50%;\n background: currentColor;\n animation: uzi-chat-dot-pulse 1.2s ease-in-out infinite;\n}\n.activityDots i:nth-child(2) { animation-delay: 150ms; }\n.activityDots i:nth-child(3) { animation-delay: 300ms; }\n\n@keyframes uzi-chat-activity-enter {\n from { opacity: 0; transform: translateY(3px); }\n to { opacity: 1; transform: translateY(0); }\n}\n@keyframes uzi-chat-dot-pulse {\n 0%, 60%, 100% { opacity: 0.35; transform: translateY(0); }\n 30% { opacity: 1; transform: translateY(-3px); }\n}\n\n@media (prefers-reduced-motion: reduce) {\n .activityBubble, .activityDots i { animation: none; }\n}\n\n.error {\n display: flex;\n flex-direction: column;\n gap: 0.5rem;\n padding: 0.75rem 1rem;\n border: 1px solid var(--destructive);\n border-radius: 0.5rem;\n align-self: flex-start;\n max-width: min(100%, 42rem);\n margin: 0;\n background: color-mix(in srgb, var(--destructive) 10%, transparent);\n}\n\n.error p {\n margin: 0;\n color: var(--destructive);\n font-size: 0.8125rem;\n}\n\n.errorActions {\n display: flex;\n gap: 0.5rem;\n}\n\n.errorActions button,\n.historyLimit button {\n padding: 0.375rem 0.75rem;\n border: 1px solid var(--border);\n border-radius: 0.375rem;\n background: transparent;\n color: var(--foreground);\n font: inherit;\n font-size: 0.75rem;\n cursor: pointer;\n}\n\n.errorActions button:hover,\n.historyLimit button:hover {\n background: var(--uzi-surface-2, var(--muted));\n}\n\n.historyLimit {\n display: flex;\n flex-direction: column;\n gap: 0.5rem;\n align-items: center;\n padding: 0.75rem 1rem;\n margin: 0.75rem 1rem;\n background: var(--uzi-surface-1, var(--muted));\n border: 1px solid var(--border);\n border-radius: 0.5rem;\n}\n\n.historyLimit span {\n font-size: 0.75rem;\n color: var(--muted-foreground);\n}\n\n.emptyState {\n display: grid;\n place-items: center;\n flex: 1;\n min-height: 12rem;\n color: var(--muted-foreground);\n text-align: center;\n}\n\n.emptyState p {\n margin: 0;\n font-size: 0.875rem;\n}\n\n@media (max-width: 640px) {\n .composerForm {\n grid-template-columns: minmax(0, 1fr) auto;\n }\n\n .errorActions {\n flex-wrap: wrap;\n }\n}\n\n/* Optional integration controls use the same Uzi surface and layout tokens. */\n.composerExtras {\n grid-column: 1 / -1;\n min-width: 0;\n}\n\n.composerActions {\n display: flex;\n align-items: center;\n gap: 0.5rem;\n}\n\n.approvalActions { display: flex; align-items: center; flex-wrap: wrap; gap: 0.5rem; padding-top: 0.5rem; }\n.approvalActions button {\n background: var(--background); color: var(--foreground); border: 1px solid var(--border);\n border-radius: 0.375rem; padding: 0.3rem 0.55rem; cursor: pointer;\n}\n.approvalActions button:disabled { opacity: 0.5; cursor: not-allowed; }\n.attachmentError { color: var(--destructive); padding: 0.5rem 1rem; margin: 0; }\n.attachmentList {\n display: flex;\n flex-wrap: nowrap;\n gap: 0.625rem;\n max-width: 100%;\n padding: 0.125rem 0.125rem 0.5rem;\n margin: 0;\n overflow-x: auto;\n list-style: none;\n scrollbar-width: thin;\n}\n.attachmentList li { display: flex; flex: 0 0 auto; min-width: 0; }\n\n/* Role-aware message layout shared by the default renderer and consumer apps. */\n.messageBubble { width: fit-content; min-width: 0; max-width: 100%; }\n.messageBubble.userMessage { align-self: flex-end; max-width: min(90%, 42rem); }\n.messageBubble.assistantMessage { align-self: flex-start; max-width: 100%; }\n.messageLabel { font-size: 0.6875rem; font-weight: 650; color: var(--muted-foreground); }\n\n/* Shared compact composer: same visual grammar as Betty, without app-owned behavior. */\n.composerSurface {\n grid-column: 1 / -1;\n min-width: 0;\n border: 1px solid var(--border);\n border-radius: 0.875rem;\n background: var(--background);\n}\n.composerSurface:focus-within { outline: 2px solid var(--ring); outline-offset: 2px; }\n.composerRow { display: flex; align-items: end; min-width: 0; gap: 0.375rem; padding: 0.375rem; }\n.composerRow .input {\n display: block; flex: 1; width: 0; min-width: 0; min-height: 2.75rem;\n max-height: 11rem; padding: 0.625rem 0.25rem; border: 0;\n background: transparent; resize: none; font-size: 1rem;\n}\n.composerRow .input:focus { outline: none; box-shadow: none; }\n.composerIconButton, .composerRow .sendButton {\n display: grid; place-items: center; flex-shrink: 0;\n width: 2.75rem; height: 2.75rem; min-height: 2.75rem;\n padding: 0; border-radius: 0.625rem; cursor: pointer;\n}\n.composerIconButton {\n color: var(--foreground); border: 0; background: transparent;\n}\n.composerIconButton:hover:not(:disabled) { background: var(--muted); }\n.composerRow .sendButton { border: 0; background: var(--primary); color: var(--primary-foreground); }\n.composerIconButton:focus-visible, .composerRow .sendButton:focus-visible {\n outline: 2px solid var(--ring); outline-offset: 2px;\n}\n.composerIconButton:disabled { opacity: 0.5; cursor: not-allowed; }\n.visuallyHidden { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }\n\n/* Shared image tiles and file cards for both the composer and message history. */\n.attachmentCard {\n position: relative;\n display: flex;\n flex-direction: column;\n min-width: 0;\n max-width: 100%;\n overflow: hidden;\n border: 1px solid var(--border);\n border-radius: 0.75rem;\n background: var(--uzi-surface-1, var(--muted));\n}\n.stagedAttachment {\n width: 5.75rem;\n height: 5.75rem;\n}\n.stagedFileAttachment { width: min(15rem, 75vw); }\n.sentAttachment {\n width: fit-content;\n max-width: min(20rem, 100%);\n}\n/* Sent images are part of the message, not nested file cards. */\n.sentImageAttachment {\n border: 0;\n background: transparent;\n}\n.imageAttachmentButton {\n display: block;\n width: 100%;\n min-width: 0;\n padding: 0;\n border: 0;\n background: transparent;\n cursor: zoom-in;\n}\n.stagedAttachment .imageAttachmentButton { height: 100%; }\n.attachmentThumbnail {\n display: block;\n max-width: 100%;\n object-fit: contain;\n}\n.stagedAttachment .attachmentThumbnail { width: 100%; height: 100%; object-fit: cover; }\n.sentAttachment .attachmentThumbnail {\n width: auto;\n height: auto;\n min-width: 8rem;\n max-width: 100%;\n max-height: min(26rem, 60dvh);\n}\n.fileAttachment {\n display: flex;\n align-items: center;\n gap: 0.625rem;\n min-width: 0;\n min-height: 4rem;\n padding: 0.625rem;\n color: var(--foreground);\n}\n.stagedFileAttachment .fileAttachment { height: 100%; box-sizing: border-box; padding-right: 1.875rem; }\n.fileAttachment svg { flex: 0 0 auto; color: var(--muted-foreground); }\n.fileAttachmentDetails {\n display: flex;\n flex-direction: column;\n gap: 0.125rem;\n min-width: 0;\n font-size: 0.75rem;\n}\n.fileAttachmentDetails a,\n.fileAttachmentDetails > span {\n display: block;\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n color: var(--foreground);\n text-decoration: none;\n}\n.fileAttachmentDetails a:hover { text-decoration: underline; }\n.fileAttachmentDetails small { color: var(--muted-foreground); font-size: 0.6875rem; }\n.removeAttachment {\n position: absolute;\n top: 0.25rem;\n right: 0.25rem;\n display: grid;\n place-items: center;\n width: 1.5rem;\n height: 1.5rem;\n padding: 0;\n border: 1px solid var(--border);\n border-radius: 50%;\n background: var(--background);\n color: var(--foreground);\n font: inherit;\n font-size: 1.125rem;\n line-height: 1;\n cursor: pointer;\n box-shadow: 0 1px 4px rgb(0 0 0 / 20%);\n}\n.removeAttachment:hover { background: var(--muted); }\n.removeAttachmentSlot {\n position: absolute;\n top: 0.25rem;\n right: 0.25rem;\n display: grid;\n place-items: center;\n}\n.removeAttachmentSlot button {\n display: grid;\n place-items: center;\n width: 1.5rem;\n min-width: 1.5rem;\n height: 1.5rem;\n min-height: 1.5rem;\n padding: 0;\n border: 1px solid var(--border);\n border-radius: 50%;\n background: var(--background);\n color: var(--foreground);\n font-size: 1.125rem;\n line-height: 1;\n box-shadow: 0 1px 4px rgb(0 0 0 / 20%);\n}\n.imageAttachmentButton:focus-visible, .removeAttachment:focus-visible,\n.fileAttachmentDetails a:focus-visible, .attachmentDialog button:focus-visible {\n outline: 2px solid var(--ring);\n outline-offset: 2px;\n}\n.attachmentDialog {\n max-width: min(95vw, 60rem);\n max-height: 90dvh;\n padding: 0.75rem;\n border: 1px solid var(--border);\n border-radius: 0.875rem;\n background: var(--background);\n color: var(--foreground);\n box-shadow: 0 16px 60px rgb(0 0 0 / 35%);\n}\n.attachmentDialog::backdrop { background: rgb(0 0 0 / 80%); }\n.attachmentDialogHeader {\n display: flex;\n align-items: center;\n justify-content: space-between;\n gap: 1rem;\n padding-bottom: 0.5rem;\n font-size: 0.8125rem;\n}\n.attachmentDialogHeader span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }\n.attachmentDialogHeader button {\n flex-shrink: 0;\n width: 2rem;\n height: 2rem;\n border: 0;\n border-radius: 50%;\n background: var(--muted);\n color: var(--foreground);\n font: inherit;\n font-size: 1.25rem;\n cursor: pointer;\n}\n.attachmentDialog > img {\n display: block;\n width: auto;\n height: auto;\n max-width: 100%;\n max-height: calc(90dvh - 5rem);\n margin: auto;\n object-fit: contain;\n}\n"],"mappings":""}
package/dist/index84.js CHANGED
@@ -1,10 +1,8 @@
1
1
  "use client";
2
2
  import ai_chat_module_default from "./index83.js";
3
- import { useEffect, useMemo, useRef, useState } from "react";
3
+ import { useEffect, useRef, useState } from "react";
4
4
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
5
- import { AuiConfig, AuiProvider, ThreadPrimitive } from "@assistant-ui/react";
6
- import { AISDKChat, AssistantChatTransport, useAISDKChat } from "@assistant-ui/ai-sdk";
7
- //#region src/components/ai-chat/AIChat.tsx
5
+ //#region src/components/ai-chat/AIChatParts.tsx
8
6
  function isRecord(value) {
9
7
  return typeof value === "object" && value !== null && !Array.isArray(value);
10
8
  }
@@ -38,7 +36,8 @@ function AIChatAttachmentPreview({ name, size, imageUrl, href, staged, onRemove,
38
36
  className: [
39
37
  ai_chat_module_default.attachmentCard,
40
38
  staged ? ai_chat_module_default.stagedAttachment : ai_chat_module_default.sentAttachment,
41
- staged && !safePreviewUrl ? ai_chat_module_default.stagedFileAttachment : ""
39
+ staged && !safePreviewUrl ? ai_chat_module_default.stagedFileAttachment : "",
40
+ safePreviewUrl && !staged ? ai_chat_module_default.sentImageAttachment : ""
42
41
  ].filter(Boolean).join(" "),
43
42
  children: [
44
43
  safePreviewUrl ? /* @__PURE__ */ jsx("button", {
@@ -81,11 +80,6 @@ function AIChatAttachmentPreview({ name, size, imageUrl, href, staged, onRemove,
81
80
  }), size !== void 0 && /* @__PURE__ */ jsx("small", { children: formatAttachmentSize(size) })]
82
81
  })]
83
82
  }),
84
- safePreviewUrl && !staged && /* @__PURE__ */ jsx("span", {
85
- className: ai_chat_module_default.sentAttachmentName,
86
- title: name,
87
- children: name
88
- }),
89
83
  removeControl && /* @__PURE__ */ jsx("span", {
90
84
  className: ai_chat_module_default.removeAttachmentSlot,
91
85
  children: removeControl
@@ -279,555 +273,7 @@ function renderPart(part, index, components, onToolApproval, pendingApprovalId)
279
273
  children: JSON.stringify(part, null, 2)
280
274
  });
281
275
  }
282
- var DEFAULT_MESSAGE_LIMIT = 8;
283
- 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, activityLabel, toolActivityLabels, history, sendAutomaticallyWhen, onClose, className, style }) {
284
- const [session, setSession] = useState(0);
285
- const transport = useMemo(() => new AssistantChatTransport({
286
- api,
287
- ...scope ? { body: { scope } } : {},
288
- ...requestFetch ? { fetch: requestFetch } : {},
289
- ...headers ? { headers } : {},
290
- ...credentials ? { credentials } : {},
291
- ...prepareSendMessagesRequest ? { prepareSendMessagesRequest } : {}
292
- }), [
293
- api,
294
- scope,
295
- requestFetch,
296
- headers,
297
- credentials,
298
- prepareSendMessagesRequest
299
- ]);
300
- const config = useMemo(() => AuiConfig({ threads: AISDKChat({
301
- transport,
302
- ...sendAutomaticallyWhen ? { sendAutomaticallyWhen } : {}
303
- }) }), [
304
- transport,
305
- session,
306
- sendAutomaticallyWhen
307
- ]);
308
- return /* @__PURE__ */ jsxs("div", {
309
- className: [ai_chat_module_default.container, className].filter(Boolean).join(" "),
310
- style,
311
- children: [
312
- scopeLabel && /* @__PURE__ */ jsxs("div", {
313
- className: ai_chat_module_default.scope,
314
- children: [/* @__PURE__ */ jsx("span", {
315
- className: ai_chat_module_default.scopeLabel,
316
- children: "Current scope"
317
- }), /* @__PURE__ */ jsx("strong", { children: scopeLabel })]
318
- }),
319
- onClose && /* @__PURE__ */ jsx("button", {
320
- className: ai_chat_module_default.closeBtn,
321
- type: "button",
322
- onClick: onClose,
323
- "aria-label": "Close chat",
324
- children: "✕"
325
- }),
326
- /* @__PURE__ */ jsx(AuiProvider, {
327
- config,
328
- children: /* @__PURE__ */ jsx(ThreadPrimitive.Root, {
329
- className: ai_chat_module_default.thread,
330
- children: /* @__PURE__ */ jsx(ChatViewport, {
331
- messageLimit: Number.isFinite(messageLimit) ? Math.max(1, Math.floor(messageLimit)) : DEFAULT_MESSAGE_LIMIT,
332
- inputPlaceholder,
333
- inputAriaLabel,
334
- inputMaxLength,
335
- components,
336
- toolbarActions,
337
- showNewChatInToolbar,
338
- newChatRequestKey,
339
- attachmentOptions: attachments,
340
- activityLabel,
341
- toolActivityLabels,
342
- history,
343
- onNewChat: () => setSession((previous) => previous + 1)
344
- })
345
- })
346
- }, JSON.stringify([
347
- api,
348
- scope,
349
- sessionKey,
350
- session
351
- ]))
352
- ]
353
- });
354
- }
355
- function ChatViewport({ messageLimit, inputPlaceholder, inputAriaLabel, inputMaxLength, components, toolbarActions, showNewChatInToolbar, newChatRequestKey, attachmentOptions, activityLabel, toolActivityLabels, history, onNewChat }) {
356
- const chat = useAISDKChat();
357
- const [draft, setDraft] = useState("");
358
- const [selectedFiles, setSelectedFiles] = useState([]);
359
- const [attachmentError, setAttachmentError] = useState(null);
360
- const [attachmentPreviews, setAttachmentPreviews] = useState([]);
361
- const [hydrated, setHydrated] = useState(!history);
362
- const expectedRestoredId = useRef(null);
363
- const saveQueue = useRef(Promise.resolve());
364
- const [approvalBusy, setApprovalBusy] = useState(false);
365
- useEffect(() => {
366
- const urls = selectedFiles.map((file) => file.type.startsWith("image/") && typeof URL.createObjectURL === "function" ? URL.createObjectURL(file) : "");
367
- setAttachmentPreviews(urls);
368
- return () => urls.forEach((url) => {
369
- if (url && typeof URL.revokeObjectURL === "function") URL.revokeObjectURL(url);
370
- });
371
- }, [selectedFiles]);
372
- const messages = chat?.messages ?? [];
373
- const status = chat?.status ?? "ready";
374
- const isBusy = status === "submitted" || status === "streaming";
375
- const historyFull = messages.filter((message) => message.role === "user").length >= messageLimit;
376
- const reportHistoryError = (operation, error) => {
377
- if (history?.onError) history.onError(operation, error);
378
- else console.warn(`[Uzi AIChat] History ${operation} failed`);
379
- };
380
- useEffect(() => {
381
- if (!history) return;
382
- let active = true;
383
- Promise.resolve().then(() => history.load()).then((restored) => {
384
- if (!active) return;
385
- if (Array.isArray(restored)) {
386
- const valid = restored.filter((message) => typeof message?.id === "string" && (message.role === "user" || message.role === "assistant") && Array.isArray(message.parts));
387
- expectedRestoredId.current = valid.length ? valid[0].id : null;
388
- if (valid.length) chat?.setMessages(valid);
389
- }
390
- setHydrated(true);
391
- }).catch((error) => {
392
- if (active) {
393
- reportHistoryError("load", error);
394
- setHydrated(true);
395
- }
396
- });
397
- return () => {
398
- active = false;
399
- };
400
- }, [chat?.setMessages, history]);
401
- useEffect(() => {
402
- if (!history || !hydrated || isBusy) return;
403
- const snapshot = messages.filter((message) => message.role === "user" || message.role === "assistant").map((message) => ({
404
- id: message.id,
405
- role: message.role,
406
- parts: message.parts,
407
- ...isRecord(message.metadata) ? { metadata: message.metadata } : {}
408
- }));
409
- if (expectedRestoredId.current) {
410
- if (!snapshot.some((message) => message.id === expectedRestoredId.current)) return;
411
- expectedRestoredId.current = null;
412
- }
413
- saveQueue.current = saveQueue.current.then(() => history.save(snapshot), () => history.save(snapshot)).then(() => {}, (error) => {
414
- reportHistoryError("save", error);
415
- });
416
- }, [
417
- history,
418
- hydrated,
419
- isBusy,
420
- messages
421
- ]);
422
- const handleSelectedFiles = (files) => {
423
- if (!attachmentOptions) return;
424
- const selected = Array.from(files);
425
- if (selected.length + selectedFiles.length > (attachmentOptions.maxFiles ?? 3)) {
426
- setAttachmentError("Too many attachments.");
427
- return;
428
- }
429
- if (selected.some((file) => file.size > (attachmentOptions.maxBytesPerFile ?? 5 * 1024 * 1024))) {
430
- setAttachmentError("An attachment exceeds the size limit.");
431
- return;
432
- }
433
- const allowedTypes = attachmentOptions.accept.split(",").map((item) => item.trim());
434
- if (selected.some((file) => !allowedTypes.some((allow) => allow === file.type || allow.endsWith("/*") && file.type.startsWith(allow.slice(0, -1))))) {
435
- setAttachmentError("Unsupported attachment type.");
436
- return;
437
- }
438
- setAttachmentError(null);
439
- setSelectedFiles((existing) => [...existing, ...selected]);
440
- };
441
- const handleSubmit = () => {
442
- const text = draft.trim();
443
- if (!chat || !text && selectedFiles.length === 0 || isBusy || historyFull || chat.error || !hydrated || approvalBusy) return;
444
- const files = selectedFiles.length ? new DataTransfer() : null;
445
- selectedFiles.forEach((file) => files?.items.add(file));
446
- const previousDraft = draft;
447
- const previousFiles = selectedFiles;
448
- setDraft("");
449
- setSelectedFiles([]);
450
- setAttachmentError(null);
451
- Promise.resolve(chat.sendMessage({
452
- text,
453
- ...files ? { files: files.files } : {}
454
- })).catch(() => {
455
- setDraft((current) => current || previousDraft);
456
- setSelectedFiles((current) => current.length ? current : previousFiles);
457
- });
458
- };
459
- const handleNewChat = () => {
460
- (async () => {
461
- await chat?.stop();
462
- if (history) try {
463
- await saveQueue.current;
464
- await history.clear();
465
- } catch (error) {
466
- reportHistoryError("clear", error);
467
- return;
468
- }
469
- onNewChat();
470
- })();
471
- };
472
- const lastNewChatRequestKey = useRef(newChatRequestKey);
473
- useEffect(() => {
474
- if (lastNewChatRequestKey.current === newChatRequestKey) return;
475
- lastNewChatRequestKey.current = newChatRequestKey;
476
- handleNewChat();
477
- }, [newChatRequestKey]);
478
- const handleRetry = () => {
479
- if (!chat || isBusy) return;
480
- chat.clearError();
481
- chat.regenerate();
482
- };
483
- return /* @__PURE__ */ jsx(AIChatView, {
484
- messages: messages.filter((message) => message.role === "user" || message.role === "assistant").map((message) => ({
485
- id: message.id,
486
- role: message.role,
487
- parts: message.parts,
488
- ...isRecord(message.metadata) ? { metadata: message.metadata } : {}
489
- })),
490
- status,
491
- activityLabel,
492
- toolActivityLabels,
493
- error: chat?.error,
494
- draft,
495
- onDraftChange: setDraft,
496
- onSend: handleSubmit,
497
- onStop: () => {
498
- chat?.stop();
499
- },
500
- onRetry: handleRetry,
501
- onNewChat: handleNewChat,
502
- showNewChatInToolbar,
503
- toolbarActions,
504
- messageLimit,
505
- attachments: selectedFiles.map((file, index) => ({
506
- name: file.name,
507
- size: file.size,
508
- ...attachmentPreviews[index] ? { previewUrl: attachmentPreviews[index] } : {}
509
- })),
510
- onSelectAttachments: attachmentOptions ? handleSelectedFiles : void 0,
511
- onRemoveAttachment: attachmentOptions ? (index) => setSelectedFiles((files) => files.filter((_, i) => i !== index)) : void 0,
512
- attachmentAccept: attachmentOptions?.accept,
513
- attachmentError,
514
- onToolApproval: chat ? async (id, approved) => {
515
- if (approvalBusy) return;
516
- setApprovalBusy(true);
517
- try {
518
- await chat.addToolApprovalResponse({
519
- id,
520
- approved,
521
- ...!approved ? { reason: "User denied approval" } : {}
522
- });
523
- } finally {
524
- setApprovalBusy(false);
525
- }
526
- } : void 0,
527
- inputPlaceholder,
528
- inputAriaLabel,
529
- inputMaxLength,
530
- components
531
- });
532
- }
533
- /**
534
- * Controlled chat presentation for apps with their own AI SDK/assistant-ui
535
- * runtime. It does not create providers, transports or chat state. Callbacks
536
- * are the only way messages/actions leave the view.
537
- */
538
- function AIChatView({ messages, status = "ready", activityLabel = "Working on your response…", toolActivityLabels, 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 }) {
539
- const viewportRef = useRef(null);
540
- const pinnedToBottom = useRef(true);
541
- const fileInputRef = useRef(null);
542
- const approvalRef = useRef(null);
543
- const [pendingApprovalId, setPendingApprovalId] = useState(null);
544
- const [approvalError, setApprovalError] = useState(null);
545
- const respondToApproval = async (id, approved) => {
546
- if (!onToolApproval || approvalRef.current) return;
547
- approvalRef.current = id;
548
- setPendingApprovalId(id);
549
- setApprovalError(null);
550
- try {
551
- await onToolApproval(id, approved);
552
- } catch {
553
- setApprovalError("Could not submit approval. Please try again.");
554
- } finally {
555
- approvalRef.current = null;
556
- setPendingApprovalId(null);
557
- }
558
- };
559
- const isBusy = status === "submitted" || status === "streaming";
560
- const lastMessage = messages[messages.length - 1];
561
- const assistantParts = lastMessage?.role === "assistant" ? lastMessage.parts.filter(isRecord) : [];
562
- const lastPart = [...assistantParts].reverse().find((part) => part.type !== "step-start");
563
- const lastPartType = asString(lastPart?.type) ?? "";
564
- const activeTool = (lastPartType.startsWith("tool-") || lastPartType === "dynamic-tool") && lastPart?.state !== "output-available" && lastPart?.state !== "output-error" ? lastPart : void 0;
565
- const hasAnswer = assistantParts.some((part) => part.type === "text" && Boolean(asString(part.text)?.trim()));
566
- const showActivity = isBusy && (!hasAnswer || Boolean(activeTool));
567
- const toolName = asString(activeTool?.toolName) ?? lastPartType.replace(/^tool-/, "");
568
- const currentActivityLabel = activeTool?.state === "approval-requested" ? "Waiting for approval…" : activeTool ? toolActivityLabels?.[toolName] ?? "Using a tool…" : activityLabel;
569
- const limit = messageLimit != null && Number.isFinite(messageLimit) ? Math.max(1, Math.floor(messageLimit)) : null;
570
- const historyFull = limit !== null && messages.filter((message) => message.role === "user").length >= limit;
571
- const MessageRenderer = components?.MessageRenderer ?? DefaultMessageRenderer;
572
- const ErrorRenderer = components?.ErrorRenderer ?? DefaultErrorRenderer;
573
- useEffect(() => {
574
- const viewport = viewportRef.current;
575
- if (viewport && pinnedToBottom.current) viewport.scrollTop = viewport.scrollHeight;
576
- });
577
- const handleKeyDown = (event) => {
578
- if (event.key === "Enter" && !event.shiftKey && !event.nativeEvent.isComposing) {
579
- event.preventDefault();
580
- if (!isBusy && !historyFull && !error && (draft.trim() || (attachments?.length ?? 0) > 0)) onSend?.();
581
- }
582
- };
583
- const handleFormSubmit = (event) => {
584
- event.preventDefault();
585
- if (!isBusy && !historyFull && !error && (draft.trim() || (attachments?.length ?? 0) > 0)) onSend?.();
586
- };
587
- return /* @__PURE__ */ jsxs("div", {
588
- className: [ai_chat_module_default.thread, className].filter(Boolean).join(" "),
589
- style,
590
- children: [
591
- header,
592
- (toolbarActions || showNewChatInToolbar && onNewChat && messages.length > 0) && /* @__PURE__ */ jsxs("div", {
593
- className: ai_chat_module_default.chatToolbar,
594
- role: "toolbar",
595
- "aria-label": "Conversation actions",
596
- children: [/* @__PURE__ */ jsx("div", {
597
- className: ai_chat_module_default.chatToolbarExtras,
598
- children: toolbarActions
599
- }), showNewChatInToolbar && onNewChat && messages.length > 0 && /* @__PURE__ */ jsx("button", {
600
- type: "button",
601
- className: ai_chat_module_default.newChatButton,
602
- onClick: onNewChat,
603
- "aria-label": "New chat",
604
- title: "New chat",
605
- children: /* @__PURE__ */ jsxs("svg", {
606
- "aria-hidden": "true",
607
- width: "18",
608
- height: "18",
609
- viewBox: "0 0 24 24",
610
- fill: "none",
611
- stroke: "currentColor",
612
- strokeWidth: "1.8",
613
- strokeLinecap: "round",
614
- strokeLinejoin: "round",
615
- children: [/* @__PURE__ */ jsx("path", { d: "M12 5H6a2 2 0 0 0-2 2v11a2 2 0 0 0 2 2h11a2 2 0 0 0 2-2v-6" }), /* @__PURE__ */ jsx("path", {
616
- d: "m15 5 4 4M13 11l7-7a2.12 2.12 0 0 1 3 3l-7 7-4 1 1-4Z",
617
- transform: "translate(-2 -2)"
618
- })]
619
- })
620
- })]
621
- }),
622
- /* @__PURE__ */ jsx("div", {
623
- ref: viewportRef,
624
- className: ai_chat_module_default.viewport,
625
- onScroll: (event) => {
626
- const viewport = event.currentTarget;
627
- pinnedToBottom.current = viewport.scrollHeight - viewport.scrollTop - viewport.clientHeight < 80;
628
- },
629
- children: /* @__PURE__ */ jsxs("div", {
630
- className: ai_chat_module_default.messageList,
631
- role: "log",
632
- "aria-label": "Chat history",
633
- "aria-live": "polite",
634
- children: [
635
- messages.length === 0 && /* @__PURE__ */ jsx("div", {
636
- className: ai_chat_module_default.emptyState,
637
- children: emptyState ?? /* @__PURE__ */ jsx("p", { children: "Start a conversation" })
638
- }),
639
- messages.map((message) => /* @__PURE__ */ jsx(MessageRenderer, {
640
- message,
641
- renderMessagePart: (part, index) => renderPart(part, index, components, onToolApproval ? respondToApproval : void 0, pendingApprovalId),
642
- onToolApproval: onToolApproval ? respondToApproval : void 0
643
- }, message.id)),
644
- showActivity && /* @__PURE__ */ jsxs("div", {
645
- className: ai_chat_module_default.activityBubble,
646
- role: "status",
647
- "aria-label": currentActivityLabel,
648
- children: [/* @__PURE__ */ jsxs("span", {
649
- className: ai_chat_module_default.activityDots,
650
- "aria-hidden": "true",
651
- children: [
652
- /* @__PURE__ */ jsx("i", {}),
653
- /* @__PURE__ */ jsx("i", {}),
654
- /* @__PURE__ */ jsx("i", {})
655
- ]
656
- }), /* @__PURE__ */ jsx("span", { children: currentActivityLabel })]
657
- })
658
- ]
659
- })
660
- }),
661
- /* @__PURE__ */ jsxs("div", {
662
- className: ai_chat_module_default.footer,
663
- children: [
664
- approvalError && /* @__PURE__ */ jsx("p", {
665
- role: "alert",
666
- className: ai_chat_module_default.attachmentError,
667
- children: approvalError
668
- }),
669
- attachmentError && /* @__PURE__ */ jsx("p", {
670
- role: "alert",
671
- className: ai_chat_module_default.attachmentError,
672
- children: attachmentError
673
- }),
674
- error && (onRetry && onNewChat ? /* @__PURE__ */ jsx(ErrorRenderer, {
675
- error,
676
- onRetry,
677
- onClear: onNewChat
678
- }) : /* @__PURE__ */ jsxs("div", {
679
- className: ai_chat_module_default.error,
680
- role: "alert",
681
- children: [/* @__PURE__ */ jsx("p", { children: error.message }), (onRetry || onNewChat) && /* @__PURE__ */ jsxs("div", {
682
- className: ai_chat_module_default.errorActions,
683
- children: [onRetry && /* @__PURE__ */ jsx("button", {
684
- type: "button",
685
- onClick: onRetry,
686
- children: "Retry response"
687
- }), onNewChat && /* @__PURE__ */ jsx("button", {
688
- type: "button",
689
- onClick: onNewChat,
690
- children: "Start new chat"
691
- })]
692
- })]
693
- })),
694
- historyFull && !error && !isBusy && onNewChat && /* @__PURE__ */ jsxs("div", {
695
- className: ai_chat_module_default.historyLimit,
696
- children: [/* @__PURE__ */ jsxs("span", { children: [
697
- "This chat has reached its ",
698
- limit,
699
- "-question limit."
700
- ] }), /* @__PURE__ */ jsx("button", {
701
- type: "button",
702
- onClick: onNewChat,
703
- children: "Start new chat"
704
- })]
705
- }),
706
- (!historyFull || isBusy) && !error && (composer !== void 0 ? composer : /* @__PURE__ */ jsxs("form", {
707
- className: ai_chat_module_default.composerForm,
708
- onSubmit: handleFormSubmit,
709
- children: [
710
- composerLeading && /* @__PURE__ */ jsx("div", {
711
- className: ai_chat_module_default.composerExtras,
712
- children: composerLeading
713
- }),
714
- onSelectAttachments && /* @__PURE__ */ jsx("input", {
715
- ref: fileInputRef,
716
- className: ai_chat_module_default.visuallyHidden,
717
- type: "file",
718
- "aria-label": "Add attachments",
719
- accept: attachmentAccept,
720
- multiple: true,
721
- disabled: isBusy,
722
- onChange: (event) => {
723
- if (event.target.files) onSelectAttachments(event.target.files);
724
- event.target.value = "";
725
- }
726
- }),
727
- attachments && attachments.length > 0 && /* @__PURE__ */ jsx("div", {
728
- className: ai_chat_module_default.composerExtras,
729
- children: /* @__PURE__ */ jsx("ul", {
730
- className: ai_chat_module_default.attachmentList,
731
- "aria-label": "Attached files",
732
- children: attachments.map((attachment, index) => /* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsx(AIChatAttachmentPreview, {
733
- name: attachment.name,
734
- size: attachment.size,
735
- staged: true,
736
- imageUrl: attachment.previewUrl,
737
- onRemove: onRemoveAttachment ? () => onRemoveAttachment(index) : void 0
738
- }) }, index))
739
- })
740
- }),
741
- /* @__PURE__ */ jsx("div", {
742
- className: ai_chat_module_default.composerSurface,
743
- children: /* @__PURE__ */ jsxs("div", {
744
- className: ai_chat_module_default.composerRow,
745
- children: [
746
- onSelectAttachments && /* @__PURE__ */ jsx("button", {
747
- type: "button",
748
- className: ai_chat_module_default.composerIconButton,
749
- "aria-label": "Attach file",
750
- title: "Attach file",
751
- disabled: isBusy,
752
- onClick: () => fileInputRef.current?.click(),
753
- children: /* @__PURE__ */ jsx("svg", {
754
- width: "20",
755
- height: "20",
756
- viewBox: "0 0 24 24",
757
- fill: "none",
758
- stroke: "currentColor",
759
- strokeWidth: "1.8",
760
- strokeLinecap: "round",
761
- strokeLinejoin: "round",
762
- "aria-hidden": "true",
763
- children: /* @__PURE__ */ jsx("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" })
764
- })
765
- }),
766
- /* @__PURE__ */ jsx("textarea", {
767
- className: ai_chat_module_default.input,
768
- "aria-label": inputAriaLabel,
769
- rows: 1,
770
- value: draft,
771
- onChange: (event) => onDraftChange?.(event.target.value),
772
- onKeyDown: handleKeyDown,
773
- placeholder: inputPlaceholder,
774
- maxLength: inputMaxLength,
775
- disabled: isBusy || !onSend || !onDraftChange,
776
- readOnly: !onDraftChange
777
- }),
778
- /* @__PURE__ */ jsxs("div", {
779
- className: ai_chat_module_default.composerActions,
780
- children: [composerTrailing, isBusy ? onStop && /* @__PURE__ */ jsx("button", {
781
- type: "button",
782
- className: ai_chat_module_default.composerIconButton,
783
- onClick: onStop,
784
- "aria-label": "Stop response",
785
- title: "Stop response",
786
- children: /* @__PURE__ */ jsx("svg", {
787
- width: "18",
788
- height: "18",
789
- viewBox: "0 0 24 24",
790
- fill: "currentColor",
791
- "aria-hidden": "true",
792
- children: /* @__PURE__ */ jsx("rect", {
793
- x: "5",
794
- y: "5",
795
- width: "14",
796
- height: "14",
797
- rx: "2"
798
- })
799
- })
800
- }) : /* @__PURE__ */ jsx("button", {
801
- type: "submit",
802
- className: ai_chat_module_default.sendButton,
803
- "aria-label": "Send message",
804
- title: "Send message",
805
- disabled: !onSend || !draft.trim() && !attachments?.length,
806
- children: /* @__PURE__ */ jsx("svg", {
807
- width: "20",
808
- height: "20",
809
- viewBox: "0 0 24 24",
810
- fill: "none",
811
- stroke: "currentColor",
812
- strokeWidth: "2",
813
- strokeLinecap: "round",
814
- strokeLinejoin: "round",
815
- "aria-hidden": "true",
816
- children: /* @__PURE__ */ jsx("path", { d: "M12 19V5m-7 7 7-7 7 7" })
817
- })
818
- })]
819
- })
820
- ]
821
- })
822
- })
823
- ]
824
- }))
825
- ]
826
- })
827
- ]
828
- });
829
- }
830
276
  //#endregion
831
- export { AIChat, AIChatAttachmentPreview, AIChatMessageBubble, AIChatView };
277
+ export { AIChatAttachmentPreview, AIChatMessageBubble, DefaultErrorRenderer, DefaultMessageRenderer, asString, isRecord, renderPart };
832
278
 
833
279
  //# sourceMappingURL=index84.js.map