@base44-preview/sdk 0.8.35-pr.213.b3debb7 → 0.8.35-pr.214.4f9e502
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 +5 -0
- package/dist/client.types.d.ts +5 -0
- package/dist/index.d.ts +1 -0
- package/dist/modules/ai-gateway.d.ts +2 -0
- package/dist/modules/ai-gateway.js +18 -0
- package/dist/modules/ai-gateway.types.d.ts +68 -0
- package/dist/modules/ai-gateway.types.js +1 -0
- package/dist/modules/types.d.ts +1 -0
- package/dist/modules/types.js +1 -0
- package/package.json +1 -1
package/dist/client.js
CHANGED
|
@@ -7,6 +7,7 @@ import { createConnectorsModule, createUserConnectorsModule, } from "./modules/c
|
|
|
7
7
|
import { getAccessToken } from "./utils/auth-utils.js";
|
|
8
8
|
import { createFunctionsModule } from "./modules/functions.js";
|
|
9
9
|
import { createAgentsModule } from "./modules/agents.js";
|
|
10
|
+
import { createAiGatewayModule } from "./modules/ai-gateway.js";
|
|
10
11
|
import { createAppLogsModule } from "./modules/app-logs.js";
|
|
11
12
|
import { createUsersModule } from "./modules/users.js";
|
|
12
13
|
import { RoomsSocket } from "./utils/socket-utils.js";
|
|
@@ -150,6 +151,7 @@ export function createClient(config) {
|
|
|
150
151
|
serverUrl,
|
|
151
152
|
token,
|
|
152
153
|
}),
|
|
154
|
+
aiGateway: createAiGatewayModule({ serverUrl, appBaseUrl: normalizedAppBaseUrl, token }),
|
|
153
155
|
appLogs: createAppLogsModule(axiosClient, appId),
|
|
154
156
|
users: createUsersModule(axiosClient, appId),
|
|
155
157
|
analytics: createAnalyticsModule({
|
|
@@ -192,6 +194,7 @@ export function createClient(config) {
|
|
|
192
194
|
serverUrl,
|
|
193
195
|
token,
|
|
194
196
|
}),
|
|
197
|
+
aiGateway: createAiGatewayModule({ serverUrl, appBaseUrl: normalizedAppBaseUrl, token: serviceToken }),
|
|
195
198
|
appLogs: createAppLogsModule(serviceRoleAxiosClient, appId),
|
|
196
199
|
cleanup: () => {
|
|
197
200
|
if (socket) {
|
|
@@ -341,6 +344,7 @@ export function createClientFromRequest(request) {
|
|
|
341
344
|
const serviceRoleAuthHeader = request.headers.get("Base44-Service-Authorization");
|
|
342
345
|
const appId = request.headers.get("Base44-App-Id");
|
|
343
346
|
const serverUrlHeader = request.headers.get("Base44-Api-Url");
|
|
347
|
+
const appBaseUrlHeader = request.headers.get("Base44-App-Base-Url");
|
|
344
348
|
const functionsVersion = request.headers.get("Base44-Functions-Version");
|
|
345
349
|
const stateHeader = request.headers.get("Base44-State");
|
|
346
350
|
if (!appId) {
|
|
@@ -372,6 +376,7 @@ export function createClientFromRequest(request) {
|
|
|
372
376
|
}
|
|
373
377
|
return createClient({
|
|
374
378
|
serverUrl: serverUrlHeader || "https://base44.app",
|
|
379
|
+
appBaseUrl: appBaseUrlHeader !== null && appBaseUrlHeader !== void 0 ? appBaseUrlHeader : undefined,
|
|
375
380
|
appId,
|
|
376
381
|
token: userToken,
|
|
377
382
|
serviceToken: serviceRoleToken,
|
package/dist/client.types.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ import type { SsoModule } from "./modules/sso.types.js";
|
|
|
5
5
|
import type { ConnectorsModule, UserConnectorsModule } from "./modules/connectors.types.js";
|
|
6
6
|
import type { FunctionsModule } from "./modules/functions.types.js";
|
|
7
7
|
import type { AgentsModule } from "./modules/agents.types.js";
|
|
8
|
+
import type { AiGatewayModule } from "./modules/ai-gateway.types.js";
|
|
8
9
|
import type { AppLogsModule } from "./modules/app-logs.types.js";
|
|
9
10
|
import type { AnalyticsModule } from "./modules/analytics.types.js";
|
|
10
11
|
/**
|
|
@@ -81,6 +82,8 @@ export interface CreateClientConfig {
|
|
|
81
82
|
export interface Base44Client {
|
|
82
83
|
/** {@link AgentsModule | Agents module} for managing AI agent conversations. */
|
|
83
84
|
agents: AgentsModule;
|
|
85
|
+
/** {@link AiGatewayModule | AI Gateway module} for connecting to the Base44 AI Gateway with your own SDK. */
|
|
86
|
+
aiGateway: AiGatewayModule;
|
|
84
87
|
/** {@link AnalyticsModule | Analytics module} for tracking custom events in your app. */
|
|
85
88
|
analytics: AnalyticsModule;
|
|
86
89
|
/** {@link AppLogsModule | App logs module} for tracking app usage. */
|
|
@@ -124,6 +127,8 @@ export interface Base44Client {
|
|
|
124
127
|
readonly asServiceRole: {
|
|
125
128
|
/** {@link AgentsModule | Agents module} with elevated permissions. */
|
|
126
129
|
agents: AgentsModule;
|
|
130
|
+
/** {@link AiGatewayModule | AI Gateway module} with the service-role token. */
|
|
131
|
+
aiGateway: AiGatewayModule;
|
|
127
132
|
/** {@link AppLogsModule | App logs module} with elevated permissions. */
|
|
128
133
|
appLogs: AppLogsModule;
|
|
129
134
|
/** {@link ConnectorsModule | Connectors module} for OAuth token retrieval. */
|
package/dist/index.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ export type { AuthModule, LoginResponse, RegisterParams, VerifyOtpParams, Change
|
|
|
9
9
|
export type { IntegrationsModule, IntegrationEndpointFunction, CoreIntegrations, InvokeLLMParams, GenerateImageParams, GenerateImageResult, UploadFileParams, UploadFileResult, SendEmailParams, SendEmailResult, ExtractDataFromUploadedFileParams, ExtractDataFromUploadedFileResult, UploadPrivateFileParams, UploadPrivateFileResult, CreateFileSignedUrlParams, CreateFileSignedUrlResult, } from "./modules/integrations.types.js";
|
|
10
10
|
export type { FunctionsModule, FunctionName, FunctionNameRegistry, } from "./modules/functions.types.js";
|
|
11
11
|
export type { AgentsModule, AgentName, AgentNameRegistry, AgentConversation, AgentMessage, AgentMessageReasoning, AgentMessageToolCall, AgentMessageUsage, AgentMessageCustomContext, AgentMessageMetadata, CreateConversationParams, } from "./modules/agents.types.js";
|
|
12
|
+
export type { AiGatewayModule, AiGatewayConnection, } from "./modules/ai-gateway.types.js";
|
|
12
13
|
export type { AppLogsModule } from "./modules/app-logs.types.js";
|
|
13
14
|
export type { SsoModule, SsoAccessTokenResponse } from "./modules/sso.types.js";
|
|
14
15
|
export type { ConnectorsModule, UserConnectorsModule, } from "./modules/connectors.types.js";
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { getAccessToken } from "../utils/auth-utils.js";
|
|
2
|
+
export function createAiGatewayModule({ serverUrl, appBaseUrl, token, }) {
|
|
3
|
+
// The gateway is a domain-resolved route: it only answers on the app's own
|
|
4
|
+
// domain. In the browser serverUrl is that domain already; in backend
|
|
5
|
+
// functions serverUrl is the API host, so prefer the app's public base URL
|
|
6
|
+
// (propagated via the Base44-App-Base-Url header) when available.
|
|
7
|
+
const gatewayOrigin = appBaseUrl || serverUrl;
|
|
8
|
+
const connection = () => {
|
|
9
|
+
var _a;
|
|
10
|
+
return ({
|
|
11
|
+
baseURL: `${gatewayOrigin}/api/ai/openai/v1`,
|
|
12
|
+
token: (_a = token !== null && token !== void 0 ? token : getAccessToken()) !== null && _a !== void 0 ? _a : "",
|
|
13
|
+
});
|
|
14
|
+
};
|
|
15
|
+
return {
|
|
16
|
+
connection,
|
|
17
|
+
};
|
|
18
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A connection to the Base44 AI Gateway.
|
|
3
|
+
*
|
|
4
|
+
* Contains the base URL and bearer token to use with any OpenAI-compatible client
|
|
5
|
+
* (the OpenAI SDK, Mastra, and others) pointed at the Base44 AI Gateway.
|
|
6
|
+
*/
|
|
7
|
+
export interface AiGatewayConnection {
|
|
8
|
+
/** Base URL of the gateway's OpenAI-compatible endpoint. */
|
|
9
|
+
baseURL: string;
|
|
10
|
+
/** Bearer token used to authenticate requests to the gateway. */
|
|
11
|
+
token: string;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Configuration for the AI Gateway module.
|
|
15
|
+
* @internal
|
|
16
|
+
*/
|
|
17
|
+
export interface AiGatewayModuleConfig {
|
|
18
|
+
/** Server URL */
|
|
19
|
+
serverUrl?: string;
|
|
20
|
+
/** The app's own public base URL (e.g. https://my-app.base44.app). Preferred over
|
|
21
|
+
* serverUrl for the gateway URL, since the gateway resolves the app by domain. */
|
|
22
|
+
appBaseUrl?: string;
|
|
23
|
+
/** Authentication token */
|
|
24
|
+
token?: string;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* The AI Gateway module.
|
|
28
|
+
*
|
|
29
|
+
* Exposes the connection details for the Base44 AI Gateway so you can call it from
|
|
30
|
+
* your own code using any OpenAI-compatible SDK — for example, to build a custom
|
|
31
|
+
* agent on top of the gateway.
|
|
32
|
+
*/
|
|
33
|
+
export interface AiGatewayModule {
|
|
34
|
+
/**
|
|
35
|
+
* Gets the connection details for the Base44 AI Gateway.
|
|
36
|
+
*
|
|
37
|
+
* Returns the `baseURL` and `token` to pass to any OpenAI-compatible client (the
|
|
38
|
+
* OpenAI SDK, Mastra, and others), so you can call the gateway from your own code
|
|
39
|
+
* without constructing the URL or handling the token yourself.
|
|
40
|
+
*
|
|
41
|
+
* The `token` is the current caller's bearer token: the app user's token for
|
|
42
|
+
* `base44.aiGateway`, or the service-role token for `base44.asServiceRole.aiGateway`.
|
|
43
|
+
* When the caller is unauthenticated, `token` is an empty string and gateway
|
|
44
|
+
* requests will be rejected.
|
|
45
|
+
*
|
|
46
|
+
* @returns The gateway {@linkcode AiGatewayConnection | connection} (`baseURL` and `token`).
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```typescript
|
|
50
|
+
* // Inside a backend function, call the gateway with any OpenAI-compatible SDK
|
|
51
|
+
* import { createClientFromRequest } from 'npm:@base44/sdk';
|
|
52
|
+
* import OpenAI from 'npm:openai';
|
|
53
|
+
*
|
|
54
|
+
* Deno.serve(async (req) => {
|
|
55
|
+
* const base44 = createClientFromRequest(req);
|
|
56
|
+
* const { baseURL, token } = base44.aiGateway.connection();
|
|
57
|
+
*
|
|
58
|
+
* const openai = new OpenAI({ baseURL, apiKey: token });
|
|
59
|
+
* const res = await openai.chat.completions.create({
|
|
60
|
+
* model: 'claude_sonnet_4_6',
|
|
61
|
+
* messages: [{ role: 'user', content: 'Hello!' }],
|
|
62
|
+
* });
|
|
63
|
+
* return Response.json({ text: res.choices[0].message.content });
|
|
64
|
+
* });
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
connection(): AiGatewayConnection;
|
|
68
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/modules/types.d.ts
CHANGED
package/dist/modules/types.js
CHANGED