import type { ZodType } from 'zod'; export type JsonSchema = Record; export type StructuredOutputErrorCode = 'SCHEMA_VALIDATION_FAILED' | 'EXTRACTION_FAILED' | 'TIMEOUT' | 'DOCUMENT_NOT_FOUND'; export type RuntimeErrorCode = StructuredOutputErrorCode | 'INVALID_REQUEST' | 'UNAUTHORIZED' | 'HTTP_ERROR' | 'INVALID_RESPONSE'; export interface CreateOkraOptions { /** Hosted default points at api.okrapdf.com. */ baseUrl?: string; /** Bearer API key (okra_...). */ apiKey?: string; /** Alternative auth header for private deployments. */ sharedSecret?: string; /** Inject custom fetch implementation for tests or runtime overrides. */ fetch?: typeof globalThis.fetch; } /** @internal Internal client constructor options. */ export interface OkraOptions extends CreateOkraOptions { } export interface UploadRedactPiiOptions { preset?: string; patterns?: string[]; includeNames?: boolean; includeAddresses?: boolean; customPatterns?: Array>; [key: string]: unknown; } export interface UploadRedactOptions { pii?: UploadRedactPiiOptions; publicFieldAllowlist?: string[]; [key: string]: unknown; } export interface UploadOptions { /** Provide your own document ID. Default: auto-generated `doc-*`. */ documentId?: string; /** Optional filename hint for binary uploads. */ fileName?: string; /** Processing capability hints forwarded to the worker. */ capabilities?: Record; /** Document visibility. 'private' (default) requires auth; 'public' auto-publishes on completion. */ visibility?: 'public' | 'private'; /** BYOK vendor keys passed through to extraction (e.g. { llamaparse: 'llx-...' }). Stateless — never stored. */ vendorKeys?: Record; /** OpenRedact policy forwarded to upload and enforced at read/query/completion surfaces. */ redact?: UploadRedactOptions; } export type UploadInput = string | ArrayBuffer | Uint8Array | Blob; export type JobStatus = 'queued' | 'processing' | 'complete' | 'error'; export interface JobUrls { self: string; status: string; cancel: string; pages: string; publish: string; } export interface OkraJob { readonly id: string; readonly url: string; readonly status: JobStatus; readonly visibility: 'public' | 'private'; readonly workflowId?: string; readonly urls: JobUrls; wait(options?: WaitOptions): Promise; reload(): Promise; pages(options?: { range?: string; signal?: AbortSignal; }): Promise; page(n: number, signal?: AbortSignal): Promise; entities(options?: { type?: string; limit?: number; offset?: number; signal?: AbortSignal; }): Promise; downloadUrl(): string; query(sql: string, signal?: AbortSignal): Promise; publish(signal?: AbortSignal): Promise; shareLink(options?: ShareLinkOptions): Promise; generate(query: string, options?: GenerateOptions & { schema?: undefined; }): Promise; generate(query: string, options: GenerateOptions & { schema: StructuredSchema; }): Promise>; stream(query: string, options?: CompletionOptions): AsyncGenerator; toSession(options?: SessionAttachOptions): Promise; } export interface DocumentStatus { phase: string; pagesTotal?: number; pagesCompleted?: number; totalNodes?: number; verifiedNodes?: number; failedNodes?: number; pendingNodes?: number; [key: string]: unknown; } export interface WaitOptions { timeoutMs?: number; pollIntervalMs?: number; signal?: AbortSignal; } export interface StructuredOutputMeta { confidence: number; model: string; durationMs: number; citations?: Array<{ page: number; text: string; }>; } export type StructuredSchema = JsonSchema | ZodType; export interface PageBlock { text: string; bbox?: { x: number; y: number; width: number; height: number; }; confidence?: number; } export interface PageEntity { id: string; type: string; label: string | null; } export interface Page { page: number; content: string; blocks: PageBlock[]; entities: PageEntity[]; } export interface Entity { id: string; type: string; label: string | null; value: string | null; page_number: number | null; status: string; bbox_x?: number | null; bbox_y?: number | null; bbox_w?: number | null; bbox_h?: number | null; metadata?: string | null; } export interface EntitiesResponse { nodes: Entity[]; total?: number; limit?: number; offset?: number; } export interface QueryResult { rows: Record[]; columns: string[]; } export type CompletionEvent = { type: 'text_delta'; text: string; } | { type: 'tool_result'; name: string; result: unknown; } | { type: 'done'; answer: string; costUsd?: number; sources?: Array<{ page: number; snippet: string; }>; } | { type: 'error'; message: string; }; export interface CompletionOptions { stream?: boolean; model?: string; signal?: AbortSignal; } export interface GenerateOptions { schema?: StructuredSchema; model?: string; timeoutMs?: number; signal?: AbortSignal; } export interface GenerateResult { answer: string; sources?: Array<{ page: number; snippet: string; }>; costUsd?: number; /** Present when schema is provided. */ data?: T; /** Present when schema is provided. */ meta?: StructuredOutputMeta; } /** Server-side session configuration passed to POST /v1/sessions. */ export interface SessionConfig { /** Data source mode. 'live' reads from DO; 'snapshot' reads from R2 export. Default: 'live'. */ dataSource?: 'live' | 'snapshot'; /** Pin to a specific export version when using snapshot mode. */ snapshotVersion?: string; /** Whether chat history is persisted across connections. Default: 'ephemeral'. */ chatPersistence?: 'persisted' | 'ephemeral'; /** Guest access level. Default: 'none'. */ guestAccess?: 'none' | 'read' | 'ask'; /** Isolate chat threads per user. Default: true. */ isolateChats?: boolean; /** Restrict which tools the session agent can invoke. */ enabledTools?: string[]; /** Custom system prompt injected into the session agent. */ systemPrompt?: string; /** Redaction role applied to content surfaces. */ redactionRole?: 'viewer' | 'admin' | 'public'; /** Owner user ID. Inferred from auth header if omitted. */ ownerUserId?: string; } export interface SessionCreateOptions { /** Wait for extraction to complete before returning the session handle. Default: true */ wait?: boolean; /** Default model used by prompt()/stream() unless overridden per call. */ model?: string; /** Upload options used when source is URL/path/file (not an existing doc ID). */ upload?: UploadOptions; /** Wait options used when `wait` is enabled. */ waitOptions?: WaitOptions; /** Server-side session configuration. */ session?: SessionConfig; } export interface SessionAttachOptions { /** Default model used by prompt()/stream() unless overridden per call. */ model?: string; /** Server-side session configuration. */ session?: SessionConfig; } export interface SessionState { /** Document ID this session is bound to. */ id: string; /** Server-side session ID (sess-...). */ sessionId: string; /** Absolute or relative URL for completions. */ completionUrl: string; model?: string; modelEndpoint: string; } export interface SessionPromptOptions extends GenerateOptions { } export interface SessionStreamOptions extends CompletionOptions { } export interface OkraSession { readonly id: string; readonly modelEndpoint: string; readonly model?: string; state(): SessionState; setModel(model: string): Promise; status(signal?: AbortSignal): Promise; wait(options?: WaitOptions): Promise; pages(options?: { range?: string; signal?: AbortSignal; }): Promise; page(pageNumber: number, signal?: AbortSignal): Promise; entities(options?: { type?: string; limit?: number; offset?: number; signal?: AbortSignal; }): Promise; downloadUrl(): string; query(sql: string, signal?: AbortSignal): Promise; publish(signal?: AbortSignal): Promise; shareLink(options?: ShareLinkOptions): Promise; prompt(query: string, options?: SessionPromptOptions & { schema?: undefined; }): Promise; prompt(query: string, options: SessionPromptOptions & { schema: StructuredSchema; }): Promise>; stream(query: string, options?: SessionStreamOptions): AsyncGenerator; } export interface OkraRuntime { readonly sessions: { create(source: UploadInput | { documentId: string; } | { collectionId: string; }, options?: SessionCreateOptions): Promise; from(documentId: string, options?: SessionAttachOptions): Promise; }; } export interface PublishResult { published: boolean; documentId: string; version: string; publicUrl: string; /** Immutable public URL: https://api.okrapdf.com/v1/documents/{id} */ url: string; hash: string; slug: string; canonicalPath: string; } export interface ShareLinkOptions { /** Link role: 'viewer' (redacted/PDF access), 'admin' (full access), or 'ask' (public completion). */ role?: 'viewer' | 'ask' | 'admin'; label?: string; expiresInMs?: number; maxViews?: number; signal?: AbortSignal; } export interface ShareLinkLinks { markdown: string | null; pdf: string | null; completion: string | null; } export interface ShareLinkCapabilities { canViewPdf: boolean; } export interface ShareLinkResult { documentId: string; token: string; tokenHint: string; /** Stable link surfaces by capability. */ links: ShareLinkLinks; /** Explicit capability flags for UI/behavior gating. */ capabilities: ShareLinkCapabilities; /** @deprecated Use `links.markdown` and `links.completion`. */ url: string; /** @deprecated Backward-compatible alias for `url`. */ shareUrl: string; /** @deprecated Use `links.markdown`. */ markdownUrl: string | null; /** @deprecated Use `links.pdf`. */ pdfUrl: string | null; /** @deprecated Use `links.completion`. */ completionUrl: string | null; role: string; expiresAt: number; maxViews: number | null; } export interface DeployOptions { /** Human-readable name for the deployed agent. Used as slug prefix. */ name?: string; /** Document metadata for the orchestrator. If omitted, IDs are used as filenames. */ documents?: Array<{ jobId: string; fileName: string; }>; signal?: AbortSignal; } export interface DeployResult { slug: string; /** Full completion URL: https://api.okrapdf.com/v1/agents/{slug}/completion */ url: string; /** Bearer token — only present on first deploy. Null on idempotent redeploy. */ token?: string; tokenHint: string; documentIds: string[]; name: string | null; /** Content hash of sorted doc IDs (6 hex chars). */ version: string; createdAt: number; /** True if this exact doc set was already deployed (idempotent). */ existing?: boolean; } export interface DeploymentCreateOptions { /** Guest access level. 'ask' allows unauthenticated completion calls. */ guestAccess?: 'ask' | 'none'; /** Chat persistence mode. 'ephemeral' means no conversation state is stored. */ chatPersistence?: 'ephemeral' | 'persistent'; /** Upload options forwarded when source is a file/URL (not a documentId). */ upload?: UploadOptions; /** Wait for extraction before creating deployment. Default: true. */ wait?: boolean; signal?: AbortSignal; } export interface DeploymentCreateResult { deploymentId: string; /** Relative completion URL path, e.g. `/{id}/completion`. */ completionUrl: string; /** Fully qualified completion URL. */ completionEndpoint: string; /** The document ID backing this deployment. */ documentId: string; } export interface DeploymentListItem { id: string; user_id: string; document_id: string | null; collection_id: string | null; guest_access: string; chat_persistence: string; data_source: string; created_at: number; } export interface UrlBuilderOptions { format?: 'json' | 'csv' | 'html' | 'markdown' | 'png'; include?: string[]; /** Provider transformation — changes extraction source, e.g. 'llamaparse', 'googleocr'. */ provider?: string; } export interface DocUrlOptions { /** * Original source filename used to build friendly artifact URLs, e.g. * /.../invoice.json */ fileName?: string; /** * Default provider transformation applied to all URLs from this builder. * Cloudinary-style: `/t_llamaparse/pages/1.md` vs `/t_googleocr/pages/1.json` */ provider?: string; /** * Default image placeholder type when page image is not yet available. * Inserts `/d_{type}/` segment. e.g. 'shimmer' → `/d_shimmer/pages/1/image.png` */ defaultImage?: string; } //# sourceMappingURL=types.d.ts.map