@base44-preview/sdk 0.8.38-pr.230.05d5213 → 0.8.39-pr.231.0f61b59

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/client.js CHANGED
@@ -346,6 +346,7 @@ export function createClientFromRequest(request) {
346
346
  const serverUrlHeader = request.headers.get("Base44-Api-Url");
347
347
  const functionsVersion = request.headers.get("Base44-Functions-Version");
348
348
  const stateHeader = request.headers.get("Base44-State");
349
+ const dataEnvHeader = request.headers.get("X-Data-Env");
349
350
  if (!appId) {
350
351
  throw new Error("Base44-App-Id header is required, but is was not found on the request");
351
352
  }
@@ -373,6 +374,16 @@ export function createClientFromRequest(request) {
373
374
  if (stateHeader) {
374
375
  additionalHeaders["Base44-State"] = stateHeader;
375
376
  }
377
+ // Propagate the data environment so entity operations from the function stay
378
+ // in the same environment (e.g. test data) as the triggering request. This
379
+ // matters for the user-scoped client: unlike the service token, the user JWT
380
+ // carries no data-env, so without forwarding this header the callbacks fall
381
+ // back to production data even when the app runs in test-data mode.
382
+ // Forward only the known closed set (matches the backend contract) rather
383
+ // than relaying an arbitrary attacker-supplied header value onward.
384
+ if (dataEnvHeader === "dev" || dataEnvHeader === "prod") {
385
+ additionalHeaders["X-Data-Env"] = dataEnvHeader;
386
+ }
376
387
  return createClient({
377
388
  serverUrl: serverUrlHeader || "https://base44.app",
378
389
  appId,
@@ -1,13 +1,13 @@
1
1
  /**
2
- * A connection to the Base44 AI Gateway.
3
- *
4
- * Contains the base URL and bearer token to use with any OpenAI-compatible
5
- * client pointed at the Base44 AI Gateway.
2
+ * Connection details for the Base44 AI Gateway.
6
3
  */
7
4
  export interface AiGatewayConnection {
8
- /** Base URL of the gateway's OpenAI-compatible endpoint. */
5
+ /** Base URL of the gateway's OpenAI-compatible Chat Completions endpoint. */
9
6
  baseURL: string;
10
- /** Bearer token used to authenticate requests to the gateway. */
7
+ /**
8
+ * Bearer token that authenticates the request. Empty string when the caller is
9
+ * unauthenticated.
10
+ */
11
11
  token: string;
12
12
  }
13
13
  /**
@@ -25,13 +25,47 @@ export interface AiGatewayModuleConfig {
25
25
  /**
26
26
  * AI Gateway module for calling Base44's managed AI models from your own code.
27
27
  *
28
- * The gateway exposes an OpenAI-compatible Chat Completions endpoint, so any
29
- * OpenAI-compatible SDK works against it:
30
- * - Build custom AI agents or call models directly from your backend code
31
- * - Uses your app's models, billing, and credit quota, no API key to manage
28
+ * `connection()` hands you a `baseURL` and `token` that authenticate as your
29
+ * Base44 app. An OpenAI-compatible client is any library, such as the `openai`
30
+ * SDK or the Vercel AI SDK, that has the same request and response format
31
+ * as OpenAI's Chat Completions API and lets you point it at a custom `baseURL`
32
+ * instead of OpenAI's own servers. Pass `connection()`'s values to one of
33
+ * these clients and it works against Base44's gateway exactly as it would
34
+ * against the provider directly, no separate account, API key, or billing
35
+ * setup with the underlying model provider required.
36
+ *
37
+ * Call `connection()` from a backend function rather than the browser. That's
38
+ * where you can wire tools that read and write your app's own entities and
39
+ * business logic without shipping that logic to the client. It also keeps the
40
+ * gateway token out of the browser, where it could be stolen and used to
41
+ * spend against your app's shared credit quota.
42
+ *
43
+ * ## Models
44
+ *
45
+ * Build AI agents or call models directly from your app's backend functions.
46
+ * Pass `'automatic'` to let Base44 choose a model, or pin a specific one such
47
+ * as `'claude_sonnet_4_6'`, `'claude_opus_4_8'`, `'gpt_5_5'`, or
48
+ * `'gemini_3_1_pro'`.
49
+ *
50
+ * See the [`model` options on `InvokeLLM`](/developers/references/sdk/docs/type-aliases/integrations#invokellm)
51
+ * for the current set of models you can use.
52
+ *
53
+ * ## Authentication Modes
54
+ *
55
+ * This module is available to use with a client in all authentication modes:
56
+ *
57
+ * - **Anonymous or User authentication** (`base44.aiGateway`): The gateway connection is scoped to the current user's permissions.
58
+ * - **Service role authentication** (`base44.asServiceRole.aiGateway`): The gateway connection uses the service role for backend code that needs elevated permissions.
59
+ *
60
+ * ## Billing and limits
32
61
  *
33
- * Available in user authentication mode (`base44.aiGateway`) and with the
34
- * service-role token via `base44.asServiceRole.aiGateway`.
62
+ * Requests are billed to your app's credit quota, which is the same shared
63
+ * quota your app's built-in AI features use, and isn't split per user. If the
64
+ * app runs out of credits, the gateway stops working for every user of the
65
+ * app until the quota resets. A request is rejected before the model runs if
66
+ * the app is out of credits.
67
+ *
68
+ * Streaming responses aren't supported yet, so leave `stream` unset on your requests.
35
69
  */
36
70
  export interface AiGatewayModule {
37
71
  /**
@@ -39,14 +73,27 @@ export interface AiGatewayModule {
39
73
  *
40
74
  * Returns the `baseURL` and `token` to pass to any OpenAI-compatible client.
41
75
  *
42
- * The `token` is the current caller's bearer token: the app user's token for
43
- * `base44.aiGateway`, or the service-role token for `base44.asServiceRole.aiGateway`.
44
- * When the caller is unauthenticated, `token` is an empty string.
45
- *
46
76
  * @returns The gateway {@linkcode AiGatewayConnection | connection} (`baseURL` and `token`).
47
77
  *
48
78
  * @example
49
79
  * ```typescript
80
+ * // Call a model directly with the OpenAI SDK, inside a backend function
81
+ * import OpenAI from "openai";
82
+ *
83
+ * const { baseURL, token } = base44.aiGateway.connection();
84
+ * const openai = new OpenAI({ baseURL, apiKey: token });
85
+ *
86
+ * const response = await openai.chat.completions.create({
87
+ * model: "automatic",
88
+ * messages: [{ role: "user", content: "Summarize this week's top support tickets." }],
89
+ * });
90
+ *
91
+ * console.log(response.choices[0].message.content);
92
+ * ```
93
+ *
94
+ * @example
95
+ * ```typescript
96
+ * // Review a return request with a tool-using agent, inside a backend function
50
97
  * import { ToolLoopAgent, tool, stepCountIs, hasToolCall } from "ai";
51
98
  * import { createOpenAICompatible } from "@ai-sdk/openai-compatible";
52
99
  * import { z } from "zod";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@base44-preview/sdk",
3
- "version": "0.8.38-pr.230.05d5213",
3
+ "version": "0.8.39-pr.231.0f61b59",
4
4
  "description": "JavaScript SDK for Base44 API",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",