import {z} from 'zod' export type FeatureFlag = {key: string, value: string}; export type IPairMakerConfig = {_t: 'FullPermutationPairMaker'} | {_t: 'OnlinePairMaker', randomMatchesRatio?: number | undefined, totalComparisonBudget?: number | undefined}; export type IRankingConfigBradleyTerryRankingConfig = {_t: 'BradleyTerryRankingConfig', startingScore: number}; export type IRankingConfigEloConfig = {_t: 'EloConfig', startingScore: number, kFactor: number, scalingFactor: number}; export type MetadataVisibilities = Array<'None' | 'Users' | 'Customers' | 'Admins' | 'Dashboard' | 'All'>; export type IMetadataInput = {_t: 'TextMetadataInput', text: string | null, visibilities: MetadataVisibilities}; export type IAssetInput = {_t: 'ExistingAssetInput', name: string, metadata?: ({[key: string]: IMetadataInput} | null) | undefined, identifier?: (string | null) | undefined} | {_t: 'MultiAssetInput', assets: Array, metadata?: ({[key: string]: IMetadataInput} | null) | undefined, identifier?: (string | null) | undefined} | {_t: 'TextAssetInput', text: string, metadata?: ({[key: string]: IMetadataInput} | null) | undefined, identifier?: (string | null) | undefined}; export type AssetBinding = {segment: string}; export type TextBinding = {literal?: (string | null) | undefined, segment?: (string | null) | undefined, language?: ('Original' | 'English' | null) | undefined}; export type IRapidSpecBoundingBoxRapidSpec = {_t: 'BoundingBox', asset: AssetBinding, context?: ({literal?: (string | null) | undefined, segment?: (string | null) | undefined, language?: ('Original' | 'English' | null) | undefined} | null) | undefined, contextAssets?: (Array | null) | undefined, target: TextBinding}; export type OptionsBindingOption = {label: string, value: string}; export type OptionsBinding = {literal?: (Array | null) | undefined, segment?: (string | null) | undefined}; export type IRapidSpecClassifyRapidSpec = {_t: 'Classify', asset: AssetBinding, context?: ({literal?: (string | null) | undefined, segment?: (string | null) | undefined, language?: ('Original' | 'English' | null) | undefined} | null) | undefined, contextAssets?: (Array | null) | undefined, title: TextBinding, categories: OptionsBinding}; export type IRapidSpecCompareRapidSpec = {_t: 'Compare', asset: AssetBinding, context?: ({literal?: (string | null) | undefined, segment?: (string | null) | undefined, language?: ('Original' | 'English' | null) | undefined} | null) | undefined, contextAssets?: (Array | null) | undefined, criteria: TextBinding, indexIdentifiers?: (Array | null) | undefined}; export type IRapidSpecFreeTextRapidSpec = {_t: 'FreeText', asset: AssetBinding, context?: ({literal?: (string | null) | undefined, segment?: (string | null) | undefined, language?: ('Original' | 'English' | null) | undefined} | null) | undefined, contextAssets?: (Array | null) | undefined, question: TextBinding, shouldValidateResponse?: (boolean | null) | undefined, validationSystemPrompt?: (string | null) | undefined}; export type IRapidSpecLineRapidSpec = {_t: 'Line', asset: AssetBinding, context?: ({literal?: (string | null) | undefined, segment?: (string | null) | undefined, language?: ('Original' | 'English' | null) | undefined} | null) | undefined, contextAssets?: (Array | null) | undefined, target: TextBinding}; export type IRapidSpecLocateRapidSpec = {_t: 'Locate', asset: AssetBinding, context?: ({literal?: (string | null) | undefined, segment?: (string | null) | undefined, language?: ('Original' | 'English' | null) | undefined} | null) | undefined, contextAssets?: (Array | null) | undefined, target: TextBinding}; export type IRapidSpecNamedEntityRapidSpec = {_t: 'NamedEntity', asset: AssetBinding, context?: ({literal?: (string | null) | undefined, segment?: (string | null) | undefined, language?: ('Original' | 'English' | null) | undefined} | null) | undefined, contextAssets?: (Array | null) | undefined, target: TextBinding, classes: Array}; export type IRapidSpecPolygonRapidSpec = {_t: 'Polygon', asset: AssetBinding, context?: ({literal?: (string | null) | undefined, segment?: (string | null) | undefined, language?: ('Original' | 'English' | null) | undefined} | null) | undefined, contextAssets?: (Array | null) | undefined, target: TextBinding}; export type IRapidSpecScrubRapidSpec = {_t: 'Scrub', asset: AssetBinding, context?: ({literal?: (string | null) | undefined, segment?: (string | null) | undefined, language?: ('Original' | 'English' | null) | undefined} | null) | undefined, contextAssets?: (Array | null) | undefined, target: TextBinding}; export type IRapidSpecTranscriptionRapidSpec = {_t: 'Transcription', asset: AssetBinding, context?: ({literal?: (string | null) | undefined, segment?: (string | null) | undefined, language?: ('Original' | 'English' | null) | undefined} | null) | undefined, contextAssets?: (Array | null) | undefined, title: TextBinding, transcription: TextBinding}; export type IOrderWorkflowInput = {_t: 'EvaluationWorkflow', validationSetId: string, shouldAcceptIncorrect: boolean, featureFlags?: Array | undefined} | {_t: 'GroupedRankingWorkflow', criteria: string, pairMakerConfig?: IPairMakerConfig | undefined, rankingConfig?: (IRankingConfigBradleyTerryRankingConfig | IRankingConfigEloConfig | null) | undefined, contexts?: ({[key: string]: string} | null) | undefined, contextAssets?: ({[key: string]: IAssetInput} | null) | undefined, featureFlags?: Array | undefined, maxParallelism?: number | undefined} | {_t: 'SimpleWorkflow', rapid?: (IRapidSpecBoundingBoxRapidSpec | IRapidSpecClassifyRapidSpec | IRapidSpecCompareRapidSpec | IRapidSpecFreeTextRapidSpec | IRapidSpecLineRapidSpec | IRapidSpecLocateRapidSpec | IRapidSpecNamedEntityRapidSpec | IRapidSpecPolygonRapidSpec | IRapidSpecScrubRapidSpec | IRapidSpecTranscriptionRapidSpec | null) | undefined, batchSize?: (number | null) | undefined, featureFlags?: Array | undefined}; export type IReferee = {_t: 'BudgetReferee', totalBudget: number} | {_t: 'EarlyStoppingReferee', maxVotes: number, threshold: number} | {_t: 'NaiveReferee', totalVotes: number} | {_t: 'QuorumReferee', maxVotes: number, threshold: number}; export type CreateJobRevisionEndpointInput = {workflow?: IOrderWorkflowInput | undefined, referee?: IReferee | undefined, datasetId?: string | undefined, rapidFeatureFlags?: Array | undefined, campaignFeatureFlags?: Array | undefined, aggregatorType?: ('NonCommittal' | 'MajorityVote' | 'SimpleMatchup' | 'LocateCluster' | 'Classification' | 'Locate' | 'BoundingBox' | 'Line' | 'Transcription' | 'SinglePointLocate' | 'FreeText' | 'Scrub' | 'Ranking' | 'MultiRanking' | null) | undefined, validationSetId?: (string | null) | undefined, baseRevisionNumber?: (number | null) | undefined, requireLatest?: boolean | undefined}; export type CreateApiJobDefinitionDefinitionIdRevisionArgs = {definitionId: string, body: CreateJobRevisionEndpointInput}; export type CreateApiJobDefinitionDefinitionIdRevisionOptions = {baseUrl?: string | undefined, OpenIdConnect?: string | undefined, fetch?: typeof fetch | undefined}; export const createJobRevisionEndpointOutput = z.object({revisionNumber: z.number().int(), pipelineId: z.string()}); 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 }; /** * Creates a new revision for an existing job definition. * * POST /job/definition/{definitionId}/revision */ export const createApiJobDefinitionDefinitionIdRevision = async (args: CreateApiJobDefinitionDefinitionIdRevisionArgs, options?: CreateApiJobDefinitionDefinitionIdRevisionOptions) => { const {baseUrl = "https://api.rapidata.ai", fetch: fetchFn = fetch, OpenIdConnect} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (OpenIdConnect !== undefined) headers.set('authorization', `Bearer ${OpenIdConnect}`) const url = `${baseUrl.replace(/\/+$/, '')}/job/definition/${encodeURIComponent(String(args.definitionId))}/revision${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", 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(createJobRevisionEndpointOutput, await res.json()) };