@evandu/super-pi 0.1.116 → 0.1.118
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/.super-pi-check-inputs.json +2 -2
- package/dist/client/.super-pi-client-sources.json +14 -13
- package/dist/client/assets/{CodeMirrorEditor-Clwe70xp.js → CodeMirrorEditor-D9UWxggU.js} +2 -2
- package/dist/client/assets/{dist-BrMKdZVk.js → dist-Adu9a_hi.js} +1 -1
- package/dist/client/assets/{dist-C5tXtmY1.js → dist-BIjlwIeL.js} +1 -1
- package/dist/client/assets/{dist-BYeP-GQ3.js → dist-BSBqp9tS.js} +1 -1
- package/dist/client/assets/{dist-j7xPxyi5.js → dist-BUJwJ5eB.js} +1 -1
- package/dist/client/assets/{dist-BHW4MmlG.js → dist-BWxNjbza.js} +1 -1
- package/dist/client/assets/{dist-XNKM2ykU.js → dist-BewFlCBY.js} +1 -1
- package/dist/client/assets/{dist-CLmxejh8.js → dist-Boep2KRH.js} +1 -1
- package/dist/client/assets/{dist-BDLUOAZX.js → dist-C7waPnE-.js} +1 -1
- package/dist/client/assets/{dist-BgyXimSG.js → dist-CDI2Ko-l.js} +1 -1
- package/dist/client/assets/{dist-D75ywTCb.js → dist-CMRuQ4se.js} +1 -1
- package/dist/client/assets/{dist-BIbiS-sH.js → dist-COGr0kGo.js} +1 -1
- package/dist/client/assets/{dist-BsfoRXPT.js → dist-C_eAtLLb.js} +1 -1
- package/dist/client/assets/{dist-DPk76fqB.js → dist-ClX_xXLe.js} +1 -1
- package/dist/client/assets/{dist-DUJafXOC.js → dist-D9571BVm.js} +1 -1
- package/dist/client/assets/{dist-B8LZmhch.js → dist-DncjdwQz.js} +1 -1
- package/dist/client/assets/{dist-D9kUpM9y.js → dist-ce3zYUZG.js} +1 -1
- package/dist/client/assets/index-CF45rxGL.js +99 -0
- package/dist/client/assets/index-DGPYJzbU.css +1 -0
- package/dist/client/index.html +2 -2
- package/dist/server/application/conversation-service.js +4 -4
- package/dist/server/application/provider-service.d.ts +11 -1
- package/dist/server/application/provider-service.js +27 -6
- package/dist/server/application/run-service.js +2 -61
- package/dist/server/application/workspace-service.js +1 -1
- package/dist/server/http-server.js +46 -28
- package/dist/server/providers.d.ts +10 -1
- package/dist/server/providers.js +95 -0
- package/dist/server/store.js +18 -18
- package/dist/server/terminal.js +3 -1
- package/dist/server/tool-registry.js +16 -16
- package/dist/server/turn-failure.d.ts +22 -0
- package/dist/server/turn-failure.js +82 -0
- package/dist/server/types.d.ts +8 -0
- package/package.json +5 -2
- package/dist/client/assets/index-D6_D2f3F.js +0 -99
- package/dist/client/assets/index-Duvz_o9d.css +0 -1
|
@@ -38,27 +38,27 @@ export class ToolRegistry {
|
|
|
38
38
|
await this.load();
|
|
39
39
|
const slug = input.slug.trim().toLowerCase();
|
|
40
40
|
if (!SLUG.test(slug))
|
|
41
|
-
throw new Error("slug
|
|
41
|
+
throw new Error("工具名(slug)只能包含小写字母、数字和连字符");
|
|
42
42
|
if (!input.name.trim() || input.name.length > 120)
|
|
43
|
-
throw new Error("
|
|
43
|
+
throw new Error("工具名称不合法(1-120 个字符)");
|
|
44
44
|
if (this.items.some((x) => x.slug === slug))
|
|
45
|
-
throw new Error("
|
|
45
|
+
throw new Error("已经有同名(slug)的工具了,换一个名字再导入");
|
|
46
46
|
if (this.items.length >= MAX_TOOLS)
|
|
47
|
-
throw new Error("
|
|
47
|
+
throw new Error("工具数量已经达到上限");
|
|
48
48
|
if (!Array.isArray(input.files) || !input.files.length || input.files.length > MAX_ASSETS)
|
|
49
|
-
throw new Error("
|
|
49
|
+
throw new Error("一个工具需要包含 1-32 个文件");
|
|
50
50
|
const entrypoint = safeRelative(input.entrypoint ?? "index.html");
|
|
51
51
|
if (!entrypoint.endsWith(".html"))
|
|
52
|
-
throw new Error("
|
|
52
|
+
throw new Error("入口文件必须是 .html");
|
|
53
53
|
const files = normalizeAssets(input.files);
|
|
54
54
|
if (!files.some((file) => file.path === entrypoint))
|
|
55
|
-
throw new Error("
|
|
55
|
+
throw new Error("入口文件必须出现在文件列表里");
|
|
56
56
|
const script = input.script ? normalizeScript(input.script, files) : undefined;
|
|
57
57
|
const environment = input.environment ? normalizeEnvironment(input.environment) : undefined;
|
|
58
58
|
const permissions = normalizePermissions(input.permissions);
|
|
59
59
|
const finalDir = join(this.toolsDir, slug), stagingDir = `${finalDir}.${crypto.randomUUID()}.staging`;
|
|
60
60
|
if (await stat(finalDir).catch(() => undefined))
|
|
61
|
-
throw new Error("
|
|
61
|
+
throw new Error("工具目录已经存在");
|
|
62
62
|
try {
|
|
63
63
|
await writeAssets(stagingDir, files);
|
|
64
64
|
await rename(stagingDir, finalDir);
|
|
@@ -84,7 +84,7 @@ export class ToolRegistry {
|
|
|
84
84
|
async resolve(id, resource = "") { await this.load(); const tool = this.items.find((x) => x.id === id && x.enabled); if (!tool)
|
|
85
85
|
return undefined; const root = join(this.toolsDir, tool.slug), file = resolve(root, resource ? safeRelative(resource) : tool.entrypoint); if (!inside(root, file))
|
|
86
86
|
throw new Error("tool resource must stay inside the tool directory"); const info = await stat(file).catch(() => undefined); if (!info?.isFile())
|
|
87
|
-
throw new Error("
|
|
87
|
+
throw new Error("工具文件不存在"); return { tool: copy(tool), file, root }; }
|
|
88
88
|
/**
|
|
89
89
|
* THE EXPORT, AND THE ONLY PRODUCER OF A SHAREABLE BUNDLE.
|
|
90
90
|
*
|
|
@@ -126,12 +126,12 @@ export class ToolRegistry {
|
|
|
126
126
|
}
|
|
127
127
|
}
|
|
128
128
|
function normalizeAssets(files) { const paths = new Set(); let bytes = 0; return files.map((item) => { if (!item || typeof item.content !== "string")
|
|
129
|
-
throw new Error("
|
|
130
|
-
throw new Error(
|
|
131
|
-
throw new Error("
|
|
129
|
+
throw new Error("工具文件的内容必须是文本"); const path = safeRelative(item.path); if (paths.has(path))
|
|
130
|
+
throw new Error(`工具里有重复的文件:${path}`); paths.add(path); bytes += Buffer.byteLength(item.content); if (bytes > MAX_ASSET_BYTES)
|
|
131
|
+
throw new Error("工具文件总大小超过 512KB"); return { path, content: item.content }; }); }
|
|
132
132
|
function normalizeScript(script, files) { const path = safeRelative(script.path); if (!path.endsWith(".py") || !files.some((x) => x.path === path))
|
|
133
|
-
throw new Error("
|
|
134
|
-
throw new Error("
|
|
133
|
+
throw new Error("脚本必须指向文件列表里的一个 .py 文件"); if (script.parameters && Object.values(script.parameters).some((x) => !isParam(x)))
|
|
134
|
+
throw new Error("脚本的参数定义不合法"); return { path, timeoutMs: script.timeoutMs, parameters: script.parameters }; }
|
|
135
135
|
/**
|
|
136
136
|
* THE PIN IS CHECKED HERE, ON THE WAY IN, AND A RANGE IS A REFUSAL RATHER THAN A WARNING.
|
|
137
137
|
* A warning would throw away exactly what the environment buys: by the time the user learned that
|
|
@@ -199,12 +199,12 @@ async function collectAssets(root, dir, files, skipped) {
|
|
|
199
199
|
async function writeAssets(root, files) { for (const asset of files) {
|
|
200
200
|
const target = resolve(root, asset.path);
|
|
201
201
|
if (!inside(root, target))
|
|
202
|
-
throw new Error("
|
|
202
|
+
throw new Error("工具文件不能写到工具目录之外");
|
|
203
203
|
await mkdir(dirname(target), { recursive: true });
|
|
204
204
|
await writeFile(target, asset.content, "utf8");
|
|
205
205
|
} }
|
|
206
206
|
function safeRelative(value) { const p = value.replace(/\\/g, "/").trim(); if (!p || p.startsWith("/") || p.includes("\0") || p.split("/").includes(".."))
|
|
207
|
-
throw new Error("
|
|
207
|
+
throw new Error("路径必须是相对路径,且不能跳出工具目录"); return p; }
|
|
208
208
|
function inside(root, target) { const r = relative(resolve(root), resolve(target)); return r === "" || (!r.startsWith(`..${sep}`) && r !== ".." && !r.includes(":")); }
|
|
209
209
|
function isParam(value) { const x = value; return !!x && typeof x === "object" && ["string", "number", "boolean", "object", "array"].includes(x.type ?? "") && (x.required === undefined || typeof x.required === "boolean") && (x.enum === undefined || Array.isArray(x.enum)); }
|
|
210
210
|
function isTool(value) { const x = value; if (!x || typeof x !== "object" || typeof x.id !== "string" || typeof x.slug !== "string" || typeof x.name !== "string" || typeof x.entrypoint !== "string" || (x.source !== "user" && x.source !== "builtin"))
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Translates a thrown error from the turn loop into a sentence a person reads.
|
|
3
|
+
*
|
|
4
|
+
* The turn loop throws for very different reasons: a model-provider rate limit, a 5xx that Pi's RPC
|
|
5
|
+
* layer chose to surface as a child exit, an OOM that took the whole process down, a path that
|
|
6
|
+
* resolved to a directory the workspace contract forbids, an `imageInput: false` mismatch. The
|
|
7
|
+
* throw message carries the technical fact; what the reader needs is the action it implies - retry,
|
|
8
|
+
* change model, check the key, change workspace - and that is the level this function writes at.
|
|
9
|
+
*
|
|
10
|
+
* The reason the shape is match-on-substring rather than match-on-error-class is that the upstream
|
|
11
|
+
* error is whatever Pi wrote to its own log: a string, not an exception class, and the host has
|
|
12
|
+
* nothing to pattern-match against other than the message itself. The literals below are
|
|
13
|
+
* deliberately permissive on the LLM side ("quota", "rate limit", "usage limit", "too many requests",
|
|
14
|
+
* "5-hour", "5h") because the underlying model APIs name this limit in several ways, and the
|
|
15
|
+
* reader cares about the bucket, not the exact wording.
|
|
16
|
+
*
|
|
17
|
+
* THIS LIVES IN ITS OWN MODULE so the buckets can be tested without starting a run: the function is
|
|
18
|
+
* pure, and every branch below is a decision about what a person is told, which is worth a test that
|
|
19
|
+
* needs no server, socket or Pi process.
|
|
20
|
+
*/
|
|
21
|
+
export declare function formatTurnFailure(error: unknown): string;
|
|
22
|
+
export declare function controllerAborted(error: unknown): boolean;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Translates a thrown error from the turn loop into a sentence a person reads.
|
|
3
|
+
*
|
|
4
|
+
* The turn loop throws for very different reasons: a model-provider rate limit, a 5xx that Pi's RPC
|
|
5
|
+
* layer chose to surface as a child exit, an OOM that took the whole process down, a path that
|
|
6
|
+
* resolved to a directory the workspace contract forbids, an `imageInput: false` mismatch. The
|
|
7
|
+
* throw message carries the technical fact; what the reader needs is the action it implies - retry,
|
|
8
|
+
* change model, check the key, change workspace - and that is the level this function writes at.
|
|
9
|
+
*
|
|
10
|
+
* The reason the shape is match-on-substring rather than match-on-error-class is that the upstream
|
|
11
|
+
* error is whatever Pi wrote to its own log: a string, not an exception class, and the host has
|
|
12
|
+
* nothing to pattern-match against other than the message itself. The literals below are
|
|
13
|
+
* deliberately permissive on the LLM side ("quota", "rate limit", "usage limit", "too many requests",
|
|
14
|
+
* "5-hour", "5h") because the underlying model APIs name this limit in several ways, and the
|
|
15
|
+
* reader cares about the bucket, not the exact wording.
|
|
16
|
+
*
|
|
17
|
+
* THIS LIVES IN ITS OWN MODULE so the buckets can be tested without starting a run: the function is
|
|
18
|
+
* pure, and every branch below is a decision about what a person is told, which is worth a test that
|
|
19
|
+
* needs no server, socket or Pi process.
|
|
20
|
+
*/
|
|
21
|
+
export function formatTurnFailure(error) {
|
|
22
|
+
if (controllerAborted(error))
|
|
23
|
+
return "本轮任务已停止。";
|
|
24
|
+
const raw = error instanceof Error ? error.message : typeof error === "string" ? error : "";
|
|
25
|
+
const lower = raw.toLowerCase();
|
|
26
|
+
// PROVIDER QUOTA / RATE LIMIT - the only reason the user is in this branch is because Pi was
|
|
27
|
+
// answering them a moment ago and now the model will not let it. The action is "wait or change
|
|
28
|
+
// model"; the wording has to make that obvious from the banner alone, without a tooltip.
|
|
29
|
+
if (/\b429\b|quota|rate limit|usage limit|too many requests|5-hour|5h|resource_exhausted|resourc exhaust|hit your limit|usage cap|usage restrict/.test(lower)) {
|
|
30
|
+
return "模型额度已用完(5 小时限额或类似上限),Pi 已停止回答。可以等待重置后重试,或在会话里换一个模型再发。";
|
|
31
|
+
}
|
|
32
|
+
// RPC CHANNEL DEAD - Pi died without producing a `settled` event. Anything in the turn is now
|
|
33
|
+
// unanswerable, but the deltas the user already saw are still on screen, so the message has to
|
|
34
|
+
// say "we noticed and stopped" rather than "your input was lost".
|
|
35
|
+
if (lower.includes("pi rpc channel closed") || lower.includes("agent rpc") || lower.includes("exited before settling")) {
|
|
36
|
+
return "Pi 进程异常退出,未完成本轮回答。已停止运行,可以直接重发任务继续。";
|
|
37
|
+
}
|
|
38
|
+
// NO PI - the launch path failed (binary missing, executable bit, Windows shim). The reader's
|
|
39
|
+
// best move is a `which pi` / reinstall, and the banner should point there.
|
|
40
|
+
if (lower.includes("could not find") && lower.includes("pi") || lower.includes("pi command") || lower.startsWith("pi ")) {
|
|
41
|
+
return `无法启动 Pi:${raw || "未知原因"}。请确认 Pi 已正确安装并可在命令行运行。`;
|
|
42
|
+
}
|
|
43
|
+
// WORKSPACE PATH - turn refused on directory the contract forbids. Refusal happens before
|
|
44
|
+
// anything is on screen, so the banner is also the only place the reason lives.
|
|
45
|
+
if (lower.includes("workspace directory") || lower.includes("does not exist or is not a directory")) {
|
|
46
|
+
return `工作区目录无效:${raw}`;
|
|
47
|
+
}
|
|
48
|
+
// PROVIDER UNREACHABLE - the request never reached the model. This is the branch a custom
|
|
49
|
+
// provider with a wrong Base URL lands in, and the person editing that URL needs to be told that
|
|
50
|
+
// the address or the network is the problem, not that "Pi failed".
|
|
51
|
+
if (/failed to fetch|fetch failed|econnrefused|econnreset|enotfound|eai_again|socket hang up|connection refused|connection reset|network\s*error/.test(lower)) {
|
|
52
|
+
return "连不上模型供应商:网络不可达或接口地址不对。请检查供应商的 Base URL 与网络连接,然后重发。";
|
|
53
|
+
}
|
|
54
|
+
// PROVIDER AUTH - the key is wrong, missing, or lacks access to this model. Pi reports this as a
|
|
55
|
+
// 401/403 from the provider; the actionable place is the supplier's key, not the conversation.
|
|
56
|
+
if (/\b401\b|\b403\b|unauthorized|forbidden|invalid api key|incorrect api key|authentication failed|insufficient permission/.test(lower)) {
|
|
57
|
+
return "模型供应商拒绝了这次请求:鉴权失败。请在设置里检查这个供应商的 API key,然后重发。";
|
|
58
|
+
}
|
|
59
|
+
// PROVIDER 5XX - their side is down. Retrying is the action, and saying so stops the reader from
|
|
60
|
+
// hunting for a configuration mistake on their own machine.
|
|
61
|
+
const status = /\bhttp\s*(?:status\s*)?[:=]?\s*(\d{3})\b|\bstatus(?:\s*code)?\s*[:=]\s*(\d{3})\b/.exec(lower);
|
|
62
|
+
const code = Number(status?.[1] ?? status?.[2] ?? 0);
|
|
63
|
+
if (code >= 500 && code <= 599 || /internal server error|bad gateway|service unavailable|gateway timeout/.test(lower)) {
|
|
64
|
+
return `模型供应商服务端出错了${code ? `(HTTP ${code})` : ""},通常稍后重试即可。`;
|
|
65
|
+
}
|
|
66
|
+
// IMAGE MISMATCH - explicit by the caller, no need to translate.
|
|
67
|
+
if (lower.includes("不支持图片输入")) {
|
|
68
|
+
return raw;
|
|
69
|
+
}
|
|
70
|
+
// GENERIC - the literal message is more useful than a paraphrase, but it has to be the LAST
|
|
71
|
+
// branch and the message has to be non-empty (a thrown `new Error()` is empty and renders
|
|
72
|
+
// nothing, which is exactly the silence this whole change exists to break).
|
|
73
|
+
return raw || "Pi 未能完成本轮回答,已标记为失败。可以重发任务继续。";
|
|
74
|
+
}
|
|
75
|
+
export function controllerAborted(error) {
|
|
76
|
+
if (!error)
|
|
77
|
+
return false;
|
|
78
|
+
if (error instanceof Error && error.name === "AbortError")
|
|
79
|
+
return true;
|
|
80
|
+
const msg = error instanceof Error ? error.message : typeof error === "string" ? error : "";
|
|
81
|
+
return /abort|cancel|aborted/i.test(msg);
|
|
82
|
+
}
|
package/dist/server/types.d.ts
CHANGED
|
@@ -407,6 +407,14 @@ export type PublicProvider = {
|
|
|
407
407
|
hasKey: boolean;
|
|
408
408
|
models: PublicProviderModel[];
|
|
409
409
|
};
|
|
410
|
+
export type DiscoveredModel = {
|
|
411
|
+
id: string;
|
|
412
|
+
name: string;
|
|
413
|
+
reasoning: boolean;
|
|
414
|
+
imageInput: boolean;
|
|
415
|
+
contextWindow: number;
|
|
416
|
+
maxTokens: number;
|
|
417
|
+
};
|
|
410
418
|
export type ModelCatalog = {
|
|
411
419
|
source: "pi" | "unavailable";
|
|
412
420
|
models: ModelOption[];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@evandu/super-pi",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.118",
|
|
4
4
|
"description": "Web control plane and companion for Pi",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -98,6 +98,7 @@
|
|
|
98
98
|
"scripts/bg-task-zombie.test.mjs",
|
|
99
99
|
"scripts/scoped-sidebar-tabs.test.mjs",
|
|
100
100
|
"scripts/send-retry.test.mjs",
|
|
101
|
+
"scripts/error-messages.test.mjs",
|
|
101
102
|
"scripts/git-diff-view.test.mjs",
|
|
102
103
|
"scripts/fork-server.test.mjs",
|
|
103
104
|
"scripts/styles-no-dangling.test.mjs",
|
|
@@ -120,6 +121,7 @@
|
|
|
120
121
|
"scripts/check-runner.test.mjs",
|
|
121
122
|
"scripts/skills-discovery.test.mjs",
|
|
122
123
|
"scripts/session-state-icon.test.mjs",
|
|
124
|
+
"scripts/provider-fetch-models.test.mjs",
|
|
123
125
|
"scripts/shared-chrome.test.mjs"
|
|
124
126
|
],
|
|
125
127
|
"check:browser": [
|
|
@@ -166,7 +168,8 @@
|
|
|
166
168
|
"scripts/workspace-picker-browser.test.mjs",
|
|
167
169
|
"scripts/optimistic-browser.test.mjs",
|
|
168
170
|
"scripts/active-memory-browser.test.mjs",
|
|
169
|
-
"scripts/knowledge-base-browser.test.mjs"
|
|
171
|
+
"scripts/knowledge-base-browser.test.mjs",
|
|
172
|
+
"scripts/ux-polish-browser.test.mjs"
|
|
170
173
|
],
|
|
171
174
|
"dependencies": {
|
|
172
175
|
"@codemirror/commands": "^6.11.1",
|