@base44/sdk 0.8.18 → 0.8.20
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/README.md +83 -11
- package/dist/client.d.ts +9 -5
- package/dist/client.js +13 -7
- package/dist/client.types.d.ts +22 -19
- package/dist/index.d.ts +4 -4
- package/dist/modules/agents.types.d.ts +50 -13
- package/dist/modules/analytics.types.d.ts +83 -3
- package/dist/modules/app-logs.types.d.ts +2 -0
- package/dist/modules/auth.js +30 -24
- package/dist/modules/auth.types.d.ts +30 -7
- package/dist/modules/connectors.js +17 -2
- package/dist/modules/connectors.types.d.ts +75 -8
- package/dist/modules/custom-integrations.types.d.ts +38 -54
- package/dist/modules/entities.types.d.ts +164 -42
- package/dist/modules/functions.types.d.ts +23 -2
- package/dist/modules/integrations.types.d.ts +67 -31
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -1,22 +1,42 @@
|
|
|
1
1
|
# Base44 JavaScript SDK
|
|
2
2
|
|
|
3
|
-
The Base44 SDK provides a JavaScript interface for building apps on the Base44 platform.
|
|
3
|
+
The Base44 SDK provides a JavaScript interface for building apps on the Base44 platform.
|
|
4
|
+
|
|
5
|
+
You can use it in two ways:
|
|
6
|
+
|
|
7
|
+
- **Inside Base44 apps**: When Base44 generates your app, the SDK is already set up and ready to use.
|
|
8
|
+
- **External apps**: Use the SDK to build your own frontend or backend that uses Base44 as a backend service.
|
|
9
|
+
|
|
10
|
+
## Installation
|
|
11
|
+
|
|
12
|
+
**Inside Base44 apps**: The SDK is already available. No installation needed.
|
|
13
|
+
|
|
14
|
+
**External apps**: Install the SDK via npm:
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm install @base44/sdk
|
|
18
|
+
```
|
|
4
19
|
|
|
5
20
|
## Modules
|
|
6
21
|
|
|
7
22
|
The SDK provides access to Base44's functionality through the following modules:
|
|
8
23
|
|
|
9
|
-
- **[`agents`](https://docs.base44.com/sdk
|
|
10
|
-
- **[`
|
|
11
|
-
- **[`
|
|
12
|
-
- **[`
|
|
13
|
-
- **[`
|
|
14
|
-
- **[`
|
|
15
|
-
- **[`
|
|
24
|
+
- **[`agents`](https://docs.base44.com/developers/references/sdk/docs/interfaces/agents)**: Interact with AI agents and manage conversations.
|
|
25
|
+
- **[`analytics`](https://docs.base44.com/developers/references/sdk/docs/interfaces/analytics)**: Track custom events in your app.
|
|
26
|
+
- **[`app-logs`](https://docs.base44.com/developers/references/sdk/docs/interfaces/app-logs)**: Access and query app logs.
|
|
27
|
+
- **[`auth`](https://docs.base44.com/developers/references/sdk/docs/interfaces/auth)**: Manage user authentication, registration, and session handling.
|
|
28
|
+
- **[`connectors`](https://docs.base44.com/developers/references/sdk/docs/interfaces/connectors)**: Manage OAuth connections and access tokens for third-party services.
|
|
29
|
+
- **[`entities`](https://docs.base44.com/developers/references/sdk/docs/interfaces/entities)**: Work with your app's data entities using CRUD operations.
|
|
30
|
+
- **[`functions`](https://docs.base44.com/developers/references/sdk/docs/interfaces/functions)**: Execute backend functions.
|
|
31
|
+
- **[`integrations`](https://docs.base44.com/developers/references/sdk/docs/type-aliases/integrations)**: Access pre-built and third-party integrations.
|
|
32
|
+
|
|
33
|
+
## Quickstarts
|
|
16
34
|
|
|
17
|
-
|
|
35
|
+
How you get started depends on whether you're working inside a Base44-generated app or building your own.
|
|
18
36
|
|
|
19
|
-
|
|
37
|
+
### Inside Base44 apps
|
|
38
|
+
|
|
39
|
+
In Base44-generated apps, the client is pre-configured. Just import and use it:
|
|
20
40
|
|
|
21
41
|
```typescript
|
|
22
42
|
import { base44 } from "@/api/base44Client";
|
|
@@ -37,14 +57,63 @@ await base44.entities.Task.update(newTask.id, {
|
|
|
37
57
|
const tasks = await base44.entities.Task.list();
|
|
38
58
|
```
|
|
39
59
|
|
|
60
|
+
### External apps
|
|
61
|
+
|
|
62
|
+
When using Base44 as a backend for your own app, install the SDK and create the client yourself:
|
|
63
|
+
|
|
64
|
+
```typescript
|
|
65
|
+
import { createClient } from "@base44/sdk";
|
|
66
|
+
|
|
67
|
+
// Create a client for your Base44 app
|
|
68
|
+
const base44 = createClient({
|
|
69
|
+
appId: "your-app-id", // Find this in the Base44 editor URL
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
// Read public data
|
|
73
|
+
const products = await base44.entities.Products.list();
|
|
74
|
+
|
|
75
|
+
// Authenticate a user (token is automatically set)
|
|
76
|
+
await base44.auth.loginViaEmailPassword("user@example.com", "password");
|
|
77
|
+
|
|
78
|
+
// Access user's data
|
|
79
|
+
const userOrders = await base44.entities.Orders.list();
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### Service role
|
|
83
|
+
|
|
84
|
+
By default, the client operates with user-level permissions, limiting access to what the current user can see and do. The service role provides elevated permissions for backend operations and is only available in Base44-hosted backend functions. External backends can't use service role permissions.
|
|
85
|
+
|
|
86
|
+
```typescript
|
|
87
|
+
import { createClientFromRequest } from "npm:@base44/sdk";
|
|
88
|
+
|
|
89
|
+
Deno.serve(async (req) => {
|
|
90
|
+
const base44 = createClientFromRequest(req);
|
|
91
|
+
|
|
92
|
+
// Access all data with admin-level permissions
|
|
93
|
+
const allOrders = await base44.asServiceRole.entities.Orders.list();
|
|
94
|
+
|
|
95
|
+
return Response.json({ orders: allOrders });
|
|
96
|
+
});
|
|
97
|
+
```
|
|
98
|
+
|
|
40
99
|
## Learn more
|
|
41
100
|
|
|
42
|
-
|
|
101
|
+
The best way to get started with the JavaScript SDK is to have Base44 build an app for you. Once you have an app, you can explore the generated code and experiment with the SDK to see how it works in practice. You can also ask Base44 to demonstrate specific features of the SDK.
|
|
102
|
+
|
|
103
|
+
For a deeper understanding, check out these guides:
|
|
104
|
+
|
|
105
|
+
1. [Base44 client](https://docs.base44.com/developers/references/sdk/getting-started/client) - Work with the client in frontend, backend, and external app contexts.
|
|
106
|
+
2. [Work with data](https://docs.base44.com/developers/references/sdk/getting-started/work-with-data) - Create, read, update, and delete data.
|
|
107
|
+
3. [Common SDK patterns](https://docs.base44.com/developers/references/sdk/getting-started/work-with-sdk) - Authentication, integrations, functions, and error handling.
|
|
108
|
+
|
|
109
|
+
For the complete documentation and API reference, visit the **[Base44 Developer Docs](https://docs.base44.com/developers/home)**.
|
|
43
110
|
|
|
44
111
|
## Development
|
|
45
112
|
|
|
46
113
|
### Build the SDK
|
|
47
114
|
|
|
115
|
+
Build the SDK from source:
|
|
116
|
+
|
|
48
117
|
```bash
|
|
49
118
|
npm install
|
|
50
119
|
npm run build
|
|
@@ -52,6 +121,8 @@ npm run build
|
|
|
52
121
|
|
|
53
122
|
### Run tests
|
|
54
123
|
|
|
124
|
+
Run the test suite:
|
|
125
|
+
|
|
55
126
|
```bash
|
|
56
127
|
# Run all tests
|
|
57
128
|
npm test
|
|
@@ -64,6 +135,7 @@ npm run test:coverage
|
|
|
64
135
|
```
|
|
65
136
|
|
|
66
137
|
For E2E tests, create a `tests/.env` file with:
|
|
138
|
+
|
|
67
139
|
```
|
|
68
140
|
BASE44_APP_ID=your_app_id
|
|
69
141
|
BASE44_AUTH_TOKEN=your_auth_token
|
package/dist/client.d.ts
CHANGED
|
@@ -5,12 +5,14 @@ export type { Base44Client, CreateClientConfig, CreateClientOptions };
|
|
|
5
5
|
*
|
|
6
6
|
* This is the main entry point for the Base44 SDK. It creates a client that provides access to the SDK's modules, such as {@linkcode EntitiesModule | entities}, {@linkcode AuthModule | auth}, and {@linkcode FunctionsModule | functions}.
|
|
7
7
|
*
|
|
8
|
-
*
|
|
8
|
+
* How you get a client depends on your context:
|
|
9
|
+
* - **Inside a Base44 app:** The client is automatically created and configured for you. Import it from `@/api/base44Client`.
|
|
10
|
+
* - **External app using Base44 as a backend:** Call `createClient()` directly in your code to create and configure the client.
|
|
9
11
|
*
|
|
10
12
|
* The client supports three authentication modes:
|
|
11
|
-
* - **Anonymous**: Access modules
|
|
12
|
-
* - **User authentication**: Access modules with user-level permissions using `base44.moduleName`. Operations are scoped to the authenticated user's data and permissions.
|
|
13
|
-
* - **Service role authentication**: Access modules with elevated permissions using `base44.asServiceRole.moduleName`. Operations can access any data available to the app's admin.
|
|
13
|
+
* - **Anonymous**: Access modules without authentication using `base44.moduleName`. Operations are scoped to public data and permissions.
|
|
14
|
+
* - **User authentication**: Access modules with user-level permissions using `base44.moduleName`. Operations are scoped to the authenticated user's data and permissions. Use `base44.auth.loginViaEmailPassword()` or other auth methods to get a token.
|
|
15
|
+
* - **Service role authentication**: Access modules with elevated permissions using `base44.asServiceRole.moduleName`. Operations can access any data available to the app's admin. Only available in Base44-hosted backend functions. Create a client with service role authentication using {@linkcode createClientFromRequest | createClientFromRequest()}.
|
|
14
16
|
*
|
|
15
17
|
* For example, when using the {@linkcode EntitiesModule | entities} module:
|
|
16
18
|
* - **Anonymous**: Can only read public data.
|
|
@@ -39,7 +41,9 @@ export declare function createClient(config: CreateClientConfig): Base44Client;
|
|
|
39
41
|
/**
|
|
40
42
|
* Creates a Base44 client from an HTTP request.
|
|
41
43
|
*
|
|
42
|
-
*
|
|
44
|
+
* This function is designed for use in Base44-hosted backend functions. For frontends and external backends, use {@linkcode createClient | createClient()} instead.
|
|
45
|
+
*
|
|
46
|
+
* When used in a Base44-hosted backend function, `createClientFromRequest()` automatically extracts authentication tokens from the request headers that Base44 injects when forwarding requests. The returned client includes service role access using `base44.asServiceRole`, which provides admin-level permissions.
|
|
43
47
|
*
|
|
44
48
|
* To learn more about the Base44 client, see {@linkcode createClient | createClient()}.
|
|
45
49
|
*
|
package/dist/client.js
CHANGED
|
@@ -16,12 +16,14 @@ import { createAnalyticsModule } from "./modules/analytics.js";
|
|
|
16
16
|
*
|
|
17
17
|
* This is the main entry point for the Base44 SDK. It creates a client that provides access to the SDK's modules, such as {@linkcode EntitiesModule | entities}, {@linkcode AuthModule | auth}, and {@linkcode FunctionsModule | functions}.
|
|
18
18
|
*
|
|
19
|
-
*
|
|
19
|
+
* How you get a client depends on your context:
|
|
20
|
+
* - **Inside a Base44 app:** The client is automatically created and configured for you. Import it from `@/api/base44Client`.
|
|
21
|
+
* - **External app using Base44 as a backend:** Call `createClient()` directly in your code to create and configure the client.
|
|
20
22
|
*
|
|
21
23
|
* The client supports three authentication modes:
|
|
22
|
-
* - **Anonymous**: Access modules
|
|
23
|
-
* - **User authentication**: Access modules with user-level permissions using `base44.moduleName`. Operations are scoped to the authenticated user's data and permissions.
|
|
24
|
-
* - **Service role authentication**: Access modules with elevated permissions using `base44.asServiceRole.moduleName`. Operations can access any data available to the app's admin.
|
|
24
|
+
* - **Anonymous**: Access modules without authentication using `base44.moduleName`. Operations are scoped to public data and permissions.
|
|
25
|
+
* - **User authentication**: Access modules with user-level permissions using `base44.moduleName`. Operations are scoped to the authenticated user's data and permissions. Use `base44.auth.loginViaEmailPassword()` or other auth methods to get a token.
|
|
26
|
+
* - **Service role authentication**: Access modules with elevated permissions using `base44.asServiceRole.moduleName`. Operations can access any data available to the app's admin. Only available in Base44-hosted backend functions. Create a client with service role authentication using {@linkcode createClientFromRequest | createClientFromRequest()}.
|
|
25
27
|
*
|
|
26
28
|
* For example, when using the {@linkcode EntitiesModule | entities} module:
|
|
27
29
|
* - **Anonymous**: Can only read public data.
|
|
@@ -48,6 +50,8 @@ import { createAnalyticsModule } from "./modules/analytics.js";
|
|
|
48
50
|
*/
|
|
49
51
|
export function createClient(config) {
|
|
50
52
|
const { serverUrl = "https://base44.app", appId, token, serviceToken, requiresAuth = false, appBaseUrl, options, functionsVersion, headers: optionalHeaders, } = config;
|
|
53
|
+
// Normalize appBaseUrl to always be a string (empty if not provided or invalid)
|
|
54
|
+
const normalizedAppBaseUrl = typeof appBaseUrl === "string" ? appBaseUrl : "";
|
|
51
55
|
const socketConfig = {
|
|
52
56
|
serverUrl,
|
|
53
57
|
mountPath: "/ws-user-apps/socket.io/",
|
|
@@ -100,7 +104,7 @@ export function createClient(config) {
|
|
|
100
104
|
interceptResponses: false,
|
|
101
105
|
});
|
|
102
106
|
const userAuthModule = createAuthModule(axiosClient, functionsAxiosClient, appId, {
|
|
103
|
-
appBaseUrl,
|
|
107
|
+
appBaseUrl: normalizedAppBaseUrl,
|
|
104
108
|
serverUrl,
|
|
105
109
|
});
|
|
106
110
|
const userModules = {
|
|
@@ -224,7 +228,7 @@ export function createClient(config) {
|
|
|
224
228
|
/**
|
|
225
229
|
* Provides access to service role modules.
|
|
226
230
|
*
|
|
227
|
-
* Service role authentication provides elevated permissions for
|
|
231
|
+
* Service role authentication provides elevated permissions for backend operations. Unlike user authentication, which is scoped to a specific user's permissions, service role authentication has access to the data and operations available to the app's admin.
|
|
228
232
|
*
|
|
229
233
|
* @throws {Error} When accessed without providing a serviceToken during client creation.
|
|
230
234
|
*
|
|
@@ -251,7 +255,9 @@ export function createClient(config) {
|
|
|
251
255
|
/**
|
|
252
256
|
* Creates a Base44 client from an HTTP request.
|
|
253
257
|
*
|
|
254
|
-
*
|
|
258
|
+
* This function is designed for use in Base44-hosted backend functions. For frontends and external backends, use {@linkcode createClient | createClient()} instead.
|
|
259
|
+
*
|
|
260
|
+
* When used in a Base44-hosted backend function, `createClientFromRequest()` automatically extracts authentication tokens from the request headers that Base44 injects when forwarding requests. The returned client includes service role access using `base44.asServiceRole`, which provides admin-level permissions.
|
|
255
261
|
*
|
|
256
262
|
* To learn more about the Base44 client, see {@linkcode createClient | createClient()}.
|
|
257
263
|
*
|
package/dist/client.types.d.ts
CHANGED
|
@@ -39,10 +39,13 @@ export interface CreateClientConfig {
|
|
|
39
39
|
appId: string;
|
|
40
40
|
/**
|
|
41
41
|
* User authentication token. Used to authenticate as a specific user.
|
|
42
|
+
*
|
|
43
|
+
* Inside Base44 apps, the token is managed automatically. For external apps, use auth methods like {@linkcode AuthModule.loginViaEmailPassword | loginViaEmailPassword()} which set the token automatically.
|
|
42
44
|
*/
|
|
43
45
|
token?: string;
|
|
44
46
|
/**
|
|
45
|
-
* Service role authentication token.
|
|
47
|
+
* Service role authentication token. Provides elevated permissions to access data available to the app's admin. Only available in Base44-hosted backend functions. Automatically added to client's created using {@linkcode createClientFromRequest | createClientFromRequest()}.
|
|
48
|
+
* @internal
|
|
46
49
|
*/
|
|
47
50
|
serviceToken?: string;
|
|
48
51
|
/**
|
|
@@ -71,20 +74,20 @@ export interface CreateClientConfig {
|
|
|
71
74
|
* Provides access to all SDK modules for interacting with the app.
|
|
72
75
|
*/
|
|
73
76
|
export interface Base44Client {
|
|
74
|
-
/** {@link EntitiesModule | Entities module} for CRUD operations on your data models. */
|
|
75
|
-
entities: EntitiesModule;
|
|
76
|
-
/** {@link IntegrationsModule | Integrations module} for calling pre-built integration endpoints. */
|
|
77
|
-
integrations: IntegrationsModule;
|
|
78
|
-
/** {@link AuthModule | Auth module} for user authentication and management. */
|
|
79
|
-
auth: AuthModule;
|
|
80
|
-
/** {@link FunctionsModule | Functions module} for invoking custom backend functions. */
|
|
81
|
-
functions: FunctionsModule;
|
|
82
77
|
/** {@link AgentsModule | Agents module} for managing AI agent conversations. */
|
|
83
78
|
agents: AgentsModule;
|
|
79
|
+
/** {@link AnalyticsModule | Analytics module} for tracking custom events in your app. */
|
|
80
|
+
analytics: AnalyticsModule;
|
|
84
81
|
/** {@link AppLogsModule | App logs module} for tracking app usage. */
|
|
85
82
|
appLogs: AppLogsModule;
|
|
86
|
-
/** {@link
|
|
87
|
-
|
|
83
|
+
/** {@link AuthModule | Auth module} for user authentication and management. */
|
|
84
|
+
auth: AuthModule;
|
|
85
|
+
/** {@link EntitiesModule | Entities module} for CRUD operations on your data models. */
|
|
86
|
+
entities: EntitiesModule;
|
|
87
|
+
/** {@link FunctionsModule | Functions module} for invoking custom backend functions. */
|
|
88
|
+
functions: FunctionsModule;
|
|
89
|
+
/** {@link IntegrationsModule | Integrations module} for calling pre-built integration endpoints. */
|
|
90
|
+
integrations: IntegrationsModule;
|
|
88
91
|
/** Cleanup function to disconnect WebSocket connections. Call when you're done with the client. */
|
|
89
92
|
cleanup: () => void;
|
|
90
93
|
/**
|
|
@@ -112,22 +115,22 @@ export interface Base44Client {
|
|
|
112
115
|
* @throws {Error} When accessed without providing a serviceToken during client creation
|
|
113
116
|
*/
|
|
114
117
|
readonly asServiceRole: {
|
|
118
|
+
/** {@link AgentsModule | Agents module} with elevated permissions. */
|
|
119
|
+
agents: AgentsModule;
|
|
120
|
+
/** {@link AppLogsModule | App logs module} with elevated permissions. */
|
|
121
|
+
appLogs: AppLogsModule;
|
|
122
|
+
/** {@link ConnectorsModule | Connectors module} for OAuth token retrieval. */
|
|
123
|
+
connectors: ConnectorsModule;
|
|
115
124
|
/** {@link EntitiesModule | Entities module} with elevated permissions. */
|
|
116
125
|
entities: EntitiesModule;
|
|
126
|
+
/** {@link FunctionsModule | Functions module} with elevated permissions. */
|
|
127
|
+
functions: FunctionsModule;
|
|
117
128
|
/** {@link IntegrationsModule | Integrations module} with elevated permissions. */
|
|
118
129
|
integrations: IntegrationsModule;
|
|
119
130
|
/** {@link SsoModule | SSO module} for generating SSO tokens.
|
|
120
131
|
* @internal
|
|
121
132
|
*/
|
|
122
133
|
sso: SsoModule;
|
|
123
|
-
/** {@link ConnectorsModule | Connectors module} for OAuth token retrieval. */
|
|
124
|
-
connectors: ConnectorsModule;
|
|
125
|
-
/** {@link FunctionsModule | Functions module} with elevated permissions. */
|
|
126
|
-
functions: FunctionsModule;
|
|
127
|
-
/** {@link AgentsModule | Agents module} with elevated permissions. */
|
|
128
|
-
agents: AgentsModule;
|
|
129
|
-
/** {@link AppLogsModule | App logs module} with elevated permissions. */
|
|
130
|
-
appLogs: AppLogsModule;
|
|
131
134
|
/** Cleanup function to disconnect WebSocket connections. */
|
|
132
135
|
cleanup: () => void;
|
|
133
136
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -4,11 +4,11 @@ import { getAccessToken, saveAccessToken, removeAccessToken, getLoginUrl } from
|
|
|
4
4
|
export { createClient, createClientFromRequest, Base44Error, getAccessToken, saveAccessToken, removeAccessToken, getLoginUrl, };
|
|
5
5
|
export type { Base44Client, CreateClientConfig, CreateClientOptions, Base44ErrorJSON, };
|
|
6
6
|
export * from "./types.js";
|
|
7
|
-
export type { EntitiesModule, EntityHandler, RealtimeEventType, RealtimeEvent, RealtimeCallback,
|
|
7
|
+
export type { DeleteManyResult, DeleteResult, EntitiesModule, EntityHandler, EntityRecord, EntityTypeRegistry, ImportResult, RealtimeEventType, RealtimeEvent, RealtimeCallback, SortField, } from "./modules/entities.types.js";
|
|
8
8
|
export type { AuthModule, LoginResponse, RegisterParams, VerifyOtpParams, ChangePasswordParams, ResetPasswordParams, User, } from "./modules/auth.types.js";
|
|
9
|
-
export type { IntegrationsModule,
|
|
10
|
-
export type { FunctionsModule } from "./modules/functions.types.js";
|
|
11
|
-
export type { AgentsModule, AgentConversation, AgentMessage, AgentMessageReasoning, AgentMessageToolCall, AgentMessageUsage, AgentMessageCustomContext, AgentMessageMetadata, CreateConversationParams, } from "./modules/agents.types.js";
|
|
9
|
+
export type { IntegrationsModule, IntegrationEndpointFunction, CoreIntegrations, InvokeLLMParams, GenerateImageParams, GenerateImageResult, UploadFileParams, UploadFileResult, SendEmailParams, SendEmailResult, ExtractDataFromUploadedFileParams, ExtractDataFromUploadedFileResult, UploadPrivateFileParams, UploadPrivateFileResult, CreateFileSignedUrlParams, CreateFileSignedUrlResult, } from "./modules/integrations.types.js";
|
|
10
|
+
export type { FunctionsModule, FunctionName, FunctionNameRegistry, } from "./modules/functions.types.js";
|
|
11
|
+
export type { AgentsModule, AgentName, AgentNameRegistry, AgentConversation, AgentMessage, AgentMessageReasoning, AgentMessageToolCall, AgentMessageUsage, AgentMessageCustomContext, AgentMessageMetadata, CreateConversationParams, } from "./modules/agents.types.js";
|
|
12
12
|
export type { AppLogsModule } from "./modules/app-logs.types.js";
|
|
13
13
|
export type { SsoModule, SsoAccessTokenResponse } from "./modules/sso.types.js";
|
|
14
14
|
export type { ConnectorsModule } from "./modules/connectors.types.js";
|
|
@@ -1,6 +1,22 @@
|
|
|
1
1
|
import { AxiosInstance } from "axios";
|
|
2
2
|
import { RoomsSocket } from "../utils/socket-utils.js";
|
|
3
3
|
import { ModelFilterParams } from "../types.js";
|
|
4
|
+
/**
|
|
5
|
+
* 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
|
+
*/
|
|
7
|
+
export interface AgentNameRegistry {
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Union of all agent names from the [`AgentNameRegistry`](#agentnameregistry). Defaults to `string` when no types have been generated.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* // Using generated agent name types
|
|
15
|
+
* // With generated types, you get autocomplete on agent names
|
|
16
|
+
* const conversation = await base44.agents.createConversation({ agent_name: 'SupportBot' });
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export type AgentName = keyof AgentNameRegistry extends never ? string : keyof AgentNameRegistry;
|
|
4
20
|
/**
|
|
5
21
|
* Reasoning information for an agent message.
|
|
6
22
|
*
|
|
@@ -72,7 +88,7 @@ export interface AgentMessageMetadata {
|
|
|
72
88
|
export interface AgentConversation {
|
|
73
89
|
/** Unique identifier for the conversation. */
|
|
74
90
|
id: string;
|
|
75
|
-
/**
|
|
91
|
+
/** App ID. */
|
|
76
92
|
app_id: string;
|
|
77
93
|
/** Name of the agent in this conversation. */
|
|
78
94
|
agent_name: string;
|
|
@@ -127,7 +143,7 @@ export interface AgentMessage {
|
|
|
127
143
|
*/
|
|
128
144
|
export interface CreateConversationParams {
|
|
129
145
|
/** The name of the agent to create a conversation with. */
|
|
130
|
-
agent_name:
|
|
146
|
+
agent_name: AgentName;
|
|
131
147
|
/** Optional metadata to attach to the conversation. */
|
|
132
148
|
metadata?: Record<string, any>;
|
|
133
149
|
}
|
|
@@ -138,9 +154,9 @@ export interface CreateConversationParams {
|
|
|
138
154
|
export interface AgentsModuleConfig {
|
|
139
155
|
/** Axios instance for HTTP requests */
|
|
140
156
|
axios: AxiosInstance;
|
|
141
|
-
/** Function to get WebSocket instance for
|
|
157
|
+
/** Function to get WebSocket instance for realtime updates (lazy initialization) */
|
|
142
158
|
getSocket: () => ReturnType<typeof RoomsSocket>;
|
|
143
|
-
/**
|
|
159
|
+
/** App ID */
|
|
144
160
|
appId: string;
|
|
145
161
|
/** Server URL */
|
|
146
162
|
serverUrl?: string;
|
|
@@ -151,29 +167,38 @@ export interface AgentsModuleConfig {
|
|
|
151
167
|
* Agents module for managing AI agent conversations.
|
|
152
168
|
*
|
|
153
169
|
* This module provides methods to create and manage conversations with AI agents,
|
|
154
|
-
* send messages, and subscribe to
|
|
170
|
+
* send messages, and subscribe to realtime updates. Conversations can be used
|
|
155
171
|
* for chat interfaces, support systems, or any interactive AI app.
|
|
156
172
|
*
|
|
173
|
+
* ## Key Features
|
|
174
|
+
*
|
|
157
175
|
* The agents module enables you to:
|
|
158
176
|
*
|
|
159
177
|
* - **Create conversations** with agents defined in the app.
|
|
160
178
|
* - **Send messages** from users to agents and receive AI-generated responses.
|
|
161
179
|
* - **Retrieve conversations** individually or as filtered lists with sorting and pagination.
|
|
162
|
-
* - **Subscribe to
|
|
180
|
+
* - **Subscribe to realtime updates** using WebSocket connections to receive instant notifications when new messages arrive.
|
|
163
181
|
* - **Attach metadata** to conversations for tracking context, categories, priorities, or linking to external systems.
|
|
164
182
|
* - **Generate WhatsApp connection URLs** for users to interact with agents through WhatsApp.
|
|
165
183
|
*
|
|
184
|
+
* ## Conversation Structure
|
|
185
|
+
*
|
|
166
186
|
* The agents module operates with a two-level hierarchy:
|
|
167
187
|
*
|
|
168
188
|
* 1. **Conversations**: Top-level containers that represent a dialogue with a specific agent. Each conversation has a unique ID, is associated with an agent by name, and belongs to the user who created it. Conversations can include optional metadata for tracking app-specific context like ticket IDs, categories, or custom fields.
|
|
169
189
|
*
|
|
170
190
|
* 2. **Messages**: Individual exchanges within a conversation. Each message has a role, content, and optional metadata like token usage, tool calls, file attachments, and reasoning information. Messages are stored as an array within their parent conversation.
|
|
171
191
|
*
|
|
192
|
+
* ## Authentication Modes
|
|
193
|
+
*
|
|
172
194
|
* This module is available to use with a client in all authentication modes:
|
|
173
195
|
*
|
|
174
|
-
* - **Anonymous or User authentication** (`base44.agents`): Access is scoped to the current user's permissions.
|
|
196
|
+
* - **Anonymous or User authentication** (`base44.agents`): Access is scoped to the current user's permissions. Users must be authenticated to create and access conversations.
|
|
175
197
|
* - **Service role authentication** (`base44.asServiceRole.agents`): Operations have elevated admin-level permissions. Can access all conversations that the app's admin role has access to.
|
|
176
198
|
*
|
|
199
|
+
* ## Generated Types
|
|
200
|
+
*
|
|
201
|
+
* If you're working in a TypeScript project, you can generate types from your agents to get autocomplete on agent names when creating conversations or subscribing to updates. See the [Dynamic Types](/developers/references/sdk/getting-started/dynamic-types) guide to get started.
|
|
177
202
|
*/
|
|
178
203
|
export interface AgentsModule {
|
|
179
204
|
/**
|
|
@@ -198,7 +223,9 @@ export interface AgentsModule {
|
|
|
198
223
|
* Gets a specific conversation by ID.
|
|
199
224
|
*
|
|
200
225
|
* Retrieves a single conversation using its unique identifier. To retrieve
|
|
201
|
-
* all conversations, use {@linkcode getConversations | getConversations()} To filter, sort, or paginate conversations, use {@linkcode listConversations | listConversations()}.
|
|
226
|
+
* all conversations, use {@linkcode getConversations | getConversations()}. To filter, sort, or paginate conversations, use {@linkcode listConversations | listConversations()}.
|
|
227
|
+
*
|
|
228
|
+
* This function returns the complete stored conversation including full tool call results, even for large responses.
|
|
202
229
|
*
|
|
203
230
|
* @param conversationId - The unique identifier of the conversation.
|
|
204
231
|
* @returns Promise resolving to the conversation, or undefined if not found.
|
|
@@ -275,7 +302,7 @@ export interface AgentsModule {
|
|
|
275
302
|
* Adds a message to a conversation.
|
|
276
303
|
*
|
|
277
304
|
* Sends a message to the agent and updates the conversation. This method
|
|
278
|
-
* also updates the
|
|
305
|
+
* also updates the realtime socket to notify any subscribers.
|
|
279
306
|
*
|
|
280
307
|
* @param conversation - The conversation to add the message to.
|
|
281
308
|
* @param message - The message to add.
|
|
@@ -293,19 +320,29 @@ export interface AgentsModule {
|
|
|
293
320
|
*/
|
|
294
321
|
addMessage(conversation: AgentConversation, message: Partial<AgentMessage>): Promise<AgentMessage>;
|
|
295
322
|
/**
|
|
296
|
-
* Subscribes to
|
|
323
|
+
* Subscribes to realtime updates for a conversation.
|
|
297
324
|
*
|
|
298
325
|
* Establishes a WebSocket connection to receive instant updates when new
|
|
299
326
|
* messages are added to the conversation. Returns an unsubscribe function
|
|
300
327
|
* to clean up the connection.
|
|
301
328
|
*
|
|
329
|
+
* <Note>
|
|
330
|
+
* When receiving messages through this function, tool call data is truncated for efficiency. The `arguments_string` is limited to 500 characters and `results` to 50 characters. The complete tool call data is always saved in storage and can be retrieved by calling {@linkcode getConversation | getConversation()} after the message completes.
|
|
331
|
+
* </Note>
|
|
332
|
+
*
|
|
302
333
|
* @param conversationId - The conversation ID to subscribe to.
|
|
303
|
-
* @param onUpdate - Callback function called when the conversation is updated.
|
|
334
|
+
* @param onUpdate - Callback function called when the conversation is updated. The callback receives a conversation object with the following properties:
|
|
335
|
+
* - `id`: Unique identifier for the conversation.
|
|
336
|
+
* - `agent_name`: Name of the agent in this conversation.
|
|
337
|
+
* - `created_date`: ISO 8601 timestamp of when the conversation was created.
|
|
338
|
+
* - `updated_date`: ISO 8601 timestamp of when the conversation was last updated.
|
|
339
|
+
* - `messages`: Array of messages in the conversation. Each message includes `id`, `role` (`'user'`, `'assistant'`, or `'system'`), `content`, `created_date`, and optionally `tool_calls`, `reasoning`, `file_urls`, and `usage`.
|
|
340
|
+
* - `metadata`: Optional metadata associated with the conversation.
|
|
304
341
|
* @returns Unsubscribe function to stop receiving updates.
|
|
305
342
|
*
|
|
306
343
|
* @example
|
|
307
344
|
* ```typescript
|
|
308
|
-
* // Subscribe to
|
|
345
|
+
* // Subscribe to realtime updates
|
|
309
346
|
* const unsubscribe = base44.agents.subscribeToConversation(
|
|
310
347
|
* 'conv-123',
|
|
311
348
|
* (updatedConversation) => {
|
|
@@ -336,5 +373,5 @@ export interface AgentsModule {
|
|
|
336
373
|
* // User can open this URL to start a WhatsApp conversation
|
|
337
374
|
* ```
|
|
338
375
|
*/
|
|
339
|
-
getWhatsAppConnectURL(agentName:
|
|
376
|
+
getWhatsAppConnectURL(agentName: AgentName): string;
|
|
340
377
|
}
|
|
@@ -1,8 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Properties for analytics events.
|
|
3
|
+
*
|
|
4
|
+
* Key-value pairs with additional event data. Values can be strings, numbers, booleans, or null.
|
|
5
|
+
*/
|
|
1
6
|
export type TrackEventProperties = {
|
|
2
7
|
[key: string]: string | number | boolean | null | undefined;
|
|
3
8
|
};
|
|
9
|
+
/**
|
|
10
|
+
* Parameters for tracking an analytics event.
|
|
11
|
+
*/
|
|
4
12
|
export type TrackEventParams = {
|
|
13
|
+
/**
|
|
14
|
+
* Name of the event to track.
|
|
15
|
+
*
|
|
16
|
+
* Use descriptive names like `button_click`, `form_submit`, or `purchase_completed`.
|
|
17
|
+
*/
|
|
5
18
|
eventName: string;
|
|
19
|
+
/**
|
|
20
|
+
* Optional key-value pairs with additional event data.
|
|
21
|
+
*
|
|
22
|
+
* Values can be strings, numbers, booleans, or null.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```typescript
|
|
26
|
+
* base44.analytics.track({
|
|
27
|
+
* eventName: 'add_to_cart',
|
|
28
|
+
* properties: {
|
|
29
|
+
* product_id: 'prod_123',
|
|
30
|
+
* price: 29.99,
|
|
31
|
+
* quantity: 2
|
|
32
|
+
* }
|
|
33
|
+
* });
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
6
36
|
properties?: TrackEventProperties;
|
|
7
37
|
};
|
|
8
38
|
export type TrackEventIntrinsicData = {
|
|
@@ -37,6 +67,56 @@ export type AnalyticsModuleOptions = {
|
|
|
37
67
|
batchSize?: number;
|
|
38
68
|
heartBeatInterval?: number;
|
|
39
69
|
};
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
70
|
+
/**
|
|
71
|
+
* Analytics module for tracking custom events in your app.
|
|
72
|
+
*
|
|
73
|
+
* Use this module to track specific user actions. Track things like button clicks, form submissions, purchases, and feature usage.
|
|
74
|
+
*
|
|
75
|
+
* <Note> Analytics events tracked with this module appear as custom event cards in the [Analytics dashboard](/documentation/performance-and-seo/app-analytics).</Note>
|
|
76
|
+
*
|
|
77
|
+
* ## Best Practices
|
|
78
|
+
*
|
|
79
|
+
* When tracking events:
|
|
80
|
+
*
|
|
81
|
+
* - Choose clear, descriptive event names in snake_case like `signup_button_click` or `purchase_completed` rather than generic names like `click`.
|
|
82
|
+
* - Include relevant context in your properties such as identifiers like `product_id`, measurements like `price`, and flags like `is_first_purchase`.
|
|
83
|
+
*
|
|
84
|
+
* ## Authentication Modes
|
|
85
|
+
*
|
|
86
|
+
* This module is only available in user authentication mode (`base44.analytics`).
|
|
87
|
+
*/
|
|
88
|
+
export interface AnalyticsModule {
|
|
89
|
+
/**
|
|
90
|
+
* Tracks a custom event that appears as a card in your Analytics dashboard.
|
|
91
|
+
*
|
|
92
|
+
* Each unique event name becomes its own card showing total count and trends over time. This method returns immediately and events are sent in batches in the background.
|
|
93
|
+
*
|
|
94
|
+
* @param params - Event parameters.
|
|
95
|
+
* @param params.eventName - Name of the event. This becomes the card title in your dashboard. Use descriptive names like `'signup_button_click'` or `'purchase_completed'`.
|
|
96
|
+
* @param params.properties - Optional data to attach to the event. You can filter and analyze events by these properties in the dashboard.
|
|
97
|
+
*
|
|
98
|
+
* @example Track a button click
|
|
99
|
+
* ```typescript
|
|
100
|
+
* // Track a button click
|
|
101
|
+
* base44.analytics.track({
|
|
102
|
+
* eventName: 'signup_button_click'
|
|
103
|
+
* });
|
|
104
|
+
* ```
|
|
105
|
+
*
|
|
106
|
+
* @example Track with properties
|
|
107
|
+
* ```typescript
|
|
108
|
+
* // Track with properties
|
|
109
|
+
* base44.analytics.track({
|
|
110
|
+
* eventName: 'add_to_cart',
|
|
111
|
+
* properties: {
|
|
112
|
+
* product_id: 'prod_123',
|
|
113
|
+
* product_name: 'Premium Widget',
|
|
114
|
+
* price: 29.99,
|
|
115
|
+
* quantity: 2,
|
|
116
|
+
* is_first_purchase: true
|
|
117
|
+
* }
|
|
118
|
+
* });
|
|
119
|
+
* ```
|
|
120
|
+
*/
|
|
121
|
+
track(params: TrackEventParams): void;
|
|
122
|
+
}
|
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
*
|
|
4
4
|
* This module provides a method to log user activity. The logs are reflected in the Analytics page in the app dashboard.
|
|
5
5
|
*
|
|
6
|
+
* ## Authentication Modes
|
|
7
|
+
*
|
|
6
8
|
* This module is available to use with a client in all authentication modes.
|
|
7
9
|
*/
|
|
8
10
|
export interface AppLogsModule {
|