@kaltura-sdk/avatars 1.14.0 → 1.15.0

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/index.esm.js CHANGED
@@ -1,4 +1,4 @@
1
- import { UnisphereLoggerFactory, TinyDataStore, TinyPubSub, performanceMonitor, environmentResolver } from '@unisphere/core';
1
+ import { UnisphereLoggerFactory, TinyDataStore, TinyPubSub, performanceMonitor } from '@unisphere/core';
2
2
  import { getPartnerIdFromKs } from '@unisphere/runtime-js';
3
3
  import { DisconnectReasons, getAvatarDefaultCapabilities, resolveActiveContextType, AvatarConnectionStatus } from '@unisphere/genie-types';
4
4
  import { z as z$1 } from 'zod/mini';
@@ -6805,6 +6805,7 @@ const genieIntellectState = {
6805
6805
  logger: context.logger,
6806
6806
  getClientToolHandler: context.getClientToolHandler,
6807
6807
  ks: context.externalInfo.kaltura.ks,
6808
+ clientToolResponseUrl: context.externalInfo.runtimeSettings.clientToolResponseUrl,
6808
6809
  threadId: context.threadId
6809
6810
  })
6810
6811
  }
@@ -7607,6 +7608,9 @@ const connectingState = {
7607
7608
  },
7608
7609
  on: {
7609
7610
  [AvatarConnectionMachineEventTypes.ServerReadyReceived]: [{
7611
+ guard: 'shouldAutoJoinSTVPlayer',
7612
+ target: 'joiningSTVPlayer'
7613
+ }, {
7610
7614
  guard: 'shouldWaitPlayerReadyState',
7611
7615
  target: 'waitingPlayerReadyState'
7612
7616
  }, {
@@ -7614,6 +7618,39 @@ const connectingState = {
7614
7618
  }]
7615
7619
  }
7616
7620
  },
7621
+ joiningSTVPlayer: {
7622
+ invoke: {
7623
+ id: 'joinSTVPlayer',
7624
+ src: 'joinSTVPlayer',
7625
+ input: ({
7626
+ context
7627
+ }) => ({
7628
+ logger: context.logger,
7629
+ // videoContainerId presence is enforced by the shouldAutoJoinSTVPlayer guard
7630
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
7631
+ videoContainerId: context.externalInfo.videoContainerId,
7632
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
7633
+ sessionId: context.sessionId,
7634
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
7635
+ webrtcUrl: context.webrtcUrl
7636
+ }),
7637
+ onDone: {
7638
+ target: 'delayingBeforeConnect'
7639
+ },
7640
+ onError: {
7641
+ actions: {
7642
+ type: 'setDisconnectData',
7643
+ params: ({
7644
+ event
7645
+ }) => ({
7646
+ reason: DisconnectReasons.PlayerConnectionFailed,
7647
+ error: event.error
7648
+ })
7649
+ },
7650
+ target: 'error'
7651
+ }
7652
+ }
7653
+ },
7617
7654
  waitingPlayerReadyState: {
7618
7655
  invoke: {
7619
7656
  src: 'onPlayerReadyState',
@@ -19463,12 +19500,52 @@ const onPlayerReadyState = fromCallback(({
19463
19500
  });
19464
19501
  });
19465
19502
 
19503
+ /**
19504
+ * Auto-join the STV (webrtc) video stream into a caller-provided container
19505
+ * element, on behalf of consumers that configured `videoContainerId` on the
19506
+ * `AvatarClientManager` constructor instead of managing joinSTV/leaveSTV
19507
+ * themselves (e.g. avatar-react's STVPlayer keeps doing that manually and
19508
+ * never reaches this actor — see `shouldAutoJoinSTVPlayer`).
19509
+ *
19510
+ * Resolves once the STV peer connection is established (mirrors the
19511
+ * `onConnected` callback consumers pass to `joinSTV` directly), not merely
19512
+ * once WebRTC signaling completes.
19513
+ */
19514
+ const joinSTVPlayer = fromPromise(_a => __awaiter(void 0, [_a], void 0, function* ({
19515
+ input
19516
+ }) {
19517
+ const {
19518
+ logger,
19519
+ videoContainerId,
19520
+ sessionId,
19521
+ webrtcUrl
19522
+ } = input;
19523
+ logger.log('Auto-joining STV player...', {
19524
+ data: {
19525
+ videoContainerId,
19526
+ sessionId
19527
+ }
19528
+ });
19529
+ yield new Promise((resolve, reject) => {
19530
+ avatarRTCClientManager.joinSTV(videoContainerId, sessionId, webrtcUrl, () => {
19531
+ logger.log('STV player auto-joined and connected');
19532
+ resolve();
19533
+ }).catch(reject);
19534
+ });
19535
+ }));
19536
+
19466
19537
  const shouldWaitPlayerReadyState = ({
19467
19538
  context
19468
19539
  }) => {
19469
19540
  return context.externalInfo.waitPlayerReadyState === true;
19470
19541
  };
19471
19542
 
19543
+ const shouldAutoJoinSTVPlayer = ({
19544
+ context
19545
+ }) => {
19546
+ return context.castMode === 'webrtc' && !!context.externalInfo.videoContainerId;
19547
+ };
19548
+
19472
19549
  const setContentData = assign$1(({
19473
19550
  context,
19474
19551
  event
@@ -22597,11 +22674,10 @@ const resolveServerConfig = fromPromise(_a => __awaiter(void 0, [_a], void 0, fu
22597
22674
  logger
22598
22675
  } = input;
22599
22676
  if (runtimeSettings.serverConfig === 'studio') {
22600
- const agenticServerUrl = environmentResolver.getFriendlyRegionUrl({
22601
- serviceName: 'api.avatar',
22602
- type: 'microservice',
22603
- domainSuffix: 'ai'
22604
- });
22677
+ if (!runtimeSettings.agenticServerUrl) {
22678
+ throw new Error('Studio mode requires runtimeSettings.agenticServerUrl to be set (the api.avatar service URL)');
22679
+ }
22680
+ const agenticServerUrl = runtimeSettings.agenticServerUrl;
22605
22681
  logger.log('Studio mode: fetching server config from appInit');
22606
22682
  const appInitRes = yield fetch(`${agenticServerUrl}/v1/application/appInit`, {
22607
22683
  method: 'POST',
@@ -22881,10 +22957,6 @@ const onAgentClientToolCall = fromCallback(({
22881
22957
  input,
22882
22958
  sendBack
22883
22959
  }) => {
22884
- const genieServerUrl = environmentResolver.getKalturaServerUrl({
22885
- serviceName: 'genie',
22886
- type: 'microservice'
22887
- });
22888
22960
  return createTinyPubsubEventsHandler({
22889
22961
  source: source$1,
22890
22962
  logger: input.logger,
@@ -22948,13 +23020,18 @@ const onAgentClientToolCall = fromCallback(({
22948
23020
  void executeClientToolCall({
22949
23021
  toolMetadata,
22950
23022
  getToolHandler: input.getClientToolHandler,
22951
- sendToolResponse: (toolId, toolName, response) => sendClientToolResponse({
22952
- genieServerUrl,
22953
- ks: input.ks,
22954
- toolId,
22955
- toolName,
22956
- response
22957
- }),
23023
+ sendToolResponse: (toolId, toolName, response) => {
23024
+ if (!input.clientToolResponseUrl) {
23025
+ return Promise.reject(new Error('Cannot send client tool call response: runtimeSettings.clientToolResponseUrl is not configured'));
23026
+ }
23027
+ return sendClientToolResponse({
23028
+ url: input.clientToolResponseUrl,
23029
+ ks: input.ks,
23030
+ toolId,
23031
+ toolName,
23032
+ response
23033
+ });
23034
+ },
22958
23035
  logger: input.logger,
22959
23036
  onCompleted: (toolName, waitForResponse) => {
22960
23037
  sendBack({
@@ -23289,6 +23366,7 @@ const avatarConnectionMachine = setup({
23289
23366
  onConversationEnded,
23290
23367
  onError,
23291
23368
  onPlayerReadyState,
23369
+ joinSTVPlayer,
23292
23370
  onAgentTalking,
23293
23371
  onAgentRawText,
23294
23372
  onConversationTimeWarning,
@@ -23317,6 +23395,7 @@ const avatarConnectionMachine = setup({
23317
23395
  hasMoreRecoveryRetries,
23318
23396
  justExceededRecoveryRetries,
23319
23397
  shouldWaitPlayerReadyState,
23398
+ shouldAutoJoinSTVPlayer,
23320
23399
  shouldDisconnect,
23321
23400
  shouldWaitBeforePurge,
23322
23401
  shouldCreateWebsocketConnection,
@@ -23355,6 +23434,7 @@ const avatarConnectionMachine = setup({
23355
23434
  debugMode: input.debugMode,
23356
23435
  level: (_b = input.level) !== null && _b !== void 0 ? _b : 'published',
23357
23436
  waitPlayerReadyState: (_c = input.waitPlayerReadyState) !== null && _c !== void 0 ? _c : true,
23437
+ videoContainerId: input.videoContainerId,
23358
23438
  kaltura: input.runtimeSettings.kaltura,
23359
23439
  features: Object.assign(Object.assign({}, input.runtimeSettings.features), {
23360
23440
  kickOffPhrase: (_d = input.kickOffPhrase) !== null && _d !== void 0 ? _d : (_e = input.runtimeSettings.features) === null || _e === void 0 ? void 0 : _e.kickOffPhrase
@@ -23947,6 +24027,7 @@ class AvatarClientManager extends ActorManager {
23947
24027
  showNotification: this._config.actions.showNotification
23948
24028
  },
23949
24029
  runtimeSettings: this._config.runtimeSettings,
24030
+ videoContainerId: this._config.videoContainerId,
23950
24031
  isInitialKalturaContextActive: this._isKalturaContextActive,
23951
24032
  dynamicVariables: options === null || options === void 0 ? void 0 : options.dynamicVariables,
23952
24033
  kickOffPhrase: options === null || options === void 0 ? void 0 : options.kickOffPhrase,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kaltura-sdk/avatars",
3
- "version": "1.14.0",
3
+ "version": "1.15.0",
4
4
  "author": "kaltura",
5
5
  "license": "AGPL-3.0",
6
6
  "repository": {
@@ -13,7 +13,7 @@
13
13
  "@kaltura-sdk/rtc-core": "^1.25.16",
14
14
  "@local/genie-shared-utils": "^1.0.0",
15
15
  "@unisphere/core": "^1.99.0",
16
- "@unisphere/genie-types": "^1.39.0",
16
+ "@unisphere/genie-types": "^1.39.1",
17
17
  "@unisphere/notifications-core": "^1.25.0",
18
18
  "@unisphere/runtime": "^1.98.0",
19
19
  "@unisphere/runtime-js": "^1.96.0",
@@ -66,6 +66,8 @@ export declare class AvatarClientManager extends ActorManager<AvatarConnectionAc
66
66
  runtimeSettings: AvatarRuntimeSettings;
67
67
  /** Optional hook for wiring up devtools/machine-inspector logging; left unset outside the Unisphere widget host. */
68
68
  registerDeveloperTools?: (actor: AvatarConnectionActor) => void;
69
+ /** DOM element id of a container div the SDK should inject its `<video>` element into and auto-join the STV stream against, once castMode is 'webrtc'. Omit to keep managing joinSTV/leaveSTV externally (e.g. avatar-react's STVPlayer). */
70
+ videoContainerId?: string;
69
71
  });
70
72
  protected _syncDerivedState(snapshot: ConnectionSnapshot): void;
71
73
  protected _isTerminalSnapshot(snapshot: ConnectionSnapshot): boolean;
@@ -0,0 +1,22 @@
1
+ import { UnisphereLoggerType } from '@unisphere/core';
2
+ /**
3
+ * Input parameters for the joinSTVPlayer actor
4
+ */
5
+ export interface JoinSTVPlayerInput {
6
+ logger: UnisphereLoggerType;
7
+ videoContainerId: string;
8
+ sessionId: string;
9
+ webrtcUrl: string;
10
+ }
11
+ /**
12
+ * Auto-join the STV (webrtc) video stream into a caller-provided container
13
+ * element, on behalf of consumers that configured `videoContainerId` on the
14
+ * `AvatarClientManager` constructor instead of managing joinSTV/leaveSTV
15
+ * themselves (e.g. avatar-react's STVPlayer keeps doing that manually and
16
+ * never reaches this actor — see `shouldAutoJoinSTVPlayer`).
17
+ *
18
+ * Resolves once the STV peer connection is established (mirrors the
19
+ * `onConnected` callback consumers pass to `joinSTV` directly), not merely
20
+ * once WebRTC signaling completes.
21
+ */
22
+ export declare const joinSTVPlayer: import("xstate").PromiseActorLogic<void, JoinSTVPlayerInput, import("xstate").EventObject>;
@@ -4,6 +4,8 @@ type OnAgentClientToolCallInput = {
4
4
  logger: UnisphereLoggerType;
5
5
  getClientToolHandler: GetAvatarClientToolHandler;
6
6
  ks: string;
7
+ /** Full URL to POST client-tool-call responses to — see `AvatarRuntimeSettings.clientToolResponseUrl`. Required for client tool calls to receive a response; if omitted, tool call responses fail with a `delivery-error`. */
8
+ clientToolResponseUrl?: string;
7
9
  threadId: string | null;
8
10
  };
9
11
  export declare const onAgentClientToolCall: import("xstate").CallbackActorLogic<AgentClientToolCallCompletedEvent | AgentClientToolCallLoggedEvent, OnAgentClientToolCallInput, import("xstate").EventObject>;
@@ -37,7 +37,7 @@ export declare const avatarConnectionMachine: import("xstate").StateMachine<Avat
37
37
  logger: import("@unisphere/core").UnisphereLoggerType;
38
38
  }, import("xstate").EventObject>> | import("xstate").ActorRefFromLogic<import("xstate").CallbackActorLogic<import("./types").PlayerReadyEvent, {
39
39
  logger: import("@unisphere/core").UnisphereLoggerType;
40
- }, import("xstate").EventObject>> | import("xstate").ActorRefFromLogic<import("xstate").CallbackActorLogic<import("./types").AgentStartedTalkingReceivedEvent | import("./types").AgentFinishedTalkingReceivedEvent, {
40
+ }, import("xstate").EventObject>> | import("xstate").ActorRefFromLogic<import("xstate").PromiseActorLogic<void, import("./actors/join-stv-player").JoinSTVPlayerInput, import("xstate").EventObject>> | import("xstate").ActorRefFromLogic<import("xstate").CallbackActorLogic<import("./types").AgentStartedTalkingReceivedEvent | import("./types").AgentFinishedTalkingReceivedEvent, {
41
41
  logger: import("@unisphere/core").UnisphereLoggerType;
42
42
  }, import("xstate").EventObject>> | import("xstate").ActorRefFromLogic<import("xstate").CallbackActorLogic<import("./types").AgentRawTextMessageCompletedEvent, {
43
43
  logger: import("@unisphere/core").UnisphereLoggerType;
@@ -75,6 +75,7 @@ export declare const avatarConnectionMachine: import("xstate").StateMachine<Avat
75
75
  logger: import("@unisphere/core").UnisphereLoggerType;
76
76
  getClientToolHandler: import("dist/unisphere/packages/local/shared-utils/src").GetClientToolHandler;
77
77
  ks: string;
78
+ clientToolResponseUrl?: string | undefined;
78
79
  threadId: string | null;
79
80
  }, import("xstate").EventObject>> | import("xstate").ActorRefFromLogic<import("xstate").CallbackActorLogic<import("./types").TapToTalkButtonShownEvent | import("./types").TapToTalkButtonHiddenEvent, {
80
81
  logger: import("@unisphere/core").UnisphereLoggerType;
@@ -174,6 +175,10 @@ export declare const avatarConnectionMachine: import("xstate").StateMachine<Avat
174
175
  logger: import("@unisphere/core").UnisphereLoggerType;
175
176
  }, import("xstate").EventObject>;
176
177
  id: string | undefined;
178
+ } | {
179
+ src: "joinSTVPlayer";
180
+ logic: import("xstate").PromiseActorLogic<void, import("./actors/join-stv-player").JoinSTVPlayerInput, import("xstate").EventObject>;
181
+ id: string | undefined;
177
182
  } | {
178
183
  src: "onAgentTalking";
179
184
  logic: import("xstate").CallbackActorLogic<import("./types").AgentStartedTalkingReceivedEvent | import("./types").AgentFinishedTalkingReceivedEvent, {
@@ -282,6 +287,7 @@ export declare const avatarConnectionMachine: import("xstate").StateMachine<Avat
282
287
  logger: import("@unisphere/core").UnisphereLoggerType;
283
288
  getClientToolHandler: import("dist/unisphere/packages/local/shared-utils/src").GetClientToolHandler;
284
289
  ks: string;
290
+ clientToolResponseUrl?: string | undefined;
285
291
  threadId: string | null;
286
292
  }, import("xstate").EventObject>;
287
293
  id: string | undefined;
@@ -544,6 +550,9 @@ export declare const avatarConnectionMachine: import("xstate").StateMachine<Avat
544
550
  } | {
545
551
  type: "shouldWaitPlayerReadyState";
546
552
  params: unknown;
553
+ } | {
554
+ type: "shouldAutoJoinSTVPlayer";
555
+ params: unknown;
547
556
  } | {
548
557
  type: "shouldDisconnect";
549
558
  params: unknown;
@@ -592,7 +601,7 @@ export declare const avatarConnectionMachine: import("xstate").StateMachine<Avat
592
601
  }, never, "error" | "devicePermissionsDenied" | {
593
602
  preparing: "done" | "resolvingConfig" | "gettingUserAgentData" | "retryingConfig";
594
603
  } | {
595
- connecting: "error" | "done" | "initializingRTCSession" | "gettingUserMedia" | "connectingWebsocket" | "waitingServerConnect" | "creatingSession" | "waitingForAgent" | "reconnectingFromExpiry" | "waitingServerReady" | "waitingPlayerReadyState" | "connectingToASR" | "delayingBeforeConnect" | {
604
+ connecting: "error" | "done" | "initializingRTCSession" | "gettingUserMedia" | "connectingWebsocket" | "waitingServerConnect" | "creatingSession" | "waitingForAgent" | "reconnectingFromExpiry" | "waitingServerReady" | "joiningSTVPlayer" | "waitingPlayerReadyState" | "connectingToASR" | "delayingBeforeConnect" | {
596
605
  joiningRoom: {
597
606
  waitingClientConfiguration: "done" | "waiting";
598
607
  waitingJoinComplete: "done" | "waiting";
@@ -663,6 +672,7 @@ export declare const avatarConnectionMachine: import("xstate").StateMachine<Avat
663
672
  reconnectingFromExpiry: {};
664
673
  waitingForAgent: {};
665
674
  waitingServerReady: {};
675
+ joiningSTVPlayer: {};
666
676
  waitingPlayerReadyState: {};
667
677
  delayingBeforeConnect: {};
668
678
  connectingToASR: {};
@@ -0,0 +1,4 @@
1
+ import { AvatarConnectionMachineContext } from '../types';
2
+ export declare const shouldAutoJoinSTVPlayer: ({ context, }: {
3
+ context: AvatarConnectionMachineContext;
4
+ }) => boolean;
@@ -562,6 +562,7 @@ export declare const connectedState: {
562
562
  logger: import("@unisphere/core").UnisphereLoggerType;
563
563
  getClientToolHandler: import("dist/unisphere/packages/local/shared-utils/src").GetClientToolHandler;
564
564
  ks: string;
565
+ clientToolResponseUrl: string | undefined;
565
566
  threadId: string | null;
566
567
  };
567
568
  };
@@ -21,6 +21,7 @@ export declare const genieIntellectState: {
21
21
  logger: import("@unisphere/core").UnisphereLoggerType;
22
22
  getClientToolHandler: import("dist/unisphere/packages/local/shared-utils/src").GetClientToolHandler;
23
23
  ks: string;
24
+ clientToolResponseUrl: string | undefined;
24
25
  threadId: string | null;
25
26
  };
26
27
  };
@@ -317,6 +317,9 @@ export declare const connectingState: {
317
317
  };
318
318
  on: {
319
319
  ServerReadyReceived: ({
320
+ guard: "shouldAutoJoinSTVPlayer";
321
+ target: string;
322
+ } | {
320
323
  guard: "shouldWaitPlayerReadyState";
321
324
  target: string;
322
325
  } | {
@@ -325,6 +328,37 @@ export declare const connectingState: {
325
328
  })[];
326
329
  };
327
330
  };
331
+ joiningSTVPlayer: {
332
+ invoke: {
333
+ id: string;
334
+ src: "joinSTVPlayer";
335
+ input: ({ context }: {
336
+ context: import("../types").AvatarConnectionMachineContext;
337
+ event: import("../types").AvatarConnectionMachineEvents;
338
+ self: import("xstate").ActorRef<import("xstate").MachineSnapshot<import("../types").AvatarConnectionMachineContext, import("../types").AvatarConnectionMachineEvents, Record<string, import("xstate").AnyActorRef>, import("xstate").StateValue, string, unknown, any, any>, import("../types").AvatarConnectionMachineEvents, import("xstate").AnyEventObject>;
339
+ }) => {
340
+ logger: import("@unisphere/core").UnisphereLoggerType;
341
+ videoContainerId: string;
342
+ sessionId: string;
343
+ webrtcUrl: string;
344
+ };
345
+ onDone: {
346
+ target: string;
347
+ };
348
+ onError: {
349
+ actions: {
350
+ type: "setDisconnectData";
351
+ params: ({ event }: {
352
+ event: ErrorActorEvent;
353
+ }) => {
354
+ reason: DisconnectReasons;
355
+ error: Error;
356
+ };
357
+ };
358
+ target: string;
359
+ };
360
+ };
361
+ };
328
362
  waitingPlayerReadyState: {
329
363
  invoke: {
330
364
  src: "onPlayerReadyState";
@@ -20,6 +20,7 @@ export interface AvatarConnectionMachineContext {
20
20
  debugMode: boolean;
21
21
  level: string;
22
22
  waitPlayerReadyState: boolean;
23
+ videoContainerId?: string;
23
24
  kaltura: {
24
25
  ks: string;
25
26
  context?: ChatContext;
@@ -20,6 +20,8 @@ export interface AvatarConnectionMachineInput {
20
20
  stickyId?: string;
21
21
  level?: string;
22
22
  waitPlayerReadyState?: boolean;
23
+ /** DOM element id of a container div the SDK should inject its `<video>` element into and auto-join the STV stream against, once castMode is 'webrtc'. Omit to keep managing joinSTV/leaveSTV externally (e.g. avatar-react's STVPlayer). */
24
+ videoContainerId?: string;
23
25
  isInitialKalturaContextActive?: boolean;
24
26
  threadId?: string;
25
27
  messageId?: string;