@crowdedkingdoms/crowdyjs 8.5.0 → 8.6.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.
package/MIGRATION.md CHANGED
@@ -1,3 +1,30 @@
1
+ # CrowdyJS v8.6 Notes
2
+
3
+ ## Added
4
+
5
+ **`client.compute` — Compute Modules** (server-side Rust/WebAssembly logic on
6
+ the Game API). Additive; no breaking changes.
7
+
8
+ - Authoring: `upsertModule`, `deployVersion({ appId, moduleName, sourceFiles })`
9
+ (stringifies the source map and defaults the SDK/ABI pins), `waitForCompile`
10
+ (polls the newest version until the compile settles), `setModuleEnabled`,
11
+ `deleteModule`, `upsertTrigger` (tick / event / invoke), `deleteTrigger`,
12
+ `setPolicy`.
13
+ - Invoke: `invoke({ appId, moduleName, exportName, paramsJson })` — synchronous
14
+ RPC to a module's client-callable export.
15
+ - Monitoring: `modules`, `module`, `moduleVersions`, `moduleTriggers`,
16
+ `modulePolicy`, `moduleRuns`, `moduleStats`, `moduleLogs`, `appDiagnostics`.
17
+ - Exports: `ComputeAPI`, `COMPUTE_SDK_VERSION`, `COMPUTE_ABI_VERSION`.
18
+
19
+ Modules execute **server-only**; the SDK manages, invokes, and observes them.
20
+ Guide: https://docs.crowdedkingdoms.com/game-api/compute-modules
21
+
22
+ ## Server compatibility
23
+
24
+ Requires a `cks-game-api` build that serves the `compute*` root fields
25
+ (v0.13.13+ dev line). Older servers reject compute operations with a GraphQL
26
+ validation error; every other sub-client is unaffected.
27
+
1
28
  # CrowdyJS v8 — Passwordless & federated sign-in (BREAKING)
2
29
 
3
30
  **Crowded Kingdoms is passwordless.** Email + password login is removed. Update
package/README.md CHANGED
@@ -12,7 +12,7 @@ npm install @crowdedkingdoms/crowdyjs
12
12
 
13
13
  CrowdyJS v4 targets browsers by default and uses native `fetch`, `WebSocket`, `crypto`, `btoa`, and `atob`. Node tools can still use the SDK, but must provide browser-compatible globals when opening realtime connections.
14
14
 
15
- > **Server compatibility:** v5.2+ targets environments on release **v0.1.19 or later** (`cks-game-api >= v0.10.3`, `cks-management-api >= v0.1.70`). The destructive mutations send an `idempotencyKey` argument that older servers don't define. v6.1's `client.gameApps.deleteGrid` additionally requires release **v0.1.33+** (`cks-game-api >= v0.12.3`). The game-model **permission effects** fields (`permissionEffects` on `gameModel.upsertFunction`/`seed`, `permissionEffectsAppliedJson` on events) require a `cks-game-api` build with the `2026-07-17-model-permission-effects` migration (v0.13.11+); older servers reject queries/mutations that include them (omit the fields and everything else keeps working). The **permission-read** surface (the `has_grid_permission`/`grid_at`/`has_chunk_permission` expression builtins the kit's `chunkPermission` locks compile to, and selector `*PermissionWhere` predicates) additionally requires `cks-game-api` **v0.13.12+**. Older `cks-game-api` builds report game-model **invoke policy denials** as `FORBIDDEN` GraphQL errors instead of resolving with `success: false`; as of this version the kit's invoke helpers map that error onto the documented `{ success: false, errorMessage }` result, so kit callers behave identically against both server generations.
15
+ > **Server compatibility:** v5.2+ targets environments on release **v0.1.19 or later** (`cks-game-api >= v0.10.3`, `cks-management-api >= v0.1.70`). The destructive mutations send an `idempotencyKey` argument that older servers don't define. v6.1's `client.gameApps.deleteGrid` additionally requires release **v0.1.33+** (`cks-game-api >= v0.12.3`). The game-model **permission effects** fields (`permissionEffects` on `gameModel.upsertFunction`/`seed`, `permissionEffectsAppliedJson` on events) require a `cks-game-api` build with the `2026-07-17-model-permission-effects` migration (v0.13.11+); older servers reject queries/mutations that include them (omit the fields and everything else keeps working). The **permission-read** surface (the `has_grid_permission`/`grid_at`/`has_chunk_permission` expression builtins the kit's `chunkPermission` locks compile to, and selector `*PermissionWhere` predicates) additionally requires `cks-game-api` **v0.13.12+**. Older `cks-game-api` builds report game-model **invoke policy denials** as `FORBIDDEN` GraphQL errors instead of resolving with `success: false`; as of this version the kit's invoke helpers map that error onto the documented `{ success: false, errorMessage }` result, so kit callers behave identically against both server generations. v8.6's **`client.compute`** (Compute Modules — server-side Rust/WASM logic) requires a `cks-game-api` build with the compute surface (the `compute*` root fields, v0.13.13+ dev line); older servers reject these operations with a GraphQL validation error, and everything else keeps working.
16
16
 
17
17
  ## Standalone builds and schema refresh
18
18
 
@@ -95,6 +95,7 @@ If `managementUrl` is omitted, the SDK falls back to `httpUrl` for backwards-com
95
95
  | `client.teleport` | Teleport requests. |
96
96
  | `client.channels`, `client.teams` | Messaging channels and app-scoped player teams (membership + roles). |
97
97
  | `client.gameModel` | Abstract game model: containers, properties, functions (incl. model-driven `notify_*` effects), sessions, and **automations / NPCs** (`upsertAutomation`, `runAutomation`, `automationRuns`, `automationStats`, …). |
98
+ | `client.compute` | **Compute Modules** — server-side Rust/WASM logic: author + deploy source (`upsertModule`, `deployVersion`, `waitForCompile`), triggers + policy, synchronous `invoke`, and monitoring (`moduleRuns`, `moduleStats`, `moduleLogs`, `appDiagnostics`). Modules run server-only; see [Compute Modules docs](https://docs.crowdedkingdoms.com/game-api/compute-modules). |
98
99
  | `client.udp` | UDP proxy subscriptions + spatial mutations (`sendActorUpdate`, `sendVoxelUpdate`, `sendAudioPacket`, `sendTextPacket`, `sendClientEvent`). |
99
100
  | `client.realtime` | Connection status, manual `connect()` / `disconnect()`, `onStatus()` listener. |
100
101
  | `client.world(appId)` | Higher-level helpers for browser games (`actor.join`, `actor.sendState`, `actor.sendText`). |
@@ -57,6 +57,7 @@ import { ChannelsAPI } from './domains/channels.js';
57
57
  import { TeamsAPI } from './domains/teams.js';
58
58
  import { UdpAPI } from './domains/udp.js';
59
59
  import { GameModelAPI } from './domains/gameModel.js';
60
+ import { ComputeAPI } from './domains/compute.js';
60
61
  export interface CrowdyClientConfig {
61
62
  /** game-api HTTP root (e.g. `https://dev-game-api.crowdedkingdoms.com`). */
62
63
  httpUrl?: string;
@@ -187,6 +188,8 @@ export declare class CrowdyClient {
187
188
  readonly udp: UdpAPI;
188
189
  /** Abstract game model: containers, properties, functions, sessions. */
189
190
  readonly gameModel: GameModelAPI;
191
+ /** Compute Modules: server-side Rust/WASM logic (manage, invoke, observe). */
192
+ readonly compute: ComputeAPI;
190
193
  /** Durable avatars + per-app avatar state (owner-aware reads). */
191
194
  readonly avatars: AvatarsAPI;
192
195
  /** Game-host election + actor liveness heartbeat. */
@@ -1 +1 @@
1
- {"version":3,"file":"crowdy-client.d.ts","sourceRoot":"","sources":["../src/crowdy-client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,EAAE,aAAa,EAAE,KAAK,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAEpE,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,KAAK,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAChE,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,SAA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QAAQ,CAAC,QAAQ,EAAE,WAAW,CAAC;IAC/B,8CAA8C;IAC9C,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC;IACzB,4EAA4E;IAC5E,QAAQ,CAAC,YAAY,EAAE,eAAe,CAAC;IACvC,+DAA+D;IAC/D,QAAQ,CAAC,QAAQ,EAAE,WAAW,CAAC;IAC/B,2EAA2E;IAC3E,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC;IACzB,gFAAgF;IAChF,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,wEAAwE;IACxE,QAAQ,CAAC,SAAS,EAAE,YAAY,CAAC;IACjC,8EAA8E;IAC9E,QAAQ,CAAC,OAAO,EAAE,UAAU,CAAC;IAC7B,kEAAkE;IAClE,QAAQ,CAAC,OAAO,EAAE,UAAU,CAAC;IAC7B,qDAAqD;IACrD,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IACvB,sEAAsE;IACtE,QAAQ,CAAC,QAAQ,EAAE,WAAW,CAAC;gBAEnB,MAAM,GAAE,kBAAuB;IA2F3C,4EAA4E;IAC5E,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI;IAIpC,0DAA0D;IAC1D,QAAQ,IAAI,MAAM,GAAG,IAAI;IAIzB;;;;;;;OAOG;IACH,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,WAAW;IAIjC;;;;;;;;;;;;OAYG;IACH,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,aAAa;IAQ3D,gEAAgE;IAChE,KAAK,IAAI,IAAI;CAId;AAED,wBAAgB,kBAAkB,CAChC,MAAM,GAAE,kBAAuB,GAC9B,YAAY,CAEd"}
@@ -55,6 +55,7 @@ import { ChannelsAPI } from './domains/channels.js';
55
55
  import { TeamsAPI } from './domains/teams.js';
56
56
  import { UdpAPI } from './domains/udp.js';
57
57
  import { GameModelAPI } from './domains/gameModel.js';
58
+ import { ComputeAPI } from './domains/compute.js';
58
59
  export class CrowdyClient {
59
60
  constructor(config = {}) {
60
61
  this.session = new AuthState(config.tokenStore);
@@ -109,6 +110,7 @@ export class CrowdyClient {
109
110
  this.teams = new TeamsAPI(this.graphql);
110
111
  this.udp = new UdpAPI(this.graphql, this.realtime, this.metrics);
111
112
  this.gameModel = new GameModelAPI(this.graphql);
113
+ this.compute = new ComputeAPI(this.graphql);
112
114
  this.avatars = new AvatarsAPI(this.graphql);
113
115
  this.host = new HostAPI(this.graphql);
114
116
  this.gameApps = new GameAppsAPI(this.graphql);
@@ -0,0 +1,175 @@
1
+ import type { GraphQLClient } from '../client.js';
2
+ import { type ComputeUpsertModuleMutation, type ComputeUpsertModuleMutationVariables, type ComputeDeployVersionMutation, type ComputeSetModuleEnabledMutation, type ComputeSetModuleEnabledMutationVariables, type ComputeDeleteModuleMutation, type ComputeDeleteModuleMutationVariables, type ComputeUpsertTriggerMutation, type ComputeUpsertTriggerMutationVariables, type ComputeDeleteTriggerMutation, type ComputeDeleteTriggerMutationVariables, type ComputeSetPolicyMutation, type ComputeSetPolicyMutationVariables, type ComputeInvokeMutation, type ComputeInvokeMutationVariables, type ComputeModulesQuery, type ComputeModulesQueryVariables, type ComputeModuleQuery, type ComputeModuleQueryVariables, type ComputeModuleVersionsQuery, type ComputeModuleVersionsQueryVariables, type ComputeModuleTriggersQuery, type ComputeModuleTriggersQueryVariables, type ComputeModulePolicyQuery, type ComputeModulePolicyQueryVariables, type ComputeModuleRunsQuery, type ComputeModuleRunsQueryVariables, type ComputeModuleStatsQuery, type ComputeModuleStatsQueryVariables, type ComputeModuleLogsQuery, type ComputeModuleLogsQueryVariables, type ComputeAppDiagnosticsQuery, type ComputeAppDiagnosticsQueryVariables } from '../generated/graphql.js';
3
+ /** The crowdy-compute-sdk version the platform toolchain currently pins. */
4
+ export declare const COMPUTE_SDK_VERSION = "0.1.0";
5
+ /** The guest ABI version the platform currently supports. */
6
+ export declare const COMPUTE_ABI_VERSION = 0;
7
+ /** Options for {@link ComputeAPI.deployVersion}. */
8
+ export interface DeployVersionOptions {
9
+ appId: ComputeSetModuleEnabledMutationVariables['appId'];
10
+ moduleName: string;
11
+ /**
12
+ * Relative path -> file contents. Must include `Cargo.toml` and
13
+ * `src/lib.rs`; only `.rs` files under `src/` plus `Cargo.toml` are
14
+ * accepted by the server (crate allowlist, size caps, no build-time code).
15
+ */
16
+ sourceFiles: Record<string, string>;
17
+ /** crowdy-compute-sdk version pin. Defaults to {@link COMPUTE_SDK_VERSION}. */
18
+ sdkVersion?: string;
19
+ /** Guest ABI version pin. Defaults to {@link COMPUTE_ABI_VERSION}. */
20
+ abiVersion?: number;
21
+ }
22
+ /** Options for {@link ComputeAPI.waitForCompile}. */
23
+ export interface WaitForCompileOptions {
24
+ /** Total budget in ms before giving up (default 120_000). */
25
+ timeoutMs?: number;
26
+ /** Poll interval in ms (default 2_000). */
27
+ intervalMs?: number;
28
+ }
29
+ /**
30
+ * Typed client for **Compute Modules** — server-side Rust/WebAssembly logic
31
+ * on the Game API (`client.compute`). Studios upload Rust source; the
32
+ * platform compiles it to WASM and runs it sandboxed on the game servers with
33
+ * fuel metering, triggers (tick / event / invoke), an app-scoped host data
34
+ * API, and replication egress. Modules are **server-only**: this client
35
+ * manages, invokes, and observes them — nothing executes client-side.
36
+ *
37
+ * Authoring mutations require the org **`manage_compute`** permission;
38
+ * monitoring queries require **`view_compute_diagnostics`**. `invoke` is
39
+ * gated per-export by the invoke trigger's policy.
40
+ *
41
+ * Docs: https://docs.crowdedkingdoms.com/game-api/compute-modules
42
+ */
43
+ export declare class ComputeAPI {
44
+ private gql;
45
+ constructor(gql: GraphQLClient);
46
+ /**
47
+ * Create or update a module's metadata (upsert key `(appId, name)`). New
48
+ * modules start disabled; enable after a successful compile. Set
49
+ * `alwaysOn: true` for world-simulation modules that must run without
50
+ * connected players (otherwise modules load lazily on realtime presence).
51
+ *
52
+ * Requires the org **`manage_compute`** permission.
53
+ *
54
+ * @throws {CrowdyGraphQLError} `FORBIDDEN` without the permission.
55
+ */
56
+ upsertModule(input: ComputeUpsertModuleMutationVariables['input']): Promise<ComputeUpsertModuleMutation['computeUpsertModule']>;
57
+ /**
58
+ * Upload an immutable source version and make it the deployed version. The
59
+ * source is validated server-side (Cargo.toml + `src/*.rs` only, dependency
60
+ * allowlist, size caps, no build-time code) and parked as
61
+ * `compileStatus: "pending"` until a game server compiles it — poll with
62
+ * {@link moduleVersions} or {@link waitForCompile}.
63
+ *
64
+ * Requires the org **`manage_compute`** permission.
65
+ *
66
+ * @param opts - App, module, `sourceFiles` map (stringified for you), and
67
+ * optional SDK/ABI pins (defaulted to the current platform pins).
68
+ */
69
+ deployVersion(opts: DeployVersionOptions): Promise<ComputeDeployVersionMutation['computeDeployVersion']>;
70
+ /**
71
+ * Enable or disable a module. Enabling requires a successfully compiled
72
+ * deployed version and resets the failure circuit; disabling stops all
73
+ * scheduling. Requires the org **`manage_compute`** permission.
74
+ */
75
+ setModuleEnabled(variables: ComputeSetModuleEnabledMutationVariables): Promise<ComputeSetModuleEnabledMutation['computeSetModuleEnabled']>;
76
+ /**
77
+ * Delete a module and (via cascade) its versions, triggers, and lease. Run
78
+ * history is retained for auditing. **Destructive.** Requires the org
79
+ * **`manage_compute`** permission.
80
+ *
81
+ * @returns `true` if a module was deleted.
82
+ */
83
+ deleteModule(variables: ComputeDeleteModuleMutationVariables): Promise<ComputeDeleteModuleMutation['computeDeleteModule']>;
84
+ /**
85
+ * Bind a trigger to a module: a tick loop (`triggerType: "tick"` +
86
+ * `tickHz`, clamped by the app policy), an event subscription
87
+ * (`triggerType: "event"` + `onEvent`: `function_invoked` |
88
+ * `property_changed` | `container_created` | `compute_event`), or a
89
+ * client-callable export (`triggerType: "invoke"` + `exportName` +
90
+ * optional `invokePolicyJson` authority tree; null policy = compute admins
91
+ * only). Requires the org **`manage_compute`** permission.
92
+ */
93
+ upsertTrigger(input: ComputeUpsertTriggerMutationVariables['input']): Promise<ComputeUpsertTriggerMutation['computeUpsertTrigger']>;
94
+ /**
95
+ * Delete a trigger by id. Requires the org **`manage_compute`** permission.
96
+ *
97
+ * @returns `true` if a trigger was deleted.
98
+ */
99
+ deleteTrigger(variables: ComputeDeleteTriggerMutationVariables): Promise<ComputeDeleteTriggerMutation['computeDeleteTrigger']>;
100
+ /**
101
+ * Set the app's compute policy (guardrails: kill switch, module count,
102
+ * tick-rate / fuel / memory / runtime / host-op / egress ceilings, circuit
103
+ * tuning). Omitted fields keep their current values; values above the
104
+ * platform ceilings are rejected. Requires the org **`manage_compute`**
105
+ * permission.
106
+ */
107
+ setPolicy(input: ComputeSetPolicyMutationVariables['input']): Promise<ComputeSetPolicyMutation['computeSetPolicy']>;
108
+ /**
109
+ * Invoke a module's client-callable export (an `invoke` trigger) as a
110
+ * **synchronous RPC**: the module runs server-side and its result comes
111
+ * back directly — unlike the spatial send surface, a failure (policy
112
+ * denial, fuel exhaustion, trap) is a thrown error, not a silent drop.
113
+ *
114
+ * Authorization: the export's invoke policy, or `manage_compute` holders
115
+ * only when no policy is set.
116
+ *
117
+ * @returns The invoke result; `resultJson` is set when the module's bytes
118
+ * parse as JSON (`resultBase64` always carries the raw bytes).
119
+ * @throws {CrowdyGraphQLError} `FORBIDDEN` on policy denial; `BAD_REQUEST`
120
+ * when the module is disabled or the call fails inside the sandbox.
121
+ */
122
+ invoke(variables: ComputeInvokeMutationVariables): Promise<ComputeInvokeMutation['computeInvoke']>;
123
+ /** List the app's modules. Requires **`view_compute_diagnostics`**. */
124
+ modules(variables: ComputeModulesQueryVariables): Promise<ComputeModulesQuery['computeModules']>;
125
+ /** Read one module by name. Requires **`view_compute_diagnostics`**. */
126
+ module(variables: ComputeModuleQueryVariables): Promise<ComputeModuleQuery['computeModule']>;
127
+ /**
128
+ * List a module's source versions, newest first, including compile
129
+ * status/log. Requires **`view_compute_diagnostics`**.
130
+ */
131
+ moduleVersions(variables: ComputeModuleVersionsQueryVariables): Promise<ComputeModuleVersionsQuery['computeModuleVersions']>;
132
+ /**
133
+ * Poll {@link moduleVersions} until the newest version's compile settles
134
+ * (`succeeded` or `failed`). Resolves with the settled version; **rejects**
135
+ * on compile failure (message includes the compile log) or timeout.
136
+ *
137
+ * Requires **`view_compute_diagnostics`**.
138
+ */
139
+ waitForCompile(appId: ComputeModuleVersionsQueryVariables['appId'], moduleName: string, opts?: WaitForCompileOptions): Promise<ComputeModuleVersionsQuery['computeModuleVersions'][number]>;
140
+ /**
141
+ * List trigger bindings, optionally filtered to one module. Requires
142
+ * **`view_compute_diagnostics`**.
143
+ */
144
+ moduleTriggers(variables: ComputeModuleTriggersQueryVariables): Promise<ComputeModuleTriggersQuery['computeModuleTriggers']>;
145
+ /**
146
+ * Read the app's compute policy (platform defaults when unset). Requires
147
+ * **`view_compute_diagnostics`**.
148
+ */
149
+ modulePolicy(variables: ComputeModulePolicyQueryVariables): Promise<ComputeModulePolicyQuery['computeModulePolicy']>;
150
+ /**
151
+ * List runs, newest first (module loads/`init`, every failure, and circuit
152
+ * probes; healthy high-frequency ticks are aggregated into per-minute
153
+ * usage instead of one row per tick). Requires
154
+ * **`view_compute_diagnostics`**.
155
+ */
156
+ moduleRuns(variables: ComputeModuleRunsQueryVariables): Promise<ComputeModuleRunsQuery['computeModuleRuns']>;
157
+ /**
158
+ * Aggregate activity over a recent window (default 60 minutes): run and
159
+ * failure counts, fuel, egress, per-module breakdown. Requires
160
+ * **`view_compute_diagnostics`**.
161
+ */
162
+ moduleStats(variables: ComputeModuleStatsQueryVariables): Promise<ComputeModuleStatsQuery['computeModuleStats']>;
163
+ /**
164
+ * Diagnostic log lines (guest `log()` output + failure lines), newest
165
+ * first. Requires **`view_compute_diagnostics`**.
166
+ */
167
+ moduleLogs(variables: ComputeModuleLogsQueryVariables): Promise<ComputeModuleLogsQuery['computeModuleLogs']>;
168
+ /**
169
+ * Snapshot of the app's compute footprint: module/version/trigger counts,
170
+ * 24h run activity, most-active modules. Requires
171
+ * **`view_compute_diagnostics`**.
172
+ */
173
+ appDiagnostics(variables: ComputeAppDiagnosticsQueryVariables): Promise<ComputeAppDiagnosticsQuery['computeAppDiagnostics']>;
174
+ }
175
+ //# sourceMappingURL=compute.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compute.d.ts","sourceRoot":"","sources":["../../src/domains/compute.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAElD,OAAO,EAEL,KAAK,2BAA2B,EAChC,KAAK,oCAAoC,EAEzC,KAAK,4BAA4B,EAEjC,KAAK,+BAA+B,EACpC,KAAK,wCAAwC,EAE7C,KAAK,2BAA2B,EAChC,KAAK,oCAAoC,EAEzC,KAAK,4BAA4B,EACjC,KAAK,qCAAqC,EAE1C,KAAK,4BAA4B,EACjC,KAAK,qCAAqC,EAE1C,KAAK,wBAAwB,EAC7B,KAAK,iCAAiC,EAEtC,KAAK,qBAAqB,EAC1B,KAAK,8BAA8B,EAEnC,KAAK,mBAAmB,EACxB,KAAK,4BAA4B,EAEjC,KAAK,kBAAkB,EACvB,KAAK,2BAA2B,EAEhC,KAAK,0BAA0B,EAC/B,KAAK,mCAAmC,EAExC,KAAK,0BAA0B,EAC/B,KAAK,mCAAmC,EAExC,KAAK,wBAAwB,EAC7B,KAAK,iCAAiC,EAEtC,KAAK,sBAAsB,EAC3B,KAAK,+BAA+B,EAEpC,KAAK,uBAAuB,EAC5B,KAAK,gCAAgC,EAErC,KAAK,sBAAsB,EAC3B,KAAK,+BAA+B,EAEpC,KAAK,0BAA0B,EAC/B,KAAK,mCAAmC,EACzC,MAAM,yBAAyB,CAAC;AAEjC,4EAA4E;AAC5E,eAAO,MAAM,mBAAmB,UAAU,CAAC;AAC3C,6DAA6D;AAC7D,eAAO,MAAM,mBAAmB,IAAI,CAAC;AAErC,oDAAoD;AACpD,MAAM,WAAW,oBAAoB;IACnC,KAAK,EAAE,wCAAwC,CAAC,OAAO,CAAC,CAAC;IACzD,UAAU,EAAE,MAAM,CAAC;IACnB;;;;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,OAAO,CAAC,0BAA0B,CAAC,uBAAuB,CAAC,CAAC;CAIhE"}
@@ -0,0 +1,232 @@
1
+ import { ComputeUpsertModuleDocument, ComputeDeployVersionDocument, ComputeSetModuleEnabledDocument, ComputeDeleteModuleDocument, ComputeUpsertTriggerDocument, ComputeDeleteTriggerDocument, ComputeSetPolicyDocument, ComputeInvokeDocument, ComputeModulesDocument, ComputeModuleDocument, ComputeModuleVersionsDocument, ComputeModuleTriggersDocument, ComputeModulePolicyDocument, ComputeModuleRunsDocument, ComputeModuleStatsDocument, ComputeModuleLogsDocument, ComputeAppDiagnosticsDocument, } from '../generated/graphql.js';
2
+ /** The crowdy-compute-sdk version the platform toolchain currently pins. */
3
+ export const COMPUTE_SDK_VERSION = '0.1.0';
4
+ /** The guest ABI version the platform currently supports. */
5
+ export const COMPUTE_ABI_VERSION = 0;
6
+ /**
7
+ * Typed client for **Compute Modules** — server-side Rust/WebAssembly logic
8
+ * on the Game API (`client.compute`). Studios upload Rust source; the
9
+ * platform compiles it to WASM and runs it sandboxed on the game servers with
10
+ * fuel metering, triggers (tick / event / invoke), an app-scoped host data
11
+ * API, and replication egress. Modules are **server-only**: this client
12
+ * manages, invokes, and observes them — nothing executes client-side.
13
+ *
14
+ * Authoring mutations require the org **`manage_compute`** permission;
15
+ * monitoring queries require **`view_compute_diagnostics`**. `invoke` is
16
+ * gated per-export by the invoke trigger's policy.
17
+ *
18
+ * Docs: https://docs.crowdedkingdoms.com/game-api/compute-modules
19
+ */
20
+ export class ComputeAPI {
21
+ constructor(gql) {
22
+ this.gql = gql;
23
+ }
24
+ // -- Authoring (manage_compute) ---------------------------------------------
25
+ /**
26
+ * Create or update a module's metadata (upsert key `(appId, name)`). New
27
+ * modules start disabled; enable after a successful compile. Set
28
+ * `alwaysOn: true` for world-simulation modules that must run without
29
+ * connected players (otherwise modules load lazily on realtime presence).
30
+ *
31
+ * Requires the org **`manage_compute`** permission.
32
+ *
33
+ * @throws {CrowdyGraphQLError} `FORBIDDEN` without the permission.
34
+ */
35
+ async upsertModule(input) {
36
+ const data = await this.gql.request(ComputeUpsertModuleDocument, { input });
37
+ return data.computeUpsertModule;
38
+ }
39
+ /**
40
+ * Upload an immutable source version and make it the deployed version. The
41
+ * source is validated server-side (Cargo.toml + `src/*.rs` only, dependency
42
+ * allowlist, size caps, no build-time code) and parked as
43
+ * `compileStatus: "pending"` until a game server compiles it — poll with
44
+ * {@link moduleVersions} or {@link waitForCompile}.
45
+ *
46
+ * Requires the org **`manage_compute`** permission.
47
+ *
48
+ * @param opts - App, module, `sourceFiles` map (stringified for you), and
49
+ * optional SDK/ABI pins (defaulted to the current platform pins).
50
+ */
51
+ async deployVersion(opts) {
52
+ const data = await this.gql.request(ComputeDeployVersionDocument, {
53
+ input: {
54
+ appId: opts.appId,
55
+ moduleName: opts.moduleName,
56
+ sourceFilesJson: JSON.stringify(opts.sourceFiles),
57
+ sdkVersion: opts.sdkVersion ?? COMPUTE_SDK_VERSION,
58
+ abiVersion: opts.abiVersion ?? COMPUTE_ABI_VERSION,
59
+ },
60
+ });
61
+ return data.computeDeployVersion;
62
+ }
63
+ /**
64
+ * Enable or disable a module. Enabling requires a successfully compiled
65
+ * deployed version and resets the failure circuit; disabling stops all
66
+ * scheduling. Requires the org **`manage_compute`** permission.
67
+ */
68
+ async setModuleEnabled(variables) {
69
+ const data = await this.gql.request(ComputeSetModuleEnabledDocument, variables);
70
+ return data.computeSetModuleEnabled;
71
+ }
72
+ /**
73
+ * Delete a module and (via cascade) its versions, triggers, and lease. Run
74
+ * history is retained for auditing. **Destructive.** Requires the org
75
+ * **`manage_compute`** permission.
76
+ *
77
+ * @returns `true` if a module was deleted.
78
+ */
79
+ async deleteModule(variables) {
80
+ const data = await this.gql.request(ComputeDeleteModuleDocument, variables);
81
+ return data.computeDeleteModule;
82
+ }
83
+ /**
84
+ * Bind a trigger to a module: a tick loop (`triggerType: "tick"` +
85
+ * `tickHz`, clamped by the app policy), an event subscription
86
+ * (`triggerType: "event"` + `onEvent`: `function_invoked` |
87
+ * `property_changed` | `container_created` | `compute_event`), or a
88
+ * client-callable export (`triggerType: "invoke"` + `exportName` +
89
+ * optional `invokePolicyJson` authority tree; null policy = compute admins
90
+ * only). Requires the org **`manage_compute`** permission.
91
+ */
92
+ async upsertTrigger(input) {
93
+ const data = await this.gql.request(ComputeUpsertTriggerDocument, { input });
94
+ return data.computeUpsertTrigger;
95
+ }
96
+ /**
97
+ * Delete a trigger by id. Requires the org **`manage_compute`** permission.
98
+ *
99
+ * @returns `true` if a trigger was deleted.
100
+ */
101
+ async deleteTrigger(variables) {
102
+ const data = await this.gql.request(ComputeDeleteTriggerDocument, variables);
103
+ return data.computeDeleteTrigger;
104
+ }
105
+ /**
106
+ * Set the app's compute policy (guardrails: kill switch, module count,
107
+ * tick-rate / fuel / memory / runtime / host-op / egress ceilings, circuit
108
+ * tuning). Omitted fields keep their current values; values above the
109
+ * platform ceilings are rejected. Requires the org **`manage_compute`**
110
+ * permission.
111
+ */
112
+ async setPolicy(input) {
113
+ const data = await this.gql.request(ComputeSetPolicyDocument, { input });
114
+ return data.computeSetPolicy;
115
+ }
116
+ // -- Invoke ------------------------------------------------------------------
117
+ /**
118
+ * Invoke a module's client-callable export (an `invoke` trigger) as a
119
+ * **synchronous RPC**: the module runs server-side and its result comes
120
+ * back directly — unlike the spatial send surface, a failure (policy
121
+ * denial, fuel exhaustion, trap) is a thrown error, not a silent drop.
122
+ *
123
+ * Authorization: the export's invoke policy, or `manage_compute` holders
124
+ * only when no policy is set.
125
+ *
126
+ * @returns The invoke result; `resultJson` is set when the module's bytes
127
+ * parse as JSON (`resultBase64` always carries the raw bytes).
128
+ * @throws {CrowdyGraphQLError} `FORBIDDEN` on policy denial; `BAD_REQUEST`
129
+ * when the module is disabled or the call fails inside the sandbox.
130
+ */
131
+ async invoke(variables) {
132
+ const data = await this.gql.request(ComputeInvokeDocument, variables);
133
+ return data.computeInvoke;
134
+ }
135
+ // -- Monitoring (view_compute_diagnostics) ------------------------------------
136
+ /** List the app's modules. Requires **`view_compute_diagnostics`**. */
137
+ async modules(variables) {
138
+ const data = await this.gql.request(ComputeModulesDocument, variables);
139
+ return data.computeModules;
140
+ }
141
+ /** Read one module by name. Requires **`view_compute_diagnostics`**. */
142
+ async module(variables) {
143
+ const data = await this.gql.request(ComputeModuleDocument, variables);
144
+ return data.computeModule;
145
+ }
146
+ /**
147
+ * List a module's source versions, newest first, including compile
148
+ * status/log. Requires **`view_compute_diagnostics`**.
149
+ */
150
+ async moduleVersions(variables) {
151
+ const data = await this.gql.request(ComputeModuleVersionsDocument, variables);
152
+ return data.computeModuleVersions;
153
+ }
154
+ /**
155
+ * Poll {@link moduleVersions} until the newest version's compile settles
156
+ * (`succeeded` or `failed`). Resolves with the settled version; **rejects**
157
+ * on compile failure (message includes the compile log) or timeout.
158
+ *
159
+ * Requires **`view_compute_diagnostics`**.
160
+ */
161
+ async waitForCompile(appId, moduleName, opts = {}) {
162
+ const timeoutMs = opts.timeoutMs ?? 120000;
163
+ const intervalMs = opts.intervalMs ?? 2000;
164
+ const deadline = Date.now() + timeoutMs;
165
+ for (;;) {
166
+ const versions = await this.moduleVersions({ appId, moduleName, limit: 1 });
167
+ const latest = versions[0];
168
+ if (latest?.compileStatus === 'succeeded')
169
+ return latest;
170
+ if (latest?.compileStatus === 'failed') {
171
+ throw new Error(`compute module '${moduleName}' compile failed:\n${latest.compileLog ?? '(no log)'}`);
172
+ }
173
+ if (Date.now() + intervalMs > deadline) {
174
+ throw new Error(`compute module '${moduleName}' compile did not settle within ${timeoutMs}ms` +
175
+ ` (status: ${latest?.compileStatus ?? 'no version found'})`);
176
+ }
177
+ await new Promise((r) => setTimeout(r, intervalMs));
178
+ }
179
+ }
180
+ /**
181
+ * List trigger bindings, optionally filtered to one module. Requires
182
+ * **`view_compute_diagnostics`**.
183
+ */
184
+ async moduleTriggers(variables) {
185
+ const data = await this.gql.request(ComputeModuleTriggersDocument, variables);
186
+ return data.computeModuleTriggers;
187
+ }
188
+ /**
189
+ * Read the app's compute policy (platform defaults when unset). Requires
190
+ * **`view_compute_diagnostics`**.
191
+ */
192
+ async modulePolicy(variables) {
193
+ const data = await this.gql.request(ComputeModulePolicyDocument, variables);
194
+ return data.computeModulePolicy;
195
+ }
196
+ /**
197
+ * List runs, newest first (module loads/`init`, every failure, and circuit
198
+ * probes; healthy high-frequency ticks are aggregated into per-minute
199
+ * usage instead of one row per tick). Requires
200
+ * **`view_compute_diagnostics`**.
201
+ */
202
+ async moduleRuns(variables) {
203
+ const data = await this.gql.request(ComputeModuleRunsDocument, variables);
204
+ return data.computeModuleRuns;
205
+ }
206
+ /**
207
+ * Aggregate activity over a recent window (default 60 minutes): run and
208
+ * failure counts, fuel, egress, per-module breakdown. Requires
209
+ * **`view_compute_diagnostics`**.
210
+ */
211
+ async moduleStats(variables) {
212
+ const data = await this.gql.request(ComputeModuleStatsDocument, variables);
213
+ return data.computeModuleStats;
214
+ }
215
+ /**
216
+ * Diagnostic log lines (guest `log()` output + failure lines), newest
217
+ * first. Requires **`view_compute_diagnostics`**.
218
+ */
219
+ async moduleLogs(variables) {
220
+ const data = await this.gql.request(ComputeModuleLogsDocument, variables);
221
+ return data.computeModuleLogs;
222
+ }
223
+ /**
224
+ * Snapshot of the app's compute footprint: module/version/trigger counts,
225
+ * 24h run activity, most-active modules. Requires
226
+ * **`view_compute_diagnostics`**.
227
+ */
228
+ async appDiagnostics(variables) {
229
+ const data = await this.gql.request(ComputeAppDiagnosticsDocument, variables);
230
+ return data.computeAppDiagnostics;
231
+ }
232
+ }