@base44-preview/sdk 0.8.32-pr.205.168e407 → 0.8.32-pr.205.c20240d
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 +1 -8
- package/dist/client.types.d.ts +1 -6
- package/dist/index.d.ts +3 -3
- package/dist/index.js +1 -1
- package/dist/modules/{agents.types.d.ts → agents/agents.types.d.ts} +336 -2
- package/dist/modules/agents/gateway.d.ts +33 -0
- package/dist/modules/{ai-gateway.js → agents/gateway.js} +3 -4
- package/dist/modules/{agents.d.ts → agents/index.d.ts} +1 -1
- package/dist/modules/{agents.js → agents/index.js} +10 -2
- package/dist/modules/agents/loop.d.ts +4 -0
- package/dist/modules/agents/loop.js +146 -0
- package/dist/modules/agents/provider.d.ts +53 -0
- package/dist/modules/agents/provider.js +1 -0
- package/dist/modules/agents/providers/openai-compatible.d.ts +8 -0
- package/dist/modules/agents/providers/openai-compatible.js +110 -0
- package/dist/modules/agents/tool.d.ts +37 -0
- package/dist/modules/agents/tool.js +38 -0
- package/dist/modules/entities.js +58 -1
- package/dist/modules/entities.types.d.ts +20 -0
- package/dist/modules/functions.types.d.ts +16 -1
- package/dist/modules/types.d.ts +1 -1
- package/dist/modules/types.js +1 -1
- package/package.json +1 -1
- package/dist/modules/ai-gateway.d.ts +0 -20
- package/dist/modules/dynamic-agents.d.ts +0 -32
- package/dist/modules/dynamic-agents.js +0 -176
- package/dist/modules/dynamic-agents.types.d.ts +0 -127
- package/dist/modules/dynamic-agents.types.js +0 -2
- /package/dist/modules/{agents.types.js → agents/agents.types.js} +0 -0
package/dist/client.js
CHANGED
|
@@ -6,8 +6,7 @@ import { createSsoModule } from "./modules/sso.js";
|
|
|
6
6
|
import { createConnectorsModule, createUserConnectorsModule, } from "./modules/connectors.js";
|
|
7
7
|
import { getAccessToken } from "./utils/auth-utils.js";
|
|
8
8
|
import { createFunctionsModule } from "./modules/functions.js";
|
|
9
|
-
import { createAgentsModule } from "./modules/agents.js";
|
|
10
|
-
import { createDynamicAgentsModule } from "./modules/dynamic-agents.js";
|
|
9
|
+
import { createAgentsModule } from "./modules/agents/index.js";
|
|
11
10
|
import { createAppLogsModule } from "./modules/app-logs.js";
|
|
12
11
|
import { createUsersModule } from "./modules/users.js";
|
|
13
12
|
import { RoomsSocket } from "./utils/socket-utils.js";
|
|
@@ -150,9 +149,6 @@ export function createClient(config) {
|
|
|
150
149
|
appId,
|
|
151
150
|
serverUrl,
|
|
152
151
|
token,
|
|
153
|
-
}),
|
|
154
|
-
dynamicAgents: createDynamicAgentsModule({
|
|
155
|
-
serverUrl,
|
|
156
152
|
getToken: () => token || getAccessToken() || undefined,
|
|
157
153
|
}),
|
|
158
154
|
appLogs: createAppLogsModule(axiosClient, appId),
|
|
@@ -196,9 +192,6 @@ export function createClient(config) {
|
|
|
196
192
|
appId,
|
|
197
193
|
serverUrl,
|
|
198
194
|
token,
|
|
199
|
-
}),
|
|
200
|
-
dynamicAgents: createDynamicAgentsModule({
|
|
201
|
-
serverUrl,
|
|
202
195
|
getToken: () => serviceToken,
|
|
203
196
|
}),
|
|
204
197
|
appLogs: createAppLogsModule(serviceRoleAxiosClient, appId),
|
package/dist/client.types.d.ts
CHANGED
|
@@ -4,10 +4,9 @@ import type { AuthModule } from "./modules/auth.types.js";
|
|
|
4
4
|
import type { SsoModule } from "./modules/sso.types.js";
|
|
5
5
|
import type { ConnectorsModule, UserConnectorsModule } from "./modules/connectors.types.js";
|
|
6
6
|
import type { FunctionsModule } from "./modules/functions.types.js";
|
|
7
|
-
import type { AgentsModule } from "./modules/agents.types.js";
|
|
7
|
+
import type { AgentsModule } from "./modules/agents/agents.types.js";
|
|
8
8
|
import type { AppLogsModule } from "./modules/app-logs.types.js";
|
|
9
9
|
import type { AnalyticsModule } from "./modules/analytics.types.js";
|
|
10
|
-
import type { DynamicAgentsModule } from "./modules/dynamic-agents.types.js";
|
|
11
10
|
/**
|
|
12
11
|
* Options for creating a Base44 client.
|
|
13
12
|
*/
|
|
@@ -86,8 +85,6 @@ export interface Base44Client {
|
|
|
86
85
|
analytics: AnalyticsModule;
|
|
87
86
|
/** {@link AppLogsModule | App logs module} for tracking app usage. */
|
|
88
87
|
appLogs: AppLogsModule;
|
|
89
|
-
/** {@link DynamicAgentsModule | Dynamic agents module} for code-defined AI agents and tool loops. */
|
|
90
|
-
dynamicAgents: DynamicAgentsModule;
|
|
91
88
|
/** {@link AuthModule | Auth module} for user authentication and management. */
|
|
92
89
|
auth: AuthModule;
|
|
93
90
|
/** {@link UserConnectorsModule | Connectors module} for app-user OAuth flows. */
|
|
@@ -129,8 +126,6 @@ export interface Base44Client {
|
|
|
129
126
|
agents: AgentsModule;
|
|
130
127
|
/** {@link AppLogsModule | App logs module} with elevated permissions. */
|
|
131
128
|
appLogs: AppLogsModule;
|
|
132
|
-
/** {@link DynamicAgentsModule | Dynamic agents module} with elevated permissions. */
|
|
133
|
-
dynamicAgents: DynamicAgentsModule;
|
|
134
129
|
/** {@link ConnectorsModule | Connectors module} for OAuth token retrieval. */
|
|
135
130
|
connectors: ConnectorsModule;
|
|
136
131
|
/** {@link EntitiesModule | Entities module} with elevated permissions. */
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createClient, createClientFromRequest, type Base44Client, type CreateClientConfig, type CreateClientOptions } from "./client.js";
|
|
2
2
|
import { Base44Error, type Base44ErrorJSON } from "./utils/axios-client.js";
|
|
3
3
|
import { getAccessToken, saveAccessToken, removeAccessToken, getLoginUrl } from "./utils/auth-utils.js";
|
|
4
|
-
import { tool } from "./modules/
|
|
4
|
+
import { tool } from "./modules/agents/tool.js";
|
|
5
5
|
export { createClient, createClientFromRequest, Base44Error, getAccessToken, saveAccessToken, removeAccessToken, getLoginUrl, tool, };
|
|
6
6
|
export type { Base44Client, CreateClientConfig, CreateClientOptions, Base44ErrorJSON, };
|
|
7
7
|
export * from "./types.js";
|
|
@@ -9,10 +9,10 @@ export type { DeleteManyResult, DeleteResult, EntitiesModule, EntityFilterOperat
|
|
|
9
9
|
export type { AuthModule, LoginResponse, RegisterParams, VerifyOtpParams, ChangePasswordParams, ResetPasswordParams, User, } from "./modules/auth.types.js";
|
|
10
10
|
export type { IntegrationsModule, IntegrationEndpointFunction, CoreIntegrations, InvokeLLMParams, GenerateImageParams, GenerateImageResult, UploadFileParams, UploadFileResult, SendEmailParams, SendEmailResult, ExtractDataFromUploadedFileParams, ExtractDataFromUploadedFileResult, UploadPrivateFileParams, UploadPrivateFileResult, CreateFileSignedUrlParams, CreateFileSignedUrlResult, } from "./modules/integrations.types.js";
|
|
11
11
|
export type { FunctionsModule, FunctionName, FunctionNameRegistry, } from "./modules/functions.types.js";
|
|
12
|
-
export type { AgentsModule, AgentName, AgentNameRegistry, AgentConversation, AgentMessage, AgentMessageReasoning, AgentMessageToolCall, AgentMessageUsage, AgentMessageCustomContext, AgentMessageMetadata, CreateConversationParams, } from "./modules/agents.types.js";
|
|
12
|
+
export type { AgentsModule, AgentName, AgentNameRegistry, AgentConversation, AgentMessage, AgentMessageReasoning, AgentMessageToolCall, AgentMessageUsage, AgentMessageCustomContext, AgentMessageMetadata, CreateConversationParams, } from "./modules/agents/agents.types.js";
|
|
13
13
|
export type { AppLogsModule } from "./modules/app-logs.types.js";
|
|
14
14
|
export type { SsoModule, SsoAccessTokenResponse } from "./modules/sso.types.js";
|
|
15
15
|
export type { ConnectorsModule, UserConnectorsModule, } from "./modules/connectors.types.js";
|
|
16
16
|
export type { CustomIntegrationsModule, CustomIntegrationCallParams, CustomIntegrationCallResponse, } from "./modules/custom-integrations.types.js";
|
|
17
|
-
export type { Tool, JSONSchema, ChatMessage, Step, RunUsage, RunResult, RunInput, RunOptions, ToolChoice, AgentConfig, Agent,
|
|
17
|
+
export type { Tool, JSONSchema, ChatMessage, Step, RunUsage, RunResult, RunInput, RunOptions, ToolChoice, AgentConfig, Agent, FinishReason, } from "./modules/agents/agents.types.js";
|
|
18
18
|
export type { GetAccessTokenOptions, SaveAccessTokenOptions, RemoveAccessTokenOptions, GetLoginUrlOptions, } from "./utils/auth-utils.types.js";
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createClient, createClientFromRequest, } from "./client.js";
|
|
2
2
|
import { Base44Error } from "./utils/axios-client.js";
|
|
3
3
|
import { getAccessToken, saveAccessToken, removeAccessToken, getLoginUrl, } from "./utils/auth-utils.js";
|
|
4
|
-
import { tool } from "./modules/
|
|
4
|
+
import { tool } from "./modules/agents/tool.js";
|
|
5
5
|
export { createClient, createClientFromRequest, Base44Error, getAccessToken, saveAccessToken, removeAccessToken, getLoginUrl, tool, };
|
|
6
6
|
export * from "./types.js";
|
|
@@ -1,6 +1,317 @@
|
|
|
1
1
|
import { AxiosInstance } from "axios";
|
|
2
|
-
import { RoomsSocket } from "
|
|
3
|
-
import { ModelFilterParams } from "
|
|
2
|
+
import { RoomsSocket } from "../../utils/socket-utils.js";
|
|
3
|
+
import { ModelFilterParams } from "../../types.js";
|
|
4
|
+
/**
|
|
5
|
+
* A JSON Schema object describing a tool's input parameters.
|
|
6
|
+
* Use the standard JSON Schema `object` shape: `{ type: "object", properties: {...}, required: [...] }`.
|
|
7
|
+
*/
|
|
8
|
+
export type JSONSchema = Record<string, unknown>;
|
|
9
|
+
/**
|
|
10
|
+
* A tool an agent can call. Create one with {@linkcode tool | tool()}, or derive it from a
|
|
11
|
+
* resource with `.asTool()`.
|
|
12
|
+
*/
|
|
13
|
+
export interface Tool {
|
|
14
|
+
/** Natural-language description the model uses to decide when to call the tool. */
|
|
15
|
+
description: string;
|
|
16
|
+
/** JSON Schema for the tool's arguments. */
|
|
17
|
+
parameters: JSONSchema;
|
|
18
|
+
/** Runs the tool. Receives parsed arguments; returns any JSON-serializable value (or a string). */
|
|
19
|
+
execute: (args: any) => Promise<unknown> | unknown;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Why the agent run ended.
|
|
23
|
+
* `"max_steps"` is set by the SDK when the step cap is hit; all other values come from the model/normalization layer.
|
|
24
|
+
*/
|
|
25
|
+
export type FinishReason = "stop" | "length" | "tool-calls" | "content-filter" | "error" | "other";
|
|
26
|
+
/** An OpenAI-shaped chat message accepted by {@linkcode Agent.run}. */
|
|
27
|
+
export interface ChatMessage {
|
|
28
|
+
role: "system" | "user" | "assistant" | "tool";
|
|
29
|
+
content?: string | null;
|
|
30
|
+
tool_calls?: Array<{
|
|
31
|
+
id: string;
|
|
32
|
+
type: "function";
|
|
33
|
+
function: {
|
|
34
|
+
name: string;
|
|
35
|
+
arguments: string;
|
|
36
|
+
};
|
|
37
|
+
}>;
|
|
38
|
+
tool_call_id?: string;
|
|
39
|
+
}
|
|
40
|
+
/** One iteration of the agent loop: the tool calls the model made and their results. */
|
|
41
|
+
export interface Step {
|
|
42
|
+
toolResults: Array<{
|
|
43
|
+
toolCallId: string;
|
|
44
|
+
toolName: string;
|
|
45
|
+
args: unknown;
|
|
46
|
+
result: string;
|
|
47
|
+
}>;
|
|
48
|
+
/** Token/credit usage of the model call that produced this step's tool calls. */
|
|
49
|
+
usage?: RunUsage;
|
|
50
|
+
}
|
|
51
|
+
/** Token/credit usage for a single model call or a sum across calls. `credits` is the Base44 gateway's `base44_credits`. */
|
|
52
|
+
export interface RunUsage {
|
|
53
|
+
inputTokens?: number;
|
|
54
|
+
outputTokens?: number;
|
|
55
|
+
totalTokens?: number;
|
|
56
|
+
credits?: number;
|
|
57
|
+
}
|
|
58
|
+
/** Result of {@linkcode Agent.run}. */
|
|
59
|
+
export interface RunResult {
|
|
60
|
+
/** The model's final text output. */
|
|
61
|
+
text: string;
|
|
62
|
+
/** The loop history (one entry per step that made tool calls). */
|
|
63
|
+
steps: Step[];
|
|
64
|
+
/**
|
|
65
|
+
* Why the run ended.
|
|
66
|
+
* Values come from the model/normalization layer (`"stop"`, `"length"`, `"tool-calls"`, `"content-filter"`, `"error"`, `"other"`)
|
|
67
|
+
* or from the SDK itself (`"max_steps"`, set when the step cap is reached).
|
|
68
|
+
*/
|
|
69
|
+
finishReason: FinishReason | "max_steps";
|
|
70
|
+
/** Token and credit usage from the final completion. */
|
|
71
|
+
usage: RunUsage;
|
|
72
|
+
/** Summed across all model calls in the loop; `usage` is the final call only. */
|
|
73
|
+
totalUsage: RunUsage;
|
|
74
|
+
/** The raw final completion body, for advanced use. */
|
|
75
|
+
raw: unknown;
|
|
76
|
+
}
|
|
77
|
+
/** Input to {@linkcode Agent.run}: either a single prompt or a full message list. */
|
|
78
|
+
export type RunInput = {
|
|
79
|
+
prompt: string;
|
|
80
|
+
} | {
|
|
81
|
+
messages: ChatMessage[];
|
|
82
|
+
};
|
|
83
|
+
/**
|
|
84
|
+
* Per-run options passed as the second argument to {@linkcode Agent.run}.
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* ```typescript
|
|
88
|
+
* const controller = new AbortController();
|
|
89
|
+
* setTimeout(() => controller.abort(), 10_000);
|
|
90
|
+
*
|
|
91
|
+
* const result = await agent.run(
|
|
92
|
+
* { prompt: "Summarize last month's sales." },
|
|
93
|
+
* { abortSignal: controller.signal },
|
|
94
|
+
* );
|
|
95
|
+
* ```
|
|
96
|
+
*/
|
|
97
|
+
export interface RunOptions {
|
|
98
|
+
/** Abort the run (and the in-flight gateway request). */
|
|
99
|
+
abortSignal?: AbortSignal;
|
|
100
|
+
}
|
|
101
|
+
/** OpenAI-compatible tool choice. */
|
|
102
|
+
export type ToolChoice = "auto" | "none" | "required" | {
|
|
103
|
+
type: "function";
|
|
104
|
+
function: {
|
|
105
|
+
name: string;
|
|
106
|
+
};
|
|
107
|
+
};
|
|
108
|
+
/**
|
|
109
|
+
* Configuration for a code-defined agent passed to {@linkcode AgentsModule.create}.
|
|
110
|
+
*
|
|
111
|
+
* @example
|
|
112
|
+
* ```typescript
|
|
113
|
+
* const agent = base44.agents.create({
|
|
114
|
+
* model: "claude_sonnet_4_6",
|
|
115
|
+
* system: "You are a concise travel planner.",
|
|
116
|
+
* tools: { getWeather, searchFlights },
|
|
117
|
+
* maxSteps: 5,
|
|
118
|
+
* });
|
|
119
|
+
* ```
|
|
120
|
+
*/
|
|
121
|
+
export interface AgentConfig {
|
|
122
|
+
/**
|
|
123
|
+
* Model alias or vendor model ID to use for this agent.
|
|
124
|
+
*
|
|
125
|
+
* Use a Base44 model alias (e.g. `"claude_sonnet_4_6"`, `"gpt_4o"`, `"gpt_5_mini"`) or a
|
|
126
|
+
* fully-qualified vendor ID. Available aliases are listed in the Base44 console.
|
|
127
|
+
*/
|
|
128
|
+
model: string;
|
|
129
|
+
/**
|
|
130
|
+
* System prompt prepended to every run.
|
|
131
|
+
*
|
|
132
|
+
* Provide instructions, persona, or constraints for the model.
|
|
133
|
+
* Omit to let the model run without a system message.
|
|
134
|
+
*/
|
|
135
|
+
system?: string;
|
|
136
|
+
/**
|
|
137
|
+
* Tools the agent may call, keyed by their function name.
|
|
138
|
+
*
|
|
139
|
+
* Each value must be a {@linkcode Tool} object — use the {@linkcode tool | tool()} factory
|
|
140
|
+
* to create one, or use `.asTool()` on a resource such as an entity or function.
|
|
141
|
+
*
|
|
142
|
+
* @example
|
|
143
|
+
* ```typescript
|
|
144
|
+
* import { tool } from "@base44/sdk";
|
|
145
|
+
*
|
|
146
|
+
* const getWeather = tool({
|
|
147
|
+
* description: "Get the current weather for a city.",
|
|
148
|
+
* parameters: { type: "object", properties: { city: { type: "string" } }, required: ["city"] },
|
|
149
|
+
* execute: async ({ city }) => fetch(`/weather?city=${city}`).then(r => r.json()),
|
|
150
|
+
* });
|
|
151
|
+
*
|
|
152
|
+
* const agent = base44.agents.create({ model: "claude_sonnet_4_6", tools: { getWeather } });
|
|
153
|
+
* ```
|
|
154
|
+
*/
|
|
155
|
+
tools?: Record<string, Tool>;
|
|
156
|
+
/**
|
|
157
|
+
* Maximum number of tool-calling loop iterations before the run stops.
|
|
158
|
+
*
|
|
159
|
+
* Each iteration is one round-trip to the model. If the model keeps calling tools
|
|
160
|
+
* and this limit is reached, the run ends with `finishReason: "max_steps"`.
|
|
161
|
+
* Defaults to `8`.
|
|
162
|
+
*/
|
|
163
|
+
maxSteps?: number;
|
|
164
|
+
/**
|
|
165
|
+
* Sampling temperature passed to the model.
|
|
166
|
+
*
|
|
167
|
+
* Controls output randomness: lower values (e.g. `0`) produce more deterministic
|
|
168
|
+
* responses; higher values (e.g. `1`) increase variety. Omit to use the model default.
|
|
169
|
+
*
|
|
170
|
+
* Note: GPT-5 series models only accept `temperature: 1`.
|
|
171
|
+
*/
|
|
172
|
+
temperature?: number;
|
|
173
|
+
/**
|
|
174
|
+
* JSON Schema to constrain the model's output to structured JSON.
|
|
175
|
+
*
|
|
176
|
+
* When set, the request is sent with `response_format: { type: "json_schema", … }`.
|
|
177
|
+
* The model's response will be valid JSON matching the schema; access it by parsing
|
|
178
|
+
* `RunResult.text`.
|
|
179
|
+
* The schema is sent with strict JSON-schema mode, so it should have `additionalProperties: false` and list every property in `required` (otherwise the provider may reject it).
|
|
180
|
+
*
|
|
181
|
+
* @example
|
|
182
|
+
* ```typescript
|
|
183
|
+
* const agent = base44.agents.create({
|
|
184
|
+
* model: "claude_sonnet_4_6",
|
|
185
|
+
* responseFormat: {
|
|
186
|
+
* type: "object",
|
|
187
|
+
* properties: { summary: { type: "string" }, score: { type: "number" } },
|
|
188
|
+
* required: ["summary", "score"],
|
|
189
|
+
* },
|
|
190
|
+
* });
|
|
191
|
+
* const { text } = await agent.run({ prompt: "Rate this product description." });
|
|
192
|
+
* const { summary, score } = JSON.parse(text);
|
|
193
|
+
* ```
|
|
194
|
+
*/
|
|
195
|
+
responseFormat?: JSONSchema;
|
|
196
|
+
/**
|
|
197
|
+
* Controls whether and which tool the model must call.
|
|
198
|
+
*
|
|
199
|
+
* - `"auto"` (default when tools are provided): the model decides.
|
|
200
|
+
* - `"none"`: the model must not call any tool.
|
|
201
|
+
* - `"required"`: the model must call at least one tool.
|
|
202
|
+
* - `{ type: "function", function: { name } }`: force a specific tool.
|
|
203
|
+
*/
|
|
204
|
+
toolChoice?: ToolChoice;
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* A reusable code-defined agent returned by {@linkcode AgentsModule.create}.
|
|
208
|
+
*
|
|
209
|
+
* An agent runs a multi-step tool-calling loop: it sends messages to the model,
|
|
210
|
+
* executes any tool calls the model requests, feeds the results back, and repeats
|
|
211
|
+
* until the model produces a final answer or `maxSteps` is reached.
|
|
212
|
+
*
|
|
213
|
+
* @example
|
|
214
|
+
* ```typescript
|
|
215
|
+
* const agent = base44.agents.create({
|
|
216
|
+
* model: "claude_sonnet_4_6",
|
|
217
|
+
* system: "You are a concise travel planner.",
|
|
218
|
+
* tools: { getWeather },
|
|
219
|
+
* });
|
|
220
|
+
*
|
|
221
|
+
* const { text } = await agent.run({ prompt: "What's the weather like in Tel Aviv?" });
|
|
222
|
+
* console.log(text);
|
|
223
|
+
* ```
|
|
224
|
+
*/
|
|
225
|
+
export interface Agent {
|
|
226
|
+
/**
|
|
227
|
+
* Runs the agent's tool-calling loop to completion and returns the final result.
|
|
228
|
+
*
|
|
229
|
+
* Builds an initial message list from `input`, then repeatedly calls the model,
|
|
230
|
+
* executes any tool calls, and feeds results back until the model stops or
|
|
231
|
+
* `maxSteps` (from {@linkcode AgentConfig}) is reached.
|
|
232
|
+
*
|
|
233
|
+
* Tool errors are fed back to the model as tool results rather than thrown, so
|
|
234
|
+
* the model can recover or explain the failure.
|
|
235
|
+
*
|
|
236
|
+
* @param input - The run input: either `{ prompt: string }` for a simple user
|
|
237
|
+
* message, or `{ messages: ChatMessage[] }` to supply a full conversation history.
|
|
238
|
+
* @param options - Optional {@linkcode RunOptions} (e.g. an `AbortSignal`).
|
|
239
|
+
* @returns Promise resolving to a {@linkcode RunResult} containing the model's
|
|
240
|
+
* final text, per-step tool call history, finish reason, and token/credit usage.
|
|
241
|
+
*
|
|
242
|
+
* @example
|
|
243
|
+
* ```typescript
|
|
244
|
+
* // Simple prompt
|
|
245
|
+
* const { text, usage } = await agent.run({ prompt: "Plan a one-day trip to Haifa." });
|
|
246
|
+
* console.log(text);
|
|
247
|
+
* console.log(`Credits used: ${usage.credits}`);
|
|
248
|
+
* ```
|
|
249
|
+
*
|
|
250
|
+
* @example
|
|
251
|
+
* ```typescript
|
|
252
|
+
* // Supply a full message history
|
|
253
|
+
* const { text } = await agent.run({
|
|
254
|
+
* messages: [
|
|
255
|
+
* { role: "user", content: "What is the capital of France?" },
|
|
256
|
+
* { role: "assistant", content: "Paris." },
|
|
257
|
+
* { role: "user", content: "And what is the population?" },
|
|
258
|
+
* ],
|
|
259
|
+
* });
|
|
260
|
+
* ```
|
|
261
|
+
*
|
|
262
|
+
* @example
|
|
263
|
+
* ```typescript
|
|
264
|
+
* // Cancel a long-running run
|
|
265
|
+
* const controller = new AbortController();
|
|
266
|
+
* setTimeout(() => controller.abort(), 15_000);
|
|
267
|
+
* const { text } = await agent.run(
|
|
268
|
+
* { prompt: "Summarize all open support tickets." },
|
|
269
|
+
* { abortSignal: controller.signal },
|
|
270
|
+
* );
|
|
271
|
+
* ```
|
|
272
|
+
*/
|
|
273
|
+
run(input: RunInput, options?: RunOptions): Promise<RunResult>;
|
|
274
|
+
/**
|
|
275
|
+
* Wraps this agent as a {@linkcode Tool} so another agent can call it as a sub-agent.
|
|
276
|
+
*
|
|
277
|
+
* The returned tool exposes a single `prompt` parameter. When called, it invokes
|
|
278
|
+
* {@linkcode Agent.run | run()} with that prompt and returns the text result.
|
|
279
|
+
* Use this to build agent hierarchies where a coordinator agent delegates tasks
|
|
280
|
+
* to specialized sub-agents.
|
|
281
|
+
*
|
|
282
|
+
* @param opts - Options for the tool wrapper.
|
|
283
|
+
* @param opts.description - Required. Natural-language description the calling
|
|
284
|
+
* model uses to decide when to invoke this sub-agent.
|
|
285
|
+
* @param opts.name - Optional display name for the tool. Defaults to the
|
|
286
|
+
* agent config's model alias when omitted.
|
|
287
|
+
* @returns A {@linkcode Tool} that can be passed in another agent's `tools` map.
|
|
288
|
+
* @note The sub-agent runs independently — the parent's `abortSignal` is not propagated and
|
|
289
|
+
* the sub-agent's token/credit usage is not included in the parent's `totalUsage`.
|
|
290
|
+
*
|
|
291
|
+
* @example
|
|
292
|
+
* ```typescript
|
|
293
|
+
* const researchAgent = base44.agents.create({
|
|
294
|
+
* model: "claude_sonnet_4_6",
|
|
295
|
+
* tools: { webSearch },
|
|
296
|
+
* });
|
|
297
|
+
*
|
|
298
|
+
* const writerAgent = base44.agents.create({
|
|
299
|
+
* model: "claude_sonnet_4_6",
|
|
300
|
+
* tools: {
|
|
301
|
+
* research: researchAgent.asTool({
|
|
302
|
+
* description: "Search the web and return a research summary.",
|
|
303
|
+
* }),
|
|
304
|
+
* },
|
|
305
|
+
* });
|
|
306
|
+
*
|
|
307
|
+
* const { text } = await writerAgent.run({ prompt: "Write a blog post about coral reefs." });
|
|
308
|
+
* ```
|
|
309
|
+
*/
|
|
310
|
+
asTool(opts: {
|
|
311
|
+
name?: string;
|
|
312
|
+
description: string;
|
|
313
|
+
}): Tool;
|
|
314
|
+
}
|
|
4
315
|
/**
|
|
5
316
|
* Registry of agent names. The [`types generate`](/developers/references/cli/commands/types-generate) command fills this registry, then [`AgentName`](#agentname) resolves to a union of the keys.
|
|
6
317
|
*/
|
|
@@ -162,6 +473,8 @@ export interface AgentsModuleConfig {
|
|
|
162
473
|
serverUrl?: string;
|
|
163
474
|
/** Authentication token */
|
|
164
475
|
token?: string;
|
|
476
|
+
/** Returns the current bearer token at call time (thunk — never a captured string). Used by `create()`. */
|
|
477
|
+
getToken?: () => string | undefined;
|
|
165
478
|
}
|
|
166
479
|
/**
|
|
167
480
|
* Agents module for managing AI agent conversations.
|
|
@@ -356,6 +669,27 @@ export interface AgentsModule {
|
|
|
356
669
|
* ```
|
|
357
670
|
*/
|
|
358
671
|
subscribeToConversation(conversationId: string, onUpdate?: (conversation: AgentConversation) => void): () => void;
|
|
672
|
+
/**
|
|
673
|
+
* Creates a code-defined agent: you specify the model, system prompt, and tools in code,
|
|
674
|
+
* and the SDK runs the tool-calling loop against the Base44 AI Gateway.
|
|
675
|
+
*
|
|
676
|
+
* Returns a reusable {@linkcode Agent} you can {@linkcode Agent.run | run} or expose to
|
|
677
|
+
* another agent as a tool with {@linkcode Agent.asTool | asTool}.
|
|
678
|
+
*
|
|
679
|
+
* @param config - Model alias, optional system prompt, tools, and step limit.
|
|
680
|
+
* @returns A reusable {@linkcode Agent} with {@linkcode Agent.run | run()} and {@linkcode Agent.asTool | asTool()}.
|
|
681
|
+
*
|
|
682
|
+
* @example
|
|
683
|
+
* ```typescript
|
|
684
|
+
* const agent = base44.agents.create({
|
|
685
|
+
* model: "claude_sonnet_4_6",
|
|
686
|
+
* system: "You plan trips.",
|
|
687
|
+
* tools: { getWeather },
|
|
688
|
+
* });
|
|
689
|
+
* const { text } = await agent.run({ prompt: "Plan a day in Haifa." });
|
|
690
|
+
* ```
|
|
691
|
+
*/
|
|
692
|
+
create(config: AgentConfig): Agent;
|
|
359
693
|
/**
|
|
360
694
|
* Gets WhatsApp connection URL for an agent.
|
|
361
695
|
*
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimal transport shape used by provider adapters to send completions requests.
|
|
3
|
+
* @internal
|
|
4
|
+
*/
|
|
5
|
+
export type GatewayTransport = {
|
|
6
|
+
complete(body: Record<string, unknown>, opts?: {
|
|
7
|
+
signal?: AbortSignal;
|
|
8
|
+
}): Promise<unknown>;
|
|
9
|
+
};
|
|
10
|
+
/** @internal */
|
|
11
|
+
export interface GatewayConfig {
|
|
12
|
+
serverUrl: string;
|
|
13
|
+
/** Returns the current bearer token at call time (thunk — never a captured string). */
|
|
14
|
+
getToken: () => string | undefined;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Resolves the AI Gateway connection from a client config.
|
|
18
|
+
* @internal
|
|
19
|
+
*/
|
|
20
|
+
export declare function resolveConnection(config: GatewayConfig): {
|
|
21
|
+
baseURL: string;
|
|
22
|
+
apiKey: string;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Creates the gateway transport — owns the single HTTP call to the OpenAI-compatible
|
|
26
|
+
* `/chat/completions` endpoint.
|
|
27
|
+
* @internal
|
|
28
|
+
*/
|
|
29
|
+
export declare function createGatewayTransport(config: GatewayConfig): {
|
|
30
|
+
complete(body: Record<string, unknown>, opts?: {
|
|
31
|
+
signal?: AbortSignal;
|
|
32
|
+
}): Promise<unknown>;
|
|
33
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Base44Error } from "
|
|
1
|
+
import { Base44Error } from "../../utils/axios-client.js";
|
|
2
2
|
/**
|
|
3
3
|
* Resolves the AI Gateway connection from a client config.
|
|
4
4
|
* @internal
|
|
@@ -13,9 +13,8 @@ export function resolveConnection(config) {
|
|
|
13
13
|
};
|
|
14
14
|
}
|
|
15
15
|
/**
|
|
16
|
-
* Creates the gateway transport
|
|
17
|
-
* `/chat/completions` endpoint.
|
|
18
|
-
* later without changing callers of `.complete()`.
|
|
16
|
+
* Creates the gateway transport — owns the single HTTP call to the OpenAI-compatible
|
|
17
|
+
* `/chat/completions` endpoint.
|
|
19
18
|
* @internal
|
|
20
19
|
*/
|
|
21
20
|
export function createGatewayTransport(config) {
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { AgentsModule, AgentsModuleConfig } from "./agents.types.js";
|
|
2
|
-
export declare function createAgentsModule({ axios, getSocket, appId, serverUrl, token, }: AgentsModuleConfig): AgentsModule;
|
|
2
|
+
export declare function createAgentsModule({ axios, getSocket, appId, serverUrl, token, getToken, }: AgentsModuleConfig): AgentsModule;
|
|
@@ -1,5 +1,12 @@
|
|
|
1
|
-
import { getAccessToken } from "
|
|
2
|
-
|
|
1
|
+
import { getAccessToken } from "../../utils/auth-utils.js";
|
|
2
|
+
import { createGatewayTransport } from "./gateway.js";
|
|
3
|
+
import { openAICompatibleProvider } from "./providers/openai-compatible.js";
|
|
4
|
+
import { createAgent } from "./loop.js";
|
|
5
|
+
export function createAgentsModule({ axios, getSocket, appId, serverUrl, token, getToken, }) {
|
|
6
|
+
const model = openAICompatibleProvider(createGatewayTransport({
|
|
7
|
+
serverUrl: serverUrl !== null && serverUrl !== void 0 ? serverUrl : "",
|
|
8
|
+
getToken: getToken !== null && getToken !== void 0 ? getToken : (() => token),
|
|
9
|
+
}));
|
|
3
10
|
const baseURL = `/apps/${appId}/agents`;
|
|
4
11
|
// Track active conversations
|
|
5
12
|
const currentConversations = {};
|
|
@@ -85,5 +92,6 @@ export function createAgentsModule({ axios, getSocket, appId, serverUrl, token,
|
|
|
85
92
|
subscribeToConversation,
|
|
86
93
|
getWhatsAppConnectURL,
|
|
87
94
|
getTelegramConnectURL,
|
|
95
|
+
create(config) { return createAgent(config, model); },
|
|
88
96
|
};
|
|
89
97
|
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Agent, AgentConfig } from "./agents.types.js";
|
|
2
|
+
import type { LanguageModel } from "./provider.js";
|
|
3
|
+
/** Creates an Agent from a config and a language model. @internal */
|
|
4
|
+
export declare function createAgent(agentConfig: AgentConfig, model: LanguageModel): Agent;
|