api-edit.md 7.6 KB


更新时间: "2026-11-24"

版本: "2026.11.24.1"

接口读写(已实测)

走 cocorobo_api,target: "cocoflow"(后端 appapi.cocorobo.cn)。凭据由客户端注入,不写 key。POST/PUT/DELETE 必须带 confirmed: true,且只在老师明确同意后带。

读

cocorobo_api({ target: "cocoflow", method: "GET", path: "/api/agents/muti_agent/<工作流编号>" })

返回(2026-11-19 实测):

字段 含义
id 工作流编号,等同编辑页里的 apiKey
muti_name 应用名称(列表接口里叫 name)
description 应用简介
headUrl 封面;空字符串 = 平台默认头像,不代表配过
content 字符串,JSON.parse 后是 {nodes:[], edges:[]},个别工作流多一个 cyid
status / isPublish 0 未发布 / 1 已发布
isEditable false 时页面不给改,接口也别硬写
userid / organizeid 归属,核对是不是当前老师
update_time / create_time UTC,比页面「保存于」早 8 小时,别当成没保存
dialoguePublishDataId 等 各发布模式的产物编号,没发布是 null

列表:GET /api/agents/muti_agent?agentName=&status=&userId=<userid>&pageNum=1&pageSize=10。

写画布(唯一正确姿势)

cocorobo_api({ target: "cocoflow", method: "PUT", path: "/api/agents/muti_agent/<工作流编号>",
  body: { content: "<JSON.stringify({nodes, edges})>" }, confirmed: true })

2026-11-19 实测(原样回写同一份 content):返回 200;回读 content 与写入前逐字符一致(字符数 11310、哈希相同);update_time 由 08:17:34 变为 08:38:21;muti_name、headUrl 原样保留。这个 PUT 是部分更新:只带 content 就只动画布。

  • content 传字符串。传对象会被后端当字符串存,读回来偏移一层。
  • 有 cyid 的工作流要保持 cyid 在里面(页面保存时也是 {...getGraphData(), cyid}),丢了会让协同标记断掉。
  • 一次 PUT 只有一份 content,没有 ETag/版本号;并发防护靠自己:改之前记 update_time,写完再看一眼,发现被别处改过就重读重算,不要旧图覆盖新图。

写元信息

cocorobo_api({ target: "cocoflow", method: "PUT", path: "/api/agents/muti_agent/<工作流编号>",
  body: { muti_name: "<原名>", description: "<原简介>", headUrl: "<封面地址>" }, confirmed: true })

三项整组写,别省字段:先 GET 拿原值再原样带回。只改名称/简介/封面,不动 content(create 技能实测 content 长度与哈希不变)。

出封面图

cocorobo_api({ target: "cocoflow", method: "POST", path: "/api/agents/generateImage",
  body: { prompt: "扁平插画风格的教学应用封面:…,白底,正方形构图,无文字", size: "1024x1024" },
  confirmed: true })

响应是纯字符串图片地址,不是对象。提示词写清学段、学科、用途、道具,必写「无文字」。拿到地址再走上面的元信息 PUT。

其它已确认接口

用途 请求
文件导入工作流 POST /api/agents/import_mutiAgent,body {userid, username, muti_name, description, headUrl, isPublish:0, organizeid, content: JSON.stringify(content), isEditable}
新建(接口式) POST /api/agents/muti_agent,body {userid, username, muti_name, description, headUrl, organizeid, content}
复制整条工作流 POST /api/agents/copy_mutiAgent,body {ids: [<编号>], userId, username};返回里的编号不能依赖,副本靠复制前后列表 id 差集定位,流程见 复制一份再改
删除整个工作流 DELETE /api/agents/muti_agent/<编号>(要老师明确同意,默认不做)
查发布产物 GET /api/agents/get_app_id?id=<编号>,未发布返回 {}
页面里现场取画布 app 帧 lf.getGraphData()(LogicFlow 实例挂在 workFlow 组件的 $data.lf)

content 里的结构(本工作流实测样本)

{
  "nodes": [
    { "id": "node_id_1", "type": "start_node", "x": 200, "y": 240,
      "properties": { "width":146, "height":50, "isShowDelete":false,
        "input_value":"<开场白全文>", "background_img":"", "background_music":"",
        "autoplay":false, "input_mode":"text" } },
    { "id": "<uuid>", "type": "form_card", "x": 620, "y": 240,
      "properties": { "tableName":"表单卡片", "tip":"<提示语>",
        "fields":[ { "key":"选项名称:", "value":"练习档位", "id":"form_<uuid>",
                     "inputValue":"", "is_input":false,
                     "options":[{"value":"基础"},{"value":"提升"},{"value":"挑战"}], "optioned":[] } ],
        "form_card_data":[], "content":"", "item":{"assistantName":"表单卡片"},
        "variable_name":"form_card1", "dispo_arr":[] } },
    { "id": "<uuid>", "type": "ocr_card", "x":1050, "y":240,
      "properties": { "content":"", "prompt":"<识别要求>",
        "item":{"assistantName":"OCR识别"}, "variable_name":"ocr3" } },
    { "id": "<uuid>", "type": "boss_card", "x":1460, "y":240,
      "properties": { "tableName":"控制卡片", "variable_name":"boss_card1",
        "fields":[ {"key":"条件","value":"基础","id":"boss_<uuid>"} ] } },
    { "id": "<uuid>", "type": "UserTask", "x":1880, "y":120,
      "properties": { "item": { "id":"<智能体实例 id>", "assistantName":"基础档讲评",
          "instructions":"<提示词全文>", "modelType":"open-doubao",
          "assistant_id":"…", "thread_id":"…", "inputMode":"text", "outputMode":"text" },
        "dispo_desc":"[表单卡片:form_card1] [OCR识别:ocr3]",
        "dispo_arr":[ {"desc":"表单卡片:form_card1","id":"<表单节点 id>","type":"form_card","selected":true} ],
        "is_export":true, "is_run":false, "is_switch":true, "is_history":true,
        "variable_name":"output5", "interaction_model":true, "is_mon_agent":false } },
    { "id": "node_id_2", "type": "end_node", "x": 2320, "y": 240,
      "properties": { "width":146, "height":50, "isShowDelete":false, "input_value":"终点" } }
  ],
  "edges": [
    { "id":"<uuid>", "type":"boss_edge", "properties":{},
      "sourceNodeId":"node_id_1", "targetNodeId":"<表单 id>",
      "sourceAnchorId":"node_id_1_1", "targetAnchorId":"<表单 id>_3",
      "startPoint":{"x":273,"y":240}, "endPoint":{"x":479,"y":240},
      "pointsList":[{"x":273,"y":240},{"x":373,"y":240},{"x":379,"y":240},{"x":479,"y":240}] }
  ]
}

要点:

  • 起点固定 node_id_1,终点固定 node_id_2,其它节点用 UUID。
  • 锚点:右出 _1、左入 _3、上 _0、下 _2;控制卡条件出口的 sourceAnchorId 就是那条条件的 id(boss_…);控制卡入口用 boss_left_anchors。
  • dispo_arr[].id 指向上游画布节点 id,desc 写 [卡片名:变量名],两个字段要和上游 variable_name 对得上,否则运行到该节点读不到内容。
  • 卡片缺省字段(is_export、is_history、is_switch、createDate)照原样保留,别自己删。
  • 导出文件(页面「导出」)是 {...整条 muti_agent_data, content: <对象>} —— 文件里 content 是对象,接口里是字符串。

改完怎么验

  1. GET 回读:update_time 变、JSON.parse(content) 成功、节点/边数与预期一致。
  2. 逐项比对:目标节点字段等于新值;未涉及的节点 variable_name、instructions、dispo_arr 一字未动。
  3. 差异用脚本比,不要肉眼扫:把改动前后的 content 各存一份 JSON,按 id 对齐比字段。
  4. 能进编辑页就再开调试跑一段(见 编辑页操作),跑不了就写进待验证项。