aglio-worker 0.72.0 → 0.74.1
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/agent.js +130 -23
- package/package.json +1 -1
package/agent.js
CHANGED
|
@@ -70267,7 +70267,8 @@ var PLAN_CATALOG = {
|
|
|
70267
70267
|
runsPerMonth: null,
|
|
70268
70268
|
storageBytes: 500 * MEGABYTE,
|
|
70269
70269
|
poolSecondsPerMonth: 7200,
|
|
70270
|
-
cloudRunsPerMonth: 20
|
|
70270
|
+
cloudRunsPerMonth: 20,
|
|
70271
|
+
aiBilledTokensPerMonth: 25e4
|
|
70271
70272
|
}
|
|
70272
70273
|
},
|
|
70273
70274
|
pro: {
|
|
@@ -70282,7 +70283,8 @@ var PLAN_CATALOG = {
|
|
|
70282
70283
|
runsPerMonth: null,
|
|
70283
70284
|
storageBytes: 5 * GIGABYTE,
|
|
70284
70285
|
poolSecondsPerMonth: 72e3,
|
|
70285
|
-
cloudRunsPerMonth: 120
|
|
70286
|
+
cloudRunsPerMonth: 120,
|
|
70287
|
+
aiBilledTokensPerMonth: 2e6
|
|
70286
70288
|
}
|
|
70287
70289
|
},
|
|
70288
70290
|
team: {
|
|
@@ -70297,7 +70299,8 @@ var PLAN_CATALOG = {
|
|
|
70297
70299
|
runsPerMonth: null,
|
|
70298
70300
|
storageBytes: 20 * GIGABYTE,
|
|
70299
70301
|
poolSecondsPerMonth: 36e4,
|
|
70300
|
-
cloudRunsPerMonth: 500
|
|
70302
|
+
cloudRunsPerMonth: 500,
|
|
70303
|
+
aiBilledTokensPerMonth: 1e7
|
|
70301
70304
|
}
|
|
70302
70305
|
},
|
|
70303
70306
|
enterprise: {
|
|
@@ -70312,7 +70315,9 @@ var PLAN_CATALOG = {
|
|
|
70312
70315
|
runsPerMonth: null,
|
|
70313
70316
|
storageBytes: null,
|
|
70314
70317
|
poolSecondsPerMonth: null,
|
|
70315
|
-
cloudRunsPerMonth: null
|
|
70318
|
+
cloudRunsPerMonth: null,
|
|
70319
|
+
// AI credits never render as unlimited. Enterprise starts at 0 + admin grants.
|
|
70320
|
+
aiBilledTokensPerMonth: 0
|
|
70316
70321
|
}
|
|
70317
70322
|
}
|
|
70318
70323
|
};
|
|
@@ -70805,6 +70810,7 @@ var createAgentConfigSchema = external_exports.object({
|
|
|
70805
70810
|
driver: agentDriverSchema,
|
|
70806
70811
|
provider: external_exports.string().trim().min(1).max(100),
|
|
70807
70812
|
model: external_exports.string().trim().min(1).max(200),
|
|
70813
|
+
authMode: external_exports.enum(["byok", "aglio"]).default("byok"),
|
|
70808
70814
|
color: external_exports.string().max(20).default("#22c55e"),
|
|
70809
70815
|
credentialId: external_exports.string().nullish(),
|
|
70810
70816
|
options: agentConfigOptionsSchema.default({})
|
|
@@ -70913,6 +70919,7 @@ var WORKER_OFFLINE_AFTER_MISSES = 3;
|
|
|
70913
70919
|
var WORKER_OFFLINE_AFTER_SECONDS = WORKER_HEARTBEAT_SECONDS * WORKER_OFFLINE_AFTER_MISSES;
|
|
70914
70920
|
var WORKER_CLAIM_LONG_POLL_SECONDS = 25;
|
|
70915
70921
|
var WORKER_MIN_VERSION = "0.1.0";
|
|
70922
|
+
var WORKER_LATEST_VERSION = releaseVersion(process.env.AGLIO_VERSION) ?? "0.72.1";
|
|
70916
70923
|
var WORKER_VERSION_HEADER = "x-aglio-worker-version";
|
|
70917
70924
|
var WORKER_MODES = ["docker", "host"];
|
|
70918
70925
|
var WORKER_OSES = ["linux", "macos"];
|
|
@@ -70958,6 +70965,21 @@ function parseWorkerLabels(input2) {
|
|
|
70958
70965
|
throw new Error(message.replace(/^Invalid routing label/, "Invalid worker label"));
|
|
70959
70966
|
}
|
|
70960
70967
|
}
|
|
70968
|
+
function parseVersion(value) {
|
|
70969
|
+
const match = /^v?(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?(?:\+[0-9A-Za-z.-]+)?$/.exec(
|
|
70970
|
+
value.trim()
|
|
70971
|
+
);
|
|
70972
|
+
if (!match) return null;
|
|
70973
|
+
return {
|
|
70974
|
+
parts: [Number(match[1]), Number(match[2]), Number(match[3])],
|
|
70975
|
+
prerelease: match[4] ?? null
|
|
70976
|
+
};
|
|
70977
|
+
}
|
|
70978
|
+
function releaseVersion(value) {
|
|
70979
|
+
const raw = typeof value === "string" ? value.trim() : "";
|
|
70980
|
+
if (!raw || !parseVersion(raw)) return null;
|
|
70981
|
+
return raw.replace(/^v/i, "");
|
|
70982
|
+
}
|
|
70961
70983
|
|
|
70962
70984
|
// ../../packages/shared/src/agent-presets.ts
|
|
70963
70985
|
var AGENT_PRESETS = ["yolo", "quick", "balanced", "careful"];
|
|
@@ -71548,6 +71570,9 @@ var themePreferencesSchema = external_exports.object({
|
|
|
71548
71570
|
themeScale: external_exports.enum(THEME_SCALES).catch(DEFAULT_THEME_PREFERENCES.themeScale)
|
|
71549
71571
|
});
|
|
71550
71572
|
|
|
71573
|
+
// ../../packages/shared/src/ai.ts
|
|
71574
|
+
var AI_TOKEN_TTL_MINUTES = 24 * 60;
|
|
71575
|
+
|
|
71551
71576
|
// ../../packages/shared/src/lists.ts
|
|
71552
71577
|
var BOARD_LIST_NAME_MAX = 40;
|
|
71553
71578
|
var boardListInputSchema = external_exports.object({
|
|
@@ -85469,6 +85494,25 @@ async function runRemoteCardJob(deps) {
|
|
|
85469
85494
|
deps.log?.("run status update failed", { error: errorText2(error63) });
|
|
85470
85495
|
});
|
|
85471
85496
|
await status({ status: "preparing" });
|
|
85497
|
+
let aiToken = null;
|
|
85498
|
+
if (context.agent.authMode === "aglio") {
|
|
85499
|
+
if (context.agent.driver !== "pi" || context.agent.provider !== "deepseek" || context.agent.model !== "deepseek-flash") {
|
|
85500
|
+
return { state: "failed", error: "Aglio credits only support the pi driver with deepseek-flash." };
|
|
85501
|
+
}
|
|
85502
|
+
if (context.agent.credential) {
|
|
85503
|
+
return { state: "failed", error: "Aglio-credit runs must not receive a provider credential." };
|
|
85504
|
+
}
|
|
85505
|
+
if (!deps.api.mintAiToken) {
|
|
85506
|
+
return { state: "failed", error: "This worker version cannot mint Aglio credits. Update the worker." };
|
|
85507
|
+
}
|
|
85508
|
+
try {
|
|
85509
|
+
aiToken = await deps.api.mintAiToken({ ...lease, runId: context.run.id });
|
|
85510
|
+
} catch (error63) {
|
|
85511
|
+
return { state: "failed", error: errorText2(error63).slice(0, 4e3) };
|
|
85512
|
+
}
|
|
85513
|
+
} else if (context.agent.credential === null) {
|
|
85514
|
+
return { state: "failed", error: "BYOK runs require a provider credential." };
|
|
85515
|
+
}
|
|
85472
85516
|
try {
|
|
85473
85517
|
await prepareWorkspace();
|
|
85474
85518
|
await deps.mcp?.startRun?.({
|
|
@@ -85531,6 +85575,11 @@ async function runRemoteCardJob(deps) {
|
|
|
85531
85575
|
await rm2(homeHost, { recursive: true, force: true }).catch(() => void 0);
|
|
85532
85576
|
await rm2(gitConfigPath, { force: true }).catch(() => void 0);
|
|
85533
85577
|
await rm2(join5(toolDir, "models.json"), { force: true }).catch(() => void 0);
|
|
85578
|
+
if (aiToken) {
|
|
85579
|
+
await deps.api.revokeAiToken?.({ ...lease, runId: context.run.id }).catch((error63) => {
|
|
85580
|
+
deps.log?.("AI token revoke failed", { error: errorText2(error63) });
|
|
85581
|
+
});
|
|
85582
|
+
}
|
|
85534
85583
|
if (mcpRelativePath) {
|
|
85535
85584
|
await rm2(join5(toolDir, mcpRelativePath), { force: true }).catch(() => void 0);
|
|
85536
85585
|
}
|
|
@@ -85538,24 +85587,50 @@ async function runRemoteCardJob(deps) {
|
|
|
85538
85587
|
async function prepareWorkspace() {
|
|
85539
85588
|
await mkdir2(homeHost, { recursive: true, mode: 448 });
|
|
85540
85589
|
await mkdir2(join5(workspace, ".aglio", "attachments"), { recursive: true });
|
|
85541
|
-
|
|
85542
|
-
|
|
85543
|
-
throw new Error(
|
|
85544
|
-
|
|
85545
|
-
|
|
85546
|
-
|
|
85547
|
-
|
|
85548
|
-
|
|
85590
|
+
if (context.agent.authMode !== "aglio") {
|
|
85591
|
+
const credential = context.agent.credential;
|
|
85592
|
+
if (!credential) throw new Error("BYOK runs require a provider credential.");
|
|
85593
|
+
const files = credentialFiles(credential.payload);
|
|
85594
|
+
if (credential.authType === "session_bundle" && Object.keys(files).length === 0) {
|
|
85595
|
+
throw new Error(`Credential "${credential.label}" has no session files.`);
|
|
85596
|
+
}
|
|
85597
|
+
for (const [relativePath, content] of Object.entries(files)) {
|
|
85598
|
+
const target = resolve4(homeHost, relativePath);
|
|
85599
|
+
if (!target.startsWith(resolve4(homeHost))) {
|
|
85600
|
+
throw new Error(`Credential "${credential.label}" has an unsafe file path.`);
|
|
85601
|
+
}
|
|
85602
|
+
await mkdir2(dirname3(target), { recursive: true, mode: 448 });
|
|
85603
|
+
await writeFile(target, content, { encoding: "utf8", mode: 384 });
|
|
85549
85604
|
}
|
|
85550
|
-
await mkdir2(dirname3(target), { recursive: true, mode: 448 });
|
|
85551
|
-
await writeFile(target, content, { encoding: "utf8", mode: 384 });
|
|
85552
85605
|
}
|
|
85553
|
-
if (
|
|
85606
|
+
if (aiToken) {
|
|
85607
|
+
await writeFile(
|
|
85608
|
+
join5(toolDir, "models.json"),
|
|
85609
|
+
JSON.stringify(
|
|
85610
|
+
{
|
|
85611
|
+
providers: {
|
|
85612
|
+
aglio: {
|
|
85613
|
+
baseUrl: aiToken.baseUrl,
|
|
85614
|
+
api: "openai-completions",
|
|
85615
|
+
apiKey: aiToken.token,
|
|
85616
|
+
models: aiToken.models.map((id) => ({ id }))
|
|
85617
|
+
}
|
|
85618
|
+
}
|
|
85619
|
+
},
|
|
85620
|
+
null,
|
|
85621
|
+
2
|
|
85622
|
+
),
|
|
85623
|
+
"utf8"
|
|
85624
|
+
);
|
|
85625
|
+
}
|
|
85626
|
+
if (context.agent.authMode !== "aglio" && context.agent.provider === "local") {
|
|
85627
|
+
const localCredential = context.agent.credential;
|
|
85628
|
+
if (!localCredential) throw new Error("Local provider runs require a credential.");
|
|
85554
85629
|
if (context.agent.driver !== "pi") {
|
|
85555
85630
|
throw new Error("Local OpenAI-compatible providers are supported through the pi driver only.");
|
|
85556
85631
|
}
|
|
85557
|
-
if (!
|
|
85558
|
-
throw new Error(`Credential "${
|
|
85632
|
+
if (!localCredential.payload.baseUrl) {
|
|
85633
|
+
throw new Error(`Credential "${localCredential.label}" has no base URL.`);
|
|
85559
85634
|
}
|
|
85560
85635
|
await writeFile(
|
|
85561
85636
|
join5(toolDir, "models.json"),
|
|
@@ -85563,9 +85638,9 @@ async function runRemoteCardJob(deps) {
|
|
|
85563
85638
|
{
|
|
85564
85639
|
providers: {
|
|
85565
85640
|
local: {
|
|
85566
|
-
baseUrl:
|
|
85641
|
+
baseUrl: localCredential.payload.baseUrl,
|
|
85567
85642
|
api: "openai-completions",
|
|
85568
|
-
apiKey:
|
|
85643
|
+
apiKey: localCredential.payload.apiKey || "local",
|
|
85569
85644
|
models: [{ id: context.agent.model }]
|
|
85570
85645
|
}
|
|
85571
85646
|
}
|
|
@@ -85670,12 +85745,13 @@ async function runRemoteCardJob(deps) {
|
|
|
85670
85745
|
return repoPaths;
|
|
85671
85746
|
}
|
|
85672
85747
|
async function agentEnv() {
|
|
85673
|
-
const
|
|
85748
|
+
const credential = context.agent.credential;
|
|
85674
85749
|
const env = {
|
|
85675
|
-
...credentialEnv(
|
|
85676
|
-
{ provider:
|
|
85677
|
-
payload
|
|
85750
|
+
...context.agent.authMode === "aglio" || !credential ? {} : credentialEnv(
|
|
85751
|
+
{ provider: credential.provider, label: credential.label, authType: credential.authType },
|
|
85752
|
+
credential.payload
|
|
85678
85753
|
),
|
|
85754
|
+
...aiToken ? { AGLIO_AI_TOKEN: aiToken.token } : {},
|
|
85679
85755
|
...agentHomeEnv(context.agent.driver, containerPath(runRoot, workspace, toolDir)),
|
|
85680
85756
|
...driverMcpEnv(context.agent.driver, extraServers),
|
|
85681
85757
|
AGLIO_RUN_ID: context.run.id,
|
|
@@ -86590,6 +86666,37 @@ function workerCardApi(config2, fetchImpl, signal) {
|
|
|
86590
86666
|
async appendConsultMessage(input2) {
|
|
86591
86667
|
return appendRunMessage(config2, fetchImpl, signal, input2, "consult");
|
|
86592
86668
|
},
|
|
86669
|
+
async mintAiToken(input2) {
|
|
86670
|
+
const response = await jobTokenRequest(
|
|
86671
|
+
config2,
|
|
86672
|
+
fetchImpl,
|
|
86673
|
+
`/api/ai/runs/${input2.runId}/token?jobId=${encodeURIComponent(input2.jobId)}&leaseId=${encodeURIComponent(input2.leaseId)}`,
|
|
86674
|
+
input2.token,
|
|
86675
|
+
{ method: "POST", signal }
|
|
86676
|
+
);
|
|
86677
|
+
if (!response.ok) throw await errorFrom(response);
|
|
86678
|
+
const body = await responseBody(response);
|
|
86679
|
+
if (typeof body.token !== "string" || typeof body.baseUrl !== "string") {
|
|
86680
|
+
throw new WorkerHttpError(500, "invalid_ai_token", "Control plane did not return an AI gateway token.");
|
|
86681
|
+
}
|
|
86682
|
+
return {
|
|
86683
|
+
token: body.token,
|
|
86684
|
+
baseUrl: body.baseUrl,
|
|
86685
|
+
models: Array.isArray(body.models) ? body.models.filter((model) => typeof model === "string") : [],
|
|
86686
|
+
expiresAt: typeof body.expiresAt === "string" ? body.expiresAt : "",
|
|
86687
|
+
maxBilledTokens: typeof body.maxBilledTokens === "number" ? body.maxBilledTokens : 0
|
|
86688
|
+
};
|
|
86689
|
+
},
|
|
86690
|
+
async revokeAiToken(input2) {
|
|
86691
|
+
const response = await jobTokenRequest(
|
|
86692
|
+
config2,
|
|
86693
|
+
fetchImpl,
|
|
86694
|
+
`/api/ai/runs/${input2.runId}/revoke?jobId=${encodeURIComponent(input2.jobId)}&leaseId=${encodeURIComponent(input2.leaseId)}`,
|
|
86695
|
+
input2.token,
|
|
86696
|
+
{ method: "POST", signal }
|
|
86697
|
+
);
|
|
86698
|
+
if (!response.ok) throw await errorFrom(response);
|
|
86699
|
+
},
|
|
86593
86700
|
async claimRun(input2) {
|
|
86594
86701
|
const response = await jobTokenRequest(
|
|
86595
86702
|
config2,
|