@crowdedkingdoms/crowdyjs 17.14.0-dev.1 → 18.0.1-dev.1

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.
Files changed (289) hide show
  1. package/MIGRATION.md +129 -1
  2. package/README.md +97 -164
  3. package/dist/crowdy-client.d.ts +12 -31
  4. package/dist/crowdy-client.d.ts.map +1 -1
  5. package/dist/crowdy-client.js +15 -37
  6. package/dist/crowdy-dsh/bridge.d.ts.map +1 -1
  7. package/dist/crowdy-dsh/bridge.js +3 -6
  8. package/dist/crowdy-studio/controller.d.ts +34 -59
  9. package/dist/crowdy-studio/controller.d.ts.map +1 -1
  10. package/dist/crowdy-studio/controller.js +96 -225
  11. package/dist/crowdy-studio/diagnostics.d.ts +3 -12
  12. package/dist/crowdy-studio/diagnostics.d.ts.map +1 -1
  13. package/dist/crowdy-studio/dom-shell.d.ts +2 -4
  14. package/dist/crowdy-studio/dom-shell.d.ts.map +1 -1
  15. package/dist/crowdy-studio/dom-shell.js +16 -49
  16. package/dist/crowdy-studio/embed/hud-layer.d.ts +1 -2
  17. package/dist/crowdy-studio/embed/hud-layer.d.ts.map +1 -1
  18. package/dist/crowdy-studio/embed/panel.d.ts +3 -13
  19. package/dist/crowdy-studio/embed/panel.d.ts.map +1 -1
  20. package/dist/crowdy-studio/embed/panel.js +3 -6
  21. package/dist/crowdy-studio/index.d.ts +1 -3
  22. package/dist/crowdy-studio/index.d.ts.map +1 -1
  23. package/dist/crowdy-studio/index.js +0 -2
  24. package/dist/crowdy-studio/models.d.ts +3 -4
  25. package/dist/crowdy-studio/models.d.ts.map +1 -1
  26. package/dist/crowdy-studio/starter-projects.d.ts +8 -12
  27. package/dist/crowdy-studio/starter-projects.d.ts.map +1 -1
  28. package/dist/crowdy-studio/starter-projects.js +12 -103
  29. package/dist/domains/appAccess.d.ts +14 -1
  30. package/dist/domains/appAccess.d.ts.map +1 -1
  31. package/dist/domains/appAccess.js +37 -1
  32. package/dist/domains/apps.d.ts +1 -10
  33. package/dist/domains/apps.d.ts.map +1 -1
  34. package/dist/domains/apps.js +1 -16
  35. package/dist/domains/host.d.ts +3 -3
  36. package/dist/domains/host.js +3 -3
  37. package/dist/domains/hosting.d.ts +0 -6
  38. package/dist/domains/hosting.d.ts.map +1 -1
  39. package/dist/domains/hosting.js +1 -16
  40. package/dist/domains/marketplace.d.ts +9 -70
  41. package/dist/domains/marketplace.d.ts.map +1 -1
  42. package/dist/domains/marketplace.js +9 -120
  43. package/dist/domains/organizations.d.ts +1 -9
  44. package/dist/domains/organizations.d.ts.map +1 -1
  45. package/dist/domains/organizations.js +1 -15
  46. package/dist/domains/payments.d.ts +5 -48
  47. package/dist/domains/payments.d.ts.map +1 -1
  48. package/dist/domains/payments.js +5 -57
  49. package/dist/domains/playerWallet.d.ts +6 -12
  50. package/dist/domains/playerWallet.d.ts.map +1 -1
  51. package/dist/domains/playerWallet.js +6 -21
  52. package/dist/domains/quotas.d.ts +20 -7
  53. package/dist/domains/quotas.d.ts.map +1 -1
  54. package/dist/domains/quotas.js +15 -6
  55. package/dist/domains/users.d.ts +7 -74
  56. package/dist/domains/users.d.ts.map +1 -1
  57. package/dist/domains/users.js +7 -105
  58. package/dist/errors.d.ts +7 -13
  59. package/dist/errors.d.ts.map +1 -1
  60. package/dist/errors.js +6 -10
  61. package/dist/generated/graphql.d.ts +955 -8272
  62. package/dist/generated/graphql.d.ts.map +1 -1
  63. package/dist/generated/graphql.js +5 -329
  64. package/dist/grid-mods/exec-client-halves.d.ts +19 -3
  65. package/dist/grid-mods/exec-client-halves.d.ts.map +1 -1
  66. package/dist/grid-mods/exec-client-halves.js +17 -2
  67. package/dist/grid-mods/grid-host-calls.d.ts +29 -17
  68. package/dist/grid-mods/grid-host-calls.d.ts.map +1 -1
  69. package/dist/grid-mods/grid-host-calls.js +40 -46
  70. package/dist/grid-mods/mod-runtime.d.ts +18 -11
  71. package/dist/grid-mods/mod-runtime.d.ts.map +1 -1
  72. package/dist/grid-mods/mod-runtime.js +4 -2
  73. package/dist/grid-scope.d.ts +0 -189
  74. package/dist/grid-scope.d.ts.map +1 -1
  75. package/dist/grid-scope.js +0 -70
  76. package/dist/index.d.ts +12 -18
  77. package/dist/index.d.ts.map +1 -1
  78. package/dist/index.js +10 -16
  79. package/dist/kit/actions.d.ts +5 -9
  80. package/dist/kit/actions.d.ts.map +1 -1
  81. package/dist/kit/actions.js +5 -9
  82. package/dist/kit/index.d.ts +2 -33
  83. package/dist/kit/index.d.ts.map +1 -1
  84. package/dist/kit/index.js +1 -32
  85. package/dist/kit/kit.d.ts +8 -208
  86. package/dist/kit/kit.d.ts.map +1 -1
  87. package/dist/kit/kit.js +5 -163
  88. package/dist/kit/social.d.ts +1 -3
  89. package/dist/kit/social.d.ts.map +1 -1
  90. package/dist/kit/social.js +1 -3
  91. package/dist/kit/wire.d.ts +16 -5
  92. package/dist/kit/wire.d.ts.map +1 -1
  93. package/dist/kit/wire.js +19 -5
  94. package/dist/live-coding/assets/browser-authoring-index.json +1 -1
  95. package/dist/live-coding/assets/manifest.json +1 -1
  96. package/dist/live-coding/browser-authoring-index.generated.d.ts.map +1 -1
  97. package/dist/live-coding/browser-authoring-index.generated.js +1496 -4386
  98. package/dist/live-coding/rust-analysis.d.ts.map +1 -1
  99. package/dist/live-coding/rust-analysis.js +30 -34
  100. package/dist/player-runtime/client-host-calls.d.ts +8 -0
  101. package/dist/player-runtime/client-host-calls.d.ts.map +1 -0
  102. package/dist/player-runtime/client-host-calls.js +28 -0
  103. package/dist/player-runtime/glue-runtime.d.ts +24 -20
  104. package/dist/player-runtime/glue-runtime.d.ts.map +1 -1
  105. package/dist/player-runtime/glue-runtime.js +26 -55
  106. package/dist/player-runtime/glue-sab.d.ts +2 -2
  107. package/dist/player-runtime/glue-sab.js +2 -2
  108. package/dist/player-runtime/player-code-broker.d.ts +70 -43
  109. package/dist/player-runtime/player-code-broker.d.ts.map +1 -1
  110. package/dist/player-runtime/player-code-broker.js +159 -64
  111. package/dist/player-runtime/player-glue-worker.d.ts +8 -9
  112. package/dist/player-runtime/player-glue-worker.d.ts.map +1 -1
  113. package/dist/player-runtime/player-glue-worker.js +26 -11
  114. package/dist/stores/inbox.d.ts +1 -1
  115. package/dist/stores/inbox.d.ts.map +1 -1
  116. package/dist/stores/index.d.ts +0 -11
  117. package/dist/stores/index.d.ts.map +1 -1
  118. package/dist/stores/index.js +0 -4
  119. package/dist/stores/session.d.ts +0 -2
  120. package/dist/stores/session.d.ts.map +1 -1
  121. package/package.json +1 -1
  122. package/dist/crowdy-studio/model-lint-log.d.ts +0 -76
  123. package/dist/crowdy-studio/model-lint-log.d.ts.map +0 -1
  124. package/dist/crowdy-studio/model-lint-log.js +0 -93
  125. package/dist/crowdy-studio/model-lint.d.ts +0 -61
  126. package/dist/crowdy-studio/model-lint.d.ts.map +0 -1
  127. package/dist/crowdy-studio/model-lint.js +0 -45
  128. package/dist/domains/compute.d.ts +0 -208
  129. package/dist/domains/compute.d.ts.map +0 -1
  130. package/dist/domains/compute.js +0 -274
  131. package/dist/domains/controlPlane.d.ts +0 -38
  132. package/dist/domains/controlPlane.d.ts.map +0 -1
  133. package/dist/domains/controlPlane.js +0 -43
  134. package/dist/domains/gameModel.d.ts +0 -1174
  135. package/dist/domains/gameModel.d.ts.map +0 -1
  136. package/dist/domains/gameModel.js +0 -1333
  137. package/dist/domains/playerCompute.d.ts +0 -91
  138. package/dist/domains/playerCompute.d.ts.map +0 -1
  139. package/dist/domains/playerCompute.js +0 -136
  140. package/dist/domains/playerModel.d.ts +0 -20
  141. package/dist/domains/playerModel.d.ts.map +0 -1
  142. package/dist/domains/playerModel.js +0 -54
  143. package/dist/kit/abilities.d.ts +0 -66
  144. package/dist/kit/abilities.d.ts.map +0 -1
  145. package/dist/kit/abilities.js +0 -71
  146. package/dist/kit/blueprints/combat.d.ts +0 -81
  147. package/dist/kit/blueprints/combat.d.ts.map +0 -1
  148. package/dist/kit/blueprints/combat.js +0 -357
  149. package/dist/kit/blueprints/core.d.ts +0 -222
  150. package/dist/kit/blueprints/core.d.ts.map +0 -1
  151. package/dist/kit/blueprints/core.js +0 -185
  152. package/dist/kit/blueprints/decks.d.ts +0 -50
  153. package/dist/kit/blueprints/decks.d.ts.map +0 -1
  154. package/dist/kit/blueprints/decks.js +0 -163
  155. package/dist/kit/blueprints/economy.d.ts +0 -88
  156. package/dist/kit/blueprints/economy.d.ts.map +0 -1
  157. package/dist/kit/blueprints/economy.js +0 -533
  158. package/dist/kit/blueprints/guild.d.ts +0 -51
  159. package/dist/kit/blueprints/guild.d.ts.map +0 -1
  160. package/dist/kit/blueprints/guild.js +0 -50
  161. package/dist/kit/blueprints/index.d.ts +0 -23
  162. package/dist/kit/blueprints/index.d.ts.map +0 -1
  163. package/dist/kit/blueprints/index.js +0 -22
  164. package/dist/kit/blueprints/inventory.d.ts +0 -84
  165. package/dist/kit/blueprints/inventory.d.ts.map +0 -1
  166. package/dist/kit/blueprints/inventory.js +0 -257
  167. package/dist/kit/blueprints/leaderboards.d.ts +0 -49
  168. package/dist/kit/blueprints/leaderboards.d.ts.map +0 -1
  169. package/dist/kit/blueprints/leaderboards.js +0 -126
  170. package/dist/kit/blueprints/liveops.d.ts +0 -42
  171. package/dist/kit/blueprints/liveops.d.ts.map +0 -1
  172. package/dist/kit/blueprints/liveops.js +0 -170
  173. package/dist/kit/blueprints/locks.d.ts +0 -82
  174. package/dist/kit/blueprints/locks.d.ts.map +0 -1
  175. package/dist/kit/blueprints/locks.js +0 -155
  176. package/dist/kit/blueprints/loot.d.ts +0 -90
  177. package/dist/kit/blueprints/loot.d.ts.map +0 -1
  178. package/dist/kit/blueprints/loot.js +0 -229
  179. package/dist/kit/blueprints/matches.d.ts +0 -84
  180. package/dist/kit/blueprints/matches.d.ts.map +0 -1
  181. package/dist/kit/blueprints/matches.js +0 -349
  182. package/dist/kit/blueprints/moderation.d.ts +0 -32
  183. package/dist/kit/blueprints/moderation.d.ts.map +0 -1
  184. package/dist/kit/blueprints/moderation.js +0 -140
  185. package/dist/kit/blueprints/npcs.d.ts +0 -78
  186. package/dist/kit/blueprints/npcs.d.ts.map +0 -1
  187. package/dist/kit/blueprints/npcs.js +0 -125
  188. package/dist/kit/blueprints/plots.d.ts +0 -63
  189. package/dist/kit/blueprints/plots.d.ts.map +0 -1
  190. package/dist/kit/blueprints/plots.js +0 -151
  191. package/dist/kit/blueprints/progression.d.ts +0 -68
  192. package/dist/kit/blueprints/progression.d.ts.map +0 -1
  193. package/dist/kit/blueprints/progression.js +0 -324
  194. package/dist/kit/blueprints/quests.d.ts +0 -72
  195. package/dist/kit/blueprints/quests.d.ts.map +0 -1
  196. package/dist/kit/blueprints/quests.js +0 -285
  197. package/dist/kit/blueprints/worldsim.d.ts +0 -91
  198. package/dist/kit/blueprints/worldsim.d.ts.map +0 -1
  199. package/dist/kit/blueprints/worldsim.js +0 -468
  200. package/dist/kit/combat.d.ts +0 -141
  201. package/dist/kit/combat.d.ts.map +0 -1
  202. package/dist/kit/combat.js +0 -196
  203. package/dist/kit/decks.d.ts +0 -157
  204. package/dist/kit/decks.d.ts.map +0 -1
  205. package/dist/kit/decks.js +0 -186
  206. package/dist/kit/director.d.ts +0 -88
  207. package/dist/kit/director.d.ts.map +0 -1
  208. package/dist/kit/director.js +0 -86
  209. package/dist/kit/economy.d.ts +0 -289
  210. package/dist/kit/economy.d.ts.map +0 -1
  211. package/dist/kit/economy.js +0 -427
  212. package/dist/kit/engine.d.ts +0 -48
  213. package/dist/kit/engine.d.ts.map +0 -1
  214. package/dist/kit/engine.js +0 -113
  215. package/dist/kit/features.d.ts +0 -60
  216. package/dist/kit/features.d.ts.map +0 -1
  217. package/dist/kit/features.js +0 -65
  218. package/dist/kit/instances.d.ts +0 -52
  219. package/dist/kit/instances.d.ts.map +0 -1
  220. package/dist/kit/instances.js +0 -60
  221. package/dist/kit/inventory.d.ts +0 -129
  222. package/dist/kit/inventory.d.ts.map +0 -1
  223. package/dist/kit/inventory.js +0 -200
  224. package/dist/kit/leaderboards.d.ts +0 -86
  225. package/dist/kit/leaderboards.d.ts.map +0 -1
  226. package/dist/kit/leaderboards.js +0 -133
  227. package/dist/kit/liveops.d.ts +0 -112
  228. package/dist/kit/liveops.d.ts.map +0 -1
  229. package/dist/kit/liveops.js +0 -183
  230. package/dist/kit/loot.d.ts +0 -128
  231. package/dist/kit/loot.d.ts.map +0 -1
  232. package/dist/kit/loot.js +0 -160
  233. package/dist/kit/matches.d.ts +0 -301
  234. package/dist/kit/matches.d.ts.map +0 -1
  235. package/dist/kit/matches.js +0 -458
  236. package/dist/kit/matchmaking.d.ts +0 -57
  237. package/dist/kit/matchmaking.d.ts.map +0 -1
  238. package/dist/kit/matchmaking.js +0 -59
  239. package/dist/kit/minigames.d.ts +0 -30
  240. package/dist/kit/minigames.d.ts.map +0 -1
  241. package/dist/kit/minigames.js +0 -38
  242. package/dist/kit/mobs.d.ts +0 -90
  243. package/dist/kit/mobs.d.ts.map +0 -1
  244. package/dist/kit/mobs.js +0 -98
  245. package/dist/kit/moderation.d.ts +0 -73
  246. package/dist/kit/moderation.d.ts.map +0 -1
  247. package/dist/kit/moderation.js +0 -103
  248. package/dist/kit/movement.d.ts +0 -78
  249. package/dist/kit/movement.d.ts.map +0 -1
  250. package/dist/kit/movement.js +0 -103
  251. package/dist/kit/notifications.d.ts +0 -45
  252. package/dist/kit/notifications.d.ts.map +0 -1
  253. package/dist/kit/notifications.js +0 -67
  254. package/dist/kit/npcs.d.ts +0 -226
  255. package/dist/kit/npcs.d.ts.map +0 -1
  256. package/dist/kit/npcs.js +0 -141
  257. package/dist/kit/objects.d.ts +0 -116
  258. package/dist/kit/objects.d.ts.map +0 -1
  259. package/dist/kit/objects.js +0 -119
  260. package/dist/kit/pets.d.ts +0 -85
  261. package/dist/kit/pets.d.ts.map +0 -1
  262. package/dist/kit/pets.js +0 -96
  263. package/dist/kit/plots.d.ts +0 -85
  264. package/dist/kit/plots.d.ts.map +0 -1
  265. package/dist/kit/plots.js +0 -113
  266. package/dist/kit/progression.d.ts +0 -181
  267. package/dist/kit/progression.d.ts.map +0 -1
  268. package/dist/kit/progression.js +0 -265
  269. package/dist/kit/quests.d.ts +0 -171
  270. package/dist/kit/quests.d.ts.map +0 -1
  271. package/dist/kit/quests.js +0 -237
  272. package/dist/kit/racing.d.ts +0 -85
  273. package/dist/kit/racing.d.ts.map +0 -1
  274. package/dist/kit/racing.js +0 -99
  275. package/dist/kit/shared.d.ts +0 -73
  276. package/dist/kit/shared.d.ts.map +0 -1
  277. package/dist/kit/shared.js +0 -101
  278. package/dist/kit/telemetry.d.ts +0 -66
  279. package/dist/kit/telemetry.d.ts.map +0 -1
  280. package/dist/kit/telemetry.js +0 -133
  281. package/dist/kit/territory.d.ts +0 -97
  282. package/dist/kit/territory.d.ts.map +0 -1
  283. package/dist/kit/territory.js +0 -114
  284. package/dist/kit/worldsim.d.ts +0 -263
  285. package/dist/kit/worldsim.d.ts.map +0 -1
  286. package/dist/kit/worldsim.js +0 -268
  287. package/dist/stores/model.d.ts +0 -81
  288. package/dist/stores/model.d.ts.map +0 -1
  289. package/dist/stores/model.js +0 -163
@@ -1 +0,0 @@
1
- {"version":3,"file":"territory.d.ts","sourceRoot":"","sources":["../../src/kit/territory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,EAA0B,KAAK,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAE3E,wCAAwC;AACxC,MAAM,WAAW,mBAAmB;IAClC,mEAAmE;IACnE,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,gDAAgD;AAChD,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,MAAM,CAAC;IAChB,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,M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AC,EAAE,MAAM,CAAC;QACpB,WAAW,CAAC,EAAE,MAAM,CAAC;KACtB;;;;;;;;;;;IA0BD,0DAA0D;IAC1D,iBAAiB,CAAC,KAAK,EAAE,UAAU,GAAG,iBAAiB,GAAG,IAAI;YAIhD,MAAM;CAOrB"}
@@ -1,114 +0,0 @@
1
- import { parseControlPointEvent } from './wire.js';
2
- /**
3
- * Runtime helpers for the territory engine (Wave 3): control-point state,
4
- * faction standings, and the admin CRUD for the map (factions, members,
5
- * points). Capture itself is pure presence — stand inside a point's radius
6
- * with your faction; the engine does the rest and announces flips as
7
- * type-96 events.
8
- *
9
- * Obtained via `client.kit(appId).territory`.
10
- */
11
- export class TerritoryKit {
12
- constructor(appId, gameModel, engines, options = {}) {
13
- this.appId = appId;
14
- this.gameModel = gameModel;
15
- this.engines = engines;
16
- this.moduleName = options.moduleName ?? 'territory';
17
- }
18
- /** Is the territory engine deployed + enabled (cached per session)? */
19
- engineAvailable() {
20
- return this.engines.has(this.moduleName);
21
- }
22
- /** Every control point with live capture state. */
23
- async points() {
24
- const body = await this.invoke('points', {});
25
- return Array.isArray(body.points)
26
- ? body.points.map((p) => ({
27
- pointId: String(p.pointId ?? ''),
28
- x: Number(p.x ?? 0),
29
- z: Number(p.z ?? 0),
30
- radius: Number(p.radius ?? 0),
31
- owner: String(p.owner ?? ''),
32
- challenger: String(p.challenger ?? ''),
33
- progress: Number(p.progress ?? 0),
34
- incomePerMin: Number(p.incomePerMin ?? 0),
35
- siegeOpen: p.siegeOpen === true,
36
- }))
37
- : [];
38
- }
39
- /** Faction standings (id + treasury). */
40
- async factions() {
41
- const body = await this.invoke('factions', {});
42
- return Array.isArray(body.factions)
43
- ? body.factions.map((f) => ({
44
- factionId: String(f.factionId ?? ''),
45
- gold: Number(f.gold ?? 0),
46
- }))
47
- : [];
48
- }
49
- /** Engine totals (flips, income paid). */
50
- async status() {
51
- return this.invoke('status', {});
52
- }
53
- /** STUDIO (admin) — create a faction. */
54
- async defineFaction(factionId, displayName) {
55
- return this.gameModel.createContainer({
56
- appId: this.appId,
57
- typeName: 'Faction',
58
- displayName: displayName ?? `faction-${factionId}`,
59
- properties: [
60
- { key: 'faction_id', valueType: 'string', valueJson: JSON.stringify(factionId) },
61
- { key: 'gold', valueType: 'int', valueJson: '0' },
62
- ],
63
- });
64
- }
65
- /** STUDIO (admin) — enroll a player in a faction. */
66
- async enroll(userId, factionId) {
67
- return this.gameModel.createContainer({
68
- appId: this.appId,
69
- typeName: 'FactionMember',
70
- displayName: `member-${userId}`,
71
- properties: [
72
- { key: 'user_id', valueType: 'string', valueJson: JSON.stringify(userId) },
73
- { key: 'faction_id', valueType: 'string', valueJson: JSON.stringify(factionId) },
74
- ],
75
- });
76
- }
77
- /** STUDIO (admin) — create a control point. */
78
- async definePoint(input) {
79
- return this.gameModel.createContainer({
80
- appId: this.appId,
81
- typeName: 'ControlPoint',
82
- displayName: input.displayName ?? `cp-${input.pointId}`,
83
- properties: [
84
- { key: 'point_id', valueType: 'string', valueJson: JSON.stringify(input.pointId) },
85
- { key: 'x', valueType: 'int', valueJson: String(Math.round(input.x)) },
86
- { key: 'z', valueType: 'int', valueJson: String(Math.round(input.z)) },
87
- { key: 'radius', valueType: 'int', valueJson: String(Math.round(input.radius)) },
88
- { key: 'owner_faction', valueType: 'string', valueJson: '""' },
89
- {
90
- key: 'income_per_min',
91
- valueType: 'int',
92
- valueJson: String(input.incomePerMin ?? 0),
93
- },
94
- ...(input.siegeFromMin !== undefined
95
- ? [{ key: 'siege_from_min', valueType: 'int', valueJson: String(input.siegeFromMin) }]
96
- : []),
97
- ...(input.siegeToMin !== undefined
98
- ? [{ key: 'siege_to_min', valueType: 'int', valueJson: String(input.siegeToMin) }]
99
- : []),
100
- ],
101
- });
102
- }
103
- /** Parse a type-96 control-point server event (flips). */
104
- parseControlPoint(bytes) {
105
- return parseControlPointEvent(bytes);
106
- }
107
- async invoke(exportName, params) {
108
- const result = await this.engines.invoke(this.moduleName, exportName, params);
109
- if (!result.success) {
110
- throw new Error(`territory.${exportName} failed: ${result.reason ?? 'unknown'}`);
111
- }
112
- return result.body;
113
- }
114
- }
@@ -1,263 +0,0 @@
1
- import type { GameModelAPI } from '../domains/gameModel.js';
2
- import type { Scalars, SeedPropertyInput } from '../generated/graphql.js';
3
- import type { EngineDetector } from './engine.js';
4
- import { type KitInvokeResult } from './shared.js';
5
- import { type WeatherEvent } from './wire.js';
6
- /** Options for {@link WorldsimKit}. Must match the deployed worldsim blueprint. */
7
- export interface WorldsimKitOptions {
8
- /** The `typePrefix` the worldsim blueprint was deployed with. */
9
- typePrefix?: string;
10
- /**
11
- * The compute module serving `forecast` when the app runs a world engine.
12
- * Defaults to `'world-engine'`.
13
- */
14
- moduleName?: string;
15
- }
16
- /** A world engine's forecast (current front + day phase). */
17
- export interface KitForecast {
18
- weather: string;
19
- /** Day phase in [0, 1) when the engine reports it. */
20
- dayPhase?: number;
21
- isNight?: boolean;
22
- /** Milliseconds until the current front rolls. */
23
- remainingMs?: number;
24
- body: Record<string, unknown>;
25
- }
26
- /** A parsed view of the world clock/weather state. */
27
- export interface KitWorldState {
28
- containerId: string;
29
- timeOfDay: number;
30
- day: number;
31
- weather: string;
32
- }
33
- /** A parsed view of one resource node. */
34
- export interface KitResourceNode {
35
- containerId: string;
36
- displayName: string;
37
- nodeId: string;
38
- resourceItemId: string;
39
- amount: number;
40
- maxAmount: number;
41
- regenRate: number;
42
- x: number;
43
- y: number;
44
- z: number;
45
- }
46
- /** A parsed view of one crop / production job. */
47
- export interface KitCrop {
48
- containerId: string;
49
- displayName: string;
50
- ownerUserId: string | null;
51
- stage: number;
52
- maxStage: number;
53
- outputItemId: string;
54
- outputQty: number;
55
- ready: boolean;
56
- }
57
- /** A parsed view of one wave spawner. */
58
- export interface KitWaveSpawner {
59
- containerId: string;
60
- displayName: string;
61
- wave: number;
62
- nextWaveSize: number;
63
- }
64
- /**
65
- * Runtime helpers for the {@link worldsimBlueprint} conventions: the world
66
- * clock/weather singleton, regenerating resource nodes players gather from,
67
- * crops that mature server-side, and wave counters the host reads. The
68
- * simulation itself runs in automations — these helpers create/read state
69
- * and drive the player-facing functions.
70
- *
71
- * Obtained via `client.kit(appId).worldsim`.
72
- */
73
- export declare class WorldsimKit {
74
- private readonly appId;
75
- private readonly gameModel;
76
- private readonly engines?;
77
- private readonly names;
78
- private readonly moduleName;
79
- constructor(appId: Scalars['BigInt']['input'], gameModel: GameModelAPI, options?: WorldsimKitOptions, engines?: EngineDetector | undefined);
80
- /** Is a world compute engine deployed + enabled (cached per session)? */
81
- engineAvailable(): Promise<boolean>;
82
- /**
83
- * The world engine's `forecast` invoke: the current weather front plus
84
- * day-phase fields. Late joiners call this once, then track transitions
85
- * from the type-90 event stream ({@link parseWeather}).
86
- */
87
- forecast(): Promise<KitForecast>;
88
- /**
89
- * Parse a server-event payload as a world-engine weather transition
90
- * (type 90), or null when it is another event type. Feed it your world
91
- * session's server-event stream.
92
- */
93
- parseWeather(payload: Uint8Array): WeatherEvent | null;
94
- /**
95
- * Find-or-create the WorldState singleton (admin). `anchorChunk` is where
96
- * the clock's spatial time-changed ping is emitted.
97
- */
98
- ensureWorld(options?: {
99
- anchorChunk?: {
100
- x: number;
101
- y: number;
102
- z: number;
103
- };
104
- displayName?: string;
105
- }): Promise<{
106
- __typename?: "GmContainer";
107
- containerId: string;
108
- appId: string;
109
- sessionId: string | null;
110
- typeName: string;
111
- displayName: string;
112
- description: string | null;
113
- ownerUserId: string | null;
114
- metadataJson: string;
115
- }>;
116
- /** Read the world clock/weather state. */
117
- worldState(): Promise<KitWorldState>;
118
- /** Force the weather (app admins only — the policy denies everyone else). */
119
- setWeather(weather: string): Promise<KitInvokeResult<string>>;
120
- /** Create a resource node (admin). */
121
- createNode(input: {
122
- displayName: string;
123
- nodeId: string;
124
- resourceItemId: string;
125
- amount?: number;
126
- maxAmount?: number;
127
- regenRate?: number;
128
- position?: {
129
- x: number;
130
- y: number;
131
- z: number;
132
- };
133
- properties?: SeedPropertyInput[];
134
- }): Promise<{
135
- __typename?: "GmContainer";
136
- containerId: string;
137
- appId: string;
138
- sessionId: string | null;
139
- typeName: string;
140
- displayName: string;
141
- description: string | null;
142
- ownerUserId: string | null;
143
- metadataJson: string;
144
- }>;
145
- /** List resource nodes with parsed state. */
146
- nodes(): Promise<KitResourceNode[]>;
147
- /**
148
- * Gather from a node into a caller-owned stack of the node's resource;
149
- * the node decrement and the grant commit atomically. Resolves with the
150
- * node's remaining amount.
151
- */
152
- gather(input: {
153
- nodeId: string;
154
- amount: number;
155
- toStackId: string;
156
- }): Promise<KitInvokeResult<number>>;
157
- /** Plant a crop / start a production job (member). */
158
- plant(input: {
159
- ownerUserId: Scalars['BigInt']['input'];
160
- outputItemId: string;
161
- outputQty?: number;
162
- maxStage?: number;
163
- displayName?: string;
164
- sessionId?: string;
165
- }): Promise<{
166
- __typename?: "GmContainer";
167
- containerId: string;
168
- appId: string;
169
- sessionId: string | null;
170
- typeName: string;
171
- displayName: string;
172
- description: string | null;
173
- ownerUserId: string | null;
174
- metadataJson: string;
175
- }>;
176
- /** List a player's crops (all crops when `ownerUserId` is null). */
177
- crops(ownerUserId: Scalars['BigInt']['input'] | null): Promise<KitCrop[]>;
178
- /**
179
- * Harvest a grown crop into a caller-owned stack of the output item;
180
- * resets the stage for regrowth. Resolves with the yield quantity.
181
- */
182
- harvest(cropId: string, toStackId: string): Promise<KitInvokeResult<number>>;
183
- /** Create a wave spawner (admin; blueprint deployed with `waves`). */
184
- createSpawner(input: {
185
- displayName: string;
186
- nextWaveSize?: number;
187
- }): Promise<{
188
- __typename?: "GmContainer";
189
- containerId: string;
190
- appId: string;
191
- sessionId: string | null;
192
- typeName: string;
193
- displayName: string;
194
- description: string | null;
195
- ownerUserId: string | null;
196
- metadataJson: string;
197
- }>;
198
- /** List wave spawners (the host reads these to spawn entities). */
199
- spawners(): Promise<KitWaveSpawner[]>;
200
- /** Run one of the worldsim automations immediately (admin; for testing). */
201
- runNow(automationName: string): Promise<{
202
- __typename?: "GmAutomationRun";
203
- runId: string;
204
- appId: string;
205
- flowId: string | null;
206
- automationId: string | null;
207
- automationName: string;
208
- triggerSource: string;
209
- triggerId: string | null;
210
- parentRunId: string | null;
211
- cascadeDepth: number;
212
- startedAt: string;
213
- finishedAt: string | null;
214
- durationUs: number;
215
- targets: number;
216
- invocations: number;
217
- mutations: number;
218
- fnCalls: number;
219
- gasUsed: number;
220
- success: boolean;
221
- errorMessage: string | null;
222
- circuitAction: string | null;
223
- computeUnits: number;
224
- }>;
225
- /** Pause or resume one of the worldsim automations (admin). */
226
- setEnabled(automationName: string, enabled: boolean): Promise<{
227
- __typename?: "GmAutomation";
228
- automationId: string;
229
- appId: string;
230
- name: string;
231
- description: string | null;
232
- enabled: boolean;
233
- actionKind: string;
234
- functionName: string | null;
235
- computeModuleName: string | null;
236
- computeExport: string | null;
237
- targetMode: string;
238
- selfContainerId: string | null;
239
- targetTypeName: string | null;
240
- sessionId: string | null;
241
- paramsJson: string;
242
- selectorJson: string | null;
243
- runAsUserId: string | null;
244
- triggerType: string;
245
- scheduleKind: string | null;
246
- intervalMs: number | null;
247
- cronExpr: string | null;
248
- maxTargets: number;
249
- maxFnDepth: number | null;
250
- gasLimit: number | null;
251
- runTimeoutMs: number | null;
252
- maxRunsPerMinute: number;
253
- failureThreshold: number;
254
- cooldownMs: number;
255
- circuitState: string;
256
- consecutiveFailures: number;
257
- pausedUntil: string | null;
258
- lastError: string | null;
259
- lastRunAt: string | null;
260
- nextRunAt: string | null;
261
- }>;
262
- }
263
- //# sourceMappingURL=worldsim.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"worldsim.d.ts","sourceRoot":"","sources":["../../src/kit/worldsim.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,KAAK,EAAE,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAE1E,OAAO,KAAK,EAAE,cAAc,EAAsB,MAAM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,OAAO,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC;IASlF,sEAAsE;IAChE,aAAa,CAAC,KAAK,EAAE;QACzB,WAAW,EAAE,MAAM,CAAC;QACpB,YAAY,CAAC,EAAE,MAAM,CAAC;KACvB;;;;;;;;;;;IAeD,mEAAmE;IAC7D,QAAQ,IAAI,OAAO,CAAC,cAAc,EAAE,CAAC;IAsB3C,4EAA4E;IACtE,MAAM,CAAC,cAAc,EAAE,MAAM;;;;;;;;;;;;;;;;;;;;;;;;IAInC,+DAA+D;IACzD,UAAU,CAAC,cAAc,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAO1D"}
@@ -1,268 +0,0 @@
1
- import { worldsimNames } from './blueprints/index.js';
2
- import { kitContainerProperties, kitInvoke, } from './shared.js';
3
- import { parseWeatherEvent } from './wire.js';
4
- /**
5
- * Runtime helpers for the {@link worldsimBlueprint} conventions: the world
6
- * clock/weather singleton, regenerating resource nodes players gather from,
7
- * crops that mature server-side, and wave counters the host reads. The
8
- * simulation itself runs in automations — these helpers create/read state
9
- * and drive the player-facing functions.
10
- *
11
- * Obtained via `client.kit(appId).worldsim`.
12
- */
13
- export class WorldsimKit {
14
- constructor(appId, gameModel, options = {}, engines) {
15
- this.appId = appId;
16
- this.gameModel = gameModel;
17
- this.engines = engines;
18
- this.names = worldsimNames(options.typePrefix ?? '');
19
- this.moduleName = options.moduleName ?? 'world-engine';
20
- }
21
- /** Is a world compute engine deployed + enabled (cached per session)? */
22
- engineAvailable() {
23
- if (!this.engines)
24
- return Promise.resolve(false);
25
- return this.engines.has(this.moduleName);
26
- }
27
- /**
28
- * The world engine's `forecast` invoke: the current weather front plus
29
- * day-phase fields. Late joiners call this once, then track transitions
30
- * from the type-90 event stream ({@link parseWeather}).
31
- */
32
- async forecast() {
33
- const result = this.engines
34
- ? await this.engines.invoke(this.moduleName, 'forecast')
35
- : { success: false, reason: 'compute domain unavailable', body: {} };
36
- if (!result.success) {
37
- throw new Error(`forecast unavailable: ${result.reason ?? 'engine missing'}`);
38
- }
39
- return {
40
- weather: String(result.body.weather ?? ''),
41
- dayPhase: typeof result.body.dayPhase === 'number' ? result.body.dayPhase : undefined,
42
- isNight: typeof result.body.isNight === 'boolean' ? result.body.isNight : undefined,
43
- remainingMs: typeof result.body.remainingMs === 'number' ? result.body.remainingMs : undefined,
44
- body: result.body,
45
- };
46
- }
47
- /**
48
- * Parse a server-event payload as a world-engine weather transition
49
- * (type 90), or null when it is another event type. Feed it your world
50
- * session's server-event stream.
51
- */
52
- parseWeather(payload) {
53
- return parseWeatherEvent(payload);
54
- }
55
- /**
56
- * Find-or-create the WorldState singleton (admin). `anchorChunk` is where
57
- * the clock's spatial time-changed ping is emitted.
58
- */
59
- async ensureWorld(options = {}) {
60
- const existing = await this.gameModel.containers({
61
- appId: this.appId,
62
- typeName: this.names.worldStateType,
63
- });
64
- if (existing.length > 0)
65
- return existing[0];
66
- return this.gameModel.createContainer({
67
- appId: this.appId,
68
- typeName: this.names.worldStateType,
69
- displayName: options.displayName ?? 'World',
70
- properties: options.anchorChunk
71
- ? [
72
- { key: 'cx', valueType: 'int', valueJson: String(options.anchorChunk.x) },
73
- { key: 'cy', valueType: 'int', valueJson: String(options.anchorChunk.y) },
74
- { key: 'cz', valueType: 'int', valueJson: String(options.anchorChunk.z) },
75
- ]
76
- : [],
77
- });
78
- }
79
- /** Read the world clock/weather state. */
80
- async worldState() {
81
- const containers = await this.gameModel.containers({
82
- appId: this.appId,
83
- typeName: this.names.worldStateType,
84
- });
85
- if (containers.length === 0) {
86
- throw new Error(`No ${this.names.worldStateType} exists yet — run kit.worldsim.ensureWorld() as admin`);
87
- }
88
- const props = await kitContainerProperties(this.gameModel, String(this.appId), containers[0].containerId);
89
- return {
90
- containerId: containers[0].containerId,
91
- timeOfDay: Number(props.time_of_day ?? 0),
92
- day: Number(props.day ?? 0),
93
- weather: String(props.weather ?? 'clear'),
94
- };
95
- }
96
- /** Force the weather (app admins only — the policy denies everyone else). */
97
- async setWeather(weather) {
98
- const state = await this.worldState();
99
- return kitInvoke(this.gameModel, {
100
- appId: String(this.appId),
101
- functionName: this.names.setWeatherFn,
102
- selfContainerId: state.containerId,
103
- params: { weather },
104
- });
105
- }
106
- /** Create a resource node (admin). */
107
- async createNode(input) {
108
- const maxAmount = input.maxAmount ?? 100;
109
- return this.gameModel.createContainer({
110
- appId: this.appId,
111
- typeName: this.names.nodeType,
112
- displayName: input.displayName,
113
- properties: [
114
- { key: 'node_id', valueType: 'string', valueJson: JSON.stringify(input.nodeId) },
115
- {
116
- key: 'resource_item_id',
117
- valueType: 'string',
118
- valueJson: JSON.stringify(input.resourceItemId),
119
- },
120
- { key: 'amount', valueType: 'int', valueJson: String(input.amount ?? maxAmount) },
121
- { key: 'max_amount', valueType: 'int', valueJson: String(maxAmount) },
122
- { key: 'regen_rate', valueType: 'int', valueJson: String(input.regenRate ?? 1) },
123
- ...(input.position
124
- ? [
125
- { key: 'x', valueType: 'float', valueJson: String(input.position.x) },
126
- { key: 'y', valueType: 'float', valueJson: String(input.position.y) },
127
- { key: 'z', valueType: 'float', valueJson: String(input.position.z) },
128
- ]
129
- : []),
130
- ...(input.properties ?? []),
131
- ],
132
- });
133
- }
134
- /** List resource nodes with parsed state. */
135
- async nodes() {
136
- const containers = await this.gameModel.containers({
137
- appId: this.appId,
138
- typeName: this.names.nodeType,
139
- });
140
- return Promise.all(containers.map(async (c) => {
141
- const props = await kitContainerProperties(this.gameModel, String(this.appId), c.containerId);
142
- return {
143
- containerId: c.containerId,
144
- displayName: c.displayName,
145
- nodeId: String(props.node_id ?? ''),
146
- resourceItemId: String(props.resource_item_id ?? ''),
147
- amount: Number(props.amount ?? 0),
148
- maxAmount: Number(props.max_amount ?? 0),
149
- regenRate: Number(props.regen_rate ?? 0),
150
- x: Number(props.x ?? 0),
151
- y: Number(props.y ?? 0),
152
- z: Number(props.z ?? 0),
153
- };
154
- }));
155
- }
156
- /**
157
- * Gather from a node into a caller-owned stack of the node's resource;
158
- * the node decrement and the grant commit atomically. Resolves with the
159
- * node's remaining amount.
160
- */
161
- async gather(input) {
162
- return kitInvoke(this.gameModel, {
163
- appId: String(this.appId),
164
- functionName: this.names.gatherNodeFn,
165
- selfContainerId: input.nodeId,
166
- params: { amount: input.amount, to_stack_id: input.toStackId },
167
- });
168
- }
169
- /** Plant a crop / start a production job (member). */
170
- async plant(input) {
171
- return this.gameModel.createContainer({
172
- appId: this.appId,
173
- typeName: this.names.cropType,
174
- displayName: input.displayName ?? `Crop ${input.outputItemId}`,
175
- ...(input.sessionId !== undefined ? { sessionId: input.sessionId } : {}),
176
- properties: [
177
- { key: 'owner_user_id', valueType: 'int', valueJson: String(input.ownerUserId) },
178
- {
179
- key: 'output_item_id',
180
- valueType: 'string',
181
- valueJson: JSON.stringify(input.outputItemId),
182
- },
183
- { key: 'output_qty', valueType: 'int', valueJson: String(input.outputQty ?? 1) },
184
- { key: 'max_stage', valueType: 'int', valueJson: String(input.maxStage ?? 3) },
185
- ],
186
- });
187
- }
188
- /** List a player's crops (all crops when `ownerUserId` is null). */
189
- async crops(ownerUserId) {
190
- const containers = await this.gameModel.containers({
191
- appId: this.appId,
192
- typeName: this.names.cropType,
193
- });
194
- const filtered = ownerUserId === null
195
- ? containers
196
- : containers.filter((c) => c.ownerUserId != null && String(c.ownerUserId) === String(ownerUserId));
197
- return Promise.all(filtered.map(async (c) => {
198
- const props = await kitContainerProperties(this.gameModel, String(this.appId), c.containerId);
199
- const stage = Number(props.stage ?? 0);
200
- const maxStage = Number(props.max_stage ?? 0);
201
- return {
202
- containerId: c.containerId,
203
- displayName: c.displayName,
204
- ownerUserId: c.ownerUserId != null ? String(c.ownerUserId) : null,
205
- stage,
206
- maxStage,
207
- outputItemId: String(props.output_item_id ?? ''),
208
- outputQty: Number(props.output_qty ?? 0),
209
- ready: maxStage > 0 && stage >= maxStage,
210
- };
211
- }));
212
- }
213
- /**
214
- * Harvest a grown crop into a caller-owned stack of the output item;
215
- * resets the stage for regrowth. Resolves with the yield quantity.
216
- */
217
- async harvest(cropId, toStackId) {
218
- return kitInvoke(this.gameModel, {
219
- appId: String(this.appId),
220
- functionName: this.names.harvestFn,
221
- selfContainerId: cropId,
222
- params: { to_stack_id: toStackId },
223
- });
224
- }
225
- /** Create a wave spawner (admin; blueprint deployed with `waves`). */
226
- async createSpawner(input) {
227
- return this.gameModel.createContainer({
228
- appId: this.appId,
229
- typeName: this.names.spawnerType,
230
- displayName: input.displayName,
231
- properties: [
232
- {
233
- key: 'next_wave_size',
234
- valueType: 'int',
235
- valueJson: String(input.nextWaveSize ?? 5),
236
- },
237
- ],
238
- });
239
- }
240
- /** List wave spawners (the host reads these to spawn entities). */
241
- async spawners() {
242
- const containers = await this.gameModel.containers({
243
- appId: this.appId,
244
- typeName: this.names.spawnerType,
245
- });
246
- return Promise.all(containers.map(async (c) => {
247
- const props = await kitContainerProperties(this.gameModel, String(this.appId), c.containerId);
248
- return {
249
- containerId: c.containerId,
250
- displayName: c.displayName,
251
- wave: Number(props.wave ?? 0),
252
- nextWaveSize: Number(props.next_wave_size ?? 0),
253
- };
254
- }));
255
- }
256
- /** Run one of the worldsim automations immediately (admin; for testing). */
257
- async runNow(automationName) {
258
- return this.gameModel.runAutomation({ appId: this.appId, name: automationName });
259
- }
260
- /** Pause or resume one of the worldsim automations (admin). */
261
- async setEnabled(automationName, enabled) {
262
- return this.gameModel.setAutomationEnabled({
263
- appId: this.appId,
264
- name: automationName,
265
- enabled,
266
- });
267
- }
268
- }