import {z} from 'zod' export type CreateApiAgentsPyflinkArgs = {body: BodyInit}; export type CreateApiAgentsPyflinkOptions = {baseUrl?: string | undefined, FronteggHTTPAuthentication?: string | undefined, fetch?: typeof fetch | undefined}; export const appModelsApiAgentsApiModelsFlinkJobsFlinkJobTypeEnum = z.enum(["pyflink", "jar", "agent_config", "knowledge_base"]); export const flinkJobStatusEnum = z.enum(["CREATED", "DEPLOYING", "RUNNING", "CANCELLING", "CANCELLED", "FAILED", "FINISHED"]); export const appModelsApiAgentsApiModelsFlinkJobsFlinkJobResponse = z.object({_id: z.string(), name: z.string(), job_type: appModelsApiAgentsApiModelsFlinkJobsFlinkJobTypeEnum, status: flinkJobStatusEnum, desired_status: flinkJobStatusEnum.nullable().optional(), flink_job_name: z.string(), flink_job_id: z.string().nullable().optional(), parallelism: z.number().int().optional(), error_message: z.string().nullable().optional(), agent_config: z.record(z.string(), z.unknown()).nullable().optional(), created_by: z.string().nullable().optional(), created_timestamp: z.string().nullable().optional(), updated_timestamp: z.string().nullable().optional()}).and(z.record(z.string(), z.unknown())); 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 }; /** * Deploy Pyflink Job * * POST /agents/pyflink */ export const createApiAgentsPyflink = async (args: CreateApiAgentsPyflinkArgs, options?: CreateApiAgentsPyflinkOptions) => { const {baseUrl = "https://api.streamkap.com", fetch: fetchFn = fetch, FronteggHTTPAuthentication} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (FronteggHTTPAuthentication !== undefined) headers.set('authorization', `Bearer ${FronteggHTTPAuthentication}`) const url = `${baseUrl.replace(/\/+$/, '')}/agents/pyflink${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: args.body}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(appModelsApiAgentsApiModelsFlinkJobsFlinkJobResponse, await res.json()) };