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,200 @@
|
|
|
1
|
+
// What the whole production should cost, before anything is spent: every
|
|
2
|
+
// session it plans, at the model the router will start it on, priced with
|
|
3
|
+
// ledger.mjs profileUsd at that model's card (models.json, the one price
|
|
4
|
+
// source). The profiles are token counts per kind of session, so the long
|
|
5
|
+
// prompt tier and the cache prices count the way they bill. `lo` is the
|
|
6
|
+
// plan as written (one attempt per task, one critic per judged task);
|
|
7
|
+
// `hi` adds the rounds that usually follow, a reserve for the climb two
|
|
8
|
+
// rungs up, a final critic, a polish allowance and the reviews of the
|
|
9
|
+
// director's notes, and is what the cost card shows and the creator
|
|
10
|
+
// approves.
|
|
11
|
+
//
|
|
12
|
+
// Every number here is a proposal (orchestrator spec 2.6) for the
|
|
13
|
+
// real-model experiments to tune.
|
|
14
|
+
|
|
15
|
+
import { profileUsd } from '../ledger.mjs'
|
|
16
|
+
import { PRICING } from '../shared.mjs'
|
|
17
|
+
import { ENDED } from './board.mjs'
|
|
18
|
+
|
|
19
|
+
export const PROFILES = {
|
|
20
|
+
decision: { calls: 1, prompt: 16_000, fresh: 16_000, output: 8_000 },
|
|
21
|
+
// The brief read back against its picture (two pictures and the subjects),
|
|
22
|
+
// one review of the director's notes between rounds, and one review of how
|
|
23
|
+
// a modelled asset is made (two pictures, the capability list).
|
|
24
|
+
readback: { calls: 1, prompt: 8_000, fresh: 8_000, output: 2_000 },
|
|
25
|
+
notes: { calls: 1, prompt: 10_000, fresh: 10_000, output: 2_500 },
|
|
26
|
+
method: { calls: 1, prompt: 9_000, fresh: 9_000, output: 1_500 },
|
|
27
|
+
critic: { calls: 1, prompt: 14_000, fresh: 14_000, output: 3_000 },
|
|
28
|
+
brief: { calls: 1, prompt: 6_000, fresh: 6_000, output: 1_500 },
|
|
29
|
+
builder: { calls: 20, prompt: 60_000, fresh: 4_000, output: 2_500 },
|
|
30
|
+
artist: { calls: 14, prompt: 50_000, fresh: 4_000, output: 2_000 },
|
|
31
|
+
modeller: { calls: 16, prompt: 45_000, fresh: 5_000, output: 3_000 },
|
|
32
|
+
sound: { calls: 8, prompt: 30_000, fresh: 3_000, output: 2_500 },
|
|
33
|
+
qa: { calls: 10, prompt: 40_000, fresh: 3_000, output: 1_500 },
|
|
34
|
+
}
|
|
35
|
+
export const FACTORS = { decisions: 1.3, attempts: 1.7, climb: 0.3, critics: 2.2, polish: 0.3, notes: 2 }
|
|
36
|
+
const VISUAL = new Set(['builder', 'artist', 'modeller'])
|
|
37
|
+
const MAX_ITEMS = 12
|
|
38
|
+
|
|
39
|
+
const cents = (n) => Math.ceil(n * 100 - 1e-9) / 100
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* @param {{ board: object, router: object, prices?: Record<string, object>, paid?: { provider: string, for: string, usd: number, hi?: number, label?: string }[],
|
|
43
|
+
* decisions?: string[], cheapest?: boolean, tasks?: object[] }} options
|
|
44
|
+
* decisions: the decision phases still to run (none on a resume);
|
|
45
|
+
* cheapest: every task on the lowest rung (the figure a cancel quotes);
|
|
46
|
+
* tasks: the tasks to price (default every task on the board).
|
|
47
|
+
*/
|
|
48
|
+
export function estimateProduction({ board, router, prices = PRICING, paid = [], decisions = ['interpret', 'vision', 'plan'], cheapest = false, tasks = board?.tasks ?? [] }) {
|
|
49
|
+
const lines = []
|
|
50
|
+
const cost = (profile, model) => profileUsd(PROFILES[profile], prices[model] ?? null)
|
|
51
|
+
const line = (entry) => lines.push(entry)
|
|
52
|
+
const lowest = router.rungs[0]
|
|
53
|
+
|
|
54
|
+
for (const phase of decisions) {
|
|
55
|
+
const pick = router.decision(phase)
|
|
56
|
+
const n = cost(phase in PROFILES ? phase : 'decision', pick.model.id)
|
|
57
|
+
line({ model: pick.model, what: 'direction', lo: n, hi: n * FACTORS.decisions })
|
|
58
|
+
}
|
|
59
|
+
const report = router.decision('report')
|
|
60
|
+
const r = cost('brief', report.model.id)
|
|
61
|
+
line({ model: report.model, what: 'report', lo: r, hi: r * FACTORS.decisions })
|
|
62
|
+
// The reviews of the director's notes between rounds, a reserve.
|
|
63
|
+
if (tasks.length) {
|
|
64
|
+
const notes = router.decision('notes')
|
|
65
|
+
line({ model: notes.model, what: 'direction', lo: 0, hi: cost('notes', notes.model.id) * FACTORS.notes })
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const perTask = {}
|
|
69
|
+
let critics = 0
|
|
70
|
+
const critic = router.decision('critic')
|
|
71
|
+
const criticUsd = cost('critic', critic.model.id)
|
|
72
|
+
for (const t of tasks) {
|
|
73
|
+
const start = cheapest ? { ...lowest } : router.start(t, board)
|
|
74
|
+
const one = cost(t.role in PROFILES ? t.role : 'builder', start.model.id)
|
|
75
|
+
const upIndex = router.rungs.findIndex((x) => x.rung === start.rung) + 2
|
|
76
|
+
const up = router.rungs[Math.min(router.rungs.length - 1, Math.max(0, upIndex))]
|
|
77
|
+
const climb = cost(t.role in PROFILES ? t.role : 'builder', up.model.id)
|
|
78
|
+
line({ model: start.model, what: t.role, task: t.id, lo: one, hi: one * FACTORS.attempts })
|
|
79
|
+
line({ model: up.model, what: 'reserve', task: t.id, lo: 0, hi: climb * FACTORS.climb })
|
|
80
|
+
let judged = 0
|
|
81
|
+
if ((t.accept?.critic ?? []).length > 0) {
|
|
82
|
+
critics++
|
|
83
|
+
line({ model: critic.model, what: 'critique', task: t.id, lo: criticUsd, hi: criticUsd * FACTORS.critics })
|
|
84
|
+
judged = criticUsd * FACTORS.critics
|
|
85
|
+
}
|
|
86
|
+
if (VISUAL.has(t.role)) line({ model: start.model, what: 'reserve', task: t.id, lo: 0, hi: one * FACTORS.polish })
|
|
87
|
+
// A modelled asset's method may be reviewed after a round that did not pass.
|
|
88
|
+
let review = 0
|
|
89
|
+
if (t.role === 'modeller' && t.method) {
|
|
90
|
+
const pick = router.decision('method')
|
|
91
|
+
review = cost('method', pick.model.id)
|
|
92
|
+
line({ model: pick.model, what: 'direction', task: t.id, lo: 0, hi: review })
|
|
93
|
+
}
|
|
94
|
+
perTask[t.id] = one * FACTORS.attempts + climb * FACTORS.climb + judged + (VISUAL.has(t.role) ? one * FACTORS.polish : 0) + review
|
|
95
|
+
}
|
|
96
|
+
// The whole-scene critic of the final gate.
|
|
97
|
+
line({ model: critic.model, what: 'critique', lo: 0, hi: criticUsd })
|
|
98
|
+
|
|
99
|
+
// A method's line counts the rounds it may be spent in (hi), one at least (lo).
|
|
100
|
+
const paidLines = paid.map((p) => ({ ...p, lo: p.usd, hi: p.hi ?? p.usd }))
|
|
101
|
+
const lo = lines.reduce((s, l) => s + l.lo, 0) + paidLines.reduce((s, p) => s + p.lo, 0)
|
|
102
|
+
const hiRaw = lines.reduce((s, l) => s + l.hi, 0) + paidLines.reduce((s, p) => s + p.hi, 0)
|
|
103
|
+
for (const p of paidLines) if (p.for) perTask[p.for] = (perTask[p.for] ?? 0) + p.hi
|
|
104
|
+
const finalUsd = criticUsd + r * FACTORS.decisions
|
|
105
|
+
return { lo, hiRaw, lines, paid: paidLines, perTask, finalUsd, critics }
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* The cost card's lines: one per model, its share of hi, labelled with the
|
|
110
|
+
* model's name and what runs on it in the creator's words (the board's
|
|
111
|
+
* roleWords and costWords), then one per paid tool; at most 12. Each line
|
|
112
|
+
* is rounded up to a cent, and the total the card shows is their sum, which
|
|
113
|
+
* is what is returned as `hi`.
|
|
114
|
+
*/
|
|
115
|
+
export function costItems(estimate, { roleWords = {}, costWords = {}, taskLabels = {} } = {}) {
|
|
116
|
+
const byModel = new Map()
|
|
117
|
+
for (const l of estimate.lines) {
|
|
118
|
+
const m = byModel.get(l.model.id) ?? { model: l.model, usd: 0, words: [] }
|
|
119
|
+
m.usd += l.hi
|
|
120
|
+
const word = roleWords[l.what] ?? costWords[l.what] ?? l.what
|
|
121
|
+
if (!m.words.includes(word)) m.words.push(word)
|
|
122
|
+
byModel.set(l.model.id, m)
|
|
123
|
+
}
|
|
124
|
+
const items = [...byModel.values()]
|
|
125
|
+
.filter((m) => m.usd > 0)
|
|
126
|
+
.map((m) => ({ label: `${m.model.name}: ${m.words.join(', ')}`.slice(0, 80), usd: cents(m.usd) }))
|
|
127
|
+
const paid = new Map()
|
|
128
|
+
for (const p of estimate.paid) {
|
|
129
|
+
const key = p.provider
|
|
130
|
+
const e = paid.get(key) ?? { label: `${p.label ?? p.provider}`, usd: 0, tasks: [] }
|
|
131
|
+
e.usd += p.hi
|
|
132
|
+
if (taskLabels[p.for] && !e.tasks.includes(taskLabels[p.for])) e.tasks.push(taskLabels[p.for])
|
|
133
|
+
paid.set(key, e)
|
|
134
|
+
}
|
|
135
|
+
for (const e of paid.values()) items.push({ label: `${e.label}${e.tasks.length ? `: ${e.tasks.join(', ')}` : ''}`.slice(0, 80), usd: cents(e.usd) })
|
|
136
|
+
// More lines than a card takes: the smallest folded into the last one.
|
|
137
|
+
while (items.length > MAX_ITEMS) {
|
|
138
|
+
items.sort((a, b) => b.usd - a.usd)
|
|
139
|
+
const last = items.pop()
|
|
140
|
+
items[items.length - 1] = { ...items[items.length - 1], usd: cents(items[items.length - 1].usd + last.usd) }
|
|
141
|
+
}
|
|
142
|
+
const hi = Math.round(items.reduce((s, i) => s + i.usd, 0) * 100) / 100
|
|
143
|
+
return { items, hi }
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* The direction's own cost card, asked before anything is spent: the
|
|
148
|
+
* decisions that read the request and plan the game (INTERPRET, with a
|
|
149
|
+
* picture its read-back, VISION, PLAN), each at the model the router gives
|
|
150
|
+
* it, one line per model named by the model alone (no model has written
|
|
151
|
+
* the creator's words yet). The whole production's card follows the plan.
|
|
152
|
+
*/
|
|
153
|
+
export function directionItems({ router, prices = PRICING, decisions = ['interpret', 'vision', 'plan'] }) {
|
|
154
|
+
const est = estimateProduction({ board: null, router, prices, decisions, tasks: [] })
|
|
155
|
+
const byModel = new Map()
|
|
156
|
+
for (const l of est.lines.filter((x) => x.what === 'direction')) {
|
|
157
|
+
const m = byModel.get(l.model.id) ?? { label: l.model.name, usd: 0 }
|
|
158
|
+
m.usd += l.hi
|
|
159
|
+
byModel.set(l.model.id, m)
|
|
160
|
+
}
|
|
161
|
+
const items = [...byModel.values()].map((m) => ({ label: String(m.label).slice(0, 80), usd: cents(m.usd) }))
|
|
162
|
+
return { items, hi: Math.round(items.reduce((s, i) => s + i.usd, 0) * 100) / 100 }
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/** One attempt of a task on a model, with its critic when it has criteria:
|
|
166
|
+
* what the next attempt will spend at least. */
|
|
167
|
+
export function attemptUsd({ task, model, router, prices = PRICING }) {
|
|
168
|
+
const role = task.role in PROFILES ? task.role : 'builder'
|
|
169
|
+
const own = profileUsd(PROFILES[role], prices[model] ?? null)
|
|
170
|
+
const judged = (task.accept?.critic ?? []).length > 0 ? profileUsd(PROFILES.critic, prices[router.decision('critic').model.id] ?? null) : 0
|
|
171
|
+
return own + judged
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/** What is left to spend: the high figure of every task not finished, less
|
|
175
|
+
* what it has spent, and the final gate's share until it ran. `next` is
|
|
176
|
+
* the attempt about to start ({ task, usd }): its task counts at least
|
|
177
|
+
* that, so a task past its share still counts the attempt it will run. */
|
|
178
|
+
export function remainingUsd({ estimate, board, spentByTask = {}, finalDone = false, next = null }) {
|
|
179
|
+
let left = finalDone ? 0 : estimate.finalUsd
|
|
180
|
+
for (const t of board.tasks) {
|
|
181
|
+
if (ENDED.has(t.status) && t.id !== next?.task) continue
|
|
182
|
+
const share = Math.max(0, (estimate.perTask[t.id] ?? 0) - (spentByTask[t.id] ?? 0))
|
|
183
|
+
left += t.id === next?.task ? Math.max(share, next.usd) : share
|
|
184
|
+
}
|
|
185
|
+
return left
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/** A paid generation's estimate lines, from asset_generate's own answer:
|
|
189
|
+
* its "For the cost card:" JSON. */
|
|
190
|
+
export function paidFromEstimate(text) {
|
|
191
|
+
const m = /For the cost card:\s*(\{.*\})\s*$/m.exec(String(text ?? ''))
|
|
192
|
+
if (!m) return null
|
|
193
|
+
try {
|
|
194
|
+
const card = JSON.parse(m[1])
|
|
195
|
+
const items = Array.isArray(card.items) ? card.items.filter((i) => Number.isFinite(i?.usd)) : []
|
|
196
|
+
return { usd: items.reduce((s, i) => s + i.usd, 0), label: card.note ? String(card.note).split(',')[0] : null, items }
|
|
197
|
+
} catch {
|
|
198
|
+
return null
|
|
199
|
+
}
|
|
200
|
+
}
|