@evandu/super-pi 0.1.255 → 0.1.256
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/agents/super-pi-web/index.ts +1 -1
- package/dist/client/.super-pi-client-sources.json +7 -7
- package/dist/client/assets/{CodeMirrorEditor-CQQoIuoy.js → CodeMirrorEditor-DLrgnK0F.js} +1 -1
- package/dist/client/assets/{GitDiffEditor-BnROmsWz.js → GitDiffEditor-DkVFBAIL.js} +1 -1
- package/dist/client/assets/{index-BUlfbbqO.js → index-D4e52gDr.js} +16 -16
- package/dist/client/index.html +1 -1
- package/dist/server/runtime.js +38 -8
- package/dist/server/web.d.ts +2 -2
- package/dist/server/web.js +21 -12
- package/dist/shared/conversation-title.d.ts +4 -0
- package/dist/shared/conversation-title.js +4 -0
- package/package.json +1 -1
package/dist/client/index.html
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
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-D4e52gDr.js"></script>
|
|
12
12
|
<link rel="modulepreload" crossorigin href="/assets/rolldown-runtime-XKyaHtl9.js">
|
|
13
13
|
<link rel="stylesheet" crossorigin href="/assets/index-Bfm53ZYL.css">
|
|
14
14
|
</head>
|
package/dist/server/runtime.js
CHANGED
|
@@ -23,6 +23,7 @@ import { PiSessionPool, repositoryRootFrom } from "./pi-session-pool.js";
|
|
|
23
23
|
import { nativeToolArgs, nativeToolEnv, nativeToolPolicy, nativeToolSettingsPath, nativeToolExtensionPath, readNativeToolSettings } from "./native-tool-settings.js";
|
|
24
24
|
import { describeDeliveredUserMessage, describePiQueue, handleSessionEvent, TurnQueue } from "./pi-session-events.js";
|
|
25
25
|
import { LengthExceededError } from "./turn-failure.js";
|
|
26
|
+
import { CONVERSATION_TITLE_CONTEXT_MAX_CHARS, CONVERSATION_TITLE_TIMEOUT_MS } from "../shared/conversation-title.js";
|
|
26
27
|
// The queue/steer recognisers live in pi-session-events.ts, where the SESSION path's bridge can use
|
|
27
28
|
// them; the one-shot drain loop below reads the same records through the same two functions, so both
|
|
28
29
|
// paths recognise a delivery identically. Re-exported because they were part of this module's surface.
|
|
@@ -2540,33 +2541,62 @@ export class PiRpcRuntime {
|
|
|
2540
2541
|
async summarizeConversation(conversation, cwd, signal) {
|
|
2541
2542
|
if (!this.pi.found)
|
|
2542
2543
|
throw new Error(this.pi.reason);
|
|
2543
|
-
const TIMEOUT_MS =
|
|
2544
|
+
const TIMEOUT_MS = CONVERSATION_TITLE_TIMEOUT_MS;
|
|
2544
2545
|
// Session names live in a narrow sidebar row. Keep the model's budget well below the storage
|
|
2545
2546
|
// limit so the result remains a concise label instead of becoming a sentence.
|
|
2546
2547
|
const MAX_TITLE_CHARS = 18;
|
|
2547
2548
|
// A throwaway session id, not the conversation's: this child reads nothing else and its history must
|
|
2548
2549
|
// not be filed under the conversation whose title it is producing.
|
|
2549
|
-
|
|
2550
|
+
// The selected model is carried over, but the current conversation transcript and its live cache are
|
|
2551
|
+
// deliberately not: title generation is an isolated, bounded one-shot request.
|
|
2552
|
+
const selectedModel = conversation.model;
|
|
2553
|
+
const child = spawn(shellQuote(this.pi.command), ["--mode", "rpc", "--no-session", "--no-tools", "--no-extensions", "--no-mcp", "--no-skills", "--no-context-files", "--no-prompt-templates"], {
|
|
2550
2554
|
cwd: resolve(cwd),
|
|
2551
|
-
env: { ...process.env, ...await readProviderProxyEnv(defaultAgentDir()) },
|
|
2555
|
+
env: { ...process.env, ...await readProviderProxyEnv(defaultAgentDir(), selectedModel?.provider) },
|
|
2552
2556
|
stdio: ["pipe", "pipe", "pipe"],
|
|
2553
2557
|
shell: process.platform === "win32",
|
|
2554
2558
|
});
|
|
2555
2559
|
const channel = new RpcChannel(child);
|
|
2556
2560
|
const deadline = Date.now() + TIMEOUT_MS;
|
|
2557
2561
|
try {
|
|
2558
|
-
const
|
|
2562
|
+
const messages = conversation.messages
|
|
2559
2563
|
.filter(message => (message.role === "user" || message.role === "assistant" || message.source === "session-reminder") && message.content.trim())
|
|
2560
|
-
.map(message =>
|
|
2561
|
-
.
|
|
2564
|
+
.map(message => ({
|
|
2565
|
+
label: message.source === "session-reminder" ? "定时提醒" : message.role === "user" ? "User" : "Assistant",
|
|
2566
|
+
content: message.content.trim(),
|
|
2567
|
+
}));
|
|
2568
|
+
const firstUser = messages.find(message => message.label === "User");
|
|
2569
|
+
const recent = messages.slice(-10);
|
|
2570
|
+
const selected = firstUser && !recent.includes(firstUser) ? [firstUser, ...recent] : recent;
|
|
2571
|
+
const excerpts = selected.map(message => {
|
|
2572
|
+
const content = message.content.length > 1_500
|
|
2573
|
+
? `${message.content.slice(0, 1_100)}\n[…中间内容省略…]\n${message.content.slice(-300)}`
|
|
2574
|
+
: message.content;
|
|
2575
|
+
return `${message.label}: ${content}`;
|
|
2576
|
+
});
|
|
2577
|
+
let transcript = excerpts.join("\n\n");
|
|
2578
|
+
if (transcript.length > CONVERSATION_TITLE_CONTEXT_MAX_CHARS) {
|
|
2579
|
+
const headSize = 2_500;
|
|
2580
|
+
transcript = `${transcript.slice(0, headSize)}\n\n[…较早对话省略…]\n\n${transcript.slice(-(CONVERSATION_TITLE_CONTEXT_MAX_CHARS - headSize - 32))}`;
|
|
2581
|
+
}
|
|
2562
2582
|
if (!transcript)
|
|
2563
2583
|
throw new Error("这个会话还没有内容,无法据此生成标题");
|
|
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));
|
|
2586
|
+
if (modelResponse.success !== true)
|
|
2587
|
+
throw new Error(modelResponse.error || `Pi 无法使用当前会话模型 ${selectedModel.provider}/${selectedModel.modelId}`);
|
|
2588
|
+
}
|
|
2589
|
+
// Reasoning adds latency without improving a short session label. Keep this one-shot call fast
|
|
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));
|
|
2592
|
+
if (thinkingResponse.success !== true)
|
|
2593
|
+
throw new Error(thinkingResponse.error || "Pi 未能关闭标题生成的思考等级");
|
|
2564
2594
|
channel.write({
|
|
2565
2595
|
id: "autotitle_prompt",
|
|
2566
2596
|
type: "prompt",
|
|
2567
2597
|
message: [
|
|
2568
|
-
"
|
|
2569
|
-
"
|
|
2598
|
+
"为下面这段对话起一个简短标题,用作会话列表里的一行字。直接命名,不需要展开分析或推理。",
|
|
2599
|
+
"只输出标题本身:不要引号、句末标点、「标题:」前缀、解释或换行。",
|
|
2570
2600
|
`只生成一个简短的会话标签,长度严格不超过 ${MAX_TITLE_CHARS} 个字符(中文按一个字计数)。优先控制在 8-12 个字符;不要写成完整句子,不要使用副标题、解释、列表或多个候选标题。用与对话内容相同的语言。`,
|
|
2571
2601
|
"",
|
|
2572
2602
|
transcript,
|
package/dist/server/web.d.ts
CHANGED
|
@@ -13,8 +13,8 @@ export type WebFetchResult = {
|
|
|
13
13
|
truncated: boolean;
|
|
14
14
|
contentType: string;
|
|
15
15
|
};
|
|
16
|
-
/** Parse
|
|
17
|
-
export declare function
|
|
16
|
+
/** Parse DuckDuckGo Lite result rows and unwrap their destination URLs. */
|
|
17
|
+
export declare function parseDuckDuckGoResults(html: string, limit?: number): WebSearchResult[];
|
|
18
18
|
export declare class WebService {
|
|
19
19
|
search(query: string, limit?: number, signal?: AbortSignal): Promise<{
|
|
20
20
|
query: string;
|
package/dist/server/web.js
CHANGED
|
@@ -26,25 +26,35 @@ function plainText(html) {
|
|
|
26
26
|
return decodeEntities(html.replace(/<script\b[^>]*>[\s\S]*?<\/script>/gi, " ").replace(/<style\b[^>]*>[\s\S]*?<\/style>/gi, " ").replace(/<[^>]+>/g, " "))
|
|
27
27
|
.replace(/\s+/g, " ").trim();
|
|
28
28
|
}
|
|
29
|
-
/** Parse
|
|
30
|
-
export function
|
|
29
|
+
/** Parse DuckDuckGo Lite result rows and unwrap their destination URLs. */
|
|
30
|
+
export function parseDuckDuckGoResults(html, limit = 5) {
|
|
31
31
|
const results = [];
|
|
32
|
-
const
|
|
32
|
+
const starts = [...html.matchAll(/<a\b(?=[^>]*\bclass=["'][^"']*\bresult-link\b[^"']*["'])[^>]*>/gi)].map(match => match.index);
|
|
33
|
+
const blocks = starts.map((start, index) => html.slice(start, starts[index + 1] ?? html.length));
|
|
33
34
|
for (const block of blocks) {
|
|
34
|
-
const anchor = /<
|
|
35
|
+
const anchor = /<a\b(?=[^>]*\bclass=["'][^"']*\bresult-link\b[^"']*["'])[^>]*href=["']([^"']+)["'][^>]*>([\s\S]*?)<\/a>/i.exec(block);
|
|
35
36
|
if (!anchor)
|
|
36
37
|
continue;
|
|
37
38
|
let url;
|
|
38
39
|
try {
|
|
39
|
-
url = new URL(decodeEntities(anchor[1]));
|
|
40
|
+
url = new URL(decodeEntities(anchor[1]), "https://duckduckgo.com");
|
|
41
|
+
if (url.hostname === "duckduckgo.com" && url.pathname === "/l/") {
|
|
42
|
+
const destination = url.searchParams.get("uddg");
|
|
43
|
+
if (!destination)
|
|
44
|
+
continue;
|
|
45
|
+
url = new URL(destination);
|
|
46
|
+
}
|
|
40
47
|
}
|
|
41
48
|
catch {
|
|
42
49
|
continue;
|
|
43
50
|
}
|
|
44
|
-
if (!/^https?:$/.test(url.protocol))
|
|
51
|
+
if (!/^https?:$/.test(url.protocol) || url.username || url.password || /(^|\.)duckduckgo\.com$/i.test(url.hostname))
|
|
52
|
+
continue;
|
|
53
|
+
const cleanTitle = plainText(anchor[2]);
|
|
54
|
+
const caption = /<td\b[^>]*class=["'][^"']*\bresult-snippet\b[^"']*["'][^>]*>([\s\S]*?)<\/td>/i.exec(block)?.[1] ?? "";
|
|
55
|
+
if (!cleanTitle)
|
|
45
56
|
continue;
|
|
46
|
-
|
|
47
|
-
results.push({ title: plainText(anchor[2]), url: url.href, snippet: plainText(caption) });
|
|
57
|
+
results.push({ title: cleanTitle, url: url.href, snippet: plainText(caption) });
|
|
48
58
|
if (results.length >= Math.min(SEARCH_LIMIT, Math.max(1, limit)))
|
|
49
59
|
break;
|
|
50
60
|
}
|
|
@@ -158,12 +168,11 @@ export class WebService {
|
|
|
158
168
|
throw new Error("搜索词不能为空");
|
|
159
169
|
if (clean.length > 500)
|
|
160
170
|
throw new Error("搜索词不能超过 500 个字符");
|
|
161
|
-
const url = new URL("https://
|
|
171
|
+
const url = new URL("https://lite.duckduckgo.com/lite/");
|
|
162
172
|
url.searchParams.set("q", clean);
|
|
163
|
-
url.searchParams.set("
|
|
164
|
-
url.searchParams.set("setlang", "zh-Hans");
|
|
173
|
+
url.searchParams.set("kl", "us-en");
|
|
165
174
|
const response = await download(url.href, signal);
|
|
166
|
-
const results =
|
|
175
|
+
const results = parseDuckDuckGoResults(response.body.toString("utf8"), limit);
|
|
167
176
|
if (!results.length)
|
|
168
177
|
throw new Error("搜索引擎没有返回可解析的结果,可能暂时限流或页面格式已变化");
|
|
169
178
|
return { query: clean, results };
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/** Title generation is a short background operation; both ends use the same deadline plus a transport margin. */
|
|
2
|
+
export declare const CONVERSATION_TITLE_TIMEOUT_MS = 90000;
|
|
3
|
+
export declare const CONVERSATION_TITLE_CLIENT_TIMEOUT_MS: number;
|
|
4
|
+
export declare const CONVERSATION_TITLE_CONTEXT_MAX_CHARS = 12000;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/** Title generation is a short background operation; both ends use the same deadline plus a transport margin. */
|
|
2
|
+
export const CONVERSATION_TITLE_TIMEOUT_MS = 90_000;
|
|
3
|
+
export const CONVERSATION_TITLE_CLIENT_TIMEOUT_MS = CONVERSATION_TITLE_TIMEOUT_MS + 5_000;
|
|
4
|
+
export const CONVERSATION_TITLE_CONTEXT_MAX_CHARS = 12_000;
|