@omnikit-ai/sdk 2.0.10 → 2.2.1
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 +573 -13
- package/dist/index.d.ts +573 -13
- package/dist/index.js +571 -64
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +568 -65
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,70 @@
|
|
|
1
1
|
export { cleanTokenFromUrl, getAccessToken, isTokenInUrl, removeAccessToken, saveAccessToken, setAccessToken } from './auth-utils.mjs';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Omnikit SDK - Connectors Module
|
|
5
|
+
*
|
|
6
|
+
* Provides access to connected external services (Slack, Google Calendar, Notion, etc.)
|
|
7
|
+
* Like Base44's connectors module - allows backend functions to get access tokens
|
|
8
|
+
* for making direct API calls to external services.
|
|
9
|
+
*
|
|
10
|
+
* SECURITY: getAccessToken requires service token authentication.
|
|
11
|
+
* Only available to backend functions, not frontend code.
|
|
12
|
+
*/
|
|
13
|
+
type ConnectorType = 'slack' | 'google_calendar' | 'gmail' | 'notion' | 'salesforce';
|
|
14
|
+
interface ConnectorAccessTokenResponse {
|
|
15
|
+
success: boolean;
|
|
16
|
+
access_token: string;
|
|
17
|
+
connector_type: string;
|
|
18
|
+
external_workspace_id?: string;
|
|
19
|
+
external_workspace_name?: string;
|
|
20
|
+
}
|
|
21
|
+
interface ConnectorStatusResponse {
|
|
22
|
+
success: boolean;
|
|
23
|
+
connector?: {
|
|
24
|
+
connector_type: string;
|
|
25
|
+
status: string;
|
|
26
|
+
external_workspace_id?: string;
|
|
27
|
+
external_workspace_name?: string;
|
|
28
|
+
external_user_email?: string;
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
interface ConnectorsModule$1 {
|
|
32
|
+
/**
|
|
33
|
+
* Get access token for a connector.
|
|
34
|
+
*
|
|
35
|
+
* SECURITY: Requires service token authentication.
|
|
36
|
+
* Only available in backend functions, not frontend code.
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```typescript
|
|
40
|
+
* // In a backend function
|
|
41
|
+
* const { access_token } = await omnikit.connectors.getAccessToken('slack');
|
|
42
|
+
*
|
|
43
|
+
* // Make direct Slack API call
|
|
44
|
+
* const response = await fetch('https://slack.com/api/chat.postMessage', {
|
|
45
|
+
* method: 'POST',
|
|
46
|
+
* headers: {
|
|
47
|
+
* 'Authorization': `Bearer ${access_token}`,
|
|
48
|
+
* 'Content-Type': 'application/json',
|
|
49
|
+
* },
|
|
50
|
+
* body: JSON.stringify({
|
|
51
|
+
* channel: '#general',
|
|
52
|
+
* text: 'Hello from Omnikit!'
|
|
53
|
+
* })
|
|
54
|
+
* });
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
getAccessToken(connectorType: ConnectorType): Promise<ConnectorAccessTokenResponse>;
|
|
58
|
+
/**
|
|
59
|
+
* Check if a connector is connected.
|
|
60
|
+
*/
|
|
61
|
+
isConnected(connectorType: ConnectorType): Promise<boolean>;
|
|
62
|
+
/**
|
|
63
|
+
* Get connector status and info.
|
|
64
|
+
*/
|
|
65
|
+
getStatus(connectorType: ConnectorType): Promise<ConnectorStatusResponse>;
|
|
66
|
+
}
|
|
67
|
+
|
|
3
68
|
/**
|
|
4
69
|
* Omnikit SDK Type Definitions v2.0
|
|
5
70
|
*/
|
|
@@ -235,6 +300,53 @@ interface LLMMessage {
|
|
|
235
300
|
* - Legacy aliases: 'gemini-flash', 'gemini-pro', 'gemini-pro-3' (for backward compatibility)
|
|
236
301
|
*/
|
|
237
302
|
type LLMModel = 'gemini-2.5-flash-lite' | 'gemini-2.5-flash' | 'gemini-2.5-pro' | 'gemini-3-flash' | 'gemini-3-pro' | 'gemini-flash' | 'gemini-pro' | 'gemini-pro-3';
|
|
303
|
+
/**
|
|
304
|
+
* Parameter definition for a tool (OpenAPI/Gemini compatible format)
|
|
305
|
+
*/
|
|
306
|
+
interface ToolParameter {
|
|
307
|
+
type: 'object';
|
|
308
|
+
properties: Record<string, {
|
|
309
|
+
type: string;
|
|
310
|
+
description?: string;
|
|
311
|
+
enum?: string[];
|
|
312
|
+
items?: {
|
|
313
|
+
type: string;
|
|
314
|
+
};
|
|
315
|
+
}>;
|
|
316
|
+
required?: string[];
|
|
317
|
+
}
|
|
318
|
+
/**
|
|
319
|
+
* Tool definition for LLM function calling.
|
|
320
|
+
*
|
|
321
|
+
* @example
|
|
322
|
+
* ```typescript
|
|
323
|
+
* const markStepTool: ToolDefinition = {
|
|
324
|
+
* name: 'mark_step_complete',
|
|
325
|
+
* description: 'Mark a workshop step as completed',
|
|
326
|
+
* parameters: {
|
|
327
|
+
* type: 'object',
|
|
328
|
+
* properties: {
|
|
329
|
+
* step_id: { type: 'string', description: 'The step ID' },
|
|
330
|
+
* summary: { type: 'string', description: 'Summary of completion' }
|
|
331
|
+
* },
|
|
332
|
+
* required: ['step_id', 'summary']
|
|
333
|
+
* }
|
|
334
|
+
* };
|
|
335
|
+
* ```
|
|
336
|
+
*/
|
|
337
|
+
interface ToolDefinition {
|
|
338
|
+
name: string;
|
|
339
|
+
description: string;
|
|
340
|
+
parameters: ToolParameter;
|
|
341
|
+
}
|
|
342
|
+
/**
|
|
343
|
+
* A tool call returned by the LLM during streaming or in response
|
|
344
|
+
*/
|
|
345
|
+
interface ToolCall {
|
|
346
|
+
id: string;
|
|
347
|
+
name: string;
|
|
348
|
+
arguments: Record<string, any>;
|
|
349
|
+
}
|
|
238
350
|
interface LLMParams {
|
|
239
351
|
/** Message-based format for advanced use */
|
|
240
352
|
messages?: LLMMessage[];
|
|
@@ -293,6 +405,106 @@ interface LLMParams {
|
|
|
293
405
|
* @param error - The error that occurred
|
|
294
406
|
*/
|
|
295
407
|
onError?: (error: Error) => void;
|
|
408
|
+
/**
|
|
409
|
+
* Tool definitions for function calling.
|
|
410
|
+
* When provided, the LLM can request tool calls which are executed client-side.
|
|
411
|
+
*
|
|
412
|
+
* @example
|
|
413
|
+
* ```typescript
|
|
414
|
+
* await omnikit.services.InvokeLLM({
|
|
415
|
+
* messages: [...],
|
|
416
|
+
* stream: true,
|
|
417
|
+
* tools: [{
|
|
418
|
+
* name: 'mark_step_complete',
|
|
419
|
+
* description: 'Mark a step as completed',
|
|
420
|
+
* parameters: {
|
|
421
|
+
* type: 'object',
|
|
422
|
+
* properties: {
|
|
423
|
+
* step_id: { type: 'string', description: 'Step ID' }
|
|
424
|
+
* },
|
|
425
|
+
* required: ['step_id']
|
|
426
|
+
* }
|
|
427
|
+
* }],
|
|
428
|
+
* onToolCall: async (toolCall) => {
|
|
429
|
+
* if (toolCall.name === 'mark_step_complete') {
|
|
430
|
+
* await markStepComplete(toolCall.arguments.step_id);
|
|
431
|
+
* }
|
|
432
|
+
* }
|
|
433
|
+
* });
|
|
434
|
+
* ```
|
|
435
|
+
*/
|
|
436
|
+
tools?: ToolDefinition[];
|
|
437
|
+
/**
|
|
438
|
+
* Callback when LLM requests a tool call (fires during streaming).
|
|
439
|
+
* Handle the tool execution and optionally continue the conversation.
|
|
440
|
+
*
|
|
441
|
+
* @param toolCall - The tool call with id, name, and arguments
|
|
442
|
+
*/
|
|
443
|
+
onToolCall?: (toolCall: ToolCall) => void | Promise<void>;
|
|
444
|
+
}
|
|
445
|
+
/**
|
|
446
|
+
* Grounding chunk from Google Search results
|
|
447
|
+
*/
|
|
448
|
+
interface GroundingChunk {
|
|
449
|
+
/** Web source */
|
|
450
|
+
web?: {
|
|
451
|
+
/** URL of the source */
|
|
452
|
+
uri: string;
|
|
453
|
+
/** Title of the source */
|
|
454
|
+
title: string;
|
|
455
|
+
};
|
|
456
|
+
}
|
|
457
|
+
/**
|
|
458
|
+
* Grounding support linking text segments to sources
|
|
459
|
+
*/
|
|
460
|
+
interface GroundingSupport {
|
|
461
|
+
/** Text segment in the response */
|
|
462
|
+
segment?: {
|
|
463
|
+
startIndex: number;
|
|
464
|
+
endIndex: number;
|
|
465
|
+
text: string;
|
|
466
|
+
};
|
|
467
|
+
/** Indices into groundingChunks array */
|
|
468
|
+
groundingChunkIndices?: number[];
|
|
469
|
+
}
|
|
470
|
+
/**
|
|
471
|
+
* Metadata from Google Search grounding
|
|
472
|
+
*/
|
|
473
|
+
interface GroundingMetadata {
|
|
474
|
+
/** Search queries that were executed */
|
|
475
|
+
webSearchQueries?: string[];
|
|
476
|
+
/** HTML/CSS for search suggestions widget (per Gemini API ToS) */
|
|
477
|
+
searchEntryPoint?: {
|
|
478
|
+
renderedContent: string;
|
|
479
|
+
};
|
|
480
|
+
/** Source chunks from web search */
|
|
481
|
+
groundingChunks?: GroundingChunk[];
|
|
482
|
+
/** Text-to-source mappings for citations */
|
|
483
|
+
groundingSupports?: GroundingSupport[];
|
|
484
|
+
/** Items array (alternative format) */
|
|
485
|
+
items?: any[];
|
|
486
|
+
}
|
|
487
|
+
/**
|
|
488
|
+
* URL retrieval status
|
|
489
|
+
*/
|
|
490
|
+
type UrlRetrievalStatus = 'URL_RETRIEVAL_STATUS_SUCCESS' | 'URL_RETRIEVAL_STATUS_UNSAFE' | 'URL_RETRIEVAL_STATUS_FAILED' | 'URL_RETRIEVAL_STATUS_UNSPECIFIED';
|
|
491
|
+
/**
|
|
492
|
+
* Metadata for a single URL context retrieval
|
|
493
|
+
*/
|
|
494
|
+
interface UrlMetadata {
|
|
495
|
+
/** The URL that was retrieved */
|
|
496
|
+
retrieved_url: string;
|
|
497
|
+
/** Status of the retrieval */
|
|
498
|
+
url_retrieval_status: UrlRetrievalStatus;
|
|
499
|
+
}
|
|
500
|
+
/**
|
|
501
|
+
* Metadata from URL context tool
|
|
502
|
+
*/
|
|
503
|
+
interface UrlContextMetadata {
|
|
504
|
+
/** Array of URL metadata for each URL processed */
|
|
505
|
+
url_metadata?: UrlMetadata[];
|
|
506
|
+
/** Items array (alternative format) */
|
|
507
|
+
items?: any[];
|
|
296
508
|
}
|
|
297
509
|
/**
|
|
298
510
|
* Result from streaming LLM completion
|
|
@@ -313,14 +525,63 @@ interface LLMStreamResult {
|
|
|
313
525
|
/** Whether files were in the input */
|
|
314
526
|
has_files?: boolean;
|
|
315
527
|
}
|
|
528
|
+
/**
|
|
529
|
+
* Full LLM response (non-streaming)
|
|
530
|
+
*/
|
|
531
|
+
interface LLMResponse {
|
|
532
|
+
/** Whether the request was successful */
|
|
533
|
+
success: boolean;
|
|
534
|
+
/** Response content (string or parsed JSON when response_format is used) */
|
|
535
|
+
result: any;
|
|
536
|
+
/** Model that was used */
|
|
537
|
+
model_used: string;
|
|
538
|
+
/** Whether images were in the input */
|
|
539
|
+
has_images?: boolean;
|
|
540
|
+
/** Whether files were in the input */
|
|
541
|
+
has_files?: boolean;
|
|
542
|
+
/** Whether Google Search grounding was used */
|
|
543
|
+
google_search_used?: boolean;
|
|
544
|
+
/** Whether URL context was used */
|
|
545
|
+
url_context_used?: boolean;
|
|
546
|
+
/** Number of continuation requests made for long outputs */
|
|
547
|
+
continuation_count?: number;
|
|
548
|
+
/** Token usage statistics */
|
|
549
|
+
usage?: {
|
|
550
|
+
prompt_tokens: number;
|
|
551
|
+
completion_tokens: number;
|
|
552
|
+
total_tokens: number;
|
|
553
|
+
};
|
|
554
|
+
/**
|
|
555
|
+
* Grounding metadata from Google Search (when google_search: true)
|
|
556
|
+
* Contains search queries, source URLs, and text-to-source mappings for citations
|
|
557
|
+
*/
|
|
558
|
+
grounding_metadata?: GroundingMetadata;
|
|
559
|
+
/**
|
|
560
|
+
* URL context metadata (when url_context: true)
|
|
561
|
+
* Contains info about which URLs were retrieved and their status
|
|
562
|
+
*/
|
|
563
|
+
url_context_metadata?: UrlContextMetadata;
|
|
564
|
+
/**
|
|
565
|
+
* Tool calls requested by the LLM (when tools are provided).
|
|
566
|
+
* In streaming mode, these are delivered via onToolCall callback.
|
|
567
|
+
* In non-streaming mode, they are included in the response.
|
|
568
|
+
*/
|
|
569
|
+
tool_calls?: ToolCall[];
|
|
570
|
+
/** @deprecated Use google_search_used instead */
|
|
571
|
+
web_search_used?: boolean;
|
|
572
|
+
}
|
|
316
573
|
/**
|
|
317
574
|
* SSE event types for LLM streaming
|
|
318
575
|
*/
|
|
319
576
|
interface LLMStreamEvent {
|
|
320
577
|
/** Event type */
|
|
321
|
-
type: 'token' | 'done' | 'error';
|
|
578
|
+
type: 'token' | 'done' | 'error' | 'tool_call';
|
|
322
579
|
/** Token content (for type: 'token') */
|
|
323
580
|
content?: string;
|
|
581
|
+
/** Tool call data (for type: 'tool_call') */
|
|
582
|
+
id?: string;
|
|
583
|
+
name?: string;
|
|
584
|
+
arguments?: Record<string, any>;
|
|
324
585
|
/** Complete result (for type: 'done') */
|
|
325
586
|
result?: string;
|
|
326
587
|
/** Model used (for type: 'done') */
|
|
@@ -655,11 +916,45 @@ interface BuiltInIntegration {
|
|
|
655
916
|
SendSMS(params: SMSParams): Promise<ServiceResponse>;
|
|
656
917
|
/**
|
|
657
918
|
* Invoke LLM for text/vision/file processing
|
|
658
|
-
*
|
|
919
|
+
*
|
|
920
|
+
* Features:
|
|
921
|
+
* - Multi-modal inputs: text, images, PDFs, videos, audio, YouTube URLs
|
|
922
|
+
* - Google Search grounding: Enable `google_search: true` for real-time web data
|
|
923
|
+
* - URL context: Enable `url_context: true` to have the model read URLs in your prompt
|
|
924
|
+
* - Streaming: Enable `stream: true` with callbacks for real-time token output
|
|
925
|
+
* - JSON output: Use `response_format: { type: 'json_object' }` for structured responses
|
|
926
|
+
*
|
|
927
|
+
* @param params - LLM parameters including messages, google_search, url_context, etc.
|
|
659
928
|
* @param options - Async options for handling long-running operations
|
|
660
|
-
* @returns
|
|
929
|
+
* @returns LLMResponse with result, grounding_metadata, and url_context_metadata
|
|
930
|
+
*
|
|
931
|
+
* @example Basic usage
|
|
932
|
+
* ```typescript
|
|
933
|
+
* const response = await InvokeLLM({ prompt: 'Hello, world!' });
|
|
934
|
+
* console.log(response.result);
|
|
935
|
+
* ```
|
|
936
|
+
*
|
|
937
|
+
* @example With Google Search grounding
|
|
938
|
+
* ```typescript
|
|
939
|
+
* const response = await InvokeLLM({
|
|
940
|
+
* prompt: 'What are the latest AI news?',
|
|
941
|
+
* google_search: true
|
|
942
|
+
* });
|
|
943
|
+
* console.log(response.result);
|
|
944
|
+
* console.log(response.grounding_metadata?.groundingChunks); // Source URLs
|
|
945
|
+
* ```
|
|
946
|
+
*
|
|
947
|
+
* @example With URL context
|
|
948
|
+
* ```typescript
|
|
949
|
+
* const response = await InvokeLLM({
|
|
950
|
+
* prompt: 'Summarize the content at https://example.com/article',
|
|
951
|
+
* url_context: true
|
|
952
|
+
* });
|
|
953
|
+
* console.log(response.result);
|
|
954
|
+
* console.log(response.url_context_metadata?.url_metadata); // Retrieval status
|
|
955
|
+
* ```
|
|
661
956
|
*/
|
|
662
|
-
InvokeLLM(params: LLMParams, options?: AsyncOptions): Promise<
|
|
957
|
+
InvokeLLM(params: LLMParams, options?: AsyncOptions): Promise<LLMResponse | AsyncJobCreatedResponse>;
|
|
663
958
|
UploadFile(params: {
|
|
664
959
|
file: File;
|
|
665
960
|
metadata?: Record<string, any>;
|
|
@@ -726,10 +1021,11 @@ interface AuthModule {
|
|
|
726
1021
|
*/
|
|
727
1022
|
me(): Promise<UserInfo>;
|
|
728
1023
|
/**
|
|
729
|
-
* Redirect to platform login page
|
|
730
|
-
*
|
|
1024
|
+
* Redirect to platform login page, or navigate directly if already authenticated.
|
|
1025
|
+
* Smart login: checks auth state first, only shows modal if not logged in.
|
|
1026
|
+
* @param returnPath - Path to return to after login (relative paths are resolved to absolute)
|
|
731
1027
|
*/
|
|
732
|
-
login(returnPath?: string): void
|
|
1028
|
+
login(returnPath?: string): void | Promise<void>;
|
|
733
1029
|
/**
|
|
734
1030
|
* Request a passwordless login code to email
|
|
735
1031
|
* @param email - User email
|
|
@@ -795,6 +1091,48 @@ interface AuthModule {
|
|
|
795
1091
|
*/
|
|
796
1092
|
onUserChange(callback: (user: UserInfo | null) => void): () => void;
|
|
797
1093
|
}
|
|
1094
|
+
/**
|
|
1095
|
+
* Connectors module interface for accessing external service tokens.
|
|
1096
|
+
* SECURITY: Only available via client.service for backend functions.
|
|
1097
|
+
*/
|
|
1098
|
+
interface ConnectorsModule {
|
|
1099
|
+
/**
|
|
1100
|
+
* Get access token for a connector (e.g., Slack, Google Calendar).
|
|
1101
|
+
* SECURITY: Only available in backend functions, not frontend code.
|
|
1102
|
+
*
|
|
1103
|
+
* @example
|
|
1104
|
+
* ```typescript
|
|
1105
|
+
* const omnikit = createServerClient(req);
|
|
1106
|
+
* const { access_token } = await omnikit.service.connectors.getAccessToken('slack');
|
|
1107
|
+
*
|
|
1108
|
+
* // Make direct Slack API call
|
|
1109
|
+
* await fetch('https://slack.com/api/chat.postMessage', {
|
|
1110
|
+
* headers: { Authorization: `Bearer ${access_token}` },
|
|
1111
|
+
* body: JSON.stringify({ channel: '#general', text: 'Hello!' })
|
|
1112
|
+
* });
|
|
1113
|
+
* ```
|
|
1114
|
+
*/
|
|
1115
|
+
getAccessToken(connectorType: string): Promise<{
|
|
1116
|
+
success: boolean;
|
|
1117
|
+
access_token: string;
|
|
1118
|
+
connector_type: string;
|
|
1119
|
+
external_workspace_id?: string;
|
|
1120
|
+
external_workspace_name?: string;
|
|
1121
|
+
}>;
|
|
1122
|
+
/** Check if a connector is connected */
|
|
1123
|
+
isConnected(connectorType: string): Promise<boolean>;
|
|
1124
|
+
/** Get connector status */
|
|
1125
|
+
getStatus(connectorType: string): Promise<{
|
|
1126
|
+
success: boolean;
|
|
1127
|
+
connector?: {
|
|
1128
|
+
connector_type: string;
|
|
1129
|
+
status: string;
|
|
1130
|
+
external_workspace_id?: string;
|
|
1131
|
+
external_workspace_name?: string;
|
|
1132
|
+
external_user_email?: string;
|
|
1133
|
+
};
|
|
1134
|
+
}>;
|
|
1135
|
+
}
|
|
798
1136
|
/**
|
|
799
1137
|
* Service role client interface (elevated admin operations)
|
|
800
1138
|
* Available when serviceToken is provided in config
|
|
@@ -808,6 +1146,17 @@ interface ServiceRoleClient {
|
|
|
808
1146
|
services: Record<string, IntegrationMethod>;
|
|
809
1147
|
/** @deprecated Use services instead. Integration operations with service role privileges */
|
|
810
1148
|
integrations: Record<string, Record<string, IntegrationMethod>>;
|
|
1149
|
+
/**
|
|
1150
|
+
* Connectors module for accessing external service tokens (Slack, Google Calendar, etc.)
|
|
1151
|
+
* SECURITY: Only available via client.service for backend functions.
|
|
1152
|
+
*
|
|
1153
|
+
* @example
|
|
1154
|
+
* ```typescript
|
|
1155
|
+
* const omnikit = createServerClient(req);
|
|
1156
|
+
* const { access_token } = await omnikit.service.connectors.getAccessToken('slack');
|
|
1157
|
+
* ```
|
|
1158
|
+
*/
|
|
1159
|
+
connectors: ConnectorsModule;
|
|
811
1160
|
}
|
|
812
1161
|
/**
|
|
813
1162
|
* Main Omnikit Client interface
|
|
@@ -867,11 +1216,36 @@ interface OmnikitClient {
|
|
|
867
1216
|
/** Authentication methods */
|
|
868
1217
|
auth: AuthModule;
|
|
869
1218
|
/**
|
|
870
|
-
* Service
|
|
871
|
-
* Only available when serviceToken is provided
|
|
872
|
-
* Throws error if accessed without serviceToken
|
|
1219
|
+
* Service-level operations (elevated privileges).
|
|
1220
|
+
* Only available when serviceToken is provided (e.g., via createServerClient).
|
|
1221
|
+
* Throws error if accessed without serviceToken.
|
|
1222
|
+
*
|
|
1223
|
+
* @example
|
|
1224
|
+
* ```typescript
|
|
1225
|
+
* // In a backend function
|
|
1226
|
+
* const omnikit = createServerClient(req);
|
|
1227
|
+
* const { access_token } = await omnikit.service.connectors.getAccessToken('slack');
|
|
1228
|
+
* ```
|
|
1229
|
+
*/
|
|
1230
|
+
service?: ServiceRoleClient;
|
|
1231
|
+
/**
|
|
1232
|
+
* @deprecated Use service instead. Will be removed in next major version.
|
|
873
1233
|
*/
|
|
874
1234
|
asServiceRole?: ServiceRoleClient;
|
|
1235
|
+
/**
|
|
1236
|
+
* Connectors module for accessing external service tokens.
|
|
1237
|
+
*
|
|
1238
|
+
* SECURITY: getAccessToken requires service token authentication.
|
|
1239
|
+
* Prefer using omnikit.service.connectors in backend functions.
|
|
1240
|
+
*
|
|
1241
|
+
* @example
|
|
1242
|
+
* ```typescript
|
|
1243
|
+
* // In a backend function (using service role)
|
|
1244
|
+
* const omnikit = createServerClient(req);
|
|
1245
|
+
* const { access_token } = await omnikit.service.connectors.getAccessToken('slack');
|
|
1246
|
+
* ```
|
|
1247
|
+
*/
|
|
1248
|
+
connectors: ConnectorsModule;
|
|
875
1249
|
/** @internal */
|
|
876
1250
|
getAppMetadata(): Promise<AppSchema>;
|
|
877
1251
|
/** @internal */
|
|
@@ -1183,6 +1557,7 @@ declare class APIClient implements OmnikitClient {
|
|
|
1183
1557
|
private _integrations;
|
|
1184
1558
|
private _auth;
|
|
1185
1559
|
private _asServiceRole?;
|
|
1560
|
+
private _connectors?;
|
|
1186
1561
|
private _metadata;
|
|
1187
1562
|
private _metadataListeners;
|
|
1188
1563
|
private _userListeners;
|
|
@@ -1269,10 +1644,42 @@ declare class APIClient implements OmnikitClient {
|
|
|
1269
1644
|
*/
|
|
1270
1645
|
get auth(): AuthModule;
|
|
1271
1646
|
/**
|
|
1272
|
-
*
|
|
1273
|
-
* Only available when serviceToken is provided
|
|
1647
|
+
* Service-level operations (elevated privileges).
|
|
1648
|
+
* Only available when serviceToken is provided (e.g., via createServerClient).
|
|
1649
|
+
*/
|
|
1650
|
+
get service(): ServiceRoleClient;
|
|
1651
|
+
/**
|
|
1652
|
+
* @deprecated Use service instead
|
|
1274
1653
|
*/
|
|
1275
1654
|
get asServiceRole(): ServiceRoleClient;
|
|
1655
|
+
/**
|
|
1656
|
+
* Lazy getter for connectors module
|
|
1657
|
+
* Like Base44's connectors - provides access to external service tokens
|
|
1658
|
+
*
|
|
1659
|
+
* SECURITY: getAccessToken requires service token authentication.
|
|
1660
|
+
* Only use in backend functions, not frontend code.
|
|
1661
|
+
*
|
|
1662
|
+
* @example
|
|
1663
|
+
* ```typescript
|
|
1664
|
+
* // In a backend function
|
|
1665
|
+
* const { access_token } = await omnikit.connectors.getAccessToken('slack');
|
|
1666
|
+
*
|
|
1667
|
+
* // Make direct Slack API call
|
|
1668
|
+
* const response = await fetch('https://slack.com/api/chat.postMessage', {
|
|
1669
|
+
* method: 'POST',
|
|
1670
|
+
* headers: { Authorization: `Bearer ${access_token}` },
|
|
1671
|
+
* body: JSON.stringify({ channel: '#general', text: 'Hello!' })
|
|
1672
|
+
* });
|
|
1673
|
+
* ```
|
|
1674
|
+
*/
|
|
1675
|
+
get connectors(): ConnectorsModule$1;
|
|
1676
|
+
/**
|
|
1677
|
+
* Resolve a return URL to an absolute URL.
|
|
1678
|
+
* Handles relative paths like "/profile" by combining with current location.
|
|
1679
|
+
* This fixes the OAuth redirect bug where relative URLs like "/profile" become
|
|
1680
|
+
* "https://omnikit.ai/profile" instead of "https://omnikit.ai/app-builder/{id}/preview/profile"
|
|
1681
|
+
*/
|
|
1682
|
+
private _resolveReturnUrl;
|
|
1276
1683
|
/**
|
|
1277
1684
|
* Create auth proxy that auto-initializes
|
|
1278
1685
|
*/
|
|
@@ -1480,6 +1887,60 @@ declare class APIClient implements OmnikitClient {
|
|
|
1480
1887
|
* ```
|
|
1481
1888
|
*/
|
|
1482
1889
|
declare function createClient(config: OmnikitConfig): OmnikitClient;
|
|
1890
|
+
/**
|
|
1891
|
+
* Request object interface for createServerClient.
|
|
1892
|
+
* Matches Deno/Node HTTP request interface.
|
|
1893
|
+
*/
|
|
1894
|
+
interface ServerRequest {
|
|
1895
|
+
headers: {
|
|
1896
|
+
get?(name: string): string | null;
|
|
1897
|
+
[key: string]: any;
|
|
1898
|
+
};
|
|
1899
|
+
}
|
|
1900
|
+
/**
|
|
1901
|
+
* Create an Omnikit client for server-side (backend function) use.
|
|
1902
|
+
*
|
|
1903
|
+
* Extracts authentication tokens from HTTP headers injected by the Omnikit platform:
|
|
1904
|
+
* - Authorization: Bearer <user_jwt> (identifies the user making the request)
|
|
1905
|
+
* - X-Omnikit-Service-Authorization: <service_token> (for privileged operations)
|
|
1906
|
+
* - X-Omnikit-App-Id: <app_id> (identifies the app)
|
|
1907
|
+
* - X-Omnikit-Server-Url: <server_url> (API server URL)
|
|
1908
|
+
*
|
|
1909
|
+
* SECURITY: The service token is injected at runtime by the platform,
|
|
1910
|
+
* ensuring it cannot be leaked through source code.
|
|
1911
|
+
*
|
|
1912
|
+
* @example
|
|
1913
|
+
* ```typescript
|
|
1914
|
+
* // In a backend function (Deno Edge Function)
|
|
1915
|
+
* import { createServerClient } from '@omnikit-ai/sdk';
|
|
1916
|
+
*
|
|
1917
|
+
* Deno.serve(async (req) => {
|
|
1918
|
+
* const omnikit = createServerClient(req);
|
|
1919
|
+
*
|
|
1920
|
+
* // Access user data (user JWT auth)
|
|
1921
|
+
* const currentUser = await omnikit.auth.me();
|
|
1922
|
+
*
|
|
1923
|
+
* // Access connectors (requires service token)
|
|
1924
|
+
* const { access_token } = await omnikit.service.connectors.getAccessToken('slack');
|
|
1925
|
+
*
|
|
1926
|
+
* // Make direct Slack API call
|
|
1927
|
+
* await fetch('https://slack.com/api/chat.postMessage', {
|
|
1928
|
+
* headers: { Authorization: `Bearer ${access_token}` },
|
|
1929
|
+
* body: JSON.stringify({ channel: '#general', text: `Hello from ${currentUser.email}!` })
|
|
1930
|
+
* });
|
|
1931
|
+
*
|
|
1932
|
+
* return new Response(JSON.stringify({ success: true }));
|
|
1933
|
+
* });
|
|
1934
|
+
* ```
|
|
1935
|
+
*
|
|
1936
|
+
* @param request - HTTP request object with headers
|
|
1937
|
+
* @returns Omnikit client configured with tokens from headers
|
|
1938
|
+
*/
|
|
1939
|
+
declare function createServerClient(request: ServerRequest): OmnikitClient;
|
|
1940
|
+
/**
|
|
1941
|
+
* @deprecated Use createServerClient instead
|
|
1942
|
+
*/
|
|
1943
|
+
declare const createClientFromRequest: typeof createServerClient;
|
|
1483
1944
|
|
|
1484
1945
|
/**
|
|
1485
1946
|
* Live Voice Session Implementation
|
|
@@ -1561,4 +2022,103 @@ declare class LiveVoiceSessionImpl implements LiveVoiceSession {
|
|
|
1561
2022
|
private cleanup;
|
|
1562
2023
|
}
|
|
1563
2024
|
|
|
1564
|
-
|
|
2025
|
+
/**
|
|
2026
|
+
* Omnikit Analytics Module
|
|
2027
|
+
*
|
|
2028
|
+
* Provides automatic event tracking for generated apps.
|
|
2029
|
+
* Supports page views, errors, auth events, and custom events.
|
|
2030
|
+
*
|
|
2031
|
+
* @example
|
|
2032
|
+
* ```typescript
|
|
2033
|
+
* import { Analytics } from '@omnikit/sdk';
|
|
2034
|
+
*
|
|
2035
|
+
* const analytics = new Analytics({
|
|
2036
|
+
* appId: 'your-app-id',
|
|
2037
|
+
* apiUrl: 'https://api.omnikit.ai'
|
|
2038
|
+
* });
|
|
2039
|
+
*
|
|
2040
|
+
* // Log events
|
|
2041
|
+
* analytics.logPageView('/dashboard');
|
|
2042
|
+
* analytics.logEvent('button_click', { action: 'submit' });
|
|
2043
|
+
* ```
|
|
2044
|
+
*/
|
|
2045
|
+
interface EventPayload {
|
|
2046
|
+
page_name?: string;
|
|
2047
|
+
action?: string;
|
|
2048
|
+
inputs?: Record<string, any>;
|
|
2049
|
+
metadata?: Record<string, any>;
|
|
2050
|
+
error_message?: string;
|
|
2051
|
+
error_stack?: string;
|
|
2052
|
+
}
|
|
2053
|
+
interface AnalyticsConfig {
|
|
2054
|
+
appId: string;
|
|
2055
|
+
apiUrl: string;
|
|
2056
|
+
sessionId?: string;
|
|
2057
|
+
userId?: string;
|
|
2058
|
+
enabled?: boolean;
|
|
2059
|
+
}
|
|
2060
|
+
declare class Analytics {
|
|
2061
|
+
private config;
|
|
2062
|
+
private sessionId;
|
|
2063
|
+
private userId?;
|
|
2064
|
+
private eventQueue;
|
|
2065
|
+
private flushTimer?;
|
|
2066
|
+
private enabled;
|
|
2067
|
+
constructor(config: AnalyticsConfig);
|
|
2068
|
+
private initSession;
|
|
2069
|
+
private generateId;
|
|
2070
|
+
private saveSession;
|
|
2071
|
+
/**
|
|
2072
|
+
* Get the current session ID
|
|
2073
|
+
*/
|
|
2074
|
+
getSessionId(): string;
|
|
2075
|
+
/**
|
|
2076
|
+
* Start a new session (e.g., after logout)
|
|
2077
|
+
*/
|
|
2078
|
+
startNewSession(): string;
|
|
2079
|
+
/**
|
|
2080
|
+
* Associate events with a user ID
|
|
2081
|
+
*/
|
|
2082
|
+
setUserId(userId: string): void;
|
|
2083
|
+
/**
|
|
2084
|
+
* Clear user association (e.g., on logout)
|
|
2085
|
+
*/
|
|
2086
|
+
clearUserId(): void;
|
|
2087
|
+
/**
|
|
2088
|
+
* Log a custom event
|
|
2089
|
+
*/
|
|
2090
|
+
logEvent(eventType: string, payload?: EventPayload): Promise<void>;
|
|
2091
|
+
/**
|
|
2092
|
+
* Log a page view event
|
|
2093
|
+
*/
|
|
2094
|
+
logPageView(pageName: string, metadata?: Record<string, any>): Promise<void>;
|
|
2095
|
+
/**
|
|
2096
|
+
* Log an error event
|
|
2097
|
+
*/
|
|
2098
|
+
logError(error: Error, componentStack?: string): Promise<void>;
|
|
2099
|
+
/**
|
|
2100
|
+
* Log an API error event
|
|
2101
|
+
*/
|
|
2102
|
+
logApiError(endpoint: string, statusCode: number, errorMessage: string, metadata?: Record<string, any>): Promise<void>;
|
|
2103
|
+
private startFlushTimer;
|
|
2104
|
+
/**
|
|
2105
|
+
* Flush all queued events to the server
|
|
2106
|
+
*/
|
|
2107
|
+
flush(): Promise<void>;
|
|
2108
|
+
private sendEvent;
|
|
2109
|
+
/**
|
|
2110
|
+
* Enable or disable analytics
|
|
2111
|
+
*/
|
|
2112
|
+
setEnabled(enabled: boolean): void;
|
|
2113
|
+
/**
|
|
2114
|
+
* Check if analytics is enabled
|
|
2115
|
+
*/
|
|
2116
|
+
isEnabled(): boolean;
|
|
2117
|
+
/**
|
|
2118
|
+
* Clean up resources
|
|
2119
|
+
*/
|
|
2120
|
+
destroy(): void;
|
|
2121
|
+
}
|
|
2122
|
+
declare function createAnalytics(config: AnalyticsConfig): Analytics;
|
|
2123
|
+
|
|
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 };
|