@evandu/super-pi 0.1.259 → 0.1.261

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.
Files changed (35) hide show
  1. package/README.md +3 -1
  2. package/bin/super-pi.js +1 -1
  3. package/desktop/brand.svg +6 -0
  4. package/desktop/icon.png +0 -0
  5. package/desktop/launch.cjs +7 -7
  6. package/desktop/login-item.cjs +7 -0
  7. package/desktop/main.cjs +27 -7
  8. package/desktop/preload.cjs +19 -0
  9. package/desktop/runtime.cjs +107 -0
  10. package/desktop/tray-icon.png +0 -0
  11. package/desktop/tray-icon@2x.png +0 -0
  12. package/desktop/tray.svg +1 -0
  13. package/dist/client/.super-pi-client-sources.json +7 -6
  14. package/dist/client/assets/{CodeMirrorEditor-mi9rGUce.js → CodeMirrorEditor-DGK07ECt.js} +1 -1
  15. package/dist/client/assets/{GitDiffEditor-FQBfGxOY.js → GitDiffEditor-DCQ2HgfJ.js} +1 -1
  16. package/dist/client/assets/index-BVn_-dwp.js +350 -0
  17. package/dist/client/assets/{index-UfzqdECL.css → index-DhW875H-.css} +1 -1
  18. package/dist/client/favicon.ico +0 -0
  19. package/dist/client/favicon.png +0 -0
  20. package/dist/client/favicon.svg +5 -9
  21. package/dist/client/index.html +2 -2
  22. package/dist/server/existing-service.d.ts +12 -0
  23. package/dist/server/existing-service.js +18 -0
  24. package/dist/server/managed-http-tunnel.d.ts +2 -2
  25. package/dist/server/managed-http-tunnel.js +7 -5
  26. package/dist/server/managed-http.js +6 -2
  27. package/dist/server/managed-servers.d.ts +46 -3
  28. package/dist/server/managed-servers.js +199 -20
  29. package/dist/server/managed-ssh.d.ts +14 -1
  30. package/dist/server/managed-ssh.js +55 -5
  31. package/dist/server/runtime.js +2 -2
  32. package/dist/shared/managed-servers.d.ts +23 -2
  33. package/package.json +8 -1
  34. package/scripts/pack-server.mjs +1 -1
  35. package/dist/client/assets/index-Cn7hdrDw.js +0 -350
@@ -10,14 +10,15 @@ export class HostTrustRequired extends Error {
10
10
  }
11
11
  }
12
12
  export const sh = (value) => `'${value.replaceAll("'", "'\\''")}'`;
13
- export async function connectSsh(profile) {
13
+ export async function connectSsh(profile, options = {}) {
14
+ options.signal?.throwIfAborted();
14
15
  const { Client } = await import("ssh2");
15
16
  const client = new Client();
16
17
  let observed = "";
17
18
  let trusted = false;
18
19
  const settings = {
19
20
  host: profile.host, port: profile.port, username: profile.username,
20
- readyTimeout: 20_000, keepaliveInterval: 15_000, keepaliveCountMax: 3,
21
+ readyTimeout: 0, tryKeyboard: true, keepaliveInterval: 15_000, keepaliveCountMax: 3,
21
22
  hostVerifier: (key) => {
22
23
  observed = `SHA256:${createHash("sha256").update(key).digest("base64").replace(/=+$/, "")}`;
23
24
  trusted = profile.fingerprint === observed;
@@ -33,10 +34,59 @@ export async function connectSsh(profile) {
33
34
  else
34
35
  settings.agent = process.env.SSH_AUTH_SOCK || (process.platform === "win32" ? "\\\\.\\pipe\\openssh-ssh-agent" : undefined);
35
36
  return new Promise((resolve, reject) => {
36
- client.once("ready", () => { client.removeListener("error", failed); client.on("error", () => { }); resolve(client); });
37
- const failed = (error) => { client.end(); reject(observed && !trusted ? new HostTrustRequired(observed, Boolean(profile.fingerprint)) : new Error(error.level === "client-authentication" ? "SSH 认证失败,请检查用户名和认证信息" : "SSH 连接失败,请检查地址、端口、网络和认证信息")); };
37
+ let settled = false, round = 0, interactive = false;
38
+ let timer;
39
+ const cleanup = () => { clearTimeout(timer); options.signal?.removeEventListener("abort", cancelled); };
40
+ const stop = (reason) => { if (settled)
41
+ return; settled = true; cleanup(); client.destroy(); reject(reason); };
42
+ const arm = (waiting) => {
43
+ clearTimeout(timer);
44
+ timer = setTimeout(() => stop(new Error(waiting ? "SSH 交互验证超时,请重新连接" : "SSH 连接超时,请检查网络后重试")), waiting ? options.verificationTimeoutMs ?? 180_000 : options.handshakeTimeoutMs ?? 20_000);
45
+ };
46
+ const cancelled = () => stop(options.signal?.reason instanceof Error ? options.signal.reason : new Error("SSH 连接已取消"));
47
+ const failed = (error) => stop(observed && !trusted ? new HostTrustRequired(observed, Boolean(profile.fingerprint)) : new Error(error.level === "client-authentication" ? interactive ? "SSH 交互验证未通过,请重新连接后重试" : "SSH 认证失败,请检查用户名和认证信息" : "SSH 连接失败,请检查地址、端口、网络和认证信息"));
48
+ client.once("ready", () => { if (settled)
49
+ return; settled = true; cleanup(); client.removeListener("error", failed); client.on("error", () => { }); resolve(client); });
38
50
  client.once("error", failed);
39
- client.connect(settings);
51
+ client.once("close", () => { if (!settled)
52
+ stop(new Error("SSH 连接在验证完成前关闭,请重新连接")); });
53
+ client.on("keyboard-interactive", (name, instruction, _language, prompts, finish) => {
54
+ if (settled)
55
+ return;
56
+ interactive = true;
57
+ if (!options.onVerification) {
58
+ if (!prompts.length) {
59
+ finish([]);
60
+ return;
61
+ }
62
+ stop(new Error("SSH 服务器要求交互验证,请通过服务器连接设置完成验证"));
63
+ return;
64
+ }
65
+ const currentRound = ++round;
66
+ arm(true);
67
+ void Promise.resolve().then(() => options.onVerification({ name, instruction, prompts: prompts.map(item => ({ prompt: item.prompt, echo: item.echo === true })) })).then(answers => {
68
+ if (settled || currentRound !== round)
69
+ return;
70
+ if (answers.length !== prompts.length || answers.some(answer => typeof answer !== "string")) {
71
+ stop(new Error("SSH 交互验证响应格式无效"));
72
+ return;
73
+ }
74
+ arm(true);
75
+ finish(answers);
76
+ }, reason => stop(reason instanceof Error ? reason : new Error("SSH 交互验证已取消")));
77
+ });
78
+ options.signal?.addEventListener("abort", cancelled, { once: true });
79
+ if (options.signal?.aborted) {
80
+ cancelled();
81
+ return;
82
+ }
83
+ arm(false);
84
+ try {
85
+ client.connect(settings);
86
+ }
87
+ catch (error) {
88
+ stop(error instanceof Error ? error : new Error("无法启动 SSH 连接"));
89
+ }
40
90
  });
41
91
  }
42
92
  export function sshExec(client, command, options = {}) {
@@ -2582,13 +2582,13 @@ export class PiRpcRuntime {
2582
2582
  if (!transcript)
2583
2583
  throw new Error("这个会话还没有内容,无法据此生成标题");
2584
2584
  if (selectedModel?.provider && selectedModel.modelId) {
2585
- const modelResponse = await channel.request({ id: "autotitle_model", type: "set_model", provider: selectedModel.provider, modelId: selectedModel.modelId }, Math.min(TIMEOUT_MS, 8_000));
2585
+ const modelResponse = await channel.request({ id: "autotitle_model", type: "set_model", provider: selectedModel.provider, modelId: selectedModel.modelId }, Math.max(1, Math.min(30_000, deadline - Date.now())));
2586
2586
  if (modelResponse.success !== true)
2587
2587
  throw new Error(modelResponse.error || `Pi 无法使用当前会话模型 ${selectedModel.provider}/${selectedModel.modelId}`);
2588
2588
  }
2589
2589
  // Reasoning adds latency without improving a short session label. Keep this one-shot call fast
2590
2590
  // even when the user's normal default thinking level is high.
2591
- const thinkingResponse = await channel.request({ id: "autotitle_thinking", type: "set_thinking_level", level: "off" }, Math.min(TIMEOUT_MS, 8_000));
2591
+ const thinkingResponse = await channel.request({ id: "autotitle_thinking", type: "set_thinking_level", level: "off" }, Math.max(1, Math.min(30_000, deadline - Date.now())));
2592
2592
  if (thinkingResponse.success !== true)
2593
2593
  throw new Error(thinkingResponse.error || "Pi 未能关闭标题生成的思考等级");
2594
2594
  channel.write({
@@ -1,3 +1,13 @@
1
+ export interface SshVerification {
2
+ id: string;
3
+ name: string;
4
+ instruction: string;
5
+ expiresAt: string;
6
+ prompts: {
7
+ prompt: string;
8
+ echo: boolean;
9
+ }[];
10
+ }
1
11
  export interface ManagedServerProfile {
2
12
  id: string;
3
13
  name: string;
@@ -13,10 +23,20 @@ export interface ManagedServerProfile {
13
23
  identity?: string;
14
24
  deployedAt?: string;
15
25
  remoteRoot?: string;
16
- ssh: "offline" | "connecting" | "online" | "needsTrust";
26
+ ssh: "offline" | "connecting" | "online" | "needsTrust" | "awaitingVerification";
17
27
  service: "unknown" | "offline" | "online";
18
28
  modelChannel: "offline" | "online";
19
- phase: "idle" | "connecting" | "needsTrust" | "deploying" | "ready" | "failed";
29
+ phase: "idle" | "connecting" | "needsTrust" | "awaitingVerification" | "deploying" | "ready" | "failed";
30
+ verification?: SshVerification;
31
+ existingService?: {
32
+ running: boolean;
33
+ attached: boolean;
34
+ version?: string;
35
+ dataDirectory?: string;
36
+ hasData?: boolean;
37
+ canStart?: boolean;
38
+ requiresToken?: boolean;
39
+ };
20
40
  step?: string;
21
41
  error?: string;
22
42
  log?: string[];
@@ -33,4 +53,5 @@ export interface ManagedServerInput {
33
53
  password?: string;
34
54
  privateKey?: string;
35
55
  passphrase?: string;
56
+ serviceAccessToken?: string;
36
57
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@evandu/super-pi",
3
- "version": "0.1.259",
3
+ "version": "0.1.261",
4
4
  "description": "Web control plane and companion for Pi",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -48,6 +48,10 @@
48
48
  "pack:server": "npm run build && node scripts/pack-server.mjs"
49
49
  },
50
50
  "check:logic": [
51
+ "scripts/existing-service.test.mjs",
52
+ "scripts/ssh-keyboard-interactive.test.mjs",
53
+ "scripts/title-cold-start.test.mjs",
54
+ "scripts/desktop-runtime.test.mjs",
51
55
  "scripts/managed-ssh.test.mjs",
52
56
  "scripts/managed-model.test.mjs",
53
57
  "scripts/multi-server.test.mjs",
@@ -302,6 +306,7 @@
302
306
  "scripts/session-reminder-pmo-rights.test.mjs"
303
307
  ],
304
308
  "check:browser": [
309
+ "scripts/ssh-keyboard-browser.test.mjs",
305
310
  "scripts/desktop-browser.test.mjs",
306
311
  "scripts/managed-remote-install.test.mjs",
307
312
  "scripts/multi-server-browser.test.mjs",
@@ -444,6 +449,8 @@
444
449
  "@codemirror/view": "^6.43.15",
445
450
  "@earendil-works/pi-ai": "1.5.2",
446
451
  "@earendil-works/pi-coding-agent": "1.5.2",
452
+ "@electron-internal/extract-zip": "1.0.8",
453
+ "@electron/get": "5.1.0",
447
454
  "@git-diff-view/react": "^0.1.8",
448
455
  "@types/diff": "^5.2.3",
449
456
  "@xterm/addon-fit": "^0.11.0",
@@ -24,7 +24,7 @@ export async function packServer(root, destination) {
24
24
  const manifest = JSON.parse(await readFile(join(root, "package.json"), "utf8"));
25
25
  const files = (manifest.files ?? []).filter(file => file !== "desktop" && file !== "scripts/pack-server.mjs");
26
26
  for (const file of files) { try { await cp(join(root, file), join(staging, file), { recursive: true }); } catch (error) { if (error.code !== "ENOENT") throw error; } }
27
- const dependencies = Object.fromEntries(Object.entries(manifest.dependencies ?? {}).filter(([name]) => !["electron", "ssh2"].includes(name)));
27
+ const dependencies = Object.fromEntries(Object.entries(manifest.dependencies ?? {}).filter(([name]) => !["electron", "ssh2", "@electron/get", "@electron-internal/extract-zip"].includes(name)));
28
28
  const server = { ...manifest, name: "@evandu/super-pi-server", description: "Super Pi remote execution service, without the desktop runtime", files, dependencies, devDependencies: undefined, scripts: undefined, bin: { "super-pi": "bin/super-pi.js", super_pi: "bin/super-pi.js", "super-pi-server": "bin/super-pi.js" } };
29
29
  await writeFile(join(staging, "package.json"), `${JSON.stringify(server, null, 2)}\n`);
30
30
  await mkdir(destination, { recursive: true });