@mgamadeus/ddd-agents 0.15.3 → 0.16.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.
Files changed (55) hide show
  1. package/README.md +34 -1
  2. package/dist/admin.js +258 -15
  3. package/dist/admin.js.map +1 -1
  4. package/dist/chat.js +221 -63
  5. package/dist/chat.js.map +1 -1
  6. package/dist/chunks/{agents-http-trace-mappers-BYEpNy0b.js → agents-http-trace-mappers-rsbGAf2_.js} +64 -14
  7. package/dist/chunks/agents-http-trace-mappers-rsbGAf2_.js.map +1 -0
  8. package/dist/chunks/{content-from-unified-diff-Dzsh8kR2.js → content-from-unified-diff-DWyBHRSy.js} +233 -63
  9. package/dist/chunks/content-from-unified-diff-DWyBHRSy.js.map +1 -0
  10. package/dist/chunks/{contract-IQHESBXq.js → contract-DtFmOk91.js} +5 -3
  11. package/dist/chunks/contract-DtFmOk91.js.map +1 -0
  12. package/dist/chunks/{conversation-B7-evdj_.js → conversation-Cbrqtx-_.js} +6 -2
  13. package/dist/chunks/{conversation-B7-evdj_.js.map → conversation-Cbrqtx-_.js.map} +1 -1
  14. package/dist/chunks/conversation-trace-fVeh6Lg6.js.map +1 -1
  15. package/dist/chunks/{withPollingChangeSubscription-XvCpjGmd.js → withPollingChangeSubscription-Cz3Diolr.js} +10 -2
  16. package/dist/chunks/withPollingChangeSubscription-Cz3Diolr.js.map +1 -0
  17. package/dist/client-testing.js +22 -2
  18. package/dist/client-testing.js.map +1 -1
  19. package/dist/client.js +23 -11
  20. package/dist/client.js.map +1 -1
  21. package/dist/contract.js +5 -3
  22. package/dist/files/i18n-keys.json +807 -13
  23. package/dist/styles.css +73 -1
  24. package/dist/types/admin/conversations/AgentConversationDetailScreen.d.ts +1 -1
  25. package/dist/types/admin/conversations/BackgroundJobsPanel.d.ts +28 -0
  26. package/dist/types/admin/conversations/agent-inspect-api.d.ts +13 -1
  27. package/dist/types/admin/conversations/agent-inspect-mappers.d.ts +3 -1
  28. package/dist/types/admin/conversations/agent-inspect-types.d.ts +45 -0
  29. package/dist/types/chat/controller/use-conversation-activity.d.ts +13 -1
  30. package/dist/types/chat/trace/ConversationTurnTrace.d.ts +4 -2
  31. package/dist/types/chat/trace/RunningBackgroundJobLines.d.ts +19 -0
  32. package/dist/types/chat/trace/StepKindDetails.d.ts +11 -1
  33. package/dist/types/chat/trace/ToolStepDetail.d.ts +2 -0
  34. package/dist/types/chat/trace/UntrustedContentText.d.ts +11 -0
  35. package/dist/types/chat/trace/index.d.ts +4 -2
  36. package/dist/types/chat/trace/running-background-jobs-context.d.ts +20 -0
  37. package/dist/types/chat/trace/trace-counts.d.ts +2 -0
  38. package/dist/types/chat/trace/trace-labels.d.ts +15 -2
  39. package/dist/types/chat/trace/trace-types.d.ts +22 -0
  40. package/dist/types/chat/trace/untrusted-content.d.ts +23 -0
  41. package/dist/types/client/AgentsConversationClient.d.ts +8 -1
  42. package/dist/types/client/http/agents-http-mappers.d.ts +8 -2
  43. package/dist/types/client/http/agents-http-trace-mappers.d.ts +4 -2
  44. package/dist/types/client/http/agents-http-trace-wire.d.ts +18 -0
  45. package/dist/types/client/http/agents-http-wire.d.ts +18 -0
  46. package/dist/types/client/testing/createInMemoryAgentsConversationClient.d.ts +6 -1
  47. package/dist/types/contract/conversation-trace.d.ts +30 -0
  48. package/dist/types/contract/conversation.d.ts +45 -0
  49. package/dist/types/entries/admin.d.ts +3 -2
  50. package/package.json +1 -1
  51. package/public-api.json +31 -0
  52. package/dist/chunks/agents-http-trace-mappers-BYEpNy0b.js.map +0 -1
  53. package/dist/chunks/content-from-unified-diff-Dzsh8kR2.js.map +0 -1
  54. package/dist/chunks/contract-IQHESBXq.js.map +0 -1
  55. package/dist/chunks/withPollingChangeSubscription-XvCpjGmd.js.map +0 -1
package/dist/chat.js CHANGED
@@ -1,10 +1,10 @@
1
1
  "use client";
2
2
  import { jsx, jsxs, Fragment as Fragment$1 } from "react/jsx-runtime";
3
- import { useRef, useEffect, useMemo, useState, useImperativeHandle, useLayoutEffect, memo, useCallback, Fragment, useReducer, useSyncExternalStore } from "react";
3
+ import { useRef, useEffect, useMemo, useState, useImperativeHandle, useLayoutEffect, memo, useCallback, Fragment, useReducer, createContext, useContext, useSyncExternalStore } from "react";
4
4
  import { u as useAgentsConversationClient, a as useOptionalAgentsConversationClient, A as AgentsConversationClientProvider } from "./chunks/AgentsConversationClientContext-B_UJSLXU.js";
5
- import { w as withPollingChangeSubscription } from "./chunks/withPollingChangeSubscription-XvCpjGmd.js";
5
+ import { w as withPollingChangeSubscription } from "./chunks/withPollingChangeSubscription-Cz3Diolr.js";
6
6
  import { r as Text, E as classNames, I as Icon, a9 as useAgentsTexts, G as GlowFrame, u as Tooltip, B as Button, m as Skeleton, i as Markdown, a0 as translateText, a6 as useAgentsOwnerSettings, J as getAgentDisplayName, a2 as useAgentsBudgetLimit, a4 as useAgentsEnvironment, g as InteractiveSurface, L as LoadingSpinner, o as SplitView, Z as reportRunningTurn, a1 as useAgentsActiveAgentSpaceKey, P as ProgressBar } from "./chunks/index-DZovGMpG.js";
7
- import { i as isAgentsClientError, A as AgentsClientError } from "./chunks/conversation-B7-evdj_.js";
7
+ import { i as isAgentsClientError, A as AgentsClientError } from "./chunks/conversation-Cbrqtx-_.js";
8
8
  import { n as normalizeServerMessageToMarkdown, V as VoiceBarsIcon, b as ConversationMessageHeader, a as ConversationMessageUser, C as ConversationMessageWidgets } from "./chunks/VoiceBarsIcon-eODB_UTI.js";
9
9
  import { a1 as useConversationWidgetContext, j as canvasBehaviourOf, J as canvasKindOpenerWidgetNamesOf, p as payloadHashOfInstanceId, A as buildWidgetAgentSpaceKeyProps, C as CANVAS_BOXED_INSET_PX, t as CHAT_COLUMN_MIN_WIDTH_PX, q as CANVAS_MIN_WIDTH_PX, bg as useCanvasViable, D as DEFAULT_CANVAS_WIDTH_PERCENT, K as canvasWidthPercentOf, aq as ElementWidthCanvasViability, ae as CanvasViabilityContext } from "./chunks/WebSearchResultsConversationWidget-l9Aek_lG.js";
10
10
  import { j as conversationWidgetRegistry, n as findWidgetFencesInMarkdown, o as ConversationWidgetErrorBoundary, p as ConversationWidgetFeatureGate, T as parseWidgetJsonObject, F as resolveCanonicalWidgetName, W as WIDGET_FENCE_LANG, y as getConversationWidgetRegistryRevision, U as BARE_WIDGET_LINE_GLOBAL, G as resolveWidgetName, t as closestWidgetNames } from "./chunks/widget-name-resolver-DXIE9JUr.js";
@@ -13,10 +13,10 @@ import { r as resolveDeepLinkableWidget, i as isWidgetClickSignalSource, a as Ca
13
13
  import { b as ConversationErrorType, a as ConversationMessageInputComposerWidgets, C as ConversationWidgetProvider, c as createAgentsChatStore } from "./chunks/ConversationMessageInputComposerWidgets-BlpIule7.js";
14
14
  import { A, E, I, r, d } from "./chunks/ConversationMessageInputComposerWidgets-BlpIule7.js";
15
15
  import { c as buildMessageTextWithComposerWidgets, e as WidgetWindowRootContext, f as findBalancedJsonObjectEnd, d as buildWidgetRenderReportSignal, W as WIDGET_RENDER_REPORT_SIGNAL_SOURCE, g as createWidgetRenderReportCollector, h as WidgetRenderReportCollectorContext } from "./chunks/ConversationMarkdown-DNQcVuz-.js";
16
- import { S as SIGNAL_SOURCES_THAT_OWE_NO_WORK, P as PHONE_CALL_LIFECYCLE_SIGNAL_SOURCES, l as lastWireMessageIsUnansweredUserMessage, b as buildChangedMessagesRequest, d as deriveAgentActivity } from "./chunks/contract-IQHESBXq.js";
16
+ import { S as SIGNAL_SOURCES_THAT_OWE_NO_WORK, P as PHONE_CALL_LIFECYCLE_SIGNAL_SOURCES, l as lastWireMessageIsUnansweredUserMessage, b as buildChangedMessagesRequest, d as deriveAgentActivity } from "./chunks/contract-DtFmOk91.js";
17
17
  import { t as textKey } from "./chunks/text-key-DnoZ4lAk.js";
18
- import { r as readTraceMoment, s as styles$m, u as useTraceFormat, a as useTraceNow, b as agentStyles, T as TraceStateIcon, f as formatTraceClock, c as readTraceStateLabel, d as styles$n, F as FileChangesSummary, e as readTraceFileChangeLetter, g as readTraceFileChangeWord, h as TracePath, i as TraceMountChip, j as TraceLink, k as FileEditBlock, E as EntityChip, l as selectVisibleTraceSteps, m as TraceStepRow, n as TaskPlanRow$1, o as readTaskPlanCountsOfStep, p as buildTaskPlanItems, q as describeStepCount, M as MIN_SHOWN_TURN_DURATION_MS, t as TurnMetaLine, v as ToolStepGroup, w as readTaskPlanCounts, x as describeTaskPlanProgress, y as isTraceBackgroundJobLabel, z as readTraceSubAgentState, A as describeTraceBackgroundJob, B as readTraceStepState } from "./chunks/content-from-unified-diff-Dzsh8kR2.js";
19
- import { C, D, L, S, G, H, I as I2, J, K, N, O, P, Q, R, U, V, W, X, Y, Z, _, $, a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, aa, ab, ac, ad, ae, af, ag, ah, ai, aj, ak, al, am, an, ao, ap, aq, ar } from "./chunks/content-from-unified-diff-Dzsh8kR2.js";
18
+ import { r as readTraceMoment, s as styles$m, u as useTraceFormat, a as useTraceNow, b as agentStyles, T as TraceStateIcon, f as formatTraceClock, c as readTraceStateLabel, d as styles$n, F as FileChangesSummary, e as readTraceFileChangeLetter, g as readTraceFileChangeWord, h as TracePath, i as TraceMountChip, j as TraceLink, k as FileEditBlock, E as EntityChip, l as selectVisibleTraceSteps, m as TraceStepRow, n as TaskPlanRow$1, o as readTaskPlanCountsOfStep, p as buildTaskPlanItems, q as describeStepCount, M as MIN_SHOWN_TURN_DURATION_MS, t as TurnMetaLine, v as ToolStepGroup, w as readTaskPlanCounts, x as describeTaskPlanProgress, y as isTraceBackgroundJobLabel, z as readTraceSubAgentState, A as describeTraceBackgroundJob, B as readTraceStepState } from "./chunks/content-from-unified-diff-DWyBHRSy.js";
19
+ import { C, D, G, L, S, H, I as I2, J, K, N, O, P, Q, R, U, V, W, X, Y, Z, _, $, a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, aa, ab, ac, ad, ae, af, ag, ah, ai, aj, ak, al, am, an, ao, ap, aq, ar, as, at } from "./chunks/content-from-unified-diff-DWyBHRSy.js";
20
20
  import { c as canvasBodies } from "./chunks/canvasBodies-BpLPp-S8.js";
21
21
  import { a as canvasFeatureFlagOf } from "./chunks/canvas-feature-flags-Cn8xBliA.js";
22
22
  import { flushSync } from "react-dom";
@@ -2470,9 +2470,14 @@ const useConversationActivity = ({
2470
2470
  const [elements, setElements] = useState([]);
2471
2471
  const [running, setRunning] = useState(false);
2472
2472
  const [turnMessageId, setTurnMessageId] = useState(null);
2473
+ const [runningBackgroundJobs, setRunningBackgroundJobs] = useState([]);
2474
+ const hasRunningBackgroundJobsRef = useRef(false);
2473
2475
  const turnMessageIdRef = useRef(null);
2474
2476
  const elementsRef = useRef([]);
2475
2477
  const inFlightRef = useRef(false);
2478
+ const inFlightConversationIdRef = useRef(null);
2479
+ const conversationIdRef = useRef(conversationId);
2480
+ const openedConversationIdRef = useRef(null);
2476
2481
  const trailingRef = useRef(false);
2477
2482
  const lastRequestAtRef = useRef(0);
2478
2483
  const trailingTimerRef = useRef(null);
@@ -2491,9 +2496,11 @@ const useConversationActivity = ({
2491
2496
  return;
2492
2497
  }
2493
2498
  inFlightRef.current = true;
2499
+ inFlightConversationIdRef.current = conversationId;
2494
2500
  lastRequestAtRef.current = Date.now();
2495
2501
  try {
2496
2502
  const response = await conversationClient.getConversationActivity(conversationId, turnMessageIdRef.current);
2503
+ if (conversationIdRef.current !== conversationId) return;
2497
2504
  const answeredTurn = response.turnMessageId;
2498
2505
  const newTurn = isDifferentTurn(turnMessageIdRef.current, answeredTurn);
2499
2506
  turnMessageIdRef.current = answeredTurn;
@@ -2501,20 +2508,30 @@ const useConversationActivity = ({
2501
2508
  const merged = mergeActivityElements(newTurn ? [] : elementsRef.current, response.elements);
2502
2509
  elementsRef.current = merged;
2503
2510
  setElements(merged);
2511
+ const answeredBackgroundJobs = response.runningBackgroundJobs ?? [];
2512
+ hasRunningBackgroundJobsRef.current = answeredBackgroundJobs.length > 0;
2513
+ setRunningBackgroundJobs(answeredBackgroundJobs);
2504
2514
  consecutiveFailedRequestsRef.current = 0;
2505
2515
  answeredRunningRef.current = response.turnRunning && runStatusRef.current !== "failed";
2506
2516
  setRunning(answeredRunningRef.current);
2507
2517
  } catch {
2518
+ if (conversationIdRef.current !== conversationId) return;
2508
2519
  consecutiveFailedRequestsRef.current += 1;
2509
- if (runStatusRef.current === "failed" || runStatusRef.current !== "running" && consecutiveFailedRequestsRef.current >= MAX_FAILED_REQUESTS_AFTER_SIGNAL_ENDED) {
2520
+ const keepsFailingAfterSignalEnded = runStatusRef.current !== "running" && consecutiveFailedRequestsRef.current >= MAX_FAILED_REQUESTS_AFTER_SIGNAL_ENDED;
2521
+ if (runStatusRef.current === "failed" || keepsFailingAfterSignalEnded) {
2510
2522
  answeredRunningRef.current = false;
2511
2523
  setRunning(false);
2512
2524
  }
2525
+ if (keepsFailingAfterSignalEnded) {
2526
+ hasRunningBackgroundJobsRef.current = false;
2527
+ setRunningBackgroundJobs([]);
2528
+ }
2513
2529
  } finally {
2514
2530
  inFlightRef.current = false;
2531
+ inFlightConversationIdRef.current = null;
2515
2532
  if (trailingRef.current) {
2516
2533
  trailingRef.current = false;
2517
- requestActivityRef.current?.();
2534
+ requestActivityRef.current?.(conversationIdRef.current !== conversationId);
2518
2535
  }
2519
2536
  }
2520
2537
  }, [conversationId, conversationClient, enabled]);
@@ -2566,12 +2583,12 @@ const useConversationActivity = ({
2566
2583
  }
2567
2584
  }, [runStatus, requestActivity]);
2568
2585
  useEffect(() => {
2569
- if (signalVersion > 0 && runningRef.current) {
2586
+ if (signalVersion > 0 && (runningRef.current || hasRunningBackgroundJobsRef.current)) {
2570
2587
  requestActivity();
2571
2588
  }
2572
2589
  }, [signalVersion, requestActivity]);
2573
2590
  useEffect(() => {
2574
- if (!enabled || runStatus !== "running" && !running) return;
2591
+ if (!enabled || runStatus !== "running" && !running && runningBackgroundJobs.length === 0) return;
2575
2592
  const interval = setInterval(() => requestActivity(), runningFloorMs);
2576
2593
  const onVisibilityChange = () => {
2577
2594
  if (!document.hidden) requestActivity(true);
@@ -2581,13 +2598,16 @@ const useConversationActivity = ({
2581
2598
  clearInterval(interval);
2582
2599
  document.removeEventListener("visibilitychange", onVisibilityChange);
2583
2600
  };
2584
- }, [enabled, runStatus, running, requestActivity, runningFloorMs]);
2601
+ }, [enabled, runStatus, running, runningBackgroundJobs.length, requestActivity, runningFloorMs]);
2585
2602
  useEffect(() => {
2603
+ conversationIdRef.current = conversationId;
2586
2604
  turnMessageIdRef.current = null;
2587
2605
  setTurnMessageId(null);
2588
2606
  elementsRef.current = [];
2589
2607
  setElements([]);
2590
2608
  setRunning(false);
2609
+ hasRunningBackgroundJobsRef.current = false;
2610
+ setRunningBackgroundJobs([]);
2591
2611
  consecutiveFailedRequestsRef.current = 0;
2592
2612
  return () => {
2593
2613
  if (trailingTimerRef.current !== null) {
@@ -2596,7 +2616,29 @@ const useConversationActivity = ({
2596
2616
  }
2597
2617
  };
2598
2618
  }, [conversationId]);
2599
- return { elements, running, turnMessageId };
2619
+ useEffect(() => {
2620
+ if (!enabled || !Number.isFinite(conversationId) || conversationId <= 0) {
2621
+ openedConversationIdRef.current = null;
2622
+ return;
2623
+ }
2624
+ if (openedConversationIdRef.current === conversationId) return;
2625
+ const readOnOpening = () => {
2626
+ openedConversationIdRef.current = conversationId;
2627
+ if (inFlightRef.current && inFlightConversationIdRef.current === conversationId) return;
2628
+ requestActivity(true);
2629
+ };
2630
+ if (typeof document === "undefined" || !document.hidden) {
2631
+ readOnOpening();
2632
+ return;
2633
+ }
2634
+ const onVisibilityChange = () => {
2635
+ if (!document.hidden && openedConversationIdRef.current !== conversationId) readOnOpening();
2636
+ };
2637
+ document.addEventListener("visibilitychange", onVisibilityChange);
2638
+ return () => document.removeEventListener("visibilitychange", onVisibilityChange);
2639
+ }, [conversationId, enabled, requestActivity]);
2640
+ const refresh = useCallback(() => requestActivity(true), [requestActivity]);
2641
+ return { elements, running, turnMessageId, runningBackgroundJobs, refresh };
2600
2642
  };
2601
2643
  const DEFAULT_AGENT_CHAT_ACTIVITY_TIMING = {
2602
2644
  activityRequestWindowMs: ACTIVITY_REQUEST_WINDOW_MS,
@@ -2946,6 +2988,8 @@ const useConversationMessagePages = (chatStore, client, pageSize = CONVERSATION_
2946
2988
  [readConversationMetadata, fetchOpeningPage, refetchChangedTail, loadOlder, loadingOlder]
2947
2989
  );
2948
2990
  };
2991
+ const RunningBackgroundJobsContext = createContext(null);
2992
+ const useRunningBackgroundJobs = () => useContext(RunningBackgroundJobsContext);
2949
2993
  const QueuedMessageChip = (props) => {
2950
2994
  const { text: text2, isCompact = false, wasTakenUp = false, className } = props;
2951
2995
  if (wasTakenUp) {
@@ -3432,7 +3476,9 @@ const AgentChatController = (props) => {
3432
3476
  const {
3433
3477
  elements: activityElements,
3434
3478
  running: activityRunning,
3435
- turnMessageId: activityTurnMessageId
3479
+ turnMessageId: activityTurnMessageId,
3480
+ runningBackgroundJobs,
3481
+ refresh: refreshActivity
3436
3482
  } = useConversationActivity({
3437
3483
  conversationId: liveConversationId ?? 0,
3438
3484
  runStatus,
@@ -3664,6 +3710,25 @@ const AgentChatController = (props) => {
3664
3710
  [messages, isTurnRunning, namedLiveTurnMessageId]
3665
3711
  );
3666
3712
  const hasTurnTraceSlot = TurnTrace !== void 0 && liveConversationId !== void 0;
3713
+ const backgroundJobsAnchorTurnMessageId = useMemo(() => {
3714
+ const threadMessages = messages ?? [];
3715
+ for (let position = threadMessages.length - 1; position >= 0; position -= 1) {
3716
+ const message = threadMessages[position];
3717
+ if (message.id != null && isTurnInitiatorMessage(message) && !turnsInFlight.queuedMessages.includes(message)) return message.id;
3718
+ }
3719
+ return null;
3720
+ }, [messages, turnsInFlight]);
3721
+ const { stopBackgroundJob: stopBackgroundJobOfClient } = client;
3722
+ const runningBackgroundJobsContextValue = useMemo(() => {
3723
+ if (liveConversationId === void 0) return null;
3724
+ return {
3725
+ conversationId: liveConversationId,
3726
+ anchorTurnMessageId: backgroundJobsAnchorTurnMessageId,
3727
+ backgroundJobs: runningBackgroundJobs,
3728
+ stopBackgroundJob: stopBackgroundJobOfClient ? (backgroundJobId) => stopBackgroundJobOfClient(liveConversationId, backgroundJobId) : void 0,
3729
+ refresh: refreshActivity
3730
+ };
3731
+ }, [liveConversationId, backgroundJobsAnchorTurnMessageId, runningBackgroundJobs, stopBackgroundJobOfClient, refreshActivity]);
3667
3732
  const showsKeptActivityHistory = keepActivityHistoryAfterAnswer && ActivityHistory !== void 0 && TurnTrace === void 0;
3668
3733
  const renderAfterMessage = useCallback(
3669
3734
  (message) => {
@@ -3713,7 +3778,7 @@ const AgentChatController = (props) => {
3713
3778
  chatStore,
3714
3779
  unansweredWidgetMessageId
3715
3780
  };
3716
- return /* @__PURE__ */ jsx(CanvasViabilityContext.Provider, { value: canvasViability, children: /* @__PURE__ */ jsx(WidgetRenderReportCollectorContext.Provider, { value: renderReportCollector, children: /* @__PURE__ */ jsxs(
3781
+ return /* @__PURE__ */ jsx(RunningBackgroundJobsContext.Provider, { value: runningBackgroundJobsContextValue, children: /* @__PURE__ */ jsx(CanvasViabilityContext.Provider, { value: canvasViability, children: /* @__PURE__ */ jsx(WidgetRenderReportCollectorContext.Provider, { value: renderReportCollector, children: /* @__PURE__ */ jsxs(
3717
3782
  ConversationWidgetProvider,
3718
3783
  {
3719
3784
  callbacks: widgetCallbacks,
@@ -3794,7 +3859,7 @@ const AgentChatController = (props) => {
3794
3859
  ) }) })
3795
3860
  ]
3796
3861
  }
3797
- ) }) });
3862
+ ) }) }) });
3798
3863
  };
3799
3864
  const chatArea = "agents_chatArea_4XiCda";
3800
3865
  const chatAreaWithTopBlurBand = "agents_chatAreaWithTopBlurBand_W-AdU0";
@@ -4672,6 +4737,78 @@ const ConsentRequestCard = (props) => {
4672
4737
  ] })
4673
4738
  ] });
4674
4739
  };
4740
+ const describeJobTime = (backgroundJob, now) => {
4741
+ const dueAt = readTraceMoment(backgroundJob.dueAt);
4742
+ if (dueAt !== null && dueAt > now) {
4743
+ return translateText("rings in %time%", { time: formatTraceClock(dueAt - now) });
4744
+ }
4745
+ const startedAt = readTraceMoment(backgroundJob.startedAt);
4746
+ return startedAt !== null ? formatTraceClock(now - startedAt) : null;
4747
+ };
4748
+ const RunningBackgroundJobLines = (props) => {
4749
+ const { backgroundJobs, onStop, onStopped, isCompact = false, className } = props;
4750
+ const now = useTraceNow(backgroundJobs.length > 0);
4751
+ const [stoppingJobIds, setStoppingJobIds] = useState([]);
4752
+ if (backgroundJobs.length === 0) return null;
4753
+ const handleStop = async (backgroundJobId) => {
4754
+ if (!onStop) return;
4755
+ setStoppingJobIds((jobIds) => [...jobIds, backgroundJobId]);
4756
+ try {
4757
+ await onStop(backgroundJobId);
4758
+ } catch {
4759
+ } finally {
4760
+ setStoppingJobIds((jobIds) => jobIds.filter((jobId) => jobId !== backgroundJobId));
4761
+ onStopped?.();
4762
+ }
4763
+ };
4764
+ return /* @__PURE__ */ jsx(
4765
+ "div",
4766
+ {
4767
+ className: classNames(styles$m.turnTrace, isCompact && styles$m.turnTraceCompact, className),
4768
+ role: "group",
4769
+ "aria-label": translateText("Background jobs"),
4770
+ "data-testid": "running-background-jobs",
4771
+ children: backgroundJobs.map((backgroundJob) => {
4772
+ const isWaitingForHost = backgroundJob.liveStatus === "WAITING_FOR_HOST";
4773
+ const isStopping = stoppingJobIds.includes(backgroundJob.id);
4774
+ const jobTime = describeJobTime(backgroundJob, now);
4775
+ return /* @__PURE__ */ jsxs(
4776
+ "div",
4777
+ {
4778
+ className: styles$m.statusLine,
4779
+ "data-testid": "running-background-job",
4780
+ "data-background-job-id": backgroundJob.id,
4781
+ "data-live-status": backgroundJob.liveStatus ?? void 0,
4782
+ children: [
4783
+ /* @__PURE__ */ jsx("span", { className: classNames(styles$m.spinner, isWaitingForHost && styles$m.spinnerWaiting), "aria-hidden": true }),
4784
+ /* @__PURE__ */ jsx("span", { className: styles$m.jobStatusText, title: backgroundJob.label, children: /* @__PURE__ */ jsxs("span", { className: styles$m.jobStatusParts, children: [
4785
+ /* @__PURE__ */ jsx("span", { className: classNames(styles$m.statusWord, styles$m.jobLabel), children: backgroundJob.label || translateText("Background job") }),
4786
+ [translateText("Background job #%number%", { number: backgroundJob.id }), isStopping ? translateText("Stopping…") : jobTime].filter((part2) => part2 !== null).map((part2) => /* @__PURE__ */ jsx("span", { className: styles$m.jobMeta, "data-testid": "running-background-job-meta", children: part2 }, part2 === jobTime ? "time" : part2))
4787
+ ] }) }),
4788
+ isWaitingForHost ? /* @__PURE__ */ jsx("span", { className: classNames(styles$m.badge, styles$m.badgeWarning), title: backgroundJob.liveNote ?? void 0, "data-testid": "background-job-waiting-for-host", children: translateText("waits for the host") }) : null,
4789
+ /* @__PURE__ */ jsx("span", { className: styles$m.metaGrow }),
4790
+ onStop ? /* @__PURE__ */ jsxs(
4791
+ "button",
4792
+ {
4793
+ type: "button",
4794
+ className: styles$m.stopButton,
4795
+ disabled: isStopping,
4796
+ "aria-label": translateText("Stop background job #%number%", { number: backgroundJob.id }),
4797
+ onClick: () => void handleStop(backgroundJob.id),
4798
+ children: [
4799
+ /* @__PURE__ */ jsx("span", { className: styles$m.stopSquare, "aria-hidden": true }),
4800
+ translateText("Stop")
4801
+ ]
4802
+ }
4803
+ ) : null
4804
+ ]
4805
+ },
4806
+ backgroundJob.id
4807
+ );
4808
+ })
4809
+ }
4810
+ );
4811
+ };
4675
4812
  const RunStatusLine = (props) => {
4676
4813
  const { startedAt, statusText, viewMode = "normal", tokens, costInUsd, formatCost, onStop, isStopping = false, children, className } = props;
4677
4814
  const format = useTraceFormat();
@@ -4754,6 +4891,22 @@ const sumModelCalls = (turn) => {
4754
4891
  return { tokens, costInUsd };
4755
4892
  };
4756
4893
  const ConversationTurnTrace = (props) => {
4894
+ const runningBackgroundJobs = useRunningBackgroundJobs();
4895
+ const showsBackgroundJobLines = runningBackgroundJobs !== null && runningBackgroundJobs.conversationId === props.conversationId && runningBackgroundJobs.anchorTurnMessageId !== null && String(runningBackgroundJobs.anchorTurnMessageId) === String(props.turnMessageId) && runningBackgroundJobs.backgroundJobs.length > 0;
4896
+ return /* @__PURE__ */ jsxs(Fragment$1, { children: [
4897
+ /* @__PURE__ */ jsx(ConversationTurnTraceBody, { ...props }),
4898
+ showsBackgroundJobLines ? /* @__PURE__ */ jsx(
4899
+ RunningBackgroundJobLines,
4900
+ {
4901
+ backgroundJobs: runningBackgroundJobs.backgroundJobs,
4902
+ onStop: runningBackgroundJobs.stopBackgroundJob,
4903
+ onStopped: runningBackgroundJobs.refresh,
4904
+ isCompact: props.isCompact
4905
+ }
4906
+ ) : null
4907
+ ] });
4908
+ };
4909
+ const ConversationTurnTraceBody = (props) => {
4757
4910
  const {
4758
4911
  conversationId,
4759
4912
  turnMessageId,
@@ -6209,13 +6362,14 @@ export {
6209
6362
  AgentChatController,
6210
6363
  A as AgentsChatStateContainer,
6211
6364
  A2 as AgentsChatStoreProvider,
6365
+ C as BackgroundJobFacts,
6212
6366
  BackgroundTasksList,
6213
6367
  CanvasPane,
6214
6368
  CanvasRestoreOnMount,
6215
6369
  ChangeSetCard,
6216
6370
  ChangedFilesPane,
6217
6371
  ChangedRecordsList,
6218
- C as CompactionDetail,
6372
+ D as CompactionDetail,
6219
6373
  ContextRing,
6220
6374
  ConversationChildTrace,
6221
6375
  ConversationClosedBar,
@@ -6236,7 +6390,7 @@ export {
6236
6390
  ConversationView,
6237
6391
  ConversationWidgetProvider,
6238
6392
  DEFAULT_AGENT_CHAT_ACTIVITY_TIMING,
6239
- D as DecisionDetail,
6393
+ G as DecisionDetail,
6240
6394
  E as EMPTY_AGENTS_CHAT_OPENING_REQUEST,
6241
6395
  EntityChip,
6242
6396
  FileChangesSummary,
@@ -6248,108 +6402,111 @@ export {
6248
6402
  PHONE_CALL_LIFECYCLE_SIGNAL_SOURCES,
6249
6403
  QueuedMessageChip,
6250
6404
  RunStatusLine,
6405
+ RunningBackgroundJobLines,
6406
+ RunningBackgroundJobsContext,
6251
6407
  SIGNAL_SOURCES_THAT_OWE_NO_WORK,
6252
6408
  SUCCESS_BEAT_MS,
6253
6409
  S as SignalDetail,
6254
- G as SkillLoadDetail,
6255
- H as StepFactsLine,
6256
- I2 as SubAgentStepGroup,
6257
- J as SubAgentStepRow,
6258
- K as TRACE_CONTEXT_SEGMENT_LABELS,
6259
- N as TRACE_DECISION_SITE_LABELS,
6410
+ H as SkillLoadDetail,
6411
+ I2 as StepFactsLine,
6412
+ J as SubAgentStepGroup,
6413
+ K as SubAgentStepRow,
6414
+ N as TRACE_CONTEXT_SEGMENT_LABELS,
6415
+ O as TRACE_DECISION_SITE_LABELS,
6260
6416
  TRACE_HIGHLIGHT_ATTRIBUTE,
6261
- O as TRACE_SIGNAL_SOURCE_LABELS,
6262
- P as TRACE_SIGNAL_TAG_LABELS,
6417
+ P as TRACE_SIGNAL_SOURCE_LABELS,
6418
+ Q as TRACE_SIGNAL_TAG_LABELS,
6263
6419
  TRACE_STEP_ANCHOR_ATTRIBUTE,
6264
6420
  TRACE_TURN_ANCHOR_ATTRIBUTE,
6265
- Q as TRACE_VIEW_MODE_OF_LEVEL,
6266
- R as TRACE_WAKE_CONDITION_LABELS,
6421
+ R as TRACE_VIEW_MODE_OF_LEVEL,
6422
+ U as TRACE_WAKE_CONDITION_LABELS,
6267
6423
  TaskPlanDrawer,
6268
6424
  TaskPlanMark,
6269
6425
  TaskPlanPane,
6270
6426
  TaskPlanRow$1 as TaskPlanRow,
6271
6427
  TaskPlanSegments,
6272
- U as TaskPlanStepDetail,
6273
- V as TerminalBlock,
6274
- W as ThinkingBlock,
6275
- X as ToolStepDetail,
6428
+ V as TaskPlanStepDetail,
6429
+ W as TerminalBlock,
6430
+ X as ThinkingBlock,
6431
+ Y as ToolStepDetail,
6276
6432
  ToolStepGroup,
6277
- Y as ToolStepRow,
6278
- Z as TraceCodePanel,
6279
- _ as TraceCopyButton,
6433
+ Z as ToolStepRow,
6434
+ _ as TraceCodePanel,
6435
+ $ as TraceCopyButton,
6280
6436
  TraceMountChip,
6281
6437
  TracePath,
6282
6438
  TraceStateIcon,
6283
6439
  TraceStepRow,
6284
- $ as TraceViewModeSwitch,
6440
+ a0 as TraceViewModeSwitch,
6285
6441
  TurnMetaLine,
6286
- a0 as WidgetDetail,
6442
+ a1 as WidgetDetail,
6287
6443
  buildMessageTimeMarks,
6288
- a1 as buildSideBySideDiffRows,
6444
+ a2 as buildSideBySideDiffRows,
6289
6445
  buildTaskPlanItems,
6290
6446
  buildTaskPlanTree,
6291
- a2 as clampTraceViewMode,
6447
+ a3 as clampTraceViewMode,
6292
6448
  collectTraceBackgroundTasks,
6293
6449
  collectTraceChangedRecords,
6294
6450
  collectTraceFileChangesByTurn,
6295
6451
  collectTraceTaskPlan,
6296
6452
  createAgentsChatStore,
6297
6453
  createMessageTimeFormat,
6298
- a3 as createTraceFormat,
6299
- a4 as defaultTraceViewModeOfPolicy,
6454
+ a4 as createTraceFormat,
6455
+ a5 as defaultTraceViewModeOfPolicy,
6300
6456
  deriveAgentActivity,
6457
+ a6 as describeBackgroundJobState,
6301
6458
  describeChangedFieldName,
6302
6459
  describeChangedRecord,
6303
- a5 as describeSubAgentCounts,
6460
+ a7 as describeSubAgentCounts,
6304
6461
  describeTraceBackgroundJob,
6305
- a6 as describeTraceCompaction,
6306
- a7 as describeTraceContextSegment,
6307
- a8 as describeTraceDecision,
6308
- a9 as describeTraceDecisionSite,
6309
- aa as describeTraceDecisionStatus,
6310
- ab as describeTraceModelName,
6311
- ac as describeTraceMount,
6312
- ad as describeTraceSignal,
6313
- ae as describeTraceSkillCause,
6314
- af as describeTraceWakeCondition,
6462
+ a8 as describeTraceCompaction,
6463
+ a9 as describeTraceContextSegment,
6464
+ aa as describeTraceDecision,
6465
+ ab as describeTraceDecisionSite,
6466
+ ac as describeTraceDecisionStatus,
6467
+ ad as describeTraceModelName,
6468
+ ae as describeTraceMount,
6469
+ af as describeTraceSignal,
6470
+ ag as describeTraceSkillCause,
6471
+ ah as describeTraceWakeCondition,
6315
6472
  findTurnsInFlight,
6316
6473
  findUnansweredWidgetMessageId,
6317
6474
  focusTraceStep,
6318
6475
  formatCallLength,
6319
6476
  formatElapsedClock,
6320
- ag as formatShortSha256,
6477
+ ai as formatShortSha256,
6321
6478
  formatTraceClock,
6322
6479
  getConversationTraceLoader,
6323
6480
  isStepStillRunning,
6324
6481
  isTraceBackgroundJobLabel,
6325
6482
  isTurnInitiatorMessage,
6326
6483
  normalizeServerMessageToMarkdown,
6327
- ah as parseUnifiedDiff,
6328
- ai as prettyPrintTraceJson,
6329
- aj as readContentFromUnifiedDiff,
6484
+ aj as parseUnifiedDiff,
6485
+ ak as prettyPrintTraceJson,
6486
+ al as readContentFromUnifiedDiff,
6330
6487
  r as readConversationErrorTypeOfRefusedSend,
6331
6488
  readDefaultExpandedKeys,
6332
6489
  readNeighbours,
6333
6490
  readShownStatus,
6334
- ak as readTraceFileChangeIcon,
6491
+ am as readTraceFileChangeIcon,
6335
6492
  readTraceFileChangeLetter,
6336
6493
  readTraceFileChangeWord,
6337
- al as readTraceIdInWords,
6494
+ an as readTraceIdInWords,
6338
6495
  readTraceMoment,
6339
- am as readTraceRunResultText,
6496
+ ao as readTraceRunResultText,
6340
6497
  readTraceStateLabel,
6341
- an as readTraceStateOfStatus,
6342
- ao as readTraceStepIcon,
6498
+ ap as readTraceStateOfStatus,
6499
+ aq as readTraceStepIcon,
6343
6500
  readTraceStepState,
6344
6501
  readTraceSubAgentState,
6345
6502
  readVisibleNodes,
6346
6503
  d as reduceAgentsChatState,
6347
6504
  releaseConversationTraceLoaders,
6348
6505
  resolveAgentChatActivityTiming,
6349
- ap as resolveAllowedTraceViewModes,
6506
+ ar as resolveAllowedTraceViewModes,
6350
6507
  selectVisibleTraceSteps,
6351
- aq as traceLevelOfViewMode,
6352
- ar as traceViewModesOfPolicy,
6508
+ as as traceLevelOfViewMode,
6509
+ at as traceViewModesOfPolicy,
6353
6510
  useActivityTicker,
6354
6511
  useAgentsChatSelector,
6355
6512
  b as useAgentsChatState,
@@ -6364,6 +6521,7 @@ export {
6364
6521
  useMessageTimeFormat,
6365
6522
  useOptionalAgentsChatStore,
6366
6523
  useOptionalAgentsConversationClient,
6524
+ useRunningBackgroundJobs,
6367
6525
  useTraceFormat
6368
6526
  };
6369
6527
  //# sourceMappingURL=chat.js.map