oda-engine 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +151 -2
- package/bin/nowhere.mjs +352 -0
- package/lib/account.mjs +57 -0
- package/lib/agentModules.mjs +57 -0
- package/lib/devServer.mjs +351 -0
- package/lib/headless.mjs +231 -0
- package/lib/headlessPreview.mjs +212 -0
- package/lib/keys.mjs +517 -0
- package/lib/make.mjs +855 -0
- package/lib/mcp.mjs +537 -0
- package/lib/open.mjs +22 -0
- package/lib/preview.mjs +87 -0
- package/lib/previewRpc.mjs +134 -0
- package/lib/project.mjs +359 -0
- package/lib/publishFlow.mjs +90 -0
- package/lib/resources.mjs +50 -0
- package/lib/rules.mjs +60 -0
- package/lib/scaffold.mjs +42 -0
- package/lib/setup.mjs +59 -0
- package/lib/tools.mjs +668 -0
- package/package.json +51 -4
- package/template/game.config.json +9 -0
- package/template/scene.json +4 -0
- package/template/src/main.ts +11 -0
- package/vendor/DOCS.md +447 -0
- package/vendor/agent/appRun.mjs +520 -0
- package/vendor/agent/assets/brief.mjs +242 -0
- package/vendor/agent/assets/collider.mjs +531 -0
- package/vendor/agent/assets/environments/index.mjs +12 -0
- package/vendor/agent/assets/environments/worldlabs.mjs +161 -0
- package/vendor/agent/assets/fetch.mjs +168 -0
- package/vendor/agent/assets/footprint.mjs +13 -0
- package/vendor/agent/assets/gltf.mjs +547 -0
- package/vendor/agent/assets/hdr.mjs +269 -0
- package/vendor/agent/assets/imageOps.mjs +171 -0
- package/vendor/agent/assets/images/codex.mjs +307 -0
- package/vendor/agent/assets/images/fal.mjs +75 -0
- package/vendor/agent/assets/images/gemini.mjs +84 -0
- package/vendor/agent/assets/images/index.mjs +25 -0
- package/vendor/agent/assets/images/openai.mjs +75 -0
- package/vendor/agent/assets/images/stability.mjs +71 -0
- package/vendor/agent/assets/images/views.mjs +31 -0
- package/vendor/agent/assets/import.mjs +1352 -0
- package/vendor/agent/assets/inspect.mjs +465 -0
- package/vendor/agent/assets/jobs.mjs +196 -0
- package/vendor/agent/assets/ktx2.mjs +290 -0
- package/vendor/agent/assets/ledger.mjs +466 -0
- package/vendor/agent/assets/net.mjs +254 -0
- package/vendor/agent/assets/prices.json +39 -0
- package/vendor/agent/assets/providers/fal.mjs +115 -0
- package/vendor/agent/assets/providers/index.mjs +22 -0
- package/vendor/agent/assets/providers/meshy.mjs +119 -0
- package/vendor/agent/assets/providers/tripo.mjs +188 -0
- package/vendor/agent/assets/sources/ambientcg.mjs +129 -0
- package/vendor/agent/assets/sources/index.mjs +23 -0
- package/vendor/agent/assets/sources/polyhaven.mjs +237 -0
- package/vendor/agent/assets/sources/polypizza.mjs +121 -0
- package/vendor/agent/assets/splat.mjs +631 -0
- package/vendor/agent/assets/targets.mjs +122 -0
- package/vendor/agent/assets/tile.mjs +261 -0
- package/vendor/agent/assets/unzip.mjs +180 -0
- package/vendor/agent/blender/cleanup.py +360 -0
- package/vendor/agent/blender/convert.py +167 -0
- package/vendor/agent/blender/find.mjs +192 -0
- package/vendor/agent/blender/nw_export.py +104 -0
- package/vendor/agent/blender/nw_rubric.py +426 -0
- package/vendor/agent/blender/run.mjs +193 -0
- package/vendor/agent/blender/runner.py +252 -0
- package/vendor/agent/blender/sheet.py +743 -0
- package/vendor/agent/depth.mjs +134 -0
- package/vendor/agent/director/board.mjs +451 -0
- package/vendor/agent/director/contracts.mjs +663 -0
- package/vendor/agent/director/director.mjs +2365 -0
- package/vendor/agent/director/estimate.mjs +200 -0
- package/vendor/agent/director/gate.mjs +802 -0
- package/vendor/agent/director/limits.json +16 -0
- package/vendor/agent/director/methods.mjs +457 -0
- package/vendor/agent/director/policy.json +33 -0
- package/vendor/agent/director/prompts.mjs +244 -0
- package/vendor/agent/director/reading.mjs +341 -0
- package/vendor/agent/director/router.mjs +184 -0
- package/vendor/agent/director/seams.mjs +243 -0
- package/vendor/agent/director/session.mjs +643 -0
- package/vendor/agent/director/store.mjs +119 -0
- package/vendor/agent/director/taskGate.mjs +110 -0
- package/vendor/agent/director/teamLedger.mjs +118 -0
- package/vendor/agent/director/triage.mjs +63 -0
- package/vendor/agent/downloads.cjs +363 -0
- package/vendor/agent/flow.mjs +78 -0
- package/vendor/agent/guard.mjs +613 -0
- package/vendor/agent/host.mjs +1736 -0
- package/vendor/agent/language.mjs +58 -0
- package/vendor/agent/ledger.mjs +360 -0
- package/vendor/agent/locale.cjs +186 -0
- package/vendor/agent/loop/capacity.mjs +74 -0
- package/vendor/agent/loop/compose.mjs +127 -0
- package/vendor/agent/loop/gate.mjs +205 -0
- package/vendor/agent/loop/judge.mjs +189 -0
- package/vendor/agent/loop/levels.mjs +273 -0
- package/vendor/agent/loop/state.mjs +358 -0
- package/vendor/agent/notes.cjs +278 -0
- package/vendor/agent/pace.mjs +258 -0
- package/vendor/agent/panels.mjs +431 -0
- package/vendor/agent/prompt.mjs +342 -0
- package/vendor/agent/reference/board.mjs +410 -0
- package/vendor/agent/reference/compose.mjs +364 -0
- package/vendor/agent/reference/decode.mjs +56 -0
- package/vendor/agent/reference/facts.mjs +1874 -0
- package/vendor/agent/reference/png.mjs +107 -0
- package/vendor/agent/reference/records.mjs +63 -0
- package/vendor/agent/reference/web.mjs +252 -0
- package/vendor/agent/roles/artist.mjs +69 -0
- package/vendor/agent/roles/builder.mjs +79 -0
- package/vendor/agent/roles/checks.mjs +223 -0
- package/vendor/agent/roles/common.mjs +188 -0
- package/vendor/agent/roles/critic.mjs +171 -0
- package/vendor/agent/roles/index.mjs +39 -0
- package/vendor/agent/roles/modeller.mjs +142 -0
- package/vendor/agent/roles/qa.mjs +58 -0
- package/vendor/agent/roles/rubrics.mjs +79 -0
- package/vendor/agent/roles/sound.mjs +69 -0
- package/vendor/agent/rounds.cjs +333 -0
- package/vendor/agent/shared.mjs +284 -0
- package/vendor/agent/stopGate.mjs +574 -0
- package/vendor/agent/subagents.mjs +129 -0
- package/vendor/agent/tools/assets.mjs +499 -0
- package/vendor/agent/tools/blender.mjs +754 -0
- package/vendor/agent/tools/cards.mjs +479 -0
- package/vendor/agent/tools/choices.mjs +479 -0
- package/vendor/agent/tools/compose.mjs +74 -0
- package/vendor/agent/tools/environment.mjs +488 -0
- package/vendor/agent/tools/eyes.mjs +733 -0
- package/vendor/agent/tools/generate.mjs +338 -0
- package/vendor/agent/tools/guide.mjs +46 -0
- package/vendor/agent/tools/harness.mjs +193 -0
- package/vendor/agent/tools/image.mjs +643 -0
- package/vendor/agent/tools/index.mjs +162 -0
- package/vendor/agent/tools/look.mjs +578 -0
- package/vendor/agent/tools/loop.mjs +858 -0
- package/vendor/agent/tools/others.mjs +123 -0
- package/vendor/agent/tools/pictures.mjs +535 -0
- package/vendor/agent/tools/reference.mjs +366 -0
- package/vendor/agent/transcripts.mjs +118 -0
- package/vendor/agent-loop.mjs +602 -0
- package/vendor/agent-plugin/.claude-plugin/plugin.json +5 -0
- package/vendor/agent-plugin/skills/art-direction/SKILL.md +82 -0
- package/vendor/agent-plugin/skills/asset-legality/SKILL.md +101 -0
- package/vendor/agent-plugin/skills/asset-sources/SKILL.md +111 -0
- package/vendor/agent-plugin/skills/blender-modeling/SKILL.md +97 -0
- package/vendor/agent-plugin/skills/look-dev/SKILL.md +104 -0
- package/vendor/agent-plugin/skills/playtesting/SKILL.md +74 -0
- package/vendor/agent-plugin/skills/reference-loop/SKILL.md +102 -0
- package/vendor/agent-plugin/skills/sound-design/SKILL.md +60 -0
- package/vendor/agent-plugin/skills/style/SKILL.md +35 -0
- package/vendor/agent-plugin/skills/tsl-r185/SKILL.md +107 -0
- package/vendor/auth.cjs +570 -0
- package/vendor/build.cjs +953 -0
- package/vendor/catalog.json +455 -0
- package/vendor/connectors.cjs +688 -0
- package/vendor/eyes.mjs +733 -0
- package/vendor/gameExports.json +1390 -0
- package/vendor/git.cjs +222 -0
- package/vendor/models.json +57 -0
- package/vendor/publish.cjs +1018 -0
- package/vendor/refBoard.cjs +301 -0
- package/vendor/schema/dist/assets.d.ts +335 -0
- package/vendor/schema/dist/assets.js +439 -0
- package/vendor/schema/dist/brief.d.ts +357 -0
- package/vendor/schema/dist/brief.js +302 -0
- package/vendor/schema/dist/common.d.ts +9 -0
- package/vendor/schema/dist/common.js +13 -0
- package/vendor/schema/dist/config.d.ts +406 -0
- package/vendor/schema/dist/config.js +355 -0
- package/vendor/schema/dist/contract.d.ts +599 -0
- package/vendor/schema/dist/contract.js +1146 -0
- package/vendor/schema/dist/index.d.ts +14 -0
- package/vendor/schema/dist/index.js +21 -0
- package/vendor/schema/dist/look.d.ts +463 -0
- package/vendor/schema/dist/look.js +681 -0
- package/vendor/schema/dist/lookStats.d.ts +230 -0
- package/vendor/schema/dist/lookStats.js +768 -0
- package/vendor/schema/dist/pilot.d.ts +32 -0
- package/vendor/schema/dist/pilot.js +44 -0
- package/vendor/schema/dist/publish.d.ts +214 -0
- package/vendor/schema/dist/publish.js +291 -0
- package/vendor/schema/dist/scene.d.ts +75 -0
- package/vendor/schema/dist/scene.js +120 -0
- package/vendor/schema/dist/skyLight.d.ts +141 -0
- package/vendor/schema/dist/skyLight.js +436 -0
- package/vendor/schema/dist/style.d.ts +131 -0
- package/vendor/schema/dist/style.js +155 -0
- package/vendor/schema/package.json +1 -0
- package/vendor/selectionPrompt.mjs +51 -0
- package/vendor/useTools.mjs +195 -0
- package/vendor/userMessage.mjs +26 -0
- package/web-dist/assets/GaussianSplatUtils-CB77cP9U.js +1 -0
- package/web-dist/assets/KTX2Loader-6OIWUF7s.js +2 -0
- package/web-dist/assets/SPZLoader-zYj0Alfv.js +1 -0
- package/web-dist/assets/gaussianSplat-CJTI1sEh.js +1 -0
- package/web-dist/assets/index-CcjyyQco.css +1 -0
- package/web-dist/assets/index-DMyJcoZJ.js +693 -0
- package/web-dist/assets/meshopt_decoder.module-BvwdjiD3.js +1 -0
- package/web-dist/assets/zstddec.module-CfFeQW7d.js +1 -0
- package/web-dist/index.html +34 -0
|
@@ -0,0 +1,338 @@
|
|
|
1
|
+
// Paid generation, only after the creator approved what it costs:
|
|
2
|
+
// asset_generate estimate -> (nw_ask kind cost, the creator approves) -> submit
|
|
3
|
+
// asset_job polls a job, downloads what it made into quarantine
|
|
4
|
+
//
|
|
5
|
+
// Nothing here spends money without a ledger approval that covers the
|
|
6
|
+
// estimate, a key the creator saved (read through ctx.secret, never printed),
|
|
7
|
+
// and a model whose output the creator may use. The vendors are Meshy, fal
|
|
8
|
+
// and Tripo (assets/providers/); every check drives them with a fake fetch.
|
|
9
|
+
// A job made from pictures keeps what they were (their hashes, and from the
|
|
10
|
+
// ledger the reference's crop or the generator each came from), so the model
|
|
11
|
+
// asset_import brings in records its whole making; image_generate
|
|
12
|
+
// (tools/image.mjs) makes those pictures and sends them through the same
|
|
13
|
+
// checks (pictureInput).
|
|
14
|
+
|
|
15
|
+
import { z } from 'zod'
|
|
16
|
+
import { createHash } from 'node:crypto'
|
|
17
|
+
import fs from 'node:fs'
|
|
18
|
+
import fsp from 'node:fs/promises'
|
|
19
|
+
import { createRequire } from 'node:module'
|
|
20
|
+
import path from 'node:path'
|
|
21
|
+
import { downloadResults, isJobId, listJobs, newJobId, overall, pollJob, readJob, writeJob } from '../assets/jobs.mjs'
|
|
22
|
+
import { inputRecordOf, readLedgerState, sha256File } from '../assets/ledger.mjs'
|
|
23
|
+
import { fetchOf, imageMime, userAgentFor } from '../assets/net.mjs'
|
|
24
|
+
import { gradeC, recordsFor } from '../reference/records.mjs'
|
|
25
|
+
import { lookOnlyWhy, webLookOnlyAmong, webLookOnlyNear, webLookOnlyOf } from '../reference/web.mjs'
|
|
26
|
+
import { PRICES, PROVIDERS, REFUSED_MODELS } from '../assets/providers/index.mjs'
|
|
27
|
+
|
|
28
|
+
const require = createRequire(import.meta.url)
|
|
29
|
+
const { blockedHost, readManifest } = require('../downloads.cjs')
|
|
30
|
+
|
|
31
|
+
export const RPC_METHODS = []
|
|
32
|
+
|
|
33
|
+
const fail = (text) => ({ text, isError: true })
|
|
34
|
+
const usd = (n) => `$${n.toFixed(2)}`
|
|
35
|
+
const MB = 1024 * 1024
|
|
36
|
+
|
|
37
|
+
// ---------------------------------------------------------------- checks before money
|
|
38
|
+
|
|
39
|
+
function realOrSelf(p) {
|
|
40
|
+
let head = path.resolve(p)
|
|
41
|
+
const rest = []
|
|
42
|
+
for (;;) {
|
|
43
|
+
try {
|
|
44
|
+
return path.join(fs.realpathSync(head), ...rest)
|
|
45
|
+
} catch {
|
|
46
|
+
const up = path.dirname(head)
|
|
47
|
+
if (up === head) return path.resolve(p)
|
|
48
|
+
rest.unshift(path.basename(head))
|
|
49
|
+
head = up
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** Where a project picture came from, when that is a host whose terms forbid
|
|
55
|
+
* feeding its images to AI tools: the ledger's source, the quarantine
|
|
56
|
+
* manifest (by hash), or a grade C entry on the reference board. */
|
|
57
|
+
export async function blockedSourceOf(projectRoot, rel, abs, { rpc = null } = {}) {
|
|
58
|
+
const { lock } = await readLedgerState(projectRoot)
|
|
59
|
+
const entry = lock.files[rel]
|
|
60
|
+
for (const u of [entry?.source?.url, entry?.source?.host && `https://${entry.source.host}/`]) if (u && blockedHost(u)) return new URL(u).hostname
|
|
61
|
+
let sha = null
|
|
62
|
+
try {
|
|
63
|
+
sha = await sha256File(abs)
|
|
64
|
+
} catch {
|
|
65
|
+
return null
|
|
66
|
+
}
|
|
67
|
+
for (const f of readManifest(projectRoot).files) {
|
|
68
|
+
if (f.sha256 && f.sha256 === sha) {
|
|
69
|
+
for (const u of [f.url, f.referrer, f.host && `https://${f.host}/`]) if (u && blockedHost(u)) return new URL(u).hostname
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
try {
|
|
73
|
+
const board = JSON.parse(await fsp.readFile(path.join(projectRoot, 'refs', 'board.json'), 'utf8'))
|
|
74
|
+
// Any record naming it, whatever the board's shape, by the rule the
|
|
75
|
+
// reference tools and the mood board read it with (reference/records.mjs).
|
|
76
|
+
const records = recordsFor(board, { rel, name: path.basename(rel), sha })
|
|
77
|
+
if (records.some(gradeC)) return 'a grade C reference (one that may not be fed to a model)'
|
|
78
|
+
for (const it of records) for (const u of [it?.url, it?.source]) if (typeof u === 'string' && blockedHost(u)) return new URL(u).hostname
|
|
79
|
+
} catch {
|
|
80
|
+
// no board
|
|
81
|
+
}
|
|
82
|
+
// A web reference kept to look at only (nw_keep_pictures, not CC0 or public domain).
|
|
83
|
+
const web = (await webLookOnlyOf(projectRoot, { rel, sha })) ?? (await webLookOnlyAmong(projectRoot, [abs]))?.record
|
|
84
|
+
if (web) return `a web reference kept to look at only (${lookOnlyWhy(web)})`
|
|
85
|
+
// Or the same picture re-encoded or resized, which has a hash of its own.
|
|
86
|
+
const near = await webLookOnlyNear(projectRoot, await fsp.readFile(abs), { rpc }).catch(() => null)
|
|
87
|
+
if (near) return `a copy of a web reference kept to look at only (${near.why})`
|
|
88
|
+
return null
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* A project picture a generator may be sent, or why it may not: inside the
|
|
93
|
+
* project, a PNG or a JPEG under 10 MB, from no host whose terms forbid
|
|
94
|
+
* feeding it to a model (nor a crop of a picture from one), and never the
|
|
95
|
+
* reference's crop of a subject the brief transforms (its likeness is the
|
|
96
|
+
* reference's). { dataUri, rel, abs, mime, data, entry } or { error }.
|
|
97
|
+
*/
|
|
98
|
+
export async function pictureInput(ctx, image) {
|
|
99
|
+
const root = realOrSelf(ctx.projectRoot)
|
|
100
|
+
const abs = realOrSelf(path.resolve(root, image))
|
|
101
|
+
const rel = path.relative(root, abs)
|
|
102
|
+
if (!rel || rel.startsWith('..') || path.isAbsolute(rel)) return { error: `image "${image}" is outside the project. Give a project path, e.g. ".nowhere/refs/<file>.png" or "concepts/barrel.png".` }
|
|
103
|
+
let buf
|
|
104
|
+
try {
|
|
105
|
+
buf = await fsp.readFile(abs)
|
|
106
|
+
} catch {
|
|
107
|
+
return { error: `image "${image}" is not there.` }
|
|
108
|
+
}
|
|
109
|
+
if (buf.length > 10 * MB) return { error: `image "${image}" is ${(buf.length / MB).toFixed(1)} MB; send one under 10 MB.` }
|
|
110
|
+
const mime = imageMime(buf)
|
|
111
|
+
if (!mime) return { error: `image "${image}" is not a PNG or a JPEG.` }
|
|
112
|
+
const relPath = rel.split(path.sep).join('/')
|
|
113
|
+
const entry = (await readLedgerState(root)).lock.files[relPath] ?? null
|
|
114
|
+
if (entry?.meta?.role === 'transform') return { error: `image "${image}" is the reference's crop of a subject the brief transforms: its likeness is the reference's, so it is never sent. Say the replacement the brief names in words instead.` }
|
|
115
|
+
const of = typeof entry?.meta?.of === 'string' ? entry.meta.of : null
|
|
116
|
+
const blocked = (await blockedSourceOf(root, relPath, abs, { rpc: ctx.rpc })) ?? (of ? await blockedSourceOf(root, of, path.join(root, of), { rpc: ctx.rpc }) : null)
|
|
117
|
+
if (blocked) return { error: `image "${image}" came from ${blocked}; ArtStation, Pinterest and Behance images are never fed to a model, and neither are grade C references or look-only web references.` }
|
|
118
|
+
const data = buf.toString('base64')
|
|
119
|
+
return { dataUri: `data:${mime};base64,${data}`, rel: relPath, abs, mime, data, entry, sha256: createHash('sha256').update(buf).digest('hex') }
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/** What a request would run as, or why it cannot run at all. */
|
|
123
|
+
function planFor(args) {
|
|
124
|
+
const provider = PROVIDERS[args.provider]
|
|
125
|
+
if (!provider) return { error: `${args.provider} is not a generator (${Object.keys(PROVIDERS).join(', ')}).` }
|
|
126
|
+
const model = args.model?.trim() || provider.defaultModel(args.task)
|
|
127
|
+
for (const r of REFUSED_MODELS) if (r.test.test(model)) return { error: `Refused: ${r.why}` }
|
|
128
|
+
if (!provider.tasks.includes(args.task)) return { error: `${provider.label} does ${provider.tasks.join(' and ')} here, not ${args.task}.` }
|
|
129
|
+
const refused = provider.refuse?.(args.task, model)
|
|
130
|
+
if (refused) return { error: refused }
|
|
131
|
+
if (args.artStyle && !(args.provider === 'meshy' && args.task === 'text-to-3d')) return { error: 'artStyle is Meshy text-to-3d\'s art_style; leave it out here and say the style in the prompt.' }
|
|
132
|
+
if (args.task === 'text-to-3d' && !args.prompt?.trim()) return { error: 'text-to-3d needs a prompt: what the object is, its materials and style, in English. Never a living artist\'s name or a copyrighted character.' }
|
|
133
|
+
if (args.task === 'image-to-3d' && !args.image) return { error: 'image-to-3d needs image: a project path to a PNG or JPEG of the object, alone on a plain background.' }
|
|
134
|
+
if (args.task === 'multi-image-to-3d' && !(args.images?.length >= 2)) return { error: 'multi-image-to-3d needs images: 2 to 4 project paths to views of the same object, in this order: the front, its right side, the back, its left side (as image_generate makes them); Tripo reads each by its place. One view is image-to-3d.' }
|
|
135
|
+
if (args.images?.length && args.task !== 'multi-image-to-3d') return { error: 'images is for multi-image-to-3d; give one picture as image.' }
|
|
136
|
+
const price = provider.price(args.task, model, PRICES)
|
|
137
|
+
if (!price) return { error: `There is no price for ${provider.label} ${args.task} (${model}) in prices.json, so it cannot be estimated or run.` }
|
|
138
|
+
const candidates = args.candidates ?? 1
|
|
139
|
+
const lines = Array.from({ length: candidates }, (_, i) => ({ label: `${provider.label} ${args.task}${candidates > 1 ? `, candidate ${i + 1}` : ''} (${model}, ${price.unit})`, usd: Math.round(price.high * 100) / 100 }))
|
|
140
|
+
const totalUsd = Math.round(lines.reduce((n, l) => n + l.usd, 0) * 100) / 100
|
|
141
|
+
const id = createHash('sha256').update(JSON.stringify([args.provider, args.task, model, args.prompt ?? '', args.image ?? '', ...(args.images?.length ? [args.images] : []), candidates, args.quality ?? null])).digest('hex').slice(0, 12)
|
|
142
|
+
return { provider, model, price, candidates, lines, totalUsd, estimateId: id }
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// ---------------------------------------------------------------- asset_generate
|
|
146
|
+
|
|
147
|
+
const GENERATE_SHAPE = {
|
|
148
|
+
action: z.enum(['estimate', 'submit']).describe('estimate first; submit only after the creator approved a cost card that covers it.'),
|
|
149
|
+
provider: z.enum(Object.keys(PROVIDERS)),
|
|
150
|
+
task: z.enum(['text-to-3d', 'image-to-3d', 'multi-image-to-3d']),
|
|
151
|
+
model: z.string().optional().describe('fal: the model id (fal-ai/trellis-2); meshy: the API\'s model field (default latest); tripo: a dated model id (default v3.1-20260211; P1-20260311 for low poly, P2-20260801 for quads-ready meshes).'),
|
|
152
|
+
prompt: z.string().max(800).optional().describe('text-to-3d: what the object is, in English. Never a living artist\'s name or a copyrighted character.'),
|
|
153
|
+
image: z.string().optional().describe('image-to-3d: a project path to a picture of the object: one image_generate made, or the reference\'s crop your task names.'),
|
|
154
|
+
images: z.array(z.string()).min(2).max(4).optional().describe('multi-image-to-3d (Meshy or Tripo): 2 to 4 project paths to views of the same object, in this order: the front, its right side, the back, its left side (as image_generate makes them); Tripo reads each by its place.'),
|
|
155
|
+
candidates: z.number().int().min(1).max(2).default(1).describe('2 to pick the better of two.'),
|
|
156
|
+
quality: z.object({ polycount: z.number().int().optional(), pbr: z.boolean().default(true) }).optional(),
|
|
157
|
+
artStyle: z.enum(['realistic', 'sculpture']).optional().describe("Meshy text-to-3d only: the vendor's art_style, chosen from this brief. Left out, the request sets none and the prompt says the style."),
|
|
158
|
+
confirm: z.string().max(40).optional().describe('Only where the host asks for it: the estimate id the estimate answered, once the creator agreed.'),
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
const GENERATE_DESCRIPTION =
|
|
162
|
+
"Generates a 3D model with a paid service (Meshy or Tripo: text, image or several views to 3D; fal TRELLIS.2: image to 3D). action estimate answers the cost lines for a cost card; ask the creator with nw_ask kind cost, in the screen language, and only after they approve call action submit with the same request. submit refuses without the vendor's key (ask with nw_ask kind key), without an approval that covers the estimate, and for Hunyuan3D. It starts the job and answers its id; follow it with asset_job, then asset_import what it made. Prefer a CC0 library (asset_search) or Blender for anything common; generate only a prop this space alone has, never its ground, walls or architecture, and delit (Meshy and Tripo are asked to remove the lighting, fal is not; asset_inspect says when shadow is baked in)."
|
|
163
|
+
|
|
164
|
+
async function generate(args, ctx) {
|
|
165
|
+
const plan = planFor(args)
|
|
166
|
+
if (plan.error) return fail(plan.error)
|
|
167
|
+
const { provider, model, lines, totalUsd, estimateId } = plan
|
|
168
|
+
|
|
169
|
+
if (args.action === 'estimate') {
|
|
170
|
+
// A vendor's block may carry the day its own prices were read.
|
|
171
|
+
const checked = PRICES[provider.id]?.checked ?? PRICES.checked
|
|
172
|
+
const text = [
|
|
173
|
+
`Estimate ${estimateId}: ${lines.map((l) => `${l.label} up to ${usd(l.usd)}`).join('; ')}. Total up to ${usd(totalUsd)} (prices checked ${checked}).`,
|
|
174
|
+
`For the cost card: ${JSON.stringify({ items: lines, note: `${provider.label}, ${checked} prices` })}`,
|
|
175
|
+
'Ask with nw_ask kind cost, in the screen language, then submit.',
|
|
176
|
+
]
|
|
177
|
+
return { text: text.join('\n') }
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// submit: the key, the approval, the input. Nothing is sent before all three.
|
|
181
|
+
const key = (() => {
|
|
182
|
+
try {
|
|
183
|
+
const v = ctx?.secret?.(provider.envVar)
|
|
184
|
+
return typeof v === 'string' && v.trim() ? v.trim() : null
|
|
185
|
+
} catch {
|
|
186
|
+
return null
|
|
187
|
+
}
|
|
188
|
+
})()
|
|
189
|
+
if (!key) return fail(`${provider.label} has no key here. Ask for it with nw_ask kind key, connector ${provider.connector}.`)
|
|
190
|
+
if (args.confirm && typeof ctx?.ledger?.confirmEstimate === 'function') {
|
|
191
|
+
try {
|
|
192
|
+
ctx.ledger.confirmEstimate({ id: args.confirm, usd: totalUsd, matches: args.confirm === estimateId })
|
|
193
|
+
} catch {
|
|
194
|
+
// the host's stand-in decides; the approval below is the gate
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
const approved = ctx?.ledger?.approvedUsd?.()
|
|
198
|
+
const spent = Number(ctx?.ledger?.spentUsd?.() ?? 0) || 0
|
|
199
|
+
if (approved === null || approved === undefined || !Number.isFinite(approved)) {
|
|
200
|
+
return fail(`No cost card has been approved for this, so nothing was sent. Run action estimate, ask the creator with nw_ask kind cost (${usd(totalUsd)}), and submit after they approve.`)
|
|
201
|
+
}
|
|
202
|
+
if (approved - spent < totalUsd - 1e-9) {
|
|
203
|
+
return fail(`The approval left is ${usd(Math.max(0, approved - spent))} (approved ${usd(approved)}, spent ${usd(spent)}), less than this estimate of ${usd(totalUsd)}, so nothing was sent. Ask again with nw_ask kind cost for the new total.`)
|
|
204
|
+
}
|
|
205
|
+
const pictures = []
|
|
206
|
+
for (const given of args.task === 'image-to-3d' ? [args.image] : args.task === 'multi-image-to-3d' ? args.images : []) {
|
|
207
|
+
const picture = await pictureInput(ctx, given)
|
|
208
|
+
if (picture.error) return fail(picture.error)
|
|
209
|
+
pictures.push(picture)
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
const fetch = fetchOf(ctx)
|
|
213
|
+
const ua = userAgentFor(ctx)
|
|
214
|
+
const jobId = newJobId(provider.id)
|
|
215
|
+
const candidates = []
|
|
216
|
+
const errors = []
|
|
217
|
+
for (let n = 1; n <= plan.candidates; n++) {
|
|
218
|
+
try {
|
|
219
|
+
const r = await provider.submit({ task: args.task, model, prompt: args.prompt, imageDataUri: pictures[0]?.dataUri, imageDataUris: pictures.map((p) => p.dataUri), quality: args.quality, artStyle: args.artStyle, key, fetch, ua })
|
|
220
|
+
candidates.push({ n, ...r, status: 'pending', progress: 0 })
|
|
221
|
+
} catch (err) {
|
|
222
|
+
errors.push(`candidate ${n}: ${String(err?.message ?? err).slice(0, 200)}`)
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
if (candidates.length === 0) return fail(`${provider.label} did not take the job, so nothing was spent: ${errors.join('; ')}`)
|
|
226
|
+
const job = {
|
|
227
|
+
id: jobId,
|
|
228
|
+
provider: provider.id,
|
|
229
|
+
task: args.task,
|
|
230
|
+
model,
|
|
231
|
+
prompt: args.prompt ?? '',
|
|
232
|
+
promptSha256: createHash('sha256').update(args.prompt ?? '').digest('hex'),
|
|
233
|
+
...(pictures.length ? { image: pictures[0].rel, inputs: pictures.map((p) => inputRecordOf(p.rel, p.sha256, p.entry)) } : {}),
|
|
234
|
+
vendorIds: candidates.map((c) => c.vendorId),
|
|
235
|
+
estimateUsd: totalUsd,
|
|
236
|
+
createdAt: new Date().toISOString(),
|
|
237
|
+
status: 'pending',
|
|
238
|
+
candidates,
|
|
239
|
+
}
|
|
240
|
+
job.status = overall(job)
|
|
241
|
+
await writeJob(ctx.projectRoot, job)
|
|
242
|
+
// Recorded once, at the estimate: what the vendor bills is the vendor's
|
|
243
|
+
// answer, and the estimate is the upper price.
|
|
244
|
+
try {
|
|
245
|
+
ctx?.ledger?.addGeneration?.(totalUsd, `${provider.id} ${args.task}`)
|
|
246
|
+
} catch (err) {
|
|
247
|
+
ctx?.log?.(`[generate] ledger.addGeneration failed: ${err?.message ?? err}`)
|
|
248
|
+
}
|
|
249
|
+
return {
|
|
250
|
+
text: [
|
|
251
|
+
`Started ${provider.label} ${args.task} as job ${jobId} (${candidates.length} ${candidates.length === 1 ? 'candidate' : 'candidates'}, up to ${usd(totalUsd)}, recorded in the spend).`,
|
|
252
|
+
...(errors.length ? [`Not started: ${errors.join('; ')}.`] : []),
|
|
253
|
+
`Follow it with asset_job (id "${jobId}"); a model takes a few minutes.`,
|
|
254
|
+
].join('\n'),
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
// ---------------------------------------------------------------- asset_job
|
|
259
|
+
|
|
260
|
+
const JOB_SHAPE = {
|
|
261
|
+
id: z.string().describe('The job id asset_generate answered.'),
|
|
262
|
+
wait: z.number().int().min(0).max(120).default(30).describe('Seconds to keep polling (every 5 s) before answering.'),
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
const JOB_DESCRIPTION =
|
|
266
|
+
"Checks a generation job from asset_generate: polls the vendor every 5 seconds for up to wait seconds and answers each candidate's status and progress. When a candidate is done it downloads the GLB (and its thumbnail) into quarantine as gen-<job>-<n> and shows the thumbnails; bring it into the space with asset_import from that id, with a class and a size. Jobs survive a restart."
|
|
267
|
+
|
|
268
|
+
async function job(args, ctx, deps) {
|
|
269
|
+
if (!ctx?.projectRoot) return fail('No project is open.')
|
|
270
|
+
if (!isJobId(args.id)) {
|
|
271
|
+
const recent = (await listJobs(ctx.projectRoot)).slice(-6)
|
|
272
|
+
return fail(`"${args.id}" is not a job id.${recent.length ? ` Jobs in this project: ${recent.join(', ')}.` : ''}`)
|
|
273
|
+
}
|
|
274
|
+
const current = await readJob(ctx.projectRoot, args.id)
|
|
275
|
+
if (!current) return fail(`There is no job ${args.id} in this project (.nowhere/jobs/).`)
|
|
276
|
+
if (current.kind === 'environment') return fail(`Job ${args.id} is a world from ${current.provider}: follow it with environment_job.`)
|
|
277
|
+
const provider = PROVIDERS[current.provider]
|
|
278
|
+
if (!provider) return fail(`Job ${args.id} is for ${current.provider}, which this studio does not run.`)
|
|
279
|
+
const key = (() => {
|
|
280
|
+
try {
|
|
281
|
+
const v = ctx?.secret?.(provider.envVar)
|
|
282
|
+
return typeof v === 'string' && v.trim() ? v.trim() : null
|
|
283
|
+
} catch {
|
|
284
|
+
return null
|
|
285
|
+
}
|
|
286
|
+
})()
|
|
287
|
+
if (!key) return fail(`${provider.label} has no key here to ask about the job. Ask for it with nw_ask kind key, connector ${provider.connector}.`)
|
|
288
|
+
const fetch = fetchOf(ctx)
|
|
289
|
+
const ua = userAgentFor(ctx)
|
|
290
|
+
const started = deps.now()
|
|
291
|
+
const waitMs = (args.wait ?? 30) * 1000
|
|
292
|
+
for (;;) {
|
|
293
|
+
await pollJob(current, provider, { key, fetch, ua })
|
|
294
|
+
await writeJob(ctx.projectRoot, current)
|
|
295
|
+
if (current.status === 'succeeded' || current.status === 'failed') break
|
|
296
|
+
if (deps.now() - started + 5000 > waitMs) break
|
|
297
|
+
await deps.sleep(5000)
|
|
298
|
+
}
|
|
299
|
+
const lines = [`Job ${current.id} (${provider.label} ${current.task}, ${current.model}): ${current.status}.`]
|
|
300
|
+
for (const c of current.candidates) {
|
|
301
|
+
lines.push(
|
|
302
|
+
`- candidate ${c.n}: ${c.status}${Number.isFinite(c.progress) ? `, ${c.progress}%` : ''}${c.stage && c.status !== 'succeeded' ? ` (${c.stage})` : ''}${c.error ? `: ${c.error}` : ''}${c.note ? ` (${c.note})` : ''}`,
|
|
303
|
+
)
|
|
304
|
+
}
|
|
305
|
+
let images = []
|
|
306
|
+
if (current.candidates.some((c) => c.status === 'succeeded')) {
|
|
307
|
+
const got = await downloadResults(ctx.projectRoot, current, provider, { key, fetch, ua })
|
|
308
|
+
await writeJob(ctx.projectRoot, current)
|
|
309
|
+
images = got.thumbnails
|
|
310
|
+
for (const c of current.candidates.filter((c) => c.downloadError)) lines.push(`- candidate ${c.n} could not be downloaded: ${c.downloadError}`)
|
|
311
|
+
for (const id of got.ids) lines.push(`asset_import from ${id} with a class and a size (e.g. as "assets/<name>.glb", class prop, size { height: 0.9 }).`)
|
|
312
|
+
} else if (current.status === 'failed') {
|
|
313
|
+
lines.push(`${provider.label} could not make it. Change the prompt or the picture and estimate again; the spend already recorded stays.`)
|
|
314
|
+
} else {
|
|
315
|
+
lines.push('Still going: call asset_job again in a minute.')
|
|
316
|
+
}
|
|
317
|
+
return { text: lines.join('\n'), ...(images.length ? { images } : {}) }
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
// ---------------------------------------------------------------- the defs
|
|
321
|
+
|
|
322
|
+
/** The ToolDefs, with the clock replaceable for checks. */
|
|
323
|
+
export function makeGenerateTools(overrides = {}) {
|
|
324
|
+
const deps = { now: () => Date.now(), sleep: (ms) => new Promise((r) => setTimeout(r, ms)), ...overrides }
|
|
325
|
+
const guarded = (name, fn) => async (args, ctx) => {
|
|
326
|
+
try {
|
|
327
|
+
return await fn(args, ctx)
|
|
328
|
+
} catch (err) {
|
|
329
|
+
return fail(`${name} failed: ${err?.message ?? err}`)
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
return [
|
|
333
|
+
{ name: 'asset_generate', description: GENERATE_DESCRIPTION, shape: GENERATE_SHAPE, readOnly: false, handler: guarded('asset_generate', (a, c) => generate(a, c)) },
|
|
334
|
+
{ name: 'asset_job', description: JOB_DESCRIPTION, shape: JOB_SHAPE, readOnly: true, handler: guarded('asset_job', (a, c) => job(a, c, deps)) },
|
|
335
|
+
]
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
export const TOOLS = makeGenerateTools()
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// nw_guide: one of the studio's guides (the plugin's skills) read in full, as
|
|
2
|
+
// a tool. Claude loads them with its Skill tool; the other vendors' loop has
|
|
3
|
+
// no such tool, nor do the CLI's MCP clients or a helper that is not given
|
|
4
|
+
// the skill, so each of them reads the same text through this one instead.
|
|
5
|
+
//
|
|
6
|
+
// Electron-free and host-agnostic: harness.mjs serves it from the studio's
|
|
7
|
+
// agent-plugin, and the CLI from its vendored copy of the same skills.
|
|
8
|
+
|
|
9
|
+
import { readFile } from 'node:fs/promises'
|
|
10
|
+
import path from 'node:path'
|
|
11
|
+
import { z } from 'zod'
|
|
12
|
+
|
|
13
|
+
/** What each guide is for, by folder name, for the tool's description. */
|
|
14
|
+
const ABOUT = {
|
|
15
|
+
'tsl-r185': 'the TSL facts on three r186 (node slots, names that exist, how uniforms and Fn behave, what does nothing here, what the studio reports when a material fails)',
|
|
16
|
+
'look-dev': "the planet's look: from the brief's numbers to look_apply values, look_compare and the numbers to judge by",
|
|
17
|
+
'asset-sources': 'where models, materials, skies and sounds come from, best first, and how to use them in code',
|
|
18
|
+
'asset-legality': 'licences, the asset ledger (assets.lock.json) and what publishing refuses',
|
|
19
|
+
'blender-modeling': 'modelling one asset in headless Blender with a bpy script of its own, and reading the sheets and the rubric',
|
|
20
|
+
'art-direction': 'turning a reference into a brief and judging the space against it',
|
|
21
|
+
'sound-design': "the space's sounds by Web Audio synthesis, from the brief's mood and events",
|
|
22
|
+
playtesting: 'playtest scripts with nw_play and nw_eval, and writing a bug that reproduces',
|
|
23
|
+
'reference-loop': 'the loop a space runs: the kickoff card, the target pictures, the brief, rounds judged against the targets, the approval card',
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* The nw_guide tool for the guides in `skillsDir` (one folder per guide, each
|
|
28
|
+
* with its SKILL.md). `names` are the folder names, in the order the
|
|
29
|
+
* description lists them.
|
|
30
|
+
*/
|
|
31
|
+
export function guideDef({ skillsDir, names }) {
|
|
32
|
+
const list = names.map((n) => `${n} (${ABOUT[n] ?? 'an Oda guide'})`).join('; ')
|
|
33
|
+
return {
|
|
34
|
+
name: 'nw_guide',
|
|
35
|
+
description: `Reads one of Oda's guides in full: ${list}. Read the one for the job before you start it: reference-loop before a new space, tsl-r185 before any material, look-dev before the mood, asset-sources before making or fetching any asset, blender-modeling before a Blender script.`,
|
|
36
|
+
shape: { name: z.enum(names).describe('The guide, by name.') },
|
|
37
|
+
readOnly: true,
|
|
38
|
+
handler: async ({ name }) => {
|
|
39
|
+
try {
|
|
40
|
+
return { text: await readFile(path.join(skillsDir, name, 'SKILL.md'), 'utf8') }
|
|
41
|
+
} catch {
|
|
42
|
+
return { text: `The guide ${name} is not in this build.`, isError: true }
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
// The tools that stay with the harness: the SDK's guide and the documents'
|
|
2
|
+
// schemas, the studio's guides (nw_guide, the skills as a tool), the build
|
|
3
|
+
// check, the creator's screen, the spend note, and the agent's hands outside
|
|
4
|
+
// the studio (its own browser and the creator's computer, useTools.mjs). The eyes on the game (nw_view, nw_play, nw_eval,
|
|
5
|
+
// nw_logs, nw_status) are tools/eyes.mjs.
|
|
6
|
+
|
|
7
|
+
import fsp from 'node:fs/promises'
|
|
8
|
+
import path from 'node:path'
|
|
9
|
+
import { z } from 'zod'
|
|
10
|
+
import { LEDGER_FILE, decodeRadiance, isPublishablePath, jsonSchemaFor, lookAdvice, measureSkySun, resolveLook, skySunAdvice, splatAdvice, validateConfig } from '../../schema/dist/index.js'
|
|
11
|
+
import { USE_TOOLS, rpcFor } from '../../useTools.mjs'
|
|
12
|
+
import { adviceUnderBrief, briefCheck } from '../assets/brief.mjs'
|
|
13
|
+
import { PLUGIN_DIR, SKILL_NAMES, sdkDocs } from '../shared.mjs'
|
|
14
|
+
import { perfFor, perfLines, untexturedNote } from './eyes.mjs'
|
|
15
|
+
import { guideDef } from './guide.mjs'
|
|
16
|
+
|
|
17
|
+
export const RPC_METHODS = ['build', 'capture-screen', 'browser', 'computer', 'computer-apps']
|
|
18
|
+
|
|
19
|
+
/** The same words for both loops. */
|
|
20
|
+
export const CAPTURE_DESCRIPTION =
|
|
21
|
+
"Looks at the creator's screen, or one app's window (e.g. Blender), when you need to check something outside the studio: a model you built through a connector, an error dialog, the state of another app mid-task. The creator is asked first and can refuse; say why in reason. frames > 1 takes that many shots a few seconds apart, a short recording. Use it when seeing is the only way to know, not by habit."
|
|
22
|
+
|
|
23
|
+
/** Browser tools that only look; navigating changes nothing in the project. */
|
|
24
|
+
const BROWSER_READS = new Set(['browser_navigate', 'browser_read_page', 'browser_find', 'browser_get_text', 'browser_tabs', 'browser_console'])
|
|
25
|
+
|
|
26
|
+
const usd = (n) => `$${n.toFixed(2)}`
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* What the look leaves to the engine, for nw_check: look values and light
|
|
30
|
+
* left to their defaults and a sky of kind none unless the brief picks none
|
|
31
|
+
* (lookAdvice, adviceUnderBrief), and under an
|
|
32
|
+
* HDRI how far lighting.sun stands from the picture's own sun
|
|
33
|
+
* (skySunAdvice). The CLI's check says the same (packages/cli/lib/project.mjs).
|
|
34
|
+
*/
|
|
35
|
+
export async function lookWarnings(projectRoot) {
|
|
36
|
+
if (!projectRoot) return []
|
|
37
|
+
let raw
|
|
38
|
+
try {
|
|
39
|
+
raw = JSON.parse(await fsp.readFile(path.join(projectRoot, 'game.config.json'), 'utf8'))
|
|
40
|
+
} catch {
|
|
41
|
+
return []
|
|
42
|
+
}
|
|
43
|
+
const out = await adviceUnderBrief(projectRoot, lookAdvice(raw))
|
|
44
|
+
const sky = raw?.sky
|
|
45
|
+
if (sky?.kind === 'hdri' && typeof sky.asset === 'string' && /\.hdr$/i.test(sky.asset)) {
|
|
46
|
+
try {
|
|
47
|
+
const picture = decodeRadiance(new Uint8Array(await fsp.readFile(path.join(projectRoot, sky.asset))))
|
|
48
|
+
if (picture) {
|
|
49
|
+
const checked = validateConfig(raw)
|
|
50
|
+
const light = resolveLook(checked.ok ? checked.config : raw).environment.intensity
|
|
51
|
+
out.push(...skySunAdvice(raw, measureSkySun({ ...picture, channels: 3, topRowFirst: true }), light))
|
|
52
|
+
}
|
|
53
|
+
} catch {
|
|
54
|
+
// A sky that cannot be read is the build's and the ledger's to say.
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return out
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* A planet's splat environments, for nw_check (schema splatAdvice): more
|
|
62
|
+
* splats in all than a planet may draw, and a planet with splats past the
|
|
63
|
+
* size it aims for. The CLI's check says the same (packages/cli/lib/project.mjs).
|
|
64
|
+
*/
|
|
65
|
+
export async function splatWarnings(projectRoot) {
|
|
66
|
+
if (!projectRoot) return []
|
|
67
|
+
let files
|
|
68
|
+
try {
|
|
69
|
+
files = JSON.parse(await fsp.readFile(path.join(projectRoot, LEDGER_FILE), 'utf8'))?.files
|
|
70
|
+
} catch {
|
|
71
|
+
return []
|
|
72
|
+
}
|
|
73
|
+
let bytes = 0
|
|
74
|
+
const dir = path.join(projectRoot, 'assets')
|
|
75
|
+
for (const name of await fsp.readdir(dir).catch(() => [])) {
|
|
76
|
+
if (!isPublishablePath(`assets/${name}`)) continue
|
|
77
|
+
bytes += (await fsp.stat(path.join(dir, name)).catch(() => ({ size: 0 }))).size
|
|
78
|
+
}
|
|
79
|
+
return splatAdvice(files, bytes)
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export const TOOLS = [
|
|
83
|
+
{
|
|
84
|
+
name: 'nw_docs',
|
|
85
|
+
description:
|
|
86
|
+
'The @nowhere/sdk guide: the World API (objects, rules, the visitor and how it moves), the createGame contract, the Oda platform rules, and a closing section on visitor health, hazards and items. Read this before writing code for the first time in a session.',
|
|
87
|
+
shape: {},
|
|
88
|
+
readOnly: true,
|
|
89
|
+
handler: async () => ({ text: sdkDocs() }),
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
name: 'nw_schema',
|
|
93
|
+
description:
|
|
94
|
+
'The exact JSON Schema for a project document. "config" is game.config.json (planet size, sky, fog, lighting, ground, bloom). "scene" is scene.json, the objects the creator placed by hand. "brief" is brief.json, the space brief: its references and what was measured from them, palette, light, scale, materials with their texel density, hero views, what its files may weigh and its sources. "style" is style.json, how the space is drawn: its medium, the works it is read from, shape, line, shading, surface, palette, rules and the look\'s drawing techniques, written before any target picture. Call before editing any of them.',
|
|
95
|
+
shape: { kind: z.enum(['config', 'scene', 'brief', 'style']).default('config') },
|
|
96
|
+
readOnly: true,
|
|
97
|
+
handler: async ({ kind }) => ({ text: JSON.stringify(jsonSchemaFor(kind ?? 'config'), null, 2) }),
|
|
98
|
+
},
|
|
99
|
+
// The skills as a tool, for the loop without a Skill tool and for helpers.
|
|
100
|
+
guideDef({ skillsDir: path.join(PLUGIN_DIR, 'skills'), names: SKILL_NAMES.map((n) => n.replace(/^nowhere:/, '')) }),
|
|
101
|
+
{
|
|
102
|
+
name: 'nw_check',
|
|
103
|
+
description:
|
|
104
|
+
'Builds the space, mounts it in the viewport and lets it run for a moment, then reports compile errors, anything it threw while running, and every material that failed to build (drawn flat black, with its mesh and the line); its warnings name WebGL habits that do nothing here and the TSL way instead, and the large surfaces in the player\'s view whose colour carries no texture (measured once the space\'s files have arrived). It ends with perf: the frame time at each tier against its limit (high 16.7 ms, low 33 ms at p95), the worst of the spawn view and each hero view of brief.json, measured only when the project changed since the last one (it shows those views in the viewport for about 10 to 30 seconds, longer while the space is still loading). Call after every batch of edits; never claim you are done while this fails.',
|
|
105
|
+
shape: {},
|
|
106
|
+
verifies: 'check',
|
|
107
|
+
handler: async (_args, ctx) => {
|
|
108
|
+
// The host's rpc notes the build, so a view after it does not build again.
|
|
109
|
+
const r = await ctx.rpc('build')
|
|
110
|
+
// The space brief, when there is one, is checked with the build: the
|
|
111
|
+
// tools hold the work to it, so a broken one fails the check.
|
|
112
|
+
const brief = ctx?.projectRoot ? await briefCheck(ctx.projectRoot) : { ok: true, lines: [] }
|
|
113
|
+
const briefText = brief.lines.length ? `\n${brief.lines.join('\n')}` : ''
|
|
114
|
+
// The build's warnings go with a failure too: they carry the file and
|
|
115
|
+
// line (a ShaderMaterial at src/x.ts:5) that a runtime finding has not.
|
|
116
|
+
if (!r?.ok) {
|
|
117
|
+
const also = Array.isArray(r?.warnings) && r.warnings.length ? `\nWarnings:\n${r.warnings.map((w) => `- ${w}`).join('\n')}` : ''
|
|
118
|
+
return { text: `CHECK FAILED:\n${r?.error ?? 'The studio did not answer.'}${also}${brief.ok ? '' : briefText}`, isError: true }
|
|
119
|
+
}
|
|
120
|
+
if (!brief.ok) return { text: `CHECK FAILED: the space builds, but ${brief.lines.join('\n')}`, isError: true }
|
|
121
|
+
// What the build let through but may throw once that code runs (a
|
|
122
|
+
// namespace member three does not have, read in a callback).
|
|
123
|
+
const warned = Array.isArray(r.warnings) && r.warnings.length ? `\nWarnings (the game builds and runs; fix these too):\n${r.warnings.map((w) => `- ${w}`).join('\n')}` : ''
|
|
124
|
+
// What the look leaves to the engine, to set from the brief.
|
|
125
|
+
const lookLines = await lookWarnings(ctx.projectRoot)
|
|
126
|
+
const splatLines = await splatWarnings(ctx.projectRoot)
|
|
127
|
+
const looked =
|
|
128
|
+
(lookLines.length ? `\nThe look (set these from the brief):\n${lookLines.map((w) => `- ${w}`).join('\n')}` : '') +
|
|
129
|
+
(splatLines.length ? `\nSplats:\n${splatLines.map((w) => `- ${w}`).join('\n')}` : '')
|
|
130
|
+
// Only a build that ran counts as checked: one the viewport holds while
|
|
131
|
+
// the creator plays, or never reported on, has not run yet.
|
|
132
|
+
if (r.ran) {
|
|
133
|
+
// Untextured surfaces in the player's view: a warning, never a failure.
|
|
134
|
+
const flat = await untexturedNote(ctx.rpc)
|
|
135
|
+
// Frame time at each tier: said, and kept for the stop gate; over
|
|
136
|
+
// budget is the gate's to hold, not a failed check.
|
|
137
|
+
const timed = await perfFor(ctx)
|
|
138
|
+
const unkept = timed.unkept ? `\n- not kept, so the next nw_check measures again: ${timed.unkept}` : ''
|
|
139
|
+
const perfText = timed.perf ? `\nFrame time (perf):\n${perfLines(timed.perf).map((l) => `- ${l}`).join('\n')}${unkept}\nperf: ${JSON.stringify(timed.perf)}` : `\nFrame time was not measured: ${timed.error}`
|
|
140
|
+
return { text: `It compiles, mounts and runs without throwing.${warned}${looked}${briefText}${flat ? `\n${flat}` : ''}${perfText}`, ...(timed.perf ? { perf: timed.perf } : {}) }
|
|
141
|
+
}
|
|
142
|
+
return { text: `${`It compiles. ${r.note ?? ''}`.trim()}${warned}${looked}${briefText}`, verifies: null }
|
|
143
|
+
},
|
|
144
|
+
},
|
|
145
|
+
{
|
|
146
|
+
name: 'nw_capture_screen',
|
|
147
|
+
description: CAPTURE_DESCRIPTION,
|
|
148
|
+
shape: {
|
|
149
|
+
reason: z.string().describe('One short sentence for the creator, in the screen language (the studio context names it) like every word on a card: what you want to see and why. They read it on the consent card before they allow it.'),
|
|
150
|
+
app: z.string().optional().describe('Part of an app window\'s name, e.g. "Blender", to see only that window. Leave out for the whole screen.'),
|
|
151
|
+
frames: z.number().int().min(1).max(6).default(1).describe('How many shots. More than one is a short recording.'),
|
|
152
|
+
interval: z.number().min(0.5).max(5).default(1).describe('Seconds between shots when frames > 1.'),
|
|
153
|
+
},
|
|
154
|
+
readOnly: true,
|
|
155
|
+
mainOnly: true,
|
|
156
|
+
handler: async ({ reason, app, frames, interval }, ctx) => {
|
|
157
|
+
const r = await ctx.rpc('capture-screen', { reason, app: app?.trim() || null, frames: frames ?? 1, interval: interval ?? 1 })
|
|
158
|
+
if (!r?.ok) return { text: r?.error ?? 'It did not work.', isError: true }
|
|
159
|
+
return { text: r.note, images: r.images }
|
|
160
|
+
},
|
|
161
|
+
},
|
|
162
|
+
{
|
|
163
|
+
name: 'nw_spend',
|
|
164
|
+
description:
|
|
165
|
+
"Records what a paid generation call cost, in US dollars, from the vendor's answer or its price list, so the creator's running total is right. Call it after every paid call.",
|
|
166
|
+
shape: {
|
|
167
|
+
usd: z.number().min(0).max(1000).describe('What the call cost, in US dollars.'),
|
|
168
|
+
what: z.string().max(120).describe('The service and the job, e.g. "Meshy text-to-3D".'),
|
|
169
|
+
},
|
|
170
|
+
readOnly: true,
|
|
171
|
+
handler: async ({ usd: amount, what }, ctx) => {
|
|
172
|
+
ctx.ledger?.addGeneration(amount, what)
|
|
173
|
+
const spent = ctx.ledger?.spentUsd?.()
|
|
174
|
+
const approved = ctx.ledger?.approvedUsd?.()
|
|
175
|
+
const total = typeof spent === 'number' ? ` This request so far: ${usd(spent)}${typeof approved === 'number' ? ` (approved ${usd(approved)})` : ''}.` : ''
|
|
176
|
+
return { text: `Noted ${usd(amount)} for ${what}.${total}` }
|
|
177
|
+
},
|
|
178
|
+
},
|
|
179
|
+
// The browser and the computer (useTools.mjs), served by the main process.
|
|
180
|
+
...USE_TOOLS.map((use) => ({
|
|
181
|
+
name: use.name,
|
|
182
|
+
description: use.description,
|
|
183
|
+
shape: use.shape,
|
|
184
|
+
readOnly: BROWSER_READS.has(use.name),
|
|
185
|
+
// Helpers never drive the creator's computer or the browser beside it.
|
|
186
|
+
mainOnly: true,
|
|
187
|
+
handler: async (args, ctx) => {
|
|
188
|
+
const r = await ctx.rpc(...rpcFor(use, args))
|
|
189
|
+
if (!r?.ok) return { text: r?.error ?? 'It did not work.', isError: true }
|
|
190
|
+
return { text: r.text ?? 'Done.', images: r.images }
|
|
191
|
+
},
|
|
192
|
+
})),
|
|
193
|
+
]
|