@crowdedkingdoms/crowdyjs 13.0.2 → 13.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -6,7 +6,7 @@ GameModelCreateSessionDocument, GameModelJoinSessionDocument, GameModelSetSessio
6
6
  // Studio authoring ops
7
7
  GameModelSeedDocument, GameModelUpsertContainerTypeDocument, GameModelUpsertPropertyDefDocument, GameModelDeletePropertyDefDocument, GameModelDeleteContainerTypeDocument, GameModelUpsertFunctionDocument, GameModelDeleteFunctionDocument, GameModelDefineFeatureDocument, GameModelGrantTierFeatureDocument, GameModelSetPolicyDocument, GameModelTypeSchemaDocument, GameModelContainerTypesDocument, GameModelPropertyDefsDocument, GameModelFunctionDocument, GameModelFunctionsDocument, GameModelFeaturesDocument, GameModelTierFeaturesDocument, GameModelPolicyDocument, GameModelRevokeTierFeatureDocument, GameModelEventsConnectionDocument,
8
8
  // Automations (autonomous processes / NPCs)
9
- GameModelUpsertAutomationDocument, GameModelDeleteAutomationDocument, GameModelSetAutomationEnabledDocument, GameModelUpsertAutomationTriggerDocument, GameModelDeleteAutomationTriggerDocument, GameModelSetAutomationPolicyDocument, GameModelRunAutomationDocument, GameModelAutomationsDocument, GameModelAutomationDocument, GameModelAutomationTriggersDocument, GameModelAutomationPolicyDocument, GameModelAutomationRunsDocument, GameModelAutomationStatsDocument, GameModelAppDiagnosticsDocument, } from '../generated/graphql.js';
9
+ GameModelUpsertAutomationDocument, GameModelDeleteAutomationDocument, GameModelSetAutomationEnabledDocument, GameModelUpsertAutomationTriggerDocument, GameModelDeleteAutomationTriggerDocument, GameModelSetAutomationPolicyDocument, GameModelRunAutomationDocument, GameModelAutomationsDocument, GameModelAutomationDocument, GameModelAutomationTriggersDocument, GameModelAutomationPolicyDocument, GameModelAutomationRunsDocument, GameModelAutomationStatsDocument, GameModelAppDiagnosticsDocument, GameModelScheduleInvokeDocument, GameModelCancelTimerDocument, GameModelTimersDocument, } from '../generated/graphql.js';
10
10
  export class GameModelAPI {
11
11
  constructor(gql, ws) {
12
12
  this.gql = gql;
@@ -852,12 +852,26 @@ export class GameModelAPI {
852
852
  /**
853
853
  * **Automations** — create an event trigger that fires an automation in
854
854
  * reaction to model activity (`function_invoked` | `property_changed` |
855
- * `container_created`), matched in the API server post-commit. Requires the
856
- * app-admin **`manage_apps`** permission.
855
+ * `container_created` | `player_count_changed`), matched in the API server
856
+ * post-commit. Requires the app-admin **`manage_apps`** permission.
857
+ *
858
+ * Each event matches on its own filters, and a filter the event does not
859
+ * match on is rejected rather than silently never firing:
860
+ * `function_invoked` takes `functionName` and `containerTypeName` (the type
861
+ * of the invocation's `self` container); `property_changed` takes
862
+ * `containerTypeName`, `propertyKey`, and `writeSource`;
863
+ * `container_created` takes `containerTypeName`; `player_count_changed`
864
+ * takes none.
865
+ *
866
+ * `writeSource` decides which writes a `property_changed` trigger sees:
867
+ * `direct` (a {@link GameModelAPI.setProperty} call), `function` (a mutation
868
+ * applied inside an invoke, automation run, or timer fire), or `any`
869
+ * (default). Most game logic writes properties from inside functions, so a
870
+ * trigger watching such a property needs `function` or `any`.
857
871
  *
858
872
  * @param input - {@link UpsertAutomationTriggerInput}: `appId`,
859
- * `automationName`, `onEvent`, optional `functionName` /
860
- * `containerTypeName` / `propertyKey` filters, and `debounceMs`.
873
+ * `automationName`, `onEvent`, the filters valid for that event, and
874
+ * `debounceMs`.
861
875
  * @returns The created {@link GmAutomationTrigger}.
862
876
  */
863
877
  async upsertAutomationTrigger(input) {
@@ -878,7 +892,8 @@ export class GameModelAPI {
878
892
  /**
879
893
  * **Automations** — set the app's automation policy (platform guardrails: the
880
894
  * kill switch, max automations, the minimum schedule interval floor, max
881
- * fan-out, max event cascade depth, and the aggregate per-minute run ceiling).
895
+ * fan-out, max event cascade depth, the aggregate per-minute run ceiling, and
896
+ * the timer floor / pending-timer ceiling).
882
897
  * Requires the app-admin **`manage_apps`** permission.
883
898
  *
884
899
  * @param input - {@link SetAutomationPolicyInput}.
@@ -927,6 +942,10 @@ export class GameModelAPI {
927
942
  * **Automations** — list event triggers for an app, optionally filtered to one
928
943
  * automation by name. Requires the app-admin **`manage_apps`** permission.
929
944
  *
945
+ * Use this to debug a trigger that isn't firing: `warnings` reports filters
946
+ * that can never match, `lastMatchedAt` is null until the trigger has
947
+ * actually dispatched a run, and `matchCount24h` shows recent activity.
948
+ *
930
949
  * @param variables - `{ appId, automationName? }`.
931
950
  * @returns The {@link GmAutomationTrigger}s.
932
951
  */
@@ -983,4 +1002,56 @@ export class GameModelAPI {
983
1002
  const data = await this.gql.request(GameModelAppDiagnosticsDocument, variables);
984
1003
  return data.gameModelAppDiagnostics;
985
1004
  }
1005
+ /**
1006
+ * **Timers** — arm a one-shot timer: invoke a function once, after a delay.
1007
+ * The timer is durable (it survives an API restart) and claimed by exactly one
1008
+ * replica, so it fires once. Requires the app-admin **`manage_apps`**
1009
+ * permission, because a timer fires headlessly with system authority rather
1010
+ * than a player's.
1011
+ *
1012
+ * For player-driven delays, declare a `timers` effect on the function instead
1013
+ * (see {@link GameModelAPI.upsertFunction}) so the delay is part of your game
1014
+ * logic and is armed atomically with that invocation's mutations.
1015
+ *
1016
+ * The target function must be `autonomousInvocable`. Pass `dedupeKey` to make
1017
+ * re-arming replace the pending timer instead of queueing another fire, which
1018
+ * is how you implement "reset the countdown".
1019
+ *
1020
+ * @param input - {@link ScheduleInvokeInput}: `appId`, `functionName`,
1021
+ * `selfContainerId`, `delayMs`, and optional `paramsJson`, `sessionId`, and
1022
+ * `dedupeKey`.
1023
+ * @returns The armed {@link GmTimer}.
1024
+ */
1025
+ async scheduleInvoke(input) {
1026
+ const data = await this.gql.request(GameModelScheduleInvokeDocument, { input });
1027
+ return data.gameModelScheduleInvoke;
1028
+ }
1029
+ /**
1030
+ * **Timers** — cancel pending timers by id or by dedupe key. A timer already
1031
+ * claimed for execution cannot be cancelled. Requires the app-admin
1032
+ * **`manage_apps`** permission.
1033
+ *
1034
+ * @param variables - `{ appId, timerId?, dedupeKey? }` (supply at least one
1035
+ * selector).
1036
+ * @returns How many pending timers were removed.
1037
+ */
1038
+ async cancelTimer(variables) {
1039
+ const data = await this.gql.request(GameModelCancelTimerDocument, variables);
1040
+ return data.gameModelCancelTimer;
1041
+ }
1042
+ /**
1043
+ * **Timers** — list pending one-shot timers, soonest first. A timer leaves
1044
+ * this list the instant it is claimed for execution, so an empty list means
1045
+ * nothing is *scheduled* — not that nothing ran. Fires that already happened
1046
+ * appear in {@link GameModelAPI.automationRuns} with
1047
+ * `triggerSource: 'timer'`. Requires the app-admin **`manage_apps`**
1048
+ * permission.
1049
+ *
1050
+ * @param variables - `{ appId, sessionId?, limit? }` (limit 1-200, default 50).
1051
+ * @returns The pending {@link GmTimer}s.
1052
+ */
1053
+ async timers(variables) {
1054
+ const data = await this.gql.request(GameModelTimersDocument, variables);
1055
+ return data.gameModelTimers;
1056
+ }
986
1057
  }
@@ -44,6 +44,12 @@ export declare class UdpAPI {
44
44
  constructor(gql: GraphQLClient, subs: SubscriptionManager, metrics?: RealtimeMetrics | undefined);
45
45
  /** Count a message accepted for sending (see `client.metrics`). */
46
46
  private record;
47
+ /**
48
+ * Try to send over the binary relay (`crowdy-relay-v1`). Returns `null`
49
+ * when the relay is not active/ready so the caller falls back to the
50
+ * GraphQL mutation. Client-side serialize + HMAC; no GraphQL on this path.
51
+ */
52
+ private sendViaRelay;
47
53
  /**
48
54
  * Open (or re-fetch) the UDP proxy session for this game token. Idempotent:
49
55
  * if a session is already open it returns the existing status; on first open
@@ -1 +1 @@
1
- {"version":3,"file":"udp.d.ts","sourceRoot":"","sources":["../../src/domains/udp.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,KAAK,EACV,mBAAmB,EACnB,uBAAuB,EACxB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAEL,KAAK,uBAAuB,EAG5B,KAAK,6BAA6B,EAElC,KAAK,gCAAgC,EAErC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B,CAAC;IAO/B;;;;;;;;;;;;;;;;;;;OAmBG;IACG,cAAc,CAClB,KAAK,EAAE,+BAA+B,CAAC,OAAO,CAAC,GAC9C,OAAO,CAAC,OAAO,CAAC;IAanB;;;;;;;;;;;;;;;;;OAiBG;IACG,qBAAqB,CACzB,KAAK,EAAE,+BAA+B,CAAC,OAAO,CAAC,EAC/C,OAAO,GAAE;QAAE,SAAS,CAAC,EAAE,MAAM,CAAA;KAAO,GACnC,OAAO,CAAC,mBAAmB,CAAC;IAO/B;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IACG,eAAe,CACnB,KAAK,EAAE,gCAAgC,CAAC,OAAO,CAAC,GAC/C,OAAO,CAAC,OAAO,CAAC;IAanB;;;;;;;;;;;;;;;;;;OAkBG;IACG,sBAAsB,CAC1B,KAAK,EAAE,gCAAgC,CAAC,OAAO,CAAC,EAChD,OAAO,GAAE;QAAE,SAAS,CAAC,EAAE,MAAM,CAAA;KAAO,GACnC,OAAO,CAAC,mBAAmB,CAAC;IAO/B;;;;;;;;;;;;;;;;;;;;OAoBG;IACG,sBAAsB,CAC1B,KAAK,EAAE,uCAAuC,CAAC,OAAO,CAAC,GACtD,OAAO,CAAC,OAAO,CAAC;IAenB;;;;;;;;;;;;;;;;;;;OAmBG;IACG,kBAAkB,CACtB,KAAK,EAAE,mCAAmC,CAAC,OAAO,CAAC,GAClD,OAAO,CAAC,OAAO,CAAC;IAanB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAqCG;IACH,SAAS,CAAC,QAAQ,EAAE,uBAAuB,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,IAAI;IAIvE,OAAO,CAAC,YAAY;CAQrB"}
@@ -1,6 +1,7 @@
1
1
  import { ConnectUdpProxyDocument, DisconnectUdpProxyDocument, UdpProxyConnectionStatusDocument, SendActorUpdateDocument, SendVoxelUpdateDocument, SendAudioPacketDocument, SendTextPacketDocument, SendClientEventDocument, SendSingleActorMessageDocument, SendChannelMessageDocument, } from '../generated/graphql.js';
2
2
  import { payloadBytesOf } from '../metrics.js';
3
3
  import { SequenceAllocator } from '../utils.js';
4
+ import { serializeActorUpdate, serializeAudioPacket, serializeChannelMessage, serializeClientEvent, serializeSingleActorMessage, serializeTextPacket, serializeVoxelUpdate, } from '../binary-wire.js';
4
5
  /**
5
6
  * UDP proxy access for browser-style clients that can't open raw UDP sockets.
6
7
  * Exposed as `client.udp`; for game loops prefer the ergonomic, app-scoped
@@ -45,6 +46,31 @@ export class UdpAPI {
45
46
  record(kind, input) {
46
47
  this.metrics?.recordSent(kind, payloadBytesOf(input));
47
48
  }
49
+ /**
50
+ * Try to send over the binary relay (`crowdy-relay-v1`). Returns `null`
51
+ * when the relay is not active/ready so the caller falls back to the
52
+ * GraphQL mutation. Client-side serialize + HMAC; no GraphQL on this path.
53
+ */
54
+ async sendViaRelay(serialize) {
55
+ if (!this.subs.usingBinaryTransport())
56
+ return null;
57
+ if (!this.subs.binarySendReady()) {
58
+ // Relay configured but not open yet (e.g. right after subscribe or a
59
+ // token rotation). Wait briefly rather than falling back to HTTP — an
60
+ // HTTP send would open a parallel GraphQL proxy session for the same
61
+ // token whose idle teardown deauthorizes it under the relay session.
62
+ const ready = await this.subs.ensureBinaryReady(2000);
63
+ if (!ready)
64
+ return null;
65
+ }
66
+ try {
67
+ return await this.subs.sendBinaryFrame(serialize);
68
+ }
69
+ catch {
70
+ // Relay hiccup (socket flapped mid-send) — let GraphQL carry this one.
71
+ return null;
72
+ }
73
+ }
48
74
  /**
49
75
  * Open (or re-fetch) the UDP proxy session for this game token. Idempotent:
50
76
  * if a session is already open it returns the existing status; on first open
@@ -60,6 +86,19 @@ export class UdpAPI {
60
86
  * valid bearer game token.
61
87
  */
62
88
  async connect() {
89
+ if (this.subs.usingBinaryTransport()) {
90
+ // Binary relay mode: the relay session (opened by subscribe) IS the
91
+ // proxy session. Never open a parallel GraphQL proxy session for the
92
+ // same token — its idle teardown would deauthorize the token on the
93
+ // game server underneath the relay.
94
+ const ready = await this.subs.ensureBinaryReady();
95
+ return {
96
+ connected: ready,
97
+ serverIp6: null,
98
+ serverClientPort: null,
99
+ lastMessageTime: null,
100
+ };
101
+ }
63
102
  const data = await this.gql.request(ConnectUdpProxyDocument, undefined);
64
103
  return data.connectUdpProxy;
65
104
  }
@@ -73,6 +112,10 @@ export class UdpAPI {
73
112
  * @throws {CrowdyGraphQLError} on auth failures.
74
113
  */
75
114
  async disconnect() {
115
+ if (this.subs.usingBinaryTransport()) {
116
+ this.subs.disconnect();
117
+ return true;
118
+ }
76
119
  const data = await this.gql.request(DisconnectUdpProxyDocument, undefined);
77
120
  return data.disconnectUdpProxy;
78
121
  }
@@ -120,6 +163,11 @@ export class UdpAPI {
120
163
  * token, or `BAD_USER_INPUT` for a malformed packet.
121
164
  */
122
165
  async sendActorUpdate(input) {
166
+ const viaRelay = await this.sendViaRelay((ctx) => serializeActorUpdate(ctx, input));
167
+ if (viaRelay !== null) {
168
+ this.record('actorUpdate', input);
169
+ return viaRelay;
170
+ }
123
171
  if (this.subs.wsUplinkReady()) {
124
172
  try {
125
173
  const data = await this.subs.executeMutation(SendActorUpdateDocument, {
@@ -219,6 +267,11 @@ export class UdpAPI {
219
267
  * @throws {CrowdyGraphQLError} on auth/validation failures.
220
268
  */
221
269
  async sendVoxelUpdate(input) {
270
+ const viaRelay = await this.sendViaRelay((ctx) => serializeVoxelUpdate(ctx, input));
271
+ if (viaRelay !== null) {
272
+ this.record('voxelUpdate', input);
273
+ return viaRelay;
274
+ }
222
275
  const data = await this.gql.request(SendVoxelUpdateDocument, { input });
223
276
  this.record('voxelUpdate', input);
224
277
  return data.sendVoxelUpdate;
@@ -272,6 +325,11 @@ export class UdpAPI {
272
325
  * @throws {CrowdyGraphQLError} on auth/validation failures.
273
326
  */
274
327
  async sendAudioPacket(input) {
328
+ const viaRelay = await this.sendViaRelay((ctx) => serializeAudioPacket(ctx, input));
329
+ if (viaRelay !== null) {
330
+ this.record('audio', input);
331
+ return viaRelay;
332
+ }
275
333
  const data = await this.gql.request(SendAudioPacketDocument, { input });
276
334
  this.record('audio', input);
277
335
  return data.sendAudioPacket;
@@ -321,6 +379,11 @@ export class UdpAPI {
321
379
  * @throws {CrowdyGraphQLError} on auth/validation failures.
322
380
  */
323
381
  async sendTextPacket(input) {
382
+ const viaRelay = await this.sendViaRelay((ctx) => serializeTextPacket(ctx, input));
383
+ if (viaRelay !== null) {
384
+ this.record('text', input);
385
+ return viaRelay;
386
+ }
324
387
  const data = await this.gql.request(SendTextPacketDocument, { input });
325
388
  this.record('text', input);
326
389
  return data.sendTextPacket;
@@ -374,6 +437,11 @@ export class UdpAPI {
374
437
  * @throws {CrowdyGraphQLError} on auth/validation failures.
375
438
  */
376
439
  async sendClientEvent(input) {
440
+ const viaRelay = await this.sendViaRelay((ctx) => serializeClientEvent(ctx, input));
441
+ if (viaRelay !== null) {
442
+ this.record('clientEvent', input);
443
+ return viaRelay;
444
+ }
377
445
  const data = await this.gql.request(SendClientEventDocument, { input });
378
446
  this.record('clientEvent', input);
379
447
  return data.sendClientEvent;
@@ -425,6 +493,11 @@ export class UdpAPI {
425
493
  * @throws {CrowdyGraphQLError} on auth/validation failures.
426
494
  */
427
495
  async sendSingleActorMessage(input) {
496
+ const viaRelay = await this.sendViaRelay((ctx) => serializeSingleActorMessage(ctx, input));
497
+ if (viaRelay !== null) {
498
+ this.record('singleActorMessage', input);
499
+ return viaRelay;
500
+ }
428
501
  const data = await this.gql.request(SendSingleActorMessageDocument, {
429
502
  input,
430
503
  });
@@ -452,6 +525,11 @@ export class UdpAPI {
452
525
  * @throws {CrowdyGraphQLError} on auth/validation failures.
453
526
  */
454
527
  async sendChannelMessage(input) {
528
+ const viaRelay = await this.sendViaRelay((ctx) => serializeChannelMessage(ctx, input));
529
+ if (viaRelay !== null) {
530
+ this.record('channelMessage', input);
531
+ return viaRelay;
532
+ }
455
533
  const data = await this.gql.request(SendChannelMessageDocument, { input });
456
534
  this.record('channelMessage', input);
457
535
  return data.sendChannelMessage;