@tekmidian/pai 0.42.1 → 0.42.3

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 (68) hide show
  1. package/README.md +1 -1
  2. package/dist/chain-B-DbR82m.mjs +164 -0
  3. package/dist/chain-B-DbR82m.mjs.map +1 -0
  4. package/dist/cli/index.mjs +8 -8
  5. package/dist/cli/program.mjs +8 -8
  6. package/dist/{config-Bi_F6lXf.mjs → config-_lQI_W08.mjs} +87 -3
  7. package/dist/config-_lQI_W08.mjs.map +1 -0
  8. package/dist/{context-handover-cache--bm6Siim.mjs → context-handover-cache-pNFdBNrU.mjs} +3 -3
  9. package/dist/{context-handover-cache--bm6Siim.mjs.map → context-handover-cache-pNFdBNrU.mjs.map} +1 -1
  10. package/dist/daemon/index.mjs +7 -7
  11. package/dist/{daemon-BOAPyL_b.mjs → daemon-Awt_3UJp.mjs} +7 -7
  12. package/dist/{daemon-DvXih78C.mjs → daemon-Dq8A1uDF.mjs} +587 -368
  13. package/dist/daemon-Dq8A1uDF.mjs.map +1 -0
  14. package/dist/daemon-mcp/index.mjs +5 -5
  15. package/dist/{fallback-8bzmg6No.mjs → fallback-vQPI1qxt.mjs} +14 -12
  16. package/dist/fallback-vQPI1qxt.mjs.map +1 -0
  17. package/dist/hooks/mcp-deferred-gate.mjs +286 -0
  18. package/dist/hooks/mcp-deferred-gate.mjs.map +7 -0
  19. package/dist/hooks/mcp-deferred-reminder.mjs +54 -0
  20. package/dist/hooks/mcp-deferred-reminder.mjs.map +7 -0
  21. package/dist/hooks/route-agents-to-worker.mjs +65 -2
  22. package/dist/hooks/route-agents-to-worker.mjs.map +2 -2
  23. package/dist/hooks/worker-proxy.mjs +64 -1
  24. package/dist/hooks/worker-proxy.mjs.map +2 -2
  25. package/dist/hooks/worker-status-line.mjs +64 -1
  26. package/dist/hooks/worker-status-line.mjs.map +2 -2
  27. package/dist/hooks/worker-supervision.mjs +64 -1
  28. package/dist/hooks/worker-supervision.mjs.map +2 -2
  29. package/dist/{main-resolver-CqppP_Bw.mjs → main-resolver-BAfOMppW.mjs} +2 -2
  30. package/dist/{main-resolver-Dip2VLB5.mjs → main-resolver-DnkxPYkr.mjs} +111 -16
  31. package/dist/main-resolver-DnkxPYkr.mjs.map +1 -0
  32. package/dist/{planner-ogy-Zy4O.mjs → planner-BfEGcEs1.mjs} +5 -5
  33. package/dist/{planner-ogy-Zy4O.mjs.map → planner-BfEGcEs1.mjs.map} +1 -1
  34. package/dist/{program-B7N5OIJR.mjs → program-BDmeZP-v.mjs} +17 -11
  35. package/dist/{program-B7N5OIJR.mjs.map → program-BDmeZP-v.mjs.map} +1 -1
  36. package/dist/{chain-DsvSHnO9.mjs → run-CGXbhf2k.mjs} +359 -163
  37. package/dist/run-CGXbhf2k.mjs.map +1 -0
  38. package/dist/{server-DvN-IFIV.mjs → server-D4vAieF4.mjs} +25 -6
  39. package/dist/server-D4vAieF4.mjs.map +1 -0
  40. package/dist/{state-BTa10SOM.mjs → state-BRdB-Bf1.mjs} +7 -2
  41. package/dist/state-BRdB-Bf1.mjs.map +1 -0
  42. package/dist/state-CY6I-Hnc.mjs +3 -0
  43. package/dist/{work-queue-worker-19r0cpH4.mjs → work-queue-worker-AEmfVE0F.mjs} +5 -5
  44. package/dist/{work-queue-worker-DXh_FnT5.mjs → work-queue-worker-DIT-VLSh.mjs} +3 -3
  45. package/dist/{work-queue-worker-DXh_FnT5.mjs.map → work-queue-worker-DIT-VLSh.mjs.map} +1 -1
  46. package/docs/cache-keepalive.md +82 -0
  47. package/docs/commands/worker.md +1 -0
  48. package/docs/provider-abstraction.md +52 -2
  49. package/package.json +1 -1
  50. package/plugins/core/hooks/hooks.json +12 -0
  51. package/src/hooks/ts/lib/mcp-deferred-gate.test.ts +258 -0
  52. package/src/hooks/ts/lib/mcp-deferred-gate.ts +261 -0
  53. package/src/hooks/ts/lib/mcp-deferred-reminder.test.ts +90 -0
  54. package/src/hooks/ts/lib/mcp-deferred-reminder.ts +66 -0
  55. package/src/hooks/ts/pre-tool-use/mcp-deferred-gate.ts +126 -0
  56. package/src/hooks/ts/pre-tool-use/route-agents-to-worker.ts +6 -2
  57. package/src/hooks/ts/session-start/mcp-deferred-reminder.ts +52 -0
  58. package/statusline-command.sh +149 -72
  59. package/dist/chain-DsvSHnO9.mjs.map +0 -1
  60. package/dist/config-Bi_F6lXf.mjs.map +0 -1
  61. package/dist/daemon-DvXih78C.mjs.map +0 -1
  62. package/dist/fallback-8bzmg6No.mjs.map +0 -1
  63. package/dist/main-resolver-Dip2VLB5.mjs.map +0 -1
  64. package/dist/scope-CfYnjy5R.mjs +0 -360
  65. package/dist/scope-CfYnjy5R.mjs.map +0 -1
  66. package/dist/server-DvN-IFIV.mjs.map +0 -1
  67. package/dist/state-BTa10SOM.mjs.map +0 -1
  68. package/dist/state-RXepvbnO.mjs +0 -3
@@ -131,6 +131,7 @@ var CONFIG_DIR = join(homedir(), ".config", "pai");
131
131
  var CONFIG_FILE = join(CONFIG_DIR, "config.json");
132
132
 
133
133
  // src/workers/config.ts
134
+ var ANTHROPIC_NATIVE = "anthropic";
134
135
  var MODEL_TIERS = ["haiku", "sonnet", "opus"];
135
136
  var PROVIDER_TAGS = [
136
137
  "code",
@@ -159,6 +160,7 @@ var DEFAULT_TREE = {
159
160
  maxDepth: 2,
160
161
  maxChildren: 4
161
162
  };
163
+ var DEFAULT_CACHE_KEEPALIVE_SECS = 0;
162
164
  var DEFAULT_MCP_SETS = {
163
165
  desktop: ["clickr"]
164
166
  };
@@ -173,6 +175,7 @@ function defaultWorkersConfig() {
173
175
  logDir: DEFAULT_LOG_DIR,
174
176
  routing: { ...DEFAULT_ROUTING2, order: [] },
175
177
  tree: { ...DEFAULT_TREE },
178
+ cacheKeepaliveSecs: DEFAULT_CACHE_KEEPALIVE_SECS,
176
179
  fallback: null
177
180
  };
178
181
  }
@@ -185,6 +188,12 @@ function str(v) {
185
188
  return typeof v === "string" ? v : "";
186
189
  }
187
190
  function parseProvider(name, raw) {
191
+ if (name === ANTHROPIC_NATIVE) {
192
+ bad(
193
+ `.providers.${name}`,
194
+ `"${ANTHROPIC_NATIVE}" is reserved for plain Anthropic (Claude Code's own OAuth/Max-plan login) and cannot be configured here \u2014 remove this entry; use --provider ${ANTHROPIC_NATIVE} or "pai worker providers use ${ANTHROPIC_NATIVE}" instead`
195
+ );
196
+ }
188
197
  if (typeof raw !== "object" || raw === null) bad(`.providers.${name}`, "must be an object");
189
198
  const p = raw;
190
199
  const protocol = p.protocol === void 0 ? "anthropic" : str(p.protocol);
@@ -278,6 +287,51 @@ function parseProvider(name, raw) {
278
287
  }
279
288
  tags = p.tags;
280
289
  }
290
+ let usage;
291
+ if (p.usage !== void 0) {
292
+ if (typeof p.usage !== "object" || p.usage === null || Array.isArray(p.usage)) {
293
+ bad(`.providers.${name}.usage`, "must be an object");
294
+ }
295
+ const u = p.usage;
296
+ const usageUrl = str(u.url);
297
+ if (!usageUrl) bad(`.providers.${name}.usage.url`, "is required");
298
+ if (!Array.isArray(u.windows) || u.windows.length === 0) {
299
+ bad(`.providers.${name}.usage.windows`, "must be a non-empty array");
300
+ }
301
+ const windows = [];
302
+ for (const [i, wRaw] of u.windows.entries()) {
303
+ const wpath = `.providers.${name}.usage.windows[${i}]`;
304
+ if (typeof wRaw !== "object" || wRaw === null || Array.isArray(wRaw)) {
305
+ bad(wpath, "must be an object");
306
+ }
307
+ const w = wRaw;
308
+ const wname = str(w.name);
309
+ if (!wname) bad(`${wpath}.name`, "is required");
310
+ const percent = str(w.percent);
311
+ if (!percent) bad(`${wpath}.percent`, "is required (a jq expression yielding 0\u2013100)");
312
+ const resetUnit = w.resetUnit === void 0 ? void 0 : str(w.resetUnit);
313
+ if (resetUnit !== void 0 && resetUnit !== "ms" && resetUnit !== "s" && resetUnit !== "iso") {
314
+ bad(`${wpath}.resetUnit`, `must be "ms", "s" or "iso"`);
315
+ }
316
+ windows.push({
317
+ name: wname,
318
+ percent,
319
+ ...str(w.resetAt) ? { resetAt: str(w.resetAt) } : {},
320
+ ...resetUnit ? { resetUnit } : {}
321
+ });
322
+ }
323
+ const ttlSeconds = u.ttlSeconds === void 0 ? void 0 : u.ttlSeconds;
324
+ if (ttlSeconds !== void 0 && (typeof ttlSeconds !== "number" || ttlSeconds <= 0)) {
325
+ bad(`.providers.${name}.usage.ttlSeconds`, "must be a positive number of seconds");
326
+ }
327
+ usage = {
328
+ url: usageUrl,
329
+ ...str(u.authHeader) ? { authHeader: str(u.authHeader) } : {},
330
+ ...str(u.label) ? { label: str(u.label) } : {},
331
+ windows,
332
+ ...ttlSeconds !== void 0 ? { ttlSeconds } : {}
333
+ };
334
+ }
281
335
  return {
282
336
  enabled: p.enabled === void 0 ? true : p.enabled === true,
283
337
  protocol,
@@ -293,7 +347,8 @@ function parseProvider(name, raw) {
293
347
  ...quotaSkipAt !== void 0 ? { quotaSkipAt } : {},
294
348
  ...contextWindow !== void 0 ? { contextWindow } : {},
295
349
  ...costTier !== void 0 ? { costTier } : {},
296
- ...tags ? { tags } : {}
350
+ ...tags ? { tags } : {},
351
+ ...usage ? { usage } : {}
297
352
  };
298
353
  }
299
354
  function parseWorkersConfig(raw) {
@@ -445,6 +500,13 @@ function parseWorkersConfig(raw) {
445
500
  maxChildren: t.maxChildren === void 0 ? DEFAULT_TREE.maxChildren : t.maxChildren
446
501
  };
447
502
  }
503
+ let cacheKeepaliveSecs = DEFAULT_CACHE_KEEPALIVE_SECS;
504
+ if (w.cacheKeepaliveSecs !== void 0) {
505
+ if (typeof w.cacheKeepaliveSecs !== "number" || !Number.isInteger(w.cacheKeepaliveSecs) || w.cacheKeepaliveSecs < 0) {
506
+ bad(".cacheKeepaliveSecs", "must be a non-negative integer (seconds, 0 = off)");
507
+ }
508
+ cacheKeepaliveSecs = w.cacheKeepaliveSecs;
509
+ }
448
510
  const active = w.active === void 0 || w.active === null ? null : str(w.active);
449
511
  if (active !== null && active !== "auto" && !(active in providers)) {
450
512
  }
@@ -491,6 +553,7 @@ function parseWorkersConfig(raw) {
491
553
  logDir: str(w.logDir) || d.logDir,
492
554
  routing,
493
555
  tree,
556
+ cacheKeepaliveSecs,
494
557
  fallback
495
558
  };
496
559
  }