@base44-preview/sdk 0.8.59-pr.371.e518662 → 0.8.59-pr.372.142c509

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 CHANGED
@@ -4,6 +4,7 @@ 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";
@@ -230,6 +231,7 @@ export function createClient(config) {
230
231
  integrations: createIntegrationsModule(serviceRoleAxiosClient, appId),
231
232
  sso: createSsoModule(serviceRoleAxiosClient, appId),
232
233
  browser: createBrowserModule(serviceRoleAxiosClient),
234
+ voice: createVoiceModule(serviceRoleAxiosClient, { functionsVersion }),
233
235
  connectors: createConnectorsModule(serviceRoleAxiosClient, appId),
234
236
  functions: createFunctionsModule(serviceRoleFunctionsAxiosClient, appId, {
235
237
  getAuthHeaders: () => {
@@ -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
@@ -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";
@@ -361,7 +361,7 @@ export interface PayPalCheckoutOnClick {
361
361
  /** Whether the checkout is a one-time payment or a subscription. */
362
362
  intent: "capture" | "subscription";
363
363
  /**
364
- * Creates the checkout when the buyer clicks, usually by calling the backend function that calls {@linkcode ServiceRolePaymentsModule.createCheckout | createCheckout()}. Resolve with its result. Reject to stop, for example when a required form field is empty: PayPal's window closes and `onError` receives the error.
364
+ * Creates the checkout when the buyer clicks, usually by calling the backend function that calls [`createCheckout()`](#createcheckout). Resolve with its result. It must be an embedded PayPal checkout with the same `currency` and `intent` you set here, or `onError` receives an error. Reject to stop, for example when a required form field is empty. PayPal's window then closes and `onError` receives the error.
365
365
  */
366
366
  createCheckout: () => Promise<MountableCheckout>;
367
367
  }
@@ -371,7 +371,7 @@ export interface PayPalCheckoutOnClick {
371
371
  export interface CheckoutMount {
372
372
  /** Removes the checkout from the page. Call it when the component that holds it unmounts. For Stripe, mounting another checkout destroys this one for you. */
373
373
  destroy: () => void;
374
- /** PayPal: greys out the button and ignores clicks, for example until a required form is filled in. After a payment completes the button stays off, so `setDisabled(false)` can't start a second payment. Stripe ignores it. */
374
+ /** Grays out PayPal's button and ignores clicks, for example until a required form is filled in. After a payment completes the button stays off, so `setDisabled(false)` can't start a second payment. Stripe ignores it. */
375
375
  setDisabled: (disabled: boolean) => void;
376
376
  }
377
377
  /**
@@ -425,7 +425,7 @@ export interface PaymentsModule {
425
425
  /**
426
426
  * Renders an embedded checkout inside an element on the page.
427
427
  *
428
- * Pass the result of a {@linkcode ServiceRolePaymentsModule.createCheckout | createCheckout()} call made with `presentation: 'embedded'`. Because only the service role can create checkouts, create it in a backend function and return the result to the page.
428
+ * Pass the result of a {@linkcode ServiceRolePaymentsModule.createCheckout | createCheckout()} call made with `presentation: 'embedded'`. Because only the service role can create checkouts, create it in a backend function and return the result to the page. For PayPal, you can instead pass a {@linkcode PayPalCheckoutOnClick} to show the button before any checkout exists. The SDK creates the checkout only when the buyer clicks the button, so visitors who don't buy don't leave unused checkouts behind.
429
429
  *
430
430
  * The SDK loads the provider's library and renders the checkout for you:
431
431
  * - PayPal: Renders a PayPal button. When the buyer approves the payment, the SDK calls {@linkcode completeCheckout | completeCheckout()} and then `onComplete`.
@@ -433,8 +433,6 @@ export interface PaymentsModule {
433
433
  *
434
434
  * To make the checkout appear faster, load the library ahead of time with [`preloadCheckout()`](#preloadcheckout) when the page opens.
435
435
  *
436
- * For PayPal, pass a {@linkcode PayPalCheckoutOnClick} instead of a created checkout to show PayPal's button right away and create the checkout only when the buyer clicks it. The buyer clicks once, and page views create no orders.
437
- *
438
436
  * Requires a browser environment and can't be used in the backend. Rejects when the checkout isn't embedded, when an on-click PayPal checkout is mounted before the app's PayPal can take payments, when the payments config can't be fetched or has no valid script URL for the provider, when the provider's library fails to load, or when PayPal isn't available for the checkout's currency.
439
437
  *
440
438
  * The checkout's callbacks run in the buyer's browser, where they can be faked. Grant access to what the buyer paid for only after your backend confirms the purchase, for example with [`listPurchases()`](#service-role-methods) in a backend function.
@@ -465,7 +463,7 @@ export interface PaymentsModule {
465
463
  *
466
464
  * @example
467
465
  * ```typescript
468
- * // PayPal: show the button on page load and create the checkout on click
466
+ * // Create a PayPal checkout on click
469
467
  * const mount = await base44.payments.mountCheckout(
470
468
  * document.getElementById('paypal')!,
471
469
  * {
@@ -478,7 +476,7 @@ export interface PaymentsModule {
478
476
  * { onComplete: ({ checkout_id }) => confirmPurchase(checkout_id) }
479
477
  * );
480
478
  *
481
- * // Grey out the button until the shipping form is valid
479
+ * // Gray out the button until the shipping form is valid
482
480
  * mount.setDisabled(!formIsValid);
483
481
  * ```
484
482
  *
@@ -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,4 @@
1
+ // This file deliberately states no backend limits, value lists, durations, or
2
+ // prices. Base44 validates every value, so changing a backend rule must never
3
+ // need an SDK release. Those details belong in the live voice guide.
4
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@base44-preview/sdk",
3
- "version": "0.8.59-pr.371.e518662",
3
+ "version": "0.8.59-pr.372.142c509",
4
4
  "description": "JavaScript SDK for Base44 API",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",