@myclaw163/clawclaw-cli 0.10.11 → 0.10.13
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/bin/clawclaw-cli.mjs +15 -6
- package/bin/startup-trace.d.mts +9 -0
- package/bin/startup-trace.mjs +100 -0
- package/cli-runtime/assets/clawclaw-map.json +1782 -0
- package/cli-runtime/assets/clawclaw-spatial-facts.json +1383 -0
- package/cli-runtime/assets/clawclaw-spatial-model.txt +142 -0
- package/cli-runtime/channel/claude-channel-ipc-server.js +220 -0
- package/cli-runtime/channel/claude-channel-ipc.js +135 -0
- package/cli-runtime/channel/claude-channel-server.js +209 -0
- package/cli-runtime/cli.js +81 -0
- package/cli-runtime/commands/_schema.js +60 -0
- package/cli-runtime/commands/account.js +577 -0
- package/cli-runtime/commands/auth.js +140 -0
- package/cli-runtime/commands/behavior.js +422 -0
- package/cli-runtime/commands/capability.js +327 -0
- package/cli-runtime/commands/communication.js +339 -0
- package/cli-runtime/commands/competition.js +55 -0
- package/cli-runtime/commands/config.js +28 -0
- package/cli-runtime/commands/data.js +78 -0
- package/cli-runtime/commands/events.js +339 -0
- package/cli-runtime/commands/game/index.js +646 -0
- package/cli-runtime/commands/hub.js +152 -0
- package/cli-runtime/commands/load.js +22 -0
- package/cli-runtime/commands/memory.js +30 -0
- package/cli-runtime/commands/module-runtime-control.js +110 -0
- package/cli-runtime/commands/peek.js +38 -0
- package/cli-runtime/commands/perception.js +146 -0
- package/cli-runtime/commands/persona.js +165 -0
- package/cli-runtime/commands/prepare.js +878 -0
- package/cli-runtime/commands/setup/codex.js +244 -0
- package/cli-runtime/commands/setup/hermes.js +55 -0
- package/cli-runtime/commands/setup/index.js +15 -0
- package/cli-runtime/commands/setup/openclaw.js +103 -0
- package/cli-runtime/commands/skill.js +76 -0
- package/cli-runtime/commands/strategy.js +4 -0
- package/cli-runtime/commands/trigger.js +271 -0
- package/cli-runtime/commands/upgrade.js +112 -0
- package/cli-runtime/lib/account-guidance.js +97 -0
- package/cli-runtime/lib/agent-workspace-client.js +66 -0
- package/cli-runtime/lib/agent-workspace-runtime.js +174 -0
- package/cli-runtime/lib/agent-workspace-skills.js +453 -0
- package/cli-runtime/lib/agent-workspace-sync.js +812 -0
- package/cli-runtime/lib/auth.js +210 -0
- package/cli-runtime/lib/capability-cloud-presence.js +134 -0
- package/cli-runtime/lib/capability-cloud-refresh.js +263 -0
- package/cli-runtime/lib/capability-cloud-sync.js +385 -0
- package/cli-runtime/lib/capability-discovery.js +94 -0
- package/cli-runtime/lib/capability-load-diagnostics.js +121 -0
- package/cli-runtime/lib/capability-operation-name.js +24 -0
- package/cli-runtime/lib/capability-operation-rename.js +120 -0
- package/cli-runtime/lib/capability-selection.js +69 -0
- package/cli-runtime/lib/capability-workspace.js +214 -0
- package/cli-runtime/lib/command-error.js +25 -0
- package/cli-runtime/lib/command-meta.js +13 -0
- package/cli-runtime/lib/competition.js +77 -0
- package/cli-runtime/lib/custom-tts.js +363 -0
- package/cli-runtime/lib/desktop-auth.js +44 -0
- package/cli-runtime/lib/desktop-mode.js +12 -0
- package/cli-runtime/lib/diagnostics-config.js +82 -0
- package/cli-runtime/lib/game-client.js +602 -0
- package/cli-runtime/lib/game-context.js +117 -0
- package/cli-runtime/lib/gameplay-config.js +232 -0
- package/cli-runtime/lib/host-config-patcher.js +101 -0
- package/cli-runtime/lib/http-keepalive.js +15 -0
- package/cli-runtime/lib/http-transport.js +163 -0
- package/cli-runtime/lib/hub-client.js +292 -0
- package/cli-runtime/lib/hub-errors.js +51 -0
- package/cli-runtime/lib/hub-reminder.js +65 -0
- package/cli-runtime/lib/hub-unzip.js +52 -0
- package/cli-runtime/lib/init-command.js +160 -0
- package/cli-runtime/lib/load-context.js +97 -0
- package/cli-runtime/lib/load-startup-context.js +59 -0
- package/cli-runtime/lib/load-startup.js +23 -0
- package/cli-runtime/lib/lobby-host-context.js +70 -0
- package/cli-runtime/lib/match-state.js +61 -0
- package/cli-runtime/lib/normalize.js +28 -0
- package/cli-runtime/lib/package-skills.js +15 -0
- package/cli-runtime/lib/participation-leave.js +54 -0
- package/cli-runtime/lib/participation-status.js +73 -0
- package/cli-runtime/lib/perception-config.js +85 -0
- package/cli-runtime/lib/persona.js +157 -0
- package/cli-runtime/lib/room.js +108 -0
- package/cli-runtime/lib/runtime-cadence-config.js +18 -0
- package/cli-runtime/lib/server-registry.js +155 -0
- package/cli-runtime/lib/server-status.js +44 -0
- package/cli-runtime/lib/service-status.js +88 -0
- package/cli-runtime/lib/skill-host.js +246 -0
- package/cli-runtime/lib/skill-name-conflicts.js +89 -0
- package/cli-runtime/lib/skill-version.js +20 -0
- package/cli-runtime/lib/training-role.js +23 -0
- package/cli-runtime/lib/trigger-config.js +138 -0
- package/cli-runtime/lib/user-data.js +336 -0
- package/cli-runtime/lib/workspace-argv.js +35 -0
- package/cli-runtime/lib/workspace-runtime-lock.js +6 -0
- package/cli-runtime/lib/zip-store.js +78 -0
- package/cli-runtime/pipeline/canonical-event-presentation.js +32 -0
- package/cli-runtime/pipeline/event-format.js +921 -0
- package/cli-runtime/pipeline/event-hints.js +235 -0
- package/cli-runtime/pipeline/game-sync-event-normalization.js +228 -0
- package/cli-runtime/pipeline/player-projection.js +272 -0
- package/cli-runtime/pipeline/role-display.js +22 -0
- package/cli-runtime/runtime/auto-upgrade.js +30 -0
- package/cli-runtime/runtime/canonical-event-emitter.js +58 -0
- package/cli-runtime/runtime/canonical-monitor.js +332 -0
- package/cli-runtime/runtime/clawclaw/agent-ability-state.js +41 -0
- package/cli-runtime/runtime/clawclaw/agent-event-policy.js +58 -0
- package/cli-runtime/runtime/clawclaw/behavior-decision.js +84 -0
- package/cli-runtime/runtime/clawclaw/behavior-input-fields.js +212 -0
- package/cli-runtime/runtime/clawclaw/behavior-input.js +54 -0
- package/cli-runtime/runtime/clawclaw/behavior-observation-memory.js +106 -0
- package/cli-runtime/runtime/clawclaw/behavior-read-api.js +110 -0
- package/cli-runtime/runtime/clawclaw/behavior-reflex-control.js +97 -0
- package/cli-runtime/runtime/clawclaw/behavior-start-control.js +159 -0
- package/cli-runtime/runtime/clawclaw/index.js +3 -0
- package/cli-runtime/runtime/clawclaw/navigation/astar-path.js +244 -0
- package/cli-runtime/runtime/clawclaw/navigation/clawclaw-walkable.bin +0 -0
- package/cli-runtime/runtime/clawclaw/navigation/distance-field.js +136 -0
- package/cli-runtime/runtime/clawclaw/navigation/escape-planner.js +273 -0
- package/cli-runtime/runtime/clawclaw/navigation/hide-spots.js +31 -0
- package/cli-runtime/runtime/clawclaw/navigation/off-route-points.js +64 -0
- package/cli-runtime/runtime/clawclaw/navigation/walkable-grid.js +85 -0
- package/cli-runtime/runtime/clawclaw/notification-policy.js +59 -0
- package/cli-runtime/runtime/clawclaw/notification-turn.js +28 -0
- package/cli-runtime/runtime/clawclaw/notifications.js +65 -0
- package/cli-runtime/runtime/clawclaw/observation-frame-projector.js +94 -0
- package/cli-runtime/runtime/clawclaw/owner-lock-error.js +17 -0
- package/cli-runtime/runtime/clawclaw/owner-lock.js +219 -0
- package/cli-runtime/runtime/clawclaw/owner.js +1257 -0
- package/cli-runtime/runtime/clawclaw/perception-module-manifest.js +67 -0
- package/cli-runtime/runtime/clawclaw/perception-strategy-names.js +12 -0
- package/cli-runtime/runtime/clawclaw/persistence-compatibility.js +38 -0
- package/cli-runtime/runtime/clawclaw/plugins/action/action-plugin.js +604 -0
- package/cli-runtime/runtime/clawclaw/plugins/action/automated-action-normalization.js +67 -0
- package/cli-runtime/runtime/clawclaw/plugins/action/index.js +1 -0
- package/cli-runtime/runtime/clawclaw/plugins/assembly.js +134 -0
- package/cli-runtime/runtime/clawclaw/plugins/behavior/activation-manager.js +1 -0
- package/cli-runtime/runtime/clawclaw/plugins/behavior/behavior-action.js +26 -0
- package/cli-runtime/runtime/clawclaw/plugins/behavior/behavior-analysis-thread-host.js +21 -0
- package/cli-runtime/runtime/clawclaw/plugins/behavior/behavior-analysis-thread-host.ts +25 -0
- package/cli-runtime/runtime/clawclaw/plugins/behavior/behavior-catalog.js +90 -0
- package/cli-runtime/runtime/clawclaw/plugins/behavior/behavior-decision-history.js +60 -0
- package/cli-runtime/runtime/clawclaw/plugins/behavior/behavior-instance-snapshot.js +1 -0
- package/cli-runtime/runtime/clawclaw/plugins/behavior/behavior-manifest.js +136 -0
- package/cli-runtime/runtime/clawclaw/plugins/behavior/behavior-module-loader.js +230 -0
- package/cli-runtime/runtime/clawclaw/plugins/behavior/behavior-normalization.js +92 -0
- package/cli-runtime/runtime/clawclaw/plugins/behavior/behavior-plugin.js +162 -0
- package/cli-runtime/runtime/clawclaw/plugins/behavior/behavior-runner.js +20 -0
- package/cli-runtime/runtime/clawclaw/plugins/behavior/behavior-source.js +493 -0
- package/cli-runtime/runtime/clawclaw/plugins/behavior/behavior-worker-bridge.js +28 -0
- package/cli-runtime/runtime/clawclaw/plugins/behavior/control-driver.js +5 -0
- package/cli-runtime/runtime/clawclaw/plugins/behavior/index.js +11 -0
- package/cli-runtime/runtime/clawclaw/plugins/behavior/thread-behavior-executor.js +18 -0
- package/cli-runtime/runtime/clawclaw/plugins/behavior-input-source.js +233 -0
- package/cli-runtime/runtime/clawclaw/plugins/derived-event/derived-event-plugin.js +25 -0
- package/cli-runtime/runtime/clawclaw/plugins/derived-event/derived-event-rules.js +289 -0
- package/cli-runtime/runtime/clawclaw/plugins/derived-event/index.js +2 -0
- package/cli-runtime/runtime/clawclaw/plugins/derived-event/player-change-tracker.js +162 -0
- package/cli-runtime/runtime/clawclaw/plugins/derived-event/reminder-plugin.js +182 -0
- package/cli-runtime/runtime/clawclaw/plugins/derived-event/reminder-rules.js +1 -0
- package/cli-runtime/runtime/clawclaw/plugins/derived-event/reminder-runner.js +83 -0
- package/cli-runtime/runtime/clawclaw/plugins/derived-event/reminder-worker.js +35 -0
- package/cli-runtime/runtime/clawclaw/plugins/derived-event/reminder-worker.ts +33 -0
- package/cli-runtime/runtime/clawclaw/plugins/derived-event/state-change-rules.js +111 -0
- package/cli-runtime/runtime/clawclaw/plugins/derived-event/task-change-tracker.js +1 -0
- package/cli-runtime/runtime/clawclaw/plugins/game-query/context-capabilities.js +10 -0
- package/cli-runtime/runtime/clawclaw/plugins/game-query/game-query-plugin.js +196 -0
- package/cli-runtime/runtime/clawclaw/plugins/game-query/index.js +2 -0
- package/cli-runtime/runtime/clawclaw/plugins/index.js +9 -0
- package/cli-runtime/runtime/clawclaw/plugins/mailbox/adapters/claude-channel-adapter.js +24 -0
- package/cli-runtime/runtime/clawclaw/plugins/mailbox/adapters/claude-channel-socket.js +21 -0
- package/cli-runtime/runtime/clawclaw/plugins/mailbox/adapters/game-sync-perception-report-adapter.js +84 -0
- package/cli-runtime/runtime/clawclaw/plugins/mailbox/adapters/game-sync-runtime-report-adapter.js +54 -0
- package/cli-runtime/runtime/clawclaw/plugins/mailbox/agent-mailbox-coordinator.js +61 -0
- package/cli-runtime/runtime/clawclaw/plugins/mailbox/consumer-ids.js +10 -0
- package/cli-runtime/runtime/clawclaw/plugins/mailbox/desktop-event-socket.js +45 -0
- package/cli-runtime/runtime/clawclaw/plugins/mailbox/index.js +11 -0
- package/cli-runtime/runtime/clawclaw/plugins/mailbox/mailbox-event-batch-delivery.js +1 -0
- package/cli-runtime/runtime/clawclaw/plugins/mailbox/mailbox-plugin.js +13 -0
- package/cli-runtime/runtime/clawclaw/plugins/mailbox/mailbox-presentation.js +99 -0
- package/cli-runtime/runtime/clawclaw/plugins/mailbox/mailbox-service.js +84 -0
- package/cli-runtime/runtime/clawclaw/plugins/perception/contracts.js +14 -0
- package/cli-runtime/runtime/clawclaw/plugins/perception/index.js +11 -0
- package/cli-runtime/runtime/clawclaw/plugins/perception/map-concurrent.js +1 -0
- package/cli-runtime/runtime/clawclaw/plugins/perception/module-input-boundary.js +64 -0
- package/cli-runtime/runtime/clawclaw/plugins/perception/module-runner.js +182 -0
- package/cli-runtime/runtime/clawclaw/plugins/perception/notification-content.js +47 -0
- package/cli-runtime/runtime/clawclaw/plugins/perception/official-module-ids.js +13 -0
- package/cli-runtime/runtime/clawclaw/plugins/perception/perception-analysis-thread-pool.js +684 -0
- package/cli-runtime/runtime/clawclaw/plugins/perception/perception-analysis-thread-worker.js +145 -0
- package/cli-runtime/runtime/clawclaw/plugins/perception/perception-analysis-thread-worker.ts +252 -0
- package/cli-runtime/runtime/clawclaw/plugins/perception/perception-module-loader.js +78 -0
- package/cli-runtime/runtime/clawclaw/plugins/perception/perception-module-output.js +15 -0
- package/cli-runtime/runtime/clawclaw/plugins/perception/perception-module-plugin.js +144 -0
- package/cli-runtime/runtime/clawclaw/plugins/perception/perception-module-runner.js +22 -0
- package/cli-runtime/runtime/clawclaw/plugins/perception/perception-module-worker.js +18 -0
- package/cli-runtime/runtime/clawclaw/plugins/perception/perception-module-worker.ts +19 -0
- package/cli-runtime/runtime/clawclaw/plugins/perception/perception-plugin.js +1343 -0
- package/cli-runtime/runtime/clawclaw/plugins/perception/perception-reducer-thread-pool.js +522 -0
- package/cli-runtime/runtime/clawclaw/plugins/perception/perception-reducer-thread-worker.js +161 -0
- package/cli-runtime/runtime/clawclaw/plugins/perception/perception-reducer-thread-worker.ts +262 -0
- package/cli-runtime/runtime/clawclaw/plugins/perception/perception-source.js +489 -0
- package/cli-runtime/runtime/clawclaw/plugins/perception/perception-test-fixtures.js +31 -0
- package/cli-runtime/runtime/clawclaw/plugins/perception/replay.js +56 -0
- package/cli-runtime/runtime/clawclaw/plugins/perception/report-content.js +39 -0
- package/cli-runtime/runtime/clawclaw/plugins/perception/shared/math.js +1 -0
- package/cli-runtime/runtime/clawclaw/plugins/perception/spatial-facts.js +103 -0
- package/cli-runtime/runtime/clawclaw/plugins/perception/task-baseline.js +29 -0
- package/cli-runtime/runtime/clawclaw/plugins/plugin-api-version.js +89 -0
- package/cli-runtime/runtime/clawclaw/plugins/source/game-transport.js +204 -0
- package/cli-runtime/runtime/clawclaw/plugins/source/index.js +5 -0
- package/cli-runtime/runtime/clawclaw/plugins/source/room-transport.js +399 -0
- package/cli-runtime/runtime/clawclaw/plugins/source/source-plugin.js +2003 -0
- package/cli-runtime/runtime/clawclaw/plugins/source/source-transports.js +26 -0
- package/cli-runtime/runtime/clawclaw/plugins/source/types.js +0 -0
- package/cli-runtime/runtime/clawclaw/plugins/system-perception/rule-runner.js +90 -0
- package/cli-runtime/runtime/clawclaw/plugins/system-perception/sabotage-availability-rule.js +59 -0
- package/cli-runtime/runtime/clawclaw/plugins/system-perception/system-perceptions.js +241 -0
- package/cli-runtime/runtime/clawclaw/plugins/trigger/contracts.js +12 -0
- package/cli-runtime/runtime/clawclaw/plugins/trigger/index.js +4 -0
- package/cli-runtime/runtime/clawclaw/plugins/trigger/trigger-module-loader.js +105 -0
- package/cli-runtime/runtime/clawclaw/plugins/trigger/trigger-plugin.js +741 -0
- package/cli-runtime/runtime/clawclaw/plugins/trigger/trigger-source.js +372 -0
- package/cli-runtime/runtime/clawclaw/plugins/trigger/trigger-thread-pool.js +378 -0
- package/cli-runtime/runtime/clawclaw/plugins/trigger/trigger-thread-worker.js +118 -0
- package/cli-runtime/runtime/clawclaw/plugins/trigger/trigger-thread-worker.ts +168 -0
- package/cli-runtime/runtime/clawclaw/reaction-behavior-resolution.js +1 -0
- package/cli-runtime/runtime/clawclaw/reaction-manifest.js +62 -0
- package/cli-runtime/runtime/clawclaw/reminder-manifest.js +39 -0
- package/cli-runtime/runtime/clawclaw/runtime-cadence.js +28 -0
- package/cli-runtime/runtime/clawclaw/runtime-data-export.js +321 -0
- package/cli-runtime/runtime/clawclaw/runtime-state.js +51 -0
- package/cli-runtime/runtime/clawclaw/runtime.js +132 -0
- package/cli-runtime/runtime/clawclaw/spatial-api.js +48 -0
- package/cli-runtime/runtime/clawclaw/starting-owner-control.js +24 -0
- package/cli-runtime/runtime/clawclaw/strategy-memory-rpc.js +1 -0
- package/cli-runtime/runtime/clawclaw/strategy-memory.js +6 -0
- package/cli-runtime/runtime/clawclaw/task-choice-projection.js +72 -0
- package/cli-runtime/runtime/clawclaw-event-catalog.js +284 -0
- package/cli-runtime/runtime/clawclaw-position.js +0 -0
- package/cli-runtime/runtime/clawclaw-room-state.js +38 -0
- package/cli-runtime/runtime/framework/action-diagnostics.js +69 -0
- package/cli-runtime/runtime/framework/capability-registry.js +1 -0
- package/cli-runtime/runtime/framework/contracts.js +1 -0
- package/cli-runtime/runtime/framework/control/control-scheduler.js +1 -0
- package/cli-runtime/runtime/framework/control/domain-set.js +1 -0
- package/cli-runtime/runtime/framework/control/index.js +1 -0
- package/cli-runtime/runtime/framework/control/types.js +1 -0
- package/cli-runtime/runtime/framework/control-coordinator.js +1 -0
- package/cli-runtime/runtime/framework/events/event-catalog.js +1 -0
- package/cli-runtime/runtime/framework/events/event-delivery-service.js +1 -0
- package/cli-runtime/runtime/framework/events/event-ingress.js +1 -0
- package/cli-runtime/runtime/framework/events/event-repository.js +1 -0
- package/cli-runtime/runtime/framework/events/index.js +5 -0
- package/cli-runtime/runtime/framework/events/memory-event-repository.js +1 -0
- package/cli-runtime/runtime/framework/events/runtime-resume.js +1 -0
- package/cli-runtime/runtime/framework/events/sqlite-event-repository.js +6 -0
- package/cli-runtime/runtime/framework/events/test-helpers.js +56 -0
- package/cli-runtime/runtime/framework/events/types.js +1 -0
- package/cli-runtime/runtime/framework/index.js +7 -0
- package/cli-runtime/runtime/framework/load-node-sqlite.js +1 -0
- package/cli-runtime/runtime/framework/mailbox/coalescer.js +1 -0
- package/cli-runtime/runtime/framework/mailbox/host-notification-sink.js +1 -0
- package/cli-runtime/runtime/framework/mailbox/identity.js +1 -0
- package/cli-runtime/runtime/framework/mailbox/index.js +1 -0
- package/cli-runtime/runtime/framework/mailbox/mailbox-dispatcher.js +1 -0
- package/cli-runtime/runtime/framework/mailbox/mailbox-repository.js +1 -0
- package/cli-runtime/runtime/framework/mailbox/notification-projector.js +1 -0
- package/cli-runtime/runtime/framework/mailbox/types.js +1 -0
- package/cli-runtime/runtime/framework/modules/runtime-module-loader-hooks.mjs +2 -0
- package/cli-runtime/runtime/framework/modules/runtime-module-loader.js +31 -0
- package/cli-runtime/runtime/framework/modules/runtime-module-output.js +1 -0
- package/cli-runtime/runtime/framework/modules/runtime-module-worker-bootstrap.mjs +3 -0
- package/cli-runtime/runtime/framework/participation-manager.js +1 -0
- package/cli-runtime/runtime/framework/persistence/async-sqlite-persistence-worker.js +1 -0
- package/cli-runtime/runtime/framework/persistence/async-sqlite-persistence-worker.ts +2 -0
- package/cli-runtime/runtime/framework/persistence/memory-first-persistence.js +9 -0
- package/cli-runtime/runtime/framework/plugins/contracts.js +1 -0
- package/cli-runtime/runtime/framework/plugins/index.js +1 -0
- package/cli-runtime/runtime/framework/plugins/runtime-event-identity.js +1 -0
- package/cli-runtime/runtime/framework/plugins/runtime-input-journal.js +1 -0
- package/cli-runtime/runtime/framework/plugins/runtime-plugin-scheduler.js +1 -0
- package/cli-runtime/runtime/framework/runtime.js +12 -0
- package/cli-runtime/runtime/framework/serial-task-queue.js +1 -0
- package/cli-runtime/runtime/framework/state/contracts.js +1 -0
- package/cli-runtime/runtime/framework/state/current-state-store.js +1 -0
- package/cli-runtime/runtime/framework/state/durable-agent-state-snapshot.js +1 -0
- package/cli-runtime/runtime/framework/state/freshness.js +1 -0
- package/cli-runtime/runtime/framework/state/history/contracts.js +1 -0
- package/cli-runtime/runtime/framework/state/history/history-writer.js +1 -0
- package/cli-runtime/runtime/framework/state/history/memory-state-history-repository.js +1 -0
- package/cli-runtime/runtime/framework/state/history/sqlite-state-history-repository.js +1 -0
- package/cli-runtime/runtime/framework/state/history/trajectory-projector.js +1 -0
- package/cli-runtime/runtime/framework/state/index.js +1 -0
- package/cli-runtime/runtime/framework/state/state-ingress.js +1 -0
- package/cli-runtime/runtime/framework/state/state-provider.js +1 -0
- package/cli-runtime/runtime/framework/state/types.js +1 -0
- package/cli-runtime/runtime/game-sync-ingress-protocol.js +0 -0
- package/cli-runtime/runtime/game-sync-ingress-worker.js +310 -0
- package/cli-runtime/runtime/game-sync-ingress-worker.ts +274 -0
- package/cli-runtime/runtime/game-sync-protocol.js +278 -0
- package/cli-runtime/runtime/host-monitor-rate-gate.js +1 -0
- package/cli-runtime/runtime/mailbox-host-relay.js +1 -0
- package/cli-runtime/runtime/observability/detail-capture.js +35 -0
- package/cli-runtime/runtime/observability/factory.js +137 -0
- package/cli-runtime/runtime/observability/index.js +6 -0
- package/cli-runtime/runtime/observability/process-timing.js +1 -0
- package/cli-runtime/runtime/observability/recorder.js +1 -0
- package/cli-runtime/runtime/observability/redaction.js +1 -0
- package/cli-runtime/runtime/observability/reporter.js +1 -0
- package/cli-runtime/runtime/observability/sinks.js +1 -0
- package/cli-runtime/runtime/observability/types.js +1 -0
- package/cli-runtime/runtime/owner-control.js +59 -0
- package/cli-runtime/runtime/parent-process-watch.js +1 -0
- package/cli-runtime/runtime/pending-event-handoff.js +48 -0
- package/cli-runtime/runtime/process-identity.js +45 -0
- package/cli-runtime/runtime/raw-ws-log.js +181 -0
- package/cli-runtime/runtime/runtime-logger.js +79 -0
- package/cli-runtime/runtime/threaded-ws-client.js +263 -0
- package/cli-runtime/runtime/ws-client.js +563 -0
- package/cli-runtime/sdk/action.js +133 -0
- package/cli-runtime/sdk/action.ts +160 -0
- package/cli-runtime/sdk/behavior-plugin/index.js +23 -0
- package/cli-runtime/sdk/behavior-plugin/index.ts +341 -0
- package/cli-runtime/sdk/behavior-toolkit/corpse-search.js +56 -0
- package/cli-runtime/sdk/behavior-toolkit/corpse-search.ts +87 -0
- package/cli-runtime/sdk/behavior-toolkit/escape.js +25 -0
- package/cli-runtime/sdk/behavior-toolkit/escape.ts +40 -0
- package/cli-runtime/sdk/behavior-toolkit/index.js +7 -0
- package/cli-runtime/sdk/behavior-toolkit/index.ts +7 -0
- package/cli-runtime/sdk/behavior-toolkit/kill-flow.js +239 -0
- package/cli-runtime/sdk/behavior-toolkit/kill-flow.ts +299 -0
- package/cli-runtime/sdk/behavior-toolkit/model.js +183 -0
- package/cli-runtime/sdk/behavior-toolkit/model.ts +265 -0
- package/cli-runtime/sdk/behavior-toolkit/move-gate.js +30 -0
- package/cli-runtime/sdk/behavior-toolkit/move-gate.ts +52 -0
- package/cli-runtime/sdk/behavior-toolkit/patrol.js +39 -0
- package/cli-runtime/sdk/behavior-toolkit/patrol.ts +53 -0
- package/cli-runtime/sdk/behavior-toolkit/search.js +81 -0
- package/cli-runtime/sdk/behavior-toolkit/search.ts +102 -0
- package/cli-runtime/sdk/index.js +78 -0
- package/cli-runtime/sdk/index.ts +136 -0
- package/cli-runtime/sdk/module-input/index.js +0 -0
- package/cli-runtime/sdk/module-input/index.ts +310 -0
- package/cli-runtime/sdk/perception-plugin/index.js +79 -0
- package/cli-runtime/sdk/perception-plugin/index.ts +251 -0
- package/cli-runtime/sdk/perception-plugin/lifecycle.js +18 -0
- package/cli-runtime/sdk/perception-plugin/lifecycle.ts +15 -0
- package/cli-runtime/sdk/perception-plugin/math.js +99 -0
- package/cli-runtime/sdk/perception-plugin/math.ts +107 -0
- package/cli-runtime/sdk/perception-plugin/module.js +4 -0
- package/cli-runtime/sdk/perception-plugin/module.ts +80 -0
- package/cli-runtime/sdk/perception-plugin/reaction.js +6 -0
- package/cli-runtime/sdk/perception-plugin/reaction.ts +79 -0
- package/cli-runtime/sdk/perception-plugin/reminder-rules.js +131 -0
- package/cli-runtime/sdk/perception-plugin/reminder-rules.ts +89 -0
- package/cli-runtime/sdk/perception-plugin/reminder.js +8 -0
- package/cli-runtime/sdk/perception-plugin/reminder.ts +68 -0
- package/cli-runtime/sdk/perception-plugin/task-change-tracker.js +150 -0
- package/cli-runtime/sdk/perception-plugin/task-change-tracker.ts +258 -0
- package/cli-runtime/sdk/resource-metadata.js +27 -0
- package/cli-runtime/sdk/resource-metadata.ts +66 -0
- package/cli-runtime/sdk/strategy-memory.js +1 -0
- package/cli-runtime/sdk/strategy-memory.ts +1 -0
- package/cli-runtime/sdk/strategy-plugin/index.js +6 -0
- package/cli-runtime/sdk/strategy-plugin/index.ts +36 -0
- package/cli-runtime/sdk/task-availability.js +56 -0
- package/cli-runtime/sdk/task-availability.ts +70 -0
- package/cli-runtime/sdk/trigger-plugin/index.js +16 -0
- package/cli-runtime/sdk/trigger-plugin/index.ts +130 -0
- package/cli-runtime/sdk/types.js +25 -0
- package/cli-runtime/sdk/types.ts +165 -0
- package/cli-runtime/short-command/classifier.js +129 -0
- package/cli-runtime/short-command/index.js +7 -0
- package/cli-runtime/short-command/presenter.js +225 -0
- package/cli-runtime/short-command/process-io.js +13 -0
- package/cli-runtime/short-command/response-contract.js +24 -0
- package/cli-runtime/short-command/runner.js +94 -0
- package/cli-runtime/short-command/sensitive-data-filter.js +92 -0
- package/cli-runtime/short-command/transport-response.js +57 -0
- package/cli-runtime/short-command/types.js +0 -0
- package/dist/strategy-worker/runtime/clawclaw/plugins/behavior/host.js +21 -29
- package/dist/strategy-worker/runtime/clawclaw/plugins/behavior/sdk-sdk.js +76 -6
- package/docs/configuration.md +13 -0
- package/package.json +7 -4
- package/scripts/build-cli.mjs +34 -0
- package/skills/clawclaw/SKILL.md +1 -1
- package/skills/clawclaw/references/STREAM.md +1 -0
- package/skills/clawclaw-start/SKILL.md +1 -0
- package/skills/clawclaw-start/references/STARTUP.md +1 -0
- package/src/cli.ts +75 -77
- package/src/commands/auth.ts +3 -2
- package/src/commands/game/index.ts +33 -9
- package/src/commands/prepare.ts +34 -18
- package/src/lib/agent-workspace-client.ts +12 -9
- package/src/lib/game-client.ts +1 -1
- package/src/lib/http-transport.ts +17 -2
- package/src/lib/hub-client.ts +10 -7
- package/src/pipeline/event-format.ts +2 -0
- package/src/pipeline/event-hints.ts +6 -0
- package/src/runtime/clawclaw/notification-policy.ts +1 -1
- package/src/runtime/clawclaw/owner-lock.ts +3 -2
- package/src/runtime/clawclaw/owner.ts +36 -10
- package/src/runtime/clawclaw/plugins/behavior/behavior-worker-bridge.ts +1 -1
- package/src/runtime/clawclaw/plugins/mailbox/desktop-event-socket.ts +19 -0
- package/src/runtime/clawclaw/plugins/mailbox/mailbox-service.ts +1 -0
- package/src/runtime/clawclaw/plugins/source/source-plugin.ts +33 -9
- package/src/runtime/clawclaw-event-catalog.ts +1 -0
- package/src/runtime/framework/modules/runtime-module-loader.ts +24 -29
- package/src/runtime/process-identity.ts +44 -0
|
@@ -0,0 +1,602 @@
|
|
|
1
|
+
import { accountRequiredMessage } from "./desktop-mode.js";
|
|
2
|
+
import { WsConnectionState } from "../sdk/types.js";
|
|
3
|
+
import { AuthStore } from "./auth.js";
|
|
4
|
+
import { ServerRegistry } from "./server-registry.js";
|
|
5
|
+
import { HttpTransport, ApiError } from "./http-transport.js";
|
|
6
|
+
import {
|
|
7
|
+
WsClient
|
|
8
|
+
} from "../runtime/ws-client.js";
|
|
9
|
+
import { RuntimeLogger } from "../runtime/runtime-logger.js";
|
|
10
|
+
import { ThreadedWsClient } from "../runtime/threaded-ws-client.js";
|
|
11
|
+
import { synthesizeConfiguredTts } from "./custom-tts.js";
|
|
12
|
+
import { lobbyHostHeaders, resolveLobbyHostContext, validateLobbyHostContext } from "./lobby-host-context.js";
|
|
13
|
+
import { ApiError as ApiError2 } from "./http-transport.js";
|
|
14
|
+
function agentMetadataHeaders(options) {
|
|
15
|
+
const headers = {};
|
|
16
|
+
if (options.agentType) headers["X-Agent-Type"] = options.agentType;
|
|
17
|
+
if (options.monitorStatus) headers["X-Monitor-Status"] = options.monitorStatus;
|
|
18
|
+
if (options.llmModel) headers["X-LLM-Model"] = options.llmModel;
|
|
19
|
+
return Object.keys(headers).length > 0 ? headers : void 0;
|
|
20
|
+
}
|
|
21
|
+
class GameClient {
|
|
22
|
+
resolvedHostContext;
|
|
23
|
+
hostEnvironment;
|
|
24
|
+
http;
|
|
25
|
+
ws = null;
|
|
26
|
+
gameSyncIngress;
|
|
27
|
+
closingIngress = /* @__PURE__ */ new Set();
|
|
28
|
+
transportGeneration = 0;
|
|
29
|
+
/** Last continuously reduced v2 baseline, retained across failed socket replacements. */
|
|
30
|
+
gameSyncResumeState;
|
|
31
|
+
/** Queue/room-owned game identity that the retained baseline must belong to. */
|
|
32
|
+
expectedGameSyncGameId;
|
|
33
|
+
wsCloseHandlers = [];
|
|
34
|
+
wsInputFrameHandlers = [];
|
|
35
|
+
wsConnectionOpenedHandlers = [];
|
|
36
|
+
wsLivenessHandlers = [];
|
|
37
|
+
wsProtocolErrorHandlers = [];
|
|
38
|
+
wsRecoveryStartedHandlers = [];
|
|
39
|
+
registry;
|
|
40
|
+
apiKey;
|
|
41
|
+
enableWs;
|
|
42
|
+
rawWsMessageSink;
|
|
43
|
+
log = new RuntimeLogger();
|
|
44
|
+
lastCustomTtsWarning = null;
|
|
45
|
+
/** 最近一次 TTS 降级警告,供 CLI 命令纳入 stdout JSON 输出。 */
|
|
46
|
+
get ttsWarning() {
|
|
47
|
+
return this.lastCustomTtsWarning;
|
|
48
|
+
}
|
|
49
|
+
constructor(config) {
|
|
50
|
+
this.resolvedHostContext = config.hostContext ? validateLobbyHostContext(config.hostContext) : void 0;
|
|
51
|
+
this.hostEnvironment = {
|
|
52
|
+
CLAWCLAW_IS_DESKTOP: process.env.CLAWCLAW_IS_DESKTOP,
|
|
53
|
+
CLAWCLAW_HOST_INSTANCE_ID: process.env.CLAWCLAW_HOST_INSTANCE_ID,
|
|
54
|
+
CLAWCLAW_HOST_SESSION_ID: process.env.CLAWCLAW_HOST_SESSION_ID
|
|
55
|
+
};
|
|
56
|
+
this.apiKey = config.apiKey;
|
|
57
|
+
this.enableWs = config.enableWs ?? false;
|
|
58
|
+
this.rawWsMessageSink = config.rawWsMessageSink;
|
|
59
|
+
this.gameSyncIngress = config.gameSyncIngress;
|
|
60
|
+
this.registry = new ServerRegistry({
|
|
61
|
+
lobbyUrl: config.lobbyUrl,
|
|
62
|
+
gameServerUrl: config.gameServerUrl,
|
|
63
|
+
agentName: config.agentName
|
|
64
|
+
});
|
|
65
|
+
this.http = new HttpTransport(config.apiKey, this.registry, {}, config.signal);
|
|
66
|
+
}
|
|
67
|
+
// ─── Factory Methods ───
|
|
68
|
+
/**
|
|
69
|
+
* Create GameClient from active auth profile.
|
|
70
|
+
* Used by both runtime listeners (ws: true) and CLI commands (ws: false).
|
|
71
|
+
*/
|
|
72
|
+
static fromAuth(opts) {
|
|
73
|
+
const store = opts?.authStore ?? new AuthStore();
|
|
74
|
+
const profile = store.getActive();
|
|
75
|
+
if (!profile) {
|
|
76
|
+
throw new Error(accountRequiredMessage("No active auth profile. Run: clawclaw-cli account register"));
|
|
77
|
+
}
|
|
78
|
+
return new GameClient({
|
|
79
|
+
lobbyUrl: profile.serverUrl,
|
|
80
|
+
gameServerUrl: profile.gameServerUrl,
|
|
81
|
+
apiKey: profile.apiKey,
|
|
82
|
+
agentName: profile.agentName,
|
|
83
|
+
enableWs: opts?.ws ?? false,
|
|
84
|
+
rawWsMessageSink: opts?.rawWsMessageSink,
|
|
85
|
+
signal: opts?.signal
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
/** Get current server addresses. */
|
|
89
|
+
get addresses() {
|
|
90
|
+
return this.registry.addresses;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Structured transport result for migrated short-command handlers. Existing
|
|
94
|
+
* typed methods keep their legacy throw/JSON behavior.
|
|
95
|
+
*/
|
|
96
|
+
requestRaw(method, path, body, headers) {
|
|
97
|
+
return this.http.requestRaw(method, path, body, headers);
|
|
98
|
+
}
|
|
99
|
+
// ─── Game API (→ game server) ───
|
|
100
|
+
/** GameSync v2 carries observations only; all Actions use acknowledged HTTP. */
|
|
101
|
+
async submitAction(action) {
|
|
102
|
+
const preparedAction = await this.prepareAction(action);
|
|
103
|
+
return this.http.post("/api/v1/game/action", preparedAction);
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Submit through the acknowledged HTTP request/response boundary even while
|
|
107
|
+
* the owner has an active WS stream. Agent-facing commands must not call a
|
|
108
|
+
* fire-and-forget WS send a confirmed success.
|
|
109
|
+
*/
|
|
110
|
+
async submitActionConfirmed(action) {
|
|
111
|
+
const preparedAction = await this.prepareActionForConfirmedSubmission(action);
|
|
112
|
+
return this.submitPreparedActionConfirmed(preparedAction);
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Reversible preparation phase for an acknowledged Action. Runtime adapters
|
|
116
|
+
* may revalidate local authority after this resolves and before calling the
|
|
117
|
+
* corresponding submit method.
|
|
118
|
+
*/
|
|
119
|
+
async prepareActionForConfirmedSubmission(action) {
|
|
120
|
+
return this.prepareAction(action);
|
|
121
|
+
}
|
|
122
|
+
/** Irreversible confirmed Action endpoint; input must already be prepared. */
|
|
123
|
+
async submitPreparedActionConfirmed(action, signal) {
|
|
124
|
+
return this.http.postRaw("/api/v1/game/action", action, void 0, signal);
|
|
125
|
+
}
|
|
126
|
+
async prepareAction(action) {
|
|
127
|
+
let preparedAction = action;
|
|
128
|
+
if (action.action === "speech" && typeof action.text === "string" && action.text.length > 0 && !action.audio_url) {
|
|
129
|
+
try {
|
|
130
|
+
const synthesized = await synthesizeConfiguredTts(action.text);
|
|
131
|
+
if (synthesized) {
|
|
132
|
+
const { audio_url } = await this.uploadAudio(
|
|
133
|
+
synthesized.audio,
|
|
134
|
+
synthesized.filename,
|
|
135
|
+
synthesized.contentType
|
|
136
|
+
);
|
|
137
|
+
preparedAction = { ...action, audio_url };
|
|
138
|
+
this.lastCustomTtsWarning = null;
|
|
139
|
+
}
|
|
140
|
+
} catch (err) {
|
|
141
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
142
|
+
if (message !== this.lastCustomTtsWarning) {
|
|
143
|
+
console.error(`Custom TTS failed: ${message}. Sending speech without audio.`);
|
|
144
|
+
this.lastCustomTtsWarning = message;
|
|
145
|
+
}
|
|
146
|
+
this.log.warn("CUSTOM_TTS_FAILED", message);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
return preparedAction;
|
|
150
|
+
}
|
|
151
|
+
async uploadAudio(filePathOrBuffer, filename, contentType = "audio/mpeg") {
|
|
152
|
+
const form = new FormData();
|
|
153
|
+
if (typeof filePathOrBuffer === "string") {
|
|
154
|
+
const { existsSync, readFileSync } = await import("fs");
|
|
155
|
+
const { basename } = await import("path");
|
|
156
|
+
if (!existsSync(filePathOrBuffer)) {
|
|
157
|
+
throw new Error(`Audio file not found: ${filePathOrBuffer}`);
|
|
158
|
+
}
|
|
159
|
+
const buffer = readFileSync(filePathOrBuffer);
|
|
160
|
+
form.append("file", new Blob([buffer], { type: contentType }), filename ?? basename(filePathOrBuffer));
|
|
161
|
+
} else {
|
|
162
|
+
form.append("file", new Blob([filePathOrBuffer], { type: contentType }), filename ?? "audio.mp3");
|
|
163
|
+
}
|
|
164
|
+
const response = await this.http.postRaw("/api/v1/agents/upload_audio", form);
|
|
165
|
+
const result = response.body.kind === "json" ? response.body.value : null;
|
|
166
|
+
if (response.status < 200 || response.status >= 300 || !result || typeof result !== "object" || result.success === false) {
|
|
167
|
+
throw new ApiError(
|
|
168
|
+
response.status,
|
|
169
|
+
response.body.rawText,
|
|
170
|
+
"POST",
|
|
171
|
+
"/api/v1/agents/upload_audio",
|
|
172
|
+
response
|
|
173
|
+
);
|
|
174
|
+
}
|
|
175
|
+
const audioUrl = result?.audio_url ?? result?.data?.audio_url;
|
|
176
|
+
if (!audioUrl) {
|
|
177
|
+
throw new Error(`upload_audio: unexpected response: ${JSON.stringify(result)}`);
|
|
178
|
+
}
|
|
179
|
+
return { audio_url: audioUrl };
|
|
180
|
+
}
|
|
181
|
+
// ─── Agent API (→ lobby) ───
|
|
182
|
+
/**
|
|
183
|
+
* Register a new agent. No auth required.
|
|
184
|
+
* Server expects multipart/form-data with optional name/description/avatar fields.
|
|
185
|
+
*/
|
|
186
|
+
async registerAgent(opts) {
|
|
187
|
+
const form = new FormData();
|
|
188
|
+
if (opts.name) form.append("name", opts.name);
|
|
189
|
+
if (opts.description) form.append("description", opts.description);
|
|
190
|
+
if (opts.inviteCode) form.append("invite_code", opts.inviteCode);
|
|
191
|
+
if (opts.avatarUrl) form.append("avatar_url", opts.avatarUrl);
|
|
192
|
+
if (opts.avatarFile) {
|
|
193
|
+
const { readFileSync } = await import("fs");
|
|
194
|
+
const { basename } = await import("path");
|
|
195
|
+
const buf = readFileSync(opts.avatarFile);
|
|
196
|
+
form.append("avatar_file", new Blob([buf]), basename(opts.avatarFile));
|
|
197
|
+
}
|
|
198
|
+
return this.http.post("/api/v1/agents/register", form);
|
|
199
|
+
}
|
|
200
|
+
async renameAgent(name) {
|
|
201
|
+
return this.http.request("PATCH", "/api/v1/agents/name", { name });
|
|
202
|
+
}
|
|
203
|
+
async login(apiKey) {
|
|
204
|
+
return this.http.post("/api/v1/agents/login", { api_key: apiKey });
|
|
205
|
+
}
|
|
206
|
+
async getMe() {
|
|
207
|
+
return this.http.get("/api/v1/agents/me");
|
|
208
|
+
}
|
|
209
|
+
// ─── Queue API (→ lobby, auto game server discovery) ───
|
|
210
|
+
/** Lazy so login, Hub and read-only status remain usable before host setup. */
|
|
211
|
+
get lobbyHostContext() {
|
|
212
|
+
return this.resolvedHostContext ??= resolveLobbyHostContext(this.hostEnvironment);
|
|
213
|
+
}
|
|
214
|
+
async enterLobby(path, body, metadata) {
|
|
215
|
+
const response = await this.http.postRaw(path, body, {
|
|
216
|
+
...agentMetadataHeaders(metadata),
|
|
217
|
+
...lobbyHostHeaders(this.lobbyHostContext)
|
|
218
|
+
});
|
|
219
|
+
if (response.status < 200 || response.status >= 300 || response.body.kind === "json" && response.body.value?.success === false) {
|
|
220
|
+
throw new ApiError(response.status, response.body.rawText, "POST", path, response);
|
|
221
|
+
}
|
|
222
|
+
if (response.body.kind !== "json") throw new SyntaxError(`Unexpected non-JSON response from ${path}`);
|
|
223
|
+
return response.body.value;
|
|
224
|
+
}
|
|
225
|
+
async joinQueue(options = "clawclaw") {
|
|
226
|
+
const gameType = typeof options === "string" ? options : options.gameType ?? "clawclaw";
|
|
227
|
+
const mode = typeof options === "string" ? "match" : options.mode ?? "match";
|
|
228
|
+
const agentType = typeof options === "string" ? void 0 : options.agentType;
|
|
229
|
+
const monitorStatus = typeof options === "string" ? void 0 : options.monitorStatus;
|
|
230
|
+
const llmModel = typeof options === "string" ? void 0 : options.llmModel;
|
|
231
|
+
const result = await this.enterLobby("/api/v1/queue/join", { game_type: gameType, mode }, { agentType, monitorStatus, llmModel });
|
|
232
|
+
this.registry.updateFromQueueResponse(result);
|
|
233
|
+
return result;
|
|
234
|
+
}
|
|
235
|
+
async getQueueStatus(gameType) {
|
|
236
|
+
const query = gameType ? `?game_type=${encodeURIComponent(gameType)}` : "";
|
|
237
|
+
const result = await this.http.get(`/api/v1/queue/status${query}`);
|
|
238
|
+
this.registry.updateFromQueueResponse(result);
|
|
239
|
+
return result;
|
|
240
|
+
}
|
|
241
|
+
async leaveQueue(gameType) {
|
|
242
|
+
const query = gameType ? `?game_type=${encodeURIComponent(gameType)}` : "";
|
|
243
|
+
return this.http.post(`/api/v1/queue/leave${query}`, void 0, { "X-Client-Type": "agent" });
|
|
244
|
+
}
|
|
245
|
+
/** Leave the active game. Normal matches require death; a training owner may abandon while alive. */
|
|
246
|
+
async leaveGame() {
|
|
247
|
+
return this.http.post("/api/v1/game/leave");
|
|
248
|
+
}
|
|
249
|
+
// ─── Room API (→ lobby) ───
|
|
250
|
+
async createRoom(options = {}) {
|
|
251
|
+
const normalized = typeof options === "string" ? { roomType: options } : options;
|
|
252
|
+
return normalized.roomType ? this.enterLobby("/api/v1/room/create", { room_type: normalized.roomType }, normalized) : this.enterLobby("/api/v1/room/create", void 0, normalized);
|
|
253
|
+
}
|
|
254
|
+
async joinRoom(roomCode, metadata = {}) {
|
|
255
|
+
return this.enterLobby("/api/v1/room/join", { room_code: roomCode }, metadata);
|
|
256
|
+
}
|
|
257
|
+
async getRoomStatus() {
|
|
258
|
+
return this.http.get("/api/v1/room/status");
|
|
259
|
+
}
|
|
260
|
+
async leaveRoom() {
|
|
261
|
+
return this.http.post("/api/v1/room/leave");
|
|
262
|
+
}
|
|
263
|
+
async startRoom() {
|
|
264
|
+
return this.http.post("/api/v1/room/start");
|
|
265
|
+
}
|
|
266
|
+
async setTrainingRoomMode(roomType) {
|
|
267
|
+
return this.http.request("PUT", "/api/v1/room/training/mode", { room_type: roomType });
|
|
268
|
+
}
|
|
269
|
+
async setTrainingRoleLock(characterId) {
|
|
270
|
+
return this.http.request("PUT", "/api/v1/room/training/role-lock", { character_id: characterId });
|
|
271
|
+
}
|
|
272
|
+
async clearTrainingRoleLock() {
|
|
273
|
+
return this.http.request("DELETE", "/api/v1/room/training/role-lock");
|
|
274
|
+
}
|
|
275
|
+
async chatRoom(content) {
|
|
276
|
+
return this.http.post("/api/v1/room/chat", { content });
|
|
277
|
+
}
|
|
278
|
+
async chatRoomConfirmed(content) {
|
|
279
|
+
return this.http.postRaw("/api/v1/room/chat", { content });
|
|
280
|
+
}
|
|
281
|
+
get lobbyAgentWsUrl() {
|
|
282
|
+
return this.registry.lobbyAgentWsUrl;
|
|
283
|
+
}
|
|
284
|
+
setRoomGameServer(gameServerName) {
|
|
285
|
+
this.registry.setGatewayGameServerName(gameServerName);
|
|
286
|
+
}
|
|
287
|
+
setGameServerUrl(url) {
|
|
288
|
+
this.registry.setGameServerUrl(url);
|
|
289
|
+
}
|
|
290
|
+
// ─── Economy / Leaderboard ───
|
|
291
|
+
async getLeaderboard(page, limit) {
|
|
292
|
+
const params = new URLSearchParams();
|
|
293
|
+
if (page != null) params.set("page", String(page));
|
|
294
|
+
if (limit != null) params.set("limit", String(limit));
|
|
295
|
+
const query = params.toString() ? `?${params.toString()}` : "";
|
|
296
|
+
return this.http.get(`/api/v1/leaderboard${query}`);
|
|
297
|
+
}
|
|
298
|
+
async getCompetitionStatus() {
|
|
299
|
+
return this.http.get("/api/v1/competition/status");
|
|
300
|
+
}
|
|
301
|
+
async getMyCompetitionRank() {
|
|
302
|
+
return this.http.get("/api/v1/leaderboard/competition/me");
|
|
303
|
+
}
|
|
304
|
+
async getSettlement() {
|
|
305
|
+
return this.http.get("/api/v1/game/settlement");
|
|
306
|
+
}
|
|
307
|
+
async getGameHistory(page, limit) {
|
|
308
|
+
const params = new URLSearchParams();
|
|
309
|
+
if (page != null) params.set("page", String(page));
|
|
310
|
+
if (limit != null) params.set("limit", String(limit));
|
|
311
|
+
const query = params.toString() ? `?${params.toString()}` : "";
|
|
312
|
+
return this.http.get(`/api/v1/game/history${query}`);
|
|
313
|
+
}
|
|
314
|
+
// ─── Connection Management ───
|
|
315
|
+
/** Bind resumable GameSync state to the game selected by Source lifecycle. */
|
|
316
|
+
setExpectedGameSyncGameId(gameId) {
|
|
317
|
+
const expected = gameId?.trim() || void 0;
|
|
318
|
+
if (this.expectedGameSyncGameId !== expected) {
|
|
319
|
+
this.expectedGameSyncGameId = expected;
|
|
320
|
+
if (!expected || this.gameSyncResumeState?.gameId !== expected) {
|
|
321
|
+
this.gameSyncResumeState = void 0;
|
|
322
|
+
}
|
|
323
|
+
return;
|
|
324
|
+
}
|
|
325
|
+
if (expected && this.gameSyncResumeState?.gameId !== expected) {
|
|
326
|
+
this.gameSyncResumeState = void 0;
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
/** Connect WebSocket to the current server (game server or lobby). */
|
|
330
|
+
async connectWs() {
|
|
331
|
+
if (!this.enableWs) return false;
|
|
332
|
+
if (this.wsConnected) return true;
|
|
333
|
+
const wsUrl = this.registry.wsUrl;
|
|
334
|
+
if (!wsUrl) {
|
|
335
|
+
this.log.warn("WS_CONNECT", "no game server URL for WebSocket");
|
|
336
|
+
return false;
|
|
337
|
+
}
|
|
338
|
+
const resumeState = this.resumeStateForExpectedGame(
|
|
339
|
+
this.ws?.resumeState ?? this.gameSyncResumeState
|
|
340
|
+
);
|
|
341
|
+
if (resumeState) this.gameSyncResumeState = resumeState;
|
|
342
|
+
if (this.ws) {
|
|
343
|
+
this.ws.clearHandlers();
|
|
344
|
+
await this.stopWs(this.ws);
|
|
345
|
+
this.markWsHandlersDetached();
|
|
346
|
+
}
|
|
347
|
+
const newWs = this.createWs({
|
|
348
|
+
url: wsUrl,
|
|
349
|
+
apiKey: this.apiKey,
|
|
350
|
+
rawMessageSink: this.rawWsMessageSink,
|
|
351
|
+
...resumeState ? { resumeState } : {}
|
|
352
|
+
});
|
|
353
|
+
this.ws = newWs;
|
|
354
|
+
this.attachWsHandlers();
|
|
355
|
+
try {
|
|
356
|
+
await newWs.connect();
|
|
357
|
+
return true;
|
|
358
|
+
} catch {
|
|
359
|
+
this.rememberGameSyncResumeState(newWs.resumeState);
|
|
360
|
+
this.log.warn("WS_CONNECT", "GameSync WebSocket connection failed; runtime will retry");
|
|
361
|
+
await this.stopWs(newWs);
|
|
362
|
+
this.ws = null;
|
|
363
|
+
this.markWsHandlersDetached();
|
|
364
|
+
return false;
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
/** Disconnect WebSocket. */
|
|
368
|
+
disconnectWs(options = {}) {
|
|
369
|
+
if (options.preserveGameSyncResumeState) {
|
|
370
|
+
this.rememberGameSyncResumeState(this.ws?.resumeState);
|
|
371
|
+
}
|
|
372
|
+
if (this.ws) {
|
|
373
|
+
this.stopWs(this.ws);
|
|
374
|
+
this.ws = null;
|
|
375
|
+
}
|
|
376
|
+
if (!options.preserveGameSyncResumeState) {
|
|
377
|
+
this.gameSyncResumeState = void 0;
|
|
378
|
+
this.expectedGameSyncGameId = void 0;
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
/** Commit one Source-accepted GameSync frame and advance its resumable ACK. */
|
|
382
|
+
acknowledgeGameSync(ackToken, immediate = false) {
|
|
383
|
+
this.ws?.acknowledge(ackToken, immediate);
|
|
384
|
+
this.rememberGameSyncResumeState(this.ws?.resumeState);
|
|
385
|
+
}
|
|
386
|
+
/** Send display-only perception output over the active GameSync connection. */
|
|
387
|
+
reportGameSyncPerceptions(perceptions) {
|
|
388
|
+
return this.ws?.reportPerceptions(perceptions) ?? false;
|
|
389
|
+
}
|
|
390
|
+
/** A report must still belong to the Source-accepted game/connection it describes. */
|
|
391
|
+
reportGameSyncRuntime(report, gameId, connectionId) {
|
|
392
|
+
if (this.ws?.connectionId !== connectionId || this.ws?.resumeState?.gameId !== gameId) return false;
|
|
393
|
+
return this.ws.reportRuntime(report);
|
|
394
|
+
}
|
|
395
|
+
get gameSyncLocale() {
|
|
396
|
+
return this.ws?.resumeState?.locale ?? this.gameSyncResumeState?.locale ?? "zh-CN";
|
|
397
|
+
}
|
|
398
|
+
/**
|
|
399
|
+
* Try to discover game server from /queue/status.
|
|
400
|
+
* If found and WS is enabled, reconnects WS to the game server.
|
|
401
|
+
* Returns both the usable-route decision and the authoritative queue probe.
|
|
402
|
+
*
|
|
403
|
+
* Note: uses http.get directly instead of getQueueStatus() to avoid
|
|
404
|
+
* double-calling registry.updateFromQueueResponse().
|
|
405
|
+
*/
|
|
406
|
+
async discoverGameServer() {
|
|
407
|
+
try {
|
|
408
|
+
const result = await this.http.get("/api/v1/queue/status");
|
|
409
|
+
const changed = this.registry.updateFromQueueResponse(result);
|
|
410
|
+
if (changed && this._gameServerUrl) {
|
|
411
|
+
this.log.info("GAME_SERVER_DISCOVERED", `url=${this._gameServerUrl}`);
|
|
412
|
+
if (this.enableWs) {
|
|
413
|
+
await this.reconnectWsToGameServer();
|
|
414
|
+
}
|
|
415
|
+
return { routeChanged: true, queue: structuredClone(result) };
|
|
416
|
+
}
|
|
417
|
+
return { routeChanged: false, queue: structuredClone(result) };
|
|
418
|
+
} catch {
|
|
419
|
+
}
|
|
420
|
+
return { routeChanged: false };
|
|
421
|
+
}
|
|
422
|
+
/** Reconnect WS to the current game server address. */
|
|
423
|
+
async reconnectWsToGameServer() {
|
|
424
|
+
const wsUrl = this.registry.wsUrl;
|
|
425
|
+
if (!wsUrl) return;
|
|
426
|
+
const resumeState = this.resumeStateForExpectedGame(
|
|
427
|
+
this.ws?.resumeState ?? this.gameSyncResumeState
|
|
428
|
+
);
|
|
429
|
+
if (resumeState) this.gameSyncResumeState = resumeState;
|
|
430
|
+
if (this.ws) {
|
|
431
|
+
this.ws.clearHandlers();
|
|
432
|
+
await this.stopWs(this.ws);
|
|
433
|
+
this.markWsHandlersDetached();
|
|
434
|
+
}
|
|
435
|
+
const newWs = this.createWs({
|
|
436
|
+
url: wsUrl,
|
|
437
|
+
apiKey: this.apiKey,
|
|
438
|
+
rawMessageSink: this.rawWsMessageSink,
|
|
439
|
+
...resumeState ? { resumeState } : {}
|
|
440
|
+
});
|
|
441
|
+
this.ws = newWs;
|
|
442
|
+
this.attachWsHandlers();
|
|
443
|
+
try {
|
|
444
|
+
await newWs.connect();
|
|
445
|
+
this.log.info("WS_RECONNECT", `connected to ${wsUrl}`);
|
|
446
|
+
} catch {
|
|
447
|
+
this.rememberGameSyncResumeState(newWs.resumeState);
|
|
448
|
+
this.log.warn("WS_RECONNECT", "GameSync WebSocket reconnect failed; runtime will retry");
|
|
449
|
+
await this.stopWs(newWs);
|
|
450
|
+
this.ws = null;
|
|
451
|
+
this.markWsHandlersDetached();
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
/** Get the current game server URL. */
|
|
455
|
+
get _gameServerUrl() {
|
|
456
|
+
return this.registry.gameServerUrl;
|
|
457
|
+
}
|
|
458
|
+
// ─── GameSync v2 proxy ───
|
|
459
|
+
onWsClose(handler) {
|
|
460
|
+
this.wsCloseHandlers.push(handler);
|
|
461
|
+
return () => {
|
|
462
|
+
const idx = this.wsCloseHandlers.indexOf(handler);
|
|
463
|
+
if (idx >= 0) this.wsCloseHandlers.splice(idx, 1);
|
|
464
|
+
};
|
|
465
|
+
}
|
|
466
|
+
onInputFrame(handler) {
|
|
467
|
+
const entry = { handler, unsubscribe: void 0 };
|
|
468
|
+
this.wsInputFrameHandlers.push(entry);
|
|
469
|
+
if (this.ws) entry.unsubscribe = this.ws.onInputFrame(handler);
|
|
470
|
+
return () => {
|
|
471
|
+
entry.unsubscribe?.();
|
|
472
|
+
const idx = this.wsInputFrameHandlers.indexOf(entry);
|
|
473
|
+
if (idx >= 0) this.wsInputFrameHandlers.splice(idx, 1);
|
|
474
|
+
};
|
|
475
|
+
}
|
|
476
|
+
onWsConnectionOpened(handler) {
|
|
477
|
+
const entry = { handler, unsubscribe: void 0 };
|
|
478
|
+
this.wsConnectionOpenedHandlers.push(entry);
|
|
479
|
+
if (this.ws) entry.unsubscribe = this.ws.onConnectionOpened(handler);
|
|
480
|
+
return () => {
|
|
481
|
+
entry.unsubscribe?.();
|
|
482
|
+
const idx = this.wsConnectionOpenedHandlers.indexOf(entry);
|
|
483
|
+
if (idx >= 0) this.wsConnectionOpenedHandlers.splice(idx, 1);
|
|
484
|
+
};
|
|
485
|
+
}
|
|
486
|
+
onWsLiveness(handler) {
|
|
487
|
+
const entry = { handler, unsubscribe: void 0 };
|
|
488
|
+
this.wsLivenessHandlers.push(entry);
|
|
489
|
+
if (this.ws) entry.unsubscribe = this.ws.onLiveness(handler);
|
|
490
|
+
return () => {
|
|
491
|
+
entry.unsubscribe?.();
|
|
492
|
+
const idx = this.wsLivenessHandlers.indexOf(entry);
|
|
493
|
+
if (idx >= 0) this.wsLivenessHandlers.splice(idx, 1);
|
|
494
|
+
};
|
|
495
|
+
}
|
|
496
|
+
onWsProtocolError(handler) {
|
|
497
|
+
const entry = { handler, unsubscribe: void 0 };
|
|
498
|
+
this.wsProtocolErrorHandlers.push(entry);
|
|
499
|
+
if (this.ws) entry.unsubscribe = this.ws.onProtocolError(handler);
|
|
500
|
+
return () => {
|
|
501
|
+
entry.unsubscribe?.();
|
|
502
|
+
const idx = this.wsProtocolErrorHandlers.indexOf(entry);
|
|
503
|
+
if (idx >= 0) this.wsProtocolErrorHandlers.splice(idx, 1);
|
|
504
|
+
};
|
|
505
|
+
}
|
|
506
|
+
onWsRecoveryStarted(handler) {
|
|
507
|
+
const entry = { handler, unsubscribe: void 0 };
|
|
508
|
+
this.wsRecoveryStartedHandlers.push(entry);
|
|
509
|
+
if (this.ws) entry.unsubscribe = this.ws.onRecoveryStarted(handler);
|
|
510
|
+
return () => {
|
|
511
|
+
entry.unsubscribe?.();
|
|
512
|
+
const idx = this.wsRecoveryStartedHandlers.indexOf(entry);
|
|
513
|
+
if (idx >= 0) this.wsRecoveryStartedHandlers.splice(idx, 1);
|
|
514
|
+
};
|
|
515
|
+
}
|
|
516
|
+
get wsConnected() {
|
|
517
|
+
return this.ws?.connected ?? false;
|
|
518
|
+
}
|
|
519
|
+
/** True while the owned WsClient is connecting, connected, or auto-reconnecting. */
|
|
520
|
+
get wsConnectionActive() {
|
|
521
|
+
return this.ws !== null && this.ws.state !== WsConnectionState.Disconnected;
|
|
522
|
+
}
|
|
523
|
+
get wsConnectionId() {
|
|
524
|
+
return this.ws?.connectionId || null;
|
|
525
|
+
}
|
|
526
|
+
attachWsHandlers() {
|
|
527
|
+
if (!this.ws) return;
|
|
528
|
+
const attachedWs = this.ws;
|
|
529
|
+
attachedWs.onInputFrame(() => {
|
|
530
|
+
this.rememberGameSyncResumeState(attachedWs.resumeState);
|
|
531
|
+
});
|
|
532
|
+
for (const entry of this.wsInputFrameHandlers) {
|
|
533
|
+
entry.unsubscribe = this.ws.onInputFrame(entry.handler);
|
|
534
|
+
}
|
|
535
|
+
for (const entry of this.wsConnectionOpenedHandlers) {
|
|
536
|
+
entry.unsubscribe = this.ws.onConnectionOpened(entry.handler);
|
|
537
|
+
}
|
|
538
|
+
for (const entry of this.wsLivenessHandlers) {
|
|
539
|
+
entry.unsubscribe = this.ws.onLiveness(entry.handler);
|
|
540
|
+
}
|
|
541
|
+
for (const entry of this.wsProtocolErrorHandlers) {
|
|
542
|
+
entry.unsubscribe = this.ws.onProtocolError(entry.handler);
|
|
543
|
+
}
|
|
544
|
+
for (const entry of this.wsRecoveryStartedHandlers) {
|
|
545
|
+
entry.unsubscribe = this.ws.onRecoveryStarted(entry.handler);
|
|
546
|
+
}
|
|
547
|
+
this.ws.onDisconnect((info) => {
|
|
548
|
+
for (const handler of this.wsCloseHandlers) handler(info);
|
|
549
|
+
});
|
|
550
|
+
}
|
|
551
|
+
markWsHandlersDetached() {
|
|
552
|
+
for (const entry of this.wsInputFrameHandlers) entry.unsubscribe = void 0;
|
|
553
|
+
for (const entry of this.wsConnectionOpenedHandlers) entry.unsubscribe = void 0;
|
|
554
|
+
for (const entry of this.wsLivenessHandlers) entry.unsubscribe = void 0;
|
|
555
|
+
for (const entry of this.wsProtocolErrorHandlers) entry.unsubscribe = void 0;
|
|
556
|
+
for (const entry of this.wsRecoveryStartedHandlers) entry.unsubscribe = void 0;
|
|
557
|
+
}
|
|
558
|
+
createWs(config) {
|
|
559
|
+
if (!this.gameSyncIngress) return new WsClient(config);
|
|
560
|
+
const { rawMessageSink: _sink, ...options } = config;
|
|
561
|
+
return new ThreadedWsClient({ ...options, ...this.gameSyncIngress, transportGeneration: ++this.transportGeneration });
|
|
562
|
+
}
|
|
563
|
+
stopWs(ws) {
|
|
564
|
+
ws.disconnect();
|
|
565
|
+
if (ws instanceof ThreadedWsClient) {
|
|
566
|
+
const closing = ws.close();
|
|
567
|
+
this.closingIngress.add(closing);
|
|
568
|
+
void closing.finally(() => this.closingIngress.delete(closing));
|
|
569
|
+
return closing;
|
|
570
|
+
}
|
|
571
|
+
return Promise.resolve();
|
|
572
|
+
}
|
|
573
|
+
/** Drain Source-owned ingress and raw journals before Owner telemetry closes. */
|
|
574
|
+
async closeGameSyncTransports() {
|
|
575
|
+
this.disconnectWs();
|
|
576
|
+
await Promise.allSettled([...this.closingIngress]);
|
|
577
|
+
}
|
|
578
|
+
rememberGameSyncResumeState(candidate) {
|
|
579
|
+
if (!candidate) return;
|
|
580
|
+
const expected = this.expectedGameSyncGameId;
|
|
581
|
+
if (expected && candidate.gameId !== expected) {
|
|
582
|
+
this.gameSyncResumeState = void 0;
|
|
583
|
+
return;
|
|
584
|
+
}
|
|
585
|
+
if (!expected) this.expectedGameSyncGameId = candidate.gameId;
|
|
586
|
+
this.gameSyncResumeState = structuredClone(candidate);
|
|
587
|
+
}
|
|
588
|
+
resumeStateForExpectedGame(candidate) {
|
|
589
|
+
if (!candidate) return void 0;
|
|
590
|
+
const expected = this.expectedGameSyncGameId;
|
|
591
|
+
if (expected && candidate.gameId !== expected) {
|
|
592
|
+
this.gameSyncResumeState = void 0;
|
|
593
|
+
return void 0;
|
|
594
|
+
}
|
|
595
|
+
if (!expected) this.expectedGameSyncGameId = candidate.gameId;
|
|
596
|
+
return structuredClone(candidate);
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
export {
|
|
600
|
+
ApiError2 as ApiError,
|
|
601
|
+
GameClient
|
|
602
|
+
};
|