更新时间: "2026-11-19"
发布只有一个入口:智能体编辑页 右上角「发布」。本文件是 B3—B4 的可抄代码与实测取值。
页面三级结构:cloud.cocorobo.cn(顶层)→ liyuan.cocorobo.cn → app.cocorobo.cn(智能体视图,id="cocoflow_agent")。openApp 在 liyuan 帧的 contentWindow 上,line_agent 在 cocoflow_agent 帧里。
.ap_h_r_publish,文字「发布」。.el-dialog__wrapper.addNewAppDialog;弹窗标题为空字符串,不要按标题找;判打开不要用 offsetParent(wrapper 是 position: fixed,恒为 null),用「元素存在 + getComputedStyle(...).display !== 'none'」。addAppDialog 组件的 form 里 njuri / copy / ntype 会同步变化,用它回读。submitBtn 组装:POST /api/agents/publishAgent/<id>,body {status:1, modes:["0"], data:{nname,nuserid,nlabel:"agent",ndetail,nurl,ntype,njuri,nstand,njson}},njson 内含 {copy,icon,modes:["0"],subject,schoolStage,typeL,cyid}。get_app_id 返回 {"id":"<appId>"}(示例 b4ca4ae0-e3ed-11f1-8551-005056924926),/api/agents/all 里该条 status 由 0 变 1,应用中心记录 juri:"1" / json.copy:"0" / type=<分类编号> / modes:["0"] 与弹窗点选一致。第 1、2、3 段代码在单智能体页均跑通。(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;
for(let i=0;i<20 && typeof w.openApp!=='function';i++) await new Promise(r=>setTimeout(r,300));
if(typeof w.openApp!=='function') return {ok:false, why:'no-openApp'};
const id='<agentId>';
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'}; const cw=t.contentWindow; if(typeof cw.line_agent!=='function') return {ok:false, why:'no-line_agent'}; try { cw.line_agent({ isEditable:true, source:'agent', id }); return {ok:true}; } catch(e) { return {ok:false, why:'line_agent-threw'}; } };
let cb=false, res=null;
try { w.openApp('cocoflow_agent', function(){ cb=true; res=callLine(); }); } catch(e) { return {ok:false, why:'openApp-threw'}; }
await new Promise(r=>setTimeout(r,2500));
if(!res) res=callLine();
await new Promise(r=>setTimeout(r,3000));
const t=findFrame();
return {cb, ...res, hash: t ? t.contentWindow.location.hash : null};
})()
判据:ok: true 且 hash 含 #/AgentPage?id=<agentId> 才算打开。cb 为 false 只说明没观察到回调,不算失败;ok: false 就停下,让老师手动打开,不盲点。
把 SCOPE、PERM、CAT 换成 B1 定下的值(文案见枚举表)。
(async () => {
const SCOPE='公开【组织】', PERM='仅体验', CAT='学习工具';
const f=[...document.querySelectorAll('iframe')].find(x=>/liyuan\.cocorobo\.cn/.test(x.getAttribute('src')||''));
if(!f) return {ok:false, why:'no-liyuan'};
const t=f.contentDocument.getElementById('cocoflow_agent');
if(!t) return {ok:false, why:'no-agent-iframe'};
const d=t.contentDocument, wait=ms=>new Promise(r=>setTimeout(r,ms));
const norm=s=>(s||'').replace(/\s+/g,' ').trim();
let btn=d.querySelector('.ap_h_r_publish');
for(let i=0;i<20 && !btn;i++){ await wait(300); btn=d.querySelector('.ap_h_r_publish'); }
if(!btn) return {ok:false, why:'no-publish-btn', hash:t.contentWindow.location.hash};
btn.click();
let dlg=null;
for(let i=0;i<20 && !dlg;i++){ await wait(300); const c=d.querySelector('.el-dialog__wrapper.addNewAppDialog'); if(c && getComputedStyle(c).display!=='none') dlg=c; }
if(!dlg) return {ok:false, why:'no-dialog'};
const radios=[...dlg.querySelectorAll('.el-radio')];
const pick=txt=>{ const el=radios.find(x=>norm(x.textContent).includes(txt)); if(!el) return {ok:false, why:'no-option:'+txt}; if(el.classList.contains('is-disabled')) return {ok:false, why:'disabled:'+txt}; el.click(); return {ok:true}; };
const r1=pick(SCOPE); if(!r1.ok) return r1; await wait(300);
const r2=pick(PERM); if(!r2.ok) return r2; await wait(300);
const input=dlg.querySelector('input[placeholder="分类"]');
if(!input) return {ok:false, why:'no-category-input'};
input.dispatchEvent(new MouseEvent('mousedown',{bubbles:true}));
input.click();
await wait(500);
const dds=[...d.querySelectorAll('.el-select-dropdown')].filter(x=>getComputedStyle(x).display!=='none');
if(!dds.length) return {ok:false, why:'no-dropdown'};
const lis=[...dds[dds.length-1].querySelectorAll('li')];
const li=lis.find(x=>norm(x.textContent)===CAT);
if(!li) return {ok:false, why:'no-category:'+CAT, options:lis.map(x=>norm(x.textContent))};
li.click(); await wait(400);
let form=null;
const root=d.querySelector('#app');
if(root && root.__vue__){
const seen=new Set();
const walk=(x,depth)=>{ if(!x||depth>18||seen.has(x)||form) return; seen.add(x);
const fm=x.form||(x.$data&&x.$data.form);
if(fm && typeof fm.njuri==='string' && 'nname' in fm){ form=fm; return; }
(x.$children||[]).forEach(c=>walk(c,depth+1)); };
walk(root.__vue__,0);
}
return {ok:true,
checked: radios.map(x=>({txt:norm(x.textContent), checked:!!(x.querySelector('input')||{}).checked})),
category: input.value,
form: form ? {njuri:form.njuri, copy:form.copy, ntype:form.ntype, nurl:form.nurl, nname:form.nname} : null};
})()
回读判据(与方案逐项对齐,不一致就不点确认):
form.njuri = 1/2/3 对应范围文案;form.copy = 0/1;form.ntype 等于该分类的编号(见枚举表),且 category 是中文名;form.nurl 是该智能体的聊天式地址,form.nname 与详情 assistantName 一致。(async () => {
const f=[...document.querySelectorAll('iframe')].find(x=>/liyuan\.cocorobo\.cn/.test(x.getAttribute('src')||''));
const t=f.contentDocument.getElementById('cocoflow_agent');
const d=t.contentDocument, wait=ms=>new Promise(r=>setTimeout(r,ms));
const norm=s=>(s||'').replace(/\s+/g,' ').trim();
const dlg=d.querySelector('.el-dialog__wrapper.addNewAppDialog');
if(!dlg || getComputedStyle(dlg).display==='none') return {ok:false, why:'no-dialog'};
const btn=[...dlg.querySelectorAll('button,.el-button')].find(x=>norm(x.textContent)==='确认发布');
if(!btn) return {ok:false, why:'no-confirm-btn'};
btn.click();
let closed=false;
for(let i=0;i<50;i++){ await wait(500); const c=d.querySelector('.el-dialog__wrapper.addNewAppDialog'); if(!c || getComputedStyle(c).display==='none'){ closed=true; break; } }
return {ok:closed, closed, messages:[...d.querySelectorAll('.el-message')].map(x=>norm(x.textContent)).filter(Boolean)};
})()
closed: true 且 messages 出现「已发布」→ 进 B5 回读;只看到提示不算完成。closed: false → 可能有红色校验提示,把弹窗里的提示原文读出来转给老师;不要连点。| 项 | 文案(点选按这段文字包含匹配) | 取值 |
|---|---|---|
| 发布模式 | 聊天式(唯一项) | form.nurl = 聊天式地址,modes:["0"] |
| 可见范围 | 仅自己【个人】 | njuri: "1" |
| 可见范围 | 公开【组织】 | njuri: "2" |
| 可见范围 | 发布至所有组织【官方】 | njuri: "3" |
| 权限 | 仅体验(用户仅能使用,不可查看设置内容) | copy: "0" |
| 权限 | 允许其他用户复制并进行二次创作(支持查看该工作流所有内容) | copy: "1" |
体验地址(聊天式):https://aichat.cocorobo.cn/#/?id=<agentId>&type=agent。工作流是 type=mutiagent,别混。
分类清单(appstore 接口与弹窗下拉一致,10 项,编号按当前账号返回,不要硬编码):
| 名称 | 编号(2026-11-19 实测) |
|---|---|
| 项目式学习 | 63915be8-cefa-11ef-a2d1-005056b86db5 |
| 教学设计 | a748cc16-be72-11ef-a2d1-005056b86db5 |
| 教学工具 | 38111096-cc11-11ef-a2d1-005056b86db5 |
| 学习工具 | 917a5a56-abd5-11ef-b887-005056b86db5 |
| 效率工具 | 9b257041-abd5-11ef-b887-005056b86db5 |
| 德育工具 | 8045d914-f02e-11ef-b508-005056924926 |
| 资源生成 | b64ad457-be72-11ef-a2d1-005056b86db5 |
| 人机共育 | 6ee6e4f7-1a67-11f0-a66a-005056924926 |
| 纲要课程 | 9e2b8daa-3786-11f0-b60f-005056924926 |
| 其他 | a7862bef-abd5-11ef-b887-005056b86db5 |
用回读记录里的 url(聊天式是 https://aichat.cocorobo.cn/#/?id=<agentId>&type=agent),不要自己拼。cocorobo_open_page 每次都会新开一个标签页,不要复用编辑页那个:
cocorobo_open_page({ url: "<回读到的 url>", title: "智能体体验页" })
cocorobo_page_eval({
urlMatch: "aichat.cocorobo.cn",
code: "(() => ({ href: location.href, title: document.title, head: (document.body ? document.body.innerText : '').replace(/\s+/g,' ').trim().slice(0,200) }))()"
})
2026-11-19 实测:aichat.cocorobo.cn 聊天页能在右侧新标签页打开,page_eval 读得到 location.href、document.title(「CocoFlow」)和正文。单智能体 type=agent 地址也已实测(正文出现智能体名称 + 问候语 + 起点/终点),没设开场白时显示的是平台默认问候语「你好!我是「名称」,发送内容给我,和我开始对话吧。」——这不是开场白没保存成功。读不到正文就只说“页面已打开”,不改发布结论。
publish() 先判断 saveing(提示“正在保存中,请等待保存完后再发布”),再判断 instructions(提示“请添加提示词之后再发布”)。空提示词的智能体点发布只会弹提示,不弹窗。click() 不弹下拉:必须先对输入框发 mousedown,再 click();只 focus() 也不行。.el-radio 顺序随版本变化,不要按索引取;点完用 input.checked 和 form 双重复核。.el-radio.is-disabled 的选项不要点,也不要用 form 直接改值绕过。prologue。