oda-engine 0.0.0-stage → 0.1.1
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 +131 -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-CptQkDVX.js +1 -0
- package/web-dist/assets/KTX2Loader-C53LJqss.js +2 -0
- package/web-dist/assets/SPZLoader-BQ3tjaTv.js +1 -0
- package/web-dist/assets/gaussianSplat-_9tcWegB.js +1 -0
- package/web-dist/assets/index-Baka-ZO7.js +693 -0
- package/web-dist/assets/index-CcjyyQco.css +1 -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,254 @@
|
|
|
1
|
+
// The asset tools' one way onto the network. Every request names the studio
|
|
2
|
+
// in its User-Agent (Poly Haven asks for that), goes only to the hosts the
|
|
3
|
+
// source or vendor lists, and follows redirects by hand so each hop is
|
|
4
|
+
// checked again: against that list, and against the hosts whose terms forbid
|
|
5
|
+
// feeding their pictures to AI tools (ArtStation, Pinterest, Behance), which
|
|
6
|
+
// nothing here ever reaches whatever a redirect says.
|
|
7
|
+
//
|
|
8
|
+
// fetch is the caller's (ctx.fetch ?? globalThis.fetch), so the checks drive
|
|
9
|
+
// all of it with fakes and never touch the network.
|
|
10
|
+
|
|
11
|
+
import { createHash } from 'node:crypto'
|
|
12
|
+
import { createWriteStream } from 'node:fs'
|
|
13
|
+
import fsp from 'node:fs/promises'
|
|
14
|
+
import { createRequire } from 'node:module'
|
|
15
|
+
import path from 'node:path'
|
|
16
|
+
import { fileURLToPath } from 'node:url'
|
|
17
|
+
|
|
18
|
+
const require = createRequire(import.meta.url)
|
|
19
|
+
const { blockedHost } = require('../downloads.cjs')
|
|
20
|
+
|
|
21
|
+
const here = path.dirname(fileURLToPath(import.meta.url))
|
|
22
|
+
|
|
23
|
+
let version = null
|
|
24
|
+
function studioVersion() {
|
|
25
|
+
if (version) return version
|
|
26
|
+
try {
|
|
27
|
+
version = JSON.parse(require('node:fs').readFileSync(path.join(here, '..', '..', '..', 'package.json'), 'utf8')).version ?? '0'
|
|
28
|
+
} catch {
|
|
29
|
+
version = '0'
|
|
30
|
+
}
|
|
31
|
+
return version
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** What every request says it is (spec 2.10). */
|
|
35
|
+
export function userAgentFor(ctx) {
|
|
36
|
+
if (ctx?.userAgent) return ctx.userAgent
|
|
37
|
+
return ctx?.host === 'cli'
|
|
38
|
+
? `oda-engine/${ctx?.version ?? studioVersion()}`
|
|
39
|
+
: `nowhere-studio/${studioVersion()} (+https://nowhere-studio.vercel.app)`
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export const fetchOf = (ctx) => ctx?.fetch ?? globalThis.fetch
|
|
43
|
+
|
|
44
|
+
export class NetError extends Error {
|
|
45
|
+
constructor(message, code) {
|
|
46
|
+
super(message)
|
|
47
|
+
this.code = code
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** Whether a host is one of `hosts`: an exact name, or '*.example.com' for
|
|
52
|
+
* any subdomain of it. */
|
|
53
|
+
export function hostAllowed(host, hosts) {
|
|
54
|
+
const h = String(host ?? '').toLowerCase()
|
|
55
|
+
return hosts.some((rule) => {
|
|
56
|
+
const r = rule.toLowerCase()
|
|
57
|
+
return r.startsWith('*.') ? h.endsWith(r.slice(1)) && h.length > r.length - 1 : h === r
|
|
58
|
+
})
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** Refuses a URL before it is asked for: not https, a blocked host, or a host
|
|
62
|
+
* off the list. Returns the parsed URL. */
|
|
63
|
+
export function checkUrl(url, hosts) {
|
|
64
|
+
let u
|
|
65
|
+
try {
|
|
66
|
+
u = new URL(String(url))
|
|
67
|
+
} catch {
|
|
68
|
+
throw new NetError(`"${url}" is not a URL.`, 'bad-url')
|
|
69
|
+
}
|
|
70
|
+
if (blockedHost(u.href)) {
|
|
71
|
+
throw new NetError(`${u.hostname} is ArtStation, Pinterest or Behance, whose terms forbid feeding their images to AI tools; nothing is fetched from there.`, 'blocked')
|
|
72
|
+
}
|
|
73
|
+
if (u.protocol !== 'https:') throw new NetError(`${u.href} is not https.`, 'bad-url')
|
|
74
|
+
if (!hostAllowed(u.hostname, hosts)) throw new NetError(`${u.hostname} is not one of the hosts this source uses (${hosts.join(', ')}), so it was not asked.`, 'host')
|
|
75
|
+
return u
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* A request that follows at most `maxRedirects` redirects, each hop checked
|
|
80
|
+
* against `hosts` and the blocked list. Resolves with the final response and
|
|
81
|
+
* the URLs it went through.
|
|
82
|
+
*/
|
|
83
|
+
export async function safeFetch(url, { fetch, hosts, method = 'GET', headers = {}, body, ua, signal, maxRedirects = 5 } = {}) {
|
|
84
|
+
if (typeof fetch !== 'function') throw new NetError('This host has no fetch.', 'no-fetch')
|
|
85
|
+
let current = checkUrl(url, hosts)
|
|
86
|
+
const chain = [current.href]
|
|
87
|
+
for (let hop = 0; ; hop++) {
|
|
88
|
+
const res = await fetch(current.href, {
|
|
89
|
+
method,
|
|
90
|
+
headers: { 'user-agent': ua, ...headers },
|
|
91
|
+
...(body !== undefined ? { body } : {}),
|
|
92
|
+
redirect: 'manual',
|
|
93
|
+
signal,
|
|
94
|
+
})
|
|
95
|
+
if (res.status >= 300 && res.status < 400 && res.status !== 304) {
|
|
96
|
+
const location = res.headers?.get?.('location')
|
|
97
|
+
if (!location) throw new NetError(`${current.hostname} answered ${res.status} without saying where to.`, 'redirect')
|
|
98
|
+
if (hop >= maxRedirects) throw new NetError(`More than ${maxRedirects} redirects from ${chain[0]}.`, 'redirect')
|
|
99
|
+
await res.body?.cancel?.().catch?.(() => {})
|
|
100
|
+
const next = new URL(location, current)
|
|
101
|
+
// The same checks for every hop: a source cannot hand the request on to
|
|
102
|
+
// a host it does not list, or to a blocked one.
|
|
103
|
+
current = checkUrl(next.href, hosts)
|
|
104
|
+
chain.push(current.href)
|
|
105
|
+
// A redirect after a POST is a GET for the new place, as browsers do.
|
|
106
|
+
if (res.status === 303) {
|
|
107
|
+
method = 'GET'
|
|
108
|
+
body = undefined
|
|
109
|
+
}
|
|
110
|
+
continue
|
|
111
|
+
}
|
|
112
|
+
return { res, chain, url: current.href }
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** A JSON answer, or a NetError that says what the server said. */
|
|
117
|
+
export async function fetchJson(url, opts) {
|
|
118
|
+
const { res, url: finalUrl } = await safeFetch(url, opts)
|
|
119
|
+
const text = await res.text()
|
|
120
|
+
if (!res.ok) {
|
|
121
|
+
let detail = text.slice(0, 200)
|
|
122
|
+
try {
|
|
123
|
+
const j = JSON.parse(text)
|
|
124
|
+
// OpenAI and Google nest it ({ error: { message } }); Stability lists it.
|
|
125
|
+
const said = j?.error?.message ?? j?.error ?? j?.message ?? j?.detail ?? (Array.isArray(j?.errors) ? j.errors.map((e) => e?.message ?? e).join('; ') : null)
|
|
126
|
+
detail = String(said ?? detail).slice(0, 200)
|
|
127
|
+
} catch {
|
|
128
|
+
// the raw text, trimmed
|
|
129
|
+
}
|
|
130
|
+
throw new NetError(`${new URL(finalUrl).hostname} answered ${res.status}${detail ? `: ${detail}` : ''}`, res.status === 401 || res.status === 403 ? 'auth' : 'status')
|
|
131
|
+
}
|
|
132
|
+
try {
|
|
133
|
+
return JSON.parse(text)
|
|
134
|
+
} catch {
|
|
135
|
+
throw new NetError(`${new URL(finalUrl).hostname} did not answer with JSON.`, 'json')
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/** The chunks of a fetch response body, whichever shape it has. */
|
|
140
|
+
async function* chunksOf(body) {
|
|
141
|
+
if (!body) return
|
|
142
|
+
if (typeof body.getReader === 'function') {
|
|
143
|
+
const reader = body.getReader()
|
|
144
|
+
try {
|
|
145
|
+
for (;;) {
|
|
146
|
+
const { done, value } = await reader.read()
|
|
147
|
+
if (done) return
|
|
148
|
+
yield value
|
|
149
|
+
}
|
|
150
|
+
} finally {
|
|
151
|
+
reader.releaseLock?.()
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
if (typeof body[Symbol.asyncIterator] === 'function') {
|
|
155
|
+
for await (const chunk of body) yield chunk
|
|
156
|
+
return
|
|
157
|
+
}
|
|
158
|
+
yield body
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Streams one file to `toFile` through a `.part` file, with a running byte
|
|
163
|
+
* cap that stops mid-stream, then checks the size and md5 when the source
|
|
164
|
+
* gave them. The part file is removed on any failure; only a whole, checked
|
|
165
|
+
* file gets its real name.
|
|
166
|
+
*
|
|
167
|
+
* @returns {Promise<{ bytes: number, md5: string, sha256: string, url: string, host: string }>}
|
|
168
|
+
*/
|
|
169
|
+
export async function download(url, toFile, { fetch, hosts, ua, maxBytes, size, md5, headers, signal } = {}) {
|
|
170
|
+
const part = `${toFile}.part`
|
|
171
|
+
await fsp.mkdir(path.dirname(toFile), { recursive: true })
|
|
172
|
+
const { res, url: finalUrl } = await safeFetch(url, { fetch, hosts, ua, headers, signal })
|
|
173
|
+
if (!res.ok) {
|
|
174
|
+
await res.body?.cancel?.().catch?.(() => {})
|
|
175
|
+
throw new NetError(`${new URL(finalUrl).hostname} answered ${res.status} for ${path.basename(toFile)}.`, 'status')
|
|
176
|
+
}
|
|
177
|
+
const declared = Number(res.headers?.get?.('content-length'))
|
|
178
|
+
if (Number.isFinite(declared) && declared > maxBytes) {
|
|
179
|
+
await res.body?.cancel?.().catch?.(() => {})
|
|
180
|
+
throw new NetError(`${path.basename(toFile)} is ${mbOf(declared)} MB, over the ${mbOf(maxBytes)} MB this download may be.`, 'cap')
|
|
181
|
+
}
|
|
182
|
+
const md5h = createHash('md5')
|
|
183
|
+
const shah = createHash('sha256')
|
|
184
|
+
let bytes = 0
|
|
185
|
+
const out = createWriteStream(part)
|
|
186
|
+
const closed = new Promise((resolve, reject) => {
|
|
187
|
+
out.on('close', resolve)
|
|
188
|
+
out.on('error', reject)
|
|
189
|
+
})
|
|
190
|
+
try {
|
|
191
|
+
for await (const raw of chunksOf(res.body)) {
|
|
192
|
+
const chunk = raw instanceof Uint8Array ? raw : Buffer.from(raw)
|
|
193
|
+
bytes += chunk.byteLength
|
|
194
|
+
if (bytes > maxBytes) {
|
|
195
|
+
// Stopped as soon as it passes the cap, not after the whole file.
|
|
196
|
+
throw new NetError(`${path.basename(toFile)} passed the ${mbOf(maxBytes)} MB this download may be, so it was stopped.`, 'cap')
|
|
197
|
+
}
|
|
198
|
+
md5h.update(chunk)
|
|
199
|
+
shah.update(chunk)
|
|
200
|
+
if (!out.write(chunk)) await new Promise((r) => out.once('drain', r))
|
|
201
|
+
}
|
|
202
|
+
out.end()
|
|
203
|
+
await closed
|
|
204
|
+
} catch (err) {
|
|
205
|
+
out.destroy()
|
|
206
|
+
await closed.catch(() => {})
|
|
207
|
+
await fsp.rm(part, { force: true })
|
|
208
|
+
try {
|
|
209
|
+
await res.body?.cancel?.()
|
|
210
|
+
} catch {
|
|
211
|
+
// already done
|
|
212
|
+
}
|
|
213
|
+
throw err
|
|
214
|
+
}
|
|
215
|
+
const digest = md5h.digest('hex')
|
|
216
|
+
const problem =
|
|
217
|
+
size !== undefined && size !== null && Number.isFinite(Number(size)) && Number(size) !== bytes
|
|
218
|
+
? `${path.basename(toFile)} is ${bytes} bytes; the source said ${size}`
|
|
219
|
+
: md5 && String(md5).toLowerCase() !== digest
|
|
220
|
+
? `${path.basename(toFile)} does not match its md5 checksum (the download is damaged or was changed on the way)`
|
|
221
|
+
: null
|
|
222
|
+
if (problem) {
|
|
223
|
+
await fsp.rm(part, { force: true })
|
|
224
|
+
throw new NetError(`${problem}, so it was deleted.`, 'checksum')
|
|
225
|
+
}
|
|
226
|
+
await fsp.rename(part, toFile)
|
|
227
|
+
return { bytes, md5: digest, sha256: shah.digest('hex'), url: finalUrl, host: new URL(finalUrl).hostname }
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
export const mbOf = (bytes) => (bytes / (1024 * 1024)).toFixed(bytes < 1024 * 1024 ? 2 : 1)
|
|
231
|
+
|
|
232
|
+
/** The kind of picture bytes are, by their magic, for tool results (which
|
|
233
|
+
* take PNG and JPEG only). */
|
|
234
|
+
export function imageMime(buf) {
|
|
235
|
+
if (!buf || buf.length < 4) return null
|
|
236
|
+
if (buf[0] === 0x89 && buf[1] === 0x50 && buf[2] === 0x4e && buf[3] === 0x47) return 'image/png'
|
|
237
|
+
if (buf[0] === 0xff && buf[1] === 0xd8 && buf[2] === 0xff) return 'image/jpeg'
|
|
238
|
+
return null
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/** A small picture to show the model, or null: PNG or JPEG only, at most
|
|
242
|
+
* `maxBytes`, from an allowed host. */
|
|
243
|
+
export async function fetchThumbnail(url, { fetch, hosts, ua, maxBytes = 512 * 1024 }) {
|
|
244
|
+
try {
|
|
245
|
+
const { res } = await safeFetch(url, { fetch, hosts, ua })
|
|
246
|
+
if (!res.ok) return null
|
|
247
|
+
const buf = Buffer.from(await res.arrayBuffer())
|
|
248
|
+
if (buf.length > maxBytes) return null
|
|
249
|
+
const mime = imageMime(buf)
|
|
250
|
+
return mime ? { data: buf.toString('base64'), mime } : null
|
|
251
|
+
} catch {
|
|
252
|
+
return null
|
|
253
|
+
}
|
|
254
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"checked": "2026-10-19",
|
|
3
|
+
"note": "Upper and lower prices as the vendors' pages gave them on that day; verify before a release. Meshy bills credits: creditUsd is the price of one credit (top-up packs to the smallest plan), each task its credits (multi-image-to-3d read on Meshy's pricing page on 2026-10-22: 30 credits textured, as image-to-3d). fal bills per request. Tripo bills credits at $0.01 each (pay as you go from $1; its block has its own checked date): per model family (h: v3.x and v2.5, p1, p2) the standard-texture credits of each task, and the add-ons a tier above standard would cost; failed and cancelled tasks are not charged.",
|
|
4
|
+
"meshy": { "creditUsd": [0.0125, 0.02], "text-to-3d": 30, "image-to-3d": 30, "multi-image-to-3d": 30, "remesh": 5, "rig": 5 },
|
|
5
|
+
"fal": { "fal-ai/trellis-2": [0.25, 0.35] },
|
|
6
|
+
"tripo": {
|
|
7
|
+
"checked": "2026-10-22",
|
|
8
|
+
"creditUsd": [0.01, 0.01],
|
|
9
|
+
"h": { "text-to-3d": 20, "image-to-3d": 30, "multi-image-to-3d": 30 },
|
|
10
|
+
"p1": { "text-to-3d": 40, "image-to-3d": 50, "multi-image-to-3d": 50 },
|
|
11
|
+
"p2": { "text-to-3d": 110, "image-to-3d": 110, "multi-image-to-3d": 110 },
|
|
12
|
+
"addons": { "detailedTexture": 10, "extremeTexture": 20, "detailedGeometry": 20 }
|
|
13
|
+
},
|
|
14
|
+
"worldlabs": {
|
|
15
|
+
"checked": "2026-10-24",
|
|
16
|
+
"note": "World Labs' World API pricing page that day: 1,250 credits to the dollar (at least 6,250 bought at a time). world: the world generation event, lower and upper, per model (marble-1.1-plus adds up to 1,500 for a big world); pano: the panorama made first, by input (none for a picture that is a panorama already). The collider and the SPZ files come with every world; a high-quality mesh export (3,500) is never asked for here.",
|
|
17
|
+
"creditUsd": 0.0008,
|
|
18
|
+
"world": { "marble-1.1": [1500, 1500], "marble-1.0": [1500, 1500], "marble-1.1-plus": [1500, 3000], "marble-1.0-draft": [150, 150] },
|
|
19
|
+
"pano": { "text": 80, "image": 80, "pano": 0 }
|
|
20
|
+
},
|
|
21
|
+
"images": {
|
|
22
|
+
"checked": "2026-10-22",
|
|
23
|
+
"note": "One picture each, lower and upper, as the vendors' own pages gave them that day (OpenAI's image guide and pricing page, Google's Gemini API pricing page, fal's model pages, Stability's pricing page); verify before a release. openai: per picture by quality at 1024x1024 (the guide's GPT Image 2 table, which it says the 2.5 models bill at the same rate: $30 per million image output tokens), and input: an allowance for each picture sent with it ($8 per million image input tokens). gemini: per 1K picture, input an allowance per picture sent. fal: the first megapixel of output, then $0.015 for each further megapixel of input or output (two inputs at most here). stability: credits of $0.01. codex: the creator's own ChatGPT plan, so nothing on the cost card; it needs the creator's consent instead.",
|
|
24
|
+
"openai": {
|
|
25
|
+
"gpt-image-2.5-flare": { "low": 0.006, "medium": 0.053, "high": 0.211, "input": 0.015 },
|
|
26
|
+
"gpt-image-2.5-sunburst": { "low": 0.006, "medium": 0.053, "high": 0.211, "input": 0.015 }
|
|
27
|
+
},
|
|
28
|
+
"gemini": {
|
|
29
|
+
"gemini-nano-banana-2.1": { "1K": 0.0336, "2K": 0.0504, "input": 0.002 },
|
|
30
|
+
"gemini-3-pro-image": { "1K": 0.134, "2K": 0.134, "input": 0.0011 }
|
|
31
|
+
},
|
|
32
|
+
"fal": {
|
|
33
|
+
"fal-ai/flux-2-pro": [0.03, 0.03],
|
|
34
|
+
"fal-ai/flux-2-pro/edit": [0.045, 0.06]
|
|
35
|
+
},
|
|
36
|
+
"stability": { "creditUsd": 0.01, "ultra": 8 },
|
|
37
|
+
"codex": { "usd": 0, "plan": "ChatGPT" }
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
// fal: hosted models through its queue API with the creator's key
|
|
2
|
+
// (connector fal, env FAL_KEY, Authorization: Key ...). The queue shape is
|
|
3
|
+
// fal's documented one (read 2026-10-19), NOT exercised against the live API
|
|
4
|
+
// from here: the checks use a fake. Verify one real job before release.
|
|
5
|
+
//
|
|
6
|
+
// POST https://queue.fal.run/{model} input JSON -> { request_id, status_url, response_url }
|
|
7
|
+
// GET status_url -> { status: IN_QUEUE | IN_PROGRESS | COMPLETED, queue_position }
|
|
8
|
+
// GET response_url -> the model's output (files on fal.media)
|
|
9
|
+
//
|
|
10
|
+
// Only the models in MODELS are taken, each with the licence of what it makes
|
|
11
|
+
// and the price prices.json gives; an unknown model's output licence is
|
|
12
|
+
// unknown, and asset_import refuses that, so it is refused before it costs
|
|
13
|
+
// anything. Hunyuan3D is refused by name: its open weights' licence does not
|
|
14
|
+
// cover Korea, the EU or the UK.
|
|
15
|
+
|
|
16
|
+
import { fetchJson } from '../net.mjs'
|
|
17
|
+
|
|
18
|
+
const QUEUE = 'https://queue.fal.run'
|
|
19
|
+
|
|
20
|
+
/** The models asset_generate may run on fal. */
|
|
21
|
+
export const MODELS = {
|
|
22
|
+
'fal-ai/trellis-2': {
|
|
23
|
+
tasks: ['image-to-3d'],
|
|
24
|
+
// TRELLIS.2's weights are MIT and fal's terms give the output to the
|
|
25
|
+
// caller, so what it makes is the creator's.
|
|
26
|
+
license: { spdx: 'LicenseRef-Generated-Owned', url: 'https://fal.ai/terms' },
|
|
27
|
+
input: ({ imageDataUri }) => ({ image_url: imageDataUri }),
|
|
28
|
+
},
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** The first GLB (and picture) anywhere in a model's output. */
|
|
32
|
+
function findOutputs(value, found = { glb: null, image: null }) {
|
|
33
|
+
if (!value || typeof value !== 'object') return found
|
|
34
|
+
if (Array.isArray(value)) {
|
|
35
|
+
for (const v of value) findOutputs(v, found)
|
|
36
|
+
return found
|
|
37
|
+
}
|
|
38
|
+
const url = typeof value.url === 'string' ? value.url : null
|
|
39
|
+
if (url) {
|
|
40
|
+
const type = String(value.content_type ?? '')
|
|
41
|
+
if (!found.glb && (/\.glb(\?|$)/i.test(url) || type === 'model/gltf-binary')) found.glb = url
|
|
42
|
+
else if (!found.image && (/\.(png|jpe?g)(\?|$)/i.test(url) || /^image\/(png|jpeg)$/.test(type))) found.image = url
|
|
43
|
+
}
|
|
44
|
+
for (const v of Object.values(value)) findOutputs(v, found)
|
|
45
|
+
return found
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export const fal = {
|
|
49
|
+
id: 'fal',
|
|
50
|
+
label: 'fal',
|
|
51
|
+
connector: 'fal',
|
|
52
|
+
envVar: 'FAL_KEY',
|
|
53
|
+
hosts: ['queue.fal.run', 'fal.run', 'fal.media', '*.fal.media'],
|
|
54
|
+
tasks: ['image-to-3d'],
|
|
55
|
+
|
|
56
|
+
defaultModel() {
|
|
57
|
+
return 'fal-ai/trellis-2'
|
|
58
|
+
},
|
|
59
|
+
|
|
60
|
+
licenseOf(model) {
|
|
61
|
+
return MODELS[model]?.license ?? { spdx: 'LicenseRef-Unknown' }
|
|
62
|
+
},
|
|
63
|
+
|
|
64
|
+
price(_task, model, prices) {
|
|
65
|
+
const p = prices?.fal?.[model]
|
|
66
|
+
if (!Array.isArray(p) || !p.every(Number.isFinite)) return null
|
|
67
|
+
return { low: p[0], high: p[1], unit: 'per request' }
|
|
68
|
+
},
|
|
69
|
+
|
|
70
|
+
/** Why a model cannot run for a task, or null. */
|
|
71
|
+
refuse(task, model) {
|
|
72
|
+
if (!MODELS[model]) return `fal model ${model} is not in the studio's table, so the licence of what it makes is unknown and asset_import would refuse it. Use one of: ${Object.keys(MODELS).join(', ')}.`
|
|
73
|
+
if (!MODELS[model].tasks.includes(task)) return `${model} does ${MODELS[model].tasks.join(' and ')}, not ${task}.`
|
|
74
|
+
return null
|
|
75
|
+
},
|
|
76
|
+
|
|
77
|
+
async submit({ task, model, imageDataUri, prompt, key, fetch, ua }) {
|
|
78
|
+
const entry = MODELS[model]
|
|
79
|
+
const r = await fetchJson(`${QUEUE}/${model}`, {
|
|
80
|
+
fetch,
|
|
81
|
+
hosts: fal.hosts,
|
|
82
|
+
ua,
|
|
83
|
+
method: 'POST',
|
|
84
|
+
headers: { authorization: `Key ${key}`, 'content-type': 'application/json' },
|
|
85
|
+
body: JSON.stringify(entry.input({ task, imageDataUri, prompt })),
|
|
86
|
+
})
|
|
87
|
+
if (!r?.request_id) throw new Error('fal did not give a request id.')
|
|
88
|
+
return {
|
|
89
|
+
vendorId: String(r.request_id),
|
|
90
|
+
stage: 'queue',
|
|
91
|
+
statusUrl: r.status_url ?? `${QUEUE}/${model}/requests/${r.request_id}/status`,
|
|
92
|
+
responseUrl: r.response_url ?? `${QUEUE}/${model}/requests/${r.request_id}`,
|
|
93
|
+
}
|
|
94
|
+
},
|
|
95
|
+
|
|
96
|
+
async poll(candidate, { key, fetch, ua }) {
|
|
97
|
+
const headers = { authorization: `Key ${key}` }
|
|
98
|
+
const s = await fetchJson(candidate.statusUrl, { fetch, hosts: fal.hosts, ua, headers })
|
|
99
|
+
const status = String(s?.status ?? '').toUpperCase()
|
|
100
|
+
if (status === 'IN_QUEUE') return { status: 'pending', progress: 0, note: Number.isFinite(s?.queue_position) ? `position ${s.queue_position} in the queue` : undefined }
|
|
101
|
+
if (status === 'IN_PROGRESS') return { status: 'running', progress: 50 }
|
|
102
|
+
if (status === 'FAILED' || status === 'ERROR') return { status: 'failed', error: String(s?.error ?? s?.detail ?? 'fal reported a failure').slice(0, 300) }
|
|
103
|
+
if (status !== 'COMPLETED') return { status: 'running', progress: 25 }
|
|
104
|
+
let out
|
|
105
|
+
try {
|
|
106
|
+
out = await fetchJson(candidate.responseUrl, { fetch, hosts: fal.hosts, ua, headers })
|
|
107
|
+
} catch (err) {
|
|
108
|
+
return { status: 'failed', error: err.message }
|
|
109
|
+
}
|
|
110
|
+
if (out?.detail && !out?.model_mesh && !out?.model_glb) return { status: 'failed', error: String(typeof out.detail === 'string' ? out.detail : JSON.stringify(out.detail)).slice(0, 300) }
|
|
111
|
+
const found = findOutputs(out)
|
|
112
|
+
if (!found.glb) return { status: 'failed', error: 'fal finished but its answer has no GLB.' }
|
|
113
|
+
return { status: 'succeeded', progress: 100, glbUrl: found.glb, thumbnailUrl: found.image }
|
|
114
|
+
},
|
|
115
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// The paid generators asset_generate can run (Meshy, fal, Tripo), behind one shape:
|
|
2
|
+
// { id, label, connector, envVar, hosts, tasks, defaultModel(task),
|
|
3
|
+
// licenseOf(model), price(task, model, prices), refuse?(task, model),
|
|
4
|
+
// submit(...), poll(candidate, ...) }
|
|
5
|
+
// Each is only ever called after the creator approved a cost card that
|
|
6
|
+
// covers it, and every check drives them with a fake fetch.
|
|
7
|
+
|
|
8
|
+
import { readFileSync } from 'node:fs'
|
|
9
|
+
import path from 'node:path'
|
|
10
|
+
import { fileURLToPath } from 'node:url'
|
|
11
|
+
import { fal } from './fal.mjs'
|
|
12
|
+
import { meshy } from './meshy.mjs'
|
|
13
|
+
import { tripo } from './tripo.mjs'
|
|
14
|
+
|
|
15
|
+
export const PROVIDERS = { meshy, fal, tripo }
|
|
16
|
+
|
|
17
|
+
/** The dated price table (prices.json). */
|
|
18
|
+
export const PRICES = JSON.parse(readFileSync(path.join(path.dirname(fileURLToPath(import.meta.url)), '..', 'prices.json'), 'utf8'))
|
|
19
|
+
|
|
20
|
+
/** Models that are refused whatever the provider: their licence does not
|
|
21
|
+
* reach the creator. */
|
|
22
|
+
export const REFUSED_MODELS = [{ test: /hunyuan/i, why: "Hunyuan3D's licence does not cover Korea, the EU or the UK." }]
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
// Meshy: text and image to a textured 3D model, through its OpenAPI with the
|
|
2
|
+
// creator's key (connector meshy, env MESHY_API_KEY, Authorization: Bearer).
|
|
3
|
+
// The shapes below are Meshy's documented v2 text-to-3d and v1 image-to-3d
|
|
4
|
+
// (docs.meshy.ai, read 2026-10-19), NOT exercised against the live API from
|
|
5
|
+
// here: no paid call is ever made by a check, and the checks use a fake.
|
|
6
|
+
// Verify one real job before release.
|
|
7
|
+
//
|
|
8
|
+
// text-to-3d POST /openapi/v2/text-to-3d { mode: 'preview', prompt, ... } -> { result: id }
|
|
9
|
+
// when the preview has SUCCEEDED:
|
|
10
|
+
// POST /openapi/v2/text-to-3d { mode: 'refine', preview_task_id, enable_pbr } -> { result: id }
|
|
11
|
+
// GET /openapi/v2/text-to-3d/{id} -> { status, progress, model_urls: { glb }, thumbnail_url, task_error }
|
|
12
|
+
// image-to-3d POST /openapi/v1/image-to-3d { image_url (a data URI), enable_pbr, ... } -> { result: id }
|
|
13
|
+
// GET /openapi/v1/image-to-3d/{id}
|
|
14
|
+
// multi-image-to-3d (read 2026-10-22)
|
|
15
|
+
// POST /openapi/v1/multi-image-to-3d { image_urls (1 to 4 data URIs, the front first), enable_pbr, ... } -> { result: id }
|
|
16
|
+
// GET /openapi/v1/multi-image-to-3d/{id}
|
|
17
|
+
//
|
|
18
|
+
// API access needs a paid Meshy plan, whose output belongs to the creator
|
|
19
|
+
// (LicenseRef-Generated-Owned). A free plan's output would be CC BY 4.0, but
|
|
20
|
+
// a free plan has no API.
|
|
21
|
+
//
|
|
22
|
+
// Delighting (read 2026-10-24): remove_lighting takes the highlights and
|
|
23
|
+
// shadows out of the base colour, so the model lights right in a space that
|
|
24
|
+
// has its own light. Meshy's default is on, and it acts only with meshy-6
|
|
25
|
+
// (meshy-7.1 and latest accept it and ignore it); sent with meshy-6-lite it
|
|
26
|
+
// is refused. It is sent, on, wherever it is accepted, so a change of
|
|
27
|
+
// Meshy's default does not change what the studio asks for. fal's TRELLIS.2
|
|
28
|
+
// has no such option.
|
|
29
|
+
|
|
30
|
+
import { fetchJson } from '../net.mjs'
|
|
31
|
+
|
|
32
|
+
const API = 'https://api.meshy.ai/openapi'
|
|
33
|
+
|
|
34
|
+
/** Whether a model takes remove_lighting (meshy-6-lite refuses it). */
|
|
35
|
+
const delights = (model) => model !== 'meshy-6-lite'
|
|
36
|
+
|
|
37
|
+
const STATUS = { PENDING: 'pending', IN_PROGRESS: 'running', SUCCEEDED: 'succeeded', FAILED: 'failed', CANCELED: 'failed', EXPIRED: 'failed' }
|
|
38
|
+
|
|
39
|
+
export const meshy = {
|
|
40
|
+
id: 'meshy',
|
|
41
|
+
label: 'Meshy',
|
|
42
|
+
connector: 'meshy',
|
|
43
|
+
envVar: 'MESHY_API_KEY',
|
|
44
|
+
hosts: ['api.meshy.ai', 'assets.meshy.ai', '*.meshy.ai'],
|
|
45
|
+
tasks: ['text-to-3d', 'image-to-3d', 'multi-image-to-3d'],
|
|
46
|
+
|
|
47
|
+
defaultModel() {
|
|
48
|
+
return 'latest'
|
|
49
|
+
},
|
|
50
|
+
|
|
51
|
+
/** The licence what this vendor makes carries. */
|
|
52
|
+
licenseOf() {
|
|
53
|
+
return { spdx: 'LicenseRef-Generated-Owned', url: 'https://www.meshy.ai/terms-of-use' }
|
|
54
|
+
},
|
|
55
|
+
|
|
56
|
+
/** Lower and upper price of one candidate, from prices.json. */
|
|
57
|
+
price(task, _model, prices) {
|
|
58
|
+
const credits = prices?.meshy?.[task]
|
|
59
|
+
const [low, high] = prices?.meshy?.creditUsd ?? []
|
|
60
|
+
if (!Number.isFinite(credits) || !Number.isFinite(low) || !Number.isFinite(high)) return null
|
|
61
|
+
return { low: credits * low, high: credits * high, unit: `${credits} credits` }
|
|
62
|
+
},
|
|
63
|
+
|
|
64
|
+
/** Starts one candidate. */
|
|
65
|
+
async submit({ task, model, prompt, imageDataUri, imageDataUris, quality, artStyle, key, fetch, ua }) {
|
|
66
|
+
const headers = { authorization: `Bearer ${key}`, 'content-type': 'application/json' }
|
|
67
|
+
const shared = {
|
|
68
|
+
...(model && model !== 'latest' ? { ai_model: model } : { ai_model: 'latest' }),
|
|
69
|
+
...(quality?.polycount ? { target_polycount: quality.polycount, should_remesh: true } : {}),
|
|
70
|
+
topology: 'triangle',
|
|
71
|
+
}
|
|
72
|
+
if (task === 'text-to-3d') {
|
|
73
|
+
const r = await fetchJson(`${API}/v2/text-to-3d`, { fetch, hosts: meshy.hosts, ua, method: 'POST', headers, body: JSON.stringify({ mode: 'preview', prompt, ...(artStyle ? { art_style: artStyle } : {}), ...shared }) })
|
|
74
|
+
if (!r?.result) throw new Error('Meshy did not give a task id.')
|
|
75
|
+
return { vendorId: String(r.result), stage: 'preview', pbr: quality?.pbr !== false, delight: delights(model) }
|
|
76
|
+
}
|
|
77
|
+
const several = task === 'multi-image-to-3d'
|
|
78
|
+
const r = await fetchJson(`${API}/v1/${several ? 'multi-image-to-3d' : 'image-to-3d'}`, {
|
|
79
|
+
fetch,
|
|
80
|
+
hosts: meshy.hosts,
|
|
81
|
+
ua,
|
|
82
|
+
method: 'POST',
|
|
83
|
+
headers,
|
|
84
|
+
body: JSON.stringify({ ...(several ? { image_urls: imageDataUris } : { image_url: imageDataUri }), enable_pbr: quality?.pbr !== false, ...(delights(model) ? { remove_lighting: true } : {}), ...(prompt ? { texture_prompt: prompt } : {}), ...shared }),
|
|
85
|
+
})
|
|
86
|
+
if (!r?.result) throw new Error('Meshy did not give a task id.')
|
|
87
|
+
return { vendorId: String(r.result), stage: several ? 'multi' : 'image', pbr: quality?.pbr !== false }
|
|
88
|
+
},
|
|
89
|
+
|
|
90
|
+
/** Where a candidate is now; a finished preview starts its refine. */
|
|
91
|
+
async poll(candidate, { task, key, fetch, ua }) {
|
|
92
|
+
const headers = { authorization: `Bearer ${key}` }
|
|
93
|
+
const url = task === 'text-to-3d' ? `${API}/v2/text-to-3d/${encodeURIComponent(candidate.vendorId)}` : `${API}/v1/${task === 'multi-image-to-3d' ? 'multi-image-to-3d' : 'image-to-3d'}/${encodeURIComponent(candidate.vendorId)}`
|
|
94
|
+
const r = await fetchJson(url, { fetch, hosts: meshy.hosts, ua, headers })
|
|
95
|
+
const status = STATUS[String(r?.status ?? '').toUpperCase()] ?? 'running'
|
|
96
|
+
if (status === 'failed') return { status, error: String(r?.task_error?.message || r?.status || 'Meshy reported a failure').slice(0, 300) }
|
|
97
|
+
if (status !== 'succeeded') {
|
|
98
|
+
// Text to 3D is two tasks (preview, then refine), each half the bar.
|
|
99
|
+
const share = candidate.stage === 'image' || candidate.stage === 'multi' ? 1 : 0.5
|
|
100
|
+
const offset = candidate.stage === 'refine' ? 50 : 0
|
|
101
|
+
return { status, progress: Math.round(offset + (Number(r?.progress) || 0) * share) }
|
|
102
|
+
}
|
|
103
|
+
if (task === 'text-to-3d' && candidate.stage === 'preview') {
|
|
104
|
+
const refine = await fetchJson(`${API}/v2/text-to-3d`, {
|
|
105
|
+
fetch,
|
|
106
|
+
hosts: meshy.hosts,
|
|
107
|
+
ua,
|
|
108
|
+
method: 'POST',
|
|
109
|
+
headers: { ...headers, 'content-type': 'application/json' },
|
|
110
|
+
body: JSON.stringify({ mode: 'refine', preview_task_id: candidate.vendorId, enable_pbr: candidate.pbr !== false, ...(candidate.delight !== false ? { remove_lighting: true } : {}) }),
|
|
111
|
+
})
|
|
112
|
+
if (!refine?.result) return { status: 'failed', error: 'Meshy finished the preview but did not start the refine.' }
|
|
113
|
+
return { status: 'running', progress: 50, next: { vendorId: String(refine.result), stage: 'refine' } }
|
|
114
|
+
}
|
|
115
|
+
const glb = r?.model_urls?.glb
|
|
116
|
+
if (!glb) return { status: 'failed', error: 'Meshy finished but gave no GLB.' }
|
|
117
|
+
return { status: 'succeeded', progress: 100, glbUrl: glb, thumbnailUrl: r?.thumbnail_url ?? null }
|
|
118
|
+
},
|
|
119
|
+
}
|