@okrapdf/ai-sdk 0.1.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/index.d.ts +72 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +42 -0
- package/dist/index.js.map +1 -0
- package/package.json +57 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { createOpenAICompatible, type OpenAICompatibleProviderSettings } from "@ai-sdk/openai-compatible";
|
|
2
|
+
export interface OkraProviderSettings {
|
|
3
|
+
/**
|
|
4
|
+
* OkraPDF API key. Defaults to `OKRA_API_KEY` env var.
|
|
5
|
+
*/
|
|
6
|
+
apiKey?: string;
|
|
7
|
+
/**
|
|
8
|
+
* Base URL for the OkraPDF API.
|
|
9
|
+
* @default "https://api.okrapdf.com"
|
|
10
|
+
*/
|
|
11
|
+
baseURL?: string;
|
|
12
|
+
/**
|
|
13
|
+
* Custom headers to include in every request.
|
|
14
|
+
*/
|
|
15
|
+
headers?: Record<string, string>;
|
|
16
|
+
/**
|
|
17
|
+
* Custom fetch implementation.
|
|
18
|
+
*/
|
|
19
|
+
fetch?: OpenAICompatibleProviderSettings["fetch"];
|
|
20
|
+
}
|
|
21
|
+
export interface OkraProvider {
|
|
22
|
+
/**
|
|
23
|
+
* Create an AI SDK language model for a document.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```ts
|
|
27
|
+
* const okra = createOkra({ apiKey: "okra_..." });
|
|
28
|
+
* const model = okra("doc-abc123");
|
|
29
|
+
* const { text } = await generateText({ model, prompt: "Summarize this" });
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
(documentId: string, model?: string): ReturnType<ReturnType<typeof createOpenAICompatible>>;
|
|
33
|
+
/**
|
|
34
|
+
* Create a model from an OkraPDF session handle.
|
|
35
|
+
* Works with any object that has a `modelEndpoint` and `id` property
|
|
36
|
+
* (i.e. the return value of `okra.sessions.create()` or `okra.sessions.from()`).
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```ts
|
|
40
|
+
* const rt = createOkra({ apiKey }); // from @okrapdf/runtime
|
|
41
|
+
* const session = await rt.sessions.create(file);
|
|
42
|
+
*
|
|
43
|
+
* const okra = createOkra({ apiKey }); // from @okrapdf/ai-sdk
|
|
44
|
+
* const model = okra.fromSession(session);
|
|
45
|
+
* const { text } = await generateText({ model, prompt: "Summarize" });
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
fromSession(session: {
|
|
49
|
+
id: string;
|
|
50
|
+
modelEndpoint: string;
|
|
51
|
+
}): ReturnType<ReturnType<typeof createOpenAICompatible>>;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Create an OkraPDF provider for the Vercel AI SDK.
|
|
55
|
+
*
|
|
56
|
+
* Each document in OkraPDF exposes an OpenAI-compatible endpoint.
|
|
57
|
+
* This provider maps document IDs to AI SDK language models.
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* ```ts
|
|
61
|
+
* import { createOkra } from "@okrapdf/ai-sdk";
|
|
62
|
+
* import { streamText } from "ai";
|
|
63
|
+
*
|
|
64
|
+
* const okra = createOkra({ apiKey: process.env.OKRA_API_KEY });
|
|
65
|
+
* const result = streamText({
|
|
66
|
+
* model: okra("doc-abc123"),
|
|
67
|
+
* messages: [{ role: "user", content: "What is the revenue?" }],
|
|
68
|
+
* });
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
export declare function createOkra(settings?: OkraProviderSettings): OkraProvider;
|
|
72
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,sBAAsB,EACtB,KAAK,gCAAgC,EACtC,MAAM,2BAA2B,CAAC;AAInC,MAAM,WAAW,oBAAoB;IACnC;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAEjC;;OAEG;IACH,KAAK,CAAC,EAAE,gCAAgC,CAAC,OAAO,CAAC,CAAC;CACnD;AAED,MAAM,WAAW,YAAY;IAC3B;;;;;;;;;OASG;IACH,CAAC,UAAU,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,UAAU,CAC9C,UAAU,CAAC,OAAO,sBAAsB,CAAC,CAC1C,CAAC;IAEF;;;;;;;;;;;;;;OAcG;IACH,WAAW,CAAC,OAAO,EAAE;QACnB,EAAE,EAAE,MAAM,CAAC;QACX,aAAa,EAAE,MAAM,CAAC;KACvB,GAAG,UAAU,CAAC,UAAU,CAAC,OAAO,sBAAsB,CAAC,CAAC,CAAC;CAC3D;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,UAAU,CAAC,QAAQ,GAAE,oBAAyB,GAAG,YAAY,CA4B5E"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { createOpenAICompatible, } from "@ai-sdk/openai-compatible";
|
|
2
|
+
const DEFAULT_BASE_URL = "https://api.okrapdf.com";
|
|
3
|
+
/**
|
|
4
|
+
* Create an OkraPDF provider for the Vercel AI SDK.
|
|
5
|
+
*
|
|
6
|
+
* Each document in OkraPDF exposes an OpenAI-compatible endpoint.
|
|
7
|
+
* This provider maps document IDs to AI SDK language models.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* import { createOkra } from "@okrapdf/ai-sdk";
|
|
12
|
+
* import { streamText } from "ai";
|
|
13
|
+
*
|
|
14
|
+
* const okra = createOkra({ apiKey: process.env.OKRA_API_KEY });
|
|
15
|
+
* const result = streamText({
|
|
16
|
+
* model: okra("doc-abc123"),
|
|
17
|
+
* messages: [{ role: "user", content: "What is the revenue?" }],
|
|
18
|
+
* });
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export function createOkra(settings = {}) {
|
|
22
|
+
const apiKey = settings.apiKey ?? globalThis.process?.env?.OKRA_API_KEY;
|
|
23
|
+
const base = (settings.baseURL ?? DEFAULT_BASE_URL).replace(/\/+$/, "");
|
|
24
|
+
function forEndpoint(endpoint, model = "default") {
|
|
25
|
+
const provider = createOpenAICompatible({
|
|
26
|
+
name: "okrapdf",
|
|
27
|
+
baseURL: endpoint,
|
|
28
|
+
apiKey,
|
|
29
|
+
headers: settings.headers,
|
|
30
|
+
fetch: settings.fetch,
|
|
31
|
+
});
|
|
32
|
+
return provider(model);
|
|
33
|
+
}
|
|
34
|
+
const provider = ((documentId, model) => {
|
|
35
|
+
return forEndpoint(`${base}/v1/documents/${encodeURIComponent(documentId)}`, model);
|
|
36
|
+
});
|
|
37
|
+
provider.fromSession = (session) => {
|
|
38
|
+
return forEndpoint(session.modelEndpoint);
|
|
39
|
+
};
|
|
40
|
+
return provider;
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,sBAAsB,GAEvB,MAAM,2BAA2B,CAAC;AAEnC,MAAM,gBAAgB,GAAG,yBAAyB,CAAC;AA6DnD;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,UAAU,CAAC,WAAiC,EAAE;IAC5D,MAAM,MAAM,GACV,QAAQ,CAAC,MAAM,IAAI,UAAU,CAAC,OAAO,EAAE,GAAG,EAAE,YAAY,CAAC;IAC3D,MAAM,IAAI,GAAG,CAAC,QAAQ,CAAC,OAAO,IAAI,gBAAgB,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;IAExE,SAAS,WAAW,CAAC,QAAgB,EAAE,QAAgB,SAAS;QAC9D,MAAM,QAAQ,GAAG,sBAAsB,CAAC;YACtC,IAAI,EAAE,SAAS;YACf,OAAO,EAAE,QAAQ;YACjB,MAAM;YACN,OAAO,EAAE,QAAQ,CAAC,OAAO;YACzB,KAAK,EAAE,QAAQ,CAAC,KAAK;SACtB,CAAC,CAAC;QACH,OAAO,QAAQ,CAAC,KAAK,CAAC,CAAC;IACzB,CAAC;IAED,MAAM,QAAQ,GAAG,CAAC,CAAC,UAAkB,EAAE,KAAc,EAAE,EAAE;QACvD,OAAO,WAAW,CAChB,GAAG,IAAI,iBAAiB,kBAAkB,CAAC,UAAU,CAAC,EAAE,EACxD,KAAK,CACN,CAAC;IACJ,CAAC,CAAiB,CAAC;IAEnB,QAAQ,CAAC,WAAW,GAAG,CAAC,OAAO,EAAE,EAAE;QACjC,OAAO,WAAW,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC;IAC5C,CAAC,CAAC;IAEF,OAAO,QAAQ,CAAC;AAClB,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@okrapdf/ai-sdk",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Vercel AI SDK provider for OkraPDF — use any document as an AI model",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"publishConfig": {
|
|
15
|
+
"access": "public"
|
|
16
|
+
},
|
|
17
|
+
"scripts": {
|
|
18
|
+
"build": "tsc",
|
|
19
|
+
"test": "vitest run",
|
|
20
|
+
"test:watch": "vitest"
|
|
21
|
+
},
|
|
22
|
+
"keywords": [
|
|
23
|
+
"okrapdf",
|
|
24
|
+
"ai-sdk",
|
|
25
|
+
"vercel",
|
|
26
|
+
"pdf",
|
|
27
|
+
"document",
|
|
28
|
+
"openai-compatible",
|
|
29
|
+
"language-model"
|
|
30
|
+
],
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"@ai-sdk/openai-compatible": "^2.0.30"
|
|
33
|
+
},
|
|
34
|
+
"peerDependencies": {
|
|
35
|
+
"ai": "^6.0.0"
|
|
36
|
+
},
|
|
37
|
+
"peerDependenciesMeta": {
|
|
38
|
+
"ai": {
|
|
39
|
+
"optional": true
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"@types/node": "^20.14.0",
|
|
44
|
+
"ai": "^6.0.0",
|
|
45
|
+
"typescript": "^5.5.0",
|
|
46
|
+
"vitest": "^2.0.0"
|
|
47
|
+
},
|
|
48
|
+
"files": [
|
|
49
|
+
"dist",
|
|
50
|
+
"README.md"
|
|
51
|
+
],
|
|
52
|
+
"repository": {
|
|
53
|
+
"type": "git",
|
|
54
|
+
"url": "https://github.com/steventsao/okrapdf",
|
|
55
|
+
"directory": "packages/ai-sdk"
|
|
56
|
+
}
|
|
57
|
+
}
|