@adminide-stack/clock-tik-browser 12.0.35-alpha.0 → 12.0.36-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/pages/Home/__tests__/connectors.test.d.ts +2 -0
- package/lib/pages/Home/__tests__/connectors.test.d.ts.map +1 -0
- package/lib/pages/Home/__tests__/history.test.d.ts +2 -0
- package/lib/pages/Home/__tests__/history.test.d.ts.map +1 -0
- package/lib/pages/Home/__tests__/queue.test.d.ts +2 -0
- package/lib/pages/Home/__tests__/queue.test.d.ts.map +1 -0
- package/lib/pages/Home/__tests__/results.test.d.ts +2 -0
- package/lib/pages/Home/__tests__/results.test.d.ts.map +1 -0
- package/lib/pages/Home/chat/ChoresChat.d.ts.map +1 -1
- package/lib/pages/Home/chat/ChoresChat.js +409 -88
- package/lib/pages/Home/chat/ChoresChat.js.map +1 -1
- package/lib/pages/Home/chat/ChoresPanel.d.ts +10 -1
- package/lib/pages/Home/chat/ChoresPanel.d.ts.map +1 -1
- package/lib/pages/Home/chat/ChoresPanel.js +27 -18
- package/lib/pages/Home/chat/ChoresPanel.js.map +1 -1
- package/lib/pages/Home/chat/ConnectorsPanel.d.ts +23 -0
- package/lib/pages/Home/chat/ConnectorsPanel.d.ts.map +1 -0
- package/lib/pages/Home/chat/ConnectorsPanel.js +132 -0
- package/lib/pages/Home/chat/ConnectorsPanel.js.map +1 -0
- package/lib/pages/Home/chat/HistoryPanel.d.ts +27 -0
- package/lib/pages/Home/chat/HistoryPanel.d.ts.map +1 -0
- package/lib/pages/Home/chat/HistoryPanel.js +234 -0
- package/lib/pages/Home/chat/HistoryPanel.js.map +1 -0
- package/lib/pages/Home/chat/ResultCards.d.ts +16 -0
- package/lib/pages/Home/chat/ResultCards.d.ts.map +1 -0
- package/lib/pages/Home/chat/ResultCards.js +509 -0
- package/lib/pages/Home/chat/ResultCards.js.map +1 -0
- package/lib/pages/Home/chat/chatTheme.d.ts.map +1 -1
- package/lib/pages/Home/chat/chatTheme.js +685 -8
- package/lib/pages/Home/chat/chatTheme.js.map +1 -1
- package/lib/pages/Home/chat/chores.d.ts +10 -3
- package/lib/pages/Home/chat/chores.d.ts.map +1 -1
- package/lib/pages/Home/chat/chores.js +22 -5
- package/lib/pages/Home/chat/chores.js.map +1 -1
- package/lib/pages/Home/chat/connectors.d.ts +37 -0
- package/lib/pages/Home/chat/connectors.d.ts.map +1 -0
- package/lib/pages/Home/chat/connectors.js +73 -0
- package/lib/pages/Home/chat/connectors.js.map +1 -0
- package/lib/pages/Home/chat/history.d.ts +51 -0
- package/lib/pages/Home/chat/history.d.ts.map +1 -0
- package/lib/pages/Home/chat/history.js +186 -0
- package/lib/pages/Home/chat/history.js.map +1 -0
- package/lib/pages/Home/chat/lucy.d.ts.map +1 -1
- package/lib/pages/Home/chat/lucy.js +1 -1
- package/lib/pages/Home/chat/lucy.js.map +1 -1
- package/lib/pages/Home/chat/queue.d.ts +94 -0
- package/lib/pages/Home/chat/queue.d.ts.map +1 -0
- package/lib/pages/Home/chat/queue.js +88 -0
- package/lib/pages/Home/chat/queue.js.map +1 -0
- package/lib/pages/Home/chat/results.d.ts +207 -0
- package/lib/pages/Home/chat/results.d.ts.map +1 -0
- package/lib/pages/Home/chat/results.js +823 -0
- package/lib/pages/Home/chat/results.js.map +1 -0
- package/lib/pages/Home/chat/stop.d.ts +7 -6
- package/lib/pages/Home/chat/stop.d.ts.map +1 -1
- package/lib/pages/Home/chat/stop.js +7 -6
- package/lib/pages/Home/chat/stop.js.map +1 -1
- package/lib/pages/Home/chat/thread.d.ts +9 -3
- package/lib/pages/Home/chat/thread.d.ts.map +1 -1
- package/lib/pages/Home/chat/thread.js +14 -5
- package/lib/pages/Home/chat/thread.js.map +1 -1
- package/lib/pages/Home/chat/tour/tourSteps.d.ts +4 -3
- package/lib/pages/Home/chat/tour/tourSteps.d.ts.map +1 -1
- package/lib/pages/Home/chat/tour/tourSteps.js +23 -3
- package/lib/pages/Home/chat/tour/tourSteps.js.map +1 -1
- package/lib/pages/Home/chat/useChores.d.ts +5 -0
- package/lib/pages/Home/chat/useChores.d.ts.map +1 -1
- package/lib/pages/Home/chat/useChores.js +4 -1
- package/lib/pages/Home/chat/useChores.js.map +1 -1
- package/package.json +3 -3
|
@@ -1,10 +1,14 @@
|
|
|
1
|
-
import {jsx,jsxs,Fragment}from'react/jsx-runtime';import {useMemo,useState,useRef,useCallback,useEffect}from'react';import {RefreshCcw,CircleHelp,ArrowLeft,SquarePen,LogOut,CalendarClock,PhoneCall,Receipt,BellRing,ArrowRight}from'lucide-react';import {openAgentSession,postAgentChatStream,isSessionBusyError,cancelAgentTurn}from'@yantra/surface-kit/agent-chat';import {getCdecliToken,clearCdecliToken}from'@yantra/surface-kit/auth';import {ASK_USER_SYSTEM_PROMPT,AgentChat,humanizeToolLine,parseAskUser}from'@yantra/surface-kit/chat';import {
|
|
1
|
+
import {jsx,jsxs,Fragment}from'react/jsx-runtime';import {useMemo,useState,useRef,useCallback,useEffect}from'react';import {RefreshCcw,CircleHelp,ArrowLeft,SquarePen,Plug,LogOut,CalendarClock,PhoneCall,Receipt,BellRing,ArrowRight}from'lucide-react';import {openAgentSession,postAgentChatStream,isSessionBusyError,cancelAgentTurn}from'@yantra/surface-kit/agent-chat';import {getCdecliToken,clearCdecliToken}from'@yantra/surface-kit/auth';import {ASK_USER_SYSTEM_PROMPT,AgentChat,HostQueuedMessages,humanizeToolLine,parseAskUser}from'@yantra/surface-kit/chat';import {registerRun,jobDeadlineAt,completeRun,failRun,removeTask,listTasks,getTask,noteRun,STOPPED_ERROR,abandonChannelTurn}from'@yantra/surface-kit/tasks';import {CHAT_STARTERS}from'../content.js';import {ImessageIcon}from'../imessage/ImessageIcon.js';import {Mark}from'../Logo.js';import {yantraAppUrl}from'../platform.js';import {placeCallsCards}from'./calls.js';import {CallsCard,SurfaceLinks}from'./CallsCard.js';import {ChatTheme}from'./chatTheme.js';import {CLOCKBOOK_SURFACE,CHORE_LANE,choreTitle,CHORE_TURN_BUDGET_MS,isQueuedLine,ANSWER_KEPT,choreList,turnFromTask}from'./chores.js';import {ChoresButton,StillWorking,ChoresPanel}from'./ChoresPanel.js';import {ConnectorsPanel,ConnectorLogo}from'./ConnectorsPanel.js';import {failureNote,canRetry}from'./failure.js';import {archiveChat,markStopped,takePastChat,listPastChats,deletePastChat,clearHistory,STOPPED_MARK}from'./history.js';import {HistoryButton,HistoryPanel}from'./HistoryPanel.js';import {LUCY_SYSTEM_PROMPT}from'./lucy.js';import {showReply}from'./media.js';import {taskOf,settleInThread,NO_ANSWER_REPLY,askingTurn,STILL_ON_IT}from'./placement.js';import {restoreQueue,draftWith,sentElsewhere,nextToSend}from'./queue.js';import {ResultCards}from'./ResultCards.js';import {RESULT_CARDS_PROMPT,takeResultWidgets,takeResults,cardPicks}from'./results.js';import {cleanStatus}from'./status.js';import {stopTurns}from'./stop.js';import {takeSurfaceMarkers,PHONE_CALLS_SURFACE}from'./surfaces.js';import {accountKeyFromToken,emailFromToken,firstNameFromToken,loadThread,saveThread,clearThread}from'./thread.js';import {ChatTour}from'./tour/ChatTour.js';import {useChatTour}from'./tour/useChatTour.js';import {useCallLog}from'./useCallLog.js';import {useChores}from'./useChores.js';/** The starters' icons, in CHAT_STARTERS order. */
|
|
2
2
|
const STARTER_ICONS = [CalendarClock, PhoneCall, Receipt, BellRing];
|
|
3
|
+
/** The composer's prompt; also how a pick from a result card finds the composer to hand the focus to. */
|
|
4
|
+
const COMPOSER_PLACEHOLDER = 'Tell Lucy what to take off your plate…';
|
|
3
5
|
/**
|
|
4
|
-
* Lucy's brief
|
|
5
|
-
*
|
|
6
|
+
* Lucy's brief; how to hand over flights and products so the chat draws them as cards (results.ts,
|
|
7
|
+
* Yantra's own note); then the kit's: her questions and the yes she needs before committing to
|
|
8
|
+
* anything come as question cards (the kit's AskUserCard) rather than prose. Applied when a session
|
|
9
|
+
* opens.
|
|
6
10
|
*/
|
|
7
|
-
const SYSTEM_PROMPT = `${LUCY_SYSTEM_PROMPT}\n\n${ASK_USER_SYSTEM_PROMPT}`;
|
|
11
|
+
const SYSTEM_PROMPT = `${LUCY_SYSTEM_PROMPT}\n\n${RESULT_CARDS_PROMPT}\n\n${ASK_USER_SYSTEM_PROMPT}`;
|
|
8
12
|
/** Videos and sound clips Lucy made, playable under her reply (media.ts lifts them out of it). */
|
|
9
13
|
function MessageMedia({
|
|
10
14
|
media
|
|
@@ -34,12 +38,14 @@ function greetingFor(hour) {
|
|
|
34
38
|
return 'Working late';
|
|
35
39
|
}
|
|
36
40
|
/**
|
|
37
|
-
* The empty chat: Lucy's greeting, the chores people hand over first,
|
|
38
|
-
* chat only ever renders in the browser, so the
|
|
41
|
+
* The empty chat: Lucy's greeting, the chores people hand over first, the apps she can use once
|
|
42
|
+
* they are connected, and the other way in. The chat only ever renders in the browser, so the
|
|
43
|
+
* visitor's own clock picks the greeting.
|
|
39
44
|
*/
|
|
40
45
|
function ChatWelcome({
|
|
41
46
|
onPick,
|
|
42
47
|
onImessage,
|
|
48
|
+
onConnectApps,
|
|
43
49
|
disabled
|
|
44
50
|
}) {
|
|
45
51
|
return jsxs("div", {
|
|
@@ -85,20 +91,47 @@ function ChatWelcome({
|
|
|
85
91
|
})]
|
|
86
92
|
}, s.label);
|
|
87
93
|
})
|
|
88
|
-
}), onImessage ? jsxs("
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
children: "
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
94
|
+
}), onConnectApps || onImessage ? jsxs("div", {
|
|
95
|
+
className: "cbh-chat-ways",
|
|
96
|
+
children: [onConnectApps ? jsxs("button", {
|
|
97
|
+
type: "button",
|
|
98
|
+
className: "cbh-chat-apps",
|
|
99
|
+
"data-tour": "apps",
|
|
100
|
+
"data-track": "chat_apps",
|
|
101
|
+
onClick: onConnectApps,
|
|
102
|
+
"aria-haspopup": "dialog",
|
|
103
|
+
children: [jsxs("span", {
|
|
104
|
+
className: "cbh-chat-apps-logos",
|
|
105
|
+
"aria-hidden": true,
|
|
106
|
+
children: [jsx(ConnectorLogo, {
|
|
107
|
+
id: "google-calendar",
|
|
108
|
+
size: 12
|
|
109
|
+
}), jsx(ConnectorLogo, {
|
|
110
|
+
id: "google-gmail",
|
|
111
|
+
size: 12
|
|
112
|
+
}), jsx(ConnectorLogo, {
|
|
113
|
+
id: "site-login",
|
|
114
|
+
size: 13
|
|
115
|
+
})]
|
|
116
|
+
}), "Connect your apps", jsx(ArrowRight, {
|
|
117
|
+
size: 14,
|
|
118
|
+
"aria-hidden": true
|
|
119
|
+
})]
|
|
120
|
+
}) : null, onImessage ? jsxs("button", {
|
|
121
|
+
type: "button",
|
|
122
|
+
className: "cbh-chat-imsg",
|
|
123
|
+
"data-track": "chat_imessage",
|
|
124
|
+
onClick: onImessage,
|
|
125
|
+
"aria-haspopup": "dialog",
|
|
126
|
+
children: [jsx(ImessageIcon, {
|
|
127
|
+
size: 22
|
|
128
|
+
}), jsx("span", {
|
|
129
|
+
children: "Prefer texting?"
|
|
130
|
+
}), "Text Lucy on iMessage", jsx(ArrowRight, {
|
|
131
|
+
size: 14,
|
|
132
|
+
"aria-hidden": true
|
|
133
|
+
})]
|
|
134
|
+
}) : null]
|
|
102
135
|
}) : null]
|
|
103
136
|
});
|
|
104
137
|
}
|
|
@@ -107,6 +140,8 @@ let turnSeq = 0;
|
|
|
107
140
|
const nextId = kind => `${kind}-${Date.now().toString(36)}-${turnSeq += 1}`;
|
|
108
141
|
/** Whether a reply of Lucy's holds one of her question cards. */
|
|
109
142
|
const asksQuestion = content => parseAskUser(content) !== null;
|
|
143
|
+
/** Presses of "Stop and send now" closer together than this are one press (a double tap). */
|
|
144
|
+
const SEND_NOW_GAP_MS = 1_500;
|
|
110
145
|
/** What a turn whose request came back with no words at all is settled with. */
|
|
111
146
|
const NO_ANSWER = 'No answer came back';
|
|
112
147
|
/** A chore's turn that settled with nothing here streaming it, as the thread takes it (placement.ts). */
|
|
@@ -215,9 +250,12 @@ function NewChatButton({
|
|
|
215
250
|
}) : null]
|
|
216
251
|
});
|
|
217
252
|
}
|
|
253
|
+
/** The account's menu: who is signed in, the apps Lucy can use (ConnectorsPanel), and Sign out. */
|
|
218
254
|
function AccountMenu({
|
|
219
255
|
email,
|
|
220
|
-
onSignOut
|
|
256
|
+
onSignOut,
|
|
257
|
+
onConnectApps,
|
|
258
|
+
buttonRef
|
|
221
259
|
}) {
|
|
222
260
|
const [open, setOpen] = useState(false);
|
|
223
261
|
const ref = useRef(null);
|
|
@@ -227,7 +265,9 @@ function AccountMenu({
|
|
|
227
265
|
className: "relative",
|
|
228
266
|
ref: ref,
|
|
229
267
|
children: [jsx("button", {
|
|
268
|
+
ref: buttonRef,
|
|
230
269
|
type: "button",
|
|
270
|
+
"data-tour": "account",
|
|
231
271
|
onClick: () => setOpen(v => !v),
|
|
232
272
|
"aria-haspopup": "menu",
|
|
233
273
|
"aria-expanded": open,
|
|
@@ -241,6 +281,20 @@ function AccountMenu({
|
|
|
241
281
|
className: "truncate px-2.5 py-2 text-xs text-muted-foreground",
|
|
242
282
|
children: email
|
|
243
283
|
}) : null, jsxs("button", {
|
|
284
|
+
type: "button",
|
|
285
|
+
role: "menuitem",
|
|
286
|
+
"data-track": "chat_apps_menu",
|
|
287
|
+
"aria-haspopup": "dialog",
|
|
288
|
+
onClick: () => {
|
|
289
|
+
setOpen(false);
|
|
290
|
+
onConnectApps();
|
|
291
|
+
},
|
|
292
|
+
className: "flex w-full items-center gap-2 rounded-lg px-2.5 py-2 text-left text-sm text-foreground hover:bg-muted",
|
|
293
|
+
children: [jsx(Plug, {
|
|
294
|
+
className: "h-4 w-4",
|
|
295
|
+
"aria-hidden": true
|
|
296
|
+
}), "Connect your apps"]
|
|
297
|
+
}), jsxs("button", {
|
|
244
298
|
type: "button",
|
|
245
299
|
role: "menuitem",
|
|
246
300
|
onClick: () => {
|
|
@@ -270,6 +324,13 @@ function ChoresChat({
|
|
|
270
324
|
const firstName = useMemo(() => firstNameFromToken(token), [token]);
|
|
271
325
|
const [thread] = useState(() => loadThread(account));
|
|
272
326
|
const [messages, setMessages] = useState(thread.messages);
|
|
327
|
+
// What waits for Lucy to finish the turn she is on (queue.ts). A closed page's goes on waiting,
|
|
328
|
+
// unless it waited too long: that comes back to the composer, unsent.
|
|
329
|
+
const [restored] = useState(() => restoreQueue(thread.waiting ?? [], Date.now()));
|
|
330
|
+
const [queued, setQueued] = useState(restored.waiting);
|
|
331
|
+
const queuedRef = useRef(queued);
|
|
332
|
+
// The composer's text, held here so Stop and New chat can hand what waited back to it.
|
|
333
|
+
const [draft, setDraft] = useState(() => draftWith('', restored.stale));
|
|
273
334
|
const [busy, setBusy] = useState(false);
|
|
274
335
|
// The tour opens by itself only on a chat that is on screen, empty and idle (useChatTour).
|
|
275
336
|
const tour = useChatTour(account, !hidden && !busy && messages.length === 0);
|
|
@@ -281,10 +342,12 @@ function ChoresChat({
|
|
|
281
342
|
const turnsRef = useRef(new Set());
|
|
282
343
|
// Only stops listening: Lucy finishes the chore, and its record has how it went.
|
|
283
344
|
const abortTurns = useCallback(() => turnsRef.current.forEach(turn => turn.controller.abort()), []);
|
|
345
|
+
// False once the chat is gone (signed out, or its session refused): nothing more goes out.
|
|
346
|
+
const aliveRef = useRef(true);
|
|
284
347
|
// Stop, and New chat while she works: Lucy stops too (stop.ts). A turn sent meanwhile waits until
|
|
285
348
|
// the agent has had the word, which could otherwise reach it after that turn and stop it instead.
|
|
286
349
|
const stoppingRef = useRef(Promise.resolve());
|
|
287
|
-
const
|
|
350
|
+
const tellLucyToStop = useCallback(() => {
|
|
288
351
|
if (turnsRef.current.size) setStatus('Stopping…');
|
|
289
352
|
stoppingRef.current = stopTurns(turnsRef.current, cancelAgentTurn);
|
|
290
353
|
}, []);
|
|
@@ -294,6 +357,16 @@ function ChoresChat({
|
|
|
294
357
|
const [choresOpen, setChoresOpen] = useState(false);
|
|
295
358
|
const [openChore, setOpenChore] = useState(null);
|
|
296
359
|
const choresButtonRef = useRef(null);
|
|
360
|
+
// The history panel, and the past chats it lists: read again each time it opens (history.ts).
|
|
361
|
+
const [historyOpen, setHistoryOpen] = useState(false);
|
|
362
|
+
const [pastChats, setPastChats] = useState([]);
|
|
363
|
+
const historyButtonRef = useRef(null);
|
|
364
|
+
// Connect your apps (ConnectorsPanel), from the account menu or the empty chat; it hangs under the
|
|
365
|
+
// account button. Connecting happens on the Yantra app.
|
|
366
|
+
const [appsOpen, setAppsOpen] = useState(false);
|
|
367
|
+
const accountButtonRef = useRef(null);
|
|
368
|
+
const openApps = useCallback(() => setAppsOpen(true), []);
|
|
369
|
+
const closeApps = useCallback(() => setAppsOpen(false), []);
|
|
297
370
|
// Chores that finished with nothing here streaming them: what came back takes its place in the
|
|
298
371
|
// thread (placement.ts). Returns the ones it took; one from before a new chat, or another tab's
|
|
299
372
|
// conversation, is only in the panel.
|
|
@@ -313,7 +386,8 @@ function ChoresChat({
|
|
|
313
386
|
jobFor,
|
|
314
387
|
releaseJob,
|
|
315
388
|
agentHas,
|
|
316
|
-
forget
|
|
389
|
+
forget,
|
|
390
|
+
placeUnplaced
|
|
317
391
|
} = useChores({
|
|
318
392
|
owner: account,
|
|
319
393
|
open: choresOpen,
|
|
@@ -322,9 +396,34 @@ function ChoresChat({
|
|
|
322
396
|
const persist = useCallback(() => {
|
|
323
397
|
saveThread(account, {
|
|
324
398
|
sessionId: sessionIdRef.current,
|
|
325
|
-
messages: messagesRef.current
|
|
399
|
+
messages: messagesRef.current,
|
|
400
|
+
waiting: queuedRef.current
|
|
326
401
|
});
|
|
327
402
|
}, [account]);
|
|
403
|
+
// The queue changes seldom, and matters most just before the page closes: it is kept at once.
|
|
404
|
+
const setQueue = useCallback(next => {
|
|
405
|
+
queuedRef.current = next;
|
|
406
|
+
setQueued(next);
|
|
407
|
+
persist();
|
|
408
|
+
}, [persist]);
|
|
409
|
+
// What this page streams in the chat on screen, as the queue reads it (queue.ts).
|
|
410
|
+
const chatNow = useCallback(() => ({
|
|
411
|
+
streaming: turnsRef.current,
|
|
412
|
+
gen: threadGenRef.current
|
|
413
|
+
}), []);
|
|
414
|
+
// What waited for Lucy comes back to the composer, unsent.
|
|
415
|
+
const handBackQueue = useCallback(() => {
|
|
416
|
+
const waiting = queuedRef.current;
|
|
417
|
+
if (!waiting.length) return;
|
|
418
|
+
setQueue([]);
|
|
419
|
+
setDraft(current => draftWith(current, waiting));
|
|
420
|
+
}, [setQueue]);
|
|
421
|
+
// Stop, and New chat: Lucy stops, all of it. What waited for her comes back to the composer
|
|
422
|
+
// rather than going out behind the chore just stopped.
|
|
423
|
+
const stopLucy = useCallback(() => {
|
|
424
|
+
tellLucyToStop();
|
|
425
|
+
handBackQueue();
|
|
426
|
+
}, [tellLucyToStop, handBackQueue]);
|
|
328
427
|
// Keep what is on screen. While a reply streams in, once it pauses rather than on every token.
|
|
329
428
|
useEffect(() => {
|
|
330
429
|
if (!busy) {
|
|
@@ -334,14 +433,20 @@ function ChoresChat({
|
|
|
334
433
|
const t = window.setTimeout(persist, 800);
|
|
335
434
|
return () => window.clearTimeout(t);
|
|
336
435
|
}, [messages, busy, persist]);
|
|
337
|
-
|
|
436
|
+
/**
|
|
437
|
+
* One turn to Lucy, now (`submit` decides when). It is a task of the chore it belongs to: an answer
|
|
438
|
+
* to Lucy's question card goes on the chore that asked it (`answering`), anything else is a new
|
|
439
|
+
* chore, `choreId` when the queue already named it.
|
|
440
|
+
*/
|
|
441
|
+
const send = useCallback(async (text, answering, choreId) => {
|
|
338
442
|
const prompt = text.trim();
|
|
339
443
|
if (!prompt) return;
|
|
340
444
|
const gen = threadGenRef.current;
|
|
341
445
|
const current = () => threadGenRef.current === gen;
|
|
342
446
|
const turn = {
|
|
343
447
|
controller: new AbortController(),
|
|
344
|
-
sessionId: ''
|
|
448
|
+
sessionId: '',
|
|
449
|
+
gen
|
|
345
450
|
};
|
|
346
451
|
const {
|
|
347
452
|
controller
|
|
@@ -349,15 +454,12 @@ function ChoresChat({
|
|
|
349
454
|
turnsRef.current.add(turn);
|
|
350
455
|
setBusy(true);
|
|
351
456
|
setStatus('Lucy is on it…');
|
|
352
|
-
// The turn is a task of the chore it belongs to: an answer to Lucy's question card goes on
|
|
353
|
-
// the chore that asked it, anything else is a new chore.
|
|
354
|
-
const answering = getTask(askingTurn(messagesRef.current, asksQuestion));
|
|
355
457
|
const chore = registerRun({
|
|
356
458
|
title: answering?.title ?? choreTitle(prompt),
|
|
357
459
|
brief: prompt,
|
|
358
460
|
lane: CHORE_LANE,
|
|
359
461
|
surface: CLOCKBOOK_SURFACE,
|
|
360
|
-
boardId: answering?.handle.boardId || answering?.id || nextId('chore'),
|
|
462
|
+
boardId: answering?.handle.boardId || answering?.id || choreId || nextId('chore'),
|
|
361
463
|
deadlineAt: jobDeadlineAt(Date.now(), CHORE_TURN_BUDGET_MS),
|
|
362
464
|
input: {
|
|
363
465
|
prompt
|
|
@@ -366,6 +468,7 @@ function ChoresChat({
|
|
|
366
468
|
owner: account
|
|
367
469
|
} : {})
|
|
368
470
|
});
|
|
471
|
+
turn.task = chore.id;
|
|
369
472
|
const asked = {
|
|
370
473
|
id: nextId('user'),
|
|
371
474
|
role: 'user',
|
|
@@ -418,8 +521,9 @@ function ChoresChat({
|
|
|
418
521
|
if (!heard() || !current()) return;
|
|
419
522
|
if (!started) {
|
|
420
523
|
started = true;
|
|
421
|
-
// Heard from: it is no longer waiting its turn.
|
|
422
|
-
|
|
524
|
+
// Heard from: it is no longer waiting its turn, whatever the agent's queue said.
|
|
525
|
+
const progress = getTask(chore.id)?.progress;
|
|
526
|
+
if (!progress || isQueuedLine(progress)) noteRun(chore.id, 'Writing back to you…');
|
|
423
527
|
addReply(delta);
|
|
424
528
|
return;
|
|
425
529
|
}
|
|
@@ -431,7 +535,7 @@ function ChoresChat({
|
|
|
431
535
|
controller.abort();
|
|
432
536
|
await turn.stopped;
|
|
433
537
|
failRun(chore.id, STOPPED_ERROR);
|
|
434
|
-
if (started) patchReply(sofar => `${sofar}\n\
|
|
538
|
+
if (started) patchReply(sofar => `${sofar}\n\n${STOPPED_MARK}`);
|
|
435
539
|
};
|
|
436
540
|
let job;
|
|
437
541
|
try {
|
|
@@ -439,13 +543,20 @@ function ChoresChat({
|
|
|
439
543
|
job = await jobFor(chore);
|
|
440
544
|
await stoppingRef.current;
|
|
441
545
|
// The session it runs on, known before it goes out: a Stop has to name it. A new chat's
|
|
442
|
-
// first turn opens one here, as the kit would have
|
|
443
|
-
//
|
|
444
|
-
turn.sessionId = sessionIdRef.current
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
546
|
+
// first turn opens one here, as the kit would have, and the chat moves onto it at once:
|
|
547
|
+
// an answer to a question Lucy asks in that turn goes to it, and what waits goes after.
|
|
548
|
+
turn.sessionId = sessionIdRef.current;
|
|
549
|
+
if (!turn.sessionId) {
|
|
550
|
+
turn.sessionId = await openAgentSession({
|
|
551
|
+
systemPrompt: SYSTEM_PROMPT,
|
|
552
|
+
permissionMode: 'auto',
|
|
553
|
+
signal: controller.signal
|
|
554
|
+
});
|
|
555
|
+
if (current()) {
|
|
556
|
+
sessionIdRef.current = turn.sessionId;
|
|
557
|
+
persist();
|
|
558
|
+
}
|
|
559
|
+
}
|
|
449
560
|
const result = await postAgentChatStream(prompt, {
|
|
450
561
|
sessionId: turn.sessionId,
|
|
451
562
|
systemPrompt: SYSTEM_PROMPT,
|
|
@@ -454,14 +565,11 @@ function ChoresChat({
|
|
|
454
565
|
...(job ? {
|
|
455
566
|
job
|
|
456
567
|
} : {}),
|
|
457
|
-
// A
|
|
458
|
-
//
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
sessionIdRef.current = recovery.sessionId;
|
|
463
|
-
persist();
|
|
464
|
-
},
|
|
568
|
+
// A session busy with another turn is not forked: the kit's recovery cancels the
|
|
569
|
+
// turn it is on, which is a chore of Lucy's. This chat sends nothing more to a
|
|
570
|
+
// session it has a turn on (queue.ts), so a refusal is about a turn it did not
|
|
571
|
+
// send (another tab of it), and is said so below.
|
|
572
|
+
recoverStuckSession: false,
|
|
465
573
|
// A passing outage (the model provider, an agent restart) is retried out of
|
|
466
574
|
// sight; a resend voids what the failed attempt said, a continue keeps it.
|
|
467
575
|
retry: {
|
|
@@ -483,7 +591,7 @@ function ChoresChat({
|
|
|
483
591
|
onStatus: s => {
|
|
484
592
|
const line = cleanStatus(s);
|
|
485
593
|
// "Queued…" is the agent holding it behind the turn it is on.
|
|
486
|
-
if (line && (
|
|
594
|
+
if (line && (isQueuedLine(line) || heard())) say(line);
|
|
487
595
|
}
|
|
488
596
|
});
|
|
489
597
|
if (current()) sessionIdRef.current = result.sessionId;
|
|
@@ -494,10 +602,15 @@ function ChoresChat({
|
|
|
494
602
|
const retry = result.text ? undefined : prompt;
|
|
495
603
|
const finalText = result.text || NO_ANSWER_REPLY;
|
|
496
604
|
if (started) patchReply(() => finalText, retry);else addReply(finalText, retry);
|
|
497
|
-
// In the thread now (or in none, after a new chat): nothing else has to place it.
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
605
|
+
// In the thread now (or in none, after a new chat): nothing else has to place it. The
|
|
606
|
+
// record keeps her words, not her result blocks: a block cut at the limit would leave
|
|
607
|
+
// its raw JSON in the Chores panel (the card itself is in the thread).
|
|
608
|
+
if (result.text) {
|
|
609
|
+
const words = takeResultWidgets(result.text).content || result.text;
|
|
610
|
+
completeRun(chore.id, {
|
|
611
|
+
text: words.slice(0, ANSWER_KEPT)
|
|
612
|
+
});
|
|
613
|
+
} else failRun(chore.id, NO_ANSWER);
|
|
501
614
|
} catch (err) {
|
|
502
615
|
// A failed or stopped turn still ran on a session; the next message continues there.
|
|
503
616
|
const failed = err;
|
|
@@ -516,9 +629,20 @@ function ChoresChat({
|
|
|
516
629
|
removeTask(chore.id);
|
|
517
630
|
setMessages(prev => prev.filter(m => m.id !== reply.id && m.id !== asked.id));
|
|
518
631
|
onSessionExpired(prompt);
|
|
632
|
+
} else if (isSessionBusyError(err)) {
|
|
633
|
+
// Lucy is on a turn of this chat that this page did not send, and the agent would
|
|
634
|
+
// not take this one: it never reached her, so it is no chore of hers. The chat
|
|
635
|
+
// says so and offers to send it again. What waits behind it would be turned away
|
|
636
|
+
// too, so it comes back to the composer rather than go out now.
|
|
637
|
+
removeTask(chore.id);
|
|
638
|
+
if (current()) {
|
|
639
|
+
const note = failureNote(err);
|
|
640
|
+
if (started) patchReply(sofar => `${sofar}\n\n${note}`, prompt);else addReply(note, prompt);
|
|
641
|
+
handBackQueue();
|
|
642
|
+
}
|
|
519
643
|
} else if (job && failed?.dropped && (started || failed.streamed)) {
|
|
520
644
|
keepGoing();
|
|
521
|
-
} else if (job && !failed?.turnFailed &&
|
|
645
|
+
} else if (job && !failed?.turnFailed && (await agentHas(chore))) {
|
|
522
646
|
// No reply came, or the agent's servers answered with an error, yet its record says
|
|
523
647
|
// the agent has the turn.
|
|
524
648
|
keepGoing();
|
|
@@ -537,40 +661,142 @@ function ChoresChat({
|
|
|
537
661
|
const open = turnsRef.current.size > 0;
|
|
538
662
|
setBusy(open);
|
|
539
663
|
if (!open) setStatus(null);
|
|
664
|
+
// Lucy may be free now: the next message waiting goes.
|
|
665
|
+
sendNextRef.current();
|
|
666
|
+
}
|
|
667
|
+
}, [account, agentHas, handBackQueue, jobFor, onSessionExpired, persist, releaseJob]);
|
|
668
|
+
// The message that waited longest goes to Lucy, once she is on nothing this page streams. Never for
|
|
669
|
+
// a chat that is gone, or signed out (`onSessionExpired` drops the token before it goes): what
|
|
670
|
+
// waits is kept with the thread, for when the chat is back. One another tab already sent is
|
|
671
|
+
// dropped instead (read from the task store as it is now, not as last rendered).
|
|
672
|
+
const sendNext = useCallback(() => {
|
|
673
|
+
if (!aliveRef.current || !getCdecliToken()) return;
|
|
674
|
+
const gone = sentElsewhere(queuedRef.current, listTasks());
|
|
675
|
+
if (gone.length) setQueue(queuedRef.current.filter(m => !gone.includes(m)));
|
|
676
|
+
const next = nextToSend(queuedRef.current, chatNow());
|
|
677
|
+
if (!next) return;
|
|
678
|
+
setQueue(queuedRef.current.filter(m => m !== next));
|
|
679
|
+
void send(next.text, undefined, next.id);
|
|
680
|
+
}, [chatNow, send, setQueue]);
|
|
681
|
+
// `send` asks for the next one as each turn ends, and is made before this.
|
|
682
|
+
const sendNextRef = useRef(sendNext);
|
|
683
|
+
sendNextRef.current = sendNext;
|
|
684
|
+
// Everything the person sends comes here. An answer to Lucy's question card goes at once: the turn
|
|
685
|
+
// that asked is waiting for it. Anything else waits its turn behind what was sent before it, which
|
|
686
|
+
// is no wait at all when Lucy is free.
|
|
687
|
+
const submit = useCallback(text => {
|
|
688
|
+
const prompt = text.trim();
|
|
689
|
+
if (!prompt) return;
|
|
690
|
+
const asking = askingTurn(messagesRef.current, asksQuestion);
|
|
691
|
+
if (asking) {
|
|
692
|
+
void send(prompt, getTask(asking));
|
|
693
|
+
return;
|
|
540
694
|
}
|
|
541
|
-
|
|
695
|
+
setQueue([...queuedRef.current, {
|
|
696
|
+
id: nextId('chore'),
|
|
697
|
+
text: prompt,
|
|
698
|
+
at: Date.now()
|
|
699
|
+
}]);
|
|
700
|
+
sendNext();
|
|
701
|
+
}, [send, sendNext, setQueue]);
|
|
702
|
+
// The strip's "Stop and send now": the chore Lucy is on stops (stop.ts), and what waited goes next.
|
|
703
|
+
// Once per press: a double tap would stop the message the first tap just sent, before it reached her.
|
|
704
|
+
const sentNowAtRef = useRef(0);
|
|
705
|
+
const stopAndSendNow = useCallback(() => {
|
|
706
|
+
if (Date.now() - sentNowAtRef.current < SEND_NOW_GAP_MS) return;
|
|
707
|
+
sentNowAtRef.current = Date.now();
|
|
708
|
+
tellLucyToStop();
|
|
709
|
+
sendNext();
|
|
710
|
+
}, [tellLucyToStop, sendNext]);
|
|
542
711
|
// Each chore from the landing goes out once, even under StrictMode's double mount.
|
|
543
712
|
const sentKey = useRef(null);
|
|
544
713
|
useEffect(() => {
|
|
545
714
|
if (!request?.text.trim() || sentKey.current === request.key) return;
|
|
546
715
|
sentKey.current = request.key;
|
|
547
|
-
|
|
548
|
-
}, [request,
|
|
549
|
-
// Unmounted only on sign-out or a refused session; nothing is left to stream to.
|
|
550
|
-
useEffect(() =>
|
|
551
|
-
|
|
552
|
-
|
|
716
|
+
submit(request.text);
|
|
717
|
+
}, [request, submit]);
|
|
718
|
+
// Unmounted only on sign-out or a refused session; nothing is left to stream to, or to send.
|
|
719
|
+
useEffect(() => {
|
|
720
|
+
aliveRef.current = true;
|
|
721
|
+
return () => {
|
|
722
|
+
aliveRef.current = false;
|
|
723
|
+
abortTurns();
|
|
724
|
+
};
|
|
725
|
+
}, [abortTurns]);
|
|
726
|
+
// The chat on screen, put away in the history as it stands (history.ts). A reply Lucy is still
|
|
727
|
+
// streaming says it was stopped, the way Stop leaves one: leaving the chat stops her.
|
|
728
|
+
const keepChat = useCallback(() => {
|
|
729
|
+
const streaming = new Set();
|
|
730
|
+
turnsRef.current.forEach(turn => {
|
|
731
|
+
if (turn.gen === threadGenRef.current && turn.task) streaming.add(turn.task);
|
|
732
|
+
});
|
|
733
|
+
archiveChat(account, {
|
|
734
|
+
sessionId: sessionIdRef.current,
|
|
735
|
+
messages: markStopped(messagesRef.current, streaming)
|
|
736
|
+
});
|
|
737
|
+
}, [account]);
|
|
738
|
+
// The chat on screen goes into the history, and an empty one takes its place. Stops what Lucy is
|
|
739
|
+
// on for this page, which New chat asked about first. A chore going on without the page (it was
|
|
740
|
+
// reloaded) is not one of them: nobody was asked, and it is left to finish; its answer takes its
|
|
741
|
+
// place in the chat once that is opened again. What waited for her comes back to the composer,
|
|
742
|
+
// for the new chat or for nothing.
|
|
553
743
|
const newChat = useCallback(() => {
|
|
744
|
+
keepChat();
|
|
554
745
|
threadGenRef.current += 1;
|
|
555
746
|
stopLucy();
|
|
556
747
|
sessionIdRef.current = '';
|
|
557
748
|
setMessages([]);
|
|
558
749
|
clearThread(account);
|
|
559
|
-
}, [account, stopLucy]);
|
|
750
|
+
}, [account, keepChat, stopLucy]);
|
|
751
|
+
// A past chat is the thread again, on its own agent session, so Lucy carries on in it; the chat
|
|
752
|
+
// on screen is put away in its place. Like New chat, it stops what Lucy is on for this page (the
|
|
753
|
+
// panel asked first). What settled while it was put away takes its place in it now.
|
|
754
|
+
const openPastChat = useCallback(id => {
|
|
755
|
+
setHistoryOpen(false);
|
|
756
|
+
const chat = takePastChat(account, id);
|
|
757
|
+
if (!chat) return;
|
|
758
|
+
keepChat();
|
|
759
|
+
threadGenRef.current += 1;
|
|
760
|
+
stopLucy();
|
|
761
|
+
sessionIdRef.current = chat.sessionId;
|
|
762
|
+
messagesRef.current = chat.messages;
|
|
763
|
+
setMessages(chat.messages);
|
|
764
|
+
saveThread(account, {
|
|
765
|
+
sessionId: chat.sessionId,
|
|
766
|
+
messages: chat.messages
|
|
767
|
+
});
|
|
768
|
+
placeUnplaced();
|
|
769
|
+
}, [account, keepChat, stopLucy, placeUnplaced]);
|
|
770
|
+
const closeHistory = useCallback(() => setHistoryOpen(false), []);
|
|
771
|
+
const toggleHistory = useCallback(() => {
|
|
772
|
+
if (historyOpen) {
|
|
773
|
+
setHistoryOpen(false);
|
|
774
|
+
return;
|
|
775
|
+
}
|
|
776
|
+
setPastChats(listPastChats(account));
|
|
777
|
+
setHistoryOpen(true);
|
|
778
|
+
}, [account, historyOpen]);
|
|
779
|
+
const deleteChat = useCallback(id => {
|
|
780
|
+
deletePastChat(account, id);
|
|
781
|
+
setPastChats(listPastChats(account));
|
|
782
|
+
}, [account]);
|
|
560
783
|
// Signing out leaves nothing of the conversation in this browser (a shared computer), its chores
|
|
561
|
-
// included. Their records stay the account's, for the next time it signs in,
|
|
562
|
-
// goes on to fill its own. The token goes first: another tab sees it gone
|
|
563
|
-
// stops recording them (useChores).
|
|
784
|
+
// and its past chats included. Their records stay the account's, for the next time it signs in,
|
|
785
|
+
// and a chore under way goes on to fill its own. The token goes first: another tab sees it gone
|
|
786
|
+
// before the chores, and stops recording them (useChores).
|
|
564
787
|
const signOut = useCallback(() => {
|
|
565
788
|
threadGenRef.current += 1;
|
|
789
|
+
// What waited goes with the rest of the conversation, and not to Lucy as the turns stop.
|
|
790
|
+
queuedRef.current = [];
|
|
566
791
|
abortTurns();
|
|
567
792
|
clearCdecliToken();
|
|
568
793
|
forget();
|
|
569
794
|
clearThread(account);
|
|
795
|
+
clearHistory(account);
|
|
570
796
|
onSignedOut();
|
|
571
797
|
}, [account, forget, onSignedOut]);
|
|
572
798
|
// Starters are for an empty chat; mid-conversation, Lucy's own question is what to answer.
|
|
573
|
-
const pickStarter = useCallback(prompt =>
|
|
799
|
+
const pickStarter = useCallback(prompt => submit(prompt), [submit]);
|
|
574
800
|
// "Try again": the attempt that did not go through leaves the thread (the reply and the chore it
|
|
575
801
|
// answered) and the chores, and the chore goes out again as if just asked.
|
|
576
802
|
const tryAgain = useCallback(failed => {
|
|
@@ -588,8 +814,8 @@ function ChoresChat({
|
|
|
588
814
|
// Read without the attempt: an answer to Lucy's question goes out as one again.
|
|
589
815
|
messagesRef.current = drop(messagesRef.current);
|
|
590
816
|
setMessages(drop);
|
|
591
|
-
|
|
592
|
-
}, [
|
|
817
|
+
submit(chore);
|
|
818
|
+
}, [submit]);
|
|
593
819
|
// Offered under the latest message only, and not while Lucy is busy with another chore. `retry`
|
|
594
820
|
// came back from storage too, so it is checked like every other field kept there.
|
|
595
821
|
const lastId = messages[messages.length - 1]?.id;
|
|
@@ -610,29 +836,75 @@ function ChoresChat({
|
|
|
610
836
|
})
|
|
611
837
|
});
|
|
612
838
|
}, [busy, lastId, tryAgain]);
|
|
613
|
-
// What the chat draws: Lucy's replies with what she made made visible (media.ts),
|
|
614
|
-
//
|
|
615
|
-
//
|
|
839
|
+
// What the chat draws: Lucy's replies with what she made made visible (media.ts), without the
|
|
840
|
+
// surface markers she writes for iMessage's cards (surfaces.ts), and without the result blocks
|
|
841
|
+
// she writes for flights and products (results.ts): what they carry goes under the reply instead.
|
|
842
|
+
// The thread keeps what she said; only the drawing changes. A reply's cards are kept while its
|
|
843
|
+
// words stay the same, so streaming into one reply redraws no other reply's cards.
|
|
844
|
+
const resultsRef = useRef(new Map());
|
|
616
845
|
const shown = useMemo(() => {
|
|
617
846
|
const media = new Map();
|
|
618
847
|
const surfaces = new Map();
|
|
848
|
+
const results = new Map();
|
|
849
|
+
const kept = new Map();
|
|
619
850
|
const drawn = messages.map(m => {
|
|
620
851
|
if (m.role !== 'assistant') return m;
|
|
621
852
|
const marked = takeSurfaceMarkers(m.content);
|
|
622
|
-
const
|
|
853
|
+
const before = resultsRef.current.get(m.id);
|
|
854
|
+
const taken = before?.from === marked.content ? before : {
|
|
855
|
+
from: marked.content,
|
|
856
|
+
...takeResults(marked.content, m.id)
|
|
857
|
+
};
|
|
858
|
+
kept.set(m.id, taken);
|
|
859
|
+
const reply = showReply(taken.content);
|
|
623
860
|
if (reply.media.length) media.set(m.id, reply.media);
|
|
624
861
|
if (marked.markers.length) surfaces.set(m.id, marked.markers);
|
|
862
|
+
if (taken.cards.length) results.set(m.id, taken.cards);
|
|
625
863
|
return reply.content === m.content ? m : {
|
|
626
864
|
...m,
|
|
627
865
|
content: reply.content
|
|
628
866
|
};
|
|
629
867
|
});
|
|
868
|
+
resultsRef.current = kept;
|
|
630
869
|
return {
|
|
631
870
|
messages: drawn,
|
|
632
871
|
media,
|
|
633
|
-
surfaces
|
|
872
|
+
surfaces,
|
|
873
|
+
results
|
|
634
874
|
};
|
|
635
875
|
}, [messages]);
|
|
876
|
+
// The pick each card already sent: the first of the person's later messages with one of its rows'
|
|
877
|
+
// exact words (a tap sends just those). Read off the thread, so it holds after a reload; passed on
|
|
878
|
+
// as JSON, so a card redraws only when its picks change.
|
|
879
|
+
const picksByReply = useMemo(() => {
|
|
880
|
+
const picks = new Map();
|
|
881
|
+
messages.forEach((m, index) => {
|
|
882
|
+
const cards = shown.results.get(m.id);
|
|
883
|
+
if (!cards) return;
|
|
884
|
+
const later = messages.slice(index + 1).filter(next => next.role === 'user').map(next => next.content.trim());
|
|
885
|
+
const chosen = later.length ? cardPicks(cards, later) : {};
|
|
886
|
+
if (Object.keys(chosen).length) picks.set(m.id, JSON.stringify(chosen));
|
|
887
|
+
});
|
|
888
|
+
return picks;
|
|
889
|
+
}, [messages, shown]);
|
|
890
|
+
// A pick goes out as her reply, the way typed words do (`submit`). The kit then redraws the thread
|
|
891
|
+
// and the button that had the focus is gone, so a pick made from the keyboard leaves the focus on
|
|
892
|
+
// the composer, where the next words go (a tap on a phone does not: it would bring up the keyboard).
|
|
893
|
+
const replyFromCard = useCallback((text, keyboard) => {
|
|
894
|
+
submit(text);
|
|
895
|
+
if (!keyboard) return;
|
|
896
|
+
window.requestAnimationFrame(() => document.querySelector(`.cbh-chat textarea[placeholder="${COMPOSER_PLACEHOLDER}"]`)?.focus());
|
|
897
|
+
}, [submit]);
|
|
898
|
+
// Cards opened past their first rows. Kept here: the kit remounts a reply's extras on every
|
|
899
|
+
// streamed word, which would close them.
|
|
900
|
+
const [openCards, setOpenCards] = useState(() => new Set());
|
|
901
|
+
const toggleCard = useCallback(key => {
|
|
902
|
+
setOpenCards(before => {
|
|
903
|
+
const next = new Set(before);
|
|
904
|
+
if (!next.delete(key)) next.add(key);
|
|
905
|
+
return next;
|
|
906
|
+
});
|
|
907
|
+
}, []);
|
|
636
908
|
// Lucy's calls, under the reply of each turn that placed some (calls.ts), kept current while the
|
|
637
909
|
// chat is on screen (useCallLog).
|
|
638
910
|
const placedCards = useMemo(() => {
|
|
@@ -662,13 +934,21 @@ function ChoresChat({
|
|
|
662
934
|
const callsCardOf = useMemo(() => new Map(callsCards.map(card => [card.message, card])), [callsCards]);
|
|
663
935
|
const renderExtras = useCallback(message => {
|
|
664
936
|
const media = shown.media.get(message.id);
|
|
937
|
+
const results = shown.results.get(message.id);
|
|
665
938
|
const retry = renderTryAgain(message);
|
|
666
939
|
const card = callsCardOf.get(message.id);
|
|
667
940
|
// The calls card is the turn's own; any other surface the reply names is a link.
|
|
668
941
|
const others = (shown.surfaces.get(message.id) ?? []).filter(s => s.id !== PHONE_CALLS_SURFACE);
|
|
669
|
-
if (!media && !retry && !card && !others.length) return null;
|
|
942
|
+
if (!media && !results && !retry && !card && !others.length) return null;
|
|
670
943
|
return jsxs(Fragment, {
|
|
671
|
-
children: [
|
|
944
|
+
children: [results ? jsx(ResultCards, {
|
|
945
|
+
cards: results,
|
|
946
|
+
picks: picksByReply.get(message.id),
|
|
947
|
+
busy: busy,
|
|
948
|
+
open: openCards,
|
|
949
|
+
onToggle: toggleCard,
|
|
950
|
+
onReply: replyFromCard
|
|
951
|
+
}) : null, card ? jsx(CallsCard, {
|
|
672
952
|
calls: calls.byCard.get(card.message) ?? [],
|
|
673
953
|
open: card.openUntil > Date.now(),
|
|
674
954
|
kept: calls.kept,
|
|
@@ -682,19 +962,28 @@ function ChoresChat({
|
|
|
682
962
|
media: media
|
|
683
963
|
}) : null, retry]
|
|
684
964
|
});
|
|
685
|
-
}, [shown, renderTryAgain, callsCardOf, calls]);
|
|
965
|
+
}, [shown, renderTryAgain, callsCardOf, calls, picksByReply, busy, openCards, toggleCard, replyFromCard]);
|
|
686
966
|
// The panel's chores (chores.ts). The one whose question waits for an answer is the one the kit's
|
|
687
967
|
// question card above the composer belongs to.
|
|
688
968
|
const asking = useMemo(() => askingTurn(messages, asksQuestion), [messages]);
|
|
689
969
|
const list = useMemo(() => choreList(choreTurns, {
|
|
690
|
-
asking
|
|
691
|
-
|
|
970
|
+
asking,
|
|
971
|
+
waiting: queued
|
|
972
|
+
}), [choreTurns, asking, queued]);
|
|
692
973
|
// Still going without this page, after it was closed and opened again: the thread shows a reply
|
|
693
974
|
// that stops short, so the line above the composer says Lucy is on it.
|
|
694
975
|
const stillOn = useMemo(() => {
|
|
695
976
|
const here = new Set(messages.map(taskOf));
|
|
696
977
|
return list.working.filter(c => c.background && c.turns.some(turn => here.has(turn)));
|
|
697
978
|
}, [list, messages]);
|
|
979
|
+
// What a closed page left waiting goes once the chat opens, and one another tab sent leaves the
|
|
980
|
+
// queue as soon as its chore shows in the task store. A turn this page streams asks for the next
|
|
981
|
+
// message as it ends (`send`).
|
|
982
|
+
useEffect(() => {
|
|
983
|
+
if (queued.length) sendNext();
|
|
984
|
+
}, [choreTurns, queued, sendNext]);
|
|
985
|
+
// The strip's Cancel: that one never goes to Lucy.
|
|
986
|
+
const cancelQueued = useCallback(id => setQueue(queuedRef.current.filter(m => m.id !== id)), [setQueue]);
|
|
698
987
|
const closeChores = useCallback(() => {
|
|
699
988
|
setChoresOpen(false);
|
|
700
989
|
setOpenChore(null);
|
|
@@ -703,10 +992,13 @@ function ChoresChat({
|
|
|
703
992
|
setOpenChore(chore);
|
|
704
993
|
setChoresOpen(true);
|
|
705
994
|
}, []);
|
|
706
|
-
// Back to the landing: the
|
|
995
|
+
// Back to the landing: the panels go with the chat, rather than open again when it is back.
|
|
707
996
|
useEffect(() => {
|
|
708
|
-
if (hidden)
|
|
709
|
-
|
|
997
|
+
if (!hidden) return;
|
|
998
|
+
closeChores();
|
|
999
|
+
closeHistory();
|
|
1000
|
+
closeApps();
|
|
1001
|
+
}, [hidden, closeChores, closeHistory, closeApps]);
|
|
710
1002
|
return jsxs("div", {
|
|
711
1003
|
className: `cbh-chat fixed inset-0 z-[1000] flex-col bg-background text-foreground ${hidden ? 'hidden' : 'flex'}`,
|
|
712
1004
|
role: "region",
|
|
@@ -717,22 +1009,32 @@ function ChoresChat({
|
|
|
717
1009
|
children: jsx(AgentChat, {
|
|
718
1010
|
fullBleed: true,
|
|
719
1011
|
messages: shown.messages,
|
|
720
|
-
onSend:
|
|
1012
|
+
onSend: submit,
|
|
1013
|
+
draft: draft,
|
|
1014
|
+
onDraftChange: setDraft,
|
|
721
1015
|
busy: busy,
|
|
722
1016
|
queueWhileBusy: true,
|
|
723
1017
|
onStop: stopLucy,
|
|
724
1018
|
status: status,
|
|
725
|
-
placeholder:
|
|
1019
|
+
placeholder: COMPOSER_PLACEHOLDER,
|
|
726
1020
|
emptyContent: jsx(ChatWelcome, {
|
|
727
1021
|
onPick: pickStarter,
|
|
728
1022
|
onImessage: onImessage,
|
|
1023
|
+
onConnectApps: openApps,
|
|
729
1024
|
disabled: busy
|
|
730
1025
|
}),
|
|
731
1026
|
enableAttachments: false,
|
|
732
1027
|
renderMessageExtras: renderExtras,
|
|
733
|
-
beforeComposer: stillOn.length ?
|
|
734
|
-
|
|
735
|
-
|
|
1028
|
+
beforeComposer: stillOn.length || queued.length ? jsxs("div", {
|
|
1029
|
+
className: "flex flex-col gap-2",
|
|
1030
|
+
children: [stillOn.length ? jsx(StillWorking, {
|
|
1031
|
+
chores: stillOn,
|
|
1032
|
+
onOpen: () => openChores(stillOn.length === 1 ? stillOn[0].id : null)
|
|
1033
|
+
}) : null, queued.length ? jsx(HostQueuedMessages, {
|
|
1034
|
+
items: queued,
|
|
1035
|
+
onCancel: cancelQueued,
|
|
1036
|
+
onSendNow: busy ? stopAndSendNow : undefined
|
|
1037
|
+
}) : null]
|
|
736
1038
|
}) : undefined,
|
|
737
1039
|
footerNote: "Lucy asks before she pays or changes an account.",
|
|
738
1040
|
headerLead: jsxs("div", {
|
|
@@ -794,12 +1096,18 @@ function ChoresChat({
|
|
|
794
1096
|
className: "hidden sm:inline",
|
|
795
1097
|
children: "iMessage"
|
|
796
1098
|
})]
|
|
797
|
-
}) : null, jsx(
|
|
1099
|
+
}) : null, jsx(HistoryButton, {
|
|
1100
|
+
open: historyOpen,
|
|
1101
|
+
onClick: toggleHistory,
|
|
1102
|
+
buttonRef: historyButtonRef
|
|
1103
|
+
}), jsx(NewChatButton, {
|
|
798
1104
|
busy: busy,
|
|
799
1105
|
onNewChat: newChat
|
|
800
1106
|
}), jsx(AccountMenu, {
|
|
801
1107
|
email: email,
|
|
802
|
-
onSignOut: signOut
|
|
1108
|
+
onSignOut: signOut,
|
|
1109
|
+
onConnectApps: openApps,
|
|
1110
|
+
buttonRef: accountButtonRef
|
|
803
1111
|
})]
|
|
804
1112
|
})
|
|
805
1113
|
})
|
|
@@ -810,6 +1118,19 @@ function ChoresChat({
|
|
|
810
1118
|
anchor: choresButtonRef,
|
|
811
1119
|
selected: openChore,
|
|
812
1120
|
onSelect: setOpenChore
|
|
1121
|
+
}), jsx(HistoryPanel, {
|
|
1122
|
+
chats: pastChats,
|
|
1123
|
+
open: historyOpen && !hidden,
|
|
1124
|
+
busy: busy,
|
|
1125
|
+
onOpen: openPastChat,
|
|
1126
|
+
onDelete: deleteChat,
|
|
1127
|
+
onClose: closeHistory,
|
|
1128
|
+
anchor: historyButtonRef
|
|
1129
|
+
}), jsx(ConnectorsPanel, {
|
|
1130
|
+
open: appsOpen && !hidden,
|
|
1131
|
+
onClose: closeApps,
|
|
1132
|
+
appUrl: yantraAppUrl(),
|
|
1133
|
+
anchor: accountButtonRef
|
|
813
1134
|
}), jsx(ChatTour, {
|
|
814
1135
|
open: tour.open && !hidden,
|
|
815
1136
|
firstName: firstName,
|