import {z} from 'zod' export type V1IndexData = {data?: Array | undefined, search_score?: number | undefined, tenant?: string | undefined, will_be_deleted_at?: string | undefined}; export type GoogleprotobufAny = {'@type'?: string | undefined} | {[key: string]: unknown}; export type V1Meta = {annotations?: {[key: string]: string} | undefined, create_time?: string | undefined, created_by?: string | undefined, description?: string | undefined, index_data?: V1IndexData | undefined, kind?: string | undefined, name: string, parent_kind?: string | undefined, parent_uuid?: string | undefined, references?: {[key: string]: GoogleprotobufAny} | undefined, tags?: Array | undefined, update_time?: string | undefined, updated_by?: string | undefined, upsert_time?: string | undefined, version?: string | undefined}; export type ContextContextType = 'CONTEXT_TYPE_UNSPECIFIED' | 'CONTEXT_TYPE_MAIN' | 'CONTEXT_TYPE_EXTERNAL' | 'CONTEXT_TYPE_CI_RUN' | 'CONTEXT_TYPE_SBOM' | 'CONTEXT_TYPE_REF'; export type V1Context = {id: string, tags?: Array | undefined, type: ContextContextType, will_be_deleted_at?: string | undefined}; export type V1Language = 'LANGUAGE_UNSPECIFIED' | 'LANGUAGE_GO' | 'LANGUAGE_JAVA' | 'LANGUAGE_SCALA' | 'LANGUAGE_PYTHON' | 'LANGUAGE_RUST' | 'LANGUAGE_JS' | 'LANGUAGE_RUBY' | 'LANGUAGE_CSHARP' | 'LANGUAGE_PHP' | 'LANGUAGE_TYPESCRIPT' | 'LANGUAGE_KOTLIN' | 'LANGUAGE_SWIFT' | 'LANGUAGE_OBJECTIVEC' | 'LANGUAGE_C' | 'LANGUAGE_CPP' | 'LANGUAGE_SWIFTURL' | 'LANGUAGE_CONAN' | 'LANGUAGE_GOSU'; export type V1DependencyScope = 'DEPENDENCY_SCOPE_UNSPECIFIED' | 'DEPENDENCY_SCOPE_TEST' | 'DEPENDENCY_SCOPE_BUILD' | 'DEPENDENCY_SCOPE_NORMAL'; export type V1SegmentContentKind = 'SEGMENT_CONTENT_KIND_UNSPECIFIED' | 'SEGMENT_CONTENT_KIND_FUNCTION' | 'SEGMENT_CONTENT_KIND_TYPE' | 'SEGMENT_CONTENT_KIND_LICENSE'; export type V1EmbeddingVector = {vector?: Array | undefined}; export type V1SegmentMetadata = {code_size?: unknown | undefined, content_kind?: V1SegmentContentKind | undefined, embedding?: V1EmbeddingVector | undefined, signature?: string | undefined}; export type V1FileSegmentsSpec = {file_hash?: string | undefined, language?: V1Language | undefined, project_uuid?: string | undefined, scope?: V1DependencyScope | undefined, segmenter_version?: number | undefined, segments?: Array | undefined}; export type V1TenantMeta = {namespace: string}; export type V1FileSegments = {context: V1Context, meta: V1Meta, spec: V1FileSegmentsSpec, tenant_meta?: V1TenantMeta | undefined, uuid?: string | undefined}; export type V1BatchFileSegmentsSpec = {data?: Array | undefined}; export type BatchFileSegmentsServiceCreateBatchFileSegmentsBody = {meta?: V1Meta | undefined, spec?: V1BatchFileSegmentsSpec | undefined, tenant_meta?: Record | undefined, uuid?: string | undefined}; export type CreateApiV1NamespacesTenantMetaNamespaceBatchFileSegmentsArgs = {'tenant_meta.namespace': string, body: BatchFileSegmentsServiceCreateBatchFileSegmentsBody}; export type CreateApiV1NamespacesTenantMetaNamespaceBatchFileSegmentsOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const v1IndexData = z.object({data: z.array(z.string()).optional(), search_score: z.number().optional(), tenant: z.string().optional(), will_be_deleted_at: z.string().optional()}); export const googleprotobufAny = z.object({"@type": z.string().optional()}).and(z.record(z.string(), z.unknown())); export const v1Meta = z.object({annotations: z.record(z.string(), z.string()).optional(), create_time: z.string().optional(), created_by: z.string().optional(), description: z.string().optional(), index_data: v1IndexData.optional(), kind: z.string().optional(), name: z.string(), parent_kind: z.string().optional(), parent_uuid: z.string().optional(), references: z.record(z.string(), googleprotobufAny).optional(), tags: z.array(z.string()).optional(), update_time: z.string().optional(), updated_by: z.string().optional(), upsert_time: z.string().optional(), version: z.string().optional()}); export const contextContextType = z.enum(["CONTEXT_TYPE_UNSPECIFIED", "CONTEXT_TYPE_MAIN", "CONTEXT_TYPE_EXTERNAL", "CONTEXT_TYPE_CI_RUN", "CONTEXT_TYPE_SBOM", "CONTEXT_TYPE_REF"]); export const v1Context = z.object({id: z.string(), tags: z.array(z.string()).optional(), type: contextContextType, will_be_deleted_at: z.string().optional()}); export const v1Language = z.enum(["LANGUAGE_UNSPECIFIED", "LANGUAGE_GO", "LANGUAGE_JAVA", "LANGUAGE_SCALA", "LANGUAGE_PYTHON", "LANGUAGE_RUST", "LANGUAGE_JS", "LANGUAGE_RUBY", "LANGUAGE_CSHARP", "LANGUAGE_PHP", "LANGUAGE_TYPESCRIPT", "LANGUAGE_KOTLIN", "LANGUAGE_SWIFT", "LANGUAGE_OBJECTIVEC", "LANGUAGE_C", "LANGUAGE_CPP", "LANGUAGE_SWIFTURL", "LANGUAGE_CONAN", "LANGUAGE_GOSU"]); export const v1DependencyScope = z.enum(["DEPENDENCY_SCOPE_UNSPECIFIED", "DEPENDENCY_SCOPE_TEST", "DEPENDENCY_SCOPE_BUILD", "DEPENDENCY_SCOPE_NORMAL"]); export const v1SegmentContentKind = z.enum(["SEGMENT_CONTENT_KIND_UNSPECIFIED", "SEGMENT_CONTENT_KIND_FUNCTION", "SEGMENT_CONTENT_KIND_TYPE", "SEGMENT_CONTENT_KIND_LICENSE"]); export const v1EmbeddingVector = z.object({vector: z.array(z.number()).optional()}); export const v1SegmentMetadata = z.object({code_size: z.string().optional(), content_kind: v1SegmentContentKind.optional(), embedding: v1EmbeddingVector.optional(), signature: z.string().optional()}); export const v1FileSegmentsSpec = z.object({file_hash: z.string().optional(), language: v1Language.optional(), project_uuid: z.string().optional(), scope: v1DependencyScope.optional(), segmenter_version: z.number().int().optional(), segments: z.array(v1SegmentMetadata).optional()}); export const v1TenantMeta = z.object({namespace: z.string()}); export const v1FileSegments = z.object({context: v1Context, meta: v1Meta, spec: v1FileSegmentsSpec, tenant_meta: v1TenantMeta.optional(), uuid: z.string().optional()}); export const v1BatchFileSegmentsSpec = z.object({data: z.array(v1FileSegments).optional()}); export const v1BatchFileSegments = z.object({meta: v1Meta.optional(), spec: v1BatchFileSegmentsSpec.optional(), tenant_meta: v1TenantMeta.optional(), uuid: z.string().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 }; /** * CreateBatchFileSegments * * POST /v1/namespaces/{tenant_meta.namespace}/batch/file-segments */ export const createApiV1NamespacesTenantMetaNamespaceBatchFileSegments = async (args: CreateApiV1NamespacesTenantMetaNamespaceBatchFileSegmentsArgs, options?: CreateApiV1NamespacesTenantMetaNamespaceBatchFileSegmentsOptions) => { const {baseUrl = "https://api.endorlabs.com", 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/namespaces/${encodeURIComponent(String(args['tenant_meta.namespace']))}/batch/file-segments${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(v1BatchFileSegments, await res.json()) };