@yuandc/aica 0.1.2 → 0.1.4
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.
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import d from"node:fs";import T from"node:os";import y from"node:path";function k(n={}){const e=n.env??process.env,o=n.platform??process.platform,t=n.arch??process.arch,c=n.homeDir??T.homedir(),i=n.execPath??process.execPath,r=o==="win32"?y.win32:y.posix,s=l(e.CODEX_PATH);if(s){const u=D(s,e,o,r);return u?P(u,o,t,r)??u:s}const f=w([D("codex",e,o,r),...F(e,o,c,i,r)]);let a=null;for(const u of f){if(!u||!b(u,o))continue;const x=P(u,o,t,r);if(x)return x;if(!N(u))return u;a??=u}for(const u of O(e,o,c,i,r)){const x=m(u,o,t,r);if(x)return x}return a??"codex"}function F(n,e,o,t,c){const i=e==="win32"?"codex.exe":"codex",r=e==="win32"?"codex.cmd":"codex",s=l(n.npm_config_prefix),f=l(n.APPDATA),a=l(n.LOCALAPPDATA);return w([c.join(o,".codex","packages","standalone","current","bin",i),n.NVM_BIN?c.join(n.NVM_BIN,i):null,n.VOLTA_HOME?c.join(n.VOLTA_HOME,"bin",i):null,s?c.join(s,e==="win32"?"":"bin",r):null,c.join(c.dirname(t),r),e==="win32"&&f?c.join(f,"npm",r):null,e==="win32"&&a?c.join(a,"npm",r):null,e!=="win32"?c.join(o,".local","bin",i):null,e==="darwin"?"/opt/homebrew/bin/codex":null,e!=="win32"?"/usr/local/bin/codex":null,e!=="win32"?"/usr/bin/codex":null])}function O(n,e,o,t,c){const i=w([l(n.npm_config_prefix),l(n.NVM_BIN)?c.dirname(l(n.NVM_BIN)):null,c.dirname(c.dirname(t)),e==="win32"?l(n.APPDATA):null,e==="win32"?l(n.LOCALAPPDATA):null,e!=="win32"?c.join(o,".local"):null,e!=="win32"?"/usr/local":null,e!=="win32"?"/usr":null]);return w(i.flatMap(r=>_(r,e,c)))}function P(n,e,o,t){const c=g(n,e,t);for(const i of c){const r=m(i,e,o,t);if(r)return r}return null}function g(n,e,o){const t=[];let c=C(n)??n;c=o.dirname(c);for(let i=0;i<8;i+=1){o.basename(c)==="codex"&&o.basename(o.dirname(c))==="@openai"&&t.push(c),t.push(..._(c,e,o));const r=o.dirname(c);if(r===c)break;c=r}return w(t)}function _(n,e,o){return e==="win32"?[o.join(n,"node_modules","@openai","codex")]:[o.join(n,"lib","node_modules","@openai","codex"),o.join(n,"node_modules","@openai","codex")]}function m(n,e,o,t){if(!L(n))return null;const c=`codex-${e}-${o==="x64"?"x64":o}`,i=t.join(n,"node_modules","@openai",c);return j(i,e,t)??j(n,e,t)}function j(n,e,o,t=0){if(t>8||!L(n))return null;let c;try{c=d.readdirSync(n,{withFileTypes:!0})}catch{return null}const i=e==="win32"?"codex.exe":"codex";for(const r of c){const s=o.join(n,r.name);if(r.isFile()&&r.name.toLowerCase()===i&&b(s,e)&&!N(s))return s}for(const r of c){if(!r.isDirectory())continue;const s=j(o.join(n,r.name),e,o,t+1);if(s)return s}return null}function D(n,e,o,t){if(t.isAbsolute(n)||n.includes("/")||n.includes("\\"))return b(n,o)?n:null;const c=o==="win32"?n.includes(".")?[""]:(e.PATHEXT||".EXE;.CMD;.BAT;.COM").split(";").map(r=>r.toLowerCase()):[""],i=o==="win32"?";":":";for(const r of(e.PATH||"").split(i)){const s=l(r);if(s)for(const f of c){const a=t.join(s,`${n}${f}`);if(b(a,o))return a}}return null}function b(n,e){try{return d.accessSync(n,e==="win32"?d.constants.F_OK:d.constants.X_OK),d.statSync(n).isFile()}catch{return!1}}function L(n){try{return d.statSync(n).isDirectory()}catch{return!1}}function N(n){const e=C(n)??n;if(/\.(?:js|mjs|cjs|cmd|bat)$/i.test(e))return!0;try{const o=d.readFileSync(e,{encoding:"utf8",flag:"r"}).slice(0,256);return/^#!.*\bnode\b/m.test(o)}catch{return!1}}function C(n){try{return d.realpathSync(n)}catch{return null}}function l(n){return n?.trim().replace(/^(?:"(.*)"|'(.*)')$/,"$1$2")||null}function w(n){return[...new Set(n.filter(e=>e!=null))]}export{k as resolveCodexPath};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{spawn as
|
|
1
|
+
import{spawn as p}from"node:child_process";import{acpChildEnvironment as n}from"../../../core/process-identity.js";import{resolveCodexPath as s}from"./codex-path.js";import{resolveCodexPath as v}from"./codex-path.js";function c(r){const o=s(),e=["app-server","--stdio"],t=p(o,e,{cwd:r,env:n({CODEX_PATH:o}),stdio:["pipe","pipe","pipe"]});return t.stdout.setEncoding("utf8"),t.stderr.setEncoding("utf8"),{command:o,args:e,child:t}}export{v as resolveCodexPath,c as startCodexAppServer};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Agent as
|
|
1
|
+
import{Agent as w}from"undici";import{loadAcaConfig as p}from"./aca-config.js";const $=new w({connect:{rejectUnauthorized:!1}});async function S(e,c,n,o={}){const s=p(),t=(o.serverUrl||s.serverUrl).replace(/\/$/,""),i=o.token??s.token,u={...n===void 0?{}:{"content-type":"application/json"},...i?{authorization:`Bearer ${i}`}:{}},a=await fetch(`${t}${c}`,{method:e,headers:u,...n===void 0?{}:{body:JSON.stringify(n)},...h(t)}),f=await a.text(),r=f?JSON.parse(f):null;if(!a.ok){const l=r&&typeof r=="object"&&"message"in r?String(r.message):`HTTP ${a.status}`;throw new Error(l)}return r}async function d(e,c={}){const n=p(),o=(c.serverUrl||n.serverUrl).replace(/\/$/,""),s=c.token??n.token,t=await fetch(`${o}${e}`,{method:"GET",headers:s?{authorization:`Bearer ${s}`}:{},...h(o)});if(!t.ok)throw new Error(`附件下载失败 HTTP ${t.status}`);return Buffer.from(await t.arrayBuffer())}async function k(e,c,n,o={},s={}){const t=p(),i=(s.serverUrl||t.serverUrl).replace(/\/$/,""),u=s.token??t.token,a=await fetch(`${i}${c}`,{method:e,headers:{...o,...u?{authorization:`Bearer ${u}`}:{}},body:n,duplex:"half",...h(i)}),f=await a.text(),r=f?JSON.parse(f):null;if(!a.ok){const l=r&&typeof r=="object"&&"message"in r?String(r.message):`HTTP ${a.status}`;throw new Error(l)}return r}function h(e){return!/^https:/i.test(e)||!g(process.env.ACA_SERVER_INSECURE_TLS)?{}:{dispatcher:$}}function g(e){return e==="1"||e?.toLowerCase()==="true"||e?.toLowerCase()==="yes"}export{d as acaServerDownload,S as acaServerRequest,k as acaServerStreamRequest};
|
package/dist/core/job-worker.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import W from"node:crypto";import
|
|
2
|
-
localPath: ${
|
|
3
|
-
workspacePath: ${
|
|
1
|
+
import W from"node:crypto";import x from"node:fs";import S from"node:path";import{compactAgentContext as V,sendAgentPrompt as q}from"../acp/agent.js";import{acaServerDownload as D,acaServerRequest as b}from"./aca-server-client.js";import{loadAcaConfig as H}from"./aca-config.js";import{prepareLocalWorktree as G}from"./worktree.js";import{getAcaHome as $}from"./paths.js";import{collectAffectedFiles as N,extractAffectedFilePathsFromAcpRaw as K}from"./affected-files.js";import{resolveJobPermissionPolicy as X}from"./job-permission-policy.js";import{appendCoalescedAcpEvent as Z}from"./acp-event-coalescer.js";import{shouldUploadAcpEvent as Q}from"./acp-event-upload-filter.js";const Y=1500,ee=5e3,M=1e3,te=320,ne=64,O=900,oe=1e4,ae=0,ie=12e3;function re(e){return e?e==="~"?S.dirname($()):e.startsWith("~/")?S.join(S.dirname($()),e.slice(2)):e:""}function se(e){const t=e.project_metadata;return t&&typeof t=="object"&&!Array.isArray(t)&&t.kind==="chat"?!0:typeof e.project_root_path=="string"&&(e.project_root_path.startsWith("~/.aca/chats/")||/(^|\/)\.aca\/chats\//.test(e.project_root_path))}function Ve(e,t={}){let n=!1,o=null,a=null;const i=new Set,c=new Set,u=new Map,s=async()=>{if(n)return;const r=ce();if(U(i.size,r))try{const m=t.loadConfig?.()??H();if(!m.token)return;for(;!n&&U(i.size,r);){const A=t.claimNextJob?await t.claimNextJob(m):await b("POST","/api/client/jobs/claim",{machineId:m.machineId,workspaceId:m.defaultWorkspaceId});if(!A.item)break;const d=A.item;if(n){await(t.cancelClaimedJob?t.cancelClaimedJob(d,m):P(d.job_id,m.machineId,"cancelled")).catch(()=>{});break}const f=d.session_id;c.has(f)&&e.warn(`claimed job=${d.job_id} for already active session=${f}; running anyway to avoid leaving it stuck`),i.add(d.job_id),c.add(f);const I=new AbortController,C=(t.runJob??ue)(d,m,e,I).catch(p=>{e.warn(`job ${d.job_id} failed outside handler: ${p instanceof Error?p.message:String(p)}`)}).finally(()=>{i.delete(d.job_id),c.delete(f),u.delete(d.job_id)});u.set(d.job_id,{controller:I,promise:C})}}catch(m){n||e.warn(`job worker failed: ${m instanceof Error?m.message:String(m)}`)}},w=()=>{if(n||o)return;const r=s();o=r,r.finally(()=>{o===r&&(o=null)})};w();const T=setInterval(()=>{w()},t.claimIntervalMs??Y);return{timer:T,stop:()=>a||(a=(async()=>{if(n)return;n=!0,clearInterval(T);for(const m of u.values())m.controller.abort();await o?.catch(()=>{});for(const m of u.values())m.controller.abort();const r=[...u.values()].map(m=>m.promise);r.length!==0&&await Promise.race([Promise.allSettled(r).then(()=>{}),E(ie)])})(),a)}}function ce(){const e=process.env.ACA_MAX_CONCURRENT_JOBS||process.env.ACA_MAX_CONCURRENT_PROJECT_JOBS||"",t=Number.parseInt(e,10);return!e.trim()||!Number.isFinite(t)||t<0?ae:t===0?0:Math.max(1,Math.min(t,8))}function U(e,t){return t===0||e<t}function le(){const e=Number.parseInt(process.env.ACA_ACP_EVENT_BATCH_INTERVAL_MS||"",10);return Number.isFinite(e)?Math.max(40,Math.min(e,2e3)):te}async function ue(e,t,n,o){const a=e.job_id,i=e.session_id,c=e.workspace_id,u=e.project_id??null,s=e.input??{},w=String(s.control?.type||"").toLowerCase();if(!w&&!s.message?.trim()&&(s.attachments??[]).length===0){await P(a,t.machineId,"job input missing message");return}const T=t.projects.find(p=>p.projectId===u),r=re(T?.rootPath||e.project_root_path||"");if(!r){await P(a,t.machineId,"job project root is unknown");return}se(e)&&x.mkdirSync(r,{recursive:!0}),n.info(`claimed job=${a} session=${i} project=${T?.name??u??"unknown"}`);const m=setInterval(()=>{b("POST",`/api/client/jobs/${encodeURIComponent(a)}/heartbeat`,{machineId:t.machineId}).catch(()=>{}),Re(a,o).catch(()=>{})},ee);let A=0;const d=we(a,t.machineId),f=be(a,t.machineId),I=new Set;let C=null;try{await f.sendNow({phase:"initializing",label:"准备工作区",detail:e.worktree_id?"worktree":"project root"}).catch(()=>{});const p=G({projectId:u,sessionId:i,projectRoot:r,worktree:e});C=p,await Pe(a,t.machineId,p);const g=pe(s.acpRun);if(w==="compact"){if(!e.acp_session_id)throw new Error("Current session does not have an ACP context to compact");const l=await V({agentType:k(g.agentType,"codex"),cliType:k(g.cliType,"builtin"),acpSessionId:e.acp_session_id,cwd:p.cwd,model:s.model,mode:s.mode,configOptionValues:s.configOptionValues,timeoutMs:s.timeoutMs,allowRollover:s.control?.allowRollover===!0,signal:o.signal,onStatus:y=>{f.report({phase:y.phase,label:y.label,detail:y.detail,updateType:y.updateType,raw:y})}});await f.flush(),await b("POST",`/api/client/jobs/${encodeURIComponent(a)}/complete`,{machineId:t.machineId,acpSessionId:l.acpSessionId,suppressTurn:!0,result:{ok:!0,control:{type:"compact",allowRollover:s.control?.allowRollover===!0},acpSessionId:l.acpSessionId,durationMs:l.durationMs,usage:l.contextUsage,maintenance:l.maintenance,worktree:R(p)}}),n.info(`completed context compact job=${a}`);return}const _=await ge({cwd:p.cwd,sessionId:i,jobId:a,attachments:s.attachments??[]});_.length>0&&(n.info(`materialized ${_.length} attachment(s) for job=${a}`),await f.sendNow({phase:"initializing",label:"附件已写入本机",detail:_.map(l=>l.relativePath).join(", "),raw:{attachments:z(_)}}).catch(()=>{}));const j=Ie(s,_),F=_e(j,_),h=await q({agentType:k(g.agentType,"codex"),cliType:k(g.cliType,"builtin"),acpSessionId:e.acp_session_id??null,prompt:j,promptBlocks:F,cwd:p.cwd,model:s.model,mode:s.mode,configOptionValues:s.configOptionValues,canExecuteTools:s.canExecuteTools,timeoutMs:s.timeoutMs,contextWindow:de(g.contextWindow),signal:o.signal,onStatus:l=>{f.report({phase:l.phase,label:l.label,detail:l.detail,updateType:l.updateType,raw:l})},onUpdate:l=>{A+=1;for(const L of K(l.raw))I.add(L);const y={turnId:e.user_turn_id??null,eventType:l.type,label:l.label,text:l.text,status:l.status,toolCallId:l.toolCallId,raw:ye(l.raw,A)};Q(y)&&d.push(y)},onPermissionRequest:l=>{const y=X(s,l);return y?Promise.resolve(y):ve(a,t.machineId,l,o.signal)},onUserInputRequest:l=>ke(a,t.machineId,l,o.signal)});await d.flush(),await f.flush();const J=N({cwd:p.cwd,evidencePaths:I}),v=fe(h.promptResponse);if(!(he(v)||!!h.content)){await P(a,t.machineId,`${h.agentType} stopped: ${v??"unknown"}`,{acpSessionId:h.acpSessionId,stopReason:v,exitCode:h.exitCode,stderr:xe(h.stderr,4e3),worktree:R(p)});return}await b("POST",`/api/client/jobs/${encodeURIComponent(a)}/complete`,{machineId:t.machineId,acpSessionId:h.acpSessionId,assistantText:h.content,result:{ok:!0,acpSessionId:h.acpSessionId,stopReason:v,durationMs:h.durationMs,acpRun:s.acpRun??null,effectiveConfig:h.effectiveConfig??null,performance:h.performance??null,usage:h.contextUsage??null,updateCount:h.updates.length,statusTimeline:h.statusTimeline,worktree:R(p),attachments:z(_),files:J}}),n.info(`completed job=${a}`)}catch(p){await d.flush(),await f.flush();const g=o.signal.aborted?"cancelled":p instanceof Error?p.message:String(p),_=C?N({cwd:C.cwd,evidencePaths:I}):[];await P(a,t.machineId,me(g),{rawError:g,files:_})}finally{await d.flush(),await f.flush(),clearInterval(m)}}function me(e){return/ACP request timed out/i.test(e)?"ACP 长时间没有完成,请稍后重试,或点击停止后重新发送。":/MimoCode request timed out/i.test(e)?"MimoCode 长时间没有完成,请稍后重试,或点击停止后重新发送。":e.replace(/\bsession\/prompt\b/g,"ACP 请求")}function pe(e){return!e||typeof e!="object"||Array.isArray(e)?{}:e}function de(e){return typeof e=="number"&&Number.isFinite(e)&&e>0?e:void 0}function k(...e){for(const t of e)if(typeof t=="string"&&t.trim())return t.trim();return""}function fe(e){if(!e||typeof e!="object"||Array.isArray(e))return;const t=e;if(typeof t.stopReason=="string")return t.stopReason;if(typeof t.reason=="string")return t.reason;const n=t.part;if(n&&typeof n=="object"&&!Array.isArray(n)&&typeof n.reason=="string")return n.reason}function he(e){return e?["end_turn","stop","completed","complete"].includes(e):!1}function we(e,t){let n=[],o=null,a=Promise.resolve();const i=async s=>{s.length!==0&&await b("POST",`/api/client/jobs/${encodeURIComponent(e)}/events/batch`,{machineId:t,events:s})},c=()=>{o&&(clearTimeout(o),o=null);const s=n;return n=[],a=a.then(()=>i(s)).catch(()=>{}),a},u=()=>{o||(o=setTimeout(()=>{c()},le()),o.unref())};return{push(s){if(Z(n,s),n.length>=ne){c();return}u()},flush:c}}function be(e,t){let n=null,o=0,a="",i=null,c=Promise.resolve();const u=r=>JSON.stringify({phase:r.phase??"",label:r.label??"",detail:r.detail??"",updateType:r.updateType??""}),s=async r=>{await b("POST",`/api/client/jobs/${encodeURIComponent(e)}/presence`,{machineId:t,phase:r.phase,label:r.label,detail:r.detail,updateType:r.updateType,raw:r.raw}),o=Date.now(),a=u(r)},w=()=>{if(i&&(clearTimeout(i),i=null),!n)return c;const r=n;return n=null,c=c.then(()=>s(r)).catch(()=>{}),c},T=r=>{i||(i=setTimeout(()=>{w()},r),i.unref())};return{report(r){const m=Date.now(),d=u(r)!==a,f=m-o>=oe;if(!d&&!f)return;n=r;const I=m-o;if(I>=O||o===0){w();return}T(O-I)},sendNow(r){return n=r,w()},flush:w}}function ye(e,t){return e&&typeof e=="object"&&!Array.isArray(e)?{...e,acaSequence:t}:{value:e,acaSequence:t}}function Ie(e,t=[]){const n=e?.message?.trim()??"";if(t.length===0)return n;const a=["用户随消息上传了以下附件,aca 已将附件写入本机工作区。需要读取附件时请直接使用下面的 localPath;图片附件也已作为 ACP image block 随本轮请求传入。",...t.map((i,c)=>`${c+1}. ${i.name} (${i.kind}, ${i.mimeType}, ${Ce(i.size)})
|
|
2
|
+
localPath: ${i.path}
|
|
3
|
+
workspacePath: ${i.relativePath}`)].join(`
|
|
4
4
|
`);return n?`${n}
|
|
5
5
|
|
|
6
|
-
${
|
|
6
|
+
${a}`:a}function _e(e,t){const n=[{type:"text",text:e}];for(const o of t)o.kind!=="image"||!o.mimeType.startsWith("image/")||n.push({type:"image",data:o.base64,mimeType:o.mimeType,uri:o.path});return n}async function ge(e){if(e.attachments.length===0)return[];const t=S.join(e.cwd,".aca","attachments",B(e.sessionId),B(e.jobId));x.mkdirSync(t,{recursive:!0});const n=[];for(const[o,a]of e.attachments.entries()){const i=a.attachmentId?{mimeType:a.mimeType||"application/octet-stream",bytes:await D(`/api/client/attachments/${encodeURIComponent(a.attachmentId)}`)}:Te(a.dataUrl??""),c=a.mimeType||i.mimeType||"application/octet-stream",u=a.kind==="image"||c.startsWith("image/")?"image":"file",s=Se(a.name||`attachment-${o+1}`,c),w=S.join(t,`${String(o+1).padStart(2,"0")}-${s}`);x.writeFileSync(w,i.bytes),n.push({name:a.name||s,mimeType:c,size:i.bytes.byteLength,kind:u,path:w,relativePath:S.relative(e.cwd,w),base64:i.bytes.toString("base64"),sha256:W.createHash("sha256").update(i.bytes).digest("hex")})}return n}function Te(e){const t=e.indexOf(",");if(!e.startsWith("data:")||t<0)throw new Error("attachment dataUrl is not a data URL");const n=e.slice(5,t),o=e.slice(t+1),a=n.split(";").filter(Boolean),i=a[0]?.includes("/")?a[0]:"application/octet-stream";if(!a.includes("base64"))throw new Error("attachment dataUrl is not base64 encoded");return{mimeType:i,bytes:Buffer.from(o,"base64")}}function Se(e,t){const n=S.basename(e).replace(/[<>:"/\\|?*\x00-\x1F]/g,"_").trim(),o=`attachment${Ae(t)}`;return(!n||n==="."||n===".."?o:n).slice(0,180)}function Ae(e){switch(e.toLowerCase()){case"image/png":return".png";case"image/jpeg":return".jpg";case"image/webp":return".webp";case"image/gif":return".gif";case"text/plain":return".txt";case"application/json":return".json";case"text/markdown":case"text/x-markdown":return".md";case"application/pdf":return".pdf";case"application/msword":return".doc";case"application/vnd.openxmlformats-officedocument.wordprocessingml.document":return".docx";case"application/vnd.ms-excel":return".xls";case"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet":return".xlsx";case"application/vnd.ms-powerpoint":return".ppt";case"application/vnd.openxmlformats-officedocument.presentationml.presentation":return".pptx";case"application/zip":return".zip";case"application/x-7z-compressed":return".7z";case"application/x-rar-compressed":case"application/vnd.rar":return".rar";case"application/gzip":return".gz";case"application/x-tar":return".tar";default:return""}}function B(e){return e.replace(/[^a-zA-Z0-9._-]+/g,"-").replace(/^-+|-+$/g,"").slice(0,80)||"item"}function z(e){return e.map(t=>({name:t.name,kind:t.kind,mimeType:t.mimeType,size:t.size,path:t.path,relativePath:t.relativePath,sha256:t.sha256}))}function Ce(e){if(!Number.isFinite(e)||e<=0)return"0 B";const t=["B","KB","MB","GB"];let n=e,o=0;for(;n>=1024&&o<t.length-1;)n/=1024,o+=1;return`${n>=10||o===0?n.toFixed(0):n.toFixed(1)} ${t[o]}`}async function Pe(e,t,n){!n.usedWorktree||!n.worktreeId||await b("POST",`/api/client/jobs/${encodeURIComponent(e)}/worktree`,{machineId:t,baseCommit:n.baseCommit??null,worktreePath:n.cwd,status:n.status??"active",raw:n.raw??R(n)})}function R(e){return{usedWorktree:e.usedWorktree,worktreeId:e.worktreeId??null,cwd:e.cwd,status:e.status??null,baseCommit:e.baseCommit??null,branchName:e.branchName??null,baseBranch:e.baseBranch??null}}async function ve(e,t,n,o){const i=(await b("POST",`/api/client/jobs/${encodeURIComponent(e)}/permissions`,{machineId:t,request:n})).item.permission_id;for(;!o.aborted;){await E(M);const c=await b("GET",`/api/client/permissions/${encodeURIComponent(i)}`);if(c.item.status==="resolved"&&c.item.response){const u=c.item.response.outcome;return u.outcome==="selected"?{outcome:u}:{outcome:{outcome:"cancelled"}}}}return{outcome:{outcome:"cancelled"}}}async function ke(e,t,n,o){const i=(await b("POST",`/api/client/jobs/${encodeURIComponent(e)}/permissions`,{machineId:t,request:{kind:"elicitation",...n}})).item.permission_id;for(;!o.aborted;){await E(M);const c=await b("GET",`/api/client/permissions/${encodeURIComponent(i)}`);if(c.item.status==="resolved"&&c.item.response){const u=c.item.response.outcome;return u.outcome==="submitted"?{outcome:u}:{outcome:{outcome:"cancelled"}}}}return{outcome:{outcome:"cancelled"}}}async function Re(e,t){if(t.signal.aborted)return;const n=await b("GET",`/api/client/jobs/${encodeURIComponent(e)}`);Number(n.item.cancel_requested??0)===1&&t.abort()}async function P(e,t,n,o){await b("POST",`/api/client/jobs/${encodeURIComponent(e)}/fail`,{machineId:t,error:n,result:o})}function E(e){return new Promise(t=>setTimeout(t,e))}function xe(e,t){return e.length<=t?e:`${e.slice(0,t)}...`}export{Ve as startJobWorkerLoop};
|
package/dist/worker-cli.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{Command as a}from"commander";import n from"node:path";import{createStartCommand as m}from"./commands/start.js";import{createWorkerAuthCommand as t}from"./commands/worker-auth.js";import{createWorkerProjectCommand as s}from"./commands/worker-project.js";import{DEFAULT_ACA_SERVER_URL as c}from"./core/aca-config.js";process.env.ACA_DEFAULT_SERVER_URL||=c;async function i(r=process.argv){const o=new a;o.name("aica").description("AICA remote Agent worker").version("0.1.
|
|
2
|
+
import{Command as a}from"commander";import n from"node:path";import{createStartCommand as m}from"./commands/start.js";import{createWorkerAuthCommand as t}from"./commands/worker-auth.js";import{createWorkerProjectCommand as s}from"./commands/worker-project.js";import{DEFAULT_ACA_SERVER_URL as c}from"./core/aca-config.js";process.env.ACA_DEFAULT_SERVER_URL||=c;async function i(r=process.argv){const o=new a;o.name("aica").description("AICA remote Agent worker").version("0.1.4").enablePositionalOptions(),o.addCommand(m()),o.addCommand(t()),o.addCommand(s()),await o.parseAsync(r)}const d=process.argv[1]||"",e=n.basename(d).replace(/\.(?:js|ts|cjs|mjs)$/i,"");(e==="worker-cli"||e==="aica"||e==="aca")&&i().catch(r=>{const o=r instanceof Error?r.message:String(r);console.error(o),process.exitCode=1});export{i as runWorkerCli};
|