@base44-preview/sdk 0.8.17-pr.70.d92fc2a → 0.8.17-pr.71.cfa9c83
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/modules/agents.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { getAccessToken } from "../utils/auth-utils.js";
|
|
2
2
|
export function createAgentsModule({ axios, getSocket, appId, serverUrl, token, }) {
|
|
3
3
|
const baseURL = `/apps/${appId}/agents`;
|
|
4
|
+
// Track active conversations
|
|
5
|
+
const currentConversations = {};
|
|
4
6
|
const getConversations = () => {
|
|
5
7
|
return axios.get(`${baseURL}/conversations`);
|
|
6
8
|
};
|
|
@@ -16,22 +18,39 @@ export function createAgentsModule({ axios, getSocket, appId, serverUrl, token,
|
|
|
16
18
|
return axios.post(`${baseURL}/conversations`, conversation);
|
|
17
19
|
};
|
|
18
20
|
const addMessage = async (conversation, message) => {
|
|
19
|
-
|
|
20
|
-
const socket = getSocket();
|
|
21
|
-
await socket.updateModel(room, {
|
|
22
|
-
...conversation,
|
|
23
|
-
messages: [...(conversation.messages || []), message],
|
|
24
|
-
});
|
|
25
|
-
return axios.post(`${baseURL}/conversations/${conversation.id}/messages`, message);
|
|
21
|
+
return axios.post(`${baseURL}/conversations/v2/${conversation.id}/messages`, message);
|
|
26
22
|
};
|
|
27
23
|
const subscribeToConversation = (conversationId, onUpdate) => {
|
|
28
24
|
const room = `/agent-conversations/${conversationId}`;
|
|
29
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
|
+
});
|
|
30
31
|
return socket.subscribeToRoom(room, {
|
|
31
32
|
connect: () => { },
|
|
32
|
-
update_model: ({ data: jsonStr }) => {
|
|
33
|
-
const
|
|
34
|
-
|
|
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
|
+
}
|
|
35
54
|
},
|
|
36
55
|
});
|
|
37
56
|
};
|
|
@@ -72,7 +72,7 @@ export interface AgentMessageMetadata {
|
|
|
72
72
|
export interface AgentConversation {
|
|
73
73
|
/** Unique identifier for the conversation. */
|
|
74
74
|
id: string;
|
|
75
|
-
/**
|
|
75
|
+
/** Application ID. */
|
|
76
76
|
app_id: string;
|
|
77
77
|
/** Name of the agent in this conversation. */
|
|
78
78
|
agent_name: string;
|
|
@@ -140,7 +140,7 @@ export interface AgentsModuleConfig {
|
|
|
140
140
|
axios: AxiosInstance;
|
|
141
141
|
/** Function to get WebSocket instance for real-time updates (lazy initialization) */
|
|
142
142
|
getSocket: () => ReturnType<typeof RoomsSocket>;
|
|
143
|
-
/**
|
|
143
|
+
/** Application ID */
|
|
144
144
|
appId: string;
|
|
145
145
|
/** Server URL */
|
|
146
146
|
serverUrl?: string;
|
|
@@ -11,7 +11,9 @@ export interface ConnectorAccessTokenResponse {
|
|
|
11
11
|
/**
|
|
12
12
|
* Connectors module for managing OAuth tokens for external services.
|
|
13
13
|
*
|
|
14
|
-
* This module allows you to retrieve OAuth access tokens for external services
|
|
14
|
+
* This module allows you to retrieve OAuth access tokens for external services
|
|
15
|
+
* that the app has connected to. Use these tokens to make API
|
|
16
|
+
* calls to external services.
|
|
15
17
|
*
|
|
16
18
|
* Unlike the integrations module that provides pre-built functions, connectors give you
|
|
17
19
|
* raw OAuth tokens so you can call external service APIs directly with full control over
|
|
@@ -24,9 +26,9 @@ export interface ConnectorsModule {
|
|
|
24
26
|
/**
|
|
25
27
|
* Retrieves an OAuth access token for a specific external integration type.
|
|
26
28
|
*
|
|
27
|
-
* Returns the OAuth token string for an external service that
|
|
28
|
-
* has connected to.
|
|
29
|
-
*
|
|
29
|
+
* Returns the OAuth token string for an external service that the app
|
|
30
|
+
* has connected to. You can then use this token to make authenticated API calls
|
|
31
|
+
* to that external service.
|
|
30
32
|
*
|
|
31
33
|
* @param integrationType - The type of integration, such as `'googlecalendar'`, `'slack'`, or `'github'`.
|
|
32
34
|
* @returns Promise resolving to the access token string.
|
|
@@ -14,6 +14,11 @@ export interface CustomIntegrationCallParams {
|
|
|
14
14
|
* Query string parameters to append to the URL.
|
|
15
15
|
*/
|
|
16
16
|
queryParams?: Record<string, any>;
|
|
17
|
+
/**
|
|
18
|
+
* Additional headers to send with this specific request.
|
|
19
|
+
* These are merged with the integration's configured headers.
|
|
20
|
+
*/
|
|
21
|
+
headers?: Record<string, string>;
|
|
17
22
|
}
|
|
18
23
|
/**
|
|
19
24
|
* Response from a custom integration call.
|
|
@@ -47,17 +52,18 @@ export interface CustomIntegrationCallResponse {
|
|
|
47
52
|
*
|
|
48
53
|
* @example
|
|
49
54
|
* ```typescript
|
|
50
|
-
* // Call a custom
|
|
55
|
+
* // Call a custom GitHub integration
|
|
51
56
|
* const response = await base44.integrations.custom.call(
|
|
52
|
-
* "
|
|
53
|
-
* "
|
|
57
|
+
* "github", // integration slug (defined by workspace admin)
|
|
58
|
+
* "listIssues", // operation ID from the OpenAPI spec
|
|
54
59
|
* {
|
|
55
|
-
*
|
|
60
|
+
* pathParams: { owner: "myorg", repo: "myrepo" },
|
|
61
|
+
* queryParams: { state: "open", per_page: 100 }
|
|
56
62
|
* }
|
|
57
63
|
* );
|
|
58
64
|
*
|
|
59
65
|
* if (response.success) {
|
|
60
|
-
* console.log("
|
|
66
|
+
* console.log("Issues:", response.data);
|
|
61
67
|
* } else {
|
|
62
68
|
* console.error("API returned error:", response.status_code);
|
|
63
69
|
* }
|
|
@@ -65,10 +71,10 @@ export interface CustomIntegrationCallResponse {
|
|
|
65
71
|
*
|
|
66
72
|
* @example
|
|
67
73
|
* ```typescript
|
|
68
|
-
* // Call with
|
|
74
|
+
* // Call with request body payload
|
|
69
75
|
* const response = await base44.integrations.custom.call(
|
|
70
76
|
* "github",
|
|
71
|
-
* "
|
|
77
|
+
* "createIssue",
|
|
72
78
|
* {
|
|
73
79
|
* pathParams: { owner: "myorg", repo: "myrepo" },
|
|
74
80
|
* payload: {
|
|
@@ -84,9 +90,9 @@ export interface CustomIntegrationsModule {
|
|
|
84
90
|
/**
|
|
85
91
|
* Call a custom integration endpoint.
|
|
86
92
|
*
|
|
87
|
-
* @param slug - The integration's unique identifier, as defined by the workspace admin.
|
|
88
|
-
* @param operationId - The
|
|
89
|
-
* @param params - Optional parameters including payload, pathParams, and
|
|
93
|
+
* @param slug - The integration's unique identifier (slug), as defined by the workspace admin.
|
|
94
|
+
* @param operationId - The operation ID from the OpenAPI spec (e.g., "listIssues", "getUser").
|
|
95
|
+
* @param params - Optional parameters including payload, pathParams, queryParams, and headers.
|
|
90
96
|
* @returns Promise resolving to the integration call response.
|
|
91
97
|
*
|
|
92
98
|
* @throws {Error} If slug is not provided.
|