Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 11x 11x 11x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 18x 18x 18x 18x 18x 1x 1x 1x 1x 1x 1x 1x 18x 6x 6x 5x 6x 12x 18x 1x 1x 1x 1x 1x 1x 1x 1x 18x 3x 3x 2x 3x 15x 18x 1x 1x 1x 1x 1x 1x 1x 1x 18x 18x 9x 2x 18x 1x 1x 17x 18x 1x 1x 1x 1x 1x 1x | import { z } from 'zod';
// Model type enum
export const ModelType = {
TEXT: 'text',
EMBED: 'embed',
} as const;
export type ModelType = (typeof ModelType)[keyof typeof ModelType];
export const ModelTypeSchema = z.enum(['text', 'embed']);
export const Model = z.object({
id: z.uuid(),
ai_provider_id: z.uuid(),
model_name: z.string().min(1),
model_type: ModelTypeSchema,
embedding_dimensions: z.number().int().positive().nullable(),
created_at: z.iso.datetime({ offset: true }),
updated_at: z.iso.datetime({ offset: true }),
});
export type Model = z.infer<typeof Model>;
export const ModelQueryParams = z
.object({
id: z.uuid().optional(),
ai_provider_id: z.uuid().optional(),
model_name: z.string().min(1).optional(),
model_type: ModelTypeSchema.optional(),
limit: z.coerce.number().int().positive().optional(),
offset: z.coerce.number().int().min(0).optional(),
})
.strict();
export type ModelQueryParams = z.infer<typeof ModelQueryParams>;
export const ModelCreateParams = z
.object({
ai_provider_id: z.uuid(),
model_name: z.string().min(1),
model_type: ModelTypeSchema.default('text'),
embedding_dimensions: z.number().int().positive().nullable().optional(),
})
.strict()
.refine(
(data) => {
// embedding_dimensions required for embed models, must be null for text models
if (data.model_type === 'embed') {
return data.embedding_dimensions != null;
}
return data.embedding_dimensions == null;
},
{
message:
'embedding_dimensions is required for embed models and must not be set for text models',
path: ['embedding_dimensions'],
},
);
export type ModelCreateParams = z.infer<typeof ModelCreateParams>;
export const ModelUpdateParams = z
.object({
model_name: z.string().min(1).optional(),
model_type: ModelTypeSchema.optional(),
embedding_dimensions: z.number().int().positive().nullable().optional(),
})
.strict()
.refine(
(data) => {
const updateFields = ['model_name', 'model_type', 'embedding_dimensions'];
return updateFields.some(
(field) => data[field as keyof typeof data] !== undefined,
);
},
{
message: 'At least one field must be provided for update',
path: ['model_name'],
},
)
.refine(
(data) => {
// If explicitly setting model_type to 'embed', embedding_dimensions must be provided
if (data.model_type === 'embed') {
return (
data.embedding_dimensions !== undefined &&
data.embedding_dimensions !== null
);
}
return true;
},
{
message:
'embedding_dimensions is required when changing model_type to embed',
path: ['embedding_dimensions'],
},
)
.refine(
(data) => {
// If explicitly setting model_type to 'text', embedding_dimensions must be null or not set
if (data.model_type === 'text') {
return (
data.embedding_dimensions === undefined ||
data.embedding_dimensions === null
);
}
return true;
},
{
message:
'embedding_dimensions must not be set when changing model_type to text',
path: ['embedding_dimensions'],
},
)
.refine(
(data) => {
// If only embedding_dimensions is being set (without model_type), it cannot be a positive number
// because we don't know if the target model is embed type
// This prevents accidentally setting dimensions on a text model
if (
data.model_type === undefined &&
data.embedding_dimensions !== undefined &&
data.embedding_dimensions !== null
) {
// Setting dimensions without specifying model_type is not allowed
// because we can't validate consistency without knowing the target model's type
return false;
}
return true;
},
{
message:
'model_type must be specified as "embed" when setting embedding_dimensions',
path: ['model_type'],
},
);
export type ModelUpdateParams = z.infer<typeof ModelUpdateParams>;
|