@whittlelabs/sifter 0.4.2 → 0.5.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.
Files changed (4) hide show
  1. package/README.md +6 -9
  2. package/bin.js +2856 -649
  3. package/bin.js.map +4 -4
  4. package/package.json +2 -2
package/bin.js CHANGED
@@ -3195,7 +3195,7 @@ var require_device_code = __commonJS({
3195
3195
  hostname: (0, os_1.hostname)(),
3196
3196
  user: (0, os_1.userInfo)().username
3197
3197
  },
3198
- attentionPools: token.attentionPools
3198
+ jobPools: token.jobPools
3199
3199
  };
3200
3200
  }
3201
3201
  async function startDeviceCode(opts) {
@@ -15265,81 +15265,12 @@ ${issues}`);
15265
15265
  }
15266
15266
  });
15267
15267
 
15268
- // ../../packages/jobs/dist/prompt-execution.js
15269
- var require_prompt_execution = __commonJS({
15270
- "../../packages/jobs/dist/prompt-execution.js"(exports2) {
15271
- "use strict";
15272
- Object.defineProperty(exports2, "__esModule", { value: true });
15273
- exports2.DEFAULT_JOB_TYPE = void 0;
15274
- exports2.buildPromptExecutionInputs = buildPromptExecutionInputs;
15275
- exports2.readPromptExecutionSpec = readPromptExecutionSpec;
15276
- exports2.DEFAULT_JOB_TYPE = "prompt-execution";
15277
- function buildPromptExecutionInputs(options) {
15278
- const spec = {
15279
- rendering: options.rendering,
15280
- outputLabel: options.output.label,
15281
- outputSchema: options.output.schema
15282
- };
15283
- if (options.providerHints)
15284
- spec.providerHints = options.providerHints;
15285
- if (options.costCapHint)
15286
- spec.costCapHint = options.costCapHint;
15287
- if (options.rendering === "producer" && !options.prompt) {
15288
- throw new Error("rendering='producer' requires `prompt`");
15289
- }
15290
- if (options.rendering === "subscriber" && !options.template) {
15291
- throw new Error("rendering='subscriber' requires `template`");
15292
- }
15293
- const inputs = [
15294
- { label: "spec", origin: "raw", payload: { spec } }
15295
- ];
15296
- if (options.rendering === "producer") {
15297
- inputs.push({ label: "prompt", origin: "raw", payload: { text: options.prompt } });
15298
- } else {
15299
- inputs.push({ label: "template", origin: "raw", payload: { text: options.template } });
15300
- if (options.vars) {
15301
- inputs.push({ label: "vars", origin: "raw", payload: options.vars });
15302
- }
15303
- }
15304
- if (options.artifacts) {
15305
- for (const artifact of options.artifacts) {
15306
- inputs.push({
15307
- label: "artifacts",
15308
- origin: artifact.origin,
15309
- payload: { label: artifact.label, ...artifact.payload }
15310
- });
15311
- }
15312
- }
15313
- return inputs;
15314
- }
15315
- function readPromptExecutionSpec(inputs) {
15316
- const specRow = inputs.find((i) => i.label === "spec");
15317
- if (!specRow)
15318
- throw new Error("prompt-execution: missing `spec` input row");
15319
- const spec = specRow.payload.spec;
15320
- if (!spec)
15321
- throw new Error("prompt-execution: spec row payload missing `spec` field");
15322
- if (spec.rendering !== "producer" && spec.rendering !== "subscriber") {
15323
- throw new Error(`prompt-execution: invalid spec.rendering "${spec.rendering}"`);
15324
- }
15325
- if (typeof spec.outputLabel !== "string" || spec.outputLabel.length === 0) {
15326
- throw new Error("prompt-execution: spec.outputLabel must be a non-empty string");
15327
- }
15328
- if (typeof spec.outputSchema !== "object" || spec.outputSchema === null) {
15329
- throw new Error("prompt-execution: spec.outputSchema must be a JSON Schema object");
15330
- }
15331
- return spec;
15332
- }
15333
- }
15334
- });
15335
-
15336
15268
  // ../../packages/jobs/dist/client.js
15337
15269
  var require_client = __commonJS({
15338
15270
  "../../packages/jobs/dist/client.js"(exports2) {
15339
15271
  "use strict";
15340
15272
  Object.defineProperty(exports2, "__esModule", { value: true });
15341
15273
  exports2.JobsClient = void 0;
15342
- var prompt_execution_1 = require_prompt_execution();
15343
15274
  var JobsClient = class {
15344
15275
  baseUrl;
15345
15276
  apiKey;
@@ -15388,19 +15319,19 @@ var require_client = __commonJS({
15388
15319
  this.onResponse?.(response);
15389
15320
  return response;
15390
15321
  }
15391
- // ── Attention Pools ──────────────────────────────────────────────
15392
- async createAttentionPool(options) {
15393
- return this.request("POST", "/api/attention-pools", options);
15322
+ // ── Job Pools ──────────────────────────────────────────────
15323
+ async createJobPool(options) {
15324
+ return this.request("POST", "/api/job-pools", options);
15394
15325
  }
15395
15326
  /**
15396
15327
  * Idempotent upsert by `(principal_class, principal_id, name)`. When the
15397
15328
  * pool exists, returns the existing row without modifying membership
15398
15329
  * constraints. The Sift provisioning hook relies on this semantics.
15399
15330
  */
15400
- async findOrCreateAttentionPool(options) {
15401
- return this.request("POST", "/api/attention-pools?idempotent=true", options);
15331
+ async findOrCreateJobPool(options) {
15332
+ return this.request("POST", "/api/job-pools?idempotent=true", options);
15402
15333
  }
15403
- async listAttentionPools(filters) {
15334
+ async listJobPools(filters) {
15404
15335
  const params = new URLSearchParams();
15405
15336
  if (filters?.principalClass)
15406
15337
  params.set("principalClass", filters.principalClass);
@@ -15409,47 +15340,45 @@ var require_client = __commonJS({
15409
15340
  if (filters?.name)
15410
15341
  params.set("name", filters.name);
15411
15342
  const qs = params.toString();
15412
- return this.request("GET", `/api/attention-pools${qs ? `?${qs}` : ""}`);
15343
+ return this.request("GET", `/api/job-pools${qs ? `?${qs}` : ""}`);
15413
15344
  }
15414
- async getAttentionPool(poolId) {
15415
- return this.request("GET", `/api/attention-pools/${poolId}`);
15345
+ async getJobPool(poolId) {
15346
+ return this.request("GET", `/api/job-pools/${poolId}`);
15416
15347
  }
15417
- async resolveAttentionPoolByName(name) {
15418
- const pools = await this.listAttentionPools({ name });
15348
+ async resolveJobPoolByName(name) {
15349
+ const pools = await this.listJobPools({ name });
15419
15350
  return pools.find((p) => p.name === name);
15420
15351
  }
15421
15352
  /** Internal: resolve a `PoolRef` to a pool id. */
15422
15353
  async resolvePoolRef(ref) {
15423
15354
  if ("id" in ref)
15424
15355
  return ref.id;
15425
- const pool = await this.resolveAttentionPoolByName(ref.name);
15356
+ const pool = await this.resolveJobPoolByName(ref.name);
15426
15357
  if (!pool)
15427
- throw new Error(`Attention pool not found by name: "${ref.name}"`);
15358
+ throw new Error(`Job pool not found by name: "${ref.name}"`);
15428
15359
  return pool.id;
15429
15360
  }
15430
15361
  // ── Members ──────────────────────────────────────────────────────
15431
15362
  // A subscriber joins a pool by registering as a member of it. These
15432
- // map to the server's `/api/attention-pools/:poolId/members` routes.
15363
+ // map to the server's `/api/job-pools/:poolId/members` routes.
15433
15364
  async listMembers(poolId) {
15434
- return this.request("GET", `/api/attention-pools/${poolId}/members`);
15365
+ return this.request("GET", `/api/job-pools/${poolId}/members`);
15435
15366
  }
15436
15367
  async registerMember(poolId, options) {
15437
- return this.request("POST", `/api/attention-pools/${poolId}/members`, options);
15368
+ return this.request("POST", `/api/job-pools/${poolId}/members`, options);
15438
15369
  }
15439
15370
  async updateMember(poolId, memberId, options) {
15440
- return this.request("PUT", `/api/attention-pools/${poolId}/members/${memberId}`, options);
15371
+ return this.request("PUT", `/api/job-pools/${poolId}/members/${memberId}`, options);
15441
15372
  }
15442
15373
  // ── Jobs (producer) ──────────────────────────────────────────────
15443
15374
  /**
15444
- * Enqueue a job into an attention pool. The job's `inputs` shape
15445
- * identifies its type; the server validates against the pool's
15446
- * `accepted_job_types`.
15375
+ * Enqueue a job into a job pool. The `inputs` are opaque to Jobs; a Shuttle
15376
+ * reads the strategy header inside them to decide how to run it (ADR 0005).
15447
15377
  */
15448
15378
  async enqueueJob(options) {
15449
- const attentionPoolId = await this.resolvePoolRef(options.pool);
15379
+ const jobPoolId = await this.resolvePoolRef(options.pool);
15450
15380
  const body = {
15451
- attentionPoolId,
15452
- jobType: options.jobType ?? prompt_execution_1.DEFAULT_JOB_TYPE,
15381
+ jobPoolId,
15453
15382
  instructions: options.instructions,
15454
15383
  maxAttempts: options.maxAttempts,
15455
15384
  deadlineDuration: options.deadlineDuration,
@@ -15509,73 +15438,6 @@ var require_client = __commonJS({
15509
15438
  const qs = params.toString();
15510
15439
  return this.requestPaginated("GET", `/api/my/jobs${qs ? `?${qs}` : ""}`);
15511
15440
  }
15512
- // ── Prompt-execution helpers ─────────────────────────────────────
15513
- /**
15514
- * Fire-and-forget prompt-execution enqueue. Returns the job id; the
15515
- * caller is responsible for correlating completion (Loom's path).
15516
- */
15517
- async enqueuePromptExecutionAsync(options) {
15518
- const inputs = (0, prompt_execution_1.buildPromptExecutionInputs)(options);
15519
- const job = await this.enqueueJob({
15520
- pool: options.pool,
15521
- jobType: "prompt-execution",
15522
- priority: options.priority,
15523
- tags: options.tags,
15524
- maxAttempts: options.maxAttempts,
15525
- deadlineDuration: options.deadlineDuration,
15526
- clientRef: options.clientRef,
15527
- clientContext: options.clientContext,
15528
- inputs
15529
- });
15530
- return { jobId: job.id };
15531
- }
15532
- /**
15533
- * Awaitable prompt-execution. Enqueues, then polls until the
15534
- * subscriber submits a schema-valid output (or the job fails / cancels
15535
- * / times out). NATS push will replace polling when available; the
15536
- * public API is unchanged.
15537
- */
15538
- async enqueuePromptExecution(options) {
15539
- const { jobId } = await this.enqueuePromptExecutionAsync(options);
15540
- const startedAt = Date.now();
15541
- const deadlineMs = options.deadlineDuration ? startedAt + parseIso8601DurationMs(options.deadlineDuration) : Infinity;
15542
- let pollIntervalMs = 2e3;
15543
- const maxPollIntervalMs = 1e4;
15544
- while (true) {
15545
- if (options.signal?.aborted) {
15546
- try {
15547
- await this.cancelJob(jobId);
15548
- } catch {
15549
- }
15550
- return { jobId, status: "cancelled", reason: "aborted by caller" };
15551
- }
15552
- if (Date.now() > deadlineMs) {
15553
- return { jobId, status: "timed_out", reason: "deadline elapsed" };
15554
- }
15555
- const job = await this.getJob(jobId);
15556
- const outputs = await this.listOutputs(jobId);
15557
- if (job.status === "completed" || job.status === "succeeded") {
15558
- const result = parsePromptExecutionOutputs(jobId, outputs, options.output.label);
15559
- return result;
15560
- }
15561
- if (job.status === "failed" || job.status === "cancelled" || job.status === "abandoned") {
15562
- const usage = pickUsage(outputs);
15563
- const reason = readFailureReason(outputs) ?? job.status;
15564
- const status = reason === "refused_over_cap" ? "refused_over_cap" : "failed";
15565
- const result = {
15566
- jobId,
15567
- status,
15568
- reason,
15569
- rawOutputs: outputs.map((o) => ({ label: o.label ?? "", content: o.content }))
15570
- };
15571
- if (usage)
15572
- result.usage = usage;
15573
- return result;
15574
- }
15575
- await sleep(pollIntervalMs);
15576
- pollIntervalMs = Math.min(pollIntervalMs * 1.5, maxPollIntervalMs);
15577
- }
15578
- }
15579
15441
  // ── HTTP plumbing ────────────────────────────────────────────────
15580
15442
  async request(method, path, body) {
15581
15443
  const url = `${this.baseUrl}${path}`;
@@ -15605,170 +15467,6 @@ var require_client = __commonJS({
15605
15467
  }
15606
15468
  };
15607
15469
  exports2.JobsClient = JobsClient;
15608
- function sleep(ms) {
15609
- return new Promise((resolve) => setTimeout(resolve, ms));
15610
- }
15611
- function parseIso8601DurationMs(s) {
15612
- const m = /^PT(?:(\d+)H)?(?:(\d+)M)?(?:(\d+(?:\.\d+)?)S)?$/.exec(s);
15613
- if (!m)
15614
- return 0;
15615
- const hours = m[1] ? parseInt(m[1], 10) : 0;
15616
- const minutes = m[2] ? parseInt(m[2], 10) : 0;
15617
- const seconds = m[3] ? parseFloat(m[3]) : 0;
15618
- return (hours * 3600 + minutes * 60) * 1e3 + seconds * 1e3;
15619
- }
15620
- function parsePromptExecutionOutputs(jobId, outputs, outputLabel) {
15621
- const usage = pickUsage(outputs);
15622
- const labelled = outputs.find((o) => o.label === outputLabel);
15623
- if (!labelled) {
15624
- const result2 = {
15625
- jobId,
15626
- status: "failed",
15627
- reason: `no output with label "${outputLabel}"`,
15628
- rawOutputs: outputs.map((o) => ({ label: o.label ?? "", content: o.content }))
15629
- };
15630
- if (usage)
15631
- result2.usage = usage;
15632
- return result2;
15633
- }
15634
- const result = {
15635
- jobId,
15636
- status: "succeeded",
15637
- output: labelled.content,
15638
- rawOutputs: outputs.map((o) => ({ label: o.label ?? "", content: o.content }))
15639
- };
15640
- if (usage)
15641
- result.usage = usage;
15642
- return result;
15643
- }
15644
- function pickUsage(outputs) {
15645
- const u = outputs.find((o) => o.label === "usage");
15646
- if (!u)
15647
- return void 0;
15648
- return u.content;
15649
- }
15650
- function readFailureReason(outputs) {
15651
- const f = outputs.find((o) => o.label === "failure");
15652
- if (!f)
15653
- return void 0;
15654
- const reason = f.content.reason;
15655
- return typeof reason === "string" ? reason : void 0;
15656
- }
15657
- }
15658
- });
15659
-
15660
- // ../../packages/jobs/dist/prompt-execution-render.js
15661
- var require_prompt_execution_render = __commonJS({
15662
- "../../packages/jobs/dist/prompt-execution-render.js"(exports2) {
15663
- "use strict";
15664
- Object.defineProperty(exports2, "__esModule", { value: true });
15665
- exports2.renderPromptExecution = renderPromptExecution;
15666
- exports2.renderTemplate = renderTemplate;
15667
- var prompt_execution_1 = require_prompt_execution();
15668
- function renderPromptExecution(inputs) {
15669
- const spec = (0, prompt_execution_1.readPromptExecutionSpec)(inputs);
15670
- const artifacts = [];
15671
- for (const i of inputs) {
15672
- if (i.label === "artifacts") {
15673
- const label = i.payload.label ?? "";
15674
- artifacts.push({ label, payload: i.payload });
15675
- }
15676
- }
15677
- let prompt = "";
15678
- if (spec.rendering === "producer") {
15679
- const promptRow = inputs.find((i) => i.label === "prompt");
15680
- if (!promptRow)
15681
- throw new Error("prompt-execution: rendering='producer' but no `prompt` input row");
15682
- const text = promptRow.payload.text;
15683
- if (typeof text !== "string") {
15684
- throw new Error("prompt-execution: prompt.payload.text must be a string");
15685
- }
15686
- prompt = text;
15687
- } else {
15688
- const templateRow = inputs.find((i) => i.label === "template");
15689
- if (!templateRow)
15690
- throw new Error("prompt-execution: rendering='subscriber' but no `template` input row");
15691
- const text = templateRow.payload.text;
15692
- if (typeof text !== "string") {
15693
- throw new Error("prompt-execution: template.payload.text must be a string");
15694
- }
15695
- const varsRow = inputs.find((i) => i.label === "vars");
15696
- const vars = varsRow?.payload ?? {};
15697
- prompt = renderTemplate(text, vars);
15698
- }
15699
- return { spec, prompt, artifacts };
15700
- }
15701
- function renderTemplate(template, vars) {
15702
- const eachRe = /\{\{#each\s+([a-zA-Z_$][\w$]*)\s*\}\}([\s\S]*?)\{\{\/each\}\}/g;
15703
- let out = template.replace(eachRe, (_match, name, body) => {
15704
- const list = vars[name];
15705
- if (!Array.isArray(list))
15706
- return "";
15707
- return list.map((item) => body.replace(/\{\{\s*this\s*\}\}/g, String(item))).join("");
15708
- });
15709
- out = out.replace(/\{\{\s*([a-zA-Z_$][\w$]*)\s*\}\}/g, (_match, name) => {
15710
- if (Object.prototype.hasOwnProperty.call(vars, name)) {
15711
- const v = vars[name];
15712
- return v === null || v === void 0 ? "" : String(v);
15713
- }
15714
- return "";
15715
- });
15716
- return out;
15717
- }
15718
- }
15719
- });
15720
-
15721
- // ../../packages/jobs/dist/observers.js
15722
- var require_observers = __commonJS({
15723
- "../../packages/jobs/dist/observers.js"(exports2) {
15724
- "use strict";
15725
- Object.defineProperty(exports2, "__esModule", { value: true });
15726
- exports2.ObserverChain = exports2.SpendCapExceeded = void 0;
15727
- var SpendCapExceeded = class extends Error {
15728
- cap;
15729
- used;
15730
- limit;
15731
- constructor(cap, used, limit) {
15732
- super(`Spend cap "${cap}" exceeded: used ${used}, limit ${limit}`);
15733
- this.cap = cap;
15734
- this.used = used;
15735
- this.limit = limit;
15736
- this.name = "SpendCapExceeded";
15737
- }
15738
- };
15739
- exports2.SpendCapExceeded = SpendCapExceeded;
15740
- var VETO_EVENTS = /* @__PURE__ */ new Set([
15741
- "spend.preflight"
15742
- ]);
15743
- var ObserverChain = class {
15744
- observers;
15745
- constructor(observers = []) {
15746
- this.observers = observers;
15747
- }
15748
- /**
15749
- * Notify every observer in registered order. Errors on non-veto events
15750
- * are caught and logged via the caller-supplied logger; veto-event
15751
- * errors propagate so the dispatcher can react.
15752
- */
15753
- async notify(event, onObserverError) {
15754
- const isVeto = VETO_EVENTS.has(event.kind);
15755
- for (const observer of this.observers) {
15756
- try {
15757
- await observer.notify(event);
15758
- } catch (err) {
15759
- if (isVeto)
15760
- throw err;
15761
- if (onObserverError)
15762
- onObserverError(err, observer.name, event);
15763
- }
15764
- }
15765
- }
15766
- /** Number of registered observers; useful for tests. */
15767
- get size() {
15768
- return this.observers.length;
15769
- }
15770
- };
15771
- exports2.ObserverChain = ObserverChain;
15772
15470
  }
15773
15471
  });
15774
15472
 
@@ -15776,46 +15474,8 @@ var require_observers = __commonJS({
15776
15474
  var require_subscribe = __commonJS({
15777
15475
  "../../packages/jobs/dist/subscribe.js"(exports2) {
15778
15476
  "use strict";
15779
- var __createBinding = exports2 && exports2.__createBinding || (Object.create ? (function(o, m, k, k2) {
15780
- if (k2 === void 0) k2 = k;
15781
- var desc = Object.getOwnPropertyDescriptor(m, k);
15782
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
15783
- desc = { enumerable: true, get: function() {
15784
- return m[k];
15785
- } };
15786
- }
15787
- Object.defineProperty(o, k2, desc);
15788
- }) : (function(o, m, k, k2) {
15789
- if (k2 === void 0) k2 = k;
15790
- o[k2] = m[k];
15791
- }));
15792
- var __setModuleDefault = exports2 && exports2.__setModuleDefault || (Object.create ? (function(o, v) {
15793
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15794
- }) : function(o, v) {
15795
- o["default"] = v;
15796
- });
15797
- var __importStar = exports2 && exports2.__importStar || /* @__PURE__ */ (function() {
15798
- var ownKeys = function(o) {
15799
- ownKeys = Object.getOwnPropertyNames || function(o2) {
15800
- var ar = [];
15801
- for (var k in o2) if (Object.prototype.hasOwnProperty.call(o2, k)) ar[ar.length] = k;
15802
- return ar;
15803
- };
15804
- return ownKeys(o);
15805
- };
15806
- return function(mod) {
15807
- if (mod && mod.__esModule) return mod;
15808
- var result = {};
15809
- if (mod != null) {
15810
- for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
15811
- }
15812
- __setModuleDefault(result, mod);
15813
- return result;
15814
- };
15815
- })();
15816
15477
  Object.defineProperty(exports2, "__esModule", { value: true });
15817
15478
  exports2.subscribe = subscribe;
15818
- var observers_1 = require_observers();
15819
15479
  var NULL_LOGGER = {
15820
15480
  debug: () => {
15821
15481
  },
@@ -15826,14 +15486,13 @@ var require_subscribe = __commonJS({
15826
15486
  error: () => {
15827
15487
  }
15828
15488
  };
15489
+ function sleep(ms) {
15490
+ return new Promise((resolve) => setTimeout(resolve, ms));
15491
+ }
15829
15492
  function subscribe(opts) {
15830
15493
  const logger = opts.logger ?? NULL_LOGGER;
15831
15494
  const pollIntervalMs = opts.pollIntervalMs ?? 2e3;
15832
15495
  const maxConcurrency = opts.maxConcurrency ?? 1;
15833
- const executorsByCapability = /* @__PURE__ */ new Map();
15834
- for (const executor of opts.executors) {
15835
- executorsByCapability.set(executor.capability.id, executor);
15836
- }
15837
15496
  let stopped = true;
15838
15497
  let pollTimer = null;
15839
15498
  let inflight = 0;
@@ -15851,19 +15510,10 @@ var require_subscribe = __commonJS({
15851
15510
  identityId: opts.subscriber.identityId,
15852
15511
  intelligence: opts.subscriber.intelligence,
15853
15512
  ...opts.subscriber.displayName !== void 0 ? { displayName: opts.subscriber.displayName } : {},
15854
- // The server has no first-class capabilities column; carry the
15855
- // advertised set in metadata so it persists on the member row.
15856
- metadata: {
15857
- ...opts.subscriber.metadata,
15858
- capabilities: opts.subscriber.capabilities
15859
- }
15513
+ ...opts.subscriber.metadata !== void 0 ? { metadata: opts.subscriber.metadata } : {}
15860
15514
  });
15861
15515
  }
15862
- logger.info("subscribe loop started", {
15863
- pools: resolvedPoolIds,
15864
- executors: Array.from(executorsByCapability.keys()),
15865
- maxConcurrency
15866
- });
15516
+ logger.info("subscribe loop started", { pools: resolvedPoolIds, maxConcurrency });
15867
15517
  schedulePoll(pollIntervalMs);
15868
15518
  }
15869
15519
  async function stop() {
@@ -15912,24 +15562,13 @@ var require_subscribe = __commonJS({
15912
15562
  schedulePoll(pollIntervalMs);
15913
15563
  }
15914
15564
  async function runOnce(available) {
15915
- const startedAt = Date.now();
15916
- await opts.observerChain.notify({
15917
- kind: "job.discovered",
15918
- jobId: available.id,
15919
- poolId: available.attentionPool.id,
15920
- poolName: available.attentionPool.name,
15921
- attempt: available.attempt,
15922
- tags: available.tags,
15923
- discoveredAt: (/* @__PURE__ */ new Date()).toISOString()
15924
- }, onObserverError);
15925
15565
  let dispatch;
15926
15566
  try {
15927
- await opts.observerChain.notify({ kind: "job.claim.requested", jobId: available.id, poolId: available.attentionPool.id }, onObserverError);
15928
15567
  dispatch = await opts.jobsClient.acceptDispatch(available.id);
15929
15568
  } catch (err) {
15930
15569
  const statusCode = err.statusCode;
15931
15570
  if (statusCode === 409) {
15932
- logger.debug?.("claim conflict; another subscriber accepted", { jobId: available.id });
15571
+ logger.debug?.("claim conflict; another member accepted", { jobId: available.id });
15933
15572
  return;
15934
15573
  }
15935
15574
  logger.error("failed to accept dispatch", {
@@ -15938,15 +15577,6 @@ var require_subscribe = __commonJS({
15938
15577
  });
15939
15578
  return;
15940
15579
  }
15941
- await opts.observerChain.notify({
15942
- kind: "job.claimed",
15943
- jobId: available.id,
15944
- attendanceId: dispatch.attendanceId,
15945
- attempt: dispatch.job.attempt,
15946
- deadline: dispatch.deadline,
15947
- claimedAt: dispatch.claimedAt,
15948
- dispatch
15949
- }, onObserverError);
15950
15580
  const controller = new AbortController();
15951
15581
  let deadlineTimer = null;
15952
15582
  if (dispatch.deadline) {
@@ -15957,215 +15587,2636 @@ var require_subscribe = __commonJS({
15957
15587
  controller.abort();
15958
15588
  }
15959
15589
  }
15590
+ let result;
15960
15591
  try {
15961
- await dispatchAndSubmit(dispatch, controller.signal, startedAt);
15592
+ result = await opts.onJob(dispatch, controller.signal);
15593
+ } catch (err) {
15594
+ result = {
15595
+ status: "failed",
15596
+ reason: `onJob threw: ${err instanceof Error ? err.message : String(err)}`
15597
+ };
15962
15598
  } finally {
15963
15599
  if (deadlineTimer !== null)
15964
15600
  clearTimeout(deadlineTimer);
15965
15601
  }
15602
+ try {
15603
+ for (const output of result.outputs ?? []) {
15604
+ await opts.jobsClient.createOutput(dispatch.job.id, {
15605
+ label: output.label,
15606
+ content: output.content
15607
+ });
15608
+ }
15609
+ await opts.jobsClient.submit(dispatch.job.id, {
15610
+ status: result.status,
15611
+ ...result.reason !== void 0 ? { reason: result.reason } : {}
15612
+ });
15613
+ } catch (err) {
15614
+ logger.error("submit/close failed", {
15615
+ jobId: dispatch.job.id,
15616
+ error: err instanceof Error ? err.message : String(err)
15617
+ });
15618
+ }
15619
+ }
15620
+ return { start, stop };
15621
+ }
15622
+ }
15623
+ });
15624
+
15625
+ // ../../packages/jobs/dist/index.js
15626
+ var require_dist2 = __commonJS({
15627
+ "../../packages/jobs/dist/index.js"(exports2) {
15628
+ "use strict";
15629
+ Object.defineProperty(exports2, "__esModule", { value: true });
15630
+ exports2.subscribe = exports2.JobsClient = void 0;
15631
+ var client_1 = require_client();
15632
+ Object.defineProperty(exports2, "JobsClient", { enumerable: true, get: function() {
15633
+ return client_1.JobsClient;
15634
+ } });
15635
+ var subscribe_1 = require_subscribe();
15636
+ Object.defineProperty(exports2, "subscribe", { enumerable: true, get: function() {
15637
+ return subscribe_1.subscribe;
15638
+ } });
15639
+ }
15640
+ });
15641
+
15642
+ // ../../packages/loom/dist/runtime/prompt-execution.js
15643
+ var require_prompt_execution = __commonJS({
15644
+ "../../packages/loom/dist/runtime/prompt-execution.js"(exports2) {
15645
+ "use strict";
15646
+ Object.defineProperty(exports2, "__esModule", { value: true });
15647
+ exports2.readPromptExecutionSpec = readPromptExecutionSpec;
15648
+ exports2.renderPromptExecution = renderPromptExecution;
15649
+ exports2.pickProviderHints = pickProviderHints;
15650
+ exports2.renderTemplate = renderTemplate;
15651
+ function readPromptExecutionSpec(inputs) {
15652
+ const specRow = inputs.find((i) => i.label === "spec");
15653
+ if (!specRow)
15654
+ throw new Error("prompt-execution: missing `spec` input row");
15655
+ const spec = specRow.payload.spec;
15656
+ if (!spec)
15657
+ throw new Error("prompt-execution: spec row payload missing `spec` field");
15658
+ if (spec.rendering !== "producer" && spec.rendering !== "subscriber") {
15659
+ throw new Error(`prompt-execution: invalid spec.rendering "${spec.rendering}"`);
15660
+ }
15661
+ if (typeof spec.outputLabel !== "string" || spec.outputLabel.length === 0) {
15662
+ throw new Error("prompt-execution: spec.outputLabel must be a non-empty string");
15663
+ }
15664
+ if (typeof spec.outputSchema !== "object" || spec.outputSchema === null) {
15665
+ throw new Error("prompt-execution: spec.outputSchema must be a JSON Schema object");
15666
+ }
15667
+ return spec;
15668
+ }
15669
+ function renderPromptExecution(inputs) {
15670
+ const spec = readPromptExecutionSpec(inputs);
15671
+ const artifacts = [];
15672
+ for (const i of inputs) {
15673
+ if (i.label === "artifacts") {
15674
+ const label = i.payload.label ?? "";
15675
+ artifacts.push({ label, payload: i.payload });
15676
+ }
15677
+ }
15678
+ let prompt = "";
15679
+ if (spec.rendering === "producer") {
15680
+ const promptRow = inputs.find((i) => i.label === "prompt");
15681
+ if (!promptRow)
15682
+ throw new Error("prompt-execution: rendering='producer' but no `prompt` input row");
15683
+ const text = promptRow.payload.text;
15684
+ if (typeof text !== "string") {
15685
+ throw new Error("prompt-execution: prompt.payload.text must be a string");
15686
+ }
15687
+ prompt = text;
15688
+ } else {
15689
+ const templateRow = inputs.find((i) => i.label === "template");
15690
+ if (!templateRow)
15691
+ throw new Error("prompt-execution: rendering='subscriber' but no `template` input row");
15692
+ const text = templateRow.payload.text;
15693
+ if (typeof text !== "string") {
15694
+ throw new Error("prompt-execution: template.payload.text must be a string");
15695
+ }
15696
+ const varsRow = inputs.find((i) => i.label === "vars");
15697
+ const vars = varsRow?.payload ?? {};
15698
+ prompt = renderTemplate(text, vars);
15699
+ }
15700
+ return { spec, prompt, artifacts };
15701
+ }
15702
+ function pickProviderHints(spec, capabilityId) {
15703
+ if (!spec.providerHints)
15704
+ return {};
15705
+ const key = capabilityId.replace(/-([a-z])/g, (_m, c) => c.toUpperCase());
15706
+ const matched = spec.providerHints[key];
15707
+ return matched && typeof matched === "object" ? matched : {};
15708
+ }
15709
+ function renderTemplate(template, vars) {
15710
+ const eachRe = /\{\{#each\s+([a-zA-Z_$][\w$]*)\s*\}\}([\s\S]*?)\{\{\/each\}\}/g;
15711
+ let out = template.replace(eachRe, (_match, name, body) => {
15712
+ const list = vars[name];
15713
+ if (!Array.isArray(list))
15714
+ return "";
15715
+ return list.map((item) => body.replace(/\{\{\s*this\s*\}\}/g, String(item))).join("");
15716
+ });
15717
+ out = out.replace(/\{\{\s*([a-zA-Z_$][\w$]*)\s*\}\}/g, (_match, name) => {
15718
+ if (Object.prototype.hasOwnProperty.call(vars, name)) {
15719
+ const v = vars[name];
15720
+ return v === null || v === void 0 ? "" : String(v);
15721
+ }
15722
+ return "";
15723
+ });
15724
+ return out;
15725
+ }
15726
+ }
15727
+ });
15728
+
15729
+ // ../../packages/loom/dist/runtime/strategy.js
15730
+ var require_strategy = __commonJS({
15731
+ "../../packages/loom/dist/runtime/strategy.js"(exports2) {
15732
+ "use strict";
15733
+ Object.defineProperty(exports2, "__esModule", { value: true });
15734
+ exports2.PROMPT_EXECUTION_STRATEGY = exports2.SHUTTLE_STRATEGY_LABEL = void 0;
15735
+ exports2.shuttleStrategyInput = shuttleStrategyInput;
15736
+ exports2.readShuttleStrategy = readShuttleStrategy;
15737
+ exports2.SHUTTLE_STRATEGY_LABEL = "shuttle-strategy";
15738
+ exports2.PROMPT_EXECUTION_STRATEGY = "prompt-execution";
15739
+ function shuttleStrategyInput(strategy) {
15740
+ return { label: exports2.SHUTTLE_STRATEGY_LABEL, origin: "raw", payload: { strategy } };
15741
+ }
15742
+ function readShuttleStrategy(inputs) {
15743
+ const row = inputs.find((i) => i.label === exports2.SHUTTLE_STRATEGY_LABEL);
15744
+ if (!row)
15745
+ return null;
15746
+ const strategy = row.payload.strategy;
15747
+ return typeof strategy === "string" ? strategy : null;
15748
+ }
15749
+ }
15750
+ });
15751
+
15752
+ // ../../packages/loom/dist/runtime/validate.js
15753
+ var require_validate = __commonJS({
15754
+ "../../packages/loom/dist/runtime/validate.js"(exports2) {
15755
+ "use strict";
15756
+ Object.defineProperty(exports2, "__esModule", { value: true });
15757
+ exports2.validateAgainstSchema = validateAgainstSchema;
15758
+ function typeOf(value) {
15759
+ if (value === null)
15760
+ return "null";
15761
+ if (Array.isArray(value))
15762
+ return "array";
15763
+ const t = typeof value;
15764
+ if (t === "number")
15765
+ return Number.isInteger(value) ? "integer" : "number";
15766
+ if (t === "boolean")
15767
+ return "boolean";
15768
+ if (t === "string")
15769
+ return "string";
15770
+ return "object";
15771
+ }
15772
+ function matchesType(value, expected) {
15773
+ const actual = typeOf(value);
15774
+ if (expected === "number")
15775
+ return actual === "number" || actual === "integer";
15776
+ if (expected === "integer")
15777
+ return actual === "integer";
15778
+ return actual === expected;
15779
+ }
15780
+ function walk(value, schema, path, errors) {
15781
+ if (schema === true)
15782
+ return;
15783
+ if (schema === false) {
15784
+ errors.push(`${path || "value"} is not allowed`);
15785
+ return;
15786
+ }
15787
+ if (schema.const !== void 0 && JSON.stringify(value) !== JSON.stringify(schema.const)) {
15788
+ errors.push(`${path || "value"} must equal ${JSON.stringify(schema.const)}`);
15789
+ }
15790
+ if (Array.isArray(schema.enum) && !schema.enum.some((e) => JSON.stringify(e) === JSON.stringify(value))) {
15791
+ errors.push(`${path || "value"} must be one of ${JSON.stringify(schema.enum)}`);
15792
+ }
15793
+ const types = Array.isArray(schema.type) ? schema.type : schema.type ? [schema.type] : [];
15794
+ if (types.length > 0 && !types.some((t) => matchesType(value, t))) {
15795
+ errors.push(`${path || "value"} expected type ${types.join("|")}, got ${typeOf(value)}`);
15796
+ return;
15797
+ }
15798
+ if (typeOf(value) === "object") {
15799
+ const obj = value;
15800
+ if (Array.isArray(schema.required)) {
15801
+ for (const key of schema.required) {
15802
+ if (!(key in obj))
15803
+ errors.push(`${path ? `${path}.` : ""}${key} is required`);
15804
+ }
15805
+ }
15806
+ if (schema.properties) {
15807
+ for (const [key, sub] of Object.entries(schema.properties)) {
15808
+ if (key in obj)
15809
+ walk(obj[key], sub, `${path ? `${path}.` : ""}${key}`, errors);
15810
+ }
15811
+ }
15812
+ }
15813
+ if (typeOf(value) === "array" && schema.items && !Array.isArray(schema.items)) {
15814
+ const itemSchema = schema.items;
15815
+ value.forEach((item, i) => walk(item, itemSchema, `${path}[${i}]`, errors));
15816
+ }
15817
+ }
15818
+ function validateAgainstSchema(value, schema) {
15819
+ const errors = [];
15820
+ walk(value ?? null, schema, "", errors);
15821
+ return { valid: errors.length === 0, errors };
15822
+ }
15823
+ }
15824
+ });
15825
+
15826
+ // ../../packages/loom/dist/runtime/index.js
15827
+ var require_runtime = __commonJS({
15828
+ "../../packages/loom/dist/runtime/index.js"(exports2) {
15829
+ "use strict";
15830
+ Object.defineProperty(exports2, "__esModule", { value: true });
15831
+ exports2.validateAgainstSchema = exports2.readShuttleStrategy = exports2.shuttleStrategyInput = exports2.PROMPT_EXECUTION_STRATEGY = exports2.SHUTTLE_STRATEGY_LABEL = exports2.pickProviderHints = exports2.renderTemplate = exports2.renderPromptExecution = exports2.readPromptExecutionSpec = void 0;
15832
+ var prompt_execution_1 = require_prompt_execution();
15833
+ Object.defineProperty(exports2, "readPromptExecutionSpec", { enumerable: true, get: function() {
15834
+ return prompt_execution_1.readPromptExecutionSpec;
15835
+ } });
15836
+ Object.defineProperty(exports2, "renderPromptExecution", { enumerable: true, get: function() {
15837
+ return prompt_execution_1.renderPromptExecution;
15838
+ } });
15839
+ Object.defineProperty(exports2, "renderTemplate", { enumerable: true, get: function() {
15840
+ return prompt_execution_1.renderTemplate;
15841
+ } });
15842
+ Object.defineProperty(exports2, "pickProviderHints", { enumerable: true, get: function() {
15843
+ return prompt_execution_1.pickProviderHints;
15844
+ } });
15845
+ var strategy_1 = require_strategy();
15846
+ Object.defineProperty(exports2, "SHUTTLE_STRATEGY_LABEL", { enumerable: true, get: function() {
15847
+ return strategy_1.SHUTTLE_STRATEGY_LABEL;
15848
+ } });
15849
+ Object.defineProperty(exports2, "PROMPT_EXECUTION_STRATEGY", { enumerable: true, get: function() {
15850
+ return strategy_1.PROMPT_EXECUTION_STRATEGY;
15851
+ } });
15852
+ Object.defineProperty(exports2, "shuttleStrategyInput", { enumerable: true, get: function() {
15853
+ return strategy_1.shuttleStrategyInput;
15854
+ } });
15855
+ Object.defineProperty(exports2, "readShuttleStrategy", { enumerable: true, get: function() {
15856
+ return strategy_1.readShuttleStrategy;
15857
+ } });
15858
+ var validate_1 = require_validate();
15859
+ Object.defineProperty(exports2, "validateAgainstSchema", { enumerable: true, get: function() {
15860
+ return validate_1.validateAgainstSchema;
15861
+ } });
15862
+ }
15863
+ });
15864
+
15865
+ // ../../packages/loom/dist/authoring/prompt-execution.js
15866
+ var require_prompt_execution2 = __commonJS({
15867
+ "../../packages/loom/dist/authoring/prompt-execution.js"(exports2) {
15868
+ "use strict";
15869
+ Object.defineProperty(exports2, "__esModule", { value: true });
15870
+ exports2.buildPromptExecutionInputs = buildPromptExecutionInputs;
15871
+ var strategy_1 = require_strategy();
15872
+ function buildPromptExecutionInputs(options) {
15873
+ const spec = {
15874
+ rendering: options.rendering,
15875
+ outputLabel: options.output.label,
15876
+ outputSchema: options.output.schema
15877
+ };
15878
+ if (options.providerHints)
15879
+ spec.providerHints = options.providerHints;
15880
+ if (options.costCapHint)
15881
+ spec.costCapHint = options.costCapHint;
15882
+ if (options.rendering === "producer" && !options.prompt) {
15883
+ throw new Error("rendering='producer' requires `prompt`");
15884
+ }
15885
+ if (options.rendering === "subscriber" && !options.template) {
15886
+ throw new Error("rendering='subscriber' requires `template`");
15887
+ }
15888
+ const inputs = [
15889
+ (0, strategy_1.shuttleStrategyInput)(strategy_1.PROMPT_EXECUTION_STRATEGY),
15890
+ { label: "spec", origin: "raw", payload: { spec } }
15891
+ ];
15892
+ if (options.rendering === "producer") {
15893
+ inputs.push({ label: "prompt", origin: "raw", payload: { text: options.prompt } });
15894
+ } else {
15895
+ inputs.push({ label: "template", origin: "raw", payload: { text: options.template } });
15896
+ if (options.vars) {
15897
+ inputs.push({ label: "vars", origin: "raw", payload: options.vars });
15898
+ }
15899
+ }
15900
+ if (options.artifacts) {
15901
+ for (const artifact of options.artifacts) {
15902
+ inputs.push({
15903
+ label: "artifacts",
15904
+ origin: artifact.origin,
15905
+ payload: { label: artifact.label, ...artifact.payload }
15906
+ });
15907
+ }
15908
+ }
15909
+ return inputs;
15910
+ }
15911
+ }
15912
+ });
15913
+
15914
+ // ../../packages/loom/dist/builder/define-workflow.js
15915
+ var require_define_workflow = __commonJS({
15916
+ "../../packages/loom/dist/builder/define-workflow.js"(exports2) {
15917
+ "use strict";
15918
+ var __importDefault = exports2 && exports2.__importDefault || function(mod) {
15919
+ return mod && mod.__esModule ? mod : { "default": mod };
15920
+ };
15921
+ Object.defineProperty(exports2, "__esModule", { value: true });
15922
+ exports2.defineWorkflow = defineWorkflow;
15923
+ var node_path_1 = __importDefault(require("node:path"));
15924
+ var node_url_1 = __importDefault(require("node:url"));
15925
+ function defineWorkflow(opts) {
15926
+ const sourcePath = opts.__dirname ?? captureCallerPath();
15927
+ const def = {
15928
+ name: opts.name,
15929
+ owner: opts.owner,
15930
+ nodes: opts.nodes,
15931
+ __sourcePath: sourcePath
15932
+ };
15933
+ if (opts.description !== void 0)
15934
+ def.description = opts.description;
15935
+ if (opts.retain !== void 0)
15936
+ def.retain = opts.retain;
15937
+ if (opts.transitions !== void 0)
15938
+ def.transitions = opts.transitions;
15939
+ return def;
15940
+ }
15941
+ function captureCallerPath() {
15942
+ const err = new Error();
15943
+ const stack = err.stack ?? "";
15944
+ const lines = stack.split("\n");
15945
+ const selfMarkers = ["/packages/loom/src/", "/packages/loom/dist/"];
15946
+ for (const line of lines) {
15947
+ const match = /\s+at\s+(?:.*?\s+)?\(?(.*?):\d+:\d+\)?$/.exec(line);
15948
+ if (!match)
15949
+ continue;
15950
+ let filePath = match[1];
15951
+ if (!filePath)
15952
+ continue;
15953
+ if (filePath.startsWith("file://")) {
15954
+ filePath = node_url_1.default.fileURLToPath(filePath);
15955
+ }
15956
+ if (!node_path_1.default.isAbsolute(filePath))
15957
+ continue;
15958
+ if (selfMarkers.some((m) => filePath.includes(m)))
15959
+ continue;
15960
+ if (filePath.endsWith("define-workflow.ts") || filePath.endsWith("define-workflow.js"))
15961
+ continue;
15962
+ return node_path_1.default.dirname(filePath);
15963
+ }
15964
+ return process.cwd();
15965
+ }
15966
+ }
15967
+ });
15968
+
15969
+ // ../../packages/loom/dist/builder/nodes.js
15970
+ var require_nodes = __commonJS({
15971
+ "../../packages/loom/dist/builder/nodes.js"(exports2) {
15972
+ "use strict";
15973
+ Object.defineProperty(exports2, "__esModule", { value: true });
15974
+ exports2.promptNode = promptNode;
15975
+ exports2.httpNode = httpNode;
15976
+ exports2.jobsCreateNode = jobsCreateNode;
15977
+ function promptNode(name, options) {
15978
+ return { name, entryBehavior: "loom.prompt", promptOptions: options };
15979
+ }
15980
+ function httpNode(name, options) {
15981
+ return { name, entryBehavior: "http.request", httpOptions: options };
15982
+ }
15983
+ function jobsCreateNode(name, options) {
15984
+ return { name, entryBehavior: "jobs.create", jobsCreateOptions: options };
15985
+ }
15986
+ }
15987
+ });
15988
+
15989
+ // ../../packages/loom/dist/builder/resolvers.js
15990
+ var require_resolvers = __commonJS({
15991
+ "../../packages/loom/dist/builder/resolvers.js"(exports2) {
15992
+ "use strict";
15993
+ Object.defineProperty(exports2, "__esModule", { value: true });
15994
+ exports2.principalJobPool = void 0;
15995
+ exports2.literalJobPool = literalJobPool;
15996
+ exports2.describeJobPoolRef = describeJobPoolRef;
15997
+ var RESOLVER_DESCRIPTORS = /* @__PURE__ */ new WeakMap();
15998
+ exports2.principalJobPool = makeNamedResolver("principal.job_pool_id");
15999
+ function literalJobPool(idOrName) {
16000
+ const fn = ((_ctx) => idOrName);
16001
+ const looksUuid = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(idOrName);
16002
+ const value = looksUuid ? { id: idOrName } : { name: idOrName };
16003
+ RESOLVER_DESCRIPTORS.set(fn, { kind: "literal", value });
16004
+ return fn;
16005
+ }
16006
+ function makeNamedResolver(resolverId) {
16007
+ const fn = ((ctx) => {
16008
+ if (!ctx.principal.jobPoolId) {
16009
+ throw new Error(`resolver '${resolverId}' requires ctx.principal.jobPoolId; consuming service must populate it before startSession`);
16010
+ }
16011
+ return ctx.principal.jobPoolId;
16012
+ });
16013
+ RESOLVER_DESCRIPTORS.set(fn, { kind: "resolver", resolverId });
16014
+ return fn;
16015
+ }
16016
+ function describeJobPoolRef(ref) {
16017
+ if (typeof ref === "function") {
16018
+ return RESOLVER_DESCRIPTORS.get(ref);
16019
+ }
16020
+ if (typeof ref === "object" && ref !== null) {
16021
+ if ("id" in ref && typeof ref.id === "string") {
16022
+ return { kind: "literal", value: { id: ref.id } };
16023
+ }
16024
+ if ("name" in ref && typeof ref.name === "string") {
16025
+ return { kind: "literal", value: { name: ref.name } };
16026
+ }
16027
+ }
16028
+ return void 0;
16029
+ }
16030
+ }
16031
+ });
16032
+
16033
+ // ../../packages/loom/dist/builder/transitions.js
16034
+ var require_transitions = __commonJS({
16035
+ "../../packages/loom/dist/builder/transitions.js"(exports2) {
16036
+ "use strict";
16037
+ Object.defineProperty(exports2, "__esModule", { value: true });
16038
+ exports2.synthesiseLinearChain = synthesiseLinearChain;
16039
+ function synthesiseLinearChain(nodes) {
16040
+ const edges = [];
16041
+ for (let i = 0; i < nodes.length - 1; i++) {
16042
+ edges.push({ from: nodes[i].name, to: nodes[i + 1].name });
16043
+ }
16044
+ return edges;
16045
+ }
16046
+ }
16047
+ });
16048
+
16049
+ // ../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@3.25.76/node_modules/zod-to-json-schema/dist/cjs/Options.js
16050
+ var require_Options = __commonJS({
16051
+ "../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@3.25.76/node_modules/zod-to-json-schema/dist/cjs/Options.js"(exports2) {
16052
+ "use strict";
16053
+ Object.defineProperty(exports2, "__esModule", { value: true });
16054
+ exports2.getDefaultOptions = exports2.defaultOptions = exports2.jsonDescription = exports2.ignoreOverride = void 0;
16055
+ exports2.ignoreOverride = Symbol("Let zodToJsonSchema decide on which parser to use");
16056
+ var jsonDescription = (jsonSchema, def) => {
16057
+ if (def.description) {
16058
+ try {
16059
+ return {
16060
+ ...jsonSchema,
16061
+ ...JSON.parse(def.description)
16062
+ };
16063
+ } catch {
16064
+ }
16065
+ }
16066
+ return jsonSchema;
16067
+ };
16068
+ exports2.jsonDescription = jsonDescription;
16069
+ exports2.defaultOptions = {
16070
+ name: void 0,
16071
+ $refStrategy: "root",
16072
+ basePath: ["#"],
16073
+ effectStrategy: "input",
16074
+ pipeStrategy: "all",
16075
+ dateStrategy: "format:date-time",
16076
+ mapStrategy: "entries",
16077
+ removeAdditionalStrategy: "passthrough",
16078
+ allowedAdditionalProperties: true,
16079
+ rejectedAdditionalProperties: false,
16080
+ definitionPath: "definitions",
16081
+ target: "jsonSchema7",
16082
+ strictUnions: false,
16083
+ definitions: {},
16084
+ errorMessages: false,
16085
+ markdownDescription: false,
16086
+ patternStrategy: "escape",
16087
+ applyRegexFlags: false,
16088
+ emailStrategy: "format:email",
16089
+ base64Strategy: "contentEncoding:base64",
16090
+ nameStrategy: "ref",
16091
+ openAiAnyTypeName: "OpenAiAnyType"
16092
+ };
16093
+ var getDefaultOptions = (options) => typeof options === "string" ? {
16094
+ ...exports2.defaultOptions,
16095
+ name: options
16096
+ } : {
16097
+ ...exports2.defaultOptions,
16098
+ ...options
16099
+ };
16100
+ exports2.getDefaultOptions = getDefaultOptions;
16101
+ }
16102
+ });
16103
+
16104
+ // ../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@3.25.76/node_modules/zod-to-json-schema/dist/cjs/Refs.js
16105
+ var require_Refs = __commonJS({
16106
+ "../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@3.25.76/node_modules/zod-to-json-schema/dist/cjs/Refs.js"(exports2) {
16107
+ "use strict";
16108
+ Object.defineProperty(exports2, "__esModule", { value: true });
16109
+ exports2.getRefs = void 0;
16110
+ var Options_js_1 = require_Options();
16111
+ var getRefs = (options) => {
16112
+ const _options = (0, Options_js_1.getDefaultOptions)(options);
16113
+ const currentPath = _options.name !== void 0 ? [..._options.basePath, _options.definitionPath, _options.name] : _options.basePath;
16114
+ return {
16115
+ ..._options,
16116
+ flags: { hasReferencedOpenAiAnyType: false },
16117
+ currentPath,
16118
+ propertyPath: void 0,
16119
+ seen: new Map(Object.entries(_options.definitions).map(([name, def]) => [
16120
+ def._def,
16121
+ {
16122
+ def: def._def,
16123
+ path: [..._options.basePath, _options.definitionPath, name],
16124
+ // Resolution of references will be forced even though seen, so it's ok that the schema is undefined here for now.
16125
+ jsonSchema: void 0
16126
+ }
16127
+ ]))
16128
+ };
16129
+ };
16130
+ exports2.getRefs = getRefs;
16131
+ }
16132
+ });
16133
+
16134
+ // ../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@3.25.76/node_modules/zod-to-json-schema/dist/cjs/errorMessages.js
16135
+ var require_errorMessages = __commonJS({
16136
+ "../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@3.25.76/node_modules/zod-to-json-schema/dist/cjs/errorMessages.js"(exports2) {
16137
+ "use strict";
16138
+ Object.defineProperty(exports2, "__esModule", { value: true });
16139
+ exports2.setResponseValueAndErrors = exports2.addErrorMessage = void 0;
16140
+ function addErrorMessage(res, key, errorMessage, refs) {
16141
+ if (!refs?.errorMessages)
16142
+ return;
16143
+ if (errorMessage) {
16144
+ res.errorMessage = {
16145
+ ...res.errorMessage,
16146
+ [key]: errorMessage
16147
+ };
16148
+ }
16149
+ }
16150
+ exports2.addErrorMessage = addErrorMessage;
16151
+ function setResponseValueAndErrors(res, key, value, errorMessage, refs) {
16152
+ res[key] = value;
16153
+ addErrorMessage(res, key, errorMessage, refs);
16154
+ }
16155
+ exports2.setResponseValueAndErrors = setResponseValueAndErrors;
16156
+ }
16157
+ });
16158
+
16159
+ // ../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@3.25.76/node_modules/zod-to-json-schema/dist/cjs/getRelativePath.js
16160
+ var require_getRelativePath = __commonJS({
16161
+ "../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@3.25.76/node_modules/zod-to-json-schema/dist/cjs/getRelativePath.js"(exports2) {
16162
+ "use strict";
16163
+ Object.defineProperty(exports2, "__esModule", { value: true });
16164
+ exports2.getRelativePath = void 0;
16165
+ var getRelativePath = (pathA, pathB) => {
16166
+ let i = 0;
16167
+ for (; i < pathA.length && i < pathB.length; i++) {
16168
+ if (pathA[i] !== pathB[i])
16169
+ break;
16170
+ }
16171
+ return [(pathA.length - i).toString(), ...pathB.slice(i)].join("/");
16172
+ };
16173
+ exports2.getRelativePath = getRelativePath;
16174
+ }
16175
+ });
16176
+
16177
+ // ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/index.cjs
16178
+ var require_v3 = __commonJS({
16179
+ "../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/index.cjs"(exports2) {
16180
+ "use strict";
16181
+ var __createBinding = exports2 && exports2.__createBinding || (Object.create ? (function(o, m, k, k2) {
16182
+ if (k2 === void 0) k2 = k;
16183
+ var desc = Object.getOwnPropertyDescriptor(m, k);
16184
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
16185
+ desc = { enumerable: true, get: function() {
16186
+ return m[k];
16187
+ } };
16188
+ }
16189
+ Object.defineProperty(o, k2, desc);
16190
+ }) : (function(o, m, k, k2) {
16191
+ if (k2 === void 0) k2 = k;
16192
+ o[k2] = m[k];
16193
+ }));
16194
+ var __setModuleDefault = exports2 && exports2.__setModuleDefault || (Object.create ? (function(o, v) {
16195
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
16196
+ }) : function(o, v) {
16197
+ o["default"] = v;
16198
+ });
16199
+ var __importStar = exports2 && exports2.__importStar || function(mod) {
16200
+ if (mod && mod.__esModule) return mod;
16201
+ var result = {};
16202
+ if (mod != null) {
16203
+ for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
16204
+ }
16205
+ __setModuleDefault(result, mod);
16206
+ return result;
16207
+ };
16208
+ var __exportStar = exports2 && exports2.__exportStar || function(m, exports3) {
16209
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports3, p)) __createBinding(exports3, m, p);
16210
+ };
16211
+ Object.defineProperty(exports2, "__esModule", { value: true });
16212
+ exports2.z = void 0;
16213
+ var z = __importStar(require_external());
16214
+ exports2.z = z;
16215
+ __exportStar(require_external(), exports2);
16216
+ exports2.default = z;
16217
+ }
16218
+ });
16219
+
16220
+ // ../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@3.25.76/node_modules/zod-to-json-schema/dist/cjs/parsers/any.js
16221
+ var require_any = __commonJS({
16222
+ "../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@3.25.76/node_modules/zod-to-json-schema/dist/cjs/parsers/any.js"(exports2) {
16223
+ "use strict";
16224
+ Object.defineProperty(exports2, "__esModule", { value: true });
16225
+ exports2.parseAnyDef = void 0;
16226
+ var getRelativePath_js_1 = require_getRelativePath();
16227
+ function parseAnyDef(refs) {
16228
+ if (refs.target !== "openAi") {
16229
+ return {};
16230
+ }
16231
+ const anyDefinitionPath = [
16232
+ ...refs.basePath,
16233
+ refs.definitionPath,
16234
+ refs.openAiAnyTypeName
16235
+ ];
16236
+ refs.flags.hasReferencedOpenAiAnyType = true;
16237
+ return {
16238
+ $ref: refs.$refStrategy === "relative" ? (0, getRelativePath_js_1.getRelativePath)(anyDefinitionPath, refs.currentPath) : anyDefinitionPath.join("/")
16239
+ };
16240
+ }
16241
+ exports2.parseAnyDef = parseAnyDef;
16242
+ }
16243
+ });
16244
+
16245
+ // ../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@3.25.76/node_modules/zod-to-json-schema/dist/cjs/parsers/array.js
16246
+ var require_array = __commonJS({
16247
+ "../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@3.25.76/node_modules/zod-to-json-schema/dist/cjs/parsers/array.js"(exports2) {
16248
+ "use strict";
16249
+ Object.defineProperty(exports2, "__esModule", { value: true });
16250
+ exports2.parseArrayDef = void 0;
16251
+ var v3_1 = require_v3();
16252
+ var errorMessages_js_1 = require_errorMessages();
16253
+ var parseDef_js_1 = require_parseDef();
16254
+ function parseArrayDef(def, refs) {
16255
+ const res = {
16256
+ type: "array"
16257
+ };
16258
+ if (def.type?._def && def.type?._def?.typeName !== v3_1.ZodFirstPartyTypeKind.ZodAny) {
16259
+ res.items = (0, parseDef_js_1.parseDef)(def.type._def, {
16260
+ ...refs,
16261
+ currentPath: [...refs.currentPath, "items"]
16262
+ });
16263
+ }
16264
+ if (def.minLength) {
16265
+ (0, errorMessages_js_1.setResponseValueAndErrors)(res, "minItems", def.minLength.value, def.minLength.message, refs);
16266
+ }
16267
+ if (def.maxLength) {
16268
+ (0, errorMessages_js_1.setResponseValueAndErrors)(res, "maxItems", def.maxLength.value, def.maxLength.message, refs);
16269
+ }
16270
+ if (def.exactLength) {
16271
+ (0, errorMessages_js_1.setResponseValueAndErrors)(res, "minItems", def.exactLength.value, def.exactLength.message, refs);
16272
+ (0, errorMessages_js_1.setResponseValueAndErrors)(res, "maxItems", def.exactLength.value, def.exactLength.message, refs);
16273
+ }
16274
+ return res;
16275
+ }
16276
+ exports2.parseArrayDef = parseArrayDef;
16277
+ }
16278
+ });
16279
+
16280
+ // ../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@3.25.76/node_modules/zod-to-json-schema/dist/cjs/parsers/bigint.js
16281
+ var require_bigint = __commonJS({
16282
+ "../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@3.25.76/node_modules/zod-to-json-schema/dist/cjs/parsers/bigint.js"(exports2) {
16283
+ "use strict";
16284
+ Object.defineProperty(exports2, "__esModule", { value: true });
16285
+ exports2.parseBigintDef = void 0;
16286
+ var errorMessages_js_1 = require_errorMessages();
16287
+ function parseBigintDef(def, refs) {
16288
+ const res = {
16289
+ type: "integer",
16290
+ format: "int64"
16291
+ };
16292
+ if (!def.checks)
16293
+ return res;
16294
+ for (const check of def.checks) {
16295
+ switch (check.kind) {
16296
+ case "min":
16297
+ if (refs.target === "jsonSchema7") {
16298
+ if (check.inclusive) {
16299
+ (0, errorMessages_js_1.setResponseValueAndErrors)(res, "minimum", check.value, check.message, refs);
16300
+ } else {
16301
+ (0, errorMessages_js_1.setResponseValueAndErrors)(res, "exclusiveMinimum", check.value, check.message, refs);
16302
+ }
16303
+ } else {
16304
+ if (!check.inclusive) {
16305
+ res.exclusiveMinimum = true;
16306
+ }
16307
+ (0, errorMessages_js_1.setResponseValueAndErrors)(res, "minimum", check.value, check.message, refs);
16308
+ }
16309
+ break;
16310
+ case "max":
16311
+ if (refs.target === "jsonSchema7") {
16312
+ if (check.inclusive) {
16313
+ (0, errorMessages_js_1.setResponseValueAndErrors)(res, "maximum", check.value, check.message, refs);
16314
+ } else {
16315
+ (0, errorMessages_js_1.setResponseValueAndErrors)(res, "exclusiveMaximum", check.value, check.message, refs);
16316
+ }
16317
+ } else {
16318
+ if (!check.inclusive) {
16319
+ res.exclusiveMaximum = true;
16320
+ }
16321
+ (0, errorMessages_js_1.setResponseValueAndErrors)(res, "maximum", check.value, check.message, refs);
16322
+ }
16323
+ break;
16324
+ case "multipleOf":
16325
+ (0, errorMessages_js_1.setResponseValueAndErrors)(res, "multipleOf", check.value, check.message, refs);
16326
+ break;
16327
+ }
16328
+ }
16329
+ return res;
16330
+ }
16331
+ exports2.parseBigintDef = parseBigintDef;
16332
+ }
16333
+ });
16334
+
16335
+ // ../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@3.25.76/node_modules/zod-to-json-schema/dist/cjs/parsers/boolean.js
16336
+ var require_boolean = __commonJS({
16337
+ "../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@3.25.76/node_modules/zod-to-json-schema/dist/cjs/parsers/boolean.js"(exports2) {
16338
+ "use strict";
16339
+ Object.defineProperty(exports2, "__esModule", { value: true });
16340
+ exports2.parseBooleanDef = void 0;
16341
+ function parseBooleanDef() {
16342
+ return {
16343
+ type: "boolean"
16344
+ };
16345
+ }
16346
+ exports2.parseBooleanDef = parseBooleanDef;
16347
+ }
16348
+ });
16349
+
16350
+ // ../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@3.25.76/node_modules/zod-to-json-schema/dist/cjs/parsers/branded.js
16351
+ var require_branded = __commonJS({
16352
+ "../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@3.25.76/node_modules/zod-to-json-schema/dist/cjs/parsers/branded.js"(exports2) {
16353
+ "use strict";
16354
+ Object.defineProperty(exports2, "__esModule", { value: true });
16355
+ exports2.parseBrandedDef = void 0;
16356
+ var parseDef_js_1 = require_parseDef();
16357
+ function parseBrandedDef(_def, refs) {
16358
+ return (0, parseDef_js_1.parseDef)(_def.type._def, refs);
16359
+ }
16360
+ exports2.parseBrandedDef = parseBrandedDef;
16361
+ }
16362
+ });
16363
+
16364
+ // ../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@3.25.76/node_modules/zod-to-json-schema/dist/cjs/parsers/catch.js
16365
+ var require_catch = __commonJS({
16366
+ "../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@3.25.76/node_modules/zod-to-json-schema/dist/cjs/parsers/catch.js"(exports2) {
16367
+ "use strict";
16368
+ Object.defineProperty(exports2, "__esModule", { value: true });
16369
+ exports2.parseCatchDef = void 0;
16370
+ var parseDef_js_1 = require_parseDef();
16371
+ var parseCatchDef = (def, refs) => {
16372
+ return (0, parseDef_js_1.parseDef)(def.innerType._def, refs);
16373
+ };
16374
+ exports2.parseCatchDef = parseCatchDef;
16375
+ }
16376
+ });
16377
+
16378
+ // ../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@3.25.76/node_modules/zod-to-json-schema/dist/cjs/parsers/date.js
16379
+ var require_date = __commonJS({
16380
+ "../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@3.25.76/node_modules/zod-to-json-schema/dist/cjs/parsers/date.js"(exports2) {
16381
+ "use strict";
16382
+ Object.defineProperty(exports2, "__esModule", { value: true });
16383
+ exports2.parseDateDef = void 0;
16384
+ var errorMessages_js_1 = require_errorMessages();
16385
+ function parseDateDef(def, refs, overrideDateStrategy) {
16386
+ const strategy = overrideDateStrategy ?? refs.dateStrategy;
16387
+ if (Array.isArray(strategy)) {
16388
+ return {
16389
+ anyOf: strategy.map((item, i) => parseDateDef(def, refs, item))
16390
+ };
16391
+ }
16392
+ switch (strategy) {
16393
+ case "string":
16394
+ case "format:date-time":
16395
+ return {
16396
+ type: "string",
16397
+ format: "date-time"
16398
+ };
16399
+ case "format:date":
16400
+ return {
16401
+ type: "string",
16402
+ format: "date"
16403
+ };
16404
+ case "integer":
16405
+ return integerDateParser(def, refs);
16406
+ }
16407
+ }
16408
+ exports2.parseDateDef = parseDateDef;
16409
+ var integerDateParser = (def, refs) => {
16410
+ const res = {
16411
+ type: "integer",
16412
+ format: "unix-time"
16413
+ };
16414
+ if (refs.target === "openApi3") {
16415
+ return res;
16416
+ }
16417
+ for (const check of def.checks) {
16418
+ switch (check.kind) {
16419
+ case "min":
16420
+ (0, errorMessages_js_1.setResponseValueAndErrors)(
16421
+ res,
16422
+ "minimum",
16423
+ check.value,
16424
+ // This is in milliseconds
16425
+ check.message,
16426
+ refs
16427
+ );
16428
+ break;
16429
+ case "max":
16430
+ (0, errorMessages_js_1.setResponseValueAndErrors)(
16431
+ res,
16432
+ "maximum",
16433
+ check.value,
16434
+ // This is in milliseconds
16435
+ check.message,
16436
+ refs
16437
+ );
16438
+ break;
16439
+ }
16440
+ }
16441
+ return res;
16442
+ };
16443
+ }
16444
+ });
16445
+
16446
+ // ../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@3.25.76/node_modules/zod-to-json-schema/dist/cjs/parsers/default.js
16447
+ var require_default = __commonJS({
16448
+ "../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@3.25.76/node_modules/zod-to-json-schema/dist/cjs/parsers/default.js"(exports2) {
16449
+ "use strict";
16450
+ Object.defineProperty(exports2, "__esModule", { value: true });
16451
+ exports2.parseDefaultDef = void 0;
16452
+ var parseDef_js_1 = require_parseDef();
16453
+ function parseDefaultDef(_def, refs) {
16454
+ return {
16455
+ ...(0, parseDef_js_1.parseDef)(_def.innerType._def, refs),
16456
+ default: _def.defaultValue()
16457
+ };
16458
+ }
16459
+ exports2.parseDefaultDef = parseDefaultDef;
16460
+ }
16461
+ });
16462
+
16463
+ // ../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@3.25.76/node_modules/zod-to-json-schema/dist/cjs/parsers/effects.js
16464
+ var require_effects = __commonJS({
16465
+ "../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@3.25.76/node_modules/zod-to-json-schema/dist/cjs/parsers/effects.js"(exports2) {
16466
+ "use strict";
16467
+ Object.defineProperty(exports2, "__esModule", { value: true });
16468
+ exports2.parseEffectsDef = void 0;
16469
+ var parseDef_js_1 = require_parseDef();
16470
+ var any_js_1 = require_any();
16471
+ function parseEffectsDef(_def, refs) {
16472
+ return refs.effectStrategy === "input" ? (0, parseDef_js_1.parseDef)(_def.schema._def, refs) : (0, any_js_1.parseAnyDef)(refs);
16473
+ }
16474
+ exports2.parseEffectsDef = parseEffectsDef;
16475
+ }
16476
+ });
16477
+
16478
+ // ../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@3.25.76/node_modules/zod-to-json-schema/dist/cjs/parsers/enum.js
16479
+ var require_enum = __commonJS({
16480
+ "../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@3.25.76/node_modules/zod-to-json-schema/dist/cjs/parsers/enum.js"(exports2) {
16481
+ "use strict";
16482
+ Object.defineProperty(exports2, "__esModule", { value: true });
16483
+ exports2.parseEnumDef = void 0;
16484
+ function parseEnumDef(def) {
16485
+ return {
16486
+ type: "string",
16487
+ enum: Array.from(def.values)
16488
+ };
16489
+ }
16490
+ exports2.parseEnumDef = parseEnumDef;
16491
+ }
16492
+ });
16493
+
16494
+ // ../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@3.25.76/node_modules/zod-to-json-schema/dist/cjs/parsers/intersection.js
16495
+ var require_intersection = __commonJS({
16496
+ "../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@3.25.76/node_modules/zod-to-json-schema/dist/cjs/parsers/intersection.js"(exports2) {
16497
+ "use strict";
16498
+ Object.defineProperty(exports2, "__esModule", { value: true });
16499
+ exports2.parseIntersectionDef = void 0;
16500
+ var parseDef_js_1 = require_parseDef();
16501
+ var isJsonSchema7AllOfType = (type) => {
16502
+ if ("type" in type && type.type === "string")
16503
+ return false;
16504
+ return "allOf" in type;
16505
+ };
16506
+ function parseIntersectionDef(def, refs) {
16507
+ const allOf = [
16508
+ (0, parseDef_js_1.parseDef)(def.left._def, {
16509
+ ...refs,
16510
+ currentPath: [...refs.currentPath, "allOf", "0"]
16511
+ }),
16512
+ (0, parseDef_js_1.parseDef)(def.right._def, {
16513
+ ...refs,
16514
+ currentPath: [...refs.currentPath, "allOf", "1"]
16515
+ })
16516
+ ].filter((x) => !!x);
16517
+ let unevaluatedProperties = refs.target === "jsonSchema2019-09" ? { unevaluatedProperties: false } : void 0;
16518
+ const mergedAllOf = [];
16519
+ allOf.forEach((schema) => {
16520
+ if (isJsonSchema7AllOfType(schema)) {
16521
+ mergedAllOf.push(...schema.allOf);
16522
+ if (schema.unevaluatedProperties === void 0) {
16523
+ unevaluatedProperties = void 0;
16524
+ }
16525
+ } else {
16526
+ let nestedSchema = schema;
16527
+ if ("additionalProperties" in schema && schema.additionalProperties === false) {
16528
+ const { additionalProperties, ...rest } = schema;
16529
+ nestedSchema = rest;
16530
+ } else {
16531
+ unevaluatedProperties = void 0;
16532
+ }
16533
+ mergedAllOf.push(nestedSchema);
16534
+ }
16535
+ });
16536
+ return mergedAllOf.length ? {
16537
+ allOf: mergedAllOf,
16538
+ ...unevaluatedProperties
16539
+ } : void 0;
16540
+ }
16541
+ exports2.parseIntersectionDef = parseIntersectionDef;
16542
+ }
16543
+ });
16544
+
16545
+ // ../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@3.25.76/node_modules/zod-to-json-schema/dist/cjs/parsers/literal.js
16546
+ var require_literal = __commonJS({
16547
+ "../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@3.25.76/node_modules/zod-to-json-schema/dist/cjs/parsers/literal.js"(exports2) {
16548
+ "use strict";
16549
+ Object.defineProperty(exports2, "__esModule", { value: true });
16550
+ exports2.parseLiteralDef = void 0;
16551
+ function parseLiteralDef(def, refs) {
16552
+ const parsedType = typeof def.value;
16553
+ if (parsedType !== "bigint" && parsedType !== "number" && parsedType !== "boolean" && parsedType !== "string") {
16554
+ return {
16555
+ type: Array.isArray(def.value) ? "array" : "object"
16556
+ };
16557
+ }
16558
+ if (refs.target === "openApi3") {
16559
+ return {
16560
+ type: parsedType === "bigint" ? "integer" : parsedType,
16561
+ enum: [def.value]
16562
+ };
16563
+ }
16564
+ return {
16565
+ type: parsedType === "bigint" ? "integer" : parsedType,
16566
+ const: def.value
16567
+ };
16568
+ }
16569
+ exports2.parseLiteralDef = parseLiteralDef;
16570
+ }
16571
+ });
16572
+
16573
+ // ../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@3.25.76/node_modules/zod-to-json-schema/dist/cjs/parsers/string.js
16574
+ var require_string2 = __commonJS({
16575
+ "../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@3.25.76/node_modules/zod-to-json-schema/dist/cjs/parsers/string.js"(exports2) {
16576
+ "use strict";
16577
+ Object.defineProperty(exports2, "__esModule", { value: true });
16578
+ exports2.parseStringDef = exports2.zodPatterns = void 0;
16579
+ var errorMessages_js_1 = require_errorMessages();
16580
+ var emojiRegex = void 0;
16581
+ exports2.zodPatterns = {
16582
+ /**
16583
+ * `c` was changed to `[cC]` to replicate /i flag
16584
+ */
16585
+ cuid: /^[cC][^\s-]{8,}$/,
16586
+ cuid2: /^[0-9a-z]+$/,
16587
+ ulid: /^[0-9A-HJKMNP-TV-Z]{26}$/,
16588
+ /**
16589
+ * `a-z` was added to replicate /i flag
16590
+ */
16591
+ email: /^(?!\.)(?!.*\.\.)([a-zA-Z0-9_'+\-\.]*)[a-zA-Z0-9_+-]@([a-zA-Z0-9][a-zA-Z0-9\-]*\.)+[a-zA-Z]{2,}$/,
16592
+ /**
16593
+ * Constructed a valid Unicode RegExp
16594
+ *
16595
+ * Lazily instantiate since this type of regex isn't supported
16596
+ * in all envs (e.g. React Native).
16597
+ *
16598
+ * See:
16599
+ * https://github.com/colinhacks/zod/issues/2433
16600
+ * Fix in Zod:
16601
+ * https://github.com/colinhacks/zod/commit/9340fd51e48576a75adc919bff65dbc4a5d4c99b
16602
+ */
16603
+ emoji: () => {
16604
+ if (emojiRegex === void 0) {
16605
+ emojiRegex = RegExp("^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$", "u");
16606
+ }
16607
+ return emojiRegex;
16608
+ },
16609
+ /**
16610
+ * Unused
16611
+ */
16612
+ uuid: /^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/,
16613
+ /**
16614
+ * Unused
16615
+ */
16616
+ ipv4: /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,
16617
+ ipv4Cidr: /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/(3[0-2]|[12]?[0-9])$/,
16618
+ /**
16619
+ * Unused
16620
+ */
16621
+ ipv6: /^(([a-f0-9]{1,4}:){7}|::([a-f0-9]{1,4}:){0,6}|([a-f0-9]{1,4}:){1}:([a-f0-9]{1,4}:){0,5}|([a-f0-9]{1,4}:){2}:([a-f0-9]{1,4}:){0,4}|([a-f0-9]{1,4}:){3}:([a-f0-9]{1,4}:){0,3}|([a-f0-9]{1,4}:){4}:([a-f0-9]{1,4}:){0,2}|([a-f0-9]{1,4}:){5}:([a-f0-9]{1,4}:){0,1})([a-f0-9]{1,4}|(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2})))$/,
16622
+ ipv6Cidr: /^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,
16623
+ base64: /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,
16624
+ base64url: /^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,
16625
+ nanoid: /^[a-zA-Z0-9_-]{21}$/,
16626
+ jwt: /^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/
16627
+ };
16628
+ function parseStringDef(def, refs) {
16629
+ const res = {
16630
+ type: "string"
16631
+ };
16632
+ if (def.checks) {
16633
+ for (const check of def.checks) {
16634
+ switch (check.kind) {
16635
+ case "min":
16636
+ (0, errorMessages_js_1.setResponseValueAndErrors)(res, "minLength", typeof res.minLength === "number" ? Math.max(res.minLength, check.value) : check.value, check.message, refs);
16637
+ break;
16638
+ case "max":
16639
+ (0, errorMessages_js_1.setResponseValueAndErrors)(res, "maxLength", typeof res.maxLength === "number" ? Math.min(res.maxLength, check.value) : check.value, check.message, refs);
16640
+ break;
16641
+ case "email":
16642
+ switch (refs.emailStrategy) {
16643
+ case "format:email":
16644
+ addFormat(res, "email", check.message, refs);
16645
+ break;
16646
+ case "format:idn-email":
16647
+ addFormat(res, "idn-email", check.message, refs);
16648
+ break;
16649
+ case "pattern:zod":
16650
+ addPattern(res, exports2.zodPatterns.email, check.message, refs);
16651
+ break;
16652
+ }
16653
+ break;
16654
+ case "url":
16655
+ addFormat(res, "uri", check.message, refs);
16656
+ break;
16657
+ case "uuid":
16658
+ addFormat(res, "uuid", check.message, refs);
16659
+ break;
16660
+ case "regex":
16661
+ addPattern(res, check.regex, check.message, refs);
16662
+ break;
16663
+ case "cuid":
16664
+ addPattern(res, exports2.zodPatterns.cuid, check.message, refs);
16665
+ break;
16666
+ case "cuid2":
16667
+ addPattern(res, exports2.zodPatterns.cuid2, check.message, refs);
16668
+ break;
16669
+ case "startsWith":
16670
+ addPattern(res, RegExp(`^${escapeLiteralCheckValue(check.value, refs)}`), check.message, refs);
16671
+ break;
16672
+ case "endsWith":
16673
+ addPattern(res, RegExp(`${escapeLiteralCheckValue(check.value, refs)}$`), check.message, refs);
16674
+ break;
16675
+ case "datetime":
16676
+ addFormat(res, "date-time", check.message, refs);
16677
+ break;
16678
+ case "date":
16679
+ addFormat(res, "date", check.message, refs);
16680
+ break;
16681
+ case "time":
16682
+ addFormat(res, "time", check.message, refs);
16683
+ break;
16684
+ case "duration":
16685
+ addFormat(res, "duration", check.message, refs);
16686
+ break;
16687
+ case "length":
16688
+ (0, errorMessages_js_1.setResponseValueAndErrors)(res, "minLength", typeof res.minLength === "number" ? Math.max(res.minLength, check.value) : check.value, check.message, refs);
16689
+ (0, errorMessages_js_1.setResponseValueAndErrors)(res, "maxLength", typeof res.maxLength === "number" ? Math.min(res.maxLength, check.value) : check.value, check.message, refs);
16690
+ break;
16691
+ case "includes": {
16692
+ addPattern(res, RegExp(escapeLiteralCheckValue(check.value, refs)), check.message, refs);
16693
+ break;
16694
+ }
16695
+ case "ip": {
16696
+ if (check.version !== "v6") {
16697
+ addFormat(res, "ipv4", check.message, refs);
16698
+ }
16699
+ if (check.version !== "v4") {
16700
+ addFormat(res, "ipv6", check.message, refs);
16701
+ }
16702
+ break;
16703
+ }
16704
+ case "base64url":
16705
+ addPattern(res, exports2.zodPatterns.base64url, check.message, refs);
16706
+ break;
16707
+ case "jwt":
16708
+ addPattern(res, exports2.zodPatterns.jwt, check.message, refs);
16709
+ break;
16710
+ case "cidr": {
16711
+ if (check.version !== "v6") {
16712
+ addPattern(res, exports2.zodPatterns.ipv4Cidr, check.message, refs);
16713
+ }
16714
+ if (check.version !== "v4") {
16715
+ addPattern(res, exports2.zodPatterns.ipv6Cidr, check.message, refs);
16716
+ }
16717
+ break;
16718
+ }
16719
+ case "emoji":
16720
+ addPattern(res, exports2.zodPatterns.emoji(), check.message, refs);
16721
+ break;
16722
+ case "ulid": {
16723
+ addPattern(res, exports2.zodPatterns.ulid, check.message, refs);
16724
+ break;
16725
+ }
16726
+ case "base64": {
16727
+ switch (refs.base64Strategy) {
16728
+ case "format:binary": {
16729
+ addFormat(res, "binary", check.message, refs);
16730
+ break;
16731
+ }
16732
+ case "contentEncoding:base64": {
16733
+ (0, errorMessages_js_1.setResponseValueAndErrors)(res, "contentEncoding", "base64", check.message, refs);
16734
+ break;
16735
+ }
16736
+ case "pattern:zod": {
16737
+ addPattern(res, exports2.zodPatterns.base64, check.message, refs);
16738
+ break;
16739
+ }
16740
+ }
16741
+ break;
16742
+ }
16743
+ case "nanoid": {
16744
+ addPattern(res, exports2.zodPatterns.nanoid, check.message, refs);
16745
+ }
16746
+ case "toLowerCase":
16747
+ case "toUpperCase":
16748
+ case "trim":
16749
+ break;
16750
+ default:
16751
+ /* @__PURE__ */ ((_) => {
16752
+ })(check);
16753
+ }
16754
+ }
16755
+ }
16756
+ return res;
16757
+ }
16758
+ exports2.parseStringDef = parseStringDef;
16759
+ function escapeLiteralCheckValue(literal, refs) {
16760
+ return refs.patternStrategy === "escape" ? escapeNonAlphaNumeric(literal) : literal;
16761
+ }
16762
+ var ALPHA_NUMERIC = new Set("ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvxyz0123456789");
16763
+ function escapeNonAlphaNumeric(source) {
16764
+ let result = "";
16765
+ for (let i = 0; i < source.length; i++) {
16766
+ if (!ALPHA_NUMERIC.has(source[i])) {
16767
+ result += "\\";
16768
+ }
16769
+ result += source[i];
16770
+ }
16771
+ return result;
16772
+ }
16773
+ function addFormat(schema, value, message, refs) {
16774
+ if (schema.format || schema.anyOf?.some((x) => x.format)) {
16775
+ if (!schema.anyOf) {
16776
+ schema.anyOf = [];
16777
+ }
16778
+ if (schema.format) {
16779
+ schema.anyOf.push({
16780
+ format: schema.format,
16781
+ ...schema.errorMessage && refs.errorMessages && {
16782
+ errorMessage: { format: schema.errorMessage.format }
16783
+ }
16784
+ });
16785
+ delete schema.format;
16786
+ if (schema.errorMessage) {
16787
+ delete schema.errorMessage.format;
16788
+ if (Object.keys(schema.errorMessage).length === 0) {
16789
+ delete schema.errorMessage;
16790
+ }
16791
+ }
16792
+ }
16793
+ schema.anyOf.push({
16794
+ format: value,
16795
+ ...message && refs.errorMessages && { errorMessage: { format: message } }
16796
+ });
16797
+ } else {
16798
+ (0, errorMessages_js_1.setResponseValueAndErrors)(schema, "format", value, message, refs);
16799
+ }
16800
+ }
16801
+ function addPattern(schema, regex, message, refs) {
16802
+ if (schema.pattern || schema.allOf?.some((x) => x.pattern)) {
16803
+ if (!schema.allOf) {
16804
+ schema.allOf = [];
16805
+ }
16806
+ if (schema.pattern) {
16807
+ schema.allOf.push({
16808
+ pattern: schema.pattern,
16809
+ ...schema.errorMessage && refs.errorMessages && {
16810
+ errorMessage: { pattern: schema.errorMessage.pattern }
16811
+ }
16812
+ });
16813
+ delete schema.pattern;
16814
+ if (schema.errorMessage) {
16815
+ delete schema.errorMessage.pattern;
16816
+ if (Object.keys(schema.errorMessage).length === 0) {
16817
+ delete schema.errorMessage;
16818
+ }
16819
+ }
16820
+ }
16821
+ schema.allOf.push({
16822
+ pattern: stringifyRegExpWithFlags(regex, refs),
16823
+ ...message && refs.errorMessages && { errorMessage: { pattern: message } }
16824
+ });
16825
+ } else {
16826
+ (0, errorMessages_js_1.setResponseValueAndErrors)(schema, "pattern", stringifyRegExpWithFlags(regex, refs), message, refs);
16827
+ }
16828
+ }
16829
+ function stringifyRegExpWithFlags(regex, refs) {
16830
+ if (!refs.applyRegexFlags || !regex.flags) {
16831
+ return regex.source;
16832
+ }
16833
+ const flags = {
16834
+ i: regex.flags.includes("i"),
16835
+ m: regex.flags.includes("m"),
16836
+ s: regex.flags.includes("s")
16837
+ // `.` matches newlines
16838
+ };
16839
+ const source = flags.i ? regex.source.toLowerCase() : regex.source;
16840
+ let pattern = "";
16841
+ let isEscaped = false;
16842
+ let inCharGroup = false;
16843
+ let inCharRange = false;
16844
+ for (let i = 0; i < source.length; i++) {
16845
+ if (isEscaped) {
16846
+ pattern += source[i];
16847
+ isEscaped = false;
16848
+ continue;
16849
+ }
16850
+ if (flags.i) {
16851
+ if (inCharGroup) {
16852
+ if (source[i].match(/[a-z]/)) {
16853
+ if (inCharRange) {
16854
+ pattern += source[i];
16855
+ pattern += `${source[i - 2]}-${source[i]}`.toUpperCase();
16856
+ inCharRange = false;
16857
+ } else if (source[i + 1] === "-" && source[i + 2]?.match(/[a-z]/)) {
16858
+ pattern += source[i];
16859
+ inCharRange = true;
16860
+ } else {
16861
+ pattern += `${source[i]}${source[i].toUpperCase()}`;
16862
+ }
16863
+ continue;
16864
+ }
16865
+ } else if (source[i].match(/[a-z]/)) {
16866
+ pattern += `[${source[i]}${source[i].toUpperCase()}]`;
16867
+ continue;
16868
+ }
16869
+ }
16870
+ if (flags.m) {
16871
+ if (source[i] === "^") {
16872
+ pattern += `(^|(?<=[\r
16873
+ ]))`;
16874
+ continue;
16875
+ } else if (source[i] === "$") {
16876
+ pattern += `($|(?=[\r
16877
+ ]))`;
16878
+ continue;
16879
+ }
16880
+ }
16881
+ if (flags.s && source[i] === ".") {
16882
+ pattern += inCharGroup ? `${source[i]}\r
16883
+ ` : `[${source[i]}\r
16884
+ ]`;
16885
+ continue;
16886
+ }
16887
+ pattern += source[i];
16888
+ if (source[i] === "\\") {
16889
+ isEscaped = true;
16890
+ } else if (inCharGroup && source[i] === "]") {
16891
+ inCharGroup = false;
16892
+ } else if (!inCharGroup && source[i] === "[") {
16893
+ inCharGroup = true;
16894
+ }
16895
+ }
16896
+ try {
16897
+ new RegExp(pattern);
16898
+ } catch {
16899
+ console.warn(`Could not convert regex pattern at ${refs.currentPath.join("/")} to a flag-independent form! Falling back to the flag-ignorant source`);
16900
+ return regex.source;
16901
+ }
16902
+ return pattern;
16903
+ }
16904
+ }
16905
+ });
16906
+
16907
+ // ../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@3.25.76/node_modules/zod-to-json-schema/dist/cjs/parsers/record.js
16908
+ var require_record = __commonJS({
16909
+ "../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@3.25.76/node_modules/zod-to-json-schema/dist/cjs/parsers/record.js"(exports2) {
16910
+ "use strict";
16911
+ Object.defineProperty(exports2, "__esModule", { value: true });
16912
+ exports2.parseRecordDef = void 0;
16913
+ var v3_1 = require_v3();
16914
+ var parseDef_js_1 = require_parseDef();
16915
+ var string_js_1 = require_string2();
16916
+ var branded_js_1 = require_branded();
16917
+ var any_js_1 = require_any();
16918
+ function parseRecordDef(def, refs) {
16919
+ if (refs.target === "openAi") {
16920
+ console.warn("Warning: OpenAI may not support records in schemas! Try an array of key-value pairs instead.");
16921
+ }
16922
+ if (refs.target === "openApi3" && def.keyType?._def.typeName === v3_1.ZodFirstPartyTypeKind.ZodEnum) {
16923
+ return {
16924
+ type: "object",
16925
+ required: def.keyType._def.values,
16926
+ properties: def.keyType._def.values.reduce((acc, key) => ({
16927
+ ...acc,
16928
+ [key]: (0, parseDef_js_1.parseDef)(def.valueType._def, {
16929
+ ...refs,
16930
+ currentPath: [...refs.currentPath, "properties", key]
16931
+ }) ?? (0, any_js_1.parseAnyDef)(refs)
16932
+ }), {}),
16933
+ additionalProperties: refs.rejectedAdditionalProperties
16934
+ };
16935
+ }
16936
+ const schema = {
16937
+ type: "object",
16938
+ additionalProperties: (0, parseDef_js_1.parseDef)(def.valueType._def, {
16939
+ ...refs,
16940
+ currentPath: [...refs.currentPath, "additionalProperties"]
16941
+ }) ?? refs.allowedAdditionalProperties
16942
+ };
16943
+ if (refs.target === "openApi3") {
16944
+ return schema;
16945
+ }
16946
+ if (def.keyType?._def.typeName === v3_1.ZodFirstPartyTypeKind.ZodString && def.keyType._def.checks?.length) {
16947
+ const { type, ...keyType } = (0, string_js_1.parseStringDef)(def.keyType._def, refs);
16948
+ return {
16949
+ ...schema,
16950
+ propertyNames: keyType
16951
+ };
16952
+ } else if (def.keyType?._def.typeName === v3_1.ZodFirstPartyTypeKind.ZodEnum) {
16953
+ return {
16954
+ ...schema,
16955
+ propertyNames: {
16956
+ enum: def.keyType._def.values
16957
+ }
16958
+ };
16959
+ } else if (def.keyType?._def.typeName === v3_1.ZodFirstPartyTypeKind.ZodBranded && def.keyType._def.type._def.typeName === v3_1.ZodFirstPartyTypeKind.ZodString && def.keyType._def.type._def.checks?.length) {
16960
+ const { type, ...keyType } = (0, branded_js_1.parseBrandedDef)(def.keyType._def, refs);
16961
+ return {
16962
+ ...schema,
16963
+ propertyNames: keyType
16964
+ };
16965
+ }
16966
+ return schema;
16967
+ }
16968
+ exports2.parseRecordDef = parseRecordDef;
16969
+ }
16970
+ });
16971
+
16972
+ // ../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@3.25.76/node_modules/zod-to-json-schema/dist/cjs/parsers/map.js
16973
+ var require_map2 = __commonJS({
16974
+ "../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@3.25.76/node_modules/zod-to-json-schema/dist/cjs/parsers/map.js"(exports2) {
16975
+ "use strict";
16976
+ Object.defineProperty(exports2, "__esModule", { value: true });
16977
+ exports2.parseMapDef = void 0;
16978
+ var parseDef_js_1 = require_parseDef();
16979
+ var record_js_1 = require_record();
16980
+ var any_js_1 = require_any();
16981
+ function parseMapDef(def, refs) {
16982
+ if (refs.mapStrategy === "record") {
16983
+ return (0, record_js_1.parseRecordDef)(def, refs);
16984
+ }
16985
+ const keys = (0, parseDef_js_1.parseDef)(def.keyType._def, {
16986
+ ...refs,
16987
+ currentPath: [...refs.currentPath, "items", "items", "0"]
16988
+ }) || (0, any_js_1.parseAnyDef)(refs);
16989
+ const values = (0, parseDef_js_1.parseDef)(def.valueType._def, {
16990
+ ...refs,
16991
+ currentPath: [...refs.currentPath, "items", "items", "1"]
16992
+ }) || (0, any_js_1.parseAnyDef)(refs);
16993
+ return {
16994
+ type: "array",
16995
+ maxItems: 125,
16996
+ items: {
16997
+ type: "array",
16998
+ items: [keys, values],
16999
+ minItems: 2,
17000
+ maxItems: 2
17001
+ }
17002
+ };
17003
+ }
17004
+ exports2.parseMapDef = parseMapDef;
17005
+ }
17006
+ });
17007
+
17008
+ // ../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@3.25.76/node_modules/zod-to-json-schema/dist/cjs/parsers/nativeEnum.js
17009
+ var require_nativeEnum = __commonJS({
17010
+ "../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@3.25.76/node_modules/zod-to-json-schema/dist/cjs/parsers/nativeEnum.js"(exports2) {
17011
+ "use strict";
17012
+ Object.defineProperty(exports2, "__esModule", { value: true });
17013
+ exports2.parseNativeEnumDef = void 0;
17014
+ function parseNativeEnumDef(def) {
17015
+ const object = def.values;
17016
+ const actualKeys = Object.keys(def.values).filter((key) => {
17017
+ return typeof object[object[key]] !== "number";
17018
+ });
17019
+ const actualValues = actualKeys.map((key) => object[key]);
17020
+ const parsedTypes = Array.from(new Set(actualValues.map((values) => typeof values)));
17021
+ return {
17022
+ type: parsedTypes.length === 1 ? parsedTypes[0] === "string" ? "string" : "number" : ["string", "number"],
17023
+ enum: actualValues
17024
+ };
17025
+ }
17026
+ exports2.parseNativeEnumDef = parseNativeEnumDef;
17027
+ }
17028
+ });
17029
+
17030
+ // ../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@3.25.76/node_modules/zod-to-json-schema/dist/cjs/parsers/never.js
17031
+ var require_never = __commonJS({
17032
+ "../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@3.25.76/node_modules/zod-to-json-schema/dist/cjs/parsers/never.js"(exports2) {
17033
+ "use strict";
17034
+ Object.defineProperty(exports2, "__esModule", { value: true });
17035
+ exports2.parseNeverDef = void 0;
17036
+ var any_js_1 = require_any();
17037
+ function parseNeverDef(refs) {
17038
+ return refs.target === "openAi" ? void 0 : {
17039
+ not: (0, any_js_1.parseAnyDef)({
17040
+ ...refs,
17041
+ currentPath: [...refs.currentPath, "not"]
17042
+ })
17043
+ };
17044
+ }
17045
+ exports2.parseNeverDef = parseNeverDef;
17046
+ }
17047
+ });
17048
+
17049
+ // ../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@3.25.76/node_modules/zod-to-json-schema/dist/cjs/parsers/null.js
17050
+ var require_null2 = __commonJS({
17051
+ "../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@3.25.76/node_modules/zod-to-json-schema/dist/cjs/parsers/null.js"(exports2) {
17052
+ "use strict";
17053
+ Object.defineProperty(exports2, "__esModule", { value: true });
17054
+ exports2.parseNullDef = void 0;
17055
+ function parseNullDef(refs) {
17056
+ return refs.target === "openApi3" ? {
17057
+ enum: ["null"],
17058
+ nullable: true
17059
+ } : {
17060
+ type: "null"
17061
+ };
17062
+ }
17063
+ exports2.parseNullDef = parseNullDef;
17064
+ }
17065
+ });
17066
+
17067
+ // ../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@3.25.76/node_modules/zod-to-json-schema/dist/cjs/parsers/union.js
17068
+ var require_union = __commonJS({
17069
+ "../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@3.25.76/node_modules/zod-to-json-schema/dist/cjs/parsers/union.js"(exports2) {
17070
+ "use strict";
17071
+ Object.defineProperty(exports2, "__esModule", { value: true });
17072
+ exports2.parseUnionDef = exports2.primitiveMappings = void 0;
17073
+ var parseDef_js_1 = require_parseDef();
17074
+ exports2.primitiveMappings = {
17075
+ ZodString: "string",
17076
+ ZodNumber: "number",
17077
+ ZodBigInt: "integer",
17078
+ ZodBoolean: "boolean",
17079
+ ZodNull: "null"
17080
+ };
17081
+ function parseUnionDef(def, refs) {
17082
+ if (refs.target === "openApi3")
17083
+ return asAnyOf(def, refs);
17084
+ const options = def.options instanceof Map ? Array.from(def.options.values()) : def.options;
17085
+ if (options.every((x) => x._def.typeName in exports2.primitiveMappings && (!x._def.checks || !x._def.checks.length))) {
17086
+ const types = options.reduce((types2, x) => {
17087
+ const type = exports2.primitiveMappings[x._def.typeName];
17088
+ return type && !types2.includes(type) ? [...types2, type] : types2;
17089
+ }, []);
17090
+ return {
17091
+ type: types.length > 1 ? types : types[0]
17092
+ };
17093
+ } else if (options.every((x) => x._def.typeName === "ZodLiteral" && !x.description)) {
17094
+ const types = options.reduce((acc, x) => {
17095
+ const type = typeof x._def.value;
17096
+ switch (type) {
17097
+ case "string":
17098
+ case "number":
17099
+ case "boolean":
17100
+ return [...acc, type];
17101
+ case "bigint":
17102
+ return [...acc, "integer"];
17103
+ case "object":
17104
+ if (x._def.value === null)
17105
+ return [...acc, "null"];
17106
+ case "symbol":
17107
+ case "undefined":
17108
+ case "function":
17109
+ default:
17110
+ return acc;
17111
+ }
17112
+ }, []);
17113
+ if (types.length === options.length) {
17114
+ const uniqueTypes = types.filter((x, i, a) => a.indexOf(x) === i);
17115
+ return {
17116
+ type: uniqueTypes.length > 1 ? uniqueTypes : uniqueTypes[0],
17117
+ enum: options.reduce((acc, x) => {
17118
+ return acc.includes(x._def.value) ? acc : [...acc, x._def.value];
17119
+ }, [])
17120
+ };
17121
+ }
17122
+ } else if (options.every((x) => x._def.typeName === "ZodEnum")) {
17123
+ return {
17124
+ type: "string",
17125
+ enum: options.reduce((acc, x) => [
17126
+ ...acc,
17127
+ ...x._def.values.filter((x2) => !acc.includes(x2))
17128
+ ], [])
17129
+ };
17130
+ }
17131
+ return asAnyOf(def, refs);
17132
+ }
17133
+ exports2.parseUnionDef = parseUnionDef;
17134
+ var asAnyOf = (def, refs) => {
17135
+ const anyOf = (def.options instanceof Map ? Array.from(def.options.values()) : def.options).map((x, i) => (0, parseDef_js_1.parseDef)(x._def, {
17136
+ ...refs,
17137
+ currentPath: [...refs.currentPath, "anyOf", `${i}`]
17138
+ })).filter((x) => !!x && (!refs.strictUnions || typeof x === "object" && Object.keys(x).length > 0));
17139
+ return anyOf.length ? { anyOf } : void 0;
17140
+ };
17141
+ }
17142
+ });
17143
+
17144
+ // ../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@3.25.76/node_modules/zod-to-json-schema/dist/cjs/parsers/nullable.js
17145
+ var require_nullable = __commonJS({
17146
+ "../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@3.25.76/node_modules/zod-to-json-schema/dist/cjs/parsers/nullable.js"(exports2) {
17147
+ "use strict";
17148
+ Object.defineProperty(exports2, "__esModule", { value: true });
17149
+ exports2.parseNullableDef = void 0;
17150
+ var parseDef_js_1 = require_parseDef();
17151
+ var union_js_1 = require_union();
17152
+ function parseNullableDef(def, refs) {
17153
+ if (["ZodString", "ZodNumber", "ZodBigInt", "ZodBoolean", "ZodNull"].includes(def.innerType._def.typeName) && (!def.innerType._def.checks || !def.innerType._def.checks.length)) {
17154
+ if (refs.target === "openApi3") {
17155
+ return {
17156
+ type: union_js_1.primitiveMappings[def.innerType._def.typeName],
17157
+ nullable: true
17158
+ };
17159
+ }
17160
+ return {
17161
+ type: [
17162
+ union_js_1.primitiveMappings[def.innerType._def.typeName],
17163
+ "null"
17164
+ ]
17165
+ };
17166
+ }
17167
+ if (refs.target === "openApi3") {
17168
+ const base2 = (0, parseDef_js_1.parseDef)(def.innerType._def, {
17169
+ ...refs,
17170
+ currentPath: [...refs.currentPath]
17171
+ });
17172
+ if (base2 && "$ref" in base2)
17173
+ return { allOf: [base2], nullable: true };
17174
+ return base2 && { ...base2, nullable: true };
17175
+ }
17176
+ const base = (0, parseDef_js_1.parseDef)(def.innerType._def, {
17177
+ ...refs,
17178
+ currentPath: [...refs.currentPath, "anyOf", "0"]
17179
+ });
17180
+ return base && { anyOf: [base, { type: "null" }] };
17181
+ }
17182
+ exports2.parseNullableDef = parseNullableDef;
17183
+ }
17184
+ });
17185
+
17186
+ // ../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@3.25.76/node_modules/zod-to-json-schema/dist/cjs/parsers/number.js
17187
+ var require_number = __commonJS({
17188
+ "../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@3.25.76/node_modules/zod-to-json-schema/dist/cjs/parsers/number.js"(exports2) {
17189
+ "use strict";
17190
+ Object.defineProperty(exports2, "__esModule", { value: true });
17191
+ exports2.parseNumberDef = void 0;
17192
+ var errorMessages_js_1 = require_errorMessages();
17193
+ function parseNumberDef(def, refs) {
17194
+ const res = {
17195
+ type: "number"
17196
+ };
17197
+ if (!def.checks)
17198
+ return res;
17199
+ for (const check of def.checks) {
17200
+ switch (check.kind) {
17201
+ case "int":
17202
+ res.type = "integer";
17203
+ (0, errorMessages_js_1.addErrorMessage)(res, "type", check.message, refs);
17204
+ break;
17205
+ case "min":
17206
+ if (refs.target === "jsonSchema7") {
17207
+ if (check.inclusive) {
17208
+ (0, errorMessages_js_1.setResponseValueAndErrors)(res, "minimum", check.value, check.message, refs);
17209
+ } else {
17210
+ (0, errorMessages_js_1.setResponseValueAndErrors)(res, "exclusiveMinimum", check.value, check.message, refs);
17211
+ }
17212
+ } else {
17213
+ if (!check.inclusive) {
17214
+ res.exclusiveMinimum = true;
17215
+ }
17216
+ (0, errorMessages_js_1.setResponseValueAndErrors)(res, "minimum", check.value, check.message, refs);
17217
+ }
17218
+ break;
17219
+ case "max":
17220
+ if (refs.target === "jsonSchema7") {
17221
+ if (check.inclusive) {
17222
+ (0, errorMessages_js_1.setResponseValueAndErrors)(res, "maximum", check.value, check.message, refs);
17223
+ } else {
17224
+ (0, errorMessages_js_1.setResponseValueAndErrors)(res, "exclusiveMaximum", check.value, check.message, refs);
17225
+ }
17226
+ } else {
17227
+ if (!check.inclusive) {
17228
+ res.exclusiveMaximum = true;
17229
+ }
17230
+ (0, errorMessages_js_1.setResponseValueAndErrors)(res, "maximum", check.value, check.message, refs);
17231
+ }
17232
+ break;
17233
+ case "multipleOf":
17234
+ (0, errorMessages_js_1.setResponseValueAndErrors)(res, "multipleOf", check.value, check.message, refs);
17235
+ break;
17236
+ }
17237
+ }
17238
+ return res;
17239
+ }
17240
+ exports2.parseNumberDef = parseNumberDef;
17241
+ }
17242
+ });
17243
+
17244
+ // ../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@3.25.76/node_modules/zod-to-json-schema/dist/cjs/parsers/object.js
17245
+ var require_object = __commonJS({
17246
+ "../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@3.25.76/node_modules/zod-to-json-schema/dist/cjs/parsers/object.js"(exports2) {
17247
+ "use strict";
17248
+ Object.defineProperty(exports2, "__esModule", { value: true });
17249
+ exports2.parseObjectDef = void 0;
17250
+ var parseDef_js_1 = require_parseDef();
17251
+ function parseObjectDef(def, refs) {
17252
+ const forceOptionalIntoNullable = refs.target === "openAi";
17253
+ const result = {
17254
+ type: "object",
17255
+ properties: {}
17256
+ };
17257
+ const required = [];
17258
+ const shape = def.shape();
17259
+ for (const propName in shape) {
17260
+ let propDef = shape[propName];
17261
+ if (propDef === void 0 || propDef._def === void 0) {
17262
+ continue;
17263
+ }
17264
+ let propOptional = safeIsOptional(propDef);
17265
+ if (propOptional && forceOptionalIntoNullable) {
17266
+ if (propDef._def.typeName === "ZodOptional") {
17267
+ propDef = propDef._def.innerType;
17268
+ }
17269
+ if (!propDef.isNullable()) {
17270
+ propDef = propDef.nullable();
17271
+ }
17272
+ propOptional = false;
17273
+ }
17274
+ const parsedDef = (0, parseDef_js_1.parseDef)(propDef._def, {
17275
+ ...refs,
17276
+ currentPath: [...refs.currentPath, "properties", propName],
17277
+ propertyPath: [...refs.currentPath, "properties", propName]
17278
+ });
17279
+ if (parsedDef === void 0) {
17280
+ continue;
17281
+ }
17282
+ result.properties[propName] = parsedDef;
17283
+ if (!propOptional) {
17284
+ required.push(propName);
17285
+ }
17286
+ }
17287
+ if (required.length) {
17288
+ result.required = required;
17289
+ }
17290
+ const additionalProperties = decideAdditionalProperties(def, refs);
17291
+ if (additionalProperties !== void 0) {
17292
+ result.additionalProperties = additionalProperties;
17293
+ }
17294
+ return result;
17295
+ }
17296
+ exports2.parseObjectDef = parseObjectDef;
17297
+ function decideAdditionalProperties(def, refs) {
17298
+ if (def.catchall._def.typeName !== "ZodNever") {
17299
+ return (0, parseDef_js_1.parseDef)(def.catchall._def, {
17300
+ ...refs,
17301
+ currentPath: [...refs.currentPath, "additionalProperties"]
17302
+ });
17303
+ }
17304
+ switch (def.unknownKeys) {
17305
+ case "passthrough":
17306
+ return refs.allowedAdditionalProperties;
17307
+ case "strict":
17308
+ return refs.rejectedAdditionalProperties;
17309
+ case "strip":
17310
+ return refs.removeAdditionalStrategy === "strict" ? refs.allowedAdditionalProperties : refs.rejectedAdditionalProperties;
17311
+ }
17312
+ }
17313
+ function safeIsOptional(schema) {
17314
+ try {
17315
+ return schema.isOptional();
17316
+ } catch {
17317
+ return true;
17318
+ }
17319
+ }
17320
+ }
17321
+ });
17322
+
17323
+ // ../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@3.25.76/node_modules/zod-to-json-schema/dist/cjs/parsers/optional.js
17324
+ var require_optional = __commonJS({
17325
+ "../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@3.25.76/node_modules/zod-to-json-schema/dist/cjs/parsers/optional.js"(exports2) {
17326
+ "use strict";
17327
+ Object.defineProperty(exports2, "__esModule", { value: true });
17328
+ exports2.parseOptionalDef = void 0;
17329
+ var parseDef_js_1 = require_parseDef();
17330
+ var any_js_1 = require_any();
17331
+ var parseOptionalDef = (def, refs) => {
17332
+ if (refs.currentPath.toString() === refs.propertyPath?.toString()) {
17333
+ return (0, parseDef_js_1.parseDef)(def.innerType._def, refs);
17334
+ }
17335
+ const innerSchema = (0, parseDef_js_1.parseDef)(def.innerType._def, {
17336
+ ...refs,
17337
+ currentPath: [...refs.currentPath, "anyOf", "1"]
17338
+ });
17339
+ return innerSchema ? {
17340
+ anyOf: [
17341
+ {
17342
+ not: (0, any_js_1.parseAnyDef)(refs)
17343
+ },
17344
+ innerSchema
17345
+ ]
17346
+ } : (0, any_js_1.parseAnyDef)(refs);
17347
+ };
17348
+ exports2.parseOptionalDef = parseOptionalDef;
17349
+ }
17350
+ });
17351
+
17352
+ // ../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@3.25.76/node_modules/zod-to-json-schema/dist/cjs/parsers/pipeline.js
17353
+ var require_pipeline = __commonJS({
17354
+ "../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@3.25.76/node_modules/zod-to-json-schema/dist/cjs/parsers/pipeline.js"(exports2) {
17355
+ "use strict";
17356
+ Object.defineProperty(exports2, "__esModule", { value: true });
17357
+ exports2.parsePipelineDef = void 0;
17358
+ var parseDef_js_1 = require_parseDef();
17359
+ var parsePipelineDef = (def, refs) => {
17360
+ if (refs.pipeStrategy === "input") {
17361
+ return (0, parseDef_js_1.parseDef)(def.in._def, refs);
17362
+ } else if (refs.pipeStrategy === "output") {
17363
+ return (0, parseDef_js_1.parseDef)(def.out._def, refs);
17364
+ }
17365
+ const a = (0, parseDef_js_1.parseDef)(def.in._def, {
17366
+ ...refs,
17367
+ currentPath: [...refs.currentPath, "allOf", "0"]
17368
+ });
17369
+ const b = (0, parseDef_js_1.parseDef)(def.out._def, {
17370
+ ...refs,
17371
+ currentPath: [...refs.currentPath, "allOf", a ? "1" : "0"]
17372
+ });
17373
+ return {
17374
+ allOf: [a, b].filter((x) => x !== void 0)
17375
+ };
17376
+ };
17377
+ exports2.parsePipelineDef = parsePipelineDef;
17378
+ }
17379
+ });
17380
+
17381
+ // ../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@3.25.76/node_modules/zod-to-json-schema/dist/cjs/parsers/promise.js
17382
+ var require_promise = __commonJS({
17383
+ "../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@3.25.76/node_modules/zod-to-json-schema/dist/cjs/parsers/promise.js"(exports2) {
17384
+ "use strict";
17385
+ Object.defineProperty(exports2, "__esModule", { value: true });
17386
+ exports2.parsePromiseDef = void 0;
17387
+ var parseDef_js_1 = require_parseDef();
17388
+ function parsePromiseDef(def, refs) {
17389
+ return (0, parseDef_js_1.parseDef)(def.type._def, refs);
17390
+ }
17391
+ exports2.parsePromiseDef = parsePromiseDef;
17392
+ }
17393
+ });
17394
+
17395
+ // ../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@3.25.76/node_modules/zod-to-json-schema/dist/cjs/parsers/set.js
17396
+ var require_set2 = __commonJS({
17397
+ "../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@3.25.76/node_modules/zod-to-json-schema/dist/cjs/parsers/set.js"(exports2) {
17398
+ "use strict";
17399
+ Object.defineProperty(exports2, "__esModule", { value: true });
17400
+ exports2.parseSetDef = void 0;
17401
+ var errorMessages_js_1 = require_errorMessages();
17402
+ var parseDef_js_1 = require_parseDef();
17403
+ function parseSetDef(def, refs) {
17404
+ const items = (0, parseDef_js_1.parseDef)(def.valueType._def, {
17405
+ ...refs,
17406
+ currentPath: [...refs.currentPath, "items"]
17407
+ });
17408
+ const schema = {
17409
+ type: "array",
17410
+ uniqueItems: true,
17411
+ items
17412
+ };
17413
+ if (def.minSize) {
17414
+ (0, errorMessages_js_1.setResponseValueAndErrors)(schema, "minItems", def.minSize.value, def.minSize.message, refs);
17415
+ }
17416
+ if (def.maxSize) {
17417
+ (0, errorMessages_js_1.setResponseValueAndErrors)(schema, "maxItems", def.maxSize.value, def.maxSize.message, refs);
17418
+ }
17419
+ return schema;
17420
+ }
17421
+ exports2.parseSetDef = parseSetDef;
17422
+ }
17423
+ });
17424
+
17425
+ // ../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@3.25.76/node_modules/zod-to-json-schema/dist/cjs/parsers/tuple.js
17426
+ var require_tuple = __commonJS({
17427
+ "../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@3.25.76/node_modules/zod-to-json-schema/dist/cjs/parsers/tuple.js"(exports2) {
17428
+ "use strict";
17429
+ Object.defineProperty(exports2, "__esModule", { value: true });
17430
+ exports2.parseTupleDef = void 0;
17431
+ var parseDef_js_1 = require_parseDef();
17432
+ function parseTupleDef(def, refs) {
17433
+ if (def.rest) {
17434
+ return {
17435
+ type: "array",
17436
+ minItems: def.items.length,
17437
+ items: def.items.map((x, i) => (0, parseDef_js_1.parseDef)(x._def, {
17438
+ ...refs,
17439
+ currentPath: [...refs.currentPath, "items", `${i}`]
17440
+ })).reduce((acc, x) => x === void 0 ? acc : [...acc, x], []),
17441
+ additionalItems: (0, parseDef_js_1.parseDef)(def.rest._def, {
17442
+ ...refs,
17443
+ currentPath: [...refs.currentPath, "additionalItems"]
17444
+ })
17445
+ };
17446
+ } else {
17447
+ return {
17448
+ type: "array",
17449
+ minItems: def.items.length,
17450
+ maxItems: def.items.length,
17451
+ items: def.items.map((x, i) => (0, parseDef_js_1.parseDef)(x._def, {
17452
+ ...refs,
17453
+ currentPath: [...refs.currentPath, "items", `${i}`]
17454
+ })).reduce((acc, x) => x === void 0 ? acc : [...acc, x], [])
17455
+ };
17456
+ }
17457
+ }
17458
+ exports2.parseTupleDef = parseTupleDef;
17459
+ }
17460
+ });
17461
+
17462
+ // ../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@3.25.76/node_modules/zod-to-json-schema/dist/cjs/parsers/undefined.js
17463
+ var require_undefined = __commonJS({
17464
+ "../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@3.25.76/node_modules/zod-to-json-schema/dist/cjs/parsers/undefined.js"(exports2) {
17465
+ "use strict";
17466
+ Object.defineProperty(exports2, "__esModule", { value: true });
17467
+ exports2.parseUndefinedDef = void 0;
17468
+ var any_js_1 = require_any();
17469
+ function parseUndefinedDef(refs) {
17470
+ return {
17471
+ not: (0, any_js_1.parseAnyDef)(refs)
17472
+ };
17473
+ }
17474
+ exports2.parseUndefinedDef = parseUndefinedDef;
17475
+ }
17476
+ });
17477
+
17478
+ // ../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@3.25.76/node_modules/zod-to-json-schema/dist/cjs/parsers/unknown.js
17479
+ var require_unknown = __commonJS({
17480
+ "../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@3.25.76/node_modules/zod-to-json-schema/dist/cjs/parsers/unknown.js"(exports2) {
17481
+ "use strict";
17482
+ Object.defineProperty(exports2, "__esModule", { value: true });
17483
+ exports2.parseUnknownDef = void 0;
17484
+ var any_js_1 = require_any();
17485
+ function parseUnknownDef(refs) {
17486
+ return (0, any_js_1.parseAnyDef)(refs);
17487
+ }
17488
+ exports2.parseUnknownDef = parseUnknownDef;
17489
+ }
17490
+ });
17491
+
17492
+ // ../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@3.25.76/node_modules/zod-to-json-schema/dist/cjs/parsers/readonly.js
17493
+ var require_readonly = __commonJS({
17494
+ "../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@3.25.76/node_modules/zod-to-json-schema/dist/cjs/parsers/readonly.js"(exports2) {
17495
+ "use strict";
17496
+ Object.defineProperty(exports2, "__esModule", { value: true });
17497
+ exports2.parseReadonlyDef = void 0;
17498
+ var parseDef_js_1 = require_parseDef();
17499
+ var parseReadonlyDef = (def, refs) => {
17500
+ return (0, parseDef_js_1.parseDef)(def.innerType._def, refs);
17501
+ };
17502
+ exports2.parseReadonlyDef = parseReadonlyDef;
17503
+ }
17504
+ });
17505
+
17506
+ // ../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@3.25.76/node_modules/zod-to-json-schema/dist/cjs/selectParser.js
17507
+ var require_selectParser = __commonJS({
17508
+ "../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@3.25.76/node_modules/zod-to-json-schema/dist/cjs/selectParser.js"(exports2) {
17509
+ "use strict";
17510
+ Object.defineProperty(exports2, "__esModule", { value: true });
17511
+ exports2.selectParser = void 0;
17512
+ var v3_1 = require_v3();
17513
+ var any_js_1 = require_any();
17514
+ var array_js_1 = require_array();
17515
+ var bigint_js_1 = require_bigint();
17516
+ var boolean_js_1 = require_boolean();
17517
+ var branded_js_1 = require_branded();
17518
+ var catch_js_1 = require_catch();
17519
+ var date_js_1 = require_date();
17520
+ var default_js_1 = require_default();
17521
+ var effects_js_1 = require_effects();
17522
+ var enum_js_1 = require_enum();
17523
+ var intersection_js_1 = require_intersection();
17524
+ var literal_js_1 = require_literal();
17525
+ var map_js_1 = require_map2();
17526
+ var nativeEnum_js_1 = require_nativeEnum();
17527
+ var never_js_1 = require_never();
17528
+ var null_js_1 = require_null2();
17529
+ var nullable_js_1 = require_nullable();
17530
+ var number_js_1 = require_number();
17531
+ var object_js_1 = require_object();
17532
+ var optional_js_1 = require_optional();
17533
+ var pipeline_js_1 = require_pipeline();
17534
+ var promise_js_1 = require_promise();
17535
+ var record_js_1 = require_record();
17536
+ var set_js_1 = require_set2();
17537
+ var string_js_1 = require_string2();
17538
+ var tuple_js_1 = require_tuple();
17539
+ var undefined_js_1 = require_undefined();
17540
+ var union_js_1 = require_union();
17541
+ var unknown_js_1 = require_unknown();
17542
+ var readonly_js_1 = require_readonly();
17543
+ var selectParser = (def, typeName, refs) => {
17544
+ switch (typeName) {
17545
+ case v3_1.ZodFirstPartyTypeKind.ZodString:
17546
+ return (0, string_js_1.parseStringDef)(def, refs);
17547
+ case v3_1.ZodFirstPartyTypeKind.ZodNumber:
17548
+ return (0, number_js_1.parseNumberDef)(def, refs);
17549
+ case v3_1.ZodFirstPartyTypeKind.ZodObject:
17550
+ return (0, object_js_1.parseObjectDef)(def, refs);
17551
+ case v3_1.ZodFirstPartyTypeKind.ZodBigInt:
17552
+ return (0, bigint_js_1.parseBigintDef)(def, refs);
17553
+ case v3_1.ZodFirstPartyTypeKind.ZodBoolean:
17554
+ return (0, boolean_js_1.parseBooleanDef)();
17555
+ case v3_1.ZodFirstPartyTypeKind.ZodDate:
17556
+ return (0, date_js_1.parseDateDef)(def, refs);
17557
+ case v3_1.ZodFirstPartyTypeKind.ZodUndefined:
17558
+ return (0, undefined_js_1.parseUndefinedDef)(refs);
17559
+ case v3_1.ZodFirstPartyTypeKind.ZodNull:
17560
+ return (0, null_js_1.parseNullDef)(refs);
17561
+ case v3_1.ZodFirstPartyTypeKind.ZodArray:
17562
+ return (0, array_js_1.parseArrayDef)(def, refs);
17563
+ case v3_1.ZodFirstPartyTypeKind.ZodUnion:
17564
+ case v3_1.ZodFirstPartyTypeKind.ZodDiscriminatedUnion:
17565
+ return (0, union_js_1.parseUnionDef)(def, refs);
17566
+ case v3_1.ZodFirstPartyTypeKind.ZodIntersection:
17567
+ return (0, intersection_js_1.parseIntersectionDef)(def, refs);
17568
+ case v3_1.ZodFirstPartyTypeKind.ZodTuple:
17569
+ return (0, tuple_js_1.parseTupleDef)(def, refs);
17570
+ case v3_1.ZodFirstPartyTypeKind.ZodRecord:
17571
+ return (0, record_js_1.parseRecordDef)(def, refs);
17572
+ case v3_1.ZodFirstPartyTypeKind.ZodLiteral:
17573
+ return (0, literal_js_1.parseLiteralDef)(def, refs);
17574
+ case v3_1.ZodFirstPartyTypeKind.ZodEnum:
17575
+ return (0, enum_js_1.parseEnumDef)(def);
17576
+ case v3_1.ZodFirstPartyTypeKind.ZodNativeEnum:
17577
+ return (0, nativeEnum_js_1.parseNativeEnumDef)(def);
17578
+ case v3_1.ZodFirstPartyTypeKind.ZodNullable:
17579
+ return (0, nullable_js_1.parseNullableDef)(def, refs);
17580
+ case v3_1.ZodFirstPartyTypeKind.ZodOptional:
17581
+ return (0, optional_js_1.parseOptionalDef)(def, refs);
17582
+ case v3_1.ZodFirstPartyTypeKind.ZodMap:
17583
+ return (0, map_js_1.parseMapDef)(def, refs);
17584
+ case v3_1.ZodFirstPartyTypeKind.ZodSet:
17585
+ return (0, set_js_1.parseSetDef)(def, refs);
17586
+ case v3_1.ZodFirstPartyTypeKind.ZodLazy:
17587
+ return () => def.getter()._def;
17588
+ case v3_1.ZodFirstPartyTypeKind.ZodPromise:
17589
+ return (0, promise_js_1.parsePromiseDef)(def, refs);
17590
+ case v3_1.ZodFirstPartyTypeKind.ZodNaN:
17591
+ case v3_1.ZodFirstPartyTypeKind.ZodNever:
17592
+ return (0, never_js_1.parseNeverDef)(refs);
17593
+ case v3_1.ZodFirstPartyTypeKind.ZodEffects:
17594
+ return (0, effects_js_1.parseEffectsDef)(def, refs);
17595
+ case v3_1.ZodFirstPartyTypeKind.ZodAny:
17596
+ return (0, any_js_1.parseAnyDef)(refs);
17597
+ case v3_1.ZodFirstPartyTypeKind.ZodUnknown:
17598
+ return (0, unknown_js_1.parseUnknownDef)(refs);
17599
+ case v3_1.ZodFirstPartyTypeKind.ZodDefault:
17600
+ return (0, default_js_1.parseDefaultDef)(def, refs);
17601
+ case v3_1.ZodFirstPartyTypeKind.ZodBranded:
17602
+ return (0, branded_js_1.parseBrandedDef)(def, refs);
17603
+ case v3_1.ZodFirstPartyTypeKind.ZodReadonly:
17604
+ return (0, readonly_js_1.parseReadonlyDef)(def, refs);
17605
+ case v3_1.ZodFirstPartyTypeKind.ZodCatch:
17606
+ return (0, catch_js_1.parseCatchDef)(def, refs);
17607
+ case v3_1.ZodFirstPartyTypeKind.ZodPipeline:
17608
+ return (0, pipeline_js_1.parsePipelineDef)(def, refs);
17609
+ case v3_1.ZodFirstPartyTypeKind.ZodFunction:
17610
+ case v3_1.ZodFirstPartyTypeKind.ZodVoid:
17611
+ case v3_1.ZodFirstPartyTypeKind.ZodSymbol:
17612
+ return void 0;
17613
+ default:
17614
+ return /* @__PURE__ */ ((_) => void 0)(typeName);
17615
+ }
17616
+ };
17617
+ exports2.selectParser = selectParser;
17618
+ }
17619
+ });
17620
+
17621
+ // ../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@3.25.76/node_modules/zod-to-json-schema/dist/cjs/parseDef.js
17622
+ var require_parseDef = __commonJS({
17623
+ "../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@3.25.76/node_modules/zod-to-json-schema/dist/cjs/parseDef.js"(exports2) {
17624
+ "use strict";
17625
+ Object.defineProperty(exports2, "__esModule", { value: true });
17626
+ exports2.parseDef = void 0;
17627
+ var Options_js_1 = require_Options();
17628
+ var selectParser_js_1 = require_selectParser();
17629
+ var getRelativePath_js_1 = require_getRelativePath();
17630
+ var any_js_1 = require_any();
17631
+ function parseDef(def, refs, forceResolution = false) {
17632
+ const seenItem = refs.seen.get(def);
17633
+ if (refs.override) {
17634
+ const overrideResult = refs.override?.(def, refs, seenItem, forceResolution);
17635
+ if (overrideResult !== Options_js_1.ignoreOverride) {
17636
+ return overrideResult;
17637
+ }
17638
+ }
17639
+ if (seenItem && !forceResolution) {
17640
+ const seenSchema = get$ref(seenItem, refs);
17641
+ if (seenSchema !== void 0) {
17642
+ return seenSchema;
17643
+ }
17644
+ }
17645
+ const newItem = { def, path: refs.currentPath, jsonSchema: void 0 };
17646
+ refs.seen.set(def, newItem);
17647
+ const jsonSchemaOrGetter = (0, selectParser_js_1.selectParser)(def, def.typeName, refs);
17648
+ const jsonSchema = typeof jsonSchemaOrGetter === "function" ? parseDef(jsonSchemaOrGetter(), refs) : jsonSchemaOrGetter;
17649
+ if (jsonSchema) {
17650
+ addMeta(def, refs, jsonSchema);
17651
+ }
17652
+ if (refs.postProcess) {
17653
+ const postProcessResult = refs.postProcess(jsonSchema, def, refs);
17654
+ newItem.jsonSchema = jsonSchema;
17655
+ return postProcessResult;
17656
+ }
17657
+ newItem.jsonSchema = jsonSchema;
17658
+ return jsonSchema;
17659
+ }
17660
+ exports2.parseDef = parseDef;
17661
+ var get$ref = (item, refs) => {
17662
+ switch (refs.$refStrategy) {
17663
+ case "root":
17664
+ return { $ref: item.path.join("/") };
17665
+ case "relative":
17666
+ return { $ref: (0, getRelativePath_js_1.getRelativePath)(refs.currentPath, item.path) };
17667
+ case "none":
17668
+ case "seen": {
17669
+ if (item.path.length < refs.currentPath.length && item.path.every((value, index) => refs.currentPath[index] === value)) {
17670
+ console.warn(`Recursive reference detected at ${refs.currentPath.join("/")}! Defaulting to any`);
17671
+ return (0, any_js_1.parseAnyDef)(refs);
17672
+ }
17673
+ return refs.$refStrategy === "seen" ? (0, any_js_1.parseAnyDef)(refs) : void 0;
17674
+ }
17675
+ }
17676
+ };
17677
+ var addMeta = (def, refs, jsonSchema) => {
17678
+ if (def.description) {
17679
+ jsonSchema.description = def.description;
17680
+ if (refs.markdownDescription) {
17681
+ jsonSchema.markdownDescription = def.description;
17682
+ }
17683
+ }
17684
+ return jsonSchema;
17685
+ };
17686
+ }
17687
+ });
17688
+
17689
+ // ../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@3.25.76/node_modules/zod-to-json-schema/dist/cjs/parseTypes.js
17690
+ var require_parseTypes = __commonJS({
17691
+ "../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@3.25.76/node_modules/zod-to-json-schema/dist/cjs/parseTypes.js"(exports2) {
17692
+ "use strict";
17693
+ Object.defineProperty(exports2, "__esModule", { value: true });
17694
+ }
17695
+ });
17696
+
17697
+ // ../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@3.25.76/node_modules/zod-to-json-schema/dist/cjs/zodToJsonSchema.js
17698
+ var require_zodToJsonSchema = __commonJS({
17699
+ "../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@3.25.76/node_modules/zod-to-json-schema/dist/cjs/zodToJsonSchema.js"(exports2) {
17700
+ "use strict";
17701
+ Object.defineProperty(exports2, "__esModule", { value: true });
17702
+ exports2.zodToJsonSchema = void 0;
17703
+ var parseDef_js_1 = require_parseDef();
17704
+ var Refs_js_1 = require_Refs();
17705
+ var any_js_1 = require_any();
17706
+ var zodToJsonSchema = (schema, options) => {
17707
+ const refs = (0, Refs_js_1.getRefs)(options);
17708
+ let definitions = typeof options === "object" && options.definitions ? Object.entries(options.definitions).reduce((acc, [name2, schema2]) => ({
17709
+ ...acc,
17710
+ [name2]: (0, parseDef_js_1.parseDef)(schema2._def, {
17711
+ ...refs,
17712
+ currentPath: [...refs.basePath, refs.definitionPath, name2]
17713
+ }, true) ?? (0, any_js_1.parseAnyDef)(refs)
17714
+ }), {}) : void 0;
17715
+ const name = typeof options === "string" ? options : options?.nameStrategy === "title" ? void 0 : options?.name;
17716
+ const main = (0, parseDef_js_1.parseDef)(schema._def, name === void 0 ? refs : {
17717
+ ...refs,
17718
+ currentPath: [...refs.basePath, refs.definitionPath, name]
17719
+ }, false) ?? (0, any_js_1.parseAnyDef)(refs);
17720
+ const title = typeof options === "object" && options.name !== void 0 && options.nameStrategy === "title" ? options.name : void 0;
17721
+ if (title !== void 0) {
17722
+ main.title = title;
17723
+ }
17724
+ if (refs.flags.hasReferencedOpenAiAnyType) {
17725
+ if (!definitions) {
17726
+ definitions = {};
17727
+ }
17728
+ if (!definitions[refs.openAiAnyTypeName]) {
17729
+ definitions[refs.openAiAnyTypeName] = {
17730
+ // Skipping "object" as no properties can be defined and additionalProperties must be "false"
17731
+ type: ["string", "number", "integer", "boolean", "array", "null"],
17732
+ items: {
17733
+ $ref: refs.$refStrategy === "relative" ? "1" : [
17734
+ ...refs.basePath,
17735
+ refs.definitionPath,
17736
+ refs.openAiAnyTypeName
17737
+ ].join("/")
17738
+ }
17739
+ };
17740
+ }
17741
+ }
17742
+ const combined = name === void 0 ? definitions ? {
17743
+ ...main,
17744
+ [refs.definitionPath]: definitions
17745
+ } : main : {
17746
+ $ref: [
17747
+ ...refs.$refStrategy === "relative" ? [] : refs.basePath,
17748
+ refs.definitionPath,
17749
+ name
17750
+ ].join("/"),
17751
+ [refs.definitionPath]: {
17752
+ ...definitions,
17753
+ [name]: main
17754
+ }
17755
+ };
17756
+ if (refs.target === "jsonSchema7") {
17757
+ combined.$schema = "http://json-schema.org/draft-07/schema#";
17758
+ } else if (refs.target === "jsonSchema2019-09" || refs.target === "openAi") {
17759
+ combined.$schema = "https://json-schema.org/draft/2019-09/schema#";
17760
+ }
17761
+ if (refs.target === "openAi" && ("anyOf" in combined || "oneOf" in combined || "allOf" in combined || "type" in combined && Array.isArray(combined.type))) {
17762
+ console.warn("Warning: OpenAI may not support schemas with unions as roots! Try wrapping it in an object property.");
17763
+ }
17764
+ return combined;
17765
+ };
17766
+ exports2.zodToJsonSchema = zodToJsonSchema;
17767
+ }
17768
+ });
17769
+
17770
+ // ../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@3.25.76/node_modules/zod-to-json-schema/dist/cjs/index.js
17771
+ var require_cjs = __commonJS({
17772
+ "../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@3.25.76/node_modules/zod-to-json-schema/dist/cjs/index.js"(exports2) {
17773
+ "use strict";
17774
+ var __createBinding = exports2 && exports2.__createBinding || (Object.create ? (function(o, m, k, k2) {
17775
+ if (k2 === void 0) k2 = k;
17776
+ var desc = Object.getOwnPropertyDescriptor(m, k);
17777
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
17778
+ desc = { enumerable: true, get: function() {
17779
+ return m[k];
17780
+ } };
17781
+ }
17782
+ Object.defineProperty(o, k2, desc);
17783
+ }) : (function(o, m, k, k2) {
17784
+ if (k2 === void 0) k2 = k;
17785
+ o[k2] = m[k];
17786
+ }));
17787
+ var __exportStar = exports2 && exports2.__exportStar || function(m, exports3) {
17788
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports3, p)) __createBinding(exports3, m, p);
17789
+ };
17790
+ Object.defineProperty(exports2, "__esModule", { value: true });
17791
+ __exportStar(require_Options(), exports2);
17792
+ __exportStar(require_Refs(), exports2);
17793
+ __exportStar(require_errorMessages(), exports2);
17794
+ __exportStar(require_getRelativePath(), exports2);
17795
+ __exportStar(require_parseDef(), exports2);
17796
+ __exportStar(require_parseTypes(), exports2);
17797
+ __exportStar(require_any(), exports2);
17798
+ __exportStar(require_array(), exports2);
17799
+ __exportStar(require_bigint(), exports2);
17800
+ __exportStar(require_boolean(), exports2);
17801
+ __exportStar(require_branded(), exports2);
17802
+ __exportStar(require_catch(), exports2);
17803
+ __exportStar(require_date(), exports2);
17804
+ __exportStar(require_default(), exports2);
17805
+ __exportStar(require_effects(), exports2);
17806
+ __exportStar(require_enum(), exports2);
17807
+ __exportStar(require_intersection(), exports2);
17808
+ __exportStar(require_literal(), exports2);
17809
+ __exportStar(require_map2(), exports2);
17810
+ __exportStar(require_nativeEnum(), exports2);
17811
+ __exportStar(require_never(), exports2);
17812
+ __exportStar(require_null2(), exports2);
17813
+ __exportStar(require_nullable(), exports2);
17814
+ __exportStar(require_number(), exports2);
17815
+ __exportStar(require_object(), exports2);
17816
+ __exportStar(require_optional(), exports2);
17817
+ __exportStar(require_pipeline(), exports2);
17818
+ __exportStar(require_promise(), exports2);
17819
+ __exportStar(require_readonly(), exports2);
17820
+ __exportStar(require_record(), exports2);
17821
+ __exportStar(require_set2(), exports2);
17822
+ __exportStar(require_string2(), exports2);
17823
+ __exportStar(require_tuple(), exports2);
17824
+ __exportStar(require_undefined(), exports2);
17825
+ __exportStar(require_union(), exports2);
17826
+ __exportStar(require_unknown(), exports2);
17827
+ __exportStar(require_selectParser(), exports2);
17828
+ __exportStar(require_zodToJsonSchema(), exports2);
17829
+ var zodToJsonSchema_js_1 = require_zodToJsonSchema();
17830
+ exports2.default = zodToJsonSchema_js_1.zodToJsonSchema;
17831
+ }
17832
+ });
17833
+
17834
+ // ../../packages/loom/dist/errors.js
17835
+ var require_errors3 = __commonJS({
17836
+ "../../packages/loom/dist/errors.js"(exports2) {
17837
+ "use strict";
17838
+ Object.defineProperty(exports2, "__esModule", { value: true });
17839
+ exports2.SeedWorkflowsError = exports2.WorkflowBuilderError = void 0;
17840
+ var WorkflowBuilderError = class extends Error {
17841
+ workflowName;
17842
+ nodeName;
17843
+ constructor(workflowName, nodeName, message) {
17844
+ super(message);
17845
+ this.workflowName = workflowName;
17846
+ this.nodeName = nodeName;
17847
+ this.name = "WorkflowBuilderError";
17848
+ }
17849
+ };
17850
+ exports2.WorkflowBuilderError = WorkflowBuilderError;
17851
+ var SeedWorkflowsError = class extends Error {
17852
+ workflowName;
17853
+ cause;
17854
+ constructor(workflowName, message, cause) {
17855
+ super(message);
17856
+ this.workflowName = workflowName;
17857
+ this.cause = cause;
17858
+ this.name = "SeedWorkflowsError";
15966
17859
  }
15967
- async function dispatchAndSubmit(dispatch, signal, startedAt) {
15968
- const jobId = dispatch.job.id;
15969
- const attendanceId = dispatch.attendanceId;
15970
- const executor = pickExecutor(dispatch.job.jobType, executorsByCapability);
15971
- if (!executor) {
15972
- await closeAttendanceSafely(jobId, attendanceId, "failed", `no executor for jobType "${dispatch.job.jobType}"`, startedAt);
15973
- return;
15974
- }
15975
- let prompt = "";
15976
- let outputSchema = {};
15977
- let outputLabel = "output";
15978
- let providerHints = {};
15979
- let costCapHint = {};
15980
- let artifacts = [];
15981
- if (dispatch.job.jobType === "prompt-execution") {
15982
- try {
15983
- const { renderPromptExecution } = await Promise.resolve().then(() => __importStar(require_prompt_execution_render()));
15984
- const rendered = renderPromptExecution(dispatch.inputs);
15985
- prompt = rendered.prompt;
15986
- outputSchema = rendered.spec.outputSchema;
15987
- outputLabel = rendered.spec.outputLabel;
15988
- providerHints = pickProviderHints(rendered.spec, executor.capability.id);
15989
- costCapHint = pickCostCapHint(rendered.spec);
15990
- artifacts = rendered.artifacts;
15991
- } catch (err) {
15992
- await closeAttendanceSafely(jobId, attendanceId, "failed", `prompt-execution spec parse failed: ${err instanceof Error ? err.message : String(err)}`, startedAt);
15993
- return;
15994
- }
15995
- } else {
15996
- artifacts = dispatch.inputs.map((i) => ({
15997
- label: i.label ?? "",
15998
- payload: i.payload
15999
- }));
16000
- }
16001
- try {
16002
- await opts.observerChain.notify({
16003
- kind: "spend.preflight",
16004
- jobId,
16005
- attendanceId,
16006
- estimate: costCapHint
16007
- }, onObserverError);
16008
- } catch (err) {
16009
- const reason = err instanceof observers_1.SpendCapExceeded ? "refused_over_cap" : `preflight rejected: ${err instanceof Error ? err.message : String(err)}`;
16010
- await closeAttendanceSafely(jobId, attendanceId, "failed", reason, startedAt);
16011
- return;
16012
- }
16013
- let response;
16014
- const dispatchStartedAt = Date.now();
16015
- try {
16016
- await opts.observerChain.notify({
16017
- kind: "executor.dispatch.started",
16018
- jobId,
16019
- attendanceId,
16020
- executor: executor.capability.id,
16021
- rendered: { prompt, outputSchema }
16022
- }, onObserverError);
16023
- response = await executor.dispatch({
16024
- jobId,
16025
- attendanceId,
16026
- jobType: dispatch.job.jobType,
16027
- prompt,
16028
- outputSchema,
16029
- outputLabel,
16030
- providerHints,
16031
- artifacts
16032
- }, signal);
16033
- } catch (err) {
16034
- await closeAttendanceSafely(jobId, attendanceId, "failed", `executor failed: ${err instanceof Error ? err.message : String(err)}`, startedAt);
16035
- return;
17860
+ };
17861
+ exports2.SeedWorkflowsError = SeedWorkflowsError;
17862
+ }
17863
+ });
17864
+
17865
+ // ../../packages/loom/dist/seed/canonicalise.js
17866
+ var require_canonicalise = __commonJS({
17867
+ "../../packages/loom/dist/seed/canonicalise.js"(exports2) {
17868
+ "use strict";
17869
+ var __importDefault = exports2 && exports2.__importDefault || function(mod) {
17870
+ return mod && mod.__esModule ? mod : { "default": mod };
17871
+ };
17872
+ Object.defineProperty(exports2, "__esModule", { value: true });
17873
+ exports2.canonicaliseWorkflow = canonicaliseWorkflow;
17874
+ var node_path_1 = __importDefault(require("node:path"));
17875
+ var node_fs_1 = require("node:fs");
17876
+ var zod_to_json_schema_1 = require_cjs();
17877
+ function toJsonSchema(schema) {
17878
+ const result = zod_to_json_schema_1.zodToJsonSchema(schema, { target: "jsonSchema7", $refStrategy: "none" });
17879
+ return result;
17880
+ }
17881
+ var errors_1 = require_errors3();
17882
+ var resolvers_1 = require_resolvers();
17883
+ var transitions_1 = require_transitions();
17884
+ async function canonicaliseWorkflow(workflow, opts) {
17885
+ const nodes = [];
17886
+ for (const node of workflow.nodes) {
17887
+ nodes.push(await canonicaliseNode(workflow, node, opts));
17888
+ }
17889
+ const transitions = (workflow.transitions ?? (0, transitions_1.synthesiseLinearChain)(workflow.nodes)).map((e) => {
17890
+ const out = {
17891
+ from: e.from,
17892
+ to: e.to,
17893
+ resolverKey: null
17894
+ };
17895
+ if (e.artifacts) {
17896
+ out.artifacts = e.artifacts.map((a) => {
17897
+ const serialised = { label: a.label };
17898
+ if (a.format !== void 0)
17899
+ serialised.format = a.format;
17900
+ if (a.outputSchema !== void 0) {
17901
+ serialised.schema = toJsonSchema(a.outputSchema);
17902
+ }
17903
+ return serialised;
17904
+ });
16036
17905
  }
16037
- await opts.observerChain.notify({
16038
- kind: "executor.dispatch.completed",
16039
- jobId,
16040
- attendanceId,
16041
- executor: executor.capability.id,
16042
- response,
16043
- durationMs: Date.now() - dispatchStartedAt
16044
- }, onObserverError);
16045
- const parsedContent = response.parsed ?? safeJsonParse(response.rawText) ?? { raw: response.rawText };
17906
+ return out;
17907
+ });
17908
+ return {
17909
+ name: workflow.name,
17910
+ description: workflow.description ?? null,
17911
+ ownerOrgId: opts.ownerOrgId,
17912
+ retainPublishedVersions: workflow.retain?.publishedVersions ?? null,
17913
+ ...opts.publish !== void 0 ? { publish: opts.publish } : {},
17914
+ nodes,
17915
+ transitions
17916
+ };
17917
+ }
17918
+ async function canonicaliseNode(workflow, node, opts) {
17919
+ if (node.entryBehavior === "loom.prompt") {
17920
+ const promptOptions = node.promptOptions;
17921
+ if (!promptOptions) {
17922
+ throw new errors_1.WorkflowBuilderError(workflow.name, node.name, "promptNode missing options");
17923
+ }
17924
+ const promptDescriptor = (0, resolvers_1.describeJobPoolRef)(promptOptions.jobPool);
17925
+ if (!promptDescriptor) {
17926
+ throw new errors_1.WorkflowBuilderError(workflow.name, node.name, "jobPool must be a substrate-shipped named resolver, literalJobPool(...), or { id } / { name }");
17927
+ }
17928
+ const templateResolved = node_path_1.default.resolve(workflow.__sourcePath, promptOptions.promptTemplate);
17929
+ let templateText;
16046
17930
  try {
16047
- await opts.jobsClient.createOutput(jobId, { label: outputLabel, content: parsedContent });
16048
- await opts.observerChain.notify({ kind: "output.submitted", jobId, attendanceId, label: outputLabel, content: parsedContent }, onObserverError);
16049
- if (response.usage) {
16050
- await opts.jobsClient.createOutput(jobId, {
16051
- label: "usage",
16052
- content: response.usage
16053
- });
16054
- await opts.observerChain.notify({ kind: "output.submitted", jobId, attendanceId, label: "usage", content: response.usage }, onObserverError);
16055
- }
17931
+ templateText = await node_fs_1.promises.readFile(templateResolved, "utf8");
16056
17932
  } catch (err) {
16057
- await closeAttendanceSafely(jobId, attendanceId, "failed", `output submit failed: ${err instanceof Error ? err.message : String(err)}`, startedAt);
16058
- return;
16059
- }
16060
- await closeAttendanceSafely(jobId, attendanceId, "completed", void 0, startedAt);
17933
+ throw new errors_1.WorkflowBuilderError(workflow.name, node.name, `failed to read prompt template at ${templateResolved}: ${err instanceof Error ? err.message : String(err)}`);
17934
+ }
17935
+ const outputLabel = promptOptions.outputLabel ?? node.name;
17936
+ const config2 = {
17937
+ jobPoolRef: promptDescriptor,
17938
+ promptTemplate: templateText,
17939
+ promptTemplatePath: promptOptions.promptTemplate,
17940
+ outputSchema: toJsonSchema(promptOptions.outputSchema),
17941
+ outputLabel,
17942
+ rendering: promptOptions.rendering,
17943
+ ...promptOptions.maxAttempts !== void 0 ? { maxAttempts: promptOptions.maxAttempts } : {},
17944
+ ...promptOptions.deadline !== void 0 ? { deadlineDuration: promptOptions.deadline } : {}
17945
+ };
17946
+ return { ...envelope(node.name, promptOptions), entryBehavior: "loom.prompt", config: config2 };
17947
+ }
17948
+ if (node.entryBehavior === "http.request") {
17949
+ const httpOptions = node.httpOptions;
17950
+ if (!httpOptions) {
17951
+ throw new errors_1.WorkflowBuilderError(workflow.name, node.name, "httpNode missing options");
17952
+ }
17953
+ const env = opts.env ?? {};
17954
+ const config2 = {
17955
+ endpoint: {
17956
+ method: httpOptions.endpoint.method,
17957
+ url: interpolate(httpOptions.endpoint.url, env)
17958
+ },
17959
+ ...httpOptions.timeout !== void 0 ? { timeout: httpOptions.timeout } : {},
17960
+ ...httpOptions.retryConfig !== void 0 ? { retryConfig: { ...httpOptions.retryConfig } } : {}
17961
+ };
17962
+ return { ...envelope(node.name, httpOptions), entryBehavior: "http.request", config: config2 };
16061
17963
  }
16062
- async function closeAttendanceSafely(jobId, attendanceId, status, reason, startedAt) {
16063
- try {
16064
- await opts.jobsClient.submit(jobId, { status, ...reason !== void 0 ? { reason } : {} });
16065
- } catch (err) {
16066
- logger.error("close attendance failed", {
16067
- jobId,
16068
- error: err instanceof Error ? err.message : String(err)
16069
- });
16070
- }
16071
- await opts.observerChain.notify({
16072
- kind: "attendance.closed",
16073
- jobId,
16074
- attendanceId,
16075
- status,
16076
- ...reason !== void 0 ? { reason } : {},
16077
- totalDurationMs: Date.now() - startedAt
16078
- }, onObserverError);
16079
- }
16080
- function onObserverError(err, observerName, event) {
16081
- logger.warn("observer threw on non-veto event", {
16082
- observerName,
16083
- eventKind: event.kind,
16084
- error: err instanceof Error ? err.message : String(err)
16085
- });
17964
+ const jobsCreateOptions = node.jobsCreateOptions;
17965
+ if (!jobsCreateOptions) {
17966
+ throw new errors_1.WorkflowBuilderError(workflow.name, node.name, "jobsCreateNode missing options");
16086
17967
  }
16087
- return { start, stop };
16088
- }
16089
- function pickExecutor(jobType, byCapability) {
16090
- for (const executor of byCapability.values()) {
16091
- if (executor.capability.jobTypes.includes(jobType))
16092
- return executor;
17968
+ const jobPoolDescriptor = (0, resolvers_1.describeJobPoolRef)(jobsCreateOptions.jobPool);
17969
+ if (!jobPoolDescriptor) {
17970
+ throw new errors_1.WorkflowBuilderError(workflow.name, node.name, "jobPool must be a substrate-shipped named resolver, literalJobPool(...), or { id } / { name }");
16093
17971
  }
16094
- return void 0;
17972
+ const config = {
17973
+ jobPoolRef: jobPoolDescriptor,
17974
+ inputs: { ...jobsCreateOptions.inputs },
17975
+ ...jobsCreateOptions.maxAttempts !== void 0 ? { maxAttempts: jobsCreateOptions.maxAttempts } : {},
17976
+ ...jobsCreateOptions.deadline !== void 0 ? { deadlineDuration: jobsCreateOptions.deadline } : {}
17977
+ };
17978
+ return { ...envelope(node.name, jobsCreateOptions), entryBehavior: "jobs.create", config };
16095
17979
  }
16096
- function pickProviderHints(spec, capabilityId) {
16097
- if (!spec.providerHints)
16098
- return {};
16099
- const key = capabilityId.replace(/-([a-z])/g, (_, c) => c.toUpperCase());
16100
- const hints = spec.providerHints;
16101
- const matched = hints[key];
16102
- if (matched && typeof matched === "object")
16103
- return matched;
16104
- return {};
16105
- }
16106
- function pickCostCapHint(spec) {
16107
- const hint = spec.costCapHint;
16108
- if (!hint)
16109
- return {};
16110
- const result = {};
16111
- if (typeof hint.estimatedInputTokens === "number")
16112
- result.inputTokens = hint.estimatedInputTokens;
16113
- if (typeof hint.estimatedOutputTokens === "number")
16114
- result.outputTokens = hint.estimatedOutputTokens;
16115
- return result;
17980
+ function envelope(name, options) {
17981
+ return {
17982
+ name,
17983
+ ...options.description !== void 0 ? { description: options.description } : {},
17984
+ ...options.transition !== void 0 ? {
17985
+ transitionResolver: options.transition.resolver,
17986
+ transitionContext: extractTransitionContext(options.transition)
17987
+ } : {},
17988
+ ...options.qualityGates !== void 0 ? { qualityGates: serialiseQualityGates(options.qualityGates) } : {},
17989
+ // Normalise the emit spec: `true` → emit-all (`{}`); object → as-is;
17990
+ // `false`/omitted → not emitted (field absent).
17991
+ ...options.emitOutput === true ? { emitOutput: {} } : options.emitOutput && typeof options.emitOutput === "object" ? { emitOutput: options.emitOutput } : {}
17992
+ };
16116
17993
  }
16117
- function safeJsonParse(s) {
16118
- try {
16119
- const parsed = JSON.parse(s);
16120
- return typeof parsed === "object" && parsed !== null ? parsed : void 0;
16121
- } catch {
16122
- return void 0;
16123
- }
17994
+ function interpolate(value, env) {
17995
+ return value.replace(/\$\{([A-Z_][A-Z0-9_]*)\}/g, (_match, name) => {
17996
+ if (Object.prototype.hasOwnProperty.call(env, name))
17997
+ return env[name];
17998
+ throw new Error(`seedWorkflows: missing env var "${name}" referenced in automation endpoint URL`);
17999
+ });
16124
18000
  }
16125
- function sleep(ms) {
16126
- return new Promise((resolve) => setTimeout(resolve, ms));
18001
+ function extractTransitionContext(tr) {
18002
+ const out = {};
18003
+ if (tr.to)
18004
+ out.to = tr.to;
18005
+ if (tr.rules)
18006
+ out.rules = tr.rules;
18007
+ return out;
18008
+ }
18009
+ function serialiseQualityGates(gates) {
18010
+ return gates.map((group) => ({
18011
+ group: group.group,
18012
+ gates: group.gates.map((g) => {
18013
+ if (g.strategy === "artifact_check") {
18014
+ return {
18015
+ name: g.name,
18016
+ strategy: "artifact_check",
18017
+ outputLabel: g.outputLabel,
18018
+ outputSchema: toJsonSchema(g.outputSchema)
18019
+ };
18020
+ }
18021
+ if (g.strategy === "webhook") {
18022
+ return {
18023
+ name: g.name,
18024
+ strategy: "webhook",
18025
+ url: g.url,
18026
+ ...g.timeout !== void 0 ? { timeout: g.timeout } : {},
18027
+ ...g.expectedStatus !== void 0 ? { expectedStatus: g.expectedStatus } : {}
18028
+ };
18029
+ }
18030
+ const descriptor = (0, resolvers_1.describeJobPoolRef)(g.jobPool);
18031
+ return {
18032
+ name: g.name,
18033
+ strategy: "job",
18034
+ jobPool: descriptor,
18035
+ ...g.instructions !== void 0 ? { instructions: g.instructions } : {},
18036
+ passCondition: g.passCondition
18037
+ };
18038
+ })
18039
+ }));
16127
18040
  }
16128
18041
  }
16129
18042
  });
16130
18043
 
16131
- // ../../packages/jobs/dist/index.js
16132
- var require_dist2 = __commonJS({
16133
- "../../packages/jobs/dist/index.js"(exports2) {
18044
+ // ../../packages/loom/dist/seed/seed-workflows.js
18045
+ var require_seed_workflows = __commonJS({
18046
+ "../../packages/loom/dist/seed/seed-workflows.js"(exports2) {
16134
18047
  "use strict";
16135
18048
  Object.defineProperty(exports2, "__esModule", { value: true });
16136
- exports2.subscribe = exports2.SpendCapExceeded = exports2.ObserverChain = exports2.renderTemplate = exports2.renderPromptExecution = exports2.DEFAULT_JOB_TYPE = exports2.readPromptExecutionSpec = exports2.buildPromptExecutionInputs = exports2.JobsClient = void 0;
16137
- var client_1 = require_client();
16138
- Object.defineProperty(exports2, "JobsClient", { enumerable: true, get: function() {
16139
- return client_1.JobsClient;
16140
- } });
16141
- var prompt_execution_1 = require_prompt_execution();
18049
+ exports2.seedWorkflows = seedWorkflows;
18050
+ var canonicalise_1 = require_canonicalise();
18051
+ var errors_1 = require_errors3();
18052
+ var NULL_LOGGER = {
18053
+ info: () => {
18054
+ },
18055
+ warn: () => {
18056
+ },
18057
+ error: () => {
18058
+ }
18059
+ };
18060
+ async function seedWorkflows(opts) {
18061
+ const logger = opts.logger ?? NULL_LOGGER;
18062
+ const fetchFn = opts.fetchFn ?? fetch;
18063
+ const baseUrl = opts.loomApiUrl.replace(/\/$/, "");
18064
+ const headers = { "Content-Type": "application/json" };
18065
+ if ("accessToken" in opts.auth) {
18066
+ headers["Authorization"] = `Bearer ${opts.auth.accessToken}`;
18067
+ } else {
18068
+ headers["X-API-Key"] = opts.auth.apiKey;
18069
+ }
18070
+ const results = [];
18071
+ for (const workflow of opts.workflows) {
18072
+ const ownerOrgId = opts.ownerSlugToOrgId[workflow.owner.slug];
18073
+ if (ownerOrgId === void 0) {
18074
+ throw new errors_1.SeedWorkflowsError(workflow.name, `seedWorkflows: owner.slug "${workflow.owner.slug}" not present in ownerSlugToOrgId map`);
18075
+ }
18076
+ const opts2 = { ownerOrgId };
18077
+ if (opts.env !== void 0)
18078
+ opts2.env = opts.env;
18079
+ if (opts.publish !== void 0)
18080
+ opts2.publish = opts.publish;
18081
+ const body = await (0, canonicalise_1.canonicaliseWorkflow)(workflow, opts2);
18082
+ logger.info(`seeding workflow ${workflow.name}`, {
18083
+ ownerOrgId,
18084
+ nodes: body.nodes.length,
18085
+ transitions: body.transitions.length
18086
+ });
18087
+ const response = await fetchFn(`${baseUrl}/api/admin/seed-workflow`, {
18088
+ method: "POST",
18089
+ headers,
18090
+ body: JSON.stringify(body)
18091
+ });
18092
+ const json = await response.json();
18093
+ if (!response.ok || !json.success || !json.data) {
18094
+ const message = json.error?.message ?? `seedWorkflows: ${workflow.name} failed with HTTP ${response.status}`;
18095
+ throw new errors_1.SeedWorkflowsError(workflow.name, message);
18096
+ }
18097
+ results.push(json.data);
18098
+ }
18099
+ return { workflows: results };
18100
+ }
18101
+ }
18102
+ });
18103
+
18104
+ // ../../packages/loom/dist/index.js
18105
+ var require_dist3 = __commonJS({
18106
+ "../../packages/loom/dist/index.js"(exports2) {
18107
+ "use strict";
18108
+ var __createBinding = exports2 && exports2.__createBinding || (Object.create ? (function(o, m, k, k2) {
18109
+ if (k2 === void 0) k2 = k;
18110
+ var desc = Object.getOwnPropertyDescriptor(m, k);
18111
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
18112
+ desc = { enumerable: true, get: function() {
18113
+ return m[k];
18114
+ } };
18115
+ }
18116
+ Object.defineProperty(o, k2, desc);
18117
+ }) : (function(o, m, k, k2) {
18118
+ if (k2 === void 0) k2 = k;
18119
+ o[k2] = m[k];
18120
+ }));
18121
+ var __exportStar = exports2 && exports2.__exportStar || function(m, exports3) {
18122
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports3, p)) __createBinding(exports3, m, p);
18123
+ };
18124
+ Object.defineProperty(exports2, "__esModule", { value: true });
18125
+ exports2.SeedWorkflowsError = exports2.WorkflowBuilderError = exports2.seedWorkflows = exports2.canonicaliseWorkflow = exports2.synthesiseLinearChain = exports2.describeJobPoolRef = exports2.literalJobPool = exports2.principalJobPool = exports2.jobsCreateNode = exports2.httpNode = exports2.promptNode = exports2.defineWorkflow = exports2.buildPromptExecutionInputs = void 0;
18126
+ __exportStar(require_runtime(), exports2);
18127
+ var prompt_execution_1 = require_prompt_execution2();
16142
18128
  Object.defineProperty(exports2, "buildPromptExecutionInputs", { enumerable: true, get: function() {
16143
18129
  return prompt_execution_1.buildPromptExecutionInputs;
16144
18130
  } });
16145
- Object.defineProperty(exports2, "readPromptExecutionSpec", { enumerable: true, get: function() {
16146
- return prompt_execution_1.readPromptExecutionSpec;
18131
+ var define_workflow_1 = require_define_workflow();
18132
+ Object.defineProperty(exports2, "defineWorkflow", { enumerable: true, get: function() {
18133
+ return define_workflow_1.defineWorkflow;
16147
18134
  } });
16148
- Object.defineProperty(exports2, "DEFAULT_JOB_TYPE", { enumerable: true, get: function() {
16149
- return prompt_execution_1.DEFAULT_JOB_TYPE;
18135
+ var nodes_1 = require_nodes();
18136
+ Object.defineProperty(exports2, "promptNode", { enumerable: true, get: function() {
18137
+ return nodes_1.promptNode;
16150
18138
  } });
16151
- var prompt_execution_render_1 = require_prompt_execution_render();
16152
- Object.defineProperty(exports2, "renderPromptExecution", { enumerable: true, get: function() {
16153
- return prompt_execution_render_1.renderPromptExecution;
18139
+ Object.defineProperty(exports2, "httpNode", { enumerable: true, get: function() {
18140
+ return nodes_1.httpNode;
16154
18141
  } });
16155
- Object.defineProperty(exports2, "renderTemplate", { enumerable: true, get: function() {
16156
- return prompt_execution_render_1.renderTemplate;
18142
+ Object.defineProperty(exports2, "jobsCreateNode", { enumerable: true, get: function() {
18143
+ return nodes_1.jobsCreateNode;
16157
18144
  } });
16158
- var observers_1 = require_observers();
16159
- Object.defineProperty(exports2, "ObserverChain", { enumerable: true, get: function() {
16160
- return observers_1.ObserverChain;
18145
+ var resolvers_1 = require_resolvers();
18146
+ Object.defineProperty(exports2, "principalJobPool", { enumerable: true, get: function() {
18147
+ return resolvers_1.principalJobPool;
16161
18148
  } });
16162
- Object.defineProperty(exports2, "SpendCapExceeded", { enumerable: true, get: function() {
16163
- return observers_1.SpendCapExceeded;
18149
+ Object.defineProperty(exports2, "literalJobPool", { enumerable: true, get: function() {
18150
+ return resolvers_1.literalJobPool;
16164
18151
  } });
16165
- var subscribe_1 = require_subscribe();
16166
- Object.defineProperty(exports2, "subscribe", { enumerable: true, get: function() {
16167
- return subscribe_1.subscribe;
18152
+ Object.defineProperty(exports2, "describeJobPoolRef", { enumerable: true, get: function() {
18153
+ return resolvers_1.describeJobPoolRef;
16168
18154
  } });
18155
+ var transitions_1 = require_transitions();
18156
+ Object.defineProperty(exports2, "synthesiseLinearChain", { enumerable: true, get: function() {
18157
+ return transitions_1.synthesiseLinearChain;
18158
+ } });
18159
+ var canonicalise_1 = require_canonicalise();
18160
+ Object.defineProperty(exports2, "canonicaliseWorkflow", { enumerable: true, get: function() {
18161
+ return canonicalise_1.canonicaliseWorkflow;
18162
+ } });
18163
+ var seed_workflows_1 = require_seed_workflows();
18164
+ Object.defineProperty(exports2, "seedWorkflows", { enumerable: true, get: function() {
18165
+ return seed_workflows_1.seedWorkflows;
18166
+ } });
18167
+ var errors_1 = require_errors3();
18168
+ Object.defineProperty(exports2, "WorkflowBuilderError", { enumerable: true, get: function() {
18169
+ return errors_1.WorkflowBuilderError;
18170
+ } });
18171
+ Object.defineProperty(exports2, "SeedWorkflowsError", { enumerable: true, get: function() {
18172
+ return errors_1.SeedWorkflowsError;
18173
+ } });
18174
+ }
18175
+ });
18176
+
18177
+ // ../../packages/shuttle/dist/observers/chain.js
18178
+ var require_chain = __commonJS({
18179
+ "../../packages/shuttle/dist/observers/chain.js"(exports2) {
18180
+ "use strict";
18181
+ Object.defineProperty(exports2, "__esModule", { value: true });
18182
+ exports2.ObserverChain = exports2.SpendCapExceeded = void 0;
18183
+ var SpendCapExceeded = class extends Error {
18184
+ cap;
18185
+ used;
18186
+ limit;
18187
+ constructor(cap, used, limit) {
18188
+ super(`Spend cap "${cap}" exceeded: used ${used}, limit ${limit}`);
18189
+ this.cap = cap;
18190
+ this.used = used;
18191
+ this.limit = limit;
18192
+ this.name = "SpendCapExceeded";
18193
+ }
18194
+ };
18195
+ exports2.SpendCapExceeded = SpendCapExceeded;
18196
+ var VETO_EVENTS = /* @__PURE__ */ new Set(["spend.preflight"]);
18197
+ var ObserverChain = class {
18198
+ observers;
18199
+ constructor(observers = []) {
18200
+ this.observers = observers;
18201
+ }
18202
+ async notify(event, onObserverError) {
18203
+ const isVeto = VETO_EVENTS.has(event.kind);
18204
+ for (const observer of this.observers) {
18205
+ try {
18206
+ await observer.notify(event);
18207
+ } catch (err) {
18208
+ if (isVeto)
18209
+ throw err;
18210
+ if (onObserverError)
18211
+ onObserverError(err, observer.name, event);
18212
+ }
18213
+ }
18214
+ }
18215
+ get size() {
18216
+ return this.observers.length;
18217
+ }
18218
+ };
18219
+ exports2.ObserverChain = ObserverChain;
16169
18220
  }
16170
18221
  });
16171
18222
 
@@ -16316,7 +18367,7 @@ var require_client2 = __commonJS({
16316
18367
  }
16317
18368
  /**
16318
18369
  * Bind a role (by name) to a service identity. Pool-scoped bindings
16319
- * pass `scopeRefs: [{kind: 'attentionPool', poolId: ...}]`. User-owned
18370
+ * pass `scopeRefs: [{kind: 'jobPool', poolId: ...}]`. User-owned
16320
18371
  * pools pass `userId` as the structural principal; team/org-owned
16321
18372
  * pools pass `teamId`/`orgId`.
16322
18373
  *
@@ -16522,7 +18573,7 @@ var require_agent_token = __commonJS({
16522
18573
  });
16523
18574
 
16524
18575
  // ../../packages/keep/dist/index.js
16525
- var require_dist3 = __commonJS({
18576
+ var require_dist4 = __commonJS({
16526
18577
  "../../packages/keep/dist/index.js"(exports2) {
16527
18578
  "use strict";
16528
18579
  Object.defineProperty(exports2, "__esModule", { value: true });
@@ -16659,6 +18710,22 @@ var require_registry = __commonJS({
16659
18710
  }
16660
18711
  });
16661
18712
 
18713
+ // ../../packages/shuttle/dist/executors/validate-output.js
18714
+ var require_validate_output = __commonJS({
18715
+ "../../packages/shuttle/dist/executors/validate-output.js"(exports2) {
18716
+ "use strict";
18717
+ Object.defineProperty(exports2, "__esModule", { value: true });
18718
+ exports2.assertOutputValid = assertOutputValid;
18719
+ var loom_1 = require_dist3();
18720
+ function assertOutputValid(spec, parsed) {
18721
+ const { valid, errors } = (0, loom_1.validateAgainstSchema)(parsed ?? null, spec.outputSchema);
18722
+ if (!valid) {
18723
+ throw new Error(`prompt-execution output failed schema validation: ${errors.join("; ")}`);
18724
+ }
18725
+ }
18726
+ }
18727
+ });
18728
+
16662
18729
  // ../../packages/shuttle/dist/executors/claude-code.js
16663
18730
  var require_claude_code = __commonJS({
16664
18731
  "../../packages/shuttle/dist/executors/claude-code.js"(exports2) {
@@ -16666,18 +18733,28 @@ var require_claude_code = __commonJS({
16666
18733
  Object.defineProperty(exports2, "__esModule", { value: true });
16667
18734
  exports2.createClaudeCodeExecutor = createClaudeCodeExecutor;
16668
18735
  var child_process_1 = require("child_process");
18736
+ var loom_1 = require_dist3();
18737
+ var validate_output_1 = require_validate_output();
18738
+ var apply_1 = require_apply();
16669
18739
  var DEFAULT_TIMEOUT = 6e5;
16670
18740
  var ClaudeCodeExecutor = class {
16671
18741
  capability;
18742
+ strategies = [loom_1.PROMPT_EXECUTION_STRATEGY];
16672
18743
  config;
16673
18744
  constructor(config) {
16674
18745
  this.config = config;
16675
- this.capability = {
16676
- id: config.capabilityId,
16677
- jobTypes: ["prompt-execution"]
18746
+ this.capability = { id: config.capabilityId };
18747
+ }
18748
+ estimate(dispatch) {
18749
+ const spec = (0, loom_1.readPromptExecutionSpec)(dispatch.inputs);
18750
+ return {
18751
+ inputTokens: spec.costCapHint?.estimatedInputTokens,
18752
+ outputTokens: spec.costCapHint?.estimatedOutputTokens
16678
18753
  };
16679
18754
  }
16680
- dispatch(req, signal) {
18755
+ execute(dispatch, signal) {
18756
+ const { prompt, spec } = (0, loom_1.renderPromptExecution)(dispatch.inputs);
18757
+ const outputLabel = spec.outputLabel;
16681
18758
  return new Promise((resolve, reject) => {
16682
18759
  const args = ["--print"];
16683
18760
  if (this.config.model)
@@ -16706,7 +18783,7 @@ var require_claude_code = __commonJS({
16706
18783
  fn();
16707
18784
  };
16708
18785
  child.stdout.on("data", (chunk) => stdoutChunks.push(chunk));
16709
- child.stdin.write(req.prompt);
18786
+ child.stdin.write(prompt);
16710
18787
  child.stdin.end();
16711
18788
  const timeout = this.config.timeout ?? DEFAULT_TIMEOUT;
16712
18789
  const timer = setTimeout(() => {
@@ -16734,9 +18811,12 @@ var require_claude_code = __commonJS({
16734
18811
  signal.removeEventListener("abort", onAbort);
16735
18812
  const stdout = Buffer.concat(stdoutChunks).toString("utf-8");
16736
18813
  if (code === 0) {
18814
+ const parsed = safeJsonParse(stdout);
18815
+ (0, validate_output_1.assertOutputValid)(spec, parsed);
16737
18816
  settle(() => resolve({
18817
+ outputs: [{ label: outputLabel, content: parsed ?? { raw: stdout } }],
16738
18818
  rawText: stdout,
16739
- parsed: safeJsonParse(stdout),
18819
+ parsed,
16740
18820
  usage: this.config.model ? { aiProvider: "claude-code", aiModel: this.config.model } : void 0
16741
18821
  }));
16742
18822
  } else {
@@ -16747,10 +18827,11 @@ var require_claude_code = __commonJS({
16747
18827
  }
16748
18828
  };
16749
18829
  function createClaudeCodeExecutor(config, capabilityId = "claude-code") {
16750
- const cwd = config.cwd;
16751
- if (typeof cwd !== "string" || cwd.length === 0) {
18830
+ const cwdRaw = config.cwd;
18831
+ if (typeof cwdRaw !== "string" || cwdRaw.length === 0) {
16752
18832
  throw new Error('ClaudeCodeExecutor requires a non-empty "cwd" string in config');
16753
18833
  }
18834
+ const cwd = (0, apply_1.expandHome)(cwdRaw);
16754
18835
  const validated = { cwd, capabilityId };
16755
18836
  if (config.model !== void 0) {
16756
18837
  if (typeof config.model !== "string")
@@ -16794,24 +18875,33 @@ var require_http_api = __commonJS({
16794
18875
  "use strict";
16795
18876
  Object.defineProperty(exports2, "__esModule", { value: true });
16796
18877
  exports2.createHttpApiExecutor = createHttpApiExecutor;
18878
+ var loom_1 = require_dist3();
18879
+ var validate_output_1 = require_validate_output();
16797
18880
  var DEFAULT_MAX_TOKENS = 4096;
16798
18881
  var DEFAULT_TIMEOUT = 12e4;
16799
18882
  var HttpApiExecutor = class {
16800
18883
  capability;
18884
+ strategies = [loom_1.PROMPT_EXECUTION_STRATEGY];
16801
18885
  config;
16802
18886
  constructor(config) {
16803
18887
  this.config = config;
16804
- this.capability = {
16805
- id: config.capabilityId,
16806
- jobTypes: ["prompt-execution"]
18888
+ this.capability = { id: config.capabilityId };
18889
+ }
18890
+ estimate(dispatch) {
18891
+ const spec = (0, loom_1.readPromptExecutionSpec)(dispatch.inputs);
18892
+ return {
18893
+ inputTokens: spec.costCapHint?.estimatedInputTokens,
18894
+ outputTokens: spec.costCapHint?.estimatedOutputTokens
16807
18895
  };
16808
18896
  }
16809
- async dispatch(req, signal) {
18897
+ async execute(dispatch, signal) {
18898
+ const { prompt, spec } = (0, loom_1.renderPromptExecution)(dispatch.inputs);
18899
+ const outputLabel = spec.outputLabel;
16810
18900
  const isAnthropic = this.config.url.includes("anthropic");
16811
18901
  const body = {
16812
18902
  model: this.config.model,
16813
18903
  max_tokens: this.config.maxTokens,
16814
- messages: [{ role: "user", content: req.prompt }]
18904
+ messages: [{ role: "user", content: prompt }]
16815
18905
  };
16816
18906
  const timeoutController = new AbortController();
16817
18907
  const timer = setTimeout(() => timeoutController.abort(), this.config.timeout);
@@ -16866,9 +18956,12 @@ var require_http_api = __commonJS({
16866
18956
  };
16867
18957
  }
16868
18958
  }
18959
+ const parsed = safeJsonParse(rawText);
18960
+ (0, validate_output_1.assertOutputValid)(spec, parsed);
16869
18961
  return {
18962
+ outputs: [{ label: outputLabel, content: parsed ?? { raw: rawText } }],
16870
18963
  rawText,
16871
- parsed: safeJsonParse(rawText),
18964
+ parsed,
16872
18965
  ...usage ? { usage } : {}
16873
18966
  };
16874
18967
  } finally {
@@ -16961,8 +19054,10 @@ var require_anthropic_api = __commonJS({
16961
19054
  "use strict";
16962
19055
  Object.defineProperty(exports2, "__esModule", { value: true });
16963
19056
  exports2.createAnthropicApiExecutor = createAnthropicApiExecutor;
16964
- var keep_1 = require_dist3();
19057
+ var loom_1 = require_dist3();
19058
+ var keep_1 = require_dist4();
16965
19059
  var env_ref_1 = require_env_ref();
19060
+ var validate_output_1 = require_validate_output();
16966
19061
  var DEFAULT_BASE_URL = "https://api.anthropic.com/v1/messages";
16967
19062
  var DEFAULT_MODEL = "claude-sonnet-4-6";
16968
19063
  var DEFAULT_MAX_TOKENS = 4096;
@@ -16970,20 +19065,28 @@ var require_anthropic_api = __commonJS({
16970
19065
  var ANTHROPIC_API_VERSION = "2023-06-01";
16971
19066
  var AnthropicApiExecutor = class {
16972
19067
  capability;
19068
+ strategies = [loom_1.PROMPT_EXECUTION_STRATEGY];
16973
19069
  instance;
16974
19070
  constructor(instance) {
16975
19071
  this.instance = instance;
16976
- this.capability = {
16977
- id: instance.capabilityId,
16978
- jobTypes: ["prompt-execution"]
19072
+ this.capability = { id: instance.capabilityId };
19073
+ }
19074
+ estimate(dispatch) {
19075
+ const spec = (0, loom_1.readPromptExecutionSpec)(dispatch.inputs);
19076
+ return {
19077
+ inputTokens: spec.costCapHint?.estimatedInputTokens,
19078
+ outputTokens: spec.costCapHint?.estimatedOutputTokens
16979
19079
  };
16980
19080
  }
16981
- async dispatch(req, signal) {
16982
- const apiKey = await this.instance.resolveKey(req);
19081
+ async execute(dispatch, signal) {
19082
+ const { prompt, spec } = (0, loom_1.renderPromptExecution)(dispatch.inputs);
19083
+ const outputLabel = spec.outputLabel;
19084
+ const providerHints = (0, loom_1.pickProviderHints)(spec, this.instance.capabilityId);
19085
+ const apiKey = await this.instance.resolveKey(providerHints);
16983
19086
  const body = {
16984
19087
  model: this.instance.model,
16985
19088
  max_tokens: this.instance.maxTokens,
16986
- messages: [{ role: "user", content: req.prompt }]
19089
+ messages: [{ role: "user", content: prompt }]
16987
19090
  };
16988
19091
  const timeoutController = new AbortController();
16989
19092
  const timer = setTimeout(() => timeoutController.abort(), this.instance.timeoutMs);
@@ -17020,9 +19123,12 @@ var require_anthropic_api = __commonJS({
17020
19123
  aiProvider: "anthropic",
17021
19124
  aiModel: this.instance.model
17022
19125
  } : void 0;
19126
+ const parsed = safeJsonParse(rawText);
19127
+ (0, validate_output_1.assertOutputValid)(spec, parsed);
17023
19128
  return {
19129
+ outputs: [{ label: outputLabel, content: parsed ?? { raw: rawText } }],
17024
19130
  rawText,
17025
- parsed: safeJsonParse(rawText),
19131
+ parsed,
17026
19132
  ...usage ? { usage } : {}
17027
19133
  };
17028
19134
  } finally {
@@ -17092,8 +19198,8 @@ var require_anthropic_api = __commonJS({
17092
19198
  const stmFactory = deps.buildServiceTokenManager ?? ((cfg) => new keep_1.ServiceTokenManager(cfg));
17093
19199
  const stm = stmFactory({ keepApiUrl, clientId, clientSecret });
17094
19200
  const keepClientFactory = deps.buildKeepClient ?? ((cfg) => new keep_1.KeepClient(cfg));
17095
- return async (req) => {
17096
- const hints = req.providerHints ?? {};
19201
+ return async (providerHints) => {
19202
+ const hints = providerHints ?? {};
17097
19203
  const customerId = typeof hints.customerId === "string" ? hints.customerId : void 0;
17098
19204
  if (!customerId) {
17099
19205
  throw new Error("AnthropicApiExecutor dynamic-key mode requires providerHints.customerId on every job");
@@ -17135,18 +19241,34 @@ var require_webhook = __commonJS({
17135
19241
  "use strict";
17136
19242
  Object.defineProperty(exports2, "__esModule", { value: true });
17137
19243
  exports2.createWebhookExecutor = createWebhookExecutor;
19244
+ var loom_1 = require_dist3();
19245
+ var validate_output_1 = require_validate_output();
17138
19246
  var DEFAULT_TIMEOUT = 3e4;
17139
19247
  var WebhookExecutor = class {
17140
19248
  capability;
19249
+ strategies = [loom_1.PROMPT_EXECUTION_STRATEGY];
17141
19250
  config;
17142
19251
  constructor(config) {
17143
19252
  this.config = config;
17144
- this.capability = {
17145
- id: config.capabilityId,
17146
- jobTypes: ["prompt-execution"]
19253
+ this.capability = { id: config.capabilityId };
19254
+ }
19255
+ estimate(dispatch) {
19256
+ const spec = (0, loom_1.readPromptExecutionSpec)(dispatch.inputs);
19257
+ return {
19258
+ inputTokens: spec.costCapHint?.estimatedInputTokens,
19259
+ outputTokens: spec.costCapHint?.estimatedOutputTokens
17147
19260
  };
17148
19261
  }
17149
- async dispatch(req, signal) {
19262
+ async execute(dispatch, signal) {
19263
+ const { prompt, spec, artifacts } = (0, loom_1.renderPromptExecution)(dispatch.inputs);
19264
+ const outputLabel = spec.outputLabel;
19265
+ const request = {
19266
+ prompt,
19267
+ outputSchema: spec.outputSchema,
19268
+ outputLabel,
19269
+ providerHints: (0, loom_1.pickProviderHints)(spec, this.config.capabilityId),
19270
+ artifacts
19271
+ };
17150
19272
  const timeoutController = new AbortController();
17151
19273
  const timer = setTimeout(() => timeoutController.abort(), this.config.timeout);
17152
19274
  function onAbort() {
@@ -17160,7 +19282,7 @@ var require_webhook = __commonJS({
17160
19282
  ...this.config.headers,
17161
19283
  "Content-Type": "application/json"
17162
19284
  },
17163
- body: JSON.stringify(req),
19285
+ body: JSON.stringify(request),
17164
19286
  signal: timeoutController.signal
17165
19287
  });
17166
19288
  if (!response.ok) {
@@ -17175,7 +19297,9 @@ var require_webhook = __commonJS({
17175
19297
  if (!data || typeof data !== "object" || typeof data.rawText !== "string") {
17176
19298
  throw new Error('Webhook response missing required "rawText" string field');
17177
19299
  }
19300
+ (0, validate_output_1.assertOutputValid)(spec, data.parsed);
17178
19301
  return {
19302
+ outputs: [{ label: outputLabel, content: data.parsed ?? { raw: data.rawText } }],
17179
19303
  rawText: data.rawText,
17180
19304
  parsed: data.parsed,
17181
19305
  usage: data.usage
@@ -17222,18 +19346,34 @@ var require_custom_script = __commonJS({
17222
19346
  Object.defineProperty(exports2, "__esModule", { value: true });
17223
19347
  exports2.createCustomScriptExecutor = createCustomScriptExecutor;
17224
19348
  var child_process_1 = require("child_process");
19349
+ var loom_1 = require_dist3();
19350
+ var validate_output_1 = require_validate_output();
17225
19351
  var DEFAULT_TIMEOUT = 3e4;
17226
19352
  var CustomScriptExecutor = class {
17227
19353
  capability;
19354
+ strategies = [loom_1.PROMPT_EXECUTION_STRATEGY];
17228
19355
  config;
17229
19356
  constructor(config) {
17230
19357
  this.config = config;
17231
- this.capability = {
17232
- id: config.capabilityId,
17233
- jobTypes: ["prompt-execution"]
19358
+ this.capability = { id: config.capabilityId };
19359
+ }
19360
+ estimate(dispatch) {
19361
+ const spec = (0, loom_1.readPromptExecutionSpec)(dispatch.inputs);
19362
+ return {
19363
+ inputTokens: spec.costCapHint?.estimatedInputTokens,
19364
+ outputTokens: spec.costCapHint?.estimatedOutputTokens
17234
19365
  };
17235
19366
  }
17236
- dispatch(req, signal) {
19367
+ execute(dispatch, signal) {
19368
+ const { prompt, spec, artifacts } = (0, loom_1.renderPromptExecution)(dispatch.inputs);
19369
+ const outputLabel = spec.outputLabel;
19370
+ const request = {
19371
+ prompt,
19372
+ outputSchema: spec.outputSchema,
19373
+ outputLabel,
19374
+ providerHints: (0, loom_1.pickProviderHints)(spec, this.config.capabilityId),
19375
+ artifacts
19376
+ };
17237
19377
  return new Promise((resolve, reject) => {
17238
19378
  let child;
17239
19379
  try {
@@ -17254,7 +19394,7 @@ var require_custom_script = __commonJS({
17254
19394
  fn();
17255
19395
  };
17256
19396
  child.stdout.on("data", (chunk) => stdoutChunks.push(chunk));
17257
- child.stdin.write(JSON.stringify(req));
19397
+ child.stdin.write(JSON.stringify(request));
17258
19398
  child.stdin.end();
17259
19399
  const timer = setTimeout(() => {
17260
19400
  child.kill("SIGTERM");
@@ -17295,8 +19435,11 @@ var require_custom_script = __commonJS({
17295
19435
  settle(() => reject(new Error('Custom script output missing "rawText" string')));
17296
19436
  return;
17297
19437
  }
19438
+ const rawText = parsed.rawText;
19439
+ (0, validate_output_1.assertOutputValid)(spec, parsed.parsed);
17298
19440
  settle(() => resolve({
17299
- rawText: parsed.rawText,
19441
+ outputs: [{ label: outputLabel, content: parsed.parsed ?? { raw: rawText } }],
19442
+ rawText,
17300
19443
  parsed: parsed.parsed,
17301
19444
  usage: parsed.usage
17302
19445
  }));
@@ -17334,16 +19477,6 @@ var require_logger2 = __commonJS({
17334
19477
  async notify(event) {
17335
19478
  const logger = (0, logger_1.getLogger)();
17336
19479
  switch (event.kind) {
17337
- case "job.discovered":
17338
- logger.debug("Job discovered", {
17339
- jobId: event.jobId,
17340
- poolId: event.poolId,
17341
- attempt: event.attempt
17342
- });
17343
- return;
17344
- case "job.claim.requested":
17345
- logger.debug("Claim requested", { jobId: event.jobId, poolId: event.poolId });
17346
- return;
17347
19480
  case "job.claimed":
17348
19481
  logger.info("Job claimed", {
17349
19482
  jobId: event.jobId,
@@ -17536,7 +19669,7 @@ var require_audit_log = __commonJS({
17536
19669
  const entry = inFlight.get(event.jobId);
17537
19670
  if (entry) {
17538
19671
  entry.executor = event.executor;
17539
- entry.prompt = event.rendered.prompt;
19672
+ entry.prompt = `strategy:${event.strategy}`;
17540
19673
  }
17541
19674
  return;
17542
19675
  }
@@ -17643,7 +19776,7 @@ var require_defaults2 = __commonJS({
17643
19776
  cliBinary: "whittle-shuttle",
17644
19777
  packageName: "@whittlelabs/shuttle",
17645
19778
  version: "0.1.0",
17646
- description: "Substrate agent harness for Whittle Jobs attention pools."
19779
+ description: "Substrate agent harness for Whittle Jobs job pools."
17647
19780
  },
17648
19781
  paths: {
17649
19782
  configDir: "~/.shuttle"
@@ -17683,9 +19816,9 @@ var require_spend_tracker = __commonJS({
17683
19816
  Object.defineProperty(exports2, "__esModule", { value: true });
17684
19817
  exports2.SpendCapExceeded = void 0;
17685
19818
  exports2.createSpendTrackerObserver = createSpendTrackerObserver;
17686
- var jobs_1 = require_dist2();
19819
+ var chain_1 = require_chain();
17687
19820
  Object.defineProperty(exports2, "SpendCapExceeded", { enumerable: true, get: function() {
17688
- return jobs_1.SpendCapExceeded;
19821
+ return chain_1.SpendCapExceeded;
17689
19822
  } });
17690
19823
  var defaults_1 = require_defaults2();
17691
19824
  var apply_1 = require_apply();
@@ -17805,7 +19938,7 @@ var require_spend_tracker = __commonJS({
17805
19938
  remaining: String(remaining),
17806
19939
  unit: "tokens"
17807
19940
  });
17808
- const err = new jobs_1.SpendCapExceeded(`${period}.tokens`, used, cap);
19941
+ const err = new chain_1.SpendCapExceeded(`${period}.tokens`, used, cap);
17809
19942
  err.message = message;
17810
19943
  throw err;
17811
19944
  }
@@ -17820,7 +19953,7 @@ var require_spend_tracker = __commonJS({
17820
19953
  remaining: String(remaining),
17821
19954
  unit: "usd"
17822
19955
  });
17823
- const err = new jobs_1.SpendCapExceeded(`${period}.usd`, used, cap);
19956
+ const err = new chain_1.SpendCapExceeded(`${period}.usd`, used, cap);
17824
19957
  err.message = message;
17825
19958
  throw err;
17826
19959
  }
@@ -17834,7 +19967,9 @@ var require_shuttle = __commonJS({
17834
19967
  Object.defineProperty(exports2, "__esModule", { value: true });
17835
19968
  exports2.Shuttle = void 0;
17836
19969
  var jobs_1 = require_dist2();
17837
- var keep_1 = require_dist3();
19970
+ var loom_1 = require_dist3();
19971
+ var chain_1 = require_chain();
19972
+ var keep_1 = require_dist4();
17838
19973
  var apply_1 = require_apply();
17839
19974
  var version_check_1 = require_version_check();
17840
19975
  var logger_1 = require_logger();
@@ -17888,6 +20023,11 @@ var require_shuttle = __commonJS({
17888
20023
  const registry = new registry_1.ExecutorRegistry(this.brand.executorAllowlist);
17889
20024
  registerBuiltInExecutors(registry, this.brand.executorAllowlist);
17890
20025
  const executors = registry.build(this.config.executors);
20026
+ const byStrategy = /* @__PURE__ */ new Map();
20027
+ for (const executor of executors) {
20028
+ for (const strategy of executor.strategies)
20029
+ byStrategy.set(strategy, executor);
20030
+ }
17891
20031
  this.spendTracker = (0, spend_tracker_1.createSpendTrackerObserver)(this.brand, paths.spendStateFile);
17892
20032
  const observers = [
17893
20033
  (0, logger_2.createLoggerObserver)(),
@@ -17895,7 +20035,76 @@ var require_shuttle = __commonJS({
17895
20035
  this.spendTracker,
17896
20036
  ...this.brand.observers ?? []
17897
20037
  ];
17898
- const observerChain = new jobs_1.ObserverChain(observers);
20038
+ const observerChain = new chain_1.ObserverChain(observers);
20039
+ const onObserverError = (err, observerName, event) => {
20040
+ logger.warn("observer threw on non-veto event", {
20041
+ observerName,
20042
+ eventKind: event.kind,
20043
+ error: err instanceof Error ? err.message : String(err)
20044
+ });
20045
+ };
20046
+ const onJob = async (dispatch, signal) => {
20047
+ const jobId = dispatch.job.id;
20048
+ const attendanceId = dispatch.attendanceId;
20049
+ const startedAt = Date.now();
20050
+ const strategy = (0, loom_1.readShuttleStrategy)(dispatch.inputs) ?? "";
20051
+ const executor = byStrategy.get(strategy);
20052
+ if (!executor) {
20053
+ const reason = `no executor for shuttle strategy "${strategy}"`;
20054
+ await observerChain.notify({ kind: "attendance.closed", jobId, attendanceId, status: "failed", reason, totalDurationMs: Date.now() - startedAt }, onObserverError);
20055
+ return { status: "failed", reason };
20056
+ }
20057
+ await observerChain.notify({
20058
+ kind: "job.claimed",
20059
+ jobId,
20060
+ attendanceId,
20061
+ attempt: dispatch.job.attempt,
20062
+ deadline: dispatch.deadline,
20063
+ claimedAt: dispatch.claimedAt,
20064
+ dispatch
20065
+ }, onObserverError);
20066
+ let estimate = {};
20067
+ if (executor.estimate) {
20068
+ try {
20069
+ estimate = await executor.estimate(dispatch);
20070
+ } catch {
20071
+ }
20072
+ }
20073
+ try {
20074
+ await observerChain.notify({ kind: "spend.preflight", jobId, attendanceId, estimate });
20075
+ } catch (err) {
20076
+ const reason = err instanceof chain_1.SpendCapExceeded ? "refused_over_cap" : `preflight rejected: ${err instanceof Error ? err.message : String(err)}`;
20077
+ await observerChain.notify({ kind: "attendance.closed", jobId, attendanceId, status: "failed", reason, totalDurationMs: Date.now() - startedAt }, onObserverError);
20078
+ return { status: "failed", reason };
20079
+ }
20080
+ await observerChain.notify({ kind: "executor.dispatch.started", jobId, attendanceId, executor: executor.capability.id, strategy }, onObserverError);
20081
+ const dispatchStartedAt = Date.now();
20082
+ let response;
20083
+ try {
20084
+ response = await executor.execute(dispatch, signal);
20085
+ } catch (err) {
20086
+ const reason = `executor failed: ${err instanceof Error ? err.message : String(err)}`;
20087
+ await observerChain.notify({ kind: "attendance.closed", jobId, attendanceId, status: "failed", reason, totalDurationMs: Date.now() - startedAt }, onObserverError);
20088
+ return { status: "failed", reason };
20089
+ }
20090
+ await observerChain.notify({
20091
+ kind: "executor.dispatch.completed",
20092
+ jobId,
20093
+ attendanceId,
20094
+ executor: executor.capability.id,
20095
+ response: { rawText: response.rawText ?? "", parsed: response.parsed, usage: response.usage },
20096
+ durationMs: Date.now() - dispatchStartedAt
20097
+ }, onObserverError);
20098
+ const outputs = [...response.outputs];
20099
+ if (response.usage) {
20100
+ outputs.push({ label: "usage", content: response.usage });
20101
+ }
20102
+ for (const output of outputs) {
20103
+ await observerChain.notify({ kind: "output.submitted", jobId, attendanceId, label: output.label, content: output.content }, onObserverError);
20104
+ }
20105
+ await observerChain.notify({ kind: "attendance.closed", jobId, attendanceId, status: "completed", totalDurationMs: Date.now() - startedAt }, onObserverError);
20106
+ return { status: "completed", outputs };
20107
+ };
17899
20108
  const pools = this.config.pools.map((p) => p.id ? { id: p.id } : { name: p.name });
17900
20109
  this.subscription = (0, jobs_1.subscribe)({
17901
20110
  jobsClient,
@@ -17904,12 +20113,10 @@ var require_shuttle = __commonJS({
17904
20113
  identityType: "agent",
17905
20114
  identityId: this.config.agent.identityId,
17906
20115
  intelligence: "digital",
17907
- capabilities: [...this.brand.executorAllowlist].filter((c) => c !== "*"),
17908
20116
  displayName: this.config.agent.displayName,
17909
20117
  metadata: this.config.agent.metadata
17910
20118
  },
17911
- executors,
17912
- observerChain,
20119
+ onJob,
17913
20120
  logger: {
17914
20121
  debug: (msg, meta) => logger.debug(msg, meta),
17915
20122
  info: (msg, meta) => logger.info(msg, meta),
@@ -18045,7 +20252,7 @@ var require_run = __commonJS({
18045
20252
  });
18046
20253
 
18047
20254
  // ../../packages/shuttle/dist/cli/validate.js
18048
- var require_validate = __commonJS({
20255
+ var require_validate2 = __commonJS({
18049
20256
  "../../packages/shuttle/dist/cli/validate.js"(exports2) {
18050
20257
  "use strict";
18051
20258
  Object.defineProperty(exports2, "__esModule", { value: true });
@@ -18263,7 +20470,7 @@ var require_list = __commonJS({
18263
20470
  Object.defineProperty(exports2, "__esModule", { value: true });
18264
20471
  exports2.buildListCommand = buildListCommand;
18265
20472
  var commander_1 = require_commander();
18266
- var keep_1 = require_dist3();
20473
+ var keep_1 = require_dist4();
18267
20474
  var apply_1 = require_apply();
18268
20475
  var store_1 = require_store();
18269
20476
  var pairings_1 = require_pairings();
@@ -18308,7 +20515,7 @@ var require_revoke = __commonJS({
18308
20515
  Object.defineProperty(exports2, "__esModule", { value: true });
18309
20516
  exports2.buildRevokeCommand = buildRevokeCommand;
18310
20517
  var commander_1 = require_commander();
18311
- var keep_1 = require_dist3();
20518
+ var keep_1 = require_dist4();
18312
20519
  var apply_1 = require_apply();
18313
20520
  var store_1 = require_store();
18314
20521
  var pairings_1 = require_pairings();
@@ -18356,7 +20563,7 @@ var require_cli = __commonJS({
18356
20563
  var commander_1 = require_commander();
18357
20564
  var init_1 = require_init();
18358
20565
  var run_1 = require_run();
18359
- var validate_1 = require_validate();
20566
+ var validate_1 = require_validate2();
18360
20567
  var audit_1 = require_audit();
18361
20568
  var caps_1 = require_caps();
18362
20569
  var list_1 = require_list();
@@ -18377,7 +20584,7 @@ var require_cli = __commonJS({
18377
20584
  });
18378
20585
 
18379
20586
  // ../../packages/shuttle/dist/index.js
18380
- var require_dist4 = __commonJS({
20587
+ var require_dist5 = __commonJS({
18381
20588
  "../../packages/shuttle/dist/index.js"(exports2) {
18382
20589
  "use strict";
18383
20590
  Object.defineProperty(exports2, "__esModule", { value: true });
@@ -18427,12 +20634,12 @@ var require_dist4 = __commonJS({
18427
20634
  Object.defineProperty(exports2, "createCustomScriptExecutor", { enumerable: true, get: function() {
18428
20635
  return custom_script_1.createCustomScriptExecutor;
18429
20636
  } });
18430
- var jobs_1 = require_dist2();
20637
+ var chain_1 = require_chain();
18431
20638
  Object.defineProperty(exports2, "ObserverChain", { enumerable: true, get: function() {
18432
- return jobs_1.ObserverChain;
20639
+ return chain_1.ObserverChain;
18433
20640
  } });
18434
20641
  Object.defineProperty(exports2, "SpendCapExceeded", { enumerable: true, get: function() {
18435
- return jobs_1.SpendCapExceeded;
20642
+ return chain_1.SpendCapExceeded;
18436
20643
  } });
18437
20644
  var logger_1 = require_logger2();
18438
20645
  Object.defineProperty(exports2, "createLoggerObserver", { enumerable: true, get: function() {
@@ -18496,20 +20703,20 @@ var require_dist4 = __commonJS({
18496
20703
  });
18497
20704
 
18498
20705
  // src/bin.ts
18499
- var import_shuttle2 = __toESM(require_dist4());
20706
+ var import_shuttle2 = __toESM(require_dist5());
18500
20707
 
18501
20708
  // src/brand.ts
18502
20709
  var import_path = require("path");
18503
20710
  var import_promises = require("fs/promises");
18504
20711
  var import_readline = require("readline");
18505
20712
  var import_yaml = __toESM(require_dist());
18506
- var import_shuttle = __toESM(require_dist4());
20713
+ var import_shuttle = __toESM(require_dist5());
18507
20714
 
18508
20715
  // package.json
18509
20716
  var package_default = {
18510
20717
  name: "@whittlelabs/sifter",
18511
- version: "0.4.2",
18512
- description: "Whittle Sifter: paired AI reviewer for Whittle Sift attention pools.",
20718
+ version: "0.5.1",
20719
+ description: "Whittle Sifter: paired AI reviewer for Whittle Sift job pools.",
18513
20720
  bin: {
18514
20721
  "whittle-sifter": "./dist/bin.js"
18515
20722
  },
@@ -18601,9 +20808,9 @@ var sifterBrand = {
18601
20808
  run: async (ctx) => {
18602
20809
  const yamlPath = (0, import_path.join)(ctx.configDir, "sifter.yaml");
18603
20810
  const pairing = new import_shuttle.PairingConfigStore((0, import_path.join)(ctx.configDir, "config.json")).read();
18604
- if (pairing.attentionPools.length === 0) {
20811
+ if (pairing.jobPools.length === 0) {
18605
20812
  throw new Error(
18606
- "Pairing returned no attention pools. The Sift backend should have provisioned one for this user during pre-pair."
20813
+ "Pairing returned no job pools. The Sift backend should have provisioned one for this user during pre-pair."
18607
20814
  );
18608
20815
  }
18609
20816
  let existing = {};
@@ -18626,7 +20833,7 @@ var sifterBrand = {
18626
20833
  displayName: pairing.serviceIdentity.displayName,
18627
20834
  identityId: pairing.serviceIdentity.id
18628
20835
  },
18629
- pools: pairing.attentionPools.map((p) => ({
20836
+ pools: pairing.jobPools.map((p) => ({
18630
20837
  id: p.id,
18631
20838
  name: p.name,
18632
20839
  executor