@steerable/agent-shell-web 0.14.0 → 0.14.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@steerable/agent-shell-web",
3
- "version": "0.14.0",
3
+ "version": "0.14.2",
4
4
  "type": "module",
5
5
  "description": "Steerable framework — product-neutral renderer SPA source for @steerable/agent-shell (React + Vite). Consumed by product web entry points via the `@/` alias (anchored at this package's src/) and the createProductViteConfig factory. Published as a source package (src/), plus the compiled vite.base config factory (vite.base.js + .d.ts) for Node-side config loading.",
6
6
  "license": "Apache-2.0",
@@ -45,8 +45,8 @@
45
45
  "react-router-dom": "^6.30.0",
46
46
  "rehype-raw": "^7.0.0",
47
47
  "remark-gfm": "^4.0.1",
48
- "@steerable/agent-protocol": "0.14.0",
49
- "@steerable/agent-ui": "0.14.0"
48
+ "@steerable/agent-protocol": "0.14.2",
49
+ "@steerable/agent-ui": "0.14.2"
50
50
  },
51
51
  "devDependencies": {
52
52
  "@tailwindcss/vite": "^4.3.0",
@@ -59,7 +59,7 @@
59
59
  "typescript": "^5.8.3",
60
60
  "vite": "^5.4.21",
61
61
  "vitest": "^3.2.4",
62
- "@steerable/pack-sdk": "0.14.0"
62
+ "@steerable/pack-sdk": "0.14.2"
63
63
  },
64
64
  "scripts": {
65
65
  "gen": "echo agent-shell-web",
@@ -688,7 +688,12 @@ function AgentChatView({
688
688
  persistExecPolicy(next);
689
689
  }, []);
690
690
 
691
- const setMessagesRef = useRef<((updater: (prev: any[]) => any[]) => void) | null>(null);
691
+ const [liveMetadataByMessageId, setLiveMetadataByMessageId] = useState<
692
+ Record<string, string>
693
+ >({});
694
+ const [tailLiveMetadata, setTailLiveMetadata] = useState<string | null>(null);
695
+ const tailLiveMetadataRef = useRef<string | null>(null);
696
+ const latestMessagesRef = useRef<ChatMessage[]>(initialMessages ?? []);
692
697
 
693
698
  const handleUnknownEvent = useCallback((event: SSEEvent) => {
694
699
  const ev = event as any;
@@ -831,20 +836,12 @@ function AgentChatView({
831
836
  setTailAssistantDbId(messageId);
832
837
  const persistedMetadata = ev.payload?.messageMetadata;
833
838
  if (typeof persistedMetadata === "string" && persistedMetadata) {
834
- setMessagesRef.current?.((prev) => {
835
- for (let idx = prev.length - 1; idx >= 0; idx -= 1) {
836
- if (prev[idx]?.role === "assistant") {
837
- const next = [...prev];
838
- next[idx] = {
839
- ...next[idx],
840
- id: messageId,
841
- messageMetadata: persistedMetadata,
842
- };
843
- return next;
844
- }
845
- }
846
- return prev;
847
- });
839
+ tailLiveMetadataRef.current = persistedMetadata;
840
+ setTailLiveMetadata(persistedMetadata);
841
+ setLiveMetadataByMessageId((prev) => ({
842
+ ...prev,
843
+ [messageId]: persistedMetadata,
844
+ }));
848
845
  }
849
846
  }
850
847
  // AI 标题更新走的是后台 IPC 广播(chat-title-updated)而不是 SSE——
@@ -878,10 +875,12 @@ function AgentChatView({
878
875
  onUnknownEvent: handleUnknownEvent,
879
876
  onStreamError: handleStreamError,
880
877
  });
881
- setMessagesRef.current = setMessages as any;
878
+ latestMessagesRef.current = messages;
882
879
  const awaitingRemoteActiveSnapshotRef = useRef(false);
883
880
  useEffect(() => {
884
881
  awaitingRemoteActiveSnapshotRef.current = false;
882
+ tailLiveMetadataRef.current = null;
883
+ setTailLiveMetadata(null);
885
884
  }, [chatId]);
886
885
 
887
886
  useEffect(() => {
@@ -1118,6 +1117,15 @@ function AgentChatView({
1118
1117
  ...(execPolicy === "full" ? { execPolicy: "full" } : {}),
1119
1118
  orchestration: readOrchestrationSetting(),
1120
1119
  };
1120
+ const prevTailMeta = tailLiveMetadataRef.current;
1121
+ if (prevTailMeta) {
1122
+ const last = latestMessagesRef.current[latestMessagesRef.current.length - 1];
1123
+ if (last?.role === "assistant") {
1124
+ setLiveMetadataByMessageId((prev) => ({ ...prev, [last.id]: prevTailMeta }));
1125
+ }
1126
+ }
1127
+ tailLiveMetadataRef.current = null;
1128
+ setTailLiveMetadata(null);
1121
1129
  return sendUserMessage({
1122
1130
  ...input,
1123
1131
  metadata: Object.keys(metadata).length > 0 ? metadata : undefined,
@@ -1306,6 +1314,15 @@ function AgentChatView({
1306
1314
  ...(mode === "plan" ? { mode: "plan" as const } : {}),
1307
1315
  ...(execPolicy === "full" ? { execPolicy: "full" as const } : {}),
1308
1316
  };
1317
+ const prevTailMeta = tailLiveMetadataRef.current;
1318
+ if (prevTailMeta) {
1319
+ const last = latestMessagesRef.current[latestMessagesRef.current.length - 1];
1320
+ if (last?.role === "assistant") {
1321
+ setLiveMetadataByMessageId((prev) => ({ ...prev, [last.id]: prevTailMeta }));
1322
+ }
1323
+ }
1324
+ tailLiveMetadataRef.current = null;
1325
+ setTailLiveMetadata(null);
1309
1326
  return resumeTurn({
1310
1327
  metadata: Object.keys(metadata).length > 0 ? metadata : undefined,
1311
1328
  });
@@ -1492,9 +1509,23 @@ function AgentChatView({
1492
1509
  // ── 把远端运行中的快照叠进渲染层 ────────────────────────────────────
1493
1510
  const remoteContent = remoteStreaming ? (liveStream.content ?? "") : null;
1494
1511
  const effectiveMessages = useMemo<ChatMessage[]>(() => {
1495
- if (remoteContent === null) return messages;
1512
+ const hasMapped = Object.keys(liveMetadataByMessageId).length > 0;
1513
+ const base =
1514
+ !hasMapped && !tailLiveMetadata
1515
+ ? messages
1516
+ : messages.map((m, idx) => {
1517
+ if ((m as ChatMessageWithMetadata).messageMetadata) return m;
1518
+ const mapped =
1519
+ liveMetadataByMessageId[m.id] ??
1520
+ (idx === messages.length - 1 && m.role === "assistant"
1521
+ ? (tailLiveMetadata ?? undefined)
1522
+ : undefined);
1523
+ if (!mapped) return m;
1524
+ return { ...m, messageMetadata: mapped } as ChatMessage;
1525
+ });
1526
+ if (remoteContent === null) return base;
1496
1527
  return [
1497
- ...messages,
1528
+ ...base,
1498
1529
  {
1499
1530
  id: `live_${chatId}`,
1500
1531
  role: "assistant",
@@ -1502,7 +1533,7 @@ function AgentChatView({
1502
1533
  createdAt: new Date().toISOString(),
1503
1534
  },
1504
1535
  ];
1505
- }, [messages, remoteContent, chatId]);
1536
+ }, [messages, liveMetadataByMessageId, tailLiveMetadata, remoteContent, chatId]);
1506
1537
  const effectiveIsStreaming = isStreaming || remoteStreaming;
1507
1538
 
1508
1539
  useEffect(() => {