@boboddy/sdk 0.0.13-alpha → 0.1.0-alpha

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 (43) hide show
  1. package/dist/boboddy-config-parser.d.ts +34 -0
  2. package/dist/boboddy-config-parser.js +510 -0
  3. package/dist/client.d.ts +3 -1
  4. package/dist/client.js +1327 -45
  5. package/dist/definitions/advancement-policies/define-advancement-policy.d.ts +218 -0
  6. package/dist/definitions/advancement-policies/index.d.ts +1 -0
  7. package/dist/definitions/advancement-policies/index.js +95 -0
  8. package/dist/definitions/pipelines/define-pipeline.d.ts +112 -0
  9. package/dist/definitions/pipelines/index.d.ts +1 -0
  10. package/dist/definitions/pipelines/index.js +141 -0
  11. package/dist/{define-step.d.ts → definitions/steps/define-step.d.ts} +37 -4
  12. package/dist/definitions/steps/index.d.ts +2 -0
  13. package/dist/definitions/steps/index.js +13302 -0
  14. package/dist/definitions/steps/step-definitions-client.d.ts +197 -0
  15. package/dist/generated/client/client.gen.d.ts +2 -0
  16. package/dist/generated/client/index.d.ts +8 -0
  17. package/dist/generated/client/types.gen.d.ts +117 -0
  18. package/dist/generated/client/utils.gen.d.ts +33 -0
  19. package/dist/generated/client.gen.d.ts +12 -0
  20. package/dist/generated/core/auth.gen.d.ts +18 -0
  21. package/dist/generated/core/bodySerializer.gen.d.ts +25 -0
  22. package/dist/generated/core/params.gen.d.ts +43 -0
  23. package/dist/generated/core/pathSerializer.gen.d.ts +33 -0
  24. package/dist/generated/core/queryKeySerializer.gen.d.ts +18 -0
  25. package/dist/generated/core/serverSentEvents.gen.d.ts +71 -0
  26. package/dist/generated/core/types.gen.d.ts +78 -0
  27. package/dist/generated/core/utils.gen.d.ts +19 -0
  28. package/dist/generated/index.d.ts +2 -0
  29. package/dist/generated/sdk.gen.d.ts +140 -0
  30. package/dist/generated/types.gen.d.ts +7842 -0
  31. package/dist/index.d.ts +5 -1
  32. package/dist/index.js +16380 -956
  33. package/dist/jsonc.d.ts +3 -0
  34. package/dist/jsonc.js +133 -0
  35. package/dist/opencode-mcp.d.ts +73 -0
  36. package/dist/opencode-mcp.js +14332 -0
  37. package/dist/step-execution-plane-client.d.ts +107 -287
  38. package/package.json +45 -19
  39. package/dist/define-step.js +0 -1018
  40. package/dist/step-definitions-client.d.ts +0 -202
  41. package/dist/step-definitions-client.js +0 -47
  42. package/dist/treaty.d.ts +0 -13
  43. package/dist/treaty.js +0 -34
@@ -1,1018 +0,0 @@
1
- // ../../../node_modules/.bun/zod@4.4.2/node_modules/zod/v4/core/util.js
2
- function getEnumValues(entries) {
3
- const numericValues = Object.values(entries).filter((v) => typeof v === "number");
4
- const values = Object.entries(entries).filter(([k, _]) => numericValues.indexOf(+k) === -1).map(([_, v]) => v);
5
- return values;
6
- }
7
- var captureStackTrace = "captureStackTrace" in Error ? Error.captureStackTrace : (..._args) => {};
8
- var NUMBER_FORMAT_RANGES = {
9
- safeint: [Number.MIN_SAFE_INTEGER, Number.MAX_SAFE_INTEGER],
10
- int32: [-2147483648, 2147483647],
11
- uint32: [0, 4294967295],
12
- float32: [-340282346638528860000000000000000000000, 340282346638528860000000000000000000000],
13
- float64: [-Number.MAX_VALUE, Number.MAX_VALUE]
14
- };
15
- // ../../../node_modules/.bun/zod@4.4.2/node_modules/zod/v4/core/registries.js
16
- var _a;
17
- var $output = Symbol("ZodOutput");
18
- var $input = Symbol("ZodInput");
19
-
20
- class $ZodRegistry {
21
- constructor() {
22
- this._map = new WeakMap;
23
- this._idmap = new Map;
24
- }
25
- add(schema, ..._meta) {
26
- const meta = _meta[0];
27
- this._map.set(schema, meta);
28
- if (meta && typeof meta === "object" && "id" in meta) {
29
- this._idmap.set(meta.id, schema);
30
- }
31
- return this;
32
- }
33
- clear() {
34
- this._map = new WeakMap;
35
- this._idmap = new Map;
36
- return this;
37
- }
38
- remove(schema) {
39
- const meta = this._map.get(schema);
40
- if (meta && typeof meta === "object" && "id" in meta) {
41
- this._idmap.delete(meta.id);
42
- }
43
- this._map.delete(schema);
44
- return this;
45
- }
46
- get(schema) {
47
- const p = schema._zod.parent;
48
- if (p) {
49
- const pm = { ...this.get(p) ?? {} };
50
- delete pm.id;
51
- const f = { ...pm, ...this._map.get(schema) };
52
- return Object.keys(f).length ? f : undefined;
53
- }
54
- return this._map.get(schema);
55
- }
56
- has(schema) {
57
- return this._map.has(schema);
58
- }
59
- }
60
- function registry() {
61
- return new $ZodRegistry;
62
- }
63
- (_a = globalThis).__zod_globalRegistry ?? (_a.__zod_globalRegistry = registry());
64
- var globalRegistry = globalThis.__zod_globalRegistry;
65
- // ../../../node_modules/.bun/zod@4.4.2/node_modules/zod/v4/core/to-json-schema.js
66
- function initializeContext(params) {
67
- let target = params?.target ?? "draft-2020-12";
68
- if (target === "draft-4")
69
- target = "draft-04";
70
- if (target === "draft-7")
71
- target = "draft-07";
72
- return {
73
- processors: params.processors ?? {},
74
- metadataRegistry: params?.metadata ?? globalRegistry,
75
- target,
76
- unrepresentable: params?.unrepresentable ?? "throw",
77
- override: params?.override ?? (() => {}),
78
- io: params?.io ?? "output",
79
- counter: 0,
80
- seen: new Map,
81
- cycles: params?.cycles ?? "ref",
82
- reused: params?.reused ?? "inline",
83
- external: params?.external ?? undefined
84
- };
85
- }
86
- function process(schema, ctx, _params = { path: [], schemaPath: [] }) {
87
- var _a2;
88
- const def = schema._zod.def;
89
- const seen = ctx.seen.get(schema);
90
- if (seen) {
91
- seen.count++;
92
- const isCycle = _params.schemaPath.includes(schema);
93
- if (isCycle) {
94
- seen.cycle = _params.path;
95
- }
96
- return seen.schema;
97
- }
98
- const result = { schema: {}, count: 1, cycle: undefined, path: _params.path };
99
- ctx.seen.set(schema, result);
100
- const overrideSchema = schema._zod.toJSONSchema?.();
101
- if (overrideSchema) {
102
- result.schema = overrideSchema;
103
- } else {
104
- const params = {
105
- ..._params,
106
- schemaPath: [..._params.schemaPath, schema],
107
- path: _params.path
108
- };
109
- if (schema._zod.processJSONSchema) {
110
- schema._zod.processJSONSchema(ctx, result.schema, params);
111
- } else {
112
- const _json = result.schema;
113
- const processor = ctx.processors[def.type];
114
- if (!processor) {
115
- throw new Error(`[toJSONSchema]: Non-representable type encountered: ${def.type}`);
116
- }
117
- processor(schema, ctx, _json, params);
118
- }
119
- const parent = schema._zod.parent;
120
- if (parent) {
121
- if (!result.ref)
122
- result.ref = parent;
123
- process(parent, ctx, params);
124
- ctx.seen.get(parent).isParent = true;
125
- }
126
- }
127
- const meta = ctx.metadataRegistry.get(schema);
128
- if (meta)
129
- Object.assign(result.schema, meta);
130
- if (ctx.io === "input" && isTransforming(schema)) {
131
- delete result.schema.examples;
132
- delete result.schema.default;
133
- }
134
- if (ctx.io === "input" && "_prefault" in result.schema)
135
- (_a2 = result.schema).default ?? (_a2.default = result.schema._prefault);
136
- delete result.schema._prefault;
137
- const _result = ctx.seen.get(schema);
138
- return _result.schema;
139
- }
140
- function extractDefs(ctx, schema) {
141
- const root = ctx.seen.get(schema);
142
- if (!root)
143
- throw new Error("Unprocessed schema. This is a bug in Zod.");
144
- const idToSchema = new Map;
145
- for (const entry of ctx.seen.entries()) {
146
- const id = ctx.metadataRegistry.get(entry[0])?.id;
147
- if (id) {
148
- const existing = idToSchema.get(id);
149
- if (existing && existing !== entry[0]) {
150
- throw new Error(`Duplicate schema id "${id}" detected during JSON Schema conversion. Two different schemas cannot share the same id when converted together.`);
151
- }
152
- idToSchema.set(id, entry[0]);
153
- }
154
- }
155
- const makeURI = (entry) => {
156
- const defsSegment = ctx.target === "draft-2020-12" ? "$defs" : "definitions";
157
- if (ctx.external) {
158
- const externalId = ctx.external.registry.get(entry[0])?.id;
159
- const uriGenerator = ctx.external.uri ?? ((id2) => id2);
160
- if (externalId) {
161
- return { ref: uriGenerator(externalId) };
162
- }
163
- const id = entry[1].defId ?? entry[1].schema.id ?? `schema${ctx.counter++}`;
164
- entry[1].defId = id;
165
- return { defId: id, ref: `${uriGenerator("__shared")}#/${defsSegment}/${id}` };
166
- }
167
- if (entry[1] === root) {
168
- return { ref: "#" };
169
- }
170
- const uriPrefix = `#`;
171
- const defUriPrefix = `${uriPrefix}/${defsSegment}/`;
172
- const defId = entry[1].schema.id ?? `__schema${ctx.counter++}`;
173
- return { defId, ref: defUriPrefix + defId };
174
- };
175
- const extractToDef = (entry) => {
176
- if (entry[1].schema.$ref) {
177
- return;
178
- }
179
- const seen = entry[1];
180
- const { ref, defId } = makeURI(entry);
181
- seen.def = { ...seen.schema };
182
- if (defId)
183
- seen.defId = defId;
184
- const schema2 = seen.schema;
185
- for (const key in schema2) {
186
- delete schema2[key];
187
- }
188
- schema2.$ref = ref;
189
- };
190
- if (ctx.cycles === "throw") {
191
- for (const entry of ctx.seen.entries()) {
192
- const seen = entry[1];
193
- if (seen.cycle) {
194
- throw new Error("Cycle detected: " + `#/${seen.cycle?.join("/")}/<root>` + '\n\nSet the `cycles` parameter to `"ref"` to resolve cyclical schemas with defs.');
195
- }
196
- }
197
- }
198
- for (const entry of ctx.seen.entries()) {
199
- const seen = entry[1];
200
- if (schema === entry[0]) {
201
- extractToDef(entry);
202
- continue;
203
- }
204
- if (ctx.external) {
205
- const ext = ctx.external.registry.get(entry[0])?.id;
206
- if (schema !== entry[0] && ext) {
207
- extractToDef(entry);
208
- continue;
209
- }
210
- }
211
- const id = ctx.metadataRegistry.get(entry[0])?.id;
212
- if (id) {
213
- extractToDef(entry);
214
- continue;
215
- }
216
- if (seen.cycle) {
217
- extractToDef(entry);
218
- continue;
219
- }
220
- if (seen.count > 1) {
221
- if (ctx.reused === "ref") {
222
- extractToDef(entry);
223
- continue;
224
- }
225
- }
226
- }
227
- }
228
- function finalize(ctx, schema) {
229
- const root = ctx.seen.get(schema);
230
- if (!root)
231
- throw new Error("Unprocessed schema. This is a bug in Zod.");
232
- const flattenRef = (zodSchema) => {
233
- const seen = ctx.seen.get(zodSchema);
234
- if (seen.ref === null)
235
- return;
236
- const schema2 = seen.def ?? seen.schema;
237
- const _cached = { ...schema2 };
238
- const ref = seen.ref;
239
- seen.ref = null;
240
- if (ref) {
241
- flattenRef(ref);
242
- const refSeen = ctx.seen.get(ref);
243
- const refSchema = refSeen.schema;
244
- if (refSchema.$ref && (ctx.target === "draft-07" || ctx.target === "draft-04" || ctx.target === "openapi-3.0")) {
245
- schema2.allOf = schema2.allOf ?? [];
246
- schema2.allOf.push(refSchema);
247
- } else {
248
- Object.assign(schema2, refSchema);
249
- }
250
- Object.assign(schema2, _cached);
251
- const isParentRef = zodSchema._zod.parent === ref;
252
- if (isParentRef) {
253
- for (const key in schema2) {
254
- if (key === "$ref" || key === "allOf")
255
- continue;
256
- if (!(key in _cached)) {
257
- delete schema2[key];
258
- }
259
- }
260
- }
261
- if (refSchema.$ref && refSeen.def) {
262
- for (const key in schema2) {
263
- if (key === "$ref" || key === "allOf")
264
- continue;
265
- if (key in refSeen.def && JSON.stringify(schema2[key]) === JSON.stringify(refSeen.def[key])) {
266
- delete schema2[key];
267
- }
268
- }
269
- }
270
- }
271
- const parent = zodSchema._zod.parent;
272
- if (parent && parent !== ref) {
273
- flattenRef(parent);
274
- const parentSeen = ctx.seen.get(parent);
275
- if (parentSeen?.schema.$ref) {
276
- schema2.$ref = parentSeen.schema.$ref;
277
- if (parentSeen.def) {
278
- for (const key in schema2) {
279
- if (key === "$ref" || key === "allOf")
280
- continue;
281
- if (key in parentSeen.def && JSON.stringify(schema2[key]) === JSON.stringify(parentSeen.def[key])) {
282
- delete schema2[key];
283
- }
284
- }
285
- }
286
- }
287
- }
288
- ctx.override({
289
- zodSchema,
290
- jsonSchema: schema2,
291
- path: seen.path ?? []
292
- });
293
- };
294
- for (const entry of [...ctx.seen.entries()].reverse()) {
295
- flattenRef(entry[0]);
296
- }
297
- const result = {};
298
- if (ctx.target === "draft-2020-12") {
299
- result.$schema = "https://json-schema.org/draft/2020-12/schema";
300
- } else if (ctx.target === "draft-07") {
301
- result.$schema = "http://json-schema.org/draft-07/schema#";
302
- } else if (ctx.target === "draft-04") {
303
- result.$schema = "http://json-schema.org/draft-04/schema#";
304
- } else if (ctx.target === "openapi-3.0") {} else {}
305
- if (ctx.external?.uri) {
306
- const id = ctx.external.registry.get(schema)?.id;
307
- if (!id)
308
- throw new Error("Schema is missing an `id` property");
309
- result.$id = ctx.external.uri(id);
310
- }
311
- Object.assign(result, root.def ?? root.schema);
312
- const rootMetaId = ctx.metadataRegistry.get(schema)?.id;
313
- if (rootMetaId !== undefined && result.id === rootMetaId)
314
- delete result.id;
315
- const defs = ctx.external?.defs ?? {};
316
- for (const entry of ctx.seen.entries()) {
317
- const seen = entry[1];
318
- if (seen.def && seen.defId) {
319
- if (seen.def.id === seen.defId)
320
- delete seen.def.id;
321
- defs[seen.defId] = seen.def;
322
- }
323
- }
324
- if (ctx.external) {} else {
325
- if (Object.keys(defs).length > 0) {
326
- if (ctx.target === "draft-2020-12") {
327
- result.$defs = defs;
328
- } else {
329
- result.definitions = defs;
330
- }
331
- }
332
- }
333
- try {
334
- const finalized = JSON.parse(JSON.stringify(result));
335
- Object.defineProperty(finalized, "~standard", {
336
- value: {
337
- ...schema["~standard"],
338
- jsonSchema: {
339
- input: createStandardJSONSchemaMethod(schema, "input", ctx.processors),
340
- output: createStandardJSONSchemaMethod(schema, "output", ctx.processors)
341
- }
342
- },
343
- enumerable: false,
344
- writable: false
345
- });
346
- return finalized;
347
- } catch (_err) {
348
- throw new Error("Error converting schema to JSON.");
349
- }
350
- }
351
- function isTransforming(_schema, _ctx) {
352
- const ctx = _ctx ?? { seen: new Set };
353
- if (ctx.seen.has(_schema))
354
- return false;
355
- ctx.seen.add(_schema);
356
- const def = _schema._zod.def;
357
- if (def.type === "transform")
358
- return true;
359
- if (def.type === "array")
360
- return isTransforming(def.element, ctx);
361
- if (def.type === "set")
362
- return isTransforming(def.valueType, ctx);
363
- if (def.type === "lazy")
364
- return isTransforming(def.getter(), ctx);
365
- if (def.type === "promise" || def.type === "optional" || def.type === "nonoptional" || def.type === "nullable" || def.type === "readonly" || def.type === "default" || def.type === "prefault") {
366
- return isTransforming(def.innerType, ctx);
367
- }
368
- if (def.type === "intersection") {
369
- return isTransforming(def.left, ctx) || isTransforming(def.right, ctx);
370
- }
371
- if (def.type === "record" || def.type === "map") {
372
- return isTransforming(def.keyType, ctx) || isTransforming(def.valueType, ctx);
373
- }
374
- if (def.type === "pipe") {
375
- if (_schema._zod.traits.has("$ZodCodec"))
376
- return true;
377
- return isTransforming(def.in, ctx) || isTransforming(def.out, ctx);
378
- }
379
- if (def.type === "object") {
380
- for (const key in def.shape) {
381
- if (isTransforming(def.shape[key], ctx))
382
- return true;
383
- }
384
- return false;
385
- }
386
- if (def.type === "union") {
387
- for (const option of def.options) {
388
- if (isTransforming(option, ctx))
389
- return true;
390
- }
391
- return false;
392
- }
393
- if (def.type === "tuple") {
394
- for (const item of def.items) {
395
- if (isTransforming(item, ctx))
396
- return true;
397
- }
398
- if (def.rest && isTransforming(def.rest, ctx))
399
- return true;
400
- return false;
401
- }
402
- return false;
403
- }
404
- var createStandardJSONSchemaMethod = (schema, io, processors = {}) => (params) => {
405
- const { libraryOptions, target } = params ?? {};
406
- const ctx = initializeContext({ ...libraryOptions ?? {}, target, io, processors });
407
- process(schema, ctx);
408
- extractDefs(ctx, schema);
409
- return finalize(ctx, schema);
410
- };
411
- // ../../../node_modules/.bun/zod@4.4.2/node_modules/zod/v4/core/json-schema-processors.js
412
- var formatMap = {
413
- guid: "uuid",
414
- url: "uri",
415
- datetime: "date-time",
416
- json_string: "json-string",
417
- regex: ""
418
- };
419
- var stringProcessor = (schema, ctx, _json, _params) => {
420
- const json = _json;
421
- json.type = "string";
422
- const { minimum, maximum, format, patterns, contentEncoding } = schema._zod.bag;
423
- if (typeof minimum === "number")
424
- json.minLength = minimum;
425
- if (typeof maximum === "number")
426
- json.maxLength = maximum;
427
- if (format) {
428
- json.format = formatMap[format] ?? format;
429
- if (json.format === "")
430
- delete json.format;
431
- if (format === "time") {
432
- delete json.format;
433
- }
434
- }
435
- if (contentEncoding)
436
- json.contentEncoding = contentEncoding;
437
- if (patterns && patterns.size > 0) {
438
- const regexes = [...patterns];
439
- if (regexes.length === 1)
440
- json.pattern = regexes[0].source;
441
- else if (regexes.length > 1) {
442
- json.allOf = [
443
- ...regexes.map((regex) => ({
444
- ...ctx.target === "draft-07" || ctx.target === "draft-04" || ctx.target === "openapi-3.0" ? { type: "string" } : {},
445
- pattern: regex.source
446
- }))
447
- ];
448
- }
449
- }
450
- };
451
- var numberProcessor = (schema, ctx, _json, _params) => {
452
- const json = _json;
453
- const { minimum, maximum, format, multipleOf, exclusiveMaximum, exclusiveMinimum } = schema._zod.bag;
454
- if (typeof format === "string" && format.includes("int"))
455
- json.type = "integer";
456
- else
457
- json.type = "number";
458
- const exMin = typeof exclusiveMinimum === "number" && exclusiveMinimum >= (minimum ?? Number.NEGATIVE_INFINITY);
459
- const exMax = typeof exclusiveMaximum === "number" && exclusiveMaximum <= (maximum ?? Number.POSITIVE_INFINITY);
460
- const legacy = ctx.target === "draft-04" || ctx.target === "openapi-3.0";
461
- if (exMin) {
462
- if (legacy) {
463
- json.minimum = exclusiveMinimum;
464
- json.exclusiveMinimum = true;
465
- } else {
466
- json.exclusiveMinimum = exclusiveMinimum;
467
- }
468
- } else if (typeof minimum === "number") {
469
- json.minimum = minimum;
470
- }
471
- if (exMax) {
472
- if (legacy) {
473
- json.maximum = exclusiveMaximum;
474
- json.exclusiveMaximum = true;
475
- } else {
476
- json.exclusiveMaximum = exclusiveMaximum;
477
- }
478
- } else if (typeof maximum === "number") {
479
- json.maximum = maximum;
480
- }
481
- if (typeof multipleOf === "number")
482
- json.multipleOf = multipleOf;
483
- };
484
- var booleanProcessor = (_schema, _ctx, json, _params) => {
485
- json.type = "boolean";
486
- };
487
- var bigintProcessor = (_schema, ctx, _json, _params) => {
488
- if (ctx.unrepresentable === "throw") {
489
- throw new Error("BigInt cannot be represented in JSON Schema");
490
- }
491
- };
492
- var symbolProcessor = (_schema, ctx, _json, _params) => {
493
- if (ctx.unrepresentable === "throw") {
494
- throw new Error("Symbols cannot be represented in JSON Schema");
495
- }
496
- };
497
- var nullProcessor = (_schema, ctx, json, _params) => {
498
- if (ctx.target === "openapi-3.0") {
499
- json.type = "string";
500
- json.nullable = true;
501
- json.enum = [null];
502
- } else {
503
- json.type = "null";
504
- }
505
- };
506
- var undefinedProcessor = (_schema, ctx, _json, _params) => {
507
- if (ctx.unrepresentable === "throw") {
508
- throw new Error("Undefined cannot be represented in JSON Schema");
509
- }
510
- };
511
- var voidProcessor = (_schema, ctx, _json, _params) => {
512
- if (ctx.unrepresentable === "throw") {
513
- throw new Error("Void cannot be represented in JSON Schema");
514
- }
515
- };
516
- var neverProcessor = (_schema, _ctx, json, _params) => {
517
- json.not = {};
518
- };
519
- var anyProcessor = (_schema, _ctx, _json, _params) => {};
520
- var unknownProcessor = (_schema, _ctx, _json, _params) => {};
521
- var dateProcessor = (_schema, ctx, _json, _params) => {
522
- if (ctx.unrepresentable === "throw") {
523
- throw new Error("Date cannot be represented in JSON Schema");
524
- }
525
- };
526
- var enumProcessor = (schema, _ctx, json, _params) => {
527
- const def = schema._zod.def;
528
- const values = getEnumValues(def.entries);
529
- if (values.every((v) => typeof v === "number"))
530
- json.type = "number";
531
- if (values.every((v) => typeof v === "string"))
532
- json.type = "string";
533
- json.enum = values;
534
- };
535
- var literalProcessor = (schema, ctx, json, _params) => {
536
- const def = schema._zod.def;
537
- const vals = [];
538
- for (const val of def.values) {
539
- if (val === undefined) {
540
- if (ctx.unrepresentable === "throw") {
541
- throw new Error("Literal `undefined` cannot be represented in JSON Schema");
542
- } else {}
543
- } else if (typeof val === "bigint") {
544
- if (ctx.unrepresentable === "throw") {
545
- throw new Error("BigInt literals cannot be represented in JSON Schema");
546
- } else {
547
- vals.push(Number(val));
548
- }
549
- } else {
550
- vals.push(val);
551
- }
552
- }
553
- if (vals.length === 0) {} else if (vals.length === 1) {
554
- const val = vals[0];
555
- json.type = val === null ? "null" : typeof val;
556
- if (ctx.target === "draft-04" || ctx.target === "openapi-3.0") {
557
- json.enum = [val];
558
- } else {
559
- json.const = val;
560
- }
561
- } else {
562
- if (vals.every((v) => typeof v === "number"))
563
- json.type = "number";
564
- if (vals.every((v) => typeof v === "string"))
565
- json.type = "string";
566
- if (vals.every((v) => typeof v === "boolean"))
567
- json.type = "boolean";
568
- if (vals.every((v) => v === null))
569
- json.type = "null";
570
- json.enum = vals;
571
- }
572
- };
573
- var nanProcessor = (_schema, ctx, _json, _params) => {
574
- if (ctx.unrepresentable === "throw") {
575
- throw new Error("NaN cannot be represented in JSON Schema");
576
- }
577
- };
578
- var templateLiteralProcessor = (schema, _ctx, json, _params) => {
579
- const _json = json;
580
- const pattern = schema._zod.pattern;
581
- if (!pattern)
582
- throw new Error("Pattern not found in template literal");
583
- _json.type = "string";
584
- _json.pattern = pattern.source;
585
- };
586
- var fileProcessor = (schema, _ctx, json, _params) => {
587
- const _json = json;
588
- const file = {
589
- type: "string",
590
- format: "binary",
591
- contentEncoding: "binary"
592
- };
593
- const { minimum, maximum, mime } = schema._zod.bag;
594
- if (minimum !== undefined)
595
- file.minLength = minimum;
596
- if (maximum !== undefined)
597
- file.maxLength = maximum;
598
- if (mime) {
599
- if (mime.length === 1) {
600
- file.contentMediaType = mime[0];
601
- Object.assign(_json, file);
602
- } else {
603
- Object.assign(_json, file);
604
- _json.anyOf = mime.map((m) => ({ contentMediaType: m }));
605
- }
606
- } else {
607
- Object.assign(_json, file);
608
- }
609
- };
610
- var successProcessor = (_schema, _ctx, json, _params) => {
611
- json.type = "boolean";
612
- };
613
- var customProcessor = (_schema, ctx, _json, _params) => {
614
- if (ctx.unrepresentable === "throw") {
615
- throw new Error("Custom types cannot be represented in JSON Schema");
616
- }
617
- };
618
- var functionProcessor = (_schema, ctx, _json, _params) => {
619
- if (ctx.unrepresentable === "throw") {
620
- throw new Error("Function types cannot be represented in JSON Schema");
621
- }
622
- };
623
- var transformProcessor = (_schema, ctx, _json, _params) => {
624
- if (ctx.unrepresentable === "throw") {
625
- throw new Error("Transforms cannot be represented in JSON Schema");
626
- }
627
- };
628
- var mapProcessor = (_schema, ctx, _json, _params) => {
629
- if (ctx.unrepresentable === "throw") {
630
- throw new Error("Map cannot be represented in JSON Schema");
631
- }
632
- };
633
- var setProcessor = (_schema, ctx, _json, _params) => {
634
- if (ctx.unrepresentable === "throw") {
635
- throw new Error("Set cannot be represented in JSON Schema");
636
- }
637
- };
638
- var arrayProcessor = (schema, ctx, _json, params) => {
639
- const json = _json;
640
- const def = schema._zod.def;
641
- const { minimum, maximum } = schema._zod.bag;
642
- if (typeof minimum === "number")
643
- json.minItems = minimum;
644
- if (typeof maximum === "number")
645
- json.maxItems = maximum;
646
- json.type = "array";
647
- json.items = process(def.element, ctx, {
648
- ...params,
649
- path: [...params.path, "items"]
650
- });
651
- };
652
- var objectProcessor = (schema, ctx, _json, params) => {
653
- const json = _json;
654
- const def = schema._zod.def;
655
- json.type = "object";
656
- json.properties = {};
657
- const shape = def.shape;
658
- for (const key in shape) {
659
- json.properties[key] = process(shape[key], ctx, {
660
- ...params,
661
- path: [...params.path, "properties", key]
662
- });
663
- }
664
- const allKeys = new Set(Object.keys(shape));
665
- const requiredKeys = new Set([...allKeys].filter((key) => {
666
- const v = def.shape[key]._zod;
667
- if (ctx.io === "input") {
668
- return v.optin === undefined;
669
- } else {
670
- return v.optout === undefined;
671
- }
672
- }));
673
- if (requiredKeys.size > 0) {
674
- json.required = Array.from(requiredKeys);
675
- }
676
- if (def.catchall?._zod.def.type === "never") {
677
- json.additionalProperties = false;
678
- } else if (!def.catchall) {
679
- if (ctx.io === "output")
680
- json.additionalProperties = false;
681
- } else if (def.catchall) {
682
- json.additionalProperties = process(def.catchall, ctx, {
683
- ...params,
684
- path: [...params.path, "additionalProperties"]
685
- });
686
- }
687
- };
688
- var unionProcessor = (schema, ctx, json, params) => {
689
- const def = schema._zod.def;
690
- const isExclusive = def.inclusive === false;
691
- const options = def.options.map((x, i) => process(x, ctx, {
692
- ...params,
693
- path: [...params.path, isExclusive ? "oneOf" : "anyOf", i]
694
- }));
695
- if (isExclusive) {
696
- json.oneOf = options;
697
- } else {
698
- json.anyOf = options;
699
- }
700
- };
701
- var intersectionProcessor = (schema, ctx, json, params) => {
702
- const def = schema._zod.def;
703
- const a = process(def.left, ctx, {
704
- ...params,
705
- path: [...params.path, "allOf", 0]
706
- });
707
- const b = process(def.right, ctx, {
708
- ...params,
709
- path: [...params.path, "allOf", 1]
710
- });
711
- const isSimpleIntersection = (val) => ("allOf" in val) && Object.keys(val).length === 1;
712
- const allOf = [
713
- ...isSimpleIntersection(a) ? a.allOf : [a],
714
- ...isSimpleIntersection(b) ? b.allOf : [b]
715
- ];
716
- json.allOf = allOf;
717
- };
718
- var tupleProcessor = (schema, ctx, _json, params) => {
719
- const json = _json;
720
- const def = schema._zod.def;
721
- json.type = "array";
722
- const prefixPath = ctx.target === "draft-2020-12" ? "prefixItems" : "items";
723
- const restPath = ctx.target === "draft-2020-12" ? "items" : ctx.target === "openapi-3.0" ? "items" : "additionalItems";
724
- const prefixItems = def.items.map((x, i) => process(x, ctx, {
725
- ...params,
726
- path: [...params.path, prefixPath, i]
727
- }));
728
- const rest = def.rest ? process(def.rest, ctx, {
729
- ...params,
730
- path: [...params.path, restPath, ...ctx.target === "openapi-3.0" ? [def.items.length] : []]
731
- }) : null;
732
- if (ctx.target === "draft-2020-12") {
733
- json.prefixItems = prefixItems;
734
- if (rest) {
735
- json.items = rest;
736
- }
737
- } else if (ctx.target === "openapi-3.0") {
738
- json.items = {
739
- anyOf: prefixItems
740
- };
741
- if (rest) {
742
- json.items.anyOf.push(rest);
743
- }
744
- json.minItems = prefixItems.length;
745
- if (!rest) {
746
- json.maxItems = prefixItems.length;
747
- }
748
- } else {
749
- json.items = prefixItems;
750
- if (rest) {
751
- json.additionalItems = rest;
752
- }
753
- }
754
- const { minimum, maximum } = schema._zod.bag;
755
- if (typeof minimum === "number")
756
- json.minItems = minimum;
757
- if (typeof maximum === "number")
758
- json.maxItems = maximum;
759
- };
760
- var recordProcessor = (schema, ctx, _json, params) => {
761
- const json = _json;
762
- const def = schema._zod.def;
763
- json.type = "object";
764
- const keyType = def.keyType;
765
- const keyBag = keyType._zod.bag;
766
- const patterns = keyBag?.patterns;
767
- if (def.mode === "loose" && patterns && patterns.size > 0) {
768
- const valueSchema = process(def.valueType, ctx, {
769
- ...params,
770
- path: [...params.path, "patternProperties", "*"]
771
- });
772
- json.patternProperties = {};
773
- for (const pattern of patterns) {
774
- json.patternProperties[pattern.source] = valueSchema;
775
- }
776
- } else {
777
- if (ctx.target === "draft-07" || ctx.target === "draft-2020-12") {
778
- json.propertyNames = process(def.keyType, ctx, {
779
- ...params,
780
- path: [...params.path, "propertyNames"]
781
- });
782
- }
783
- json.additionalProperties = process(def.valueType, ctx, {
784
- ...params,
785
- path: [...params.path, "additionalProperties"]
786
- });
787
- }
788
- const keyValues = keyType._zod.values;
789
- if (keyValues) {
790
- const validKeyValues = [...keyValues].filter((v) => typeof v === "string" || typeof v === "number");
791
- if (validKeyValues.length > 0) {
792
- json.required = validKeyValues;
793
- }
794
- }
795
- };
796
- var nullableProcessor = (schema, ctx, json, params) => {
797
- const def = schema._zod.def;
798
- const inner = process(def.innerType, ctx, params);
799
- const seen = ctx.seen.get(schema);
800
- if (ctx.target === "openapi-3.0") {
801
- seen.ref = def.innerType;
802
- json.nullable = true;
803
- } else {
804
- json.anyOf = [inner, { type: "null" }];
805
- }
806
- };
807
- var nonoptionalProcessor = (schema, ctx, _json, params) => {
808
- const def = schema._zod.def;
809
- process(def.innerType, ctx, params);
810
- const seen = ctx.seen.get(schema);
811
- seen.ref = def.innerType;
812
- };
813
- var defaultProcessor = (schema, ctx, json, params) => {
814
- const def = schema._zod.def;
815
- process(def.innerType, ctx, params);
816
- const seen = ctx.seen.get(schema);
817
- seen.ref = def.innerType;
818
- json.default = JSON.parse(JSON.stringify(def.defaultValue));
819
- };
820
- var prefaultProcessor = (schema, ctx, json, params) => {
821
- const def = schema._zod.def;
822
- process(def.innerType, ctx, params);
823
- const seen = ctx.seen.get(schema);
824
- seen.ref = def.innerType;
825
- if (ctx.io === "input")
826
- json._prefault = JSON.parse(JSON.stringify(def.defaultValue));
827
- };
828
- var catchProcessor = (schema, ctx, json, params) => {
829
- const def = schema._zod.def;
830
- process(def.innerType, ctx, params);
831
- const seen = ctx.seen.get(schema);
832
- seen.ref = def.innerType;
833
- let catchValue;
834
- try {
835
- catchValue = def.catchValue(undefined);
836
- } catch {
837
- throw new Error("Dynamic catch values are not supported in JSON Schema");
838
- }
839
- json.default = catchValue;
840
- };
841
- var pipeProcessor = (schema, ctx, _json, params) => {
842
- const def = schema._zod.def;
843
- const inIsTransform = def.in._zod.traits.has("$ZodTransform");
844
- const innerType = ctx.io === "input" ? inIsTransform ? def.out : def.in : def.out;
845
- process(innerType, ctx, params);
846
- const seen = ctx.seen.get(schema);
847
- seen.ref = innerType;
848
- };
849
- var readonlyProcessor = (schema, ctx, json, params) => {
850
- const def = schema._zod.def;
851
- process(def.innerType, ctx, params);
852
- const seen = ctx.seen.get(schema);
853
- seen.ref = def.innerType;
854
- json.readOnly = true;
855
- };
856
- var promiseProcessor = (schema, ctx, _json, params) => {
857
- const def = schema._zod.def;
858
- process(def.innerType, ctx, params);
859
- const seen = ctx.seen.get(schema);
860
- seen.ref = def.innerType;
861
- };
862
- var optionalProcessor = (schema, ctx, _json, params) => {
863
- const def = schema._zod.def;
864
- process(def.innerType, ctx, params);
865
- const seen = ctx.seen.get(schema);
866
- seen.ref = def.innerType;
867
- };
868
- var lazyProcessor = (schema, ctx, _json, params) => {
869
- const innerType = schema._zod.innerType;
870
- process(innerType, ctx, params);
871
- const seen = ctx.seen.get(schema);
872
- seen.ref = innerType;
873
- };
874
- var allProcessors = {
875
- string: stringProcessor,
876
- number: numberProcessor,
877
- boolean: booleanProcessor,
878
- bigint: bigintProcessor,
879
- symbol: symbolProcessor,
880
- null: nullProcessor,
881
- undefined: undefinedProcessor,
882
- void: voidProcessor,
883
- never: neverProcessor,
884
- any: anyProcessor,
885
- unknown: unknownProcessor,
886
- date: dateProcessor,
887
- enum: enumProcessor,
888
- literal: literalProcessor,
889
- nan: nanProcessor,
890
- template_literal: templateLiteralProcessor,
891
- file: fileProcessor,
892
- success: successProcessor,
893
- custom: customProcessor,
894
- function: functionProcessor,
895
- transform: transformProcessor,
896
- map: mapProcessor,
897
- set: setProcessor,
898
- array: arrayProcessor,
899
- object: objectProcessor,
900
- union: unionProcessor,
901
- intersection: intersectionProcessor,
902
- tuple: tupleProcessor,
903
- record: recordProcessor,
904
- nullable: nullableProcessor,
905
- nonoptional: nonoptionalProcessor,
906
- default: defaultProcessor,
907
- prefault: prefaultProcessor,
908
- catch: catchProcessor,
909
- pipe: pipeProcessor,
910
- readonly: readonlyProcessor,
911
- promise: promiseProcessor,
912
- optional: optionalProcessor,
913
- lazy: lazyProcessor
914
- };
915
- function toJSONSchema(input, params) {
916
- if ("_idmap" in input) {
917
- const registry2 = input;
918
- const ctx2 = initializeContext({ ...params, processors: allProcessors });
919
- const defs = {};
920
- for (const entry of registry2._idmap.entries()) {
921
- const [_, schema] = entry;
922
- process(schema, ctx2);
923
- }
924
- const schemas = {};
925
- const external = {
926
- registry: registry2,
927
- uri: params?.uri,
928
- defs
929
- };
930
- ctx2.external = external;
931
- for (const entry of registry2._idmap.entries()) {
932
- const [key, schema] = entry;
933
- extractDefs(ctx2, schema);
934
- schemas[key] = finalize(ctx2, schema);
935
- }
936
- if (Object.keys(defs).length > 0) {
937
- const defsSegment = ctx2.target === "draft-2020-12" ? "$defs" : "definitions";
938
- schemas.__shared = {
939
- [defsSegment]: defs
940
- };
941
- }
942
- return { schemas };
943
- }
944
- const ctx = initializeContext({ ...params, processors: allProcessors });
945
- process(input, ctx);
946
- extractDefs(ctx, input);
947
- return finalize(ctx, input);
948
- }
949
- // src/define-step.ts
950
- var UNWRAP_TYPES = new Set(["optional", "nullable", "default"]);
951
- function unwrapZodType(schema) {
952
- while (UNWRAP_TYPES.has(schema._def.type)) {
953
- const inner = schema._def.innerType;
954
- if (!inner)
955
- break;
956
- schema = inner;
957
- }
958
- return schema;
959
- }
960
- function deriveSignalType(schema, path) {
961
- if (!schema)
962
- return "string";
963
- let current = unwrapZodType(schema);
964
- for (const part of path.split(".")) {
965
- if (current._def.type !== "object")
966
- return "string";
967
- const next = current._def.shape?.[part];
968
- if (!next)
969
- return "string";
970
- current = unwrapZodType(next);
971
- }
972
- switch (current._def.type) {
973
- case "string":
974
- return "string";
975
- case "number":
976
- return "number";
977
- case "boolean":
978
- return "boolean";
979
- case "array":
980
- return "array";
981
- case "object":
982
- case "record":
983
- return "object";
984
- default:
985
- return "string";
986
- }
987
- }
988
- function defineStep(config) {
989
- return {
990
- key: config.key,
991
- name: config.name,
992
- description: config.description ?? null,
993
- version: config.version ?? 1,
994
- kind: "user_defined",
995
- status: config.status ?? "active",
996
- prompt: config.prompt ?? null,
997
- inputSchemaJson: config.input ? toJSONSchema(config.input) : null,
998
- resultSchemaJson: config.result ? toJSONSchema(config.result) : null,
999
- signalExtractorDefinitions: (config.signals ?? []).map((s) => ({
1000
- key: s.key ?? s.sourcePath,
1001
- sourcePath: s.sourcePath,
1002
- type: s.type ?? deriveSignalType(config.result, s.sourcePath),
1003
- required: s.required ?? true,
1004
- availableWhenResultStatusIn: s.availableWhenResultStatusIn ?? null
1005
- })),
1006
- computedSignalDefinitions: (config.computedSignals ?? []).map((cs) => ({
1007
- key: cs.key,
1008
- type: cs.type,
1009
- inputSignalKeys: cs.inputSignalKeys,
1010
- configJson: cs.configJson ?? null,
1011
- availableWhenResultStatusIn: cs.availableWhenResultStatusIn ?? null
1012
- })),
1013
- opencodeMcpJson: config.mcpServers ?? null
1014
- };
1015
- }
1016
- export {
1017
- defineStep
1018
- };