@tomflow/chatloop-extension 0.4.15 → 0.4.21
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.
|
@@ -5,22 +5,44 @@ const detailNode=document.getElementById('details');
|
|
|
5
5
|
const show=(status,detail)=>{statusNode.textContent=status;detailNode.textContent=detail;document.body.dataset.result=status==='SUCCESS'?'success':'error';};
|
|
6
6
|
const pause=ms=>new Promise(r=>setTimeout(r,ms));
|
|
7
7
|
const safeCode=code=>/^[A-Z][A-Z0-9_]{1,95}$/.test(code||'')?code:'ENTRY_TEST_UNVERIFIED';
|
|
8
|
-
async function readNewChat(id){
|
|
8
|
+
async function readNewChat(id,recoverTestAt=false,recoverExactDraft=''){
|
|
9
9
|
const end=Date.now()+90000;
|
|
10
|
+
let cleaned=false;
|
|
10
11
|
while(Date.now()<end){
|
|
11
12
|
const tab=await chrome.tabs.get(id).catch(()=>null);
|
|
12
13
|
if(!tab)throw Error('ENTRY_CHAT_TAB_GONE');
|
|
13
14
|
if(tab.url==='https://chatgpt.com/'){
|
|
14
|
-
const proof=await chrome.scripting.executeScript({target:{tabId:id},
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
15
|
+
const proof=await chrome.scripting.executeScript({target:{tabId:id},
|
|
16
|
+
func:(recover,exactDraft)=>{
|
|
17
|
+
if(location.origin!=='https://chatgpt.com'||location.pathname!=='/')return false;
|
|
18
|
+
const mains=[...document.querySelectorAll('main')].filter(e=>e.getClientRects().length);
|
|
19
|
+
const editor=document.querySelector('#prompt-textarea[contenteditable="true"]')
|
|
20
|
+
||document.querySelector('[contenteditable="true"][data-composer-markdown]');
|
|
21
|
+
if(mains.length!==1||!editor?.getClientRects().length||!editor.isContentEditable
|
|
22
|
+
||mains[0].querySelector('[data-chatgpt-search-message-ids],[data-message-author-role]'))
|
|
23
|
+
return false;
|
|
24
|
+
const current=(editor.innerText||editor.textContent||'').trim();
|
|
25
|
+
if(!current)return 'READY';
|
|
26
|
+
const canonical=value=>String(value||'').replace(/\s+/g,'');
|
|
27
|
+
const exactRecovery=typeof exactDraft==='string'&&!!exactDraft
|
|
28
|
+
&&canonical(current)===canonical(exactDraft);
|
|
29
|
+
if(!recover&& !exactRecovery)return 'HAS_DRAFT';
|
|
30
|
+
if(recover&¤t!=='@'&&!exactRecovery)return 'HAS_DRAFT';
|
|
31
|
+
// Only a verified leftover "@" or byte-equivalent earlier TEST_ONLY
|
|
32
|
+
// draft may be cleared, on the newly created empty Chat home. Never
|
|
33
|
+
// touch other drafts, user turns or existing Chat tabs.
|
|
34
|
+
editor.focus();
|
|
35
|
+
const selection=window.getSelection(),range=document.createRange();
|
|
36
|
+
range.selectNodeContents(editor);selection.removeAllRanges();selection.addRange(range);
|
|
37
|
+
if(!document.execCommand('delete',false))return 'RECOVERY_FAILED';
|
|
38
|
+
return !(editor.innerText||editor.textContent||'').trim()
|
|
39
|
+
?'RECOVERED_DRAFT':'RECOVERY_FAILED';
|
|
40
|
+
},args:[recoverTestAt&&!cleaned,cleaned?'':recoverExactDraft]}).catch(()=>null);
|
|
41
|
+
const state=proof?.[0]?.result;
|
|
42
|
+
if(state==='READY')return;
|
|
43
|
+
if(state==='RECOVERED_DRAFT'){cleaned=true;continue;}
|
|
44
|
+
if(state==='HAS_DRAFT')throw Error('ENTRY_COMPOSER_HAS_DRAFT');
|
|
45
|
+
if(state==='RECOVERY_FAILED')throw Error('ENTRY_AT_RECOVERY_FAILED');
|
|
24
46
|
}
|
|
25
47
|
await pause(320);
|
|
26
48
|
}
|
|
@@ -39,22 +61,34 @@ async function nativeMentionAndSend(id,appId,prompt){
|
|
|
39
61
|
||!editor||!visible(editor)||!editor.isContentEditable
|
|
40
62
|
||(editor.innerText||editor.textContent||'').trim())
|
|
41
63
|
return fail('ENTRY_EDITOR_UNVERIFIED');
|
|
64
|
+
// Commit the natural-language task to the host editor first. Selecting
|
|
65
|
+
// a native App mention can rehydrate the composer and otherwise discard
|
|
66
|
+
// text entered immediately after the selection transaction.
|
|
42
67
|
editor.focus();
|
|
68
|
+
if(!document.execCommand('insertText',false,prompt))return fail('ENTRY_PROMPT_INPUT_FAILED');
|
|
69
|
+
await wait(700);
|
|
70
|
+
if(!canonical(editor.innerText||editor.textContent).includes(canonical(prompt)))
|
|
71
|
+
return fail('ENTRY_PROMPT_NOT_VISIBLE');
|
|
72
|
+
const selection=window.getSelection(),range=document.createRange();
|
|
73
|
+
range.selectNodeContents(editor);range.collapse(true);
|
|
74
|
+
selection.removeAllRanges();selection.addRange(range);
|
|
43
75
|
if(!document.execCommand('insertText',false,'@'))return fail('ENTRY_AT_INPUT_FAILED');
|
|
44
76
|
let choice=null,diagnostic='';
|
|
45
|
-
const selectors=['[role="option"]','[role="menuitem"]','[cmdk-item]',
|
|
77
|
+
const selectors=['button[data-plugin-impression-id]','[role="option"]','[role="menuitem"]','[cmdk-item]',
|
|
46
78
|
'[data-testid*="app-item"]','[data-testid*="mention-item"]'];
|
|
47
79
|
for(let i=0;i<55;i++){
|
|
48
80
|
if(location.pathname!=='/')return fail('ENTRY_PAGE_CHANGED');
|
|
49
81
|
const nodes=[...document.querySelectorAll(selectors.join(','))]
|
|
50
82
|
.filter(visible).filter(e=>(e.innerText||'').includes('Chat Loop'));
|
|
83
|
+
const matching=nodes.filter(e=>e.getAttribute('data-plugin-impression-id')===appId);
|
|
84
|
+
if(matching.length===1){choice=matching[0];break;}
|
|
51
85
|
const exact=nodes.filter(e=>{
|
|
52
86
|
const t=(e.innerText||'').trim();
|
|
53
87
|
return t==='Chat Loop'||t.startsWith('Chat Loop\n');
|
|
54
88
|
});
|
|
55
89
|
if(exact.length===1){choice=exact[0];break;}
|
|
56
90
|
if(!exact.length && nodes.length===1){choice=nodes[0];break;}
|
|
57
|
-
diagnostic=nodes.slice(0,4).map(e=>e.getAttribute('
|
|
91
|
+
diagnostic=nodes.slice(0,4).map(e=>e.getAttribute('data-plugin-impression-id')+':'+(e.innerText||'').slice(0,55)).join('|');
|
|
58
92
|
await wait(220);
|
|
59
93
|
}
|
|
60
94
|
if(!choice)return fail('ENTRY_NATIVE_APP_OPTION_MISSING',diagnostic);
|
|
@@ -70,14 +104,14 @@ async function nativeMentionAndSend(id,appId,prompt){
|
|
|
70
104
|
await wait(120);
|
|
71
105
|
}
|
|
72
106
|
if(!native)return fail('ENTRY_NATIVE_MENTION_UNVERIFIED',editor.innerHTML);
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
for(let i=0;i<
|
|
76
|
-
|
|
77
|
-
|
|
107
|
+
// Wait for the host selection transaction to settle; never rely on
|
|
108
|
+
// a transient DOM text match before clicking its native send button.
|
|
109
|
+
for(let i=0;i<5;i++){
|
|
110
|
+
await wait(240);
|
|
111
|
+
if(location.pathname!=='/')return fail('ENTRY_PAGE_CHANGED_BEFORE_SEND');
|
|
112
|
+
if(!canonical(editor.innerText||editor.textContent).includes(canonical(prompt)))
|
|
113
|
+
return fail('ENTRY_PROMPT_LOST_ON_MENTION');
|
|
78
114
|
}
|
|
79
|
-
if(!canonical(editor.innerText||editor.textContent).includes(canonical(prompt)))
|
|
80
|
-
return fail('ENTRY_PROMPT_NOT_VISIBLE');
|
|
81
115
|
const tokens=[...editor.querySelectorAll('[data-prompt-link-href],[data-app-mention-path],a[href],[data-type="mention"]')];
|
|
82
116
|
if(!tokens.some(e=>(e.getAttribute('data-prompt-link-href')||'').includes(appId)
|
|
83
117
|
||(e.getAttribute('data-app-mention-path')||'').includes(appId)
|
|
@@ -97,7 +131,7 @@ async function nativeMentionAndSend(id,appId,prompt){
|
|
|
97
131
|
if(r.status!=='CLICKED_ONCE')throw Error(safeCode(r.code));
|
|
98
132
|
}
|
|
99
133
|
async function verifyNativeUserTurn(id,appId,prompt){
|
|
100
|
-
const end=Date.now()+120000;let last=null,stable=0;
|
|
134
|
+
const end=Date.now()+120000;let last=null,stable=0,mismatch=0;
|
|
101
135
|
while(Date.now()<end){
|
|
102
136
|
const tab=await chrome.tabs.get(id).catch(()=>null);
|
|
103
137
|
if(!tab)throw Error('ENTRY_CHAT_TAB_GONE');
|
|
@@ -106,11 +140,12 @@ async function verifyNativeUserTurn(id,appId,prompt){
|
|
|
106
140
|
const r=await chrome.scripting.executeScript({target:{tabId:id},
|
|
107
141
|
func:(appId,prompt)=>{
|
|
108
142
|
if(location.origin!=='https://chatgpt.com')return null;
|
|
109
|
-
|
|
110
|
-
|
|
143
|
+
// ChatGPT can render conversation turns outside its composer <main>.
|
|
144
|
+
// A main-scoped read silently misses real user turns in that layout.
|
|
145
|
+
const users=[...document.querySelectorAll('[data-chatgpt-search-unit-key][data-chatgpt-search-message-ids]')]
|
|
111
146
|
.filter(x=>x.getAttribute('data-chatgpt-search-unit-key')?.endsWith(':user'));
|
|
112
147
|
if(!users.length){
|
|
113
|
-
users.push(...
|
|
148
|
+
users.push(...document.querySelectorAll('[data-message-author-role="user"]'));
|
|
114
149
|
}
|
|
115
150
|
const u=users.at(-1);
|
|
116
151
|
const key=u?.getAttribute('data-message-id')
|
|
@@ -128,6 +163,9 @@ async function verifyNativeUserTurn(id,appId,prompt){
|
|
|
128
163
|
const v=r?.[0]?.result;
|
|
129
164
|
if(v?.userCount>1||v?.ids?.some(x=>x!==v.ids[0]))
|
|
130
165
|
throw Error('ENTRY_DUPLICATE_USER_TURN');
|
|
166
|
+
if(v?.path===path&&v.userCount===1&&v.hasNativeApp&&!v.userKey){
|
|
167
|
+
if(++mismatch>=4)throw Error('ENTRY_USER_TURN_CONTENT_MISMATCH');
|
|
168
|
+
}else mismatch=0;
|
|
131
169
|
if(v?.path===path&&v.userCount===1&&v.hasNativeApp&&v.userKey){
|
|
132
170
|
const k=path+'|'+v.userKey;
|
|
133
171
|
stable=last===k?stable+1:1;last=k;
|
|
@@ -157,18 +195,35 @@ async function run(){
|
|
|
157
195
|
const intent=proof.intent;
|
|
158
196
|
let tab,clicked=false;
|
|
159
197
|
try{
|
|
160
|
-
//
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
await
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
198
|
+
// This read-only Worker/Native gate may admit a provably frozen orphan
|
|
199
|
+
// for an independent TEST_ONLY Chat; it never releases the old Session.
|
|
200
|
+
const admitted=async()=>{
|
|
201
|
+
const decision=await chrome.runtime.sendMessage({
|
|
202
|
+
type:'CHAT_LOOP_ENTRY_TEST_ADMISSION_V1',requestId:id}).catch(()=>null);
|
|
203
|
+
if(decision?.status!=='OK'||decision.scope!=='TEST_ONLY')
|
|
204
|
+
throw Error(safeCode(decision?.code||'ENTRY_TEST_OWNER_UNVERIFIED'));
|
|
205
|
+
};
|
|
206
|
+
await admitted();
|
|
207
|
+
let result;
|
|
208
|
+
if(intent.verifyChatUrl){
|
|
209
|
+
// Pure receipt recovery. Never click, resend, adopt or modify an existing Chat.
|
|
210
|
+
show('RUNNING','只读核对已存在 Chat 的唯一原生 @ App 用户消息。');
|
|
211
|
+
const candidates=await chrome.tabs.query({url:intent.verifyChatUrl});
|
|
212
|
+
const matches=candidates.filter(t=>t.url===intent.verifyChatUrl
|
|
213
|
+
&&Number.isSafeInteger(t.id));
|
|
214
|
+
if(matches.length!==1)throw Error('ENTRY_VERIFY_TAB_UNVERIFIED');
|
|
215
|
+
result=await verifyNativeUserTurn(matches[0].id,intent.appId,intent.prompt);
|
|
216
|
+
}else{
|
|
217
|
+
show('RUNNING','新普通 Chat 正在加载;仅验证原生 App 入口,不进行批准或 Start。');
|
|
218
|
+
tab=await chrome.tabs.create({url:'https://chatgpt.com/',active:true,
|
|
219
|
+
windowId:own.windowId,openerTabId:own.id});
|
|
220
|
+
if(!Number.isSafeInteger(tab?.id))throw Error('ENTRY_NEW_TAB_UNVERIFIED');
|
|
221
|
+
await readNewChat(tab.id,intent.recoverTestAt===true,intent.recoverExactDraft||'');
|
|
222
|
+
await admitted(); // Recheck before the only possible first send.
|
|
223
|
+
await nativeMentionAndSend(tab.id,intent.appId,intent.prompt);
|
|
224
|
+
clicked=true;
|
|
225
|
+
result=await verifyNativeUserTurn(tab.id,intent.appId,intent.prompt);
|
|
226
|
+
}
|
|
172
227
|
const stored=await chrome.runtime.sendNativeMessage(HOST,{op:'complete',id,
|
|
173
228
|
nonce:proof.nonce,action:'entry_test',status:'OK',payload:JSON.stringify(result)});
|
|
174
229
|
if(stored?.status!=='SAVED'||stored.id!==id)throw Error('ENTRY_TEST_NATIVE_RECEIPT_UNVERIFIED');
|
|
@@ -141,16 +141,32 @@ if (message?.type === "CHAT_LOOP_APPROVAL_EVIDENCE_V1") {
|
|
|
141
141
|
fail("APPROVAL_REQUIREMENTS_MISSING");return false;
|
|
142
142
|
}
|
|
143
143
|
const rVersion=rAssistant?versionOf(textOf(rAssistant),"R"):nativeRVersion;
|
|
144
|
+
// A stage-02 plan can generate an immutable Rn synchronization SNAPSHOT
|
|
145
|
+
// after its P approval. It is not a new R approval: Context retains the
|
|
146
|
+
// original R/P approvals and exact P.requirementRef. Only a precisely
|
|
147
|
+
// linked notice is exempt from the "new R version" visual alarm.
|
|
148
|
+
const planDerivedSync=text=>{
|
|
149
|
+
const m=text.match(/(?:^|\n)需求文档派生同步[::]\s*(R[1-9][0-9]*)\s*←\s*已批准\s*(P[1-9][0-9]*)[((]保留原批准\s*(R[1-9][0-9]*)[,,]不签发新 R 审批[))]/);
|
|
150
|
+
return Boolean(m&&m[1]!==rVersion&&m[2]===pVersion
|
|
151
|
+
&&m[3]===rVersion
|
|
152
|
+
&&!/(?:REQUIREMENTS_REVIEW|提交需求评审|R[1-9][0-9]*-ISSUE|已撤销|撤销需求|拒绝需求)/i.test(text)
|
|
153
|
+
&&!/(?:^|\n)\s*#{1,6}\s*R[1-9][0-9]*\s+v[1-9][0-9]*/i.test(text));
|
|
154
|
+
};
|
|
144
155
|
const intervening=rows.slice(rIndex+1,lastUser-1);
|
|
145
156
|
const invalidated=intervening.some(x=>{
|
|
146
157
|
const text=textOf(x);
|
|
147
158
|
if(x.role==="assistant"){
|
|
159
|
+
if(/需求文档派生同步/.test(text)&&!planDerivedSync(text))return true;
|
|
148
160
|
const next=versionOf(text,"R");
|
|
149
|
-
return
|
|
161
|
+
return !planDerivedSync(text)&&/需求|范围|验收/.test(text)&&next&&next!==rVersion;
|
|
150
162
|
}
|
|
151
163
|
// Updating a plan while retaining the approved requirement is NOT
|
|
152
164
|
// a requirement revocation.
|
|
153
165
|
// Only an explicit requirement-targeted change invalidates this R.
|
|
166
|
+
const planSyncRequest=(/(?:修改|修订|调整).{0,14}方案.{0,80}(?:同步|更新|改).{0,14}需求/.test(text)
|
|
167
|
+
||/(?:方案|计划|P[1-9][0-9]*).{0,50}(?:同步|更新|修改|调整|改).{0,50}(?:需求|R[1-9][0-9]*)/.test(text))
|
|
168
|
+
&&!/(?:撤销|取消|拒绝|不批准|不同意|不确认)/.test(text);
|
|
169
|
+
if(planSyncRequest)return false;
|
|
154
170
|
return /(?:撤销|取消|拒绝|不同意|不批准|修改|修订|变更)\s*(?:(?:当前|本次|这份|上述)\s*)?(?:需求|R[1-9][0-9]*)/i.test(text)
|
|
155
171
|
|| /\bR[1-9][0-9]*\b\s*(?:需求)?\s*(?:需要|应当|应该)?\s*(?:撤销|取消|拒绝|修改|修订|变更)/i.test(text);
|
|
156
172
|
});
|
|
@@ -174,7 +190,8 @@ if (message?.type === "CHAT_LOOP_APPROVAL_EVIDENCE_V1") {
|
|
|
174
190
|
const text=textOf(x),nextR=versionOf(text,"R"),
|
|
175
191
|
nextP=versionOf(text,"P");
|
|
176
192
|
return Boolean(
|
|
177
|
-
|
|
193
|
+
/需求文档派生同步/.test(text)&&!planDerivedSync(text)
|
|
194
|
+
||!planDerivedSync(text)&&/(?:需求|范围|验收)/.test(text)&&nextR&&nextR!==rVersion
|
|
178
195
|
||/(?:方案|计划)/.test(text)&&nextP&&nextP!==pVersion
|
|
179
196
|
||/(?:SUPERSEDED|已失效|已废弃|已撤销)/i.test(text)
|
|
180
197
|
&&/(?:需求|方案|计划|R[1-9][0-9]*|P[1-9][0-9]*)/i.test(text)
|
package/extension/manifest.json
CHANGED
|
@@ -102,6 +102,49 @@ async function startReadinessEvidence(run){
|
|
|
102
102
|
pageState:tab.url==='https://chatgpt.com/'?'BLANK_HOME':'CHANGED_UNVERIFIED',
|
|
103
103
|
...(result&&typeof result.mainCount==='number'?{readiness:result}:{})};
|
|
104
104
|
}
|
|
105
|
+
// TEST_ONLY is an independent native @ App first-turn, never a managed Owner.
|
|
106
|
+
// A frozen BLOCKED run with a lost Owner tab must not disable ordinary first-
|
|
107
|
+
// turn testing forever. Keep its Native pointer untouched: this read-only
|
|
108
|
+
// gate checks both authorities and denies any live/unknown Owner transition.
|
|
109
|
+
async function entryTestAdmission(message,sender){
|
|
110
|
+
if(!sessionPage(sender,'entry_test',message.requestId))
|
|
111
|
+
return {status:'DENIED',code:'ENTRY_TEST_SOURCE_UNVERIFIED'};
|
|
112
|
+
const disk=await chrome.runtime.sendNativeMessage(SESSION_HOST,
|
|
113
|
+
{op:'session-read'}).catch(()=>null);
|
|
114
|
+
if(disk?.status!=='OK')return {status:'DENIED',code:'ENTRY_TEST_NATIVE_UNVERIFIED'};
|
|
115
|
+
const run=await readRun(),record=disk.session;
|
|
116
|
+
if(!run?.sessionId){
|
|
117
|
+
return !record||record.phase==='DONE'
|
|
118
|
+
?{status:'OK',scope:'TEST_ONLY'}
|
|
119
|
+
:{status:'DENIED',code:'ENTRY_TEST_OWNER_UNVERIFIED'};
|
|
120
|
+
}
|
|
121
|
+
if(!matchesNativeProjection(sessionProjection(run),record))
|
|
122
|
+
return {status:'DENIED',code:'ENTRY_TEST_OWNER_MISMATCH'};
|
|
123
|
+
if(run.phase==='DONE')
|
|
124
|
+
return !run.contextManaged||run.taskId&&terminalFenceVerified(run)
|
|
125
|
+
?{status:'OK',scope:'TEST_ONLY'}
|
|
126
|
+
:{status:'DENIED',code:'ENTRY_TEST_UNFENCED'};
|
|
127
|
+
if(run.phase!=='BLOCKED'||run.contextManaged&&(!run.taskId||!terminalFenceVerified(run))
|
|
128
|
+
||!Number.isSafeInteger(run.tabId)||!pathOf('https://chatgpt.com'+run.page))
|
|
129
|
+
return {status:'DENIED',code:'ENTRY_TEST_ACTIVE_OWNER'};
|
|
130
|
+
// Chrome may reuse the old numeric tab ID. Even a changed tab is not a
|
|
131
|
+
// verified absence. A new tab showing the same Chat is also a live risk.
|
|
132
|
+
if(await chrome.tabs.get(run.tabId).catch(()=>null))
|
|
133
|
+
return {status:'DENIED',code:'ENTRY_TEST_OWNER_TAB_PRESENT'};
|
|
134
|
+
const existing=await chrome.tabs.query({url:'https://chatgpt.com/*'}).catch(()=>null);
|
|
135
|
+
if(!Array.isArray(existing)
|
|
136
|
+
||existing.some(tab=>chatIdOf(tab.url)===chatIdOf('https://chatgpt.com'+run.page)))
|
|
137
|
+
return {status:'DENIED',code:'ENTRY_TEST_OWNER_REOPENED'};
|
|
138
|
+
const again=await readRun();
|
|
139
|
+
const second=await chrome.runtime.sendNativeMessage(SESSION_HOST,
|
|
140
|
+
{op:'session-read'}).catch(()=>null);
|
|
141
|
+
if(!again||JSON.stringify(again)!==JSON.stringify(run)
|
|
142
|
+
||second?.status!=='OK'||!second.session
|
|
143
|
+
||second.session.updatedAt!==record.updatedAt
|
|
144
|
+
||!matchesNativeProjection(sessionProjection(again),second.session))
|
|
145
|
+
return {status:'DENIED',code:'ENTRY_TEST_OWNER_DRIFT'};
|
|
146
|
+
return {status:'OK',scope:'TEST_ONLY',mode:'FROZEN_BLOCKED_NO_OWNER'};
|
|
147
|
+
}
|
|
105
148
|
async function sessionStatus(message,sender){
|
|
106
149
|
if(!sessionPage(sender,'status',message.requestId))
|
|
107
150
|
return {status:'DENIED',code:'INVALID_STATUS_SOURCE'};
|
|
@@ -68,6 +68,7 @@ const SERIAL_ROUTES=new Map([
|
|
|
68
68
|
['CHAT_LOOP_SESSION_START_TAKE_V1',sessionStartTake],
|
|
69
69
|
['CHAT_LOOP_SESSION_START_RESULT_V1',sessionStartResult],
|
|
70
70
|
['CHAT_LOOP_SESSION_STATUS_V1',sessionStatus],
|
|
71
|
+
['CHAT_LOOP_ENTRY_TEST_ADMISSION_V1',entryTestAdmission],
|
|
71
72
|
['CHAT_LOOP_RESOURCE_CHAT_V1',resourceChatGate]
|
|
72
73
|
|
|
73
74
|
]);
|
package/lib/bridge.mjs
CHANGED
|
@@ -51,13 +51,25 @@ export function requestDir(id) {
|
|
|
51
51
|
function validateIntent(action, intent) {
|
|
52
52
|
if(action==='entry_test'){
|
|
53
53
|
if(!intent||typeof intent!=='object'||Array.isArray(intent)
|
|
54
|
-
||Object.keys(intent).some(k=>!['prompt','appId','testOnly','confirmed'].includes(k))
|
|
54
|
+
||Object.keys(intent).some(k=>!['prompt','appId','testOnly','confirmed','recoverTestAt','recoverExactDraft','verifyChatUrl'].includes(k))
|
|
55
55
|
||typeof intent.prompt!=='string'||!intent.prompt.trim()||intent.prompt.length>4000
|
|
56
56
|
||/[\x00-\x08\x0b\x0c\x0e-\x1f]/.test(intent.prompt)
|
|
57
57
|
||typeof intent.appId!=='string'||!/^asdk_app_[a-z0-9]{20,64}$/.test(intent.appId)
|
|
58
|
-
||intent.testOnly!==true||intent.confirmed!==true
|
|
58
|
+
||intent.testOnly!==true||intent.confirmed!==true
|
|
59
|
+
||(intent.verifyChatUrl!==undefined&&(
|
|
60
|
+
typeof intent.verifyChatUrl!=='string'
|
|
61
|
+
||!/^https:\/\/chatgpt\.com\/c\/[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}$/i.test(intent.verifyChatUrl)
|
|
62
|
+
||intent.recoverTestAt!==undefined||intent.recoverExactDraft!==undefined))
|
|
63
|
+
||(intent.recoverTestAt!==undefined&&intent.recoverTestAt!==true)
|
|
64
|
+
||(intent.recoverExactDraft!==undefined
|
|
65
|
+
&&(typeof intent.recoverExactDraft!=='string'
|
|
66
|
+
||!intent.recoverExactDraft.trim()
|
|
67
|
+
||intent.recoverExactDraft.length>4000)))
|
|
59
68
|
throw Object.assign(Error('Explicit test-only entry intent required'),{code:'INVALID_ENTRY_TEST_INTENT'});
|
|
60
|
-
return {prompt:intent.prompt,appId:intent.appId,testOnly:true,confirmed:true
|
|
69
|
+
return {prompt:intent.prompt,appId:intent.appId,testOnly:true,confirmed:true,
|
|
70
|
+
...(intent.recoverTestAt?{recoverTestAt:true}:{}),
|
|
71
|
+
...(intent.recoverExactDraft?{recoverExactDraft:intent.recoverExactDraft}:{}),
|
|
72
|
+
...(intent.verifyChatUrl?{verifyChatUrl:intent.verifyChatUrl}:{})};
|
|
61
73
|
}
|
|
62
74
|
if(action==='start'){
|
|
63
75
|
if(!intent||typeof intent!=='object'||Array.isArray(intent)
|