incanto 0.79.1 → 0.79.3

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/editor/index.html CHANGED
@@ -5,8 +5,9 @@
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
6
  <title>Incanto Scene Editor</title>
7
7
  <link rel="icon" href="data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'><rect width='16' height='16' rx='3' fill='%236ee7dc'/><text x='8' y='12' text-anchor='middle' font-size='11' font-family='monospace' fill='%230e1018'>i</text></svg>" />
8
- <script type="module" crossorigin src="./assets/index-QEwr2eXD.js"></script>
9
- <link rel="modulepreload" crossorigin href="./assets/GameServer-C56iOUgF.js">
8
+ <script type="module" crossorigin src="./assets/index-CMOFrNki.js"></script>
9
+ <link rel="modulepreload" crossorigin href="./assets/GameServer-BlrNxR5M.js">
10
+ <link rel="modulepreload" crossorigin href="./assets/errors-BlwBM544.js">
10
11
  </head>
11
12
  <body>
12
13
  <!-- The shell is built by src/shell.ts (generated from this file by
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "incanto",
3
- "version": "0.79.1",
3
+ "version": "0.79.3",
4
4
  "description": "Vibe-coding-first web game engine SDK — JSON-driven scenes on three.js",
5
5
  "keywords": [
6
6
  "game-engine",
@@ -52,7 +52,7 @@ Authority rules:
52
52
  ## Scene JSON
53
53
 
54
54
  ```json
55
- "multiplayer": { "room": "auto" },
55
+ "multiplayer": { "room": "arena" },
56
56
  "root": { ..., "children": [
57
57
  { "name": "Player", "type": "CharacterBody2D",
58
58
  "network": { "mode": "owner", "sync": ["position", "Skin.animation"], "throttleMs": 50 },
@@ -205,6 +205,13 @@ Implement `NetworkTransport` (exported from `incanto/net`): `connect`/`disconnec
205
205
  `subscribeRoomCollection`, `onRoomMessage`, `onRoomUserJoin/Leave`). `LoopbackTransport`'s source is the reference
206
206
  implementation — anything that behaves like it works with the whole engine.
207
207
 
208
+ **If your backend does not route rooms through the game's server**, implement the two
209
+ OPTIONAL members instead of answering those two names — `joinRoom(roomId?)` resolving to
210
+ the room actually joined, and `leaveRoom(roomId)`. The engine prefers them when present
211
+ and never sends `remoteFunction('joinRoom')` to that transport. This is what the agent8
212
+ adapter does on SDK 2.x. Implementations that cannot assign a room for `joinRoom()` with
213
+ no argument should REJECT — inventing an id gives you a room nobody else will ever join.
214
+
208
215
  ## Preview: run your REAL server locally (no cloud, no auth)
209
216
 
210
217
  `LoopbackHub` answers only the FIXED built-in protocol — it cannot run your
@@ -257,7 +264,9 @@ Rapier when the scene has bodies; `physics: false` opts out) — without it a
257
264
  `CharacterBody2D` never moves. The first panel's clock pumps `server.tick` (so
258
265
  `$roomTick` runs) — don't add your own. Every panel joins ONE room: a shared scene usually says
259
266
  `multiplayer: { room: "auto" }`, and "auto" means a server-ASSIGNED room, so the
260
- harness pins panels 1..N to the room panel 0 got (`room: 'lobby'` overrides).
267
+ harness pins panels 1..N to the room panel 0 got (`room: 'lobby'` overrides). ("auto"
268
+ is a PREVIEW convenience — the loopback hub and `LocalGameServer` assign one. Live on
269
+ agent8 SDK 2.x nothing can, and incanto refuses it at boot; see "Going live" below.)
261
270
  `dispose()` tears every panel down. Going live is unchanged: ONE
262
271
  client per browser with `createAgent8Server()` as the transport.
263
272
 
@@ -456,7 +465,7 @@ the composition:
456
465
  game.engine.start(); // the first frame is a networked one
457
466
  ```
458
467
 
459
- ## Going live on agent8 (gameserver-sdk v2)
468
+ ## Going live on agent8 (GameServer SDK 2.x)
460
469
 
461
470
  The agent8 platform exposes NOTHING client-callable by default — every function
462
471
  NetworkManager calls (`joinRoom`/`leaveRoom`/`setMyState`/`patchRoomState`/
@@ -483,14 +492,53 @@ The client side is unchanged — `await NetworkManager.create(engine)` uses the
483
492
  built-in `createAgent8Server()` transport (verse/account/auth auto-resolve via the
484
493
  SDK). Develop against `LoopbackHub`, then drop the `{ transport }` option to go live.
485
494
 
495
+ **`@agent8/gameserver` 1.10.x and 2.x both work**, which is why the peer range is
496
+ `>=1.10.0` — but **2.x took room entry away from the server**, and that is the one
497
+ place the two majors are not interchangeable:
498
+
499
+ | | 1.10.x | 2.x |
500
+ |---|---|---|
501
+ | enter a room | `remoteFunction('joinRoom', [roomId])` → your kernel's `joinRoom` | `GameServer.joinRoom(roomId)` on the CLIENT; the gateway routes the room and the kernel is never asked |
502
+ | leave | `remoteFunction('leaveRoom', […])` | `GameServer.leaveRoom()` — synchronous, returns `void` |
503
+ | `room: "auto"` | server assigns a random room | **gone** — `roomId` is required and there is no matchmaking call |
504
+ | those two names via `remoteFunction` | fine | **throws client-side**: *"joinRoom() is no longer available via remoteFunction(). Use server.joinRoom() directly."* |
505
+
506
+ The adapter feature-detects which SDK it was handed, so you write the same game
507
+ either way. What you cannot keep is `"room": "auto"` on 2.x — nothing can assign a
508
+ room, so incanto refuses it at boot and tells you to name one. **Declare the room**
509
+ (`"multiplayer": { "room": "arena" }`); everyone who passes the same id meets, and a
510
+ game that wants private matches mints an id per match and shares it.
511
+
512
+ Everything else measured equal across the two: every other method the adapter touches
513
+ exists in both, and 2.x adds two `remoteFunction` options.
514
+
515
+ **The SDK's own `react` peer is narrow, in both majors** — `^18.2.0` in 2.x, an exact
516
+ `19.2.7` in 1.10.2 — so `npm add @agent8/gameserver` fails with `ERESOLVE` on a project
517
+ that is on React 19 (measured: 19.3.0 is refused by both). Platform templates pin React
518
+ 18.3.1 and install cleanly. The adapter itself never touches React: it deep-imports the
519
+ framework-free `GameServer` class, so the peer only constrains INSTALLING the package.
520
+
521
+ One 2.x behaviour change is worth knowing: **`new GameServer(config)` returns a SHARED
522
+ instance** for the same `verse:account:remoteUrl:auth`, ref-counted, where 1.x always
523
+ built a new one. Two `createAgent8Server()` calls with the same config are therefore one
524
+ socket in 2.x and two in 1.x, and only the first `connect()`'s disconnect callback is
525
+ registered. It does not affect the shipped paths — split-screen runs on `LocalGameServer`,
526
+ and live play is one client per browser — but a game that deliberately opened two live
527
+ transports under one account was relying on 1.x behaviour.
528
+
486
529
  > **Cross-links — defer server-code specifics to the service skills, don't duplicate them here:**
487
- > - **`gameserver-sdk-v2`** — the authoritative server AND client reference: the
530
+ > - **`gameserver-sdk`** — the authoritative server AND client reference for **2.x**: the
488
531
  > `$global`/`$room`/`$sender`/`$asset`/`$lock` contexts, `$roomTick`, collection/state
489
532
  > APIs, the init/test/build/deploy flow, the isolated-vm limits, AND client connection +
490
533
  > auth/identity (`useGameServer`, `server.connect`, `$sender.isGuest`/`isFollower`/
491
534
  > `isSubscriber`, Verse8 identity). Read it before editing `server/src/server.ts` and for
492
535
  > how the live client connects.
493
- > - **`gameserver-sdk`** — legacy v1 single-file `server.js` reference.
536
+ > - **`gameserver-sdk-v1`** — legacy 1.x single-file `server.js` reference. Only for a
537
+ > project that already ships one.
538
+ >
539
+ > These two swapped names when the platform made 2.x the default: `gameserver-sdk` used to
540
+ > be the 1.x doc and the 2.x one was `gameserver-sdk-v2`. A skill document older than that
541
+ > — including one installed from an earlier incanto — still uses the old pair.
494
542
 
495
543
  How incanto's model maps onto v2 rooms:
496
544
  - **`network: {mode:'owner', sync:[...]}`** → throttled `setMyState(roomId, {sync:{…}})`
@@ -14,7 +14,8 @@
14
14
  * Server-code specifics (the $global/$room/$sender/$asset/$lock contexts, the
15
15
  * isolated-vm limits, build/deploy) AND the live client's connection + auth/identity
16
16
  * (useGameServer / server.connect / $sender.isGuest etc.) are owned by the service's
17
- * `gameserver-sdk-v2` skill — this file is ONLY the incanto-flavored room protocol body.
17
+ * `gameserver-sdk` skill (the 2.x reference; `gameserver-sdk-v1` is the legacy 1.x one)
18
+ * — this file is ONLY the incanto-flavored room protocol body.
18
19
  *
19
20
  * This class implements EXACTLY the room protocol incanto's NetworkManager (and
20
21
  * the in-memory LoopbackHub) speak, so a game proven on Loopback runs live by
@@ -31,7 +32,7 @@
31
32
  * STRUCTURED v2 requires the `export` keyword (legacy root server.js must NOT export).
32
33
  */
33
34
 
34
- // These globals are injected by the agent8 isolated-vm runtime (see gameserver-sdk-v2).
35
+ // These globals are injected by the agent8 isolated-vm runtime (see the gameserver-sdk skill).
35
36
  declare const $sender: { account: string; roomId: string; isGuest?: boolean };
36
37
 
37
38
  /**
@@ -132,6 +133,19 @@ declare const $asset: {
132
133
 
133
134
  export class Server {
134
135
  // ---- rooms -----------------------------------------------------------------
136
+ // KEEP THESE, and know that on the live platform nothing calls them.
137
+ //
138
+ // SDK 2.x took room entry away from the server: the client calls
139
+ // `GameServer.joinRoom(roomId)`, which asks the gateway to route the room and
140
+ // connects to its Room Server, and the deployed kernel is never consulted. The
141
+ // SDK goes further and REFUSES the old path — `remoteFunction('joinRoom')` and
142
+ // `('leaveRoom')` throw client-side with *"no longer available via
143
+ // remoteFunction()"*, so these two names are the only ones you may not expose
144
+ // as remote functions.
145
+ //
146
+ // They still earn their place: `createLocalGameServer` runs this same class in
147
+ // PREVIEW and enters rooms through them, and a project still on SDK 1.x reaches
148
+ // them for real. Deployed on 2.x they are simply never reached.
135
149
 
136
150
  /** undefined roomId → server-assigned random room; explicit id → shared room. */
137
151
  async joinRoom(roomId?: string): Promise<string> {
@@ -14,7 +14,7 @@
14
14
  "@dimforge/rapier2d-compat": "0.19.3",
15
15
  "@dimforge/rapier3d-compat": "0.19.3",
16
16
  "@pixiv/three-vrm": "^3.5.3",
17
- "incanto": "^0.79.1",
17
+ "incanto": "^0.79.3",
18
18
  "react": "^18.3.1",
19
19
  "react-dom": "^18.3.1",
20
20
  "three": "^0.184.0"
@@ -11,7 +11,7 @@
11
11
  },
12
12
  "dependencies": {
13
13
  "@dimforge/rapier2d-compat": "0.19.3",
14
- "incanto": "^0.79.1",
14
+ "incanto": "^0.79.3",
15
15
  "react": "^18.3.1",
16
16
  "react-dom": "^18.3.1",
17
17
  "three": "^0.184.0"
@@ -11,7 +11,7 @@
11
11
  },
12
12
  "dependencies": {
13
13
  "@dimforge/rapier2d-compat": "0.19.3",
14
- "incanto": "^0.79.1",
14
+ "incanto": "^0.79.3",
15
15
  "react": "^18.3.1",
16
16
  "react-dom": "^18.3.1",
17
17
  "three": "^0.184.0"
@@ -11,7 +11,7 @@
11
11
  },
12
12
  "dependencies": {
13
13
  "@dimforge/rapier2d-compat": "0.19.3",
14
- "incanto": "^0.79.1",
14
+ "incanto": "^0.79.3",
15
15
  "react": "^18.3.1",
16
16
  "react-dom": "^18.3.1",
17
17
  "three": "^0.184.0"
@@ -13,7 +13,7 @@
13
13
  "@dimforge/rapier2d-compat": "0.19.3",
14
14
  "@dimforge/rapier3d-compat": "0.19.3",
15
15
  "@pixiv/three-vrm": "^3.5.3",
16
- "incanto": "^0.79.1",
16
+ "incanto": "^0.79.3",
17
17
  "react": "^18.3.1",
18
18
  "react-dom": "^18.3.1",
19
19
  "three": "^0.184.0"
@@ -13,7 +13,7 @@
13
13
  "@dimforge/rapier2d-compat": "0.19.3",
14
14
  "@dimforge/rapier3d-compat": "0.19.3",
15
15
  "@pixiv/three-vrm": "^3.5.3",
16
- "incanto": "^0.79.1",
16
+ "incanto": "^0.79.3",
17
17
  "react": "^18.3.1",
18
18
  "react-dom": "^18.3.1",
19
19
  "three": "^0.184.0"
@@ -1 +0,0 @@
1
- var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,t)=>()=>(t||(e((t={exports:{}}).exports,t),e=null),t.exports),s=(e,n)=>{let r={};for(var i in e)t(r,i,{get:e[i],enumerable:!0});return n||t(r,Symbol.toStringTag,{value:`Module`}),r},c=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},l=(n,r,a)=>(a=n==null?{}:e(i(n)),c(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));function u(e){return{BASE_URL:`./`,DEV:!1,MODE:`production`,PROD:!0,SSR:!1}[`VITE_${e}`]}function d(){return!1}var f=o((e=>{e.hashU32=function(e){return e|=0,e=e+2127912214+(e<<12)|0,e=e^-949894596^e>>>19,e=e+374761393+(e<<5)|0,e=e+-744332180^e<<9,e=e+-42973499+(e<<3)|0,e^-1252372727^e>>>16|0},e.readU64=function(e,t){var n=0;return n|=e[t++]<<0,n|=e[t++]<<8,n|=e[t++]<<16,n|=e[t++]<<24,n|=e[t++]<<32,n|=e[t++]<<40,n|=e[t++]<<48,n|=e[t++]<<56,n},e.readU32=function(e,t){var n=0;return n|=e[t++]<<0,n|=e[t++]<<8,n|=e[t++]<<16,n|=e[t++]<<24,n},e.writeU32=function(e,t,n){e[t++]=n>>0&255,e[t++]=n>>8&255,e[t++]=n>>16&255,e[t++]=n>>24&255},e.imul=function(e,t){var n=e>>>16,r=e&65535,i=t>>>16,a=t&65535;return r*a+(n*a+r*i<<16)|0}})),p=o((e=>{var t=f(),n=2654435761,r=2246822519,i=3266489917,a=668265263,o=374761393;function s(e,t){return e|=0,t|=0,e>>>(32-t|0)|e<<t|0}function c(e,n,r){return e|=0,n|=0,r|=0,t.imul(e>>>(32-n|0)|e<<n,r)|0}function l(e,t){return e|=0,t|=0,e>>>t^e|0}function u(e,n,r,i,a){return c(t.imul(n,r)+e,i,a)}function d(e,r,i){return c(e+t.imul(r[i],o),11,n)}function p(e,n,r){return u(e,t.readU32(n,r),i,17,a)}function m(e,i,a){return[u(e[0],t.readU32(i,a+0),r,13,n),u(e[1],t.readU32(i,a+4),r,13,n),u(e[2],t.readU32(i,a+8),r,13,n),u(e[3],t.readU32(i,a+12),r,13,n)]}function h(e,a,c,u){var f,h=u;if(u>=16){for(f=[e+n+r,e+r,e,e-n];u>=16;)f=m(f,a,c),c+=16,u-=16;f=s(f[0],1)+s(f[1],7)+s(f[2],12)+s(f[3],18)+h}else f=e+o+u>>>0;for(;u>=4;)f=p(f,a,c),c+=4,u-=4;for(;u>0;)f=d(f,a,c),c++,u--;return f=l(t.imul(l(t.imul(l(f,15),r),13),i),16),f>>>0}e.hash=h})),m=o((e=>{var t=p(),n=f(),r=4,i=13,a=5,o=6,s=65536,c=4,l=(1<<c)-1,u=15,d=O(5<<20),m=E(),h=407708164,g=4,_=8,v=16,y=64,b=192,x=2147483648,S=7,C=4,w=7,T={4:65536,5:262144,6:1048576,7:4194304};function E(){try{return new Uint32Array(s)}catch{for(var e=Array(s),t=0;t<s;t++)e[t]=0;return e}}function D(e){for(var t=0;t<s;t++)m[t]=0}function O(e){try{return new Uint8Array(e)}catch{for(var t=Array(e),n=0;n<e;n++)t[n]=0;return t}}function k(e,t,n){if(Uint8Array.prototype.slice)return e.slice(t,n);var r=e.length;t|=0,t=t<0?Math.max(r+t,0):Math.min(t,r),n=n===void 0?r:n|0,n=n<0?Math.max(r+n,0):Math.min(n,r);for(var i=new Uint8Array(n-t),a=t,o=0;a<n;)i[o++]=e[a++];return i}e.compressBound=function(e){return e+e/255+16|0},e.decompressBound=function(e){var t=0;if(n.readU32(e,t)!==h)throw Error(`invalid magic number`);t+=4;var r=e[t++];if((r&b)!==y)throw Error(`incompatible descriptor version `+(r&b));var i=(r&v)!==0,a=(r&_)!==0,o=e[t++]>>C&w;if(T[o]===void 0)throw Error(`invalid block size `+o);var s=T[o];if(a)return n.readU64(e,t);t++;for(var c=0;;){var l=n.readU32(e,t);if(t+=4,l&x?(l&=~x,c+=l):c+=s,l===0)return c;i&&(t+=4),t+=l}},e.makeBuffer=O,e.decompressBlock=function(e,t,n,i,a){for(var o,s,c=n+i,l,u;n<c;){var d=e[n++],f=d>>4;if(f>0){if(f===15)for(;f+=e[n],e[n++]===255;);for(l=n+f;n<l;)t[a++]=e[n++]}if(n>=c)break;if(o=d&15,s=e[n++]|e[n++]<<8,o===15)for(;o+=e[n],e[n++]===255;);for(o+=r,u=a-s,l=u+o;u<l;)t[a++]=t[u++]|0}return a},e.compressBlock=function(e,t,s,d,f){var p,m,h,g,_,v,y=0,b=d+s,x;if(m=s,d>=i)for(var S=(1<<o)+3;s+r<b-a;){var C=n.readU32(e,s),w=n.hashU32(C)>>>0;if(w=(w>>16^w)>>>0&65535,p=f[w]-1,f[w]=s+1,p<0||s-p>>>16>0||n.readU32(e,p)!==C){_=S++>>o,s+=_;continue}for(S=(1<<o)+3,v=s-m,g=s-p,s+=r,p+=r,h=s;s<b-a&&e[s]===e[p];)s++,p++;h=s-h;var T=h<l?h:l;if(v>=u){for(t[y++]=(u<<c)+T,x=v-u;x>=255;x-=255)t[y++]=255;t[y++]=x}else t[y++]=(v<<c)+T;for(var E=0;E<v;E++)t[y++]=e[m+E];if(t[y++]=g,t[y++]=g>>8,h>=l){for(x=h-l;x>=255;x-=255)t[y++]=255;t[y++]=x}m=s}if(m===0)return 0;if(v=b-m,v>=u){for(t[y++]=u<<c,x=v-u;x>=255;x-=255)t[y++]=255;t[y++]=x}else t[y++]=v<<c;for(s=m;s<b;)t[y++]=e[s++];return y},e.decompressFrame=function(t,r){var i,a,o,s,c=0,l=0;if(n.readU32(t,c)!==h)throw Error(`invalid magic number`);if(c+=4,s=t[c++],(s&b)!==y)throw Error(`incompatible descriptor version`);if(i=(s&v)!==0,a=(s&g)!==0,o=(s&_)!==0,T[t[c++]>>C&w]===void 0)throw Error(`invalid block size`);for(o&&(c+=8),c++;;){var u=n.readU32(t,c);if(c+=4,u===0)break;if(i&&(c+=4),(u&x)!==0){u&=~x;for(var d=0;d<u;d++)r[l++]=t[c++]}else l=e.decompressBlock(t,r,c,u,l),c+=u}return a&&(c+=4),l},e.compressFrame=function(r,i){var a=0;n.writeU32(i,a,h),a+=4,i[a++]=y,i[a++]=S<<C,i[a]=t.hash(0,i,4,a-4)>>8,a++;var o=T[S],s=r.length,c=0;for(D(m);s>0;){var l=0,u=s>o?o:s;if(l=e.compressBlock(r,d,c,u,m),l>u||l===0){n.writeU32(i,a,2147483648|u),a+=4;for(var f=c+u;c<f;)i[a++]=r[c++];s-=u}else{n.writeU32(i,a,l),a+=4;for(var p=0;p<l;)i[a++]=d[p++];c+=u,s-=u}}return n.writeU32(i,a,0),a+=4,a},e.decompress=function(t,n){var r,i;return n===void 0&&(n=e.decompressBound(t)),r=e.makeBuffer(n),i=e.decompressFrame(t,r),i!==n&&(r=k(r,0,i)),r},e.compress=function(t,n){var r,i;return n===void 0&&(n=e.compressBound(t.length)),r=e.makeBuffer(n),i=e.compressFrame(t,r),i!==n&&(r=k(r,0,i)),r}})),h=o(((e,t)=>{function n(e){var t=typeof e;return e!=null&&(t==`object`||t==`function`)}t.exports=n})),g=o(((e,t)=>{t.exports=typeof global==`object`&&global&&global.Object===Object&&global})),_=o(((e,t)=>{var n=g(),r=typeof self==`object`&&self&&self.Object===Object&&self;t.exports=n||r||Function(`return this`)()})),v=o(((e,t)=>{var n=_();t.exports=function(){return n.Date.now()}})),y=o(((e,t)=>{var n=/\s/;function r(e){for(var t=e.length;t--&&n.test(e.charAt(t)););return t}t.exports=r})),b=o(((e,t)=>{var n=y(),r=/^\s+/;function i(e){return e&&e.slice(0,n(e)+1).replace(r,``)}t.exports=i})),x=o(((e,t)=>{t.exports=_().Symbol})),S=o(((e,t)=>{var n=x(),r=Object.prototype,i=r.hasOwnProperty,a=r.toString,o=n?n.toStringTag:void 0;function s(e){var t=i.call(e,o),n=e[o];try{e[o]=void 0;var r=!0}catch{}var s=a.call(e);return r&&(t?e[o]=n:delete e[o]),s}t.exports=s})),C=o(((e,t)=>{var n=Object.prototype.toString;function r(e){return n.call(e)}t.exports=r})),w=o(((e,t)=>{var n=x(),r=S(),i=C(),a=`[object Null]`,o=`[object Undefined]`,s=n?n.toStringTag:void 0;function c(e){return e==null?e===void 0?o:a:s&&s in Object(e)?r(e):i(e)}t.exports=c})),T=o(((e,t)=>{function n(e){return typeof e==`object`&&!!e}t.exports=n})),E=o(((e,t)=>{var n=w(),r=T(),i=`[object Symbol]`;function a(e){return typeof e==`symbol`||r(e)&&n(e)==i}t.exports=a})),D=o(((e,t)=>{var n=b(),r=h(),i=E(),a=NaN,o=/^[-+]0x[0-9a-f]+$/i,s=/^0b[01]+$/i,c=/^0o[0-7]+$/i,l=parseInt;function u(e){if(typeof e==`number`)return e;if(i(e))return a;if(r(e)){var t=typeof e.valueOf==`function`?e.valueOf():e;e=r(t)?t+``:t}if(typeof e!=`string`)return e===0?e:+e;e=n(e);var u=s.test(e);return u||c.test(e)?l(e.slice(2),u?2:8):o.test(e)?a:+e}t.exports=u})),O=o(((e,t)=>{var n=h(),r=v(),i=D(),a=`Expected a function`,o=Math.max,s=Math.min;function c(e,t,c){var l,u,d,f,p,m,h=0,g=!1,_=!1,v=!0;if(typeof e!=`function`)throw TypeError(a);t=i(t)||0,n(c)&&(g=!!c.leading,_=`maxWait`in c,d=_?o(i(c.maxWait)||0,t):d,v=`trailing`in c?!!c.trailing:v);function y(t){var n=l,r=u;return l=u=void 0,h=t,f=e.apply(r,n),f}function b(e){return h=e,p=setTimeout(C,t),g?y(e):f}function x(e){var n=e-m,r=e-h,i=t-n;return _?s(i,d-r):i}function S(e){var n=e-m,r=e-h;return m===void 0||n>=t||n<0||_&&r>=d}function C(){var e=r();if(S(e))return w(e);p=setTimeout(C,x(e))}function w(e){return p=void 0,v&&l?y(e):(l=u=void 0,f)}function T(){p!==void 0&&clearTimeout(p),h=0,l=m=u=p=void 0}function E(){return p===void 0?f:w(r())}function D(){var e=r(),n=S(e);if(l=arguments,u=this,m=e,n){if(p===void 0)return b(m);if(_)return clearTimeout(p),p=setTimeout(C,t),y(m)}return p===void 0&&(p=setTimeout(C,t)),f}return D.cancel=T,D.flush=E,D}t.exports=c})),k=o(((e,t)=>{var n=O(),r=h(),i=`Expected a function`;function a(e,t,a){var o=!0,s=!0;if(typeof e!=`function`)throw TypeError(i);return r(a)&&(o=`leading`in a?!!a.leading:o,s=`trailing`in a?!!a.trailing:s),n(e,t,{leading:o,maxWait:t,trailing:s})}t.exports=a}));function ee(e){let t=e.length,n=0,r=0;for(;r<t;){let i=e.charCodeAt(r++);if(!(i&4294967168)){n++;continue}else if(!(i&4294965248))n+=2;else{if(i>=55296&&i<=56319&&r<t){let t=e.charCodeAt(r);(t&64512)==56320&&(++r,i=((i&1023)<<10)+(t&1023)+65536)}i&4294901760?n+=4:n+=3}}return n}function te(e,t,n){let r=e.length,i=n,a=0;for(;a<r;){let n=e.charCodeAt(a++);if(!(n&4294967168)){t[i++]=n;continue}else if(!(n&4294965248))t[i++]=n>>6&31|192;else{if(n>=55296&&n<=56319&&a<r){let t=e.charCodeAt(a);(t&64512)==56320&&(++a,n=((n&1023)<<10)+(t&1023)+65536)}n&4294901760?(t[i++]=n>>18&7|240,t[i++]=n>>12&63|128,t[i++]=n>>6&63|128):(t[i++]=n>>12&15|224,t[i++]=n>>6&63|128)}t[i++]=n&63|128}}var ne=new TextEncoder,re=50;function ie(e,t,n){ne.encodeInto(e,t.subarray(n))}function ae(e,t,n){e.length>re?ie(e,t,n):te(e,t,n)}var oe=4096;function se(e,t,n){let r=t,i=r+n,a=[],o=``;for(;r<i;){let t=e[r++];if(!(t&128))a.push(t);else if((t&224)==192){let n=e[r++]&63;a.push((t&31)<<6|n)}else if((t&240)==224){let n=e[r++]&63,i=e[r++]&63;a.push((t&31)<<12|n<<6|i)}else if((t&248)==240){let n=e[r++]&63,i=e[r++]&63,o=e[r++]&63,s=(t&7)<<18|n<<12|i<<6|o;s>65535&&(s-=65536,a.push(s>>>10&1023|55296),s=56320|s&1023),a.push(s)}else a.push(t);a.length>=oe&&(o+=String.fromCharCode(...a),a.length=0)}return a.length>0&&(o+=String.fromCharCode(...a)),o}var ce=new TextDecoder,le=200;function ue(e,t,n){let r=e.subarray(t,t+n);return ce.decode(r)}function de(e,t,n){return n>le?ue(e,t,n):se(e,t,n)}var A=class{type;data;constructor(e,t){this.type=e,this.data=t}},j=class e extends Error{constructor(t){super(t);let n=Object.create(e.prototype);Object.setPrototypeOf(this,n),Object.defineProperty(this,"name",{configurable:!0,enumerable:!1,value:e.name})}};function fe(e,t,n){let r=n/4294967296,i=n;e.setUint32(t,r),e.setUint32(t+4,i)}function M(e,t,n){let r=Math.floor(n/4294967296),i=n;e.setUint32(t,r),e.setUint32(t+4,i)}function N(e,t){let n=e.getInt32(t),r=e.getUint32(t+4);return n*4294967296+r}function pe(e,t){let n=e.getUint32(t),r=e.getUint32(t+4);return n*4294967296+r}var me=4294967295,he=17179869183;function ge({sec:e,nsec:t}){if(e>=0&&t>=0&&e<=he)if(t===0&&e<=me){let t=new Uint8Array(4);return new DataView(t.buffer).setUint32(0,e),t}else{let n=e/4294967296,r=e&4294967295,i=new Uint8Array(8),a=new DataView(i.buffer);return a.setUint32(0,t<<2|n&3),a.setUint32(4,r),i}else{let n=new Uint8Array(12),r=new DataView(n.buffer);return r.setUint32(0,t),M(r,4,e),n}}function _e(e){let t=e.getTime(),n=Math.floor(t/1e3),r=(t-n*1e3)*1e6,i=Math.floor(r/1e9);return{sec:n+i,nsec:r-i*1e9}}function ve(e){return e instanceof Date?ge(_e(e)):null}function ye(e){let t=new DataView(e.buffer,e.byteOffset,e.byteLength);switch(e.byteLength){case 4:return{sec:t.getUint32(0),nsec:0};case 8:{let e=t.getUint32(0),n=t.getUint32(4);return{sec:(e&3)*4294967296+n,nsec:e>>>2}}case 12:return{sec:N(t,4),nsec:t.getUint32(0)};default:throw new j(`Unrecognized data size for timestamp (expected 4, 8, or 12): ${e.length}`)}}function be(e){let t=ye(e);return new Date(t.sec*1e3+t.nsec/1e6)}var xe={type:-1,encode:ve,decode:be},P=class e{static defaultCodec=new e;__brand;builtInEncoders=[];builtInDecoders=[];encoders=[];decoders=[];constructor(){this.register(xe)}register({type:e,encode:t,decode:n}){if(e>=0)this.encoders[e]=t,this.decoders[e]=n;else{let r=-1-e;this.builtInEncoders[r]=t,this.builtInDecoders[r]=n}}tryToEncode(e,t){for(let n=0;n<this.builtInEncoders.length;n++){let r=this.builtInEncoders[n];if(r!=null){let i=r(e,t);if(i!=null)return new A(-1-n,i)}}for(let n=0;n<this.encoders.length;n++){let r=this.encoders[n];if(r!=null){let i=r(e,t);if(i!=null)return new A(n,i)}}return e instanceof A?e:null}decode(e,t,n){let r=t<0?this.builtInDecoders[-1-t]:this.decoders[t];return r?r(e,t,n):new A(t,e)}};function Se(e){return e instanceof ArrayBuffer||typeof SharedArrayBuffer<`u`&&e instanceof SharedArrayBuffer}function F(e){return e instanceof Uint8Array?e:ArrayBuffer.isView(e)?new Uint8Array(e.buffer,e.byteOffset,e.byteLength):Se(e)?new Uint8Array(e):Uint8Array.from(e)}var Ce=class e{extensionCodec;context;useBigInt64;maxDepth;initialBufferSize;sortKeys;forceFloat32;ignoreUndefined;forceIntegerToFloat;pos;view;bytes;entered=!1;constructor(e){this.extensionCodec=e?.extensionCodec??P.defaultCodec,this.context=e?.context,this.useBigInt64=e?.useBigInt64??!1,this.maxDepth=e?.maxDepth??100,this.initialBufferSize=e?.initialBufferSize??2048,this.sortKeys=e?.sortKeys??!1,this.forceFloat32=e?.forceFloat32??!1,this.ignoreUndefined=e?.ignoreUndefined??!1,this.forceIntegerToFloat=e?.forceIntegerToFloat??!1,this.pos=0,this.view=new DataView(new ArrayBuffer(this.initialBufferSize)),this.bytes=new Uint8Array(this.view.buffer)}clone(){return new e({extensionCodec:this.extensionCodec,context:this.context,useBigInt64:this.useBigInt64,maxDepth:this.maxDepth,initialBufferSize:this.initialBufferSize,sortKeys:this.sortKeys,forceFloat32:this.forceFloat32,ignoreUndefined:this.ignoreUndefined,forceIntegerToFloat:this.forceIntegerToFloat})}reinitializeState(){this.pos=0}encodeSharedRef(e){if(this.entered)return this.clone().encodeSharedRef(e);try{return this.entered=!0,this.reinitializeState(),this.doEncode(e,1),this.bytes.subarray(0,this.pos)}finally{this.entered=!1}}encode(e){if(this.entered)return this.clone().encode(e);try{return this.entered=!0,this.reinitializeState(),this.doEncode(e,1),this.bytes.slice(0,this.pos)}finally{this.entered=!1}}doEncode(e,t){if(t>this.maxDepth)throw Error(`Too deep objects in depth ${t}`);e==null?this.encodeNil():typeof e==`boolean`?this.encodeBoolean(e):typeof e==`number`?this.forceIntegerToFloat?this.encodeNumberAsFloat(e):this.encodeNumber(e):typeof e==`string`?this.encodeString(e):this.useBigInt64&&typeof e==`bigint`?this.encodeBigInt64(e):this.encodeObject(e,t)}ensureBufferSizeToWrite(e){let t=this.pos+e;this.view.byteLength<t&&this.resizeBuffer(t*2)}resizeBuffer(e){let t=new ArrayBuffer(e),n=new Uint8Array(t),r=new DataView(t);n.set(this.bytes),this.view=r,this.bytes=n}encodeNil(){this.writeU8(192)}encodeBoolean(e){e===!1?this.writeU8(194):this.writeU8(195)}encodeNumber(e){!this.forceIntegerToFloat&&Number.isSafeInteger(e)?e>=0?e<128?this.writeU8(e):e<256?(this.writeU8(204),this.writeU8(e)):e<65536?(this.writeU8(205),this.writeU16(e)):e<4294967296?(this.writeU8(206),this.writeU32(e)):this.useBigInt64?this.encodeNumberAsFloat(e):(this.writeU8(207),this.writeU64(e)):e>=-32?this.writeU8(224|e+32):e>=-128?(this.writeU8(208),this.writeI8(e)):e>=-32768?(this.writeU8(209),this.writeI16(e)):e>=-2147483648?(this.writeU8(210),this.writeI32(e)):this.useBigInt64?this.encodeNumberAsFloat(e):(this.writeU8(211),this.writeI64(e)):this.encodeNumberAsFloat(e)}encodeNumberAsFloat(e){this.forceFloat32?(this.writeU8(202),this.writeF32(e)):(this.writeU8(203),this.writeF64(e))}encodeBigInt64(e){e>=BigInt(0)?(this.writeU8(207),this.writeBigUint64(e)):(this.writeU8(211),this.writeBigInt64(e))}writeStringHeader(e){if(e<32)this.writeU8(160+e);else if(e<256)this.writeU8(217),this.writeU8(e);else if(e<65536)this.writeU8(218),this.writeU16(e);else if(e<4294967296)this.writeU8(219),this.writeU32(e);else throw Error(`Too long string: ${e} bytes in UTF-8`)}encodeString(e){let t=ee(e);this.ensureBufferSizeToWrite(5+t),this.writeStringHeader(t),ae(e,this.bytes,this.pos),this.pos+=t}encodeObject(e,t){let n=this.extensionCodec.tryToEncode(e,this.context);if(n!=null)this.encodeExtension(n);else if(Array.isArray(e))this.encodeArray(e,t);else if(ArrayBuffer.isView(e))this.encodeBinary(e);else if(typeof e==`object`)this.encodeMap(e,t);else throw Error(`Unrecognized object: ${Object.prototype.toString.apply(e)}`)}encodeBinary(e){let t=e.byteLength;if(t<256)this.writeU8(196),this.writeU8(t);else if(t<65536)this.writeU8(197),this.writeU16(t);else if(t<4294967296)this.writeU8(198),this.writeU32(t);else throw Error(`Too large binary: ${t}`);let n=F(e);this.writeU8a(n)}encodeArray(e,t){let n=e.length;if(n<16)this.writeU8(144+n);else if(n<65536)this.writeU8(220),this.writeU16(n);else if(n<4294967296)this.writeU8(221),this.writeU32(n);else throw Error(`Too large array: ${n}`);for(let n of e)this.doEncode(n,t+1)}countWithoutUndefined(e,t){let n=0;for(let r of t)e[r]!==void 0&&n++;return n}encodeMap(e,t){let n=Object.keys(e);this.sortKeys&&n.sort();let r=this.ignoreUndefined?this.countWithoutUndefined(e,n):n.length;if(r<16)this.writeU8(128+r);else if(r<65536)this.writeU8(222),this.writeU16(r);else if(r<4294967296)this.writeU8(223),this.writeU32(r);else throw Error(`Too large map object: ${r}`);for(let r of n){let n=e[r];this.ignoreUndefined&&n===void 0||(this.encodeString(r),this.doEncode(n,t+1))}}encodeExtension(e){if(typeof e.data==`function`){let t=e.data(this.pos+6),n=t.length;if(n>=4294967296)throw Error(`Too large extension object: ${n}`);this.writeU8(201),this.writeU32(n),this.writeI8(e.type),this.writeU8a(t);return}let t=e.data.length;if(t===1)this.writeU8(212);else if(t===2)this.writeU8(213);else if(t===4)this.writeU8(214);else if(t===8)this.writeU8(215);else if(t===16)this.writeU8(216);else if(t<256)this.writeU8(199),this.writeU8(t);else if(t<65536)this.writeU8(200),this.writeU16(t);else if(t<4294967296)this.writeU8(201),this.writeU32(t);else throw Error(`Too large extension object: ${t}`);this.writeI8(e.type),this.writeU8a(e.data)}writeU8(e){this.ensureBufferSizeToWrite(1),this.view.setUint8(this.pos,e),this.pos++}writeU8a(e){let t=e.length;this.ensureBufferSizeToWrite(t),this.bytes.set(e,this.pos),this.pos+=t}writeI8(e){this.ensureBufferSizeToWrite(1),this.view.setInt8(this.pos,e),this.pos++}writeU16(e){this.ensureBufferSizeToWrite(2),this.view.setUint16(this.pos,e),this.pos+=2}writeI16(e){this.ensureBufferSizeToWrite(2),this.view.setInt16(this.pos,e),this.pos+=2}writeU32(e){this.ensureBufferSizeToWrite(4),this.view.setUint32(this.pos,e),this.pos+=4}writeI32(e){this.ensureBufferSizeToWrite(4),this.view.setInt32(this.pos,e),this.pos+=4}writeF32(e){this.ensureBufferSizeToWrite(4),this.view.setFloat32(this.pos,e),this.pos+=4}writeF64(e){this.ensureBufferSizeToWrite(8),this.view.setFloat64(this.pos,e),this.pos+=8}writeU64(e){this.ensureBufferSizeToWrite(8),fe(this.view,this.pos,e),this.pos+=8}writeI64(e){this.ensureBufferSizeToWrite(8),M(this.view,this.pos,e),this.pos+=8}writeBigUint64(e){this.ensureBufferSizeToWrite(8),this.view.setBigUint64(this.pos,e),this.pos+=8}writeBigInt64(e){this.ensureBufferSizeToWrite(8),this.view.setBigInt64(this.pos,e),this.pos+=8}};function we(e,t){return new Ce(t).encodeSharedRef(e)}function I(e){return`${e<0?`-`:``}0x${Math.abs(e).toString(16).padStart(2,`0`)}`}var Te=16,Ee=16,De=class{hit=0;miss=0;caches;maxKeyLength;maxLengthPerKey;constructor(e=Te,t=Ee){this.maxKeyLength=e,this.maxLengthPerKey=t,this.caches=[];for(let e=0;e<this.maxKeyLength;e++)this.caches.push([])}canBeCached(e){return e>0&&e<=this.maxKeyLength}find(e,t,n){let r=this.caches[n-1];FIND_CHUNK:for(let i of r){let r=i.bytes;for(let i=0;i<n;i++)if(r[i]!==e[t+i])continue FIND_CHUNK;return i.str}return null}store(e,t){let n=this.caches[e.length-1],r={bytes:e,str:t};n.length>=this.maxLengthPerKey?n[Math.random()*n.length|0]=r:n.push(r)}decode(e,t,n){let r=this.find(e,t,n);if(r!=null)return this.hit++,r;this.miss++;let i=se(e,t,n),a=Uint8Array.prototype.slice.call(e,t,t+n);return this.store(a,i),i}},L=`array`,R=`map_key`,z=`map_value`,Oe=e=>{if(typeof e==`string`||typeof e==`number`)return e;throw new j(`The type of key must be string or number but `+typeof e)},ke=class{stack=[];stackHeadPosition=-1;get length(){return this.stackHeadPosition+1}top(){return this.stack[this.stackHeadPosition]}pushArrayState(e){let t=this.getUninitializedStateFromPool();t.type=L,t.position=0,t.size=e,t.array=Array(e)}pushMapState(e){let t=this.getUninitializedStateFromPool();t.type=R,t.readCount=0,t.size=e,t.map={}}getUninitializedStateFromPool(){return this.stackHeadPosition++,this.stackHeadPosition===this.stack.length&&this.stack.push({type:void 0,size:0,array:void 0,position:0,readCount:0,map:void 0,key:null}),this.stack[this.stackHeadPosition]}release(e){if(this.stack[this.stackHeadPosition]!==e)throw Error(`Invalid stack state. Released state is not on top of the stack.`);if(e.type===L){let t=e;t.size=0,t.array=void 0,t.position=0,t.type=void 0}if(e.type===R||e.type===z){let t=e;t.size=0,t.map=void 0,t.readCount=0,t.type=void 0}this.stackHeadPosition--}reset(){this.stack.length=0,this.stackHeadPosition=-1}},B=-1,V=new DataView(new ArrayBuffer(0)),Ae=new Uint8Array(V.buffer);try{V.getInt8(0)}catch(e){if(!(e instanceof RangeError))throw Error(`This module is not supported in the current JavaScript engine because DataView does not throw RangeError on out-of-bounds access`)}var je=RangeError(`Insufficient data`),Me=new De,Ne=class e{extensionCodec;context;useBigInt64;rawStrings;maxStrLength;maxBinLength;maxArrayLength;maxMapLength;maxExtLength;keyDecoder;mapKeyConverter;totalPos=0;pos=0;view=V;bytes=Ae;headByte=B;stack=new ke;entered=!1;constructor(e){this.extensionCodec=e?.extensionCodec??P.defaultCodec,this.context=e?.context,this.useBigInt64=e?.useBigInt64??!1,this.rawStrings=e?.rawStrings??!1,this.maxStrLength=e?.maxStrLength??4294967295,this.maxBinLength=e?.maxBinLength??4294967295,this.maxArrayLength=e?.maxArrayLength??4294967295,this.maxMapLength=e?.maxMapLength??4294967295,this.maxExtLength=e?.maxExtLength??4294967295,this.keyDecoder=e?.keyDecoder===void 0?Me:e.keyDecoder,this.mapKeyConverter=e?.mapKeyConverter??Oe}clone(){return new e({extensionCodec:this.extensionCodec,context:this.context,useBigInt64:this.useBigInt64,rawStrings:this.rawStrings,maxStrLength:this.maxStrLength,maxBinLength:this.maxBinLength,maxArrayLength:this.maxArrayLength,maxMapLength:this.maxMapLength,maxExtLength:this.maxExtLength,keyDecoder:this.keyDecoder})}reinitializeState(){this.totalPos=0,this.headByte=B,this.stack.reset()}setBuffer(e){let t=F(e);this.bytes=t,this.view=new DataView(t.buffer,t.byteOffset,t.byteLength),this.pos=0}appendBuffer(e){if(this.headByte===B&&!this.hasRemaining(1))this.setBuffer(e);else{let t=this.bytes.subarray(this.pos),n=F(e),r=new Uint8Array(t.length+n.length);r.set(t),r.set(n,t.length),this.setBuffer(r)}}hasRemaining(e){return this.view.byteLength-this.pos>=e}createExtraByteError(e){let{view:t,pos:n}=this;return RangeError(`Extra ${t.byteLength-n} of ${t.byteLength} byte(s) found at buffer[${e}]`)}decode(e){if(this.entered)return this.clone().decode(e);try{this.entered=!0,this.reinitializeState(),this.setBuffer(e);let t=this.doDecodeSync();if(this.hasRemaining(1))throw this.createExtraByteError(this.pos);return t}finally{this.entered=!1}}*decodeMulti(e){if(this.entered){yield*this.clone().decodeMulti(e);return}try{for(this.entered=!0,this.reinitializeState(),this.setBuffer(e);this.hasRemaining(1);)yield this.doDecodeSync()}finally{this.entered=!1}}async decodeAsync(e){if(this.entered)return this.clone().decodeAsync(e);try{this.entered=!0;let t=!1,n;for await(let r of e){if(t)throw this.entered=!1,this.createExtraByteError(this.totalPos);this.appendBuffer(r);try{n=this.doDecodeSync(),t=!0}catch(e){if(!(e instanceof RangeError))throw e}this.totalPos+=this.pos}if(t){if(this.hasRemaining(1))throw this.createExtraByteError(this.totalPos);return n}let{headByte:r,pos:i,totalPos:a}=this;throw RangeError(`Insufficient data in parsing ${I(r)} at ${a} (${i} in the current buffer)`)}finally{this.entered=!1}}decodeArrayStream(e){return this.decodeMultiAsync(e,!0)}decodeStream(e){return this.decodeMultiAsync(e,!1)}async*decodeMultiAsync(e,t){if(this.entered){yield*this.clone().decodeMultiAsync(e,t);return}try{this.entered=!0;let n=t,r=-1;for await(let i of e){if(t&&r===0)throw this.createExtraByteError(this.totalPos);this.appendBuffer(i),n&&(r=this.readArraySize(),n=!1,this.complete());try{for(;yield this.doDecodeSync(),--r!==0;);}catch(e){if(!(e instanceof RangeError))throw e}this.totalPos+=this.pos}}finally{this.entered=!1}}doDecodeSync(){DECODE:for(;;){let e=this.readHeadByte(),t;if(e>=224)t=e-256;else if(e<192)if(e<128)t=e;else if(e<144){let n=e-128;if(n!==0){this.pushMapState(n),this.complete();continue DECODE}else t={}}else if(e<160){let n=e-144;if(n!==0){this.pushArrayState(n),this.complete();continue DECODE}else t=[]}else{let n=e-160;t=this.decodeString(n,0)}else if(e===192)t=null;else if(e===194)t=!1;else if(e===195)t=!0;else if(e===202)t=this.readF32();else if(e===203)t=this.readF64();else if(e===204)t=this.readU8();else if(e===205)t=this.readU16();else if(e===206)t=this.readU32();else if(e===207)t=this.useBigInt64?this.readU64AsBigInt():this.readU64();else if(e===208)t=this.readI8();else if(e===209)t=this.readI16();else if(e===210)t=this.readI32();else if(e===211)t=this.useBigInt64?this.readI64AsBigInt():this.readI64();else if(e===217){let e=this.lookU8();t=this.decodeString(e,1)}else if(e===218){let e=this.lookU16();t=this.decodeString(e,2)}else if(e===219){let e=this.lookU32();t=this.decodeString(e,4)}else if(e===220){let e=this.readU16();if(e!==0){this.pushArrayState(e),this.complete();continue DECODE}else t=[]}else if(e===221){let e=this.readU32();if(e!==0){this.pushArrayState(e),this.complete();continue DECODE}else t=[]}else if(e===222){let e=this.readU16();if(e!==0){this.pushMapState(e),this.complete();continue DECODE}else t={}}else if(e===223){let e=this.readU32();if(e!==0){this.pushMapState(e),this.complete();continue DECODE}else t={}}else if(e===196){let e=this.lookU8();t=this.decodeBinary(e,1)}else if(e===197){let e=this.lookU16();t=this.decodeBinary(e,2)}else if(e===198){let e=this.lookU32();t=this.decodeBinary(e,4)}else if(e===212)t=this.decodeExtension(1,0);else if(e===213)t=this.decodeExtension(2,0);else if(e===214)t=this.decodeExtension(4,0);else if(e===215)t=this.decodeExtension(8,0);else if(e===216)t=this.decodeExtension(16,0);else if(e===199){let e=this.lookU8();t=this.decodeExtension(e,1)}else if(e===200){let e=this.lookU16();t=this.decodeExtension(e,2)}else if(e===201){let e=this.lookU32();t=this.decodeExtension(e,4)}else throw new j(`Unrecognized type byte: ${I(e)}`);this.complete();let n=this.stack;for(;n.length>0;){let e=n.top();if(e.type===L)if(e.array[e.position]=t,e.position++,e.position===e.size)t=e.array,n.release(e);else continue DECODE;else if(e.type===R){if(t===`__proto__`)throw new j(`The key __proto__ is not allowed`);e.key=this.mapKeyConverter(t),e.type=z;continue DECODE}else if(e.map[e.key]=t,e.readCount++,e.readCount===e.size)t=e.map,n.release(e);else{e.key=null,e.type=R;continue DECODE}}return t}}readHeadByte(){return this.headByte===B&&(this.headByte=this.readU8()),this.headByte}complete(){this.headByte=B}readArraySize(){let e=this.readHeadByte();switch(e){case 220:return this.readU16();case 221:return this.readU32();default:if(e<160)return e-144;throw new j(`Unrecognized array type byte: ${I(e)}`)}}pushMapState(e){if(e>this.maxMapLength)throw new j(`Max length exceeded: map length (${e}) > maxMapLengthLength (${this.maxMapLength})`);this.stack.pushMapState(e)}pushArrayState(e){if(e>this.maxArrayLength)throw new j(`Max length exceeded: array length (${e}) > maxArrayLength (${this.maxArrayLength})`);this.stack.pushArrayState(e)}decodeString(e,t){return!this.rawStrings||this.stateIsMapKey()?this.decodeUtf8String(e,t):this.decodeBinary(e,t)}decodeUtf8String(e,t){if(e>this.maxStrLength)throw new j(`Max length exceeded: UTF-8 byte length (${e}) > maxStrLength (${this.maxStrLength})`);if(this.bytes.byteLength<this.pos+t+e)throw je;let n=this.pos+t,r;return r=this.stateIsMapKey()&&this.keyDecoder?.canBeCached(e)?this.keyDecoder.decode(this.bytes,n,e):de(this.bytes,n,e),this.pos+=t+e,r}stateIsMapKey(){return this.stack.length>0?this.stack.top().type===R:!1}decodeBinary(e,t){if(e>this.maxBinLength)throw new j(`Max length exceeded: bin length (${e}) > maxBinLength (${this.maxBinLength})`);if(!this.hasRemaining(e+t))throw je;let n=this.pos+t,r=this.bytes.subarray(n,n+e);return this.pos+=t+e,r}decodeExtension(e,t){if(e>this.maxExtLength)throw new j(`Max length exceeded: ext length (${e}) > maxExtLength (${this.maxExtLength})`);let n=this.view.getInt8(this.pos+t),r=this.decodeBinary(e,t+1);return this.extensionCodec.decode(r,n,this.context)}lookU8(){return this.view.getUint8(this.pos)}lookU16(){return this.view.getUint16(this.pos)}lookU32(){return this.view.getUint32(this.pos)}readU8(){let e=this.view.getUint8(this.pos);return this.pos++,e}readI8(){let e=this.view.getInt8(this.pos);return this.pos++,e}readU16(){let e=this.view.getUint16(this.pos);return this.pos+=2,e}readI16(){let e=this.view.getInt16(this.pos);return this.pos+=2,e}readU32(){let e=this.view.getUint32(this.pos);return this.pos+=4,e}readI32(){let e=this.view.getInt32(this.pos);return this.pos+=4,e}readU64(){let e=pe(this.view,this.pos);return this.pos+=8,e}readI64(){let e=N(this.view,this.pos);return this.pos+=8,e}readU64AsBigInt(){let e=this.view.getBigUint64(this.pos);return this.pos+=8,e}readI64AsBigInt(){let e=this.view.getBigInt64(this.pos);return this.pos+=8,e}readF32(){let e=this.view.getFloat32(this.pos);return this.pos+=4,e}readF64(){let e=this.view.getFloat64(this.pos);return this.pos+=8,e}};function Pe(e,t){return new Ne(t).decode(e)}var Fe=l(k()),H=l(m()),Ie=class{client;throttleTime;queue=[];batchTimeout=null;constructor(e,t=30){this.client=e,this.throttleTime=t}emit(e){this.queue.push(e),this.batchTimeout||=setTimeout(()=>{this.queue.length>0&&this.client.readyState===1&&this.client.send(H.compress(we({event:`fn:call`,data:this.queue.splice(0,this.queue.length)}))),this.batchTimeout=null},this.throttleTime)}},U={addItems:(e,t)=>t.forEach(t=>{let n=e.findIndex(e=>e.__id===t.__id);n===-1?e.push(t):e[n]=t}),removeItems:(e,t)=>t.forEach(t=>{let n=e.findIndex(e=>e.__id===t.__id);n!==-1&&e.splice(n,1)}),updateItems:(e,t)=>t.forEach(t=>{let n=e.findIndex(e=>e.__id===t.__id);n===-1?e.push(t):e[n]=t}),setItems:(e,t)=>{e.length=0,e.push(...t)}},Le=class{remoteUrl;verse;account;auth;constructor(e,t,n,r){this.remoteUrl=e,this.verse=t,this.account=n,this.auth=r}async fetchUrl(e,t=`en`){let n=`${this.remoteUrl.replace(/^ws/,`http`)}/crossramp/${encodeURIComponent(this.verse)}/${encodeURIComponent(this.account)}/${e}?lang=${t}`,r=await fetch(n,{headers:{"Content-Type":`application/json`,...this.auth&&{Authorization:`Bearer ${this.auth}`}}});if(!r.ok){let t=`Failed to get CrossRamp ${e}: HTTP ${r.status}`;try{let e=await r.json();e?.message&&(t=e.message)}catch{}throw Error(t)}let i=await r.json();if(!i.success||!i.data?.url)throw Error(i.errorCode||`Invalid CrossRamp API response`);return i.data.url}async getShopUrl(e=`en`){return this.fetchUrl(`shop-url`,e)}async getForgeUrl(e=`en`){return this.fetchUrl(`forge-url`,e)}updateConfig(e,t,n,r){this.remoteUrl=e,this.verse=t,this.account=n,r!==void 0&&(this.auth=r)}},W=BigInt(2**32-1),G=BigInt(32);function Re(e,t=!1){return t?{h:Number(e&W),l:Number(e>>G&W)}:{h:Number(e>>G&W)|0,l:Number(e&W)|0}}function ze(e,t=!1){let n=e.length,r=new Uint32Array(n),i=new Uint32Array(n);for(let a=0;a<n;a++){let{h:n,l:o}=Re(e[a],t);[r[a],i[a]]=[n,o]}return[r,i]}var Be=(e,t,n)=>e<<n|t>>>32-n,Ve=(e,t,n)=>t<<n|e>>>32-n,He=(e,t,n)=>t<<n-32|e>>>64-n,Ue=(e,t,n)=>e<<n-32|t>>>64-n;function We(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name===`Uint8Array`}function K(e){if(!Number.isSafeInteger(e)||e<0)throw Error(`positive integer expected, got `+e)}function q(e,...t){if(!We(e))throw Error(`Uint8Array expected`);if(t.length>0&&!t.includes(e.length))throw Error(`Uint8Array expected of length `+t+`, got length=`+e.length)}function J(e,t=!0){if(e.destroyed)throw Error(`Hash instance has been destroyed`);if(t&&e.finished)throw Error(`Hash#digest() has already been called`)}function Ge(e,t){q(e);let n=t.outputLen;if(e.length<n)throw Error(`digestInto() expects output buffer of length at least `+n)}function Ke(e){return new Uint32Array(e.buffer,e.byteOffset,Math.floor(e.byteLength/4))}function Y(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}var qe=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function Je(e){return e<<24&4278190080|e<<8&16711680|e>>>8&65280|e>>>24&255}function Ye(e){for(let t=0;t<e.length;t++)e[t]=Je(e[t]);return e}var X=qe?e=>e:Ye;function Xe(e){if(typeof e!=`string`)throw Error(`string expected`);return new Uint8Array(new TextEncoder().encode(e))}function Ze(e){return typeof e==`string`&&(e=Xe(e)),q(e),e}var Qe=class{};function $e(e){let t=t=>e().update(Ze(t)).digest(),n=e();return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=()=>e(),t}var et=BigInt(0),Z=BigInt(1),tt=BigInt(2),nt=BigInt(7),rt=BigInt(256),it=BigInt(113),at=[],ot=[],st=[];for(let e=0,t=Z,n=1,r=0;e<24;e++){[n,r]=[r,(2*n+3*r)%5],at.push(2*(5*r+n)),ot.push((e+1)*(e+2)/2%64);let i=et;for(let e=0;e<7;e++)t=(t<<Z^(t>>nt)*it)%rt,t&tt&&(i^=Z<<(Z<<BigInt(e))-Z);st.push(i)}var ct=ze(st,!0),lt=ct[0],ut=ct[1],Q=(e,t,n)=>n>32?He(e,t,n):Be(e,t,n),dt=(e,t,n)=>n>32?Ue(e,t,n):Ve(e,t,n);function ft(e,t=24){let n=new Uint32Array(10);for(let r=24-t;r<24;r++){for(let t=0;t<10;t++)n[t]=e[t]^e[t+10]^e[t+20]^e[t+30]^e[t+40];for(let t=0;t<10;t+=2){let r=(t+8)%10,i=(t+2)%10,a=n[i],o=n[i+1],s=Q(a,o,1)^n[r],c=dt(a,o,1)^n[r+1];for(let n=0;n<50;n+=10)e[t+n]^=s,e[t+n+1]^=c}let t=e[2],i=e[3];for(let n=0;n<24;n++){let r=ot[n],a=Q(t,i,r),o=dt(t,i,r),s=at[n];t=e[s],i=e[s+1],e[s]=a,e[s+1]=o}for(let t=0;t<50;t+=10){for(let r=0;r<10;r++)n[r]=e[t+r];for(let r=0;r<10;r++)e[t+r]^=~n[(r+2)%10]&n[(r+4)%10]}e[0]^=lt[r],e[1]^=ut[r]}Y(n)}var pt=class e extends Qe{constructor(e,t,n,r=!1,i=24){if(super(),this.pos=0,this.posOut=0,this.finished=!1,this.destroyed=!1,this.enableXOF=!1,this.blockLen=e,this.suffix=t,this.outputLen=n,this.enableXOF=r,this.rounds=i,K(n),!(0<e&&e<200))throw Error(`only keccak-f1600 function is supported`);this.state=new Uint8Array(200),this.state32=Ke(this.state)}clone(){return this._cloneInto()}keccak(){X(this.state32),ft(this.state32,this.rounds),X(this.state32),this.posOut=0,this.pos=0}update(e){J(this),e=Ze(e),q(e);let{blockLen:t,state:n}=this,r=e.length;for(let i=0;i<r;){let a=Math.min(t-this.pos,r-i);for(let t=0;t<a;t++)n[this.pos++]^=e[i++];this.pos===t&&this.keccak()}return this}finish(){if(this.finished)return;this.finished=!0;let{state:e,suffix:t,pos:n,blockLen:r}=this;e[n]^=t,t&128&&n===r-1&&this.keccak(),e[r-1]^=128,this.keccak()}writeInto(e){J(this,!1),q(e),this.finish();let t=this.state,{blockLen:n}=this;for(let r=0,i=e.length;r<i;){this.posOut>=n&&this.keccak();let a=Math.min(n-this.posOut,i-r);e.set(t.subarray(this.posOut,this.posOut+a),r),this.posOut+=a,r+=a}return e}xofInto(e){if(!this.enableXOF)throw Error(`XOF is not possible for this instance`);return this.writeInto(e)}xof(e){return K(e),this.xofInto(new Uint8Array(e))}digestInto(e){if(Ge(e,this),this.finished)throw Error(`digest() was already called`);return this.writeInto(e),this.destroy(),e}digest(){return this.digestInto(new Uint8Array(this.outputLen))}destroy(){this.destroyed=!0,Y(this.state)}_cloneInto(t){let{blockLen:n,suffix:r,outputLen:i,rounds:a,enableXOF:o}=this;return t||=new e(n,r,i,o,a),t.state32.set(this.state32),t.pos=this.pos,t.posOut=this.posOut,t.finished=this.finished,t.rounds=a,t.suffix=r,t.outputLen=i,t.enableXOF=o,t.destroyed=this.destroyed,t}},mt=((e,t,n)=>$e(()=>new pt(t,e,n)))(1,136,256/8);function ht(e){e=e.toLowerCase();let t=e.substring(2).split(``),n=new Uint8Array(40);for(let e=0;e<40;e++)n[e]=t[e].charCodeAt(0);let r=mt(n);for(let e=0;e<40;e+=2)r[e>>1]>>4>=8&&(t[e]=t[e].toUpperCase()),(r[e>>1]&15)>=8&&(t[e+1]=t[e+1].toUpperCase());return`0x`+t.join(``)}function gt(e){if(typeof e!=`string`)throw Error(`invalid address: ${e}`);if(e.match(/^(0x)?[0-9a-fA-F]{40}$/)){e.startsWith(`0x`)||(e=`0x`+e);let t=ht(e);if(e.match(/([A-F].*[a-f])|([a-f].*[A-F])/)&&t!==e)throw Error(`bad address checksum: ${e}`);return t}throw Error(`invalid address: ${e}`)}function _t(e){try{return gt(e),!0}catch{return!1}}function vt(e){return _t(e)?gt(e):e}var yt=o(((e,t)=>{t.exports=function(){throw Error(`ws does not work in the browser. Browser clients must use the native WebSocket object`)}})),$=(()=>{if(typeof window<`u`&&window.WebSocket)return window.WebSocket;if(typeof global<`u`)try{let e=yt();return e.WebSocket||e}catch(e){throw console.warn(`WebSocket library not found. Please install ws package for Node.js environment.`),e}else throw Error(`WebSocket is not available in this environment`)})(),bt=class e{account;verse;remoteUrl;auth;socket=null;eventSocket=null;connected=!1;listeners={};batchEmitter=null;pendingSubscriptions=[];eventSocketReady=!1;crossRampIntegration;pingInterval=null;socketPongTimeout=null;eventSocketPongTimeout=null;static randomAccount=(()=>{if(localStorage.getItem(`agent8:temporary_account`))return localStorage.getItem(`agent8:temporary_account`);let e=`anonymous-`+Math.random().toString(36).substring(2,15);return localStorage.setItem(`agent8:temporary_account`,e),e})();static instances=new Map;static getInitialVerse(e={}){if(d()){if(e.verse)return e.verse;let t=u(`AGENT8_VERSE`);return t?t+`-preview`:(console.warn(`[GameServer] VITE_AGENT8_VERSE is required for preview environment. Please set it in your .env file.`),`default`)}return e.verse||u(`AGENT8_VERSE`)||`default`}static getInitialAccount(t={}){return vt(t.account||new URLSearchParams(window.location.search).get(`account`)||window.location.hostname.startsWith(`agent8-container`)&&u(`AGENT8_ACCOUNT`)||e.randomAccount)}static getInitialRemoteUrl(e={}){return(e.remoteUrl||u(`AGENT8_REMOTE_URL`)||`https://verse8-game-backend-kr-609824224664.asia-northeast3.run.app`).replace(`https://`,`wss://`).replace(`http://`,`ws://`)}static getInitialAuth(e={}){return e.auth||new URLSearchParams(window.location.search).get(`auth`)||void 0}static getInstanceKey(t={}){return`${e.getInitialVerse(t)}:${e.getInitialAccount(t)}:${e.getInitialRemoteUrl(t)}`}static getInstance(t={}){let n=e.getInstanceKey(t);if(!e.instances.has(n)){let r=new e(t);e.instances.set(n,r)}return e.instances.get(n)}constructor(t={}){this.verse=e.getInitialVerse(t),this.account=e.getInitialAccount(t),this.remoteUrl=e.getInitialRemoteUrl(t),this.auth=e.getInitialAuth(t),this.crossRampIntegration=new Le(this.remoteUrl,this.verse,this.account,this.auth)}createWebSocket(e){let t=new $(e);return t.onopen=()=>{console.log(`WebSocket connection opened`)},t.onclose=()=>{console.log(`WebSocket connection closed`),this.disconnect()},t.onerror=e=>{console.warn(`WebSocket error:`,e)},t}sendMessage(e,t,n){if(e&&e.readyState===$.OPEN){if(e===this.eventSocket&&!this.eventSocketReady&&t!==`subscribeEvents`){this.pendingSubscriptions.push({event:t,data:n});return}e.send(H.compress(we({event:t,data:n})))}else e===this.eventSocket&&t!==`subscribeEvents`&&this.pendingSubscriptions.push({event:t,data:n})}async connect(t={}){t.verse&&(this.verse=t.verse),t.account&&(this.account=t.account),t.remoteUrl&&(this.remoteUrl=e.getInitialRemoteUrl({remoteUrl:t.remoteUrl})),t.auth!==void 0&&(this.auth=t.auth),this.crossRampIntegration.updateConfig(this.remoteUrl,this.verse,this.account,this.auth),console.log(`connect`,d(),this.verse,this.account,this.remoteUrl),this.socket&&this.socket.readyState===$.OPEN&&(this.socket.close(),this.socket=null),this.eventSocket&&this.eventSocket.readyState===$.OPEN&&(this.eventSocket.close(),this.eventSocket=null),this.connected=!1,this.socket=this.createWebSocket(this.remoteUrl),this.batchEmitter=new Ie(this.socket);async function n(e){return typeof e==`string`?JSON.parse(e):e instanceof Blob?Pe(H.decompress(new Uint8Array(await e.arrayBuffer()))):Pe(H.decompress(new Uint8Array(e)))}let r=async()=>new Promise(e=>{this.eventSocket.onmessage=async t=>{try{let r=await n(t.data);this.handleEventSocketMessage(r),r.event===`connected`&&(this.eventSocketReady=!0,this.pendingSubscriptions.length>0&&(this.pendingSubscriptions.forEach(({event:e,data:t})=>{this.sendMessage(this.eventSocket,e,t)}),this.pendingSubscriptions=[]),e(!0))}catch(e){console.warn(`Error parsing event socket message:`,e)}},this.eventSocket.onopen=()=>{this.sendMessage(this.eventSocket,`subscribeEvents`,{verse:this.verse,account:this.account,...this.auth&&{auth:this.auth}})},this.eventSocket.onclose=()=>{this.disconnect(),t.onDisconnect&&t.onDisconnect()},this.eventSocket.onerror=e=>{this.disconnect(),t.onError&&t.onError(e)}}),i=async()=>new Promise(e=>{this.socket.onmessage=async t=>{try{let r=await n(t.data);this.handleSocketMessage(r),r.event===`connected`?(console.log(`Connected to server`,this.verse,this.account),e(!0)):r.event===`notReady`&&(console.log(`Server is not ready`),e(!1))}catch(e){console.warn(`Error parsing socket message:`,e)}},this.socket.onopen=()=>{this.sendMessage(this.socket,`connectServer`,{verse:this.verse,account:this.account,...this.auth&&{auth:this.auth}})},this.socket.onclose=()=>{this.disconnect(),t.onDisconnect&&t.onDisconnect()},this.socket.onerror=e=>{this.disconnect(),t.onError&&t.onError(e)}});return this.connected=await i(),this.connected&&=(this.eventSocket=this.createWebSocket(this.remoteUrl),await r()),this.connected&&this.startPingPong(),this.connected}handleEventSocketMessage(e){let{event:t,data:n}=e;switch(t){case`connected`:this.emit(`connected`,n);break;case`pong`:this.eventSocketPongTimeout&&=(clearTimeout(this.eventSocketPongTimeout),null);break;case`global:state:changed`:this.emit(`global:state:changed`,JSON.parse(n.message));break;case`global:users:state:changed`:n.account===this.account&&this.emit(`global:me:state:changed`,JSON.parse(n.message)),this.emit(`global:users:${n.account}:state:changed`,JSON.parse(n.message));break;case`global:collections:changed`:this.emit(`global:collections:${n.collectionId}:changed`,JSON.parse(n.message));break;case`asset:changed`:try{let e=JSON.parse(n.message);this.emit(`asset:${n.account}:changed`,e)}catch(e){console.error(`[GameServer] Error parsing asset message:`,n.message,e)}break;case`global:message`:this.emit(`global:message:${n.type}`,JSON.parse(n.message));break;case`room:state:changed`:this.emit(`rooms:${n.roomId}:state:changed`,JSON.parse(n.message));break;case`room:users:state:changed`:n.account?this.emit(`rooms:${n.roomId}:users:${n.account}:state:changed`,JSON.parse(n.message)):this.emit(`rooms:${n.roomId}:users:state:changed`,JSON.parse(n.message));break;case`room:collections:changed`:this.emit(`rooms:${n.roomId}:collections:${n.collectionId}:changed`,JSON.parse(n.message));break;case`room:message`:this.emit(`rooms:${n.roomId}:message:${n.type}`,JSON.parse(n.message));break;case`batch`:for(let e of n)this.handleEventSocketMessage(e);break}}handleSocketMessage(e){let{event:t,data:n}=e;switch(t){case`connected`:case`notReady`:this.emit(t,n);break;case`pong`:this.socketPongTimeout&&=(clearTimeout(this.socketPongTimeout),null);break;case`batch`:for(let e of n)e.event?.startsWith(`fn:return:`)?this.emit(e.event,e.data):this.handleSocketMessage(e);break;default:t?.startsWith(`fn:return:`)&&this.emit(t,n);break}}async disconnect(){this.stopPingPong(),this.socket&&=(this.socket.close(),null),this.eventSocket&&=(this.eventSocket.close(),null),this.connected=!1,this.pendingSubscriptions=[],this.eventSocketReady=!1}startPingPong(){this.stopPingPong(),this.pingInterval=setInterval(()=>{this.socket&&this.socket.readyState===$.OPEN&&(this.sendMessage(this.socket,`ping`,{}),this.socketPongTimeout=setTimeout(()=>{console.warn(`Socket did not respond to ping within 3 seconds`),this.disconnect()},3e3)),this.eventSocket&&this.eventSocket.readyState===$.OPEN&&(this.sendMessage(this.eventSocket,`ping`,{}),this.eventSocketPongTimeout=setTimeout(()=>{console.warn(`Event socket did not respond to ping within 3 seconds`),this.disconnect()},3e3))},5e3)}stopPingPong(){this.pingInterval&&=(clearInterval(this.pingInterval),null),this.socketPongTimeout&&=(clearTimeout(this.socketPongTimeout),null),this.eventSocketPongTimeout&&=(clearTimeout(this.eventSocketPongTimeout),null)}subscribeGlobalState(e){let t=`global:state:changed`,n=`global:state:changed`,r=n=>{this.subscribeLastState[t]=n,e(n)};this.subscribeCount[t]?this.subscribeLastState[t]&&e(this.subscribeLastState[t]):this.sendMessage(this.eventSocket,n,{}),this.subscribeCount[t]=(this.subscribeCount[t]||0)+1;let i=this.on(t,r);return()=>{i(),this.subscribeCount[t]--,this.subscribeCount[t]===0&&this.sendMessage(this.eventSocket,n,{unsubscribe:!0})}}subscribeCount={};subscribeLastState={};subscribeGlobalMyState(e){return this.subscribeGlobalUserState(this.account,e)}subscribeGlobalUserState(e,t){if(!e)return console.warn(`subscribeGlobalUserState: account is required`),()=>{};let n=`global:users:${e}:state:changed`,r=`global:users:state:changed`,i=e=>{this.subscribeLastState[n]=e,t(e)};this.subscribeCount[n]?this.subscribeLastState[n]&&t(this.subscribeLastState[n]):this.sendMessage(this.eventSocket,r,{account:e}),this.subscribeCount[n]=(this.subscribeCount[n]||0)+1;let a=this.on(n,i);return()=>{a(),this.subscribeCount[n]--,this.subscribeCount[n]===0&&this.sendMessage(this.eventSocket,r,{account:e,unsubscribe:!0})}}subscribeGlobalCollection(e,t){if(!e)return console.warn(`subscribeGlobalCollection: collectionId is required`),()=>{};let n=`global:collections:${e}:changed`,r=`global:collections:changed`,i=({op:e,items:r})=>{this.subscribeLastState[n]||(this.subscribeLastState[n]=[]),e===`add`?U.addItems(this.subscribeLastState[n],r):e===`deleteAll`?this.subscribeLastState[n]=[]:e===`delete`?U.removeItems(this.subscribeLastState[n],r):e===`update`&&U.updateItems(this.subscribeLastState[n],r),t({items:this.subscribeLastState[n],changes:{op:e,items:r}})};this.subscribeCount[n]?this.subscribeLastState[n]&&t({items:this.subscribeLastState[n],changes:{op:`add`,items:this.subscribeLastState[n]}}):this.sendMessage(this.eventSocket,r,{collectionId:e}),this.subscribeCount[n]=(this.subscribeCount[n]||0)+1;let a=this.on(n,i);return()=>{a(),this.subscribeCount[n]--,this.subscribeCount[n]===0&&this.sendMessage(this.eventSocket,r,{collectionId:e,unsubscribe:!0})}}subscribeAsset(e,t){if(!e)return console.warn(`subscribeAsset: account is required`),()=>{};let n=`asset:${e}:changed`,r=`asset:changed`,i=e=>{this.subscribeLastState[n]=e,t(e)};this.subscribeCount[n]?this.subscribeLastState[n]&&t(this.subscribeLastState[n]):this.sendMessage(this.eventSocket,r,{account:e}),this.subscribeCount[n]=(this.subscribeCount[n]||0)+1;let a=this.on(n,i);return()=>{a(),this.subscribeCount[n]--,this.subscribeCount[n]===0&&this.sendMessage(this.eventSocket,r,{account:e,unsubscribe:!0})}}onGlobalMessage(e,t){if(!e)return console.warn(`onGlobalMessage: type is required`),()=>{};let n=this.on(`global:message:${e}`,t);return this.sendMessage(this.eventSocket,`global:message`,{type:e}),()=>{n(),this.sendMessage(this.eventSocket,`global:message`,{type:e,unsubscribe:!0})}}subscribeRoomState(e,t){if(!e)return console.warn(`subscribeRoomState: roomId is required`),()=>{};let n=`rooms:${e}:state:changed`,r=e=>{this.subscribeLastState[n]=e,t(e)};this.subscribeCount[n]?this.subscribeLastState[n]&&t(this.subscribeLastState[n]):this.sendMessage(this.eventSocket,`room:state:changed`,{roomId:e}),this.subscribeCount[n]=(this.subscribeCount[n]||0)+1;let i=this.on(n,r);return()=>{i(),this.subscribeCount[n]--,this.subscribeCount[n]===0&&this.sendMessage(this.eventSocket,`room:state:changed`,{roomId:e,unsubscribe:!0})}}subscribeRoomMyState(e,t){return this.subscribeRoomUserState(e,this.account,t)}subscribeRoomUserState(e,t,n){if(!e)return console.warn(`subscribeRoomUserState: roomId is required`),()=>{};if(!t)return console.warn(`subscribeRoomUserState: account is required`),()=>{};let r=`rooms:${e}:users:${t}:state:changed`,i=`room:users:state:changed`,a=e=>{this.subscribeLastState[r]=e,n(e)};this.subscribeCount[r]?this.subscribeLastState[r]&&n(this.subscribeLastState[r]):this.sendMessage(this.eventSocket,i,{roomId:e,account:t}),this.subscribeCount[r]=(this.subscribeCount[r]||0)+1;let o=this.on(r,a);return()=>{o(),this.subscribeCount[r]--,this.subscribeCount[r]===0&&this.sendMessage(this.eventSocket,i,{roomId:e,account:t,unsubscribe:!0})}}subscribeRoomAllUserStates(e,t){if(!e)return console.warn(`subscribeRoomAllUserStates: roomId is required`),()=>{};let n=`rooms:${e}:users:state:changed`,r=e=>{this.subscribeLastState[n]||(this.subscribeLastState[n]=[]);let r={};for(let e of this.subscribeLastState[n])delete e.updated,r[e.account]=e;for(let t of e)t.__leaved?delete r[t.account]:r[t.account]={...t,account:t.account,__updated:!0};let i=Object.values(r);this.subscribeLastState[n]=i,t(i)};this.subscribeCount[n]?this.subscribeLastState[n]&&t(this.subscribeLastState[n]):this.sendMessage(this.eventSocket,`room:users:state:changed`,{roomId:e}),this.subscribeCount[n]=(this.subscribeCount[n]||0)+1;let i=this.on(n,r);return()=>{i(),this.subscribeCount[n]--,this.subscribeCount[n]===0&&this.sendMessage(this.eventSocket,`room:users:state:changed`,{roomId:e,unsubscribe:!0})}}subscribeRoomCollection(e,t,n){if(!e)return console.warn(`subscribeRoomCollection: roomId is required`),()=>{};if(!t)return console.warn(`subscribeRoomCollection: collectionId is required`),()=>{};let r=`rooms:${e}:collections:${t}:changed`,i=({op:e,items:t})=>{this.subscribeLastState[r]||(this.subscribeLastState[r]=[]),e===`add`?U.addItems(this.subscribeLastState[r],t):e===`deleteAll`?this.subscribeLastState[r]=[]:e===`delete`?U.removeItems(this.subscribeLastState[r],t):e===`update`&&U.updateItems(this.subscribeLastState[r],t),n({items:this.subscribeLastState[r],changes:{op:e,items:t}})};this.subscribeCount[r]?this.subscribeLastState[r]&&n({items:this.subscribeLastState[r],changes:{op:`add`,items:this.subscribeLastState[r]}}):this.sendMessage(this.eventSocket,`room:collections:changed`,{collectionId:t,roomId:e}),this.subscribeCount[r]=(this.subscribeCount[r]||0)+1;let a=this.on(r,i);return()=>{a(),this.subscribeCount[r]--,this.subscribeCount[r]===0&&this.sendMessage(this.eventSocket,`room:collections:changed`,{roomId:e,collectionId:t,unsubscribe:!0})}}onRoomUserJoin(e,t){return this.onRoomMessage(e,`$JOIN`,e=>{t(e.account)})}onRoomUserLeave(e,t){return this.onRoomMessage(e,`$LEAVE`,e=>{t(e.account)})}onRoomMessage(e,t,n){if(!e)return console.warn(`onRoomMessage: roomId is required`),()=>{};if(!t)return console.warn(`onRoomMessage: type is required`),()=>{};let r=this.on(`rooms:${e}:message:${t}`,n);return this.sendMessage(this.eventSocket,`room:message`,{roomId:e,type:t}),()=>{r(),this.sendMessage(this.eventSocket,`room:message`,{roomId:e,type:t,unsubscribe:!0})}}callTimestamps={};throttledFunctions={};async remoteFunction(e,t=[],{needResponse:n,throttle:r,throttleKey:i}={}){if(t=JSON.parse(JSON.stringify(t,(e,t)=>t===void 0?`__undefined__`:t)),typeof r==`number`){r<30&&(r=30);let a=i?`${e}:${i}`:e;n=!1,this.throttledFunctions[a]||(this.throttledFunctions[a]=(0,Fe.default)(e=>{this.batchEmitter.emit(e)},r,{leading:!0,trailing:!1}));let o=Math.random().toString(36).substring(2,15);return this.throttledFunctions[a]({callId:o,fn:e,args:t,needResponse:!1}),Promise.resolve(null)}else{let r=Date.now();return this.callTimestamps[e]||(this.callTimestamps[e]=[]),this.callTimestamps[e]=this.callTimestamps[e].filter(e=>r-e<1e3),this.callTimestamps[e].length>=10?Promise.reject(Error(`Too many calls to the function. Use throttle option.`)):(this.callTimestamps[e].push(r),new Promise((r,i)=>{let a=Math.random().toString(36).substring(2,15),o;this.batchEmitter.emit({callId:a,fn:e,args:t,needResponse:n}),n===!1?r(null):o=this.on(`fn:return:`+a,e=>{o(),e.error?i(e.error):r(e.result)})}))}}on(e,t){return t?(this.listeners[e]||(this.listeners[e]=[]),this.listeners[e].push(t),()=>{this.listeners[e]=this.listeners[e].filter(e=>e!==t)}):()=>{}}emit(e,t){if(this.listeners[e])for(let n of this.listeners[e])n(t)}async getCrossRampShopUrl(e=`en`){return this.crossRampIntegration.getShopUrl(e)}async getCrossRampForgeUrl(e=`en`){return this.crossRampIntegration.getForgeUrl(e)}};export{bt as GameServer,s as t};
@@ -1 +0,0 @@
1
- import{i as e,n as t}from"./index-QEwr2eXD.js";async function n(e,n){return new a((await t(()=>import(`./GameServer-C56iOUgF.js`),[],import.meta.url)).GameServer,e,{diagnostics:n})}var r=[500,1e3,2e3,4e3,8e3],i=8,a=class{raw;active=new Map;reconnecting=!1;disposed=!1;diagnostics;wait;constructor(e,t,n){this.diagnostics=n?.diagnostics??null,this.wait=n?.wait??(e=>new Promise(t=>{setTimeout(t,e)})),this.raw=new e({...t})}get account(){return this.raw.account}get connected(){return this.raw.connected}connect(){return this.raw.connected?Promise.resolve(!0):(this.disposed=!1,this.rawConnect())}rawConnect(){return this.raw.connect({onDisconnect:()=>void this.reconnect()})}disconnect(){this.disposed=!0;for(let e of this.active.values())e.off();return this.active.clear(),this.raw.disconnect()}remoteFunction(e,t,n){return this.raw.remoteFunction(e,t,n)}track(e){let t=Symbol(`sub`),n={make:e,off:e()};return this.active.set(t,n),()=>{n.off(),this.active.delete(t)}}async reconnect(){if(!this.disposed&&!this.reconnecting){this.reconnecting=!0;try{for(let t=0;t<i;t++){let n=!1,i=null;try{n=await this.rawConnect()!==!1}catch(e){i=e}if(this.disposed)return;if(n){for(let e of this.active.values())e.off(),e.off=e.make();t>0&&e(this.diagnostics,`info`,`[incanto] multiplayer reconnected after ${t+1} attempts.`);return}t===0&&e(this.diagnostics,`warn`,`[incanto] the multiplayer connection dropped and the server would not take it back${i?` (${i instanceof Error?i.message:String(i)})`:``}. Retrying — other players cannot see this one until it comes back.`);let a=r[Math.min(t,r.length-1)]??8e3;if(await this.wait(a),this.disposed)return}e(this.diagnostics,`error`,`[incanto] multiplayer gave up after ${i} reconnect attempts — this client is offline and the others cannot see it. Call connect() again to retry.`)}finally{this.reconnecting=!1}}}subscribeRoomState(e,t){return this.track(()=>this.raw.subscribeRoomState(e,t))}subscribeRoomMyState(e,t){return this.track(()=>this.raw.subscribeRoomMyState(e,t))}subscribeRoomAllUserStates(e,t){return this.track(()=>this.raw.subscribeRoomAllUserStates(e,e=>{let n={};for(let t of e??[]){if(!t||typeof t.account!=`string`||t.__leaved)continue;let{account:e,__updated:r,__leaved:i,...a}=t;n[e]=a}t(n)}))}subscribeRoomCollection(e,t,n){return this.track(()=>this.raw.subscribeRoomCollection(e,t,({items:e})=>{let t={};for(let n of e??[])n&&typeof n.__id==`string`&&(t[n.__id]=n);n(t)}))}onRoomMessage(e,t,n){return this.track(()=>this.raw.onRoomMessage(e,t,n))}onRoomUserJoin(e,t){return this.track(()=>this.raw.onRoomUserJoin(e,t))}onRoomUserLeave(e,t){return this.track(()=>this.raw.onRoomUserLeave(e,t))}subscribeGlobalState(e){return this.track(()=>this.raw.subscribeGlobalState(e))}subscribeGlobalMyState(e){return this.track(()=>this.raw.subscribeGlobalMyState(e))}subscribeGlobalUserState(e,t){return this.track(()=>this.raw.subscribeGlobalUserState(e,t))}subscribeGlobalCollection(e,t){return this.track(()=>this.raw.subscribeGlobalCollection(e,({items:e})=>{let n={};for(let t of e??[])t&&typeof t.__id==`string`&&(n[t.__id]=t);t(n)}))}subscribeAsset(e,t){return this.track(()=>this.raw.subscribeAsset(e,t))}onGlobalMessage(e,t){return this.track(()=>this.raw.onGlobalMessage(e,t))}};export{n as createAgent8Server};