tripo-cli 0.1.0 → 0.2.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 +20 -4
- package/dist/commands/completion.js +1 -1
- package/dist/commands/config-cmd.js +32 -17
- package/dist/commands/doctor.js +6 -5
- package/dist/commands/home.js +4 -2
- package/dist/commands/login.js +201 -39
- package/dist/config/config.js +103 -14
- package/dist/core/client.js +16 -2
- package/dist/core/device-auth.js +41 -9
- package/dist/program.js +21 -1
- package/package.json +2 -2
- package/skill/SKILL.md +13 -1
- package/skill/commands/account.md +19 -5
- package/dist/src/ai/experts.js +0 -115
- package/dist/src/ai/llm.js +0 -88
- package/dist/src/ai/plan-card.js +0 -79
- package/dist/src/ai/wizard.js +0 -104
- package/dist/src/cli.js +0 -7
- package/dist/src/commands/account.js +0 -27
- package/dist/src/commands/ai.js +0 -113
- package/dist/src/commands/batch.js +0 -148
- package/dist/src/commands/completion.js +0 -84
- package/dist/src/commands/config-cmd.js +0 -84
- package/dist/src/commands/docs.js +0 -30
- package/dist/src/commands/doctor.js +0 -94
- package/dist/src/commands/generate.js +0 -81
- package/dist/src/commands/home.js +0 -68
- package/dist/src/commands/login.js +0 -225
- package/dist/src/commands/make.js +0 -142
- package/dist/src/commands/mcp.js +0 -194
- package/dist/src/commands/process-groups.js +0 -164
- package/dist/src/commands/shared.js +0 -75
- package/dist/src/commands/task.js +0 -127
- package/dist/src/commands/topup.js +0 -61
- package/dist/src/commands/view.js +0 -97
- package/dist/src/config/config.js +0 -79
- package/dist/src/config/context.js +0 -44
- package/dist/src/config/history.js +0 -104
- package/dist/src/core/client.js +0 -120
- package/dist/src/core/download.js +0 -107
- package/dist/src/core/errors.js +0 -64
- package/dist/src/core/output.js +0 -72
- package/dist/src/core/requests.js +0 -169
- package/dist/src/core/task-service.js +0 -161
- package/dist/src/core/upload.js +0 -36
- package/dist/src/core/viewer-assets.js +0 -24
- package/dist/src/core/viewer.js +0 -59
- package/dist/src/core/watch.js +0 -41
- package/dist/src/i18n.js +0 -19
- package/dist/src/knowledge/chains.js +0 -152
- package/dist/src/knowledge/error-catalog.js +0 -91
- package/dist/src/knowledge/models.js +0 -110
- package/dist/src/knowledge/params.js +0 -174
- package/dist/src/knowledge/scenarios.js +0 -112
- package/dist/src/pipeline/make.js +0 -233
- package/dist/src/pipeline/runner.js +0 -73
- package/dist/src/pipeline/stdin.js +0 -40
- package/dist/src/program.js +0 -147
- package/dist/src/types.js +0 -2
- package/dist/src/util/input-detect.js +0 -92
- package/dist/src/util/notify.js +0 -17
- package/dist/src/util/open.js +0 -18
- package/dist/src/util/spinner.js +0 -62
- package/dist/src/util/term-image.js +0 -28
- package/dist/src/version.js +0 -10
|
@@ -1,233 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,73 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
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/src/program.js
DELETED
|
@@ -1,147 +0,0 @@
|
|
|
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
|
-
}
|
package/dist/src/types.js
DELETED
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Input classification for `tripo make` and friends: figure out what the user
|
|
3
|
-
* gave us (text prompt / image / model file / URL / task id / history ref)
|
|
4
|
-
* without asking them to know the difference.
|
|
5
|
-
*/
|
|
6
|
-
import { existsSync, statSync } from 'node:fs';
|
|
7
|
-
import { extname } from 'node:path';
|
|
8
|
-
export const IMAGE_EXTS = new Set(['.png', '.jpg', '.jpeg', '.webp', '.bmp']);
|
|
9
|
-
export const MODEL_EXTS = new Set(['.glb', '.gltf', '.fbx', '.obj', '.stl']);
|
|
10
|
-
const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
11
|
-
const TASK_RE = /^task_[A-Za-z0-9_-]+$/;
|
|
12
|
-
const FILE_TOKEN_RE = /^file_[A-Za-z0-9_-]+$/;
|
|
13
|
-
export function detectInput(raw) {
|
|
14
|
-
const value = raw.trim();
|
|
15
|
-
if (value.startsWith('@'))
|
|
16
|
-
return { kind: 'history-ref', value };
|
|
17
|
-
if (FILE_TOKEN_RE.test(value))
|
|
18
|
-
return { kind: 'file-token', value };
|
|
19
|
-
if (TASK_RE.test(value) || UUID_RE.test(value))
|
|
20
|
-
return { kind: 'task-id', value };
|
|
21
|
-
if (/^https?:\/\//i.test(value))
|
|
22
|
-
return { kind: 'url', value };
|
|
23
|
-
if (isExistingFile(value)) {
|
|
24
|
-
const ext = extname(value).toLowerCase();
|
|
25
|
-
if (IMAGE_EXTS.has(ext))
|
|
26
|
-
return { kind: 'image-file', value };
|
|
27
|
-
if (MODEL_EXTS.has(ext))
|
|
28
|
-
return { kind: 'model-file', value };
|
|
29
|
-
// A real file with an unknown extension is still most likely an asset;
|
|
30
|
-
// treat by extension guess, otherwise reject early with a clear message.
|
|
31
|
-
throw new InputDetectError(`"${value}" exists but has an unsupported extension "${ext}" (images: ${[...IMAGE_EXTS].join(' ')}; models: ${[...MODEL_EXTS].join(' ')})`);
|
|
32
|
-
}
|
|
33
|
-
// Looks like a path but doesn't exist → almost certainly a typo, not a prompt.
|
|
34
|
-
if (looksLikePath(value)) {
|
|
35
|
-
throw new InputDetectError(`file not found: "${value}" (if you meant a text prompt, quote a sentence instead)`);
|
|
36
|
-
}
|
|
37
|
-
return { kind: 'text', value };
|
|
38
|
-
}
|
|
39
|
-
export function classifyInputs(args) {
|
|
40
|
-
if (args.length === 0)
|
|
41
|
-
throw new InputDetectError('no input given');
|
|
42
|
-
const detected = args.map(detectInput);
|
|
43
|
-
const kinds = new Set(detected.map((d) => d.kind));
|
|
44
|
-
if (kinds.size === 1) {
|
|
45
|
-
const kind = detected[0].kind;
|
|
46
|
-
switch (kind) {
|
|
47
|
-
case 'text':
|
|
48
|
-
// Multiple bare words are one prompt, joined.
|
|
49
|
-
return { kind: 'text', values: [{ kind: 'text', value: args.join(' ') }] };
|
|
50
|
-
case 'image-file':
|
|
51
|
-
return detected.length === 1
|
|
52
|
-
? { kind: 'image', values: detected }
|
|
53
|
-
: { kind: 'multiview', values: detected };
|
|
54
|
-
case 'model-file':
|
|
55
|
-
if (detected.length > 1)
|
|
56
|
-
throw new InputDetectError('only one model file at a time');
|
|
57
|
-
return { kind: 'model', values: detected };
|
|
58
|
-
case 'url':
|
|
59
|
-
if (detected.length > 1)
|
|
60
|
-
return { kind: 'multiview', values: detected };
|
|
61
|
-
return { kind: 'url-image', values: detected };
|
|
62
|
-
case 'task-id':
|
|
63
|
-
case 'history-ref':
|
|
64
|
-
case 'file-token':
|
|
65
|
-
if (detected.length > 1)
|
|
66
|
-
throw new InputDetectError('only one task reference at a time');
|
|
67
|
-
return { kind: 'task', values: detected };
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
// Mixed images + urls → multiview; anything else mixed is ambiguous.
|
|
71
|
-
if ([...kinds].every((k) => k === 'image-file' || k === 'url')) {
|
|
72
|
-
return { kind: 'multiview', values: detected };
|
|
73
|
-
}
|
|
74
|
-
throw new InputDetectError(`mixed input types (${[...kinds].join(' + ')}) — pass one kind of input per command`);
|
|
75
|
-
}
|
|
76
|
-
export class InputDetectError extends Error {
|
|
77
|
-
}
|
|
78
|
-
function isExistingFile(p) {
|
|
79
|
-
try {
|
|
80
|
-
return existsSync(p) && statSync(p).isFile();
|
|
81
|
-
}
|
|
82
|
-
catch {
|
|
83
|
-
return false;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
function looksLikePath(value) {
|
|
87
|
-
if (/\s/.test(value))
|
|
88
|
-
return false;
|
|
89
|
-
const ext = extname(value).toLowerCase();
|
|
90
|
-
return ((value.includes('/') || value.includes('\\') || IMAGE_EXTS.has(ext) || MODEL_EXTS.has(ext)) &&
|
|
91
|
-
!value.includes(' '));
|
|
92
|
-
}
|
package/dist/src/util/notify.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/** Desktop notification + terminal bell for long-running task completion. */
|
|
2
|
-
import { spawn } from 'node:child_process';
|
|
3
|
-
export function notifyDone(title, message) {
|
|
4
|
-
try {
|
|
5
|
-
if (process.platform === 'darwin') {
|
|
6
|
-
const script = `display notification ${JSON.stringify(message)} with title ${JSON.stringify(title)}`;
|
|
7
|
-
spawn('osascript', ['-e', script], { stdio: 'ignore', detached: true }).on('error', () => { }); // best-effort
|
|
8
|
-
}
|
|
9
|
-
else if (process.platform === 'linux') {
|
|
10
|
-
spawn('notify-send', [title, message], { stdio: 'ignore', detached: true }).on('error', () => { });
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
catch { }
|
|
14
|
-
// Terminal bell as the lowest common denominator.
|
|
15
|
-
if (process.stderr.isTTY)
|
|
16
|
-
process.stderr.write('\x07');
|
|
17
|
-
}
|
package/dist/src/util/open.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/** Cross-platform "open in default app/browser" without extra dependencies. */
|
|
2
|
-
import { spawn } from 'node:child_process';
|
|
3
|
-
export function openExternal(target) {
|
|
4
|
-
try {
|
|
5
|
-
const [cmd, args] = process.platform === 'darwin'
|
|
6
|
-
? ['open', [target]]
|
|
7
|
-
: process.platform === 'win32'
|
|
8
|
-
? ['cmd', ['/c', 'start', '', target]]
|
|
9
|
-
: ['xdg-open', [target]];
|
|
10
|
-
const child = spawn(cmd, args, { stdio: 'ignore', detached: true });
|
|
11
|
-
child.on('error', () => { });
|
|
12
|
-
child.unref();
|
|
13
|
-
return true;
|
|
14
|
-
}
|
|
15
|
-
catch {
|
|
16
|
-
return false;
|
|
17
|
-
}
|
|
18
|
-
}
|