@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, appId }),
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, appId }),
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, appId, }: AiGatewayModuleConfig): AiGatewayModule;
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, appId, }) {
2
+ export function createAiGatewayModule({ serverUrl, token, }) {
3
3
  const connection = () => {
4
4
  var _a;
5
5
  return ({
6
- baseURL: `${serverUrl}/api/apps/${appId}/ai/openai/v1`,
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
- * client pointed at the Base44 AI Gateway.
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 or call models directly from your backend code
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
- * import { ToolLoopAgent, tool, stepCountIs, hasToolCall } from "ai";
51
- * import { createOpenAICompatible } from "@ai-sdk/openai-compatible";
52
- * import { z } from "zod";
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
- * 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 });
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
- * 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")],
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
- * await agent.generate({ prompt: `Review this return request: ${JSON.stringify(request)}` });
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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@base44-preview/sdk",
3
- "version": "0.8.37-pr.226.49a8ffd",
3
+ "version": "0.8.37-pr.227.6e9ea56",
4
4
  "description": "JavaScript SDK for Base44 API",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",