import {z} from 'zod' export type GatewayDatasetState = 'STATE_UNSPECIFIED' | 'UPLOADING' | 'READY'; export type GatewayCode = 'OK' | 'CANCELLED' | 'UNKNOWN' | 'INVALID_ARGUMENT' | 'DEADLINE_EXCEEDED' | 'NOT_FOUND' | 'ALREADY_EXISTS' | 'PERMISSION_DENIED' | 'UNAUTHENTICATED' | 'RESOURCE_EXHAUSTED' | 'FAILED_PRECONDITION' | 'ABORTED' | 'OUT_OF_RANGE' | 'UNIMPLEMENTED' | 'INTERNAL' | 'UNAVAILABLE' | 'DATA_LOSS'; export type GatewayStatus = {code?: GatewayCode | undefined, message?: string | undefined}; export type GatewayUserUploaded = Record; export type GatewayEvaluationResult = {evaluationJobId: string}; export type DatasetFormat = 'FORMAT_UNSPECIFIED' | 'CHAT' | 'COMPLETION' | 'RL'; export type GatewayTransformed = {sourceDatasetId: string, filter?: string | undefined, originalFormat?: DatasetFormat | undefined}; export type GatewaySplitted = {sourceDatasetId: string}; export type GatewayEvalProtocol = Record; export type GatewayEncryptionState = 'ENCRYPTION_STATE_UNSPECIFIED' | 'ENCRYPTION_STATE_PLAINTEXT' | 'ENCRYPTION_STATE_CMEK'; export type PatchApiV1AccountsAccountIdDatasetsDatasetIdArgs = {account_id: string, dataset_id: string, body: {displayName?: string | undefined, createTime?: string | undefined, state?: GatewayDatasetState | undefined, status?: GatewayStatus | undefined, exampleCount?: unknown | undefined, userUploaded?: GatewayUserUploaded | undefined, evaluationResult?: GatewayEvaluationResult | undefined, transformed?: GatewayTransformed | undefined, splitted?: GatewaySplitted | undefined, evalProtocol?: GatewayEvalProtocol | undefined, externalUrl?: string | undefined, format?: DatasetFormat | undefined, createdBy?: string | undefined, updateTime?: string | undefined, sourceJobName?: string | undefined, estimatedTokenCount?: unknown | undefined, averageTurnCount?: number | undefined, encryptionState?: GatewayEncryptionState | undefined}}; export type PatchApiV1AccountsAccountIdDatasetsDatasetIdOptions = {baseUrl: string, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const gatewayDatasetState = z.enum(["STATE_UNSPECIFIED", "UPLOADING", "READY"]); export const gatewayCode = z.enum(["OK", "CANCELLED", "UNKNOWN", "INVALID_ARGUMENT", "DEADLINE_EXCEEDED", "NOT_FOUND", "ALREADY_EXISTS", "PERMISSION_DENIED", "UNAUTHENTICATED", "RESOURCE_EXHAUSTED", "FAILED_PRECONDITION", "ABORTED", "OUT_OF_RANGE", "UNIMPLEMENTED", "INTERNAL", "UNAVAILABLE", "DATA_LOSS"]); export const gatewayStatus = z.object({code: gatewayCode.optional(), message: z.string().optional()}); export const gatewayUserUploaded = z.object({}); export const gatewayEvaluationResult = z.object({evaluationJobId: z.string()}); export const datasetFormat = z.enum(["FORMAT_UNSPECIFIED", "CHAT", "COMPLETION", "RL"]); export const gatewayTransformed = z.object({sourceDatasetId: z.string(), filter: z.string().optional(), originalFormat: datasetFormat.optional()}); export const gatewaySplitted = z.object({sourceDatasetId: z.string()}); export const gatewayEvalProtocol = z.object({}); export const gatewayEncryptionState = z.enum(["ENCRYPTION_STATE_UNSPECIFIED", "ENCRYPTION_STATE_PLAINTEXT", "ENCRYPTION_STATE_CMEK"]); export const gatewayDataset = z.object({name: z.string().optional(), displayName: z.string().optional(), createTime: z.string().optional(), state: gatewayDatasetState.optional(), status: gatewayStatus.optional(), exampleCount: z.string().optional(), userUploaded: gatewayUserUploaded.optional(), evaluationResult: gatewayEvaluationResult.optional(), transformed: gatewayTransformed.optional(), splitted: gatewaySplitted.optional(), evalProtocol: gatewayEvalProtocol.optional(), externalUrl: z.string().optional(), format: datasetFormat.optional(), createdBy: z.string().optional(), updateTime: z.string().optional(), sourceJobName: z.string().optional(), estimatedTokenCount: z.string().optional(), averageTurnCount: z.number().optional(), encryptionState: gatewayEncryptionState.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 }; /** * Update Dataset * * PATCH /v1/accounts/{account_id}/datasets/{dataset_id} */ export const patchApiV1AccountsAccountIdDatasetsDatasetId = async (args: PatchApiV1AccountsAccountIdDatasetsDatasetIdArgs, options: PatchApiV1AccountsAccountIdDatasetsDatasetIdOptions) => { const {baseUrl, fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/accounts/${encodeURIComponent(String(args.account_id))}/datasets/${encodeURIComponent(String(args.dataset_id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", 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(gatewayDataset, await res.json()) };