@tomflow/chatloop-tools 0.9.62 → 0.9.64
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/README.md +13 -1
- package/index.mjs +7 -7
- package/lib/context-control-run.mjs +23 -5
- package/lib/extension-proxy.mjs +29 -10
- package/lib/native-owner-v2.mjs +128 -0
- package/lib/release-health-checks.mjs +29 -5
- package/lib/trace-gateway.mjs +3 -1
- package/package.json +3 -13
- package/providers/extension.mjs +59 -16
- package/node_modules/@tomflow/chatloop-context/README.md +0 -240
- package/node_modules/@tomflow/chatloop-context/bin/cli.mjs +0 -48
- package/node_modules/@tomflow/chatloop-context/capabilities/approval.mjs +0 -151
- package/node_modules/@tomflow/chatloop-context/capabilities/context.mjs +0 -376
- package/node_modules/@tomflow/chatloop-context/capabilities/document.mjs +0 -266
- package/node_modules/@tomflow/chatloop-context/capabilities/evidence.mjs +0 -134
- package/node_modules/@tomflow/chatloop-context/capabilities/presentation.mjs +0 -82
- package/node_modules/@tomflow/chatloop-context/capabilities/project.mjs +0 -349
- package/node_modules/@tomflow/chatloop-context/capabilities/sdk.mjs +0 -72
- package/node_modules/@tomflow/chatloop-context/capabilities/start.mjs +0 -73
- package/node_modules/@tomflow/chatloop-context/capabilities/task.mjs +0 -507
- package/node_modules/@tomflow/chatloop-context/capabilities.generated.mjs +0 -11
- package/node_modules/@tomflow/chatloop-context/docs/interfaces.md +0 -192
- package/node_modules/@tomflow/chatloop-context/docs/operator-and-migration.md +0 -277
- package/node_modules/@tomflow/chatloop-context/index.mjs +0 -236
- package/node_modules/@tomflow/chatloop-context/lib/api-log.mjs +0 -86
- package/node_modules/@tomflow/chatloop-context/lib/approval-policy.mjs +0 -77
- package/node_modules/@tomflow/chatloop-context/lib/capability-catalog.generated.json +0 -1989
- package/node_modules/@tomflow/chatloop-context/lib/capability-router.mjs +0 -69
- package/node_modules/@tomflow/chatloop-context/lib/cli-commands.mjs +0 -285
- package/node_modules/@tomflow/chatloop-context/lib/context-cli.mjs +0 -298
- package/node_modules/@tomflow/chatloop-context/lib/context-migration.mjs +0 -286
- package/node_modules/@tomflow/chatloop-context/lib/core/context.mjs +0 -115
- package/node_modules/@tomflow/chatloop-context/lib/core/evidence.mjs +0 -51
- package/node_modules/@tomflow/chatloop-context/lib/core/health.mjs +0 -75
- package/node_modules/@tomflow/chatloop-context/lib/core/migration.mjs +0 -262
- package/node_modules/@tomflow/chatloop-context/lib/core/project.mjs +0 -246
- package/node_modules/@tomflow/chatloop-context/lib/core/review.mjs +0 -147
- package/node_modules/@tomflow/chatloop-context/lib/core/run-cancel.mjs +0 -54
- package/node_modules/@tomflow/chatloop-context/lib/core/run.mjs +0 -375
- package/node_modules/@tomflow/chatloop-context/lib/core/store.mjs +0 -397
- package/node_modules/@tomflow/chatloop-context/lib/core/task.mjs +0 -183
- package/node_modules/@tomflow/chatloop-context/lib/line-review.mjs +0 -13
- package/node_modules/@tomflow/chatloop-context/lib/methods.mjs +0 -111
- package/node_modules/@tomflow/chatloop-context/lib/operations.mjs +0 -107
- package/node_modules/@tomflow/chatloop-context/lib/orphan-operator.mjs +0 -118
- package/node_modules/@tomflow/chatloop-context/lib/process-inventory.mjs +0 -20
- package/node_modules/@tomflow/chatloop-context/lib/project-branch.mjs +0 -316
- package/node_modules/@tomflow/chatloop-context/lib/project-diagnostic.mjs +0 -153
- package/node_modules/@tomflow/chatloop-context/lib/project-guards.mjs +0 -19
- package/node_modules/@tomflow/chatloop-context/lib/project-store.mjs +0 -117
- package/node_modules/@tomflow/chatloop-context/lib/trusted-run.mjs +0 -97
- package/node_modules/@tomflow/chatloop-context/lib/workspace-operator.mjs +0 -169
- package/node_modules/@tomflow/chatloop-context/package.json +0 -40
- package/node_modules/@tomflow/chatloop-context/scripts/build-capabilities.mjs +0 -114
- package/node_modules/@tomflow/chatloop-extension/README.md +0 -124
- package/node_modules/@tomflow/chatloop-extension/actions.generated.mjs +0 -13
- package/node_modules/@tomflow/chatloop-extension/bin/cli.mjs +0 -153
- package/node_modules/@tomflow/chatloop-extension/bin/native-host.mjs +0 -207
- package/node_modules/@tomflow/chatloop-extension/capabilities/chat_dom.mjs +0 -1
- package/node_modules/@tomflow/chatloop-extension/capabilities/chat_screenshot.mjs +0 -1
- package/node_modules/@tomflow/chatloop-extension/capabilities/chat_text.mjs +0 -1
- package/node_modules/@tomflow/chatloop-extension/capabilities/clean.mjs +0 -1
- package/node_modules/@tomflow/chatloop-extension/capabilities/continue.mjs +0 -1
- package/node_modules/@tomflow/chatloop-extension/capabilities/entry_test.mjs +0 -1
- package/node_modules/@tomflow/chatloop-extension/capabilities/handoff.mjs +0 -1
- package/node_modules/@tomflow/chatloop-extension/capabilities/reload.mjs +0 -1
- package/node_modules/@tomflow/chatloop-extension/capabilities/session.mjs +0 -1
- package/node_modules/@tomflow/chatloop-extension/capabilities/start.mjs +0 -1
- package/node_modules/@tomflow/chatloop-extension/capabilities/status.mjs +0 -1
- package/node_modules/@tomflow/chatloop-extension/extension/actions/clean.js +0 -123
- package/node_modules/@tomflow/chatloop-extension/extension/actions/common.js +0 -183
- package/node_modules/@tomflow/chatloop-extension/extension/actions/continue.js +0 -340
- package/node_modules/@tomflow/chatloop-extension/extension/actions/dom.js +0 -2
- package/node_modules/@tomflow/chatloop-extension/extension/actions/entry_test.js +0 -241
- package/node_modules/@tomflow/chatloop-extension/extension/actions/handoff.js +0 -393
- package/node_modules/@tomflow/chatloop-extension/extension/actions/index.js +0 -2
- package/node_modules/@tomflow/chatloop-extension/extension/actions/model-intent.js +0 -56
- package/node_modules/@tomflow/chatloop-extension/extension/actions/read-mode.js +0 -9
- package/node_modules/@tomflow/chatloop-extension/extension/actions/reload.js +0 -20
- package/node_modules/@tomflow/chatloop-extension/extension/actions/screenshot.js +0 -77
- package/node_modules/@tomflow/chatloop-extension/extension/actions/session.js +0 -52
- package/node_modules/@tomflow/chatloop-extension/extension/actions/start.js +0 -295
- package/node_modules/@tomflow/chatloop-extension/extension/actions/status.js +0 -24
- package/node_modules/@tomflow/chatloop-extension/extension/actions/text.js +0 -2
- package/node_modules/@tomflow/chatloop-extension/extension/background.js +0 -17
- package/node_modules/@tomflow/chatloop-extension/extension/clean.html +0 -5
- package/node_modules/@tomflow/chatloop-extension/extension/content.js +0 -40
- package/node_modules/@tomflow/chatloop-extension/extension/continue.html +0 -9
- package/node_modules/@tomflow/chatloop-extension/extension/dom.html +0 -17
- package/node_modules/@tomflow/chatloop-extension/extension/entry_test.html +0 -6
- package/node_modules/@tomflow/chatloop-extension/extension/handoff.html +0 -9
- package/node_modules/@tomflow/chatloop-extension/extension/loop/action-catalog.generated.js +0 -2
- package/node_modules/@tomflow/chatloop-extension/extension/loop/api-aspect.generated.js +0 -275
- package/node_modules/@tomflow/chatloop-extension/extension/loop/api-observation-queue.generated.js +0 -84
- package/node_modules/@tomflow/chatloop-extension/extension/loop/core.js +0 -107
- package/node_modules/@tomflow/chatloop-extension/extension/loop/index.js +0 -36
- package/node_modules/@tomflow/chatloop-extension/extension/loop/observer-approval.js +0 -299
- package/node_modules/@tomflow/chatloop-extension/extension/loop/observer-inspect.js +0 -144
- package/node_modules/@tomflow/chatloop-extension/extension/loop/observer-poll.js +0 -171
- package/node_modules/@tomflow/chatloop-extension/extension/loop/observer-recovery.js +0 -109
- package/node_modules/@tomflow/chatloop-extension/extension/loop/observer.js +0 -154
- package/node_modules/@tomflow/chatloop-extension/extension/loop/resources.js +0 -259
- package/node_modules/@tomflow/chatloop-extension/extension/manifest.json +0 -42
- package/node_modules/@tomflow/chatloop-extension/extension/popup.html +0 -25
- package/node_modules/@tomflow/chatloop-extension/extension/popup.js +0 -99
- package/node_modules/@tomflow/chatloop-extension/extension/reload.html +0 -17
- package/node_modules/@tomflow/chatloop-extension/extension/screenshot.html +0 -17
- package/node_modules/@tomflow/chatloop-extension/extension/session.html +0 -6
- package/node_modules/@tomflow/chatloop-extension/extension/start.html +0 -6
- package/node_modules/@tomflow/chatloop-extension/extension/status.html +0 -6
- package/node_modules/@tomflow/chatloop-extension/extension/text.html +0 -17
- package/node_modules/@tomflow/chatloop-extension/extension/worker/action-result.js +0 -136
- package/node_modules/@tomflow/chatloop-extension/extension/worker/action-take.js +0 -218
- package/node_modules/@tomflow/chatloop-extension/extension/worker/admission.js +0 -124
- package/node_modules/@tomflow/chatloop-extension/extension/worker/adopt-prepare.js +0 -296
- package/node_modules/@tomflow/chatloop-extension/extension/worker/adopt-recovery.js +0 -186
- package/node_modules/@tomflow/chatloop-extension/extension/worker/adopt-result.js +0 -126
- package/node_modules/@tomflow/chatloop-extension/extension/worker/bootstrap.js +0 -230
- package/node_modules/@tomflow/chatloop-extension/extension/worker/manual.js +0 -163
- package/node_modules/@tomflow/chatloop-extension/extension/worker/readiness.js +0 -345
- package/node_modules/@tomflow/chatloop-extension/extension/worker/router.js +0 -192
- package/node_modules/@tomflow/chatloop-extension/extension/worker/scheduler.js +0 -161
- package/node_modules/@tomflow/chatloop-extension/extension/worker/session-control.js +0 -75
- package/node_modules/@tomflow/chatloop-extension/extension/worker/turn-failure.js +0 -197
- package/node_modules/@tomflow/chatloop-extension/extension/worker/turn-finished.js +0 -205
- package/node_modules/@tomflow/chatloop-extension/index.mjs +0 -71
- package/node_modules/@tomflow/chatloop-extension/lib/action-routing.mjs +0 -19
- package/node_modules/@tomflow/chatloop-extension/lib/api-observation-queue.mjs +0 -82
- package/node_modules/@tomflow/chatloop-extension/lib/bridge.mjs +0 -303
- package/node_modules/@tomflow/chatloop-extension/lib/browser-launch.mjs +0 -83
- package/node_modules/@tomflow/chatloop-extension/lib/context-binding.mjs +0 -45
- package/node_modules/@tomflow/chatloop-extension/lib/context-ipc.mjs +0 -115
- package/node_modules/@tomflow/chatloop-extension/lib/owner-evidence.mjs +0 -75
- package/node_modules/@tomflow/chatloop-extension/lib/session-file.mjs +0 -185
- package/node_modules/@tomflow/chatloop-extension/package.json +0 -38
- package/node_modules/@tomflow/chatloop-extension/scripts/build-actions.mjs +0 -138
- package/node_modules/@tomflow/chatloop-trace/README.md +0 -118
- package/node_modules/@tomflow/chatloop-trace/events/context.api.mjs +0 -23
- package/node_modules/@tomflow/chatloop-trace/events/typed.api.call.mjs +0 -22
- package/node_modules/@tomflow/chatloop-trace/events.generated.mjs +0 -4
- package/node_modules/@tomflow/chatloop-trace/index.mjs +0 -59
- package/node_modules/@tomflow/chatloop-trace/lib/api-aspect.mjs +0 -273
- package/node_modules/@tomflow/chatloop-trace/lib/trace-reader.mjs +0 -308
- package/node_modules/@tomflow/chatloop-trace/lib/trace-retention.mjs +0 -140
- package/node_modules/@tomflow/chatloop-trace/lib/trace.mjs +0 -236
- package/node_modules/@tomflow/chatloop-trace/package.json +0 -30
- package/node_modules/@tomflow/chatloop-trace/scripts/build-events.mjs +0 -68
- package/node_modules/ps-list/index.d.ts +0 -76
- package/node_modules/ps-list/index.js +0 -366
- package/node_modules/ps-list/license +0 -9
- package/node_modules/ps-list/package.json +0 -44
- package/node_modules/ps-list/readme.md +0 -56
- package/node_modules/ps-list/vendor/fastlist-0.3.0-x64.exe +0 -0
- package/node_modules/ps-list/vendor/fastlist-0.3.0-x86.exe +0 -0
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
// The only model-driven entrance reuses the two existing formal Action pages.
|
|
2
|
-
// It registers a decision; it never edits ChatGPT, creates a new Chat, or sends.
|
|
3
|
-
export async function queueModelIntent(action) {
|
|
4
|
-
const params = new URLSearchParams(location.search);
|
|
5
|
-
const id = params.get('requestId');
|
|
6
|
-
if([...params.keys()].length !== 1 || !/^[a-f0-9]{32}$/.test(id||''))
|
|
7
|
-
throw Error('INVALID_MODEL_REQUEST');
|
|
8
|
-
const own = await chrome.tabs.getCurrent();
|
|
9
|
-
if(!own?.id || own.url !== location.href)
|
|
10
|
-
throw Error('MODEL_ACTION_TAB_UNVERIFIED');
|
|
11
|
-
const host='com.tomflow.chatloop.extension';
|
|
12
|
-
const auth = await chrome.runtime.sendNativeMessage(host,{op:'acquire',id,action});
|
|
13
|
-
if(auth?.status!=='OK'||auth.id!==id||auth.action!==action
|
|
14
|
-
||typeof auth.nonce!=='string'||!auth.intent)
|
|
15
|
-
throw Error(auth?.code||'MODEL_REQUEST_UNVERIFIED');
|
|
16
|
-
let outcome;
|
|
17
|
-
try {
|
|
18
|
-
const query=typeof auth.intent.intentId==='string'||auth.intent.lookup===true;
|
|
19
|
-
outcome = await chrome.runtime.sendMessage({
|
|
20
|
-
type:query?'CHAT_LOOP_MODEL_INTENT_STATUS_V1':'CHAT_LOOP_MODEL_INTENT_V1',
|
|
21
|
-
id, action:action.toUpperCase(),intent:auth.intent,
|
|
22
|
-
...(auth.traceParent?{traceParent:auth.traceParent}:{})
|
|
23
|
-
});
|
|
24
|
-
if(outcome?.status!==(query?'STATUS':'QUEUED')
|
|
25
|
-
|| !/^[a-f0-9]{32}$/.test(outcome.intentId||'')
|
|
26
|
-
|| (query&&auth.intent.intentId&&outcome.intentId!==auth.intent.intentId)
|
|
27
|
-
|| (!query&&outcome.intentId!==id)
|
|
28
|
-
||outcome.action!==action.toUpperCase())
|
|
29
|
-
throw Error(outcome?.code||'MODEL_INTENT_DENIED');
|
|
30
|
-
const saved = await chrome.runtime.sendNativeMessage(host,{
|
|
31
|
-
op:'complete',id,nonce:auth.nonce,action,status:'OK',
|
|
32
|
-
payload:JSON.stringify(outcome)
|
|
33
|
-
});
|
|
34
|
-
if(saved?.status!=='SAVED'||saved.id!==id)
|
|
35
|
-
throw Error(saved?.code||'INTENT_RECEIPT_UNVERIFIED');
|
|
36
|
-
await chrome.tabs.remove(own.id);
|
|
37
|
-
} catch(e) {
|
|
38
|
-
// An already-queued intent is not retried. Native failure is diagnostic only.
|
|
39
|
-
try {
|
|
40
|
-
const rawCode=e?.code||e?.message;
|
|
41
|
-
const code=typeof rawCode==='string'&&/^[A-Z][A-Z0-9_]{1,95}$/.test(rawCode)
|
|
42
|
-
?rawCode:'INTENT_UNVERIFIED';
|
|
43
|
-
const saved=await chrome.runtime.sendNativeMessage(host,{
|
|
44
|
-
op:'complete',id,nonce:auth.nonce,action,status:'FAILED',code
|
|
45
|
-
});
|
|
46
|
-
// The CLI already has a durable failure receipt. Keep the page only
|
|
47
|
-
// when that receipt could not be verified; never resubmit the intent.
|
|
48
|
-
if(saved?.status==='SAVED'&&saved.id===id) {
|
|
49
|
-
const live=await chrome.tabs.getCurrent();
|
|
50
|
-
if(live?.id===own.id&&live.url===location.href)
|
|
51
|
-
await chrome.tabs.remove(own.id).catch(()=>{});
|
|
52
|
-
}
|
|
53
|
-
} catch {}
|
|
54
|
-
throw e;
|
|
55
|
-
}
|
|
56
|
-
};
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
// Stateless Eye executor: read only a declared text/DOM mode with the same
|
|
2
|
-
// trusted Owner/Native admission as the two original Eye pages.
|
|
3
|
-
const script=document.currentScript;
|
|
4
|
-
const action=script?.dataset?.action;
|
|
5
|
-
const mode=script?.dataset?.readMode;
|
|
6
|
-
if(!/^chat_[a-z0-9_]+$/.test(action||'')||!['text','dom'].includes(mode))
|
|
7
|
-
throw Error('EYE_CAPABILITY_INVALID');
|
|
8
|
-
void globalThis.ChatLoopActionCommonV1.runReadAction(
|
|
9
|
-
mode,mode==='text'?250:1000,action);
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
// Reload Action: request reloading this extension, not other tabs/extensions.
|
|
2
|
-
(() => {
|
|
3
|
-
const {show, fail, requireOwnTab, machineBinding, machineResult, machineFailure} = globalThis.ChatLoopActionCommonV1;
|
|
4
|
-
async function run() {
|
|
5
|
-
const machine = await machineBinding("reload");
|
|
6
|
-
const own = requireOwnTab(await chrome.tabs.getCurrent());
|
|
7
|
-
show("RELOADING", "正在刷新 Chat Loop 扩展...");
|
|
8
|
-
// Save an ACCEPTED-but-unverified receipt before reload destroys this page.
|
|
9
|
-
if(machine)await machineResult(machine,"ACCEPTED");
|
|
10
|
-
const response = await chrome.runtime.sendMessage({
|
|
11
|
-
type: "CHAT_LOOP_EYE_RELOAD_V1", tabId: own.id
|
|
12
|
-
});
|
|
13
|
-
if (response?.status !== "ACCEPTED") throw Error("RELOAD_UNVERIFIED");
|
|
14
|
-
}
|
|
15
|
-
run().catch(async error => {
|
|
16
|
-
await machineFailure("reload",error);
|
|
17
|
-
fail(error.message || "UNEXPECTED_ERROR",
|
|
18
|
-
"操作未完成;动作页已保留,未对其他 ChatGPT 标签页进行操作。");
|
|
19
|
-
});
|
|
20
|
-
})();
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
// Screenshot Action: capture only the selected ChatGPT tab; wait for download completion.
|
|
2
|
-
(() => {
|
|
3
|
-
const {show, fail, findTarget, done, requireOwnTab,
|
|
4
|
-
machineBinding, machineTarget, machineResult, machineFailure} = globalThis.ChatLoopActionCommonV1;
|
|
5
|
-
async function saveScreenshot(tab,machine) {
|
|
6
|
-
await chrome.windows.update(tab.windowId, {focused: true});
|
|
7
|
-
await chrome.tabs.update(tab.id, {active: true});
|
|
8
|
-
// captureVisibleTab may otherwise return a stale compositor frame from an
|
|
9
|
-
// unfocused window even when tabs.query already reports the requested tab.
|
|
10
|
-
const [paint] = await chrome.scripting.executeScript({target: {tabId: tab.id},
|
|
11
|
-
func: async () => {
|
|
12
|
-
await new Promise(resolve => requestAnimationFrame(() => requestAnimationFrame(resolve)));
|
|
13
|
-
return {visible: document.visibilityState === "visible", url: location.href};
|
|
14
|
-
}});
|
|
15
|
-
if (paint?.result?.visible !== true || paint.result.url !== tab.url)
|
|
16
|
-
throw Error("TARGET_PAINT_UNVERIFIED");
|
|
17
|
-
await new Promise(resolve => setTimeout(resolve, 600));
|
|
18
|
-
const [active] = await chrome.tabs.query({windowId: tab.windowId, active: true});
|
|
19
|
-
if (active?.id !== tab.id) throw Error("TARGET_NOT_VISIBLE");
|
|
20
|
-
const current = await chrome.tabs.get(tab.id);
|
|
21
|
-
if (current.url !== tab.url) throw Error("TARGET_CHANGED_BEFORE_CAPTURE");
|
|
22
|
-
let dataUrl;
|
|
23
|
-
try { dataUrl = await chrome.tabs.captureVisibleTab(tab.windowId, {format: "png"}); }
|
|
24
|
-
catch (error) {
|
|
25
|
-
const message = String(error?.message || '');
|
|
26
|
-
if (/activeTab|<all_urls>|permission|not allowed to capture/i.test(message))
|
|
27
|
-
throw Error('CAPTURE_PERMISSION_REQUIRED');
|
|
28
|
-
if (/^[A-Z][A-Z0-9_]{1,95}$/.test(message)) throw error;
|
|
29
|
-
throw Error('CAPTURE_API_FAILED');
|
|
30
|
-
}
|
|
31
|
-
if (!dataUrl?.startsWith("data:image/png;base64,")) throw Error("CAPTURE_FAILED");
|
|
32
|
-
if(machine) { await machineResult(machine,dataUrl.slice("data:image/png;base64,".length)); return; }
|
|
33
|
-
const stamp = new Date().toISOString().replace(/[:.]/g, "-");
|
|
34
|
-
const filename = "ChatLoop/eye/chat-" + tab.id + "-" + stamp + ".png";
|
|
35
|
-
const downloadId = await chrome.downloads.download({
|
|
36
|
-
url: dataUrl, filename, saveAs: false, conflictAction: "uniquify"
|
|
37
|
-
});
|
|
38
|
-
if (!Number.isInteger(downloadId)) throw Error("DOWNLOAD_NOT_STARTED");
|
|
39
|
-
await new Promise((resolve, reject) => {
|
|
40
|
-
let settled = false;
|
|
41
|
-
const timer = setTimeout(() => finish("DOWNLOAD_TIMEOUT"), 30000);
|
|
42
|
-
function finish(error) {
|
|
43
|
-
if (settled) return;
|
|
44
|
-
settled = true;
|
|
45
|
-
clearTimeout(timer);
|
|
46
|
-
chrome.downloads.onChanged.removeListener(onChanged);
|
|
47
|
-
if (error) reject(Error(error));
|
|
48
|
-
else resolve();
|
|
49
|
-
}
|
|
50
|
-
function onChanged(delta) {
|
|
51
|
-
if (delta.id !== downloadId) return;
|
|
52
|
-
if (delta.error?.current) return finish("DOWNLOAD_FAILED: " + delta.error.current);
|
|
53
|
-
if (delta.state?.current === "complete") return finish();
|
|
54
|
-
if (delta.state?.current === "interrupted") return finish("DOWNLOAD_INTERRUPTED");
|
|
55
|
-
}
|
|
56
|
-
chrome.downloads.onChanged.addListener(onChanged);
|
|
57
|
-
void chrome.downloads.search({id: downloadId}).then(items => {
|
|
58
|
-
if (items[0]?.state === "complete") finish();
|
|
59
|
-
if (items[0]?.state === "interrupted") finish("DOWNLOAD_INTERRUPTED");
|
|
60
|
-
}).catch(() => finish("DOWNLOAD_STATUS_UNVERIFIED"));
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
let machine;
|
|
64
|
-
async function run() {
|
|
65
|
-
machine = await machineBinding("chat_screenshot");
|
|
66
|
-
const own = requireOwnTab(await chrome.tabs.getCurrent());
|
|
67
|
-
const target = machine ? await machineTarget(machine) : await findTarget(own);
|
|
68
|
-
show("RUNNING", "screenshot → ChatGPT tab " + target.id);
|
|
69
|
-
await saveScreenshot(target,machine);
|
|
70
|
-
await done(own, "screenshot", target);
|
|
71
|
-
}
|
|
72
|
-
run().catch(async error => {
|
|
73
|
-
await machineFailure("chat_screenshot",error);
|
|
74
|
-
fail(error.message || "UNEXPECTED_ERROR",
|
|
75
|
-
"操作未完成;动作页已保留,未对其他 ChatGPT 标签页进行操作。");
|
|
76
|
-
});
|
|
77
|
-
})();
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
// One built-in lifecycle Action page. Query string locates a private CLI
|
|
2
|
-
// request; its operation and authorization are read from Native acquire.
|
|
3
|
-
const host='com.tomflow.chatloop.extension';
|
|
4
|
-
const statusNode=document.getElementById('status');
|
|
5
|
-
const detailsNode=document.getElementById('details');
|
|
6
|
-
const show=(status,text)=>{statusNode.textContent=status;
|
|
7
|
-
detailsNode.textContent=text;document.body.dataset.result=status==='SUCCESS'?'success':'error'};
|
|
8
|
-
async function run(){
|
|
9
|
-
const own=await chrome.tabs.getCurrent(),params=new URLSearchParams(location.search);
|
|
10
|
-
const id=params.get('requestId');
|
|
11
|
-
if(!own?.id||own.url!==location.href||[...params.keys()].join(',')!=='requestId,operation'
|
|
12
|
-
||params.get('operation')!=='cancel'||!/^[a-f0-9]{32}$/.test(id||''))
|
|
13
|
-
throw Error('INVALID_SESSION_ACTION');
|
|
14
|
-
const acquired=await chrome.runtime.sendNativeMessage(host,{
|
|
15
|
-
op:'acquire',id,action:'session'
|
|
16
|
-
});
|
|
17
|
-
if(acquired?.status!=='OK'||acquired.id!==id
|
|
18
|
-
||acquired.action!=='session'||typeof acquired.nonce!=='string'
|
|
19
|
-
||acquired.intent?.operation!=='cancel')
|
|
20
|
-
throw Error(acquired?.code||'SESSION_INTENT_UNVERIFIED');
|
|
21
|
-
show('RUNNING','核验 Session、停止调度并撤销 Context 写权…');
|
|
22
|
-
let result;
|
|
23
|
-
try{
|
|
24
|
-
result=await chrome.runtime.sendMessage({
|
|
25
|
-
type:'CHAT_LOOP_SESSION_CONTROL_V1',requestId:id,operation:'cancel'
|
|
26
|
-
});
|
|
27
|
-
if(result?.status!=='OK'||result.state!=='CANCELLED_NOT_DELIVERED')
|
|
28
|
-
throw Error(result?.code||'SESSION_CANCEL_UNVERIFIED');
|
|
29
|
-
const receipt=await chrome.runtime.sendNativeMessage(host,{
|
|
30
|
-
op:'complete',id,nonce:acquired.nonce,action:'session',
|
|
31
|
-
status:'OK',payload:JSON.stringify(result)
|
|
32
|
-
});
|
|
33
|
-
if(receipt?.status!=='SAVED'||receipt.id!==id)
|
|
34
|
-
throw Error(receipt?.code||'SESSION_RESULT_UNVERIFIED');
|
|
35
|
-
show('SUCCESS','Session 已安全取消;业务任务未交付。');
|
|
36
|
-
await chrome.tabs.remove(own.id);
|
|
37
|
-
}catch(error){
|
|
38
|
-
// The Worker may have fenced Context before a transport failure. Never
|
|
39
|
-
// retry a mutation; the original request and persisted receipt are proof.
|
|
40
|
-
const raw=error?.message;
|
|
41
|
-
const code=/^[A-Z][A-Z0-9_]{1,95}$/.test(raw||'')?raw:'SESSION_CANCEL_UNVERIFIED';
|
|
42
|
-
const receipt=await chrome.runtime.sendNativeMessage(host,{
|
|
43
|
-
op:'complete',id,nonce:acquired.nonce,action:'session',
|
|
44
|
-
status:'FAILED',code
|
|
45
|
-
}).catch(()=>null);
|
|
46
|
-
show('BLOCKED',code);
|
|
47
|
-
if(receipt?.status==='SAVED'&&receipt.id===id)
|
|
48
|
-
await chrome.tabs.remove(own.id).catch(()=>{});
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
void run().catch(e=>show('UNVERIFIED',
|
|
52
|
-
/^[A-Z][A-Z0-9_]{1,95}$/.test(e?.message||'')?e.message:'SESSION_ACTION_UNVERIFIED'));
|
|
@@ -1,295 +0,0 @@
|
|
|
1
|
-
// Dedicated first-Turn Action. Only this page creates and sends the initial Web Chat.
|
|
2
|
-
// All subsequent turns are owned by the existing Observer / Continue / Handoff flow.
|
|
3
|
-
const info=document.getElementById('details'),label=document.getElementById('status');
|
|
4
|
-
const pause=ms=>new Promise(resolve=>setTimeout(resolve,ms));
|
|
5
|
-
// Timeout only read-only Chrome probes. Never race/retry a composer write or click.
|
|
6
|
-
const boundedRead=(call,ms)=>Promise.race([
|
|
7
|
-
Promise.resolve().then(call).catch(()=>null),
|
|
8
|
-
pause(Math.max(1,ms)).then(()=>null)
|
|
9
|
-
]);
|
|
10
|
-
const show=(s,d)=>{label.textContent=s;info.textContent=d;document.body.dataset.result=s==='SUCCESS'?'success':'error';};
|
|
11
|
-
const host='com.tomflow.chatloop.extension';
|
|
12
|
-
async function waitForHomeUrl(id){
|
|
13
|
-
const deadline=Date.now()+12_000;
|
|
14
|
-
for(let i=0;i<40 && Date.now()<deadline;i++){
|
|
15
|
-
const tab=await boundedRead(()=>chrome.tabs.get(id),
|
|
16
|
-
Math.min(1200,deadline-Date.now()));
|
|
17
|
-
if(tab?.url==='https://chatgpt.com/')return;
|
|
18
|
-
await pause(Math.min(250,Math.max(1,deadline-Date.now())));
|
|
19
|
-
}
|
|
20
|
-
throw Error('START_HOME_URL_UNVERIFIED');
|
|
21
|
-
}
|
|
22
|
-
async function newChatReady(id){
|
|
23
|
-
// Preserve 35s+ cold hydration but return well before the Worker watchdog.
|
|
24
|
-
// A never-settling Chrome read must not leave Start PENDING indefinitely.
|
|
25
|
-
const deadline=Date.now()+90_000;
|
|
26
|
-
for(let i=0;i<200 && Date.now()<deadline;i++){
|
|
27
|
-
const tab=await boundedRead(()=>chrome.tabs.get(id),
|
|
28
|
-
Math.min(1500,deadline-Date.now()));
|
|
29
|
-
if(tab?.url==='https://chatgpt.com/'){
|
|
30
|
-
const result=await boundedRead(()=>chrome.scripting.executeScript({target:{tabId:id},func:()=>{
|
|
31
|
-
const visible=e=>Boolean(e?.getClientRects?.().length);
|
|
32
|
-
const mains=[...document.querySelectorAll('main')].filter(visible);
|
|
33
|
-
const editor=document.querySelector('[contenteditable="true"][data-composer-markdown]')
|
|
34
|
-
||document.querySelector('#prompt-textarea[contenteditable="true"]');
|
|
35
|
-
if(location.origin!=='https://chatgpt.com'||location.pathname!=='/'
|
|
36
|
-
||mains.length!==1||!visible(editor)
|
|
37
|
-
||mains[0].querySelector('[data-chatgpt-search-message-ids],[data-message-author-role]'))
|
|
38
|
-
return false;
|
|
39
|
-
// A visible account-switch notice invalidates the first-send
|
|
40
|
-
// environment. Catch it before any editor mutation or send click.
|
|
41
|
-
const switched=/你的账户已切换[。.!!\s]*请重新发送消息|your account (?:has been |was )?switched[.!\s]*please (?:re-?send|send again) (?:your )?message/i;
|
|
42
|
-
if(switched.test(mains[0].innerText||mains[0].textContent||''))
|
|
43
|
-
return 'START_ACCOUNT_SWITCH_VISIBLE';
|
|
44
|
-
return (editor.innerText||editor.textContent||'').trim()
|
|
45
|
-
?'START_COMPOSER_NOT_EMPTY':true;
|
|
46
|
-
}}),Math.min(1500,deadline-Date.now()));
|
|
47
|
-
if(result?.[0]?.result==='START_COMPOSER_NOT_EMPTY')
|
|
48
|
-
throw Error('START_COMPOSER_NOT_EMPTY');
|
|
49
|
-
if(result?.[0]?.result==='START_ACCOUNT_SWITCH_VISIBLE')
|
|
50
|
-
throw Error('START_ACCOUNT_SWITCH_VISIBLE');
|
|
51
|
-
if(result?.[0]?.result===true)return;
|
|
52
|
-
}
|
|
53
|
-
await pause(Math.min(420,Math.max(1,deadline-Date.now())));
|
|
54
|
-
}
|
|
55
|
-
throw Error('NEW_CHAT_NOT_READY');
|
|
56
|
-
}
|
|
57
|
-
async function observerReady(id){
|
|
58
|
-
let proof=await boundedRead(()=>chrome.tabs.sendMessage(id,
|
|
59
|
-
{type:'CHAT_LOOP_TURN_OBSERVE_V1'}),3000);
|
|
60
|
-
if(proof?.contract!=='chat-loop.turn-observer.v1'){
|
|
61
|
-
const injected=await boundedRead(()=>chrome.scripting.executeScript({
|
|
62
|
-
target:{tabId:id},files:['content.js', 'loop/observer-inspect.js', 'loop/observer-poll.js', 'loop/observer-recovery.js', 'loop/observer-approval.js', 'loop/observer.js']}),3000);
|
|
63
|
-
if(!injected)throw Error('FIRST_TURN_OBSERVER_UNAVAILABLE');
|
|
64
|
-
proof=await boundedRead(()=>chrome.tabs.sendMessage(id,
|
|
65
|
-
{type:'CHAT_LOOP_TURN_OBSERVE_V1'}),3000);
|
|
66
|
-
}
|
|
67
|
-
if(proof?.contract!=='chat-loop.turn-observer.v1')
|
|
68
|
-
throw Error('FIRST_TURN_OBSERVER_UNAVAILABLE');
|
|
69
|
-
}
|
|
70
|
-
async function sendFirst(id,text){
|
|
71
|
-
const [clicked]=await chrome.scripting.executeScript({target:{tabId:id},
|
|
72
|
-
func:async instruction=>{
|
|
73
|
-
try{
|
|
74
|
-
const visible=e=>Boolean(e?.getClientRects?.().length);
|
|
75
|
-
if(location.origin!=='https://chatgpt.com'||location.pathname!=='/')throw Error('START_PAGE_CHANGED');
|
|
76
|
-
const mains=[...document.querySelectorAll('main')].filter(visible);
|
|
77
|
-
const editor=document.querySelector('[contenteditable="true"][data-composer-markdown]')
|
|
78
|
-
||document.querySelector('#prompt-textarea[contenteditable="true"]');
|
|
79
|
-
if(mains.length!==1||!visible(editor)||!(editor.isContentEditable)||!document.contains(editor)
|
|
80
|
-
||(editor.innerText||editor.textContent||'').trim()
|
|
81
|
-
||mains[0].querySelector('[data-chatgpt-search-message-ids],[data-message-author-role]'))
|
|
82
|
-
throw Error('START_COMPOSER_UNVERIFIED');
|
|
83
|
-
// Recheck immediately before changing the composer; account
|
|
84
|
-
// identity may have switched after the initial readiness probe.
|
|
85
|
-
const switched=/你的账户已切换[。.!!\s]*请重新发送消息|your account (?:has been |was )?switched[.!\s]*please (?:re-?send|send again) (?:your )?message/i;
|
|
86
|
-
if(switched.test(mains[0].innerText||mains[0].textContent||''))
|
|
87
|
-
throw Error('START_ACCOUNT_SWITCH_VISIBLE');
|
|
88
|
-
const canonical=v=>String(v||'').replace(/\s+/g,'');
|
|
89
|
-
editor.focus();
|
|
90
|
-
if(!document.execCommand('insertText',false,instruction))throw Error('START_INPUT_REJECTED');
|
|
91
|
-
let verified=false;
|
|
92
|
-
for(let i=0;i<25;i++){
|
|
93
|
-
if(location.pathname!=='/')throw Error('START_PAGE_CHANGED_DURING_INPUT');
|
|
94
|
-
if(canonical(editor.innerText)===canonical(instruction)
|
|
95
|
-
||canonical(editor.textContent)===canonical(instruction)){verified=true;break;}
|
|
96
|
-
await new Promise(r=>setTimeout(r,120));
|
|
97
|
-
}
|
|
98
|
-
if(!verified)throw Error('START_INPUT_UNVERIFIED');
|
|
99
|
-
let send;
|
|
100
|
-
for(let i=0;i<16;i++){
|
|
101
|
-
send=document.querySelector('button[data-testid="send-button"]')
|
|
102
|
-
||document.querySelector('button[data-testid="composer-send-button"]')
|
|
103
|
-
||document.querySelector('button[type="submit"][aria-label="发送"]')
|
|
104
|
-
||document.querySelector('button[aria-label="Send message"]');
|
|
105
|
-
if(send&&!send.disabled&&visible(send))break;
|
|
106
|
-
await new Promise(r=>setTimeout(r,120));
|
|
107
|
-
}
|
|
108
|
-
if(!send||send.disabled||!visible(send))throw Error('START_SEND_BUTTON_UNAVAILABLE');
|
|
109
|
-
if(location.pathname!=='/'||(canonical(editor.innerText)!==canonical(instruction)
|
|
110
|
-
&&canonical(editor.textContent)!==canonical(instruction)))
|
|
111
|
-
throw Error('START_INPUT_CHANGED');
|
|
112
|
-
send.click(); // Once only. Worker persisted PENDING before this point.
|
|
113
|
-
return {clickedOnce:true};
|
|
114
|
-
}catch(e){
|
|
115
|
-
const code=e?.code||e?.message;
|
|
116
|
-
return {clickedOnce:false,reason:
|
|
117
|
-
/^[A-Z][A-Z0-9_]{1,95}$/.test(code||'')?code:'START_INPUT_UNKNOWN'};
|
|
118
|
-
}
|
|
119
|
-
},args:[text]});
|
|
120
|
-
if(clicked?.result?.clickedOnce!==true)
|
|
121
|
-
throw Error(clicked?.result?.reason||'START_CLICK_UNVERIFIED');
|
|
122
|
-
// Once clicked: ONLY bounded read-only receipt probes. A provisional
|
|
123
|
-
// local-chatgpt URL can settle late; never retry typing or clicking.
|
|
124
|
-
// Keep even the worst-case read budget below the 330s Worker watchdog,
|
|
125
|
-
// including the preceding 90s cold-page readiness window.
|
|
126
|
-
const deadline=Date.now()+120_000;
|
|
127
|
-
// E15 must verify a single, stable server-backed first user Turn.
|
|
128
|
-
// One transient bubble is not proof that ChatGPT emitted exactly one Turn.
|
|
129
|
-
let candidatePage=null,candidateUserKey=null,stableProbes=0;
|
|
130
|
-
for(let i=0;i<200&&Date.now()<deadline;i++){
|
|
131
|
-
const tab=await boundedRead(()=>chrome.tabs.get(id),
|
|
132
|
-
Math.min(1200,Math.max(1,deadline-Date.now())));
|
|
133
|
-
const page=tab?.url&&new URL(tab.url).pathname;
|
|
134
|
-
if(/^\/c\/[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}$/i.test(page||'')){
|
|
135
|
-
const rows=await boundedRead(()=>chrome.scripting.executeScript({target:{tabId:id},func:expected=>{
|
|
136
|
-
const visible=e=>Boolean(e?.getClientRects?.().length);
|
|
137
|
-
const mains=[...document.querySelectorAll('main')].filter(visible);
|
|
138
|
-
if(mains.length!==1)return null;
|
|
139
|
-
const modern=[...mains[0].querySelectorAll('[data-chatgpt-search-unit-key][data-chatgpt-search-message-ids]')];
|
|
140
|
-
const rows=modern.length?modern:[...mains[0].querySelectorAll('[data-message-author-role]')];
|
|
141
|
-
const role=n=>n.getAttribute('data-message-author-role')
|
|
142
|
-
||n.getAttribute('data-chatgpt-search-unit-key')?.split(':').at(-1);
|
|
143
|
-
const users=rows.filter(n=>role(n)==='user');
|
|
144
|
-
const user=users.at(-1);
|
|
145
|
-
const idOf=node=>node?.getAttribute('data-message-id')
|
|
146
|
-
||node?.getAttribute('data-chatgpt-search-message-ids')?.trim().split(/\s+/)[0];
|
|
147
|
-
const ids=users.map(idOf);
|
|
148
|
-
const id=idOf(user);
|
|
149
|
-
const bubble=user?.querySelector('[data-search-result-target]')
|
|
150
|
-
||user?.querySelector('[data-user-message-bubble="true"]')||user;
|
|
151
|
-
const canonical=v=>String(v||'').replace(/\s+/g,'');
|
|
152
|
-
return {observedPage:location.pathname,userMessageCount:users.length,
|
|
153
|
-
distinctUserIds:new Set(ids).size,
|
|
154
|
-
userKey:id&&canonical(bubble?.innerText||bubble?.textContent)===canonical(expected)
|
|
155
|
-
?'user:'+id:null};
|
|
156
|
-
},args:[text]}),Math.min(1200,Math.max(1,deadline-Date.now())));
|
|
157
|
-
const evidence=rows?.[0]?.result;
|
|
158
|
-
if(evidence?.observedPage&&evidence.observedPage!==page)
|
|
159
|
-
throw Error('FIRST_SEND_PAGE_DRIFT_UNVERIFIED');
|
|
160
|
-
if(evidence?.userMessageCount>1||evidence?.distinctUserIds>1)
|
|
161
|
-
throw Error('FIRST_SEND_DUPLICATE_UNVERIFIED');
|
|
162
|
-
const exactOne=evidence?.userMessageCount===1
|
|
163
|
-
&&evidence.distinctUserIds===1&&typeof evidence.userKey==='string';
|
|
164
|
-
if(exactOne){
|
|
165
|
-
if(candidatePage===page&&candidateUserKey===evidence.userKey)stableProbes++;
|
|
166
|
-
else {candidatePage=page;candidateUserKey=evidence.userKey;stableProbes=1;}
|
|
167
|
-
// Four independent bounded DOM probes (~1.2s in Chrome). Never
|
|
168
|
-
// claim SENT_CONFIRMED from the first transient matching bubble.
|
|
169
|
-
if(stableProbes>=4)return {status:'SENT_CONFIRMED',
|
|
170
|
-
newUserKey:candidateUserKey,newPage:page,newTabId:id};
|
|
171
|
-
}else if(evidence){candidatePage=null;candidateUserKey=null;stableProbes=0;}
|
|
172
|
-
}
|
|
173
|
-
await pause(Math.min(420,Math.max(1,deadline-Date.now())));
|
|
174
|
-
}
|
|
175
|
-
throw Error('FIRST_SEND_RECEIPT_UNKNOWN');
|
|
176
|
-
}
|
|
177
|
-
async function run(){
|
|
178
|
-
const own=await chrome.tabs.getCurrent();
|
|
179
|
-
const q=new URLSearchParams(location.search),id=q.get('requestId');
|
|
180
|
-
if(!own?.id||own.url!==location.href||[...q.keys()].length!==1
|
|
181
|
-
||!/^[a-f0-9]{32}$/.test(id||''))throw Error('START_ACTION_SOURCE_INVALID');
|
|
182
|
-
const proof=await chrome.runtime.sendNativeMessage(host,{op:'acquire',id,action:'start'});
|
|
183
|
-
if(proof?.status!=='OK'||proof.action!=='start'||proof.id!==id
|
|
184
|
-
||typeof proof.nonce!=='string')throw Error(proof?.code||'START_NATIVE_INVALID');
|
|
185
|
-
let prepared,taken,newTab,committed;
|
|
186
|
-
try{
|
|
187
|
-
prepared=await chrome.runtime.sendMessage({type:'CHAT_LOOP_SESSION_START_PREPARE_V1',
|
|
188
|
-
requestId:id,...(proof.traceParent?{traceParent:proof.traceParent}:{})});
|
|
189
|
-
if(prepared?.status!=='PREPARED')throw Error(prepared?.code||'START_PREPARE_DENIED');
|
|
190
|
-
taken=await chrome.runtime.sendMessage({type:'CHAT_LOOP_SESSION_START_TAKE_V1',
|
|
191
|
-
requestId:id,token:prepared.token,
|
|
192
|
-
...(proof.traceParent?{traceParent:proof.traceParent}:{})});
|
|
193
|
-
if(taken?.status!=='OK'||taken.sessionId!==prepared.sessionId
|
|
194
|
-
||(taken.mode==='adopt'
|
|
195
|
-
? !Number.isSafeInteger(taken.tabId)||!/^\/c\/[0-9a-f-]{12,}$/i.test(taken.page||'')
|
|
196
|
-
&& !/^\/g\/[^/]+\/c\/[0-9a-f-]{12,}$/i.test(taken.page||'')
|
|
197
|
-
||typeof taken.userKey!=='string'
|
|
198
|
-
: typeof taken.prompt!=='string'))
|
|
199
|
-
throw Error(taken?.code||'START_TAKE_DENIED');
|
|
200
|
-
if(taken.mode==='adopt'){
|
|
201
|
-
const existing=await chrome.tabs.get(taken.tabId).catch(()=>null);
|
|
202
|
-
if(!existing || new URL(existing.url).pathname!==taken.page)
|
|
203
|
-
throw Error('ADOPTION_TAB_UNVERIFIED');
|
|
204
|
-
await observerReady(existing.id);
|
|
205
|
-
const repair=taken.purpose==='REPAIR_SAME_SCOPE';
|
|
206
|
-
const evidence=await chrome.tabs.sendMessage(existing.id,
|
|
207
|
-
{type:repair?'CHAT_LOOP_REPAIR_EVIDENCE_V1':'CHAT_LOOP_APPROVAL_EVIDENCE_V1',
|
|
208
|
-
...(taken.explicitChatId
|
|
209
|
-
?{explicitChatId:taken.explicitChatId}:{}),
|
|
210
|
-
...(taken.expectedTaskId
|
|
211
|
-
?{expectedTaskId:taken.expectedTaskId}:{})}).catch(()=>null);
|
|
212
|
-
if(evidence?.contract!=='chat-loop.turn-observer.v1'
|
|
213
|
-
||evidence.status!=='VERIFIED'||evidence.page!==taken.page
|
|
214
|
-
||evidence.userKey!==taken.userKey
|
|
215
|
-
||(repair
|
|
216
|
-
? evidence.userText!==taken.repairUserText
|
|
217
|
-
||evidence.priorDoneAssistantKey!==taken.priorDoneAssistantKey
|
|
218
|
-
: evidence.rVersion!==taken.rVersion
|
|
219
|
-
||evidence.pVersion!==taken.pVersion
|
|
220
|
-
||(evidence.priorAssistantKey||null)!==(taken.priorAssistantKey||null)
|
|
221
|
-
||(evidence.postApprovalAssistantKey||null)!==(taken.postApprovalAssistantKey||null)))
|
|
222
|
-
throw Error('ADOPTION_APPROVAL_CHANGED');
|
|
223
|
-
const registered=await chrome.runtime.sendMessage({type:'CHAT_LOOP_RESOURCE_CHAT_V1',
|
|
224
|
-
action:'start',stage:'adopt',tabId:existing.id});
|
|
225
|
-
if(registered?.status!=='OK')throw Error(registered?.code||'ADOPTION_RESOURCE_UNVERIFIED');
|
|
226
|
-
// No tabs.create, no composer input, no send-button click in this branch.
|
|
227
|
-
committed=await chrome.runtime.sendMessage({type:'CHAT_LOOP_SESSION_START_RESULT_V1',
|
|
228
|
-
requestId:id,token:prepared.token,result:'ADOPTED_CONFIRMED',
|
|
229
|
-
...(proof.traceParent?{traceParent:proof.traceParent}:{}),
|
|
230
|
-
newTabId:existing.id,newPage:taken.page,newUserKey:taken.userKey});
|
|
231
|
-
if(committed?.status!=='OK')throw Error(committed?.code||'ADOPTION_COMMIT_UNVERIFIED');
|
|
232
|
-
await chrome.tabs.sendMessage(existing.id,{type:'CHAT_LOOP_TURN_RESUME_V1',
|
|
233
|
-
page:taken.page,userKey:taken.userKey,
|
|
234
|
-
assistantKey:taken.postApprovalAssistantKey||taken.priorAssistantKey||null,
|
|
235
|
-
...(taken.postApprovalAssistantKey?{baselineOnly:true}:{}),
|
|
236
|
-
startedAt:Date.now()}).catch(()=>null);
|
|
237
|
-
const stored=await chrome.runtime.sendNativeMessage(host,{op:'complete',
|
|
238
|
-
id,nonce:proof.nonce,action:'start',status:'OK',payload:JSON.stringify(committed)});
|
|
239
|
-
if(stored?.status!=='SAVED')throw Error(stored?.code||'ADOPTION_RECEIPT_UNVERIFIED');
|
|
240
|
-
show('SUCCESS','已接管完成 R/P 确认的原 Chat;没有新建会话或重新发送消息。');
|
|
241
|
-
await chrome.tabs.remove(own.id);
|
|
242
|
-
return;
|
|
243
|
-
}
|
|
244
|
-
const quota=await chrome.runtime.sendMessage({type:'CHAT_LOOP_RESOURCE_CHAT_V1',
|
|
245
|
-
action:'start',stage:'preflight'});
|
|
246
|
-
if(quota?.status!=='OK')throw Error(quota?.code||'RESOURCE_QUOTA_UNVERIFIED');
|
|
247
|
-
show('RUNNING','已独占会话,正在创建唯一网页 Chat 并确认首轮发送。');
|
|
248
|
-
newTab=await chrome.tabs.create({url:'https://chatgpt.com/',active:true,
|
|
249
|
-
windowId:own.windowId,openerTabId:own.id});
|
|
250
|
-
await waitForHomeUrl(newTab.id);
|
|
251
|
-
const registered=await chrome.runtime.sendMessage({type:'CHAT_LOOP_RESOURCE_CHAT_V1',
|
|
252
|
-
action:'start',stage:'register',tabId:newTab.id});
|
|
253
|
-
if(registered?.status!=='OK')throw Error(registered?.code||'RESOURCE_REGISTER_UNVERIFIED');
|
|
254
|
-
await newChatReady(newTab.id);
|
|
255
|
-
await observerReady(newTab.id);
|
|
256
|
-
const receipt=await sendFirst(newTab.id,taken.prompt);
|
|
257
|
-
committed=await chrome.runtime.sendMessage({type:'CHAT_LOOP_SESSION_START_RESULT_V1',
|
|
258
|
-
requestId:id,token:prepared.token,...receipt,result:receipt.status,
|
|
259
|
-
...(proof.traceParent?{traceParent:proof.traceParent}:{})});
|
|
260
|
-
if(committed?.status!=='OK')throw Error(committed?.code||'START_COMMIT_UNVERIFIED');
|
|
261
|
-
const stored=await chrome.runtime.sendNativeMessage(host,{op:'complete',
|
|
262
|
-
id,nonce:proof.nonce,action:'start',status:'OK',payload:JSON.stringify(committed)});
|
|
263
|
-
if(stored?.status!=='SAVED')throw Error(stored?.code||'START_RECEIPT_NOT_STORED');
|
|
264
|
-
show('SUCCESS','唯一网页 Chat 已确认;执行由 Observer 和 Continue/Handoff 接管。');
|
|
265
|
-
await chrome.tabs.remove(own.id);
|
|
266
|
-
}catch(e){
|
|
267
|
-
if(taken&&committed?.status!=='OK') {
|
|
268
|
-
// This is diagnostics only; it does NOT authorize a retry or prove a
|
|
269
|
-
// message was never sent. Keep the existing fail-closed Owner semantics.
|
|
270
|
-
const failureCode=['START_HOME_URL_UNVERIFIED','NEW_CHAT_NOT_READY',
|
|
271
|
-
'START_COMPOSER_NOT_EMPTY','START_ACCOUNT_SWITCH_VISIBLE',
|
|
272
|
-
'FIRST_TURN_OBSERVER_UNAVAILABLE','START_SEND_BUTTON_UNAVAILABLE','START_INPUT_CHANGED',
|
|
273
|
-
'START_INPUT_UNVERIFIED','START_INPUT_REJECTED',
|
|
274
|
-
'START_CLICK_UNVERIFIED','FIRST_SEND_RECEIPT_UNKNOWN',
|
|
275
|
-
'FIRST_SEND_DUPLICATE_UNVERIFIED','FIRST_SEND_PAGE_DRIFT_UNVERIFIED']
|
|
276
|
-
.includes(e.message) ? e.message : null;
|
|
277
|
-
await chrome.runtime.sendMessage({type:'CHAT_LOOP_SESSION_START_RESULT_V1',
|
|
278
|
-
requestId:id,token:prepared.token,result:'UNVERIFIED',newTabId:newTab?.id,
|
|
279
|
-
...(proof.traceParent?{traceParent:proof.traceParent}:{}),
|
|
280
|
-
...(failureCode?{failureCode}:{})}).catch(()=>{});
|
|
281
|
-
}
|
|
282
|
-
const rawCode=e?.code||e?.message;
|
|
283
|
-
const code=typeof rawCode==='string'&&/^[A-Z][A-Z0-9_]{1,95}$/.test(rawCode)
|
|
284
|
-
?rawCode:'START_UNVERIFIED';
|
|
285
|
-
const failed=await chrome.runtime.sendNativeMessage(host,{op:'complete',id,nonce:proof.nonce,
|
|
286
|
-
action:'start',status:'FAILED',code}).catch(()=>null);
|
|
287
|
-
// Only the Action page closes after its durable FAILED receipt; the
|
|
288
|
-
// possibly-sent Chat and any unverified draft remain untouched.
|
|
289
|
-
if(failed?.status==='SAVED' && failed.id===id)
|
|
290
|
-
await chrome.tabs.remove(own.id).catch(()=>{});
|
|
291
|
-
throw e; // Never auto-retry a possibly clicked first user Turn.
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
void run().catch(e=>show('BLOCKED',
|
|
295
|
-
/^[A-Z][A-Z0-9_]{1,95}$/.test(e?.message||'')?e.message:'START_UNVERIFIED'));
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
// Read-only machine Status. Does not create a Chat or modify the browser Owner.
|
|
2
|
-
const host='com.tomflow.chatloop.extension';
|
|
3
|
-
async function run(){
|
|
4
|
-
const own=await chrome.tabs.getCurrent(),q=new URLSearchParams(location.search);
|
|
5
|
-
const id=q.get('requestId');
|
|
6
|
-
if(!own?.id||own.url!==location.href||[...q.keys()].length!==1
|
|
7
|
-
||!/^[a-f0-9]{32}$/.test(id||''))throw Error('INVALID_STATUS_ACTION');
|
|
8
|
-
const proof=await chrome.runtime.sendNativeMessage(host,{op:'acquire',id,action:'status'});
|
|
9
|
-
if(proof?.status!=='OK'||proof.action!=='status'||proof.id!==id)
|
|
10
|
-
throw Error(proof?.code||'STATUS_NATIVE_INVALID');
|
|
11
|
-
const state=await chrome.runtime.sendMessage({type:'CHAT_LOOP_SESSION_STATUS_V1',
|
|
12
|
-
requestId:id,...(proof.traceParent?{traceParent:proof.traceParent}:{})});
|
|
13
|
-
const receipt=await chrome.runtime.sendNativeMessage(host,{op:'complete',id,
|
|
14
|
-
nonce:proof.nonce,action:'status',status:'OK',payload:JSON.stringify(state)});
|
|
15
|
-
if(receipt?.status!=='SAVED')throw Error(receipt?.code||'STATUS_NOT_STORED');
|
|
16
|
-
document.getElementById('status').textContent='SUCCESS';
|
|
17
|
-
document.getElementById('details').textContent='只读状态已返回本机请求;未修改执行 Chat。';
|
|
18
|
-
await chrome.tabs.remove(own.id);
|
|
19
|
-
}
|
|
20
|
-
void run().catch(e=>{
|
|
21
|
-
document.getElementById('status').textContent='UNVERIFIED';
|
|
22
|
-
document.getElementById('details').textContent=
|
|
23
|
-
/^[A-Z][A-Z0-9_]{1,95}$/.test(e?.message||'')?e.message:'STATUS_UNKNOWN';
|
|
24
|
-
});
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
// Chrome MV3 classic service Worker. Shared lexical context; exact order
|
|
2
|
-
// preserves the original single-Worker Owner and serialized Action lifecycle.
|
|
3
|
-
importScripts("loop/index.js");
|
|
4
|
-
importScripts("worker/bootstrap.js");
|
|
5
|
-
importScripts("worker/admission.js");
|
|
6
|
-
importScripts("worker/adopt-prepare.js");
|
|
7
|
-
importScripts("worker/adopt-result.js");
|
|
8
|
-
importScripts("worker/session-control.js");
|
|
9
|
-
importScripts("worker/readiness.js");
|
|
10
|
-
importScripts("worker/turn-failure.js");
|
|
11
|
-
importScripts("worker/turn-finished.js");
|
|
12
|
-
importScripts("worker/adopt-recovery.js");
|
|
13
|
-
importScripts("worker/manual.js");
|
|
14
|
-
importScripts("worker/action-take.js");
|
|
15
|
-
importScripts("worker/action-result.js");
|
|
16
|
-
importScripts("worker/scheduler.js");
|
|
17
|
-
importScripts("worker/router.js");
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
<!doctype html>
|
|
2
|
-
<html lang="zh-CN"><head><meta charset="utf-8"><title>Chat Loop · Clean</title>
|
|
3
|
-
<style>body{font:14px system-ui;padding:22px;color:#242424}#status{font-weight:bold}#details{color:#666}</style></head>
|
|
4
|
-
<body><h1>Clean · 清理输入框</h1><p id="status">VERIFYING</p><p id="details">正在核实目标 Chat,不发送消息。</p>
|
|
5
|
-
<script src="actions/clean.js"></script></body></html>
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
// Read-only ChatGPT page agent. Reinjection after extension reload is idempotent.
|
|
2
|
-
(() => {
|
|
3
|
-
if (globalThis.__CHAT_LOOP_EYE_V1__) return;
|
|
4
|
-
globalThis.__CHAT_LOOP_EYE_V1__ = true;
|
|
5
|
-
const CONTRACT = "chat-loop.web-environment.v1";
|
|
6
|
-
const READ_CONTRACT = "chat-loop.eye.v1";
|
|
7
|
-
const onChatGPT = () => location.protocol === "https:" && location.hostname === "chatgpt.com";
|
|
8
|
-
|
|
9
|
-
function inspectChatPage() {
|
|
10
|
-
const brands = navigator.userAgentData?.brands;
|
|
11
|
-
const chromeBrowser = Array.isArray(brands)
|
|
12
|
-
&& brands.some(entry => entry?.brand === "Google Chrome");
|
|
13
|
-
return {
|
|
14
|
-
contract: CONTRACT,
|
|
15
|
-
status: !onChatGPT() ? "UNSUPPORTED_PAGE" : !chromeBrowser
|
|
16
|
-
? "BROWSER_UNVERIFIED" : "WEB_READY",
|
|
17
|
-
pageOrigin: onChatGPT() ? "https://chatgpt.com" : null,
|
|
18
|
-
browser: chromeBrowser ? "GOOGLE_CHROME" : "UNVERIFIED",
|
|
19
|
-
extensionVersion: chrome.runtime.getManifest().version
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
chrome.runtime.onMessage.addListener((message, _sender, sendResponse) => {
|
|
24
|
-
if (message?.type === "CHAT_LOOP_WEB_CHECK_V1") {
|
|
25
|
-
sendResponse(inspectChatPage());
|
|
26
|
-
return false;
|
|
27
|
-
}
|
|
28
|
-
if (message?.type !== "CHAT_LOOP_EYE_READ_V1") return false;
|
|
29
|
-
if (!onChatGPT() || !["dom", "text"].includes(message.mode)) {
|
|
30
|
-
sendResponse({contract: READ_CONTRACT, status: "UNSUPPORTED"});
|
|
31
|
-
return false;
|
|
32
|
-
}
|
|
33
|
-
const value = message.mode === "dom"
|
|
34
|
-
? document.documentElement.outerHTML
|
|
35
|
-
: (document.querySelector("main")?.innerText ?? document.body?.innerText ?? "");
|
|
36
|
-
sendResponse({contract: READ_CONTRACT, status: "OK",
|
|
37
|
-
mode: message.mode, url: location.href, value, length: value.length});
|
|
38
|
-
return false;
|
|
39
|
-
});
|
|
40
|
-
})();
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
<!doctype html>
|
|
2
|
-
<html lang="zh-CN"><head><meta charset="utf-8"><title>Chat Loop Extension · Continue Action</title>
|
|
3
|
-
<style>body{font:15px system-ui,sans-serif;padding:24px;max-width:620px;color:#222}#status{font-weight:bold}#details{white-space:pre-wrap;overflow-wrap:anywhere}body[data-result="error"] #status{color:#b00020}</style>
|
|
4
|
-
</head><body>
|
|
5
|
-
<h1>Chat Loop · Continue</h1>
|
|
6
|
-
<p id="status" role="status">STARTING</p>
|
|
7
|
-
<p id="details">仅执行一次已授权的固定续接。失败时保留本页,不重新发送。</p>
|
|
8
|
-
<script src="actions/continue.js"></script>
|
|
9
|
-
</body></html>
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
<!doctype html>
|
|
2
|
-
<html lang="zh-CN">
|
|
3
|
-
<head>
|
|
4
|
-
<meta charset="utf-8">
|
|
5
|
-
<title>Chat Loop Extension · DOM</title>
|
|
6
|
-
<style>body{font:15px system-ui,sans-serif;padding:24px;max-width:620px;color:#222}
|
|
7
|
-
#status{font-weight:700}#details{white-space:pre-wrap;overflow-wrap:anywhere;color:#555}
|
|
8
|
-
body[data-result="error"] #status{color:#b00020}</style>
|
|
9
|
-
</head>
|
|
10
|
-
<body>
|
|
11
|
-
<h1>Chat Loop · DOM</h1>
|
|
12
|
-
<p id="status" role="status">STARTING</p>
|
|
13
|
-
<p id="details">正在执行,成功后关闭此页面;失败则保留错误以供诊断。</p>
|
|
14
|
-
<script src="actions/common.js"></script>
|
|
15
|
-
<script src="actions/dom.js"></script>
|
|
16
|
-
</body>
|
|
17
|
-
</html>
|