@naylence/agent-sdk 0.3.15 → 0.3.16

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.
@@ -5,12 +5,12 @@
5
5
  })(this, (function (exports, runtime, factory, core, node) { 'use strict';
6
6
 
7
7
  // This file is auto-generated during build - do not edit manually
8
- // Generated from package.json version: 0.3.15
8
+ // Generated from package.json version: 0.3.16
9
9
  /**
10
10
  * The package version, injected at build time.
11
11
  * @internal
12
12
  */
13
- const VERSION = '0.3.15';
13
+ const VERSION = '0.3.16';
14
14
 
15
15
  /**
16
16
  * AUTO-GENERATED FILE. DO NOT EDIT DIRECTLY.
@@ -1289,8 +1289,8 @@
1289
1289
 
1290
1290
  const version = {
1291
1291
  major: 4,
1292
- minor: 1,
1293
- patch: 13,
1292
+ minor: 2,
1293
+ patch: 1,
1294
1294
  };
1295
1295
 
1296
1296
  const $ZodType = /*@__PURE__*/ $constructor("$ZodType", (inst, def) => {
@@ -1360,16 +1360,6 @@
1360
1360
  }
1361
1361
  return payload;
1362
1362
  };
1363
- // const handleChecksResult = (
1364
- // checkResult: ParsePayload,
1365
- // originalResult: ParsePayload,
1366
- // ctx: ParseContextInternal
1367
- // ): util.MaybeAsync<ParsePayload> => {
1368
- // // if the checks mutated the value && there are no issues, re-parse the result
1369
- // if (checkResult.value !== originalResult.value && !checkResult.issues.length)
1370
- // return inst._zod.parse(checkResult, ctx);
1371
- // return originalResult;
1372
- // };
1373
1363
  const handleCanaryResult = (canary, payload, ctx) => {
1374
1364
  // abort if the canary is aborted
1375
1365
  if (aborted(canary)) {
@@ -2153,6 +2143,7 @@
2153
2143
  const $ZodDiscriminatedUnion =
2154
2144
  /*@__PURE__*/
2155
2145
  $constructor("$ZodDiscriminatedUnion", (inst, def) => {
2146
+ def.inclusive = false;
2156
2147
  $ZodUnion.init(inst, def);
2157
2148
  const _super = inst._zod.parse;
2158
2149
  defineLazy(inst._zod, "propValues", () => {
@@ -2359,15 +2350,21 @@
2359
2350
  throw new Error("Async schemas not supported in object keys currently");
2360
2351
  }
2361
2352
  if (keyResult.issues.length) {
2362
- payload.issues.push({
2363
- code: "invalid_key",
2364
- origin: "record",
2365
- issues: keyResult.issues.map((iss) => finalizeIssue(iss, ctx, config())),
2366
- input: key,
2367
- path: [key],
2368
- inst,
2369
- });
2370
- payload.value[keyResult.value] = keyResult.value;
2353
+ if (def.mode === "loose") {
2354
+ // Pass through unchanged
2355
+ payload.value[key] = input[key];
2356
+ }
2357
+ else {
2358
+ // Default "strict" behavior: error on invalid key
2359
+ payload.issues.push({
2360
+ code: "invalid_key",
2361
+ origin: "record",
2362
+ issues: keyResult.issues.map((iss) => finalizeIssue(iss, ctx, config())),
2363
+ input: key,
2364
+ path: [key],
2365
+ inst,
2366
+ });
2367
+ }
2371
2368
  continue;
2372
2369
  }
2373
2370
  const result = def.valueType._zod.run({ value: input[key], issues: [] }, ctx);
@@ -3227,6 +3224,723 @@
3227
3224
  return ch;
3228
3225
  }
3229
3226
 
3227
+ // function initializeContext<T extends schemas.$ZodType>(inputs: JSONSchemaGeneratorParams<T>): ToJSONSchemaContext<T> {
3228
+ // return {
3229
+ // processor: inputs.processor,
3230
+ // metadataRegistry: inputs.metadata ?? globalRegistry,
3231
+ // target: inputs.target ?? "draft-2020-12",
3232
+ // unrepresentable: inputs.unrepresentable ?? "throw",
3233
+ // };
3234
+ // }
3235
+ function initializeContext(params) {
3236
+ // Normalize target: convert old non-hyphenated versions to hyphenated versions
3237
+ let target = params?.target ?? "draft-2020-12";
3238
+ if (target === "draft-4")
3239
+ target = "draft-04";
3240
+ if (target === "draft-7")
3241
+ target = "draft-07";
3242
+ return {
3243
+ processors: params.processors ?? {},
3244
+ metadataRegistry: params?.metadata ?? globalRegistry,
3245
+ target,
3246
+ unrepresentable: params?.unrepresentable ?? "throw",
3247
+ override: params?.override ?? (() => { }),
3248
+ io: params?.io ?? "output",
3249
+ counter: 0,
3250
+ seen: new Map(),
3251
+ cycles: params?.cycles ?? "ref",
3252
+ reused: params?.reused ?? "inline",
3253
+ external: params?.external ?? undefined,
3254
+ };
3255
+ }
3256
+ function process$1(schema, ctx, _params = { path: [], schemaPath: [] }) {
3257
+ var _a;
3258
+ const def = schema._zod.def;
3259
+ // check for schema in seens
3260
+ const seen = ctx.seen.get(schema);
3261
+ if (seen) {
3262
+ seen.count++;
3263
+ // check if cycle
3264
+ const isCycle = _params.schemaPath.includes(schema);
3265
+ if (isCycle) {
3266
+ seen.cycle = _params.path;
3267
+ }
3268
+ return seen.schema;
3269
+ }
3270
+ // initialize
3271
+ const result = { schema: {}, count: 1, cycle: undefined, path: _params.path };
3272
+ ctx.seen.set(schema, result);
3273
+ // custom method overrides default behavior
3274
+ const overrideSchema = schema._zod.toJSONSchema?.();
3275
+ if (overrideSchema) {
3276
+ result.schema = overrideSchema;
3277
+ }
3278
+ else {
3279
+ const params = {
3280
+ ..._params,
3281
+ schemaPath: [..._params.schemaPath, schema],
3282
+ path: _params.path,
3283
+ };
3284
+ const parent = schema._zod.parent;
3285
+ if (parent) {
3286
+ // schema was cloned from another schema
3287
+ result.ref = parent;
3288
+ process$1(parent, ctx, params);
3289
+ ctx.seen.get(parent).isParent = true;
3290
+ }
3291
+ else if (schema._zod.processJSONSchema) {
3292
+ schema._zod.processJSONSchema(ctx, result.schema, params);
3293
+ }
3294
+ else {
3295
+ const _json = result.schema;
3296
+ const processor = ctx.processors[def.type];
3297
+ if (!processor) {
3298
+ throw new Error(`[toJSONSchema]: Non-representable type encountered: ${def.type}`);
3299
+ }
3300
+ processor(schema, ctx, _json, params);
3301
+ }
3302
+ }
3303
+ // metadata
3304
+ const meta = ctx.metadataRegistry.get(schema);
3305
+ if (meta)
3306
+ Object.assign(result.schema, meta);
3307
+ if (ctx.io === "input" && isTransforming(schema)) {
3308
+ // examples/defaults only apply to output type of pipe
3309
+ delete result.schema.examples;
3310
+ delete result.schema.default;
3311
+ }
3312
+ // set prefault as default
3313
+ if (ctx.io === "input" && result.schema._prefault)
3314
+ (_a = result.schema).default ?? (_a.default = result.schema._prefault);
3315
+ delete result.schema._prefault;
3316
+ // pulling fresh from ctx.seen in case it was overwritten
3317
+ const _result = ctx.seen.get(schema);
3318
+ return _result.schema;
3319
+ }
3320
+ function extractDefs(ctx, schema
3321
+ // params: EmitParams
3322
+ ) {
3323
+ // iterate over seen map;
3324
+ const root = ctx.seen.get(schema);
3325
+ if (!root)
3326
+ throw new Error("Unprocessed schema. This is a bug in Zod.");
3327
+ // returns a ref to the schema
3328
+ // defId will be empty if the ref points to an external schema (or #)
3329
+ const makeURI = (entry) => {
3330
+ // comparing the seen objects because sometimes
3331
+ // multiple schemas map to the same seen object.
3332
+ // e.g. lazy
3333
+ // external is configured
3334
+ const defsSegment = ctx.target === "draft-2020-12" ? "$defs" : "definitions";
3335
+ if (ctx.external) {
3336
+ const externalId = ctx.external.registry.get(entry[0])?.id; // ?? "__shared";// `__schema${ctx.counter++}`;
3337
+ // check if schema is in the external registry
3338
+ const uriGenerator = ctx.external.uri ?? ((id) => id);
3339
+ if (externalId) {
3340
+ return { ref: uriGenerator(externalId) };
3341
+ }
3342
+ // otherwise, add to __shared
3343
+ const id = entry[1].defId ?? entry[1].schema.id ?? `schema${ctx.counter++}`;
3344
+ entry[1].defId = id; // set defId so it will be reused if needed
3345
+ return { defId: id, ref: `${uriGenerator("__shared")}#/${defsSegment}/${id}` };
3346
+ }
3347
+ if (entry[1] === root) {
3348
+ return { ref: "#" };
3349
+ }
3350
+ // self-contained schema
3351
+ const uriPrefix = `#`;
3352
+ const defUriPrefix = `${uriPrefix}/${defsSegment}/`;
3353
+ const defId = entry[1].schema.id ?? `__schema${ctx.counter++}`;
3354
+ return { defId, ref: defUriPrefix + defId };
3355
+ };
3356
+ // stored cached version in `def` property
3357
+ // remove all properties, set $ref
3358
+ const extractToDef = (entry) => {
3359
+ // if the schema is already a reference, do not extract it
3360
+ if (entry[1].schema.$ref) {
3361
+ return;
3362
+ }
3363
+ const seen = entry[1];
3364
+ const { ref, defId } = makeURI(entry);
3365
+ seen.def = { ...seen.schema };
3366
+ // defId won't be set if the schema is a reference to an external schema
3367
+ // or if the schema is the root schema
3368
+ if (defId)
3369
+ seen.defId = defId;
3370
+ // wipe away all properties except $ref
3371
+ const schema = seen.schema;
3372
+ for (const key in schema) {
3373
+ delete schema[key];
3374
+ }
3375
+ schema.$ref = ref;
3376
+ };
3377
+ // throw on cycles
3378
+ // break cycles
3379
+ if (ctx.cycles === "throw") {
3380
+ for (const entry of ctx.seen.entries()) {
3381
+ const seen = entry[1];
3382
+ if (seen.cycle) {
3383
+ throw new Error("Cycle detected: " +
3384
+ `#/${seen.cycle?.join("/")}/<root>` +
3385
+ '\n\nSet the `cycles` parameter to `"ref"` to resolve cyclical schemas with defs.');
3386
+ }
3387
+ }
3388
+ }
3389
+ // extract schemas into $defs
3390
+ for (const entry of ctx.seen.entries()) {
3391
+ const seen = entry[1];
3392
+ // convert root schema to # $ref
3393
+ if (schema === entry[0]) {
3394
+ extractToDef(entry); // this has special handling for the root schema
3395
+ continue;
3396
+ }
3397
+ // extract schemas that are in the external registry
3398
+ if (ctx.external) {
3399
+ const ext = ctx.external.registry.get(entry[0])?.id;
3400
+ if (schema !== entry[0] && ext) {
3401
+ extractToDef(entry);
3402
+ continue;
3403
+ }
3404
+ }
3405
+ // extract schemas with `id` meta
3406
+ const id = ctx.metadataRegistry.get(entry[0])?.id;
3407
+ if (id) {
3408
+ extractToDef(entry);
3409
+ continue;
3410
+ }
3411
+ // break cycles
3412
+ if (seen.cycle) {
3413
+ // any
3414
+ extractToDef(entry);
3415
+ continue;
3416
+ }
3417
+ // extract reused schemas
3418
+ if (seen.count > 1) {
3419
+ if (ctx.reused === "ref") {
3420
+ extractToDef(entry);
3421
+ // biome-ignore lint:
3422
+ continue;
3423
+ }
3424
+ }
3425
+ }
3426
+ }
3427
+ function finalize(ctx, schema) {
3428
+ //
3429
+ // iterate over seen map;
3430
+ const root = ctx.seen.get(schema);
3431
+ if (!root)
3432
+ throw new Error("Unprocessed schema. This is a bug in Zod.");
3433
+ // flatten _refs
3434
+ const flattenRef = (zodSchema) => {
3435
+ const seen = ctx.seen.get(zodSchema);
3436
+ const schema = seen.def ?? seen.schema;
3437
+ const _cached = { ...schema };
3438
+ // already seen
3439
+ if (seen.ref === null) {
3440
+ return;
3441
+ }
3442
+ // flatten ref if defined
3443
+ const ref = seen.ref;
3444
+ seen.ref = null; // prevent recursion
3445
+ if (ref) {
3446
+ flattenRef(ref);
3447
+ // merge referenced schema into current
3448
+ const refSchema = ctx.seen.get(ref).schema;
3449
+ if (refSchema.$ref && (ctx.target === "draft-07" || ctx.target === "draft-04" || ctx.target === "openapi-3.0")) {
3450
+ schema.allOf = schema.allOf ?? [];
3451
+ schema.allOf.push(refSchema);
3452
+ }
3453
+ else {
3454
+ Object.assign(schema, refSchema);
3455
+ Object.assign(schema, _cached); // prevent overwriting any fields in the original schema
3456
+ }
3457
+ }
3458
+ // execute overrides
3459
+ if (!seen.isParent)
3460
+ ctx.override({
3461
+ zodSchema: zodSchema,
3462
+ jsonSchema: schema,
3463
+ path: seen.path ?? [],
3464
+ });
3465
+ };
3466
+ for (const entry of [...ctx.seen.entries()].reverse()) {
3467
+ flattenRef(entry[0]);
3468
+ }
3469
+ const result = {};
3470
+ if (ctx.target === "draft-2020-12") {
3471
+ result.$schema = "https://json-schema.org/draft/2020-12/schema";
3472
+ }
3473
+ else if (ctx.target === "draft-07") {
3474
+ result.$schema = "http://json-schema.org/draft-07/schema#";
3475
+ }
3476
+ else if (ctx.target === "draft-04") {
3477
+ result.$schema = "http://json-schema.org/draft-04/schema#";
3478
+ }
3479
+ else if (ctx.target === "openapi-3.0") ;
3480
+ else ;
3481
+ if (ctx.external?.uri) {
3482
+ const id = ctx.external.registry.get(schema)?.id;
3483
+ if (!id)
3484
+ throw new Error("Schema is missing an `id` property");
3485
+ result.$id = ctx.external.uri(id);
3486
+ }
3487
+ Object.assign(result, root.def ?? root.schema);
3488
+ // build defs object
3489
+ const defs = ctx.external?.defs ?? {};
3490
+ for (const entry of ctx.seen.entries()) {
3491
+ const seen = entry[1];
3492
+ if (seen.def && seen.defId) {
3493
+ defs[seen.defId] = seen.def;
3494
+ }
3495
+ }
3496
+ // set definitions in result
3497
+ if (ctx.external) ;
3498
+ else {
3499
+ if (Object.keys(defs).length > 0) {
3500
+ if (ctx.target === "draft-2020-12") {
3501
+ result.$defs = defs;
3502
+ }
3503
+ else {
3504
+ result.definitions = defs;
3505
+ }
3506
+ }
3507
+ }
3508
+ try {
3509
+ // this "finalizes" this schema and ensures all cycles are removed
3510
+ // each call to finalize() is functionally independent
3511
+ // though the seen map is shared
3512
+ const finalized = JSON.parse(JSON.stringify(result));
3513
+ Object.defineProperty(finalized, "~standard", {
3514
+ value: {
3515
+ ...schema["~standard"],
3516
+ jsonSchema: {
3517
+ input: createStandardJSONSchemaMethod(schema, "input"),
3518
+ output: createStandardJSONSchemaMethod(schema, "output"),
3519
+ },
3520
+ },
3521
+ enumerable: false,
3522
+ writable: false,
3523
+ });
3524
+ return finalized;
3525
+ }
3526
+ catch (_err) {
3527
+ throw new Error("Error converting schema to JSON.");
3528
+ }
3529
+ }
3530
+ function isTransforming(_schema, _ctx) {
3531
+ const ctx = _ctx ?? { seen: new Set() };
3532
+ if (ctx.seen.has(_schema))
3533
+ return false;
3534
+ ctx.seen.add(_schema);
3535
+ const def = _schema._zod.def;
3536
+ if (def.type === "transform")
3537
+ return true;
3538
+ if (def.type === "array")
3539
+ return isTransforming(def.element, ctx);
3540
+ if (def.type === "set")
3541
+ return isTransforming(def.valueType, ctx);
3542
+ if (def.type === "lazy")
3543
+ return isTransforming(def.getter(), ctx);
3544
+ if (def.type === "promise" ||
3545
+ def.type === "optional" ||
3546
+ def.type === "nonoptional" ||
3547
+ def.type === "nullable" ||
3548
+ def.type === "readonly" ||
3549
+ def.type === "default" ||
3550
+ def.type === "prefault") {
3551
+ return isTransforming(def.innerType, ctx);
3552
+ }
3553
+ if (def.type === "intersection") {
3554
+ return isTransforming(def.left, ctx) || isTransforming(def.right, ctx);
3555
+ }
3556
+ if (def.type === "record" || def.type === "map") {
3557
+ return isTransforming(def.keyType, ctx) || isTransforming(def.valueType, ctx);
3558
+ }
3559
+ if (def.type === "pipe") {
3560
+ return isTransforming(def.in, ctx) || isTransforming(def.out, ctx);
3561
+ }
3562
+ if (def.type === "object") {
3563
+ for (const key in def.shape) {
3564
+ if (isTransforming(def.shape[key], ctx))
3565
+ return true;
3566
+ }
3567
+ return false;
3568
+ }
3569
+ if (def.type === "union") {
3570
+ for (const option of def.options) {
3571
+ if (isTransforming(option, ctx))
3572
+ return true;
3573
+ }
3574
+ return false;
3575
+ }
3576
+ if (def.type === "tuple") {
3577
+ for (const item of def.items) {
3578
+ if (isTransforming(item, ctx))
3579
+ return true;
3580
+ }
3581
+ if (def.rest && isTransforming(def.rest, ctx))
3582
+ return true;
3583
+ return false;
3584
+ }
3585
+ return false;
3586
+ }
3587
+ /**
3588
+ * Creates a toJSONSchema method for a schema instance.
3589
+ * This encapsulates the logic of initializing context, processing, extracting defs, and finalizing.
3590
+ */
3591
+ const createToJSONSchemaMethod = (schema, processors = {}) => (params) => {
3592
+ const ctx = initializeContext({ ...params, processors });
3593
+ process$1(schema, ctx);
3594
+ extractDefs(ctx, schema);
3595
+ return finalize(ctx, schema);
3596
+ };
3597
+ const createStandardJSONSchemaMethod = (schema, io) => (params) => {
3598
+ const { libraryOptions, target } = params ?? {};
3599
+ const ctx = initializeContext({ ...(libraryOptions ?? {}), target, io, processors: {} });
3600
+ process$1(schema, ctx);
3601
+ extractDefs(ctx, schema);
3602
+ return finalize(ctx, schema);
3603
+ };
3604
+
3605
+ const formatMap = {
3606
+ guid: "uuid",
3607
+ url: "uri",
3608
+ datetime: "date-time",
3609
+ json_string: "json-string",
3610
+ regex: "", // do not set
3611
+ };
3612
+ // ==================== SIMPLE TYPE PROCESSORS ====================
3613
+ const stringProcessor = (schema, ctx, _json, _params) => {
3614
+ const json = _json;
3615
+ json.type = "string";
3616
+ const { minimum, maximum, format, patterns, contentEncoding } = schema._zod
3617
+ .bag;
3618
+ if (typeof minimum === "number")
3619
+ json.minLength = minimum;
3620
+ if (typeof maximum === "number")
3621
+ json.maxLength = maximum;
3622
+ // custom pattern overrides format
3623
+ if (format) {
3624
+ json.format = formatMap[format] ?? format;
3625
+ if (json.format === "")
3626
+ delete json.format; // empty format is not valid
3627
+ }
3628
+ if (contentEncoding)
3629
+ json.contentEncoding = contentEncoding;
3630
+ if (patterns && patterns.size > 0) {
3631
+ const regexes = [...patterns];
3632
+ if (regexes.length === 1)
3633
+ json.pattern = regexes[0].source;
3634
+ else if (regexes.length > 1) {
3635
+ json.allOf = [
3636
+ ...regexes.map((regex) => ({
3637
+ ...(ctx.target === "draft-07" || ctx.target === "draft-04" || ctx.target === "openapi-3.0"
3638
+ ? { type: "string" }
3639
+ : {}),
3640
+ pattern: regex.source,
3641
+ })),
3642
+ ];
3643
+ }
3644
+ }
3645
+ };
3646
+ const numberProcessor = (schema, ctx, _json, _params) => {
3647
+ const json = _json;
3648
+ const { minimum, maximum, format, multipleOf, exclusiveMaximum, exclusiveMinimum } = schema._zod.bag;
3649
+ if (typeof format === "string" && format.includes("int"))
3650
+ json.type = "integer";
3651
+ else
3652
+ json.type = "number";
3653
+ if (typeof exclusiveMinimum === "number") {
3654
+ if (ctx.target === "draft-04" || ctx.target === "openapi-3.0") {
3655
+ json.minimum = exclusiveMinimum;
3656
+ json.exclusiveMinimum = true;
3657
+ }
3658
+ else {
3659
+ json.exclusiveMinimum = exclusiveMinimum;
3660
+ }
3661
+ }
3662
+ if (typeof minimum === "number") {
3663
+ json.minimum = minimum;
3664
+ if (typeof exclusiveMinimum === "number" && ctx.target !== "draft-04") {
3665
+ if (exclusiveMinimum >= minimum)
3666
+ delete json.minimum;
3667
+ else
3668
+ delete json.exclusiveMinimum;
3669
+ }
3670
+ }
3671
+ if (typeof exclusiveMaximum === "number") {
3672
+ if (ctx.target === "draft-04" || ctx.target === "openapi-3.0") {
3673
+ json.maximum = exclusiveMaximum;
3674
+ json.exclusiveMaximum = true;
3675
+ }
3676
+ else {
3677
+ json.exclusiveMaximum = exclusiveMaximum;
3678
+ }
3679
+ }
3680
+ if (typeof maximum === "number") {
3681
+ json.maximum = maximum;
3682
+ if (typeof exclusiveMaximum === "number" && ctx.target !== "draft-04") {
3683
+ if (exclusiveMaximum <= maximum)
3684
+ delete json.maximum;
3685
+ else
3686
+ delete json.exclusiveMaximum;
3687
+ }
3688
+ }
3689
+ if (typeof multipleOf === "number")
3690
+ json.multipleOf = multipleOf;
3691
+ };
3692
+ const booleanProcessor = (_schema, _ctx, json, _params) => {
3693
+ json.type = "boolean";
3694
+ };
3695
+ const neverProcessor = (_schema, _ctx, json, _params) => {
3696
+ json.not = {};
3697
+ };
3698
+ const anyProcessor = (_schema, _ctx, _json, _params) => {
3699
+ // empty schema accepts anything
3700
+ };
3701
+ const unknownProcessor = (_schema, _ctx, _json, _params) => {
3702
+ // empty schema accepts anything
3703
+ };
3704
+ const dateProcessor = (_schema, ctx, _json, _params) => {
3705
+ if (ctx.unrepresentable === "throw") {
3706
+ throw new Error("Date cannot be represented in JSON Schema");
3707
+ }
3708
+ };
3709
+ const enumProcessor = (schema, _ctx, json, _params) => {
3710
+ const def = schema._zod.def;
3711
+ const values = getEnumValues(def.entries);
3712
+ // Number enums can have both string and number values
3713
+ if (values.every((v) => typeof v === "number"))
3714
+ json.type = "number";
3715
+ if (values.every((v) => typeof v === "string"))
3716
+ json.type = "string";
3717
+ json.enum = values;
3718
+ };
3719
+ const literalProcessor = (schema, ctx, json, _params) => {
3720
+ const def = schema._zod.def;
3721
+ const vals = [];
3722
+ for (const val of def.values) {
3723
+ if (val === undefined) {
3724
+ if (ctx.unrepresentable === "throw") {
3725
+ throw new Error("Literal `undefined` cannot be represented in JSON Schema");
3726
+ }
3727
+ }
3728
+ else if (typeof val === "bigint") {
3729
+ if (ctx.unrepresentable === "throw") {
3730
+ throw new Error("BigInt literals cannot be represented in JSON Schema");
3731
+ }
3732
+ else {
3733
+ vals.push(Number(val));
3734
+ }
3735
+ }
3736
+ else {
3737
+ vals.push(val);
3738
+ }
3739
+ }
3740
+ if (vals.length === 0) ;
3741
+ else if (vals.length === 1) {
3742
+ const val = vals[0];
3743
+ json.type = val === null ? "null" : typeof val;
3744
+ if (ctx.target === "draft-04" || ctx.target === "openapi-3.0") {
3745
+ json.enum = [val];
3746
+ }
3747
+ else {
3748
+ json.const = val;
3749
+ }
3750
+ }
3751
+ else {
3752
+ if (vals.every((v) => typeof v === "number"))
3753
+ json.type = "number";
3754
+ if (vals.every((v) => typeof v === "string"))
3755
+ json.type = "string";
3756
+ if (vals.every((v) => typeof v === "boolean"))
3757
+ json.type = "boolean";
3758
+ if (vals.every((v) => v === null))
3759
+ json.type = "null";
3760
+ json.enum = vals;
3761
+ }
3762
+ };
3763
+ const customProcessor = (_schema, ctx, _json, _params) => {
3764
+ if (ctx.unrepresentable === "throw") {
3765
+ throw new Error("Custom types cannot be represented in JSON Schema");
3766
+ }
3767
+ };
3768
+ const transformProcessor = (_schema, ctx, _json, _params) => {
3769
+ if (ctx.unrepresentable === "throw") {
3770
+ throw new Error("Transforms cannot be represented in JSON Schema");
3771
+ }
3772
+ };
3773
+ // ==================== COMPOSITE TYPE PROCESSORS ====================
3774
+ const arrayProcessor = (schema, ctx, _json, params) => {
3775
+ const json = _json;
3776
+ const def = schema._zod.def;
3777
+ const { minimum, maximum } = schema._zod.bag;
3778
+ if (typeof minimum === "number")
3779
+ json.minItems = minimum;
3780
+ if (typeof maximum === "number")
3781
+ json.maxItems = maximum;
3782
+ json.type = "array";
3783
+ json.items = process$1(def.element, ctx, { ...params, path: [...params.path, "items"] });
3784
+ };
3785
+ const objectProcessor = (schema, ctx, _json, params) => {
3786
+ const json = _json;
3787
+ const def = schema._zod.def;
3788
+ json.type = "object";
3789
+ json.properties = {};
3790
+ const shape = def.shape;
3791
+ for (const key in shape) {
3792
+ json.properties[key] = process$1(shape[key], ctx, {
3793
+ ...params,
3794
+ path: [...params.path, "properties", key],
3795
+ });
3796
+ }
3797
+ // required keys
3798
+ const allKeys = new Set(Object.keys(shape));
3799
+ const requiredKeys = new Set([...allKeys].filter((key) => {
3800
+ const v = def.shape[key]._zod;
3801
+ if (ctx.io === "input") {
3802
+ return v.optin === undefined;
3803
+ }
3804
+ else {
3805
+ return v.optout === undefined;
3806
+ }
3807
+ }));
3808
+ if (requiredKeys.size > 0) {
3809
+ json.required = Array.from(requiredKeys);
3810
+ }
3811
+ // catchall
3812
+ if (def.catchall?._zod.def.type === "never") {
3813
+ // strict
3814
+ json.additionalProperties = false;
3815
+ }
3816
+ else if (!def.catchall) {
3817
+ // regular
3818
+ if (ctx.io === "output")
3819
+ json.additionalProperties = false;
3820
+ }
3821
+ else if (def.catchall) {
3822
+ json.additionalProperties = process$1(def.catchall, ctx, {
3823
+ ...params,
3824
+ path: [...params.path, "additionalProperties"],
3825
+ });
3826
+ }
3827
+ };
3828
+ const unionProcessor = (schema, ctx, json, params) => {
3829
+ const def = schema._zod.def;
3830
+ // Exclusive unions (inclusive === false) use oneOf (exactly one match) instead of anyOf (one or more matches)
3831
+ // This includes both z.xor() and discriminated unions
3832
+ const isExclusive = def.inclusive === false;
3833
+ const options = def.options.map((x, i) => process$1(x, ctx, {
3834
+ ...params,
3835
+ path: [...params.path, isExclusive ? "oneOf" : "anyOf", i],
3836
+ }));
3837
+ if (isExclusive) {
3838
+ json.oneOf = options;
3839
+ }
3840
+ else {
3841
+ json.anyOf = options;
3842
+ }
3843
+ };
3844
+ const intersectionProcessor = (schema, ctx, json, params) => {
3845
+ const def = schema._zod.def;
3846
+ const a = process$1(def.left, ctx, {
3847
+ ...params,
3848
+ path: [...params.path, "allOf", 0],
3849
+ });
3850
+ const b = process$1(def.right, ctx, {
3851
+ ...params,
3852
+ path: [...params.path, "allOf", 1],
3853
+ });
3854
+ const isSimpleIntersection = (val) => "allOf" in val && Object.keys(val).length === 1;
3855
+ const allOf = [
3856
+ ...(isSimpleIntersection(a) ? a.allOf : [a]),
3857
+ ...(isSimpleIntersection(b) ? b.allOf : [b]),
3858
+ ];
3859
+ json.allOf = allOf;
3860
+ };
3861
+ const recordProcessor = (schema, ctx, _json, params) => {
3862
+ const json = _json;
3863
+ const def = schema._zod.def;
3864
+ json.type = "object";
3865
+ if (ctx.target === "draft-07" || ctx.target === "draft-2020-12") {
3866
+ json.propertyNames = process$1(def.keyType, ctx, {
3867
+ ...params,
3868
+ path: [...params.path, "propertyNames"],
3869
+ });
3870
+ }
3871
+ json.additionalProperties = process$1(def.valueType, ctx, {
3872
+ ...params,
3873
+ path: [...params.path, "additionalProperties"],
3874
+ });
3875
+ };
3876
+ const nullableProcessor = (schema, ctx, json, params) => {
3877
+ const def = schema._zod.def;
3878
+ const inner = process$1(def.innerType, ctx, params);
3879
+ const seen = ctx.seen.get(schema);
3880
+ if (ctx.target === "openapi-3.0") {
3881
+ seen.ref = def.innerType;
3882
+ json.nullable = true;
3883
+ }
3884
+ else {
3885
+ json.anyOf = [inner, { type: "null" }];
3886
+ }
3887
+ };
3888
+ const nonoptionalProcessor = (schema, ctx, _json, params) => {
3889
+ const def = schema._zod.def;
3890
+ process$1(def.innerType, ctx, params);
3891
+ const seen = ctx.seen.get(schema);
3892
+ seen.ref = def.innerType;
3893
+ };
3894
+ const defaultProcessor = (schema, ctx, json, params) => {
3895
+ const def = schema._zod.def;
3896
+ process$1(def.innerType, ctx, params);
3897
+ const seen = ctx.seen.get(schema);
3898
+ seen.ref = def.innerType;
3899
+ json.default = JSON.parse(JSON.stringify(def.defaultValue));
3900
+ };
3901
+ const prefaultProcessor = (schema, ctx, json, params) => {
3902
+ const def = schema._zod.def;
3903
+ process$1(def.innerType, ctx, params);
3904
+ const seen = ctx.seen.get(schema);
3905
+ seen.ref = def.innerType;
3906
+ if (ctx.io === "input")
3907
+ json._prefault = JSON.parse(JSON.stringify(def.defaultValue));
3908
+ };
3909
+ const catchProcessor = (schema, ctx, json, params) => {
3910
+ const def = schema._zod.def;
3911
+ process$1(def.innerType, ctx, params);
3912
+ const seen = ctx.seen.get(schema);
3913
+ seen.ref = def.innerType;
3914
+ let catchValue;
3915
+ try {
3916
+ catchValue = def.catchValue(undefined);
3917
+ }
3918
+ catch {
3919
+ throw new Error("Dynamic catch values are not supported in JSON Schema");
3920
+ }
3921
+ json.default = catchValue;
3922
+ };
3923
+ const pipeProcessor = (schema, ctx, _json, params) => {
3924
+ const def = schema._zod.def;
3925
+ const innerType = ctx.io === "input" ? (def.in._zod.def.type === "transform" ? def.out : def.in) : def.out;
3926
+ process$1(innerType, ctx, params);
3927
+ const seen = ctx.seen.get(schema);
3928
+ seen.ref = innerType;
3929
+ };
3930
+ const readonlyProcessor = (schema, ctx, json, params) => {
3931
+ const def = schema._zod.def;
3932
+ process$1(def.innerType, ctx, params);
3933
+ const seen = ctx.seen.get(schema);
3934
+ seen.ref = def.innerType;
3935
+ json.readOnly = true;
3936
+ };
3937
+ const optionalProcessor = (schema, ctx, _json, params) => {
3938
+ const def = schema._zod.def;
3939
+ process$1(def.innerType, ctx, params);
3940
+ const seen = ctx.seen.get(schema);
3941
+ seen.ref = def.innerType;
3942
+ };
3943
+
3230
3944
  const ZodISODateTime = /*@__PURE__*/ $constructor("ZodISODateTime", (inst, def) => {
3231
3945
  $ZodISODateTime.init(inst, def);
3232
3946
  ZodStringFormat.init(inst, def);
@@ -3318,6 +4032,13 @@
3318
4032
 
3319
4033
  const ZodType = /*@__PURE__*/ $constructor("ZodType", (inst, def) => {
3320
4034
  $ZodType.init(inst, def);
4035
+ Object.assign(inst["~standard"], {
4036
+ jsonSchema: {
4037
+ input: createStandardJSONSchemaMethod(inst, "input"),
4038
+ output: createStandardJSONSchemaMethod(inst, "output"),
4039
+ },
4040
+ });
4041
+ inst.toJSONSchema = createToJSONSchemaMethod(inst, {});
3321
4042
  inst.def = def;
3322
4043
  inst.type = def.type;
3323
4044
  Object.defineProperty(inst, "_def", { value: def });
@@ -3399,6 +4120,7 @@
3399
4120
  const _ZodString = /*@__PURE__*/ $constructor("_ZodString", (inst, def) => {
3400
4121
  $ZodString.init(inst, def);
3401
4122
  ZodType.init(inst, def);
4123
+ inst._zod.processJSONSchema = (ctx, json, params) => stringProcessor(inst, ctx, json);
3402
4124
  const bag = inst._zod.bag;
3403
4125
  inst.format = bag.format ?? null;
3404
4126
  inst.minLength = bag.minimum ?? null;
@@ -3556,6 +4278,7 @@
3556
4278
  const ZodNumber = /*@__PURE__*/ $constructor("ZodNumber", (inst, def) => {
3557
4279
  $ZodNumber.init(inst, def);
3558
4280
  ZodType.init(inst, def);
4281
+ inst._zod.processJSONSchema = (ctx, json, params) => numberProcessor(inst, ctx, json);
3559
4282
  inst.gt = (value, params) => inst.check(_gt(value, params));
3560
4283
  inst.gte = (value, params) => inst.check(_gte(value, params));
3561
4284
  inst.min = (value, params) => inst.check(_gte(value, params));
@@ -3594,6 +4317,7 @@
3594
4317
  const ZodBoolean = /*@__PURE__*/ $constructor("ZodBoolean", (inst, def) => {
3595
4318
  $ZodBoolean.init(inst, def);
3596
4319
  ZodType.init(inst, def);
4320
+ inst._zod.processJSONSchema = (ctx, json, params) => booleanProcessor(inst, ctx, json);
3597
4321
  });
3598
4322
  function boolean(params) {
3599
4323
  return _boolean(ZodBoolean, params);
@@ -3601,6 +4325,7 @@
3601
4325
  const ZodAny = /*@__PURE__*/ $constructor("ZodAny", (inst, def) => {
3602
4326
  $ZodAny.init(inst, def);
3603
4327
  ZodType.init(inst, def);
4328
+ inst._zod.processJSONSchema = (ctx, json, params) => anyProcessor();
3604
4329
  });
3605
4330
  function any() {
3606
4331
  return _any(ZodAny);
@@ -3608,6 +4333,7 @@
3608
4333
  const ZodUnknown = /*@__PURE__*/ $constructor("ZodUnknown", (inst, def) => {
3609
4334
  $ZodUnknown.init(inst, def);
3610
4335
  ZodType.init(inst, def);
4336
+ inst._zod.processJSONSchema = (ctx, json, params) => unknownProcessor();
3611
4337
  });
3612
4338
  function unknown() {
3613
4339
  return _unknown(ZodUnknown);
@@ -3615,6 +4341,7 @@
3615
4341
  const ZodNever = /*@__PURE__*/ $constructor("ZodNever", (inst, def) => {
3616
4342
  $ZodNever.init(inst, def);
3617
4343
  ZodType.init(inst, def);
4344
+ inst._zod.processJSONSchema = (ctx, json, params) => neverProcessor(inst, ctx, json);
3618
4345
  });
3619
4346
  function never(params) {
3620
4347
  return _never(ZodNever, params);
@@ -3622,6 +4349,7 @@
3622
4349
  const ZodDate = /*@__PURE__*/ $constructor("ZodDate", (inst, def) => {
3623
4350
  $ZodDate.init(inst, def);
3624
4351
  ZodType.init(inst, def);
4352
+ inst._zod.processJSONSchema = (ctx, json, params) => dateProcessor(inst, ctx);
3625
4353
  inst.min = (value, params) => inst.check(_gte(value, params));
3626
4354
  inst.max = (value, params) => inst.check(_lte(value, params));
3627
4355
  const c = inst._zod.bag;
@@ -3634,6 +4362,7 @@
3634
4362
  const ZodArray = /*@__PURE__*/ $constructor("ZodArray", (inst, def) => {
3635
4363
  $ZodArray.init(inst, def);
3636
4364
  ZodType.init(inst, def);
4365
+ inst._zod.processJSONSchema = (ctx, json, params) => arrayProcessor(inst, ctx, json, params);
3637
4366
  inst.element = def.element;
3638
4367
  inst.min = (minLength, params) => inst.check(_minLength(minLength, params));
3639
4368
  inst.nonempty = (params) => inst.check(_minLength(1, params));
@@ -3647,6 +4376,7 @@
3647
4376
  const ZodObject = /*@__PURE__*/ $constructor("ZodObject", (inst, def) => {
3648
4377
  $ZodObjectJIT.init(inst, def);
3649
4378
  ZodType.init(inst, def);
4379
+ inst._zod.processJSONSchema = (ctx, json, params) => objectProcessor(inst, ctx, json, params);
3650
4380
  defineLazy(inst, "shape", () => {
3651
4381
  return def.shape;
3652
4382
  });
@@ -3679,6 +4409,7 @@
3679
4409
  const ZodUnion = /*@__PURE__*/ $constructor("ZodUnion", (inst, def) => {
3680
4410
  $ZodUnion.init(inst, def);
3681
4411
  ZodType.init(inst, def);
4412
+ inst._zod.processJSONSchema = (ctx, json, params) => unionProcessor(inst, ctx, json, params);
3682
4413
  inst.options = def.options;
3683
4414
  });
3684
4415
  function union(options, params) {
@@ -3704,6 +4435,7 @@
3704
4435
  const ZodIntersection = /*@__PURE__*/ $constructor("ZodIntersection", (inst, def) => {
3705
4436
  $ZodIntersection.init(inst, def);
3706
4437
  ZodType.init(inst, def);
4438
+ inst._zod.processJSONSchema = (ctx, json, params) => intersectionProcessor(inst, ctx, json, params);
3707
4439
  });
3708
4440
  function intersection(left, right) {
3709
4441
  return new ZodIntersection({
@@ -3715,6 +4447,7 @@
3715
4447
  const ZodRecord = /*@__PURE__*/ $constructor("ZodRecord", (inst, def) => {
3716
4448
  $ZodRecord.init(inst, def);
3717
4449
  ZodType.init(inst, def);
4450
+ inst._zod.processJSONSchema = (ctx, json, params) => recordProcessor(inst, ctx, json, params);
3718
4451
  inst.keyType = def.keyType;
3719
4452
  inst.valueType = def.valueType;
3720
4453
  });
@@ -3729,6 +4462,7 @@
3729
4462
  const ZodEnum = /*@__PURE__*/ $constructor("ZodEnum", (inst, def) => {
3730
4463
  $ZodEnum.init(inst, def);
3731
4464
  ZodType.init(inst, def);
4465
+ inst._zod.processJSONSchema = (ctx, json, params) => enumProcessor(inst, ctx, json);
3732
4466
  inst.enum = def.entries;
3733
4467
  inst.options = Object.values(def.entries);
3734
4468
  const keys = new Set(Object.keys(def.entries));
@@ -3790,6 +4524,7 @@
3790
4524
  const ZodLiteral = /*@__PURE__*/ $constructor("ZodLiteral", (inst, def) => {
3791
4525
  $ZodLiteral.init(inst, def);
3792
4526
  ZodType.init(inst, def);
4527
+ inst._zod.processJSONSchema = (ctx, json, params) => literalProcessor(inst, ctx, json);
3793
4528
  inst.values = new Set(def.values);
3794
4529
  Object.defineProperty(inst, "value", {
3795
4530
  get() {
@@ -3810,6 +4545,7 @@
3810
4545
  const ZodTransform = /*@__PURE__*/ $constructor("ZodTransform", (inst, def) => {
3811
4546
  $ZodTransform.init(inst, def);
3812
4547
  ZodType.init(inst, def);
4548
+ inst._zod.processJSONSchema = (ctx, json, params) => transformProcessor(inst, ctx);
3813
4549
  inst._zod.parse = (payload, _ctx) => {
3814
4550
  if (_ctx.direction === "backward") {
3815
4551
  throw new $ZodEncodeError(inst.constructor.name);
@@ -3850,6 +4586,7 @@
3850
4586
  const ZodOptional = /*@__PURE__*/ $constructor("ZodOptional", (inst, def) => {
3851
4587
  $ZodOptional.init(inst, def);
3852
4588
  ZodType.init(inst, def);
4589
+ inst._zod.processJSONSchema = (ctx, json, params) => optionalProcessor(inst, ctx, json, params);
3853
4590
  inst.unwrap = () => inst._zod.def.innerType;
3854
4591
  });
3855
4592
  function optional(innerType) {
@@ -3861,6 +4598,7 @@
3861
4598
  const ZodNullable = /*@__PURE__*/ $constructor("ZodNullable", (inst, def) => {
3862
4599
  $ZodNullable.init(inst, def);
3863
4600
  ZodType.init(inst, def);
4601
+ inst._zod.processJSONSchema = (ctx, json, params) => nullableProcessor(inst, ctx, json, params);
3864
4602
  inst.unwrap = () => inst._zod.def.innerType;
3865
4603
  });
3866
4604
  function nullable(innerType) {
@@ -3872,6 +4610,7 @@
3872
4610
  const ZodDefault = /*@__PURE__*/ $constructor("ZodDefault", (inst, def) => {
3873
4611
  $ZodDefault.init(inst, def);
3874
4612
  ZodType.init(inst, def);
4613
+ inst._zod.processJSONSchema = (ctx, json, params) => defaultProcessor(inst, ctx, json, params);
3875
4614
  inst.unwrap = () => inst._zod.def.innerType;
3876
4615
  inst.removeDefault = inst.unwrap;
3877
4616
  });
@@ -3887,6 +4626,7 @@
3887
4626
  const ZodPrefault = /*@__PURE__*/ $constructor("ZodPrefault", (inst, def) => {
3888
4627
  $ZodPrefault.init(inst, def);
3889
4628
  ZodType.init(inst, def);
4629
+ inst._zod.processJSONSchema = (ctx, json, params) => prefaultProcessor(inst, ctx, json, params);
3890
4630
  inst.unwrap = () => inst._zod.def.innerType;
3891
4631
  });
3892
4632
  function prefault(innerType, defaultValue) {
@@ -3901,6 +4641,7 @@
3901
4641
  const ZodNonOptional = /*@__PURE__*/ $constructor("ZodNonOptional", (inst, def) => {
3902
4642
  $ZodNonOptional.init(inst, def);
3903
4643
  ZodType.init(inst, def);
4644
+ inst._zod.processJSONSchema = (ctx, json, params) => nonoptionalProcessor(inst, ctx, json, params);
3904
4645
  inst.unwrap = () => inst._zod.def.innerType;
3905
4646
  });
3906
4647
  function nonoptional(innerType, params) {
@@ -3913,6 +4654,7 @@
3913
4654
  const ZodCatch = /*@__PURE__*/ $constructor("ZodCatch", (inst, def) => {
3914
4655
  $ZodCatch.init(inst, def);
3915
4656
  ZodType.init(inst, def);
4657
+ inst._zod.processJSONSchema = (ctx, json, params) => catchProcessor(inst, ctx, json, params);
3916
4658
  inst.unwrap = () => inst._zod.def.innerType;
3917
4659
  inst.removeCatch = inst.unwrap;
3918
4660
  });
@@ -3926,6 +4668,7 @@
3926
4668
  const ZodPipe = /*@__PURE__*/ $constructor("ZodPipe", (inst, def) => {
3927
4669
  $ZodPipe.init(inst, def);
3928
4670
  ZodType.init(inst, def);
4671
+ inst._zod.processJSONSchema = (ctx, json, params) => pipeProcessor(inst, ctx, json, params);
3929
4672
  inst.in = def.in;
3930
4673
  inst.out = def.out;
3931
4674
  });
@@ -3940,6 +4683,7 @@
3940
4683
  const ZodReadonly = /*@__PURE__*/ $constructor("ZodReadonly", (inst, def) => {
3941
4684
  $ZodReadonly.init(inst, def);
3942
4685
  ZodType.init(inst, def);
4686
+ inst._zod.processJSONSchema = (ctx, json, params) => readonlyProcessor(inst, ctx, json, params);
3943
4687
  inst.unwrap = () => inst._zod.def.innerType;
3944
4688
  });
3945
4689
  function readonly(innerType) {
@@ -3951,6 +4695,7 @@
3951
4695
  const ZodCustom = /*@__PURE__*/ $constructor("ZodCustom", (inst, def) => {
3952
4696
  $ZodCustom.init(inst, def);
3953
4697
  ZodType.init(inst, def);
4698
+ inst._zod.processJSONSchema = (ctx, json, params) => customProcessor(inst, ctx);
3954
4699
  });
3955
4700
  function refine(fn, _params = {}) {
3956
4701
  return _refine(ZodCustom, fn, _params);
@@ -6966,10 +7711,17 @@
6966
7711
  {
6967
7712
  type: 'HttpListener',
6968
7713
  port: SENTINEL_PORT,
7714
+ enabled: '${env:FAME_LISTENER_HTTP_ENABLED:true}',
6969
7715
  },
6970
7716
  {
6971
7717
  type: 'WebSocketListener',
6972
7718
  port: SENTINEL_PORT,
7719
+ enabled: '${env:FAME_LISTENER_WEBSOCKET_ENABLED:true}',
7720
+ },
7721
+ {
7722
+ type: 'AgentHttpGatewayListener',
7723
+ port: SENTINEL_PORT,
7724
+ enabled: '${env:FAME_LISTENER_AGENT_HTTP_GATEWAY_ENABLED:false}',
6973
7725
  },
6974
7726
  ],
6975
7727
  requested_logicals: ['fame.fabric'],