@blade-hq/agent-react 2612.0.0-beta.112 → 2612.0.0-beta.113

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 (28) hide show
  1. package/dist/{McpAppCard-PGME4ZPA.js → McpAppCard-NJEKKEEN.js} +2 -2
  2. package/dist/{McpAppFrame-YKQ7ZZX6.js → McpAppFrame-IQK5AOMD.js} +2 -2
  3. package/dist/chat/AssistantTurnBlock.d.ts +1 -1
  4. package/dist/chat/AttachmentPreviewDialog.d.ts +1 -6
  5. package/dist/chat/ChatLoadingIndicator.d.ts +2 -1
  6. package/dist/chat/chat-run.d.ts +4 -0
  7. package/dist/chat/message-list-blocks.d.ts +1 -0
  8. package/dist/{chunk-SWYLHUQM.js → chunk-4WFRH7FG.js} +27 -7
  9. package/dist/{chunk-SWYLHUQM.js.map → chunk-4WFRH7FG.js.map} +1 -1
  10. package/dist/{chunk-B27HARE3.js → chunk-5XLLPGSU.js} +78 -32
  11. package/dist/chunk-5XLLPGSU.js.map +1 -0
  12. package/dist/{chunk-7TYNY2AX.js → chunk-M6SNZHK3.js} +11 -8
  13. package/dist/{chunk-7TYNY2AX.js.map → chunk-M6SNZHK3.js.map} +1 -1
  14. package/dist/{chunk-AOM334QU.js → chunk-VYTLF6JE.js} +8 -9
  15. package/dist/chunk-VYTLF6JE.js.map +1 -0
  16. package/dist/{chunk-VON7UU2E.js → chunk-XLG3BTUA.js} +2 -2
  17. package/dist/components/McpAppFrame.d.ts +2 -0
  18. package/dist/components/use-session-plugin-activation.d.ts +3 -1
  19. package/dist/index.js +3 -3
  20. package/dist/internal.js +5 -5
  21. package/dist/rich-input.js +2 -2
  22. package/dist/tool-details.js +1 -1
  23. package/package.json +2 -2
  24. package/dist/chunk-AOM334QU.js.map +0 -1
  25. package/dist/chunk-B27HARE3.js.map +0 -1
  26. /package/dist/{McpAppCard-PGME4ZPA.js.map → McpAppCard-NJEKKEEN.js.map} +0 -0
  27. /package/dist/{McpAppFrame-YKQ7ZZX6.js.map → McpAppFrame-IQK5AOMD.js.map} +0 -0
  28. /package/dist/{chunk-VON7UU2E.js.map → chunk-XLG3BTUA.js.map} +0 -0
@@ -16,13 +16,13 @@ import {
16
16
  useEffectEvent,
17
17
  useSessionPluginActivation,
18
18
  useSessionSkills
19
- } from "./chunk-7TYNY2AX.js";
19
+ } from "./chunk-M6SNZHK3.js";
20
20
  import {
21
21
  ImageLightbox,
22
22
  MessageImage,
23
23
  ToolUiCardView,
24
24
  getRenderer
25
- } from "./chunk-VON7UU2E.js";
25
+ } from "./chunk-XLG3BTUA.js";
26
26
  import {
27
27
  MarkdownContent
28
28
  } from "./chunk-5JDQG2JJ.js";
@@ -2012,6 +2012,7 @@ ${content}`);
2012
2012
  }
2013
2013
 
2014
2014
  // src/chat/ChatLoadingIndicator.tsx
2015
+ import { getServerTime } from "@blade-hq/agent-client/internal";
2015
2016
  import { useEffect as useEffect7, useState as useState10 } from "react";
2016
2017
 
2017
2018
  // src/chat/ai-elements/shimmer.tsx
@@ -2086,20 +2087,23 @@ function resolveLoadingStageLabel({
2086
2087
  function ChatLoadingIndicator({
2087
2088
  preparing = false,
2088
2089
  startedAtMs,
2089
- activeToolLabel
2090
+ activeToolLabel,
2091
+ useRunClock = false
2090
2092
  }) {
2093
+ const client = useOptionalBladeClient();
2091
2094
  const [mountTime] = useState10(() => Date.now());
2092
2095
  const originMs = typeof startedAtMs === "number" && Number.isFinite(startedAtMs) && startedAtMs > 0 ? startedAtMs : mountTime;
2093
- const [nowMs, setNowMs] = useState10(() => Date.now());
2096
+ const [tick, setTick] = useState10(() => ({ wall: Date.now(), monotonic: performance.now() }));
2097
+ const nowMs = (useRunClock ? getServerTime(client, tick.monotonic) : null) ?? tick.wall;
2094
2098
  useEffect7(() => {
2095
2099
  const elapsed = Math.max(0, nowMs - originMs);
2096
- if (elapsed >= MAX_LIVE_CLOCK_MS) return;
2100
+ if (!useRunClock && elapsed >= MAX_LIVE_CLOCK_MS) return;
2097
2101
  const delayMs = elapsed < 1e4 ? 100 : 1e3;
2098
2102
  const timer = window.setTimeout(() => {
2099
- setNowMs(Date.now());
2103
+ setTick({ wall: Date.now(), monotonic: performance.now() });
2100
2104
  }, delayMs);
2101
2105
  return () => window.clearTimeout(timer);
2102
- }, [originMs, nowMs]);
2106
+ }, [originMs, nowMs, useRunClock]);
2103
2107
  const elapsedMs = Math.max(0, nowMs - originMs);
2104
2108
  const label = resolveLoadingStageLabel({ preparing, elapsedMs, activeToolLabel });
2105
2109
  return /* @__PURE__ */ jsxs11(
@@ -6612,12 +6616,31 @@ function extractPlanMessagesForTurn(messages, turnLastMessage) {
6612
6616
  return extractLatestPlanMessages(messages.slice(enterIndex, endIndex));
6613
6617
  }
6614
6618
 
6619
+ // src/chat/chat-run.ts
6620
+ function lastChatRun(messages) {
6621
+ for (let index = messages.length - 1; index >= 0; index--) {
6622
+ const run = messages[index].chat_run;
6623
+ if (run) return run;
6624
+ }
6625
+ }
6626
+ function formatExecutionDuration(durationMs) {
6627
+ const totalSeconds = Math.max(0, Math.round(durationMs / 1e3));
6628
+ const minutes = Math.floor(totalSeconds / 60);
6629
+ const seconds = totalSeconds % 60;
6630
+ return minutes > 0 ? `${minutes}\u5206${seconds}\u79D2` : `${seconds}\u79D2`;
6631
+ }
6632
+ function terminalChatLabel(run) {
6633
+ if (!run || run.status !== "cancelled" && run.status !== "failed") return null;
6634
+ const label = run.status === "failed" ? "\u6267\u884C\u5931\u8D25" : "\u6267\u884C\u5DF2\u4E2D\u65AD";
6635
+ return run.duration_ms == null ? label : `${label} ${formatExecutionDuration(run.duration_ms)}`;
6636
+ }
6637
+
6615
6638
  // src/components/ExecutionProcessContext.ts
6616
6639
  import { createContext as createContext5 } from "react";
6617
6640
  var KeepToolStepsOpenContext = createContext5(false);
6618
6641
 
6619
6642
  // src/chat/AssistantTurnBlock.tsx
6620
- import { getServerTime } from "@blade-hq/agent-client/internal";
6643
+ import { getServerTime as getServerTime2 } from "@blade-hq/agent-client/internal";
6621
6644
  import { memo as memo3, useCallback as useCallback9, useContext as useContext7, useEffect as useEffect18, useMemo as useMemo13, useRef as useRef16, useState as useState25 } from "react";
6622
6645
 
6623
6646
  // src/chat/lib/citations.ts
@@ -7597,13 +7620,11 @@ function useAsyncValue(key, load2) {
7597
7620
  // src/chat/AttachmentPreviewDialog.tsx
7598
7621
  import { jsx as jsx23, jsxs as jsxs21 } from "react/jsx-runtime";
7599
7622
  function AttachmentPreviewDialog({ open, onOpenChange, filename, url, mode }) {
7623
+ const client = useOptionalBladeClient();
7600
7624
  const enabled = open && url != null && (mode === "markdown" || mode === "text");
7601
7625
  const { data: content, error } = useAsyncValue(enabled ? `${mode}:${url}` : null, async (signal) => {
7602
7626
  if (!url) return null;
7603
- const res = await fetch(url, {
7604
- signal,
7605
- credentials: "include"
7606
- });
7627
+ const res = client && !url.startsWith("blob:") ? await client.fetch("GET", url, { signal, expectOk: false }) : await fetch(url, { signal, credentials: "include" });
7607
7628
  if (!res.ok) {
7608
7629
  const body = await res.text().catch(() => "");
7609
7630
  throw new Error(`\u52A0\u8F7D\u5931\u8D25\uFF08HTTP ${res.status}\uFF09${body ? `\uFF1A${body.slice(0, 200)}` : ""}`);
@@ -8903,17 +8924,17 @@ function resolveTurnDisplayMode({
8903
8924
  }) {
8904
8925
  return displayMode;
8905
8926
  }
8906
- function formatExecutionDuration(durationMs) {
8907
- const totalSeconds = Math.max(0, Math.round(durationMs / 1e3));
8908
- const minutes = Math.floor(totalSeconds / 60);
8909
- const seconds = totalSeconds % 60;
8910
- return minutes > 0 ? `${minutes}\u5206${seconds}\u79D2` : `${seconds}\u79D2`;
8911
- }
8912
8927
  function getExecutionDurationMs({
8913
8928
  messages,
8914
8929
  isStreaming,
8915
8930
  now = null
8916
8931
  }) {
8932
+ const run = lastChatRun(messages);
8933
+ if (run?.duration_ms != null) return run.duration_ms;
8934
+ if (run?.started_at && isStreaming && now !== null) {
8935
+ const start = Date.parse(run.started_at);
8936
+ if (Number.isFinite(start)) return Math.max(0, now - start);
8937
+ }
8917
8938
  const knownDuration = messages.reduce(
8918
8939
  (total, message) => {
8919
8940
  if (typeof message.duration_ms === "number" && message.duration_ms > 0) {
@@ -8953,6 +8974,11 @@ function executionSummaryLabel({
8953
8974
  sessionStatus,
8954
8975
  askAnswers
8955
8976
  }) {
8977
+ const run = lastChatRun(messages);
8978
+ const runStatus = run?.status;
8979
+ if (runStatus === "incomplete" && !isStreaming) return "\u672C\u8F6E\u4ECD\u5728\u6267\u884C";
8980
+ const terminal = terminalChatLabel(run);
8981
+ if (terminal) return terminal;
8956
8982
  if (isStreaming) {
8957
8983
  return durationMs > 0 ? `\u6B63\u5728\u6267\u884C ${formatExecutionDuration(durationMs)}` : "\u6B63\u5728\u6267\u884C";
8958
8984
  }
@@ -9180,6 +9206,7 @@ function AssistantTurnBlockBase({
9180
9206
  () => finalMessage ? getTextContent3(normalizeMessageContent2(finalMessage.content)).trim() : "",
9181
9207
  [finalMessage]
9182
9208
  );
9209
+ const terminalLabel = terminalChatLabel(lastChatRun(messages));
9183
9210
  const hasInterruptedState = messages.some((message) => message.status === "interrupted");
9184
9211
  const hasFailedWithoutContent = messages.some(
9185
9212
  (message) => message.status === "failed" && !hasRenderableMessageContent(message)
@@ -9199,7 +9226,7 @@ function AssistantTurnBlockBase({
9199
9226
  const liveExecutionDurationMs = isStreaming ? getExecutionDurationMs({
9200
9227
  messages,
9201
9228
  isStreaming,
9202
- now: sessionId ? getServerTime(client, clock) : Date.now()
9229
+ now: sessionId ? getServerTime2(client, clock) : Date.now()
9203
9230
  }) : executionDurationMs;
9204
9231
  const observedMemoryRefs = useMemo13(() => collectMemoryRefs(messages), [messages]);
9205
9232
  const [cachedMemoryRefs, setCachedMemoryRefs] = useState25([]);
@@ -9219,8 +9246,9 @@ function AssistantTurnBlockBase({
9219
9246
  ),
9220
9247
  children: [
9221
9248
  memoryRefs.length > 0 && /* @__PURE__ */ jsx31(MemoryRefsHint, { refs: memoryRefs }),
9222
- hasInterruptedState && /* @__PURE__ */ jsx31("div", { className: "w-fit rounded-full border border-[hsl(var(--swf-warning)/0.3)] bg-[hsl(var(--swf-warning-soft))] px-2.5 py-1 text-[10px] font-medium text-[hsl(var(--swf-warning))]", children: "\u5DF2\u4E2D\u65AD" }),
9223
- hasFailedWithoutContent && /* @__PURE__ */ jsx31("div", { className: "w-fit rounded-full border border-[hsl(var(--destructive)/0.3)] bg-[hsl(var(--destructive)/0.1)] px-2.5 py-1 text-[10px] font-medium text-[hsl(var(--destructive))]", children: "\u751F\u6210\u5931\u8D25" }),
9249
+ !hasExecutionProcess && terminalLabel && /* @__PURE__ */ jsx31("div", { className: "text-xs text-muted-foreground", children: terminalLabel }),
9250
+ hasInterruptedState && !terminalLabel && /* @__PURE__ */ jsx31("div", { className: "w-fit rounded-full border border-[hsl(var(--swf-warning)/0.3)] bg-[hsl(var(--swf-warning-soft))] px-2.5 py-1 text-[10px] font-medium text-[hsl(var(--swf-warning))]", children: "\u5DF2\u4E2D\u65AD" }),
9251
+ hasFailedWithoutContent && !terminalLabel && /* @__PURE__ */ jsx31("div", { className: "w-fit rounded-full border border-[hsl(var(--destructive)/0.3)] bg-[hsl(var(--destructive)/0.1)] px-2.5 py-1 text-[10px] font-medium text-[hsl(var(--destructive))]", children: "\u751F\u6210\u5931\u8D25" }),
9224
9252
  hasExecutionProcess && /* @__PURE__ */ jsxs29("div", { className: "flex w-full items-start gap-2.5", children: [
9225
9253
  /* @__PURE__ */ jsx31(
9226
9254
  "span",
@@ -10791,7 +10819,7 @@ function getAssistantTurnPreview(messages) {
10791
10819
  return "\u672C\u8F6E\u56DE\u590D";
10792
10820
  }
10793
10821
  function shouldAppendPendingAssistantTurn(sessionIsStreaming, lastMessage) {
10794
- return sessionIsStreaming && lastMessage?.role === "user";
10822
+ return sessionIsStreaming && lastMessage?.role === "user" && (!lastMessage.chat_run || lastMessage.chat_run.status === "incomplete");
10795
10823
  }
10796
10824
  function hasAssistantReply(block) {
10797
10825
  return block?.type === "assistant_turn" && block.messages.some((message) => {
@@ -10816,7 +10844,9 @@ function buildMessageListBlocks({
10816
10844
  });
10817
10845
  const blocks = [];
10818
10846
  let contextBuffer = [];
10847
+ const unanswered = /* @__PURE__ */ new Map();
10819
10848
  let assistantBuffer = [];
10849
+ let bufferRunId;
10820
10850
  let assistantTurnCount = 0;
10821
10851
  let lastUserPreview = "";
10822
10852
  let pendingUserEntryId = null;
@@ -10839,6 +10869,7 @@ function buildMessageListBlocks({
10839
10869
  });
10840
10870
  pendingUserEntryId = null;
10841
10871
  assistantBuffer = [];
10872
+ bufferRunId = void 0;
10842
10873
  };
10843
10874
  const flushContexts = () => {
10844
10875
  if (contextBuffer.length === 0) return;
@@ -10910,6 +10941,9 @@ function buildMessageListBlocks({
10910
10941
  continue;
10911
10942
  }
10912
10943
  if (message.role === "assistant" && !notice) {
10944
+ if (message.chat_run && bufferRunId && bufferRunId !== message.chat_run.run_id) flushAssistant();
10945
+ if (message.chat_run) bufferRunId = message.chat_run.run_id;
10946
+ if (message.chat_run && terminalChatLabel(message.chat_run)) unanswered.set(message.chat_run.run_id, null);
10913
10947
  assistantBuffer.push(message);
10914
10948
  continue;
10915
10949
  }
@@ -10919,21 +10953,26 @@ function buildMessageListBlocks({
10919
10953
  lastUserPreview = getMessagePreview(message);
10920
10954
  pendingUserEntryId = persistentId;
10921
10955
  }
10922
- blocks.push({
10956
+ const block = {
10923
10957
  type: "message",
10924
10958
  message,
10925
10959
  key: message.render_id ?? persistentId ?? `${message.role}-${blocks.length}`,
10926
10960
  persistentId,
10927
10961
  anchorId: persistentId ? `chat-entry-${persistentId}` : null,
10928
10962
  isStreaming: message.status === "streaming"
10929
- });
10963
+ };
10964
+ blocks.push(block);
10965
+ if (message.role === "user" && message.chat_run && terminalChatLabel(message.chat_run) && unanswered.get(message.chat_run.run_id) !== null) {
10966
+ unanswered.set(message.chat_run.run_id, block);
10967
+ }
10930
10968
  }
10931
10969
  flushAssistant();
10932
10970
  flushContexts();
10933
10971
  if (sessionIsStreaming && completionNotice(visible.at(-1)?.blocks)?.source.source_kind !== "subagent") {
10934
10972
  const last = blocks[blocks.length - 1];
10935
10973
  if (last?.type === "assistant_turn") {
10936
- last.isStreaming = true;
10974
+ const run = lastChatRun(last.messages);
10975
+ last.isStreaming = !run || run.status === "incomplete";
10937
10976
  } else if (shouldAppendPendingAssistantTurn(
10938
10977
  sessionIsStreaming,
10939
10978
  last?.type === "message" ? last.message : void 0
@@ -10947,6 +10986,7 @@ function buildMessageListBlocks({
10947
10986
  role: "assistant",
10948
10987
  content: "",
10949
10988
  entry_id: pendingKey,
10989
+ ...last.type === "message" && last.message.chat_run?.status === "incomplete" ? { chat_run: last.message.chat_run } : {},
10950
10990
  status: "streaming",
10951
10991
  loop_name: "root"
10952
10992
  }
@@ -10960,6 +11000,9 @@ function buildMessageListBlocks({
10960
11000
  });
10961
11001
  }
10962
11002
  }
11003
+ for (const block of unanswered.values()) {
11004
+ if (block) block.unansweredLabel = terminalChatLabel(block.message.chat_run) ?? void 0;
11005
+ }
10963
11006
  return blocks;
10964
11007
  }
10965
11008
  function getRenderBlockPersistentId(block) {
@@ -11204,7 +11247,7 @@ function MessageListBody({
11204
11247
  }, [agentLoopNameSet, messages, sessionIsStreaming, isRevealingAny]);
11205
11248
  const hasInterruptedTurn = useMemo14(
11206
11249
  () => renderBlocks.some(
11207
- (block) => block.type === "assistant_turn" && block.messages.some((message) => message.status === "interrupted")
11250
+ (block) => block.type === "message" && block.unansweredLabel && block.message.chat_run?.status === "cancelled" || block.type === "assistant_turn" && (lastChatRun(block.messages)?.status === "cancelled" || block.messages.some((message) => message.status === "interrupted"))
11208
11251
  ),
11209
11252
  [renderBlocks]
11210
11253
  );
@@ -11240,12 +11283,14 @@ function MessageListBody({
11240
11283
  }
11241
11284
  return null;
11242
11285
  }, [renderBlocks]);
11286
+ const preparingRun = latestUserBlock?.message.chat_run ?? (isPreparing && latestUserBlock?.message.entry_id?.startsWith("local-user-") ? lastChatRun(messages) : void 0);
11287
+ const preparingStart = preparingRun?.status === "incomplete" ? preparingRun.started_at : void 0;
11243
11288
  const latestUserStartedAtMs = useMemo14(() => {
11244
- const ts = latestUserBlock?.message.timestamp;
11289
+ const ts = preparingStart ?? latestUserBlock?.message.timestamp;
11245
11290
  if (!ts) return null;
11246
11291
  const parsed = Date.parse(ts);
11247
11292
  return Number.isFinite(parsed) ? parsed : null;
11248
- }, [latestUserBlock]);
11293
+ }, [latestUserBlock, preparingStart]);
11249
11294
  const latestUserAnchorId = latestUserBlock?.anchorId ?? null;
11250
11295
  const latestUserStableId = latestUserBlock?.message.render_id ?? latestUserAnchorId;
11251
11296
  const latestUserIsOptimistic = latestUserBlock?.message.entry_id?.startsWith("local-user-") ?? false;
@@ -12166,7 +12211,7 @@ function MessageListBody({
12166
12211
  emptyState
12167
12212
  }
12168
12213
  ),
12169
- isPreparing ? /* @__PURE__ */ jsx37("div", { className: "mx-auto mt-3 max-w-[var(--blade-chat-width,780px)] px-4", children: /* @__PURE__ */ jsx37(ChatLoadingIndicator, { preparing: true, startedAtMs: latestUserStartedAtMs }) }) : null,
12214
+ isPreparing ? /* @__PURE__ */ jsx37("div", { className: "mx-auto mt-3 max-w-[var(--blade-chat-width,780px)] px-4", children: /* @__PURE__ */ jsx37(ChatLoadingIndicator, { preparing: true, startedAtMs: latestUserStartedAtMs, useRunClock: Boolean(preparingStart) }) }) : null,
12170
12215
  /* @__PURE__ */ jsx37("div", { ref: newTurnSpacerRef, "aria-hidden": "true", className: "pointer-events-none w-full" })
12171
12216
  ]
12172
12217
  }
@@ -12281,7 +12326,8 @@ function MessageListContent({
12281
12326
  message: block.message,
12282
12327
  className: customization?.classNames?.errorMessage
12283
12328
  }
12284
- ) : null
12329
+ ) : null,
12330
+ block.unansweredLabel && /* @__PURE__ */ jsx37("div", { className: "mt-2 text-xs text-muted-foreground", children: block.unansweredLabel })
12285
12331
  ]
12286
12332
  }
12287
12333
  );
@@ -14133,6 +14179,7 @@ export {
14133
14179
  PlanSummaryCard,
14134
14180
  extractLatestPlanMessages,
14135
14181
  extractPlanMessagesForTurn,
14182
+ formatExecutionDuration,
14136
14183
  buildCitationsFromToolCalls,
14137
14184
  LOOPBACK_HOSTS,
14138
14185
  isLoopbackUrl,
@@ -14181,7 +14228,6 @@ export {
14181
14228
  toolCallAnswered,
14182
14229
  defaultTurnDisplayMode,
14183
14230
  resolveTurnDisplayMode,
14184
- formatExecutionDuration,
14185
14231
  getExecutionDurationMs,
14186
14232
  AssistantTurnBlock,
14187
14233
  collectMemoryRefs,
@@ -14246,4 +14292,4 @@ use-stick-to-bottom/dist/StickToBottom.js:
14246
14292
  js-yaml/dist/js-yaml.mjs:
14247
14293
  (*! js-yaml 4.1.1 https://github.com/nodeca/js-yaml @license MIT *)
14248
14294
  */
14249
- //# sourceMappingURL=chunk-B27HARE3.js.map
14295
+ //# sourceMappingURL=chunk-5XLLPGSU.js.map