@playcraft/cli 0.1.53-beta → 0.1.54
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/README.md +3 -62
- package/dist/agent/local-backend.js +1 -1
- package/dist/cli-root-help.js +0 -2
- package/dist/commands/build-all.js +19 -5
- package/dist/commands/build.js +28 -15
- package/dist/commands/create.js +33 -26
- package/dist/commands/login.js +42 -84
- package/dist/commands/skills.js +0 -4
- package/dist/commands/tools-3d.js +0 -11
- package/dist/commands/tools-generation.js +0 -6
- package/dist/commands/tools.js +0 -2
- package/dist/config.js +4 -59
- package/dist/index.js +3 -42
- package/dist/remix/clone.js +0 -2
- package/dist/remix/init-template.js +0 -2
- package/dist/remix/pull.js +0 -2
- package/dist/remix/push.js +1 -21
- package/dist/utils/agent-api-client.js +30 -210
- package/dist/utils/playcraft-http-client.js +4 -6
- package/package.json +5 -15
- package/SKILLS_REGISTRY.md +0 -149
- package/dist/auth/account-activation.js +0 -157
- package/dist/auth/messages.js +0 -30
- package/dist/commands/build-temp.js +0 -26
- package/dist/commands/platform-skills.generated.js +0 -19
- package/dist/commands/playable.js +0 -53
- package/dist/commands/preview-runtime.js +0 -21
- package/dist/commands/tools-batch.js +0 -113
- package/dist/commands/video.js +0 -122
- package/dist/commands/workspace-runtime.js +0 -54
- package/dist/commands/workspace.js +0 -40
- package/dist/preview-runtime/distribution.js +0 -77
- package/dist/project-skills/builtin-import.js +0 -225
- package/dist/project-skills/commands.js +0 -77
- package/dist/project-skills/lifecycle.js +0 -28
- package/dist/project-skills/local-run.js +0 -112
- package/dist/project-skills/local-store.js +0 -221
- package/dist/project-skills/messages.js +0 -80
- package/dist/project-skills/reconcile.js +0 -62
- package/dist/project-skills/remote-cache.js +0 -51
- package/dist/project-skills/validation.js +0 -19
- package/dist/recording/messages.js +0 -40
- package/dist/recording/project-digest.js +0 -85
- package/dist/recording/recorder.js +0 -293
- package/dist/recording/scenario.js +0 -50
- package/dist/skill-registry/client.js +0 -345
- package/dist/skill-registry/commands.js +0 -180
- package/dist/skill-registry/evaluation-client.js +0 -156
- package/dist/skill-registry/evaluation-commands.js +0 -174
- package/dist/skill-registry/messages.js +0 -177
- package/dist/skill-registry/package.js +0 -275
- package/dist/skill-registry/platform-package.js +0 -100
- package/dist/utils/environment-endpoints.js +0 -17
- package/dist/utils/error-diagnostics.js +0 -20
- package/dist/utils/tool-operation-journal.js +0 -124
- package/dist/utils/video-evidence-git.js +0 -81
- package/dist/video-replication/client.js +0 -234
- package/dist/video-replication/comparison-evidence.js +0 -149
- package/dist/video-replication/comparison-files.js +0 -57
- package/dist/video-replication/comparison-log.js +0 -72
- package/dist/video-replication/comparison-messages.js +0 -104
- package/dist/video-replication/comparison-output.js +0 -63
- package/dist/video-replication/comparison-preflight.js +0 -66
- package/dist/video-replication/comparison.js +0 -230
- package/dist/video-replication/diagnostics.js +0 -41
- package/dist/video-replication/evidence.js +0 -165
- package/dist/video-replication/media.js +0 -112
- package/dist/video-replication/messages.js +0 -97
- package/dist/workspace/messages.js +0 -67
- package/dist/workspace/transfer-client.js +0 -237
- package/dist/workspace/transfer-errors.js +0 -48
- package/dist/workspace-runtime/batch/content-changes.js +0 -30
- package/dist/workspace-runtime/batch/control.js +0 -86
- package/dist/workspace-runtime/batch/deliver.js +0 -173
- package/dist/workspace-runtime/batch/freeze.js +0 -101
- package/dist/workspace-runtime/batch/generate.js +0 -249
- package/dist/workspace-runtime/batch/git.js +0 -40
- package/dist/workspace-runtime/batch/occupancy.js +0 -8
- package/dist/workspace-runtime/batch/policy.js +0 -70
- package/dist/workspace-runtime/batch/prepare.js +0 -317
- package/dist/workspace-runtime/batch/processes.js +0 -72
- package/dist/workspace-runtime/batch/records.js +0 -113
- package/dist/workspace-runtime/batch/routes.js +0 -61
- package/dist/workspace-runtime/batch/source-candidate.js +0 -86
- package/dist/workspace-runtime/batch/source-capture.js +0 -146
- package/dist/workspace-runtime/batch/source-failure.js +0 -43
- package/dist/workspace-runtime/batch/source-publish.js +0 -130
- package/dist/workspace-runtime/codex/app-server.js +0 -1065
- package/dist/workspace-runtime/codex/compact.js +0 -46
- package/dist/workspace-runtime/codex/config-toml.js +0 -107
- package/dist/workspace-runtime/codex/delivery-tools.js +0 -144
- package/dist/workspace-runtime/codex/jsonrpc-stdio.js +0 -145
- package/dist/workspace-runtime/codex/launcher-client.js +0 -177
- package/dist/workspace-runtime/codex/loopback.js +0 -146
- package/dist/workspace-runtime/codex/mcp-config.js +0 -39
- package/dist/workspace-runtime/codex/model-broker.js +0 -263
- package/dist/workspace-runtime/codex/native-adapter.js +0 -9
- package/dist/workspace-runtime/codex/permissions.js +0 -79
- package/dist/workspace-runtime/codex/thread-image.js +0 -38
- package/dist/workspace-runtime/codex/tool-response.js +0 -10
- package/dist/workspace-runtime/codex/ui-instructions.js +0 -4
- package/dist/workspace-runtime/codex/ui-tools.js +0 -203
- package/dist/workspace-runtime/codex/work-mode.js +0 -15
- package/dist/workspace-runtime/main.js +0 -10
- package/dist/workspace-runtime/persistence/journal.js +0 -365
- package/dist/workspace-runtime/persistence/native-subagents.js +0 -162
- package/dist/workspace-runtime/persistence/sqlite-client.js +0 -77
- package/dist/workspace-runtime/persistence/sqlite-worker.js +0 -1161
- package/dist/workspace-runtime/persistence/stopped-execution.js +0 -77
- package/dist/workspace-runtime/previews/diagnostics.js +0 -44
- package/dist/workspace-runtime/previews/output.js +0 -36
- package/dist/workspace-runtime/previews/publish.js +0 -283
- package/dist/workspace-runtime/previews/runtime-preview.js +0 -251
- package/dist/workspace-runtime/previews/single-file.js +0 -43
- package/dist/workspace-runtime/processes/managed-writes.js +0 -69
- package/dist/workspace-runtime/serve.js +0 -441
- package/dist/workspace-runtime/server/accept-operation.js +0 -61
- package/dist/workspace-runtime/server/asset-transfers.js +0 -63
- package/dist/workspace-runtime/server/auth.js +0 -21
- package/dist/workspace-runtime/server/connectivity.js +0 -211
- package/dist/workspace-runtime/server/desktop-host.js +0 -429
- package/dist/workspace-runtime/server/desktop-preview-config.js +0 -81
- package/dist/workspace-runtime/server/desktop-preview-service.js +0 -157
- package/dist/workspace-runtime/server/desktop-preview-static.js +0 -53
- package/dist/workspace-runtime/server/desktop-preview.js +0 -189
- package/dist/workspace-runtime/server/dispatch.js +0 -1655
- package/dist/workspace-runtime/server/endpoints.js +0 -21
- package/dist/workspace-runtime/server/execution-group.js +0 -90
- package/dist/workspace-runtime/server/http.js +0 -1339
- package/dist/workspace-runtime/server/lock.js +0 -53
- package/dist/workspace-runtime/server/operation-record.js +0 -33
- package/dist/workspace-runtime/server/rfb-watch-gate.js +0 -168
- package/dist/workspace-runtime/server/session-restore.js +0 -84
- package/dist/workspace-runtime/server/source-uploader.js +0 -138
- package/dist/workspace-runtime/server/submit-operation.js +0 -41
- package/dist/workspace-runtime/server/terminal-host.js +0 -366
- package/dist/workspace-runtime/server/types.js +0 -1
- package/dist/workspace-runtime/server/workspace-transfer.js +0 -168
- package/dist/workspace-runtime/verify-artifact.js +0 -59
- package/dist/workspace-runtime/workspaces/append-only-log.js +0 -62
- package/dist/workspace-runtime/workspaces/archive.js +0 -207
- package/dist/workspace-runtime/workspaces/artifact-events.js +0 -55
- package/dist/workspace-runtime/workspaces/artifact-files.js +0 -199
- package/dist/workspace-runtime/workspaces/artifact-receipts.js +0 -89
- package/dist/workspace-runtime/workspaces/artifacts.js +0 -282
- package/dist/workspace-runtime/workspaces/asset-library-import.js +0 -387
- package/dist/workspace-runtime/workspaces/asset-publication-access.js +0 -25
- package/dist/workspace-runtime/workspaces/asset-transfer-dependencies.js +0 -81
- package/dist/workspace-runtime/workspaces/asset-transfer-publish.js +0 -438
- package/dist/workspace-runtime/workspaces/asset-transfer-storage.js +0 -389
- package/dist/workspace-runtime/workspaces/attachment-content.js +0 -73
- package/dist/workspace-runtime/workspaces/attachments.js +0 -185
- package/dist/workspace-runtime/workspaces/batch-commit.js +0 -142
- package/dist/workspace-runtime/workspaces/binary-content.js +0 -65
- package/dist/workspace-runtime/workspaces/binary-write.js +0 -117
- package/dist/workspace-runtime/workspaces/cli-context.js +0 -23
- package/dist/workspace-runtime/workspaces/cli-credentials.js +0 -115
- package/dist/workspace-runtime/workspaces/composer-context.js +0 -147
- package/dist/workspace-runtime/workspaces/context-error.js +0 -2
- package/dist/workspace-runtime/workspaces/delivery-build.js +0 -331
- package/dist/workspace-runtime/workspaces/delivery-store.js +0 -168
- package/dist/workspace-runtime/workspaces/delivery.js +0 -64
- package/dist/workspace-runtime/workspaces/dependencies.js +0 -279
- package/dist/workspace-runtime/workspaces/developer-command.js +0 -98
- package/dist/workspace-runtime/workspaces/directories.js +0 -132
- package/dist/workspace-runtime/workspaces/directory-access.js +0 -37
- package/dist/workspace-runtime/workspaces/directory-attachments.js +0 -245
- package/dist/workspace-runtime/workspaces/directory-create.js +0 -57
- package/dist/workspace-runtime/workspaces/directory-maintenance.js +0 -111
- package/dist/workspace-runtime/workspaces/directory-mutations.js +0 -238
- package/dist/workspace-runtime/workspaces/directory-revisions.js +0 -56
- package/dist/workspace-runtime/workspaces/directory-stats.js +0 -49
- package/dist/workspace-runtime/workspaces/disk-snapshot.js +0 -31
- package/dist/workspace-runtime/workspaces/empty-template.js +0 -42
- package/dist/workspace-runtime/workspaces/file-content.js +0 -48
- package/dist/workspace-runtime/workspaces/files-search.js +0 -116
- package/dist/workspace-runtime/workspaces/files.js +0 -150
- package/dist/workspace-runtime/workspaces/git-credential-broker.js +0 -312
- package/dist/workspace-runtime/workspaces/git-credential-helper.js +0 -68
- package/dist/workspace-runtime/workspaces/git-direct-store.js +0 -155
- package/dist/workspace-runtime/workspaces/git.js +0 -670
- package/dist/workspace-runtime/workspaces/instructions.js +0 -56
- package/dist/workspace-runtime/workspaces/json5-edit.js +0 -313
- package/dist/workspace-runtime/workspaces/library-attachments.js +0 -268
- package/dist/workspace-runtime/workspaces/operation-log.js +0 -23
- package/dist/workspace-runtime/workspaces/optional-platform-skills.js +0 -14
- package/dist/workspace-runtime/workspaces/parameter-agent-inputs.js +0 -97
- package/dist/workspace-runtime/workspaces/parameter-agent-protocol.js +0 -40
- package/dist/workspace-runtime/workspaces/parameter-agent-store.js +0 -58
- package/dist/workspace-runtime/workspaces/parameter-agent.js +0 -284
- package/dist/workspace-runtime/workspaces/parameter-assets.js +0 -189
- package/dist/workspace-runtime/workspaces/parameters.js +0 -329
- package/dist/workspace-runtime/workspaces/prepare.js +0 -278
- package/dist/workspace-runtime/workspaces/registry.js +0 -251
- package/dist/workspace-runtime/workspaces/remix-references.js +0 -301
- package/dist/workspace-runtime/workspaces/revisions.js +0 -31
- package/dist/workspace-runtime/workspaces/session-image.js +0 -104
- package/dist/workspace-runtime/workspaces/shared-git.js +0 -40
- package/dist/workspace-runtime/workspaces/skill-artifact-loader.js +0 -95
- package/dist/workspace-runtime/workspaces/skills.js +0 -191
- package/dist/workspace-runtime/workspaces/theme-asset-index.js +0 -157
- package/dist/workspace-runtime/workspaces/transfer-quota.js +0 -69
- package/dist/workspace-runtime/workspaces/transfer.js +0 -471
- package/dist/workspace-runtime/workspaces/turn-changes.js +0 -75
- package/dist/workspace-runtime/workspaces/video-attachments.js +0 -49
- package/project-template/.claude/skills/playcraft-replica-validation/SKILL.md +0 -25
- package/project-template/.claude/skills/playcraft-replica-validation/references/contracts.md +0 -79
- package/project-template/.claude/skills/playcraft-video-understanding/SKILL.md +0 -29
- package/project-template/.claude/skills/playcraft-video-understanding/references/contracts.md +0 -37
- package/project-template-v2/.claude/agents/artist.md +0 -82
- package/project-template-v2/.claude/agents/developer.md +0 -153
- package/project-template-v2/.claude/agents/game-designer.md +0 -264
- package/project-template-v2/.claude/agents/refs/artist-art-style-catalog.md +0 -533
- package/project-template-v2/.claude/agents/refs/artist-color-audio-recipes.md +0 -153
- package/project-template-v2/.claude/agents/refs/artist-dimension-axis.md +0 -27
- package/project-template-v2/.claude/agents/refs/artist-master-composite-recipes.md +0 -208
- package/project-template-v2/.claude/agents/refs/atom-skill-library.md +0 -81
- package/project-template-v2/.claude/agents/refs/developer-impl-cookbook.md +0 -432
- package/project-template-v2/.claude/agents/refs/framework-5-component-filter.md +0 -252
- package/project-template-v2/.claude/agents/refs/framework-game-feel-juice.md +0 -266
- package/project-template-v2/.claude/agents/refs/framework-mda.md +0 -147
- package/project-template-v2/.claude/agents/refs/game-designer-gameplay-sufficiency.md +0 -123
- package/project-template-v2/.claude/agents/refs/ta-3d-flip-recipe.md +0 -88
- package/project-template-v2/.claude/agents/refs/ta-atlas-deliverable-standard.md +0 -67
- package/project-template-v2/.claude/agents/refs/ta-batch-pipeline-recipes.md +0 -120
- package/project-template-v2/.claude/agents/refs/ta-image-generation-detail.md +0 -300
- package/project-template-v2/.claude/agents/refs/ta-image-ops-reference.md +0 -495
- package/project-template-v2/.claude/agents/refs/ta-pipeline-cookbook.md +0 -1141
- package/project-template-v2/.claude/agents/refs/ta-tools-reference.md +0 -111
- package/project-template-v2/.claude/agents/refs/ta-vfx-preset-catalog.md +0 -365
- package/project-template-v2/.claude/agents/refs/threejs-cannon-pitfalls.md +0 -412
- package/project-template-v2/.claude/agents/reviewer.md +0 -75
- package/project-template-v2/.claude/agents/technical-artist.md +0 -86
- package/project-template-v2/.claude/hooks/snapshot-milestone.mjs +0 -243
- package/project-template-v2/.claude/hooks/user-prompt.mjs +0 -133
- package/project-template-v2/.claude/settings.json +0 -33
- package/project-template-v2/.claude/skills/brainstorming/SKILL.md +0 -161
- package/project-template-v2/.claude/skills/brainstorming/scripts/frame-template.html +0 -270
- package/project-template-v2/.claude/skills/brainstorming/scripts/helper.js +0 -177
- package/project-template-v2/.claude/skills/brainstorming/scripts/server.cjs +0 -354
- package/project-template-v2/.claude/skills/brainstorming/scripts/start-server.sh +0 -148
- package/project-template-v2/.claude/skills/brainstorming/scripts/stop-server.sh +0 -56
- package/project-template-v2/.claude/skills/brainstorming/scripts/wait-for-selection.sh +0 -62
- package/project-template-v2/.claude/skills/brainstorming/spec-document-reviewer-prompt.md +0 -49
- package/project-template-v2/.claude/skills/brainstorming/visual-companion.md +0 -309
- package/project-template-v2/.claude/skills/playcraft-ad-psychology/SKILL.md +0 -182
- package/project-template-v2/.claude/skills/playcraft-art-style-guide/SKILL.md +0 -123
- package/project-template-v2/.claude/skills/playcraft-asset-state-sheet/SKILL.md +0 -205
- package/project-template-v2/.claude/skills/playcraft-audio-generation/SKILL.md +0 -280
- package/project-template-v2/.claude/skills/playcraft-batch-pipeline/SKILL.md +0 -184
- package/project-template-v2/.claude/skills/playcraft-build-optimizer/SKILL.md +0 -306
- package/project-template-v2/.claude/skills/playcraft-image-generation/SKILL.md +0 -370
- package/project-template-v2/.claude/skills/playcraft-image-generation/reference/build-sprite-sheet.template.mjs +0 -123
- package/project-template-v2/.claude/skills/playcraft-image-generation/reference/compare-style.template.mjs +0 -254
- package/project-template-v2/.claude/skills/playcraft-image-generation/reference/gen-batch-sprite.template.mjs +0 -333
- package/project-template-v2/.claude/skills/playcraft-image-generation/reference/gen-batch.template.mjs +0 -95
- package/project-template-v2/.claude/skills/playcraft-image-generation/reference/gen-edit-variants.template.mjs +0 -118
- package/project-template-v2/.claude/skills/playcraft-image-generation/reference/process-batch.template.mjs +0 -136
- package/project-template-v2/.claude/skills/playcraft-image-generation/reference/prompt-cookbook.md +0 -397
- package/project-template-v2/.claude/skills/playcraft-image-generation/reference/validate-sprite-sheet.template.mjs +0 -296
- package/project-template-v2/.claude/skills/playcraft-image-ops/SKILL.md +0 -122
- package/project-template-v2/.claude/skills/playcraft-image-processing/SKILL.md +0 -219
- package/project-template-v2/.claude/skills/playcraft-masking/SKILL.md +0 -373
- package/project-template-v2/.claude/skills/playcraft-playable-optimization/SKILL.md +0 -161
- package/project-template-v2/.claude/skills/playcraft-research/SKILL.md +0 -215
- package/project-template-v2/.claude/skills/playcraft-skill-recommender/SKILL.md +0 -382
- package/project-template-v2/.claude/skills/playcraft-sprite-generation/SKILL.md +0 -423
- package/project-template-v2/.claude/skills/playcraft-sprite-remix/SKILL.md +0 -158
- package/project-template-v2/.claude/skills/playcraft-sprite-sheet/SKILL.md +0 -100
- package/project-template-v2/.claude/skills/playcraft-storyboard/SKILL.md +0 -167
- package/project-template-v2/.claude/skills/playcraft-style-qa/SKILL.md +0 -270
- package/project-template-v2/.claude/skills/playcraft-text-rendering/SKILL.md +0 -236
- package/project-template-v2/.claude/skills/playcraft-vfx-animation/SKILL.md +0 -130
- package/project-template-v2/.claude/skills/playwright-cli/SKILL.md +0 -390
- package/project-template-v2/.claude/skills/playwright-cli/references/element-attributes.md +0 -23
- package/project-template-v2/.claude/skills/playwright-cli/references/playwright-tests.md +0 -39
- package/project-template-v2/.claude/skills/playwright-cli/references/request-mocking.md +0 -87
- package/project-template-v2/.claude/skills/playwright-cli/references/running-code.md +0 -240
- package/project-template-v2/.claude/skills/playwright-cli/references/session-management.md +0 -226
- package/project-template-v2/.claude/skills/playwright-cli/references/spec-driven-testing.md +0 -308
- package/project-template-v2/.claude/skills/playwright-cli/references/storage-state.md +0 -275
- package/project-template-v2/.claude/skills/playwright-cli/references/test-generation.md +0 -134
- package/project-template-v2/.claude/skills/playwright-cli/references/tracing.md +0 -142
- package/project-template-v2/.claude/skills/playwright-cli/references/video-recording.md +0 -153
- package/project-template-v2/.claude/skills/session-analyzer/SKILL.md +0 -386
- package/project-template-v2/.claude/skills/session-analyzer/scripts/execution-breakdown.mjs +0 -182
- package/project-template-v2/.claude/skills/session-analyzer/scripts/find-turns.mjs +0 -72
- package/project-template-v2/.claude/skills/session-analyzer/scripts/heavy-output.mjs +0 -121
- package/project-template-v2/.claude/skills/session-analyzer/scripts/resolve-session.mjs +0 -102
- package/project-template-v2/.claude/skills/session-analyzer/scripts/subagent-stats.mjs +0 -127
- package/project-template-v2/.claude/skills/session-analyzer/scripts/subagent-tool-timeline.mjs +0 -106
- package/project-template-v2/.claude/skills/session-analyzer/scripts/time-gaps.mjs +0 -128
- package/project-template-v2/.claude/skills/session-analyzer/scripts/turn-timeline.mjs +0 -67
- package/project-template-v2/.claude/snapshot.mjs +0 -263
- package/project-template-v2/.playcraft/skills.lock.json +0 -152
- package/project-template-v2/CLAUDE.md +0 -146
- package/project-template-v2/assets/audio/bgm/.gitkeep +0 -0
- package/project-template-v2/assets/audio/sfx/.gitkeep +0 -0
- package/project-template-v2/assets/bundles/.gitkeep +0 -0
- package/project-template-v2/assets/images/bg/.gitkeep +0 -0
- package/project-template-v2/assets/images/reference/.gitkeep +0 -0
- package/project-template-v2/assets/images/storyboard/.gitkeep +0 -0
- package/project-template-v2/assets/images/tiles/.gitkeep +0 -0
- package/project-template-v2/assets/images/ui/.gitkeep +0 -0
- package/project-template-v2/assets/images/vfx/.gitkeep +0 -0
- package/project-template-v2/assets/models/.gitkeep +0 -0
- package/project-template-v2/docs/harness/iteration-1/context-flow.md +0 -254
- package/project-template-v2/docs/harness/iteration-1/generate-flow.md +0 -91
- package/project-template-v2/docs/harness/iteration-1/ideate-flow.md +0 -214
- package/project-template-v2/docs/harness/iteration-1/optimize-flow.md +0 -75
- package/project-template-v2/docs/harness/iteration-1/wrapup-flow.md +0 -63
- package/project-template-v2/docs/harness/iteration-2/context-flow.md +0 -223
- package/project-template-v2/docs/harness/iteration-2/generate-flow.md +0 -129
- package/project-template-v2/docs/harness/iteration-2/ideate-flow.md +0 -267
- package/project-template-v2/docs/harness/iteration-2/optimize-flow.md +0 -164
- package/project-template-v2/docs/harness/iteration-2/wrapup-flow.md +0 -115
- package/project-template-v2/docs/harness/orchestrator-flow.md +0 -364
- package/project-template-v2/docs/project-state.json +0 -60
- package/project-template-v2/docs/project-state.md +0 -72
- package/project-template-v2/docs/standards/README.md +0 -225
- package/project-template-v2/docs/standards/agent-behavior-standards.md +0 -174
- package/project-template-v2/docs/standards/artifacts/design-brief.md +0 -19
- package/project-template-v2/docs/standards/artifacts/design.md +0 -22
- package/project-template-v2/docs/standards/artifacts/game-code.md +0 -41
- package/project-template-v2/docs/standards/artifacts/todo-list.md +0 -41
- package/project-template-v2/docs/standards/iter1-agent-behavior-standards.md +0 -343
- package/project-template-v2/game/index.ts +0 -18
- package/project-template-v2/globals.d.ts +0 -51
- package/project-template-v2/index.css +0 -34
- package/project-template-v2/index.html +0 -18
- package/project-template-v2/main.ts +0 -9
- package/project-template-v2/package.json +0 -46
- package/project-template-v2/skills/_shared/scripts/dispatch-clear.mjs +0 -31
- package/project-template-v2/skills/_shared/scripts/dispatch-set.mjs +0 -86
- package/project-template-v2/skills/_shared/scripts/dod-check.mjs +0 -153
- package/project-template-v2/skills/_shared/scripts/handoff-append.mjs +0 -70
- package/project-template-v2/skills/_shared/scripts/lib/validator-artifacts.mjs +0 -91
- package/project-template-v2/skills/_shared/scripts/pipeline/dod-config.mjs +0 -131
- package/project-template-v2/skills/_shared/scripts/pipeline/index.mjs +0 -80
- package/project-template-v2/skills/_shared/scripts/pipeline/iteration-1-core.mjs +0 -90
- package/project-template-v2/skills/_shared/scripts/pipeline/iteration-2-wrap.mjs +0 -93
- package/project-template-v2/skills/_shared/scripts/pipeline/iteration-3-visual.mjs +0 -23
- package/project-template-v2/skills/_shared/scripts/render-project-state.mjs +0 -230
- package/project-template-v2/skills/_shared/scripts/state-advance-stage.mjs +0 -58
- package/project-template-v2/skills/_shared/scripts/state-get.mjs +0 -339
- package/project-template-v2/skills/_shared/scripts/state-handoff.mjs +0 -39
- package/project-template-v2/skills/_shared/scripts/state-set.mjs +0 -94
- package/project-template-v2/skills/_shared/scripts/state-store.mjs +0 -783
- package/project-template-v2/skills/_shared/scripts/todo-add.mjs +0 -88
- package/project-template-v2/skills/_shared/scripts/todo-get.mjs +0 -130
- package/project-template-v2/skills/_shared/scripts/todo-remove.mjs +0 -33
- package/project-template-v2/skills/_shared/scripts/todo-set.mjs +0 -47
- package/project-template-v2/skills/_shared/scripts/verify-asset-code-sync.mjs +0 -268
- package/project-template-v2/skills/_shared/scripts/verify-env.mjs +0 -285
- package/project-template-v2/skills/_shared/scripts/verify-placeholders.mjs +0 -161
- package/project-template-v2/skills/playable-autoplay/SKILL.md +0 -176
- package/project-template-v2/skills/playable-autoplay/agents/openai.yaml +0 -4
- package/project-template-v2/skills/playable-debug/SKILL.md +0 -116
- package/project-template-v2/skills/playable-debug/agents/openai.yaml +0 -4
- package/project-template-v2/skills/playable-debug/references/debug-config.md +0 -40
- package/project-template-v2/skills/playable-record/SKILL.md +0 -140
- package/project-template-v2/skills/playable-record/scripts/lib/dev-server.mjs +0 -104
- package/project-template-v2/skills/playable-record/scripts/lib/record-audio-bridge.js +0 -141
- package/project-template-v2/skills/playable-record/scripts/record-playable.mjs +0 -425
- package/project-template-v2/skills/playable-record/scripts/verify-contract.mjs +0 -261
- package/project-template-v2/skills/playable-record/scripts/verify-firstwin.mjs +0 -398
- package/project-template-v2/skills/playable-record/scripts/verify-fusion.mjs +0 -322
- package/project-template-v2/skills/playable-record/scripts/verify-lifecycle.mjs +0 -105
- package/project-template-v2/skills/playable-record/scripts/verify-vlm-video.mjs +0 -230
- package/project-template-v2/skills/playable-validate/SKILL.md +0 -61
- package/project-template-v2/skills/playable-validate/validation-rules.md +0 -14
- package/project-template-v2/skills/playable-verify-ui/SKILL.md +0 -63
- package/project-template-v2/skills/playable-verify-ui/scripts/lib/__init__.py +0 -1
- package/project-template-v2/skills/playable-verify-ui/scripts/lib/config_expr.js +0 -218
- package/project-template-v2/skills/playable-verify-ui/scripts/lib/node_utils.js +0 -51
- package/project-template-v2/skills/playable-verify-ui/scripts/lib/profile_loader.py +0 -59
- package/project-template-v2/skills/playable-verify-ui/scripts/lib/report.py +0 -106
- package/project-template-v2/skills/playable-verify-ui/scripts/lib/runtime_contract.js +0 -116
- package/project-template-v2/skills/playable-verify-ui/scripts/verify_fetch_antipatterns.py +0 -59
- package/project-template-v2/skills/playable-verify-ui/scripts/verify_hardcoded_layout.js +0 -64
- package/project-template-v2/skills/playable-verify-ui/scripts/verify_runtime_contract.js +0 -58
- package/project-template-v2/skills/playable-verify-ui/scripts/verify_text_overlap.py +0 -333
- package/project-template-v2/ta-workspace/scripts/.gitkeep +0 -0
- package/project-template-v2/tsconfig.json +0 -20
- package/project-template-v2/vite.config.ts +0 -27
- package/project-templates/batch-locks/phaser.yaml +0 -922
- package/project-templates/batch-locks/threejs.yaml +0 -978
- package/project-templates/empty/AGENTS.md +0 -41
- package/project-templates/empty/gitignore +0 -33
- package/templates/preview-runtime/v1/README.md +0 -71
- package/templates/preview-runtime/v1/build-preview.mjs +0 -1324
- package/templates/preview-runtime/v1/manifest.json +0 -17
- package/templates/preview-runtime/v1/release-guard.mjs +0 -87
- package/templates/preview-runtime/v1/runtime.d.mts +0 -3
- package/templates/preview-runtime/v1/runtime.d.ts +0 -3
- package/templates/preview-runtime/v1/runtime.mjs +0 -1121
- package/templates/preview-runtime/v1/types/adapters.d.ts +0 -26
- package/templates/preview-runtime/v1/types/preview.d.ts +0 -23
- package/templates/preview-runtime/v1/types/protocol.d.ts +0 -94
- package/templates/preview-runtime/v1/types/runtime.d.ts +0 -14
|
@@ -1,1121 +0,0 @@
|
|
|
1
|
-
// ../iframe-bridge/package.json
|
|
2
|
-
var package_default = {
|
|
3
|
-
name: "@playcraft/iframe-bridge",
|
|
4
|
-
version: "0.0.55",
|
|
5
|
-
private: false,
|
|
6
|
-
type: "module",
|
|
7
|
-
description: "PlayCraft iframe postMessage bridge SDK for parent \u2194 child communication",
|
|
8
|
-
sideEffects: false,
|
|
9
|
-
publishConfig: {
|
|
10
|
-
access: "public"
|
|
11
|
-
},
|
|
12
|
-
main: "./dist/index.js",
|
|
13
|
-
types: "./dist/index.d.ts",
|
|
14
|
-
exports: {
|
|
15
|
-
".": {
|
|
16
|
-
types: "./dist/index.d.ts",
|
|
17
|
-
default: "./dist/index.js"
|
|
18
|
-
}
|
|
19
|
-
},
|
|
20
|
-
files: [
|
|
21
|
-
"dist",
|
|
22
|
-
"README.md"
|
|
23
|
-
],
|
|
24
|
-
scripts: {
|
|
25
|
-
build: `node -e "require('fs').rmSync('dist',{recursive:true,force:true})" && rollup -c`,
|
|
26
|
-
dev: "rollup -c -w",
|
|
27
|
-
typecheck: "tsc -p tsconfig.json --noEmit",
|
|
28
|
-
prepublishOnly: "pnpm build",
|
|
29
|
-
test: "vitest run",
|
|
30
|
-
"test:watch": "vitest",
|
|
31
|
-
playground: 'pnpm --filter "@playcraft/iframe-bridge-playground-*" --parallel dev',
|
|
32
|
-
lint: "echo 'No eslint config yet'",
|
|
33
|
-
release: "node ../../scripts/release-npm.mjs --packages=iframe-bridge --skip-install --skip-tests --skip-git-push"
|
|
34
|
-
},
|
|
35
|
-
devDependencies: {
|
|
36
|
-
"@rollup/plugin-json": "6.1.0",
|
|
37
|
-
"@rollup/plugin-node-resolve": "16.0.3",
|
|
38
|
-
"@rollup/plugin-swc": "0.4.0",
|
|
39
|
-
"@swc/core": "1.15.3",
|
|
40
|
-
"@types/node": "^25.2.0",
|
|
41
|
-
"happy-dom": "^20.0.10",
|
|
42
|
-
rollup: "4.57.1",
|
|
43
|
-
"rollup-plugin-dts": "6.3.0",
|
|
44
|
-
typescript: "^5.9.3",
|
|
45
|
-
vite: "^8.0.3",
|
|
46
|
-
vitest: "^3.2.4"
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
// ../iframe-bridge/src/configs/constants.ts
|
|
51
|
-
var PROTOCOL_VERSION = package_default.version;
|
|
52
|
-
var DEFAULT_REQUEST_TIMEOUT_MS = 15e4;
|
|
53
|
-
var BridgeErrorCodes = {
|
|
54
|
-
ABORTED: "ABORTED",
|
|
55
|
-
DESTROYED: "DESTROYED",
|
|
56
|
-
INTERNAL_ERROR: "INTERNAL_ERROR",
|
|
57
|
-
INVALID_PARAM: "INVALID_PARAM",
|
|
58
|
-
METHOD_NOT_FOUND: "METHOD_NOT_FOUND",
|
|
59
|
-
PEER_UNAVAILABLE: "PEER_UNAVAILABLE",
|
|
60
|
-
REQUEST_FAILED: "REQUEST_FAILED",
|
|
61
|
-
TIMEOUT: "TIMEOUT"
|
|
62
|
-
};
|
|
63
|
-
var RetCodes = {
|
|
64
|
-
OK: 0,
|
|
65
|
-
INVALID_PARAM: 1,
|
|
66
|
-
TIMEOUT: 2,
|
|
67
|
-
ABORTED: 3,
|
|
68
|
-
REQUEST_FAILED: 4,
|
|
69
|
-
INTERNAL_ERROR: 5,
|
|
70
|
-
PEER_UNAVAILABLE: 6,
|
|
71
|
-
DESTROYED: 7,
|
|
72
|
-
METHOD_NOT_FOUND: 8
|
|
73
|
-
};
|
|
74
|
-
var ERROR_CODE_TO_RET = {
|
|
75
|
-
[BridgeErrorCodes.INVALID_PARAM]: RetCodes.INVALID_PARAM,
|
|
76
|
-
[BridgeErrorCodes.TIMEOUT]: RetCodes.TIMEOUT,
|
|
77
|
-
[BridgeErrorCodes.ABORTED]: RetCodes.ABORTED,
|
|
78
|
-
[BridgeErrorCodes.REQUEST_FAILED]: RetCodes.REQUEST_FAILED,
|
|
79
|
-
[BridgeErrorCodes.INTERNAL_ERROR]: RetCodes.INTERNAL_ERROR,
|
|
80
|
-
[BridgeErrorCodes.PEER_UNAVAILABLE]: RetCodes.PEER_UNAVAILABLE,
|
|
81
|
-
[BridgeErrorCodes.DESTROYED]: RetCodes.DESTROYED,
|
|
82
|
-
[BridgeErrorCodes.METHOD_NOT_FOUND]: RetCodes.METHOD_NOT_FOUND
|
|
83
|
-
};
|
|
84
|
-
var RET_TO_ERROR_CODE = {
|
|
85
|
-
[RetCodes.INVALID_PARAM]: BridgeErrorCodes.INVALID_PARAM,
|
|
86
|
-
[RetCodes.TIMEOUT]: BridgeErrorCodes.TIMEOUT,
|
|
87
|
-
[RetCodes.ABORTED]: BridgeErrorCodes.ABORTED,
|
|
88
|
-
[RetCodes.REQUEST_FAILED]: BridgeErrorCodes.REQUEST_FAILED,
|
|
89
|
-
[RetCodes.INTERNAL_ERROR]: BridgeErrorCodes.INTERNAL_ERROR,
|
|
90
|
-
[RetCodes.PEER_UNAVAILABLE]: BridgeErrorCodes.PEER_UNAVAILABLE,
|
|
91
|
-
[RetCodes.DESTROYED]: BridgeErrorCodes.DESTROYED,
|
|
92
|
-
[RetCodes.METHOD_NOT_FOUND]: BridgeErrorCodes.METHOD_NOT_FOUND
|
|
93
|
-
};
|
|
94
|
-
function errorCodeToRet(code) {
|
|
95
|
-
return ERROR_CODE_TO_RET[code] ?? RetCodes.REQUEST_FAILED;
|
|
96
|
-
}
|
|
97
|
-
function retToErrorCode(ret) {
|
|
98
|
-
return RET_TO_ERROR_CODE[ret] ?? BridgeErrorCodes.REQUEST_FAILED;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
// ../iframe-bridge/src/utils/envelope.ts
|
|
102
|
-
function isEnvelopeKind(kind) {
|
|
103
|
-
return kind === "req" || kind === "res";
|
|
104
|
-
}
|
|
105
|
-
function isPlaycraftEnvelopeShape(data) {
|
|
106
|
-
if (!data || typeof data !== "object") return false;
|
|
107
|
-
const env = data;
|
|
108
|
-
return typeof env.__playcraft__ === "string" && isEnvelopeKind(env.kind) && typeof env.id === "string" && typeof env.name === "string";
|
|
109
|
-
}
|
|
110
|
-
function getPlaycraftEnvelopeVersionMismatch(data) {
|
|
111
|
-
if (!isPlaycraftEnvelopeShape(data)) return void 0;
|
|
112
|
-
const peer = data.__playcraft__;
|
|
113
|
-
if (peer === PROTOCOL_VERSION) return void 0;
|
|
114
|
-
return { local: PROTOCOL_VERSION, peer };
|
|
115
|
-
}
|
|
116
|
-
function createEnvelope(kind, id, name, data) {
|
|
117
|
-
return { __playcraft__: PROTOCOL_VERSION, kind, id, name, data };
|
|
118
|
-
}
|
|
119
|
-
function createSuccessResponse(id, name, data) {
|
|
120
|
-
return { ...createEnvelope("res", id, name), ret: RetCodes.OK, data };
|
|
121
|
-
}
|
|
122
|
-
function createErrorResponse(id, name, error) {
|
|
123
|
-
return {
|
|
124
|
-
...createEnvelope("res", id, name),
|
|
125
|
-
ret: error.ret,
|
|
126
|
-
msg: error.msg
|
|
127
|
-
};
|
|
128
|
-
}
|
|
129
|
-
function isPlaycraftEnvelope(data) {
|
|
130
|
-
return isPlaycraftEnvelopeShape(data);
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
// ../iframe-bridge/src/utils/errors.ts
|
|
134
|
-
var PlaycraftBridgeError = class extends Error {
|
|
135
|
-
code;
|
|
136
|
-
detail;
|
|
137
|
-
constructor(code, message, detail) {
|
|
138
|
-
super(message);
|
|
139
|
-
this.name = "PlaycraftBridgeError";
|
|
140
|
-
this.code = code;
|
|
141
|
-
this.detail = detail;
|
|
142
|
-
}
|
|
143
|
-
};
|
|
144
|
-
function isRpcError(value) {
|
|
145
|
-
return !!value && typeof value === "object" && "ret" in value && "msg" in value && typeof value.ret === "number" && typeof value.msg === "string";
|
|
146
|
-
}
|
|
147
|
-
function isLegacyCodeMessageError(value) {
|
|
148
|
-
return !!value && typeof value === "object" && "code" in value && "message" in value && typeof value.code === "string" && typeof value.message === "string";
|
|
149
|
-
}
|
|
150
|
-
function toPlaycraftError(err) {
|
|
151
|
-
if (isRpcError(err)) {
|
|
152
|
-
return err;
|
|
153
|
-
}
|
|
154
|
-
if (err instanceof PlaycraftBridgeError) {
|
|
155
|
-
return {
|
|
156
|
-
ret: errorCodeToRet(err.code),
|
|
157
|
-
msg: err.message
|
|
158
|
-
};
|
|
159
|
-
}
|
|
160
|
-
if (isLegacyCodeMessageError(err)) {
|
|
161
|
-
return {
|
|
162
|
-
ret: errorCodeToRet(err.code),
|
|
163
|
-
msg: err.message
|
|
164
|
-
};
|
|
165
|
-
}
|
|
166
|
-
return {
|
|
167
|
-
ret: RetCodes.INTERNAL_ERROR,
|
|
168
|
-
msg: err instanceof Error ? err.message : String(err)
|
|
169
|
-
};
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
// ../iframe-bridge/src/configs/method-names.ts
|
|
173
|
-
var BridgeMethods = {
|
|
174
|
-
form: {
|
|
175
|
-
get: "form.get",
|
|
176
|
-
set: "form.set"
|
|
177
|
-
},
|
|
178
|
-
image: {
|
|
179
|
-
aiGenerate: "image.aiGenerate"
|
|
180
|
-
},
|
|
181
|
-
dialog: {
|
|
182
|
-
close: "dialog.close"
|
|
183
|
-
},
|
|
184
|
-
storage: {
|
|
185
|
-
get: "storage.get"
|
|
186
|
-
},
|
|
187
|
-
child: {
|
|
188
|
-
ready: "child.ready"
|
|
189
|
-
},
|
|
190
|
-
host: {
|
|
191
|
-
init: "host.init"
|
|
192
|
-
},
|
|
193
|
-
runtimeParameters: {
|
|
194
|
-
hello: "runtime.parameters.hello",
|
|
195
|
-
snapshot: "runtime.parameters.snapshot",
|
|
196
|
-
patch: "runtime.parameters.patch",
|
|
197
|
-
restart: "runtime.parameters.restart",
|
|
198
|
-
status: "runtime.parameters.status",
|
|
199
|
-
dispose: "runtime.parameters.dispose",
|
|
200
|
-
capabilities: "runtime.parameters.capabilities",
|
|
201
|
-
result: "runtime.parameters.result",
|
|
202
|
-
resyncRequired: "runtime.parameters.resync-required"
|
|
203
|
-
}
|
|
204
|
-
};
|
|
205
|
-
var BRIDGE_EVENT_NAMES = [
|
|
206
|
-
BridgeMethods.child.ready,
|
|
207
|
-
BridgeMethods.host.init,
|
|
208
|
-
BridgeMethods.dialog.close,
|
|
209
|
-
BridgeMethods.runtimeParameters.capabilities,
|
|
210
|
-
BridgeMethods.runtimeParameters.result,
|
|
211
|
-
BridgeMethods.runtimeParameters.resyncRequired
|
|
212
|
-
];
|
|
213
|
-
var BRIDGE_RPC_NAMES = [
|
|
214
|
-
BridgeMethods.form.get,
|
|
215
|
-
BridgeMethods.form.set,
|
|
216
|
-
BridgeMethods.image.aiGenerate,
|
|
217
|
-
BridgeMethods.storage.get,
|
|
218
|
-
BridgeMethods.runtimeParameters.hello,
|
|
219
|
-
BridgeMethods.runtimeParameters.snapshot,
|
|
220
|
-
BridgeMethods.runtimeParameters.patch,
|
|
221
|
-
BridgeMethods.runtimeParameters.restart,
|
|
222
|
-
BridgeMethods.runtimeParameters.status,
|
|
223
|
-
BridgeMethods.runtimeParameters.dispose
|
|
224
|
-
];
|
|
225
|
-
|
|
226
|
-
// ../iframe-bridge/src/configs/perspective.ts
|
|
227
|
-
var BridgePerspectives = {
|
|
228
|
-
parent: "parent",
|
|
229
|
-
child: "child"
|
|
230
|
-
};
|
|
231
|
-
function bridgePeerForPerspective(perspective) {
|
|
232
|
-
return perspective === BridgePerspectives.parent ? "Parent" : "Child";
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
// ../iframe-bridge/src/utils/debug-log.ts
|
|
236
|
-
var PARENT_TO_CHILD_REQS = /* @__PURE__ */ new Set([BridgeMethods.host.init]);
|
|
237
|
-
var PEER_CONSOLE_STYLES = {
|
|
238
|
-
Parent: "color: #6366f1; font-weight: bold",
|
|
239
|
-
Child: "color: #fead43; font-weight: bold"
|
|
240
|
-
};
|
|
241
|
-
var LOCAL_CONSOLE_STYLES = {
|
|
242
|
-
[BridgePerspectives.parent]: "color: #6366f1; font-weight: bold",
|
|
243
|
-
[BridgePerspectives.child]: "color: #fead43; font-weight: bold"
|
|
244
|
-
};
|
|
245
|
-
function resolveWireFlow(name, kind) {
|
|
246
|
-
if (kind === "res" || PARENT_TO_CHILD_REQS.has(name)) {
|
|
247
|
-
return { from: "Parent", to: "Child" };
|
|
248
|
-
}
|
|
249
|
-
return { from: "Child", to: "Parent" };
|
|
250
|
-
}
|
|
251
|
-
function logBridgeDebug(perspective, direction, msg) {
|
|
252
|
-
if (!perspective) {
|
|
253
|
-
console.debug(`[playcraft:${direction}]`, msg);
|
|
254
|
-
return;
|
|
255
|
-
}
|
|
256
|
-
const { from, to } = resolveWireFlow(msg.name, msg.kind);
|
|
257
|
-
const localLabel = bridgePeerForPerspective(perspective);
|
|
258
|
-
console.debug(
|
|
259
|
-
`%c[${localLabel}]%c %c${from}%c \u2192 %c${to}%c \xB7 ${direction} \xB7 ${msg.kind} \xB7 ${msg.name}`,
|
|
260
|
-
LOCAL_CONSOLE_STYLES[perspective],
|
|
261
|
-
"",
|
|
262
|
-
PEER_CONSOLE_STYLES[from],
|
|
263
|
-
"color: inherit",
|
|
264
|
-
PEER_CONSOLE_STYLES[to],
|
|
265
|
-
"color: inherit",
|
|
266
|
-
msg
|
|
267
|
-
);
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
// ../iframe-bridge/src/utils/is-event-name.ts
|
|
271
|
-
var EVENT_NAMES = new Set(BRIDGE_EVENT_NAMES);
|
|
272
|
-
function isEventName(name) {
|
|
273
|
-
return EVENT_NAMES.has(name);
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
// ../iframe-bridge/src/utils/id.ts
|
|
277
|
-
var idSeq = 0;
|
|
278
|
-
function genId() {
|
|
279
|
-
return `${Date.now()}-${idSeq++}`;
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
// ../iframe-bridge/src/utils/send-req.ts
|
|
283
|
-
function sendReq(bridge, name, data) {
|
|
284
|
-
bridge.postMessage(createEnvelope("req", genId(), name, data));
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
// ../iframe-bridge/src/libs/invoke.ts
|
|
288
|
-
function normalizeInvokeCall(call) {
|
|
289
|
-
if (Array.isArray(call)) {
|
|
290
|
-
const [name, data, options] = call;
|
|
291
|
-
return { name, data, options };
|
|
292
|
-
}
|
|
293
|
-
return call;
|
|
294
|
-
}
|
|
295
|
-
function isInvokeGroups(input) {
|
|
296
|
-
return Array.isArray(input) && input.length > 0 && typeof input[0] === "object" && input[0] !== null && "calls" in input[0];
|
|
297
|
-
}
|
|
298
|
-
async function settleParallel(promises) {
|
|
299
|
-
const settled = await Promise.allSettled(promises);
|
|
300
|
-
return settled.map(
|
|
301
|
-
(outcome) => outcome.status === "fulfilled" ? outcome.value : { error: toPlaycraftError(outcome.reason) }
|
|
302
|
-
);
|
|
303
|
-
}
|
|
304
|
-
async function runInvokeCalls(bridge, calls, mode, batchOptions = {}, defaultTimeout = DEFAULT_REQUEST_TIMEOUT_MS) {
|
|
305
|
-
const normalized = calls.map(normalizeInvokeCall);
|
|
306
|
-
const shared = { timeout: batchOptions.timeout, signal: batchOptions.signal };
|
|
307
|
-
if (mode === "parallel") {
|
|
308
|
-
return settleParallel(
|
|
309
|
-
normalized.map(
|
|
310
|
-
(call) => emitOne(bridge, call.name, call.data, { ...shared, ...call.options }, defaultTimeout)
|
|
311
|
-
)
|
|
312
|
-
);
|
|
313
|
-
}
|
|
314
|
-
const results = [];
|
|
315
|
-
for (const call of normalized) {
|
|
316
|
-
results.push(
|
|
317
|
-
await emitOne(bridge, call.name, call.data, { ...shared, ...call.options }, defaultTimeout)
|
|
318
|
-
);
|
|
319
|
-
}
|
|
320
|
-
return results;
|
|
321
|
-
}
|
|
322
|
-
function emitOne(bridge, name, data, options = {}, defaultTimeout = DEFAULT_REQUEST_TIMEOUT_MS) {
|
|
323
|
-
if (isEventName(name)) {
|
|
324
|
-
sendReq(bridge, name, data ?? {});
|
|
325
|
-
return Promise.resolve(void 0);
|
|
326
|
-
}
|
|
327
|
-
const timeout = options.timeout ?? defaultTimeout;
|
|
328
|
-
const id = genId();
|
|
329
|
-
return new Promise((resolve, reject) => {
|
|
330
|
-
let pending;
|
|
331
|
-
const offMessage = bridge.addEventListener("message", (e) => {
|
|
332
|
-
const msg = e.data;
|
|
333
|
-
if (msg.kind !== "res" || msg.id !== id || msg.name !== name) return;
|
|
334
|
-
clearTimeout(pending.timer);
|
|
335
|
-
pending.cleanupAbortListener?.();
|
|
336
|
-
offMessage();
|
|
337
|
-
if (msg.ret === RetCodes.OK) {
|
|
338
|
-
resolve(msg.data);
|
|
339
|
-
} else {
|
|
340
|
-
reject(
|
|
341
|
-
new PlaycraftBridgeError(
|
|
342
|
-
retToErrorCode(msg.ret ?? RetCodes.REQUEST_FAILED),
|
|
343
|
-
msg.msg ?? "request failed"
|
|
344
|
-
)
|
|
345
|
-
);
|
|
346
|
-
}
|
|
347
|
-
});
|
|
348
|
-
pending = {
|
|
349
|
-
resolve,
|
|
350
|
-
reject,
|
|
351
|
-
timer: setTimeout(() => {
|
|
352
|
-
offMessage();
|
|
353
|
-
reject(
|
|
354
|
-
new PlaycraftBridgeError(
|
|
355
|
-
BridgeErrorCodes.TIMEOUT,
|
|
356
|
-
`[playcraft] emit "${name}" timeout after ${timeout}ms`
|
|
357
|
-
)
|
|
358
|
-
);
|
|
359
|
-
}, timeout),
|
|
360
|
-
offMessage
|
|
361
|
-
};
|
|
362
|
-
if (options.signal) {
|
|
363
|
-
const onAbort = () => {
|
|
364
|
-
clearTimeout(pending.timer);
|
|
365
|
-
offMessage();
|
|
366
|
-
reject(
|
|
367
|
-
new PlaycraftBridgeError(BridgeErrorCodes.ABORTED, `[playcraft] emit "${name}" aborted`)
|
|
368
|
-
);
|
|
369
|
-
};
|
|
370
|
-
if (options.signal.aborted) {
|
|
371
|
-
onAbort();
|
|
372
|
-
return;
|
|
373
|
-
}
|
|
374
|
-
options.signal.addEventListener("abort", onAbort, { once: true });
|
|
375
|
-
pending.cleanupAbortListener = () => options.signal?.removeEventListener("abort", onAbort);
|
|
376
|
-
}
|
|
377
|
-
try {
|
|
378
|
-
bridge.postMessage(createEnvelope("req", id, name, data));
|
|
379
|
-
} catch (err) {
|
|
380
|
-
clearTimeout(pending.timer);
|
|
381
|
-
offMessage();
|
|
382
|
-
reject(err);
|
|
383
|
-
}
|
|
384
|
-
});
|
|
385
|
-
}
|
|
386
|
-
function emitForBridge(bridge, nameOrCalls, dataOrOptions, options) {
|
|
387
|
-
if (typeof nameOrCalls === "string") {
|
|
388
|
-
return emitOne(
|
|
389
|
-
bridge,
|
|
390
|
-
nameOrCalls,
|
|
391
|
-
dataOrOptions,
|
|
392
|
-
options
|
|
393
|
-
);
|
|
394
|
-
}
|
|
395
|
-
const batchOptions = dataOrOptions ?? {};
|
|
396
|
-
if (isInvokeGroups(nameOrCalls)) {
|
|
397
|
-
const outerMode = batchOptions.mode ?? "serial";
|
|
398
|
-
const runGroup = (group) => runInvokeCalls(bridge, group.calls, group.mode ?? "serial", batchOptions);
|
|
399
|
-
if (outerMode === "parallel") {
|
|
400
|
-
return settleParallel(nameOrCalls.map(runGroup));
|
|
401
|
-
}
|
|
402
|
-
return (async () => {
|
|
403
|
-
const results = [];
|
|
404
|
-
for (const group of nameOrCalls) {
|
|
405
|
-
results.push(await runGroup(group));
|
|
406
|
-
}
|
|
407
|
-
return results;
|
|
408
|
-
})();
|
|
409
|
-
}
|
|
410
|
-
return runInvokeCalls(bridge, nameOrCalls, batchOptions.mode ?? "serial", batchOptions);
|
|
411
|
-
}
|
|
412
|
-
|
|
413
|
-
// ../iframe-bridge/src/libs/handle.ts
|
|
414
|
-
function safeReply(bridge, message) {
|
|
415
|
-
try {
|
|
416
|
-
bridge.postMessage(message);
|
|
417
|
-
} catch (err) {
|
|
418
|
-
if (err instanceof PlaycraftBridgeError && err.code === BridgeErrorCodes.PEER_UNAVAILABLE) {
|
|
419
|
-
return;
|
|
420
|
-
}
|
|
421
|
-
throw err;
|
|
422
|
-
}
|
|
423
|
-
}
|
|
424
|
-
function onForBridge(bridge, name, fn) {
|
|
425
|
-
return bridge.addEventListener("message", async (e) => {
|
|
426
|
-
const msg = e.data;
|
|
427
|
-
if (msg.kind !== "req" || msg.name !== name) return;
|
|
428
|
-
if (isEventName(name)) {
|
|
429
|
-
await fn(msg.data);
|
|
430
|
-
return;
|
|
431
|
-
}
|
|
432
|
-
try {
|
|
433
|
-
const data = await fn(msg.data, {
|
|
434
|
-
id: msg.id
|
|
435
|
-
});
|
|
436
|
-
safeReply(bridge, createSuccessResponse(msg.id, msg.name, data));
|
|
437
|
-
} catch (err) {
|
|
438
|
-
safeReply(bridge, createErrorResponse(msg.id, msg.name, toPlaycraftError(err)));
|
|
439
|
-
}
|
|
440
|
-
});
|
|
441
|
-
}
|
|
442
|
-
|
|
443
|
-
// ../iframe-bridge/src/libs/bridge.ts
|
|
444
|
-
var Bridge = class {
|
|
445
|
-
constructor(options) {
|
|
446
|
-
this.options = options;
|
|
447
|
-
this.targetOrigin = options.targetOrigin;
|
|
448
|
-
this.messageTarget = options.messageTarget ?? window;
|
|
449
|
-
this.messageTarget.addEventListener("message", this.onWindowMessage);
|
|
450
|
-
}
|
|
451
|
-
options;
|
|
452
|
-
targetOrigin;
|
|
453
|
-
listeners = /* @__PURE__ */ new Set();
|
|
454
|
-
warnedPeerVersions = /* @__PURE__ */ new Set();
|
|
455
|
-
destroyed = false;
|
|
456
|
-
messageTarget;
|
|
457
|
-
emit(nameOrCalls, dataOrOptions, options) {
|
|
458
|
-
return emitForBridge(this, nameOrCalls, dataOrOptions, options);
|
|
459
|
-
}
|
|
460
|
-
on(name, fn) {
|
|
461
|
-
return onForBridge(this, name, fn);
|
|
462
|
-
}
|
|
463
|
-
postMessage(message, targetOrigin = this.options.targetOrigin, transfer) {
|
|
464
|
-
this.assertAlive();
|
|
465
|
-
const peer = this.options.peer();
|
|
466
|
-
if (!peer) {
|
|
467
|
-
throw new PlaycraftBridgeError(
|
|
468
|
-
BridgeErrorCodes.PEER_UNAVAILABLE,
|
|
469
|
-
"[playcraft] peer window is not available"
|
|
470
|
-
);
|
|
471
|
-
}
|
|
472
|
-
this.log("send", message);
|
|
473
|
-
peer.postMessage(message, targetOrigin, transfer ?? []);
|
|
474
|
-
}
|
|
475
|
-
addEventListener(type, listener) {
|
|
476
|
-
this.assertAlive();
|
|
477
|
-
this.listeners.add(listener);
|
|
478
|
-
return () => this.listeners.delete(listener);
|
|
479
|
-
}
|
|
480
|
-
destroy() {
|
|
481
|
-
if (this.destroyed) return;
|
|
482
|
-
this.destroyed = true;
|
|
483
|
-
this.messageTarget.removeEventListener("message", this.onWindowMessage);
|
|
484
|
-
this.listeners.clear();
|
|
485
|
-
}
|
|
486
|
-
assertAlive() {
|
|
487
|
-
if (this.destroyed) {
|
|
488
|
-
throw new PlaycraftBridgeError(BridgeErrorCodes.DESTROYED, "[playcraft] bridge destroyed");
|
|
489
|
-
}
|
|
490
|
-
}
|
|
491
|
-
log(event, msg) {
|
|
492
|
-
const { debug, perspective } = this.options;
|
|
493
|
-
if (!debug) return;
|
|
494
|
-
if (typeof debug === "function") debug(event, msg);
|
|
495
|
-
else logBridgeDebug(perspective, event, msg);
|
|
496
|
-
}
|
|
497
|
-
warnVersionMismatch(localVersion, peerVersion) {
|
|
498
|
-
if (this.warnedPeerVersions.has(peerVersion)) return;
|
|
499
|
-
this.warnedPeerVersions.add(peerVersion);
|
|
500
|
-
console.warn(
|
|
501
|
-
`[playcraft] protocol version mismatch: local ${localVersion}, peer ${peerVersion}. Messages are still processed; align @playcraft/iframe-bridge versions when possible.`
|
|
502
|
-
);
|
|
503
|
-
}
|
|
504
|
-
onWindowMessage = (e) => {
|
|
505
|
-
const msgEvent = e;
|
|
506
|
-
if (this.destroyed || !this.options.allowedOrigins.includes(msgEvent.origin)) return;
|
|
507
|
-
if (this.options.strictSource) {
|
|
508
|
-
const peer = this.options.peer();
|
|
509
|
-
if (!peer || msgEvent.source !== peer) return;
|
|
510
|
-
}
|
|
511
|
-
if (!isPlaycraftEnvelope(msgEvent.data)) return;
|
|
512
|
-
const mismatch = getPlaycraftEnvelopeVersionMismatch(msgEvent.data);
|
|
513
|
-
if (mismatch) {
|
|
514
|
-
this.warnVersionMismatch(mismatch.local, mismatch.peer);
|
|
515
|
-
}
|
|
516
|
-
this.log("recv", msgEvent.data);
|
|
517
|
-
const event = {
|
|
518
|
-
data: msgEvent.data,
|
|
519
|
-
origin: msgEvent.origin,
|
|
520
|
-
source: msgEvent.source
|
|
521
|
-
};
|
|
522
|
-
this.listeners.forEach((fn) => fn(event));
|
|
523
|
-
};
|
|
524
|
-
};
|
|
525
|
-
|
|
526
|
-
// ../preview-runtime/src/protocol.ts
|
|
527
|
-
var ProtocolError = class extends Error {
|
|
528
|
-
constructor(code, message) {
|
|
529
|
-
super(message);
|
|
530
|
-
this.code = code;
|
|
531
|
-
this.name = "ProtocolError";
|
|
532
|
-
}
|
|
533
|
-
code;
|
|
534
|
-
};
|
|
535
|
-
var forbidden = /* @__PURE__ */ new Set(["__proto__", "prototype", "constructor"]);
|
|
536
|
-
var record = (value) => !!value && typeof value === "object" && !Array.isArray(value) && (Object.getPrototypeOf(value) === Object.prototype || Object.getPrototypeOf(value) === null);
|
|
537
|
-
var exactKeys = (value, allowed) => {
|
|
538
|
-
if (Object.keys(value).some((key) => !allowed.includes(key)))
|
|
539
|
-
throw new ProtocolError("INVALID", "Unexpected message field");
|
|
540
|
-
};
|
|
541
|
-
var string = (v) => typeof v === "string" && v.length > 0 && v.length <= 1024;
|
|
542
|
-
var revision = (v) => Number.isSafeInteger(v) && v >= 0;
|
|
543
|
-
function assertJson(value, depth = 0) {
|
|
544
|
-
if (depth > 64) throw new ProtocolError("LIMIT", "Configuration nesting exceeds limit");
|
|
545
|
-
if (value === null || typeof value === "boolean" || typeof value === "string" || typeof value === "number" && Number.isFinite(value))
|
|
546
|
-
return;
|
|
547
|
-
if (Array.isArray(value)) {
|
|
548
|
-
for (const child of value) assertJson(child, depth + 1);
|
|
549
|
-
return;
|
|
550
|
-
}
|
|
551
|
-
if (record(value)) {
|
|
552
|
-
for (const [key, child] of Object.entries(value)) {
|
|
553
|
-
if (forbidden.has(key)) throw new ProtocolError("INVALID", "Unsafe configuration key");
|
|
554
|
-
assertJson(child, depth + 1);
|
|
555
|
-
}
|
|
556
|
-
return;
|
|
557
|
-
}
|
|
558
|
-
throw new ProtocolError("INVALID", "Configuration must contain finite JSON data");
|
|
559
|
-
}
|
|
560
|
-
function clone(value) {
|
|
561
|
-
return structuredClone(value);
|
|
562
|
-
}
|
|
563
|
-
function freeze(value) {
|
|
564
|
-
if (value && typeof value === "object") {
|
|
565
|
-
Object.freeze(value);
|
|
566
|
-
for (const child of Object.values(value)) freeze(child);
|
|
567
|
-
}
|
|
568
|
-
return value;
|
|
569
|
-
}
|
|
570
|
-
function fingerprint(value) {
|
|
571
|
-
if (Array.isArray(value)) return "[" + value.map(fingerprint).join(",") + "]";
|
|
572
|
-
if (record(value))
|
|
573
|
-
return "{" + Object.keys(value).sort().map((k) => JSON.stringify(k) + ":" + fingerprint(value[k])).join(",") + "}";
|
|
574
|
-
return JSON.stringify(value);
|
|
575
|
-
}
|
|
576
|
-
function assertHello(value) {
|
|
577
|
-
if (!record(value) || value.protocolVersion !== 1 || !string(value.sessionId) || !revision(value.frameEpoch) || !string(value.schemaVersion) || !string(value.configContractVersion) || !string(value.locale) || !record(value.scope))
|
|
578
|
-
throw new ProtocolError("IDENTITY", "Invalid runtime session binding");
|
|
579
|
-
if (!["projectId", "branchName", "themeId"].every(
|
|
580
|
-
(k) => string(value.scope[k])
|
|
581
|
-
))
|
|
582
|
-
throw new ProtocolError("IDENTITY", "Invalid configuration scope");
|
|
583
|
-
exactKeys(value.scope, ["projectId", "branchName", "themeId"]);
|
|
584
|
-
}
|
|
585
|
-
function assertIdentity(value) {
|
|
586
|
-
assertHello(value);
|
|
587
|
-
if (!string(value.runtimeInstanceId))
|
|
588
|
-
throw new ProtocolError("IDENTITY", "Missing runtime instance");
|
|
589
|
-
}
|
|
590
|
-
function sameIdentity(a, b) {
|
|
591
|
-
try {
|
|
592
|
-
assertIdentity(b);
|
|
593
|
-
} catch {
|
|
594
|
-
return false;
|
|
595
|
-
}
|
|
596
|
-
return [
|
|
597
|
-
"protocolVersion",
|
|
598
|
-
"sessionId",
|
|
599
|
-
"frameEpoch",
|
|
600
|
-
"runtimeInstanceId",
|
|
601
|
-
"schemaVersion",
|
|
602
|
-
"configContractVersion",
|
|
603
|
-
"locale"
|
|
604
|
-
].every((k) => a[k] === b[k]) && fingerprint(a.scope) === fingerprint(b.scope);
|
|
605
|
-
}
|
|
606
|
-
function assertBinding(expected, actual) {
|
|
607
|
-
if (fingerprint(expected.scope) !== fingerprint(actual.scope) || expected.locale !== actual.locale || expected.schemaVersion !== actual.schemaVersion || expected.configContractVersion !== actual.configContractVersion)
|
|
608
|
-
throw new ProtocolError("CONTRACT", "Scope, locale, schema or configuration contract mismatch");
|
|
609
|
-
}
|
|
610
|
-
function assertDocuments(value) {
|
|
611
|
-
assertJson(value);
|
|
612
|
-
if (!record(value) || Object.values(value).some((v) => !record(v)))
|
|
613
|
-
throw new ProtocolError("INVALID", "Expected raw document objects");
|
|
614
|
-
}
|
|
615
|
-
var identityKeys = [
|
|
616
|
-
"protocolVersion",
|
|
617
|
-
"sessionId",
|
|
618
|
-
"frameEpoch",
|
|
619
|
-
"runtimeInstanceId",
|
|
620
|
-
"scope",
|
|
621
|
-
"schemaVersion",
|
|
622
|
-
"configContractVersion",
|
|
623
|
-
"locale"
|
|
624
|
-
];
|
|
625
|
-
function assertSnapshot(value) {
|
|
626
|
-
assertIdentity(value);
|
|
627
|
-
exactKeys(value, [
|
|
628
|
-
...identityKeys,
|
|
629
|
-
"draftRevision",
|
|
630
|
-
"documents"
|
|
631
|
-
]);
|
|
632
|
-
if (!revision(value.draftRevision))
|
|
633
|
-
throw new ProtocolError("INVALID", "Invalid snapshot revision");
|
|
634
|
-
assertDocuments(value.documents);
|
|
635
|
-
limit(value, 512 * 1024);
|
|
636
|
-
}
|
|
637
|
-
function assertPatch(value) {
|
|
638
|
-
assertIdentity(value);
|
|
639
|
-
const v = value;
|
|
640
|
-
exactKeys(v, [
|
|
641
|
-
...identityKeys,
|
|
642
|
-
"baseDraftRevision",
|
|
643
|
-
"draftRevision",
|
|
644
|
-
"phase",
|
|
645
|
-
"operations"
|
|
646
|
-
]);
|
|
647
|
-
if (!revision(v.baseDraftRevision) || !revision(v.draftRevision) || v.draftRevision !== v.baseDraftRevision + 1 || !["preview", "commit"].includes(v.phase) || !Array.isArray(v.operations) || v.operations.length > 256)
|
|
648
|
-
throw new ProtocolError("INVALID", "Invalid patch sequence or operation count");
|
|
649
|
-
for (const op of v.operations) {
|
|
650
|
-
if (!record(op) || !["set", "remove"].includes(op.op) || !string(op.documentId) || forbidden.has(op.documentId) || !Array.isArray(op.path) || !op.path.length || op.path.length > 32 || op.path.some((p) => !string(p) || forbidden.has(p)))
|
|
651
|
-
throw new ProtocolError("INVALID", "Unsafe or invalid operation path");
|
|
652
|
-
exactKeys(
|
|
653
|
-
op,
|
|
654
|
-
op.op === "set" ? ["op", "documentId", "path", "value"] : ["op", "documentId", "path"]
|
|
655
|
-
);
|
|
656
|
-
if (op.op === "set") assertJson(op.value);
|
|
657
|
-
}
|
|
658
|
-
limit(v, 64 * 1024);
|
|
659
|
-
}
|
|
660
|
-
function limit(value, bytes) {
|
|
661
|
-
if (new TextEncoder().encode(JSON.stringify(value)).length > bytes)
|
|
662
|
-
throw new ProtocolError("LIMIT", "Runtime message exceeds byte limit");
|
|
663
|
-
}
|
|
664
|
-
function applyOperations(documents, operations) {
|
|
665
|
-
const next = clone(documents);
|
|
666
|
-
for (const op of operations) {
|
|
667
|
-
if (op.op === "remove" && readPath(next[op.documentId], op.path) === void 0) continue;
|
|
668
|
-
let target = next[op.documentId] ??= {};
|
|
669
|
-
for (const part of op.path.slice(0, -1)) {
|
|
670
|
-
if (!record(target[part])) target[part] = {};
|
|
671
|
-
target = target[part];
|
|
672
|
-
}
|
|
673
|
-
const key = op.path[op.path.length - 1];
|
|
674
|
-
if (op.op === "set") target[key] = clone(op.value);
|
|
675
|
-
else delete target[key];
|
|
676
|
-
}
|
|
677
|
-
return next;
|
|
678
|
-
}
|
|
679
|
-
function readPath(value, path) {
|
|
680
|
-
for (const key of path) {
|
|
681
|
-
if (!record(value) && !Array.isArray(value)) return void 0;
|
|
682
|
-
value = value[key];
|
|
683
|
-
}
|
|
684
|
-
return value;
|
|
685
|
-
}
|
|
686
|
-
|
|
687
|
-
// ../preview-runtime/src/runtime.ts
|
|
688
|
-
function createParameterRuntime(options) {
|
|
689
|
-
const runtimeInstanceId = crypto.randomUUID();
|
|
690
|
-
let identity;
|
|
691
|
-
let controller = new AbortController();
|
|
692
|
-
let queue = Promise.resolve();
|
|
693
|
-
let adapter;
|
|
694
|
-
let target;
|
|
695
|
-
let installed;
|
|
696
|
-
let receivedRevision = -1, installedRevision = -1, appliedRevision = -1;
|
|
697
|
-
let stage = "bootstrap-ready";
|
|
698
|
-
let status = "idle";
|
|
699
|
-
let error;
|
|
700
|
-
let disposed = false;
|
|
701
|
-
let cleanupFailure;
|
|
702
|
-
let resultSequence = 0;
|
|
703
|
-
const retiredSessions = /* @__PURE__ */ new Set();
|
|
704
|
-
const groups = /* @__PURE__ */ new Map();
|
|
705
|
-
const receipts = /* @__PURE__ */ new Map();
|
|
706
|
-
const listeners = /* @__PURE__ */ new Set();
|
|
707
|
-
const capabilityListeners = /* @__PURE__ */ new Set();
|
|
708
|
-
async function release(game) {
|
|
709
|
-
try {
|
|
710
|
-
await game?.dispose();
|
|
711
|
-
} catch (e) {
|
|
712
|
-
cleanupFailure = e;
|
|
713
|
-
throw e;
|
|
714
|
-
}
|
|
715
|
-
}
|
|
716
|
-
for (const field of options.fields)
|
|
717
|
-
groups.set(field.groupId, { groupId: field.groupId, appliedRevision: -1, status: "unknown" });
|
|
718
|
-
const capabilities = () => ({
|
|
719
|
-
...requireIdentity(),
|
|
720
|
-
stage,
|
|
721
|
-
canAcceptSnapshot: true,
|
|
722
|
-
fields: clone(options.fields)
|
|
723
|
-
});
|
|
724
|
-
function requireIdentity() {
|
|
725
|
-
if (!identity || disposed)
|
|
726
|
-
throw new ProtocolError("SESSION", "Runtime session is not connected");
|
|
727
|
-
return identity;
|
|
728
|
-
}
|
|
729
|
-
function check(value) {
|
|
730
|
-
assertIdentity(value);
|
|
731
|
-
if (!sameIdentity(requireIdentity(), value))
|
|
732
|
-
throw new ProtocolError("STALE", "Stale runtime identity");
|
|
733
|
-
}
|
|
734
|
-
const result = () => ({
|
|
735
|
-
...requireIdentity(),
|
|
736
|
-
resultSequence,
|
|
737
|
-
receivedRevision,
|
|
738
|
-
installedRevision,
|
|
739
|
-
appliedRevision,
|
|
740
|
-
status,
|
|
741
|
-
groups: clone([...groups.values()]),
|
|
742
|
-
...error ? { error } : {}
|
|
743
|
-
});
|
|
744
|
-
function publish() {
|
|
745
|
-
if (!identity || disposed) return;
|
|
746
|
-
resultSequence++;
|
|
747
|
-
const value = result();
|
|
748
|
-
listeners.forEach((fn) => fn(value));
|
|
749
|
-
}
|
|
750
|
-
function context(config, beforeConfig, draftRevision, fields, signal) {
|
|
751
|
-
return {
|
|
752
|
-
config,
|
|
753
|
-
beforeConfig,
|
|
754
|
-
draftRevision,
|
|
755
|
-
fields,
|
|
756
|
-
signal,
|
|
757
|
-
assertCurrent() {
|
|
758
|
-
signal.throwIfAborted();
|
|
759
|
-
if (signal !== controller.signal || disposed)
|
|
760
|
-
throw new ProtocolError("STALE", "Application task expired");
|
|
761
|
-
}
|
|
762
|
-
};
|
|
763
|
-
}
|
|
764
|
-
function enqueue(work) {
|
|
765
|
-
const signal = controller.signal;
|
|
766
|
-
queue = queue.then(async () => {
|
|
767
|
-
if (signal.aborted) return;
|
|
768
|
-
try {
|
|
769
|
-
await work(signal);
|
|
770
|
-
} catch (e) {
|
|
771
|
-
if (signal.aborted) return;
|
|
772
|
-
status = "error";
|
|
773
|
-
installedRevision = appliedRevision = -1;
|
|
774
|
-
error = e instanceof Error ? e.message : String(e);
|
|
775
|
-
for (const group of groups.values()) group.status = "unknown";
|
|
776
|
-
publish();
|
|
777
|
-
}
|
|
778
|
-
});
|
|
779
|
-
}
|
|
780
|
-
function remember(kind, request) {
|
|
781
|
-
const key = `${kind}:${request.draftRevision}`;
|
|
782
|
-
const previous = receipts.get(key);
|
|
783
|
-
if (previous) {
|
|
784
|
-
if (previous.fingerprint !== fingerprint(request))
|
|
785
|
-
throw new ProtocolError("CONFLICT", "Revision was already accepted with different content");
|
|
786
|
-
return previous.receipt;
|
|
787
|
-
}
|
|
788
|
-
return void 0;
|
|
789
|
-
}
|
|
790
|
-
function accept(kind, request) {
|
|
791
|
-
receivedRevision = request.draftRevision;
|
|
792
|
-
const receipt = { accepted: true, receivedRevision };
|
|
793
|
-
receipts.set(`${kind}:${receivedRevision}`, { fingerprint: fingerprint(request), receipt });
|
|
794
|
-
if (receipts.size > 256) receipts.delete(receipts.keys().next().value);
|
|
795
|
-
return receipt;
|
|
796
|
-
}
|
|
797
|
-
function updateState(rev, changed) {
|
|
798
|
-
for (const field of changed)
|
|
799
|
-
groups.set(field.groupId, {
|
|
800
|
-
groupId: field.groupId,
|
|
801
|
-
appliedRevision: rev,
|
|
802
|
-
status: "applied"
|
|
803
|
-
});
|
|
804
|
-
let pending = false, reload = false;
|
|
805
|
-
for (const field of options.fields) {
|
|
806
|
-
if (fingerprint(readPath(installed?.[field.documentId], field.path)) !== fingerprint(readPath(target?.[field.documentId], field.path))) {
|
|
807
|
-
const group = groups.get(field.groupId);
|
|
808
|
-
group.status = field.mode === "reload" ? "requires-reload" : "pending-commit";
|
|
809
|
-
pending = true;
|
|
810
|
-
reload ||= field.mode === "reload";
|
|
811
|
-
}
|
|
812
|
-
}
|
|
813
|
-
if (fingerprint(installed) === fingerprint(target)) {
|
|
814
|
-
appliedRevision = receivedRevision;
|
|
815
|
-
installedRevision = receivedRevision;
|
|
816
|
-
status = "applied";
|
|
817
|
-
} else status = reload ? "requires-reload" : pending ? "pending-commit" : "applying";
|
|
818
|
-
publish();
|
|
819
|
-
}
|
|
820
|
-
async function applyTarget(documents, rev, commit, signal) {
|
|
821
|
-
if (status === "error") return;
|
|
822
|
-
if (!adapter || !installed)
|
|
823
|
-
throw new ProtocolError("STATE", "Initial snapshot must create the game first");
|
|
824
|
-
const operations = [];
|
|
825
|
-
for (const field of options.fields) {
|
|
826
|
-
if (field.mode !== "live" && !(commit && field.mode === "restart-scene")) continue;
|
|
827
|
-
const value = readPath(documents[field.documentId], field.path);
|
|
828
|
-
operations.push(
|
|
829
|
-
value === void 0 ? { op: "remove", documentId: field.documentId, path: field.path } : {
|
|
830
|
-
op: "set",
|
|
831
|
-
documentId: field.documentId,
|
|
832
|
-
path: field.path,
|
|
833
|
-
value: clone(value)
|
|
834
|
-
}
|
|
835
|
-
);
|
|
836
|
-
}
|
|
837
|
-
const candidate = applyOperations(installed, operations);
|
|
838
|
-
const before = options.source.get();
|
|
839
|
-
const config = freeze(options.resolve(freeze(clone(candidate))));
|
|
840
|
-
const changed = options.fields.filter(
|
|
841
|
-
(field) => fingerprint(readPath(before, field.effectivePath)) !== fingerprint(readPath(config, field.effectivePath))
|
|
842
|
-
);
|
|
843
|
-
const ctx = context(config, before, rev, changed, signal);
|
|
844
|
-
ctx.assertCurrent();
|
|
845
|
-
status = "applying";
|
|
846
|
-
publish();
|
|
847
|
-
options.source.install(config);
|
|
848
|
-
installedRevision = fingerprint(candidate) === fingerprint(documents) ? rev : -1;
|
|
849
|
-
try {
|
|
850
|
-
if (changed.some((field) => field.mode === "restart-scene")) await adapter.restartScene(ctx);
|
|
851
|
-
else if (changed.length) await adapter.apply(ctx);
|
|
852
|
-
ctx.assertCurrent();
|
|
853
|
-
await adapter.afterRender(ctx);
|
|
854
|
-
ctx.assertCurrent();
|
|
855
|
-
installed = candidate;
|
|
856
|
-
updateState(rev, changed);
|
|
857
|
-
} catch (e) {
|
|
858
|
-
if (!signal.aborted) options.source.install(before);
|
|
859
|
-
throw e;
|
|
860
|
-
}
|
|
861
|
-
}
|
|
862
|
-
return {
|
|
863
|
-
hello(value) {
|
|
864
|
-
assertHello(value);
|
|
865
|
-
assertBinding(options.binding, value);
|
|
866
|
-
if (disposed) throw new ProtocolError("DISPOSED", "Runtime endpoint is disposed");
|
|
867
|
-
if (retiredSessions.has(value.sessionId))
|
|
868
|
-
throw new ProtocolError("STALE", "Retired runtime session");
|
|
869
|
-
if (identity && value.sessionId === identity.sessionId && value.frameEpoch < identity.frameEpoch)
|
|
870
|
-
throw new ProtocolError("STALE", "Old frame epoch");
|
|
871
|
-
if (identity && fingerprint({ ...identity, runtimeInstanceId: void 0 }) === fingerprint({ ...value, runtimeInstanceId: void 0 }))
|
|
872
|
-
return capabilities();
|
|
873
|
-
if (identity && identity.sessionId !== value.sessionId)
|
|
874
|
-
retiredSessions.add(identity.sessionId);
|
|
875
|
-
controller.abort();
|
|
876
|
-
controller = new AbortController();
|
|
877
|
-
const previous = adapter;
|
|
878
|
-
adapter = void 0;
|
|
879
|
-
queue = queue.then(async () => {
|
|
880
|
-
await release(previous);
|
|
881
|
-
}).catch((e) => {
|
|
882
|
-
cleanupFailure = e;
|
|
883
|
-
});
|
|
884
|
-
identity = freeze({ ...clone(value), runtimeInstanceId });
|
|
885
|
-
target = installed = void 0;
|
|
886
|
-
receivedRevision = installedRevision = appliedRevision = -1;
|
|
887
|
-
receipts.clear();
|
|
888
|
-
stage = "bootstrap-ready";
|
|
889
|
-
status = "idle";
|
|
890
|
-
error = void 0;
|
|
891
|
-
resultSequence = 0;
|
|
892
|
-
for (const group of groups.values()) {
|
|
893
|
-
group.appliedRevision = -1;
|
|
894
|
-
group.status = "unknown";
|
|
895
|
-
}
|
|
896
|
-
return capabilities();
|
|
897
|
-
},
|
|
898
|
-
snapshot(value) {
|
|
899
|
-
assertSnapshot(value);
|
|
900
|
-
check(value);
|
|
901
|
-
const previous = remember("snapshot", value);
|
|
902
|
-
if (previous) return previous;
|
|
903
|
-
if (value.draftRevision < receivedRevision)
|
|
904
|
-
throw new ProtocolError("STALE", "Old snapshot revision");
|
|
905
|
-
if (value.draftRevision === receivedRevision && fingerprint(value.documents) !== fingerprint(target))
|
|
906
|
-
throw new ProtocolError("CONFLICT", "Snapshot cannot change an already accepted revision");
|
|
907
|
-
const rev = value.draftRevision;
|
|
908
|
-
const documents = freeze(clone(value.documents));
|
|
909
|
-
options.resolve(documents);
|
|
910
|
-
target = documents;
|
|
911
|
-
const receipt = accept("snapshot", value);
|
|
912
|
-
enqueue(async (signal) => {
|
|
913
|
-
if (cleanupFailure)
|
|
914
|
-
throw new ProtocolError(
|
|
915
|
-
"RECOVERY",
|
|
916
|
-
"Previous game cleanup failed; reload the preview frame"
|
|
917
|
-
);
|
|
918
|
-
const before = options.source.get();
|
|
919
|
-
const config = freeze(options.resolve(documents));
|
|
920
|
-
const ctx = context(config, before, rev, clone(options.fields), signal);
|
|
921
|
-
ctx.assertCurrent();
|
|
922
|
-
status = "applying";
|
|
923
|
-
publish();
|
|
924
|
-
const previousAdapter = adapter;
|
|
925
|
-
adapter = void 0;
|
|
926
|
-
stage = "bootstrap-ready";
|
|
927
|
-
await release(previousAdapter);
|
|
928
|
-
ctx.assertCurrent();
|
|
929
|
-
options.source.install(config);
|
|
930
|
-
installedRevision = rev;
|
|
931
|
-
let created;
|
|
932
|
-
try {
|
|
933
|
-
created = await options.createGame(ctx);
|
|
934
|
-
if (signal.aborted) {
|
|
935
|
-
await release(created);
|
|
936
|
-
return;
|
|
937
|
-
}
|
|
938
|
-
ctx.assertCurrent();
|
|
939
|
-
adapter = created;
|
|
940
|
-
stage = "game-ready";
|
|
941
|
-
capabilityListeners.forEach((fn) => fn(capabilities()));
|
|
942
|
-
await created.afterRender(ctx);
|
|
943
|
-
ctx.assertCurrent();
|
|
944
|
-
installed = clone(documents);
|
|
945
|
-
error = void 0;
|
|
946
|
-
updateState(rev, options.fields);
|
|
947
|
-
} catch (e) {
|
|
948
|
-
if (!signal.aborted) {
|
|
949
|
-
adapter = void 0;
|
|
950
|
-
stage = "bootstrap-ready";
|
|
951
|
-
options.source.install(before);
|
|
952
|
-
capabilityListeners.forEach((fn) => fn(capabilities()));
|
|
953
|
-
}
|
|
954
|
-
await release(created);
|
|
955
|
-
throw e;
|
|
956
|
-
}
|
|
957
|
-
});
|
|
958
|
-
return receipt;
|
|
959
|
-
},
|
|
960
|
-
patch(value) {
|
|
961
|
-
assertPatch(value);
|
|
962
|
-
check(value);
|
|
963
|
-
const previous = remember("patch", value);
|
|
964
|
-
if (previous) return previous;
|
|
965
|
-
if (!target || value.baseDraftRevision !== receivedRevision)
|
|
966
|
-
throw new ProtocolError("RESYNC", "Patch base does not match received revision");
|
|
967
|
-
if (status === "error")
|
|
968
|
-
throw new ProtocolError(
|
|
969
|
-
"RECOVERY",
|
|
970
|
-
"Application state is unknown; send a recovery snapshot"
|
|
971
|
-
);
|
|
972
|
-
for (const op of value.operations)
|
|
973
|
-
if (!options.fields.some(
|
|
974
|
-
(field) => field.documentId === op.documentId && fingerprint(field.path) === fingerprint(op.path)
|
|
975
|
-
))
|
|
976
|
-
throw new ProtocolError("UNSUPPORTED", "Unregistered parameter path");
|
|
977
|
-
const documents = freeze(applyOperations(target, value.operations));
|
|
978
|
-
const rev = value.draftRevision, commit = value.phase === "commit";
|
|
979
|
-
options.resolve(documents);
|
|
980
|
-
target = documents;
|
|
981
|
-
const receipt = accept("patch", value);
|
|
982
|
-
enqueue((signal) => applyTarget(documents, rev, commit, signal));
|
|
983
|
-
return receipt;
|
|
984
|
-
},
|
|
985
|
-
restart(value) {
|
|
986
|
-
check(value);
|
|
987
|
-
if (status === "error")
|
|
988
|
-
throw new ProtocolError(
|
|
989
|
-
"RECOVERY",
|
|
990
|
-
"Application state is unknown; send a recovery snapshot"
|
|
991
|
-
);
|
|
992
|
-
const rev = value.draftRevision;
|
|
993
|
-
if (rev !== receivedRevision || !target)
|
|
994
|
-
throw new ProtocolError("STALE", "Restart must name the current target");
|
|
995
|
-
const documents = clone(target);
|
|
996
|
-
enqueue((signal) => applyTarget(documents, rev, true, signal));
|
|
997
|
-
return { accepted: true, receivedRevision };
|
|
998
|
-
},
|
|
999
|
-
status(value) {
|
|
1000
|
-
check(value);
|
|
1001
|
-
return result();
|
|
1002
|
-
},
|
|
1003
|
-
subscribe(fn) {
|
|
1004
|
-
listeners.add(fn);
|
|
1005
|
-
return () => listeners.delete(fn);
|
|
1006
|
-
},
|
|
1007
|
-
onCapabilities(fn) {
|
|
1008
|
-
capabilityListeners.add(fn);
|
|
1009
|
-
return () => capabilityListeners.delete(fn);
|
|
1010
|
-
},
|
|
1011
|
-
async settled() {
|
|
1012
|
-
await queue;
|
|
1013
|
-
},
|
|
1014
|
-
async dispose() {
|
|
1015
|
-
if (disposed) return;
|
|
1016
|
-
disposed = true;
|
|
1017
|
-
controller.abort();
|
|
1018
|
-
listeners.clear();
|
|
1019
|
-
capabilityListeners.clear();
|
|
1020
|
-
await queue;
|
|
1021
|
-
await adapter?.dispose();
|
|
1022
|
-
adapter = void 0;
|
|
1023
|
-
}
|
|
1024
|
-
};
|
|
1025
|
-
}
|
|
1026
|
-
|
|
1027
|
-
// ../preview-runtime/src/preview.ts
|
|
1028
|
-
function readWorkspacePreviewContext(expectedContractVersion) {
|
|
1029
|
-
try {
|
|
1030
|
-
const mark = "playcraft-preview-storage:";
|
|
1031
|
-
if (!window.name.startsWith(mark)) throw new Error("Missing workspace context");
|
|
1032
|
-
const context = JSON.parse(window.name.slice(mark.length)).__playcraft_preview_context__;
|
|
1033
|
-
if (!context || typeof context.parentOrigin !== "string" || !context.binding)
|
|
1034
|
-
throw new Error("Missing workspace binding");
|
|
1035
|
-
const parent = new URL(context.parentOrigin);
|
|
1036
|
-
if (!["http:", "https:"].includes(parent.protocol) || parent.origin !== context.parentOrigin || parent.origin === "null")
|
|
1037
|
-
throw new Error("Invalid parent origin");
|
|
1038
|
-
const hello = {
|
|
1039
|
-
...context.binding,
|
|
1040
|
-
protocolVersion: 1,
|
|
1041
|
-
sessionId: "workspace-context",
|
|
1042
|
-
frameEpoch: 0
|
|
1043
|
-
};
|
|
1044
|
-
assertHello(hello);
|
|
1045
|
-
if (context.binding.configContractVersion !== expectedContractVersion)
|
|
1046
|
-
throw new Error("Unexpected configuration contract");
|
|
1047
|
-
const profiles = document.querySelectorAll("script#playcraft-runtime-profile");
|
|
1048
|
-
if (profiles.length !== 1 || profiles[0].getAttribute("type") !== "application/json")
|
|
1049
|
-
throw new Error("Missing build profile");
|
|
1050
|
-
const profile = JSON.parse(profiles[0].textContent ?? "");
|
|
1051
|
-
if (profile.version !== 1 || profile.protocolVersion !== 1 || profile.target !== "editor-static")
|
|
1052
|
-
throw new Error("Invalid build profile");
|
|
1053
|
-
assertBinding(profile.binding, hello);
|
|
1054
|
-
return freeze(
|
|
1055
|
-
clone({ binding: context.binding, parentOrigin: parent.origin })
|
|
1056
|
-
);
|
|
1057
|
-
} catch (error) {
|
|
1058
|
-
throw new ProtocolError(
|
|
1059
|
-
"CONTEXT",
|
|
1060
|
-
error instanceof Error ? error.message : "Invalid workspace preview context"
|
|
1061
|
-
);
|
|
1062
|
-
}
|
|
1063
|
-
}
|
|
1064
|
-
function connectPreviewRuntime(options) {
|
|
1065
|
-
const origin = new URL(options.parentOrigin).origin;
|
|
1066
|
-
if (origin === "null" || options.parentOrigin !== origin)
|
|
1067
|
-
throw new ProtocolError("ORIGIN", "An exact parent origin is required");
|
|
1068
|
-
const runtime = createParameterRuntime(options);
|
|
1069
|
-
const bridge = new Bridge({
|
|
1070
|
-
peer: () => window.parent,
|
|
1071
|
-
targetOrigin: origin,
|
|
1072
|
-
allowedOrigins: [origin],
|
|
1073
|
-
strictSource: true
|
|
1074
|
-
});
|
|
1075
|
-
const names = BridgeMethods.runtimeParameters;
|
|
1076
|
-
const off = [
|
|
1077
|
-
bridge.on(names.hello, (value) => runtime.hello(value)),
|
|
1078
|
-
bridge.on(names.snapshot, (value) => runtime.snapshot(value)),
|
|
1079
|
-
bridge.on(names.patch, (value) => {
|
|
1080
|
-
try {
|
|
1081
|
-
return runtime.patch(value);
|
|
1082
|
-
} catch (error) {
|
|
1083
|
-
if (error instanceof ProtocolError && error.code === "RESYNC")
|
|
1084
|
-
void bridge.emit(
|
|
1085
|
-
names.resyncRequired,
|
|
1086
|
-
{ ...runtime.status(value), reason: error.message },
|
|
1087
|
-
{ timeout: 1e3 }
|
|
1088
|
-
).catch(() => {
|
|
1089
|
-
});
|
|
1090
|
-
throw error;
|
|
1091
|
-
}
|
|
1092
|
-
}),
|
|
1093
|
-
bridge.on(names.restart, (value) => runtime.restart(value)),
|
|
1094
|
-
bridge.on(names.status, (value) => runtime.status(value)),
|
|
1095
|
-
bridge.on(names.dispose, async (value) => {
|
|
1096
|
-
runtime.status(value);
|
|
1097
|
-
await runtime.dispose();
|
|
1098
|
-
return { disposed: true };
|
|
1099
|
-
}),
|
|
1100
|
-
runtime.subscribe((value) => {
|
|
1101
|
-
void bridge.emit(names.result, value, { timeout: 1e3 }).catch(() => {
|
|
1102
|
-
});
|
|
1103
|
-
}),
|
|
1104
|
-
runtime.onCapabilities((value) => {
|
|
1105
|
-
void bridge.emit(names.capabilities, value, { timeout: 1e3 }).catch(() => {
|
|
1106
|
-
});
|
|
1107
|
-
})
|
|
1108
|
-
];
|
|
1109
|
-
return {
|
|
1110
|
-
runtime,
|
|
1111
|
-
async dispose() {
|
|
1112
|
-
off.forEach((fn) => fn());
|
|
1113
|
-
bridge.destroy();
|
|
1114
|
-
await runtime.dispose();
|
|
1115
|
-
}
|
|
1116
|
-
};
|
|
1117
|
-
}
|
|
1118
|
-
export {
|
|
1119
|
-
connectPreviewRuntime,
|
|
1120
|
-
readWorkspacePreviewContext
|
|
1121
|
-
};
|