@base44-preview/sdk 0.8.39-pr.231.cbd75f8 → 0.8.39-pr.232.affea8a
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.
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* A connection to the Base44 AI Gateway.
|
|
3
|
+
*
|
|
4
|
+
* Contains the base URL and bearer token to use with any OpenAI-compatible
|
|
5
|
+
* client pointed at the Base44 AI Gateway.
|
|
3
6
|
*/
|
|
4
7
|
export interface AiGatewayConnection {
|
|
5
|
-
/** Base URL of the gateway's OpenAI-compatible
|
|
8
|
+
/** Base URL of the gateway's OpenAI-compatible endpoint. */
|
|
6
9
|
baseURL: string;
|
|
7
|
-
/**
|
|
8
|
-
* Bearer token that authenticates the request. Empty string when the caller is
|
|
9
|
-
* unauthenticated.
|
|
10
|
-
*/
|
|
10
|
+
/** Bearer token used to authenticate requests to the gateway. */
|
|
11
11
|
token: string;
|
|
12
12
|
}
|
|
13
13
|
/**
|
|
@@ -25,47 +25,13 @@ export interface AiGatewayModuleConfig {
|
|
|
25
25
|
/**
|
|
26
26
|
* AI Gateway module for calling Base44's managed AI models from your own code.
|
|
27
27
|
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
* instead of OpenAI's own servers. Pass `connection()`'s values to one of
|
|
33
|
-
* these clients and it works against Base44's gateway exactly as it would
|
|
34
|
-
* against the provider directly, no separate account, API key, or billing
|
|
35
|
-
* setup with the underlying model provider required.
|
|
36
|
-
*
|
|
37
|
-
* Call `connection()` from a backend function rather than the browser. That's
|
|
38
|
-
* where your instructions, tools, and business logic stay server-side, where
|
|
39
|
-
* users can't inspect or tamper with them, and where you can enforce your own
|
|
40
|
-
* auth checks, rate limits, or spend limits around the call. `token` is the
|
|
41
|
-
* caller's own session token, the same one the SDK already uses for every
|
|
42
|
-
* other call, so calling from the browser doesn't expose anything new.
|
|
43
|
-
*
|
|
44
|
-
* ## Models
|
|
45
|
-
*
|
|
46
|
-
* Build AI agents or call models directly from your app's backend functions.
|
|
47
|
-
* Pass `'automatic'` to let Base44 choose a model, or pin a specific one such
|
|
48
|
-
* as `'claude_sonnet_4_6'`, `'gpt_5_5'`, or `'gemini_3_1_pro'`.
|
|
49
|
-
*
|
|
50
|
-
* See the [`model` options on `InvokeLLM`](/developers/references/sdk/docs/type-aliases/integrations#invokellm)
|
|
51
|
-
* for the current set of models you can use.
|
|
52
|
-
*
|
|
53
|
-
* ## Authentication Modes
|
|
54
|
-
*
|
|
55
|
-
* This module is available to use with a client in all authentication modes:
|
|
56
|
-
*
|
|
57
|
-
* - **Anonymous or User authentication** (`base44.aiGateway`): The gateway connection is scoped to the current user's permissions.
|
|
58
|
-
* - **Service role authentication** (`base44.asServiceRole.aiGateway`): The gateway connection uses the service role for backend code that needs elevated permissions.
|
|
59
|
-
*
|
|
60
|
-
* ## Billing and limits
|
|
28
|
+
* The gateway exposes an OpenAI-compatible Chat Completions endpoint, so any
|
|
29
|
+
* OpenAI-compatible SDK works against it:
|
|
30
|
+
* - Build custom AI agents or call models directly from your backend code
|
|
31
|
+
* - Uses your app's models, billing, and credit quota, no API key to manage
|
|
61
32
|
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
* app runs out of credits, the gateway stops working for every user of the
|
|
65
|
-
* app until the quota resets. A request is rejected before the model runs if
|
|
66
|
-
* the app is out of credits.
|
|
67
|
-
*
|
|
68
|
-
* Streaming responses aren't supported yet, so leave `stream` unset on your requests.
|
|
33
|
+
* Available in user authentication mode (`base44.aiGateway`) and with the
|
|
34
|
+
* service-role token via `base44.asServiceRole.aiGateway`.
|
|
69
35
|
*/
|
|
70
36
|
export interface AiGatewayModule {
|
|
71
37
|
/**
|
|
@@ -73,36 +39,19 @@ export interface AiGatewayModule {
|
|
|
73
39
|
*
|
|
74
40
|
* Returns the `baseURL` and `token` to pass to any OpenAI-compatible client.
|
|
75
41
|
*
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
-
*
|
|
79
|
-
* ```typescript
|
|
80
|
-
* // Call a model directly with the OpenAI SDK, inside a backend function
|
|
81
|
-
* import { createClientFromRequest } from "@base44/sdk";
|
|
82
|
-
* import OpenAI from "openai";
|
|
42
|
+
* The `token` is the current caller's bearer token: the app user's token for
|
|
43
|
+
* `base44.aiGateway`, or the service-role token for `base44.asServiceRole.aiGateway`.
|
|
44
|
+
* When the caller is unauthenticated, `token` is an empty string.
|
|
83
45
|
*
|
|
84
|
-
*
|
|
85
|
-
* const { baseURL, token } = base44.aiGateway.connection();
|
|
86
|
-
* const openai = new OpenAI({ baseURL, apiKey: token });
|
|
87
|
-
*
|
|
88
|
-
* const response = await openai.chat.completions.create({
|
|
89
|
-
* model: "automatic",
|
|
90
|
-
* messages: [{ role: "user", content: "Summarize this week's top support tickets." }],
|
|
91
|
-
* });
|
|
92
|
-
*
|
|
93
|
-
* console.log(response.choices[0].message.content);
|
|
94
|
-
* ```
|
|
46
|
+
* @returns The gateway {@linkcode AiGatewayConnection | connection} (`baseURL` and `token`).
|
|
95
47
|
*
|
|
96
48
|
* @example
|
|
97
49
|
* ```typescript
|
|
98
|
-
* // Review a return request with a tool-using agent, inside a backend function
|
|
99
|
-
* import { createClientFromRequest } from "@base44/sdk";
|
|
100
50
|
* import { ToolLoopAgent, tool, stepCountIs, hasToolCall } from "ai";
|
|
101
51
|
* import { createOpenAICompatible } from "@ai-sdk/openai-compatible";
|
|
102
52
|
* import { z } from "zod";
|
|
103
53
|
*
|
|
104
|
-
* const
|
|
105
|
-
* const returnRequest = await base44.entities.ReturnRequest.get(returnId);
|
|
54
|
+
* const request = await base44.entities.ReturnRequest.get(returnId);
|
|
106
55
|
* const { baseURL, token } = base44.aiGateway.connection();
|
|
107
56
|
* // Point any OpenAI-compatible client at `baseURL` with `apiKey: token`.
|
|
108
57
|
* const models = createOpenAICompatible({ name: "base44", baseURL, apiKey: token });
|
|
@@ -117,7 +66,7 @@ export interface AiGatewayModule {
|
|
|
117
66
|
* description: "This customer's past orders, optionally filtered by status",
|
|
118
67
|
* inputSchema: z.object({ status: z.string().optional() }),
|
|
119
68
|
* execute: ({ status }) => {
|
|
120
|
-
* const query = { customer_email:
|
|
69
|
+
* const query = { customer_email: request.customer_email };
|
|
121
70
|
* if (status) query.status = status;
|
|
122
71
|
* return base44.entities.Order.filter(query, "-created_date", 50);
|
|
123
72
|
* },
|
|
@@ -132,7 +81,7 @@ export interface AiGatewayModule {
|
|
|
132
81
|
* stopWhen: [stepCountIs(8), hasToolCall("submitVerdict")],
|
|
133
82
|
* });
|
|
134
83
|
*
|
|
135
|
-
* await agent.generate({ prompt: `Review this return request: ${JSON.stringify(
|
|
84
|
+
* await agent.generate({ prompt: `Review this return request: ${JSON.stringify(request)}` });
|
|
136
85
|
* ```
|
|
137
86
|
*/
|
|
138
87
|
connection(): AiGatewayConnection;
|