@tea-agent/loop-agent 0.55.0-next.3 → 0.55.0-next.5

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 (107) hide show
  1. package/CHANGELOG.md +11 -1
  2. package/README.md +1 -0
  3. package/dist/build-stamp.json +3 -3
  4. package/dist/worker/cli.js +16 -4
  5. package/dist/worker/console/chat/browser-automation.js +530 -26
  6. package/dist/worker/console/chat/browser-cdp.js +145 -0
  7. package/dist/worker/console/chat/browser-evaluation.js +26 -25
  8. package/dist/worker/console/chat/browser-exposure.js +8 -26
  9. package/dist/worker/console/chat/browser-la.js +266 -0
  10. package/dist/worker/console/chat/browser-policy.js +5 -4
  11. package/dist/worker/console/chat/browser-preload.js +119 -0
  12. package/dist/worker/console/chat/browser-preloads/vcp.js +417 -0
  13. package/dist/worker/console/chat/browser-region-fingerprint.js +36 -0
  14. package/dist/worker/console/chat/browser-run.js +97 -0
  15. package/dist/worker/console/chat/browser-screenshot-result.js +2 -2
  16. package/dist/worker/console/chat/browser-scripts.js +42 -4
  17. package/dist/worker/console/chat/browser-timeline.js +4 -0
  18. package/dist/worker/console/chat/pi-runtime/custom-tools/browser-tools.js +73 -16
  19. package/dist/worker/console/chat/pi-runtime/sdk-bindings.js +70 -0
  20. package/dist/worker/console/chat/pi-runtime.js +53 -35
  21. package/dist/worker/console/chat/png-fingerprint.js +189 -0
  22. package/dist/worker/console/chat/routes.js +47 -38
  23. package/dist/worker/console/chat/session-store.js +7 -21
  24. package/dist/worker/console/chat/terminal-sessions.js +1 -1
  25. package/dist/worker/console/chat/terminal-tools.js +1 -0
  26. package/dist/worker/console/chat/tool-exposure-catalog.js +2 -2
  27. package/dist/worker/console/chat/tools.js +2 -0
  28. package/dist/worker/console/chat/workspace-landing.js +9 -0
  29. package/dist/worker/console/static/assets/{abnfDiagram-N423BO3Z-C29lbS0T.js → abnfDiagram-N423BO3Z-mcArn3xd.js} +1 -1
  30. package/dist/worker/console/static/assets/{arc--Vi-BzUR.js → arc-D22Gr5Kh.js} +1 -1
  31. package/dist/worker/console/static/assets/{architectureDiagram-T3A2C74G-DwdFPJd-.js → architectureDiagram-T3A2C74G-5P-xaSwS.js} +1 -1
  32. package/dist/worker/console/static/assets/{blockDiagram-VBNYF7ZC-BFuPq4yu.js → blockDiagram-VBNYF7ZC-ClYqZUog.js} +1 -1
  33. package/dist/worker/console/static/assets/{c4Diagram-5PPSVZJV-oKn9EfQa.js → c4Diagram-5PPSVZJV-B5615n-w.js} +1 -1
  34. package/dist/worker/console/static/assets/channel-BcPrK1uQ.js +1 -0
  35. package/dist/worker/console/static/assets/{chunk-2GRJ4B5K-TwXtrEhU.js → chunk-2GRJ4B5K-DaXOOg2S.js} +1 -1
  36. package/dist/worker/console/static/assets/{chunk-2Q5K7J3B-Cc3zFHjT.js → chunk-2Q5K7J3B-DewgVpWS.js} +1 -1
  37. package/dist/worker/console/static/assets/{chunk-5RXB4S5H-xJfu4YKo.js → chunk-5RXB4S5H-C6dIPMGB.js} +1 -1
  38. package/dist/worker/console/static/assets/{chunk-5VM5RSS4-VBNdtRqb.js → chunk-5VM5RSS4-CIxapjAj.js} +1 -1
  39. package/dist/worker/console/static/assets/{chunk-6Q2QTUOP-DxhJidW7.js → chunk-6Q2QTUOP-dYOgBsXL.js} +1 -1
  40. package/dist/worker/console/static/assets/{chunk-GF5L2VYU-P6N3qPX5.js → chunk-GF5L2VYU-NOEzJIgx.js} +1 -1
  41. package/dist/worker/console/static/assets/{chunk-JWPE2WC7-LE21hHhq.js → chunk-JWPE2WC7-BYibgnxd.js} +1 -1
  42. package/dist/worker/console/static/assets/{chunk-KBJHAD2P-CZmtvzKZ.js → chunk-KBJHAD2P-CbxJFJr1.js} +1 -1
  43. package/dist/worker/console/static/assets/{chunk-RYQCIY6F-BQrw57-q.js → chunk-RYQCIY6F-MaH52RLP.js} +1 -1
  44. package/dist/worker/console/static/assets/{chunk-XXDRQBXY-DSNQHlxO.js → chunk-XXDRQBXY-D3YLa2yq.js} +1 -1
  45. package/dist/worker/console/static/assets/classDiagram-JCYQIIEL-DdqL4uaJ.js +1 -0
  46. package/dist/worker/console/static/assets/classDiagram-v2-OCEON4UE-DdqL4uaJ.js +1 -0
  47. package/dist/worker/console/static/assets/{cose-bilkent-JH36ORCC-Ckm2oC4s.js → cose-bilkent-JH36ORCC-lsxffBWh.js} +1 -1
  48. package/dist/worker/console/static/assets/{cynefinDiagram-MW4NZA55-B7ecDXon.js → cynefinDiagram-MW4NZA55-FlNQHEbD.js} +1 -1
  49. package/dist/worker/console/static/assets/{dagre-VZM6K2ZE-Cx_kCtwr.js → dagre-VZM6K2ZE-ChG_TvEA.js} +1 -1
  50. package/dist/worker/console/static/assets/{diagram-7IWD3JNH-DTqfz-9k.js → diagram-7IWD3JNH-BL-8sI-U.js} +1 -1
  51. package/dist/worker/console/static/assets/{diagram-B4RE2ZJO-BH8nNNYl.js → diagram-B4RE2ZJO-DRuUXlYn.js} +1 -1
  52. package/dist/worker/console/static/assets/{diagram-LBJQPF4R-mwUmtiIR.js → diagram-LBJQPF4R-BNWH241c.js} +1 -1
  53. package/dist/worker/console/static/assets/{diagram-Q27KOJAE-B6_cW-cc.js → diagram-Q27KOJAE-DM4OKpX4.js} +1 -1
  54. package/dist/worker/console/static/assets/{diagram-UB23O5K3-D1sGiHf5.js → diagram-UB23O5K3-DngjP8qb.js} +1 -1
  55. package/dist/worker/console/static/assets/{ebnfDiagram-BXEA7PRR-C07tYieV.js → ebnfDiagram-BXEA7PRR-jVdtkqdM.js} +1 -1
  56. package/dist/worker/console/static/assets/{erDiagram-JOGREHBK-eHwocxI1.js → erDiagram-JOGREHBK-BTc9JI_e.js} +1 -1
  57. package/dist/worker/console/static/assets/{flowDiagram-UKHOOZJN-B1B-mb0t.js → flowDiagram-UKHOOZJN-48TF2hOm.js} +1 -1
  58. package/dist/worker/console/static/assets/{ganttDiagram-PKOTCBZU-B2fpno6f.js → ganttDiagram-PKOTCBZU-Dk-BQhyz.js} +1 -1
  59. package/dist/worker/console/static/assets/{gitGraphDiagram-DS77QQ5N-DcM98HR9.js → gitGraphDiagram-DS77QQ5N-Cq8vG_LR.js} +1 -1
  60. package/dist/worker/console/static/assets/{infoDiagram-6WML65LV-edHmAaaC.js → infoDiagram-6WML65LV-YL-Nd82t.js} +1 -1
  61. package/dist/worker/console/static/assets/{ishikawaDiagram-WSZJBQD7-Df_rsjoZ.js → ishikawaDiagram-WSZJBQD7-FWxeUP4G.js} +1 -1
  62. package/dist/worker/console/static/assets/{journeyDiagram-NVQOT4AX-BqK30536.js → journeyDiagram-NVQOT4AX-B9joXO0y.js} +1 -1
  63. package/dist/worker/console/static/assets/{kanban-definition-27J2QSJJ-DCvcYw-F.js → kanban-definition-27J2QSJJ-DUr3LGth.js} +1 -1
  64. package/dist/worker/console/static/assets/{linear-4rMK0UAe.js → linear-Cs-mfq2-.js} +1 -1
  65. package/dist/worker/console/static/assets/main-DKX9JQ3f.css +1 -0
  66. package/dist/worker/console/static/assets/main-ashAmyih.js +655 -0
  67. package/dist/worker/console/static/assets/{mermaid.core-CIeuqFlz.js → mermaid.core-DXXCdcu4.js} +4 -4
  68. package/dist/worker/console/static/assets/{mindmap-definition-FAOFIHXS-isklXv_u.js → mindmap-definition-FAOFIHXS--vtGc5sI.js} +1 -1
  69. package/dist/worker/console/static/assets/{pegDiagram-VL7TDLO6-DufJ3B32.js → pegDiagram-VL7TDLO6-fiXBc-id.js} +1 -1
  70. package/dist/worker/console/static/assets/{pieDiagram-7S7Q4E2Y-e-dscJOX.js → pieDiagram-7S7Q4E2Y-Cx5Lr1-Y.js} +1 -1
  71. package/dist/worker/console/static/assets/{quadrantDiagram-CIZ2JOQS-BMXdwlfZ.js → quadrantDiagram-CIZ2JOQS-BlNemfDx.js} +1 -1
  72. package/dist/worker/console/static/assets/{railroadDiagram-AXF67PYL-BkLHnA2m.js → railroadDiagram-AXF67PYL-BsuFyiqc.js} +1 -1
  73. package/dist/worker/console/static/assets/{requirementDiagram-LRYGKXZP-BzXmvm6l.js → requirementDiagram-LRYGKXZP-CKEYRC2J.js} +1 -1
  74. package/dist/worker/console/static/assets/{sankeyDiagram-W5VNT64P-BZuur-BM.js → sankeyDiagram-W5VNT64P-vrMh2hZZ.js} +1 -1
  75. package/dist/worker/console/static/assets/{sequenceDiagram-SI44F4Z6-DbZxmtRn.js → sequenceDiagram-SI44F4Z6-BeA4ln2I.js} +1 -1
  76. package/dist/worker/console/static/assets/{sheet-workbook-D_6Enbgn.js → sheet-workbook-P_0sJUSC.js} +1 -1
  77. package/dist/worker/console/static/assets/{sizeCapture-X5ZJPWSS-BHbP5ADt.js → sizeCapture-X5ZJPWSS-BdgLOvid.js} +1 -1
  78. package/dist/worker/console/static/assets/{stateDiagram-OKZ733FA-CGNrvQQV.js → stateDiagram-OKZ733FA-CcI28rqU.js} +1 -1
  79. package/dist/worker/console/static/assets/stateDiagram-v2-UEYNNEHI-B0DPdHTy.js +1 -0
  80. package/dist/worker/console/static/assets/{swimlanes-SLNWSIFB-BWNaMfHj.js → swimlanes-SLNWSIFB-DGNDAHUl.js} +2 -2
  81. package/dist/worker/console/static/assets/swimlanesDiagram-ULZ7WXOC-Ctgvnx6w.js +8 -0
  82. package/dist/worker/console/static/assets/{timeline-definition-Z64GVDOM-BhI167N4.js → timeline-definition-Z64GVDOM-DBzInzT7.js} +1 -1
  83. package/dist/worker/console/static/assets/{vennDiagram-T6HMQDX7-BFHqLPNk.js → vennDiagram-T6HMQDX7-C97pu5Ae.js} +1 -1
  84. package/dist/worker/console/static/assets/{wardleyDiagram-T6FBY63Y-D-ThxcCm.js → wardleyDiagram-T6FBY63Y-D3tT-Oxo.js} +1 -1
  85. package/dist/worker/console/static/assets/{xychartDiagram-ELKLHX3M-CeUzoGed.js → xychartDiagram-ELKLHX3M-1_u6WRbI.js} +1 -1
  86. package/dist/worker/console/static/index.html +2 -2
  87. package/dist/worker/console/static-src/operator-chat/controlled-request-status.js +28 -0
  88. package/dist/worker/console/static-src/operator-chat/turn-submission.js +3 -0
  89. package/dist/worker/console/static-src/operator-chat/useChatSessions.js +140 -34
  90. package/dist/worker/console/static-src/operator-chat/useChatStream.js +12 -2
  91. package/dist/worker/console/static-src/operator-chat/useChatThread.js +5 -0
  92. package/dist/worker/console/static-src/operator-chat/useComposer.js +10 -17
  93. package/dist/worker/console/static-src/operator-chat/useControlledHandoff.js +33 -0
  94. package/dist/worker/console/static-src/operator-chat/useControlledReceipt.js +206 -0
  95. package/dist/worker/console/static-src/shell/workspace-route.js +17 -1
  96. package/dist/worker/observe/static/operator-chrome.css +49 -0
  97. package/dist/worker/observe/static/operator-chrome.d.ts +7 -0
  98. package/dist/worker/observe/static/operator-chrome.js +31 -0
  99. package/docs/architecture/runtime-boundaries.md +5 -0
  100. package/package.json +3 -3
  101. package/dist/worker/console/static/assets/channel-o_uspxIc.js +0 -1
  102. package/dist/worker/console/static/assets/classDiagram-JCYQIIEL-BAMhQfS-.js +0 -1
  103. package/dist/worker/console/static/assets/classDiagram-v2-OCEON4UE-BAMhQfS-.js +0 -1
  104. package/dist/worker/console/static/assets/main-CBjwyx0a.js +0 -654
  105. package/dist/worker/console/static/assets/main-CGnkpKqw.css +0 -1
  106. package/dist/worker/console/static/assets/stateDiagram-v2-UEYNNEHI-Oa0mw2RA.js +0 -1
  107. package/dist/worker/console/static/assets/swimlanesDiagram-ULZ7WXOC-CylkK52a.js +0 -8
@@ -831,10 +831,12 @@ export async function handleForkChatSession(req, res, deps, sourceSessionId) {
831
831
  });
832
832
  return;
833
833
  }
834
- if (deps.events.getActiveTurn(sourceSessionId)) {
834
+ const sourceBusy = () => Boolean(deps.events.getActiveTurn(sourceSessionId)) ||
835
+ Object.values(deps.runtime.getSessionBusyFacts?.(sourceSessionId) ?? {}).some(value => value === true);
836
+ if (sourceBusy()) {
835
837
  sendJson(res, 409, {
836
838
  ok: false,
837
- error: { code: "TURN_ACTIVE", message: "cannot fork an active turn" },
839
+ error: { code: "TURN_ACTIVE", message: "等待当前回复结束后重试。" },
838
840
  });
839
841
  return;
840
842
  }
@@ -853,38 +855,24 @@ export async function handleForkChatSession(req, res, deps, sourceSessionId) {
853
855
  let forkPersisted = false;
854
856
  try {
855
857
  const body = await readJsonBody(req);
856
- const throughMessageId = typeof body.throughMessageId === "string" && body.throughMessageId.trim()
857
- ? body.throughMessageId.trim()
858
- : undefined;
859
- // Accept a user or assistant message as the fork anchor. An assistant
860
- // anchor resolves to the user message of its own turn so the runtime
861
- // branch and the persisted copy both truncate at the same Q&A pair.
862
- const anchorIndex = throughMessageId
863
- ? source.messages.findIndex((message) => message.id === throughMessageId)
864
- : -1;
865
- if (throughMessageId && anchorIndex < 0) {
858
+ if (sourceBusy())
859
+ throw new Error("TURN_ACTIVE");
860
+ const requestedAnchor = Object.hasOwn(body, "sourceMessageId") ? body.sourceMessageId : body.throughMessageId;
861
+ const throughMessageId = typeof requestedAnchor === "string" ? requestedAnchor.trim() : undefined;
862
+ const anchorIndex = throughMessageId ? source.messages.findIndex(message => message.id === throughMessageId) : -1;
863
+ const anchor = source.messages[anchorIndex];
864
+ if (requestedAnchor !== undefined && (!anchor || (anchor.role !== "user" && anchor.role !== "assistant"))) {
866
865
  throw new Error("FORK_MESSAGE_NOT_FOUND");
867
866
  }
868
- const throughUserMessageIndex = throughMessageId
869
- ? (() => {
870
- const boundary = anchorIndex >= 0 && source.messages[anchorIndex]?.role === "assistant"
871
- ? (() => {
872
- let index = anchorIndex;
873
- while (index >= 0 && source.messages[index]?.role !== "user") {
874
- index -= 1;
875
- }
876
- return index;
877
- })()
878
- : anchorIndex;
879
- if (boundary < 0)
880
- throw new Error("FORK_MESSAGE_TURN_USER_NOT_FOUND");
881
- return source.messages
882
- .slice(0, boundary + 1)
883
- .filter((message) => message.role === "user").length - 1;
884
- })()
867
+ const throughUserMessageIndex = anchor?.role === "user"
868
+ ? source.messages.slice(0, anchorIndex).filter(message => message.role === "user").length
885
869
  : undefined;
886
870
  const handle = await deps.runtime.forkSession({
871
+ sourceSessionId,
887
872
  sourceSessionFile: source.sessionFile ?? "",
873
+ ...(anchor?.role === "assistant" ? {
874
+ assistantAnchor: { messageId: anchor.id, messages: source.messages },
875
+ } : {}),
888
876
  ...(source.systemPromptSuffix ? { systemPromptSuffix: source.systemPromptSuffix } : {}),
889
877
  sessionMode: source.sessionMode,
890
878
  ...(source.modelProvider && source.modelId
@@ -895,6 +883,8 @@ export async function handleForkChatSession(req, res, deps, sourceSessionId) {
895
883
  : {}),
896
884
  });
897
885
  forkedHandle = handle;
886
+ if (sourceBusy())
887
+ throw new Error("TURN_ACTIVE");
898
888
  await deps.store.forkFrom({
899
889
  sourceSessionId,
900
890
  targetSessionId: handle.sessionId,
@@ -910,7 +900,7 @@ export async function handleForkChatSession(req, res, deps, sourceSessionId) {
910
900
  targetSessionId: handle.sessionId,
911
901
  targetTurnId: `${handle.sessionId}:fork`,
912
902
  });
913
- await deps.operationLinker.recoverSession(handle.sessionId);
903
+ await deps.operationLinker.recoverSession(handle.sessionId).catch(() => undefined);
914
904
  sendJson(res, 201, {
915
905
  ok: true,
916
906
  sessionId: handle.sessionId,
@@ -924,18 +914,20 @@ export async function handleForkChatSession(req, res, deps, sourceSessionId) {
924
914
  }
925
915
  catch (error) {
926
916
  if (forkedHandle && !forkPersisted) {
927
- await deps.runtime.dispose(forkedHandle.sessionId);
917
+ await deps.runtime.dispose(forkedHandle.sessionId).catch(() => undefined);
928
918
  await deps.store
929
919
  .discardUnownedSession(forkedHandle.sessionId, forkedHandle.sessionFile)
930
920
  .catch(() => undefined);
931
921
  }
932
- sendJson(res, 409, {
933
- ok: false,
934
- error: {
935
- code: "SESSION_FORK_FAILED",
936
- message: error instanceof Error ? error.message : String(error),
937
- },
938
- });
922
+ const reason = error instanceof Error ? error.message : "";
923
+ const failure = reason === "FORK_MESSAGE_NOT_FOUND"
924
+ ? { code: reason, message: "找不到这条已保存的消息。请重新打开会话后选择一条回复。" }
925
+ : reason === "FORK_MESSAGE_UNMAPPED" || reason === "FORK_MESSAGE_ENTRY_NOT_FOUND"
926
+ ? { code: "FORK_MESSAGE_UNMAPPED", message: "无法定位这条回复的模型上下文。请选择其他已保存的回复。" }
927
+ : reason === "TURN_ACTIVE"
928
+ ? { code: reason, message: "等待当前回复结束后重试。" }
929
+ : { code: "SESSION_FORK_FAILED", message: "未能创建分支。请重试。" };
930
+ sendJson(res, reason === "FORK_MESSAGE_NOT_FOUND" ? 404 : 409, { ok: false, error: failure });
939
931
  }
940
932
  }
941
933
  export async function handleBranchChatSession(req, res, deps, sessionId) {
@@ -1312,6 +1304,20 @@ export async function handlePutDeferredTurn(req, res, deps, sessionId) {
1312
1304
  });
1313
1305
  return;
1314
1306
  }
1307
+ // A delayed retry may arrive after this request has left the queue and
1308
+ // another turn has started. Return its existing receipt before enqueueing.
1309
+ const admitted = clientRequestId && deps.events.findTurnByClientRequestId(sessionId, clientRequestId);
1310
+ if (admitted) {
1311
+ const normalizedText = text.trim() || (images.length ? "请查看附件图片。" : "");
1312
+ const payloadHash = hashChatTurnPayload({ text: normalizedText, images, references });
1313
+ if (admitted.payloadHash !== payloadHash) {
1314
+ sendJson(res, 409, { ok: false, accepted: false, error: { code: "REQUEST_ID_REUSE_CONFLICT", message: "此请求号已绑定到另一条消息" } });
1315
+ }
1316
+ else {
1317
+ sendJson(res, 200, { ok: true, accepted: true, idempotent: true, turnId: admitted.turnId, turn: turnSummary(admitted) });
1318
+ }
1319
+ return;
1320
+ }
1315
1321
  const active = deps.events.getActiveTurn(sessionId);
1316
1322
  // Queueing binds to the active Turn (running OR stopping); the durable
1317
1323
  // follow-up auto-dispatches when that Turn reaches a terminal state.
@@ -1360,6 +1366,9 @@ export async function handlePutDeferredTurn(req, res, deps, sessionId) {
1360
1366
  });
1361
1367
  return;
1362
1368
  }
1369
+ if (typeof body.draftVersion === "string" && body.draftVersion.length <= 128) {
1370
+ await new ComposerDraftStore(deps.appData).clearSubmitted(sessionId, body.draftVersion).catch(() => undefined);
1371
+ }
1363
1372
  await emitDeferredTurnUpdate(deps, sessionId, blockedByTurnId, result.deferredTurn, result.deferredTurn.revision);
1364
1373
  sendJson(res, 200, {
1365
1374
  ok: true,
@@ -291,29 +291,12 @@ export class ChatSessionStore {
291
291
  const source = await this.get(input.sourceSessionId);
292
292
  if (!source)
293
293
  throw new Error(`chat session not found: ${input.sourceSessionId}`);
294
- // The fork anchor may be a user message or an assistant message. A user
295
- // anchor truncates at itself; an assistant anchor resolves to the user
296
- // message of its own turn so the complete Q&A pair carries into the fork.
297
294
  const anchorIndex = input.throughMessageId
298
295
  ? source.messages.findIndex((message) => message.id === input.throughMessageId)
299
296
  : -1;
300
297
  if (input.throughMessageId && anchorIndex < 0) {
301
298
  throw new Error("FORK_MESSAGE_NOT_FOUND");
302
299
  }
303
- let throughIndex = anchorIndex;
304
- if (anchorIndex >= 0 && source.messages[anchorIndex]?.role === "assistant") {
305
- // Keep the complete Q&A pair: truncate at the assistant answer
306
- // itself. The turn's user message must exist directly before the
307
- // answer chain (same rule the route uses for the runtime branch),
308
- // otherwise the persisted copy and the runtime branch would
309
- // truncate at different turns.
310
- for (let index = anchorIndex; index >= 0; index -= 1) {
311
- if (source.messages[index]?.role === "user")
312
- break;
313
- if (index === 0)
314
- throw new Error("FORK_MESSAGE_TURN_USER_NOT_FOUND");
315
- }
316
- }
317
300
  return this.serialize(input.targetSessionId, async () => {
318
301
  const now = new Date().toISOString();
319
302
  const record = {
@@ -326,10 +309,10 @@ export class ChatSessionStore {
326
309
  updatedAt: now,
327
310
  deferredTurns: [],
328
311
  deferredQueueRevision: 0,
329
- messages: structuredClone(throughIndex >= 0
330
- ? source.messages.slice(0, throughIndex + 1)
312
+ messages: structuredClone(anchorIndex >= 0
313
+ ? source.messages.slice(0, anchorIndex + 1)
331
314
  : source.messages),
332
- toolInvocations: throughIndex >= 0 ? [] : structuredClone(source.toolInvocations),
315
+ toolInvocations: anchorIndex >= 0 ? [] : structuredClone(source.toolInvocations),
333
316
  };
334
317
  const attachmentIds = record.messages.flatMap((message) => Array.isArray(message.attachments)
335
318
  ? message.attachments.map((attachment) => attachment.id)
@@ -970,6 +953,8 @@ export async function runChatTurn(options) {
970
953
  settledEvent = event;
971
954
  }
972
955
  else if (event.type === "message_end") {
956
+ const { piEntryId, ...publicEvent } = event;
957
+ const entryId = await piEntryId;
973
958
  // Persist the assistant bubble FIRST so the SSE frame and the restore
974
959
  // projection share the same durable message id (2026-09-13). The text-
975
960
  // match + 30s window in projectStoredMessagesWithEventOrder was the only
@@ -979,6 +964,7 @@ export async function runChatTurn(options) {
979
964
  const stored = await store.appendMessage(sessionId, {
980
965
  role: "assistant",
981
966
  text: event.text,
967
+ ...(entryId ? { piEntryId: entryId } : {}),
982
968
  ...(event.interrupted ? { interrupted: true } : {}),
983
969
  ...(options.turnId ? { turnId: options.turnId } : {}),
984
970
  ...(event.content && event.content.length > 0
@@ -991,7 +977,7 @@ export async function runChatTurn(options) {
991
977
  // Persistence failure must not swallow the SSE frame — the client
992
978
  // still needs the terminal text even if the durable row is absent.
993
979
  }
994
- options.onEvent?.(messageId ? { ...event, messageId } : event);
980
+ options.onEvent?.(messageId ? { ...publicEvent, messageId } : publicEvent);
995
981
  }
996
982
  else if (event.type !== "tool_result") {
997
983
  options.onEvent?.(event);
@@ -229,7 +229,7 @@ export class TerminalSessionRegistry {
229
229
  cwd: options.cwd,
230
230
  cols: options.cols ?? 120,
231
231
  rows: options.rows ?? 30,
232
- env: process.env ?? {},
232
+ env: { ...(process.env ?? {}), ...options.env },
233
233
  encoding: "utf8",
234
234
  /*
235
235
  * winpty allocates a REAL console host window — the black box that
@@ -41,6 +41,7 @@ export async function buildPersistentTerminalTools(deps) {
41
41
  name: kind,
42
42
  shell: kind,
43
43
  cwd: cwd ?? deps.defaultCwd ?? process.cwd(),
44
+ env: deps.environment?.(),
44
45
  });
45
46
  };
46
47
  const runInShell = async (kind, command, timeoutMs) => {
@@ -4,7 +4,7 @@
4
4
  * Product default remains full: deferred exposure is applied only when a
5
5
  * session explicitly selects progressive mode.
6
6
  */
7
- export const PI_TOOL_CATALOG_VERSION = 1;
7
+ export const PI_TOOL_CATALOG_VERSION = 2;
8
8
  export const PI_TOOL_EXPOSURE_ENTRY = "console-pi-tool-exposure";
9
9
  export const PI_TOOL_FAMILIES = [
10
10
  "default-core",
@@ -55,7 +55,7 @@ export const PI_BROWSER_ADVANCED_TOOLS = Object.freeze([
55
55
  "browser_storage_export", "browser_storage_import",
56
56
  ]);
57
57
  export const PI_BROWSER_AUTOMATION_TOOLS = Object.freeze([
58
- "browser_batch", "browser_script_list", "browser_script_save", "browser_script_run",
58
+ "browser_batch", "browser_cdp", "browser_run", "browser_script_list", "browser_script_save", "browser_script_run",
59
59
  ]);
60
60
  export const PI_REMOTE_TOOLS = Object.freeze([
61
61
  "ssh_list", "ssh_test", "ssh_exec", "ssh_transfer",
@@ -112,6 +112,8 @@ export const OPERATOR_CHAT_BUILTIN_CUSTOM_TOOLS = Object.freeze([
112
112
  "browser_script_list",
113
113
  "browser_script_save",
114
114
  "browser_script_run",
115
+ "browser_cdp",
116
+ "browser_run",
115
117
  ...OPERATOR_CHAT_SQL_TOOL_CAPABILITIES.map((tool) => tool.toolId),
116
118
  ...OPERATOR_CHAT_APIWB_TOOL_CAPABILITIES.map((tool) => tool.toolId),
117
119
  ]);
@@ -1,3 +1,12 @@
1
+ /** The controlled desk keeps its binding in the URL so a reconnect can recover it. */
2
+ export function buildControlledChatHref(workspaceId, sessionId) {
3
+ const query = new URLSearchParams();
4
+ if (workspaceId)
5
+ query.set("workspaceId", workspaceId);
6
+ if (sessionId)
7
+ query.set("sessionId", sessionId);
8
+ return `/#/chat/controlled${query.size ? `?${query}` : ""}`;
9
+ }
1
10
  export const ACTIVE_CHAT_SESSION_STORAGE_KEY = "loop-console.operator-chat.active-session.v1";
2
11
  export const ACTIVE_CHAT_SESSION_BY_WORKSPACE_STORAGE_KEY = "loop-console.operator-chat.active-session-by-workspace.v1";
3
12
  export const DEFAULT_LANDING_STORAGE_KEY = "loop-console.operator-chat.default-landing.v1";
@@ -1 +1 @@
1
- import{g as p,r as u,d as a}from"./chunk-6Q2QTUOP-DxhJidW7.js";import{p as f}from"./chunk-JWPE2WC7-LE21hHhq.js";import{_ as n,l as o}from"./mermaid.core-CIeuqFlz.js";import{M as c,b as d}from"./cynefin-VYW2F7L2-BIFL8KrA.js";import"./FilePreviewDocx-ybM3ZqSl.js";var v=d().RailroadAbnf.parser.LangiumParser,i=n(e=>{const r=e.alternatives.map(g);return r.length===1?r[0]:{type:"choice",alternatives:r}},"transformAlternation"),g=n(e=>{const r=e.elements.map(y);return r.length===1?r[0]:{type:"sequence",elements:r}},"transformConcatenation"),b=n(e=>{if(e.includes("*")){const[t,s]=e.split("*"),l=t?parseInt(t,10):0,m=s?parseInt(s,10):1/0;return{min:l,max:m}}const r=parseInt(e,10);return{min:r,max:r}},"parseRepeat"),y=n(e=>{const r=A(e.primary);if(!e.repeat)return r;const{min:t,max:s}=b(e.repeat);return t===0&&s===1?{type:"optional",element:r}:{type:"repetition",element:r,min:t,max:s}},"transformElement"),A=n(e=>{switch(e.$type){case"AbnfStringLiteral":return{type:"terminal",value:e.value};case"AbnfNumVal":return{type:"terminal",value:e.value};case"AbnfRuleName":return{type:"nonterminal",name:e.name};case"AbnfGroup":return i(e.element);case"AbnfOptionalGroup":return{type:"optional",element:i(e.element)};default:throw new Error(`Unsupported ABNF primary node: ${e.$type}`)}},"transformPrimary"),P=n(e=>({name:e.name,definition:i(e.definition)}),"transformRule"),h=n(e=>{f(e,a),e.title&&a.setTitle(e.title),e.rules.map(r=>a.addRule(P(r)))},"populateDb"),R={parse:n(e=>{a.clear(),o.debug("[ABNF Parser] Starting Langium parse");const r=v.parse(e);if(r.lexerErrors.length>0||r.parserErrors.length>0)throw new c(r);const t=r.value;o.debug("[ABNF Parser] Parsed rules:",t.rules.length),h(t),o.debug("[ABNF Parser] Parse complete")},"parse"),parser:{yy:a}},B={parser:R,db:a,renderer:u,styles:p};export{B as diagram};
1
+ import{g as p,r as u,d as a}from"./chunk-6Q2QTUOP-dYOgBsXL.js";import{p as f}from"./chunk-JWPE2WC7-BYibgnxd.js";import{_ as n,l as o}from"./mermaid.core-DXXCdcu4.js";import{M as c,b as d}from"./cynefin-VYW2F7L2-BIFL8KrA.js";import"./FilePreviewDocx-ybM3ZqSl.js";var v=d().RailroadAbnf.parser.LangiumParser,i=n(e=>{const r=e.alternatives.map(g);return r.length===1?r[0]:{type:"choice",alternatives:r}},"transformAlternation"),g=n(e=>{const r=e.elements.map(y);return r.length===1?r[0]:{type:"sequence",elements:r}},"transformConcatenation"),b=n(e=>{if(e.includes("*")){const[t,s]=e.split("*"),l=t?parseInt(t,10):0,m=s?parseInt(s,10):1/0;return{min:l,max:m}}const r=parseInt(e,10);return{min:r,max:r}},"parseRepeat"),y=n(e=>{const r=A(e.primary);if(!e.repeat)return r;const{min:t,max:s}=b(e.repeat);return t===0&&s===1?{type:"optional",element:r}:{type:"repetition",element:r,min:t,max:s}},"transformElement"),A=n(e=>{switch(e.$type){case"AbnfStringLiteral":return{type:"terminal",value:e.value};case"AbnfNumVal":return{type:"terminal",value:e.value};case"AbnfRuleName":return{type:"nonterminal",name:e.name};case"AbnfGroup":return i(e.element);case"AbnfOptionalGroup":return{type:"optional",element:i(e.element)};default:throw new Error(`Unsupported ABNF primary node: ${e.$type}`)}},"transformPrimary"),P=n(e=>({name:e.name,definition:i(e.definition)}),"transformRule"),h=n(e=>{f(e,a),e.title&&a.setTitle(e.title),e.rules.map(r=>a.addRule(P(r)))},"populateDb"),R={parse:n(e=>{a.clear(),o.debug("[ABNF Parser] Starting Langium parse");const r=v.parse(e);if(r.lexerErrors.length>0||r.parserErrors.length>0)throw new c(r);const t=r.value;o.debug("[ABNF Parser] Parsed rules:",t.rules.length),h(t),o.debug("[ABNF Parser] Parse complete")},"parse"),parser:{yy:a}},B={parser:R,db:a,renderer:u,styles:p};export{B as diagram};
@@ -1 +1 @@
1
- import{Y as ln,$ as an,a0 as F,a1 as q,a2 as j,a3 as un,a4 as y,a5 as tn,a6 as J,a7 as _,a8 as rn,a9 as o,aa as on,ab as sn,ac as fn}from"./mermaid.core-CIeuqFlz.js";function cn(l){return l.innerRadius}function yn(l){return l.outerRadius}function gn(l){return l.startAngle}function dn(l){return l.endAngle}function mn(l){return l&&l.padAngle}function pn(l,h,I,D,v,A,z,a){var O=I-l,i=D-h,n=z-v,d=a-A,u=d*O-n*i;if(!(u*u<y))return u=(n*(h-A)-d*(l-v))/u,[l+u*O,h+u*i]}function U(l,h,I,D,v,A,z){var a=l-I,O=h-D,i=(z?A:-A)/J(a*a+O*O),n=i*O,d=-i*a,u=l+n,s=h+d,f=I+n,c=D+d,B=(u+f)/2,t=(s+c)/2,m=f-u,g=c-s,R=m*m+g*g,T=v-A,P=u*c-f*s,S=(g<0?-1:1)*J(on(0,T*T*R-P*P)),Y=(P*g-m*S)/R,$=(-P*m-g*S)/R,w=(P*g+m*S)/R,p=(-P*m+g*S)/R,x=Y-B,e=$-t,r=w-B,C=p-t;return x*x+e*e>r*r+C*C&&(Y=w,$=p),{cx:Y,cy:$,x01:-n,y01:-d,x11:Y*(v/T-1),y11:$*(v/T-1)}}function hn(){var l=cn,h=yn,I=j(0),D=null,v=gn,A=dn,z=mn,a=null,O=ln(i);function i(){var n,d,u=+l.apply(this,arguments),s=+h.apply(this,arguments),f=v.apply(this,arguments)-un,c=A.apply(this,arguments)-un,B=rn(c-f),t=c>f;if(a||(a=n=O()),s<u&&(d=s,s=u,u=d),!(s>y))a.moveTo(0,0);else if(B>tn-y)a.moveTo(s*F(f),s*q(f)),a.arc(0,0,s,f,c,!t),u>y&&(a.moveTo(u*F(c),u*q(c)),a.arc(0,0,u,c,f,t));else{var m=f,g=c,R=f,T=c,P=B,S=B,Y=z.apply(this,arguments)/2,$=Y>y&&(D?+D.apply(this,arguments):J(u*u+s*s)),w=_(rn(s-u)/2,+I.apply(this,arguments)),p=w,x=w,e,r;if($>y){var C=sn($/u*q(Y)),K=sn($/s*q(Y));(P-=C*2)>y?(C*=t?1:-1,R+=C,T-=C):(P=0,R=T=(f+c)/2),(S-=K*2)>y?(K*=t?1:-1,m+=K,g-=K):(S=0,m=g=(f+c)/2)}var G=s*F(m),H=s*q(m),L=u*F(T),M=u*q(T);if(w>y){var N=s*F(g),Q=s*q(g),V=u*F(R),W=u*q(R),E;if(B<an)if(E=pn(G,H,V,W,N,Q,L,M)){var X=G-E[0],Z=H-E[1],b=N-E[0],k=Q-E[1],nn=1/q(fn((X*b+Z*k)/(J(X*X+Z*Z)*J(b*b+k*k)))/2),en=J(E[0]*E[0]+E[1]*E[1]);p=_(w,(u-en)/(nn-1)),x=_(w,(s-en)/(nn+1))}else p=x=0}S>y?x>y?(e=U(V,W,G,H,s,x,t),r=U(N,Q,L,M,s,x,t),a.moveTo(e.cx+e.x01,e.cy+e.y01),x<w?a.arc(e.cx,e.cy,x,o(e.y01,e.x01),o(r.y01,r.x01),!t):(a.arc(e.cx,e.cy,x,o(e.y01,e.x01),o(e.y11,e.x11),!t),a.arc(0,0,s,o(e.cy+e.y11,e.cx+e.x11),o(r.cy+r.y11,r.cx+r.x11),!t),a.arc(r.cx,r.cy,x,o(r.y11,r.x11),o(r.y01,r.x01),!t))):(a.moveTo(G,H),a.arc(0,0,s,m,g,!t)):a.moveTo(G,H),!(u>y)||!(P>y)?a.lineTo(L,M):p>y?(e=U(L,M,N,Q,u,-p,t),r=U(G,H,V,W,u,-p,t),a.lineTo(e.cx+e.x01,e.cy+e.y01),p<w?a.arc(e.cx,e.cy,p,o(e.y01,e.x01),o(r.y01,r.x01),!t):(a.arc(e.cx,e.cy,p,o(e.y01,e.x01),o(e.y11,e.x11),!t),a.arc(0,0,u,o(e.cy+e.y11,e.cx+e.x11),o(r.cy+r.y11,r.cx+r.x11),t),a.arc(r.cx,r.cy,p,o(r.y11,r.x11),o(r.y01,r.x01),!t))):a.arc(0,0,u,T,R,t)}if(a.closePath(),n)return a=null,n+""||null}return i.centroid=function(){var n=(+l.apply(this,arguments)+ +h.apply(this,arguments))/2,d=(+v.apply(this,arguments)+ +A.apply(this,arguments))/2-an/2;return[F(d)*n,q(d)*n]},i.innerRadius=function(n){return arguments.length?(l=typeof n=="function"?n:j(+n),i):l},i.outerRadius=function(n){return arguments.length?(h=typeof n=="function"?n:j(+n),i):h},i.cornerRadius=function(n){return arguments.length?(I=typeof n=="function"?n:j(+n),i):I},i.padRadius=function(n){return arguments.length?(D=n==null?null:typeof n=="function"?n:j(+n),i):D},i.startAngle=function(n){return arguments.length?(v=typeof n=="function"?n:j(+n),i):v},i.endAngle=function(n){return arguments.length?(A=typeof n=="function"?n:j(+n),i):A},i.padAngle=function(n){return arguments.length?(z=typeof n=="function"?n:j(+n),i):z},i.context=function(n){return arguments.length?(a=n??null,i):a},i}export{hn as d};
1
+ import{Y as ln,$ as an,a0 as F,a1 as q,a2 as j,a3 as un,a4 as y,a5 as tn,a6 as J,a7 as _,a8 as rn,a9 as o,aa as on,ab as sn,ac as fn}from"./mermaid.core-DXXCdcu4.js";function cn(l){return l.innerRadius}function yn(l){return l.outerRadius}function gn(l){return l.startAngle}function dn(l){return l.endAngle}function mn(l){return l&&l.padAngle}function pn(l,h,I,D,v,A,z,a){var O=I-l,i=D-h,n=z-v,d=a-A,u=d*O-n*i;if(!(u*u<y))return u=(n*(h-A)-d*(l-v))/u,[l+u*O,h+u*i]}function U(l,h,I,D,v,A,z){var a=l-I,O=h-D,i=(z?A:-A)/J(a*a+O*O),n=i*O,d=-i*a,u=l+n,s=h+d,f=I+n,c=D+d,B=(u+f)/2,t=(s+c)/2,m=f-u,g=c-s,R=m*m+g*g,T=v-A,P=u*c-f*s,S=(g<0?-1:1)*J(on(0,T*T*R-P*P)),Y=(P*g-m*S)/R,$=(-P*m-g*S)/R,w=(P*g+m*S)/R,p=(-P*m+g*S)/R,x=Y-B,e=$-t,r=w-B,C=p-t;return x*x+e*e>r*r+C*C&&(Y=w,$=p),{cx:Y,cy:$,x01:-n,y01:-d,x11:Y*(v/T-1),y11:$*(v/T-1)}}function hn(){var l=cn,h=yn,I=j(0),D=null,v=gn,A=dn,z=mn,a=null,O=ln(i);function i(){var n,d,u=+l.apply(this,arguments),s=+h.apply(this,arguments),f=v.apply(this,arguments)-un,c=A.apply(this,arguments)-un,B=rn(c-f),t=c>f;if(a||(a=n=O()),s<u&&(d=s,s=u,u=d),!(s>y))a.moveTo(0,0);else if(B>tn-y)a.moveTo(s*F(f),s*q(f)),a.arc(0,0,s,f,c,!t),u>y&&(a.moveTo(u*F(c),u*q(c)),a.arc(0,0,u,c,f,t));else{var m=f,g=c,R=f,T=c,P=B,S=B,Y=z.apply(this,arguments)/2,$=Y>y&&(D?+D.apply(this,arguments):J(u*u+s*s)),w=_(rn(s-u)/2,+I.apply(this,arguments)),p=w,x=w,e,r;if($>y){var C=sn($/u*q(Y)),K=sn($/s*q(Y));(P-=C*2)>y?(C*=t?1:-1,R+=C,T-=C):(P=0,R=T=(f+c)/2),(S-=K*2)>y?(K*=t?1:-1,m+=K,g-=K):(S=0,m=g=(f+c)/2)}var G=s*F(m),H=s*q(m),L=u*F(T),M=u*q(T);if(w>y){var N=s*F(g),Q=s*q(g),V=u*F(R),W=u*q(R),E;if(B<an)if(E=pn(G,H,V,W,N,Q,L,M)){var X=G-E[0],Z=H-E[1],b=N-E[0],k=Q-E[1],nn=1/q(fn((X*b+Z*k)/(J(X*X+Z*Z)*J(b*b+k*k)))/2),en=J(E[0]*E[0]+E[1]*E[1]);p=_(w,(u-en)/(nn-1)),x=_(w,(s-en)/(nn+1))}else p=x=0}S>y?x>y?(e=U(V,W,G,H,s,x,t),r=U(N,Q,L,M,s,x,t),a.moveTo(e.cx+e.x01,e.cy+e.y01),x<w?a.arc(e.cx,e.cy,x,o(e.y01,e.x01),o(r.y01,r.x01),!t):(a.arc(e.cx,e.cy,x,o(e.y01,e.x01),o(e.y11,e.x11),!t),a.arc(0,0,s,o(e.cy+e.y11,e.cx+e.x11),o(r.cy+r.y11,r.cx+r.x11),!t),a.arc(r.cx,r.cy,x,o(r.y11,r.x11),o(r.y01,r.x01),!t))):(a.moveTo(G,H),a.arc(0,0,s,m,g,!t)):a.moveTo(G,H),!(u>y)||!(P>y)?a.lineTo(L,M):p>y?(e=U(L,M,N,Q,u,-p,t),r=U(G,H,V,W,u,-p,t),a.lineTo(e.cx+e.x01,e.cy+e.y01),p<w?a.arc(e.cx,e.cy,p,o(e.y01,e.x01),o(r.y01,r.x01),!t):(a.arc(e.cx,e.cy,p,o(e.y01,e.x01),o(e.y11,e.x11),!t),a.arc(0,0,u,o(e.cy+e.y11,e.cx+e.x11),o(r.cy+r.y11,r.cx+r.x11),t),a.arc(r.cx,r.cy,p,o(r.y11,r.x11),o(r.y01,r.x01),!t))):a.arc(0,0,u,T,R,t)}if(a.closePath(),n)return a=null,n+""||null}return i.centroid=function(){var n=(+l.apply(this,arguments)+ +h.apply(this,arguments))/2,d=(+v.apply(this,arguments)+ +A.apply(this,arguments))/2-an/2;return[F(d)*n,q(d)*n]},i.innerRadius=function(n){return arguments.length?(l=typeof n=="function"?n:j(+n),i):l},i.outerRadius=function(n){return arguments.length?(h=typeof n=="function"?n:j(+n),i):h},i.cornerRadius=function(n){return arguments.length?(I=typeof n=="function"?n:j(+n),i):I},i.padRadius=function(n){return arguments.length?(D=n==null?null:typeof n=="function"?n:j(+n),i):D},i.startAngle=function(n){return arguments.length?(v=typeof n=="function"?n:j(+n),i):v},i.endAngle=function(n){return arguments.length?(A=typeof n=="function"?n:j(+n),i):A},i.padAngle=function(n){return arguments.length?(z=typeof n=="function"?n:j(+n),i):z},i.context=function(n){return arguments.length?(a=n??null,i):a},i}export{hn as d};