@base44/sdk 0.8.17 → 0.8.18
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 +2 -2
- package/dist/modules/agents.js +29 -10
- package/dist/modules/auth.js +10 -0
- package/dist/modules/auth.types.d.ts +21 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -12,7 +12,7 @@ The SDK provides access to Base44's functionality through the following modules:
|
|
|
12
12
|
- **[`connectors`](https://docs.base44.com/sdk-docs/interfaces/connectors)**: Manage OAuth connections and access tokens for third-party services.
|
|
13
13
|
- **[`entities`](https://docs.base44.com/sdk-docs/interfaces/entities)**: Work with your app's data entities using CRUD operations.
|
|
14
14
|
- **[`functions`](https://docs.base44.com/sdk-docs/interfaces/functions)**: Execute backend functions.
|
|
15
|
-
- **[`integrations`](https://docs.base44.com/sdk-docs/type-aliases/integrations)**:
|
|
15
|
+
- **[`integrations`](https://docs.base44.com/sdk-docs/type-aliases/integrations)**: Pre-built server-side functions for external services.
|
|
16
16
|
|
|
17
17
|
## Example
|
|
18
18
|
|
|
@@ -78,4 +78,4 @@ Generate API documentation locally:
|
|
|
78
78
|
npm run create-docs
|
|
79
79
|
cd docs
|
|
80
80
|
mintlify dev
|
|
81
|
-
```
|
|
81
|
+
```
|
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
|
};
|
package/dist/modules/auth.js
CHANGED
|
@@ -34,6 +34,16 @@ export function createAuthModule(axios, functionsAxiosClient, appId, options) {
|
|
|
34
34
|
// Redirect to the login page
|
|
35
35
|
window.location.href = loginUrl;
|
|
36
36
|
},
|
|
37
|
+
// Redirects the user to a provider's login page
|
|
38
|
+
loginWithProvider(provider, fromUrl = "/") {
|
|
39
|
+
// Build the full redirect URL
|
|
40
|
+
const redirectUrl = new URL(fromUrl, window.location.origin).toString();
|
|
41
|
+
// Build the provider login URL (google is the default, so no provider path needed)
|
|
42
|
+
const providerPath = provider === "google" ? "" : `/${provider}`;
|
|
43
|
+
const loginUrl = `${options.serverUrl}/api/apps/auth${providerPath}/login?app_id=${appId}&from_url=${encodeURIComponent(redirectUrl)}`;
|
|
44
|
+
// Redirect to the provider login page
|
|
45
|
+
window.location.href = loginUrl;
|
|
46
|
+
},
|
|
37
47
|
// Logout the current user
|
|
38
48
|
// Removes the token from localStorage and optionally redirects to a URL or reloads the page
|
|
39
49
|
logout(redirectUrl) {
|
|
@@ -171,6 +171,27 @@ export interface AuthModule {
|
|
|
171
171
|
* ```
|
|
172
172
|
*/
|
|
173
173
|
redirectToLogin(nextUrl: string): void;
|
|
174
|
+
/**
|
|
175
|
+
* Redirects the user to a third-party authentication provider's login page.
|
|
176
|
+
*
|
|
177
|
+
* Initiates OAuth/SSO login flow with providers like Google, Microsoft, etc. Requires a browser environment and can't be used in the backend.
|
|
178
|
+
*
|
|
179
|
+
* @param provider - Name of the supported authentication provider (e.g., 'google', 'microsoft').
|
|
180
|
+
* @param fromUrl - URL to redirect to after successful authentication. Defaults to '/'.
|
|
181
|
+
*
|
|
182
|
+
* @example
|
|
183
|
+
* ```typescript
|
|
184
|
+
* // Login with Google and return to current page
|
|
185
|
+
* base44.auth.loginWithProvider('google', window.location.pathname);
|
|
186
|
+
* ```
|
|
187
|
+
*
|
|
188
|
+
* @example
|
|
189
|
+
* ```typescript
|
|
190
|
+
* // Login with GitHub and redirect to dashboard
|
|
191
|
+
* base44.auth.loginWithProvider('microsoft', '/dashboard');
|
|
192
|
+
* ```
|
|
193
|
+
*/
|
|
194
|
+
loginWithProvider(provider: string, fromUrl?: string): void;
|
|
174
195
|
/**
|
|
175
196
|
* Logs out the current user.
|
|
176
197
|
*
|