rpg-engine 0.7.0 → 0.8.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/dist/adventures/index.d.ts +1 -1
- package/dist/adventures/index.js +1 -1
- package/dist/adventures/source.js +13 -13
- package/dist/campaign/create-campaign.js +10 -1
- package/dist/campaign/host-files.d.ts +2 -1
- package/dist/campaign/host-files.js +11 -11
- package/dist/campaign/index.d.ts +1 -1
- package/dist/campaign/index.js +1 -1
- package/dist/campaign/settings.d.ts +55 -64
- package/dist/campaign/settings.js +171 -174
- package/dist/{cli.js → cli/cli.js} +3 -3
- package/dist/{command-line.d.ts → cli/command-line.d.ts} +1 -1
- package/dist/{command-line.js → cli/command-line.js} +21 -20
- package/dist/commands/advance.d.ts +1 -1
- package/dist/commands/advance.js +7 -7
- package/dist/commands/ask.d.ts +1 -8
- package/dist/commands/ask.js +16 -29
- package/dist/commands/{change.d.ts → change/change.d.ts} +2 -2
- package/dist/commands/{change.js → change/change.js} +46 -52
- package/dist/commands/{game-damage.d.ts → change/damage.d.ts} +2 -2
- package/dist/commands/{game-damage.js → change/damage.js} +3 -3
- package/dist/commands/{game-recipe-pace.d.ts → change/recipe-pace.d.ts} +2 -2
- package/dist/commands/{game-recipe-pace.js → change/recipe-pace.js} +4 -4
- package/dist/commands/config.d.ts +4 -4
- package/dist/commands/config.js +142 -138
- package/dist/commands/effect.d.ts +1 -1
- package/dist/commands/effect.js +11 -12
- package/dist/commands/find.d.ts +4 -4
- package/dist/commands/find.js +2 -2
- package/dist/commands/image.js +6 -6
- package/dist/commands/{import.d.ts → import/import.d.ts} +2 -2
- package/dist/commands/{import.js → import/import.js} +101 -101
- package/dist/commands/{game-import.d.ts → import/run.d.ts} +3 -3
- package/dist/commands/{game-import.js → import/run.js} +13 -12
- package/dist/commands/index.js +7 -7
- package/dist/commands/init.js +3 -3
- package/dist/commands/install.js +1 -1
- package/dist/commands/instructions.js +6 -6
- package/dist/commands/mode.d.ts +2 -2
- package/dist/commands/mode.js +8 -8
- package/dist/commands/mood.js +4 -4
- package/dist/commands/move.js +13 -20
- package/dist/commands/package.d.ts +2 -2
- package/dist/commands/package.js +138 -93
- package/dist/commands/rename.js +3 -3
- package/dist/commands/reveal.js +29 -18
- package/dist/commands/{roll.d.ts → roll/roll.d.ts} +4 -4
- package/dist/commands/{roll.js → roll/roll.js} +69 -69
- package/dist/commands/{game-tables.d.ts → roll/tables.d.ts} +2 -2
- package/dist/commands/{game-tables.js → roll/tables.js} +4 -4
- package/dist/commands/rules.d.ts +2 -2
- package/dist/commands/rules.js +3 -3
- package/dist/commands/save.d.ts +1 -1
- package/dist/commands/save.js +18 -18
- package/dist/commands/scene.d.ts +4 -4
- package/dist/commands/scene.js +31 -28
- package/dist/commands/{game-advance.d.ts → shared/advance.d.ts} +4 -4
- package/dist/commands/{game-advance.js → shared/advance.js} +27 -27
- package/dist/commands/{game-adventures.d.ts → shared/adventures.d.ts} +3 -3
- package/dist/commands/{game-adventures.js → shared/adventures.js} +20 -27
- package/dist/commands/{game-bonds.d.ts → shared/bonds.d.ts} +3 -3
- package/dist/commands/{game-bonds.js → shared/bonds.js} +2 -2
- package/dist/commands/{game-checks.d.ts → shared/checks.d.ts} +3 -3
- package/dist/commands/{game-checks.js → shared/checks.js} +7 -7
- package/dist/commands/{game-dice-pool.d.ts → shared/dice-pool.d.ts} +3 -3
- package/dist/commands/{game-dice-pool.js → shared/dice-pool.js} +19 -12
- package/dist/commands/{effect-layer.d.ts → shared/effect-layer.d.ts} +2 -2
- package/dist/commands/{effect-layer.js → shared/effect-layer.js} +12 -12
- package/dist/commands/{game-effects.d.ts → shared/effects.d.ts} +7 -7
- package/dist/commands/{game-effects.js → shared/effects.js} +19 -19
- package/dist/commands/{game-environment.d.ts → shared/environment.d.ts} +1 -1
- package/dist/commands/{game-environment.js → shared/environment.js} +3 -3
- package/dist/commands/{game-events.d.ts → shared/events.d.ts} +5 -5
- package/dist/commands/{game-events.js → shared/events.js} +20 -22
- package/dist/commands/{game-examples.d.ts → shared/examples.d.ts} +4 -8
- package/dist/commands/{game-examples.js → shared/examples.js} +23 -23
- package/dist/commands/{game-experience.d.ts → shared/experience.d.ts} +2 -2
- package/dist/commands/{game-experience.js → shared/experience.js} +8 -11
- package/dist/commands/{game-grid-moves.d.ts → shared/grid-moves.d.ts} +6 -6
- package/dist/commands/{game-grid-moves.js → shared/grid-moves.js} +5 -5
- package/dist/commands/{game-grids.d.ts → shared/grids.d.ts} +4 -9
- package/dist/commands/{game-grids.js → shared/grids.js} +20 -19
- package/dist/commands/{game-images.d.ts → shared/images.d.ts} +3 -3
- package/dist/commands/{game-images.js → shared/images.js} +7 -6
- package/dist/commands/shared/inputs.d.ts +9 -0
- package/dist/commands/shared/inputs.js +12 -0
- package/dist/commands/{game-journey.d.ts → shared/journey.d.ts} +4 -6
- package/dist/commands/{game-journey.js → shared/journey.js} +13 -15
- package/dist/commands/{game-knowledge.d.ts → shared/knowledge.d.ts} +15 -8
- package/dist/commands/{game-knowledge.js → shared/knowledge.js} +42 -42
- package/dist/{library-reader.js → commands/shared/library-reader.js} +4 -4
- package/dist/commands/{game-library.d.ts → shared/library.d.ts} +7 -4
- package/dist/commands/{game-library.js → shared/library.js} +70 -50
- package/dist/commands/{game-limits.d.ts → shared/limits.d.ts} +3 -3
- package/dist/commands/{game-limits.js → shared/limits.js} +3 -3
- package/dist/commands/{game-loot.d.ts → shared/loot.d.ts} +2 -2
- package/dist/commands/{game-loot.js → shared/loot.js} +3 -3
- package/dist/commands/{game-master-rolls.d.ts → shared/master-rolls.d.ts} +2 -2
- package/dist/commands/{game-master-rolls.js → shared/master-rolls.js} +6 -6
- package/dist/commands/{game-mode.d.ts → shared/mode.d.ts} +4 -6
- package/dist/commands/{game-mode.js → shared/mode.js} +10 -10
- package/dist/commands/{game-money.d.ts → shared/money.d.ts} +3 -3
- package/dist/commands/{game-money.js → shared/money.js} +4 -4
- package/dist/commands/{game-moods.d.ts → shared/moods.d.ts} +3 -3
- package/dist/commands/{game-moods.js → shared/moods.js} +3 -3
- package/dist/commands/{game-moves.d.ts → shared/moves.d.ts} +2 -2
- package/dist/commands/{game-moves.js → shared/moves.js} +5 -5
- package/dist/commands/{game-offers.d.ts → shared/offers.d.ts} +3 -3
- package/dist/commands/{game-offers.js → shared/offers.js} +9 -12
- package/dist/commands/{game-outside.d.ts → shared/outside.d.ts} +3 -3
- package/dist/commands/{game-outside.js → shared/outside.js} +9 -9
- package/dist/commands/{game-catalog.d.ts → shared/packages/catalog.d.ts} +1 -3
- package/dist/commands/{game-catalog.js → shared/packages/catalog.js} +17 -22
- package/dist/commands/{game-package-code.d.ts → shared/packages/code.d.ts} +10 -14
- package/dist/commands/{game-package-code.js → shared/packages/code.js} +156 -59
- package/dist/commands/{game-extension-list.d.ts → shared/packages/extensions.d.ts} +6 -6
- package/dist/commands/{game-extension-list.js → shared/packages/extensions.js} +43 -22
- package/dist/commands/{game-package-hooks.d.ts → shared/packages/hooks.d.ts} +3 -3
- package/dist/commands/{game-package-hooks.js → shared/packages/hooks.js} +3 -3
- package/dist/commands/{game-widgets.d.ts → shared/packages/widgets.d.ts} +6 -10
- package/dist/commands/{game-widgets.js → shared/packages/widgets.js} +57 -57
- package/dist/commands/{page-counters.d.ts → shared/page-counters.d.ts} +3 -3
- package/dist/commands/{page-counters.js → shared/page-counters.js} +5 -5
- package/dist/{page-words.d.ts → commands/shared/page-words.d.ts} +2 -2
- package/dist/{page-words.js → commands/shared/page-words.js} +5 -4
- package/dist/commands/{parts.d.ts → shared/parts.d.ts} +3 -3
- package/dist/commands/{parts.js → shared/parts.js} +4 -4
- package/dist/commands/{game-positions.d.ts → shared/positions.d.ts} +3 -5
- package/dist/commands/{game-positions.js → shared/positions.js} +6 -7
- package/dist/commands/{problems.d.ts → shared/problems.d.ts} +3 -3
- package/dist/commands/{problems.js → shared/problems.js} +21 -22
- package/dist/commands/{progression.d.ts → shared/progression.d.ts} +2 -2
- package/dist/commands/{progression.js → shared/progression.js} +4 -4
- package/dist/commands/{game-quests.d.ts → shared/quests.d.ts} +4 -4
- package/dist/commands/{game-quests.js → shared/quests.js} +6 -6
- package/dist/commands/{game-recipes.d.ts → shared/recipes.d.ts} +3 -3
- package/dist/commands/{game-recipes.js → shared/recipes.js} +3 -3
- package/dist/commands/{game-reminders.d.ts → shared/reminders.d.ts} +4 -4
- package/dist/commands/{game-reminders.js → shared/reminders.js} +4 -4
- package/dist/commands/{game-roads.d.ts → shared/roads.d.ts} +5 -5
- package/dist/commands/{game-roads.js → shared/roads.js} +43 -44
- package/dist/commands/{game-rules.d.ts → shared/rules.d.ts} +2 -2
- package/dist/commands/{game-rules.js → shared/rules.js} +4 -4
- package/dist/commands/{game-saves.d.ts → shared/saves.d.ts} +4 -4
- package/dist/commands/{game-saves.js → shared/saves.js} +51 -51
- package/dist/commands/{game-scene.d.ts → shared/scene.d.ts} +13 -3
- package/dist/commands/{game-scene.js → shared/scene.js} +41 -13
- package/dist/commands/{sheet.d.ts → shared/sheet.d.ts} +5 -5
- package/dist/commands/{sheet.js → shared/sheet.js} +76 -76
- package/dist/commands/{game-stacks.d.ts → shared/stacks.d.ts} +2 -9
- package/dist/commands/{game-stacks.js → shared/stacks.js} +22 -22
- package/dist/commands/{game-theme.d.ts → shared/theme.d.ts} +3 -3
- package/dist/commands/{game-theme.js → shared/theme.js} +2 -2
- package/dist/commands/{game-thoughts.d.ts → shared/thoughts.d.ts} +2 -4
- package/dist/commands/{game-thoughts.js → shared/thoughts.js} +6 -8
- package/dist/commands/{game-thresholds.d.ts → shared/thresholds.d.ts} +1 -1
- package/dist/commands/{game-thresholds.js → shared/thresholds.js} +4 -4
- package/dist/commands/{game-time.d.ts → shared/time.d.ts} +4 -4
- package/dist/commands/{game-time.js → shared/time.js} +6 -6
- package/dist/commands/{game-turn-uses.d.ts → shared/turn-uses.d.ts} +3 -3
- package/dist/commands/{game-turn-uses.js → shared/turn-uses.js} +12 -15
- package/dist/commands/{game-upkeep.d.ts → shared/upkeep.d.ts} +3 -3
- package/dist/commands/{game-upkeep.js → shared/upkeep.js} +69 -57
- package/dist/commands/{game-voices.d.ts → shared/voices.d.ts} +1 -1
- package/dist/commands/{game-voices.js → shared/voices.js} +2 -2
- package/dist/commands/{worked-out.d.ts → shared/worked-out.d.ts} +3 -8
- package/dist/commands/{worked-out.js → shared/worked-out.js} +238 -238
- package/dist/commands/{game-world.d.ts → shared/world.d.ts} +5 -14
- package/dist/commands/{game-world.js → shared/world.js} +72 -76
- package/dist/commands/show.d.ts +1 -1
- package/dist/commands/show.js +32 -17
- package/dist/commands/status.d.ts +1 -1
- package/dist/commands/status.js +28 -28
- package/dist/commands/thoughts.js +3 -3
- package/dist/commands/trade.js +9 -10
- package/dist/commands/translate.d.ts +1 -1
- package/dist/commands/translate.js +3 -3
- package/dist/commands/{game-open.d.ts → travel/open.d.ts} +3 -3
- package/dist/commands/{game-open.js → travel/open.js} +4 -5
- package/dist/commands/{route.d.ts → travel/route.d.ts} +1 -1
- package/dist/commands/{route.js → travel/route.js} +9 -10
- package/dist/commands/{travel.d.ts → travel/travel.d.ts} +2 -2
- package/dist/commands/{travel.js → travel/travel.js} +19 -21
- package/dist/commands/validate.js +5 -5
- package/dist/commands/{game-view-journal.d.ts → view/journal.d.ts} +5 -5
- package/dist/commands/{game-view-journal.js → view/journal.js} +5 -5
- package/dist/commands/{game-view-map.d.ts → view/map.d.ts} +3 -3
- package/dist/commands/{game-view-map.js → view/map.js} +15 -16
- package/dist/commands/{game-view-place.d.ts → view/place.d.ts} +6 -6
- package/dist/commands/{game-view-place.js → view/place.js} +108 -108
- package/dist/commands/{view.d.ts → view/view.d.ts} +16 -16
- package/dist/commands/{view.js → view/view.js} +35 -35
- package/dist/commands/{game-view-world.d.ts → view/world.d.ts} +4 -4
- package/dist/commands/{game-view-world.js → view/world.js} +7 -7
- package/dist/commands/{game-here.d.ts → write/here.d.ts} +5 -3
- package/dist/commands/{game-here.js → write/here.js} +18 -12
- package/dist/commands/{write.d.ts → write/write.d.ts} +6 -6
- package/dist/commands/{write.js → write/write.js} +44 -41
- package/dist/confirm/confirm.d.ts +2 -0
- package/dist/confirm/confirm.js +15 -5
- package/dist/core/consents.d.ts +3 -2
- package/dist/core/consents.js +43 -4
- package/dist/core/context.d.ts +8 -6
- package/dist/core/context.js +4 -2
- package/dist/core/download.js +16 -5
- package/dist/core/files.d.ts +6 -1
- package/dist/core/files.js +47 -21
- package/dist/core/formula.d.ts +7 -2
- package/dist/core/formula.js +63 -66
- package/dist/core/instruction-parts.js +1 -1
- package/dist/core/mood.d.ts +0 -1
- package/dist/core/mood.js +3 -3
- package/dist/core/package-api.d.ts +11 -0
- package/dist/core/package-api.js +2 -1
- package/dist/core/package-declarations.d.ts +9 -9
- package/dist/core/package-declarations.js +3 -3
- package/dist/core/process-mark.d.ts +8 -0
- package/dist/core/process-mark.js +72 -0
- package/dist/core/registry.d.ts +5 -0
- package/dist/core/registry.js +10 -0
- package/dist/core/session-store.d.ts +0 -1
- package/dist/core/session-store.js +11 -14
- package/dist/core/store.d.ts +4 -0
- package/dist/core/store.js +29 -8
- package/dist/core/text.d.ts +4 -0
- package/dist/core/text.js +11 -2
- package/dist/core/yaml-file.js +2 -2
- package/dist/dashboard/{acts.js → acts/acts.js} +2 -2
- package/dist/dashboard/{act-names.js → acts/names.js} +1 -1
- package/dist/dashboard/{act-sheet.js → acts/sheet.js} +3 -3
- package/dist/dashboard/{act-strip.js → acts/strip.js} +2 -2
- package/dist/dashboard/app.js +13 -13
- package/dist/dashboard/asked.js +1 -1
- package/dist/dashboard/dice/burn.js +1 -1
- package/dist/dashboard/dice/stage.js +1 -1
- package/dist/dashboard/{guide-blocks.js → help/blocks.js} +1 -1
- package/dist/dashboard/{help.js → help/help.js} +6 -6
- package/dist/dashboard/journal.js +1 -1
- package/dist/dashboard/kit.js +6 -5
- package/dist/dashboard/labels.js +7 -3
- package/dist/dashboard/markdown.js +1 -1
- package/dist/dashboard/{ask-card.js → packages/ask-card.js} +6 -6
- package/dist/dashboard/{package-page.js → packages/package-page.js} +3 -3
- package/dist/dashboard/{packages.js → packages/packages.js} +12 -12
- package/dist/dashboard/{page-code.js → packages/page-code.js} +4 -4
- package/dist/dashboard/{extension-widgets.js → packages/widgets.js} +5 -5
- package/dist/dashboard/party.js +1 -1
- package/dist/dashboard/person-panel.js +2 -13
- package/dist/dashboard/{map-sheet.js → place/map-sheet.js} +4 -4
- package/dist/dashboard/{place-map-view.js → place/map-view.js} +11 -11
- package/dist/dashboard/scene.js +4 -4
- package/dist/dashboard/settings.js +1 -1
- package/dist/dashboard/sheet.js +3 -3
- package/dist/dashboard/top.js +2 -2
- package/dist/dashboard/turns.js +2 -2
- package/dist/dashboard/widgets.js +1 -1
- package/dist/dashboard/{world-calendar.js → world/calendar.js} +7 -7
- package/dist/dashboard/{lore.js → world/known.js} +1 -1
- package/dist/dashboard/{world-lore.js → world/lore.js} +9 -9
- package/dist/dashboard/{world-map.js → world/map.js} +1 -1
- package/dist/dashboard/{world.js → world/world.js} +14 -14
- package/dist/dice/evaluate.js +1 -1
- package/dist/dice/index.d.ts +2 -2
- package/dist/dice/index.js +2 -2
- package/dist/dice/notation.d.ts +2 -0
- package/dist/dice/notation.js +22 -4
- package/dist/documents/markup.js +2 -2
- package/dist/documents/read.js +29 -13
- package/dist/effects/effect.js +2 -5
- package/dist/extensions/extension.js +6 -8
- package/dist/extensions/index.d.ts +1 -4
- package/dist/extensions/index.js +1 -4
- package/dist/extensions/words.js +2 -1
- package/dist/{pictures → helpers}/briefs.js +17 -14
- package/dist/{pictures → helpers}/claude.js +8 -18
- package/dist/{pictures → helpers}/codex.js +3 -15
- package/dist/helpers/index.d.ts +7 -0
- package/dist/helpers/index.js +9 -0
- package/dist/{pictures/helpers.d.ts → helpers/programs.d.ts} +6 -1
- package/dist/{pictures/helpers.js → helpers/programs.js} +16 -2
- package/dist/images/images.js +7 -5
- package/dist/images/index.d.ts +1 -1
- package/dist/images/index.js +1 -1
- package/dist/importer/index.d.ts +1 -1
- package/dist/importer/index.js +1 -1
- package/dist/importer/work.d.ts +0 -2
- package/dist/importer/work.js +9 -30
- package/dist/instructions/index.d.ts +2 -0
- package/dist/instructions/index.js +10 -0
- package/dist/languages/index.d.ts +1 -1
- package/dist/languages/index.js +1 -1
- package/dist/languages/language-pack.js +15 -3
- package/dist/library/books.js +29 -83
- package/dist/{extensions → packages}/engine.d.ts +1 -1
- package/dist/{extensions → packages}/engine.js +1 -1
- package/dist/packages/index.d.ts +3 -0
- package/dist/packages/index.js +4 -0
- package/dist/{extensions/packages.d.ts → packages/npm.d.ts} +2 -0
- package/dist/{extensions/packages.js → packages/npm.js} +74 -45
- package/dist/page.d.ts +9 -11
- package/dist/page.js +1 -2
- package/dist/pages/check.js +31 -40
- package/dist/pages/containers.js +20 -20
- package/dist/pages/environment.js +15 -15
- package/dist/pages/index.d.ts +9 -9
- package/dist/pages/index.js +9 -9
- package/dist/pages/inheritance.d.ts +2 -1
- package/dist/pages/inheritance.js +24 -24
- package/dist/pages/load.js +7 -7
- package/dist/pages/maps.d.ts +20 -0
- package/dist/pages/maps.js +51 -1
- package/dist/pages/markdown.d.ts +2 -0
- package/dist/pages/markdown.js +110 -79
- package/dist/pages/page-file.d.ts +2 -1
- package/dist/pages/page-file.js +31 -29
- package/dist/pages/rename-page.d.ts +4 -1
- package/dist/pages/rename-page.js +7 -3
- package/dist/pages/{stack-entry.d.ts → stacks/entry.d.ts} +0 -2
- package/dist/pages/{stack-entry.js → stacks/entry.js} +2 -6
- package/dist/pages/{stacks.d.ts → stacks/kinds.d.ts} +8 -1
- package/dist/pages/{stacks.js → stacks/kinds.js} +36 -41
- package/dist/pages/{stack-writes.d.ts → stacks/writes.d.ts} +2 -2
- package/dist/pages/{stack-writes.js → stacks/writes.js} +32 -32
- package/dist/pages/system-pages.js +15 -15
- package/dist/pages/world.js +25 -19
- package/dist/pages/write-page.js +35 -34
- package/dist/player-notes/index.d.ts +1 -1
- package/dist/player-notes/index.js +1 -1
- package/dist/rules/page-search.js +3 -4
- package/dist/rules/rule-book.js +1 -1
- package/dist/rules/search.js +21 -21
- package/dist/rules/shown.js +1 -3
- package/dist/saves/saves.d.ts +2 -2
- package/dist/saves/saves.js +15 -3
- package/dist/{bell-listener.js → server/bell-listener.js} +3 -3
- package/dist/server/dashboard/files.d.ts +59 -0
- package/dist/server/dashboard/files.js +326 -0
- package/dist/server/dashboard/index.d.ts +114 -0
- package/dist/server/dashboard/index.js +419 -0
- package/dist/server/dashboard/news.d.ts +39 -0
- package/dist/server/dashboard/news.js +390 -0
- package/dist/server/dashboard/player.d.ts +48 -0
- package/dist/server/dashboard/player.js +242 -0
- package/dist/server/dashboard/ports.d.ts +10 -0
- package/dist/server/dashboard/ports.js +15 -0
- package/dist/server/dashboard/writes.d.ts +58 -0
- package/dist/server/dashboard/writes.js +492 -0
- package/dist/{mcp-server.d.ts → server/mcp.d.ts} +2 -2
- package/dist/{mcp-server.js → server/mcp.js} +57 -42
- package/dist/systems/game-system.d.ts +5 -3
- package/dist/systems/game-system.js +178 -149
- package/dist/systems/index.d.ts +1 -1
- package/dist/systems/index.js +1 -1
- package/dist/{testing.d.ts → testing/index.d.ts} +6 -6
- package/dist/{testing.js → testing/index.js} +32 -18
- package/dist/{system-checks.js → testing/system-checks.js} +18 -12
- package/dist/themes/theme.d.ts +3 -3
- package/dist/themes/theme.js +14 -14
- package/dist/time/calendar.js +5 -2
- package/dist/triggers/trigger.js +5 -8
- package/instructions/dashboard-guide.md +2 -1
- package/instructions/play.md +1 -1
- package/package.json +5 -5
- package/dist/commands/game-maps.d.ts +0 -20
- package/dist/commands/game-maps.js +0 -51
- package/dist/dashboard-server.d.ts +0 -47
- package/dist/dashboard-server.js +0 -1830
- package/dist/pictures/index.d.ts +0 -7
- package/dist/pictures/index.js +0 -9
- /package/dist/{cli.d.ts → cli/cli.d.ts} +0 -0
- /package/dist/{library-reader.d.ts → commands/shared/library-reader.d.ts} +0 -0
- /package/dist/commands/{notes.d.ts → shared/notes.d.ts} +0 -0
- /package/dist/commands/{notes.js → shared/notes.js} +0 -0
- /package/dist/dashboard/{guide-markdown.js → help/markdown.js} +0 -0
- /package/dist/dashboard/{pack-card.js → packages/card.js} +0 -0
- /package/dist/dashboard/{people.js → packages/people.js} +0 -0
- /package/dist/dashboard/{place-map.js → place/map.js} +0 -0
- /package/dist/dashboard/{calendar.js → world/days.js} +0 -0
- /package/dist/{pictures → helpers}/briefs.d.ts +0 -0
- /package/dist/{pictures → helpers}/chosen.d.ts +0 -0
- /package/dist/{pictures → helpers}/chosen.js +0 -0
- /package/dist/{pictures → helpers}/claude.d.ts +0 -0
- /package/dist/{pictures → helpers}/codex.d.ts +0 -0
- /package/dist/{pictures → helpers}/stop.d.ts +0 -0
- /package/dist/{pictures → helpers}/stop.js +0 -0
- /package/dist/{pictures → helpers}/svg.d.ts +0 -0
- /package/dist/{pictures → helpers}/svg.js +0 -0
- /package/dist/{extensions → packages}/tarball.d.ts +0 -0
- /package/dist/{extensions → packages}/tarball.js +0 -0
- /package/dist/{bell-listener.d.ts → server/bell-listener.d.ts} +0 -0
- /package/dist/{player-acts.d.ts → server/player-acts.d.ts} +0 -0
- /package/dist/{player-acts.js → server/player-acts.js} +0 -0
- /package/dist/{system-checks.d.ts → testing/system-checks.d.ts} +0 -0
|
@@ -0,0 +1,492 @@
|
|
|
1
|
+
import { basename, join } from "node:path";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { readAdventureZip } from "../../adventures/index.js";
|
|
4
|
+
import { findCampaign, readSettings, readTextSetting, requireCampaign, settingNames } from "../../campaign/index.js";
|
|
5
|
+
import { config, playerSettingNamed, playerSettings, setupSettingNamed } from "../../commands/config.js";
|
|
6
|
+
import { adventureText, isInstalledPackage, packageCommand, YesRefused } from "../../commands/package.js";
|
|
7
|
+
import { playerSaveNews, save } from "../../commands/save.js";
|
|
8
|
+
import { installAdventure } from "../../commands/shared/adventures.js";
|
|
9
|
+
import { libraryContents, libraryEntries, startLibraryReading, unquoted } from "../../commands/shared/library.js";
|
|
10
|
+
import { campaignMode } from "../../commands/shared/mode.js";
|
|
11
|
+
import { catalog } from "../../commands/shared/packages/catalog.js";
|
|
12
|
+
import { packageCommands } from "../../commands/shared/packages/code.js";
|
|
13
|
+
import { exportsFolderName, resetPoints } from "../../commands/shared/saves.js";
|
|
14
|
+
import { campaignSystem, campaignWorld } from "../../commands/shared/world.js";
|
|
15
|
+
import { packagesFolder } from "../../core/context.js";
|
|
16
|
+
import { files, withFiles } from "../../core/store.js";
|
|
17
|
+
import { comparableText } from "../../core/text.js";
|
|
18
|
+
import { getVersion, isNewerVersion } from "../../core/version.js";
|
|
19
|
+
import { extensionWords, findExtension } from "../../extensions/index.js";
|
|
20
|
+
import { samePath } from "../../library/index.js";
|
|
21
|
+
import { readableSystems } from "../../systems/index.js";
|
|
22
|
+
import { decoded, mostSaid, readBody, readBytes, securityHeaders, send, sendJson } from "./files.js";
|
|
23
|
+
// How long the catalog is kept before npm and GitHub are asked again.
|
|
24
|
+
const catalogLife = 10 * 60 * 1000;
|
|
25
|
+
// The version of rpg-engine this server runs, read as it starts: an update on disk comes only with a new chat (D-515 (3)).
|
|
26
|
+
const runningVersion = getVersion();
|
|
27
|
+
// The largest .zip the page sends for an adventure: far more than one holds, far less than the engine reads of a package.
|
|
28
|
+
const largestUpload = 100 * 1024 * 1024;
|
|
29
|
+
/**
|
|
30
|
+
* Runs a command of a package the player may run from its page code (D-510, D-514): one the campaign's packages give with player, whose code runs; as the
|
|
31
|
+
* player's, its output among what the master hears at their next call, quoted as another's words.
|
|
32
|
+
*/
|
|
33
|
+
export async function runForPlayer(request, response, served) {
|
|
34
|
+
const parsed = z.object({ command: z.string().trim().min(1).max(80), input: z.record(z.string(), z.unknown()).optional() }).strict().safeParse(await readBody(request));
|
|
35
|
+
if (!parsed.success) {
|
|
36
|
+
sendJson(response, 400, { error: "Send the command to run and its input: { command, input }." });
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
try {
|
|
40
|
+
await served.session.ready();
|
|
41
|
+
const context = { ...served.context, actor: "player" };
|
|
42
|
+
const { text, readOnly } = await withFiles(served.session, async () => {
|
|
43
|
+
const root = requireCampaign(context.folder);
|
|
44
|
+
const command = (await packageCommands(root, context)).commands.find((one) => one.name === parsed.data.command && one.forPlayer === true);
|
|
45
|
+
if (command === undefined) {
|
|
46
|
+
throw new Error(`No package of the campaign gives ${parsed.data.command} to the player: a page runs only the commands its package marks player.`);
|
|
47
|
+
}
|
|
48
|
+
const input = command.input.safeParse(parsed.data.input ?? {});
|
|
49
|
+
if (!input.success) {
|
|
50
|
+
throw new Error(`The input of ${command.name} is not valid: ${input.error.issues.map((issue) => `${issue.path.join(".") || "input"}: ${issue.message}`).join("; ")}.`);
|
|
51
|
+
}
|
|
52
|
+
return { text: command.format(await command.run(input.data, context)), readOnly: command.readOnly === true };
|
|
53
|
+
});
|
|
54
|
+
const quoted = text.split("\n").map((line) => `> ${line}`).join("\n");
|
|
55
|
+
// A command that only reads tells the master nothing (D-514).
|
|
56
|
+
if (readOnly) {
|
|
57
|
+
sendJson(response, 200, { text });
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
served.events.push(`The player, on the dashboard, ran ${parsed.data.command}: it is already done, do not run it again. It said, as its package's words:\n${quoted}`);
|
|
61
|
+
served.notify();
|
|
62
|
+
sendJson(response, 200, { text });
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
sendJson(response, 400, { error: error instanceof Error ? error.message : String(error) });
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* One of the player's settings changed on the page (D-341): a value, or an item added to or taken off a list, as config takes it, with the player as who
|
|
70
|
+
* changed it; the master hears of it at the head of their next call. A setting of the master's is refused.
|
|
71
|
+
*/
|
|
72
|
+
export async function changeSetting(request, response, served) {
|
|
73
|
+
const body = await readBody(request);
|
|
74
|
+
const parsed = z.union([
|
|
75
|
+
z.object({ setting: z.string(), value: z.string().trim().min(1).max(mostSaid) }).strict(),
|
|
76
|
+
z.object({ setting: z.string(), add: z.string().trim().min(1).max(mostSaid) }).strict(),
|
|
77
|
+
z.object({ setting: z.string(), remove: z.string().min(1).max(mostSaid) }).strict(),
|
|
78
|
+
]).safeParse(body);
|
|
79
|
+
if (!parsed.success) {
|
|
80
|
+
sendJson(response, 400, { error: "Send a setting of the player's with its value, { setting, value }, or an item to add to a list or take off it, { setting, add } or { setting, remove }." });
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
try {
|
|
84
|
+
await served.session.ready();
|
|
85
|
+
const change = parsed.data;
|
|
86
|
+
const refused = withFiles(served.session, () => {
|
|
87
|
+
const root = requireCampaign(served.context.folder);
|
|
88
|
+
// In the setup, how companions come, the preparation and the name are the player's too (D-370).
|
|
89
|
+
const setup = campaignMode(root, campaignWorld(root, served.context)) === "setup";
|
|
90
|
+
// Where the page shows the extensions' widgets is the page's own: the master hears nothing of it (D-502).
|
|
91
|
+
if (change.setting.trim() === "widgets" && !("add" in change)) {
|
|
92
|
+
config.run(config.input.parse({ setting: "widgets", ...("value" in change ? { value: change.value } : { remove: [change.remove] }) }), { ...served.context, actor: "player" });
|
|
93
|
+
return undefined;
|
|
94
|
+
}
|
|
95
|
+
const before = playerSettingNamed(root, served.context, change.setting) ?? (setup ? setupSettingNamed(root, change.setting) : undefined);
|
|
96
|
+
if (before === undefined) {
|
|
97
|
+
return settingNames.includes(change.setting.trim())
|
|
98
|
+
? { status: 403, error: `${change.setting} is the master's to change, in the chat.` }
|
|
99
|
+
: { status: 400, error: `There is no setting "${change.setting}": the player's are ${playerSettings(root, served.context).map((one) => one.name).join(", ")}.` };
|
|
100
|
+
}
|
|
101
|
+
const input = "value" in change ? { value: change.value } : "add" in change ? { add: [change.add] } : { remove: [change.remove] };
|
|
102
|
+
config.run(config.input.parse({ setting: before.name, ...input }), { ...served.context, actor: "player" });
|
|
103
|
+
if (!served.changed.has(before.name)) {
|
|
104
|
+
served.changed.set(before.name, before);
|
|
105
|
+
}
|
|
106
|
+
return undefined;
|
|
107
|
+
});
|
|
108
|
+
if (refused === undefined) {
|
|
109
|
+
sendJson(response, 202, {});
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
sendJson(response, refused.status, { error: refused.error });
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
catch (error) {
|
|
116
|
+
sendJson(response, 400, { error: error instanceof Error ? error.message : String(error) });
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* A save the player makes on the page, one they go back to, or the campaign started over from its first, as save does, with the player as who did it; the
|
|
121
|
+
* mode of saves allows it or refuses it as in the chat, and starting over needs the campaign's name written. The master hears of it at their next call (D-359).
|
|
122
|
+
*/
|
|
123
|
+
export async function changeSaves(request, response, served) {
|
|
124
|
+
const parsed = z.union([
|
|
125
|
+
z.object({ action: z.literal("make"), label: z.string().trim().max(80).optional() }).strict(),
|
|
126
|
+
z.object({ action: z.literal("load"), save: z.number().int().positive() }).strict(),
|
|
127
|
+
z.object({ action: z.literal("reset"), campaign: z.string().trim().max(mostSaid), to: z.enum(resetPoints).optional() }).strict(),
|
|
128
|
+
z.object({ action: z.literal("new chat") }).strict(),
|
|
129
|
+
]).safeParse(await readBody(request));
|
|
130
|
+
if (!parsed.success) {
|
|
131
|
+
sendJson(response, 400, {
|
|
132
|
+
error: "Send { action: make } with a label if you like, { action: load, save } with its number, or { action: reset, campaign } with the campaign's name, "
|
|
133
|
+
+ "to start it over, and to: start or session zero; or { action: new chat } once a new chat with the master is open after going back.",
|
|
134
|
+
});
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
// Going back while the master waits for the player's answer would answer it in the game started over (D-361); while a call of theirs runs, it would write
|
|
138
|
+
// in the game loaded.
|
|
139
|
+
if ((parsed.data.action === "load" || parsed.data.action === "reset") && served.asked !== undefined) {
|
|
140
|
+
sendJson(response, 409, { error: "The master is asking you something: answer it first, then go back." });
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
if ((parsed.data.action === "load" || parsed.data.action === "reset") && (served.context.chat?.calls ?? 0) > 0) {
|
|
144
|
+
sendJson(response, 409, { error: "The master is working on the game now: go back once they have answered." });
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
try {
|
|
148
|
+
await served.session.ready();
|
|
149
|
+
const change = parsed.data;
|
|
150
|
+
const news = await withFiles(served.session, async () => {
|
|
151
|
+
const name = readSettings(requireCampaign(served.context.folder)).name;
|
|
152
|
+
if (change.action === "reset" && comparableText(change.campaign) !== comparableText(name)) {
|
|
153
|
+
throw new Error(`Write the campaign's name, ${name}, to start it over. Nothing changed.`);
|
|
154
|
+
}
|
|
155
|
+
const input = change.action === "make"
|
|
156
|
+
? { action: "make", ...(change.label === undefined || change.label === "" ? {} : { label: change.label }) }
|
|
157
|
+
: change.action === "load"
|
|
158
|
+
? { action: "load", save: String(change.save) }
|
|
159
|
+
: change.action === "new chat"
|
|
160
|
+
? { action: "new chat" }
|
|
161
|
+
: { action: "reset", ...(change.to === undefined ? {} : { to: change.to }) };
|
|
162
|
+
return playerSaveNews(await save.run(save.input.parse(input), { ...served.context, actor: "player" }));
|
|
163
|
+
});
|
|
164
|
+
served.events.push(news);
|
|
165
|
+
sendJson(response, 202, {});
|
|
166
|
+
}
|
|
167
|
+
catch (error) {
|
|
168
|
+
sendJson(response, 400, { error: error instanceof Error ? error.message : String(error) });
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* The packages as the page shows them (D-475): the game system, those on this computer with whether the campaign uses them, those it lists and lacks, what npm
|
|
173
|
+
* has when asked, and the one the player is working on now.
|
|
174
|
+
*/
|
|
175
|
+
export async function packagesNow(response, served, npm) {
|
|
176
|
+
try {
|
|
177
|
+
await served.session.ready();
|
|
178
|
+
const shown = await withFiles(served.session, async () => {
|
|
179
|
+
const root = requireCampaign(served.context.folder);
|
|
180
|
+
const system = campaignSystem(root, served.context);
|
|
181
|
+
const list = await packageCommand.run(packageCommand.input.parse({ action: "list" }), served.context);
|
|
182
|
+
const available = npm ? await packageCommand.run(packageCommand.input.parse({ action: "available" }), served.context) : undefined;
|
|
183
|
+
return {
|
|
184
|
+
system: system === undefined ? null : { name: system.name, title: system.title },
|
|
185
|
+
// The other systems of this computer, for a new campaign: a campaign's own is chosen in its setup (D-475).
|
|
186
|
+
otherSystems: readableSystems(served.context.systemFolders).filter((other) => other.name !== system?.name).map((other) => ({ name: other.name, title: other.title })),
|
|
187
|
+
...(list.kind === "list" ? { installed: inLanguage(list.installed, served, readTextSetting(root, "language")), missing: list.missing, adventures: list.adventures, systems: list.systems, languages: list.languages } : {}),
|
|
188
|
+
...(available?.kind === "available" ? { available: available.packages, ...(available.failed === undefined ? {} : { failed: available.failed }) } : {}),
|
|
189
|
+
...(served.packageWork === undefined ? {} : { working: served.packageWork }),
|
|
190
|
+
};
|
|
191
|
+
});
|
|
192
|
+
sendJson(response, 200, shown);
|
|
193
|
+
}
|
|
194
|
+
catch (error) {
|
|
195
|
+
sendJson(response, 400, { error: error instanceof Error ? error.message : String(error) });
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* A package the player updates, takes out of the campaign or off this computer on the page (D-475, D-485), as package does with the player as who did it; the
|
|
200
|
+
* master hears of it at the head of their next call. One not ours is updated with the player's yes in a window of their computer, never the page's click (D-478).
|
|
201
|
+
*/
|
|
202
|
+
export async function changePackage(request, response, served) {
|
|
203
|
+
const parsed = z.object({ action: z.enum(["update", "remove", "uninstall"]), name: z.string().trim().min(1).max(214) }).strict().safeParse(await readBody(request));
|
|
204
|
+
if (!parsed.success) {
|
|
205
|
+
sendJson(response, 400, { error: "Send what to do with which package: { action: update, remove or uninstall, name }." });
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
const { action, name } = parsed.data;
|
|
209
|
+
// The page updates or takes away only what this computer has: it never brings a package new to it, nor its window, by these (D-510).
|
|
210
|
+
if (!isInstalledPackage(served.context, name)) {
|
|
211
|
+
sendJson(response, 400, { error: `${name} is not installed on this computer: add a package from the Packages page, where you choose it.` });
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
const done = action === "update" ? "updated" : action === "remove" ? "took out of the campaign" : "uninstalled";
|
|
215
|
+
await packageWork(response, served, name, action, async (context) => {
|
|
216
|
+
const result = await packageCommand.run(packageCommand.input.parse({ action: action === "update" ? "install" : action, name }), context);
|
|
217
|
+
return { kind: result.kind, news: `The player, on the dashboard, ${done} ${name}: ${packageCommand.format(result)}` };
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Something the player adds on the page (D-485 (1)): a .zip or a .tgz as the request's body, named by its X-File-Name, or { source }: a link, an npm name or a
|
|
222
|
+
* folder of this computer. The engine tells the kind by what it holds; an adventure is read in memory, a .tgz kept in the player's data folder while npm installs it.
|
|
223
|
+
*/
|
|
224
|
+
export async function addPackage(request, response, served) {
|
|
225
|
+
const json = /^application\/json/i.test(String(request.headers["content-type"] ?? ""));
|
|
226
|
+
const given = json ? z.object({ source: z.string().trim().min(1).max(2000) }).strict().safeParse(await readBody(request)) : undefined;
|
|
227
|
+
const file = fileName(String(request.headers["x-file-name"] ?? "package.zip")).replace(/[\\/:*?"<>|\u0000-\u001f]/g, "").slice(0, 120) || "package.zip";
|
|
228
|
+
const bytes = json ? undefined : await readBytes(request, largestUpload);
|
|
229
|
+
if (given?.success === false) {
|
|
230
|
+
sendJson(response, 400, { error: "Send what to add: { source }, a link, an npm name or a folder of this computer; or a .zip or a .tgz as the body." });
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
if (!json && bytes === undefined) {
|
|
234
|
+
sendJson(response, 413, { error: `The file is more than ${largestUpload / 1024 / 1024} MB: no package is that big.` });
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
if (bytes !== undefined && !/\.(zip|tgz|tar\.gz)$/i.test(file)) {
|
|
238
|
+
sendJson(response, 400, { error: `${file} is neither a .zip nor a .tgz: an adventure comes as a .zip, an extension, a game system or a language as a .tgz.` });
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
const source = given?.success === true ? given.data.source : file;
|
|
242
|
+
await packageWork(response, served, source, "add", async (context) => {
|
|
243
|
+
if (bytes !== undefined && /\.zip$/i.test(file)) {
|
|
244
|
+
const root = requireCampaign(context.folder);
|
|
245
|
+
const installed = installAdventure(root, context, readAdventureZip(bytes, file), file);
|
|
246
|
+
return { kind: "adventure", news: `The player, on the dashboard, added an adventure: ${adventureText(installed)}` };
|
|
247
|
+
}
|
|
248
|
+
const kept = bytes === undefined ? undefined : join(served.context.home ?? packagesFolder(), "uploads", file);
|
|
249
|
+
try {
|
|
250
|
+
if (kept !== undefined && bytes !== undefined) {
|
|
251
|
+
files().writeBytes(kept, bytes);
|
|
252
|
+
}
|
|
253
|
+
const result = await packageCommand.run(packageCommand.input.parse({ action: "install", name: kept ?? source }), context);
|
|
254
|
+
return { kind: kindOf(result.kind), news: `The player, on the dashboard, added ${bytes === undefined ? source : file}: ${packageCommand.format(result)}` };
|
|
255
|
+
}
|
|
256
|
+
finally {
|
|
257
|
+
if (kept !== undefined) {
|
|
258
|
+
files().remove(kept);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* This computer's library as the page shows it (D-491 (13)): each entry with its books read, being read and skipped, and whether the campaign uses it; and the
|
|
265
|
+
* work under way, if any.
|
|
266
|
+
*/
|
|
267
|
+
export async function libraryNow(response, served) {
|
|
268
|
+
try {
|
|
269
|
+
await served.session.ready();
|
|
270
|
+
const entries = withFiles(served.session, () => libraryEntries(requireCampaign(served.context.folder), served.context));
|
|
271
|
+
// Books still to read, as after the computer started again, are read now: the page counts them as they come.
|
|
272
|
+
startLibraryReading(served.context);
|
|
273
|
+
sendJson(response, 200, { entries, ...(served.packageWork === undefined ? {} : { working: served.packageWork }) });
|
|
274
|
+
}
|
|
275
|
+
catch (error) {
|
|
276
|
+
sendJson(response, 400, { error: error instanceof Error ? error.message : String(error) });
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* A folder or a book of the library the player turns on in the campaign on the page, off, or takes off this computer (D-491 (13)), as config does with the
|
|
281
|
+
* player as who did it: one new to the computer with their yes in a window of their computer, never the page's click (D-477); the books are never touched.
|
|
282
|
+
* One work at a time, as the packages'.
|
|
283
|
+
*/
|
|
284
|
+
export async function changeLibrary(request, response, served) {
|
|
285
|
+
const parsed = z.object({ action: z.enum(["add", "remove", "forget"]), path: z.string().trim().min(1).max(1000) }).strict().safeParse(await readBody(request));
|
|
286
|
+
if (!parsed.success) {
|
|
287
|
+
sendJson(response, 400, { error: "Send what to do with which folder: { action: add, remove or forget, path }." });
|
|
288
|
+
return;
|
|
289
|
+
}
|
|
290
|
+
const { action } = parsed.data;
|
|
291
|
+
const path = unquoted(parsed.data.path);
|
|
292
|
+
await packageWork(response, served, path, "library", async (context) => {
|
|
293
|
+
const root = requireCampaign(context.folder);
|
|
294
|
+
const before = libraryEntries(root, context).find((entry) => entry.used && samePath(entry.path, path)) !== undefined;
|
|
295
|
+
const input = action === "add" ? { add: [path] } : { remove: [path], ...(action === "forget" ? { computer: true } : {}) };
|
|
296
|
+
await config.run(config.input.parse({ setting: "library", ...input }), context);
|
|
297
|
+
const after = libraryEntries(root, context).find((entry) => entry.used && samePath(entry.path, path)) !== undefined;
|
|
298
|
+
// The master hears only of a change to this campaign's library.
|
|
299
|
+
const news = before === after
|
|
300
|
+
? ""
|
|
301
|
+
: after
|
|
302
|
+
? `The player, on the dashboard, turned on ${path} in the campaign's library: ${libraryContents(context, path)}. Before you rule on what they cover, `
|
|
303
|
+
+ "search them with rules, even when you know the system's rule."
|
|
304
|
+
: `The player, on the dashboard, turned off ${path} in the campaign's library.`;
|
|
305
|
+
return { kind: "library", news };
|
|
306
|
+
});
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
* rpg-engine itself on the Packages page (D-515 (3)): its version, npm's latest and whether it is newer, and how it is installed, read at each look; its update,
|
|
310
|
+
* from the page alone, globally with npm as it was installed, a development link or another install told and never touched; then how the chat takes it.
|
|
311
|
+
*/
|
|
312
|
+
export async function engineNow(request, response, served) {
|
|
313
|
+
const updater = served.context.engine;
|
|
314
|
+
const version = runningVersion;
|
|
315
|
+
// Where nothing updates it, as in the demo, its version alone.
|
|
316
|
+
if (updater === undefined) {
|
|
317
|
+
sendJson(response, request.method === "GET" ? 200 : 400, request.method === "GET" ? { version } : { error: "Only the game's server, started by the chat, updates rpg-engine." });
|
|
318
|
+
return;
|
|
319
|
+
}
|
|
320
|
+
// What npm installed since this server started comes with a new chat: said apart, never as the version that runs.
|
|
321
|
+
const onDisk = updater.onDisk();
|
|
322
|
+
if (request.method === "GET") {
|
|
323
|
+
const [latest, installed] = await Promise.all([updater.latest(), updater.installed()]);
|
|
324
|
+
sendJson(response, 200, {
|
|
325
|
+
version,
|
|
326
|
+
...(onDisk === version ? {} : { installed: onDisk }),
|
|
327
|
+
...("failed" in latest ? { failed: latest.failed } : { latest: latest.version, update: isNewerVersion(latest.version, onDisk) }),
|
|
328
|
+
install: installed.how,
|
|
329
|
+
...("folder" in installed ? { folder: installed.folder } : {}),
|
|
330
|
+
...(served.packageWork === undefined ? {} : { working: served.packageWork }),
|
|
331
|
+
});
|
|
332
|
+
return;
|
|
333
|
+
}
|
|
334
|
+
const parsed = z.object({ action: z.literal("update") }).strict().safeParse(await readBody(request));
|
|
335
|
+
if (!parsed.success) {
|
|
336
|
+
sendJson(response, 400, { error: "Send what to do with rpg-engine: { action: update }." });
|
|
337
|
+
return;
|
|
338
|
+
}
|
|
339
|
+
await packageWork(response, served, "rpg-engine", "engine", async () => {
|
|
340
|
+
const latest = await updater.latest();
|
|
341
|
+
if ("failed" in latest) {
|
|
342
|
+
throw new Error(`${latest.failed}: update it once this computer is online. Nothing changed.`);
|
|
343
|
+
}
|
|
344
|
+
if (!isNewerVersion(latest.version, onDisk)) {
|
|
345
|
+
throw new Error(onDisk === version ? `rpg-engine ${version} is npm's latest: there is nothing to update.` : `rpg-engine ${onDisk} is installed already: it comes with a new chat.`);
|
|
346
|
+
}
|
|
347
|
+
const installed = await updater.installed();
|
|
348
|
+
if (installed.how !== "global") {
|
|
349
|
+
throw new Error(installed.how === "link"
|
|
350
|
+
? `rpg-engine here is a link to the folder ${installed.folder}, made by npm link for its development: update it there, with git pull and npm run build. Nothing changed.`
|
|
351
|
+
: `rpg-engine runs from ${installed.folder}, not from npm's global folder: update it the way it was installed. Nothing changed.`);
|
|
352
|
+
}
|
|
353
|
+
const why = await updater.update(latest.version);
|
|
354
|
+
if (why !== undefined) {
|
|
355
|
+
throw new Error(`rpg-engine could not be updated: ${why}. Nothing changed.`);
|
|
356
|
+
}
|
|
357
|
+
// The chat goes on with the server it started, and so does this page: the new engine comes with a new chat, or the app opened again.
|
|
358
|
+
const host = served.context.host?.() ?? "";
|
|
359
|
+
const restart = /codex|claude-ai|claude desktop/i.test(host) ? "app" : "chat";
|
|
360
|
+
return {
|
|
361
|
+
kind: "engine-updated",
|
|
362
|
+
news: `The player updated rpg-engine from ${version} to ${latest.version} on the dashboard: this chat goes on with ${version}, the new one comes with their next chat. Nothing to do now.`,
|
|
363
|
+
answer: { version: latest.version, restart },
|
|
364
|
+
};
|
|
365
|
+
});
|
|
366
|
+
}
|
|
367
|
+
/** What the page may add (D-485, D-486), from npm and GitHub, read again at most every ten minutes, or when the page asks it fresh. */
|
|
368
|
+
export async function catalogNow(response, served, fresh) {
|
|
369
|
+
const kept = served.catalog;
|
|
370
|
+
if (kept !== undefined && !fresh && served.context.now().getTime() - kept.at < catalogLife) {
|
|
371
|
+
sendJson(response, 200, kept.catalog);
|
|
372
|
+
return;
|
|
373
|
+
}
|
|
374
|
+
try {
|
|
375
|
+
await served.session.ready();
|
|
376
|
+
const read = await withFiles(served.session, () => catalog(requireCampaign(served.context.folder), served.context));
|
|
377
|
+
served.catalog = { at: served.context.now().getTime(), catalog: read };
|
|
378
|
+
sendJson(response, 200, read);
|
|
379
|
+
}
|
|
380
|
+
catch (error) {
|
|
381
|
+
sendJson(response, 400, { error: error instanceof Error ? error.message : String(error) });
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
/** The campaign exported as an adventure on the page (ADV-7), with the credits the player gives: the name of its file, which the page then downloads. */
|
|
385
|
+
export async function exportCampaign(request, response, served) {
|
|
386
|
+
const parsed = z.object({ author: z.string().trim().min(1).max(200).optional(), license: z.string().trim().min(1).max(200).optional() }).strict().safeParse(await readBody(request));
|
|
387
|
+
if (!parsed.success) {
|
|
388
|
+
sendJson(response, 400, { error: "Send the credits, if any: { author, license }." });
|
|
389
|
+
return;
|
|
390
|
+
}
|
|
391
|
+
try {
|
|
392
|
+
await served.session.ready();
|
|
393
|
+
const result = await withFiles(served.session, () => packageCommand.run(packageCommand.input.parse({ action: "export", ...parsed.data }), { ...served.context, actor: "player" }));
|
|
394
|
+
sendJson(response, 200, result.kind === "exported" ? { file: basename(result.file), pages: result.pages } : {});
|
|
395
|
+
}
|
|
396
|
+
catch (error) {
|
|
397
|
+
sendJson(response, 400, { error: error instanceof Error ? error.message : String(error) });
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
/** A zip of the campaign's exports/ folder, for the browser to save: by its name alone, never a path. */
|
|
401
|
+
export function exportedFile(response, served, name) {
|
|
402
|
+
const root = findCampaign(served.context.folder);
|
|
403
|
+
const path = root === undefined || basename(name) !== name || !/\.adventure\.zip$/i.test(name) ? undefined : join(root, exportsFolderName, name);
|
|
404
|
+
const bytes = path === undefined ? undefined : files().bytes(path);
|
|
405
|
+
if (bytes === undefined) {
|
|
406
|
+
send(response, 404, "text/plain; charset=utf-8", "There is no such export: export the campaign again.");
|
|
407
|
+
return;
|
|
408
|
+
}
|
|
409
|
+
response.writeHead(200, {
|
|
410
|
+
...securityHeaders,
|
|
411
|
+
"Content-Type": "application/zip",
|
|
412
|
+
"Content-Disposition": `attachment; filename*=UTF-8''${encodeURIComponent(name)}`,
|
|
413
|
+
"Cache-Control": "no-store",
|
|
414
|
+
});
|
|
415
|
+
response.end(bytes);
|
|
416
|
+
}
|
|
417
|
+
/** The extensions on this computer with their title and about in the campaign's language, where their words give them (D-502). */
|
|
418
|
+
function inLanguage(installed, served, language) {
|
|
419
|
+
return installed.map((one) => {
|
|
420
|
+
if (language === undefined || one.title === undefined) {
|
|
421
|
+
return one;
|
|
422
|
+
}
|
|
423
|
+
try {
|
|
424
|
+
const extension = findExtension(served.context.extensionFolders ?? [], one.package);
|
|
425
|
+
const words = extension === undefined || extension.language.split("-")[0] === language.split("-")[0] ? undefined : extensionWords(extension.folder, language);
|
|
426
|
+
return { ...one, ...(words?.title === undefined ? {} : { title: words.title }), ...(words?.about === undefined ? {} : { about: words.about }) };
|
|
427
|
+
}
|
|
428
|
+
catch {
|
|
429
|
+
return one;
|
|
430
|
+
}
|
|
431
|
+
});
|
|
432
|
+
}
|
|
433
|
+
/**
|
|
434
|
+
* One package's work on the page, one at a time (D-475): while it lasts, the page shows it and its phase, the player's yes waited for in a window of their
|
|
435
|
+
* computer among them (D-478); then the master hears of it, and the page has the kind the engine recognized, or what went wrong, with a code when the yes was not given.
|
|
436
|
+
*/
|
|
437
|
+
async function packageWork(response, served, name, action, work) {
|
|
438
|
+
if (served.packageWork !== undefined) {
|
|
439
|
+
sendJson(response, 409, { error: `${served.packageWork.name} is still being worked on: wait for it, then try again.`, code: "busy" });
|
|
440
|
+
return;
|
|
441
|
+
}
|
|
442
|
+
served.packageWork = { name, action, phase: "working" };
|
|
443
|
+
served.notify();
|
|
444
|
+
const phase = (now) => {
|
|
445
|
+
if (served.packageWork !== undefined) {
|
|
446
|
+
served.packageWork = { ...served.packageWork, phase: now };
|
|
447
|
+
served.notify();
|
|
448
|
+
}
|
|
449
|
+
};
|
|
450
|
+
const confirm = served.context.confirm;
|
|
451
|
+
// The page's player is asked in a window of their computer only: never the host's form, which the page cannot show, and never the page's click (D-477).
|
|
452
|
+
const context = {
|
|
453
|
+
...served.context,
|
|
454
|
+
actor: "player",
|
|
455
|
+
player: undefined,
|
|
456
|
+
// Never the terminal: a folder new to the library asks the yes in a window (D-477).
|
|
457
|
+
terminal: undefined,
|
|
458
|
+
// A no in a window holds for the session: a page, or a package's code in it, cannot make the window come back and back (D-510).
|
|
459
|
+
declined: served.declined,
|
|
460
|
+
...(confirm === undefined ? {} : {
|
|
461
|
+
confirm: {
|
|
462
|
+
ask: async (title, text, signal, answers) => {
|
|
463
|
+
phase("yes");
|
|
464
|
+
return await confirm.ask(title, text, signal, answers).finally(() => phase("working"));
|
|
465
|
+
},
|
|
466
|
+
},
|
|
467
|
+
}),
|
|
468
|
+
};
|
|
469
|
+
try {
|
|
470
|
+
await served.session.ready();
|
|
471
|
+
const done = await withFiles(served.session, () => work(context));
|
|
472
|
+
if (done.news !== "") {
|
|
473
|
+
served.events.push(done.news);
|
|
474
|
+
}
|
|
475
|
+
sendJson(response, 202, { kind: done.kind, ...done.answer });
|
|
476
|
+
}
|
|
477
|
+
catch (error) {
|
|
478
|
+
sendJson(response, 400, { error: error instanceof Error ? error.message : String(error), ...(error instanceof YesRefused ? { code: error.code } : {}) });
|
|
479
|
+
}
|
|
480
|
+
finally {
|
|
481
|
+
served.packageWork = undefined;
|
|
482
|
+
served.notify();
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
/** The kind of package a result of package install says it installed. */
|
|
486
|
+
function kindOf(result) {
|
|
487
|
+
return result === "adventure-installed" ? "adventure" : result === "system-installed" ? "system" : result === "language-installed" ? "language" : "extension";
|
|
488
|
+
}
|
|
489
|
+
/** A file's name as the page sends it, encoded for a header; as it is when it does not decode. */
|
|
490
|
+
function fileName(header) {
|
|
491
|
+
return decoded(header) ?? header;
|
|
492
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
|
-
import { type Context } from "
|
|
3
|
-
import { SessionStore } from "
|
|
2
|
+
import { type Context } from "../core/context.ts";
|
|
3
|
+
import { SessionStore } from "../core/session-store.ts";
|
|
4
4
|
/**
|
|
5
5
|
* The MCP server: every command becomes a tool with the same name, description and parameters, and answers with the same text as the command line. Its instructions send
|
|
6
6
|
* the host to instructions, then status. The commands that ask the player appear for a host that shows forms, through which they ask (D-148), and wherever the
|