@ikonai/sdk 0.0.10 → 0.0.11
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/channel/channel-manager.d.ts +0 -4
- package/client/ikon-client-config.d.ts +30 -21
- package/connection/authenticator.d.ts +13 -25
- package/connection/urls.d.ts +60 -0
- package/functions/types.d.ts +3 -2
- package/index.d.ts +3 -1
- package/index.js +1236 -987
- package/package.json +1 -1
- package/storage.d.ts +20 -0
- package/utils/delay.d.ts +7 -0
- package/utils/logger.d.ts +0 -5
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { ProtocolMessage } from '../../../../shared/generated/src/index.ts';
|
|
2
|
+
import { BackendType } from '../connection/urls';
|
|
2
3
|
import { ConnectionState } from './connection-state';
|
|
3
|
-
|
|
4
|
-
* Backend environment type.
|
|
5
|
-
*/
|
|
6
|
-
export type BackendType = 'production' | 'development';
|
|
4
|
+
export type { BackendType };
|
|
7
5
|
/**
|
|
8
6
|
* Common connection options shared across all modes.
|
|
9
7
|
*/
|
|
@@ -70,7 +68,7 @@ export interface LocalConfig extends CommonConnectionConfig {
|
|
|
70
68
|
userId?: string;
|
|
71
69
|
}
|
|
72
70
|
/**
|
|
73
|
-
* Common options for cloud-based modes (
|
|
71
|
+
* Common options for cloud-based modes (apiKey and sessionToken).
|
|
74
72
|
*/
|
|
75
73
|
export interface CloudConnectionConfig extends CommonConnectionConfig {
|
|
76
74
|
/**
|
|
@@ -89,14 +87,6 @@ export interface CloudConnectionConfig extends CommonConnectionConfig {
|
|
|
89
87
|
*/
|
|
90
88
|
provisioningTimeoutMs?: number;
|
|
91
89
|
}
|
|
92
|
-
/**
|
|
93
|
-
* Configuration for browser authentication mode.
|
|
94
|
-
* Use this when the app is hosted on Ikon's domain and user is logged in via browser.
|
|
95
|
-
* Space is auto-discovered from the hostname subdomain.
|
|
96
|
-
* User identity comes from the browser session cookie.
|
|
97
|
-
*/
|
|
98
|
-
export interface BrowserConfig extends CloudConnectionConfig {
|
|
99
|
-
}
|
|
100
90
|
/**
|
|
101
91
|
* Configuration for API key authentication mode.
|
|
102
92
|
* Use this for programmatic/library access to cloud channels.
|
|
@@ -118,8 +108,8 @@ export interface ApiKeyConfig extends CloudConnectionConfig {
|
|
|
118
108
|
externalUserId: string;
|
|
119
109
|
/**
|
|
120
110
|
* Backend environment. Defaults to 'production'.
|
|
121
|
-
* - 'production' →
|
|
122
|
-
* - 'development' →
|
|
111
|
+
* - 'production' → IKON_BACKEND_URL_PROD
|
|
112
|
+
* - 'development' → IKON_BACKEND_URL_DEV
|
|
123
113
|
*/
|
|
124
114
|
backendType?: BackendType;
|
|
125
115
|
/**
|
|
@@ -135,6 +125,25 @@ export interface ApiKeyConfig extends CloudConnectionConfig {
|
|
|
135
125
|
*/
|
|
136
126
|
clientType?: number;
|
|
137
127
|
}
|
|
128
|
+
/**
|
|
129
|
+
* Configuration for session token authentication mode.
|
|
130
|
+
* Use this when the session token was obtained from IKON_AUTH_BASE_URL (OAuth) or /auth/anonymous.
|
|
131
|
+
* The JWT token already contains the internal userId - no additional mapping needed.
|
|
132
|
+
*/
|
|
133
|
+
export interface SessionTokenConfig extends CloudConnectionConfig {
|
|
134
|
+
/**
|
|
135
|
+
* JWT token from IKON_AUTH_BASE_URL or /auth/anonymous (contains internal userId).
|
|
136
|
+
*/
|
|
137
|
+
token: string;
|
|
138
|
+
/**
|
|
139
|
+
* Space ID (from ikon-config.json, injected at build time).
|
|
140
|
+
*/
|
|
141
|
+
spaceId: string;
|
|
142
|
+
/**
|
|
143
|
+
* Backend environment. Defaults to 'production'.
|
|
144
|
+
*/
|
|
145
|
+
backendType?: BackendType;
|
|
146
|
+
}
|
|
138
147
|
/**
|
|
139
148
|
* Timeout configuration for the SDK.
|
|
140
149
|
*/
|
|
@@ -175,17 +184,17 @@ export interface IkonClientConfig {
|
|
|
175
184
|
* Use this when connecting to a local Ikon server.
|
|
176
185
|
*/
|
|
177
186
|
local?: LocalConfig;
|
|
178
|
-
/**
|
|
179
|
-
* Browser-based authentication.
|
|
180
|
-
* Use this when the app is hosted on Ikon's domain and user is logged in via browser.
|
|
181
|
-
* Space is auto-discovered from hostname subdomain.
|
|
182
|
-
*/
|
|
183
|
-
browser?: BrowserConfig;
|
|
184
187
|
/**
|
|
185
188
|
* API key authentication for programmatic access.
|
|
186
189
|
* Use this for libraries, scripts, plugins that need to connect to cloud channels.
|
|
187
190
|
*/
|
|
188
191
|
apiKey?: ApiKeyConfig;
|
|
192
|
+
/**
|
|
193
|
+
* Session token authentication for frontend apps.
|
|
194
|
+
* Use this when the token was obtained from IKON_AUTH_BASE_URL (OAuth) or /auth/anonymous.
|
|
195
|
+
* The token already contains the internal userId.
|
|
196
|
+
*/
|
|
197
|
+
sessionToken?: SessionTokenConfig;
|
|
189
198
|
/**
|
|
190
199
|
* Timeout configuration.
|
|
191
200
|
*/
|
|
@@ -1,23 +1,11 @@
|
|
|
1
1
|
import { AuthResponse } from '../../../../shared/generated/src/index.ts';
|
|
2
|
-
import { ApiKeyConfig,
|
|
2
|
+
import { ApiKeyConfig, LocalConfig, SessionTokenConfig } from '../client/ikon-client-config';
|
|
3
3
|
/**
|
|
4
4
|
* Result of authentication - contains the AuthResponse from the server.
|
|
5
5
|
*/
|
|
6
6
|
export interface AuthResult {
|
|
7
7
|
authResponse: AuthResponse;
|
|
8
8
|
}
|
|
9
|
-
/**
|
|
10
|
-
* Derive backend API URL from window.location.hostname.
|
|
11
|
-
* - If hostname contains '.dev.' → https://api.dev.ikon.live
|
|
12
|
-
* - Otherwise → https://api.prod.ikon.live
|
|
13
|
-
*/
|
|
14
|
-
export declare function deriveBackendUrl(): string;
|
|
15
|
-
/**
|
|
16
|
-
* Extract space domain from hostname.
|
|
17
|
-
* - First checks VITE_IKON_SPACE_DOMAIN env variable (via import.meta.env)
|
|
18
|
-
* - Otherwise extracts first subdomain: myapp.dev.ikon.live → myapp
|
|
19
|
-
*/
|
|
20
|
-
export declare function deriveSpaceDomain(): string;
|
|
21
9
|
/**
|
|
22
10
|
* Authenticate with a local Ikon server in development mode.
|
|
23
11
|
*
|
|
@@ -26,18 +14,6 @@ export declare function deriveSpaceDomain(): string;
|
|
|
26
14
|
* 2. GET /connect?token=jwt → get binary AuthResponse
|
|
27
15
|
*/
|
|
28
16
|
export declare function authenticateLocal(config: LocalConfig, signal?: AbortSignal): Promise<AuthResult>;
|
|
29
|
-
/**
|
|
30
|
-
* Authenticate with the Ikon backend using browser session cookies.
|
|
31
|
-
*
|
|
32
|
-
* Flow:
|
|
33
|
-
* 1. Parse URL query parameters (id → sessionId, ck → channelKey, all → parameters)
|
|
34
|
-
* 2. Derive backend URL and space domain from hostname
|
|
35
|
-
* 3. Fetch space info by domain
|
|
36
|
-
* 4. Request channel
|
|
37
|
-
* 5. POST /rooms/connect and poll until running
|
|
38
|
-
* 6. Connect to the returned Ikon server URL
|
|
39
|
-
*/
|
|
40
|
-
export declare function authenticateBrowser(config: BrowserConfig, signal?: AbortSignal): Promise<AuthResult>;
|
|
41
17
|
/**
|
|
42
18
|
* Authenticate with the Ikon backend using an API key.
|
|
43
19
|
*
|
|
@@ -50,3 +26,15 @@ export declare function authenticateBrowser(config: BrowserConfig, signal?: Abor
|
|
|
50
26
|
* 6. Connect to the returned Ikon server URL
|
|
51
27
|
*/
|
|
52
28
|
export declare function authenticateApiKey(config: ApiKeyConfig, signal?: AbortSignal): Promise<AuthResult>;
|
|
29
|
+
/**
|
|
30
|
+
* Authenticate with the Ikon backend using a pre-obtained session token.
|
|
31
|
+
* Use this when the token was obtained from auth.ikonai.com (OAuth) or /auth/anonymous.
|
|
32
|
+
*
|
|
33
|
+
* Flow:
|
|
34
|
+
* 1. Use provided token as Bearer auth for backend requests
|
|
35
|
+
* 2. GET /profiles/me?space={spaceId} to verify profile exists
|
|
36
|
+
* 3. Request channel
|
|
37
|
+
* 4. POST /rooms/connect and poll until running
|
|
38
|
+
* 5. Connect to the returned Ikon server URL
|
|
39
|
+
*/
|
|
40
|
+
export declare function authenticateSessionToken(config: SessionTokenConfig, signal?: AbortSignal): Promise<AuthResult>;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ikon platform URL constants and utilities.
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Backend environment type.
|
|
6
|
+
*/
|
|
7
|
+
export type BackendType = 'production' | 'development';
|
|
8
|
+
export declare const IKON_BACKEND_URL_PROD = "https://api.prod.ikon.live";
|
|
9
|
+
export declare const IKON_BACKEND_URL_DEV = "https://api.dev.ikon.live";
|
|
10
|
+
export declare const IKON_AUTH_BASE_URL = "https://auth.ikonai.com";
|
|
11
|
+
/**
|
|
12
|
+
* Get backend URL from BackendType.
|
|
13
|
+
*/
|
|
14
|
+
export declare function getBackendUrl(backendType?: BackendType): string;
|
|
15
|
+
/**
|
|
16
|
+
* Derive backend API URL from window.location.hostname.
|
|
17
|
+
* - If hostname contains '.dev.' → IKON_BACKEND_URL_DEV
|
|
18
|
+
* - Otherwise → IKON_BACKEND_URL_PROD
|
|
19
|
+
*/
|
|
20
|
+
export declare function deriveBackendUrl(): string;
|
|
21
|
+
/**
|
|
22
|
+
* Derive backend type from environment or window.location.hostname.
|
|
23
|
+
* - If VITE_IKON_BASE_URL env var contains '.dev.' → 'development'
|
|
24
|
+
* - If hostname contains '.dev.' → 'development'
|
|
25
|
+
* - Otherwise → 'production'
|
|
26
|
+
*/
|
|
27
|
+
export declare function deriveBackendType(): BackendType;
|
|
28
|
+
/**
|
|
29
|
+
* Parse URL query parameters.
|
|
30
|
+
*/
|
|
31
|
+
export declare function parseQueryParams(): Record<string, string>;
|
|
32
|
+
/**
|
|
33
|
+
* Result of parsing URL path and query parameters.
|
|
34
|
+
*/
|
|
35
|
+
export interface UrlParams {
|
|
36
|
+
sessionId?: string;
|
|
37
|
+
channelKey?: string;
|
|
38
|
+
parameters: Record<string, string>;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Parse URL path and query parameters for browser authentication.
|
|
42
|
+
*
|
|
43
|
+
* URL path patterns:
|
|
44
|
+
* - /s/[sessionId] → sessionId
|
|
45
|
+
* - /c/[channelKey] → channelKey
|
|
46
|
+
*
|
|
47
|
+
* Query parameters → parameters dict (excluding OAuth-reserved params)
|
|
48
|
+
*
|
|
49
|
+
* @throws Error if both sessionId and channelKey are in the URL path
|
|
50
|
+
*/
|
|
51
|
+
export declare function parseUrlParams(): UrlParams;
|
|
52
|
+
/**
|
|
53
|
+
* Check if running in a cloud environment (not localhost or local network).
|
|
54
|
+
* Returns false for:
|
|
55
|
+
* - localhost and 127.0.0.1
|
|
56
|
+
* - IPv6 localhost (::1)
|
|
57
|
+
* - Private network ranges (192.168.x.x, 10.x.x.x, 172.16-31.x.x)
|
|
58
|
+
* - SSR (typeof window === 'undefined')
|
|
59
|
+
*/
|
|
60
|
+
export declare function isCloudEnvironment(): boolean;
|
package/functions/types.d.ts
CHANGED
|
@@ -38,8 +38,9 @@ export interface FunctionParameterDefinition {
|
|
|
38
38
|
export interface FunctionDefinition {
|
|
39
39
|
name: string;
|
|
40
40
|
description?: string;
|
|
41
|
-
|
|
42
|
-
|
|
41
|
+
llmInlineResult?: boolean;
|
|
42
|
+
llmCallOnlyOnce?: boolean;
|
|
43
|
+
requiresInstance?: boolean;
|
|
43
44
|
returnType: ValueDescriptor;
|
|
44
45
|
parameters?: FunctionParameterDefinition[];
|
|
45
46
|
}
|
package/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { IkonClient, type ProtocolMessageHandler, type StateHandler } from './client/ikon-client';
|
|
2
|
-
export type { IkonClientConfig, LocalConfig,
|
|
2
|
+
export type { IkonClientConfig, LocalConfig, ApiKeyConfig, SessionTokenConfig, CloudConnectionConfig, CommonConnectionConfig, TimeoutConfig, BackendType } from './client/ikon-client-config';
|
|
3
3
|
export type { ConnectionState } from './client/connection-state';
|
|
4
4
|
export { isConnecting, isConnected, isOffline, isError } from './client/connection-state';
|
|
5
5
|
export { ChannelManager, type ChannelManagerConfig, type ChannelManagerState } from './channel/channel-manager';
|
|
@@ -16,3 +16,5 @@ export { initializeLogSink, setSendLogsCallback, getBufferedLogs, takeBufferedLo
|
|
|
16
16
|
export type { LogSinkConfig } from './utils/logSink';
|
|
17
17
|
export { FunctionRegistry, registerBrowserFunctions, isBrowserEnvironment, type FunctionRegistryConfig } from './functions';
|
|
18
18
|
export type { ValueDescriptor, NormalizedValueDescriptor, PrimitiveValueKind, FunctionParameterDefinition, FunctionDefinition, FunctionHandler } from './functions';
|
|
19
|
+
export { IKON_AUTH_BASE_URL, IKON_BACKEND_URL_PROD, IKON_BACKEND_URL_DEV, deriveBackendUrl, deriveBackendType, parseUrlParams, isCloudEnvironment, type UrlParams } from './connection/urls';
|
|
20
|
+
export { getOrCreateDeviceId, clearDeviceId, extractUserIdFromToken } from './storage';
|