@depup/base44__sdk 0.8.22-depup.0
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/LICENSE +21 -0
- package/README.md +32 -0
- package/changes.json +14 -0
- package/dist/client.d.ts +96 -0
- package/dist/client.js +375 -0
- package/dist/client.types.d.ts +144 -0
- package/dist/client.types.js +1 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +5 -0
- package/dist/modules/agents.d.ts +2 -0
- package/dist/modules/agents.js +77 -0
- package/dist/modules/agents.types.d.ts +377 -0
- package/dist/modules/agents.types.js +1 -0
- package/dist/modules/analytics.d.ts +20 -0
- package/dist/modules/analytics.js +277 -0
- package/dist/modules/analytics.types.d.ts +122 -0
- package/dist/modules/analytics.types.js +1 -0
- package/dist/modules/app-logs.d.ts +11 -0
- package/dist/modules/app-logs.js +27 -0
- package/dist/modules/app-logs.types.d.ts +46 -0
- package/dist/modules/app-logs.types.js +1 -0
- package/dist/modules/app.types.d.ts +142 -0
- package/dist/modules/app.types.js +1 -0
- package/dist/modules/auth.d.ts +13 -0
- package/dist/modules/auth.js +180 -0
- package/dist/modules/auth.types.d.ts +481 -0
- package/dist/modules/auth.types.js +1 -0
- package/dist/modules/connectors.d.ts +20 -0
- package/dist/modules/connectors.js +71 -0
- package/dist/modules/connectors.types.d.ts +296 -0
- package/dist/modules/connectors.types.js +1 -0
- package/dist/modules/custom-integrations.d.ts +11 -0
- package/dist/modules/custom-integrations.js +32 -0
- package/dist/modules/custom-integrations.types.d.ts +89 -0
- package/dist/modules/custom-integrations.types.js +1 -0
- package/dist/modules/entities.d.ts +20 -0
- package/dist/modules/entities.js +149 -0
- package/dist/modules/entities.types.d.ts +552 -0
- package/dist/modules/entities.types.js +1 -0
- package/dist/modules/functions.d.ts +12 -0
- package/dist/modules/functions.js +79 -0
- package/dist/modules/functions.types.d.ts +103 -0
- package/dist/modules/functions.types.js +1 -0
- package/dist/modules/integrations.d.ts +11 -0
- package/dist/modules/integrations.js +77 -0
- package/dist/modules/integrations.types.d.ts +413 -0
- package/dist/modules/integrations.types.js +1 -0
- package/dist/modules/sso.d.ts +12 -0
- package/dist/modules/sso.js +23 -0
- package/dist/modules/sso.types.d.ts +44 -0
- package/dist/modules/sso.types.js +1 -0
- package/dist/modules/types.d.ts +4 -0
- package/dist/modules/types.js +4 -0
- package/dist/modules/users.d.ts +16 -0
- package/dist/modules/users.js +23 -0
- package/dist/types.d.ts +72 -0
- package/dist/types.js +1 -0
- package/dist/utils/auth-utils.d.ts +117 -0
- package/dist/utils/auth-utils.js +189 -0
- package/dist/utils/auth-utils.types.d.ts +146 -0
- package/dist/utils/auth-utils.types.js +1 -0
- package/dist/utils/axios-client.d.ts +100 -0
- package/dist/utils/axios-client.js +193 -0
- package/dist/utils/axios-client.types.d.ts +28 -0
- package/dist/utils/axios-client.types.js +1 -0
- package/dist/utils/common.d.ts +3 -0
- package/dist/utils/common.js +6 -0
- package/dist/utils/sharedInstance.d.ts +1 -0
- package/dist/utils/sharedInstance.js +15 -0
- package/dist/utils/socket-utils.d.ts +47 -0
- package/dist/utils/socket-utils.js +115 -0
- package/package.json +87 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { createClient, createClientFromRequest, type Base44Client, type CreateClientConfig, type CreateClientOptions } from "./client.js";
|
|
2
|
+
import { Base44Error, type Base44ErrorJSON } from "./utils/axios-client.js";
|
|
3
|
+
import { getAccessToken, saveAccessToken, removeAccessToken, getLoginUrl } from "./utils/auth-utils.js";
|
|
4
|
+
export { createClient, createClientFromRequest, Base44Error, getAccessToken, saveAccessToken, removeAccessToken, getLoginUrl, };
|
|
5
|
+
export type { Base44Client, CreateClientConfig, CreateClientOptions, Base44ErrorJSON, };
|
|
6
|
+
export * from "./types.js";
|
|
7
|
+
export type { DeleteManyResult, DeleteResult, EntitiesModule, EntityHandler, EntityRecord, EntityTypeRegistry, ImportResult, RealtimeEventType, RealtimeEvent, RealtimeCallback, SortField, UpdateManyResult, } from "./modules/entities.types.js";
|
|
8
|
+
export type { AuthModule, LoginResponse, RegisterParams, VerifyOtpParams, ChangePasswordParams, ResetPasswordParams, User, } from "./modules/auth.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
|
+
export type { AppLogsModule } from "./modules/app-logs.types.js";
|
|
13
|
+
export type { SsoModule, SsoAccessTokenResponse } from "./modules/sso.types.js";
|
|
14
|
+
export type { ConnectorsModule, UserConnectorsModule, } from "./modules/connectors.types.js";
|
|
15
|
+
export type { CustomIntegrationsModule, CustomIntegrationCallParams, CustomIntegrationCallResponse, } from "./modules/custom-integrations.types.js";
|
|
16
|
+
export type { GetAccessTokenOptions, SaveAccessTokenOptions, RemoveAccessTokenOptions, GetLoginUrlOptions, } from "./utils/auth-utils.types.js";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { createClient, createClientFromRequest, } from "./client.js";
|
|
2
|
+
import { Base44Error } from "./utils/axios-client.js";
|
|
3
|
+
import { getAccessToken, saveAccessToken, removeAccessToken, getLoginUrl, } from "./utils/auth-utils.js";
|
|
4
|
+
export { createClient, createClientFromRequest, Base44Error, getAccessToken, saveAccessToken, removeAccessToken, getLoginUrl, };
|
|
5
|
+
export * from "./types.js";
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { getAccessToken } from "../utils/auth-utils.js";
|
|
2
|
+
export function createAgentsModule({ axios, getSocket, appId, serverUrl, token, }) {
|
|
3
|
+
const baseURL = `/apps/${appId}/agents`;
|
|
4
|
+
// Track active conversations
|
|
5
|
+
const currentConversations = {};
|
|
6
|
+
const getConversations = () => {
|
|
7
|
+
return axios.get(`${baseURL}/conversations`);
|
|
8
|
+
};
|
|
9
|
+
const getConversation = (conversationId) => {
|
|
10
|
+
return axios.get(`${baseURL}/conversations/${conversationId}`);
|
|
11
|
+
};
|
|
12
|
+
const listConversations = (filterParams) => {
|
|
13
|
+
return axios.get(`${baseURL}/conversations`, {
|
|
14
|
+
params: filterParams,
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
const createConversation = (conversation) => {
|
|
18
|
+
return axios.post(`${baseURL}/conversations`, conversation);
|
|
19
|
+
};
|
|
20
|
+
const addMessage = async (conversation, message) => {
|
|
21
|
+
return axios.post(`${baseURL}/conversations/v2/${conversation.id}/messages`, message);
|
|
22
|
+
};
|
|
23
|
+
const subscribeToConversation = (conversationId, onUpdate) => {
|
|
24
|
+
const room = `/agent-conversations/${conversationId}`;
|
|
25
|
+
const socket = getSocket();
|
|
26
|
+
// Store the promise for initial conversation state
|
|
27
|
+
const conversationPromise = getConversation(conversationId).then((conv) => {
|
|
28
|
+
currentConversations[conversationId] = conv;
|
|
29
|
+
return conv;
|
|
30
|
+
});
|
|
31
|
+
return socket.subscribeToRoom(room, {
|
|
32
|
+
connect: () => { },
|
|
33
|
+
update_model: async ({ data: jsonStr }) => {
|
|
34
|
+
const data = JSON.parse(jsonStr);
|
|
35
|
+
if (data._message) {
|
|
36
|
+
// Wait for initial conversation to be loaded
|
|
37
|
+
await conversationPromise;
|
|
38
|
+
const message = data._message;
|
|
39
|
+
// Update shared conversation state
|
|
40
|
+
const currentConversation = currentConversations[conversationId];
|
|
41
|
+
if (currentConversation) {
|
|
42
|
+
const messages = currentConversation.messages || [];
|
|
43
|
+
const existingIndex = messages.findIndex((m) => m.id === message.id);
|
|
44
|
+
const updatedMessages = existingIndex !== -1
|
|
45
|
+
? messages.map((m, i) => (i === existingIndex ? message : m))
|
|
46
|
+
: [...messages, message];
|
|
47
|
+
currentConversations[conversationId] = {
|
|
48
|
+
...currentConversation,
|
|
49
|
+
messages: updatedMessages,
|
|
50
|
+
};
|
|
51
|
+
onUpdate === null || onUpdate === void 0 ? void 0 : onUpdate(currentConversations[conversationId]);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
};
|
|
57
|
+
const getWhatsAppConnectURL = (agentName) => {
|
|
58
|
+
const baseUrl = `${serverUrl}/api/apps/${appId}/agents/${encodeURIComponent(agentName)}/whatsapp`;
|
|
59
|
+
const accessToken = token !== null && token !== void 0 ? token : getAccessToken();
|
|
60
|
+
if (accessToken) {
|
|
61
|
+
return `${baseUrl}?token=${accessToken}`;
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
// No token - URL will redirect to login automatically
|
|
65
|
+
return baseUrl;
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
return {
|
|
69
|
+
getConversations,
|
|
70
|
+
getConversation,
|
|
71
|
+
listConversations,
|
|
72
|
+
createConversation,
|
|
73
|
+
addMessage,
|
|
74
|
+
subscribeToConversation,
|
|
75
|
+
getWhatsAppConnectURL,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
@@ -0,0 +1,377 @@
|
|
|
1
|
+
import { AxiosInstance } from "axios";
|
|
2
|
+
import { RoomsSocket } from "../utils/socket-utils.js";
|
|
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;
|
|
20
|
+
/**
|
|
21
|
+
* Reasoning information for an agent message.
|
|
22
|
+
*
|
|
23
|
+
* Contains details about the agent's reasoning process when generating a response.
|
|
24
|
+
*/
|
|
25
|
+
export interface AgentMessageReasoning {
|
|
26
|
+
/** When reasoning started. */
|
|
27
|
+
start_date: string;
|
|
28
|
+
/** When reasoning ended. */
|
|
29
|
+
end_date?: string;
|
|
30
|
+
/** Reasoning content. */
|
|
31
|
+
content: string;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* A tool call made by the agent.
|
|
35
|
+
*
|
|
36
|
+
* Represents a function or tool that the agent invoked during message generation.
|
|
37
|
+
*/
|
|
38
|
+
export interface AgentMessageToolCall {
|
|
39
|
+
/** Tool call ID. */
|
|
40
|
+
id: string;
|
|
41
|
+
/** Name of the tool called. */
|
|
42
|
+
name: string;
|
|
43
|
+
/** Arguments passed to the tool as JSON string. */
|
|
44
|
+
arguments_string: string;
|
|
45
|
+
/** Status of the tool call. */
|
|
46
|
+
status: "running" | "success" | "error" | "stopped";
|
|
47
|
+
/** Results from the tool call. */
|
|
48
|
+
results?: string;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Token usage statistics for an agent message.
|
|
52
|
+
*
|
|
53
|
+
* Tracks the number of tokens consumed when generating the message.
|
|
54
|
+
*/
|
|
55
|
+
export interface AgentMessageUsage {
|
|
56
|
+
/** Number of tokens in the prompt. */
|
|
57
|
+
prompt_tokens?: number;
|
|
58
|
+
/** Number of tokens in the completion. */
|
|
59
|
+
completion_tokens?: number;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Custom context provided with an agent message.
|
|
63
|
+
*
|
|
64
|
+
* Additional contextual information that can be passed to the agent.
|
|
65
|
+
*/
|
|
66
|
+
export interface AgentMessageCustomContext {
|
|
67
|
+
/** Context message. */
|
|
68
|
+
message: string;
|
|
69
|
+
/** Associated data for the context. */
|
|
70
|
+
data: Record<string, any>;
|
|
71
|
+
/** Type of context. */
|
|
72
|
+
type: string;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Metadata about when and by whom a message was created.
|
|
76
|
+
*/
|
|
77
|
+
export interface AgentMessageMetadata {
|
|
78
|
+
/** When the message was created. */
|
|
79
|
+
created_date: string;
|
|
80
|
+
/** Email of the user who created the message. */
|
|
81
|
+
created_by_email: string;
|
|
82
|
+
/** Full name of the user who created the message. */
|
|
83
|
+
created_by_full_name: string;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* An agent conversation containing messages exchanged with an AI agent.
|
|
87
|
+
*/
|
|
88
|
+
export interface AgentConversation {
|
|
89
|
+
/** Unique identifier for the conversation. */
|
|
90
|
+
id: string;
|
|
91
|
+
/** App ID. */
|
|
92
|
+
app_id: string;
|
|
93
|
+
/** Name of the agent in this conversation. */
|
|
94
|
+
agent_name: string;
|
|
95
|
+
/** ID of the user who created the conversation. */
|
|
96
|
+
created_by_id: string;
|
|
97
|
+
/** When the conversation was created. */
|
|
98
|
+
created_date: string;
|
|
99
|
+
/** When the conversation was last updated. */
|
|
100
|
+
updated_date: string;
|
|
101
|
+
/** Array of messages in the conversation. */
|
|
102
|
+
messages: AgentMessage[];
|
|
103
|
+
/** Optional metadata associated with the conversation. */
|
|
104
|
+
metadata?: Record<string, any>;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* A message in an agent conversation.
|
|
108
|
+
*/
|
|
109
|
+
export interface AgentMessage {
|
|
110
|
+
/** Unique identifier for the message. */
|
|
111
|
+
id: string;
|
|
112
|
+
/** Role of the message sender. */
|
|
113
|
+
role: "user" | "assistant" | "system";
|
|
114
|
+
/** When the message was created. */
|
|
115
|
+
created_date: string;
|
|
116
|
+
/** When the message was last updated. */
|
|
117
|
+
updated_date: string;
|
|
118
|
+
/** Optional reasoning information for the message. */
|
|
119
|
+
reasoning?: AgentMessageReasoning | null;
|
|
120
|
+
/** Message content. */
|
|
121
|
+
content?: string | Record<string, any>;
|
|
122
|
+
/** URLs to files attached to the message. */
|
|
123
|
+
file_urls?: string[];
|
|
124
|
+
/** Tool calls made by the agent. */
|
|
125
|
+
tool_calls?: AgentMessageToolCall[];
|
|
126
|
+
/** Token usage statistics. */
|
|
127
|
+
usage?: AgentMessageUsage;
|
|
128
|
+
/** Whether the message is hidden from the user. */
|
|
129
|
+
hidden?: boolean;
|
|
130
|
+
/** Custom context provided with the message. */
|
|
131
|
+
custom_context?: AgentMessageCustomContext[];
|
|
132
|
+
/** Model used to generate the message. */
|
|
133
|
+
model?: string;
|
|
134
|
+
/** Checkpoint ID for the message. */
|
|
135
|
+
checkpoint_id?: string;
|
|
136
|
+
/** Metadata about when and by whom the message was created. */
|
|
137
|
+
metadata?: AgentMessageMetadata;
|
|
138
|
+
/** Additional custom parameters for the message. */
|
|
139
|
+
additional_message_params?: Record<string, any>;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Parameters for creating a new conversation.
|
|
143
|
+
*/
|
|
144
|
+
export interface CreateConversationParams {
|
|
145
|
+
/** The name of the agent to create a conversation with. */
|
|
146
|
+
agent_name: AgentName;
|
|
147
|
+
/** Optional metadata to attach to the conversation. */
|
|
148
|
+
metadata?: Record<string, any>;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Configuration for creating the agents module.
|
|
152
|
+
* @internal
|
|
153
|
+
*/
|
|
154
|
+
export interface AgentsModuleConfig {
|
|
155
|
+
/** Axios instance for HTTP requests */
|
|
156
|
+
axios: AxiosInstance;
|
|
157
|
+
/** Function to get WebSocket instance for realtime updates (lazy initialization) */
|
|
158
|
+
getSocket: () => ReturnType<typeof RoomsSocket>;
|
|
159
|
+
/** App ID */
|
|
160
|
+
appId: string;
|
|
161
|
+
/** Server URL */
|
|
162
|
+
serverUrl?: string;
|
|
163
|
+
/** Authentication token */
|
|
164
|
+
token?: string;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Agents module for managing AI agent conversations.
|
|
168
|
+
*
|
|
169
|
+
* This module provides methods to create and manage conversations with AI agents,
|
|
170
|
+
* send messages, and subscribe to realtime updates. Conversations can be used
|
|
171
|
+
* for chat interfaces, support systems, or any interactive AI app.
|
|
172
|
+
*
|
|
173
|
+
* ## Key Features
|
|
174
|
+
*
|
|
175
|
+
* The agents module enables you to:
|
|
176
|
+
*
|
|
177
|
+
* - **Create conversations** with agents defined in the app.
|
|
178
|
+
* - **Send messages** from users to agents and receive AI-generated responses.
|
|
179
|
+
* - **Retrieve conversations** individually or as filtered lists with sorting and pagination.
|
|
180
|
+
* - **Subscribe to realtime updates** using WebSocket connections to receive instant notifications when new messages arrive.
|
|
181
|
+
* - **Attach metadata** to conversations for tracking context, categories, priorities, or linking to external systems.
|
|
182
|
+
* - **Generate WhatsApp connection URLs** for users to interact with agents through WhatsApp.
|
|
183
|
+
*
|
|
184
|
+
* ## Conversation Structure
|
|
185
|
+
*
|
|
186
|
+
* The agents module operates with a two-level hierarchy:
|
|
187
|
+
*
|
|
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.
|
|
189
|
+
*
|
|
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.
|
|
191
|
+
*
|
|
192
|
+
* ## Authentication Modes
|
|
193
|
+
*
|
|
194
|
+
* This module is available to use with a client in all authentication modes:
|
|
195
|
+
*
|
|
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.
|
|
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.
|
|
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.
|
|
202
|
+
*/
|
|
203
|
+
export interface AgentsModule {
|
|
204
|
+
/**
|
|
205
|
+
* Gets all conversations from all agents in the app.
|
|
206
|
+
*
|
|
207
|
+
* Retrieves all conversations. Use {@linkcode listConversations | listConversations()} to filter which conversations are returned, apply sorting, or paginate results. Use {@linkcode getConversation | getConversation()} to retrieve a specific conversation by ID.
|
|
208
|
+
*
|
|
209
|
+
* @returns Promise resolving to an array of conversations.
|
|
210
|
+
*
|
|
211
|
+
* @example
|
|
212
|
+
* ```typescript
|
|
213
|
+
* // Get all conversations
|
|
214
|
+
* const conversations = await base44.agents.getConversations();
|
|
215
|
+
* console.log(`Total conversations: ${conversations.length}`);
|
|
216
|
+
* ```
|
|
217
|
+
*
|
|
218
|
+
* @see {@linkcode listConversations | listConversations()} for filtering, sorting, and pagination
|
|
219
|
+
* @see {@linkcode getConversation | getConversation()} for retrieving a specific conversation by ID
|
|
220
|
+
*/
|
|
221
|
+
getConversations(): Promise<AgentConversation[]>;
|
|
222
|
+
/**
|
|
223
|
+
* Gets a specific conversation by ID.
|
|
224
|
+
*
|
|
225
|
+
* Retrieves a single conversation using its unique identifier. To retrieve
|
|
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.
|
|
229
|
+
*
|
|
230
|
+
* @param conversationId - The unique identifier of the conversation.
|
|
231
|
+
* @returns Promise resolving to the conversation, or undefined if not found.
|
|
232
|
+
*
|
|
233
|
+
* @example
|
|
234
|
+
* ```typescript
|
|
235
|
+
* // Get a specific conversation by ID
|
|
236
|
+
* const conversation = await base44.agents.getConversation('conv-123');
|
|
237
|
+
* if (conversation) {
|
|
238
|
+
* console.log(`Conversation has ${conversation.messages.length} messages`);
|
|
239
|
+
* }
|
|
240
|
+
* ```
|
|
241
|
+
*
|
|
242
|
+
* @see {@linkcode getConversations | getConversations()} for retrieving all conversations
|
|
243
|
+
* @see {@linkcode listConversations | listConversations()} for filtering and sorting conversations
|
|
244
|
+
*/
|
|
245
|
+
getConversation(conversationId: string): Promise<AgentConversation | undefined>;
|
|
246
|
+
/**
|
|
247
|
+
* Lists conversations with filtering, sorting, and pagination.
|
|
248
|
+
*
|
|
249
|
+
* Provides querying capabilities including filtering by fields, sorting, pagination, and field selection. For cases where you need all conversations without filtering, use {@linkcode getConversations | getConversations()}. To retrieve a specific conversation by ID, use {@linkcode getConversation | getConversation()}.
|
|
250
|
+
*
|
|
251
|
+
* @param filterParams - Filter parameters for querying conversations.
|
|
252
|
+
* @returns Promise resolving to an array of filtered conversations.
|
|
253
|
+
*
|
|
254
|
+
* @example
|
|
255
|
+
* ```typescript
|
|
256
|
+
* // List recent conversations with pagination
|
|
257
|
+
* const recentConversations = await base44.agents.listConversations({
|
|
258
|
+
* limit: 10,
|
|
259
|
+
* sort: '-created_date'
|
|
260
|
+
* });
|
|
261
|
+
* ```
|
|
262
|
+
*
|
|
263
|
+
* @example
|
|
264
|
+
* ```typescript
|
|
265
|
+
* // Filter by agent and metadata
|
|
266
|
+
* const supportConversations = await base44.agents.listConversations({
|
|
267
|
+
* q: {
|
|
268
|
+
* agent_name: 'support-agent',
|
|
269
|
+
* 'metadata.priority': 'high'
|
|
270
|
+
* },
|
|
271
|
+
* sort: '-created_date',
|
|
272
|
+
* limit: 20
|
|
273
|
+
* });
|
|
274
|
+
* ```
|
|
275
|
+
*
|
|
276
|
+
* @see {@linkcode getConversations | getConversations()} for retrieving all conversations without filtering
|
|
277
|
+
* @see {@linkcode getConversation | getConversation()} for retrieving a specific conversation by ID
|
|
278
|
+
*/
|
|
279
|
+
listConversations(filterParams: ModelFilterParams): Promise<AgentConversation[]>;
|
|
280
|
+
/**
|
|
281
|
+
* Creates a new conversation with an agent.
|
|
282
|
+
*
|
|
283
|
+
* @param conversation - Conversation details including agent name and optional metadata.
|
|
284
|
+
* @returns Promise resolving to the created conversation.
|
|
285
|
+
*
|
|
286
|
+
* @example
|
|
287
|
+
* ```typescript
|
|
288
|
+
* // Create a new conversation with metadata
|
|
289
|
+
* const conversation = await base44.agents.createConversation({
|
|
290
|
+
* agent_name: 'support-agent',
|
|
291
|
+
* metadata: {
|
|
292
|
+
* order_id: 'ORD-789',
|
|
293
|
+
* product_id: 'PROD-456',
|
|
294
|
+
* category: 'technical-support'
|
|
295
|
+
* }
|
|
296
|
+
* });
|
|
297
|
+
* console.log(`Created conversation: ${conversation.id}`);
|
|
298
|
+
* ```
|
|
299
|
+
*/
|
|
300
|
+
createConversation(conversation: CreateConversationParams): Promise<AgentConversation>;
|
|
301
|
+
/**
|
|
302
|
+
* Adds a message to a conversation.
|
|
303
|
+
*
|
|
304
|
+
* Sends a message to the agent and updates the conversation. This method
|
|
305
|
+
* also updates the realtime socket to notify any subscribers.
|
|
306
|
+
*
|
|
307
|
+
* @param conversation - The conversation to add the message to.
|
|
308
|
+
* @param message - The message to add.
|
|
309
|
+
* @returns Promise resolving to the created message.
|
|
310
|
+
*
|
|
311
|
+
* @example
|
|
312
|
+
* ```typescript
|
|
313
|
+
* // Send a message to the agent
|
|
314
|
+
* const message = await base44.agents.addMessage(conversation, {
|
|
315
|
+
* role: 'user',
|
|
316
|
+
* content: 'Hello, I need help with my order #12345'
|
|
317
|
+
* });
|
|
318
|
+
* console.log(`Message sent with ID: ${message.id}`);
|
|
319
|
+
* ```
|
|
320
|
+
*/
|
|
321
|
+
addMessage(conversation: AgentConversation, message: Partial<AgentMessage>): Promise<AgentMessage>;
|
|
322
|
+
/**
|
|
323
|
+
* Subscribes to realtime updates for a conversation.
|
|
324
|
+
*
|
|
325
|
+
* Establishes a WebSocket connection to receive instant updates when new
|
|
326
|
+
* messages are added to the conversation. Returns an unsubscribe function
|
|
327
|
+
* to clean up the connection.
|
|
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
|
+
*
|
|
333
|
+
* @param conversationId - The conversation ID to subscribe to.
|
|
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.
|
|
341
|
+
* @returns Unsubscribe function to stop receiving updates.
|
|
342
|
+
*
|
|
343
|
+
* @example
|
|
344
|
+
* ```typescript
|
|
345
|
+
* // Subscribe to realtime updates
|
|
346
|
+
* const unsubscribe = base44.agents.subscribeToConversation(
|
|
347
|
+
* 'conv-123',
|
|
348
|
+
* (updatedConversation) => {
|
|
349
|
+
* const latestMessage = updatedConversation.messages[updatedConversation.messages.length - 1];
|
|
350
|
+
* console.log('New message:', latestMessage.content);
|
|
351
|
+
* }
|
|
352
|
+
* );
|
|
353
|
+
*
|
|
354
|
+
* // Later, clean up the subscription
|
|
355
|
+
* unsubscribe();
|
|
356
|
+
* ```
|
|
357
|
+
*/
|
|
358
|
+
subscribeToConversation(conversationId: string, onUpdate?: (conversation: AgentConversation) => void): () => void;
|
|
359
|
+
/**
|
|
360
|
+
* Gets WhatsApp connection URL for an agent.
|
|
361
|
+
*
|
|
362
|
+
* Generates a URL that users can use to connect with the agent through WhatsApp.
|
|
363
|
+
* The URL includes authentication if a token is available.
|
|
364
|
+
*
|
|
365
|
+
* @param agentName - The name of the agent.
|
|
366
|
+
* @returns WhatsApp connection URL.
|
|
367
|
+
*
|
|
368
|
+
* @example
|
|
369
|
+
* ```typescript
|
|
370
|
+
* // Get WhatsApp connection URL
|
|
371
|
+
* const whatsappUrl = base44.agents.getWhatsAppConnectURL('support-agent');
|
|
372
|
+
* console.log(`Connect through WhatsApp: ${whatsappUrl}`);
|
|
373
|
+
* // User can open this URL to start a WhatsApp conversation
|
|
374
|
+
* ```
|
|
375
|
+
*/
|
|
376
|
+
getWhatsAppConnectURL(agentName: AgentName): string;
|
|
377
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { AxiosInstance } from "axios";
|
|
2
|
+
import { TrackEventParams, AnalyticsModuleOptions } from "./analytics.types";
|
|
3
|
+
import type { AuthModule } from "./auth.types";
|
|
4
|
+
export declare const USER_HEARTBEAT_EVENT_NAME = "__user_heartbeat_event__";
|
|
5
|
+
export declare const ANALYTICS_INITIALIZATION_EVENT_NAME = "__initialization_event__";
|
|
6
|
+
export declare const ANALYTICS_SESSION_DURATION_EVENT_NAME = "__session_duration_event__";
|
|
7
|
+
export declare const ANALYTICS_CONFIG_ENABLE_URL_PARAM_KEY = "analytics-enable";
|
|
8
|
+
export declare const ANALYTICS_SESSION_ID_LOCAL_STORAGE_KEY = "base44_analytics_session_id";
|
|
9
|
+
export interface AnalyticsModuleArgs {
|
|
10
|
+
axiosClient: AxiosInstance;
|
|
11
|
+
serverUrl: string;
|
|
12
|
+
appId: string;
|
|
13
|
+
userAuthModule: AuthModule;
|
|
14
|
+
}
|
|
15
|
+
export declare const createAnalyticsModule: ({ axiosClient, serverUrl, appId, userAuthModule, }: AnalyticsModuleArgs) => {
|
|
16
|
+
track: (params: TrackEventParams) => void;
|
|
17
|
+
cleanup: () => void;
|
|
18
|
+
};
|
|
19
|
+
export declare function getAnalyticsConfigFromUrlParams(): AnalyticsModuleOptions | undefined;
|
|
20
|
+
export declare function getAnalyticsSessionId(): string;
|