| import { z } from 'zod';
|
| import { pageInfoSchema } from '@/gql/pagination';
|
| import { apiKeySchema } from '@/features/apikeys/data/schema';
|
| import { channelSchema } from '@/features/channels/data';
|
| import { usageLogSchema } from '@/features/usage-logs/data/schema';
|
|
|
|
|
| export const requestStatusSchema = z.enum(['pending', 'processing', 'completed', 'failed', 'canceled']);
|
| export type RequestStatus = z.infer<typeof requestStatusSchema>;
|
|
|
|
|
| export const requestSourceSchema = z.enum(['api', 'playground', 'test']);
|
| export type RequestSource = z.infer<typeof requestSourceSchema>;
|
|
|
|
|
| export const requestExecutionStatusSchema = z.enum(['pending', 'processing', 'completed', 'failed', 'canceled']);
|
| export type RequestExecutionStatus = z.infer<typeof requestExecutionStatusSchema>;
|
|
|
|
|
| export const requestExecutionSchema = z.object({
|
| id: z.string(),
|
| createdAt: z.coerce.date(),
|
| updatedAt: z.coerce.date(),
|
|
|
|
|
|
|
| channel: channelSchema.partial().nullable().optional(),
|
| modelID: z.string(),
|
| requestHeaders: z.any().nullable().optional(),
|
| requestBody: z.any(),
|
| responseBody: z.any().nullable(),
|
| responseChunks: z.array(z.any()).nullable(),
|
| errorMessage: z.string().nullable(),
|
| status: requestExecutionStatusSchema,
|
| format: z.string().optional(),
|
| metricsLatencyMs: z.number().nullable().optional(),
|
| metricsFirstTokenLatencyMs: z.number().nullable().optional(),
|
| });
|
| export type RequestExecution = z.infer<typeof requestExecutionSchema>;
|
|
|
|
|
| export const requestSchema = z.object({
|
| id: z.string(),
|
| createdAt: z.coerce.date(),
|
| updatedAt: z.coerce.date(),
|
|
|
| apiKey: apiKeySchema.partial().nullable().optional(),
|
|
|
| channel: channelSchema.partial().nullable().optional(),
|
| source: requestSourceSchema,
|
| modelID: z.string(),
|
| requestHeaders: z.any().nullable().optional(),
|
| requestBody: z.any().nullable().optional(),
|
| responseBody: z.any().nullable().optional(),
|
| responseChunks: z.array(z.any()).nullable().optional(),
|
| status: requestStatusSchema,
|
| format: z.string().optional(),
|
| clientIP: z.string().nullable().optional(),
|
| stream: z.boolean().nullable(),
|
| metricsLatencyMs: z.number().nullable().optional(),
|
| metricsFirstTokenLatencyMs: z.number().nullable().optional(),
|
| executions: z
|
| .object({
|
| edges: z.array(
|
| z.object({
|
| node: requestExecutionSchema.partial().nullable().optional(),
|
| cursor: z.string(),
|
| })
|
| ),
|
| pageInfo: pageInfoSchema,
|
| totalCount: z.number(),
|
| })
|
| .optional(),
|
| usageLogs: z
|
| .object({
|
| edges: z
|
| .array(
|
| z.object({
|
| node: usageLogSchema.partial().nullable().optional(),
|
| cursor: z.string().optional(),
|
| })
|
| )
|
| .optional(),
|
| pageInfo: pageInfoSchema.optional(),
|
| })
|
| .optional()
|
| .nullable(),
|
| });
|
|
|
| export type Request = z.infer<typeof requestSchema>;
|
|
|
|
|
| export const requestConnectionSchema = z.object({
|
| edges: z.array(
|
| z.object({
|
| node: requestSchema,
|
| cursor: z.string(),
|
| })
|
| ),
|
| pageInfo: pageInfoSchema,
|
| totalCount: z.number(),
|
| });
|
| export type RequestConnection = z.infer<typeof requestConnectionSchema>;
|
|
|
|
|
| export const requestExecutionConnectionSchema = z.object({
|
| edges: z.array(
|
| z.object({
|
| node: requestExecutionSchema,
|
| cursor: z.string(),
|
| })
|
| ),
|
| pageInfo: pageInfoSchema,
|
| totalCount: z.number(),
|
| });
|
| export type RequestExecutionConnection = z.infer<typeof requestExecutionConnectionSchema>;
|
|
|