@omnikit-ai/sdk 2.2.1 → 2.2.3

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
@@ -10,7 +10,7 @@ export { cleanTokenFromUrl, getAccessToken, isTokenInUrl, removeAccessToken, sav
10
10
  * SECURITY: getAccessToken requires service token authentication.
11
11
  * Only available to backend functions, not frontend code.
12
12
  */
13
- type ConnectorType = 'slack' | 'google_calendar' | 'gmail' | 'notion' | 'salesforce';
13
+ type ConnectorType = 'slack' | 'google_calendar' | 'gmail' | 'google_sheets' | 'notion' | 'salesforce';
14
14
  interface ConnectorAccessTokenResponse {
15
15
  success: boolean;
16
16
  access_token: string;
@@ -178,7 +178,30 @@ interface AppSchema {
178
178
  platform_version?: number;
179
179
  }
180
180
  /**
181
- * MongoDB-style list options (Mongoose-compatible)
181
+ * Paginated response for cursor-based pagination (Google/Notion style)
182
+ * Returned by list() and filter() methods
183
+ *
184
+ * @example
185
+ * ```typescript
186
+ * // First page
187
+ * const page1 = await Task.list({}, { limit: 100 });
188
+ * // page1 = { data: [...], hasMore: true, nextCursor: "abc123" }
189
+ *
190
+ * // Next page
191
+ * const page2 = await Task.list({}, { limit: 100, after: page1.nextCursor });
192
+ * // page2 = { data: [...], hasMore: false, nextCursor: null }
193
+ * ```
194
+ */
195
+ interface PaginatedResult<T = CollectionRecord> {
196
+ /** Array of records for this page */
197
+ data: T[];
198
+ /** Whether there are more records after this page */
199
+ hasMore: boolean;
200
+ /** Cursor to pass to 'after' parameter for next page (null if no more pages) */
201
+ nextCursor: string | null;
202
+ }
203
+ /**
204
+ * MongoDB-style list options with cursor-based pagination
182
205
  * Used in the second parameter of list(filter, options)
183
206
  *
184
207
  * @example
@@ -189,17 +212,29 @@ interface AppSchema {
189
212
  * // Sort descending by timestamp
190
213
  * await Entity.list({}, { sort: { timestamp: -1 } })
191
214
  *
192
- * // With pagination
215
+ * // Cursor-based pagination (RECOMMENDED for large datasets)
216
+ * const page1 = await Entity.list({}, { limit: 100 });
217
+ * const page2 = await Entity.list({}, { limit: 100, after: page1.nextCursor });
218
+ *
219
+ * // Legacy offset pagination (still supported)
193
220
  * await Entity.list({}, { sort: { created_at: -1 }, limit: 20, offset: 10 })
194
221
  * ```
195
222
  */
196
223
  interface ListOptions {
197
224
  /** Sort order: { field: 1 } for ascending, { field: -1 } for descending. Also accepts string format: 'field' or '-field' */
198
225
  sort?: Record<string, 1 | -1> | string;
199
- /** Maximum number of results to return */
226
+ /** Maximum number of results to return (default: 100) */
200
227
  limit?: number;
201
- /** Number of results to skip (for pagination) */
228
+ /**
229
+ * Number of results to skip (for offset-based pagination)
230
+ * @deprecated Use 'after' cursor for better performance on large datasets
231
+ */
202
232
  offset?: number;
233
+ /**
234
+ * Cursor for pagination - pass nextCursor from previous response
235
+ * More efficient than offset for large datasets (O(1) vs O(n))
236
+ */
237
+ after?: string;
203
238
  }
204
239
  /**
205
240
  * @deprecated Use separate filter and ListOptions parameters instead
@@ -285,13 +320,28 @@ interface EmailParams {
285
320
  from_name?: string;
286
321
  }
287
322
  interface LLMMessage {
288
- role: 'system' | 'user' | 'assistant';
323
+ role: 'system' | 'user' | 'assistant' | 'tool';
289
324
  content: string | Array<{
290
325
  type: string;
291
326
  text?: string;
292
327
  file?: any;
293
328
  image_url?: any;
294
329
  }>;
330
+ /**
331
+ * For role="tool" messages - links to the tool_calls[].id from the assistant message.
332
+ * Required when role is "tool".
333
+ */
334
+ tool_call_id?: string;
335
+ /**
336
+ * For role="tool" messages - the function name that was called.
337
+ * Optional but recommended for clarity.
338
+ */
339
+ name?: string;
340
+ /**
341
+ * For assistant messages - tool calls the assistant wants to make.
342
+ * Present when the assistant decides to use tools.
343
+ */
344
+ tool_calls?: ToolCall[];
295
345
  }
296
346
  /**
297
347
  * Available LLM models:
@@ -347,6 +397,33 @@ interface ToolCall {
347
397
  name: string;
348
398
  arguments: Record<string, any>;
349
399
  }
400
+ /**
401
+ * Configuration for server-side persistence of LLM results.
402
+ * When provided, the backend automatically saves the result to the specified collection,
403
+ * ensuring data is not lost if the user navigates away before polling completes.
404
+ *
405
+ * @example
406
+ * ```typescript
407
+ * await invokeLLM({
408
+ * prompt: 'Analyze this data...',
409
+ * saveResult: {
410
+ * collection: 'analysis_results',
411
+ * field: 'result',
412
+ * additionalFields: { status: 'completed' }
413
+ * }
414
+ * });
415
+ * ```
416
+ */
417
+ interface SaveResultConfig {
418
+ /** Collection name to save the result to */
419
+ collection: string;
420
+ /** Document ID to update. If omitted, creates a new document */
421
+ documentId?: string;
422
+ /** Field name to save the LLM result to (default: 'content') */
423
+ field?: string;
424
+ /** Additional fields to include when creating/updating the document */
425
+ additionalFields?: Record<string, any>;
426
+ }
350
427
  interface LLMParams {
351
428
  /** Message-based format for advanced use */
352
429
  messages?: LLMMessage[];
@@ -441,6 +518,25 @@ interface LLMParams {
441
518
  * @param toolCall - The tool call with id, name, and arguments
442
519
  */
443
520
  onToolCall?: (toolCall: ToolCall) => void | Promise<void>;
521
+ /**
522
+ * Server-side persistence configuration.
523
+ * When provided, the backend saves the LLM result directly to the app's database,
524
+ * ensuring data is not lost if the user navigates away before polling completes.
525
+ *
526
+ * @example
527
+ * ```typescript
528
+ * await invokeLLM({
529
+ * prompt: 'Analyze this data...',
530
+ * saveResult: {
531
+ * collection: 'analysis_results',
532
+ * field: 'result',
533
+ * additionalFields: { status: 'completed' }
534
+ * }
535
+ * });
536
+ * // Result is saved server-side even if user navigates away!
537
+ * ```
538
+ */
539
+ saveResult?: SaveResultConfig;
444
540
  }
445
541
  /**
446
542
  * Grounding chunk from Google Search results
@@ -567,6 +663,14 @@ interface LLMResponse {
567
663
  * In non-streaming mode, they are included in the response.
568
664
  */
569
665
  tool_calls?: ToolCall[];
666
+ /**
667
+ * Server-side save result (when saveResult was provided in the request).
668
+ * Contains the collection and document ID where the result was saved.
669
+ */
670
+ saved_to?: {
671
+ collection: string;
672
+ document_id: string;
673
+ };
570
674
  /** @deprecated Use google_search_used instead */
571
675
  web_search_used?: boolean;
572
676
  }
@@ -1399,6 +1503,156 @@ interface IntegrationPackage {
1399
1503
  interface IntegrationSchema {
1400
1504
  installed_packages: IntegrationPackage[];
1401
1505
  }
1506
+ /**
1507
+ * Message in an assistant thread
1508
+ */
1509
+ interface AssistantMessage {
1510
+ role: 'user' | 'assistant' | 'tool';
1511
+ content: string;
1512
+ }
1513
+ /**
1514
+ * Action call made by the assistant during execution
1515
+ */
1516
+ interface AssistantActionCall {
1517
+ id: string;
1518
+ name: string;
1519
+ arguments: Record<string, any>;
1520
+ status: 'pending' | 'running' | 'completed' | 'failed';
1521
+ output?: any;
1522
+ error?: string;
1523
+ }
1524
+ /**
1525
+ * Parameters for running an assistant
1526
+ */
1527
+ interface AssistantRunParams {
1528
+ /**
1529
+ * Messages to send to the assistant
1530
+ */
1531
+ messages: AssistantMessage[];
1532
+ /**
1533
+ * Optional thread ID to continue an existing conversation.
1534
+ * If not provided, a new thread will be created.
1535
+ */
1536
+ threadId?: string;
1537
+ /**
1538
+ * Callback when a text token is received during streaming
1539
+ */
1540
+ onToken?: (token: string) => void;
1541
+ /**
1542
+ * Callback when an action starts executing
1543
+ */
1544
+ onActionStart?: (action: {
1545
+ id: string;
1546
+ name: string;
1547
+ arguments: Record<string, any>;
1548
+ }) => void;
1549
+ /**
1550
+ * Callback when an action completes successfully
1551
+ */
1552
+ onActionComplete?: (action: {
1553
+ id: string;
1554
+ name: string;
1555
+ output: any;
1556
+ }) => void;
1557
+ /**
1558
+ * Callback when an action fails
1559
+ */
1560
+ onActionFailed?: (action: {
1561
+ id: string;
1562
+ name: string;
1563
+ error: string;
1564
+ }) => void;
1565
+ /**
1566
+ * Callback when the run completes
1567
+ */
1568
+ onComplete?: (result: AssistantRunResult) => void;
1569
+ /**
1570
+ * Callback when an error occurs
1571
+ */
1572
+ onError?: (error: Error) => void;
1573
+ }
1574
+ /**
1575
+ * Result from running an assistant
1576
+ */
1577
+ interface AssistantRunResult {
1578
+ /** Thread ID (for continuing the conversation) */
1579
+ threadId: string;
1580
+ /** Number of messages in the thread */
1581
+ messageCount: number;
1582
+ /** Full response text from the assistant */
1583
+ response: string;
1584
+ }
1585
+ /**
1586
+ * Callbacks for thread subscription via WebSocket
1587
+ */
1588
+ interface ThreadSubscriptionCallbacks {
1589
+ /**
1590
+ * Called when connection is established
1591
+ */
1592
+ onConnected?: (info: {
1593
+ threadId: string;
1594
+ assistantName: string;
1595
+ messageCount: number;
1596
+ }) => void;
1597
+ /**
1598
+ * Called when a text token is received
1599
+ */
1600
+ onToken?: (token: string) => void;
1601
+ /**
1602
+ * Called when an action starts
1603
+ */
1604
+ onActionStart?: (action: {
1605
+ id: string;
1606
+ name: string;
1607
+ arguments: Record<string, any>;
1608
+ }) => void;
1609
+ /**
1610
+ * Called when an action completes
1611
+ */
1612
+ onActionComplete?: (action: {
1613
+ id: string;
1614
+ name: string;
1615
+ output: any;
1616
+ }) => void;
1617
+ /**
1618
+ * Called when an action fails
1619
+ */
1620
+ onActionFailed?: (action: {
1621
+ id: string;
1622
+ name: string;
1623
+ error: string;
1624
+ }) => void;
1625
+ /**
1626
+ * Called when the run completes
1627
+ */
1628
+ onRunComplete?: (result: {
1629
+ threadId: string;
1630
+ messageCount: number;
1631
+ }) => void;
1632
+ /**
1633
+ * Called when an error occurs
1634
+ */
1635
+ onError?: (error: Error) => void;
1636
+ /**
1637
+ * Called when connection closes
1638
+ */
1639
+ onDisconnect?: () => void;
1640
+ }
1641
+ /**
1642
+ * SSE event types for assistant streaming
1643
+ */
1644
+ interface AssistantStreamEvent {
1645
+ type: 'token' | 'action_start' | 'action_complete' | 'action_failed' | 'done' | 'error';
1646
+ content?: string;
1647
+ id?: string;
1648
+ name?: string;
1649
+ arguments?: Record<string, any>;
1650
+ output?: any;
1651
+ error?: string;
1652
+ message?: string;
1653
+ thread_id?: string;
1654
+ message_count?: number;
1655
+ }
1402
1656
  /**
1403
1657
  * Available voice options for Live Voice AI
1404
1658
  */
@@ -1822,6 +2076,63 @@ declare class APIClient implements OmnikitClient {
1822
2076
  * @returns A LiveVoiceSession object to control the session
1823
2077
  */
1824
2078
  createLiveVoiceSession(config?: LiveVoiceConfig): LiveVoiceSession;
2079
+ /**
2080
+ * Run an assistant with streaming response.
2081
+ *
2082
+ * Assistants are server-side AI agents with custom instructions and built-in actions.
2083
+ * They can create/update/delete records, send emails, make HTTP requests, etc.
2084
+ *
2085
+ * @example
2086
+ * ```typescript
2087
+ * const result = await omnikit.runAssistant('customer_support', {
2088
+ * messages: [{ role: 'user', content: 'Help me track my order #12345' }],
2089
+ * onToken: (token) => setResponse(prev => prev + token),
2090
+ * onActionStart: (action) => console.log(`Starting: ${action.name}`),
2091
+ * onActionComplete: (action) => console.log(`Completed: ${action.name}`),
2092
+ * });
2093
+ *
2094
+ * // Continue the conversation
2095
+ * await omnikit.runAssistant('customer_support', {
2096
+ * messages: [{ role: 'user', content: 'When will it arrive?' }],
2097
+ * threadId: result.threadId,
2098
+ * onToken: (token) => setResponse(prev => prev + token),
2099
+ * });
2100
+ * ```
2101
+ *
2102
+ * @param assistantName - Name of the assistant to run
2103
+ * @param params - Run parameters including messages and callbacks
2104
+ * @returns Promise resolving to the run result with threadId
2105
+ */
2106
+ runAssistant(assistantName: string, params: AssistantRunParams): Promise<AssistantRunResult>;
2107
+ /**
2108
+ * Subscribe to a thread via WebSocket for real-time updates.
2109
+ *
2110
+ * Use this to watch a thread without triggering a run. Useful for:
2111
+ * - Showing live updates when another client runs the assistant
2112
+ * - Reconnecting after page navigation
2113
+ * - Observing thread activity in real-time
2114
+ *
2115
+ * @example
2116
+ * ```typescript
2117
+ * // Subscribe to a thread
2118
+ * const unsubscribe = omnikit.subscribeToThread(threadId, {
2119
+ * onConnected: (info) => console.log(`Connected to ${info.assistantName}`),
2120
+ * onToken: (token) => setResponse(prev => prev + token),
2121
+ * onActionStart: (action) => console.log(`Action: ${action.name}`),
2122
+ * onActionComplete: (action) => console.log(`Result: ${JSON.stringify(action.output)}`),
2123
+ * onRunComplete: (result) => console.log(`Run complete, ${result.messageCount} messages`),
2124
+ * onError: (error) => console.error(error),
2125
+ * });
2126
+ *
2127
+ * // Later: disconnect
2128
+ * unsubscribe();
2129
+ * ```
2130
+ *
2131
+ * @param threadId - Thread ID to subscribe to
2132
+ * @param callbacks - Event callbacks for real-time updates
2133
+ * @returns Unsubscribe function to close the WebSocket
2134
+ */
2135
+ subscribeToThread(threadId: string, callbacks: ThreadSubscriptionCallbacks): () => void;
1825
2136
  /**
1826
2137
  * Invoke a backend function by name.
1827
2138
  *
@@ -2121,4 +2432,4 @@ declare class Analytics {
2121
2432
  }
2122
2433
  declare function createAnalytics(config: AnalyticsConfig): Analytics;
2123
2434
 
2124
- export { APIClient, Analytics, type AnalyticsConfig, type AppMetadata, type AppSchema, type AsyncJobCreatedResponse, type AsyncJobStatus, type AsyncJobStatusResponse, type AsyncJobType, type AsyncOptions, type AuthModule, type AuthResponse, type BuiltInIntegration, type BulkResult, type CachedMetadata, type CheckJobStatusParams, type CollectionClass, type CollectionDefinition, type CollectionField, type CollectionRecord, type ConnectorAccessTokenResponse, type ConnectorStatusResponse, type ConnectorType, type ConnectorsModule, type EmailParams, type Entity, type EntityClass, type EntityDefinition, type EntityField, type EntityRecord, type EventPayload, type ExtractParams, type GroundingChunk, type GroundingMetadata, type GroundingSupport, type ImageParams, type ImportResult, type InitialMetadata, type IntegrationEndpoint, type IntegrationMethod, type IntegrationPackage, type IntegrationSchema, type LLMMessage, type LLMModel, type LLMParams, type LLMResponse, type LLMStreamEvent, type LLMStreamResult, type ListOptions, type LiveVoiceClientMessage, type LiveVoiceConfig, type LiveVoiceServerMessage, type LiveVoiceSession, LiveVoiceSessionImpl, type LiveVoiceStatus, type LiveVoiceVoice, type OAuthProvider, type OAuthProvidersResponse, type OmnikitClient, type OmnikitConfig, OmnikitError, type QueryOptions, type RequestOptions, type SMSParams, type ServiceDefinition, type ServiceResponse, type ServiceRoleClient, type ServicesSchema, type SpeechParams, type TemplateDefinition, type ToolCall, type ToolDefinition, type ToolParameter, type UrlContextMetadata, type UrlMetadata, type UrlRetrievalStatus, type UserCollectionClass, type UserEntityClass, type UserInfo, type VideoParams, type VideoStatusParams, createAnalytics, createClient, createClientFromRequest, createServerClient };
2435
+ export { APIClient, Analytics, type AnalyticsConfig, type AppMetadata, type AppSchema, type AssistantActionCall, type AssistantMessage, type AssistantRunParams, type AssistantRunResult, type AssistantStreamEvent, type AsyncJobCreatedResponse, type AsyncJobStatus, type AsyncJobStatusResponse, type AsyncJobType, type AsyncOptions, type AuthModule, type AuthResponse, type BuiltInIntegration, type BulkResult, type CachedMetadata, type CheckJobStatusParams, type CollectionClass, type CollectionDefinition, type CollectionField, type CollectionRecord, type ConnectorAccessTokenResponse, type ConnectorStatusResponse, type ConnectorType, type ConnectorsModule, type EmailParams, type Entity, type EntityClass, type EntityDefinition, type EntityField, type EntityRecord, type EventPayload, type ExtractParams, type GroundingChunk, type GroundingMetadata, type GroundingSupport, type ImageParams, type ImportResult, type InitialMetadata, type IntegrationEndpoint, type IntegrationMethod, type IntegrationPackage, type IntegrationSchema, type LLMMessage, type LLMModel, type LLMParams, type LLMResponse, type LLMStreamEvent, type LLMStreamResult, type ListOptions, type LiveVoiceClientMessage, type LiveVoiceConfig, type LiveVoiceServerMessage, type LiveVoiceSession, LiveVoiceSessionImpl, type LiveVoiceStatus, type LiveVoiceVoice, type OAuthProvider, type OAuthProvidersResponse, type OmnikitClient, type OmnikitConfig, OmnikitError, type PaginatedResult, type QueryOptions, type RequestOptions, type SMSParams, type SaveResultConfig, type ServiceDefinition, type ServiceResponse, type ServiceRoleClient, type ServicesSchema, type SpeechParams, type TemplateDefinition, type ThreadSubscriptionCallbacks, type ToolCall, type ToolDefinition, type ToolParameter, type UrlContextMetadata, type UrlMetadata, type UrlRetrievalStatus, type UserCollectionClass, type UserEntityClass, type UserInfo, type VideoParams, type VideoStatusParams, createAnalytics, createClient, createClientFromRequest, createServerClient };