@ikonai/sdk 1.0.44 → 1.0.45

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.
@@ -33,6 +33,12 @@ export interface ChannelManagerConfig {
33
33
  * Useful for worker environments where localStorage might be unavailable.
34
34
  */
35
35
  orderedEndpointTypes?: EntrypointType[];
36
+ /**
37
+ * True when the user has explicitly constrained the allowed transports via
38
+ * `proxy`, `websocket`, or `webtransport` settings. When set, unstable types
39
+ * are not demoted on reconnect — the user's transport choice is respected.
40
+ */
41
+ hasTransportConstraint?: boolean;
36
42
  /**
37
43
  * Called when a working endpoint type is discovered.
38
44
  * Typically used by the host to persist endpoint preference.
@@ -55,6 +61,15 @@ export interface ChannelManagerConfig {
55
61
  * WebRTC-type entrypoints are filtered out (they are signal-only, not real channels).
56
62
  */
57
63
  webRtcEnabled?: boolean;
64
+ /**
65
+ * Called during transport fallback when a partial connection occurred.
66
+ * Returns fresh entrypoints from a new /connect call so the next transport
67
+ * type uses a clean server session with no stale channel state.
68
+ */
69
+ onRefreshEntrypoints?: () => Promise<{
70
+ entrypoints: Entrypoint[];
71
+ sessionId: number;
72
+ }>;
58
73
  }
59
74
  /**
60
75
  * ChannelManager orchestrates multiple channels to an Ikon server.
@@ -29,6 +29,13 @@ export declare class EndpointSelector {
29
29
  });
30
30
  get proxyMode(): ProxyMode;
31
31
  get proxyPreferred(): boolean;
32
+ /**
33
+ * True when the user has explicitly narrowed the set of allowed transports
34
+ * via `proxy`, `websocket`, or `webtransport` settings. In that case the SDK
35
+ * should respect the user's choice rather than silently reordering types
36
+ * (e.g. demoting an "unstable" type on transient failure).
37
+ */
38
+ get hasTransportConstraint(): boolean;
32
39
  /**
33
40
  * Mark proxy as preferred and persist to localStorage.
34
41
  * Called by IkonClient when auth-level proxy fallback succeeds in auto mode.
@@ -177,7 +177,7 @@ export interface TimeoutConfig {
177
177
  slowConnectionThresholdMs?: number;
178
178
  /**
179
179
  * Duration in milliseconds before giving up and showing offline.
180
- * Default: 60000 (60 seconds)
180
+ * Default: 180000 (3 minutes)
181
181
  */
182
182
  connectionTimeoutMs?: number;
183
183
  /**
@@ -351,7 +351,7 @@ export interface IkonClientConfig {
351
351
  proxy?: boolean;
352
352
  }
353
353
  export declare const DEFAULT_SLOW_CONNECTION_THRESHOLD_MS = 5000;
354
- export declare const DEFAULT_CONNECTION_TIMEOUT_MS = 60000;
354
+ export declare const DEFAULT_CONNECTION_TIMEOUT_MS = 180000;
355
355
  export declare const DEFAULT_KEEPALIVE_TIMEOUT_MS = 15000;
356
356
  export declare const DEFAULT_RECONNECT_BACKOFF_MS = 2000;
357
357
  export declare const DEFAULT_MAX_RECONNECT_ATTEMPTS = 2;
@@ -90,8 +90,10 @@ export type StateHandler = (state: ConnectionState) => void;
90
90
  export declare class IkonClient {
91
91
  private channelManager;
92
92
  private protocolWorker;
93
+ private preloadedWorker;
93
94
  private workerManagerState;
94
95
  private authResponse;
96
+ private _connectUrl;
95
97
  private currentState;
96
98
  private slowConnectionTimer;
97
99
  private connectionTimer;
@@ -119,6 +121,7 @@ export declare class IkonClient {
119
121
  private unregisterBrowserFunctions;
120
122
  private unregisterMediaCaptureFunctions;
121
123
  private unregisterSoundFunctions;
124
+ private unregisterLoginInterceptor;
122
125
  private nextProtocolPortId;
123
126
  private nextProtocolSendPortId;
124
127
  private readonly _audioEnabled;
@@ -130,6 +133,7 @@ export declare class IkonClient {
130
133
  private _webRtcAudioStreams;
131
134
  private _webRtcVideoStreams;
132
135
  private _webRtcTrackMap;
136
+ private _pendingActiveAudioTracks;
133
137
  private _keepaliveLockAbort;
134
138
  private _fullReauthAttempted;
135
139
  private _softReconnectAttempted;
@@ -310,10 +314,9 @@ export declare class IkonClient {
310
314
  private setupWebRtcSignaling;
311
315
  private _webRtcAudioUnlockHandler;
312
316
  private readonly _webRtcMediaSession;
313
- private ensureWebRtcAudioElement;
314
- private playWebRtcAudioTrack;
317
+ private createWebRtcAudioElement;
318
+ private destroyWebRtcAudioElement;
315
319
  private ensureWebRtcAudioUnlockHandler;
316
- private stopWebRtcAudioTrack;
317
320
  private setupWebRtcMediaSession;
318
321
  private removeWebRtcAudioUnlockHandler;
319
322
  private connectProtocolOnMainThread;
@@ -15,6 +15,7 @@ export declare const IKON_AUTH_URL_DEV = "https://auth.dev.ikonai.com";
15
15
  export declare const IKON_AUTH_BASE_URL = "https://auth.ikonai.com";
16
16
  /**
17
17
  * Get backend URL from BackendType.
18
+ * Honors ?ikon-api=true by routing through the same-origin /ikon/api path.
18
19
  */
19
20
  export declare function getBackendUrl(backendType?: BackendType): string;
20
21
  /**
@@ -22,9 +23,10 @@ export declare function getBackendUrl(backendType?: BackendType): string;
22
23
  * Priority:
23
24
  * 1. Explicit override (e.g. from config)
24
25
  * 2. VITE_IKON_BACKEND_URL env var (set by .NET server during local dev)
25
- * 3. Local environment (localhost, LAN IPs) → IKON_BACKEND_URL_DEV
26
- * 4. Hostname contains '.dev.' → IKON_BACKEND_URL_DEV
27
- * 5. DefaultIKON_BACKEND_URL_PROD
26
+ * 3. ikon-api=true query param same-origin /ikon/api
27
+ * 4. Local environment (localhost, LAN IPs) → IKON_BACKEND_URL_DEV
28
+ * 5. Hostname contains '.dev.' IKON_BACKEND_URL_DEV
29
+ * 6. Default → IKON_BACKEND_URL_PROD
28
30
  */
29
31
  export declare function deriveBackendUrl(override?: string): string;
30
32
  /**
@@ -1,5 +1,5 @@
1
1
  import { ProtocolMessage, ActionFunctionRegister, GlobalState } from '../../../../shared/protocol/src/index.ts';
2
- import { FunctionDefinition, FunctionHandler, NormalizedFunction } from './types';
2
+ import { FunctionCallError, FunctionDefinition, FunctionHandler, NormalizedFunction } from './types';
3
3
  export interface RemoteFunction {
4
4
  id: string;
5
5
  name: string;
@@ -11,6 +11,15 @@ export interface RemoteFunction {
11
11
  llmCallOnlyOnce: boolean;
12
12
  requiresInstance: boolean;
13
13
  }
14
+ /**
15
+ * An error interceptor can observe and optionally handle function call errors.
16
+ * Return a Promise to take over resolution of the original call (e.g. retry after login).
17
+ * Return null to let the error propagate normally.
18
+ */
19
+ export type ErrorInterceptor = (error: FunctionCallError, callInfo: {
20
+ functionName: string;
21
+ args: unknown[];
22
+ }) => Promise<unknown> | null;
14
23
  export interface FunctionRegistryConfig {
15
24
  sendProtocolMessage: (message: ProtocolMessage) => void;
16
25
  sessionId: number;
@@ -19,6 +28,7 @@ export declare class FunctionRegistry {
19
28
  private readonly functions;
20
29
  private readonly remoteFunctions;
21
30
  private readonly pendingCalls;
31
+ private readonly errorInterceptors;
22
32
  private config;
23
33
  private isConnected;
24
34
  /**
@@ -30,6 +40,11 @@ export declare class FunctionRegistry {
30
40
  * Detach from the client (on disconnect).
31
41
  */
32
42
  detach(): void;
43
+ /**
44
+ * Add an error interceptor that can handle or transform function call errors.
45
+ * Returns an unregister function.
46
+ */
47
+ addErrorInterceptor(interceptor: ErrorInterceptor): () => void;
33
48
  /**
34
49
  * Register a function with the registry.
35
50
  * If already connected, sends registration to server immediately.
@@ -1,5 +1,5 @@
1
1
  export type { ValueDescriptor, NormalizedValueDescriptor, PrimitiveValueKind, FunctionParameterDefinition, FunctionDefinition, FunctionHandler, FunctionResultWithData } from './types';
2
2
  export { withResultData, FunctionCallError } from './types';
3
- export { FunctionRegistry, type FunctionRegistryConfig } from './function-registry';
3
+ export { FunctionRegistry, type FunctionRegistryConfig, type ErrorInterceptor } from './function-registry';
4
4
  export { registerBrowserFunctions, isBrowserEnvironment } from './browser-functions';
5
5
  export { registerSoundFunctions, SoundFunctionNames } from './sound-functions';
@@ -67,6 +67,7 @@ export interface NormalizedFunction {
67
67
  export declare class FunctionCallError extends Error {
68
68
  readonly remoteErrorType: string;
69
69
  readonly remoteStackTrace: string;
70
- constructor(message: string, remoteErrorType: string, remoteStackTrace: string);
70
+ readonly code: string;
71
+ constructor(message: string, remoteErrorType: string, remoteStackTrace: string, code?: string);
71
72
  }
72
73
  export {};
package/index.d.ts CHANGED
@@ -14,14 +14,16 @@ export { setLogLevel, setLogSink, getLogLevel, getLogSink, createLogger, LogLeve
14
14
  export type { LogEntry, LogSink, Logger, LogEventListener, LogEventSubscriptionOptions } from './utils/logger';
15
15
  export { initializeDebugMode, isDebugModeEnabled } from './utils/debug-mode';
16
16
  export { initializeInspectMode, isInspectModeEnabled, enableInspectMode } from './utils/inspect-mode';
17
- export { getLangParam, getProxyParam, getWebSocketParam, getWebTransportParam, getDebugParam, getServerUrlParam, getAudioParam, getVideoParam, getWebRtcParam, getInspectParam, setSdkUrlParam, IKON_PARAM_PROXY, IKON_PARAM_WEBSOCKET, IKON_PARAM_WEBTRANSPORT, IKON_PARAM_DEBUG, IKON_PARAM_LANG, IKON_PARAM_SERVER_URL, IKON_PARAM_GIT_SOURCE, IKON_PARAM_GIT_BRANCH, IKON_PARAM_AUDIO, IKON_PARAM_VIDEO, IKON_PARAM_WEBRTC, IKON_PARAM_INSPECT } from './utils/query-params';
17
+ export { getLangParam, getProxyParam, getWebSocketParam, getWebTransportParam, getDebugParam, getServerUrlParam, getAudioParam, getVideoParam, getWebRtcParam, getInspectParam, getRetryParam, setSdkUrlParam, IKON_PARAM_PROXY, IKON_PARAM_WEBSOCKET, IKON_PARAM_WEBTRANSPORT, IKON_PARAM_DEBUG, IKON_PARAM_LANG, IKON_PARAM_SERVER_URL, IKON_PARAM_GIT_SOURCE, IKON_PARAM_GIT_BRANCH, IKON_PARAM_AUDIO, IKON_PARAM_VIDEO, IKON_PARAM_WEBRTC, IKON_PARAM_INSPECT, IKON_PARAM_RETRY } from './utils/query-params';
18
18
  export { getOpcodeName } from './utils/opcode-names';
19
19
  export { initializeLogSink, setSendLogsCallback, getBufferedLogs, takeBufferedLogs, flushLogs, clearLogBuffer, getLogBufferSize } from './utils/log-sink';
20
20
  export type { LogSinkConfig } from './utils/log-sink';
21
21
  export { startLogSender, stopLogSender } from './utils/log-sender';
22
- export { FunctionRegistry, registerBrowserFunctions, isBrowserEnvironment, FunctionCallError, type FunctionRegistryConfig } from './functions';
22
+ export { FunctionRegistry, registerBrowserFunctions, isBrowserEnvironment, FunctionCallError, type FunctionRegistryConfig, type ErrorInterceptor } from './functions';
23
23
  export { withResultData } from './functions';
24
24
  export type { ValueDescriptor, NormalizedValueDescriptor, PrimitiveValueKind, FunctionParameterDefinition, FunctionDefinition, FunctionHandler, FunctionResultWithData } from './functions';
25
+ export { loginErrorInterceptor, reprovisionAfterLogin, consumeLoginHandoff, getLoginPromptState, clearLoginPrompt, subscribe as subscribeLoginPrompt, consumeLoginPendingCall } from './login';
26
+ export type { LoginPromptState, LoginPendingCall } from './login';
25
27
  export { IKON_AUTH_BASE_URL, IKON_AUTH_URL_PROD, IKON_AUTH_URL_DEV, IKON_BACKEND_URL_PROD, IKON_BACKEND_URL_DEV, deriveAuthUrl, deriveBackendUrl, deriveBackendType, parseUrlParams, clearSessionParamsFromUrl, isCloudEnvironment, type UrlParams } from './connection/urls';
26
28
  export { getOrCreateDeviceId, clearDeviceId, extractUserIdFromToken } from './storage';
27
29
  export { IkonMedia, IkonAudioPlayback, IkonVideoPlayback, isSharedArrayBufferSupported, isAudioWorkletSupported, IkonMediaCapture, IkonVideoCapture, IkonAudioCapture, IkonImageCapture } from './media';