@deepdesk/deepdesk-sdk 17.3.1-beta.1 → 18.0.1-beta.0

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/index.d.mts CHANGED
@@ -2059,7 +2059,7 @@ interface KnowledgeAssistantWidgetOptions extends KnowledgeAssistOptions {
2059
2059
  declare class DeepdeskSDK {
2060
2060
  static version: string;
2061
2061
  static count: number;
2062
- private deepdeskApi;
2062
+ deepdeskApi: DeepdeskAPI;
2063
2063
  inputMediator: InputMediator<any> | null;
2064
2064
  private version;
2065
2065
  private broadcastEvents;
@@ -2077,6 +2077,37 @@ declare class DeepdeskSDK {
2077
2077
  private shouldRender;
2078
2078
  private ws;
2079
2079
  store: Store;
2080
+ /**
2081
+ * Creates a new DeepdeskSDK instance for managing a single conversation.
2082
+ *
2083
+ * Each SDK instance should be created for one conversation. The SDK handles
2084
+ * authentication, rendering suggestions, and rendering a widget.
2085
+ *
2086
+ * @param options - Optional configuration options for the SDK
2087
+ * @param options.deepdeskUrl - Base API URL for the Deepdesk backend (e.g., https://acme.deepdesk.com)
2088
+ * @param options.version - Release version for analytics tracking (defaults to SDK version)
2089
+ * @param options.locale - Language locale for UI labels (not for suggestions) (defaults to 'en-US')
2090
+ * @param options.token - Optional JWT token for Authorization header (alternative to SSO)
2091
+ * @param options.fetch - Custom fetch implementation (defaults to window.fetch)
2092
+ * @param options.productName - Product name for whitelabelling purposes
2093
+ * @param options.createCustomChannel - Custom channel creation function for broadcast events
2094
+ * @param options.websocketClient - Custom WebSocket client implementation
2095
+ *
2096
+ * @example
2097
+ * ```typescript
2098
+ * const sdk = new DeepdeskSDK({
2099
+ * deepdeskUrl: 'https://acme.deepdesk.com',
2100
+ * locale: 'en-US',
2101
+ * productName: 'My Platform'
2102
+ * });
2103
+ *
2104
+ * // With JWT token authentication
2105
+ * const sdk = new DeepdeskSDK({
2106
+ * deepdeskUrl: 'https://acme.deepdesk.com',
2107
+ * token: 'your-jwt-token-here'
2108
+ * });
2109
+ * ```
2110
+ */
2080
2111
  constructor({ deepdeskUrl, version, locale, token, fetch, productName, createCustomChannel, websocketClient, }: SDKOptions);
2081
2112
  get state(): {
2082
2113
  assistants: State$2;
@@ -2172,7 +2203,45 @@ declare class DeepdeskSDK {
2172
2203
  hasKeyboardInput: boolean;
2173
2204
  };
2174
2205
  get selectedTextSuggestion(): TextSuggestion;
2206
+ /**
2207
+ * Checks if a conversation is currently loaded in this SDK instance.
2208
+ *
2209
+ * This method returns true if a conversation has been successfully loaded
2210
+ * via methods like `getConversationByExternalId()`, `createConversation()`,
2211
+ * or `upsertConversation()`.
2212
+ *
2213
+ * @returns true if a conversation exists and is loaded, false otherwise
2214
+ *
2215
+ * @example
2216
+ * ```typescript
2217
+ * if (sdk.hasConversation()) {
2218
+ * console.log('Conversation loaded:', sdk.conversationId());
2219
+ * } else {
2220
+ * console.log('No conversation loaded yet');
2221
+ * }
2222
+ * ```
2223
+ */
2175
2224
  hasConversation(): boolean;
2225
+ /**
2226
+ * Gets the current conversation ID.
2227
+ *
2228
+ * Returns the unique identifier for the currently loaded conversation.
2229
+ * This ID is used internally by Deepdesk for tracking and analytics.
2230
+ *
2231
+ * @returns The conversation ID as a string
2232
+ *
2233
+ * @example
2234
+ * ```typescript
2235
+ * try {
2236
+ * const id = sdk.conversationId();
2237
+ * console.log('Current conversation ID:', id);
2238
+ * } catch (error) {
2239
+ * console.log('No conversation loaded yet');
2240
+ * }
2241
+ * ```
2242
+ *
2243
+ * @throws {Error} If no conversation is currently loaded
2244
+ */
2176
2245
  conversationId(): string;
2177
2246
  private externalId;
2178
2247
  private shouldAbort;
@@ -2182,88 +2251,569 @@ declare class DeepdeskSDK {
2182
2251
  */
2183
2252
  private whenLoggedIn;
2184
2253
  /**
2185
- * This method checks if the user has a valid access token cookie or valid refresh token.
2254
+ * Checks if the user is logged in and returns a promise that resolves when logged in.
2255
+ *
2256
+ * **Important Notes:**
2257
+ * - If using this method, make sure to call `mount()` and/or `renderWidget()`
2258
+ * before waiting on the login promise to resolve.
2259
+ * - The login promise only resolves after successful authentication and never throws.
2186
2260
  *
2187
- * @returns Return a promise that resolves when the user is logged in.
2261
+ * @returns Promise that resolves when the user is logged in
2262
+ *
2263
+ * @example
2264
+ * ```typescript
2265
+ * // Mount first, then login
2266
+ * sdk.mount(inputElement);
2267
+ *
2268
+ * sdk.login().then(() => {
2269
+ * console.log('User is logged in');
2270
+ * // Now safe to load conversation
2271
+ * return sdk.getConversationByExternalId('conversation-123');
2272
+ * }).catch(() => {
2273
+ * console.log('Login failed or was cancelled');
2274
+ * sdk.unmount();
2275
+ * });
2276
+ * ```
2188
2277
  */
2189
2278
  login(): Promise<void>;
2279
+ /**
2280
+ * Checks if the user is currently logged in.
2281
+ *
2282
+ * This method performs an API call to verify the current authentication status.
2283
+ * It checks for valid access tokens and refresh tokens.
2284
+ *
2285
+ * @returns Promise that resolves to true if user is logged in, false otherwise
2286
+ *
2287
+ * @example
2288
+ * ```typescript
2289
+ * const isLoggedIn = await sdk.isLoggedIn();
2290
+ * if (isLoggedIn) {
2291
+ * console.log('User is authenticated');
2292
+ * // Proceed with conversation operations
2293
+ * } else {
2294
+ * console.log('User needs to login');
2295
+ * await sdk.login();
2296
+ * }
2297
+ * ```
2298
+ */
2190
2299
  isLoggedIn(): Promise<boolean>;
2191
2300
  /**
2192
- * Check if conversation is supported by Deepdesk
2193
- * @param externalId - A string with the conversation external ID.
2194
- * A external ID is local to the customer service platform, and identifies a
2195
- * conversation that takes place within a certain time frame.
2301
+ * Checks if a conversation is supported by Deepdesk.
2302
+ *
2303
+ * This method verifies whether a conversation with the given external ID
2304
+ * is supported by the Deepdesk platform. This check does not require
2305
+ * the user to be logged in.
2306
+ *
2307
+ * @param externalId - The conversation external ID to check
2308
+ * @param options - Optional retry parameters for the check
2309
+ * @param options.attempts - Number of attempts if conversation is not created yet via webhook (default: 1)
2310
+ * @param options.retryDelay - Delay between attempts in milliseconds (default: 1000)
2311
+ * @returns Promise that resolves to true if conversation is supported, false otherwise
2312
+ *
2313
+ * @example
2314
+ * ```typescript
2315
+ * const isSupported = await sdk.isConversationSupported('conversation-123');
2316
+ * if (isSupported) {
2317
+ * console.log('Conversation is supported by Deepdesk');
2318
+ * // Proceed with loading the conversation
2319
+ * } else {
2320
+ * console.log('Conversation is not supported');
2321
+ * }
2322
+ *
2323
+ * // With polling options for webhook delays
2324
+ * const isSupported = await sdk.isConversationSupported('conversation-123', {
2325
+ * attempts: 5,
2326
+ * retryDelay: 500
2327
+ * });
2328
+ * ```
2196
2329
  */
2197
2330
  isConversationSupported(externalId: string, options?: Parameters<typeof DeepdeskAPI.prototype.isConversationSupported>[1]): Promise<boolean>;
2198
2331
  /**
2199
- * Create a conversation
2200
- * This should only be used when backend ingestion (via webhooks) is not possible.
2201
- * @param data - The create conversation options
2332
+ * Creates a new conversation in Deepdesk.
2333
+ *
2334
+ * **Important:** This method should only be used when backend ingestion (via webhooks)
2335
+ * is not possible. The preferred approach is to implement Deepdesk backend webhooks
2336
+ * for notifying Deepdesk of new messages, which automatically creates conversations
2337
+ * in the backend, and then use `getConversationByExternalId()` in the frontend.
2338
+ *
2339
+ * If a conversation with a different external ID is already loaded, this method
2340
+ * will reset the current conversation before creating the new one.
2341
+ *
2342
+ * @param data - Conversation creation data
2343
+ * @param data.externalId - The platform's conversation/thread/case ID
2344
+ * @param data.platform - The messaging platform (e.g., 'liveengage', 'zendesk')
2345
+ * @param data.agentId - The platform's agent ID
2346
+ * @param data.agentName - The platform's agent name (optional)
2347
+ * @param data.agentNickname - The platform's agent nickname (optional)
2348
+ * @param data.agentEmail - The platform's agent email (optional)
2349
+ * @param data.profileCode - Optional client profile code (e.g., 'b2b', 'b2c')
2350
+ * @param data.metadata - Optional conversation metadata for matching the right profile.
2351
+ * @returns Promise that resolves to the created conversation
2352
+ *
2353
+ * @example
2354
+ * ```typescript
2355
+ * const conversation = await sdk.createConversation({
2356
+ * externalId: 'conversation-123',
2357
+ * platform: 'zendesk',
2358
+ * agentId: 'agent-456',
2359
+ * agentName: 'John Doe',
2360
+ * agentEmail: 'john@company.com',
2361
+ * metadata: {
2362
+ * team: 'support',
2363
+ * channel: 'web-chat'
2364
+ * }
2365
+ * });
2366
+ *
2367
+ * console.log('Created conversation:', conversation.id);
2368
+ * ```
2202
2369
  */
2203
2370
  createConversation(data: CreateConversation): Promise<Conversation>;
2204
2371
  /**
2205
- * Get a conversation by session ID
2206
- * @param externalId - A string with the conversation session ID.
2207
- * A session ID is local to the customer service platform, and identifies a
2208
- * conversation that takes place within a certain time frame.
2372
+ * Retrieves a conversation by its external ID.
2373
+ *
2374
+ * This method fetches a conversation that was created by the Deepdesk backend
2375
+ * via webhooks. It's the preferred method for loading conversations when
2376
+ * backend integration is implemented.
2377
+ *
2378
+ * If a conversation with a different external ID is already loaded, this method
2379
+ * will reset the current conversation before loading the new one.
2380
+ *
2381
+ * @param externalId - The conversation external ID to retrieve
2382
+ * @param options - Optional retry parameters for webhook delays
2383
+ * @param options.attempts - Number of attempts if conversation is not created yet via webhook (default: 1)
2384
+ * @param options.retryDelay - Delay between attempts in milliseconds (default: 1000)
2385
+ * @returns Promise that resolves to the conversation
2386
+ *
2387
+ * @example
2388
+ * ```typescript
2389
+ * try {
2390
+ * const conversation = await sdk.getConversationByExternalId('conversation-123');
2391
+ * console.log('Loaded conversation:', conversation.id);
2392
+ * } catch (error) {
2393
+ * console.log('Conversation not found or not supported');
2394
+ * }
2395
+ *
2396
+ * // With retry options for webhook delays
2397
+ * const conversation = await sdk.getConversationByExternalId('conversation-123', {
2398
+ * attempts: 5,
2399
+ * retryDelay: 500
2400
+ * });
2401
+ * ```
2209
2402
  */
2210
2403
  getConversationByExternalId(externalId: string, options?: Parameters<typeof DeepdeskAPI.prototype.getConversationByExternalId>[1]): Promise<Conversation>;
2211
2404
  /**
2212
- * Upsert a conversation: Get and update conversation or create it if it does not exist yet.
2405
+ * Creates or updates a conversation based on unique externalId/agentId/platform signature.
2406
+ *
2407
+ * **Important:** Only use this method when there is no backend integration possible.
2408
+ * The preferred route is to implement Deepdesk backend webhooks for notifying Deepdesk
2409
+ * of new messages (thus creating the conversation in the backend) and using
2410
+ * `getConversationByExternalId()` in the frontend to get the correct conversation.
2411
+ *
2412
+ * This method will create a new conversation if one doesn't exist, or update
2413
+ * an existing conversation if it does. If a conversation with a different external ID
2414
+ * is already loaded, this method will reset the current conversation first.
2415
+ *
2416
+ * @param data - Conversation data for creation or update
2417
+ * @param data.externalId - The platform's conversation/thread/case ID
2418
+ * @param data.platform - The messaging platform (e.g., 'liveengage', 'zendesk')
2419
+ * @param data.agentId - The platform's agent ID
2420
+ * @param data.agentName - The platform's agent name (optional)
2421
+ * @param data.agentNickname - The platform's agent nickname (optional)
2422
+ * @param data.agentEmail - The platform's agent email (optional)
2423
+ * @param data.profileCode - Optional client profile code (e.g., 'b2b', 'b2c')
2424
+ * @param data.metadata - Optional conversation metadata for distinguishing conversation types
2425
+ * @returns Promise that resolves to the conversation (created or updated)
2426
+ *
2427
+ * @example
2428
+ * ```typescript
2429
+ * const conversation = await sdk.upsertConversation({
2430
+ * externalId: 'conversation-123',
2431
+ * platform: 'zendesk',
2432
+ * agentId: 'agent-456',
2433
+ * agentName: 'John Doe',
2434
+ * agentEmail: 'john@company.com',
2435
+ * metadata: {
2436
+ * team: 'support',
2437
+ * channel: 'web-chat'
2438
+ * }
2439
+ * });
2440
+ *
2441
+ * console.log('Conversation upserted:', conversation.id);
2442
+ * ```
2213
2443
  */
2214
2444
  upsertConversation(data: CreateConversation): Promise<Conversation>;
2215
2445
  /**
2216
- * Method to call when the conversation is updated, either by an incoming message
2217
- * from the visitor, or a message sent by the agent.
2446
+ * Posts messages to the current conversation.
2447
+ *
2448
+ * **Important:** Only use this method when there is no backend integration possible.
2449
+ * The preferred route is to implement Deepdesk backend webhooks for notifying Deepdesk
2450
+ * of new messages, which automatically handles message ingestion.
2451
+ *
2452
+ * This method allows you to manually post visitor, agent, or bot messages to Deepdesk.
2453
+ * Messages are deduplicated based on their external ID, so if a message with the same
2454
+ * ID already exists, the new message will be ignored.
2455
+ *
2456
+ * @param messages - Array of conversation messages to post
2457
+ * @param messages[].externalId - The message ID (used for deduplication)
2458
+ * @param messages[].source - The type of entity who wrote the message ('agent', 'visitor', 'bot', 'system')
2459
+ * @param messages[].text - The message text content
2460
+ * @param messages[].time - The message timestamp (ISO 8601 format, e.g., '2023-07-25T11:43:55.308+00:00')
2461
+ * @param messages[].authorId - The platform's native author ID
2462
+ * @param messages[].authorName - The message author name (optional)
2463
+ * @param messages[].authorEmail - The message author email (optional)
2464
+ * @param messages[].metadata - Optional message metadata for distinguishing message types
2465
+ * @returns Promise that resolves when messages are posted
2466
+ *
2467
+ * @example
2468
+ * ```typescript
2469
+ * await sdk.postMessages([
2470
+ * {
2471
+ * externalId: 'msg-123',
2472
+ * source: 'visitor',
2473
+ * text: 'Hello, I need help with my order',
2474
+ * time: '2023-07-25T11:43:55.308+00:00',
2475
+ * authorId: 'visitor-456',
2476
+ * authorName: 'John Smith',
2477
+ * authorEmail: 'john@example.com',
2478
+ * metadata: {
2479
+ * channel: 'web-chat',
2480
+ * priority: 'normal'
2481
+ * }
2482
+ * },
2483
+ * {
2484
+ * externalId: 'msg-124',
2485
+ * source: 'agent',
2486
+ * text: 'Hi John, I\'d be happy to help you with your order',
2487
+ * time: '2023-07-25T11:44:00.000+00:00',
2488
+ * authorId: 'agent-789',
2489
+ * authorName: 'Support Agent',
2490
+ * metadata: {
2491
+ * team: 'customer-service'
2492
+ * }
2493
+ * }
2494
+ * ]);
2495
+ * ```
2218
2496
  */
2219
2497
  postMessages(messages: ConversationMessage[]): Promise<void>;
2220
2498
  /**
2221
- * Update converstation meta data
2499
+ * Updates conversation metadata.
2500
+ *
2501
+ * This method allows you to update various properties of the current conversation,
2502
+ * such as metadata, status, or other conversation-specific information.
2503
+ *
2504
+ * @param conversation - Partial conversation data to update
2505
+ * @param conversation.metadata - Optional metadata to update
2506
+ * @param conversation.status - Optional conversation status to update
2507
+ * @param conversation.externalId - Optional external ID to update
2508
+ * @param conversation.platform - Optional platform to update
2509
+ * @param conversation.agentId - Optional agent ID to update
2510
+ * @param conversation.agentName - Optional agent name to update
2511
+ * @param conversation.agentEmail - Optional agent email to update
2512
+ * @returns Promise that resolves to the updated conversation
2513
+ *
2514
+ * @example
2515
+ * ```typescript
2516
+ * const updatedConversation = await sdk.updateConversation({
2517
+ * metadata: {
2518
+ * priority: 'high',
2519
+ * category: 'technical-support',
2520
+ * assignedTeam: 'level-2'
2521
+ * }
2522
+ * });
2523
+ *
2524
+ * console.log('Updated conversation:', updatedConversation.id);
2525
+ * ```
2222
2526
  */
2223
2527
  updateConversation(conversation: Partial<Conversation>): Promise<Conversation>;
2224
2528
  /**
2225
- * Reset conversation
2529
+ * Resets the current conversation state.
2530
+ *
2531
+ * This method clears the currently loaded conversation and resets all
2532
+ * conversation-related state, including profile configuration and conversation
2533
+ * query functions. This is useful when switching between conversations or
2534
+ * when you need to start fresh.
2535
+ *
2536
+ * After calling this method, you'll need to load a new conversation using
2537
+ * methods like `getConversationByExternalId()`, `createConversation()`, or
2538
+ * `upsertConversation()`.
2539
+ *
2540
+ * **Note:** It's safer to use a different DeepdeskSDK instance for each conversation.
2541
+ *
2542
+ * @example
2543
+ * ```typescript
2544
+ * // Reset current conversation
2545
+ * sdk.resetConversation();
2546
+ *
2547
+ * // Load a different conversation
2548
+ * await sdk.getConversationByExternalId('new-conversation-123');
2549
+ *
2550
+ * // Or create a new conversation
2551
+ * await sdk.createConversation({
2552
+ * externalId: 'new-conversation-456',
2553
+ * platform: 'zendesk',
2554
+ * agentId: 'agent-789'
2555
+ * });
2556
+ * ```
2226
2557
  */
2227
2558
  resetConversation(): void;
2228
2559
  /**
2229
- * Change settings value
2560
+ * Updates SDK configuration settings.
2561
+ *
2562
+ * This method allows you to dynamically update various SDK settings at runtime.
2563
+ * Settings include locale, visibility, suggestion preferences, and other
2564
+ * configuration options.
2565
+ *
2566
+ * @param settings - Optional settings object to update SDK configuration.
2567
+ * @param settings.locale: Language locale for UI labels (default: 'en-US')
2568
+ * @param settings.deanonymize: Whether to deanonymize messages (default: false)
2569
+ * @param settings.fallbackImage: Whether to use a fallback image (default: false)
2570
+ * @param settings.showImages: Show images in suggestions (default: false)
2571
+ * @param settings.showSearch: Show search UI (default: false)
2572
+ * @param settings.showImageSearch: Show image search UI (default: false)
2573
+ * @param settings.showStyleSuggestions: Show style suggestions (default: false)
2574
+ * @param settings.showMidSentenceSuggestions: Show mid-sentence suggestions (default: false)
2575
+ * @param settings.showSuggestionsBeforePattern: Pattern for showing suggestions before (default: false)
2576
+ * @param settings.showSuggestionsAfterPattern: Pattern for showing suggestions after (default: false)
2577
+ * @param settings.showTabCompletion: Enable tab completion (default: true)
2578
+ * @param settings.showTextSuggestions: Show text suggestions (default: true)
2579
+ * @param settings.showEntitiesCommand: Show entities command (default: false)
2580
+ * @param settings.showSummaryCommand: Show summary command (default: false)
2581
+ * @param settings.showKnowledgeSearch: Show knowledge search (default: false)
2582
+ * @param settings.textSuggestionsCount: Number of text suggestions to show (default: 3)
2583
+ * @param settings.recommendTextSuggestions: Recommend text suggestions (default: true)
2584
+ * @param settings.searchTriggerKey: Key to trigger search (default: 'k')
2585
+ * @param settings.insertLink: Enable insert link (default: false)
2586
+ * @param settings.automaticHandlingTime: Enable automatic handling time (default: false)
2587
+ * @param settings.enableSuggestionFeedback: Enable suggestion feedback (default: false)
2588
+ * @param settings.enableFeedbackForm: Enable feedback form (default: true)
2589
+ * @param settings.adminUrl: Admin URL (default: deepdeskUrl provided by DeepdeskSDK constructor)
2590
+ * @param settings.productName: Product name (default: 'Deepdesk')
2591
+ * @param settings.hasKeyboardInput: Whether keyboard input is enabled (default: true)
2592
+ *
2593
+ * @example
2594
+ * ```typescript
2595
+ * // Update locale
2596
+ * sdk.configure({ locale: 'nl-NL' });
2597
+ * ```
2230
2598
  */
2231
2599
  configure(settings: Parameters<typeof set>[0]): void;
2232
2600
  /**
2233
- * Store the visitor information in memory
2601
+ * Sets visitor information for placeholder interpolation in suggestions.
2602
+ *
2603
+ * This method allows you to provide visitor information that can be used
2604
+ * in suggestion templates. The information is used for placeholder replacement
2605
+ * in suggestion text, making suggestions more personalized and contextual.
2606
+ *
2607
+ * @param visitorInfo - Visitor data to store
2608
+ * @param visitorInfo.visitorId - Optional Platform's visitor ID
2609
+ * @param visitorInfo.visitorName - Optional Visitor name (first name is often preferred for suggestions)
2610
+ * @param visitorInfo.visitorTimeZone - Optional Visitor time zone
2611
+ *
2612
+ * @example
2613
+ * ```typescript
2614
+ * sdk.setVisitorInfo({
2615
+ * visitorId: 'visitor-123',
2616
+ * visitorName: 'John Smith',
2617
+ * visitorTimeZone: 'Europe/Amsterdam'
2618
+ * });
2619
+ *
2620
+ * // This enables placeholders in suggestions like:
2621
+ * // "Hello {visitor_name}, I can help you with your order"
2622
+ * ```
2234
2623
  */
2235
2624
  setVisitorInfo(visitorInfo: VisitorInfo): void;
2236
2625
  /**
2237
- * Set custom data to show in the widget
2626
+ * Sets custom data to display in the widget.
2627
+ *
2628
+ * This method allows you to provide custom data that will be displayed
2629
+ * in the Deepdesk widget. This can include any information you want
2630
+ * to show to agents, such as customer details, order information,
2631
+ * or other contextual data.
2632
+ *
2633
+ * **Important:** The actual UI configuration of the widget is done in the Deepdesk Studio.
2634
+ *
2635
+ * @param data - Custom data object to injest for display in the widget
2636
+ *
2637
+ * @example
2638
+ * ```typescript
2639
+ * sdk.setCustomData({
2640
+ * customer_id: 'CUST-12345',
2641
+ * order_number: 'ORD-67890',
2642
+ * });
2643
+ * ```
2238
2644
  */
2239
2645
  setCustomData(data: CustomData): void;
2240
2646
  /**
2241
- * Store the agent information in memory and on the server.
2242
- * Pass `skipPatch` as option to skip saving on the server.
2647
+ * Sets agent information for placeholder interpolation in suggestions.
2648
+ *
2649
+ * This method allows you to provide agent information that can be used
2650
+ * in suggestion templates. The information is used for placeholder replacement
2651
+ * in suggestion text, making suggestions more personalized for the agent.
2652
+ *
2653
+ * @param agentInfo - Agent data to store
2654
+ * @param agentInfo.agentId - Platform's agent ID
2655
+ * @param agentInfo.agentNickname - Agent's nickname or first name (preferred for suggestions)
2656
+ * @param agentInfo.agentName - Optional Agent's first name or full name
2657
+ * @param agentInfo.agentEmail - Optional Agent's email address
2658
+ * @param options - Optional configuration
2659
+ * @param options.skipSync - Whether to skip syncing with the backend (default: false)
2660
+ *
2661
+ * @example
2662
+ * ```typescript
2663
+ * sdk.setAgentInfo({
2664
+ * agentId: 'agent-123',
2665
+ * agentNickname: 'John',
2666
+ * agentName: 'John Doe',
2667
+ * agentEmail: 'john.doe@company.com'
2668
+ * });
2669
+ *
2670
+ * // This enables placeholders in suggestions like:
2671
+ * // "Hi {agent_name}, here's a suggestion for your response"
2672
+ * ```
2673
+ *
2674
+ * **Available Placeholders:**
2675
+ * - agentNickname or agentName → `{agent_name}`
2243
2676
  */
2244
2677
  setAgentInfo(agentInfo: AgentInfo, options?: {
2245
2678
  skipSync?: boolean;
2246
2679
  }): Promise<void>;
2247
2680
  /**
2248
- * Store the agent settings
2681
+ * Updates agent settings.
2682
+ *
2683
+ * This method allows you to update various agent-specific settings for your
2684
+ * custom integration that are stored in the Deepdesk backend. These settings
2685
+ * can be retrieved later using `getAgentSettings()`.
2686
+ *
2687
+ * @param patch - Settings to update (partial object)
2688
+ * @returns Promise that resolves when settings are updated
2689
+ *
2690
+ * @example
2691
+ * ```typescript
2692
+ * // Update agent preferences
2693
+ * await sdk.setAgentSettings({
2694
+ * theme: 'dark'
2695
+ * });
2696
+ * ```
2249
2697
  */
2250
2698
  setAgentSettings<T = unknown>(patch: Partial<T>): Promise<void>;
2251
2699
  /**
2252
- * Get the agent settings
2700
+ * Retrieves agent settings.
2701
+ *
2702
+ * This method fetches the current agent settings from the Deepdesk backend.
2703
+ * These settings can be updated using `setAgentSettings()`.
2704
+ *
2705
+ * @returns Promise that resolves to agent settings
2706
+ *
2707
+ * @example
2708
+ * ```typescript
2709
+ * // Get all agent settings
2710
+ * const settings = await sdk.getAgentSettings();
2711
+ * console.log('Agent settings:', settings);
2712
+ *
2713
+ * // Get settings with specific type
2714
+ * interface AgentPreferences {
2715
+ * theme: 'light' | 'dark';
2716
+ * }
2717
+ *
2718
+ * const preferences = await sdk.getAgentSettings<AgentPreferences>();
2719
+ * console.log('Preferred language:', preferences.theme);
2720
+ * ```
2253
2721
  */
2254
2722
  getAgentSettings<T = unknown>(): Promise<T>;
2255
2723
  /**
2256
- * Refresh suggestions based on the current conversation.
2257
- * Only refresh text suggestions when the agent is not typing.
2724
+ * Refreshes suggestions based on the current conversation.
2725
+ *
2726
+ * This method triggers a refresh of both text suggestions and widget suggestions
2727
+ * based on the current conversation context. Use this when the agent or visitor
2728
+ * has submitted a message and the Deepdesk webhook has been notified.
2729
+ *
2730
+ * **Important:** Be careful not to refresh suggestions when the agent is already
2731
+ * typing, as this could interfere with the user experience.
2732
+ *
2733
+ * @returns Promise that resolves when refresh is complete
2734
+ *
2735
+ * @example
2736
+ * ```typescript
2737
+ * // Refresh after a new message is received
2738
+ * // ---handle sending a message in the integration---
2739
+ * await sdk.refresh();
2740
+ * console.log('Suggestions refreshed');
2741
+ * ```
2258
2742
  */
2259
2743
  refresh(): Promise<void>;
2260
2744
  private syncInputMediator;
2745
+ /**
2746
+ * Adds an external suggestion to the current input.
2747
+ *
2748
+ * This method allows you to programmatically commit a suggestion to the
2749
+ * current input field. This is useful when you want to add suggestions
2750
+ * from external sources or custom logic.
2751
+ *
2752
+ * @param suggestion - Suggestion to commit
2753
+ * @param suggestion.text - The text to insert
2754
+ * @param suggestion.suggestion - The suggestion object
2755
+ * @param suggestion.eventMetrics - Metrics for tracking the suggestion usage
2756
+ * @param suggestion.replace - Range to replace ('selection' or 'until-selection-end')
2757
+ *
2758
+ * @example
2759
+ * ```typescript
2760
+ * // Add a custom suggestion from external system
2761
+ * sdk.notifyExternalSuggestion({
2762
+ * text: 'Thank you for contacting us!',
2763
+ * suggestion: {
2764
+ * id: 'custom-1',
2765
+ * text: 'Thank you for contacting us!',
2766
+ * type: 'template'
2767
+ * },
2768
+ * eventMetrics: {
2769
+ * inputType: 'mouse'
2770
+ * },
2771
+ * replace: 'until-selection-end'
2772
+ * });
2773
+ * ```
2774
+ */
2261
2775
  notifyExternalSuggestion(suggestion: StageSuggestion): void;
2262
2776
  /**
2263
- * Evaluate assistant
2264
- * By default will expect cues and show them in the widget.
2265
- * Disable cues in widget by providing `showCuesInWidget: false`-option.
2266
- * `expectFormat` could be 'text', 'json-object', 'json-schema:cues' or 'json-schema:knowledge-assist'
2777
+ * Evaluates an assistant with the given code.
2778
+ *
2779
+ * This is a low-level method that allows you to evaluate an assistant.
2780
+ * You are probably better off using `evaluateConversationAssistant()` for conversation lifecycle events.
2781
+ *
2782
+ * @param assistantCode - The assistant code to evaluate
2783
+ * @param options - Evaluation options
2784
+ * @param options.expectFormat - Expected response format ('json-schema:cues', 'json-schema:knowledge-assist', 'text', 'json-object')
2785
+ * @param options.input - Additional input data for the assistant
2786
+ * @param options.transcript - Transcript option ('in-memory-transcript' or custom transcript)
2787
+ * @param options.includeMetadata - Whether to include metadata in the response
2788
+ * @param options.showCuesInWidget - Whether to show cues in the widget (default: true)
2789
+ * @returns Promise that resolves to evaluation output or string
2790
+ *
2791
+ * @example
2792
+ * ```typescript
2793
+ * // Evaluate assistant with cues format
2794
+ * const result = await sdk.evaluateAssistant('assistant-code-123', {
2795
+ * expectFormat: 'json-schema:cues',
2796
+ * input: {
2797
+ * customerType: 'premium',
2798
+ * issueType: 'technical'
2799
+ * }
2800
+ * });
2801
+ *
2802
+ * // Evaluate with custom transcript
2803
+ * const result = await sdk.evaluateAssistant('assistant-code-456', {
2804
+ * expectFormat: 'text',
2805
+ * transcript: [
2806
+ * { source: 'visitor', text: 'I have a problem with my order' },
2807
+ * { source: 'agent', text: 'I can help you with that' }
2808
+ * ]
2809
+ * });
2810
+ *
2811
+ * // Evaluate with in-memory transcript (requires setConversationQuery)
2812
+ * const result = await sdk.evaluateAssistant('assistant-code-789', {
2813
+ * transcript: 'in-memory-transcript',
2814
+ * includeMetadata: true
2815
+ * });
2816
+ * ```
2267
2817
  */
2268
2818
  evaluateAssistant<T extends Server.ResponseFormat = 'json-schema:cues'>(assistantCode: string, options?: {
2269
2819
  expectFormat?: T;
@@ -2273,9 +2823,44 @@ declare class DeepdeskSDK {
2273
2823
  showCuesInWidget?: boolean;
2274
2824
  }): Promise<EvaluationOutput<T> | string>;
2275
2825
  /**
2276
- * Evaluate conversation lifecycle assistant
2277
- * Convenient wrapper around `evaluateAssistant`.
2278
- * By default includes the server transcript and 'metadata'.
2826
+ * Evaluates conversation lifecycle assistants.
2827
+ *
2828
+ * This is a convenient wrapper around `evaluateAssistant()` that evaluates
2829
+ * assistants based on conversation lifecycle events. It automatically loads
2830
+ * the profile configuration and evaluates the appropriate assistants for
2831
+ * the given event.
2832
+ *
2833
+ * @param event - The conversation event type 'accepted' | 'new-message' | 'ended'
2834
+ * @param options - Evaluation options
2835
+ * @param options.input - Additional input data for the assistant. Will be used as 'params' in the prompt.
2836
+ * @param options.transcript - Transcript option ('in-memory-transcript' or custom transcript)
2837
+ * @param options.includeMetadata - Whether to include metadata in the response
2838
+ * @param options.showCuesInWidget - Whether to show cues in the widget (default: true)
2839
+ * @returns Promise that resolves when evaluation is complete
2840
+ *
2841
+ * @example
2842
+ * ```typescript
2843
+ * // Evaluate when conversation is accepted
2844
+ * await sdk.evaluateConversationAssistant('accepted', {
2845
+ * input: {
2846
+ * agentName: 'John Doe',
2847
+ * priority: 'high'
2848
+ * }
2849
+ * });
2850
+ *
2851
+ * // Evaluate when new message is received
2852
+ * await sdk.evaluateConversationAssistant('new-message', {
2853
+ * includeMetadata: true,
2854
+ * });
2855
+ *
2856
+ * // Evaluate when conversation ends
2857
+ * await sdk.evaluateConversationAssistant('ended', {
2858
+ * input: {
2859
+ * resolution: 'solved',
2860
+ * satisfaction: 'positive'
2861
+ * }
2862
+ * });
2863
+ * ```
2279
2864
  */
2280
2865
  evaluateConversationAssistant(event: 'accepted' | 'new-message' | 'ended', options?: {
2281
2866
  input?: Record<string, any>;
@@ -2284,44 +2869,287 @@ declare class DeepdeskSDK {
2284
2869
  showCuesInWidget?: boolean;
2285
2870
  }): Promise<void>;
2286
2871
  /**
2287
- * Get summary from conversation
2872
+ * @deprecated Specific 'Summarizer' assistants are deprecated.
2873
+ *
2874
+ * Generates a summary of the current conversation.
2875
+ *
2876
+ * This method uses the summarizer assistant configured in the profile to
2877
+ * generate a concise summary of the current conversation. It assumes that
2878
+ * `setConversationQuery()` has been called before this method and will
2879
+ * throw an error if this is not the case.
2880
+ *
2881
+ * @param args - Summary generation options
2882
+ * @param args.includeMetadata - Whether to include metadata in the summary
2883
+ * @param args.transcript - Custom transcript to use (optional)
2884
+ * @returns Promise that resolves to the summary text or null if no summarizer is configured
2885
+ *
2886
+ * @example
2887
+ * ```typescript
2888
+ * // Set up conversation query first
2889
+ * sdk.setConversationQuery(async () => {
2890
+ * return [
2891
+ * { source: 'visitor', text: 'I have a problem with my order' },
2892
+ * { source: 'agent', text: 'I can help you with that' },
2893
+ * { source: 'visitor', text: 'My order number is 12345' }
2894
+ * ];
2895
+ * });
2896
+ *
2897
+ * // Generate summary
2898
+ * const summary = await sdk.getSummary();
2899
+ * console.log('Conversation summary:', summary);
2900
+ *
2901
+ * // Generate summary with metadata
2902
+ * const summaryWithMetadata = await sdk.getSummary({
2903
+ * includeMetadata: true
2904
+ * });
2905
+ *
2906
+ * // Generate summary with custom transcript
2907
+ * const customSummary = await sdk.getSummary({
2908
+ * transcript: [
2909
+ * { source: 'visitor', text: 'Custom conversation data' },
2910
+ * { source: 'agent', text: 'Agent response' }
2911
+ * ]
2912
+ * });
2913
+ * ```
2914
+ *
2915
+ * @throws {Error} If `setConversationQuery()` has not been called
2288
2916
  */
2289
2917
  getSummary(args?: SummaryInput): Promise<string | null>;
2290
2918
  private handleKeyDown;
2291
2919
  private handleAfterSendMessage;
2920
+ /**
2921
+ * Starts or continues timing the interaction between agent and customer.
2922
+ *
2923
+ * This method is used to track the average handling time (AHT) for conversations.
2924
+ * It starts timing when called and continues timing if already started.
2925
+ * The timing is used for analytics and performance metrics.
2926
+ *
2927
+ * **Note:** For automatic handling time tracking, consider using the
2928
+ * `automaticHandlingTime` setting instead of manually calling this method.
2929
+ *
2930
+ * @example
2931
+ * ```typescript
2932
+ * sdk.handlingTimeStart();
2933
+ * ```
2934
+ */
2292
2935
  handlingTimeStart(): void;
2936
+ /**
2937
+ * Stops or pauses timing the interaction between agent and customer.
2938
+ *
2939
+ * This method stops the current handling time tracking and sends an
2940
+ * intermediate analytics event to Deepdesk with the accumulated timing data.
2941
+ *
2942
+ * **Note:** For automatic handling time tracking, consider using the
2943
+ * `automaticHandlingTime` setting instead of manually calling this method.
2944
+ *
2945
+ * @example
2946
+ * ```typescript
2947
+ * sdk.handlingTimeStop();
2948
+ * ```
2949
+ */
2293
2950
  handlingTimeStop(): void;
2294
2951
  private logSendMessage;
2295
2952
  private logHandlingTime;
2296
2953
  /**
2297
- * Method to call when the agent has sent a message to the visitor
2298
- * Optionally pass the sent text
2954
+ * Notifies the SDK that a message has been submitted.
2955
+ *
2956
+ * This method should be called when the agent has sent a message to the visitor.
2957
+ * It sends an analytics event to Deepdesk containing the sent text and other metrics.
2958
+ *
2959
+ * **Important:** Call `notifySubmit` after the message is successfully sent by the platform,
2960
+ * but before the agent input element is emptied. This ensures the correct text is captured
2961
+ * for analytics.
2962
+ *
2963
+ * @param options - Submit options
2964
+ * @param options.text - Optional text to use if the input field is already reset
2965
+ *
2966
+ * @example
2967
+ * ```typescript
2968
+ * // Call after message is sent but before input is cleared
2969
+ * function sendMessage() {
2970
+ * const messageText = inputElement.value;
2971
+ *
2972
+ * // Integration sends message
2973
+ * platformAPI.sendMessage(messageText).then(() => {
2974
+ * // Notify SDK before clearing input
2975
+ * sdk.notifySubmit();
2976
+ *
2977
+ * // Now clear the input
2978
+ * inputElement.value = '';
2979
+ * });
2980
+ * }
2981
+ *
2982
+ * // If input is already cleared, pass the text manually
2983
+ * function sendMessageWithClearedInput() {
2984
+ * const messageText = inputElement.value;
2985
+ *
2986
+ * // Integration sends message and clears input
2987
+ * platformAPI.sendMessage(messageText);
2988
+ * inputElement.value = '';
2989
+ *
2990
+ * // Pass text manually since input is already cleared
2991
+ * sdk.notifySubmit({ text: messageText });
2992
+ * }
2993
+ * ```
2299
2994
  */
2300
2995
  notifySubmit(options?: {
2301
2996
  text?: string;
2302
2997
  }): void;
2998
+ /**
2999
+ * Emits an event to registered listeners
3000
+ * @param type - Event type
3001
+ * @param eventPayload - Event data
3002
+ */
2303
3003
  emit<K extends keyof SDKEventMap>(type: K, eventPayload: SDKEventMap[K]): void;
2304
3004
  /**
2305
- * Attach listener to SDK event
2306
- * Returns removeListener
3005
+ * Registers an event listener for SDK events.
3006
+ *
3007
+ * This method allows you to listen to various events that occur when the agent
3008
+ * interacts with suggestions, messages are sent, or other SDK activities happen.
3009
+ *
3010
+ * The function returns a callback which allows you to remove the listener.
3011
+ * An alternative to remove a listener is to use the `off()` method.
3012
+ *
3013
+ * @param type - Event type to listen for
3014
+ * @param handler - Event handler function that receives the event payload
3015
+ * @returns Function to remove the listener
3016
+ *
3017
+ * @example
3018
+ * ```typescript
3019
+ * // Listen for suggestion selection
3020
+ * const removeListener = sdk.on('select-suggestion', (event) => {
3021
+ * console.log('Suggestion selected:', event.text);
3022
+ * console.log('Suggestion type:', event.type);
3023
+ * });
3024
+ *
3025
+ * // Listen for message sending
3026
+ * sdk.on('send-message', (message) => {
3027
+ * console.log('Message sent:', message);
3028
+ * });
3029
+ *
3030
+ * // Listen for conversation events
3031
+ * sdk.on('event', (event) => {
3032
+ * console.log('Event:', event.name, event.data);
3033
+ * });
3034
+ *
3035
+ * // Remove listener using returned function
3036
+ * removeListener();
3037
+ *
3038
+ * // Or remove using off method
3039
+ * sdk.off('select-suggestion', handler);
3040
+ * ```
2307
3041
  */
2308
3042
  on<K extends keyof SDKEventMap>(type: K, handler: SDKHandler<K>): () => void;
2309
3043
  /**
2310
- * Remove listener from SDK
2311
- * Similar to HTMLElement.removeListener
3044
+ * Removes event listeners from the SDK.
3045
+ *
3046
+ * This method allows you to remove specific event listeners or all listeners
3047
+ * for a particular event type. If no parameters are provided, all listeners
3048
+ * are removed.
3049
+ *
3050
+ * @param type - Event type to remove listeners for (optional, removes all if not specified)
3051
+ * @param handler - Specific handler function to remove (optional)
3052
+ *
3053
+ * @example
3054
+ * ```typescript
3055
+ * // Remove specific listener
3056
+ * sdk.off('select-suggestion', myHandler);
3057
+ *
3058
+ * // Remove all listeners for a specific event type
3059
+ * sdk.off('select-suggestion');
3060
+ *
3061
+ * // Remove all listeners (cleanup)
3062
+ * sdk.off();
3063
+ * ```
2312
3064
  */
2313
- off<K extends keyof SDKEventMap>(type: K, handler: SDKHandler<K>): void;
2314
- off(): void;
3065
+ off<K extends keyof SDKEventMap>(type?: K, handler?: SDKHandler<K>): void;
2315
3066
  /**
2316
- * Set the fetch function to retrieve conversation data to be used for NER endpoints
2317
- * This way the NER service can remain a separate system and ensure anonomity
2318
- * @param fetchFn function that returns the conversation data as a string
3067
+ * Sets a function to fetch a transcript for features that require an unanonymized transcript.
3068
+ *
3069
+ * This method allows you to provide a function that returns conversation data for features
3070
+ * like extracting entities from the transcript or generating summaries. The transcript
3071
+ * is used once and then discarded for privacy reasons.
3072
+ *
3073
+ * The conversation returned must be an array of objects, each containing a `text` and a `source`.
3074
+ * The `source` should be either 'agent' or 'visitor'.
3075
+ *
3076
+ * @param fetchFn - Function that returns conversation data
3077
+ * @param fetchFn.source - The source of the message ('agent' or 'visitor')
3078
+ * @param fetchFn.text - The text content of the message
3079
+ *
3080
+ * @example
3081
+ * ```typescript
3082
+ * // Set up conversation query function
3083
+ * sdk.setConversationQuery(async () => {
3084
+ * // Fetch conversation from your platform
3085
+ * const messages = await somePlatformSDK.getConversationMessages(conversationId);
3086
+ *
3087
+ * return messages.map(msg => ({
3088
+ * source: msg.author === 'agent' ? 'agent' : 'visitor',
3089
+ * text: msg.content
3090
+ * }));
3091
+ * });
3092
+ *
3093
+ * // Now you can use features that require setConversationQuery to be set
3094
+ * const summary = await sdk.getSummary();
3095
+ * ```
2319
3096
  */
2320
3097
  setConversationQuery(fetchFn: () => Promise<Array<{
2321
3098
  source: string;
2322
3099
  text: string;
2323
3100
  }>>): void;
3101
+ /**
3102
+ * Sets platform-specific variables for placeholder interpolation.
3103
+ *
3104
+ * This method allows you to provide platform-specific variables that can be used
3105
+ * in suggestion templates. These variables are used for placeholder replacement
3106
+ * in suggestion text, making suggestions more contextual to your platform.
3107
+ *
3108
+ * @param mapping - Variable mapping object
3109
+ * @param mapping[key] - The value for the variable placeholder
3110
+ *
3111
+ * @example
3112
+ * ```typescript
3113
+ * // Set platform variables
3114
+ * sdk.setPlatformVariables({
3115
+ * 'platform_name': 'Zendesk',
3116
+ * 'company_name': 'Acme Corp',
3117
+ * 'support_email': 'support@acme.com',
3118
+ * 'business_hours': '9 AM - 5 PM EST'
3119
+ * });
3120
+ *
3121
+ * // This enables placeholders in suggestions like:
3122
+ * // "Thank you for contacting {company_name} support"
3123
+ * // "Our {platform_name} team is available {business_hours}"
3124
+ *
3125
+ * // Update variables dynamically
3126
+ * sdk.setPlatformVariables({
3127
+ * 'current_agent': 'John Doe',
3128
+ * 'queue_length': '5'
3129
+ * });
3130
+ * ```
3131
+ */
2324
3132
  setPlatformVariables(mapping: VariableMapping): void;
3133
+ /**
3134
+ * Registers a callback to be called when conversation is loaded.
3135
+ *
3136
+ * This method allows you to register a callback function that will be executed
3137
+ * when a conversation is successfully loaded. The callback is called after
3138
+ * the profile configuration has been loaded.
3139
+ *
3140
+ * If a conversation is already loaded when this method is called, the callback
3141
+ * will be executed immediately.
3142
+ *
3143
+ * @param callback - Function to call when conversation loads
3144
+ *
3145
+ * @example
3146
+ * ```typescript
3147
+ * // Register callback for when conversation loads
3148
+ * sdk.whenConversationLoaded(() => {
3149
+ * console.log('Conversation loaded, profile configured');
3150
+ * });
3151
+ * ```
3152
+ */
2325
3153
  whenConversationLoaded(callback: () => void): void;
2326
3154
  private overlayContainerFactory;
2327
3155
  private createInlineContainer;
@@ -2329,12 +3157,99 @@ declare class DeepdeskSDK {
2329
3157
  private storeMetrics;
2330
3158
  private restoreMetrics;
2331
3159
  /**
2332
- * Renders the tab completion and suggestions overlay and 2-way binds events
2333
- * @param inputElement - the agent input element to enhance
2334
- * @param options - optional mount options
3160
+ * Mounts the tab completion and suggestions overlay to an input element.
3161
+ *
3162
+ * This method enhances a textarea or contentEditable div with Deepdesk's
3163
+ * suggestion functionality, including text suggestions, tab completion,
3164
+ * and floating menus. It sets up all necessary event listeners and renders
3165
+ * the UI components.
3166
+ *
3167
+ * **Important:** This method can only be called once per SDK instance.
3168
+ * If you need to remount, call `unmount()` first.
3169
+ *
3170
+ * @param inputElement - The input element to enhance (textarea or contentEditable div)
3171
+ * @param options - Mount configuration options
3172
+ * @param options.customStyles - Custom styling for overlays and components
3173
+ * @param options.closestScrollSelector - CSS selector for closest scrollable parent
3174
+ * @param options.floatingMenuParent - Parent element for floating menu
3175
+ * @param options.appendOverlayTo - Element to append overlays to (default: inputElement.parentElement)
3176
+ * @param options.inputMediator - Custom input mediator implementation
3177
+ * @param options.xxx - All other options are passed to the configure method
3178
+ *
3179
+ * @example
3180
+ * ```typescript
3181
+ * // Basic mounting on a textarea
3182
+ * const textarea = document.querySelector('textarea');
3183
+ * sdk.mount(textarea);
3184
+ *
3185
+ * // Mount on contentEditable div
3186
+ * const contentEditable = document.querySelector('[contenteditable="true"]');
3187
+ * sdk.mount(contentEditable, {
3188
+ * customStyles: {
3189
+ * rootNode: 'my-custom-root-class'
3190
+ * },
3191
+ * appendOverlayTo: document.body
3192
+ * });
3193
+ *
3194
+ * // Mount with custom input mediator
3195
+ * class CustomInputMediator extends InputMediator<HTMLElement> {
3196
+ * // Custom implementation
3197
+ * }
3198
+ *
3199
+ * sdk.mount(textarea, {
3200
+ * inputMediator: new CustomInputMediator(textarea)
3201
+ * });
3202
+ * ```
3203
+ *
3204
+ * @throws {Error} If the SDK instance is already mounted
3205
+ * @throws {Error} If the input element is not a supported type (textarea or contentEditable div)
2335
3206
  */
2336
3207
  mount(inputElement: HTMLElement, options?: MountOptions): void;
3208
+ /**
3209
+ * Subscribes to internal state changes.
3210
+ *
3211
+ * This method allows you to subscribe to changes in the SDK's internal state.
3212
+ * It uses a selector function to extract specific parts of the state and calls
3213
+ * the callback function whenever that part of the state changes.
3214
+ *
3215
+ * The subscription only triggers when the selected value actually changes
3216
+ * (reference equality check), preventing unnecessary callbacks.
3217
+ *
3218
+ * @param selector - Function to select a specific part of the state
3219
+ * @param callback - Function called when the selected state changes
3220
+ * @returns Function to unsubscribe from the state changes
3221
+ *
3222
+ * @example
3223
+ * ```typescript
3224
+ * // Subscribe to input text changes
3225
+ * const unsubscribe = sdk.subscribe(
3226
+ * (state) => state.input.text,
3227
+ * (text) => {
3228
+ * console.log('Input text changed:', text);
3229
+ * }
3230
+ * );
3231
+ *
3232
+ * // Unsubscribe when done
3233
+ * unsubscribe();
3234
+ * ```
3235
+ */
2337
3236
  subscribe<T>(selector: (state: RootState) => T, callback: (value: T) => void): Unsubscribe;
3237
+ /**
3238
+ * Unmounts the SDK and cleans up all resources.
3239
+ *
3240
+ * This method removes all UI components, event listeners, and cleans up
3241
+ * internal resources. It should be called when you're done using the SDK
3242
+ * or when you need to remount it on a different element.
3243
+ *
3244
+ * After calling this method, the SDK instance can be reused by calling
3245
+ * `mount()` again on a new input element.
3246
+ *
3247
+ * @example
3248
+ * ```typescript
3249
+ * // Unmount when switching conversations
3250
+ * sdk.unmount();
3251
+ * ```
3252
+ */
2338
3253
  unmount(): void;
2339
3254
  private renderSuggestions;
2340
3255
  private renderInlineSuggestions;
@@ -2342,12 +3257,121 @@ declare class DeepdeskSDK {
2342
3257
  private renderFloatingMenu;
2343
3258
  private renderOverlays;
2344
3259
  /**
2345
- * Injects the Deepdesk Widget element into the provided DOM element.
2346
- * @param containerElement - the element to inject the deepdesk element in
2347
- * @param options - optional widget options
3260
+ * Renders the Deepdesk widget in a container element.
3261
+ *
3262
+ * This method renders the main Deepdesk widget that contains suggestions,
3263
+ * pinned messages, and other content. The widget will expand to fit the
3264
+ * full height and width of the container element.
3265
+ *
3266
+ * **Important:** Make sure to set the container element to a fixed or minimum size
3267
+ * (height and width) as the widget will grow to fill the container.
3268
+ *
3269
+ * **Note:** Only one widget can be rendered per SDK instance.
3270
+ *
3271
+ * @param containerElement - Element to render widget in
3272
+ * @param options - Optional options for widget configuration
3273
+ * @param options.customStyles - Custom styling for the widget
3274
+ * @param options.showImages - Whether to show images in suggestions (default: false)
3275
+ * @param options.isEmbedded - Whether the widget is embedded in another application
3276
+ * @param options.knowledgeAssist - Knowledge assistant configuration
3277
+ * @param options.assistantOptions - Assistant evaluation options
3278
+ *
3279
+ * @example
3280
+ * ```typescript
3281
+ * // Basic widget rendering
3282
+ * const container = document.getElementById('widget-container');
3283
+ * container.style.width = '400px';
3284
+ * container.style.height = '600px';
3285
+ *
3286
+ * sdk.renderWidget(container);
3287
+ *
3288
+ * // Widget with custom options
3289
+ * sdk.renderWidget(container, {
3290
+ * showImages: true,
3291
+ * isEmbedded: true,
3292
+ * customStyles: {
3293
+ * // Custom CSS classes
3294
+ * }
3295
+ * });
3296
+ *
3297
+ * // Widget with knowledge assistant options
3298
+ * sdk.renderWidget(container, {
3299
+ * knowledgeAssist: {
3300
+ * initialQuestion: 'How can I help you today?',
3301
+ * emptyState: {
3302
+ * title: 'No knowledge base available',
3303
+ * description: 'Please contact support for assistance.'
3304
+ * }
3305
+ * }
3306
+ * });
3307
+ * ```
2348
3308
  */
2349
3309
  renderWidget(containerElement: HTMLElement, options?: WidgetOptions): void;
3310
+ /**
3311
+ * Unmounts the widget and cleans up resources.
3312
+ *
3313
+ * This method removes the rendered widget from the DOM and cleans up
3314
+ * all associated resources. It should be called when you're done using
3315
+ * the widget.
3316
+ *
3317
+ * @example
3318
+ * ```typescript
3319
+ * // Unmount widget when switching views
3320
+ * function switchToDifferentView() {
3321
+ * sdk.unmountWidget();
3322
+ * // Render different content in the container
3323
+ * }
3324
+ * ```
3325
+ */
2350
3326
  unmountWidget(): void;
3327
+ /**
3328
+ * Renders a knowledge assistant widget.
3329
+ *
3330
+ * This method renders a specialized widget for knowledge assistant functionality,
3331
+ * which allows users to ask questions and get responses about a knowledge base.
3332
+ * The widget includes a feed for displaying responses and an input field for
3333
+ * asking questions.
3334
+ *
3335
+ * Unlike the main widget, this creates a standalone knowledge assistant that
3336
+ * can be used independently of a conversation.
3337
+ *
3338
+ * @param assistantCode - The assistant code to use for knowledge assistance
3339
+ * @param containerElement - Element to render the knowledge assistant widget in
3340
+ * @param options - Optional widget configuration options
3341
+ * @param options.customStyles - Custom styling for the widget
3342
+ * @param options.initialQuestion - Initial question to display
3343
+ * @param options.emptyState - Custom empty state configuration
3344
+ * @param options.isLegacyKnowledgeAssist - Whether to use legacy knowledge assistant (default: false)
3345
+ * @param options.title - Custom title for the widget
3346
+ * @returns Object with unmount function to clean up the widget
3347
+ *
3348
+ * @example
3349
+ * ```typescript
3350
+ * // Basic knowledge assistant widget
3351
+ * const container = document.getElementById('knowledge-container');
3352
+ * const widget = sdk.renderKnowledgeAssistantWidget(
3353
+ * 'knowledge-assistant-123',
3354
+ * container
3355
+ * );
3356
+ *
3357
+ * // Knowledge assistant with custom options
3358
+ * const widget = sdk.renderKnowledgeAssistantWidget(
3359
+ * 'knowledge-assistant-456',
3360
+ * container,
3361
+ * {
3362
+ * initialQuestion: 'How can I help you today?',
3363
+ * title: 'Support Knowledge Base',
3364
+ * emptyState: {
3365
+ * title: 'No knowledge available',
3366
+ * description: 'Please contact support for assistance.'
3367
+ * },
3368
+ * customStyles: {
3369
+ * // Custom styling
3370
+ * }
3371
+ * }
3372
+ * );
3373
+ * ```
3374
+ */
2351
3375
  renderKnowledgeAssistantWidget(assistantCode: string, containerElement: HTMLElement, options?: KnowledgeAssistantWidgetOptions): {
2352
3376
  unmount(): void;
2353
3377
  };
@@ -2355,11 +3379,71 @@ declare class DeepdeskSDK {
2355
3379
  private handleError;
2356
3380
  private loadProfileConfigPromise;
2357
3381
  private loadProfileConfig;
3382
+ /**
3383
+ * Authenticates user via popup window.
3384
+ *
3385
+ * This method opens a popup window that goes through a configured SSO (Single Sign-On)
3386
+ * flow. The popup window will handle the authentication process and automatically
3387
+ * close itself when the user is successfully logged in.
3388
+ *
3389
+ * This is typically used when you want to provide a more seamless authentication experience without
3390
+ * redirecting the entire page.
3391
+ *
3392
+ * **Note:** The platform url must be correctly configured in the account settings.
3393
+ *
3394
+ * @param options - Optional authentication options
3395
+ * @param options.url - Custom URL for the SSO flow (optional, uses default if not provided)
3396
+ * @returns Promise that resolves when authentication is complete
3397
+ *
3398
+ * @example
3399
+ * ```typescript
3400
+ * // Basic popup login
3401
+ * try {
3402
+ * await sdk.loginViaPopup();
3403
+ * console.log('User logged in successfully');
3404
+ * } catch (error) {
3405
+ * console.log('Login failed or was cancelled:', error.message);
3406
+ * }
3407
+ * ```
3408
+ *
3409
+ * @throws {Error} 'Popup blocked by browser' if popup is blocked by browser
3410
+ * @throws {Error} 'Popup closed by user' if popup is closed by user
3411
+ * @throws {Error} 'Timeout' If authentication fails or times out
3412
+ */
2358
3413
  loginViaPopup(options?: {
2359
3414
  url?: string;
2360
3415
  }): Promise<void>;
3416
+ /**
3417
+ * Translates messages
3418
+ *
3419
+ * This method allows you to translate text messages using Deepdesk's
3420
+ * translation service. It's useful for translating messages between
3421
+ * different languages in multi-language support scenarios.
3422
+ *
3423
+ * @param params - Translation request parameters
3424
+ * @param params.targetLanguage - The target language code (e.g., 'en', 'es', 'fr')
3425
+ * @param params.messages - A list of strings to translate. Each string will be translated to the target language.
3426
+ * @returns Promise that resolves to translation response.
3427
+ * Each response will have the original (detected) language and the target language.
3428
+ * And the translated text.
3429
+ *
3430
+ * @example
3431
+ * ```typescript
3432
+ * // Translate a message from English to Spanish
3433
+ * const translations = await sdk.translateMessages({
3434
+ * messages: ['Hello, how can I help you?', 'I have a problem with my order'],
3435
+ * targetLanguage: 'es'
3436
+ * });
3437
+ *
3438
+ * console.log('Translation:', translations[0]);
3439
+ * // {
3440
+ * // translation: 'Hola, ¿cómo puedo ayudarte?'
3441
+ * // originalLanguage: 'en',
3442
+ * // targetLanguage: 'es',
3443
+ * // }
3444
+ * ```
3445
+ */
2361
3446
  translateMessages(params: TranslationRequest): Promise<TranslationResponse>;
2362
- checkForTrialMode(agentId: string): Promise<void>;
2363
3447
  private refreshTextSuggestions;
2364
3448
  private refreshWidgetSuggestions;
2365
3449
  }