@ai-matrx/chat 0.6.6 → 0.7.1
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/CHANGELOG.md +42 -0
- package/README.md +1 -1
- package/dist/agents/components/agent-widgets/AgentChatHistorySidebar.js +16 -55
- package/dist/agents/components/chat/chat-door.d.ts +67 -0
- package/dist/agents/components/chat/chat-door.js +100 -0
- package/dist/agents/components/conversation-history/AgentConversationList.d.ts +83 -0
- package/dist/agents/components/conversation-history/AgentConversationList.js +252 -0
- package/dist/agents/components/conversation-history/ConversationArchiveSection.d.ts +5 -1
- package/dist/agents/components/conversation-history/ConversationArchiveSection.js +22 -4
- package/dist/agents/components/conversation-history/ConversationHistorySidebar.js +20 -65
- package/dist/agents/components/inputs/input-components/TextareaInput.js +2 -0
- package/dist/agents/components/inputs/input-components/VariableInputComponent.js +7 -6
- package/dist/agents/components/inputs/smart-input/ConversationCompanionPills.d.ts +3 -0
- package/dist/agents/components/inputs/smart-input/ConversationCompanionPills.js +40 -0
- package/dist/agents/components/inputs/smart-input/ConversationContextRail.js +6 -29
- package/dist/agents/components/inputs/smart-input/DeviceToolsModeRow.d.ts +3 -0
- package/dist/agents/components/inputs/smart-input/DeviceToolsModeRow.js +35 -0
- package/dist/agents/components/inputs/smart-input/InboxQueueStrip.js +0 -8
- package/dist/agents/components/inputs/smart-input/RunToolPicker.js +15 -11
- package/dist/agents/components/inputs/smart-input/composer/ComposerPlusMenu.js +22 -0
- package/dist/agents/components/inputs/smart-input/rail-pill.d.ts +35 -0
- package/dist/agents/components/inputs/smart-input/rail-pill.js +30 -0
- package/dist/agents/components/inputs/variable-input-variations/AgentVariableForm.js +52 -48
- package/dist/agents/components/run-controls/panels/shared.d.ts +1 -1
- package/dist/agents/components/shared/AgentModeController.js +3 -2
- package/dist/agents/components/shell/AgentRunSidebarMenu.js +15 -54
- package/dist/agents/components/working-document/documents-workspace/DocumentsListRail.js +1 -2
- package/dist/agents/engine.d.ts +15 -0
- package/dist/agents/engine.js +17 -0
- package/dist/agents/hooks/useModelControls.js +3 -175
- package/dist/agents/redux/agent-definition/selectors.d.ts +237 -237
- package/dist/agents/redux/agent-shortcut-categories/selectors.d.ts +50 -50
- package/dist/agents/redux/agent-shortcuts/selectors.d.ts +147 -147
- package/dist/agents/redux/conversation-history/thunks.js +6 -18
- package/dist/agents/redux/conversation-list/conversation-list.selectors.d.ts +1 -73
- package/dist/agents/redux/conversation-list/conversation-list.selectors.js +2 -36
- package/dist/agents/redux/conversation-list/conversation-list.slice.d.ts +7 -22
- package/dist/agents/redux/conversation-list/conversation-list.slice.js +7 -62
- package/dist/agents/redux/conversation-list/conversation-list.thunks.d.ts +0 -25
- package/dist/agents/redux/conversation-list/conversation-list.thunks.js +2 -58
- package/dist/agents/redux/conversation-list/conversation-list.types.d.ts +0 -5
- package/dist/agents/redux/conversation-list/conversation-rows.d.ts +16 -0
- package/dist/agents/redux/conversation-list/conversation-rows.js +24 -0
- package/dist/agents/redux/conversation-list/conversation-trash.thunks.d.ts +1 -0
- package/dist/agents/redux/conversation-list/conversation-trash.thunks.js +13 -18
- package/dist/agents/redux/execution-system/active-requests/active-requests.selectors.d.ts +54 -54
- package/dist/agents/redux/execution-system/context-state/context-state.selectors.d.ts +14 -14
- package/dist/agents/redux/execution-system/conversations/conversations.selectors.d.ts +5 -5
- package/dist/agents/redux/execution-system/instance-context/instance-context.selectors.d.ts +3 -3
- package/dist/agents/redux/execution-system/instance-resources/instance-resources.selectors.d.ts +8 -8
- package/dist/agents/redux/execution-system/instance-ui-state/instance-ui-state.selectors.d.ts +5 -5
- package/dist/agents/redux/execution-system/instance-variable-values/instance-variable-values.selectors.d.ts +7 -7
- package/dist/agents/redux/execution-system/messages/messages.selectors.d.ts +1 -1
- package/dist/agents/redux/execution-system/observability/observability.selectors.d.ts +7 -7
- package/dist/agents/redux/execution-system/observational-memory/observational-memory.selectors.d.ts +1 -1
- package/dist/agents/redux/execution-system/selectors/aggregate.selectors.d.ts +14 -14
- package/dist/agents/redux/execution-system/thunks/create-instance.thunk.d.ts +10 -1
- package/dist/agents/redux/execution-system/thunks/create-instance.thunk.js +114 -265
- package/dist/agents/redux/execution-system/thunks/dispatch-matrx-extend-tool.thunk.js +18 -2
- package/dist/agents/redux/execution-system/thunks/dispatch-surface-client-tool.thunk.js +10 -28
- package/dist/agents/redux/execution-system/thunks/dispatch-surface-write.thunk.js +10 -25
- package/dist/agents/redux/execution-system/thunks/execute-instance.thunk.js +20 -0
- package/dist/agents/redux/execution-system/thunks/execute-manual-instance.thunk.js +6 -1
- package/dist/agents/redux/execution-system/thunks/notify-and-play-dispatcher.d.ts +58 -0
- package/dist/agents/redux/execution-system/thunks/notify-and-play-dispatcher.js +62 -0
- package/dist/agents/redux/execution-system/thunks/post-delegated-tool-outcome.d.ts +23 -0
- package/dist/agents/redux/execution-system/thunks/post-delegated-tool-outcome.js +37 -0
- package/dist/agents/redux/execution-system/thunks/resume-instance.thunk.js +10 -2
- package/dist/agents/redux/execution-system/utils/build-tool-injection.d.ts +7 -0
- package/dist/agents/redux/execution-system/utils/build-tool-injection.js +18 -6
- package/dist/agents/redux/execution-system/utils/host-turn.d.ts +45 -0
- package/dist/agents/redux/execution-system/utils/host-turn.js +119 -0
- package/dist/agents/redux/proposed-directives/proposedDirectivesSlice.d.ts +1 -1
- package/dist/agents/scribe-tools/dispatcher/dispatch-scribe-tool.thunk.d.ts +50 -20
- package/dist/agents/scribe-tools/dispatcher/dispatch-scribe-tool.thunk.js +9 -101
- package/dist/agents/types/tool-injection.types.d.ts +18 -2
- package/dist/agents/ui-first-tools/redux/agent-lists.selectors.d.ts +2 -2
- package/dist/agents/ui-first-tools/redux/pending-asks.slice.d.ts +2 -1
- package/dist/agents/ui-first-tools/redux/resolve-asks-with-input.thunk.js +1 -1
- package/dist/agents/ui-first-tools/tools/ask-response.d.ts +29 -0
- package/dist/agents/ui-first-tools/tools/ask-response.js +15 -0
- package/dist/agents/ui-first-tools/tools/schemas.d.ts +3 -25
- package/dist/agents/ui-first-tools/tools/schemas.js +1 -12
- package/dist/agents/ui-first-tools/ui/ApprovalCard.js +1 -1
- package/dist/agents/ui-first-tools/ui/AskWizard.d.ts +1 -1
- package/dist/agents/ui-first-tools/ui/AskWizard.js +1 -1
- package/dist/cx-chat/_legacy-stubs.d.ts +5 -5
- package/dist/cx-chat/components/SsrSidebarChats.js +13 -15
- package/dist/cx-chat/components/messages/UserMessage.d.ts +2 -2
- package/dist/cx-chat/types/conversation.d.ts +6 -6
- package/dist/cx-chat/utils/buildContentBlocksForSave.d.ts +1 -1
- package/dist/cx-chat/utils/cx-content-converter.d.ts +1 -1
- package/dist/host/bare-host-chrome.js +9 -3
- package/dist/host/composer-extensions.d.ts +75 -0
- package/dist/host/composer-extensions.js +92 -0
- package/dist/host/configure.js +1 -0
- package/dist/host/contract.d.ts +105 -13
- package/dist/host/defaults/confirm.d.ts +15 -0
- package/dist/host/defaults/confirm.js +25 -0
- package/dist/host/defaults/files-ui.d.ts +85 -0
- package/dist/host/defaults/files-ui.js +158 -0
- package/dist/host/defaults/gates.d.ts +27 -0
- package/dist/host/defaults/gates.js +72 -0
- package/dist/host/defaults/media-client.d.ts +15 -0
- package/dist/host/defaults/media-client.js +40 -0
- package/dist/host/defaults/voice.d.ts +81 -0
- package/dist/host/defaults/voice.js +239 -0
- package/dist/host/device-tool-handoff.d.ts +26 -0
- package/dist/host/device-tool-handoff.js +45 -0
- package/dist/host/index.d.ts +1 -0
- package/dist/host/index.js +4 -1
- package/dist/host/microphone.d.ts +11 -0
- package/dist/host/microphone.js +17 -0
- package/dist/host/ui-slots.d.ts +29 -74
- package/dist/host/ui-slots.js +40 -42
- package/dist/store/create-chat-store.d.ts +2 -2
- package/dist/store/middlewares.d.ts +5 -5
- package/dist/store/slices.d.ts +1 -1
- package/dist/surfaces/redux/selectors.d.ts +2 -2
- package/dist/tool-call-visualization/components/ToolCallVisualization.js +3 -2
- package/dist/tool-call-visualization/configured-rows/ConfiguredRowRenderer.d.ts +15 -0
- package/dist/tool-call-visualization/configured-rows/ConfiguredRowRenderer.js +36 -0
- package/dist/tool-call-visualization/configured-rows/ConfiguredToolRow.d.ts +40 -0
- package/dist/tool-call-visualization/configured-rows/ConfiguredToolRow.js +296 -0
- package/dist/tool-call-visualization/configured-rows/CopyToolButton.d.ts +23 -0
- package/dist/tool-call-visualization/configured-rows/CopyToolButton.js +62 -0
- package/dist/tool-call-visualization/configured-rows/ToolProgressView.d.ts +23 -0
- package/dist/tool-call-visualization/configured-rows/ToolProgressView.js +147 -0
- package/dist/tool-call-visualization/configured-rows/field-components.d.ts +15 -0
- package/dist/tool-call-visualization/configured-rows/field-components.js +244 -0
- package/dist/tool-call-visualization/configured-rows/helpers.d.ts +39 -0
- package/dist/tool-call-visualization/configured-rows/helpers.js +110 -0
- package/dist/tool-call-visualization/configured-rows/register.d.ts +25 -0
- package/dist/tool-call-visualization/configured-rows/register.js +51 -0
- package/dist/tool-call-visualization/configured-rows/registries.d.ts +27 -0
- package/dist/tool-call-visualization/configured-rows/registries.js +14 -0
- package/dist/tool-call-visualization/configured-rows/to-row-entry.d.ts +8 -0
- package/dist/tool-call-visualization/configured-rows/to-row-entry.js +38 -0
- package/dist/tool-call-visualization/configured-rows/transforms.d.ts +14 -0
- package/dist/tool-call-visualization/configured-rows/transforms.js +30 -0
- package/dist/tool-call-visualization/configured-rows/types.d.ts +140 -0
- package/dist/tool-call-visualization/redux/selectors.d.ts +1 -1
- package/dist/tool-call-visualization/registry/registry.d.ts +1 -1
- package/dist/tool-call-visualization/registry/registry.js +8 -1
- package/dist/tool-call-visualization/types.d.ts +1 -1
- package/dist/ui/chat-protocol-types.d.ts +0 -1
- package/dist/ui/ownership.d.ts +25 -0
- package/dist/ui/ownership.js +18 -0
- package/dist/voice-agent/audio/audioCapture.js +11 -6
- package/dist/window-panels/windows/agents/AgentRunHistoryWindow.d.ts +1 -2
- package/dist/window-panels/windows/agents/AgentRunHistoryWindow.js +21 -181
- package/dist/window-panels/windows/agents/AgentRunWindow.js +26 -13
- package/package.json +4627 -125
- package/dist/agents/components/agent-widgets/chat-assistant/AssistantMessageCard.d.ts +0 -7
- package/dist/agents/components/agent-widgets/chat-assistant/AssistantMessageCard.js +0 -33
- package/dist/agents/components/agent-widgets/chat-assistant/StatusCard.d.ts +0 -6
- package/dist/agents/components/agent-widgets/chat-assistant/StatusCard.js +0 -21
- package/dist/agents/components/agent-widgets/chat-assistant/UserMessageCard.d.ts +0 -6
- package/dist/agents/components/agent-widgets/chat-assistant/UserMessageCard.js +0 -11
- package/dist/agents/components/agent-widgets/chat-assistant/VariableInputCard.d.ts +0 -12
- package/dist/agents/components/agent-widgets/chat-assistant/VariableInputCard.js +0 -7
- package/dist/agents/components/agent-widgets/execution-gates/PreExecutionCard.d.ts +0 -4
- package/dist/agents/components/agent-widgets/execution-gates/PreExecutionCard.js +0 -81
- package/dist/agents/components/run/run-sidebar/SidebarHeader.d.ts +0 -21
- package/dist/agents/components/run/run-sidebar/SidebarHeader.js +0 -50
- package/dist/agents/components/run-controls/AdvancedRunSettings/index.d.ts +0 -6
- package/dist/agents/components/run-controls/AdvancedRunSettings/index.js +0 -32
- package/dist/agents/components/run-controls/RunSettingsModal.d.ts +0 -5
- package/dist/agents/components/run-controls/RunSettingsModal.js +0 -22
- package/dist/agents/components/shell/AgentBuildSidebarExtras.d.ts +0 -6
- package/dist/agents/components/shell/AgentBuildSidebarExtras.js +0 -30
- package/dist/agents/constants/agent-system-competitors.d.ts +0 -9
- package/dist/agents/constants/agent-system-competitors.js +0 -125
- package/dist/agents/hooks/message-crud/useMessageActions.d.ts +0 -29
- package/dist/agents/hooks/message-crud/useMessageActions.js +0 -119
- package/dist/agents/hooks/useConversationPendingCalls.d.ts +0 -30
- package/dist/agents/hooks/useConversationPendingCalls.js +0 -42
- package/dist/agents/model-registry/model-classes.d.ts +0 -1
- package/dist/agents/model-registry/model-classes.js +0 -1
- package/dist/agents/redux/conversation-history/index.d.ts +0 -18
- package/dist/agents/redux/conversation-history/index.js +0 -4
- package/dist/agents/redux/execution-system/instance-variable-values/instance-variable-values.thunks.d.ts +0 -38
- package/dist/agents/redux/execution-system/instance-variable-values/instance-variable-values.thunks.js +0 -42
- package/dist/agents/redux/execution-system/message-crud/server/compact-turns.thunk.d.ts +0 -58
- package/dist/agents/redux/execution-system/message-crud/server/compact-turns.thunk.js +0 -50
- package/dist/agents/redux/execution-system/message-crud/server/fork-and-run-server.thunk.d.ts +0 -76
- package/dist/agents/redux/execution-system/message-crud/server/fork-and-run-server.thunk.js +0 -101
- package/dist/agents/redux/execution-system/thunks/attach-workflow-run.d.ts +0 -38
- package/dist/agents/redux/execution-system/thunks/attach-workflow-run.js +0 -25
- package/dist/agents/redux/execution-system/utils/source-slice-helpers.d.ts +0 -45
- package/dist/agents/redux/execution-system/utils/source-slice-helpers.js +0 -50
- package/dist/agents/runtime/realtime/launchRealtimeSession.thunk.d.ts +0 -25
- package/dist/agents/runtime/realtime/launchRealtimeSession.thunk.js +0 -15
- package/dist/agents/services/agentService.d.ts +0 -12
- package/dist/agents/services/agentService.js +0 -92
- package/dist/agents/utils/escape-code-fences.d.ts +0 -15
- package/dist/agents/utils/escape-code-fences.js +0 -9
- package/dist/agents/utils/normalize-managed-options.d.ts +0 -30
- package/dist/agents/utils/normalize-managed-options.js +0 -29
- package/dist/agents/utils/processedDocumentContext.d.ts +0 -51
- package/dist/agents/utils/processedDocumentContext.js +0 -51
- package/dist/agents/utils/variable-validation.d.ts +0 -28
- package/dist/agents/utils/variable-validation.js +0 -54
- package/dist/cx-chat/components/ChatConversationSkeleton.d.ts +0 -9
- package/dist/cx-chat/components/ChatConversationSkeleton.js +0 -45
- package/dist/cx-chat/components/ChatPanelBackButton.d.ts +0 -1
- package/dist/cx-chat/components/ChatPanelBackButton.js +0 -26
- package/dist/cx-chat/components/messages/MessageErrorBoundary.d.ts +0 -20
- package/dist/cx-chat/components/messages/MessageErrorBoundary.js +0 -40
- package/dist/cx-chat/components/variable-inputs/CheckboxGroupInput.d.ts +0 -14
- package/dist/cx-chat/components/variable-inputs/CheckboxGroupInput.js +0 -160
- package/dist/cx-chat/components/variable-inputs/NumberInput.d.ts +0 -15
- package/dist/cx-chat/components/variable-inputs/NumberInput.js +0 -79
- package/dist/cx-chat/components/variable-inputs/RadioGroupInput.d.ts +0 -14
- package/dist/cx-chat/components/variable-inputs/RadioGroupInput.js +0 -125
- package/dist/cx-chat/components/variable-inputs/SelectInput.d.ts +0 -14
- package/dist/cx-chat/components/variable-inputs/SelectInput.js +0 -92
- package/dist/cx-chat/components/variable-inputs/TextareaInput.d.ts +0 -14
- package/dist/cx-chat/components/variable-inputs/TextareaInput.js +0 -46
- package/dist/cx-chat/components/variable-inputs/ToggleInput.d.ts +0 -14
- package/dist/cx-chat/components/variable-inputs/ToggleInput.js +0 -46
- package/dist/cx-chat/hooks/useChatPersistence.d.ts +0 -28
- package/dist/cx-chat/hooks/useChatPersistence.js +0 -180
- package/dist/cx-chat/hooks/useInstanceBootstrap.d.ts +0 -1
- package/dist/cx-chat/hooks/useInstanceBootstrap.js +0 -115
- package/dist/cx-chat/types/content.d.ts +0 -184
- package/dist/cx-chat/types/content.js +0 -91
- package/dist/cx-chat/types/cx-tables.d.ts +0 -176
- package/dist/cx-chat/utils/settings-diff.d.ts +0 -13
- package/dist/cx-chat/utils/settings-diff.js +0 -25
- package/dist/public-chat/components/AgentSelector.d.ts +0 -22
- package/dist/public-chat/components/AgentSelector.js +0 -80
- package/dist/public-chat/components/GuidedVariableInputs.d.ts +0 -25
- package/dist/public-chat/components/GuidedVariableInputs.js +0 -623
- package/dist/public-chat/components/PublicVariableInputs.d.ts +0 -29
- package/dist/public-chat/components/PublicVariableInputs.js +0 -172
- package/dist/public-chat/types/content.d.ts +0 -184
- package/dist/public-chat/types/content.js +0 -91
- package/dist/tool-call-visualization/renderers/_shared-entity/EntityOpenActions.d.ts +0 -15
- package/dist/tool-call-visualization/renderers/_shared-entity/EntityOpenActions.js +0 -31
- package/dist/tool-call-visualization/utils/toolCallBlockToLifecycleEntry.d.ts +0 -24
- package/dist/tool-call-visualization/utils/toolCallBlockToLifecycleEntry.js +0 -26
- package/dist/ui/AudioOutputBlockSkeleton.d.ts +0 -17
- package/dist/ui/AudioOutputBlockSkeleton.js +0 -78
- package/dist/ui/lazy/PublicChatVariableInputs.d.ts +0 -2
- package/dist/ui/lazy/PublicChatVariableInputs.js +0 -16
- package/dist/utils/xml/readXmlTag.d.ts +0 -12
- package/dist/utils/xml/readXmlTag.js +0 -66
- /package/dist/{cx-chat/types/cx-tables.js → tool-call-visualization/configured-rows/types.js} +0 -0
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { Label } from "@ai-matrx/design-system";
|
|
3
|
-
import { Switch } from "../../../ui/switch.js";
|
|
4
|
-
function ToggleInput({
|
|
5
|
-
value,
|
|
6
|
-
onChange,
|
|
7
|
-
offLabel = "No",
|
|
8
|
-
onLabel = "Yes",
|
|
9
|
-
variableName,
|
|
10
|
-
compact = false
|
|
11
|
-
}) {
|
|
12
|
-
const isOn = value === onLabel;
|
|
13
|
-
const handleToggle = (checked) => {
|
|
14
|
-
onChange(checked ? onLabel : offLabel);
|
|
15
|
-
};
|
|
16
|
-
return /* @__PURE__ */ jsxs("div", { className: compact ? "space-y-1" : "space-y-4", children: [
|
|
17
|
-
value && value !== onLabel && value !== offLabel && /* @__PURE__ */ jsxs("div", { className: compact ? "p-1.5 bg-amber-50 dark:bg-amber-900/20 border border-amber-200 dark:border-amber-800 rounded" : "p-3 bg-amber-50 dark:bg-amber-900/20 border border-amber-200 dark:border-amber-800 rounded-lg", children: [
|
|
18
|
-
/* @__PURE__ */ jsx("p", { className: compact ? "text-[11px] font-medium text-amber-800 dark:text-amber-300 mb-0.5" : "text-xs font-medium text-amber-800 dark:text-amber-300 mb-1", children: "Current value:" }),
|
|
19
|
-
/* @__PURE__ */ jsx("p", { className: compact ? "text-xs text-amber-900 dark:text-amber-200" : "text-sm text-amber-900 dark:text-amber-200", children: value }),
|
|
20
|
-
/* @__PURE__ */ jsx("p", { className: compact ? "text-[11px] text-amber-700 dark:text-amber-400 mt-0.5" : "text-xs text-amber-700 dark:text-amber-400 mt-1", children: "Select an option below to replace" })
|
|
21
|
-
] }),
|
|
22
|
-
/* @__PURE__ */ jsxs("div", { className: compact ? "flex items-center justify-between p-2 bg-background rounded border-border" : "flex items-center justify-between p-4 bg-background rounded-lg border-border", children: [
|
|
23
|
-
/* @__PURE__ */ jsxs("div", { className: compact ? "" : "space-y-1", children: [
|
|
24
|
-
/* @__PURE__ */ jsxs(Label, { className: compact ? "text-xs font-medium" : "text-sm font-medium", children: [
|
|
25
|
-
offLabel,
|
|
26
|
-
" / ",
|
|
27
|
-
onLabel
|
|
28
|
-
] }),
|
|
29
|
-
!compact && /* @__PURE__ */ jsxs("p", { className: "text-xs text-gray-500 dark:text-gray-400", children: [
|
|
30
|
-
"Currently: ",
|
|
31
|
-
/* @__PURE__ */ jsx("span", { className: "font-medium", children: isOn ? onLabel : offLabel })
|
|
32
|
-
] })
|
|
33
|
-
] }),
|
|
34
|
-
/* @__PURE__ */ jsx(
|
|
35
|
-
Switch,
|
|
36
|
-
{
|
|
37
|
-
checked: isOn,
|
|
38
|
-
onCheckedChange: handleToggle
|
|
39
|
-
}
|
|
40
|
-
)
|
|
41
|
-
] })
|
|
42
|
-
] });
|
|
43
|
-
}
|
|
44
|
-
export {
|
|
45
|
-
ToggleInput
|
|
46
|
-
};
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import type { CxConversationSummary, CxConversationWithMessages, CxMessageRole } from "../types/cx-tables.js";
|
|
2
|
-
/** Minimal chat message shape used by saveMessages */
|
|
3
|
-
interface ChatMessage {
|
|
4
|
-
id: string;
|
|
5
|
-
role: CxMessageRole;
|
|
6
|
-
content: string;
|
|
7
|
-
variables?: Record<string, string>;
|
|
8
|
-
resources?: unknown[];
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* Client-side hook for persisting chat data to cx_ tables via API routes.
|
|
12
|
-
*
|
|
13
|
-
* Handles: creating conversations, saving messages, loading history, rename, delete.
|
|
14
|
-
*/
|
|
15
|
-
export declare function useChatPersistence(): {
|
|
16
|
-
createConversation: (params: {
|
|
17
|
-
title?: string;
|
|
18
|
-
systemInstruction?: string;
|
|
19
|
-
}) => Promise<string | null>;
|
|
20
|
-
saveMessages: (conversationId: string, messages: ChatMessage[], organizationId: string) => Promise<boolean>;
|
|
21
|
-
loadHistory: (limit?: number, offset?: number) => Promise<CxConversationSummary[]>;
|
|
22
|
-
loadConversation: (conversationId: string) => Promise<CxConversationWithMessages | null>;
|
|
23
|
-
renameConversation: (conversationId: string, newTitle: string) => Promise<boolean>;
|
|
24
|
-
deleteConversation: (conversationId: string) => Promise<boolean>;
|
|
25
|
-
updateConversationStatus: (conversationId: string, status: "active" | "completed" | "archived") => Promise<boolean>;
|
|
26
|
-
pendingConversationId: string | null;
|
|
27
|
-
};
|
|
28
|
-
export {};
|
|
@@ -1,180 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { useCallback, useRef } from "react";
|
|
3
|
-
function useChatPersistence() {
|
|
4
|
-
const pendingConversationId = useRef(null);
|
|
5
|
-
const createConversation = useCallback(
|
|
6
|
-
async (params) => {
|
|
7
|
-
try {
|
|
8
|
-
const res = await fetch("/api/cx-chat/request", {
|
|
9
|
-
method: "POST",
|
|
10
|
-
headers: { "Content-Type": "application/json" },
|
|
11
|
-
body: JSON.stringify({
|
|
12
|
-
title: params.title,
|
|
13
|
-
system_instruction: params.systemInstruction
|
|
14
|
-
})
|
|
15
|
-
});
|
|
16
|
-
const json = await res.json();
|
|
17
|
-
if (json.success && json.data?.id) {
|
|
18
|
-
pendingConversationId.current = json.data.id;
|
|
19
|
-
return json.data.id;
|
|
20
|
-
}
|
|
21
|
-
return null;
|
|
22
|
-
} catch (error) {
|
|
23
|
-
console.error("createConversation error:", error);
|
|
24
|
-
return null;
|
|
25
|
-
}
|
|
26
|
-
},
|
|
27
|
-
[]
|
|
28
|
-
);
|
|
29
|
-
const saveMessages = useCallback(
|
|
30
|
-
async (conversationId, messages, organizationId) => {
|
|
31
|
-
try {
|
|
32
|
-
const cxMessages = messages.map((msg, index) => {
|
|
33
|
-
const content = [
|
|
34
|
-
{
|
|
35
|
-
type: "text",
|
|
36
|
-
text: msg.content
|
|
37
|
-
}
|
|
38
|
-
];
|
|
39
|
-
return {
|
|
40
|
-
organization_id: organizationId,
|
|
41
|
-
conversation_id: conversationId,
|
|
42
|
-
role: msg.role,
|
|
43
|
-
position: index,
|
|
44
|
-
content,
|
|
45
|
-
metadata: {
|
|
46
|
-
...msg.variables ? { variables: msg.variables } : {},
|
|
47
|
-
...msg.resources ? { resources: msg.resources } : {}
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
});
|
|
51
|
-
const res = await fetch("/api/cx-chat/messages", {
|
|
52
|
-
method: "POST",
|
|
53
|
-
headers: { "Content-Type": "application/json" },
|
|
54
|
-
body: JSON.stringify({ messages: cxMessages })
|
|
55
|
-
});
|
|
56
|
-
const json = await res.json();
|
|
57
|
-
return json.success;
|
|
58
|
-
} catch (error) {
|
|
59
|
-
console.error("saveMessages error:", error);
|
|
60
|
-
return false;
|
|
61
|
-
}
|
|
62
|
-
},
|
|
63
|
-
[]
|
|
64
|
-
);
|
|
65
|
-
const loadHistory = useCallback(
|
|
66
|
-
async (limit = 50, offset = 0) => {
|
|
67
|
-
try {
|
|
68
|
-
const params = new URLSearchParams({
|
|
69
|
-
limit: String(limit),
|
|
70
|
-
offset: String(offset)
|
|
71
|
-
});
|
|
72
|
-
const url = `/api/cx-chat/history?${params}`;
|
|
73
|
-
console.log("[useChatPersistence] loadHistory \u2192", url);
|
|
74
|
-
const res = await fetch(url);
|
|
75
|
-
console.log(
|
|
76
|
-
"[useChatPersistence] loadHistory response:",
|
|
77
|
-
res.status,
|
|
78
|
-
res.statusText
|
|
79
|
-
);
|
|
80
|
-
const json = await res.json();
|
|
81
|
-
if (!json.success) {
|
|
82
|
-
console.warn("[useChatPersistence] loadHistory failed:", json.error);
|
|
83
|
-
}
|
|
84
|
-
return json.success ? json.data : [];
|
|
85
|
-
} catch (error) {
|
|
86
|
-
console.error("[useChatPersistence] loadHistory error:", error);
|
|
87
|
-
return [];
|
|
88
|
-
}
|
|
89
|
-
},
|
|
90
|
-
[]
|
|
91
|
-
);
|
|
92
|
-
const loadConversation = useCallback(
|
|
93
|
-
async (conversationId) => {
|
|
94
|
-
try {
|
|
95
|
-
const url = `/api/cx-chat/request?id=${conversationId}`;
|
|
96
|
-
console.log("[useChatPersistence] loadConversation \u2192", url);
|
|
97
|
-
const res = await fetch(url);
|
|
98
|
-
console.log(
|
|
99
|
-
"[useChatPersistence] loadConversation response:",
|
|
100
|
-
res.status,
|
|
101
|
-
res.statusText
|
|
102
|
-
);
|
|
103
|
-
const json = await res.json();
|
|
104
|
-
if (!json.success) {
|
|
105
|
-
console.warn(
|
|
106
|
-
"[useChatPersistence] loadConversation failed:",
|
|
107
|
-
json.error
|
|
108
|
-
);
|
|
109
|
-
}
|
|
110
|
-
return json.success ? json.data : null;
|
|
111
|
-
} catch (error) {
|
|
112
|
-
console.error("[useChatPersistence] loadConversation error:", error);
|
|
113
|
-
return null;
|
|
114
|
-
}
|
|
115
|
-
},
|
|
116
|
-
[]
|
|
117
|
-
);
|
|
118
|
-
const renameConversation = useCallback(
|
|
119
|
-
async (conversationId, newTitle) => {
|
|
120
|
-
try {
|
|
121
|
-
const res = await fetch("/api/cx-chat/request", {
|
|
122
|
-
method: "PATCH",
|
|
123
|
-
headers: { "Content-Type": "application/json" },
|
|
124
|
-
body: JSON.stringify({ id: conversationId, title: newTitle })
|
|
125
|
-
});
|
|
126
|
-
const json = await res.json();
|
|
127
|
-
return json.success;
|
|
128
|
-
} catch (error) {
|
|
129
|
-
console.error("renameConversation error:", error);
|
|
130
|
-
return false;
|
|
131
|
-
}
|
|
132
|
-
},
|
|
133
|
-
[]
|
|
134
|
-
);
|
|
135
|
-
const deleteConversation = useCallback(
|
|
136
|
-
async (conversationId) => {
|
|
137
|
-
try {
|
|
138
|
-
const res = await fetch(`/api/cx-chat/request?id=${conversationId}`, {
|
|
139
|
-
method: "DELETE"
|
|
140
|
-
});
|
|
141
|
-
const json = await res.json();
|
|
142
|
-
return json.success;
|
|
143
|
-
} catch (error) {
|
|
144
|
-
console.error("deleteConversation error:", error);
|
|
145
|
-
return false;
|
|
146
|
-
}
|
|
147
|
-
},
|
|
148
|
-
[]
|
|
149
|
-
);
|
|
150
|
-
const updateConversationStatus = useCallback(
|
|
151
|
-
async (conversationId, status) => {
|
|
152
|
-
try {
|
|
153
|
-
const res = await fetch("/api/cx-chat/request", {
|
|
154
|
-
method: "PATCH",
|
|
155
|
-
headers: { "Content-Type": "application/json" },
|
|
156
|
-
body: JSON.stringify({ id: conversationId, status })
|
|
157
|
-
});
|
|
158
|
-
const json = await res.json();
|
|
159
|
-
return json.success;
|
|
160
|
-
} catch (error) {
|
|
161
|
-
console.error("updateConversationStatus error:", error);
|
|
162
|
-
return false;
|
|
163
|
-
}
|
|
164
|
-
},
|
|
165
|
-
[]
|
|
166
|
-
);
|
|
167
|
-
return {
|
|
168
|
-
createConversation,
|
|
169
|
-
saveMessages,
|
|
170
|
-
loadHistory,
|
|
171
|
-
loadConversation,
|
|
172
|
-
renameConversation,
|
|
173
|
-
deleteConversation,
|
|
174
|
-
updateConversationStatus,
|
|
175
|
-
pendingConversationId: pendingConversationId.current
|
|
176
|
-
};
|
|
177
|
-
}
|
|
178
|
-
export {
|
|
179
|
-
useChatPersistence
|
|
180
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function useInstanceBootstrap(): void;
|
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { useEffect, useRef } from "react";
|
|
3
|
-
import { usePathname, useSearchParams, useRouter } from "../../host/navigation.js";
|
|
4
|
-
import { useAppDispatch } from "../../store/hooks.js";
|
|
5
|
-
import {
|
|
6
|
-
fetchAgentExecutionMinimal
|
|
7
|
-
} from "../../agents/redux/agent-definition/thunks.js";
|
|
8
|
-
import { launchAgentExecution } from "../../agents/redux/execution-system/thunks/launch-agent-execution.thunk.js";
|
|
9
|
-
import { loadConversation } from "../../agents/redux/execution-system/thunks/load-conversation.thunk.js";
|
|
10
|
-
import { followWhatIsStillInFlight } from "../../agents/runtime-reconnect/follow-what-is-still-in-flight.js";
|
|
11
|
-
import { toast } from "../../host/notify.js";
|
|
12
|
-
import { isNotAuthenticatedError } from "../../host/identity.js";
|
|
13
|
-
import { isOrganizationSelectionCancelled } from "../../host/org.js";
|
|
14
|
-
import { DEFAULT_AGENT_ID } from "../components/agent/local-agents.js";
|
|
15
|
-
import { replaceAddressWithoutNavigating } from "@ai-matrx/rich-content/utils/addressWithoutNavigating";
|
|
16
|
-
import { ensureAgentCatalog, isAgentCatalogStale } from "../../agents/identity/agent-identity.js";
|
|
17
|
-
function parseChatUrl(pathname, searchParams) {
|
|
18
|
-
const agentPathMatch = pathname.match(/\/demos\/chat\/a\/([^/?]+)/);
|
|
19
|
-
const convPathMatch = pathname.match(/\/demos\/chat\/c\/([^/?]+)/);
|
|
20
|
-
const agentId = agentPathMatch?.[1] ?? searchParams.get("agent") ?? DEFAULT_AGENT_ID;
|
|
21
|
-
return {
|
|
22
|
-
agentId,
|
|
23
|
-
conversationId: convPathMatch?.[1] ?? null,
|
|
24
|
-
instanceId: searchParams.get("instance")
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
function withInstanceParam(pathname, searchParams, instanceId) {
|
|
28
|
-
const params = new URLSearchParams(searchParams.toString());
|
|
29
|
-
params.set("instance", instanceId);
|
|
30
|
-
return `${pathname}?${params.toString()}`;
|
|
31
|
-
}
|
|
32
|
-
function useInstanceBootstrap() {
|
|
33
|
-
const dispatch = useAppDispatch();
|
|
34
|
-
const router = useRouter();
|
|
35
|
-
const pathname = usePathname();
|
|
36
|
-
const searchParams = useSearchParams();
|
|
37
|
-
const instanceByAgentId = useRef(/* @__PURE__ */ new Map());
|
|
38
|
-
const lastKey = useRef(null);
|
|
39
|
-
useEffect(() => {
|
|
40
|
-
void ensureAgentCatalog();
|
|
41
|
-
}, [dispatch]);
|
|
42
|
-
useEffect(() => {
|
|
43
|
-
const handleVisibility = () => {
|
|
44
|
-
if (document.visibilityState === "visible" && isAgentCatalogStale()) {
|
|
45
|
-
void ensureAgentCatalog({ force: true });
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
document.addEventListener("visibilitychange", handleVisibility);
|
|
49
|
-
return () => document.removeEventListener("visibilitychange", handleVisibility);
|
|
50
|
-
}, [dispatch]);
|
|
51
|
-
useEffect(() => {
|
|
52
|
-
const {
|
|
53
|
-
agentId,
|
|
54
|
-
conversationId,
|
|
55
|
-
instanceId: urlInstanceId
|
|
56
|
-
} = parseChatUrl(pathname, searchParams);
|
|
57
|
-
const key = `${agentId}::${conversationId ?? ""}`;
|
|
58
|
-
if (key === lastKey.current) return;
|
|
59
|
-
lastKey.current = key;
|
|
60
|
-
(async () => {
|
|
61
|
-
await dispatch(fetchAgentExecutionMinimal(agentId));
|
|
62
|
-
let resolvedId = null;
|
|
63
|
-
if (urlInstanceId) {
|
|
64
|
-
const stillAlive = await dispatch(
|
|
65
|
-
(_, getState) => !!getState().conversations.byConversationId[urlInstanceId]
|
|
66
|
-
);
|
|
67
|
-
if (stillAlive) resolvedId = urlInstanceId;
|
|
68
|
-
}
|
|
69
|
-
if (!resolvedId) {
|
|
70
|
-
const cached = instanceByAgentId.current.get(agentId);
|
|
71
|
-
if (cached) {
|
|
72
|
-
const stillAlive = await dispatch(
|
|
73
|
-
(_, getState) => !!getState().conversations.byConversationId[cached]
|
|
74
|
-
);
|
|
75
|
-
if (stillAlive) resolvedId = cached;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
if (!resolvedId) {
|
|
79
|
-
const result = await dispatch(
|
|
80
|
-
launchAgentExecution({
|
|
81
|
-
surfaceKey: `cx-chat:${agentId}`,
|
|
82
|
-
agentId,
|
|
83
|
-
sourceFeature: "chat",
|
|
84
|
-
config: {
|
|
85
|
-
autoRun: false,
|
|
86
|
-
displayMode: "direct"
|
|
87
|
-
}
|
|
88
|
-
})
|
|
89
|
-
);
|
|
90
|
-
if (launchAgentExecution.fulfilled.match(result)) {
|
|
91
|
-
resolvedId = result.payload.conversationId;
|
|
92
|
-
instanceByAgentId.current.set(agentId, resolvedId);
|
|
93
|
-
} else if (launchAgentExecution.rejected.match(result) && // Signed out is a state (the sign-in gate), not a failed launch.
|
|
94
|
-
!isNotAuthenticatedError(result.error) && // A closed organization chooser is the person's "not now", never a failure.
|
|
95
|
-
!isOrganizationSelectionCancelled(result.error)) {
|
|
96
|
-
toast.error(
|
|
97
|
-
result.error.message ?? "Failed to start the agent conversation."
|
|
98
|
-
);
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
if (!resolvedId) return;
|
|
102
|
-
if (searchParams.get("instance") !== resolvedId) {
|
|
103
|
-
replaceAddressWithoutNavigating(withInstanceParam(pathname, searchParams, resolvedId));
|
|
104
|
-
}
|
|
105
|
-
if (conversationId) {
|
|
106
|
-
void dispatch(loadConversation({ conversationId })).finally(
|
|
107
|
-
() => followWhatIsStillInFlight(dispatch, conversationId)
|
|
108
|
-
);
|
|
109
|
-
}
|
|
110
|
-
})();
|
|
111
|
-
}, [pathname, searchParams]);
|
|
112
|
-
}
|
|
113
|
-
export {
|
|
114
|
-
useInstanceBootstrap
|
|
115
|
-
};
|
|
@@ -1,184 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* BACKEND SUPPORTED TYPES (from types/agent-api.ts):
|
|
3
|
-
* - input_text: { type, text }
|
|
4
|
-
* - input_image: { type, url }
|
|
5
|
-
* - input_audio: { type, url }
|
|
6
|
-
* - input_file: { type, url }
|
|
7
|
-
*
|
|
8
|
-
* All file/media types use a consistent 'url' field for the resource location.
|
|
9
|
-
* Backend accepts [key: string]: unknown, so additional fields won't break.
|
|
10
|
-
*/
|
|
11
|
-
/**
|
|
12
|
-
* Base content item - all content items have a type
|
|
13
|
-
*/
|
|
14
|
-
interface BaseContentItem {
|
|
15
|
-
type: string;
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* Text input content
|
|
19
|
-
* Backend field: text
|
|
20
|
-
*/
|
|
21
|
-
export interface TextContentItem extends BaseContentItem {
|
|
22
|
-
type: 'input_text';
|
|
23
|
-
text: string;
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Image input content
|
|
27
|
-
* Backend field: url
|
|
28
|
-
*/
|
|
29
|
-
export interface ImageContentItem extends BaseContentItem {
|
|
30
|
-
type: 'input_image';
|
|
31
|
-
url: string;
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Audio input content
|
|
35
|
-
* Backend field: url
|
|
36
|
-
*/
|
|
37
|
-
export interface AudioContentItem extends BaseContentItem {
|
|
38
|
-
type: 'input_audio';
|
|
39
|
-
url: string;
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Generic file input (server will determine type)
|
|
43
|
-
* Backend field: url
|
|
44
|
-
*/
|
|
45
|
-
export interface FileContentItem extends BaseContentItem {
|
|
46
|
-
type: 'input_file';
|
|
47
|
-
url: string;
|
|
48
|
-
}
|
|
49
|
-
export type VideoContentItem = FileContentItem;
|
|
50
|
-
export type DocumentContentItem = FileContentItem;
|
|
51
|
-
/**
|
|
52
|
-
* YouTube video content
|
|
53
|
-
* Note: Backend may not support this - sending as-is for future support
|
|
54
|
-
*/
|
|
55
|
-
export interface YouTubeContentItem extends BaseContentItem {
|
|
56
|
-
type: 'youtube_video';
|
|
57
|
-
url: string;
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* Webpage content (scraped text)
|
|
61
|
-
* Note: Backend may not support this - sending as-is for future support
|
|
62
|
-
*/
|
|
63
|
-
export interface WebpageContentItem extends BaseContentItem {
|
|
64
|
-
type: 'input_webpage';
|
|
65
|
-
url: string;
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* Note content (from Matrx notes)
|
|
69
|
-
* Note: Backend may not support this - sending as-is for future support
|
|
70
|
-
*/
|
|
71
|
-
export interface NoteContentItem extends BaseContentItem {
|
|
72
|
-
type: 'input_note';
|
|
73
|
-
note_id: string;
|
|
74
|
-
title: string;
|
|
75
|
-
content: string;
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Task content (from Matrx tasks)
|
|
79
|
-
* Note: Backend may not support this - sending as-is for future support
|
|
80
|
-
*/
|
|
81
|
-
export interface TaskContentItem extends BaseContentItem {
|
|
82
|
-
type: 'input_task';
|
|
83
|
-
task_id: string;
|
|
84
|
-
title: string;
|
|
85
|
-
description?: string;
|
|
86
|
-
status?: string;
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
* Table content (from Matrx tables)
|
|
90
|
-
* Note: Backend may not support this - sending as-is for future support
|
|
91
|
-
*/
|
|
92
|
-
export interface TableContentItem extends BaseContentItem {
|
|
93
|
-
type: 'input_table';
|
|
94
|
-
table_id: string;
|
|
95
|
-
table_name: string;
|
|
96
|
-
data?: string;
|
|
97
|
-
}
|
|
98
|
-
/**
|
|
99
|
-
* Union type for all content items
|
|
100
|
-
*/
|
|
101
|
-
export type ContentItem = TextContentItem | ImageContentItem | AudioContentItem | VideoContentItem | DocumentContentItem | YouTubeContentItem | FileContentItem | WebpageContentItem | NoteContentItem | TaskContentItem | TableContentItem;
|
|
102
|
-
/**
|
|
103
|
-
* Resource types that can be attached to messages.
|
|
104
|
-
* Aligned with features/prompts/types/resources.ts for full cross-route parity.
|
|
105
|
-
*
|
|
106
|
-
* - 'file' — Uploaded canonical file
|
|
107
|
-
* - 'image_link' — Direct image URL (alias for image_url, kept for backward compat)
|
|
108
|
-
* - 'image_url' — Direct image URL (canonical name, matches prompts system)
|
|
109
|
-
* - 'file_link' — Direct file URL (alias for file_url, kept for backward compat)
|
|
110
|
-
* - 'file_url' — Direct file URL (canonical name, matches prompts system)
|
|
111
|
-
* - 'audio' — Audio file
|
|
112
|
-
* - 'youtube' — YouTube video
|
|
113
|
-
* - 'webpage' — Scraped webpage content
|
|
114
|
-
* - 'note' — Matrx note (requires auth)
|
|
115
|
-
* - 'task' — Matrx task (requires auth)
|
|
116
|
-
* - 'project' — Matrx project (requires auth)
|
|
117
|
-
* - 'table' — Matrx table / data reference (requires auth)
|
|
118
|
-
* - 'storage' — File from Matrx storage browser (requires auth)
|
|
119
|
-
*/
|
|
120
|
-
export type PublicResourceType = 'file' | 'image_link' | 'image_url' | 'file_link' | 'file_url' | 'audio' | 'youtube' | 'webpage' | 'note' | 'task' | 'project' | 'table' | 'storage';
|
|
121
|
-
/**
|
|
122
|
-
* Public resource structure.
|
|
123
|
-
* The `data` bag is intentionally flexible so that both the public chat
|
|
124
|
-
* and the authenticated prompts system can share the same type without
|
|
125
|
-
* requiring separate conversion layers.
|
|
126
|
-
*/
|
|
127
|
-
export interface PublicResource {
|
|
128
|
-
type: PublicResourceType;
|
|
129
|
-
data: {
|
|
130
|
-
url?: string;
|
|
131
|
-
filename?: string;
|
|
132
|
-
mime_type?: string;
|
|
133
|
-
type?: string;
|
|
134
|
-
size?: number;
|
|
135
|
-
id?: string;
|
|
136
|
-
title?: string;
|
|
137
|
-
content?: string;
|
|
138
|
-
description?: string;
|
|
139
|
-
label?: string;
|
|
140
|
-
folder_name?: string;
|
|
141
|
-
tags?: string[];
|
|
142
|
-
status?: string;
|
|
143
|
-
priority?: string;
|
|
144
|
-
project_id?: string;
|
|
145
|
-
project_name?: string;
|
|
146
|
-
name?: string;
|
|
147
|
-
table_name?: string;
|
|
148
|
-
table_id?: string;
|
|
149
|
-
table_type?: 'full_table' | 'table_row' | 'table_column' | 'table_cell';
|
|
150
|
-
row_id?: string;
|
|
151
|
-
column_name?: string;
|
|
152
|
-
text_content?: string;
|
|
153
|
-
video_id?: string;
|
|
154
|
-
videoId?: string;
|
|
155
|
-
transcript?: string;
|
|
156
|
-
filepath?: string;
|
|
157
|
-
duration?: number;
|
|
158
|
-
[key: string]: unknown;
|
|
159
|
-
};
|
|
160
|
-
}
|
|
161
|
-
/**
|
|
162
|
-
* Convert a PublicResource to a ContentItem for the API.
|
|
163
|
-
*
|
|
164
|
-
* Backend natively supports: input_text, input_image, input_audio, input_file.
|
|
165
|
-
* All other types are sent with their type name for future backend support.
|
|
166
|
-
*/
|
|
167
|
-
export declare function resourceToContentItem(resource: PublicResource): ContentItem | null;
|
|
168
|
-
/**
|
|
169
|
-
* Build content array from text and resources
|
|
170
|
-
*/
|
|
171
|
-
export declare function buildContentArray(text: string, resources: PublicResource[]): ContentItem[];
|
|
172
|
-
/**
|
|
173
|
-
* Adapter: convert a prompts `Resource` (from features/prompts/types/resources.ts)
|
|
174
|
-
* to a `PublicResource` so that the prompts picker components can be reused in any route
|
|
175
|
-
* without requiring callers to depend on the prompts type system directly.
|
|
176
|
-
*
|
|
177
|
-
* The prompts Resource discriminated union uses canonical names that already match
|
|
178
|
-
* the extended PublicResourceType, so this is a safe cast with data normalisation.
|
|
179
|
-
*/
|
|
180
|
-
export declare function promptsResourceToPublicResource(resource: {
|
|
181
|
-
type: string;
|
|
182
|
-
data: Record<string, unknown>;
|
|
183
|
-
}): PublicResource;
|
|
184
|
-
export {};
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
function resourceToContentItem(resource) {
|
|
2
|
-
const { type, data } = resource;
|
|
3
|
-
switch (type) {
|
|
4
|
-
// ── Media / file types ────────────────────────────────────────────
|
|
5
|
-
case "image_link":
|
|
6
|
-
case "image_url":
|
|
7
|
-
if (!data.url) return null;
|
|
8
|
-
return { type: "input_image", url: data.url };
|
|
9
|
-
case "file_link":
|
|
10
|
-
case "file_url":
|
|
11
|
-
if (!data.url) return null;
|
|
12
|
-
return { type: "input_file", url: data.url };
|
|
13
|
-
case "audio":
|
|
14
|
-
if (!data.url) return null;
|
|
15
|
-
return { type: "input_audio", url: data.url };
|
|
16
|
-
case "file":
|
|
17
|
-
case "storage": {
|
|
18
|
-
if (!data.url) return null;
|
|
19
|
-
const mimeType = data.mime_type ?? data.type ?? "";
|
|
20
|
-
if (mimeType.startsWith("image/")) return { type: "input_image", url: data.url };
|
|
21
|
-
if (mimeType.startsWith("audio/")) return { type: "input_audio", url: data.url };
|
|
22
|
-
return { type: "input_file", url: data.url };
|
|
23
|
-
}
|
|
24
|
-
case "youtube":
|
|
25
|
-
if (!data.url) return null;
|
|
26
|
-
return { type: "youtube_video", url: data.url };
|
|
27
|
-
case "webpage":
|
|
28
|
-
if (!data.url) return null;
|
|
29
|
-
return { type: "input_webpage", url: data.url };
|
|
30
|
-
// ── Matrx data types (backend receives structured objects) ────────
|
|
31
|
-
case "note":
|
|
32
|
-
return {
|
|
33
|
-
type: "input_note",
|
|
34
|
-
note_id: data.id ?? "",
|
|
35
|
-
title: data.label ?? data.title ?? data.filename ?? "Note",
|
|
36
|
-
content: data.content ?? ""
|
|
37
|
-
};
|
|
38
|
-
case "task":
|
|
39
|
-
return {
|
|
40
|
-
type: "input_task",
|
|
41
|
-
task_id: data.id ?? "",
|
|
42
|
-
title: data.title ?? "Task",
|
|
43
|
-
description: data.description,
|
|
44
|
-
status: data.status
|
|
45
|
-
};
|
|
46
|
-
case "project":
|
|
47
|
-
return {
|
|
48
|
-
type: "input_task",
|
|
49
|
-
task_id: data.id ?? "",
|
|
50
|
-
title: data.name ?? data.title ?? "Project",
|
|
51
|
-
description: data.description
|
|
52
|
-
};
|
|
53
|
-
case "table":
|
|
54
|
-
return {
|
|
55
|
-
type: "input_table",
|
|
56
|
-
table_id: data.table_id ?? data.id ?? "",
|
|
57
|
-
table_name: data.table_name ?? data.title ?? "Table",
|
|
58
|
-
data: typeof data.content === "string" ? data.content : JSON.stringify(data.content ?? {})
|
|
59
|
-
};
|
|
60
|
-
default:
|
|
61
|
-
console.warn("Unknown resource type:", type);
|
|
62
|
-
return null;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
function buildContentArray(text, resources) {
|
|
66
|
-
const content = [];
|
|
67
|
-
if (text.trim()) {
|
|
68
|
-
content.push({
|
|
69
|
-
type: "input_text",
|
|
70
|
-
text
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
for (const resource of resources) {
|
|
74
|
-
const item = resourceToContentItem(resource);
|
|
75
|
-
if (item) {
|
|
76
|
-
content.push(item);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
return content;
|
|
80
|
-
}
|
|
81
|
-
function promptsResourceToPublicResource(resource) {
|
|
82
|
-
return {
|
|
83
|
-
type: resource.type,
|
|
84
|
-
data: resource.data
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
export {
|
|
88
|
-
buildContentArray,
|
|
89
|
-
promptsResourceToPublicResource,
|
|
90
|
-
resourceToContentItem
|
|
91
|
-
};
|