mirror of
https://github.com/nexu-io/openmotion.git
synced 2026-12-06 23:47:48 +08:00
* feat(game-static-play): add 274-template R2 zip packaging, cookieless static play deploy, and verification pipeline * feat(game-skill): port 21-section OpenGame skill with dual-mode workflow and fast-play path * feat(onboarding): upgrade Cloud MCP install guide and add shared OpenGame prompt builders * feat(game-catalog): sync 274 official templates, 4 kits, downloads manifest, and game contract * feat(cloud-mcp): add read-only game catalog, free asset search, guest catalog API, redirects, and Docker packaging * feat(opengame): enable Stage 1 Game Studio routing, feature flags, and analytics * feat(opengame): add Stage 1 market, multi-client modal, Cursor HTTP fix, SuperAgent prompt, and i18n * fix(opengame): align nullable GameCardWithMeta fields and add opengame-catalog MCP capability * test(mcp-onboarding): update registered public tool count from 22 to 24 for Stage 1 game tools * chore(game-catalog): register 26 verified live R2 in-repo template bundles in game-downloads.json * fix(opengame): address Stage 1 review feedback and failing CI lanes - Send no play URL when GAME_PLAY_PUBLIC_ORIGIN is unset instead of a main-site path that no route serves; Studio falls back to bundled in-repo templates - Keep legacy-host 301 redirects on the configured origin for network-path inputs - Correct the BlenderKit page host in the asset search allowlist - Reuse the shared withdrawn list, TOP earning tag, curated order and comparator in Studio - Remove the unused shared prompt module; the shipped builders stay covered by Studio tests - Drop the blurred launch backdrop and the in-dialog copy notices in favour of Toasts - Describe the shipped read-only Game Studio boundary and 24-tool MCP contract in the architecture - Schedule the game skill and static play suites in CI and budget the three OpenGame events * fix(game-static-play): retry stalled template bundle downloads before failing the run * fix(game-asset-search): size the pagination cursor limit for every supported query A 200-unit query with non-ASCII, control or lone-surrogate characters produced a cursor longer than the 512-character limit, so nextCursor was rejected by both the decoder and the public schema. Share one limit derived from the worst-case JSON/base64url expansion and add a round-trip test for maximum-length queries. * fix(game-asset-search): accept BlenderKit pages on www.blendkit.com and guide licence checks www.blenderkit.com now redirects to www.blendkit.com and the upstream catalog returns that host, so requiring www.blenderkit.com dropped every BlenderKit result. Restore the live host, pin a real upstream row in tests, and tell Agents to confirm the licence on the source page when a source omits it. * fix(deploy): forward game play origin and legacy redirect hosts to the API deploy/.env.example and deploy/k8s/configmap.yaml declared GAME_PLAY_PUBLIC_ORIGIN and APP_REDIRECT_FROM_HOSTS, but neither the compose api service nor the reference api Deployment passed them to the process. Wire both and assert that every reference ConfigMap key is read by a workload. * Address review: keep legacy-host writes, enforce play-origin isolation, share catalog constants - Legacy-host redirects answer GET/HEAD with 301 and every other method with 308, so MCP and API writes keep their method and body. - parseConfig rejects a GAME_PLAY_PUBLIC_ORIGIN that is not https (loopback http excepted), carries a path, or shares or sits under the APP_PUBLIC_ORIGIN host. - The template id pattern, bundle key prefix, withdrawn set and TOP tag predicate live in shared/game-contract.ts; static play, deploy/verify scripts and the catalog service reuse them and the shared bundle URL builder. - Remove unused game-contract and model-catalog exports. - Update the MCP contract, AGENTS.md, README and docs to the 24-name phase-one surface and document the read-only OpenGame tools and guest catalog routes. * fix(game-static-play): make the full play-site upload resumable Upload through the S3 SDK instead of one aws CLI process per file, skip objects whose ETag already matches the local MD5, retry each request with backoff, and write assets before entry pages and the manifest. Give large bundle downloads time for a slow link. Record the provisioned bucket, domain and remaining header rule in the runbook. * feat(game-static-play): harden live play verification and add manual R2 publish workflow * fix(opengame): raise prompt/remix maxLength for >4k OG-13 test and reset notes on target change * fix(mcp): register resources/templates/list handler for Codex MCP compliance * chore(game-catalog): register uploaded tidebreaker bundle for 274/274 R2 CDN parity --------- Co-authored-by: heggria <bshengtao@gmail.com>
318 lines
12 KiB
TypeScript
318 lines
12 KiB
TypeScript
/**
|
|
* Game Studio contract shared by Studio (studio/src/motion/game), the local
|
|
* service (game-projects.ts), and the Cloud read-only Game Catalog API/MCP.
|
|
*
|
|
* Flow: pick genre / style / setting → one-line single-player brief → the Agent
|
|
* interviews, fixes a style formula, writes the game and validates it → the game
|
|
* is published to the game market where anyone can play it and remix it.
|
|
*/
|
|
|
|
export const gameGenres = ['shooter', 'platformer', 'story', 'casual', 'racing', 'horror'] as const;
|
|
export const gameStyles = ['pixel', 'minimal', 'ascii', 'voxel', 'anime', '3d'] as const;
|
|
export const gameSettings = ['medieval', 'cyberpunk', 'retro', 'modern', 'space', 'fantasy'] as const;
|
|
|
|
export const TOP_EARNING_GAME_TAG = 'TOP赚钱' as const;
|
|
/** Official template ids: directory names, bundle manifest keys and MCP/HTTP route parameters. */
|
|
export const GAME_TEMPLATE_ID_PATTERN = /^[a-zA-Z0-9][a-zA-Z0-9_-]{0,100}$/;
|
|
/** Release-bucket key prefix for immutable template zips (`<prefix><sha256>.zip`). */
|
|
export const GAME_BUNDLE_OBJECT_PREFIX = 'open-game/games/objects/';
|
|
|
|
// Keep withdrawn templates out of the catalogue, detail endpoints, MCP tools, and direct play routes.
|
|
export const WITHDRAWN_GAME_TEMPLATES: ReadonlySet<string> = new Set([
|
|
'school-tycoon-3d',
|
|
'arrow-pop-clear',
|
|
'shaman-block-pop',
|
|
]);
|
|
export const isListedGameTemplate = (id: string): boolean => !WITHDRAWN_GAME_TEMPLATES.has(id);
|
|
|
|
export function isTopEarningGameTags(tags?: readonly string[] | null): boolean {
|
|
if (!Array.isArray(tags)) return false;
|
|
return tags.some((tag) => typeof tag === 'string' && tag.trim().toLowerCase() === 'top赚钱');
|
|
}
|
|
|
|
export type GameGenre = typeof gameGenres[number];
|
|
export type GameStyle = typeof gameStyles[number];
|
|
export type GameSetting = typeof gameSettings[number];
|
|
|
|
/** Lifecycle of a game project. Only `published` games appear in Explore. */
|
|
export type GameStatus = 'draft' | 'building' | 'ready' | 'published' | 'failed';
|
|
|
|
export type GameBrief = {
|
|
prompt: string;
|
|
genre: GameGenre | null;
|
|
style: GameStyle | null;
|
|
setting: GameSetting | null;
|
|
multiplayer: boolean;
|
|
/** Screen shape the game is built for; portrait is a 9:16 phone layout. Defaults to landscape. */
|
|
orientation?: 'landscape' | 'portrait';
|
|
/** Portrait only: build a playable ad (instant play, hand tutorial, short levels, end card with a call to action) instead of a regular game. */
|
|
playableAd?: boolean;
|
|
};
|
|
|
|
export type GameCard = {
|
|
id: string;
|
|
title: string;
|
|
/** The workspace owner named the game explicitly. Keep it when the Agent revises the game. */
|
|
titleCustomized?: boolean;
|
|
description: string;
|
|
genre: GameGenre;
|
|
style: GameStyle | null;
|
|
setting: GameSetting | null;
|
|
multiplayer: boolean;
|
|
/** Max players per room; 1 for single-player games. */
|
|
maxPlayers: number;
|
|
/** Portrait games are built for a phone held upright (9:16); the stage shows them in a phone-shaped frame. */
|
|
orientation?: 'portrait' | 'landscape';
|
|
/** True when the game was built as a playable ad. */
|
|
playableAd?: boolean;
|
|
status: GameStatus;
|
|
/** Studio-relative or absolute URL of the cover image. */
|
|
cover: string | null;
|
|
/** URL that loads the playable game (an HTML page); `null` when no playable host is configured. */
|
|
playUrl: string | null;
|
|
/** Direct R2/CDN zip archive URL for official hosted templates, when available. */
|
|
bundleUrl?: string | null;
|
|
/** Expected SHA-256 hex digest of the zip archive, when hosted on CDN. */
|
|
bundleSha256?: string | null;
|
|
/** Expected byte length of the zip archive, when hosted on CDN. */
|
|
bundleBytes?: number | null;
|
|
/** True when the template carries the curated TOP赚钱 tag. */
|
|
topEarning?: boolean;
|
|
plays: number;
|
|
likes: number;
|
|
dislikes: number;
|
|
/** The current viewer's reaction and favourite state. */
|
|
reaction: -1 | 0 | 1;
|
|
favorite: boolean;
|
|
/** `template` games ship with OpenMotion; `mine` games were made in this workspace; `community` games are external links. */
|
|
source: 'template' | 'mine' | 'community';
|
|
/** Community games open on the creator's own site and cannot be remixed here. */
|
|
external?: { url: string; author: string; postUrl: string; model: string; embeddable: boolean } | null;
|
|
remixOf: string | null;
|
|
controls: string;
|
|
/** Optional per-locale title, description and controls shipped with the game (e.g. { 'zh-CN': { title, description } }). */
|
|
i18n?: Record<string, { title?: string; description?: string; controls?: string }>;
|
|
/** Optional featured curation tags (e.g. "TOP赚钱") exposed as visible card badges and market filters. */
|
|
tags?: string[];
|
|
/** Latest trailer job for this game, if one was started. */
|
|
trailer?: GameTrailer;
|
|
createdAt: string;
|
|
updatedAt: string;
|
|
};
|
|
|
|
/**
|
|
* Trailer pipeline: the server records gameplay headlessly, then composes a short trailer as an OpenMotion video
|
|
* project (title card from the cover, gameplay highlights, controls/invite end card) and renders an MP4.
|
|
* POST /api/games/:id/trailer starts or restarts it; GET /api/games/:id/trailer reads the latest job.
|
|
*/
|
|
export type GameTrailerStatus = 'recording' | 'composing' | 'rendering' | 'ready' | 'failed';
|
|
export type GameTrailer = {
|
|
status: GameTrailerStatus;
|
|
/** 0–1 overall progress, when known. */
|
|
progress?: number;
|
|
/** Served MP4 of the finished trailer (game-relative URL under /api/games/:id/play/). */
|
|
videoUrl?: string;
|
|
/** Raw gameplay clips recorded for the trailer. */
|
|
clips?: string[];
|
|
/** The OpenMotion video project, so the user can keep editing the trailer in the Motion editor. */
|
|
projectId?: string;
|
|
error?: string;
|
|
updatedAt: string;
|
|
};
|
|
|
|
/** Official starter / helper kit shipped under `templates/game-kits/`. */
|
|
export type GameKitSummary = {
|
|
id: 'arcade-2d' | 'coop-3d' | 'characters' | 'vendor';
|
|
title: string;
|
|
description: string;
|
|
license?: string;
|
|
files: string[];
|
|
baseUrl: string;
|
|
};
|
|
|
|
/** A game folder the catalog could not read (an interrupted create or a malformed game.json); the other games still load. */
|
|
export type GameCatalogIssue = { id: string; message: string };
|
|
export type GameCatalog = {
|
|
schemaVersion?: 1;
|
|
playOrigin?: string | null;
|
|
bundleBaseUrl?: string;
|
|
total?: number;
|
|
topEarningCount?: number;
|
|
games: GameCard[];
|
|
kits?: GameKitSummary[];
|
|
issues?: GameCatalogIssue[];
|
|
};
|
|
|
|
/** Optional metadata overrides applied when remixing an existing local game or template. */
|
|
export type GameRemixOptions = {
|
|
genre?: GameGenre | null;
|
|
style?: GameStyle | null;
|
|
setting?: GameSetting | null;
|
|
orientation?: 'landscape' | 'portrait' | null;
|
|
/** Promote a pristine built-in template copy straight to ready when no agent build turn follows. */
|
|
ready?: boolean;
|
|
};
|
|
|
|
/**
|
|
* Curated default display order for the Top-100 flagship TOP赚钱 mini-game templates when play counts are tied.
|
|
* Balances high-recognition viral genres across 20 rows (~5 screenfuls) so discovery leads with proven hits
|
|
* backed by upgraded full-bleed covers and hover preview clips instead of arbitrary A-Z folder names.
|
|
*/
|
|
export const CURATED_TOP_EARNING_ORDER: readonly string[] = [
|
|
// Tier 1 (Top 1–30): First-fold viral blockbusters & 3D showcase hits
|
|
'catch-goose-3d',
|
|
'plants-vs-zombies',
|
|
'archero-bow-legend',
|
|
'billiards-3d-pro',
|
|
'screw-puzzle',
|
|
'fruit-slash-frenzy',
|
|
'tile-stack',
|
|
'dream-kitchen-chef',
|
|
'watermelon-merge-3d',
|
|
'beach-soccer-pro',
|
|
'haunted-dorm-clash',
|
|
'big-hero-squad',
|
|
'backpack-hero',
|
|
'bear-dash-runner',
|
|
'arrow-out-3d',
|
|
'hoop-dunk-master',
|
|
'3d-mahjong',
|
|
'zuma-marble-blast',
|
|
'bus-queue-sort',
|
|
'heroes-tactics-war',
|
|
'block-blast',
|
|
'billiards-trick-shot',
|
|
'monkey-mart-idle',
|
|
'assault-duel-combat',
|
|
'parking-jam-hero',
|
|
'battle-cats-clash',
|
|
'knit-yarn-unravel',
|
|
'human-cannon-blast',
|
|
'dungeon-escape-horde',
|
|
'apex-drift-3d',
|
|
|
|
// Tier 2 (Top 31–65): High-recognition mini-game classics & second-fold hits
|
|
'save-the-dog',
|
|
'gold-miner',
|
|
'goods-sort-master',
|
|
'doomsday-survivor',
|
|
'supermarket-tycoon',
|
|
'sand-tetris',
|
|
'crowd-rush-3d',
|
|
'water-sort-puzzle',
|
|
'zombie-siege-3d',
|
|
'cut-the-rope-mini',
|
|
'rope-untangle-3d',
|
|
'knife-throw-frenzy',
|
|
'candy-match',
|
|
'dino-island-3d',
|
|
'jump-jump-3d',
|
|
'life-restart-sim',
|
|
'cube-chain-2048',
|
|
'drift-king-rush',
|
|
'yarn-sort-color',
|
|
'merge-plants-zombies',
|
|
'earn-100-million',
|
|
'chinese-chess-solo',
|
|
'car-klotski-3d',
|
|
'alien-sniper-3d',
|
|
'garden-makeover-match',
|
|
'mermaid-pin-rescue',
|
|
'blade-spin-survivor',
|
|
'blossom-bloom-match',
|
|
'five-star-clinic',
|
|
'flappy-pixel-bird',
|
|
'catch-piggy',
|
|
'happy-glass-draw',
|
|
'battle-cars-arena',
|
|
'my-burger-bistro',
|
|
'magic-tower-rpg',
|
|
|
|
// Tier 3 (Top 66–100): Polished 3D action, cozy tycoons, & evergreen puzzle/board staples
|
|
'gomoku-ai-pro',
|
|
'breakout-siege-3d',
|
|
'button-cut-200',
|
|
'kitty-snack-shop',
|
|
'hanzi-meme',
|
|
'corgi-dash-run',
|
|
'tetris-blast-boom',
|
|
'ace-archer-3d',
|
|
'doctor-sim-3d',
|
|
'classic-sudoku-pro',
|
|
'bullet-storm-horde',
|
|
'fruit-bubble-pop',
|
|
'piggy-escape-jam',
|
|
'master-chef-bistro',
|
|
'ludo-aero-chess',
|
|
'blade-clash-arena',
|
|
'lipstick-pin-hit',
|
|
'boba-tea-adventure',
|
|
'merge-tower-defense',
|
|
'fire-water-duo',
|
|
'tower-stack-3d',
|
|
'pinball-bricks-2999',
|
|
'monkey-dash-3d',
|
|
'ceo-comeback-sim',
|
|
'number-link-2248',
|
|
'catch-kitty-3d',
|
|
'pixel-air-strike',
|
|
'pipe-twist-flow',
|
|
'mahjong-kong-pop',
|
|
'master-hunter-3d',
|
|
'ring-stack-match',
|
|
'daily-drift-3d',
|
|
'ball-laser-bounce',
|
|
'imperial-palace-merge',
|
|
'one-stroke-dots',
|
|
];
|
|
|
|
const curatedOrderIndex = new Map(CURATED_TOP_EARNING_ORDER.map((id, index) => [id, index]));
|
|
|
|
/** Canonical catalog sort: published first, then play count descending, then curated flagship order, then id. */
|
|
export function compareGameCatalogOrder(
|
|
a: Pick<GameCard, 'id' | 'plays'> & { status?: GameStatus },
|
|
b: Pick<GameCard, 'id' | 'plays'> & { status?: GameStatus },
|
|
): number {
|
|
const pubDiff = Number(b.status === 'published') - Number(a.status === 'published');
|
|
if (pubDiff !== 0) return pubDiff;
|
|
const playDiff = (b.plays ?? 0) - (a.plays ?? 0);
|
|
if (playDiff !== 0) return playDiff;
|
|
const rankA = curatedOrderIndex.get(a.id) ?? Number.MAX_SAFE_INTEGER;
|
|
const rankB = curatedOrderIndex.get(b.id) ?? Number.MAX_SAFE_INTEGER;
|
|
if (rankA !== rankB) return rankA - rankB;
|
|
return a.id.localeCompare(b.id);
|
|
}
|
|
|
|
/** POST /api/games and POST /api/games/:id/remix return the new project and the Agent brief. */
|
|
export type GameCreated = { game: GameCard; agentInstruction: string };
|
|
/** GET /api/games/:id/handoff — the full instruction to give the user's Agent for a workspace draft. */
|
|
export type GameHandoff = { gameId: string; status: GameStatus; agentInstruction: string };
|
|
|
|
/**
|
|
* Server-authoritative multiplayer rules (logic.js). The room server calls these;
|
|
* the client only sends inputs (about 10 per second) and draws `viewFor` results.
|
|
* logic.js must be deterministic: no imports, no Math.random, no Date.now —
|
|
* use ctx.random() and ctx.now instead.
|
|
*/
|
|
export type GameLogicModule<State = unknown, Action = unknown, View = unknown> = {
|
|
meta: { minPlayers: number; maxPlayers: number; tickRate?: number };
|
|
setup(ctx: GameLogicContext, players: string[]): State;
|
|
validateAction(state: State, playerId: string, action: Action, ctx: GameLogicContext): boolean;
|
|
applyAction(state: State, playerId: string, action: Action, ctx: GameLogicContext): State;
|
|
isGameOver(state: State, ctx: GameLogicContext): { over: boolean; winners?: string[] };
|
|
viewFor(state: State, playerId: string, ctx: GameLogicContext): View;
|
|
};
|
|
|
|
export type GameLogicContext = { random(): number; now: number; tick: number };
|
|
|
|
/** Room socket: ws(s)://<host>/api/games/:id/rooms/:room */
|
|
export type RoomClientMessage =
|
|
| { type: 'join'; name?: string; /** Returned in 'joined'; reclaims the same player within 30 s after a refresh. */ reconnectToken?: string }
|
|
| { type: 'input'; action: unknown }
|
|
| { type: 'start' };
|
|
export type RoomServerMessage =
|
|
| { type: 'joined'; playerId: string; room: string; players: { id: string; name: string }[]; maxPlayers: number; reconnectToken: string }
|
|
| { type: 'state'; view: unknown; tick: number }
|
|
| { type: 'over'; winners?: string[] }
|
|
| { type: 'error'; message: string };
|