@elevasis/sdk 0.2.0 → 0.3.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.
- package/dist/cli.cjs +40895 -0
- package/dist/index.d.ts +403 -1
- package/dist/index.js +3413 -1
- package/dist/server/index.js +174 -0
- package/package.json +29 -10
package/dist/index.js
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
4
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
5
|
+
}) : x)(function(x) {
|
|
6
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
7
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
8
|
+
});
|
|
9
|
+
|
|
1
10
|
// src/runtime.ts
|
|
2
11
|
var StepType = /* @__PURE__ */ ((StepType2) => {
|
|
3
12
|
StepType2["LINEAR"] = "linear";
|
|
@@ -30,4 +39,3407 @@ var ToolingError = class extends ExecutionError {
|
|
|
30
39
|
}
|
|
31
40
|
};
|
|
32
41
|
|
|
33
|
-
|
|
42
|
+
// ../core/src/platform/registry/domains.ts
|
|
43
|
+
var DOMAINS = {
|
|
44
|
+
// Business domains
|
|
45
|
+
ACQUISITION: "acquisition",
|
|
46
|
+
SUPPORT: "support",
|
|
47
|
+
DELIVERY: "delivery",
|
|
48
|
+
OPERATIONS: "operations",
|
|
49
|
+
FINANCE: "finance",
|
|
50
|
+
EXECUTIVE: "executive",
|
|
51
|
+
// Technical domains
|
|
52
|
+
TESTING: "testing",
|
|
53
|
+
INTERNAL: "internal",
|
|
54
|
+
INTEGRATION: "integration",
|
|
55
|
+
UTILITY: "utility",
|
|
56
|
+
DIAGNOSTIC: "diagnostic"
|
|
57
|
+
};
|
|
58
|
+
var ACQUISITION_DOMAIN = {
|
|
59
|
+
id: DOMAINS.ACQUISITION,
|
|
60
|
+
name: "Client Acquisition",
|
|
61
|
+
description: "Client acquisition pipeline and lead database management",
|
|
62
|
+
color: "blue"
|
|
63
|
+
};
|
|
64
|
+
var SUPPORT_DOMAIN = {
|
|
65
|
+
id: DOMAINS.SUPPORT,
|
|
66
|
+
name: "Customer Support",
|
|
67
|
+
description: "Ticket triage, knowledge base, escalations",
|
|
68
|
+
color: "green"
|
|
69
|
+
};
|
|
70
|
+
var DELIVERY_DOMAIN = {
|
|
71
|
+
id: DOMAINS.DELIVERY,
|
|
72
|
+
name: "Client Delivery",
|
|
73
|
+
description: "Project execution and milestone tracking",
|
|
74
|
+
color: "orange"
|
|
75
|
+
};
|
|
76
|
+
var OPERATIONS_DOMAIN = {
|
|
77
|
+
id: DOMAINS.OPERATIONS,
|
|
78
|
+
name: "Operations",
|
|
79
|
+
description: "Internal business operations and administration",
|
|
80
|
+
color: "violet"
|
|
81
|
+
};
|
|
82
|
+
var FINANCE_DOMAIN = {
|
|
83
|
+
id: DOMAINS.FINANCE,
|
|
84
|
+
name: "Finance",
|
|
85
|
+
description: "Billing, invoicing, and financial operations",
|
|
86
|
+
color: "pink"
|
|
87
|
+
};
|
|
88
|
+
var EXECUTIVE_DOMAIN = {
|
|
89
|
+
id: DOMAINS.EXECUTIVE,
|
|
90
|
+
name: "Executive Operations",
|
|
91
|
+
description: "High-level business orchestration and decision-making",
|
|
92
|
+
color: "indigo"
|
|
93
|
+
};
|
|
94
|
+
var TESTING_DOMAIN = {
|
|
95
|
+
id: DOMAINS.TESTING,
|
|
96
|
+
name: "Testing",
|
|
97
|
+
description: "Test resources and development workflows",
|
|
98
|
+
color: "gray"
|
|
99
|
+
};
|
|
100
|
+
var INTERNAL_DOMAIN = {
|
|
101
|
+
id: DOMAINS.INTERNAL,
|
|
102
|
+
name: "Internal",
|
|
103
|
+
description: "Internal platform resources",
|
|
104
|
+
color: "dark"
|
|
105
|
+
};
|
|
106
|
+
var INTEGRATION_DOMAIN = {
|
|
107
|
+
id: DOMAINS.INTEGRATION,
|
|
108
|
+
name: "Integration",
|
|
109
|
+
description: "External service integrations",
|
|
110
|
+
color: "teal"
|
|
111
|
+
};
|
|
112
|
+
var UTILITY_DOMAIN = {
|
|
113
|
+
id: DOMAINS.UTILITY,
|
|
114
|
+
name: "Utility",
|
|
115
|
+
description: "Utility workflows for maintenance and diagnostics",
|
|
116
|
+
color: "grape"
|
|
117
|
+
};
|
|
118
|
+
var DIAGNOSTIC_DOMAIN = {
|
|
119
|
+
id: DOMAINS.DIAGNOSTIC,
|
|
120
|
+
name: "Diagnostic",
|
|
121
|
+
description: "Diagnostic workflows for testing integrations and services",
|
|
122
|
+
color: "yellow"
|
|
123
|
+
};
|
|
124
|
+
var DOMAIN_MAP = {
|
|
125
|
+
[DOMAINS.ACQUISITION]: ACQUISITION_DOMAIN,
|
|
126
|
+
[DOMAINS.SUPPORT]: SUPPORT_DOMAIN,
|
|
127
|
+
[DOMAINS.DELIVERY]: DELIVERY_DOMAIN,
|
|
128
|
+
[DOMAINS.OPERATIONS]: OPERATIONS_DOMAIN,
|
|
129
|
+
[DOMAINS.FINANCE]: FINANCE_DOMAIN,
|
|
130
|
+
[DOMAINS.EXECUTIVE]: EXECUTIVE_DOMAIN,
|
|
131
|
+
[DOMAINS.TESTING]: TESTING_DOMAIN,
|
|
132
|
+
[DOMAINS.INTERNAL]: INTERNAL_DOMAIN,
|
|
133
|
+
[DOMAINS.INTEGRATION]: INTEGRATION_DOMAIN,
|
|
134
|
+
[DOMAINS.UTILITY]: UTILITY_DOMAIN,
|
|
135
|
+
[DOMAINS.DIAGNOSTIC]: DIAGNOSTIC_DOMAIN
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
// ../core/src/execution/core/server/environment.ts
|
|
139
|
+
function detectEnvironment() {
|
|
140
|
+
const env = process.env.NODE_ENV || "development";
|
|
141
|
+
if (env === "production") return "production";
|
|
142
|
+
if (env === "staging") return "staging";
|
|
143
|
+
return "development";
|
|
144
|
+
}
|
|
145
|
+
function canExecuteResource(resource, environment) {
|
|
146
|
+
const env = environment || detectEnvironment();
|
|
147
|
+
return env === "production" ? resource.status === "prod" : true;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// ../core/src/execution/engine/base/errors.ts
|
|
151
|
+
var ExecutionError2 = class extends Error {
|
|
152
|
+
/**
|
|
153
|
+
* Additional context/metadata for the error.
|
|
154
|
+
* Stored in execution_errors.metadata JSONB column.
|
|
155
|
+
*/
|
|
156
|
+
context;
|
|
157
|
+
/**
|
|
158
|
+
* @param message - Human-readable error message
|
|
159
|
+
* @param context - Additional context/metadata for observability
|
|
160
|
+
*/
|
|
161
|
+
constructor(message, context) {
|
|
162
|
+
super(message);
|
|
163
|
+
this.name = this.constructor.name;
|
|
164
|
+
this.context = context;
|
|
165
|
+
if (Error.captureStackTrace) {
|
|
166
|
+
Error.captureStackTrace(this, this.constructor);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Indicates whether this error type is retryable.
|
|
171
|
+
* Default: false (safe default - only retry when explicitly safe to do so)
|
|
172
|
+
*
|
|
173
|
+
* Subclasses should override to return true for retryable scenarios:
|
|
174
|
+
* - Network/infrastructure errors (exponential backoff)
|
|
175
|
+
* - Rate limiting (linear backoff)
|
|
176
|
+
* - Service availability (exponential backoff)
|
|
177
|
+
* - Circuit breaker (circuit breaker's own delay)
|
|
178
|
+
*
|
|
179
|
+
* DO NOT retry:
|
|
180
|
+
* - Authentication/authorization errors
|
|
181
|
+
* - Validation errors
|
|
182
|
+
* - Configuration errors
|
|
183
|
+
* - Resource exhaustion errors
|
|
184
|
+
*/
|
|
185
|
+
isRetryable() {
|
|
186
|
+
return false;
|
|
187
|
+
}
|
|
188
|
+
};
|
|
189
|
+
var GPT5OptionsSchema = z.object({
|
|
190
|
+
reasoning_effort: z.enum(["minimal", "low", "medium", "high"]).optional(),
|
|
191
|
+
verbosity: z.enum(["low", "medium", "high"]).optional()
|
|
192
|
+
});
|
|
193
|
+
var GPT5ConfigSchema = z.object({
|
|
194
|
+
model: z.enum(["gpt-5", "gpt-5-mini"]),
|
|
195
|
+
provider: z.enum(["openai"]),
|
|
196
|
+
apiKey: z.string().min(1),
|
|
197
|
+
temperature: z.literal(1),
|
|
198
|
+
// Required to be exactly 1
|
|
199
|
+
maxTokens: z.number().min(4e3).optional(),
|
|
200
|
+
topP: z.number().min(0).max(1).optional(),
|
|
201
|
+
modelOptions: GPT5OptionsSchema.optional()
|
|
202
|
+
});
|
|
203
|
+
var MockConfigSchema = z.object({
|
|
204
|
+
model: z.enum(["mock"]),
|
|
205
|
+
provider: z.enum(["mock"]),
|
|
206
|
+
apiKey: z.string(),
|
|
207
|
+
temperature: z.number().min(0).max(2).optional(),
|
|
208
|
+
maxTokens: z.number().min(500).optional(),
|
|
209
|
+
topP: z.number().min(0).max(1).optional(),
|
|
210
|
+
modelOptions: z.object({}).strict().optional()
|
|
211
|
+
// No options supported
|
|
212
|
+
});
|
|
213
|
+
var OpenRouterOptionsSchema = z.object({
|
|
214
|
+
/** Optional transforms to apply (e.g., 'middle-out' for long context) */
|
|
215
|
+
transforms: z.array(z.string()).optional(),
|
|
216
|
+
/** Routing strategy (e.g., 'fallback' for automatic provider failover) */
|
|
217
|
+
route: z.enum(["fallback"]).optional()
|
|
218
|
+
});
|
|
219
|
+
var OpenRouterConfigSchema = z.object({
|
|
220
|
+
model: z.enum([
|
|
221
|
+
"openrouter/anthropic/claude-sonnet-4.5",
|
|
222
|
+
"openrouter/deepseek/deepseek-v3.2",
|
|
223
|
+
"openrouter/x-ai/grok-4.1-fast"
|
|
224
|
+
]),
|
|
225
|
+
provider: z.literal("openrouter"),
|
|
226
|
+
apiKey: z.string().min(1),
|
|
227
|
+
temperature: z.number().min(0).max(2).optional(),
|
|
228
|
+
maxTokens: z.number().min(500).optional(),
|
|
229
|
+
topP: z.number().min(0).max(1).optional(),
|
|
230
|
+
modelOptions: OpenRouterOptionsSchema.optional()
|
|
231
|
+
});
|
|
232
|
+
var GoogleOptionsSchema = z.object({
|
|
233
|
+
/** Thinking level for Gemini 3 models (controls reasoning depth) */
|
|
234
|
+
thinkingLevel: z.enum(["minimal", "low", "medium", "high"]).optional()
|
|
235
|
+
});
|
|
236
|
+
var GoogleConfigSchema = z.object({
|
|
237
|
+
model: z.enum(["gemini-3-flash-preview"]),
|
|
238
|
+
provider: z.literal("google"),
|
|
239
|
+
apiKey: z.string().min(1),
|
|
240
|
+
temperature: z.literal(1).optional(),
|
|
241
|
+
// Must be 1 for Gemini 3 (changing degrades performance)
|
|
242
|
+
maxTokens: z.number().min(500).optional(),
|
|
243
|
+
topP: z.number().min(0).max(1).optional(),
|
|
244
|
+
modelOptions: GoogleOptionsSchema.optional()
|
|
245
|
+
});
|
|
246
|
+
var AnthropicOptionsSchema = z.object({});
|
|
247
|
+
var AnthropicConfigSchema = z.object({
|
|
248
|
+
model: z.enum(["claude-opus-4-5", "claude-sonnet-4-5", "claude-haiku-4-5"]),
|
|
249
|
+
provider: z.literal("anthropic"),
|
|
250
|
+
apiKey: z.string().min(1),
|
|
251
|
+
temperature: z.number().min(0).max(1).optional(),
|
|
252
|
+
maxTokens: z.number().min(1e3).optional(),
|
|
253
|
+
// Anthropic requires max_tokens
|
|
254
|
+
topP: z.number().min(0).max(1).optional(),
|
|
255
|
+
modelOptions: AnthropicOptionsSchema.optional()
|
|
256
|
+
});
|
|
257
|
+
var MODEL_INFO = {
|
|
258
|
+
// OpenAI GPT-5 (Reasoning Models)
|
|
259
|
+
"gpt-5": {
|
|
260
|
+
inputCostPer1M: 125,
|
|
261
|
+
// $1.25 per 1M tokens
|
|
262
|
+
outputCostPer1M: 1e3,
|
|
263
|
+
// $10.00 per 1M tokens
|
|
264
|
+
minTokens: 4e3,
|
|
265
|
+
// Reasoning models need more
|
|
266
|
+
recommendedTokens: 8e3,
|
|
267
|
+
maxTokens: 4e5,
|
|
268
|
+
// 128k context window
|
|
269
|
+
category: "reasoning",
|
|
270
|
+
configSchema: GPT5ConfigSchema
|
|
271
|
+
},
|
|
272
|
+
"gpt-5-mini": {
|
|
273
|
+
inputCostPer1M: 25,
|
|
274
|
+
// $0.25 per 1M tokens
|
|
275
|
+
outputCostPer1M: 200,
|
|
276
|
+
// $2.00 per 1M tokens
|
|
277
|
+
minTokens: 4e3,
|
|
278
|
+
// Reasoning models need more
|
|
279
|
+
recommendedTokens: 8e3,
|
|
280
|
+
maxTokens: 4e5,
|
|
281
|
+
// 128k context window
|
|
282
|
+
category: "reasoning",
|
|
283
|
+
configSchema: GPT5ConfigSchema
|
|
284
|
+
// Same schema as gpt-5
|
|
285
|
+
},
|
|
286
|
+
// Mock model for testing
|
|
287
|
+
mock: {
|
|
288
|
+
inputCostPer1M: 0,
|
|
289
|
+
// Free for tests
|
|
290
|
+
outputCostPer1M: 0,
|
|
291
|
+
minTokens: 500,
|
|
292
|
+
// Low minimum for test flexibility
|
|
293
|
+
recommendedTokens: 1e3,
|
|
294
|
+
maxTokens: 1e5,
|
|
295
|
+
// 100k for testing
|
|
296
|
+
category: "standard",
|
|
297
|
+
configSchema: MockConfigSchema
|
|
298
|
+
},
|
|
299
|
+
// OpenRouter Models (via openrouter.ai)
|
|
300
|
+
"openrouter/anthropic/claude-sonnet-4.5": {
|
|
301
|
+
inputCostPer1M: 300,
|
|
302
|
+
// $3.00 per 1M tokens
|
|
303
|
+
outputCostPer1M: 1500,
|
|
304
|
+
// $15.00 per 1M tokens
|
|
305
|
+
minTokens: 4e3,
|
|
306
|
+
recommendedTokens: 4e3,
|
|
307
|
+
maxTokens: 2e5,
|
|
308
|
+
// 200k context window
|
|
309
|
+
category: "standard",
|
|
310
|
+
configSchema: OpenRouterConfigSchema
|
|
311
|
+
},
|
|
312
|
+
"openrouter/deepseek/deepseek-v3.2": {
|
|
313
|
+
inputCostPer1M: 26,
|
|
314
|
+
// $0.26 per 1M tokens
|
|
315
|
+
outputCostPer1M: 39,
|
|
316
|
+
// $0.39 per 1M tokens
|
|
317
|
+
minTokens: 4e3,
|
|
318
|
+
recommendedTokens: 4e3,
|
|
319
|
+
maxTokens: 163840,
|
|
320
|
+
// 163,840 context window
|
|
321
|
+
category: "reasoning",
|
|
322
|
+
configSchema: OpenRouterConfigSchema
|
|
323
|
+
},
|
|
324
|
+
"openrouter/x-ai/grok-4.1-fast": {
|
|
325
|
+
inputCostPer1M: 20,
|
|
326
|
+
// $0.20 per 1M tokens
|
|
327
|
+
outputCostPer1M: 50,
|
|
328
|
+
// $0.50 per 1M tokens
|
|
329
|
+
minTokens: 4e3,
|
|
330
|
+
recommendedTokens: 4e3,
|
|
331
|
+
maxTokens: 2e6,
|
|
332
|
+
// 2M context window
|
|
333
|
+
category: "standard",
|
|
334
|
+
configSchema: OpenRouterConfigSchema
|
|
335
|
+
},
|
|
336
|
+
// Google Gemini Models (direct SDK access via @google/genai)
|
|
337
|
+
"gemini-3-flash-preview": {
|
|
338
|
+
inputCostPer1M: 50,
|
|
339
|
+
// $0.50 per 1M tokens
|
|
340
|
+
outputCostPer1M: 300,
|
|
341
|
+
// $3.00 per 1M tokens
|
|
342
|
+
minTokens: 4e3,
|
|
343
|
+
recommendedTokens: 8e3,
|
|
344
|
+
maxTokens: 1e6,
|
|
345
|
+
// 1M context window
|
|
346
|
+
category: "standard",
|
|
347
|
+
configSchema: GoogleConfigSchema
|
|
348
|
+
},
|
|
349
|
+
// Anthropic Claude Models (direct SDK access via @anthropic-ai/sdk)
|
|
350
|
+
// Using aliases - automatically points to latest versions
|
|
351
|
+
"claude-opus-4-5": {
|
|
352
|
+
inputCostPer1M: 1500,
|
|
353
|
+
// $15.00 per 1M tokens
|
|
354
|
+
outputCostPer1M: 7500,
|
|
355
|
+
// $75.00 per 1M tokens
|
|
356
|
+
minTokens: 4e3,
|
|
357
|
+
recommendedTokens: 8e3,
|
|
358
|
+
maxTokens: 2e5,
|
|
359
|
+
// 200k context window
|
|
360
|
+
category: "reasoning",
|
|
361
|
+
configSchema: AnthropicConfigSchema
|
|
362
|
+
},
|
|
363
|
+
"claude-sonnet-4-5": {
|
|
364
|
+
inputCostPer1M: 300,
|
|
365
|
+
// $3.00 per 1M tokens
|
|
366
|
+
outputCostPer1M: 1500,
|
|
367
|
+
// $15.00 per 1M tokens
|
|
368
|
+
minTokens: 4e3,
|
|
369
|
+
recommendedTokens: 8e3,
|
|
370
|
+
maxTokens: 2e5,
|
|
371
|
+
// 200k context window
|
|
372
|
+
category: "standard",
|
|
373
|
+
configSchema: AnthropicConfigSchema
|
|
374
|
+
},
|
|
375
|
+
"claude-haiku-4-5": {
|
|
376
|
+
inputCostPer1M: 80,
|
|
377
|
+
// $0.80 per 1M tokens
|
|
378
|
+
outputCostPer1M: 400,
|
|
379
|
+
// $4.00 per 1M tokens
|
|
380
|
+
minTokens: 2e3,
|
|
381
|
+
recommendedTokens: 4e3,
|
|
382
|
+
maxTokens: 2e5,
|
|
383
|
+
// 200k context window
|
|
384
|
+
category: "standard",
|
|
385
|
+
configSchema: AnthropicConfigSchema
|
|
386
|
+
}
|
|
387
|
+
};
|
|
388
|
+
function getModelInfo(model) {
|
|
389
|
+
if (model in MODEL_INFO) {
|
|
390
|
+
return MODEL_INFO[model];
|
|
391
|
+
}
|
|
392
|
+
for (const [knownModel, info] of Object.entries(MODEL_INFO)) {
|
|
393
|
+
if (model.startsWith(knownModel)) {
|
|
394
|
+
return info;
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
return void 0;
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
// ../core/src/execution/engine/llm/errors.ts
|
|
401
|
+
var ModelConfigError = class extends ExecutionError2 {
|
|
402
|
+
constructor(message, field, model, context) {
|
|
403
|
+
super(message, { ...context, field, model });
|
|
404
|
+
this.field = field;
|
|
405
|
+
this.model = model;
|
|
406
|
+
}
|
|
407
|
+
type = "model_config_error";
|
|
408
|
+
severity = "warning";
|
|
409
|
+
category = "validation";
|
|
410
|
+
};
|
|
411
|
+
function validateModelConfig(config) {
|
|
412
|
+
const model = config.model;
|
|
413
|
+
if (!model) {
|
|
414
|
+
throw new ModelConfigError("Missing model field", "model", "unknown");
|
|
415
|
+
}
|
|
416
|
+
const modelInfo = getModelInfo(model);
|
|
417
|
+
if (!modelInfo) {
|
|
418
|
+
throw new ModelConfigError(`Unknown model: ${model}`, "model", model);
|
|
419
|
+
}
|
|
420
|
+
if (!modelInfo.configSchema) {
|
|
421
|
+
return;
|
|
422
|
+
}
|
|
423
|
+
const result = modelInfo.configSchema.safeParse(config);
|
|
424
|
+
if (!result.success) {
|
|
425
|
+
const firstError = result.error.issues[0];
|
|
426
|
+
const fieldPath = firstError.path.join(".");
|
|
427
|
+
const fieldName = fieldPath || "config";
|
|
428
|
+
throw new ModelConfigError(`Invalid config for ${model}: ${firstError.message}`, fieldName, model);
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
// ../core/src/platform/registry/validation.ts
|
|
433
|
+
var RegistryValidationError = class extends Error {
|
|
434
|
+
constructor(orgName, resourceId, field, message) {
|
|
435
|
+
super(message);
|
|
436
|
+
this.orgName = orgName;
|
|
437
|
+
this.resourceId = resourceId;
|
|
438
|
+
this.field = field;
|
|
439
|
+
this.name = "RegistryValidationError";
|
|
440
|
+
}
|
|
441
|
+
};
|
|
442
|
+
function validateOrganizationResources(orgName, resources) {
|
|
443
|
+
const seenIds = /* @__PURE__ */ new Set();
|
|
444
|
+
resources.workflows?.forEach((workflow) => {
|
|
445
|
+
const id = workflow.config.resourceId;
|
|
446
|
+
if (seenIds.has(id)) {
|
|
447
|
+
throw new RegistryValidationError(
|
|
448
|
+
orgName,
|
|
449
|
+
id,
|
|
450
|
+
null,
|
|
451
|
+
`Duplicate resourceId "${id}" in organization "${orgName}". Workflows and agents must have unique IDs within an organization.`
|
|
452
|
+
);
|
|
453
|
+
}
|
|
454
|
+
seenIds.add(id);
|
|
455
|
+
if ("modelConfig" in workflow && workflow.modelConfig) {
|
|
456
|
+
validateResourceModelConfig(orgName, id, workflow.modelConfig);
|
|
457
|
+
}
|
|
458
|
+
if (workflow.interface) {
|
|
459
|
+
validateExecutionInterface(orgName, id, workflow.interface, workflow.contract.inputSchema);
|
|
460
|
+
}
|
|
461
|
+
});
|
|
462
|
+
resources.agents?.forEach((agent) => {
|
|
463
|
+
const id = agent.config.resourceId;
|
|
464
|
+
if (seenIds.has(id)) {
|
|
465
|
+
throw new RegistryValidationError(
|
|
466
|
+
orgName,
|
|
467
|
+
id,
|
|
468
|
+
null,
|
|
469
|
+
`Duplicate resourceId "${id}" in organization "${orgName}". Workflows and agents must have unique IDs within an organization.`
|
|
470
|
+
);
|
|
471
|
+
}
|
|
472
|
+
seenIds.add(id);
|
|
473
|
+
validateResourceModelConfig(orgName, id, agent.modelConfig);
|
|
474
|
+
if (agent.interface) {
|
|
475
|
+
validateExecutionInterface(orgName, id, agent.interface, agent.contract.inputSchema);
|
|
476
|
+
}
|
|
477
|
+
});
|
|
478
|
+
}
|
|
479
|
+
function validateResourceModelConfig(orgName, resourceId, modelConfig) {
|
|
480
|
+
try {
|
|
481
|
+
validateModelConfig(modelConfig);
|
|
482
|
+
} catch (error) {
|
|
483
|
+
if (error instanceof ModelConfigError) {
|
|
484
|
+
throw new RegistryValidationError(
|
|
485
|
+
orgName,
|
|
486
|
+
resourceId,
|
|
487
|
+
error.field,
|
|
488
|
+
`Invalid model config in ${orgName}/${resourceId}: ${error.message} (field: ${error.field})`
|
|
489
|
+
);
|
|
490
|
+
}
|
|
491
|
+
throw error;
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
function validateExecutionInterface(orgName, resourceId, executionInterface, inputSchema) {
|
|
495
|
+
const form = executionInterface.form;
|
|
496
|
+
const fieldMappings = form.fieldMappings ?? {};
|
|
497
|
+
const schemaShape = extractZodShape(inputSchema);
|
|
498
|
+
if (!schemaShape) {
|
|
499
|
+
return;
|
|
500
|
+
}
|
|
501
|
+
const schemaFieldNames = Object.keys(schemaShape);
|
|
502
|
+
const formToSchemaMap = /* @__PURE__ */ new Map();
|
|
503
|
+
for (const field of form.fields) {
|
|
504
|
+
const schemaKey = fieldMappings[field.name] ?? field.name;
|
|
505
|
+
formToSchemaMap.set(field.name, schemaKey);
|
|
506
|
+
}
|
|
507
|
+
for (const schemaFieldName of schemaFieldNames) {
|
|
508
|
+
const schemaField = schemaShape[schemaFieldName];
|
|
509
|
+
const isRequired = !isZodOptional(schemaField);
|
|
510
|
+
let hasFormField = false;
|
|
511
|
+
for (const [formFieldName, mappedSchemaName] of Array.from(formToSchemaMap.entries())) {
|
|
512
|
+
if (mappedSchemaName === schemaFieldName) {
|
|
513
|
+
hasFormField = true;
|
|
514
|
+
const formField = form.fields.find((f) => f.name === formFieldName);
|
|
515
|
+
if (isRequired && !formField?.required) {
|
|
516
|
+
throw new RegistryValidationError(
|
|
517
|
+
orgName,
|
|
518
|
+
resourceId,
|
|
519
|
+
`interface.form.fields.${formFieldName}`,
|
|
520
|
+
`ExecutionInterface field "${formFieldName}" should be required to match inputSchema field "${schemaFieldName}" in ${orgName}/${resourceId}`
|
|
521
|
+
);
|
|
522
|
+
}
|
|
523
|
+
break;
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
if (isRequired && !hasFormField) {
|
|
527
|
+
throw new RegistryValidationError(
|
|
528
|
+
orgName,
|
|
529
|
+
resourceId,
|
|
530
|
+
"interface.form.fields",
|
|
531
|
+
`ExecutionInterface missing required field "${schemaFieldName}" from inputSchema in ${orgName}/${resourceId}`
|
|
532
|
+
);
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
for (const [formFieldName, schemaFieldName] of Array.from(formToSchemaMap.entries())) {
|
|
536
|
+
if (schemaFieldName.includes(".")) {
|
|
537
|
+
const topLevelField = schemaFieldName.split(".")[0];
|
|
538
|
+
throw new RegistryValidationError(
|
|
539
|
+
orgName,
|
|
540
|
+
resourceId,
|
|
541
|
+
`interface.form.fields.${formFieldName}`,
|
|
542
|
+
`ExecutionInterface field "${formFieldName}" uses nested notation. Flatten the inputSchema by moving nested fields to top-level (e.g., "${topLevelField}.x" \u2192 "x") in ${orgName}/${resourceId}`
|
|
543
|
+
);
|
|
544
|
+
}
|
|
545
|
+
if (!schemaFieldNames.includes(schemaFieldName)) {
|
|
546
|
+
throw new RegistryValidationError(
|
|
547
|
+
orgName,
|
|
548
|
+
resourceId,
|
|
549
|
+
`interface.form.fields.${formFieldName}`,
|
|
550
|
+
`ExecutionInterface field "${formFieldName}" maps to non-existent schema field "${schemaFieldName}" in ${orgName}/${resourceId}`
|
|
551
|
+
);
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
function extractZodShape(schema) {
|
|
556
|
+
if ("shape" in schema && typeof schema.shape === "object") {
|
|
557
|
+
return schema.shape;
|
|
558
|
+
}
|
|
559
|
+
if ("_def" in schema) {
|
|
560
|
+
const def = schema._def;
|
|
561
|
+
if (def.innerType) {
|
|
562
|
+
return extractZodShape(def.innerType);
|
|
563
|
+
}
|
|
564
|
+
if (def.schema) {
|
|
565
|
+
return extractZodShape(def.schema);
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
return null;
|
|
569
|
+
}
|
|
570
|
+
function isZodOptional(schema) {
|
|
571
|
+
return schema.isOptional();
|
|
572
|
+
}
|
|
573
|
+
function validateRelationships(orgName, resources) {
|
|
574
|
+
if (!resources.relationships && !resources.triggers && !resources.externalResources && !resources.humanCheckpoints) return;
|
|
575
|
+
const validAgentIds = new Set(resources.agents?.map((a) => a.config.resourceId) ?? []);
|
|
576
|
+
const validWorkflowIds = new Set(resources.workflows?.map((w) => w.config.resourceId) ?? []);
|
|
577
|
+
const validIntegrationIds = new Set(resources.integrations?.map((i) => i.resourceId) ?? []);
|
|
578
|
+
const validTriggerIds = new Set(resources.triggers?.map((t) => t.resourceId) ?? []);
|
|
579
|
+
const allInternalIds = /* @__PURE__ */ new Set([
|
|
580
|
+
...Array.from(validAgentIds),
|
|
581
|
+
...Array.from(validWorkflowIds),
|
|
582
|
+
...Array.from(validTriggerIds),
|
|
583
|
+
...Array.from(validIntegrationIds)
|
|
584
|
+
]);
|
|
585
|
+
validateTriggers(orgName, resources.triggers ?? []);
|
|
586
|
+
validateResourceRelationships(
|
|
587
|
+
orgName,
|
|
588
|
+
resources.relationships ?? {},
|
|
589
|
+
validAgentIds,
|
|
590
|
+
validWorkflowIds,
|
|
591
|
+
validIntegrationIds,
|
|
592
|
+
validTriggerIds
|
|
593
|
+
);
|
|
594
|
+
validateExternalResources(
|
|
595
|
+
orgName,
|
|
596
|
+
resources.externalResources ?? [],
|
|
597
|
+
allInternalIds,
|
|
598
|
+
validAgentIds,
|
|
599
|
+
validWorkflowIds,
|
|
600
|
+
validIntegrationIds
|
|
601
|
+
);
|
|
602
|
+
validateHumanCheckpoints(orgName, resources.humanCheckpoints ?? [], allInternalIds, validAgentIds, validWorkflowIds);
|
|
603
|
+
}
|
|
604
|
+
function validateTriggers(_orgName, _triggers, _validAgentIds, _validWorkflowIds) {
|
|
605
|
+
}
|
|
606
|
+
function validateResourceRelationships(orgName, relationships, validAgentIds, validWorkflowIds, validIntegrationIds, validTriggerIds) {
|
|
607
|
+
for (const [resourceId, declaration] of Object.entries(relationships)) {
|
|
608
|
+
const resourceExists = validAgentIds.has(resourceId) || validWorkflowIds.has(resourceId) || validTriggerIds.has(resourceId);
|
|
609
|
+
if (!resourceExists) {
|
|
610
|
+
throw new RegistryValidationError(
|
|
611
|
+
orgName,
|
|
612
|
+
resourceId,
|
|
613
|
+
null,
|
|
614
|
+
`[${orgName}] Relationship declared for non-existent resource: ${resourceId}`
|
|
615
|
+
);
|
|
616
|
+
}
|
|
617
|
+
declaration.triggers?.agents?.forEach((agentId) => {
|
|
618
|
+
if (!validAgentIds.has(agentId)) {
|
|
619
|
+
throw new RegistryValidationError(
|
|
620
|
+
orgName,
|
|
621
|
+
resourceId,
|
|
622
|
+
"triggers.agents",
|
|
623
|
+
`[${orgName}] Resource '${resourceId}' triggers non-existent agent: ${agentId}`
|
|
624
|
+
);
|
|
625
|
+
}
|
|
626
|
+
});
|
|
627
|
+
declaration.triggers?.workflows?.forEach((workflowId) => {
|
|
628
|
+
if (!validWorkflowIds.has(workflowId)) {
|
|
629
|
+
throw new RegistryValidationError(
|
|
630
|
+
orgName,
|
|
631
|
+
resourceId,
|
|
632
|
+
"triggers.workflows",
|
|
633
|
+
`[${orgName}] Resource '${resourceId}' triggers non-existent workflow: ${workflowId}`
|
|
634
|
+
);
|
|
635
|
+
}
|
|
636
|
+
});
|
|
637
|
+
declaration.uses?.integrations?.forEach((integrationId) => {
|
|
638
|
+
if (!validIntegrationIds.has(integrationId)) {
|
|
639
|
+
throw new RegistryValidationError(
|
|
640
|
+
orgName,
|
|
641
|
+
resourceId,
|
|
642
|
+
"uses.integrations",
|
|
643
|
+
`[${orgName}] Resource '${resourceId}' uses non-existent integration: ${integrationId}`
|
|
644
|
+
);
|
|
645
|
+
}
|
|
646
|
+
});
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
function validateExternalResources(orgName, externalResources, allInternalIds, validAgentIds, validWorkflowIds, validIntegrationIds) {
|
|
650
|
+
externalResources.forEach((external) => {
|
|
651
|
+
if (allInternalIds.has(external.resourceId)) {
|
|
652
|
+
throw new RegistryValidationError(
|
|
653
|
+
orgName,
|
|
654
|
+
external.resourceId,
|
|
655
|
+
null,
|
|
656
|
+
`[${orgName}] External resource ID '${external.resourceId}' conflicts with internal resource ID`
|
|
657
|
+
);
|
|
658
|
+
}
|
|
659
|
+
external.triggers?.agents?.forEach((agentId) => {
|
|
660
|
+
if (!validAgentIds.has(agentId)) {
|
|
661
|
+
throw new RegistryValidationError(
|
|
662
|
+
orgName,
|
|
663
|
+
external.resourceId,
|
|
664
|
+
"triggers.agents",
|
|
665
|
+
`[${orgName}] External resource '${external.resourceId}' triggers non-existent agent: ${agentId}`
|
|
666
|
+
);
|
|
667
|
+
}
|
|
668
|
+
});
|
|
669
|
+
external.triggers?.workflows?.forEach((workflowId) => {
|
|
670
|
+
if (!validWorkflowIds.has(workflowId)) {
|
|
671
|
+
throw new RegistryValidationError(
|
|
672
|
+
orgName,
|
|
673
|
+
external.resourceId,
|
|
674
|
+
"triggers.workflows",
|
|
675
|
+
`[${orgName}] External resource '${external.resourceId}' triggers non-existent workflow: ${workflowId}`
|
|
676
|
+
);
|
|
677
|
+
}
|
|
678
|
+
});
|
|
679
|
+
external.uses?.integrations?.forEach((integrationId) => {
|
|
680
|
+
if (!validIntegrationIds.has(integrationId)) {
|
|
681
|
+
throw new RegistryValidationError(
|
|
682
|
+
orgName,
|
|
683
|
+
external.resourceId,
|
|
684
|
+
"uses.integrations",
|
|
685
|
+
`[${orgName}] External resource '${external.resourceId}' uses non-existent integration: ${integrationId}`
|
|
686
|
+
);
|
|
687
|
+
}
|
|
688
|
+
});
|
|
689
|
+
});
|
|
690
|
+
}
|
|
691
|
+
function validateHumanCheckpoints(orgName, humanCheckpoints, allInternalIds, validAgentIds, validWorkflowIds) {
|
|
692
|
+
humanCheckpoints.forEach((humanCheckpoint) => {
|
|
693
|
+
if (allInternalIds.has(humanCheckpoint.resourceId)) {
|
|
694
|
+
throw new RegistryValidationError(
|
|
695
|
+
orgName,
|
|
696
|
+
humanCheckpoint.resourceId,
|
|
697
|
+
null,
|
|
698
|
+
`[${orgName}] Human checkpoint ID '${humanCheckpoint.resourceId}' conflicts with internal resource ID`
|
|
699
|
+
);
|
|
700
|
+
}
|
|
701
|
+
humanCheckpoint.requestedBy?.agents?.forEach((agentId) => {
|
|
702
|
+
if (!validAgentIds.has(agentId)) {
|
|
703
|
+
throw new RegistryValidationError(
|
|
704
|
+
orgName,
|
|
705
|
+
humanCheckpoint.resourceId,
|
|
706
|
+
"requestedBy.agents",
|
|
707
|
+
`[${orgName}] Human checkpoint '${humanCheckpoint.resourceId}' requestedBy non-existent agent: ${agentId}`
|
|
708
|
+
);
|
|
709
|
+
}
|
|
710
|
+
});
|
|
711
|
+
humanCheckpoint.requestedBy?.workflows?.forEach((workflowId) => {
|
|
712
|
+
if (!validWorkflowIds.has(workflowId)) {
|
|
713
|
+
throw new RegistryValidationError(
|
|
714
|
+
orgName,
|
|
715
|
+
humanCheckpoint.resourceId,
|
|
716
|
+
"requestedBy.workflows",
|
|
717
|
+
`[${orgName}] Human checkpoint '${humanCheckpoint.resourceId}' requestedBy non-existent workflow: ${workflowId}`
|
|
718
|
+
);
|
|
719
|
+
}
|
|
720
|
+
});
|
|
721
|
+
humanCheckpoint.routesTo?.agents?.forEach((agentId) => {
|
|
722
|
+
if (!validAgentIds.has(agentId)) {
|
|
723
|
+
throw new RegistryValidationError(
|
|
724
|
+
orgName,
|
|
725
|
+
humanCheckpoint.resourceId,
|
|
726
|
+
"routesTo.agents",
|
|
727
|
+
`[${orgName}] Human checkpoint '${humanCheckpoint.resourceId}' routesTo non-existent agent: ${agentId}`
|
|
728
|
+
);
|
|
729
|
+
}
|
|
730
|
+
});
|
|
731
|
+
humanCheckpoint.routesTo?.workflows?.forEach((workflowId) => {
|
|
732
|
+
if (!validWorkflowIds.has(workflowId)) {
|
|
733
|
+
throw new RegistryValidationError(
|
|
734
|
+
orgName,
|
|
735
|
+
humanCheckpoint.resourceId,
|
|
736
|
+
"routesTo.workflows",
|
|
737
|
+
`[${orgName}] Human checkpoint '${humanCheckpoint.resourceId}' routesTo non-existent workflow: ${workflowId}`
|
|
738
|
+
);
|
|
739
|
+
}
|
|
740
|
+
});
|
|
741
|
+
});
|
|
742
|
+
}
|
|
743
|
+
|
|
744
|
+
// ../../node_modules/.pnpm/@alcyone-labs+zod-to-json-schema@4.0.10_zod@4.1.12/node_modules/@alcyone-labs/zod-to-json-schema/dist/esm/Options.js
|
|
745
|
+
var ignoreOverride = /* @__PURE__ */ Symbol("Let zodToJsonSchema decide on which parser to use");
|
|
746
|
+
var defaultOptions = {
|
|
747
|
+
name: void 0,
|
|
748
|
+
$refStrategy: "root",
|
|
749
|
+
basePath: ["#"],
|
|
750
|
+
effectStrategy: "input",
|
|
751
|
+
pipeStrategy: "all",
|
|
752
|
+
dateStrategy: "format:date-time",
|
|
753
|
+
mapStrategy: "entries",
|
|
754
|
+
removeAdditionalStrategy: "passthrough",
|
|
755
|
+
allowedAdditionalProperties: true,
|
|
756
|
+
rejectedAdditionalProperties: false,
|
|
757
|
+
definitionPath: "definitions",
|
|
758
|
+
target: "jsonSchema7",
|
|
759
|
+
strictUnions: false,
|
|
760
|
+
definitions: {},
|
|
761
|
+
errorMessages: false,
|
|
762
|
+
markdownDescription: false,
|
|
763
|
+
patternStrategy: "escape",
|
|
764
|
+
applyRegexFlags: false,
|
|
765
|
+
emailStrategy: "format:email",
|
|
766
|
+
base64Strategy: "contentEncoding:base64",
|
|
767
|
+
nameStrategy: "ref",
|
|
768
|
+
openAiAnyTypeName: "OpenAiAnyType"
|
|
769
|
+
};
|
|
770
|
+
var getDefaultOptions = (options) => typeof options === "string" ? {
|
|
771
|
+
...defaultOptions,
|
|
772
|
+
name: options
|
|
773
|
+
} : {
|
|
774
|
+
...defaultOptions,
|
|
775
|
+
...options
|
|
776
|
+
};
|
|
777
|
+
|
|
778
|
+
// ../../node_modules/.pnpm/@alcyone-labs+zod-to-json-schema@4.0.10_zod@4.1.12/node_modules/@alcyone-labs/zod-to-json-schema/dist/esm/Refs.js
|
|
779
|
+
var getRefs = (options) => {
|
|
780
|
+
const _options = getDefaultOptions(options);
|
|
781
|
+
const currentPath = _options.name !== void 0 ? [..._options.basePath, _options.definitionPath, _options.name] : _options.basePath;
|
|
782
|
+
return {
|
|
783
|
+
..._options,
|
|
784
|
+
flags: { hasReferencedOpenAiAnyType: false },
|
|
785
|
+
currentPath,
|
|
786
|
+
propertyPath: void 0,
|
|
787
|
+
seen: new Map(Object.entries(_options.definitions).map(([name, def]) => [
|
|
788
|
+
def._def,
|
|
789
|
+
{
|
|
790
|
+
def: def._def,
|
|
791
|
+
path: [..._options.basePath, _options.definitionPath, name],
|
|
792
|
+
// Resolution of references will be forced even though seen, so it's ok that the schema is undefined here for now.
|
|
793
|
+
jsonSchema: void 0
|
|
794
|
+
}
|
|
795
|
+
]))
|
|
796
|
+
};
|
|
797
|
+
};
|
|
798
|
+
|
|
799
|
+
// ../../node_modules/.pnpm/@alcyone-labs+zod-to-json-schema@4.0.10_zod@4.1.12/node_modules/@alcyone-labs/zod-to-json-schema/dist/esm/errorMessages.js
|
|
800
|
+
function addErrorMessage(res, key, errorMessage, refs) {
|
|
801
|
+
if (!refs?.errorMessages)
|
|
802
|
+
return;
|
|
803
|
+
if (errorMessage) {
|
|
804
|
+
res.errorMessage = {
|
|
805
|
+
...res.errorMessage,
|
|
806
|
+
[key]: errorMessage
|
|
807
|
+
};
|
|
808
|
+
}
|
|
809
|
+
}
|
|
810
|
+
function setResponseValueAndErrors(res, key, value, errorMessage, refs) {
|
|
811
|
+
res[key] = value;
|
|
812
|
+
addErrorMessage(res, key, errorMessage, refs);
|
|
813
|
+
}
|
|
814
|
+
|
|
815
|
+
// ../../node_modules/.pnpm/@alcyone-labs+zod-to-json-schema@4.0.10_zod@4.1.12/node_modules/@alcyone-labs/zod-to-json-schema/dist/esm/getRelativePath.js
|
|
816
|
+
var getRelativePath = (pathA, pathB) => {
|
|
817
|
+
let i = 0;
|
|
818
|
+
for (; i < pathA.length && i < pathB.length; i++) {
|
|
819
|
+
if (pathA[i] !== pathB[i])
|
|
820
|
+
break;
|
|
821
|
+
}
|
|
822
|
+
return [(pathA.length - i).toString(), ...pathB.slice(i)].join("/");
|
|
823
|
+
};
|
|
824
|
+
|
|
825
|
+
// ../../node_modules/.pnpm/@alcyone-labs+zod-to-json-schema@4.0.10_zod@4.1.12/node_modules/@alcyone-labs/zod-to-json-schema/dist/esm/zodV3V4Compat.js
|
|
826
|
+
var ZodFirstPartyTypeKindFromZod;
|
|
827
|
+
try {
|
|
828
|
+
const zodImport = __require("zod");
|
|
829
|
+
ZodFirstPartyTypeKindFromZod = zodImport.ZodFirstPartyTypeKind;
|
|
830
|
+
} catch {
|
|
831
|
+
}
|
|
832
|
+
var ZodFirstPartyTypeKind = ZodFirstPartyTypeKindFromZod || {
|
|
833
|
+
ZodNumber: "ZodNumber",
|
|
834
|
+
ZodBigInt: "ZodBigInt",
|
|
835
|
+
ZodBoolean: "ZodBoolean",
|
|
836
|
+
ZodDate: "ZodDate",
|
|
837
|
+
ZodUndefined: "ZodUndefined",
|
|
838
|
+
ZodNull: "ZodNull",
|
|
839
|
+
ZodVoid: "ZodVoid",
|
|
840
|
+
ZodAny: "ZodAny",
|
|
841
|
+
ZodUnknown: "ZodUnknown",
|
|
842
|
+
ZodNever: "ZodNever",
|
|
843
|
+
ZodArray: "ZodArray",
|
|
844
|
+
ZodObject: "ZodObject",
|
|
845
|
+
ZodUnion: "ZodUnion",
|
|
846
|
+
ZodDiscriminatedUnion: "ZodDiscriminatedUnion",
|
|
847
|
+
ZodIntersection: "ZodIntersection",
|
|
848
|
+
ZodTuple: "ZodTuple",
|
|
849
|
+
ZodRecord: "ZodRecord",
|
|
850
|
+
ZodMap: "ZodMap",
|
|
851
|
+
ZodSet: "ZodSet",
|
|
852
|
+
ZodFunction: "ZodFunction",
|
|
853
|
+
ZodLazy: "ZodLazy",
|
|
854
|
+
ZodLiteral: "ZodLiteral",
|
|
855
|
+
ZodEnum: "ZodEnum",
|
|
856
|
+
ZodNativeEnum: "ZodNativeEnum",
|
|
857
|
+
ZodPromise: "ZodPromise",
|
|
858
|
+
ZodEffects: "ZodEffects",
|
|
859
|
+
ZodOptional: "ZodOptional",
|
|
860
|
+
ZodNullable: "ZodNullable",
|
|
861
|
+
ZodDefault: "ZodDefault",
|
|
862
|
+
ZodCatch: "ZodCatch",
|
|
863
|
+
ZodReadonly: "ZodReadonly",
|
|
864
|
+
ZodBranded: "ZodBranded",
|
|
865
|
+
ZodPipeline: "ZodPipeline"};
|
|
866
|
+
function getDefTypeName(def) {
|
|
867
|
+
return def?.typeName || def?.type;
|
|
868
|
+
}
|
|
869
|
+
function getInnerTypeDef(wrapperDef) {
|
|
870
|
+
if (!wrapperDef?.innerType)
|
|
871
|
+
return void 0;
|
|
872
|
+
return wrapperDef.innerType.def || wrapperDef.innerType._def;
|
|
873
|
+
}
|
|
874
|
+
function isNullableType(def) {
|
|
875
|
+
const typeName = getDefTypeName(def);
|
|
876
|
+
return typeName === "nullable" || typeName === "ZodNullable";
|
|
877
|
+
}
|
|
878
|
+
function getAllPrimitiveTypeNames() {
|
|
879
|
+
return [
|
|
880
|
+
// V3 names
|
|
881
|
+
"ZodString",
|
|
882
|
+
"ZodNumber",
|
|
883
|
+
"ZodBigInt",
|
|
884
|
+
"ZodBoolean",
|
|
885
|
+
"ZodNull",
|
|
886
|
+
// V4 names
|
|
887
|
+
"string",
|
|
888
|
+
"number",
|
|
889
|
+
"bigint",
|
|
890
|
+
"boolean",
|
|
891
|
+
"null"
|
|
892
|
+
];
|
|
893
|
+
}
|
|
894
|
+
function extractMetadata(schema) {
|
|
895
|
+
let metadata = {};
|
|
896
|
+
if (schema?._def?.description) {
|
|
897
|
+
metadata.description = schema._def.description;
|
|
898
|
+
}
|
|
899
|
+
if (typeof schema?.meta === "function") {
|
|
900
|
+
try {
|
|
901
|
+
const meta = schema.meta();
|
|
902
|
+
if (meta && typeof meta === "object") {
|
|
903
|
+
metadata = { ...metadata, ...meta };
|
|
904
|
+
}
|
|
905
|
+
} catch {
|
|
906
|
+
}
|
|
907
|
+
}
|
|
908
|
+
if (!metadata.description && schema?.description) {
|
|
909
|
+
metadata.description = schema.description;
|
|
910
|
+
}
|
|
911
|
+
return metadata;
|
|
912
|
+
}
|
|
913
|
+
var primitiveMappings = {
|
|
914
|
+
// V3 mappings
|
|
915
|
+
ZodString: "string",
|
|
916
|
+
ZodNumber: "number",
|
|
917
|
+
ZodBigInt: "string",
|
|
918
|
+
// BigInt is represented as string in JSON
|
|
919
|
+
ZodBoolean: "boolean",
|
|
920
|
+
ZodNull: "null",
|
|
921
|
+
// V4 mappings
|
|
922
|
+
string: "string",
|
|
923
|
+
number: "number",
|
|
924
|
+
bigint: "string",
|
|
925
|
+
// BigInt is represented as string in JSON
|
|
926
|
+
boolean: "boolean",
|
|
927
|
+
null: "null"
|
|
928
|
+
};
|
|
929
|
+
|
|
930
|
+
// ../../node_modules/.pnpm/@alcyone-labs+zod-to-json-schema@4.0.10_zod@4.1.12/node_modules/@alcyone-labs/zod-to-json-schema/dist/esm/parsers/any.js
|
|
931
|
+
function parseAnyDef(refs) {
|
|
932
|
+
if (refs.target !== "openAi") {
|
|
933
|
+
return {};
|
|
934
|
+
}
|
|
935
|
+
const anyDefinitionPath = [
|
|
936
|
+
...refs.basePath,
|
|
937
|
+
refs.definitionPath,
|
|
938
|
+
refs.openAiAnyTypeName
|
|
939
|
+
];
|
|
940
|
+
refs.flags.hasReferencedOpenAiAnyType = true;
|
|
941
|
+
return {
|
|
942
|
+
$ref: refs.$refStrategy === "relative" ? getRelativePath(anyDefinitionPath, refs.currentPath) : anyDefinitionPath.join("/")
|
|
943
|
+
};
|
|
944
|
+
}
|
|
945
|
+
|
|
946
|
+
// ../../node_modules/.pnpm/@alcyone-labs+zod-to-json-schema@4.0.10_zod@4.1.12/node_modules/@alcyone-labs/zod-to-json-schema/dist/esm/parsers/array.js
|
|
947
|
+
function parseArrayDef(def, refs) {
|
|
948
|
+
const res = {
|
|
949
|
+
type: "array"
|
|
950
|
+
};
|
|
951
|
+
const elementType = def.element || def.type;
|
|
952
|
+
const elementDef = elementType?.def || elementType?._def;
|
|
953
|
+
const elementTypeName = elementDef?.type || elementDef?.typeName;
|
|
954
|
+
if (elementDef && elementTypeName !== "any" && elementTypeName !== "ZodAny") {
|
|
955
|
+
res.items = parseDef(elementDef, {
|
|
956
|
+
...refs,
|
|
957
|
+
currentPath: [...refs.currentPath, "items"]
|
|
958
|
+
});
|
|
959
|
+
}
|
|
960
|
+
if (def.checks) {
|
|
961
|
+
for (const check of def.checks) {
|
|
962
|
+
const checkDef = check._zod?.def;
|
|
963
|
+
if (checkDef) {
|
|
964
|
+
let message = checkDef.message;
|
|
965
|
+
if (!message && checkDef.error && typeof checkDef.error === "function") {
|
|
966
|
+
try {
|
|
967
|
+
message = checkDef.error();
|
|
968
|
+
} catch (e) {
|
|
969
|
+
}
|
|
970
|
+
}
|
|
971
|
+
switch (checkDef.check) {
|
|
972
|
+
case "min_length":
|
|
973
|
+
setResponseValueAndErrors(res, "minItems", checkDef.minimum, message, refs);
|
|
974
|
+
break;
|
|
975
|
+
case "max_length":
|
|
976
|
+
setResponseValueAndErrors(res, "maxItems", checkDef.maximum, message, refs);
|
|
977
|
+
break;
|
|
978
|
+
case "length_equals":
|
|
979
|
+
const length = checkDef.length;
|
|
980
|
+
if (length !== void 0) {
|
|
981
|
+
setResponseValueAndErrors(res, "minItems", length, message, refs);
|
|
982
|
+
setResponseValueAndErrors(res, "maxItems", length, message, refs);
|
|
983
|
+
}
|
|
984
|
+
break;
|
|
985
|
+
}
|
|
986
|
+
}
|
|
987
|
+
}
|
|
988
|
+
}
|
|
989
|
+
if (def.minLength) {
|
|
990
|
+
setResponseValueAndErrors(res, "minItems", def.minLength.value, def.minLength.message, refs);
|
|
991
|
+
}
|
|
992
|
+
if (def.maxLength) {
|
|
993
|
+
setResponseValueAndErrors(res, "maxItems", def.maxLength.value, def.maxLength.message, refs);
|
|
994
|
+
}
|
|
995
|
+
if (def.exactLength) {
|
|
996
|
+
setResponseValueAndErrors(res, "minItems", def.exactLength.value, def.exactLength.message, refs);
|
|
997
|
+
setResponseValueAndErrors(res, "maxItems", def.exactLength.value, def.exactLength.message, refs);
|
|
998
|
+
}
|
|
999
|
+
return res;
|
|
1000
|
+
}
|
|
1001
|
+
|
|
1002
|
+
// ../../node_modules/.pnpm/@alcyone-labs+zod-to-json-schema@4.0.10_zod@4.1.12/node_modules/@alcyone-labs/zod-to-json-schema/dist/esm/parsers/bigint.js
|
|
1003
|
+
function parseBigintDef(def, refs) {
|
|
1004
|
+
const res = {
|
|
1005
|
+
type: "integer",
|
|
1006
|
+
format: "int64"
|
|
1007
|
+
};
|
|
1008
|
+
if (!def.checks)
|
|
1009
|
+
return res;
|
|
1010
|
+
for (const check of def.checks) {
|
|
1011
|
+
const checkDef = check._zod?.def;
|
|
1012
|
+
if (checkDef) {
|
|
1013
|
+
let message = checkDef.message;
|
|
1014
|
+
if (!message && checkDef.error && typeof checkDef.error === "function") {
|
|
1015
|
+
try {
|
|
1016
|
+
message = checkDef.error();
|
|
1017
|
+
} catch (e) {
|
|
1018
|
+
}
|
|
1019
|
+
}
|
|
1020
|
+
switch (checkDef.check) {
|
|
1021
|
+
case "greater_than":
|
|
1022
|
+
const minValue = checkDef.value;
|
|
1023
|
+
if (refs.target === "jsonSchema7") {
|
|
1024
|
+
if (checkDef.inclusive) {
|
|
1025
|
+
setResponseValueAndErrors(res, "minimum", minValue, message, refs);
|
|
1026
|
+
} else {
|
|
1027
|
+
setResponseValueAndErrors(res, "exclusiveMinimum", minValue, message, refs);
|
|
1028
|
+
}
|
|
1029
|
+
} else {
|
|
1030
|
+
if (!checkDef.inclusive) {
|
|
1031
|
+
res.exclusiveMinimum = true;
|
|
1032
|
+
}
|
|
1033
|
+
setResponseValueAndErrors(res, "minimum", minValue, message, refs);
|
|
1034
|
+
}
|
|
1035
|
+
break;
|
|
1036
|
+
case "less_than":
|
|
1037
|
+
const maxValue = checkDef.value;
|
|
1038
|
+
if (refs.target === "jsonSchema7") {
|
|
1039
|
+
if (checkDef.inclusive) {
|
|
1040
|
+
setResponseValueAndErrors(res, "maximum", maxValue, message, refs);
|
|
1041
|
+
} else {
|
|
1042
|
+
setResponseValueAndErrors(res, "exclusiveMaximum", maxValue, message, refs);
|
|
1043
|
+
}
|
|
1044
|
+
} else {
|
|
1045
|
+
if (!checkDef.inclusive) {
|
|
1046
|
+
res.exclusiveMaximum = true;
|
|
1047
|
+
}
|
|
1048
|
+
setResponseValueAndErrors(res, "maximum", maxValue, message, refs);
|
|
1049
|
+
}
|
|
1050
|
+
break;
|
|
1051
|
+
case "multiple_of":
|
|
1052
|
+
const multipleValue = checkDef.value;
|
|
1053
|
+
setResponseValueAndErrors(res, "multipleOf", multipleValue, message, refs);
|
|
1054
|
+
break;
|
|
1055
|
+
}
|
|
1056
|
+
} else {
|
|
1057
|
+
switch (check.kind) {
|
|
1058
|
+
case "min":
|
|
1059
|
+
if (refs.target === "jsonSchema7") {
|
|
1060
|
+
if (check.inclusive) {
|
|
1061
|
+
setResponseValueAndErrors(res, "minimum", check.value, check.message, refs);
|
|
1062
|
+
} else {
|
|
1063
|
+
setResponseValueAndErrors(res, "exclusiveMinimum", check.value, check.message, refs);
|
|
1064
|
+
}
|
|
1065
|
+
} else {
|
|
1066
|
+
if (!check.inclusive) {
|
|
1067
|
+
res.exclusiveMinimum = true;
|
|
1068
|
+
}
|
|
1069
|
+
setResponseValueAndErrors(res, "minimum", check.value, check.message, refs);
|
|
1070
|
+
}
|
|
1071
|
+
break;
|
|
1072
|
+
case "max":
|
|
1073
|
+
if (refs.target === "jsonSchema7") {
|
|
1074
|
+
if (check.inclusive) {
|
|
1075
|
+
setResponseValueAndErrors(res, "maximum", check.value, check.message, refs);
|
|
1076
|
+
} else {
|
|
1077
|
+
setResponseValueAndErrors(res, "exclusiveMaximum", check.value, check.message, refs);
|
|
1078
|
+
}
|
|
1079
|
+
} else {
|
|
1080
|
+
if (!check.inclusive) {
|
|
1081
|
+
res.exclusiveMaximum = true;
|
|
1082
|
+
}
|
|
1083
|
+
setResponseValueAndErrors(res, "maximum", check.value, check.message, refs);
|
|
1084
|
+
}
|
|
1085
|
+
break;
|
|
1086
|
+
case "multipleOf":
|
|
1087
|
+
setResponseValueAndErrors(res, "multipleOf", check.value, check.message, refs);
|
|
1088
|
+
break;
|
|
1089
|
+
}
|
|
1090
|
+
}
|
|
1091
|
+
}
|
|
1092
|
+
return res;
|
|
1093
|
+
}
|
|
1094
|
+
|
|
1095
|
+
// ../../node_modules/.pnpm/@alcyone-labs+zod-to-json-schema@4.0.10_zod@4.1.12/node_modules/@alcyone-labs/zod-to-json-schema/dist/esm/parsers/boolean.js
|
|
1096
|
+
function parseBooleanDef() {
|
|
1097
|
+
return {
|
|
1098
|
+
type: "boolean"
|
|
1099
|
+
};
|
|
1100
|
+
}
|
|
1101
|
+
|
|
1102
|
+
// ../../node_modules/.pnpm/@alcyone-labs+zod-to-json-schema@4.0.10_zod@4.1.12/node_modules/@alcyone-labs/zod-to-json-schema/dist/esm/parsers/branded.js
|
|
1103
|
+
function parseBrandedDef(_def, refs) {
|
|
1104
|
+
if (_def.type && _def.type._def) {
|
|
1105
|
+
return parseDef(_def.type._def, refs);
|
|
1106
|
+
} else {
|
|
1107
|
+
return parseDef(_def, refs);
|
|
1108
|
+
}
|
|
1109
|
+
}
|
|
1110
|
+
|
|
1111
|
+
// ../../node_modules/.pnpm/@alcyone-labs+zod-to-json-schema@4.0.10_zod@4.1.12/node_modules/@alcyone-labs/zod-to-json-schema/dist/esm/parsers/catch.js
|
|
1112
|
+
var parseCatchDef = (def, refs) => {
|
|
1113
|
+
return parseDef(def.innerType._def, refs);
|
|
1114
|
+
};
|
|
1115
|
+
|
|
1116
|
+
// ../../node_modules/.pnpm/@alcyone-labs+zod-to-json-schema@4.0.10_zod@4.1.12/node_modules/@alcyone-labs/zod-to-json-schema/dist/esm/parsers/date.js
|
|
1117
|
+
function parseDateDef(def, refs, overrideDateStrategy) {
|
|
1118
|
+
const strategy = overrideDateStrategy ?? refs.dateStrategy;
|
|
1119
|
+
if (Array.isArray(strategy)) {
|
|
1120
|
+
return {
|
|
1121
|
+
anyOf: strategy.map((item, i) => parseDateDef(def, refs, item))
|
|
1122
|
+
};
|
|
1123
|
+
}
|
|
1124
|
+
switch (strategy) {
|
|
1125
|
+
case "string":
|
|
1126
|
+
case "format:date-time":
|
|
1127
|
+
return {
|
|
1128
|
+
type: "string",
|
|
1129
|
+
format: "date-time"
|
|
1130
|
+
};
|
|
1131
|
+
case "format:date":
|
|
1132
|
+
return {
|
|
1133
|
+
type: "string",
|
|
1134
|
+
format: "date"
|
|
1135
|
+
};
|
|
1136
|
+
case "integer":
|
|
1137
|
+
return integerDateParser(def, refs);
|
|
1138
|
+
}
|
|
1139
|
+
}
|
|
1140
|
+
var integerDateParser = (def, refs) => {
|
|
1141
|
+
const res = {
|
|
1142
|
+
type: "integer",
|
|
1143
|
+
format: "unix-time"
|
|
1144
|
+
};
|
|
1145
|
+
if (refs.target === "openApi3") {
|
|
1146
|
+
return res;
|
|
1147
|
+
}
|
|
1148
|
+
if (def.checks) {
|
|
1149
|
+
for (const check of def.checks) {
|
|
1150
|
+
const checkDef = check._zod?.def;
|
|
1151
|
+
if (checkDef) {
|
|
1152
|
+
let message = checkDef.message;
|
|
1153
|
+
if (!message && checkDef.error && typeof checkDef.error === "function") {
|
|
1154
|
+
try {
|
|
1155
|
+
message = checkDef.error();
|
|
1156
|
+
} catch (e) {
|
|
1157
|
+
}
|
|
1158
|
+
}
|
|
1159
|
+
switch (checkDef.check) {
|
|
1160
|
+
case "greater_than":
|
|
1161
|
+
const minValue = checkDef.value instanceof Date ? checkDef.value.getTime() : checkDef.value;
|
|
1162
|
+
setResponseValueAndErrors(res, "minimum", minValue, message, refs);
|
|
1163
|
+
break;
|
|
1164
|
+
case "less_than":
|
|
1165
|
+
const maxValue = checkDef.value instanceof Date ? checkDef.value.getTime() : checkDef.value;
|
|
1166
|
+
setResponseValueAndErrors(res, "maximum", maxValue, message, refs);
|
|
1167
|
+
break;
|
|
1168
|
+
}
|
|
1169
|
+
} else {
|
|
1170
|
+
switch (check.kind) {
|
|
1171
|
+
case "min":
|
|
1172
|
+
setResponseValueAndErrors(
|
|
1173
|
+
res,
|
|
1174
|
+
"minimum",
|
|
1175
|
+
check.value,
|
|
1176
|
+
// This is in milliseconds
|
|
1177
|
+
check.message,
|
|
1178
|
+
refs
|
|
1179
|
+
);
|
|
1180
|
+
break;
|
|
1181
|
+
case "max":
|
|
1182
|
+
setResponseValueAndErrors(
|
|
1183
|
+
res,
|
|
1184
|
+
"maximum",
|
|
1185
|
+
check.value,
|
|
1186
|
+
// This is in milliseconds
|
|
1187
|
+
check.message,
|
|
1188
|
+
refs
|
|
1189
|
+
);
|
|
1190
|
+
break;
|
|
1191
|
+
}
|
|
1192
|
+
}
|
|
1193
|
+
}
|
|
1194
|
+
}
|
|
1195
|
+
return res;
|
|
1196
|
+
};
|
|
1197
|
+
|
|
1198
|
+
// ../../node_modules/.pnpm/@alcyone-labs+zod-to-json-schema@4.0.10_zod@4.1.12/node_modules/@alcyone-labs/zod-to-json-schema/dist/esm/parsers/default.js
|
|
1199
|
+
function parseDefaultDef(_def, refs) {
|
|
1200
|
+
return {
|
|
1201
|
+
...parseDef(_def.innerType._def, refs),
|
|
1202
|
+
default: _def.defaultValue
|
|
1203
|
+
};
|
|
1204
|
+
}
|
|
1205
|
+
|
|
1206
|
+
// ../../node_modules/.pnpm/@alcyone-labs+zod-to-json-schema@4.0.10_zod@4.1.12/node_modules/@alcyone-labs/zod-to-json-schema/dist/esm/parsers/effects.js
|
|
1207
|
+
function parseEffectsDef(_def, refs) {
|
|
1208
|
+
if (_def.type === "pipe") {
|
|
1209
|
+
return refs.effectStrategy === "input" ? parseDef(_def.in?.def || _def.in?._def, refs) : parseAnyDef(refs);
|
|
1210
|
+
}
|
|
1211
|
+
if (_def.schema) {
|
|
1212
|
+
return refs.effectStrategy === "input" ? parseDef(_def.schema._def || _def.schema.def, refs) : parseAnyDef(refs);
|
|
1213
|
+
}
|
|
1214
|
+
return parseAnyDef(refs);
|
|
1215
|
+
}
|
|
1216
|
+
|
|
1217
|
+
// ../../node_modules/.pnpm/@alcyone-labs+zod-to-json-schema@4.0.10_zod@4.1.12/node_modules/@alcyone-labs/zod-to-json-schema/dist/esm/parsers/enum.js
|
|
1218
|
+
function parseEnumDef(def) {
|
|
1219
|
+
const values = def.entries ? Object.values(def.entries) : def.values;
|
|
1220
|
+
return {
|
|
1221
|
+
type: "string",
|
|
1222
|
+
enum: Array.from(values)
|
|
1223
|
+
};
|
|
1224
|
+
}
|
|
1225
|
+
|
|
1226
|
+
// ../../node_modules/.pnpm/@alcyone-labs+zod-to-json-schema@4.0.10_zod@4.1.12/node_modules/@alcyone-labs/zod-to-json-schema/dist/esm/parsers/intersection.js
|
|
1227
|
+
var isJsonSchema7AllOfType = (type) => {
|
|
1228
|
+
if ("type" in type && type.type === "string")
|
|
1229
|
+
return false;
|
|
1230
|
+
return "allOf" in type;
|
|
1231
|
+
};
|
|
1232
|
+
function parseIntersectionDef(def, refs) {
|
|
1233
|
+
const allOf = [
|
|
1234
|
+
parseDef(def.left._def, {
|
|
1235
|
+
...refs,
|
|
1236
|
+
currentPath: [...refs.currentPath, "allOf", "0"]
|
|
1237
|
+
}),
|
|
1238
|
+
parseDef(def.right._def, {
|
|
1239
|
+
...refs,
|
|
1240
|
+
currentPath: [...refs.currentPath, "allOf", "1"]
|
|
1241
|
+
})
|
|
1242
|
+
].filter((x) => !!x);
|
|
1243
|
+
let unevaluatedProperties = refs.target === "jsonSchema2019-09" ? { unevaluatedProperties: false } : void 0;
|
|
1244
|
+
const mergedAllOf = [];
|
|
1245
|
+
allOf.forEach((schema) => {
|
|
1246
|
+
if (isJsonSchema7AllOfType(schema)) {
|
|
1247
|
+
mergedAllOf.push(...schema.allOf);
|
|
1248
|
+
if (schema.unevaluatedProperties === void 0) {
|
|
1249
|
+
unevaluatedProperties = void 0;
|
|
1250
|
+
}
|
|
1251
|
+
} else {
|
|
1252
|
+
let nestedSchema = schema;
|
|
1253
|
+
if ("additionalProperties" in schema && schema.additionalProperties === false) {
|
|
1254
|
+
const { additionalProperties, ...rest } = schema;
|
|
1255
|
+
nestedSchema = rest;
|
|
1256
|
+
} else {
|
|
1257
|
+
unevaluatedProperties = void 0;
|
|
1258
|
+
}
|
|
1259
|
+
mergedAllOf.push(nestedSchema);
|
|
1260
|
+
}
|
|
1261
|
+
});
|
|
1262
|
+
return mergedAllOf.length ? {
|
|
1263
|
+
allOf: mergedAllOf,
|
|
1264
|
+
...unevaluatedProperties
|
|
1265
|
+
} : void 0;
|
|
1266
|
+
}
|
|
1267
|
+
|
|
1268
|
+
// ../../node_modules/.pnpm/@alcyone-labs+zod-to-json-schema@4.0.10_zod@4.1.12/node_modules/@alcyone-labs/zod-to-json-schema/dist/esm/parsers/literal.js
|
|
1269
|
+
function parseLiteralDef(def, refs) {
|
|
1270
|
+
const value = def.values ? def.values[0] : def.value;
|
|
1271
|
+
const parsedType = typeof value;
|
|
1272
|
+
if (parsedType !== "bigint" && parsedType !== "number" && parsedType !== "boolean" && parsedType !== "string") {
|
|
1273
|
+
return {
|
|
1274
|
+
type: Array.isArray(value) ? "array" : "object"
|
|
1275
|
+
};
|
|
1276
|
+
}
|
|
1277
|
+
if (refs.target === "openApi3") {
|
|
1278
|
+
return {
|
|
1279
|
+
type: parsedType === "bigint" ? "integer" : parsedType,
|
|
1280
|
+
enum: [value]
|
|
1281
|
+
};
|
|
1282
|
+
}
|
|
1283
|
+
return {
|
|
1284
|
+
type: parsedType === "bigint" ? "integer" : parsedType,
|
|
1285
|
+
const: value
|
|
1286
|
+
};
|
|
1287
|
+
}
|
|
1288
|
+
|
|
1289
|
+
// ../../node_modules/.pnpm/@alcyone-labs+zod-to-json-schema@4.0.10_zod@4.1.12/node_modules/@alcyone-labs/zod-to-json-schema/dist/esm/parsers/string.js
|
|
1290
|
+
var emojiRegex = void 0;
|
|
1291
|
+
var zodPatterns = {
|
|
1292
|
+
/**
|
|
1293
|
+
* `c` was changed to `[cC]` to replicate /i flag
|
|
1294
|
+
*/
|
|
1295
|
+
cuid: /^[cC][^\s-]{8,}$/,
|
|
1296
|
+
cuid2: /^[0-9a-z]+$/,
|
|
1297
|
+
ulid: /^[0-9A-HJKMNP-TV-Z]{26}$/,
|
|
1298
|
+
/**
|
|
1299
|
+
* `a-z` was added to replicate /i flag
|
|
1300
|
+
*/
|
|
1301
|
+
email: /^(?!\.)(?!.*\.\.)([a-zA-Z0-9_'+\-\.]*)[a-zA-Z0-9_+-]@([a-zA-Z0-9][a-zA-Z0-9\-]*\.)+[a-zA-Z]{2,}$/,
|
|
1302
|
+
/**
|
|
1303
|
+
* Constructed a valid Unicode RegExp
|
|
1304
|
+
*
|
|
1305
|
+
* Lazily instantiate since this type of regex isn't supported
|
|
1306
|
+
* in all envs (e.g. React Native).
|
|
1307
|
+
*
|
|
1308
|
+
* See:
|
|
1309
|
+
* https://github.com/colinhacks/zod/issues/2433
|
|
1310
|
+
* Fix in Zod:
|
|
1311
|
+
* https://github.com/colinhacks/zod/commit/9340fd51e48576a75adc919bff65dbc4a5d4c99b
|
|
1312
|
+
*/
|
|
1313
|
+
emoji: () => {
|
|
1314
|
+
if (emojiRegex === void 0) {
|
|
1315
|
+
emojiRegex = RegExp("^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$", "u");
|
|
1316
|
+
}
|
|
1317
|
+
return emojiRegex;
|
|
1318
|
+
},
|
|
1319
|
+
/**
|
|
1320
|
+
* Unused
|
|
1321
|
+
*/
|
|
1322
|
+
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}$/,
|
|
1323
|
+
/**
|
|
1324
|
+
* Unused
|
|
1325
|
+
*/
|
|
1326
|
+
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])$/,
|
|
1327
|
+
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])$/,
|
|
1328
|
+
/**
|
|
1329
|
+
* Unused
|
|
1330
|
+
*/
|
|
1331
|
+
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})))$/,
|
|
1332
|
+
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])$/,
|
|
1333
|
+
base64: /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,
|
|
1334
|
+
base64url: /^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,
|
|
1335
|
+
nanoid: /^[a-zA-Z0-9_-]{21}$/,
|
|
1336
|
+
jwt: /^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/
|
|
1337
|
+
};
|
|
1338
|
+
function parseStringDef(def, refs) {
|
|
1339
|
+
const res = {
|
|
1340
|
+
type: "string"
|
|
1341
|
+
};
|
|
1342
|
+
if (def.checks) {
|
|
1343
|
+
for (const check of def.checks) {
|
|
1344
|
+
const checkDef = check._zod?.def;
|
|
1345
|
+
if (checkDef) {
|
|
1346
|
+
switch (checkDef.check) {
|
|
1347
|
+
case "min_length":
|
|
1348
|
+
let minLengthMessage = checkDef.message;
|
|
1349
|
+
if (!minLengthMessage && checkDef.error && typeof checkDef.error === "function") {
|
|
1350
|
+
try {
|
|
1351
|
+
minLengthMessage = checkDef.error();
|
|
1352
|
+
} catch (e) {
|
|
1353
|
+
}
|
|
1354
|
+
}
|
|
1355
|
+
setResponseValueAndErrors(res, "minLength", typeof res.minLength === "number" ? Math.max(res.minLength, checkDef.minimum) : checkDef.minimum, minLengthMessage, refs);
|
|
1356
|
+
break;
|
|
1357
|
+
case "max_length":
|
|
1358
|
+
let maxLengthMessage = checkDef.message;
|
|
1359
|
+
if (!maxLengthMessage && checkDef.error && typeof checkDef.error === "function") {
|
|
1360
|
+
try {
|
|
1361
|
+
maxLengthMessage = checkDef.error();
|
|
1362
|
+
} catch (e) {
|
|
1363
|
+
}
|
|
1364
|
+
}
|
|
1365
|
+
setResponseValueAndErrors(res, "maxLength", typeof res.maxLength === "number" ? Math.min(res.maxLength, checkDef.maximum) : checkDef.maximum, maxLengthMessage, refs);
|
|
1366
|
+
break;
|
|
1367
|
+
case "length_equals":
|
|
1368
|
+
let message = checkDef.message;
|
|
1369
|
+
if (!message && checkDef.error && typeof checkDef.error === "function") {
|
|
1370
|
+
try {
|
|
1371
|
+
message = checkDef.error();
|
|
1372
|
+
} catch (e) {
|
|
1373
|
+
}
|
|
1374
|
+
}
|
|
1375
|
+
const length = checkDef.length;
|
|
1376
|
+
if (length !== void 0) {
|
|
1377
|
+
setResponseValueAndErrors(res, "minLength", typeof res.minLength === "number" ? Math.max(res.minLength, length) : length, message, refs);
|
|
1378
|
+
setResponseValueAndErrors(res, "maxLength", typeof res.maxLength === "number" ? Math.min(res.maxLength, length) : length, message, refs);
|
|
1379
|
+
}
|
|
1380
|
+
break;
|
|
1381
|
+
case "string_format":
|
|
1382
|
+
let formatMessage = checkDef.message;
|
|
1383
|
+
if (!formatMessage && checkDef.error && typeof checkDef.error === "function") {
|
|
1384
|
+
try {
|
|
1385
|
+
formatMessage = checkDef.error();
|
|
1386
|
+
} catch (e) {
|
|
1387
|
+
}
|
|
1388
|
+
}
|
|
1389
|
+
const format = checkDef.format;
|
|
1390
|
+
if (format === "email") {
|
|
1391
|
+
switch (refs.emailStrategy) {
|
|
1392
|
+
case "format:email":
|
|
1393
|
+
addFormat(res, "email", formatMessage, refs);
|
|
1394
|
+
break;
|
|
1395
|
+
case "format:idn-email":
|
|
1396
|
+
addFormat(res, "idn-email", formatMessage, refs);
|
|
1397
|
+
break;
|
|
1398
|
+
case "pattern:zod":
|
|
1399
|
+
addPattern(res, zodPatterns.email, formatMessage, refs);
|
|
1400
|
+
break;
|
|
1401
|
+
}
|
|
1402
|
+
} else if (format === "uri") {
|
|
1403
|
+
addFormat(res, "uri", formatMessage, refs);
|
|
1404
|
+
} else if (format === "url") {
|
|
1405
|
+
addFormat(res, "uri", formatMessage, refs);
|
|
1406
|
+
} else if (format === "uuid") {
|
|
1407
|
+
addFormat(res, "uuid", formatMessage, refs);
|
|
1408
|
+
} else if (format === "date-time") {
|
|
1409
|
+
addFormat(res, "date-time", formatMessage, refs);
|
|
1410
|
+
} else if (format === "date") {
|
|
1411
|
+
addFormat(res, "date", formatMessage, refs);
|
|
1412
|
+
} else if (format === "time") {
|
|
1413
|
+
addFormat(res, "time", formatMessage, refs);
|
|
1414
|
+
} else if (format === "duration") {
|
|
1415
|
+
addFormat(res, "duration", formatMessage, refs);
|
|
1416
|
+
} else if (format === "datetime") {
|
|
1417
|
+
addFormat(res, "date-time", formatMessage, refs);
|
|
1418
|
+
} else if (format === "ipv4") {
|
|
1419
|
+
addFormat(res, "ipv4", formatMessage, refs);
|
|
1420
|
+
} else if (format === "ipv6") {
|
|
1421
|
+
addFormat(res, "ipv6", formatMessage, refs);
|
|
1422
|
+
} else if (format === "ulid") {
|
|
1423
|
+
addPattern(res, zodPatterns.ulid, formatMessage, refs);
|
|
1424
|
+
} else if (format === "nanoid") {
|
|
1425
|
+
addPattern(res, zodPatterns.nanoid, formatMessage, refs);
|
|
1426
|
+
} else if (format === "cuid") {
|
|
1427
|
+
addPattern(res, zodPatterns.cuid, formatMessage, refs);
|
|
1428
|
+
} else if (format === "cuid2") {
|
|
1429
|
+
addPattern(res, zodPatterns.cuid2, formatMessage, refs);
|
|
1430
|
+
} else if (format === "base64") {
|
|
1431
|
+
switch (refs.base64Strategy) {
|
|
1432
|
+
case "format:binary":
|
|
1433
|
+
addFormat(res, "binary", formatMessage, refs);
|
|
1434
|
+
break;
|
|
1435
|
+
case "contentEncoding:base64":
|
|
1436
|
+
default:
|
|
1437
|
+
if (formatMessage && refs.errorMessages) {
|
|
1438
|
+
res.errorMessage = {
|
|
1439
|
+
...res.errorMessage,
|
|
1440
|
+
contentEncoding: formatMessage
|
|
1441
|
+
};
|
|
1442
|
+
}
|
|
1443
|
+
res.contentEncoding = "base64";
|
|
1444
|
+
break;
|
|
1445
|
+
case "pattern:zod":
|
|
1446
|
+
addPattern(res, zodPatterns.base64, formatMessage, refs);
|
|
1447
|
+
break;
|
|
1448
|
+
}
|
|
1449
|
+
} else if (format === "regex" && checkDef.pattern) {
|
|
1450
|
+
let message2 = checkDef.message;
|
|
1451
|
+
if (!message2 && checkDef.error && typeof checkDef.error === "function") {
|
|
1452
|
+
try {
|
|
1453
|
+
message2 = checkDef.error();
|
|
1454
|
+
} catch (e) {
|
|
1455
|
+
}
|
|
1456
|
+
}
|
|
1457
|
+
addPattern(res, checkDef.pattern, message2, refs);
|
|
1458
|
+
} else if (checkDef.pattern) {
|
|
1459
|
+
let message2 = checkDef.message;
|
|
1460
|
+
if (!message2 && checkDef.error && typeof checkDef.error === "function") {
|
|
1461
|
+
try {
|
|
1462
|
+
message2 = checkDef.error();
|
|
1463
|
+
} catch (e) {
|
|
1464
|
+
}
|
|
1465
|
+
}
|
|
1466
|
+
if (refs.patternStrategy === "preserve") {
|
|
1467
|
+
let preservedPattern;
|
|
1468
|
+
if (checkDef.prefix !== void 0) {
|
|
1469
|
+
preservedPattern = `^${checkDef.prefix}`;
|
|
1470
|
+
} else if (checkDef.suffix !== void 0) {
|
|
1471
|
+
preservedPattern = `${checkDef.suffix}$`;
|
|
1472
|
+
} else if (checkDef.includes !== void 0) {
|
|
1473
|
+
preservedPattern = checkDef.includes;
|
|
1474
|
+
}
|
|
1475
|
+
if (preservedPattern !== void 0) {
|
|
1476
|
+
addPattern(res, new RegExp(preservedPattern), message2, refs);
|
|
1477
|
+
break;
|
|
1478
|
+
}
|
|
1479
|
+
}
|
|
1480
|
+
let normalizedPattern = checkDef.pattern;
|
|
1481
|
+
const patternSource = checkDef.pattern.source;
|
|
1482
|
+
if (patternSource.startsWith("^") && patternSource.endsWith(".*")) {
|
|
1483
|
+
normalizedPattern = new RegExp(patternSource.slice(0, -2), checkDef.pattern.flags);
|
|
1484
|
+
} else if (patternSource.startsWith(".*") && patternSource.endsWith("$")) {
|
|
1485
|
+
normalizedPattern = new RegExp(patternSource.slice(2), checkDef.pattern.flags);
|
|
1486
|
+
}
|
|
1487
|
+
addPattern(res, normalizedPattern, message2, refs);
|
|
1488
|
+
}
|
|
1489
|
+
break;
|
|
1490
|
+
}
|
|
1491
|
+
continue;
|
|
1492
|
+
}
|
|
1493
|
+
if (check.kind) {
|
|
1494
|
+
switch (check.kind) {
|
|
1495
|
+
case "min":
|
|
1496
|
+
setResponseValueAndErrors(res, "minLength", typeof res.minLength === "number" ? Math.max(res.minLength, check.value) : check.value, check.message, refs);
|
|
1497
|
+
break;
|
|
1498
|
+
case "max":
|
|
1499
|
+
setResponseValueAndErrors(res, "maxLength", typeof res.maxLength === "number" ? Math.min(res.maxLength, check.value) : check.value, check.message, refs);
|
|
1500
|
+
break;
|
|
1501
|
+
case "email":
|
|
1502
|
+
switch (refs.emailStrategy) {
|
|
1503
|
+
case "format:email":
|
|
1504
|
+
addFormat(res, "email", check.message, refs);
|
|
1505
|
+
break;
|
|
1506
|
+
case "format:idn-email":
|
|
1507
|
+
addFormat(res, "idn-email", check.message, refs);
|
|
1508
|
+
break;
|
|
1509
|
+
case "pattern:zod":
|
|
1510
|
+
addPattern(res, zodPatterns.email, check.message, refs);
|
|
1511
|
+
break;
|
|
1512
|
+
}
|
|
1513
|
+
break;
|
|
1514
|
+
case "url":
|
|
1515
|
+
addFormat(res, "uri", check.message, refs);
|
|
1516
|
+
break;
|
|
1517
|
+
case "uuid":
|
|
1518
|
+
addFormat(res, "uuid", check.message, refs);
|
|
1519
|
+
break;
|
|
1520
|
+
case "regex":
|
|
1521
|
+
addPattern(res, check.regex, check.message, refs);
|
|
1522
|
+
break;
|
|
1523
|
+
case "cuid":
|
|
1524
|
+
addPattern(res, zodPatterns.cuid, check.message, refs);
|
|
1525
|
+
break;
|
|
1526
|
+
case "cuid2":
|
|
1527
|
+
addPattern(res, zodPatterns.cuid2, check.message, refs);
|
|
1528
|
+
break;
|
|
1529
|
+
case "startsWith":
|
|
1530
|
+
addPattern(res, RegExp(`^${escapeLiteralCheckValue(check.value, refs)}`), check.message, refs);
|
|
1531
|
+
break;
|
|
1532
|
+
case "endsWith":
|
|
1533
|
+
addPattern(res, RegExp(`${escapeLiteralCheckValue(check.value, refs)}$`), check.message, refs);
|
|
1534
|
+
break;
|
|
1535
|
+
case "datetime":
|
|
1536
|
+
addFormat(res, "date-time", check.message, refs);
|
|
1537
|
+
break;
|
|
1538
|
+
case "date":
|
|
1539
|
+
addFormat(res, "date", check.message, refs);
|
|
1540
|
+
break;
|
|
1541
|
+
case "time":
|
|
1542
|
+
addFormat(res, "time", check.message, refs);
|
|
1543
|
+
break;
|
|
1544
|
+
case "duration":
|
|
1545
|
+
addFormat(res, "duration", check.message, refs);
|
|
1546
|
+
break;
|
|
1547
|
+
case "length":
|
|
1548
|
+
setResponseValueAndErrors(res, "minLength", typeof res.minLength === "number" ? Math.max(res.minLength, check.value) : check.value, check.message, refs);
|
|
1549
|
+
setResponseValueAndErrors(res, "maxLength", typeof res.maxLength === "number" ? Math.min(res.maxLength, check.value) : check.value, check.message, refs);
|
|
1550
|
+
break;
|
|
1551
|
+
case "includes": {
|
|
1552
|
+
addPattern(res, RegExp(escapeLiteralCheckValue(check.value, refs)), check.message, refs);
|
|
1553
|
+
break;
|
|
1554
|
+
}
|
|
1555
|
+
case "ip": {
|
|
1556
|
+
if (check.version !== "v6") {
|
|
1557
|
+
addFormat(res, "ipv4", check.message, refs);
|
|
1558
|
+
}
|
|
1559
|
+
if (check.version !== "v4") {
|
|
1560
|
+
addFormat(res, "ipv6", check.message, refs);
|
|
1561
|
+
}
|
|
1562
|
+
break;
|
|
1563
|
+
}
|
|
1564
|
+
case "base64url":
|
|
1565
|
+
addPattern(res, zodPatterns.base64url, check.message, refs);
|
|
1566
|
+
break;
|
|
1567
|
+
case "jwt":
|
|
1568
|
+
addPattern(res, zodPatterns.jwt, check.message, refs);
|
|
1569
|
+
break;
|
|
1570
|
+
case "cidr": {
|
|
1571
|
+
if (check.version !== "v6") {
|
|
1572
|
+
addPattern(res, zodPatterns.ipv4Cidr, check.message, refs);
|
|
1573
|
+
}
|
|
1574
|
+
if (check.version !== "v4") {
|
|
1575
|
+
addPattern(res, zodPatterns.ipv6Cidr, check.message, refs);
|
|
1576
|
+
}
|
|
1577
|
+
break;
|
|
1578
|
+
}
|
|
1579
|
+
case "emoji":
|
|
1580
|
+
addPattern(res, zodPatterns.emoji(), check.message, refs);
|
|
1581
|
+
break;
|
|
1582
|
+
case "ulid": {
|
|
1583
|
+
addPattern(res, zodPatterns.ulid, check.message, refs);
|
|
1584
|
+
break;
|
|
1585
|
+
}
|
|
1586
|
+
case "base64": {
|
|
1587
|
+
switch (refs.base64Strategy) {
|
|
1588
|
+
case "format:binary": {
|
|
1589
|
+
addFormat(res, "binary", check.message, refs);
|
|
1590
|
+
break;
|
|
1591
|
+
}
|
|
1592
|
+
case "contentEncoding:base64": {
|
|
1593
|
+
setResponseValueAndErrors(res, "contentEncoding", "base64", check.message, refs);
|
|
1594
|
+
break;
|
|
1595
|
+
}
|
|
1596
|
+
case "pattern:zod": {
|
|
1597
|
+
addPattern(res, zodPatterns.base64, check.message, refs);
|
|
1598
|
+
break;
|
|
1599
|
+
}
|
|
1600
|
+
}
|
|
1601
|
+
break;
|
|
1602
|
+
}
|
|
1603
|
+
case "nanoid": {
|
|
1604
|
+
addPattern(res, zodPatterns.nanoid, check.message, refs);
|
|
1605
|
+
}
|
|
1606
|
+
}
|
|
1607
|
+
}
|
|
1608
|
+
}
|
|
1609
|
+
}
|
|
1610
|
+
return res;
|
|
1611
|
+
}
|
|
1612
|
+
function escapeLiteralCheckValue(literal, refs) {
|
|
1613
|
+
return refs.patternStrategy === "escape" ? escapeNonAlphaNumeric(literal) : literal;
|
|
1614
|
+
}
|
|
1615
|
+
var ALPHA_NUMERIC = new Set("ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvxyz0123456789");
|
|
1616
|
+
function escapeNonAlphaNumeric(source) {
|
|
1617
|
+
let result = "";
|
|
1618
|
+
for (let i = 0; i < source.length; i++) {
|
|
1619
|
+
if (!ALPHA_NUMERIC.has(source[i])) {
|
|
1620
|
+
result += "\\";
|
|
1621
|
+
}
|
|
1622
|
+
result += source[i];
|
|
1623
|
+
}
|
|
1624
|
+
return result;
|
|
1625
|
+
}
|
|
1626
|
+
function addFormat(schema, value, message, refs) {
|
|
1627
|
+
if (schema.format || schema.anyOf?.some((x) => x.format)) {
|
|
1628
|
+
if (!schema.anyOf) {
|
|
1629
|
+
schema.anyOf = [];
|
|
1630
|
+
}
|
|
1631
|
+
if (schema.format) {
|
|
1632
|
+
schema.anyOf.push({
|
|
1633
|
+
format: schema.format,
|
|
1634
|
+
...schema.errorMessage && refs.errorMessages && {
|
|
1635
|
+
errorMessage: { format: schema.errorMessage.format }
|
|
1636
|
+
}
|
|
1637
|
+
});
|
|
1638
|
+
delete schema.format;
|
|
1639
|
+
if (schema.errorMessage) {
|
|
1640
|
+
delete schema.errorMessage.format;
|
|
1641
|
+
if (Object.keys(schema.errorMessage).length === 0) {
|
|
1642
|
+
delete schema.errorMessage;
|
|
1643
|
+
}
|
|
1644
|
+
}
|
|
1645
|
+
}
|
|
1646
|
+
schema.anyOf.push({
|
|
1647
|
+
format: value,
|
|
1648
|
+
...message && refs.errorMessages && { errorMessage: { format: message } }
|
|
1649
|
+
});
|
|
1650
|
+
} else {
|
|
1651
|
+
setResponseValueAndErrors(schema, "format", value, message, refs);
|
|
1652
|
+
}
|
|
1653
|
+
}
|
|
1654
|
+
function addPattern(schema, regex, message, refs) {
|
|
1655
|
+
if (schema.pattern || schema.allOf?.some((x) => x.pattern)) {
|
|
1656
|
+
if (!schema.allOf) {
|
|
1657
|
+
schema.allOf = [];
|
|
1658
|
+
}
|
|
1659
|
+
if (schema.pattern) {
|
|
1660
|
+
schema.allOf.push({
|
|
1661
|
+
pattern: schema.pattern,
|
|
1662
|
+
...schema.errorMessage && refs.errorMessages && {
|
|
1663
|
+
errorMessage: { pattern: schema.errorMessage.pattern }
|
|
1664
|
+
}
|
|
1665
|
+
});
|
|
1666
|
+
delete schema.pattern;
|
|
1667
|
+
if (schema.errorMessage) {
|
|
1668
|
+
delete schema.errorMessage.pattern;
|
|
1669
|
+
if (Object.keys(schema.errorMessage).length === 0) {
|
|
1670
|
+
delete schema.errorMessage;
|
|
1671
|
+
}
|
|
1672
|
+
}
|
|
1673
|
+
}
|
|
1674
|
+
schema.allOf.push({
|
|
1675
|
+
pattern: stringifyRegExpWithFlags(regex, refs),
|
|
1676
|
+
...message && refs.errorMessages && { errorMessage: { pattern: message } }
|
|
1677
|
+
});
|
|
1678
|
+
} else {
|
|
1679
|
+
setResponseValueAndErrors(schema, "pattern", stringifyRegExpWithFlags(regex, refs), message, refs);
|
|
1680
|
+
}
|
|
1681
|
+
}
|
|
1682
|
+
function stringifyRegExpWithFlags(regex, refs) {
|
|
1683
|
+
if (!refs.applyRegexFlags || !regex.flags) {
|
|
1684
|
+
return regex.source;
|
|
1685
|
+
}
|
|
1686
|
+
const flags = {
|
|
1687
|
+
i: regex.flags.includes("i"),
|
|
1688
|
+
// Case-insensitive
|
|
1689
|
+
m: regex.flags.includes("m"),
|
|
1690
|
+
// `^` and `$` matches adjacent to newline characters
|
|
1691
|
+
s: regex.flags.includes("s")
|
|
1692
|
+
// `.` matches newlines
|
|
1693
|
+
};
|
|
1694
|
+
const source = flags.i ? regex.source.toLowerCase() : regex.source;
|
|
1695
|
+
let pattern = "";
|
|
1696
|
+
let isEscaped = false;
|
|
1697
|
+
let inCharGroup = false;
|
|
1698
|
+
let inCharRange = false;
|
|
1699
|
+
for (let i = 0; i < source.length; i++) {
|
|
1700
|
+
if (isEscaped) {
|
|
1701
|
+
pattern += source[i];
|
|
1702
|
+
isEscaped = false;
|
|
1703
|
+
continue;
|
|
1704
|
+
}
|
|
1705
|
+
if (flags.i) {
|
|
1706
|
+
if (inCharGroup) {
|
|
1707
|
+
if (source[i].match(/[a-z]/)) {
|
|
1708
|
+
if (inCharRange) {
|
|
1709
|
+
pattern += source[i];
|
|
1710
|
+
pattern += `${source[i - 2]}-${source[i]}`.toUpperCase();
|
|
1711
|
+
inCharRange = false;
|
|
1712
|
+
} else if (source[i + 1] === "-" && source[i + 2]?.match(/[a-z]/)) {
|
|
1713
|
+
pattern += source[i];
|
|
1714
|
+
inCharRange = true;
|
|
1715
|
+
} else {
|
|
1716
|
+
pattern += `${source[i]}${source[i].toUpperCase()}`;
|
|
1717
|
+
}
|
|
1718
|
+
continue;
|
|
1719
|
+
}
|
|
1720
|
+
} else if (source[i].match(/[a-z]/)) {
|
|
1721
|
+
pattern += `[${source[i]}${source[i].toUpperCase()}]`;
|
|
1722
|
+
continue;
|
|
1723
|
+
}
|
|
1724
|
+
}
|
|
1725
|
+
if (flags.m) {
|
|
1726
|
+
if (source[i] === "^") {
|
|
1727
|
+
pattern += `(^|(?<=[\r
|
|
1728
|
+
]))`;
|
|
1729
|
+
continue;
|
|
1730
|
+
} else if (source[i] === "$") {
|
|
1731
|
+
pattern += `($|(?=[\r
|
|
1732
|
+
]))`;
|
|
1733
|
+
continue;
|
|
1734
|
+
}
|
|
1735
|
+
}
|
|
1736
|
+
if (flags.s && source[i] === ".") {
|
|
1737
|
+
pattern += inCharGroup ? `${source[i]}\r
|
|
1738
|
+
` : `[${source[i]}\r
|
|
1739
|
+
]`;
|
|
1740
|
+
continue;
|
|
1741
|
+
}
|
|
1742
|
+
pattern += source[i];
|
|
1743
|
+
if (source[i] === "\\") {
|
|
1744
|
+
isEscaped = true;
|
|
1745
|
+
} else if (inCharGroup && source[i] === "]") {
|
|
1746
|
+
inCharGroup = false;
|
|
1747
|
+
} else if (!inCharGroup && source[i] === "[") {
|
|
1748
|
+
inCharGroup = true;
|
|
1749
|
+
}
|
|
1750
|
+
}
|
|
1751
|
+
try {
|
|
1752
|
+
new RegExp(pattern);
|
|
1753
|
+
} catch {
|
|
1754
|
+
console.warn(`Could not convert regex pattern at ${refs.currentPath.join("/")} to a flag-independent form! Falling back to the flag-ignorant source`);
|
|
1755
|
+
return regex.source;
|
|
1756
|
+
}
|
|
1757
|
+
return pattern;
|
|
1758
|
+
}
|
|
1759
|
+
|
|
1760
|
+
// ../../node_modules/.pnpm/@alcyone-labs+zod-to-json-schema@4.0.10_zod@4.1.12/node_modules/@alcyone-labs/zod-to-json-schema/dist/esm/parsers/record.js
|
|
1761
|
+
function parseRecordDef(def, refs) {
|
|
1762
|
+
if (refs.target === "openAi") {
|
|
1763
|
+
console.warn("Warning: OpenAI may not support records in schemas! Try an array of key-value pairs instead.");
|
|
1764
|
+
}
|
|
1765
|
+
const keyTypeDef = def.keyType?.def || def.keyType?._def;
|
|
1766
|
+
const keyTypeType = keyTypeDef?.type || keyTypeDef?.typeName;
|
|
1767
|
+
if (refs.target === "openApi3" && (keyTypeType === "enum" || keyTypeType === "ZodEnum")) {
|
|
1768
|
+
const enumValues = keyTypeDef?.entries ? Object.values(keyTypeDef.entries) : keyTypeDef?.values;
|
|
1769
|
+
const valueTypeDef2 = def.valueType?.def || def.valueType?._def;
|
|
1770
|
+
if (enumValues && Array.isArray(enumValues)) {
|
|
1771
|
+
return {
|
|
1772
|
+
type: "object",
|
|
1773
|
+
required: enumValues,
|
|
1774
|
+
properties: enumValues.reduce((acc, key) => ({
|
|
1775
|
+
...acc,
|
|
1776
|
+
[key]: parseDef(valueTypeDef2, {
|
|
1777
|
+
...refs,
|
|
1778
|
+
currentPath: [...refs.currentPath, "properties", key]
|
|
1779
|
+
}) ?? parseAnyDef(refs)
|
|
1780
|
+
}), {}),
|
|
1781
|
+
additionalProperties: refs.rejectedAdditionalProperties
|
|
1782
|
+
};
|
|
1783
|
+
}
|
|
1784
|
+
}
|
|
1785
|
+
const actualValueType = def.valueType || def.keyType;
|
|
1786
|
+
const valueTypeDef = actualValueType?.def || actualValueType?._def;
|
|
1787
|
+
const schema = {
|
|
1788
|
+
type: "object",
|
|
1789
|
+
additionalProperties: valueTypeDef ? parseDef(valueTypeDef, {
|
|
1790
|
+
...refs,
|
|
1791
|
+
currentPath: [...refs.currentPath, "additionalProperties"]
|
|
1792
|
+
}) : refs.allowedAdditionalProperties
|
|
1793
|
+
};
|
|
1794
|
+
if (refs.target === "openApi3") {
|
|
1795
|
+
return schema;
|
|
1796
|
+
}
|
|
1797
|
+
if ((keyTypeType === "string" || keyTypeType === "ZodString") && keyTypeDef?.checks?.length) {
|
|
1798
|
+
const { type, ...keyType } = parseStringDef(keyTypeDef, refs);
|
|
1799
|
+
return {
|
|
1800
|
+
...schema,
|
|
1801
|
+
propertyNames: keyType
|
|
1802
|
+
};
|
|
1803
|
+
} else if (keyTypeType === "enum" || keyTypeType === "ZodEnum") {
|
|
1804
|
+
const enumValues = keyTypeDef?.entries ? Object.values(keyTypeDef.entries) : keyTypeDef?.values;
|
|
1805
|
+
return {
|
|
1806
|
+
...schema,
|
|
1807
|
+
propertyNames: {
|
|
1808
|
+
enum: enumValues
|
|
1809
|
+
}
|
|
1810
|
+
};
|
|
1811
|
+
} else if ((keyTypeType === "branded" || keyTypeType === "ZodBranded") && keyTypeDef?.type) {
|
|
1812
|
+
const brandedTypeDef = keyTypeDef.type?.def || keyTypeDef.type?._def;
|
|
1813
|
+
const brandedTypeType = brandedTypeDef?.type || brandedTypeDef?.typeName;
|
|
1814
|
+
if ((brandedTypeType === "string" || brandedTypeType === "ZodString") && brandedTypeDef?.checks?.length) {
|
|
1815
|
+
const { type, ...keyType } = parseBrandedDef(keyTypeDef, refs);
|
|
1816
|
+
return {
|
|
1817
|
+
...schema,
|
|
1818
|
+
propertyNames: keyType
|
|
1819
|
+
};
|
|
1820
|
+
}
|
|
1821
|
+
}
|
|
1822
|
+
return schema;
|
|
1823
|
+
}
|
|
1824
|
+
|
|
1825
|
+
// ../../node_modules/.pnpm/@alcyone-labs+zod-to-json-schema@4.0.10_zod@4.1.12/node_modules/@alcyone-labs/zod-to-json-schema/dist/esm/parsers/map.js
|
|
1826
|
+
function parseMapDef(def, refs) {
|
|
1827
|
+
if (refs.mapStrategy === "record") {
|
|
1828
|
+
return parseRecordDef(def, refs);
|
|
1829
|
+
}
|
|
1830
|
+
const keys = parseDef(def.keyType._def, {
|
|
1831
|
+
...refs,
|
|
1832
|
+
currentPath: [...refs.currentPath, "items", "items", "0"]
|
|
1833
|
+
}) || parseAnyDef(refs);
|
|
1834
|
+
const values = parseDef(def.valueType._def, {
|
|
1835
|
+
...refs,
|
|
1836
|
+
currentPath: [...refs.currentPath, "items", "items", "1"]
|
|
1837
|
+
}) || parseAnyDef(refs);
|
|
1838
|
+
return {
|
|
1839
|
+
type: "array",
|
|
1840
|
+
maxItems: 125,
|
|
1841
|
+
items: {
|
|
1842
|
+
type: "array",
|
|
1843
|
+
items: [keys, values],
|
|
1844
|
+
minItems: 2,
|
|
1845
|
+
maxItems: 2
|
|
1846
|
+
}
|
|
1847
|
+
};
|
|
1848
|
+
}
|
|
1849
|
+
|
|
1850
|
+
// ../../node_modules/.pnpm/@alcyone-labs+zod-to-json-schema@4.0.10_zod@4.1.12/node_modules/@alcyone-labs/zod-to-json-schema/dist/esm/parsers/nativeEnum.js
|
|
1851
|
+
function parseNativeEnumDef(def) {
|
|
1852
|
+
const object = def.entries || def.values;
|
|
1853
|
+
const actualKeys = Object.keys(object).filter((key) => {
|
|
1854
|
+
return typeof object[object[key]] !== "number";
|
|
1855
|
+
});
|
|
1856
|
+
const actualValues = actualKeys.map((key) => object[key]);
|
|
1857
|
+
const parsedTypes = Array.from(new Set(actualValues.map((values) => typeof values)));
|
|
1858
|
+
return {
|
|
1859
|
+
type: parsedTypes.length === 1 ? parsedTypes[0] === "string" ? "string" : "number" : ["string", "number"],
|
|
1860
|
+
enum: actualValues
|
|
1861
|
+
};
|
|
1862
|
+
}
|
|
1863
|
+
|
|
1864
|
+
// ../../node_modules/.pnpm/@alcyone-labs+zod-to-json-schema@4.0.10_zod@4.1.12/node_modules/@alcyone-labs/zod-to-json-schema/dist/esm/parsers/never.js
|
|
1865
|
+
function parseNeverDef(refs) {
|
|
1866
|
+
return refs.target === "openAi" ? void 0 : {
|
|
1867
|
+
not: parseAnyDef({
|
|
1868
|
+
...refs,
|
|
1869
|
+
currentPath: [...refs.currentPath, "not"]
|
|
1870
|
+
})
|
|
1871
|
+
};
|
|
1872
|
+
}
|
|
1873
|
+
|
|
1874
|
+
// ../../node_modules/.pnpm/@alcyone-labs+zod-to-json-schema@4.0.10_zod@4.1.12/node_modules/@alcyone-labs/zod-to-json-schema/dist/esm/parsers/null.js
|
|
1875
|
+
function parseNullDef(refs) {
|
|
1876
|
+
return refs.target === "openApi3" ? {
|
|
1877
|
+
enum: ["null"],
|
|
1878
|
+
nullable: true
|
|
1879
|
+
} : {
|
|
1880
|
+
type: "null"
|
|
1881
|
+
};
|
|
1882
|
+
}
|
|
1883
|
+
|
|
1884
|
+
// ../../node_modules/.pnpm/@alcyone-labs+zod-to-json-schema@4.0.10_zod@4.1.12/node_modules/@alcyone-labs/zod-to-json-schema/dist/esm/parsers/nullable.js
|
|
1885
|
+
function parseNullableDef(def, refs) {
|
|
1886
|
+
const innerTypeDef = getInnerTypeDef(def);
|
|
1887
|
+
const innerTypeKey = getDefTypeName(innerTypeDef);
|
|
1888
|
+
if (innerTypeKey && getAllPrimitiveTypeNames().includes(innerTypeKey) && (!innerTypeDef.checks || !innerTypeDef.checks.length)) {
|
|
1889
|
+
if (refs.target === "openApi3") {
|
|
1890
|
+
return {
|
|
1891
|
+
type: primitiveMappings[innerTypeKey],
|
|
1892
|
+
nullable: true
|
|
1893
|
+
};
|
|
1894
|
+
}
|
|
1895
|
+
return {
|
|
1896
|
+
type: [
|
|
1897
|
+
primitiveMappings[innerTypeKey],
|
|
1898
|
+
"null"
|
|
1899
|
+
]
|
|
1900
|
+
};
|
|
1901
|
+
}
|
|
1902
|
+
if (refs.target === "openApi3") {
|
|
1903
|
+
const base2 = parseDef(innerTypeDef, {
|
|
1904
|
+
...refs,
|
|
1905
|
+
currentPath: [...refs.currentPath]
|
|
1906
|
+
});
|
|
1907
|
+
if (base2 && "$ref" in base2) {
|
|
1908
|
+
const result = { allOf: [base2], nullable: true };
|
|
1909
|
+
const refPath = base2.$ref;
|
|
1910
|
+
if (refPath && refPath.includes(refs.definitionPath)) {
|
|
1911
|
+
const pathParts = refPath.split("/");
|
|
1912
|
+
const defName = pathParts[pathParts.length - 1];
|
|
1913
|
+
const definitionSchema = refs.definitions[defName];
|
|
1914
|
+
if (definitionSchema) {
|
|
1915
|
+
let description;
|
|
1916
|
+
if (typeof definitionSchema.meta === "function") {
|
|
1917
|
+
try {
|
|
1918
|
+
const meta = definitionSchema.meta();
|
|
1919
|
+
if (meta && meta.description) {
|
|
1920
|
+
description = meta.description;
|
|
1921
|
+
}
|
|
1922
|
+
} catch (e) {
|
|
1923
|
+
}
|
|
1924
|
+
}
|
|
1925
|
+
if (!description && definitionSchema.description) {
|
|
1926
|
+
description = definitionSchema.description;
|
|
1927
|
+
}
|
|
1928
|
+
if (description) {
|
|
1929
|
+
result.description = description;
|
|
1930
|
+
}
|
|
1931
|
+
}
|
|
1932
|
+
}
|
|
1933
|
+
return result;
|
|
1934
|
+
}
|
|
1935
|
+
return base2 && { ...base2, nullable: true };
|
|
1936
|
+
}
|
|
1937
|
+
const base = parseDef(innerTypeDef, {
|
|
1938
|
+
...refs,
|
|
1939
|
+
currentPath: [...refs.currentPath, "anyOf", "0"]
|
|
1940
|
+
});
|
|
1941
|
+
return base && { anyOf: [base, { type: "null" }] };
|
|
1942
|
+
}
|
|
1943
|
+
|
|
1944
|
+
// ../../node_modules/.pnpm/@alcyone-labs+zod-to-json-schema@4.0.10_zod@4.1.12/node_modules/@alcyone-labs/zod-to-json-schema/dist/esm/parsers/number.js
|
|
1945
|
+
function parseNumberDef(def, refs) {
|
|
1946
|
+
const res = {
|
|
1947
|
+
type: "number"
|
|
1948
|
+
};
|
|
1949
|
+
if (!def.checks)
|
|
1950
|
+
return res;
|
|
1951
|
+
for (const check of def.checks) {
|
|
1952
|
+
const checkDef = check._zod?.def;
|
|
1953
|
+
if (checkDef) {
|
|
1954
|
+
let message = checkDef.message;
|
|
1955
|
+
if (!message && checkDef.error && typeof checkDef.error === "function") {
|
|
1956
|
+
try {
|
|
1957
|
+
message = checkDef.error();
|
|
1958
|
+
} catch (e) {
|
|
1959
|
+
}
|
|
1960
|
+
}
|
|
1961
|
+
switch (checkDef.check) {
|
|
1962
|
+
case "number_format":
|
|
1963
|
+
if (checkDef.format === "safeint") {
|
|
1964
|
+
res.type = "integer";
|
|
1965
|
+
addErrorMessage(res, "type", message, refs);
|
|
1966
|
+
}
|
|
1967
|
+
break;
|
|
1968
|
+
case "greater_than":
|
|
1969
|
+
if (refs.target === "jsonSchema7") {
|
|
1970
|
+
if (checkDef.inclusive) {
|
|
1971
|
+
setResponseValueAndErrors(res, "minimum", checkDef.value, message, refs);
|
|
1972
|
+
} else {
|
|
1973
|
+
setResponseValueAndErrors(res, "exclusiveMinimum", checkDef.value, message, refs);
|
|
1974
|
+
}
|
|
1975
|
+
} else {
|
|
1976
|
+
if (!checkDef.inclusive) {
|
|
1977
|
+
res.exclusiveMinimum = true;
|
|
1978
|
+
}
|
|
1979
|
+
setResponseValueAndErrors(res, "minimum", checkDef.value, message, refs);
|
|
1980
|
+
}
|
|
1981
|
+
break;
|
|
1982
|
+
case "less_than":
|
|
1983
|
+
if (refs.target === "jsonSchema7") {
|
|
1984
|
+
if (checkDef.inclusive) {
|
|
1985
|
+
setResponseValueAndErrors(res, "maximum", checkDef.value, message, refs);
|
|
1986
|
+
} else {
|
|
1987
|
+
setResponseValueAndErrors(res, "exclusiveMaximum", checkDef.value, message, refs);
|
|
1988
|
+
}
|
|
1989
|
+
} else {
|
|
1990
|
+
if (!checkDef.inclusive) {
|
|
1991
|
+
res.exclusiveMaximum = true;
|
|
1992
|
+
}
|
|
1993
|
+
setResponseValueAndErrors(res, "maximum", checkDef.value, message, refs);
|
|
1994
|
+
}
|
|
1995
|
+
break;
|
|
1996
|
+
case "multiple_of":
|
|
1997
|
+
setResponseValueAndErrors(res, "multipleOf", checkDef.value, message, refs);
|
|
1998
|
+
break;
|
|
1999
|
+
}
|
|
2000
|
+
} else {
|
|
2001
|
+
switch (check.kind) {
|
|
2002
|
+
case "int":
|
|
2003
|
+
res.type = "integer";
|
|
2004
|
+
addErrorMessage(res, "type", check.message, refs);
|
|
2005
|
+
break;
|
|
2006
|
+
case "min":
|
|
2007
|
+
if (refs.target === "jsonSchema7") {
|
|
2008
|
+
if (check.inclusive) {
|
|
2009
|
+
setResponseValueAndErrors(res, "minimum", check.value, check.message, refs);
|
|
2010
|
+
} else {
|
|
2011
|
+
setResponseValueAndErrors(res, "exclusiveMinimum", check.value, check.message, refs);
|
|
2012
|
+
}
|
|
2013
|
+
} else {
|
|
2014
|
+
if (!check.inclusive) {
|
|
2015
|
+
res.exclusiveMinimum = true;
|
|
2016
|
+
}
|
|
2017
|
+
setResponseValueAndErrors(res, "minimum", check.value, check.message, refs);
|
|
2018
|
+
}
|
|
2019
|
+
break;
|
|
2020
|
+
case "max":
|
|
2021
|
+
if (refs.target === "jsonSchema7") {
|
|
2022
|
+
if (check.inclusive) {
|
|
2023
|
+
setResponseValueAndErrors(res, "maximum", check.value, check.message, refs);
|
|
2024
|
+
} else {
|
|
2025
|
+
setResponseValueAndErrors(res, "exclusiveMaximum", check.value, check.message, refs);
|
|
2026
|
+
}
|
|
2027
|
+
} else {
|
|
2028
|
+
if (!check.inclusive) {
|
|
2029
|
+
res.exclusiveMaximum = true;
|
|
2030
|
+
}
|
|
2031
|
+
setResponseValueAndErrors(res, "maximum", check.value, check.message, refs);
|
|
2032
|
+
}
|
|
2033
|
+
break;
|
|
2034
|
+
case "multipleOf":
|
|
2035
|
+
setResponseValueAndErrors(res, "multipleOf", check.value, check.message, refs);
|
|
2036
|
+
break;
|
|
2037
|
+
}
|
|
2038
|
+
}
|
|
2039
|
+
}
|
|
2040
|
+
return res;
|
|
2041
|
+
}
|
|
2042
|
+
|
|
2043
|
+
// ../../node_modules/.pnpm/@alcyone-labs+zod-to-json-schema@4.0.10_zod@4.1.12/node_modules/@alcyone-labs/zod-to-json-schema/dist/esm/parsers/object.js
|
|
2044
|
+
function parseObjectDef(def, refs) {
|
|
2045
|
+
const forceOptionalIntoNullable = refs.target === "openAi";
|
|
2046
|
+
const result = {
|
|
2047
|
+
type: "object",
|
|
2048
|
+
properties: {}
|
|
2049
|
+
};
|
|
2050
|
+
const required = [];
|
|
2051
|
+
const shape = def.shape;
|
|
2052
|
+
for (const propName in shape) {
|
|
2053
|
+
let propDef = shape[propName];
|
|
2054
|
+
const propDefInner = propDef.def || propDef._def;
|
|
2055
|
+
if (propDef === void 0 || propDefInner === void 0) {
|
|
2056
|
+
continue;
|
|
2057
|
+
}
|
|
2058
|
+
let propOptional = safeIsOptional(propDef);
|
|
2059
|
+
let parsedDef;
|
|
2060
|
+
if (propOptional && forceOptionalIntoNullable) {
|
|
2061
|
+
const typeName = propDefInner.typeName || propDefInner.type;
|
|
2062
|
+
if (typeName === "ZodOptional" || typeName === "optional") {
|
|
2063
|
+
const innerType = propDefInner.innerType;
|
|
2064
|
+
if (innerType) {
|
|
2065
|
+
const innerTypeDef = innerType.def || innerType._def;
|
|
2066
|
+
innerTypeDef?.type || innerTypeDef?.typeName;
|
|
2067
|
+
const innerParsed = parseDef(innerTypeDef, {
|
|
2068
|
+
...refs,
|
|
2069
|
+
currentPath: [...refs.currentPath, "properties", propName],
|
|
2070
|
+
propertyPath: [...refs.currentPath, "properties", propName]
|
|
2071
|
+
});
|
|
2072
|
+
if (innerParsed && typeof innerParsed === "object" && "type" in innerParsed) {
|
|
2073
|
+
if (typeof innerParsed.type === "string") {
|
|
2074
|
+
parsedDef = {
|
|
2075
|
+
...innerParsed,
|
|
2076
|
+
type: [innerParsed.type, "null"]
|
|
2077
|
+
};
|
|
2078
|
+
} else {
|
|
2079
|
+
parsedDef = innerParsed;
|
|
2080
|
+
}
|
|
2081
|
+
} else {
|
|
2082
|
+
parsedDef = innerParsed;
|
|
2083
|
+
}
|
|
2084
|
+
}
|
|
2085
|
+
}
|
|
2086
|
+
propOptional = false;
|
|
2087
|
+
} else {
|
|
2088
|
+
parsedDef = parseDef(propDefInner, {
|
|
2089
|
+
...refs,
|
|
2090
|
+
currentPath: [...refs.currentPath, "properties", propName],
|
|
2091
|
+
propertyPath: [...refs.currentPath, "properties", propName]
|
|
2092
|
+
});
|
|
2093
|
+
}
|
|
2094
|
+
if (parsedDef === void 0) {
|
|
2095
|
+
continue;
|
|
2096
|
+
}
|
|
2097
|
+
result.properties[propName] = parsedDef;
|
|
2098
|
+
if (!propOptional) {
|
|
2099
|
+
required.push(propName);
|
|
2100
|
+
}
|
|
2101
|
+
}
|
|
2102
|
+
if (required.length) {
|
|
2103
|
+
result.required = required;
|
|
2104
|
+
}
|
|
2105
|
+
const additionalProperties = decideAdditionalProperties(def, refs);
|
|
2106
|
+
if (additionalProperties !== void 0) {
|
|
2107
|
+
result.additionalProperties = additionalProperties;
|
|
2108
|
+
}
|
|
2109
|
+
return result;
|
|
2110
|
+
}
|
|
2111
|
+
function decideAdditionalProperties(def, refs) {
|
|
2112
|
+
if (def.catchall) {
|
|
2113
|
+
const catchallDef = def.catchall.def || def.catchall._def;
|
|
2114
|
+
const catchallType = catchallDef?.type || catchallDef?.typeName;
|
|
2115
|
+
if (catchallType === "never" || catchallType === "ZodNever") {
|
|
2116
|
+
return refs.rejectedAdditionalProperties;
|
|
2117
|
+
} else if (catchallType === "unknown" || catchallType === "ZodUnknown") {
|
|
2118
|
+
return refs.allowedAdditionalProperties;
|
|
2119
|
+
} else {
|
|
2120
|
+
return parseDef(catchallDef, {
|
|
2121
|
+
...refs,
|
|
2122
|
+
currentPath: [...refs.currentPath, "additionalProperties"]
|
|
2123
|
+
});
|
|
2124
|
+
}
|
|
2125
|
+
}
|
|
2126
|
+
switch (def.unknownKeys) {
|
|
2127
|
+
case "passthrough":
|
|
2128
|
+
return refs.allowedAdditionalProperties;
|
|
2129
|
+
case "strict":
|
|
2130
|
+
return refs.rejectedAdditionalProperties;
|
|
2131
|
+
case "strip":
|
|
2132
|
+
return refs.removeAdditionalStrategy === "strict" ? refs.allowedAdditionalProperties : refs.rejectedAdditionalProperties;
|
|
2133
|
+
}
|
|
2134
|
+
return refs.removeAdditionalStrategy === "strict" ? refs.allowedAdditionalProperties : refs.rejectedAdditionalProperties;
|
|
2135
|
+
}
|
|
2136
|
+
function safeIsOptional(schema) {
|
|
2137
|
+
try {
|
|
2138
|
+
return schema.isOptional();
|
|
2139
|
+
} catch {
|
|
2140
|
+
return true;
|
|
2141
|
+
}
|
|
2142
|
+
}
|
|
2143
|
+
|
|
2144
|
+
// ../../node_modules/.pnpm/@alcyone-labs+zod-to-json-schema@4.0.10_zod@4.1.12/node_modules/@alcyone-labs/zod-to-json-schema/dist/esm/parsers/optional.js
|
|
2145
|
+
var parseOptionalDef = (def, refs) => {
|
|
2146
|
+
if (refs.currentPath.toString() === refs.propertyPath?.toString()) {
|
|
2147
|
+
return parseDef(def.innerType._def, refs);
|
|
2148
|
+
}
|
|
2149
|
+
const innerSchema = parseDef(def.innerType._def, {
|
|
2150
|
+
...refs,
|
|
2151
|
+
currentPath: [...refs.currentPath, "anyOf", "1"]
|
|
2152
|
+
});
|
|
2153
|
+
return innerSchema ? {
|
|
2154
|
+
anyOf: [
|
|
2155
|
+
{
|
|
2156
|
+
not: parseAnyDef(refs)
|
|
2157
|
+
},
|
|
2158
|
+
innerSchema
|
|
2159
|
+
]
|
|
2160
|
+
} : parseAnyDef(refs);
|
|
2161
|
+
};
|
|
2162
|
+
|
|
2163
|
+
// ../../node_modules/.pnpm/@alcyone-labs+zod-to-json-schema@4.0.10_zod@4.1.12/node_modules/@alcyone-labs/zod-to-json-schema/dist/esm/parsers/pipeline.js
|
|
2164
|
+
var parsePipelineDef = (def, refs) => {
|
|
2165
|
+
const inDef = def.in?.def || def.in?._def;
|
|
2166
|
+
const outDef = def.out?.def || def.out?._def;
|
|
2167
|
+
const isTransformLike = inDef?.type === "transform" || outDef?.type === "transform";
|
|
2168
|
+
if (isTransformLike) {
|
|
2169
|
+
if (refs.effectStrategy === "input") {
|
|
2170
|
+
return inDef?.type === "transform" ? parseDef(outDef, refs) : parseDef(inDef, refs);
|
|
2171
|
+
} else {
|
|
2172
|
+
return {};
|
|
2173
|
+
}
|
|
2174
|
+
}
|
|
2175
|
+
if (refs.pipeStrategy === "input") {
|
|
2176
|
+
return parseDef(inDef, refs);
|
|
2177
|
+
} else if (refs.pipeStrategy === "output") {
|
|
2178
|
+
return parseDef(outDef, refs);
|
|
2179
|
+
}
|
|
2180
|
+
const a = parseDef(inDef, {
|
|
2181
|
+
...refs,
|
|
2182
|
+
currentPath: [...refs.currentPath, "allOf", "0"]
|
|
2183
|
+
});
|
|
2184
|
+
const b = parseDef(outDef, {
|
|
2185
|
+
...refs,
|
|
2186
|
+
currentPath: [...refs.currentPath, "allOf", a ? "1" : "0"]
|
|
2187
|
+
});
|
|
2188
|
+
return {
|
|
2189
|
+
allOf: [a, b].filter((x) => x !== void 0)
|
|
2190
|
+
};
|
|
2191
|
+
};
|
|
2192
|
+
|
|
2193
|
+
// ../../node_modules/.pnpm/@alcyone-labs+zod-to-json-schema@4.0.10_zod@4.1.12/node_modules/@alcyone-labs/zod-to-json-schema/dist/esm/parsers/promise.js
|
|
2194
|
+
function parsePromiseDef(def, refs) {
|
|
2195
|
+
const innerType = def.innerType || def.type;
|
|
2196
|
+
const innerDef = innerType?.def || innerType?._def;
|
|
2197
|
+
return parseDef(innerDef, refs);
|
|
2198
|
+
}
|
|
2199
|
+
|
|
2200
|
+
// ../../node_modules/.pnpm/@alcyone-labs+zod-to-json-schema@4.0.10_zod@4.1.12/node_modules/@alcyone-labs/zod-to-json-schema/dist/esm/parsers/set.js
|
|
2201
|
+
function parseSetDef(def, refs) {
|
|
2202
|
+
const valueTypeDef = def.valueType?.def || def.valueType?._def;
|
|
2203
|
+
const items = parseDef(valueTypeDef, {
|
|
2204
|
+
...refs,
|
|
2205
|
+
currentPath: [...refs.currentPath, "items"]
|
|
2206
|
+
});
|
|
2207
|
+
const schema = {
|
|
2208
|
+
type: "array",
|
|
2209
|
+
uniqueItems: true,
|
|
2210
|
+
items
|
|
2211
|
+
};
|
|
2212
|
+
if (def.checks) {
|
|
2213
|
+
for (const check of def.checks) {
|
|
2214
|
+
const checkDef = check._zod?.def;
|
|
2215
|
+
if (checkDef) {
|
|
2216
|
+
let message = checkDef.message;
|
|
2217
|
+
if (!message && checkDef.error && typeof checkDef.error === "function") {
|
|
2218
|
+
try {
|
|
2219
|
+
message = checkDef.error();
|
|
2220
|
+
} catch (e) {
|
|
2221
|
+
}
|
|
2222
|
+
}
|
|
2223
|
+
switch (checkDef.check) {
|
|
2224
|
+
case "min_size":
|
|
2225
|
+
setResponseValueAndErrors(schema, "minItems", checkDef.minimum, message, refs);
|
|
2226
|
+
break;
|
|
2227
|
+
case "max_size":
|
|
2228
|
+
setResponseValueAndErrors(schema, "maxItems", checkDef.maximum, message, refs);
|
|
2229
|
+
break;
|
|
2230
|
+
}
|
|
2231
|
+
}
|
|
2232
|
+
}
|
|
2233
|
+
}
|
|
2234
|
+
if (def.minSize) {
|
|
2235
|
+
setResponseValueAndErrors(schema, "minItems", def.minSize.value, def.minSize.message, refs);
|
|
2236
|
+
}
|
|
2237
|
+
if (def.maxSize) {
|
|
2238
|
+
setResponseValueAndErrors(schema, "maxItems", def.maxSize.value, def.maxSize.message, refs);
|
|
2239
|
+
}
|
|
2240
|
+
return schema;
|
|
2241
|
+
}
|
|
2242
|
+
|
|
2243
|
+
// ../../node_modules/.pnpm/@alcyone-labs+zod-to-json-schema@4.0.10_zod@4.1.12/node_modules/@alcyone-labs/zod-to-json-schema/dist/esm/parsers/tuple.js
|
|
2244
|
+
function parseTupleDef(def, refs) {
|
|
2245
|
+
if (def.rest) {
|
|
2246
|
+
return {
|
|
2247
|
+
type: "array",
|
|
2248
|
+
minItems: def.items.length,
|
|
2249
|
+
items: def.items.map((x, i) => parseDef(x._def, {
|
|
2250
|
+
...refs,
|
|
2251
|
+
currentPath: [...refs.currentPath, "items", `${i}`]
|
|
2252
|
+
})).reduce((acc, x) => x === void 0 ? acc : [...acc, x], []),
|
|
2253
|
+
additionalItems: parseDef(def.rest._def, {
|
|
2254
|
+
...refs,
|
|
2255
|
+
currentPath: [...refs.currentPath, "additionalItems"]
|
|
2256
|
+
})
|
|
2257
|
+
};
|
|
2258
|
+
} else {
|
|
2259
|
+
return {
|
|
2260
|
+
type: "array",
|
|
2261
|
+
minItems: def.items.length,
|
|
2262
|
+
maxItems: def.items.length,
|
|
2263
|
+
items: def.items.map((x, i) => parseDef(x._def, {
|
|
2264
|
+
...refs,
|
|
2265
|
+
currentPath: [...refs.currentPath, "items", `${i}`]
|
|
2266
|
+
})).reduce((acc, x) => x === void 0 ? acc : [...acc, x], [])
|
|
2267
|
+
};
|
|
2268
|
+
}
|
|
2269
|
+
}
|
|
2270
|
+
|
|
2271
|
+
// ../../node_modules/.pnpm/@alcyone-labs+zod-to-json-schema@4.0.10_zod@4.1.12/node_modules/@alcyone-labs/zod-to-json-schema/dist/esm/parsers/undefined.js
|
|
2272
|
+
function parseUndefinedDef(refs) {
|
|
2273
|
+
return {
|
|
2274
|
+
not: parseAnyDef(refs)
|
|
2275
|
+
};
|
|
2276
|
+
}
|
|
2277
|
+
|
|
2278
|
+
// ../../node_modules/.pnpm/@alcyone-labs+zod-to-json-schema@4.0.10_zod@4.1.12/node_modules/@alcyone-labs/zod-to-json-schema/dist/esm/parsers/union.js
|
|
2279
|
+
var primitiveMappings2 = {
|
|
2280
|
+
// Zod V3 type names
|
|
2281
|
+
ZodString: "string",
|
|
2282
|
+
ZodNumber: "number",
|
|
2283
|
+
ZodBigInt: "integer",
|
|
2284
|
+
ZodBoolean: "boolean",
|
|
2285
|
+
ZodNull: "null",
|
|
2286
|
+
// Zod V4 type names
|
|
2287
|
+
string: "string",
|
|
2288
|
+
number: "number",
|
|
2289
|
+
bigint: "integer",
|
|
2290
|
+
boolean: "boolean",
|
|
2291
|
+
null: "null"
|
|
2292
|
+
};
|
|
2293
|
+
var extractMetaInfoForSchema = (schema) => {
|
|
2294
|
+
if (!schema || !schema._def)
|
|
2295
|
+
return;
|
|
2296
|
+
let metaInfo = {};
|
|
2297
|
+
if (schema.description) {
|
|
2298
|
+
metaInfo.description = schema.description;
|
|
2299
|
+
}
|
|
2300
|
+
if (typeof schema.meta === "function") {
|
|
2301
|
+
try {
|
|
2302
|
+
const meta = schema.meta();
|
|
2303
|
+
if (meta && typeof meta === "object") {
|
|
2304
|
+
metaInfo = { ...metaInfo, ...meta };
|
|
2305
|
+
}
|
|
2306
|
+
} catch (e) {
|
|
2307
|
+
}
|
|
2308
|
+
}
|
|
2309
|
+
if (Object.keys(metaInfo).length > 0) {
|
|
2310
|
+
setSchemaMetaInfo(schema._def, metaInfo);
|
|
2311
|
+
}
|
|
2312
|
+
};
|
|
2313
|
+
function parseUnionDef(def, refs) {
|
|
2314
|
+
if (refs.target === "openApi3")
|
|
2315
|
+
return asAnyOf(def, refs);
|
|
2316
|
+
const options = def.options instanceof Map ? Array.from(def.options.values()) : def.options;
|
|
2317
|
+
options.forEach((option) => extractMetaInfoForSchema(option));
|
|
2318
|
+
if (options.every((x) => {
|
|
2319
|
+
const typeKey = getDefTypeName(x._def);
|
|
2320
|
+
return typeKey && typeKey in primitiveMappings2 && (!x._def.checks || !x._def.checks.length);
|
|
2321
|
+
})) {
|
|
2322
|
+
const types = options.reduce((types2, x) => {
|
|
2323
|
+
const typeKey = getDefTypeName(x._def);
|
|
2324
|
+
const type = typeKey ? primitiveMappings2[typeKey] : void 0;
|
|
2325
|
+
return type && !types2.includes(type) ? [...types2, type] : types2;
|
|
2326
|
+
}, []);
|
|
2327
|
+
return {
|
|
2328
|
+
type: types.length > 1 ? types : types[0]
|
|
2329
|
+
};
|
|
2330
|
+
} else if (options.every((x) => {
|
|
2331
|
+
const typeKey = getDefTypeName(x._def);
|
|
2332
|
+
const hasDescription = x.description || getSchemaMetaInfo(x._def)?.description;
|
|
2333
|
+
return typeKey && (typeKey === "ZodLiteral" || typeKey === "literal") && !hasDescription;
|
|
2334
|
+
})) {
|
|
2335
|
+
const types = options.reduce((acc, x) => {
|
|
2336
|
+
const value = x._def.values ? x._def.values[0] : x._def.value;
|
|
2337
|
+
const type = typeof value;
|
|
2338
|
+
switch (type) {
|
|
2339
|
+
case "string":
|
|
2340
|
+
case "number":
|
|
2341
|
+
case "boolean":
|
|
2342
|
+
return [...acc, type];
|
|
2343
|
+
case "bigint":
|
|
2344
|
+
return [...acc, "integer"];
|
|
2345
|
+
case "object":
|
|
2346
|
+
if (value === null)
|
|
2347
|
+
return [...acc, "null"];
|
|
2348
|
+
case "symbol":
|
|
2349
|
+
case "undefined":
|
|
2350
|
+
case "function":
|
|
2351
|
+
default:
|
|
2352
|
+
return acc;
|
|
2353
|
+
}
|
|
2354
|
+
}, []);
|
|
2355
|
+
if (types.length === options.length) {
|
|
2356
|
+
const uniqueTypes = types.filter((x, i, a) => a.indexOf(x) === i);
|
|
2357
|
+
return {
|
|
2358
|
+
type: uniqueTypes.length > 1 ? uniqueTypes : uniqueTypes[0],
|
|
2359
|
+
enum: options.reduce((acc, x) => {
|
|
2360
|
+
const value = x._def.values ? x._def.values[0] : x._def.value;
|
|
2361
|
+
return acc.includes(value) ? acc : [...acc, value];
|
|
2362
|
+
}, [])
|
|
2363
|
+
};
|
|
2364
|
+
}
|
|
2365
|
+
} else if (options.every((x) => {
|
|
2366
|
+
const typeKey = getDefTypeName(x._def);
|
|
2367
|
+
return typeKey === "ZodEnum" || typeKey === "enum";
|
|
2368
|
+
})) {
|
|
2369
|
+
return {
|
|
2370
|
+
type: "string",
|
|
2371
|
+
enum: options.reduce((acc, x) => {
|
|
2372
|
+
const values = x._def.entries ? Object.values(x._def.entries) : x._def.values;
|
|
2373
|
+
return [...acc, ...values.filter((x2) => !acc.includes(x2))];
|
|
2374
|
+
}, [])
|
|
2375
|
+
};
|
|
2376
|
+
}
|
|
2377
|
+
return asAnyOf(def, refs);
|
|
2378
|
+
}
|
|
2379
|
+
var asAnyOf = (def, refs) => {
|
|
2380
|
+
const anyOf = (def.options instanceof Map ? Array.from(def.options.values()) : def.options).map((x, i) => parseDef(x._def, {
|
|
2381
|
+
...refs,
|
|
2382
|
+
currentPath: [...refs.currentPath, "anyOf", `${i}`]
|
|
2383
|
+
})).filter((x) => !!x && (!refs.strictUnions || typeof x === "object" && Object.keys(x).length > 0));
|
|
2384
|
+
return anyOf.length ? { anyOf } : void 0;
|
|
2385
|
+
};
|
|
2386
|
+
|
|
2387
|
+
// ../../node_modules/.pnpm/@alcyone-labs+zod-to-json-schema@4.0.10_zod@4.1.12/node_modules/@alcyone-labs/zod-to-json-schema/dist/esm/parsers/unknown.js
|
|
2388
|
+
function parseUnknownDef(refs) {
|
|
2389
|
+
return parseAnyDef(refs);
|
|
2390
|
+
}
|
|
2391
|
+
|
|
2392
|
+
// ../../node_modules/.pnpm/@alcyone-labs+zod-to-json-schema@4.0.10_zod@4.1.12/node_modules/@alcyone-labs/zod-to-json-schema/dist/esm/parsers/readonly.js
|
|
2393
|
+
var parseReadonlyDef = (def, refs) => {
|
|
2394
|
+
return parseDef(def.innerType._def, refs);
|
|
2395
|
+
};
|
|
2396
|
+
|
|
2397
|
+
// ../../node_modules/.pnpm/@alcyone-labs+zod-to-json-schema@4.0.10_zod@4.1.12/node_modules/@alcyone-labs/zod-to-json-schema/dist/esm/selectParser.js
|
|
2398
|
+
var selectParser = (def, typeName, refs) => {
|
|
2399
|
+
const actualType = typeName || def.type;
|
|
2400
|
+
switch (actualType) {
|
|
2401
|
+
case "ZodString":
|
|
2402
|
+
case "string":
|
|
2403
|
+
return parseStringDef(def, refs);
|
|
2404
|
+
case "ZodNumber":
|
|
2405
|
+
case "number":
|
|
2406
|
+
case ZodFirstPartyTypeKind.ZodNumber:
|
|
2407
|
+
return parseNumberDef(def, refs);
|
|
2408
|
+
case "ZodObject":
|
|
2409
|
+
case "object":
|
|
2410
|
+
case ZodFirstPartyTypeKind.ZodObject:
|
|
2411
|
+
return parseObjectDef(def, refs);
|
|
2412
|
+
case "ZodBigInt":
|
|
2413
|
+
case "bigint":
|
|
2414
|
+
case ZodFirstPartyTypeKind.ZodBigInt:
|
|
2415
|
+
return parseBigintDef(def, refs);
|
|
2416
|
+
case "ZodBoolean":
|
|
2417
|
+
case "boolean":
|
|
2418
|
+
case ZodFirstPartyTypeKind.ZodBoolean:
|
|
2419
|
+
return parseBooleanDef();
|
|
2420
|
+
case "ZodDate":
|
|
2421
|
+
case "date":
|
|
2422
|
+
case ZodFirstPartyTypeKind.ZodDate:
|
|
2423
|
+
return parseDateDef(def, refs);
|
|
2424
|
+
case "ZodUndefined":
|
|
2425
|
+
case "undefined":
|
|
2426
|
+
case ZodFirstPartyTypeKind.ZodUndefined:
|
|
2427
|
+
return parseUndefinedDef(refs);
|
|
2428
|
+
case "ZodNull":
|
|
2429
|
+
case "null":
|
|
2430
|
+
case ZodFirstPartyTypeKind.ZodNull:
|
|
2431
|
+
return parseNullDef(refs);
|
|
2432
|
+
case "ZodArray":
|
|
2433
|
+
case "array":
|
|
2434
|
+
case ZodFirstPartyTypeKind.ZodArray:
|
|
2435
|
+
return parseArrayDef(def, refs);
|
|
2436
|
+
case "ZodUnion":
|
|
2437
|
+
case "union":
|
|
2438
|
+
case "ZodDiscriminatedUnion":
|
|
2439
|
+
case "discriminatedUnion":
|
|
2440
|
+
case ZodFirstPartyTypeKind.ZodUnion:
|
|
2441
|
+
case ZodFirstPartyTypeKind.ZodDiscriminatedUnion:
|
|
2442
|
+
return parseUnionDef(def, refs);
|
|
2443
|
+
case "ZodIntersection":
|
|
2444
|
+
case "intersection":
|
|
2445
|
+
case ZodFirstPartyTypeKind.ZodIntersection:
|
|
2446
|
+
return parseIntersectionDef(def, refs);
|
|
2447
|
+
case "ZodTuple":
|
|
2448
|
+
case "tuple":
|
|
2449
|
+
case ZodFirstPartyTypeKind.ZodTuple:
|
|
2450
|
+
return parseTupleDef(def, refs);
|
|
2451
|
+
case "ZodRecord":
|
|
2452
|
+
case "record":
|
|
2453
|
+
case ZodFirstPartyTypeKind.ZodRecord:
|
|
2454
|
+
return parseRecordDef(def, refs);
|
|
2455
|
+
case "ZodLiteral":
|
|
2456
|
+
case "literal":
|
|
2457
|
+
case ZodFirstPartyTypeKind.ZodLiteral:
|
|
2458
|
+
return parseLiteralDef(def, refs);
|
|
2459
|
+
case "ZodEnum":
|
|
2460
|
+
case "enum":
|
|
2461
|
+
case ZodFirstPartyTypeKind.ZodEnum:
|
|
2462
|
+
if (def.entries) {
|
|
2463
|
+
const keys = Object.keys(def.entries);
|
|
2464
|
+
const values = Object.values(def.entries);
|
|
2465
|
+
const isNativeEnum = !keys.every((k, i) => k === values[i]);
|
|
2466
|
+
if (isNativeEnum) {
|
|
2467
|
+
return parseNativeEnumDef(def);
|
|
2468
|
+
}
|
|
2469
|
+
}
|
|
2470
|
+
return parseEnumDef(def);
|
|
2471
|
+
case "ZodNativeEnum":
|
|
2472
|
+
case "nativeEnum":
|
|
2473
|
+
case ZodFirstPartyTypeKind.ZodNativeEnum:
|
|
2474
|
+
return parseNativeEnumDef(def);
|
|
2475
|
+
case "ZodNullable":
|
|
2476
|
+
case "nullable":
|
|
2477
|
+
case ZodFirstPartyTypeKind.ZodNullable:
|
|
2478
|
+
return parseNullableDef(def, refs);
|
|
2479
|
+
case "ZodOptional":
|
|
2480
|
+
case "optional":
|
|
2481
|
+
case ZodFirstPartyTypeKind.ZodOptional:
|
|
2482
|
+
return parseOptionalDef(def, refs);
|
|
2483
|
+
case "ZodMap":
|
|
2484
|
+
case "map":
|
|
2485
|
+
case ZodFirstPartyTypeKind.ZodMap:
|
|
2486
|
+
return parseMapDef(def, refs);
|
|
2487
|
+
case "ZodSet":
|
|
2488
|
+
case "set":
|
|
2489
|
+
case ZodFirstPartyTypeKind.ZodSet:
|
|
2490
|
+
return parseSetDef(def, refs);
|
|
2491
|
+
case "ZodLazy":
|
|
2492
|
+
case "lazy":
|
|
2493
|
+
case ZodFirstPartyTypeKind.ZodLazy:
|
|
2494
|
+
return () => def.getter()._def;
|
|
2495
|
+
case "ZodPromise":
|
|
2496
|
+
case "promise":
|
|
2497
|
+
case ZodFirstPartyTypeKind.ZodPromise:
|
|
2498
|
+
return parsePromiseDef(def, refs);
|
|
2499
|
+
case "ZodNaN":
|
|
2500
|
+
case "nan":
|
|
2501
|
+
case "ZodNever":
|
|
2502
|
+
case "never":
|
|
2503
|
+
case ZodFirstPartyTypeKind.ZodNaN:
|
|
2504
|
+
case ZodFirstPartyTypeKind.ZodNever:
|
|
2505
|
+
return parseNeverDef(refs);
|
|
2506
|
+
case "ZodEffects":
|
|
2507
|
+
case "effects":
|
|
2508
|
+
case ZodFirstPartyTypeKind.ZodEffects:
|
|
2509
|
+
return parseEffectsDef(def, refs);
|
|
2510
|
+
case "ZodAny":
|
|
2511
|
+
case "any":
|
|
2512
|
+
case ZodFirstPartyTypeKind.ZodAny:
|
|
2513
|
+
return parseAnyDef(refs);
|
|
2514
|
+
case "ZodUnknown":
|
|
2515
|
+
case "unknown":
|
|
2516
|
+
case ZodFirstPartyTypeKind.ZodUnknown:
|
|
2517
|
+
return parseUnknownDef(refs);
|
|
2518
|
+
case "ZodDefault":
|
|
2519
|
+
case "default":
|
|
2520
|
+
case ZodFirstPartyTypeKind.ZodDefault:
|
|
2521
|
+
return parseDefaultDef(def, refs);
|
|
2522
|
+
case "ZodBranded":
|
|
2523
|
+
case "branded":
|
|
2524
|
+
case ZodFirstPartyTypeKind.ZodBranded:
|
|
2525
|
+
return parseBrandedDef(def, refs);
|
|
2526
|
+
case "ZodReadonly":
|
|
2527
|
+
case "readonly":
|
|
2528
|
+
case ZodFirstPartyTypeKind.ZodReadonly:
|
|
2529
|
+
return parseReadonlyDef(def, refs);
|
|
2530
|
+
case "ZodCatch":
|
|
2531
|
+
case "catch":
|
|
2532
|
+
case ZodFirstPartyTypeKind.ZodCatch:
|
|
2533
|
+
return parseCatchDef(def, refs);
|
|
2534
|
+
case "ZodPipeline":
|
|
2535
|
+
case "pipeline":
|
|
2536
|
+
case "pipe":
|
|
2537
|
+
// Zod V4 uses "pipe" instead of "pipeline"
|
|
2538
|
+
case ZodFirstPartyTypeKind.ZodPipeline:
|
|
2539
|
+
return parsePipelineDef(def, refs);
|
|
2540
|
+
case "ZodFunction":
|
|
2541
|
+
case "function":
|
|
2542
|
+
case "ZodVoid":
|
|
2543
|
+
case "void":
|
|
2544
|
+
case "ZodSymbol":
|
|
2545
|
+
case "symbol":
|
|
2546
|
+
case ZodFirstPartyTypeKind.ZodFunction:
|
|
2547
|
+
case ZodFirstPartyTypeKind.ZodVoid:
|
|
2548
|
+
case ZodFirstPartyTypeKind.ZodSymbol:
|
|
2549
|
+
return void 0;
|
|
2550
|
+
case "custom":
|
|
2551
|
+
return parseAnyDef(refs);
|
|
2552
|
+
default:
|
|
2553
|
+
return void 0;
|
|
2554
|
+
}
|
|
2555
|
+
};
|
|
2556
|
+
|
|
2557
|
+
// ../../node_modules/.pnpm/@alcyone-labs+zod-to-json-schema@4.0.10_zod@4.1.12/node_modules/@alcyone-labs/zod-to-json-schema/dist/esm/parseDef.js
|
|
2558
|
+
var schemaMetaMap = /* @__PURE__ */ new WeakMap();
|
|
2559
|
+
var setSchemaMetaInfo = (def, metaInfo) => {
|
|
2560
|
+
schemaMetaMap.set(def, metaInfo);
|
|
2561
|
+
};
|
|
2562
|
+
var getSchemaMetaInfo = (def) => {
|
|
2563
|
+
return schemaMetaMap.get(def);
|
|
2564
|
+
};
|
|
2565
|
+
function parseDef(def, refs, forceResolution = false) {
|
|
2566
|
+
const seenItem = refs.seen.get(def);
|
|
2567
|
+
if (refs.override) {
|
|
2568
|
+
const overrideResult = refs.override?.(def, refs, seenItem, forceResolution);
|
|
2569
|
+
if (overrideResult !== ignoreOverride) {
|
|
2570
|
+
return overrideResult;
|
|
2571
|
+
}
|
|
2572
|
+
}
|
|
2573
|
+
if (seenItem && !forceResolution) {
|
|
2574
|
+
const seenSchema = get$ref(seenItem, refs);
|
|
2575
|
+
if (seenSchema !== void 0) {
|
|
2576
|
+
getDefTypeName(def);
|
|
2577
|
+
if (isNullableType(def) && refs.target === "openApi3" && "$ref" in seenSchema) {
|
|
2578
|
+
const metaInfo = getSchemaMetaInfo(def);
|
|
2579
|
+
const innerTypeDef = getInnerTypeDef(def);
|
|
2580
|
+
const innerSeenItem = innerTypeDef ? refs.seen.get(innerTypeDef) : null;
|
|
2581
|
+
const hasOwnDescription = metaInfo?.description;
|
|
2582
|
+
const innerMetaInfo = innerTypeDef ? getSchemaMetaInfo(innerTypeDef) : null;
|
|
2583
|
+
const hasInnerDescription = innerMetaInfo?.description;
|
|
2584
|
+
let referencedDefinitionDescription;
|
|
2585
|
+
if (innerSeenItem && innerSeenItem.path.includes(refs.definitionPath)) {
|
|
2586
|
+
const defName = innerSeenItem.path[innerSeenItem.path.length - 1];
|
|
2587
|
+
const definitionSchema = refs.definitions[defName];
|
|
2588
|
+
if (definitionSchema) {
|
|
2589
|
+
if (typeof definitionSchema.meta === "function") {
|
|
2590
|
+
try {
|
|
2591
|
+
const meta = definitionSchema.meta();
|
|
2592
|
+
if (meta && meta.description) {
|
|
2593
|
+
referencedDefinitionDescription = meta.description;
|
|
2594
|
+
}
|
|
2595
|
+
} catch (e) {
|
|
2596
|
+
}
|
|
2597
|
+
}
|
|
2598
|
+
if (!referencedDefinitionDescription && definitionSchema.description) {
|
|
2599
|
+
referencedDefinitionDescription = definitionSchema.description;
|
|
2600
|
+
}
|
|
2601
|
+
}
|
|
2602
|
+
}
|
|
2603
|
+
if (hasOwnDescription || hasInnerDescription || referencedDefinitionDescription) {
|
|
2604
|
+
let refToUse = seenSchema;
|
|
2605
|
+
if (innerSeenItem && innerSeenItem.path.includes(refs.definitionPath)) {
|
|
2606
|
+
refToUse = { $ref: innerSeenItem.path.join("/") };
|
|
2607
|
+
}
|
|
2608
|
+
const result = { allOf: [refToUse], nullable: true };
|
|
2609
|
+
const currentPathStr = refs.currentPath.join("/");
|
|
2610
|
+
if (hasOwnDescription && !currentPathStr.includes("group")) {
|
|
2611
|
+
result.description = metaInfo.description;
|
|
2612
|
+
} else if (hasInnerDescription && !hasOwnDescription) {
|
|
2613
|
+
result.description = innerMetaInfo.description;
|
|
2614
|
+
} else if (referencedDefinitionDescription && !hasOwnDescription) {
|
|
2615
|
+
result.description = referencedDefinitionDescription;
|
|
2616
|
+
}
|
|
2617
|
+
return result;
|
|
2618
|
+
}
|
|
2619
|
+
return seenSchema;
|
|
2620
|
+
}
|
|
2621
|
+
return seenSchema;
|
|
2622
|
+
}
|
|
2623
|
+
}
|
|
2624
|
+
const newItem = { def, path: refs.currentPath, jsonSchema: void 0 };
|
|
2625
|
+
refs.seen.set(def, newItem);
|
|
2626
|
+
const typeName = getDefTypeName(def);
|
|
2627
|
+
const jsonSchemaOrGetter = selectParser(def, typeName, refs);
|
|
2628
|
+
const jsonSchema = typeof jsonSchemaOrGetter === "function" ? parseDef(jsonSchemaOrGetter(), refs) : jsonSchemaOrGetter;
|
|
2629
|
+
if (jsonSchema) {
|
|
2630
|
+
addMeta(def, refs, jsonSchema);
|
|
2631
|
+
}
|
|
2632
|
+
if (refs.postProcess) {
|
|
2633
|
+
const postProcessResult = refs.postProcess(jsonSchema, def, refs);
|
|
2634
|
+
newItem.jsonSchema = jsonSchema;
|
|
2635
|
+
return postProcessResult;
|
|
2636
|
+
}
|
|
2637
|
+
newItem.jsonSchema = jsonSchema;
|
|
2638
|
+
return jsonSchema;
|
|
2639
|
+
}
|
|
2640
|
+
var get$ref = (item, refs) => {
|
|
2641
|
+
switch (refs.$refStrategy) {
|
|
2642
|
+
case "root":
|
|
2643
|
+
return { $ref: item.path.join("/") };
|
|
2644
|
+
case "relative":
|
|
2645
|
+
return { $ref: getRelativePath(refs.currentPath, item.path) };
|
|
2646
|
+
case "none":
|
|
2647
|
+
case "seen": {
|
|
2648
|
+
if (item.path.length < refs.currentPath.length && item.path.every((value, index) => refs.currentPath[index] === value)) {
|
|
2649
|
+
console.warn(`Recursive reference detected at ${refs.currentPath.join("/")}! Defaulting to any`);
|
|
2650
|
+
return parseAnyDef(refs);
|
|
2651
|
+
}
|
|
2652
|
+
return refs.$refStrategy === "seen" ? parseAnyDef(refs) : void 0;
|
|
2653
|
+
}
|
|
2654
|
+
}
|
|
2655
|
+
};
|
|
2656
|
+
var addMeta = (def, refs, jsonSchema) => {
|
|
2657
|
+
if (def.description) {
|
|
2658
|
+
jsonSchema.description = def.description;
|
|
2659
|
+
if (refs.markdownDescription) {
|
|
2660
|
+
jsonSchema.markdownDescription = def.description;
|
|
2661
|
+
}
|
|
2662
|
+
}
|
|
2663
|
+
const metaInfo = getSchemaMetaInfo(def);
|
|
2664
|
+
if (metaInfo) {
|
|
2665
|
+
if (metaInfo.description) {
|
|
2666
|
+
jsonSchema.description = metaInfo.description;
|
|
2667
|
+
if (refs.markdownDescription) {
|
|
2668
|
+
jsonSchema.markdownDescription = metaInfo.description;
|
|
2669
|
+
}
|
|
2670
|
+
}
|
|
2671
|
+
if (metaInfo.title) {
|
|
2672
|
+
jsonSchema.title = metaInfo.title;
|
|
2673
|
+
}
|
|
2674
|
+
if (metaInfo.examples) {
|
|
2675
|
+
jsonSchema.examples = metaInfo.examples;
|
|
2676
|
+
}
|
|
2677
|
+
for (const [key, value] of Object.entries(metaInfo)) {
|
|
2678
|
+
if (key !== "description" && key !== "title" && key !== "examples") {
|
|
2679
|
+
jsonSchema[key] = value;
|
|
2680
|
+
}
|
|
2681
|
+
}
|
|
2682
|
+
}
|
|
2683
|
+
return jsonSchema;
|
|
2684
|
+
};
|
|
2685
|
+
|
|
2686
|
+
// ../../node_modules/.pnpm/@alcyone-labs+zod-to-json-schema@4.0.10_zod@4.1.12/node_modules/@alcyone-labs/zod-to-json-schema/dist/esm/zodToJsonSchema.js
|
|
2687
|
+
var extractAndStoreMetaInfo = (schema) => {
|
|
2688
|
+
if (!schema || !schema._def)
|
|
2689
|
+
return;
|
|
2690
|
+
const metaInfo = extractMetadata(schema);
|
|
2691
|
+
if (Object.keys(metaInfo).length > 0) {
|
|
2692
|
+
setSchemaMetaInfo(schema._def, metaInfo);
|
|
2693
|
+
}
|
|
2694
|
+
if (schema._def.innerType) {
|
|
2695
|
+
extractAndStoreMetaInfo(schema._def.innerType);
|
|
2696
|
+
}
|
|
2697
|
+
if (schema._def.options && Array.isArray(schema._def.options)) {
|
|
2698
|
+
schema._def.options.forEach((option) => extractAndStoreMetaInfo(option));
|
|
2699
|
+
}
|
|
2700
|
+
if (schema._def.left) {
|
|
2701
|
+
extractAndStoreMetaInfo(schema._def.left);
|
|
2702
|
+
}
|
|
2703
|
+
if (schema._def.right) {
|
|
2704
|
+
extractAndStoreMetaInfo(schema._def.right);
|
|
2705
|
+
}
|
|
2706
|
+
if (schema._def.schema) {
|
|
2707
|
+
extractAndStoreMetaInfo(schema._def.schema);
|
|
2708
|
+
}
|
|
2709
|
+
if (schema._def.type) {
|
|
2710
|
+
extractAndStoreMetaInfo(schema._def.type);
|
|
2711
|
+
}
|
|
2712
|
+
if (schema._def.shape && typeof schema._def.shape === "object") {
|
|
2713
|
+
Object.values(schema._def.shape).forEach((propSchema) => {
|
|
2714
|
+
extractAndStoreMetaInfo(propSchema);
|
|
2715
|
+
});
|
|
2716
|
+
}
|
|
2717
|
+
if (schema._def.element) {
|
|
2718
|
+
extractAndStoreMetaInfo(schema._def.element);
|
|
2719
|
+
}
|
|
2720
|
+
if (schema._def.shape && typeof schema._def.shape === "object") {
|
|
2721
|
+
Object.values(schema._def.shape).forEach((propertySchema) => {
|
|
2722
|
+
extractAndStoreMetaInfo(propertySchema);
|
|
2723
|
+
});
|
|
2724
|
+
}
|
|
2725
|
+
if (schema._def.type && schema._def.type._def) {
|
|
2726
|
+
extractAndStoreMetaInfo(schema._def.type);
|
|
2727
|
+
}
|
|
2728
|
+
};
|
|
2729
|
+
var zodToJsonSchema = (schema, options) => {
|
|
2730
|
+
const refs = getRefs(options);
|
|
2731
|
+
extractAndStoreMetaInfo(schema);
|
|
2732
|
+
if (typeof options === "object" && options.definitions) {
|
|
2733
|
+
Object.values(options.definitions).forEach((defSchema) => {
|
|
2734
|
+
extractAndStoreMetaInfo(defSchema);
|
|
2735
|
+
});
|
|
2736
|
+
}
|
|
2737
|
+
let definitions = typeof options === "object" && options.definitions ? Object.entries(options.definitions).reduce((acc, [name2, schema2]) => ({
|
|
2738
|
+
...acc,
|
|
2739
|
+
[name2]: parseDef(schema2._def, {
|
|
2740
|
+
...refs,
|
|
2741
|
+
currentPath: [...refs.basePath, refs.definitionPath, name2]
|
|
2742
|
+
}, true) ?? parseAnyDef(refs)
|
|
2743
|
+
}), {}) : void 0;
|
|
2744
|
+
const name = typeof options === "string" ? options : options?.nameStrategy === "title" ? void 0 : options?.name;
|
|
2745
|
+
const main = parseDef(schema._def, name === void 0 ? refs : {
|
|
2746
|
+
...refs,
|
|
2747
|
+
currentPath: [...refs.basePath, refs.definitionPath, name]
|
|
2748
|
+
}, false) ?? parseAnyDef(refs);
|
|
2749
|
+
const title = typeof options === "object" && options.name !== void 0 && options.nameStrategy === "title" ? options.name : void 0;
|
|
2750
|
+
if (title !== void 0) {
|
|
2751
|
+
main.title = title;
|
|
2752
|
+
}
|
|
2753
|
+
if (refs.flags.hasReferencedOpenAiAnyType) {
|
|
2754
|
+
if (!definitions) {
|
|
2755
|
+
definitions = {};
|
|
2756
|
+
}
|
|
2757
|
+
if (!definitions[refs.openAiAnyTypeName]) {
|
|
2758
|
+
definitions[refs.openAiAnyTypeName] = {
|
|
2759
|
+
// Skipping "object" as no properties can be defined and additionalProperties must be "false"
|
|
2760
|
+
type: ["string", "number", "integer", "boolean", "array", "null"],
|
|
2761
|
+
items: {
|
|
2762
|
+
$ref: refs.$refStrategy === "relative" ? "1" : [
|
|
2763
|
+
...refs.basePath,
|
|
2764
|
+
refs.definitionPath,
|
|
2765
|
+
refs.openAiAnyTypeName
|
|
2766
|
+
].join("/")
|
|
2767
|
+
}
|
|
2768
|
+
};
|
|
2769
|
+
}
|
|
2770
|
+
}
|
|
2771
|
+
const combined = name === void 0 ? definitions ? {
|
|
2772
|
+
...main,
|
|
2773
|
+
[refs.definitionPath]: definitions
|
|
2774
|
+
} : main : {
|
|
2775
|
+
$ref: [
|
|
2776
|
+
...refs.$refStrategy === "relative" ? [] : refs.basePath,
|
|
2777
|
+
refs.definitionPath,
|
|
2778
|
+
name
|
|
2779
|
+
].join("/"),
|
|
2780
|
+
[refs.definitionPath]: {
|
|
2781
|
+
...definitions,
|
|
2782
|
+
[name]: main
|
|
2783
|
+
}
|
|
2784
|
+
};
|
|
2785
|
+
if (refs.target === "jsonSchema7") {
|
|
2786
|
+
combined.$schema = "http://json-schema.org/draft-07/schema#";
|
|
2787
|
+
} else if (refs.target === "jsonSchema2019-09" || refs.target === "openAi") {
|
|
2788
|
+
combined.$schema = "https://json-schema.org/draft/2019-09/schema#";
|
|
2789
|
+
}
|
|
2790
|
+
if (refs.target === "openAi" && ("anyOf" in combined || "oneOf" in combined || "allOf" in combined || "type" in combined && Array.isArray(combined.type))) {
|
|
2791
|
+
console.warn("Warning: OpenAI may not support schemas with unions as roots! Try wrapping it in an object property.");
|
|
2792
|
+
}
|
|
2793
|
+
return combined;
|
|
2794
|
+
};
|
|
2795
|
+
|
|
2796
|
+
// ../core/src/execution/engine/base/serialization.ts
|
|
2797
|
+
function serializeDefinition(definition, options) {
|
|
2798
|
+
const opts = {
|
|
2799
|
+
redactSecrets: true,
|
|
2800
|
+
includeToolSchemas: true,
|
|
2801
|
+
includeKnowledgeMap: true,
|
|
2802
|
+
...options
|
|
2803
|
+
};
|
|
2804
|
+
const context = {
|
|
2805
|
+
...opts,
|
|
2806
|
+
visited: /* @__PURE__ */ new WeakSet()
|
|
2807
|
+
};
|
|
2808
|
+
return deepSerialize(definition, context);
|
|
2809
|
+
}
|
|
2810
|
+
function deepSerialize(value, ctx) {
|
|
2811
|
+
if (value === null || value === void 0) return value;
|
|
2812
|
+
if (typeof value !== "object") return value;
|
|
2813
|
+
if (ctx.visited.has(value)) {
|
|
2814
|
+
return { __circular: true };
|
|
2815
|
+
}
|
|
2816
|
+
ctx.visited.add(value);
|
|
2817
|
+
if (isZodSchema(value)) return convertZodToJsonSchema(value);
|
|
2818
|
+
if (value instanceof Map) return convertMapToArray(value, ctx);
|
|
2819
|
+
if (value instanceof Set) return convertSetToArray(value, ctx);
|
|
2820
|
+
if (value instanceof Date) return value.toISOString();
|
|
2821
|
+
if (typeof value === "function") return void 0;
|
|
2822
|
+
if (Array.isArray(value)) {
|
|
2823
|
+
return value.map((item) => deepSerialize(item, ctx)).filter((item) => item !== void 0);
|
|
2824
|
+
}
|
|
2825
|
+
if (isToolObject(value)) return serializeTool(value, ctx);
|
|
2826
|
+
if (isKnowledgeMapObject(value)) return serializeKnowledgeMap(value, ctx);
|
|
2827
|
+
if (isNextConfigObject(value)) return serializeNextConfig(value);
|
|
2828
|
+
return serializeObject(value, ctx);
|
|
2829
|
+
}
|
|
2830
|
+
function serializeObject(obj, ctx) {
|
|
2831
|
+
const result = {};
|
|
2832
|
+
for (const [key, val] of Object.entries(obj)) {
|
|
2833
|
+
if (typeof val === "function") continue;
|
|
2834
|
+
if (ctx.redactSecrets && isSecretKey(key)) {
|
|
2835
|
+
result[key] = redactSecret(val);
|
|
2836
|
+
continue;
|
|
2837
|
+
}
|
|
2838
|
+
if (key === "steps" && isWorkflowStepsRecord(val)) {
|
|
2839
|
+
result[key] = convertRecordToArray(val, ctx);
|
|
2840
|
+
continue;
|
|
2841
|
+
}
|
|
2842
|
+
const serialized = deepSerialize(val, ctx);
|
|
2843
|
+
if (serialized !== void 0) {
|
|
2844
|
+
result[key] = serialized;
|
|
2845
|
+
}
|
|
2846
|
+
}
|
|
2847
|
+
return result;
|
|
2848
|
+
}
|
|
2849
|
+
function serializeTool(tool, ctx) {
|
|
2850
|
+
const result = {
|
|
2851
|
+
name: tool.name,
|
|
2852
|
+
description: tool.description
|
|
2853
|
+
};
|
|
2854
|
+
if (ctx.includeToolSchemas && tool.inputSchema) {
|
|
2855
|
+
result.inputSchema = deepSerialize(tool.inputSchema, ctx);
|
|
2856
|
+
}
|
|
2857
|
+
if (ctx.includeToolSchemas && tool.outputSchema) {
|
|
2858
|
+
result.outputSchema = deepSerialize(tool.outputSchema, ctx);
|
|
2859
|
+
}
|
|
2860
|
+
return result;
|
|
2861
|
+
}
|
|
2862
|
+
function serializeKnowledgeMap(km, ctx) {
|
|
2863
|
+
if (!ctx.includeKnowledgeMap) return void 0;
|
|
2864
|
+
const nodes = km.nodes || {};
|
|
2865
|
+
const nodeEntries = Object.entries(nodes).map(([id, node]) => ({
|
|
2866
|
+
id,
|
|
2867
|
+
description: node.description,
|
|
2868
|
+
loaded: node.loaded || false,
|
|
2869
|
+
hasPrompt: Boolean(node.prompt)
|
|
2870
|
+
// load function automatically omitted
|
|
2871
|
+
// prompt content omitted (too large for structure metadata)
|
|
2872
|
+
}));
|
|
2873
|
+
return {
|
|
2874
|
+
nodeCount: nodeEntries.length,
|
|
2875
|
+
nodes: nodeEntries
|
|
2876
|
+
};
|
|
2877
|
+
}
|
|
2878
|
+
function serializeNextConfig(nextConfig, _context) {
|
|
2879
|
+
if (!nextConfig) return null;
|
|
2880
|
+
if (nextConfig.type === "linear" /* LINEAR */) {
|
|
2881
|
+
return {
|
|
2882
|
+
type: nextConfig.type,
|
|
2883
|
+
target: nextConfig.target
|
|
2884
|
+
};
|
|
2885
|
+
}
|
|
2886
|
+
if (nextConfig.type === "conditional" /* CONDITIONAL */) {
|
|
2887
|
+
return {
|
|
2888
|
+
type: nextConfig.type,
|
|
2889
|
+
routes: nextConfig.routes?.map((route) => ({
|
|
2890
|
+
// Strip condition function, keep only target
|
|
2891
|
+
target: route.target
|
|
2892
|
+
})) ?? [],
|
|
2893
|
+
default: nextConfig.default
|
|
2894
|
+
};
|
|
2895
|
+
}
|
|
2896
|
+
return null;
|
|
2897
|
+
}
|
|
2898
|
+
function convertMapToArray(map, ctx) {
|
|
2899
|
+
return Array.from(map.entries()).map(([key, val]) => ({
|
|
2900
|
+
id: key,
|
|
2901
|
+
...deepSerialize(val, ctx)
|
|
2902
|
+
}));
|
|
2903
|
+
}
|
|
2904
|
+
function isWorkflowStepsRecord(value) {
|
|
2905
|
+
if (!value || typeof value !== "object" || Array.isArray(value) || value instanceof Map || value instanceof Set) {
|
|
2906
|
+
return false;
|
|
2907
|
+
}
|
|
2908
|
+
const entries = Object.values(value);
|
|
2909
|
+
if (entries.length === 0) return false;
|
|
2910
|
+
const first = entries[0];
|
|
2911
|
+
return first && typeof first === "object" && "name" in first && "handler" in first;
|
|
2912
|
+
}
|
|
2913
|
+
function convertRecordToArray(record, ctx) {
|
|
2914
|
+
return Object.entries(record).map(([key, val]) => ({
|
|
2915
|
+
id: key,
|
|
2916
|
+
...deepSerialize(val, ctx)
|
|
2917
|
+
}));
|
|
2918
|
+
}
|
|
2919
|
+
function convertSetToArray(set, ctx) {
|
|
2920
|
+
return Array.from(set).map((v) => deepSerialize(v, ctx));
|
|
2921
|
+
}
|
|
2922
|
+
function convertZodToJsonSchema(schema) {
|
|
2923
|
+
return zodToJsonSchema(schema, {
|
|
2924
|
+
$refStrategy: "none",
|
|
2925
|
+
errorMessages: true
|
|
2926
|
+
});
|
|
2927
|
+
}
|
|
2928
|
+
function isZodSchema(value) {
|
|
2929
|
+
return value && typeof value === "object" && "_def" in value && "parse" in value;
|
|
2930
|
+
}
|
|
2931
|
+
function isToolObject(value) {
|
|
2932
|
+
return value && typeof value === "object" && "name" in value && "description" in value && "execute" in value;
|
|
2933
|
+
}
|
|
2934
|
+
function isKnowledgeMapObject(value) {
|
|
2935
|
+
return value && typeof value === "object" && "nodes" in value && typeof value.nodes === "object";
|
|
2936
|
+
}
|
|
2937
|
+
function isNextConfigObject(value) {
|
|
2938
|
+
return value && typeof value === "object" && "type" in value && (value.type === "linear" /* LINEAR */ || value.type === "conditional" /* CONDITIONAL */);
|
|
2939
|
+
}
|
|
2940
|
+
function isSecretKey(key) {
|
|
2941
|
+
const lower = key.toLowerCase();
|
|
2942
|
+
const whitelist = ["maxtokens", "memorytokens", "inputtokens", "outputtokens"];
|
|
2943
|
+
if (whitelist.some((w) => lower.includes(w))) return false;
|
|
2944
|
+
const patterns = ["apikey", "secret", "password", "token", "credential"];
|
|
2945
|
+
return patterns.some((p) => lower.includes(p));
|
|
2946
|
+
}
|
|
2947
|
+
function redactSecret(value) {
|
|
2948
|
+
if (typeof value !== "string") return "[REDACTED]";
|
|
2949
|
+
if (value.length <= 7) return "[REDACTED]";
|
|
2950
|
+
return value.substring(0, 7) + "...";
|
|
2951
|
+
}
|
|
2952
|
+
|
|
2953
|
+
// ../core/src/platform/registry/serialization.ts
|
|
2954
|
+
function serializeAllOrganizations(registry) {
|
|
2955
|
+
const cache = /* @__PURE__ */ new Map();
|
|
2956
|
+
for (const [orgName, resources] of Object.entries(registry)) {
|
|
2957
|
+
cache.set(orgName, serializeOrganization(resources));
|
|
2958
|
+
}
|
|
2959
|
+
return cache;
|
|
2960
|
+
}
|
|
2961
|
+
function deriveDomainDefinitions(resources) {
|
|
2962
|
+
const domainIds = /* @__PURE__ */ new Set();
|
|
2963
|
+
resources.workflows?.forEach((w) => w.config.domains?.forEach((d) => domainIds.add(d)));
|
|
2964
|
+
resources.agents?.forEach((a) => a.config.domains?.forEach((d) => domainIds.add(d)));
|
|
2965
|
+
resources.triggers?.forEach((t) => t.domains?.forEach((d) => domainIds.add(d)));
|
|
2966
|
+
resources.integrations?.forEach((i) => i.domains?.forEach((d) => domainIds.add(d)));
|
|
2967
|
+
resources.externalResources?.forEach((e) => e.domains?.forEach((d) => domainIds.add(d)));
|
|
2968
|
+
resources.humanCheckpoints?.forEach((h) => h.domains?.forEach((d) => domainIds.add(d)));
|
|
2969
|
+
return Array.from(domainIds).map((id) => DOMAIN_MAP[id]);
|
|
2970
|
+
}
|
|
2971
|
+
function serializeOrganization(resources) {
|
|
2972
|
+
const workflowDefinitions = /* @__PURE__ */ new Map();
|
|
2973
|
+
const workflowResources = [];
|
|
2974
|
+
const commandViewWorkflows = [];
|
|
2975
|
+
for (const workflow of resources.workflows ?? []) {
|
|
2976
|
+
const resourceId = workflow.config.resourceId;
|
|
2977
|
+
const serialized = serializeDefinition(workflow);
|
|
2978
|
+
workflowDefinitions.set(resourceId, serialized);
|
|
2979
|
+
workflowResources.push({
|
|
2980
|
+
resourceId,
|
|
2981
|
+
name: workflow.config.name,
|
|
2982
|
+
description: workflow.config.description,
|
|
2983
|
+
version: workflow.config.version,
|
|
2984
|
+
type: "workflow",
|
|
2985
|
+
status: workflow.config.status
|
|
2986
|
+
});
|
|
2987
|
+
commandViewWorkflows.push({
|
|
2988
|
+
resourceId,
|
|
2989
|
+
name: workflow.config.name,
|
|
2990
|
+
description: workflow.config.description,
|
|
2991
|
+
version: workflow.config.version,
|
|
2992
|
+
type: "workflow",
|
|
2993
|
+
status: workflow.config.status,
|
|
2994
|
+
domains: workflow.config.domains,
|
|
2995
|
+
stepCount: Object.keys(workflow.steps).length,
|
|
2996
|
+
entryPoint: workflow.entryPoint
|
|
2997
|
+
});
|
|
2998
|
+
}
|
|
2999
|
+
const agentDefinitions = /* @__PURE__ */ new Map();
|
|
3000
|
+
const agentResources = [];
|
|
3001
|
+
const commandViewAgents = [];
|
|
3002
|
+
for (const agent of resources.agents ?? []) {
|
|
3003
|
+
const resourceId = agent.config.resourceId;
|
|
3004
|
+
const serialized = serializeDefinition(agent);
|
|
3005
|
+
agentDefinitions.set(resourceId, serialized);
|
|
3006
|
+
agentResources.push({
|
|
3007
|
+
resourceId,
|
|
3008
|
+
name: agent.config.name,
|
|
3009
|
+
description: agent.config.description,
|
|
3010
|
+
version: agent.config.version,
|
|
3011
|
+
type: "agent",
|
|
3012
|
+
status: agent.config.status
|
|
3013
|
+
});
|
|
3014
|
+
commandViewAgents.push({
|
|
3015
|
+
resourceId,
|
|
3016
|
+
name: agent.config.name,
|
|
3017
|
+
description: agent.config.description,
|
|
3018
|
+
version: agent.config.version,
|
|
3019
|
+
type: "agent",
|
|
3020
|
+
status: agent.config.status,
|
|
3021
|
+
domains: agent.config.domains,
|
|
3022
|
+
modelProvider: agent.modelConfig.provider,
|
|
3023
|
+
modelId: agent.modelConfig.model,
|
|
3024
|
+
toolCount: agent.tools.length,
|
|
3025
|
+
hasKnowledgeMap: agent.knowledgeMap !== void 0,
|
|
3026
|
+
hasMemory: agent.config.memoryPreferences !== void 0,
|
|
3027
|
+
sessionCapable: agent.config.sessionCapable ?? false
|
|
3028
|
+
});
|
|
3029
|
+
}
|
|
3030
|
+
const edges = buildEdges(resources);
|
|
3031
|
+
const triggers = resources.triggers ?? [];
|
|
3032
|
+
const integrations = resources.integrations ?? [];
|
|
3033
|
+
const externalResources = resources.externalResources ?? [];
|
|
3034
|
+
const humanCheckpoints = resources.humanCheckpoints ?? [];
|
|
3035
|
+
const domainDefinitions = deriveDomainDefinitions(resources);
|
|
3036
|
+
return {
|
|
3037
|
+
resources: {
|
|
3038
|
+
workflows: workflowResources,
|
|
3039
|
+
agents: agentResources,
|
|
3040
|
+
total: workflowResources.length + agentResources.length
|
|
3041
|
+
},
|
|
3042
|
+
definitions: {
|
|
3043
|
+
workflows: workflowDefinitions,
|
|
3044
|
+
agents: agentDefinitions
|
|
3045
|
+
},
|
|
3046
|
+
commandView: {
|
|
3047
|
+
workflows: commandViewWorkflows,
|
|
3048
|
+
agents: commandViewAgents,
|
|
3049
|
+
triggers,
|
|
3050
|
+
integrations,
|
|
3051
|
+
externalResources,
|
|
3052
|
+
humanCheckpoints,
|
|
3053
|
+
edges,
|
|
3054
|
+
domainDefinitions
|
|
3055
|
+
},
|
|
3056
|
+
triggers,
|
|
3057
|
+
integrations,
|
|
3058
|
+
externalResources,
|
|
3059
|
+
humanCheckpoints,
|
|
3060
|
+
relationships: resources.relationships
|
|
3061
|
+
};
|
|
3062
|
+
}
|
|
3063
|
+
function buildEdges(resources) {
|
|
3064
|
+
const edges = [];
|
|
3065
|
+
let edgeId = 0;
|
|
3066
|
+
for (const [resourceId, declaration] of Object.entries(resources.relationships ?? {})) {
|
|
3067
|
+
for (const agentId of declaration.triggers?.agents ?? []) {
|
|
3068
|
+
edges.push({
|
|
3069
|
+
id: `edge-${edgeId++}`,
|
|
3070
|
+
source: resourceId,
|
|
3071
|
+
target: agentId,
|
|
3072
|
+
relationship: "triggers"
|
|
3073
|
+
});
|
|
3074
|
+
}
|
|
3075
|
+
for (const workflowId of declaration.triggers?.workflows ?? []) {
|
|
3076
|
+
edges.push({
|
|
3077
|
+
id: `edge-${edgeId++}`,
|
|
3078
|
+
source: resourceId,
|
|
3079
|
+
target: workflowId,
|
|
3080
|
+
relationship: "triggers"
|
|
3081
|
+
});
|
|
3082
|
+
}
|
|
3083
|
+
for (const integrationId of declaration.uses?.integrations ?? []) {
|
|
3084
|
+
edges.push({
|
|
3085
|
+
id: `edge-${edgeId++}`,
|
|
3086
|
+
source: resourceId,
|
|
3087
|
+
target: integrationId,
|
|
3088
|
+
relationship: "uses"
|
|
3089
|
+
});
|
|
3090
|
+
}
|
|
3091
|
+
}
|
|
3092
|
+
for (const external of resources.externalResources ?? []) {
|
|
3093
|
+
for (const workflowId of external.triggers?.workflows ?? []) {
|
|
3094
|
+
edges.push({
|
|
3095
|
+
id: `edge-${edgeId++}`,
|
|
3096
|
+
source: external.resourceId,
|
|
3097
|
+
target: workflowId,
|
|
3098
|
+
relationship: "triggers"
|
|
3099
|
+
});
|
|
3100
|
+
}
|
|
3101
|
+
for (const agentId of external.triggers?.agents ?? []) {
|
|
3102
|
+
edges.push({
|
|
3103
|
+
id: `edge-${edgeId++}`,
|
|
3104
|
+
source: external.resourceId,
|
|
3105
|
+
target: agentId,
|
|
3106
|
+
relationship: "triggers"
|
|
3107
|
+
});
|
|
3108
|
+
}
|
|
3109
|
+
for (const integrationId of external.uses?.integrations ?? []) {
|
|
3110
|
+
edges.push({
|
|
3111
|
+
id: `edge-${edgeId++}`,
|
|
3112
|
+
source: external.resourceId,
|
|
3113
|
+
target: integrationId,
|
|
3114
|
+
relationship: "uses"
|
|
3115
|
+
});
|
|
3116
|
+
}
|
|
3117
|
+
}
|
|
3118
|
+
for (const humanCheckpoint of resources.humanCheckpoints ?? []) {
|
|
3119
|
+
for (const agentId of humanCheckpoint.requestedBy?.agents ?? []) {
|
|
3120
|
+
edges.push({
|
|
3121
|
+
id: `edge-${edgeId++}`,
|
|
3122
|
+
source: agentId,
|
|
3123
|
+
target: humanCheckpoint.resourceId,
|
|
3124
|
+
relationship: "approval"
|
|
3125
|
+
});
|
|
3126
|
+
}
|
|
3127
|
+
for (const workflowId of humanCheckpoint.requestedBy?.workflows ?? []) {
|
|
3128
|
+
edges.push({
|
|
3129
|
+
id: `edge-${edgeId++}`,
|
|
3130
|
+
source: workflowId,
|
|
3131
|
+
target: humanCheckpoint.resourceId,
|
|
3132
|
+
relationship: "approval"
|
|
3133
|
+
});
|
|
3134
|
+
}
|
|
3135
|
+
for (const agentId of humanCheckpoint.routesTo?.agents ?? []) {
|
|
3136
|
+
edges.push({
|
|
3137
|
+
id: `edge-${edgeId++}`,
|
|
3138
|
+
source: humanCheckpoint.resourceId,
|
|
3139
|
+
target: agentId,
|
|
3140
|
+
relationship: "triggers"
|
|
3141
|
+
});
|
|
3142
|
+
}
|
|
3143
|
+
for (const workflowId of humanCheckpoint.routesTo?.workflows ?? []) {
|
|
3144
|
+
edges.push({
|
|
3145
|
+
id: `edge-${edgeId++}`,
|
|
3146
|
+
source: humanCheckpoint.resourceId,
|
|
3147
|
+
target: workflowId,
|
|
3148
|
+
relationship: "triggers"
|
|
3149
|
+
});
|
|
3150
|
+
}
|
|
3151
|
+
}
|
|
3152
|
+
return edges;
|
|
3153
|
+
}
|
|
3154
|
+
|
|
3155
|
+
// ../core/src/platform/registry/resource-registry.ts
|
|
3156
|
+
var ResourceRegistry = class {
|
|
3157
|
+
constructor(registry) {
|
|
3158
|
+
this.registry = registry;
|
|
3159
|
+
this.validateRegistry();
|
|
3160
|
+
this.validateRelationships();
|
|
3161
|
+
this.serializedCache = serializeAllOrganizations(registry);
|
|
3162
|
+
}
|
|
3163
|
+
/**
|
|
3164
|
+
* Pre-serialized organization data cache
|
|
3165
|
+
* Computed once at construction, never invalidated (static registry)
|
|
3166
|
+
*/
|
|
3167
|
+
serializedCache;
|
|
3168
|
+
/**
|
|
3169
|
+
* Validates registry on construction
|
|
3170
|
+
* - Checks for duplicate resourceIds within organizations
|
|
3171
|
+
* - Validates model configurations against constraints
|
|
3172
|
+
* - Validates ExecutionInterface matches inputSchema
|
|
3173
|
+
* @throws Error if validation fails
|
|
3174
|
+
*/
|
|
3175
|
+
validateRegistry() {
|
|
3176
|
+
for (const [orgName, resources] of Object.entries(this.registry)) {
|
|
3177
|
+
validateOrganizationResources(orgName, resources);
|
|
3178
|
+
}
|
|
3179
|
+
}
|
|
3180
|
+
/**
|
|
3181
|
+
* Validates relationship declarations reference valid resources
|
|
3182
|
+
* Runs at API server startup - fails fast in development
|
|
3183
|
+
* @throws Error if validation fails
|
|
3184
|
+
*/
|
|
3185
|
+
validateRelationships() {
|
|
3186
|
+
for (const [orgName, resources] of Object.entries(this.registry)) {
|
|
3187
|
+
validateRelationships(orgName, resources);
|
|
3188
|
+
}
|
|
3189
|
+
}
|
|
3190
|
+
/**
|
|
3191
|
+
* Get a resource definition by ID
|
|
3192
|
+
* Returns full definition (WorkflowDefinition or AgentDefinition)
|
|
3193
|
+
* Check definition.config.type to determine if it's a workflow or agent
|
|
3194
|
+
*/
|
|
3195
|
+
getResourceDefinition(organizationName, resourceId) {
|
|
3196
|
+
const orgResources = this.registry[organizationName];
|
|
3197
|
+
if (!orgResources) return null;
|
|
3198
|
+
const workflow = orgResources.workflows?.find((w) => w.config.resourceId === resourceId);
|
|
3199
|
+
if (workflow) return workflow;
|
|
3200
|
+
const agent = orgResources.agents?.find((a) => a.config.resourceId === resourceId);
|
|
3201
|
+
if (agent) return agent;
|
|
3202
|
+
return null;
|
|
3203
|
+
}
|
|
3204
|
+
/**
|
|
3205
|
+
* List all resources for an organization
|
|
3206
|
+
* Returns ResourceDefinition metadata (not full definitions)
|
|
3207
|
+
*
|
|
3208
|
+
* Environment filtering (automatic):
|
|
3209
|
+
* - Development: Returns all resources (dev + prod)
|
|
3210
|
+
* - Production: Returns only prod resources (filters out dev)
|
|
3211
|
+
*/
|
|
3212
|
+
listResourcesForOrganization(organizationName, environment) {
|
|
3213
|
+
const orgResources = this.registry[organizationName];
|
|
3214
|
+
if (!orgResources) {
|
|
3215
|
+
return {
|
|
3216
|
+
workflows: [],
|
|
3217
|
+
agents: [],
|
|
3218
|
+
total: 0,
|
|
3219
|
+
organizationName,
|
|
3220
|
+
environment
|
|
3221
|
+
};
|
|
3222
|
+
}
|
|
3223
|
+
const currentEnv = detectEnvironment();
|
|
3224
|
+
const workflows = (orgResources.workflows || []).map((def) => ({
|
|
3225
|
+
resourceId: def.config.resourceId,
|
|
3226
|
+
name: def.config.name,
|
|
3227
|
+
description: def.config.description,
|
|
3228
|
+
version: def.config.version,
|
|
3229
|
+
type: def.config.type,
|
|
3230
|
+
status: def.config.status
|
|
3231
|
+
})).filter((resource) => {
|
|
3232
|
+
if (environment) {
|
|
3233
|
+
return resource.status === environment;
|
|
3234
|
+
}
|
|
3235
|
+
return canExecuteResource(resource, currentEnv);
|
|
3236
|
+
});
|
|
3237
|
+
const agents = (orgResources.agents || []).map((def) => ({
|
|
3238
|
+
resourceId: def.config.resourceId,
|
|
3239
|
+
name: def.config.name,
|
|
3240
|
+
description: def.config.description,
|
|
3241
|
+
version: def.config.version,
|
|
3242
|
+
type: def.config.type,
|
|
3243
|
+
status: def.config.status,
|
|
3244
|
+
sessionCapable: def.config.sessionCapable ?? false
|
|
3245
|
+
})).filter((resource) => {
|
|
3246
|
+
if (environment) {
|
|
3247
|
+
return resource.status === environment;
|
|
3248
|
+
}
|
|
3249
|
+
return canExecuteResource(resource, currentEnv);
|
|
3250
|
+
});
|
|
3251
|
+
return {
|
|
3252
|
+
workflows,
|
|
3253
|
+
agents,
|
|
3254
|
+
total: workflows.length + agents.length,
|
|
3255
|
+
organizationName,
|
|
3256
|
+
environment: environment || (currentEnv === "production" ? "prod" : void 0)
|
|
3257
|
+
};
|
|
3258
|
+
}
|
|
3259
|
+
/**
|
|
3260
|
+
* List all resources from all organizations
|
|
3261
|
+
* NOTE: For debugging only - returns raw registry data
|
|
3262
|
+
*/
|
|
3263
|
+
listAllResources() {
|
|
3264
|
+
return this.registry;
|
|
3265
|
+
}
|
|
3266
|
+
// ============================================================================
|
|
3267
|
+
// Resource Manifest Accessors
|
|
3268
|
+
// ============================================================================
|
|
3269
|
+
/**
|
|
3270
|
+
* Get triggers for an organization
|
|
3271
|
+
* @param organizationName - Organization name
|
|
3272
|
+
* @returns Array of trigger definitions (empty if none defined)
|
|
3273
|
+
*/
|
|
3274
|
+
getTriggers(organizationName) {
|
|
3275
|
+
return this.registry[organizationName]?.triggers ?? [];
|
|
3276
|
+
}
|
|
3277
|
+
/**
|
|
3278
|
+
* Get integrations for an organization
|
|
3279
|
+
* @param organizationName - Organization name
|
|
3280
|
+
* @returns Array of integration definitions (empty if none defined)
|
|
3281
|
+
*/
|
|
3282
|
+
getIntegrations(organizationName) {
|
|
3283
|
+
return this.registry[organizationName]?.integrations ?? [];
|
|
3284
|
+
}
|
|
3285
|
+
/**
|
|
3286
|
+
* Get resource relationships for an organization
|
|
3287
|
+
* @param organizationName - Organization name
|
|
3288
|
+
* @returns Resource relationships map (undefined if none defined)
|
|
3289
|
+
*/
|
|
3290
|
+
getRelationships(organizationName) {
|
|
3291
|
+
return this.registry[organizationName]?.relationships;
|
|
3292
|
+
}
|
|
3293
|
+
/**
|
|
3294
|
+
* Get a specific trigger by ID
|
|
3295
|
+
* @param organizationName - Organization name
|
|
3296
|
+
* @param triggerId - Trigger ID
|
|
3297
|
+
* @returns Trigger definition or null if not found
|
|
3298
|
+
*/
|
|
3299
|
+
getTrigger(organizationName, triggerId) {
|
|
3300
|
+
const triggers = this.getTriggers(organizationName);
|
|
3301
|
+
return triggers.find((t) => t.resourceId === triggerId) ?? null;
|
|
3302
|
+
}
|
|
3303
|
+
/**
|
|
3304
|
+
* Get a specific integration by ID
|
|
3305
|
+
* @param organizationName - Organization name
|
|
3306
|
+
* @param integrationId - Integration ID
|
|
3307
|
+
* @returns Integration definition or null if not found
|
|
3308
|
+
*/
|
|
3309
|
+
getIntegration(organizationName, integrationId) {
|
|
3310
|
+
const integrations = this.getIntegrations(organizationName);
|
|
3311
|
+
return integrations.find((i) => i.resourceId === integrationId) ?? null;
|
|
3312
|
+
}
|
|
3313
|
+
/**
|
|
3314
|
+
* Get external resources for an organization
|
|
3315
|
+
* @param organizationName - Organization name
|
|
3316
|
+
* @returns Array of external resource definitions (empty if none defined)
|
|
3317
|
+
*/
|
|
3318
|
+
getExternalResources(organizationName) {
|
|
3319
|
+
return this.registry[organizationName]?.externalResources ?? [];
|
|
3320
|
+
}
|
|
3321
|
+
/**
|
|
3322
|
+
* Get a specific external resource by ID
|
|
3323
|
+
* @param organizationName - Organization name
|
|
3324
|
+
* @param externalId - External resource ID
|
|
3325
|
+
* @returns External resource definition or null if not found
|
|
3326
|
+
*/
|
|
3327
|
+
getExternalResource(organizationName, externalId) {
|
|
3328
|
+
const externalResources = this.getExternalResources(organizationName);
|
|
3329
|
+
return externalResources.find((e) => e.resourceId === externalId) ?? null;
|
|
3330
|
+
}
|
|
3331
|
+
/**
|
|
3332
|
+
* Get human checkpoints for an organization
|
|
3333
|
+
* @param organizationName - Organization name
|
|
3334
|
+
* @returns Array of human checkpoint definitions (empty if none defined)
|
|
3335
|
+
*/
|
|
3336
|
+
getHumanCheckpoints(organizationName) {
|
|
3337
|
+
return this.registry[organizationName]?.humanCheckpoints ?? [];
|
|
3338
|
+
}
|
|
3339
|
+
/**
|
|
3340
|
+
* Get a specific human checkpoint by ID
|
|
3341
|
+
* @param organizationName - Organization name
|
|
3342
|
+
* @param humanCheckpointId - Human checkpoint ID
|
|
3343
|
+
* @returns Human checkpoint definition or null if not found
|
|
3344
|
+
*/
|
|
3345
|
+
getHumanCheckpoint(organizationName, humanCheckpointId) {
|
|
3346
|
+
const humanCheckpoints = this.getHumanCheckpoints(organizationName);
|
|
3347
|
+
return humanCheckpoints.find((hc) => hc.resourceId === humanCheckpointId) ?? null;
|
|
3348
|
+
}
|
|
3349
|
+
// ============================================================================
|
|
3350
|
+
// Serialized Data Access (Pre-computed at Startup)
|
|
3351
|
+
// ============================================================================
|
|
3352
|
+
/**
|
|
3353
|
+
* Get serialized resource definition (instant lookup)
|
|
3354
|
+
* Use for API responses - returns pre-computed JSON-safe structure
|
|
3355
|
+
*
|
|
3356
|
+
* @param organizationName - Organization name
|
|
3357
|
+
* @param resourceId - Resource ID
|
|
3358
|
+
* @returns Serialized definition or null if not found
|
|
3359
|
+
*/
|
|
3360
|
+
getSerializedDefinition(organizationName, resourceId) {
|
|
3361
|
+
const cache = this.serializedCache.get(organizationName);
|
|
3362
|
+
if (!cache) return null;
|
|
3363
|
+
return cache.definitions.agents.get(resourceId) ?? cache.definitions.workflows.get(resourceId) ?? null;
|
|
3364
|
+
}
|
|
3365
|
+
/**
|
|
3366
|
+
* Get resource list for organization (instant lookup)
|
|
3367
|
+
* Use for /resources endpoint - returns pre-computed ResourceDefinition array
|
|
3368
|
+
*
|
|
3369
|
+
* @param organizationName - Organization name
|
|
3370
|
+
* @returns Resource list with workflows, agents, and total count
|
|
3371
|
+
*/
|
|
3372
|
+
getResourceList(organizationName) {
|
|
3373
|
+
const cache = this.serializedCache.get(organizationName);
|
|
3374
|
+
if (!cache) {
|
|
3375
|
+
return { workflows: [], agents: [], total: 0 };
|
|
3376
|
+
}
|
|
3377
|
+
return cache.resources;
|
|
3378
|
+
}
|
|
3379
|
+
/**
|
|
3380
|
+
* Get Command View data for organization (instant lookup)
|
|
3381
|
+
* Use for /command-view endpoint - returns complete graph data
|
|
3382
|
+
*
|
|
3383
|
+
* @param organizationName - Organization name
|
|
3384
|
+
* @returns Command View data with nodes and edges
|
|
3385
|
+
*/
|
|
3386
|
+
getCommandViewData(organizationName) {
|
|
3387
|
+
const cache = this.serializedCache.get(organizationName);
|
|
3388
|
+
if (!cache) {
|
|
3389
|
+
return {
|
|
3390
|
+
workflows: [],
|
|
3391
|
+
agents: [],
|
|
3392
|
+
triggers: [],
|
|
3393
|
+
integrations: [],
|
|
3394
|
+
externalResources: [],
|
|
3395
|
+
humanCheckpoints: [],
|
|
3396
|
+
edges: []
|
|
3397
|
+
};
|
|
3398
|
+
}
|
|
3399
|
+
return cache.commandView;
|
|
3400
|
+
}
|
|
3401
|
+
/**
|
|
3402
|
+
* List resources that have UI interfaces configured
|
|
3403
|
+
* Used by Execution Runner Catalog UI
|
|
3404
|
+
*
|
|
3405
|
+
* @param organizationName - Organization name
|
|
3406
|
+
* @param environment - Optional environment filter ('dev' or 'prod')
|
|
3407
|
+
* @returns Array of resources with interfaces
|
|
3408
|
+
*/
|
|
3409
|
+
listExecutable(organizationName, environment) {
|
|
3410
|
+
const cache = this.serializedCache.get(organizationName);
|
|
3411
|
+
if (!cache) {
|
|
3412
|
+
return [];
|
|
3413
|
+
}
|
|
3414
|
+
const results = [];
|
|
3415
|
+
cache.definitions.workflows.forEach((serializedWorkflow, resourceId) => {
|
|
3416
|
+
if (!serializedWorkflow.interface) return;
|
|
3417
|
+
if (environment && serializedWorkflow.config.status !== environment) return;
|
|
3418
|
+
results.push({
|
|
3419
|
+
resourceId,
|
|
3420
|
+
resourceName: serializedWorkflow.config.name,
|
|
3421
|
+
resourceType: "workflow",
|
|
3422
|
+
description: serializedWorkflow.config.description,
|
|
3423
|
+
status: serializedWorkflow.config.status,
|
|
3424
|
+
version: serializedWorkflow.config.version,
|
|
3425
|
+
interface: serializedWorkflow.interface
|
|
3426
|
+
});
|
|
3427
|
+
});
|
|
3428
|
+
cache.definitions.agents.forEach((serializedAgent, resourceId) => {
|
|
3429
|
+
if (!serializedAgent.interface) return;
|
|
3430
|
+
if (environment && serializedAgent.config.status !== environment) return;
|
|
3431
|
+
results.push({
|
|
3432
|
+
resourceId,
|
|
3433
|
+
resourceName: serializedAgent.config.name,
|
|
3434
|
+
resourceType: "agent",
|
|
3435
|
+
description: serializedAgent.config.description,
|
|
3436
|
+
status: serializedAgent.config.status,
|
|
3437
|
+
version: serializedAgent.config.version,
|
|
3438
|
+
interface: serializedAgent.interface
|
|
3439
|
+
});
|
|
3440
|
+
});
|
|
3441
|
+
return results;
|
|
3442
|
+
}
|
|
3443
|
+
};
|
|
3444
|
+
|
|
3445
|
+
export { ExecutionError, RegistryValidationError, ResourceRegistry, StepType, ToolingError };
|