@base44-preview/sdk 0.8.52-pr.297.c6f2448 → 0.8.52-pr.297.e5cedd8
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/modules/ai-gateway.types.d.ts +22 -57
- package/package.json +5 -23
|
@@ -51,15 +51,15 @@ export interface AiGatewayModuleConfig {
|
|
|
51
51
|
* against the provider directly, no separate account, API key, or billing
|
|
52
52
|
* setup with the underlying model provider required.
|
|
53
53
|
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
*
|
|
54
|
+
* `connection()` takes an optional `provider`, and each provider serves a different API:
|
|
55
|
+
*
|
|
56
|
+
* - `openai` (default): OpenAI-compatible chat completions and image endpoints.
|
|
57
|
+
* - `typesafe`: structured evaluations with the `jev` model.
|
|
57
58
|
*
|
|
58
59
|
* Call `connection()` from a backend function rather than the browser. This
|
|
59
60
|
* keeps your instructions, tools, and business logic server-side, and lets
|
|
60
|
-
* you enforce your own auth, rate, and spend limits around the call.
|
|
61
|
-
*
|
|
62
|
-
* used for every other SDK call.
|
|
61
|
+
* you enforce your own auth, rate, and spend limits around the call. Which
|
|
62
|
+
* token it returns depends on the authentication mode, described below.
|
|
63
63
|
*
|
|
64
64
|
* ## OpenAI-compatible models
|
|
65
65
|
*
|
|
@@ -76,33 +76,23 @@ export interface AiGatewayModuleConfig {
|
|
|
76
76
|
* `'gemini_3_1_flash_image'` or `'gpt_image_2'`. For request options, the
|
|
77
77
|
* full model list, and limits, see [Generate images with the AI Gateway](/developers/references/sdk/getting-started/ai-gateway-images).
|
|
78
78
|
*
|
|
79
|
-
* ## Videos
|
|
80
|
-
*
|
|
81
|
-
* The gateway serves OpenAI's asynchronous video endpoints through the
|
|
82
|
-
* `openai` SDK's `videos` client. `videos.create()` starts a job and returns
|
|
83
|
-
* its `id` right away; call `videos.retrieve(id)` until `status` is
|
|
84
|
-
* `completed` or `failed`. A completed job exposes the stored video at `url`.
|
|
85
|
-
* A backend function is a bounded HTTP call, so don't poll inside one: return
|
|
86
|
-
* the `id`, then retrieve it from a later call or scheduled run. Video
|
|
87
|
-
* requests need a specific model, such as `'veo_3_1_fast'` or
|
|
88
|
-
* `'seedance_2_fast'`; there's no `'automatic'` option.
|
|
89
|
-
*
|
|
90
79
|
* ## Structured evaluations
|
|
91
80
|
*
|
|
92
81
|
* The `typesafe` provider runs the `jev` evaluation model through
|
|
93
|
-
* `@ai-sdk/typesafe-ai` and the `ai` package
|
|
94
|
-
*
|
|
95
|
-
* `
|
|
96
|
-
*
|
|
97
|
-
*
|
|
82
|
+
* `@ai-sdk/typesafe-ai` and `experimental_evaluate` from the `ai` package,
|
|
83
|
+
* version 7.0.105 or later. Pass `evaluationModel("jev")`; the gateway rejects
|
|
84
|
+
* other model IDs, such as `"jev-latest"`. Give it some app state and a set of
|
|
85
|
+
* questions, each a `choice`, `score`, or `boolean`. Choice and score answers
|
|
86
|
+
* come back with `probabilities` per option; boolean answers with a single
|
|
87
|
+
* `probability` of `true`. Use it to classify, score, or route records, then
|
|
88
|
+
* apply your own thresholds and actions in code.
|
|
98
89
|
*
|
|
99
90
|
* ## Authentication Modes
|
|
100
91
|
*
|
|
101
|
-
*
|
|
102
|
-
* token `connection()` returns:
|
|
92
|
+
* The mode determines which token `connection()` returns:
|
|
103
93
|
*
|
|
104
94
|
* - **User authentication** (`base44.aiGateway`): Returns the signed-in app user's token.
|
|
105
|
-
* - **Service role authentication** (`base44.asServiceRole.aiGateway`): Returns the service-role token instead, for
|
|
95
|
+
* - **Service role authentication** (`base44.asServiceRole.aiGateway`): Returns the service-role token instead. Use it from backend functions: apps that restrict Core integrations, the default for new apps, reject user-token gateway calls on public apps. It also works when there's no signed-in user, such as from a scheduled automation.
|
|
106
96
|
*
|
|
107
97
|
* ## Billing and limits
|
|
108
98
|
*
|
|
@@ -131,7 +121,7 @@ export interface AiGatewayModule {
|
|
|
131
121
|
*
|
|
132
122
|
* // Runs inside a backend function
|
|
133
123
|
* const base44 = createClientFromRequest(request);
|
|
134
|
-
* const { baseURL, token, headers } = base44.aiGateway.connection();
|
|
124
|
+
* const { baseURL, token, headers } = base44.asServiceRole.aiGateway.connection();
|
|
135
125
|
* const openai = new OpenAI({ baseURL, apiKey: token, defaultHeaders: headers });
|
|
136
126
|
*
|
|
137
127
|
* const response = await openai.chat.completions.create({
|
|
@@ -153,7 +143,7 @@ export interface AiGatewayModule {
|
|
|
153
143
|
* // Runs inside a backend function, reviewing a return request
|
|
154
144
|
* const base44 = createClientFromRequest(request);
|
|
155
145
|
* const returnRequest = await base44.entities.ReturnRequest.get(returnId);
|
|
156
|
-
* const { baseURL, token, headers } = base44.aiGateway.connection();
|
|
146
|
+
* const { baseURL, token, headers } = base44.asServiceRole.aiGateway.connection();
|
|
157
147
|
* // Point any OpenAI-compatible client at `baseURL` with `apiKey: token` and `headers`.
|
|
158
148
|
* const models = createOpenAICompatible({ name: "base44", baseURL, apiKey: token, headers });
|
|
159
149
|
*
|
|
@@ -194,7 +184,7 @@ export interface AiGatewayModule {
|
|
|
194
184
|
*
|
|
195
185
|
* // Runs inside a backend function
|
|
196
186
|
* const base44 = createClientFromRequest(request);
|
|
197
|
-
* const { baseURL, token, headers } = base44.aiGateway.connection();
|
|
187
|
+
* const { baseURL, token, headers } = base44.asServiceRole.aiGateway.connection();
|
|
198
188
|
* const models = createOpenAICompatible({ name: "base44", baseURL, apiKey: token, headers });
|
|
199
189
|
*
|
|
200
190
|
* const { image } = await generateImage({
|
|
@@ -210,32 +200,6 @@ export interface AiGatewayModule {
|
|
|
210
200
|
*
|
|
211
201
|
* @example
|
|
212
202
|
* ```typescript
|
|
213
|
-
* // Start a video job, then check on it from a later call
|
|
214
|
-
* import { createClientFromRequest } from "@base44/sdk";
|
|
215
|
-
* import OpenAI from "openai";
|
|
216
|
-
*
|
|
217
|
-
* // Runs inside a backend function
|
|
218
|
-
* const base44 = createClientFromRequest(request);
|
|
219
|
-
* const { baseURL, token, headers } = base44.aiGateway.connection();
|
|
220
|
-
* const { videos } = new OpenAI({ baseURL, apiKey: token, defaultHeaders: headers });
|
|
221
|
-
*
|
|
222
|
-
* const { videoId } = await request.json();
|
|
223
|
-
* if (!videoId) {
|
|
224
|
-
* // Avoid automatic replays of billed requests
|
|
225
|
-
* const job = await videos.create(
|
|
226
|
-
* { model: "veo_3_1_fast", prompt: "A paper boat drifting down a rainy street", seconds: "4" },
|
|
227
|
-
* { maxRetries: 0 },
|
|
228
|
-
* );
|
|
229
|
-
* return Response.json({ videoId: job.id, status: job.status }, { status: 202 });
|
|
230
|
-
* }
|
|
231
|
-
*
|
|
232
|
-
* const video = await videos.retrieve(videoId);
|
|
233
|
-
* // `queued` and `in_progress` mean unfinished; `url` is set once `completed`
|
|
234
|
-
* return Response.json(video);
|
|
235
|
-
* ```
|
|
236
|
-
*
|
|
237
|
-
* @example
|
|
238
|
-
* ```typescript
|
|
239
203
|
* // Route a support ticket with a structured evaluation
|
|
240
204
|
* import { createClientFromRequest } from "@base44/sdk";
|
|
241
205
|
* import { experimental_evaluate as evaluate } from "ai";
|
|
@@ -243,12 +207,12 @@ export interface AiGatewayModule {
|
|
|
243
207
|
*
|
|
244
208
|
* // Runs inside a backend function
|
|
245
209
|
* const base44 = createClientFromRequest(request);
|
|
246
|
-
* const { baseURL, token, headers } = base44.aiGateway.connection({ provider: "typesafe" });
|
|
210
|
+
* const { baseURL, token, headers } = base44.asServiceRole.aiGateway.connection({ provider: "typesafe" });
|
|
247
211
|
* const typesafe = createTypeSafeAi({ baseURL, apiKey: token, headers });
|
|
248
212
|
*
|
|
249
|
-
* const { answers } = await evaluate({
|
|
213
|
+
* const { answers, providerMetadata } = await evaluate({
|
|
250
214
|
* model: typesafe.evaluationModel("jev"),
|
|
251
|
-
* maxRetries: 0,
|
|
215
|
+
* maxRetries: 0, // Avoid automatic replays of billed requests
|
|
252
216
|
* state: { message: "Please refund today's duplicate charge." },
|
|
253
217
|
* questions: {
|
|
254
218
|
* department: {
|
|
@@ -268,6 +232,7 @@ export interface AiGatewayModule {
|
|
|
268
232
|
* // answers.department → { type: "choice", choice: "billing", probabilities: { billing: 0.97, support: 0.03 } }
|
|
269
233
|
* // answers.urgency → { type: "score", score: 1.2, probabilities: { 0: 0.1, 1: 0.6, 2: 0.3 } }
|
|
270
234
|
* // answers.refund → { type: "boolean", probability: 0.99 }
|
|
235
|
+
* // Choice and score confidence is in providerMetadata.typesafe.confidence
|
|
271
236
|
* // Pick your own thresholds and act on them in code
|
|
272
237
|
* const autoRefund = answers.department.choice === "billing" && answers.refund.probability > 0.9;
|
|
273
238
|
* ```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@base44-preview/sdk",
|
|
3
|
-
"version": "0.8.52-pr.297.
|
|
3
|
+
"version": "0.8.52-pr.297.e5cedd8",
|
|
4
4
|
"description": "JavaScript SDK for Base44 API",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -10,7 +10,6 @@
|
|
|
10
10
|
],
|
|
11
11
|
"scripts": {
|
|
12
12
|
"build": "tsc",
|
|
13
|
-
"lint": "eslint src",
|
|
14
13
|
"test": "npm run test:types && vitest run",
|
|
15
14
|
"test:types": "tsc --noEmit -p tsconfig.type-tests.json",
|
|
16
15
|
"test:unit": "vitest run tests/unit",
|
|
@@ -26,29 +25,11 @@
|
|
|
26
25
|
"create-docs:process": "node scripts/mintlify-post-processing/file-processing/file-processing.js"
|
|
27
26
|
},
|
|
28
27
|
"dependencies": {
|
|
29
|
-
"axios": "^1.
|
|
28
|
+
"axios": "^1.20.0",
|
|
30
29
|
"partysocket": "^0.0.23",
|
|
31
30
|
"socket.io-client": "^4.8.3",
|
|
32
31
|
"uuid": "^13.0.2"
|
|
33
32
|
},
|
|
34
|
-
"devDependencies": {
|
|
35
|
-
"@types/hast": "^3.0.4",
|
|
36
|
-
"@types/node": "^25.0.1",
|
|
37
|
-
"@types/unist": "^3.0.3",
|
|
38
|
-
"@typescript-eslint/parser": "^8.51.0",
|
|
39
|
-
"@vitest/coverage-istanbul": "^4.1.9",
|
|
40
|
-
"@vitest/coverage-v8": "^4.1.9",
|
|
41
|
-
"@vitest/ui": "^4.1.9",
|
|
42
|
-
"dotenv": "^16.3.1",
|
|
43
|
-
"eslint": "^9.39.2",
|
|
44
|
-
"eslint-plugin-import": "^2.32.0",
|
|
45
|
-
"nock": "^13.4.0",
|
|
46
|
-
"typedoc": "^0.28.14",
|
|
47
|
-
"typedoc-plugin-markdown": "^4.9.0",
|
|
48
|
-
"typescript": "^5.3.2",
|
|
49
|
-
"typescript-eslint": "^8.51.0",
|
|
50
|
-
"vitest": "^4.1.9"
|
|
51
|
-
},
|
|
52
33
|
"keywords": [
|
|
53
34
|
"base44",
|
|
54
35
|
"api",
|
|
@@ -58,10 +39,11 @@
|
|
|
58
39
|
"license": "MIT",
|
|
59
40
|
"repository": {
|
|
60
41
|
"type": "git",
|
|
61
|
-
"url": "git+https://github.com/base44/javascript-sdk.git"
|
|
42
|
+
"url": "git+https://github.com/base44/javascript-sdk.git",
|
|
43
|
+
"directory": "packages/sdk"
|
|
62
44
|
},
|
|
63
45
|
"bugs": {
|
|
64
46
|
"url": "https://github.com/base44/javascript-sdk/issues"
|
|
65
47
|
},
|
|
66
|
-
"homepage": "https://github.com/base44/javascript-sdk#readme"
|
|
48
|
+
"homepage": "https://github.com/base44/javascript-sdk/tree/main/packages/sdk#readme"
|
|
67
49
|
}
|