@cocorograph/hub-agent 0.7.76 → 0.7.77

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": "@cocorograph/hub-agent",
3
- "version": "0.7.76",
3
+ "version": "0.7.77",
4
4
  "description": "Hub Hosted Cockpit のローカル常駐 agent。Hub と outbound WSS で接続し、ローカルの tmux/pty を中継する。",
5
5
  "type": "module",
6
6
  "license": "UNLICENSED",
@@ -126,7 +126,27 @@ function flattenThreadItems(thread, { maxItems = HISTORY_MAX_ITEMS, maxBytes = H
126
126
  const turns = Array.isArray(thread?.turns) ? thread.turns : []
127
127
  const all = []
128
128
  for (const turn of turns) {
129
- if (Array.isArray(turn?.items)) all.push(...turn.items)
129
+ if (!Array.isArray(turn?.items)) continue
130
+ // 表示用バブル時刻 (症状⑧: 履歴 hydrate で全バブルが reload 時刻 = Date.now() になる問題)。
131
+ // app-server の ThreadItem は per-item timestamp を持たない (生成スキーマで確認済み)。
132
+ // ターン単位の時刻 (単位は秒) を各 item に at_ms (ms epoch) として付与する。
133
+ //
134
+ // ⚠️ ライブ経路との整合 (round2 minor): item の種別で使う時刻を変える。
135
+ // - userMessage: ライブでは item/completed.completedAtMs = **ターン冒頭**の時刻で届く
136
+ // (ユーザー入力の echo は即完了するため)。履歴で completedAt(ターン終了) を当てると、
137
+ // 長いターンでリロード後にユーザーバブルが終了時刻へ飛ぶ。→ Turn.startedAt を優先。
138
+ // - それ以外 (agentMessage/tool 等): ライブでは各 item の完了時刻で届くので、
139
+ // ターン終了に近い Turn.completedAt を優先 (無ければ startedAt)。
140
+ const num = (v) => (typeof v === "number" ? v : null)
141
+ const startSec = num(turn.startedAt)
142
+ const endSec = num(turn.completedAt)
143
+ const secFor = (item) =>
144
+ item?.type === "userMessage" ? (startSec ?? endSec) : (endSec ?? startSec)
145
+ for (const item of turn.items) {
146
+ const sec = secFor(item)
147
+ const atMs = sec != null ? Math.round(sec * 1000) : null
148
+ all.push(atMs != null && item && typeof item === "object" ? { ...item, at_ms: atMs } : item)
149
+ }
130
150
  }
131
151
  const total = all.length
132
152
  const kept = []