@yuandc/aica 0.1.91 → 0.1.93
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/dist/acp/providers/workbuddy/launch.js +1 -1
- package/dist/core/workbuddy-credits/checkin.js +1 -0
- package/dist/core/workbuddy-credits/query.js +1 -1
- package/dist/core/workbuddy-credits/scheduler.js +1 -1
- package/dist/core/workbuddy-credits/worker.js +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{installedProviderEntry as d,entryLaunch as m}from"../../../core/provider-install-paths.js";import
|
|
1
|
+
import{installedProviderEntry as d,entryLaunch as m}from"../../../core/provider-install-paths.js";import o from"node:fs";import r from"node:path";import{createHash as D}from"node:crypto";import{workBuddyRegionEnv as p}from"./auth-environment.js";function E(e=!0){const s=process.env.ACA_WORKBUDDY_COMMAND||process.env.ACA_CODEBUDDY_COMMAND||"codebuddy",n=_(s),t=[...n.args,"--acp"];e?t.push("--settings",JSON.stringify({enableAllProjectMcpServers:!0})):t.push("--tools","","--strict-mcp-config","--mcp-config",'{"mcpServers":{}}');const c={CODEBUDDY_CODE_DISABLE_BACKGROUND_TASKS:"1",...p()},a=D("sha256").update(JSON.stringify({command:n.command,args:t,env:c,configDir:process.env.CODEBUDDY_CONFIG_DIR,region:process.env.CODEBUDDY_INTERNET_ENVIRONMENT,apiKey:process.env.CODEBUDDY_API_KEY,authToken:process.env.CODEBUDDY_AUTH_TOKEN})).digest("hex");return{command:n.command,args:t,env:c,runtimeIdentity:a}}function _(e){if(e==="codebuddy"&&!process.env.ACA_WORKBUDDY_COMMAND&&!process.env.ACA_CODEBUDDY_COMMAND){const n=d("workbuddy");if(n)return m(n)}if(/\.[cm]?js$/i.test(e)||/[/\\]/.test(e)&&u(e))return{command:i(r.dirname(r.resolve(e))),args:[r.resolve(e)]};if(process.platform!=="win32")return{command:e,args:[]};const s=r.isAbsolute(e)||/[/\\]/.test(e)?[r.dirname(r.resolve(e))]:(process.env.PATH||"").split(r.delimiter);for(const n of s){const t=r.join(n,"node_modules","@tencent-ai","codebuddy-code","bin","codebuddy");if(o.existsSync(t)&&/^(codebuddy(?:-code)?|cbc)(?:\.cmd)?$/i.test(r.basename(e)))return{command:i(n),args:[t]};const c=r.join(n,/\.exe$/i.test(e)?r.basename(e):`${r.basename(e)}.exe`);if(o.existsSync(c))return{command:c,args:[]}}if(/\.cmd$/i.test(e))throw new Error("WorkBuddy 无法解析 CodeBuddy npm 启动入口,请将 ACA_WORKBUDDY_COMMAND 指向官方 bin/codebuddy 的 JS 包装文件或原生 exe。");return{command:e,args:[]}}function i(e){if(process.env.ACA_WORKBUDDY_NODE)return process.env.ACA_WORKBUDDY_NODE;const s=r.join(e,"node.exe");return process.platform==="win32"&&o.existsSync(s)?s:process.isSea||process.env.ACA_SINGLE_FILE_WORKER==="1"?"node":process.execPath}function u(e){let s;try{s=o.openSync(e,"r");const n=Buffer.alloc(128),t=o.readSync(s,n,0,n.length,0);return/^#![^\r\n]*\bnode\b/.test(n.subarray(0,t).toString("utf8"))}catch{return!1}finally{s!==void 0&&o.closeSync(s)}}function v(){const e=Number(process.env.ACA_WORKBUDDY_PROMPT_TIMEOUT_MS||process.env.ACA_ACP_PROMPT_TIMEOUT_MS);return Number.isSafeInteger(e)&&e>=3e4?e:720*60*1e3}export{_ as resolveWorkBuddyExecutable,E as resolveWorkBuddyLaunch,v as workBuddyTimeout};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{record as i}from"../../acp/providers/workbuddy/config.js";const h=new Intl.DateTimeFormat("en-GB",{timeZone:"Asia/Shanghai",hour:"2-digit",hourCycle:"h23"});function d(t){const e=Number(h.format(t));return e>=7&&e<19}async function w(t){try{const e=t.now??Date.now;if(!d(e()))return;const r=AbortSignal.timeout(8e3),o=async s=>{const n=await(t.fetch??fetch)(`https://www.codebuddy.cn/v2/billing/meter/${s}`,{method:"POST",headers:t.headers,redirect:"error",signal:r,body:"{}"});if(!n.ok){await n.body?.cancel();return}const c=i(await n.json());if(c.code===0)return i(c.data)},a=await o("checkin-activity-status");if(a?.active!==!0||a.today_checked_in!==!1||r.aborted||!d(e()))return;await o("daily-checkin")}catch{}}export{w as checkinWorkBuddy,d as inWorkBuddyCheckinWindow};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createWorkBuddyAuthTransport as
|
|
1
|
+
import{createWorkBuddyAuthTransport as T}from"../../acp/providers/workbuddy/auth-transport.js";import{enterWorkBuddyTask as _}from"../../acp/providers/workbuddy/auth-gate.js";import{workBuddyRegion as R,workBuddyEnvironmentCredentials as S}from"../../acp/providers/workbuddy/auth-environment.js";import{record as s}from"../../acp/providers/workbuddy/config.js";import{checkinWorkBuddy as P}from"./checkin.js";function m(n,t=null){return{state:n,account:t,remaining:null,total:null,unlimited:!1,resources:[]}}function h(n){if(typeof n!="number"&&(typeof n!="string"||!/^-?\d+(?:\.\d+)?$/.test(n)))return;const t=Number(n);return Number.isFinite(t)?t:void 0}function A(n){const t=[];for(const r of n){const e=s(r);if(e.Status!==void 0&&![0,3].includes(Number(e.Status)))continue;const a=h(e.CycleCapacityRemainPrecise??e.CycleCapacityRemain??e.CapacityRemainPrecise??e.CapacityRemain),i=h(e.CycleCapacitySizePrecise??e.CycleCapacitySize??e.CapacitySizePrecise??e.CapacitySize),c=e.Unlimited===!0||e.Unlimited===1||i===-1;if(a===void 0||i===void 0||!c&&(i<0||a<0))throw new Error("invalid_credits");const g=typeof e.CycleEndTime=="string"&&e.CycleEndTime.length<=100?e.CycleEndTime:null;t.push({name:typeof e.PackageName=="string"?e.PackageName.slice(0,200):"积分套餐",remaining:a,total:i,unlimited:c,cycleEnd:g})}const o=t.some(r=>r.unlimited),l=r=>Math.round(t.reduce((e,a)=>e+a[r],0)*100)/100;return{remaining:o?null:l("remaining"),total:o?null:l("total"),unlimited:o,resources:t}}async function U(n={}){let t=null,o,l;try{l=_();const r=R();o=(n.transport??T)(),await o.initialize();const e=await o.billingIdentity();if(!e.account)return m(S()?"unsupported":"signed_out");if(t={...e.account,region:r,scope:e.enterpriseId.slice(0,200)},r==="ioa"||!e.token)return m("unsupported",t);const a=r==="internal"?"https://www.codebuddy.cn":"https://www.codebuddy.ai",i={Authorization:`Bearer ${e.token}`,"Content-Type":"application/json",Accept:"application/json","X-User-Id":t.id};e.enterpriseId&&(i["X-Enterprise-Id"]=e.enterpriseId,i["X-Tenant-Id"]=e.enterpriseId),n.allowCheckin&&r==="internal"&&await P({headers:i,fetch:n.fetch,now:n.now});const c=[],g=AbortSignal.timeout(25e3),C=new Date,w=new Date(C);w.setUTCFullYear(w.getUTCFullYear()+101);const b=p=>p.toISOString().slice(0,19).replace("T"," ");for(let p=1;p<=10;p++){const d=await(n.fetch??fetch)(`${a}/v2/billing/meter/get-user-resource`,{method:"POST",headers:i,redirect:"error",signal:g,body:JSON.stringify({PageNumber:p,PageSize:100,ProductCode:"p_tcaca",Status:[0,3],PackageEndTimeRangeBegin:b(C),PackageEndTimeRangeEnd:b(w)})});if(d.status===429){const f=d.headers.get("Retry-After"),E=f&&/^\d+$/.test(f)?Number(f)*1e3:Date.parse(f||"")-Date.now();return{...m("error",t),retryAfterMs:Number.isFinite(E)?Math.max(0,E):3e5}}if(d.status===401||d.status===403)return m("signed_out");if(!d.ok)throw new Error("credits_http_error");const u=s(await d.json());if(u.code!==void 0&&![0,"0"].includes(u.code))throw new Error("credits_business_error");const y=s(s(s(u.data).Response??u.Response).Data);if(s(s(u.data).Response??u.Response).Error||!Array.isArray(y.Accounts))throw new Error("invalid_credits_response");c.push(...y.Accounts);const k=h(y.TotalCount);if(y.Accounts.length<100||k!==void 0&&c.length>=k)return{state:"ready",account:t,...A(c)}}throw new Error("credits_page_limit")}catch{return m("error",t)}finally{try{await o?.close()}finally{l?.()}}}export{m as emptyCredits,A as parseCreditsResources,U as queryWorkBuddyCredits};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{emptyCredits as r}from"./query.js";import{ACTIVE_CREDITS_INTERVAL_MS as n,IDLE_CREDITS_INTERVAL_MS as u}from"./types.js";class y{query;changed;now;value={...r("error"),fetchedAtMs:null,checkedAtMs:null,revision:0};lastAttempt=-1/0;retryAt=0;limitedUntil=0;failures=0;dirty=!1;active=0;epoch=0;timer;pending;running=!1;constructor(t,s,e=Date.now){this.query=t,this.changed=s,this.now=e}snapshot(){return this.value}start(){this.running||(this.running=!0,this.tick())}async stop(){this.running=!1,clearTimeout(this.timer),await this.pending}beginUsage(){this.active++,this.dirty=!0,this.running&&this.tick();let t=!1;return()=>{t||(t=!0,this.active--,this.dirty=!0,this.running&&this.tick())}}reset(){this.epoch++,this.lastAttempt=-1/0,this.retryAt=0,this.limitedUntil=0,this.failures=0,this.dirty=!1,this.value={...r("error"),fetchedAtMs:null,checkedAtMs:null,revision:this.value.revision+1},this.changed(this.value),this.running&&(this.pending??Promise.resolve()).then(()=>{if(this.running)return this.tick()})}nextDue(){const t=this.dirty||this.active||this.failures?n:u;return Math.max(this.lastAttempt+t,this.retryAt,this.limitedUntil)}async tick(){
|
|
1
|
+
import{emptyCredits as r}from"./query.js";import{ACTIVE_CREDITS_INTERVAL_MS as n,IDLE_CREDITS_INTERVAL_MS as u}from"./types.js";class y{query;changed;now;value={...r("error"),fetchedAtMs:null,checkedAtMs:null,revision:0};lastAttempt=-1/0;retryAt=0;limitedUntil=0;failures=0;dirty=!1;active=0;epoch=0;timer;pending;running=!1;constructor(t,s,e=Date.now){this.query=t,this.changed=s,this.now=e}snapshot(){return this.value}start(){this.running||(this.running=!0,this.tick())}async stop(){this.running=!1,clearTimeout(this.timer),await this.pending}beginUsage(){this.active++,this.dirty=!0,this.running&&this.tick();let t=!1;return()=>{t||(t=!0,this.active--,this.dirty=!0,this.running&&this.tick())}}reset(){this.epoch++,this.lastAttempt=-1/0,this.retryAt=0,this.limitedUntil=0,this.failures=0,this.dirty=!1,this.value={...r("error"),fetchedAtMs:null,checkedAtMs:null,revision:this.value.revision+1},this.changed(this.value),this.running&&(this.pending??Promise.resolve()).then(()=>{if(this.running)return this.tick()})}nextDue(){const t=this.dirty||this.active||this.failures?n:u;return Math.max(this.lastAttempt+t,this.retryAt,this.limitedUntil)}async tick(){if(this.pending)return this.pending;if(this.now()>=this.nextDue()){const t=Number.isFinite(this.lastAttempt)?this.failures?"retry":this.dirty||this.active?"usage":"hourly":"initial";return this.collect(t)}return this.arm(),this.value}refresh(t=!1){return this.pending?this.pending:t&&this.now()<this.limitedUntil?Promise.resolve(this.value):this.collect("manual")}collect(t){const s=this.epoch,e=this.now();this.lastAttempt=e;const l=this.dirty;return this.dirty=!1,this.pending=Promise.resolve().then(()=>this.query(t)).catch(()=>r("error")).then(i=>{if(s!==this.epoch)return this.value;const o=i.state==="error"&&!i.account||JSON.stringify(i.account)===JSON.stringify(this.value.account),h=i.state==="error";h?(this.failures++,this.dirty||=l,this.retryAt=this.now()+Math.max(n,Math.min(u,n*2**Math.min(4,this.failures-1)))):(this.failures=0,this.retryAt=0,this.limitedUntil=0),i.retryAfterMs&&(this.limitedUntil=this.now()+i.retryAfterMs);const{retryAfterMs:f,...c}=i,a=h&&o&&this.value.fetchedAtMs!==null;return this.value={...c,...a?{account:this.value.account,remaining:this.value.remaining,total:this.value.total,unlimited:this.value.unlimited,resources:this.value.resources}:{},fetchedAtMs:i.state==="ready"?this.now():a?this.value.fetchedAtMs:null,checkedAtMs:e,revision:this.value.revision+1},this.changed(this.value),this.value}).finally(()=>{this.pending=void 0,this.arm()}),this.pending}arm(){clearTimeout(this.timer),!(!this.running||this.pending)&&(this.timer=setTimeout(()=>{this.tick()},Math.min(2147483647,Math.max(1,this.nextDue()-this.now()))),this.timer.unref())}}export{y as WorkBuddyCreditsScheduler};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{acaServerRequest as u}from"../aca-server-client.js";import{loadAcaConfig as a}from"../aca-config.js";import{managementActivity as i}from"../management/activity.js";import{emptyCredits as f,queryWorkBuddyCredits as
|
|
1
|
+
import{acaServerRequest as u}from"../aca-server-client.js";import{loadAcaConfig as a}from"../aca-config.js";import{managementActivity as i}from"../management/activity.js";import{emptyCredits as f,queryWorkBuddyCredits as l}from"./query.js";import{WorkBuddyCreditsScheduler as p}from"./scheduler.js";let r=!1,s=!1,d="",o=Promise.resolve();const n=new p(async e=>{const t=i.enter("workbuddy-credits");if(!t)return f("error");try{return await l({allowCheckin:e==="hourly"})}finally{t()}},()=>{c()});function c(){const e=a();if(!e.token||!r)return Promise.resolve();const t=n.snapshot();return o=o.catch(()=>{}).then(()=>u("POST","/api/client/workbuddy-credits",{machineId:e.machineId,instanceId:process.env.ACA_WORKER_INSTANCE_ID||String(process.pid),snapshot:t},{serverUrl:e.serverUrl,token:e.token})).catch(()=>{}),o}function w(){r=!0,s&&m()}function m(){if(s=!0,!r||i.paused||i.stopping)return;const e=a(),t=`${e.serverUrl}\0${e.machineId}\0${e.token}`;d&&d!==t&&n.reset(),d=t,n.start(),c()}async function g(){r=!1,s=!1,await n.stop(),await o}export{w as activateWorkBuddyCredits,g as stopWorkBuddyCredits,n as workBuddyCredits,m as workBuddyCreditsConnected};
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const o="0.1.
|
|
1
|
+
const o="0.1.93";export{o as AICA_VERSION};
|