@base44-preview/sdk 0.8.50-pr.292.d7cb5e4 → 0.8.51-pr.294.a7ae332
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
|
@@ -77,6 +77,12 @@ export function createClient(config) {
|
|
|
77
77
|
...optionalHeaders,
|
|
78
78
|
"X-App-Id": String(appId),
|
|
79
79
|
};
|
|
80
|
+
// Base44-State is the platform's signed proof that the caller passed the
|
|
81
|
+
// workspace IP allowlist; the gateway checks it like any other app route.
|
|
82
|
+
const stateHeader = optionalHeaders === null || optionalHeaders === void 0 ? void 0 : optionalHeaders["Base44-State"];
|
|
83
|
+
const aiGatewayHeaders = stateHeader
|
|
84
|
+
? { "Base44-State": stateHeader }
|
|
85
|
+
: {};
|
|
80
86
|
const functionHeaders = functionsVersion
|
|
81
87
|
? {
|
|
82
88
|
...headers,
|
|
@@ -187,7 +193,12 @@ export function createClient(config) {
|
|
|
187
193
|
serverUrl,
|
|
188
194
|
token,
|
|
189
195
|
}),
|
|
190
|
-
aiGateway: createAiGatewayModule({
|
|
196
|
+
aiGateway: createAiGatewayModule({
|
|
197
|
+
serverUrl,
|
|
198
|
+
token,
|
|
199
|
+
appId,
|
|
200
|
+
headers: aiGatewayHeaders,
|
|
201
|
+
}),
|
|
191
202
|
appLogs: createAppLogsModule(axiosClient, appId),
|
|
192
203
|
app: createAppModule(axiosClient, appId),
|
|
193
204
|
users: createUsersModule(axiosClient, appId),
|
|
@@ -234,7 +245,12 @@ export function createClient(config) {
|
|
|
234
245
|
serverUrl,
|
|
235
246
|
token,
|
|
236
247
|
}),
|
|
237
|
-
aiGateway: createAiGatewayModule({
|
|
248
|
+
aiGateway: createAiGatewayModule({
|
|
249
|
+
serverUrl,
|
|
250
|
+
token: serviceToken,
|
|
251
|
+
appId,
|
|
252
|
+
headers: aiGatewayHeaders,
|
|
253
|
+
}),
|
|
238
254
|
appLogs: createAppLogsModule(serviceRoleAxiosClient, appId),
|
|
239
255
|
cleanup: () => {
|
|
240
256
|
if (socket) {
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { AiGatewayModule, AiGatewayModuleConfig } from "./ai-gateway.types.js";
|
|
2
|
-
export declare function createAiGatewayModule({ serverUrl, token, appId, }: AiGatewayModuleConfig): AiGatewayModule;
|
|
2
|
+
export declare function createAiGatewayModule({ serverUrl, token, appId, headers, }: AiGatewayModuleConfig): AiGatewayModule;
|
|
@@ -3,7 +3,7 @@ const PROVIDER_PATHS = {
|
|
|
3
3
|
openai: "openai",
|
|
4
4
|
typesafe: "typesafe",
|
|
5
5
|
};
|
|
6
|
-
export function createAiGatewayModule({ serverUrl, token, appId, }) {
|
|
6
|
+
export function createAiGatewayModule({ serverUrl, token, appId, headers = {}, }) {
|
|
7
7
|
const connection = ({ provider = "openai" } = {}) => {
|
|
8
8
|
var _a;
|
|
9
9
|
if (!Object.prototype.hasOwnProperty.call(PROVIDER_PATHS, provider)) {
|
|
@@ -13,6 +13,7 @@ export function createAiGatewayModule({ serverUrl, token, appId, }) {
|
|
|
13
13
|
return {
|
|
14
14
|
baseURL: `${serverUrl}/api/apps/${appId}/ai/${providerPath}/v1`,
|
|
15
15
|
token: (_a = token !== null && token !== void 0 ? token : getAccessToken()) !== null && _a !== void 0 ? _a : "",
|
|
16
|
+
headers: { ...headers },
|
|
16
17
|
};
|
|
17
18
|
};
|
|
18
19
|
return {
|
|
@@ -9,6 +9,16 @@ export interface AiGatewayConnection {
|
|
|
9
9
|
* unauthenticated.
|
|
10
10
|
*/
|
|
11
11
|
token: string;
|
|
12
|
+
/**
|
|
13
|
+
* Extra headers to send with every gateway request. Pass them to your client's
|
|
14
|
+
* header option, such as `defaultHeaders` for the `openai` SDK and TanStack AI,
|
|
15
|
+
* or `headers` for the Vercel AI SDK.
|
|
16
|
+
*
|
|
17
|
+
* On a client from {@linkcode createClientFromRequest | createClientFromRequest()},
|
|
18
|
+
* this carries the signed `Base44-State` the platform attached to the request,
|
|
19
|
+
* which a workspace IP allowlist requires. Otherwise it's empty.
|
|
20
|
+
*/
|
|
21
|
+
headers: Record<string, string>;
|
|
12
22
|
}
|
|
13
23
|
/** Options for selecting an AI Gateway provider. */
|
|
14
24
|
export interface AiGatewayConnectionOptions {
|
|
@@ -26,14 +36,16 @@ export interface AiGatewayModuleConfig {
|
|
|
26
36
|
token?: string;
|
|
27
37
|
/** Application ID */
|
|
28
38
|
appId: string;
|
|
39
|
+
/** Platform headers to forward on gateway requests */
|
|
40
|
+
headers?: Record<string, string>;
|
|
29
41
|
}
|
|
30
42
|
/**
|
|
31
43
|
* AI Gateway module for calling Base44's managed AI models from your own code.
|
|
32
44
|
*
|
|
33
|
-
* `connection()` hands you a `baseURL` and `
|
|
34
|
-
* Base44 app. An OpenAI-compatible client is any library, such as the `openai`
|
|
45
|
+
* `connection()` hands you a `baseURL`, `token`, and `headers` that
|
|
46
|
+
* authenticate as your Base44 app. An OpenAI-compatible client is any library, such as the `openai`
|
|
35
47
|
* SDK or the Vercel AI SDK, that has the same request and response format
|
|
36
|
-
* as OpenAI's
|
|
48
|
+
* as OpenAI's API and lets you point it at a custom `baseURL`
|
|
37
49
|
* instead of OpenAI's own servers. Pass `connection()`'s values to one of
|
|
38
50
|
* these clients and it works against Base44's gateway exactly as it would
|
|
39
51
|
* against the provider directly, no separate account, API key, or billing
|
|
@@ -55,6 +67,15 @@ export interface AiGatewayModuleConfig {
|
|
|
55
67
|
* Pass `'automatic'` to let Base44 choose one, or pin a specific model such
|
|
56
68
|
* as `'claude_sonnet_4_6'`, `'gpt_5_5'`, or `'gemini_3_1_pro'`.
|
|
57
69
|
*
|
|
70
|
+
* ## Images
|
|
71
|
+
*
|
|
72
|
+
* The gateway also serves OpenAI's image endpoints, `/images/generations`
|
|
73
|
+
* and `/images/edits`, so you can generate images and edit them using
|
|
74
|
+
* reference images. Image requests use their own set of models: pass
|
|
75
|
+
* `'automatic'` to let Base44 choose one, or pin a model such as
|
|
76
|
+
* `'gemini_3_1_flash_image'` or `'gpt_image_2'`. For request options, the
|
|
77
|
+
* full model list, and limits, see [Generate images with the AI Gateway](/developers/references/sdk/getting-started/ai-gateway-images).
|
|
78
|
+
*
|
|
58
79
|
* ## Authentication Modes
|
|
59
80
|
*
|
|
60
81
|
* There's no permission difference between modes. Both just determine which
|
|
@@ -71,18 +92,16 @@ export interface AiGatewayModuleConfig {
|
|
|
71
92
|
* app until the quota resets. A request is rejected before the model runs if
|
|
72
93
|
* the app is out of credits. If you need to cap usage per user, build that
|
|
73
94
|
* check yourself, for example by tracking calls per user in your own entity.
|
|
74
|
-
*
|
|
75
|
-
* Streaming responses aren't supported yet, so leave `stream` unset on your requests.
|
|
76
95
|
*/
|
|
77
96
|
export interface AiGatewayModule {
|
|
78
97
|
/**
|
|
79
98
|
* Gets the connection details for the Base44 AI Gateway.
|
|
80
99
|
*
|
|
81
|
-
* Returns the `baseURL` and `
|
|
100
|
+
* Returns the `baseURL`, `token`, and `headers` to pass to the selected provider client.
|
|
82
101
|
*
|
|
83
102
|
* @param options - Provider selection. Omit it to use the OpenAI-compatible gateway.
|
|
84
103
|
*
|
|
85
|
-
* @returns The gateway {@linkcode AiGatewayConnection | connection} (`baseURL` and `
|
|
104
|
+
* @returns The gateway {@linkcode AiGatewayConnection | connection} (`baseURL`, `token`, and `headers`).
|
|
86
105
|
*
|
|
87
106
|
* @example
|
|
88
107
|
* ```typescript
|
|
@@ -92,8 +111,8 @@ export interface AiGatewayModule {
|
|
|
92
111
|
*
|
|
93
112
|
* // Runs inside a backend function
|
|
94
113
|
* const base44 = createClientFromRequest(request);
|
|
95
|
-
* const { baseURL, token } = base44.aiGateway.connection();
|
|
96
|
-
* const openai = new OpenAI({ baseURL, apiKey: token });
|
|
114
|
+
* const { baseURL, token, headers } = base44.aiGateway.connection();
|
|
115
|
+
* const openai = new OpenAI({ baseURL, apiKey: token, defaultHeaders: headers });
|
|
97
116
|
*
|
|
98
117
|
* const response = await openai.chat.completions.create({
|
|
99
118
|
* model: "automatic",
|
|
@@ -114,9 +133,9 @@ export interface AiGatewayModule {
|
|
|
114
133
|
* // Runs inside a backend function, reviewing a return request
|
|
115
134
|
* const base44 = createClientFromRequest(request);
|
|
116
135
|
* const returnRequest = await base44.entities.ReturnRequest.get(returnId);
|
|
117
|
-
* const { baseURL, token } = base44.aiGateway.connection();
|
|
118
|
-
* // Point any OpenAI-compatible client at `baseURL` with `apiKey: token`.
|
|
119
|
-
* const models = createOpenAICompatible({ name: "base44", baseURL, apiKey: token });
|
|
136
|
+
* const { baseURL, token, headers } = base44.aiGateway.connection();
|
|
137
|
+
* // Point any OpenAI-compatible client at `baseURL` with `apiKey: token` and `headers`.
|
|
138
|
+
* const models = createOpenAICompatible({ name: "base44", baseURL, apiKey: token, headers });
|
|
120
139
|
*
|
|
121
140
|
* const agent = new ToolLoopAgent({
|
|
122
141
|
* model: models("automatic"),
|
|
@@ -145,6 +164,29 @@ export interface AiGatewayModule {
|
|
|
145
164
|
*
|
|
146
165
|
* await agent.generate({ prompt: `Review this return request: ${JSON.stringify(returnRequest)}` });
|
|
147
166
|
* ```
|
|
167
|
+
*
|
|
168
|
+
* @example
|
|
169
|
+
* ```typescript
|
|
170
|
+
* // Generate an image
|
|
171
|
+
* import { createClientFromRequest } from "@base44/sdk";
|
|
172
|
+
* import { generateImage } from "ai";
|
|
173
|
+
* import { createOpenAICompatible } from "@ai-sdk/openai-compatible";
|
|
174
|
+
*
|
|
175
|
+
* // Runs inside a backend function
|
|
176
|
+
* const base44 = createClientFromRequest(request);
|
|
177
|
+
* const { baseURL, token, headers } = base44.aiGateway.connection();
|
|
178
|
+
* const models = createOpenAICompatible({ name: "base44", baseURL, apiKey: token, headers });
|
|
179
|
+
*
|
|
180
|
+
* const { image } = await generateImage({
|
|
181
|
+
* model: models.imageModel("automatic"),
|
|
182
|
+
* prompt: "A watercolor illustration of a lighthouse at dawn",
|
|
183
|
+
* // Base44 options go under the provider name you passed above
|
|
184
|
+
* providerOptions: { base44: { aspect_ratio: "16:9" } },
|
|
185
|
+
* });
|
|
186
|
+
*
|
|
187
|
+
* const file = new File([image.uint8Array], "lighthouse.png", { type: image.mediaType });
|
|
188
|
+
* const { file_url } = await base44.integrations.Core.UploadFile({ file });
|
|
189
|
+
* ```
|
|
148
190
|
*/
|
|
149
191
|
connection(options?: AiGatewayConnectionOptions): AiGatewayConnection;
|
|
150
192
|
}
|
|
@@ -59,8 +59,17 @@ export interface InvokeLLMParams {
|
|
|
59
59
|
* Parameters for the GenerateImage function.
|
|
60
60
|
*/
|
|
61
61
|
export interface GenerateImageParams {
|
|
62
|
-
/**
|
|
62
|
+
/**
|
|
63
|
+
* Description of the image to generate. When you pass `existing_image_urls`,
|
|
64
|
+
* describe what to do with the reference images instead.
|
|
65
|
+
*/
|
|
63
66
|
prompt: string;
|
|
67
|
+
/**
|
|
68
|
+
* URLs of images to use as references, for example to edit an existing
|
|
69
|
+
* image, match a style, or add visual context. Images that can't be read are
|
|
70
|
+
* skipped. If none of them can be read, the request fails.
|
|
71
|
+
*/
|
|
72
|
+
existing_image_urls?: string[];
|
|
64
73
|
}
|
|
65
74
|
export interface GenerateImageResult {
|
|
66
75
|
/** URL of the generated image. */
|
|
@@ -173,12 +182,17 @@ export interface CoreIntegrations {
|
|
|
173
182
|
*/
|
|
174
183
|
InvokeLLM(params: InvokeLLMParams): Promise<string | object>;
|
|
175
184
|
/**
|
|
176
|
-
* Create AI-generated images from text prompts.
|
|
185
|
+
* Create AI-generated images from text prompts, optionally guided by reference images.
|
|
177
186
|
*
|
|
178
187
|
* Images are generated as PNG files at approximately 1024px on the shorter side. The
|
|
179
188
|
* exact dimensions vary by aspect ratio.
|
|
180
189
|
*
|
|
181
|
-
*
|
|
190
|
+
* Pass `existing_image_urls` to edit an existing image or to guide the result
|
|
191
|
+
* with reference images. To choose the model, aspect ratio, resolution, or
|
|
192
|
+
* quality, use the [AI Gateway image endpoints](/developers/references/sdk/getting-started/ai-gateway-images)
|
|
193
|
+
* instead.
|
|
194
|
+
*
|
|
195
|
+
* Prompts that violate the AI provider's content policy are refused.
|
|
182
196
|
*
|
|
183
197
|
* @param params - Parameters for image generation
|
|
184
198
|
* @returns Promise resolving to an object containing the URL of the generated PNG image.
|
|
@@ -191,6 +205,15 @@ export interface CoreIntegrations {
|
|
|
191
205
|
* });
|
|
192
206
|
* console.log(url); // https://...generated_image.png
|
|
193
207
|
* ```
|
|
208
|
+
*
|
|
209
|
+
* @example
|
|
210
|
+
* ```typescript
|
|
211
|
+
* // Edit an existing image
|
|
212
|
+
* const {url} = await base44.integrations.Core.GenerateImage({
|
|
213
|
+
* prompt: "Replace the background with a sunset beach",
|
|
214
|
+
* existing_image_urls: [productPhotoUrl]
|
|
215
|
+
* });
|
|
216
|
+
* ```
|
|
194
217
|
*/
|
|
195
218
|
GenerateImage(params: GenerateImageParams): Promise<GenerateImageResult>;
|
|
196
219
|
/**
|