@base44-preview/sdk 0.8.52-pr.296.452f327 → 0.8.52-pr.297.7590c31

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,13 @@ 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
+ * By default, `connection()` uses the OpenAI-compatible provider, which serves
55
+ * chat and images. Pass `{ provider: "typesafe" }` for structured evaluations.
57
56
  *
58
57
  * Call `connection()` from a backend function rather than the browser. This
59
58
  * 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.
59
+ * you enforce your own auth, rate, and spend limits around the call. Which
60
+ * token it returns depends on the authentication mode, described below.
63
61
  *
64
62
  * ## OpenAI-compatible models
65
63
  *
@@ -76,13 +74,23 @@ export interface AiGatewayModuleConfig {
76
74
  * `'gemini_3_1_flash_image'` or `'gpt_image_2'`. For request options, the
77
75
  * full model list, and limits, see [Generate images with the AI Gateway](/developers/references/sdk/getting-started/ai-gateway-images).
78
76
  *
77
+ * ## Structured evaluations
78
+ *
79
+ * The `typesafe` provider runs the `jev` evaluation model through
80
+ * `@ai-sdk/typesafe-ai` and `experimental_evaluate` from the `ai` package,
81
+ * version 7.0.105 or later. Pass `evaluationModel("jev")`; the gateway rejects
82
+ * other model IDs, such as `"jev-latest"`. Give it some app state and a set of
83
+ * questions, each a `choice`, `score`, or `boolean`. Choice and score answers
84
+ * come back with `probabilities` per option; boolean answers with a single
85
+ * `probability` of `true`. Use it to classify, score, or route records, then
86
+ * apply your own thresholds and actions in code.
87
+ *
79
88
  * ## Authentication Modes
80
89
  *
81
- * There's no permission difference between modes. Both just determine which
82
- * token `connection()` returns:
90
+ * The mode determines which token `connection()` returns:
83
91
  *
84
- * - **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.
92
+ * - **Service role authentication** (`base44.asServiceRole.aiGateway`): Returns the service-role token. Use this from backend functions, including scheduled automations with no signed-in user. Every call spends the app's credits, so check the caller with `base44.auth.me()` first when a user triggers the function.
93
+ * - **User authentication** (`base44.aiGateway`): Returns the signed-in app user's token. When an app restricts Core integrations, which is the default for new apps, public apps reject gateway calls made with a user token unless the AI Gateway is allowed.
86
94
  *
87
95
  * ## Billing and limits
88
96
  *
@@ -111,7 +119,7 @@ export interface AiGatewayModule {
111
119
  *
112
120
  * // Runs inside a backend function
113
121
  * const base44 = createClientFromRequest(request);
114
- * const { baseURL, token, headers } = base44.aiGateway.connection();
122
+ * const { baseURL, token, headers } = base44.asServiceRole.aiGateway.connection();
115
123
  * const openai = new OpenAI({ baseURL, apiKey: token, defaultHeaders: headers });
116
124
  *
117
125
  * const response = await openai.chat.completions.create({
@@ -133,7 +141,7 @@ export interface AiGatewayModule {
133
141
  * // Runs inside a backend function, reviewing a return request
134
142
  * const base44 = createClientFromRequest(request);
135
143
  * const returnRequest = await base44.entities.ReturnRequest.get(returnId);
136
- * const { baseURL, token, headers } = base44.aiGateway.connection();
144
+ * const { baseURL, token, headers } = base44.asServiceRole.aiGateway.connection();
137
145
  * // Point any OpenAI-compatible client at `baseURL` with `apiKey: token` and `headers`.
138
146
  * const models = createOpenAICompatible({ name: "base44", baseURL, apiKey: token, headers });
139
147
  *
@@ -174,7 +182,7 @@ export interface AiGatewayModule {
174
182
  *
175
183
  * // Runs inside a backend function
176
184
  * const base44 = createClientFromRequest(request);
177
- * const { baseURL, token, headers } = base44.aiGateway.connection();
185
+ * const { baseURL, token, headers } = base44.asServiceRole.aiGateway.connection();
178
186
  * const models = createOpenAICompatible({ name: "base44", baseURL, apiKey: token, headers });
179
187
  *
180
188
  * const { image } = await generateImage({
@@ -187,6 +195,45 @@ export interface AiGatewayModule {
187
195
  * const file = new File([image.uint8Array], "lighthouse.png", { type: image.mediaType });
188
196
  * const { file_url } = await base44.integrations.Core.UploadFile({ file });
189
197
  * ```
198
+ *
199
+ * @example
200
+ * ```typescript
201
+ * // Route a support ticket with a structured evaluation
202
+ * import { createClientFromRequest } from "@base44/sdk";
203
+ * import { experimental_evaluate as evaluate } from "ai";
204
+ * import { createTypeSafeAi } from "@ai-sdk/typesafe-ai";
205
+ *
206
+ * // Runs inside a backend function
207
+ * const base44 = createClientFromRequest(request);
208
+ * const { baseURL, token, headers } = base44.asServiceRole.aiGateway.connection({ provider: "typesafe" });
209
+ * const typesafe = createTypeSafeAi({ baseURL, apiKey: token, headers });
210
+ *
211
+ * const { answers, providerMetadata } = await evaluate({
212
+ * model: typesafe.evaluationModel("jev"),
213
+ * maxRetries: 0, // Avoid automatic replays of billed requests
214
+ * state: { message: "Please refund today's duplicate charge." },
215
+ * questions: {
216
+ * department: {
217
+ * type: "choice",
218
+ * instructions: "Which team should handle this?",
219
+ * criteria: { billing: "Payments and refunds", support: "Other requests" },
220
+ * },
221
+ * urgency: {
222
+ * type: "score",
223
+ * instructions: "How urgent is this?",
224
+ * criteria: ["No deadline", "Requested today", "Immediate emergency"],
225
+ * },
226
+ * refund: { type: "boolean", instructions: "Is a refund explicitly requested?" },
227
+ * },
228
+ * });
229
+ *
230
+ * // answers.department → { type: "choice", choice: "billing", probabilities: { billing: 0.97, support: 0.03 } }
231
+ * // answers.urgency → { type: "score", score: 1.2, probabilities: { 0: 0.1, 1: 0.6, 2: 0.3 } }
232
+ * // answers.refund → { type: "boolean", probability: 0.99 }
233
+ * // Choice and score confidence is in providerMetadata.typesafe.confidence
234
+ * // Pick your own thresholds and act on them in code
235
+ * const autoRefund = answers.department.choice === "billing" && answers.refund.probability > 0.9;
236
+ * ```
190
237
  */
191
238
  connection(options?: AiGatewayConnectionOptions): AiGatewayConnection;
192
239
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@base44-preview/sdk",
3
- "version": "0.8.52-pr.296.452f327",
3
+ "version": "0.8.52-pr.297.7590c31",
4
4
  "description": "JavaScript SDK for Base44 API",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",