3 lines
3.8 KiB
Java
3 lines
3.8 KiB
Java
import{u as k,f as i}from"./index-BI6CMai0.js";import{r as I}from"./dayjs.min-3azO_lpC-BamC5rSi.js";var l=(t,s,e)=>new Promise((o,g)=>{var h=u=>{try{c(e.next(u))}catch(p){g(p)}},w=u=>{try{c(e.throw(u))}catch(p){g(p)}},c=u=>u.done?o(u.value):Promise.resolve(u.value).then(h,w);c((e=e.apply(t,s)).next())});const{createMessage:T}=k(),x=300*1e3;function $(t,s){const e=(n,a)=>[`%c${n}`,`color: ${a};`],o=()=>e("[INFO]","#2196F3"),g=()=>e("[WARN]","#FFC107"),h=()=>e("[ERRO]","#F44336"),w=e("[stream-run]","#999999"),c=(n,...a)=>{const f=n();`${w[0]}${f[0]}`,w[1],f[1],I().format("HH:mm:ss.SSS")};let u="";function p(){return l(this,null,function*(){const n=(yield i.post({url:"/airag/flow/debug",params:{flow:t,inputParams:s,responseMode:"streaming"},adapter:"fetch",responseType:"stream",timeout:x},{isTransformResponse:!1})).getReader(),a=new TextDecoder;for(u="";;){const{done:f,value:r}=yield n.read();if(f)break;const d=a.decode(r,{stream:!0});try{c(o,"收到 chunkText:",{chunkText:d}),F(d)}catch(v){}}})}function F(n){if(!n){c(h,"chunkText 为空:",{chunkText:n});return}u.length>0&&(n=u+n,c(o,"合并解析失败的数据:",{chunkText:n}),u="");let a=!1;const f=n.split(`
|
|
`).flatMap(r=>{if(r=r?r.trim():"",!r)return[];if(r.startsWith("data:")&&(r=r.slice(5)),!r)return c(h,"chunk 为空:",{chunk:r,chunkText:n}),[];try{return[JSON.parse(r)]}catch(d){a=!0,c(h,"chunk 解析失败:",{chunk:r,chunkText:n})}return[]});a&&(u+=n),f.forEach(M)}const y=new Map,S=new Set;function M(n){var a,f;if(n.success==!1){const v=y.get("FLOW_FINISHED");if(typeof v=="function"){v(n);return}}const r=`${n.event}-${((a=n.data)==null?void 0:a.id)||((f=n.data)==null?void 0:f.fromNodeId)||""}`;S.has(r),S.add(r);const d=y.get(n.event);typeof d=="function"?(c(o,` ------ 处理 ${n.event} 事件:`,{key:r,data:n}),d(n.data,n)):c(g,`${n.event} 事件对应的回调不存在:`,{key:r,data:n})}function m(n,a){y.set(n,a)}return{run:p,onFlowStarted:n=>m("FLOW_STARTED",n),onFlowFinished:n=>m("FLOW_FINISHED",n),onNodeStarted:n=>m("NODE_STARTED",n),onNodeFinished:n=>m("NODE_FINISHED",n),onMessage:n=>m("MESSAGE",n)}}function O(t){return l(this,null,function*(){return i.get({url:"/airag/flow/list",params:t})})}function R(t,s){return l(this,null,function*(){var e;const o=(e=s==null?void 0:s.silent)!=null?e:!1;return i.post({url:"/airag/flow/add",params:t},{successMessageMode:o?"none":"success"})})}function b(t){return l(this,null,function*(){return i.put({url:"/airag/flow/edit",params:t})})}function D(t,s=!1){return l(this,null,function*(){const e=s?"取消发布":"发布",o=yield i.put({url:"/airag/flow/edit",params:{id:t,status:s?"enable":"release"}},{successMessageMode:"none",isTransformResponse:!1});return o.success?(T.success(`${e}成功`),!0):(T.warn(o.message||`${e}失败`),!1)})}function H(t,s){return l(this,null,function*(){var e;const o=(e=s==null?void 0:s.silent)!=null?e:!1;return i.put({url:"/airag/flow/design/save",params:{id:t.id,name:t.name,chain:t.chain,design:t.design}},{successMessageMode:o?"none":"success"})})}function P(t){return l(this,null,function*(){return i.delete({url:"/airag/flow/delete",data:{id:t}},{joinParamsToUrl:!0})})}function W(t){return l(this,null,function*(){return i.delete({url:"/airag/flow/deleteBatch",data:{ids:t.join(",")}},{joinParamsToUrl:!0})})}function _(t){return l(this,null,function*(){return i.get({url:"/airag/flow/querySubflowById",params:{subflowId:t}})})}function A(t){return l(this,null,function*(){return i.get({url:"/airag/flow/querySubflowById",params:{subflowId:t}},{isTransformResponse:!1,errorMessageMode:"none"})})}function j(t){return l(this,null,function*(){return i.get({url:"/airag/flow/queryById",params:{id:t}})})}function q(t,s){return l(this,null,function*(){return i.post({url:"/airag/flow/copyFlow",params:t}).then(()=>{s()})})}export{_ as A,b as H,A as L,$ as O,O as P,q as U,H as W,P as _,W as j,R as q,D as v,j as x};
|