agentix-cli 0.25.0 → 0.26.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/dist/{App-6Y7B3YQH.js → App-BPNHIGUX.js} +2 -2
- package/dist/{ChatApp-KIEUJ2DS.js → ChatApp-6XSSZB4U.js} +2 -2
- package/dist/{agent-QGZIAZMY.js → agent-5QMITZT6.js} +2 -2
- package/dist/{board-dashboard-CQ5F4GPD.js → board-dashboard-M3372FLO.js} +1191 -225
- package/dist/board-dashboard-M3372FLO.js.map +1 -0
- package/dist/{chunk-JXWAGMI2.js → chunk-BTHHSY7D.js} +7 -7
- package/dist/chunk-BTHHSY7D.js.map +1 -0
- package/dist/{chunk-TRJTTBE2.js → chunk-BVGJSPW4.js} +2 -2
- package/dist/{chunk-53GCFZPR.js → chunk-D46VZ7K7.js} +2 -2
- package/dist/{chunk-HA3XI7Z2.js → chunk-E5CXCI33.js} +27 -27
- package/dist/chunk-E5CXCI33.js.map +1 -0
- package/dist/{chunk-FDMWOPEL.js → chunk-K2CAPYES.js} +2 -2
- package/dist/{chunk-TMKLHTCG.js → chunk-METYYZKQ.js} +264 -120
- package/dist/chunk-METYYZKQ.js.map +1 -0
- package/dist/{chunk-Q6YO7LYE.js → chunk-MTAPOCGA.js} +2 -2
- package/dist/{chunk-G57RZCXM.js → chunk-O6YPEOQF.js} +2 -2
- package/dist/{chunk-KUCCW2VG.js → chunk-UHE5FCPB.js} +8 -8
- package/dist/{chunk-LNXCJWOU.js → chunk-V3U4OF7L.js} +2 -2
- package/dist/{chunk-NGSIRE4X.js → chunk-VT5XYFDD.js} +2 -2
- package/dist/cli.js +1 -1
- package/dist/client-HGKAC6VP.js +2 -0
- package/dist/{config-7FSZFRTQ.js → config-A4RWEJHV.js} +2 -2
- package/dist/config-mutator-MNSFUN7D.js +2 -0
- package/dist/doctor-3Q36ZFE6.js +2 -0
- package/dist/index.d.ts +58 -1
- package/dist/index.js +1 -1
- package/dist/{program-WVAVJFND.js → program-SAUNRCCD.js} +2 -2
- package/dist/{registry-T36ZIAWV.js → registry-HK3WQ7BS.js} +2 -2
- package/dist/scheduler-6T2SU5ST.js +2 -0
- package/package.json +1 -1
- package/dist/board-dashboard-CQ5F4GPD.js.map +0 -1
- package/dist/chunk-HA3XI7Z2.js.map +0 -1
- package/dist/chunk-JXWAGMI2.js.map +0 -1
- package/dist/chunk-TMKLHTCG.js.map +0 -1
- package/dist/client-GGVVLOOF.js +0 -2
- package/dist/config-mutator-POCOYYJ4.js +0 -2
- package/dist/doctor-DHLBEKA4.js +0 -2
- package/dist/scheduler-GH7TIKYS.js +0 -2
- /package/dist/{App-6Y7B3YQH.js.map → App-BPNHIGUX.js.map} +0 -0
- /package/dist/{ChatApp-KIEUJ2DS.js.map → ChatApp-6XSSZB4U.js.map} +0 -0
- /package/dist/{agent-QGZIAZMY.js.map → agent-5QMITZT6.js.map} +0 -0
- /package/dist/{chunk-TRJTTBE2.js.map → chunk-BVGJSPW4.js.map} +0 -0
- /package/dist/{chunk-53GCFZPR.js.map → chunk-D46VZ7K7.js.map} +0 -0
- /package/dist/{chunk-FDMWOPEL.js.map → chunk-K2CAPYES.js.map} +0 -0
- /package/dist/{chunk-Q6YO7LYE.js.map → chunk-MTAPOCGA.js.map} +0 -0
- /package/dist/{chunk-G57RZCXM.js.map → chunk-O6YPEOQF.js.map} +0 -0
- /package/dist/{chunk-KUCCW2VG.js.map → chunk-UHE5FCPB.js.map} +0 -0
- /package/dist/{chunk-LNXCJWOU.js.map → chunk-V3U4OF7L.js.map} +0 -0
- /package/dist/{chunk-NGSIRE4X.js.map → chunk-VT5XYFDD.js.map} +0 -0
- /package/dist/{client-GGVVLOOF.js.map → client-HGKAC6VP.js.map} +0 -0
- /package/dist/{config-7FSZFRTQ.js.map → config-A4RWEJHV.js.map} +0 -0
- /package/dist/{config-mutator-POCOYYJ4.js.map → config-mutator-MNSFUN7D.js.map} +0 -0
- /package/dist/{doctor-DHLBEKA4.js.map → doctor-3Q36ZFE6.js.map} +0 -0
- /package/dist/{program-WVAVJFND.js.map → program-SAUNRCCD.js.map} +0 -0
- /package/dist/{registry-T36ZIAWV.js.map → registry-HK3WQ7BS.js.map} +0 -0
- /package/dist/{scheduler-GH7TIKYS.js.map → scheduler-6T2SU5ST.js.map} +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{a as ie}from"./chunk-M4AMWP3H.js";import{b as oe}from"./chunk-AFRHKA7B.js";import{a as Ae,c as $e,d as Te,f as De,g as Pe,h as We}from"./chunk-
|
|
1
|
+
import{a as ie}from"./chunk-M4AMWP3H.js";import{b as oe}from"./chunk-AFRHKA7B.js";import{a as Ae,c as $e,d as Te,f as De,g as Pe,h as We}from"./chunk-D46VZ7K7.js";import{a as y,b as j}from"./chunk-ISEBLHWX.js";import{existsSync as bt,mkdirSync as Ne,readFileSync as vt,writeFileSync as It,renameSync as St}from"fs";import{resolve as Ee,dirname as Rt}from"path";var xe=class{filePath;log;constructor(e={}){let t=e.baseDir??Ee(process.cwd(),".agentx");this.filePath=Ee(t,"handover.json"),this.log=e.log??console.error.bind(console,"[handover]"),Ne(t,{recursive:!0})}key(e,t,r){return`${e}::${t}::${r||"-"}`}load(){if(!bt(this.filePath))return{version:1,overrides:{}};try{let e=vt(this.filePath,"utf-8"),t=JSON.parse(e);return!t||typeof t!="object"?{version:1,overrides:{}}:(t.overrides||(t.overrides={}),t)}catch(e){return this.log(`load failed, starting empty: ${e?.message||e}`),{version:1,overrides:{}}}}save(e){Ne(Rt(this.filePath),{recursive:!0});let t=`${this.filePath}.tmp-${process.pid}`;It(t,JSON.stringify(e,null,2)),St(t,this.filePath)}get(e,t,r){let o=this.load().overrides[this.key(e,t,r)];if(o&&!(o.expiresAt&&Date.parse(o.expiresAt)<Date.now()))return o}set(e){if(!e.channel||!e.chatId||!e.toAgent)throw new Error("channel, chatId and toAgent are required");let t=this.load(),r={...e,createdAt:e.createdAt??new Date().toISOString()};return t.overrides[this.key(r.channel,r.chatId,r.accountId)]=r,this.save(t),r}remove(e,t,r){let s=this.load(),o=this.key(e,t,r);return o in s.overrides?(delete s.overrides[o],this.save(s),!0):!1}consumeSummary(e,t,r){let s=this.load(),o=s.overrides[this.key(e,t,r)];if(!o||!o.summary||o.summaryConsumedAt)return;let i=o.summary;return o.summaryConsumedAt=new Date().toISOString(),this.save(s),i}listActive(){let e=this.load(),t=Date.now();return Object.values(e.overrides).filter(r=>!r.expiresAt||Date.parse(r.expiresAt)>=t)}listByAgent(e){let t=this.listActive();return{incoming:t.filter(r=>r.toAgent===e),outgoing:t.filter(r=>r.fromAgent===e)}}};import{existsSync as b,mkdirSync as Et,readdirSync as z,readFileSync as G,unlinkSync as V,writeFileSync as de}from"fs";import{resolve as R,relative as le}from"path";import Oe from"js-yaml";var At=new Set(["branch","gateway.parallel","rule","signal.wait","subProcess","timer.boundary","checkpoint"]),k=class extends Error{constructor(t,r){super(t);this.mark=r;this.name="WorkflowYamlError"}};function x(n,e={}){if(!n||n.trim()==="")throw new k(`${A(e)}empty file \u2014 workflow YAML must contain at least an id, version, title, and one node.`);let t;try{t=Oe.loadAll(n)}catch(s){let o=s?.mark;throw new k(`${A(e)}YAML parse error: ${s?.reason??s?.message??s}`+(o?` (line ${o.line+1}, column ${o.column+1})`:""),o)}if(t.length===0||t.length===1&&t[0]==null)throw new k(`${A(e)}YAML produced no document.`);if(t.length>1)throw new k(`${A(e)}multi-document YAML is not supported in v1; one workflow per file.`);let r=t[0];if(typeof r!="object"||r===null||Array.isArray(r)){let s=Array.isArray(r)?"array":typeof r;throw new k(`${A(e)}top-level YAML must be a mapping (got ${s}).`)}return je(r,e)}function je(n,e={}){if(!("flow"in n))return n;let t=n.flow;if(t==null){let c={...n};return delete c.flow,c}if(!Array.isArray(t))throw new k(`${A(e)}flow must be an array of node ids (got ${typeof t}).`);for(let c of t)if(typeof c!="string")throw new k(`${A(e)}flow entries must be strings (got ${typeof c}).`);let r=t,s=Array.isArray(n.nodes)?n.nodes:[],o=new Map;for(let c of s)c&&typeof c=="object"&&typeof c.id=="string"&&typeof c.type=="string"&&o.set(c.id,c.type);for(let c of r){if(!o.has(c))throw new k(`${A(e)}flow references unknown node "${c}".`);let f=o.get(c);if(At.has(f))throw new k(`${A(e)}flow cannot include ${f} node "${c}"; use explicit edges for ${f} nodes.`)}let i=[];for(let c=0;c<r.length-1;c++)i.push({from:r[c],to:r[c+1]});let a=Array.isArray(n.edges)?n.edges:[],d=new Set,l=[];for(let c of a){if(!c||typeof c!="object")continue;let f=_e(c.from,c.fromPort,c.to);f&&!d.has(f)?(d.add(f),l.push(c)):f||l.push(c)}for(let c of i){let f=_e(c.from,void 0,c.to);f&&!d.has(f)&&(d.add(f),l.push(c))}let p={...n,edges:l};return delete p.flow,p}function _e(n,e,t){return typeof n!="string"||typeof t!="string"?null:`${n}::${typeof e=="string"?e:""}::${t}`}function A(n){return n.filePath?`${n.filePath}: `:""}function Y(n){return Oe.dump(n,{noRefs:!0,lineWidth:100,sortKeys:!1})}import{Document as $t,isMap as J,isSeq as Tt,isScalar as Fe,parseDocument as Dt}from"yaml";function Ce(n,e){let t=Dt(n);if(!t.contents||!J(t.contents)){let r=new $t(e);return t.commentBefore&&(r.commentBefore=t.commentBefore),String(r)}return ae(t,t.contents,e),String(t)}function ae(n,e,t){let r=Object.keys(t),s=new Set(r),o=new Map;for(let a of e.items){let d=Nt(a);d!==null&&o.set(d,a)}let i=[];for(let a of r){let d=t[a],l=o.get(a);l?(Pt(n,l,d),i.push(l)):i.push(n.createPair(a,d))}e.items=i}function Pt(n,e,t){let r=e.value;if(t==null){e.value=n.createNode(null);return}if(typeof t!="object"){e.value=n.createNode(t);return}if(Array.isArray(t)){Tt(r)?Wt(n,r,t):e.value=n.createNode(t);return}J(r)?ae(n,r,t):e.value=n.createNode(t)}function Wt(n,e,t){if(!(t.length>0&&t.every(i=>i&&typeof i=="object"&&typeof i.id=="string"))){let i=n.createNode(t);e.items=i.items;return}let s=new Map;for(let i of e.items)if(J(i)){let a=i.get("id",!0);Fe(a)&&typeof a.value=="string"&&s.set(a.value,i)}let o=[];for(let i of t){let a=i.id,d=s.get(a);d&&J(d)?(ae(n,d,i),o.push(d)):o.push(n.createNode(i))}e.items=o}function Nt(n){let e=n.key;return Fe(e)&&typeof e.value=="string"?e.value:typeof e=="string"?e:null}var ce=class{baseDir;constructor(e={}){this.baseDir=e.baseDir??R(process.cwd(),".agentx/workflows"),Et(this.baseDir,{recursive:!0})}pathFor(e){return this.pathForJson(e)}pathForJson(e){return R(this.baseDir,`${e}.json`)}pathForYaml(e){return R(this.baseDir,`${e}.yaml`)}isWorkflowFile(e){return e.startsWith("_")?!1:e.endsWith(".json")||e.endsWith(".yaml")||e.endsWith(".yml")}idFromFilename(e){return e.replace(/\.(json|ya?ml)$/,"")}readAndParse(e){let t=R(this.baseDir,e),r=G(t,"utf-8");return e.endsWith(".json")?JSON.parse(r):x(r,{filePath:e})}list(){if(!b(this.baseDir))return[];let e=new Map;for(let r of z(this.baseDir,{withFileTypes:!0})){if(!r.isFile()||!this.isWorkflowFile(r.name))continue;let s=this.idFromFilename(r.name),o=e.get(s)??[];o.push(r.name),e.set(s,o)}let t=[];for(let[,r]of e)if(!(r.length>1))try{let s=this.readAndParse(r[0]),o=y.safeParse(s);o.success&&t.push(o.data)}catch{}return t.sort((r,s)=>r.id.localeCompare(s.id))}validateAll(){let e=[];if(!b(this.baseDir))return e;let t=new Map;for(let r of z(this.baseDir,{withFileTypes:!0})){if(!r.isFile()||!this.isWorkflowFile(r.name))continue;let s=this.idFromFilename(r.name),o=t.get(s)??[];o.push(r.name),t.set(s,o)}for(let[r,s]of t){if(s.length>1){let c=[...s].sort();for(let f of c)e.push({id:r,path:le(this.baseDir,R(this.baseDir,f)),issues:[`duplicate workflow id "${r}" \u2014 found ${c.join(" and ")}; delete one to disambiguate`],isValid:!1});continue}let o=s[0],i=R(this.baseDir,o),a=le(this.baseDir,i),d;try{d=this.readAndParse(o)}catch(c){let f=c instanceof k?c.message:`parse error: ${c?.message??c}`;e.push({id:r,path:a,issues:[f],isValid:!1});continue}let l=y.safeParse(d);if(!l.success){let c=l.error.issues.map(f=>`${f.path.join(".")||"<root>"}: ${f.message}`);e.push({id:String(d?.id??r),path:a,issues:c,isValid:!1});continue}let p=j(l.data);e.push({workflow:l.data,issues:p,isValid:p.length===0})}return e}get(e){let t=this.pathForJson(e),r=this.pathForYaml(e),s=R(this.baseDir,`${e}.yml`),o=b(t),i=b(r)||b(s);if(o&&i)return null;if(o)try{let d=JSON.parse(G(t,"utf-8")),l=y.safeParse(d);return l.success?l.data:null}catch{return null}let a=b(r)?r:b(s)?s:null;if(a)try{let d=G(a,"utf-8"),l=x(d,{filePath:le(this.baseDir,a)}),p=y.safeParse(l);return p.success?p.data:null}catch{return null}if(!b(this.baseDir))return null;for(let d of z(this.baseDir,{withFileTypes:!0}))if(!(!d.isFile()||!this.isWorkflowFile(d.name)||this.idFromFilename(d.name)===e))try{let p=this.readAndParse(d.name),c=y.safeParse(p);if(c.success&&c.data.id===e)return c.data}catch{}return null}save(e,t={}){let r=new Date().toISOString().slice(0,10),s=y.parse({...e,created:e.created||r,updated:r}),o=this.pathForYaml(s.id),i=R(this.baseDir,`${s.id}.yml`),a=b(o)?o:b(i)?i:null;if(!a&&b(this.baseDir)){for(let d of z(this.baseDir,{withFileTypes:!0}))if(!(!d.isFile()||!this.isWorkflowFile(d.name))&&!d.name.endsWith(".json"))try{let l=this.readAndParse(d.name),p=y.safeParse(l);if(p.success&&p.data.id===s.id){a=R(this.baseDir,d.name);break}}catch{}}if(a&&t.convertFromYaml)return V(a),de(this.pathForJson(s.id),JSON.stringify(s,null,2)+`
|
|
2
2
|
`),s;if(a){let d=G(a,"utf-8");try{let l=Ce(d,s);return de(a,l),s}catch(l){let p=new Error(`yaml round-trip failed for "${s.id}" at ${a}: ${l?.message??l}`);throw p.yamlPath=a,p}}return de(this.pathForJson(s.id),JSON.stringify(s,null,2)+`
|
|
3
3
|
`),s}delete(e){let t=this.pathForJson(e),r=this.pathForYaml(e),s=R(this.baseDir,`${e}.yml`),o=!1;return b(t)&&(V(t),o=!0),b(r)&&(V(r),o=!0),b(s)&&(V(s),o=!0),o}};import{createHash as xt,randomUUID as _t}from"crypto";import{appendFileSync as Me,existsSync as _,mkdirSync as Le,readdirSync as He,readFileSync as ue,statSync as Ue,unlinkSync as qe,writeFileSync as Ot}from"fs";import{resolve as N}from"path";function jt(n){return n.replace(/[^a-zA-Z0-9._:#@-]/g,"_").slice(0,200)}function T(n,e,t){return xt("sha1").update(`${n}|${e}|${t}`).digest("hex").slice(0,16)}var pe=class{baseDir;runsDir;indexDir;nodeId;constructor(e){this.baseDir=e.baseDir??N(process.cwd(),".agentx/workflows"),this.runsDir=N(this.baseDir,"_runs"),this.indexDir=N(this.baseDir,"_index"),this.nodeId=e.nodeId,Le(this.runsDir,{recursive:!0}),Le(this.indexDir,{recursive:!0})}runPath(e){return N(this.runsDir,`${e}.jsonl`)}indexPath(e){return N(this.indexDir,`${e.backend}__${jt(e.id)}.json`)}create(e){let t=new Date().toISOString(),r=_t(),s={id:r,workflowId:e.workflowId,workflowVersion:2,homeNode:this.nodeId,status:"running",pausedAt:void 0,context:e.initialContext??{},pending:e.initialPending,entityRef:e.entityRef,history:[],parentRunId:e.parentRunId??null,parentNodeId:e.parentNodeId??null,rootRunId:e.rootRunId??r,depth:e.depth??0,joinCounters:{},createdAt:t,updatedAt:t};return this.appendSnapshot(s),this.writeIndex(e.entityRef,s.id),s}get(e){let t=this.runPath(e);if(!_(t))return null;let r=ue(t,"utf-8").trim();if(!r)return null;let s=null;for(let o of r.split(`
|
|
4
4
|
`)){let i;try{i=JSON.parse(o)}catch{continue}if(i.v===2){if(i.kind==="snapshot")s=i.run;else if(i.kind==="exec"&&s&&s.id===i.runId){let a=s;s={...a,history:[...a.history,i.entry],pending:i.pending,status:i.status??a.status,pausedAt:i.pausedAt===null?void 0:i.pausedAt??a.pausedAt,context:i.context??a.context,joinCounters:i.joinCounters??a.joinCounters,updatedAt:i.entry.at}}}}return s}getActiveByEntity(e){let t=this.indexPath(e);if(!_(t))return null;try{return JSON.parse(ue(t,"utf-8")).runId}catch{return null}}getHomeNodeByEntity(e){let t=this.indexPath(e);if(!_(t))return null;try{return JSON.parse(ue(t,"utf-8")).homeNode}catch{return null}}recordExecution(e){let t=this.get(e.runId);if(!t)return null;if(t.history.some(o=>o.idempotencyKey===e.entry.idempotencyKey))return t;let r={v:2,kind:"exec",runId:e.runId,entry:e.entry,pending:e.nextPending,status:e.status,pausedAt:e.pausedAt===null?null:e.pausedAt,context:e.context,joinCounters:e.joinCounters};Me(this.runPath(e.runId),JSON.stringify(r)+`
|
|
@@ -44,4 +44,4 @@ import{a as ie}from"./chunk-M4AMWP3H.js";import{b as oe}from"./chunk-AFRHKA7B.js
|
|
|
44
44
|
`);return y.parse({id:s,version:2,title:`Draft: ${i}`,description:`Generated from task trace ${n.taskId}. Review before promotion.`,status:"draft",state:"disabled",tags:Mn(n,e),entity:n.chatId||void 0,generatedFrom:t.generatedFrom??"task-trace",sourceTaskIds:o,confidence:t.confidence??.55,workflowVersion:"draft-1",ownerAgent:n.agentId,nodes:[{id:"trigger",type:"trigger.manual",config:{inputSchema:{type:"object",properties:{message:{type:"string"},taskId:{type:"string"}}}}},{id:"run_cleaned_task",type:"agent",config:{agentId:n.agentId,prompt:a}},{id:"done",type:"end",config:{status:"completed",output:"{{run_cleaned_task.reply}}"}}],edges:[{from:"trigger",to:"run_cleaned_task"},{from:"run_cleaned_task",to:"done"}],envAllow:[],retention:{maxRuns:500,maxDays:90},maxChildDepth:5})}async function it(n,e=[],t={}){let r=L(n,e),s=t.id||ot(r,n),o=t.sourceTaskIds?.length?t.sourceTaskIds:[n.taskId],i=t.confidence??.55;if(t.viaAgent)try{let{architectWorkflowViaAgent:a}=await import("./architect-SEPWMWS4.js"),d=await a(n,e,s,o,i,{agentId:t.viaAgent,daemonUrl:t.daemonUrl});return{workflow:d.workflow,usedLlm:!0,via:d.via}}catch(a){let d=a?.message||String(a);return t.log?.(`[architect] agent path (${t.viaAgent}) failed for ${n.taskId.slice(0,8)}, falling back to deterministic: ${d}`),{workflow:ne(n,e,t),usedLlm:!1,error:d}}if(t.model)try{let{architectWorkflowFromTrace:a}=await import("./architect-SEPWMWS4.js"),d=await a(n,e,s,o,i,{model:t.model});return{workflow:d.workflow,usedLlm:!0,via:`direct:${d.model}`}}catch(a){let d=a?.message||String(a);return t.log?.(`[architect] direct API failed for ${n.taskId.slice(0,8)}, falling back to deterministic: ${d}`),{workflow:ne(n,e,t),usedLlm:!1,error:d}}return{workflow:ne(n,e,t),usedLlm:!1}}function at(n){let e=y.safeParse(n);return e.success?j(e.data):e.error.issues.map(t=>`${t.path.join(".")||"<root>"}: ${t.message}`)}var Hn=new Set(["agent","action.run","action.send","action.builtin","action.callHTTP","action.createIssue","action.setLabel","action.readLabel","action.react","action.editMessage","action.logTime","transform","extract.structured","branch","rule","subProcess"]);function Un(n){return n.nodes.filter(t=>Hn.has(t.type)).length>0&&n.nodes.length>=3}function H(n=process.cwd()){return I(n,".agentx/workflows/_drafts")}function U(n){return I(n,"_drafts")}function qn(n=process.cwd()){return I(n,".agentx/workflows/_drafts/_rejected")}function Bn(n){return I(U(n),"_rejected")}function dt(n,e="yaml",t=process.cwd()){return I(H(t),`${n}.${e}`)}function Kn(n,e,t="yaml"){return I(U(e),`${n}.${t}`)}function Yn(n,e={}){let t=e.format??"yaml",r=e.workflowDir?U(e.workflowDir):H(e.baseDir);Ie(r,{recursive:!0});let s=e.workflowDir?Kn(n.id,e.workflowDir,t):dt(n.id,t,e.baseDir);if(!e.force&&re(s))throw new Error(`draft already exists: ${s}`);let o=t==="json"?JSON.stringify(n,null,2)+`
|
|
45
45
|
`:Y(n);return nt(s,o),s}function lt(n){let e=En(n,"utf-8"),t=/\.(ya?ml)$/i.test(n)?x(e,{filePath:rt(n)}):JSON.parse(e);return y.parse(t)}function Jn(n=process.cwd(),e={}){let t=e.workflowDir?U(e.workflowDir):H(n);return re(t)?xn(t,{withFileTypes:!0}).filter(r=>r.isFile()&&/\.(json|ya?ml)$/i.test(r.name)).map(r=>{let s=I(t,r.name);return{id:r.name.replace(/\.(json|ya?ml)$/i,""),path:s,workflow:lt(s)}}).sort((r,s)=>r.id.localeCompare(s.id)):[]}function Se(n,e=process.cwd(),t={}){let r=t.workflowDir?U(t.workflowDir):H(e);for(let s of["yaml","yml","json"]){let o=I(r,`${n}.${s}`);if(re(o))return{id:n,path:o,workflow:lt(o)}}return null}function zn(n,e={}){let t=Se(n,e.baseDir,{workflowDir:e.workflowDir});if(!t)throw new Error(`draft not found: ${n}`);let r=e.format??(t.path.endsWith(".json")?"json":"yaml"),s=y.parse({...t.workflow,status:"active",state:"active",updated:new Date().toISOString().slice(0,10)}),o=at(s);if(o.length)throw new Error(`draft is invalid: ${o.join("; ")}`);let i=e.workflowDir??I(e.baseDir??process.cwd(),".agentx/workflows"),a=I(i,`${s.id}.${r}`);if(!e.replace&&re(a))throw new Error(`workflow already exists: ${a}`);return Ie(i,{recursive:!0}),nt(a,r==="json"?JSON.stringify(s,null,2)+`
|
|
46
46
|
`:Y(s)),On(t.path),{workflow:s,from:t.path,to:a}}function Gn(n,e=process.cwd(),t={}){let r=Se(n,e,{workflowDir:t.workflowDir});if(!r)throw new Error(`draft not found: ${n}`);let s=t.workflowDir?Bn(t.workflowDir):qn(e);Ie(s,{recursive:!0});let o=I(s,`${Date.now().toString(36)}-${rt(r.path)}`);return _n(r.path,o),o}var Vn=30;function Zn(n,e={}){let t=e.minMessageLength??Vn;return tt(n,{agentId:e.agentId,status:"ok",since:e.since,limit:e.limit??1e3}).filter(r=>!r.workflowRunId).filter(r=>(r.messagePreview||"").trim().length>=t).filter(r=>!(r.chatId||"").startsWith("architect-"))}function Xn(n){let e=L(n);if(e.project&&e.kind)return[e.project,e.kind,e.intent,e.environment].filter(Boolean).join(":");let t=(n.messagePreview||"").toLowerCase().replace(/[^a-z0-9\s]/g," ").split(/\s+/).filter(r=>r.length>3).slice(0,6).join("-");return[n.channel||"unknown",t||"task"].join(":")}function Qn(n,e={}){let t=new Map;for(let s of n){let o=Xn(s),i=t.get(o)??[];i.push(s),t.set(o,i)}let r=Math.max(1,e.minClusterSize??3);return Array.from(t.entries()).map(([s,o])=>{let i=L(o[0]),a=(i.project?.05:0)+(i.kind?.05:0)+(i.intent?.1:0)+(i.environment?.05:0),d=.45+o.length*.1;return{key:s,traces:o.sort((l,p)=>p.startedAt-l.startedAt),confidence:Math.min(.95,d+a)}}).filter(s=>s.traces.length>=r).sort((s,o)=>o.confidence-s.confidence||o.traces.length-s.traces.length).slice(0,Math.max(1,e.max??10))}async function er(n,e,t={}){let r=[];for(let s of e){let o=s.traces[0],i=et(n,o.taskId),a=s.traces.map(l=>l.taskId),d=await it(o,i?.steps??[],{sourceTaskIds:a,confidence:s.confidence,generatedFrom:t.viaAgent||t.model?"llm-architect":"workflow-absorb",model:t.model,viaAgent:t.viaAgent,daemonUrl:t.daemonUrl,log:t.log});r.push({id:d.workflow.id,workflow:d.workflow,sourceTaskIds:a,confidence:s.confidence,reason:`${s.traces.length} similar successful task traces${d.usedLlm?` (LLM-architected via ${d.via})`:""}`,usedLlm:d.usedLlm,via:d.via})}return r}function ct(n){return n.nodes.find(r=>r.type.startsWith("trigger."))?.config?.inputSchema??null}function ut(n,e){if(!n||!e?.properties)return{};let t=n.match(/^([^:]+\/[^:]+):([^:]+):(.+)$/);if(!t)return{};let[,r,s,o]=t,i={};if(e.properties.project&&(i.project=r),s==="push"){let a=o.match(/^refs\/heads\/(.+)$/);a&&e.properties.ref&&(i.ref=a[1])}else{let a=Number(o);Number.isFinite(a)&&(e.properties.id&&(i.id=a),e.properties.iid&&(i.iid=a),e.properties.mrId&&(i.mrId=a),e.properties.issueId&&(i.issueId=a),e.properties.prId&&(i.prId=a))}return i}function pt(n,e){if(!n?.properties)return e;let t={...e};for(let[r,s]of Object.entries(n.properties))t[r]===void 0&&s&&"default"in s&&(t[r]=s.default);return t}function ft(n,e){return!n?.required||!Array.isArray(n.required)?[]:n.required.filter(t=>{let r=e[t];return r===void 0||r===""||r===null})}function tr(n,e){let t=ct(n);if(!t?.properties){let d={};for(let[l,p]of Object.entries(e))p!==void 0&&(d[l]=p);return{inputs:d,missing:[],filledFrom:{passthrough:Object.keys(d),chatId:[],defaults:[]}}}let r={};for(let d of["message","agentId","channel","chatId","senderId","senderUsername"])t.properties[d]&&e[d]!==void 0&&(r[d]=e[d]);let s=ut(e.chatId,t),o={...r,...s},i={...o};o=pt(t,o);let a=Object.keys(o).filter(d=>i[d]===void 0&&o[d]!==void 0);return{inputs:o,missing:ft(t,o),filledFrom:{passthrough:Object.keys(r),chatId:Object.keys(s),defaults:a}}}export{xe as a,k as b,x as c,Y as d,ce as e,pe as f,ge as g,Ze as h,Xe as i,Cr as j,et as k,Mr as l,tt as m,ve as n,An as o,Dn as p,ne as q,it as r,at as s,Un as t,Yn as u,Jn as v,Se as w,zn as x,Gn as y,Zn as z,Qn as A,er as B,Ut as C,tr as D};
|
|
47
|
-
//# sourceMappingURL=chunk-
|
|
47
|
+
//# sourceMappingURL=chunk-MTAPOCGA.js.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import{f as m}from"./chunk-
|
|
1
|
+
import{f as m}from"./chunk-BTHHSY7D.js";function y(t){let e=typeof t.node=="string"?t.node:"",n=typeof t.token=="string"?t.token:"";if(!e||!n)try{let o=m(t.config);e||(e=o.dashboard?.daemonUrl||""),n||(n=o.dashboard?.token||"")}catch{}return e||(e="http://localhost:18800"),{baseUrl:e.replace(/\/+$/,""),token:n}}async function d(t,e,n){let o={Accept:"application/json"};t.token&&(o.Authorization=`Bearer ${t.token}`);let r=await fetch(`${t.baseUrl}${e}`,{headers:o,signal:n});if(!r.ok)throw new Error(`GET ${e} \u2192 HTTP ${r.status}`);return await r.json()}function w(t,e){return d(t,"/agents",e)}async function R(t,e){return(await d(t,"/api/processes",e)).processes??[]}function S(t,e){return d(t,"/crons",e)}async function h(t,e,n,o){let r={Accept:"application/json","Content-Type":"application/json"};t.token&&(r.Authorization=`Bearer ${t.token}`);let s=await fetch(`${t.baseUrl}${e}`,{method:"POST",headers:r,body:JSON.stringify(n),signal:o}),a=await s.text(),i;try{i=a?JSON.parse(a):{}}catch{i={raw:a}}if(!s.ok)throw new Error(i?.error||`POST ${e} \u2192 HTTP ${s.status}`);return i}function P(t,e,n="tui"){return h(t,"/api/processes/kill",{...e,reason:n})}function A(t,e,n,o){return h(t,"/task",{agent:e,message:n,context:o??{channel:"tui",chatId:"tui:operator"}})}async function C(t,e,n,o={}){let r={Accept:"text/event-stream","Content-Type":"application/json"};t.token&&(r.Authorization=`Bearer ${t.token}`);let s=await fetch(`${t.baseUrl}/task`,{method:"POST",headers:r,body:JSON.stringify({agent:e,message:n,stream:!0,context:{channel:o.channel??"chat-cli",chatId:o.chatId??"chat-cli:operator"}}),signal:o.signal});if(!s.ok||!s.body){let g=await s.text().catch(()=>"");throw new Error(`POST /task (stream) \u2192 HTTP ${s.status}${g?`: ${g.slice(0,200)}`:""}`)}let a=s.body.getReader(),i=new TextDecoder,u={content:""},c="";try{for(;;){let{done:g,value:p}=await a.read();if(g)break;c+=i.decode(p,{stream:!0});let l;for(;(l=c.indexOf(`
|
|
2
2
|
|
|
3
3
|
`))>=0;){let k=c.slice(0,l);c=c.slice(l+2);let f=T(k);f&&b(f,o,u)}}}finally{try{a.releaseLock()}catch{}}return u}function b(t,e,n){let{event:o,data:r}=t;switch(o){case"text":r?.text&&(n.content+=r.text,e.onText?.(r.text));break;case"thinking":r?.text&&e.onThinking?.(r.text);break;case"tool":e.onTool?.(r);break;case"done":typeof r?.content=="string"&&(n.content=r.content),n.usage=r?.usage,n.duration=r?.duration;break;case"error":n.error=r?.error,n.errorKind=r?.errorKind;break}}function T(t){let e="message",n="";for(let r of t.split(`
|
|
4
4
|
`))r.startsWith("event: ")?e=r.slice(7).trim():r.startsWith("data: ")&&(n=r.slice(6));if(!n)return null;let o;try{o=JSON.parse(n)}catch{o=n}return{event:e,data:o}}export{y as a,w as b,R as c,S as d,P as e,A as f,C as g};
|
|
5
|
-
//# sourceMappingURL=chunk-
|
|
5
|
+
//# sourceMappingURL=chunk-O6YPEOQF.js.map
|