更新时间: "2026-11-19"
只在步骤 6 回读核对通过后执行;核对未通过时先走中断恢复,不要用打开页面来“证明”创建成功。分两段:8.1 打开 CocoFlow,8.2 再尝试定位。第二段命中与否都要如实说。
cocorobo_open_page({ url: "https://cloud.cocorobo.cn/", title: "CocoFlow" })
cocorobo_page_eval({
urlMatch: "cloud.cocorobo.cn",
code: "(() => { const f=[...document.querySelectorAll('iframe')].find(x=>/liyuan\\.cocorobo\\.cn/.test(x.getAttribute('src')||'')); if(!f) return 'no-iframe'; if(typeof f.contentWindow.openApp!=='function') return 'no-openApp'; f.contentWindow.openApp('cocoflow'); return 'called'; })()"
})
cocorobo_page_eval({
urlMatch: "cloud.cocorobo.cn",
code: "(() => { const f=[...document.querySelectorAll('iframe')].find(x=>/liyuan\\.cocorobo\\.cn/.test(x.getAttribute('src')||'')); if(!f) return {open:false, why:'no-liyuan'}; let inner=[]; try { inner=[...f.contentDocument.querySelectorAll('iframe')].map(x=>x.getAttribute('src')||''); } catch(e) { return {open:false, why:'blocked'}; } return { open: inner.some(s=>/app\\.cocorobo\\.cn/.test(s)), inner }; })()"
})
window.openApp,只在 liyuan iframe 的 contentWindow 上调;调用返回 undefined 属正常。cocoflow,不试 project、cocostudy001、cocobookllm 等其他名称。querySelectorAll('iframe') 查不到,不要拿顶层判失败。open: true 才算打开成功;返回 false 就按失败规则说明,不再进 8.2。平台 openWithCallback(val, callback) 支持回调:callback 存进 openAppCallback,应用 iframe load 完成后由 runOpenAppCallback() 执行一次。openApp('cocoflow_agent') 打开的是单智能体视图。顶层拿不到组件引用,改为在 liyuan frame 的 document 里取 getElementById('cocoflow_agent'),取不到再按 src 匹配 app.cocorobo.cn。line_agent 只挂在单智能体视图那个 iframe 上,普通 cocoflow 的 iframe 里它是 undefined。
回调里找 iframe、调 line_agent;2.5 秒内回调没跑起来就主动补调一次(旧版本 openApp 只接一个参数会吞掉回调;应用已经打开时 iframe 不重新 load,回调也不触发):
cocorobo_page_eval({
urlMatch: "cloud.cocorobo.cn",
code: "(async () => { const f=[...document.querySelectorAll('iframe')].find(x=>/liyuan\\.cocorobo\\.cn/.test(x.getAttribute('src')||'')); if(!f) return {ok:false, why:'no-liyuan'}; const w=f.contentWindow; if(typeof w.openApp!=='function') return {ok:false, why:'no-openApp'}; const id='<本次创建的编号>'; const findFrame=()=>{ try { return f.contentDocument.getElementById('cocoflow_agent') || [...f.contentDocument.querySelectorAll('iframe')].find(x=>/app\\.cocorobo\\.cn/.test(x.getAttribute('src')||'')) || null; } catch(e) { return null; } }; const callLine=()=>{ const t=findFrame(); if(!t||!t.contentWindow) return {ok:false, why:'no-agent-iframe'}; if(typeof t.contentWindow.line_agent!=='function') return {ok:false, why:'no-line_agent'}; try { t.contentWindow.line_agent({ isEditable:true, source:'agent', id }); return {ok:true, called:'line_agent'}; } catch(e) { return {ok:false, why:'line_agent-threw'}; } }; let cbRan=false; let res=null; try { w.openApp('cocoflow_agent', function(){ cbRan=true; res=callLine(); }); } catch(e) { return {ok:false, why:'openApp-threw'}; } await new Promise(r=>setTimeout(r,2500)); if(!res) res=callLine(); return Object.assign({cbRan}, res); })()"
})
还要再试一次定位(不重开应用)时用这段:
cocorobo_page_eval({
urlMatch: "cloud.cocorobo.cn",
code: "(() => { const f=[...document.querySelectorAll('iframe')].find(x=>/liyuan\\.cocorobo\\.cn/.test(x.getAttribute('src')||'')); if(!f) return {ok:false, why:'no-liyuan'}; let frames=[]; try { frames=[...f.contentDocument.querySelectorAll('iframe')]; } catch(e) { return {ok:false, why:'blocked'}; } const t=frames.find(x=>/agent/i.test((x.getAttribute('name')||'')+(x.id||'')+(x.getAttribute('src')||''))); if(!t||!t.contentWindow) return {ok:false, why:'no-agent-iframe'}; if(typeof t.contentWindow.line_agent!=='function') return {ok:false, why:'no-line_agent'}; t.contentWindow.line_agent({ isEditable: true, source: 'agent', id: '<本次创建的编号>' }); return {ok:true, called:'line_agent'}; })()"
})
按返回的 cbRan 和 called 判定:
ok: true, called: 'line_agent' → 才能说“右侧已定位到刚建的智能体”。cbRan: false 只说明本次没观察到回调,不单独证明旧版本或失败;超时补调得到 ok: true 就按成功记录。cbRan: true 但 ok: false → 视图起来了、回调也执行了,缺的是 line_agent(该版本没有这个 API),同样如实说没定位。ok: false 都只说明情况,不循环重试,不换应用名试探,不虚构定位成功。三件事分开说,不混成一句:
called: 'line_agent';否则说「创作空间已打开,但没能自动定位到该智能体,请按名称找到它。」打开失败不改写创建结论,也不要为了打开页面重发 POST 或 PUT。页面里看到新对象只作参考,列表可能延迟,核对仍以步骤 6 为准。