@devicai/ui 0.57.0 → 0.58.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 +162 -0
- package/dist/cjs/api/types.js.map +1 -1
- package/dist/cjs/components/AICommandBar/AICommandBar.js +10 -7
- package/dist/cjs/components/AICommandBar/AICommandBar.js.map +1 -1
- package/dist/cjs/components/AICommandBar/useAICommandBar.js +7 -5
- package/dist/cjs/components/AICommandBar/useAICommandBar.js.map +1 -1
- package/dist/cjs/components/AIElementWrapper/AIElementWrapper.js +17 -14
- package/dist/cjs/components/AIElementWrapper/AIElementWrapper.js.map +1 -1
- package/dist/cjs/components/AIElementWrapper/useAIElementWrapper.js +7 -5
- package/dist/cjs/components/AIElementWrapper/useAIElementWrapper.js.map +1 -1
- package/dist/cjs/components/AIGenerationButton/AIGenerationButton.js +11 -6
- package/dist/cjs/components/AIGenerationButton/AIGenerationButton.js.map +1 -1
- package/dist/cjs/components/AIGenerationButton/useAIGenerationButton.js +6 -4
- package/dist/cjs/components/AIGenerationButton/useAIGenerationButton.js.map +1 -1
- package/dist/cjs/components/ChatDrawer/ChatDrawer.js +26 -12
- 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/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/UsageBar.js +23 -18
- package/dist/cjs/components/ChatDrawer/UsageBar.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/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/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/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/hooks/useDevicChat.js +11 -5
- package/dist/cjs/hooks/useDevicChat.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/DevicProvider.js +3 -1
- package/dist/cjs/provider/DevicProvider.js.map +1 -1
- package/dist/cjs/styles.css +1 -1
- package/dist/esm/api/types.d.ts +10 -1
- package/dist/esm/api/types.js.map +1 -1
- package/dist/esm/components/AICommandBar/AICommandBar.js +11 -8
- package/dist/esm/components/AICommandBar/AICommandBar.js.map +1 -1
- package/dist/esm/components/AICommandBar/AICommandBar.types.d.ts +10 -0
- package/dist/esm/components/AICommandBar/useAICommandBar.js +7 -5
- package/dist/esm/components/AICommandBar/useAICommandBar.js.map +1 -1
- package/dist/esm/components/AIElementWrapper/AIElementWrapper.js +17 -14
- package/dist/esm/components/AIElementWrapper/AIElementWrapper.js.map +1 -1
- package/dist/esm/components/AIElementWrapper/AIElementWrapper.types.d.ts +10 -0
- package/dist/esm/components/AIElementWrapper/useAIElementWrapper.js +7 -5
- package/dist/esm/components/AIElementWrapper/useAIElementWrapper.js.map +1 -1
- package/dist/esm/components/AIGenerationButton/AIGenerationButton.js +12 -7
- package/dist/esm/components/AIGenerationButton/AIGenerationButton.js.map +1 -1
- package/dist/esm/components/AIGenerationButton/AIGenerationButton.types.d.ts +10 -0
- package/dist/esm/components/AIGenerationButton/useAIGenerationButton.js +6 -4
- package/dist/esm/components/AIGenerationButton/useAIGenerationButton.js.map +1 -1
- package/dist/esm/components/ChatDrawer/ChatDrawer.js +27 -13
- package/dist/esm/components/ChatDrawer/ChatDrawer.js.map +1 -1
- package/dist/esm/components/ChatDrawer/ChatDrawer.types.d.ts +33 -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/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/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/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/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/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/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/hooks/useDevicChat.js +12 -6
- package/dist/esm/hooks/useDevicChat.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/DevicProvider.d.ts +1 -1
- package/dist/esm/provider/DevicProvider.js +3 -1
- package/dist/esm/provider/DevicProvider.js.map +1 -1
- package/dist/esm/provider/types.d.ts +33 -0
- package/dist/esm/styles.css +1 -1
- package/package.json +1 -1
|
@@ -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","_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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,EAPC,CAAC,CAQL,CACP,CAAC,EAAA,CACE,CACP,EAEA,QAAQ,CAAC,MAAM,GAAG,CAAC,KAClBC,GAAA,CAAA,KAAA,EAAA,EAAK,SAAS,EAAC,uBAAuB,EAAA,QAAA,EACnC,QAAQ,CAAC,GAAG,CAAC,CAAC,MAAM,MACnBD,IAAA,CAAA,MAAA,EAAA,EAEE,SAAS,EAAC,qBAAqB,EAC/B,KAAK,EAAE,MAAM,CAAC,OAAO,IAAI,SAAS,aAEjC,MAAM,CAAC,IAAI,EACZA,eAAM,SAAS,EAAC,0BAA0B,EAAA,QAAA,EAAA,CACvC,GAAG,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,IAAA,CAAA,KAAA,EAAA,EAAK,SAAS,EAAC,oBAAoB,EAAA,QAAA,EAAA,CACjCC,GAAA,CAAA,MAAA,EAAA,EAAM,SAAS,EAAC,0BAA0B,EAAA,QAAA,EAAA,0BAAA,EAAA,CAEnC,EACN,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC,MACjBD,IAAA,CAAA,MAAA,EAAA,EAAc,SAAS,EAAC,mBAAmB,aACzCA,IAAA,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 R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D,IAAA,CAAA,MAAA,EAAA,EAAc,SAAS,EAAC,mBAAmB,EAAA,QAAA,EAAA,CACzCA,IAAA,CAAA,MAAA,EAAA,EAAM,SAAS,EAAC,wBAAwB,EAAA,QAAA,EAAA,CAAE,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,CAAA,EAAA,CACG,CACP,CAAA,EAAA,CACG;AAEV;;"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
2
|
+
import { useTranslations } from '../../i18n/useTranslations.js';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* Reusable chip node for an AIElementWrapper reference. Shared by the
|
|
@@ -7,10 +8,11 @@ import { jsxs, jsx } from 'react/jsx-runtime';
|
|
|
7
8
|
* exact same chip markup and styling.
|
|
8
9
|
*/
|
|
9
10
|
function ReferenceChip({ label, onRemove, variant = "input", icon, className, }) {
|
|
11
|
+
const t = useTranslations();
|
|
10
12
|
const base = variant === "message"
|
|
11
13
|
? "devic-message-reference-chip"
|
|
12
14
|
: "devic-reference-chip";
|
|
13
|
-
return (jsxs("div", { className: className ? `${base} ${className}` : base, title: label, children: [icon ?? jsx(ReferenceArrowIcon, {}), jsxs("span", { className: `${base}-label`, children: ["\"", label, "\""] }), onRemove && (jsx("button", { type: "button", className: "devic-reference-chip-remove", onClick: onRemove, "aria-label": "
|
|
15
|
+
return (jsxs("div", { className: className ? `${base} ${className}` : base, title: label, children: [icon ?? jsx(ReferenceArrowIcon, {}), jsxs("span", { className: `${base}-label`, children: ["\"", label, "\""] }), onRemove && (jsx("button", { type: "button", className: "devic-reference-chip-remove", onClick: onRemove, "aria-label": t("Remove reference"), children: "\u00D7" }))] }));
|
|
14
16
|
}
|
|
15
17
|
/** Corner-down-right arrow used as the default reference glyph. */
|
|
16
18
|
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":["_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,GAAG,eAAe,EAAE;AAC3B,IAAA,MAAM,IAAI,GACR,OAAO,KAAK;AACV,UAAE;UACA,sBAAsB;AAE5B,IAAA,QACEA,IAAA,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,GAAA,CAAC,kBAAkB,EAAA,EAAA,CAAG,EAC/BD,eAAM,SAAS,EAAE,CAAA,EAAG,IAAI,CAAA,MAAA,CAAQ,EAAA,QAAA,EAAA,CAAA,IAAA,EAAI,KAAK,EAAA,IAAA,CAAA,EAAA,CAAS,EACjD,QAAQ,KACPC,GAAA,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,cACE,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,GAAA,CAAA,UAAA,EAAA,EAAU,MAAM,EAAC,mBAAmB,EAAA,CAAG,EACvCA,GAAA,CAAA,MAAA,EAAA,EAAM,CAAC,EAAC,yBAAyB,EAAA,CAAG,CAAA,EAAA,CAChC;AAEV;;"}
|
|
@@ -2,6 +2,7 @@ import { jsx, Fragment, jsxs } from 'react/jsx-runtime';
|
|
|
2
2
|
import { useMemo, useState, useCallback, useEffect } from 'react';
|
|
3
3
|
import { useOptionalDevicContext } from '../../provider/DevicContext.js';
|
|
4
4
|
import { DevicApiClient } from '../../api/client.js';
|
|
5
|
+
import { useTranslations } from '../../i18n/useTranslations.js';
|
|
5
6
|
|
|
6
7
|
const DEFAULT_DISPLAY = {
|
|
7
8
|
showValues: false,
|
|
@@ -24,24 +25,27 @@ function formatAmount(value, metric) {
|
|
|
24
25
|
}
|
|
25
26
|
return Math.round(value).toLocaleString();
|
|
26
27
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
// The unit names are translated on their own so a dictionary can decline
|
|
29
|
+
// them; the sentence around them is a separate entry with placeholders, which
|
|
30
|
+
// is what a language with a different word order needs.
|
|
31
|
+
function windowLabel(t, unit, every) {
|
|
32
|
+
const u = every > 1 ? t(`{count} ${unit}s`, { count: every }) : t(unit);
|
|
33
|
+
return every > 1 ? t('every {window}', { window: u }) : t('per {window}', { window: u });
|
|
30
34
|
}
|
|
31
|
-
function resetLabel(resetsAt) {
|
|
35
|
+
function resetLabel(t, resetsAt) {
|
|
32
36
|
if (!resetsAt)
|
|
33
37
|
return '';
|
|
34
38
|
const ms = resetsAt - Date.now();
|
|
35
39
|
if (ms <= 0)
|
|
36
|
-
return 'resets now';
|
|
40
|
+
return t('resets now');
|
|
37
41
|
const mins = Math.round(ms / 60000);
|
|
38
42
|
if (mins < 60)
|
|
39
|
-
return
|
|
43
|
+
return t('resets in {count}m', { count: mins });
|
|
40
44
|
const hours = Math.round(mins / 60);
|
|
41
45
|
if (hours < 48)
|
|
42
|
-
return
|
|
46
|
+
return t('resets in {count}h', { count: hours });
|
|
43
47
|
const days = Math.round(hours / 24);
|
|
44
|
-
return
|
|
48
|
+
return t('resets in {count}d', { count: days });
|
|
45
49
|
}
|
|
46
50
|
/**
|
|
47
51
|
* A thin usage bar showing the current tenant/subtenant usage window(s).
|
|
@@ -49,6 +53,7 @@ function resetLabel(resetsAt) {
|
|
|
49
53
|
* Renders nothing when there are no usage limits configured for the tenant.
|
|
50
54
|
*/
|
|
51
55
|
function UsageBar({ apiKey, baseUrl, tenantId, subtenantId, mode = 'always', metric, display, customUsageBar, color = '#1890ff', refreshKey, debug = false, }) {
|
|
56
|
+
const t = useTranslations();
|
|
52
57
|
const cfg = useMemo(() => ({ ...DEFAULT_DISPLAY, ...display }), [display]);
|
|
53
58
|
const devicContext = useOptionalDevicContext();
|
|
54
59
|
const getTenantSession = devicContext?.getTenantSession;
|
|
@@ -112,14 +117,14 @@ function UsageBar({ apiKey, baseUrl, tenantId, subtenantId, mode = 'always', met
|
|
|
112
117
|
}
|
|
113
118
|
// onDemand, collapsed: show a small toggle button.
|
|
114
119
|
if (mode === 'onDemand' && !visible) {
|
|
115
|
-
return (jsx("div", { className: "devic-usage-bar-wrap", "data-mode": "onDemand", children: jsxs("button", { type: "button", className: "devic-usage-toggle", onClick: () => setVisible(true), title:
|
|
120
|
+
return (jsx("div", { className: "devic-usage-bar-wrap", "data-mode": "onDemand", children: jsxs("button", { type: "button", className: "devic-usage-toggle", onClick: () => setVisible(true), title: t('Show usage'), children: [jsx(GaugeIcon, {}), jsx("span", { children: t('Usage') })] }) }));
|
|
116
121
|
}
|
|
117
122
|
// No configured limits (or not loaded yet with nothing to show): render nothing
|
|
118
123
|
// in 'always' mode; in expanded onDemand, show a subtle note so the toggle isn't
|
|
119
124
|
// confusing.
|
|
120
125
|
if (rules.length === 0) {
|
|
121
126
|
if (mode === 'onDemand' && loaded) {
|
|
122
|
-
return (jsx("div", { className: "devic-usage-bar-wrap", "data-mode": "onDemand", children: jsxs("div", { className: "devic-usage-bar", "data-empty": "true", children: [jsx("span", { className: "devic-usage-bar-label", children:
|
|
127
|
+
return (jsx("div", { className: "devic-usage-bar-wrap", "data-mode": "onDemand", children: jsxs("div", { className: "devic-usage-bar", "data-empty": "true", children: [jsx("span", { className: "devic-usage-bar-label", children: t('No usage limits') }), jsx("button", { type: "button", className: "devic-usage-collapse", onClick: () => setVisible(false), title: t('Hide usage'), "aria-label": t('Hide usage'), children: "\u00D7" })] }) }));
|
|
123
128
|
}
|
|
124
129
|
return null;
|
|
125
130
|
}
|
|
@@ -127,20 +132,20 @@ function UsageBar({ apiKey, baseUrl, tenantId, subtenantId, mode = 'always', met
|
|
|
127
132
|
const multi = rules.length > 1;
|
|
128
133
|
// A header carries the tier chip and/or the onDemand collapse control, so the
|
|
129
134
|
// collapse "×" has a stable home regardless of how many rows render below.
|
|
130
|
-
const header = showTierChip || mode === 'onDemand' ? (jsxs("div", { className: "devic-usage-bar-head", children: [showTierChip ? (jsx("span", { className: "devic-usage-tier", title:
|
|
135
|
+
const header = showTierChip || mode === 'onDemand' ? (jsxs("div", { className: "devic-usage-bar-head", children: [showTierChip ? (jsx("span", { className: "devic-usage-tier", title: t('Tier: {tier}', { tier: tierId }), children: tierId })) : (jsx("span", {})), mode === 'onDemand' && (jsx("button", { type: "button", className: "devic-usage-collapse", onClick: () => setVisible(false), title: t('Hide usage'), "aria-label": t('Hide usage'), children: "\u00D7" }))] })) : null;
|
|
131
136
|
return (jsxs("div", { className: "devic-usage-bar-wrap", "data-mode": mode, children: [header, jsx("div", { className: "devic-usage-bar-group", children: rules.map((rule, i) => {
|
|
132
137
|
const pct = Math.min(100, Math.round(rule.percent));
|
|
133
138
|
const fill = fillColor(pct, color);
|
|
134
|
-
const valuesText = `${formatAmount(rule.current, rule.metric)} / ${formatAmount(rule.limit, rule.metric)} ${rule.metric}`;
|
|
139
|
+
const valuesText = `${formatAmount(rule.current, rule.metric)} / ${formatAmount(rule.limit, rule.metric)} ${t(rule.metric)}`;
|
|
135
140
|
// Distinguish rows by metric when several render; otherwise use the
|
|
136
141
|
// scope-aware label so single-rule mode reads "Usage 24%".
|
|
137
142
|
const prefix = multi
|
|
138
143
|
? rule.metric === 'cost'
|
|
139
|
-
? 'Cost'
|
|
140
|
-
: 'Tokens'
|
|
144
|
+
? t('Cost')
|
|
145
|
+
: t('Tokens')
|
|
141
146
|
: rule.scope === 'subtenant'
|
|
142
|
-
? 'Your usage'
|
|
143
|
-
: 'Usage';
|
|
147
|
+
? t('Your usage')
|
|
148
|
+
: t('Usage');
|
|
144
149
|
const main = [];
|
|
145
150
|
if (cfg.showPercent)
|
|
146
151
|
main.push(`${pct}%`);
|
|
@@ -149,8 +154,8 @@ function UsageBar({ apiKey, baseUrl, tenantId, subtenantId, mode = 'always', met
|
|
|
149
154
|
if (main.length === 0)
|
|
150
155
|
main.push(`${pct}%`);
|
|
151
156
|
const label = `${prefix} ${main.join(' · ')}`.trim();
|
|
152
|
-
const reset = resetLabel(rule.resetsAt);
|
|
153
|
-
const win = windowLabel(rule.windowUnit, rule.windowEvery);
|
|
157
|
+
const reset = resetLabel(t, rule.resetsAt);
|
|
158
|
+
const win = windowLabel(t, rule.windowUnit, rule.windowEvery);
|
|
154
159
|
const title = `${valuesText} · ${win}${reset ? ` · ${reset}` : ''}`;
|
|
155
160
|
return (jsxs("div", { className: "devic-usage-bar", title: title, "data-state": pct >= 100 ? 'exceeded' : 'ok', children: [jsx("span", { className: "devic-usage-bar-label", children: label }), jsx("div", { className: "devic-usage-bar-track", children: jsx("div", { className: "devic-usage-bar-fill", style: { width: `${pct}%`, backgroundColor: fill } }) }), cfg.showWindow && (jsx("span", { className: "devic-usage-bar-window", children: win })), reset && jsx("span", { className: "devic-usage-bar-reset", children: reset })] }, `${rule.metric}-${rule.windowUnit}-${rule.windowEvery}-${rule.scope}-${i}`));
|
|
156
161
|
}) })] }));
|
|
@@ -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":["_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;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,QAAA,EAAA,CAEtBF,GAAA,CAAA,MAAA,EAAA,EAAM,CAAC,EAAC,sBAAsB,EAAA,CAAG,EACjCA,GAAA,CAAA,MAAA,EAAA,EAAM,CAAC,EAAC,sBAAsB,EAAA,CAAG,EACjCA,cAAM,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":["_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,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,IAAA,CAAA,KAAA,EAAA,EACE,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,QAAA,EAAA,CAEtBF,GAAA,CAAA,MAAA,EAAA,EAAM,CAAC,EAAC,sBAAsB,EAAA,CAAG,EACjCA,GAAA,CAAA,MAAA,EAAA,EAAM,CAAC,EAAC,sBAAsB,EAAA,CAAG,EACjCA,cAAM,EAAE,EAAC,IAAI,EAAC,EAAE,EAAC,IAAI,EAAC,EAAE,EAAC,IAAI,EAAC,EAAE,EAAC,IAAI,EAAA,CAAG,CAAA,EAAA,CACpC;AAEV;;"}
|
|
@@ -15,6 +15,8 @@ export type { QueueNoticeProps } from './QueueNotice';
|
|
|
15
15
|
export { RecalledMemoriesWidget } from './RecalledMemoriesWidget';
|
|
16
16
|
export type { CompactionWidgetProps, CompactionRenderer, CompactionRendererProps, } from './CompactionWidget';
|
|
17
17
|
export { CompactionWidget } from './CompactionWidget';
|
|
18
|
+
export { GuardrailNotice } from './GuardrailNotice';
|
|
19
|
+
export type { GuardrailNoticeProps, GuardrailRenderer, GuardrailPayload, } from './GuardrailNotice';
|
|
18
20
|
export type { RecalledMemoriesWidgetProps, RecalledMemoriesRenderer, RecalledMemoriesRendererProps, } from './RecalledMemoriesWidget';
|
|
19
21
|
export type { ChatDrawerProps, ChatDrawerOptions, ChatDrawerHandle, ChatMessagesProps, ChatInputProps, CustomPromptBoxProps, MessageBubbleRenderer, MessageBubbleRendererProps, ToolTimelineProps, AllowedFileTypes, ConversationSelectorProps, SuggestedMessage, } from './ChatDrawer.types';
|
|
20
22
|
export type { HandoffSubagentWidgetProps } from './HandoffSubagentWidget';
|
|
@@ -4,6 +4,7 @@ import { createPortal } from 'react-dom';
|
|
|
4
4
|
import { DevicApiClient } from '../../api/client.js';
|
|
5
5
|
import { useOptionalDevicContext } from '../../provider/DevicContext.js';
|
|
6
6
|
import { themeVars } from '../theme.js';
|
|
7
|
+
import { useTranslations } from '../../i18n/useTranslations.js';
|
|
7
8
|
|
|
8
9
|
/** Canonical sections of the core tier, in display order. */
|
|
9
10
|
const SECTIONS = ["persona", "instructions", "decisions", "profile"];
|
|
@@ -47,15 +48,25 @@ function PinIcon() {
|
|
|
47
48
|
* the API key needs that endpoint allowed.
|
|
48
49
|
*/
|
|
49
50
|
function CoreMemoryModal({ isOpen, onClose, assistantId, tenantId, subtenantId, apiKey, baseUrl, editable = true, title, labels, theme, }) {
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
51
|
+
const t = useTranslations();
|
|
52
|
+
// Three layers, narrowest first: the `labels` this host passed, then the
|
|
53
|
+
// dictionary, then English. `labels` stays authoritative — a host that
|
|
54
|
+
// already spells this dialog out itself must not have it changed underneath
|
|
55
|
+
// by a page-wide dictionary.
|
|
56
|
+
const l = useMemo(() => {
|
|
57
|
+
const translated = Object.fromEntries(Object.entries(DEFAULT_CORE_MEMORY_LABELS)
|
|
58
|
+
.filter(([, value]) => typeof value === "string")
|
|
59
|
+
.map(([key, value]) => [key, t(value)]));
|
|
60
|
+
return {
|
|
61
|
+
...translated,
|
|
62
|
+
...labels,
|
|
63
|
+
title: labels?.title ?? title ?? t(DEFAULT_CORE_MEMORY_LABELS.title),
|
|
64
|
+
sections: {
|
|
65
|
+
...Object.fromEntries(Object.entries(DEFAULT_CORE_MEMORY_LABELS.sections).map(([key, value]) => [key, t(value)])),
|
|
66
|
+
...labels?.sections,
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
}, [labels, title, t]);
|
|
59
70
|
const context = useOptionalDevicContext();
|
|
60
71
|
const resolvedBaseUrl = baseUrl || context?.baseUrl || "https://api.devic.ai";
|
|
61
72
|
const resolvedTenantId = tenantId || context?.tenantId;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CoreMemoryModal.js","sources":["../../../../src/components/CoreMemoryModal/CoreMemoryModal.tsx"],"sourcesContent":["import {\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useState,\n type JSX,\n} from \"react\";\nimport { createPortal } from \"react-dom\";\nimport { DevicApiClient } from \"../../api/client\";\nimport type { CoreMemoryEntry, CoreMemoryLimits } from \"../../api/types\";\nimport { useOptionalDevicContext } from \"../../provider\";\nimport { themeVars, type DevicTheme } from \"../theme\";\nimport \"./CoreMemoryModal.css\";\n\n/** Canonical sections of the core tier, in display order. */\nconst SECTIONS = [\"persona\", \"instructions\", \"decisions\", \"profile\"] as const;\n\n/**\n * Every piece of text the modal shows, so a host can render it in its own\n * language. Any subset can be given; the rest keeps the English default.\n */\nexport interface CoreMemoryLabels {\n /** Modal title; the drawer also uses it for its brain button tooltip. */\n title: string;\n /** Accessible name of the close button. */\n close: string;\n loading: string;\n /** Shown when the assistant has no core memory tier enabled. */\n disabled: string;\n /** Shown when the bucket holds no entries yet. */\n empty: string;\n /** Tooltip of the pin mark. */\n pinned: string;\n edit: string;\n remove: string;\n save: string;\n cancel: string;\n /** Confirms the composer. */\n add: string;\n /** Opens the composer. */\n addMemory: string;\n /** Composer placeholder. */\n placeholder: string;\n /** Footer; `{count}`, `{max}` and `{chars}` are replaced. */\n footer: string;\n /** Display names of the sections, by section key. */\n sections: Record<string, string>;\n}\n\nexport const DEFAULT_CORE_MEMORY_LABELS: CoreMemoryLabels = {\n title: \"Assistant memory\",\n close: \"Close\",\n loading: \"Loading memory…\",\n disabled: \"Memory is not enabled for this assistant.\",\n empty:\n \"Nothing remembered yet. What the assistant learns and is told to keep will appear here.\",\n pinned: \"Pinned: always kept, never changed by the assistant\",\n edit: \"Edit\",\n remove: \"Remove\",\n save: \"Save\",\n cancel: \"Cancel\",\n add: \"Add\",\n addMemory: \"+ Add memory\",\n placeholder: \"Something the assistant should always remember…\",\n footer: \"{count}/{max} entries · up to {chars} characters each\",\n sections: {\n persona: \"persona\",\n instructions: \"instructions\",\n decisions: \"decisions\",\n profile: \"profile\",\n },\n};\n\nconst fillTemplate = (template: string, values: Record<string, string>) =>\n template.replace(/\\{(\\w+)\\}/g, (_, key: string) => values[key] ?? \"\");\n\nexport interface CoreMemoryModalProps {\n /** Whether the modal is visible. */\n isOpen: boolean;\n onClose: () => void;\n /** Assistant whose memory bucket is shown. */\n assistantId: string;\n /** Tenant of the end user (falls back to the provider's tenantId). */\n tenantId?: string;\n /** Subtenant of the end user (falls back to the provider's subtenantId). */\n subtenantId?: string;\n /** API key override (falls back to the provider's). */\n apiKey?: string;\n /** Base URL override (falls back to the provider's). */\n baseUrl?: string;\n /**\n * Let the user add, edit and remove entries. Set false for a read-only\n * view of what the assistant remembers.\n * @default true\n */\n editable?: boolean;\n /**\n * Modal title. @default \"Assistant memory\"\n * @deprecated Prefer `labels.title`; kept so existing hosts keep working.\n */\n title?: string;\n /** Texts of the modal, for a host that renders it in its own language. */\n labels?: Partial<CoreMemoryLabels>;\n /**\n * Colours and font. Same names as the drawer's style options, and the drawer\n * passes its own down — a dialog opening in the default light palette over a\n * themed application is the one thing this must not do.\n */\n theme?: DevicTheme;\n}\n\nfunction BrainIcon(): JSX.Element {\n return (\n <svg\n width=\"16\"\n height=\"16\"\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 PinIcon(): JSX.Element {\n return (\n <svg\n width=\"11\"\n height=\"11\"\n viewBox=\"0 0 24 24\"\n fill=\"currentColor\"\n stroke=\"none\"\n aria-hidden=\"true\"\n >\n <path d=\"M16 3a1 1 0 0 1 .97 1.243l-1.2 4.8 3.937 3.938A1 1 0 0 1 19 14.688V15a1 1 0 0 1-1 1h-5v6l-1 1-1-1v-6H6a1 1 0 0 1-1-1v-.312a1 1 0 0 1 .293-.707L9.23 9.043l-1.2-4.8A1 1 0 0 1 9 3h7Z\" />\n </svg>\n );\n}\n\n/**\n * Modal showing — and, when `editable`, managing — the core memory of an\n * assistant for a tenant/subtenant combination: the standing entries\n * (persona, instructions, decisions, profile) injected into every prompt of\n * the bucket the assistant resolves there. Lets the end user see and control\n * what the assistant permanently remembers about them.\n *\n * Backed by the public memory API (`/api/v1/memory/assistants/:id/core`);\n * the API key needs that endpoint allowed.\n */\nexport function CoreMemoryModal({\n isOpen,\n onClose,\n assistantId,\n tenantId,\n subtenantId,\n apiKey,\n baseUrl,\n editable = true,\n title,\n labels,\n theme,\n}: CoreMemoryModalProps): JSX.Element | null {\n const l = useMemo<CoreMemoryLabels>(\n () => ({\n ...DEFAULT_CORE_MEMORY_LABELS,\n ...labels,\n title: labels?.title ?? title ?? DEFAULT_CORE_MEMORY_LABELS.title,\n sections: {\n ...DEFAULT_CORE_MEMORY_LABELS.sections,\n ...labels?.sections,\n },\n }),\n [labels, title]\n );\n const context = useOptionalDevicContext();\n const resolvedBaseUrl = baseUrl || context?.baseUrl || \"https://api.devic.ai\";\n const resolvedTenantId = tenantId || context?.tenantId;\n const resolvedSubtenantId = subtenantId || context?.subtenantId;\n\n const resolvedApiKey = apiKey || context?.apiKey;\n const resolvedTenantSession = context?.getTenantSession;\n const onSessionExpired = context?.onSessionExpired;\n\n const client = useMemo(\n () =>\n resolvedApiKey || resolvedTenantSession\n ? new DevicApiClient({\n apiKey: resolvedApiKey,\n baseUrl: resolvedBaseUrl,\n getTenantSession: resolvedTenantSession,\n onSessionExpired,\n })\n : null,\n [resolvedApiKey, resolvedTenantSession, resolvedBaseUrl]\n );\n\n const [loading, setLoading] = useState(false);\n const [enabled, setEnabled] = useState(true);\n const [entries, setEntries] = useState<CoreMemoryEntry[]>([]);\n const [limits, setLimits] = useState<CoreMemoryLimits | null>(null);\n const [error, setError] = useState<string | null>(null);\n const [saving, setSaving] = useState(false);\n\n // Inline composer / editor state\n const [composerOpen, setComposerOpen] = useState(false);\n const [composerSection, setComposerSection] = useState<string>(\"profile\");\n const [composerText, setComposerText] = useState(\"\");\n const [editingId, setEditingId] = useState<number | null>(null);\n const [editingText, setEditingText] = useState(\"\");\n\n const scopeOptions = useMemo(\n () => ({\n tenantId: resolvedTenantId || undefined,\n subtenantId: resolvedSubtenantId || undefined,\n }),\n [resolvedTenantId, resolvedSubtenantId]\n );\n\n const refresh = useCallback(async () => {\n if (!client) {\n setError(\"API key not configured\");\n return;\n }\n setLoading(true);\n setError(null);\n try {\n const list = await client.getCoreMemory(assistantId, scopeOptions);\n setEnabled(list.enabled);\n setEntries(list.entries);\n setLimits(list.limits ?? null);\n } catch (err) {\n setError(err instanceof Error ? err.message : String(err));\n } finally {\n setLoading(false);\n }\n }, [client, assistantId, scopeOptions]);\n\n // Fetch on every open (memory may have changed since the last look).\n const wasOpenRef = useRef(false);\n useEffect(() => {\n if (isOpen && !wasOpenRef.current) {\n setComposerOpen(false);\n setComposerText(\"\");\n setEditingId(null);\n void refresh();\n }\n wasOpenRef.current = isOpen;\n }, [isOpen, refresh]);\n\n // Escape closes\n useEffect(() => {\n if (!isOpen) return;\n const onKey = (e: KeyboardEvent) => {\n if (e.key === \"Escape\") onClose();\n };\n document.addEventListener(\"keydown\", onKey);\n return () => document.removeEventListener(\"keydown\", onKey);\n }, [isOpen, onClose]);\n\n const runWrite = useCallback(\n async (write: () => Promise<unknown>) => {\n setSaving(true);\n setError(null);\n try {\n await write();\n await refresh();\n return true;\n } catch (err) {\n setError(err instanceof Error ? err.message : String(err));\n return false;\n } finally {\n setSaving(false);\n }\n },\n [refresh]\n );\n\n const handleAdd = async () => {\n if (!client || !composerText.trim()) return;\n const ok = await runWrite(() =>\n client.addCoreMemoryEntry(\n assistantId,\n { content: composerText.trim(), section: composerSection },\n scopeOptions\n )\n );\n if (ok) {\n setComposerOpen(false);\n setComposerText(\"\");\n }\n };\n\n const handleSaveEdit = async (entry: CoreMemoryEntry) => {\n if (!client || !editingText.trim()) return;\n const ok = await runWrite(() =>\n client.updateCoreMemoryEntry(\n assistantId,\n entry.id,\n { content: editingText.trim() },\n scopeOptions\n )\n );\n if (ok) setEditingId(null);\n };\n\n const handleRemove = async (entry: CoreMemoryEntry) => {\n if (!client) return;\n await runWrite(() =>\n client.deleteCoreMemoryEntry(assistantId, entry.id, scopeOptions)\n );\n };\n\n if (!isOpen) return null;\n\n // Group entries by section, canonical sections first.\n const sections: Array<{ name: string; entries: CoreMemoryEntry[] }> = [];\n const bySection = new Map<string, CoreMemoryEntry[]>();\n for (const entry of entries) {\n const list = bySection.get(entry.section);\n if (list) list.push(entry);\n else bySection.set(entry.section, [entry]);\n }\n for (const name of SECTIONS) {\n const list = bySection.get(name);\n if (list) {\n sections.push({ name, entries: list });\n bySection.delete(name);\n }\n }\n for (const [name, list] of bySection) sections.push({ name, entries: list });\n\n return createPortal(\n // The variables go on the overlay: a portal inherits nothing from the\n // drawer that opened it, so without this the dialog ignores the theme.\n <div\n className=\"devic-cm-overlay\"\n style={themeVars(theme)}\n onClick={onClose}\n >\n <div\n className=\"devic-cm-modal\"\n role=\"dialog\"\n aria-modal=\"true\"\n aria-label={l.title}\n onClick={(e) => e.stopPropagation()}\n >\n <div className=\"devic-cm-header\">\n <h3 className=\"devic-cm-title\">\n <BrainIcon />\n {l.title}\n </h3>\n <button\n className=\"devic-cm-close\"\n onClick={onClose}\n type=\"button\"\n aria-label={l.close}\n >\n ×\n </button>\n </div>\n\n <div className=\"devic-cm-body\">\n {error && <div className=\"devic-cm-error\">{error}</div>}\n\n {loading ? (\n <div className=\"devic-cm-loading\">{l.loading}</div>\n ) : !enabled ? (\n <div className=\"devic-cm-empty\">{l.disabled}</div>\n ) : entries.length === 0 && !composerOpen ? (\n <div className=\"devic-cm-empty\">{l.empty}</div>\n ) : (\n sections.map((section) => (\n <div key={section.name} className=\"devic-cm-section\">\n <div className=\"devic-cm-section-title\">\n {l.sections[section.name] ?? section.name}\n </div>\n {section.entries.map((entry) => (\n <div key={entry.id} className=\"devic-cm-entry\">\n {editingId === entry.id ? (\n <div className=\"devic-cm-editor\">\n <textarea\n className=\"devic-cm-textarea\"\n value={editingText}\n maxLength={limits?.maxEntryChars || undefined}\n onChange={(e) => setEditingText(e.target.value)}\n disabled={saving}\n autoFocus\n />\n <div className=\"devic-cm-editor-actions\">\n <button\n type=\"button\"\n className=\"devic-cm-btn devic-cm-btn-primary\"\n onClick={() => handleSaveEdit(entry)}\n disabled={saving || !editingText.trim()}\n >\n {l.save}\n </button>\n <button\n type=\"button\"\n className=\"devic-cm-btn\"\n onClick={() => setEditingId(null)}\n disabled={saving}\n >\n {l.cancel}\n </button>\n </div>\n </div>\n ) : (\n <>\n <div className=\"devic-cm-entry-content\">\n {entry.pinned && (\n <span\n className=\"devic-cm-pin\"\n title={l.pinned}\n >\n <PinIcon />\n </span>\n )}\n <span>{entry.content}</span>\n </div>\n {editable && (\n <div className=\"devic-cm-entry-actions\">\n <button\n type=\"button\"\n className=\"devic-cm-btn devic-cm-btn-small\"\n onClick={() => {\n setEditingId(entry.id);\n setEditingText(entry.content);\n }}\n disabled={saving}\n >\n {l.edit}\n </button>\n <button\n type=\"button\"\n className=\"devic-cm-btn devic-cm-btn-small devic-cm-btn-danger\"\n onClick={() => handleRemove(entry)}\n disabled={saving}\n >\n {l.remove}\n </button>\n </div>\n )}\n </>\n )}\n </div>\n ))}\n </div>\n ))\n )}\n\n {editable && enabled && !loading && (\n <div className=\"devic-cm-composer\">\n {composerOpen ? (\n <>\n <div className=\"devic-cm-composer-row\">\n <select\n className=\"devic-cm-select\"\n value={composerSection}\n onChange={(e) => setComposerSection(e.target.value)}\n disabled={saving}\n >\n {SECTIONS.map((s) => (\n <option key={s} value={s}>\n {l.sections[s] ?? s}\n </option>\n ))}\n </select>\n </div>\n <textarea\n className=\"devic-cm-textarea\"\n placeholder={l.placeholder}\n value={composerText}\n maxLength={limits?.maxEntryChars || undefined}\n onChange={(e) => setComposerText(e.target.value)}\n disabled={saving}\n autoFocus\n />\n <div className=\"devic-cm-editor-actions\">\n <button\n type=\"button\"\n className=\"devic-cm-btn devic-cm-btn-primary\"\n onClick={handleAdd}\n disabled={saving || !composerText.trim()}\n >\n {l.add}\n </button>\n <button\n type=\"button\"\n className=\"devic-cm-btn\"\n onClick={() => {\n setComposerOpen(false);\n setComposerText(\"\");\n }}\n disabled={saving}\n >\n {l.cancel}\n </button>\n </div>\n </>\n ) : (\n <button\n type=\"button\"\n className=\"devic-cm-btn\"\n onClick={() => setComposerOpen(true)}\n disabled={saving}\n >\n {l.addMemory}\n </button>\n )}\n </div>\n )}\n </div>\n\n {limits && enabled && (\n <div className=\"devic-cm-footer\">\n {fillTemplate(l.footer, {\n count: String(entries.length),\n max: String(limits.maxEntries),\n chars: String(limits.maxEntryChars),\n })}\n </div>\n )}\n </div>\n </div>,\n document.body\n );\n}\n\nexport default CoreMemoryModal;\n"],"names":["_jsxs","_jsx","_Fragment"],"mappings":";;;;;;;AAeA;AACA,MAAM,QAAQ,GAAG,CAAC,SAAS,EAAE,cAAc,EAAE,WAAW,EAAE,SAAS,CAAU;AAkCtE,MAAM,0BAA0B,GAAqB;AAC1D,IAAA,KAAK,EAAE,kBAAkB;AACzB,IAAA,KAAK,EAAE,OAAO;AACd,IAAA,OAAO,EAAE,iBAAiB;AAC1B,IAAA,Q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rB,gDAAA,CAAC,EACD,QAAQ,EAAE,MAAM,EAAA,QAAA,EAEf,CAAC,CAAC,MAAM,EAAA,CACF,CAAA,EAAA,CACL,CAAA,EAAA,CACL,KAEHA,GAAA,CAAA,QAAA,EAAA,EACE,IAAI,EAAC,QAAQ,EACb,SAAS,EAAC,cAAc,EACxB,OAAO,EAAE,MAAM,eAAe,CAAC,IAAI,CAAC,EACpC,QAAQ,EAAE,MAAM,EAAA,QAAA,EAEf,CAAC,CAAC,SAAS,EAAA,CACL,CACV,EAAA,CACG,CACP,CAAA,EAAA,CACG,EAEL,MAAM,IAAI,OAAO,KAChBA,GAAA,CAAA,KAAA,EAAA,EAAK,SAAS,EAAC,iBAAiB,EAAA,QAAA,EAC7B,YAAY,CAAC,CAAC,CAAC,MAAM,EAAE;AACtB,wBAAA,KAAK,EAAE,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC;AAC7B,wBAAA,GAAG,EAAE,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC;AAC9B,wBAAA,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,aAAa,CAAC;qBACpC,CAAC,EAAA,CACE,CACP,CAAA,EAAA,CACG,EAAA,CACF,EACN,QAAQ,CAAC,IAAI,CACd;AACH;;"}
|
|
1
|
+
{"version":3,"file":"CoreMemoryModal.js","sources":["../../../../src/components/CoreMemoryModal/CoreMemoryModal.tsx"],"sourcesContent":["import {\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useState,\n type JSX,\n} from \"react\";\nimport { createPortal } from \"react-dom\";\nimport { DevicApiClient } from \"../../api/client\";\nimport type { CoreMemoryEntry, CoreMemoryLimits } from \"../../api/types\";\nimport { useOptionalDevicContext } from \"../../provider\";\nimport { themeVars, type DevicTheme } from \"../theme\";\nimport { useTranslations } from \"../../i18n\";\nimport \"./CoreMemoryModal.css\";\n\n/** Canonical sections of the core tier, in display order. */\nconst SECTIONS = [\"persona\", \"instructions\", \"decisions\", \"profile\"] as const;\n\n/**\n * Every piece of text the modal shows, so a host can render it in its own\n * language. Any subset can be given; the rest keeps the English default.\n */\nexport interface CoreMemoryLabels {\n /** Modal title; the drawer also uses it for its brain button tooltip. */\n title: string;\n /** Accessible name of the close button. */\n close: string;\n loading: string;\n /** Shown when the assistant has no core memory tier enabled. */\n disabled: string;\n /** Shown when the bucket holds no entries yet. */\n empty: string;\n /** Tooltip of the pin mark. */\n pinned: string;\n edit: string;\n remove: string;\n save: string;\n cancel: string;\n /** Confirms the composer. */\n add: string;\n /** Opens the composer. */\n addMemory: string;\n /** Composer placeholder. */\n placeholder: string;\n /** Footer; `{count}`, `{max}` and `{chars}` are replaced. */\n footer: string;\n /** Display names of the sections, by section key. */\n sections: Record<string, string>;\n}\n\nexport const DEFAULT_CORE_MEMORY_LABELS: CoreMemoryLabels = {\n title: \"Assistant memory\",\n close: \"Close\",\n loading: \"Loading memory…\",\n disabled: \"Memory is not enabled for this assistant.\",\n empty:\n \"Nothing remembered yet. What the assistant learns and is told to keep will appear here.\",\n pinned: \"Pinned: always kept, never changed by the assistant\",\n edit: \"Edit\",\n remove: \"Remove\",\n save: \"Save\",\n cancel: \"Cancel\",\n add: \"Add\",\n addMemory: \"+ Add memory\",\n placeholder: \"Something the assistant should always remember…\",\n footer: \"{count}/{max} entries · up to {chars} characters each\",\n sections: {\n persona: \"persona\",\n instructions: \"instructions\",\n decisions: \"decisions\",\n profile: \"profile\",\n },\n};\n\nconst fillTemplate = (template: string, values: Record<string, string>) =>\n template.replace(/\\{(\\w+)\\}/g, (_, key: string) => values[key] ?? \"\");\n\nexport interface CoreMemoryModalProps {\n /** Whether the modal is visible. */\n isOpen: boolean;\n onClose: () => void;\n /** Assistant whose memory bucket is shown. */\n assistantId: string;\n /** Tenant of the end user (falls back to the provider's tenantId). */\n tenantId?: string;\n /** Subtenant of the end user (falls back to the provider's subtenantId). */\n subtenantId?: string;\n /** API key override (falls back to the provider's). */\n apiKey?: string;\n /** Base URL override (falls back to the provider's). */\n baseUrl?: string;\n /**\n * Let the user add, edit and remove entries. Set false for a read-only\n * view of what the assistant remembers.\n * @default true\n */\n editable?: boolean;\n /**\n * Modal title. @default \"Assistant memory\"\n * @deprecated Prefer `labels.title`; kept so existing hosts keep working.\n */\n title?: string;\n /** Texts of the modal, for a host that renders it in its own language. */\n labels?: Partial<CoreMemoryLabels>;\n /**\n * Colours and font. Same names as the drawer's style options, and the drawer\n * passes its own down — a dialog opening in the default light palette over a\n * themed application is the one thing this must not do.\n */\n theme?: DevicTheme;\n}\n\nfunction BrainIcon(): JSX.Element {\n return (\n <svg\n width=\"16\"\n height=\"16\"\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 PinIcon(): JSX.Element {\n return (\n <svg\n width=\"11\"\n height=\"11\"\n viewBox=\"0 0 24 24\"\n fill=\"currentColor\"\n stroke=\"none\"\n aria-hidden=\"true\"\n >\n <path d=\"M16 3a1 1 0 0 1 .97 1.243l-1.2 4.8 3.937 3.938A1 1 0 0 1 19 14.688V15a1 1 0 0 1-1 1h-5v6l-1 1-1-1v-6H6a1 1 0 0 1-1-1v-.312a1 1 0 0 1 .293-.707L9.23 9.043l-1.2-4.8A1 1 0 0 1 9 3h7Z\" />\n </svg>\n );\n}\n\n/**\n * Modal showing — and, when `editable`, managing — the core memory of an\n * assistant for a tenant/subtenant combination: the standing entries\n * (persona, instructions, decisions, profile) injected into every prompt of\n * the bucket the assistant resolves there. Lets the end user see and control\n * what the assistant permanently remembers about them.\n *\n * Backed by the public memory API (`/api/v1/memory/assistants/:id/core`);\n * the API key needs that endpoint allowed.\n */\nexport function CoreMemoryModal({\n isOpen,\n onClose,\n assistantId,\n tenantId,\n subtenantId,\n apiKey,\n baseUrl,\n editable = true,\n title,\n labels,\n theme,\n}: CoreMemoryModalProps): JSX.Element | null {\n const t = useTranslations();\n // Three layers, narrowest first: the `labels` this host passed, then the\n // dictionary, then English. `labels` stays authoritative — a host that\n // already spells this dialog out itself must not have it changed underneath\n // by a page-wide dictionary.\n const l = useMemo<CoreMemoryLabels>(() => {\n const translated = Object.fromEntries(\n Object.entries(DEFAULT_CORE_MEMORY_LABELS)\n .filter(([, value]) => typeof value === \"string\")\n .map(([key, value]) => [key, t(value as string)])\n ) as Omit<CoreMemoryLabels, \"sections\">;\n return {\n ...translated,\n ...labels,\n title: labels?.title ?? title ?? t(DEFAULT_CORE_MEMORY_LABELS.title),\n sections: {\n ...Object.fromEntries(\n Object.entries(DEFAULT_CORE_MEMORY_LABELS.sections).map(\n ([key, value]) => [key, t(value)]\n )\n ),\n ...labels?.sections,\n },\n };\n }, [labels, title, t]);\n const context = useOptionalDevicContext();\n const resolvedBaseUrl = baseUrl || context?.baseUrl || \"https://api.devic.ai\";\n const resolvedTenantId = tenantId || context?.tenantId;\n const resolvedSubtenantId = subtenantId || context?.subtenantId;\n\n const resolvedApiKey = apiKey || context?.apiKey;\n const resolvedTenantSession = context?.getTenantSession;\n const onSessionExpired = context?.onSessionExpired;\n\n const client = useMemo(\n () =>\n resolvedApiKey || resolvedTenantSession\n ? new DevicApiClient({\n apiKey: resolvedApiKey,\n baseUrl: resolvedBaseUrl,\n getTenantSession: resolvedTenantSession,\n onSessionExpired,\n })\n : null,\n [resolvedApiKey, resolvedTenantSession, resolvedBaseUrl]\n );\n\n const [loading, setLoading] = useState(false);\n const [enabled, setEnabled] = useState(true);\n const [entries, setEntries] = useState<CoreMemoryEntry[]>([]);\n const [limits, setLimits] = useState<CoreMemoryLimits | null>(null);\n const [error, setError] = useState<string | null>(null);\n const [saving, setSaving] = useState(false);\n\n // Inline composer / editor state\n const [composerOpen, setComposerOpen] = useState(false);\n const [composerSection, setComposerSection] = useState<string>(\"profile\");\n const [composerText, setComposerText] = useState(\"\");\n const [editingId, setEditingId] = useState<number | null>(null);\n const [editingText, setEditingText] = useState(\"\");\n\n const scopeOptions = useMemo(\n () => ({\n tenantId: resolvedTenantId || undefined,\n subtenantId: resolvedSubtenantId || undefined,\n }),\n [resolvedTenantId, resolvedSubtenantId]\n );\n\n const refresh = useCallback(async () => {\n if (!client) {\n setError(\"API key not configured\");\n return;\n }\n setLoading(true);\n setError(null);\n try {\n const list = await client.getCoreMemory(assistantId, scopeOptions);\n setEnabled(list.enabled);\n setEntries(list.entries);\n setLimits(list.limits ?? null);\n } catch (err) {\n setError(err instanceof Error ? err.message : String(err));\n } finally {\n setLoading(false);\n }\n }, [client, assistantId, scopeOptions]);\n\n // Fetch on every open (memory may have changed since the last look).\n const wasOpenRef = useRef(false);\n useEffect(() => {\n if (isOpen && !wasOpenRef.current) {\n setComposerOpen(false);\n setComposerText(\"\");\n setEditingId(null);\n void refresh();\n }\n wasOpenRef.current = isOpen;\n }, [isOpen, refresh]);\n\n // Escape closes\n useEffect(() => {\n if (!isOpen) return;\n const onKey = (e: KeyboardEvent) => {\n if (e.key === \"Escape\") onClose();\n };\n document.addEventListener(\"keydown\", onKey);\n return () => document.removeEventListener(\"keydown\", onKey);\n }, [isOpen, onClose]);\n\n const runWrite = useCallback(\n async (write: () => Promise<unknown>) => {\n setSaving(true);\n setError(null);\n try {\n await write();\n await refresh();\n return true;\n } catch (err) {\n setError(err instanceof Error ? err.message : String(err));\n return false;\n } finally {\n setSaving(false);\n }\n },\n [refresh]\n );\n\n const handleAdd = async () => {\n if (!client || !composerText.trim()) return;\n const ok = await runWrite(() =>\n client.addCoreMemoryEntry(\n assistantId,\n { content: composerText.trim(), section: composerSection },\n scopeOptions\n )\n );\n if (ok) {\n setComposerOpen(false);\n setComposerText(\"\");\n }\n };\n\n const handleSaveEdit = async (entry: CoreMemoryEntry) => {\n if (!client || !editingText.trim()) return;\n const ok = await runWrite(() =>\n client.updateCoreMemoryEntry(\n assistantId,\n entry.id,\n { content: editingText.trim() },\n scopeOptions\n )\n );\n if (ok) setEditingId(null);\n };\n\n const handleRemove = async (entry: CoreMemoryEntry) => {\n if (!client) return;\n await runWrite(() =>\n client.deleteCoreMemoryEntry(assistantId, entry.id, scopeOptions)\n );\n };\n\n if (!isOpen) return null;\n\n // Group entries by section, canonical sections first.\n const sections: Array<{ name: string; entries: CoreMemoryEntry[] }> = [];\n const bySection = new Map<string, CoreMemoryEntry[]>();\n for (const entry of entries) {\n const list = bySection.get(entry.section);\n if (list) list.push(entry);\n else bySection.set(entry.section, [entry]);\n }\n for (const name of SECTIONS) {\n const list = bySection.get(name);\n if (list) {\n sections.push({ name, entries: list });\n bySection.delete(name);\n }\n }\n for (const [name, list] of bySection) sections.push({ name, entries: list });\n\n return createPortal(\n // The variables go on the overlay: a portal inherits nothing from the\n // drawer that opened it, so without this the dialog ignores the theme.\n <div\n className=\"devic-cm-overlay\"\n style={themeVars(theme)}\n onClick={onClose}\n >\n <div\n className=\"devic-cm-modal\"\n role=\"dialog\"\n aria-modal=\"true\"\n aria-label={l.title}\n onClick={(e) => e.stopPropagation()}\n >\n <div className=\"devic-cm-header\">\n <h3 className=\"devic-cm-title\">\n <BrainIcon />\n {l.title}\n </h3>\n <button\n className=\"devic-cm-close\"\n onClick={onClose}\n type=\"button\"\n aria-label={l.close}\n >\n ×\n </button>\n </div>\n\n <div className=\"devic-cm-body\">\n {error && <div className=\"devic-cm-error\">{error}</div>}\n\n {loading ? (\n <div className=\"devic-cm-loading\">{l.loading}</div>\n ) : !enabled ? (\n <div className=\"devic-cm-empty\">{l.disabled}</div>\n ) : entries.length === 0 && !composerOpen ? (\n <div className=\"devic-cm-empty\">{l.empty}</div>\n ) : (\n sections.map((section) => (\n <div key={section.name} className=\"devic-cm-section\">\n <div className=\"devic-cm-section-title\">\n {l.sections[section.name] ?? section.name}\n </div>\n {section.entries.map((entry) => (\n <div key={entry.id} className=\"devic-cm-entry\">\n {editingId === entry.id ? (\n <div className=\"devic-cm-editor\">\n <textarea\n className=\"devic-cm-textarea\"\n value={editingText}\n maxLength={limits?.maxEntryChars || undefined}\n onChange={(e) => setEditingText(e.target.value)}\n disabled={saving}\n autoFocus\n />\n <div className=\"devic-cm-editor-actions\">\n <button\n type=\"button\"\n className=\"devic-cm-btn devic-cm-btn-primary\"\n onClick={() => handleSaveEdit(entry)}\n disabled={saving || !editingText.trim()}\n >\n {l.save}\n </button>\n <button\n type=\"button\"\n className=\"devic-cm-btn\"\n onClick={() => setEditingId(null)}\n disabled={saving}\n >\n {l.cancel}\n </button>\n </div>\n </div>\n ) : (\n <>\n <div className=\"devic-cm-entry-content\">\n {entry.pinned && (\n <span\n className=\"devic-cm-pin\"\n title={l.pinned}\n >\n <PinIcon />\n </span>\n )}\n <span>{entry.content}</span>\n </div>\n {editable && (\n <div className=\"devic-cm-entry-actions\">\n <button\n type=\"button\"\n className=\"devic-cm-btn devic-cm-btn-small\"\n onClick={() => {\n setEditingId(entry.id);\n setEditingText(entry.content);\n }}\n disabled={saving}\n >\n {l.edit}\n </button>\n <button\n type=\"button\"\n className=\"devic-cm-btn devic-cm-btn-small devic-cm-btn-danger\"\n onClick={() => handleRemove(entry)}\n disabled={saving}\n >\n {l.remove}\n </button>\n </div>\n )}\n </>\n )}\n </div>\n ))}\n </div>\n ))\n )}\n\n {editable && enabled && !loading && (\n <div className=\"devic-cm-composer\">\n {composerOpen ? (\n <>\n <div className=\"devic-cm-composer-row\">\n <select\n className=\"devic-cm-select\"\n value={composerSection}\n onChange={(e) => setComposerSection(e.target.value)}\n disabled={saving}\n >\n {SECTIONS.map((s) => (\n <option key={s} value={s}>\n {l.sections[s] ?? s}\n </option>\n ))}\n </select>\n </div>\n <textarea\n className=\"devic-cm-textarea\"\n placeholder={l.placeholder}\n value={composerText}\n maxLength={limits?.maxEntryChars || undefined}\n onChange={(e) => setComposerText(e.target.value)}\n disabled={saving}\n autoFocus\n />\n <div className=\"devic-cm-editor-actions\">\n <button\n type=\"button\"\n className=\"devic-cm-btn devic-cm-btn-primary\"\n onClick={handleAdd}\n disabled={saving || !composerText.trim()}\n >\n {l.add}\n </button>\n <button\n type=\"button\"\n className=\"devic-cm-btn\"\n onClick={() => {\n setComposerOpen(false);\n setComposerText(\"\");\n }}\n disabled={saving}\n >\n {l.cancel}\n </button>\n </div>\n </>\n ) : (\n <button\n type=\"button\"\n className=\"devic-cm-btn\"\n onClick={() => setComposerOpen(true)}\n disabled={saving}\n >\n {l.addMemory}\n </button>\n )}\n </div>\n )}\n </div>\n\n {limits && enabled && (\n <div className=\"devic-cm-footer\">\n {fillTemplate(l.footer, {\n count: String(entries.length),\n max: String(limits.maxEntries),\n chars: String(limits.maxEntryChars),\n })}\n </div>\n )}\n </div>\n </div>,\n document.body\n );\n}\n\nexport default CoreMemoryModal;\n"],"names":["_jsxs","_jsx","_Fragment"],"mappings":";;;;;;;;AAgBA;AACA,MAAM,QAAQ,GAAG,CAAC,SAAS,EAAE,cAAc,EAAE,WAAW,EAAE,SAAS,CAAU;AAkCtE,MAAM,0BAA0B,GAAqB;AAC1D,IAAA,KAAK,EAAE,kBAAkB;AACzB,IAAA,KAAK,EAAE,OAAO;AACd,IAAA,OAAO,EAAE,iBAAiB;AAC1B,IAAA,QAAQ,EAAE,2CAA2C;AACrD,IAAA,KAAK,EACH,yFAAyF;AAC3F,IAAA,MAAM,EAAE,qDAAqD;AAC7D,IAAA,IAAI,EAAE,MAAM;AACZ,IAAA,MAAM,EAAE,QAAQ;AAChB,IAAA,IAAI,EAAE,MAAM;AACZ,IAAA,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, useMemo, useEffect } from 'react';
|
|
3
|
+
import { useTranslations } from '../../i18n/useTranslations.js';
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* Modal for submitting feedback with optional comment
|
|
6
7
|
*/
|
|
7
8
|
function FeedbackModal({ isOpen, onClose, onSubmit, feedbackType, isSubmitting = false, theme, }) {
|
|
9
|
+
const t = useTranslations();
|
|
8
10
|
const [comment, setComment] = useState('');
|
|
9
11
|
const textareaRef = useRef(null);
|
|
10
12
|
const modalRef = useRef(null);
|
|
@@ -68,7 +70,9 @@ function FeedbackModal({ isOpen, onClose, onSubmit, feedbackType, isSubmitting =
|
|
|
68
70
|
onSubmit(comment);
|
|
69
71
|
}
|
|
70
72
|
};
|
|
71
|
-
return (jsx("div", { className: "devic-feedback-overlay", children: jsxs("div", { className: "devic-feedback-modal", ref: modalRef, style: modalStyle, children: [jsxs("div", { className: "devic-feedback-modal-header", children: [jsx("span", { className: "devic-feedback-modal-icon", children: feedbackType === 'positive' ? jsx(ThumbsUpIcon, { filled: true }) : jsx(ThumbsDownIcon, { filled: true }) }), jsx("span", { className: "devic-feedback-modal-title", children: feedbackType === 'positive'
|
|
73
|
+
return (jsx("div", { className: "devic-feedback-overlay", children: jsxs("div", { className: "devic-feedback-modal", ref: modalRef, style: modalStyle, children: [jsxs("div", { className: "devic-feedback-modal-header", children: [jsx("span", { className: "devic-feedback-modal-icon", children: feedbackType === 'positive' ? jsx(ThumbsUpIcon, { filled: true }) : jsx(ThumbsDownIcon, { filled: true }) }), jsx("span", { className: "devic-feedback-modal-title", children: feedbackType === 'positive'
|
|
74
|
+
? t('What did you like?')
|
|
75
|
+
: t('What could be improved?') }), jsx("button", { type: "button", className: "devic-feedback-modal-close", onClick: onClose, "aria-label": t('Close'), children: jsx(CloseIcon, {}) })] }), jsxs("form", { onSubmit: handleSubmit, children: [jsx("textarea", { ref: textareaRef, className: "devic-feedback-textarea", placeholder: t('Add a comment (optional)...'), value: comment, onChange: (e) => setComment(e.target.value), onKeyDown: handleKeyDown, rows: 3, disabled: isSubmitting }), jsxs("div", { className: "devic-feedback-modal-actions", children: [jsx("button", { type: "button", className: "devic-feedback-btn devic-feedback-btn--secondary", onClick: onClose, disabled: isSubmitting, children: t('Cancel') }), jsx("button", { type: "submit", className: "devic-feedback-btn devic-feedback-btn--primary", disabled: isSubmitting, children: isSubmitting ? t('Sending...') : t('Submit') })] })] })] }) }));
|
|
72
76
|
}
|
|
73
77
|
/* ── Icons ── */
|
|
74
78
|
function ThumbsUpIcon({ filled = false }) {
|