@base44-preview/sdk 0.8.37-pr.226.49a8ffd → 0.8.37-pr.227.6e9ea56
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 }),
|
|
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 }),
|
|
198
198
|
appLogs: createAppLogsModule(serviceRoleAxiosClient, appId),
|
|
199
199
|
cleanup: () => {
|
|
200
200
|
if (socket) {
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { AiGatewayModule, AiGatewayModuleConfig } from "./ai-gateway.types.js";
|
|
2
|
-
export declare function createAiGatewayModule({ serverUrl, token,
|
|
2
|
+
export declare function createAiGatewayModule({ serverUrl, token, }: 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, }) {
|
|
3
3
|
const connection = () => {
|
|
4
4
|
var _a;
|
|
5
5
|
return ({
|
|
6
|
-
baseURL: `${serverUrl}/api/
|
|
6
|
+
baseURL: `${serverUrl}/api/ai/openai/v1`,
|
|
7
7
|
token: (_a = token !== null && token !== void 0 ? token : getAccessToken()) !== null && _a !== void 0 ? _a : "",
|
|
8
8
|
});
|
|
9
9
|
};
|
|
@@ -1,8 +1,9 @@
|
|
|
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
|
-
*
|
|
4
|
+
* Contains the base URL and bearer token to use with any OpenAI-compatible client
|
|
5
|
+
* (OpenAI SDK, Mastra, Vercel AI SDK, and others) pointed at the Base44 AI
|
|
6
|
+
* Gateway.
|
|
6
7
|
*/
|
|
7
8
|
export interface AiGatewayConnection {
|
|
8
9
|
/** Base URL of the gateway's OpenAI-compatible endpoint. */
|
|
@@ -19,15 +20,13 @@ export interface AiGatewayModuleConfig {
|
|
|
19
20
|
serverUrl?: string;
|
|
20
21
|
/** Authentication token */
|
|
21
22
|
token?: string;
|
|
22
|
-
/** Application ID */
|
|
23
|
-
appId: string;
|
|
24
23
|
}
|
|
25
24
|
/**
|
|
26
25
|
* AI Gateway module for calling Base44's managed AI models from your own code.
|
|
27
26
|
*
|
|
28
27
|
* The gateway exposes an OpenAI-compatible Chat Completions endpoint, so any
|
|
29
28
|
* OpenAI-compatible SDK works against it:
|
|
30
|
-
* - Build custom AI agents
|
|
29
|
+
* - Build custom AI agents with agent SDKs such as Mastra or the Vercel AI SDK
|
|
31
30
|
* - Uses your app's models, billing, and credit quota, no API key to manage
|
|
32
31
|
*
|
|
33
32
|
* Available in user authentication mode (`base44.aiGateway`) and with the
|
|
@@ -47,41 +46,55 @@ export interface AiGatewayModule {
|
|
|
47
46
|
*
|
|
48
47
|
* @example
|
|
49
48
|
* ```typescript
|
|
50
|
-
*
|
|
51
|
-
* import {
|
|
52
|
-
* import {
|
|
49
|
+
* // Build an AI agent with Mastra on top of the gateway, inside a backend function
|
|
50
|
+
* import { createClientFromRequest } from 'npm:@base44/sdk';
|
|
51
|
+
* import { Agent } from 'npm:@mastra/core/agent';
|
|
52
|
+
* import { createTool } from 'npm:@mastra/core/tools';
|
|
53
|
+
* import { createOpenAICompatible } from 'npm:@ai-sdk/openai-compatible';
|
|
54
|
+
* import { z } from 'npm:zod';
|
|
53
55
|
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
*
|
|
56
|
+
* Deno.serve(async (req) => {
|
|
57
|
+
* const base44 = createClientFromRequest(req);
|
|
58
|
+
* const { baseURL, token } = base44.aiGateway.connection();
|
|
59
|
+
* const models = createOpenAICompatible({ name: 'base44', baseURL, apiKey: token });
|
|
58
60
|
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
*
|
|
75
|
-
*
|
|
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")],
|
|
61
|
+
* const agent = new Agent({
|
|
62
|
+
* id: 'order-helper',
|
|
63
|
+
* name: 'order-helper',
|
|
64
|
+
* instructions: 'Help the user with their orders.',
|
|
65
|
+
* model: models('claude_sonnet_4_6'),
|
|
66
|
+
* tools: {
|
|
67
|
+
* lookupOrder: createTool({
|
|
68
|
+
* id: 'lookup-order',
|
|
69
|
+
* description: 'Fetch an order by id',
|
|
70
|
+
* inputSchema: z.object({ orderId: z.string() }),
|
|
71
|
+
* execute: async ({ orderId }) => base44.entities.Order.get(orderId),
|
|
72
|
+
* }),
|
|
73
|
+
* },
|
|
74
|
+
* });
|
|
75
|
+
*
|
|
76
|
+
* const { text } = await agent.generate('Where is order 123?');
|
|
77
|
+
* return Response.json({ text });
|
|
82
78
|
* });
|
|
79
|
+
* ```
|
|
83
80
|
*
|
|
84
|
-
*
|
|
81
|
+
* @example
|
|
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
|
+
* });
|
|
85
98
|
* ```
|
|
86
99
|
*/
|
|
87
100
|
connection(): AiGatewayConnection;
|