import type { GraphQLClient } from '../client.js'; import { type ComputeUpsertModuleMutation, type ComputeUpsertModuleMutationVariables, type ComputeDeployVersionMutation, type ComputeSetModuleEnabledMutation, type ComputeSetModuleEnabledMutationVariables, type ComputeResetBreakerMutation, type ComputeResetBreakerMutationVariables, 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 ComputeDeployTemplateMutation, type ComputeDeployTemplateMutationVariables, type ComputeTemplatesQuery, type ComputeTemplatesQueryVariables, type ComputeAppDiagnosticsQuery, type ComputeAppDiagnosticsQueryVariables } from '../generated/graphql.js'; /** The crowdy-compute-sdk version the platform toolchain currently pins. */ export declare const COMPUTE_SDK_VERSION = "0.1.3"; /** The guest ABI version the platform currently supports. */ export declare const COMPUTE_ABI_VERSION = 0; /** Options for {@link ComputeAPI.deployVersion}. */ export interface DeployVersionOptions { appId: ComputeSetModuleEnabledMutationVariables['appId']; moduleName: string; /** * Relative path -> file contents. Must include `Cargo.toml` and * `src/lib.rs`; only `.rs` files under `src/` plus `Cargo.toml` are * accepted by the server (crate allowlist, size caps, no build-time code). */ sourceFiles: Record; /** crowdy-compute-sdk version pin. Defaults to {@link COMPUTE_SDK_VERSION}. */ sdkVersion?: string; /** Guest ABI version pin. Defaults to {@link COMPUTE_ABI_VERSION}. */ abiVersion?: number; } /** Options for {@link ComputeAPI.waitForCompile}. */ export interface WaitForCompileOptions { /** Total budget in ms before giving up (default 120_000). */ timeoutMs?: number; /** Poll interval in ms (default 2_000). */ intervalMs?: number; } /** * Typed client for **Compute Modules** — server-side Rust/WebAssembly logic * on the Game API (`client.compute`). Studios upload Rust source; the * platform compiles it to WASM and runs it sandboxed on the game servers with * fuel metering, triggers (tick / event / invoke), an app-scoped host data * API, and replication egress. Modules are **server-only**: this client * manages, invokes, and observes them — nothing executes client-side. * * Authoring mutations require the org **`manage_compute`** permission; * monitoring queries require **`view_compute_diagnostics`**. `invoke` is * gated per-export by the invoke trigger's policy. * * Docs: https://docs.crowdedkingdoms.com/game-api/compute-modules */ export declare class ComputeAPI { private gql; constructor(gql: GraphQLClient); /** * Create or update a module's metadata (upsert key `(appId, name)`). New * modules start disabled; enable after a successful compile. Set * `alwaysOn: true` for world-simulation modules that must run without * connected players (otherwise modules load lazily on realtime presence). * * Requires the org **`manage_compute`** permission. * * @throws {CrowdyGraphQLError} `FORBIDDEN` without the permission. */ upsertModule(input: ComputeUpsertModuleMutationVariables['input']): Promise; /** * Upload an immutable source version and make it the deployed version. The * source is validated server-side (Cargo.toml + `src/*.rs` only, dependency * allowlist, size caps, no build-time code) and parked as * `compileStatus: "pending"` until a game server compiles it — poll with * {@link moduleVersions} or {@link waitForCompile}. * * Requires the org **`manage_compute`** permission. * * @param opts - App, module, `sourceFiles` map (stringified for you), and * optional SDK/ABI pins (defaulted to the current platform pins). */ deployVersion(opts: DeployVersionOptions): Promise; /** * Enable or disable a module. Enabling requires a successfully compiled * deployed version and resets the failure circuit; disabling stops all * scheduling. Requires the org **`manage_compute`** permission. * * This does **not** restart a module that was stopped for exceeding a * resource limit (`breakerLatchedAt`). Deploy a fixed version, or call * {@link resetBreaker}. */ setModuleEnabled(variables: ComputeSetModuleEnabledMutationVariables): Promise; /** * Restart a module that was stopped for exceeding a resource limit, without * deploying a new version. * * A module stopped this way reports `breakerLatchedAt` and a * `breakerReason` saying what it exceeded. Deploying a fix clears it * automatically and is the normal path; use this when the limit itself was * wrong, or the load is being accepted deliberately. The reason is recorded * with the module's history. Requires the org **`manage_compute`** * permission. */ resetBreaker(variables: ComputeResetBreakerMutationVariables): Promise; /** * Delete a module and (via cascade) its versions, triggers, and lease. Run * history is retained for auditing. **Destructive.** Requires the org * **`manage_compute`** permission. * * @returns `true` if a module was deleted. */ deleteModule(variables: ComputeDeleteModuleMutationVariables): Promise; /** * Bind a trigger to a module: a tick loop (`triggerType: "tick"` + * `tickHz`, clamped by the app policy), an event subscription * (`triggerType: "event"` + `onEvent`: `function_invoked` | * `property_changed` | `container_created` | `compute_event`), or a * client-callable export (`triggerType: "invoke"` + `exportName` + * optional `invokePolicyJson` authority tree; null policy = compute admins * only). Requires the org **`manage_compute`** permission. */ upsertTrigger(input: ComputeUpsertTriggerMutationVariables['input']): Promise; /** * Delete a trigger by id. Requires the org **`manage_compute`** permission. * * @returns `true` if a trigger was deleted. */ deleteTrigger(variables: ComputeDeleteTriggerMutationVariables): Promise; /** * Set the app's compute policy (guardrails: kill switch, module count, * tick-rate / fuel / memory / runtime / host-op / egress ceilings, circuit * tuning). Omitted fields keep their current values; values above the * platform ceilings are rejected. Requires the org **`manage_compute`** * permission. */ setPolicy(input: ComputeSetPolicyMutationVariables['input']): Promise; /** * Invoke a module's client-callable export (an `invoke` trigger) as a * **synchronous RPC**: the module runs server-side and its result comes * back directly — unlike the spatial send surface, a failure (policy * denial, fuel exhaustion, trap) is a thrown error, not a silent drop. * * Authorization: the export's invoke policy, or `manage_compute` holders * only when no policy is set. * * @returns The invoke result; `resultJson` is set when the module's bytes * parse as JSON (`resultBase64` always carries the raw bytes). * @throws {CrowdyGraphQLError} `FORBIDDEN` on policy denial; `BAD_REQUEST` * when the module is disabled or the call fails inside the sandbox. */ invoke(variables: ComputeInvokeMutationVariables): Promise; /** List the app's modules. Requires **`view_compute_diagnostics`**. */ modules(variables: ComputeModulesQueryVariables): Promise; /** Read one module by name. Requires **`view_compute_diagnostics`**. */ module(variables: ComputeModuleQueryVariables): Promise; /** * List a module's source versions, newest first, including compile * status/log. Requires **`view_compute_diagnostics`**. */ moduleVersions(variables: ComputeModuleVersionsQueryVariables): Promise; /** * The platform's engine-template registry: ready-made engines deployable * by name with {@link deployTemplate}. */ templates(variables: ComputeTemplatesQueryVariables): Promise; /** * Deploy a named engine template from the platform registry — one call * instead of the upsert/deploy/trigger/enable sequence. Compilation runs * asynchronously; follow with {@link waitForCompile}. */ deployTemplate(variables: ComputeDeployTemplateMutationVariables): Promise; /** * Poll {@link moduleVersions} until the newest version's compile settles * (`succeeded` or `failed`). Resolves with the settled version; **rejects** * on compile failure (message includes the compile log) or timeout. * * Requires **`view_compute_diagnostics`**. */ waitForCompile(appId: ComputeModuleVersionsQueryVariables['appId'], moduleName: string, opts?: WaitForCompileOptions): Promise; /** * List trigger bindings, optionally filtered to one module. Requires * **`view_compute_diagnostics`**. */ moduleTriggers(variables: ComputeModuleTriggersQueryVariables): Promise; /** * Read the app's compute policy (platform defaults when unset). Requires * **`view_compute_diagnostics`**. */ modulePolicy(variables: ComputeModulePolicyQueryVariables): Promise; /** * List runs, newest first (module loads/`init`, every failure, and circuit * probes; healthy high-frequency ticks are aggregated into per-minute * usage instead of one row per tick). Requires * **`view_compute_diagnostics`**. */ moduleRuns(variables: ComputeModuleRunsQueryVariables): Promise; /** * Aggregate activity over a recent window (default 60 minutes): run and * failure counts, fuel, egress, per-module breakdown. Requires * **`view_compute_diagnostics`**. */ moduleStats(variables: ComputeModuleStatsQueryVariables): Promise; /** * Diagnostic log lines (guest `log()` output + failure lines), newest * first. Requires **`view_compute_diagnostics`**. */ moduleLogs(variables: ComputeModuleLogsQueryVariables): Promise; /** * Snapshot of the app's compute footprint: module/version/trigger counts, * 24h run activity, most-active modules. Requires * **`view_compute_diagnostics`**. */ appDiagnostics(variables: ComputeAppDiagnosticsQueryVariables): Promise; } //# sourceMappingURL=compute.d.ts.map