@tomflow/chatloop-extension 0.3.82 → 0.3.83
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/bin/native-host.mjs +3 -2
- package/extension/actions/start.js +31 -9
- package/extension/manifest.json +1 -1
- package/package.json +1 -1
package/bin/native-host.mjs
CHANGED
|
@@ -39,7 +39,8 @@ process.stdin.on('data',async chunk=>{
|
|
|
39
39
|
if(!session?.taskId||!session.sessionId)
|
|
40
40
|
throw Object.assign(Error('No Context-managed session'),{code:'CONTEXT_SESSION_UNBOUND'});
|
|
41
41
|
if(!['permit.consume','run.bind.initial','run.fence','run.bind.handoff',
|
|
42
|
-
'run.restore-same-owner','run.fence.terminal','run.
|
|
42
|
+
'run.restore-same-owner','run.fence.terminal','run.credential.rotate',
|
|
43
|
+
'run.terminalStatus','run.snapshot'].includes(m.command)
|
|
43
44
|
||!m.args||typeof m.args!=='object'||Array.isArray(m.args))
|
|
44
45
|
throw Object.assign(Error('Invalid Context command'),{code:'CONTEXT_COMMAND_INVALID'});
|
|
45
46
|
const own=new Set(['projectId','taskId','sessionId','generation','activeChatId',
|
|
@@ -52,7 +53,7 @@ process.stdin.on('data',async chunk=>{
|
|
|
52
53
|
activeChatId:session.activeChatId};
|
|
53
54
|
if(m.command==='run.bind.initial'||m.command==='run.bind.handoff')
|
|
54
55
|
args.runRef=session.sessionId+':'+session.taskId+':'+session.generation;
|
|
55
|
-
if(
|
|
56
|
+
if(['run.fence','run.fence.terminal','run.credential.rotate'].includes(m.command))
|
|
56
57
|
args.runRef=session.sessionId+':'+session.taskId+':'+session.generation;
|
|
57
58
|
const result=await nativeContextControl(m.command,args);
|
|
58
59
|
write({status:'OK',result});
|
|
@@ -120,11 +120,14 @@ async function sendFirst(id,text){
|
|
|
120
120
|
// Keep even the worst-case read budget below the 330s Worker watchdog,
|
|
121
121
|
// including the preceding 90s cold-page readiness window.
|
|
122
122
|
const deadline=Date.now()+120_000;
|
|
123
|
+
// E15 must verify a single, stable server-backed first user Turn.
|
|
124
|
+
// One transient bubble is not proof that ChatGPT emitted exactly one Turn.
|
|
125
|
+
let candidatePage=null,candidateUserKey=null,stableProbes=0;
|
|
123
126
|
for(let i=0;i<200&&Date.now()<deadline;i++){
|
|
124
127
|
const tab=await boundedRead(()=>chrome.tabs.get(id),
|
|
125
128
|
Math.min(1200,Math.max(1,deadline-Date.now())));
|
|
126
129
|
const page=tab?.url&&new URL(tab.url).pathname;
|
|
127
|
-
if(/^\/c\/[0-9a-f-]{12
|
|
130
|
+
if(/^\/c\/[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}$/i.test(page||'')){
|
|
128
131
|
const rows=await boundedRead(()=>chrome.scripting.executeScript({target:{tabId:id},func:expected=>{
|
|
129
132
|
const visible=e=>Boolean(e?.getClientRects?.().length);
|
|
130
133
|
const mains=[...document.querySelectorAll('main')].filter(visible);
|
|
@@ -133,17 +136,35 @@ async function sendFirst(id,text){
|
|
|
133
136
|
const rows=modern.length?modern:[...mains[0].querySelectorAll('[data-message-author-role]')];
|
|
134
137
|
const role=n=>n.getAttribute('data-message-author-role')
|
|
135
138
|
||n.getAttribute('data-chatgpt-search-unit-key')?.split(':').at(-1);
|
|
136
|
-
const
|
|
137
|
-
const
|
|
138
|
-
|
|
139
|
+
const users=rows.filter(n=>role(n)==='user');
|
|
140
|
+
const user=users.at(-1);
|
|
141
|
+
const idOf=node=>node?.getAttribute('data-message-id')
|
|
142
|
+
||node?.getAttribute('data-chatgpt-search-message-ids')?.trim().split(/\s+/)[0];
|
|
143
|
+
const ids=users.map(idOf);
|
|
144
|
+
const id=idOf(user);
|
|
139
145
|
const bubble=user?.querySelector('[data-search-result-target]')
|
|
140
146
|
||user?.querySelector('[data-user-message-bubble="true"]')||user;
|
|
141
147
|
const canonical=v=>String(v||'').replace(/\s+/g,'');
|
|
142
|
-
return
|
|
143
|
-
|
|
148
|
+
return {observedPage:location.pathname,userMessageCount:users.length,
|
|
149
|
+
distinctUserIds:new Set(ids).size,
|
|
150
|
+
userKey:id&&canonical(bubble?.innerText||bubble?.textContent)===canonical(expected)
|
|
151
|
+
?'user:'+id:null};
|
|
144
152
|
},args:[text]}),Math.min(1200,Math.max(1,deadline-Date.now())));
|
|
145
|
-
|
|
146
|
-
|
|
153
|
+
const evidence=rows?.[0]?.result;
|
|
154
|
+
if(evidence?.observedPage&&evidence.observedPage!==page)
|
|
155
|
+
throw Error('FIRST_SEND_PAGE_DRIFT_UNVERIFIED');
|
|
156
|
+
if(evidence?.userMessageCount>1||evidence?.distinctUserIds>1)
|
|
157
|
+
throw Error('FIRST_SEND_DUPLICATE_UNVERIFIED');
|
|
158
|
+
const exactOne=evidence?.userMessageCount===1
|
|
159
|
+
&&evidence.distinctUserIds===1&&typeof evidence.userKey==='string';
|
|
160
|
+
if(exactOne){
|
|
161
|
+
if(candidatePage===page&&candidateUserKey===evidence.userKey)stableProbes++;
|
|
162
|
+
else {candidatePage=page;candidateUserKey=evidence.userKey;stableProbes=1;}
|
|
163
|
+
// Four independent bounded DOM probes (~1.2s in Chrome). Never
|
|
164
|
+
// claim SENT_CONFIRMED from the first transient matching bubble.
|
|
165
|
+
if(stableProbes>=4)return {status:'SENT_CONFIRMED',
|
|
166
|
+
newUserKey:candidateUserKey,newPage:page,newTabId:id};
|
|
167
|
+
}else if(evidence){candidatePage=null;candidateUserKey=null;stableProbes=0;}
|
|
147
168
|
}
|
|
148
169
|
await pause(Math.min(420,Math.max(1,deadline-Date.now())));
|
|
149
170
|
}
|
|
@@ -242,7 +263,8 @@ async function run(){
|
|
|
242
263
|
'START_COMPOSER_NOT_EMPTY','START_ACCOUNT_SWITCH_VISIBLE',
|
|
243
264
|
'FIRST_TURN_OBSERVER_UNAVAILABLE','START_SEND_BUTTON_UNAVAILABLE','START_INPUT_CHANGED',
|
|
244
265
|
'START_INPUT_UNVERIFIED','START_INPUT_REJECTED',
|
|
245
|
-
'START_CLICK_UNVERIFIED','FIRST_SEND_RECEIPT_UNKNOWN'
|
|
266
|
+
'START_CLICK_UNVERIFIED','FIRST_SEND_RECEIPT_UNKNOWN',
|
|
267
|
+
'FIRST_SEND_DUPLICATE_UNVERIFIED','FIRST_SEND_PAGE_DRIFT_UNVERIFIED']
|
|
246
268
|
.includes(e.message) ? e.message : null;
|
|
247
269
|
await chrome.runtime.sendMessage({type:'CHAT_LOOP_SESSION_START_RESULT_V1',
|
|
248
270
|
requestId:id,token:prepared.token,result:'UNVERIFIED',newTabId:newTab?.id,
|
package/extension/manifest.json
CHANGED