@ai-matrx/chat 0.4.0 → 0.4.7
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 +80 -0
- package/dist/agent-copy/RichCopySplit.d.ts +17 -0
- package/dist/agent-copy/RichCopySplit.js +34 -0
- package/dist/agents/addressing/useAgentHref.js +4 -1
- package/dist/agents/api/submit-tool-results.js +11 -1
- package/dist/agents/components/agent-widgets/chat-assistant/AssistantMessageCard.js +1 -1
- package/dist/agents/components/chat/ConversationRecordsChip.js +1 -1
- package/dist/agents/components/chat/useCanvasScopedToConversation.js +1 -1
- package/dist/agents/components/context-items/bodies/WorkingDocumentBody.d.ts +5 -2
- package/dist/agents/components/context-items/bodies/WorkingDocumentBody.js +6 -1
- package/dist/agents/components/context-policies-display/ContextValueBody.js +1 -1
- package/dist/agents/components/context-preview/ContextCompareView.js +1 -1
- package/dist/agents/components/custom-agent/CustomAgentWindow.js +1 -1
- package/dist/agents/components/inputs/smart-input/AgentTextarea.d.ts +6 -1
- package/dist/agents/components/inputs/smart-input/AgentTextarea.js +2 -2
- package/dist/agents/components/inputs/smart-input/ComposerToolsNotice.d.ts +1 -0
- package/dist/agents/components/inputs/smart-input/ComposerToolsNotice.js +5 -0
- package/dist/agents/components/inputs/smart-input/ConversationContextRail.d.ts +5 -1
- package/dist/agents/components/inputs/smart-input/ConversationContextRail.js +6 -1
- package/dist/agents/components/inputs/smart-input/InboxQueueStrip.d.ts +6 -1
- package/dist/agents/components/inputs/smart-input/InboxQueueStrip.js +6 -1
- package/dist/agents/components/inputs/smart-input/InputActionButtons.js +8 -6
- package/dist/agents/components/inputs/smart-input/SmartInputFileDropTarget.d.ts +5 -1
- package/dist/agents/components/inputs/smart-input/SmartInputFileDropTarget.js +8 -1
- package/dist/agents/components/inputs/smart-input/composer/ComposerAgentPill.js +2 -2
- package/dist/agents/components/inputs/smart-input/composer/ComposerChipsRow.d.ts +5 -2
- package/dist/agents/components/inputs/smart-input/composer/ComposerChipsRow.js +6 -1
- package/dist/agents/components/inputs/smart-input/composer/ComposerMetaRow.d.ts +6 -8
- package/dist/agents/components/inputs/smart-input/composer/ComposerMetaRow.js +13 -1
- package/dist/agents/components/inputs/smart-input/composer/useOutputShapeCatalog.d.ts +1 -1
- package/dist/agents/components/inputs/smart-input/composer/useOutputShapeCatalog.js +1 -1
- package/dist/agents/components/live-run/LiveRunDisplay.js +1 -1
- package/dist/agents/components/live-run/RunSetDisplay.js +1 -1
- package/dist/agents/components/memory/components/AgentMemoryAllView.js +1 -1
- package/dist/agents/components/messages-display/AgentConversationDisplay.js +4 -1
- package/dist/agents/components/messages-display/assistant/AgentAssistantMessage.d.ts +1 -0
- package/dist/agents/components/messages-display/assistant/AgentAssistantMessage.js +4 -3
- package/dist/agents/components/messages-display/assistant/AgentEmptyMessageDisplay.js +1 -1
- package/dist/agents/components/messages-display/assistant/AssistantMessageFooter.d.ts +2 -2
- package/dist/agents/components/messages-display/assistant/AssistantMessageFooter.js +4 -7
- package/dist/agents/components/messages-display/assistant/InPlaceAnswerEditor.js +2 -2
- package/dist/agents/components/messages-display/citations/MessageSourcesRow.js +1 -1
- package/dist/agents/components/messages-display/rich-document/chat-message-source.d.ts +2 -0
- package/dist/agents/components/messages-display/rich-document/chat-message-source.js +41 -0
- package/dist/agents/components/messages-display/rich-document/chatMessageActions.d.ts +31 -0
- package/dist/agents/components/messages-display/rich-document/chatMessageActions.js +39 -0
- package/dist/agents/components/messages-display/user/AgentUserMessage.d.ts +1 -0
- package/dist/agents/components/messages-display/user/AgentUserMessage.js +7 -4
- package/dist/agents/components/messages-display/user/CollabNoteMessage.js +1 -1
- package/dist/agents/components/messages-display/user/UserActionBar.js +49 -39
- package/dist/agents/components/run-controls/panels/shared.d.ts +1 -0
- package/dist/agents/components/shared/AgentConversationColumn.js +3 -2
- package/dist/agents/components/working-document/WorkingDocumentEditor.d.ts +1 -1
- package/dist/agents/components/working-document/WorkingDocumentPanel.js +2 -1
- package/dist/agents/components/working-document/workingDocumentSurface.d.ts +1 -1
- package/dist/agents/identity/model-catalog.js +5 -3
- package/dist/agents/identity/run-tier-store.js +3 -0
- package/dist/agents/redux/agent-definition/cache-bust-middleware.js +2 -0
- package/dist/agents/redux/agent-definition/selectors.d.ts +237 -0
- package/dist/agents/redux/agent-settings/agentSettingsSlice.d.ts +0 -4
- package/dist/agents/redux/agent-settings/agentSettingsSlice.js +12 -5
- package/dist/agents/redux/agent-settings/selectors.d.ts +12 -0
- package/dist/agents/redux/agent-shortcut-categories/selectors.d.ts +50 -0
- package/dist/agents/redux/agent-shortcuts/selectors.d.ts +147 -0
- package/dist/agents/redux/conversation-history/selectors.d.ts +16 -0
- package/dist/agents/redux/conversation-list/conversation-list.selectors.d.ts +2 -0
- package/dist/agents/redux/execution-system/active-requests/active-requests.selectors.d.ts +54 -0
- package/dist/agents/redux/execution-system/context-state/context-state.selectors.d.ts +14 -0
- package/dist/agents/redux/execution-system/conversations/conversations.selectors.d.ts +5 -0
- package/dist/agents/redux/execution-system/host-conversations/conversation-abilities.d.ts +12 -0
- package/dist/agents/redux/execution-system/host-conversations/conversation-abilities.js +25 -0
- package/dist/agents/redux/execution-system/host-conversations/host-conversation.thunks.d.ts +53 -0
- package/dist/agents/redux/execution-system/host-conversations/host-conversation.thunks.js +412 -0
- package/dist/agents/redux/execution-system/host-conversations/host-conversations.selectors.d.ts +28 -0
- package/dist/agents/redux/execution-system/host-conversations/host-conversations.selectors.js +41 -0
- package/dist/agents/redux/execution-system/host-conversations/host-conversations.slice.d.ts +43 -0
- package/dist/agents/redux/execution-system/host-conversations/host-conversations.slice.js +38 -0
- package/dist/agents/redux/execution-system/host-conversations/source-registry.d.ts +9 -0
- package/dist/agents/redux/execution-system/host-conversations/source-registry.js +15 -0
- package/dist/agents/redux/execution-system/host-conversations/useHostConversation.d.ts +4 -0
- package/dist/agents/redux/execution-system/host-conversations/useHostConversation.js +24 -0
- package/dist/agents/redux/execution-system/inbox/inbox-turn-end.middleware.js +2 -1
- package/dist/agents/redux/execution-system/instance-context/instance-context.selectors.d.ts +3 -0
- package/dist/agents/redux/execution-system/instance-resources/default-remark-durability.d.ts +22 -0
- package/dist/agents/redux/execution-system/instance-resources/default-remark-durability.js +164 -0
- package/dist/agents/redux/execution-system/instance-resources/instance-resources.selectors.d.ts +8 -0
- package/dist/agents/redux/execution-system/instance-ui-state/instance-ui-state.selectors.d.ts +5 -0
- package/dist/agents/redux/execution-system/instance-ui-state/run-configuration-persist.js +2 -0
- package/dist/agents/redux/execution-system/instance-user-input/composer-draft-store.js +20 -0
- package/dist/agents/redux/execution-system/instance-user-input/useComposerDraftRestore.js +2 -1
- package/dist/agents/redux/execution-system/instance-variable-values/instance-variable-values.selectors.d.ts +7 -0
- package/dist/agents/redux/execution-system/messages/messages.selectors.d.ts +1 -0
- package/dist/agents/redux/execution-system/messages/messages.selectors.js +1 -1
- package/dist/agents/redux/execution-system/observability/observability.selectors.d.ts +7 -0
- package/dist/agents/redux/execution-system/observational-memory/observational-memory.selectors.d.ts +1 -0
- package/dist/agents/redux/execution-system/selectors/aggregate.selectors.d.ts +14 -0
- package/dist/agents/redux/execution-system/thunks/execute-instance.thunk.js +8 -1
- package/dist/agents/redux/execution-system/thunks/execute-manual-instance.thunk.js +2 -1
- package/dist/agents/redux/execution-system/thunks/load-conversation.thunk.js +6 -0
- package/dist/agents/redux/execution-system/thunks/load-older-messages.thunk.js +12 -0
- package/dist/agents/redux/execution-system/thunks/process-stream.js +6 -4
- package/dist/agents/redux/execution-system/thunks/resolve-base-url.js +1 -1
- package/dist/agents/redux/execution-system/thunks/smart-execute.thunk.js +43 -0
- package/dist/agents/redux/execution-system/utils/assemble-cx-content-blocks.js +2 -1
- package/dist/agents/redux/execution-system/utils/continuation-body.d.ts +1 -0
- package/dist/agents/redux/execution-system/utils/continuation-body.js +2 -1
- package/dist/agents/redux/execution-system/utils/inbound-render-block.d.ts +8 -0
- package/dist/agents/redux/execution-system/utils/inbound-render-block.js +17 -2
- package/dist/agents/redux/execution-system/utils/normalize-content-blocks.js +1 -1
- package/dist/agents/redux/execution-system/utils/progress-data-block.d.ts +11 -0
- package/dist/agents/redux/execution-system/utils/progress-data-block.js +37 -0
- package/dist/agents/redux/execution-system/utils/stream-block-accumulator.js +10 -8
- package/dist/agents/redux/mcp/mcp.slice.js +15 -7
- package/dist/agents/redux/proposed-directives/proposedDirectivesSlice.d.ts +1 -0
- package/dist/agents/redux/tools/tools.selectors.d.ts +1 -0
- package/dist/agents/redux/tools/tools.thunks.js +3 -0
- package/dist/agents/resources/default-picker-items.d.ts +17 -0
- package/dist/agents/resources/default-picker-items.js +48 -0
- package/dist/agents/runtime-reconnect/ServerOperationBanner.d.ts +6 -1
- package/dist/agents/runtime-reconnect/ServerOperationBanner.js +6 -1
- package/dist/agents/types/instance.types.d.ts +2 -1
- package/dist/agents/ui-first-tools/redux/agent-lists.selectors.d.ts +2 -0
- package/dist/agents/ui-first-tools/ui/ApprovalCard.js +1 -1
- package/dist/agents/ui-first-tools/ui/AskCard.js +1 -1
- package/dist/agents/ui-first-tools/ui/lists/TaskPanel.js +1 -1
- package/dist/conversation/hooks/useDomCapturePrint.js +1 -1
- package/dist/conversation/utils/markdown-print.js +1 -1
- package/dist/cx-chat/components/SsrSidebarChats.js +1 -1
- package/dist/cx-chat/components/messages/AssistantMessage.js +3 -5
- package/dist/cx-chat/components/sidebar/SidebarUserFooter.js +1 -1
- package/dist/cx-conversation/AssistantMessage.js +3 -5
- package/dist/host/app-data-slots.d.ts +85 -0
- package/dist/host/app-data-slots.js +42 -0
- package/dist/host/app-identity.d.ts +20 -0
- package/dist/host/app-identity.js +21 -0
- package/dist/host/bare-host-chrome.d.ts +14 -0
- package/dist/host/bare-host-chrome.js +45 -0
- package/dist/host/configure.d.ts +9 -1
- package/dist/host/configure.js +44 -8
- package/dist/host/contract.d.ts +39 -2
- package/dist/host/db-types.d.ts +99 -1
- package/dist/host/defaults/navigation-hooks.d.ts +2 -0
- package/dist/host/defaults/navigation-hooks.js +7 -1
- package/dist/host/defaults/navigation.d.ts +4 -3
- package/dist/host/defaults/navigation.js +38 -7
- package/dist/host/defaults/org.d.ts +12 -4
- package/dist/host/defaults/org.js +39 -1
- package/dist/host/defaults/prefs.d.ts +11 -0
- package/dist/host/defaults/prefs.js +43 -0
- package/dist/host/defaults/workspace-gate.d.ts +16 -0
- package/dist/host/defaults/workspace-gate.js +89 -0
- package/dist/host/diagnostics.d.ts +7 -2
- package/dist/host/diagnostics.js +6 -0
- package/dist/host/identity.js +2 -1
- package/dist/host/index.d.ts +6 -3
- package/dist/host/index.js +23 -2
- package/dist/host/no-database.d.ts +38 -0
- package/dist/host/no-database.js +107 -0
- package/dist/host/react.d.ts +1 -0
- package/dist/host/react.js +40 -2
- package/dist/host/registered-source.js +2 -2
- package/dist/host/source.d.ts +130 -0
- package/dist/host/source.js +86 -0
- package/dist/host/ui-slots.d.ts +9 -31
- package/dist/host/ui-slots.js +5 -37
- package/dist/mandates/useMandate.js +13 -0
- package/dist/public-chat/components/PublicMessageOptionsMenu.js +3 -2
- package/dist/store/create-chat-store.d.ts +4 -2
- package/dist/store/middlewares.d.ts +5 -0
- package/dist/store/slices.d.ts +1 -0
- package/dist/store/slices.js +4 -1
- package/dist/surfaces/redux/selectors.d.ts +2 -0
- package/dist/surfaces/redux/surfaceConfigSlice.js +2 -0
- package/dist/surfaces/redux/userStateSlice.js +3 -1
- package/dist/surfaces/runtime/agent-offer.js +1 -1
- package/dist/surfaces/runtime/surface-writeback.js +1 -1
- package/dist/testing/turn-harness.d.ts +35 -0
- package/dist/testing/turn-harness.js +85 -0
- package/dist/tool-call-visualization/db-renderer/fetchToolRendererRow.js +2 -0
- package/dist/tool-call-visualization/redux/selectors.d.ts +1 -0
- package/dist/tool-call-visualization/renderers/agent-call/AgentCallInline.js +1 -1
- package/dist/tool-call-visualization/renderers/agent-call/CollabCallCard.js +1 -1
- package/dist/tool-call-visualization/renderers/fs/FsInline.js +1 -1
- package/dist/tool-call-visualization/renderers/random-wheel/RandomWheelInline.js +1 -1
- package/dist/tool-call-visualization/renderers/research/ResearchOverlay.js +4 -4
- package/dist/tool-call-visualization/renderers/research/SubagentReportBlock.js +2 -2
- package/dist/tool-call-visualization/renderers/scrape/ScrapeOverlay.js +1 -1
- package/dist/tool-call-visualization/renderers/search/SearchInline.js +1 -1
- package/dist/tool-call-visualization/renderers/search/SearchOverlay.js +1 -1
- package/dist/tool-call-visualization/renderers/sql/SqlInline.js +1 -1
- package/dist/tool-call-visualization/result-fields/KeyValueGrid.js +1 -1
- package/dist/tool-call-visualization/result-fields/ResultMarkdown.js +1 -1
- package/dist/tool-call-visualization/result-fields/ResultValue.js +1 -1
- package/dist/tool-call-visualization/surface-write/SurfaceWriteDiff.js +1 -1
- package/dist/ui/AudioOutputBlockSkeleton.d.ts +17 -0
- package/dist/ui/AudioOutputBlockSkeleton.js +78 -0
- package/dist/ui/chat-protocol-from-stream.d.ts +60 -0
- package/dist/ui/chat-protocol-from-stream.js +135 -0
- package/dist/ui/markdown-stream/EnhancedChatMarkdown.d.ts +59 -0
- package/dist/ui/markdown-stream/EnhancedChatMarkdown.js +1108 -0
- package/dist/ui/markdown-stream/MarkdownStream.d.ts +88 -0
- package/dist/ui/markdown-stream/MarkdownStream.js +14 -0
- package/dist/ui/markdown-stream/MarkdownStreamImpl.d.ts +4 -0
- package/dist/ui/markdown-stream/MarkdownStreamImpl.js +86 -0
- package/dist/ui/markdown-stream/StreamAwareChatMarkdown.d.ts +58 -0
- package/dist/ui/markdown-stream/StreamAwareChatMarkdown.js +294 -0
- package/dist/ui/markdown-stream/internal-handlers/AgentCallChildTrace.d.ts +22 -0
- package/dist/ui/markdown-stream/internal-handlers/AgentCallChildTrace.js +128 -0
- package/dist/ui/markdown-stream/internal-handlers/InlineAssistantError.d.ts +3 -0
- package/dist/ui/markdown-stream/internal-handlers/InlineAssistantError.js +26 -0
- package/dist/ui/markdown-stream/internal-handlers/InlineThinkingSlot.d.ts +14 -0
- package/dist/ui/markdown-stream/internal-handlers/InlineThinkingSlot.js +23 -0
- package/dist/ui/markdown-stream/internal-handlers/ToolHandlers.d.ts +42 -0
- package/dist/ui/markdown-stream/internal-handlers/ToolHandlers.js +109 -0
- package/dist/ui/markdown-stream/useBoundAgentOutputSchema.d.ts +2 -0
- package/dist/ui/markdown-stream/useBoundAgentOutputSchema.js +33 -0
- package/dist/window-panels/windows/agents/AgentAssistantMarkdownDebugWindow.js +1 -1
- package/package.json +10 -5
- package/dist/host/content-ir-slots.d.ts +0 -231
- package/dist/host/content-ir-slots.js +0 -131
- package/dist/host/markdown-slots.d.ts +0 -53
- package/dist/host/markdown-slots.js +0 -32
- package/dist/host/rich-document-slots.d.ts +0 -123
- package/dist/host/rich-document-slots.js +0 -36
- package/dist/utils/content-ir/report-kind-at-raw-renderer.d.ts +0 -19
- package/dist/utils/content-ir/report-kind-at-raw-renderer.js +0 -32
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useEffect, useMemo, useState, useSyncExternalStore } from "react";
|
|
4
|
+
import { useChatHost } from "../react.js";
|
|
5
|
+
import { chatHostHasDatabase } from "../configure.js";
|
|
6
|
+
import { invalidateMandateCache } from "../../mandates/service.js";
|
|
7
|
+
const PAGE = 500;
|
|
8
|
+
const CHUNK = 100;
|
|
9
|
+
function DefaultWorkspaceGate({ blocked, sentence, description, children, className }) {
|
|
10
|
+
const host = useChatHost();
|
|
11
|
+
const active = useSyncExternalStore(host.org.subscribe, host.org.active, () => null);
|
|
12
|
+
if (!blocked || active || !host.org.choose || !chatHostHasDatabase()) return /* @__PURE__ */ jsx(Fragment, { children });
|
|
13
|
+
return /* @__PURE__ */ jsx(WorkspacePicker, { sentence, description, className });
|
|
14
|
+
}
|
|
15
|
+
function WorkspacePicker({ sentence, description, className }) {
|
|
16
|
+
const host = useChatHost();
|
|
17
|
+
const [orgs, setOrgs] = useState(null);
|
|
18
|
+
const [error, setError] = useState(null);
|
|
19
|
+
const [filter, setFilter] = useState("");
|
|
20
|
+
useEffect(() => {
|
|
21
|
+
let cancelled = false;
|
|
22
|
+
void (async () => {
|
|
23
|
+
const db = host.db;
|
|
24
|
+
const ids = [];
|
|
25
|
+
for (let from = 0; ; from += PAGE) {
|
|
26
|
+
const { data, error: e } = await db.rpc("mbr_for_user", { p_container_type: "organization" }).order("id", { ascending: true }).range(from, from + PAGE - 1);
|
|
27
|
+
if (e) throw new Error(e.message);
|
|
28
|
+
const page = Array.isArray(data) ? data : [];
|
|
29
|
+
ids.push(...page.map((row) => row.container_id));
|
|
30
|
+
if (page.length < PAGE) break;
|
|
31
|
+
}
|
|
32
|
+
const found = [];
|
|
33
|
+
for (let i = 0; i < ids.length; i += CHUNK) {
|
|
34
|
+
const { data, error: e } = await db.schema("iam").from("organizations").select("id,name").in("id", ids.slice(i, i + CHUNK)).is("archived_at", null);
|
|
35
|
+
if (e) throw new Error(e.message);
|
|
36
|
+
found.push(...data ?? []);
|
|
37
|
+
}
|
|
38
|
+
found.sort((a, b) => (a.name ?? "").localeCompare(b.name ?? ""));
|
|
39
|
+
if (!cancelled) setOrgs(found);
|
|
40
|
+
})().catch((e) => {
|
|
41
|
+
if (cancelled) return;
|
|
42
|
+
const message = e instanceof Error ? e.message : String(e);
|
|
43
|
+
host.diagnostics.capture(e, { area: "org", code: "workspace-list-failed" });
|
|
44
|
+
setError(message);
|
|
45
|
+
});
|
|
46
|
+
return () => {
|
|
47
|
+
cancelled = true;
|
|
48
|
+
};
|
|
49
|
+
}, [host]);
|
|
50
|
+
const shown = useMemo(() => {
|
|
51
|
+
const q = filter.trim().toLowerCase();
|
|
52
|
+
return (orgs ?? []).filter((o) => !q || (o.name ?? "").toLowerCase().includes(q)).slice(0, 50);
|
|
53
|
+
}, [orgs, filter]);
|
|
54
|
+
const choose = (org) => {
|
|
55
|
+
host.org.choose?.(org);
|
|
56
|
+
invalidateMandateCache();
|
|
57
|
+
};
|
|
58
|
+
return /* @__PURE__ */ jsx("div", { "data-testid": "workspace-gate", className: className ?? "flex h-full min-h-0 w-full flex-col items-center overflow-y-auto p-6", children: /* @__PURE__ */ jsxs("div", { className: "w-full max-w-sm space-y-2", children: [
|
|
59
|
+
/* @__PURE__ */ jsx("p", { className: "text-sm font-medium", children: sentence }),
|
|
60
|
+
description ? /* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground", children: description }) : null,
|
|
61
|
+
error ? /* @__PURE__ */ jsxs("p", { className: "text-xs text-destructive", children: [
|
|
62
|
+
"Couldn't list your organizations: ",
|
|
63
|
+
error
|
|
64
|
+
] }) : orgs === null ? /* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground", children: "Loading your organizations\u2026" }) : orgs.length === 0 ? /* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground", children: "You are not a member of any organization." }) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
65
|
+
orgs.length > 8 ? /* @__PURE__ */ jsx(
|
|
66
|
+
"input",
|
|
67
|
+
{
|
|
68
|
+
value: filter,
|
|
69
|
+
onChange: (e) => setFilter(e.target.value),
|
|
70
|
+
placeholder: "Find an organization",
|
|
71
|
+
className: "w-full rounded-md border border-border bg-background px-2 py-1 text-sm"
|
|
72
|
+
}
|
|
73
|
+
) : null,
|
|
74
|
+
/* @__PURE__ */ jsx("ul", { className: "divide-y divide-border rounded-md border border-border", children: shown.map((org) => /* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsx(
|
|
75
|
+
"button",
|
|
76
|
+
{
|
|
77
|
+
type: "button",
|
|
78
|
+
"data-workspace-choice": org.id,
|
|
79
|
+
onClick: () => choose(org),
|
|
80
|
+
className: "w-full px-3 py-2 text-left text-sm hover:bg-muted",
|
|
81
|
+
children: org.name ?? org.id
|
|
82
|
+
}
|
|
83
|
+
) }, org.id)) })
|
|
84
|
+
] })
|
|
85
|
+
] }) });
|
|
86
|
+
}
|
|
87
|
+
export {
|
|
88
|
+
DefaultWorkspaceGate
|
|
89
|
+
};
|
|
@@ -81,8 +81,13 @@ export interface StreamClientErrorInput {
|
|
|
81
81
|
export declare function captureStreamClientError(input: StreamClientErrorInput): void;
|
|
82
82
|
/** Test-only: drop held entries and restart local ids. */
|
|
83
83
|
export declare function _resetDiagnosticsForTests(): void;
|
|
84
|
+
/** The one degradation that is NOT a stand-in: the registration is missing and the call throws. */
|
|
85
|
+
export declare const SLOT_CANNOT_RUN = "it cannot run";
|
|
84
86
|
/**
|
|
85
|
-
* A host registration (UI slot, usage gate, model-class hooks) was never made
|
|
86
|
-
*
|
|
87
|
+
* A host registration (UI slot, usage gate, model-class hooks) was never made.
|
|
88
|
+
*
|
|
89
|
+
* A stand-in is an OPTIONAL enhancement the host may add: it announces itself ONCE as a quiet
|
|
90
|
+
* console info line and nothing else (Law 4: announced, not an error). A registration the package
|
|
91
|
+
* CANNOT run without (`SLOT_CANNOT_RUN`) is an error: console warning + the host's diagnostics.
|
|
87
92
|
*/
|
|
88
93
|
export declare function reportUnregisteredHostSlot(name: string, degraded: string): void;
|
package/dist/host/diagnostics.js
CHANGED
|
@@ -146,8 +146,13 @@ function _resetDiagnosticsForTests() {
|
|
|
146
146
|
early = [];
|
|
147
147
|
localIds = 0;
|
|
148
148
|
}
|
|
149
|
+
const SLOT_CANNOT_RUN = "it cannot run";
|
|
149
150
|
function reportUnregisteredHostSlot(name, degraded) {
|
|
150
151
|
const message = `The host registered no "${name}" for the chat package, so ${degraded}.`;
|
|
152
|
+
if (degraded !== SLOT_CANNOT_RUN) {
|
|
153
|
+
announceOnce(`chat-host-slot:${name}`, message, "info");
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
151
156
|
if (!announceOnce(`chat-host-slot:${name}`, message)) return;
|
|
152
157
|
captureError({
|
|
153
158
|
source: "surface-registration",
|
|
@@ -162,6 +167,7 @@ function reportUnregisteredHostSlot(name, degraded) {
|
|
|
162
167
|
export {
|
|
163
168
|
EARLY_DIAGNOSTICS_LIMIT,
|
|
164
169
|
RecordUnavailableError,
|
|
170
|
+
SLOT_CANNOT_RUN,
|
|
165
171
|
_resetDiagnosticsForTests,
|
|
166
172
|
captureError,
|
|
167
173
|
captureReactRenderError,
|
package/dist/host/identity.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { SIGNED_OUT_IDENTITY } from "./defaults/identity.js";
|
|
2
|
-
import { getChatHost } from "./configure.js";
|
|
2
|
+
import { chatHostHasDatabase, getChatHost } from "./configure.js";
|
|
3
3
|
import { announceOnce } from "./errors.js";
|
|
4
4
|
import { getStoreSingleton } from "../store/store-singleton.js";
|
|
5
5
|
function identityOf(state) {
|
|
@@ -41,6 +41,7 @@ function requireUserId() {
|
|
|
41
41
|
return id;
|
|
42
42
|
}
|
|
43
43
|
async function hasBrowserSession() {
|
|
44
|
+
if (!chatHostHasDatabase()) return false;
|
|
44
45
|
let db;
|
|
45
46
|
try {
|
|
46
47
|
db = getChatHost().db;
|
package/dist/host/index.d.ts
CHANGED
|
@@ -2,14 +2,15 @@
|
|
|
2
2
|
* @ai-matrx/chat/host — the host contract (no React). React door: `@ai-matrx/chat/host/react`.
|
|
3
3
|
*/
|
|
4
4
|
export * from "./contract.js";
|
|
5
|
-
export { configureChat, getChatHost, isChatHostConfigured, resolveChatHost, _resetChatHostForTests, } from "./configure.js";
|
|
5
|
+
export { configureChat, DEFAULT_CHAT_APP, getChatHost, isChatHostConfigured, resolveChatHost, _resetChatHostForTests, } from "./configure.js";
|
|
6
|
+
export { attributionForSend, currentChatApp, type WireAttribution } from "./app-identity.js";
|
|
6
7
|
export { ChatHostInvalidError, ChatHostNotConfiguredError, ChatOrganizationRequiredError, } from "./errors.js";
|
|
7
8
|
export { createLogClientErrorDiagnostics, isChatSourceApp, CHAT_SOURCE_FEATURE, DIAGNOSTICS_FLUSH_DELAY_MS, DIAGNOSTICS_MAX_PER_FLUSH, } from "./defaults/diagnostics.js";
|
|
8
9
|
export { createDbIdentity, SIGNED_OUT_IDENTITY } from "./defaults/identity.js";
|
|
9
|
-
export { createNoPickerOrg } from "./defaults/org.js";
|
|
10
|
+
export { createNoPickerOrg, createStoredOrg, CHAT_ACTIVE_ORG_STORAGE_KEY } from "./defaults/org.js";
|
|
10
11
|
export { createDefaultServer, DEFAULT_CHAT_SERVER_URL, } from "./defaults/server.js";
|
|
11
12
|
export { createDomNotifier } from "./defaults/notify.js";
|
|
12
|
-
export { createWebPrefs, CHAT_PREFS_PREFIX } from "./defaults/prefs.js";
|
|
13
|
+
export { createWebPrefs, createHostKeptPrefs, CHAT_PREFS_PREFIX } from "./defaults/prefs.js";
|
|
13
14
|
export { createWindowNavigation } from "./defaults/navigation.js";
|
|
14
15
|
export { createUnhostedWindows } from "./defaults/windows.js";
|
|
15
16
|
export { CHAT_WINDOWS, CHAT_WINDOW_IDS, DEFAULT_WINDOW_INSTANCE_ID, isChatWindowId, type ChatWindowId, } from "./windows.js";
|
|
@@ -21,3 +22,5 @@ export { createUnhostedCanvas, UNHOSTED_CANVAS_VIEW } from "./defaults/canvas.js
|
|
|
21
22
|
export { DEFAULT_CHAT_ROUTES } from "./configure.js";
|
|
22
23
|
export { createClient, getClaimsUser, schedulerDb, supabase, type ChatClaimsUser, type ClaimsCapableClient, } from "./db.js";
|
|
23
24
|
export type { ChatDatabase } from "./db-types.js";
|
|
25
|
+
export { ChatNoDatabaseError, NO_DATABASE_CODE_PREFIX, createNoDatabaseStandIn, isChatNoDatabaseError, isNoDatabase, } from "./no-database.js";
|
|
26
|
+
export * from "./source.js";
|
package/dist/host/index.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
export * from "./contract.js";
|
|
2
2
|
import {
|
|
3
3
|
configureChat,
|
|
4
|
+
DEFAULT_CHAT_APP,
|
|
4
5
|
getChatHost,
|
|
5
6
|
isChatHostConfigured,
|
|
6
7
|
resolveChatHost,
|
|
7
8
|
_resetChatHostForTests
|
|
8
9
|
} from "./configure.js";
|
|
10
|
+
import { attributionForSend, currentChatApp } from "./app-identity.js";
|
|
9
11
|
import {
|
|
10
12
|
ChatHostInvalidError,
|
|
11
13
|
ChatHostNotConfiguredError,
|
|
@@ -19,13 +21,13 @@ import {
|
|
|
19
21
|
DIAGNOSTICS_MAX_PER_FLUSH
|
|
20
22
|
} from "./defaults/diagnostics.js";
|
|
21
23
|
import { createDbIdentity, SIGNED_OUT_IDENTITY } from "./defaults/identity.js";
|
|
22
|
-
import { createNoPickerOrg } from "./defaults/org.js";
|
|
24
|
+
import { createNoPickerOrg, createStoredOrg, CHAT_ACTIVE_ORG_STORAGE_KEY } from "./defaults/org.js";
|
|
23
25
|
import {
|
|
24
26
|
createDefaultServer,
|
|
25
27
|
DEFAULT_CHAT_SERVER_URL
|
|
26
28
|
} from "./defaults/server.js";
|
|
27
29
|
import { createDomNotifier } from "./defaults/notify.js";
|
|
28
|
-
import { createWebPrefs, CHAT_PREFS_PREFIX } from "./defaults/prefs.js";
|
|
30
|
+
import { createWebPrefs, createHostKeptPrefs, CHAT_PREFS_PREFIX } from "./defaults/prefs.js";
|
|
29
31
|
import { createWindowNavigation } from "./defaults/navigation.js";
|
|
30
32
|
import { createUnhostedWindows } from "./defaults/windows.js";
|
|
31
33
|
import {
|
|
@@ -45,23 +47,36 @@ import {
|
|
|
45
47
|
schedulerDb,
|
|
46
48
|
supabase
|
|
47
49
|
} from "./db.js";
|
|
50
|
+
import {
|
|
51
|
+
ChatNoDatabaseError,
|
|
52
|
+
NO_DATABASE_CODE_PREFIX,
|
|
53
|
+
createNoDatabaseStandIn,
|
|
54
|
+
isChatNoDatabaseError,
|
|
55
|
+
isNoDatabase
|
|
56
|
+
} from "./no-database.js";
|
|
57
|
+
export * from "./source.js";
|
|
48
58
|
export {
|
|
59
|
+
CHAT_ACTIVE_ORG_STORAGE_KEY,
|
|
49
60
|
CHAT_PREFS_PREFIX,
|
|
50
61
|
CHAT_SOURCE_FEATURE,
|
|
51
62
|
CHAT_WINDOWS,
|
|
52
63
|
CHAT_WINDOW_IDS,
|
|
53
64
|
ChatHostInvalidError,
|
|
54
65
|
ChatHostNotConfiguredError,
|
|
66
|
+
ChatNoDatabaseError,
|
|
55
67
|
ChatOrganizationRequiredError,
|
|
68
|
+
DEFAULT_CHAT_APP,
|
|
56
69
|
DEFAULT_CHAT_ROUTES,
|
|
57
70
|
DEFAULT_CHAT_SERVER_URL,
|
|
58
71
|
DEFAULT_CHROME_STYLES,
|
|
59
72
|
DEFAULT_WINDOW_INSTANCE_ID,
|
|
60
73
|
DIAGNOSTICS_FLUSH_DELAY_MS,
|
|
61
74
|
DIAGNOSTICS_MAX_PER_FLUSH,
|
|
75
|
+
NO_DATABASE_CODE_PREFIX,
|
|
62
76
|
SIGNED_OUT_IDENTITY,
|
|
63
77
|
UNHOSTED_CANVAS_VIEW,
|
|
64
78
|
_resetChatHostForTests,
|
|
79
|
+
attributionForSend,
|
|
65
80
|
configureChat,
|
|
66
81
|
createClient,
|
|
67
82
|
createDbCatalogGetter,
|
|
@@ -70,17 +85,23 @@ export {
|
|
|
70
85
|
createDefaultChrome,
|
|
71
86
|
createDefaultServer,
|
|
72
87
|
createDomNotifier,
|
|
88
|
+
createHostKeptPrefs,
|
|
73
89
|
createLogClientErrorDiagnostics,
|
|
90
|
+
createNoDatabaseStandIn,
|
|
74
91
|
createNoPickerOrg,
|
|
92
|
+
createStoredOrg,
|
|
75
93
|
createUnhostedCanvas,
|
|
76
94
|
createUnhostedWindows,
|
|
77
95
|
createWebPrefs,
|
|
78
96
|
createWindowNavigation,
|
|
97
|
+
currentChatApp,
|
|
79
98
|
getChatHost,
|
|
80
99
|
getClaimsUser,
|
|
81
100
|
isChatHostConfigured,
|
|
101
|
+
isChatNoDatabaseError,
|
|
82
102
|
isChatSourceApp,
|
|
83
103
|
isChatWindowId,
|
|
104
|
+
isNoDatabase,
|
|
84
105
|
resolveChatHost,
|
|
85
106
|
schedulerDb,
|
|
86
107
|
supabase
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The no-database stand-in (HOST-OWNED-SOURCE-PLAN §2.3, P28a).
|
|
3
|
+
*
|
|
4
|
+
* A host that passes a message `source` and no `db` still gets a `db` port — this stand-in. Every
|
|
5
|
+
* use of it throws `ChatNoDatabaseError` naming the feature that reached for a database, and is
|
|
6
|
+
* reported to diagnostics ONCE per feature (Law 4: a stand-in announces itself). The engine's
|
|
7
|
+
* doors branch before they reach it (G-DOOR, `scripts/check-host-source-doors.mjs`); the forcing
|
|
8
|
+
* test (`host-source-runs-a-turn.test.tsx`) mounts the real column over it and fails on any report.
|
|
9
|
+
*
|
|
10
|
+
* Pure: no React, no Redux, no `window` at import.
|
|
11
|
+
*/
|
|
12
|
+
import type { ChatDb, ChatDiagnosticsPort } from "./contract.js";
|
|
13
|
+
/** Diagnostics `code` prefix every stand-in report carries: `no-database:<feature>`. */
|
|
14
|
+
export declare const NO_DATABASE_CODE_PREFIX = "no-database:";
|
|
15
|
+
export declare class ChatNoDatabaseError extends Error {
|
|
16
|
+
readonly feature: string;
|
|
17
|
+
readonly code = "chat-no-database";
|
|
18
|
+
constructor(feature: string);
|
|
19
|
+
}
|
|
20
|
+
export declare function isChatNoDatabaseError(error: unknown): error is ChatNoDatabaseError;
|
|
21
|
+
/** True when `db` is the stand-in (the host has no database). */
|
|
22
|
+
export declare function isNoDatabase(db: unknown): boolean;
|
|
23
|
+
/**
|
|
24
|
+
* The `db` for a host with none. `report(feature)` is called once per feature, then the access
|
|
25
|
+
* throws. Reading `then` or a symbol answers `undefined`, so the stand-in is never a thenable and
|
|
26
|
+
* survives `await`, logging and React dev tooling.
|
|
27
|
+
*/
|
|
28
|
+
export declare function createNoDatabaseStandIn(report: (feature: string) => void): ChatDb;
|
|
29
|
+
/** Diagnostics for a host with no database: the console, each class said once. */
|
|
30
|
+
export declare function createConsoleDiagnostics(): ChatDiagnosticsPort;
|
|
31
|
+
/**
|
|
32
|
+
* The server client for a host with no database and no `server` port: every call refuses, named
|
|
33
|
+
* `server.<call>`, through the same once-per-feature report (the platform server needs a signed-in
|
|
34
|
+
* caller this host does not have).
|
|
35
|
+
*/
|
|
36
|
+
/** Members of the server client that never leave the page: the stream parser and state readers. */
|
|
37
|
+
export declare function isLocalServerMember(key: string): boolean;
|
|
38
|
+
export declare function createNoServerApi(report: (feature: string) => void, local?: Record<string, unknown>): unknown;
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { announceOnce } from "./errors.js";
|
|
2
|
+
const NO_DATABASE_CODE_PREFIX = "no-database:";
|
|
3
|
+
class ChatNoDatabaseError extends Error {
|
|
4
|
+
constructor(feature) {
|
|
5
|
+
super(
|
|
6
|
+
`"${feature}" needs a database, and this chat host has none (it was given a message source). The control that reached it should be absent here; pass \`db\` to the chat host to enable it.`
|
|
7
|
+
);
|
|
8
|
+
this.feature = feature;
|
|
9
|
+
this.name = "ChatNoDatabaseError";
|
|
10
|
+
}
|
|
11
|
+
feature;
|
|
12
|
+
code = "chat-no-database";
|
|
13
|
+
}
|
|
14
|
+
function isChatNoDatabaseError(error) {
|
|
15
|
+
return error instanceof ChatNoDatabaseError || typeof error === "object" && error !== null && error.code === "chat-no-database";
|
|
16
|
+
}
|
|
17
|
+
const STAND_IN = /* @__PURE__ */ Symbol.for("@ai-matrx/chat/no-database");
|
|
18
|
+
function isNoDatabase(db) {
|
|
19
|
+
return typeof db === "object" && db !== null && db[STAND_IN] === true;
|
|
20
|
+
}
|
|
21
|
+
const NAMED_CALLS = new Set("from rpc schema channel".split(" "));
|
|
22
|
+
function createNoDatabaseStandIn(report) {
|
|
23
|
+
const reported = /* @__PURE__ */ new Set();
|
|
24
|
+
const refuse = (feature) => {
|
|
25
|
+
if (!reported.has(feature)) {
|
|
26
|
+
reported.add(feature);
|
|
27
|
+
try {
|
|
28
|
+
report(feature);
|
|
29
|
+
} catch {
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
throw new ChatNoDatabaseError(feature);
|
|
33
|
+
};
|
|
34
|
+
return new Proxy({}, {
|
|
35
|
+
get(_target, key) {
|
|
36
|
+
if (key === STAND_IN) return true;
|
|
37
|
+
if (typeof key === "symbol" || key === "then" || key === "toJSON") return void 0;
|
|
38
|
+
if (NAMED_CALLS.has(key)) {
|
|
39
|
+
return (name) => refuse(`db.${key}(${typeof name === "string" ? name : "?"})`);
|
|
40
|
+
}
|
|
41
|
+
return refuse(`db.${key}`);
|
|
42
|
+
},
|
|
43
|
+
has(_target, key) {
|
|
44
|
+
return key === STAND_IN;
|
|
45
|
+
},
|
|
46
|
+
set(_target, key) {
|
|
47
|
+
return refuse(`db.${String(key)}=`);
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
function createConsoleDiagnostics() {
|
|
52
|
+
return {
|
|
53
|
+
capture(error, ctx) {
|
|
54
|
+
announceOnce(
|
|
55
|
+
`console-diagnostics:${ctx.area}:${ctx.code}`,
|
|
56
|
+
`${ctx.area}/${ctx.code}: ${error instanceof Error ? error.message : String(error)}`,
|
|
57
|
+
"error"
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
function isLocalServerMember(key) {
|
|
63
|
+
return key === "parseNdjsonStream" || /^select[A-Z]/.test(key);
|
|
64
|
+
}
|
|
65
|
+
function createNoServerApi(report, local = {}) {
|
|
66
|
+
const reported = /* @__PURE__ */ new Set();
|
|
67
|
+
const refuse = (feature) => {
|
|
68
|
+
if (!reported.has(feature)) {
|
|
69
|
+
reported.add(feature);
|
|
70
|
+
try {
|
|
71
|
+
report(feature);
|
|
72
|
+
} catch {
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
throw new ChatNoDatabaseError(feature);
|
|
76
|
+
};
|
|
77
|
+
const at = (path) => new Proxy(() => {
|
|
78
|
+
}, {
|
|
79
|
+
get(_target, key) {
|
|
80
|
+
if (typeof key === "symbol" || key === "then" || key === "toJSON") return void 0;
|
|
81
|
+
return at(`${path}.${key}`);
|
|
82
|
+
},
|
|
83
|
+
apply() {
|
|
84
|
+
return refuse(path);
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
return new Proxy(
|
|
88
|
+
{},
|
|
89
|
+
{
|
|
90
|
+
get(_target, key) {
|
|
91
|
+
if (typeof key === "symbol" || key === "then" || key === "toJSON") return void 0;
|
|
92
|
+
if (isLocalServerMember(key) && key in local) return local[key];
|
|
93
|
+
return at(`server.${key}`);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
export {
|
|
99
|
+
ChatNoDatabaseError,
|
|
100
|
+
NO_DATABASE_CODE_PREFIX,
|
|
101
|
+
createConsoleDiagnostics,
|
|
102
|
+
createNoDatabaseStandIn,
|
|
103
|
+
createNoServerApi,
|
|
104
|
+
isChatNoDatabaseError,
|
|
105
|
+
isLocalServerMember,
|
|
106
|
+
isNoDatabase
|
|
107
|
+
};
|
package/dist/host/react.d.ts
CHANGED
|
@@ -30,3 +30,4 @@ export declare function ChatProvider({ host, store, children }: ChatProviderProp
|
|
|
30
30
|
export declare function useMaybeChatHost(): ResolvedChatHost | null;
|
|
31
31
|
/** The host from the nearest <ChatProvider>. Throws the named, remedied error outside one. */
|
|
32
32
|
export declare function useChatHost(): ResolvedChatHost;
|
|
33
|
+
export { Link, usePathname, useRouter, useSearchParams } from "./navigation.js";
|
package/dist/host/react.js
CHANGED
|
@@ -8,12 +8,32 @@ import { ChatStoreContext } from "../store/context.js";
|
|
|
8
8
|
import { createChatStore } from "../store/create-chat-store.js";
|
|
9
9
|
import { useChatHostSync } from "../store/chat-host-sync.js";
|
|
10
10
|
import { setStoreSingleton } from "../store/store-singleton.js";
|
|
11
|
+
import { BareHostChrome } from "./bare-host-chrome.js";
|
|
12
|
+
import { AlchemyActionsProvider, useOptionalAlchemyActions } from "@ai-matrx/alchemy/react/host";
|
|
13
|
+
import { captureError } from "./diagnostics.js";
|
|
14
|
+
import {
|
|
15
|
+
isRemarkDurabilityRegistered,
|
|
16
|
+
registerRemarkDurability
|
|
17
|
+
} from "../agents/redux/execution-system/instance-resources/remarks.js";
|
|
18
|
+
import { createDbRemarkDurability } from "../agents/redux/execution-system/instance-resources/default-remark-durability.js";
|
|
11
19
|
const ChatHostContext = createContext(null);
|
|
12
20
|
function ChatProvider({ host, store, children }) {
|
|
13
21
|
const resolved = typeof window === "undefined" ? resolveChatHost(host) : configureChat(host);
|
|
14
22
|
const [privateStore] = useState(() => {
|
|
15
23
|
if (store) return null;
|
|
16
24
|
const created = createChatStore();
|
|
25
|
+
if (typeof window !== "undefined" && !isRemarkDurabilityRegistered()) {
|
|
26
|
+
registerRemarkDurability(
|
|
27
|
+
createDbRemarkDurability({
|
|
28
|
+
db: resolved.db,
|
|
29
|
+
dispatch: created.dispatch,
|
|
30
|
+
onFailure: (message, error) => {
|
|
31
|
+
resolved.notify.error(message);
|
|
32
|
+
console.error("[remarks] write failed:", error);
|
|
33
|
+
}
|
|
34
|
+
})
|
|
35
|
+
);
|
|
36
|
+
}
|
|
17
37
|
return { store: created, snapshot: created.getState() };
|
|
18
38
|
});
|
|
19
39
|
const chatStore = store ?? privateStore.store;
|
|
@@ -21,8 +41,21 @@ function ChatProvider({ host, store, children }) {
|
|
|
21
41
|
const serverState = privateStore?.snapshot ?? (parent && parent.store === store ? parent.getServerState?.() : void 0);
|
|
22
42
|
if (typeof window !== "undefined") setStoreSingleton(chatStore);
|
|
23
43
|
useChatHostSync(chatStore, resolved);
|
|
24
|
-
|
|
44
|
+
const outerAlchemy = useOptionalAlchemyActions();
|
|
45
|
+
const body = privateStore ? /* @__PURE__ */ jsx(BareHostChrome, { host: resolved, children }) : children;
|
|
46
|
+
return /* @__PURE__ */ jsx(ChatHostContext.Provider, { value: resolved, children: /* @__PURE__ */ jsx(Provider, { store: chatStore, context: ChatStoreContext, serverState, children: outerAlchemy ? body : /* @__PURE__ */ jsx(AlchemyActionsProvider, { ports: BARE_ALCHEMY_PORTS, children: body }) }) });
|
|
25
47
|
}
|
|
48
|
+
const BARE_ALCHEMY_PORTS = {
|
|
49
|
+
diagnostics: {
|
|
50
|
+
capture: (error, context) => {
|
|
51
|
+
captureError({
|
|
52
|
+
source: "chat",
|
|
53
|
+
message: `Alchemy ${context.area}: ${error instanceof Error ? error.message : String(error)}`,
|
|
54
|
+
raw: context.detail
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
};
|
|
26
59
|
function useMaybeChatHost() {
|
|
27
60
|
return useContext(ChatHostContext);
|
|
28
61
|
}
|
|
@@ -31,8 +64,13 @@ function useChatHost() {
|
|
|
31
64
|
if (!host) throw new ChatHostNotConfiguredError();
|
|
32
65
|
return host;
|
|
33
66
|
}
|
|
67
|
+
import { Link, usePathname, useRouter, useSearchParams } from "./navigation.js";
|
|
34
68
|
export {
|
|
35
69
|
ChatProvider,
|
|
70
|
+
Link,
|
|
36
71
|
useChatHost,
|
|
37
|
-
useMaybeChatHost
|
|
72
|
+
useMaybeChatHost,
|
|
73
|
+
usePathname,
|
|
74
|
+
useRouter,
|
|
75
|
+
useSearchParams
|
|
38
76
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createElement } from "react";
|
|
2
|
-
import { reportUnregisteredHostSlot } from "./diagnostics.js";
|
|
2
|
+
import { reportUnregisteredHostSlot, SLOT_CANNOT_RUN } from "./diagnostics.js";
|
|
3
3
|
function createRegisteredSource(sourceName, registerCall, defaults) {
|
|
4
4
|
let impl = null;
|
|
5
5
|
const label = (key) => `${sourceName}.${String(key)}`;
|
|
@@ -12,7 +12,7 @@ function createRegisteredSource(sourceName, registerCall, defaults) {
|
|
|
12
12
|
reportUnregisteredHostSlot(label(key), "its generic default runs");
|
|
13
13
|
return defaults[key];
|
|
14
14
|
}
|
|
15
|
-
reportUnregisteredHostSlot(label(key),
|
|
15
|
+
reportUnregisteredHostSlot(label(key), SLOT_CANNOT_RUN);
|
|
16
16
|
throw new Error(
|
|
17
17
|
`The host registered no "${label(key)}" for the chat package (${registerCall}).`
|
|
18
18
|
);
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @ai-matrx/chat/host/source — THE host-owned message source (HOST-OWNED-SOURCE-PLAN §2.2, P28a).
|
|
3
|
+
*
|
|
4
|
+
* A host with no database (coding sessions, desktop) still renders through the ONE real message
|
|
5
|
+
* list + composer: it hands the package history as records and live turns as platform stream
|
|
6
|
+
* events, and receives sends. It mirrors the engine's own two inputs — history arrives as
|
|
7
|
+
* records (`hydrateMessages`), live turns as events (`processStream`) — so nothing downstream
|
|
8
|
+
* learns a second shape. Capability by presence: a handler left out is a control left out.
|
|
9
|
+
*
|
|
10
|
+
* Pure: no React, no Redux, no `window` at import.
|
|
11
|
+
*/
|
|
12
|
+
import type { MessagePart, TypedStreamEvent } from "@ai-matrx/agents/generated/stream-events";
|
|
13
|
+
/** One stored message the host hands over. `content` is the platform's own `MessagePart[]`. */
|
|
14
|
+
export interface HostMessageRecord {
|
|
15
|
+
id: string;
|
|
16
|
+
role: "user" | "assistant" | "system" | "tool";
|
|
17
|
+
content: MessagePart[];
|
|
18
|
+
position: number;
|
|
19
|
+
/** ISO timestamp. */
|
|
20
|
+
createdAt: string;
|
|
21
|
+
/** Presence means the turn failed; `message` is the sentence the person reads, `code` its class. */
|
|
22
|
+
error?: {
|
|
23
|
+
message: string;
|
|
24
|
+
code?: string | null;
|
|
25
|
+
} | null;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* One finished (or still running) tool call in the host's history: what a saved `tool_call` part's
|
|
29
|
+
* card shows — its result, its failure, its display name. A database-backed conversation reads
|
|
30
|
+
* these from its tool-call rows; a host hands them over with the page.
|
|
31
|
+
*/
|
|
32
|
+
export interface HostToolCall {
|
|
33
|
+
/** The `call_id` of the `tool_call` part it belongs to. */
|
|
34
|
+
callId: string;
|
|
35
|
+
name: string;
|
|
36
|
+
/** What the card's title says ("Run a command"), when the host has a friendlier name. */
|
|
37
|
+
displayName?: string | null;
|
|
38
|
+
arguments: Record<string, unknown>;
|
|
39
|
+
/** The tool's output as text (JSON text renders structured); null while it runs. */
|
|
40
|
+
output: string | null;
|
|
41
|
+
isError: boolean;
|
|
42
|
+
status: "running" | "completed" | "failed";
|
|
43
|
+
/** The assistant message it belongs to. */
|
|
44
|
+
messageId?: string | null;
|
|
45
|
+
}
|
|
46
|
+
export interface HostHistoryPage {
|
|
47
|
+
records: HostMessageRecord[];
|
|
48
|
+
/** The tool calls the records' `tool_call` parts refer to. */
|
|
49
|
+
toolCalls?: HostToolCall[];
|
|
50
|
+
hasMoreOlder: boolean;
|
|
51
|
+
/** The host's sentence when its history could not be read ("This chat's file could not be read"). */
|
|
52
|
+
unavailable?: string | null;
|
|
53
|
+
}
|
|
54
|
+
/** A live turn: the platform NDJSON as-is, or typed events. */
|
|
55
|
+
export interface HostTurn {
|
|
56
|
+
requestId: string;
|
|
57
|
+
/** The person's message, when the HOST started the turn (another device, the CLI). */
|
|
58
|
+
user?: MessagePart[] | null;
|
|
59
|
+
events: Response | AsyncIterable<TypedStreamEvent>;
|
|
60
|
+
}
|
|
61
|
+
/** What the package gives the host for one bound conversation. */
|
|
62
|
+
export interface HostSourceSink {
|
|
63
|
+
/** A turn the host started (or a reconnect to one already running). */
|
|
64
|
+
turn(turn: HostTurn): void;
|
|
65
|
+
/** The host's history changed out of band: re-load it. */
|
|
66
|
+
history(): void;
|
|
67
|
+
/** The composer waits, with the host's sentence; null releases it. */
|
|
68
|
+
held(reason: string | null): void;
|
|
69
|
+
}
|
|
70
|
+
export interface HostSendInput {
|
|
71
|
+
conversationId: string;
|
|
72
|
+
text: string;
|
|
73
|
+
/** "send" when idle; "queue" / "steer" when a turn is running (per `whileBusy`). */
|
|
74
|
+
mode: "send" | "queue" | "steer";
|
|
75
|
+
}
|
|
76
|
+
/** The host's conversation list. Ids are always the host's — the package never mints one. */
|
|
77
|
+
export interface HostConversationSummary {
|
|
78
|
+
id: string;
|
|
79
|
+
title: string | null;
|
|
80
|
+
updatedAt: string | null;
|
|
81
|
+
}
|
|
82
|
+
export interface HostConversationList {
|
|
83
|
+
list(): Promise<HostConversationSummary[]>;
|
|
84
|
+
/** Absent ⇒ no New control. Resolves the host's id for the new conversation. */
|
|
85
|
+
start?(): Promise<string>;
|
|
86
|
+
}
|
|
87
|
+
export type HostPersistence = {
|
|
88
|
+
saved: true;
|
|
89
|
+
where: string;
|
|
90
|
+
} | {
|
|
91
|
+
saved: false;
|
|
92
|
+
reason: string;
|
|
93
|
+
};
|
|
94
|
+
export interface ChatMessageSource {
|
|
95
|
+
/** Stable id of the source ("coding-sessions"). */
|
|
96
|
+
id: string;
|
|
97
|
+
load(conversationId: string, page?: {
|
|
98
|
+
before: number | null;
|
|
99
|
+
}): Promise<HostHistoryPage>;
|
|
100
|
+
subscribe(conversationId: string, sink: HostSourceSink): () => void;
|
|
101
|
+
/** Absent ⇒ read-only. Returns the turn when it holds the stream, `void` when the turn arrives via `sink.turn`. */
|
|
102
|
+
send?(input: HostSendInput, signal: AbortSignal): Promise<HostTurn | void>;
|
|
103
|
+
stop?(conversationId: string, requestId: string | null): Promise<void>;
|
|
104
|
+
retry?(conversationId: string, messageId: string, signal: AbortSignal): Promise<HostTurn | void>;
|
|
105
|
+
answer?(conversationId: string, askId: string, value: unknown): Promise<void>;
|
|
106
|
+
conversations?: HostConversationList;
|
|
107
|
+
whileBusy: "queue" | "steer" | "refuse";
|
|
108
|
+
persistence: HostPersistence;
|
|
109
|
+
}
|
|
110
|
+
/** The host refused a send. `message` is the host's sentence; the words go back in the box. */
|
|
111
|
+
export declare class HostSendRefused extends Error {
|
|
112
|
+
readonly code = "host-send-refused";
|
|
113
|
+
constructor(message: string);
|
|
114
|
+
}
|
|
115
|
+
export declare function isHostSendRefused(error: unknown): error is HostSendRefused;
|
|
116
|
+
/** Typed events as the platform's NDJSON `Response` — the one shape `processStream` reads. */
|
|
117
|
+
export declare function eventsToResponse(events: AsyncIterable<TypedStreamEvent>): Response;
|
|
118
|
+
/** A turn's events as the NDJSON `Response` `processStream` reads. */
|
|
119
|
+
export declare function hostTurnResponse(turn: HostTurn): Response;
|
|
120
|
+
export interface HostTurnWriter {
|
|
121
|
+
turn: HostTurn;
|
|
122
|
+
push(event: TypedStreamEvent): void;
|
|
123
|
+
end(): void;
|
|
124
|
+
fail(error: unknown): void;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* A turn the host fills as its own events arrive (a socket, an IPC channel). Events pushed before
|
|
128
|
+
* the package reads are buffered in order; `end()` closes the stream, `fail()` errors it.
|
|
129
|
+
*/
|
|
130
|
+
export declare function createHostTurn(requestId: string): HostTurnWriter;
|