@rtsdk/topia 0.19.5 → 0.19.6

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.cjs CHANGED
@@ -43665,7 +43665,13 @@ class Visitor extends User {
43665
43665
  createNpc(userInventoryItemId, options) {
43666
43666
  return __awaiter(this, void 0, void 0, function* () {
43667
43667
  try {
43668
- const response = yield this.topiaPublicApi().post(`/world/${this.urlSlug}/visitors/${this.id}/create-npc`, { userInventoryItemId, showNameplate: options === null || options === void 0 ? void 0 : options.showNameplate }, this.requestOptions);
43668
+ const response = yield this.topiaPublicApi().post(`/world/${this.urlSlug}/visitors/${this.id}/create-npc`, {
43669
+ userInventoryItemId,
43670
+ showNameplate: options === null || options === void 0 ? void 0 : options.showNameplate,
43671
+ stationary: options === null || options === void 0 ? void 0 : options.stationary,
43672
+ replace: options === null || options === void 0 ? void 0 : options.replace,
43673
+ spawnEffect: options === null || options === void 0 ? void 0 : options.spawnEffect,
43674
+ }, this.requestOptions);
43669
43675
  return new Visitor(this.topia, response.data.player.playerId, this.urlSlug, {
43670
43676
  attributes: response.data,
43671
43677
  credentials: this.credentials,
@@ -43710,6 +43716,77 @@ class Visitor extends User {
43710
43716
  }
43711
43717
  });
43712
43718
  }
43719
+ /**
43720
+ * Start an AI voice session for this visitor's NPC.
43721
+ *
43722
+ * @remarks
43723
+ * Establishes a real-time voice connection between the visitor and an AI backend
43724
+ * (currently OpenAI Realtime API) through the NPC. The NPC must already be spawned
43725
+ * via `createNpc()` before calling this method.
43726
+ *
43727
+ * The voice session occupies a video slot in the visitor's peer video grid, showing
43728
+ * the NPC's avatar image. Audio streams bidirectionally between the visitor's microphone
43729
+ * and the AI model. Only the NPC's owner hears the AI audio.
43730
+ *
43731
+ * Topia automatically prepends non-removable child safety guardrails to the instructions.
43732
+ * Only one voice session is allowed per visitor per world at a time.
43733
+ *
43734
+ * @keywords voice, npc, ai, chat, audio, realtime, session, start, speech
43735
+ *
43736
+ * @category NPCs
43737
+ *
43738
+ * @param config - Voice session configuration including ephemeral key and AI instructions
43739
+ *
43740
+ * @example
43741
+ * ```ts
43742
+ * const ephemeralKey = await generateOpenAIEphemeralKey();
43743
+ *
43744
+ * await visitor.startNpcVoiceSession({
43745
+ * ephemeralKey,
43746
+ * voice: "alloy",
43747
+ * instructions: "You are a friendly science tutor helping with photosynthesis.",
43748
+ * model: "gpt-4o-realtime-preview",
43749
+ * });
43750
+ * ```
43751
+ *
43752
+ * @returns {Promise<void | ResponseType>} Returns `{ success: true }` or an error.
43753
+ */
43754
+ startNpcVoiceSession(config) {
43755
+ return __awaiter(this, void 0, void 0, function* () {
43756
+ try {
43757
+ const response = yield this.topiaPublicApi().put(`/world/${this.urlSlug}/visitors/${this.id}/start-npc-voice-session`, { voiceConfig: config }, this.requestOptions);
43758
+ return response.data;
43759
+ }
43760
+ catch (error) {
43761
+ throw this.errorHandler({ error, params: config, sdkMethod: "Visitor.startNpcVoiceSession" });
43762
+ }
43763
+ });
43764
+ }
43765
+ /**
43766
+ * Stop the active AI voice session for this visitor's NPC.
43767
+ *
43768
+ * @keywords voice, npc, ai, chat, audio, realtime, session, stop, end
43769
+ *
43770
+ * @category NPCs
43771
+ *
43772
+ * @example
43773
+ * ```ts
43774
+ * await visitor.stopNpcVoiceSession();
43775
+ * ```
43776
+ *
43777
+ * @returns {Promise<void | ResponseType>} Returns `{ success: true }` or an error.
43778
+ */
43779
+ stopNpcVoiceSession() {
43780
+ return __awaiter(this, void 0, void 0, function* () {
43781
+ try {
43782
+ const response = yield this.topiaPublicApi().put(`/world/${this.urlSlug}/visitors/${this.id}/stop-npc-voice-session`, {}, this.requestOptions);
43783
+ return response.data;
43784
+ }
43785
+ catch (error) {
43786
+ throw this.errorHandler({ error, sdkMethod: "Visitor.stopNpcVoiceSession" });
43787
+ }
43788
+ });
43789
+ }
43713
43790
  /**
43714
43791
  * Retrieves all inventory items owned by this visitor and app's key.
43715
43792
  *
package/dist/index.d.ts CHANGED
@@ -2160,9 +2160,7 @@ declare class Visitor extends User implements VisitorInterface {
2160
2160
  *
2161
2161
  * @returns {Promise<Visitor>} Returns a Visitor object representing the created NPC. The NPC will automatically follow the visitor.
2162
2162
  */
2163
- createNpc(userInventoryItemId: string, options?: {
2164
- showNameplate?: boolean;
2165
- }): Promise<Visitor>;
2163
+ createNpc(userInventoryItemId: string, options?: CreateNpcOptions): Promise<Visitor>;
2166
2164
  /**
2167
2165
  * Deletes the NPC (Non-Player Character) this app has assigned to this visitor.
2168
2166
  *
@@ -2188,6 +2186,57 @@ declare class Visitor extends User implements VisitorInterface {
2188
2186
  * @returns {Promise<void>} Returns nothing if successful.
2189
2187
  */
2190
2188
  deleteNpc(): Promise<void>;
2189
+ /**
2190
+ * Start an AI voice session for this visitor's NPC.
2191
+ *
2192
+ * @remarks
2193
+ * Establishes a real-time voice connection between the visitor and an AI backend
2194
+ * (currently OpenAI Realtime API) through the NPC. The NPC must already be spawned
2195
+ * via `createNpc()` before calling this method.
2196
+ *
2197
+ * The voice session occupies a video slot in the visitor's peer video grid, showing
2198
+ * the NPC's avatar image. Audio streams bidirectionally between the visitor's microphone
2199
+ * and the AI model. Only the NPC's owner hears the AI audio.
2200
+ *
2201
+ * Topia automatically prepends non-removable child safety guardrails to the instructions.
2202
+ * Only one voice session is allowed per visitor per world at a time.
2203
+ *
2204
+ * @keywords voice, npc, ai, chat, audio, realtime, session, start, speech
2205
+ *
2206
+ * @category NPCs
2207
+ *
2208
+ * @param config - Voice session configuration including ephemeral key and AI instructions
2209
+ *
2210
+ * @example
2211
+ * ```ts
2212
+ * const ephemeralKey = await generateOpenAIEphemeralKey();
2213
+ *
2214
+ * await visitor.startNpcVoiceSession({
2215
+ * ephemeralKey,
2216
+ * voice: "alloy",
2217
+ * instructions: "You are a friendly science tutor helping with photosynthesis.",
2218
+ * model: "gpt-4o-realtime-preview",
2219
+ * });
2220
+ * ```
2221
+ *
2222
+ * @returns {Promise<void | ResponseType>} Returns `{ success: true }` or an error.
2223
+ */
2224
+ startNpcVoiceSession(config: NpcVoiceConfigInterface): Promise<void | ResponseType>;
2225
+ /**
2226
+ * Stop the active AI voice session for this visitor's NPC.
2227
+ *
2228
+ * @keywords voice, npc, ai, chat, audio, realtime, session, stop, end
2229
+ *
2230
+ * @category NPCs
2231
+ *
2232
+ * @example
2233
+ * ```ts
2234
+ * await visitor.stopNpcVoiceSession();
2235
+ * ```
2236
+ *
2237
+ * @returns {Promise<void | ResponseType>} Returns `{ success: true }` or an error.
2238
+ */
2239
+ stopNpcVoiceSession(): Promise<void | ResponseType>;
2191
2240
  /**
2192
2241
  * Retrieves all inventory items owned by this visitor and app's key.
2193
2242
  *
@@ -2649,11 +2698,11 @@ interface VisitorInterface extends SDKInterface {
2649
2698
  grantInventoryItem(item: InventoryItemInterface, quantity: number): Promise<UserInventoryItem>;
2650
2699
  modifyInventoryItemQuantity(item: UserInventoryItemInterface | InventoryItemInterface, quantity: number): Promise<UserInventoryItem>;
2651
2700
  fetchInventoryItem(item: InventoryItemInterface): Promise<UserInventoryItem>;
2652
- createNpc(userInventoryItemId: string, options?: {
2653
- showNameplate?: boolean;
2654
- }): Promise<Visitor>;
2701
+ createNpc(userInventoryItemId: string, options?: CreateNpcOptions): Promise<Visitor>;
2655
2702
  deleteNpc(): Promise<void>;
2656
2703
  getNpc(): Promise<Visitor | null>;
2704
+ startNpcVoiceSession(config: NpcVoiceConfigInterface): Promise<void | ResponseType>;
2705
+ stopNpcVoiceSession(): Promise<void | ResponseType>;
2657
2706
  triggerParticle({ id, name, duration, }: {
2658
2707
  id?: string;
2659
2708
  name?: string;
@@ -2710,6 +2759,39 @@ interface OpenIframeInterface {
2710
2759
  shouldOpenInDrawer?: boolean;
2711
2760
  title?: string;
2712
2761
  }
2762
+ interface SpawnEffectConfig {
2763
+ type?: "portal" | "none";
2764
+ colors?: number[];
2765
+ glowColor?: number;
2766
+ glowOpacity?: number;
2767
+ centerColor?: number;
2768
+ duration?: number;
2769
+ sectorCount?: number;
2770
+ gridSize?: number;
2771
+ }
2772
+ interface CreateNpcOptions {
2773
+ showNameplate?: boolean;
2774
+ stationary?: boolean;
2775
+ replace?: boolean;
2776
+ spawnEffect?: SpawnEffectConfig;
2777
+ }
2778
+ interface NpcVoiceConfigInterface {
2779
+ /** OpenAI ephemeral key (ek_*). Generated server-side, used once to establish WebRTC connection. */
2780
+ ephemeralKey: string;
2781
+ /** OpenAI voice ID (e.g., "alloy", "echo", "shimmer"). */
2782
+ voice: string;
2783
+ /** System prompt including curriculum context and behavioral instructions. */
2784
+ instructions: string;
2785
+ /** OpenAI model ID. Defaults to "gpt-4o-realtime-preview". */
2786
+ model?: string;
2787
+ /** Voice activity detection configuration. */
2788
+ turnDetection?: {
2789
+ type: "server_vad";
2790
+ threshold?: number;
2791
+ prefix_padding_ms?: number;
2792
+ silence_duration_ms?: number;
2793
+ };
2794
+ }
2713
2795
 
2714
2796
  interface WebhookInterface {
2715
2797
  webhookId?: string;
@@ -4185,4 +4267,4 @@ declare class WorldFactory extends SDKController {
4185
4267
  }>;
4186
4268
  }
4187
4269
 
4188
- export { AnalyticType, AnimationMetaType, Asset, AssetFactory, AssetInterface, AssetOptionalInterface, AssetOptions, AssetType, DroppedAsset, DroppedAssetClickType, DroppedAssetFactory, DroppedAssetInterface, DroppedAssetLinkType, DroppedAssetMediaType, DroppedAssetMediaVolumeRadius, DroppedAssetOptionalInterface, DroppedAssetOptions, Ecosystem, EcosystemFactory, EcosystemInterface, EcosystemOptionalInterface, FireToastInterface, FrameType, InteractiveCredentials$1 as InteractiveCredentials, InventoryItemInterface, InventoryItemOptionalInterface, MoveAllVisitorsInterface, MoveVisitorInterface, OpenIframeInterface, RemoveClickableLinkInterface, ResponseType, SDKController, SDKInterface, Scene, SceneFactory, SceneInterface, SceneOptionalInterface, SetClickableLinkMultiInterface, Topia, TopiaInterface, UpdateBroadcastInterface, UpdateClickTypeInterface, UpdateClickableLinkMultiInterface, UpdateDroppedAssetInterface, UpdateMediaTypeInterface, UpdatePrivateZoneInterface, User, UserFactory, UserInterface, UserInventoryItemInterface, UserInventoryItemMetadataType, UserInventoryItemOptionalInterface, UserOptionalInterface, UserOptions, Visitor, VisitorFactory, VisitorInterface, VisitorOptionalInterface, VisitorOptions, VisitorType, VisitorsToMoveArrayType, VisitorsToMoveType, WebRTCConnector, WebRTCConnectorFactory, WebRTCConnectorInterface, WebRTCConnectorOptionalInterface, WebhookInterface, World, WorldActivity, WorldActivityFactory, WorldActivityOptionalInterface, WorldActivityType, WorldDetailsInterface, WorldFactory, WorldInterface, WorldOptionalInterface, WorldOptions, WorldWebhooksInterface };
4270
+ export { AnalyticType, AnimationMetaType, Asset, AssetFactory, AssetInterface, AssetOptionalInterface, AssetOptions, AssetType, CreateNpcOptions, DroppedAsset, DroppedAssetClickType, DroppedAssetFactory, DroppedAssetInterface, DroppedAssetLinkType, DroppedAssetMediaType, DroppedAssetMediaVolumeRadius, DroppedAssetOptionalInterface, DroppedAssetOptions, Ecosystem, EcosystemFactory, EcosystemInterface, EcosystemOptionalInterface, FireToastInterface, FrameType, InteractiveCredentials$1 as InteractiveCredentials, InventoryItemInterface, InventoryItemOptionalInterface, MoveAllVisitorsInterface, MoveVisitorInterface, NpcVoiceConfigInterface, OpenIframeInterface, RemoveClickableLinkInterface, ResponseType, SDKController, SDKInterface, Scene, SceneFactory, SceneInterface, SceneOptionalInterface, SetClickableLinkMultiInterface, SpawnEffectConfig, Topia, TopiaInterface, UpdateBroadcastInterface, UpdateClickTypeInterface, UpdateClickableLinkMultiInterface, UpdateDroppedAssetInterface, UpdateMediaTypeInterface, UpdatePrivateZoneInterface, User, UserFactory, UserInterface, UserInventoryItemInterface, UserInventoryItemMetadataType, UserInventoryItemOptionalInterface, UserOptionalInterface, UserOptions, Visitor, VisitorFactory, VisitorInterface, VisitorOptionalInterface, VisitorOptions, VisitorType, VisitorsToMoveArrayType, VisitorsToMoveType, WebRTCConnector, WebRTCConnectorFactory, WebRTCConnectorInterface, WebRTCConnectorOptionalInterface, WebhookInterface, World, WorldActivity, WorldActivityFactory, WorldActivityOptionalInterface, WorldActivityType, WorldDetailsInterface, WorldFactory, WorldInterface, WorldOptionalInterface, WorldOptions, WorldWebhooksInterface };
package/dist/index.js CHANGED
@@ -43663,7 +43663,13 @@ class Visitor extends User {
43663
43663
  createNpc(userInventoryItemId, options) {
43664
43664
  return __awaiter(this, void 0, void 0, function* () {
43665
43665
  try {
43666
- const response = yield this.topiaPublicApi().post(`/world/${this.urlSlug}/visitors/${this.id}/create-npc`, { userInventoryItemId, showNameplate: options === null || options === void 0 ? void 0 : options.showNameplate }, this.requestOptions);
43666
+ const response = yield this.topiaPublicApi().post(`/world/${this.urlSlug}/visitors/${this.id}/create-npc`, {
43667
+ userInventoryItemId,
43668
+ showNameplate: options === null || options === void 0 ? void 0 : options.showNameplate,
43669
+ stationary: options === null || options === void 0 ? void 0 : options.stationary,
43670
+ replace: options === null || options === void 0 ? void 0 : options.replace,
43671
+ spawnEffect: options === null || options === void 0 ? void 0 : options.spawnEffect,
43672
+ }, this.requestOptions);
43667
43673
  return new Visitor(this.topia, response.data.player.playerId, this.urlSlug, {
43668
43674
  attributes: response.data,
43669
43675
  credentials: this.credentials,
@@ -43708,6 +43714,77 @@ class Visitor extends User {
43708
43714
  }
43709
43715
  });
43710
43716
  }
43717
+ /**
43718
+ * Start an AI voice session for this visitor's NPC.
43719
+ *
43720
+ * @remarks
43721
+ * Establishes a real-time voice connection between the visitor and an AI backend
43722
+ * (currently OpenAI Realtime API) through the NPC. The NPC must already be spawned
43723
+ * via `createNpc()` before calling this method.
43724
+ *
43725
+ * The voice session occupies a video slot in the visitor's peer video grid, showing
43726
+ * the NPC's avatar image. Audio streams bidirectionally between the visitor's microphone
43727
+ * and the AI model. Only the NPC's owner hears the AI audio.
43728
+ *
43729
+ * Topia automatically prepends non-removable child safety guardrails to the instructions.
43730
+ * Only one voice session is allowed per visitor per world at a time.
43731
+ *
43732
+ * @keywords voice, npc, ai, chat, audio, realtime, session, start, speech
43733
+ *
43734
+ * @category NPCs
43735
+ *
43736
+ * @param config - Voice session configuration including ephemeral key and AI instructions
43737
+ *
43738
+ * @example
43739
+ * ```ts
43740
+ * const ephemeralKey = await generateOpenAIEphemeralKey();
43741
+ *
43742
+ * await visitor.startNpcVoiceSession({
43743
+ * ephemeralKey,
43744
+ * voice: "alloy",
43745
+ * instructions: "You are a friendly science tutor helping with photosynthesis.",
43746
+ * model: "gpt-4o-realtime-preview",
43747
+ * });
43748
+ * ```
43749
+ *
43750
+ * @returns {Promise<void | ResponseType>} Returns `{ success: true }` or an error.
43751
+ */
43752
+ startNpcVoiceSession(config) {
43753
+ return __awaiter(this, void 0, void 0, function* () {
43754
+ try {
43755
+ const response = yield this.topiaPublicApi().put(`/world/${this.urlSlug}/visitors/${this.id}/start-npc-voice-session`, { voiceConfig: config }, this.requestOptions);
43756
+ return response.data;
43757
+ }
43758
+ catch (error) {
43759
+ throw this.errorHandler({ error, params: config, sdkMethod: "Visitor.startNpcVoiceSession" });
43760
+ }
43761
+ });
43762
+ }
43763
+ /**
43764
+ * Stop the active AI voice session for this visitor's NPC.
43765
+ *
43766
+ * @keywords voice, npc, ai, chat, audio, realtime, session, stop, end
43767
+ *
43768
+ * @category NPCs
43769
+ *
43770
+ * @example
43771
+ * ```ts
43772
+ * await visitor.stopNpcVoiceSession();
43773
+ * ```
43774
+ *
43775
+ * @returns {Promise<void | ResponseType>} Returns `{ success: true }` or an error.
43776
+ */
43777
+ stopNpcVoiceSession() {
43778
+ return __awaiter(this, void 0, void 0, function* () {
43779
+ try {
43780
+ const response = yield this.topiaPublicApi().put(`/world/${this.urlSlug}/visitors/${this.id}/stop-npc-voice-session`, {}, this.requestOptions);
43781
+ return response.data;
43782
+ }
43783
+ catch (error) {
43784
+ throw this.errorHandler({ error, sdkMethod: "Visitor.stopNpcVoiceSession" });
43785
+ }
43786
+ });
43787
+ }
43711
43788
  /**
43712
43789
  * Retrieves all inventory items owned by this visitor and app's key.
43713
43790
  *
package/package.json CHANGED
@@ -61,5 +61,5 @@
61
61
  "yalc-push": "yarn build && yalc publish --push --dev --no-scripts"
62
62
  },
63
63
  "type": "module",
64
- "version": "0.19.05"
64
+ "version": "0.19.06"
65
65
  }