@vivix-ai/ivi-frontend-sdk 0.3.8 → 0.3.10

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.cts CHANGED
@@ -1,5 +1,7 @@
1
1
  import { ReceiveSessionSourceReadyPayload, IviStream, IviConversationItem, IviRealtimeSessionConfig, IviStageComposition, IviTrack, IviSourceAsset, ReceiveSessionSourceFailedPayload, IviConversationItemContent, ReceiveSessionEndedEvent, ParsedIviEvent, IviRealtimeResponseCreateParams, ReceiveConversationItemAddedEvent, ReceiveConversationItemDoneEvent, ReceiveResponseCreatedEvent, IviClient, IviClientConfig } from '@vivix-ai/ivi-sdk-ts';
2
+ import { Tracer, Context, Attributes, Span } from '@opentelemetry/api';
2
3
  import { LiveKitBrowserTransportConfig } from '@vivix-ai/ivi-sdk-ts/transports/livekit-browser';
4
+ import { WebSocketTransportConfig } from '@vivix-ai/ivi-sdk-ts/transports/websocket';
3
5
  import { ReactNode, CSSProperties, ReactElement, VideoHTMLAttributes, ImgHTMLAttributes } from 'react';
4
6
  import { IviClientLogEntry } from '@vivix-ai/ivi-sdk-ts/client';
5
7
 
@@ -8,6 +10,27 @@ type IviSourcePlayback = NonNullable<ReceiveSessionSourceReadyPayload["playback"
8
10
  type IviSourcePlaybackTrtc = NonNullable<IviSourcePlayback["trtc"]>;
9
11
  type IviStreamStatus = IviStream["status"];
10
12
 
13
+ interface IviFrontendTelemetryOptions {
14
+ /**
15
+ * OpenTelemetry tracer。未传入时使用全局 `trace.getTracer("@vivix-ai/ivi-frontend-sdk")`。
16
+ *
17
+ * SDK 只依赖 `@opentelemetry/api`,不会内置 exporter/provider;未配置 provider 时这些 span 会是 no-op。
18
+ */
19
+ tracer?: Tracer;
20
+ /**
21
+ * 外部调用链的父 context。通常由业务点击、建会话或上层 SDK span 内传入 `context.active()`。
22
+ */
23
+ context?: Context;
24
+ /**
25
+ * 追加到每个 frontend SDK span 上的低基数字段。不要放 token、密钥、完整 payload 或用户文本。
26
+ */
27
+ attributes?: Attributes;
28
+ }
29
+ interface IviTelemetrySpanHandle {
30
+ span: Span;
31
+ context: Context;
32
+ }
33
+
11
34
  type IviRuntimeStatus = "idle" | "connecting" | "syncing" | "running" | "stopped";
12
35
  interface IviRuntimeState {
13
36
  status: IviRuntimeStatus;
@@ -18,6 +41,7 @@ interface IviRuntimeState {
18
41
  streams: Map<string, IviRuntimeStream>;
19
42
  conversationItems: Map<string, IviRuntimeConversationItem>;
20
43
  conversations: IviRuntimeConversationItem[];
44
+ bootstrap?: IviRuntimeBootstrapViewState | null;
21
45
  }
22
46
  /**
23
47
  * Runtime 层归一化后的 stream 视图。
@@ -37,6 +61,7 @@ interface IviRuntimeSourcePreloadState {
37
61
  */
38
62
  autoclearAfterPlay: boolean;
39
63
  }
64
+ type IviRuntimeSourceOrigin = "prebuilt-session-response";
40
65
  interface IviRuntimeSource {
41
66
  source: IviSourceAsset;
42
67
  status: "created" | "ready" | "failed";
@@ -52,6 +77,27 @@ interface IviRuntimeSource {
52
77
  * - 不存在:不进行预加载(active source 由上层独立决定是否渲染)。
53
78
  */
54
79
  preload?: IviRuntimeSourcePreloadState;
80
+ origin?: IviRuntimeSourceOrigin;
81
+ provisional?: boolean;
82
+ }
83
+ interface IviRuntimeBootstrapSource {
84
+ sourceId: string;
85
+ streamId?: string;
86
+ slot: string;
87
+ trackId: string;
88
+ playback: IviSourcePlayback;
89
+ width?: number;
90
+ height?: number;
91
+ durationMs?: number;
92
+ hasAudio?: boolean;
93
+ source?: Partial<IviSourceAsset>;
94
+ }
95
+ interface IviRuntimeBootstrapViewState {
96
+ active: boolean;
97
+ slot: string;
98
+ trackId: string;
99
+ sourceId: string;
100
+ streamId?: string;
55
101
  }
56
102
  type IviRuntimeLogLevel = "info" | "warn" | "error";
57
103
  interface IviRuntimeLogEntry {
@@ -122,6 +168,10 @@ interface IviRuntimeCoordinatorConfig {
122
168
  * TRTC SDK AIDenoiser 降噪配置。默认开启;传 false 可关闭。
123
169
  */
124
170
  trtcAIDenoiser?: boolean | IviRuntimeTrtcAIDenoiserOptions;
171
+ /**
172
+ * OpenTelemetry 埋点配置;SDK 只创建 span,不负责配置 provider/exporter。
173
+ */
174
+ telemetry?: IviFrontendTelemetryOptions;
125
175
  }
126
176
  /**
127
177
  * 用户输入触发回复链路配置。
@@ -197,10 +247,11 @@ declare class TrtcSourceManager {
197
247
  private readonly onLog?;
198
248
  private readonly onTrtcEvent?;
199
249
  private readonly aiDenoiser?;
250
+ private readonly telemetry?;
200
251
  private readonly sessions;
201
252
  private readonly sourceSessionKeys;
202
253
  private readonly listeners;
203
- constructor(onLog?: IviRuntimeLogCallback | undefined, onTrtcEvent?: IviRuntimeTrtcEventListener | undefined, aiDenoiser?: (boolean | IviRuntimeTrtcAIDenoiserOptions) | undefined);
254
+ constructor(onLog?: IviRuntimeLogCallback | undefined, onTrtcEvent?: IviRuntimeTrtcEventListener | undefined, aiDenoiser?: (boolean | IviRuntimeTrtcAIDenoiserOptions) | undefined, telemetry?: IviFrontendTelemetryOptions | undefined);
204
255
  /**
205
256
  * 将 runtime 当前 sources 与 TRTC 会话池对齐:
206
257
  * - 对 ready + trtc 的 source 进行 upsert(必要时建立连接)
@@ -239,6 +290,7 @@ declare class TrtcSourceManager {
239
290
  attachView(sourceId: string, viewId: string, container: HTMLElement, muted: boolean): Promise<void>;
240
291
  detachView(sourceId: string, viewId: string): void;
241
292
  updateViewMuted(sourceId: string, viewId: string, muted: boolean): void;
293
+ reassignView(fromSourceId: string, toSourceId: string, viewId: string): boolean;
242
294
  private unlinkSourceFromSession;
243
295
  private getSession;
244
296
  private snapshotFromSession;
@@ -315,9 +367,11 @@ type LivekitSourceListener = (snapshot: LivekitSourceSnapshot) => void;
315
367
  */
316
368
  declare class LivekitSourceManager {
317
369
  private readonly onLog?;
370
+ private readonly onRemoteVideoAvailable?;
371
+ private readonly telemetry?;
318
372
  private readonly sessions;
319
373
  private readonly listeners;
320
- constructor(onLog?: IviRuntimeLogCallback | undefined);
374
+ constructor(onLog?: IviRuntimeLogCallback | undefined, onRemoteVideoAvailable?: ((sourceId: string) => void) | undefined, telemetry?: IviFrontendTelemetryOptions | undefined);
321
375
  /**
322
376
  * 与 runtime 当前 sources 对齐:
323
377
  * - 对 ready + livekit 的 source 进行 upsert(必要时建立连接);
@@ -428,6 +482,7 @@ declare class IviRuntimeCoordinator {
428
482
  private userTextFlowCounter;
429
483
  private waitingTracksListValidation;
430
484
  private waitingSourcesListValidation;
485
+ private bootstrapSource;
431
486
  private state;
432
487
  /**
433
488
  * @param client 底层实时客户端,负责实际事件收发。
@@ -444,10 +499,12 @@ declare class IviRuntimeCoordinator {
444
499
  */
445
500
  stop(): void;
446
501
  getState(): IviRuntimeState;
502
+ getTelemetryOptions(): IviRuntimeCoordinatorConfig["telemetry"];
447
503
  onStateChange(listener: (state: IviRuntimeState) => void): () => void;
448
504
  onEvent(listener: IviRuntimeEventListener): () => void;
449
505
  onTrtcEvent(listener: IviRuntimeTrtcEventListener): () => void;
450
506
  emitLog(entry: IviRuntimeLogEntry): void;
507
+ setBootstrapSource(source: IviRuntimeBootstrapSource | null): void;
451
508
  /**
452
509
  * 编排一次"用户文本输入 -> 触发模型回复"链路。
453
510
  *
@@ -484,8 +541,15 @@ declare class IviRuntimeCoordinator {
484
541
  private onStreamsChanged;
485
542
  private onConversationsChanged;
486
543
  private setState;
544
+ private composeBootstrapState;
545
+ private shouldExposeBootstrap;
546
+ private isReadyForBootstrapHandoff;
547
+ private recomposeBootstrapState;
548
+ private ensureBootstrapSourceRegistered;
549
+ private syncPlaybackManagers;
487
550
  private emitEvent;
488
551
  private emitTrtcEvent;
552
+ private onTrtcManagerEvent;
489
553
  private resetStoppedState;
490
554
  private ensureSourcesSyncedForTracks;
491
555
  private validateSourcesListRefreshed;
@@ -523,10 +587,110 @@ declare class IviRuntimeDispatcher {
523
587
  private dispatchEvent;
524
588
  }
525
589
 
590
+ type IviCreateSessionStreamType = "TRTC" | "LIVEKIT" | string;
591
+ interface IviCreateIVISessionPrebuiltCharacter {
592
+ characterId: string;
593
+ characterPayload: unknown;
594
+ }
595
+ interface IviCreateIVISessionPrebuiltStream {
596
+ streamId?: string;
597
+ sourceId?: string;
598
+ mode: "character" | string;
599
+ streamConfig: unknown;
600
+ }
601
+ interface IviCreateIVISessionRequest {
602
+ idempotencyKey?: string;
603
+ streamType?: IviCreateSessionStreamType;
604
+ iviVersion?: string;
605
+ sessionParameters?: Record<string, string>;
606
+ enableDecoderPublish?: boolean;
607
+ sessionRecording?: {
608
+ enabled: boolean;
609
+ aspectRatio?: string;
610
+ };
611
+ prebuiltCharacters?: IviCreateIVISessionPrebuiltCharacter[];
612
+ prebuiltStream?: IviCreateIVISessionPrebuiltStream;
613
+ [key: string]: unknown;
614
+ }
615
+ interface IviCreateIVISessionHttpOptions {
616
+ baseUrl?: string;
617
+ path?: string;
618
+ url?: string;
619
+ headers?: HeadersInit | (() => HeadersInit | Promise<HeadersInit>);
620
+ fetch?: typeof fetch;
621
+ credentials?: RequestCredentials;
622
+ signal?: AbortSignal;
623
+ telemetry?: IviFrontendTelemetryOptions;
624
+ }
625
+ interface IviPrebuiltPlayback {
626
+ sourceId: string;
627
+ streamId?: string;
628
+ kind: "trtc" | "livekit";
629
+ playback: IviSourcePlayback;
630
+ provisional: true;
631
+ }
632
+ interface IviCreateIVISessionResult {
633
+ iviSessionId: string;
634
+ endpoint: string;
635
+ tokenInfo?: unknown;
636
+ trtcInfo?: IviSourcePlaybackTrtc;
637
+ livekitInfo?: IviSourcePlaybackLivekit;
638
+ prebuildTrtcInfo?: {
639
+ trtcInfo?: IviSourcePlaybackTrtc;
640
+ livekitInfo?: IviSourcePlaybackLivekit;
641
+ };
642
+ prebuiltPlayback?: IviPrebuiltPlayback;
643
+ raw: unknown;
644
+ requestBody: Record<string, unknown>;
645
+ }
646
+ interface IviRuntimeWebSocketOptions {
647
+ url?: string;
648
+ protocols?: WebSocketTransportConfig["protocols"];
649
+ query?: Record<string, string | undefined | null>;
650
+ socketFactory?: WebSocketTransportConfig["socketFactory"];
651
+ }
652
+ interface IviRuntimeFromSessionOptions {
653
+ fastStart?: boolean;
654
+ bootstrapSlot?: string;
655
+ bootstrapTrackId?: string;
656
+ clientConfig?: Omit<IviClientConfig, "transport">;
657
+ runtimeConfig?: IviRuntimeCoordinatorConfig;
658
+ websocket?: IviRuntimeWebSocketOptions;
659
+ telemetry?: IviFrontendTelemetryOptions;
660
+ }
661
+ interface IviSessionRuntime {
662
+ session: IviCreateIVISessionResult;
663
+ client: IviClient;
664
+ runtime: IviRuntimeCoordinator;
665
+ }
666
+ interface IviCreateIVISessionRuntimeOptions extends IviRuntimeFromSessionOptions {
667
+ http: IviCreateIVISessionHttpOptions;
668
+ }
669
+ declare class IviCreateIVISessionError extends Error {
670
+ readonly status: number;
671
+ readonly statusText: string;
672
+ readonly body: unknown;
673
+ constructor(response: Response, body: unknown);
674
+ }
675
+ declare function createIVISession(request: IviCreateIVISessionRequest, options: IviCreateIVISessionHttpOptions): Promise<IviCreateIVISessionResult>;
676
+ declare function createRuntimeFromSession(session: IviCreateIVISessionResult, options?: IviRuntimeFromSessionOptions): IviSessionRuntime;
677
+ declare function createIVISessionRuntime(request: IviCreateIVISessionRequest, options: IviCreateIVISessionRuntimeOptions): Promise<IviSessionRuntime>;
678
+ declare function toCpCreateIVISessionRequestBody(request: IviCreateIVISessionRequest): Record<string, unknown>;
679
+ declare function normalizeCreateIVISessionResponse(responseBody: unknown, request?: IviCreateIVISessionRequest, requestBody?: Record<string, unknown>): IviCreateIVISessionResult;
680
+
526
681
  type IviFrontendClientConfig = IviClientConfig;
682
+ interface IviFrontendSdkConfig {
683
+ http?: IviCreateIVISessionHttpOptions;
684
+ telemetry?: IviFrontendTelemetryOptions;
685
+ }
527
686
  declare class IviFrontendSdk {
687
+ private readonly config;
688
+ constructor(config?: IviFrontendSdkConfig);
528
689
  createClient(config: IviFrontendClientConfig): IviClient;
529
690
  createRuntimeCoordinator(clientConfig: IviFrontendClientConfig, runtimeConfig?: IviRuntimeCoordinatorConfig): IviRuntimeCoordinator;
691
+ createIVISession(request: IviCreateIVISessionRequest, options?: IviCreateIVISessionHttpOptions): Promise<IviCreateIVISessionResult>;
692
+ createRuntimeFromSession(session: IviCreateIVISessionResult, options?: IviRuntimeFromSessionOptions): IviSessionRuntime;
693
+ createIVISessionRuntime(request: IviCreateIVISessionRequest, options?: Partial<IviCreateIVISessionRuntimeOptions>): Promise<IviSessionRuntime>;
530
694
  }
531
695
 
532
696
  interface IviStageSlotBinding {
@@ -800,6 +964,24 @@ interface IviManagedRuntimeConfig {
800
964
  }
801
965
  declare function useManagedIviRuntime(config: IviManagedRuntimeConfig): IviRuntimeCoordinator | null;
802
966
 
967
+ type IviSessionRuntimeHookStatus = "idle" | "creating" | "connecting" | "running" | "error" | "stopped";
968
+ interface UseIviSessionRuntimeConfig extends IviCreateIVISessionRuntimeOptions {
969
+ request: IviCreateIVISessionRequest | null | undefined;
970
+ enabled?: boolean;
971
+ autoStart?: boolean;
972
+ onCreated?: (session: IviCreateIVISessionResult) => void;
973
+ onRuntimeReady?: (runtime: IviRuntimeCoordinator, client: IviClient) => void;
974
+ onError?: (error: unknown) => void;
975
+ }
976
+ interface UseIviSessionRuntimeResult {
977
+ status: IviSessionRuntimeHookStatus;
978
+ session: IviCreateIVISessionResult | null;
979
+ runtime: IviRuntimeCoordinator | null;
980
+ client: IviClient | null;
981
+ error: Error | null;
982
+ }
983
+ declare function useIviSessionRuntime(config: UseIviSessionRuntimeConfig): UseIviSessionRuntimeResult;
984
+
803
985
  declare function useIviStageView(): IviStageViewContextValue;
804
986
 
805
- export { DEFAULT_HIDE_COMPLETED_SUBTITLE_AFTER_MS, EMPTY_RUNTIME_STATE, IVILivekitPlayer, type IVILivekitPlayerProps, IVIStageView, type IVIStageViewProps, IVISubtitleOverlay, type IVISubtitleOverlayProps, type IVISubtitleOverlayStyle, IVITrackSlot, type IVITrackSlotProps, IVITrtcPlayer, type IVITrtcPlayerProps, type IviCompletedSubtitleDecision, type IviCompletedSubtitleDecisionResult, type IviFrontendClientConfig, IviFrontendSdk, type IviManagedRuntimeConfig, type IviManagedRuntimeLogCallback, type IviManagedRuntimeLogEntry, type IviManagedRuntimeLogLevel, type IviManagedRuntimeLogSource, type IviRuntimeConversationItem, type IviRuntimeConversationLifecycle, type IviRuntimeConversationStatus, IviRuntimeCoordinator, type IviRuntimeCoordinatorConfig, IviRuntimeDispatcher, type IviRuntimeDispatcherConfig, type IviRuntimeEventListener, type IviRuntimeLogCallback, type IviRuntimeLogEntry, type IviRuntimeLogLevel, type IviRuntimeSource, type IviRuntimeSourcePreloadState, type IviRuntimeState, type IviRuntimeStatus, type IviRuntimeStream, type IviRuntimeTrtcAIDenoiserMode, type IviRuntimeTrtcAIDenoiserOptions, type IviRuntimeTrtcEvent, type IviRuntimeTrtcEventListener, type IviRuntimeTrtcEventType, type IviRuntimeUserTextToResponseCallbacks, type IviRuntimeUserTextToResponseOptions, type IviRuntimeUserTextToResponseResult, type IviSourcePlaybackLivekit, type IviSourcePlaybackLivekitDescriptor, type IviStageSlotBinding, type IviStageViewContextValue, type IviSubtitleCompletedContext, type IviSubtitleCompletedHandler, type IviSubtitleCompletedReason, type IviSubtitleItem, type IviSubtitleRole, type IviSubtitleSource, type IviUseSubtitlesOptions, LivekitSourceManager, TrtcSourceManager, isLivekitSourcePlayback, isReadyLivekitRuntimeSource, isSameLivekitConfig, useIviStageView, useIviSubtitles, useManagedIviRuntime, useRuntimeState };
987
+ export { DEFAULT_HIDE_COMPLETED_SUBTITLE_AFTER_MS, EMPTY_RUNTIME_STATE, IVILivekitPlayer, type IVILivekitPlayerProps, IVIStageView, type IVIStageViewProps, IVISubtitleOverlay, type IVISubtitleOverlayProps, type IVISubtitleOverlayStyle, IVITrackSlot, type IVITrackSlotProps, IVITrtcPlayer, type IVITrtcPlayerProps, type IviCompletedSubtitleDecision, type IviCompletedSubtitleDecisionResult, IviCreateIVISessionError, type IviCreateIVISessionHttpOptions, type IviCreateIVISessionPrebuiltCharacter, type IviCreateIVISessionPrebuiltStream, type IviCreateIVISessionRequest, type IviCreateIVISessionResult, type IviCreateIVISessionRuntimeOptions, type IviCreateSessionStreamType, type IviFrontendClientConfig, IviFrontendSdk, type IviFrontendSdkConfig, type IviFrontendTelemetryOptions, type IviManagedRuntimeConfig, type IviManagedRuntimeLogCallback, type IviManagedRuntimeLogEntry, type IviManagedRuntimeLogLevel, type IviManagedRuntimeLogSource, type IviPrebuiltPlayback, type IviRuntimeBootstrapSource, type IviRuntimeBootstrapViewState, type IviRuntimeConversationItem, type IviRuntimeConversationLifecycle, type IviRuntimeConversationStatus, IviRuntimeCoordinator, type IviRuntimeCoordinatorConfig, IviRuntimeDispatcher, type IviRuntimeDispatcherConfig, type IviRuntimeEventListener, type IviRuntimeFromSessionOptions, type IviRuntimeLogCallback, type IviRuntimeLogEntry, type IviRuntimeLogLevel, type IviRuntimeSource, type IviRuntimeSourceOrigin, type IviRuntimeSourcePreloadState, type IviRuntimeState, type IviRuntimeStatus, type IviRuntimeStream, type IviRuntimeTrtcAIDenoiserMode, type IviRuntimeTrtcAIDenoiserOptions, type IviRuntimeTrtcEvent, type IviRuntimeTrtcEventListener, type IviRuntimeTrtcEventType, type IviRuntimeUserTextToResponseCallbacks, type IviRuntimeUserTextToResponseOptions, type IviRuntimeUserTextToResponseResult, type IviRuntimeWebSocketOptions, type IviSessionRuntime, type IviSessionRuntimeHookStatus, type IviSourcePlaybackLivekit, type IviSourcePlaybackLivekitDescriptor, type IviStageSlotBinding, type IviStageViewContextValue, type IviSubtitleCompletedContext, type IviSubtitleCompletedHandler, type IviSubtitleCompletedReason, type IviSubtitleItem, type IviSubtitleRole, type IviSubtitleSource, type IviTelemetrySpanHandle, type IviUseSubtitlesOptions, LivekitSourceManager, TrtcSourceManager, type UseIviSessionRuntimeConfig, type UseIviSessionRuntimeResult, createIVISession, createIVISessionRuntime, createRuntimeFromSession, isLivekitSourcePlayback, isReadyLivekitRuntimeSource, isSameLivekitConfig, normalizeCreateIVISessionResponse, toCpCreateIVISessionRequestBody, useIviSessionRuntime, useIviStageView, useIviSubtitles, useManagedIviRuntime, useRuntimeState };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  import { ReceiveSessionSourceReadyPayload, IviStream, IviConversationItem, IviRealtimeSessionConfig, IviStageComposition, IviTrack, IviSourceAsset, ReceiveSessionSourceFailedPayload, IviConversationItemContent, ReceiveSessionEndedEvent, ParsedIviEvent, IviRealtimeResponseCreateParams, ReceiveConversationItemAddedEvent, ReceiveConversationItemDoneEvent, ReceiveResponseCreatedEvent, IviClient, IviClientConfig } from '@vivix-ai/ivi-sdk-ts';
2
+ import { Tracer, Context, Attributes, Span } from '@opentelemetry/api';
2
3
  import { LiveKitBrowserTransportConfig } from '@vivix-ai/ivi-sdk-ts/transports/livekit-browser';
4
+ import { WebSocketTransportConfig } from '@vivix-ai/ivi-sdk-ts/transports/websocket';
3
5
  import { ReactNode, CSSProperties, ReactElement, VideoHTMLAttributes, ImgHTMLAttributes } from 'react';
4
6
  import { IviClientLogEntry } from '@vivix-ai/ivi-sdk-ts/client';
5
7
 
@@ -8,6 +10,27 @@ type IviSourcePlayback = NonNullable<ReceiveSessionSourceReadyPayload["playback"
8
10
  type IviSourcePlaybackTrtc = NonNullable<IviSourcePlayback["trtc"]>;
9
11
  type IviStreamStatus = IviStream["status"];
10
12
 
13
+ interface IviFrontendTelemetryOptions {
14
+ /**
15
+ * OpenTelemetry tracer。未传入时使用全局 `trace.getTracer("@vivix-ai/ivi-frontend-sdk")`。
16
+ *
17
+ * SDK 只依赖 `@opentelemetry/api`,不会内置 exporter/provider;未配置 provider 时这些 span 会是 no-op。
18
+ */
19
+ tracer?: Tracer;
20
+ /**
21
+ * 外部调用链的父 context。通常由业务点击、建会话或上层 SDK span 内传入 `context.active()`。
22
+ */
23
+ context?: Context;
24
+ /**
25
+ * 追加到每个 frontend SDK span 上的低基数字段。不要放 token、密钥、完整 payload 或用户文本。
26
+ */
27
+ attributes?: Attributes;
28
+ }
29
+ interface IviTelemetrySpanHandle {
30
+ span: Span;
31
+ context: Context;
32
+ }
33
+
11
34
  type IviRuntimeStatus = "idle" | "connecting" | "syncing" | "running" | "stopped";
12
35
  interface IviRuntimeState {
13
36
  status: IviRuntimeStatus;
@@ -18,6 +41,7 @@ interface IviRuntimeState {
18
41
  streams: Map<string, IviRuntimeStream>;
19
42
  conversationItems: Map<string, IviRuntimeConversationItem>;
20
43
  conversations: IviRuntimeConversationItem[];
44
+ bootstrap?: IviRuntimeBootstrapViewState | null;
21
45
  }
22
46
  /**
23
47
  * Runtime 层归一化后的 stream 视图。
@@ -37,6 +61,7 @@ interface IviRuntimeSourcePreloadState {
37
61
  */
38
62
  autoclearAfterPlay: boolean;
39
63
  }
64
+ type IviRuntimeSourceOrigin = "prebuilt-session-response";
40
65
  interface IviRuntimeSource {
41
66
  source: IviSourceAsset;
42
67
  status: "created" | "ready" | "failed";
@@ -52,6 +77,27 @@ interface IviRuntimeSource {
52
77
  * - 不存在:不进行预加载(active source 由上层独立决定是否渲染)。
53
78
  */
54
79
  preload?: IviRuntimeSourcePreloadState;
80
+ origin?: IviRuntimeSourceOrigin;
81
+ provisional?: boolean;
82
+ }
83
+ interface IviRuntimeBootstrapSource {
84
+ sourceId: string;
85
+ streamId?: string;
86
+ slot: string;
87
+ trackId: string;
88
+ playback: IviSourcePlayback;
89
+ width?: number;
90
+ height?: number;
91
+ durationMs?: number;
92
+ hasAudio?: boolean;
93
+ source?: Partial<IviSourceAsset>;
94
+ }
95
+ interface IviRuntimeBootstrapViewState {
96
+ active: boolean;
97
+ slot: string;
98
+ trackId: string;
99
+ sourceId: string;
100
+ streamId?: string;
55
101
  }
56
102
  type IviRuntimeLogLevel = "info" | "warn" | "error";
57
103
  interface IviRuntimeLogEntry {
@@ -122,6 +168,10 @@ interface IviRuntimeCoordinatorConfig {
122
168
  * TRTC SDK AIDenoiser 降噪配置。默认开启;传 false 可关闭。
123
169
  */
124
170
  trtcAIDenoiser?: boolean | IviRuntimeTrtcAIDenoiserOptions;
171
+ /**
172
+ * OpenTelemetry 埋点配置;SDK 只创建 span,不负责配置 provider/exporter。
173
+ */
174
+ telemetry?: IviFrontendTelemetryOptions;
125
175
  }
126
176
  /**
127
177
  * 用户输入触发回复链路配置。
@@ -197,10 +247,11 @@ declare class TrtcSourceManager {
197
247
  private readonly onLog?;
198
248
  private readonly onTrtcEvent?;
199
249
  private readonly aiDenoiser?;
250
+ private readonly telemetry?;
200
251
  private readonly sessions;
201
252
  private readonly sourceSessionKeys;
202
253
  private readonly listeners;
203
- constructor(onLog?: IviRuntimeLogCallback | undefined, onTrtcEvent?: IviRuntimeTrtcEventListener | undefined, aiDenoiser?: (boolean | IviRuntimeTrtcAIDenoiserOptions) | undefined);
254
+ constructor(onLog?: IviRuntimeLogCallback | undefined, onTrtcEvent?: IviRuntimeTrtcEventListener | undefined, aiDenoiser?: (boolean | IviRuntimeTrtcAIDenoiserOptions) | undefined, telemetry?: IviFrontendTelemetryOptions | undefined);
204
255
  /**
205
256
  * 将 runtime 当前 sources 与 TRTC 会话池对齐:
206
257
  * - 对 ready + trtc 的 source 进行 upsert(必要时建立连接)
@@ -239,6 +290,7 @@ declare class TrtcSourceManager {
239
290
  attachView(sourceId: string, viewId: string, container: HTMLElement, muted: boolean): Promise<void>;
240
291
  detachView(sourceId: string, viewId: string): void;
241
292
  updateViewMuted(sourceId: string, viewId: string, muted: boolean): void;
293
+ reassignView(fromSourceId: string, toSourceId: string, viewId: string): boolean;
242
294
  private unlinkSourceFromSession;
243
295
  private getSession;
244
296
  private snapshotFromSession;
@@ -315,9 +367,11 @@ type LivekitSourceListener = (snapshot: LivekitSourceSnapshot) => void;
315
367
  */
316
368
  declare class LivekitSourceManager {
317
369
  private readonly onLog?;
370
+ private readonly onRemoteVideoAvailable?;
371
+ private readonly telemetry?;
318
372
  private readonly sessions;
319
373
  private readonly listeners;
320
- constructor(onLog?: IviRuntimeLogCallback | undefined);
374
+ constructor(onLog?: IviRuntimeLogCallback | undefined, onRemoteVideoAvailable?: ((sourceId: string) => void) | undefined, telemetry?: IviFrontendTelemetryOptions | undefined);
321
375
  /**
322
376
  * 与 runtime 当前 sources 对齐:
323
377
  * - 对 ready + livekit 的 source 进行 upsert(必要时建立连接);
@@ -428,6 +482,7 @@ declare class IviRuntimeCoordinator {
428
482
  private userTextFlowCounter;
429
483
  private waitingTracksListValidation;
430
484
  private waitingSourcesListValidation;
485
+ private bootstrapSource;
431
486
  private state;
432
487
  /**
433
488
  * @param client 底层实时客户端,负责实际事件收发。
@@ -444,10 +499,12 @@ declare class IviRuntimeCoordinator {
444
499
  */
445
500
  stop(): void;
446
501
  getState(): IviRuntimeState;
502
+ getTelemetryOptions(): IviRuntimeCoordinatorConfig["telemetry"];
447
503
  onStateChange(listener: (state: IviRuntimeState) => void): () => void;
448
504
  onEvent(listener: IviRuntimeEventListener): () => void;
449
505
  onTrtcEvent(listener: IviRuntimeTrtcEventListener): () => void;
450
506
  emitLog(entry: IviRuntimeLogEntry): void;
507
+ setBootstrapSource(source: IviRuntimeBootstrapSource | null): void;
451
508
  /**
452
509
  * 编排一次"用户文本输入 -> 触发模型回复"链路。
453
510
  *
@@ -484,8 +541,15 @@ declare class IviRuntimeCoordinator {
484
541
  private onStreamsChanged;
485
542
  private onConversationsChanged;
486
543
  private setState;
544
+ private composeBootstrapState;
545
+ private shouldExposeBootstrap;
546
+ private isReadyForBootstrapHandoff;
547
+ private recomposeBootstrapState;
548
+ private ensureBootstrapSourceRegistered;
549
+ private syncPlaybackManagers;
487
550
  private emitEvent;
488
551
  private emitTrtcEvent;
552
+ private onTrtcManagerEvent;
489
553
  private resetStoppedState;
490
554
  private ensureSourcesSyncedForTracks;
491
555
  private validateSourcesListRefreshed;
@@ -523,10 +587,110 @@ declare class IviRuntimeDispatcher {
523
587
  private dispatchEvent;
524
588
  }
525
589
 
590
+ type IviCreateSessionStreamType = "TRTC" | "LIVEKIT" | string;
591
+ interface IviCreateIVISessionPrebuiltCharacter {
592
+ characterId: string;
593
+ characterPayload: unknown;
594
+ }
595
+ interface IviCreateIVISessionPrebuiltStream {
596
+ streamId?: string;
597
+ sourceId?: string;
598
+ mode: "character" | string;
599
+ streamConfig: unknown;
600
+ }
601
+ interface IviCreateIVISessionRequest {
602
+ idempotencyKey?: string;
603
+ streamType?: IviCreateSessionStreamType;
604
+ iviVersion?: string;
605
+ sessionParameters?: Record<string, string>;
606
+ enableDecoderPublish?: boolean;
607
+ sessionRecording?: {
608
+ enabled: boolean;
609
+ aspectRatio?: string;
610
+ };
611
+ prebuiltCharacters?: IviCreateIVISessionPrebuiltCharacter[];
612
+ prebuiltStream?: IviCreateIVISessionPrebuiltStream;
613
+ [key: string]: unknown;
614
+ }
615
+ interface IviCreateIVISessionHttpOptions {
616
+ baseUrl?: string;
617
+ path?: string;
618
+ url?: string;
619
+ headers?: HeadersInit | (() => HeadersInit | Promise<HeadersInit>);
620
+ fetch?: typeof fetch;
621
+ credentials?: RequestCredentials;
622
+ signal?: AbortSignal;
623
+ telemetry?: IviFrontendTelemetryOptions;
624
+ }
625
+ interface IviPrebuiltPlayback {
626
+ sourceId: string;
627
+ streamId?: string;
628
+ kind: "trtc" | "livekit";
629
+ playback: IviSourcePlayback;
630
+ provisional: true;
631
+ }
632
+ interface IviCreateIVISessionResult {
633
+ iviSessionId: string;
634
+ endpoint: string;
635
+ tokenInfo?: unknown;
636
+ trtcInfo?: IviSourcePlaybackTrtc;
637
+ livekitInfo?: IviSourcePlaybackLivekit;
638
+ prebuildTrtcInfo?: {
639
+ trtcInfo?: IviSourcePlaybackTrtc;
640
+ livekitInfo?: IviSourcePlaybackLivekit;
641
+ };
642
+ prebuiltPlayback?: IviPrebuiltPlayback;
643
+ raw: unknown;
644
+ requestBody: Record<string, unknown>;
645
+ }
646
+ interface IviRuntimeWebSocketOptions {
647
+ url?: string;
648
+ protocols?: WebSocketTransportConfig["protocols"];
649
+ query?: Record<string, string | undefined | null>;
650
+ socketFactory?: WebSocketTransportConfig["socketFactory"];
651
+ }
652
+ interface IviRuntimeFromSessionOptions {
653
+ fastStart?: boolean;
654
+ bootstrapSlot?: string;
655
+ bootstrapTrackId?: string;
656
+ clientConfig?: Omit<IviClientConfig, "transport">;
657
+ runtimeConfig?: IviRuntimeCoordinatorConfig;
658
+ websocket?: IviRuntimeWebSocketOptions;
659
+ telemetry?: IviFrontendTelemetryOptions;
660
+ }
661
+ interface IviSessionRuntime {
662
+ session: IviCreateIVISessionResult;
663
+ client: IviClient;
664
+ runtime: IviRuntimeCoordinator;
665
+ }
666
+ interface IviCreateIVISessionRuntimeOptions extends IviRuntimeFromSessionOptions {
667
+ http: IviCreateIVISessionHttpOptions;
668
+ }
669
+ declare class IviCreateIVISessionError extends Error {
670
+ readonly status: number;
671
+ readonly statusText: string;
672
+ readonly body: unknown;
673
+ constructor(response: Response, body: unknown);
674
+ }
675
+ declare function createIVISession(request: IviCreateIVISessionRequest, options: IviCreateIVISessionHttpOptions): Promise<IviCreateIVISessionResult>;
676
+ declare function createRuntimeFromSession(session: IviCreateIVISessionResult, options?: IviRuntimeFromSessionOptions): IviSessionRuntime;
677
+ declare function createIVISessionRuntime(request: IviCreateIVISessionRequest, options: IviCreateIVISessionRuntimeOptions): Promise<IviSessionRuntime>;
678
+ declare function toCpCreateIVISessionRequestBody(request: IviCreateIVISessionRequest): Record<string, unknown>;
679
+ declare function normalizeCreateIVISessionResponse(responseBody: unknown, request?: IviCreateIVISessionRequest, requestBody?: Record<string, unknown>): IviCreateIVISessionResult;
680
+
526
681
  type IviFrontendClientConfig = IviClientConfig;
682
+ interface IviFrontendSdkConfig {
683
+ http?: IviCreateIVISessionHttpOptions;
684
+ telemetry?: IviFrontendTelemetryOptions;
685
+ }
527
686
  declare class IviFrontendSdk {
687
+ private readonly config;
688
+ constructor(config?: IviFrontendSdkConfig);
528
689
  createClient(config: IviFrontendClientConfig): IviClient;
529
690
  createRuntimeCoordinator(clientConfig: IviFrontendClientConfig, runtimeConfig?: IviRuntimeCoordinatorConfig): IviRuntimeCoordinator;
691
+ createIVISession(request: IviCreateIVISessionRequest, options?: IviCreateIVISessionHttpOptions): Promise<IviCreateIVISessionResult>;
692
+ createRuntimeFromSession(session: IviCreateIVISessionResult, options?: IviRuntimeFromSessionOptions): IviSessionRuntime;
693
+ createIVISessionRuntime(request: IviCreateIVISessionRequest, options?: Partial<IviCreateIVISessionRuntimeOptions>): Promise<IviSessionRuntime>;
530
694
  }
531
695
 
532
696
  interface IviStageSlotBinding {
@@ -800,6 +964,24 @@ interface IviManagedRuntimeConfig {
800
964
  }
801
965
  declare function useManagedIviRuntime(config: IviManagedRuntimeConfig): IviRuntimeCoordinator | null;
802
966
 
967
+ type IviSessionRuntimeHookStatus = "idle" | "creating" | "connecting" | "running" | "error" | "stopped";
968
+ interface UseIviSessionRuntimeConfig extends IviCreateIVISessionRuntimeOptions {
969
+ request: IviCreateIVISessionRequest | null | undefined;
970
+ enabled?: boolean;
971
+ autoStart?: boolean;
972
+ onCreated?: (session: IviCreateIVISessionResult) => void;
973
+ onRuntimeReady?: (runtime: IviRuntimeCoordinator, client: IviClient) => void;
974
+ onError?: (error: unknown) => void;
975
+ }
976
+ interface UseIviSessionRuntimeResult {
977
+ status: IviSessionRuntimeHookStatus;
978
+ session: IviCreateIVISessionResult | null;
979
+ runtime: IviRuntimeCoordinator | null;
980
+ client: IviClient | null;
981
+ error: Error | null;
982
+ }
983
+ declare function useIviSessionRuntime(config: UseIviSessionRuntimeConfig): UseIviSessionRuntimeResult;
984
+
803
985
  declare function useIviStageView(): IviStageViewContextValue;
804
986
 
805
- export { DEFAULT_HIDE_COMPLETED_SUBTITLE_AFTER_MS, EMPTY_RUNTIME_STATE, IVILivekitPlayer, type IVILivekitPlayerProps, IVIStageView, type IVIStageViewProps, IVISubtitleOverlay, type IVISubtitleOverlayProps, type IVISubtitleOverlayStyle, IVITrackSlot, type IVITrackSlotProps, IVITrtcPlayer, type IVITrtcPlayerProps, type IviCompletedSubtitleDecision, type IviCompletedSubtitleDecisionResult, type IviFrontendClientConfig, IviFrontendSdk, type IviManagedRuntimeConfig, type IviManagedRuntimeLogCallback, type IviManagedRuntimeLogEntry, type IviManagedRuntimeLogLevel, type IviManagedRuntimeLogSource, type IviRuntimeConversationItem, type IviRuntimeConversationLifecycle, type IviRuntimeConversationStatus, IviRuntimeCoordinator, type IviRuntimeCoordinatorConfig, IviRuntimeDispatcher, type IviRuntimeDispatcherConfig, type IviRuntimeEventListener, type IviRuntimeLogCallback, type IviRuntimeLogEntry, type IviRuntimeLogLevel, type IviRuntimeSource, type IviRuntimeSourcePreloadState, type IviRuntimeState, type IviRuntimeStatus, type IviRuntimeStream, type IviRuntimeTrtcAIDenoiserMode, type IviRuntimeTrtcAIDenoiserOptions, type IviRuntimeTrtcEvent, type IviRuntimeTrtcEventListener, type IviRuntimeTrtcEventType, type IviRuntimeUserTextToResponseCallbacks, type IviRuntimeUserTextToResponseOptions, type IviRuntimeUserTextToResponseResult, type IviSourcePlaybackLivekit, type IviSourcePlaybackLivekitDescriptor, type IviStageSlotBinding, type IviStageViewContextValue, type IviSubtitleCompletedContext, type IviSubtitleCompletedHandler, type IviSubtitleCompletedReason, type IviSubtitleItem, type IviSubtitleRole, type IviSubtitleSource, type IviUseSubtitlesOptions, LivekitSourceManager, TrtcSourceManager, isLivekitSourcePlayback, isReadyLivekitRuntimeSource, isSameLivekitConfig, useIviStageView, useIviSubtitles, useManagedIviRuntime, useRuntimeState };
987
+ export { DEFAULT_HIDE_COMPLETED_SUBTITLE_AFTER_MS, EMPTY_RUNTIME_STATE, IVILivekitPlayer, type IVILivekitPlayerProps, IVIStageView, type IVIStageViewProps, IVISubtitleOverlay, type IVISubtitleOverlayProps, type IVISubtitleOverlayStyle, IVITrackSlot, type IVITrackSlotProps, IVITrtcPlayer, type IVITrtcPlayerProps, type IviCompletedSubtitleDecision, type IviCompletedSubtitleDecisionResult, IviCreateIVISessionError, type IviCreateIVISessionHttpOptions, type IviCreateIVISessionPrebuiltCharacter, type IviCreateIVISessionPrebuiltStream, type IviCreateIVISessionRequest, type IviCreateIVISessionResult, type IviCreateIVISessionRuntimeOptions, type IviCreateSessionStreamType, type IviFrontendClientConfig, IviFrontendSdk, type IviFrontendSdkConfig, type IviFrontendTelemetryOptions, type IviManagedRuntimeConfig, type IviManagedRuntimeLogCallback, type IviManagedRuntimeLogEntry, type IviManagedRuntimeLogLevel, type IviManagedRuntimeLogSource, type IviPrebuiltPlayback, type IviRuntimeBootstrapSource, type IviRuntimeBootstrapViewState, type IviRuntimeConversationItem, type IviRuntimeConversationLifecycle, type IviRuntimeConversationStatus, IviRuntimeCoordinator, type IviRuntimeCoordinatorConfig, IviRuntimeDispatcher, type IviRuntimeDispatcherConfig, type IviRuntimeEventListener, type IviRuntimeFromSessionOptions, type IviRuntimeLogCallback, type IviRuntimeLogEntry, type IviRuntimeLogLevel, type IviRuntimeSource, type IviRuntimeSourceOrigin, type IviRuntimeSourcePreloadState, type IviRuntimeState, type IviRuntimeStatus, type IviRuntimeStream, type IviRuntimeTrtcAIDenoiserMode, type IviRuntimeTrtcAIDenoiserOptions, type IviRuntimeTrtcEvent, type IviRuntimeTrtcEventListener, type IviRuntimeTrtcEventType, type IviRuntimeUserTextToResponseCallbacks, type IviRuntimeUserTextToResponseOptions, type IviRuntimeUserTextToResponseResult, type IviRuntimeWebSocketOptions, type IviSessionRuntime, type IviSessionRuntimeHookStatus, type IviSourcePlaybackLivekit, type IviSourcePlaybackLivekitDescriptor, type IviStageSlotBinding, type IviStageViewContextValue, type IviSubtitleCompletedContext, type IviSubtitleCompletedHandler, type IviSubtitleCompletedReason, type IviSubtitleItem, type IviSubtitleRole, type IviSubtitleSource, type IviTelemetrySpanHandle, type IviUseSubtitlesOptions, LivekitSourceManager, TrtcSourceManager, type UseIviSessionRuntimeConfig, type UseIviSessionRuntimeResult, createIVISession, createIVISessionRuntime, createRuntimeFromSession, isLivekitSourcePlayback, isReadyLivekitRuntimeSource, isSameLivekitConfig, normalizeCreateIVISessionResponse, toCpCreateIVISessionRequestBody, useIviSessionRuntime, useIviStageView, useIviSubtitles, useManagedIviRuntime, useRuntimeState };