@base44-preview/sdk 0.8.37-pr.224.eb846f3 → 0.8.37-pr.226.49a8ffd
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) {
|
|
@@ -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;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import axios from "axios";
|
|
2
|
-
import { isInIFrame
|
|
2
|
+
import { isInIFrame } from "./common.js";
|
|
3
|
+
import { v4 as uuidv4 } from "uuid";
|
|
3
4
|
import { getAnalyticsSessionId } from "../modules/analytics.js";
|
|
4
5
|
/**
|
|
5
6
|
* Custom error class for Base44 SDK errors.
|
|
@@ -140,10 +141,7 @@ export function createAxiosClient({ baseURL, headers = {}, token, interceptRespo
|
|
|
140
141
|
config.headers.set("X-Base44-Anonymous-Id", getAnalyticsSessionId());
|
|
141
142
|
}
|
|
142
143
|
}
|
|
143
|
-
|
|
144
|
-
// unique, not cryptographically random. `uuid` would pull in
|
|
145
|
-
// `crypto.getRandomValues`, which React Native lacks, so use `generateUuid`.
|
|
146
|
-
const requestId = generateUuid();
|
|
144
|
+
const requestId = uuidv4();
|
|
147
145
|
config.requestId = requestId;
|
|
148
146
|
if (isInIFrame) {
|
|
149
147
|
try {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@base44-preview/sdk",
|
|
3
|
-
"version": "0.8.37-pr.
|
|
3
|
+
"version": "0.8.37-pr.226.49a8ffd",
|
|
4
4
|
"description": "JavaScript SDK for Base44 API",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -27,7 +27,8 @@
|
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"axios": "^1.17.0",
|
|
30
|
-
"socket.io-client": "^4.8.3"
|
|
30
|
+
"socket.io-client": "^4.8.3",
|
|
31
|
+
"uuid": "^13.0.2"
|
|
31
32
|
},
|
|
32
33
|
"devDependencies": {
|
|
33
34
|
"@types/hast": "^3.0.4",
|