refactor(config): dedupe repeated zod schema shapes
This commit is contained in:
parent
884ca65dc7
commit
e290f4ca41
@ -128,6 +128,31 @@ const HttpUrlSchema = z
|
|||||||
return protocol === "http:" || protocol === "https:";
|
return protocol === "http:" || protocol === "https:";
|
||||||
}, "Expected http:// or https:// URL");
|
}, "Expected http:// or https:// URL");
|
||||||
|
|
||||||
|
const ResponsesEndpointUrlFetchShape = {
|
||||||
|
allowUrl: z.boolean().optional(),
|
||||||
|
urlAllowlist: z.array(z.string()).optional(),
|
||||||
|
allowedMimes: z.array(z.string()).optional(),
|
||||||
|
maxBytes: z.number().int().positive().optional(),
|
||||||
|
maxRedirects: z.number().int().nonnegative().optional(),
|
||||||
|
timeoutMs: z.number().int().positive().optional(),
|
||||||
|
};
|
||||||
|
|
||||||
|
const SkillEntrySchema = z
|
||||||
|
.object({
|
||||||
|
enabled: z.boolean().optional(),
|
||||||
|
apiKey: SecretInputSchema.optional().register(sensitive),
|
||||||
|
env: z.record(z.string(), z.string()).optional(),
|
||||||
|
config: z.record(z.string(), z.unknown()).optional(),
|
||||||
|
})
|
||||||
|
.strict();
|
||||||
|
|
||||||
|
const PluginEntrySchema = z
|
||||||
|
.object({
|
||||||
|
enabled: z.boolean().optional(),
|
||||||
|
config: z.record(z.string(), z.unknown()).optional(),
|
||||||
|
})
|
||||||
|
.strict();
|
||||||
|
|
||||||
export const OpenClawSchema = z
|
export const OpenClawSchema = z
|
||||||
.object({
|
.object({
|
||||||
$schema: z.string().optional(),
|
$schema: z.string().optional(),
|
||||||
@ -687,13 +712,8 @@ export const OpenClawSchema = z
|
|||||||
maxUrlParts: z.number().int().nonnegative().optional(),
|
maxUrlParts: z.number().int().nonnegative().optional(),
|
||||||
files: z
|
files: z
|
||||||
.object({
|
.object({
|
||||||
allowUrl: z.boolean().optional(),
|
...ResponsesEndpointUrlFetchShape,
|
||||||
urlAllowlist: z.array(z.string()).optional(),
|
|
||||||
allowedMimes: z.array(z.string()).optional(),
|
|
||||||
maxBytes: z.number().int().positive().optional(),
|
|
||||||
maxChars: z.number().int().positive().optional(),
|
maxChars: z.number().int().positive().optional(),
|
||||||
maxRedirects: z.number().int().nonnegative().optional(),
|
|
||||||
timeoutMs: z.number().int().positive().optional(),
|
|
||||||
pdf: z
|
pdf: z
|
||||||
.object({
|
.object({
|
||||||
maxPages: z.number().int().positive().optional(),
|
maxPages: z.number().int().positive().optional(),
|
||||||
@ -707,12 +727,7 @@ export const OpenClawSchema = z
|
|||||||
.optional(),
|
.optional(),
|
||||||
images: z
|
images: z
|
||||||
.object({
|
.object({
|
||||||
allowUrl: z.boolean().optional(),
|
...ResponsesEndpointUrlFetchShape,
|
||||||
urlAllowlist: z.array(z.string()).optional(),
|
|
||||||
allowedMimes: z.array(z.string()).optional(),
|
|
||||||
maxBytes: z.number().int().positive().optional(),
|
|
||||||
maxRedirects: z.number().int().nonnegative().optional(),
|
|
||||||
timeoutMs: z.number().int().positive().optional(),
|
|
||||||
})
|
})
|
||||||
.strict()
|
.strict()
|
||||||
.optional(),
|
.optional(),
|
||||||
@ -781,19 +796,7 @@ export const OpenClawSchema = z
|
|||||||
})
|
})
|
||||||
.strict()
|
.strict()
|
||||||
.optional(),
|
.optional(),
|
||||||
entries: z
|
entries: z.record(z.string(), SkillEntrySchema).optional(),
|
||||||
.record(
|
|
||||||
z.string(),
|
|
||||||
z
|
|
||||||
.object({
|
|
||||||
enabled: z.boolean().optional(),
|
|
||||||
apiKey: SecretInputSchema.optional().register(sensitive),
|
|
||||||
env: z.record(z.string(), z.string()).optional(),
|
|
||||||
config: z.record(z.string(), z.unknown()).optional(),
|
|
||||||
})
|
|
||||||
.strict(),
|
|
||||||
)
|
|
||||||
.optional(),
|
|
||||||
})
|
})
|
||||||
.strict()
|
.strict()
|
||||||
.optional(),
|
.optional(),
|
||||||
@ -814,17 +817,7 @@ export const OpenClawSchema = z
|
|||||||
})
|
})
|
||||||
.strict()
|
.strict()
|
||||||
.optional(),
|
.optional(),
|
||||||
entries: z
|
entries: z.record(z.string(), PluginEntrySchema).optional(),
|
||||||
.record(
|
|
||||||
z.string(),
|
|
||||||
z
|
|
||||||
.object({
|
|
||||||
enabled: z.boolean().optional(),
|
|
||||||
config: z.record(z.string(), z.unknown()).optional(),
|
|
||||||
})
|
|
||||||
.strict(),
|
|
||||||
)
|
|
||||||
.optional(),
|
|
||||||
installs: z
|
installs: z
|
||||||
.record(
|
.record(
|
||||||
z.string(),
|
z.string(),
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user