@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
@@ -132,6 +132,7 @@ var CONFIG_DIR = join(homedir(), ".config", "pai");
132
132
  var CONFIG_FILE = join(CONFIG_DIR, "config.json");
133
133
 
134
134
  // src/workers/config.ts
135
+ var ANTHROPIC_NATIVE = "anthropic";
135
136
  var MODEL_TIERS = ["haiku", "sonnet", "opus"];
136
137
  var PROVIDER_TAGS = [
137
138
  "code",
@@ -160,6 +161,7 @@ var DEFAULT_TREE = {
160
161
  maxDepth: 2,
161
162
  maxChildren: 4
162
163
  };
164
+ var DEFAULT_CACHE_KEEPALIVE_SECS = 0;
163
165
  var DEFAULT_MCP_SETS = {
164
166
  desktop: ["clickr"]
165
167
  };
@@ -174,6 +176,7 @@ function defaultWorkersConfig() {
174
176
  logDir: DEFAULT_LOG_DIR,
175
177
  routing: { ...DEFAULT_ROUTING2, order: [] },
176
178
  tree: { ...DEFAULT_TREE },
179
+ cacheKeepaliveSecs: DEFAULT_CACHE_KEEPALIVE_SECS,
177
180
  fallback: null
178
181
  };
179
182
  }
@@ -186,6 +189,12 @@ function str(v) {
186
189
  return typeof v === "string" ? v : "";
187
190
  }
188
191
  function parseProvider(name, raw) {
192
+ if (name === ANTHROPIC_NATIVE) {
193
+ bad(
194
+ `.providers.${name}`,
195
+ `"${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`
196
+ );
197
+ }
189
198
  if (typeof raw !== "object" || raw === null) bad(`.providers.${name}`, "must be an object");
190
199
  const p = raw;
191
200
  const protocol = p.protocol === void 0 ? "anthropic" : str(p.protocol);
@@ -279,6 +288,51 @@ function parseProvider(name, raw) {
279
288
  }
280
289
  tags = p.tags;
281
290
  }
291
+ let usage;
292
+ if (p.usage !== void 0) {
293
+ if (typeof p.usage !== "object" || p.usage === null || Array.isArray(p.usage)) {
294
+ bad(`.providers.${name}.usage`, "must be an object");
295
+ }
296
+ const u = p.usage;
297
+ const usageUrl = str(u.url);
298
+ if (!usageUrl) bad(`.providers.${name}.usage.url`, "is required");
299
+ if (!Array.isArray(u.windows) || u.windows.length === 0) {
300
+ bad(`.providers.${name}.usage.windows`, "must be a non-empty array");
301
+ }
302
+ const windows = [];
303
+ for (const [i, wRaw] of u.windows.entries()) {
304
+ const wpath = `.providers.${name}.usage.windows[${i}]`;
305
+ if (typeof wRaw !== "object" || wRaw === null || Array.isArray(wRaw)) {
306
+ bad(wpath, "must be an object");
307
+ }
308
+ const w = wRaw;
309
+ const wname = str(w.name);
310
+ if (!wname) bad(`${wpath}.name`, "is required");
311
+ const percent = str(w.percent);
312
+ if (!percent) bad(`${wpath}.percent`, "is required (a jq expression yielding 0\u2013100)");
313
+ const resetUnit = w.resetUnit === void 0 ? void 0 : str(w.resetUnit);
314
+ if (resetUnit !== void 0 && resetUnit !== "ms" && resetUnit !== "s" && resetUnit !== "iso") {
315
+ bad(`${wpath}.resetUnit`, `must be "ms", "s" or "iso"`);
316
+ }
317
+ windows.push({
318
+ name: wname,
319
+ percent,
320
+ ...str(w.resetAt) ? { resetAt: str(w.resetAt) } : {},
321
+ ...resetUnit ? { resetUnit } : {}
322
+ });
323
+ }
324
+ const ttlSeconds = u.ttlSeconds === void 0 ? void 0 : u.ttlSeconds;
325
+ if (ttlSeconds !== void 0 && (typeof ttlSeconds !== "number" || ttlSeconds <= 0)) {
326
+ bad(`.providers.${name}.usage.ttlSeconds`, "must be a positive number of seconds");
327
+ }
328
+ usage = {
329
+ url: usageUrl,
330
+ ...str(u.authHeader) ? { authHeader: str(u.authHeader) } : {},
331
+ ...str(u.label) ? { label: str(u.label) } : {},
332
+ windows,
333
+ ...ttlSeconds !== void 0 ? { ttlSeconds } : {}
334
+ };
335
+ }
282
336
  return {
283
337
  enabled: p.enabled === void 0 ? true : p.enabled === true,
284
338
  protocol,
@@ -294,7 +348,8 @@ function parseProvider(name, raw) {
294
348
  ...quotaSkipAt !== void 0 ? { quotaSkipAt } : {},
295
349
  ...contextWindow !== void 0 ? { contextWindow } : {},
296
350
  ...costTier !== void 0 ? { costTier } : {},
297
- ...tags ? { tags } : {}
351
+ ...tags ? { tags } : {},
352
+ ...usage ? { usage } : {}
298
353
  };
299
354
  }
300
355
  function parseWorkersConfig(raw) {
@@ -446,6 +501,13 @@ function parseWorkersConfig(raw) {
446
501
  maxChildren: t.maxChildren === void 0 ? DEFAULT_TREE.maxChildren : t.maxChildren
447
502
  };
448
503
  }
504
+ let cacheKeepaliveSecs = DEFAULT_CACHE_KEEPALIVE_SECS;
505
+ if (w.cacheKeepaliveSecs !== void 0) {
506
+ if (typeof w.cacheKeepaliveSecs !== "number" || !Number.isInteger(w.cacheKeepaliveSecs) || w.cacheKeepaliveSecs < 0) {
507
+ bad(".cacheKeepaliveSecs", "must be a non-negative integer (seconds, 0 = off)");
508
+ }
509
+ cacheKeepaliveSecs = w.cacheKeepaliveSecs;
510
+ }
449
511
  const active = w.active === void 0 || w.active === null ? null : str(w.active);
450
512
  if (active !== null && active !== "auto" && !(active in providers)) {
451
513
  }
@@ -492,6 +554,7 @@ function parseWorkersConfig(raw) {
492
554
  logDir: str(w.logDir) || d.logDir,
493
555
  routing,
494
556
  tree,
557
+ cacheKeepaliveSecs,
495
558
  fallback
496
559
  };
497
560
  }