okrapdf 0.9.0 → 0.10.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/LICENSE +21 -0
- package/dist/browser.d.ts +1 -1
- package/dist/browser.js +1 -1
- package/dist/{chunk-DQ3ZXFXO.js → chunk-4IHOG655.js} +13 -10
- package/dist/{chunk-DQ3ZXFXO.js.map → chunk-4IHOG655.js.map} +1 -1
- package/dist/{chunk-4RJBVZJL.js → chunk-EZLAOKOP.js} +20 -1
- package/dist/chunk-EZLAOKOP.js.map +1 -0
- package/dist/chunk-QKII53VN.js +195 -0
- package/dist/chunk-QKII53VN.js.map +1 -0
- package/dist/{chunk-FS55NWKZ.js → chunk-Y72DLYYO.js} +2 -2
- package/dist/cli/bin.js +38 -3
- package/dist/cli/bin.js.map +1 -1
- package/dist/cli/index.d.ts +2 -2
- package/dist/cli/index.js +1 -1
- package/dist/{client-BWcRvduT.d.ts → client-CyA8BgrE.d.ts} +7 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +3 -3
- package/dist/react/index.d.ts +3 -3
- package/dist/react/index.js +2 -2
- package/dist/{types-C7IWrjwl.d.ts → types-DpLY63Cg.d.ts} +59 -1
- package/dist/url.d.ts +19 -6
- package/dist/url.js +1 -1
- package/package.json +2 -2
- package/dist/chunk-4RJBVZJL.js.map +0 -1
- package/dist/chunk-5NINKIAC.js +0 -139
- package/dist/chunk-5NINKIAC.js.map +0 -1
- /package/dist/{chunk-FS55NWKZ.js.map → chunk-Y72DLYYO.js.map} +0 -0
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
// src/url.ts
|
|
2
|
+
var DEFAULT_BASE_URL = "https://api.okrapdf.com";
|
|
3
|
+
var DELIVERY_KEY_ORDER = [
|
|
4
|
+
"w",
|
|
5
|
+
"h",
|
|
6
|
+
"dpr",
|
|
7
|
+
"q",
|
|
8
|
+
"f",
|
|
9
|
+
"md",
|
|
10
|
+
"c",
|
|
11
|
+
"g",
|
|
12
|
+
"zm",
|
|
13
|
+
"bl",
|
|
14
|
+
"sh",
|
|
15
|
+
"br",
|
|
16
|
+
"co",
|
|
17
|
+
"sa",
|
|
18
|
+
"r",
|
|
19
|
+
"fl",
|
|
20
|
+
"bg",
|
|
21
|
+
"anim",
|
|
22
|
+
"seg"
|
|
23
|
+
];
|
|
24
|
+
var VALID_FORMATS = /* @__PURE__ */ new Set(["auto", "webp", "avif", "jpeg", "png"]);
|
|
25
|
+
var VALID_CROPS = /* @__PURE__ */ new Set(["scale-down", "contain", "cover", "crop", "pad", "squeeze"]);
|
|
26
|
+
var VALID_GRAVITIES = /* @__PURE__ */ new Set(["auto", "face", "left", "right", "top", "bottom", "center"]);
|
|
27
|
+
var VALID_FLIPS = /* @__PURE__ */ new Set(["h", "v", "hv"]);
|
|
28
|
+
var VALID_ROTATIONS = /* @__PURE__ */ new Set([0, 90, 180, 270]);
|
|
29
|
+
function validateTransform(t) {
|
|
30
|
+
if (t.w !== void 0 && (!Number.isInteger(t.w) || t.w <= 0)) throw new Error("Invalid delivery transform: w must be a positive integer");
|
|
31
|
+
if (t.h !== void 0 && (!Number.isInteger(t.h) || t.h <= 0)) throw new Error("Invalid delivery transform: h must be a positive integer");
|
|
32
|
+
if (t.dpr !== void 0 && t.dpr <= 0) throw new Error("Invalid delivery transform: dpr must be positive");
|
|
33
|
+
if (t.q !== void 0 && (!Number.isInteger(t.q) || t.q < 1 || t.q > 100)) throw new Error("Invalid delivery transform: q must be 1-100");
|
|
34
|
+
if (t.f !== void 0 && !VALID_FORMATS.has(t.f)) throw new Error(`Invalid delivery transform: f must be one of ${[...VALID_FORMATS].join(", ")}`);
|
|
35
|
+
if (t.c !== void 0 && !VALID_CROPS.has(t.c)) throw new Error(`Invalid delivery transform: c must be one of ${[...VALID_CROPS].join(", ")}`);
|
|
36
|
+
if (t.g !== void 0 && !VALID_GRAVITIES.has(t.g)) throw new Error(`Invalid delivery transform: g must be one of ${[...VALID_GRAVITIES].join(", ")}`);
|
|
37
|
+
if (t.zm !== void 0 && (t.zm < 0 || t.zm > 1)) throw new Error("Invalid delivery transform: zm must be 0-1");
|
|
38
|
+
if (t.bl !== void 0 && (!Number.isInteger(t.bl) || t.bl < 1 || t.bl > 250)) throw new Error("Invalid delivery transform: bl must be 1-250");
|
|
39
|
+
if (t.sh !== void 0 && (t.sh < 0 || t.sh > 10)) throw new Error("Invalid delivery transform: sh must be 0-10");
|
|
40
|
+
if (t.r !== void 0 && !VALID_ROTATIONS.has(t.r)) throw new Error("Invalid delivery transform: r must be 0, 90, 180, or 270");
|
|
41
|
+
if (t.fl !== void 0 && !VALID_FLIPS.has(t.fl)) throw new Error(`Invalid delivery transform: fl must be one of ${[...VALID_FLIPS].join(", ")}`);
|
|
42
|
+
}
|
|
43
|
+
function serializeTransform(t) {
|
|
44
|
+
const tokens = [];
|
|
45
|
+
const rec = t;
|
|
46
|
+
for (const k of DELIVERY_KEY_ORDER) {
|
|
47
|
+
if (rec[k] !== void 0) tokens.push(`${k}_${rec[k]}`);
|
|
48
|
+
}
|
|
49
|
+
return tokens.join(",");
|
|
50
|
+
}
|
|
51
|
+
function buildModifierSegments(mods) {
|
|
52
|
+
const parts = [];
|
|
53
|
+
if (mods.variant) parts.push(`t_${mods.variant}`);
|
|
54
|
+
if (mods.default) parts.push(`d_${mods.default}`);
|
|
55
|
+
if (mods.output) parts.push(`o_${mods.output}`);
|
|
56
|
+
if (mods.transform) {
|
|
57
|
+
const seg = serializeTransform(mods.transform);
|
|
58
|
+
if (seg) parts.push(seg);
|
|
59
|
+
}
|
|
60
|
+
return parts;
|
|
61
|
+
}
|
|
62
|
+
var FORMAT_TO_EXT = {
|
|
63
|
+
json: "json",
|
|
64
|
+
csv: "csv",
|
|
65
|
+
html: "html",
|
|
66
|
+
markdown: "md",
|
|
67
|
+
png: "png"
|
|
68
|
+
};
|
|
69
|
+
function slugifyFileStem(fileName) {
|
|
70
|
+
const leaf = fileName.split("/").pop() || fileName;
|
|
71
|
+
const noExt = leaf.replace(/\.[A-Za-z0-9]{1,8}$/, "");
|
|
72
|
+
const slug = noExt.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 48);
|
|
73
|
+
return slug || "document";
|
|
74
|
+
}
|
|
75
|
+
function extensionFor(format, fallback) {
|
|
76
|
+
if (!format) return fallback;
|
|
77
|
+
const lower = format.toLowerCase();
|
|
78
|
+
if (lower === "markdown") return "md";
|
|
79
|
+
return FORMAT_TO_EXT[lower] || lower;
|
|
80
|
+
}
|
|
81
|
+
function doc(documentId, baseUrlOrOptions = DEFAULT_BASE_URL, maybeOptions = {}) {
|
|
82
|
+
const baseUrl = typeof baseUrlOrOptions === "string" ? baseUrlOrOptions : DEFAULT_BASE_URL;
|
|
83
|
+
const options = typeof baseUrlOrOptions === "string" ? maybeOptions : baseUrlOrOptions;
|
|
84
|
+
const base = baseUrl.replace(/\/+$/, "");
|
|
85
|
+
const defaultProvider = options.provider;
|
|
86
|
+
const defaultImage = options.placeholder || options.defaultImage;
|
|
87
|
+
const defaultOutput = options.output;
|
|
88
|
+
const docBase = `${base}/v1/documents/${encodeURIComponent(documentId)}`;
|
|
89
|
+
const artifactBase = options.fileName ? slugifyFileStem(options.fileName) : "document";
|
|
90
|
+
const formatParams = (opts) => {
|
|
91
|
+
const params = new URLSearchParams();
|
|
92
|
+
if (opts?.format) params.set("format", opts.format);
|
|
93
|
+
if (opts?.include?.length) params.set("include", opts.include.join(","));
|
|
94
|
+
const qs = params.toString();
|
|
95
|
+
return qs ? `?${qs}` : "";
|
|
96
|
+
};
|
|
97
|
+
const buildUrl = (resource, opts) => {
|
|
98
|
+
const mods = {};
|
|
99
|
+
const prov = opts?.provider || defaultProvider;
|
|
100
|
+
if (prov) mods.variant = prov;
|
|
101
|
+
const ph = opts?.placeholder || defaultImage;
|
|
102
|
+
if (ph) mods.default = ph;
|
|
103
|
+
const out = opts?.output || defaultOutput;
|
|
104
|
+
if (out) mods.output = out;
|
|
105
|
+
if (opts?.transform) {
|
|
106
|
+
validateTransform(opts.transform);
|
|
107
|
+
mods.transform = opts.transform;
|
|
108
|
+
}
|
|
109
|
+
const segs = buildModifierSegments(mods);
|
|
110
|
+
const modPath = segs.length > 0 ? `/${segs.join("/")}` : "";
|
|
111
|
+
const resourcePart = resource ? `/${resource}` : "";
|
|
112
|
+
const artifactSuffix = opts?.artifact ? `/${opts.artifact.stem}.${opts.artifact.ext}` : "";
|
|
113
|
+
const qs = opts?.qs || "";
|
|
114
|
+
return `${docBase}${modPath}${resourcePart}${artifactSuffix}${qs}`;
|
|
115
|
+
};
|
|
116
|
+
const makeEntityCollection = (type) => {
|
|
117
|
+
return new Proxy({}, {
|
|
118
|
+
get(_target, prop) {
|
|
119
|
+
if (prop === "url") {
|
|
120
|
+
return (opts) => buildUrl(`entities/${type}`, {
|
|
121
|
+
provider: opts?.provider,
|
|
122
|
+
transform: opts?.transform,
|
|
123
|
+
artifact: { stem: artifactBase, ext: extensionFor(opts?.format, "json") },
|
|
124
|
+
qs: formatParams(opts)
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
const index = typeof prop === "string" ? parseInt(prop, 10) : NaN;
|
|
128
|
+
if (!isNaN(index)) {
|
|
129
|
+
return {
|
|
130
|
+
url: (opts) => buildUrl(`entities/${type}/${index}`, {
|
|
131
|
+
provider: opts?.provider,
|
|
132
|
+
artifact: { stem: artifactBase, ext: extensionFor(opts?.format, "json") },
|
|
133
|
+
qs: opts?.format ? `?format=${opts.format}` : ""
|
|
134
|
+
})
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
return void 0;
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
};
|
|
141
|
+
const makePgPage = (pageNum) => ({
|
|
142
|
+
png: (opts) => buildUrl(`pg_${pageNum}.png`, { placeholder: opts?.placeholder, transform: opts?.transform }),
|
|
143
|
+
md: (opts) => buildUrl(`pg_${pageNum}.md`, { transform: opts?.transform }),
|
|
144
|
+
json: (opts) => buildUrl(`pg_${pageNum}.json`, { transform: opts?.transform })
|
|
145
|
+
});
|
|
146
|
+
const makePgRange = (segment) => ({
|
|
147
|
+
md: (opts) => buildUrl(`pg_${segment}.md`, { transform: opts?.transform }),
|
|
148
|
+
json: (opts) => buildUrl(`pg_${segment}.json`, { transform: opts?.transform })
|
|
149
|
+
});
|
|
150
|
+
const pg = new Proxy({}, {
|
|
151
|
+
get(_target, prop) {
|
|
152
|
+
if (prop === "range") {
|
|
153
|
+
return (start, end) => makePgRange(`${start}-${end}`);
|
|
154
|
+
}
|
|
155
|
+
if (prop === "list") {
|
|
156
|
+
return (...pages) => makePgRange(pages.join(","));
|
|
157
|
+
}
|
|
158
|
+
const pageNum = typeof prop === "string" ? parseInt(prop, 10) : NaN;
|
|
159
|
+
if (!isNaN(pageNum)) {
|
|
160
|
+
return makePgPage(pageNum);
|
|
161
|
+
}
|
|
162
|
+
return void 0;
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
const buildDocumentUrl = (outputOverride) => ({
|
|
166
|
+
url: (opts) => buildUrl("", {
|
|
167
|
+
provider: opts?.provider,
|
|
168
|
+
output: outputOverride,
|
|
169
|
+
transform: opts?.transform,
|
|
170
|
+
artifact: { stem: artifactBase, ext: extensionFor(opts?.format, "json") },
|
|
171
|
+
qs: formatParams(opts)
|
|
172
|
+
}),
|
|
173
|
+
thumbnail: {
|
|
174
|
+
url: (opts) => buildUrl("pg_1.png", { transform: opts?.transform })
|
|
175
|
+
},
|
|
176
|
+
full: {
|
|
177
|
+
md: () => `${docBase}/full.md`
|
|
178
|
+
},
|
|
179
|
+
download: () => `${base}/document/${encodeURIComponent(documentId)}/download`,
|
|
180
|
+
pg,
|
|
181
|
+
entities: {
|
|
182
|
+
tables: makeEntityCollection("tables"),
|
|
183
|
+
figures: makeEntityCollection("figures")
|
|
184
|
+
},
|
|
185
|
+
output: (schema) => {
|
|
186
|
+
return doc(documentId, baseUrl, { ...options, output: schema });
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
return buildDocumentUrl();
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
export {
|
|
193
|
+
doc
|
|
194
|
+
};
|
|
195
|
+
//# sourceMappingURL=chunk-QKII53VN.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/url.ts"],"sourcesContent":["import type { DeliveryTransform, DocUrlOptions, UrlBuilderOptions } from './types';\n\nconst DEFAULT_BASE_URL = 'https://api.okrapdf.com';\n\n// ── Delivery transform key ordering (matches @okrapdf/schemas DELIVERY_KEYS) ──\n\nconst DELIVERY_KEY_ORDER = [\n 'w', 'h', 'dpr', 'q', 'f', 'md', 'c', 'g', 'zm',\n 'bl', 'sh', 'br', 'co', 'sa', 'r', 'fl', 'bg', 'anim', 'seg',\n] as const;\n\nconst VALID_FORMATS = new Set(['auto', 'webp', 'avif', 'jpeg', 'png']);\nconst VALID_CROPS = new Set(['scale-down', 'contain', 'cover', 'crop', 'pad', 'squeeze']);\nconst VALID_GRAVITIES = new Set(['auto', 'face', 'left', 'right', 'top', 'bottom', 'center']);\nconst VALID_FLIPS = new Set(['h', 'v', 'hv']);\nconst VALID_ROTATIONS = new Set([0, 90, 180, 270]);\n\nfunction validateTransform(t: DeliveryTransform): void {\n if (t.w !== undefined && (!Number.isInteger(t.w) || t.w <= 0)) throw new Error('Invalid delivery transform: w must be a positive integer');\n if (t.h !== undefined && (!Number.isInteger(t.h) || t.h <= 0)) throw new Error('Invalid delivery transform: h must be a positive integer');\n if (t.dpr !== undefined && t.dpr <= 0) throw new Error('Invalid delivery transform: dpr must be positive');\n if (t.q !== undefined && (!Number.isInteger(t.q) || t.q < 1 || t.q > 100)) throw new Error('Invalid delivery transform: q must be 1-100');\n if (t.f !== undefined && !VALID_FORMATS.has(t.f)) throw new Error(`Invalid delivery transform: f must be one of ${[...VALID_FORMATS].join(', ')}`);\n if (t.c !== undefined && !VALID_CROPS.has(t.c)) throw new Error(`Invalid delivery transform: c must be one of ${[...VALID_CROPS].join(', ')}`);\n if (t.g !== undefined && !VALID_GRAVITIES.has(t.g)) throw new Error(`Invalid delivery transform: g must be one of ${[...VALID_GRAVITIES].join(', ')}`);\n if (t.zm !== undefined && (t.zm < 0 || t.zm > 1)) throw new Error('Invalid delivery transform: zm must be 0-1');\n if (t.bl !== undefined && (!Number.isInteger(t.bl) || t.bl < 1 || t.bl > 250)) throw new Error('Invalid delivery transform: bl must be 1-250');\n if (t.sh !== undefined && (t.sh < 0 || t.sh > 10)) throw new Error('Invalid delivery transform: sh must be 0-10');\n if (t.r !== undefined && !VALID_ROTATIONS.has(t.r)) throw new Error('Invalid delivery transform: r must be 0, 90, 180, or 270');\n if (t.fl !== undefined && !VALID_FLIPS.has(t.fl)) throw new Error(`Invalid delivery transform: fl must be one of ${[...VALID_FLIPS].join(', ')}`);\n}\n\n/** Serialize delivery transform to a single URL segment: \"w_200,h_300,q_80\" */\nfunction serializeTransform(t: DeliveryTransform): string {\n const tokens: string[] = [];\n const rec = t as Record<string, unknown>;\n for (const k of DELIVERY_KEY_ORDER) {\n if (rec[k] !== undefined) tokens.push(`${k}_${rec[k]}`);\n }\n return tokens.join(',');\n}\n\n// ── Modifier segment builder (inlined from @okrapdf/schemas/document-url) ──\n\ninterface Modifiers {\n variant?: string;\n default?: string;\n output?: string;\n transform?: DeliveryTransform;\n}\n\nfunction buildModifierSegments(mods: Modifiers): string[] {\n const parts: string[] = [];\n if (mods.variant) parts.push(`t_${mods.variant}`);\n if (mods.default) parts.push(`d_${mods.default}`);\n if (mods.output) parts.push(`o_${mods.output}`);\n if (mods.transform) {\n const seg = serializeTransform(mods.transform);\n if (seg) parts.push(seg);\n }\n return parts;\n}\n\n// ── Interfaces ──────────────────────────────────────────────────────────────\n\ninterface PgPage {\n png: (opts?: { placeholder?: string; transform?: DeliveryTransform }) => string;\n md: (opts?: { transform?: DeliveryTransform }) => string;\n json: (opts?: { transform?: DeliveryTransform }) => string;\n}\n\ninterface PgPageRange {\n md: (opts?: { transform?: DeliveryTransform }) => string;\n json: (opts?: { transform?: DeliveryTransform }) => string;\n}\n\ninterface PgProxy {\n [index: number]: PgPage;\n range: (start: number, end: number) => PgPageRange;\n list: (...pages: number[]) => PgPageRange;\n}\n\ninterface DocumentUrl {\n /** Base document URL */\n url: (opts?: UrlBuilderOptions) => string;\n /** Thumbnail image URL (pg_1.png) */\n thumbnail: { url: (opts?: { transform?: DeliveryTransform }) => string };\n /** Full document markdown */\n full: { md: () => string };\n /** Original PDF download (auth required) */\n download: () => string;\n /** Page access: d.pg[1].png(), d.pg[1].md(), d.pg[1].json() */\n pg: PgProxy;\n /** Entity-level access */\n entities: EntitiesProxy;\n /** Output schema — returns a new DocumentUrl scoped to o_{schema} */\n output: (schema: string) => DocumentUrl;\n}\n\ninterface EntitiesProxy {\n tables: EntityCollectionProxy;\n figures: EntityCollectionProxy;\n}\n\ninterface EntityCollectionProxy {\n [index: number]: {\n url: (opts?: { format?: 'json' | 'csv' | 'html' }) => string;\n };\n url: (opts?: UrlBuilderOptions) => string;\n}\n\n// ── Helpers ──────────────────────────────────────────────────────────────────\n\nconst FORMAT_TO_EXT: Record<NonNullable<UrlBuilderOptions['format']>, string> = {\n json: 'json',\n csv: 'csv',\n html: 'html',\n markdown: 'md',\n png: 'png',\n};\n\nfunction slugifyFileStem(fileName: string): string {\n const leaf = fileName.split('/').pop() || fileName;\n const noExt = leaf.replace(/\\.[A-Za-z0-9]{1,8}$/, '');\n const slug = noExt\n .toLowerCase()\n .replace(/[^a-z0-9]+/g, '-')\n .replace(/^-+|-+$/g, '')\n .slice(0, 48);\n return slug || 'document';\n}\n\nfunction extensionFor(format: string | undefined, fallback: string): string {\n if (!format) return fallback;\n const lower = format.toLowerCase();\n if (lower === 'markdown') return 'md';\n return FORMAT_TO_EXT[lower as keyof typeof FORMAT_TO_EXT] || lower;\n}\n\n/**\n * Build-time URL builder — Cloudinary for documents.\n *\n * ```tsx\n * import { doc } from 'okrapdf';\n * const d = doc('doc_7fK3x');\n * <Image src={d.thumbnail.url()} />\n * <a href={d.entities.tables[0].url({ format: 'csv' })}>CSV</a>\n * ```\n */\nexport function doc(\n documentId: string,\n baseUrlOrOptions: string | DocUrlOptions = DEFAULT_BASE_URL,\n maybeOptions: DocUrlOptions = {},\n): DocumentUrl {\n const baseUrl = typeof baseUrlOrOptions === 'string' ? baseUrlOrOptions : DEFAULT_BASE_URL;\n const options = typeof baseUrlOrOptions === 'string' ? maybeOptions : baseUrlOrOptions;\n\n const base = baseUrl.replace(/\\/+$/, '');\n const defaultProvider = options.provider;\n const defaultImage = options.placeholder || options.defaultImage;\n const defaultOutput = options.output;\n const docBase = `${base}/v1/documents/${encodeURIComponent(documentId)}`;\n const artifactBase = options.fileName\n ? slugifyFileStem(options.fileName)\n : 'document';\n\n const formatParams = (opts?: UrlBuilderOptions) => {\n const params = new URLSearchParams();\n if (opts?.format) params.set('format', opts.format);\n if (opts?.include?.length) params.set('include', opts.include.join(','));\n const qs = params.toString();\n return qs ? `?${qs}` : '';\n };\n\n /** Single path for all modifier → URL serialization. */\n const buildUrl = (\n resource: string,\n opts?: {\n placeholder?: string;\n provider?: string;\n output?: string;\n transform?: DeliveryTransform;\n artifact?: { stem: string; ext: string };\n qs?: string;\n },\n ): string => {\n const mods: Modifiers = {};\n\n const prov = opts?.provider || defaultProvider;\n if (prov) mods.variant = prov;\n\n const ph = opts?.placeholder || defaultImage;\n if (ph) mods.default = ph;\n\n const out = opts?.output || defaultOutput;\n if (out) mods.output = out;\n\n if (opts?.transform) {\n validateTransform(opts.transform);\n mods.transform = opts.transform;\n }\n\n const segs = buildModifierSegments(mods);\n const modPath = segs.length > 0 ? `/${segs.join('/')}` : '';\n const resourcePart = resource ? `/${resource}` : '';\n const artifactSuffix = opts?.artifact ? `/${opts.artifact.stem}.${opts.artifact.ext}` : '';\n const qs = opts?.qs || '';\n return `${docBase}${modPath}${resourcePart}${artifactSuffix}${qs}`;\n };\n\n const makeEntityCollection = (type: string): EntityCollectionProxy => {\n return new Proxy({} as EntityCollectionProxy, {\n get(_target, prop) {\n if (prop === 'url') {\n return (opts?: UrlBuilderOptions) =>\n buildUrl(`entities/${type}`, {\n provider: opts?.provider,\n transform: opts?.transform,\n artifact: { stem: artifactBase, ext: extensionFor(opts?.format, 'json') },\n qs: formatParams(opts),\n });\n }\n const index = typeof prop === 'string' ? parseInt(prop, 10) : NaN;\n if (!isNaN(index)) {\n return {\n url: (opts?: { format?: string; provider?: string }) =>\n buildUrl(`entities/${type}/${index}`, {\n provider: opts?.provider,\n artifact: { stem: artifactBase, ext: extensionFor(opts?.format, 'json') },\n qs: opts?.format ? `?format=${opts.format}` : '',\n }),\n };\n }\n return undefined;\n },\n });\n };\n\n const makePgPage = (pageNum: number): PgPage => ({\n png: (opts?: { placeholder?: string; transform?: DeliveryTransform }) =>\n buildUrl(`pg_${pageNum}.png`, { placeholder: opts?.placeholder, transform: opts?.transform }),\n md: (opts?: { transform?: DeliveryTransform }) =>\n buildUrl(`pg_${pageNum}.md`, { transform: opts?.transform }),\n json: (opts?: { transform?: DeliveryTransform }) =>\n buildUrl(`pg_${pageNum}.json`, { transform: opts?.transform }),\n });\n\n const makePgRange = (segment: string): PgPageRange => ({\n md: (opts?: { transform?: DeliveryTransform }) =>\n buildUrl(`pg_${segment}.md`, { transform: opts?.transform }),\n json: (opts?: { transform?: DeliveryTransform }) =>\n buildUrl(`pg_${segment}.json`, { transform: opts?.transform }),\n });\n\n const pg: PgProxy = new Proxy({} as PgProxy, {\n get(_target, prop) {\n if (prop === 'range') {\n return (start: number, end: number) => makePgRange(`${start}-${end}`);\n }\n if (prop === 'list') {\n return (...pages: number[]) => makePgRange(pages.join(','));\n }\n const pageNum = typeof prop === 'string' ? parseInt(prop, 10) : NaN;\n if (!isNaN(pageNum)) {\n return makePgPage(pageNum);\n }\n return undefined;\n },\n });\n\n const buildDocumentUrl = (outputOverride?: string): DocumentUrl => ({\n url: (opts?: UrlBuilderOptions) =>\n buildUrl('', {\n provider: opts?.provider,\n output: outputOverride,\n transform: opts?.transform,\n artifact: { stem: artifactBase, ext: extensionFor(opts?.format, 'json') },\n qs: formatParams(opts),\n }),\n thumbnail: {\n url: (opts?: { transform?: DeliveryTransform }) =>\n buildUrl('pg_1.png', { transform: opts?.transform }),\n },\n full: {\n md: () => `${docBase}/full.md`,\n },\n download: () => `${base}/document/${encodeURIComponent(documentId)}/download`,\n pg,\n entities: {\n tables: makeEntityCollection('tables'),\n figures: makeEntityCollection('figures'),\n },\n output: (schema: string) => {\n // Return a new builder with the output schema baked in.\n // We create a new doc() call with the output option set.\n return doc(documentId, baseUrl, { ...options, output: schema });\n },\n });\n\n return buildDocumentUrl();\n}\n"],"mappings":";AAEA,IAAM,mBAAmB;AAIzB,IAAM,qBAAqB;AAAA,EACzB;AAAA,EAAK;AAAA,EAAK;AAAA,EAAO;AAAA,EAAK;AAAA,EAAK;AAAA,EAAM;AAAA,EAAK;AAAA,EAAK;AAAA,EAC3C;AAAA,EAAM;AAAA,EAAM;AAAA,EAAM;AAAA,EAAM;AAAA,EAAM;AAAA,EAAK;AAAA,EAAM;AAAA,EAAM;AAAA,EAAQ;AACzD;AAEA,IAAM,gBAAgB,oBAAI,IAAI,CAAC,QAAQ,QAAQ,QAAQ,QAAQ,KAAK,CAAC;AACrE,IAAM,cAAc,oBAAI,IAAI,CAAC,cAAc,WAAW,SAAS,QAAQ,OAAO,SAAS,CAAC;AACxF,IAAM,kBAAkB,oBAAI,IAAI,CAAC,QAAQ,QAAQ,QAAQ,SAAS,OAAO,UAAU,QAAQ,CAAC;AAC5F,IAAM,cAAc,oBAAI,IAAI,CAAC,KAAK,KAAK,IAAI,CAAC;AAC5C,IAAM,kBAAkB,oBAAI,IAAI,CAAC,GAAG,IAAI,KAAK,GAAG,CAAC;AAEjD,SAAS,kBAAkB,GAA4B;AACrD,MAAI,EAAE,MAAM,WAAc,CAAC,OAAO,UAAU,EAAE,CAAC,KAAK,EAAE,KAAK,GAAI,OAAM,IAAI,MAAM,0DAA0D;AACzI,MAAI,E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AmB;AAG1B,aAAO,IAAI,YAAY,SAAS,EAAE,GAAG,SAAS,QAAQ,OAAO,CAAC;AAAA,IAChE;AAAA,EACF;AAEA,SAAO,iBAAiB;AAC1B;","names":[]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
OkraClient
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-EZLAOKOP.js";
|
|
4
4
|
|
|
5
5
|
// src/providers.ts
|
|
6
6
|
function isPlainObject(value) {
|
|
@@ -81,4 +81,4 @@ export {
|
|
|
81
81
|
withQualityScore,
|
|
82
82
|
withSecret
|
|
83
83
|
};
|
|
84
|
-
//# sourceMappingURL=chunk-
|
|
84
|
+
//# sourceMappingURL=chunk-Y72DLYYO.js.map
|
package/dist/cli/bin.js
CHANGED
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
authStatus,
|
|
6
6
|
collectionList,
|
|
7
7
|
collectionQueryRaw,
|
|
8
|
+
collectionSetVisibility,
|
|
8
9
|
find,
|
|
9
10
|
formatCollectionCsv,
|
|
10
11
|
formatCollectionList,
|
|
@@ -34,10 +35,10 @@ import {
|
|
|
34
35
|
tree,
|
|
35
36
|
upload,
|
|
36
37
|
writeOutput
|
|
37
|
-
} from "../chunk-
|
|
38
|
+
} from "../chunk-4IHOG655.js";
|
|
38
39
|
import {
|
|
39
40
|
OkraClient
|
|
40
|
-
} from "../chunk-
|
|
41
|
+
} from "../chunk-EZLAOKOP.js";
|
|
41
42
|
import "../chunk-NIZM2ETT.js";
|
|
42
43
|
|
|
43
44
|
// src/cli/bin.ts
|
|
@@ -56,7 +57,7 @@ function getClient() {
|
|
|
56
57
|
process.stderr.write(JSON.stringify({ error: "No API key found", code: 401 }) + "\n");
|
|
57
58
|
} else {
|
|
58
59
|
process.stderr.write(
|
|
59
|
-
'No API key found.\n\n Get one: https://okrapdf.dev/api-keys\n Then: export OKRA_API_KEY="okra_xxx"\n Or: npx okra auth login\n'
|
|
60
|
+
'No API key found.\n\n Get one: https://okrapdf.dev/api-keys\n Then: export OKRA_API_KEY="okra_xxx"\n Or: npx okra auth login\n\n Docs: https://okrapdf.dev/docs\n Discord: https://discord.gg/BHNmbZVs\n'
|
|
60
61
|
);
|
|
61
62
|
}
|
|
62
63
|
process.exit(1);
|
|
@@ -87,6 +88,8 @@ program.command("upload <source>").description("Upload a PDF (file path or URL),
|
|
|
87
88
|
lines.push(" /v1/documents/{id}/pg_{N}.md page markdown");
|
|
88
89
|
lines.push(" /v1/documents/{id}/d_shimmer/pg_{N}.png page image");
|
|
89
90
|
lines.push(" /v1/documents/{id}/full.md full document");
|
|
91
|
+
lines.push("");
|
|
92
|
+
lines.push(" Docs: https://okrapdf.dev/docs Discord: https://discord.gg/BHNmbZVs");
|
|
90
93
|
}
|
|
91
94
|
writeOutput(lines.join("\n"), g.output);
|
|
92
95
|
}
|
|
@@ -137,6 +140,38 @@ collectionCmd.command("query <nameOrId> <question>").description("Fan-out query
|
|
|
137
140
|
handleError(error, g.json);
|
|
138
141
|
}
|
|
139
142
|
});
|
|
143
|
+
collectionCmd.command("publish <nameOrId>").description("Make a collection publicly queryable").action(async (nameOrId) => {
|
|
144
|
+
const g = globals();
|
|
145
|
+
try {
|
|
146
|
+
const client = getClient();
|
|
147
|
+
await collectionSetVisibility(client, nameOrId, "public");
|
|
148
|
+
if (g.json) {
|
|
149
|
+
writeOutput(JSON.stringify({ ok: true, visibility: "public", collection: nameOrId }), g.output);
|
|
150
|
+
} else {
|
|
151
|
+
writeOutput(
|
|
152
|
+
`Published "${nameOrId}"
|
|
153
|
+
Share with: okra collection query ${nameOrId} "your question"`,
|
|
154
|
+
g.output
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
} catch (error) {
|
|
158
|
+
handleError(error, g.json);
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
collectionCmd.command("unpublish <nameOrId>").description("Make a collection private (owner-only)").action(async (nameOrId) => {
|
|
162
|
+
const g = globals();
|
|
163
|
+
try {
|
|
164
|
+
const client = getClient();
|
|
165
|
+
await collectionSetVisibility(client, nameOrId, "private");
|
|
166
|
+
if (g.json) {
|
|
167
|
+
writeOutput(JSON.stringify({ ok: true, visibility: "private", collection: nameOrId }), g.output);
|
|
168
|
+
} else {
|
|
169
|
+
writeOutput(`Unpublished "${nameOrId}" \u2014 now private`, g.output);
|
|
170
|
+
}
|
|
171
|
+
} catch (error) {
|
|
172
|
+
handleError(error, g.json);
|
|
173
|
+
}
|
|
174
|
+
});
|
|
140
175
|
var authCmd = program.command("auth").description("Manage authentication");
|
|
141
176
|
authCmd.command("login").description("Save API key to global config").action(async () => {
|
|
142
177
|
try {
|
package/dist/cli/bin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/cli/bin.ts"],"sourcesContent":["#!/usr/bin/env node\n/**\n * okra CLI — Agent-friendly PDF extraction and collection queries.\n *\n * Global flags:\n * -j, --json Structured JSON output\n * -q, --quiet Suppress progress (just data to stdout)\n * -o, --output Write output to file (CSV/JSON)\n *\n * Action commands (agent-grade):\n * okra upload <source> # Upload + wait\n * okra collection list # List collections\n * okra collection query <name> \"<question>\" # Fan-out → CSV\n *\n * Review commands (existing):\n * okra tree / find / page / search / tables / history / toc\n *\n * Exit codes: 0=success, 1=client error, 2=server error\n */\n\nimport { Command } from 'commander';\nimport { OkraClient } from '../client';\nimport {\n tree,\n formatTreeOutput,\n find,\n formatFindOutput,\n formatStats,\n pageGet,\n pageEdit,\n pageResolve,\n pageVersions,\n formatPageOutput,\n formatVersionsOutput,\n search,\n formatSearchOutput,\n tables,\n formatTablesOutput,\n history,\n formatHistoryOutput,\n toc,\n formatTocOutput,\n authLogin,\n authStatus,\n authLogout,\n upload,\n collectionList,\n collectionQueryRaw,\n formatCollectionList,\n formatCollectionCsv,\n formatCollectionTable,\n formatQueryJsonl,\n} from './commands';\nimport { getApiKey, getBaseUrl } from './config';\nimport { handleError, writeOutput, progress } from './output';\nimport type { GlobalFlags } from './output';\n\nconst program = new Command();\n\nprogram\n .name('okra')\n .description('OkraPDF CLI — upload PDFs, query collections, extract data')\n .version('0.9.0')\n .option('-j, --json', 'Output JSON (structured, machine-readable)')\n .option('-q, --quiet', 'Suppress progress and human-readable frills')\n .option('-o, --output <file>', 'Write output to file instead of stdout');\n\n/** Read global flags from program.opts(). */\nfunction globals(): GlobalFlags {\n return program.opts();\n}\n\n// Create client with proper config priority:\n// 1. Environment variable (OKRA_API_KEY)\n// 2. Project config (.okrarc, .okra.json)\n// 3. Global config (~/.okra/config.json)\nfunction getClient(): OkraClient {\n const apiKey = getApiKey();\n const baseUrl = getBaseUrl();\n\n if (!apiKey) {\n const g = globals();\n if (g.json) {\n process.stderr.write(JSON.stringify({ error: 'No API key found', code: 401 }) + '\\n');\n } else {\n process.stderr.write(\n 'No API key found.\\n\\n' +\n ' Get one: https://okrapdf.dev/api-keys\\n' +\n ' Then: export OKRA_API_KEY=\"okra_xxx\"\\n' +\n ' Or: npx okra auth login\\n',\n );\n }\n process.exit(1);\n }\n\n return new OkraClient({ apiKey, baseUrl });\n}\n\n// ============================================================================\n// upload command\n// ============================================================================\nprogram\n .command('upload <source>')\n .description('Upload a PDF (file path or URL), wait for processing')\n .option('--no-wait', 'Fire-and-forget (don\\'t wait for processing)')\n .action(async (source, options) => {\n const g = globals();\n try {\n const client = getClient();\n const result = await upload(client, source, {\n ...g,\n noWait: options.wait === false,\n });\n\n if (g.json) {\n writeOutput(JSON.stringify(result), g.output);\n } else {\n const lines = [`Done — ${result.pages ?? '?'} pages`, ''];\n lines.push(` ${result.id}`);\n if (result.urls) {\n const short = result.id.slice(0, 11) + '...';\n lines.push('');\n lines.push(` Markdown: ${result.urls.full_md.replace(result.id, short)}`);\n lines.push(` Page 1: ${result.urls.page_png.replace(result.id, short).replace('{N}', '1')}`);\n lines.push(` Completion: ${result.urls.completion.replace(result.id, short)}`);\n lines.push('');\n lines.push(' URL patterns:');\n lines.push(' /v1/documents/{id}/pg_{N}.md page markdown');\n lines.push(' /v1/documents/{id}/d_shimmer/pg_{N}.png page image');\n lines.push(' /v1/documents/{id}/full.md full document');\n }\n writeOutput(lines.join('\\n'), g.output);\n }\n } catch (error) {\n handleError(error, g.json);\n }\n });\n\n// ============================================================================\n// collection command\n// ============================================================================\nconst collectionCmd = program.command('collection').description('Collection operations');\n\ncollectionCmd\n .command('list')\n .description('List available collections')\n .action(async () => {\n const g = globals();\n try {\n const client = getClient();\n const rows = await collectionList(client, g);\n writeOutput(formatCollectionList(rows, g.json), g.output);\n } catch (error) {\n handleError(error, g.json);\n }\n });\n\ncollectionCmd\n .command('query <nameOrId> <question>')\n .description('Fan-out query across collection documents')\n .option('--schema <file>', 'JSON Schema file for structured extraction')\n .action(async (nameOrId, question, options) => {\n const g = globals();\n try {\n const apiKey = getApiKey();\n const baseUrl = getBaseUrl();\n if (!apiKey) {\n handleError(new Error('No API key found'), g.json);\n }\n\n const { results, summary } = await collectionQueryRaw(\n baseUrl!,\n apiKey!,\n nameOrId,\n question,\n { ...g, schema: options.schema },\n );\n\n // Determine output format based on flags\n if (g.json) {\n // --json: JSONL events to stdout\n writeOutput(formatQueryJsonl(results), g.output);\n } else if (g.output && g.output.endsWith('.csv')) {\n // -o file.csv → CSV\n writeOutput(formatCollectionCsv(results), g.output);\n } else if (g.output) {\n // -o file.json or other → JSON\n writeOutput(JSON.stringify({ results, summary }), g.output);\n } else {\n // Default: compact table to stdout\n writeOutput(formatCollectionTable(results));\n }\n\n progress(\n `${summary.completed} completed, ${summary.failed} failed — $${summary.total_cost_usd.toFixed(4)}`,\n g.quiet,\n );\n } catch (error) {\n handleError(error, g.json);\n }\n });\n\n// ============================================================================\n// auth command - Authentication management\n// ============================================================================\nconst authCmd = program.command('auth').description('Manage authentication');\n\nauthCmd\n .command('login')\n .description('Save API key to global config')\n .action(async () => {\n try {\n await authLogin();\n } catch (error) {\n handleError(error, globals().json);\n }\n });\n\nauthCmd\n .command('status')\n .description('Show authentication status')\n .action(async () => {\n try {\n await authStatus();\n } catch (error) {\n handleError(error, globals().json);\n }\n });\n\nauthCmd\n .command('logout')\n .description('Remove API key from global config')\n .action(async () => {\n try {\n await authLogout();\n } catch (error) {\n handleError(error, globals().json);\n }\n });\n\n// ============================================================================\n// tree command - Document verification tree\n// ============================================================================\nprogram\n .command('tree <jobId>')\n .description('Show document verification tree')\n .option('-s, --status <status>', 'Filter by status (complete|partial|pending|flagged|empty|gap)')\n .option('-e, --entity <type>', 'Filter by entity type (table|figure|footnote)')\n .option('-f, --format <format>', 'Output format (text|json|markdown)', 'text')\n .action(async (jobId, options) => {\n const g = globals();\n try {\n const client = getClient();\n const fmt = g.json ? 'json' : options.format;\n const result = await tree(client, jobId, {\n status: options.status,\n entity: options.entity,\n });\n writeOutput(formatTreeOutput(result, fmt), g.output);\n } catch (error) {\n handleError(error, g.json);\n }\n });\n\n// ============================================================================\n// find command - jQuery-like entity search\n// ============================================================================\nprogram\n .command('find <jobId> <selector>')\n .description('Find entities using jQuery-like selectors')\n .option('-k, --top-k <n>', 'Limit results', parseInt)\n .option('-c, --min-confidence <n>', 'Minimum confidence (0-1)', parseFloat)\n .option('-p, --pages <range>', 'Page range (e.g., 1-10)')\n .option('--sort <by>', 'Sort by (confidence|page|type)')\n .option('--stats', 'Show aggregate statistics')\n .option('-f, --format <format>', 'Output format (text|json|entities|ids)', 'text')\n .action(async (jobId, selector, options) => {\n const g = globals();\n try {\n const client = getClient();\n const fmt = g.json ? 'json' : options.format;\n const pageRange = options.pages\n ? options.pages.split('-').map(Number) as [number, number]\n : undefined;\n\n const result = await find(client, jobId, selector, {\n topK: options.topK,\n minConfidence: options.minConfidence,\n pageRange,\n sortBy: options.sort,\n });\n\n if (options.stats && fmt === 'text') {\n writeOutput(formatStats(result.stats), g.output);\n } else {\n writeOutput(formatFindOutput(result, fmt, options.stats), g.output);\n }\n } catch (error) {\n handleError(error, g.json);\n }\n });\n\n// ============================================================================\n// page command - Page content operations\n// ============================================================================\nconst pageCmd = program.command('page').description('Page content operations');\n\npageCmd\n .command('get <jobId> <pageNum>')\n .description('Get page content')\n .option('-v, --version <n>', 'Specific version', parseInt)\n .option('-f, --format <format>', 'Output format (text|json|markdown)', 'markdown')\n .action(async (jobId, pageNum, options) => {\n const g = globals();\n try {\n const client = getClient();\n const fmt = g.json ? 'json' : options.format;\n const content = await pageGet(client, jobId, parseInt(pageNum), {\n version: options.version,\n });\n writeOutput(formatPageOutput(content, fmt), g.output);\n } catch (error) {\n handleError(error, g.json);\n }\n });\n\npageCmd\n .command('edit <jobId> <pageNum>')\n .description('Edit page content (reads from stdin)')\n .action(async (jobId, pageNum) => {\n const g = globals();\n try {\n const chunks: Buffer[] = [];\n for await (const chunk of process.stdin) {\n chunks.push(chunk);\n }\n const content = Buffer.concat(chunks).toString('utf8');\n\n const client = getClient();\n const result = await pageEdit(client, jobId, parseInt(pageNum), content);\n if (g.json) {\n writeOutput(JSON.stringify({ version: result.version }), g.output);\n } else {\n writeOutput(`Saved as version ${result.version}`, g.output);\n }\n } catch (error) {\n handleError(error, g.json);\n }\n });\n\npageCmd\n .command('resolve <jobId> <pageNum> <resolution>')\n .description('Resolve page verification status')\n .option('-c, --classification <class>', 'Classification')\n .option('-r, --reason <reason>', 'Reason')\n .action(async (jobId, pageNum, resolution, options) => {\n const g = globals();\n try {\n const client = getClient();\n const result = await pageResolve(client, jobId, parseInt(pageNum), {\n resolution,\n classification: options.classification,\n reason: options.reason,\n });\n if (g.json) {\n writeOutput(JSON.stringify({ success: result.success }), g.output);\n } else {\n writeOutput(result.success ? 'Resolved' : 'Failed', g.output);\n }\n } catch (error) {\n handleError(error, g.json);\n }\n });\n\npageCmd\n .command('versions <jobId> <pageNum>')\n .description('List page versions')\n .option('-f, --format <format>', 'Output format (text|json)', 'text')\n .action(async (jobId, pageNum, options) => {\n const g = globals();\n try {\n const client = getClient();\n const fmt = g.json ? 'json' : options.format;\n const versions = await pageVersions(client, jobId, parseInt(pageNum));\n writeOutput(formatVersionsOutput(versions, fmt), g.output);\n } catch (error) {\n handleError(error, g.json);\n }\n });\n\n// ============================================================================\n// search command - Full-text search\n// ============================================================================\nprogram\n .command('search <jobId> <query>')\n .description('Search page content')\n .option('-f, --format <format>', 'Output format (text|json)', 'text')\n .action(async (jobId, query, options) => {\n const g = globals();\n try {\n const client = getClient();\n const fmt = g.json ? 'json' : options.format;\n const result = await search(client, jobId, query);\n writeOutput(formatSearchOutput(result, fmt), g.output);\n } catch (error) {\n handleError(error, g.json);\n }\n });\n\n// ============================================================================\n// tables command - List tables\n// ============================================================================\nprogram\n .command('tables <jobId>')\n .description('List extracted tables')\n .option('-p, --page <n>', 'Filter by page', parseInt)\n .option('-s, --status <status>', 'Filter by status (pending|verified|flagged|rejected)')\n .option('-f, --format <format>', 'Output format (text|json|markdown)', 'text')\n .action(async (jobId, options) => {\n const g = globals();\n try {\n const client = getClient();\n const fmt = g.json ? 'json' : options.format;\n const result = await tables(client, jobId, {\n page: options.page,\n status: options.status,\n });\n writeOutput(formatTablesOutput(result, fmt), g.output);\n } catch (error) {\n handleError(error, g.json);\n }\n });\n\n// ============================================================================\n// history command - Verification audit trail\n// ============================================================================\nprogram\n .command('history <jobId>')\n .description('Show verification history')\n .option('-l, --limit <n>', 'Limit entries', parseInt, 50)\n .option('-f, --format <format>', 'Output format (text|json)', 'text')\n .action(async (jobId, options) => {\n const g = globals();\n try {\n const client = getClient();\n const fmt = g.json ? 'json' : options.format;\n const result = await history(client, jobId, { limit: options.limit });\n writeOutput(formatHistoryOutput(result, fmt), g.output);\n } catch (error) {\n handleError(error, g.json);\n }\n });\n\n// ============================================================================\n// toc command - Table of contents extraction\n// ============================================================================\nprogram\n .command('toc <jobId>')\n .description('Extract table of contents from PDF')\n .option('--max-depth <n>', 'Maximum TOC depth', parseInt)\n .option('-f, --format <format>', 'Output format (text|json|markdown)', 'text')\n .option('--watch', 'Watch live extraction events via WebSocket')\n .action(async (jobId, options) => {\n const g = globals();\n try {\n const client = getClient();\n const fmt = g.json ? 'json' : options.format;\n const result = await toc(client, jobId, {\n maxDepth: options.maxDepth,\n watch: options.watch,\n });\n writeOutput(formatTocOutput(result, fmt), g.output);\n } catch (error) {\n handleError(error, g.json);\n }\n });\n\nprogram.parse();\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoBA,SAAS,eAAe;AAqCxB,IAAM,UAAU,IAAI,QAAQ;AAE5B,QACG,KAAK,MAAM,EACX,YAAY,iEAA4D,EACxE,QAAQ,OAAO,EACf,OAAO,cAAc,4CAA4C,EACjE,OAAO,eAAe,6CAA6C,EACnE,OAAO,uBAAuB,wCAAwC;AAGzE,SAAS,UAAuB;AAC9B,SAAO,QAAQ,KAAK;AACtB;AAMA,SAAS,YAAwB;AAC/B,QAAM,SAAS,UAAU;AACzB,QAAM,UAAU,WAAW;AAE3B,MAAI,CAAC,QAAQ;AACX,UAAM,IAAI,QAAQ;AAClB,QAAI,EAAE,MAAM;AACV,cAAQ,OAAO,MAAM,KAAK,UAAU,EAAE,OAAO,oBAAoB,MAAM,IAAI,CAAC,IAAI,IAAI;AAAA,IACtF,OAAO;AACL,cAAQ,OAAO;AAAA,QACb;AAAA,MAIF;AAAA,IACF;AACA,YAAQ,KAAK,CAAC;AAAA,EAChB;AAEA,SAAO,IAAI,WAAW,EAAE,QAAQ,QAAQ,CAAC;AAC3C;AAKA,QACG,QAAQ,iBAAiB,EACzB,YAAY,sDAAsD,EAClE,OAAO,aAAa,6CAA8C,EAClE,OAAO,OAAO,QAAQ,YAAY;AACjC,QAAM,IAAI,QAAQ;AAClB,MAAI;AACF,UAAM,SAAS,UAAU;AACzB,UAAM,SAAS,MAAM,OAAO,QAAQ,QAAQ;AAAA,MAC1C,GAAG;AAAA,MACH,QAAQ,QAAQ,SAAS;AAAA,IAC3B,CAAC;AAED,QAAI,EAAE,MAAM;AACV,kBAAY,KAAK,UAAU,MAAM,GAAG,EAAE,MAAM;AAAA,IAC9C,OAAO;AACL,YAAM,QAAQ,CAAC,eAA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M,MAAM,EAAE,OAAO,SAAS,QAAQ;AACtC,UAAM,SAAS,MAAM,QAAQ,QAAQ,OAAO,EAAE,OAAO,QAAQ,MAAM,CAAC;AACpE,gBAAY,oBAAoB,QAAQ,GAAG,GAAG,EAAE,MAAM;AAAA,EACxD,SAAS,OAAO;AACd,gBAAY,OAAO,EAAE,IAAI;AAAA,EAC3B;AACF,CAAC;AAKH,QACG,QAAQ,aAAa,EACrB,YAAY,oCAAoC,EAChD,OAAO,mBAAmB,qBAAqB,QAAQ,EACvD,OAAO,yBAAyB,sCAAsC,MAAM,EAC5E,OAAO,WAAW,4CAA4C,EAC9D,OAAO,OAAO,OAAO,YAAY;AAChC,QAAM,IAAI,QAAQ;AAClB,MAAI;AACF,UAAM,SAAS,UAAU;AACzB,UAAM,MAAM,EAAE,OAAO,SAAS,QAAQ;AACtC,UAAM,SAAS,MAAM,IAAI,QAAQ,OAAO;AAAA,MACtC,UAAU,QAAQ;AAAA,MAClB,OAAO,QAAQ;AAAA,IACjB,CAAC;AACD,gBAAY,gBAAgB,QAAQ,GAAG,GAAG,EAAE,MAAM;AAAA,EACpD,SAAS,OAAO;AACd,gBAAY,OAAO,EAAE,IAAI;AAAA,EAC3B;AACF,CAAC;AAEH,QAAQ,MAAM;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/cli/bin.ts"],"sourcesContent":["#!/usr/bin/env node\n/**\n * okra CLI — Agent-friendly PDF extraction and collection queries.\n *\n * Global flags:\n * -j, --json Structured JSON output\n * -q, --quiet Suppress progress (just data to stdout)\n * -o, --output Write output to file (CSV/JSON)\n *\n * Action commands (agent-grade):\n * okra upload <source> # Upload + wait\n * okra collection list # List collections\n * okra collection query <name> \"<question>\" # Fan-out → CSV\n *\n * Review commands (existing):\n * okra tree / find / page / search / tables / history / toc\n *\n * Exit codes: 0=success, 1=client error, 2=server error\n */\n\nimport { Command } from 'commander';\nimport { OkraClient } from '../client';\nimport {\n tree,\n formatTreeOutput,\n find,\n formatFindOutput,\n formatStats,\n pageGet,\n pageEdit,\n pageResolve,\n pageVersions,\n formatPageOutput,\n formatVersionsOutput,\n search,\n formatSearchOutput,\n tables,\n formatTablesOutput,\n history,\n formatHistoryOutput,\n toc,\n formatTocOutput,\n authLogin,\n authStatus,\n authLogout,\n upload,\n collectionList,\n collectionSetVisibility,\n collectionQueryRaw,\n formatCollectionList,\n formatCollectionCsv,\n formatCollectionTable,\n formatQueryJsonl,\n} from './commands';\nimport { getApiKey, getBaseUrl } from './config';\nimport { handleError, writeOutput, progress } from './output';\nimport type { GlobalFlags } from './output';\n\nconst program = new Command();\n\nprogram\n .name('okra')\n .description('OkraPDF CLI — upload PDFs, query collections, extract data')\n .version('0.9.0')\n .option('-j, --json', 'Output JSON (structured, machine-readable)')\n .option('-q, --quiet', 'Suppress progress and human-readable frills')\n .option('-o, --output <file>', 'Write output to file instead of stdout');\n\n/** Read global flags from program.opts(). */\nfunction globals(): GlobalFlags {\n return program.opts();\n}\n\n// Create client with proper config priority:\n// 1. Environment variable (OKRA_API_KEY)\n// 2. Project config (.okrarc, .okra.json)\n// 3. Global config (~/.okra/config.json)\nfunction getClient(): OkraClient {\n const apiKey = getApiKey();\n const baseUrl = getBaseUrl();\n\n if (!apiKey) {\n const g = globals();\n if (g.json) {\n process.stderr.write(JSON.stringify({ error: 'No API key found', code: 401 }) + '\\n');\n } else {\n process.stderr.write(\n 'No API key found.\\n\\n' +\n ' Get one: https://okrapdf.dev/api-keys\\n' +\n ' Then: export OKRA_API_KEY=\"okra_xxx\"\\n' +\n ' Or: npx okra auth login\\n\\n' +\n ' Docs: https://okrapdf.dev/docs\\n' +\n ' Discord: https://discord.gg/BHNmbZVs\\n',\n );\n }\n process.exit(1);\n }\n\n return new OkraClient({ apiKey, baseUrl });\n}\n\n// ============================================================================\n// upload command\n// ============================================================================\nprogram\n .command('upload <source>')\n .description('Upload a PDF (file path or URL), wait for processing')\n .option('--no-wait', 'Fire-and-forget (don\\'t wait for processing)')\n .action(async (source, options) => {\n const g = globals();\n try {\n const client = getClient();\n const result = await upload(client, source, {\n ...g,\n noWait: options.wait === false,\n });\n\n if (g.json) {\n writeOutput(JSON.stringify(result), g.output);\n } else {\n const lines = [`Done — ${result.pages ?? '?'} pages`, ''];\n lines.push(` ${result.id}`);\n if (result.urls) {\n const short = result.id.slice(0, 11) + '...';\n lines.push('');\n lines.push(` Markdown: ${result.urls.full_md.replace(result.id, short)}`);\n lines.push(` Page 1: ${result.urls.page_png.replace(result.id, short).replace('{N}', '1')}`);\n lines.push(` Completion: ${result.urls.completion.replace(result.id, short)}`);\n lines.push('');\n lines.push(' URL patterns:');\n lines.push(' /v1/documents/{id}/pg_{N}.md page markdown');\n lines.push(' /v1/documents/{id}/d_shimmer/pg_{N}.png page image');\n lines.push(' /v1/documents/{id}/full.md full document');\n lines.push('');\n lines.push(' Docs: https://okrapdf.dev/docs Discord: https://discord.gg/BHNmbZVs');\n }\n writeOutput(lines.join('\\n'), g.output);\n }\n } catch (error) {\n handleError(error, g.json);\n }\n });\n\n// ============================================================================\n// collection command\n// ============================================================================\nconst collectionCmd = program.command('collection').description('Collection operations');\n\ncollectionCmd\n .command('list')\n .description('List available collections')\n .action(async () => {\n const g = globals();\n try {\n const client = getClient();\n const rows = await collectionList(client, g);\n writeOutput(formatCollectionList(rows, g.json), g.output);\n } catch (error) {\n handleError(error, g.json);\n }\n });\n\ncollectionCmd\n .command('query <nameOrId> <question>')\n .description('Fan-out query across collection documents')\n .option('--schema <file>', 'JSON Schema file for structured extraction')\n .action(async (nameOrId, question, options) => {\n const g = globals();\n try {\n const apiKey = getApiKey();\n const baseUrl = getBaseUrl();\n if (!apiKey) {\n handleError(new Error('No API key found'), g.json);\n }\n\n const { results, summary } = await collectionQueryRaw(\n baseUrl!,\n apiKey!,\n nameOrId,\n question,\n { ...g, schema: options.schema },\n );\n\n // Determine output format based on flags\n if (g.json) {\n // --json: JSONL events to stdout\n writeOutput(formatQueryJsonl(results), g.output);\n } else if (g.output && g.output.endsWith('.csv')) {\n // -o file.csv → CSV\n writeOutput(formatCollectionCsv(results), g.output);\n } else if (g.output) {\n // -o file.json or other → JSON\n writeOutput(JSON.stringify({ results, summary }), g.output);\n } else {\n // Default: compact table to stdout\n writeOutput(formatCollectionTable(results));\n }\n\n progress(\n `${summary.completed} completed, ${summary.failed} failed — $${summary.total_cost_usd.toFixed(4)}`,\n g.quiet,\n );\n } catch (error) {\n handleError(error, g.json);\n }\n });\n\ncollectionCmd\n .command('publish <nameOrId>')\n .description('Make a collection publicly queryable')\n .action(async (nameOrId) => {\n const g = globals();\n try {\n const client = getClient();\n await collectionSetVisibility(client, nameOrId, 'public');\n if (g.json) {\n writeOutput(JSON.stringify({ ok: true, visibility: 'public', collection: nameOrId }), g.output);\n } else {\n writeOutput(\n `Published \"${nameOrId}\"\\n` +\n `Share with: okra collection query ${nameOrId} \"your question\"`,\n g.output,\n );\n }\n } catch (error) {\n handleError(error, g.json);\n }\n });\n\ncollectionCmd\n .command('unpublish <nameOrId>')\n .description('Make a collection private (owner-only)')\n .action(async (nameOrId) => {\n const g = globals();\n try {\n const client = getClient();\n await collectionSetVisibility(client, nameOrId, 'private');\n if (g.json) {\n writeOutput(JSON.stringify({ ok: true, visibility: 'private', collection: nameOrId }), g.output);\n } else {\n writeOutput(`Unpublished \"${nameOrId}\" — now private`, g.output);\n }\n } catch (error) {\n handleError(error, g.json);\n }\n });\n\n// ============================================================================\n// auth command - Authentication management\n// ============================================================================\nconst authCmd = program.command('auth').description('Manage authentication');\n\nauthCmd\n .command('login')\n .description('Save API key to global config')\n .action(async () => {\n try {\n await authLogin();\n } catch (error) {\n handleError(error, globals().json);\n }\n });\n\nauthCmd\n .command('status')\n .description('Show authentication status')\n .action(async () => {\n try {\n await authStatus();\n } catch (error) {\n handleError(error, globals().json);\n }\n });\n\nauthCmd\n .command('logout')\n .description('Remove API key from global config')\n .action(async () => {\n try {\n await authLogout();\n } catch (error) {\n handleError(error, globals().json);\n }\n });\n\n// ============================================================================\n// tree command - Document verification tree\n// ============================================================================\nprogram\n .command('tree <jobId>')\n .description('Show document verification tree')\n .option('-s, --status <status>', 'Filter by status (complete|partial|pending|flagged|empty|gap)')\n .option('-e, --entity <type>', 'Filter by entity type (table|figure|footnote)')\n .option('-f, --format <format>', 'Output format (text|json|markdown)', 'text')\n .action(async (jobId, options) => {\n const g = globals();\n try {\n const client = getClient();\n const fmt = g.json ? 'json' : options.format;\n const result = await tree(client, jobId, {\n status: options.status,\n entity: options.entity,\n });\n writeOutput(formatTreeOutput(result, fmt), g.output);\n } catch (error) {\n handleError(error, g.json);\n }\n });\n\n// ============================================================================\n// find command - jQuery-like entity search\n// ============================================================================\nprogram\n .command('find <jobId> <selector>')\n .description('Find entities using jQuery-like selectors')\n .option('-k, --top-k <n>', 'Limit results', parseInt)\n .option('-c, --min-confidence <n>', 'Minimum confidence (0-1)', parseFloat)\n .option('-p, --pages <range>', 'Page range (e.g., 1-10)')\n .option('--sort <by>', 'Sort by (confidence|page|type)')\n .option('--stats', 'Show aggregate statistics')\n .option('-f, --format <format>', 'Output format (text|json|entities|ids)', 'text')\n .action(async (jobId, selector, options) => {\n const g = globals();\n try {\n const client = getClient();\n const fmt = g.json ? 'json' : options.format;\n const pageRange = options.pages\n ? options.pages.split('-').map(Number) as [number, number]\n : undefined;\n\n const result = await find(client, jobId, selector, {\n topK: options.topK,\n minConfidence: options.minConfidence,\n pageRange,\n sortBy: options.sort,\n });\n\n if (options.stats && fmt === 'text') {\n writeOutput(formatStats(result.stats), g.output);\n } else {\n writeOutput(formatFindOutput(result, fmt, options.stats), g.output);\n }\n } catch (error) {\n handleError(error, g.json);\n }\n });\n\n// ============================================================================\n// page command - Page content operations\n// ============================================================================\nconst pageCmd = program.command('page').description('Page content operations');\n\npageCmd\n .command('get <jobId> <pageNum>')\n .description('Get page content')\n .option('-v, --version <n>', 'Specific version', parseInt)\n .option('-f, --format <format>', 'Output format (text|json|markdown)', 'markdown')\n .action(async (jobId, pageNum, options) => {\n const g = globals();\n try {\n const client = getClient();\n const fmt = g.json ? 'json' : options.format;\n const content = await pageGet(client, jobId, parseInt(pageNum), {\n version: options.version,\n });\n writeOutput(formatPageOutput(content, fmt), g.output);\n } catch (error) {\n handleError(error, g.json);\n }\n });\n\npageCmd\n .command('edit <jobId> <pageNum>')\n .description('Edit page content (reads from stdin)')\n .action(async (jobId, pageNum) => {\n const g = globals();\n try {\n const chunks: Buffer[] = [];\n for await (const chunk of process.stdin) {\n chunks.push(chunk);\n }\n const content = Buffer.concat(chunks).toString('utf8');\n\n const client = getClient();\n const result = await pageEdit(client, jobId, parseInt(pageNum), content);\n if (g.json) {\n writeOutput(JSON.stringify({ version: result.version }), g.output);\n } else {\n writeOutput(`Saved as version ${result.version}`, g.output);\n }\n } catch (error) {\n handleError(error, g.json);\n }\n });\n\npageCmd\n .command('resolve <jobId> <pageNum> <resolution>')\n .description('Resolve page verification status')\n .option('-c, --classification <class>', 'Classification')\n .option('-r, --reason <reason>', 'Reason')\n .action(async (jobId, pageNum, resolution, options) => {\n const g = globals();\n try {\n const client = getClient();\n const result = await pageResolve(client, jobId, parseInt(pageNum), {\n resolution,\n classification: options.classification,\n reason: options.reason,\n });\n if (g.json) {\n writeOutput(JSON.stringify({ success: result.success }), g.output);\n } else {\n writeOutput(result.success ? 'Resolved' : 'Failed', g.output);\n }\n } catch (error) {\n handleError(error, g.json);\n }\n });\n\npageCmd\n .command('versions <jobId> <pageNum>')\n .description('List page versions')\n .option('-f, --format <format>', 'Output format (text|json)', 'text')\n .action(async (jobId, pageNum, options) => {\n const g = globals();\n try {\n const client = getClient();\n const fmt = g.json ? 'json' : options.format;\n const versions = await pageVersions(client, jobId, parseInt(pageNum));\n writeOutput(formatVersionsOutput(versions, fmt), g.output);\n } catch (error) {\n handleError(error, g.json);\n }\n });\n\n// ============================================================================\n// search command - Full-text search\n// ============================================================================\nprogram\n .command('search <jobId> <query>')\n .description('Search page content')\n .option('-f, --format <format>', 'Output format (text|json)', 'text')\n .action(async (jobId, query, options) => {\n const g = globals();\n try {\n const client = getClient();\n const fmt = g.json ? 'json' : options.format;\n const result = await search(client, jobId, query);\n writeOutput(formatSearchOutput(result, fmt), g.output);\n } catch (error) {\n handleError(error, g.json);\n }\n });\n\n// ============================================================================\n// tables command - List tables\n// ============================================================================\nprogram\n .command('tables <jobId>')\n .description('List extracted tables')\n .option('-p, --page <n>', 'Filter by page', parseInt)\n .option('-s, --status <status>', 'Filter by status (pending|verified|flagged|rejected)')\n .option('-f, --format <format>', 'Output format (text|json|markdown)', 'text')\n .action(async (jobId, options) => {\n const g = globals();\n try {\n const client = getClient();\n const fmt = g.json ? 'json' : options.format;\n const result = await tables(client, jobId, {\n page: options.page,\n status: options.status,\n });\n writeOutput(formatTablesOutput(result, fmt), g.output);\n } catch (error) {\n handleError(error, g.json);\n }\n });\n\n// ============================================================================\n// history command - Verification audit trail\n// ============================================================================\nprogram\n .command('history <jobId>')\n .description('Show verification history')\n .option('-l, --limit <n>', 'Limit entries', parseInt, 50)\n .option('-f, --format <format>', 'Output format (text|json)', 'text')\n .action(async (jobId, options) => {\n const g = globals();\n try {\n const client = getClient();\n const fmt = g.json ? 'json' : options.format;\n const result = await history(client, jobId, { limit: options.limit });\n writeOutput(formatHistoryOutput(result, fmt), g.output);\n } catch (error) {\n handleError(error, g.json);\n }\n });\n\n// ============================================================================\n// toc command - Table of contents extraction\n// ============================================================================\nprogram\n .command('toc <jobId>')\n .description('Extract table of contents from PDF')\n .option('--max-depth <n>', 'Maximum TOC depth', parseInt)\n .option('-f, --format <format>', 'Output format (text|json|markdown)', 'text')\n .option('--watch', 'Watch live extraction events via WebSocket')\n .action(async (jobId, options) => {\n const g = globals();\n try {\n const client = getClient();\n const fmt = g.json ? 'json' : options.format;\n const result = await toc(client, jobId, {\n maxDepth: options.maxDepth,\n watch: options.watch,\n });\n writeOutput(formatTocOutput(result, fmt), g.output);\n } catch (error) {\n handleError(error, g.json);\n }\n });\n\nprogram.parse();\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;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I,QAAQ;AAClB,MAAI;AACF,UAAM,SAAS,UAAU;AACzB,UAAM,MAAM,EAAE,OAAO,SAAS,QAAQ;AACtC,UAAM,SAAS,MAAM,IAAI,QAAQ,OAAO;AAAA,MACtC,UAAU,QAAQ;AAAA,MAClB,OAAO,QAAQ;AAAA,IACjB,CAAC;AACD,gBAAY,gBAAgB,QAAQ,GAAG,GAAG,EAAE,MAAM;AAAA,EACpD,SAAS,OAAO;AACd,gBAAY,OAAO,EAAE,IAAI;AAAA,EAC3B;AACF,CAAC;AAEH,QAAQ,MAAM;","names":[]}
|
package/dist/cli/index.d.ts
CHANGED
package/dist/cli/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { b as UploadInput, S as SessionCreateOptions, O as OkraSession, c as SessionAttachOptions, C as CollectionSummary, d as Collection, e as OkraClientOptions, f as UploadOptions, g as DocumentStatus, W as WaitOptions, P as Page, E as EntitiesResponse, Q as QueryResult, h as CompletionOptions, i as CompletionEvent, G as GenerateOptions, j as GenerateResult, k as StructuredSchema, l as PublishResult, m as ShareLinkOptions, n as ShareLinkResult } from './types-DpLY63Cg.js';
|
|
2
2
|
|
|
3
3
|
declare class OkraClient {
|
|
4
4
|
private readonly baseUrl;
|
|
@@ -9,7 +9,13 @@ declare class OkraClient {
|
|
|
9
9
|
create: (sourceOrDocId: UploadInput, options?: SessionCreateOptions) => Promise<OkraSession>;
|
|
10
10
|
from: (documentId: string, options?: SessionAttachOptions) => OkraSession;
|
|
11
11
|
};
|
|
12
|
+
readonly collections: {
|
|
13
|
+
list: (signal?: AbortSignal) => Promise<CollectionSummary[]>;
|
|
14
|
+
get: (collectionId: string, signal?: AbortSignal) => Promise<Collection>;
|
|
15
|
+
};
|
|
12
16
|
constructor(options: OkraClientOptions);
|
|
17
|
+
private collectionList;
|
|
18
|
+
private collectionGet;
|
|
13
19
|
upload(input: UploadInput, options?: UploadOptions): Promise<OkraSession>;
|
|
14
20
|
status(documentId: string, signal?: AbortSignal): Promise<DocumentStatus>;
|
|
15
21
|
wait(documentId: string, options?: WaitOptions): Promise<DocumentStatus>;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { O as OkraClient } from './client-
|
|
2
|
-
import {
|
|
3
|
-
export {
|
|
1
|
+
import { O as OkraClient } from './client-CyA8BgrE.js';
|
|
2
|
+
import { e as OkraClientOptions, O as OkraSession, h as CompletionOptions, i as CompletionEvent, o as SessionState, g as DocumentStatus, W as WaitOptions, P as Page, E as EntitiesResponse, Q as QueryResult, l as PublishResult, m as ShareLinkOptions, n as ShareLinkResult, G as GenerateOptions, j as GenerateResult, k as StructuredSchema, R as RuntimeErrorCode, p as StructuredOutputErrorCode } from './types-DpLY63Cg.js';
|
|
3
|
+
export { d as Collection, q as CollectionDocument, r as CollectionQueryEvent, s as CollectionQueryOptions, t as CollectionQueryResult, u as CollectionQueryStream, C as CollectionSummary, D as DocUrlOptions, v as DocumentAnswer, w as Entity, J as JsonSchema, x as OkraCollections, y as PageBlock, z as PageEntity, c as SessionAttachOptions, S as SessionCreateOptions, A as ShareLinkCapabilities, B as ShareLinkLinks, F as StructuredOutputMeta, b as UploadInput, f as UploadOptions, H as UploadRedactOptions, I as UploadRedactPiiOptions, U as UrlBuilderOptions } from './types-DpLY63Cg.js';
|
|
4
4
|
export { doc } from './url.js';
|
|
5
5
|
import 'zod';
|
|
6
6
|
|
package/dist/index.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import {
|
|
2
2
|
doc
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-QKII53VN.js";
|
|
4
4
|
import {
|
|
5
5
|
createOkra,
|
|
6
6
|
withCache,
|
|
7
7
|
withQualityScore,
|
|
8
8
|
withSecret
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-Y72DLYYO.js";
|
|
10
10
|
import {
|
|
11
11
|
OkraClient
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-EZLAOKOP.js";
|
|
13
13
|
import {
|
|
14
14
|
OkraRuntimeError,
|
|
15
15
|
StructuredOutputError
|
package/dist/react/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
|
-
import { O as OkraClient } from '../client-
|
|
3
|
-
import { O as OkraSession,
|
|
4
|
-
export {
|
|
2
|
+
import { O as OkraClient } from '../client-CyA8BgrE.js';
|
|
3
|
+
import { O as OkraSession, g as DocumentStatus, P as Page, k as StructuredSchema, j as GenerateResult } from '../types-DpLY63Cg.js';
|
|
4
|
+
export { i as CompletionEvent } from '../types-DpLY63Cg.js';
|
|
5
5
|
import 'zod';
|
|
6
6
|
|
|
7
7
|
interface OkraContextValue {
|