spriteforge 0.1.1__py3-none-any.whl
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.
- spriteforge/__init__.py +1 -0
- spriteforge/__main__.py +3 -0
- spriteforge/agents/__init__.py +0 -0
- spriteforge/agents/assets.py +109 -0
- spriteforge/agents/cancellation.py +12 -0
- spriteforge/agents/director.py +50 -0
- spriteforge/agents/models.py +63 -0
- spriteforge/agents/roles/art-director.md +15 -0
- spriteforge/agents/roles/art-reviewer.md +14 -0
- spriteforge/agents/roles/director.md +14 -0
- spriteforge/agents/roles/game-designer.md +15 -0
- spriteforge/agents/roles/level-tile-designer.md +16 -0
- spriteforge/agents/roles/librarian.md +13 -0
- spriteforge/agents/roles/menu-designer.md +15 -0
- spriteforge/agents/roles/pixel-artist.md +14 -0
- spriteforge/agents/roles/programmer.md +14 -0
- spriteforge/agents/roles/qa-playtester.md +13 -0
- spriteforge/agents/roles/sound-director.md +14 -0
- spriteforge/agents/roles.py +39 -0
- spriteforge/agents/router.py +233 -0
- spriteforge/agents/router_eval.py +145 -0
- spriteforge/agents/routing_state.py +133 -0
- spriteforge/agents/runtime.py +430 -0
- spriteforge/agents/workflow.py +389 -0
- spriteforge/app/__init__.py +0 -0
- spriteforge/app/agents_view.py +248 -0
- spriteforge/app/chat.py +114 -0
- spriteforge/app/extensions.py +115 -0
- spriteforge/app/index.html +279 -0
- spriteforge/app/local_only.py +49 -0
- spriteforge/app/server.py +358 -0
- spriteforge/app/static/assets/index-L2s1wlcp.css +1 -0
- spriteforge/app/static/assets/index-aBfzgLQl.js +71 -0
- spriteforge/app/static/assets/press-start-2p-latin-400-normal-BKfmdmKK.woff +0 -0
- spriteforge/app/static/assets/press-start-2p-latin-400-normal-xj9lRvVs.woff2 +0 -0
- spriteforge/app/static/index.html +13 -0
- spriteforge/app/static/press-start-2p-LICENSE.txt +93 -0
- spriteforge/app/studio.py +278 -0
- spriteforge/app/workers.py +73 -0
- spriteforge/cli.py +241 -0
- spriteforge/config.py +193 -0
- spriteforge/config.yaml +157 -0
- spriteforge/core/__init__.py +0 -0
- spriteforge/core/acting.py +16 -0
- spriteforge/core/cost.py +236 -0
- spriteforge/core/credentials.py +24 -0
- spriteforge/core/demo.py +79 -0
- spriteforge/core/forms.py +20 -0
- spriteforge/core/gates.py +175 -0
- spriteforge/core/security.py +42 -0
- spriteforge/core/state.py +222 -0
- spriteforge/core/team.py +15 -0
- spriteforge/core/usage.py +68 -0
- spriteforge/game/__init__.py +0 -0
- spriteforge/game/actors.py +377 -0
- spriteforge/game/agent_tools.py +178 -0
- spriteforge/game/art.py +2097 -0
- spriteforge/game/art_checks.py +190 -0
- spriteforge/game/art_review.py +518 -0
- spriteforge/game/build.py +134 -0
- spriteforge/game/bundle.py +1178 -0
- spriteforge/game/cli.py +119 -0
- spriteforge/game/codegen.py +433 -0
- spriteforge/game/codeinfo.py +154 -0
- spriteforge/game/dbsource.py +137 -0
- spriteforge/game/design.py +342 -0
- spriteforge/game/export.py +62 -0
- spriteforge/game/gamedb.py +191 -0
- spriteforge/game/image_cache.py +61 -0
- spriteforge/game/lessons.py +259 -0
- spriteforge/game/level_gen.py +118 -0
- spriteforge/game/level_preview.py +97 -0
- spriteforge/game/levels.py +934 -0
- spriteforge/game/loops.py +38 -0
- spriteforge/game/menus.py +712 -0
- spriteforge/game/mock_game.js +109 -0
- spriteforge/game/mock_platformer.js +58 -0
- spriteforge/game/motion.py +881 -0
- spriteforge/game/pipeline.py +1768 -0
- spriteforge/game/plan.py +502 -0
- spriteforge/game/playtest.py +318 -0
- spriteforge/game/qa.py +664 -0
- spriteforge/game/qa_checks.py +223 -0
- spriteforge/game/qa_runtime.py +565 -0
- spriteforge/game/reach.py +807 -0
- spriteforge/game/record.py +138 -0
- spriteforge/game/research.py +262 -0
- spriteforge/game/revision.py +225 -0
- spriteforge/game/sdk/API.md +104 -0
- spriteforge/game/sdk/FLOW.md +19 -0
- spriteforge/game/sdk/LEVELS.md +65 -0
- spriteforge/game/sdk/sf.js +418 -0
- spriteforge/game/sdk/sfflow.js +442 -0
- spriteforge/game/sdk/sflevel.js +683 -0
- spriteforge/game/sdk/sfsound-editor.js +225 -0
- spriteforge/game/sdk/sfsound.js +260 -0
- spriteforge/game/sdk/sounds.html +67 -0
- spriteforge/game/sounds.py +793 -0
- spriteforge/game/story.py +188 -0
- spriteforge/game/structure.py +98 -0
- spriteforge/game/team_reports.py +394 -0
- spriteforge/game/tilesets.py +70 -0
- spriteforge/game/title_art.py +186 -0
- spriteforge/genres/__init__.py +0 -0
- spriteforge/library/__init__.py +15 -0
- spriteforge/library/cli.py +126 -0
- spriteforge/library/describe.py +242 -0
- spriteforge/library/looks.py +154 -0
- spriteforge/library/models.py +79 -0
- spriteforge/library/store.py +422 -0
- spriteforge/library/tilesets/README.md +32 -0
- spriteforge/library/tilesets/gandalf-seasons.json +111 -0
- spriteforge/library/tilesets/pixel-crawler-dungeon.json +66 -0
- spriteforge/mcp/__init__.py +0 -0
- spriteforge/mcp/cli.py +58 -0
- spriteforge/mcp/client.py +57 -0
- spriteforge/mcp/filesystem_read.py +32 -0
- spriteforge/mcp/gamedb.py +56 -0
- spriteforge/mcp/library.py +179 -0
- spriteforge/mcp/memory.py +37 -0
- spriteforge/mcp/pixel_tools.py +145 -0
- spriteforge/mcp/registry.py +145 -0
- spriteforge/mcp/service.py +224 -0
- spriteforge/mcp/templates/context7.json +6 -0
- spriteforge/mcp/templates/fetch.json +6 -0
- spriteforge/mcp/templates/filesystem-read.json +6 -0
- spriteforge/mcp/templates/pixel-tools.json +6 -0
- spriteforge/memory/README.md +10 -0
- spriteforge/memory/__init__.py +0 -0
- spriteforge/memory/cli.py +131 -0
- spriteforge/memory/okf/__init__.py +1 -0
- spriteforge/memory/okf/catalog.py +331 -0
- spriteforge/memory/okf/codec.py +63 -0
- spriteforge/memory/okf/git.py +104 -0
- spriteforge/memory/okf/indexes.py +50 -0
- spriteforge/memory/okf/models.py +114 -0
- spriteforge/memory/okf/search.py +53 -0
- spriteforge/memory/okf/seed.py +81 -0
- spriteforge/memory/okf/seeds/genres.yaml +121 -0
- spriteforge/memory/okf/seeds/other.yaml +150 -0
- spriteforge/memory/okf/store.py +402 -0
- spriteforge/memory/okf/validate.py +115 -0
- spriteforge/pixel/__init__.py +17 -0
- spriteforge/pixel/atlas.py +110 -0
- spriteforge/pixel/grid.py +174 -0
- spriteforge/pixel/palette.py +156 -0
- spriteforge/pixel/palettes/dungeon.json +9 -0
- spriteforge/pixel/postprocess.py +170 -0
- spriteforge/pixel/preview.py +40 -0
- spriteforge/pixel/schemas.py +139 -0
- spriteforge/pixel/source.py +237 -0
- spriteforge/pixel/terrain.py +48 -0
- spriteforge/pixel/validate.py +138 -0
- spriteforge/prompts/anim_frame.txt +1 -0
- spriteforge/prompts/character.txt +1 -0
- spriteforge/prompts/item.txt +1 -0
- spriteforge/prompts/tile.txt +1 -0
- spriteforge/prompts/ui.txt +1 -0
- spriteforge/providers/__init__.py +0 -0
- spriteforge/providers/base.py +97 -0
- spriteforge/providers/http.py +38 -0
- spriteforge/providers/mock.py +111 -0
- spriteforge/providers/muse_image.py +60 -0
- spriteforge/providers/muse_search.py +91 -0
- spriteforge/providers/muse_spark.py +66 -0
- spriteforge/skills/__init__.py +0 -0
- spriteforge/skills/builtin/LICENSE-awesome-gamedev-agent-skills.txt +201 -0
- spriteforge/skills/builtin/NOTICE-awesome-gamedev-agent-skills.txt +15 -0
- spriteforge/skills/builtin/THIRD_PARTY.md +21 -0
- spriteforge/skills/builtin/audio-design/SKILL.md +190 -0
- spriteforge/skills/builtin/game-feel/SKILL.md +174 -0
- spriteforge/skills/builtin/game-ui-ux/SKILL.md +167 -0
- spriteforge/skills/builtin/level-design/SKILL.md +169 -0
- spriteforge/skills/builtin/phaser-arcade-physics/SKILL.md +17 -0
- spriteforge/skills/builtin/physics-tuning/SKILL.md +164 -0
- spriteforge/skills/builtin/pixel-art-prompting/SKILL.md +12 -0
- spriteforge/skills/builtin/platformer/SKILL.md +153 -0
- spriteforge/skills/builtin/puzzle/SKILL.md +143 -0
- spriteforge/skills/builtin/sprite-animation-frames/SKILL.md +11 -0
- spriteforge/skills/builtin/tileset-design/SKILL.md +10 -0
- spriteforge/skills/catalog.py +200 -0
- spriteforge/skills/cli.py +41 -0
- spriteforge/stages/__init__.py +0 -0
- spriteforge/stages/asset_context.py +301 -0
- spriteforge/stages/asset_models.py +192 -0
- spriteforge/stages/asset_render.py +366 -0
- spriteforge/stages/asset_review.py +140 -0
- spriteforge/stages/asset_store.py +94 -0
- spriteforge/stages/chat_changes.py +236 -0
- spriteforge/stages/concept.py +42 -0
- spriteforge/stages/game.py +1699 -0
- spriteforge/stages/game_confirm.py +112 -0
- spriteforge/stages/game_final.py +220 -0
- spriteforge/stages/game_record.py +246 -0
- spriteforge/stages/gameplay.py +218 -0
- spriteforge/stages/intake.py +372 -0
- spriteforge/stages/preview_assets.py +212 -0
- spriteforge/stages/preview_models.py +167 -0
- spriteforge/stages/preview_render.py +169 -0
- spriteforge/stages/preview_repair.py +61 -0
- spriteforge/stages/preview_review.py +169 -0
- spriteforge/stages/production.py +170 -0
- spriteforge/stages/references.py +105 -0
- spriteforge/stages/rewind.py +128 -0
- spriteforge/stages/workflow.py +440 -0
- spriteforge/templates/phaser/audit.js +45 -0
- spriteforge/templates/phaser/font.png +0 -0
- spriteforge/templates/phaser/font.xml +1 -0
- spriteforge/templates/phaser/preview.html +9 -0
- spriteforge/templates/phaser/room.js +49 -0
- spriteforge/templates/phaser/vendor/LICENSE.md +20 -0
- spriteforge/templates/phaser/vendor/phaser.min.js +1 -0
- spriteforge-0.1.1.dist-info/METADATA +364 -0
- spriteforge-0.1.1.dist-info/RECORD +218 -0
- spriteforge-0.1.1.dist-info/WHEEL +5 -0
- spriteforge-0.1.1.dist-info/entry_points.txt +2 -0
- spriteforge-0.1.1.dist-info/licenses/LICENSE +27 -0
- spriteforge-0.1.1.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
6
|
+
<title>SpriteForge Studio</title>
|
|
7
|
+
<script type="module" crossorigin src="/assets/index-aBfzgLQl.js"></script>
|
|
8
|
+
<link rel="stylesheet" crossorigin href="/assets/index-L2s1wlcp.css">
|
|
9
|
+
</head>
|
|
10
|
+
<body>
|
|
11
|
+
<div id="root"></div>
|
|
12
|
+
</body>
|
|
13
|
+
</html>
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
Copyright 2012 The Press Start 2P Project Authors (cody@zone38.net), with Reserved Font Name "Press Start 2P"
|
|
2
|
+
|
|
3
|
+
This Font Software is licensed under the SIL Open Font License, Version 1.1.
|
|
4
|
+
This license is copied below, and is also available with a FAQ at:
|
|
5
|
+
http://scripts.sil.org/OFL
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
-----------------------------------------------------------
|
|
9
|
+
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
|
|
10
|
+
-----------------------------------------------------------
|
|
11
|
+
|
|
12
|
+
PREAMBLE
|
|
13
|
+
The goals of the Open Font License (OFL) are to stimulate worldwide
|
|
14
|
+
development of collaborative font projects, to support the font creation
|
|
15
|
+
efforts of academic and linguistic communities, and to provide a free and
|
|
16
|
+
open framework in which fonts may be shared and improved in partnership
|
|
17
|
+
with others.
|
|
18
|
+
|
|
19
|
+
The OFL allows the licensed fonts to be used, studied, modified and
|
|
20
|
+
redistributed freely as long as they are not sold by themselves. The
|
|
21
|
+
fonts, including any derivative works, can be bundled, embedded,
|
|
22
|
+
redistributed and/or sold with any software provided that any reserved
|
|
23
|
+
names are not used by derivative works. The fonts and derivatives,
|
|
24
|
+
however, cannot be released under any other type of license. The
|
|
25
|
+
requirement for fonts to remain under this license does not apply
|
|
26
|
+
to any document created using the fonts or their derivatives.
|
|
27
|
+
|
|
28
|
+
DEFINITIONS
|
|
29
|
+
"Font Software" refers to the set of files released by the Copyright
|
|
30
|
+
Holder(s) under this license and clearly marked as such. This may
|
|
31
|
+
include source files, build scripts and documentation.
|
|
32
|
+
|
|
33
|
+
"Reserved Font Name" refers to any names specified as such after the
|
|
34
|
+
copyright statement(s).
|
|
35
|
+
|
|
36
|
+
"Original Version" refers to the collection of Font Software components as
|
|
37
|
+
distributed by the Copyright Holder(s).
|
|
38
|
+
|
|
39
|
+
"Modified Version" refers to any derivative made by adding to, deleting,
|
|
40
|
+
or substituting -- in part or in whole -- any of the components of the
|
|
41
|
+
Original Version, by changing formats or by porting the Font Software to a
|
|
42
|
+
new environment.
|
|
43
|
+
|
|
44
|
+
"Author" refers to any designer, engineer, programmer, technical
|
|
45
|
+
writer or other person who contributed to the Font Software.
|
|
46
|
+
|
|
47
|
+
PERMISSION & CONDITIONS
|
|
48
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
49
|
+
a copy of the Font Software, to use, study, copy, merge, embed, modify,
|
|
50
|
+
redistribute, and sell modified and unmodified copies of the Font
|
|
51
|
+
Software, subject to the following conditions:
|
|
52
|
+
|
|
53
|
+
1) Neither the Font Software nor any of its individual components,
|
|
54
|
+
in Original or Modified Versions, may be sold by itself.
|
|
55
|
+
|
|
56
|
+
2) Original or Modified Versions of the Font Software may be bundled,
|
|
57
|
+
redistributed and/or sold with any software, provided that each copy
|
|
58
|
+
contains the above copyright notice and this license. These can be
|
|
59
|
+
included either as stand-alone text files, human-readable headers or
|
|
60
|
+
in the appropriate machine-readable metadata fields within text or
|
|
61
|
+
binary files as long as those fields can be easily viewed by the user.
|
|
62
|
+
|
|
63
|
+
3) No Modified Version of the Font Software may use the Reserved Font
|
|
64
|
+
Name(s) unless explicit written permission is granted by the corresponding
|
|
65
|
+
Copyright Holder. This restriction only applies to the primary font name as
|
|
66
|
+
presented to the users.
|
|
67
|
+
|
|
68
|
+
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
|
|
69
|
+
Software shall not be used to promote, endorse or advertise any
|
|
70
|
+
Modified Version, except to acknowledge the contribution(s) of the
|
|
71
|
+
Copyright Holder(s) and the Author(s) or with their explicit written
|
|
72
|
+
permission.
|
|
73
|
+
|
|
74
|
+
5) The Font Software, modified or unmodified, in part or in whole,
|
|
75
|
+
must be distributed entirely under this license, and must not be
|
|
76
|
+
distributed under any other license. The requirement for fonts to
|
|
77
|
+
remain under this license does not apply to any document created
|
|
78
|
+
using the Font Software.
|
|
79
|
+
|
|
80
|
+
TERMINATION
|
|
81
|
+
This license becomes null and void if any of the above conditions are
|
|
82
|
+
not met.
|
|
83
|
+
|
|
84
|
+
DISCLAIMER
|
|
85
|
+
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
86
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
|
|
87
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
|
|
88
|
+
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
|
|
89
|
+
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
90
|
+
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
|
|
91
|
+
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
92
|
+
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
|
|
93
|
+
OTHER DEALINGS IN THE FONT SOFTWARE.
|
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
"""The studio's API: projects (runs started from a first message), the agents of a run, each
|
|
2
|
+
agent's thread and chat messages. Gates, artifacts, events and play stay in server.py."""
|
|
3
|
+
|
|
4
|
+
import asyncio
|
|
5
|
+
import json
|
|
6
|
+
import os
|
|
7
|
+
import re
|
|
8
|
+
from functools import cache
|
|
9
|
+
|
|
10
|
+
from fastapi import APIRouter, File, Form, HTTPException, UploadFile
|
|
11
|
+
from pydantic import BaseModel, Field
|
|
12
|
+
|
|
13
|
+
from spriteforge.agents.workflow import WORKFLOW as AGENT_WORKFLOW
|
|
14
|
+
from spriteforge.config import Config
|
|
15
|
+
from spriteforge.core.cost import BudgetExceeded
|
|
16
|
+
from spriteforge.core.gates import Gates
|
|
17
|
+
from spriteforge.core.security import redact
|
|
18
|
+
from spriteforge.core.state import Store
|
|
19
|
+
from spriteforge.core.usage import usage_report
|
|
20
|
+
from spriteforge.stages.chat_changes import file_change, for_gate
|
|
21
|
+
from spriteforge.stages.references import MAX_BYTES, ReferenceError, add_reference, references
|
|
22
|
+
from spriteforge.stages.rewind import LATE, request_stop, round_info
|
|
23
|
+
from spriteforge.stages.workflow import WORKFLOW as INTAKE
|
|
24
|
+
|
|
25
|
+
from .agents_view import AGENTS, actor, summarize, thread
|
|
26
|
+
from .chat import Intent, answer_question, classify
|
|
27
|
+
from .workers import FINAL, Workers
|
|
28
|
+
|
|
29
|
+
# Runs with human gates are projects; the rest are tools (memory audits, evals, CLI builds).
|
|
30
|
+
PROJECT_WORKFLOWS = {INTAKE, AGENT_WORKFLOW}
|
|
31
|
+
# Project card picture, best first: the build's poster, its title screen, the art sheet.
|
|
32
|
+
THUMBNAILS = [r"game/v(\d+)/poster\.png", r"game/v(\d+)/menus/title\.png", r"game/v(\d+)/art\.png",
|
|
33
|
+
r"concept/v(\d+)\.png", r"preview/v(\d+)/gameplay-4x\.png"] # fmt: skip
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
class NewProject(BaseModel):
|
|
37
|
+
text: str = Field(min_length=1, max_length=10000)
|
|
38
|
+
mock: bool = False
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
class Stop(BaseModel):
|
|
42
|
+
change: int # the chat change (its chat.user event id) the Go back card is about
|
|
43
|
+
later: bool = False # Queue for later: apply it at the next gate instead
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
class ChatMessage(BaseModel):
|
|
47
|
+
text: str = Field(min_length=1, max_length=4000)
|
|
48
|
+
attachments: list[str] = Field(default_factory=list) # reference ids (phase 4)
|
|
49
|
+
intent: Intent | None = None # None: classified; the user can override a wrong guess
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
@cache
|
|
53
|
+
def chromium_installed() -> bool:
|
|
54
|
+
"""Playwright's Chromium plays and checks every build; checked once per process."""
|
|
55
|
+
from playwright.sync_api import sync_playwright
|
|
56
|
+
|
|
57
|
+
try:
|
|
58
|
+
with sync_playwright() as p:
|
|
59
|
+
return os.path.exists(p.chromium.executable_path)
|
|
60
|
+
except Exception: # noqa: BLE001 -- any failure here means "not usable"
|
|
61
|
+
return False
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def project(store: Store, run, busy: bool) -> dict:
|
|
65
|
+
with store.connect() as db:
|
|
66
|
+
created = db.execute(
|
|
67
|
+
"SELECT timestamp FROM events WHERE run_id=? ORDER BY id LIMIT 1", (run.id,)
|
|
68
|
+
).fetchone()
|
|
69
|
+
images = db.execute(
|
|
70
|
+
"SELECT id,name FROM artifacts WHERE run_id=? AND mime LIKE 'image/%'", (run.id,)
|
|
71
|
+
).fetchall()
|
|
72
|
+
designs = db.execute(
|
|
73
|
+
"SELECT name,data FROM artifacts WHERE run_id=? AND name GLOB 'game/design/v*.json'",
|
|
74
|
+
(run.id,),
|
|
75
|
+
).fetchall()
|
|
76
|
+
thumbnail = None
|
|
77
|
+
for pattern in THUMBNAILS:
|
|
78
|
+
found = [(int(m[1]), r["id"]) for r in images if (m := re.fullmatch(pattern, r["name"]))]
|
|
79
|
+
if found:
|
|
80
|
+
thumbnail = max(found)[1]
|
|
81
|
+
break
|
|
82
|
+
title = None
|
|
83
|
+
versions = [(int(m[1]), r["data"]) for r in designs
|
|
84
|
+
if (m := re.fullmatch(r"game/design/v(\d+)\.json", r["name"]))] # fmt: skip
|
|
85
|
+
if versions:
|
|
86
|
+
title = json.loads(max(versions)[1]).get("title")
|
|
87
|
+
goal = " ".join(str(run.config.get("goal") or "").split())
|
|
88
|
+
gate = Gates(store).pending(run.id)
|
|
89
|
+
return {
|
|
90
|
+
"id": run.id,
|
|
91
|
+
"title": title or (goal[:80] + "…" if len(goal) > 80 else goal) or "Untitled game",
|
|
92
|
+
"idea": goal,
|
|
93
|
+
"status": run.status,
|
|
94
|
+
"workflow": run.config.get("workflow"),
|
|
95
|
+
"mock": bool(run.config.get("mock")),
|
|
96
|
+
"created": created[0] if created else None,
|
|
97
|
+
"cost": round(usage_report(store, run.id).known_estimated_cost, 4),
|
|
98
|
+
"thumbnail": thumbnail,
|
|
99
|
+
"gate": {"id": gate.id, "title": gate.title, "stage": gate.stage} if gate else None,
|
|
100
|
+
"busy": busy,
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
def agent_cap(run) -> float | None:
|
|
105
|
+
"""Each agent's allowance since the human's last action (None: the run's caps are per run)."""
|
|
106
|
+
budget = run.config.get("budget") or {}
|
|
107
|
+
return budget.get("max_agent_cost", 10) if budget.get("per_request") else None
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
def studio_router(store: Store, workers: Workers, cfg: Config) -> APIRouter:
|
|
111
|
+
api = APIRouter(prefix="/api")
|
|
112
|
+
|
|
113
|
+
def require_run(id):
|
|
114
|
+
try:
|
|
115
|
+
return store.get_run(id)
|
|
116
|
+
except KeyError:
|
|
117
|
+
raise HTTPException(404, "Run not found") from None
|
|
118
|
+
|
|
119
|
+
def require_agent(name):
|
|
120
|
+
if name not in AGENTS:
|
|
121
|
+
raise HTTPException(404, "Unknown agent")
|
|
122
|
+
return name
|
|
123
|
+
|
|
124
|
+
@api.get("/setup")
|
|
125
|
+
async def setup():
|
|
126
|
+
"""The first-run check: what live mode needs, in plain words."""
|
|
127
|
+
return {
|
|
128
|
+
"meta_api_key": bool(os.environ.get("META_API_KEY")),
|
|
129
|
+
"chromium": await asyncio.to_thread(chromium_installed),
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
@api.get("/projects")
|
|
133
|
+
def projects():
|
|
134
|
+
runs = [r for r in store.runs() if r.config.get("workflow") in PROJECT_WORKFLOWS]
|
|
135
|
+
return {"projects": [project(store, r, workers.busy(r.id)) for r in runs]}
|
|
136
|
+
|
|
137
|
+
@api.post("/projects", status_code=201)
|
|
138
|
+
async def create(body: NewProject):
|
|
139
|
+
from spriteforge.stages.workflow import start_run
|
|
140
|
+
|
|
141
|
+
if not body.mock and not os.environ.get("META_API_KEY"):
|
|
142
|
+
raise HTTPException(
|
|
143
|
+
409, "No META_API_KEY is set, so Muse cannot be called. Add your key to .env "
|
|
144
|
+
"and restart, or try offline (mock)."
|
|
145
|
+
) # fmt: skip
|
|
146
|
+
run = await asyncio.to_thread(start_run, store, cfg, mock=body.mock, goal=body.text)
|
|
147
|
+
store.append_event(run.id, "Human", "chat.user", {"to": "Director", "text": body.text,
|
|
148
|
+
"intent": "idea"}) # fmt: skip
|
|
149
|
+
workers.start(run.id)
|
|
150
|
+
return project(store, store.get_run(run.id), workers.busy(run.id))
|
|
151
|
+
|
|
152
|
+
@api.get("/runs/{id}/project")
|
|
153
|
+
def one(id: str):
|
|
154
|
+
return project(store, require_run(id), workers.busy(id))
|
|
155
|
+
|
|
156
|
+
@api.post("/runs/{id}/resume")
|
|
157
|
+
async def resume(id: str): # async: the worker task needs the server's event loop
|
|
158
|
+
"""Carry on a run whose worker is not running (the studio restarted mid-step, or the
|
|
159
|
+
run failed): the step functions continue from the durable checkpoint."""
|
|
160
|
+
run = require_run(id)
|
|
161
|
+
if run.status == "failed" and run.config.get("workflow") == INTAKE:
|
|
162
|
+
store.retry_failed(id)
|
|
163
|
+
elif run.status == "budget_exhausted": # Continue: a fresh allowance (cost policy)
|
|
164
|
+
store.continue_run(id)
|
|
165
|
+
elif run.status in FINAL:
|
|
166
|
+
raise HTTPException(409, f"This project is {run.status.replace('_', ' ')}")
|
|
167
|
+
return {"started": workers.start(id)}
|
|
168
|
+
|
|
169
|
+
@api.get("/runs/{id}/agents")
|
|
170
|
+
def agents(id: str):
|
|
171
|
+
run = require_run(id)
|
|
172
|
+
# A finished run's worker may still be returning from its last step: not busy.
|
|
173
|
+
busy = workers.busy(id) and run.status not in FINAL
|
|
174
|
+
gate = Gates(store).pending(id)
|
|
175
|
+
from .server import latest_play
|
|
176
|
+
|
|
177
|
+
with store.connect() as db:
|
|
178
|
+
last = db.execute("SELECT MAX(id) FROM events WHERE run_id=?", (id,)).fetchone()[0]
|
|
179
|
+
return {
|
|
180
|
+
"agents": [a.model_dump() for a in summarize(store, id, busy)],
|
|
181
|
+
"last_event": last or 0, # the event stream continues from here
|
|
182
|
+
"play": latest_play(store, id),
|
|
183
|
+
"status": run.status,
|
|
184
|
+
"busy": busy,
|
|
185
|
+
"gate": gate.model_dump(mode="json") if gate else None,
|
|
186
|
+
"queued": for_gate(store, id), # chat changes the open gate's Request changes applies
|
|
187
|
+
"agent_cap": agent_cap(run),
|
|
188
|
+
"error": workers.errors.get(id),
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
@api.get("/runs/{id}/agents/{agent:path}/thread")
|
|
192
|
+
def agent_thread(id: str, agent: str, after: int = 0):
|
|
193
|
+
require_run(id)
|
|
194
|
+
return {"items": thread(store, id, require_agent(agent), after)}
|
|
195
|
+
|
|
196
|
+
@api.post("/runs/{id}/agents/{agent:path}/messages", status_code=201)
|
|
197
|
+
async def message(id: str, agent: str, body: ChatMessage):
|
|
198
|
+
require_run(id)
|
|
199
|
+
require_agent(agent)
|
|
200
|
+
intent = body.intent or classify(body.text)
|
|
201
|
+
cursor = max((e.id for e in store.events(id)), default=0)
|
|
202
|
+
user = {"to": agent, "text": body.text, "intent": intent}
|
|
203
|
+
if intent == "change":
|
|
204
|
+
# Filed under the agent's Revision slot; the gated pipeline applies it (chat_changes).
|
|
205
|
+
fields, reply = await asyncio.to_thread(file_change, store, id, agent, body.text)
|
|
206
|
+
store.append_event(id, "Human", "chat.user", {**user, **fields})
|
|
207
|
+
answer = {"text": reply, "intent": "change"}
|
|
208
|
+
info = round_info(store, id) if fields.get("slot") and workers.busy(id) else None
|
|
209
|
+
if info:
|
|
210
|
+
answer = await asyncio.to_thread(go_back_offer, id, agent, fields["slot"], info)
|
|
211
|
+
store.append_event(id, agent, "chat.agent", answer)
|
|
212
|
+
else:
|
|
213
|
+
store.append_event(id, "Human", "chat.user", user)
|
|
214
|
+
try:
|
|
215
|
+
reply = {"text": await asyncio.to_thread(answer_question, store, id, agent,
|
|
216
|
+
body.text)} # fmt: skip
|
|
217
|
+
except BudgetExceeded as exc:
|
|
218
|
+
reply = {"text": f"I can't answer now: {exc}.", "error": True}
|
|
219
|
+
except Exception as exc: # noqa: BLE001 -- the reason is shown, scrubbed
|
|
220
|
+
reply = {"text": "I couldn't answer: " + redact(str(exc))[:300], "error": True}
|
|
221
|
+
store.append_event(id, agent, "chat.agent", {**reply, "intent": "question"})
|
|
222
|
+
return {"items": thread(store, id, agent, cursor)}
|
|
223
|
+
|
|
224
|
+
def go_back_offer(id: str, agent: str, slot: str, info: dict) -> dict:
|
|
225
|
+
"""A change asked while a round of work runs: the agent's reply, with the Go back card
|
|
226
|
+
when the change concerns work this round already did (or is doing)."""
|
|
227
|
+
events = store.events(id, info["start"])
|
|
228
|
+
change = max(e.id for e in events if e.type == "chat.user")
|
|
229
|
+
build = f"build v{info['build']}" if info["build"] else "this round"
|
|
230
|
+
if slot in LATE and not any(actor(e) == agent for e in events):
|
|
231
|
+
return {"text": f"Noted: I'll use it when I get to it in {build}. Nothing stops.",
|
|
232
|
+
"intent": "change"} # fmt: skip
|
|
233
|
+
working = next((a.name for a in summarize(store, id, True) if a.status == "working"),
|
|
234
|
+
"Director") # fmt: skip
|
|
235
|
+
return {
|
|
236
|
+
"text": f"This stops the {working} ({build}, ${info['cost']:.2f} so far) and goes "
|
|
237
|
+
f"back to the {agent}, so no more is spent on work this change replaces.",
|
|
238
|
+
"intent": "change",
|
|
239
|
+
"rewind": {"change": change, "round": info["round"], "working": working,
|
|
240
|
+
"build": info["build"], "cost": info["cost"]},
|
|
241
|
+
} # fmt: skip
|
|
242
|
+
|
|
243
|
+
@api.get("/runs/{id}/references")
|
|
244
|
+
def list_references(id: str):
|
|
245
|
+
require_run(id)
|
|
246
|
+
return {"references": references(store, id)}
|
|
247
|
+
|
|
248
|
+
@api.post("/runs/{id}/references", status_code=201)
|
|
249
|
+
async def upload_reference(id: str, file: UploadFile = File(...), agent: str = Form(...),
|
|
250
|
+
rights: bool = Form(False)): # fmt: skip
|
|
251
|
+
"""A reference image for one agent (the Director: every agent), stored locked once the
|
|
252
|
+
human confirms they may use it (stages/references.py)."""
|
|
253
|
+
require_run(id)
|
|
254
|
+
require_agent(agent)
|
|
255
|
+
data = await file.read(MAX_BYTES + 1)
|
|
256
|
+
try:
|
|
257
|
+
ref = await asyncio.to_thread(add_reference, store, id, agent, file.filename or "",
|
|
258
|
+
data, rights) # fmt: skip
|
|
259
|
+
except ReferenceError as exc:
|
|
260
|
+
raise HTTPException(400, str(exc)) from None
|
|
261
|
+
return ref
|
|
262
|
+
|
|
263
|
+
@api.post("/runs/{id}/stop")
|
|
264
|
+
def stop(id: str, body: Stop):
|
|
265
|
+
"""The Go back card's answer: stop the round now (the worker rewinds it with every
|
|
266
|
+
queued change) or keep the change queued for the next gate."""
|
|
267
|
+
require_run(id)
|
|
268
|
+
if body.later:
|
|
269
|
+
store.append_event(id, "Human", "rewind.declined", {"change": body.change})
|
|
270
|
+
return {"stopping": False}
|
|
271
|
+
info = round_info(store, id)
|
|
272
|
+
if info is None or not workers.busy(id):
|
|
273
|
+
raise HTTPException(409, "That work already finished: your change waits for the "
|
|
274
|
+
"review that is open now") # fmt: skip
|
|
275
|
+
request_stop(store, id, [body.change])
|
|
276
|
+
return {"stopping": True, "round": info["round"]}
|
|
277
|
+
|
|
278
|
+
return api
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"""One background worker per active run: it steps the run's workflow until the next gate (or
|
|
2
|
+
the end), so several projects can be in progress at once in one studio process."""
|
|
3
|
+
|
|
4
|
+
import asyncio
|
|
5
|
+
from contextlib import suppress
|
|
6
|
+
|
|
7
|
+
from spriteforge.agents.workflow import WORKFLOW
|
|
8
|
+
from spriteforge.agents.workflow import workflow_step as agent_step
|
|
9
|
+
from spriteforge.core.cost import BudgetExceeded, Cancelled
|
|
10
|
+
from spriteforge.core.demo import demo_step
|
|
11
|
+
from spriteforge.core.security import redact
|
|
12
|
+
from spriteforge.core.state import Store
|
|
13
|
+
from spriteforge.stages.rewind import rewind
|
|
14
|
+
from spriteforge.stages.workflow import WORKFLOW as INTAKE
|
|
15
|
+
from spriteforge.stages.workflow import workflow_step as intake_step
|
|
16
|
+
|
|
17
|
+
# budget_exhausted is not final: the run waits for Continue (cost policy).
|
|
18
|
+
FINAL = {"completed", "aborted", "failed"}
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def step_for(store: Store, run_id: str):
|
|
22
|
+
workflow = store.get_run(run_id).config.get("workflow")
|
|
23
|
+
return intake_step if workflow == INTAKE else agent_step if workflow == WORKFLOW else demo_step
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class Workers:
|
|
27
|
+
def __init__(self, store: Store, interval: float = 1.0):
|
|
28
|
+
self.store, self.interval = store, interval
|
|
29
|
+
self.tasks: dict[str, asyncio.Task] = {}
|
|
30
|
+
self.errors: dict[str, str] = {} # run id -> scrubbed message of the failure
|
|
31
|
+
|
|
32
|
+
def busy(self, run_id: str) -> bool:
|
|
33
|
+
task = self.tasks.get(run_id)
|
|
34
|
+
return task is not None and not task.done()
|
|
35
|
+
|
|
36
|
+
def start(self, run_id: str) -> bool:
|
|
37
|
+
"""Step this run in the background; False when its worker is already running.
|
|
38
|
+
Needs a running event loop (call from a route or the app lifespan)."""
|
|
39
|
+
if self.busy(run_id):
|
|
40
|
+
return False
|
|
41
|
+
self.errors.pop(run_id, None)
|
|
42
|
+
self.tasks[run_id] = asyncio.create_task(self._work(run_id))
|
|
43
|
+
return True
|
|
44
|
+
|
|
45
|
+
async def _work(self, run_id: str):
|
|
46
|
+
while True:
|
|
47
|
+
try:
|
|
48
|
+
if self.store.get_run(run_id).status in FINAL:
|
|
49
|
+
break
|
|
50
|
+
more = await asyncio.to_thread(step_for(self.store, run_id), self.store, run_id)
|
|
51
|
+
if not more:
|
|
52
|
+
break
|
|
53
|
+
except Cancelled:
|
|
54
|
+
# Go back: the stopped round is superseded and starts again with the changes.
|
|
55
|
+
await asyncio.to_thread(rewind, self.store, run_id)
|
|
56
|
+
continue
|
|
57
|
+
except BudgetExceeded as exc:
|
|
58
|
+
await asyncio.to_thread(self.store.pause_for_budget, run_id,
|
|
59
|
+
f"{redact(str(exc))}: press Continue for a fresh allowance") # fmt: skip
|
|
60
|
+
break
|
|
61
|
+
except Exception as exc: # noqa: BLE001 -- persist any worker failure at task boundary
|
|
62
|
+
# No traceback/HTTP headers: errors are scrubbed at this boundary.
|
|
63
|
+
self.errors[run_id] = redact(str(exc))
|
|
64
|
+
await asyncio.to_thread(self.store.fail, run_id, str(exc))
|
|
65
|
+
break
|
|
66
|
+
await asyncio.sleep(self.interval)
|
|
67
|
+
|
|
68
|
+
async def close(self):
|
|
69
|
+
for task in self.tasks.values():
|
|
70
|
+
task.cancel()
|
|
71
|
+
for task in self.tasks.values():
|
|
72
|
+
with suppress(asyncio.CancelledError):
|
|
73
|
+
await task
|