@base44-preview/sdk 0.8.52-pr.304.d2a318a → 0.8.52-pr.305.970f972
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 +111 -14
- package/package.json +4 -22
|
@@ -42,7 +42,7 @@ export interface AiGatewayModuleConfig {
|
|
|
42
42
|
/**
|
|
43
43
|
* AI Gateway module for calling Base44's managed AI models from your own code.
|
|
44
44
|
*
|
|
45
|
-
* `connection()`
|
|
45
|
+
* Call `connection()` to get a `baseURL`, `token`, and `headers` that
|
|
46
46
|
* authenticate as your Base44 app. An OpenAI-compatible client is any library, such as the `openai`
|
|
47
47
|
* SDK or the Vercel AI SDK, that has the same request and response format
|
|
48
48
|
* as OpenAI's API and lets you point it at a custom `baseURL`
|
|
@@ -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
|
+
* The optional `provider` picks the API you connect to:
|
|
55
|
+
*
|
|
56
|
+
* - `openai` (default): OpenAI-compatible chat completions, image, and video 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
|
*
|
|
@@ -71,18 +71,52 @@ export interface AiGatewayModuleConfig {
|
|
|
71
71
|
*
|
|
72
72
|
* The gateway also serves OpenAI's image endpoints, `/images/generations`
|
|
73
73
|
* and `/images/edits`, so you can generate images and edit them using
|
|
74
|
-
* reference images. Image requests use their own set of models
|
|
74
|
+
* reference images. Image requests use their own set of models. Pass
|
|
75
75
|
* `'automatic'` to let Base44 choose one, or pin a model such as
|
|
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
|
+
* ## Video
|
|
80
|
+
*
|
|
81
|
+
* The gateway also serves OpenAI's video endpoints, `/videos`, so you can
|
|
82
|
+
* generate video from a prompt, from a still image, or from existing media.
|
|
83
|
+
* Video generation is asynchronous. `POST /videos` returns a job, and you poll
|
|
84
|
+
* `GET /videos/{id}` until its status is `completed` or `failed`, which can
|
|
85
|
+
* take minutes. Video models are their own set, and there's no `automatic`
|
|
86
|
+
* option, so pin a model such as `'veo_3_1_fast'` or `'seedance_2'`. For
|
|
87
|
+
* request options, the full model list, and limits, see
|
|
88
|
+
* [Generate video with the AI Gateway](/developers/references/sdk/getting-started/ai-gateway-video).
|
|
89
|
+
*
|
|
90
|
+
* ## Structured evaluations
|
|
91
|
+
*
|
|
92
|
+
* The `typesafe` provider runs the `jev` evaluation model through
|
|
93
|
+
* `@ai-sdk/typesafe-ai` and `experimental_evaluate` from the `ai` package,
|
|
94
|
+
* version 7.0.105 or later. Pass `evaluationModel("jev")`, and note that the
|
|
95
|
+
* gateway rejects other model IDs, such as `"jev-latest"`. Give it some app
|
|
96
|
+
* state and a set of questions, each a `choice`, `score`, or `boolean`. Choice
|
|
97
|
+
* and score answers come back with `probabilities` per option, and boolean
|
|
98
|
+
* answers with a single `probability` of `true`. Use it to classify, score, or
|
|
99
|
+
* route records, then apply your own thresholds and actions in code.
|
|
100
|
+
*
|
|
79
101
|
* ## Authentication Modes
|
|
80
102
|
*
|
|
81
|
-
*
|
|
82
|
-
* token `connection()` returns:
|
|
103
|
+
* The mode determines which token `connection()` returns:
|
|
83
104
|
*
|
|
84
105
|
* - **User authentication** (`base44.aiGateway`): Returns the signed-in app user's token.
|
|
85
|
-
* - **Service role authentication** (`base44.asServiceRole.aiGateway`): Returns the service-role token instead
|
|
106
|
+
* - **Service role authentication** (`base44.asServiceRole.aiGateway`): Returns the service-role token instead.
|
|
107
|
+
*
|
|
108
|
+
* Use service role, as every example here does. An app that restricts Core
|
|
109
|
+
* integrations rejects user-token gateway calls unless it's shared privately
|
|
110
|
+
* or with your workspace, and most new apps have that restriction on from the
|
|
111
|
+
* start. A user-token call therefore works while you're building and starts
|
|
112
|
+
* failing the moment you share the app publicly. Service role also works when
|
|
113
|
+
* there's no signed-in user at all, such as from a scheduled automation.
|
|
114
|
+
*
|
|
115
|
+
* The mode changes which token you get and nothing else. It grants the model
|
|
116
|
+
* no extra reach, because the gateway runs a model and never touches your
|
|
117
|
+
* data. Access to your app's data comes from the `base44.entities` calls you
|
|
118
|
+
* write around the gateway call, so pick the mode for those on their own
|
|
119
|
+
* merits rather than matching this one.
|
|
86
120
|
*
|
|
87
121
|
* ## Billing and limits
|
|
88
122
|
*
|
|
@@ -111,7 +145,7 @@ export interface AiGatewayModule {
|
|
|
111
145
|
*
|
|
112
146
|
* // Runs inside a backend function
|
|
113
147
|
* const base44 = createClientFromRequest(request);
|
|
114
|
-
* const { baseURL, token, headers } = base44.aiGateway.connection();
|
|
148
|
+
* const { baseURL, token, headers } = base44.asServiceRole.aiGateway.connection();
|
|
115
149
|
* const openai = new OpenAI({ baseURL, apiKey: token, defaultHeaders: headers });
|
|
116
150
|
*
|
|
117
151
|
* const response = await openai.chat.completions.create({
|
|
@@ -133,7 +167,7 @@ export interface AiGatewayModule {
|
|
|
133
167
|
* // Runs inside a backend function, reviewing a return request
|
|
134
168
|
* const base44 = createClientFromRequest(request);
|
|
135
169
|
* const returnRequest = await base44.entities.ReturnRequest.get(returnId);
|
|
136
|
-
* const { baseURL, token, headers } = base44.aiGateway.connection();
|
|
170
|
+
* const { baseURL, token, headers } = base44.asServiceRole.aiGateway.connection();
|
|
137
171
|
* // Point any OpenAI-compatible client at `baseURL` with `apiKey: token` and `headers`.
|
|
138
172
|
* const models = createOpenAICompatible({ name: "base44", baseURL, apiKey: token, headers });
|
|
139
173
|
*
|
|
@@ -174,7 +208,7 @@ export interface AiGatewayModule {
|
|
|
174
208
|
*
|
|
175
209
|
* // Runs inside a backend function
|
|
176
210
|
* const base44 = createClientFromRequest(request);
|
|
177
|
-
* const { baseURL, token, headers } = base44.aiGateway.connection();
|
|
211
|
+
* const { baseURL, token, headers } = base44.asServiceRole.aiGateway.connection();
|
|
178
212
|
* const models = createOpenAICompatible({ name: "base44", baseURL, apiKey: token, headers });
|
|
179
213
|
*
|
|
180
214
|
* const { image } = await generateImage({
|
|
@@ -187,6 +221,69 @@ export interface AiGatewayModule {
|
|
|
187
221
|
* const file = new File([image.uint8Array], "lighthouse.png", { type: image.mediaType });
|
|
188
222
|
* const { file_url } = await base44.integrations.Core.UploadFile({ file });
|
|
189
223
|
* ```
|
|
224
|
+
*
|
|
225
|
+
* @example
|
|
226
|
+
* ```typescript
|
|
227
|
+
* // Start a video and record the job to poll later
|
|
228
|
+
* import { createClientFromRequest } from "@base44/sdk";
|
|
229
|
+
*
|
|
230
|
+
* // Runs inside a backend function
|
|
231
|
+
* const base44 = createClientFromRequest(request);
|
|
232
|
+
* const { baseURL, token, headers } = base44.asServiceRole.aiGateway.connection();
|
|
233
|
+
*
|
|
234
|
+
* const response = await fetch(`${baseURL}/videos`, {
|
|
235
|
+
* method: "POST",
|
|
236
|
+
* headers: { ...headers, Authorization: `Bearer ${token}`, "Content-Type": "application/json" },
|
|
237
|
+
* body: JSON.stringify({
|
|
238
|
+
* model: "veo_3_1_fast",
|
|
239
|
+
* prompt: "A lighthouse beam sweeping across a calm sea at dawn",
|
|
240
|
+
* seconds: 8,
|
|
241
|
+
* }),
|
|
242
|
+
* });
|
|
243
|
+
*
|
|
244
|
+
* // Video generation takes minutes, so store the id and poll it from a later request
|
|
245
|
+
* const { id } = await response.json();
|
|
246
|
+
* await base44.asServiceRole.entities.Clip.update(clipId, { video_id: id });
|
|
247
|
+
* ```
|
|
248
|
+
*
|
|
249
|
+
* @example
|
|
250
|
+
* ```typescript
|
|
251
|
+
* // Route a support ticket with a structured evaluation
|
|
252
|
+
* import { createClientFromRequest } from "@base44/sdk";
|
|
253
|
+
* import { experimental_evaluate as evaluate } from "ai";
|
|
254
|
+
* import { createTypeSafeAi } from "@ai-sdk/typesafe-ai";
|
|
255
|
+
*
|
|
256
|
+
* // Runs inside a backend function
|
|
257
|
+
* const base44 = createClientFromRequest(request);
|
|
258
|
+
* const { baseURL, token, headers } = base44.asServiceRole.aiGateway.connection({ provider: "typesafe" });
|
|
259
|
+
* const typesafe = createTypeSafeAi({ baseURL, apiKey: token, headers });
|
|
260
|
+
*
|
|
261
|
+
* const { answers, providerMetadata } = await evaluate({
|
|
262
|
+
* model: typesafe.evaluationModel("jev"),
|
|
263
|
+
* maxRetries: 0, // Avoid automatic replays of billed requests
|
|
264
|
+
* state: { message: "Please refund today's duplicate charge." },
|
|
265
|
+
* questions: {
|
|
266
|
+
* department: {
|
|
267
|
+
* type: "choice",
|
|
268
|
+
* instructions: "Which team should handle this?",
|
|
269
|
+
* criteria: { billing: "Payments and refunds", support: "Other requests" },
|
|
270
|
+
* },
|
|
271
|
+
* urgency: {
|
|
272
|
+
* type: "score",
|
|
273
|
+
* instructions: "How urgent is this?",
|
|
274
|
+
* criteria: ["No deadline", "Requested today", "Immediate emergency"],
|
|
275
|
+
* },
|
|
276
|
+
* refund: { type: "boolean", instructions: "Is a refund explicitly requested?" },
|
|
277
|
+
* },
|
|
278
|
+
* });
|
|
279
|
+
*
|
|
280
|
+
* // answers.department → { type: "choice", choice: "billing", probabilities: { billing: 0.97, support: 0.03 } }
|
|
281
|
+
* // answers.urgency → { type: "score", score: 1.2, probabilities: { 0: 0.1, 1: 0.6, 2: 0.3 } }
|
|
282
|
+
* // answers.refund → { type: "boolean", probability: 0.99 }
|
|
283
|
+
* // Choice and score confidence is in providerMetadata.typesafe.confidence
|
|
284
|
+
* // Pick your own thresholds and act on them in code
|
|
285
|
+
* const autoRefund = answers.department.choice === "billing" && answers.refund.probability > 0.9;
|
|
286
|
+
* ```
|
|
190
287
|
*/
|
|
191
288
|
connection(options?: AiGatewayConnectionOptions): AiGatewayConnection;
|
|
192
289
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@base44-preview/sdk",
|
|
3
|
-
"version": "0.8.52-pr.
|
|
3
|
+
"version": "0.8.52-pr.305.970f972",
|
|
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",
|
|
@@ -31,24 +30,6 @@
|
|
|
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
|
}
|