import {z} from 'zod' export type GetApiV3TelemetryDestinationsArgs = {limit?: number | undefined, starting_after?: string | undefined}; export type GetApiV3TelemetryDestinationsOptions = {baseUrl?: string | undefined, ApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const telemetryContentMode = z.enum(["TELEMETRY_CONTENT_MODE_METADATA_ONLY", "TELEMETRY_CONTENT_MODE_FULL_CONTENT"]); export const telemetryProjectScope = z.enum(["TELEMETRY_PROJECT_SCOPE_ALL", "TELEMETRY_PROJECT_SCOPE_SELECTED", "TELEMETRY_PROJECT_SCOPE_ALL_EXCEPT"]); export const telemetryDestination = z.object({id: z.string().optional(), workspace_id: z.string().optional(), display_name: z.string().optional(), provider: z.string().optional(), endpoint_url: z.string().optional(), request_headers: z.record(z.string(), z.string()).optional(), settings: z.record(z.string(), z.string()).optional(), content_mode: telemetryContentMode.optional(), project_scope: telemetryProjectScope.optional(), project_ids: z.array(z.string()).optional(), enabled: z.boolean().optional(), created_at: z.string().optional(), updated_at: z.string().optional(), failure_count: z.number().int().optional(), last_error: z.string().optional(), last_status_code: z.number().int().optional(), last_attempt_at: z.string().optional(), disabled_reason: z.string().optional()}); export const listTelemetryDestinationsResponse = z.object({destinations: z.array(telemetryDestination).optional(), has_more: z.boolean().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 }; /** * List OpenTelemetry destinations * * GET /v3/telemetry-destinations */ export const getApiV3TelemetryDestinations = async (args: GetApiV3TelemetryDestinationsArgs, options?: GetApiV3TelemetryDestinationsOptions) => { const {baseUrl = "https://my.orq.ai", fetch: fetchFn = fetch, ApiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.limit != null) query.append("limit", String(args.limit)) if (args.starting_after != null) query.append("starting_after", String(args.starting_after)) if (ApiKey !== undefined) headers.set('authorization', `Bearer ${ApiKey}`) const url = `${baseUrl.replace(/\/+$/, '')}/v3/telemetry-destinations${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(listTelemetryDestinationsResponse, await res.json()) };