publish-ui.md 9.5 KB


更新时间: "2026-11-19" 版本: "2026.11.19.1"

同步说明: 与 cocoflow-agent-create-publish/references/publish-ui.md 同源,改动请两边一起改

发布弹窗操作手册(发布已有智能体)

发布只有一个入口:智能体编辑页 右上角「发布」。下面三段代码依次是:打开编辑页 → 开弹窗按方案点选并回读 → 提交。

页面三级结构:cloud.cocorobo.cn(顶层)→ liyuan.cocorobo.cn → app.cocorobo.cn(智能体视图,id="cocoflow_agent")。

实测结论(2026-11-19,本机)

  • 发布按钮 .ap_h_r_publish,文字「发布」;点击后弹 .el-dialog__wrapper.addNewAppDialog。
  • 弹窗标题是空字符串,别按标题找;判打开不要用 offsetParent(position: fixed,恒为 null),用「元素存在 + display !== 'none'」。
  • 弹窗默认「聊天式 + 仅自己【个人】 + 仅体验 + 项目式学习」,这是平台默认值,不是老师的选择。
  • 提交走组件方法 submitBtn → POST /api/agents/publishAgent/<id>,body {status:1, modes:["0"], data:{nname,nuserid,nlabel:"agent",ndetail,nurl,ntype,njuri,nstand,njson}}。
  • 提交落库已实测(2026-11-19,单智能体页全流程):弹窗关闭 + 「已发布」提示 + get_app_id 返回 {"id":"<appId>"} + /api/agents/all 里 status 由 0 变 1,应用中心记录的 juri / json.copy / type 与弹窗点选一致。第 1、2、3 段代码均跑通。

1. 打开该智能体的编辑页

(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 就停下让老师手动打开。

2. 打开弹窗、按方案点选并回读

把 SCOPE、PERM、CAT 换成第 1 步定下的值。

(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.nname 与详情 assistantName 一致。任一不符就不点确认。

3. 提交并确认关闭

(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 且出现「已发布」→ 回读;只看到提示不算完成。

枚举表

项 文案(按包含匹配) 取值
发布模式 聊天式(唯一项) modes:["0"]
可见范围 仅自己【个人】 njuri: "1"
可见范围 公开【组织】 njuri: "2"
可见范围 发布至所有组织【官方】 njuri: "3"
权限 仅体验(用户仅能使用,不可查看设置内容) copy: "0"
权限 允许其他用户复制并进行二次创作(支持查看该工作流所有内容) copy: "1"

体验地址(聊天式):https://aichat.cocorobo.cn/#/?id=<agentId>&type=agent。工作流是 type=mutiagent,别混。

分类十项:项目式学习、教学设计、教学工具、学习工具、效率工具、德育工具、资源生成、人机共育、纲要课程、其他。编号一律从 appstore 的 /api/pbl/select_appStoreType_exceptType 现查,不硬编码。

4. 发布后打开发布页

用回读记录里的 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 聊天页能在右侧新标签页打开并读到 location.href、document.title、正文。单智能体 type=agent 也已实测(正文出现名称 + 问候语 + 起点/终点),没设开场白时显示平台默认问候语,不是开场白丢失。读不到正文就只说“页面已打开”,不改发布结论。

陷阱

  • 提示词为空不能发布:点「发布」只弹“请添加提示词之后再发布”,不弹窗;保存中会提示“正在保存中,请等待保存完后再发布”。
  • 分类只 click() 不弹下拉:必须先 mousedown 再 click()。
  • 单选按文字点,不按索引;点完用 input.checked + 表单值双重复核。
  • 置灰(is-disabled)就是没资格:不点、不用表单改值绕过。
  • 没设开场白的智能体,体验页显示平台默认问候语;别据此重写 prologue。