@blocksdiy/react-common 1.65.0 → 1.67.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/dist/components/agent-chat.d.ts.map +1 -1
- package/dist/components/agent-chat.js +3 -0
- package/dist/components/new-agent-chat.d.ts +5 -0
- package/dist/components/new-agent-chat.d.ts.map +1 -1
- package/dist/components/new-agent-chat.js +190 -41
- package/dist/utils/live-turn.d.ts +83 -0
- package/dist/utils/live-turn.d.ts.map +1 -0
- package/dist/utils/live-turn.js +71 -0
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-chat.d.ts","sourceRoot":"","sources":["../../src/components/agent-chat.tsx"],"names":[],"mappings":"AASA,OAAO,EAAiB,SAAS,EAAE,cAAc,EAAwD,MAAM,OAAO,CAAC;AAEvH,OAAO,EAAgB,KAAK,gBAAgB,EAA4B,MAAM,yBAAyB,CAAC;AACxG,OAAO,EAAiB,KAAK,UAAU,EAAE,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"agent-chat.d.ts","sourceRoot":"","sources":["../../src/components/agent-chat.tsx"],"names":[],"mappings":"AASA,OAAO,EAAiB,SAAS,EAAE,cAAc,EAAwD,MAAM,OAAO,CAAC;AAEvH,OAAO,EAAgB,KAAK,gBAAgB,EAA4B,MAAM,yBAAyB,CAAC;AACxG,OAAO,EAAiB,KAAK,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAgBzE,MAAM,WAAW,UAAU;IACzB,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAqBD,MAAM,MAAM,WAAW,GAAG,OAAO,GAAG,IAAI,CAAC;AACzC,KAAK,WAAW,GAAG,UAAU,GAAG,MAAM,GAAG,qBAAqB,CAAC;AAE/D;;;;;;GAMG;AACH,MAAM,WAAW,oBAAoB;IACnC,EAAE,EAAE,MAAM,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,oBAAoB,CAAC,EACnC,OAAe,EACf,MAAM,EACN,KAAK,EACL,GAAG,KAAK,EACT,EAAE,KAAK,CAAC,cAAc,CAAC,KAAK,CAAC,GAAG,yBAAyB,+BAmBzD"}
|
|
@@ -5,6 +5,9 @@ import { WorkflowRequest } from "@blocksdiy/blocks-client-api/workflowService";
|
|
|
5
5
|
import { createContext, useCallback, useContext, useEffect, useRef, useState } from "react";
|
|
6
6
|
import { useVoiceCall } from "../hooks/use-voice-call.js";
|
|
7
7
|
import { ComposeRender } from "../utils/compose-render.js";
|
|
8
|
+
// The react-agent chat runtime (the ChatAgentCall workflow). It stays exported only because built
|
|
9
|
+
// apps load `@blocksdiy/react-common/agent-chat` at run time until they are rebuilt: the registry's
|
|
10
|
+
// `agent-chat` item runs every agent on `./new-agent-chat`. Build nothing new on it.
|
|
8
11
|
/* public decouple - blocks common */
|
|
9
12
|
const CHAT_AGENT_HISTORY_TABLE_BLOCK_ID = "688ed13adefd8b565c779b8e";
|
|
10
13
|
const CHAT_AGENT_CALL_ACTION_BLOCK_ID = "688ed4d77b454b1fdaf5cf2d";
|
|
@@ -107,6 +107,11 @@ export interface AgentChatContextValue {
|
|
|
107
107
|
/** A tool step's title: the tool's display name when the server stamped one, else its name, in words. */
|
|
108
108
|
toolTitleFor?: (toolCallId: string, toolName: string) => string;
|
|
109
109
|
stopGeneration: () => void;
|
|
110
|
+
/**
|
|
111
|
+
* A running reply Stop applies to: this tab's own, or a followed one a chat started (never a
|
|
112
|
+
* workflow's or a reminder's), and only with the live turn stream on.
|
|
113
|
+
*/
|
|
114
|
+
canStop?: boolean;
|
|
110
115
|
addAttachments: (attachments: Attachment[]) => void;
|
|
111
116
|
removeAttachment: (url: string) => void;
|
|
112
117
|
clearAttachments: () => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"new-agent-chat.d.ts","sourceRoot":"","sources":["../../src/components/new-agent-chat.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAkB,KAAK,OA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|
|
|
12
12
|
import { ComposeRender } from "../utils/compose-render.js";
|
|
13
13
|
import { buildArmedMessageContent, userTextOfContent } from "../utils/composer-message.js";
|
|
14
14
|
import { forwardedLegacyChatId, pinnedLegacyChatThreadId } from "../utils/legacy-chat-thread-id.js";
|
|
15
|
+
import { buildStopEnvelope, canStop, isThreadBusyError, liveAfterTerminal, readLiveTurnEvent, shouldConnectForRun, shouldReconnectAfterStream, stopRunIdOf, streamRunIdOf, } from "../utils/live-turn.js";
|
|
15
16
|
import { claimRunInput, EMPTY_MESSAGE_RUN_IDS, EMPTY_RUN_STARTED_AT, findMessageGroupElement, mergeEntries, MESSAGE_IDS_ATTRIBUTE, messageIdsOfRun, readMessageRunIdsEvent, readRunStartedAtEvent, } from "../utils/message-run-ids.js";
|
|
16
17
|
import { scheduledTriggersByMessageId } from "../utils/scheduled-trigger.js";
|
|
17
18
|
export { useTextGrowthAnimating } from "../hooks/text-growth-animation.js";
|
|
@@ -248,24 +249,6 @@ const ChatInitializer = ({ agentBlock, agentChatBlock, token, appId, components,
|
|
|
248
249
|
token ?? "",
|
|
249
250
|
appId ?? "",
|
|
250
251
|
].join("|");
|
|
251
|
-
// Readiness latch. CopilotKit's `isAvailable` deadlocks false when a replayed
|
|
252
|
-
// transcript ends with an unanswered frontend HITL tool call — see
|
|
253
|
-
// `isConnectParkedOnPendingToolCall`. So also treat "parked but loaded" as
|
|
254
|
-
// ready, and latch it: once ready we stay ready for the session, otherwise
|
|
255
|
-
// typing past the question (which empties the pending set) would re-lock the
|
|
256
|
-
// composer while `isAvailable` is still parked-false. Keyed to `initKey` so a
|
|
257
|
-
// swap resets readiness. We skip promotion on the render the key changes on,
|
|
258
|
-
// because `isCopilotAgentAvailable`/`copilotMessages` still hold the previous
|
|
259
|
-
// session's values until CopilotKit's connect effect runs post-commit.
|
|
260
|
-
const agentReadyLatchRef = useRef({ key: initKey, ready: false });
|
|
261
|
-
const initKeyChanged = agentReadyLatchRef.current.key !== initKey;
|
|
262
|
-
if (initKeyChanged) {
|
|
263
|
-
agentReadyLatchRef.current = { key: initKey, ready: false };
|
|
264
|
-
}
|
|
265
|
-
if (!initKeyChanged && (isCopilotAgentAvailable || isConnectParkedOnPendingToolCall(copilotMessages))) {
|
|
266
|
-
agentReadyLatchRef.current.ready = true;
|
|
267
|
-
}
|
|
268
|
-
const isAgentReady = agentReadyLatchRef.current.ready;
|
|
269
252
|
const { copilotkit } = useCopilotKit();
|
|
270
253
|
const renderToolCall = useRenderToolCall();
|
|
271
254
|
const messageById = useMemo(() => {
|
|
@@ -301,6 +284,58 @@ const ChatInitializer = ({ agentBlock, agentChatBlock, token, appId, components,
|
|
|
301
284
|
const [runStartedAt, setRunStartedAt] = useState(EMPTY_RUN_STARTED_AT);
|
|
302
285
|
const liveRunRef = useRef(null);
|
|
303
286
|
const ownRunIdsRef = useRef(new Set());
|
|
287
|
+
// The live turn stream (flag on): what the connect said about the thread's active turn. A
|
|
288
|
+
// flag-off server sends no such event, so `liveTurn` stays null and every branch stays off.
|
|
289
|
+
const [liveTurn, setLiveTurn] = useState(null);
|
|
290
|
+
const liveTurnRef = useRef(null);
|
|
291
|
+
liveTurnRef.current = liveTurn;
|
|
292
|
+
// Readiness latch. CopilotKit's `isAvailable` deadlocks false when a replayed
|
|
293
|
+
// transcript ends with an unanswered frontend HITL tool call — see
|
|
294
|
+
// `isConnectParkedOnPendingToolCall`. So also treat "parked but loaded" as
|
|
295
|
+
// ready, and latch it: once ready we stay ready for the session, otherwise
|
|
296
|
+
// typing past the question (which empties the pending set) would re-lock the
|
|
297
|
+
// composer while `isAvailable` is still parked-false. Keyed to `initKey` so a
|
|
298
|
+
// swap resets readiness. We skip promotion on the render the key changes on,
|
|
299
|
+
// because `isCopilotAgentAvailable`/`copilotMessages` still hold the previous
|
|
300
|
+
// session's values until CopilotKit's connect effect runs post-commit.
|
|
301
|
+
// A tab that joined a running turn is ready too: its connect streams until the turn ends, so
|
|
302
|
+
// `isAvailable` stays false while the tab already shows the reply and may stop it.
|
|
303
|
+
const agentReadyLatchRef = useRef({ key: initKey, ready: false });
|
|
304
|
+
const initKeyChanged = agentReadyLatchRef.current.key !== initKey;
|
|
305
|
+
if (initKeyChanged) {
|
|
306
|
+
agentReadyLatchRef.current = { key: initKey, ready: false };
|
|
307
|
+
}
|
|
308
|
+
if (!initKeyChanged &&
|
|
309
|
+
(isCopilotAgentAvailable || isConnectParkedOnPendingToolCall(copilotMessages) || Boolean(liveTurn?.runId))) {
|
|
310
|
+
agentReadyLatchRef.current.ready = true;
|
|
311
|
+
}
|
|
312
|
+
const isAgentReady = agentReadyLatchRef.current.ready;
|
|
313
|
+
const ownRunInFlightRef = useRef(false);
|
|
314
|
+
// The run each stream last started (a connect's own history run first, then the followed
|
|
315
|
+
// turn's), and the runs a RUN_FINISHED / RUN_ERROR closed.
|
|
316
|
+
const streamRunIdRef = useRef(null);
|
|
317
|
+
const terminalRunIdsRef = useRef(new Set());
|
|
318
|
+
// Whether the stream now ending delivered its RUN_STARTED: a request that failed outright did not.
|
|
319
|
+
const streamStartedRef = useRef(false);
|
|
320
|
+
const connectInFlightRef = useRef(false);
|
|
321
|
+
const lastConnectedForRunIdRef = useRef(null);
|
|
322
|
+
const threadBusyRefusedRef = useRef(false);
|
|
323
|
+
// One connect to watch the thread's running turn; `runId` is the run it answers for.
|
|
324
|
+
const followRunningTurn = useCallback((runId) => {
|
|
325
|
+
if (!copilotAgent || connectInFlightRef.current) {
|
|
326
|
+
return;
|
|
327
|
+
}
|
|
328
|
+
connectInFlightRef.current = true;
|
|
329
|
+
if (runId) {
|
|
330
|
+
lastConnectedForRunIdRef.current = runId;
|
|
331
|
+
}
|
|
332
|
+
void copilotkit
|
|
333
|
+
.connectAgent({ agent: copilotAgent })
|
|
334
|
+
.catch(() => undefined)
|
|
335
|
+
.finally(() => {
|
|
336
|
+
connectInFlightRef.current = false;
|
|
337
|
+
});
|
|
338
|
+
}, [copilotAgent, copilotkit]);
|
|
304
339
|
// Paired once, when the pause arrives: while the next run streams, a sub-agent's own
|
|
305
340
|
// calls arrive as the parent's and would re-pair the request with them -- a second
|
|
306
341
|
// card on the parent's call.
|
|
@@ -328,6 +363,20 @@ const ChatInitializer = ({ agentBlock, agentChatBlock, token, appId, components,
|
|
|
328
363
|
if (!copilotAgent) {
|
|
329
364
|
return;
|
|
330
365
|
}
|
|
366
|
+
const threadOfStream = () => copilotAgent.threadId;
|
|
367
|
+
const endRun = (runId) => {
|
|
368
|
+
if (!runId) {
|
|
369
|
+
return;
|
|
370
|
+
}
|
|
371
|
+
terminalRunIdsRef.current.add(runId);
|
|
372
|
+
const live = liveTurnRef.current;
|
|
373
|
+
if (live?.runId === runId) {
|
|
374
|
+
// Answered for: the row still names it until the settle arrives, so no doorbell.
|
|
375
|
+
lastConnectedForRunIdRef.current = runId;
|
|
376
|
+
liveTurnRef.current = liveAfterTerminal(live, runId);
|
|
377
|
+
setLiveTurn(liveTurnRef.current);
|
|
378
|
+
}
|
|
379
|
+
};
|
|
331
380
|
const claimLive = (messageId) => {
|
|
332
381
|
const run = liveRunRef.current;
|
|
333
382
|
if (!run) {
|
|
@@ -350,7 +399,11 @@ const ChatInitializer = ({ agentBlock, agentChatBlock, token, appId, components,
|
|
|
350
399
|
onRunStartedEvent: ({ event, messages }) => {
|
|
351
400
|
liveRunRef.current = { runId: event.runId, startedAt: event.timestamp ?? Date.now(), input: messages };
|
|
352
401
|
ownRunIdsRef.current.add(event.runId);
|
|
402
|
+
streamRunIdRef.current = event.runId;
|
|
403
|
+
streamStartedRef.current = true;
|
|
353
404
|
},
|
|
405
|
+
onRunFinishedEvent: ({ event }) => endRun(event.runId),
|
|
406
|
+
onRunErrorEvent: () => endRun(streamRunIdRef.current),
|
|
354
407
|
onTextMessageStartEvent: ({ event }) => claimLive(event.messageId),
|
|
355
408
|
onToolCallStartEvent: ({ event }) => claimLive(event.parentMessageId ?? event.toolCallId),
|
|
356
409
|
onRunFinalized: () => {
|
|
@@ -358,8 +411,36 @@ const ChatInitializer = ({ agentBlock, agentChatBlock, token, appId, components,
|
|
|
358
411
|
// The agent's own field, which @ag-ui/client has set on RUN_FINISHED by now (pinned
|
|
359
412
|
// in agui-interrupts.spec) -- live runs and connects alike; a RUN_ERROR leaves it.
|
|
360
413
|
setInterruptRequests(requestsOf(openInterruptsOf(copilotAgent), copilotAgent.messages));
|
|
414
|
+
// A stream that closed with no terminal event for the turn it showed (the 400 s
|
|
415
|
+
// self-close, a restart, a drop): watch the turn again.
|
|
416
|
+
const streamStarted = streamStartedRef.current;
|
|
417
|
+
streamStartedRef.current = false;
|
|
418
|
+
const streamRunId = streamRunIdOf({
|
|
419
|
+
ownRunInFlight: ownRunInFlightRef.current,
|
|
420
|
+
lastStartedRunId: streamRunIdRef.current,
|
|
421
|
+
live: liveTurnRef.current,
|
|
422
|
+
});
|
|
423
|
+
streamRunIdRef.current = null;
|
|
424
|
+
if (shouldReconnectAfterStream({
|
|
425
|
+
liveEnabled: liveTurnRef.current?.enabled === true,
|
|
426
|
+
streamRunId,
|
|
427
|
+
sawTerminalFor: terminalRunIdsRef.current,
|
|
428
|
+
streamStarted,
|
|
429
|
+
})) {
|
|
430
|
+
const threadId = threadOfStream();
|
|
431
|
+
setTimeout(() => {
|
|
432
|
+
if (threadOfStream() === threadId && !copilotAgent.isRunning) {
|
|
433
|
+
followRunningTurn(streamRunId);
|
|
434
|
+
}
|
|
435
|
+
}, 0);
|
|
436
|
+
}
|
|
361
437
|
},
|
|
362
438
|
onCustomEvent: ({ event }) => {
|
|
439
|
+
const live = readLiveTurnEvent(event);
|
|
440
|
+
if (live) {
|
|
441
|
+
liveTurnRef.current = live;
|
|
442
|
+
setLiveTurn(live);
|
|
443
|
+
}
|
|
363
444
|
const runIds = readMessageRunIdsEvent(event);
|
|
364
445
|
if (runIds) {
|
|
365
446
|
setRunIdByMessageId((previous) => mergeEntries(previous, runIds));
|
|
@@ -374,14 +455,15 @@ const ChatInitializer = ({ agentBlock, agentChatBlock, token, appId, components,
|
|
|
374
455
|
unsubscribe();
|
|
375
456
|
liveRunRef.current = null;
|
|
376
457
|
};
|
|
377
|
-
}, [copilotAgent]);
|
|
458
|
+
}, [copilotAgent, followRunningTurn]);
|
|
378
459
|
// Mirror `currentThreadId` onto the agent instance — the `<CopilotKit>`
|
|
379
460
|
// prop only feeds React context, but `agent.threadId` is what hits the
|
|
380
461
|
// wire and the LangGraph checkpoint. `<CopilotChat>` does this for you;
|
|
381
462
|
// we use the headless hook so we do it ourselves. Layout-effect timing
|
|
382
463
|
// is required to beat the library's connect-on-mount/on-swap effect.
|
|
383
|
-
// A swap
|
|
384
|
-
//
|
|
464
|
+
// A swap never stops a run: the connect effect's cleanup only detaches this client's
|
|
465
|
+
// reader. With the live turn stream on, the turn keeps going on the server and a later
|
|
466
|
+
// connect watches it again; with it off, the run still completes server-side as before.
|
|
385
467
|
useIsomorphicLayoutEffect(() => {
|
|
386
468
|
if (copilotAgent && currentThreadId) {
|
|
387
469
|
copilotAgent.threadId = currentThreadId;
|
|
@@ -399,6 +481,7 @@ const ChatInitializer = ({ agentBlock, agentChatBlock, token, appId, components,
|
|
|
399
481
|
const isRunningElsewhere = runningElsewhereRunId !== null && !ownRunInFlight && !ownRunIdsRef.current.has(runningElsewhereRunId);
|
|
400
482
|
const isRunningElsewhereRef = useRef(isRunningElsewhere);
|
|
401
483
|
isRunningElsewhereRef.current = isRunningElsewhere;
|
|
484
|
+
ownRunInFlightRef.current = ownRunInFlight;
|
|
402
485
|
const conversationKey = currentThreadId ?? "";
|
|
403
486
|
const prevConversationKeyRef = useRef(conversationKey);
|
|
404
487
|
useIsomorphicLayoutEffect(() => {
|
|
@@ -414,6 +497,11 @@ const ChatInitializer = ({ agentBlock, agentChatBlock, token, appId, components,
|
|
|
414
497
|
setComposerMessageMeta(null);
|
|
415
498
|
resetInterrupts();
|
|
416
499
|
setOwnRunInFlight(false);
|
|
500
|
+
setLiveTurn(null);
|
|
501
|
+
streamRunIdRef.current = null;
|
|
502
|
+
terminalRunIdsRef.current.clear();
|
|
503
|
+
lastConnectedForRunIdRef.current = null;
|
|
504
|
+
connectInFlightRef.current = false;
|
|
417
505
|
const detachable = copilotAgent;
|
|
418
506
|
const drained = detachable?.detachActiveRun?.();
|
|
419
507
|
if (drained) {
|
|
@@ -430,6 +518,20 @@ const ChatInitializer = ({ agentBlock, agentChatBlock, token, appId, components,
|
|
|
430
518
|
const canSendMessage = Boolean(agentChatBlock && agentChat && agent && isConfigLoaded && isAgentReady && !isAgentRunning && !isRunningElsewhere);
|
|
431
519
|
const isFetchingMessages = !isConfigLoaded || (!isAgentReady && copilotMessages.length === 0);
|
|
432
520
|
const isThinking = (isAgentRunning || isRunningElsewhere) && !isFetchingMessages && isAgentReady;
|
|
521
|
+
// Doorbell: the row names a run this tab neither started nor follows, so connect and
|
|
522
|
+
// stream it live (replaces thinking until the end, then a reload).
|
|
523
|
+
useEffect(() => {
|
|
524
|
+
if (shouldConnectForRun({
|
|
525
|
+
liveEnabled: liveTurn?.enabled === true,
|
|
526
|
+
runningRunId: runningElsewhereRunId,
|
|
527
|
+
followingRunId: liveTurn?.runId ?? null,
|
|
528
|
+
lastConnectedForRunId: lastConnectedForRunIdRef.current,
|
|
529
|
+
ownRunIds: ownRunIdsRef.current,
|
|
530
|
+
connectInFlight: isAgentRunning || ownRunInFlight || connectInFlightRef.current,
|
|
531
|
+
})) {
|
|
532
|
+
followRunningTurn(runningElsewhereRunId);
|
|
533
|
+
}
|
|
534
|
+
}, [liveTurn, runningElsewhereRunId, isAgentRunning, ownRunInFlight, followRunningTurn]);
|
|
433
535
|
const runAgentWithRetry = useCallback(async (agentToRun, messageCountAtRunStart, forwardedProps, resume, withoutSend = false) => {
|
|
434
536
|
// A run elsewhere is on this conversation's checkpoint too: ours would race it.
|
|
435
537
|
if (agentToRun.isRunning || isRunningElsewhereRef.current) {
|
|
@@ -440,14 +542,21 @@ const ChatInitializer = ({ agentBlock, agentChatBlock, token, appId, components,
|
|
|
440
542
|
setOwnRunsWithoutSend((count) => count + 1);
|
|
441
543
|
}
|
|
442
544
|
let finished = false;
|
|
545
|
+
threadBusyRefusedRef.current = false;
|
|
443
546
|
const runAgentAndThrowError = async () => {
|
|
444
547
|
let runEventError;
|
|
445
548
|
const { unsubscribe } = agentToRun.subscribe({
|
|
446
549
|
onRunFailed: (event) => {
|
|
447
550
|
runEventError = event;
|
|
448
551
|
},
|
|
449
|
-
onRunErrorEvent: (
|
|
450
|
-
|
|
552
|
+
onRunErrorEvent: (params) => {
|
|
553
|
+
// A refused send on a busy thread is not a failure: the sender puts its text back.
|
|
554
|
+
const { event } = params;
|
|
555
|
+
if (isThreadBusyError(event)) {
|
|
556
|
+
threadBusyRefusedRef.current = true;
|
|
557
|
+
return;
|
|
558
|
+
}
|
|
559
|
+
runEventError = params;
|
|
451
560
|
},
|
|
452
561
|
onRunFinishedEvent: () => {
|
|
453
562
|
finished = true;
|
|
@@ -503,14 +612,15 @@ const ChatInitializer = ({ agentBlock, agentChatBlock, token, appId, components,
|
|
|
503
612
|
reconnected = true;
|
|
504
613
|
}
|
|
505
614
|
}
|
|
506
|
-
// A reconnected run did not take effect as sent: callers must not record it as done.
|
|
507
|
-
return !reconnected;
|
|
615
|
+
// A reconnected or refused run did not take effect as sent: callers must not record it as done.
|
|
616
|
+
return !reconnected && !threadBusyRefusedRef.current;
|
|
508
617
|
}, [copilotkit, currentThreadId, resetInterrupts, readChatContext]);
|
|
509
618
|
const sendMessage = useCallback(async (message) => {
|
|
510
619
|
if (!canSendMessage || !copilotAgent || copilotAgent.isRunning || isRunningElsewhereRef.current) {
|
|
511
620
|
return;
|
|
512
621
|
}
|
|
513
|
-
|
|
622
|
+
const sentMessageId = generateId();
|
|
623
|
+
copilotAgent.addMessage({ ...message, id: sentMessageId, role: "user" });
|
|
514
624
|
if (onUserMessageSent) {
|
|
515
625
|
onUserMessageSent(userTextOfContent(message.content), message);
|
|
516
626
|
}
|
|
@@ -524,6 +634,13 @@ const ChatInitializer = ({ agentBlock, agentChatBlock, token, appId, components,
|
|
|
524
634
|
const interrupts = openInterruptsOf(copilotAgent);
|
|
525
635
|
if (interrupts.length === 0) {
|
|
526
636
|
await runAgentWithRetry(copilotAgent, copilotAgent.messages.length);
|
|
637
|
+
if (threadBusyRefusedRef.current) {
|
|
638
|
+
// Refused: a turn is already running on the thread. Give the text back and watch it.
|
|
639
|
+
threadBusyRefusedRef.current = false;
|
|
640
|
+
copilotAgent.setMessages?.(copilotAgent.messages.filter((existing) => existing.id !== sentMessageId));
|
|
641
|
+
setPrompt(userTextOfContent(message.content));
|
|
642
|
+
followRunningTurn(null);
|
|
643
|
+
}
|
|
527
644
|
return;
|
|
528
645
|
}
|
|
529
646
|
const requests = requestsOf(interrupts, copilotAgent.messages);
|
|
@@ -546,7 +663,7 @@ const ChatInitializer = ({ agentBlock, agentChatBlock, token, appId, components,
|
|
|
546
663
|
}
|
|
547
664
|
setInterruptAnswers(EMPTY_ANSWERS);
|
|
548
665
|
}
|
|
549
|
-
}, [canSendMessage, copilotAgent, runAgentWithRetry, onUserMessageSent]);
|
|
666
|
+
}, [canSendMessage, copilotAgent, runAgentWithRetry, onUserMessageSent, followRunningTurn]);
|
|
550
667
|
const reloadMessages = useCallback(async () => {
|
|
551
668
|
if (!copilotAgent || copilotAgent.isRunning) {
|
|
552
669
|
return;
|
|
@@ -669,10 +786,39 @@ const ChatInitializer = ({ agentBlock, agentChatBlock, token, appId, components,
|
|
|
669
786
|
throw new Error("answerInterrupt: a run was already in flight; answer not sent");
|
|
670
787
|
}
|
|
671
788
|
}, [copilotAgent, runAgentWithRetry, submitInterruptAnswers]);
|
|
789
|
+
const stoppable = canStop({ ownRunInFlight, following: liveTurn });
|
|
790
|
+
// The run body's thread fields, from the same values a run sends, to the runtime URL with
|
|
791
|
+
// the headers CopilotKit uses. Fire and forget: a failed stop request is only logged.
|
|
792
|
+
const postStopEnvelope = useCallback(() => {
|
|
793
|
+
const runId = stopRunIdOf({ ownRunInFlight, lastStartedRunId: streamRunIdRef.current, live: liveTurn });
|
|
794
|
+
if (!copilotAgent?.threadId || !runId || !copilotkit.runtimeUrl) {
|
|
795
|
+
return;
|
|
796
|
+
}
|
|
797
|
+
const envelope = buildStopEnvelope({
|
|
798
|
+
threadId: copilotAgent.threadId,
|
|
799
|
+
runId,
|
|
800
|
+
forwardedProps: { ...copilotkit.properties, chatContext: readChatContext() },
|
|
801
|
+
});
|
|
802
|
+
fetch(copilotkit.runtimeUrl, {
|
|
803
|
+
method: "POST",
|
|
804
|
+
headers: { ...copilotkit.headers, "Content-Type": "application/json" },
|
|
805
|
+
body: JSON.stringify(envelope),
|
|
806
|
+
...(copilotkit.credentials ? { credentials: copilotkit.credentials } : {}),
|
|
807
|
+
}).catch((error) => {
|
|
808
|
+
console.warn("agent stop request failed", error);
|
|
809
|
+
});
|
|
810
|
+
}, [copilotAgent, copilotkit, liveTurn, ownRunInFlight, readChatContext]);
|
|
672
811
|
const stopGeneration = useCallback(() => {
|
|
812
|
+
if (liveTurn?.enabled) {
|
|
813
|
+
if (!stoppable) {
|
|
814
|
+
return;
|
|
815
|
+
}
|
|
816
|
+
// Closing the stream no longer stops a turn: ask the server, before the reader goes.
|
|
817
|
+
postStopEnvelope();
|
|
818
|
+
}
|
|
673
819
|
copilotStopGeneration();
|
|
674
820
|
copilotAgent?.abortRun?.();
|
|
675
|
-
}, [copilotAgent, copilotStopGeneration]);
|
|
821
|
+
}, [copilotAgent, copilotStopGeneration, liveTurn, stoppable, postStopEnvelope]);
|
|
676
822
|
const initKeyRef = useRef(null);
|
|
677
823
|
// Guard against re-firing the initial prompt across re-renders of the
|
|
678
824
|
// post-connect effect. Reset whenever the init key changes (thread
|
|
@@ -944,6 +1090,7 @@ const ChatInitializer = ({ agentBlock, agentChatBlock, token, appId, components,
|
|
|
944
1090
|
approvalCardsFor,
|
|
945
1091
|
toolTitleFor,
|
|
946
1092
|
stopGeneration,
|
|
1093
|
+
canStop: stoppable,
|
|
947
1094
|
addAttachments,
|
|
948
1095
|
removeAttachment,
|
|
949
1096
|
clearAttachments,
|
|
@@ -1382,26 +1529,28 @@ export function AgentChatInput({ asChild = false, render, onChange, onKeyDown, o
|
|
|
1382
1529
|
: onDrop, "data-slot": "agent-chat-input", ...props }));
|
|
1383
1530
|
}
|
|
1384
1531
|
export function AgentChatSendTrigger({ asChild = false, render, onClick, disabled, ...props }) {
|
|
1385
|
-
const { attachments, prompt, isThinking, isAgentReady, isFetchingMessages, sendFromInputs, composerMessageMeta,
|
|
1386
|
-
|
|
1387
|
-
|
|
1532
|
+
const { attachments, prompt, isThinking, isAgentReady, isFetchingMessages, sendFromInputs, composerMessageMeta, stopGeneration, canStop, } = useAgentChat();
|
|
1533
|
+
// While a reply Stop applies to runs, the send button stops it instead.
|
|
1534
|
+
const stops = isThinking && canStop === true;
|
|
1388
1535
|
const isDisabled = Boolean(disabled ||
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1536
|
+
(!stops &&
|
|
1537
|
+
(isThinking ||
|
|
1538
|
+
!isAgentReady ||
|
|
1539
|
+
isFetchingMessages ||
|
|
1540
|
+
!hasSendableInput(prompt, attachments, composerMessageMeta))));
|
|
1393
1541
|
return (_jsx(ComposeRender, { render: render, asChild: asChild, defaultTag: "button", onClick: (e) => {
|
|
1394
1542
|
if (isDisabled) {
|
|
1395
1543
|
e.preventDefault();
|
|
1396
1544
|
return;
|
|
1397
1545
|
}
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1546
|
+
if (stops) {
|
|
1547
|
+
stopGeneration();
|
|
1548
|
+
}
|
|
1549
|
+
else {
|
|
1550
|
+
sendFromInputs();
|
|
1551
|
+
}
|
|
1403
1552
|
onClick?.(e);
|
|
1404
|
-
}, disabled: isDisabled, "data-slot": "agent-chat-send-trigger", ...props }));
|
|
1553
|
+
}, disabled: isDisabled, "data-slot": "agent-chat-send-trigger", "data-state": stops ? "stop" : "send", ...props }));
|
|
1405
1554
|
}
|
|
1406
1555
|
export function AgentChatAttachmentTrigger({ asChild = false, render, onClick, disabled, accept, multiple = true, ...props }) {
|
|
1407
1556
|
const { isThinking, isAgentReady, isFetchingMessages, addAttachments, agentChat } = useAgentChat();
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The chat's side of the live turn stream.
|
|
3
|
+
*
|
|
4
|
+
* With the server flag on, every `agent/connect` opens with one CUSTOM event,
|
|
5
|
+
* `blocks.live_turn`, and then streams the thread's active turn live in the same response.
|
|
6
|
+
* With the flag off the server sends none of this, so `liveEnabled` stays false and every
|
|
7
|
+
* decision below answers "do nothing".
|
|
8
|
+
*/
|
|
9
|
+
export declare const LIVE_TURN_EVENT_NAME = "blocks.live_turn";
|
|
10
|
+
/** The RUN_ERROR code of a send refused because a turn is already running on the thread. */
|
|
11
|
+
export declare const THREAD_BUSY_ERROR_CODE = "thread_busy";
|
|
12
|
+
export type LiveTurnInfo = {
|
|
13
|
+
enabled: boolean;
|
|
14
|
+
runId?: string;
|
|
15
|
+
startedBy?: "chat" | "server";
|
|
16
|
+
};
|
|
17
|
+
/** The payload of the connect's live-turn CUSTOM event, or null for any other event. */
|
|
18
|
+
export declare const readLiveTurnEvent: (event: {
|
|
19
|
+
type: string;
|
|
20
|
+
name?: string;
|
|
21
|
+
value?: unknown;
|
|
22
|
+
}) => LiveTurnInfo | null;
|
|
23
|
+
/**
|
|
24
|
+
* Whether the thread row's running run (the doorbell) calls for a connect to watch it:
|
|
25
|
+
* one this tab neither follows nor started, that no connect has answered for yet.
|
|
26
|
+
*/
|
|
27
|
+
export declare const shouldConnectForRun: (args: {
|
|
28
|
+
liveEnabled: boolean;
|
|
29
|
+
runningRunId: string | null;
|
|
30
|
+
followingRunId: string | null;
|
|
31
|
+
lastConnectedForRunId: string | null;
|
|
32
|
+
ownRunIds: ReadonlySet<string>;
|
|
33
|
+
connectInFlight: boolean;
|
|
34
|
+
}) => boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Whether a run or connect stream that just ended should be followed by one more connect: it
|
|
37
|
+
* showed a running turn (this tab's send, or one the server named) and ended with no terminal
|
|
38
|
+
* event for it -- the 400 s self-close, a pod restart, a dropped network. A connect for a turn
|
|
39
|
+
* that has finished meanwhile names none, so it is not followed again. A stream that never
|
|
40
|
+
* started (the server unreachable) is not retried, or an outage would loop.
|
|
41
|
+
*/
|
|
42
|
+
export declare const shouldReconnectAfterStream: (args: {
|
|
43
|
+
liveEnabled: boolean;
|
|
44
|
+
streamRunId: string | null;
|
|
45
|
+
sawTerminalFor: ReadonlySet<string>;
|
|
46
|
+
streamStarted: boolean;
|
|
47
|
+
}) => boolean;
|
|
48
|
+
/**
|
|
49
|
+
* Stop is for this tab's own run, or a followed turn a chat started (never workflow, reminder,
|
|
50
|
+
* ...), and only with the live turn stream on: only then does the server stop the turn itself.
|
|
51
|
+
*/
|
|
52
|
+
export declare const canStop: (args: {
|
|
53
|
+
ownRunInFlight: boolean;
|
|
54
|
+
following: LiveTurnInfo | null;
|
|
55
|
+
}) => boolean;
|
|
56
|
+
export declare const isThreadBusyError: (event: {
|
|
57
|
+
type: string;
|
|
58
|
+
code?: string;
|
|
59
|
+
}) => boolean;
|
|
60
|
+
/** The `agent/stop` request: the run body's thread fields only, none of its content. */
|
|
61
|
+
export declare const buildStopEnvelope: (runBody: Record<string, unknown>) => {
|
|
62
|
+
method: "agent/stop";
|
|
63
|
+
body: Record<string, unknown>;
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* The run a stream that just ended is judged by. A tab's own send streams under its own run
|
|
67
|
+
* id; a connect body carries its own id for the history replay (RUN_STARTED/RUN_FINISHED),
|
|
68
|
+
* followed by the live turn's events, so a followed stream is judged by the live turn's id.
|
|
69
|
+
*/
|
|
70
|
+
export declare const streamRunIdOf: (args: {
|
|
71
|
+
ownRunInFlight: boolean;
|
|
72
|
+
lastStartedRunId: string | null;
|
|
73
|
+
live: LiveTurnInfo | null;
|
|
74
|
+
}) => string | null;
|
|
75
|
+
/** The run a stop is for: the tab's own run, else the followed turn (never a connect's id). */
|
|
76
|
+
export declare const stopRunIdOf: (args: {
|
|
77
|
+
ownRunInFlight: boolean;
|
|
78
|
+
lastStartedRunId: string | null;
|
|
79
|
+
live: LiveTurnInfo | null;
|
|
80
|
+
}) => string | null;
|
|
81
|
+
/** After a terminal event for `runId`: a followed turn that just ended is no longer followed. */
|
|
82
|
+
export declare const liveAfterTerminal: (live: LiveTurnInfo | null, runId: string | null) => LiveTurnInfo | null;
|
|
83
|
+
//# sourceMappingURL=live-turn.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"live-turn.d.ts","sourceRoot":"","sources":["../../src/utils/live-turn.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,eAAO,MAAM,oBAAoB,qBAAqB,CAAC;AACvD,4FAA4F;AAC5F,eAAO,MAAM,sBAAsB,gBAAgB,CAAC;AAEpD,MAAM,MAAM,YAAY,GAAG;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,GAAG,QAAQ,CAAA;CAAE,CAAC;AAK/F,wFAAwF;AACxF,eAAO,MAAM,iBAAiB,GAAI,OAAO;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,OAAO,CAAA;CAAE,KAAG,YAAY,GAAG,IAU1G,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,mBAAmB,GAAI,MAAM;IACxC,WAAW,EAAE,OAAO,CAAC;IACrB,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,qBAAqB,EAAE,MAAM,GAAG,IAAI,CAAC;IACrC,SAAS,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IAC/B,eAAe,EAAE,OAAO,CAAC;CAC1B,KAAG,OAMoC,C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KAAG,YAAY,GAAG,IAChB,CAAC"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The chat's side of the live turn stream.
|
|
3
|
+
*
|
|
4
|
+
* With the server flag on, every `agent/connect` opens with one CUSTOM event,
|
|
5
|
+
* `blocks.live_turn`, and then streams the thread's active turn live in the same response.
|
|
6
|
+
* With the flag off the server sends none of this, so `liveEnabled` stays false and every
|
|
7
|
+
* decision below answers "do nothing".
|
|
8
|
+
*/
|
|
9
|
+
export const LIVE_TURN_EVENT_NAME = "blocks.live_turn";
|
|
10
|
+
/** The RUN_ERROR code of a send refused because a turn is already running on the thread. */
|
|
11
|
+
export const THREAD_BUSY_ERROR_CODE = "thread_busy";
|
|
12
|
+
const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
13
|
+
/** The payload of the connect's live-turn CUSTOM event, or null for any other event. */
|
|
14
|
+
export const readLiveTurnEvent = (event) => {
|
|
15
|
+
if (event.type !== "CUSTOM" || event.name !== LIVE_TURN_EVENT_NAME || !isRecord(event.value)) {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
const { enabled, runId, startedBy } = event.value;
|
|
19
|
+
return {
|
|
20
|
+
enabled: enabled === true,
|
|
21
|
+
...(typeof runId === "string" && runId !== "" ? { runId } : {}),
|
|
22
|
+
...(startedBy === "chat" || startedBy === "server" ? { startedBy } : {}),
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Whether the thread row's running run (the doorbell) calls for a connect to watch it:
|
|
27
|
+
* one this tab neither follows nor started, that no connect has answered for yet.
|
|
28
|
+
*/
|
|
29
|
+
export const shouldConnectForRun = (args) => args.liveEnabled &&
|
|
30
|
+
args.runningRunId !== null &&
|
|
31
|
+
!args.connectInFlight &&
|
|
32
|
+
args.runningRunId !== args.followingRunId &&
|
|
33
|
+
args.runningRunId !== args.lastConnectedForRunId &&
|
|
34
|
+
!args.ownRunIds.has(args.runningRunId);
|
|
35
|
+
/**
|
|
36
|
+
* Whether a run or connect stream that just ended should be followed by one more connect: it
|
|
37
|
+
* showed a running turn (this tab's send, or one the server named) and ended with no terminal
|
|
38
|
+
* event for it -- the 400 s self-close, a pod restart, a dropped network. A connect for a turn
|
|
39
|
+
* that has finished meanwhile names none, so it is not followed again. A stream that never
|
|
40
|
+
* started (the server unreachable) is not retried, or an outage would loop.
|
|
41
|
+
*/
|
|
42
|
+
export const shouldReconnectAfterStream = (args) => args.liveEnabled && args.streamStarted && args.streamRunId !== null && !args.sawTerminalFor.has(args.streamRunId);
|
|
43
|
+
/**
|
|
44
|
+
* Stop is for this tab's own run, or a followed turn a chat started (never workflow, reminder,
|
|
45
|
+
* ...), and only with the live turn stream on: only then does the server stop the turn itself.
|
|
46
|
+
*/
|
|
47
|
+
export const canStop = (args) => args.following?.enabled === true && (args.ownRunInFlight || args.following.startedBy === "chat");
|
|
48
|
+
export const isThreadBusyError = (event) => event.type === "RUN_ERROR" && event.code === THREAD_BUSY_ERROR_CODE;
|
|
49
|
+
/** The `agent/stop` request: the run body's thread fields only, none of its content. */
|
|
50
|
+
export const buildStopEnvelope = (runBody) => ({
|
|
51
|
+
method: "agent/stop",
|
|
52
|
+
body: {
|
|
53
|
+
threadId: runBody.threadId,
|
|
54
|
+
runId: runBody.runId,
|
|
55
|
+
forwardedProps: isRecord(runBody.forwardedProps) ? runBody.forwardedProps : {},
|
|
56
|
+
messages: [],
|
|
57
|
+
tools: [],
|
|
58
|
+
context: [],
|
|
59
|
+
state: {},
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
/**
|
|
63
|
+
* The run a stream that just ended is judged by. A tab's own send streams under its own run
|
|
64
|
+
* id; a connect body carries its own id for the history replay (RUN_STARTED/RUN_FINISHED),
|
|
65
|
+
* followed by the live turn's events, so a followed stream is judged by the live turn's id.
|
|
66
|
+
*/
|
|
67
|
+
export const streamRunIdOf = (args) => (args.ownRunInFlight ? args.lastStartedRunId : (args.live?.runId ?? null));
|
|
68
|
+
/** The run a stop is for: the tab's own run, else the followed turn (never a connect's id). */
|
|
69
|
+
export const stopRunIdOf = (args) => args.ownRunInFlight ? (args.lastStartedRunId ?? args.live?.runId ?? null) : (args.live?.runId ?? null);
|
|
70
|
+
/** After a terminal event for `runId`: a followed turn that just ended is no longer followed. */
|
|
71
|
+
export const liveAfterTerminal = (live, runId) => live && runId !== null && live.runId === runId ? { enabled: live.enabled } : live;
|