import {z} from 'zod' export type PlaygroundV1UpdateSessionRequest = {params?: string | undefined, sessionId?: string | undefined, status?: string | undefined, systemPrompt?: string | undefined, title?: string | undefined}; export type UpdateApiV1PlaygroundSessionsSessionIdArgs = {sessionId: string, body: PlaygroundV1UpdateSessionRequest}; export type UpdateApiV1PlaygroundSessionsSessionIdOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const playgroundV1Session = z.object({categoryId: z.string().optional(), createdAt: z.string().optional(), id: z.string().optional(), modelId: z.string().optional(), params: z.string().optional(), status: z.string().optional(), systemPrompt: z.string().optional(), title: z.string().optional(), totalBilledMicros: z.string().optional(), totalTokens: z.string().optional(), updatedAt: z.string().optional(), userId: z.string().optional()}); export const playgroundV1UpdateSessionReply = z.object({session: playgroundV1Session.optional()}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * UpdateSession 更新会话 * * PUT /v1/playground/sessions/{sessionId} */ export const updateApiV1PlaygroundSessionsSessionId = async (args: UpdateApiV1PlaygroundSessionsSessionIdArgs, options: UpdateApiV1PlaygroundSessionsSessionIdOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/v1/playground/sessions/${encodeURIComponent(String(args.sessionId))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(playgroundV1UpdateSessionReply, await res.json()) };