@omnikit-ai/sdk 2.2.1 → 2.2.2
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 +301 -5
- package/dist/index.d.ts +301 -5
- package/dist/index.js +296 -10
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +296 -10
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -178,7 +178,30 @@ interface AppSchema {
|
|
|
178
178
|
platform_version?: number;
|
|
179
179
|
}
|
|
180
180
|
/**
|
|
181
|
-
*
|
|
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
|
-
* //
|
|
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
|
-
/**
|
|
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
|
|
@@ -347,6 +382,33 @@ interface ToolCall {
|
|
|
347
382
|
name: string;
|
|
348
383
|
arguments: Record<string, any>;
|
|
349
384
|
}
|
|
385
|
+
/**
|
|
386
|
+
* Configuration for server-side persistence of LLM results.
|
|
387
|
+
* When provided, the backend automatically saves the result to the specified collection,
|
|
388
|
+
* ensuring data is not lost if the user navigates away before polling completes.
|
|
389
|
+
*
|
|
390
|
+
* @example
|
|
391
|
+
* ```typescript
|
|
392
|
+
* await invokeLLM({
|
|
393
|
+
* prompt: 'Analyze this data...',
|
|
394
|
+
* saveResult: {
|
|
395
|
+
* collection: 'analysis_results',
|
|
396
|
+
* field: 'result',
|
|
397
|
+
* additionalFields: { status: 'completed' }
|
|
398
|
+
* }
|
|
399
|
+
* });
|
|
400
|
+
* ```
|
|
401
|
+
*/
|
|
402
|
+
interface SaveResultConfig {
|
|
403
|
+
/** Collection name to save the result to */
|
|
404
|
+
collection: string;
|
|
405
|
+
/** Document ID to update. If omitted, creates a new document */
|
|
406
|
+
documentId?: string;
|
|
407
|
+
/** Field name to save the LLM result to (default: 'content') */
|
|
408
|
+
field?: string;
|
|
409
|
+
/** Additional fields to include when creating/updating the document */
|
|
410
|
+
additionalFields?: Record<string, any>;
|
|
411
|
+
}
|
|
350
412
|
interface LLMParams {
|
|
351
413
|
/** Message-based format for advanced use */
|
|
352
414
|
messages?: LLMMessage[];
|
|
@@ -441,6 +503,25 @@ interface LLMParams {
|
|
|
441
503
|
* @param toolCall - The tool call with id, name, and arguments
|
|
442
504
|
*/
|
|
443
505
|
onToolCall?: (toolCall: ToolCall) => void | Promise<void>;
|
|
506
|
+
/**
|
|
507
|
+
* Server-side persistence configuration.
|
|
508
|
+
* When provided, the backend saves the LLM result directly to the app's database,
|
|
509
|
+
* ensuring data is not lost if the user navigates away before polling completes.
|
|
510
|
+
*
|
|
511
|
+
* @example
|
|
512
|
+
* ```typescript
|
|
513
|
+
* await invokeLLM({
|
|
514
|
+
* prompt: 'Analyze this data...',
|
|
515
|
+
* saveResult: {
|
|
516
|
+
* collection: 'analysis_results',
|
|
517
|
+
* field: 'result',
|
|
518
|
+
* additionalFields: { status: 'completed' }
|
|
519
|
+
* }
|
|
520
|
+
* });
|
|
521
|
+
* // Result is saved server-side even if user navigates away!
|
|
522
|
+
* ```
|
|
523
|
+
*/
|
|
524
|
+
saveResult?: SaveResultConfig;
|
|
444
525
|
}
|
|
445
526
|
/**
|
|
446
527
|
* Grounding chunk from Google Search results
|
|
@@ -567,6 +648,14 @@ interface LLMResponse {
|
|
|
567
648
|
* In non-streaming mode, they are included in the response.
|
|
568
649
|
*/
|
|
569
650
|
tool_calls?: ToolCall[];
|
|
651
|
+
/**
|
|
652
|
+
* Server-side save result (when saveResult was provided in the request).
|
|
653
|
+
* Contains the collection and document ID where the result was saved.
|
|
654
|
+
*/
|
|
655
|
+
saved_to?: {
|
|
656
|
+
collection: string;
|
|
657
|
+
document_id: string;
|
|
658
|
+
};
|
|
570
659
|
/** @deprecated Use google_search_used instead */
|
|
571
660
|
web_search_used?: boolean;
|
|
572
661
|
}
|
|
@@ -1399,6 +1488,156 @@ interface IntegrationPackage {
|
|
|
1399
1488
|
interface IntegrationSchema {
|
|
1400
1489
|
installed_packages: IntegrationPackage[];
|
|
1401
1490
|
}
|
|
1491
|
+
/**
|
|
1492
|
+
* Message in an assistant thread
|
|
1493
|
+
*/
|
|
1494
|
+
interface AssistantMessage {
|
|
1495
|
+
role: 'user' | 'assistant' | 'tool';
|
|
1496
|
+
content: string;
|
|
1497
|
+
}
|
|
1498
|
+
/**
|
|
1499
|
+
* Action call made by the assistant during execution
|
|
1500
|
+
*/
|
|
1501
|
+
interface AssistantActionCall {
|
|
1502
|
+
id: string;
|
|
1503
|
+
name: string;
|
|
1504
|
+
arguments: Record<string, any>;
|
|
1505
|
+
status: 'pending' | 'running' | 'completed' | 'failed';
|
|
1506
|
+
output?: any;
|
|
1507
|
+
error?: string;
|
|
1508
|
+
}
|
|
1509
|
+
/**
|
|
1510
|
+
* Parameters for running an assistant
|
|
1511
|
+
*/
|
|
1512
|
+
interface AssistantRunParams {
|
|
1513
|
+
/**
|
|
1514
|
+
* Messages to send to the assistant
|
|
1515
|
+
*/
|
|
1516
|
+
messages: AssistantMessage[];
|
|
1517
|
+
/**
|
|
1518
|
+
* Optional thread ID to continue an existing conversation.
|
|
1519
|
+
* If not provided, a new thread will be created.
|
|
1520
|
+
*/
|
|
1521
|
+
threadId?: string;
|
|
1522
|
+
/**
|
|
1523
|
+
* Callback when a text token is received during streaming
|
|
1524
|
+
*/
|
|
1525
|
+
onToken?: (token: string) => void;
|
|
1526
|
+
/**
|
|
1527
|
+
* Callback when an action starts executing
|
|
1528
|
+
*/
|
|
1529
|
+
onActionStart?: (action: {
|
|
1530
|
+
id: string;
|
|
1531
|
+
name: string;
|
|
1532
|
+
arguments: Record<string, any>;
|
|
1533
|
+
}) => void;
|
|
1534
|
+
/**
|
|
1535
|
+
* Callback when an action completes successfully
|
|
1536
|
+
*/
|
|
1537
|
+
onActionComplete?: (action: {
|
|
1538
|
+
id: string;
|
|
1539
|
+
name: string;
|
|
1540
|
+
output: any;
|
|
1541
|
+
}) => void;
|
|
1542
|
+
/**
|
|
1543
|
+
* Callback when an action fails
|
|
1544
|
+
*/
|
|
1545
|
+
onActionFailed?: (action: {
|
|
1546
|
+
id: string;
|
|
1547
|
+
name: string;
|
|
1548
|
+
error: string;
|
|
1549
|
+
}) => void;
|
|
1550
|
+
/**
|
|
1551
|
+
* Callback when the run completes
|
|
1552
|
+
*/
|
|
1553
|
+
onComplete?: (result: AssistantRunResult) => void;
|
|
1554
|
+
/**
|
|
1555
|
+
* Callback when an error occurs
|
|
1556
|
+
*/
|
|
1557
|
+
onError?: (error: Error) => void;
|
|
1558
|
+
}
|
|
1559
|
+
/**
|
|
1560
|
+
* Result from running an assistant
|
|
1561
|
+
*/
|
|
1562
|
+
interface AssistantRunResult {
|
|
1563
|
+
/** Thread ID (for continuing the conversation) */
|
|
1564
|
+
threadId: string;
|
|
1565
|
+
/** Number of messages in the thread */
|
|
1566
|
+
messageCount: number;
|
|
1567
|
+
/** Full response text from the assistant */
|
|
1568
|
+
response: string;
|
|
1569
|
+
}
|
|
1570
|
+
/**
|
|
1571
|
+
* Callbacks for thread subscription via WebSocket
|
|
1572
|
+
*/
|
|
1573
|
+
interface ThreadSubscriptionCallbacks {
|
|
1574
|
+
/**
|
|
1575
|
+
* Called when connection is established
|
|
1576
|
+
*/
|
|
1577
|
+
onConnected?: (info: {
|
|
1578
|
+
threadId: string;
|
|
1579
|
+
assistantName: string;
|
|
1580
|
+
messageCount: number;
|
|
1581
|
+
}) => void;
|
|
1582
|
+
/**
|
|
1583
|
+
* Called when a text token is received
|
|
1584
|
+
*/
|
|
1585
|
+
onToken?: (token: string) => void;
|
|
1586
|
+
/**
|
|
1587
|
+
* Called when an action starts
|
|
1588
|
+
*/
|
|
1589
|
+
onActionStart?: (action: {
|
|
1590
|
+
id: string;
|
|
1591
|
+
name: string;
|
|
1592
|
+
arguments: Record<string, any>;
|
|
1593
|
+
}) => void;
|
|
1594
|
+
/**
|
|
1595
|
+
* Called when an action completes
|
|
1596
|
+
*/
|
|
1597
|
+
onActionComplete?: (action: {
|
|
1598
|
+
id: string;
|
|
1599
|
+
name: string;
|
|
1600
|
+
output: any;
|
|
1601
|
+
}) => void;
|
|
1602
|
+
/**
|
|
1603
|
+
* Called when an action fails
|
|
1604
|
+
*/
|
|
1605
|
+
onActionFailed?: (action: {
|
|
1606
|
+
id: string;
|
|
1607
|
+
name: string;
|
|
1608
|
+
error: string;
|
|
1609
|
+
}) => void;
|
|
1610
|
+
/**
|
|
1611
|
+
* Called when the run completes
|
|
1612
|
+
*/
|
|
1613
|
+
onRunComplete?: (result: {
|
|
1614
|
+
threadId: string;
|
|
1615
|
+
messageCount: number;
|
|
1616
|
+
}) => void;
|
|
1617
|
+
/**
|
|
1618
|
+
* Called when an error occurs
|
|
1619
|
+
*/
|
|
1620
|
+
onError?: (error: Error) => void;
|
|
1621
|
+
/**
|
|
1622
|
+
* Called when connection closes
|
|
1623
|
+
*/
|
|
1624
|
+
onDisconnect?: () => void;
|
|
1625
|
+
}
|
|
1626
|
+
/**
|
|
1627
|
+
* SSE event types for assistant streaming
|
|
1628
|
+
*/
|
|
1629
|
+
interface AssistantStreamEvent {
|
|
1630
|
+
type: 'token' | 'action_start' | 'action_complete' | 'action_failed' | 'done' | 'error';
|
|
1631
|
+
content?: string;
|
|
1632
|
+
id?: string;
|
|
1633
|
+
name?: string;
|
|
1634
|
+
arguments?: Record<string, any>;
|
|
1635
|
+
output?: any;
|
|
1636
|
+
error?: string;
|
|
1637
|
+
message?: string;
|
|
1638
|
+
thread_id?: string;
|
|
1639
|
+
message_count?: number;
|
|
1640
|
+
}
|
|
1402
1641
|
/**
|
|
1403
1642
|
* Available voice options for Live Voice AI
|
|
1404
1643
|
*/
|
|
@@ -1822,6 +2061,63 @@ declare class APIClient implements OmnikitClient {
|
|
|
1822
2061
|
* @returns A LiveVoiceSession object to control the session
|
|
1823
2062
|
*/
|
|
1824
2063
|
createLiveVoiceSession(config?: LiveVoiceConfig): LiveVoiceSession;
|
|
2064
|
+
/**
|
|
2065
|
+
* Run an assistant with streaming response.
|
|
2066
|
+
*
|
|
2067
|
+
* Assistants are server-side AI agents with custom instructions and built-in actions.
|
|
2068
|
+
* They can create/update/delete records, send emails, make HTTP requests, etc.
|
|
2069
|
+
*
|
|
2070
|
+
* @example
|
|
2071
|
+
* ```typescript
|
|
2072
|
+
* const result = await omnikit.runAssistant('customer_support', {
|
|
2073
|
+
* messages: [{ role: 'user', content: 'Help me track my order #12345' }],
|
|
2074
|
+
* onToken: (token) => setResponse(prev => prev + token),
|
|
2075
|
+
* onActionStart: (action) => console.log(`Starting: ${action.name}`),
|
|
2076
|
+
* onActionComplete: (action) => console.log(`Completed: ${action.name}`),
|
|
2077
|
+
* });
|
|
2078
|
+
*
|
|
2079
|
+
* // Continue the conversation
|
|
2080
|
+
* await omnikit.runAssistant('customer_support', {
|
|
2081
|
+
* messages: [{ role: 'user', content: 'When will it arrive?' }],
|
|
2082
|
+
* threadId: result.threadId,
|
|
2083
|
+
* onToken: (token) => setResponse(prev => prev + token),
|
|
2084
|
+
* });
|
|
2085
|
+
* ```
|
|
2086
|
+
*
|
|
2087
|
+
* @param assistantName - Name of the assistant to run
|
|
2088
|
+
* @param params - Run parameters including messages and callbacks
|
|
2089
|
+
* @returns Promise resolving to the run result with threadId
|
|
2090
|
+
*/
|
|
2091
|
+
runAssistant(assistantName: string, params: AssistantRunParams): Promise<AssistantRunResult>;
|
|
2092
|
+
/**
|
|
2093
|
+
* Subscribe to a thread via WebSocket for real-time updates.
|
|
2094
|
+
*
|
|
2095
|
+
* Use this to watch a thread without triggering a run. Useful for:
|
|
2096
|
+
* - Showing live updates when another client runs the assistant
|
|
2097
|
+
* - Reconnecting after page navigation
|
|
2098
|
+
* - Observing thread activity in real-time
|
|
2099
|
+
*
|
|
2100
|
+
* @example
|
|
2101
|
+
* ```typescript
|
|
2102
|
+
* // Subscribe to a thread
|
|
2103
|
+
* const unsubscribe = omnikit.subscribeToThread(threadId, {
|
|
2104
|
+
* onConnected: (info) => console.log(`Connected to ${info.assistantName}`),
|
|
2105
|
+
* onToken: (token) => setResponse(prev => prev + token),
|
|
2106
|
+
* onActionStart: (action) => console.log(`Action: ${action.name}`),
|
|
2107
|
+
* onActionComplete: (action) => console.log(`Result: ${JSON.stringify(action.output)}`),
|
|
2108
|
+
* onRunComplete: (result) => console.log(`Run complete, ${result.messageCount} messages`),
|
|
2109
|
+
* onError: (error) => console.error(error),
|
|
2110
|
+
* });
|
|
2111
|
+
*
|
|
2112
|
+
* // Later: disconnect
|
|
2113
|
+
* unsubscribe();
|
|
2114
|
+
* ```
|
|
2115
|
+
*
|
|
2116
|
+
* @param threadId - Thread ID to subscribe to
|
|
2117
|
+
* @param callbacks - Event callbacks for real-time updates
|
|
2118
|
+
* @returns Unsubscribe function to close the WebSocket
|
|
2119
|
+
*/
|
|
2120
|
+
subscribeToThread(threadId: string, callbacks: ThreadSubscriptionCallbacks): () => void;
|
|
1825
2121
|
/**
|
|
1826
2122
|
* Invoke a backend function by name.
|
|
1827
2123
|
*
|
|
@@ -2121,4 +2417,4 @@ declare class Analytics {
|
|
|
2121
2417
|
}
|
|
2122
2418
|
declare function createAnalytics(config: AnalyticsConfig): Analytics;
|
|
2123
2419
|
|
|
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 };
|
|
2420
|
+
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 };
|