okrapdf 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser.d.ts +9 -0
- package/dist/browser.js +16 -0
- package/dist/browser.js.map +1 -0
- package/dist/chunk-AG3A2T3B.js +84 -0
- package/dist/chunk-AG3A2T3B.js.map +1 -0
- package/dist/chunk-C6ZT7DKX.js +113 -0
- package/dist/chunk-C6ZT7DKX.js.map +1 -0
- package/dist/chunk-HITG34US.js +626 -0
- package/dist/chunk-HITG34US.js.map +1 -0
- package/dist/chunk-SBT5T6ZK.js +817 -0
- package/dist/chunk-SBT5T6ZK.js.map +1 -0
- package/dist/cli/bin.d.ts +1 -0
- package/dist/cli/bin.js +212 -0
- package/dist/cli/bin.js.map +1 -0
- package/dist/cli/index.d.ts +536 -0
- package/dist/cli/index.js +73 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/client-aHzx0a5x.d.ts +58 -0
- package/dist/index.d.ts +57 -0
- package/dist/index.js +26 -0
- package/dist/index.js.map +1 -0
- package/dist/react/index.d.ts +197 -0
- package/dist/react/index.js +432 -0
- package/dist/react/index.js.map +1 -0
- package/dist/types-DEYgGUnH.d.ts +329 -0
- package/dist/url.d.ts +48 -0
- package/dist/url.js +7 -0
- package/dist/url.js.map +1 -0
- package/dist/worker.d.ts +44 -0
- package/dist/worker.js +82 -0
- package/dist/worker.js.map +1 -0
- package/package.json +82 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { O as OkraClient } from './client-aHzx0a5x.js';
|
|
2
|
+
import { l as OkraClientOptions, R as RuntimeErrorCode, u as StructuredOutputErrorCode } from './types-DEYgGUnH.js';
|
|
3
|
+
export { o as CompletionEvent, C as CompletionOptions, c as DeploymentCreateOptions, d as DeploymentResult, D as DocUrlOptions, n as DocumentStatus, E as EntitiesResponse, v as Entity, G as GenerateOptions, p as GenerateResult, J as JsonSchema, O as OkraSession, P as Page, w as PageBlock, x as PageEntity, r as PublishResult, Q as QueryResult, b as SessionAttachOptions, S as SessionCreateOptions, y as SessionState, z as ShareLinkCapabilities, A as ShareLinkLinks, s as ShareLinkOptions, t as ShareLinkResult, B as StructuredOutputMeta, q as StructuredSchema, a as UploadInput, m as UploadOptions, F as UploadRedactOptions, H as UploadRedactPiiOptions, U as UrlBuilderOptions, W as WaitOptions } from './types-DEYgGUnH.js';
|
|
4
|
+
export { doc } from './url.js';
|
|
5
|
+
import 'zod';
|
|
6
|
+
|
|
7
|
+
type ExtractionPhase = 'ocr' | 'enhance' | 'metadata' | 'verify';
|
|
8
|
+
interface OkraProvider {
|
|
9
|
+
name: string;
|
|
10
|
+
supportedPhases: ExtractionPhase[];
|
|
11
|
+
}
|
|
12
|
+
interface OkraMiddleware {
|
|
13
|
+
name: string;
|
|
14
|
+
config: Record<string, unknown>;
|
|
15
|
+
}
|
|
16
|
+
interface CreateOkraOptions extends OkraClientOptions {
|
|
17
|
+
providers?: Record<string, OkraProvider>;
|
|
18
|
+
extraction?: Partial<Record<ExtractionPhase, string>>;
|
|
19
|
+
middleware?: OkraMiddleware[];
|
|
20
|
+
vendorKeys?: Record<string, string>;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Factory function — AI SDK-style provider abstraction.
|
|
24
|
+
*
|
|
25
|
+
* ```ts
|
|
26
|
+
* import { createOkra } from 'okrapdf';
|
|
27
|
+
*
|
|
28
|
+
* const okra = createOkra({
|
|
29
|
+
* apiKey: 'okra_...',
|
|
30
|
+
* providers: { azureDocAI },
|
|
31
|
+
* extraction: { ocr: 'azureDocAI' },
|
|
32
|
+
* });
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
declare function createOkra(options: CreateOkraOptions): OkraClient;
|
|
36
|
+
declare function withCache(opts: {
|
|
37
|
+
by: 'pdf-hash' | 'content-hash';
|
|
38
|
+
}): OkraMiddleware;
|
|
39
|
+
declare function withQualityScore(opts: {
|
|
40
|
+
threshold: number;
|
|
41
|
+
}): OkraMiddleware;
|
|
42
|
+
declare function withSecret(namespace: string, opts?: {
|
|
43
|
+
required?: boolean;
|
|
44
|
+
}): OkraMiddleware;
|
|
45
|
+
|
|
46
|
+
declare class OkraRuntimeError extends Error {
|
|
47
|
+
readonly code: RuntimeErrorCode;
|
|
48
|
+
readonly status: number;
|
|
49
|
+
readonly details?: unknown;
|
|
50
|
+
constructor(code: RuntimeErrorCode, message: string, status?: number, details?: unknown);
|
|
51
|
+
}
|
|
52
|
+
declare class StructuredOutputError extends OkraRuntimeError {
|
|
53
|
+
readonly code: StructuredOutputErrorCode;
|
|
54
|
+
constructor(code: StructuredOutputErrorCode, message: string, status: number, details?: unknown);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export { type CreateOkraOptions, type ExtractionPhase, OkraClient, OkraClientOptions, type OkraMiddleware, type OkraProvider, OkraClient as OkraRuntime, OkraRuntimeError, RuntimeErrorCode, StructuredOutputError, StructuredOutputErrorCode, createOkra, withCache, withQualityScore, withSecret };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import {
|
|
2
|
+
doc
|
|
3
|
+
} from "./chunk-C6ZT7DKX.js";
|
|
4
|
+
import {
|
|
5
|
+
createOkra,
|
|
6
|
+
withCache,
|
|
7
|
+
withQualityScore,
|
|
8
|
+
withSecret
|
|
9
|
+
} from "./chunk-AG3A2T3B.js";
|
|
10
|
+
import {
|
|
11
|
+
OkraClient,
|
|
12
|
+
OkraRuntimeError,
|
|
13
|
+
StructuredOutputError
|
|
14
|
+
} from "./chunk-HITG34US.js";
|
|
15
|
+
export {
|
|
16
|
+
OkraClient,
|
|
17
|
+
OkraClient as OkraRuntime,
|
|
18
|
+
OkraRuntimeError,
|
|
19
|
+
StructuredOutputError,
|
|
20
|
+
createOkra,
|
|
21
|
+
doc,
|
|
22
|
+
withCache,
|
|
23
|
+
withQualityScore,
|
|
24
|
+
withSecret
|
|
25
|
+
};
|
|
26
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { O as OkraClient } from '../client-aHzx0a5x.js';
|
|
3
|
+
import { O as OkraSession, n as DocumentStatus, P as Page, q as StructuredSchema, p as GenerateResult } from '../types-DEYgGUnH.js';
|
|
4
|
+
export { o as CompletionEvent } from '../types-DEYgGUnH.js';
|
|
5
|
+
import 'zod';
|
|
6
|
+
|
|
7
|
+
interface OkraContextValue {
|
|
8
|
+
client: OkraClient;
|
|
9
|
+
apiKey: string;
|
|
10
|
+
}
|
|
11
|
+
interface OkraProviderProps {
|
|
12
|
+
apiKey: string;
|
|
13
|
+
baseUrl?: string;
|
|
14
|
+
children: React.ReactNode;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Provides the OkraPDF runtime client to all child hooks.
|
|
18
|
+
*
|
|
19
|
+
* ```tsx
|
|
20
|
+
* <OkraProvider apiKey={process.env.OKRA_API_KEY!}>
|
|
21
|
+
* <App />
|
|
22
|
+
* </OkraProvider>
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
declare function OkraProvider({ apiKey, baseUrl, children }: OkraProviderProps): react.FunctionComponentElement<react.ProviderProps<OkraContextValue | null>>;
|
|
26
|
+
/**
|
|
27
|
+
* Access the OkraPDF runtime client from context.
|
|
28
|
+
*
|
|
29
|
+
* ```ts
|
|
30
|
+
* const { client } = useOkra();
|
|
31
|
+
* const session = await client.sessions.create(file);
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
declare function useOkra(): OkraContextValue;
|
|
35
|
+
|
|
36
|
+
interface Message {
|
|
37
|
+
id: string;
|
|
38
|
+
role: 'user' | 'assistant';
|
|
39
|
+
content: string;
|
|
40
|
+
createdAt?: Date;
|
|
41
|
+
sources?: Array<{
|
|
42
|
+
page: number;
|
|
43
|
+
snippet: string;
|
|
44
|
+
}>;
|
|
45
|
+
}
|
|
46
|
+
type SessionStatus = 'idle' | 'uploading' | 'processing' | 'ready' | 'error';
|
|
47
|
+
interface UseDocumentSessionReturn {
|
|
48
|
+
session: OkraSession | null;
|
|
49
|
+
status: SessionStatus;
|
|
50
|
+
error: Error | null;
|
|
51
|
+
upload: (source: string | File | Blob) => Promise<void>;
|
|
52
|
+
documentStatus: DocumentStatus | null;
|
|
53
|
+
}
|
|
54
|
+
interface UseChatReturn {
|
|
55
|
+
messages: Message[];
|
|
56
|
+
input: string;
|
|
57
|
+
handleInputChange: (e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => void;
|
|
58
|
+
handleSubmit: (e?: {
|
|
59
|
+
preventDefault?: () => void;
|
|
60
|
+
}) => void;
|
|
61
|
+
isLoading: boolean;
|
|
62
|
+
stop: () => void;
|
|
63
|
+
append: (message: Pick<Message, 'role' | 'content'>) => void;
|
|
64
|
+
setMessages: React.Dispatch<React.SetStateAction<Message[]>>;
|
|
65
|
+
}
|
|
66
|
+
interface ChatConfig {
|
|
67
|
+
session: OkraSession | null;
|
|
68
|
+
/** Use streaming (default: true) */
|
|
69
|
+
stream?: boolean;
|
|
70
|
+
onFinish?: (message: Message) => void;
|
|
71
|
+
onError?: (error: Error) => void;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
interface UseDocumentSessionOptions {
|
|
75
|
+
/** If true (default), waits for extraction to complete before session is ready */
|
|
76
|
+
wait?: boolean;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Upload a document and get an interactive session.
|
|
80
|
+
*
|
|
81
|
+
* ```tsx
|
|
82
|
+
* const { session, status, upload } = useDocumentSession();
|
|
83
|
+
* await upload(file); // or upload('https://...')
|
|
84
|
+
* // session is ready when status === 'ready'
|
|
85
|
+
* ```
|
|
86
|
+
*/
|
|
87
|
+
declare function useDocumentSession(options?: UseDocumentSessionOptions): UseDocumentSessionReturn;
|
|
88
|
+
|
|
89
|
+
interface UseDocumentStatusOptions {
|
|
90
|
+
/** Poll interval in ms while processing (default: 2000). 0 to disable. */
|
|
91
|
+
pollInterval?: number;
|
|
92
|
+
/** Skip fetching entirely */
|
|
93
|
+
enabled?: boolean;
|
|
94
|
+
}
|
|
95
|
+
interface UseDocumentStatusReturn {
|
|
96
|
+
data: DocumentStatus | null;
|
|
97
|
+
isLoading: boolean;
|
|
98
|
+
error: Error | null;
|
|
99
|
+
isComplete: boolean;
|
|
100
|
+
isProcessing: boolean;
|
|
101
|
+
refetch: () => void;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Poll document processing status from the CF Worker.
|
|
105
|
+
* Accepts either a session object or a raw document ID.
|
|
106
|
+
*
|
|
107
|
+
* ```tsx
|
|
108
|
+
* const { data, isComplete, isProcessing } = useDocumentStatus(session);
|
|
109
|
+
* // or
|
|
110
|
+
* const { data } = useDocumentStatus('doc-abc123');
|
|
111
|
+
* ```
|
|
112
|
+
*/
|
|
113
|
+
declare function useDocumentStatus(sessionOrId: OkraSession | string | null, options?: UseDocumentStatusOptions): UseDocumentStatusReturn;
|
|
114
|
+
|
|
115
|
+
interface UsePagesOptions {
|
|
116
|
+
/** Skip fetching (default: true) */
|
|
117
|
+
enabled?: boolean;
|
|
118
|
+
}
|
|
119
|
+
interface UsePagesReturn {
|
|
120
|
+
data: Page[];
|
|
121
|
+
isLoading: boolean;
|
|
122
|
+
error: Error | null;
|
|
123
|
+
refetch: () => void;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Fetch all pages for a document.
|
|
127
|
+
*
|
|
128
|
+
* ```tsx
|
|
129
|
+
* const { data: pages, isLoading } = usePages(session);
|
|
130
|
+
* // or with a document ID
|
|
131
|
+
* const { data: pages } = usePages('doc-abc123');
|
|
132
|
+
* ```
|
|
133
|
+
*/
|
|
134
|
+
declare function usePages(sessionOrId: OkraSession | string | null, options?: UsePagesOptions): UsePagesReturn;
|
|
135
|
+
|
|
136
|
+
interface UsePageContentOptions {
|
|
137
|
+
/** Poll interval while content not yet ready (default: 3000). 0 to disable. */
|
|
138
|
+
pollInterval?: number;
|
|
139
|
+
}
|
|
140
|
+
interface UsePageContentReturn {
|
|
141
|
+
data: Page | null;
|
|
142
|
+
content: string;
|
|
143
|
+
isLoading: boolean;
|
|
144
|
+
error: Error | null;
|
|
145
|
+
refetch: () => void;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Fetch a single page's content (markdown + blocks + entities).
|
|
149
|
+
* Polls until content arrives if the page is still processing.
|
|
150
|
+
*
|
|
151
|
+
* ```tsx
|
|
152
|
+
* const { content, data, isLoading } = usePageContent(session, 1);
|
|
153
|
+
* ```
|
|
154
|
+
*/
|
|
155
|
+
declare function usePageContent(sessionOrId: OkraSession | string | null, pageNumber: number, options?: UsePageContentOptions): UsePageContentReturn;
|
|
156
|
+
|
|
157
|
+
declare function useChat(config: ChatConfig): UseChatReturn;
|
|
158
|
+
|
|
159
|
+
interface UseDocumentQueryOptions<T = undefined> {
|
|
160
|
+
/** Document ID (e.g. "doc-xxx" or "ocr-xxx") */
|
|
161
|
+
documentId: string | null;
|
|
162
|
+
/** The query/prompt to run against the document */
|
|
163
|
+
query: string;
|
|
164
|
+
/** JSON schema or Zod schema for structured output */
|
|
165
|
+
schema?: StructuredSchema<T>;
|
|
166
|
+
/** Skip the query (e.g. while waiting for doc to be ready) */
|
|
167
|
+
skip?: boolean;
|
|
168
|
+
/** Model override */
|
|
169
|
+
model?: string;
|
|
170
|
+
/** Timeout in ms */
|
|
171
|
+
timeoutMs?: number;
|
|
172
|
+
/** How long cached results stay valid in ms (default: 300000 / 5 min) */
|
|
173
|
+
cacheTime?: number;
|
|
174
|
+
}
|
|
175
|
+
interface UseDocumentQueryReturn<T = undefined> {
|
|
176
|
+
data: T | null;
|
|
177
|
+
result: GenerateResult<T> | null;
|
|
178
|
+
isLoading: boolean;
|
|
179
|
+
error: Error | null;
|
|
180
|
+
refetch: () => void;
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Run a one-shot query against a document, optionally with structured output.
|
|
184
|
+
* Results are cached in-memory for `cacheTime` ms (default 5 min).
|
|
185
|
+
*
|
|
186
|
+
* ```tsx
|
|
187
|
+
* const { data } = useDocumentQuery({
|
|
188
|
+
* documentId: "doc-xxx",
|
|
189
|
+
* query: "Generate 4 chat suggestions",
|
|
190
|
+
* schema: z.object({ suggestions: z.array(z.object({ id: z.string(), text: z.string() })) }),
|
|
191
|
+
* skip: !isReady,
|
|
192
|
+
* })
|
|
193
|
+
* ```
|
|
194
|
+
*/
|
|
195
|
+
declare function useDocumentQuery<T = undefined>(options: UseDocumentQueryOptions<T>): UseDocumentQueryReturn<T>;
|
|
196
|
+
|
|
197
|
+
export { type ChatConfig, DocumentStatus, GenerateResult, type Message, type OkraContextValue, OkraProvider, type OkraProviderProps, OkraSession, Page, type SessionStatus, type UseChatReturn, type UseDocumentQueryOptions, type UseDocumentQueryReturn, type UseDocumentSessionOptions, type UseDocumentSessionReturn, type UseDocumentStatusOptions, type UseDocumentStatusReturn, type UsePageContentOptions, type UsePageContentReturn, type UsePagesOptions, type UsePagesReturn, useChat, useDocumentQuery, useDocumentSession, useDocumentStatus, useOkra, usePageContent, usePages };
|