@base44-preview/sdk 0.8.40-pr.212.5212229 → 0.8.40-pr.212.8d7ec0a
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 +6 -9
- package/dist/client.types.d.ts +6 -20
- package/dist/modules/actors.d.ts +1 -3
- package/dist/modules/actors.js +6 -5
- package/dist/modules/ai-gateway.types.d.ts +70 -19
- package/dist/modules/sso.types.d.ts +28 -22
- package/package.json +1 -1
package/dist/client.js
CHANGED
|
@@ -52,19 +52,19 @@ import { createActorsModule } from "./modules/actors.js";
|
|
|
52
52
|
*/
|
|
53
53
|
export function createClient(config) {
|
|
54
54
|
var _a, _b;
|
|
55
|
-
const { serverUrl = "https://base44.app", appId, token, serviceToken, requiresAuth = false, appBaseUrl, options, functionsVersion, headers: optionalHeaders,
|
|
55
|
+
const { serverUrl = "https://base44.app", appId, token, serviceToken, requiresAuth = false, appBaseUrl, options, functionsVersion, headers: optionalHeaders, actorsWsUrl, } = config;
|
|
56
56
|
// Normalize appBaseUrl to always be a string (empty if not provided or invalid)
|
|
57
57
|
const normalizedAppBaseUrl = typeof appBaseUrl === "string" ? appBaseUrl : "";
|
|
58
|
-
// Derive the
|
|
58
|
+
// Derive the Actor WebSocket URL if not explicitly provided. Default to
|
|
59
59
|
// the app's OWN origin (the app URL proxies /parties to the backend) so the
|
|
60
60
|
// socket is same-origin with the running app, not the API host: prefer an
|
|
61
61
|
// explicit appBaseUrl, then the browser origin, then fall back to serverUrl
|
|
62
62
|
// (Node/SSR, where there's no window). Convert https:// → wss:// (http → ws)
|
|
63
63
|
// and strip the trailing slash.
|
|
64
|
-
const
|
|
64
|
+
const resolvedActorsWsUrl = (() => {
|
|
65
65
|
var _a, _b;
|
|
66
|
-
if (
|
|
67
|
-
return
|
|
66
|
+
if (actorsWsUrl)
|
|
67
|
+
return actorsWsUrl.replace(/\/$/, "");
|
|
68
68
|
const appOrigin = normalizedAppBaseUrl ||
|
|
69
69
|
// React Native has a bare `window` with no `location`, so guard both.
|
|
70
70
|
(typeof window !== "undefined" ? (_b = (_a = window.location) === null || _a === void 0 ? void 0 : _a.origin) !== null && _b !== void 0 ? _b : "" : "");
|
|
@@ -181,11 +181,8 @@ export function createClient(config) {
|
|
|
181
181
|
}),
|
|
182
182
|
actors: createActorsModule({
|
|
183
183
|
appId,
|
|
184
|
-
|
|
185
|
-
webSocketImpl,
|
|
184
|
+
actorsWsUrl: resolvedActorsWsUrl,
|
|
186
185
|
functionsVersion,
|
|
187
|
-
// Same credential as function calls; the platform proxy authenticates the
|
|
188
|
-
// WS connection with it (anonymous when absent) — no pre-connect token mint.
|
|
189
186
|
getAuthToken: () => token || getAccessToken(),
|
|
190
187
|
}),
|
|
191
188
|
cleanup: () => {
|
package/dist/client.types.d.ts
CHANGED
|
@@ -75,27 +75,15 @@ export interface CreateClientConfig {
|
|
|
75
75
|
*/
|
|
76
76
|
options?: CreateClientOptions;
|
|
77
77
|
/**
|
|
78
|
-
* Base WebSocket URL for
|
|
78
|
+
* Base WebSocket URL for Actor connections.
|
|
79
79
|
*
|
|
80
80
|
* Defaults to the app's own origin (`appBaseUrl`, else the browser's
|
|
81
81
|
* `window.location.origin`, else `serverUrl`) with `https://` replaced by
|
|
82
|
-
* `wss://` (or `http://` by `ws://`) — so the
|
|
83
|
-
* with the running app, which proxies `/parties` to the backend.
|
|
84
|
-
* Override when the
|
|
82
|
+
* `wss://` (or `http://` by `ws://`) — so the Actor socket is same-origin
|
|
83
|
+
* with the running app, which proxies `/parties` to the backend dispatcher.
|
|
84
|
+
* Override only when the Actor host differs from the app origin.
|
|
85
85
|
*/
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* WebSocket implementation for realtime subscriptions in environments
|
|
89
|
-
* without a global `WebSocket` (Node.js < 22). Browsers and Node ≥ 22
|
|
90
|
-
* don't need this.
|
|
91
|
-
*
|
|
92
|
-
* @example
|
|
93
|
-
* ```typescript
|
|
94
|
-
* import WS from "ws";
|
|
95
|
-
* const base44 = createClient({ appId, webSocketImpl: WS });
|
|
96
|
-
* ```
|
|
97
|
-
*/
|
|
98
|
-
webSocketImpl?: unknown;
|
|
86
|
+
actorsWsUrl?: string;
|
|
99
87
|
}
|
|
100
88
|
/**
|
|
101
89
|
* The Base44 client instance.
|
|
@@ -164,9 +152,7 @@ export interface Base44Client {
|
|
|
164
152
|
functions: FunctionsModule;
|
|
165
153
|
/** {@link IntegrationsModule | Integrations module} with elevated permissions. */
|
|
166
154
|
integrations: IntegrationsModule;
|
|
167
|
-
/** {@link SsoModule | SSO module} for generating SSO tokens.
|
|
168
|
-
* @internal
|
|
169
|
-
*/
|
|
155
|
+
/** {@link SsoModule | SSO module} for generating SSO tokens. */
|
|
170
156
|
sso: SsoModule;
|
|
171
157
|
/** Cleanup function to disconnect WebSocket connections. */
|
|
172
158
|
cleanup: () => void;
|
package/dist/modules/actors.d.ts
CHANGED
|
@@ -7,9 +7,7 @@ interface ActorsConfig {
|
|
|
7
7
|
/** Same semantics as function calls: editors with a non-prod version get the
|
|
8
8
|
* draft actor script; everyone else gets the published one. */
|
|
9
9
|
functionsVersion?: string;
|
|
10
|
-
|
|
11
|
-
/** WebSocket implementation for runtimes without a global one (Node < 22). */
|
|
12
|
-
webSocketImpl?: unknown;
|
|
10
|
+
actorsWsUrl: string;
|
|
13
11
|
}
|
|
14
12
|
export declare function createActorsModule(config: ActorsConfig): Record<string, (instanceId: string) => ActorRoom>;
|
|
15
13
|
export {};
|
package/dist/modules/actors.js
CHANGED
|
@@ -27,11 +27,10 @@ class Room {
|
|
|
27
27
|
const connId = (_a = options === null || options === void 0 ? void 0 : options.id) !== null && _a !== void 0 ? _a : crypto.randomUUID();
|
|
28
28
|
this.connId = connId;
|
|
29
29
|
const ws = new PartySocket({
|
|
30
|
-
host: this.config.
|
|
30
|
+
host: this.config.actorsWsUrl,
|
|
31
31
|
party: this.actorName,
|
|
32
32
|
room: this.instanceId,
|
|
33
33
|
id: connId,
|
|
34
|
-
...(this.config.webSocketImpl ? { WebSocket: this.config.webSocketImpl } : {}),
|
|
35
34
|
// Re-read on every (re)connect so a login/logout is picked up.
|
|
36
35
|
query: () => {
|
|
37
36
|
const token = this.config.getAuthToken();
|
|
@@ -54,11 +53,11 @@ class Room {
|
|
|
54
53
|
data = JSON.parse(ev.data);
|
|
55
54
|
}
|
|
56
55
|
catch (_a) {
|
|
57
|
-
return;
|
|
56
|
+
return;
|
|
58
57
|
}
|
|
59
58
|
const msgType = data && typeof data === "object" ? data.type : undefined;
|
|
60
59
|
if (msgType === "__pong")
|
|
61
|
-
return;
|
|
60
|
+
return;
|
|
62
61
|
for (const listener of this.listeners)
|
|
63
62
|
listener(data);
|
|
64
63
|
});
|
|
@@ -69,10 +68,12 @@ class Room {
|
|
|
69
68
|
return;
|
|
70
69
|
}
|
|
71
70
|
try {
|
|
71
|
+
// The deployed shim echoes __ping → __pong (base44-userapp-bundler
|
|
72
|
+
// shim/actor.ts); without that, an idle room reconnects every DEAD_MS.
|
|
72
73
|
ws.send(JSON.stringify({ type: "__ping" }));
|
|
73
74
|
}
|
|
74
75
|
catch (_a) {
|
|
75
|
-
//
|
|
76
|
+
// not open; the watchdog above will reconnect
|
|
76
77
|
}
|
|
77
78
|
}, PING_MS);
|
|
78
79
|
return this;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
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
|
-
/**
|
|
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,45 @@ export interface AiGatewayModuleConfig {
|
|
|
25
25
|
/**
|
|
26
26
|
* AI Gateway module for calling Base44's managed AI models from your own code.
|
|
27
27
|
*
|
|
28
|
-
*
|
|
29
|
-
* OpenAI-compatible
|
|
30
|
-
*
|
|
31
|
-
*
|
|
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. This
|
|
38
|
+
* keeps your instructions, tools, and business logic server-side, and lets
|
|
39
|
+
* you enforce your own auth, rate, and spend limits around the call. The
|
|
40
|
+
* `token` it returns is the caller's regular session token, the same one
|
|
41
|
+
* used for every other SDK call.
|
|
42
|
+
*
|
|
43
|
+
* ## Models
|
|
44
|
+
*
|
|
45
|
+
* You can use any of the [models available through `InvokeLLM`](/developers/references/sdk/docs/type-aliases/integrations#invokellm).
|
|
46
|
+
* Pass `'automatic'` to let Base44 choose one, or pin a specific model such
|
|
47
|
+
* as `'claude_sonnet_4_6'`, `'gpt_5_5'`, or `'gemini_3_1_pro'`.
|
|
48
|
+
*
|
|
49
|
+
* ## Authentication Modes
|
|
50
|
+
*
|
|
51
|
+
* There's no permission difference between modes. Both just determine which
|
|
52
|
+
* token `connection()` returns:
|
|
53
|
+
*
|
|
54
|
+
* - **User authentication** (`base44.aiGateway`): Returns the signed-in app user's token.
|
|
55
|
+
* - **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.
|
|
56
|
+
*
|
|
57
|
+
* ## Billing and limits
|
|
58
|
+
*
|
|
59
|
+
* Requests are billed to your app's credit quota, which is the same shared
|
|
60
|
+
* quota your app's built-in AI features use, and isn't split per user. If the
|
|
61
|
+
* app runs out of credits, the gateway stops working for every user of the
|
|
62
|
+
* app until the quota resets. A request is rejected before the model runs if
|
|
63
|
+
* the app is out of credits. If you need to cap usage per user, build that
|
|
64
|
+
* check yourself, for example by tracking calls per user in your own entity.
|
|
32
65
|
*
|
|
33
|
-
*
|
|
34
|
-
* service-role token via `base44.asServiceRole.aiGateway`.
|
|
66
|
+
* Streaming responses aren't supported yet, so leave `stream` unset on your requests.
|
|
35
67
|
*/
|
|
36
68
|
export interface AiGatewayModule {
|
|
37
69
|
/**
|
|
@@ -39,19 +71,38 @@ export interface AiGatewayModule {
|
|
|
39
71
|
*
|
|
40
72
|
* Returns the `baseURL` and `token` to pass to any OpenAI-compatible client.
|
|
41
73
|
*
|
|
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
74
|
* @returns The gateway {@linkcode AiGatewayConnection | connection} (`baseURL` and `token`).
|
|
47
75
|
*
|
|
48
76
|
* @example
|
|
49
77
|
* ```typescript
|
|
78
|
+
* // Call a model directly
|
|
79
|
+
* import { createClientFromRequest } from "@base44/sdk";
|
|
80
|
+
* import OpenAI from "openai";
|
|
81
|
+
*
|
|
82
|
+
* // Runs inside a backend function
|
|
83
|
+
* const base44 = createClientFromRequest(request);
|
|
84
|
+
* const { baseURL, token } = base44.aiGateway.connection();
|
|
85
|
+
* const openai = new OpenAI({ baseURL, apiKey: token });
|
|
86
|
+
*
|
|
87
|
+
* const response = await openai.chat.completions.create({
|
|
88
|
+
* model: "automatic",
|
|
89
|
+
* messages: [{ role: "user", content: "Summarize this week's top support tickets." }],
|
|
90
|
+
* });
|
|
91
|
+
*
|
|
92
|
+
* console.log(response.choices[0].message.content);
|
|
93
|
+
* ```
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* ```typescript
|
|
97
|
+
* // Use a tool-calling agent
|
|
98
|
+
* import { createClientFromRequest } from "@base44/sdk";
|
|
50
99
|
* import { ToolLoopAgent, tool, stepCountIs, hasToolCall } from "ai";
|
|
51
100
|
* import { createOpenAICompatible } from "@ai-sdk/openai-compatible";
|
|
52
101
|
* import { z } from "zod";
|
|
53
102
|
*
|
|
54
|
-
*
|
|
103
|
+
* // Runs inside a backend function, reviewing a return request
|
|
104
|
+
* const base44 = createClientFromRequest(request);
|
|
105
|
+
* const returnRequest = await base44.entities.ReturnRequest.get(returnId);
|
|
55
106
|
* const { baseURL, token } = base44.aiGateway.connection();
|
|
56
107
|
* // Point any OpenAI-compatible client at `baseURL` with `apiKey: token`.
|
|
57
108
|
* const models = createOpenAICompatible({ name: "base44", baseURL, apiKey: token });
|
|
@@ -66,7 +117,7 @@ export interface AiGatewayModule {
|
|
|
66
117
|
* description: "This customer's past orders, optionally filtered by status",
|
|
67
118
|
* inputSchema: z.object({ status: z.string().optional() }),
|
|
68
119
|
* execute: ({ status }) => {
|
|
69
|
-
* const query = { customer_email:
|
|
120
|
+
* const query = { customer_email: returnRequest.customer_email };
|
|
70
121
|
* if (status) query.status = status;
|
|
71
122
|
* return base44.entities.Order.filter(query, "-created_date", 50);
|
|
72
123
|
* },
|
|
@@ -81,7 +132,7 @@ export interface AiGatewayModule {
|
|
|
81
132
|
* stopWhen: [stepCountIs(8), hasToolCall("submitVerdict")],
|
|
82
133
|
* });
|
|
83
134
|
*
|
|
84
|
-
* await agent.generate({ prompt: `Review this return request: ${JSON.stringify(
|
|
135
|
+
* await agent.generate({ prompt: `Review this return request: ${JSON.stringify(returnRequest)}` });
|
|
85
136
|
* ```
|
|
86
137
|
*/
|
|
87
138
|
connection(): AiGatewayConnection;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Response from SSO access token endpoint.
|
|
3
|
-
* @internal
|
|
4
3
|
*/
|
|
5
4
|
export interface SsoAccessTokenResponse {
|
|
6
5
|
access_token: string;
|
|
@@ -13,46 +12,53 @@ export interface SsoAccessTokenResponse {
|
|
|
13
12
|
* services.
|
|
14
13
|
*
|
|
15
14
|
* This module is only available to use with a client in service role authentication mode, which means it can only be used in backend environments.
|
|
16
|
-
*
|
|
17
|
-
* @internal
|
|
18
|
-
*
|
|
19
|
-
* @example
|
|
20
|
-
* ```typescript
|
|
21
|
-
* // Access SSO module with service role
|
|
22
|
-
* const response = await base44.asServiceRole.sso.getAccessToken('user_123');
|
|
23
|
-
* console.log(response.data.access_token);
|
|
24
|
-
* ```
|
|
25
15
|
*/
|
|
26
16
|
export interface SsoModule {
|
|
27
17
|
/**
|
|
28
|
-
* Gets SSO access token for
|
|
18
|
+
* Gets an SSO access token for the user who made the current request.
|
|
29
19
|
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
20
|
+
* Use this token to authenticate the user with external systems or services.
|
|
21
|
+
* This only works for that same user. Create the client with
|
|
22
|
+
* {@link createClientFromRequest} so it acts on behalf of the request's user,
|
|
23
|
+
* then pass that user's ID as `userid`. If `userid` is any other user, the
|
|
24
|
+
* call fails. An expired token is refreshed automatically when a refresh token
|
|
25
|
+
* is available.
|
|
32
26
|
*
|
|
33
|
-
* @param userid - The user
|
|
27
|
+
* @param userid - The ID of the user who made the current request, such as the
|
|
28
|
+
* `id` returned by {@link AuthModule | base44.auth.me()}.
|
|
34
29
|
* @returns Promise resolving to the SSO access token response.
|
|
35
30
|
*
|
|
36
31
|
* @example
|
|
37
32
|
* ```typescript
|
|
38
|
-
* // Get SSO access token
|
|
39
|
-
*
|
|
40
|
-
*
|
|
33
|
+
* // Get the user's SSO access token to call an external system
|
|
34
|
+
* import { createClientFromRequest } from 'npm:@base44/sdk';
|
|
35
|
+
*
|
|
36
|
+
* Deno.serve(async (req) => {
|
|
37
|
+
* const base44 = createClientFromRequest(req);
|
|
38
|
+
* const user = await base44.auth.me();
|
|
39
|
+
* const { access_token } = await base44.asServiceRole.sso.getAccessToken(user.id);
|
|
40
|
+
*
|
|
41
|
+
* return Response.json({ access_token });
|
|
42
|
+
* });
|
|
41
43
|
* ```
|
|
42
44
|
*/
|
|
43
45
|
getAccessToken(userid: string): Promise<SsoAccessTokenResponse>;
|
|
44
46
|
/**
|
|
45
|
-
* Gets the stored SSO OIDC ID token for the current
|
|
47
|
+
* Gets the stored SSO OIDC ID token for the user who made the current request.
|
|
46
48
|
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
49
|
+
* This only works for that same user, not for arbitrary users. Create the
|
|
50
|
+
* client with {@link createClientFromRequest} so it acts on behalf of the
|
|
51
|
+
* request's user, then pass that user's ID as `userid`. If `userid` is any
|
|
52
|
+
* other user, the call fails. The stored token is returned as-is and is never
|
|
53
|
+
* refreshed, so the call fails if the token has already expired.
|
|
50
54
|
*
|
|
51
|
-
* @param userid - The
|
|
55
|
+
* @param userid - The ID of the user who made the current request, such as the
|
|
56
|
+
* `id` returned by {@link AuthModule | base44.auth.me()}.
|
|
52
57
|
* @returns Promise resolving to the raw ID-token string.
|
|
53
58
|
*
|
|
54
59
|
* @example
|
|
55
60
|
* ```typescript
|
|
61
|
+
* // Get the user's ID token to read identity claims such as email
|
|
56
62
|
* import { createClientFromRequest } from 'npm:@base44/sdk';
|
|
57
63
|
*
|
|
58
64
|
* Deno.serve(async (req) => {
|