@mgamadeus/ddd-agents 0.1.0-alpha.23 → 0.1.0-alpha.25
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/chat.js +71 -827
- package/dist/chat.js.map +1 -1
- package/dist/chunks/ConversationMessageInputComposerWidgets-BxyaFBA6.js +631 -0
- package/dist/chunks/ConversationMessageInputComposerWidgets-BxyaFBA6.js.map +1 -0
- package/dist/chunks/{WebSearchResultsConversationWidget-DRBQvycE.js → WebSearchResultsConversationWidget-as3p5bHw.js} +92 -85
- package/dist/chunks/WebSearchResultsConversationWidget-as3p5bHw.js.map +1 -0
- package/dist/chunks/{decide-canvas-open-DBWoWtAC.js → canvas-behaviours-AvzKSYyv.js} +3 -19
- package/dist/chunks/canvas-behaviours-AvzKSYyv.js.map +1 -0
- package/dist/chunks/canvas-reducers-Bfp_i7lc.js +88 -0
- package/dist/chunks/canvas-reducers-Bfp_i7lc.js.map +1 -0
- package/dist/chunks/{canvasBodies-DLjDkviP.js → canvasBodies-Cvu3l38p.js} +6 -3
- package/dist/chunks/{canvasBodies-DLjDkviP.js.map → canvasBodies-Cvu3l38p.js.map} +1 -1
- package/dist/chunks/canvasStorage-EvQsGdto.js +65 -0
- package/dist/chunks/canvasStorage-EvQsGdto.js.map +1 -0
- package/dist/chunks/contract-BxmMxYPF.js +96 -0
- package/dist/chunks/contract-BxmMxYPF.js.map +1 -0
- package/dist/chunks/conversation-BEF0aesf.js +31 -0
- package/dist/chunks/conversation-BEF0aesf.js.map +1 -0
- package/dist/chunks/{ConversationMarkdown-CJhAnuVa.js → widget-click-signal-sources-DulRkNvZ.js} +22 -77
- package/dist/chunks/widget-click-signal-sources-DulRkNvZ.js.map +1 -0
- package/dist/chunks/{widget-name-resolver-C8SfpiR5.js → widget-name-resolver-BGN3HpoG.js} +61 -30
- package/dist/chunks/widget-name-resolver-BGN3HpoG.js.map +1 -0
- package/dist/chunks/{withPollingChangeSubscription-BLDAWF-o.js → withPollingChangeSubscription-B16htQGd.js} +2 -2
- package/dist/chunks/{withPollingChangeSubscription-BLDAWF-o.js.map → withPollingChangeSubscription-B16htQGd.js.map} +1 -1
- package/dist/client-testing.js +28 -6
- package/dist/client-testing.js.map +1 -1
- package/dist/client.js +1 -1
- package/dist/contract.js +8 -27
- package/dist/contract.js.map +1 -1
- package/dist/image-render.js +8 -8
- package/dist/index.js +6 -5
- package/dist/kit.js +2 -2
- package/dist/preview.js +44 -16
- package/dist/preview.js.map +1 -1
- package/dist/renderer.js +62 -57
- package/dist/renderer.js.map +1 -1
- package/dist/styles.css +55 -22
- package/dist/types/client/testing/widget-hydration-stand-ins.d.ts +12 -3
- package/dist/types/entries/chat.d.ts +2 -0
- package/dist/types/entries/client-testing.d.ts +2 -0
- package/dist/types/entries/contract.d.ts +1 -0
- package/dist/types/entries/index.d.ts +1 -1
- package/dist/types/entries/preview.d.ts +1 -0
- package/dist/types/entries/renderer.d.ts +3 -1
- package/dist/types/kit/components/data/chart-model.d.ts +2 -2
- package/dist/types/kit/components/data/use-chart-palette.d.ts +2 -2
- package/dist/types/kit/components/map/use-google-maps-auth-failure.d.ts +18 -0
- package/dist/types/kit/entity-detail/entity-detail-bodies.d.ts +2 -0
- package/dist/types/renderer/canvas/entity-detail-instance.d.ts +5 -3
- package/dist/types/renderer/widget-hydration/use-widget-hydration.d.ts +5 -0
- package/dist/types/widgets/EntityMentionConversationWidget/stories/EntityMentionAskFlowStory.d.ts +8 -0
- package/dist/widgets.js +33 -33
- package/package.json +1 -1
- package/public-api.json +19 -1
- package/dist/chunks/ConversationMarkdown-CJhAnuVa.js.map +0 -1
- package/dist/chunks/WebSearchResultsConversationWidget-DRBQvycE.js.map +0 -1
- package/dist/chunks/decide-canvas-open-DBWoWtAC.js.map +0 -1
- package/dist/chunks/widget-name-resolver-C8SfpiR5.js.map +0 -1
package/dist/chat.js
CHANGED
|
@@ -1,29 +1,33 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx, jsxs, Fragment } from "react/jsx-runtime";
|
|
3
|
-
import { useRef, useEffect, useMemo,
|
|
3
|
+
import { useRef, useEffect, useMemo, useState, useImperativeHandle, useLayoutEffect, useCallback, useContext, memo, Fragment as Fragment$1, useReducer } from "react";
|
|
4
4
|
import { u as useAgentsConversationClient, a as useOptionalAgentsConversationClient } from "./chunks/AgentsConversationClientContext-C4T7g_Qk.js";
|
|
5
|
-
import { w as withPollingChangeSubscription } from "./chunks/withPollingChangeSubscription-
|
|
6
|
-
import { q as Text, I as Icon,
|
|
7
|
-
import { isAgentsClientError, AgentsClientError } from "./
|
|
8
|
-
import { W as WIDGET_FENCE_LANG,
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import { r as
|
|
12
|
-
import { c as
|
|
5
|
+
import { w as withPollingChangeSubscription } from "./chunks/withPollingChangeSubscription-B16htQGd.js";
|
|
6
|
+
import { q as Text, I as Icon, $ as translateText, G as GlowFrame, t as Tooltip, B as Button, z as classNames, l as Skeleton, a3 as useAgentsEnvironment, h as Markdown, F as getAgentDisplayName, a1 as useAgentsBudgetLimit, f as InteractiveSurface, L as LoadingSpinner, n as SplitView, Y as reportRunningTurn, a0 as useAgentsActiveAgentSpaceKey, P as ProgressBar } from "./chunks/index-7Qc_3GbG.js";
|
|
7
|
+
import { i as isAgentsClientError, A as AgentsClientError } from "./chunks/conversation-BEF0aesf.js";
|
|
8
|
+
import { W as WIDGET_FENCE_LANG, G as resolveWidgetName, j as conversationWidgetRegistry, n as findWidgetFencesInMarkdown, o as ConversationWidgetErrorBoundary, p as ConversationWidgetFeatureGate, T as parseWidgetJsonObject, F as resolveCanonicalWidgetName, y as getConversationWidgetRegistryRevision, U as BARE_WIDGET_LINE_GLOBAL, t as closestWidgetNames } from "./chunks/widget-name-resolver-BGN3HpoG.js";
|
|
9
|
+
import { E as useConversationWidgetContext, p as payloadHashOfInstanceId, j as buildWidgetAgentSpaceKeyProps, ap as useCanvasViable } from "./chunks/WebSearchResultsConversationWidget-as3p5bHw.js";
|
|
10
|
+
import { c as canvasBehaviourOf, d as CHAT_COLUMN_MIN_WIDTH_PX, b as CANVAS_MIN_WIDTH_PX, D as DEFAULT_CANVAS_WIDTH_PERCENT, e as canvasWidthPercentOf, C as CANVAS_BOXED_INSET_PX } from "./chunks/canvas-behaviours-AvzKSYyv.js";
|
|
11
|
+
import { r as readStoredCanvas, c as clearStoredCanvas } from "./chunks/canvasStorage-EvQsGdto.js";
|
|
12
|
+
import { r as resolveDeepLinkableWidget, c as WidgetWindowRootContext, C as ConversationMarkdown, i as isWidgetClickSignalSource, b as buildWidgetRenderReportSignal, W as WIDGET_RENDER_REPORT_SIGNAL_SOURCE, e as createWidgetRenderReportCollector, f as WidgetRenderReportCollectorContext } from "./chunks/widget-click-signal-sources-DulRkNvZ.js";
|
|
13
|
+
import { b as ConversationErrorType, a as ConversationMessageInputComposerWidgets, u as useAgentsChatSelector, C as ConversationWidgetProvider, c as createAgentsChatStore } from "./chunks/ConversationMessageInputComposerWidgets-BxyaFBA6.js";
|
|
14
|
+
import { A, d, E, I, r, e, f, g, h } from "./chunks/ConversationMessageInputComposerWidgets-BxyaFBA6.js";
|
|
15
|
+
import { c as canvasBodies } from "./chunks/canvasBodies-Cvu3l38p.js";
|
|
13
16
|
import { c as canvasFeatureFlagOf } from "./chunks/canvas-feature-flags-BmmxC3bz.js";
|
|
14
17
|
import { flushSync } from "react-dom";
|
|
18
|
+
import { b as buildChangedMessagesRequest, d as deriveAgentActivity } from "./chunks/contract-BxmMxYPF.js";
|
|
15
19
|
const history = "agents_history_BIbikt";
|
|
16
|
-
const styles$
|
|
20
|
+
const styles$l = {
|
|
17
21
|
history
|
|
18
22
|
};
|
|
19
23
|
const AgentChatActivityHistory = (props) => {
|
|
20
24
|
const { turn } = props;
|
|
21
25
|
if (turn === null || turn.lines.length === 0) return null;
|
|
22
|
-
return /* @__PURE__ */ jsx("div", { className: styles$
|
|
26
|
+
return /* @__PURE__ */ jsx("div", { className: styles$l.history, "data-testid": "agent-chat-activity-history", children: turn.lines.map((line) => /* @__PURE__ */ jsx(Text, { role: "help", color: "--agents-fg-light", translate: false, children: line.line }, `${line.toolCallMessageId}-${line.state}`)) });
|
|
23
27
|
};
|
|
24
28
|
const activity = "agents_activity_Gv-0ee";
|
|
25
29
|
const dots = "agents_dots_Qvm8gN";
|
|
26
|
-
const styles$
|
|
30
|
+
const styles$k = {
|
|
27
31
|
activity,
|
|
28
32
|
dots
|
|
29
33
|
};
|
|
@@ -33,8 +37,8 @@ const AgentChatActivityIndicator = (props) => {
|
|
|
33
37
|
if (!isWorking) return null;
|
|
34
38
|
const currentLines = activityTicker.currentTurn?.lines ?? [];
|
|
35
39
|
const currentLine = currentLines.length > 0 ? currentLines[currentLines.length - 1].line : null;
|
|
36
|
-
return /* @__PURE__ */ jsxs("div", { className: styles$
|
|
37
|
-
/* @__PURE__ */ jsxs("div", { className: styles$
|
|
40
|
+
return /* @__PURE__ */ jsxs("div", { className: styles$k.activity, role: "status", "aria-live": "polite", "data-testid": "agent-chat-activity", children: [
|
|
41
|
+
/* @__PURE__ */ jsxs("div", { className: styles$k.dots, "aria-hidden": "true", children: [
|
|
38
42
|
/* @__PURE__ */ jsx("span", {}),
|
|
39
43
|
/* @__PURE__ */ jsx("span", {}),
|
|
40
44
|
/* @__PURE__ */ jsx("span", {})
|
|
@@ -43,12 +47,12 @@ const AgentChatActivityIndicator = (props) => {
|
|
|
43
47
|
] });
|
|
44
48
|
};
|
|
45
49
|
const bar = "agents_bar_DAkgRp";
|
|
46
|
-
const styles$
|
|
50
|
+
const styles$j = {
|
|
47
51
|
bar
|
|
48
52
|
};
|
|
49
53
|
const ConversationClosedBar = (props) => {
|
|
50
54
|
const { text = "This conversation is closed." } = props;
|
|
51
|
-
return /* @__PURE__ */ jsxs("div", { className: styles$
|
|
55
|
+
return /* @__PURE__ */ jsxs("div", { className: styles$j.bar, "data-testid": "agent-chat-closed-bar", children: [
|
|
52
56
|
/* @__PURE__ */ jsx(Icon, { name: "check", color: "--agents-success-500" }),
|
|
53
57
|
/* @__PURE__ */ jsx(Text, { children: text })
|
|
54
58
|
] });
|
|
@@ -318,63 +322,6 @@ const normalizeServerMessageToMarkdown = (message2) => {
|
|
|
318
322
|
}
|
|
319
323
|
return referenceNakedWidgetJson(repairMalformedWidgetFences(stripPreCallMessageMarker(result)));
|
|
320
324
|
};
|
|
321
|
-
const CANVAS_STORAGE_KEY_PREFIX = "agent.canvas.";
|
|
322
|
-
const canvasStorageKey = (conversationId) => `${CANVAS_STORAGE_KEY_PREFIX}${conversationId}`;
|
|
323
|
-
const isPositiveInteger = (value) => typeof value === "number" && Number.isInteger(value) && value > 0;
|
|
324
|
-
const parseAnchor = (value) => {
|
|
325
|
-
if (typeof value !== "object" || value === null) return null;
|
|
326
|
-
const candidate = value;
|
|
327
|
-
if (candidate.kind === "message" && isPositiveInteger(candidate.messageId)) {
|
|
328
|
-
return { kind: "message", messageId: candidate.messageId };
|
|
329
|
-
}
|
|
330
|
-
if (candidate.kind === "page" && isPositiveInteger(candidate.agentSpaceKey)) {
|
|
331
|
-
return { kind: "page", agentSpaceKey: candidate.agentSpaceKey };
|
|
332
|
-
}
|
|
333
|
-
return null;
|
|
334
|
-
};
|
|
335
|
-
const parseStoredCanvasPointer = (value) => {
|
|
336
|
-
if (typeof value !== "object" || value === null) return null;
|
|
337
|
-
const candidate = value;
|
|
338
|
-
const anchor = parseAnchor(candidate.anchor);
|
|
339
|
-
if (!isCanvasId(candidate.canvasId) || anchor === null) return null;
|
|
340
|
-
if (typeof candidate.instanceId !== "string" || candidate.instanceId.length === 0) return null;
|
|
341
|
-
return {
|
|
342
|
-
canvasId: candidate.canvasId,
|
|
343
|
-
anchor,
|
|
344
|
-
instanceId: candidate.instanceId,
|
|
345
|
-
...isPositiveInteger(candidate.createdEntityId) ? { createdEntityId: candidate.createdEntityId } : {}
|
|
346
|
-
};
|
|
347
|
-
};
|
|
348
|
-
const storeOpenCanvas = (conversationId, canvas) => {
|
|
349
|
-
if (conversationId === void 0) return;
|
|
350
|
-
const pointer = {
|
|
351
|
-
canvasId: canvas.canvasId,
|
|
352
|
-
anchor: canvas.anchor,
|
|
353
|
-
instanceId: canvas.instanceId,
|
|
354
|
-
...canvas.createdEntityId !== void 0 ? { createdEntityId: canvas.createdEntityId } : {}
|
|
355
|
-
};
|
|
356
|
-
try {
|
|
357
|
-
window.sessionStorage.setItem(canvasStorageKey(conversationId), JSON.stringify(pointer));
|
|
358
|
-
} catch {
|
|
359
|
-
}
|
|
360
|
-
};
|
|
361
|
-
const readStoredCanvas = (conversationId) => {
|
|
362
|
-
if (conversationId === void 0) return null;
|
|
363
|
-
try {
|
|
364
|
-
const raw = window.sessionStorage.getItem(canvasStorageKey(conversationId));
|
|
365
|
-
if (raw === null) return null;
|
|
366
|
-
return parseStoredCanvasPointer(JSON.parse(raw));
|
|
367
|
-
} catch {
|
|
368
|
-
return null;
|
|
369
|
-
}
|
|
370
|
-
};
|
|
371
|
-
const clearStoredCanvas = (conversationId) => {
|
|
372
|
-
if (conversationId === void 0) return;
|
|
373
|
-
try {
|
|
374
|
-
window.sessionStorage.removeItem(canvasStorageKey(conversationId));
|
|
375
|
-
} catch {
|
|
376
|
-
}
|
|
377
|
-
};
|
|
378
325
|
const anchorMessageCarriesCanvasWidget = (pointer, anchorMessage) => {
|
|
379
326
|
const openers = new Set(
|
|
380
327
|
conversationWidgetRegistry.widgets.filter((entry) => entry.opensCanvases?.includes(pointer.canvasId)).map((entry) => entry.name)
|
|
@@ -437,576 +384,6 @@ const ConversationDeepLinkedWidget = ({ widgetName, agentSpaceKey }) => {
|
|
|
437
384
|
}
|
|
438
385
|
) : widget });
|
|
439
386
|
};
|
|
440
|
-
const EMPTY_AGENTS_CHAT_OPENING_REQUEST = {
|
|
441
|
-
userMessage: null,
|
|
442
|
-
startSignalText: null,
|
|
443
|
-
entryPointKey: null,
|
|
444
|
-
deepLinkedWidgetName: null
|
|
445
|
-
};
|
|
446
|
-
const INITIAL_AGENTS_CHAT_STATE = {
|
|
447
|
-
conversation: null,
|
|
448
|
-
messages: null,
|
|
449
|
-
conversationLoading: false,
|
|
450
|
-
conversationLoaded: false,
|
|
451
|
-
hasMoreOlder: false,
|
|
452
|
-
aiThinking: false,
|
|
453
|
-
error: null,
|
|
454
|
-
rateLimitRetryAfterSeconds: null,
|
|
455
|
-
requestedConversationId: null,
|
|
456
|
-
startingNewConversation: false,
|
|
457
|
-
pendingStartToken: null,
|
|
458
|
-
startTokenCount: 0,
|
|
459
|
-
openingRequest: EMPTY_AGENTS_CHAT_OPENING_REQUEST,
|
|
460
|
-
canvas: null,
|
|
461
|
-
lastClosedCanvas: null,
|
|
462
|
-
canvasMountCount: 0
|
|
463
|
-
};
|
|
464
|
-
const ConversationErrorType = {
|
|
465
|
-
AI_BUDGET: "AI_BUDGET",
|
|
466
|
-
/**
|
|
467
|
-
* HTTP 429 from an AI endpoint — a per-minute/hour/day usage quota was hit. Distinct from AI_BUDGET (monthly budget):
|
|
468
|
-
* this one clears on its own after the Retry-After window.
|
|
469
|
-
*/
|
|
470
|
-
RATE_LIMIT: "RATE_LIMIT",
|
|
471
|
-
NETWORK_ERROR: "NETWORK_ERROR",
|
|
472
|
-
CONVERSATION_NOT_FOUND: "CONVERSATION_NOT_FOUND",
|
|
473
|
-
/**
|
|
474
|
-
* The backend run FAILED (e.g. the model provider returned an error). The raw provider error is admin-only (never
|
|
475
|
-
* shown here); the owner gets a generic "something went wrong" card.
|
|
476
|
-
*/
|
|
477
|
-
AGENT_ERROR: "AGENT_ERROR",
|
|
478
|
-
/**
|
|
479
|
-
* The conversation is COMPLETED/CANCELLED and refuses further owner input. Set from the server's stable error code
|
|
480
|
-
* `CONVERSATION_CLOSED` or by the chat's own pre-send guard; the error card owns the copy.
|
|
481
|
-
*/
|
|
482
|
-
CONVERSATION_CLOSED: "CONVERSATION_CLOSED"
|
|
483
|
-
};
|
|
484
|
-
const readConversationErrorTypeOfRefusedSend = (error) => {
|
|
485
|
-
if (error.kind === "budget") return ConversationErrorType.AI_BUDGET;
|
|
486
|
-
if (error.kind === "rateLimit") return ConversationErrorType.RATE_LIMIT;
|
|
487
|
-
if (error.kind === "closed") return ConversationErrorType.CONVERSATION_CLOSED;
|
|
488
|
-
return ConversationErrorType.NETWORK_ERROR;
|
|
489
|
-
};
|
|
490
|
-
const mergeChatMessagesByIndex = (existing, incoming) => {
|
|
491
|
-
const messagesByIndex = /* @__PURE__ */ new Map();
|
|
492
|
-
const messagesWithoutIndex = [];
|
|
493
|
-
const collectMessage = (message2) => {
|
|
494
|
-
if (message2.indexInConversation != null) {
|
|
495
|
-
messagesByIndex.set(message2.indexInConversation, message2);
|
|
496
|
-
} else {
|
|
497
|
-
messagesWithoutIndex.push(message2);
|
|
498
|
-
}
|
|
499
|
-
};
|
|
500
|
-
existing.forEach(collectMessage);
|
|
501
|
-
incoming.forEach(collectMessage);
|
|
502
|
-
const indexedMessages = Array.from(messagesByIndex.values()).sort(
|
|
503
|
-
(first, second) => (first.indexInConversation ?? 0) - (second.indexInConversation ?? 0)
|
|
504
|
-
);
|
|
505
|
-
return [...indexedMessages, ...messagesWithoutIndex];
|
|
506
|
-
};
|
|
507
|
-
const tagFreshChatMessages = (incoming, previousMessages) => {
|
|
508
|
-
const previousIds = new Set(previousMessages.map((message2) => message2.id).filter((id) => id != null));
|
|
509
|
-
return incoming.map((message2) => ({ ...message2, fresh: message2.id != null && !previousIds.has(message2.id) }));
|
|
510
|
-
};
|
|
511
|
-
const mergeMessagesPage = (loadedMessages, page, requestedConversationId) => {
|
|
512
|
-
const shownConversationId = loadedMessages?.find((message2) => message2.conversationId != null)?.conversationId;
|
|
513
|
-
const replacesShownConversation = shownConversationId != null && shownConversationId !== requestedConversationId;
|
|
514
|
-
const existingMessages = replacesShownConversation ? [] : loadedMessages ?? [];
|
|
515
|
-
const messagesByIndex = /* @__PURE__ */ new Map();
|
|
516
|
-
for (const existingMessage of existingMessages) {
|
|
517
|
-
if (existingMessage.indexInConversation != null) {
|
|
518
|
-
messagesByIndex.set(existingMessage.indexInConversation, existingMessage);
|
|
519
|
-
}
|
|
520
|
-
}
|
|
521
|
-
const hadMessagesBeforeMerge = existingMessages.length > 0;
|
|
522
|
-
const highestShownIndex = Math.max(-1, ...existingMessages.map((message2) => message2.indexInConversation ?? -1));
|
|
523
|
-
for (const incomingMessage of page) {
|
|
524
|
-
if (incomingMessage.indexInConversation == null) continue;
|
|
525
|
-
const previousMessage = messagesByIndex.get(incomingMessage.indexInConversation);
|
|
526
|
-
const isLiveArrival = hadMessagesBeforeMerge && previousMessage == null && incomingMessage.indexInConversation > highestShownIndex;
|
|
527
|
-
messagesByIndex.set(incomingMessage.indexInConversation, {
|
|
528
|
-
...incomingMessage,
|
|
529
|
-
fresh: previousMessage?.fresh ?? isLiveArrival
|
|
530
|
-
});
|
|
531
|
-
}
|
|
532
|
-
return Array.from(messagesByIndex.values()).sort(
|
|
533
|
-
(first, second) => (first.indexInConversation ?? 0) - (second.indexInConversation ?? 0)
|
|
534
|
-
);
|
|
535
|
-
};
|
|
536
|
-
const withRefusedSendError = (state, error) => {
|
|
537
|
-
const conversationErrorType = readConversationErrorTypeOfRefusedSend(error);
|
|
538
|
-
return {
|
|
539
|
-
...state,
|
|
540
|
-
error: conversationErrorType,
|
|
541
|
-
rateLimitRetryAfterSeconds: conversationErrorType === ConversationErrorType.RATE_LIMIT ? error.retryAfterSeconds ?? null : null
|
|
542
|
-
};
|
|
543
|
-
};
|
|
544
|
-
const mergeSendAnswer = (loadedMessages, answerMessages) => {
|
|
545
|
-
const messagesWithoutOptimisticMessage = loadedMessages ? loadedMessages.slice(0, loadedMessages.length - 1) : [];
|
|
546
|
-
return mergeChatMessagesByIndex(
|
|
547
|
-
messagesWithoutOptimisticMessage,
|
|
548
|
-
tagFreshChatMessages(answerMessages, messagesWithoutOptimisticMessage)
|
|
549
|
-
);
|
|
550
|
-
};
|
|
551
|
-
const withCanvasTransition = (state, applyCanvasTransition) => {
|
|
552
|
-
const nextState = { ...state };
|
|
553
|
-
applyCanvasTransition(nextState);
|
|
554
|
-
const changed = nextState.canvas !== state.canvas || nextState.lastClosedCanvas !== state.lastClosedCanvas || nextState.canvasMountCount !== state.canvasMountCount;
|
|
555
|
-
return changed ? nextState : state;
|
|
556
|
-
};
|
|
557
|
-
const reduceAgentsChatState = (state, event) => {
|
|
558
|
-
switch (event.type) {
|
|
559
|
-
case "reset":
|
|
560
|
-
return {
|
|
561
|
-
...INITIAL_AGENTS_CHAT_STATE,
|
|
562
|
-
openingRequest: state.openingRequest,
|
|
563
|
-
canvasMountCount: state.canvasMountCount,
|
|
564
|
-
startTokenCount: state.startTokenCount
|
|
565
|
-
};
|
|
566
|
-
case "conversationMetadataRequested":
|
|
567
|
-
case "messagesPageRequested":
|
|
568
|
-
return state.requestedConversationId === event.conversationId ? state : { ...state, requestedConversationId: event.conversationId };
|
|
569
|
-
case "conversationMetadataReceived":
|
|
570
|
-
if (state.requestedConversationId === null || state.requestedConversationId !== event.conversationId) {
|
|
571
|
-
return state;
|
|
572
|
-
}
|
|
573
|
-
return { ...state, conversation: event.conversation, conversationLoaded: true };
|
|
574
|
-
case "conversationMetadataFailed":
|
|
575
|
-
return { ...state, conversationLoaded: true };
|
|
576
|
-
case "messagesPageReceived": {
|
|
577
|
-
if (state.requestedConversationId === null || state.requestedConversationId !== event.conversationId) {
|
|
578
|
-
return state;
|
|
579
|
-
}
|
|
580
|
-
if (state.conversation !== null && state.conversation.id !== event.conversationId) {
|
|
581
|
-
return state;
|
|
582
|
-
}
|
|
583
|
-
return {
|
|
584
|
-
...state,
|
|
585
|
-
messages: mergeMessagesPage(state.messages, event.messages, event.conversationId),
|
|
586
|
-
hasMoreOlder: event.hasMoreOlder ?? state.hasMoreOlder,
|
|
587
|
-
conversationLoaded: true
|
|
588
|
-
};
|
|
589
|
-
}
|
|
590
|
-
case "messagePostRequested":
|
|
591
|
-
return {
|
|
592
|
-
...state,
|
|
593
|
-
conversationLoading: true,
|
|
594
|
-
conversationLoaded: false,
|
|
595
|
-
aiThinking: true,
|
|
596
|
-
error: null,
|
|
597
|
-
rateLimitRetryAfterSeconds: null,
|
|
598
|
-
messages: [...state.messages ?? [], event.message]
|
|
599
|
-
};
|
|
600
|
-
case "messagePostReceived":
|
|
601
|
-
if (event.conversationId !== state.conversation?.id) {
|
|
602
|
-
return state;
|
|
603
|
-
}
|
|
604
|
-
return {
|
|
605
|
-
...state,
|
|
606
|
-
messages: mergeSendAnswer(state.messages, event.posted.messages),
|
|
607
|
-
conversationLoading: false,
|
|
608
|
-
conversationLoaded: true,
|
|
609
|
-
error: null
|
|
610
|
-
};
|
|
611
|
-
case "messagePostFailed":
|
|
612
|
-
return withRefusedSendError(
|
|
613
|
-
{ ...state, conversationLoading: false, conversationLoaded: true, aiThinking: false },
|
|
614
|
-
event.error
|
|
615
|
-
);
|
|
616
|
-
case "startRequested":
|
|
617
|
-
return {
|
|
618
|
-
...state,
|
|
619
|
-
conversation: null,
|
|
620
|
-
conversationLoading: true,
|
|
621
|
-
conversationLoaded: false,
|
|
622
|
-
aiThinking: true,
|
|
623
|
-
error: null,
|
|
624
|
-
rateLimitRetryAfterSeconds: null,
|
|
625
|
-
startingNewConversation: true,
|
|
626
|
-
startTokenCount: state.startTokenCount + 1,
|
|
627
|
-
pendingStartToken: state.startTokenCount + 1,
|
|
628
|
-
// A signal-only start (an empty visible message carries the start signal) seeds no empty bubble.
|
|
629
|
-
messages: event.message.message ? [event.message] : []
|
|
630
|
-
};
|
|
631
|
-
case "startReceived": {
|
|
632
|
-
if (event.startToken !== state.pendingStartToken) {
|
|
633
|
-
return state;
|
|
634
|
-
}
|
|
635
|
-
const { started } = event;
|
|
636
|
-
if (started.reopenedExisting) {
|
|
637
|
-
return {
|
|
638
|
-
...state,
|
|
639
|
-
conversation: started.conversation,
|
|
640
|
-
messages: [],
|
|
641
|
-
conversationLoading: false,
|
|
642
|
-
conversationLoaded: true,
|
|
643
|
-
aiThinking: false,
|
|
644
|
-
startingNewConversation: false,
|
|
645
|
-
pendingStartToken: null
|
|
646
|
-
};
|
|
647
|
-
}
|
|
648
|
-
return {
|
|
649
|
-
...state,
|
|
650
|
-
conversation: started.conversation,
|
|
651
|
-
messages: mergeSendAnswer(state.messages, started.messages),
|
|
652
|
-
conversationLoading: false,
|
|
653
|
-
conversationLoaded: true,
|
|
654
|
-
startingNewConversation: false,
|
|
655
|
-
pendingStartToken: null
|
|
656
|
-
};
|
|
657
|
-
}
|
|
658
|
-
case "startFailed":
|
|
659
|
-
return withRefusedSendError(
|
|
660
|
-
{
|
|
661
|
-
...state,
|
|
662
|
-
conversation: null,
|
|
663
|
-
conversationLoading: false,
|
|
664
|
-
conversationLoaded: true,
|
|
665
|
-
aiThinking: false,
|
|
666
|
-
startingNewConversation: false,
|
|
667
|
-
pendingStartToken: null
|
|
668
|
-
},
|
|
669
|
-
event.error
|
|
670
|
-
);
|
|
671
|
-
case "errorSet":
|
|
672
|
-
return state.error === event.error ? state : { ...state, error: event.error };
|
|
673
|
-
case "aiThinkingSet":
|
|
674
|
-
return state.aiThinking === event.aiThinking ? state : { ...state, aiThinking: event.aiThinking };
|
|
675
|
-
case "openingRequestSet":
|
|
676
|
-
return { ...state, openingRequest: { ...state.openingRequest, ...event.openingRequest } };
|
|
677
|
-
case "canvasOpened":
|
|
678
|
-
return withCanvasTransition(state, (nextState) => {
|
|
679
|
-
applyOpenCanvas(nextState, event.request);
|
|
680
|
-
});
|
|
681
|
-
case "canvasClosed":
|
|
682
|
-
return withCanvasTransition(state, (nextState) => applyCloseCanvas(nextState, event.byCustomer));
|
|
683
|
-
case "canvasResetForNewTurn":
|
|
684
|
-
return withCanvasTransition(state, applyResetCanvasForNewTurn);
|
|
685
|
-
case "canvasCleared":
|
|
686
|
-
return withCanvasTransition(state, applyClearCanvas);
|
|
687
|
-
case "canvasCreatedEntityIdSet":
|
|
688
|
-
return withCanvasTransition(state, (nextState) => {
|
|
689
|
-
applySetCanvasCreatedEntityId(nextState, event.created);
|
|
690
|
-
});
|
|
691
|
-
}
|
|
692
|
-
};
|
|
693
|
-
class AgentsChatStateContainer {
|
|
694
|
-
constructor(initialState = INITIAL_AGENTS_CHAT_STATE) {
|
|
695
|
-
this.listeners = /* @__PURE__ */ new Set();
|
|
696
|
-
this.getState = () => this.state;
|
|
697
|
-
this.subscribe = (listener) => {
|
|
698
|
-
this.listeners.add(listener);
|
|
699
|
-
return () => {
|
|
700
|
-
this.listeners.delete(listener);
|
|
701
|
-
};
|
|
702
|
-
};
|
|
703
|
-
this.dispatch = (event) => {
|
|
704
|
-
const nextState = reduceAgentsChatState(this.state, event);
|
|
705
|
-
if (nextState === this.state) return;
|
|
706
|
-
this.state = nextState;
|
|
707
|
-
for (const notifyListener of [...this.listeners]) notifyListener();
|
|
708
|
-
};
|
|
709
|
-
this.state = initialState;
|
|
710
|
-
}
|
|
711
|
-
}
|
|
712
|
-
const createAgentsChatStore = (initialState) => new AgentsChatStateContainer(initialState);
|
|
713
|
-
const AgentsChatStoreContext = createContext(null);
|
|
714
|
-
const AgentsChatStoreProvider = (props) => {
|
|
715
|
-
const { chatStore, children } = props;
|
|
716
|
-
return /* @__PURE__ */ jsx(AgentsChatStoreContext.Provider, { value: chatStore, children });
|
|
717
|
-
};
|
|
718
|
-
const useAgentsChatStore = () => {
|
|
719
|
-
const chatStore = useContext(AgentsChatStoreContext);
|
|
720
|
-
if (chatStore === null) {
|
|
721
|
-
throw new Error("A chat component rendered outside AgentsChatStoreProvider: the app has to mount its chat store.");
|
|
722
|
-
}
|
|
723
|
-
return chatStore;
|
|
724
|
-
};
|
|
725
|
-
const useOptionalAgentsChatStore = () => useContext(AgentsChatStoreContext);
|
|
726
|
-
const subscribeToNothing = () => () => void 0;
|
|
727
|
-
const useAgentsChatSelector = (chatStore, selector, valueWithoutStore) => {
|
|
728
|
-
const subscribe = chatStore ? chatStore.subscribe : subscribeToNothing;
|
|
729
|
-
const readSelectedValue = useCallback(
|
|
730
|
-
() => chatStore ? selector(chatStore.getState()) : valueWithoutStore,
|
|
731
|
-
[chatStore, selector, valueWithoutStore]
|
|
732
|
-
);
|
|
733
|
-
return useSyncExternalStore(subscribe, readSelectedValue, readSelectedValue);
|
|
734
|
-
};
|
|
735
|
-
const useAgentsChatState = (selector) => useAgentsChatSelector(useAgentsChatStore(), selector);
|
|
736
|
-
let agenticChatMountCount = 0;
|
|
737
|
-
const selectCanvas$1 = (state) => state.canvas;
|
|
738
|
-
const selectLastClosedCanvas = (state) => state.lastClosedCanvas;
|
|
739
|
-
const selectAiThinking = (state) => state.aiThinking;
|
|
740
|
-
const selectRunState = (state) => state.conversation?.runState;
|
|
741
|
-
const selectMessages$1 = (state) => state.messages;
|
|
742
|
-
const ChatStoreConversationWidgetProvider = (props) => {
|
|
743
|
-
const { chatStore, ...bodyProps } = props;
|
|
744
|
-
const canvas = useAgentsChatSelector(chatStore, selectCanvas$1);
|
|
745
|
-
const lastClosedCanvas = useAgentsChatSelector(chatStore, selectLastClosedCanvas);
|
|
746
|
-
const isConversationRunning = useAgentsChatSelector(chatStore, selectAiThinking);
|
|
747
|
-
const runState = useAgentsChatSelector(chatStore, selectRunState);
|
|
748
|
-
const messages = useAgentsChatSelector(chatStore, selectMessages$1);
|
|
749
|
-
const chatState = useMemo(
|
|
750
|
-
() => ({
|
|
751
|
-
canvas,
|
|
752
|
-
lastClosedCanvas,
|
|
753
|
-
isConversationRunning,
|
|
754
|
-
runState,
|
|
755
|
-
messages,
|
|
756
|
-
dispatchCanvasEvent: chatStore.dispatch
|
|
757
|
-
}),
|
|
758
|
-
[canvas, lastClosedCanvas, isConversationRunning, runState, messages, chatStore]
|
|
759
|
-
);
|
|
760
|
-
return /* @__PURE__ */ jsx(ConversationWidgetProviderBody, { ...bodyProps, chatState });
|
|
761
|
-
};
|
|
762
|
-
const SliceConversationWidgetProvider = (props) => {
|
|
763
|
-
const { sliceInstance, ...bodyProps } = props;
|
|
764
|
-
const dispatch = useAgentsStateDispatch();
|
|
765
|
-
const canvas = useAgentsStateSelector((state) => sliceInstance.selectState(state).canvas);
|
|
766
|
-
const lastClosedCanvas = useAgentsStateSelector((state) => sliceInstance.selectState(state).lastClosedCanvas);
|
|
767
|
-
const isConversationRunning = useAgentsStateSelector((state) => sliceInstance.selectState(state).aiThinking);
|
|
768
|
-
const runState = useAgentsStateSelector((state) => sliceInstance.selectState(state).conversation?.runState);
|
|
769
|
-
const messages = useAgentsStateSelector((state) => sliceInstance.selectState(state).messages);
|
|
770
|
-
const dispatchCanvasEvent = useCallback(
|
|
771
|
-
(event) => {
|
|
772
|
-
const { actions: actions2 } = sliceInstance;
|
|
773
|
-
if (event.type === "canvasOpened") dispatch(actions2.openCanvas(event.request));
|
|
774
|
-
else if (event.type === "canvasClosed") dispatch(actions2.closeCanvas({ byCustomer: event.byCustomer }));
|
|
775
|
-
else if (event.type === "canvasResetForNewTurn") dispatch(actions2.resetCanvasForNewTurn());
|
|
776
|
-
else if (event.type === "canvasCleared") dispatch(actions2.clearCanvas());
|
|
777
|
-
else dispatch(actions2.setCanvasCreatedEntityId(event.created));
|
|
778
|
-
},
|
|
779
|
-
[dispatch, sliceInstance]
|
|
780
|
-
);
|
|
781
|
-
const chatState = useMemo(
|
|
782
|
-
() => ({ canvas, lastClosedCanvas, isConversationRunning, runState, messages, dispatchCanvasEvent }),
|
|
783
|
-
[canvas, lastClosedCanvas, isConversationRunning, runState, messages, dispatchCanvasEvent]
|
|
784
|
-
);
|
|
785
|
-
return /* @__PURE__ */ jsx(ConversationWidgetProviderBody, { ...bodyProps, chatState });
|
|
786
|
-
};
|
|
787
|
-
const OwnChatStoreConversationWidgetProvider = (props) => {
|
|
788
|
-
const [ownChatStore] = useState(createAgentsChatStore);
|
|
789
|
-
return /* @__PURE__ */ jsx(ChatStoreConversationWidgetProvider, { ...props, chatStore: ownChatStore });
|
|
790
|
-
};
|
|
791
|
-
const ConversationWidgetProvider = (props) => {
|
|
792
|
-
const { sliceInstance, chatStore, ...bodyProps } = props;
|
|
793
|
-
const { defaultChatStatePartition } = useAgentsEnvironment();
|
|
794
|
-
const statePartition = sliceInstance ?? defaultChatStatePartition;
|
|
795
|
-
if (chatStore) return /* @__PURE__ */ jsx(ChatStoreConversationWidgetProvider, { ...bodyProps, chatStore });
|
|
796
|
-
if (statePartition) return /* @__PURE__ */ jsx(SliceConversationWidgetProvider, { ...bodyProps, sliceInstance: statePartition });
|
|
797
|
-
return /* @__PURE__ */ jsx(OwnChatStoreConversationWidgetProvider, { ...bodyProps });
|
|
798
|
-
};
|
|
799
|
-
const ConversationWidgetProviderBody = ({
|
|
800
|
-
children,
|
|
801
|
-
callbacks,
|
|
802
|
-
hostHasCanvasSurface = true,
|
|
803
|
-
chatState
|
|
804
|
-
}) => {
|
|
805
|
-
const dispatch = useAgentsStateDispatch();
|
|
806
|
-
const { buildChatSurfaceOpenChangedAction } = useAgentsEnvironment();
|
|
807
|
-
const { canvas, lastClosedCanvas, isConversationRunning, runState, messages } = chatState;
|
|
808
|
-
const isConversationClosed = runState === "COMPLETED" || runState === "CANCELLED";
|
|
809
|
-
const dispatchCanvasEventRef = useRef(chatState.dispatchCanvasEvent);
|
|
810
|
-
dispatchCanvasEventRef.current = chatState.dispatchCanvasEvent;
|
|
811
|
-
const hostHasCanvasSurfaceRef = useRef(hostHasCanvasSurface);
|
|
812
|
-
hostHasCanvasSurfaceRef.current = hostHasCanvasSurface;
|
|
813
|
-
const buildChatSurfaceOpenChangedActionRef = useRef(buildChatSurfaceOpenChangedAction);
|
|
814
|
-
buildChatSurfaceOpenChangedActionRef.current = buildChatSurfaceOpenChangedAction;
|
|
815
|
-
useEffect(() => {
|
|
816
|
-
agenticChatMountCount += 1;
|
|
817
|
-
if (agenticChatMountCount === 1 && buildChatSurfaceOpenChangedActionRef.current) {
|
|
818
|
-
dispatch(buildChatSurfaceOpenChangedActionRef.current(true));
|
|
819
|
-
}
|
|
820
|
-
return () => {
|
|
821
|
-
agenticChatMountCount -= 1;
|
|
822
|
-
if (agenticChatMountCount === 0 && buildChatSurfaceOpenChangedActionRef.current) {
|
|
823
|
-
dispatch(buildChatSurfaceOpenChangedActionRef.current(false));
|
|
824
|
-
}
|
|
825
|
-
};
|
|
826
|
-
}, [dispatch]);
|
|
827
|
-
const callbacksRef = useRef(callbacks);
|
|
828
|
-
callbacksRef.current = callbacks;
|
|
829
|
-
const isComposerWidgetsControlled = callbacks.composerWidgets !== void 0;
|
|
830
|
-
const [internalComposerWidgets, setInternalComposerWidgets] = useState([]);
|
|
831
|
-
const composerWidgets = isComposerWidgetsControlled ? callbacks.composerWidgets : internalComposerWidgets;
|
|
832
|
-
const composerWidgetsStateRef = useRef({ composerWidgets, isComposerWidgetsControlled });
|
|
833
|
-
composerWidgetsStateRef.current = { composerWidgets, isComposerWidgetsControlled };
|
|
834
|
-
const publishComposerWidgets = useCallback((next) => {
|
|
835
|
-
if (composerWidgetsStateRef.current.isComposerWidgetsControlled) {
|
|
836
|
-
callbacksRef.current.onComposerWidgetsChange?.(next);
|
|
837
|
-
} else {
|
|
838
|
-
setInternalComposerWidgets(next);
|
|
839
|
-
}
|
|
840
|
-
}, []);
|
|
841
|
-
const addComposerWidget = useCallback(
|
|
842
|
-
(widgetName, fields) => {
|
|
843
|
-
const composerWidgetId = crypto.randomUUID();
|
|
844
|
-
publishComposerWidgets([
|
|
845
|
-
...composerWidgetsStateRef.current.composerWidgets,
|
|
846
|
-
{ composerWidgetId, widgetName, fields }
|
|
847
|
-
]);
|
|
848
|
-
return composerWidgetId;
|
|
849
|
-
},
|
|
850
|
-
[publishComposerWidgets]
|
|
851
|
-
);
|
|
852
|
-
const replaceComposerWidgetFields = useCallback(
|
|
853
|
-
(composerWidgetId, fields) => {
|
|
854
|
-
publishComposerWidgets(
|
|
855
|
-
composerWidgetsStateRef.current.composerWidgets.map(
|
|
856
|
-
(widget) => widget.composerWidgetId === composerWidgetId ? { ...widget, fields } : widget
|
|
857
|
-
)
|
|
858
|
-
);
|
|
859
|
-
},
|
|
860
|
-
[publishComposerWidgets]
|
|
861
|
-
);
|
|
862
|
-
const removeComposerWidget = useCallback(
|
|
863
|
-
(composerWidgetId) => {
|
|
864
|
-
publishComposerWidgets(
|
|
865
|
-
composerWidgetsStateRef.current.composerWidgets.filter(
|
|
866
|
-
(widget) => widget.composerWidgetId !== composerWidgetId
|
|
867
|
-
)
|
|
868
|
-
);
|
|
869
|
-
},
|
|
870
|
-
[publishComposerWidgets]
|
|
871
|
-
);
|
|
872
|
-
const clearComposerWidgets = useCallback(() => {
|
|
873
|
-
publishComposerWidgets([]);
|
|
874
|
-
}, [publishComposerWidgets]);
|
|
875
|
-
const openCanvas = useCallback(
|
|
876
|
-
(request) => {
|
|
877
|
-
dispatchCanvasEventRef.current({
|
|
878
|
-
type: "canvasOpened",
|
|
879
|
-
request: {
|
|
880
|
-
...request,
|
|
881
|
-
viewportViable: window.innerWidth >= CANVAS_VIABLE_MIN_WIDTH,
|
|
882
|
-
hostHasCanvasSurface: hostHasCanvasSurfaceRef.current
|
|
883
|
-
}
|
|
884
|
-
});
|
|
885
|
-
},
|
|
886
|
-
[]
|
|
887
|
-
);
|
|
888
|
-
const closeCanvas = useCallback(
|
|
889
|
-
(byCustomer) => {
|
|
890
|
-
dispatchCanvasEventRef.current({ type: "canvasClosed", byCustomer });
|
|
891
|
-
},
|
|
892
|
-
[]
|
|
893
|
-
);
|
|
894
|
-
const lastClosedCanvasRef = useRef(lastClosedCanvas);
|
|
895
|
-
lastClosedCanvasRef.current = lastClosedCanvas;
|
|
896
|
-
const reopenLastClosedCanvas = useCallback(() => {
|
|
897
|
-
const last = lastClosedCanvasRef.current;
|
|
898
|
-
if (last === null) return;
|
|
899
|
-
dispatchCanvasEventRef.current({
|
|
900
|
-
type: "canvasOpened",
|
|
901
|
-
request: {
|
|
902
|
-
canvasId: last.canvasId,
|
|
903
|
-
instanceId: last.instanceId,
|
|
904
|
-
anchor: last.anchor,
|
|
905
|
-
origin: "cardClick",
|
|
906
|
-
justDelivered: false,
|
|
907
|
-
viewportViable: window.innerWidth >= CANVAS_VIABLE_MIN_WIDTH,
|
|
908
|
-
hostHasCanvasSurface: hostHasCanvasSurfaceRef.current,
|
|
909
|
-
...last.createdEntityId !== void 0 ? { createdEntityId: last.createdEntityId } : {}
|
|
910
|
-
}
|
|
911
|
-
});
|
|
912
|
-
}, []);
|
|
913
|
-
const setCanvasCreatedEntityId = useCallback(
|
|
914
|
-
(created) => {
|
|
915
|
-
dispatchCanvasEventRef.current({ type: "canvasCreatedEntityIdSet", created });
|
|
916
|
-
},
|
|
917
|
-
[]
|
|
918
|
-
);
|
|
919
|
-
const storedCanvasConversationIdRef = useRef(void 0);
|
|
920
|
-
const conversationIdForStorage = callbacks.conversationId;
|
|
921
|
-
useEffect(() => {
|
|
922
|
-
if (canvas !== null) {
|
|
923
|
-
storeOpenCanvas(conversationIdForStorage, canvas);
|
|
924
|
-
storedCanvasConversationIdRef.current = conversationIdForStorage;
|
|
925
|
-
return;
|
|
926
|
-
}
|
|
927
|
-
if (storedCanvasConversationIdRef.current !== void 0 && storedCanvasConversationIdRef.current === conversationIdForStorage) {
|
|
928
|
-
clearStoredCanvas(conversationIdForStorage);
|
|
929
|
-
}
|
|
930
|
-
storedCanvasConversationIdRef.current = void 0;
|
|
931
|
-
}, [canvas, conversationIdForStorage]);
|
|
932
|
-
const resetCanvas = useCallback(() => {
|
|
933
|
-
dispatchCanvasEventRef.current({ type: "canvasCleared" });
|
|
934
|
-
}, []);
|
|
935
|
-
const resetCanvasForNewTurn = useCallback(() => {
|
|
936
|
-
dispatchCanvasEventRef.current({ type: "canvasResetForNewTurn" });
|
|
937
|
-
}, []);
|
|
938
|
-
const sendMessageToChat = useCallback((message2) => {
|
|
939
|
-
return callbacksRef.current.sendMessageToChat?.(message2);
|
|
940
|
-
}, []);
|
|
941
|
-
const prefillComposer = useCallback((text) => {
|
|
942
|
-
callbacksRef.current.prefillComposer?.(text);
|
|
943
|
-
}, []);
|
|
944
|
-
const injectSignal = useCallback((signalText, options) => {
|
|
945
|
-
return callbacksRef.current.injectSignal?.(signalText, options);
|
|
946
|
-
}, []);
|
|
947
|
-
const minimizeChatHost = useCallback(() => {
|
|
948
|
-
callbacksRef.current.minimizeChatHost?.();
|
|
949
|
-
}, []);
|
|
950
|
-
const contextValue = useMemo(
|
|
951
|
-
() => ({
|
|
952
|
-
canvas,
|
|
953
|
-
hostHasCanvasSurface,
|
|
954
|
-
lastClosedCanvas,
|
|
955
|
-
openCanvas,
|
|
956
|
-
closeCanvas,
|
|
957
|
-
reopenLastClosedCanvas,
|
|
958
|
-
setCanvasCreatedEntityId,
|
|
959
|
-
resetCanvas,
|
|
960
|
-
resetCanvasForNewTurn,
|
|
961
|
-
sendMessageToChat,
|
|
962
|
-
prefillComposer,
|
|
963
|
-
injectSignal,
|
|
964
|
-
minimizeChatHost,
|
|
965
|
-
chatAgentSpaceKey: callbacks.chatAgentSpaceKey,
|
|
966
|
-
isConversationRunning,
|
|
967
|
-
isConversationClosed,
|
|
968
|
-
conversationId: callbacks.conversationId,
|
|
969
|
-
composerWidgets,
|
|
970
|
-
addComposerWidget,
|
|
971
|
-
replaceComposerWidgetFields,
|
|
972
|
-
removeComposerWidget,
|
|
973
|
-
clearComposerWidgets,
|
|
974
|
-
onOpenConversation: callbacks.onOpenConversation,
|
|
975
|
-
onSwitchConversation: callbacks.onSwitchConversation,
|
|
976
|
-
isOnboardingSetupConversation: callbacks.isOnboardingSetupConversation ?? false,
|
|
977
|
-
messages
|
|
978
|
-
}),
|
|
979
|
-
[
|
|
980
|
-
canvas,
|
|
981
|
-
hostHasCanvasSurface,
|
|
982
|
-
lastClosedCanvas,
|
|
983
|
-
openCanvas,
|
|
984
|
-
closeCanvas,
|
|
985
|
-
reopenLastClosedCanvas,
|
|
986
|
-
setCanvasCreatedEntityId,
|
|
987
|
-
resetCanvas,
|
|
988
|
-
resetCanvasForNewTurn,
|
|
989
|
-
sendMessageToChat,
|
|
990
|
-
prefillComposer,
|
|
991
|
-
injectSignal,
|
|
992
|
-
minimizeChatHost,
|
|
993
|
-
callbacks.chatAgentSpaceKey,
|
|
994
|
-
isConversationRunning,
|
|
995
|
-
isConversationClosed,
|
|
996
|
-
callbacks.conversationId,
|
|
997
|
-
composerWidgets,
|
|
998
|
-
addComposerWidget,
|
|
999
|
-
replaceComposerWidgetFields,
|
|
1000
|
-
removeComposerWidget,
|
|
1001
|
-
clearComposerWidgets,
|
|
1002
|
-
callbacks.onOpenConversation,
|
|
1003
|
-
callbacks.onSwitchConversation,
|
|
1004
|
-
callbacks.isOnboardingSetupConversation,
|
|
1005
|
-
messages
|
|
1006
|
-
]
|
|
1007
|
-
);
|
|
1008
|
-
return /* @__PURE__ */ jsx(ConversationWidgetContext.Provider, { value: contextValue, children });
|
|
1009
|
-
};
|
|
1010
387
|
const chat = "agents_chat_fuWV-c";
|
|
1011
388
|
const genericChat = "agents_genericChat_AyTt-f";
|
|
1012
389
|
const customBg = "agents_customBg_RtIJtP";
|
|
@@ -1023,7 +400,7 @@ const input = "agents_input_GCtiXU";
|
|
|
1023
400
|
const inputReplacement = "agents_inputReplacement_EAhjsv";
|
|
1024
401
|
const inputInCategory = "agents_inputInCategory_RDuOYA";
|
|
1025
402
|
const olderLoading = "agents_olderLoading_5X7nMg";
|
|
1026
|
-
const styles$
|
|
403
|
+
const styles$i = {
|
|
1027
404
|
chat,
|
|
1028
405
|
genericChat,
|
|
1029
406
|
customBg,
|
|
@@ -1053,7 +430,7 @@ const sendBlocked = "agents_sendBlocked_rNqOKm";
|
|
|
1053
430
|
const compact = "agents_compact_ZBtAbD";
|
|
1054
431
|
const collapsed = "agents_collapsed_v3Ekqz";
|
|
1055
432
|
const collapsedPillSizer = "agents_collapsedPillSizer_aqw7WI";
|
|
1056
|
-
const styles$
|
|
433
|
+
const styles$h = {
|
|
1057
434
|
inputContainer,
|
|
1058
435
|
aiGlow,
|
|
1059
436
|
editableInput,
|
|
@@ -1202,15 +579,15 @@ const ConversationMessageInput = (props) => {
|
|
|
1202
579
|
replaceComposerWidgetFields(lastWidget.composerWidgetId, nextFields);
|
|
1203
580
|
}
|
|
1204
581
|
};
|
|
1205
|
-
const handleKeyPress = (
|
|
1206
|
-
if (
|
|
582
|
+
const handleKeyPress = (e2) => {
|
|
583
|
+
if (e2.key === "Enter" && !e2.shiftKey) {
|
|
1207
584
|
if (isComposingRef.current) return;
|
|
1208
|
-
|
|
585
|
+
e2.preventDefault();
|
|
1209
586
|
handleSendMessage();
|
|
1210
587
|
return;
|
|
1211
588
|
}
|
|
1212
|
-
if (
|
|
1213
|
-
|
|
589
|
+
if (e2.key === "Backspace" && inputValue === "" && (outgoingComposerWidgets?.length ?? 0) > 0) {
|
|
590
|
+
e2.preventDefault();
|
|
1214
591
|
handleBackspaceOnEmptyInput();
|
|
1215
592
|
}
|
|
1216
593
|
};
|
|
@@ -1232,12 +609,12 @@ const ConversationMessageInput = (props) => {
|
|
|
1232
609
|
const handleBlur = () => {
|
|
1233
610
|
setIsFocused(false);
|
|
1234
611
|
};
|
|
1235
|
-
const handleContainerMouseDown = (
|
|
1236
|
-
const target =
|
|
612
|
+
const handleContainerMouseDown = (e2) => {
|
|
613
|
+
const target = e2.target;
|
|
1237
614
|
if (target === inputRef.current || inputRef.current?.contains(target)) return;
|
|
1238
615
|
if (target.closest("button")) return;
|
|
1239
616
|
if (disabled || isProcessing) return;
|
|
1240
|
-
|
|
617
|
+
e2.preventDefault();
|
|
1241
618
|
focusInputAtEnd();
|
|
1242
619
|
};
|
|
1243
620
|
useLayoutEffect(() => {
|
|
@@ -1257,9 +634,9 @@ const ConversationMessageInput = (props) => {
|
|
|
1257
634
|
wasProcessingRef.current = isProcessing;
|
|
1258
635
|
}, [isProcessing, disabled]);
|
|
1259
636
|
useEffect(() => {
|
|
1260
|
-
const handlePasteEvent = (
|
|
1261
|
-
|
|
1262
|
-
const text =
|
|
637
|
+
const handlePasteEvent = (e2) => {
|
|
638
|
+
e2.preventDefault();
|
|
639
|
+
const text = e2.clipboardData?.getData("text/plain");
|
|
1263
640
|
if (!text) {
|
|
1264
641
|
return;
|
|
1265
642
|
}
|
|
@@ -1285,7 +662,7 @@ const ConversationMessageInput = (props) => {
|
|
|
1285
662
|
/* @__PURE__ */ jsx(
|
|
1286
663
|
GlowFrame,
|
|
1287
664
|
{
|
|
1288
|
-
className: classNames(styles$
|
|
665
|
+
className: classNames(styles$h.aiGlow),
|
|
1289
666
|
color: isMessageTooLong ? "var(--agents-danger-500)" : void 0,
|
|
1290
667
|
borderRadius: compact2 ? COMPACT_INPUT_RADIUS_PX : void 0,
|
|
1291
668
|
borderWidth: 2,
|
|
@@ -1293,9 +670,9 @@ const ConversationMessageInput = (props) => {
|
|
|
1293
670
|
children: /* @__PURE__ */ jsxs(
|
|
1294
671
|
"div",
|
|
1295
672
|
{
|
|
1296
|
-
className: classNames(styles$
|
|
1297
|
-
[styles$
|
|
1298
|
-
[styles$
|
|
673
|
+
className: classNames(styles$h.inputContainer, {
|
|
674
|
+
[styles$h.compact]: compact2,
|
|
675
|
+
[styles$h.collapsed]: compact2 && collapsed2
|
|
1299
676
|
}),
|
|
1300
677
|
onMouseDown: handleContainerMouseDown,
|
|
1301
678
|
children: [
|
|
@@ -1311,26 +688,26 @@ const ConversationMessageInput = (props) => {
|
|
|
1311
688
|
onKeyDown: handleKeyPress,
|
|
1312
689
|
onFocus: handleFocus,
|
|
1313
690
|
onBlur: handleBlur,
|
|
1314
|
-
className: `${styles$
|
|
691
|
+
className: `${styles$h.editableInput} ${!inputValue && !isFocused ? styles$h.showPlaceholder : ""}`,
|
|
1315
692
|
"data-placeholder": translatedPlaceholder,
|
|
1316
693
|
"data-testid": `${testId}-textarea`
|
|
1317
694
|
}
|
|
1318
695
|
),
|
|
1319
|
-
inputValue.length >= CHARACTER_COUNTER_SHOWN_FROM_LENGTH && /* @__PURE__ */ jsx("div", { className: styles$
|
|
696
|
+
inputValue.length >= CHARACTER_COUNTER_SHOWN_FROM_LENGTH && /* @__PURE__ */ jsx("div", { className: styles$h.statusRow, children: /* @__PURE__ */ jsx(
|
|
1320
697
|
Text,
|
|
1321
698
|
{
|
|
1322
699
|
role: "caption",
|
|
1323
700
|
translate: false,
|
|
1324
701
|
color: isMessageTooLong ? "var(--agents-danger-500)" : "var(--agents-fg-lightest)",
|
|
1325
|
-
className: styles$
|
|
702
|
+
className: styles$h.characterCounter,
|
|
1326
703
|
testId: `${testId}-character-counter`,
|
|
1327
704
|
children: `${inputValue.length.toLocaleString()} / ${MAX_MESSAGE_LENGTH.toLocaleString()}`
|
|
1328
705
|
}
|
|
1329
706
|
) }),
|
|
1330
|
-
/* @__PURE__ */ jsxs("div", { className: styles$
|
|
1331
|
-
actionsSlotStart && /* @__PURE__ */ jsx("div", { className: styles$
|
|
707
|
+
/* @__PURE__ */ jsxs("div", { className: styles$h.actions, children: [
|
|
708
|
+
actionsSlotStart && /* @__PURE__ */ jsx("div", { className: styles$h.actionsStart, children: actionsSlotStart }),
|
|
1332
709
|
actionsSlot,
|
|
1333
|
-
sendReplacementWhenEmpty && !hasSendableContent ? sendReplacementWhenEmpty : /* @__PURE__ */ jsx("div", { className: classNames({ [styles$
|
|
710
|
+
sendReplacementWhenEmpty && !hasSendableContent ? sendReplacementWhenEmpty : /* @__PURE__ */ jsx("div", { className: classNames({ [styles$h.sendBlocked]: isMessageTooLong }), children: /* @__PURE__ */ jsx(
|
|
1334
711
|
Tooltip,
|
|
1335
712
|
{
|
|
1336
713
|
text: isMessageTooLong ? "Your message is over the %maxLength% character limit" : void 0,
|
|
@@ -1356,45 +733,9 @@ const ConversationMessageInput = (props) => {
|
|
|
1356
733
|
)
|
|
1357
734
|
}
|
|
1358
735
|
),
|
|
1359
|
-
measuresCollapsedPillWidth && /* @__PURE__ */ jsx("span", { ref: collapsedPillSizerRef, className: styles$
|
|
736
|
+
measuresCollapsedPillWidth && /* @__PURE__ */ jsx("span", { ref: collapsedPillSizerRef, className: styles$h.collapsedPillSizer, "aria-hidden": "true", children: translatedPlaceholder })
|
|
1360
737
|
] });
|
|
1361
738
|
};
|
|
1362
|
-
const stripReveal$1 = "agents_stripReveal_6XAjCM";
|
|
1363
|
-
const stripRevealOpen$1 = "agents_stripRevealOpen_sWkJwh";
|
|
1364
|
-
const stripRevealInner$1 = "agents_stripRevealInner_C2VlV7";
|
|
1365
|
-
const strip$1 = "agents_strip_rKQFvx";
|
|
1366
|
-
const styles$h = {
|
|
1367
|
-
stripReveal: stripReveal$1,
|
|
1368
|
-
stripRevealOpen: stripRevealOpen$1,
|
|
1369
|
-
stripRevealInner: stripRevealInner$1,
|
|
1370
|
-
strip: strip$1
|
|
1371
|
-
};
|
|
1372
|
-
const ConversationMessageInputComposerWidgets = (props) => {
|
|
1373
|
-
const { testId = "chat-input" } = props;
|
|
1374
|
-
const { composerWidgets, replaceComposerWidgetFields, removeComposerWidget } = useConversationWidgetContext();
|
|
1375
|
-
const renderableWidgets = composerWidgets.flatMap((widget) => {
|
|
1376
|
-
const entry = conversationWidgetRegistry.widgets.find((candidate) => candidate.name === widget.widgetName);
|
|
1377
|
-
return entry?.composerComponent ? [{ widget, Component: entry.composerComponent }] : [];
|
|
1378
|
-
});
|
|
1379
|
-
return /* @__PURE__ */ jsx(
|
|
1380
|
-
"div",
|
|
1381
|
-
{
|
|
1382
|
-
className: classNames(styles$h.stripReveal, { [styles$h.stripRevealOpen]: renderableWidgets.length > 0 }),
|
|
1383
|
-
"data-testid": `${testId}-composer-widgets-strip`,
|
|
1384
|
-
children: /* @__PURE__ */ jsx("div", { className: styles$h.stripRevealInner, children: /* @__PURE__ */ jsx("div", { className: styles$h.strip, children: renderableWidgets.map(({ widget, Component }) => /* @__PURE__ */ jsx(
|
|
1385
|
-
Component,
|
|
1386
|
-
{
|
|
1387
|
-
composerWidgetId: widget.composerWidgetId,
|
|
1388
|
-
fields: widget.fields,
|
|
1389
|
-
replaceFields: (nextFields) => replaceComposerWidgetFields(widget.composerWidgetId, nextFields),
|
|
1390
|
-
remove: () => removeComposerWidget(widget.composerWidgetId),
|
|
1391
|
-
testId: `${testId}-composer-widget-${widget.composerWidgetId}`
|
|
1392
|
-
},
|
|
1393
|
-
widget.composerWidgetId
|
|
1394
|
-
)) }) })
|
|
1395
|
-
}
|
|
1396
|
-
);
|
|
1397
|
-
};
|
|
1398
739
|
const canvasReopenControl = "agents_canvasReopenControl_7vGS8F";
|
|
1399
740
|
const splitViewRoot = "agents_splitViewRoot_OfrSES";
|
|
1400
741
|
const splitViewPane = "agents_splitViewPane_YSX5Rp";
|
|
@@ -1865,17 +1206,6 @@ const widgetNamesInMarkdown = (markdown) => {
|
|
|
1865
1206
|
}
|
|
1866
1207
|
return names;
|
|
1867
1208
|
};
|
|
1868
|
-
const FRONTEND_WIDGET_CLICK_SIGNAL_SOURCE = "FRONTEND_WIDGET_CLICK";
|
|
1869
|
-
const OWNER_ACTION_CONFIRM_SIGNAL_SOURCE = "OWNER_ACTION_CONFIRM";
|
|
1870
|
-
const PACKAGE_WIDGET_CLICK_SIGNAL_SOURCES = [
|
|
1871
|
-
FRONTEND_WIDGET_CLICK_SIGNAL_SOURCE,
|
|
1872
|
-
OWNER_ACTION_CONFIRM_SIGNAL_SOURCE
|
|
1873
|
-
];
|
|
1874
|
-
const getWidgetClickSignalSources = () => [
|
|
1875
|
-
...PACKAGE_WIDGET_CLICK_SIGNAL_SOURCES,
|
|
1876
|
-
...getFurtherWidgetClickSignalSources()
|
|
1877
|
-
];
|
|
1878
|
-
const isWidgetClickSignalSource = (signalSource) => signalSource != null && getWidgetClickSignalSources().includes(signalSource);
|
|
1879
1209
|
const isBareUnknownTypeJson = (markdown) => {
|
|
1880
1210
|
if (!markdown.startsWith("{")) return false;
|
|
1881
1211
|
let parsed;
|
|
@@ -2558,7 +1888,7 @@ const ConversationViewBody = (props) => {
|
|
|
2558
1888
|
);
|
|
2559
1889
|
const { readAssistantThemeClassName, AssistantBackground } = useAgentsEnvironment();
|
|
2560
1890
|
const colorPalette = useMemo(
|
|
2561
|
-
() => currentCategory?.alias ? readAssistantThemeClassName?.(currentCategory.alias) ?? styles$
|
|
1891
|
+
() => currentCategory?.alias ? readAssistantThemeClassName?.(currentCategory.alias) ?? styles$i.genericChat : styles$i.genericChat,
|
|
2562
1892
|
[currentCategory, readAssistantThemeClassName]
|
|
2563
1893
|
);
|
|
2564
1894
|
const isMessageListVisible = !!messages && (!!conversationId || !!showMessagesWithoutConversation) || startingNewConversation || !!error && error !== ConversationErrorType.CONVERSATION_NOT_FOUND;
|
|
@@ -2763,7 +2093,7 @@ const ConversationViewBody = (props) => {
|
|
|
2763
2093
|
const messageColumn = /* @__PURE__ */ jsxs(
|
|
2764
2094
|
"div",
|
|
2765
2095
|
{
|
|
2766
|
-
className: styles$
|
|
2096
|
+
className: styles$i.contentWrapper,
|
|
2767
2097
|
"data-agents-chat-scroll": "",
|
|
2768
2098
|
"data-testid": "chat-messages-scroll",
|
|
2769
2099
|
ref: handleContentWrapperRef,
|
|
@@ -2781,11 +2111,11 @@ const ConversationViewBody = (props) => {
|
|
|
2781
2111
|
onSuggestionClick
|
|
2782
2112
|
}
|
|
2783
2113
|
) : null,
|
|
2784
|
-
!!loadingOlder ? /* @__PURE__ */ jsx("span", { className: styles$
|
|
2114
|
+
!!loadingOlder ? /* @__PURE__ */ jsx("span", { className: styles$i.olderLoading, children: /* @__PURE__ */ jsx(Text, { children: "Loading older messages…" }) }) : null,
|
|
2785
2115
|
isMessageListVisible ? /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsx(WidgetWindowRootContext.Provider, { value: scrollContainer, children: /* @__PURE__ */ jsx(
|
|
2786
2116
|
ConversationMessageList,
|
|
2787
2117
|
{
|
|
2788
|
-
className: enablePinQuestionAndRevealAnswer && (conversationId || startingNewConversation || aiThinking || error) ? styles$
|
|
2118
|
+
className: enablePinQuestionAndRevealAnswer && (conversationId || startingNewConversation || aiThinking || error) ? styles$i.topAlignedMessages : void 0,
|
|
2789
2119
|
messages,
|
|
2790
2120
|
currentCategory,
|
|
2791
2121
|
aiPromptExtension,
|
|
@@ -2812,40 +2142,40 @@ const ConversationViewBody = (props) => {
|
|
|
2812
2142
|
"div",
|
|
2813
2143
|
{
|
|
2814
2144
|
className: classNames(
|
|
2815
|
-
styles$
|
|
2816
|
-
background || backgroundPaintedByHost2 ? styles$
|
|
2817
|
-
backgroundPaintedByHost2 ? styles$
|
|
2818
|
-
isCompact ? styles$
|
|
2819
|
-
confineTopBlurBandToChatPane2 ? styles$
|
|
2145
|
+
styles$i.chat,
|
|
2146
|
+
background || backgroundPaintedByHost2 ? styles$i.customBg : colorPalette,
|
|
2147
|
+
backgroundPaintedByHost2 ? styles$i.backgroundPaintedByHost : void 0,
|
|
2148
|
+
isCompact ? styles$i.chatCompact : void 0,
|
|
2149
|
+
confineTopBlurBandToChatPane2 ? styles$i.confineTopBlurBandToChatPane : void 0
|
|
2820
2150
|
),
|
|
2821
2151
|
children: [
|
|
2822
|
-
background ? /* @__PURE__ */ jsx("div", { className: styles$
|
|
2152
|
+
background ? /* @__PURE__ */ jsx("div", { className: styles$i.backgroundLayer, children: background }) : backgroundPaintedByHost2 ? null : AssistantBackground ? /* @__PURE__ */ jsx(AssistantBackground, { category: currentCategory, categoryAlias: currentCategory?.alias ?? void 0 }) : null,
|
|
2823
2153
|
progressStepperSlot,
|
|
2824
|
-
contentOverlaySlot !== void 0 ? /* @__PURE__ */ jsxs("div", { className: styles$
|
|
2154
|
+
contentOverlaySlot !== void 0 ? /* @__PURE__ */ jsxs("div", { className: styles$i.contentLayers, "data-overlay-shown": isContentOverlayShown || void 0, children: [
|
|
2825
2155
|
messageColumn,
|
|
2826
2156
|
/* @__PURE__ */ jsx(
|
|
2827
2157
|
"div",
|
|
2828
2158
|
{
|
|
2829
|
-
className: styles$
|
|
2159
|
+
className: styles$i.contentOverlay,
|
|
2830
2160
|
"aria-hidden": !isContentOverlayShown || void 0,
|
|
2831
2161
|
inert: !isContentOverlayShown || void 0,
|
|
2832
2162
|
children: contentOverlaySlot
|
|
2833
2163
|
}
|
|
2834
2164
|
)
|
|
2835
2165
|
] }) : messageColumn,
|
|
2836
|
-
enablePinQuestionAndRevealAnswer && /* @__PURE__ */ jsx("div", { className: styles$
|
|
2166
|
+
enablePinQuestionAndRevealAnswer && /* @__PURE__ */ jsx("div", { className: styles$i.scrollToLatestAnchor, children: /* @__PURE__ */ jsx(
|
|
2837
2167
|
ConversationScrollToLatestMessageButton,
|
|
2838
2168
|
{
|
|
2839
2169
|
visible: isMessagesBottomOutOfView,
|
|
2840
2170
|
onClick: scrollToLatestMessage
|
|
2841
2171
|
}
|
|
2842
2172
|
) }),
|
|
2843
|
-
inputReplacementSlot ? /* @__PURE__ */ jsx("div", { className: styles$
|
|
2173
|
+
inputReplacementSlot ? /* @__PURE__ */ jsx("div", { className: styles$i.inputReplacement, children: inputReplacementSlot }) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
2844
2174
|
inputBandSlot,
|
|
2845
2175
|
/* @__PURE__ */ jsx(
|
|
2846
2176
|
ConversationMessageInput,
|
|
2847
2177
|
{
|
|
2848
|
-
className: classNames(styles$
|
|
2178
|
+
className: classNames(styles$i.input, currentCategory?.alias ? styles$i.inputInCategory : void 0),
|
|
2849
2179
|
isProcessing: allowSendWhileAiThinking ? !!startingNewConversation : aiThinking,
|
|
2850
2180
|
onSendMessage,
|
|
2851
2181
|
actionsSlot: inputActionsSlot,
|
|
@@ -3288,78 +2618,6 @@ const ConversationView = (props) => {
|
|
|
3288
2618
|
) : null
|
|
3289
2619
|
] });
|
|
3290
2620
|
};
|
|
3291
|
-
const DELEGATE_TOOL_NAME = "delegate";
|
|
3292
|
-
const RESOLVED_STATUSES = ["COMPLETED", "FAILED", "CANCELLED"];
|
|
3293
|
-
const isResolved = (status) => status != null && RESOLVED_STATUSES.includes(status);
|
|
3294
|
-
const TERMINAL_RUN_STATES = ["COMPLETED", "FAILED", "CANCELLED"];
|
|
3295
|
-
const UNRESOLVED_RUN_STATUSES = ["QUEUED", "RUNNING"];
|
|
3296
|
-
const isEffectivelyResolved = (message2) => {
|
|
3297
|
-
if (message2 == null) return false;
|
|
3298
|
-
if (isResolved(message2.toolCall?.status)) return true;
|
|
3299
|
-
if (message2.toolCall?.name !== DELEGATE_TOOL_NAME) return false;
|
|
3300
|
-
const children = message2.delegatedConversations ?? [];
|
|
3301
|
-
if (children.length === 0) return false;
|
|
3302
|
-
const declaredTasks = message2.toolCall?.arguments?.tasks;
|
|
3303
|
-
if (Array.isArray(declaredTasks) && declaredTasks.length > children.length) return false;
|
|
3304
|
-
return children.every((child) => TERMINAL_RUN_STATES.includes(child.runState ?? ""));
|
|
3305
|
-
};
|
|
3306
|
-
const countOutstandingChildren = (message2) => {
|
|
3307
|
-
const children = message2.delegatedConversations ?? [];
|
|
3308
|
-
if (children.length > 0) {
|
|
3309
|
-
return children.filter((child) => !TERMINAL_RUN_STATES.includes(child.runState ?? "")).length;
|
|
3310
|
-
}
|
|
3311
|
-
if (message2.toolCall?.name !== DELEGATE_TOOL_NAME) {
|
|
3312
|
-
return 0;
|
|
3313
|
-
}
|
|
3314
|
-
const subAgent = message2.subAgent;
|
|
3315
|
-
if (subAgent != null) {
|
|
3316
|
-
const currentRun = (subAgent.runs ?? []).find((run) => run.runNumber === subAgent.currentRunNumber);
|
|
3317
|
-
return currentRun != null && UNRESOLVED_RUN_STATUSES.includes(currentRun.status ?? "") ? 1 : 0;
|
|
3318
|
-
}
|
|
3319
|
-
if (isResolved(message2.toolCall?.status)) {
|
|
3320
|
-
return 0;
|
|
3321
|
-
}
|
|
3322
|
-
const declaredTasks = message2.toolCall?.arguments?.tasks;
|
|
3323
|
-
return Array.isArray(declaredTasks) && declaredTasks.length > 0 ? declaredTasks.length : 1;
|
|
3324
|
-
};
|
|
3325
|
-
const hasUnresolvedToolCall = (message2) => message2.toolCall != null && !isEffectivelyResolved(message2);
|
|
3326
|
-
const hasDelegationInFlight = (message2) => countOutstandingChildren(message2) > 0 || message2.toolCall?.name === DELEGATE_TOOL_NAME && !isEffectivelyResolved(message2);
|
|
3327
|
-
const deriveAgentActivity = (messages, runStatus) => {
|
|
3328
|
-
if (runStatus === "failed") {
|
|
3329
|
-
return { active: false, label: "" };
|
|
3330
|
-
}
|
|
3331
|
-
const sorted = [...messages ?? []].sort(
|
|
3332
|
-
(a, b) => (a.indexInConversation ?? Number.POSITIVE_INFINITY) - (b.indexInConversation ?? Number.POSITIVE_INFINITY)
|
|
3333
|
-
);
|
|
3334
|
-
const lastMessage = sorted[sorted.length - 1];
|
|
3335
|
-
if (lastMessage?.role === "USER") {
|
|
3336
|
-
return { active: true, label: "" };
|
|
3337
|
-
}
|
|
3338
|
-
const unresolvedDelegateCount = sorted.reduce((count, message2) => count + countOutstandingChildren(message2), 0);
|
|
3339
|
-
if (runStatus === "idle" && unresolvedDelegateCount === 0) {
|
|
3340
|
-
return { active: false, label: "" };
|
|
3341
|
-
}
|
|
3342
|
-
if (unresolvedDelegateCount > 0) {
|
|
3343
|
-
return {
|
|
3344
|
-
active: true,
|
|
3345
|
-
label: "Waiting for %count% delegations...",
|
|
3346
|
-
replacements: { count: unresolvedDelegateCount },
|
|
3347
|
-
context: unresolvedDelegateCount === 1 ? "one" : "other"
|
|
3348
|
-
};
|
|
3349
|
-
}
|
|
3350
|
-
if (lastMessage?.messageType === "TOOL_CALL" && !isEffectivelyResolved(lastMessage)) {
|
|
3351
|
-
return {
|
|
3352
|
-
active: true,
|
|
3353
|
-
label: "Running: %tool%...",
|
|
3354
|
-
replacements: { tool: lastMessage.toolCall?.name ?? "Tool" },
|
|
3355
|
-
toolRunning: true
|
|
3356
|
-
};
|
|
3357
|
-
}
|
|
3358
|
-
if (runStatus === "running") {
|
|
3359
|
-
return { active: true, label: "" };
|
|
3360
|
-
}
|
|
3361
|
-
return { active: false, label: "" };
|
|
3362
|
-
};
|
|
3363
2621
|
const pickPendingStartRequest = (pendingStartUserMessage, pendingStartSignalText) => {
|
|
3364
2622
|
if (pendingStartUserMessage) {
|
|
3365
2623
|
return { kind: "message", text: pendingStartUserMessage };
|
|
@@ -3977,23 +3235,6 @@ const useAgentsConversationRunStatus = (client, conversationId) => {
|
|
|
3977
3235
|
}, [client, conversationId]);
|
|
3978
3236
|
return runStatus;
|
|
3979
3237
|
};
|
|
3980
|
-
const CHANGING_STATUSES = ["PENDING", "RUNNING", "CANCEL_REQUESTED"];
|
|
3981
|
-
const canStillChange = (message2) => CHANGING_STATUSES.includes(message2.status ?? "") || hasUnresolvedToolCall(message2) || hasDelegationInFlight(message2);
|
|
3982
|
-
const buildChangedMessagesRequest = (messages, pageSize) => {
|
|
3983
|
-
const loaded = (messages ?? []).filter((message2) => message2.indexInConversation != null);
|
|
3984
|
-
if (loaded.length === 0) {
|
|
3985
|
-
return null;
|
|
3986
|
-
}
|
|
3987
|
-
const indexes = (list) => list.map((message2) => message2.indexInConversation);
|
|
3988
|
-
const highestIndex = Math.max(...indexes(loaded));
|
|
3989
|
-
const changing = loaded.filter(canStillChange);
|
|
3990
|
-
const fromIndex = Math.max(
|
|
3991
|
-
changing.length > 0 ? Math.min(...indexes(changing)) : highestIndex + 1,
|
|
3992
|
-
highestIndex - pageSize + 1
|
|
3993
|
-
);
|
|
3994
|
-
const highestKnownId = Math.max(...loaded.map((message2) => message2.id ?? 0));
|
|
3995
|
-
return { highestKnownId, fromIndex, pageSize };
|
|
3996
|
-
};
|
|
3997
3238
|
const CONVERSATION_MESSAGE_PAGE_SIZE = 50;
|
|
3998
3239
|
const useConversationMessagePages = (chatStore, client, pageSize = CONVERSATION_MESSAGE_PAGE_SIZE) => {
|
|
3999
3240
|
const openingPageRef = useRef(null);
|
|
@@ -5174,11 +4415,12 @@ export {
|
|
|
5174
4415
|
AgentChatActivityHistory,
|
|
5175
4416
|
AgentChatActivityIndicator,
|
|
5176
4417
|
AgentChatController,
|
|
5177
|
-
AgentsChatStateContainer,
|
|
5178
|
-
AgentsChatStoreProvider,
|
|
4418
|
+
A as AgentsChatStateContainer,
|
|
4419
|
+
d as AgentsChatStoreProvider,
|
|
5179
4420
|
CanvasPane,
|
|
5180
4421
|
CanvasRestoreOnMount,
|
|
5181
4422
|
ConversationClosedBar,
|
|
4423
|
+
ConversationDeepLinkedWidget,
|
|
5182
4424
|
ConversationErrorCard,
|
|
5183
4425
|
ConversationErrorType,
|
|
5184
4426
|
ConversationMessageInput,
|
|
@@ -5190,24 +4432,26 @@ export {
|
|
|
5190
4432
|
ConversationMessageWidgets,
|
|
5191
4433
|
ConversationView,
|
|
5192
4434
|
ConversationWidgetProvider,
|
|
5193
|
-
EMPTY_AGENTS_CHAT_OPENING_REQUEST,
|
|
5194
|
-
INITIAL_AGENTS_CHAT_STATE,
|
|
4435
|
+
E as EMPTY_AGENTS_CHAT_OPENING_REQUEST,
|
|
4436
|
+
I as INITIAL_AGENTS_CHAT_STATE,
|
|
5195
4437
|
MAX_MESSAGE_LENGTH,
|
|
4438
|
+
PHONE_CALL_LIFECYCLE_SIGNAL_SOURCES,
|
|
4439
|
+
SIGNAL_SOURCES_THAT_OWE_NO_WORK,
|
|
5196
4440
|
SUCCESS_BEAT_MS,
|
|
5197
4441
|
createAgentsChatStore,
|
|
5198
4442
|
deriveAgentActivity,
|
|
5199
4443
|
formatElapsedClock,
|
|
5200
4444
|
isStepStillRunning,
|
|
5201
4445
|
normalizeServerMessageToMarkdown,
|
|
5202
|
-
readConversationErrorTypeOfRefusedSend,
|
|
5203
|
-
reduceAgentsChatState,
|
|
4446
|
+
r as readConversationErrorTypeOfRefusedSend,
|
|
4447
|
+
e as reduceAgentsChatState,
|
|
5204
4448
|
useActivityTicker,
|
|
5205
4449
|
useAgentsChatSelector,
|
|
5206
|
-
useAgentsChatState,
|
|
5207
|
-
useAgentsChatStore,
|
|
4450
|
+
f as useAgentsChatState,
|
|
4451
|
+
g as useAgentsChatStore,
|
|
5208
4452
|
useAgentsConversationRunStatus,
|
|
5209
4453
|
useConversationMessageSearch,
|
|
5210
4454
|
useConversationsSearch,
|
|
5211
|
-
useOptionalAgentsChatStore
|
|
4455
|
+
h as useOptionalAgentsChatStore
|
|
5212
4456
|
};
|
|
5213
4457
|
//# sourceMappingURL=chat.js.map
|