@tomflow/chatloop-tools 0.9.17 → 0.9.19

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.
Files changed (140) hide show
  1. package/package.json +3 -11
  2. package/providers/form.mjs +13 -5
  3. package/ui/form/review-app.js +122 -71
  4. package/ui/form/review.html +1 -814
  5. package/node_modules/@tomflow/chatloop-context/README.md +0 -240
  6. package/node_modules/@tomflow/chatloop-context/bin/cli.mjs +0 -48
  7. package/node_modules/@tomflow/chatloop-context/capabilities/approval.mjs +0 -151
  8. package/node_modules/@tomflow/chatloop-context/capabilities/context.mjs +0 -376
  9. package/node_modules/@tomflow/chatloop-context/capabilities/document.mjs +0 -266
  10. package/node_modules/@tomflow/chatloop-context/capabilities/evidence.mjs +0 -134
  11. package/node_modules/@tomflow/chatloop-context/capabilities/presentation.mjs +0 -82
  12. package/node_modules/@tomflow/chatloop-context/capabilities/project.mjs +0 -349
  13. package/node_modules/@tomflow/chatloop-context/capabilities/sdk.mjs +0 -72
  14. package/node_modules/@tomflow/chatloop-context/capabilities/start.mjs +0 -73
  15. package/node_modules/@tomflow/chatloop-context/capabilities/task.mjs +0 -507
  16. package/node_modules/@tomflow/chatloop-context/capabilities.generated.mjs +0 -11
  17. package/node_modules/@tomflow/chatloop-context/docs/interfaces.md +0 -182
  18. package/node_modules/@tomflow/chatloop-context/docs/operator-and-migration.md +0 -277
  19. package/node_modules/@tomflow/chatloop-context/index.mjs +0 -233
  20. package/node_modules/@tomflow/chatloop-context/lib/api-log.mjs +0 -86
  21. package/node_modules/@tomflow/chatloop-context/lib/approval-policy.mjs +0 -24
  22. package/node_modules/@tomflow/chatloop-context/lib/capability-catalog.generated.json +0 -1989
  23. package/node_modules/@tomflow/chatloop-context/lib/capability-router.mjs +0 -67
  24. package/node_modules/@tomflow/chatloop-context/lib/cli-commands.mjs +0 -280
  25. package/node_modules/@tomflow/chatloop-context/lib/context-cli.mjs +0 -298
  26. package/node_modules/@tomflow/chatloop-context/lib/context-migration.mjs +0 -280
  27. package/node_modules/@tomflow/chatloop-context/lib/core/context.mjs +0 -115
  28. package/node_modules/@tomflow/chatloop-context/lib/core/evidence.mjs +0 -51
  29. package/node_modules/@tomflow/chatloop-context/lib/core/health.mjs +0 -55
  30. package/node_modules/@tomflow/chatloop-context/lib/core/migration.mjs +0 -262
  31. package/node_modules/@tomflow/chatloop-context/lib/core/project.mjs +0 -246
  32. package/node_modules/@tomflow/chatloop-context/lib/core/review.mjs +0 -147
  33. package/node_modules/@tomflow/chatloop-context/lib/core/run.mjs +0 -343
  34. package/node_modules/@tomflow/chatloop-context/lib/core/store.mjs +0 -391
  35. package/node_modules/@tomflow/chatloop-context/lib/core/task.mjs +0 -166
  36. package/node_modules/@tomflow/chatloop-context/lib/line-review.mjs +0 -13
  37. package/node_modules/@tomflow/chatloop-context/lib/methods.mjs +0 -111
  38. package/node_modules/@tomflow/chatloop-context/lib/operations.mjs +0 -107
  39. package/node_modules/@tomflow/chatloop-context/lib/orphan-operator.mjs +0 -117
  40. package/node_modules/@tomflow/chatloop-context/lib/process-inventory.mjs +0 -20
  41. package/node_modules/@tomflow/chatloop-context/lib/project-branch.mjs +0 -312
  42. package/node_modules/@tomflow/chatloop-context/lib/project-diagnostic.mjs +0 -153
  43. package/node_modules/@tomflow/chatloop-context/lib/project-guards.mjs +0 -19
  44. package/node_modules/@tomflow/chatloop-context/lib/project-store.mjs +0 -115
  45. package/node_modules/@tomflow/chatloop-context/lib/trusted-run.mjs +0 -86
  46. package/node_modules/@tomflow/chatloop-context/lib/workspace-operator.mjs +0 -169
  47. package/node_modules/@tomflow/chatloop-context/package.json +0 -40
  48. package/node_modules/@tomflow/chatloop-context/scripts/build-capabilities.mjs +0 -114
  49. package/node_modules/@tomflow/chatloop-extension/README.md +0 -94
  50. package/node_modules/@tomflow/chatloop-extension/actions.generated.mjs +0 -11
  51. package/node_modules/@tomflow/chatloop-extension/bin/cli.mjs +0 -141
  52. package/node_modules/@tomflow/chatloop-extension/bin/native-host.mjs +0 -109
  53. package/node_modules/@tomflow/chatloop-extension/capabilities/chat_dom.mjs +0 -1
  54. package/node_modules/@tomflow/chatloop-extension/capabilities/chat_screenshot.mjs +0 -1
  55. package/node_modules/@tomflow/chatloop-extension/capabilities/chat_text.mjs +0 -1
  56. package/node_modules/@tomflow/chatloop-extension/capabilities/clean.mjs +0 -1
  57. package/node_modules/@tomflow/chatloop-extension/capabilities/continue.mjs +0 -1
  58. package/node_modules/@tomflow/chatloop-extension/capabilities/handoff.mjs +0 -1
  59. package/node_modules/@tomflow/chatloop-extension/capabilities/reload.mjs +0 -1
  60. package/node_modules/@tomflow/chatloop-extension/capabilities/start.mjs +0 -1
  61. package/node_modules/@tomflow/chatloop-extension/capabilities/status.mjs +0 -1
  62. package/node_modules/@tomflow/chatloop-extension/extension/actions/clean.js +0 -120
  63. package/node_modules/@tomflow/chatloop-extension/extension/actions/common.js +0 -180
  64. package/node_modules/@tomflow/chatloop-extension/extension/actions/continue.js +0 -322
  65. package/node_modules/@tomflow/chatloop-extension/extension/actions/dom.js +0 -2
  66. package/node_modules/@tomflow/chatloop-extension/extension/actions/handoff.js +0 -378
  67. package/node_modules/@tomflow/chatloop-extension/extension/actions/index.js +0 -2
  68. package/node_modules/@tomflow/chatloop-extension/extension/actions/model-intent.js +0 -54
  69. package/node_modules/@tomflow/chatloop-extension/extension/actions/read-mode.js +0 -9
  70. package/node_modules/@tomflow/chatloop-extension/extension/actions/reload.js +0 -20
  71. package/node_modules/@tomflow/chatloop-extension/extension/actions/screenshot.js +0 -69
  72. package/node_modules/@tomflow/chatloop-extension/extension/actions/start.js +0 -287
  73. package/node_modules/@tomflow/chatloop-extension/extension/actions/status.js +0 -23
  74. package/node_modules/@tomflow/chatloop-extension/extension/actions/text.js +0 -2
  75. package/node_modules/@tomflow/chatloop-extension/extension/background.js +0 -16
  76. package/node_modules/@tomflow/chatloop-extension/extension/clean.html +0 -5
  77. package/node_modules/@tomflow/chatloop-extension/extension/content.js +0 -40
  78. package/node_modules/@tomflow/chatloop-extension/extension/continue.html +0 -9
  79. package/node_modules/@tomflow/chatloop-extension/extension/dom.html +0 -17
  80. package/node_modules/@tomflow/chatloop-extension/extension/handoff.html +0 -9
  81. package/node_modules/@tomflow/chatloop-extension/extension/loop/action-catalog.generated.js +0 -2
  82. package/node_modules/@tomflow/chatloop-extension/extension/loop/api-aspect.generated.js +0 -275
  83. package/node_modules/@tomflow/chatloop-extension/extension/loop/api-observation-queue.generated.js +0 -76
  84. package/node_modules/@tomflow/chatloop-extension/extension/loop/core.js +0 -107
  85. package/node_modules/@tomflow/chatloop-extension/extension/loop/index.js +0 -36
  86. package/node_modules/@tomflow/chatloop-extension/extension/loop/observer-approval.js +0 -227
  87. package/node_modules/@tomflow/chatloop-extension/extension/loop/observer-inspect.js +0 -144
  88. package/node_modules/@tomflow/chatloop-extension/extension/loop/observer-poll.js +0 -171
  89. package/node_modules/@tomflow/chatloop-extension/extension/loop/observer-recovery.js +0 -109
  90. package/node_modules/@tomflow/chatloop-extension/extension/loop/observer.js +0 -154
  91. package/node_modules/@tomflow/chatloop-extension/extension/loop/resources.js +0 -254
  92. package/node_modules/@tomflow/chatloop-extension/extension/manifest.json +0 -42
  93. package/node_modules/@tomflow/chatloop-extension/extension/popup.html +0 -25
  94. package/node_modules/@tomflow/chatloop-extension/extension/popup.js +0 -93
  95. package/node_modules/@tomflow/chatloop-extension/extension/reload.html +0 -17
  96. package/node_modules/@tomflow/chatloop-extension/extension/screenshot.html +0 -17
  97. package/node_modules/@tomflow/chatloop-extension/extension/start.html +0 -6
  98. package/node_modules/@tomflow/chatloop-extension/extension/status.html +0 -6
  99. package/node_modules/@tomflow/chatloop-extension/extension/text.html +0 -17
  100. package/node_modules/@tomflow/chatloop-extension/extension/worker/action-result.js +0 -136
  101. package/node_modules/@tomflow/chatloop-extension/extension/worker/action-take.js +0 -220
  102. package/node_modules/@tomflow/chatloop-extension/extension/worker/admission.js +0 -122
  103. package/node_modules/@tomflow/chatloop-extension/extension/worker/adopt-prepare.js +0 -155
  104. package/node_modules/@tomflow/chatloop-extension/extension/worker/adopt-recovery.js +0 -185
  105. package/node_modules/@tomflow/chatloop-extension/extension/worker/adopt-result.js +0 -120
  106. package/node_modules/@tomflow/chatloop-extension/extension/worker/bootstrap.js +0 -172
  107. package/node_modules/@tomflow/chatloop-extension/extension/worker/manual.js +0 -165
  108. package/node_modules/@tomflow/chatloop-extension/extension/worker/readiness.js +0 -244
  109. package/node_modules/@tomflow/chatloop-extension/extension/worker/router.js +0 -181
  110. package/node_modules/@tomflow/chatloop-extension/extension/worker/scheduler.js +0 -147
  111. package/node_modules/@tomflow/chatloop-extension/extension/worker/turn-failure.js +0 -197
  112. package/node_modules/@tomflow/chatloop-extension/extension/worker/turn-finished.js +0 -200
  113. package/node_modules/@tomflow/chatloop-extension/index.mjs +0 -71
  114. package/node_modules/@tomflow/chatloop-extension/lib/action-routing.mjs +0 -18
  115. package/node_modules/@tomflow/chatloop-extension/lib/api-observation-queue.mjs +0 -74
  116. package/node_modules/@tomflow/chatloop-extension/lib/bridge.mjs +0 -208
  117. package/node_modules/@tomflow/chatloop-extension/lib/browser-launch.mjs +0 -40
  118. package/node_modules/@tomflow/chatloop-extension/lib/context-binding.mjs +0 -45
  119. package/node_modules/@tomflow/chatloop-extension/lib/context-ipc.mjs +0 -111
  120. package/node_modules/@tomflow/chatloop-extension/lib/owner-evidence.mjs +0 -67
  121. package/node_modules/@tomflow/chatloop-extension/lib/session-file.mjs +0 -120
  122. package/node_modules/@tomflow/chatloop-extension/package.json +0 -38
  123. package/node_modules/@tomflow/chatloop-extension/scripts/build-actions.mjs +0 -133
  124. package/node_modules/@tomflow/chatloop-trace/README.md +0 -105
  125. package/node_modules/@tomflow/chatloop-trace/events/context.api.mjs +0 -23
  126. package/node_modules/@tomflow/chatloop-trace/events/typed.api.call.mjs +0 -22
  127. package/node_modules/@tomflow/chatloop-trace/events.generated.mjs +0 -4
  128. package/node_modules/@tomflow/chatloop-trace/index.mjs +0 -59
  129. package/node_modules/@tomflow/chatloop-trace/lib/api-aspect.mjs +0 -273
  130. package/node_modules/@tomflow/chatloop-trace/lib/trace-reader.mjs +0 -265
  131. package/node_modules/@tomflow/chatloop-trace/lib/trace.mjs +0 -205
  132. package/node_modules/@tomflow/chatloop-trace/package.json +0 -30
  133. package/node_modules/@tomflow/chatloop-trace/scripts/build-events.mjs +0 -68
  134. package/node_modules/ps-list/index.d.ts +0 -76
  135. package/node_modules/ps-list/index.js +0 -366
  136. package/node_modules/ps-list/license +0 -9
  137. package/node_modules/ps-list/package.json +0 -44
  138. package/node_modules/ps-list/readme.md +0 -56
  139. package/node_modules/ps-list/vendor/fastlist-0.3.0-x64.exe +0 -0
  140. 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.17",
6
+ "version": "0.9.19",
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
  }
@@ -2,7 +2,10 @@
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-v1';
5
+ const RESOURCE_URI='ui://chat-loop/form/review-v2';
6
+ // Previously rendered chat messages still reference v1 after an upgrade.
7
+ // Preserve their resource locator; both URIs serve the same audited UI.
8
+ const LEGACY_RESOURCE_URI='ui://chat-loop/form/review-v1';
6
9
  const RESOURCE_MIME='text/html;profile=mcp-app';
7
10
  const ID=/^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/;
8
11
  const FORM_ID=/^[A-Za-z0-9_-]{8,80}$/;
@@ -225,12 +228,17 @@ export const provider=Object.freeze({
225
228
  };
226
229
  return Object.freeze({
227
230
  tools:()=>tools,
228
- resources:()=>[{uri:RESOURCE_URI,name:'Chat Loop Review',
229
- mimeType:RESOURCE_MIME,description:'A/B review with one locked submit'}],
231
+ resources:()=>[RESOURCE_URI,LEGACY_RESOURCE_URI].map(uri=>({
232
+ uri,name:'Chat Loop Review',mimeType:RESOURCE_MIME,
233
+ description:'A/B review with one locked submit'
234
+ })),
230
235
  async readResource(uri){
231
- if(uri!==RESOURCE_URI)throw fail('MCP_RESOURCE_NOT_FOUND');
236
+ if(uri!==RESOURCE_URI&&uri!==LEGACY_RESOURCE_URI)
237
+ throw fail('MCP_RESOURCE_NOT_FOUND');
232
238
  return {contents:[{uri,mimeType:RESOURCE_MIME,
233
- text:readFileSync(new URL('../ui/form/review.html',import.meta.url),'utf8')}]};
239
+ text:readFileSync(new URL('../ui/form/review.html',import.meta.url),'utf8'),
240
+ _meta:{'openai/ui':{availableDisplayModes:['inline'],
241
+ preferredDisplayMode:'inline'}}}]};
234
242
  },
235
243
  async call(name,args){
236
244
  try{
@@ -1,16 +1,29 @@
1
- import {App} from '@modelcontextprotocol/ext-apps';
2
-
3
- // A host-connected MCP App, not a standalone approval authority.
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 radios=[...document.querySelectorAll('input[name="choice"]')];
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
- function selected(){return radios.find(x=>x.checked)?.value||null}
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
- const enabled=Boolean(prepared)&&!locked&&choice
26
- &&(choice!=='B'||$('comment').value.trim());
27
- $('submit').disabled=!enabled;
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||view.options[0]?.value!=='A'
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 safeMode=view.mode==='TEST_ONLY'||view.mode==='GENERAL';
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=!safeMode;
48
- radios.forEach(x=>{x.checked=false});
60
+ $('options').disabled=!safe;
49
61
  $('comment').value='';
50
- locked=!safeMode;
51
- status(safeMode?'已连接 Form prepare;请选择 A 或 B。'
52
- :'正式审批需要宿主真实用户消息身份,目前禁止从组件直接代签。',safeMode?'ok':'error');
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
- app.ontoolinput=params=>{
56
- if(params?.arguments&&typeof params.arguments==='object')
57
- toolInput=params.arguments;
58
- };
59
- app.ontoolresult=result=>{
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 value=decode(result);
62
- if(['TEST_ONLY_PREVIEW','FORM_PREPARED_SOFT','WAITING_APPROVAL'].includes(value.status))
63
- render(value);
64
- else status('工具返回的不是 prepare 回执。','error');
65
- }catch{status('Form prepare 回执无效,禁止提交。','error')}
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||!['GENERAL','TEST_ONLY'].includes(prepared.mode))return;
69
- const choice=selected();
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.formId,mode=prepared.mode;
75
- const requestId=crypto.randomUUID();
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-'+requestId,
137
+ userTurn:'unverified-app-'+writeRequestId,
79
138
  presentedAssistantRef:'app-form-'+formId,
80
- writeRequestId:requestId,
139
+ writeRequestId,
81
140
  ...(mode==='TEST_ONLY'?{
82
- projectId:prepared.projectId,
83
- chatRef:prepared.chatRef,
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
- receipt=decode(await app.callServerTool({
92
- name:'chat_loop_form__submit',arguments:scope
93
- }));
94
- }catch{
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('Form submit 未验证准备记录;未发送用户消息。','error');
156
+ status('Submit 未验证绑定,用户消息未发送。','error');
102
157
  return;
103
158
  }
104
159
  const version=prepared.documentId
105
- ?prepared.documentId+' v'+prepared.version
106
- :'自定义表单';
107
- const message='【Chat Loop Form|'+mode+'】formId='+formId+'|'
108
- +version+'|'+(choice==='A'?'A 确认':'B 修改:'+comment)
109
- +'。此消息来自组件请求;请独立核对真实用户 Turn 身份。'
110
- +(mode==='TEST_ONLY'?'不批准正式业务,不 Start/Continue/Handoff。':'');
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 sent=await app.sendMessage({
114
- role:'user',content:[{type:'text',text:message}]
167
+ const result=await call('ui/message',{
168
+ role:'user',content:[{type:'text',text}]
115
169
  });
116
- if(sent?.isError){
117
- status('宿主拒绝用户消息;Form 仅有软提交记录,未批准。','error');
118
- return;
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
- radios.forEach(x=>x.addEventListener('change',update));
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
- app.connect().catch(()=>status('MCP Apps 宿主连接失败,不能提交。','error'));
179
+ void initialize();