@devicai/ui 0.57.0 → 0.59.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +186 -0
- package/dist/cjs/api/assistantInfo.js.map +1 -1
- package/dist/cjs/api/client.js +17 -1
- package/dist/cjs/api/client.js.map +1 -1
- package/dist/cjs/api/types.js.map +1 -1
- package/dist/cjs/components/AICommandBar/AICommandBar.js +12 -8
- package/dist/cjs/components/AICommandBar/AICommandBar.js.map +1 -1
- package/dist/cjs/components/AICommandBar/useAICommandBar.js +12 -6
- package/dist/cjs/components/AICommandBar/useAICommandBar.js.map +1 -1
- package/dist/cjs/components/AIElementWrapper/AIElementWrapper.js +19 -15
- package/dist/cjs/components/AIElementWrapper/AIElementWrapper.js.map +1 -1
- package/dist/cjs/components/AIElementWrapper/activeWrapperRegistry.js.map +1 -1
- package/dist/cjs/components/AIElementWrapper/useAIElementWrapper.js +12 -6
- package/dist/cjs/components/AIElementWrapper/useAIElementWrapper.js.map +1 -1
- package/dist/cjs/components/AIGenerationButton/AIGenerationButton.js +13 -7
- package/dist/cjs/components/AIGenerationButton/AIGenerationButton.js.map +1 -1
- package/dist/cjs/components/AIGenerationButton/useAIGenerationButton.js +11 -5
- package/dist/cjs/components/AIGenerationButton/useAIGenerationButton.js.map +1 -1
- package/dist/cjs/components/ChatDrawer/ChatDrawer.js +28 -13
- package/dist/cjs/components/ChatDrawer/ChatDrawer.js.map +1 -1
- package/dist/cjs/components/ChatDrawer/ChatInput.js +21 -15
- package/dist/cjs/components/ChatDrawer/ChatInput.js.map +1 -1
- package/dist/cjs/components/ChatDrawer/ChatMessages.js +54 -13
- package/dist/cjs/components/ChatDrawer/ChatMessages.js.map +1 -1
- package/dist/cjs/components/ChatDrawer/CompactionWidget.js +13 -4
- package/dist/cjs/components/ChatDrawer/CompactionWidget.js.map +1 -1
- package/dist/cjs/components/ChatDrawer/ConversationSelector.js +6 -4
- package/dist/cjs/components/ChatDrawer/ConversationSelector.js.map +1 -1
- package/dist/cjs/components/ChatDrawer/ErrorBoundary.js.map +1 -1
- package/dist/cjs/components/ChatDrawer/GuardrailNotice.js +40 -0
- package/dist/cjs/components/ChatDrawer/GuardrailNotice.js.map +1 -0
- package/dist/cjs/components/ChatDrawer/HandoffSubagentWidget.js +3 -1
- package/dist/cjs/components/ChatDrawer/HandoffSubagentWidget.js.map +1 -1
- package/dist/cjs/components/ChatDrawer/LimitBanner.js +19 -9
- package/dist/cjs/components/ChatDrawer/LimitBanner.js.map +1 -1
- package/dist/cjs/components/ChatDrawer/QueueNotice.js +19 -7
- package/dist/cjs/components/ChatDrawer/QueueNotice.js.map +1 -1
- package/dist/cjs/components/ChatDrawer/RecalledMemoriesWidget.js +17 -5
- package/dist/cjs/components/ChatDrawer/RecalledMemoriesWidget.js.map +1 -1
- package/dist/cjs/components/ChatDrawer/ReferenceChip.js +3 -1
- package/dist/cjs/components/ChatDrawer/ReferenceChip.js.map +1 -1
- package/dist/cjs/components/ChatDrawer/ToolTimeline.js.map +1 -1
- package/dist/cjs/components/ChatDrawer/UsageBar.js +23 -18
- package/dist/cjs/components/ChatDrawer/UsageBar.js.map +1 -1
- package/dist/cjs/components/ChatDrawer/pastedText.js.map +1 -1
- package/dist/cjs/components/CoreMemoryModal/CoreMemoryModal.js +20 -9
- package/dist/cjs/components/CoreMemoryModal/CoreMemoryModal.js.map +1 -1
- package/dist/cjs/components/Feedback/FeedbackModal.js +5 -1
- package/dist/cjs/components/Feedback/FeedbackModal.js.map +1 -1
- package/dist/cjs/components/Feedback/MessageActions.js +3 -1
- package/dist/cjs/components/Feedback/MessageActions.js.map +1 -1
- package/dist/cjs/components/IntegrationsModal/ConnectFieldsForm.js +12 -8
- package/dist/cjs/components/IntegrationsModal/ConnectFieldsForm.js.map +1 -1
- package/dist/cjs/components/IntegrationsModal/IntegrationLogo.js.map +1 -1
- package/dist/cjs/components/IntegrationsModal/IntegrationsHint.js +5 -3
- package/dist/cjs/components/IntegrationsModal/IntegrationsHint.js.map +1 -1
- package/dist/cjs/components/IntegrationsModal/IntegrationsLauncher.js +12 -3
- package/dist/cjs/components/IntegrationsModal/IntegrationsLauncher.js.map +1 -1
- package/dist/cjs/components/IntegrationsModal/IntegrationsModal.js.map +1 -1
- package/dist/cjs/components/IntegrationsModal/IntegrationsPanel.js +34 -24
- package/dist/cjs/components/IntegrationsModal/IntegrationsPanel.js.map +1 -1
- package/dist/cjs/components/IntegrationsModal/IntegrationsToggle.js +15 -6
- package/dist/cjs/components/IntegrationsModal/IntegrationsToggle.js.map +1 -1
- package/dist/cjs/components/IntegrationsModal/McpConnectForm.js +15 -7
- package/dist/cjs/components/IntegrationsModal/McpConnectForm.js.map +1 -1
- package/dist/cjs/components/IntegrationsModal/McpServersSection.js +32 -19
- package/dist/cjs/components/IntegrationsModal/McpServersSection.js.map +1 -1
- package/dist/cjs/components/IntegrationsModal/integrationChoice.js.map +1 -1
- package/dist/cjs/components/IntegrationsModal/useIntegrations.js +3 -1
- package/dist/cjs/components/IntegrationsModal/useIntegrations.js.map +1 -1
- package/dist/cjs/components/IntegrationsModal/useTenantMcp.js +3 -1
- package/dist/cjs/components/IntegrationsModal/useTenantMcp.js.map +1 -1
- package/dist/cjs/components/ThreadStateTag/ThreadStateTag.js +63 -40
- package/dist/cjs/components/ThreadStateTag/ThreadStateTag.js.map +1 -1
- package/dist/cjs/components/theme.js.map +1 -1
- package/dist/cjs/hooks/useDevicChat.js +21 -7
- package/dist/cjs/hooks/useDevicChat.js.map +1 -1
- package/dist/cjs/hooks/useModelInterface.js.map +1 -1
- package/dist/cjs/hooks/usePolling.js +117 -7
- package/dist/cjs/hooks/usePolling.js.map +1 -1
- package/dist/cjs/hooks/useSpeechRecording.js +8 -4
- package/dist/cjs/hooks/useSpeechRecording.js.map +1 -1
- package/dist/cjs/i18n/translate.js +48 -0
- package/dist/cjs/i18n/translate.js.map +1 -0
- package/dist/cjs/i18n/useTranslations.js +57 -0
- package/dist/cjs/i18n/useTranslations.js.map +1 -0
- package/dist/cjs/index.js +11 -0
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/provider/DevicContext.js.map +1 -1
- package/dist/cjs/provider/DevicProvider.js +5 -1
- package/dist/cjs/provider/DevicProvider.js.map +1 -1
- package/dist/cjs/provider/sharedSession.js.map +1 -1
- package/dist/cjs/styles.css +1 -1
- package/dist/cjs/utils/avatar.js.map +1 -1
- package/dist/cjs/utils/consumeChatStream.js +44 -0
- package/dist/cjs/utils/consumeChatStream.js.map +1 -0
- package/dist/cjs/utils/index.js.map +1 -1
- package/dist/cjs/utils/logger.js.map +1 -1
- package/dist/cjs/utils/toolGroups.js.map +1 -1
- package/dist/esm/api/assistantInfo.js.map +1 -1
- package/dist/esm/api/client.d.ts +5 -1
- package/dist/esm/api/client.js +17 -1
- package/dist/esm/api/client.js.map +1 -1
- package/dist/esm/api/types.d.ts +12 -1
- package/dist/esm/api/types.js.map +1 -1
- package/dist/esm/components/AICommandBar/AICommandBar.js +13 -9
- package/dist/esm/components/AICommandBar/AICommandBar.js.map +1 -1
- package/dist/esm/components/AICommandBar/AICommandBar.types.d.ts +16 -0
- package/dist/esm/components/AICommandBar/useAICommandBar.d.ts +2 -0
- package/dist/esm/components/AICommandBar/useAICommandBar.js +13 -7
- package/dist/esm/components/AICommandBar/useAICommandBar.js.map +1 -1
- package/dist/esm/components/AIElementWrapper/AIElementWrapper.js +19 -15
- package/dist/esm/components/AIElementWrapper/AIElementWrapper.js.map +1 -1
- package/dist/esm/components/AIElementWrapper/AIElementWrapper.types.d.ts +16 -0
- package/dist/esm/components/AIElementWrapper/activeWrapperRegistry.js.map +1 -1
- package/dist/esm/components/AIElementWrapper/useAIElementWrapper.d.ts +2 -0
- package/dist/esm/components/AIElementWrapper/useAIElementWrapper.js +13 -7
- package/dist/esm/components/AIElementWrapper/useAIElementWrapper.js.map +1 -1
- package/dist/esm/components/AIGenerationButton/AIGenerationButton.js +14 -8
- package/dist/esm/components/AIGenerationButton/AIGenerationButton.js.map +1 -1
- package/dist/esm/components/AIGenerationButton/AIGenerationButton.types.d.ts +16 -0
- package/dist/esm/components/AIGenerationButton/useAIGenerationButton.d.ts +2 -0
- package/dist/esm/components/AIGenerationButton/useAIGenerationButton.js +12 -6
- package/dist/esm/components/AIGenerationButton/useAIGenerationButton.js.map +1 -1
- package/dist/esm/components/ChatDrawer/ChatDrawer.js +29 -14
- package/dist/esm/components/ChatDrawer/ChatDrawer.js.map +1 -1
- package/dist/esm/components/ChatDrawer/ChatDrawer.types.d.ts +41 -0
- package/dist/esm/components/ChatDrawer/ChatInput.js +21 -15
- package/dist/esm/components/ChatDrawer/ChatInput.js.map +1 -1
- package/dist/esm/components/ChatDrawer/ChatMessages.d.ts +1 -1
- package/dist/esm/components/ChatDrawer/ChatMessages.js +54 -13
- package/dist/esm/components/ChatDrawer/ChatMessages.js.map +1 -1
- package/dist/esm/components/ChatDrawer/CompactionWidget.js +13 -4
- package/dist/esm/components/ChatDrawer/CompactionWidget.js.map +1 -1
- package/dist/esm/components/ChatDrawer/ConversationSelector.js +6 -4
- package/dist/esm/components/ChatDrawer/ConversationSelector.js.map +1 -1
- package/dist/esm/components/ChatDrawer/ErrorBoundary.js.map +1 -1
- package/dist/esm/components/ChatDrawer/GuardrailNotice.d.ts +36 -0
- package/dist/esm/components/ChatDrawer/GuardrailNotice.js +38 -0
- package/dist/esm/components/ChatDrawer/GuardrailNotice.js.map +1 -0
- package/dist/esm/components/ChatDrawer/HandoffSubagentWidget.js +3 -1
- package/dist/esm/components/ChatDrawer/HandoffSubagentWidget.js.map +1 -1
- package/dist/esm/components/ChatDrawer/LimitBanner.js +19 -9
- package/dist/esm/components/ChatDrawer/LimitBanner.js.map +1 -1
- package/dist/esm/components/ChatDrawer/QueueNotice.js +19 -7
- package/dist/esm/components/ChatDrawer/QueueNotice.js.map +1 -1
- package/dist/esm/components/ChatDrawer/RecalledMemoriesWidget.js +17 -5
- package/dist/esm/components/ChatDrawer/RecalledMemoriesWidget.js.map +1 -1
- package/dist/esm/components/ChatDrawer/ReferenceChip.js +3 -1
- package/dist/esm/components/ChatDrawer/ReferenceChip.js.map +1 -1
- package/dist/esm/components/ChatDrawer/ToolTimeline.js.map +1 -1
- package/dist/esm/components/ChatDrawer/UsageBar.js +23 -18
- package/dist/esm/components/ChatDrawer/UsageBar.js.map +1 -1
- package/dist/esm/components/ChatDrawer/index.d.ts +2 -0
- package/dist/esm/components/ChatDrawer/pastedText.js.map +1 -1
- package/dist/esm/components/CoreMemoryModal/CoreMemoryModal.js +20 -9
- package/dist/esm/components/CoreMemoryModal/CoreMemoryModal.js.map +1 -1
- package/dist/esm/components/Feedback/FeedbackModal.js +5 -1
- package/dist/esm/components/Feedback/FeedbackModal.js.map +1 -1
- package/dist/esm/components/Feedback/MessageActions.js +3 -1
- package/dist/esm/components/Feedback/MessageActions.js.map +1 -1
- package/dist/esm/components/IntegrationsModal/ConnectFieldsForm.js +12 -8
- package/dist/esm/components/IntegrationsModal/ConnectFieldsForm.js.map +1 -1
- package/dist/esm/components/IntegrationsModal/IntegrationLogo.js.map +1 -1
- package/dist/esm/components/IntegrationsModal/IntegrationsHint.js +5 -3
- package/dist/esm/components/IntegrationsModal/IntegrationsHint.js.map +1 -1
- package/dist/esm/components/IntegrationsModal/IntegrationsLauncher.js +12 -3
- package/dist/esm/components/IntegrationsModal/IntegrationsLauncher.js.map +1 -1
- package/dist/esm/components/IntegrationsModal/IntegrationsModal.js.map +1 -1
- package/dist/esm/components/IntegrationsModal/IntegrationsPanel.d.ts +1 -1
- package/dist/esm/components/IntegrationsModal/IntegrationsPanel.js +34 -24
- package/dist/esm/components/IntegrationsModal/IntegrationsPanel.js.map +1 -1
- package/dist/esm/components/IntegrationsModal/IntegrationsToggle.d.ts +1 -1
- package/dist/esm/components/IntegrationsModal/IntegrationsToggle.js +15 -6
- package/dist/esm/components/IntegrationsModal/IntegrationsToggle.js.map +1 -1
- package/dist/esm/components/IntegrationsModal/McpConnectForm.js +15 -7
- package/dist/esm/components/IntegrationsModal/McpConnectForm.js.map +1 -1
- package/dist/esm/components/IntegrationsModal/McpServersSection.js +32 -19
- package/dist/esm/components/IntegrationsModal/McpServersSection.js.map +1 -1
- package/dist/esm/components/IntegrationsModal/integrationChoice.js.map +1 -1
- package/dist/esm/components/IntegrationsModal/useIntegrations.js +3 -1
- package/dist/esm/components/IntegrationsModal/useIntegrations.js.map +1 -1
- package/dist/esm/components/IntegrationsModal/useTenantMcp.js +3 -1
- package/dist/esm/components/IntegrationsModal/useTenantMcp.js.map +1 -1
- package/dist/esm/components/ThreadStateTag/ThreadStateTag.js +63 -40
- package/dist/esm/components/ThreadStateTag/ThreadStateTag.js.map +1 -1
- package/dist/esm/components/theme.js.map +1 -1
- package/dist/esm/hooks/index.d.ts +1 -1
- package/dist/esm/hooks/useDevicChat.d.ts +6 -0
- package/dist/esm/hooks/useDevicChat.js +23 -9
- package/dist/esm/hooks/useDevicChat.js.map +1 -1
- package/dist/esm/hooks/useModelInterface.js.map +1 -1
- package/dist/esm/hooks/usePolling.d.ts +35 -0
- package/dist/esm/hooks/usePolling.js +114 -8
- package/dist/esm/hooks/usePolling.js.map +1 -1
- package/dist/esm/hooks/useSpeechRecording.js +8 -4
- package/dist/esm/hooks/useSpeechRecording.js.map +1 -1
- package/dist/esm/i18n/index.d.ts +4 -0
- package/dist/esm/i18n/translate.d.ts +23 -0
- package/dist/esm/i18n/translate.js +43 -0
- package/dist/esm/i18n/translate.js.map +1 -0
- package/dist/esm/i18n/types.d.ts +27 -0
- package/dist/esm/i18n/useTranslations.d.ts +32 -0
- package/dist/esm/i18n/useTranslations.js +53 -0
- package/dist/esm/i18n/useTranslations.js.map +1 -0
- package/dist/esm/index.d.ts +4 -2
- package/dist/esm/index.js +3 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/provider/DevicContext.js.map +1 -1
- package/dist/esm/provider/DevicProvider.d.ts +1 -1
- package/dist/esm/provider/DevicProvider.js +5 -1
- package/dist/esm/provider/DevicProvider.js.map +1 -1
- package/dist/esm/provider/sharedSession.js.map +1 -1
- package/dist/esm/provider/types.d.ts +51 -0
- package/dist/esm/styles.css +1 -1
- package/dist/esm/utils/avatar.js.map +1 -1
- package/dist/esm/utils/consumeChatStream.d.ts +6 -0
- package/dist/esm/utils/consumeChatStream.js +42 -0
- package/dist/esm/utils/consumeChatStream.js.map +1 -0
- package/dist/esm/utils/index.js.map +1 -1
- package/dist/esm/utils/logger.js.map +1 -1
- package/dist/esm/utils/toolGroups.js.map +1 -1
- package/package.json +3 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"QueueNotice.js","sources":["../../../../../src/components/ChatDrawer/QueueNotice.tsx"],"sourcesContent":["import React from 'react';\nimport type { QueueDisposition } from '../../api/types';\n\nexport interface QueueNoticeProps {\n /** How many messages are waiting on this conversation right now. */\n queuedCount: number;\n /** What the last accepted message was told. Shapes the wording. */\n willProcess?: QueueDisposition;\n /**\n * Something happened to a message that the count alone does not explain — it\n * was turned down, or a stop threw it away. Replaces the standing text while\n * it is set, since it is the more urgent of the two.\n */\n alert?: string;\n}\n\n/**\n * The line above the input that says what happens to a message written while\n * the assistant is working.\n *\n * Writing into a conversation that is busy is allowed but not obvious, so it is\n * spelled out twice: before sending, what the button will do; after, what became\n * of it. Suppress it with `options.hideQueueNotice`, or replace it with\n * `options.queueNoticeRenderer`.\n */\nexport function QueueNotice({\n queuedCount,\n willProcess,\n alert,\n}: QueueNoticeProps): JSX.Element {\n return (\n <div\n className=\"devic-queue-notice\"\n data-alert={alert ? 'true' : undefined}\n role={alert ? 'alert' : 'status'}\n >\n <span className=\"devic-queue-notice-icon\" aria-hidden=\"true\">\n {alert ? <WarningIcon /> : <ClockIcon />}\n </span>\n <span>{alert || noticeText(queuedCount, willProcess)}</span>\n </div>\n );\n}\n\n/**\n * Three different promises, so three different sentences.\n *\n * `after_delay` is the one that is easy to get wrong: an assistant with an input\n * delay queues what is written while the conversation is *idle*, waiting for the\n * sender to finish. Telling that person the assistant will pick it up \"on its\n * next turn\" describes a turn that is not happening.\n */\nfunction noticeText(\n queuedCount: number,\n willProcess?: QueueDisposition\n): string {\n if (queuedCount <= 0) {\n return 'The assistant is still answering. Send anyway and your message joins its next turn.';\n }\n\n
|
|
1
|
+
{"version":3,"file":"QueueNotice.js","sources":["../../../../../src/components/ChatDrawer/QueueNotice.tsx"],"sourcesContent":["import React from 'react';\nimport type { QueueDisposition } from '../../api/types';\nimport { useTranslations } from '../../i18n';\nimport type { Translator } from '../../i18n';\n\nexport interface QueueNoticeProps {\n /** How many messages are waiting on this conversation right now. */\n queuedCount: number;\n /** What the last accepted message was told. Shapes the wording. */\n willProcess?: QueueDisposition;\n /**\n * Something happened to a message that the count alone does not explain — it\n * was turned down, or a stop threw it away. Replaces the standing text while\n * it is set, since it is the more urgent of the two.\n */\n alert?: string;\n}\n\n/**\n * The line above the input that says what happens to a message written while\n * the assistant is working.\n *\n * Writing into a conversation that is busy is allowed but not obvious, so it is\n * spelled out twice: before sending, what the button will do; after, what became\n * of it. Suppress it with `options.hideQueueNotice`, or replace it with\n * `options.queueNoticeRenderer`.\n */\nexport function QueueNotice({\n queuedCount,\n willProcess,\n alert,\n}: QueueNoticeProps): JSX.Element {\n const t = useTranslations();\n return (\n <div\n className=\"devic-queue-notice\"\n data-alert={alert ? 'true' : undefined}\n role={alert ? 'alert' : 'status'}\n >\n <span className=\"devic-queue-notice-icon\" aria-hidden=\"true\">\n {alert ? <WarningIcon /> : <ClockIcon />}\n </span>\n <span>{alert || noticeText(t, queuedCount, willProcess)}</span>\n </div>\n );\n}\n\n/**\n * Three different promises, so three different sentences.\n *\n * `after_delay` is the one that is easy to get wrong: an assistant with an input\n * delay queues what is written while the conversation is *idle*, waiting for the\n * sender to finish. Telling that person the assistant will pick it up \"on its\n * next turn\" describes a turn that is not happening.\n */\nfunction noticeText(\n t: Translator,\n queuedCount: number,\n willProcess?: QueueDisposition\n): string {\n if (queuedCount <= 0) {\n return t(\n 'The assistant is still answering. Send anyway and your message joins its next turn.'\n );\n }\n\n // Singular and plural are separate entries rather than a placeholder over a\n // suffix: the two differ by more than an \"s\" in most languages.\n const one = queuedCount === 1;\n\n if (willProcess === 'after_delay') {\n return one\n ? t(\n '1 message waiting — the assistant is giving you a moment to finish before it answers.'\n )\n : t(\n '{count} messages waiting — the assistant is giving you a moment to finish before it answers.',\n { count: queuedCount }\n );\n }\n if (willProcess === 'on_resume') {\n return one\n ? t(\n '1 message waiting — the assistant picks it up when it comes back to this conversation.'\n )\n : t(\n '{count} messages waiting — the assistant picks them up when it comes back to this conversation.',\n { count: queuedCount }\n );\n }\n return one\n ? t('1 message waiting — the assistant picks it up on its next turn.')\n : t('{count} messages waiting — the assistant picks them up on its next turn.', {\n count: queuedCount,\n });\n}\n\nfunction WarningIcon(): JSX.Element {\n return (\n <svg\n width=\"14\"\n height=\"14\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"2\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n >\n <path d=\"M10.29 3.86 1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z\" />\n <line x1=\"12\" y1=\"9\" x2=\"12\" y2=\"13\" />\n <line x1=\"12\" y1=\"17\" x2=\"12.01\" y2=\"17\" />\n </svg>\n );\n}\n\nfunction ClockIcon(): JSX.Element {\n return (\n <svg\n width=\"14\"\n height=\"14\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"2\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n >\n <circle cx=\"12\" cy=\"12\" r=\"9\" />\n <polyline points=\"12 7 12 12 15 14\" />\n </svg>\n );\n}\n"],"names":["useTranslations","_jsxs","_jsx"],"mappings":";;;;;AAkBA;;;;;;;;AAQG;AACG,SAAU,WAAW,CAAC,EAC1B,WAAW,EACX,WAAW,EACX,KAAK,GACY,EAAA;AACjB,IAAA,MAA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5
|
+
var useTranslations = require('../../i18n/useTranslations.js');
|
|
5
6
|
|
|
6
7
|
const SOURCE_LABELS = {
|
|
7
8
|
conversation_start: "Automatic recall",
|
|
@@ -49,6 +50,7 @@ function ChevronIcon({ up }) {
|
|
|
49
50
|
* Renders nothing when the records carry no content.
|
|
50
51
|
*/
|
|
51
52
|
function RecalledMemoriesWidget({ records, isLoading = false, renderer, }) {
|
|
53
|
+
const t = useTranslations.useTranslations();
|
|
52
54
|
const [expanded, setExpanded] = React.useState(false);
|
|
53
55
|
if (renderer) {
|
|
54
56
|
return jsxRuntime.jsx(jsxRuntime.Fragment, { children: renderer({ records, isLoading }) });
|
|
@@ -58,19 +60,29 @@ function RecalledMemoriesWidget({ records, isLoading = false, renderer, }) {
|
|
|
58
60
|
const turns = records
|
|
59
61
|
.filter((r) => r.source === "conversation_start")
|
|
60
62
|
.flatMap((r) => r.turns ?? []);
|
|
61
|
-
const sources = [
|
|
63
|
+
const sources = [
|
|
64
|
+
...new Set(records.map((r) => t(SOURCE_LABELS[r.source]))),
|
|
65
|
+
];
|
|
62
66
|
if (!facts.length && !entities.length && !turns.length)
|
|
63
67
|
return null;
|
|
64
68
|
const summaryParts = [];
|
|
65
69
|
if (facts.length) {
|
|
66
|
-
summaryParts.push(
|
|
70
|
+
summaryParts.push(facts.length === 1
|
|
71
|
+
? t("1 fact")
|
|
72
|
+
: t("{count} facts", { count: facts.length }));
|
|
67
73
|
}
|
|
68
74
|
if (entities.length) {
|
|
69
|
-
summaryParts.push(
|
|
75
|
+
summaryParts.push(entities.length === 1
|
|
76
|
+
? t("1 entity")
|
|
77
|
+
: t("{count} entities", { count: entities.length }));
|
|
70
78
|
}
|
|
71
|
-
return (jsxRuntime.jsxs("div", { className: "devic-recall", children: [jsxRuntime.jsxs("button", { type: "button", className: "devic-recall-header", onClick: () => setExpanded((v) => !v), "aria-expanded": expanded, children: [jsxRuntime.jsx(BrainIcon, {}), jsxRuntime.jsx("span", { className: "devic-recall-title", children: "Recalled memories" }), summaryParts.length > 0 && (jsxRuntime.jsx("span", { className: "devic-recall-summary", children: summaryParts.join(" · ") })), jsxRuntime.jsx("span", { className: "devic-recall-spacer" }), sources.map((s) => (jsxRuntime.jsx("span", { className: "devic-recall-source", children: s }, s))), jsxRuntime.jsx(ChevronIcon, { up: expanded })] }), expanded && (jsxRuntime.jsxs("div", { className: "devic-recall-body", children: [facts.length > 0 && (jsxRuntime.jsx("div", { className: "devic-recall-facts", children: facts.map((fact, i) => (jsxRuntime.jsxs("div", { className: "devic-recall-fact", children: [jsxRuntime.jsx("span", { children: fact.fact }), jsxRuntime.jsxs("span", { className: "devic-recall-fact-meta", children: [fact.source && fact.target
|
|
79
|
+
return (jsxRuntime.jsxs("div", { className: "devic-recall", children: [jsxRuntime.jsxs("button", { type: "button", className: "devic-recall-header", onClick: () => setExpanded((v) => !v), "aria-expanded": expanded, children: [jsxRuntime.jsx(BrainIcon, {}), jsxRuntime.jsx("span", { className: "devic-recall-title", children: t("Recalled memories") }), summaryParts.length > 0 && (jsxRuntime.jsx("span", { className: "devic-recall-summary", children: summaryParts.join(" · ") })), jsxRuntime.jsx("span", { className: "devic-recall-spacer" }), sources.map((s) => (jsxRuntime.jsx("span", { className: "devic-recall-source", children: s }, s))), jsxRuntime.jsx(ChevronIcon, { up: expanded })] }), expanded && (jsxRuntime.jsxs("div", { className: "devic-recall-body", children: [facts.length > 0 && (jsxRuntime.jsx("div", { className: "devic-recall-facts", children: facts.map((fact, i) => (jsxRuntime.jsxs("div", { className: "devic-recall-fact", children: [jsxRuntime.jsx("span", { children: fact.fact }), jsxRuntime.jsxs("span", { className: "devic-recall-fact-meta", children: [fact.source && fact.target
|
|
72
80
|
? `${fact.source} → ${fact.relation} → ${fact.target}`
|
|
73
|
-
: fact.relation, fact.validAt
|
|
81
|
+
: fact.relation, fact.validAt
|
|
82
|
+
? ` · ${t("since {date}", {
|
|
83
|
+
date: fact.validAt.slice(0, 10),
|
|
84
|
+
})}`
|
|
85
|
+
: ""] })] }, i))) })), entities.length > 0 && (jsxRuntime.jsx("div", { className: "devic-recall-entities", children: entities.map((entity) => (jsxRuntime.jsxs("span", { className: "devic-recall-entity", title: entity.summary || undefined, children: [entity.name, jsxRuntime.jsxs("span", { className: "devic-recall-entity-type", children: [" ", "\u00B7 ", entity.type] })] }, entity.id))) })), turns.length > 0 && (jsxRuntime.jsxs("div", { className: "devic-recall-turns", children: [jsxRuntime.jsx("span", { className: "devic-recall-turns-title", children: t("Previous session context") }), turns.map((turn, i) => (jsxRuntime.jsxs("span", { className: "devic-recall-turn", children: [jsxRuntime.jsxs("span", { className: "devic-recall-turn-role", children: [turn.role, ":"] }), " ", turn.content] }, i)))] }))] }))] }));
|
|
74
86
|
}
|
|
75
87
|
|
|
76
88
|
exports.RecalledMemoriesWidget = RecalledMemoriesWidget;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RecalledMemoriesWidget.js","sources":["../../../../../src/components/ChatDrawer/RecalledMemoriesWidget.tsx"],"sourcesContent":["import { useState, type JSX, type ReactNode } from \"react\";\nimport type {\n RecalledMemoryEntity,\n RecalledMemoryFact,\n RecalledMemoryRecord,\n} from \"../../api/types\";\n\n/** Data handed to a custom recalled-memories renderer. */\nexport interface RecalledMemoriesRendererProps {\n /** The recall events anchored at this point of the conversation. */\n records: RecalledMemoryRecord[];\n /** True while the run that produced (or is producing) them is in flight. */\n isLoading: boolean;\n}\n\n/** Replaces the built-in \"Recalled memories\" strip. Return null to hide it. */\nexport type RecalledMemoriesRenderer = (\n props: RecalledMemoriesRendererProps\n) => ReactNode;\n\nconst SOURCE_LABELS: Record<RecalledMemoryRecord[\"source\"], string> = {\n conversation_start: \"Automatic recall\",\n search_memory: \"Memory search\",\n search_memory_nodes: \"Graph node search\",\n explore_memory_graph: \"Graph exploration\",\n};\n\nfunction dedupeFacts(records: RecalledMemoryRecord[]): RecalledMemoryFact[] {\n const seen = new Set<string>();\n const facts: RecalledMemoryFact[] = [];\n for (const record of records) {\n for (const fact of record.facts ?? []) {\n const key = (fact.fact ?? \"\").trim().toLowerCase();\n if (!key || seen.has(key)) continue;\n seen.add(key);\n facts.push(fact);\n }\n }\n return facts;\n}\n\nfunction dedupeEntities(\n records: RecalledMemoryRecord[]\n): RecalledMemoryEntity[] {\n const seen = new Set<string>();\n return records\n .flatMap((r) => r.entities ?? [])\n .filter((e) => {\n const key = (e.name ?? \"\").trim().toLowerCase();\n if (!key || seen.has(key)) return false;\n seen.add(key);\n return true;\n });\n}\n\nfunction BrainIcon(): JSX.Element {\n return (\n <svg\n className=\"devic-recall-icon\"\n width=\"14\"\n height=\"14\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"2\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n aria-hidden=\"true\"\n >\n <path d=\"M9.5 2a2.5 2.5 0 0 0-2.45 2A3.5 3.5 0 0 0 4.6 8.6 3.5 3.5 0 0 0 3 11.5c0 1.1.5 2.08 1.29 2.73A3.5 3.5 0 0 0 7 20a3 3 0 0 0 5-2.24V4.5A2.5 2.5 0 0 0 9.5 2Z\" />\n <path d=\"M14.5 2a2.5 2.5 0 0 1 2.45 2 3.5 3.5 0 0 1 2.45 4.6A3.5 3.5 0 0 1 21 11.5a3.49 3.49 0 0 1-1.29 2.73A3.5 3.5 0 0 1 17 20a3 3 0 0 1-5-2.24V4.5A2.5 2.5 0 0 1 14.5 2Z\" />\n </svg>\n );\n}\n\nfunction ChevronIcon({ up }: { up: boolean }): JSX.Element {\n return (\n <svg\n className=\"devic-recall-chevron\"\n width=\"12\"\n height=\"12\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"2\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n aria-hidden=\"true\"\n style={{ transform: up ? \"rotate(180deg)\" : undefined }}\n >\n <polyline points=\"6 9 12 15 18 9\" />\n </svg>\n );\n}\n\nexport interface RecalledMemoriesWidgetProps {\n records: RecalledMemoryRecord[];\n /** True while the run that produced the records is still processing. */\n isLoading?: boolean;\n /** Custom renderer replacing the built-in strip. */\n renderer?: RecalledMemoriesRenderer;\n}\n\n/**\n * Collapsible \"Recalled memories\" strip interleaved in the chat with the\n * message that brought long-term memories into the conversation. Collapsed it\n * summarizes (\"N facts · M entities\"); expanded it lists the facts (with\n * their graph endpoints), the entities and any previous-session context.\n * Renders nothing when the records carry no content.\n */\nexport function RecalledMemoriesWidget({\n records,\n isLoading = false,\n renderer,\n}: RecalledMemoriesWidgetProps): JSX.Element | null {\n const [expanded, setExpanded] = useState(false);\n\n if (renderer) {\n return <>{renderer({ records, isLoading })}</>;\n }\n\n const facts = dedupeFacts(records);\n const entities = dedupeEntities(records);\n const turns = records\n .filter((r) => r.source === \"conversation_start\")\n .flatMap((r) => r.turns ?? []);\n const sources = [...new Set(records.map((r) => SOURCE_LABELS[r.source]))];\n\n if (!facts.length && !entities.length && !turns.length) return null;\n\n const summaryParts: string[] = [];\n if (facts.length) {\n summaryParts.push(`${facts.length} fact${facts.length > 1 ? \"s\" : \"\"}`);\n }\n if (entities.length) {\n summaryParts.push(\n `${entities.length} entit${entities.length > 1 ? \"ies\" : \"y\"}`\n );\n }\n\n return (\n <div className=\"devic-recall\">\n <button\n type=\"button\"\n className=\"devic-recall-header\"\n onClick={() => setExpanded((v) => !v)}\n aria-expanded={expanded}\n >\n <BrainIcon />\n <span className=\"devic-recall-title\">Recalled memories</span>\n {summaryParts.length > 0 && (\n <span className=\"devic-recall-summary\">\n {summaryParts.join(\" · \")}\n </span>\n )}\n <span className=\"devic-recall-spacer\" />\n {sources.map((s) => (\n <span key={s} className=\"devic-recall-source\">\n {s}\n </span>\n ))}\n <ChevronIcon up={expanded} />\n </button>\n\n {expanded && (\n <div className=\"devic-recall-body\">\n {facts.length > 0 && (\n <div className=\"devic-recall-facts\">\n {facts.map((fact, i) => (\n <div key={i} className=\"devic-recall-fact\">\n <span>{fact.fact}</span>\n <span className=\"devic-recall-fact-meta\">\n {fact.source && fact.target\n ? `${fact.source} → ${fact.relation} → ${fact.target}`\n : fact.relation}\n {fact.validAt ? ` · since ${fact.validAt.slice(0, 10)}` : \"\"}\n </span>\n </div>\n ))}\n </div>\n )}\n\n {entities.length > 0 && (\n <div className=\"devic-recall-entities\">\n {entities.map((entity) => (\n <span\n key={entity.id}\n className=\"devic-recall-entity\"\n title={entity.summary || undefined}\n >\n {entity.name}\n <span className=\"devic-recall-entity-type\">\n {\" \"}\n · {entity.type}\n </span>\n </span>\n ))}\n </div>\n )}\n\n {turns.length > 0 && (\n <div className=\"devic-recall-turns\">\n <span className=\"devic-recall-turns-title\">\n Previous session context\n </span>\n {turns.map((turn, i) => (\n <span key={i} className=\"devic-recall-turn\">\n <span className=\"devic-recall-turn-role\">{turn.role}:</span>{\" \"}\n {turn.content}\n </span>\n ))}\n </div>\n )}\n </div>\n )}\n </div>\n );\n}\n\nexport default RecalledMemoriesWidget;\n"],"names":["_jsxs","_jsx","useState","_Fragment"],"mappings":";;;;;AAoBA,MAAM,aAAa,GAAmD;AACpE,IAAA,kBAAkB,EAAE,kBAAkB;AACtC,IAAA,aAAa,EAAE,eAAe;AAC9B,IAAA,mBAAmB,EAAE,mBAAmB;AACxC,IAAA,oBAAoB,EAAE,mBAAmB;CAC1C;AAED,SAAS,WAAW,CAAC,OAA+B,EAAA;AAClD,IAAA,MAAM,IAAI,GAAG,IAAI,GAAG,EAAU;IAC9B,MAAM,KAAK,GAAyB,EAAE;AACtC,IAAA,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE;QAC5B,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,KAAK,IAAI,EAAE,EAAE;AACrC,YAAA,MAAM,GAAG,GAAG,CAAC,IAAI,CAAC,IAAI,IAAI,EAAE,EAAE,IAAI,EAAE,CAAC,WAAW,EAAE;YAClD,IAAI,CAAC,GAAG,IAAI,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC;gBAAE;AAC3B,YAAA,IAAI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EAAA,SAAA,EACD,MAAM,CAAC,IAAI,IACT,CAAA,EAAA,EARF,MAAM,CAAC,EAAE,CAST,CACR,CAAC,EAAA,CACE,CACP,EAEA,KAAK,CAAC,MAAM,GAAG,CAAC,KACfA,eAAA,CAAA,KAAA,EAAA,EAAK,SAAS,EAAC,oBAAoB,EAAA,QAAA,EAAA,CACjCC,cAAA,CAAA,MAAA,EAAA,EAAM,SAAS,EAAC,0BAA0B,EAAA,QAAA,EAAA,0BAAA,EAAA,CAEnC,EACN,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC,MACjBD,eAAA,CAAA,MAAA,EAAA,EAAc,SAAS,EAAC,mBAAmB,aACzCA,eAAA,CAAA,MAAA,EAAA,EAAM,SAAS,EAAC,wBAAwB,aAAE,IAAI,CAAC,IAAI,EAAA,GAAA,CAAA,EAAA,CAAS,EAAC,GAAG,EAC/D,IAAI,CAAC,OAAO,CAAA,EAAA,EAFJ,CAAC,CAGL,CACR,CAAC,CAAA,EAAA,CACE,CACP,IACG,CACP,CAAA,EAAA,CACG;AAEV;;"}
|
|
1
|
+
{"version":3,"file":"RecalledMemoriesWidget.js","sources":["../../../../../src/components/ChatDrawer/RecalledMemoriesWidget.tsx"],"sourcesContent":["import { useState, type JSX, type ReactNode } from \"react\";\nimport { useTranslations } from \"../../i18n\";\nimport type {\n RecalledMemoryEntity,\n RecalledMemoryFact,\n RecalledMemoryRecord,\n} from \"../../api/types\";\n\n/** Data handed to a custom recalled-memories renderer. */\nexport interface RecalledMemoriesRendererProps {\n /** The recall events anchored at this point of the conversation. */\n records: RecalledMemoryRecord[];\n /** True while the run that produced (or is producing) them is in flight. */\n isLoading: boolean;\n}\n\n/** Replaces the built-in \"Recalled memories\" strip. Return null to hide it. */\nexport type RecalledMemoriesRenderer = (\n props: RecalledMemoriesRendererProps\n) => ReactNode;\n\nconst SOURCE_LABELS: Record<RecalledMemoryRecord[\"source\"], string> = {\n conversation_start: \"Automatic recall\",\n search_memory: \"Memory search\",\n search_memory_nodes: \"Graph node search\",\n explore_memory_graph: \"Graph exploration\",\n};\n\nfunction dedupeFacts(records: RecalledMemoryRecord[]): RecalledMemoryFact[] {\n const seen = new Set<string>();\n const facts: RecalledMemoryFact[] = [];\n for (const record of records) {\n for (const fact of record.facts ?? []) {\n const key = (fact.fact ?? \"\").trim().toLowerCase();\n if (!key || seen.has(key)) continue;\n seen.add(key);\n facts.push(fact);\n }\n }\n return facts;\n}\n\nfunction dedupeEntities(\n records: RecalledMemoryRecord[]\n): RecalledMemoryEntity[] {\n const seen = new Set<string>();\n return records\n .flatMap((r) => r.entities ?? [])\n .filter((e) => {\n const key = (e.name ?? \"\").trim().toLowerCase();\n if (!key || seen.has(key)) return false;\n seen.add(key);\n return true;\n });\n}\n\nfunction BrainIcon(): JSX.Element {\n return (\n <svg\n className=\"devic-recall-icon\"\n width=\"14\"\n height=\"14\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"2\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n aria-hidden=\"true\"\n >\n <path d=\"M9.5 2a2.5 2.5 0 0 0-2.45 2A3.5 3.5 0 0 0 4.6 8.6 3.5 3.5 0 0 0 3 11.5c0 1.1.5 2.08 1.29 2.73A3.5 3.5 0 0 0 7 20a3 3 0 0 0 5-2.24V4.5A2.5 2.5 0 0 0 9.5 2Z\" />\n <path d=\"M14.5 2a2.5 2.5 0 0 1 2.45 2 3.5 3.5 0 0 1 2.45 4.6A3.5 3.5 0 0 1 21 11.5a3.49 3.49 0 0 1-1.29 2.73A3.5 3.5 0 0 1 17 20a3 3 0 0 1-5-2.24V4.5A2.5 2.5 0 0 1 14.5 2Z\" />\n </svg>\n );\n}\n\nfunction ChevronIcon({ up }: { up: boolean }): JSX.Element {\n return (\n <svg\n className=\"devic-recall-chevron\"\n width=\"12\"\n height=\"12\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"2\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n aria-hidden=\"true\"\n style={{ transform: up ? \"rotate(180deg)\" : undefined }}\n >\n <polyline points=\"6 9 12 15 18 9\" />\n </svg>\n );\n}\n\nexport interface RecalledMemoriesWidgetProps {\n records: RecalledMemoryRecord[];\n /** True while the run that produced the records is still processing. */\n isLoading?: boolean;\n /** Custom renderer replacing the built-in strip. */\n renderer?: RecalledMemoriesRenderer;\n}\n\n/**\n * Collapsible \"Recalled memories\" strip interleaved in the chat with the\n * message that brought long-term memories into the conversation. Collapsed it\n * summarizes (\"N facts · M entities\"); expanded it lists the facts (with\n * their graph endpoints), the entities and any previous-session context.\n * Renders nothing when the records carry no content.\n */\nexport function RecalledMemoriesWidget({\n records,\n isLoading = false,\n renderer,\n}: RecalledMemoriesWidgetProps): JSX.Element | null {\n const t = useTranslations();\n const [expanded, setExpanded] = useState(false);\n\n if (renderer) {\n return <>{renderer({ records, isLoading })}</>;\n }\n\n const facts = dedupeFacts(records);\n const entities = dedupeEntities(records);\n const turns = records\n .filter((r) => r.source === \"conversation_start\")\n .flatMap((r) => r.turns ?? []);\n const sources = [\n ...new Set(records.map((r) => t(SOURCE_LABELS[r.source]))),\n ];\n\n if (!facts.length && !entities.length && !turns.length) return null;\n\n const summaryParts: string[] = [];\n if (facts.length) {\n summaryParts.push(\n facts.length === 1\n ? t(\"1 fact\")\n : t(\"{count} facts\", { count: facts.length })\n );\n }\n if (entities.length) {\n summaryParts.push(\n entities.length === 1\n ? t(\"1 entity\")\n : t(\"{count} entities\", { count: entities.length })\n );\n }\n\n return (\n <div className=\"devic-recall\">\n <button\n type=\"button\"\n className=\"devic-recall-header\"\n onClick={() => setExpanded((v) => !v)}\n aria-expanded={expanded}\n >\n <BrainIcon />\n <span className=\"devic-recall-title\">{t(\"Recalled memories\")}</span>\n {summaryParts.length > 0 && (\n <span className=\"devic-recall-summary\">\n {summaryParts.join(\" · \")}\n </span>\n )}\n <span className=\"devic-recall-spacer\" />\n {sources.map((s) => (\n <span key={s} className=\"devic-recall-source\">\n {s}\n </span>\n ))}\n <ChevronIcon up={expanded} />\n </button>\n\n {expanded && (\n <div className=\"devic-recall-body\">\n {facts.length > 0 && (\n <div className=\"devic-recall-facts\">\n {facts.map((fact, i) => (\n <div key={i} className=\"devic-recall-fact\">\n <span>{fact.fact}</span>\n <span className=\"devic-recall-fact-meta\">\n {fact.source && fact.target\n ? `${fact.source} → ${fact.relation} → ${fact.target}`\n : fact.relation}\n {fact.validAt\n ? ` · ${t(\"since {date}\", {\n date: fact.validAt.slice(0, 10),\n })}`\n : \"\"}\n </span>\n </div>\n ))}\n </div>\n )}\n\n {entities.length > 0 && (\n <div className=\"devic-recall-entities\">\n {entities.map((entity) => (\n <span\n key={entity.id}\n className=\"devic-recall-entity\"\n title={entity.summary || undefined}\n >\n {entity.name}\n <span className=\"devic-recall-entity-type\">\n {\" \"}\n · {entity.type}\n </span>\n </span>\n ))}\n </div>\n )}\n\n {turns.length > 0 && (\n <div className=\"devic-recall-turns\">\n <span className=\"devic-recall-turns-title\">\n {t(\"Previous session context\")}\n </span>\n {turns.map((turn, i) => (\n <span key={i} className=\"devic-recall-turn\">\n <span className=\"devic-recall-turn-role\">{turn.role}:</span>{\" \"}\n {turn.content}\n </span>\n ))}\n </div>\n )}\n </div>\n )}\n </div>\n );\n}\n\nexport default RecalledMemoriesWidget;\n"],"names":["_jsxs","_jsx","useTranslations","useState","_Fragment"],"mappings":";;;;;;AAqBA,MAAM,aAAa,GAAmD;AACpE,IAAA,kBAAkB,EAAE,kBAAkB;AACtC,IAAA,aAAa,EAAE,eAAe;AAC9B,IAAA,mBAAmB,EAAE,mBAAmB;AACxC,IAAA,oBAAoB,EAAE,mBAAmB;CAC1C;AAED,SAAS,WAAW,CAAC,OAA+B,EAAA;AAClD,IAAA,MAAM,IAAI,GAAG,IAAI,GAAG,EAAU;IAC9B,MAAM,KAAK,GAAyB,EAAE;AACtC,IAAA,KAAK,MAAM,MAAM,IAA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+1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var jsxRuntime = require('react/jsx-runtime');
|
|
4
|
+
var useTranslations = require('../../i18n/useTranslations.js');
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* Reusable chip node for an AIElementWrapper reference. Shared by the
|
|
@@ -9,10 +10,11 @@ var jsxRuntime = require('react/jsx-runtime');
|
|
|
9
10
|
* exact same chip markup and styling.
|
|
10
11
|
*/
|
|
11
12
|
function ReferenceChip({ label, onRemove, variant = "input", icon, className, }) {
|
|
13
|
+
const t = useTranslations.useTranslations();
|
|
12
14
|
const base = variant === "message"
|
|
13
15
|
? "devic-message-reference-chip"
|
|
14
16
|
: "devic-reference-chip";
|
|
15
|
-
return (jsxRuntime.jsxs("div", { className: className ? `${base} ${className}` : base, title: label, children: [icon ?? jsxRuntime.jsx(ReferenceArrowIcon, {}), jsxRuntime.jsxs("span", { className: `${base}-label`, children: ["\"", label, "\""] }), onRemove && (jsxRuntime.jsx("button", { type: "button", className: "devic-reference-chip-remove", onClick: onRemove, "aria-label": "
|
|
17
|
+
return (jsxRuntime.jsxs("div", { className: className ? `${base} ${className}` : base, title: label, children: [icon ?? jsxRuntime.jsx(ReferenceArrowIcon, {}), jsxRuntime.jsxs("span", { className: `${base}-label`, children: ["\"", label, "\""] }), onRemove && (jsxRuntime.jsx("button", { type: "button", className: "devic-reference-chip-remove", onClick: onRemove, "aria-label": t("Remove reference"), children: "\u00D7" }))] }));
|
|
16
18
|
}
|
|
17
19
|
/** Corner-down-right arrow used as the default reference glyph. */
|
|
18
20
|
function ReferenceArrowIcon() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ReferenceChip.js","sources":["../../../../../src/components/ChatDrawer/ReferenceChip.tsx"],"sourcesContent":["import React from \"react\";\n\n/**\n * Visual context a {@link ReferenceChip} is rendered in:\n * - `input`: inside the prompt box, as an editable, removable chip.\n * - `message`: above a sent user bubble, as a read-only chip.\n */\nexport type ReferenceChipVariant = \"input\" | \"message\";\n\nexport interface ReferenceChipProps {\n /** Short label shown inside the chip (quoted automatically). */\n label: string;\n /**\n * When provided, renders a remove (×) button that invokes this handler.\n * Only meaningful for the `input` variant.\n */\n onRemove?: () => void;\n /** Visual context. Defaults to `input`. */\n variant?: ReferenceChipVariant;\n /** Optional custom icon replacing the default reference arrow. */\n icon?: React.ReactNode;\n /** Extra className appended to the chip root. */\n className?: string;\n}\n\n/**\n * Reusable chip node for an AIElementWrapper reference. Shared by the\n * ChatInput (active references in the prompt box) and ChatMessages\n * (references parsed out of a sent user message), so both render the\n * exact same chip markup and styling.\n */\nexport function ReferenceChip({\n label,\n onRemove,\n variant = \"input\",\n icon,\n className,\n}: ReferenceChipProps): JSX.Element {\n const base =\n variant === \"message\"\n ? \"devic-message-reference-chip\"\n : \"devic-reference-chip\";\n\n return (\n <div className={className ? `${base} ${className}` : base} title={label}>\n {icon ?? <ReferenceArrowIcon />}\n <span className={`${base}-label`}>\"{label}\"</span>\n {onRemove && (\n <button\n type=\"button\"\n className=\"devic-reference-chip-remove\"\n onClick={onRemove}\n aria-label
|
|
1
|
+
{"version":3,"file":"ReferenceChip.js","sources":["../../../../../src/components/ChatDrawer/ReferenceChip.tsx"],"sourcesContent":["import React from \"react\";\nimport { useTranslations } from \"../../i18n\";\n\n/**\n * Visual context a {@link ReferenceChip} is rendered in:\n * - `input`: inside the prompt box, as an editable, removable chip.\n * - `message`: above a sent user bubble, as a read-only chip.\n */\nexport type ReferenceChipVariant = \"input\" | \"message\";\n\nexport interface ReferenceChipProps {\n /** Short label shown inside the chip (quoted automatically). */\n label: string;\n /**\n * When provided, renders a remove (×) button that invokes this handler.\n * Only meaningful for the `input` variant.\n */\n onRemove?: () => void;\n /** Visual context. Defaults to `input`. */\n variant?: ReferenceChipVariant;\n /** Optional custom icon replacing the default reference arrow. */\n icon?: React.ReactNode;\n /** Extra className appended to the chip root. */\n className?: string;\n}\n\n/**\n * Reusable chip node for an AIElementWrapper reference. Shared by the\n * ChatInput (active references in the prompt box) and ChatMessages\n * (references parsed out of a sent user message), so both render the\n * exact same chip markup and styling.\n */\nexport function ReferenceChip({\n label,\n onRemove,\n variant = \"input\",\n icon,\n className,\n}: ReferenceChipProps): JSX.Element {\n const t = useTranslations();\n const base =\n variant === \"message\"\n ? \"devic-message-reference-chip\"\n : \"devic-reference-chip\";\n\n return (\n <div className={className ? `${base} ${className}` : base} title={label}>\n {icon ?? <ReferenceArrowIcon />}\n <span className={`${base}-label`}>\"{label}\"</span>\n {onRemove && (\n <button\n type=\"button\"\n className=\"devic-reference-chip-remove\"\n onClick={onRemove}\n aria-label={t(\"Remove reference\")}\n >\n ×\n </button>\n )}\n </div>\n );\n}\n\n/** Corner-down-right arrow used as the default reference glyph. */\nfunction ReferenceArrowIcon(): JSX.Element {\n return (\n <svg\n width=\"12\"\n height=\"12\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"2\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n aria-hidden=\"true\"\n >\n <polyline points=\"15 10 20 15 15 20\" />\n <path d=\"M4 4v7a4 4 0 0 0 4 4h12\" />\n </svg>\n );\n}\n"],"names":["useTranslations","_jsxs","_jsx"],"mappings":";;;;;AA0BA;;;;;AAKG;AACG,SAAU,aAAa,CAAC,EAC5B,KAAK,EACL,QAAQ,EACR,OAAO,GAAG,OAAO,EACjB,IAAI,EACJ,SAAS,GACU,EAAA;AACnB,IAAA,MAAM,CAAC,GAAGA,+BAAe,EAAE;AAC3B,IAAA,MAAM,IAAI,GACR,OAAO,KAAK;AACV,UAAE;UACA,sBAAsB;AAE5B,IAAA,QACEC,eAAA,CAAA,KAAA,EAAA,EAAK,SAAS,EAAE,SAAS,GAAG,CAAA,EAAG,IAAI,CAAA,CAAA,EAAI,SAAS,CAAA,CAAE,GAAG,IAAI,EAAE,KAAK,EAAE,KAAK,EAAA,QAAA,EAAA,CACpE,IAAI,IAAIC,cAAA,CAAC,kBAAkB,EAAA,EAAA,CAAG,EAC/BD,0BAAM,SAAS,EAAE,CAAA,EAAG,IAAI,CAAA,MAAA,CAAQ,EAAA,QAAA,EAAA,CAAA,IAAA,EAAI,KAAK,EAAA,IAAA,CAAA,EAAA,CAAS,EACjD,QAAQ,KACPC,cAAA,CAAA,QAAA,EAAA,EACE,IAAI,EAAC,QAAQ,EACb,SAAS,EAAC,6BAA6B,EACvC,OAAO,EAAE,QAAQ,EAAA,YAAA,EACL,CAAC,CAAC,kBAAkB,CAAC,EAAA,QAAA,EAAA,QAAA,EAAA,CAG1B,CACV,CAAA,EAAA,CACG;AAEV;AAEA;AACA,SAAS,kBAAkB,GAAA;IACzB,QACED,yBACE,KAAK,EAAC,IAAI,EACV,MAAM,EAAC,IAAI,EACX,OAAO,EAAC,WAAW,EACnB,IAAI,EAAC,MAAM,EACX,MAAM,EAAC,cAAc,EACrB,WAAW,EAAC,GAAG,EACf,aAAa,EAAC,OAAO,EACrB,cAAc,EAAC,OAAO,EAAA,aAAA,EACV,MAAM,EAAA,QAAA,EAAA,CAElBC,cAAA,CAAA,UAAA,EAAA,EAAU,MAAM,EAAC,mBAAmB,EAAA,CAAG,EACvCA,cAAA,CAAA,MAAA,EAAA,EAAM,CAAC,EAAC,yBAAyB,EAAA,CAAG,CAAA,EAAA,CAChC;AAEV;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ToolTimeline.js","sources":["../../../../../src/components/ChatDrawer/ToolTimeline.tsx"],"sourcesContent":["import React from 'react';\nimport type { ToolTimelineProps } from './ChatDrawer.types';\n\n/**\n * Tool execution timeline component\n */\nexport function ToolTimeline({ toolCalls }: ToolTimelineProps): JSX.Element | null {\n if (toolCalls.length === 0) {\n return null;\n }\n\n return (\n <div className=\"devic-tool-timeline\">\n {toolCalls.map((tool) => (\n <div key={tool.id} className=\"devic-tool-item\">\n <span className=\"devic-tool-status\" data-status={tool.status} />\n <span className=\"devic-tool-name\">{formatToolName(tool.name)}</span>\n {tool.status === 'error' && tool.error && (\n <span className=\"devic-tool-error\">{tool.error}</span>\n )}\n </div>\n ))}\n </div>\n );\n}\n\n/**\n * Format tool name for display\n */\nfunction formatToolName(name: string): string {\n // Convert snake_case or camelCase to Title Case with spaces\n return name\n .replace(/_/g, ' ')\n .replace(/([a-z])([A-Z])/g, '$1 $2')\n .replace(/\\b\\w/g, (char) => char.toUpperCase());\n}\n"],"names":["_jsx","_jsxs"],"mappings":";;;;AAGA;;AAEG;AACG,SAAU,YAAY,CAAC,EAAE,SAAS,EAAqB,EAAA;AAC3D,IAAA,IAAI,SAAS,CAAC,MAAM,KAAK,CAAC,EAAE;AAC1B,QAAA,OAAO,IAAI;IACb;AAEA,IAAA,QACEA,cAAA,CAAA,KAAA,EAAA,EAAK,SAAS,EAAC,qBAAqB,EAAA,QAAA,EACjC,SAAS,CAAC,GAAG,CAAC,CAAC,IAAI,MAClBC,eAAA,CAAA,KAAA,EAAA,EAAmB,SAAS,EAAC,iBAAiB,EAAA,QAAA,EAAA,CAC5CD,cAAA,CAAA,MAAA,EAAA,EAAM,SAAS,EAAC,mBAAmB,EAAA,aAAA,EAAc,IAAI,CAAC,MAAM,GAAI,EAChEA,cAAA,CAAA,MAAA,EAAA,EAAM,SAAS,EAAC,iBAAiB,EAAA,QAAA,EAAE,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,EAAA,CAAQ,EACnE,IAAI,CAAC,MAAM,KAAK,OAAO,IAAI,IAAI,CAAC,KAAK,KACpCA,cAAA,CAAA,MAAA,EAAA,EAAM,SAAS,EAAC,kBAAkB,EAAA,QAAA,EAAE,IAAI,CAAC,KAAK,GAAQ,CACvD,CAAA,EAAA,EALO,IAAI,CAAC,EAAE,CAMX,CACP,CAAC,EAAA,CACE;AAEV;AAEA;;AAEG;AACH,SAAS,cAAc,CAAC,IAAY,EAAA;;AAElC,IAAA,OAAO;AACJ,SAAA,OAAO,CAAC,IAAI,EAAE,GAAG;AACjB,SAAA,OAAO,CAAC,iBAAiB,EAAE,OAAO;AAClC,SAAA,OAAO,CAAC,OAAO,EAAE,CAAC,IAAI,KAAK,IAAI,CAAC,WAAW,EAAE,CAAC;AACnD
|
|
1
|
+
{"version":3,"file":"ToolTimeline.js","sources":["../../../../../src/components/ChatDrawer/ToolTimeline.tsx"],"sourcesContent":["import React from 'react';\nimport type { ToolTimelineProps } from './ChatDrawer.types';\n\n/**\n * Tool execution timeline component\n */\nexport function ToolTimeline({ toolCalls }: ToolTimelineProps): JSX.Element | null {\n if (toolCalls.length === 0) {\n return null;\n }\n\n return (\n <div className=\"devic-tool-timeline\">\n {toolCalls.map((tool) => (\n <div key={tool.id} className=\"devic-tool-item\">\n <span className=\"devic-tool-status\" data-status={tool.status} />\n <span className=\"devic-tool-name\">{formatToolName(tool.name)}</span>\n {tool.status === 'error' && tool.error && (\n <span className=\"devic-tool-error\">{tool.error}</span>\n )}\n </div>\n ))}\n </div>\n );\n}\n\n/**\n * Format tool name for display\n */\nfunction formatToolName(name: string): string {\n // Convert snake_case or camelCase to Title Case with spaces\n return name\n .replace(/_/g, ' ')\n .replace(/([a-z])([A-Z])/g, '$1 $2')\n .replace(/\\b\\w/g, (char) => char.toUpperCase());\n}\n"],"names":["_jsx","_jsxs"],"mappings":";;;;AAGA;;AAEG;AACG,SAAU,YAAY,CAAC,EAAE,SAAS,EAAqB,EAAA;AAC3D,IAAA,IAAI,SAAS,CAAC,MAAM,KAAK,CAAC,EAAE;AAC1B,QAAA,OAAO,IAAI;IACb;AAEA,IAAA,QACEA,cAAA,CAAA,KAAA,EAAA,EAAK,SAAS,EAAC,qBAAqB,EAAA,QAAA,EACjC,SAAS,CAAC,GAAG,CAAC,CAAC,IAAI,MAClBC,eAAA,CAAA,KAAA,EAAA,EAAmB,SAAS,EAAC,iBAAiB,EAAA,QAAA,EAAA,CAC5CD,cAAA,CAAA,MAAA,EAAA,EAAM,SAAS,EAAC,mBAAmB,EAAA,aAAA,EAAc,IAAI,CAAC,MAAM,GAAI,EAChEA,cAAA,CAAA,MAAA,EAAA,EAAM,SAAS,EAAC,iBAAiB,EAAA,QAAA,EAAE,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,EAAA,CAAQ,EACnE,IAAI,CAAC,MAAM,KAAK,OAAO,IAAI,IAAI,CAAC,KAAK,KACpCA,cAAA,CAAA,MAAA,EAAA,EAAM,SAAS,EAAC,kBAAkB,EAAA,QAAA,EAAE,IAAI,CAAC,KAAK,GAAQ,CACvD,CAAA,EAAA,EALO,IAAI,CAAC,EAAE,CAMX,CACP,CAAC,EAAA,CACE;AAEV;AAEA;;AAEG;AACH,SAAS,cAAc,CAAC,IAAY,EAAA;;AAElC,IAAA,OAAO;AACJ,SAAA,OAAO,CAAC,IAAI,EAAE,GAAG;AACjB,SAAA,OAAO,CAAC,iBAAiB,EAAE,OAAO;AAClC,SAAA,OAAO,CAAC,OAAO,EAAE,CAAC,IAAI,KAAK,IAAI,CAAC,WAAW,EAAE,CAAC;AACnD;;;;"}
|
|
@@ -4,6 +4,7 @@ var jsxRuntime = require('react/jsx-runtime');
|
|
|
4
4
|
var React = require('react');
|
|
5
5
|
var DevicContext = require('../../provider/DevicContext.js');
|
|
6
6
|
var client = require('../../api/client.js');
|
|
7
|
+
var useTranslations = require('../../i18n/useTranslations.js');
|
|
7
8
|
|
|
8
9
|
const DEFAULT_DISPLAY = {
|
|
9
10
|
showValues: false,
|
|
@@ -26,24 +27,27 @@ function formatAmount(value, metric) {
|
|
|
26
27
|
}
|
|
27
28
|
return Math.round(value).toLocaleString();
|
|
28
29
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
// The unit names are translated on their own so a dictionary can decline
|
|
31
|
+
// them; the sentence around them is a separate entry with placeholders, which
|
|
32
|
+
// is what a language with a different word order needs.
|
|
33
|
+
function windowLabel(t, unit, every) {
|
|
34
|
+
const u = every > 1 ? t(`{count} ${unit}s`, { count: every }) : t(unit);
|
|
35
|
+
return every > 1 ? t('every {window}', { window: u }) : t('per {window}', { window: u });
|
|
32
36
|
}
|
|
33
|
-
function resetLabel(resetsAt) {
|
|
37
|
+
function resetLabel(t, resetsAt) {
|
|
34
38
|
if (!resetsAt)
|
|
35
39
|
return '';
|
|
36
40
|
const ms = resetsAt - Date.now();
|
|
37
41
|
if (ms <= 0)
|
|
38
|
-
return 'resets now';
|
|
42
|
+
return t('resets now');
|
|
39
43
|
const mins = Math.round(ms / 60000);
|
|
40
44
|
if (mins < 60)
|
|
41
|
-
return
|
|
45
|
+
return t('resets in {count}m', { count: mins });
|
|
42
46
|
const hours = Math.round(mins / 60);
|
|
43
47
|
if (hours < 48)
|
|
44
|
-
return
|
|
48
|
+
return t('resets in {count}h', { count: hours });
|
|
45
49
|
const days = Math.round(hours / 24);
|
|
46
|
-
return
|
|
50
|
+
return t('resets in {count}d', { count: days });
|
|
47
51
|
}
|
|
48
52
|
/**
|
|
49
53
|
* A thin usage bar showing the current tenant/subtenant usage window(s).
|
|
@@ -51,6 +55,7 @@ function resetLabel(resetsAt) {
|
|
|
51
55
|
* Renders nothing when there are no usage limits configured for the tenant.
|
|
52
56
|
*/
|
|
53
57
|
function UsageBar({ apiKey, baseUrl, tenantId, subtenantId, mode = 'always', metric, display, customUsageBar, color = '#1890ff', refreshKey, debug = false, }) {
|
|
58
|
+
const t = useTranslations.useTranslations();
|
|
54
59
|
const cfg = React.useMemo(() => ({ ...DEFAULT_DISPLAY, ...display }), [display]);
|
|
55
60
|
const devicContext = DevicContext.useOptionalDevicContext();
|
|
56
61
|
const getTenantSession = devicContext?.getTenantSession;
|
|
@@ -114,14 +119,14 @@ function UsageBar({ apiKey, baseUrl, tenantId, subtenantId, mode = 'always', met
|
|
|
114
119
|
}
|
|
115
120
|
// onDemand, collapsed: show a small toggle button.
|
|
116
121
|
if (mode === 'onDemand' && !visible) {
|
|
117
|
-
return (jsxRuntime.jsx("div", { className: "devic-usage-bar-wrap", "data-mode": "onDemand", children: jsxRuntime.jsxs("button", { type: "button", className: "devic-usage-toggle", onClick: () => setVisible(true), title:
|
|
122
|
+
return (jsxRuntime.jsx("div", { className: "devic-usage-bar-wrap", "data-mode": "onDemand", children: jsxRuntime.jsxs("button", { type: "button", className: "devic-usage-toggle", onClick: () => setVisible(true), title: t('Show usage'), children: [jsxRuntime.jsx(GaugeIcon, {}), jsxRuntime.jsx("span", { children: t('Usage') })] }) }));
|
|
118
123
|
}
|
|
119
124
|
// No configured limits (or not loaded yet with nothing to show): render nothing
|
|
120
125
|
// in 'always' mode; in expanded onDemand, show a subtle note so the toggle isn't
|
|
121
126
|
// confusing.
|
|
122
127
|
if (rules.length === 0) {
|
|
123
128
|
if (mode === 'onDemand' && loaded) {
|
|
124
|
-
return (jsxRuntime.jsx("div", { className: "devic-usage-bar-wrap", "data-mode": "onDemand", children: jsxRuntime.jsxs("div", { className: "devic-usage-bar", "data-empty": "true", children: [jsxRuntime.jsx("span", { className: "devic-usage-bar-label", children:
|
|
129
|
+
return (jsxRuntime.jsx("div", { className: "devic-usage-bar-wrap", "data-mode": "onDemand", children: jsxRuntime.jsxs("div", { className: "devic-usage-bar", "data-empty": "true", children: [jsxRuntime.jsx("span", { className: "devic-usage-bar-label", children: t('No usage limits') }), jsxRuntime.jsx("button", { type: "button", className: "devic-usage-collapse", onClick: () => setVisible(false), title: t('Hide usage'), "aria-label": t('Hide usage'), children: "\u00D7" })] }) }));
|
|
125
130
|
}
|
|
126
131
|
return null;
|
|
127
132
|
}
|
|
@@ -129,20 +134,20 @@ function UsageBar({ apiKey, baseUrl, tenantId, subtenantId, mode = 'always', met
|
|
|
129
134
|
const multi = rules.length > 1;
|
|
130
135
|
// A header carries the tier chip and/or the onDemand collapse control, so the
|
|
131
136
|
// collapse "×" has a stable home regardless of how many rows render below.
|
|
132
|
-
const header = showTierChip || mode === 'onDemand' ? (jsxRuntime.jsxs("div", { className: "devic-usage-bar-head", children: [showTierChip ? (jsxRuntime.jsx("span", { className: "devic-usage-tier", title:
|
|
137
|
+
const header = showTierChip || mode === 'onDemand' ? (jsxRuntime.jsxs("div", { className: "devic-usage-bar-head", children: [showTierChip ? (jsxRuntime.jsx("span", { className: "devic-usage-tier", title: t('Tier: {tier}', { tier: tierId }), children: tierId })) : (jsxRuntime.jsx("span", {})), mode === 'onDemand' && (jsxRuntime.jsx("button", { type: "button", className: "devic-usage-collapse", onClick: () => setVisible(false), title: t('Hide usage'), "aria-label": t('Hide usage'), children: "\u00D7" }))] })) : null;
|
|
133
138
|
return (jsxRuntime.jsxs("div", { className: "devic-usage-bar-wrap", "data-mode": mode, children: [header, jsxRuntime.jsx("div", { className: "devic-usage-bar-group", children: rules.map((rule, i) => {
|
|
134
139
|
const pct = Math.min(100, Math.round(rule.percent));
|
|
135
140
|
const fill = fillColor(pct, color);
|
|
136
|
-
const valuesText = `${formatAmount(rule.current, rule.metric)} / ${formatAmount(rule.limit, rule.metric)} ${rule.metric}`;
|
|
141
|
+
const valuesText = `${formatAmount(rule.current, rule.metric)} / ${formatAmount(rule.limit, rule.metric)} ${t(rule.metric)}`;
|
|
137
142
|
// Distinguish rows by metric when several render; otherwise use the
|
|
138
143
|
// scope-aware label so single-rule mode reads "Usage 24%".
|
|
139
144
|
const prefix = multi
|
|
140
145
|
? rule.metric === 'cost'
|
|
141
|
-
? 'Cost'
|
|
142
|
-
: 'Tokens'
|
|
146
|
+
? t('Cost')
|
|
147
|
+
: t('Tokens')
|
|
143
148
|
: rule.scope === 'subtenant'
|
|
144
|
-
? 'Your usage'
|
|
145
|
-
: 'Usage';
|
|
149
|
+
? t('Your usage')
|
|
150
|
+
: t('Usage');
|
|
146
151
|
const main = [];
|
|
147
152
|
if (cfg.showPercent)
|
|
148
153
|
main.push(`${pct}%`);
|
|
@@ -151,8 +156,8 @@ function UsageBar({ apiKey, baseUrl, tenantId, subtenantId, mode = 'always', met
|
|
|
151
156
|
if (main.length === 0)
|
|
152
157
|
main.push(`${pct}%`);
|
|
153
158
|
const label = `${prefix} ${main.join(' · ')}`.trim();
|
|
154
|
-
const reset = resetLabel(rule.resetsAt);
|
|
155
|
-
const win = windowLabel(rule.windowUnit, rule.windowEvery);
|
|
159
|
+
const reset = resetLabel(t, rule.resetsAt);
|
|
160
|
+
const win = windowLabel(t, rule.windowUnit, rule.windowEvery);
|
|
156
161
|
const title = `${valuesText} · ${win}${reset ? ` · ${reset}` : ''}`;
|
|
157
162
|
return (jsxRuntime.jsxs("div", { className: "devic-usage-bar", title: title, "data-state": pct >= 100 ? 'exceeded' : 'ok', children: [jsxRuntime.jsx("span", { className: "devic-usage-bar-label", children: label }), jsxRuntime.jsx("div", { className: "devic-usage-bar-track", children: jsxRuntime.jsx("div", { className: "devic-usage-bar-fill", style: { width: `${pct}%`, backgroundColor: fill } }) }), cfg.showWindow && (jsxRuntime.jsx("span", { className: "devic-usage-bar-window", children: win })), reset && jsxRuntime.jsx("span", { className: "devic-usage-bar-reset", children: reset })] }, `${rule.metric}-${rule.windowUnit}-${rule.windowEvery}-${rule.scope}-${i}`));
|
|
158
163
|
}) })] }));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UsageBar.js","sources":["../../../../../src/components/ChatDrawer/UsageBar.tsx"],"sourcesContent":["import React, { useCallback, useEffect, useMemo, useState } from 'react';\nimport { useOptionalDevicContext } from '../../provider';\nimport { DevicApiClient } from '../../api/client';\nimport type { TenantUsage, TenantUsageRule } from '../../api/types';\n\n/**\n * Controls what each usage row renders. All flags compose, so a developer can,\n * for example, show absolute values together with the percentage and the tier.\n */\nexport interface UsageBarDisplay {\n /**\n * Show the absolute amount of the active window: `current / limit metric`\n * (e.g. `1,200 / 5,000 tokens`).\n * @default false\n */\n showValues?: boolean;\n /**\n * Show the utilization percentage (e.g. `24%`).\n * @default true\n */\n showPercent?: boolean;\n /**\n * Show the temporal dimension of the window (e.g. `per 3h`, `every 3 hours`).\n * @default true\n */\n showWindow?: boolean;\n /**\n * Show the tier (plan) the limits come from, as a chip above the bar(s).\n * @default false\n */\n showTier?: boolean;\n /**\n * When more than one limit rule applies, render every rule (`true`) or only\n * the single most restrictive one (`false`, highest utilization). The\n * per-row presentation still follows the flags above.\n * @default true\n */\n showAllRules?: boolean;\n}\n\nconst DEFAULT_DISPLAY: Required<UsageBarDisplay> = {\n showValues: false,\n showPercent: true,\n showWindow: true,\n showTier: false,\n showAllRules: true,\n};\n\n/**\n * Usage data handed to a `customUsageBar` renderer so a developer can build\n * their own component with the live consumption / limits.\n */\nexport interface UsageBarData {\n /** Tenant the usage belongs to. */\n tenantId?: string;\n /** Subtenant the usage is scoped to, if any. */\n subtenantId?: string;\n /** Tier (plan) the limits come from, if any. */\n tierId?: string;\n /**\n * Applicable usage rules (filtered by `metric` when set), sorted by\n * utilization descending — the most restrictive first.\n */\n rules: TenantUsageRule[];\n /** `true` until the first fetch resolves. */\n loading: boolean;\n}\n\n/**\n * Props for the UsageBar component.\n */\nexport interface UsageBarProps {\n /** API key (resolved from provider by the ChatDrawer). */\n apiKey?: string;\n /** Base URL (resolved from provider by the ChatDrawer). */\n baseUrl?: string;\n /** Tenant whose usage is displayed. Required — without it the bar renders nothing. */\n tenantId?: string;\n /** Optional subtenant to scope the usage to a specific end user. */\n subtenantId?: string;\n /**\n * Display mode:\n * - 'always': the bar is always visible.\n * - 'onDemand': a small toggle button is shown; the bar appears on click.\n */\n mode?: 'always' | 'onDemand';\n /** Restrict the bar to a single metric. When omitted, all applicable rules are considered. */\n metric?: 'tokens' | 'cost';\n /**\n * What to render per rule (values / percentage / window / tier) and whether\n * to render all applicable rules or only the most restrictive one.\n */\n display?: UsageBarDisplay;\n /**\n * Render your own component instead of the built-in bar(s). Receives the live\n * usage data (rules + tier + loading) and renders in the same slot, replacing\n * the default UI entirely. When set, fetching/polling is still handled here;\n * `mode`/`display` only affect the default UI and are ignored.\n */\n customUsageBar?: (data: UsageBarData) => React.ReactNode;\n /** Primary color for the bar fill (below the warning threshold). */\n color?: string;\n /**\n * Changes to this value trigger a refetch (e.g. the message count, so the bar\n * refreshes after each assistant turn).\n */\n refreshKey?: number | string;\n /** Enable debug logging of fetch errors to the console. */\n debug?: boolean;\n}\n\nconst WARN_THRESHOLD = 90;\n\nfunction fillColor(percent: number, base: string): string {\n if (percent >= 100) return '#ff4d4f';\n if (percent >= WARN_THRESHOLD) return '#faad14';\n return base;\n}\n\nfunction formatAmount(value: number, metric: 'tokens' | 'cost'): string {\n if (metric === 'cost') {\n return `$${value.toFixed(value < 1 ? 4 : 2)}`;\n }\n return Math.round(value).toLocaleString();\n}\n\nfunction windowLabel(unit: string, every: number): string {\n const u = every > 1 ? `${unit}s` : unit;\n return every > 1 ? `every ${every} ${u}` : `per ${unit}`;\n}\n\nfunction resetLabel(resetsAt?: number): string {\n if (!resetsAt) return '';\n const ms = resetsAt - Date.now();\n if (ms <= 0) return 'resets now';\n const mins = Math.round(ms / 60000);\n if (mins < 60) return `resets in ${mins}m`;\n const hours = Math.round(mins / 60);\n if (hours < 48) return `resets in ${hours}h`;\n const days = Math.round(hours / 24);\n return `resets in ${days}d`;\n}\n\n/**\n * A thin usage bar showing the current tenant/subtenant usage window(s).\n * Rendered above the chat input. Antd-free — styled via `.devic-usage-*` classes.\n * Renders nothing when there are no usage limits configured for the tenant.\n */\nexport function UsageBar({\n apiKey,\n baseUrl,\n tenantId,\n subtenantId,\n mode = 'always',\n metric,\n display,\n customUsageBar,\n color = '#1890ff',\n refreshKey,\n debug = false,\n}: UsageBarProps): JSX.Element | null {\n const cfg = useMemo(() => ({ ...DEFAULT_DISPLAY, ...display }), [display]);\n\n const devicContext = useOptionalDevicContext();\n const getTenantSession = devicContext?.getTenantSession;\n const onSessionExpired = devicContext?.onSessionExpired;\n const client = useMemo(() => {\n if (!apiKey && !getTenantSession) return null;\n return new DevicApiClient({\n apiKey,\n baseUrl: baseUrl || 'https://api.devic.ai',\n getTenantSession,\n onSessionExpired,\n });\n }, [apiKey, getTenantSession, baseUrl]);\n\n const [usage, setUsage] = useState<TenantUsage | null>(null);\n const [loaded, setLoaded] = useState(false);\n // onDemand starts hidden; 'always' is effectively visible from the start.\n const [visible, setVisible] = useState(mode !== 'onDemand');\n\n const fetchUsage = useCallback(async () => {\n if (!client || !tenantId) return;\n try {\n const data = await client.getTenantUsage(tenantId, subtenantId);\n setUsage(data || null);\n } catch (err) {\n if (debug) console.warn('[UsageBar] getTenantUsage failed:', err);\n setUsage(null);\n } finally {\n setLoaded(true);\n }\n }, [client, tenantId, subtenantId, debug]);\n\n // A custom renderer always wants the data, regardless of the onDemand toggle.\n const active = !!customUsageBar || visible;\n\n useEffect(() => {\n if (!active) return;\n void fetchUsage();\n }, [active, fetchUsage, refreshKey]);\n\n // Applicable rules: filter by metric, sort most-restrictive first.\n const filteredSorted = useMemo(() => {\n const pool = (usage?.usage || []).filter(\n (r) => !metric || r.metric === metric,\n );\n return [...pool].sort((a, b) => b.percent - a.percent);\n }, [usage, metric]);\n\n // Default UI honours showAllRules; custom renderers always get the full set.\n const rules = useMemo(\n () => (cfg.showAllRules ? filteredSorted : filteredSorted.slice(0, 1)),\n [filteredSorted, cfg.showAllRules],\n );\n\n const tierId = usage?.tierId || filteredSorted[0]?.tierId;\n\n if (!tenantId || !client) return null;\n\n // Custom renderer fully replaces the default UI; hand it the live data.\n if (customUsageBar) {\n return (\n <>\n {customUsageBar({\n tenantId,\n subtenantId,\n tierId,\n rules: filteredSorted,\n loading: !loaded,\n })}\n </>\n );\n }\n\n // onDemand, collapsed: show a small toggle button.\n if (mode === 'onDemand' && !visible) {\n return (\n <div className=\"devic-usage-bar-wrap\" data-mode=\"onDemand\">\n <button\n type=\"button\"\n className=\"devic-usage-toggle\"\n onClick={() => setVisible(true)}\n title=\"Show usage\"\n >\n <GaugeIcon />\n <span>Usage</span>\n </button>\n </div>\n );\n }\n\n // No configured limits (or not loaded yet with nothing to show): render nothing\n // in 'always' mode; in expanded onDemand, show a subtle note so the toggle isn't\n // confusing.\n if (rules.length === 0) {\n if (mode === 'onDemand' && loaded) {\n return (\n <div className=\"devic-usage-bar-wrap\" data-mode=\"onDemand\">\n <div className=\"devic-usage-bar\" data-empty=\"true\">\n <span className=\"devic-usage-bar-label\">No usage limits</span>\n <button\n type=\"button\"\n className=\"devic-usage-collapse\"\n onClick={() => setVisible(false)}\n title=\"Hide usage\"\n aria-label=\"Hide usage\"\n >\n ×\n </button>\n </div>\n </div>\n );\n }\n return null;\n }\n\n const showTierChip = cfg.showTier && !!tierId;\n const multi = rules.length > 1;\n // A header carries the tier chip and/or the onDemand collapse control, so the\n // collapse \"×\" has a stable home regardless of how many rows render below.\n const header =\n showTierChip || mode === 'onDemand' ? (\n <div className=\"devic-usage-bar-head\">\n {showTierChip ? (\n <span className=\"devic-usage-tier\" title={`Tier: ${tierId}`}>\n {tierId}\n </span>\n ) : (\n <span />\n )}\n {mode === 'onDemand' && (\n <button\n type=\"button\"\n className=\"devic-usage-collapse\"\n onClick={() => setVisible(false)}\n title=\"Hide usage\"\n aria-label=\"Hide usage\"\n >\n ×\n </button>\n )}\n </div>\n ) : null;\n\n return (\n <div className=\"devic-usage-bar-wrap\" data-mode={mode}>\n {header}\n {/* All rows share a single container by default. */}\n <div className=\"devic-usage-bar-group\">\n {rules.map((rule, i) => {\n const pct = Math.min(100, Math.round(rule.percent));\n const fill = fillColor(pct, color);\n const valuesText = `${formatAmount(rule.current, rule.metric)} / ${formatAmount(\n rule.limit,\n rule.metric,\n )} ${rule.metric}`;\n // Distinguish rows by metric when several render; otherwise use the\n // scope-aware label so single-rule mode reads \"Usage 24%\".\n const prefix = multi\n ? rule.metric === 'cost'\n ? 'Cost'\n : 'Tokens'\n : rule.scope === 'subtenant'\n ? 'Your usage'\n : 'Usage';\n const main: string[] = [];\n if (cfg.showPercent) main.push(`${pct}%`);\n if (cfg.showValues) main.push(valuesText);\n if (main.length === 0) main.push(`${pct}%`);\n const label = `${prefix} ${main.join(' · ')}`.trim();\n const reset = resetLabel(rule.resetsAt);\n const win = windowLabel(rule.windowUnit, rule.windowEvery);\n const title = `${valuesText} · ${win}${reset ? ` · ${reset}` : ''}`;\n\n return (\n <div\n key={`${rule.metric}-${rule.windowUnit}-${rule.windowEvery}-${rule.scope}-${i}`}\n className=\"devic-usage-bar\"\n title={title}\n data-state={pct >= 100 ? 'exceeded' : 'ok'}\n >\n <span className=\"devic-usage-bar-label\">{label}</span>\n <div className=\"devic-usage-bar-track\">\n <div\n className=\"devic-usage-bar-fill\"\n style={{ width: `${pct}%`, backgroundColor: fill }}\n />\n </div>\n {cfg.showWindow && (\n <span className=\"devic-usage-bar-window\">{win}</span>\n )}\n {reset && <span className=\"devic-usage-bar-reset\">{reset}</span>}\n </div>\n );\n })}\n </div>\n </div>\n );\n}\n\n/** Small gauge icon for the on-demand toggle. */\nfunction GaugeIcon(): JSX.Element {\n return (\n <svg\n width=\"14\"\n height=\"14\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"2\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n >\n <path d=\"M12 14a4 4 0 1 0-4-4\" />\n <path d=\"M3 18a9 9 0 0 1 18 0\" />\n <line x1=\"12\" y1=\"14\" x2=\"15\" y2=\"11\" />\n </svg>\n );\n}\n"],"names":["useMemo","useOptionalDevicContext","client","DevicApiClient","useState","useCallback","useEffect","_jsx","_Fragment","_jsxs"],"mappings":";;;;;;;AAwCA,MAAM,eAAe,GAA8B;AACjD,IAAA,UAAU,EAAE,KAAK;AACjB,IAAA,WAAW,EAAE,IAAI;AACjB,IAAA,UAAU,EAAE,IAAI;AAChB,IAAA,QAAQ,EAAE,KAAK;AACf,IAAA,YAAY,EAAE,IAAI;CACnB;AAiED,MAAM,cAAc,GAAG,EAAE;AAEzB,SAAS,SAAS,CAAC,OAAe,EAAE,IAAY,EAAA;IAC9C,IAAI,OAAO,IAAI,GAAG;AAAE,QAAA,OAAO,SAAS;IACpC,IAAI,OAAO,IAAI,cAAc;AAAE,QAAA,OAAO,SAAS;AAC/C,IAAA,OAAO,IAAI;AACb;AAEA,SAAS,YAAY,CAAC,KAAa,EAAE,MAAyB,E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yBAAM,EAAE,EAAC,IAAI,EAAC,EAAE,EAAC,IAAI,EAAC,EAAE,EAAC,IAAI,EAAC,EAAE,EAAC,IAAI,EAAA,CAAG,CAAA,EAAA,CACpC;AAEV;;"}
|
|
1
|
+
{"version":3,"file":"UsageBar.js","sources":["../../../../../src/components/ChatDrawer/UsageBar.tsx"],"sourcesContent":["import React, { useCallback, useEffect, useMemo, useState } from 'react';\nimport { useOptionalDevicContext } from '../../provider';\nimport { DevicApiClient } from '../../api/client';\nimport type { TenantUsage, TenantUsageRule } from '../../api/types';\nimport { useTranslations } from '../../i18n';\nimport type { Translator } from '../../i18n';\n\n/**\n * Controls what each usage row renders. All flags compose, so a developer can,\n * for example, show absolute values together with the percentage and the tier.\n */\nexport interface UsageBarDisplay {\n /**\n * Show the absolute amount of the active window: `current / limit metric`\n * (e.g. `1,200 / 5,000 tokens`).\n * @default false\n */\n showValues?: boolean;\n /**\n * Show the utilization percentage (e.g. `24%`).\n * @default true\n */\n showPercent?: boolean;\n /**\n * Show the temporal dimension of the window (e.g. `per 3h`, `every 3 hours`).\n * @default true\n */\n showWindow?: boolean;\n /**\n * Show the tier (plan) the limits come from, as a chip above the bar(s).\n * @default false\n */\n showTier?: boolean;\n /**\n * When more than one limit rule applies, render every rule (`true`) or only\n * the single most restrictive one (`false`, highest utilization). The\n * per-row presentation still follows the flags above.\n * @default true\n */\n showAllRules?: boolean;\n}\n\nconst DEFAULT_DISPLAY: Required<UsageBarDisplay> = {\n showValues: false,\n showPercent: true,\n showWindow: true,\n showTier: false,\n showAllRules: true,\n};\n\n/**\n * Usage data handed to a `customUsageBar` renderer so a developer can build\n * their own component with the live consumption / limits.\n */\nexport interface UsageBarData {\n /** Tenant the usage belongs to. */\n tenantId?: string;\n /** Subtenant the usage is scoped to, if any. */\n subtenantId?: string;\n /** Tier (plan) the limits come from, if any. */\n tierId?: string;\n /**\n * Applicable usage rules (filtered by `metric` when set), sorted by\n * utilization descending — the most restrictive first.\n */\n rules: TenantUsageRule[];\n /** `true` until the first fetch resolves. */\n loading: boolean;\n}\n\n/**\n * Props for the UsageBar component.\n */\nexport interface UsageBarProps {\n /** API key (resolved from provider by the ChatDrawer). */\n apiKey?: string;\n /** Base URL (resolved from provider by the ChatDrawer). */\n baseUrl?: string;\n /** Tenant whose usage is displayed. Required — without it the bar renders nothing. */\n tenantId?: string;\n /** Optional subtenant to scope the usage to a specific end user. */\n subtenantId?: string;\n /**\n * Display mode:\n * - 'always': the bar is always visible.\n * - 'onDemand': a small toggle button is shown; the bar appears on click.\n */\n mode?: 'always' | 'onDemand';\n /** Restrict the bar to a single metric. When omitted, all applicable rules are considered. */\n metric?: 'tokens' | 'cost';\n /**\n * What to render per rule (values / percentage / window / tier) and whether\n * to render all applicable rules or only the most restrictive one.\n */\n display?: UsageBarDisplay;\n /**\n * Render your own component instead of the built-in bar(s). Receives the live\n * usage data (rules + tier + loading) and renders in the same slot, replacing\n * the default UI entirely. When set, fetching/polling is still handled here;\n * `mode`/`display` only affect the default UI and are ignored.\n */\n customUsageBar?: (data: UsageBarData) => React.ReactNode;\n /** Primary color for the bar fill (below the warning threshold). */\n color?: string;\n /**\n * Changes to this value trigger a refetch (e.g. the message count, so the bar\n * refreshes after each assistant turn).\n */\n refreshKey?: number | string;\n /** Enable debug logging of fetch errors to the console. */\n debug?: boolean;\n}\n\nconst WARN_THRESHOLD = 90;\n\nfunction fillColor(percent: number, base: string): string {\n if (percent >= 100) return '#ff4d4f';\n if (percent >= WARN_THRESHOLD) return '#faad14';\n return base;\n}\n\nfunction formatAmount(value: number, metric: 'tokens' | 'cost'): string {\n if (metric === 'cost') {\n return `$${value.toFixed(value < 1 ? 4 : 2)}`;\n }\n return Math.round(value).toLocaleString();\n}\n\n// The unit names are translated on their own so a dictionary can decline\n// them; the sentence around them is a separate entry with placeholders, which\n// is what a language with a different word order needs.\nfunction windowLabel(t: Translator, unit: string, every: number): string {\n const u = every > 1 ? t(`{count} ${unit}s`, { count: every }) : t(unit);\n return every > 1 ? t('every {window}', { window: u }) : t('per {window}', { window: u });\n}\n\nfunction resetLabel(t: Translator, resetsAt?: number): string {\n if (!resetsAt) return '';\n const ms = resetsAt - Date.now();\n if (ms <= 0) return t('resets now');\n const mins = Math.round(ms / 60000);\n if (mins < 60) return t('resets in {count}m', { count: mins });\n const hours = Math.round(mins / 60);\n if (hours < 48) return t('resets in {count}h', { count: hours });\n const days = Math.round(hours / 24);\n return t('resets in {count}d', { count: days });\n}\n\n/**\n * A thin usage bar showing the current tenant/subtenant usage window(s).\n * Rendered above the chat input. Antd-free — styled via `.devic-usage-*` classes.\n * Renders nothing when there are no usage limits configured for the tenant.\n */\nexport function UsageBar({\n apiKey,\n baseUrl,\n tenantId,\n subtenantId,\n mode = 'always',\n metric,\n display,\n customUsageBar,\n color = '#1890ff',\n refreshKey,\n debug = false,\n}: UsageBarProps): JSX.Element | null {\n const t = useTranslations();\n const cfg = useMemo(() => ({ ...DEFAULT_DISPLAY, ...display }), [display]);\n\n const devicContext = useOptionalDevicContext();\n const getTenantSession = devicContext?.getTenantSession;\n const onSessionExpired = devicContext?.onSessionExpired;\n const client = useMemo(() => {\n if (!apiKey && !getTenantSession) return null;\n return new DevicApiClient({\n apiKey,\n baseUrl: baseUrl || 'https://api.devic.ai',\n getTenantSession,\n onSessionExpired,\n });\n }, [apiKey, getTenantSession, baseUrl]);\n\n const [usage, setUsage] = useState<TenantUsage | null>(null);\n const [loaded, setLoaded] = useState(false);\n // onDemand starts hidden; 'always' is effectively visible from the start.\n const [visible, setVisible] = useState(mode !== 'onDemand');\n\n const fetchUsage = useCallback(async () => {\n if (!client || !tenantId) return;\n try {\n const data = await client.getTenantUsage(tenantId, subtenantId);\n setUsage(data || null);\n } catch (err) {\n if (debug) console.warn('[UsageBar] getTenantUsage failed:', err);\n setUsage(null);\n } finally {\n setLoaded(true);\n }\n }, [client, tenantId, subtenantId, debug]);\n\n // A custom renderer always wants the data, regardless of the onDemand toggle.\n const active = !!customUsageBar || visible;\n\n useEffect(() => {\n if (!active) return;\n void fetchUsage();\n }, [active, fetchUsage, refreshKey]);\n\n // Applicable rules: filter by metric, sort most-restrictive first.\n const filteredSorted = useMemo(() => {\n const pool = (usage?.usage || []).filter(\n (r) => !metric || r.metric === metric,\n );\n return [...pool].sort((a, b) => b.percent - a.percent);\n }, [usage, metric]);\n\n // Default UI honours showAllRules; custom renderers always get the full set.\n const rules = useMemo(\n () => (cfg.showAllRules ? filteredSorted : filteredSorted.slice(0, 1)),\n [filteredSorted, cfg.showAllRules],\n );\n\n const tierId = usage?.tierId || filteredSorted[0]?.tierId;\n\n if (!tenantId || !client) return null;\n\n // Custom renderer fully replaces the default UI; hand it the live data.\n if (customUsageBar) {\n return (\n <>\n {customUsageBar({\n tenantId,\n subtenantId,\n tierId,\n rules: filteredSorted,\n loading: !loaded,\n })}\n </>\n );\n }\n\n // onDemand, collapsed: show a small toggle button.\n if (mode === 'onDemand' && !visible) {\n return (\n <div className=\"devic-usage-bar-wrap\" data-mode=\"onDemand\">\n <button\n type=\"button\"\n className=\"devic-usage-toggle\"\n onClick={() => setVisible(true)}\n title={t('Show usage')}\n >\n <GaugeIcon />\n <span>{t('Usage')}</span>\n </button>\n </div>\n );\n }\n\n // No configured limits (or not loaded yet with nothing to show): render nothing\n // in 'always' mode; in expanded onDemand, show a subtle note so the toggle isn't\n // confusing.\n if (rules.length === 0) {\n if (mode === 'onDemand' && loaded) {\n return (\n <div className=\"devic-usage-bar-wrap\" data-mode=\"onDemand\">\n <div className=\"devic-usage-bar\" data-empty=\"true\">\n <span className=\"devic-usage-bar-label\">\n {t('No usage limits')}\n </span>\n <button\n type=\"button\"\n className=\"devic-usage-collapse\"\n onClick={() => setVisible(false)}\n title={t('Hide usage')}\n aria-label={t('Hide usage')}\n >\n ×\n </button>\n </div>\n </div>\n );\n }\n return null;\n }\n\n const showTierChip = cfg.showTier && !!tierId;\n const multi = rules.length > 1;\n // A header carries the tier chip and/or the onDemand collapse control, so the\n // collapse \"×\" has a stable home regardless of how many rows render below.\n const header =\n showTierChip || mode === 'onDemand' ? (\n <div className=\"devic-usage-bar-head\">\n {showTierChip ? (\n <span className=\"devic-usage-tier\" title={t('Tier: {tier}', { tier: tierId })}>\n {tierId}\n </span>\n ) : (\n <span />\n )}\n {mode === 'onDemand' && (\n <button\n type=\"button\"\n className=\"devic-usage-collapse\"\n onClick={() => setVisible(false)}\n title={t('Hide usage')}\n aria-label={t('Hide usage')}\n >\n ×\n </button>\n )}\n </div>\n ) : null;\n\n return (\n <div className=\"devic-usage-bar-wrap\" data-mode={mode}>\n {header}\n {/* All rows share a single container by default. */}\n <div className=\"devic-usage-bar-group\">\n {rules.map((rule, i) => {\n const pct = Math.min(100, Math.round(rule.percent));\n const fill = fillColor(pct, color);\n const valuesText = `${formatAmount(rule.current, rule.metric)} / ${formatAmount(\n rule.limit,\n rule.metric,\n )} ${t(rule.metric)}`;\n // Distinguish rows by metric when several render; otherwise use the\n // scope-aware label so single-rule mode reads \"Usage 24%\".\n const prefix = multi\n ? rule.metric === 'cost'\n ? t('Cost')\n : t('Tokens')\n : rule.scope === 'subtenant'\n ? t('Your usage')\n : t('Usage');\n const main: string[] = [];\n if (cfg.showPercent) main.push(`${pct}%`);\n if (cfg.showValues) main.push(valuesText);\n if (main.length === 0) main.push(`${pct}%`);\n const label = `${prefix} ${main.join(' · ')}`.trim();\n const reset = resetLabel(t, rule.resetsAt);\n const win = windowLabel(t, rule.windowUnit, rule.windowEvery);\n const title = `${valuesText} · ${win}${reset ? ` · ${reset}` : ''}`;\n\n return (\n <div\n key={`${rule.metric}-${rule.windowUnit}-${rule.windowEvery}-${rule.scope}-${i}`}\n className=\"devic-usage-bar\"\n title={title}\n data-state={pct >= 100 ? 'exceeded' : 'ok'}\n >\n <span className=\"devic-usage-bar-label\">{label}</span>\n <div className=\"devic-usage-bar-track\">\n <div\n className=\"devic-usage-bar-fill\"\n style={{ width: `${pct}%`, backgroundColor: fill }}\n />\n </div>\n {cfg.showWindow && (\n <span className=\"devic-usage-bar-window\">{win}</span>\n )}\n {reset && <span className=\"devic-usage-bar-reset\">{reset}</span>}\n </div>\n );\n })}\n </div>\n </div>\n );\n}\n\n/** Small gauge icon for the on-demand toggle. */\nfunction GaugeIcon(): JSX.Element {\n return (\n <svg\n width=\"14\"\n height=\"14\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"2\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n >\n <path d=\"M12 14a4 4 0 1 0-4-4\" />\n <path d=\"M3 18a9 9 0 0 1 18 0\" />\n <line x1=\"12\" y1=\"14\" x2=\"15\" y2=\"11\" />\n </svg>\n );\n}\n"],"names":["useTranslations","useMemo","useOptionalDevicContext","client","DevicApiClient","useState","useCallback","useEffect","_jsx","_Fragment","_jsxs"],"mappings":";;;;;;;;AA0CA,MAAM,eAAe,GAA8B;AACjD,IAAA,UAAU,EAAE,KAAK;AACjB,IAAA,WAAW,EAAE,IAAI;AACjB,IAAA,UAAU,EAAE,IAAI;AAChB,IAAA,QAAQ,EAAE,KAAK;AACf,IAAA,YAAY,EAAE,IAAI;CACnB;AAiED,MAAM,cAAc,GAAG,EAAE;AAEzB,SAAS,SAAS,CAAC,OAAe,EAAE,IAAY,EAAA;IAC9C,IAAI,OAAO,IAAI,GAAG;AAAE,QAAA,OAAO,SAAS;IACpC,IAAI,OAAO,IAAI,cAAc;AAAE,QAAA,OAAO,SAAS;AAC/C,IAAA,OAAO,IAAI;AACb;AAEA,SAAS,YAAY,CAAC,KAAa,EAAE,MAAyB,EAAA;AAC5D,IAAA,IAAI,MAAM,KAAK,MAAM,EAAE;AACrB,QAAA,OAAO,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,EAAE;IAC/C;IACA,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,cAAc,EAAE;AAC3C;AAEA;AACA;AACA;AACA,SAAS,WAAW,CAAC,CA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OAAO,EAAC,WAAW,EACnB,IAAI,EAAC,MAAM,EACX,MAAM,EAAC,cAAc,EACrB,WAAW,EAAC,GAAG,EACf,aAAa,EAAC,OAAO,EACrB,cAAc,EAAC,OAAO,EAAA,QAAA,EAAA,CAEtBF,cAAA,CAAA,MAAA,EAAA,EAAM,CAAC,EAAC,sBAAsB,EAAA,CAAG,EACjCA,cAAA,CAAA,MAAA,EAAA,EAAM,CAAC,EAAC,sBAAsB,EAAA,CAAG,EACjCA,yBAAM,EAAE,EAAC,IAAI,EAAC,EAAE,EAAC,IAAI,EAAC,EAAE,EAAC,IAAI,EAAC,EAAE,EAAC,IAAI,EAAA,CAAG,CAAA,EAAA,CACpC;AAEV;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pastedText.js","sources":["../../../../../src/components/ChatDrawer/pastedText.ts"],"sourcesContent":["/**\n * Shared contract for long blocks of pasted text.\n *\n * A long paste is shown in the prompt box as an attachment card instead of\n * flooding the textarea, but its content still reaches the model in full: on\n * send it is prepended to the message inside a <pasted-text> block. The thread\n * parses those blocks back out so the bubble shows a card too, rather than\n * thousands of lines of raw text.\n *\n * Both sides of that round-trip live here so they can never drift apart.\n */\n\nexport interface PastedText {\n id: string;\n text: string;\n}\n\n/**\n * A pasted block could itself contain the literal closing tag (pasting this\n * very file, say), which would truncate the block when parsed back. Escaping it\n * on the way out keeps the round-trip exact and still reads as the intended\n * text to the model.\n */\nconst CLOSING_TAG = '</pasted-text>';\nconst ESCAPED_CLOSING_TAG = '<\\\\/pasted-text>';\n\nconst PASTED_BLOCK_RE = /<pasted-text id=\"([^\"]*)\">\\n([\\s\\S]*?)\\n<\\/pasted-text>/g;\n\n/** Serialize a pasted block for the message sent to the assistant. */\nexport function toPastedBlock({ id, text }: PastedText): string {\n const escaped = text.split(CLOSING_TAG).join(ESCAPED_CLOSING_TAG);\n return `<pasted-text id=\"${id}\">\\n${escaped}\\n${CLOSING_TAG}`;\n}\n\n/**\n * Pull the pasted blocks out of a user message, returning them alongside the\n * message with those blocks removed. Returns null when there are none, so\n * callers can keep rendering untouched messages exactly as before.\n */\nexport function parsePastedBlocks(\n content: string\n): { blocks: PastedText[]; cleanContent: string } | null {\n const blocks: PastedText[] = [];\n const cleanContent = content\n .replace(PASTED_BLOCK_RE, (_match, id: string, text: string) => {\n blocks.push({\n id,\n text: text.split(ESCAPED_CLOSING_TAG).join(CLOSING_TAG),\n });\n return '';\n })\n .trim();\n\n if (blocks.length === 0) return null;\n return { blocks, cleanContent };\n}\n\n/** Short, single-line-ish excerpt shown on the collapsed card. */\nexport function pastedPreview(text: string, maxChars = 160): string {\n const collapsed = text.replace(/\\s+/g, ' ').trim();\n return collapsed.length > maxChars\n ? `${collapsed.slice(0, maxChars)}…`\n : collapsed;\n}\n\n/** Line count shown on the card, mirroring how editors report a selection. */\nexport function pastedLineCount(text: string): number {\n return text.split('\\n').length;\n}\n"],"names":[],"mappings":";;AAAA;;;;;;;;;;AAUG;AAOH;;;;;AAKG;AACH,MAAM,WAAW,GAAG,gBAAgB;AACpC,MAAM,mBAAmB,GAAG,kBAAkB;AAE9C,MAAM,eAAe,GAAG,0DAA0D;AAElF;SACgB,aAAa,CAAC,EAAE,EAAE,EAAE,IAAI,EAAc,EAAA;AACpD,IAAA,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,mBAAmB,CAAC;AACjE,IAAA,OAAO,oBAAoB,EAAE,CAAA,IAAA,EAAO,OAAO,CAAA,EAAA,EAAK,WAAW,EAAE;AAC/D;AAEA;;;;AAIG;AACG,SAAU,iBAAiB,CAC/B,OAAe,EAAA;IAEf,MAAM,MAAM,GAAiB,EAAE;IAC/B,MAAM,YAAY,GAAG;SAClB,OAAO,CAAC,eAAe,EAAE,CAAC,MAAM,EAAE,EAAU,EAAE,IAAY,KAAI;QAC7D,MAAM,CAAC,IAAI,CAAC;YACV,EAAE;YACF,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,mBAAmB,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC;AACxD,SAAA,CAAC;AACF,QAAA,OAAO,EAAE;AACX,IAAA,CAAC;AACA,SAAA,IAAI,EAAE;AAET,IAAA,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC;AAAE,QAAA,OAAO,IAAI;AACpC,IAAA,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE;AACjC;AAEA;SACgB,aAAa,CAAC,IAAY,EAAE,QAAQ,GAAG,GAAG,EAAA;AACxD,IAAA,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,IAAI,EAAE;AAClD,IAAA,OAAO,SAAS,CAAC,MAAM,GAAG;UACtB,CAAA,EAAG,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAA,CAAA;UAC/B,SAAS;AACf;AAEA;AACM,SAAU,eAAe,CAAC,IAAY,EAAA;IAC1C,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,MAAM;AAChC
|
|
1
|
+
{"version":3,"file":"pastedText.js","sources":["../../../../../src/components/ChatDrawer/pastedText.ts"],"sourcesContent":["/**\n * Shared contract for long blocks of pasted text.\n *\n * A long paste is shown in the prompt box as an attachment card instead of\n * flooding the textarea, but its content still reaches the model in full: on\n * send it is prepended to the message inside a <pasted-text> block. The thread\n * parses those blocks back out so the bubble shows a card too, rather than\n * thousands of lines of raw text.\n *\n * Both sides of that round-trip live here so they can never drift apart.\n */\n\nexport interface PastedText {\n id: string;\n text: string;\n}\n\n/**\n * A pasted block could itself contain the literal closing tag (pasting this\n * very file, say), which would truncate the block when parsed back. Escaping it\n * on the way out keeps the round-trip exact and still reads as the intended\n * text to the model.\n */\nconst CLOSING_TAG = '</pasted-text>';\nconst ESCAPED_CLOSING_TAG = '<\\\\/pasted-text>';\n\nconst PASTED_BLOCK_RE = /<pasted-text id=\"([^\"]*)\">\\n([\\s\\S]*?)\\n<\\/pasted-text>/g;\n\n/** Serialize a pasted block for the message sent to the assistant. */\nexport function toPastedBlock({ id, text }: PastedText): string {\n const escaped = text.split(CLOSING_TAG).join(ESCAPED_CLOSING_TAG);\n return `<pasted-text id=\"${id}\">\\n${escaped}\\n${CLOSING_TAG}`;\n}\n\n/**\n * Pull the pasted blocks out of a user message, returning them alongside the\n * message with those blocks removed. Returns null when there are none, so\n * callers can keep rendering untouched messages exactly as before.\n */\nexport function parsePastedBlocks(\n content: string\n): { blocks: PastedText[]; cleanContent: string } | null {\n const blocks: PastedText[] = [];\n const cleanContent = content\n .replace(PASTED_BLOCK_RE, (_match, id: string, text: string) => {\n blocks.push({\n id,\n text: text.split(ESCAPED_CLOSING_TAG).join(CLOSING_TAG),\n });\n return '';\n })\n .trim();\n\n if (blocks.length === 0) return null;\n return { blocks, cleanContent };\n}\n\n/** Short, single-line-ish excerpt shown on the collapsed card. */\nexport function pastedPreview(text: string, maxChars = 160): string {\n const collapsed = text.replace(/\\s+/g, ' ').trim();\n return collapsed.length > maxChars\n ? `${collapsed.slice(0, maxChars)}…`\n : collapsed;\n}\n\n/** Line count shown on the card, mirroring how editors report a selection. */\nexport function pastedLineCount(text: string): number {\n return text.split('\\n').length;\n}\n"],"names":[],"mappings":";;AAAA;;;;;;;;;;AAUG;AAOH;;;;;AAKG;AACH,MAAM,WAAW,GAAG,gBAAgB;AACpC,MAAM,mBAAmB,GAAG,kBAAkB;AAE9C,MAAM,eAAe,GAAG,0DAA0D;AAElF;SACgB,aAAa,CAAC,EAAE,EAAE,EAAE,IAAI,EAAc,EAAA;AACpD,IAAA,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,mBAAmB,CAAC;AACjE,IAAA,OAAO,oBAAoB,EAAE,CAAA,IAAA,EAAO,OAAO,CAAA,EAAA,EAAK,WAAW,EAAE;AAC/D;AAEA;;;;AAIG;AACG,SAAU,iBAAiB,CAC/B,OAAe,EAAA;IAEf,MAAM,MAAM,GAAiB,EAAE;IAC/B,MAAM,YAAY,GAAG;SAClB,OAAO,CAAC,eAAe,EAAE,CAAC,MAAM,EAAE,EAAU,EAAE,IAAY,KAAI;QAC7D,MAAM,CAAC,IAAI,CAAC;YACV,EAAE;YACF,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,mBAAmB,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC;AACxD,SAAA,CAAC;AACF,QAAA,OAAO,EAAE;AACX,IAAA,CAAC;AACA,SAAA,IAAI,EAAE;AAET,IAAA,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC;AAAE,QAAA,OAAO,IAAI;AACpC,IAAA,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE;AACjC;AAEA;SACgB,aAAa,CAAC,IAAY,EAAE,QAAQ,GAAG,GAAG,EAAA;AACxD,IAAA,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,IAAI,EAAE;AAClD,IAAA,OAAO,SAAS,CAAC,MAAM,GAAG;UACtB,CAAA,EAAG,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAA,CAAA;UAC/B,SAAS;AACf;AAEA;AACM,SAAU,eAAe,CAAC,IAAY,EAAA;IAC1C,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,MAAM;AAChC;;;;;;;"}
|
|
@@ -6,6 +6,7 @@ var reactDom = require('react-dom');
|
|
|
6
6
|
var client = require('../../api/client.js');
|
|
7
7
|
var DevicContext = require('../../provider/DevicContext.js');
|
|
8
8
|
var theme = require('../theme.js');
|
|
9
|
+
var useTranslations = require('../../i18n/useTranslations.js');
|
|
9
10
|
|
|
10
11
|
/** Canonical sections of the core tier, in display order. */
|
|
11
12
|
const SECTIONS = ["persona", "instructions", "decisions", "profile"];
|
|
@@ -49,15 +50,25 @@ function PinIcon() {
|
|
|
49
50
|
* the API key needs that endpoint allowed.
|
|
50
51
|
*/
|
|
51
52
|
function CoreMemoryModal({ isOpen, onClose, assistantId, tenantId, subtenantId, apiKey, baseUrl, editable = true, title, labels, theme: theme$1, }) {
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
53
|
+
const t = useTranslations.useTranslations();
|
|
54
|
+
// Three layers, narrowest first: the `labels` this host passed, then the
|
|
55
|
+
// dictionary, then English. `labels` stays authoritative — a host that
|
|
56
|
+
// already spells this dialog out itself must not have it changed underneath
|
|
57
|
+
// by a page-wide dictionary.
|
|
58
|
+
const l = React.useMemo(() => {
|
|
59
|
+
const translated = Object.fromEntries(Object.entries(DEFAULT_CORE_MEMORY_LABELS)
|
|
60
|
+
.filter(([, value]) => typeof value === "string")
|
|
61
|
+
.map(([key, value]) => [key, t(value)]));
|
|
62
|
+
return {
|
|
63
|
+
...translated,
|
|
64
|
+
...labels,
|
|
65
|
+
title: labels?.title ?? title ?? t(DEFAULT_CORE_MEMORY_LABELS.title),
|
|
66
|
+
sections: {
|
|
67
|
+
...Object.fromEntries(Object.entries(DEFAULT_CORE_MEMORY_LABELS.sections).map(([key, value]) => [key, t(value)])),
|
|
68
|
+
...labels?.sections,
|
|
69
|
+
},
|
|
70
|
+
};
|
|
71
|
+
}, [labels, title, t]);
|
|
61
72
|
const context = DevicContext.useOptionalDevicContext();
|
|
62
73
|
const resolvedBaseUrl = baseUrl || context?.baseUrl || "https://api.devic.ai";
|
|
63
74
|
const resolvedTenantId = tenantId || context?.tenantId;
|