@evandu/super-pi 0.1.288 → 0.1.290
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/desktop/main.cjs +14 -2
- package/desktop/notification-routing.cjs +45 -0
- package/desktop/notifications.cjs +1 -1
- package/desktop/pet-preload.cjs +11 -0
- package/desktop/pet-renderer.js +34 -0
- package/desktop/pet.cjs +77 -0
- package/desktop/pet.css +26 -0
- package/desktop/pet.html +32 -0
- package/desktop/preload.cjs +4 -1
- package/dist/client/.super-pi-client-sources.json +15 -14
- package/dist/client/assets/{CodeMirrorEditor-CWtrW4l8.js → CodeMirrorEditor-CC6Mf3yd.js} +1 -1
- package/dist/client/assets/{GitDiffEditor-as0g7l10.js → GitDiffEditor-AhSKDGru.js} +1 -1
- package/dist/client/assets/index-D-sud3i3.js +350 -0
- package/dist/client/assets/index-dkbN-Swt.css +1 -0
- package/dist/client/index.html +2 -2
- package/dist/server/application/catalog-service.js +1 -0
- package/dist/server/application/run-service.d.ts +1 -0
- package/dist/server/application/run-service.js +26 -1
- package/dist/server/command-handler.js +35 -0
- package/dist/server/managed-model-adapter.js +101 -30
- package/dist/server/managed-model-flow.d.ts +20 -0
- package/dist/server/managed-model-flow.js +94 -0
- package/dist/server/managed-model-gateway.d.ts +6 -1
- package/dist/server/managed-model-gateway.js +95 -13
- package/dist/server/managed-model-relay.d.ts +1 -0
- package/dist/server/managed-model-relay.js +63 -11
- package/dist/server/managed-model-wire.d.ts +20 -0
- package/dist/server/managed-model-wire.js +82 -0
- package/dist/server/pi-session-pool.d.ts +1 -0
- package/dist/server/pi-session-pool.js +1 -0
- package/dist/server/pi-session.d.ts +8 -0
- package/dist/server/pi-session.js +19 -1
- package/dist/server/runtime.d.ts +2 -0
- package/dist/server/runtime.js +13 -0
- package/dist/server/turn-failure.js +1 -1
- package/dist/server/types.d.ts +3 -0
- package/dist/shared/slash-commands.d.ts +7 -0
- package/dist/shared/slash-commands.js +18 -0
- package/package.json +3 -1
- package/dist/.super-pi-check-inputs.json +0 -4
- package/dist/client/assets/index-CA58HvxO.css +0 -1
- package/dist/client/assets/index-CtgkiwLi.js +0 -350
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { randomUUID } from "node:crypto";
|
|
2
2
|
import { WebSocket } from "ws";
|
|
3
|
+
import { MODEL_REQUEST_HEADER, ModelFlowTrace, modelRequestId } from "./managed-model-flow.js";
|
|
3
4
|
// Only model requests cross this connection. The destination and credential are
|
|
4
5
|
// selected by the manager and never taken from a remote request.
|
|
5
6
|
const maxRequest = 32 * 1024 * 1024;
|
|
@@ -7,6 +8,7 @@ const maxConcurrent = 32;
|
|
|
7
8
|
export class ModelRelay {
|
|
8
9
|
socket;
|
|
9
10
|
requests = new Map();
|
|
11
|
+
traces = new Map();
|
|
10
12
|
waiting = new Set();
|
|
11
13
|
close() {
|
|
12
14
|
this.socket?.terminate();
|
|
@@ -18,14 +20,20 @@ export class ModelRelay {
|
|
|
18
20
|
for (const response of this.requests.values())
|
|
19
21
|
response.destroy();
|
|
20
22
|
this.requests.clear();
|
|
23
|
+
for (const trace of this.traces.values())
|
|
24
|
+
trace.finish("channel-replaced");
|
|
25
|
+
this.traces.clear();
|
|
21
26
|
this.socket = socket;
|
|
22
27
|
for (const resume of this.waiting)
|
|
23
28
|
resume();
|
|
24
29
|
socket.on("error", () => socket.terminate());
|
|
25
|
-
socket.on("close",
|
|
30
|
+
socket.on("close", code => {
|
|
26
31
|
if (this.socket !== socket)
|
|
27
32
|
return;
|
|
28
33
|
this.socket = undefined;
|
|
34
|
+
for (const trace of this.traces.values())
|
|
35
|
+
trace.finish(`channel-closed-${code}`);
|
|
36
|
+
this.traces.clear();
|
|
29
37
|
for (const response of this.requests.values())
|
|
30
38
|
response.destroy();
|
|
31
39
|
this.requests.clear();
|
|
@@ -38,19 +46,34 @@ export class ModelRelay {
|
|
|
38
46
|
const response = this.requests.get(id);
|
|
39
47
|
if (!response)
|
|
40
48
|
return;
|
|
41
|
-
|
|
49
|
+
const trace = this.traces.get(id);
|
|
50
|
+
if (type === "start") {
|
|
42
51
|
response.writeHead(status, { "content-type": contentType === "application/json" ? contentType : "application/x-ndjson", "cache-control": "no-store" });
|
|
52
|
+
response.flushHeaders();
|
|
53
|
+
trace?.record("response-start", 0, true);
|
|
54
|
+
}
|
|
43
55
|
else if (type === "data") {
|
|
44
|
-
|
|
56
|
+
const chunk = Buffer.from(data, "base64");
|
|
57
|
+
trace?.record("ws-receive", chunk.length);
|
|
58
|
+
if (response.writableLength > maxRequest) {
|
|
59
|
+
trace?.finish("downstream-buffer-limit");
|
|
60
|
+
this.traces.delete(id);
|
|
45
61
|
response.destroy();
|
|
46
|
-
|
|
47
|
-
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
response.write(chunk);
|
|
65
|
+
trace?.record("http-write", chunk.length);
|
|
66
|
+
}
|
|
48
67
|
}
|
|
49
68
|
else if (type === "end") {
|
|
69
|
+
trace?.finish("http-end");
|
|
70
|
+
this.traces.delete(id);
|
|
50
71
|
this.requests.delete(id);
|
|
51
72
|
response.end();
|
|
52
73
|
}
|
|
53
74
|
else if (type === "error") {
|
|
75
|
+
trace?.finish("entry-forward-error");
|
|
76
|
+
this.traces.delete(id);
|
|
54
77
|
this.requests.delete(id);
|
|
55
78
|
if (response.headersSent)
|
|
56
79
|
response.destroy();
|
|
@@ -102,9 +125,17 @@ export class ModelRelay {
|
|
|
102
125
|
response.writeHead(503).end();
|
|
103
126
|
return;
|
|
104
127
|
}
|
|
105
|
-
|
|
128
|
+
let id = modelRequestId(request.headers[MODEL_REQUEST_HEADER]);
|
|
129
|
+
if (this.requests.has(id))
|
|
130
|
+
id = randomUUID();
|
|
131
|
+
const trace = new ModelFlowTrace(id, "remote-relay");
|
|
132
|
+
this.traces.set(id, trace);
|
|
133
|
+
response.setHeader(MODEL_REQUEST_HEADER, id);
|
|
134
|
+
trace.record("request", Buffer.concat(parts).length, true);
|
|
106
135
|
this.requests.set(id, response);
|
|
107
136
|
response.once("close", () => {
|
|
137
|
+
this.traces.get(id)?.finish("response-closed");
|
|
138
|
+
this.traces.delete(id);
|
|
108
139
|
if (this.requests.delete(id) && socket.readyState === WebSocket.OPEN)
|
|
109
140
|
socket.send(JSON.stringify({ type: "cancel", id }));
|
|
110
141
|
});
|
|
@@ -134,7 +165,20 @@ export function connectModelRelay(origin, key, gatewayPort, modelToken) {
|
|
|
134
165
|
socket.on("error", () => socket.terminate());
|
|
135
166
|
socket.on("close", () => { clearInterval(heartbeat); for (const controller of active.values())
|
|
136
167
|
controller.abort(); });
|
|
137
|
-
const send = (value) => new Promise((resolve, reject) =>
|
|
168
|
+
const send = (value, signal) => new Promise((resolve, reject) => {
|
|
169
|
+
const finish = (error) => { clearTimeout(timer); signal?.removeEventListener("abort", aborted); if (error)
|
|
170
|
+
reject(error);
|
|
171
|
+
else
|
|
172
|
+
resolve(); };
|
|
173
|
+
const aborted = () => finish(new Error("Model relay request aborted"));
|
|
174
|
+
const timer = setTimeout(() => finish(new Error("Model relay WebSocket send timed out")), 30_000);
|
|
175
|
+
signal?.addEventListener("abort", aborted, { once: true });
|
|
176
|
+
if (signal?.aborted) {
|
|
177
|
+
aborted();
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
socket.send(JSON.stringify(value), error => finish(error));
|
|
181
|
+
});
|
|
138
182
|
socket.on("message", async (raw) => {
|
|
139
183
|
let message;
|
|
140
184
|
try {
|
|
@@ -158,25 +202,33 @@ export function connectModelRelay(origin, key, gatewayPort, modelToken) {
|
|
|
158
202
|
return;
|
|
159
203
|
}
|
|
160
204
|
const controller = new AbortController();
|
|
205
|
+
const trace = new ModelFlowTrace(modelRequestId(id), "entry-relay");
|
|
206
|
+
trace.record("request", Buffer.byteLength(body, "base64"), true);
|
|
161
207
|
active.set(id, controller);
|
|
208
|
+
let endReason = "forward-error";
|
|
162
209
|
try {
|
|
163
|
-
const result = await fetch(`http://127.0.0.1:${gatewayPort}${path}`, { method: "POST", redirect: "error", headers: { authorization: `Bearer ${modelToken}`, "content-type": "application/json" }, body: Buffer.from(body, "base64"), signal: controller.signal });
|
|
164
|
-
await send({ id, type: "start", status: result.status, contentType: result.headers.get("content-type") });
|
|
210
|
+
const result = await fetch(`http://127.0.0.1:${gatewayPort}${path}`, { method: "POST", redirect: "error", headers: { authorization: `Bearer ${modelToken}`, "content-type": "application/json", [MODEL_REQUEST_HEADER]: id }, body: Buffer.from(body, "base64"), signal: controller.signal });
|
|
211
|
+
await send({ id, type: "start", status: result.status, contentType: result.headers.get("content-type") }, controller.signal);
|
|
165
212
|
const reader = result.body?.getReader();
|
|
166
213
|
if (reader)
|
|
167
214
|
for (;;) {
|
|
168
215
|
const { value, done } = await reader.read();
|
|
169
216
|
if (done)
|
|
170
217
|
break;
|
|
171
|
-
|
|
218
|
+
trace.record("gateway-receive", value.byteLength);
|
|
219
|
+
trace.record("ws-send-begin", value.byteLength);
|
|
220
|
+
await send({ id, type: "data", data: Buffer.from(value).toString("base64") }, controller.signal);
|
|
221
|
+
trace.record("ws-send-complete", value.byteLength);
|
|
172
222
|
}
|
|
173
|
-
await send({ id, type: "end" });
|
|
223
|
+
await send({ id, type: "end" }, controller.signal);
|
|
224
|
+
endReason = "http-end";
|
|
174
225
|
}
|
|
175
226
|
catch {
|
|
176
227
|
if (socket.readyState === WebSocket.OPEN)
|
|
177
228
|
await send({ id, type: "error" }).catch(() => { });
|
|
178
229
|
}
|
|
179
230
|
finally {
|
|
231
|
+
trace.finish(controller.signal.aborted ? "aborted" : endReason);
|
|
180
232
|
controller.abort();
|
|
181
233
|
active.delete(id);
|
|
182
234
|
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { AssistantMessage, AssistantMessageEvent } from "@earendil-works/pi-ai";
|
|
2
|
+
export declare const MODEL_STREAM_PROTOCOL = "compact-v1";
|
|
3
|
+
type Block = AssistantMessage["content"][number];
|
|
4
|
+
type Frame = {
|
|
5
|
+
wire: 1;
|
|
6
|
+
event: Record<string, unknown>;
|
|
7
|
+
meta?: Omit<AssistantMessage, "content">;
|
|
8
|
+
block?: Block;
|
|
9
|
+
};
|
|
10
|
+
/** Pi partials are live mutable helpers. Reconstruct event-time content from deltas. */
|
|
11
|
+
export declare class ModelWireEncoder {
|
|
12
|
+
private previousMeta;
|
|
13
|
+
encode(event: AssistantMessageEvent): AssistantMessageEvent | Frame;
|
|
14
|
+
}
|
|
15
|
+
export declare class ModelWireDecoder {
|
|
16
|
+
private partial?;
|
|
17
|
+
private arguments;
|
|
18
|
+
decode(value: unknown): AssistantMessageEvent;
|
|
19
|
+
}
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { parseStreamingJson } from "@earendil-works/pi-ai";
|
|
2
|
+
export const MODEL_STREAM_PROTOCOL = "compact-v1";
|
|
3
|
+
/** Pi partials are live mutable helpers. Reconstruct event-time content from deltas. */
|
|
4
|
+
export class ModelWireEncoder {
|
|
5
|
+
previousMeta = "";
|
|
6
|
+
encode(event) {
|
|
7
|
+
if (!("partial" in event))
|
|
8
|
+
return event;
|
|
9
|
+
const { partial, ...value } = event;
|
|
10
|
+
const { content, ...meta } = partial;
|
|
11
|
+
const serialized = JSON.stringify(meta);
|
|
12
|
+
const frame = { wire: 1, event: value };
|
|
13
|
+
if (serialized !== this.previousMeta) {
|
|
14
|
+
frame.meta = meta;
|
|
15
|
+
this.previousMeta = serialized;
|
|
16
|
+
}
|
|
17
|
+
if ("contentIndex" in event && !event.type.endsWith("_delta")) {
|
|
18
|
+
const block = content[event.contentIndex];
|
|
19
|
+
if (block)
|
|
20
|
+
frame.block = block;
|
|
21
|
+
}
|
|
22
|
+
return frame;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
export class ModelWireDecoder {
|
|
26
|
+
partial;
|
|
27
|
+
arguments = new Map();
|
|
28
|
+
decode(value) {
|
|
29
|
+
const frame = value;
|
|
30
|
+
if (frame.wire !== 1)
|
|
31
|
+
return value;
|
|
32
|
+
if (frame.meta)
|
|
33
|
+
this.partial = { ...frame.meta, content: this.partial?.content ?? [] };
|
|
34
|
+
const partial = this.partial;
|
|
35
|
+
if (!partial)
|
|
36
|
+
throw new Error("模型通道增量事件缺少初始消息信息。");
|
|
37
|
+
const event = frame.event;
|
|
38
|
+
const type = event.type, index = event.contentIndex;
|
|
39
|
+
if (type === "start")
|
|
40
|
+
partial.content = [];
|
|
41
|
+
else if (type.endsWith("_start") && frame.block) {
|
|
42
|
+
const block = { ...frame.block };
|
|
43
|
+
if (block.type === "text")
|
|
44
|
+
block.text = "";
|
|
45
|
+
if (block.type === "thinking" && !block.redacted)
|
|
46
|
+
block.thinking = "";
|
|
47
|
+
partial.content[index] = block;
|
|
48
|
+
if (block.type === "toolCall")
|
|
49
|
+
this.arguments.delete(index);
|
|
50
|
+
}
|
|
51
|
+
else if (type === "text_delta" || type === "thinking_delta") {
|
|
52
|
+
const kind = type === "text_delta" ? "text" : "thinking";
|
|
53
|
+
let block = partial.content[index];
|
|
54
|
+
if (!block || block.type !== kind)
|
|
55
|
+
block = kind === "text" ? { type: "text", text: "" } : { type: "thinking", thinking: "" };
|
|
56
|
+
if (block.type === "text")
|
|
57
|
+
block.text += event.delta;
|
|
58
|
+
else if (block.type === "thinking")
|
|
59
|
+
block.thinking += event.delta;
|
|
60
|
+
partial.content[index] = block;
|
|
61
|
+
}
|
|
62
|
+
else if (type === "toolcall_delta") {
|
|
63
|
+
const text = (this.arguments.get(index) ?? "") + event.delta;
|
|
64
|
+
this.arguments.set(index, text);
|
|
65
|
+
const block = partial.content[index];
|
|
66
|
+
if (block?.type === "toolCall")
|
|
67
|
+
block.arguments = parseStreamingJson(text);
|
|
68
|
+
}
|
|
69
|
+
else if (type.endsWith("_end")) {
|
|
70
|
+
if (frame.block)
|
|
71
|
+
partial.content[index] = frame.block;
|
|
72
|
+
if (type === "text_end" && partial.content[index]?.type === "text")
|
|
73
|
+
partial.content[index].text = event.content;
|
|
74
|
+
if (type === "thinking_end" && partial.content[index]?.type === "thinking")
|
|
75
|
+
partial.content[index].thinking = event.content;
|
|
76
|
+
if (type === "toolcall_end")
|
|
77
|
+
partial.content[index] = event.toolCall;
|
|
78
|
+
this.arguments.delete(index);
|
|
79
|
+
}
|
|
80
|
+
return { ...event, partial };
|
|
81
|
+
}
|
|
82
|
+
}
|
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
import { type PiSessionFactory, type PiSessionLike } from "./pi-session.js";
|
|
24
24
|
/** What the pool needs to build a session for a conversation. */
|
|
25
25
|
export interface SessionRequest {
|
|
26
|
+
refreshResources?: boolean;
|
|
26
27
|
conversationId: string;
|
|
27
28
|
cwd: string;
|
|
28
29
|
/** The recorded transcript locator, verified against the real header before use. */
|
|
@@ -206,6 +206,7 @@ export class PiSessionPool {
|
|
|
206
206
|
...(request.sessionFile ? { sessionFile: request.sessionFile } : {}),
|
|
207
207
|
extensionPaths: superPiExtensionPaths(this.repositoryRoot),
|
|
208
208
|
skillPaths: superPiSkillPaths(this.repositoryRoot),
|
|
209
|
+
...(request.refreshResources ? { refreshResources: true } : {}),
|
|
209
210
|
extensionEnv: request.extensionEnv,
|
|
210
211
|
...(request.systemPromptFile ? { systemPromptFile: request.systemPromptFile } : {}),
|
|
211
212
|
...(request.systemPromptMode ? { systemPromptMode: request.systemPromptMode } : {}),
|
|
@@ -60,6 +60,12 @@ interface PiSdk {
|
|
|
60
60
|
extensionFactories?: unknown[];
|
|
61
61
|
}) => {
|
|
62
62
|
reload(): Promise<void>;
|
|
63
|
+
getExtensions?(): {
|
|
64
|
+
errors: Array<{
|
|
65
|
+
path: string;
|
|
66
|
+
error: string;
|
|
67
|
+
}>;
|
|
68
|
+
};
|
|
63
69
|
getPrompts?: () => {
|
|
64
70
|
prompts: Array<{
|
|
65
71
|
name: string;
|
|
@@ -553,6 +559,8 @@ export interface PiSessionLike {
|
|
|
553
559
|
}
|
|
554
560
|
/** How a session should be built. Everything here is decided once, at creation. */
|
|
555
561
|
export interface SessionCreation {
|
|
562
|
+
/** Explicit user reload bypasses Pi's cross-session extension factory cache. */
|
|
563
|
+
refreshResources?: boolean;
|
|
556
564
|
/** The workspace. Pi resolves tools and the session file against it. */
|
|
557
565
|
cwd: string;
|
|
558
566
|
/** The session id, which is the Super Pi conversation id. */
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
import { existsSync, readdirSync, statSync } from "node:fs";
|
|
27
27
|
import { open, readdir } from "node:fs/promises";
|
|
28
28
|
import { StringDecoder } from "node:string_decoder";
|
|
29
|
-
import { dirname, join, resolve } from "node:path";
|
|
29
|
+
import { basename, dirname, join, resolve } from "node:path";
|
|
30
30
|
import { createModelResolver } from "./model-context-window.js";
|
|
31
31
|
import { installProviderProxy, proxyCredentialStore, readProviderProxyEnv, withAuthProxy } from "./provider-proxy.js";
|
|
32
32
|
import { fetchRemoteModels, KNOWN_APIS } from "./providers.js";
|
|
@@ -441,6 +441,24 @@ export async function createPiSession(creation) {
|
|
|
441
441
|
...(creation.thinkingLevel ? { thinkingLevel: creation.thinkingLevel } : {}),
|
|
442
442
|
};
|
|
443
443
|
const { session } = await sdk.createAgentSession(options);
|
|
444
|
+
if (creation.refreshResources) {
|
|
445
|
+
// A new loader's first pass may reuse cached extension factories for the same cwd.
|
|
446
|
+
// Pi's public reload performs shutdown cleanup and invalidates that cache on its second pass.
|
|
447
|
+
// Keep both factory passes in the same isolated credential environment.
|
|
448
|
+
const reload = session.reload;
|
|
449
|
+
try {
|
|
450
|
+
if (!reload)
|
|
451
|
+
throw new Error("当前 Pi SDK 不支持资源重新加载,请升级运行时。");
|
|
452
|
+
await withIsolatedSessionEnv({ ...creation.extensionEnv, ...nativeToolEnv(creation.sessionDir, nativePolicy), SUPER_PI_NATIVE_AGENT_DIR: agentDir }, () => reload.call(session));
|
|
453
|
+
const problems = loader.getExtensions?.().errors ?? [];
|
|
454
|
+
if (problems.length)
|
|
455
|
+
throw new Error(`资源重新加载失败:${problems.map(problem => `${basename(problem.path)}: ${problem.error}`).join(";")}`);
|
|
456
|
+
}
|
|
457
|
+
catch (error) {
|
|
458
|
+
session.dispose();
|
|
459
|
+
throw error;
|
|
460
|
+
}
|
|
461
|
+
}
|
|
444
462
|
traceSession(creation.sessionId, "sdk.session.created", startedAt);
|
|
445
463
|
const live = session;
|
|
446
464
|
// THE WHOLE MODEL, LOOKED UP THE WAY PI LOOKS IT UP. Pi's `setModel` puts the model it is given
|
package/dist/server/runtime.d.ts
CHANGED
|
@@ -304,6 +304,7 @@ export interface AgentRuntime {
|
|
|
304
304
|
cacheWarmingSettings?(): Promise<PiCacheWarmingSettings>;
|
|
305
305
|
setCacheWarming?(mode: PiCacheWarmingMode): Promise<PiCacheWarmingSettings>;
|
|
306
306
|
reloadNativeTools?(): void;
|
|
307
|
+
reloadConversation?(conversation: Conversation, cwd: string): Promise<string | undefined>;
|
|
307
308
|
stop?(conversationId: string): Promise<void>;
|
|
308
309
|
/**
|
|
309
310
|
* Hands one message to the Pi process that is running RIGHT NOW, to be injected at its next turn
|
|
@@ -878,6 +879,7 @@ export declare class PiRpcRuntime implements AgentRuntime {
|
|
|
878
879
|
* the old context in memory would keep answering from history the user has withdrawn.
|
|
879
880
|
*/
|
|
880
881
|
disposeSessions(conversationId?: string): Promise<void>;
|
|
882
|
+
reloadConversation(conversation: Conversation, cwd: string): Promise<string | undefined>;
|
|
881
883
|
compactContext(input: Pick<AnswerInput, "conversation" | "cwd" | "signal" | "onCompaction" | "onUsage" | "onSessionFile">): Promise<void>;
|
|
882
884
|
private compactRpcContext;
|
|
883
885
|
cacheWarmingSettings(): Promise<PiCacheWarmingSettings>;
|
package/dist/server/runtime.js
CHANGED
|
@@ -597,6 +597,19 @@ export class PiRpcRuntime {
|
|
|
597
597
|
await this.sessionPool.disposeAll();
|
|
598
598
|
await this.backgroundUsageWrites;
|
|
599
599
|
}
|
|
600
|
+
async reloadConversation(conversation, cwd) {
|
|
601
|
+
// Rebuild through the normal factory to refresh permissions, resources and isolated credentials.
|
|
602
|
+
// The current transcript survives; no prompt or model request is made during this operation.
|
|
603
|
+
const file = this.sessionPool.get(conversation.id)?.sessionFile ?? conversation.piSessionFile;
|
|
604
|
+
await this.disposeSessions(conversation.id);
|
|
605
|
+
if (this.sessionMode !== "sdk")
|
|
606
|
+
return file;
|
|
607
|
+
const configuration = await this.sessionConfiguration(conversation, cwd);
|
|
608
|
+
const session = await this.sessionPool.acquire({ ...configuration, refreshResources: true, conversationId: conversation.id,
|
|
609
|
+
cwd: resolve(cwd), agentId: conversation.agentId ?? null, ...(file ? { sessionFile: file } : {}) });
|
|
610
|
+
this.builtSessions.set(conversation.id, configuration);
|
|
611
|
+
return session.sessionFile;
|
|
612
|
+
}
|
|
600
613
|
async compactContext(input) {
|
|
601
614
|
if (this.sessionMode !== "sdk")
|
|
602
615
|
return this.compactRpcContext(input);
|
|
@@ -33,7 +33,7 @@ export function formatTurnFailure(error) {
|
|
|
33
33
|
const raw = error instanceof Error ? error.message : typeof error === "string" ? error : "";
|
|
34
34
|
if (/^上下文(?:自动)?压缩失败/.test(raw))
|
|
35
35
|
return raw;
|
|
36
|
-
if (/^(
|
|
36
|
+
if (/^(本地模型通道|模型通道|入口模型)/.test(raw))
|
|
37
37
|
return raw;
|
|
38
38
|
const lower = raw.toLowerCase();
|
|
39
39
|
// PROVIDER QUOTA / RATE LIMIT - the only reason the user is in this branch is because Pi was
|
package/dist/server/types.d.ts
CHANGED
|
@@ -1692,6 +1692,9 @@ export type ClientCommandBody =
|
|
|
1692
1692
|
} | {
|
|
1693
1693
|
type: "conversation.compact";
|
|
1694
1694
|
conversationId: string;
|
|
1695
|
+
} | {
|
|
1696
|
+
type: "conversation.reload";
|
|
1697
|
+
conversationId: string;
|
|
1695
1698
|
} | {
|
|
1696
1699
|
type: "conversation.compact.cancel";
|
|
1697
1700
|
conversationId: string;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** Workbench commands share the same UI actions; they are never model prompts. */
|
|
2
|
+
export declare const BUILTIN_SLASH_COMMANDS: readonly [readonly ["help", "打开使用指南"], readonly ["model", "打开模型选择器"], readonly ["settings", "打开设置"], readonly ["clear", "新建空白会话,保留原历史"], readonly ["compact", "压缩上下文并显示进度"], readonly ["reload", "重新加载 Agent、技能和扩展,无需重启服务"], readonly ["new", "在当前目录新建会话"], readonly ["fork", "从当前上下文分叉会话"], readonly ["resume", "打开会话列表"], readonly ["stop", "停止当前任务"], readonly ["start", "在浏览器打开 Super Pi"], readonly ["restart", "重启服务(需要确认)"], readonly ["update", "打开软件更新面板"]];
|
|
3
|
+
export declare function parseBuiltinSlashCommand(text: string): {
|
|
4
|
+
id: typeof BUILTIN_SLASH_COMMANDS[number][0];
|
|
5
|
+
args: string;
|
|
6
|
+
} | undefined;
|
|
7
|
+
export declare function builtinSlashHint(text: string): string | undefined;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/** Workbench commands share the same UI actions; they are never model prompts. */
|
|
2
|
+
export const BUILTIN_SLASH_COMMANDS = [
|
|
3
|
+
["help", "打开使用指南"], ["model", "打开模型选择器"], ["settings", "打开设置"],
|
|
4
|
+
["clear", "新建空白会话,保留原历史"], ["compact", "压缩上下文并显示进度"],
|
|
5
|
+
["reload", "重新加载 Agent、技能和扩展,无需重启服务"], ["new", "在当前目录新建会话"],
|
|
6
|
+
["fork", "从当前上下文分叉会话"], ["resume", "打开会话列表"], ["stop", "停止当前任务"],
|
|
7
|
+
["start", "在浏览器打开 Super Pi"], ["restart", "重启服务(需要确认)"], ["update", "打开软件更新面板"],
|
|
8
|
+
];
|
|
9
|
+
export function parseBuiltinSlashCommand(text) {
|
|
10
|
+
const match = /^\/([\w-]+)(?:\s+([\s\S]*))?$/.exec(text.trim());
|
|
11
|
+
const entry = match && BUILTIN_SLASH_COMMANDS.find(([id]) => id === match[1]);
|
|
12
|
+
return entry ? { id: entry[0], args: match[2]?.trim() ?? "" } : undefined;
|
|
13
|
+
}
|
|
14
|
+
export function builtinSlashHint(text) {
|
|
15
|
+
const command = parseBuiltinSlashCommand(text);
|
|
16
|
+
const entry = command && BUILTIN_SLASH_COMMANDS.find(([id]) => id === command.id);
|
|
17
|
+
return entry?.[1];
|
|
18
|
+
}
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"superPi": {
|
|
4
4
|
"managedDirectListener": true
|
|
5
5
|
},
|
|
6
|
-
"version": "0.1.
|
|
6
|
+
"version": "0.1.290",
|
|
7
7
|
"description": "Web control plane and companion for Pi",
|
|
8
8
|
"license": "MIT",
|
|
9
9
|
"type": "module",
|
|
@@ -83,6 +83,7 @@
|
|
|
83
83
|
"scripts/desktop-runtime.test.mjs",
|
|
84
84
|
"scripts/managed-ssh.test.mjs",
|
|
85
85
|
"scripts/managed-model.test.mjs",
|
|
86
|
+
"scripts/managed-model-flow.test.mjs",
|
|
86
87
|
"scripts/multi-server.test.mjs",
|
|
87
88
|
"scripts/native-tools.test.mjs",
|
|
88
89
|
"scripts/markdown-syntax.test.mjs",
|
|
@@ -336,6 +337,7 @@
|
|
|
336
337
|
"scripts/session-reminder-pmo-rights.test.mjs"
|
|
337
338
|
],
|
|
338
339
|
"check:browser": [
|
|
340
|
+
"scripts/managed-model-errors-browser.test.mjs",
|
|
339
341
|
"scripts/git-panel-upgrade-browser.test.mjs",
|
|
340
342
|
"scripts/welcome-workspace-git-browser.test.mjs",
|
|
341
343
|
"scripts/editor-search-design-browser.test.mjs",
|