@yuandc/aica 0.1.62 → 0.1.63
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
import{CodexSubtaskExecutions as A}from"./subtask-executions.js";class O{routes=new Map;executions=new A;idleWaiters=new Set;reset(){this.routes.clear(),this.executions.reset(),this.resolveIdleWaiters(!1)}routeFor(t){return t?this.routes.get(t)??null:null}routesForSubscription(){return[...this.routes.values()]}activeThreadIds(){return this.executions.activeThreadIds()}hasActiveSubtasks(){return this.activeThreadIds().length>0}waitForIdle(t){return this.activeThreadIds().length===0?Promise.resolve({timedOut:!1,activeThreadIds:[]}):new Promise(s=>{const i={resolve:s,timer:setTimeout(()=>{this.idleWaiters.delete(i),s({timedOut:!0,activeThreadIds:this.activeThreadIds()})},t)};i.timer.unref(),this.idleWaiters.add(i)})}stopWaiting(){this.resolveIdleWaiters(!1)}acceptNotification(t,e,s){const i=this.executions.accept(t,e,
|
|
1
|
+
import{CodexSubtaskExecutions as A}from"./subtask-executions.js";class O{routes=new Map;executions=new A;idleWaiters=new Set;reset(){this.routes.clear(),this.executions.reset(),this.resolveIdleWaiters(!1)}routeFor(t){return t?this.routes.get(t)??null:null}routesForSubscription(){return[...this.routes.values()]}activeThreadIds(){return this.executions.activeThreadIds()}hasActiveSubtasks(){return this.activeThreadIds().length>0}waitForIdle(t){return this.activeThreadIds().length===0?Promise.resolve({timedOut:!1,activeThreadIds:[]}):new Promise(s=>{const i={resolve:s,timer:setTimeout(()=>{this.idleWaiters.delete(i),s({timedOut:!0,activeThreadIds:this.activeThreadIds()})},t)};i.timer.unref(),this.idleWaiters.add(i)})}stopWaiting(){this.resolveIdleWaiters(!1)}acceptNotification(t,e,s){const i=this.executions.accept(t,e,c(s));return this.hasActiveSubtasks()||this.resolveIdleWaiters(!1),i}restoreFromSessionSnapshot(t,e){const s=c(t),i=c(s.thread),n=a(i,"id")||e,o=c(s.initialTurnsPage),h=[...I(i,"turns"),...I(o,"data")];let u=0;for(const f of h){const l=c(f);for(const p of I(l,"items"))u+=this.observe({threadId:n,item:p},e,!0)}return u}observe(t,e,s=!1){const i=c(t),n=c(i.item);if(a(n,"type")==="subAgentActivity")return this.observeSubAgentActivity(n,a(i,"threadId"),e,s);if(!k(n))return 0;const o=a(n,"id");if(!o)return 0;const h=a(n,"senderThreadId")||a(i,"threadId"),u=this.routeFor(h||null),f=u?.parentToolCallId||o,l=Math.min(8,(u?.depth??0)+1),p=x(n),b=w(n.agentsStates);let T=0;for(const d of p){if(!d||d===e||d===h)continue;this.routes.has(d)||(this.routes.set(d,{parentToolCallId:f,sourceThreadId:d,depth:l}),T+=1);const m=b.get(d);if(!s){if(a(n,"tool")==="spawnAgent"){const S=this.executions.get(d);!this.executions.hasStart(d,o)&&(!S||!["pending","running"].includes(S.state))&&this.routes.set(d,{parentToolCallId:f,sourceThreadId:d,depth:l}),this.executions.start(this.routes.get(d),o,"pending",{description:a(n,"prompt")||void 0})}m?this.updateStatus(d,m):a(n,"tool")==="spawnAgent"&&this.updateStatus(d,"pending")}}return T}observeSubAgentActivity(t,e,s,i){const n=a(t,"kind"),o=a(t,"agentThreadId");if(!o||o===s||!i&&n==="started"&&this.executions.hasStart(o,a(t,"id")))return 0;if(n==="completed"||n==="interrupted")return i||this.updateStatus(o,n==="completed"?"completed":"interrupted"),0;if(n!=="started"&&n!=="interacted")return 0;const h=this.routeFor(e||null),u=h?.parentToolCallId||a(t,"id"),f=Math.min(8,(h?.depth??0)+1);if(!u)return 0;const l=this.routes.has(o)?0:1;if(l&&this.routes.set(o,{parentToolCallId:u,sourceThreadId:o,depth:f}),i)return l;if(n==="started"){const p=this.executions.get(o);(!p||!["pending","running"].includes(p.state))&&this.routes.set(o,{parentToolCallId:u,sourceThreadId:o,depth:f}),this.executions.start(this.routes.get(o),a(t,"id"),"running",{name:a(t,"agentPath").split("/").filter(Boolean).at(-1)}),this.updateStatus(o,"running")}return l}updateStatus(t,e){const s=this.routes.get(t);s&&this.executions.observeState(s,e),this.hasActiveSubtasks()||this.resolveIdleWaiters(!1)}resolveIdleWaiters(t){const e=this.activeThreadIds();for(const s of this.idleWaiters)clearTimeout(s.timer),s.resolve({timedOut:t,activeThreadIds:e});this.idleWaiters.clear()}}function w(r){const t=new Map,e=c(r);for(const[s,i]of Object.entries(e)){const n=y(a(c(i),"status"));s.trim()&&n!=="unknown"&&t.set(s.trim(),n)}return t}function y(r){switch(r.toLowerCase()){case"pending":case"pendinginit":return"pending";case"running":case"inprogress":case"in_progress":return"running";case"completed":case"shutdown":return"completed";case"failed":case"errored":case"notfound":return"failed";case"cancelled":case"canceled":case"interrupted":return"interrupted";default:return"unknown"}}function x(r){const t=c(r),e=new Set;g(e,t.newThreadId),g(e,t.receiverThreadId),C(e,t.receiverThreadIds);const s=t.agentsStates;if(Array.isArray(s))for(const i of s)v(e,i);else{const i=c(s);for(const[n,o]of Object.entries(i))v(e,o),W(n)&&e.add(n)}return[...e]}function k(r){const t=a(c(r),"type");return t==="collabAgentToolCall"||t==="collabToolCall"}function v(r,t){const e=c(t);for(const s of["threadId","thread_id","receiverThreadId","newThreadId"])g(r,e[s])}function g(r,t){typeof t=="string"&&t.trim()&&r.add(t.trim())}function C(r,t){if(Array.isArray(t))for(const e of t)g(r,e)}function I(r,t){const e=r[t];return Array.isArray(e)?e:[]}function W(r){return r.length<8?!1:!["pending","running","completed","failed","cancelled","canceled"].includes(r.toLowerCase())}function c(r){return r&&typeof r=="object"&&!Array.isArray(r)?r:{}}function a(r,t){const e=r[t];return typeof e=="string"?e:""}export{O as CodexSubtaskRouter,x as collaborationChildThreadIds,k as isCollaborationItem};
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const o="0.1.
|
|
1
|
+
const o="0.1.63";export{o as AICA_VERSION};
|