@base44-preview/sdk 0.8.59-pr.371.9b61876 → 0.8.59-pr.372.0aefdf1

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";
@@ -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 start and end live voice sessions
21
+ * @internal
22
+ */
23
+ export declare function createVoiceModule(axios: AxiosInstance, { functionsVersion }?: VoiceModuleConfig): VoiceModule;
@@ -0,0 +1,56 @@
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 start 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 startSession(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
+ end: () => endSession(data.session_id),
52
+ };
53
+ },
54
+ endSession,
55
+ };
56
+ }
@@ -0,0 +1,191 @@
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.startSession | startSession()}.
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.startSession | startSession()}.
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 from a different request.
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
+ * Ends the session. Equivalent to calling [`endSession()`](#endsession) with this session's ID.
86
+ */
87
+ end: () => Promise<void>;
88
+ }
89
+ /**
90
+ * Voice module for live voice conversations between your app's users and an AI agent.
91
+ *
92
+ * This module starts 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 handles the start and the end of a session.
93
+ *
94
+ * A session takes three steps:
95
+ * - The browser creates a WebRTC SDP offer and sends it to one of your backend functions.
96
+ * - The backend function calls {@linkcode startSession | startSession()} with the offer and your voice settings, and returns the SDP answer to the browser.
97
+ * - The browser applies the answer, and the conversation starts.
98
+ *
99
+ * Keep the instructions, models, and MCP profile ID in the backend function. Only the SDP offer should come from the browser.
100
+ *
101
+ * This module is in beta and may change.
102
+ *
103
+ * ## Authentication modes
104
+ *
105
+ * 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.
106
+ */
107
+ export interface VoiceModule {
108
+ /**
109
+ * Starts a live voice session and returns the SDP answer for the browser.
110
+ *
111
+ * Each call starts 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. When the current user hangs up, call `end()` on the session. To end it from a different request, use {@linkcode endSession | endSession()}.
112
+ *
113
+ * @param options - The browser's SDP offer and the voice settings.
114
+ * @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).
115
+ * @throws `insufficient_credits`: The workspace is out of credits.
116
+ * @throws `authentication_required`: The app requires a current user, and the request had none.
117
+ * @throws `unsupported_voice_model`: The voice model isn't supported.
118
+ * @throws `unsupported_agent_model`: The agent model isn't supported.
119
+ * @throws `voice_settings_rejected`: The voice provider rejected the settings, for example because the instructions are too long.
120
+ * @throws `invalid_request`: A value in the options is invalid.
121
+ * @throws `rate_limited`: You started too many sessions in a short time.
122
+ * @throws `voice_capacity_exceeded`: Voice capacity is temporarily unavailable.
123
+ * @throws `voice_connection_failed`: The voice provider couldn't be reached or rejected the request.
124
+ *
125
+ * @example
126
+ * ```typescript
127
+ * // Backend function that starts a voice session for the current user
128
+ * import { createClientFromRequest } from 'npm:@base44/sdk';
129
+ *
130
+ * const VOICE_PROFILE_ID = '6a1f0c2b9d8e7f6a5b4c3d2e';
131
+ *
132
+ * Deno.serve(async (req) => {
133
+ * const base44 = createClientFromRequest(req);
134
+ * // Only the SDP offer comes from the browser.
135
+ * const { sdp } = await req.json();
136
+ *
137
+ * const session = await base44.asServiceRole.voice.startSession({
138
+ * sdp,
139
+ * mcpProfileId: VOICE_PROFILE_ID,
140
+ * voiceInstructions: 'You are the shop assistant. Speak briefly and let the person interrupt.',
141
+ * agentInstructions: 'Use the app tools to look up orders. Report only what the tools return.',
142
+ * });
143
+ *
144
+ * return Response.json({ sessionId: session.sessionId, sdp: session.sdp });
145
+ * });
146
+ * ```
147
+ *
148
+ * @example
149
+ * ```typescript
150
+ * // Pick the models and voice, and give the agent context about the current page
151
+ * const session = await base44.asServiceRole.voice.startSession({
152
+ * sdp,
153
+ * mcpProfileId: VOICE_PROFILE_ID,
154
+ * voiceModel: 'gpt_live_1',
155
+ * agentModel: 'gpt_6_luna',
156
+ * voiceInstructions: 'You are the shop assistant.',
157
+ * agentInstructions: 'Use the app tools to look up orders.',
158
+ * voice: 'cedar',
159
+ * initialMessages: [
160
+ * { role: 'developer', text: 'The person is viewing order 1042 on the checkout page.' },
161
+ * ],
162
+ * });
163
+ * ```
164
+ */
165
+ startSession(options: VoiceSessionOptions): Promise<VoiceSession>;
166
+ /**
167
+ * Ends a voice session started by your app.
168
+ *
169
+ * Use this when the session was started in a different request, such as when the browser reports that the current user hung up. Otherwise call `end()` on the session returned by {@linkcode startSession | startSession()}. Ending a session that has already ended succeeds, so it's safe to call more than once.
170
+ *
171
+ * @param sessionId - The `sessionId` returned by {@linkcode startSession | startSession()}.
172
+ * @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).
173
+ * @throws `voice_session_not_found`: The session ID wasn't issued to your app.
174
+ * @throws `voice_connection_failed`: Base44 couldn't reach its background processing. It closes the session directly where possible, and retrying is safe.
175
+ *
176
+ * @example
177
+ * ```typescript
178
+ * // End a session from a later request, using the ID sent in the request body
179
+ * import { createClientFromRequest } from 'npm:@base44/sdk';
180
+ *
181
+ * Deno.serve(async (req) => {
182
+ * const base44 = createClientFromRequest(req);
183
+ * const { sessionId } = await req.json();
184
+ * await base44.asServiceRole.voice.endSession(sessionId);
185
+ *
186
+ * return new Response(null, { status: 204 });
187
+ * });
188
+ * ```
189
+ */
190
+ endSession(sessionId: string): Promise<void>;
191
+ }
@@ -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.9b61876",
3
+ "version": "0.8.59-pr.372.0aefdf1",
4
4
  "description": "JavaScript SDK for Base44 API",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",