u1s1-cli 1.2.3 → 1.2.5
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/dist/agent-setup.js +3 -3
- package/dist/api.d.ts +5 -1
- package/dist/api.js +6 -6
- package/dist/bench-report.d.ts +22 -0
- package/dist/bench-report.js +158 -0
- package/dist/bench-scoring.d.ts +8 -0
- package/dist/bench-scoring.js +101 -0
- package/dist/bench-types.d.ts +50 -0
- package/dist/bench-types.js +1 -0
- package/dist/bench.js +101 -367
- package/dist/brand.d.ts +9 -3
- package/dist/brand.js +12 -12
- package/dist/deploy.js +72 -49
- package/dist/embed.d.ts +1 -1
- package/dist/embed.js +1 -1
- package/dist/import/claude.d.ts +2 -1
- package/dist/import/claude.js +162 -129
- package/dist/import/codex.d.ts +2 -1
- package/dist/import/codex.js +184 -157
- package/dist/import/index.js +62 -47
- package/dist/index.js +13 -13
- package/dist/shell-doctor.d.ts +4 -1
- package/dist/shell-doctor.js +35 -25
- package/dist/style.js +7 -1
- package/dist/subagent.d.ts +6 -1
- package/dist/subagent.js +4 -4
- package/dist/tools.d.ts +18 -12
- package/dist/tools.js +22 -16
- package/dist/usage.js +95 -74
- package/dist/webui-brand.d.ts +0 -7
- package/dist/webui-brand.js +4 -32
- package/dist/workflow/runner.js +36 -26
- package/dist/workflow/tool.js +67 -55
- package/package.json +1 -1
- package/scripts/render-regression.mjs +3 -1
package/dist/workflow/tool.js
CHANGED
|
@@ -6,6 +6,65 @@ import { Type } from "typebox";
|
|
|
6
6
|
import { compactResultRender, truncate } from "../tools.js";
|
|
7
7
|
import { runWorkflow, saveWorkflowScript, validateScript, workflowsDir, WORKFLOW_DEFAULT_BUDGET_TOKENS, WORKFLOW_TIMEOUT_MS, } from "./runner.js";
|
|
8
8
|
import { buildFromTemplate, TEMPLATES } from "./templates.js";
|
|
9
|
+
function assertValidWorkflowCode(code) {
|
|
10
|
+
const errors = validateScript(code);
|
|
11
|
+
if (errors.length > 0) {
|
|
12
|
+
throw new Error(`脚本未通过静态校验,请修复后重试:\n- ${errors.join("\n- ")}`);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
function buildTemplateSource(template, input) {
|
|
16
|
+
try {
|
|
17
|
+
return buildFromTemplate(template, input);
|
|
18
|
+
}
|
|
19
|
+
catch (error) {
|
|
20
|
+
throw new Error(`${error.message}\n模板 input 说明:${TEMPLATES[template]?.inputHint ?? "—"}`, { cause: error });
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
function readWorkflowSource(scriptPath) {
|
|
24
|
+
try {
|
|
25
|
+
return readFileSync(scriptPath, "utf8");
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
throw new Error(`读不到脚本文件:${scriptPath}`);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
function resolveWorkflowSource(params) {
|
|
32
|
+
const saveAs = params.save_as?.trim();
|
|
33
|
+
if (saveAs && !/^[a-zA-Z0-9_-]+$/.test(saveAs)) {
|
|
34
|
+
throw new Error("save_as 只允许字母、数字、横线和下划线");
|
|
35
|
+
}
|
|
36
|
+
if (saveAs && params.script_path?.trim()) {
|
|
37
|
+
throw new Error("script_path 指向的脚本已经落盘,不能再配 save_as;要另存新名字请用 script 传入源码");
|
|
38
|
+
}
|
|
39
|
+
const inlineCode = params.script?.trim();
|
|
40
|
+
if (inlineCode) {
|
|
41
|
+
assertValidWorkflowCode(inlineCode);
|
|
42
|
+
return { code: inlineCode, saveAs };
|
|
43
|
+
}
|
|
44
|
+
const template = params.template?.trim();
|
|
45
|
+
if (template) {
|
|
46
|
+
return { code: buildTemplateSource(template, params.input ?? {}), saveAs };
|
|
47
|
+
}
|
|
48
|
+
const requestedPath = params.script_path?.trim();
|
|
49
|
+
if (requestedPath) {
|
|
50
|
+
const scriptPath = resolve(requestedPath);
|
|
51
|
+
return { code: readWorkflowSource(scriptPath), scriptPath };
|
|
52
|
+
}
|
|
53
|
+
throw new Error("script、template、script_path 至少填一个");
|
|
54
|
+
}
|
|
55
|
+
function persistWorkflowSource(source) {
|
|
56
|
+
if (source.scriptPath)
|
|
57
|
+
return source.scriptPath;
|
|
58
|
+
if (!source.saveAs)
|
|
59
|
+
return saveWorkflowScript(source.code);
|
|
60
|
+
const scriptPath = resolve(workflowsDir(), `${source.saveAs}.mjs`);
|
|
61
|
+
if (existsSync(scriptPath)) {
|
|
62
|
+
throw new Error(`工作流 "${source.saveAs}" 已存在(${scriptPath})。要重跑它请用 script_path 指向该文件(可加 resume:true 续跑);要新建请换个名字`);
|
|
63
|
+
}
|
|
64
|
+
mkdirSync(dirname(scriptPath), { recursive: true });
|
|
65
|
+
writeFileSync(scriptPath, source.code);
|
|
66
|
+
return scriptPath;
|
|
67
|
+
}
|
|
9
68
|
/**
|
|
10
69
|
* run_workflow 工具:主 agent 把模型生成的编排脚本交给 WorkflowRunner 执行。
|
|
11
70
|
* 脚本在 vm 沙箱里跑,只能用注入的 subagent/parallel/pipeline 原语。
|
|
@@ -61,67 +120,20 @@ export function createRunWorkflowTool(getParentModel) {
|
|
|
61
120
|
renderCall() {
|
|
62
121
|
return new Text("", 0, 0);
|
|
63
122
|
},
|
|
64
|
-
renderResult(
|
|
123
|
+
renderResult(...args) {
|
|
124
|
+
const [result, options, theme, context] = args;
|
|
65
125
|
const d = result.details;
|
|
66
126
|
const summary = d && typeof d.ok === "number"
|
|
67
127
|
? `🧭 工作流 · ✓${d.ok}${d.failed ? ` ✗${d.failed}` : ""}` +
|
|
68
128
|
(typeof d.seconds === "number" ? ` · ${d.seconds}s` : "") +
|
|
69
129
|
(d.aborted ? " · 已中止" : "")
|
|
70
130
|
: "🧭 工作流";
|
|
71
|
-
return compactResultRender(result, options, theme, context, summary);
|
|
131
|
+
return compactResultRender({ result, options, theme, context, summaryLine: summary });
|
|
72
132
|
},
|
|
73
|
-
async execute(
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
const
|
|
77
|
-
if (named && !/^[a-zA-Z0-9_-]+$/.test(named)) {
|
|
78
|
-
throw new Error("save_as 只允许字母、数字、横线和下划线");
|
|
79
|
-
}
|
|
80
|
-
if (named && params.script_path?.trim()) {
|
|
81
|
-
throw new Error("script_path 指向的脚本已经落盘,不能再配 save_as;要另存新名字请用 script 传入源码");
|
|
82
|
-
}
|
|
83
|
-
if (code) {
|
|
84
|
-
const errors = validateScript(code);
|
|
85
|
-
if (errors.length > 0) {
|
|
86
|
-
throw new Error(`脚本未通过静态校验,请修复后重试:\n- ${errors.join("\n- ")}`);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
else if (params.template?.trim()) {
|
|
90
|
-
// 内置模板:模型只填参数,脚本由模板生成(生成后自检过静态校验)
|
|
91
|
-
try {
|
|
92
|
-
code = buildFromTemplate(params.template.trim(), (params.input ?? {}));
|
|
93
|
-
}
|
|
94
|
-
catch (e) {
|
|
95
|
-
throw new Error(`${e.message}\n模板 input 说明:${TEMPLATES[params.template.trim()]?.inputHint ?? "—"}`);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
else if (params.script_path?.trim()) {
|
|
99
|
-
scriptPath = resolve(params.script_path.trim());
|
|
100
|
-
try {
|
|
101
|
-
code = readFileSync(scriptPath, "utf8");
|
|
102
|
-
}
|
|
103
|
-
catch {
|
|
104
|
-
throw new Error(`读不到脚本文件:${scriptPath}`);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
else {
|
|
108
|
-
throw new Error("script、template、script_path 至少填一个");
|
|
109
|
-
}
|
|
110
|
-
// 落盘:save_as 用语义化名字(同名报错防覆盖进度配对),否则时间戳名;
|
|
111
|
-
// script_path 分支上面已读入,不重复落盘
|
|
112
|
-
if (!scriptPath) {
|
|
113
|
-
if (named) {
|
|
114
|
-
scriptPath = resolve(workflowsDir(), `${named}.mjs`);
|
|
115
|
-
if (existsSync(scriptPath)) {
|
|
116
|
-
throw new Error(`工作流 "${named}" 已存在(${scriptPath})。要重跑它请用 script_path 指向该文件(可加 resume:true 续跑);要新建请换个名字`);
|
|
117
|
-
}
|
|
118
|
-
mkdirSync(dirname(scriptPath), { recursive: true });
|
|
119
|
-
writeFileSync(scriptPath, code ?? "");
|
|
120
|
-
}
|
|
121
|
-
else {
|
|
122
|
-
scriptPath = saveWorkflowScript(code ?? "");
|
|
123
|
-
}
|
|
124
|
-
}
|
|
133
|
+
async execute(...args) {
|
|
134
|
+
const [, params, signal, onUpdate] = args;
|
|
135
|
+
const source = resolveWorkflowSource(params);
|
|
136
|
+
const scriptPath = persistWorkflowSource(source);
|
|
125
137
|
const progressPath = scriptPath.replace(/\.mjs$/, ".progress.jsonl");
|
|
126
138
|
// 流式进度:onProgress 高频触发,节流到 ≥2s 一次才推给 TUI
|
|
127
139
|
let lastPush = 0;
|
|
@@ -143,7 +155,7 @@ export function createRunWorkflowTool(getParentModel) {
|
|
|
143
155
|
}
|
|
144
156
|
: undefined;
|
|
145
157
|
const result = await runWorkflow({
|
|
146
|
-
code: code
|
|
158
|
+
code: source.code,
|
|
147
159
|
progressPath,
|
|
148
160
|
resume: params.resume === true,
|
|
149
161
|
parentModel: getParentModel(),
|
package/package.json
CHANGED
|
@@ -60,7 +60,9 @@ function hiddenToolDef(orig) {
|
|
|
60
60
|
renderCall() {
|
|
61
61
|
return new Text("", 0, 0);
|
|
62
62
|
},
|
|
63
|
-
|
|
63
|
+
// pi owns this positional callback contract; keep the adapter narrow here.
|
|
64
|
+
renderResult(...args) {
|
|
65
|
+
const [result, { expanded }, theme, context] = args;
|
|
64
66
|
if (context.isError) {
|
|
65
67
|
const c = result.content.find((x) => x.type === "text");
|
|
66
68
|
return new Text(theme.fg("warning", "✗ ") + theme.fg("muted", c?.text ?? "error"), 0, 0);
|