import {z} from 'zod' export type SessionLawSearchRequest = {query: string, jurisdiction?: ('al' | 'ak' | 'as' | 'az' | 'ar' | 'ca' | 'co' | 'ct' | 'de' | 'dc' | 'fl' | 'ga' | 'gu' | 'hi' | 'id' | 'il' | 'in' | 'ia' | 'ks' | 'ky' | 'la' | 'me' | 'md' | 'ma' | 'mi' | 'mn' | 'ms' | 'mo' | 'mt' | 'ne' | 'nv' | 'nh' | 'nj' | 'nm' | 'ny' | 'nc' | 'nd' | 'mp' | 'oh' | 'ok' | 'or' | 'pa' | 'pr' | 'ri' | 'sc' | 'sd' | 'tn' | 'tx' | 'ut' | 'vt' | 'vi' | 'va' | 'wa' | 'wv' | 'wi' | 'wy' | null) | undefined, session?: (string | null) | undefined, series?: (Array<'general' | 'public' | 'public_act' | 'special_act' | 'private_and_special' | 'act' | 'acts' | 'law' | 'local' | 'municipal' | 'appropriation' | 'resolve' | 'resolves' | 'resolution' | 'resolution_chapter' | 'joint_resolution' | 'concurrent_resolution' | 'memorial' | 'initiated_bill' | 'constitutional_amendment' | 'private' | 'constitutional_resolution' | 'competing_measure_resolution' | 'resolution_act'> | null) | undefined, instrumentType?: (Array<'act' | 'joint_resolution' | 'concurrent_resolution' | 'resolution' | 'resolve' | 'memorial' | 'other'> | null) | undefined, approvedFrom?: (string | null) | undefined, approvedTo?: (string | null) | undefined, limit?: number | undefined, offset?: number | undefined, includeUnverified?: boolean | undefined}; export type CreateApiApiV1UsSessionLawsSearchArgs = {'Idempotency-Key'?: (string | null) | undefined, body: SessionLawSearchRequest}; export type CreateApiApiV1UsSessionLawsSearchOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const sessionLawSearchParsed = z.object({text: z.string(), phrases: z.array(z.string()).optional(), citationTokens: z.array(z.string()).optional(), billNumbers: z.array(z.string()).optional()}); export const sessionLawSearchPassage = z.object({seq: z.number().int(), ownStart: z.number().int(), ownEnd: z.number().int(), pageStart: z.number().int().nullable().optional(), heading: z.string().nullable().optional(), snippet: z.string(), highlights: z.array(z.array(z.number().int())).optional(), bodyHref: z.string()}); export const sessionLawSearchResult = z.object({sessionLawId: z.string(), jurisdiction: z.string(), session: z.string(), series: z.string(), instrumentType: z.string(), citation: z.string(), title: z.string().nullable().optional(), approvedDate: z.string().nullable().optional(), enactmentOutcome: z.string(), billNumbers: z.array(z.string()).optional(), amendedSections: z.array(z.string()).optional(), matchType: z.enum(["exact", "text"]), matchedBy: z.array(z.enum(["title", "text", "phrase", "citation", "codeSection", "billNumber"])), passage: sessionLawSearchPassage.nullable().optional(), holdingState: z.literal("quarantined").nullable().optional(), textReliability: z.enum(["unverified", "known_issue"]).nullable().optional(), reasonCode: z.string().nullable().optional(), href: z.string()}); export const sessionLawSearchResponse = z.object({query: z.string(), parsed: sessionLawSearchParsed, results: z.array(sessionLawSearchResult).optional(), count: z.number().int().optional(), offset: z.number().int().optional(), limit: z.number().int().optional(), hasMore: z.boolean().optional(), creditsConsumed: z.number().int().optional(), processingTimeMs: z.number().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 }; /** * Search the text of state session laws * * POST /api/v1/us/session-laws/search * * Also accepts auth: ApiKeyHeader */ export const createApiApiV1UsSessionLawsSearch = async (args: CreateApiApiV1UsSessionLawsSearchArgs, options?: CreateApiApiV1UsSessionLawsSearchOptions) => { const {baseUrl = "https://api.vaquill.ai", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args['Idempotency-Key'] != null) headers.set("Idempotency-Key", String(args['Idempotency-Key'])) if (ApiKeyAuth !== undefined) headers.set('authorization', `Bearer ${ApiKeyAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/us/session-laws/search${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(sessionLawSearchResponse, await res.json()) };