tripo-cli 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 +105 -0
- package/dist/ai/experts.js +115 -0
- package/dist/ai/llm.js +88 -0
- package/dist/ai/plan-card.js +79 -0
- package/dist/ai/wizard.js +105 -0
- package/dist/cli.js +7 -0
- package/dist/commands/account.js +27 -0
- package/dist/commands/ai.js +114 -0
- package/dist/commands/batch.js +148 -0
- package/dist/commands/completion.js +84 -0
- package/dist/commands/config-cmd.js +84 -0
- package/dist/commands/docs.js +30 -0
- package/dist/commands/doctor.js +102 -0
- package/dist/commands/generate.js +81 -0
- package/dist/commands/home.js +68 -0
- package/dist/commands/login.js +309 -0
- package/dist/commands/make.js +142 -0
- package/dist/commands/mcp.js +194 -0
- package/dist/commands/process-groups.js +166 -0
- package/dist/commands/shared.js +75 -0
- package/dist/commands/task.js +128 -0
- package/dist/commands/topup.js +61 -0
- package/dist/commands/view.js +97 -0
- package/dist/config/config.js +99 -0
- package/dist/config/context.js +44 -0
- package/dist/config/history.js +104 -0
- package/dist/core/client.js +129 -0
- package/dist/core/device-auth.js +141 -0
- package/dist/core/download.js +107 -0
- package/dist/core/errors.js +64 -0
- package/dist/core/output.js +72 -0
- package/dist/core/region.js +45 -0
- package/dist/core/requests.js +197 -0
- package/dist/core/task-service.js +167 -0
- package/dist/core/upload.js +42 -0
- package/dist/core/viewer-assets.js +24 -0
- package/dist/core/viewer.js +59 -0
- package/dist/core/watch.js +42 -0
- package/dist/i18n.js +19 -0
- package/dist/knowledge/chains.js +157 -0
- package/dist/knowledge/error-catalog.js +91 -0
- package/dist/knowledge/models.js +158 -0
- package/dist/knowledge/params.js +203 -0
- package/dist/knowledge/scenarios.js +112 -0
- package/dist/pipeline/make.js +233 -0
- package/dist/pipeline/runner.js +73 -0
- package/dist/pipeline/stdin.js +40 -0
- package/dist/program.js +147 -0
- package/dist/src/ai/experts.js +115 -0
- package/dist/src/ai/llm.js +88 -0
- package/dist/src/ai/plan-card.js +79 -0
- package/dist/src/ai/wizard.js +104 -0
- package/dist/src/cli.js +7 -0
- package/dist/src/commands/account.js +27 -0
- package/dist/src/commands/ai.js +113 -0
- package/dist/src/commands/batch.js +148 -0
- package/dist/src/commands/completion.js +84 -0
- package/dist/src/commands/config-cmd.js +84 -0
- package/dist/src/commands/docs.js +30 -0
- package/dist/src/commands/doctor.js +94 -0
- package/dist/src/commands/generate.js +81 -0
- package/dist/src/commands/home.js +68 -0
- package/dist/src/commands/login.js +225 -0
- package/dist/src/commands/make.js +142 -0
- package/dist/src/commands/mcp.js +194 -0
- package/dist/src/commands/process-groups.js +164 -0
- package/dist/src/commands/shared.js +75 -0
- package/dist/src/commands/task.js +127 -0
- package/dist/src/commands/topup.js +61 -0
- package/dist/src/commands/view.js +97 -0
- package/dist/src/config/config.js +79 -0
- package/dist/src/config/context.js +44 -0
- package/dist/src/config/history.js +104 -0
- package/dist/src/core/client.js +120 -0
- package/dist/src/core/download.js +107 -0
- package/dist/src/core/errors.js +64 -0
- package/dist/src/core/output.js +72 -0
- package/dist/src/core/requests.js +169 -0
- package/dist/src/core/task-service.js +161 -0
- package/dist/src/core/upload.js +36 -0
- package/dist/src/core/viewer-assets.js +24 -0
- package/dist/src/core/viewer.js +59 -0
- package/dist/src/core/watch.js +41 -0
- package/dist/src/i18n.js +19 -0
- package/dist/src/knowledge/chains.js +152 -0
- package/dist/src/knowledge/error-catalog.js +91 -0
- package/dist/src/knowledge/models.js +110 -0
- package/dist/src/knowledge/params.js +174 -0
- package/dist/src/knowledge/scenarios.js +112 -0
- package/dist/src/pipeline/make.js +233 -0
- package/dist/src/pipeline/runner.js +73 -0
- package/dist/src/pipeline/stdin.js +40 -0
- package/dist/src/program.js +147 -0
- package/dist/src/types.js +2 -0
- package/dist/src/util/input-detect.js +92 -0
- package/dist/src/util/notify.js +17 -0
- package/dist/src/util/open.js +18 -0
- package/dist/src/util/spinner.js +62 -0
- package/dist/src/util/term-image.js +28 -0
- package/dist/src/version.js +10 -0
- package/dist/types.js +2 -0
- package/dist/util/input-detect.js +93 -0
- package/dist/util/notify.js +17 -0
- package/dist/util/open.js +18 -0
- package/dist/util/spinner.js +62 -0
- package/dist/util/term-image.js +28 -0
- package/dist/version.js +10 -0
- package/package.json +63 -0
- package/skill/SKILL.md +70 -0
- package/skill/commands/account.md +41 -0
- package/skill/commands/batch.md +33 -0
- package/skill/commands/generate.md +34 -0
- package/skill/commands/make.md +47 -0
- package/skill/commands/process.md +50 -0
- package/skill/commands/task.md +27 -0
- package/skill/commands/view.md +25 -0
- package/skill/common-errors.md +38 -0
- package/skill/examples/animation.md +33 -0
- package/skill/examples/ar-web.md +23 -0
- package/skill/examples/film.md +22 -0
- package/skill/examples/game-asset.md +35 -0
- package/skill/examples/pipes.md +39 -0
- package/skill/examples/print.md +31 -0
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Scenario decision matrix: --for presets and the AI wizard both read this
|
|
3
|
+
* table. Changing production strategy means editing data here, not logic.
|
|
4
|
+
*/
|
|
5
|
+
import { MODEL_P1, MODEL_V31, RIG_MODEL_V25 } from './models.js';
|
|
6
|
+
export const SCENARIOS = [
|
|
7
|
+
{
|
|
8
|
+
id: 'game-mobile',
|
|
9
|
+
label: { zh: '手游/低模', en: 'Mobile game / low-poly' },
|
|
10
|
+
description: { zh: '移动端游戏资产,面数预算严格,干净拓扑', en: 'Mobile game assets with strict face budgets and clean topology' },
|
|
11
|
+
model: MODEL_P1,
|
|
12
|
+
genParams: { texture: true, pbr: true, texture_quality: 'standard', face_limit: 15000 },
|
|
13
|
+
chain: [{ step: 'convert', args: { format: 'FBX', texture_size: 2048 } }],
|
|
14
|
+
deliverables: ['FBX', 'GLB'],
|
|
15
|
+
notes: {
|
|
16
|
+
zh: ['P1 原生低模,拓扑干净', '2K 贴图适配移动端', '需要骨骼时追加 --then rig'],
|
|
17
|
+
en: ['P1 native low-poly with clean topology', '2K textures for mobile budgets', 'append --then rig if you need a skeleton'],
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
id: 'game-pc',
|
|
22
|
+
label: { zh: '端游/主机', en: 'PC / console game' },
|
|
23
|
+
description: { zh: '高预算引擎资产,PBR 全开', en: 'High-budget engine assets with full PBR' },
|
|
24
|
+
model: MODEL_V31,
|
|
25
|
+
genParams: { texture: true, pbr: true, texture_quality: 'detailed' },
|
|
26
|
+
chain: [{ step: 'convert', args: { format: 'FBX' } }],
|
|
27
|
+
deliverables: ['FBX', 'GLTF'],
|
|
28
|
+
notes: {
|
|
29
|
+
zh: ['v3.1 高精度 + detailed 贴图', '需要 LOD 时追加 --then decimate:5000', '进 Blender/3dsMax 用 fbx_preset 对齐'],
|
|
30
|
+
en: ['v3.1 high fidelity + detailed textures', 'append --then decimate:5000 for LODs', 'use fbx_preset to match Blender/3dsMax'],
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
id: 'film',
|
|
35
|
+
label: { zh: '影视/离线渲染', en: 'Film / offline rendering' },
|
|
36
|
+
description: { zh: '细分友好四边面,规格拉满', en: 'Subdivision-friendly quads, maximum quality' },
|
|
37
|
+
model: MODEL_V31,
|
|
38
|
+
genParams: { texture: true, pbr: true, quad: true, geometry_quality: 'detailed', texture_quality: 'detailed' },
|
|
39
|
+
chain: [],
|
|
40
|
+
deliverables: ['FBX (quad)', 'USDZ/OBJ via convert'],
|
|
41
|
+
notes: {
|
|
42
|
+
zh: ['quad=true 输出 FBX(quad 进不了 GLB)', 'geometry detailed 加收 HD credit', '进 USD 管线追加 --then convert:usdz'],
|
|
43
|
+
en: ['quad=true outputs FBX (quads cannot be stored in GLB)', 'geometry detailed bills an extra HD credit', 'append --then convert:usdz for USD pipelines'],
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
id: 'print',
|
|
48
|
+
label: { zh: '3D 打印', en: '3D printing' },
|
|
49
|
+
description: { zh: '水密可打印几何,免贴图省积分', en: 'Watertight printable geometry, skipping textures saves credits' },
|
|
50
|
+
model: MODEL_V31,
|
|
51
|
+
genParams: { texture: false, pbr: false },
|
|
52
|
+
chain: [{ step: 'convert', args: { format: 'STL', flatten_bottom: true } }],
|
|
53
|
+
deliverables: ['STL', '3MF (colored)'],
|
|
54
|
+
notes: {
|
|
55
|
+
zh: ['白模生成,不花贴图积分', 'flatten_bottom 平底利于 FDM', '彩色打印改 --then convert:3mf,export_vertex_colors=true'],
|
|
56
|
+
en: ['bare geometry: no texture credits spent', 'flatten_bottom helps FDM adhesion', 'for color prints use --then convert:3mf,export_vertex_colors=true'],
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
id: 'ar-web',
|
|
61
|
+
label: { zh: 'AR/Web/电商', en: 'AR / Web / e-commerce' },
|
|
62
|
+
description: { zh: '移动端性能预算,glb+usdz 双交付', en: 'Mobile performance budgets with dual glb+usdz delivery' },
|
|
63
|
+
model: MODEL_V31,
|
|
64
|
+
genParams: { texture: true, pbr: true },
|
|
65
|
+
chain: [
|
|
66
|
+
{ step: 'decimate', args: { face_limit: 20000 } },
|
|
67
|
+
{ step: 'convert', args: { format: 'USDZ' } },
|
|
68
|
+
],
|
|
69
|
+
deliverables: ['GLB', 'USDZ'],
|
|
70
|
+
notes: {
|
|
71
|
+
zh: ['v3.1 生成后减面到 2 万内', 'iOS QuickLook 需要 USDZ', 'decimate 默认 bake 烘焙贴图到低模'],
|
|
72
|
+
en: ['generate with v3.1, then decimate under 20k faces', 'iOS QuickLook requires USDZ', 'decimate bakes textures onto the low-poly by default'],
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
id: 'anim',
|
|
77
|
+
label: { zh: '角色动画', en: 'Character animation' },
|
|
78
|
+
description: { zh: '绑骨+动作重定向全链路', en: 'Full rig + retarget pipeline' },
|
|
79
|
+
model: MODEL_V31,
|
|
80
|
+
genParams: { texture: true, pbr: true },
|
|
81
|
+
chain: [
|
|
82
|
+
{ step: 'rig-check', args: {} },
|
|
83
|
+
{ step: 'rig', args: { model: RIG_MODEL_V25, spec: 'tripo', out_format: 'glb' } },
|
|
84
|
+
{ step: 'retarget', args: { animations: ['preset:idle', 'preset:walk'] } },
|
|
85
|
+
],
|
|
86
|
+
deliverables: ['GLB', 'FBX'],
|
|
87
|
+
notes: {
|
|
88
|
+
zh: ['先 rig-check 预检,不可绑骨即止损', '接 Mixamo/Unity Humanoid 用 rig:spec=mixamo', '提示词建议 T-pose 站姿,或先 text-to-image template=t_pose'],
|
|
89
|
+
en: ['rig-check first: stop early if not riggable', 'use rig:spec=mixamo for Mixamo/Unity Humanoid', 'prompt for a T-pose, or pre-generate with text-to-image template=t_pose'],
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
id: 'toy',
|
|
94
|
+
label: { zh: '风格化摆件', en: 'Stylized toy / desk piece' },
|
|
95
|
+
description: { zh: '低模可爱风或积木/体素风格化', en: 'Cute low-poly or brick/voxel stylization' },
|
|
96
|
+
model: MODEL_P1,
|
|
97
|
+
genParams: { texture: true, pbr: true, face_limit: 20000 },
|
|
98
|
+
chain: [],
|
|
99
|
+
deliverables: ['GLB', 'STL via convert'],
|
|
100
|
+
notes: {
|
|
101
|
+
zh: ['P1 出干净低模', '积木/体素风追加 --then stylize:lego 或 stylize:voxel', '要打印实物追加 --then convert:stl'],
|
|
102
|
+
en: ['P1 produces clean low-poly', 'append --then stylize:lego or stylize:voxel for brick/voxel looks', 'append --then convert:stl to print it'],
|
|
103
|
+
},
|
|
104
|
+
},
|
|
105
|
+
];
|
|
106
|
+
const byId = new Map(SCENARIOS.map((s) => [s.id, s]));
|
|
107
|
+
export function getScenario(id) {
|
|
108
|
+
return byId.get(id);
|
|
109
|
+
}
|
|
110
|
+
export function scenarioIds() {
|
|
111
|
+
return SCENARIOS.map((s) => s.id);
|
|
112
|
+
}
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `make` orchestrator — one entry point that turns any input (text /
|
|
3
|
+
* image / multiview / model file / task ref) into finished artifacts,
|
|
4
|
+
* applying the dual-model rule, scenario presets, and the processing chain.
|
|
5
|
+
* Shared by `tripo make`, `tripo ai`, `tripo redo`, batch, and the MCP server.
|
|
6
|
+
*/
|
|
7
|
+
import { basename } from 'node:path';
|
|
8
|
+
import { UsageError } from '../core/errors.js';
|
|
9
|
+
import { log, warn } from '../core/output.js';
|
|
10
|
+
import { buildImageToModel, buildMultiviewToModel, buildStepRequest, buildTextToModel, } from '../core/requests.js';
|
|
11
|
+
import { precheckBalance, resolveInputValue, runTask } from '../core/task-service.js';
|
|
12
|
+
import { t } from '../i18n.js';
|
|
13
|
+
import { validateChain, ChainError } from '../knowledge/chains.js';
|
|
14
|
+
import { chooseModel, detectLowPolyIntent } from '../knowledge/models.js';
|
|
15
|
+
import { getScenario } from '../knowledge/scenarios.js';
|
|
16
|
+
import { classifyInputs } from '../util/input-detect.js';
|
|
17
|
+
import { runChain, assertSourceReady } from './runner.js';
|
|
18
|
+
/** Build the full plan (no network calls except none): what model, what chain, why. */
|
|
19
|
+
export async function planMake(client, options) {
|
|
20
|
+
const classified = classifyInputs(options.inputs);
|
|
21
|
+
const scenario = options.scenario ? getScenario(options.scenario) : undefined;
|
|
22
|
+
if (options.scenario && !scenario) {
|
|
23
|
+
throw new UsageError(`unknown scenario "${options.scenario}" (valid: game-mobile, game-pc, film, print, ar-web, anim, toy)`);
|
|
24
|
+
}
|
|
25
|
+
const userParams = options.params ?? {};
|
|
26
|
+
const genParams = { ...(scenario?.genParams ?? {}), ...userParams };
|
|
27
|
+
const chain = options.chain && options.chain.length > 0 ? options.chain : (scenario?.chain ?? []);
|
|
28
|
+
const warnings = [];
|
|
29
|
+
if (options.chain && options.chain.length > 0 && scenario && scenario.chain.length > 0) {
|
|
30
|
+
warnings.push(t({
|
|
31
|
+
zh: `--then 覆盖了 ${scenario.id} 场景默认加工链`,
|
|
32
|
+
en: `--then overrides the default ${scenario.id} processing chain`,
|
|
33
|
+
}));
|
|
34
|
+
}
|
|
35
|
+
switch (classified.kind) {
|
|
36
|
+
case 'text': {
|
|
37
|
+
const prompt = classified.values[0].value;
|
|
38
|
+
const choice = chooseModel({
|
|
39
|
+
explicit: options.model ?? scenario?.model,
|
|
40
|
+
faceLimit: typeof genParams.face_limit === 'number' ? genParams.face_limit : undefined,
|
|
41
|
+
lowPoly: detectLowPolyIntent(prompt),
|
|
42
|
+
});
|
|
43
|
+
const generation = buildTextToModel(prompt, choice.model, genParams);
|
|
44
|
+
return {
|
|
45
|
+
generation,
|
|
46
|
+
chain,
|
|
47
|
+
model: choice.model,
|
|
48
|
+
modelReason: choice.reason,
|
|
49
|
+
name: options.name ?? prompt,
|
|
50
|
+
warnings: [...warnings, ...generation.warnings],
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
case 'image':
|
|
54
|
+
case 'url-image': {
|
|
55
|
+
const raw = classified.values[0].value;
|
|
56
|
+
const { value } = await resolveInputValue(client, raw);
|
|
57
|
+
const choice = chooseModel({
|
|
58
|
+
explicit: options.model ?? scenario?.model,
|
|
59
|
+
faceLimit: typeof genParams.face_limit === 'number' ? genParams.face_limit : undefined,
|
|
60
|
+
});
|
|
61
|
+
const generation = buildImageToModel(value, choice.model, genParams);
|
|
62
|
+
return {
|
|
63
|
+
generation,
|
|
64
|
+
chain,
|
|
65
|
+
model: choice.model,
|
|
66
|
+
modelReason: choice.reason,
|
|
67
|
+
name: options.name ?? basename(raw),
|
|
68
|
+
warnings: [...warnings, ...generation.warnings],
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
case 'multiview': {
|
|
72
|
+
const views = await assignViews(client, classified.values.map((v) => v.value));
|
|
73
|
+
const choice = chooseModel({
|
|
74
|
+
explicit: options.model ?? scenario?.model,
|
|
75
|
+
faceLimit: typeof genParams.face_limit === 'number' ? genParams.face_limit : undefined,
|
|
76
|
+
});
|
|
77
|
+
const generation = buildMultiviewToModel(views, choice.model, genParams);
|
|
78
|
+
return {
|
|
79
|
+
generation,
|
|
80
|
+
chain,
|
|
81
|
+
model: choice.model,
|
|
82
|
+
modelReason: choice.reason,
|
|
83
|
+
name: options.name ?? basename(classified.values[0].value),
|
|
84
|
+
warnings: [...warnings, ...generation.warnings],
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
case 'model': {
|
|
88
|
+
const raw = classified.values[0].value;
|
|
89
|
+
const { value } = await resolveInputValue(client, raw);
|
|
90
|
+
const generation = buildStepRequest('import', value, {});
|
|
91
|
+
if (chain.length === 0) {
|
|
92
|
+
warnings.push(t({
|
|
93
|
+
zh: '导入模型后没有加工步骤;用 --then 指定(如 --then texture,rig)',
|
|
94
|
+
en: 'importing a model with no processing steps; add --then (e.g. --then texture,rig)',
|
|
95
|
+
}));
|
|
96
|
+
}
|
|
97
|
+
return {
|
|
98
|
+
generation,
|
|
99
|
+
chain,
|
|
100
|
+
name: options.name ?? basename(raw),
|
|
101
|
+
warnings: [...warnings, ...generation.warnings],
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
case 'task': {
|
|
105
|
+
const { value, sourceTaskType } = await resolveInputValue(client, classified.values[0].value);
|
|
106
|
+
if (chain.length === 0) {
|
|
107
|
+
throw new UsageError('a task reference needs processing steps: add --then (e.g. tripo make @last --then texture,convert:fbx)');
|
|
108
|
+
}
|
|
109
|
+
return {
|
|
110
|
+
sourceTaskId: value,
|
|
111
|
+
sourceType: sourceTaskType,
|
|
112
|
+
chain,
|
|
113
|
+
name: options.name ?? value.slice(0, 8),
|
|
114
|
+
warnings,
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
/** Execute a plan produced by planMake. */
|
|
120
|
+
export async function executeMake(client, plan, options) {
|
|
121
|
+
for (const w of plan.warnings)
|
|
122
|
+
warn(w);
|
|
123
|
+
// Validate chain legality up front so an illegal plan spends zero credits.
|
|
124
|
+
if (plan.chain.length > 0) {
|
|
125
|
+
const upstream = plan.generation?.taskType ?? plan.sourceType;
|
|
126
|
+
if (upstream) {
|
|
127
|
+
try {
|
|
128
|
+
validateChain(plan.chain, upstream);
|
|
129
|
+
}
|
|
130
|
+
catch (error) {
|
|
131
|
+
if (error instanceof ChainError)
|
|
132
|
+
throw new UsageError(error.message);
|
|
133
|
+
throw error;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
await precheckBalance(client);
|
|
138
|
+
let sourceTaskId;
|
|
139
|
+
let sourceType;
|
|
140
|
+
let primary;
|
|
141
|
+
if (plan.generation) {
|
|
142
|
+
if (plan.model && plan.modelReason) {
|
|
143
|
+
log(t({ zh: `模型选择:${plan.model}(${plan.modelReason})`, en: `model: ${plan.model} (${plan.modelReason})` }));
|
|
144
|
+
}
|
|
145
|
+
primary = await runTask({
|
|
146
|
+
client,
|
|
147
|
+
request: plan.generation.request,
|
|
148
|
+
taskType: plan.generation.taskType,
|
|
149
|
+
name: plan.name,
|
|
150
|
+
outDir: options.outDir,
|
|
151
|
+
noWait: options.noWait,
|
|
152
|
+
noDownload: options.noDownload || plan.chain.length > 0,
|
|
153
|
+
timeoutMs: options.timeoutMs,
|
|
154
|
+
notify: options.notify && plan.chain.length === 0,
|
|
155
|
+
precheckBalance: false,
|
|
156
|
+
});
|
|
157
|
+
if (options.noWait)
|
|
158
|
+
return { primary, chainResults: [] };
|
|
159
|
+
sourceTaskId = primary.task_id;
|
|
160
|
+
sourceType = plan.generation.taskType;
|
|
161
|
+
}
|
|
162
|
+
else {
|
|
163
|
+
sourceTaskId = plan.sourceTaskId;
|
|
164
|
+
sourceType = plan.sourceType ?? (await assertSourceReady(client, sourceTaskId));
|
|
165
|
+
primary = { task_id: sourceTaskId, type: sourceType, status: 'success' };
|
|
166
|
+
}
|
|
167
|
+
if (plan.chain.length === 0) {
|
|
168
|
+
return { primary, chainResults: [] };
|
|
169
|
+
}
|
|
170
|
+
const { results, stoppedEarly } = await runChain({
|
|
171
|
+
client,
|
|
172
|
+
chain: plan.chain,
|
|
173
|
+
sourceTaskId,
|
|
174
|
+
sourceType,
|
|
175
|
+
namePrefix: plan.name,
|
|
176
|
+
outDir: options.outDir,
|
|
177
|
+
notify: false,
|
|
178
|
+
timeoutMs: options.timeoutMs,
|
|
179
|
+
});
|
|
180
|
+
// If the chain stopped early (not riggable) and nothing was downloaded yet,
|
|
181
|
+
// fetch the source artifacts so the user still gets their model.
|
|
182
|
+
if (stoppedEarly && plan.generation && !options.noDownload) {
|
|
183
|
+
const detail = await client.getTask(sourceTaskId);
|
|
184
|
+
const { downloadArtifacts, defaultOutputDir } = await import('../core/download.js');
|
|
185
|
+
const { slugify } = await import('../config/history.js');
|
|
186
|
+
const dir = defaultOutputDir(options.outDir ?? process.cwd(), slugify(plan.name), sourceTaskId);
|
|
187
|
+
const artifacts = await downloadArtifacts(detail, dir);
|
|
188
|
+
primary.output_dir = artifacts.outputDir;
|
|
189
|
+
primary.model_file = artifacts.modelFile;
|
|
190
|
+
primary.preview = artifacts.preview;
|
|
191
|
+
}
|
|
192
|
+
return { primary, chainResults: results, stoppedEarly };
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Map 2–4 images to views. Filename hints (front/back/left/right, 前/后/左/右)
|
|
196
|
+
* win; remaining slots fill positionally in [front, left, back, right] order.
|
|
197
|
+
*/
|
|
198
|
+
export async function assignViews(client, files) {
|
|
199
|
+
if (files.length < 2 || files.length > 4) {
|
|
200
|
+
throw new UsageError(`multiview needs 2–4 images (got ${files.length})`);
|
|
201
|
+
}
|
|
202
|
+
const hints = {
|
|
203
|
+
front: /front|正面|前/i,
|
|
204
|
+
back: /back|背面|后/i,
|
|
205
|
+
left: /left|左/i,
|
|
206
|
+
right: /right|右/i,
|
|
207
|
+
};
|
|
208
|
+
const views = {};
|
|
209
|
+
const unassigned = [];
|
|
210
|
+
for (const file of files) {
|
|
211
|
+
const name = basename(file);
|
|
212
|
+
const hit = Object.entries(hints).find(([view, re]) => !views[view] && re.test(name));
|
|
213
|
+
if (hit)
|
|
214
|
+
views[hit[0]] = file;
|
|
215
|
+
else
|
|
216
|
+
unassigned.push(file);
|
|
217
|
+
}
|
|
218
|
+
const order = ['front', 'left', 'back', 'right'];
|
|
219
|
+
for (const file of unassigned) {
|
|
220
|
+
const slot = order.find((v) => !views[v]);
|
|
221
|
+
if (!slot)
|
|
222
|
+
throw new UsageError('too many images for 4 view slots');
|
|
223
|
+
views[slot] = file;
|
|
224
|
+
}
|
|
225
|
+
if (!views.front) {
|
|
226
|
+
throw new UsageError('multiview requires a front view — name one file with "front" or pass it first');
|
|
227
|
+
}
|
|
228
|
+
const resolved = {};
|
|
229
|
+
for (const [view, file] of Object.entries(views)) {
|
|
230
|
+
resolved[view] = (await resolveInputValue(client, file)).value;
|
|
231
|
+
}
|
|
232
|
+
return resolved;
|
|
233
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Chain runner: execute a validated sequence of processing steps, feeding
|
|
3
|
+
* each step the previous task id. rig-check gates the rig step (stop early
|
|
4
|
+
* when the model is not riggable, and adopt the recommended rig_type).
|
|
5
|
+
*/
|
|
6
|
+
import { UsageError } from '../core/errors.js';
|
|
7
|
+
import { log, warn } from '../core/output.js';
|
|
8
|
+
import { buildStepRequest } from '../core/requests.js';
|
|
9
|
+
import { runTask } from '../core/task-service.js';
|
|
10
|
+
import { t } from '../i18n.js';
|
|
11
|
+
import { getStep, validateChain } from '../knowledge/chains.js';
|
|
12
|
+
export async function runChain(options) {
|
|
13
|
+
const { client, chain } = options;
|
|
14
|
+
validateChain(chain, options.sourceType);
|
|
15
|
+
const results = [];
|
|
16
|
+
let currentTaskId = options.sourceTaskId;
|
|
17
|
+
let rigTypeRecommendation;
|
|
18
|
+
for (let i = 0; i < chain.length; i++) {
|
|
19
|
+
const spec = chain[i];
|
|
20
|
+
const args = { ...spec.args };
|
|
21
|
+
if (spec.step === 'rig' && rigTypeRecommendation && args.rig_type === undefined) {
|
|
22
|
+
args.rig_type = rigTypeRecommendation;
|
|
23
|
+
log(t({ zh: `采用 rig-check 推荐体型:${rigTypeRecommendation}`, en: `using rig-check recommendation: ${rigTypeRecommendation}` }));
|
|
24
|
+
}
|
|
25
|
+
const built = buildStepRequest(spec.step, currentTaskId, args);
|
|
26
|
+
for (const w of built.warnings)
|
|
27
|
+
warn(w);
|
|
28
|
+
const result = await runTask({
|
|
29
|
+
client,
|
|
30
|
+
request: built.request,
|
|
31
|
+
taskType: built.taskType,
|
|
32
|
+
name: `${options.namePrefix}-${spec.step}`,
|
|
33
|
+
outDir: options.outDir,
|
|
34
|
+
notify: false,
|
|
35
|
+
timeoutMs: options.timeoutMs,
|
|
36
|
+
// Intermediate steps skip download; final step downloads.
|
|
37
|
+
noDownload: i < chain.length - 1 && spec.step !== 'rig-check',
|
|
38
|
+
precheckBalance: false, // checked once by the caller
|
|
39
|
+
});
|
|
40
|
+
results.push(result);
|
|
41
|
+
if (spec.step === 'rig-check') {
|
|
42
|
+
const verdict = await client.getTask(result.task_id);
|
|
43
|
+
const output = verdict.output ?? {};
|
|
44
|
+
const riggable = output.riggable;
|
|
45
|
+
rigTypeRecommendation = typeof output.rig_type === 'string' ? output.rig_type : undefined;
|
|
46
|
+
if (riggable === false) {
|
|
47
|
+
const message = t({
|
|
48
|
+
zh: 'rig-check 判定该模型不可绑骨,动画链止损停止(后续步骤未执行,未扣积分)',
|
|
49
|
+
en: 'rig-check says this model is not riggable; stopping the chain early (no further credits spent)',
|
|
50
|
+
});
|
|
51
|
+
warn(message);
|
|
52
|
+
return { results, stoppedEarly: message };
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
// Gate steps (passthrough) inspect the model; the chain continues from
|
|
56
|
+
// the same upstream task.
|
|
57
|
+
if (!getStep(spec.step)?.passthrough) {
|
|
58
|
+
currentTaskId = result.task_id;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return { results };
|
|
62
|
+
}
|
|
63
|
+
/** Ensure a source task exists + succeeded before chaining onto it. */
|
|
64
|
+
export async function assertSourceReady(client, taskId) {
|
|
65
|
+
const task = await client.getTask(taskId);
|
|
66
|
+
if (task.status !== 'success') {
|
|
67
|
+
throw new UsageError(`task ${taskId} is ${task.status}; processing steps need a successful upstream task` +
|
|
68
|
+
(task.status === 'running' || task.status === 'queued'
|
|
69
|
+
? ` (wait with "tripo task watch ${taskId}")`
|
|
70
|
+
: ''));
|
|
71
|
+
}
|
|
72
|
+
return task.type;
|
|
73
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* NDJSON pipe support: downstream commands read the upstream task result from
|
|
3
|
+
* stdin, enabling `tripo make cat.png | tripo model texture | tripo anim rig`.
|
|
4
|
+
*/
|
|
5
|
+
/** Read piped NDJSON/JSON from stdin; returns undefined on a TTY. */
|
|
6
|
+
export async function readPipedTask() {
|
|
7
|
+
if (process.stdin.isTTY)
|
|
8
|
+
return undefined;
|
|
9
|
+
const raw = await readAll(process.stdin);
|
|
10
|
+
return parsePipedText(raw);
|
|
11
|
+
}
|
|
12
|
+
/** Parse piped text: JSON object, NDJSON (last task line wins), or a bare task id. */
|
|
13
|
+
export function parsePipedText(raw) {
|
|
14
|
+
const text = raw.trim();
|
|
15
|
+
if (!text)
|
|
16
|
+
return undefined;
|
|
17
|
+
const lines = text.split('\n').map((l) => l.trim()).filter(Boolean);
|
|
18
|
+
for (let i = lines.length - 1; i >= 0; i--) {
|
|
19
|
+
try {
|
|
20
|
+
const obj = JSON.parse(lines[i]);
|
|
21
|
+
if (typeof obj.task_id === 'string') {
|
|
22
|
+
return { task_id: obj.task_id, type: typeof obj.type === 'string' ? obj.type : undefined };
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
catch { }
|
|
26
|
+
}
|
|
27
|
+
const last = lines[lines.length - 1];
|
|
28
|
+
if (/^(task_[A-Za-z0-9_-]+|[0-9a-f-]{36})$/i.test(last))
|
|
29
|
+
return { task_id: last };
|
|
30
|
+
return undefined;
|
|
31
|
+
}
|
|
32
|
+
function readAll(stream) {
|
|
33
|
+
return new Promise((resolve, reject) => {
|
|
34
|
+
let data = '';
|
|
35
|
+
stream.setEncoding('utf8');
|
|
36
|
+
stream.on('data', (chunk) => (data += chunk));
|
|
37
|
+
stream.on('end', () => resolve(data));
|
|
38
|
+
stream.on('error', reject);
|
|
39
|
+
});
|
|
40
|
+
}
|
package/dist/program.js
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
/** Command tree assembly + global flags + the error → exit-code boundary. */
|
|
2
|
+
import { Command } from 'commander';
|
|
3
|
+
import pc from 'picocolors';
|
|
4
|
+
import { registerAccountCommands } from './commands/account.js';
|
|
5
|
+
import { registerAiCommand } from './commands/ai.js';
|
|
6
|
+
import { registerAuthCommands } from './commands/login.js';
|
|
7
|
+
import { registerBatchCommand } from './commands/batch.js';
|
|
8
|
+
import { registerCompletionCommand } from './commands/completion.js';
|
|
9
|
+
import { registerConfigCommands } from './commands/config-cmd.js';
|
|
10
|
+
import { registerDoctorCommand } from './commands/doctor.js';
|
|
11
|
+
import { registerDocsCommand } from './commands/docs.js';
|
|
12
|
+
import { registerGenerateCommands } from './commands/generate.js';
|
|
13
|
+
import { registerHomeAction } from './commands/home.js';
|
|
14
|
+
import { registerMakeCommand } from './commands/make.js';
|
|
15
|
+
import { registerMcpCommand } from './commands/mcp.js';
|
|
16
|
+
import { registerProcessCommands } from './commands/process-groups.js';
|
|
17
|
+
import { registerTaskCommands } from './commands/task.js';
|
|
18
|
+
import { registerTopupCommand } from './commands/topup.js';
|
|
19
|
+
import { registerViewCommands } from './commands/view.js';
|
|
20
|
+
import { loadConfig } from './config/config.js';
|
|
21
|
+
import { RefError } from './config/history.js';
|
|
22
|
+
import { ApiError, CliError, UsageError } from './core/errors.js';
|
|
23
|
+
import { configureOutput, errorLine, isJsonMode } from './core/output.js';
|
|
24
|
+
import { setLocale, t } from './i18n.js';
|
|
25
|
+
import { EXIT } from './knowledge/error-catalog.js';
|
|
26
|
+
import { cliVersion } from './version.js';
|
|
27
|
+
export function buildProgram() {
|
|
28
|
+
const program = new Command();
|
|
29
|
+
program
|
|
30
|
+
.name('tripo')
|
|
31
|
+
.description(t({
|
|
32
|
+
zh: 'Tripo 3D 智能 CLI — 一句话/一张图,直出可进引擎的 3D 资产\n高频: make(生成) ai(专家规划) view(预览) topup(充值)',
|
|
33
|
+
en: 'Tripo 3D intelligent CLI — turn a sentence or an image into engine-ready 3D assets\ntop commands: make · ai · view · topup',
|
|
34
|
+
}))
|
|
35
|
+
.version(cliVersion(), '-v, --version')
|
|
36
|
+
.option('--json', 'machine-readable output on stdout (auto-enabled when piped)')
|
|
37
|
+
.option('--yes', 'skip confirmations (auto-enabled when headless)')
|
|
38
|
+
.option('--quiet', 'suppress progress logs on stderr')
|
|
39
|
+
.option('--no-open', 'never auto-open the browser/viewer')
|
|
40
|
+
.enablePositionalOptions()
|
|
41
|
+
.showSuggestionAfterError(true);
|
|
42
|
+
program.hook('preAction', (_thisCommand, actionCommand) => {
|
|
43
|
+
configureOutput({
|
|
44
|
+
json: resolveGlobalFlag(actionCommand, 'json', false),
|
|
45
|
+
yes: resolveGlobalFlag(actionCommand, 'yes', false),
|
|
46
|
+
quiet: resolveGlobalFlag(actionCommand, 'quiet', false),
|
|
47
|
+
noOpen: !resolveGlobalFlag(actionCommand, 'open', true),
|
|
48
|
+
});
|
|
49
|
+
const lang = loadConfig().language;
|
|
50
|
+
if (lang)
|
|
51
|
+
setLocale(lang);
|
|
52
|
+
});
|
|
53
|
+
registerMakeCommand(program);
|
|
54
|
+
registerAiCommand(program);
|
|
55
|
+
registerViewCommands(program);
|
|
56
|
+
registerAuthCommands(program);
|
|
57
|
+
registerTopupCommand(program);
|
|
58
|
+
registerAccountCommands(program);
|
|
59
|
+
registerGenerateCommands(program);
|
|
60
|
+
registerProcessCommands(program);
|
|
61
|
+
registerTaskCommands(program);
|
|
62
|
+
registerBatchCommand(program);
|
|
63
|
+
registerConfigCommands(program);
|
|
64
|
+
registerDoctorCommand(program);
|
|
65
|
+
registerDocsCommand(program);
|
|
66
|
+
registerCompletionCommand(program);
|
|
67
|
+
registerMcpCommand(program);
|
|
68
|
+
registerHomeAction(program);
|
|
69
|
+
attachGlobalFlags(program);
|
|
70
|
+
return program;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* The 4 global flags live on every leaf command so `tripo balance --json`
|
|
74
|
+
* works the way people type it (prefix `tripo --json balance` works too).
|
|
75
|
+
*/
|
|
76
|
+
function attachGlobalFlags(cmd) {
|
|
77
|
+
for (const sub of cmd.commands)
|
|
78
|
+
attachGlobalFlags(sub);
|
|
79
|
+
if (cmd.commands.length > 0)
|
|
80
|
+
return;
|
|
81
|
+
const has = (long) => cmd.options.some((o) => o.long === long);
|
|
82
|
+
if (!has('--json'))
|
|
83
|
+
cmd.option('--json', 'machine-readable output on stdout');
|
|
84
|
+
if (!has('--yes'))
|
|
85
|
+
cmd.option('--yes', 'skip confirmations');
|
|
86
|
+
if (!has('--quiet'))
|
|
87
|
+
cmd.option('--quiet', 'suppress progress logs on stderr');
|
|
88
|
+
if (!has('--no-open'))
|
|
89
|
+
cmd.option('--no-open', 'never auto-open the browser/viewer');
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Resolve a flag along the command chain, innermost explicit value first.
|
|
93
|
+
* (optsWithGlobals can't do this: a leaf's *default* would shadow an explicit
|
|
94
|
+
* `tripo --no-open <cmd>` on the root.)
|
|
95
|
+
*/
|
|
96
|
+
function resolveGlobalFlag(cmd, key, def) {
|
|
97
|
+
for (let c = cmd; c; c = c.parent) {
|
|
98
|
+
const source = c.getOptionValueSource(key);
|
|
99
|
+
if (source !== undefined && source !== 'default')
|
|
100
|
+
return Boolean(c.getOptionValue(key));
|
|
101
|
+
}
|
|
102
|
+
return def;
|
|
103
|
+
}
|
|
104
|
+
/** Run the CLI; converts errors into the stable exit-code contract. */
|
|
105
|
+
export async function runCli(argv) {
|
|
106
|
+
const program = buildProgram();
|
|
107
|
+
try {
|
|
108
|
+
await program.parseAsync(argv);
|
|
109
|
+
}
|
|
110
|
+
catch (err) {
|
|
111
|
+
handleError(err);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
export function handleError(err) {
|
|
115
|
+
// History reference misses (@last with empty history etc.) are usage errors.
|
|
116
|
+
if (err instanceof RefError)
|
|
117
|
+
err = new UsageError(err.message);
|
|
118
|
+
if (err instanceof CliError) {
|
|
119
|
+
if (isJsonMode()) {
|
|
120
|
+
process.stdout.write(JSON.stringify({
|
|
121
|
+
error: err.message,
|
|
122
|
+
exit_code: err.exitCode,
|
|
123
|
+
...(err instanceof ApiError
|
|
124
|
+
? { api_code: err.apiCode, request_id: err.requestId, http_status: err.httpStatus }
|
|
125
|
+
: {}),
|
|
126
|
+
...(err.suggestion ? { suggestion: err.suggestion } : {}),
|
|
127
|
+
}) + '\n');
|
|
128
|
+
}
|
|
129
|
+
errorLine(err.message);
|
|
130
|
+
if (err.suggestion)
|
|
131
|
+
process.stderr.write(pc.dim(` → ${err.suggestion}\n`));
|
|
132
|
+
if (err instanceof ApiError && err.requestId) {
|
|
133
|
+
process.stderr.write(pc.dim(` request_id: ${err.requestId}\n`));
|
|
134
|
+
}
|
|
135
|
+
process.exit(err.exitCode);
|
|
136
|
+
}
|
|
137
|
+
// commander already printed its own message for help/version pseudo-errors
|
|
138
|
+
if (typeof err === 'object' && err !== null && 'code' in err) {
|
|
139
|
+
const code = err.code ?? '';
|
|
140
|
+
if (code.startsWith('commander.')) {
|
|
141
|
+
process.exit(code === 'commander.help' || code === 'commander.version' || code === 'commander.helpDisplayed' ? 0 : EXIT.USAGE);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
const message = err instanceof Error ? (err.stack ?? err.message) : String(err);
|
|
145
|
+
errorLine(message);
|
|
146
|
+
process.exit(EXIT.FATAL);
|
|
147
|
+
}
|