@tomflow/chatloop-tools 0.9.17 → 0.9.18
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/package.json +3 -11
- package/providers/form.mjs +4 -2
- package/ui/form/review-app.js +122 -71
- package/ui/form/review.html +1 -814
- 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 -182
- package/node_modules/@tomflow/chatloop-context/docs/operator-and-migration.md +0 -277
- package/node_modules/@tomflow/chatloop-context/index.mjs +0 -233
- package/node_modules/@tomflow/chatloop-context/lib/api-log.mjs +0 -86
- package/node_modules/@tomflow/chatloop-context/lib/approval-policy.mjs +0 -24
- package/node_modules/@tomflow/chatloop-context/lib/capability-catalog.generated.json +0 -1989
- package/node_modules/@tomflow/chatloop-context/lib/capability-router.mjs +0 -67
- package/node_modules/@tomflow/chatloop-context/lib/cli-commands.mjs +0 -280
- package/node_modules/@tomflow/chatloop-context/lib/context-cli.mjs +0 -298
- package/node_modules/@tomflow/chatloop-context/lib/context-migration.mjs +0 -280
- 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 -55
- 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.mjs +0 -343
- package/node_modules/@tomflow/chatloop-context/lib/core/store.mjs +0 -391
- package/node_modules/@tomflow/chatloop-context/lib/core/task.mjs +0 -166
- 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 -117
- package/node_modules/@tomflow/chatloop-context/lib/process-inventory.mjs +0 -20
- package/node_modules/@tomflow/chatloop-context/lib/project-branch.mjs +0 -312
- 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 -115
- package/node_modules/@tomflow/chatloop-context/lib/trusted-run.mjs +0 -86
- 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 -94
- package/node_modules/@tomflow/chatloop-extension/actions.generated.mjs +0 -11
- package/node_modules/@tomflow/chatloop-extension/bin/cli.mjs +0 -141
- package/node_modules/@tomflow/chatloop-extension/bin/native-host.mjs +0 -109
- 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/handoff.mjs +0 -1
- package/node_modules/@tomflow/chatloop-extension/capabilities/reload.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 -120
- package/node_modules/@tomflow/chatloop-extension/extension/actions/common.js +0 -180
- package/node_modules/@tomflow/chatloop-extension/extension/actions/continue.js +0 -322
- package/node_modules/@tomflow/chatloop-extension/extension/actions/dom.js +0 -2
- package/node_modules/@tomflow/chatloop-extension/extension/actions/handoff.js +0 -378
- package/node_modules/@tomflow/chatloop-extension/extension/actions/index.js +0 -2
- package/node_modules/@tomflow/chatloop-extension/extension/actions/model-intent.js +0 -54
- 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 -69
- package/node_modules/@tomflow/chatloop-extension/extension/actions/start.js +0 -287
- package/node_modules/@tomflow/chatloop-extension/extension/actions/status.js +0 -23
- package/node_modules/@tomflow/chatloop-extension/extension/actions/text.js +0 -2
- package/node_modules/@tomflow/chatloop-extension/extension/background.js +0 -16
- 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/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 -76
- 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 -227
- 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 -254
- 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 -93
- 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/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 -220
- package/node_modules/@tomflow/chatloop-extension/extension/worker/admission.js +0 -122
- package/node_modules/@tomflow/chatloop-extension/extension/worker/adopt-prepare.js +0 -155
- package/node_modules/@tomflow/chatloop-extension/extension/worker/adopt-recovery.js +0 -185
- package/node_modules/@tomflow/chatloop-extension/extension/worker/adopt-result.js +0 -120
- package/node_modules/@tomflow/chatloop-extension/extension/worker/bootstrap.js +0 -172
- package/node_modules/@tomflow/chatloop-extension/extension/worker/manual.js +0 -165
- package/node_modules/@tomflow/chatloop-extension/extension/worker/readiness.js +0 -244
- package/node_modules/@tomflow/chatloop-extension/extension/worker/router.js +0 -181
- package/node_modules/@tomflow/chatloop-extension/extension/worker/scheduler.js +0 -147
- 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 -200
- package/node_modules/@tomflow/chatloop-extension/index.mjs +0 -71
- package/node_modules/@tomflow/chatloop-extension/lib/action-routing.mjs +0 -18
- package/node_modules/@tomflow/chatloop-extension/lib/api-observation-queue.mjs +0 -74
- package/node_modules/@tomflow/chatloop-extension/lib/bridge.mjs +0 -208
- package/node_modules/@tomflow/chatloop-extension/lib/browser-launch.mjs +0 -40
- package/node_modules/@tomflow/chatloop-extension/lib/context-binding.mjs +0 -45
- package/node_modules/@tomflow/chatloop-extension/lib/context-ipc.mjs +0 -111
- package/node_modules/@tomflow/chatloop-extension/lib/owner-evidence.mjs +0 -67
- package/node_modules/@tomflow/chatloop-extension/lib/session-file.mjs +0 -120
- package/node_modules/@tomflow/chatloop-extension/package.json +0 -38
- package/node_modules/@tomflow/chatloop-extension/scripts/build-actions.mjs +0 -133
- package/node_modules/@tomflow/chatloop-trace/README.md +0 -105
- 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 -265
- package/node_modules/@tomflow/chatloop-trace/lib/trace.mjs +0 -205
- 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
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "0.9.
|
|
6
|
+
"version": "0.9.18",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"description": "Chat Loop local tools: MCP gateway, isolated bundled tunnel-client and unified CLI",
|
|
9
9
|
"bin": {
|
|
@@ -33,9 +33,7 @@
|
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@tomflow/chatloop-context": "0.6.11",
|
|
35
35
|
"@tomflow/chatloop-trace": "0.4.4",
|
|
36
|
-
"@wonderwhy-er/desktop-commander": "0.2.44"
|
|
37
|
-
"ps-list": "9.0.0",
|
|
38
|
-
"@tomflow/chatloop-extension": "0.4.11"
|
|
36
|
+
"@wonderwhy-er/desktop-commander": "0.2.44"
|
|
39
37
|
},
|
|
40
38
|
"engines": {
|
|
41
39
|
"node": ">=24"
|
|
@@ -50,11 +48,5 @@
|
|
|
50
48
|
"devDependencies": {
|
|
51
49
|
"@modelcontextprotocol/ext-apps": "1.7.5",
|
|
52
50
|
"esbuild": "0.28.2"
|
|
53
|
-
}
|
|
54
|
-
"bundleDependencies": [
|
|
55
|
-
"@tomflow/chatloop-context",
|
|
56
|
-
"@tomflow/chatloop-trace",
|
|
57
|
-
"ps-list",
|
|
58
|
-
"@tomflow/chatloop-extension"
|
|
59
|
-
]
|
|
51
|
+
}
|
|
60
52
|
}
|
package/providers/form.mjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Form IDs identify interactions; Context Issue IDs own R/P decisions.
|
|
3
3
|
import {randomUUID} from 'node:crypto';
|
|
4
4
|
import {readFileSync} from 'node:fs';
|
|
5
|
-
const RESOURCE_URI='ui://chat-loop/form/review-
|
|
5
|
+
const RESOURCE_URI='ui://chat-loop/form/review-v2';
|
|
6
6
|
const RESOURCE_MIME='text/html;profile=mcp-app';
|
|
7
7
|
const ID=/^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/;
|
|
8
8
|
const FORM_ID=/^[A-Za-z0-9_-]{8,80}$/;
|
|
@@ -230,7 +230,9 @@ export const provider=Object.freeze({
|
|
|
230
230
|
async readResource(uri){
|
|
231
231
|
if(uri!==RESOURCE_URI)throw fail('MCP_RESOURCE_NOT_FOUND');
|
|
232
232
|
return {contents:[{uri,mimeType:RESOURCE_MIME,
|
|
233
|
-
text:readFileSync(new URL('../ui/form/review.html',import.meta.url),'utf8')
|
|
233
|
+
text:readFileSync(new URL('../ui/form/review.html',import.meta.url),'utf8'),
|
|
234
|
+
_meta:{'openai/ui':{availableDisplayModes:['inline'],
|
|
235
|
+
preferredDisplayMode:'inline'}}}]};
|
|
234
236
|
},
|
|
235
237
|
async call(name,args){
|
|
236
238
|
try{
|
package/ui/form/review-app.js
CHANGED
|
@@ -1,16 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
//
|
|
4
|
-
// Only TEST_ONLY/GENERAL submits are enabled until real user Turn proof exists.
|
|
5
|
-
const app=new App({name:'Chat Loop Review',version:'1.0.0'});
|
|
1
|
+
// Minimal MCP Apps View bridge: JSON-RPC over postMessage, no bundled runtime.
|
|
2
|
+
// Protocol: https://modelcontextprotocol.io/extensions/apps
|
|
3
|
+
// GENERAL/TEST_ONLY only; MANAGED approval remains Context + real user Turn.
|
|
6
4
|
const $=id=>document.getElementById(id);
|
|
7
|
-
const
|
|
8
|
-
let prepared=null,toolInput=null,locked=false;
|
|
5
|
+
const options=[...document.querySelectorAll('input[name="choice"]')];
|
|
9
6
|
const idPattern=/^[A-Za-z0-9_-]{8,80}$/;
|
|
7
|
+
const requests=new Map();
|
|
8
|
+
let seq=0,connected=false,prepared=null,locked=false,toolResult=null;
|
|
10
9
|
function status(message,state='info'){
|
|
11
10
|
$('status').textContent=message;
|
|
12
11
|
$('status').dataset.state=state;
|
|
13
12
|
}
|
|
13
|
+
function send(message){window.parent.postMessage({jsonrpc:'2.0',...message},'*')}
|
|
14
|
+
function notify(method,params={}){send({method,params})}
|
|
15
|
+
function call(method,params){
|
|
16
|
+
if(!connected)throw Error('FORM_APP_NOT_INITIALIZED');
|
|
17
|
+
return new Promise((resolve,reject)=>{
|
|
18
|
+
const id=++seq;
|
|
19
|
+
// A timeout never authorizes a retry of a write.
|
|
20
|
+
const timer=setTimeout(()=>{
|
|
21
|
+
requests.delete(id);reject(Error('FORM_APP_REPLY_UNKNOWN'));
|
|
22
|
+
},30000);
|
|
23
|
+
requests.set(id,{resolve,reject,timer});
|
|
24
|
+
send({id,method,params});
|
|
25
|
+
});
|
|
26
|
+
}
|
|
14
27
|
function decode(result){
|
|
15
28
|
if(result?.isError)throw Error('FORM_TOOL_REJECTED');
|
|
16
29
|
if(result?.structuredContent?.status)return result.structuredContent;
|
|
@@ -18,13 +31,13 @@ function decode(result){
|
|
|
18
31
|
if(typeof text!=='string'||text.length>20000)throw Error('FORM_RECEIPT_MISSING');
|
|
19
32
|
return JSON.parse(text);
|
|
20
33
|
}
|
|
21
|
-
|
|
34
|
+
const selected=()=>options.find(x=>x.checked)?.value||null;
|
|
22
35
|
function update(){
|
|
23
36
|
const choice=selected();
|
|
24
37
|
$('modify').hidden=choice!=='B';
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
38
|
+
$('submit').disabled=!prepared||locked||!choice
|
|
39
|
+
||(choice==='B'&&!$('comment').value.trim());
|
|
40
|
+
resize();
|
|
28
41
|
}
|
|
29
42
|
function render(value){
|
|
30
43
|
const view=value?.view;
|
|
@@ -32,10 +45,10 @@ function render(value){
|
|
|
32
45
|
||!idPattern.test(value.formId||'')
|
|
33
46
|
||view.formId!==value.formId
|
|
34
47
|
||!['GENERAL','TEST_ONLY','MANAGED'].includes(view.mode)
|
|
35
|
-
||view.options?.length!==2
|
|
36
|
-
||view.options[1]?.value!=='B')
|
|
48
|
+
||view.options?.length!==2
|
|
49
|
+
||view.options[0]?.value!=='A'||view.options[1]?.value!=='B')
|
|
37
50
|
throw Error('FORM_VIEW_INVALID');
|
|
38
|
-
const
|
|
51
|
+
const safe=view.mode==='GENERAL'||view.mode==='TEST_ONLY';
|
|
39
52
|
prepared={...value,mode:view.mode};
|
|
40
53
|
$('title').textContent=view.title;
|
|
41
54
|
$('description').textContent=view.description;
|
|
@@ -44,85 +57,123 @@ function render(value){
|
|
|
44
57
|
$('comment').placeholder=view.modifyField?.placeholder||'填写修改意见';
|
|
45
58
|
$('submit').textContent=view.submit?.label||'提交';
|
|
46
59
|
$('footer').textContent=view.footer||'';
|
|
47
|
-
$('options').disabled=!
|
|
48
|
-
radios.forEach(x=>{x.checked=false});
|
|
60
|
+
$('options').disabled=!safe;
|
|
49
61
|
$('comment').value='';
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
62
|
+
options.forEach(x=>x.checked=false);
|
|
63
|
+
locked=!safe;
|
|
64
|
+
status(safe?'已连接 Form prepare;请选择 A 或 B。':
|
|
65
|
+
'正式审批需要真实用户消息身份,组件不得代签。',safe?'ok':'error');
|
|
53
66
|
update();
|
|
54
67
|
}
|
|
55
|
-
|
|
56
|
-
if(
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
68
|
+
function receive(event){
|
|
69
|
+
if(event.source!==window.parent)return;
|
|
70
|
+
const message=event.data;
|
|
71
|
+
if(!message||message.jsonrpc!=='2.0'||typeof message!=='object')return;
|
|
72
|
+
if(Object.hasOwn(message,'id')&&!Object.hasOwn(message,'method')){
|
|
73
|
+
const request=requests.get(message.id);
|
|
74
|
+
if(!request)return;
|
|
75
|
+
requests.delete(message.id);clearTimeout(request.timer);
|
|
76
|
+
if(message.error)request.reject(Error('MCP_APP_HOST_REJECTED'));
|
|
77
|
+
else request.resolve(message.result);
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
if(message.method==='ui/notifications/tool-result'){
|
|
81
|
+
toolResult=message.params;
|
|
82
|
+
try{render(decode(toolResult))}
|
|
83
|
+
catch{status('Form prepare 回执无效,禁止提交。','error')}
|
|
84
|
+
}
|
|
85
|
+
if(message.method==='ui/resource-teardown'&&message.id!==undefined)
|
|
86
|
+
send({id:message.id,result:{}});
|
|
87
|
+
}
|
|
88
|
+
let lastHeight=0,lastWidth=0;
|
|
89
|
+
function resize(){
|
|
90
|
+
if(!connected)return;
|
|
91
|
+
const height=Math.ceil(document.documentElement.scrollHeight);
|
|
92
|
+
const width=Math.ceil(document.documentElement.clientWidth);
|
|
93
|
+
if(height===lastHeight&&width===lastWidth)return;
|
|
94
|
+
lastHeight=height;lastWidth=width;
|
|
95
|
+
notify('ui/notifications/size-changed',{width,height});
|
|
96
|
+
}
|
|
97
|
+
async function initialize(){
|
|
98
|
+
if(window.parent===window){
|
|
99
|
+
status('未在 ChatGPT MCP App iframe 中运行,禁止提交。','error');
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
const id=++seq;
|
|
103
|
+
const init=new Promise((resolve,reject)=>{
|
|
104
|
+
const timer=setTimeout(()=>{
|
|
105
|
+
requests.delete(id);reject(Error('FORM_APP_INIT_TIMEOUT'));
|
|
106
|
+
},12000);
|
|
107
|
+
requests.set(id,{resolve,reject,timer});
|
|
108
|
+
send({id,method:'ui/initialize',params:{
|
|
109
|
+
appInfo:{name:'Chat Loop Review',version:'1.0.1'},
|
|
110
|
+
appCapabilities:{},
|
|
111
|
+
protocolVersion:'2026-01-26'
|
|
112
|
+
}});
|
|
113
|
+
});
|
|
60
114
|
try{
|
|
61
|
-
const
|
|
62
|
-
if(
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
115
|
+
const response=await init;
|
|
116
|
+
if(!response?.protocolVersion||!response.hostInfo)
|
|
117
|
+
throw Error('FORM_APP_INIT_INVALID');
|
|
118
|
+
connected=true;
|
|
119
|
+
notify('ui/notifications/initialized',{});
|
|
120
|
+
resize();
|
|
121
|
+
if(toolResult)render(decode(toolResult));
|
|
122
|
+
if(typeof ResizeObserver==='function')
|
|
123
|
+
new ResizeObserver(resize).observe(document.documentElement);
|
|
124
|
+
}catch{
|
|
125
|
+
status('MCP App 初始化失败,请核查 ChatGPT 宿主连接。','error');
|
|
126
|
+
}
|
|
127
|
+
}
|
|
67
128
|
async function submit(){
|
|
68
|
-
if(locked||!prepared
|
|
69
|
-
|
|
70
|
-
const comment=$('comment').value.trim();
|
|
129
|
+
if(!connected||locked||!prepared
|
|
130
|
+
||!['GENERAL','TEST_ONLY'].includes(prepared.mode))return;
|
|
131
|
+
const choice=selected(),comment=$('comment').value.trim();
|
|
71
132
|
if(!['A','B'].includes(choice)||choice==='B'&&!comment)return;
|
|
72
|
-
// Freeze the unique request before any asynchronous host call.
|
|
73
133
|
locked=true;update();
|
|
74
|
-
const formId=prepared
|
|
75
|
-
const
|
|
76
|
-
const scope={mode,formId,choice,kind:prepared.kind,
|
|
134
|
+
const {formId,mode}=prepared,writeRequestId=crypto.randomUUID();
|
|
135
|
+
const args={mode,formId,choice,kind:prepared.kind,
|
|
77
136
|
...(choice==='B'?{comment}:{}),
|
|
78
|
-
userTurn:'unverified-app-'+
|
|
137
|
+
userTurn:'unverified-app-'+writeRequestId,
|
|
79
138
|
presentedAssistantRef:'app-form-'+formId,
|
|
80
|
-
writeRequestId
|
|
139
|
+
writeRequestId,
|
|
81
140
|
...(mode==='TEST_ONLY'?{
|
|
82
|
-
projectId:prepared.projectId,
|
|
83
|
-
|
|
84
|
-
kind:prepared.kind,
|
|
85
|
-
documentId:prepared.documentId,
|
|
86
|
-
version:prepared.version
|
|
141
|
+
projectId:prepared.projectId,chatRef:prepared.chatRef,
|
|
142
|
+
documentId:prepared.documentId,version:prepared.version
|
|
87
143
|
}:{})};
|
|
88
|
-
status('正在向 Form submit
|
|
144
|
+
status('正在向 Form submit 提交唯一请求…');
|
|
89
145
|
let receipt;
|
|
90
|
-
try{
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
status('Form submit 结果未知。为防止重复提交,表单已锁定;请查原请求回执。','error');
|
|
146
|
+
try{receipt=decode(await call('tools/call',{
|
|
147
|
+
name:'chat_loop_form__submit',arguments:args
|
|
148
|
+
}))}
|
|
149
|
+
catch{
|
|
150
|
+
status('Submit 结果未知,禁止重复提交;请查原请求回执。','error');
|
|
96
151
|
return;
|
|
97
152
|
}
|
|
98
153
|
if(receipt.status!=='FORM_SUBMISSION_OBSERVED_SOFT'
|
|
99
154
|
||receipt.formId!==formId||receipt.choice!==choice
|
|
100
155
|
||receipt.preparedFormIdVerified!==true){
|
|
101
|
-
status('
|
|
156
|
+
status('Submit 未验证绑定,用户消息未发送。','error');
|
|
102
157
|
return;
|
|
103
158
|
}
|
|
104
159
|
const version=prepared.documentId
|
|
105
|
-
?prepared.documentId+' v'+prepared.version
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
+
|
|
109
|
-
+'
|
|
110
|
-
|
|
111
|
-
status('Form submit 软回执已收到,正在请求宿主发送一次用户消息…');
|
|
160
|
+
?prepared.documentId+' v'+prepared.version:'自定义表单';
|
|
161
|
+
const text='【Chat Loop Form|'+mode+'】formId='+formId+'|'+version+'|'
|
|
162
|
+
+(choice==='A'?'A 确认':'B 修改:'+comment)
|
|
163
|
+
+'。组件请求发送,用户消息身份须独立核对。'
|
|
164
|
+
+(mode==='TEST_ONLY'?'不构成正式审批,不 Start/Continue/Handoff。':'');
|
|
165
|
+
status('Submit 软回执成功,正在申请单次用户消息…');
|
|
112
166
|
try{
|
|
113
|
-
const
|
|
114
|
-
role:'user',content:[{type:'text',text
|
|
167
|
+
const result=await call('ui/message',{
|
|
168
|
+
role:'user',content:[{type:'text',text}]
|
|
115
169
|
});
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
status('宿主已接受一次消息请求;实际 userMessageId 与日志关联仍需独立核验。','ok');
|
|
121
|
-
}catch{
|
|
122
|
-
status('宿主消息回执未知,禁止重复发送。Form 仅有软提交记录。','error');
|
|
123
|
-
}
|
|
170
|
+
status(result?.isError?'宿主拒绝消息;未完成正式审批。':
|
|
171
|
+
'宿主接受消息请求;userMessageId 仍需独立核验。',
|
|
172
|
+
result?.isError?'error':'ok');
|
|
173
|
+
}catch{status('宿主消息状态未知,禁止重复发送。','error')}
|
|
124
174
|
}
|
|
125
|
-
|
|
175
|
+
window.addEventListener('message',receive);
|
|
176
|
+
options.forEach(x=>x.addEventListener('change',update));
|
|
126
177
|
$('comment').addEventListener('input',update);
|
|
127
178
|
$('submit').addEventListener('click',submit);
|
|
128
|
-
|
|
179
|
+
void initialize();
|