@evandu/super-pi 0.1.197 → 0.1.199
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/bin/npm-prefix.d.ts +1 -0
- package/bin/npm-prefix.js +10 -0
- package/bin/super-pi.js +2 -1
- package/dist/client/.super-pi-client-sources.json +1 -1
- package/dist/server/application/provider-service.js +4 -1
- package/dist/server/pi-session.js +2 -0
- package/dist/server/provider-proxy.d.ts +8 -0
- package/dist/server/provider-proxy.js +88 -0
- package/dist/server/providers.d.ts +1 -0
- package/dist/server/providers.js +12 -3
- package/dist/server/runtime.js +5 -1
- package/dist/server/update.d.ts +1 -1
- package/dist/server/update.js +4 -7
- package/package.json +2 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export function npmInstallPrefix(rootDir: string, platform?: string): string | undefined;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** Infer npm's global prefix from this package's installation root, not its node_modules parent. */
|
|
2
|
+
export function npmInstallPrefix(rootDir, platform = process.platform) {
|
|
3
|
+
const match = rootDir.match(/^(.*)[\\/]node_modules[\\/]@evandu[\\/]super-pi[\\/]?$/i);
|
|
4
|
+
if (!match) return undefined;
|
|
5
|
+
const parent = match[1];
|
|
6
|
+
// Unix global packages live in <prefix>/lib/node_modules; Windows omits lib.
|
|
7
|
+
// Passing the Unix lib directory as --prefix would install into lib/lib/node_modules.
|
|
8
|
+
if (platform !== "win32" && /[\\/]lib$/.test(parent)) return parent.slice(0, -4) || "/";
|
|
9
|
+
return parent;
|
|
10
|
+
}
|
package/bin/super-pi.js
CHANGED
|
@@ -6,12 +6,13 @@ import { homedir } from "node:os";
|
|
|
6
6
|
import { dirname, join, resolve } from "node:path";
|
|
7
7
|
import { promisify } from "node:util";
|
|
8
8
|
import { pathToFileURL } from "node:url";
|
|
9
|
+
import { npmInstallPrefix } from "./npm-prefix.js";
|
|
9
10
|
|
|
10
11
|
const execFileAsync = promisify(execFile);
|
|
11
12
|
const root = resolve(import.meta.dirname, "..");
|
|
12
13
|
const entry = resolve(root, "dist/server/index.js");
|
|
13
|
-
const prefix = root.match(/^(.*)[\\/]node_modules[\\/]/i)?.[1];
|
|
14
14
|
const platform = process.env.SUPER_PI_AUTOSTART_PLATFORM ?? process.platform;
|
|
15
|
+
const prefix = npmInstallPrefix(root, platform);
|
|
15
16
|
const home = process.env.SUPER_PI_AUTOSTART_HOME ?? homedir();
|
|
16
17
|
|
|
17
18
|
/**
|
|
@@ -40,5 +40,5 @@
|
|
|
40
40
|
"src/client/types.ts": "0d32fd568f188507ce2b48266f44fa20da1bcf436090893b1ff0c164ed0f3132",
|
|
41
41
|
"src/client/vite-env.d.ts": "65996936fbb042915f7b74a200fcdde7e410f32a669b1ab9597cfaa4b0faddb5"
|
|
42
42
|
},
|
|
43
|
-
"recordedAt": "2026-11-
|
|
43
|
+
"recordedAt": "2026-11-12T15:12:54.897Z"
|
|
44
44
|
}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { KNOWN_APIS, publicProviders, validateProvider, fetchRemoteModels } from "../providers.js";
|
|
2
|
+
import { readProviderProxyEnv } from "../provider-proxy.js";
|
|
3
|
+
import { piAgentDir } from "../providers.js";
|
|
2
4
|
/**
|
|
3
5
|
* THE PROVIDERS A PERSON ADDED, as a service.
|
|
4
6
|
*
|
|
@@ -352,6 +354,7 @@ export class ProviderService {
|
|
|
352
354
|
if (match?.apiKey)
|
|
353
355
|
key = match.apiKey;
|
|
354
356
|
}
|
|
355
|
-
|
|
357
|
+
const proxyEnv = input.providerId ? await readProviderProxyEnv(piAgentDir(), input.providerId) : undefined;
|
|
358
|
+
return fetchRemoteModels({ baseUrl: input.baseUrl, apiKey: key, api: input.api, proxyEnv });
|
|
356
359
|
}
|
|
357
360
|
}
|
|
@@ -28,6 +28,7 @@ import { open, readdir } from "node:fs/promises";
|
|
|
28
28
|
import { StringDecoder } from "node:string_decoder";
|
|
29
29
|
import { dirname, join, resolve } from "node:path";
|
|
30
30
|
import { createModelResolver } from "./model-context-window.js";
|
|
31
|
+
import { installProviderProxy } from "./provider-proxy.js";
|
|
31
32
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
32
33
|
const traceSession = (conversationId, phase, startedAt, extra = "") => {
|
|
33
34
|
if (process.env.SUPER_PI_TRACE_LATENCY !== "1")
|
|
@@ -291,6 +292,7 @@ export async function createPiSession(creation) {
|
|
|
291
292
|
: await resolveSessionManager(sdk, creation);
|
|
292
293
|
traceSession(creation.sessionId, "sdk.transcript.ready", startedAt, `bytes=${transcriptBytes(sessionManager)}`);
|
|
293
294
|
const modelRuntime = await sdk.ModelRuntime.create();
|
|
295
|
+
installProviderProxy(modelRuntime);
|
|
294
296
|
traceSession(creation.sessionId, "sdk.model-runtime", startedAt);
|
|
295
297
|
// THE MODEL IS RESOLVED, NOT PASSED THROUGH. Pi's SDK takes a whole Model object - the provider's
|
|
296
298
|
// configuration, the endpoint, the capability list - and Super Pi only knows the pair
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** Read only proxy keys; provider secrets must never become child process environment variables. */
|
|
2
|
+
export declare function readProviderProxyEnv(agentDir: string, providerId?: string): Promise<Record<string, string>>;
|
|
3
|
+
type Env = Record<string, string | undefined>;
|
|
4
|
+
/** Apply scoped proxy values without changing the server's process environment. */
|
|
5
|
+
export declare function providerProxyFetch(env: Env | undefined): typeof fetch | undefined;
|
|
6
|
+
/** Pi's SDK accepts a fetch per request, but its OpenAI adapters do not use env proxies themselves. */
|
|
7
|
+
export declare function installProviderProxy(runtime: unknown): void;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { EnvHttpProxyAgent } from "undici";
|
|
2
|
+
import { readFile } from "node:fs/promises";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
/** Read only proxy keys; provider secrets must never become child process environment variables. */
|
|
5
|
+
export async function readProviderProxyEnv(agentDir, providerId) {
|
|
6
|
+
const read = async (file) => {
|
|
7
|
+
try {
|
|
8
|
+
return JSON.parse(await readFile(join(agentDir, file), "utf8"));
|
|
9
|
+
}
|
|
10
|
+
catch (error) {
|
|
11
|
+
if (error.code === "ENOENT")
|
|
12
|
+
return {};
|
|
13
|
+
throw error;
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
const id = providerId ?? (await read("settings.json")).defaultProvider;
|
|
17
|
+
if (!id)
|
|
18
|
+
return {};
|
|
19
|
+
const env = (await read("auth.json"))[id]?.env ?? {};
|
|
20
|
+
const result = {};
|
|
21
|
+
for (const name of ["HTTP_PROXY", "HTTPS_PROXY", "ALL_PROXY", "NO_PROXY"]) {
|
|
22
|
+
const value = env[name.toLowerCase()] ?? env[name];
|
|
23
|
+
if (typeof value === "string") {
|
|
24
|
+
result[name] = value;
|
|
25
|
+
result[name.toLowerCase()] = value;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return result;
|
|
29
|
+
}
|
|
30
|
+
const agents = new Map();
|
|
31
|
+
/** Apply scoped proxy values without changing the server's process environment. */
|
|
32
|
+
export function providerProxyFetch(env) {
|
|
33
|
+
if (!env || !["HTTP_PROXY", "HTTPS_PROXY", "ALL_PROXY", "NO_PROXY", "http_proxy", "https_proxy", "all_proxy", "no_proxy"].some(key => env[key] !== undefined))
|
|
34
|
+
return undefined;
|
|
35
|
+
const value = (key) => env[key.toLowerCase()] ?? env[key] ?? process.env[key.toLowerCase()] ?? process.env[key];
|
|
36
|
+
const allProxy = value("ALL_PROXY");
|
|
37
|
+
const httpProxy = value("HTTP_PROXY") ?? allProxy;
|
|
38
|
+
const httpsProxy = value("HTTPS_PROXY") ?? allProxy ?? httpProxy;
|
|
39
|
+
const noProxy = value("NO_PROXY");
|
|
40
|
+
for (const address of [httpProxy, httpsProxy]) {
|
|
41
|
+
if (!address)
|
|
42
|
+
continue;
|
|
43
|
+
let protocol;
|
|
44
|
+
try {
|
|
45
|
+
protocol = new URL(address).protocol;
|
|
46
|
+
}
|
|
47
|
+
catch {
|
|
48
|
+
throw new Error("供应商代理地址必须是合法的 HTTP / HTTPS URL");
|
|
49
|
+
}
|
|
50
|
+
if (protocol !== "http:" && protocol !== "https:")
|
|
51
|
+
throw new Error("供应商代理仅支持 HTTP / HTTPS");
|
|
52
|
+
}
|
|
53
|
+
const key = JSON.stringify([httpProxy, httpsProxy, noProxy]);
|
|
54
|
+
let agent = agents.get(key);
|
|
55
|
+
if (!agent) {
|
|
56
|
+
agent = new EnvHttpProxyAgent({ httpProxy, httpsProxy, noProxy });
|
|
57
|
+
if (agents.size >= 32) {
|
|
58
|
+
const oldest = agents.keys().next().value;
|
|
59
|
+
void agents.get(oldest).close().catch(() => { });
|
|
60
|
+
agents.delete(oldest);
|
|
61
|
+
}
|
|
62
|
+
agents.set(key, agent);
|
|
63
|
+
}
|
|
64
|
+
return (input, init) => globalThis.fetch(input, { ...init, dispatcher: agent });
|
|
65
|
+
}
|
|
66
|
+
/** Pi's SDK accepts a fetch per request, but its OpenAI adapters do not use env proxies themselves. */
|
|
67
|
+
export function installProviderProxy(runtime) {
|
|
68
|
+
const target = runtime;
|
|
69
|
+
if (typeof target.getAuth !== "function")
|
|
70
|
+
return;
|
|
71
|
+
for (const method of ["stream", "streamSimple", "streamDeferred"]) {
|
|
72
|
+
const original = target[method];
|
|
73
|
+
if (typeof original !== "function")
|
|
74
|
+
continue;
|
|
75
|
+
target[method] = function (model, context, options) {
|
|
76
|
+
// These SDK adapters reject injected fetch implementations; preserve their native transport.
|
|
77
|
+
if (["bedrock-converse-stream", "google-generative-ai", "google-vertex"].includes(model?.api ?? ""))
|
|
78
|
+
return original.call(target, model, context, options);
|
|
79
|
+
if (options?.fetch)
|
|
80
|
+
return original.call(target, model, context, options);
|
|
81
|
+
const requestFetch = async (input, init) => {
|
|
82
|
+
const auth = await target.getAuth(model);
|
|
83
|
+
return (providerProxyFetch(auth?.env) ?? globalThis.fetch)(input, init);
|
|
84
|
+
};
|
|
85
|
+
return original.call(target, model, context, { ...options, fetch: requestFetch });
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
}
|
|
@@ -281,6 +281,7 @@ export declare function validateProvider(input: unknown): ProviderDefinition;
|
|
|
281
281
|
*/
|
|
282
282
|
export declare function fetchRemoteModels(input: {
|
|
283
283
|
baseUrl: string;
|
|
284
|
+
proxyEnv?: Record<string, string>;
|
|
284
285
|
apiKey?: string;
|
|
285
286
|
api?: string;
|
|
286
287
|
}): Promise<DiscoveredModel[]>;
|
package/dist/server/providers.js
CHANGED
|
@@ -3,6 +3,7 @@ import { mkdir, readFile, rename, stat, writeFile } from "node:fs/promises";
|
|
|
3
3
|
import { dirname, join } from "node:path";
|
|
4
4
|
import { readModelStore, storeWindowFor } from "./models-store.js";
|
|
5
5
|
import { SUPER_PI_DEFAULT_MAX_TOKENS, SUPER_PI_GUESSED_MAX_TOKENS as GUESSED_MAX_TOKENS } from "./model-context-window.js";
|
|
6
|
+
import { providerProxyFetch } from "./provider-proxy.js";
|
|
6
7
|
/**
|
|
7
8
|
* The API adapters Pi ships, as the ids a provider may name.
|
|
8
9
|
*
|
|
@@ -601,8 +602,16 @@ export class ProviderRegistry {
|
|
|
601
602
|
const auth = await readJsonFile(authPath) ?? {};
|
|
602
603
|
const nextById = new Map(next.map((provider) => [provider.id, provider]));
|
|
603
604
|
for (const provider of next) {
|
|
604
|
-
if (provider.apiKey)
|
|
605
|
-
|
|
605
|
+
if (provider.apiKey) {
|
|
606
|
+
// API-key credentials can carry provider-scoped env (including proxy routing).
|
|
607
|
+
// Preserve these settings when saving a key, but never mix OAuth fields into it.
|
|
608
|
+
const stored = auth[provider.id];
|
|
609
|
+
auth[provider.id] = {
|
|
610
|
+
...(stored?.type === "api_key" ? stored : {}),
|
|
611
|
+
type: "api_key",
|
|
612
|
+
key: provider.apiKey,
|
|
613
|
+
};
|
|
614
|
+
}
|
|
606
615
|
}
|
|
607
616
|
for (const provider of previous) {
|
|
608
617
|
const updated = nextById.get(provider.id);
|
|
@@ -749,7 +758,7 @@ export async function fetchRemoteModels(input) {
|
|
|
749
758
|
let payload = null;
|
|
750
759
|
for (const candidate of candidates) {
|
|
751
760
|
try {
|
|
752
|
-
const response = await fetch(candidate, {
|
|
761
|
+
const response = await (providerProxyFetch(input.proxyEnv) ?? fetch)(candidate, {
|
|
753
762
|
headers,
|
|
754
763
|
signal: AbortSignal.timeout(10000),
|
|
755
764
|
});
|
package/dist/server/runtime.js
CHANGED
|
@@ -9,6 +9,7 @@ import { WEB_FETCH_TOOL_NAME, WEB_SEARCH_TOOL_NAME } from "./web.js";
|
|
|
9
9
|
import { existsSync } from "node:fs";
|
|
10
10
|
import { ConversationUsageCollector } from "./conversation-usage.js";
|
|
11
11
|
import { defaultAgentDir } from "./pi-session.js";
|
|
12
|
+
import { readProviderProxyEnv } from "./provider-proxy.js";
|
|
12
13
|
import { withArbitratedWindows } from "./model-context-window.js";
|
|
13
14
|
import { mkdir, stat } from "node:fs/promises";
|
|
14
15
|
import { forkSessionFile, truncateSessionFile } from "./session-repository.js";
|
|
@@ -1496,6 +1497,7 @@ export class PiRpcRuntime {
|
|
|
1496
1497
|
if (!this.pi.found)
|
|
1497
1498
|
throw new Error(this.pi.reason);
|
|
1498
1499
|
// npm exposes global CLIs as .cmd shims on Windows; Node requires a shell to launch those shims.
|
|
1500
|
+
const providerProxyEnv = await readProviderProxyEnv(defaultAgentDir(), conversation.model?.provider);
|
|
1499
1501
|
const child = spawn(shellQuote(this.pi.command), ["--mode", "rpc", "--session-dir", this.sessionDir, "--session-id", conversation.id, ...extensionArgs, ...memoryArgs, ...knowledgeArgs, ...documentArgs, ...webArgs, ...feishuArgs, ...agentArgs], {
|
|
1500
1502
|
cwd: childCwd,
|
|
1501
1503
|
stdio: ["pipe", "pipe", "pipe"],
|
|
@@ -1504,7 +1506,7 @@ export class PiRpcRuntime {
|
|
|
1504
1506
|
// every turn would silently replace the child's environment with whatever THIS process has at
|
|
1505
1507
|
// spawn time. Inheriting is what an omitted `env` already does, so the two paths differ in nothing
|
|
1506
1508
|
// but the four documented additions.
|
|
1507
|
-
...((extensionArgs.length || memoryEnabled || knowledgeEnabled || documentsEnabled || webEnabled || feishuEnabled) ? { env: { ...process.env, ...(oneShotCapability ? await this.oneShotExtensionEnv(conversation.id, conversation.workspaceId, oneShotCapability, conversation.parentConversationId) : {}), ...(memoryEnabled ? {
|
|
1509
|
+
...((Object.keys(providerProxyEnv).length || extensionArgs.length || memoryEnabled || knowledgeEnabled || documentsEnabled || webEnabled || feishuEnabled) ? { env: { ...process.env, ...providerProxyEnv, ...(oneShotCapability ? await this.oneShotExtensionEnv(conversation.id, conversation.workspaceId, oneShotCapability, conversation.parentConversationId) : {}), ...(memoryEnabled ? {
|
|
1508
1510
|
SUPER_PI_MEMORY_ENDPOINT: process.env.SUPER_PI_MEMORY_ENDPOINT,
|
|
1509
1511
|
SUPER_PI_MEMORY_TOKEN: memoryToken,
|
|
1510
1512
|
SUPER_PI_MEMORY_REVIEW: memoryReview ? "1" : "0",
|
|
@@ -2424,6 +2426,7 @@ export class PiRpcRuntime {
|
|
|
2424
2426
|
// not be filed under the conversation whose title it is producing.
|
|
2425
2427
|
const child = spawn(shellQuote(this.pi.command), ["--mode", "rpc", "--session-dir", this.sessionDir, "--session-id", `autotitle-${randomUUID()}`], {
|
|
2426
2428
|
cwd: resolve(cwd),
|
|
2429
|
+
env: { ...process.env, ...await readProviderProxyEnv(defaultAgentDir()) },
|
|
2427
2430
|
stdio: ["pipe", "pipe", "pipe"],
|
|
2428
2431
|
shell: process.platform === "win32",
|
|
2429
2432
|
});
|
|
@@ -2502,6 +2505,7 @@ export class PiRpcRuntime {
|
|
|
2502
2505
|
// part of any conversation's transcript and must never be filed under one.
|
|
2503
2506
|
const child = spawn(shellQuote(this.pi.command), ["--mode", "rpc", "--session-dir", this.sessionDir, "--session-id", `tool-llm-${randomUUID()}`, "--no-extensions", "--no-skills", "--no-mcp", "--no-context-files", "--no-prompt-templates"], {
|
|
2504
2507
|
cwd: resolve(input.cwd),
|
|
2508
|
+
env: { ...process.env, ...await readProviderProxyEnv(defaultAgentDir()) },
|
|
2505
2509
|
stdio: ["pipe", "pipe", "pipe"],
|
|
2506
2510
|
shell: process.platform === "win32",
|
|
2507
2511
|
});
|
package/dist/server/update.d.ts
CHANGED
|
@@ -33,7 +33,7 @@ export declare function shellArgs(args: string[]): string[];
|
|
|
33
33
|
* The fetch options are there because the tarball is ~32 MB: npm's default
|
|
34
34
|
* 5 minute timeout fails on a slow line and the update looks broken.
|
|
35
35
|
*/
|
|
36
|
-
export declare function packageUpdateArgs(rootDir: string, version?: string): {
|
|
36
|
+
export declare function packageUpdateArgs(rootDir: string, version?: string, platform?: NodeJS.Platform): {
|
|
37
37
|
args: string[];
|
|
38
38
|
prefix?: string;
|
|
39
39
|
};
|
package/dist/server/update.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { npmInstallPrefix } from "../../bin/npm-prefix.js";
|
|
2
2
|
/**
|
|
3
3
|
* Quote an argument for a shell on Windows.
|
|
4
4
|
*
|
|
@@ -38,16 +38,13 @@ export function shellArgs(args) {
|
|
|
38
38
|
* The fetch options are there because the tarball is ~32 MB: npm's default
|
|
39
39
|
* 5 minute timeout fails on a slow line and the update looks broken.
|
|
40
40
|
*/
|
|
41
|
-
export function packageUpdateArgs(rootDir, version) {
|
|
42
|
-
const
|
|
43
|
-
const lower = rootDir.toLowerCase();
|
|
44
|
-
const index = lower.lastIndexOf(marker);
|
|
41
|
+
export function packageUpdateArgs(rootDir, version, platform = process.platform) {
|
|
42
|
+
const prefix = npmInstallPrefix(rootDir, platform);
|
|
45
43
|
// THE VERSION THE USER CONFIRMED. The check reads the registry directly while npm resolves
|
|
46
44
|
// "latest" from its own cache, so the two can disagree: the dialog promises vX and the
|
|
47
45
|
// install silently lands on vY. Pinning the version the dialog showed removes that gap.
|
|
48
46
|
const target = version ? `@evandu/super-pi@${version}` : "@evandu/super-pi";
|
|
49
|
-
if (
|
|
50
|
-
const prefix = rootDir.slice(0, index);
|
|
47
|
+
if (prefix !== undefined) {
|
|
51
48
|
return { prefix, args: ["install", "-g", "--prefix", prefix, "--fetch-timeout=900000", "--fetch-retries=8", "--fetch-retry-maxtimeout=120000", target] };
|
|
52
49
|
}
|
|
53
50
|
return { args: ["install", "-g", "--fetch-timeout=900000", "--fetch-retries=8", "--fetch-retry-maxtimeout=120000", target] };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@evandu/super-pi",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.199",
|
|
4
4
|
"description": "Web control plane and companion for Pi",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -404,6 +404,7 @@
|
|
|
404
404
|
"diff": "^5.2.2",
|
|
405
405
|
"fuse.js": "^7.5.0",
|
|
406
406
|
"node-pty": "^1.2.0-beta.15",
|
|
407
|
+
"undici": "^7.30.2",
|
|
407
408
|
"ws": "latest"
|
|
408
409
|
},
|
|
409
410
|
"devDependencies": {
|