@vivix-ai/ivi-frontend-sdk 0.3.1 → 0.3.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.cts CHANGED
@@ -62,6 +62,16 @@ interface IviRuntimeLogEntry {
62
62
  data?: unknown;
63
63
  }
64
64
  type IviRuntimeLogCallback = (entry: IviRuntimeLogEntry) => void;
65
+ type IviRuntimeTrtcEventType = "remote_video_available" | "remote_video_unavailable" | "remote_audio_available" | "remote_audio_unavailable";
66
+ interface IviRuntimeTrtcEvent {
67
+ sourceId: string;
68
+ type: IviRuntimeTrtcEventType;
69
+ rawType: string;
70
+ payload: unknown;
71
+ userId?: string;
72
+ streamType?: unknown;
73
+ }
74
+ type IviRuntimeTrtcEventListener = (event: IviRuntimeTrtcEvent) => void;
65
75
  type IviRuntimeConversationLifecycle = "added" | "done";
66
76
  type IviRuntimeConversationStatus = "in_progress" | "completed" | "incomplete";
67
77
  interface IviRuntimeConversationItem {
@@ -89,6 +99,10 @@ interface IviRuntimeCoordinatorConfig {
89
99
  * Runtime 内部链路日志回调;未传入时不输出日志。
90
100
  */
91
101
  onLog?: IviRuntimeLogCallback;
102
+ /**
103
+ * TRTC SDK 原始事件回调;可用于业务监听远端音视频可用性等底层事件。
104
+ */
105
+ onTrtcEvent?: IviRuntimeTrtcEventListener;
92
106
  }
93
107
  /**
94
108
  * 用户输入触发回复链路配置。
@@ -162,9 +176,10 @@ interface TrtcSourceSnapshot {
162
176
  type TrtcSourceListener = (snapshot: TrtcSourceSnapshot) => void;
163
177
  declare class TrtcSourceManager {
164
178
  private readonly onLog?;
179
+ private readonly onTrtcEvent?;
165
180
  private readonly sessions;
166
181
  private readonly listeners;
167
- constructor(onLog?: IviRuntimeLogCallback | undefined);
182
+ constructor(onLog?: IviRuntimeLogCallback | undefined, onTrtcEvent?: IviRuntimeTrtcEventListener | undefined);
168
183
  /**
169
184
  * 将 runtime 当前 sources 与 TRTC 会话池对齐:
170
185
  * - 对 ready + trtc 的 source 进行 upsert(必要时建立连接)
@@ -224,6 +239,7 @@ declare class TrtcSourceManager {
224
239
  private disposeSession;
225
240
  private emitSnapshot;
226
241
  private log;
242
+ private emitTrtcEvent;
227
243
  }
228
244
 
229
245
  /**
@@ -380,6 +396,7 @@ declare class IviRuntimeCoordinator {
380
396
  private readonly conversationHandler;
381
397
  private readonly stateListeners;
382
398
  private readonly eventListeners;
399
+ private readonly trtcEventListeners;
383
400
  private readonly pendingUserTextToResponseFlows;
384
401
  private userTextFlowCounter;
385
402
  private waitingTracksListValidation;
@@ -402,6 +419,7 @@ declare class IviRuntimeCoordinator {
402
419
  getState(): IviRuntimeState;
403
420
  onStateChange(listener: (state: IviRuntimeState) => void): () => void;
404
421
  onEvent(listener: IviRuntimeEventListener): () => void;
422
+ onTrtcEvent(listener: IviRuntimeTrtcEventListener): () => void;
405
423
  emitLog(entry: IviRuntimeLogEntry): void;
406
424
  /**
407
425
  * 编排一次"用户文本输入 -> 触发模型回复"链路。
@@ -440,6 +458,7 @@ declare class IviRuntimeCoordinator {
440
458
  private onConversationsChanged;
441
459
  private setState;
442
460
  private emitEvent;
461
+ private emitTrtcEvent;
443
462
  private resetStoppedState;
444
463
  private ensureSourcesSyncedForTracks;
445
464
  private validateSourcesListRefreshed;
@@ -705,4 +724,4 @@ declare function useManagedIviRuntime(config: IviManagedRuntimeConfig): IviRunti
705
724
 
706
725
  declare function useIviStageView(): IviStageViewContextValue;
707
726
 
708
- export { EMPTY_RUNTIME_STATE, IVILivekitPlayer, type IVILivekitPlayerProps, IVIStageView, type IVIStageViewProps, IVISubtitleOverlay, type IVISubtitleOverlayProps, type IVISubtitleOverlayStyle, IVITrackSlot, type IVITrackSlotProps, IVITrtcPlayer, type IVITrtcPlayerProps, 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 IviRuntimeUserTextToResponseCallbacks, type IviRuntimeUserTextToResponseOptions, type IviRuntimeUserTextToResponseResult, type IviSourcePlaybackLivekit, type IviSourcePlaybackLivekitDescriptor, type IviStageSlotBinding, type IviStageViewContextValue, type IviSubtitleItem, type IviSubtitleRole, type IviUseSubtitlesOptions, LivekitSourceManager, TrtcSourceManager, isLivekitSourcePlayback, isReadyLivekitRuntimeSource, isSameLivekitConfig, useIviStageView, useIviSubtitles, useManagedIviRuntime, useRuntimeState };
727
+ export { EMPTY_RUNTIME_STATE, IVILivekitPlayer, type IVILivekitPlayerProps, IVIStageView, type IVIStageViewProps, IVISubtitleOverlay, type IVISubtitleOverlayProps, type IVISubtitleOverlayStyle, IVITrackSlot, type IVITrackSlotProps, IVITrtcPlayer, type IVITrtcPlayerProps, 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 IviRuntimeTrtcEvent, type IviRuntimeTrtcEventListener, type IviRuntimeTrtcEventType, type IviRuntimeUserTextToResponseCallbacks, type IviRuntimeUserTextToResponseOptions, type IviRuntimeUserTextToResponseResult, type IviSourcePlaybackLivekit, type IviSourcePlaybackLivekitDescriptor, type IviStageSlotBinding, type IviStageViewContextValue, type IviSubtitleItem, type IviSubtitleRole, type IviUseSubtitlesOptions, LivekitSourceManager, TrtcSourceManager, isLivekitSourcePlayback, isReadyLivekitRuntimeSource, isSameLivekitConfig, useIviStageView, useIviSubtitles, useManagedIviRuntime, useRuntimeState };
package/dist/index.d.ts CHANGED
@@ -62,6 +62,16 @@ interface IviRuntimeLogEntry {
62
62
  data?: unknown;
63
63
  }
64
64
  type IviRuntimeLogCallback = (entry: IviRuntimeLogEntry) => void;
65
+ type IviRuntimeTrtcEventType = "remote_video_available" | "remote_video_unavailable" | "remote_audio_available" | "remote_audio_unavailable";
66
+ interface IviRuntimeTrtcEvent {
67
+ sourceId: string;
68
+ type: IviRuntimeTrtcEventType;
69
+ rawType: string;
70
+ payload: unknown;
71
+ userId?: string;
72
+ streamType?: unknown;
73
+ }
74
+ type IviRuntimeTrtcEventListener = (event: IviRuntimeTrtcEvent) => void;
65
75
  type IviRuntimeConversationLifecycle = "added" | "done";
66
76
  type IviRuntimeConversationStatus = "in_progress" | "completed" | "incomplete";
67
77
  interface IviRuntimeConversationItem {
@@ -89,6 +99,10 @@ interface IviRuntimeCoordinatorConfig {
89
99
  * Runtime 内部链路日志回调;未传入时不输出日志。
90
100
  */
91
101
  onLog?: IviRuntimeLogCallback;
102
+ /**
103
+ * TRTC SDK 原始事件回调;可用于业务监听远端音视频可用性等底层事件。
104
+ */
105
+ onTrtcEvent?: IviRuntimeTrtcEventListener;
92
106
  }
93
107
  /**
94
108
  * 用户输入触发回复链路配置。
@@ -162,9 +176,10 @@ interface TrtcSourceSnapshot {
162
176
  type TrtcSourceListener = (snapshot: TrtcSourceSnapshot) => void;
163
177
  declare class TrtcSourceManager {
164
178
  private readonly onLog?;
179
+ private readonly onTrtcEvent?;
165
180
  private readonly sessions;
166
181
  private readonly listeners;
167
- constructor(onLog?: IviRuntimeLogCallback | undefined);
182
+ constructor(onLog?: IviRuntimeLogCallback | undefined, onTrtcEvent?: IviRuntimeTrtcEventListener | undefined);
168
183
  /**
169
184
  * 将 runtime 当前 sources 与 TRTC 会话池对齐:
170
185
  * - 对 ready + trtc 的 source 进行 upsert(必要时建立连接)
@@ -224,6 +239,7 @@ declare class TrtcSourceManager {
224
239
  private disposeSession;
225
240
  private emitSnapshot;
226
241
  private log;
242
+ private emitTrtcEvent;
227
243
  }
228
244
 
229
245
  /**
@@ -380,6 +396,7 @@ declare class IviRuntimeCoordinator {
380
396
  private readonly conversationHandler;
381
397
  private readonly stateListeners;
382
398
  private readonly eventListeners;
399
+ private readonly trtcEventListeners;
383
400
  private readonly pendingUserTextToResponseFlows;
384
401
  private userTextFlowCounter;
385
402
  private waitingTracksListValidation;
@@ -402,6 +419,7 @@ declare class IviRuntimeCoordinator {
402
419
  getState(): IviRuntimeState;
403
420
  onStateChange(listener: (state: IviRuntimeState) => void): () => void;
404
421
  onEvent(listener: IviRuntimeEventListener): () => void;
422
+ onTrtcEvent(listener: IviRuntimeTrtcEventListener): () => void;
405
423
  emitLog(entry: IviRuntimeLogEntry): void;
406
424
  /**
407
425
  * 编排一次"用户文本输入 -> 触发模型回复"链路。
@@ -440,6 +458,7 @@ declare class IviRuntimeCoordinator {
440
458
  private onConversationsChanged;
441
459
  private setState;
442
460
  private emitEvent;
461
+ private emitTrtcEvent;
443
462
  private resetStoppedState;
444
463
  private ensureSourcesSyncedForTracks;
445
464
  private validateSourcesListRefreshed;
@@ -705,4 +724,4 @@ declare function useManagedIviRuntime(config: IviManagedRuntimeConfig): IviRunti
705
724
 
706
725
  declare function useIviStageView(): IviStageViewContextValue;
707
726
 
708
- export { EMPTY_RUNTIME_STATE, IVILivekitPlayer, type IVILivekitPlayerProps, IVIStageView, type IVIStageViewProps, IVISubtitleOverlay, type IVISubtitleOverlayProps, type IVISubtitleOverlayStyle, IVITrackSlot, type IVITrackSlotProps, IVITrtcPlayer, type IVITrtcPlayerProps, 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 IviRuntimeUserTextToResponseCallbacks, type IviRuntimeUserTextToResponseOptions, type IviRuntimeUserTextToResponseResult, type IviSourcePlaybackLivekit, type IviSourcePlaybackLivekitDescriptor, type IviStageSlotBinding, type IviStageViewContextValue, type IviSubtitleItem, type IviSubtitleRole, type IviUseSubtitlesOptions, LivekitSourceManager, TrtcSourceManager, isLivekitSourcePlayback, isReadyLivekitRuntimeSource, isSameLivekitConfig, useIviStageView, useIviSubtitles, useManagedIviRuntime, useRuntimeState };
727
+ export { EMPTY_RUNTIME_STATE, IVILivekitPlayer, type IVILivekitPlayerProps, IVIStageView, type IVIStageViewProps, IVISubtitleOverlay, type IVISubtitleOverlayProps, type IVISubtitleOverlayStyle, IVITrackSlot, type IVITrackSlotProps, IVITrtcPlayer, type IVITrtcPlayerProps, 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 IviRuntimeTrtcEvent, type IviRuntimeTrtcEventListener, type IviRuntimeTrtcEventType, type IviRuntimeUserTextToResponseCallbacks, type IviRuntimeUserTextToResponseOptions, type IviRuntimeUserTextToResponseResult, type IviSourcePlaybackLivekit, type IviSourcePlaybackLivekitDescriptor, type IviStageSlotBinding, type IviStageViewContextValue, type IviSubtitleItem, type IviSubtitleRole, type IviUseSubtitlesOptions, LivekitSourceManager, TrtcSourceManager, isLivekitSourcePlayback, isReadyLivekitRuntimeSource, isSameLivekitConfig, useIviStageView, useIviSubtitles, useManagedIviRuntime, useRuntimeState };
package/dist/index.js CHANGED
@@ -1106,8 +1106,9 @@ var ConversationManager = class {
1106
1106
  // src/runtime/managers/trtc-source-manager.ts
1107
1107
  var TAG = "[IVI-TRTC]";
1108
1108
  var TrtcSourceManager = class {
1109
- constructor(onLog) {
1109
+ constructor(onLog, onTrtcEvent) {
1110
1110
  this.onLog = onLog;
1111
+ this.onTrtcEvent = onTrtcEvent;
1111
1112
  this.sessions = /* @__PURE__ */ new Map();
1112
1113
  this.listeners = /* @__PURE__ */ new Map();
1113
1114
  }
@@ -1343,6 +1344,7 @@ var TrtcSourceManager = class {
1343
1344
  session.views.forEach((binding) => {
1344
1345
  void this.startRemoteVideoForBinding(client, event.userId, event.streamType, binding, remoteVideoKey);
1345
1346
  });
1347
+ this.emitTrtcEvent(session.sourceId, "remote_video_available", TRTC.EVENT.REMOTE_VIDEO_AVAILABLE, event);
1346
1348
  };
1347
1349
  const onRemoteVideoUnavailable = (event) => {
1348
1350
  this.log("info", `\u8FDC\u7AEF\u89C6\u9891\u4E0D\u53EF\u7528 source=${session.sourceId} userId=${event.userId} streamType=${event.streamType}`);
@@ -1356,16 +1358,19 @@ var TrtcSourceManager = class {
1356
1358
  userId: event.userId,
1357
1359
  streamType: event.streamType
1358
1360
  }).catch(() => void 0);
1361
+ this.emitTrtcEvent(session.sourceId, "remote_video_unavailable", TRTC.EVENT.REMOTE_VIDEO_UNAVAILABLE, event);
1359
1362
  };
1360
1363
  const onRemoteAudioAvailable = (event) => {
1361
1364
  this.log("info", `\u8FDC\u7AEF\u97F3\u9891\u53EF\u7528 source=${session.sourceId} userId=${event.userId}`);
1362
1365
  session.remoteAudioUsers.add(event.userId);
1363
1366
  void this.applyAudioPolicy(session);
1367
+ this.emitTrtcEvent(session.sourceId, "remote_audio_available", TRTC.EVENT.REMOTE_AUDIO_AVAILABLE, event);
1364
1368
  };
1365
1369
  const onRemoteAudioUnavailable = (event) => {
1366
1370
  this.log("info", `\u8FDC\u7AEF\u97F3\u9891\u4E0D\u53EF\u7528 source=${session.sourceId} userId=${event.userId}`);
1367
1371
  session.remoteAudioUsers.delete(event.userId);
1368
1372
  void this.applyAudioPolicy(session);
1373
+ this.emitTrtcEvent(session.sourceId, "remote_audio_unavailable", TRTC.EVENT.REMOTE_AUDIO_UNAVAILABLE, event);
1369
1374
  };
1370
1375
  session.onRemoteVideoAvailable = onRemoteVideoAvailable;
1371
1376
  session.onRemoteVideoUnavailable = onRemoteVideoUnavailable;
@@ -1538,6 +1543,17 @@ var TrtcSourceManager = class {
1538
1543
  data: extra.length > 0 ? { message, extra } : { message }
1539
1544
  });
1540
1545
  }
1546
+ emitTrtcEvent(sourceId, type, rawType, payload) {
1547
+ const event = {
1548
+ sourceId,
1549
+ type,
1550
+ rawType: String(rawType),
1551
+ payload,
1552
+ userId: payload.userId,
1553
+ streamType: payload.streamType
1554
+ };
1555
+ this.onTrtcEvent?.(event);
1556
+ }
1541
1557
  };
1542
1558
  function isRuntimeTrtcSource(source) {
1543
1559
  return source.status === "ready" && source.playback?.type === "trtc" && typeof source.playback.trtc === "object" && source.playback.trtc !== null;
@@ -2036,6 +2052,7 @@ var IviRuntimeCoordinator = class {
2036
2052
  this.conversationManager = new ConversationManager();
2037
2053
  this.stateListeners = /* @__PURE__ */ new Set();
2038
2054
  this.eventListeners = /* @__PURE__ */ new Set();
2055
+ this.trtcEventListeners = /* @__PURE__ */ new Set();
2039
2056
  this.pendingUserTextToResponseFlows = /* @__PURE__ */ new Map();
2040
2057
  this.userTextFlowCounter = 0;
2041
2058
  this.waitingTracksListValidation = false;
@@ -2055,7 +2072,10 @@ var IviRuntimeCoordinator = class {
2055
2072
  syncStageOnSessionCreated: true,
2056
2073
  ...config
2057
2074
  };
2058
- this.trtcSourceManager = new TrtcSourceManager(this.config.onLog);
2075
+ this.trtcSourceManager = new TrtcSourceManager(
2076
+ this.config.onLog,
2077
+ (event) => this.emitTrtcEvent(event)
2078
+ );
2059
2079
  this.livekitSourceManager = new LivekitSourceManager(this.config.onLog);
2060
2080
  this.sessionHandler = new SessionEventHandler(this.sessionManager, {
2061
2081
  onSessionCreated: (event) => this.onSessionCreated(event),
@@ -2128,6 +2148,12 @@ var IviRuntimeCoordinator = class {
2128
2148
  this.eventListeners.delete(listener);
2129
2149
  };
2130
2150
  }
2151
+ onTrtcEvent(listener) {
2152
+ this.trtcEventListeners.add(listener);
2153
+ return () => {
2154
+ this.trtcEventListeners.delete(listener);
2155
+ };
2156
+ }
2131
2157
  emitLog(entry) {
2132
2158
  this.config.onLog?.(entry);
2133
2159
  }
@@ -2382,6 +2408,10 @@ var IviRuntimeCoordinator = class {
2382
2408
  this.progressUserTextToResponseFlows(event);
2383
2409
  this.eventListeners.forEach((listener) => listener(event, this.state));
2384
2410
  }
2411
+ emitTrtcEvent(event) {
2412
+ this.config.onTrtcEvent?.(event);
2413
+ this.trtcEventListeners.forEach((listener) => listener(event));
2414
+ }
2385
2415
  resetStoppedState() {
2386
2416
  this.rejectPendingUserTextToResponseFlows(
2387
2417
  new Error("Runtime stopped before user text to response flow completed.")