@tomflow/chatloop-tools 0.9.35 → 0.9.37

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 CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "0.9.35",
6
+ "version": "0.9.37",
7
7
  "type": "module",
8
8
  "description": "Chat Loop local tools: MCP gateway, isolated bundled tunnel-client and unified CLI",
9
9
  "bin": {
@@ -3,7 +3,7 @@ const $=id=>document.getElementById(id);
3
3
  const idPattern=/^[A-Za-z0-9][A-Za-z0-9_-]{7,79}$/;
4
4
  const tracePattern=/^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
5
5
  const requests=new Map();
6
- let seq=0,connected=false,prepared=null,locked=false,toolResult=null,hostFailure=null,renderReported=null;
6
+ let seq=0,connected=false,prepared=null,locked=false,toolResult=null,hostFailure=null,renderReported=null,messageSupported=false;
7
7
  function status(message,state='info'){
8
8
  $('status').textContent=message;
9
9
  $('status').dataset.state=state;
@@ -54,6 +54,14 @@ function update(){
54
54
  const text=$('input').value.trim();
55
55
  $('submit').disabled=!connected||!prepared||locked||!option
56
56
  ||(visible&&inputRequired(option)&&!text);
57
+ // Reflect the current selection, not the initial prepare state.
58
+ // Business decisions and validation remain the caller's responsibility.
59
+ if(connected&&prepared&&!locked&&!hostFailure){
60
+ if(!option)status('请选择一项。','ok');
61
+ else if(visible&&inputRequired(option)&&!text)
62
+ status('已选择「'+option.label+'」,请填写必要信息。','info');
63
+ else status('已选择「'+option.label+'」,可以提交。','ok');
64
+ }
57
65
  resize();
58
66
  }
59
67
  function reportRendered(value){
@@ -102,7 +110,7 @@ function render(value){
102
110
  &&prepared?.traceRef===value.traceRef&&locked;
103
111
  if(!preserveLock){
104
112
  delete $('status').dataset.submitReceipt;
105
- delete $('status').dataset.modelContextDelivery;
113
+ delete $('status').dataset.messageDelivery;
106
114
  }
107
115
  prepared=value;
108
116
  $('title').textContent=view.title;
@@ -204,6 +212,7 @@ async function initialize(){
204
212
  hostFailure='当前宿主缺少 serverTools 能力,表单不可提交。';
205
213
  status(hostFailure,'error');update();return;
206
214
  }
215
+ messageSupported=Boolean(response.hostCapabilities.message?.text);
207
216
  connected=true;hostFailure=null;
208
217
  notify('ui/notifications/initialized',{});
209
218
  resize();
@@ -240,24 +249,37 @@ async function submit(){
240
249
  status('Submit 返回的数据与当前表单不匹配。','error');return;
241
250
  }
242
251
  $('status').dataset.submitReceipt='confirmed';
243
- // Update model-visible context without posting a new Chat message.
244
- // This is not proof of a user Turn, business approval, or model consumption.
245
- $('status').dataset.modelContextDelivery='pending';
246
- void call('ui/update-model-context',{content:[{type:'text',
247
- text:JSON.stringify({kind:'form-selection',formId,traceRef,
248
- selection:receipt.selection,
249
- ...(receipt.input!==undefined?{input:receipt.input}:{})})
250
- }]}).then(result=>{
251
- if(result?.isError)throw Error('FORM_MODEL_CONTEXT_REJECTED');
252
- $('status').dataset.modelContextDelivery='acknowledged';
253
- }).catch(()=>{
254
- $('status').dataset.modelContextDelivery='unverified';
255
- console.warn('FORM_MODEL_CONTEXT_DELIVERY_UNVERIFIED');
256
- });
257
- // Opaque receipts are for the caller, not the normal user-facing card.
252
+ // Submit confirms data, not a user turn or business approval. The host
253
+ // owns message creation; never treat an ACK as proof of model consumption.
258
254
  $('result').textContent='';
259
255
  $('result').hidden=true;
260
- status('已提交表单,等待当前业务流程处理。','ok');
256
+ if(!messageSupported){
257
+ $('status').dataset.messageDelivery='unsupported';
258
+ status('表单已提交;当前宿主不支持从表单发送后续消息,业务尚未续接。','error');
259
+ return;
260
+ }
261
+ const message=[
262
+ 'Chat Loop Form 提交结果(由用户点击表单提交)',
263
+ 'formId: '+formId,
264
+ 'traceRef: '+traceRef,
265
+ '选项值: '+receipt.selection.value,
266
+ '选项标签: '+receipt.selection.label,
267
+ ...(receipt.input!==undefined?['补充信息:'+receipt.input]:[]),
268
+ '请核对当前业务任务、文档与 Issue 版本及原生消息身份后处理本次选择;表单回执本身不构成审批或写权。'
269
+ ].join('\n');
270
+ $('status').dataset.messageDelivery='pending';
271
+ status('表单已提交,正在请求宿主发送后续消息…');
272
+ try{
273
+ const delivered=await call('ui/message',{
274
+ role:'user',content:[{type:'text',text:message}]
275
+ });
276
+ if(delivered?.isError)throw Error('FORM_MESSAGE_HOST_REJECTED');
277
+ $('status').dataset.messageDelivery='acknowledged';
278
+ status('表单已提交,宿主已受理后续消息;请核对新消息和业务处理结果。','ok');
279
+ }catch{
280
+ $('status').dataset.messageDelivery='unverified';
281
+ status('表单已提交,但后续消息交付结果未知;请核查当前对话,勿重复提交。','error');
282
+ }
261
283
  }catch(error){
262
284
  const code=typeof error?.message==='string'
263
285
  &&/^[A-Z][A-Z0-9_]{1,95}$/.test(error.message)
@@ -47,7 +47,8 @@ button:disabled{opacity:.44;cursor:not-allowed}
47
47
  <small id="footer"></small>
48
48
  </section>
49
49
  </main>
50
- <script>(()=>{var r=t=>document.getElementById(t),L=/^[A-Za-z0-9][A-Za-z0-9_-]{7,79}$/,T=/^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i,h=new Map,v=0,c=!1,a=null,f=!1,R=null,l=null,g=null;function u(t,e="info"){r("status").textContent=t,r("status").dataset.state=e}function _(t){window.parent.postMessage({jsonrpc:"2.0",...t},"*")}function C(t,e={}){_({method:t,params:e})}function I(t,e){if(!c)throw Error("FORM_APP_NOT_INITIALIZED");return new Promise((n,o)=>{let s=++v,p=setTimeout(()=>{h.delete(s),o(Error("FORM_APP_REPLY_UNKNOWN"))},3e4);h.set(s,{resolve:n,reject:o,timer:p}),_({id:s,method:t,params:e})})}function b(t){if(t?.isError){let n=t.content?.find(o=>o.type==="text")?.text;throw Error(typeof n=="string"&&/^[A-Z][A-Z0-9_]{1,95}$/.test(n)?n:"FORM_TOOL_REJECTED")}if(t?.structuredContent?.status)return t.structuredContent;let e=t?.content?.find(n=>n.type==="text")?.text;if(typeof e!="string"||e.length>2e4)throw Error("FORM_RECEIPT_MISSING");return JSON.parse(e)}var D=()=>[...document.querySelectorAll('input[name="choice"]')],W=()=>D().find(t=>t.checked)?.value||null;function x(){let t=W();return a?.view.options.find(e=>e.value===t)||null}function P(t){let e=a?.view.textInput;return!!(e&&t&&e.showWhen.includes(t.value))}function A(t){let e=a?.view.textInput;return!!(e&&t&&e.requiredWhen.includes(t.value))}function m(){let t=x(),e=P(t);r("options").disabled=!c||!a||f,r("text-input").hidden=!e;let n=r("input").value.trim();r("submit").disabled=!c||!a||f||!t||e&&A(t)&&!n,O()}function M(t){if(!c||!t)return;let e=document.querySelector("main")?.getBoundingClientRect();if(!e||e.width<1||e.height<1){r("status").dataset.renderObservation="not-visible";return}let n=t.formId+":"+t.traceRef;g!==n&&(g=n,r("status").dataset.renderObservation="pending",I("tools/call",{name:"chat_loop_form__render",arguments:{formId:t.formId,traceRef:t.traceRef}}).then(b).then(o=>{if(o.status!=="FORM_RENDERED"||o.formId!==t.formId||o.traceRef!==t.traceRef)throw Error("FORM_RENDER_RECEIPT_INVALID");r("status").dataset.renderObservation="confirmed"}).catch(()=>{r("status").dataset.renderObservation="unverified",console.warn("FORM_RENDER_OBSERVATION_UNVERIFIED")}))}function F(t){let e=t?.view,n=e?.options;if(!e||e.template!=="chat-loop-form-v1"||typeof t.formId!="string"||!L.test(t.formId)||typeof t.traceRef!="string"||!T.test(t.traceRef)||e.formId!==t.formId||!Array.isArray(n)||n.length<1||n.length>32||n.some(i=>!i||typeof i.value!="string"||!i.value.trim()||typeof i.label!="string"||!i.label.trim())||new Set(n.map(i=>i.value)).size!==n.length)throw Error("FORM_VIEW_INVALID");let o=e.textInput;if(o&&(!Array.isArray(o.showWhen)||!Array.isArray(o.requiredWhen)||o.requiredWhen.some(i=>!o.showWhen.includes(i)))||Object.hasOwn(e,"document"))throw Error("FORM_VIEW_INVALID");let s=a?.formId===t.formId&&a?.traceRef===t.traceRef&&f;s||(delete r("status").dataset.submitReceipt,delete r("status").dataset.modelContextDelivery),a=t,r("title").textContent=e.title,r("description").textContent=e.description,r("submit").textContent=e.submitLabel||"\u63D0\u4EA4",r("footer").textContent=e.footer||"";let p=r("option-list");p.replaceChildren();for(let i of n){let d=document.createElement("label");d.className="option";let E=document.createElement("input");E.type="radio",E.name="choice",E.value=i.value,E.addEventListener("change",m);let w=document.createElement("span");w.textContent=i.label,d.append(E,w),p.append(d)}r("text-label").textContent=o?.label||"\u8865\u5145\u4FE1\u606F",r("input").placeholder=o?.placeholder||"",r("input").maxLength=o?.maxLength||4e3,r("input").rows=o?.rows||4,r("text-input").hidden=!0,r("input").value="",f=s,r("result").hidden=!0,r("result").textContent="",u(s?"\u672C\u8868\u5355\u5DF2\u63D0\u4EA4\u6216\u7ED3\u679C\u672A\u77E5\uFF0C\u8BF7\u6838\u5BF9\u539F\u8BF7\u6C42\u56DE\u6267\u3002":l||(c?"\u8868\u5355\u5DF2\u51C6\u5907\uFF0C\u8BF7\u9009\u62E9\u4E00\u9879\u3002":"\u8868\u5355\u5DF2\u51C6\u5907\uFF0C\u6B63\u5728\u7B49\u5F85\u5BBF\u4E3B\u80FD\u529B\u786E\u8BA4\u3002"),s?"info":l?"error":c?"ok":"info"),m(),M(t)}function V(t){if(t.source!==window.parent)return;let e=t.data;if(!(!e||e.jsonrpc!=="2.0"||typeof e!="object")){if(Object.hasOwn(e,"id")&&!Object.hasOwn(e,"method")){let n=h.get(e.id);if(!n)return;h.delete(e.id),clearTimeout(n.timer),e.error?n.reject(Error("FORM_APP_REPLY_UNKNOWN")):n.resolve(e.result);return}if(e.method==="ui/notifications/tool-result"){R=e.params;try{F(b(R))}catch{a=null,f=!0,m(),u("Form prepare \u56DE\u6267\u65E0\u6548\uFF0C\u7981\u6B62\u63D0\u4EA4\u3002","error")}}e.method==="ui/resource-teardown"&&e.id!==void 0&&_({id:e.id,result:{}})}}var y=0,N=0;function O(){if(!c)return;let t=document.querySelector("main");if(!t)return;let e=t.getBoundingClientRect();if(e.width<1||e.height<1)return;M(a);let n=parseFloat(getComputedStyle(document.body).paddingBottom)||0,o=Math.ceil(e.bottom+n),s=Math.ceil(document.documentElement.clientWidth);!Number.isFinite(o)||o<1||!Number.isFinite(s)||s<1||o===y&&s===N||(y=o,N=s,C("ui/notifications/size-changed",{width:s,height:o}))}async function S(){if(window.parent===window){u("\u672A\u5728 ChatGPT MCP App iframe \u4E2D\u8FD0\u884C\uFF0C\u7981\u6B62\u63D0\u4EA4\u3002","error");return}let t=++v,e=new Promise((n,o)=>{let s=setTimeout(()=>{h.delete(t),o(Error("FORM_APP_INIT_TIMEOUT"))},12e3);h.set(t,{resolve:n,reject:o,timer:s}),_({id:t,method:"ui/initialize",params:{appInfo:{name:"Chat Loop Form",version:"1.1.0"},appCapabilities:{},protocolVersion:"2026-01-26"}})});try{let n=await e;if(!n?.protocolVersion||!n.hostInfo||!n.hostCapabilities)throw Error("FORM_APP_INIT_INVALID");if(!n.hostCapabilities.serverTools){l="\u5F53\u524D\u5BBF\u4E3B\u7F3A\u5C11 serverTools \u80FD\u529B\uFF0C\u8868\u5355\u4E0D\u53EF\u63D0\u4EA4\u3002",u(l,"error"),m();return}c=!0,l=null,C("ui/notifications/initialized",{}),O(),R&&F(b(R)),typeof ResizeObserver=="function"&&new ResizeObserver(O).observe(document.querySelector("main"))}catch{l="MCP App \u521D\u59CB\u5316\u5931\u8D25\uFF0C\u8BF7\u6838\u67E5\u5BBF\u4E3B\u8FDE\u63A5\u4E0E\u534F\u8BAE\u80FD\u529B\u3002",u(l,"error"),c=!1,m()}}async function q(){if(!c||f||!a)return;let t=x();if(!t)return;let e=P(t),n=r("input").value.trim();if(e&&A(t)&&!n)return;f=!0,m();let{formId:o,traceRef:s}=a,p={formId:o,traceRef:s,selection:{value:t.value,label:t.label},...e&&n?{input:n}:{}};r("status").dataset.submitReceipt="pending",u("\u6B63\u5728\u63D0\u4EA4\u8868\u5355\u2026");try{let i=b(await I("tools/call",{name:"chat_loop_form__submit",arguments:p}));if(i.status!=="FORM_SUBMITTED"||i.formId!==o||i.traceRef!==s||i.selection?.value!==t.value||i.selection?.label!==t.label){r("status").dataset.submitReceipt="failed",u("Submit \u8FD4\u56DE\u7684\u6570\u636E\u4E0E\u5F53\u524D\u8868\u5355\u4E0D\u5339\u914D\u3002","error");return}r("status").dataset.submitReceipt="confirmed",r("status").dataset.modelContextDelivery="pending",I("ui/update-model-context",{content:[{type:"text",text:JSON.stringify({kind:"form-selection",formId:o,traceRef:s,selection:i.selection,...i.input!==void 0?{input:i.input}:{}})}]}).then(d=>{if(d?.isError)throw Error("FORM_MODEL_CONTEXT_REJECTED");r("status").dataset.modelContextDelivery="acknowledged"}).catch(()=>{r("status").dataset.modelContextDelivery="unverified",console.warn("FORM_MODEL_CONTEXT_DELIVERY_UNVERIFIED")}),r("result").textContent="",r("result").hidden=!0,u("\u5DF2\u63D0\u4EA4\u8868\u5355\uFF0C\u7B49\u5F85\u5F53\u524D\u4E1A\u52A1\u6D41\u7A0B\u5904\u7406\u3002","ok")}catch(i){let d=typeof i?.message=="string"&&/^[A-Z][A-Z0-9_]{1,95}$/.test(i.message)?i.message:"FORM_APP_REPLY_UNKNOWN";r("status").dataset.submitReceipt=d==="FORM_APP_REPLY_UNKNOWN"?"unknown":"failed",u(d==="FORM_APP_REPLY_UNKNOWN"?"\u63D0\u4EA4\u7ED3\u679C\u672A\u77E5\uFF1B\u5DF2\u9501\u5B9A\u5F53\u524D\u8868\u5355\uFF0C\u8BF7\u6838\u67E5\u539F\u8BF7\u6C42\u56DE\u6267\u3002":"\u63D0\u4EA4\u5931\u8D25\uFF08"+d+"\uFF09\u3002","error")}}window.addEventListener("message",V);r("input").addEventListener("input",m);r("submit").addEventListener("click",q);S();})();
50
+ <script>(()=>{var r=e=>document.getElementById(e),T=/^[A-Za-z0-9][A-Za-z0-9_-]{7,79}$/,D=/^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i,R=new Map,A=0,u=!1,c=null,f=!1,b=null,l=null,v=null,P=!1;function a(e,t="info"){r("status").textContent=e,r("status").dataset.state=t}function E(e){window.parent.postMessage({jsonrpc:"2.0",...e},"*")}function C(e,t={}){E({method:e,params:t})}function g(e,t){if(!u)throw Error("FORM_APP_NOT_INITIALIZED");return new Promise((n,o)=>{let s=++A,p=setTimeout(()=>{R.delete(s),o(Error("FORM_APP_REPLY_UNKNOWN"))},3e4);R.set(s,{resolve:n,reject:o,timer:p}),E({id:s,method:e,params:t})})}function _(e){if(e?.isError){let n=e.content?.find(o=>o.type==="text")?.text;throw Error(typeof n=="string"&&/^[A-Z][A-Z0-9_]{1,95}$/.test(n)?n:"FORM_TOOL_REJECTED")}if(e?.structuredContent?.status)return e.structuredContent;let t=e?.content?.find(n=>n.type==="text")?.text;if(typeof t!="string"||t.length>2e4)throw Error("FORM_RECEIPT_MISSING");return JSON.parse(t)}var S=()=>[...document.querySelectorAll('input[name="choice"]')],W=()=>S().find(e=>e.checked)?.value||null;function M(){let e=W();return c?.view.options.find(t=>t.value===e)||null}function x(e){let t=c?.view.textInput;return!!(t&&e&&t.showWhen.includes(e.value))}function I(e){let t=c?.view.textInput;return!!(t&&e&&t.requiredWhen.includes(e.value))}function m(){let e=M(),t=x(e);r("options").disabled=!u||!c||f,r("text-input").hidden=!t;let n=r("input").value.trim();r("submit").disabled=!u||!c||f||!e||t&&I(e)&&!n,u&&c&&!f&&!l&&(e?t&&I(e)&&!n?a("\u5DF2\u9009\u62E9\u300C"+e.label+"\u300D\uFF0C\u8BF7\u586B\u5199\u5FC5\u8981\u4FE1\u606F\u3002","info"):a("\u5DF2\u9009\u62E9\u300C"+e.label+"\u300D\uFF0C\u53EF\u4EE5\u63D0\u4EA4\u3002","ok"):a("\u8BF7\u9009\u62E9\u4E00\u9879\u3002","ok")),w()}function F(e){if(!u||!e)return;let t=document.querySelector("main")?.getBoundingClientRect();if(!t||t.width<1||t.height<1){r("status").dataset.renderObservation="not-visible";return}let n=e.formId+":"+e.traceRef;v!==n&&(v=n,r("status").dataset.renderObservation="pending",g("tools/call",{name:"chat_loop_form__render",arguments:{formId:e.formId,traceRef:e.traceRef}}).then(_).then(o=>{if(o.status!=="FORM_RENDERED"||o.formId!==e.formId||o.traceRef!==e.traceRef)throw Error("FORM_RENDER_RECEIPT_INVALID");r("status").dataset.renderObservation="confirmed"}).catch(()=>{r("status").dataset.renderObservation="unverified",console.warn("FORM_RENDER_OBSERVATION_UNVERIFIED")}))}function L(e){let t=e?.view,n=t?.options;if(!t||t.template!=="chat-loop-form-v1"||typeof e.formId!="string"||!T.test(e.formId)||typeof e.traceRef!="string"||!D.test(e.traceRef)||t.formId!==e.formId||!Array.isArray(n)||n.length<1||n.length>32||n.some(i=>!i||typeof i.value!="string"||!i.value.trim()||typeof i.label!="string"||!i.label.trim())||new Set(n.map(i=>i.value)).size!==n.length)throw Error("FORM_VIEW_INVALID");let o=t.textInput;if(o&&(!Array.isArray(o.showWhen)||!Array.isArray(o.requiredWhen)||o.requiredWhen.some(i=>!o.showWhen.includes(i)))||Object.hasOwn(t,"document"))throw Error("FORM_VIEW_INVALID");let s=c?.formId===e.formId&&c?.traceRef===e.traceRef&&f;s||(delete r("status").dataset.submitReceipt,delete r("status").dataset.messageDelivery),c=e,r("title").textContent=t.title,r("description").textContent=t.description,r("submit").textContent=t.submitLabel||"\u63D0\u4EA4",r("footer").textContent=t.footer||"";let p=r("option-list");p.replaceChildren();for(let i of n){let d=document.createElement("label");d.className="option";let h=document.createElement("input");h.type="radio",h.name="choice",h.value=i.value,h.addEventListener("change",m);let O=document.createElement("span");O.textContent=i.label,d.append(h,O),p.append(d)}r("text-label").textContent=o?.label||"\u8865\u5145\u4FE1\u606F",r("input").placeholder=o?.placeholder||"",r("input").maxLength=o?.maxLength||4e3,r("input").rows=o?.rows||4,r("text-input").hidden=!0,r("input").value="",f=s,r("result").hidden=!0,r("result").textContent="",a(s?"\u672C\u8868\u5355\u5DF2\u63D0\u4EA4\u6216\u7ED3\u679C\u672A\u77E5\uFF0C\u8BF7\u6838\u5BF9\u539F\u8BF7\u6C42\u56DE\u6267\u3002":l||(u?"\u8868\u5355\u5DF2\u51C6\u5907\uFF0C\u8BF7\u9009\u62E9\u4E00\u9879\u3002":"\u8868\u5355\u5DF2\u51C6\u5907\uFF0C\u6B63\u5728\u7B49\u5F85\u5BBF\u4E3B\u80FD\u529B\u786E\u8BA4\u3002"),s?"info":l?"error":u?"ok":"info"),m(),F(e)}function V(e){if(e.source!==window.parent)return;let t=e.data;if(!(!t||t.jsonrpc!=="2.0"||typeof t!="object")){if(Object.hasOwn(t,"id")&&!Object.hasOwn(t,"method")){let n=R.get(t.id);if(!n)return;R.delete(t.id),clearTimeout(n.timer),t.error?n.reject(Error("FORM_APP_REPLY_UNKNOWN")):n.resolve(t.result);return}if(t.method==="ui/notifications/tool-result"){b=t.params;try{L(_(b))}catch{c=null,f=!0,m(),a("Form prepare \u56DE\u6267\u65E0\u6548\uFF0C\u7981\u6B62\u63D0\u4EA4\u3002","error")}}t.method==="ui/resource-teardown"&&t.id!==void 0&&E({id:t.id,result:{}})}}var y=0,N=0;function w(){if(!u)return;let e=document.querySelector("main");if(!e)return;let t=e.getBoundingClientRect();if(t.width<1||t.height<1)return;F(c);let n=parseFloat(getComputedStyle(document.body).paddingBottom)||0,o=Math.ceil(t.bottom+n),s=Math.ceil(document.documentElement.clientWidth);!Number.isFinite(o)||o<1||!Number.isFinite(s)||s<1||o===y&&s===N||(y=o,N=s,C("ui/notifications/size-changed",{width:s,height:o}))}async function k(){if(window.parent===window){a("\u672A\u5728 ChatGPT MCP App iframe \u4E2D\u8FD0\u884C\uFF0C\u7981\u6B62\u63D0\u4EA4\u3002","error");return}let e=++A,t=new Promise((n,o)=>{let s=setTimeout(()=>{R.delete(e),o(Error("FORM_APP_INIT_TIMEOUT"))},12e3);R.set(e,{resolve:n,reject:o,timer:s}),E({id:e,method:"ui/initialize",params:{appInfo:{name:"Chat Loop Form",version:"1.1.0"},appCapabilities:{},protocolVersion:"2026-01-26"}})});try{let n=await t;if(!n?.protocolVersion||!n.hostInfo||!n.hostCapabilities)throw Error("FORM_APP_INIT_INVALID");if(!n.hostCapabilities.serverTools){l="\u5F53\u524D\u5BBF\u4E3B\u7F3A\u5C11 serverTools \u80FD\u529B\uFF0C\u8868\u5355\u4E0D\u53EF\u63D0\u4EA4\u3002",a(l,"error"),m();return}P=!!n.hostCapabilities.message?.text,u=!0,l=null,C("ui/notifications/initialized",{}),w(),b&&L(_(b)),typeof ResizeObserver=="function"&&new ResizeObserver(w).observe(document.querySelector("main"))}catch{l="MCP App \u521D\u59CB\u5316\u5931\u8D25\uFF0C\u8BF7\u6838\u67E5\u5BBF\u4E3B\u8FDE\u63A5\u4E0E\u534F\u8BAE\u80FD\u529B\u3002",a(l,"error"),u=!1,m()}}async function q(){if(!u||f||!c)return;let e=M();if(!e)return;let t=x(e),n=r("input").value.trim();if(t&&I(e)&&!n)return;f=!0,m();let{formId:o,traceRef:s}=c,p={formId:o,traceRef:s,selection:{value:e.value,label:e.label},...t&&n?{input:n}:{}};r("status").dataset.submitReceipt="pending",a("\u6B63\u5728\u63D0\u4EA4\u8868\u5355\u2026");try{let i=_(await g("tools/call",{name:"chat_loop_form__submit",arguments:p}));if(i.status!=="FORM_SUBMITTED"||i.formId!==o||i.traceRef!==s||i.selection?.value!==e.value||i.selection?.label!==e.label){r("status").dataset.submitReceipt="failed",a("Submit \u8FD4\u56DE\u7684\u6570\u636E\u4E0E\u5F53\u524D\u8868\u5355\u4E0D\u5339\u914D\u3002","error");return}if(r("status").dataset.submitReceipt="confirmed",r("result").textContent="",r("result").hidden=!0,!P){r("status").dataset.messageDelivery="unsupported",a("\u8868\u5355\u5DF2\u63D0\u4EA4\uFF1B\u5F53\u524D\u5BBF\u4E3B\u4E0D\u652F\u6301\u4ECE\u8868\u5355\u53D1\u9001\u540E\u7EED\u6D88\u606F\uFF0C\u4E1A\u52A1\u5C1A\u672A\u7EED\u63A5\u3002","error");return}let d=["Chat Loop Form \u63D0\u4EA4\u7ED3\u679C\uFF08\u7531\u7528\u6237\u70B9\u51FB\u8868\u5355\u63D0\u4EA4\uFF09","formId: "+o,"traceRef: "+s,"\u9009\u9879\u503C: "+i.selection.value,"\u9009\u9879\u6807\u7B7E: "+i.selection.label,...i.input!==void 0?["\u8865\u5145\u4FE1\u606F\uFF1A"+i.input]:[],"\u8BF7\u6838\u5BF9\u5F53\u524D\u4E1A\u52A1\u4EFB\u52A1\u3001\u6587\u6863\u4E0E Issue \u7248\u672C\u53CA\u539F\u751F\u6D88\u606F\u8EAB\u4EFD\u540E\u5904\u7406\u672C\u6B21\u9009\u62E9\uFF1B\u8868\u5355\u56DE\u6267\u672C\u8EAB\u4E0D\u6784\u6210\u5BA1\u6279\u6216\u5199\u6743\u3002"].join(`
51
+ `);r("status").dataset.messageDelivery="pending",a("\u8868\u5355\u5DF2\u63D0\u4EA4\uFF0C\u6B63\u5728\u8BF7\u6C42\u5BBF\u4E3B\u53D1\u9001\u540E\u7EED\u6D88\u606F\u2026");try{if((await g("ui/message",{role:"user",content:[{type:"text",text:d}]}))?.isError)throw Error("FORM_MESSAGE_HOST_REJECTED");r("status").dataset.messageDelivery="acknowledged",a("\u8868\u5355\u5DF2\u63D0\u4EA4\uFF0C\u5BBF\u4E3B\u5DF2\u53D7\u7406\u540E\u7EED\u6D88\u606F\uFF1B\u8BF7\u6838\u5BF9\u65B0\u6D88\u606F\u548C\u4E1A\u52A1\u5904\u7406\u7ED3\u679C\u3002","ok")}catch{r("status").dataset.messageDelivery="unverified",a("\u8868\u5355\u5DF2\u63D0\u4EA4\uFF0C\u4F46\u540E\u7EED\u6D88\u606F\u4EA4\u4ED8\u7ED3\u679C\u672A\u77E5\uFF1B\u8BF7\u6838\u67E5\u5F53\u524D\u5BF9\u8BDD\uFF0C\u52FF\u91CD\u590D\u63D0\u4EA4\u3002","error")}}catch(i){let d=typeof i?.message=="string"&&/^[A-Z][A-Z0-9_]{1,95}$/.test(i.message)?i.message:"FORM_APP_REPLY_UNKNOWN";r("status").dataset.submitReceipt=d==="FORM_APP_REPLY_UNKNOWN"?"unknown":"failed",a(d==="FORM_APP_REPLY_UNKNOWN"?"\u63D0\u4EA4\u7ED3\u679C\u672A\u77E5\uFF1B\u5DF2\u9501\u5B9A\u5F53\u524D\u8868\u5355\uFF0C\u8BF7\u6838\u67E5\u539F\u8BF7\u6C42\u56DE\u6267\u3002":"\u63D0\u4EA4\u5931\u8D25\uFF08"+d+"\uFF09\u3002","error")}}window.addEventListener("message",V);r("input").addEventListener("input",m);r("submit").addEventListener("click",q);k();})();
51
52
  </script>
52
53
  </body>
53
54
  </html>