@base44-preview/sdk 0.8.59-pr.373.e530673 → 0.8.60-pr.375.db5e899
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 +22 -3
- package/dist/client.types.d.ts +3 -0
- package/dist/index.d.ts +2 -1
- package/dist/modules/integrations.types.d.ts +53 -5
- package/dist/modules/voice.d.ts +23 -0
- package/dist/modules/voice.js +55 -0
- package/dist/modules/voice.types.d.ts +187 -0
- package/dist/modules/voice.types.js +4 -0
- package/dist/utils/build-commit-source.d.ts +19 -0
- package/dist/utils/build-commit-source.fallback.d.ts +14 -0
- package/dist/utils/build-commit-source.fallback.js +16 -0
- package/dist/utils/build-commit-source.js +26 -0
- package/dist/utils/build-commit.d.ts +12 -0
- package/dist/utils/build-commit.js +24 -0
- package/package.json +8 -1
package/dist/client.js
CHANGED
|
@@ -4,9 +4,11 @@ import { createIntegrationsModule } from "./modules/integrations.js";
|
|
|
4
4
|
import { createAuthModule } from "./modules/auth.js";
|
|
5
5
|
import { createSsoModule } from "./modules/sso.js";
|
|
6
6
|
import { createBrowserModule } from "./modules/browser.js";
|
|
7
|
+
import { createVoiceModule } from "./modules/voice.js";
|
|
7
8
|
import { createConnectorsModule, createUserConnectorsModule, } from "./modules/connectors.js";
|
|
8
9
|
import { getAccessToken } from "./utils/auth-utils.js";
|
|
9
10
|
import { createFetchWithAuth } from "./utils/fetch-with-auth.js";
|
|
11
|
+
import { BUILD_COMMIT_HEADER, getBuildCommitHeaders, } from "./utils/build-commit.js";
|
|
10
12
|
import { createFunctionsModule } from "./modules/functions.js";
|
|
11
13
|
import { createAgentsModule } from "./modules/agents.js";
|
|
12
14
|
import { createAiGatewayModule } from "./modules/ai-gateway.js";
|
|
@@ -55,6 +57,9 @@ import { createActorsModule, resolveActorsHost, } from "./modules/actors.js";
|
|
|
55
57
|
* ```
|
|
56
58
|
*/
|
|
57
59
|
export function createClient(config) {
|
|
60
|
+
return buildClient(config, { sendBuildCommit: true });
|
|
61
|
+
}
|
|
62
|
+
function buildClient(config, { sendBuildCommit }) {
|
|
58
63
|
var _a, _b, _c, _d;
|
|
59
64
|
const { serverUrl = "https://base44.app", appId, analytics, token, serviceToken, requiresAuth = false, appBaseUrl, options, functionsVersion, headers: optionalHeaders, } = config;
|
|
60
65
|
// Normalize appBaseUrl to always be a string (empty if not provided or invalid)
|
|
@@ -75,7 +80,18 @@ export function createClient(config) {
|
|
|
75
80
|
}
|
|
76
81
|
return socket;
|
|
77
82
|
};
|
|
83
|
+
// The build commit goes on every API call, so the backend can tell which
|
|
84
|
+
// frontend bundle a request came from. One set by the caller, in any
|
|
85
|
+
// casing, replaces it; resolving that once here keeps every call path,
|
|
86
|
+
// functions.fetch() included, reporting the same build.
|
|
87
|
+
const callerBuildCommit = Object.entries(optionalHeaders !== null && optionalHeaders !== void 0 ? optionalHeaders : {}).find(([name]) => name.toLowerCase() === BUILD_COMMIT_HEADER.toLowerCase());
|
|
88
|
+
const buildCommitHeaders = callerBuildCommit
|
|
89
|
+
? { [BUILD_COMMIT_HEADER]: callerBuildCommit[1] }
|
|
90
|
+
: sendBuildCommit
|
|
91
|
+
? getBuildCommitHeaders()
|
|
92
|
+
: {};
|
|
78
93
|
const headers = {
|
|
94
|
+
...(callerBuildCommit ? {} : buildCommitHeaders),
|
|
79
95
|
...optionalHeaders,
|
|
80
96
|
"X-App-Id": String(appId),
|
|
81
97
|
};
|
|
@@ -178,7 +194,7 @@ export function createClient(config) {
|
|
|
178
194
|
auth: userAuthModule,
|
|
179
195
|
functions: createFunctionsModule(functionsAxiosClient, appId, {
|
|
180
196
|
getAuthHeaders: () => {
|
|
181
|
-
const headers = {};
|
|
197
|
+
const headers = { ...buildCommitHeaders };
|
|
182
198
|
// Get current token from storage or initial config
|
|
183
199
|
const currentToken = token || getAccessToken();
|
|
184
200
|
if (currentToken) {
|
|
@@ -230,6 +246,7 @@ export function createClient(config) {
|
|
|
230
246
|
integrations: createIntegrationsModule(serviceRoleAxiosClient, appId),
|
|
231
247
|
sso: createSsoModule(serviceRoleAxiosClient, appId),
|
|
232
248
|
browser: createBrowserModule(serviceRoleAxiosClient),
|
|
249
|
+
voice: createVoiceModule(serviceRoleAxiosClient, { functionsVersion }),
|
|
233
250
|
connectors: createConnectorsModule(serviceRoleAxiosClient, appId),
|
|
234
251
|
functions: createFunctionsModule(serviceRoleFunctionsAxiosClient, appId, {
|
|
235
252
|
getAuthHeaders: () => {
|
|
@@ -454,12 +471,14 @@ export function createClientFromRequest(request) {
|
|
|
454
471
|
if (dataEnvHeader === "dev" || dataEnvHeader === "prod") {
|
|
455
472
|
additionalHeaders["X-Data-Env"] = dataEnvHeader;
|
|
456
473
|
}
|
|
457
|
-
|
|
474
|
+
// A backend function isn't the browser bundle, so it never reports a build
|
|
475
|
+
// commit, whatever its runtime looks like.
|
|
476
|
+
return buildClient({
|
|
458
477
|
serverUrl: serverUrlHeader || "https://base44.app",
|
|
459
478
|
appId,
|
|
460
479
|
token: userToken,
|
|
461
480
|
serviceToken: serviceRoleToken,
|
|
462
481
|
functionsVersion: functionsVersion !== null && functionsVersion !== void 0 ? functionsVersion : undefined,
|
|
463
482
|
headers: additionalHeaders,
|
|
464
|
-
});
|
|
483
|
+
}, { sendBuildCommit: false });
|
|
465
484
|
}
|
package/dist/client.types.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import type { IntegrationsModule } from "./modules/integrations.types.js";
|
|
|
3
3
|
import type { AuthModule } from "./modules/auth.types.js";
|
|
4
4
|
import type { SsoModule } from "./modules/sso.types.js";
|
|
5
5
|
import type { BrowserModule } from "./modules/browser.types.js";
|
|
6
|
+
import type { VoiceModule } from "./modules/voice.types.js";
|
|
6
7
|
import type { PaymentsModule, ServiceRolePaymentsModule } from "./modules/payments.types.js";
|
|
7
8
|
import type { ConnectorsModule, UserConnectorsModule } from "./modules/connectors.types.js";
|
|
8
9
|
import type { FunctionsModule } from "./modules/functions.types.js";
|
|
@@ -245,6 +246,8 @@ export interface Base44Client {
|
|
|
245
246
|
payments: ServiceRolePaymentsModule;
|
|
246
247
|
/** {@link SsoModule | SSO module} for generating SSO tokens. */
|
|
247
248
|
sso: SsoModule;
|
|
249
|
+
/** {@link VoiceModule | Voice module} for live voice sessions. */
|
|
250
|
+
voice: VoiceModule;
|
|
248
251
|
/** Cleanup function to disconnect WebSocket connections. */
|
|
249
252
|
cleanup: () => void;
|
|
250
253
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ export type { Base44Client, CreateClientAnalyticsConfig, CreateClientConfig, Cre
|
|
|
6
6
|
export * from "./types.js";
|
|
7
7
|
export type { DeleteManyResult, DeleteResult, EntitiesModule, EntityAggregateResult, EntityAggregateSpec, EntityDateBucket, EntityDistinctOptions, EntityFilterOperators, EntityFilterQuery, EntityFilterValue, EntityHandler, EntityListOptions, EntityPage, EntityRecord, EntityTypeRegistry, EntityUpsertOptions, EntityUpsertResult, ImportResult, RealtimeEventType, RealtimeEvent, RealtimeCallback, SortField, UpdateManyResult, } 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, IntegrationEndpointFunction, CoreIntegrations, InvokeLLMParams, GenerateImageParams, GenerateImageResult, UploadFileParams, UploadFileResult, SendEmailParams, SendEmailResult, ExtractDataFromUploadedFileParams, ExtractDataFromUploadedFileResult, UploadPrivateFileParams, UploadPrivateFileResult, CreateFileSignedUrlParams, CreateFileSignedUrlResult, } from "./modules/integrations.types.js";
|
|
9
|
+
export type { IntegrationsModule, IntegrationEndpointFunction, CoreIntegrations, InvokeLLMParams, GenerateImageParams, GenerateImageResult, UploadFileParams, UploadFileResult, EmailAttachment, SendEmailParams, SendEmailResult, ExtractDataFromUploadedFileParams, ExtractDataFromUploadedFileResult, UploadPrivateFileParams, UploadPrivateFileResult, CreateFileSignedUrlParams, CreateFileSignedUrlResult, } from "./modules/integrations.types.js";
|
|
10
10
|
export type { FunctionsModule, FunctionName, FunctionNameRegistry, } from "./modules/functions.types.js";
|
|
11
11
|
export type { AgentsModule, AgentName, AgentNameRegistry, AgentConversation, AgentMessage, AgentMessageReasoning, AgentMessageToolCall, AgentMessageUsage, AgentMessageCustomContext, AgentMessageMetadata, CreateConversationParams, } from "./modules/agents.types.js";
|
|
12
12
|
export type { AiGatewayModule, AiGatewayConnection, AiGatewayConnectionOptions, } from "./modules/ai-gateway.types.js";
|
|
@@ -16,6 +16,7 @@ export type { ActorsModule, ActorClient, ActorRef, Connection, ActorSubscription
|
|
|
16
16
|
export type { SsoModule, SsoAccessTokenResponse } from "./modules/sso.types.js";
|
|
17
17
|
export type { PaymentsModule, ServiceRolePaymentsModule, PaymentsErrorCode, PaymentsRecurringFrequency, CheckoutBuyer, CheckoutFreeTrial, CheckoutItem, CheckoutItemRecurring, CheckoutPresentation, CheckoutShipping, CheckoutElement, CheckoutMount, MountableCheckout, CreateCheckoutParams, CreateCheckoutResult, CompleteCheckoutResult, EmbeddedCheckout, PayPalCheckoutOnClick, PayPalEmbeddedCheckout, StripeEmbeddedCheckout, MountCheckoutOptions, ListPurchasesParams, ServiceRoleListPurchasesParams, ListPurchasesResult, Purchase, PurchaseItem, PurchaseStatus, RefundParams, ShippingAddress, RefundResult, CancelSubscriptionOptions, SubscriptionResult, } from "./modules/payments.types.js";
|
|
18
18
|
export type { BrowserModule, BrowserSession, BrowserSessionOptions, } from "./modules/browser.types.js";
|
|
19
|
+
export type { VoiceModule, VoiceSession, VoiceSessionMessage, VoiceSessionOptions, } from "./modules/voice.types.js";
|
|
19
20
|
export { Actor, type Conn } from "./actor.js";
|
|
20
21
|
export type { ConnectorsModule, UserConnectorsModule, ConnectorApiRequest, ConnectorApiResponse, ConnectorApiResponsePhase, } from "./modules/connectors.types.js";
|
|
21
22
|
export type { CustomIntegrationsModule, CustomIntegrationCallParams, CustomIntegrationCallResponse, } from "./modules/custom-integrations.types.js";
|
|
@@ -86,6 +86,21 @@ export interface UploadFileResult {
|
|
|
86
86
|
/** URL of the uploaded file. */
|
|
87
87
|
file_url: string;
|
|
88
88
|
}
|
|
89
|
+
/**
|
|
90
|
+
* A file to attach to an email.
|
|
91
|
+
*/
|
|
92
|
+
export interface EmailAttachment {
|
|
93
|
+
/**
|
|
94
|
+
* File name the recipient sees, including the extension. The supported extensions are `csv`, `docx`, `gif`, `ics`, `jpeg`, `jpg`, `md`, `pdf`, `png`, `txt`, `webp`, and `xlsx`.
|
|
95
|
+
*/
|
|
96
|
+
filename: string;
|
|
97
|
+
/**
|
|
98
|
+
* A file your app already uploaded, such as the `file_url` returned by [`UploadFile()`](#uploadfile) or the `file_uri` returned by [`UploadPrivateFile()`](#uploadprivatefile). Files uploaded by other apps are rejected.
|
|
99
|
+
*/
|
|
100
|
+
file_url?: string;
|
|
101
|
+
/** Base64-encoded file contents, for a file your code generated. */
|
|
102
|
+
content?: string;
|
|
103
|
+
}
|
|
89
104
|
/**
|
|
90
105
|
* Parameters for the SendEmail function.
|
|
91
106
|
*/
|
|
@@ -94,10 +109,18 @@ export interface SendEmailParams {
|
|
|
94
109
|
to: string;
|
|
95
110
|
/** Email subject line. */
|
|
96
111
|
subject: string;
|
|
97
|
-
/**
|
|
98
|
-
body
|
|
99
|
-
/** The
|
|
112
|
+
/** HTML email body. The same as `html`, so set one or the other, not both. */
|
|
113
|
+
body?: string;
|
|
114
|
+
/** HTML email body. The same as `body`, so set one or the other, not both. */
|
|
115
|
+
html?: string;
|
|
116
|
+
/**
|
|
117
|
+
* Plain-text email body. On its own, it sends a plain-text email. Set it together with `body` or `html` to send both versions in one email, and the recipient's mail client shows whichever it prefers. Make sure both versions say the same thing.
|
|
118
|
+
*/
|
|
119
|
+
text?: string;
|
|
120
|
+
/** The name of the sender. If omitted, the app's name is used. */
|
|
100
121
|
from_name?: string;
|
|
122
|
+
/** Files to attach. You can attach up to 5 files, up to 5 MB each and 10 MB in total. Set `filename` and exactly one of `file_url` or `content` on each file. */
|
|
123
|
+
attachments?: EmailAttachment[];
|
|
101
124
|
}
|
|
102
125
|
export type SendEmailResult = any;
|
|
103
126
|
/**
|
|
@@ -236,10 +259,35 @@ export interface CoreIntegrations {
|
|
|
236
259
|
*/
|
|
237
260
|
UploadFile(params: UploadFileParams): Promise<UploadFileResult>;
|
|
238
261
|
/**
|
|
239
|
-
* Send
|
|
262
|
+
* Send an email from your app.
|
|
263
|
+
*
|
|
264
|
+
* You can always email registered users of your app. To email anyone else, the app needs a paid plan and a connected custom domain.
|
|
240
265
|
*
|
|
241
|
-
* @param params - Parameters for sending email
|
|
266
|
+
* @param params - Parameters for sending email. Set at least one of `body`, `html`, or `text`.
|
|
242
267
|
* @returns Promise resolving when the email is sent.
|
|
268
|
+
*
|
|
269
|
+
* @example
|
|
270
|
+
* ```typescript
|
|
271
|
+
* // Send an HTML email with a plain-text version
|
|
272
|
+
* await base44.integrations.Core.SendEmail({
|
|
273
|
+
* to: "user@example.com",
|
|
274
|
+
* subject: "Your order has shipped",
|
|
275
|
+
* html: "<p>Your order <strong>#1234</strong> is on its way.</p>",
|
|
276
|
+
* text: "Your order #1234 is on its way.",
|
|
277
|
+
* });
|
|
278
|
+
* ```
|
|
279
|
+
*
|
|
280
|
+
* @example
|
|
281
|
+
* ```typescript
|
|
282
|
+
* // Attach a file your app uploaded
|
|
283
|
+
* const { file_url } = await base44.integrations.Core.UploadFile({ file });
|
|
284
|
+
* await base44.integrations.Core.SendEmail({
|
|
285
|
+
* to: "user@example.com",
|
|
286
|
+
* subject: "Your invoice",
|
|
287
|
+
* html: "<p>Your invoice is attached.</p>",
|
|
288
|
+
* attachments: [{ filename: "invoice.pdf", file_url }],
|
|
289
|
+
* });
|
|
290
|
+
* ```
|
|
243
291
|
*/
|
|
244
292
|
SendEmail(params: SendEmailParams): Promise<SendEmailResult>;
|
|
245
293
|
/**
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { AxiosInstance } from "axios";
|
|
2
|
+
import { VoiceModule } from "./voice.types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Options for {@linkcode createVoiceModule}.
|
|
5
|
+
*
|
|
6
|
+
* @internal
|
|
7
|
+
*/
|
|
8
|
+
export interface VoiceModuleConfig {
|
|
9
|
+
/** Sent as `Base44-Functions-Version` so the backend can pick the draft MCP profile. */
|
|
10
|
+
functionsVersion?: string;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Creates the Voice module for the Base44 SDK.
|
|
14
|
+
*
|
|
15
|
+
* The module passes every value through unchanged. Base44 validates them, so
|
|
16
|
+
* a backend rule change never needs an SDK release.
|
|
17
|
+
*
|
|
18
|
+
* @param axios - Axios instance (should be service role client)
|
|
19
|
+
* @param config - Module configuration
|
|
20
|
+
* @returns Voice module with methods to create and end live voice sessions
|
|
21
|
+
* @internal
|
|
22
|
+
*/
|
|
23
|
+
export declare function createVoiceModule(axios: AxiosInstance, { functionsVersion }?: VoiceModuleConfig): VoiceModule;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates the Voice module for the Base44 SDK.
|
|
3
|
+
*
|
|
4
|
+
* The module passes every value through unchanged. Base44 validates them, so
|
|
5
|
+
* a backend rule change never needs an SDK release.
|
|
6
|
+
*
|
|
7
|
+
* @param axios - Axios instance (should be service role client)
|
|
8
|
+
* @param config - Module configuration
|
|
9
|
+
* @returns Voice module with methods to create and end live voice sessions
|
|
10
|
+
* @internal
|
|
11
|
+
*/
|
|
12
|
+
export function createVoiceModule(axios, { functionsVersion } = {}) {
|
|
13
|
+
const endSession = async (sessionId) => {
|
|
14
|
+
if (!sessionId || typeof sessionId !== "string") {
|
|
15
|
+
throw new Error("Session ID is required and must be a string");
|
|
16
|
+
}
|
|
17
|
+
await axios.delete(`/v1/voice-sessions/${encodeURIComponent(sessionId)}`);
|
|
18
|
+
};
|
|
19
|
+
return {
|
|
20
|
+
async createSession(options) {
|
|
21
|
+
// The app is derived from the service token, so the route isn't app-scoped.
|
|
22
|
+
const response = await axios.post("/v1/voice-sessions", {
|
|
23
|
+
sdp: options.sdp,
|
|
24
|
+
mcp_profile_id: options.mcpProfileId,
|
|
25
|
+
voice_instructions: options.voiceInstructions,
|
|
26
|
+
agent_instructions: options.agentInstructions,
|
|
27
|
+
// Send optional keys only when set, so the backend applies its defaults.
|
|
28
|
+
...(options.voiceModel !== undefined && {
|
|
29
|
+
voice_model: options.voiceModel,
|
|
30
|
+
}),
|
|
31
|
+
...(options.agentModel !== undefined && {
|
|
32
|
+
agent_model: options.agentModel,
|
|
33
|
+
}),
|
|
34
|
+
...(options.voice !== undefined && { voice: options.voice }),
|
|
35
|
+
...(options.initialMessages !== undefined && {
|
|
36
|
+
initial_messages: options.initialMessages,
|
|
37
|
+
}),
|
|
38
|
+
}, {
|
|
39
|
+
// The backend picks the draft or published MCP profile from this
|
|
40
|
+
// header. The service-role client doesn't send it by default.
|
|
41
|
+
headers: functionsVersion
|
|
42
|
+
? { "Base44-Functions-Version": functionsVersion }
|
|
43
|
+
: undefined,
|
|
44
|
+
});
|
|
45
|
+
const data = response;
|
|
46
|
+
return {
|
|
47
|
+
sessionId: data.session_id,
|
|
48
|
+
sdp: data.sdp,
|
|
49
|
+
expiresAt: data.expires_at,
|
|
50
|
+
environment: data.environment,
|
|
51
|
+
};
|
|
52
|
+
},
|
|
53
|
+
endSession,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A text message placed in the conversation before the call starts.
|
|
3
|
+
*/
|
|
4
|
+
export interface VoiceSessionMessage {
|
|
5
|
+
/**
|
|
6
|
+
* Who wrote the message, such as:
|
|
7
|
+
*
|
|
8
|
+
* - `'developer'`: Context for the voice agent, such as what the current user is looking at.
|
|
9
|
+
* - `'user'`: An earlier turn by the current user.
|
|
10
|
+
* - `'assistant'`: An earlier turn by the voice agent.
|
|
11
|
+
*/
|
|
12
|
+
role: string;
|
|
13
|
+
/** The message text. */
|
|
14
|
+
text: string;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Options for {@linkcode VoiceModule.createSession | createSession()}.
|
|
18
|
+
*/
|
|
19
|
+
export interface VoiceSessionOptions {
|
|
20
|
+
/**
|
|
21
|
+
* The browser's WebRTC SDP offer.
|
|
22
|
+
*
|
|
23
|
+
* Create it in the browser with [`RTCPeerConnection.createOffer()`](https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/createOffer) and send it to your backend function. A new offer is needed for every session.
|
|
24
|
+
*/
|
|
25
|
+
sdp: string;
|
|
26
|
+
/**
|
|
27
|
+
* ID of the app's MCP profile whose tools the voice agent can use.
|
|
28
|
+
*
|
|
29
|
+
* The AI inserts this ID into your backend function when it sets up voice for the app.
|
|
30
|
+
*/
|
|
31
|
+
mcpProfileId: string;
|
|
32
|
+
/**
|
|
33
|
+
* Model that talks with the current user, as an AI Gateway model ID. Defaults to Base44's default voice model.
|
|
34
|
+
*/
|
|
35
|
+
voiceModel?: string;
|
|
36
|
+
/**
|
|
37
|
+
* Model behind the voice that calls the app's tools, as an AI Gateway model ID, such as `'gpt_6_luna'`. Defaults to Base44's default agent model.
|
|
38
|
+
*/
|
|
39
|
+
agentModel?: string;
|
|
40
|
+
/**
|
|
41
|
+
* How the voice model speaks with the current user, such as its persona, tone, and turn-taking.
|
|
42
|
+
*/
|
|
43
|
+
voiceInstructions: string;
|
|
44
|
+
/**
|
|
45
|
+
* How the agent behind the voice uses the app's tools to answer and act.
|
|
46
|
+
*/
|
|
47
|
+
agentInstructions: string;
|
|
48
|
+
/**
|
|
49
|
+
* Built-in voice to speak with, such as `'cedar'`. The voice is fixed for the whole session. Defaults to the provider's default voice.
|
|
50
|
+
*/
|
|
51
|
+
voice?: string;
|
|
52
|
+
/**
|
|
53
|
+
* Text conversation placed before the call starts, oldest first.
|
|
54
|
+
*
|
|
55
|
+
* Use it to give the voice agent context, or to continue a conversation the current user started in text.
|
|
56
|
+
*/
|
|
57
|
+
initialMessages?: VoiceSessionMessage[];
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* A live voice session returned by {@linkcode VoiceModule.createSession | createSession()}.
|
|
61
|
+
*/
|
|
62
|
+
export interface VoiceSession {
|
|
63
|
+
/**
|
|
64
|
+
* Opaque session identifier issued to your app.
|
|
65
|
+
*
|
|
66
|
+
* Pass it unchanged to [`endSession()`](#endsession) to end the session.
|
|
67
|
+
*/
|
|
68
|
+
sessionId: string;
|
|
69
|
+
/**
|
|
70
|
+
* The SDP answer.
|
|
71
|
+
*
|
|
72
|
+
* Return it to the browser and apply it with [`RTCPeerConnection.setRemoteDescription()`](https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/setRemoteDescription). Audio then flows directly between the browser and the voice model.
|
|
73
|
+
*/
|
|
74
|
+
sdp: string;
|
|
75
|
+
/** ISO 8601 timestamp when the session ends at the latest. */
|
|
76
|
+
expiresAt: string;
|
|
77
|
+
/**
|
|
78
|
+
* Where the voice agent's tools come from.
|
|
79
|
+
*
|
|
80
|
+
* - `'live'`: The published MCP profile.
|
|
81
|
+
* - `'draft'`: The current draft of the MCP profile. Served when the app's owner or an editor starts the session from the app editor preview, so voice works before the app is published.
|
|
82
|
+
*/
|
|
83
|
+
environment: "live" | "draft";
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Voice module for live voice conversations between your app's users and an AI agent.
|
|
87
|
+
*
|
|
88
|
+
* This module creates and ends live voice sessions. The voice agent can use your app's tools through one of the app's MCP profiles, acting as the current user. Audio flows directly between the browser and the voice model over [WebRTC](https://developer.mozilla.org/en-US/docs/Web/API/WebRTC_API), so your backend only creates and ends the session.
|
|
89
|
+
*
|
|
90
|
+
* A session takes three steps:
|
|
91
|
+
* - The browser creates a WebRTC SDP offer and sends it to one of your backend functions.
|
|
92
|
+
* - The backend function calls {@linkcode createSession | createSession()} with the offer and your voice settings, and returns the SDP answer to the browser.
|
|
93
|
+
* - The browser applies the answer, and the conversation starts.
|
|
94
|
+
*
|
|
95
|
+
* Keep the instructions, models, and MCP profile ID in the backend function. Only the SDP offer should come from the browser.
|
|
96
|
+
*
|
|
97
|
+
* This module is in beta and may change.
|
|
98
|
+
*
|
|
99
|
+
* ## Authentication modes
|
|
100
|
+
*
|
|
101
|
+
* This module is only available to use with a client in [service role authentication mode](/developers/references/sdk/getting-started/client#service-role) (`base44.asServiceRole.voice`), which means it can only be used in backend environments. The app's tools run as the current user of the request that created the client. Without a current user, they run as a guest, which only works in apps that allow anonymous access.
|
|
102
|
+
*/
|
|
103
|
+
export interface VoiceModule {
|
|
104
|
+
/**
|
|
105
|
+
* Creates a live voice session and returns the SDP answer for the browser.
|
|
106
|
+
*
|
|
107
|
+
* Each call creates a new session, which uses credits from the workspace that owns the app. The session ends on its own when it's idle or reaches its maximum duration. To end it sooner, such as when the current user hangs up, call {@linkcode endSession | endSession()} from a later request.
|
|
108
|
+
*
|
|
109
|
+
* @param options - The browser's SDP offer and the voice settings.
|
|
110
|
+
* @returns Promise resolving to the new voice session. Rejects with a [`Base44Error`](/developers/references/sdk/getting-started/work-with-sdk#error-handling) whose `code` is one of the values under [Throws](#throws).
|
|
111
|
+
* @throws `insufficient_credits`: The workspace is out of credits.
|
|
112
|
+
* @throws `authentication_required`: The app requires a current user, and the request had none.
|
|
113
|
+
* @throws `unsupported_voice_model`: The voice model isn't supported.
|
|
114
|
+
* @throws `unsupported_agent_model`: The agent model isn't supported.
|
|
115
|
+
* @throws `voice_settings_rejected`: The voice provider rejected the settings, for example because the instructions are too long.
|
|
116
|
+
* @throws `invalid_request`: A value in the options is invalid.
|
|
117
|
+
* @throws `rate_limited`: You created too many sessions in a short time.
|
|
118
|
+
* @throws `voice_capacity_exceeded`: Voice capacity is temporarily unavailable.
|
|
119
|
+
* @throws `voice_connection_failed`: The voice provider couldn't be reached or rejected the request.
|
|
120
|
+
*
|
|
121
|
+
* @example
|
|
122
|
+
* ```typescript
|
|
123
|
+
* // Backend function that creates a voice session for the current user
|
|
124
|
+
* import { createClientFromRequest } from 'npm:@base44/sdk';
|
|
125
|
+
*
|
|
126
|
+
* const VOICE_PROFILE_ID = '6a1f0c2b9d8e7f6a5b4c3d2e';
|
|
127
|
+
*
|
|
128
|
+
* Deno.serve(async (req) => {
|
|
129
|
+
* const base44 = createClientFromRequest(req);
|
|
130
|
+
* // Only the SDP offer comes from the browser.
|
|
131
|
+
* const { sdp } = await req.json();
|
|
132
|
+
*
|
|
133
|
+
* const session = await base44.asServiceRole.voice.createSession({
|
|
134
|
+
* sdp,
|
|
135
|
+
* mcpProfileId: VOICE_PROFILE_ID,
|
|
136
|
+
* voiceInstructions: 'You are the shop assistant. Speak briefly and let the person interrupt.',
|
|
137
|
+
* agentInstructions: 'Use the app tools to look up orders. Report only what the tools return.',
|
|
138
|
+
* });
|
|
139
|
+
*
|
|
140
|
+
* return Response.json({ sessionId: session.sessionId, sdp: session.sdp });
|
|
141
|
+
* });
|
|
142
|
+
* ```
|
|
143
|
+
*
|
|
144
|
+
* @example
|
|
145
|
+
* ```typescript
|
|
146
|
+
* // Pick the models and voice, and give the agent context about the current page
|
|
147
|
+
* const session = await base44.asServiceRole.voice.createSession({
|
|
148
|
+
* sdp,
|
|
149
|
+
* mcpProfileId: VOICE_PROFILE_ID,
|
|
150
|
+
* voiceModel: 'gpt_live_1',
|
|
151
|
+
* agentModel: 'gpt_6_luna',
|
|
152
|
+
* voiceInstructions: 'You are the shop assistant.',
|
|
153
|
+
* agentInstructions: 'Use the app tools to look up orders.',
|
|
154
|
+
* voice: 'cedar',
|
|
155
|
+
* initialMessages: [
|
|
156
|
+
* { role: 'developer', text: 'The person is viewing order 1042 on the checkout page.' },
|
|
157
|
+
* ],
|
|
158
|
+
* });
|
|
159
|
+
* ```
|
|
160
|
+
*/
|
|
161
|
+
createSession(options: VoiceSessionOptions): Promise<VoiceSession>;
|
|
162
|
+
/**
|
|
163
|
+
* Ends a voice session created by your app.
|
|
164
|
+
*
|
|
165
|
+
* Call it from a later request, such as when the browser reports that the current user hung up. Ending a session that has already ended succeeds, so it's safe to call more than once.
|
|
166
|
+
*
|
|
167
|
+
* @param sessionId - The `sessionId` returned by {@linkcode createSession | createSession()}.
|
|
168
|
+
* @returns Promise that resolves when Base44 accepts the request. The session closes in the background. Rejects with a [`Base44Error`](/developers/references/sdk/getting-started/work-with-sdk#error-handling) whose `code` is one of the values under [Throws](#throws-2).
|
|
169
|
+
* @throws `voice_session_not_found`: The session ID wasn't issued to your app.
|
|
170
|
+
* @throws `voice_connection_failed`: Base44 couldn't reach its background processing. It closes the session directly where possible, and retrying is safe.
|
|
171
|
+
*
|
|
172
|
+
* @example
|
|
173
|
+
* ```typescript
|
|
174
|
+
* // End a session from a later request, using the ID sent in the request body
|
|
175
|
+
* import { createClientFromRequest } from 'npm:@base44/sdk';
|
|
176
|
+
*
|
|
177
|
+
* Deno.serve(async (req) => {
|
|
178
|
+
* const base44 = createClientFromRequest(req);
|
|
179
|
+
* const { sessionId } = await req.json();
|
|
180
|
+
* await base44.asServiceRole.voice.endSession(sessionId);
|
|
181
|
+
*
|
|
182
|
+
* return new Response(null, { status: 204 });
|
|
183
|
+
* });
|
|
184
|
+
* ```
|
|
185
|
+
*/
|
|
186
|
+
endSession(sessionId: string): Promise<void>;
|
|
187
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reads the commit the app's frontend bundle was built from.
|
|
3
|
+
*
|
|
4
|
+
* Base44's publish pipeline sets `VITE_BASE44_BUILD_COMMIT` for the build, and
|
|
5
|
+
* Vite replaces the expression below with that literal string when it bundles
|
|
6
|
+
* this file out of `node_modules`, in `vite build` and in the dev server's
|
|
7
|
+
* prebundled deps alike. The expression must stay spelled out exactly like
|
|
8
|
+
* this: Vite matches it statically, and any indirection leaves a runtime lookup
|
|
9
|
+
* that is always undefined.
|
|
10
|
+
*
|
|
11
|
+
* A bundler that isn't Vite leaves `import.meta.env` undefined, so the lookup
|
|
12
|
+
* throws, and that means "no build commit".
|
|
13
|
+
*
|
|
14
|
+
* Only reached as `#build-commit-source` under the `module` condition; see
|
|
15
|
+
* `build-commit-source.fallback.ts`.
|
|
16
|
+
*
|
|
17
|
+
* @internal
|
|
18
|
+
*/
|
|
19
|
+
export declare function readBuildCommitSource(): unknown;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What `#build-commit-source` resolves to without the `module` condition: no
|
|
3
|
+
* build commit.
|
|
4
|
+
*
|
|
5
|
+
* The package's `imports` field gives the `import.meta` reader
|
|
6
|
+
* (`build-commit-source.ts`) only to bundlers that match `module`: Vite,
|
|
7
|
+
* webpack and esbuild. Everything else gets this file, so `import.meta` never
|
|
8
|
+
* reaches a runtime or bundler that can't take it. That includes Node, Deno,
|
|
9
|
+
* and Metro on every platform: Hermes rejects `import.meta` outright, and
|
|
10
|
+
* Metro's web build ships a classic script, where it is a SyntaxError.
|
|
11
|
+
*
|
|
12
|
+
* @internal
|
|
13
|
+
*/
|
|
14
|
+
export declare function readBuildCommitSource(): unknown;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What `#build-commit-source` resolves to without the `module` condition: no
|
|
3
|
+
* build commit.
|
|
4
|
+
*
|
|
5
|
+
* The package's `imports` field gives the `import.meta` reader
|
|
6
|
+
* (`build-commit-source.ts`) only to bundlers that match `module`: Vite,
|
|
7
|
+
* webpack and esbuild. Everything else gets this file, so `import.meta` never
|
|
8
|
+
* reaches a runtime or bundler that can't take it. That includes Node, Deno,
|
|
9
|
+
* and Metro on every platform: Hermes rejects `import.meta` outright, and
|
|
10
|
+
* Metro's web build ships a classic script, where it is a SyntaxError.
|
|
11
|
+
*
|
|
12
|
+
* @internal
|
|
13
|
+
*/
|
|
14
|
+
export function readBuildCommitSource() {
|
|
15
|
+
return undefined;
|
|
16
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reads the commit the app's frontend bundle was built from.
|
|
3
|
+
*
|
|
4
|
+
* Base44's publish pipeline sets `VITE_BASE44_BUILD_COMMIT` for the build, and
|
|
5
|
+
* Vite replaces the expression below with that literal string when it bundles
|
|
6
|
+
* this file out of `node_modules`, in `vite build` and in the dev server's
|
|
7
|
+
* prebundled deps alike. The expression must stay spelled out exactly like
|
|
8
|
+
* this: Vite matches it statically, and any indirection leaves a runtime lookup
|
|
9
|
+
* that is always undefined.
|
|
10
|
+
*
|
|
11
|
+
* A bundler that isn't Vite leaves `import.meta.env` undefined, so the lookup
|
|
12
|
+
* throws, and that means "no build commit".
|
|
13
|
+
*
|
|
14
|
+
* Only reached as `#build-commit-source` under the `module` condition; see
|
|
15
|
+
* `build-commit-source.fallback.ts`.
|
|
16
|
+
*
|
|
17
|
+
* @internal
|
|
18
|
+
*/
|
|
19
|
+
export function readBuildCommitSource() {
|
|
20
|
+
try {
|
|
21
|
+
return import.meta.env.VITE_BASE44_BUILD_COMMIT;
|
|
22
|
+
}
|
|
23
|
+
catch (_a) {
|
|
24
|
+
return undefined;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** Header the backend reads to tell which frontend build sent a request. */
|
|
2
|
+
export declare const BUILD_COMMIT_HEADER = "X-Base44-Build";
|
|
3
|
+
/**
|
|
4
|
+
* The build-commit header to send from this client, if any.
|
|
5
|
+
*
|
|
6
|
+
* Only a browser sends it: the value names the browser bundle, so a server
|
|
7
|
+
* (Node, Deno, a backend function) or React Native would report a commit that
|
|
8
|
+
* isn't the one running.
|
|
9
|
+
*
|
|
10
|
+
* @internal
|
|
11
|
+
*/
|
|
12
|
+
export declare function getBuildCommitHeaders(): Record<string, string>;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { isNode, isReactNative } from "./common.js";
|
|
2
|
+
import { readBuildCommitSource } from "#build-commit-source";
|
|
3
|
+
/** Header the backend reads to tell which frontend build sent a request. */
|
|
4
|
+
export const BUILD_COMMIT_HEADER = "X-Base44-Build";
|
|
5
|
+
// The backend accepts exactly this shape and ignores anything else, so a value
|
|
6
|
+
// that doesn't match is never sent.
|
|
7
|
+
const BUILD_COMMIT_PATTERN = /^[a-f0-9]{40}$/;
|
|
8
|
+
/**
|
|
9
|
+
* The build-commit header to send from this client, if any.
|
|
10
|
+
*
|
|
11
|
+
* Only a browser sends it: the value names the browser bundle, so a server
|
|
12
|
+
* (Node, Deno, a backend function) or React Native would report a commit that
|
|
13
|
+
* isn't the one running.
|
|
14
|
+
*
|
|
15
|
+
* @internal
|
|
16
|
+
*/
|
|
17
|
+
export function getBuildCommitHeaders() {
|
|
18
|
+
if (isNode || isReactNative)
|
|
19
|
+
return {};
|
|
20
|
+
const commit = readBuildCommitSource();
|
|
21
|
+
return typeof commit === "string" && BUILD_COMMIT_PATTERN.test(commit)
|
|
22
|
+
? { [BUILD_COMMIT_HEADER]: commit }
|
|
23
|
+
: {};
|
|
24
|
+
}
|
package/package.json
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@base44-preview/sdk",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.60-pr.375.db5e899",
|
|
4
4
|
"description": "JavaScript SDK for Base44 API",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
|
+
"imports": {
|
|
8
|
+
"#build-commit-source": {
|
|
9
|
+
"module": "./dist/utils/build-commit-source.js",
|
|
10
|
+
"default": "./dist/utils/build-commit-source.fallback.js"
|
|
11
|
+
}
|
|
12
|
+
},
|
|
7
13
|
"type": "module",
|
|
8
14
|
"files": [
|
|
9
15
|
"dist"
|
|
@@ -16,6 +22,7 @@
|
|
|
16
22
|
"test:e2e": "vitest run tests/e2e",
|
|
17
23
|
"test:watch": "vitest",
|
|
18
24
|
"test:coverage": "vitest run --coverage",
|
|
25
|
+
"test:build-commit": "scripts/verify-build-commit.sh",
|
|
19
26
|
"docs": "typedoc",
|
|
20
27
|
"prepublishOnly": "npm run build",
|
|
21
28
|
"create-docs": "npm run create-docs:generate && npm run create-docs:process",
|