@base44-preview/sdk 0.8.52-pr.303.ccc8858 → 0.8.52-pr.305.7dff8f5

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.
@@ -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
- * By default, `connection()` uses the OpenAI-compatible provider. Pass
55
- * `{ provider: "typesafe" }` to connect to TypeSafe for structured evaluations
56
- * with `@ai-sdk/typesafe-ai`.
54
+ * `connection()` takes an optional `provider`, and each provider serves a different API:
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. The
61
- * `token` it returns is the caller's regular session token, the same one
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,13 +76,34 @@ 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
+ * ## 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")`; the gateway rejects
95
+ * other model IDs, such as `"jev-latest"`. Give it some app state and a set of
96
+ * questions, each a `choice`, `score`, or `boolean`. Choice and score answers
97
+ * come back with `probabilities` per option; boolean answers with a single
98
+ * `probability` of `true`. Use it to classify, score, or route records, then
99
+ * apply your own thresholds and actions in code.
100
+ *
79
101
  * ## Authentication Modes
80
102
  *
81
- * There's no permission difference between modes. Both just determine which
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, for calling the gateway when there's no signed-in user, such as from a scheduled automation.
106
+ * - **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.
86
107
  *
87
108
  * ## Billing and limits
88
109
  *
@@ -111,7 +132,7 @@ export interface AiGatewayModule {
111
132
  *
112
133
  * // Runs inside a backend function
113
134
  * const base44 = createClientFromRequest(request);
114
- * const { baseURL, token, headers } = base44.aiGateway.connection();
135
+ * const { baseURL, token, headers } = base44.asServiceRole.aiGateway.connection();
115
136
  * const openai = new OpenAI({ baseURL, apiKey: token, defaultHeaders: headers });
116
137
  *
117
138
  * const response = await openai.chat.completions.create({
@@ -133,7 +154,7 @@ export interface AiGatewayModule {
133
154
  * // Runs inside a backend function, reviewing a return request
134
155
  * const base44 = createClientFromRequest(request);
135
156
  * const returnRequest = await base44.entities.ReturnRequest.get(returnId);
136
- * const { baseURL, token, headers } = base44.aiGateway.connection();
157
+ * const { baseURL, token, headers } = base44.asServiceRole.aiGateway.connection();
137
158
  * // Point any OpenAI-compatible client at `baseURL` with `apiKey: token` and `headers`.
138
159
  * const models = createOpenAICompatible({ name: "base44", baseURL, apiKey: token, headers });
139
160
  *
@@ -174,7 +195,7 @@ export interface AiGatewayModule {
174
195
  *
175
196
  * // Runs inside a backend function
176
197
  * const base44 = createClientFromRequest(request);
177
- * const { baseURL, token, headers } = base44.aiGateway.connection();
198
+ * const { baseURL, token, headers } = base44.asServiceRole.aiGateway.connection();
178
199
  * const models = createOpenAICompatible({ name: "base44", baseURL, apiKey: token, headers });
179
200
  *
180
201
  * const { image } = await generateImage({
@@ -187,6 +208,69 @@ export interface AiGatewayModule {
187
208
  * const file = new File([image.uint8Array], "lighthouse.png", { type: image.mediaType });
188
209
  * const { file_url } = await base44.integrations.Core.UploadFile({ file });
189
210
  * ```
211
+ *
212
+ * @example
213
+ * ```typescript
214
+ * // Start a video and record the job to poll later
215
+ * import { createClientFromRequest } from "@base44/sdk";
216
+ *
217
+ * // Runs inside a backend function
218
+ * const base44 = createClientFromRequest(request);
219
+ * const { baseURL, token, headers } = base44.asServiceRole.aiGateway.connection();
220
+ *
221
+ * const response = await fetch(`${baseURL}/videos`, {
222
+ * method: "POST",
223
+ * headers: { ...headers, Authorization: `Bearer ${token}`, "Content-Type": "application/json" },
224
+ * body: JSON.stringify({
225
+ * model: "veo_3_1_fast",
226
+ * prompt: "A lighthouse beam sweeping across a calm sea at dawn",
227
+ * seconds: 8,
228
+ * }),
229
+ * });
230
+ *
231
+ * // Video generation takes minutes, so store the id and poll it from a later request
232
+ * const { id } = await response.json();
233
+ * await base44.asServiceRole.entities.Clip.update(clipId, { video_id: id });
234
+ * ```
235
+ *
236
+ * @example
237
+ * ```typescript
238
+ * // Route a support ticket with a structured evaluation
239
+ * import { createClientFromRequest } from "@base44/sdk";
240
+ * import { experimental_evaluate as evaluate } from "ai";
241
+ * import { createTypeSafeAi } from "@ai-sdk/typesafe-ai";
242
+ *
243
+ * // Runs inside a backend function
244
+ * const base44 = createClientFromRequest(request);
245
+ * const { baseURL, token, headers } = base44.asServiceRole.aiGateway.connection({ provider: "typesafe" });
246
+ * const typesafe = createTypeSafeAi({ baseURL, apiKey: token, headers });
247
+ *
248
+ * const { answers, providerMetadata } = await evaluate({
249
+ * model: typesafe.evaluationModel("jev"),
250
+ * maxRetries: 0, // Avoid automatic replays of billed requests
251
+ * state: { message: "Please refund today's duplicate charge." },
252
+ * questions: {
253
+ * department: {
254
+ * type: "choice",
255
+ * instructions: "Which team should handle this?",
256
+ * criteria: { billing: "Payments and refunds", support: "Other requests" },
257
+ * },
258
+ * urgency: {
259
+ * type: "score",
260
+ * instructions: "How urgent is this?",
261
+ * criteria: ["No deadline", "Requested today", "Immediate emergency"],
262
+ * },
263
+ * refund: { type: "boolean", instructions: "Is a refund explicitly requested?" },
264
+ * },
265
+ * });
266
+ *
267
+ * // answers.department → { type: "choice", choice: "billing", probabilities: { billing: 0.97, support: 0.03 } }
268
+ * // answers.urgency → { type: "score", score: 1.2, probabilities: { 0: 0.1, 1: 0.6, 2: 0.3 } }
269
+ * // answers.refund → { type: "boolean", probability: 0.99 }
270
+ * // Choice and score confidence is in providerMetadata.typesafe.confidence
271
+ * // Pick your own thresholds and act on them in code
272
+ * const autoRefund = answers.department.choice === "billing" && answers.refund.probability > 0.9;
273
+ * ```
190
274
  */
191
275
  connection(options?: AiGatewayConnectionOptions): AiGatewayConnection;
192
276
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@base44-preview/sdk",
3
- "version": "0.8.52-pr.303.ccc8858",
3
+ "version": "0.8.52-pr.305.7dff8f5",
4
4
  "description": "JavaScript SDK for Base44 API",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -25,7 +25,7 @@
25
25
  "create-docs:process": "node scripts/mintlify-post-processing/file-processing/file-processing.js"
26
26
  },
27
27
  "dependencies": {
28
- "axios": "^1.18.1",
28
+ "axios": "^1.20.0",
29
29
  "partysocket": "^0.0.23",
30
30
  "socket.io-client": "^4.8.3",
31
31
  "uuid": "^13.0.2"