@base44-preview/sdk 0.8.37-pr.228.93ccd45 → 0.8.38-pr.219.9f3b9dd
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
|
@@ -151,7 +151,7 @@ export function createClient(config) {
|
|
|
151
151
|
serverUrl,
|
|
152
152
|
token,
|
|
153
153
|
}),
|
|
154
|
-
aiGateway: createAiGatewayModule({ serverUrl, token }),
|
|
154
|
+
aiGateway: createAiGatewayModule({ serverUrl, token, appId }),
|
|
155
155
|
appLogs: createAppLogsModule(axiosClient, appId),
|
|
156
156
|
users: createUsersModule(axiosClient, appId),
|
|
157
157
|
analytics: createAnalyticsModule({
|
|
@@ -194,7 +194,7 @@ export function createClient(config) {
|
|
|
194
194
|
serverUrl,
|
|
195
195
|
token,
|
|
196
196
|
}),
|
|
197
|
-
aiGateway: createAiGatewayModule({ serverUrl, token: serviceToken }),
|
|
197
|
+
aiGateway: createAiGatewayModule({ serverUrl, token: serviceToken, appId }),
|
|
198
198
|
appLogs: createAppLogsModule(serviceRoleAxiosClient, appId),
|
|
199
199
|
cleanup: () => {
|
|
200
200
|
if (socket) {
|
|
@@ -346,7 +346,6 @@ 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");
|
|
350
349
|
if (!appId) {
|
|
351
350
|
throw new Error("Base44-App-Id header is required, but is was not found on the request");
|
|
352
351
|
}
|
|
@@ -374,14 +373,6 @@ export function createClientFromRequest(request) {
|
|
|
374
373
|
if (stateHeader) {
|
|
375
374
|
additionalHeaders["Base44-State"] = stateHeader;
|
|
376
375
|
}
|
|
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
|
-
if (dataEnvHeader) {
|
|
383
|
-
additionalHeaders["X-Data-Env"] = dataEnvHeader;
|
|
384
|
-
}
|
|
385
376
|
return createClient({
|
|
386
377
|
serverUrl: serverUrlHeader || "https://base44.app",
|
|
387
378
|
appId,
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { AiGatewayModule, AiGatewayModuleConfig } from "./ai-gateway.types.js";
|
|
2
|
-
export declare function createAiGatewayModule({ serverUrl, token, }: AiGatewayModuleConfig): AiGatewayModule;
|
|
2
|
+
export declare function createAiGatewayModule({ serverUrl, token, appId, }: AiGatewayModuleConfig): AiGatewayModule;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { getAccessToken } from "../utils/auth-utils.js";
|
|
2
|
-
export function createAiGatewayModule({ serverUrl, token, }) {
|
|
2
|
+
export function createAiGatewayModule({ serverUrl, token, appId, }) {
|
|
3
3
|
const connection = () => {
|
|
4
4
|
var _a;
|
|
5
5
|
return ({
|
|
6
|
-
baseURL: `${serverUrl}/api/ai/openai/v1`,
|
|
6
|
+
baseURL: `${serverUrl}/api/apps/${appId}/ai/openai/v1`,
|
|
7
7
|
token: (_a = token !== null && token !== void 0 ? token : getAccessToken()) !== null && _a !== void 0 ? _a : "",
|
|
8
8
|
});
|
|
9
9
|
};
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* A connection to the Base44 AI Gateway.
|
|
3
3
|
*
|
|
4
|
-
* Contains the base URL and bearer token to use with any OpenAI-compatible
|
|
5
|
-
*
|
|
6
|
-
* Gateway.
|
|
4
|
+
* Contains the base URL and bearer token to use with any OpenAI-compatible
|
|
5
|
+
* client pointed at the Base44 AI Gateway.
|
|
7
6
|
*/
|
|
8
7
|
export interface AiGatewayConnection {
|
|
9
8
|
/** Base URL of the gateway's OpenAI-compatible endpoint. */
|
|
@@ -20,13 +19,15 @@ export interface AiGatewayModuleConfig {
|
|
|
20
19
|
serverUrl?: string;
|
|
21
20
|
/** Authentication token */
|
|
22
21
|
token?: string;
|
|
22
|
+
/** Application ID */
|
|
23
|
+
appId: string;
|
|
23
24
|
}
|
|
24
25
|
/**
|
|
25
26
|
* AI Gateway module for calling Base44's managed AI models from your own code.
|
|
26
27
|
*
|
|
27
28
|
* The gateway exposes an OpenAI-compatible Chat Completions endpoint, so any
|
|
28
29
|
* OpenAI-compatible SDK works against it:
|
|
29
|
-
* - Build custom AI agents
|
|
30
|
+
* - Build custom AI agents or call models directly from your backend code
|
|
30
31
|
* - Uses your app's models, billing, and credit quota, no API key to manage
|
|
31
32
|
*
|
|
32
33
|
* Available in user authentication mode (`base44.aiGateway`) and with the
|
|
@@ -46,55 +47,41 @@ export interface AiGatewayModule {
|
|
|
46
47
|
*
|
|
47
48
|
* @example
|
|
48
49
|
* ```typescript
|
|
49
|
-
*
|
|
50
|
-
* import {
|
|
51
|
-
* import {
|
|
52
|
-
* import { createTool } from 'npm:@mastra/core/tools';
|
|
53
|
-
* import { createOpenAICompatible } from 'npm:@ai-sdk/openai-compatible';
|
|
54
|
-
* import { z } from 'npm:zod';
|
|
50
|
+
* import { ToolLoopAgent, tool, stepCountIs, hasToolCall } from "ai";
|
|
51
|
+
* import { createOpenAICompatible } from "@ai-sdk/openai-compatible";
|
|
52
|
+
* import { z } from "zod";
|
|
55
53
|
*
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
54
|
+
* const request = await base44.entities.ReturnRequest.get(returnId);
|
|
55
|
+
* const { baseURL, token } = base44.aiGateway.connection();
|
|
56
|
+
* // Point any OpenAI-compatible client at `baseURL` with `apiKey: token`.
|
|
57
|
+
* const models = createOpenAICompatible({ name: "base44", baseURL, apiKey: token });
|
|
60
58
|
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
*
|
|
59
|
+
* const agent = new ToolLoopAgent({
|
|
60
|
+
* model: models("automatic"),
|
|
61
|
+
* instructions:
|
|
62
|
+
* "Decide whether this return looks fine or needs the owner's attention. " +
|
|
63
|
+
* "Check the customer's past orders, then submit your verdict.",
|
|
64
|
+
* tools: {
|
|
65
|
+
* searchOrders: tool({
|
|
66
|
+
* description: "This customer's past orders, optionally filtered by status",
|
|
67
|
+
* inputSchema: z.object({ status: z.string().optional() }),
|
|
68
|
+
* execute: ({ status }) => {
|
|
69
|
+
* const query = { customer_email: request.customer_email };
|
|
70
|
+
* if (status) query.status = status;
|
|
71
|
+
* return base44.entities.Order.filter(query, "-created_date", 50);
|
|
72
|
+
* },
|
|
73
|
+
* }),
|
|
74
|
+
* submitVerdict: tool({
|
|
75
|
+
* description: "Record the final verdict",
|
|
76
|
+
* inputSchema: z.object({ decision: z.enum(["approved", "flagged"]), reason: z.string() }),
|
|
77
|
+
* execute: ({ decision, reason }) =>
|
|
78
|
+
* base44.entities.ReturnRequest.update(returnId, { status: decision, review_note: reason }),
|
|
79
|
+
* }),
|
|
80
|
+
* },
|
|
81
|
+
* stopWhen: [stepCountIs(8), hasToolCall("submitVerdict")],
|
|
78
82
|
* });
|
|
79
|
-
* ```
|
|
80
83
|
*
|
|
81
|
-
*
|
|
82
|
-
* ```typescript
|
|
83
|
-
* // Call a model directly with the OpenAI SDK
|
|
84
|
-
* import { createClientFromRequest } from 'npm:@base44/sdk';
|
|
85
|
-
* import OpenAI from 'npm:openai';
|
|
86
|
-
*
|
|
87
|
-
* Deno.serve(async (req) => {
|
|
88
|
-
* const base44 = createClientFromRequest(req);
|
|
89
|
-
* const { baseURL, token } = base44.aiGateway.connection();
|
|
90
|
-
*
|
|
91
|
-
* const openai = new OpenAI({ baseURL, apiKey: token });
|
|
92
|
-
* const res = await openai.chat.completions.create({
|
|
93
|
-
* model: 'claude_sonnet_4_6',
|
|
94
|
-
* messages: [{ role: 'user', content: 'Hello!' }],
|
|
95
|
-
* });
|
|
96
|
-
* return Response.json({ text: res.choices[0].message.content });
|
|
97
|
-
* });
|
|
84
|
+
* await agent.generate({ prompt: `Review this return request: ${JSON.stringify(request)}` });
|
|
98
85
|
* ```
|
|
99
86
|
*/
|
|
100
87
|
connection(): AiGatewayConnection;
|