@evandu/super-pi 0.1.302 → 0.1.304
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-managed-model/index.ts +2 -0
- package/dist/.super-pi-check-inputs.json +2 -2
- package/dist/client/.super-pi-client-sources.json +23 -18
- package/dist/client/assets/CodeMirrorEditor-BgCUmuUG.js +2 -0
- package/dist/client/assets/GitDiffEditor-BT1PriQU.js +29 -0
- package/dist/client/assets/index-2PIw_FRw.css +1 -0
- package/dist/client/assets/index-BklBoCmG.js +355 -0
- package/dist/client/index.html +2 -2
- package/dist/server/application/catalog-service.js +2 -8
- package/dist/server/application/group-chat-service.js +13 -3
- package/dist/server/application/rsi-repairs.js +2 -2
- package/dist/server/application/rsi-service.js +13 -13
- package/dist/server/application/run-service.js +2 -0
- package/dist/server/explicit-file-open.d.ts +2 -0
- package/dist/server/explicit-file-open.js +3 -2
- package/dist/server/files.d.ts +4 -1
- package/dist/server/files.js +24 -8
- package/dist/server/http-server.js +5 -5
- package/dist/server/index.js +8 -2
- package/dist/server/managed-helper-model.d.ts +11 -0
- package/dist/server/managed-helper-model.js +58 -0
- package/dist/server/managed-model-adapter.js +4 -1
- package/dist/server/model-filter.d.ts +15 -0
- package/dist/server/model-filter.js +24 -0
- package/dist/server/pi-session.js +1 -1
- package/dist/server/rsi-http.js +11 -1
- package/dist/server/runtime.d.ts +1 -0
- package/dist/server/runtime.js +48 -4
- package/dist/server/store.d.ts +1 -0
- package/dist/server/store.js +7 -0
- package/dist/server/types.d.ts +1 -0
- package/dist/shared/rsi.d.ts +7 -2
- package/package.json +4 -1
- package/dist/client/assets/CodeMirrorEditor-BeVgHVpR.js +0 -2
- package/dist/client/assets/GitDiffEditor-D3hvVjdf.js +0 -29
- package/dist/client/assets/index-BAq4p4ug.js +0 -354
- package/dist/client/assets/index-BzYJAyfI.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-BklBoCmG.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-2PIw_FRw.css">
|
|
14
14
|
</head>
|
|
15
15
|
<body>
|
|
16
16
|
<div id="root"></div>
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { allowedCatalog } from "../model-filter.js";
|
|
2
2
|
import { readAgents, resolveAgentDirectories } from "../agents.js";
|
|
3
3
|
import { loadPromptTemplateSummaries } from "../pi-session.js";
|
|
4
4
|
function summarize(agent) {
|
|
@@ -80,13 +80,7 @@ export class CatalogService {
|
|
|
80
80
|
if (!workspace)
|
|
81
81
|
throw new Error("会话所属工作区不存在");
|
|
82
82
|
const rules = this.store.modelFilterRules();
|
|
83
|
-
return
|
|
84
|
-
assertModelAllowed(rules, workspace, model);
|
|
85
|
-
return true;
|
|
86
|
-
}
|
|
87
|
-
catch {
|
|
88
|
-
return false;
|
|
89
|
-
} }) };
|
|
83
|
+
return allowedCatalog(catalog, rules, workspace);
|
|
90
84
|
}
|
|
91
85
|
/**
|
|
92
86
|
* Broadcasts the model catalog to connected clients.
|
|
@@ -4,7 +4,7 @@ import { dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
|
4
4
|
import { createGitWorktree } from "../git.js";
|
|
5
5
|
import { DEFAULT_GROUP_MEMBER_IDS, groupTimeline } from "../../shared/group-chat.js";
|
|
6
6
|
import { CODING_STANDARD_REQUEST } from "../active-memory.js";
|
|
7
|
-
import { applicableRules, assertModelAllowed } from "../model-filter.js";
|
|
7
|
+
import { applicableRules, assertModelAllowed, resolveRsiModel } from "../model-filter.js";
|
|
8
8
|
import { replaceFile } from "../persistence/rename.js";
|
|
9
9
|
import { saveUpload, loadConversationImages, findUploadFile } from "../upload.js";
|
|
10
10
|
import { finishGroupExecution, GroupExecutionRecorder } from "./group-execution.js";
|
|
@@ -957,7 +957,16 @@ export class GroupChatService {
|
|
|
957
957
|
this.scheduleRsi(this.find(this.rooms, workspaceId, id), true);
|
|
958
958
|
return this.get(workspaceId, id);
|
|
959
959
|
}
|
|
960
|
-
if (body.action === "rsi.
|
|
960
|
+
if (body.action === "rsi.model") {
|
|
961
|
+
const model = await resolveRsiModel(body.model, this.store, workspaceId, this.runtime);
|
|
962
|
+
await this.edit(rooms => {
|
|
963
|
+
const room = this.activeRoom(rooms, workspaceId, id);
|
|
964
|
+
room.rsi ??= defaultGroupRsi();
|
|
965
|
+
room.rsi.model = model;
|
|
966
|
+
room.revision += 1;
|
|
967
|
+
});
|
|
968
|
+
}
|
|
969
|
+
else if (body.action === "rsi.configure") {
|
|
961
970
|
if (body.enabled !== undefined && typeof body.enabled !== "boolean")
|
|
962
971
|
throw new Error("RSI 启用设置无效");
|
|
963
972
|
if (body.automaticImprovements !== undefined && typeof body.automaticImprovements !== "boolean")
|
|
@@ -967,8 +976,9 @@ export class GroupChatService {
|
|
|
967
976
|
await this.edit(rooms => {
|
|
968
977
|
const room = this.activeRoom(rooms, workspaceId, id);
|
|
969
978
|
room.rsi ??= defaultGroupRsi();
|
|
979
|
+
if ("model" in body)
|
|
980
|
+
room.rsi.model = config.model;
|
|
970
981
|
room.rsi.enabled = body.enabled !== false;
|
|
971
|
-
room.rsi.model = config.model;
|
|
972
982
|
room.rsi.prompt = config.prompt;
|
|
973
983
|
room.rsi.sourceKey = undefined;
|
|
974
984
|
room.rsi.status = "idle";
|
|
@@ -74,10 +74,10 @@ export class RsiRepairs {
|
|
|
74
74
|
const messages = (conversation?.messages ?? []).filter(message => (message.role === "user" || message.role === "assistant") && message.id !== job.initialMessageId && !job.observationMessageIds?.includes(message.id)
|
|
75
75
|
&& !(message.role === "user" && message.content.startsWith("继续同一来源的综合 RSI 讨论。")));
|
|
76
76
|
const last = messages.at(-1);
|
|
77
|
-
return { ...structuredClone(job), busy: busy(conversation?.status),
|
|
77
|
+
return { ...structuredClone(job), model: conversation?.model, busy: busy(conversation?.status),
|
|
78
78
|
revision: last?.role === "assistant" && last.content.trim() ? last.id : undefined,
|
|
79
79
|
proposedPlan: last?.role === "assistant" ? last.content.slice(0, 16000) : undefined,
|
|
80
|
-
messages: messages.slice(-40).map(message => ({ id: message.id, role: message.role, content: message.id === job.executionMessageId ? `已授权实施:\n${job.approvedPlan}` : message.content.slice(0, 16000) })) };
|
|
80
|
+
messages: messages.slice(-40).map(message => ({ id: message.id, actualModel: message.actualModel, role: message.role, content: message.id === job.executionMessageId ? `已授权实施:\n${job.approvedPlan}` : message.content.slice(0, 16000) })) };
|
|
81
81
|
});
|
|
82
82
|
}
|
|
83
83
|
async action(source, body, report, context) {
|
|
@@ -4,7 +4,7 @@ import { join } from "node:path";
|
|
|
4
4
|
import { rsiKey } from "../../shared/rsi.js";
|
|
5
5
|
import { defaultGroupRsi, updateUnifiedObservation, parseRsiReport, rsiInput, rsiSourceKey, RSI_INSTRUCTIONS, rsiFailure } from "./group-rsi.js";
|
|
6
6
|
import { rsiEvidence } from "../rsi-evidence.js";
|
|
7
|
-
import { applicableRules, assertModelAllowed } from "../model-filter.js";
|
|
7
|
+
import { applicableRules, assertModelAllowed, resolveRsiModel } from "../model-filter.js";
|
|
8
8
|
import { resolveFileCwd } from "../session-cwd.js";
|
|
9
9
|
import { RsiRepairs } from "./rsi-repairs.js";
|
|
10
10
|
/** Observations never block foreground turns; implementation uses ordinary visible primary sessions. */
|
|
@@ -116,7 +116,10 @@ export class RsiService {
|
|
|
116
116
|
const key = this.source(source);
|
|
117
117
|
const improvements = this.data.improvements.filter(job => rsiKey(job.source) === key);
|
|
118
118
|
const slugs = new Set(improvements.map(job => job.slug));
|
|
119
|
-
return { state: groupState ?? this.state(source), improvements:
|
|
119
|
+
return { state: groupState ?? this.state(source), improvements: improvements.map(job => {
|
|
120
|
+
const conversation = job.conversationId ? this.store.conversation(job.conversationId) : undefined;
|
|
121
|
+
return { ...structuredClone(job), model: conversation?.model, actualModel: conversation?.messages?.slice().reverse().find(message => message.actualModel)?.actualModel };
|
|
122
|
+
}), repairs: this.repairs.list(source),
|
|
120
123
|
capabilities: this.tools.list().filter(tool => slugs.has(tool.slug)).map(({ slug, name, kind, version, applicability }) => ({ slug, name, kind, version, applicability })),
|
|
121
124
|
usage: this.tools.receipts().filter(item => slugs.has(item.slug)).map(({ slug, version, status, durationMs, at }) => ({ slug, version, status, durationMs, at })) };
|
|
122
125
|
}
|
|
@@ -212,6 +215,7 @@ export class RsiService {
|
|
|
212
215
|
const sourceKey = `${rsiSourceKey(room)}:${conversation.cwd ?? ""}`;
|
|
213
216
|
if (state.enabled === false || state.sourceKey === sourceKey || this.observing.has(key) || !room.messages.some(post => post.role === "assistant"))
|
|
214
217
|
return;
|
|
218
|
+
const model = state.model ?? conversation.model ?? this.store.workspace(source.workspaceId)?.defaultModel;
|
|
215
219
|
const controller = new AbortController();
|
|
216
220
|
this.observing.set(key, controller);
|
|
217
221
|
this.lastRun.set(key, Date.now());
|
|
@@ -227,7 +231,7 @@ export class RsiService {
|
|
|
227
231
|
if (!agent || !this.runtime.askOnce)
|
|
228
232
|
throw new Error("RSI 观察员不可用。");
|
|
229
233
|
const coverage = rsiInput(room, room.executions, 42000);
|
|
230
|
-
|
|
234
|
+
let observedModel;
|
|
231
235
|
const workspace = this.store.workspace(source.workspaceId);
|
|
232
236
|
const cwd = await resolveFileCwd(workspace.path, conversation.cwd);
|
|
233
237
|
const rules = this.store.modelFilterRules?.() ?? [];
|
|
@@ -236,13 +240,14 @@ export class RsiService {
|
|
|
236
240
|
const artifactReads = [];
|
|
237
241
|
let calls = 0;
|
|
238
242
|
const report = parseRsiReport(await this.runtime.askOnce({ agent, model, cwd, signal: controller.signal, timeoutMs: 90000, finalResponseOnly: true,
|
|
243
|
+
onModel: actual => { observedModel = actual; },
|
|
239
244
|
onToolStart: () => { if (++calls > 12)
|
|
240
245
|
controller.abort(); },
|
|
241
246
|
onExecution: event => { if (event.kind === "tool" && event.phase === "end" && event.call.name === "read" && event.call.status === "ok" && event.call.detail)
|
|
242
247
|
artifactReads.push(event.call.detail); },
|
|
243
248
|
prompt: `${RSI_INSTRUCTIONS}\n这是普通 session 的实际任务过程。不要假设存在群聊或成员分工。runEvidence 是运行槽的真实总用时,含工具与等待用户,不是纯模型耗时;不能从相邻消息间隔推断思考耗时。仅凭文字不能证明产物的视觉或事实质量。\n${state.prompt}\n${JSON.stringify({ discussion: this.discussionContext(source), previous: [...(state.archivedReports ?? []), ...state.reports].slice(-8), runEvidence: this.data.timings?.[key]?.slice(-3), userCapabilities: this.tools.list().map(({ slug, kind, version, applicability }) => ({ slug, kind, version, applicability })), coverage, messages: coverage.records })}` }), room, coverage);
|
|
244
249
|
controller.signal.throwIfAborted();
|
|
245
|
-
report.model =
|
|
250
|
+
report.model = observedModel;
|
|
246
251
|
updateUnifiedObservation(state, report);
|
|
247
252
|
state.status = "completed";
|
|
248
253
|
state.sourceKey = sourceKey;
|
|
@@ -415,18 +420,13 @@ export class RsiService {
|
|
|
415
420
|
this.schedule(source, true);
|
|
416
421
|
}
|
|
417
422
|
}
|
|
423
|
+
else if (body.action === "rsi.model")
|
|
424
|
+
state.model = await resolveRsiModel(body.model, this.store, source.workspaceId, this.runtime);
|
|
418
425
|
else if (body.action === "rsi.configure") {
|
|
419
426
|
if (body.enabled !== undefined && typeof body.enabled !== "boolean" || body.automaticImprovements !== undefined && typeof body.automaticImprovements !== "boolean")
|
|
420
427
|
throw new Error("RSI 开关无效。");
|
|
421
|
-
if (body
|
|
422
|
-
|
|
423
|
-
const selected = catalog.models.find(model => model.provider === body.model.provider && model.modelId === body.model.modelId);
|
|
424
|
-
if (!selected)
|
|
425
|
-
throw new Error("RSI 模型不可用。");
|
|
426
|
-
state.model = selected;
|
|
427
|
-
}
|
|
428
|
-
else
|
|
429
|
-
state.model = undefined;
|
|
428
|
+
if ("model" in body)
|
|
429
|
+
state.model = await resolveRsiModel(body.model, this.store, source.workspaceId, this.runtime);
|
|
430
430
|
state.enabled = body.enabled !== false;
|
|
431
431
|
state.automaticImprovements = body.automaticImprovements === true;
|
|
432
432
|
state.automaticImprovementsAuthorized = state.automaticImprovements;
|
|
@@ -1694,6 +1694,8 @@ export class RunService {
|
|
|
1694
1694
|
onModel: async (model) => {
|
|
1695
1695
|
if (!acceptsEvent("model", true))
|
|
1696
1696
|
return;
|
|
1697
|
+
if (["rsi-discussion", "rsi-repair", "rsi-builder"].includes(conversation.agentId ?? ""))
|
|
1698
|
+
await this.store.recordMessageModel(conversation.id, assistant.id, model);
|
|
1697
1699
|
for (const observer of this.modelObservers.get(conversation.id) ?? [])
|
|
1698
1700
|
await observer(model);
|
|
1699
1701
|
},
|
|
@@ -4,6 +4,7 @@ export declare function createExplicitFileOpen(): {
|
|
|
4
4
|
text: boolean;
|
|
5
5
|
path: string;
|
|
6
6
|
name: string;
|
|
7
|
+
writeTargetId?: string | undefined;
|
|
7
8
|
} | {
|
|
8
9
|
content: string;
|
|
9
10
|
eol: "\n" | "\r\n";
|
|
@@ -12,6 +13,7 @@ export declare function createExplicitFileOpen(): {
|
|
|
12
13
|
text: boolean;
|
|
13
14
|
path: string;
|
|
14
15
|
name: string;
|
|
16
|
+
writeTargetId?: string | undefined;
|
|
15
17
|
} | {
|
|
16
18
|
meta: import("./files.js").FileMeta;
|
|
17
19
|
text: boolean;
|
|
@@ -2,7 +2,7 @@ import { randomUUID } from "node:crypto";
|
|
|
2
2
|
import { constants } from "node:fs";
|
|
3
3
|
import { lstat, open, realpath } from "node:fs/promises";
|
|
4
4
|
import { basename, isAbsolute, posix, resolve } from "node:path";
|
|
5
|
-
import { contains, decodeWorkspaceText, fileMetaFromStat, FilesError, hasBinaryExtension, MAX_FILE_BYTES, toRelative } from "./files.js";
|
|
5
|
+
import { contains, decodeWorkspaceText, fileMetaFromStat, FilesError, hasBinaryExtension, MAX_FILE_BYTES, toRelative, writeTargetId } from "./files.js";
|
|
6
6
|
import { explorerInternalPath, explorerPath } from "./workspace-file-operations.js";
|
|
7
7
|
const MAX_OPEN_TICKETS = 256;
|
|
8
8
|
function localAbsolute(path) {
|
|
@@ -76,7 +76,8 @@ export function createExplicitFileOpen() {
|
|
|
76
76
|
const scoped = toRelative(canonicalRoot, path);
|
|
77
77
|
await explorerPath(workspace, root, scoped);
|
|
78
78
|
const displayPath = contains(resolve(root), selected) ? toRelative(root, selected) : scoped;
|
|
79
|
-
|
|
79
|
+
const contents = await readOpenedFile(path);
|
|
80
|
+
return { path: displayPath, name: basename(selected), ...contents, ...(contents.text ? { writeTargetId: await writeTargetId(resolve(root, displayPath)) } : {}) };
|
|
80
81
|
}
|
|
81
82
|
const contents = await readOpenedFile(path);
|
|
82
83
|
const ticket = randomUUID();
|
package/dist/server/files.d.ts
CHANGED
|
@@ -77,6 +77,8 @@ export declare function resolveInsideRoot(root: string, requested: string | null
|
|
|
77
77
|
* user has been told it is safe to save.
|
|
78
78
|
*/
|
|
79
79
|
export declare function fileEtag(path: string): Promise<string>;
|
|
80
|
+
/** Identify the directory entry atomically replaced by a save, preserving a final symlink's name. */
|
|
81
|
+
export declare function writeTargetId(target: string): Promise<string>;
|
|
80
82
|
export type FileMeta = {
|
|
81
83
|
etag: string;
|
|
82
84
|
size: number;
|
|
@@ -208,6 +210,7 @@ export type SearchResult = {
|
|
|
208
210
|
*/
|
|
209
211
|
export declare function searchByName(root: string, query: string): Promise<SearchResult>;
|
|
210
212
|
export type FileContents = {
|
|
213
|
+
writeTargetId: string;
|
|
211
214
|
path: string;
|
|
212
215
|
content: string;
|
|
213
216
|
meta: FileMeta;
|
|
@@ -256,7 +259,7 @@ export type WriteOutcome = {
|
|
|
256
259
|
* is derived from the target's OWN name rather than living in the system temp directory, because a rename
|
|
257
260
|
* across filesystems is not atomic and would silently become a copy.
|
|
258
261
|
*/
|
|
259
|
-
export declare function writeWorkspaceFile(root: string, requested: string, content: string, baseEtag: string | null | undefined): Promise<WriteOutcome>;
|
|
262
|
+
export declare function writeWorkspaceFile(root: string, requested: string, content: string, baseEtag: string | null | undefined, baseTargetId?: string): Promise<WriteOutcome>;
|
|
260
263
|
/** Every `FilesError` carries the status it should be rendered with; anything else is a real fault and
|
|
261
264
|
* becomes a 500 rather than being dressed up as a refusal the user is asked to understand. */
|
|
262
265
|
export declare function describe(error: unknown): {
|
package/dist/server/files.js
CHANGED
|
@@ -311,6 +311,12 @@ export function resolveInsideRoot(root, requested) {
|
|
|
311
311
|
export async function fileEtag(path) {
|
|
312
312
|
return fileMetaFromStat(await stat(path, { bigint: true })).etag;
|
|
313
313
|
}
|
|
314
|
+
/** Identify the directory entry atomically replaced by a save, preserving a final symlink's name. */
|
|
315
|
+
export async function writeTargetId(target) {
|
|
316
|
+
const parent = await realpath(dirname(target));
|
|
317
|
+
const key = join(parent, basename(target));
|
|
318
|
+
return createHash("sha256").update("write-target-v1\0" + key).digest("hex");
|
|
319
|
+
}
|
|
314
320
|
export async function fileMeta(path) {
|
|
315
321
|
return fileMetaFromStat(await stat(path, { bigint: true }));
|
|
316
322
|
}
|
|
@@ -608,7 +614,7 @@ export async function readWorkspaceFile(root, requested) {
|
|
|
608
614
|
if (meta.size > MAX_FILE_BYTES) {
|
|
609
615
|
throw new FilesError(413, `文件过大(${(meta.size / 1024 / 1024).toFixed(1)}MB),上限 ${MAX_FILE_BYTES / 1024 / 1024}MB:${requested}`, "too_large");
|
|
610
616
|
}
|
|
611
|
-
return { path: toRelative(root, target), meta, ...decodeWorkspaceText(await readFile(target), requested) };
|
|
617
|
+
return { path: toRelative(root, target), meta, ...decodeWorkspaceText(await readFile(target), requested), writeTargetId: await writeTargetId(target) };
|
|
612
618
|
}
|
|
613
619
|
export function decodeWorkspaceText(raw, requested) {
|
|
614
620
|
if (looksBinary(raw))
|
|
@@ -650,13 +656,23 @@ const writeLocks = new Map();
|
|
|
650
656
|
* is derived from the target's OWN name rather than living in the system temp directory, because a rename
|
|
651
657
|
* across filesystems is not atomic and would silently become a copy.
|
|
652
658
|
*/
|
|
653
|
-
export async function writeWorkspaceFile(root, requested, content, baseEtag) {
|
|
654
|
-
const
|
|
655
|
-
const
|
|
659
|
+
export async function writeWorkspaceFile(root, requested, content, baseEtag, baseTargetId) {
|
|
660
|
+
const logicalTarget = await resolveInsideRoot(root, requested);
|
|
661
|
+
const parent = await realpath(dirname(logicalTarget)).catch((error) => {
|
|
662
|
+
if (error.code === "ENOENT" || error.code === "ENOTDIR")
|
|
663
|
+
throw new FilesError(428, `文件不存在,本面板只允许写入已存在的文件:${requested}`, "missing_target");
|
|
664
|
+
throw error;
|
|
665
|
+
});
|
|
666
|
+
const target = join(parent, basename(logicalTarget));
|
|
667
|
+
if (baseTargetId && await writeTargetId(target) !== baseTargetId)
|
|
668
|
+
throw new FilesError(409, "文件指向的保存目标已变化,未写入;原草稿已保留", "target_changed");
|
|
669
|
+
// A directory mutex also serializes case aliases without merging distinct case-sensitive entries.
|
|
670
|
+
const writeKey = parent;
|
|
671
|
+
const previous = writeLocks.get(writeKey) ?? Promise.resolve();
|
|
656
672
|
let release;
|
|
657
673
|
const currentLock = new Promise((resolve) => { release = resolve; });
|
|
658
674
|
const queued = previous.then(() => currentLock);
|
|
659
|
-
writeLocks.set(
|
|
675
|
+
writeLocks.set(writeKey, queued);
|
|
660
676
|
await previous;
|
|
661
677
|
try {
|
|
662
678
|
const info = await stat(target).catch((error) => {
|
|
@@ -720,10 +736,10 @@ export async function writeWorkspaceFile(root, requested, content, baseEtag) {
|
|
|
720
736
|
finally {
|
|
721
737
|
await import("node:fs/promises").then(({ rm }) => rm(temporary, { recursive: true, force: true })).catch(() => { });
|
|
722
738
|
release();
|
|
723
|
-
if (writeLocks.get(
|
|
724
|
-
writeLocks.delete(
|
|
739
|
+
if (writeLocks.get(writeKey) === queued)
|
|
740
|
+
writeLocks.delete(writeKey);
|
|
725
741
|
}
|
|
726
|
-
return { path: toRelative(root,
|
|
742
|
+
return { path: toRelative(root, logicalTarget), meta: await fileMeta(target), created: false };
|
|
727
743
|
}
|
|
728
744
|
catch (error) {
|
|
729
745
|
release();
|
|
@@ -2002,7 +2002,7 @@ export function createHttpServer(options) {
|
|
|
2002
2002
|
const editSession = checkout?.path ?? sessionRoot;
|
|
2003
2003
|
await explorerPath(editRoot, editSession, body.path, true);
|
|
2004
2004
|
const path = await workspacePathFromSession(editRoot, editSession, body.path);
|
|
2005
|
-
const saved = await serializeWorkspaceWrite(workspace.path, () => writeWorkspaceFile(editRoot, path, body.content, body.baseEtag));
|
|
2005
|
+
const saved = await serializeWorkspaceWrite(workspace.path, () => writeWorkspaceFile(editRoot, path, body.content, body.baseEtag, typeof body.baseTargetId === "string" ? body.baseTargetId : undefined));
|
|
2006
2006
|
broadcaster.broadcast({ type: "files.invalidated", workspaceId: workspace.id, paths: checkout ? [] : [path] });
|
|
2007
2007
|
json(200, saved);
|
|
2008
2008
|
return;
|
|
@@ -2104,7 +2104,7 @@ export function createHttpServer(options) {
|
|
|
2104
2104
|
gitIndexFileContent(editRoot, path),
|
|
2105
2105
|
readWorkspaceFile(editRoot, path),
|
|
2106
2106
|
]);
|
|
2107
|
-
json(200, { path: file.path, original, content: file.content, eol: file.eol, bom: file.bom, meta: file.meta });
|
|
2107
|
+
json(200, { path: file.path, original, content: file.content, eol: file.eol, bom: file.bom, meta: file.meta, writeTargetId: file.writeTargetId });
|
|
2108
2108
|
}
|
|
2109
2109
|
else if (op === "diff") {
|
|
2110
2110
|
const path = url.searchParams.get("path");
|
|
@@ -3782,12 +3782,12 @@ export function createHttpServer(options) {
|
|
|
3782
3782
|
const meta = await fileMeta(resolved);
|
|
3783
3783
|
const path = toRelative(root, resolved);
|
|
3784
3784
|
context.fileIndexes?.get(indexKey)?.recordFile(path, meta);
|
|
3785
|
-
json(200, { path, ...meta });
|
|
3785
|
+
json(200, { path, ...meta, writeTargetId: await import("./files.js").then(files => files.writeTargetId(resolved)) });
|
|
3786
3786
|
return;
|
|
3787
3787
|
}
|
|
3788
3788
|
const file = await readWorkspaceFile(root, rel);
|
|
3789
3789
|
context.fileIndexes?.get(indexKey)?.recordFile(file.path, file.meta);
|
|
3790
|
-
json(200, { path: file.path, content: file.content, eol: file.eol, bom: file.bom, meta: file.meta, maxBytes: MAX_FILE_BYTES });
|
|
3790
|
+
json(200, { path: file.path, content: file.content, eol: file.eol, bom: file.bom, meta: file.meta, maxBytes: MAX_FILE_BYTES, writeTargetId: file.writeTargetId });
|
|
3791
3791
|
return;
|
|
3792
3792
|
}
|
|
3793
3793
|
if (request.method === "PUT") {
|
|
@@ -3824,7 +3824,7 @@ export function createHttpServer(options) {
|
|
|
3824
3824
|
const { path, content, baseEtag } = parsed;
|
|
3825
3825
|
const outcome = await serializeWorkspaceWrite(workspace.path, async () => {
|
|
3826
3826
|
await explorerPath(workspace.path, root, path, true);
|
|
3827
|
-
const saved = await writeWorkspaceFile(root, path, content, baseEtag);
|
|
3827
|
+
const saved = await writeWorkspaceFile(root, path, content, baseEtag, typeof parsed.baseTargetId === "string" ? parsed.baseTargetId : undefined);
|
|
3828
3828
|
const changedPath = await workspacePathFromSession(workspace.path, root, saved.path);
|
|
3829
3829
|
context.fileIndexes?.get(indexKey)?.recordFile(saved.path, saved.meta);
|
|
3830
3830
|
refreshWorkspaceIndex(context.fileIndexes, workspaceId, changedPath, workspace.path);
|
package/dist/server/index.js
CHANGED
|
@@ -379,6 +379,12 @@ async function queueRsiConversation(id, prompt) {
|
|
|
379
379
|
});
|
|
380
380
|
});
|
|
381
381
|
}
|
|
382
|
+
function initialRsiModel(source) {
|
|
383
|
+
if (source.kind === "session")
|
|
384
|
+
return rsiService.state(source).model ?? store.conversation(source.id)?.model;
|
|
385
|
+
const room = groupChatService.get(source.workspaceId, source.id);
|
|
386
|
+
return room.rsi?.model ?? room.moderator.model;
|
|
387
|
+
}
|
|
382
388
|
const rsiService = await RsiService.open(join(dataDir, "rsi"), store, runtime, userTools, {
|
|
383
389
|
repairs: {
|
|
384
390
|
async discuss(source, title, prompt) {
|
|
@@ -386,7 +392,7 @@ const rsiService = await RsiService.open(join(dataDir, "rsi"), store, runtime, u
|
|
|
386
392
|
const id = await conversationService.createConversation(source.workspaceId, { origin: "orchestrator", separateMemoryTree: true }, original?.cwd);
|
|
387
393
|
await store.setConversationAgent(id, "rsi-discussion");
|
|
388
394
|
await store.renameConversation(id, title);
|
|
389
|
-
const model =
|
|
395
|
+
const model = initialRsiModel(source);
|
|
390
396
|
if (model)
|
|
391
397
|
await conversationService.setModel(id, model.provider, model.modelId);
|
|
392
398
|
const catalog = await runtime.catalog(store.conversation(id)?.model);
|
|
@@ -406,7 +412,7 @@ const rsiService = await RsiService.open(join(dataDir, "rsi"), store, runtime, u
|
|
|
406
412
|
const id = await conversationService.createConversation(source.workspaceId, source.kind === "session" ? { parentConversationId: source.id, origin: "orchestrator", separateMemoryTree: true } : { origin: "orchestrator", separateMemoryTree: true }, original?.cwd);
|
|
407
413
|
await store.setConversationAgent(id, "rsi-builder");
|
|
408
414
|
await store.renameConversation(id, title);
|
|
409
|
-
const model =
|
|
415
|
+
const model = initialRsiModel(source);
|
|
410
416
|
if (model)
|
|
411
417
|
await conversationService.setModel(id, model.provider, model.modelId);
|
|
412
418
|
const catalog = await runtime.catalog(store.conversation(id)?.model);
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import type { ManagedModelConfig } from "./managed-model-adapter.js";
|
|
3
|
+
type Context = Pick<ExtensionContext, "model" | "modelRegistry" | "sessionManager" | "signal">;
|
|
4
|
+
/** Pi uses this sentinel when its initial availability snapshot did not contain a default. */
|
|
5
|
+
export declare function isUnresolvedModel(model: {
|
|
6
|
+
provider?: unknown;
|
|
7
|
+
id?: unknown;
|
|
8
|
+
} | undefined): boolean;
|
|
9
|
+
/** Repair startup before RPC input is attached, preserving the session's actual model precedence. */
|
|
10
|
+
export declare function initializeManagedHelperModel(config: ManagedModelConfig, pi: Pick<ExtensionAPI, "getSettings" | "setModel">, ctx: Context, timeoutMs?: number): Promise<void>;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { setTimeout as delay } from "node:timers/promises";
|
|
2
|
+
/** Pi uses this sentinel when its initial availability snapshot did not contain a default. */
|
|
3
|
+
export function isUnresolvedModel(model) {
|
|
4
|
+
return !model || !model.provider || !model.id || model.provider === "unknown" && model.id === "unknown";
|
|
5
|
+
}
|
|
6
|
+
// Read only the current branch. A virtual model selection survives the physical responses it routes.
|
|
7
|
+
function branchSelection(branch, registry) {
|
|
8
|
+
for (let i = branch.length - 1; i >= 0; i--) {
|
|
9
|
+
const entry = branch[i];
|
|
10
|
+
if (entry.type === "model_change")
|
|
11
|
+
return { provider: entry.provider, modelId: entry.modelId };
|
|
12
|
+
if (entry.type !== "message" || entry.message.role !== "assistant" || entry.message.api === "pi-virtual")
|
|
13
|
+
continue;
|
|
14
|
+
for (let j = i - 1; j >= 0; j--) {
|
|
15
|
+
const change = branch[j];
|
|
16
|
+
if (change.type !== "model_change")
|
|
17
|
+
continue;
|
|
18
|
+
if (registry.find(change.provider, change.modelId)?.api === "pi-virtual")
|
|
19
|
+
return { provider: change.provider, modelId: change.modelId };
|
|
20
|
+
break;
|
|
21
|
+
}
|
|
22
|
+
return { provider: entry.message.provider, modelId: entry.message.model };
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
/** Repair startup before RPC input is attached, preserving the session's actual model precedence. */
|
|
26
|
+
export async function initializeManagedHelperModel(config, pi, ctx, timeoutMs = 30_000) {
|
|
27
|
+
const unresolved = isUnresolvedModel(ctx.model);
|
|
28
|
+
let target;
|
|
29
|
+
if (!unresolved) {
|
|
30
|
+
target = { provider: ctx.model.provider, modelId: ctx.model.id };
|
|
31
|
+
// A real non-managed provider is Pi's decision, not a reason to select the entry's default.
|
|
32
|
+
if (!config.models.some(model => model.provider === target.provider && model.id === target.modelId))
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
target = branchSelection(ctx.sessionManager.getBranch(), ctx.modelRegistry);
|
|
37
|
+
const settings = pi.getSettings();
|
|
38
|
+
if (!target && settings.defaultProvider && settings.defaultModel)
|
|
39
|
+
target = { provider: settings.defaultProvider, modelId: settings.defaultModel };
|
|
40
|
+
target ??= config.defaultModel;
|
|
41
|
+
}
|
|
42
|
+
const model = target && ctx.modelRegistry.find(target.provider, target.modelId);
|
|
43
|
+
if (!model || isUnresolvedModel(model))
|
|
44
|
+
throw new Error("托管 Pi 未能恢复有效模型,请检查当前历史模型与默认模型配置;不会自动改用其他模型。");
|
|
45
|
+
const deadline = Date.now() + timeoutMs;
|
|
46
|
+
// registerNativeProvider starts a refresh without awaiting it. A later awaited refresh may be
|
|
47
|
+
// invalidated by that pass, so its completion alone does not prove the availability snapshot is ready.
|
|
48
|
+
while (!ctx.modelRegistry.getAvailable().some(item => item.provider === model.provider && item.id === model.id)) {
|
|
49
|
+
ctx.signal?.throwIfAborted();
|
|
50
|
+
const remaining = deadline - Date.now();
|
|
51
|
+
if (remaining <= 0)
|
|
52
|
+
throw new Error(`托管模型 ${model.provider}/${model.id} 的可用目录未在 ${timeoutMs / 1000} 秒内就绪,请重试或检查模型配置。`);
|
|
53
|
+
await delay(Math.min(25, remaining), undefined, { signal: ctx.signal });
|
|
54
|
+
}
|
|
55
|
+
ctx.signal?.throwIfAborted();
|
|
56
|
+
if (unresolved && !await pi.setModel(model))
|
|
57
|
+
throw new Error(`托管 Pi 无法选择已恢复的模型 ${model.provider}/${model.id},请检查模型目录初始化状态。`);
|
|
58
|
+
}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { readFile } from "node:fs/promises";
|
|
2
|
+
import { Agent } from "undici";
|
|
2
3
|
import { MODEL_OPTION_KEYS, MODEL_REQUEST_HEADER, ModelFlowTrace, modelRequestId } from "./managed-model-flow.js";
|
|
3
4
|
import { MODEL_STREAM_PROTOCOL, ModelWireDecoder } from "./managed-model-wire.js";
|
|
5
|
+
// This authenticated channel is restricted to loopback, independently of provider/global proxies.
|
|
6
|
+
const modelChannelDispatcher = new Agent();
|
|
4
7
|
export async function readManagedModelConfig() {
|
|
5
8
|
const path = process.env.SUPER_PI_MANAGED_CONFIG;
|
|
6
9
|
if (!path)
|
|
@@ -47,7 +50,7 @@ export async function managedProviderDefinitions(config) {
|
|
|
47
50
|
const latest = await readManagedModelConfig() ?? config;
|
|
48
51
|
const { signal, ...rest } = options ?? {};
|
|
49
52
|
const safeOptions = Object.fromEntries(Object.entries(rest).filter(([key, value]) => MODEL_OPTION_KEYS.includes(key) && typeof value !== "function"));
|
|
50
|
-
const response = await fetch(latest.endpoint, { method: "POST", signal, headers: { authorization: `Bearer ${latest.token}`, "content-type": "application/json", [MODEL_REQUEST_HEADER]: requestId }, body: JSON.stringify({ provider: model.provider, modelId: model.id, context, options: safeOptions, streamProtocol: MODEL_STREAM_PROTOCOL }) }).catch(cause => {
|
|
53
|
+
const response = await fetch(latest.endpoint, { method: "POST", signal, dispatcher: modelChannelDispatcher, headers: { authorization: `Bearer ${latest.token}`, "content-type": "application/json", [MODEL_REQUEST_HEADER]: requestId }, body: JSON.stringify({ provider: model.provider, modelId: model.id, context, options: safeOptions, streamProtocol: MODEL_STREAM_PROTOCOL }) }).catch(cause => {
|
|
51
54
|
if (signal?.aborted)
|
|
52
55
|
throw cause;
|
|
53
56
|
const detail = transportDetail(cause);
|
|
@@ -4,6 +4,21 @@ export declare function applicableRules(rules: ModelFilterRule[] | undefined, wo
|
|
|
4
4
|
modelRegex: RegExp;
|
|
5
5
|
}[];
|
|
6
6
|
export declare function assertModelAllowed(rules: ModelFilterRule[] | undefined, workspace: Workspace, model: ModelSelection | undefined): void;
|
|
7
|
+
export declare function allowedCatalog(catalog: import("./types.js").ModelCatalog, rules: ModelFilterRule[] | undefined, workspace: Workspace): {
|
|
8
|
+
source: "pi" | "unavailable";
|
|
9
|
+
levels: string[];
|
|
10
|
+
defaultModel?: ModelSelection;
|
|
11
|
+
defaultThinkingLevel?: string;
|
|
12
|
+
fetchedAt: string;
|
|
13
|
+
error?: string;
|
|
14
|
+
configError?: string;
|
|
15
|
+
models: import("./types.js").ModelOption[];
|
|
16
|
+
};
|
|
17
|
+
export declare function resolveRsiModel(input: unknown, store: Pick<import("./store.js").Store, "workspace" | "modelFilterRules">, workspaceId: string, runtime: Pick<import("./runtime.js").AgentRuntime, "catalog">): Promise<{
|
|
18
|
+
provider: string;
|
|
19
|
+
modelId: string;
|
|
20
|
+
label: string;
|
|
21
|
+
} | undefined>;
|
|
7
22
|
export declare function conversationWorkspace(state: AppState, conversationId: string): Workspace;
|
|
8
23
|
/** Resolve Pi's actual global default when no model was selected; never guess a permitted replacement. */
|
|
9
24
|
/**
|
|
@@ -22,6 +22,30 @@ export function assertModelAllowed(rules, workspace, model) {
|
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
|
+
export function allowedCatalog(catalog, rules, workspace) {
|
|
26
|
+
return { ...catalog, models: catalog.models.filter(model => { try {
|
|
27
|
+
assertModelAllowed(rules, workspace, model);
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
return false;
|
|
32
|
+
} }) };
|
|
33
|
+
}
|
|
34
|
+
export async function resolveRsiModel(input, store, workspaceId, runtime) {
|
|
35
|
+
if (input === null)
|
|
36
|
+
return undefined;
|
|
37
|
+
if (!input || typeof input !== "object" || !("provider" in input) || !("modelId" in input))
|
|
38
|
+
throw new Error("请选择有效的 RSI 模型。");
|
|
39
|
+
const catalog = await runtime.catalog();
|
|
40
|
+
const model = catalog.models.find(item => item.provider === input.provider && item.modelId === input.modelId);
|
|
41
|
+
if (!model)
|
|
42
|
+
throw new Error("RSI 模型不可用。");
|
|
43
|
+
const workspace = store.workspace(workspaceId);
|
|
44
|
+
if (!workspace)
|
|
45
|
+
throw new Error("工作区不存在。");
|
|
46
|
+
assertModelAllowed(store.modelFilterRules(), workspace, model);
|
|
47
|
+
return { provider: model.provider, modelId: model.modelId, label: model.label };
|
|
48
|
+
}
|
|
25
49
|
export function conversationWorkspace(state, conversationId) {
|
|
26
50
|
const conversation = state.conversations.find(item => item.id === conversationId);
|
|
27
51
|
const workspace = state.workspaces.find(item => item.id === conversation?.workspaceId);
|
|
@@ -234,7 +234,7 @@ async function resolveDefaultModel(sdk, options) {
|
|
|
234
234
|
});
|
|
235
235
|
session = created.session;
|
|
236
236
|
const model = session.model;
|
|
237
|
-
if (typeof model?.provider !== "string" || !model.provider || typeof model.id !== "string" || !model.id)
|
|
237
|
+
if (typeof model?.provider !== "string" || !model.provider || typeof model.id !== "string" || !model.id || model.provider === "unknown" && model.id === "unknown")
|
|
238
238
|
return undefined;
|
|
239
239
|
return { model: { provider: model.provider, modelId: model.id }, thinking: sessionThinking(session) };
|
|
240
240
|
}
|
package/dist/server/rsi-http.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { verifyCapability } from "./capability.js";
|
|
2
2
|
import { toolSelection } from "./agents.js";
|
|
3
|
+
import { allowedCatalog } from "./model-filter.js";
|
|
3
4
|
async function body(request, limit) {
|
|
4
5
|
const chunks = [];
|
|
5
6
|
let size = 0;
|
|
@@ -73,7 +74,16 @@ export async function handleRsiHttp(context, request, response, url) {
|
|
|
73
74
|
if (source.kind === "group" && !group)
|
|
74
75
|
throw new Error("群聊不存在。");
|
|
75
76
|
if (request.method === "GET") {
|
|
76
|
-
|
|
77
|
+
if (url.searchParams.get("view") === "models") {
|
|
78
|
+
context.rsiService.state(source);
|
|
79
|
+
const catalog = await context.runtime.catalog();
|
|
80
|
+
const workspace = context.store.workspace(source.workspaceId);
|
|
81
|
+
const { models } = allowedCatalog(catalog, context.store.modelFilterRules(), workspace);
|
|
82
|
+
const inherited = (group ? group.moderator.model : context.store.conversation(source.id)?.model) ?? workspace.defaultModel ?? catalog.defaultModel;
|
|
83
|
+
send(200, { inherited, models: models.map(({ provider, modelId, label }) => ({ provider, modelId, label })) });
|
|
84
|
+
}
|
|
85
|
+
else
|
|
86
|
+
send(200, context.rsiService.snapshot(source, group?.rsi));
|
|
77
87
|
return true;
|
|
78
88
|
}
|
|
79
89
|
if (request.method !== "POST") {
|
package/dist/server/runtime.d.ts
CHANGED
|
@@ -1276,6 +1276,7 @@ export declare class PiRpcRuntime implements AgentRuntime {
|
|
|
1276
1276
|
groupMembersBusy(workspaceId: string, roomId: string): boolean;
|
|
1277
1277
|
stopGroupMembers(workspaceId: string, roomId: string, memberIds: string[]): Promise<void>;
|
|
1278
1278
|
forgetGroupMemberSessions(workspaceId: string, roomId: string): Promise<void>;
|
|
1279
|
+
private confirmManagedHelperModel;
|
|
1279
1280
|
private completeOnce;
|
|
1280
1281
|
/**
|
|
1281
1282
|
* The live session for a conversation, if there is one.
|