@base44-preview/sdk 0.8.59-pr.372.0aefdf1 → 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.
@@ -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
  *
@@ -17,7 +17,7 @@ export interface VoiceModuleConfig {
17
17
  *
18
18
  * @param axios - Axios instance (should be service role client)
19
19
  * @param config - Module configuration
20
- * @returns Voice module with methods to start and end live voice sessions
20
+ * @returns Voice module with methods to create and end live voice sessions
21
21
  * @internal
22
22
  */
23
23
  export declare function createVoiceModule(axios: AxiosInstance, { functionsVersion }?: VoiceModuleConfig): VoiceModule;
@@ -6,7 +6,7 @@
6
6
  *
7
7
  * @param axios - Axios instance (should be service role client)
8
8
  * @param config - Module configuration
9
- * @returns Voice module with methods to start and end live voice sessions
9
+ * @returns Voice module with methods to create and end live voice sessions
10
10
  * @internal
11
11
  */
12
12
  export function createVoiceModule(axios, { functionsVersion } = {}) {
@@ -17,7 +17,7 @@ export function createVoiceModule(axios, { functionsVersion } = {}) {
17
17
  await axios.delete(`/v1/voice-sessions/${encodeURIComponent(sessionId)}`);
18
18
  };
19
19
  return {
20
- async startSession(options) {
20
+ async createSession(options) {
21
21
  // The app is derived from the service token, so the route isn't app-scoped.
22
22
  const response = await axios.post("/v1/voice-sessions", {
23
23
  sdp: options.sdp,
@@ -48,7 +48,6 @@ export function createVoiceModule(axios, { functionsVersion } = {}) {
48
48
  sdp: data.sdp,
49
49
  expiresAt: data.expires_at,
50
50
  environment: data.environment,
51
- end: () => endSession(data.session_id),
52
51
  };
53
52
  },
54
53
  endSession,
@@ -14,7 +14,7 @@ export interface VoiceSessionMessage {
14
14
  text: string;
15
15
  }
16
16
  /**
17
- * Options for {@linkcode VoiceModule.startSession | startSession()}.
17
+ * Options for {@linkcode VoiceModule.createSession | createSession()}.
18
18
  */
19
19
  export interface VoiceSessionOptions {
20
20
  /**
@@ -57,13 +57,13 @@ export interface VoiceSessionOptions {
57
57
  initialMessages?: VoiceSessionMessage[];
58
58
  }
59
59
  /**
60
- * A live voice session returned by {@linkcode VoiceModule.startSession | startSession()}.
60
+ * A live voice session returned by {@linkcode VoiceModule.createSession | createSession()}.
61
61
  */
62
62
  export interface VoiceSession {
63
63
  /**
64
64
  * Opaque session identifier issued to your app.
65
65
  *
66
- * Pass it unchanged to [`endSession()`](#endsession) to end the session from a different request.
66
+ * Pass it unchanged to [`endSession()`](#endsession) to end the session.
67
67
  */
68
68
  sessionId: string;
69
69
  /**
@@ -81,19 +81,15 @@ export interface VoiceSession {
81
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
82
  */
83
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
84
  }
89
85
  /**
90
86
  * Voice module for live voice conversations between your app's users and an AI agent.
91
87
  *
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.
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.
93
89
  *
94
90
  * A session takes three steps:
95
91
  * - 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.
92
+ * - The backend function calls {@linkcode createSession | createSession()} with the offer and your voice settings, and returns the SDP answer to the browser.
97
93
  * - The browser applies the answer, and the conversation starts.
98
94
  *
99
95
  * Keep the instructions, models, and MCP profile ID in the backend function. Only the SDP offer should come from the browser.
@@ -106,9 +102,9 @@ export interface VoiceSession {
106
102
  */
107
103
  export interface VoiceModule {
108
104
  /**
109
- * Starts a live voice session and returns the SDP answer for the browser.
105
+ * Creates a live voice session and returns the SDP answer for the browser.
110
106
  *
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()}.
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.
112
108
  *
113
109
  * @param options - The browser's SDP offer and the voice settings.
114
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).
@@ -118,13 +114,13 @@ export interface VoiceModule {
118
114
  * @throws `unsupported_agent_model`: The agent model isn't supported.
119
115
  * @throws `voice_settings_rejected`: The voice provider rejected the settings, for example because the instructions are too long.
120
116
  * @throws `invalid_request`: A value in the options is invalid.
121
- * @throws `rate_limited`: You started too many sessions in a short time.
117
+ * @throws `rate_limited`: You created too many sessions in a short time.
122
118
  * @throws `voice_capacity_exceeded`: Voice capacity is temporarily unavailable.
123
119
  * @throws `voice_connection_failed`: The voice provider couldn't be reached or rejected the request.
124
120
  *
125
121
  * @example
126
122
  * ```typescript
127
- * // Backend function that starts a voice session for the current user
123
+ * // Backend function that creates a voice session for the current user
128
124
  * import { createClientFromRequest } from 'npm:@base44/sdk';
129
125
  *
130
126
  * const VOICE_PROFILE_ID = '6a1f0c2b9d8e7f6a5b4c3d2e';
@@ -134,7 +130,7 @@ export interface VoiceModule {
134
130
  * // Only the SDP offer comes from the browser.
135
131
  * const { sdp } = await req.json();
136
132
  *
137
- * const session = await base44.asServiceRole.voice.startSession({
133
+ * const session = await base44.asServiceRole.voice.createSession({
138
134
  * sdp,
139
135
  * mcpProfileId: VOICE_PROFILE_ID,
140
136
  * voiceInstructions: 'You are the shop assistant. Speak briefly and let the person interrupt.',
@@ -148,7 +144,7 @@ export interface VoiceModule {
148
144
  * @example
149
145
  * ```typescript
150
146
  * // Pick the models and voice, and give the agent context about the current page
151
- * const session = await base44.asServiceRole.voice.startSession({
147
+ * const session = await base44.asServiceRole.voice.createSession({
152
148
  * sdp,
153
149
  * mcpProfileId: VOICE_PROFILE_ID,
154
150
  * voiceModel: 'gpt_live_1',
@@ -162,13 +158,13 @@ export interface VoiceModule {
162
158
  * });
163
159
  * ```
164
160
  */
165
- startSession(options: VoiceSessionOptions): Promise<VoiceSession>;
161
+ createSession(options: VoiceSessionOptions): Promise<VoiceSession>;
166
162
  /**
167
- * Ends a voice session started by your app.
163
+ * Ends a voice session created by your app.
168
164
  *
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.
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.
170
166
  *
171
- * @param sessionId - The `sessionId` returned by {@linkcode startSession | startSession()}.
167
+ * @param sessionId - The `sessionId` returned by {@linkcode createSession | createSession()}.
172
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).
173
169
  * @throws `voice_session_not_found`: The session ID wasn't issued to your app.
174
170
  * @throws `voice_connection_failed`: Base44 couldn't reach its background processing. It closes the session directly where possible, and retrying is safe.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@base44-preview/sdk",
3
- "version": "0.8.59-pr.372.0aefdf1",
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",