@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.
- package/CHANGELOG.md +11 -1
- package/README.md +1 -0
- package/dist/build-stamp.json +3 -3
- package/dist/worker/cli.js +16 -4
- package/dist/worker/console/chat/browser-automation.js +530 -26
- package/dist/worker/console/chat/browser-cdp.js +145 -0
- package/dist/worker/console/chat/browser-evaluation.js +26 -25
- package/dist/worker/console/chat/browser-exposure.js +8 -26
- package/dist/worker/console/chat/browser-la.js +266 -0
- package/dist/worker/console/chat/browser-policy.js +5 -4
- package/dist/worker/console/chat/browser-preload.js +119 -0
- package/dist/worker/console/chat/browser-preloads/vcp.js +417 -0
- package/dist/worker/console/chat/browser-region-fingerprint.js +36 -0
- package/dist/worker/console/chat/browser-run.js +97 -0
- package/dist/worker/console/chat/browser-screenshot-result.js +2 -2
- package/dist/worker/console/chat/browser-scripts.js +42 -4
- package/dist/worker/console/chat/browser-timeline.js +4 -0
- package/dist/worker/console/chat/pi-runtime/custom-tools/browser-tools.js +73 -16
- package/dist/worker/console/chat/pi-runtime/sdk-bindings.js +70 -0
- package/dist/worker/console/chat/pi-runtime.js +53 -35
- package/dist/worker/console/chat/png-fingerprint.js +189 -0
- package/dist/worker/console/chat/routes.js +47 -38
- package/dist/worker/console/chat/session-store.js +7 -21
- package/dist/worker/console/chat/terminal-sessions.js +1 -1
- package/dist/worker/console/chat/terminal-tools.js +1 -0
- package/dist/worker/console/chat/tool-exposure-catalog.js +2 -2
- package/dist/worker/console/chat/tools.js +2 -0
- package/dist/worker/console/chat/workspace-landing.js +9 -0
- package/dist/worker/console/static/assets/{abnfDiagram-N423BO3Z-C29lbS0T.js → abnfDiagram-N423BO3Z-mcArn3xd.js} +1 -1
- package/dist/worker/console/static/assets/{arc--Vi-BzUR.js → arc-D22Gr5Kh.js} +1 -1
- package/dist/worker/console/static/assets/{architectureDiagram-T3A2C74G-DwdFPJd-.js → architectureDiagram-T3A2C74G-5P-xaSwS.js} +1 -1
- package/dist/worker/console/static/assets/{blockDiagram-VBNYF7ZC-BFuPq4yu.js → blockDiagram-VBNYF7ZC-ClYqZUog.js} +1 -1
- package/dist/worker/console/static/assets/{c4Diagram-5PPSVZJV-oKn9EfQa.js → c4Diagram-5PPSVZJV-B5615n-w.js} +1 -1
- package/dist/worker/console/static/assets/channel-BcPrK1uQ.js +1 -0
- package/dist/worker/console/static/assets/{chunk-2GRJ4B5K-TwXtrEhU.js → chunk-2GRJ4B5K-DaXOOg2S.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-2Q5K7J3B-Cc3zFHjT.js → chunk-2Q5K7J3B-DewgVpWS.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-5RXB4S5H-xJfu4YKo.js → chunk-5RXB4S5H-C6dIPMGB.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-5VM5RSS4-VBNdtRqb.js → chunk-5VM5RSS4-CIxapjAj.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-6Q2QTUOP-DxhJidW7.js → chunk-6Q2QTUOP-dYOgBsXL.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-GF5L2VYU-P6N3qPX5.js → chunk-GF5L2VYU-NOEzJIgx.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-JWPE2WC7-LE21hHhq.js → chunk-JWPE2WC7-BYibgnxd.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-KBJHAD2P-CZmtvzKZ.js → chunk-KBJHAD2P-CbxJFJr1.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-RYQCIY6F-BQrw57-q.js → chunk-RYQCIY6F-MaH52RLP.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-XXDRQBXY-DSNQHlxO.js → chunk-XXDRQBXY-D3YLa2yq.js} +1 -1
- package/dist/worker/console/static/assets/classDiagram-JCYQIIEL-DdqL4uaJ.js +1 -0
- package/dist/worker/console/static/assets/classDiagram-v2-OCEON4UE-DdqL4uaJ.js +1 -0
- package/dist/worker/console/static/assets/{cose-bilkent-JH36ORCC-Ckm2oC4s.js → cose-bilkent-JH36ORCC-lsxffBWh.js} +1 -1
- package/dist/worker/console/static/assets/{cynefinDiagram-MW4NZA55-B7ecDXon.js → cynefinDiagram-MW4NZA55-FlNQHEbD.js} +1 -1
- package/dist/worker/console/static/assets/{dagre-VZM6K2ZE-Cx_kCtwr.js → dagre-VZM6K2ZE-ChG_TvEA.js} +1 -1
- package/dist/worker/console/static/assets/{diagram-7IWD3JNH-DTqfz-9k.js → diagram-7IWD3JNH-BL-8sI-U.js} +1 -1
- package/dist/worker/console/static/assets/{diagram-B4RE2ZJO-BH8nNNYl.js → diagram-B4RE2ZJO-DRuUXlYn.js} +1 -1
- package/dist/worker/console/static/assets/{diagram-LBJQPF4R-mwUmtiIR.js → diagram-LBJQPF4R-BNWH241c.js} +1 -1
- package/dist/worker/console/static/assets/{diagram-Q27KOJAE-B6_cW-cc.js → diagram-Q27KOJAE-DM4OKpX4.js} +1 -1
- package/dist/worker/console/static/assets/{diagram-UB23O5K3-D1sGiHf5.js → diagram-UB23O5K3-DngjP8qb.js} +1 -1
- package/dist/worker/console/static/assets/{ebnfDiagram-BXEA7PRR-C07tYieV.js → ebnfDiagram-BXEA7PRR-jVdtkqdM.js} +1 -1
- package/dist/worker/console/static/assets/{erDiagram-JOGREHBK-eHwocxI1.js → erDiagram-JOGREHBK-BTc9JI_e.js} +1 -1
- package/dist/worker/console/static/assets/{flowDiagram-UKHOOZJN-B1B-mb0t.js → flowDiagram-UKHOOZJN-48TF2hOm.js} +1 -1
- package/dist/worker/console/static/assets/{ganttDiagram-PKOTCBZU-B2fpno6f.js → ganttDiagram-PKOTCBZU-Dk-BQhyz.js} +1 -1
- package/dist/worker/console/static/assets/{gitGraphDiagram-DS77QQ5N-DcM98HR9.js → gitGraphDiagram-DS77QQ5N-Cq8vG_LR.js} +1 -1
- package/dist/worker/console/static/assets/{infoDiagram-6WML65LV-edHmAaaC.js → infoDiagram-6WML65LV-YL-Nd82t.js} +1 -1
- package/dist/worker/console/static/assets/{ishikawaDiagram-WSZJBQD7-Df_rsjoZ.js → ishikawaDiagram-WSZJBQD7-FWxeUP4G.js} +1 -1
- package/dist/worker/console/static/assets/{journeyDiagram-NVQOT4AX-BqK30536.js → journeyDiagram-NVQOT4AX-B9joXO0y.js} +1 -1
- package/dist/worker/console/static/assets/{kanban-definition-27J2QSJJ-DCvcYw-F.js → kanban-definition-27J2QSJJ-DUr3LGth.js} +1 -1
- package/dist/worker/console/static/assets/{linear-4rMK0UAe.js → linear-Cs-mfq2-.js} +1 -1
- package/dist/worker/console/static/assets/main-DKX9JQ3f.css +1 -0
- package/dist/worker/console/static/assets/main-ashAmyih.js +655 -0
- package/dist/worker/console/static/assets/{mermaid.core-CIeuqFlz.js → mermaid.core-DXXCdcu4.js} +4 -4
- package/dist/worker/console/static/assets/{mindmap-definition-FAOFIHXS-isklXv_u.js → mindmap-definition-FAOFIHXS--vtGc5sI.js} +1 -1
- package/dist/worker/console/static/assets/{pegDiagram-VL7TDLO6-DufJ3B32.js → pegDiagram-VL7TDLO6-fiXBc-id.js} +1 -1
- package/dist/worker/console/static/assets/{pieDiagram-7S7Q4E2Y-e-dscJOX.js → pieDiagram-7S7Q4E2Y-Cx5Lr1-Y.js} +1 -1
- package/dist/worker/console/static/assets/{quadrantDiagram-CIZ2JOQS-BMXdwlfZ.js → quadrantDiagram-CIZ2JOQS-BlNemfDx.js} +1 -1
- package/dist/worker/console/static/assets/{railroadDiagram-AXF67PYL-BkLHnA2m.js → railroadDiagram-AXF67PYL-BsuFyiqc.js} +1 -1
- package/dist/worker/console/static/assets/{requirementDiagram-LRYGKXZP-BzXmvm6l.js → requirementDiagram-LRYGKXZP-CKEYRC2J.js} +1 -1
- package/dist/worker/console/static/assets/{sankeyDiagram-W5VNT64P-BZuur-BM.js → sankeyDiagram-W5VNT64P-vrMh2hZZ.js} +1 -1
- package/dist/worker/console/static/assets/{sequenceDiagram-SI44F4Z6-DbZxmtRn.js → sequenceDiagram-SI44F4Z6-BeA4ln2I.js} +1 -1
- package/dist/worker/console/static/assets/{sheet-workbook-D_6Enbgn.js → sheet-workbook-P_0sJUSC.js} +1 -1
- package/dist/worker/console/static/assets/{sizeCapture-X5ZJPWSS-BHbP5ADt.js → sizeCapture-X5ZJPWSS-BdgLOvid.js} +1 -1
- package/dist/worker/console/static/assets/{stateDiagram-OKZ733FA-CGNrvQQV.js → stateDiagram-OKZ733FA-CcI28rqU.js} +1 -1
- package/dist/worker/console/static/assets/stateDiagram-v2-UEYNNEHI-B0DPdHTy.js +1 -0
- package/dist/worker/console/static/assets/{swimlanes-SLNWSIFB-BWNaMfHj.js → swimlanes-SLNWSIFB-DGNDAHUl.js} +2 -2
- package/dist/worker/console/static/assets/swimlanesDiagram-ULZ7WXOC-Ctgvnx6w.js +8 -0
- package/dist/worker/console/static/assets/{timeline-definition-Z64GVDOM-BhI167N4.js → timeline-definition-Z64GVDOM-DBzInzT7.js} +1 -1
- package/dist/worker/console/static/assets/{vennDiagram-T6HMQDX7-BFHqLPNk.js → vennDiagram-T6HMQDX7-C97pu5Ae.js} +1 -1
- package/dist/worker/console/static/assets/{wardleyDiagram-T6FBY63Y-D-ThxcCm.js → wardleyDiagram-T6FBY63Y-D3tT-Oxo.js} +1 -1
- package/dist/worker/console/static/assets/{xychartDiagram-ELKLHX3M-CeUzoGed.js → xychartDiagram-ELKLHX3M-1_u6WRbI.js} +1 -1
- package/dist/worker/console/static/index.html +2 -2
- package/dist/worker/console/static-src/operator-chat/controlled-request-status.js +28 -0
- package/dist/worker/console/static-src/operator-chat/turn-submission.js +3 -0
- package/dist/worker/console/static-src/operator-chat/useChatSessions.js +140 -34
- package/dist/worker/console/static-src/operator-chat/useChatStream.js +12 -2
- package/dist/worker/console/static-src/operator-chat/useChatThread.js +5 -0
- package/dist/worker/console/static-src/operator-chat/useComposer.js +10 -17
- package/dist/worker/console/static-src/operator-chat/useControlledHandoff.js +33 -0
- package/dist/worker/console/static-src/operator-chat/useControlledReceipt.js +206 -0
- package/dist/worker/console/static-src/shell/workspace-route.js +17 -1
- package/dist/worker/observe/static/operator-chrome.css +49 -0
- package/dist/worker/observe/static/operator-chrome.d.ts +7 -0
- package/dist/worker/observe/static/operator-chrome.js +31 -0
- package/docs/architecture/runtime-boundaries.md +5 -0
- package/package.json +3 -3
- package/dist/worker/console/static/assets/channel-o_uspxIc.js +0 -1
- package/dist/worker/console/static/assets/classDiagram-JCYQIIEL-BAMhQfS-.js +0 -1
- package/dist/worker/console/static/assets/classDiagram-v2-OCEON4UE-BAMhQfS-.js +0 -1
- package/dist/worker/console/static/assets/main-CBjwyx0a.js +0 -654
- package/dist/worker/console/static/assets/main-CGnkpKqw.css +0 -1
- package/dist/worker/console/static/assets/stateDiagram-v2-UEYNNEHI-Oa0mw2RA.js +0 -1
- package/dist/worker/console/static/assets/swimlanesDiagram-ULZ7WXOC-CylkK52a.js +0 -8
|
@@ -151,6 +151,7 @@ export function useChatStream(params) {
|
|
|
151
151
|
if (refs.sessionRef.current?.sessionId !== sessionId ||
|
|
152
152
|
refs.sessionGenerationRef.current !== generation)
|
|
153
153
|
return;
|
|
154
|
+
const wasStopping = refs.stopRequestedRef.current || refs.stoppingTurnIdRef.current;
|
|
154
155
|
const pendingClientRequestId = refs.pendingSubmissionRef.current?.clientRequestId;
|
|
155
156
|
if (pendingClientRequestId)
|
|
156
157
|
releaseSubmitOwnership(pendingClientRequestId);
|
|
@@ -159,6 +160,10 @@ export function useChatStream(params) {
|
|
|
159
160
|
refs.assistantIdRef.current = null;
|
|
160
161
|
refs.stoppingTurnIdRef.current = null;
|
|
161
162
|
refs.stopRequestedRef.current = false;
|
|
163
|
+
// The composer may already show idle, while actions such as forking
|
|
164
|
+
// still depend on the retained stop ownership.
|
|
165
|
+
if (wasStopping)
|
|
166
|
+
thread.notifyTurnOwnershipChange();
|
|
162
167
|
setStreaming(false);
|
|
163
168
|
setTurnPhase("idle");
|
|
164
169
|
setStreamingAssistantId(null);
|
|
@@ -169,6 +174,7 @@ export function useChatStream(params) {
|
|
|
169
174
|
clearEmptyAssistant(setMessages, assistantId);
|
|
170
175
|
}, [
|
|
171
176
|
refs,
|
|
177
|
+
thread.notifyTurnOwnershipChange,
|
|
172
178
|
releaseSubmitOwnership,
|
|
173
179
|
setStreaming,
|
|
174
180
|
setTurnPhase,
|
|
@@ -639,6 +645,10 @@ export function useChatStream(params) {
|
|
|
639
645
|
try {
|
|
640
646
|
for (let retry = 0; retry < 2; retry += 1) {
|
|
641
647
|
const { response, body } = await putOnce();
|
|
648
|
+
if (response.ok && body.accepted && body.turn?.clientRequestId === attempt.clientRequestId) {
|
|
649
|
+
settleSubmission(attempt, "accepted");
|
|
650
|
+
return { action: "handled" };
|
|
651
|
+
}
|
|
642
652
|
if (response.ok && body.accepted && body.deferredTurn) {
|
|
643
653
|
acceptDeferred(body.deferredTurn, body.deferredTurns);
|
|
644
654
|
return { action: "handled" };
|
|
@@ -655,7 +665,7 @@ export function useChatStream(params) {
|
|
|
655
665
|
`待发送消息未被服务端接受(HTTP ${response.status})`);
|
|
656
666
|
return { action: "handled" };
|
|
657
667
|
}
|
|
658
|
-
const canonical = await fetchSessionState(attempt.identity.sessionId);
|
|
668
|
+
const canonical = await fetchSessionState(attempt.identity.sessionId, { clientRequestId: attempt.clientRequestId });
|
|
659
669
|
const decision = reconcileDeferredSubmissionFromState({
|
|
660
670
|
clientRequestId: attempt.clientRequestId,
|
|
661
671
|
blockedByTurnId: input.blockedByTurnId,
|
|
@@ -689,7 +699,7 @@ export function useChatStream(params) {
|
|
|
689
699
|
catch (error) {
|
|
690
700
|
if (attempt.signal.aborted)
|
|
691
701
|
return { action: "handled" };
|
|
692
|
-
const canonical = await fetchSessionState(attempt.identity.sessionId);
|
|
702
|
+
const canonical = await fetchSessionState(attempt.identity.sessionId, { clientRequestId: attempt.clientRequestId });
|
|
693
703
|
const decision = reconcileDeferredSubmissionFromState({
|
|
694
704
|
clientRequestId: attempt.clientRequestId,
|
|
695
705
|
blockedByTurnId: input.blockedByTurnId,
|
|
@@ -169,6 +169,10 @@ export function useChatThread(params) {
|
|
|
169
169
|
const [sddSessionIdentity, setSddSessionIdentity] = useState(null);
|
|
170
170
|
const [streaming, setStreaming] = useState(false);
|
|
171
171
|
const [turnPhase, setTurnPhase] = useState("idle");
|
|
172
|
+
const [, setTurnOwnershipRevision] = useState(0);
|
|
173
|
+
const notifyTurnOwnershipChange = useCallback(() => {
|
|
174
|
+
setTurnOwnershipRevision((revision) => revision + 1);
|
|
175
|
+
}, []);
|
|
172
176
|
const [deferredTurn, setDeferredTurn] = useState(null);
|
|
173
177
|
const [deferredTurns, setDeferredTurns] = useState([]);
|
|
174
178
|
const [pendingQuestion, setPendingQuestion] = useState(null);
|
|
@@ -773,6 +777,7 @@ export function useChatThread(params) {
|
|
|
773
777
|
setStreaming,
|
|
774
778
|
turnPhase,
|
|
775
779
|
setTurnPhase,
|
|
780
|
+
notifyTurnOwnershipChange,
|
|
776
781
|
deferredTurn,
|
|
777
782
|
setDeferredTurn,
|
|
778
783
|
deferredTurns,
|
|
@@ -119,23 +119,15 @@ export function removePendingImage(items, image) {
|
|
|
119
119
|
export function useComposer(params) {
|
|
120
120
|
const { origin, sessionIdentity, sessionMode, sessionReady = true, refs, setError, onUnrecoverableSession, } = params;
|
|
121
121
|
const sessionId = sessionIdentity?.sessionId;
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
*/
|
|
132
|
-
ledgerRef.current = new ComposerSessionLedger(Date.now, releaseImagePreviews);
|
|
133
|
-
}
|
|
134
|
-
const ledger = ledgerRef.current;
|
|
135
|
-
const draftSyncQueueRef = useRef(null);
|
|
136
|
-
if (!draftSyncQueueRef.current)
|
|
137
|
-
draftSyncQueueRef.current = new ComposerDraftSyncQueue();
|
|
138
|
-
const draftSyncQueue = draftSyncQueueRef.current;
|
|
122
|
+
// A view switch remounts the composer. Both layouts share draft versions,
|
|
123
|
+
// attachment previews, and the per-session ordering of writes already in flight.
|
|
124
|
+
const localDrafts = useRef(null);
|
|
125
|
+
const owner = params.sharedDrafts ?? localDrafts;
|
|
126
|
+
owner.current ??= {
|
|
127
|
+
ledger: new ComposerSessionLedger(Date.now, releaseImagePreviews),
|
|
128
|
+
queue: new ComposerDraftSyncQueue(),
|
|
129
|
+
};
|
|
130
|
+
const { ledger, queue: draftSyncQueue } = owner.current;
|
|
139
131
|
const draftSyncGenerationRef = useRef(0);
|
|
140
132
|
const activeIdentityRef = useRef(sessionIdentity);
|
|
141
133
|
activeIdentityRef.current = sessionIdentity;
|
|
@@ -926,6 +918,7 @@ export function useComposer(params) {
|
|
|
926
918
|
}, [origin, sessionId, sessionReady, refs, onUnrecoverableSession]);
|
|
927
919
|
return {
|
|
928
920
|
input,
|
|
921
|
+
draftVersion: activeSnapshot.draftVersion,
|
|
929
922
|
setInput,
|
|
930
923
|
handleInputChange,
|
|
931
924
|
handleSelectionChange,
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { useCallback, useSyncExternalStore } from "react";
|
|
2
|
+
const changeEvent = "loop:controlled-handoff";
|
|
3
|
+
function subscribe(listener) {
|
|
4
|
+
window.addEventListener(changeEvent, listener);
|
|
5
|
+
window.addEventListener("storage", listener);
|
|
6
|
+
return () => {
|
|
7
|
+
window.removeEventListener(changeEvent, listener);
|
|
8
|
+
window.removeEventListener("storage", listener);
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
/** Human handoff belongs to the selected guest session, including its other open tabs. */
|
|
12
|
+
export function useControlledHandoff(workspaceId, sessionId) {
|
|
13
|
+
const key = "loop:controlled-owner:" + JSON.stringify([workspaceId, sessionId]);
|
|
14
|
+
const read = useCallback(() => {
|
|
15
|
+
try {
|
|
16
|
+
return window.localStorage.getItem(key) === "human";
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
}, [key]);
|
|
22
|
+
const human = useSyncExternalStore(subscribe, read, () => false);
|
|
23
|
+
function setHuman(value) {
|
|
24
|
+
if (!workspaceId || !sessionId)
|
|
25
|
+
return;
|
|
26
|
+
if (value)
|
|
27
|
+
window.localStorage.setItem(key, "human");
|
|
28
|
+
else
|
|
29
|
+
window.localStorage.removeItem(key);
|
|
30
|
+
window.dispatchEvent(new Event(changeEvent));
|
|
31
|
+
}
|
|
32
|
+
return { human, takeOver: () => setHuman(true), handBack: () => setHuman(false) };
|
|
33
|
+
}
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import { useEffect, useMemo, useSyncExternalStore } from "react";
|
|
2
|
+
import { confirmationToken } from "./format.js";
|
|
3
|
+
import { operatorChatStateUrl, operatorChatTurnsUrl } from "./turn-stream-controller.js";
|
|
4
|
+
function needsConfirmation(receipt) {
|
|
5
|
+
return receipt?.status === "unknown" || receipt?.status === "absent";
|
|
6
|
+
}
|
|
7
|
+
/** The server owns execution and request identity. This record freezes the exact
|
|
8
|
+
* text and request ID before dispatch, so a browser restart can query that ID. */
|
|
9
|
+
export class ControlledReceiptStore {
|
|
10
|
+
scope;
|
|
11
|
+
storage;
|
|
12
|
+
key;
|
|
13
|
+
snapshot = { receipt: null, busy: false };
|
|
14
|
+
listeners = new Set();
|
|
15
|
+
constructor(scope, storage) {
|
|
16
|
+
this.scope = scope;
|
|
17
|
+
this.storage = storage;
|
|
18
|
+
this.key = "loop-controlled-receipt:" + JSON.stringify([scope.origin, scope.workspaceId ?? "", scope.sessionId]);
|
|
19
|
+
this.reload();
|
|
20
|
+
}
|
|
21
|
+
subscribe = (listener) => {
|
|
22
|
+
this.listeners.add(listener);
|
|
23
|
+
return () => { this.listeners.delete(listener); };
|
|
24
|
+
};
|
|
25
|
+
getSnapshot = () => this.snapshot;
|
|
26
|
+
update(snapshot) {
|
|
27
|
+
this.snapshot = snapshot;
|
|
28
|
+
for (const listener of this.listeners)
|
|
29
|
+
listener();
|
|
30
|
+
}
|
|
31
|
+
reload = () => {
|
|
32
|
+
try {
|
|
33
|
+
const raw = (this.storage ?? window.localStorage).getItem(this.key);
|
|
34
|
+
const receipt = raw === null ? null : JSON.parse(raw);
|
|
35
|
+
if (raw !== null && (!receipt || typeof receipt.text !== "string" || typeof receipt.clientRequestId !== "string" ||
|
|
36
|
+
!receipt.clientRequestId.trim() || !["unknown", "absent", "queued", "accepted", "rejected"].includes(receipt.status))) {
|
|
37
|
+
throw new Error("invalid receipt");
|
|
38
|
+
}
|
|
39
|
+
this.update({ ...this.snapshot, receipt, storageError: undefined });
|
|
40
|
+
return true;
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
this.update({ ...this.snapshot, storageError: "本地回执无法读取。请恢复浏览器存储并在会话记录中核对上一条请求。" });
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
save(receipt) {
|
|
48
|
+
(this.storage ?? window.localStorage).setItem(this.key, JSON.stringify(receipt));
|
|
49
|
+
this.update({ ...this.snapshot, receipt });
|
|
50
|
+
}
|
|
51
|
+
withOwner(url) {
|
|
52
|
+
if (!this.scope.workspaceId)
|
|
53
|
+
return url;
|
|
54
|
+
const separator = url.includes("?") ? "&" : "?";
|
|
55
|
+
return url + separator + new URLSearchParams({ workspaceId: this.scope.workspaceId }).toString();
|
|
56
|
+
}
|
|
57
|
+
async exclusive(action) {
|
|
58
|
+
// Synchronous per-view guard also handles same-frame double clicks.
|
|
59
|
+
if (this.snapshot.busy)
|
|
60
|
+
return;
|
|
61
|
+
this.update({ ...this.snapshot, busy: true });
|
|
62
|
+
const run = async () => {
|
|
63
|
+
if (this.reload())
|
|
64
|
+
await action();
|
|
65
|
+
};
|
|
66
|
+
try {
|
|
67
|
+
// Coordinate the single outstanding receipt across Console tabs.
|
|
68
|
+
if (globalThis.navigator?.locks) {
|
|
69
|
+
await navigator.locks.request(this.key, { ifAvailable: true }, async (lock) => {
|
|
70
|
+
if (lock)
|
|
71
|
+
await run();
|
|
72
|
+
else
|
|
73
|
+
this.reload();
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
await run();
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
catch {
|
|
81
|
+
this.update({ ...this.snapshot, storageError: "本地回执暂不可用,请检查浏览器存储后重新查询。" });
|
|
82
|
+
}
|
|
83
|
+
finally {
|
|
84
|
+
this.update({ ...this.snapshot, busy: false });
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
async inspect(receipt) {
|
|
88
|
+
const url = operatorChatStateUrl(this.scope.origin, this.scope.sessionId, undefined, receipt.clientRequestId);
|
|
89
|
+
const response = await fetch(this.withOwner(url), { credentials: "include", cache: "no-store", signal: AbortSignal.timeout(8000) });
|
|
90
|
+
if (!response.ok)
|
|
91
|
+
throw new Error("服务端状态查询失败");
|
|
92
|
+
const { ok, state } = await response.json();
|
|
93
|
+
if (!ok || !state || !Object.hasOwn(state, "matchedTurn") || !Array.isArray(state.deferredTurns)) {
|
|
94
|
+
throw new Error("服务端未返回请求查询结果");
|
|
95
|
+
}
|
|
96
|
+
if (state.matchedTurn?.clientRequestId === receipt.clientRequestId) {
|
|
97
|
+
return { ...receipt, status: "accepted", turnId: state.matchedTurn.turnId, detail: undefined };
|
|
98
|
+
}
|
|
99
|
+
const queued = state.deferredTurns.find(item => item.clientRequestId === receipt.clientRequestId);
|
|
100
|
+
if (queued) {
|
|
101
|
+
if (queued.state === "failed")
|
|
102
|
+
return { ...receipt, status: "rejected", detail: queued.lastError?.message ?? "排队指令执行失败" };
|
|
103
|
+
return { ...receipt, status: "queued", detail: undefined };
|
|
104
|
+
}
|
|
105
|
+
// The original blocker may have finished while the view was offline.
|
|
106
|
+
// A confirmed miss can be retried behind the current turn, or immediately
|
|
107
|
+
// if idle. The frozen request ID and text remain identical.
|
|
108
|
+
return { ...receipt, status: "absent", blockedByTurnId: state.activeTurn?.turnId, detail: "服务端尚未找到此请求,可按原请求号重试" };
|
|
109
|
+
}
|
|
110
|
+
async write(receipt) {
|
|
111
|
+
const { origin, sessionId } = this.scope;
|
|
112
|
+
const queued = Boolean(receipt.blockedByTurnId);
|
|
113
|
+
const url = queued ? origin + "/api/operator/v1/chat/sessions/" + encodeURIComponent(sessionId) + "/deferred-turn" : operatorChatTurnsUrl(origin, sessionId);
|
|
114
|
+
this.save({ ...receipt, status: "unknown", detail: undefined });
|
|
115
|
+
try {
|
|
116
|
+
const response = await fetch(this.withOwner(url), {
|
|
117
|
+
method: queued ? "PUT" : "POST", credentials: "include",
|
|
118
|
+
headers: { "Content-Type": "application/json", "x-loop-console-confirmation": confirmationToken() },
|
|
119
|
+
body: JSON.stringify({ text: receipt.text, clientRequestId: receipt.clientRequestId, blockedByTurnId: receipt.blockedByTurnId, draftVersion: receipt.draftVersion }),
|
|
120
|
+
signal: AbortSignal.timeout(15000),
|
|
121
|
+
});
|
|
122
|
+
const result = await response.json();
|
|
123
|
+
if (response.ok && result.accepted && result.turn?.clientRequestId === receipt.clientRequestId) {
|
|
124
|
+
this.save({ ...receipt, status: "accepted", turnId: result.turn.turnId, detail: undefined });
|
|
125
|
+
}
|
|
126
|
+
else if (response.ok && result.accepted && result.deferredTurn?.clientRequestId === receipt.clientRequestId) {
|
|
127
|
+
this.save({ ...receipt, status: "queued", detail: undefined });
|
|
128
|
+
}
|
|
129
|
+
else if (result.error?.code === "TURN_NOT_ACTIVE" || result.error?.code === "TURN_ACTIVE") {
|
|
130
|
+
this.save(await this.inspect(receipt));
|
|
131
|
+
}
|
|
132
|
+
else if (response.status >= 400 && response.status < 500 && result.accepted === false && result.error?.code) {
|
|
133
|
+
this.save({ ...receipt, status: "rejected", detail: result.error.message });
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
this.save(await this.inspect(receipt));
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
catch {
|
|
140
|
+
this.save({ ...receipt, status: "unknown", detail: "尚未取得服务端回执,请查询原请求" });
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
submit = (text, blockedByTurnId, draftVersion) => this.exclusive(async () => {
|
|
144
|
+
const previous = this.snapshot.receipt;
|
|
145
|
+
if (!text.trim() || needsConfirmation(previous))
|
|
146
|
+
return;
|
|
147
|
+
if (draftVersion && previous?.draftVersion === draftVersion && previous.text === text &&
|
|
148
|
+
(previous.status === "accepted" || previous.status === "queued"))
|
|
149
|
+
return;
|
|
150
|
+
await this.write({ clientRequestId: crypto.randomUUID(), text, blockedByTurnId, draftVersion, status: "unknown" });
|
|
151
|
+
});
|
|
152
|
+
lookup = () => this.exclusive(async () => {
|
|
153
|
+
const receipt = this.snapshot.receipt;
|
|
154
|
+
if (!receipt || receipt.status === "accepted" || receipt.status === "rejected")
|
|
155
|
+
return;
|
|
156
|
+
try {
|
|
157
|
+
const checked = await this.inspect(receipt);
|
|
158
|
+
// A previously confirmed queue item may have been withdrawn from another
|
|
159
|
+
// view. Its disappearance cannot justify running the instruction again.
|
|
160
|
+
if (receipt.status === "queued" && checked.status === "absent") {
|
|
161
|
+
this.save({ ...receipt, status: "rejected", detail: "原排队项已移出队列,没有关联执行记录" });
|
|
162
|
+
}
|
|
163
|
+
else {
|
|
164
|
+
this.save(checked);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
catch {
|
|
168
|
+
this.save({ ...receipt, detail: "服务端状态暂不可读,请重新查询原请求" });
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
retry = () => this.exclusive(async () => {
|
|
172
|
+
const receipt = this.snapshot.receipt;
|
|
173
|
+
if (receipt?.status !== "absent")
|
|
174
|
+
return;
|
|
175
|
+
// Re-check at the moment of the click, after any late acknowledgement.
|
|
176
|
+
try {
|
|
177
|
+
const checked = await this.inspect(receipt);
|
|
178
|
+
if (checked.status === "absent")
|
|
179
|
+
await this.write(checked);
|
|
180
|
+
else
|
|
181
|
+
this.save(checked);
|
|
182
|
+
}
|
|
183
|
+
catch {
|
|
184
|
+
this.save({ ...receipt, status: "unknown", detail: "重试前无法读取原请求,请重新查询" });
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
export function useControlledReceipt({ origin, workspaceId, sessionId }) {
|
|
189
|
+
const store = useMemo(() => new ControlledReceiptStore({ origin, workspaceId, sessionId }), [origin, workspaceId, sessionId]);
|
|
190
|
+
const snapshot = useSyncExternalStore(store.subscribe, store.getSnapshot, store.getSnapshot);
|
|
191
|
+
useEffect(() => {
|
|
192
|
+
const onStorage = (event) => {
|
|
193
|
+
if (event.key === store.key || event.key === null)
|
|
194
|
+
store.reload();
|
|
195
|
+
};
|
|
196
|
+
const onReconnect = () => { void store.lookup(); };
|
|
197
|
+
window.addEventListener("storage", onStorage);
|
|
198
|
+
window.addEventListener("online", onReconnect);
|
|
199
|
+
onReconnect();
|
|
200
|
+
return () => {
|
|
201
|
+
window.removeEventListener("storage", onStorage);
|
|
202
|
+
window.removeEventListener("online", onReconnect);
|
|
203
|
+
};
|
|
204
|
+
}, [store]);
|
|
205
|
+
return { ...snapshot, submit: store.submit, lookup: store.lookup, retry: store.retry };
|
|
206
|
+
}
|
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Console 单壳 canonical hash 路由。
|
|
3
|
+
*
|
|
4
|
+
* 产品路径只使用 `/#/chat`、`/#/operate/*`、`/#/inspect/*`。
|
|
5
|
+
* 旧 Console hash(`/#/tasks` 等)、历史 `/#/dag/<id>`、以及独立
|
|
6
|
+
* `/inspect/#/...` 仅作为兼容输入,规范化后不得再作为壳内点击目标。
|
|
7
|
+
*/
|
|
8
|
+
import { buildControlledChatHref } from "../../chat/workspace-landing.js";
|
|
1
9
|
export function resolveRouteWorkspaceSelection(workspaceId, knownWorkspaceIds) {
|
|
2
10
|
const id = workspaceId?.trim();
|
|
3
11
|
if (!id)
|
|
@@ -163,6 +171,8 @@ export function buildInspectHref(inspectPath = "/", query) {
|
|
|
163
171
|
* explicit deep-link exception: preserve its parent/session identity so a
|
|
164
172
|
* refresh can reopen the same parent-scoped child panel. */
|
|
165
173
|
export function buildChatHref(params = {}) {
|
|
174
|
+
if (params.controlled)
|
|
175
|
+
return buildControlledChatHref(params.workspaceId, params.sessionId);
|
|
166
176
|
const query = new URLSearchParams();
|
|
167
177
|
// Ordinary Chat navigation remains a stable bare route. Child resources
|
|
168
178
|
// are the explicit deep-link exception and therefore carry their parent
|
|
@@ -273,7 +283,7 @@ function finishChat(replace, params) {
|
|
|
273
283
|
canonicalHref,
|
|
274
284
|
// Legacy session/workspace query params are consumed into client state;
|
|
275
285
|
// a child deep link is already canonical and must survive refresh intact.
|
|
276
|
-
replace: replace || (!effective.childSessionId && !effective.subagentToolCallId && paramsQuery(effective).length > 0),
|
|
286
|
+
replace: replace || (!effective.controlled && !effective.childSessionId && !effective.subagentToolCallId && paramsQuery(effective).length > 0),
|
|
277
287
|
...effective,
|
|
278
288
|
};
|
|
279
289
|
}
|
|
@@ -292,6 +302,12 @@ export function parseWorkspaceRoute(location, options = {}) {
|
|
|
292
302
|
}
|
|
293
303
|
if (path === "/chat")
|
|
294
304
|
return finishChat(false, readWorkspaceParams(query));
|
|
305
|
+
if (path === "/chat/controlled")
|
|
306
|
+
return finishChat(false, {
|
|
307
|
+
controlled: true,
|
|
308
|
+
workspaceId: readParam(query, "workspaceId"),
|
|
309
|
+
sessionId: readParam(query, "sessionId"),
|
|
310
|
+
});
|
|
295
311
|
if (path === "/operate") {
|
|
296
312
|
return finishOperate(lastTab, query, true);
|
|
297
313
|
}
|
|
@@ -482,6 +482,46 @@
|
|
|
482
482
|
flex: 1 1 auto;
|
|
483
483
|
}
|
|
484
484
|
|
|
485
|
+
/* 对话顶栏右端的会话动作。线框胶囊,和居中的产品模式分段控件分开。 */
|
|
486
|
+
.och-controlled-entry {
|
|
487
|
+
appearance: none;
|
|
488
|
+
display: inline-flex;
|
|
489
|
+
align-items: center;
|
|
490
|
+
justify-content: center;
|
|
491
|
+
flex-shrink: 0;
|
|
492
|
+
height: 30px;
|
|
493
|
+
margin-left: auto;
|
|
494
|
+
padding: 0 12px;
|
|
495
|
+
border: 1px solid var(--och-hairline);
|
|
496
|
+
border-radius: 999px;
|
|
497
|
+
background: var(--och-surface);
|
|
498
|
+
color: var(--och-body);
|
|
499
|
+
font: inherit;
|
|
500
|
+
font-size: 13px;
|
|
501
|
+
font-weight: 600;
|
|
502
|
+
white-space: nowrap;
|
|
503
|
+
cursor: pointer;
|
|
504
|
+
}
|
|
505
|
+
.och-controlled-entry:hover {
|
|
506
|
+
color: var(--och-ink);
|
|
507
|
+
border-color: var(--och-hairline-strong);
|
|
508
|
+
}
|
|
509
|
+
.och-controlled-entry.is-human {
|
|
510
|
+
color: var(--och-orange-active);
|
|
511
|
+
border-color: color-mix(in srgb, var(--och-orange) 55%, var(--och-hairline));
|
|
512
|
+
background: color-mix(in srgb, var(--och-orange) 14%, var(--och-surface));
|
|
513
|
+
}
|
|
514
|
+
.och-controlled-entry.is-human:hover {
|
|
515
|
+
color: var(--och-orange-active);
|
|
516
|
+
}
|
|
517
|
+
.och-controlled-entry:focus-visible {
|
|
518
|
+
outline: 2px solid var(--och-orange);
|
|
519
|
+
outline-offset: 2px;
|
|
520
|
+
}
|
|
521
|
+
.och-controlled-entry-short {
|
|
522
|
+
display: none;
|
|
523
|
+
}
|
|
524
|
+
|
|
485
525
|
/* 新鲜度格(Inspect 模式渲染;元素 id 保持 header-refresh 供轮询回写) */
|
|
486
526
|
.och-fresh {
|
|
487
527
|
display: inline-flex;
|
|
@@ -697,6 +737,15 @@
|
|
|
697
737
|
}
|
|
698
738
|
|
|
699
739
|
@media (max-width: 760px) {
|
|
740
|
+
.och-controlled-entry {
|
|
741
|
+
padding-inline: 10px;
|
|
742
|
+
}
|
|
743
|
+
.och-controlled-entry-full {
|
|
744
|
+
display: none;
|
|
745
|
+
}
|
|
746
|
+
.och-controlled-entry-short {
|
|
747
|
+
display: inline;
|
|
748
|
+
}
|
|
700
749
|
.och-inner {
|
|
701
750
|
padding-inline: 12px;
|
|
702
751
|
}
|
|
@@ -54,6 +54,12 @@ export type ChromeModel = {
|
|
|
54
54
|
workspaceTabsVisible: boolean;
|
|
55
55
|
tabs: Array<OperatorChromeTab & { active: boolean }>;
|
|
56
56
|
tabsAriaLabel: string;
|
|
57
|
+
controlledEntry: {
|
|
58
|
+
human: boolean;
|
|
59
|
+
label: string;
|
|
60
|
+
shortLabel: string;
|
|
61
|
+
ariaLabel: string;
|
|
62
|
+
} | null;
|
|
57
63
|
};
|
|
58
64
|
|
|
59
65
|
export function parseInspectObjectView(
|
|
@@ -98,6 +104,7 @@ export function buildOperatorChromeModel(config: {
|
|
|
98
104
|
freshness?: boolean;
|
|
99
105
|
context?: InspectContext | null;
|
|
100
106
|
onSelectWorkspace?: (workspaceId: string) => void;
|
|
107
|
+
controlledEntry?: { human?: boolean } | null;
|
|
101
108
|
}): ChromeModel;
|
|
102
109
|
export function mountOperatorChrome(
|
|
103
110
|
root: HTMLElement,
|
|
@@ -290,6 +290,19 @@ export function buildOperatorChromeModel(config) {
|
|
|
290
290
|
: mode === "operate"
|
|
291
291
|
? "操作工作区"
|
|
292
292
|
: "对话工作区",
|
|
293
|
+
/* 会话级动作,不是第四个产品模式。只在对话里出现,避免塞进居中的分段控件。 */
|
|
294
|
+
controlledEntry: controlledEntryForMode(mode, config.controlledEntry),
|
|
295
|
+
};
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
function controlledEntryForMode(mode, requested) {
|
|
299
|
+
if (mode !== "chat" || !requested || typeof requested !== "object") return null;
|
|
300
|
+
const human = requested.human === true;
|
|
301
|
+
return {
|
|
302
|
+
human,
|
|
303
|
+
label: human ? "交回 AI" : "AI 被控视图",
|
|
304
|
+
shortLabel: human ? "交回" : "被控",
|
|
305
|
+
ariaLabel: human ? "交回 AI" : "打开 AI 被控视图",
|
|
293
306
|
};
|
|
294
307
|
}
|
|
295
308
|
|
|
@@ -710,6 +723,24 @@ export function mountOperatorChrome(root, config = {}) {
|
|
|
710
723
|
|
|
711
724
|
global.appendChild(el("span", "och-spacer"));
|
|
712
725
|
|
|
726
|
+
/* 顶栏右端:当前 Pi 会话的被控入口。分段控件仍只有对话 / 操作 / 观测。 */
|
|
727
|
+
if (model.controlledEntry) {
|
|
728
|
+
const entry = el("button", "och-controlled-entry");
|
|
729
|
+
entry.type = "button";
|
|
730
|
+
if (model.controlledEntry.human) entry.classList.add("is-human");
|
|
731
|
+
entry.setAttribute("aria-label", model.controlledEntry.ariaLabel);
|
|
732
|
+
entry.title = model.controlledEntry.label;
|
|
733
|
+
entry.append(
|
|
734
|
+
el("span", "och-controlled-entry-full", model.controlledEntry.label),
|
|
735
|
+
el("span", "och-controlled-entry-short", model.controlledEntry.shortLabel),
|
|
736
|
+
);
|
|
737
|
+
entry.addEventListener("click", () => {
|
|
738
|
+
if (typeof currentConfig.onControlledEntry === "function") {
|
|
739
|
+
currentConfig.onControlledEntry();
|
|
740
|
+
}
|
|
741
|
+
});
|
|
742
|
+
global.appendChild(entry);
|
|
743
|
+
}
|
|
713
744
|
|
|
714
745
|
if (model.statusVisible && model.freshness) {
|
|
715
746
|
const fresh = el("span", "och-fresh");
|
|
@@ -152,6 +152,11 @@ Governance (scripts/check-*.sh, src/governance/)
|
|
|
152
152
|
- **DAG recovery mutation**:`dag reconcile-run` 是显式 operator 边界;默认仅检查,只有给出 action + reason 且 runner 已证明停止时才能保存原始快照、写 terminal reconciliation facts 并迁移 lifecycle。Observe、status 和 doctor 始终只读。Task Pool 侧的 abandon/Failed 投影由 `agent-worker task reconcile` 持有,不得让 DAG kernel 反向依赖 Worker。
|
|
153
153
|
- **禁止**:把 raw path mutation 扩散给 runner、loop action 或 command handler。
|
|
154
154
|
|
|
155
|
+
### Console browser tools
|
|
156
|
+
|
|
157
|
+
- 普通 Pi 和 Workflow 会话均注册浏览器自动化工具。旧环境变量 `CONSOLE_CHAT_BROWSER_AUTOMATION` 已移除;工作区升级并重启 Console 后,原先显式关闭的会话也能使用这些工具。`browserCapabilities` 列出当前会话已激活的浏览器工具,Pi 默认按需激活诊断组。多步、循环、分支和画布操作用 `browser_run`;单条调试命令用 `browser_cdp`。Console 发布本机回环上的临时调试端口,不附着外部 `:9222`。
|
|
158
|
+
- `browser_run` 在 Console 进程里执行,没有额外沙箱。超时或取消不能打断已经发出的调用,并会把效果标成不确定。过大的返回内容存成文件。
|
|
159
|
+
|
|
155
160
|
### Console automation persistence and clock
|
|
156
161
|
|
|
157
162
|
- 纯时间、schema 与目录 DTO 位于 `src/shared/automation/`,不依赖 Console 或 CLI;Worker 的 `AutomationStore` / `ScheduledGoalStore` 使用同一 v2 `.harness/scheduled-goals/state.json`,不复制 Workflow 授权/运行状态。
|