@series-inc/venus-sdk 3.0.3 → 3.0.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
@@ -1,243 +1,9 @@
1
1
  'use strict';
2
2
 
3
3
  var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
4
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
- var __esm = (fn, res) => function __init() {
9
- return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
10
- };
11
- var __export = (target, all) => {
12
- for (var name in all)
13
- __defProp(target, name, { get: all[name], enumerable: true });
14
- };
15
- var __copyProps = (to, from, except, desc) => {
16
- if (from && typeof from === "object" || typeof from === "function") {
17
- for (let key of __getOwnPropNames(from))
18
- if (!__hasOwnProp.call(to, key) && key !== except)
19
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
20
- }
21
- return to;
22
- };
23
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
24
5
  var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
25
6
 
26
- // src/rooms/RoomsApi.ts
27
- var init_RoomsApi = __esm({
28
- "src/rooms/RoomsApi.ts"() {
29
- }
30
- });
31
-
32
- // src/rooms/VenusRoom.ts
33
- exports.VenusRoom = void 0;
34
- var init_VenusRoom = __esm({
35
- "src/rooms/VenusRoom.ts"() {
36
- exports.VenusRoom = class {
37
- constructor(roomData) {
38
- __publicField(this, "id");
39
- __publicField(this, "name");
40
- __publicField(this, "players");
41
- __publicField(this, "maxPlayers");
42
- __publicField(this, "gameType");
43
- __publicField(this, "appId");
44
- __publicField(this, "type");
45
- __publicField(this, "createdBy");
46
- __publicField(this, "createdAt");
47
- __publicField(this, "updatedAt");
48
- __publicField(this, "isPrivate");
49
- __publicField(this, "currentPlayers");
50
- __publicField(this, "status");
51
- __publicField(this, "customMetadata");
52
- __publicField(this, "admins");
53
- __publicField(this, "roomCode");
54
- __publicField(this, "description");
55
- __publicField(this, "data");
56
- __publicField(this, "version");
57
- __publicField(this, "_subscriptions", /* @__PURE__ */ new Map());
58
- this.id = roomData.id;
59
- this.name = roomData.name;
60
- this.players = roomData.currentPlayers || [];
61
- this.maxPlayers = roomData.maxPlayers;
62
- this.gameType = roomData.gameType;
63
- this.appId = roomData.appId;
64
- this.type = roomData.type;
65
- this.createdBy = roomData.createdBy;
66
- this.createdAt = roomData.createdAt;
67
- this.updatedAt = roomData.updatedAt;
68
- this.isPrivate = roomData.isPrivate;
69
- this.currentPlayers = roomData.currentPlayers || [];
70
- this.status = roomData.status;
71
- this.customMetadata = roomData.customMetadata || {};
72
- this.admins = roomData.admins || [];
73
- this.roomCode = roomData.roomCode;
74
- this.description = roomData.description;
75
- this.data = roomData.data || {};
76
- this.version = roomData.version;
77
- console.log(`VenusRoom: Created room object for ${this.id}`, {
78
- hasCustomMetadata: !!this.customMetadata,
79
- hasGameState: !!this.customMetadata?.rules?.gameState,
80
- gamePhase: this.customMetadata?.rules?.gameState?.phase,
81
- currentPlayer: this.customMetadata?.rules?.gameState?.currentPlayer
82
- });
83
- }
84
- updateFromRoomData(newRoomData) {
85
- if (newRoomData.id === this.id) {
86
- this.name = newRoomData.name || this.name;
87
- this.players = newRoomData.currentPlayers || this.players;
88
- this.maxPlayers = newRoomData.maxPlayers || this.maxPlayers;
89
- this.gameType = newRoomData.gameType || this.gameType;
90
- this.currentPlayers = newRoomData.currentPlayers || this.currentPlayers;
91
- this.customMetadata = newRoomData.customMetadata || this.customMetadata;
92
- this.data = newRoomData.data || this.data;
93
- this.status = newRoomData.status || this.status;
94
- this.updatedAt = newRoomData.updatedAt || this.updatedAt;
95
- console.log(`VenusRoom: Updated room object ${this.id} with fresh data`, {
96
- hasCustomMetadata: !!this.customMetadata,
97
- hasGameState: !!this.customMetadata?.rules?.gameState,
98
- gamePhase: this.customMetadata?.rules?.gameState?.phase,
99
- currentPlayer: this.customMetadata?.rules?.gameState?.currentPlayer
100
- });
101
- }
102
- }
103
- };
104
- }
105
- });
106
-
107
- // src/rooms/index.ts
108
- var rooms_exports = {};
109
- __export(rooms_exports, {
110
- VenusRoom: () => exports.VenusRoom,
111
- initializeRoomsApi: () => initializeRoomsApi,
112
- setupRoomNotifications: () => setupRoomNotifications
113
- });
114
- function bindMethod(target, targetKey, source, sourceKey) {
115
- const key = sourceKey ?? targetKey;
116
- const fn = source?.[key];
117
- if (typeof fn === "function") {
118
- target[targetKey] = fn.bind(source);
119
- return true;
120
- }
121
- return false;
122
- }
123
- function setupRoomNotifications(transport, getSubscriptions) {
124
- console.log("[Venus Rooms] Setting up room notification listeners");
125
- return transport.onVenusMessage((message) => {
126
- const subscriptions = getSubscriptions();
127
- if (!subscriptions) {
128
- return;
129
- }
130
- if (message.type === "H5_ROOM_DATA_UPDATED") {
131
- const messageData = message.data;
132
- const { roomId, roomData } = messageData;
133
- if (!roomId) return;
134
- const callbacks = subscriptions.data?.[roomId] || [];
135
- const allEventsCallbacks = subscriptions.allEvents?.[roomId] || [];
136
- console.log(`[Venus Rooms] \u{1F514} Room data updated for ${roomId}, notifying ${callbacks.length} callbacks`, roomData);
137
- callbacks.forEach((callback) => {
138
- try {
139
- callback(roomData);
140
- } catch (error) {
141
- console.error("[Venus Rooms] Error in room data callback:", error);
142
- throw error;
143
- }
144
- });
145
- allEventsCallbacks.forEach((callback) => {
146
- try {
147
- callback({ type: message.type, ...messageData });
148
- } catch (error) {
149
- console.error("[Venus Rooms] Error in allEvents callback:", error);
150
- throw error;
151
- }
152
- });
153
- }
154
- if (message.type === "H5_ROOM_MESSAGE_RECEIVED" || message.type === "H5_ROOM_MESSAGE_UPDATED" || message.type === "H5_ROOM_MESSAGE_DELETED") {
155
- const messageData = message.data;
156
- const { roomId } = messageData;
157
- if (!roomId) return;
158
- const callbacks = subscriptions.messages?.[roomId] || [];
159
- const allEventsCallbacks = subscriptions.allEvents?.[roomId] || [];
160
- console.log(`[Venus Rooms] \u{1F514} Room message event for ${roomId}, notifying ${callbacks.length} callbacks`);
161
- callbacks.forEach((callback) => {
162
- try {
163
- callback(messageData);
164
- } catch (error) {
165
- console.error("[Venus Rooms] Error in room message callback:", error);
166
- throw error;
167
- }
168
- });
169
- allEventsCallbacks.forEach((callback) => {
170
- try {
171
- callback({ type: message.type, ...messageData });
172
- } catch (error) {
173
- console.error("[Venus Rooms] Error in allEvents callback:", error);
174
- throw error;
175
- }
176
- });
177
- }
178
- if (message.type === "app:h5:proposedMoveValidationUpdated") {
179
- const messageData = message.data;
180
- const { roomId } = messageData;
181
- if (!roomId) return;
182
- const callbacks = subscriptions.gameEvents?.[roomId] || [];
183
- const allEventsCallbacks = subscriptions.allEvents?.[roomId] || [];
184
- console.log(`[Venus Rooms] \u{1F514} Proposed move validation updated for ${roomId}, notifying ${callbacks.length} callbacks`);
185
- callbacks.forEach((callback) => {
186
- try {
187
- callback(messageData);
188
- } catch (error) {
189
- console.error("[Venus Rooms] Error in game event callback:", error);
190
- throw error;
191
- }
192
- });
193
- allEventsCallbacks.forEach((callback) => {
194
- try {
195
- callback({ type: message.type, ...messageData });
196
- } catch (error) {
197
- console.error("[Venus Rooms] Error in allEvents callback:", error);
198
- throw error;
199
- }
200
- });
201
- }
202
- });
203
- }
204
- function initializeRoomsApi(venusApi, host) {
205
- const roomsApi = host?.rooms;
206
- if (!roomsApi) {
207
- console.warn(
208
- "[Venus SDK] Host did not provide a rooms implementation. Rooms API will be unavailable."
209
- );
210
- return;
211
- }
212
- const venus = venusApi;
213
- const existingNamespace = venus.rooms || {};
214
- const roomsNamespace = Object.assign({}, existingNamespace);
215
- const namespaceBindings = [
216
- ["create", "createRoom"],
217
- ["joinOrCreate", "joinOrCreateRoom"],
218
- ["joinByCode", "joinRoomByCode"],
219
- ["list", "getUserRooms"],
220
- ["subscribeToRoom", "subscribe"],
221
- ["updateRoomData", "updateData"],
222
- ["getRoomData", "getData"],
223
- ["sendRoomMessage", "sendMessage"],
224
- ["leaveRoom", "leave"],
225
- ["startRoomGame", "startGame"],
226
- ["proposeMove"],
227
- ["validateMove"]
228
- ];
229
- namespaceBindings.forEach(([targetKey, sourceKey]) => {
230
- bindMethod(roomsNamespace, targetKey, roomsApi, sourceKey);
231
- });
232
- venus.rooms = roomsNamespace;
233
- }
234
- var init_rooms = __esm({
235
- "src/rooms/index.ts"() {
236
- init_RoomsApi();
237
- init_VenusRoom();
238
- }
239
- });
240
-
241
7
  // src/VenusMessageId.ts
242
8
  var VenusMessageId = /* @__PURE__ */ ((VenusMessageId2) => {
243
9
  VenusMessageId2["H5_RESPONSE"] = "H5_RESPONSE";
@@ -329,11 +95,14 @@ var VenusMessageId = /* @__PURE__ */ ((VenusMessageId2) => {
329
95
  VenusMessageId2["H5_SIMULATION_GET_AVAILABLE_ITEMS"] = "H5_SIMULATION_GET_AVAILABLE_ITEMS";
330
96
  VenusMessageId2["H5_SIMULATION_VALIDATE_ASSIGNMENT"] = "H5_SIMULATION_VALIDATE_ASSIGNMENT";
331
97
  VenusMessageId2["H5_SIMULATION_BATCH_OPERATIONS"] = "H5_SIMULATION_BATCH_OPERATIONS";
332
- VenusMessageId2["H5_LEADERBOARD_START_RUN"] = "H5_LEADERBOARD_START_RUN";
98
+ VenusMessageId2["H5_SIMULATION_SUBSCRIBE"] = "H5_SIMULATION_SUBSCRIBE";
99
+ VenusMessageId2["H5_SIMULATION_UNSUBSCRIBE"] = "H5_SIMULATION_UNSUBSCRIBE";
100
+ VenusMessageId2["H5_SIMULATION_UPDATE"] = "H5_SIMULATION_UPDATE";
101
+ VenusMessageId2["H5_LEADERBOARD_CREATE_SCORE_TOKEN"] = "H5_LEADERBOARD_CREATE_SCORE_TOKEN";
333
102
  VenusMessageId2["H5_LEADERBOARD_SUBMIT_SCORE"] = "H5_LEADERBOARD_SUBMIT_SCORE";
334
- VenusMessageId2["H5_LEADERBOARD_GET"] = "H5_LEADERBOARD_GET";
335
- VenusMessageId2["H5_LEADERBOARD_GET_HIGHLIGHT"] = "H5_LEADERBOARD_GET_HIGHLIGHT";
336
- VenusMessageId2["H5_LEADERBOARD_GET_PLAYER_STATS"] = "H5_LEADERBOARD_GET_PLAYER_STATS";
103
+ VenusMessageId2["H5_LEADERBOARD_GET_PAGED_SCORES"] = "H5_LEADERBOARD_GET_PAGED_SCORES";
104
+ VenusMessageId2["H5_LEADERBOARD_GET_PODIUM_SCORES"] = "H5_LEADERBOARD_GET_PODIUM_SCORES";
105
+ VenusMessageId2["H5_LEADERBOARD_GET_MY_RANK"] = "H5_LEADERBOARD_GET_MY_RANK";
337
106
  VenusMessageId2["H5_ROOM_CREATE"] = "H5_ROOM_CREATE";
338
107
  VenusMessageId2["H5_ROOM_JOIN"] = "H5_ROOM_JOIN";
339
108
  VenusMessageId2["H5_ROOM_JOIN_OR_CREATE"] = "H5_ROOM_JOIN_OR_CREATE";
@@ -1195,7 +964,8 @@ var MockCdnApi = class {
1195
964
  return index === pathParts.length - 1 ? encodeURIComponent(part) : part;
1196
965
  });
1197
966
  const encodedSubPath = encodedParts.join("/");
1198
- const fullUrl = `${this.baseUrl}${encodedSubPath}`;
967
+ const cacheBust = Date.now();
968
+ const fullUrl = `${this.baseUrl}${encodedSubPath}?cacheBust=${cacheBust}`;
1199
969
  return fullUrl;
1200
970
  }
1201
971
  resolveAvatarAssetUrl(subPath) {
@@ -1588,10 +1358,10 @@ function initializeLifecycleApi(venusApi, host) {
1588
1358
  // src/logging/MockLoggingApi.ts
1589
1359
  var MockLoggingApi = class {
1590
1360
  logDebug(message, ...args) {
1591
- console.log(`[Venus Mock] ${message}`, args);
1361
+ console.log(`[Venus Mock] ${message}`, ...args);
1592
1362
  }
1593
1363
  logError(message, ...args) {
1594
- console.error(`[Venus Mock] ${message}`, args);
1364
+ console.error(`[Venus Mock] ${message}`, ...args);
1595
1365
  }
1596
1366
  };
1597
1367
 
@@ -1792,13 +1562,8 @@ var MockNotificationsApi = class {
1792
1562
  async cancelNotification(notificationId) {
1793
1563
  const venusApi = this.venusApi;
1794
1564
  if (isWebPlatform()) {
1795
- console.log(
1796
- "[Venus Mock] Cancel notification on web platform (simulated):",
1797
- notificationId
1798
- );
1799
1565
  return true;
1800
1566
  }
1801
- console.log("[Venus Mock] Cancel local notification:", notificationId);
1802
1567
  await createMockDelay(MOCK_DELAYS.short);
1803
1568
  if (venusApi._mock.scheduledNotifications && venusApi._mock.scheduledNotifications[notificationId]) {
1804
1569
  delete venusApi._mock.scheduledNotifications[notificationId];
@@ -1808,12 +1573,8 @@ var MockNotificationsApi = class {
1808
1573
  }
1809
1574
  async getAllScheduledLocalNotifications() {
1810
1575
  if (isWebPlatform()) {
1811
- console.log(
1812
- "[Venus Mock] Get notifications on web platform (returning empty list)"
1813
- );
1814
1576
  return [];
1815
1577
  }
1816
- console.log("[Venus Mock] Get all scheduled local notifications");
1817
1578
  await createMockDelay(MOCK_DELAYS.short);
1818
1579
  const venusApi = this.venusApi;
1819
1580
  const notifications = venusApi._mock.scheduledNotifications || {};
@@ -1821,10 +1582,8 @@ var MockNotificationsApi = class {
1821
1582
  }
1822
1583
  async isLocalNotificationsEnabled() {
1823
1584
  if (isWebPlatform()) {
1824
- console.log("[Venus Mock] Notifications not available on web platform");
1825
1585
  return false;
1826
1586
  }
1827
- console.log("[Venus Mock] Check if local notifications are enabled");
1828
1587
  await createMockDelay(MOCK_DELAYS.short);
1829
1588
  const venusApi = this.venusApi;
1830
1589
  const isEnabled = venusApi._mock.notificationsEnabled !== false;
@@ -1833,9 +1592,6 @@ var MockNotificationsApi = class {
1833
1592
  async scheduleAsync(title, body, seconds, notificationId, options) {
1834
1593
  const { priority = 50, groupId, payload } = options || {};
1835
1594
  if (isWebPlatform()) {
1836
- console.log(
1837
- "[Venus Mock] Notifications not supported on web platform, simulating success"
1838
- );
1839
1595
  console.info(
1840
1596
  "\u{1F514} [Venus Mock] Notification would be scheduled:",
1841
1597
  title || "Untitled",
@@ -1846,14 +1602,11 @@ var MockNotificationsApi = class {
1846
1602
  const mockId = `mock-web-notification-${Date.now()}`;
1847
1603
  return mockId;
1848
1604
  }
1849
- console.log("[Venus Mock] Schedule local notification:", { title, body, seconds, options });
1850
1605
  const venusApi = this.venusApi;
1851
1606
  if (!venusApi._mock.pendingRequests) {
1852
- console.log("[Venus Mock] Initializing pendingRequests");
1853
1607
  venusApi._mock.pendingRequests = {};
1854
1608
  }
1855
1609
  const requestId = Date.now().toString();
1856
- console.log("[Venus Mock] Creating request with ID:", requestId);
1857
1610
  return new Promise((resolve) => {
1858
1611
  venusApi._mock.pendingRequests[requestId] = { resolve };
1859
1612
  const id = notificationId || `mock-notification-${Date.now()}`;
@@ -1875,13 +1628,8 @@ var MockNotificationsApi = class {
1875
1628
  async setLocalNotificationsEnabled(enabled) {
1876
1629
  const venusApi = this.venusApi;
1877
1630
  if (isWebPlatform()) {
1878
- console.log(
1879
- "[Venus Mock] Set notifications enabled on web platform (simulated):",
1880
- enabled
1881
- );
1882
1631
  return true;
1883
1632
  }
1884
- console.log("[Venus Mock] Set local notifications enabled:", enabled);
1885
1633
  await createMockDelay(MOCK_DELAYS.short);
1886
1634
  venusApi._mock.notificationsEnabled = enabled;
1887
1635
  return enabled;
@@ -2146,6 +1894,11 @@ function initializeProfile(venusApi, host) {
2146
1894
  };
2147
1895
  }
2148
1896
 
1897
+ // src/utils/idGenerator.ts
1898
+ function generateId() {
1899
+ return `${Date.now()}-${Math.random().toString(36).substring(2, 9)}`;
1900
+ }
1901
+
2149
1902
  // src/rpc/RpcClient.ts
2150
1903
  var RpcClient = class {
2151
1904
  constructor() {
@@ -2188,7 +1941,7 @@ var RpcClient = class {
2188
1941
  }
2189
1942
  async call(method, args, timeout = 5e3) {
2190
1943
  return new Promise((resolve, reject) => {
2191
- const id = this.generateId();
1944
+ const id = generateId();
2192
1945
  this.addPendingCall(id, resolve, reject);
2193
1946
  const request = {
2194
1947
  type: "rpc-request",
@@ -2225,9 +1978,6 @@ var RpcClient = class {
2225
1978
  getPendingCall(id) {
2226
1979
  return this.pendingCalls.get(id);
2227
1980
  }
2228
- generateId() {
2229
- return `${Date.now()}-${Math.random().toString(36).substring(2, 9)}`;
2230
- }
2231
1981
  handleRpcResponse(response) {
2232
1982
  const pending = this.getPendingCall(response.id);
2233
1983
  if (!pending) {
@@ -2249,103 +1999,520 @@ var RpcClient = class {
2249
1999
  }
2250
2000
  };
2251
2001
 
2252
- // src/index.ts
2253
- init_rooms();
2254
-
2255
- // src/storage/MockStorageApi.ts
2256
- function createMockStorageApi(storageType, appUrl) {
2257
- const appIdentifier = appUrl ? generateAppIdentifier(appUrl) : null;
2258
- let prefix;
2259
- let syncDelay = 0;
2260
- switch (storageType) {
2261
- case "deviceCache":
2262
- prefix = "venus:app";
2263
- syncDelay = 0;
2264
- break;
2265
- case "appStorage":
2266
- prefix = "venus:app";
2267
- syncDelay = 100;
2268
- break;
2269
- case "globalStorage":
2270
- prefix = "venus:global";
2271
- syncDelay = 100;
2272
- break;
2273
- default:
2274
- throw new Error(`Unknown storage type: ${storageType}`);
2002
+ // src/rooms/VenusRoom.ts
2003
+ var VenusRoom = class {
2004
+ constructor(roomData) {
2005
+ __publicField(this, "id");
2006
+ __publicField(this, "name");
2007
+ __publicField(this, "players");
2008
+ __publicField(this, "maxPlayers");
2009
+ __publicField(this, "gameType");
2010
+ __publicField(this, "appId");
2011
+ __publicField(this, "type");
2012
+ __publicField(this, "createdBy");
2013
+ __publicField(this, "createdAt");
2014
+ __publicField(this, "updatedAt");
2015
+ __publicField(this, "isPrivate");
2016
+ __publicField(this, "status");
2017
+ __publicField(this, "customMetadata");
2018
+ __publicField(this, "admins");
2019
+ __publicField(this, "roomCode");
2020
+ __publicField(this, "description");
2021
+ __publicField(this, "data");
2022
+ __publicField(this, "version");
2023
+ this.id = roomData.id;
2024
+ this.name = roomData.name;
2025
+ this.players = Array.isArray(roomData.currentPlayers) ? [...roomData.currentPlayers] : [];
2026
+ this.maxPlayers = roomData.maxPlayers;
2027
+ this.gameType = roomData.gameType;
2028
+ this.appId = roomData.appId;
2029
+ this.type = roomData.type;
2030
+ this.createdBy = roomData.createdBy;
2031
+ this.createdAt = roomData.createdAt;
2032
+ this.updatedAt = roomData.updatedAt;
2033
+ this.isPrivate = roomData.isPrivate;
2034
+ this.status = roomData.status;
2035
+ this.customMetadata = roomData.customMetadata || {};
2036
+ this.admins = Array.isArray(roomData.admins) ? [...roomData.admins] : [];
2037
+ this.roomCode = roomData.roomCode;
2038
+ this.description = roomData.description;
2039
+ this.data = roomData.data || {};
2040
+ this.version = roomData.version;
2275
2041
  }
2276
- prefix = storageType === "globalStorage" || !appIdentifier ? `${prefix}:` : `${prefix}:${appIdentifier}:`;
2277
- return new MockStorageApi(prefix, syncDelay);
2042
+ };
2043
+
2044
+ // src/rooms/setupRoomNotifications.ts
2045
+ function invokeCallbacks(callbacks, event, context) {
2046
+ callbacks.forEach((callback) => {
2047
+ try {
2048
+ callback(event);
2049
+ } catch (error) {
2050
+ console.error(`[Venus SDK] Error in ${context} callback:`, error);
2051
+ throw error;
2052
+ }
2053
+ });
2278
2054
  }
2279
- var MockStorageApi = class {
2280
- constructor(prefix, syncDelay) {
2281
- __publicField(this, "prefix");
2282
- __publicField(this, "syncDelay");
2283
- this.prefix = prefix;
2284
- this.syncDelay = syncDelay;
2285
- }
2286
- async clear() {
2287
- const fullLength = localStorage.length;
2288
- for (let i = 0; i < fullLength; i++) {
2289
- const fullKey = localStorage.key(i);
2290
- if (fullKey && fullKey.startsWith(this.prefix)) {
2291
- localStorage.removeItem(fullKey);
2292
- }
2055
+ function setupRoomNotifications(transport, getSubscriptions) {
2056
+ return transport.onVenusMessage((message) => {
2057
+ const subscriptions = getSubscriptions();
2058
+ if (!subscriptions) {
2059
+ return;
2293
2060
  }
2294
- await this.simulateSyncDelay();
2295
- }
2296
- async getAllItems() {
2297
- const items = new Array();
2298
- const fullLength = localStorage.length;
2299
- for (let i = 0; i < fullLength; i++) {
2300
- const fullKey = localStorage.key(i);
2301
- if (fullKey && fullKey.startsWith(this.prefix)) {
2302
- const item = localStorage.getItem(fullKey);
2303
- if (item) {
2304
- items.push(item);
2305
- }
2306
- }
2061
+ if (message.type === "H5_ROOM_DATA_UPDATED") {
2062
+ const messageData = message.data;
2063
+ const { roomId, roomData } = messageData;
2064
+ if (!roomId) return;
2065
+ const callbacks = subscriptions.data[roomId] || [];
2066
+ const event = {
2067
+ type: "H5_ROOM_DATA_UPDATED",
2068
+ roomId,
2069
+ roomData,
2070
+ timestamp: messageData.timestamp
2071
+ };
2072
+ invokeCallbacks(callbacks, event, "room data");
2307
2073
  }
2308
- return items;
2309
- }
2310
- async getItem(key) {
2311
- const fullKey = this.buildKey(key);
2312
- await this.simulateSyncDelay();
2313
- return localStorage.getItem(fullKey);
2314
- }
2315
- async key(index) {
2316
- const keys = this.keys();
2317
- if (index < 0 || index >= keys.length) {
2318
- return null;
2074
+ if (message.type === "H5_ROOM_MESSAGE_RECEIVED" || message.type === "H5_ROOM_MESSAGE_UPDATED" || message.type === "H5_ROOM_MESSAGE_DELETED") {
2075
+ const messageData = message.data;
2076
+ const { roomId } = messageData;
2077
+ if (!roomId) return;
2078
+ const callbacks = subscriptions.messages[roomId] || [];
2079
+ const event = {
2080
+ type: message.type,
2081
+ roomId,
2082
+ message: messageData.message,
2083
+ timestamp: messageData.timestamp
2084
+ };
2085
+ invokeCallbacks(callbacks, event, "room message");
2319
2086
  }
2320
- await this.simulateSyncDelay();
2321
- return keys[index];
2322
- }
2323
- async length() {
2324
- return this.keys().length;
2087
+ if (message.type === "app:h5:proposedMoveValidationUpdated") {
2088
+ const messageData = message.data;
2089
+ const { roomId } = messageData;
2090
+ if (!roomId) return;
2091
+ const callbacks = subscriptions.gameEvents[roomId] || [];
2092
+ const event = {
2093
+ type: "app:h5:proposedMoveValidationUpdated",
2094
+ roomId,
2095
+ proposedMoveData: messageData.proposedMoveData,
2096
+ proposedMoveId: messageData.proposedMoveId,
2097
+ changeType: messageData.changeType,
2098
+ timestamp: messageData.timestamp
2099
+ };
2100
+ invokeCallbacks(callbacks, event, "game event");
2101
+ }
2102
+ });
2103
+ }
2104
+
2105
+ // src/rooms/RpcRoomsApi.ts
2106
+ var RpcRoomsApi = class {
2107
+ constructor(rpcClient) {
2108
+ __publicField(this, "rpcClient");
2109
+ __publicField(this, "subscriptions");
2110
+ this.rpcClient = rpcClient;
2111
+ this.subscriptions = {
2112
+ data: {},
2113
+ messages: {},
2114
+ gameEvents: {}
2115
+ };
2325
2116
  }
2326
- async removeItem(key) {
2327
- const fullKey = this.buildKey(key);
2328
- await this.simulateSyncDelay();
2329
- localStorage.removeItem(fullKey);
2117
+ /**
2118
+ * Get the subscription state for external access (used by setupRoomNotifications)
2119
+ */
2120
+ getSubscriptions() {
2121
+ return this.subscriptions;
2330
2122
  }
2331
- async setItem(key, item) {
2332
- const fullKey = this.buildKey(key);
2333
- await this.simulateSyncDelay();
2334
- localStorage.setItem(fullKey, item);
2123
+ /**
2124
+ * Set up room notification routing from the transport
2125
+ */
2126
+ setupNotifications(transport) {
2127
+ setupRoomNotifications(transport, () => this.getSubscriptions());
2335
2128
  }
2336
- async setMultipleItems(entries) {
2337
- for (const entry of entries) {
2338
- const fullKey = this.buildKey(entry.key);
2339
- localStorage.setItem(fullKey, entry.value);
2129
+ async createRoomAsync(options) {
2130
+ const response = await this.rpcClient.call(
2131
+ "H5_ROOM_CREATE" /* H5_ROOM_CREATE */,
2132
+ {
2133
+ options
2134
+ }
2135
+ );
2136
+ if (response.success === false) {
2137
+ const errorMessage = typeof response.error === "string" ? response.error : "Failed to create room";
2138
+ throw new Error(errorMessage);
2340
2139
  }
2341
- await this.simulateSyncDelay();
2140
+ const room = new VenusRoom(response.roomData);
2141
+ return room;
2342
2142
  }
2343
- async removeMultipleItems(keys) {
2344
- for (const key of keys) {
2345
- const fullKey = this.buildKey(key);
2346
- localStorage.removeItem(fullKey);
2143
+ async joinOrCreateRoomAsync(options) {
2144
+ const response = await this.rpcClient.call(
2145
+ "H5_ROOM_JOIN_OR_CREATE" /* H5_ROOM_JOIN_OR_CREATE */,
2146
+ {
2147
+ options
2148
+ }
2149
+ );
2150
+ if (response.success === false) {
2151
+ const errorMessage = typeof response.error === "string" ? response.error : "Failed to join or create room";
2152
+ throw new Error(errorMessage);
2347
2153
  }
2348
- await this.simulateSyncDelay();
2154
+ const room = new VenusRoom(response.value.roomData);
2155
+ return {
2156
+ action: response.value.action,
2157
+ room,
2158
+ playersJoined: response.value.playersJoined
2159
+ };
2160
+ }
2161
+ async joinRoomByCodeAsync(roomCode) {
2162
+ const response = await this.rpcClient.call(
2163
+ "H5_ROOM_JOIN_BY_CODE" /* H5_ROOM_JOIN_BY_CODE */,
2164
+ {
2165
+ roomCode
2166
+ }
2167
+ );
2168
+ if (response?.success === false) {
2169
+ const errorMessage = typeof response.error === "string" ? response.error : "Failed to join room by code";
2170
+ throw new Error(errorMessage);
2171
+ }
2172
+ const room = new VenusRoom(response.roomData);
2173
+ return room;
2174
+ }
2175
+ // Get user's rooms with optional filtering
2176
+ async getUserRoomsAsync(options = {}) {
2177
+ const response = await this.rpcClient.call(
2178
+ "H5_ROOM_GET_USER_ROOMS" /* H5_ROOM_GET_USER_ROOMS */,
2179
+ {
2180
+ includeArchived: options.includeArchived ?? false
2181
+ }
2182
+ );
2183
+ if (response?.success === false) {
2184
+ const errorMessage = typeof response.error === "string" ? response.error : "Failed to get user rooms";
2185
+ throw new Error(errorMessage);
2186
+ }
2187
+ const venusRooms = [];
2188
+ for (const roomData of response.rooms) {
2189
+ if (!roomData.id) {
2190
+ console.warn("[Venus SDK] getUserRooms: Skipping room with missing ID:", roomData);
2191
+ continue;
2192
+ }
2193
+ try {
2194
+ const venusRoom = new VenusRoom(roomData);
2195
+ venusRooms.push(venusRoom);
2196
+ } catch (error) {
2197
+ console.warn(
2198
+ "[Venus SDK] getUserRooms: Failed to create VenusRoom object:",
2199
+ error,
2200
+ roomData
2201
+ );
2202
+ }
2203
+ }
2204
+ return venusRooms;
2205
+ }
2206
+ async updateRoomDataAsync(room, updates, options = {}) {
2207
+ const response = await this.rpcClient.call(
2208
+ "H5_ROOM_UPDATE_DATA" /* H5_ROOM_UPDATE_DATA */,
2209
+ {
2210
+ roomId: room.id,
2211
+ updates,
2212
+ merge: options.merge ?? true
2213
+ }
2214
+ );
2215
+ if (response?.success === false) {
2216
+ const errorMessage = typeof response.error === "string" ? response.error : "Failed to update room data";
2217
+ throw new Error(errorMessage);
2218
+ }
2219
+ }
2220
+ async getRoomDataAsync(room) {
2221
+ const response = await this.rpcClient.call(
2222
+ "H5_ROOM_GET_DATA" /* H5_ROOM_GET_DATA */,
2223
+ {
2224
+ roomId: room.id
2225
+ }
2226
+ );
2227
+ if (response?.success === false) {
2228
+ const errorMessage = typeof response.error === "string" ? response.error : "Failed to get room data";
2229
+ throw new Error(errorMessage);
2230
+ }
2231
+ return response.data;
2232
+ }
2233
+ async sendRoomMessageAsync(venusRoom, request) {
2234
+ const response = await this.rpcClient.call(
2235
+ "H5_ROOM_SEND_MESSAGE" /* H5_ROOM_SEND_MESSAGE */,
2236
+ {
2237
+ roomId: venusRoom.id,
2238
+ message: request.message,
2239
+ metadata: request.metadata
2240
+ }
2241
+ );
2242
+ if (response?.success === false) {
2243
+ const errorMessage = typeof response.error === "string" ? response.error : "Failed to send message";
2244
+ throw new Error(errorMessage);
2245
+ }
2246
+ return response.messageId;
2247
+ }
2248
+ async leaveRoomAsync(room) {
2249
+ const response = await this.rpcClient.call(
2250
+ "H5_ROOM_LEAVE" /* H5_ROOM_LEAVE */,
2251
+ {
2252
+ roomId: room.id
2253
+ }
2254
+ );
2255
+ if (response?.success === false) {
2256
+ const errorMessage = typeof response.error === "string" ? response.error : "Failed to leave room";
2257
+ throw new Error(errorMessage);
2258
+ }
2259
+ }
2260
+ async startRoomGameAsync(room, options = {}) {
2261
+ const response = await this.rpcClient.call(
2262
+ "H5_ROOM_START_GAME" /* H5_ROOM_START_GAME */,
2263
+ {
2264
+ roomId: room.id,
2265
+ gameConfig: options.gameConfig ?? {},
2266
+ turnOrder: options.turnOrder ?? null
2267
+ }
2268
+ );
2269
+ if (response?.success === false) {
2270
+ const errorMessage = typeof response.error === "string" ? response.error : "Failed to start game";
2271
+ throw new Error(errorMessage);
2272
+ }
2273
+ }
2274
+ async proposeMoveAsync(room, proposalPayload) {
2275
+ const response = await this.rpcClient.call(
2276
+ "h5:room:proposeMove" /* H5_ROOM_PROPOSE_MOVE */,
2277
+ {
2278
+ roomId: room.id,
2279
+ gameSpecificState: proposalPayload.gameSpecificState,
2280
+ moveType: proposalPayload.moveType,
2281
+ clientContext: proposalPayload.clientContext,
2282
+ clientProposalId: proposalPayload.clientProposalId
2283
+ }
2284
+ );
2285
+ if (response?.success === false) {
2286
+ const errorMessage = typeof response.error === "string" ? response.error : "Failed to propose move";
2287
+ throw new Error(errorMessage);
2288
+ }
2289
+ return response.data;
2290
+ }
2291
+ async validateMoveAsync(_room, moveId, verdict) {
2292
+ return {
2293
+ success: true,
2294
+ moveId,
2295
+ isValid: verdict.isValid,
2296
+ reason: verdict.reason
2297
+ };
2298
+ }
2299
+ async subscribeAsync(room, options = {}) {
2300
+ const roomId = room.id;
2301
+ const existingData = this.subscriptions.data[roomId];
2302
+ const existingMessages = this.subscriptions.messages[roomId];
2303
+ const existingGameEvents = this.subscriptions.gameEvents[roomId];
2304
+ const subscribeToData = Boolean(options.onData) && (existingData?.length ?? 0) === 0;
2305
+ const subscribeToMessages = Boolean(options.onMessages) && (existingMessages?.length ?? 0) === 0;
2306
+ const subscribeToProposedMoves = Boolean(options.onGameEvents) && (existingGameEvents?.length ?? 0) === 0;
2307
+ if (subscribeToData || subscribeToMessages || subscribeToProposedMoves) {
2308
+ try {
2309
+ await this.rpcClient.call("H5_ROOM_SUBSCRIBE" /* H5_ROOM_SUBSCRIBE */, {
2310
+ roomId,
2311
+ subscribeToData,
2312
+ subscribeToMessages,
2313
+ subscribeToProposedMoves
2314
+ });
2315
+ } catch (error) {
2316
+ console.error("[Venus SDK] Failed to set up room subscription:", error);
2317
+ throw error;
2318
+ }
2319
+ }
2320
+ if (options.onData) {
2321
+ if (!this.subscriptions.data[roomId]) {
2322
+ this.subscriptions.data[roomId] = [];
2323
+ }
2324
+ this.subscriptions.data[roomId].push(options.onData);
2325
+ }
2326
+ if (options.onMessages) {
2327
+ if (!this.subscriptions.messages[roomId]) {
2328
+ this.subscriptions.messages[roomId] = [];
2329
+ }
2330
+ this.subscriptions.messages[roomId].push(options.onMessages);
2331
+ }
2332
+ if (options.onGameEvents) {
2333
+ if (!this.subscriptions.gameEvents[roomId]) {
2334
+ this.subscriptions.gameEvents[roomId] = [];
2335
+ }
2336
+ this.subscriptions.gameEvents[roomId].push(options.onGameEvents);
2337
+ }
2338
+ let disposed = false;
2339
+ return () => {
2340
+ if (disposed) return;
2341
+ disposed = true;
2342
+ if (options.onData) {
2343
+ const callbacks = this.subscriptions.data[roomId];
2344
+ if (callbacks) {
2345
+ const index = callbacks.indexOf(options.onData);
2346
+ if (index > -1) {
2347
+ callbacks.splice(index, 1);
2348
+ }
2349
+ }
2350
+ }
2351
+ if (options.onMessages) {
2352
+ const callbacks = this.subscriptions.messages[roomId];
2353
+ if (callbacks) {
2354
+ const index = callbacks.indexOf(options.onMessages);
2355
+ if (index > -1) {
2356
+ callbacks.splice(index, 1);
2357
+ }
2358
+ }
2359
+ }
2360
+ if (options.onGameEvents) {
2361
+ const callbacks = this.subscriptions.gameEvents[roomId];
2362
+ if (callbacks) {
2363
+ const index = callbacks.indexOf(options.onGameEvents);
2364
+ if (index > -1) {
2365
+ callbacks.splice(index, 1);
2366
+ }
2367
+ }
2368
+ }
2369
+ const hasAnySubscriptions = (this.subscriptions.data[roomId]?.length ?? 0) > 0 || (this.subscriptions.messages[roomId]?.length ?? 0) > 0 || (this.subscriptions.gameEvents[roomId]?.length ?? 0) > 0;
2370
+ if (!hasAnySubscriptions) {
2371
+ this.rpcClient.call("H5_ROOM_UNSUBSCRIBE" /* H5_ROOM_UNSUBSCRIBE */, {
2372
+ roomId
2373
+ }).catch((error) => {
2374
+ console.error("[Venus SDK] Failed to clean up room subscription:", error);
2375
+ });
2376
+ }
2377
+ };
2378
+ }
2379
+ };
2380
+
2381
+ // src/rooms/index.ts
2382
+ function bindMethod(target, targetKey, source, sourceKey) {
2383
+ const key = sourceKey ?? targetKey;
2384
+ const fn = source?.[key];
2385
+ if (typeof fn === "function") {
2386
+ target[targetKey] = fn.bind(source);
2387
+ return true;
2388
+ }
2389
+ return false;
2390
+ }
2391
+ function initializeRoomsApi(venusApi, host) {
2392
+ const roomsApi = host?.rooms;
2393
+ if (!roomsApi) {
2394
+ console.warn(
2395
+ "[Venus SDK] Host did not provide a rooms implementation. Rooms API will be unavailable."
2396
+ );
2397
+ return;
2398
+ }
2399
+ const venus = venusApi;
2400
+ const existingNamespace = venus.rooms || {};
2401
+ const roomsNamespace = Object.assign({}, existingNamespace);
2402
+ const namespaceBindings = [
2403
+ ["createRoomAsync"],
2404
+ ["joinOrCreateRoomAsync"],
2405
+ ["joinRoomByCodeAsync"],
2406
+ ["getUserRoomsAsync"],
2407
+ ["subscribeAsync"],
2408
+ ["updateRoomDataAsync"],
2409
+ ["getRoomDataAsync"],
2410
+ ["sendRoomMessageAsync"],
2411
+ ["leaveRoomAsync"],
2412
+ ["startRoomGameAsync"],
2413
+ ["proposeMoveAsync"],
2414
+ ["validateMoveAsync"]
2415
+ ];
2416
+ namespaceBindings.forEach(([targetKey, sourceKey]) => {
2417
+ bindMethod(roomsNamespace, targetKey, roomsApi, sourceKey);
2418
+ });
2419
+ venus.rooms = roomsNamespace;
2420
+ }
2421
+
2422
+ // src/storage/MockStorageApi.ts
2423
+ function createMockStorageApi(storageType, appUrl) {
2424
+ const appIdentifier = appUrl ? generateAppIdentifier(appUrl) : null;
2425
+ let prefix;
2426
+ let syncDelay = 0;
2427
+ switch (storageType) {
2428
+ case "deviceCache":
2429
+ prefix = "venus:app";
2430
+ syncDelay = 0;
2431
+ break;
2432
+ case "appStorage":
2433
+ prefix = "venus:app";
2434
+ syncDelay = 100;
2435
+ break;
2436
+ case "globalStorage":
2437
+ prefix = "venus:global";
2438
+ syncDelay = 100;
2439
+ break;
2440
+ default:
2441
+ throw new Error(`Unknown storage type: ${storageType}`);
2442
+ }
2443
+ prefix = storageType === "globalStorage" || !appIdentifier ? `${prefix}:` : `${prefix}:${appIdentifier}:`;
2444
+ return new MockStorageApi(prefix, syncDelay);
2445
+ }
2446
+ var MockStorageApi = class {
2447
+ constructor(prefix, syncDelay) {
2448
+ __publicField(this, "prefix");
2449
+ __publicField(this, "syncDelay");
2450
+ this.prefix = prefix;
2451
+ this.syncDelay = syncDelay;
2452
+ }
2453
+ async clear() {
2454
+ const fullLength = localStorage.length;
2455
+ for (let i = 0; i < fullLength; i++) {
2456
+ const fullKey = localStorage.key(i);
2457
+ if (fullKey && fullKey.startsWith(this.prefix)) {
2458
+ localStorage.removeItem(fullKey);
2459
+ }
2460
+ }
2461
+ await this.simulateSyncDelay();
2462
+ }
2463
+ async getAllItems() {
2464
+ const items = new Array();
2465
+ const fullLength = localStorage.length;
2466
+ for (let i = 0; i < fullLength; i++) {
2467
+ const fullKey = localStorage.key(i);
2468
+ if (fullKey && fullKey.startsWith(this.prefix)) {
2469
+ const item = localStorage.getItem(fullKey);
2470
+ if (item) {
2471
+ items.push(item);
2472
+ }
2473
+ }
2474
+ }
2475
+ return items;
2476
+ }
2477
+ async getItem(key) {
2478
+ const fullKey = this.buildKey(key);
2479
+ await this.simulateSyncDelay();
2480
+ return localStorage.getItem(fullKey);
2481
+ }
2482
+ async key(index) {
2483
+ const keys = this.keys();
2484
+ if (index < 0 || index >= keys.length) {
2485
+ return null;
2486
+ }
2487
+ await this.simulateSyncDelay();
2488
+ return keys[index];
2489
+ }
2490
+ async length() {
2491
+ return this.keys().length;
2492
+ }
2493
+ async removeItem(key) {
2494
+ const fullKey = this.buildKey(key);
2495
+ await this.simulateSyncDelay();
2496
+ localStorage.removeItem(fullKey);
2497
+ }
2498
+ async setItem(key, item) {
2499
+ const fullKey = this.buildKey(key);
2500
+ await this.simulateSyncDelay();
2501
+ localStorage.setItem(fullKey, item);
2502
+ }
2503
+ async setMultipleItems(entries) {
2504
+ for (const entry of entries) {
2505
+ const fullKey = this.buildKey(entry.key);
2506
+ localStorage.setItem(fullKey, entry.value);
2507
+ }
2508
+ await this.simulateSyncDelay();
2509
+ }
2510
+ async removeMultipleItems(keys) {
2511
+ for (const key of keys) {
2512
+ const fullKey = this.buildKey(key);
2513
+ localStorage.removeItem(fullKey);
2514
+ }
2515
+ await this.simulateSyncDelay();
2349
2516
  }
2350
2517
  buildKey(key) {
2351
2518
  const prefix = this.prefix;
@@ -2485,24 +2652,20 @@ function initializeStorage(venusApiInstance, host) {
2485
2652
  venusApiInstance.globalStorage = host.globalStorage;
2486
2653
  }
2487
2654
 
2488
- // src/simulation/utils.ts
2489
- function sumContributions(contributions) {
2490
- const totals = {};
2491
- for (const profileId in contributions) {
2492
- for (const entityId in contributions[profileId]) {
2493
- const amount = contributions[profileId][entityId] || 0;
2494
- totals[entityId] = (totals[entityId] || 0) + amount;
2495
- }
2496
- }
2497
- return totals;
2498
- }
2499
-
2500
2655
  // src/simulation/RpcSimulationApi.ts
2501
2656
  var RpcSimulationApi = class {
2502
2657
  constructor(rpcClient) {
2503
2658
  __publicField(this, "rpcClient");
2504
2659
  __publicField(this, "_simulationConfig", null);
2660
+ __publicField(this, "subscriptionCallbacks", /* @__PURE__ */ new Map());
2505
2661
  this.rpcClient = rpcClient;
2662
+ this.rpcClient.onNotification(
2663
+ "H5_SIMULATION_UPDATE" /* H5_SIMULATION_UPDATE */,
2664
+ this.handleSimulationUpdate.bind(this)
2665
+ );
2666
+ }
2667
+ isEnabled() {
2668
+ return true;
2506
2669
  }
2507
2670
  async validateSlotAssignmentAsync(containerId, slotId, itemId) {
2508
2671
  return this.rpcClient.call(
@@ -2514,14 +2677,47 @@ var RpcSimulationApi = class {
2514
2677
  }
2515
2678
  );
2516
2679
  }
2517
- sumContributions(contributions) {
2518
- return sumContributions(contributions);
2680
+ async subscribeAsync(options) {
2681
+ this.ensureValidSubscribeOptions(options);
2682
+ const subscriptionId = generateId();
2683
+ this.subscriptionCallbacks.set(subscriptionId, options.onUpdate);
2684
+ try {
2685
+ await this.rpcClient.call("H5_SIMULATION_SUBSCRIBE" /* H5_SIMULATION_SUBSCRIBE */, {
2686
+ subscriptionId,
2687
+ entities: options.entities,
2688
+ tags: options.tags,
2689
+ activeRuns: options.activeRuns,
2690
+ roomId: options.roomId
2691
+ });
2692
+ } catch (error) {
2693
+ this.subscriptionCallbacks.delete(subscriptionId);
2694
+ throw error;
2695
+ }
2696
+ let unsubscribed = false;
2697
+ return () => {
2698
+ if (unsubscribed) {
2699
+ return;
2700
+ }
2701
+ unsubscribed = true;
2702
+ this.subscriptionCallbacks.delete(subscriptionId);
2703
+ void this.rpcClient.call("H5_SIMULATION_UNSUBSCRIBE" /* H5_SIMULATION_UNSUBSCRIBE */, {
2704
+ subscriptionId
2705
+ }).catch((error) => {
2706
+ console.error(
2707
+ "[Venus SDK] Failed to unsubscribe simulation listener",
2708
+ error
2709
+ );
2710
+ });
2711
+ };
2519
2712
  }
2520
2713
  executeBatchOperationsAsync(operations, validateOnly) {
2521
- return this.rpcClient.call("H5_SIMULATION_BATCH_OPERATIONS" /* H5_SIMULATION_BATCH_OPERATIONS */, {
2522
- operations,
2523
- validateOnly
2524
- });
2714
+ return this.rpcClient.call(
2715
+ "H5_SIMULATION_BATCH_OPERATIONS" /* H5_SIMULATION_BATCH_OPERATIONS */,
2716
+ {
2717
+ operations,
2718
+ validateOnly
2719
+ }
2720
+ );
2525
2721
  }
2526
2722
  async getAvailableItemsAsync(containerId, slotId) {
2527
2723
  const response = await this.rpcClient.call(
@@ -2544,17 +2740,23 @@ var RpcSimulationApi = class {
2544
2740
  );
2545
2741
  }
2546
2742
  assignItemToSlotAsync(containerId, slotId, itemId) {
2547
- return this.rpcClient.call("H5_SIMULATION_ASSIGN_ITEM" /* H5_SIMULATION_ASSIGN_ITEM */, {
2548
- containerId,
2549
- slotId,
2550
- itemId
2551
- });
2743
+ return this.rpcClient.call(
2744
+ "H5_SIMULATION_ASSIGN_ITEM" /* H5_SIMULATION_ASSIGN_ITEM */,
2745
+ {
2746
+ containerId,
2747
+ slotId,
2748
+ itemId
2749
+ }
2750
+ );
2552
2751
  }
2553
2752
  removeItemFromSlotAsync(containerId, slotId) {
2554
- return this.rpcClient.call("H5_SIMULATION_REMOVE_ITEM" /* H5_SIMULATION_REMOVE_ITEM */, {
2555
- containerId,
2556
- slotId
2557
- });
2753
+ return this.rpcClient.call(
2754
+ "H5_SIMULATION_REMOVE_ITEM" /* H5_SIMULATION_REMOVE_ITEM */,
2755
+ {
2756
+ containerId,
2757
+ slotId
2758
+ }
2759
+ );
2558
2760
  }
2559
2761
  async getSlotContainersAsync() {
2560
2762
  const response = await this.rpcClient.call(
@@ -2579,7 +2781,6 @@ var RpcSimulationApi = class {
2579
2781
  roomId
2580
2782
  }
2581
2783
  );
2582
- console.log("[Venus SDK] getStateAsync", response);
2583
2784
  if (response.configuration) {
2584
2785
  this._simulationConfig = response.configuration;
2585
2786
  }
@@ -2591,9 +2792,10 @@ var RpcSimulationApi = class {
2591
2792
  }
2592
2793
  const config = await this.rpcClient.call(
2593
2794
  "H5_SIMULATION_GET_CONFIG" /* H5_SIMULATION_GET_CONFIG */,
2594
- {}
2795
+ {
2796
+ roomId
2797
+ }
2595
2798
  );
2596
- console.log("[Venus SDK] getConfigAsync", config);
2597
2799
  if (config) {
2598
2800
  this._simulationConfig = config;
2599
2801
  return config;
@@ -2601,14 +2803,17 @@ var RpcSimulationApi = class {
2601
2803
  throw new Error("No simulation configuration available");
2602
2804
  }
2603
2805
  executeRecipeAsync(recipeId, inputs, options) {
2604
- return this.rpcClient.call("H5_SIMULATION_EXECUTE_RECIPE" /* H5_SIMULATION_EXECUTE_RECIPE */, {
2605
- recipeId,
2606
- inputs,
2607
- roomId: options?.roomId,
2608
- batchAmount: options?.batchAmount,
2609
- allowPartialBatch: options?.allowPartialBatch,
2610
- entity: options?.entity
2611
- });
2806
+ return this.rpcClient.call(
2807
+ "H5_SIMULATION_EXECUTE_RECIPE" /* H5_SIMULATION_EXECUTE_RECIPE */,
2808
+ {
2809
+ recipeId,
2810
+ inputs,
2811
+ roomId: options?.roomId,
2812
+ batchAmount: options?.batchAmount,
2813
+ allowPartialBatch: options?.allowPartialBatch,
2814
+ entity: options?.entity
2815
+ }
2816
+ );
2612
2817
  }
2613
2818
  collectRecipeAsync(runId) {
2614
2819
  return this.rpcClient.call("H5_SIMULATION_COLLECT_RECIPE" /* H5_SIMULATION_COLLECT_RECIPE */, {
@@ -2616,9 +2821,12 @@ var RpcSimulationApi = class {
2616
2821
  });
2617
2822
  }
2618
2823
  getActiveRunsAsync(options) {
2619
- return this.rpcClient.call("H5_SIMULATION_GET_ACTIVE_RUNS" /* H5_SIMULATION_GET_ACTIVE_RUNS */, {
2620
- roomId: options?.roomId
2621
- });
2824
+ return this.rpcClient.call(
2825
+ "H5_SIMULATION_GET_ACTIVE_RUNS" /* H5_SIMULATION_GET_ACTIVE_RUNS */,
2826
+ {
2827
+ roomId: options?.roomId
2828
+ }
2829
+ );
2622
2830
  }
2623
2831
  executeScopedRecipeAsync(recipeId, entity, inputs, options) {
2624
2832
  return this.rpcClient.call(
@@ -2688,583 +2896,52 @@ var RpcSimulationApi = class {
2688
2896
  );
2689
2897
  return response.value;
2690
2898
  }
2691
- };
2692
-
2693
- // src/simulation/MockSimulationApi.ts
2694
- function generateAppIdentifier2() {
2695
- if (typeof window === "undefined") return "unknown-app";
2696
- const url = window.location.href;
2697
- const match = url.match(/\/H5\/([^\/]+)/);
2698
- return match ? match[1] : "unknown-app";
2699
- }
2700
- var MockSimulationApi = class {
2701
- constructor(simulationConfig = null) {
2702
- __publicField(this, "mockSimulationConfigs", /* @__PURE__ */ new Map());
2703
- // appIdentifier -> config
2704
- __publicField(this, "mockSimulationStates", /* @__PURE__ */ new Map());
2705
- // appIdentifier -> config
2706
- __publicField(this, "mockActiveTimers", /* @__PURE__ */ new Map());
2707
- // appIdentifier -> timers[]
2708
- __publicField(this, "appId");
2709
- __publicField(this, "providedSimulationConfig");
2710
- this.appId = generateAppIdentifier2();
2711
- this.providedSimulationConfig = simulationConfig;
2712
- }
2713
- sumContributions(contributions) {
2714
- return sumContributions(contributions);
2715
- }
2716
- async validateSlotAssignmentAsync(containerId, slotId, itemId) {
2717
- this.log("validateSlotAssignmentAsync called:", {
2718
- containerId,
2719
- slotId,
2720
- itemId
2721
- });
2722
- return { valid: true, message: "Mock validation successful" };
2723
- }
2724
- async executeBatchOperationsAsync(operations, validateOnly) {
2725
- this.log("executeBatchOperationsAsync called:", {
2726
- operations,
2727
- validateOnly
2728
- });
2729
- return {
2730
- success: true,
2731
- results: operations.map(() => ({ success: true }))
2732
- };
2733
- }
2734
- async getAvailableItemsAsync(containerId, slotId) {
2735
- console.log("[Venus Simulation Mock] getAvailableItemsAsync called:", {
2736
- containerId,
2737
- slotId
2738
- });
2739
- const appIdentifier = generateAppIdentifier2();
2740
- const mockSimulationConfigs = this.mockSimulationConfigs;
2741
- const config = mockSimulationConfigs.get(appIdentifier) || {
2742
- entities: {}
2743
- };
2744
- const availableItems = Object.entries(config.entities).slice(0, 3).map(([entityId, entity]) => ({
2745
- entityId,
2746
- quantity: 1,
2747
- metadata: entity.metadata,
2748
- powerPreview: 100
2749
- // Mock power value
2750
- }));
2751
- return availableItems;
2752
- }
2753
- async calculatePowerPreviewAsync(containerId, slotId, candidateItemId) {
2754
- this.log("calculatePowerPreviewAsync called:", {
2755
- containerId,
2756
- slotId,
2757
- candidateItemId
2758
- });
2759
- return {
2760
- currentPower: 1e3,
2761
- previewPower: 1200,
2762
- powerDelta: 200,
2763
- breakdown: { base: 800, weapon: 200, armor: 200 }
2764
- };
2765
- }
2766
- async getSlotContainersAsync() {
2767
- this.log("getSlotContainersAsync called");
2768
- const appIdentifier = this.appId;
2769
- const mockSimulationConfigs = this.mockSimulationConfigs;
2770
- const config = mockSimulationConfigs.get(appIdentifier) || {
2771
- entities: {}
2772
- };
2773
- const containers = Object.entries(config.entities).filter(([_, entity]) => entity.metadata?.slots).map(([entityId, entity]) => ({
2774
- entityId,
2775
- slots: entity.metadata?.slots,
2776
- isOwned: true
2777
- // Mock: assume all containers are owned
2778
- }));
2779
- return containers;
2780
- }
2781
- async getSlotAssignmentsAsync(containerId) {
2782
- this.log("getSlotAssignmentsAsync called for:", containerId);
2783
- return [];
2784
- }
2785
- async resolveFieldValueAsync(entityId, fieldPath, entity) {
2786
- this.log("resolveFieldValueAsync called:", {
2787
- entityId,
2788
- fieldPath,
2789
- entity
2790
- });
2791
- const mockValues = {
2792
- basePower: 850,
2793
- weaponPower: 300,
2794
- armorPower: 150,
2795
- total_power: 1300,
2796
- total_defense_power: 5e3
2797
- };
2798
- return mockValues[fieldPath] || 100;
2799
- }
2800
- async getEntityMetadataAsync(entityId) {
2801
- this.log("getEntityMetadataAsync called for:", entityId);
2802
- const mockSimulationConfigs = this.mockSimulationConfigs;
2803
- const appIdentifier = this.appId;
2804
- const config = mockSimulationConfigs.get(
2805
- appIdentifier
2806
- ) || {
2807
- entities: {}};
2808
- const entity = config.entities[entityId];
2809
- return entity?.metadata || {};
2810
- }
2811
- async collectRecipeAsync(runId) {
2812
- this.log("collectRecipeAsync called:", { runId });
2813
- const mockRewards = {
2814
- cash: Math.floor(Math.random() * 1e3) + 500,
2815
- experience: Math.floor(Math.random() * 50) + 25
2816
- };
2817
- return {
2818
- success: true,
2819
- runId,
2820
- rewards: mockRewards,
2821
- message: "Rewards collected successfully"
2822
- };
2823
- }
2824
- executeRecipeAsync(recipeId, inputs, options) {
2825
- this.log("executeRecipeAsync called:", {
2826
- recipeId,
2827
- inputs,
2828
- options
2829
- });
2830
- const appIdentifier = this.appId;
2831
- return this.executeRecipe(appIdentifier, recipeId, inputs);
2832
- }
2833
- async executeScopedRecipeAsync(recipeId, entity, inputs, options) {
2834
- this.log("executeScopedRecipeAsync called:", {
2835
- recipeId,
2836
- entity,
2837
- inputs,
2838
- roomId: options?.roomId,
2839
- options
2840
- });
2841
- return {
2842
- success: true,
2843
- message: "Mock scoped recipe execution successful"
2844
- };
2845
- }
2846
- async getActiveRunsAsync(options) {
2847
- this.log("getActiveRunsAsync called:", options);
2848
- const appIdentifier = this.appId;
2849
- let state = this.mockSimulationStates.get(appIdentifier);
2850
- if (!state) {
2851
- state = await this.initializeSimulationState(appIdentifier);
2852
- }
2853
- return state.activeRuns || [];
2854
- }
2855
- async getAvailableRecipesAsync(options) {
2856
- this.log("getAvailableRecipesAsync called:", options);
2857
- const baseRecipes = [
2858
- { id: "collect_resources", scope: "player", clientViewable: true },
2859
- { id: "upgrade_equipment", scope: "player", clientViewable: true }
2860
- ];
2861
- if (options?.roomId) {
2862
- baseRecipes.push(
2863
- { id: "room_upgrade", scope: "room", clientViewable: true },
2864
- { id: "cooperative_project", scope: "room", clientViewable: true }
2865
- );
2899
+ handleSimulationUpdate(notification) {
2900
+ if (!notification || !notification.subscriptionId) {
2901
+ console.warn("[Venus SDK] Received malformed simulation update");
2902
+ return;
2866
2903
  }
2867
- if (options?.includeActorRecipes && options?.roomId) {
2868
- baseRecipes.push(
2869
- { id: "trade_with_npc", scope: "actor", clientViewable: true },
2870
- { id: "attack_monster", scope: "actor", clientViewable: true }
2904
+ const callback = this.subscriptionCallbacks.get(notification.subscriptionId);
2905
+ if (!callback) {
2906
+ console.warn(
2907
+ "[Venus SDK] Received update for unknown subscription:",
2908
+ notification.subscriptionId
2871
2909
  );
2910
+ return;
2872
2911
  }
2873
- return { success: true, recipes: baseRecipes };
2874
- }
2875
- async getBatchRecipeRequirementsAsync(recipes) {
2876
- this.log("getBatchRecipeRequirementsAsync called:", {
2877
- count: recipes?.length
2878
- });
2879
- const results = (recipes || []).map((q) => ({
2880
- recipeId: q.recipeId,
2881
- entity: q.entity || null,
2882
- amount: q.batchAmount || 1,
2883
- inputs: { cash: "BE:0" },
2884
- canAfford: true,
2885
- disabled: false
2886
- }));
2887
- return { success: true, results };
2888
- }
2889
- async getRecipeRequirementsAsync(recipe) {
2890
- this.log("getRecipeRequirementsAsync called:", recipe);
2891
- return {
2892
- recipeId: recipe.recipeId,
2893
- entity: recipe.entity || null,
2894
- amount: recipe.batchAmount,
2895
- inputs: { cash: "BE:0" },
2896
- canAfford: true,
2897
- disabled: false
2898
- };
2899
- }
2900
- async triggerRecipeChainAsync(recipeId, options) {
2901
- this.log("triggerRecipeChainAsync called:", { recipeId, ...options });
2902
- return {
2903
- success: true,
2904
- message: "Mock recipe chain triggered successfully"
2905
- };
2906
- }
2907
- log(message, ...args) {
2908
- console.log(`[Venus Sim Mock] ${message}`, args);
2909
- }
2910
- async executeRecipe(appIdentifier, recipeId, inputs) {
2911
- this.log(`Executing recipe ${recipeId} for ${appIdentifier}`, inputs);
2912
- const mockSimulationConfigs = this.mockSimulationConfigs;
2913
- const mockSimulationStates = this.mockSimulationStates;
2914
- let config = mockSimulationConfigs.get(appIdentifier);
2915
- let state = mockSimulationStates.get(appIdentifier);
2916
- if (!config || !state) {
2917
- state = await this.initializeSimulationState(appIdentifier);
2918
- config = mockSimulationConfigs.get(appIdentifier);
2919
- if (!config) {
2920
- throw new Error("Failed to initialize simulation config");
2921
- }
2922
- }
2923
- const recipe = config.recipes?.[recipeId];
2924
- if (!recipe) {
2925
- throw new Error(`Recipe ${recipeId} not found`);
2926
- }
2927
- if (state.disabledRecipes?.includes(recipeId)) {
2928
- throw new Error(`Recipe ${recipeId} is disabled`);
2929
- }
2930
- if (recipe.inputs) {
2931
- for (const [entityId, required] of Object.entries(recipe.inputs)) {
2932
- const available = state.inventory[entityId] || 0;
2933
- if (available < required) {
2934
- throw new Error(
2935
- `Insufficient ${entityId}: required ${required}, available ${available}`
2936
- );
2937
- }
2938
- }
2939
- }
2940
- if (recipe.inputs) {
2941
- for (const [entityId, input] of Object.entries(recipe.inputs)) {
2942
- const inventoryValue = state.inventory[entityId] || 0;
2943
- if (typeof input === "number" && typeof inventoryValue === "number") {
2944
- state.inventory[entityId] = inventoryValue - input;
2945
- }
2946
- }
2947
- }
2948
- if (recipe.beginEffects) {
2949
- this.applyEffects(state, recipe.beginEffects);
2950
- }
2951
- const runId = this.generateRunId();
2952
- const now = Date.now();
2953
- const expiresAt = now + (recipe.duration || 0);
2954
- const run = {
2955
- id: runId,
2956
- recipeId,
2957
- status: "running",
2958
- startTime: now,
2959
- expiresAt,
2960
- inputs: recipe.inputs || {}
2961
- };
2962
- state.activeRuns.push(run);
2963
- if (recipe.duration === 0) {
2964
- this.completeRun(appIdentifier, runId);
2965
- return { status: "completed", runId };
2966
- } else {
2967
- const mockActiveTimers = this.mockActiveTimers;
2968
- const timer = setTimeout(() => {
2969
- this.completeRun(appIdentifier, runId);
2970
- }, recipe.duration);
2971
- const timers = mockActiveTimers.get(appIdentifier) || [];
2972
- timers.push(timer);
2973
- mockActiveTimers.set(appIdentifier, timers);
2974
- return {
2975
- status: "running",
2976
- runId,
2977
- expiresAt: new Date(expiresAt).toISOString()
2978
- };
2912
+ try {
2913
+ callback(notification.updates);
2914
+ } catch (error) {
2915
+ console.error("[Venus SDK] Error in simulation subscription callback", error);
2979
2916
  }
2980
2917
  }
2981
- async initializeSimulationState(appIdentifier) {
2982
- this.log(`Initializing simulation state for ${appIdentifier}`);
2983
- const providedSimulationConfig = this.providedSimulationConfig;
2984
- const mockSimulationConfigs = this.mockSimulationConfigs;
2985
- const mockSimulationStates = this.mockSimulationStates;
2986
- const mockActiveTimers = this.mockActiveTimers;
2987
- const config = providedSimulationConfig || {
2988
- version: "1.0",
2989
- entities: {},
2990
- recipes: {}
2991
- };
2992
- mockSimulationConfigs.set(appIdentifier, config);
2993
- const initialInventory = {};
2994
- if (providedSimulationConfig && config.entities) {
2995
- Object.keys(config.entities).forEach((entityId) => {
2996
- initialInventory[entityId] = 0;
2997
- });
2998
- }
2999
- const state = {
3000
- inventory: initialInventory,
3001
- activeRuns: [],
3002
- disabledRecipes: new Array()
3003
- };
3004
- if (config.recipes) {
3005
- Object.entries(config.recipes).forEach(([recipeId, recipe]) => {
3006
- if (recipe.metadata?.startsDisabled) {
3007
- state.disabledRecipes.push(recipeId);
3008
- }
3009
- });
3010
- }
3011
- mockSimulationStates.set(appIdentifier, state);
3012
- mockActiveTimers.set(appIdentifier, []);
3013
- console.log(
3014
- `[Venus Simulation Mock] Initialized state for ${appIdentifier}:`,
3015
- state
3016
- );
3017
- if (config.recipes) {
3018
- Object.entries(config.recipes).forEach(([recipeId, recipe]) => {
3019
- const isAutoRestart = recipe.autoRestart || recipe.metadata?.autoRestart;
3020
- if (isAutoRestart && recipe.outputs) {
3021
- this.log(`Found auto-restart recipe: ${recipeId}`, {
3022
- topLevelAutoRestart: recipe.autoRestart,
3023
- metadataAutoRestart: recipe.metadata?.autoRestart,
3024
- hasOutputs: !!recipe.outputs,
3025
- duration: recipe.duration
3026
- });
3027
- const condition = recipe.maxRestartCondition || recipe.metadata?.maxRestartCondition;
3028
- if (condition && condition.entity) {
3029
- const currentAmount = initialInventory[condition.entity] || 0;
3030
- if (currentAmount < condition.maxValue) {
3031
- console.log(
3032
- `[Venus Simulation Mock] Auto-starting ${recipeId} at initialization`,
3033
- {
3034
- currentAmount,
3035
- maxValue: condition.maxValue,
3036
- entity: condition.entity
3037
- }
3038
- );
3039
- setTimeout(() => {
3040
- this.executeRecipe(appIdentifier, recipeId, {});
3041
- }, 1e3);
3042
- }
3043
- } else {
3044
- console.log(
3045
- `[Venus Simulation Mock] Auto-starting ${recipeId} at initialization (no condition)`
3046
- );
3047
- setTimeout(() => {
3048
- this.executeRecipe(appIdentifier, recipeId, {});
3049
- }, 1e3);
3050
- }
3051
- }
3052
- });
3053
- }
3054
- return state;
3055
- }
3056
- generateRunId() {
3057
- return "run_" + Date.now() + "_" + Math.random().toString(36).substr(2, 9);
3058
- }
3059
- completeRun(appIdentifier, runId) {
3060
- this.log(`Completing run ${runId} for ${appIdentifier}`);
3061
- const mockSimulationConfigs = this.mockSimulationConfigs;
3062
- const mockSimulationStates = this.mockSimulationStates;
3063
- const config = mockSimulationConfigs.get(appIdentifier);
3064
- const state = mockSimulationStates.get(appIdentifier);
3065
- if (!config || !state) return;
3066
- const runIndex = state.activeRuns.findIndex((r) => r.id === runId);
3067
- if (runIndex === -1) return;
3068
- const run = state.activeRuns[runIndex];
3069
- const recipe = config.recipes?.[run.recipeId];
3070
- if (!recipe) return;
3071
- const outputs = {};
3072
- const rng = this.createSeededRandom(runId);
3073
- if (recipe.outputs) {
3074
- for (const [entityId, value] of Object.entries(recipe.outputs)) {
3075
- if (typeof value === "number") {
3076
- outputs[entityId] = value;
3077
- } else if (typeof value === "object" && value != null && "min" in value && "max" in value && typeof value.min == "number" && typeof value.max === "number") {
3078
- outputs[entityId] = Math.floor(rng() * (value.max - value.min + 1)) + value.min;
3079
- }
3080
- }
2918
+ ensureValidSubscribeOptions(options) {
2919
+ if (typeof options !== "object" || options === null) {
2920
+ throw new Error("Simulation subscribe requires an options object");
3081
2921
  }
3082
- for (const [entityId, amount] of Object.entries(outputs)) {
3083
- state.inventory[entityId] = (state.inventory[entityId] || 0) + amount;
2922
+ const opts = options;
2923
+ if (typeof opts.onUpdate !== "function") {
2924
+ throw new Error("Simulation subscribe requires an onUpdate callback");
3084
2925
  }
3085
- if (recipe.endEffects) {
3086
- this.applyEffects(state, recipe.endEffects);
3087
- }
3088
- run.status = "completed";
3089
- run.outputs = outputs;
3090
- state.activeRuns.splice(runIndex, 1);
3091
- const isAutoRestart = recipe.autoRestart || recipe.metadata?.autoRestart;
3092
- if (isAutoRestart) {
3093
- console.log(
3094
- `[Venus Simulation Mock] Checking auto-restart for ${run.recipeId}`,
3095
- {
3096
- topLevelAutoRestart: recipe.autoRestart,
3097
- metadataAutoRestart: recipe.metadata?.autoRestart,
3098
- hasCondition: !!(recipe.maxRestartCondition || recipe.metadata?.maxRestartCondition)
3099
- }
2926
+ const hasFilter = Array.isArray(opts.entities) && opts.entities.length > 0 || Array.isArray(opts.tags) && opts.tags.length > 0 || Boolean(opts.activeRuns);
2927
+ if (!hasFilter) {
2928
+ throw new Error(
2929
+ "Simulation subscribe requires at least one filter (entities, tags, activeRuns)"
3100
2930
  );
3101
- const condition = recipe.maxRestartCondition || recipe.metadata?.maxRestartCondition;
3102
- if (condition) {
3103
- const currentAmount = state.inventory[condition.entity] || 0;
3104
- if (currentAmount < condition.maxValue) {
3105
- console.log(
3106
- `[Venus Simulation Mock] Auto-restarting ${run.recipeId}`,
3107
- {
3108
- currentAmount,
3109
- maxValue: condition.maxValue,
3110
- entity: condition.entity
3111
- }
3112
- );
3113
- setTimeout(() => {
3114
- this.executeRecipe(appIdentifier, run.recipeId, recipe.inputs || {});
3115
- }, 1e3);
3116
- }
3117
- } else {
3118
- console.log(
3119
- `[Venus Simulation Mock] Auto-restarting ${run.recipeId} (no condition)`
3120
- );
3121
- setTimeout(() => {
3122
- this.executeRecipe(appIdentifier, run.recipeId, recipe.inputs || {});
3123
- }, 1e3);
3124
- }
3125
- }
3126
- console.log(
3127
- `[Venus Simulation Mock] Completed run ${runId}, outputs:`,
3128
- outputs
3129
- );
3130
- }
3131
- createSeededRandom(seed) {
3132
- let hash = 0;
3133
- for (let i = 0; i < seed.length; i++) {
3134
- const char = seed.charCodeAt(i);
3135
- hash = (hash << 5) - hash + char;
3136
- hash = hash & hash;
3137
- }
3138
- return () => {
3139
- hash = (hash * 9301 + 49297) % 233280;
3140
- return hash / 233280;
3141
- };
3142
- }
3143
- applyEffects(state, effects) {
3144
- if (!effects || !Array.isArray(effects)) return;
3145
- for (const effect of effects) {
3146
- switch (effect.type) {
3147
- case "set":
3148
- state.inventory[effect.target] = effect.value;
3149
- console.log(
3150
- `[Venus Simulation Mock] Effect: Set ${effect.target} = ${effect.value}`
3151
- );
3152
- break;
3153
- case "add":
3154
- state.inventory[effect.target] = (state.inventory[effect.target] || 0) + effect.value;
3155
- console.log(
3156
- `[Venus Simulation Mock] Effect: Add ${effect.value} to ${effect.target} (new value: ${state.inventory[effect.target]})`
3157
- );
3158
- break;
3159
- case "multiply":
3160
- state.inventory[effect.target] = (state.inventory[effect.target] || 0) * effect.value;
3161
- console.log(
3162
- `[Venus Simulation Mock] Effect: Multiply ${effect.target} by ${effect.value} (new value: ${state.inventory[effect.target]})`
3163
- );
3164
- break;
3165
- case "min":
3166
- state.inventory[effect.target] = Math.max(
3167
- state.inventory[effect.target] || 0,
3168
- effect.value
3169
- );
3170
- console.log(
3171
- `[Venus Simulation Mock] Effect: Set ${effect.target} min ${effect.value} (new value: ${state.inventory[effect.target]})`
3172
- );
3173
- break;
3174
- case "max":
3175
- state.inventory[effect.target] = Math.min(
3176
- state.inventory[effect.target] || 0,
3177
- effect.value
3178
- );
3179
- console.log(
3180
- `[Venus Simulation Mock] Effect: Set ${effect.target} max ${effect.value} (new value: ${state.inventory[effect.target]})`
3181
- );
3182
- break;
3183
- case "enable_recipe":
3184
- if (state.disabledRecipes?.includes(effect.target)) {
3185
- state.disabledRecipes = state.disabledRecipes.filter(
3186
- (r) => r !== effect.target
3187
- );
3188
- console.log(
3189
- `[Venus Simulation Mock] Effect: Enabled recipe ${effect.target}`
3190
- );
3191
- }
3192
- break;
3193
- case "disable_recipe":
3194
- if (!state.disabledRecipes) state.disabledRecipes = [];
3195
- if (!state.disabledRecipes.includes(effect.target)) {
3196
- state.disabledRecipes.push(effect.target);
3197
- console.log(
3198
- `[Venus Simulation Mock] Effect: Disabled recipe ${effect.target}`
3199
- );
3200
- }
3201
- break;
3202
- case "trigger_recipe":
3203
- console.log(
3204
- `[Venus Simulation Mock] Effect: Trigger recipe ${effect.target} (not implemented)`
3205
- );
3206
- break;
3207
- default:
3208
- console.warn(
3209
- `[Venus Simulation Mock] Unknown effect type: ${effect.type}`
3210
- );
3211
- }
3212
2931
  }
3213
2932
  }
3214
- async getConfigAsync() {
3215
- console.log("[Venus Simulation Mock] getConfigAsync called");
3216
- const appIdentifier = this.appId;
3217
- const mockSimulationConfigs = this.mockSimulationConfigs;
3218
- const config = mockSimulationConfigs.get(appIdentifier) || {
3219
- version: "1.0",
3220
- entities: {},
3221
- recipes: {}
3222
- };
3223
- return config;
3224
- }
3225
- async getStateAsync(roomId) {
3226
- this.log("getStateAsync called:", roomId);
3227
- const appIdentifier = this.appId;
3228
- const mockSimulationStates = this.mockSimulationStates;
3229
- let state = mockSimulationStates.get(appIdentifier);
3230
- if (!state) {
3231
- state = await this.initializeSimulationState(appIdentifier);
3232
- }
3233
- const mockSimulationConfigs = this.mockSimulationConfigs;
3234
- return {
3235
- ...state,
3236
- roomId,
3237
- configuration: mockSimulationConfigs.get(appIdentifier)
3238
- };
3239
- }
3240
- async assignItemToSlotAsync(containerId, slotId, itemId) {
3241
- this.log("assignItemToSlotAsync called:", {
3242
- containerId,
3243
- slotId,
3244
- itemId
3245
- });
3246
- return { success: true, message: "Mock assignment successful" };
3247
- }
3248
- async removeItemFromSlotAsync(containerId, slotId) {
3249
- this.log("removeItemFromSlotAsync called:", {
3250
- containerId,
3251
- slotId
3252
- });
3253
- return { success: true, message: "Mock removal successful" };
3254
- }
3255
2933
  };
3256
2934
 
3257
2935
  // src/simulation/index.ts
3258
2936
  function initializeSimulation(venusApi, host) {
3259
- console.log("[Venus SDK] Initializing new Simulation Api");
3260
2937
  venusApi.simulation = {
3261
2938
  isEnabled: () => true
3262
2939
  };
3263
2940
  venusApi.simulation.getConfigAsync = () => {
3264
2941
  return host.simulation.getConfigAsync();
3265
2942
  };
3266
- venusApi.simulation.getStateAsync = (options) => {
3267
- return host.simulation.getStateAsync(options?.roomId);
2943
+ venusApi.simulation.getStateAsync = (roomId) => {
2944
+ return host.simulation.getStateAsync(roomId);
3268
2945
  };
3269
2946
  venusApi.simulation.executeRecipeAsync = (recipeId, inputs, options) => {
3270
2947
  return host.simulation.executeRecipeAsync(recipeId, inputs, options);
@@ -3275,31 +2952,17 @@ function initializeSimulation(venusApi, host) {
3275
2952
  venusApi.simulation.collectRecipeAsync = (runId) => {
3276
2953
  return host.simulation.collectRecipeAsync(runId);
3277
2954
  };
3278
- venusApi.simulation.executeScopedRecipeAsync = (recipeId, entity, inputs, roomId, options) => {
3279
- return host.simulation.executeScopedRecipeAsync(recipeId, entity, inputs, {
3280
- roomId,
3281
- ...options
3282
- });
2955
+ venusApi.simulation.executeScopedRecipeAsync = (recipeId, entity, inputs, options) => {
2956
+ return host.simulation.executeScopedRecipeAsync(recipeId, entity, inputs, options);
3283
2957
  };
3284
- venusApi.simulation.triggerRecipeChainAsync = (recipeId, context, roomId) => {
3285
- return host.simulation.triggerRecipeChainAsync(recipeId, {
3286
- context,
3287
- roomId
3288
- });
2958
+ venusApi.simulation.triggerRecipeChainAsync = (recipeId, options) => {
2959
+ return host.simulation.triggerRecipeChainAsync(recipeId, options);
3289
2960
  };
3290
- venusApi.simulation.getAvailableRecipesAsync = async (roomId, includeActorRecipes) => {
3291
- const result = await host.simulation.getAvailableRecipesAsync({
3292
- roomId,
3293
- includeActorRecipes
3294
- });
3295
- return result.recipes;
2961
+ venusApi.simulation.getAvailableRecipesAsync = async (options) => {
2962
+ return host.simulation.getAvailableRecipesAsync(options);
3296
2963
  };
3297
- venusApi.simulation.getRecipeRequirementsAsync = (recipeId, entity, amount) => {
3298
- return host.simulation.getRecipeRequirementsAsync({
3299
- recipeId,
3300
- entity,
3301
- batchAmount: amount
3302
- });
2964
+ venusApi.simulation.getRecipeRequirementsAsync = (recipe) => {
2965
+ return host.simulation.getRecipeRequirementsAsync(recipe);
3303
2966
  };
3304
2967
  venusApi.simulation.getBatchRecipeRequirementsAsync = (recipes) => {
3305
2968
  return host.simulation.getBatchRecipeRequirementsAsync(recipes);
@@ -3342,9 +3005,6 @@ function initializeSimulation(venusApi, host) {
3342
3005
  itemId
3343
3006
  );
3344
3007
  };
3345
- venusApi.simulation.sumContributions = (contributions) => {
3346
- return host.simulation.sumContributions(contributions);
3347
- };
3348
3008
  }
3349
3009
 
3350
3010
  // src/time/utils.ts
@@ -3363,9 +3023,11 @@ function isPacificDaylightTime(date) {
3363
3023
 
3364
3024
  // src/time/HostTimeApi.ts
3365
3025
  var HostTimeApi = class {
3366
- constructor(rpcClient) {
3026
+ constructor(rpcClient, venusApi) {
3367
3027
  __publicField(this, "rpcClient");
3028
+ __publicField(this, "venusApi");
3368
3029
  this.rpcClient = rpcClient;
3030
+ this.venusApi = venusApi;
3369
3031
  }
3370
3032
  async requestTimeAsync() {
3371
3033
  const response = await this.rpcClient.call(
@@ -3375,13 +3037,7 @@ var HostTimeApi = class {
3375
3037
  return response;
3376
3038
  }
3377
3039
  formatTime(timestamp, options) {
3378
- let locale = "en-US";
3379
- const windowVenus = window.venus;
3380
- if (windowVenus._config.locale) {
3381
- locale = windowVenus._config.locale;
3382
- } else if (windowVenus._config.environment && windowVenus._config.environment.browserInfo && windowVenus._config.environment.browserInfo.language) {
3383
- locale = windowVenus._config.environment.browserInfo.language;
3384
- }
3040
+ const locale = this.venusApi.getLocale();
3385
3041
  const date = new Date(timestamp);
3386
3042
  const dateTimeOptions = {
3387
3043
  dateStyle: options.dateStyle || "medium",
@@ -3393,13 +3049,7 @@ var HostTimeApi = class {
3393
3049
  }
3394
3050
  formatNumber(value, options) {
3395
3051
  try {
3396
- let locale = "en-US";
3397
- const windowVenus = window.venus;
3398
- if (windowVenus._config.locale) {
3399
- locale = windowVenus._config.locale;
3400
- } else if (windowVenus._config.environment && windowVenus._config.environment.browserInfo && windowVenus._config.environment.browserInfo.language) {
3401
- locale = windowVenus._config.environment.browserInfo.language;
3402
- }
3052
+ const locale = this.venusApi.getLocale();
3403
3053
  const numberOptions = {
3404
3054
  style: options?.style || "decimal",
3405
3055
  minimumFractionDigits: options?.minimumFractionDigits || 0,
@@ -3462,18 +3112,17 @@ var MockTimeApi = class {
3462
3112
  this.venusApi = venusApi;
3463
3113
  }
3464
3114
  formatNumber(value, options) {
3465
- const locale = this.getLocale();
3115
+ const locale = this.venusApi.getLocale();
3466
3116
  const numberOptions = {
3467
3117
  style: options?.style || "decimal",
3468
3118
  minimumFractionDigits: options?.minimumFractionDigits || 0,
3469
3119
  maximumFractionDigits: options?.maximumFractionDigits || 2,
3470
3120
  ...options
3471
3121
  };
3472
- console.log(`[Venus Mock] Formatting number ${value} with locale ${locale}`);
3473
3122
  return value.toLocaleString(locale, numberOptions);
3474
3123
  }
3475
3124
  formatTime(timestamp, options) {
3476
- const locale = this.getLocale();
3125
+ const locale = this.venusApi.getLocale();
3477
3126
  const date = new Date(timestamp);
3478
3127
  const dateTimeOptions = {
3479
3128
  dateStyle: options.dateStyle || "medium",
@@ -3481,13 +3130,9 @@ var MockTimeApi = class {
3481
3130
  hour12: options.hour12 !== void 0 ? options.hour12 : true,
3482
3131
  ...options
3483
3132
  };
3484
- console.log(
3485
- `[Venus Mock] Formatting time ${timestamp} with locale ${locale}`
3486
- );
3487
3133
  return date.toLocaleString(locale, dateTimeOptions);
3488
3134
  }
3489
3135
  async getFutureTimeAsync(options) {
3490
- console.log("[Venus Mock] Getting future time with options:", options);
3491
3136
  const timeInfo = await this.requestTimeAsync();
3492
3137
  const serverTime = new Date(timeInfo.serverTime);
3493
3138
  const result = new Date(serverTime);
@@ -3532,7 +3177,6 @@ var MockTimeApi = class {
3532
3177
  return result.getTime();
3533
3178
  }
3534
3179
  async requestTimeAsync() {
3535
- console.log("[Venus Mock] Requesting time");
3536
3180
  await createMockDelay(MOCK_DELAYS.short);
3537
3181
  const venusApi = this.venusApi;
3538
3182
  const mockOffset = venusApi._mock.serverTimeOffset || 2500;
@@ -3546,23 +3190,8 @@ var MockTimeApi = class {
3546
3190
  formattedTime: new Date(localTime).toISOString(),
3547
3191
  locale: venusApi._mock.user?.locale || "en-US"
3548
3192
  };
3549
- console.log("[Venus Mock] Time response:", {
3550
- serverTime: new Date(timeInfo.serverTime).toISOString(),
3551
- localTime: new Date(timeInfo.localTime).toISOString(),
3552
- timezoneOffset: timeInfo.timezoneOffset
3553
- });
3554
3193
  return timeInfo;
3555
3194
  }
3556
- getLocale() {
3557
- const venusApi = this.venusApi;
3558
- let locale = "en-US";
3559
- if (venusApi._mock.user && venusApi._mock.user.locale) {
3560
- locale = venusApi._mock.user.locale;
3561
- } else if (venusApi._mock.environment && venusApi._mock.environment.browserInfo.language) {
3562
- locale = venusApi._mock.environment.browserInfo.language;
3563
- }
3564
- return locale;
3565
- }
3566
3195
  };
3567
3196
 
3568
3197
  // src/time/index.ts
@@ -3582,7 +3211,7 @@ function initializeTime(venusApi, host) {
3582
3211
  }
3583
3212
 
3584
3213
  // src/version.ts
3585
- var SDK_VERSION = "3.0.3";
3214
+ var SDK_VERSION = "3.0.5";
3586
3215
 
3587
3216
  // src/shared-assets/consts.ts
3588
3217
  var BurgerTimeAssetsCdnPath = "burger-time/Core.stow";
@@ -3653,47 +3282,106 @@ var MockSharedAssetsApi = class {
3653
3282
  }
3654
3283
  };
3655
3284
 
3285
+ // src/leaderboard/utils.ts
3286
+ var HASH_ALGORITHM_WEB_CRYPTO = "SHA-256";
3287
+ var HASH_ALGORITHM_NODE = "sha256";
3288
+ async function computeScoreHash(score, duration, token, sealingNonce, sealingSecret) {
3289
+ const payload = `score:${score}|duration:${duration}|token:${token}`;
3290
+ const fullPayload = `${payload}|nonce:${sealingNonce}`;
3291
+ const encoder = new TextEncoder();
3292
+ const keyData = encoder.encode(sealingSecret);
3293
+ const messageData = encoder.encode(fullPayload);
3294
+ const cryptoKey = await crypto.subtle.importKey(
3295
+ "raw",
3296
+ keyData,
3297
+ { name: "HMAC", hash: HASH_ALGORITHM_WEB_CRYPTO },
3298
+ false,
3299
+ ["sign"]
3300
+ );
3301
+ const signature = await crypto.subtle.sign("HMAC", cryptoKey, messageData);
3302
+ return Array.from(new Uint8Array(signature)).map((b) => b.toString(16).padStart(2, "0")).join("");
3303
+ }
3304
+
3656
3305
  // src/leaderboard/RpcLeaderboardApi.ts
3657
3306
  var RpcLeaderboardApi = class {
3658
3307
  constructor(rpcClient) {
3659
3308
  __publicField(this, "rpcClient");
3309
+ /** Cache of score tokens for automatic hash computation */
3310
+ __publicField(this, "tokenCache", /* @__PURE__ */ new Map());
3660
3311
  this.rpcClient = rpcClient;
3661
3312
  }
3662
- startRun(mode) {
3663
- return this.rpcClient.call(
3664
- "H5_LEADERBOARD_START_RUN" /* H5_LEADERBOARD_START_RUN */,
3313
+ /**
3314
+ * Create a score token for submitting a score.
3315
+ * Token is cached for automatic hash computation if score sealing is enabled.
3316
+ *
3317
+ * @param mode - Optional game mode
3318
+ * @returns Score token with sealing data if enabled
3319
+ */
3320
+ async createScoreToken(mode) {
3321
+ const token = await this.rpcClient.call(
3322
+ "H5_LEADERBOARD_CREATE_SCORE_TOKEN" /* H5_LEADERBOARD_CREATE_SCORE_TOKEN */,
3665
3323
  mode ? { mode } : {}
3666
3324
  );
3325
+ this.tokenCache.set(token.token, token);
3326
+ return token;
3667
3327
  }
3668
- submitScore(sessionId, score, durationSec, options) {
3328
+ /**
3329
+ * Submit a score to the leaderboard.
3330
+ * Automatically computes hash if score sealing is enabled and token was created via createScoreToken().
3331
+ *
3332
+ * @param params - Score submission parameters
3333
+ * @returns Submission result with acceptance status and rank
3334
+ * @throws Error if token not found in cache
3335
+ */
3336
+ async submitScore(params) {
3337
+ let hash;
3338
+ if (params.token) {
3339
+ const cachedToken = this.tokenCache.get(params.token);
3340
+ if (!cachedToken) {
3341
+ throw new Error(
3342
+ "Invalid token: not found in cache. Did you call createScoreToken() first?"
3343
+ );
3344
+ }
3345
+ if (cachedToken.sealingNonce && cachedToken.sealingSecret) {
3346
+ hash = await computeScoreHash(
3347
+ params.score,
3348
+ params.duration,
3349
+ params.token,
3350
+ cachedToken.sealingNonce,
3351
+ cachedToken.sealingSecret
3352
+ );
3353
+ }
3354
+ this.tokenCache.delete(params.token);
3355
+ }
3669
3356
  return this.rpcClient.call(
3670
3357
  "H5_LEADERBOARD_SUBMIT_SCORE" /* H5_LEADERBOARD_SUBMIT_SCORE */,
3671
3358
  {
3672
- sessionId,
3673
- score,
3674
- durationSec,
3675
- mode: options?.mode,
3676
- telemetry: options?.telemetry,
3677
- metadata: options?.metadata,
3678
- hash: options?.hash
3359
+ token: params.token,
3360
+ score: params.score,
3361
+ duration: params.duration,
3362
+ mode: params.mode,
3363
+ telemetry: params.telemetry,
3364
+ metadata: params.metadata,
3365
+ hash
3366
+ // undefined if no sealing, computed if sealing enabled
3679
3367
  }
3680
3368
  );
3681
3369
  }
3682
- getLeaderboard(options) {
3370
+ getPagedScores(options) {
3683
3371
  return this.rpcClient.call(
3684
- "H5_LEADERBOARD_GET" /* H5_LEADERBOARD_GET */,
3372
+ "H5_LEADERBOARD_GET_PAGED_SCORES" /* H5_LEADERBOARD_GET_PAGED_SCORES */,
3685
3373
  options ?? {}
3686
3374
  );
3687
3375
  }
3688
- getPlayerStats(options) {
3376
+ getMyRank(options) {
3689
3377
  return this.rpcClient.call(
3690
- "H5_LEADERBOARD_GET_PLAYER_STATS" /* H5_LEADERBOARD_GET_PLAYER_STATS */,
3378
+ "H5_LEADERBOARD_GET_MY_RANK" /* H5_LEADERBOARD_GET_MY_RANK */,
3691
3379
  options ?? {}
3692
3380
  );
3693
3381
  }
3694
- getLeaderboardHighlight(options) {
3382
+ getPodiumScores(options) {
3695
3383
  return this.rpcClient.call(
3696
- "H5_LEADERBOARD_GET_HIGHLIGHT" /* H5_LEADERBOARD_GET_HIGHLIGHT */,
3384
+ "H5_LEADERBOARD_GET_PODIUM_SCORES" /* H5_LEADERBOARD_GET_PODIUM_SCORES */,
3697
3385
  options ?? {}
3698
3386
  );
3699
3387
  }
@@ -3702,17 +3390,31 @@ var RpcLeaderboardApi = class {
3702
3390
  // src/leaderboard/MockLeaderboardApi.ts
3703
3391
  var MockLeaderboardApi = class {
3704
3392
  constructor(options) {
3705
- __publicField(this, "sessions", /* @__PURE__ */ new Map());
3393
+ __publicField(this, "tokens", /* @__PURE__ */ new Map());
3394
+ /** Cache of score tokens for automatic hash computation */
3395
+ __publicField(this, "tokenCache", /* @__PURE__ */ new Map());
3706
3396
  __publicField(this, "entriesByMode", /* @__PURE__ */ new Map());
3707
- __publicField(this, "sessionCounter", 0);
3708
- __publicField(this, "requiresHash", false);
3709
- if (options?.requiresHash) {
3710
- this.requiresHash = true;
3397
+ __publicField(this, "tokenCounter", 0);
3398
+ __publicField(this, "enableScoreSealing", false);
3399
+ __publicField(this, "scoreSealingSecret", "mock-leaderboard-secret-key");
3400
+ if (options?.enableScoreSealing) {
3401
+ this.enableScoreSealing = true;
3402
+ }
3403
+ if (options?.scoreSealingSecret) {
3404
+ this.scoreSealingSecret = options.scoreSealingSecret;
3711
3405
  }
3712
3406
  }
3407
+ /**
3408
+ * Configure mock leaderboard settings
3409
+ *
3410
+ * @param options - Configuration options
3411
+ */
3713
3412
  configure(options) {
3714
- if (typeof options.requiresHash === "boolean") {
3715
- this.requiresHash = options.requiresHash;
3413
+ if (typeof options.enableScoreSealing === "boolean") {
3414
+ this.enableScoreSealing = options.enableScoreSealing;
3415
+ }
3416
+ if (options.scoreSealingSecret) {
3417
+ this.scoreSealingSecret = options.scoreSealingSecret;
3716
3418
  }
3717
3419
  }
3718
3420
  generateNonce() {
@@ -3729,83 +3431,149 @@ var MockLeaderboardApi = class {
3729
3431
  }
3730
3432
  return this.entriesByMode.get(key);
3731
3433
  }
3732
- async startRun(mode) {
3733
- const sessionId = `mock_session_${++this.sessionCounter}`;
3434
+ /**
3435
+ * Create a mock score token for testing.
3436
+ * Token is cached for automatic hash computation if score sealing is enabled.
3437
+ *
3438
+ * @param mode - Optional game mode
3439
+ * @returns Score token with sealing data if enabled
3440
+ */
3441
+ async createScoreToken(mode) {
3442
+ const token = `mock_token_${++this.tokenCounter}`;
3734
3443
  const startTime = Date.now();
3735
3444
  const expiresAt = startTime + 36e5;
3736
3445
  const resolvedMode = mode || "default";
3737
- const hashNonce = this.requiresHash ? this.generateNonce() : null;
3738
- this.sessions.set(sessionId, {
3739
- id: sessionId,
3446
+ const sealingNonce = this.enableScoreSealing ? this.generateNonce() : null;
3447
+ const sealingSecret = this.enableScoreSealing ? this.scoreSealingSecret : null;
3448
+ this.tokens.set(token, {
3449
+ id: token,
3740
3450
  expiresAt,
3741
3451
  mode: resolvedMode,
3742
- hashNonce,
3452
+ sealingNonce,
3743
3453
  used: false
3744
3454
  });
3745
- return {
3746
- sessionId,
3455
+ const result = {
3456
+ token,
3747
3457
  startTime,
3748
3458
  expiresAt,
3749
- hashNonce,
3459
+ sealingNonce,
3460
+ sealingSecret,
3750
3461
  mode: resolvedMode
3751
3462
  };
3463
+ this.tokenCache.set(token, result);
3464
+ return result;
3752
3465
  }
3753
- async submitScore(sessionId, score, durationSec, options) {
3754
- const session = this.sessions.get(sessionId);
3755
- if (!session) {
3756
- throw new Error("Invalid leaderboard session");
3466
+ /**
3467
+ * Submit a mock score to the leaderboard.
3468
+ * Automatically computes hash if score sealing is enabled and token was created via createScoreToken().
3469
+ *
3470
+ * @param params - Score submission parameters
3471
+ * @returns Submission result with acceptance status and rank
3472
+ * @throws Error if token not found in cache or validation fails
3473
+ */
3474
+ async submitScore(params) {
3475
+ let hash;
3476
+ if (params.token) {
3477
+ const cachedToken = this.tokenCache.get(params.token);
3478
+ if (!cachedToken) {
3479
+ throw new Error(
3480
+ "Invalid token: not found in cache. Did you call createScoreToken() first?"
3481
+ );
3482
+ }
3483
+ if (cachedToken.sealingNonce && cachedToken.sealingSecret) {
3484
+ hash = await computeScoreHash(
3485
+ params.score,
3486
+ params.duration,
3487
+ params.token,
3488
+ cachedToken.sealingNonce,
3489
+ cachedToken.sealingSecret
3490
+ );
3491
+ }
3757
3492
  }
3758
- if (session.expiresAt < Date.now()) {
3759
- throw new Error("Invalid or expired leaderboard session");
3493
+ if (!params.token) {
3494
+ const mode = params.mode || "default";
3495
+ const submittedAt2 = Date.now();
3496
+ const entry2 = {
3497
+ profileId: `mock_profile`,
3498
+ username: "Mock Player",
3499
+ avatarUrl: null,
3500
+ score: params.score,
3501
+ duration: params.duration,
3502
+ submittedAt: submittedAt2,
3503
+ token: "simple-mode",
3504
+ rank: null,
3505
+ zScore: null,
3506
+ isAnomaly: false,
3507
+ trustScore: 50,
3508
+ metadata: params.metadata ?? null,
3509
+ isSeed: false
3510
+ };
3511
+ const modeEntries2 = this.getEntriesForMode(mode);
3512
+ modeEntries2.push(entry2);
3513
+ modeEntries2.sort((a, b) => {
3514
+ if (b.score !== a.score) return b.score - a.score;
3515
+ return a.submittedAt - b.submittedAt;
3516
+ });
3517
+ modeEntries2.forEach((e, index) => {
3518
+ modeEntries2[index] = { ...e, rank: index + 1 };
3519
+ });
3520
+ const inserted2 = modeEntries2.find((e) => e.submittedAt === submittedAt2);
3521
+ return {
3522
+ accepted: true,
3523
+ rank: inserted2?.rank ?? null
3524
+ };
3525
+ }
3526
+ const scoreToken = this.tokens.get(params.token);
3527
+ if (!scoreToken) {
3528
+ throw new Error("Invalid score token");
3760
3529
  }
3761
- if (session.used) {
3762
- throw new Error("Leaderboard session already used");
3530
+ if (scoreToken.expiresAt < Date.now()) {
3531
+ throw new Error("Invalid or expired score token");
3763
3532
  }
3764
- if (options?.mode && options.mode !== session.mode) {
3765
- throw new Error("Submission mode does not match session mode");
3533
+ if (scoreToken.used) {
3534
+ throw new Error("Score token already used");
3766
3535
  }
3767
- if (session.hashNonce && !options?.hash) {
3768
- throw new Error("Score hash is required for sealed leaderboard submissions");
3536
+ if (params.mode && params.mode !== scoreToken.mode) {
3537
+ throw new Error("Submission mode does not match token mode");
3538
+ }
3539
+ if (scoreToken.sealingNonce && !hash) {
3540
+ throw new Error("Score hash required when score sealing is enabled");
3769
3541
  }
3770
3542
  const submittedAt = Date.now();
3771
3543
  const entry = {
3772
3544
  profileId: `mock_profile`,
3773
3545
  username: "Mock Player",
3774
3546
  avatarUrl: null,
3775
- score,
3776
- durationSec,
3547
+ score: params.score,
3548
+ duration: params.duration,
3777
3549
  submittedAt,
3778
- sessionId,
3550
+ token: params.token,
3779
3551
  rank: null,
3780
3552
  zScore: null,
3781
3553
  isAnomaly: false,
3782
3554
  trustScore: 50,
3783
- metadata: options?.metadata ?? null,
3555
+ metadata: params.metadata ?? null,
3784
3556
  isSeed: false
3785
3557
  };
3786
- const modeEntries = this.getEntriesForMode(session.mode);
3558
+ const modeEntries = this.getEntriesForMode(scoreToken.mode);
3787
3559
  modeEntries.push(entry);
3788
3560
  modeEntries.sort((a, b) => {
3789
- if (b.score !== a.score) {
3790
- return b.score - a.score;
3791
- }
3561
+ if (b.score !== a.score) return b.score - a.score;
3792
3562
  return a.submittedAt - b.submittedAt;
3793
3563
  });
3794
3564
  modeEntries.forEach((e, index) => {
3795
- modeEntries[index] = {
3796
- ...e,
3797
- rank: index + 1
3798
- };
3565
+ modeEntries[index] = { ...e, rank: index + 1 };
3799
3566
  });
3800
- session.used = true;
3801
- session.hashNonce = null;
3802
- const inserted = modeEntries.find((e) => e.sessionId === sessionId && e.submittedAt === submittedAt);
3567
+ scoreToken.used = true;
3568
+ scoreToken.sealingNonce = null;
3569
+ this.tokenCache.delete(params.token);
3570
+ const inserted = modeEntries.find((e) => e.token === params.token && e.submittedAt === submittedAt);
3803
3571
  return {
3804
3572
  accepted: true,
3805
3573
  rank: inserted?.rank ?? null
3806
3574
  };
3807
3575
  }
3808
- async getLeaderboard(options) {
3576
+ async getPagedScores(options) {
3809
3577
  const limit = options?.limit ?? 10;
3810
3578
  const mode = options?.mode ?? "default";
3811
3579
  const modeEntries = [...this.getEntriesForMode(mode)];
@@ -3821,7 +3589,7 @@ var MockLeaderboardApi = class {
3821
3589
  periodInstance: options?.period ?? "alltime"
3822
3590
  };
3823
3591
  }
3824
- async getPlayerStats(_options) {
3592
+ async getMyRank(_options) {
3825
3593
  const mode = _options?.mode ?? "default";
3826
3594
  const modeEntries = this.getEntriesForMode(mode);
3827
3595
  const playerEntry = modeEntries[0] ?? null;
@@ -3834,7 +3602,7 @@ var MockLeaderboardApi = class {
3834
3602
  periodInstance: _options?.period ?? "alltime"
3835
3603
  };
3836
3604
  }
3837
- async getLeaderboardHighlight(options) {
3605
+ async getPodiumScores(options) {
3838
3606
  const mode = options?.mode ?? "default";
3839
3607
  const modeEntries = [...this.getEntriesForMode(mode)];
3840
3608
  const topCount = Math.max(1, Math.min(options?.topCount ?? 3, 10));
@@ -3946,7 +3714,6 @@ var MockPostApi = class {
3946
3714
  }
3947
3715
  async toggleFollowAsync() {
3948
3716
  const venusApi = this.venusApi;
3949
- console.log("[Venus Mock] *Toggling follow status");
3950
3717
  await createMockDelay(MOCK_DELAYS.short);
3951
3718
  venusApi._mock.currentPostInteractions.isFollowing = !venusApi._mock.currentPostInteractions.isFollowing;
3952
3719
  const isFollowing = venusApi._mock.currentPostInteractions.isFollowing;
@@ -3999,9 +3766,6 @@ var RpcPostApi = class {
3999
3766
  }
4000
3767
  };
4001
3768
 
4002
- // src/MockHost.ts
4003
- init_rooms();
4004
-
4005
3769
  // src/social/MockSocialApi.ts
4006
3770
  var MOCK_QR_CODE = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==";
4007
3771
  var MockSocialApi = class {
@@ -4038,44 +3802,116 @@ var ROOMS_UNAVAILABLE_MESSAGE = "[Venus SDK] Rooms API is only available when ru
4038
3802
  function createUnavailableRoomsApi() {
4039
3803
  const roomsUnavailableError = () => new Error(ROOMS_UNAVAILABLE_MESSAGE);
4040
3804
  return {
4041
- async createRoom() {
3805
+ async createRoomAsync() {
4042
3806
  throw roomsUnavailableError();
4043
3807
  },
4044
- async joinOrCreateRoom() {
3808
+ async joinOrCreateRoomAsync() {
4045
3809
  throw roomsUnavailableError();
4046
3810
  },
4047
- async getUserRooms() {
3811
+ async joinRoomByCodeAsync() {
4048
3812
  throw roomsUnavailableError();
4049
3813
  },
4050
- async joinRoomByCode() {
3814
+ async getUserRoomsAsync() {
4051
3815
  throw roomsUnavailableError();
4052
3816
  },
4053
- subscribe() {
3817
+ async subscribeAsync() {
4054
3818
  throw roomsUnavailableError();
4055
3819
  },
4056
- async updateData() {
3820
+ async updateRoomDataAsync() {
4057
3821
  throw roomsUnavailableError();
4058
3822
  },
4059
- async getData() {
3823
+ async getRoomDataAsync() {
4060
3824
  throw roomsUnavailableError();
4061
3825
  },
4062
- async sendMessage() {
3826
+ async sendRoomMessageAsync() {
4063
3827
  throw roomsUnavailableError();
4064
3828
  },
4065
- async leave() {
3829
+ async leaveRoomAsync() {
4066
3830
  throw roomsUnavailableError();
4067
3831
  },
4068
- async startGame() {
3832
+ async startRoomGameAsync() {
4069
3833
  throw roomsUnavailableError();
4070
3834
  },
4071
- async proposeMove() {
3835
+ async proposeMoveAsync() {
4072
3836
  throw roomsUnavailableError();
4073
3837
  },
4074
- async validateMove() {
3838
+ async validateMoveAsync() {
4075
3839
  throw roomsUnavailableError();
4076
3840
  }
4077
3841
  };
4078
3842
  }
3843
+ var SIMULATION_UNAVAILABLE_MESSAGE = "[Venus SDK] Simulation API is only available when running inside the Venus host environment.";
3844
+ function createUnavailableSimulationApi() {
3845
+ const simulationUnavailableError = () => new Error(SIMULATION_UNAVAILABLE_MESSAGE);
3846
+ return {
3847
+ isEnabled() {
3848
+ return false;
3849
+ },
3850
+ async getStateAsync() {
3851
+ throw simulationUnavailableError();
3852
+ },
3853
+ async getConfigAsync() {
3854
+ throw simulationUnavailableError();
3855
+ },
3856
+ async executeRecipeAsync() {
3857
+ throw simulationUnavailableError();
3858
+ },
3859
+ async getActiveRunsAsync() {
3860
+ throw simulationUnavailableError();
3861
+ },
3862
+ async collectRecipeAsync() {
3863
+ throw simulationUnavailableError();
3864
+ },
3865
+ async executeScopedRecipeAsync() {
3866
+ throw simulationUnavailableError();
3867
+ },
3868
+ async triggerRecipeChainAsync() {
3869
+ throw simulationUnavailableError();
3870
+ },
3871
+ async getAvailableRecipesAsync() {
3872
+ throw simulationUnavailableError();
3873
+ },
3874
+ async getRecipeRequirementsAsync() {
3875
+ throw simulationUnavailableError();
3876
+ },
3877
+ async getBatchRecipeRequirementsAsync() {
3878
+ throw simulationUnavailableError();
3879
+ },
3880
+ async resolveFieldValueAsync() {
3881
+ throw simulationUnavailableError();
3882
+ },
3883
+ async getEntityMetadataAsync() {
3884
+ throw simulationUnavailableError();
3885
+ },
3886
+ async getSlotContainersAsync() {
3887
+ throw simulationUnavailableError();
3888
+ },
3889
+ async getSlotAssignmentsAsync() {
3890
+ throw simulationUnavailableError();
3891
+ },
3892
+ async assignItemToSlotAsync() {
3893
+ throw simulationUnavailableError();
3894
+ },
3895
+ async removeItemFromSlotAsync() {
3896
+ throw simulationUnavailableError();
3897
+ },
3898
+ async getAvailableItemsAsync() {
3899
+ throw simulationUnavailableError();
3900
+ },
3901
+ async calculatePowerPreviewAsync() {
3902
+ throw simulationUnavailableError();
3903
+ },
3904
+ async validateSlotAssignmentAsync() {
3905
+ throw simulationUnavailableError();
3906
+ },
3907
+ async executeBatchOperationsAsync() {
3908
+ throw simulationUnavailableError();
3909
+ },
3910
+ async subscribeAsync() {
3911
+ throw simulationUnavailableError();
3912
+ }
3913
+ };
3914
+ }
4079
3915
  var MockHost = class {
4080
3916
  constructor(venusApi) {
4081
3917
  __publicField(this, "ads");
@@ -4130,7 +3966,7 @@ var MockHost = class {
4130
3966
  this.haptics = new MockHapticsApi(venusApi);
4131
3967
  this.features = new MockFeaturesApi();
4132
3968
  this.lifecycle = this._mockLifecyclesApi;
4133
- this.simulation = new MockSimulationApi();
3969
+ this.simulation = createUnavailableSimulationApi();
4134
3970
  this.rooms = createUnavailableRoomsApi();
4135
3971
  this.logging = new MockLoggingApi();
4136
3972
  this.iap = new MockIapApi();
@@ -4663,6 +4499,16 @@ var VenusTransport = class {
4663
4499
  this.isProcessingMessage = false;
4664
4500
  return;
4665
4501
  }
4502
+ if (message.type === "H5_SIMULATION_UPDATE" /* H5_SIMULATION_UPDATE */) {
4503
+ const notification = {
4504
+ type: "rpc-notification",
4505
+ id: message.type,
4506
+ payload: message.data
4507
+ };
4508
+ this.handleNotification(notification);
4509
+ this.isProcessingMessage = false;
4510
+ return;
4511
+ }
4666
4512
  const requestId = messageData.requestId;
4667
4513
  if (!requestId) {
4668
4514
  this.logWarn("No requestId. Ignoring message...");
@@ -4829,294 +4675,6 @@ var VenusTransport = class {
4829
4675
  }
4830
4676
  };
4831
4677
 
4832
- // src/RemoteHost.ts
4833
- init_rooms();
4834
-
4835
- // src/rooms/RpcRoomsApi.ts
4836
- init_VenusRoom();
4837
- var RpcRoomsApi = class {
4838
- constructor(rpcClient) {
4839
- __publicField(this, "rpcClient");
4840
- __publicField(this, "subscriptions");
4841
- __publicField(this, "transportSubscription", null);
4842
- this.rpcClient = rpcClient;
4843
- this.subscriptions = {
4844
- data: {},
4845
- messages: {},
4846
- gameEvents: {},
4847
- allEvents: {}
4848
- };
4849
- }
4850
- /**
4851
- * Get the subscription state for external access (used by setupRoomNotifications)
4852
- */
4853
- getSubscriptions() {
4854
- return this.subscriptions;
4855
- }
4856
- /**
4857
- * Set up room notification routing from the transport
4858
- */
4859
- setupNotifications(transport) {
4860
- const { setupRoomNotifications: setupRoomNotifications2 } = (init_rooms(), __toCommonJS(rooms_exports));
4861
- this.transportSubscription = setupRoomNotifications2(
4862
- transport,
4863
- () => this.getSubscriptions()
4864
- );
4865
- }
4866
- /**
4867
- * Clean up subscriptions and resources
4868
- */
4869
- dispose() {
4870
- if (this.transportSubscription) {
4871
- this.transportSubscription.unsubscribe();
4872
- this.transportSubscription = null;
4873
- console.log("[Venus Rooms] Cleaned up room notification subscription");
4874
- }
4875
- }
4876
- async createRoom(options) {
4877
- const response = await this.rpcClient.call(
4878
- "H5_ROOM_CREATE" /* H5_ROOM_CREATE */,
4879
- {
4880
- options
4881
- }
4882
- );
4883
- if (response.success === false) {
4884
- throw new Error(response.error || "Failed to create room");
4885
- }
4886
- const roomData = response.roomData || response;
4887
- const room = new exports.VenusRoom(roomData);
4888
- return room;
4889
- }
4890
- async joinOrCreateRoom(options) {
4891
- const response = await this.rpcClient.call(
4892
- "H5_ROOM_JOIN_OR_CREATE" /* H5_ROOM_JOIN_OR_CREATE */,
4893
- {
4894
- options
4895
- }
4896
- );
4897
- if (response.success === false) {
4898
- throw new Error(response.error || "Failed to join or create room");
4899
- }
4900
- const data = response.value || response;
4901
- const room = new exports.VenusRoom(data.roomData);
4902
- return {
4903
- action: data.action,
4904
- room,
4905
- playersJoined: data.playersJoined
4906
- };
4907
- }
4908
- async joinRoomByCode(roomCode) {
4909
- const response = await this.rpcClient.call(
4910
- "H5_ROOM_JOIN_BY_CODE" /* H5_ROOM_JOIN_BY_CODE */,
4911
- {
4912
- roomCode
4913
- }
4914
- );
4915
- if (response?.success === false) {
4916
- throw new Error(response.error || "Failed to join room by code");
4917
- }
4918
- const roomData = response.roomData || response;
4919
- const room = new exports.VenusRoom(roomData);
4920
- return room;
4921
- }
4922
- // Get user's rooms with optional filtering
4923
- async getUserRooms(includeArchived = false) {
4924
- const response = await this.rpcClient.call(
4925
- "H5_ROOM_GET_USER_ROOMS" /* H5_ROOM_GET_USER_ROOMS */,
4926
- {
4927
- includeArchived
4928
- }
4929
- );
4930
- if (response?.success === false) {
4931
- throw new Error(response.error || "Failed to get user rooms");
4932
- }
4933
- const rawRooms = response.rooms || [];
4934
- const venusRooms = [];
4935
- for (const roomData of rawRooms) {
4936
- if (!roomData.id) {
4937
- console.warn("getUserRooms: Skipping room with missing ID:", roomData);
4938
- continue;
4939
- }
4940
- try {
4941
- const venusRoom = new exports.VenusRoom(roomData);
4942
- venusRooms.push(venusRoom);
4943
- } catch (error) {
4944
- console.warn(
4945
- "getUserRooms: Failed to create VenusRoom object:",
4946
- error,
4947
- roomData
4948
- );
4949
- }
4950
- }
4951
- return venusRooms;
4952
- }
4953
- async updateData(room, updates, merge = true) {
4954
- const response = await this.rpcClient.call(
4955
- "H5_ROOM_UPDATE_DATA" /* H5_ROOM_UPDATE_DATA */,
4956
- {
4957
- roomId: room.id,
4958
- updates,
4959
- merge
4960
- }
4961
- );
4962
- if (response?.success === false) {
4963
- throw new Error(response.error || "Failed to update room data");
4964
- }
4965
- return response.data;
4966
- }
4967
- async getData(room) {
4968
- const response = await this.rpcClient.call(
4969
- "H5_ROOM_GET_DATA" /* H5_ROOM_GET_DATA */,
4970
- {
4971
- roomId: room.id
4972
- }
4973
- );
4974
- if (response?.success === false) {
4975
- throw new Error(response.error || "Failed to get room data");
4976
- }
4977
- return response.data;
4978
- }
4979
- async sendMessage(venusRoom, messageData) {
4980
- const response = await this.rpcClient.call(
4981
- "H5_ROOM_SEND_MESSAGE" /* H5_ROOM_SEND_MESSAGE */,
4982
- {
4983
- roomId: venusRoom.id,
4984
- message: messageData
4985
- }
4986
- );
4987
- if (response?.success === false) {
4988
- throw new Error(response.error || "Failed to send message");
4989
- }
4990
- return response.messageId;
4991
- }
4992
- async leave(room) {
4993
- const response = await this.rpcClient.call(
4994
- "H5_ROOM_LEAVE" /* H5_ROOM_LEAVE */,
4995
- {
4996
- roomId: room.id
4997
- }
4998
- );
4999
- if (response?.success === false) {
5000
- throw new Error(response.error || "Failed to leave room");
5001
- }
5002
- return response;
5003
- }
5004
- async startGame(room, gameConfig = {}, turnOrder = null) {
5005
- const response = await this.rpcClient.call(
5006
- "H5_ROOM_START_GAME" /* H5_ROOM_START_GAME */,
5007
- {
5008
- roomId: room.id,
5009
- gameConfig,
5010
- turnOrder
5011
- }
5012
- );
5013
- if (response?.success === false) {
5014
- throw new Error(response.error || "Failed to start game");
5015
- }
5016
- return response.data;
5017
- }
5018
- async proposeMove(room, proposalPayload) {
5019
- const response = await this.rpcClient.call(
5020
- "h5:room:proposeMove" /* H5_ROOM_PROPOSE_MOVE */,
5021
- {
5022
- roomId: room.id,
5023
- gameSpecificState: proposalPayload.gameSpecificState,
5024
- moveType: proposalPayload.moveType,
5025
- clientContext: proposalPayload.clientContext,
5026
- clientProposalId: proposalPayload.clientProposalId
5027
- }
5028
- );
5029
- if (response?.success === false) {
5030
- throw new Error(response.error || "Failed to propose move");
5031
- }
5032
- return response.data;
5033
- }
5034
- async validateMove(room, moveId, isValid, reason = null, validatorId = null) {
5035
- console.log(`[Venus Rooms] Validating move ${moveId}: ${isValid}`);
5036
- return { success: true, moveId, isValid, reason };
5037
- }
5038
- async roomSubscribeToGameEvents(room, callback) {
5039
- "game_" + Date.now() + "_" + Math.random().toString(36).substr(2, 9);
5040
- if (!this.subscriptions.gameEvents[room.id]) {
5041
- this.subscriptions.gameEvents[room.id] = [];
5042
- }
5043
- this.subscriptions.gameEvents[room.id].push(callback);
5044
- }
5045
- subscribe(room, options = {}) {
5046
- const subscriptionIds = [];
5047
- const roomId = room.id;
5048
- if (options.onData) {
5049
- const dataSubId = "data_" + Date.now() + "_" + Math.random().toString(36).substr(2, 9);
5050
- if (!this.subscriptions.data[roomId]) {
5051
- this.subscriptions.data[roomId] = [];
5052
- }
5053
- this.subscriptions.data[roomId].push(options.onData);
5054
- subscriptionIds.push({
5055
- type: "data",
5056
- id: dataSubId,
5057
- callback: options.onData
5058
- });
5059
- }
5060
- if (options.onMessages) {
5061
- const msgSubId = "messages_" + Date.now() + "_" + Math.random().toString(36).substr(2, 9);
5062
- if (!this.subscriptions.messages[roomId]) {
5063
- this.subscriptions.messages[roomId] = [];
5064
- }
5065
- this.subscriptions.messages[roomId].push(options.onMessages);
5066
- subscriptionIds.push({
5067
- type: "messages",
5068
- id: msgSubId,
5069
- callback: options.onMessages
5070
- });
5071
- }
5072
- if (options.onMoves || options.onGameEvents) {
5073
- const handler = options.onMoves || options.onGameEvents;
5074
- if (handler) {
5075
- const gameSubId = "game_" + Date.now() + "_" + Math.random().toString(36).substr(2, 9);
5076
- if (!this.subscriptions.gameEvents[roomId]) {
5077
- this.subscriptions.gameEvents[roomId] = [];
5078
- }
5079
- this.subscriptions.gameEvents[roomId].push(handler);
5080
- subscriptionIds.push({
5081
- type: "gameEvents",
5082
- id: gameSubId,
5083
- callback: handler
5084
- });
5085
- }
5086
- }
5087
- const needsSubscription = subscriptionIds.length > 0 && (this.subscriptions.data[roomId]?.length ?? 0) <= 1 && (this.subscriptions.messages[roomId]?.length ?? 0) <= 1 && (this.subscriptions.gameEvents[roomId]?.length ?? 0) <= 1;
5088
- if (needsSubscription) {
5089
- this.rpcClient.call("H5_ROOM_SUBSCRIBE" /* H5_ROOM_SUBSCRIBE */, {
5090
- roomId,
5091
- subscribeToData: !!options.onData,
5092
- subscribeToMessages: !!options.onMessages,
5093
- subscribeToProposedMoves: !!(options.onMoves || options.onGameEvents)
5094
- }).catch((error) => {
5095
- console.error("Failed to set up room subscription:", error);
5096
- });
5097
- }
5098
- let called = false;
5099
- return () => {
5100
- if (called) return;
5101
- called = true;
5102
- subscriptionIds.forEach((sub) => {
5103
- const bucket = this.subscriptions[sub.type];
5104
- const callbacks = bucket && bucket[roomId] || [];
5105
- const index = callbacks.indexOf(sub.callback);
5106
- if (index > -1) callbacks.splice(index, 1);
5107
- });
5108
- const hasNoCallbacks = (this.subscriptions.data[roomId]?.length ?? 0) === 0 && (this.subscriptions.messages[roomId]?.length ?? 0) === 0 && (this.subscriptions.gameEvents[roomId]?.length ?? 0) === 0;
5109
- if (hasNoCallbacks) {
5110
- this.rpcClient.call("H5_ROOM_UNSUBSCRIBE" /* H5_ROOM_UNSUBSCRIBE */, {
5111
- roomId
5112
- }).catch((error) => {
5113
- console.error("Failed to clean up room subscription:", error);
5114
- });
5115
- }
5116
- };
5117
- }
5118
- };
5119
-
5120
4678
  // src/social/RpcSocialApi.ts
5121
4679
  var RpcSocialApi = class {
5122
4680
  constructor(rpcClient) {
@@ -5221,7 +4779,7 @@ var RemoteHost = class {
5221
4779
  this.popups = new RpcPopupsApi(rpcClient);
5222
4780
  this.profile = new HostProfileApi();
5223
4781
  this.cdn = new HostCdnApi(getCdnBaseUrl());
5224
- this.time = new HostTimeApi(rpcClient);
4782
+ this.time = new HostTimeApi(rpcClient, venusApi);
5225
4783
  this.post = new RpcPostApi(rpcClient);
5226
4784
  this.ai = new RpcAiApi(rpcClient);
5227
4785
  this.haptics = new RpcHapticsApi(rpcClient);
@@ -5237,7 +4795,6 @@ var RemoteHost = class {
5237
4795
  venusApi.isMock = () => false;
5238
4796
  this.venusApi.sharedAssets = new RpcSharedAssetsApi(rpcClient, venusApi);
5239
4797
  initializeRoomsApi(this.venusApi, this);
5240
- console.log("[Venus SDK] Remote host created");
5241
4798
  }
5242
4799
  get isInitialized() {
5243
4800
  return this._isInitialized;
@@ -5296,10 +4853,8 @@ var RemoteHost = class {
5296
4853
  // src/Host.ts
5297
4854
  function createHost(venusApi, isMock) {
5298
4855
  if (isMock) {
5299
- console.log("[Venus SDK] Creating Local Host");
5300
4856
  return new MockHost(venusApi);
5301
4857
  } else {
5302
- console.log("[Venus SDK] Creating Remote Host");
5303
4858
  return new RemoteHost(venusApi);
5304
4859
  }
5305
4860
  }
@@ -5312,6 +4867,8 @@ function initializeSocial(venusApi, host) {
5312
4867
  };
5313
4868
  }
5314
4869
 
4870
+ exports.HASH_ALGORITHM_NODE = HASH_ALGORITHM_NODE;
4871
+ exports.HASH_ALGORITHM_WEB_CRYPTO = HASH_ALGORITHM_WEB_CRYPTO;
5315
4872
  exports.HapticFeedbackStyle = HapticFeedbackStyle;
5316
4873
  exports.HostCdnApi = HostCdnApi;
5317
4874
  exports.HostProfileApi = HostProfileApi;
@@ -5333,7 +4890,6 @@ exports.MockPopupsApi = MockPopupsApi;
5333
4890
  exports.MockPreloaderApi = MockPreloaderApi;
5334
4891
  exports.MockProfileApi = MockProfileApi;
5335
4892
  exports.MockSharedAssetsApi = MockSharedAssetsApi;
5336
- exports.MockSimulationApi = MockSimulationApi;
5337
4893
  exports.MockSocialApi = MockSocialApi;
5338
4894
  exports.MockStorageApi = MockStorageApi;
5339
4895
  exports.MockTimeApi = MockTimeApi;
@@ -5353,12 +4909,15 @@ exports.RpcNavigationApi = RpcNavigationApi;
5353
4909
  exports.RpcNotificationsApi = RpcNotificationsApi;
5354
4910
  exports.RpcPopupsApi = RpcPopupsApi;
5355
4911
  exports.RpcPreloaderApi = RpcPreloaderApi;
4912
+ exports.RpcRoomsApi = RpcRoomsApi;
5356
4913
  exports.RpcSharedAssetsApi = RpcSharedAssetsApi;
5357
4914
  exports.RpcSimulationApi = RpcSimulationApi;
5358
4915
  exports.RpcSocialApi = RpcSocialApi;
5359
4916
  exports.RpcStorageApi = RpcStorageApi;
5360
4917
  exports.SDK_VERSION = SDK_VERSION;
5361
4918
  exports.VenusMessageId = VenusMessageId;
4919
+ exports.VenusRoom = VenusRoom;
4920
+ exports.computeScoreHash = computeScoreHash;
5362
4921
  exports.createHost = createHost;
5363
4922
  exports.createMockStorageApi = createMockStorageApi;
5364
4923
  exports.initializeAds = initializeAds;