aglio-worker 0.71.0 → 0.74.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.
Files changed (2) hide show
  1. package/agent.js +201 -29
  2. package/package.json +1 -1
package/agent.js CHANGED
@@ -50180,9 +50180,10 @@ var RUN_STATUSES_FOR_SCHEMA = [
50180
50180
  "awaiting_input",
50181
50181
  "completed",
50182
50182
  "failed",
50183
- "cancelled"
50183
+ "cancelled",
50184
+ "skipped"
50184
50185
  ];
50185
- var RUN_KINDS = ["planning", "build", "consult", "review", "workspace_consult"];
50186
+ var RUN_KINDS = ["planning", "build", "consult", "review", "workspace_consult", "job"];
50186
50187
  var AGENT_DRIVERS = ["pi", "claude", "codex", "gemini", "cursor", "opencode"];
50187
50188
  var QUESTION_TYPES = ["single", "multi", "text"];
50188
50189
  var VERIFICATION_KINDS = ["test_output", "screenshot", "recording", "not_applicable"];
@@ -50205,7 +50206,8 @@ var RUN_TRIGGERS = [
50205
50206
  "review_poll",
50206
50207
  "planning_chat",
50207
50208
  "followup",
50208
- "workspace_chat"
50209
+ "workspace_chat",
50210
+ "schedule"
50209
50211
  ];
50210
50212
  var NOTIFICATION_TYPES = [
50211
50213
  "question",
@@ -70265,7 +70267,8 @@ var PLAN_CATALOG = {
70265
70267
  runsPerMonth: null,
70266
70268
  storageBytes: 500 * MEGABYTE,
70267
70269
  poolSecondsPerMonth: 7200,
70268
- cloudRunsPerMonth: 20
70270
+ cloudRunsPerMonth: 20,
70271
+ aiBilledTokensPerMonth: 25e4
70269
70272
  }
70270
70273
  },
70271
70274
  pro: {
@@ -70280,7 +70283,8 @@ var PLAN_CATALOG = {
70280
70283
  runsPerMonth: null,
70281
70284
  storageBytes: 5 * GIGABYTE,
70282
70285
  poolSecondsPerMonth: 72e3,
70283
- cloudRunsPerMonth: 120
70286
+ cloudRunsPerMonth: 120,
70287
+ aiBilledTokensPerMonth: 2e6
70284
70288
  }
70285
70289
  },
70286
70290
  team: {
@@ -70295,7 +70299,8 @@ var PLAN_CATALOG = {
70295
70299
  runsPerMonth: null,
70296
70300
  storageBytes: 20 * GIGABYTE,
70297
70301
  poolSecondsPerMonth: 36e4,
70298
- cloudRunsPerMonth: 500
70302
+ cloudRunsPerMonth: 500,
70303
+ aiBilledTokensPerMonth: 1e7
70299
70304
  }
70300
70305
  },
70301
70306
  enterprise: {
@@ -70310,7 +70315,9 @@ var PLAN_CATALOG = {
70310
70315
  runsPerMonth: null,
70311
70316
  storageBytes: null,
70312
70317
  poolSecondsPerMonth: null,
70313
- cloudRunsPerMonth: null
70318
+ cloudRunsPerMonth: null,
70319
+ // AI credits never render as unlimited. Enterprise starts at 0 + admin grants.
70320
+ aiBilledTokensPerMonth: 0
70314
70321
  }
70315
70322
  }
70316
70323
  };
@@ -70697,13 +70704,41 @@ var repoConfigSchema = external_exports.object({
70697
70704
  devCommand: external_exports.string().nullish(),
70698
70705
  port: external_exports.number().int().nullish()
70699
70706
  });
70707
+ var createJobCardSchema = external_exports.object({
70708
+ projectId: external_exports.string().min(1),
70709
+ title: external_exports.string().trim().min(1).max(300),
70710
+ body: external_exports.string().max(5e4).default(""),
70711
+ cron: external_exports.string().trim().min(1).max(200),
70712
+ timezone: external_exports.string().trim().min(1).max(100).default("UTC"),
70713
+ schedulePreset: external_exports.union([
70714
+ external_exports.object({ id: external_exports.literal("minutes"), every: external_exports.number().int() }),
70715
+ external_exports.object({ id: external_exports.literal("hours"), every: external_exports.number().int() }),
70716
+ external_exports.object({ id: external_exports.literal("daily"), hour: external_exports.number().int(), minute: external_exports.number().int() }),
70717
+ external_exports.object({ id: external_exports.literal("weekdays"), hour: external_exports.number().int(), minute: external_exports.number().int() }),
70718
+ external_exports.object({
70719
+ id: external_exports.literal("weekly"),
70720
+ weekday: external_exports.number().int(),
70721
+ hour: external_exports.number().int(),
70722
+ minute: external_exports.number().int()
70723
+ })
70724
+ ]).nullish().default(null),
70725
+ scheduleEnabled: external_exports.boolean().default(false)
70726
+ });
70727
+ var updateJobScheduleSchema = external_exports.object({
70728
+ cardId: external_exports.string().min(1),
70729
+ cron: external_exports.string().trim().min(1).max(200),
70730
+ timezone: external_exports.string().trim().min(1).max(100).default("UTC"),
70731
+ schedulePreset: external_exports.unknown().nullish(),
70732
+ scheduleEnabled: external_exports.boolean().optional()
70733
+ });
70700
70734
  var createCardSchema = external_exports.object({
70701
70735
  projectId: external_exports.string().min(1),
70702
70736
  title: external_exports.string().trim().min(1).max(300),
70703
70737
  body: external_exports.string().max(5e4).default(""),
70704
70738
  column: cardColumnSchema.default("backlog"),
70705
70739
  parentId: external_exports.string().nullish(),
70706
- priority: external_exports.number().int().min(-100).max(100).default(0)
70740
+ priority: external_exports.number().int().min(-100).max(100).default(0),
70741
+ kind: external_exports.enum(["work", "job"]).default("work")
70707
70742
  });
70708
70743
  var updateCardSchema = external_exports.object({
70709
70744
  cardId: external_exports.string().min(1),
@@ -70775,6 +70810,7 @@ var createAgentConfigSchema = external_exports.object({
70775
70810
  driver: agentDriverSchema,
70776
70811
  provider: external_exports.string().trim().min(1).max(100),
70777
70812
  model: external_exports.string().trim().min(1).max(200),
70813
+ authMode: external_exports.enum(["byok", "aglio"]).default("byok"),
70778
70814
  color: external_exports.string().max(20).default("#22c55e"),
70779
70815
  credentialId: external_exports.string().nullish(),
70780
70816
  options: agentConfigOptionsSchema.default({})
@@ -70818,6 +70854,10 @@ var mcpHeaderTemplateSchema = external_exports.object({
70818
70854
  // ../../packages/shared/src/auto-claim-schedule.ts
70819
70855
  var MAX_SCAN_MINUTES = 8 * 24 * 60;
70820
70856
 
70857
+ // ../../packages/shared/src/job-schedule.ts
70858
+ var MINUTE_MS = 6e4;
70859
+ var DAY_MS = 24 * 60 * MINUTE_MS;
70860
+
70821
70861
  // ../../packages/shared/src/workers.ts
70822
70862
  import { createHash, randomBytes } from "node:crypto";
70823
70863
 
@@ -70879,6 +70919,7 @@ var WORKER_OFFLINE_AFTER_MISSES = 3;
70879
70919
  var WORKER_OFFLINE_AFTER_SECONDS = WORKER_HEARTBEAT_SECONDS * WORKER_OFFLINE_AFTER_MISSES;
70880
70920
  var WORKER_CLAIM_LONG_POLL_SECONDS = 25;
70881
70921
  var WORKER_MIN_VERSION = "0.1.0";
70922
+ var WORKER_LATEST_VERSION = releaseVersion(process.env.AGLIO_VERSION) ?? "0.72.1";
70882
70923
  var WORKER_VERSION_HEADER = "x-aglio-worker-version";
70883
70924
  var WORKER_MODES = ["docker", "host"];
70884
70925
  var WORKER_OSES = ["linux", "macos"];
@@ -70924,6 +70965,21 @@ function parseWorkerLabels(input2) {
70924
70965
  throw new Error(message.replace(/^Invalid routing label/, "Invalid worker label"));
70925
70966
  }
70926
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
+ }
70927
70983
 
70928
70984
  // ../../packages/shared/src/agent-presets.ts
70929
70985
  var AGENT_PRESETS = ["yolo", "quick", "balanced", "careful"];
@@ -71514,6 +71570,9 @@ var themePreferencesSchema = external_exports.object({
71514
71570
  themeScale: external_exports.enum(THEME_SCALES).catch(DEFAULT_THEME_PREFERENCES.themeScale)
71515
71571
  });
71516
71572
 
71573
+ // ../../packages/shared/src/ai.ts
71574
+ var AI_TOKEN_TTL_MINUTES = 24 * 60;
71575
+
71517
71576
  // ../../packages/shared/src/lists.ts
71518
71577
  var BOARD_LIST_NAME_MAX = 40;
71519
71578
  var boardListInputSchema = external_exports.object({
@@ -71526,6 +71585,12 @@ var boardListMoveSchema = external_exports.object({
71526
71585
  insertAfter: external_exports.boolean().default(false)
71527
71586
  });
71528
71587
 
71588
+ // ../../packages/shared/src/project-sections.ts
71589
+ var PROJECT_SECTION_NAME_MAX = 40;
71590
+ var projectSectionInputSchema = external_exports.object({
71591
+ name: external_exports.string().trim().min(1).max(PROJECT_SECTION_NAME_MAX)
71592
+ });
71593
+
71529
71594
  // ../../packages/shared/src/password-reset.ts
71530
71595
  var PASSWORD_RESET_TTL_SECONDS = 60 * 60;
71531
71596
 
@@ -73664,7 +73729,8 @@ function stripAnsi(value) {
73664
73729
  return value.replace(ANSI, "").replace(/\r/g, "");
73665
73730
  }
73666
73731
  function trimLoginOutput(value) {
73667
- return value.length > LOGIN_OUTPUT_LIMIT ? value.slice(-LOGIN_OUTPUT_LIMIT) : value;
73732
+ const clean = value.replace(/\u0000/g, "");
73733
+ return clean.length > LOGIN_OUTPUT_LIMIT ? clean.slice(-LOGIN_OUTPUT_LIMIT) : clean;
73668
73734
  }
73669
73735
  function withoutUrls(value) {
73670
73736
  return value.replace(/https?:\/\/\S+/g, " ");
@@ -85428,6 +85494,25 @@ async function runRemoteCardJob(deps) {
85428
85494
  deps.log?.("run status update failed", { error: errorText2(error63) });
85429
85495
  });
85430
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
+ }
85431
85516
  try {
85432
85517
  await prepareWorkspace();
85433
85518
  await deps.mcp?.startRun?.({
@@ -85451,6 +85536,9 @@ async function runRemoteCardJob(deps) {
85451
85536
  log: (message) => deps.log?.(message)
85452
85537
  });
85453
85538
  const repoPaths = await cloneRepos();
85539
+ if (context.run.kind === "workspace_consult") {
85540
+ await rm2(gitConfigPath, { force: true }).catch(() => void 0);
85541
+ }
85454
85542
  const env = await agentEnv();
85455
85543
  for (const command2 of driverSetupCommands(context.agent.driver, mcpUrl, extraServers)) {
85456
85544
  const code = await exec(command2, workspace, env, { log: false });
@@ -85487,6 +85575,11 @@ async function runRemoteCardJob(deps) {
85487
85575
  await rm2(homeHost, { recursive: true, force: true }).catch(() => void 0);
85488
85576
  await rm2(gitConfigPath, { force: true }).catch(() => void 0);
85489
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
+ }
85490
85583
  if (mcpRelativePath) {
85491
85584
  await rm2(join5(toolDir, mcpRelativePath), { force: true }).catch(() => void 0);
85492
85585
  }
@@ -85494,24 +85587,50 @@ async function runRemoteCardJob(deps) {
85494
85587
  async function prepareWorkspace() {
85495
85588
  await mkdir2(homeHost, { recursive: true, mode: 448 });
85496
85589
  await mkdir2(join5(workspace, ".aglio", "attachments"), { recursive: true });
85497
- const files = credentialFiles(context.agent.credential.payload);
85498
- if (context.agent.credential.authType === "session_bundle" && Object.keys(files).length === 0) {
85499
- throw new Error(`Credential "${context.agent.credential.label}" has no session files.`);
85500
- }
85501
- for (const [relativePath, content] of Object.entries(files)) {
85502
- const target = resolve4(homeHost, relativePath);
85503
- if (!target.startsWith(resolve4(homeHost))) {
85504
- throw new Error(`Credential "${context.agent.credential.label}" has an unsafe file path.`);
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 });
85505
85604
  }
85506
- await mkdir2(dirname3(target), { recursive: true, mode: 448 });
85507
- await writeFile(target, content, { encoding: "utf8", mode: 384 });
85508
85605
  }
85509
- if (context.agent.provider === "local") {
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.");
85510
85629
  if (context.agent.driver !== "pi") {
85511
85630
  throw new Error("Local OpenAI-compatible providers are supported through the pi driver only.");
85512
85631
  }
85513
- if (!context.agent.credential.payload.baseUrl) {
85514
- throw new Error(`Credential "${context.agent.credential.label}" has no base URL.`);
85632
+ if (!localCredential.payload.baseUrl) {
85633
+ throw new Error(`Credential "${localCredential.label}" has no base URL.`);
85515
85634
  }
85516
85635
  await writeFile(
85517
85636
  join5(toolDir, "models.json"),
@@ -85519,9 +85638,9 @@ async function runRemoteCardJob(deps) {
85519
85638
  {
85520
85639
  providers: {
85521
85640
  local: {
85522
- baseUrl: context.agent.credential.payload.baseUrl,
85641
+ baseUrl: localCredential.payload.baseUrl,
85523
85642
  api: "openai-completions",
85524
- apiKey: context.agent.credential.payload.apiKey || "local",
85643
+ apiKey: localCredential.payload.apiKey || "local",
85525
85644
  models: [{ id: context.agent.model }]
85526
85645
  }
85527
85646
  }
@@ -85584,6 +85703,20 @@ async function runRemoteCardJob(deps) {
85584
85703
  );
85585
85704
  const branch = context.run.branch;
85586
85705
  const base = repo.baseBranch || "main";
85706
+ if (context.run.kind === "workspace_consult") {
85707
+ if (hasGit) {
85708
+ write(`[aglio] updating ${repo.name} (${base}) for read-only access
85709
+ `);
85710
+ const repoCommands = await repoGit(targetRun);
85711
+ await fetchBranch(repoCommands, base, { depth: 1 });
85712
+ await git(["-C", targetRun, "checkout", "-B", base, `origin/${base}`], workspace);
85713
+ } else {
85714
+ write(`[aglio] cloning ${repo.owner}/${repo.repo} (${base}) for read-only access
85715
+ `);
85716
+ await git(["clone", "--depth", "1", "--branch", base, repo.cloneUrl, targetRun], workspace);
85717
+ }
85718
+ continue;
85719
+ }
85587
85720
  let baseAlreadyFetched = false;
85588
85721
  if (hasGit) {
85589
85722
  write(`[aglio] updating ${repo.name} (${base})
@@ -85594,6 +85727,13 @@ async function runRemoteCardJob(deps) {
85594
85727
  await git(["clone", "--depth", "1", "--branch", base, repo.cloneUrl, targetRun], workspace);
85595
85728
  baseAlreadyFetched = true;
85596
85729
  }
85730
+ if (context.run.kind === "job") {
85731
+ if (!baseAlreadyFetched) await git(["fetch", "origin", base], workspace);
85732
+ await git(["checkout", "-B", base, `origin/${base}`], workspace);
85733
+ write(`[aglio] ${repo.name} starts from origin/${base} (job run)
85734
+ `);
85735
+ continue;
85736
+ }
85597
85737
  const start = await prepareBranchCheckout(await repoGit(targetRun), {
85598
85738
  branch,
85599
85739
  base,
@@ -85605,12 +85745,13 @@ async function runRemoteCardJob(deps) {
85605
85745
  return repoPaths;
85606
85746
  }
85607
85747
  async function agentEnv() {
85608
- const payload = context.agent.credential.payload;
85748
+ const credential = context.agent.credential;
85609
85749
  const env = {
85610
- ...credentialEnv(
85611
- { provider: context.agent.credential.provider, label: context.agent.credential.label, authType: context.agent.credential.authType },
85612
- payload
85750
+ ...context.agent.authMode === "aglio" || !credential ? {} : credentialEnv(
85751
+ { provider: credential.provider, label: credential.label, authType: credential.authType },
85752
+ credential.payload
85613
85753
  ),
85754
+ ...aiToken ? { AGLIO_AI_TOKEN: aiToken.token } : {},
85614
85755
  ...agentHomeEnv(context.agent.driver, containerPath(runRoot, workspace, toolDir)),
85615
85756
  ...driverMcpEnv(context.agent.driver, extraServers),
85616
85757
  AGLIO_RUN_ID: context.run.id,
@@ -85629,7 +85770,7 @@ async function runRemoteCardJob(deps) {
85629
85770
  GIT_CONFIG_GLOBAL: containerPath(runRoot, workspace, gitConfigPath),
85630
85771
  ...context.secrets
85631
85772
  };
85632
- if (context.git.token) {
85773
+ if (context.run.kind !== "workspace_consult" && context.git.token) {
85633
85774
  env.GIT_TOKEN = context.git.token;
85634
85775
  if (context.git.providerId === "github") {
85635
85776
  env.GITHUB_TOKEN = context.git.token;
@@ -86525,6 +86666,37 @@ function workerCardApi(config2, fetchImpl, signal) {
86525
86666
  async appendConsultMessage(input2) {
86526
86667
  return appendRunMessage(config2, fetchImpl, signal, input2, "consult");
86527
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
+ },
86528
86700
  async claimRun(input2) {
86529
86701
  const response = await jobTokenRequest(
86530
86702
  config2,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aglio-worker",
3
- "version": "0.71.0",
3
+ "version": "0.74.0",
4
4
  "description": "Host machine agent for Aglio: claims jobs over the API and starts aglio-runner containers.",
5
5
  "type": "module",
6
6
  "bin": {