@evandu/super-pi 0.1.301 → 0.1.303

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.
@@ -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-BJds5OrY.js"></script>
11
+ <script type="module" crossorigin src="/assets/index-DDvvcuuS.js"></script>
12
12
  <link rel="modulepreload" crossorigin href="/assets/rolldown-runtime-XKyaHtl9.js">
13
- <link rel="stylesheet" crossorigin href="/assets/index-BV-OeWsY.css">
13
+ <link rel="stylesheet" crossorigin href="/assets/index-DBuR5Y3G.css">
14
14
  </head>
15
15
  <body>
16
16
  <div id="root"></div>
@@ -1,4 +1,4 @@
1
- import { assertModelAllowed } from "../model-filter.js";
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 { ...catalog, models: catalog.models.filter(model => { try {
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.configure") {
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: structuredClone(improvements), repairs: this.repairs.list(source),
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
- const model = state.model ?? conversation.model ?? this.store.workspace(source.workspaceId)?.defaultModel;
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 = 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.model) {
422
- const catalog = await this.runtime.catalog();
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
  },
@@ -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 = source.kind === "session" ? rsiService.state(source).model ?? original?.model : groupChatService.get(source.workspaceId, source.id).rsi?.model ?? groupChatService.get(source.workspaceId, source.id).moderator.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 = original?.model ?? (source.kind === "group" ? groupChatService.get(source.workspaceId, source.id).rsi?.model ?? groupChatService.get(source.workspaceId, source.id).moderator.model : undefined);
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);
@@ -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);
@@ -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
- send(200, context.rsiService.snapshot(source, group?.rsi));
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") {
@@ -588,6 +588,7 @@ export declare class Store {
588
588
  setThinkingActiveLive(conversationId: string, messageId: string, active: boolean): void;
589
589
  appendThinkingDelta(conversationId: string, messageId: string, delta: string): Promise<void>;
590
590
  /** Persists the message exactly as it stands now, including any live text, thinking and tool updates. */
591
+ recordMessageModel(conversationId: string, messageId: string, model: ModelSelection): Promise<void>;
591
592
  checkpointMessage(conversationId: string, messageId: string): Promise<void>;
592
593
  /**
593
594
  * Appends one tool call to the message it belongs to, and returns the message's whole `toolCalls`
@@ -2286,6 +2286,13 @@ export class Store {
2286
2286
  await this.checkpointMessage(conversationId, messageId);
2287
2287
  }
2288
2288
  /** Persists the message exactly as it stands now, including any live text, thinking and tool updates. */
2289
+ async recordMessageModel(conversationId, messageId, model) {
2290
+ const message = this.requireConversation(conversationId).messages.find(item => item.id === messageId);
2291
+ if (!message || message.role !== "assistant")
2292
+ throw new Error("找不到对应的助手消息。");
2293
+ message.actualModel = { provider: model.provider, modelId: model.modelId, label: model.label };
2294
+ await this.checkpointMessage(conversationId, messageId);
2295
+ }
2289
2296
  async checkpointMessage(conversationId, messageId) {
2290
2297
  const conversation = this.requireConversation(conversationId);
2291
2298
  const message = conversation.messages.find((item) => item.id === messageId);
@@ -114,6 +114,7 @@ export type ToolCallQuestion = {
114
114
  answers?: QuestionAnswer[];
115
115
  };
116
116
  export type Message = {
117
+ actualModel?: ModelSelection;
117
118
  backgroundBatch?: Pick<Message, "id" | "content" | "createdAt" | "backgroundTask">[];
118
119
  batchedInto?: string;
119
120
  backgroundTask?: BackgroundTaskSummary;
@@ -1,4 +1,4 @@
1
- import type { GroupRsi, GroupRsiFinding } from "./group-chat.js";
1
+ import type { GroupModel, GroupRsi, GroupRsiFinding } from "./group-chat.js";
2
2
  export type RsiSource = {
3
3
  kind: "session" | "group";
4
4
  id: string;
@@ -29,6 +29,7 @@ export type RsiRepair = {
29
29
  }[];
30
30
  };
31
31
  export type RsiRepairView = RsiRepair & {
32
+ model?: GroupModel;
32
33
  busy: boolean;
33
34
  revision?: string;
34
35
  proposedPlan?: string;
@@ -36,6 +37,7 @@ export type RsiRepairView = RsiRepair & {
36
37
  id: string;
37
38
  role: "user" | "assistant";
38
39
  content: string;
40
+ actualModel?: GroupModel;
39
41
  }[];
40
42
  };
41
43
  export type RsiImprovement = {
@@ -60,7 +62,10 @@ export type RsiImprovement = {
60
62
  export type RsiSnapshot = {
61
63
  state: GroupRsi;
62
64
  repairs?: RsiRepairView[];
63
- improvements: RsiImprovement[];
65
+ improvements: (RsiImprovement & {
66
+ model?: GroupModel;
67
+ actualModel?: GroupModel;
68
+ })[];
64
69
  capabilities: {
65
70
  slug: string;
66
71
  name: string;
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "superPi": {
4
4
  "managedDirectListener": true
5
5
  },
6
- "version": "0.1.301",
6
+ "version": "0.1.303",
7
7
  "description": "Web control plane and companion for Pi",
8
8
  "license": "MIT",
9
9
  "type": "module",