@ai-matrx/chat 0.4.15 → 0.4.18
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 +43 -0
- package/dist/agent-copy/AlchemySurfaceBridge.js +1 -1
- package/dist/agents/components/agent-widgets/chat-assistant/AssistantCardStack.js +1 -1
- package/dist/agents/components/ambient-assistant/ScrollAssistantLauncher.js +1 -1
- package/dist/agents/components/conversation-actions/rename/ConversationRenameDialogHost.js +1 -1
- package/dist/agents/components/messages-display/assistant/AgentEmptyMessageDisplay.js +1 -1
- package/dist/agents/components/messages-display/assistant/AssistantMessageFooter.js +3 -1
- package/dist/agents/components/messages-display/user/AgentUserMessage.js +95 -85
- package/dist/agents/components/messages-display/user/useCollapsibleMessageText.d.ts +1 -1
- package/dist/agents/components/messages-display/user/useCollapsibleMessageText.js +5 -4
- package/dist/agents/components/shared/AgentConversationColumn.d.ts +7 -1
- package/dist/agents/components/shared/AgentConversationColumn.js +14 -7
- package/dist/agents/components/shared/transcript-layout.d.ts +31 -0
- package/dist/agents/components/shared/transcript-layout.js +38 -0
- package/dist/agents/redux/execution-system/message-crud/answer-text-splice.js +1 -1
- package/dist/agents/redux/execution-system/messages/messages.selectors.js +1 -1
- package/dist/canvas/workspace/ChatPanelTitleMenu.js +8 -2
- package/dist/canvas/workspace/ShellChatDock.js +60 -10
- package/dist/canvas/workspace/shell-chat-route.d.ts +5 -4
- package/dist/canvas/workspace/shell-chat-route.js +2 -4
- package/dist/canvas/workspace/side-chat-address.d.ts +91 -0
- package/dist/canvas/workspace/side-chat-address.js +110 -0
- package/dist/canvas/workspace/useCanvasWorkspaceConversation.d.ts +31 -12
- package/dist/canvas/workspace/useCanvasWorkspaceConversation.js +105 -36
- package/dist/cx-chat/components/ChatMobileAgentName.js +1 -1
- package/dist/cx-chat/components/ChatSidebarClient.js +1 -1
- package/dist/cx-chat/components/ChatWelcomeClient.js +1 -1
- package/dist/cx-chat/components/core/ChatConversationClient.js +1 -1
- package/dist/cx-chat/components/user-input/ConversationInput.js +1 -1
- package/dist/cx-conversation/ConversationInput.js +1 -1
- package/dist/cx-conversation/MessageList.js +1 -1
- package/dist/host/db-types.d.ts +9 -12
- package/dist/host/ui-slots.js +17 -2
- package/dist/surfaces/components/chrome/SurfaceAgentsHeaderButton.d.ts +1 -1
- package/dist/surfaces/components/chrome/SurfaceAgentsHeaderButton.js +1 -1
- package/dist/tool-call-visualization/db-renderer/DbToolRenderer.js +1 -1
- package/dist/{next → ui}/lazy/AgentAssistantMessage.js +3 -4
- package/dist/{next → ui}/lazy/AgentPickerSheet.js +3 -4
- package/dist/{next → ui}/lazy/ChatVariableInputs.js +5 -7
- package/dist/{next → ui}/lazy/ConversationRenameDialogHostImpl.d.ts +1 -1
- package/dist/{next → ui}/lazy/ConversationRenameDialogHostImpl.js +3 -3
- package/dist/{next → ui}/lazy/CxAssistantMessage.js +3 -4
- package/dist/{next → ui}/lazy/DbToolRendererImpl.js +3 -3
- package/dist/{next → ui}/lazy/IconResolver.js +3 -4
- package/dist/{next → ui}/lazy/PublicChatVariableInputs.js +5 -7
- package/dist/{next → ui}/lazy/ScrollAssistantLaunchers.d.ts +1 -1
- package/dist/{next → ui}/lazy/ScrollAssistantLaunchers.js +3 -5
- package/dist/{next → ui}/lazy/SurfaceAgentsPanelImpl.js +2 -3
- package/dist/utils/client-lazy.d.ts +16 -0
- package/dist/utils/client-lazy.js +27 -0
- package/package.json +7 -7
- /package/dist/{next → ui}/lazy/AgentAssistantMessage.d.ts +0 -0
- /package/dist/{next → ui}/lazy/AgentPickerSheet.d.ts +0 -0
- /package/dist/{next → ui}/lazy/ChatVariableInputs.d.ts +0 -0
- /package/dist/{next → ui}/lazy/CxAssistantMessage.d.ts +0 -0
- /package/dist/{next → ui}/lazy/DbToolRendererImpl.d.ts +0 -0
- /package/dist/{next → ui}/lazy/IconResolver.d.ts +0 -0
- /package/dist/{next → ui}/lazy/PublicChatVariableInputs.d.ts +0 -0
- /package/dist/{next → ui}/lazy/SurfaceAgentsPanelImpl.d.ts +0 -0
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
3
3
|
import { useEffect, useEffectEvent, useRef, useState } from "react";
|
|
4
4
|
import { Maximize2, PictureInPicture2 } from "lucide-react";
|
|
5
|
-
import { usePathname } from "../../host/navigation.js";
|
|
5
|
+
import { usePathname, useSearchParams } from "../../host/navigation.js";
|
|
6
6
|
import {
|
|
7
7
|
Drawer,
|
|
8
8
|
DrawerContent,
|
|
@@ -23,6 +23,14 @@ import { CanvasChatColumn } from "./CanvasChatColumn.js";
|
|
|
23
23
|
import { ChatPanelTitleMenu, useChatPanelTitle } from "./ChatPanelTitleMenu.js";
|
|
24
24
|
import { useCanvasWorkspaceConversation } from "./useCanvasWorkspaceConversation.js";
|
|
25
25
|
import { useShellChatPageContext } from "./shell-chat-page-context.js";
|
|
26
|
+
import { useComposerMode } from "../../agents/components/inputs/smart-input/composer/useComposerMode.js";
|
|
27
|
+
import { replaceAddressWithoutNavigating } from "@ai-matrx/rich-content/utils/addressWithoutNavigating";
|
|
28
|
+
import {
|
|
29
|
+
addressAfterSideChatLink,
|
|
30
|
+
readSideChatLink,
|
|
31
|
+
sideChatOpen,
|
|
32
|
+
sideChatSignature
|
|
33
|
+
} from "./side-chat-address.js";
|
|
26
34
|
import {
|
|
27
35
|
CANVAS_CHAT_SIZES,
|
|
28
36
|
CANVAS_PANEL_IDS,
|
|
@@ -77,6 +85,8 @@ function useCanvasFullScreenActive() {
|
|
|
77
85
|
}
|
|
78
86
|
function ShellChatDock({ initialChat, initialWidth, initialMode = null, signedIn, initialPathname }) {
|
|
79
87
|
const pathname = usePathname() ?? initialPathname;
|
|
88
|
+
const searchParams = useSearchParams();
|
|
89
|
+
const linkSignature = sideChatSignature((name) => searchParams?.get(name) ?? null);
|
|
80
90
|
const home = shellChatHome(pathname, signedIn);
|
|
81
91
|
const hostedElsewhere = shellChatHostedElsewhere(pathname);
|
|
82
92
|
const viewportCompact = useMediaQueryState(COMPACT_QUERY);
|
|
@@ -88,6 +98,9 @@ function ShellChatDock({ initialChat, initialWidth, initialMode = null, signedIn
|
|
|
88
98
|
});
|
|
89
99
|
const [wideDefault, setWideDefault] = useState(false);
|
|
90
100
|
const [sheetOpen, setSheetOpen] = useState(false);
|
|
101
|
+
const [visit, setVisit] = useState(null);
|
|
102
|
+
const ownWrite = useRef(null);
|
|
103
|
+
const { setMode } = useComposerMode(initialMode, { enabled: signedIn });
|
|
91
104
|
if (choice.layoutId !== home.layoutId) {
|
|
92
105
|
setChoice({
|
|
93
106
|
layoutId: home.layoutId,
|
|
@@ -97,21 +110,57 @@ function ShellChatDock({ initialChat, initialWidth, initialMode = null, signedIn
|
|
|
97
110
|
useEffect(() => {
|
|
98
111
|
setWideDefault(window.matchMedia(SHELL_CHAT_WIDE_QUERY).matches);
|
|
99
112
|
}, []);
|
|
113
|
+
const visitHere = visit && visit.pathname === pathname && visit.surfaceKey === home.surfaceKey ? visit : null;
|
|
114
|
+
const link = visitHere?.link ?? null;
|
|
115
|
+
const standsAside = hostedElsewhere && !link;
|
|
100
116
|
const placement = choice.state?.placement ?? "side";
|
|
101
|
-
const open =
|
|
117
|
+
const open = sideChatOpen({
|
|
118
|
+
hostedElsewhere,
|
|
119
|
+
link,
|
|
120
|
+
personActed: visitHere?.acted ?? false,
|
|
121
|
+
remembered: choice.state?.open ?? home.defaultOpen ?? wideDefault
|
|
122
|
+
});
|
|
102
123
|
const shown = open && !fullScreen;
|
|
103
124
|
const docked = shown && placement === "side";
|
|
104
125
|
const floating = !compact && shown && placement === "floating";
|
|
105
|
-
const chatOnScreen = !
|
|
126
|
+
const chatOnScreen = !standsAside && (compact ? sheetOpen : viewportCompact === false && shown);
|
|
127
|
+
const readLink = useEffectEvent(() => {
|
|
128
|
+
const search = window.location.search;
|
|
129
|
+
if (visitHere && ownWrite.current === search) return;
|
|
130
|
+
const read = readSideChatLink(search);
|
|
131
|
+
setVisit({ pathname, surfaceKey: home.surfaceKey, link: read, acted: false });
|
|
132
|
+
if (!linkSignature) return;
|
|
133
|
+
const consumed = addressAfterSideChatLink(search, read, { hostedElsewhere });
|
|
134
|
+
ownWrite.current = consumed;
|
|
135
|
+
if (consumed !== search) {
|
|
136
|
+
replaceAddressWithoutNavigating(`${window.location.pathname}${consumed}${window.location.hash}`);
|
|
137
|
+
}
|
|
138
|
+
if (!read) return;
|
|
139
|
+
const opens = read.open ?? (hostedElsewhere ? true : null);
|
|
140
|
+
if (opens !== null) setSheetOpen(opens);
|
|
141
|
+
if (opens) window.dispatchEvent(new Event(SHELL_CHAT_REVEAL_EVENT));
|
|
142
|
+
if (read.mode) setMode(read.mode);
|
|
143
|
+
});
|
|
144
|
+
useEffect(() => {
|
|
145
|
+
if (signedIn) readLink();
|
|
146
|
+
}, [signedIn, pathname, home.surfaceKey, linkSignature]);
|
|
106
147
|
const chat = useCanvasWorkspaceConversation(home.surfaceKey, {
|
|
107
148
|
enabled: signedIn && chatOnScreen,
|
|
108
|
-
|
|
149
|
+
address: {
|
|
150
|
+
link: visitHere ? visitHere.link : void 0,
|
|
151
|
+
open: compact ? sheetOpen : open,
|
|
152
|
+
hostedElsewhere,
|
|
153
|
+
onWrite: (search) => {
|
|
154
|
+
ownWrite.current = search;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
109
157
|
});
|
|
110
158
|
const conversationId = chat.conversationId;
|
|
111
159
|
const chatTitle = useChatPanelTitle(conversationId);
|
|
112
160
|
const pageContext = useShellChatPageContext();
|
|
113
161
|
const floatingSize = readFloatingSize(useSessionKnob(COMPOSER_KNOBS.floatingPanelSize));
|
|
114
162
|
const setChat = (next) => {
|
|
163
|
+
setVisit((current) => current && !current.acted ? { ...current, acted: true } : current);
|
|
115
164
|
setChoice({ layoutId: home.layoutId, state: next });
|
|
116
165
|
writeCanvasChatCookie(home.layoutId, next);
|
|
117
166
|
};
|
|
@@ -132,14 +181,14 @@ function ShellChatDock({ initialChat, initialWidth, initialMode = null, signedIn
|
|
|
132
181
|
const root = document.querySelector(".shell-root");
|
|
133
182
|
if (!root || !signedIn) return void 0;
|
|
134
183
|
root.toggleAttribute("data-shell-chat-open", docked && wideKnown);
|
|
135
|
-
root.toggleAttribute("data-shell-chat-available", !
|
|
184
|
+
root.toggleAttribute("data-shell-chat-available", !standsAside);
|
|
136
185
|
return () => {
|
|
137
186
|
root.removeAttribute("data-shell-chat-open");
|
|
138
187
|
root.removeAttribute("data-shell-chat-available");
|
|
139
188
|
};
|
|
140
|
-
}, [docked, wideKnown,
|
|
189
|
+
}, [docked, wideKnown, standsAside, signedIn]);
|
|
141
190
|
useEffect(() => {
|
|
142
|
-
if (!signedIn || !wideKnown ||
|
|
191
|
+
if (!signedIn || !wideKnown || standsAside) return;
|
|
143
192
|
const root = document.querySelector(".shell-root");
|
|
144
193
|
const sidebarToggle = document.getElementById("shell-sidebar-toggle");
|
|
145
194
|
if (!root?.hasAttribute("data-domain-panel") || !sidebarToggle) return;
|
|
@@ -155,17 +204,18 @@ function ShellChatDock({ initialChat, initialWidth, initialMode = null, signedIn
|
|
|
155
204
|
const want = saved?.split("=")[1] !== "0";
|
|
156
205
|
if (sidebarToggle.checked !== want) sidebarToggle.checked = want;
|
|
157
206
|
}
|
|
158
|
-
}, [docked, choice.state, wideKnown,
|
|
207
|
+
}, [docked, choice.state, wideKnown, standsAside, signedIn, home.layoutId]);
|
|
159
208
|
const onToggle = useEffectEvent(() => {
|
|
160
|
-
if (!
|
|
209
|
+
if (!standsAside) toggle();
|
|
161
210
|
});
|
|
211
|
+
const takesToggle = useEffectEvent(() => !standsAside);
|
|
162
212
|
useEffect(() => {
|
|
163
213
|
const onEvent = () => onToggle();
|
|
164
214
|
const onKey = (e) => {
|
|
165
215
|
if (!signedIn || !shellChatTakesToggleKey(e)) return;
|
|
166
216
|
const inChat = e.target instanceof Element && e.target.closest(".shell-chat-dock, .shell-chat-floating");
|
|
167
217
|
if (isTypingTarget(e.target) && !inChat) return;
|
|
168
|
-
if (
|
|
218
|
+
if (!takesToggle()) return;
|
|
169
219
|
e.preventDefault();
|
|
170
220
|
onToggle();
|
|
171
221
|
};
|
|
@@ -30,7 +30,8 @@ export declare function shellChatWorkspaceId(family: string): string;
|
|
|
30
30
|
* The only pages the shell's chat stands aside on: the full chat itself and
|
|
31
31
|
* the code workspace (it docks its own coding agent). Every other page —
|
|
32
32
|
* the Board and Education included — shows THE chat (owner, 2026-10-05: one
|
|
33
|
-
* chat, on every page).
|
|
33
|
+
* chat, on every page). A side_chat* link brings it in here too
|
|
34
|
+
* (side-chat-address.ts `sideChatOpen`, owner 2026-10-07).
|
|
34
35
|
*/
|
|
35
36
|
export declare function shellChatHostedElsewhere(pathname: string): boolean;
|
|
36
37
|
/**
|
|
@@ -46,14 +47,14 @@ export declare function shellChatPageSurfaceKey(pathname: string): string;
|
|
|
46
47
|
* - `layoutId` — its remembered open / closed + docked / floating
|
|
47
48
|
* (`canvasChatCookieName(layoutId)`);
|
|
48
49
|
* - `surfaceKey` — the conversation it shows (and this device's memory of it);
|
|
49
|
-
*
|
|
50
|
+
* the address names it as `?side_chat=` on every home
|
|
51
|
+
* (side-chat-address.ts);
|
|
50
52
|
* - `defaultOpen` — open with no remembered choice; null = open on a wide
|
|
51
53
|
* screen only (SHELL_CHAT_WIDE_QUERY).
|
|
52
54
|
*/
|
|
53
55
|
export interface ShellChatHome {
|
|
54
56
|
layoutId: string;
|
|
55
57
|
surfaceKey: string;
|
|
56
|
-
addressParam: string;
|
|
57
58
|
defaultOpen: boolean | null;
|
|
58
59
|
}
|
|
59
60
|
/**
|
|
@@ -64,7 +65,7 @@ export interface ShellChatHome {
|
|
|
64
65
|
export declare const SHELL_CHAT_CLOSED_BY_DEFAULT_PAGES: readonly RegExp[];
|
|
65
66
|
/**
|
|
66
67
|
* A page with a chat of its OWN keeps it inside the shell chat: each board
|
|
67
|
-
* has its conversation, signed-in Education has one. The ids
|
|
68
|
+
* has its conversation, signed-in Education has one. The ids and
|
|
68
69
|
* defaults are exactly the ones those pages used when they drew their own chat
|
|
69
70
|
* column (ChatCanvasWorkspace, until 2026-10-05), so a person's remembered
|
|
70
71
|
* layout and conversation carry over untouched. Every other page remembers its
|
|
@@ -31,16 +31,14 @@ function shellChatHome(pathname, signedIn) {
|
|
|
31
31
|
const board = BOARD_PAGE.exec(pathname);
|
|
32
32
|
if (board) {
|
|
33
33
|
const layoutId = `board-${board[1]}`;
|
|
34
|
-
return { layoutId, surfaceKey: `canvas-workspace:${layoutId}`,
|
|
34
|
+
return { layoutId, surfaceKey: `canvas-workspace:${layoutId}`, defaultOpen: true };
|
|
35
35
|
}
|
|
36
36
|
if (signedIn && EDUCATION_PAGES.test(pathname)) {
|
|
37
|
-
return { layoutId: "education", surfaceKey: "canvas-workspace:education",
|
|
37
|
+
return { layoutId: "education", surfaceKey: "canvas-workspace:education", defaultOpen: false };
|
|
38
38
|
}
|
|
39
39
|
return {
|
|
40
40
|
layoutId: shellChatWorkspaceId(shellChatFamily(pathname)),
|
|
41
41
|
surfaceKey: shellChatPageSurfaceKey(pathname),
|
|
42
|
-
// `pageChat`, not `chat`: /code keeps its own `?chat=`.
|
|
43
|
-
addressParam: "pageChat",
|
|
44
42
|
defaultOpen: SHELL_CHAT_CLOSED_BY_DEFAULT_PAGES.some((p) => p.test(pathname)) ? false : null
|
|
45
43
|
};
|
|
46
44
|
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* THE SIDE CHAT'S LINK CONTRACT (owner, 2026-10-07) — the ONE param family that
|
|
3
|
+
* opens, closes and aims the chat beside every page, on every home (an ordinary
|
|
4
|
+
* page, a board, Education — and /chat and /code, where the Side Chat is absent
|
|
5
|
+
* unless a link asks for it).
|
|
6
|
+
*
|
|
7
|
+
* side_chat open | closed | new | <conversation uuid>
|
|
8
|
+
* side_chat_agent <agent uuid> | mandate:<key> (the agent picker's ref shape)
|
|
9
|
+
* side_chat_mode chat | work | advanced (the composer's mode)
|
|
10
|
+
*
|
|
11
|
+
* The link WINS over the remembered state (the per-page conversation, the family
|
|
12
|
+
* cookie, the defaults) for that visit; it never writes the person's open / closed
|
|
13
|
+
* choice — only the person's own act does. Once read, the address keeps naming
|
|
14
|
+
* what the panel shows: `side_chat=<uuid>` for a conversation the server has,
|
|
15
|
+
* `side_chat=open` / `closed` otherwise; `side_chat_agent` / `side_chat_mode` and
|
|
16
|
+
* `side_chat=new` are consumed so a reload never starts yet another new chat.
|
|
17
|
+
*
|
|
18
|
+
* Plain module, no React: the dock, the conversation hook and the tests share it.
|
|
19
|
+
* A value it cannot use is IGNORED with a console warning naming it — never silently.
|
|
20
|
+
*/
|
|
21
|
+
import { type AnyMandateKey } from "@ai-matrx/agents/mandates";
|
|
22
|
+
import { type ComposerMode } from "../../agents/components/inputs/smart-input/composer/composer-types.js";
|
|
23
|
+
export declare const SIDE_CHAT_PARAM = "side_chat";
|
|
24
|
+
export declare const SIDE_CHAT_AGENT_PARAM = "side_chat_agent";
|
|
25
|
+
export declare const SIDE_CHAT_MODE_PARAM = "side_chat_mode";
|
|
26
|
+
export declare const SIDE_CHAT_PARAMS: readonly ["side_chat", "side_chat_agent", "side_chat_mode"];
|
|
27
|
+
/** What a link asks the Side Chat's conversation to be. */
|
|
28
|
+
export type SideChatLinkConversation = {
|
|
29
|
+
kind: "new";
|
|
30
|
+
} | {
|
|
31
|
+
kind: "open";
|
|
32
|
+
conversationId: string;
|
|
33
|
+
} | {
|
|
34
|
+
kind: "agent";
|
|
35
|
+
agentId: string;
|
|
36
|
+
} | {
|
|
37
|
+
kind: "mandate";
|
|
38
|
+
mandateKey: AnyMandateKey;
|
|
39
|
+
agentRef: string;
|
|
40
|
+
};
|
|
41
|
+
export interface SideChatLink {
|
|
42
|
+
/** true / false = the link sets the panel; null = it says nothing about it. */
|
|
43
|
+
open: boolean | null;
|
|
44
|
+
conversation: SideChatLinkConversation | null;
|
|
45
|
+
mode: ComposerMode | null;
|
|
46
|
+
}
|
|
47
|
+
export type SideChatWarn = (message: string) => void;
|
|
48
|
+
/**
|
|
49
|
+
* The Side Chat link in `search`, or null when it carries no usable side_chat*
|
|
50
|
+
* instruction (absent, or every value invalid — each invalid one is warned).
|
|
51
|
+
*/
|
|
52
|
+
export declare function readSideChatLink(search: string, warn?: SideChatWarn): SideChatLink | null;
|
|
53
|
+
/**
|
|
54
|
+
* Whether the Side Chat is open. The link wins for its visit until the person
|
|
55
|
+
* acts; then their remembered choice does again. On a page that hosts its own
|
|
56
|
+
* chat (/chat, /code) the Side Chat is absent unless a link summoned it, and a
|
|
57
|
+
* link that names no open / closed (only a mode) still brings it in.
|
|
58
|
+
*/
|
|
59
|
+
export declare function sideChatOpen({ hostedElsewhere, link, personActed, remembered, }: {
|
|
60
|
+
hostedElsewhere: boolean;
|
|
61
|
+
/** This visit's link; null = none. */
|
|
62
|
+
link: SideChatLink | null;
|
|
63
|
+
/** The person opened / closed / docked the chat since the link was read. */
|
|
64
|
+
personActed: boolean;
|
|
65
|
+
/** The remembered choice, else the home's default. */
|
|
66
|
+
remembered: boolean;
|
|
67
|
+
}): boolean;
|
|
68
|
+
/**
|
|
69
|
+
* The address right after a link is read: `side_chat_agent`, `side_chat_mode`,
|
|
70
|
+
* `side_chat=new` and any invalid side_chat* value are consumed, and `side_chat`
|
|
71
|
+
* says what the panel now is (`open` / `closed`, or the conversation id it was
|
|
72
|
+
* asked to open). Everything else in the address is untouched.
|
|
73
|
+
*/
|
|
74
|
+
export declare function addressAfterSideChatLink(search: string, link: SideChatLink | null, { hostedElsewhere }: {
|
|
75
|
+
hostedElsewhere: boolean;
|
|
76
|
+
}): string;
|
|
77
|
+
/**
|
|
78
|
+
* The address while the Side Chat shows a conversation: open on a conversation
|
|
79
|
+
* the server has → `side_chat=<uuid>` (a copied link reproduces it); open on an
|
|
80
|
+
* unsent chat → `side_chat=open` where it already said so or where the page
|
|
81
|
+
* hosts its own chat (else nothing, as before); closed → no conversation in the
|
|
82
|
+
* address (a `side_chat=closed` the link set stays). The one-shot params never
|
|
83
|
+
* survive.
|
|
84
|
+
*/
|
|
85
|
+
export declare function sideChatAddress(search: string, { conversationId, open, hostedElsewhere }: {
|
|
86
|
+
conversationId: string | null;
|
|
87
|
+
open: boolean;
|
|
88
|
+
hostedElsewhere: boolean;
|
|
89
|
+
}): string;
|
|
90
|
+
/** The side_chat* values of `search`, as one comparable string ("" when none). */
|
|
91
|
+
export declare function sideChatSignature(get: (name: string) => string | null): string;
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { isUuidShape } from "@ai-matrx/kit/uuid";
|
|
2
|
+
import { isMandateAgentId, mandateAgentId } from "@ai-matrx/agents/catalog";
|
|
3
|
+
import { storedMandateKey } from "@ai-matrx/agents/mandates";
|
|
4
|
+
import { isComposerMode } from "../../agents/components/inputs/smart-input/composer/composer-types.js";
|
|
5
|
+
const SIDE_CHAT_PARAM = "side_chat";
|
|
6
|
+
const SIDE_CHAT_AGENT_PARAM = "side_chat_agent";
|
|
7
|
+
const SIDE_CHAT_MODE_PARAM = "side_chat_mode";
|
|
8
|
+
const SIDE_CHAT_PARAMS = [SIDE_CHAT_PARAM, SIDE_CHAT_AGENT_PARAM, SIDE_CHAT_MODE_PARAM];
|
|
9
|
+
const defaultWarn = (message) => console.warn(`[side-chat] ${message}`);
|
|
10
|
+
const MANDATE_KEY_SHAPE = /^[a-z0-9][a-z0-9_.:-]*$/i;
|
|
11
|
+
function readAgent(value, warn) {
|
|
12
|
+
if (isUuidShape(value)) return { kind: "agent", agentId: value };
|
|
13
|
+
if (isMandateAgentId(value)) {
|
|
14
|
+
const key = value.slice("mandate:".length);
|
|
15
|
+
if (MANDATE_KEY_SHAPE.test(key)) {
|
|
16
|
+
return { kind: "mandate", mandateKey: storedMandateKey(key), agentRef: mandateAgentId(key) };
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
warn(`ignored ${SIDE_CHAT_AGENT_PARAM}="${value}": expected an agent id or mandate:<key>`);
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
function readSideChatLink(search, warn = defaultWarn) {
|
|
23
|
+
const params = new URLSearchParams(search);
|
|
24
|
+
const rawChat = params.get(SIDE_CHAT_PARAM);
|
|
25
|
+
const rawAgent = params.get(SIDE_CHAT_AGENT_PARAM);
|
|
26
|
+
const rawMode = params.get(SIDE_CHAT_MODE_PARAM);
|
|
27
|
+
if (rawChat === null && rawAgent === null && rawMode === null) return null;
|
|
28
|
+
let open = null;
|
|
29
|
+
let conversation = null;
|
|
30
|
+
if (rawChat !== null) {
|
|
31
|
+
if (rawChat === "open") open = true;
|
|
32
|
+
else if (rawChat === "closed") open = false;
|
|
33
|
+
else if (rawChat === "new") {
|
|
34
|
+
open = true;
|
|
35
|
+
conversation = { kind: "new" };
|
|
36
|
+
} else if (isUuidShape(rawChat)) {
|
|
37
|
+
open = true;
|
|
38
|
+
conversation = { kind: "open", conversationId: rawChat };
|
|
39
|
+
} else {
|
|
40
|
+
warn(`ignored ${SIDE_CHAT_PARAM}="${rawChat}": expected open, closed, new or a conversation id`);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
if (rawAgent !== null) {
|
|
44
|
+
const agent = readAgent(rawAgent, warn);
|
|
45
|
+
if (agent) {
|
|
46
|
+
if (conversation?.kind === "open") {
|
|
47
|
+
warn(`${SIDE_CHAT_AGENT_PARAM} wins over ${SIDE_CHAT_PARAM}=${conversation.conversationId}: a new chat with that agent opens`);
|
|
48
|
+
}
|
|
49
|
+
if (open === false) warn(`${SIDE_CHAT_AGENT_PARAM} wins over ${SIDE_CHAT_PARAM}=closed: the chat opens`);
|
|
50
|
+
conversation = agent;
|
|
51
|
+
open = true;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
let mode = null;
|
|
55
|
+
if (rawMode !== null) {
|
|
56
|
+
if (isComposerMode(rawMode)) mode = rawMode;
|
|
57
|
+
else warn(`ignored ${SIDE_CHAT_MODE_PARAM}="${rawMode}": expected chat, work or advanced`);
|
|
58
|
+
}
|
|
59
|
+
if (open === null && conversation === null && mode === null) return null;
|
|
60
|
+
return { open, conversation, mode };
|
|
61
|
+
}
|
|
62
|
+
function sideChatOpen({
|
|
63
|
+
hostedElsewhere,
|
|
64
|
+
link,
|
|
65
|
+
personActed,
|
|
66
|
+
remembered
|
|
67
|
+
}) {
|
|
68
|
+
if (hostedElsewhere && !link) return false;
|
|
69
|
+
if (link && !personActed) return link.open ?? (hostedElsewhere ? true : remembered);
|
|
70
|
+
return remembered;
|
|
71
|
+
}
|
|
72
|
+
function addressAfterSideChatLink(search, link, { hostedElsewhere }) {
|
|
73
|
+
const params = new URLSearchParams(search);
|
|
74
|
+
for (const name of SIDE_CHAT_PARAMS) params.delete(name);
|
|
75
|
+
const open = link ? link.open ?? (hostedElsewhere ? true : null) : null;
|
|
76
|
+
if (open !== null) {
|
|
77
|
+
const named = link?.conversation?.kind === "open" ? link.conversation.conversationId : null;
|
|
78
|
+
params.set(SIDE_CHAT_PARAM, open ? named ?? "open" : "closed");
|
|
79
|
+
}
|
|
80
|
+
const qs = params.toString();
|
|
81
|
+
return qs ? `?${qs}` : "";
|
|
82
|
+
}
|
|
83
|
+
function sideChatAddress(search, { conversationId, open, hostedElsewhere }) {
|
|
84
|
+
const params = new URLSearchParams(search);
|
|
85
|
+
const current = params.get(SIDE_CHAT_PARAM);
|
|
86
|
+
params.delete(SIDE_CHAT_AGENT_PARAM);
|
|
87
|
+
params.delete(SIDE_CHAT_MODE_PARAM);
|
|
88
|
+
if (open && conversationId) params.set(SIDE_CHAT_PARAM, conversationId);
|
|
89
|
+
else if (open) {
|
|
90
|
+
if (current === "open" || hostedElsewhere) params.set(SIDE_CHAT_PARAM, "open");
|
|
91
|
+
else params.delete(SIDE_CHAT_PARAM);
|
|
92
|
+
} else if (current !== "closed") params.delete(SIDE_CHAT_PARAM);
|
|
93
|
+
const qs = params.toString();
|
|
94
|
+
return qs ? `?${qs}` : "";
|
|
95
|
+
}
|
|
96
|
+
function sideChatSignature(get) {
|
|
97
|
+
const parts = SIDE_CHAT_PARAMS.map((name) => get(name));
|
|
98
|
+
return parts.every((p) => p === null) ? "" : parts.map((p) => p ?? "").join("|");
|
|
99
|
+
}
|
|
100
|
+
export {
|
|
101
|
+
SIDE_CHAT_AGENT_PARAM,
|
|
102
|
+
SIDE_CHAT_MODE_PARAM,
|
|
103
|
+
SIDE_CHAT_PARAM,
|
|
104
|
+
SIDE_CHAT_PARAMS,
|
|
105
|
+
addressAfterSideChatLink,
|
|
106
|
+
readSideChatLink,
|
|
107
|
+
sideChatAddress,
|
|
108
|
+
sideChatOpen,
|
|
109
|
+
sideChatSignature
|
|
110
|
+
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type SideChatLink } from "./side-chat-address.js";
|
|
1
2
|
import type { AnyMandateKey } from "@ai-matrx/agents/mandates";
|
|
2
3
|
export type CanvasWorkspaceConversation = {
|
|
3
4
|
state: "opening";
|
|
@@ -39,18 +40,28 @@ export type CanvasWorkspaceConversationOptions = {
|
|
|
39
40
|
*/
|
|
40
41
|
surfaceName?: null;
|
|
41
42
|
/**
|
|
42
|
-
*
|
|
43
|
-
* returns the person to it the way `/chat/<id>`
|
|
44
|
-
*
|
|
45
|
-
* conversation
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
43
|
+
* THE SIDE CHAT'S ADDRESS (side-chat-address.ts): the conversation lives at
|
|
44
|
+
* `?side_chat=<id>`, so a reload returns the person to it the way `/chat/<id>`
|
|
45
|
+
* does. The link is read once per home (it wins over the remembered
|
|
46
|
+
* conversation and the default new chat); a later link on the same home is
|
|
47
|
+
* applied when it arrives. The address names the conversation once the server
|
|
48
|
+
* has it and while the panel is open. With no link, the conversation this
|
|
49
|
+
* chat last showed on this device opens instead (`recallWorkspaceConversation`).
|
|
50
|
+
* Omitted = neither the address nor the memory is touched (board chat TILES:
|
|
51
|
+
* many conversations, one page).
|
|
49
52
|
*/
|
|
50
|
-
|
|
53
|
+
address?: SideChatAddressOptions;
|
|
51
54
|
};
|
|
52
|
-
|
|
53
|
-
|
|
55
|
+
export interface SideChatAddressOptions {
|
|
56
|
+
/** This visit's link: undefined = not read yet (nothing launches), null = none. */
|
|
57
|
+
link: SideChatLink | null | undefined;
|
|
58
|
+
/** The panel is open — the address names the conversation only while it is. */
|
|
59
|
+
open: boolean;
|
|
60
|
+
/** The page hosts its own chat (/chat, /code): an unsent chat keeps `side_chat=open`. */
|
|
61
|
+
hostedElsewhere: boolean;
|
|
62
|
+
/** Told every address this hook writes, so the reader never re-reads its own write as a link. */
|
|
63
|
+
onWrite?: (search: string) => void;
|
|
64
|
+
}
|
|
54
65
|
/**
|
|
55
66
|
* THIS CHAT'S LAST CONVERSATION, remembered on this device (2026-10-05).
|
|
56
67
|
* `?<param>=` alone was not enough: any address without it — the board opened
|
|
@@ -74,8 +85,16 @@ export declare function rememberWorkspaceConversation(surfaceKey: string, conver
|
|
|
74
85
|
export declare function reservedChatKey(surfaceKey: string): string;
|
|
75
86
|
export declare function reserveWorkspaceConversationId(surfaceKey: string, fresh: boolean): string | undefined;
|
|
76
87
|
export declare function releaseWorkspaceConversationId(surfaceKey: string): void;
|
|
77
|
-
/**
|
|
78
|
-
|
|
88
|
+
/**
|
|
89
|
+
* The server refused a new chat's id because it is already TAKEN (409
|
|
90
|
+
* `conversation_already_exists`, run-ai-stream): a reserved id another tab
|
|
91
|
+
* already sent with, or one kept past a send. Retrying the same id can never
|
|
92
|
+
* succeed.
|
|
93
|
+
*/
|
|
94
|
+
export declare function isConversationIdTaken(error: {
|
|
95
|
+
message?: unknown;
|
|
96
|
+
error_type?: unknown;
|
|
97
|
+
} | undefined): boolean;
|
|
79
98
|
export interface CanvasWorkspaceConversationController {
|
|
80
99
|
conversation: CanvasWorkspaceConversation;
|
|
81
100
|
/** The id when ready, else null. */
|