@joiner-platform/cli 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +30 -2
- package/bundled-resources/poe-tile-templates/base/CLAUDE.md +72 -0
- package/bundled-resources/poe-tile-templates/base/README.md +7 -0
- package/bundled-resources/poe-tile-templates/base/_bunfig.toml +8 -0
- package/bundled-resources/poe-tile-templates/base/_gitignore +18 -0
- package/bundled-resources/poe-tile-templates/base/client.ts +12 -0
- package/bundled-resources/poe-tile-templates/base/package.json +36 -0
- package/bundled-resources/poe-tile-templates/base/playwright.config.ts +38 -0
- package/bundled-resources/poe-tile-templates/base/scripts/check-source.ts +148 -0
- package/bundled-resources/poe-tile-templates/base/scripts/dev.ts +19 -0
- package/bundled-resources/poe-tile-templates/base/scripts/doctor.sh +29 -0
- package/bundled-resources/poe-tile-templates/base/scripts/visual-check.ts +64 -0
- package/bundled-resources/poe-tile-templates/base/synced-store/backend-config.ts +9 -0
- package/bundled-resources/poe-tile-templates/base/synced-store/client-config.ts +8 -0
- package/bundled-resources/poe-tile-templates/base/synced-store/data/items.ts +16 -0
- package/bundled-resources/poe-tile-templates/base/synced-store/mutators/index.ts +10 -0
- package/bundled-resources/poe-tile-templates/base/synced-store/mutators/remove-todo.ts +5 -0
- package/bundled-resources/poe-tile-templates/base/synced-store/mutators/set-todo.ts +20 -0
- package/bundled-resources/poe-tile-templates/base/synced-store/mutators/types.ts +5 -0
- package/bundled-resources/poe-tile-templates/base/synced-store/mutators.test.ts +138 -0
- package/bundled-resources/poe-tile-templates/base/synced-store/schema.ts +40 -0
- package/bundled-resources/poe-tile-templates/base/tests/e2e.test.playwright.ts +92 -0
- package/bundled-resources/poe-tile-templates/base/tests/mobile-viewport.test.playwright.ts +111 -0
- package/bundled-resources/poe-tile-templates/base/tests/render-check.test.playwright.ts +128 -0
- package/bundled-resources/poe-tile-templates/base/tests/screenshot.test.playwright.ts +86 -0
- package/bundled-resources/poe-tile-templates/base/tests/setup-dom.ts +70 -0
- package/bundled-resources/poe-tile-templates/base/tile/src/backend.ts +3 -0
- package/bundled-resources/poe-tile-templates/base/tile/styles.css +47 -0
- package/bundled-resources/poe-tile-templates/base/tsconfig.json +13 -0
- package/bundled-resources/poe-tile-templates/coverage.config.json +6 -0
- package/bundled-resources/poe-tile-templates/index.ts +27 -0
- package/bundled-resources/poe-tile-templates/package.json +31 -0
- package/bundled-resources/poe-tile-templates/phaserjs/package.partial.json +6 -0
- package/bundled-resources/poe-tile-templates/phaserjs/tile/index.html +14 -0
- package/bundled-resources/poe-tile-templates/phaserjs/tile/src/entry.ts +35 -0
- package/bundled-resources/poe-tile-templates/phaserjs/ui/App.test.happydom.tsx +98 -0
- package/bundled-resources/poe-tile-templates/phaserjs/ui/App.ts +180 -0
- package/bundled-resources/poe-tile-templates/phaserjs/ui/phaser-scene.ts +174 -0
- package/bundled-resources/poe-tile-templates/phaserjs/vite.config.ts +28 -0
- package/bundled-resources/poe-tile-templates/preact/package.partial.json +9 -0
- package/bundled-resources/poe-tile-templates/preact/postcss.config.js +5 -0
- package/bundled-resources/poe-tile-templates/preact/tile/index.html +14 -0
- package/bundled-resources/poe-tile-templates/preact/tile/src/entry.tsx +36 -0
- package/bundled-resources/poe-tile-templates/preact/tile/styles.css +51 -0
- package/bundled-resources/poe-tile-templates/preact/tsconfig.json +15 -0
- package/bundled-resources/poe-tile-templates/preact/ui/App.test.happydom.tsx +69 -0
- package/bundled-resources/poe-tile-templates/preact/ui/App.tsx +116 -0
- package/bundled-resources/poe-tile-templates/preact/vite.config.ts +18 -0
- package/bundled-resources/poe-tile-templates/react/package.partial.json +12 -0
- package/bundled-resources/poe-tile-templates/react/postcss.config.js +5 -0
- package/bundled-resources/poe-tile-templates/react/tile/index.html +14 -0
- package/bundled-resources/poe-tile-templates/react/tile/src/entry.tsx +38 -0
- package/bundled-resources/poe-tile-templates/react/tile/styles.css +51 -0
- package/bundled-resources/poe-tile-templates/react/tsconfig.json +14 -0
- package/bundled-resources/poe-tile-templates/react/ui/App.test.happydom.tsx +71 -0
- package/bundled-resources/poe-tile-templates/react/ui/App.tsx +110 -0
- package/bundled-resources/poe-tile-templates/react/vite.config.ts +21 -0
- package/bundled-resources/poe-tile-templates/scripts/cleanup.ts +10 -0
- package/bundled-resources/poe-tile-templates/scripts/generate.ts +57 -0
- package/bundled-resources/poe-tile-templates/scripts/install-diagnostics.ts +52 -0
- package/bundled-resources/poe-tile-templates/scripts/paths.ts +7 -0
- package/bundled-resources/poe-tile-templates/scripts/sdk-dependency-key.ts +288 -0
- package/bundled-resources/poe-tile-templates/scripts/verify-all-sdks.ts +132 -0
- package/bundled-resources/poe-tile-templates/scripts/verify-local-sdk-command.ts +30 -0
- package/bundled-resources/poe-tile-templates/scripts/verify-local-sdk-tarball.ts +397 -0
- package/bundled-resources/poe-tile-templates/solidjs/_bunfig.toml +14 -0
- package/bundled-resources/poe-tile-templates/solidjs/package.partial.json +13 -0
- package/bundled-resources/poe-tile-templates/solidjs/postcss.config.js +5 -0
- package/bundled-resources/poe-tile-templates/solidjs/tests/solid-plugin.ts +49 -0
- package/bundled-resources/poe-tile-templates/solidjs/tile/index.html +14 -0
- package/bundled-resources/poe-tile-templates/solidjs/tile/src/entry.tsx +36 -0
- package/bundled-resources/poe-tile-templates/solidjs/tile/styles.css +51 -0
- package/bundled-resources/poe-tile-templates/solidjs/tsconfig.json +15 -0
- package/bundled-resources/poe-tile-templates/solidjs/ui/App.test.happydom.tsx +70 -0
- package/bundled-resources/poe-tile-templates/solidjs/ui/App.tsx +129 -0
- package/bundled-resources/poe-tile-templates/solidjs/vite.config.ts +18 -0
- package/bundled-resources/poe-tile-templates/tests/check-source.test.ts +131 -0
- package/bundled-resources/poe-tile-templates/tests/dev-script.test.slow.ts +166 -0
- package/bundled-resources/poe-tile-templates/tests/fixtures/customized-manager.ts +67 -0
- package/bundled-resources/poe-tile-templates/tests/fixtures/extended-mutators.ts.txt +106 -0
- package/bundled-resources/poe-tile-templates/tests/fixtures/multiplayer-verification.test.playwright.ts.txt +103 -0
- package/bundled-resources/poe-tile-templates/tests/fixtures/replace-starter-schema.ts +67 -0
- package/bundled-resources/poe-tile-templates/tests/fixtures/starter-demo/phaserjs.tsx.txt +85 -0
- package/bundled-resources/poe-tile-templates/tests/fixtures/starter-demo/preact.tsx.txt +69 -0
- package/bundled-resources/poe-tile-templates/tests/fixtures/starter-demo/react.tsx.txt +73 -0
- package/bundled-resources/poe-tile-templates/tests/fixtures/starter-demo/seating.ts.txt +54 -0
- package/bundled-resources/poe-tile-templates/tests/fixtures/starter-demo/solidjs.tsx.txt +70 -0
- package/bundled-resources/poe-tile-templates/tests/fixtures/starter-demo/vanilla-js.tsx.txt +85 -0
- package/bundled-resources/poe-tile-templates/tests/generated-templates.test.ts +278 -0
- package/bundled-resources/poe-tile-templates/tests/happy-dom-version.test.ts +27 -0
- package/bundled-resources/poe-tile-templates/tests/install-diagnostics.test.ts +99 -0
- package/bundled-resources/poe-tile-templates/tests/native-gesture-defaults.test.ts +23 -0
- package/bundled-resources/poe-tile-templates/tests/playwright-version.test.ts +84 -0
- package/bundled-resources/poe-tile-templates/tests/render-check-scaffold.test.ts +56 -0
- package/bundled-resources/poe-tile-templates/tests/sdk-dependency-key.test.ts +129 -0
- package/bundled-resources/poe-tile-templates/tests/visual-check.test.ts +90 -0
- package/bundled-resources/poe-tile-templates/vanilla-js/package.partial.json +3 -0
- package/bundled-resources/poe-tile-templates/vanilla-js/tile/index.html +14 -0
- package/bundled-resources/poe-tile-templates/vanilla-js/tile/src/entry.ts +35 -0
- package/bundled-resources/poe-tile-templates/vanilla-js/ui/App.test.happydom.tsx +96 -0
- package/bundled-resources/poe-tile-templates/vanilla-js/ui/App.ts +113 -0
- package/bundled-resources/poe-tile-templates/vanilla-js/vite.config.ts +17 -0
- package/cli.ts +134 -0
- package/index.ts +96 -0
- package/package.json +48 -5
- package/skills/audio-generation/.generated-by-poe-templated-docs +0 -0
- package/skills/audio-generation/SKILL.md +125 -0
- package/skills/finish-prototype/.generated-by-poe-templated-docs +0 -0
- package/skills/finish-prototype/SKILL.md +22 -0
- package/skills/help-me-build/.generated-by-poe-templated-docs +0 -0
- package/skills/help-me-build/SKILL.md +56 -0
- package/skills/image-generation/.generated-by-poe-templated-docs +0 -0
- package/skills/image-generation/SKILL.md +128 -0
- package/skills/one-shot/.generated-by-poe-templated-docs +0 -0
- package/skills/one-shot/SKILL.md +22 -0
- package/skills/platform-prototype/.generated-by-poe-templated-docs +0 -0
- package/skills/platform-prototype/SKILL.md +60 -0
- package/skills/platform-subagent/.generated-by-poe-templated-docs +0 -0
- package/skills/platform-subagent/SKILL.md +16 -0
- package/skills/poe-tiles-cli/.generated-by-poe-templated-docs +0 -0
- package/skills/poe-tiles-cli/SKILL.md +609 -0
- package/skills/poe-tiles-cli/references/device-motion.md +40 -0
- package/skills/poe-tiles-cli/references/player-updates.md +41 -0
- package/skills/prototype/.generated-by-poe-templated-docs +0 -0
- package/skills/prototype/SKILL.md +148 -0
- package/skills/publish/.generated-by-poe-templated-docs +0 -0
- package/skills/publish/SKILL.md +73 -0
- package/skills/synced-store/.generated-by-poe-templated-docs +0 -0
- package/skills/synced-store/SKILL.md +583 -0
- package/skills/synced-store/references/actions.md +85 -0
- package/skills/synced-store/references/api-patterns.md +245 -0
- package/skills/synced-store/references/architecture-scaling-and-performance.md +280 -0
- package/skills/synced-store/references/client-api-reference.md +263 -0
- package/skills/synced-store/references/data-visibility.md +95 -0
- package/skills/synced-store/references/external-stores.md +162 -0
- package/skills/synced-store/references/file-uploads.md +216 -0
- package/skills/synced-store/references/getting-user-info-of-members.md +228 -0
- package/skills/synced-store/references/limitations.md +72 -0
- package/skills/synced-store/references/live-data-limit-hook.md +131 -0
- package/skills/synced-store/references/mutator-rules.md +169 -0
- package/skills/synced-store/references/platform.md +49 -0
- package/skills/synced-store/references/schema-and-bindings.md +85 -0
- package/skills/synced-store/references/schema-libraries.md +57 -0
- package/skills/synced-store/references/schema-migrations.md +119 -0
- package/skills/synced-store/references/searchable-tables.md +27 -0
- package/skills/synced-store/references/server-forking.md +115 -0
- package/skills/synced-store/references/singleton-tables.md +61 -0
- package/skills/synced-store/references/sort-keys.md +253 -0
- package/skills/synced-store/references/ui-patterns.md +95 -0
- package/skills/tile-creator/.generated-by-poe-templated-docs +0 -0
- package/skills/tile-creator/SKILL.md +196 -0
- package/skills/tile-creator/references/assets.md +124 -0
- package/skills/tile-creator/references/backend-api.md +308 -0
- package/skills/tile-creator/references/cli-limitations.md +64 -0
- package/skills/tile-creator/references/cli.md +604 -0
- package/skills/tile-creator/references/client-api.md +2407 -0
- package/skills/tile-creator/references/composing-apps.md +166 -0
- package/skills/tile-creator/references/e2e-tests.md +55 -0
- package/skills/tile-creator/references/game-ux-best-practices.md +57 -0
- package/skills/tile-creator/references/migrating-pre-rename-tiles.md +79 -0
- package/skills/tile-creator/references/multiplayer-api-recipe.md +205 -0
- package/skills/tile-creator/references/native-results.md +100 -0
- package/skills/tile-creator/references/platform-integration.md +201 -0
- package/skills/tile-creator/references/power-report.md +199 -0
- package/skills/tile-creator/references/publish-rollout.md +166 -0
- package/skills/tile-creator/references/publishing.md +33 -0
- package/skills/tile-creator/references/push-notification-guidelines.md +58 -0
- package/skills/tile-creator/references/render-check.md +266 -0
- package/skills/tile-creator/references/running-the-client-api-on-a-server-owned-by-the-user.md +95 -0
- package/skills/tile-creator/references/safe-area-insets.md +79 -0
- package/skills/tile-creator/references/sandbox-limitations.md +32 -0
- package/skills/tile-creator/references/scaffolded-tile-folder-structure.md +48 -0
- package/skills/tile-creator/references/scaffolding-a-new-app.md +202 -0
- package/skills/tile-creator/references/simulations.md +125 -0
- package/skills/tile-creator/references/synced-store-client-reference.md +92 -0
- package/skills/tile-creator/references/troubleshooting.md +22 -0
- package/skills/tile-creator/references/turn-based-mutator.md +43 -0
- package/skills/tile-creator/references/user-erasure.md +14 -0
- package/skills/tile-creator/references/vite-plugin.md +166 -0
- package/skills/tile-creator/references/workspace-retention.md +72 -0
- package/src/admin-conversions-client.ts +28 -0
- package/src/admin-reviews-client.ts +36 -0
- package/src/api.generated.ts +1527 -0
- package/src/auth-token.ts +198 -0
- package/src/bounded-read.ts +35 -0
- package/src/bun-version.ts +33 -0
- package/src/checkout-base.ts +207 -0
- package/src/cli-bun-version.ts +16 -0
- package/src/cli-env.ts +28 -0
- package/src/cli-name.ts +23 -0
- package/src/client.ts +2474 -0
- package/src/collect-files.ts +226 -0
- package/src/commands/accounts.ts +55 -0
- package/src/commands/admin-abandon-conversion.ts +60 -0
- package/src/commands/admin-reviews.ts +66 -0
- package/src/commands/admin.ts +219 -0
- package/src/commands/auth.ts +89 -0
- package/src/commands/checkout-prototype.ts +67 -0
- package/src/commands/creator-source-capability.ts +11 -0
- package/src/commands/doctor-bun.ts +145 -0
- package/src/commands/doctor-command.ts +64 -0
- package/src/commands/doctor-package-json.ts +47 -0
- package/src/commands/doctor-sdk-pin.ts +156 -0
- package/src/commands/doctor-store-keys-lexer.ts +213 -0
- package/src/commands/doctor-store-keys-scan.ts +262 -0
- package/src/commands/doctor-store-keys.ts +196 -0
- package/src/commands/doctor.ts +371 -0
- package/src/commands/init/blank-scaffold-templates.ts +397 -0
- package/src/commands/init/index.ts +170 -0
- package/src/commands/init/internal-toolchain.ts +49 -0
- package/src/commands/init/manager-test-template.ts +107 -0
- package/src/commands/init/multiplayer-test-template.ts +217 -0
- package/src/commands/init/name-input.tsx +167 -0
- package/src/commands/init/no-store-scaffold-templates.ts +281 -0
- package/src/commands/init/no-store-scaffold.ts +134 -0
- package/src/commands/init/package-json-scripts.ts +72 -0
- package/src/commands/init/scaffold.ts +960 -0
- package/src/commands/init/sdk-tarball-url.generated.ts +4 -0
- package/src/commands/init/sdk-tarball-url.ts +31 -0
- package/src/commands/init/template-picker.tsx +147 -0
- package/src/commands/inspect-child-entry.ts +107 -0
- package/src/commands/inspect-contract.ts +87 -0
- package/src/commands/inspect-freshness.ts +217 -0
- package/src/commands/inspect-lock.ts +201 -0
- package/src/commands/inspect-options.ts +360 -0
- package/src/commands/inspect-orchestrate.ts +375 -0
- package/src/commands/inspect-process.ts +172 -0
- package/src/commands/inspect-ready.ts +65 -0
- package/src/commands/inspect-report.ts +235 -0
- package/src/commands/inspect-run-state.ts +296 -0
- package/src/commands/inspect-run.ts +157 -0
- package/src/commands/inspect-watchdog.ts +74 -0
- package/src/commands/install-joiner.ts +208 -0
- package/src/commands/login.ts +308 -0
- package/src/commands/models.ts +40 -0
- package/src/commands/parse-options.ts +36 -0
- package/src/commands/remix-package-json.ts +64 -0
- package/src/commands/remix.ts +379 -0
- package/src/commands/sdk-url.ts +141 -0
- package/src/commands/simulations.ts +133 -0
- package/src/commands/skills.ts +108 -0
- package/src/commands/store-files.ts +92 -0
- package/src/commands/stores.ts +703 -0
- package/src/commands/tiles-channel-commands.ts +115 -0
- package/src/commands/tiles-checkout.ts +351 -0
- package/src/commands/tiles-gallery-command.ts +95 -0
- package/src/commands/tiles-get-helpers.ts +27 -0
- package/src/commands/tiles-inspect.ts +276 -0
- package/src/commands/tiles-power-command.ts +308 -0
- package/src/commands/tiles-power-format.ts +396 -0
- package/src/commands/tiles-power-versions.ts +299 -0
- package/src/commands/tiles-publish-helpers.ts +145 -0
- package/src/commands/tiles-upload-command.ts +277 -0
- package/src/commands/tiles-version-commands.ts +201 -0
- package/src/commands/tiles-visibility-command.ts +103 -0
- package/src/commands/tiles.ts +257 -0
- package/src/commands/upgrade.ts +307 -0
- package/src/commit-in-progress.ts +42 -0
- package/src/creator-source-context.ts +97 -0
- package/src/creator-source-publish.ts +52 -0
- package/src/deferred-assets.ts +125 -0
- package/src/distribution.ts +28 -0
- package/src/errors.ts +61 -0
- package/src/install-command.ts +43 -0
- package/src/output.ts +62 -0
- package/src/poe-tile-config-files.ts +100 -0
- package/src/poe-tile-config-players.ts +168 -0
- package/src/poe-tile-config-remix.ts +166 -0
- package/src/poe-tile-config.ts +831 -0
- package/src/power-report-client.ts +55 -0
- package/src/prototype-startup.ts +21 -0
- package/src/publish-change-summary.ts +55 -0
- package/src/publish-overrides-validation.ts +49 -0
- package/src/publish-pack.ts +167 -0
- package/src/publish-phases.ts +57 -0
- package/src/publish-retry.ts +51 -0
- package/src/publish-tile-from-config.ts +434 -0
- package/src/recorder-stream.ts +169 -0
- package/src/remix-provenance.ts +156 -0
- package/src/resolve-client-credential.ts +71 -0
- package/src/resolve-media-uploads.ts +147 -0
- package/src/sdk-dependency.ts +54 -0
- package/src/sdk-skills.ts +85 -0
- package/src/should-skip-client-setup.ts +20 -0
- package/src/simulation-snapshot.ts +123 -0
- package/src/simulation-types.ts +74 -0
- package/src/simulations-client.ts +112 -0
- package/src/source-bundle.ts +466 -0
- package/src/staged-publish-cleanup.ts +44 -0
- package/src/staged-publish-deferred.ts +160 -0
- package/src/staged-publish.ts +401 -0
- package/src/store-file-upload.ts +268 -0
- package/src/store-request.ts +168 -0
- package/src/tar-canonical.ts +41 -0
- package/src/tar-extensions.ts +159 -0
- package/src/tar-extract.ts +193 -0
- package/src/tar-parse.ts +224 -0
- package/src/tar.ts +231 -0
- package/src/template-check-scripts.ts +18 -0
- package/src/tile-gallery-client.ts +82 -0
- package/src/types.ts +258 -0
- package/src/upload-concurrency.ts +54 -0
- package/src/whole-tile.ts +52 -0
|
@@ -0,0 +1,434 @@
|
|
|
1
|
+
// owner: jyoung-q
|
|
2
|
+
/**
|
|
3
|
+
* Programmatic entry point for the `tiles upload` / `tiles deploy` commands.
|
|
4
|
+
* Resolves a publish-options bag from `.poe-tile.json` + explicit overrides
|
|
5
|
+
* (mirroring the precedence the CLI flag-handler uses) and invokes
|
|
6
|
+
* `SlopPoeClient.publishTile`.
|
|
7
|
+
*
|
|
8
|
+
* Two call sites share this function:
|
|
9
|
+
*
|
|
10
|
+
* - `src/commands/tiles-upload-command.ts` — the CLI `tiles upload` (alias
|
|
11
|
+
* `publish`) and `tiles deploy` action handlers are thin wrappers that map
|
|
12
|
+
* commander flags to overrides and print the result.
|
|
13
|
+
* - `scripts/dev-watch-tiles.ts` (and other in-monorepo seeders) — call
|
|
14
|
+
* directly so dev publishing exercises the same resolution rules,
|
|
15
|
+
* validation, and form-data shape production does.
|
|
16
|
+
*
|
|
17
|
+
* The function throws `CliError` on validation failures (invalid handle,
|
|
18
|
+
* missing config, unreadable picture, oversized description, etc.) so
|
|
19
|
+
* both call sites can rely on the same error surface; callers should
|
|
20
|
+
* surface the message and exit non-zero.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
import { statSync } from "node:fs";
|
|
24
|
+
import { dirname, extname, resolve } from "node:path";
|
|
25
|
+
import { readBoundedText } from "./bounded-read.js";
|
|
26
|
+
import type { SlopPoeClient } from "./client.js";
|
|
27
|
+
import {
|
|
28
|
+
type CreatorSourcePublishOverrides,
|
|
29
|
+
resolveEditSourcePublishIntent,
|
|
30
|
+
} from "./creator-source-publish.js";
|
|
31
|
+
import { CliError } from "./errors.js";
|
|
32
|
+
import {
|
|
33
|
+
DISPLAY_NAME_MAX_LENGTH,
|
|
34
|
+
describeInvalidTileHandle,
|
|
35
|
+
LONG_DESCRIPTION_MAX_BYTES,
|
|
36
|
+
type PoeTileConfigVideo,
|
|
37
|
+
readPoeTileConfig,
|
|
38
|
+
SHORT_DESCRIPTION_MAX_LENGTH,
|
|
39
|
+
type TileInstancing,
|
|
40
|
+
} from "./poe-tile-config.js";
|
|
41
|
+
import type { TilePlayerCount } from "./poe-tile-config-players.js";
|
|
42
|
+
import type { PoeTileConfigRemixOf } from "./poe-tile-config-remix.js";
|
|
43
|
+
import {
|
|
44
|
+
normalizeChangeSummary,
|
|
45
|
+
normalizeVersionName,
|
|
46
|
+
normalizeVersionNotes,
|
|
47
|
+
} from "./publish-change-summary.js";
|
|
48
|
+
import {
|
|
49
|
+
type PublishBoundaryOverrides,
|
|
50
|
+
validatePublishBoundaryOverrides,
|
|
51
|
+
} from "./publish-overrides-validation.js";
|
|
52
|
+
import type { PublishPhaseObserver } from "./publish-phases.js";
|
|
53
|
+
import {
|
|
54
|
+
IMAGE_UPLOAD_MAX_BYTES,
|
|
55
|
+
inferImageMimeType,
|
|
56
|
+
readMediaFile,
|
|
57
|
+
resolveScreenshots,
|
|
58
|
+
resolveVideo,
|
|
59
|
+
} from "./resolve-media-uploads.js";
|
|
60
|
+
import type { PublishResult, PublishWholeTileBundle } from "./types.js";
|
|
61
|
+
import { resolveWholeTileUpload, type SourceUpload } from "./whole-tile.js";
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Override values that mirror the CLI flags one-for-one. Every field is
|
|
65
|
+
* optional. Most omitted values are taken from `.poe-tile.json` in `cwd`;
|
|
66
|
+
* `publishAsPoe` is intentionally override-only so @poe publishing cannot
|
|
67
|
+
* be pinned in project config. An explicit `""` for a string field is
|
|
68
|
+
* forwarded as-is (the server treats empty strings as "clear this column"
|
|
69
|
+
* for profile picture and descriptions; mirrors the CLI's empty-string
|
|
70
|
+
* override pattern).
|
|
71
|
+
*/
|
|
72
|
+
export interface PublishAppOverrides
|
|
73
|
+
extends CreatorSourcePublishOverrides,
|
|
74
|
+
PublishBoundaryOverrides {
|
|
75
|
+
handle?: string;
|
|
76
|
+
/** Runtime bundle directory. Relative paths resolve to `cwd`. */
|
|
77
|
+
dir?: string;
|
|
78
|
+
publishAsPoe?: boolean;
|
|
79
|
+
publishAsTileAuthor?: boolean;
|
|
80
|
+
/** Release automation: let the server pick @poe vs the configured author. */
|
|
81
|
+
publishAsReleaseIdentity?: boolean;
|
|
82
|
+
/** Promote `live` to this upload in-band (`tiles deploy`, or the deprecated `--promote`). */
|
|
83
|
+
promote?: boolean;
|
|
84
|
+
/** Local file path OR `https://…` URL OR `""` to clear. */
|
|
85
|
+
profilePicture?: string;
|
|
86
|
+
/** Tagline (≤140 chars) OR `""` to clear. */
|
|
87
|
+
shortDescription?: string;
|
|
88
|
+
/** Path to a markdown file (≤16 KB) OR `""` to clear. */
|
|
89
|
+
longDescription?: string;
|
|
90
|
+
/** Human-friendly display name (≤80 chars) OR `""` to clear. */
|
|
91
|
+
displayName?: string;
|
|
92
|
+
/** Concise user-facing summary for this specific publish (≤500 chars). */
|
|
93
|
+
changeSummary?: string;
|
|
94
|
+
/** Version label (≤60 chars) shown instead of the default "Version N". */
|
|
95
|
+
versionName?: string;
|
|
96
|
+
/** What-changed notes (≤2000 chars); defaults to changeSummary server-side. */
|
|
97
|
+
versionNotes?: string;
|
|
98
|
+
/**
|
|
99
|
+
* Which bundle holds the whole tile. In-process callers only (Creator's
|
|
100
|
+
* bridge); deliberately not a CLI flag.
|
|
101
|
+
*/
|
|
102
|
+
wholeTileBundle?: PublishWholeTileBundle;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** The description's cap, checked against the file's size before it is read. */
|
|
106
|
+
function readLongDescription(absPath: string): string {
|
|
107
|
+
return readBoundedText(
|
|
108
|
+
absPath,
|
|
109
|
+
LONG_DESCRIPTION_MAX_BYTES,
|
|
110
|
+
(size) =>
|
|
111
|
+
new CliError(
|
|
112
|
+
`Long description is ${size} bytes; the maximum is ${LONG_DESCRIPTION_MAX_BYTES}.`,
|
|
113
|
+
),
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export interface PublishAppFromConfigParams {
|
|
118
|
+
client: SlopPoeClient;
|
|
119
|
+
/** Directory containing `.poe-tile.json` (and, by default, `dist/`). */
|
|
120
|
+
cwd: string;
|
|
121
|
+
overrides?: PublishAppOverrides;
|
|
122
|
+
/** Client-side phase timings, for a caller that measures. See `publish-phases.ts`. */
|
|
123
|
+
observe?: PublishPhaseObserver;
|
|
124
|
+
beforeUpload?: (sourceUpload: SourceUpload) => void;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Resolve `.poe-tile.json` + overrides into a fully-formed publish call
|
|
129
|
+
* and execute it.
|
|
130
|
+
*
|
|
131
|
+
* Resolution precedence: explicit override > config value > built-in
|
|
132
|
+
* default (e.g. `dist` for runtime bundle dir).
|
|
133
|
+
*/
|
|
134
|
+
|
|
135
|
+
// biome-ignore lint/complexity/noExcessiveCognitiveComplexity: Existing function exceeds the cognitive-complexity limit; keep the rule enabled for new code.
|
|
136
|
+
export async function publishTileFromConfig(
|
|
137
|
+
params: PublishAppFromConfigParams,
|
|
138
|
+
): Promise<PublishResult> {
|
|
139
|
+
const { client, cwd } = params;
|
|
140
|
+
const opts = params.overrides ?? {};
|
|
141
|
+
const editSourcePublishIntent = resolveEditSourcePublishIntent(opts);
|
|
142
|
+
validatePublishBoundaryOverrides(opts);
|
|
143
|
+
|
|
144
|
+
// 2. Read .poe-tile.json. Missing → proceed with overrides only;
|
|
145
|
+
// malformed → readPoeTileConfig throws a helpful message we rewrap
|
|
146
|
+
// as CliError so callers treat it as a clean error.
|
|
147
|
+
let configDir: string | undefined;
|
|
148
|
+
let configHandle: string | undefined;
|
|
149
|
+
let configRuntimeBundleDir: string | undefined;
|
|
150
|
+
let configSourceBundleDir: string | undefined;
|
|
151
|
+
let configSourceBundleVisibility: "owner_only" | "public" | undefined;
|
|
152
|
+
let configSourceBundleIgnore: string | undefined;
|
|
153
|
+
let configProfilePicture: string | undefined;
|
|
154
|
+
let configShortDescription: string | undefined;
|
|
155
|
+
let configLongDescriptionPath: string | undefined;
|
|
156
|
+
let configDisplayName: string | undefined;
|
|
157
|
+
let configScreenshots: string[] | undefined;
|
|
158
|
+
let configPlayers: TilePlayerCount | null | undefined;
|
|
159
|
+
let configRemixOf: PoeTileConfigRemixOf | null | undefined;
|
|
160
|
+
let configVideo: PoeTileConfigVideo | null | undefined;
|
|
161
|
+
let configInstancing: TileInstancing | undefined;
|
|
162
|
+
try {
|
|
163
|
+
const result = readPoeTileConfig(cwd);
|
|
164
|
+
if (result.found) {
|
|
165
|
+
configDir = dirname(result.path);
|
|
166
|
+
configHandle = result.config.handle;
|
|
167
|
+
if (result.config.runtimeBundle) {
|
|
168
|
+
configRuntimeBundleDir = resolve(
|
|
169
|
+
configDir,
|
|
170
|
+
result.config.runtimeBundle.dir,
|
|
171
|
+
);
|
|
172
|
+
}
|
|
173
|
+
if (result.config.sourceBundle) {
|
|
174
|
+
configSourceBundleDir = resolve(
|
|
175
|
+
configDir,
|
|
176
|
+
result.config.sourceBundle.dir,
|
|
177
|
+
);
|
|
178
|
+
configSourceBundleVisibility = result.config.sourceBundle.visibility;
|
|
179
|
+
if (result.config.sourceBundle.ignoreFile) {
|
|
180
|
+
configSourceBundleIgnore = resolve(
|
|
181
|
+
configDir,
|
|
182
|
+
result.config.sourceBundle.ignoreFile,
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
configProfilePicture = result.config.profilePicture;
|
|
187
|
+
configShortDescription = result.config.shortDescription;
|
|
188
|
+
configDisplayName = result.config.displayName;
|
|
189
|
+
configScreenshots = result.config.screenshots;
|
|
190
|
+
configPlayers = result.config.players;
|
|
191
|
+
configRemixOf = result.config.remixOf;
|
|
192
|
+
configVideo = result.config.video;
|
|
193
|
+
configInstancing = result.config.instancing;
|
|
194
|
+
if (result.config.longDescription !== undefined) {
|
|
195
|
+
configLongDescriptionPath = resolve(
|
|
196
|
+
configDir,
|
|
197
|
+
result.config.longDescription,
|
|
198
|
+
);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
} catch (err) {
|
|
202
|
+
throw new CliError(err instanceof Error ? err.message : String(err));
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
// 3. Resolve each value with explicit-override-wins precedence.
|
|
206
|
+
const handle = opts.handle ?? configHandle;
|
|
207
|
+
if (!handle) {
|
|
208
|
+
throw new CliError(
|
|
209
|
+
"--handle is required when no .poe-tile.json with a handle is in the current directory.",
|
|
210
|
+
);
|
|
211
|
+
}
|
|
212
|
+
const handleProblem = describeInvalidTileHandle(handle);
|
|
213
|
+
if (handleProblem !== undefined) {
|
|
214
|
+
throw new CliError(`Invalid handle "${handle}": ${handleProblem}.`);
|
|
215
|
+
}
|
|
216
|
+
const publishAsPoe = opts.publishAsPoe ?? false;
|
|
217
|
+
const publishAsTileAuthor = opts.publishAsTileAuthor ?? false;
|
|
218
|
+
const publishAsReleaseIdentity = opts.publishAsReleaseIdentity ?? false;
|
|
219
|
+
|
|
220
|
+
let resolvedSourceBundle:
|
|
221
|
+
| {
|
|
222
|
+
dir: string;
|
|
223
|
+
visibility: "owner_only" | "public";
|
|
224
|
+
ignoreFile?: string;
|
|
225
|
+
}
|
|
226
|
+
| undefined;
|
|
227
|
+
if (opts.sourceBundle) {
|
|
228
|
+
resolvedSourceBundle = {
|
|
229
|
+
dir: resolve(cwd, opts.sourceBundle),
|
|
230
|
+
visibility: opts.sourceBundleVisibility as "owner_only" | "public",
|
|
231
|
+
ignoreFile: opts.sourceBundleIgnore
|
|
232
|
+
? resolve(cwd, opts.sourceBundleIgnore)
|
|
233
|
+
: undefined,
|
|
234
|
+
};
|
|
235
|
+
} else if (configSourceBundleDir && configSourceBundleVisibility) {
|
|
236
|
+
resolvedSourceBundle = {
|
|
237
|
+
dir: configSourceBundleDir,
|
|
238
|
+
visibility: configSourceBundleVisibility,
|
|
239
|
+
ignoreFile: configSourceBundleIgnore,
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
// Profile picture: undefined → leave alone; "" → clear; value → set.
|
|
244
|
+
const profilePictureValue: string | undefined =
|
|
245
|
+
opts.profilePicture !== undefined
|
|
246
|
+
? opts.profilePicture
|
|
247
|
+
: configProfilePicture;
|
|
248
|
+
let profilePictureBytes: Uint8Array | undefined;
|
|
249
|
+
let profilePictureMimeType: string | undefined;
|
|
250
|
+
let profilePictureUrl: string | undefined;
|
|
251
|
+
let profilePictureClear = false;
|
|
252
|
+
if (profilePictureValue === "") {
|
|
253
|
+
profilePictureClear = true;
|
|
254
|
+
} else if (profilePictureValue !== undefined) {
|
|
255
|
+
if (profilePictureValue.startsWith("https://")) {
|
|
256
|
+
profilePictureUrl = profilePictureValue;
|
|
257
|
+
} else {
|
|
258
|
+
// Local path. Explicit override resolves relative to cwd; the
|
|
259
|
+
// config value resolves relative to the config file's directory.
|
|
260
|
+
const absPath =
|
|
261
|
+
opts.profilePicture !== undefined
|
|
262
|
+
? resolve(cwd, profilePictureValue)
|
|
263
|
+
: resolve(configDir ?? cwd, profilePictureValue);
|
|
264
|
+
if (!statSync(absPath, { throwIfNoEntry: false })?.isFile()) {
|
|
265
|
+
throw new CliError(`Profile picture file not found: ${absPath}`);
|
|
266
|
+
}
|
|
267
|
+
profilePictureMimeType = inferImageMimeType(absPath);
|
|
268
|
+
if (!profilePictureMimeType) {
|
|
269
|
+
throw new CliError(
|
|
270
|
+
`Profile picture must be a .png, .jpg, .jpeg, or .webp file (got ${extname(absPath)}).`,
|
|
271
|
+
);
|
|
272
|
+
}
|
|
273
|
+
profilePictureBytes = readMediaFile(
|
|
274
|
+
absPath,
|
|
275
|
+
IMAGE_UPLOAD_MAX_BYTES,
|
|
276
|
+
"Profile picture",
|
|
277
|
+
);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
const shortDescriptionValue: string | undefined =
|
|
282
|
+
opts.shortDescription !== undefined
|
|
283
|
+
? opts.shortDescription
|
|
284
|
+
: configShortDescription;
|
|
285
|
+
if (
|
|
286
|
+
shortDescriptionValue !== undefined &&
|
|
287
|
+
shortDescriptionValue !== "" &&
|
|
288
|
+
shortDescriptionValue.length > SHORT_DESCRIPTION_MAX_LENGTH
|
|
289
|
+
) {
|
|
290
|
+
throw new CliError(
|
|
291
|
+
`--short-description is ${shortDescriptionValue.length} characters; the maximum is ${SHORT_DESCRIPTION_MAX_LENGTH}.`,
|
|
292
|
+
);
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
const displayNameValue: string | undefined =
|
|
296
|
+
opts.displayName !== undefined ? opts.displayName : configDisplayName;
|
|
297
|
+
if (
|
|
298
|
+
displayNameValue !== undefined &&
|
|
299
|
+
displayNameValue !== "" &&
|
|
300
|
+
displayNameValue.length > DISPLAY_NAME_MAX_LENGTH
|
|
301
|
+
) {
|
|
302
|
+
throw new CliError(
|
|
303
|
+
`--display-name is ${displayNameValue.length} characters; the maximum is ${DISPLAY_NAME_MAX_LENGTH}.`,
|
|
304
|
+
);
|
|
305
|
+
}
|
|
306
|
+
const changeSummary = normalizeChangeSummary(opts.changeSummary);
|
|
307
|
+
const versionName = normalizeVersionName(opts.versionName);
|
|
308
|
+
const versionNotes = normalizeVersionNotes(opts.versionNotes);
|
|
309
|
+
|
|
310
|
+
let longDescriptionValue: string | undefined;
|
|
311
|
+
let longDescriptionClear = false;
|
|
312
|
+
if (opts.longDescription !== undefined) {
|
|
313
|
+
if (opts.longDescription === "") {
|
|
314
|
+
longDescriptionClear = true;
|
|
315
|
+
} else {
|
|
316
|
+
const absPath = resolve(cwd, opts.longDescription);
|
|
317
|
+
if (!statSync(absPath, { throwIfNoEntry: false })?.isFile()) {
|
|
318
|
+
throw new CliError(`Long description file not found: ${absPath}`);
|
|
319
|
+
}
|
|
320
|
+
longDescriptionValue = readLongDescription(absPath);
|
|
321
|
+
}
|
|
322
|
+
} else if (configLongDescriptionPath !== undefined) {
|
|
323
|
+
if (
|
|
324
|
+
!statSync(configLongDescriptionPath, { throwIfNoEntry: false })?.isFile()
|
|
325
|
+
) {
|
|
326
|
+
throw new CliError(
|
|
327
|
+
`Long description file not found: ${configLongDescriptionPath} (from .poe-tile.json)`,
|
|
328
|
+
);
|
|
329
|
+
}
|
|
330
|
+
longDescriptionValue = readLongDescription(configLongDescriptionPath);
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
// Screenshots come from `.poe-tile.json` only (no CLI flag). Each entry is
|
|
334
|
+
// resolved like the profile picture: an `https://` URL is forwarded as-is;
|
|
335
|
+
// a local path (relative to the config file's directory) is read + typed.
|
|
336
|
+
const screenshots = configScreenshots
|
|
337
|
+
? resolveScreenshots(configScreenshots, configDir ?? cwd)
|
|
338
|
+
: undefined;
|
|
339
|
+
|
|
340
|
+
// Players is config-only (no CLI flag). `undefined` → preserve on republish;
|
|
341
|
+
// `null` → the explicit clear sentinel; an object → set the value. The
|
|
342
|
+
// config validator already canonicalized + capped it.
|
|
343
|
+
const players: { value: TilePlayerCount } | { clear: true } | undefined =
|
|
344
|
+
configPlayers === undefined
|
|
345
|
+
? undefined
|
|
346
|
+
: configPlayers === null
|
|
347
|
+
? { clear: true }
|
|
348
|
+
: { value: configPlayers };
|
|
349
|
+
|
|
350
|
+
// Remix provenance is config-only (no CLI flag) — `poe-tiles remix` writes
|
|
351
|
+
// it into `.poe-tile.json`. Same tri-state: `undefined` → preserve on
|
|
352
|
+
// republish; `null` → the explicit clear sentinel; an object → claim. The
|
|
353
|
+
// config validator checked the shape, which is all the server checks too.
|
|
354
|
+
const remixOf: { value: PoeTileConfigRemixOf } | { clear: true } | undefined =
|
|
355
|
+
configRemixOf === undefined
|
|
356
|
+
? undefined
|
|
357
|
+
: configRemixOf === null
|
|
358
|
+
? { clear: true }
|
|
359
|
+
: { value: configRemixOf };
|
|
360
|
+
|
|
361
|
+
// Video is config-only (no CLI flag), same tri-state. `resolveVideo` reads
|
|
362
|
+
// the local mp4 + poster into bytes; `null` → clear.
|
|
363
|
+
const resolvedVideo =
|
|
364
|
+
configVideo === undefined
|
|
365
|
+
? undefined
|
|
366
|
+
: resolveVideo(configVideo, configDir ?? cwd);
|
|
367
|
+
const video:
|
|
368
|
+
| { value: NonNullable<typeof resolvedVideo> }
|
|
369
|
+
| { clear: true }
|
|
370
|
+
| undefined =
|
|
371
|
+
resolvedVideo === undefined
|
|
372
|
+
? undefined
|
|
373
|
+
: resolvedVideo === null
|
|
374
|
+
? { clear: true }
|
|
375
|
+
: { value: resolvedVideo };
|
|
376
|
+
|
|
377
|
+
// Runtime bundle dir: override > config > `dist`. The default matches
|
|
378
|
+
// what the overwhelming majority of scaffolded apps use; the few that
|
|
379
|
+
// build elsewhere set runtimeBundle.dir in their config.
|
|
380
|
+
const dir = opts.dir
|
|
381
|
+
? resolve(cwd, opts.dir)
|
|
382
|
+
: (configRuntimeBundleDir ?? resolve(cwd, "dist"));
|
|
383
|
+
|
|
384
|
+
const wholeTile = resolveWholeTileUpload({
|
|
385
|
+
explicit: opts.wholeTileBundle,
|
|
386
|
+
dir,
|
|
387
|
+
configDir,
|
|
388
|
+
markerDir: configDir ?? cwd,
|
|
389
|
+
sourceBundleVisibility: resolvedSourceBundle?.visibility,
|
|
390
|
+
});
|
|
391
|
+
const { sourceUpload } = wholeTile;
|
|
392
|
+
params.beforeUpload?.(sourceUpload);
|
|
393
|
+
const result = await client.publishTile({
|
|
394
|
+
handle,
|
|
395
|
+
dir,
|
|
396
|
+
...wholeTile.publish,
|
|
397
|
+
editSourcePublishIntent,
|
|
398
|
+
publishAsPoe,
|
|
399
|
+
publishAsTileAuthor,
|
|
400
|
+
publishAsReleaseIdentity,
|
|
401
|
+
promote: opts.promote ?? false,
|
|
402
|
+
changeSummary,
|
|
403
|
+
versionName,
|
|
404
|
+
versionNotes,
|
|
405
|
+
sourceBundle: resolvedSourceBundle,
|
|
406
|
+
screenshots,
|
|
407
|
+
players,
|
|
408
|
+
remixOf,
|
|
409
|
+
// Instancing is config-only (no CLI flag). Two-state: `undefined` →
|
|
410
|
+
// preserve on republish; a mode literal → set (`per-launch` resets).
|
|
411
|
+
instancing: configInstancing,
|
|
412
|
+
video,
|
|
413
|
+
profilePicture: profilePictureClear
|
|
414
|
+
? { clear: true }
|
|
415
|
+
: profilePictureBytes && profilePictureMimeType
|
|
416
|
+
? { bytes: profilePictureBytes, mimeType: profilePictureMimeType }
|
|
417
|
+
: profilePictureUrl
|
|
418
|
+
? { url: profilePictureUrl }
|
|
419
|
+
: undefined,
|
|
420
|
+
shortDescription:
|
|
421
|
+
shortDescriptionValue !== undefined
|
|
422
|
+
? { value: shortDescriptionValue }
|
|
423
|
+
: undefined,
|
|
424
|
+
longDescription: longDescriptionClear
|
|
425
|
+
? { clear: true }
|
|
426
|
+
: longDescriptionValue !== undefined
|
|
427
|
+
? { value: longDescriptionValue }
|
|
428
|
+
: undefined,
|
|
429
|
+
displayName:
|
|
430
|
+
displayNameValue !== undefined ? { value: displayNameValue } : undefined,
|
|
431
|
+
observe: params.observe,
|
|
432
|
+
});
|
|
433
|
+
return result.success ? { ...result, sourceUpload } : result;
|
|
434
|
+
}
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
// owner: jyoung-q
|
|
2
|
+
/**
|
|
3
|
+
* Streams span messages from an admin recorder WebSocket (see
|
|
4
|
+
* `SlopPoeClient.openAdminRecorderSocket`) to the console until the process
|
|
5
|
+
* receives SIGINT or the server closes the connection. Sends a periodic
|
|
6
|
+
* keepalive ping so an idle connection (no room activity) doesn't get
|
|
7
|
+
* dropped — an idle admin recorder connection was observed closing with
|
|
8
|
+
* code 1006 after a few minutes with no traffic in either direction.
|
|
9
|
+
*
|
|
10
|
+
* Span formatting is INLINED (not imported from `@ai-app/recorder`, whose
|
|
11
|
+
* `formatSpanTree` this mirrors) so the published CLI tarball never depends
|
|
12
|
+
* on a workspace-only package that isn't installable outside the monorepo —
|
|
13
|
+
* same rationale as `tar.ts` and `poe-tile-config-players.ts` in this
|
|
14
|
+
* directory.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import type { CliWebSocket } from "./client.js";
|
|
18
|
+
|
|
19
|
+
interface RecorderSpan {
|
|
20
|
+
id: string;
|
|
21
|
+
parentId: string | null;
|
|
22
|
+
name: string;
|
|
23
|
+
startTime: number;
|
|
24
|
+
endTime?: number;
|
|
25
|
+
status: "ok" | "error";
|
|
26
|
+
attributes: Record<string, unknown>;
|
|
27
|
+
children: RecorderSpan[];
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
interface RecorderSpanMessage {
|
|
31
|
+
type: "span";
|
|
32
|
+
span: RecorderSpan;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function isRecorderSpanMessage(value: unknown): value is RecorderSpanMessage {
|
|
36
|
+
return (
|
|
37
|
+
typeof value === "object" &&
|
|
38
|
+
value !== null &&
|
|
39
|
+
(value as { type?: unknown }).type === "span" &&
|
|
40
|
+
"span" in value
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function formatDuration(span: RecorderSpan): string {
|
|
45
|
+
if (span.endTime === undefined) return "pending";
|
|
46
|
+
return `${span.endTime - span.startTime}ms`;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** Mirrors `formatSpanTree` in `@ai-app/recorder`'s `formatting.ts`. */
|
|
50
|
+
function formatSpanTree(span: RecorderSpan, indent = 0): string[] {
|
|
51
|
+
const lines: string[] = [];
|
|
52
|
+
const prefix = " ".repeat(indent);
|
|
53
|
+
const duration = formatDuration(span);
|
|
54
|
+
const status = span.status === "error" ? " [ERROR]" : "";
|
|
55
|
+
|
|
56
|
+
const attrs = Object.entries(span.attributes)
|
|
57
|
+
.filter(([, v]) => v !== undefined && v !== null)
|
|
58
|
+
.map(([k, v]) => `${k}=${JSON.stringify(v)}`)
|
|
59
|
+
.join(", ");
|
|
60
|
+
|
|
61
|
+
lines.push(`${prefix}${span.name} (${duration})${status}`);
|
|
62
|
+
if (attrs) {
|
|
63
|
+
lines.push(`${prefix} └─ ${attrs}`);
|
|
64
|
+
}
|
|
65
|
+
for (const child of span.children) {
|
|
66
|
+
lines.push(...formatSpanTree(child, indent + 1));
|
|
67
|
+
}
|
|
68
|
+
return lines;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function parseRecorderSpanMessage(data: unknown): RecorderSpan | undefined {
|
|
72
|
+
let parsed: unknown;
|
|
73
|
+
try {
|
|
74
|
+
parsed = JSON.parse(String(data));
|
|
75
|
+
} catch {
|
|
76
|
+
return undefined;
|
|
77
|
+
}
|
|
78
|
+
return isRecorderSpanMessage(parsed) ? parsed.span : undefined;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function printRecorderSpan(span: RecorderSpan, json: boolean): void {
|
|
82
|
+
if (json) {
|
|
83
|
+
console.log(JSON.stringify(span));
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
if (span.parentId !== null) return;
|
|
87
|
+
console.log(formatSpanTree(span).join("\n"));
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** How often to send a keepalive ping while the connection is idle. */
|
|
91
|
+
const KEEPALIVE_INTERVAL_MS = 30_000;
|
|
92
|
+
|
|
93
|
+
export interface StreamRecorderSpansOptions {
|
|
94
|
+
/**
|
|
95
|
+
* Print one JSON object per span (NDJSON) instead of a formatted span
|
|
96
|
+
* tree. NOTE: unlike the rest of this CLI's `--json` mode (one JSON value
|
|
97
|
+
* per invocation), this prints one JSON value per line, since this is an
|
|
98
|
+
* unbounded live stream rather than a single request/response result.
|
|
99
|
+
*/
|
|
100
|
+
json: boolean;
|
|
101
|
+
/** Overrides `KEEPALIVE_INTERVAL_MS`, for tests only. */
|
|
102
|
+
keepaliveIntervalMs?: number;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** Why `streamRecorderSpans` stopped. */
|
|
106
|
+
export type StreamRecorderStopReason = "sigint" | "closed" | "error";
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Streams spans from an already-open admin recorder WebSocket to stdout
|
|
110
|
+
* until Ctrl+C or the server closes the connection, sending a keepalive
|
|
111
|
+
* ping every `KEEPALIVE_INTERVAL_MS` so an idle connection doesn't time
|
|
112
|
+
* out. Only root spans (`parentId === null`) are printed in tree mode —
|
|
113
|
+
* children are already nested under their parent by the time the recorder
|
|
114
|
+
* emits the root, so printing children too would just duplicate output. In
|
|
115
|
+
* `--json` mode every span is printed as it arrives, root or not, since a
|
|
116
|
+
* scripting consumer may want the raw stream.
|
|
117
|
+
*
|
|
118
|
+
* Resolves with the reason streaming stopped so the caller can distinguish
|
|
119
|
+
* a user-initiated Ctrl+C (stop entirely) from a server-side close/error
|
|
120
|
+
* (worth reconnecting).
|
|
121
|
+
*/
|
|
122
|
+
export function streamRecorderSpans(
|
|
123
|
+
socket: CliWebSocket,
|
|
124
|
+
options: StreamRecorderSpansOptions,
|
|
125
|
+
): Promise<StreamRecorderStopReason> {
|
|
126
|
+
return new Promise((resolve) => {
|
|
127
|
+
let settled = false;
|
|
128
|
+
let pingId = 0;
|
|
129
|
+
const keepalive = setInterval(() => {
|
|
130
|
+
if (socket.readyState !== 1) return;
|
|
131
|
+
pingId += 1;
|
|
132
|
+
socket.send(JSON.stringify({ type: "ping", id: String(pingId) }));
|
|
133
|
+
}, options.keepaliveIntervalMs ?? KEEPALIVE_INTERVAL_MS);
|
|
134
|
+
|
|
135
|
+
const finish = (
|
|
136
|
+
reason: StreamRecorderStopReason,
|
|
137
|
+
message?: string,
|
|
138
|
+
): void => {
|
|
139
|
+
if (settled) return;
|
|
140
|
+
settled = true;
|
|
141
|
+
clearInterval(keepalive);
|
|
142
|
+
process.off("SIGINT", onSigint);
|
|
143
|
+
if (message) console.error(message);
|
|
144
|
+
resolve(reason);
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
function onSigint(): void {
|
|
148
|
+
socket.close();
|
|
149
|
+
finish("sigint", "Disconnected.");
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
socket.onmessage = (event) => {
|
|
153
|
+
const span = parseRecorderSpanMessage(event.data);
|
|
154
|
+
if (span) printRecorderSpan(span, options.json);
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
socket.onclose = (event) => {
|
|
158
|
+
finish(
|
|
159
|
+
"closed",
|
|
160
|
+
`Recorder connection closed by server (${event.code}${event.reason ? `: ${event.reason}` : ""}).`,
|
|
161
|
+
);
|
|
162
|
+
};
|
|
163
|
+
socket.onerror = () => {
|
|
164
|
+
finish("error", "Recorder connection error.");
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
process.on("SIGINT", onSigint);
|
|
168
|
+
});
|
|
169
|
+
}
|