@evandu/super-pi 0.1.247 → 0.1.249
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/client/.super-pi-client-sources.json +8 -8
- package/dist/client/assets/{CodeMirrorEditor-CfRZBw_k.js → CodeMirrorEditor-u02rD73w.js} +1 -1
- package/dist/client/assets/{GitDiffEditor-CxVEErgk.js → GitDiffEditor-aR4Mf581.js} +1 -1
- package/dist/client/assets/index-DwnvdiKk.css +1 -0
- package/dist/client/assets/{index-D-5yq-Mj.js → index-GBbUXCIM.js} +27 -25
- package/dist/client/index.html +2 -2
- package/dist/server/application/provider-service.d.ts +22 -0
- package/dist/server/application/provider-service.js +98 -1
- package/dist/server/application/run-service.js +4 -3
- package/dist/server/http-server.js +45 -0
- package/dist/server/index.js +2 -1
- package/dist/server/pi-session.d.ts +36 -0
- package/dist/server/pi-session.js +16 -0
- package/dist/server/runtime.d.ts +26 -0
- package/dist/server/runtime.js +13 -0
- package/dist/server/types.d.ts +4 -0
- package/dist/shared/background-task.d.ts +3 -0
- package/dist/shared/background-task.js +178 -0
- package/package.json +1 -1
- package/dist/client/assets/index-oGFfK21_.css +0 -1
package/dist/client/index.html
CHANGED
|
@@ -8,9 +8,9 @@
|
|
|
8
8
|
<link rel="alternate icon" href="/favicon.ico" />
|
|
9
9
|
<link rel="apple-touch-icon" href="/favicon.svg" />
|
|
10
10
|
<title>Super Pi</title>
|
|
11
|
-
<script type="module" crossorigin src="/assets/index-
|
|
11
|
+
<script type="module" crossorigin src="/assets/index-GBbUXCIM.js"></script>
|
|
12
12
|
<link rel="modulepreload" crossorigin href="/assets/rolldown-runtime-XKyaHtl9.js">
|
|
13
|
-
<link rel="stylesheet" crossorigin href="/assets/index-
|
|
13
|
+
<link rel="stylesheet" crossorigin href="/assets/index-DwnvdiKk.css">
|
|
14
14
|
</head>
|
|
15
15
|
<body>
|
|
16
16
|
<div id="root"></div>
|
|
@@ -32,6 +32,7 @@ export declare class ProviderService {
|
|
|
32
32
|
private readonly broadcaster;
|
|
33
33
|
private readonly catalogService;
|
|
34
34
|
private readonly store;
|
|
35
|
+
private readonly oauthJobs;
|
|
35
36
|
constructor(registry: ProviderRegistry, runtime: AgentRuntime, broadcaster: EventBroadcaster, catalogService: CatalogService, store: Store);
|
|
36
37
|
/**
|
|
37
38
|
* Every provider Pi knows about, as the browser may see it: no keys, only the fact of one.
|
|
@@ -45,6 +46,27 @@ export declare class ProviderService {
|
|
|
45
46
|
* because that provider is a built-in whose only configuration is a credential.
|
|
46
47
|
*/
|
|
47
48
|
list(): Promise<PublicProvider[]>;
|
|
49
|
+
oauthSnapshot(): {
|
|
50
|
+
id: string;
|
|
51
|
+
providerId: string;
|
|
52
|
+
state: string;
|
|
53
|
+
event?: Record<string, unknown>;
|
|
54
|
+
prompt?: {
|
|
55
|
+
type: string;
|
|
56
|
+
message: string;
|
|
57
|
+
placeholder?: string;
|
|
58
|
+
options?: {
|
|
59
|
+
id: string;
|
|
60
|
+
label: string;
|
|
61
|
+
description?: string;
|
|
62
|
+
}[];
|
|
63
|
+
};
|
|
64
|
+
error?: string;
|
|
65
|
+
}[];
|
|
66
|
+
startOAuthLogin(providerId: unknown): Promise<string>;
|
|
67
|
+
answerOAuthPrompt(id: unknown, answer: unknown): void;
|
|
68
|
+
cancelOAuthLogin(id: unknown): void;
|
|
69
|
+
logoutOAuth(providerId: unknown): Promise<void>;
|
|
48
70
|
/**
|
|
49
71
|
* Turns a provider off, then makes every LIVE conversation stop pointing at the models it removed.
|
|
50
72
|
*
|
|
@@ -3,6 +3,7 @@ import { readProviderProxyEnv } from "../provider-proxy.js";
|
|
|
3
3
|
import { piAgentDir } from "../providers.js";
|
|
4
4
|
import { hasStoredCredential } from "../provider-network.js";
|
|
5
5
|
import { thinkingLevelsEndpoint } from "../../shared/thinking-levels.js";
|
|
6
|
+
import { randomUUID } from "node:crypto";
|
|
6
7
|
/**
|
|
7
8
|
* THE PROVIDERS A PERSON ADDED, as a service.
|
|
8
9
|
*
|
|
@@ -31,6 +32,7 @@ export class ProviderService {
|
|
|
31
32
|
broadcaster;
|
|
32
33
|
catalogService;
|
|
33
34
|
store;
|
|
35
|
+
oauthJobs = new Map();
|
|
34
36
|
constructor(registry, runtime, broadcaster, catalogService, store) {
|
|
35
37
|
this.registry = registry;
|
|
36
38
|
this.runtime = runtime;
|
|
@@ -93,7 +95,102 @@ export class ProviderService {
|
|
|
93
95
|
disabled: true,
|
|
94
96
|
models: entry.models,
|
|
95
97
|
}));
|
|
96
|
-
|
|
98
|
+
const base = publicProviders([...configured, ...credentialOnly, ...offList]);
|
|
99
|
+
const oauth = await this.runtime.oauthProviders?.() ?? [];
|
|
100
|
+
const byId = new Map(base.map((provider) => [provider.id, provider]));
|
|
101
|
+
for (const info of oauth) {
|
|
102
|
+
const provider = byId.get(info.id) ?? {
|
|
103
|
+
id: info.id, name: info.name, baseUrl: "", api: "", hasKey: info.authenticated,
|
|
104
|
+
builtin: true, models: [],
|
|
105
|
+
};
|
|
106
|
+
provider.name = info.name;
|
|
107
|
+
provider.authType = "oauth";
|
|
108
|
+
provider.oauthSubscription = info.isSubscription;
|
|
109
|
+
if (info.loginLabel)
|
|
110
|
+
provider.oauthLoginLabel = info.loginLabel;
|
|
111
|
+
provider.authenticated = info.authenticated;
|
|
112
|
+
provider.hasKey = info.authenticated;
|
|
113
|
+
provider.builtin = true;
|
|
114
|
+
byId.set(info.id, provider);
|
|
115
|
+
}
|
|
116
|
+
return [...byId.values()];
|
|
117
|
+
}
|
|
118
|
+
oauthSnapshot() {
|
|
119
|
+
return [...this.oauthJobs.values()].map(({ answer: _answer, abort: _abort, ...job }) => structuredClone(job));
|
|
120
|
+
}
|
|
121
|
+
async startOAuthLogin(providerId) {
|
|
122
|
+
if (typeof providerId !== "string" || !providerId)
|
|
123
|
+
throw new Error("请选择 Pi 内置的授权供应商。");
|
|
124
|
+
const provider = (await this.runtime.oauthProviders?.() ?? []).find((item) => item.id === providerId);
|
|
125
|
+
if (!provider)
|
|
126
|
+
throw new Error("Pi 当前版本不支持这个供应商的 OAuth 登录。");
|
|
127
|
+
for (const job of this.oauthJobs.values())
|
|
128
|
+
if (job.providerId === providerId && ["starting", "authorizing", "prompt"].includes(job.state))
|
|
129
|
+
this.cancelOAuthLogin(job.id);
|
|
130
|
+
if (this.oauthJobs.size >= 20) {
|
|
131
|
+
for (const [id, job] of this.oauthJobs)
|
|
132
|
+
if (!["starting", "authorizing", "prompt"].includes(job.state)) {
|
|
133
|
+
this.oauthJobs.delete(id);
|
|
134
|
+
break;
|
|
135
|
+
}
|
|
136
|
+
if (this.oauthJobs.size >= 20)
|
|
137
|
+
throw new Error("同时进行的 OAuth 登录过多,请先完成或取消一个登录。");
|
|
138
|
+
}
|
|
139
|
+
const job = { id: randomUUID(), providerId, state: "starting", abort: new AbortController() };
|
|
140
|
+
this.oauthJobs.set(job.id, job);
|
|
141
|
+
void (async () => {
|
|
142
|
+
try {
|
|
143
|
+
await this.runtime.loginOAuth(providerId, {
|
|
144
|
+
signal: job.abort.signal,
|
|
145
|
+
notify: (event) => { job.event = event && typeof event === "object" ? structuredClone(event) : undefined; job.state = event?.type === "auth_url" || event?.type === "device_code" ? "authorizing" : "starting"; },
|
|
146
|
+
prompt: (prompt) => new Promise((resolve, reject) => {
|
|
147
|
+
job.prompt = { type: String(prompt.type ?? "text"), message: String(prompt.message ?? "Pi 需要输入授权信息"),
|
|
148
|
+
...(typeof prompt.placeholder === "string" ? { placeholder: prompt.placeholder } : {}),
|
|
149
|
+
...(Array.isArray(prompt.options) ? { options: prompt.options.map((item) => ({ id: String(item.id), label: String(item.label), ...(item.description ? { description: String(item.description) } : {}) })) } : {}) };
|
|
150
|
+
job.state = "prompt";
|
|
151
|
+
const signal = prompt.signal ?? job.abort.signal;
|
|
152
|
+
const abort = () => { job.answer = undefined; job.prompt = undefined; reject(new Error("登录已取消。")); };
|
|
153
|
+
signal.addEventListener("abort", abort, { once: true });
|
|
154
|
+
job.answer = (value) => { signal.removeEventListener("abort", abort); job.prompt = undefined; job.answer = undefined; resolve(value); };
|
|
155
|
+
if (signal.aborted)
|
|
156
|
+
abort();
|
|
157
|
+
}),
|
|
158
|
+
});
|
|
159
|
+
job.state = "completed";
|
|
160
|
+
job.event = undefined;
|
|
161
|
+
await this.afterChange();
|
|
162
|
+
}
|
|
163
|
+
catch (error) {
|
|
164
|
+
job.state = job.abort.signal.aborted ? "cancelled" : "failed";
|
|
165
|
+
job.error = job.abort.signal.aborted ? "登录已取消。" : "Pi OAuth 登录失败,请重试并检查授权页面。";
|
|
166
|
+
job.prompt = undefined;
|
|
167
|
+
job.event = undefined;
|
|
168
|
+
}
|
|
169
|
+
})();
|
|
170
|
+
return job.id;
|
|
171
|
+
}
|
|
172
|
+
answerOAuthPrompt(id, answer) {
|
|
173
|
+
const job = this.oauthJobs.get(String(id));
|
|
174
|
+
if (!job || job.state !== "prompt" || !job.answer || typeof answer !== "string" || answer.length > 8192)
|
|
175
|
+
throw new Error("授权输入已过期,请重新登录。");
|
|
176
|
+
const submit = job.answer;
|
|
177
|
+
submit(answer);
|
|
178
|
+
}
|
|
179
|
+
cancelOAuthLogin(id) {
|
|
180
|
+
const job = this.oauthJobs.get(String(id));
|
|
181
|
+
if (!job || !["starting", "authorizing", "prompt"].includes(job.state))
|
|
182
|
+
return;
|
|
183
|
+
job.state = "cancelled";
|
|
184
|
+
job.abort.abort();
|
|
185
|
+
job.answer?.("");
|
|
186
|
+
job.answer = undefined;
|
|
187
|
+
job.prompt = undefined;
|
|
188
|
+
}
|
|
189
|
+
async logoutOAuth(providerId) {
|
|
190
|
+
if (typeof providerId !== "string" || !(await this.runtime.oauthProviders?.() ?? []).some((item) => item.id === providerId))
|
|
191
|
+
throw new Error("Pi 当前版本不支持这个供应商。");
|
|
192
|
+
await this.runtime.logoutOAuth?.(providerId);
|
|
193
|
+
await this.afterChange([{ provider: providerId }]);
|
|
97
194
|
}
|
|
98
195
|
/**
|
|
99
196
|
* Turns a provider off, then makes every LIVE conversation stop pointing at the models it removed.
|
|
@@ -13,7 +13,7 @@ import { toWorkspaceRelative } from "../files.js";
|
|
|
13
13
|
import { inScope, refreshWorkspaceIndex } from "../file-index.js";
|
|
14
14
|
import { resolveSessionCwd } from "../session-cwd.js";
|
|
15
15
|
import { CHILD_QUESTION_LOCK_REASON, isChildSession } from "../../shared/child-session-lock.js";
|
|
16
|
-
import { BACKGROUND_LOG_LIMIT, subagentProgress } from "../../shared/background-task.js";
|
|
16
|
+
import { BACKGROUND_LOG_LIMIT, sanitizeBackgroundOutput, subagentProgress } from "../../shared/background-task.js";
|
|
17
17
|
import { execFile } from "node:child_process";
|
|
18
18
|
import { promisify } from "node:util";
|
|
19
19
|
import { randomUUID } from "node:crypto";
|
|
@@ -332,7 +332,8 @@ export class RunService {
|
|
|
332
332
|
const task = this.store.backgroundTask(sessionId);
|
|
333
333
|
if (!task)
|
|
334
334
|
return;
|
|
335
|
-
const
|
|
335
|
+
const rawOutput = stdout + stderr;
|
|
336
|
+
const output = sanitizeBackgroundOutput(rawOutput).slice(-BACKGROUND_LOG_LIMIT);
|
|
336
337
|
const offset = completion?.offset ?? stdout.length + stderr.length;
|
|
337
338
|
const status = completion?.status === "cancelled" || completion?.status === "interrupted"
|
|
338
339
|
? completion.status : exitCode === 0 && !completion?.signal ? "completed" : "failed";
|
|
@@ -341,7 +342,7 @@ export class RunService {
|
|
|
341
342
|
: completion?.signal ? `进程收到信号 ${completion.signal}`
|
|
342
343
|
: status === "failed" ? `Command exited with code ${exitCode}` : undefined;
|
|
343
344
|
const settling = this.trackDetached(this.finishBackgroundResult(task, {
|
|
344
|
-
status, output, outputOffset: offset, outputTruncated: offset >
|
|
345
|
+
status, output, outputOffset: offset, outputTruncated: offset > rawOutput.length,
|
|
345
346
|
exitCode, signal: completion?.signal, reason,
|
|
346
347
|
}, status === "completed" || status === "failed")).catch(error => {
|
|
347
348
|
console.warn("Super Pi: could not record background command completion:", error);
|
|
@@ -1010,6 +1010,51 @@ export function createHttpServer(options) {
|
|
|
1010
1010
|
}
|
|
1011
1011
|
return;
|
|
1012
1012
|
}
|
|
1013
|
+
if (url.pathname === "/api/providers/oauth") {
|
|
1014
|
+
const remote = request.socket.remoteAddress;
|
|
1015
|
+
const origin = request.headers.origin;
|
|
1016
|
+
const fetchSite = request.headers["sec-fetch-site"];
|
|
1017
|
+
if (!isLocalOrPrivateAddress(remote) || (origin && (fetchSite ? fetchSite !== "same-origin" : origin !== url.origin))) {
|
|
1018
|
+
json(403, { error: "供应商授权只允许本机或局域网的同源请求。" });
|
|
1019
|
+
return;
|
|
1020
|
+
}
|
|
1021
|
+
try {
|
|
1022
|
+
if (request.method === "GET") {
|
|
1023
|
+
json(200, { jobs: context.providerService.oauthSnapshot() });
|
|
1024
|
+
return;
|
|
1025
|
+
}
|
|
1026
|
+
if (request.method !== "POST") {
|
|
1027
|
+
json(405, { error: "供应商授权仅支持 GET / POST" });
|
|
1028
|
+
return;
|
|
1029
|
+
}
|
|
1030
|
+
const asked = await readRequestText(request, 16384);
|
|
1031
|
+
if (asked.tooLarge) {
|
|
1032
|
+
json(413, { error: "授权请求过大" });
|
|
1033
|
+
return;
|
|
1034
|
+
}
|
|
1035
|
+
const body = JSON.parse(asked.text || "{}");
|
|
1036
|
+
switch (body.action) {
|
|
1037
|
+
case "login":
|
|
1038
|
+
await context.providerService.startOAuthLogin(body.providerId);
|
|
1039
|
+
break;
|
|
1040
|
+
case "answer":
|
|
1041
|
+
context.providerService.answerOAuthPrompt(body.id, body.answer);
|
|
1042
|
+
break;
|
|
1043
|
+
case "cancel":
|
|
1044
|
+
context.providerService.cancelOAuthLogin(body.id);
|
|
1045
|
+
break;
|
|
1046
|
+
case "logout":
|
|
1047
|
+
await context.providerService.logoutOAuth(body.providerId);
|
|
1048
|
+
break;
|
|
1049
|
+
default: throw new Error("未知的授权操作。");
|
|
1050
|
+
}
|
|
1051
|
+
json(200, { jobs: context.providerService.oauthSnapshot() });
|
|
1052
|
+
}
|
|
1053
|
+
catch (error) {
|
|
1054
|
+
json(400, { error: error instanceof Error ? error.message : "供应商授权失败。" });
|
|
1055
|
+
}
|
|
1056
|
+
return;
|
|
1057
|
+
}
|
|
1013
1058
|
if (url.pathname === "/api/providers/fetch-models") {
|
|
1014
1059
|
if (request.method !== "POST") {
|
|
1015
1060
|
response.writeHead(405).end();
|
package/dist/server/index.js
CHANGED
|
@@ -8,6 +8,7 @@ import { homedir } from "node:os";
|
|
|
8
8
|
import { join, resolve } from "node:path";
|
|
9
9
|
import { pathToFileURL } from "node:url";
|
|
10
10
|
import { isChildSession } from "../shared/child-session-lock.js";
|
|
11
|
+
import { sanitizeBackgroundOutput } from "../shared/background-task.js";
|
|
11
12
|
import { openStateStore } from "./persistence/open-state-store.js";
|
|
12
13
|
import { PiRpcRuntime, WelcomeRuntime } from "./runtime.js";
|
|
13
14
|
import { agentModeOf, resolveAgentDirectories } from "./agents.js";
|
|
@@ -314,7 +315,7 @@ const terminalService = new TerminalService({
|
|
|
314
315
|
* Background command execution, independent from subagents. Uses node-pty to run shell commands
|
|
315
316
|
* and delivers results via WebSocket + injected conversation message.
|
|
316
317
|
*/
|
|
317
|
-
const execService = new ExecService((event) => broadcaster.broadcast(event), (sessionId, exitCode, stdout, stderr, completion) => runService.enqueueExecResult(sessionId, exitCode, stdout, stderr, completion), (sessionId, output, offset) => store.checkpointBackgroundOutput(sessionId, output, offset));
|
|
318
|
+
const execService = new ExecService((event) => broadcaster.broadcast(event), (sessionId, exitCode, stdout, stderr, completion) => runService.enqueueExecResult(sessionId, exitCode, stdout, stderr, completion), (sessionId, output, offset) => store.checkpointBackgroundOutput(sessionId, sanitizeBackgroundOutput(output), offset));
|
|
318
319
|
runService.setExecService(execService, join(dataDir, "background-logs"));
|
|
319
320
|
replayRuntime = (state, scope) => execService.outputSnapshots(state, scope);
|
|
320
321
|
projectRuntime = state => {
|
|
@@ -91,6 +91,29 @@ interface PiSdk {
|
|
|
91
91
|
* when one entry in `models.json` is refused.
|
|
92
92
|
*/
|
|
93
93
|
getError?: () => string | undefined;
|
|
94
|
+
getProviders?: () => readonly {
|
|
95
|
+
id: string;
|
|
96
|
+
name?: string;
|
|
97
|
+
auth?: {
|
|
98
|
+
oauth?: {
|
|
99
|
+
name?: string;
|
|
100
|
+
isSubscription?: boolean;
|
|
101
|
+
loginLabel?: string;
|
|
102
|
+
};
|
|
103
|
+
};
|
|
104
|
+
}[];
|
|
105
|
+
checkAuth?: (providerId: string) => Promise<{
|
|
106
|
+
type: string;
|
|
107
|
+
} | undefined>;
|
|
108
|
+
login?: (providerId: string, type: "oauth", interaction: {
|
|
109
|
+
signal?: AbortSignal;
|
|
110
|
+
prompt(prompt: any): Promise<string>;
|
|
111
|
+
notify(event: any): void;
|
|
112
|
+
}, options?: {
|
|
113
|
+
agentName?: string;
|
|
114
|
+
}) => Promise<unknown>;
|
|
115
|
+
logout?: (providerId: string) => Promise<void>;
|
|
116
|
+
refresh?: () => Promise<unknown>;
|
|
94
117
|
}>;
|
|
95
118
|
};
|
|
96
119
|
AuthStorage?: {
|
|
@@ -188,6 +211,19 @@ export interface SdkCatalog {
|
|
|
188
211
|
* settings panel shows instead of a guess.
|
|
189
212
|
*/
|
|
190
213
|
configError(): string | undefined;
|
|
214
|
+
oauthProviders(): Promise<{
|
|
215
|
+
id: string;
|
|
216
|
+
name: string;
|
|
217
|
+
isSubscription: boolean;
|
|
218
|
+
loginLabel?: string;
|
|
219
|
+
authenticated: boolean;
|
|
220
|
+
}[]>;
|
|
221
|
+
loginOAuth(providerId: string, interaction: {
|
|
222
|
+
signal?: AbortSignal;
|
|
223
|
+
prompt(prompt: any): Promise<string>;
|
|
224
|
+
notify(event: any): void;
|
|
225
|
+
}): Promise<void>;
|
|
226
|
+
logoutOAuth(providerId: string): Promise<void>;
|
|
191
227
|
}
|
|
192
228
|
/**
|
|
193
229
|
* What a session says about one model's thinking: the levels it offers, and the one in force.
|
|
@@ -122,6 +122,22 @@ export async function createSdkCatalog(cwd) {
|
|
|
122
122
|
return {
|
|
123
123
|
models,
|
|
124
124
|
configError: () => modelRuntime.getError?.(),
|
|
125
|
+
oauthProviders: async () => Promise.all((modelRuntime.getProviders?.() ?? []).flatMap((provider) => provider.auth?.oauth
|
|
126
|
+
? [Promise.resolve(modelRuntime.checkAuth?.(provider.id)).then((auth) => ({ id: provider.id, name: provider.auth.oauth.name ?? provider.name ?? provider.id,
|
|
127
|
+
isSubscription: provider.auth.oauth.isSubscription === true,
|
|
128
|
+
...(provider.auth.oauth.loginLabel ? { loginLabel: provider.auth.oauth.loginLabel } : {}), authenticated: auth?.type === "oauth" }))]
|
|
129
|
+
: [])),
|
|
130
|
+
loginOAuth: async (providerId, interaction) => {
|
|
131
|
+
if (!modelRuntime.login)
|
|
132
|
+
throw new Error("当前 Pi SDK 不支持供应商登录。");
|
|
133
|
+
await modelRuntime.login(providerId, "oauth", interaction, { agentName: "Super Pi" });
|
|
134
|
+
await modelRuntime.refresh?.();
|
|
135
|
+
},
|
|
136
|
+
logoutOAuth: async (providerId) => {
|
|
137
|
+
if (!modelRuntime.logout)
|
|
138
|
+
throw new Error("当前 Pi SDK 不支持供应商退出登录。");
|
|
139
|
+
await modelRuntime.logout(providerId);
|
|
140
|
+
},
|
|
125
141
|
...(resolved ? { defaultModel: resolved.model } : {}),
|
|
126
142
|
thinkingLevelsFor: async (model) => {
|
|
127
143
|
const key = `${model.provider}/${model.modelId}`;
|
package/dist/server/runtime.d.ts
CHANGED
|
@@ -384,6 +384,19 @@ export interface AgentRuntime {
|
|
|
384
384
|
* selected model silently clamps away.
|
|
385
385
|
*/
|
|
386
386
|
catalog(selection?: ModelSelection): Promise<ModelCatalog>;
|
|
387
|
+
oauthProviders?(): Promise<{
|
|
388
|
+
id: string;
|
|
389
|
+
name: string;
|
|
390
|
+
isSubscription: boolean;
|
|
391
|
+
loginLabel?: string;
|
|
392
|
+
authenticated: boolean;
|
|
393
|
+
}[]>;
|
|
394
|
+
loginOAuth?(providerId: string, interaction: {
|
|
395
|
+
signal: AbortSignal;
|
|
396
|
+
prompt(prompt: any): Promise<string>;
|
|
397
|
+
notify(event: any): void;
|
|
398
|
+
}): Promise<void>;
|
|
399
|
+
logoutOAuth?(providerId: string): Promise<void>;
|
|
387
400
|
/**
|
|
388
401
|
* Throws away every cached answer about the models Pi offers.
|
|
389
402
|
*
|
|
@@ -1272,6 +1285,19 @@ export declare class PiRpcRuntime implements AgentRuntime {
|
|
|
1272
1285
|
* what just changed.
|
|
1273
1286
|
*/
|
|
1274
1287
|
invalidateCatalog(): void;
|
|
1288
|
+
oauthProviders(): Promise<never[] | {
|
|
1289
|
+
id: string;
|
|
1290
|
+
name: string;
|
|
1291
|
+
isSubscription: boolean;
|
|
1292
|
+
loginLabel?: string;
|
|
1293
|
+
authenticated: boolean;
|
|
1294
|
+
}[]>;
|
|
1295
|
+
loginOAuth(providerId: string, interaction: {
|
|
1296
|
+
signal: AbortSignal;
|
|
1297
|
+
prompt(prompt: any): Promise<string>;
|
|
1298
|
+
notify(event: any): void;
|
|
1299
|
+
}): Promise<void>;
|
|
1300
|
+
logoutOAuth(providerId: string): Promise<void>;
|
|
1275
1301
|
/**
|
|
1276
1302
|
* Makes every live session stale, so the next turn builds one that knows the current models.
|
|
1277
1303
|
*
|
package/dist/server/runtime.js
CHANGED
|
@@ -2895,6 +2895,19 @@ export class PiRpcRuntime {
|
|
|
2895
2895
|
this.pendingCatalogs.clear();
|
|
2896
2896
|
this.sdkCatalogPromise = undefined;
|
|
2897
2897
|
}
|
|
2898
|
+
async oauthProviders() { return (await this.sdkCatalog())?.oauthProviders() ?? []; }
|
|
2899
|
+
async loginOAuth(providerId, interaction) {
|
|
2900
|
+
const catalog = await this.sdkCatalog();
|
|
2901
|
+
if (!catalog)
|
|
2902
|
+
throw new Error("Pi 的供应商登录功能不可用。");
|
|
2903
|
+
await catalog.loginOAuth(providerId, interaction);
|
|
2904
|
+
}
|
|
2905
|
+
async logoutOAuth(providerId) {
|
|
2906
|
+
const catalog = await this.sdkCatalog();
|
|
2907
|
+
if (!catalog)
|
|
2908
|
+
throw new Error("Pi 的供应商登录功能不可用。");
|
|
2909
|
+
await catalog.logoutOAuth(providerId);
|
|
2910
|
+
}
|
|
2898
2911
|
/**
|
|
2899
2912
|
* Makes every live session stale, so the next turn builds one that knows the current models.
|
|
2900
2913
|
*
|
package/dist/server/types.d.ts
CHANGED
|
@@ -428,6 +428,10 @@ export type PublicProvider = {
|
|
|
428
428
|
baseUrl: string;
|
|
429
429
|
api: string;
|
|
430
430
|
hasKey: boolean;
|
|
431
|
+
authType?: "api_key" | "oauth";
|
|
432
|
+
oauthSubscription?: boolean;
|
|
433
|
+
oauthLoginLabel?: string;
|
|
434
|
+
authenticated?: boolean;
|
|
431
435
|
/**
|
|
432
436
|
* TRUE when the key lives in `models.json` itself (Pi's `"apiKey": "$MY_KEY"` form) rather than
|
|
433
437
|
* in `auth.json`. It is a credential all the same, so the panel must not report it as missing.
|
|
@@ -10,6 +10,9 @@ export type BackgroundTaskDetails = {
|
|
|
10
10
|
reason?: string;
|
|
11
11
|
};
|
|
12
12
|
export declare const BACKGROUND_LOG_LIMIT = 128000;
|
|
13
|
+
/** Render a PTY byte stream as readable text for logs and chat. This is deliberately a text view, not a
|
|
14
|
+
* terminal UI: cursor movement edits the buffered lines, while colour, title and mode controls vanish. */
|
|
15
|
+
export declare function sanitizeBackgroundOutput(value: string): string;
|
|
13
16
|
export type BackgroundCompletion = Omit<BackgroundTaskDetails, "id" | "status"> & {
|
|
14
17
|
status: Exclude<BackgroundTaskStatus, "running">;
|
|
15
18
|
};
|
|
@@ -1,4 +1,182 @@
|
|
|
1
1
|
export const BACKGROUND_LOG_LIMIT = 128_000;
|
|
2
|
+
/** Render a PTY byte stream as readable text for logs and chat. This is deliberately a text view, not a
|
|
3
|
+
* terminal UI: cursor movement edits the buffered lines, while colour, title and mode controls vanish. */
|
|
4
|
+
export function sanitizeBackgroundOutput(value) {
|
|
5
|
+
const lines = [[]];
|
|
6
|
+
let row = 0;
|
|
7
|
+
let column = 0;
|
|
8
|
+
let savedCursor = [0, 0];
|
|
9
|
+
const ensureRow = (index) => {
|
|
10
|
+
while (lines.length <= index)
|
|
11
|
+
lines.push([]);
|
|
12
|
+
};
|
|
13
|
+
const write = (text) => {
|
|
14
|
+
const cells = lines[row];
|
|
15
|
+
while (cells.length < column)
|
|
16
|
+
cells.push(" ");
|
|
17
|
+
for (const char of text) {
|
|
18
|
+
cells[column] = char;
|
|
19
|
+
column += 1;
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
const paramsOf = (raw) => raw.replace(/^[?>!]/u, "").split(";").map(item => Number.parseInt(item, 10) || 0);
|
|
23
|
+
const consumeCsi = (raw, final) => {
|
|
24
|
+
const params = paramsOf(raw);
|
|
25
|
+
const amount = Math.max(1, params[0] || 1);
|
|
26
|
+
switch (final) {
|
|
27
|
+
case "A":
|
|
28
|
+
row = Math.max(0, row - amount);
|
|
29
|
+
break;
|
|
30
|
+
case "B":
|
|
31
|
+
case "e":
|
|
32
|
+
row += amount;
|
|
33
|
+
ensureRow(row);
|
|
34
|
+
break;
|
|
35
|
+
case "C":
|
|
36
|
+
case "a":
|
|
37
|
+
column += amount;
|
|
38
|
+
break;
|
|
39
|
+
case "D":
|
|
40
|
+
column = Math.max(0, column - amount);
|
|
41
|
+
break;
|
|
42
|
+
case "E":
|
|
43
|
+
row += amount;
|
|
44
|
+
ensureRow(row);
|
|
45
|
+
column = 0;
|
|
46
|
+
break;
|
|
47
|
+
case "F":
|
|
48
|
+
row = Math.max(0, row - amount);
|
|
49
|
+
column = 0;
|
|
50
|
+
break;
|
|
51
|
+
case "G":
|
|
52
|
+
case "`":
|
|
53
|
+
column = Math.max(0, amount - 1);
|
|
54
|
+
break;
|
|
55
|
+
case "d":
|
|
56
|
+
row = Math.max(0, amount - 1);
|
|
57
|
+
ensureRow(row);
|
|
58
|
+
break;
|
|
59
|
+
case "H":
|
|
60
|
+
case "f":
|
|
61
|
+
row = Math.max(0, amount - 1);
|
|
62
|
+
ensureRow(row);
|
|
63
|
+
column = Math.max(0, (params[1] || 1) - 1);
|
|
64
|
+
break;
|
|
65
|
+
case "K": {
|
|
66
|
+
const cells = lines[row];
|
|
67
|
+
if ((params[0] ?? 0) === 2)
|
|
68
|
+
lines[row] = [];
|
|
69
|
+
else if ((params[0] ?? 0) === 1)
|
|
70
|
+
lines[row] = [...Array.from({ length: Math.min(column + 1, cells.length) }, () => " "), ...cells.slice(column + 1)];
|
|
71
|
+
else
|
|
72
|
+
cells.splice(column);
|
|
73
|
+
break;
|
|
74
|
+
}
|
|
75
|
+
case "J":
|
|
76
|
+
if ((params[0] ?? 0) === 2 || (params[0] ?? 0) === 3) {
|
|
77
|
+
lines.splice(0, lines.length, []);
|
|
78
|
+
row = 0;
|
|
79
|
+
column = 0;
|
|
80
|
+
}
|
|
81
|
+
else if ((params[0] ?? 0) === 0)
|
|
82
|
+
lines.splice(row + 1);
|
|
83
|
+
else if ((params[0] ?? 0) === 1) {
|
|
84
|
+
lines.splice(0, row);
|
|
85
|
+
row = 0;
|
|
86
|
+
lines[0] = [];
|
|
87
|
+
}
|
|
88
|
+
break;
|
|
89
|
+
case "s":
|
|
90
|
+
savedCursor = [row, column];
|
|
91
|
+
break;
|
|
92
|
+
case "u":
|
|
93
|
+
[row, column] = savedCursor;
|
|
94
|
+
ensureRow(row);
|
|
95
|
+
break;
|
|
96
|
+
case "P":
|
|
97
|
+
lines[row].splice(column, amount);
|
|
98
|
+
break;
|
|
99
|
+
case "X": {
|
|
100
|
+
const cells = lines[row];
|
|
101
|
+
for (let index = column; index < Math.min(cells.length, column + amount); index += 1)
|
|
102
|
+
cells[index] = " ";
|
|
103
|
+
break;
|
|
104
|
+
}
|
|
105
|
+
case "@": {
|
|
106
|
+
const cells = lines[row];
|
|
107
|
+
cells.splice(column, 0, ...Array.from({ length: amount }, () => " "));
|
|
108
|
+
break;
|
|
109
|
+
}
|
|
110
|
+
default: break;
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
const skipStringControl = (start) => {
|
|
114
|
+
for (let index = start; index < value.length; index += 1) {
|
|
115
|
+
if (value[index] === "\u0007")
|
|
116
|
+
return index + 1;
|
|
117
|
+
if (value[index] === "\u001b" && value[index + 1] === "\\")
|
|
118
|
+
return index + 2;
|
|
119
|
+
}
|
|
120
|
+
return value.length;
|
|
121
|
+
};
|
|
122
|
+
for (let index = 0; index < value.length;) {
|
|
123
|
+
const char = value[index];
|
|
124
|
+
if (char === "\u0090" || char === "\u009d" || char === "\u009e" || char === "\u009f") {
|
|
125
|
+
index = skipStringControl(index + 1);
|
|
126
|
+
continue;
|
|
127
|
+
}
|
|
128
|
+
if (char === "\u001b" || char === "\u009b") {
|
|
129
|
+
const next = value[index + 1];
|
|
130
|
+
if (char === "\u001b" && (next === "]" || next === "P" || next === "^" || next === "_")) {
|
|
131
|
+
index = skipStringControl(index + 2);
|
|
132
|
+
continue;
|
|
133
|
+
}
|
|
134
|
+
if ((char === "\u001b" && next === "[") || char === "\u009b") {
|
|
135
|
+
const parameterStart = index + (char === "\u009b" ? 1 : 2);
|
|
136
|
+
let end = parameterStart;
|
|
137
|
+
while (end < value.length && !(value.charCodeAt(end) >= 0x40 && value.charCodeAt(end) <= 0x7e))
|
|
138
|
+
end += 1;
|
|
139
|
+
if (end < value.length)
|
|
140
|
+
consumeCsi(value.slice(parameterStart, end), value[end]);
|
|
141
|
+
index = Math.min(value.length, end + 1);
|
|
142
|
+
continue;
|
|
143
|
+
}
|
|
144
|
+
index += next === undefined ? 1 : 2;
|
|
145
|
+
continue;
|
|
146
|
+
}
|
|
147
|
+
if (char === "\r") {
|
|
148
|
+
index += 1;
|
|
149
|
+
column = 0;
|
|
150
|
+
continue;
|
|
151
|
+
}
|
|
152
|
+
if (char === "\n") {
|
|
153
|
+
index += 1;
|
|
154
|
+
row += 1;
|
|
155
|
+
ensureRow(row);
|
|
156
|
+
column = 0;
|
|
157
|
+
continue;
|
|
158
|
+
}
|
|
159
|
+
if (char === "\b") {
|
|
160
|
+
index += 1;
|
|
161
|
+
column = Math.max(0, column - 1);
|
|
162
|
+
continue;
|
|
163
|
+
}
|
|
164
|
+
if (char === "\t") {
|
|
165
|
+
index += 1;
|
|
166
|
+
write(" ".repeat(8 - (column % 8)));
|
|
167
|
+
continue;
|
|
168
|
+
}
|
|
169
|
+
const code = value.codePointAt(index) ?? 0;
|
|
170
|
+
if (code < 0x20 || code === 0x7f || (code >= 0x80 && code <= 0x9f)) {
|
|
171
|
+
index += code > 0xffff ? 2 : 1;
|
|
172
|
+
continue;
|
|
173
|
+
}
|
|
174
|
+
const printable = String.fromCodePoint(code);
|
|
175
|
+
write(printable);
|
|
176
|
+
index += printable.length;
|
|
177
|
+
}
|
|
178
|
+
return lines.map(cells => cells.join("")).join("\n").replace(/\n+$/u, "");
|
|
179
|
+
}
|
|
2
180
|
export function subagentProgress(run) {
|
|
3
181
|
return [run.partialOutput ?? run.output, ...(run.toolCalls ?? []).map(call => call.output)]
|
|
4
182
|
.filter(Boolean).join("\n\n");
|