@evandu/super-pi 0.1.217 → 0.1.219
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/project-leader.md +1 -1
- package/agents/super-pi-task/core.ts +1 -1
- package/agents/super-pi-task/index.ts +4 -2
- package/dist/client/.super-pi-client-sources.json +7 -7
- package/dist/client/assets/{CodeMirrorEditor-Bu2HpCg6.js → CodeMirrorEditor-BoRBaVec.js} +2 -2
- package/dist/client/assets/{dist-DeUjsvtg.js → dist-BOC9yjsN.js} +1 -1
- package/dist/client/assets/{dist-2N8cRAr1.js → dist-BOF4T7jI.js} +1 -1
- package/dist/client/assets/{dist-CaSc7b5q.js → dist-BVVJTFYw.js} +1 -1
- package/dist/client/assets/{dist-CgcNjGWq.js → dist-BXOV_xtI.js} +1 -1
- package/dist/client/assets/{dist-cckoD98D.js → dist-Bh20DSAa.js} +1 -1
- package/dist/client/assets/{dist-BhKjqL1a.js → dist-CIv6vCdn.js} +1 -1
- package/dist/client/assets/{dist-CcBbs6jt.js → dist-CMdO3YzL.js} +1 -1
- package/dist/client/assets/{dist-BUqWmkxx.js → dist-CPjKkcyd.js} +1 -1
- package/dist/client/assets/{dist-CygI57SH.js → dist-CYpk6fXT.js} +1 -1
- package/dist/client/assets/{dist-CfdUiqMV.js → dist-CiRgPe6t.js} +1 -1
- package/dist/client/assets/{dist-D-HE23hj.js → dist-CjhpwEGf.js} +1 -1
- package/dist/client/assets/{dist-D68xvrk-.js → dist-Cp3XgqJR.js} +1 -1
- package/dist/client/assets/{dist-CpZQNnTs.js → dist-D1hdxSH6.js} +1 -1
- package/dist/client/assets/{dist-CWdNmsfe.js → dist-DLYLxwOe.js} +1 -1
- package/dist/client/assets/{dist-WWllmrHS.js → dist-DQ_C0DEU.js} +1 -1
- package/dist/client/assets/{dist-Oe-g6uQR.js → dist-DUbHNa35.js} +1 -1
- package/dist/client/assets/{dist-DFwdzVqB.js → dist-Digy2Mj0.js} +1 -1
- package/dist/client/assets/{dist-CX_2RyPQ.js → dist-DvWgfLRt.js} +1 -1
- package/dist/client/assets/{dist-BHl8lGVB.js → dist-Dwsqs8C-.js} +1 -1
- package/dist/client/assets/{dist-BgzW1ukH.js → dist-gRtmlyhZ.js} +1 -1
- package/dist/client/assets/{dist-BdSsUofL.js → dist-mAA5Fw0-.js} +1 -1
- package/dist/client/assets/{dist-DjNZcW3s.js → dist-xb23AFcT.js} +1 -1
- package/dist/client/assets/{index-BuAaKh0Q.js → index-DmxXnVfN.js} +20 -20
- package/dist/client/assets/index-Nu--gcBs.css +1 -0
- package/dist/client/index.html +2 -2
- package/dist/server/application/conversation-service.d.ts +7 -2
- package/dist/server/application/conversation-service.js +45 -5
- package/dist/server/application/project-service.d.ts +8 -4
- package/dist/server/application/project-service.js +76 -34
- package/dist/server/application/provider-service.js +50 -7
- package/dist/server/application/run-service.js +2 -0
- package/dist/server/application/session-orchestrator-service.d.ts +3 -0
- package/dist/server/application/session-orchestrator-service.js +53 -21
- package/dist/server/command-handler.d.ts +3 -1
- package/dist/server/command-handler.js +21 -1
- package/dist/server/index.js +2 -2
- package/dist/server/pi-session.d.ts +26 -5
- package/dist/server/pi-session.js +64 -12
- package/dist/server/providers.d.ts +22 -1
- package/dist/server/providers.js +106 -17
- package/dist/server/runtime.js +19 -3
- package/dist/server/store.d.ts +7 -1
- package/dist/server/store.js +47 -8
- package/dist/server/thinking-level-discovery.d.ts +38 -0
- package/dist/server/thinking-level-discovery.js +159 -0
- package/dist/server/types.d.ts +42 -1
- package/dist/server/upload.d.ts +2 -0
- package/dist/server/upload.js +19 -2
- package/dist/shared/project-overview.d.ts +9 -0
- package/dist/shared/project-overview.js +21 -7
- package/dist/shared/project-presentation.d.ts +3 -0
- package/dist/shared/project-presentation.js +13 -5
- package/dist/shared/team-context.d.ts +1 -1
- package/dist/shared/thinking-levels.d.ts +53 -0
- package/dist/shared/thinking-levels.js +85 -0
- package/package.json +1 -1
- package/dist/client/assets/index-BGgKzf3Y.css +0 -1
|
@@ -127,7 +127,15 @@ export class SessionOrchestratorService {
|
|
|
127
127
|
if (!workspace)
|
|
128
128
|
throw new Error("找不到这个工作区。");
|
|
129
129
|
const parent = options.parentConversationId ? this.store.conversation(options.parentConversationId) : undefined;
|
|
130
|
-
const
|
|
130
|
+
const source = options.forkFromConversationId ? this.store.conversation(options.forkFromConversationId) : undefined;
|
|
131
|
+
if (options.forkFromConversationId && (!source || !parent || source.workspaceId !== workspaceId
|
|
132
|
+
|| parent.workspaceId !== workspaceId || (!source.warmSession && source.parentConversationId !== parent.id) || parent.archivedAt)) {
|
|
133
|
+
throw new Error("只能分叉同工作区及同一直属上级的会话");
|
|
134
|
+
}
|
|
135
|
+
if (source && options.cwd !== undefined && options.cwd !== (source.cwd ?? ".")) {
|
|
136
|
+
throw new Error("分叉任务须使用来源会话的工作目录");
|
|
137
|
+
}
|
|
138
|
+
const cwd = source ? source.cwd : options.cwd !== undefined ? options.cwd : parent?.workspaceId === workspaceId ? parent.cwd : undefined;
|
|
131
139
|
await assertSessionCwdInsideWorkspace(workspace.path, cwd);
|
|
132
140
|
if (options.handoffNote !== undefined && (typeof options.handoffNote !== "string" || options.handoffNote.length > 8000))
|
|
133
141
|
throw new Error("handoffNote 须为最多 8000 字符的交接说明");
|
|
@@ -135,28 +143,42 @@ export class SessionOrchestratorService {
|
|
|
135
143
|
// in-memory ledger below. The ledger is task/status/progress metadata and dies with the process;
|
|
136
144
|
// the conversation's parentConversationId/origin is what the sidebar's session tree redraws
|
|
137
145
|
// from after a restart, so it has to be the persistent record.
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
if (options.title) {
|
|
145
|
-
await this.conversationService.renameConversation(conversationId, options.title);
|
|
146
|
+
let conversationId;
|
|
147
|
+
if (source) {
|
|
148
|
+
const result = await this.conversationService.forkConversation(source.id, { parentConversationId: parent?.id });
|
|
149
|
+
if (!result.ok)
|
|
150
|
+
throw new Error(result.message);
|
|
151
|
+
conversationId = result.forkedId;
|
|
146
152
|
}
|
|
147
|
-
else
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
await this.conversationService.setAgent(conversationId, options.agentId);
|
|
153
|
+
else {
|
|
154
|
+
conversationId = await this.conversationService.createConversation(workspaceId, {
|
|
155
|
+
parentConversationId: options.parentConversationId,
|
|
156
|
+
origin: options.parentConversationId ? "orchestrator" : "user",
|
|
157
|
+
...(options.separateMemoryTree ? { separateMemoryTree: true } : {}),
|
|
158
|
+
}, cwd);
|
|
154
159
|
}
|
|
155
|
-
|
|
156
|
-
|
|
160
|
+
try {
|
|
161
|
+
if (options.title) {
|
|
162
|
+
await this.conversationService.renameConversation(conversationId, options.title);
|
|
163
|
+
}
|
|
164
|
+
else if (options.task) {
|
|
165
|
+
const titleSnippet = options.task.trim().replace(/\s+/g, " ").slice(0, 30);
|
|
166
|
+
await this.conversationService.renameConversation(conversationId, `任务:${titleSnippet}`);
|
|
167
|
+
}
|
|
168
|
+
if (options.agentId) {
|
|
169
|
+
await this.conversationService.setAgent(conversationId, options.agentId);
|
|
170
|
+
}
|
|
171
|
+
if (options.model) {
|
|
172
|
+
await this.conversationService.setModel(conversationId, options.model.provider, options.model.modelId);
|
|
173
|
+
}
|
|
174
|
+
if (options.thinkingLevel) {
|
|
175
|
+
await this.conversationService.setThinking(conversationId, options.thinkingLevel);
|
|
176
|
+
}
|
|
157
177
|
}
|
|
158
|
-
|
|
159
|
-
|
|
178
|
+
catch (error) {
|
|
179
|
+
if (source)
|
|
180
|
+
await this.remove(conversationId);
|
|
181
|
+
throw error;
|
|
160
182
|
}
|
|
161
183
|
// Register in relationship ledger
|
|
162
184
|
this.ledger.register({
|
|
@@ -205,6 +227,8 @@ export class SessionOrchestratorService {
|
|
|
205
227
|
if (!conversation) {
|
|
206
228
|
throw new Error(`找不到会话:${conversationId}`);
|
|
207
229
|
}
|
|
230
|
+
if (conversation.warmSession)
|
|
231
|
+
throw new Error("预热快照只能通过项目派发使用");
|
|
208
232
|
this.ledger.update(conversationId, {
|
|
209
233
|
status: "running",
|
|
210
234
|
});
|
|
@@ -871,6 +895,14 @@ export class SessionOrchestratorService {
|
|
|
871
895
|
descendantCount: descendants.length,
|
|
872
896
|
};
|
|
873
897
|
}
|
|
898
|
+
async removeWarmSession(conversationId) {
|
|
899
|
+
const conversation = this.store.conversation(conversationId);
|
|
900
|
+
if (!conversation)
|
|
901
|
+
return;
|
|
902
|
+
if (!conversation.warmSession)
|
|
903
|
+
throw new Error("只能通过此操作移除预热快照");
|
|
904
|
+
await this.remove(conversationId);
|
|
905
|
+
}
|
|
874
906
|
/**
|
|
875
907
|
* Permanently destroys a direct child session and its entire descendant subtree (stopping any
|
|
876
908
|
* running/queued turns first) and removes all transcripts, outputs, runs, and auxiliary state.
|
|
@@ -891,7 +923,7 @@ export class SessionOrchestratorService {
|
|
|
891
923
|
...(reason ? { reason } : {}),
|
|
892
924
|
};
|
|
893
925
|
}
|
|
894
|
-
if (!conversation.parentConversationId) {
|
|
926
|
+
if (!conversation.parentConversationId && !conversation.warmSession) {
|
|
895
927
|
throw new Error("顶层会话不能销毁,只能由用户归档。");
|
|
896
928
|
}
|
|
897
929
|
const descendants = this.descendantsOf(conversationId);
|
|
@@ -6,6 +6,7 @@ import type { ExtensionUiService } from "./application/extension-ui-service.js";
|
|
|
6
6
|
import type { CatalogService } from "./application/catalog-service.js";
|
|
7
7
|
import type { ProviderService } from "./application/provider-service.js";
|
|
8
8
|
import type { ScheduledTaskService } from "./application/scheduled-task-service.js";
|
|
9
|
+
import type { SessionOrchestratorService } from "./application/session-orchestrator-service.js";
|
|
9
10
|
import type { TerminalService } from "./terminal.js";
|
|
10
11
|
export type SocketSender = (event: ServerEvent) => void;
|
|
11
12
|
/**
|
|
@@ -34,6 +35,7 @@ export declare class CommandHandler {
|
|
|
34
35
|
* follows.
|
|
35
36
|
*/
|
|
36
37
|
private readonly scheduledTaskService?;
|
|
38
|
+
private readonly sessionOrchestratorService?;
|
|
37
39
|
/**
|
|
38
40
|
* The built-in terminal service.
|
|
39
41
|
*
|
|
@@ -57,7 +59,7 @@ export declare class CommandHandler {
|
|
|
57
59
|
* service has to say so rather than take the whole handler down - the same rule `providerService`
|
|
58
60
|
* follows.
|
|
59
61
|
*/
|
|
60
|
-
scheduledTaskService?: ScheduledTaskService | undefined);
|
|
62
|
+
scheduledTaskService?: ScheduledTaskService | undefined, sessionOrchestratorService?: SessionOrchestratorService | undefined);
|
|
61
63
|
/**
|
|
62
64
|
* Processes a client command.
|
|
63
65
|
*
|
|
@@ -15,6 +15,7 @@ export class CommandHandler {
|
|
|
15
15
|
rootDir;
|
|
16
16
|
providerService;
|
|
17
17
|
scheduledTaskService;
|
|
18
|
+
sessionOrchestratorService;
|
|
18
19
|
/**
|
|
19
20
|
* The built-in terminal service.
|
|
20
21
|
*
|
|
@@ -38,7 +39,7 @@ export class CommandHandler {
|
|
|
38
39
|
* service has to say so rather than take the whole handler down - the same rule `providerService`
|
|
39
40
|
* follows.
|
|
40
41
|
*/
|
|
41
|
-
scheduledTaskService) {
|
|
42
|
+
scheduledTaskService, sessionOrchestratorService) {
|
|
42
43
|
this.workspaceService = workspaceService;
|
|
43
44
|
this.conversationService = conversationService;
|
|
44
45
|
this.runService = runService;
|
|
@@ -47,6 +48,7 @@ export class CommandHandler {
|
|
|
47
48
|
this.rootDir = rootDir;
|
|
48
49
|
this.providerService = providerService;
|
|
49
50
|
this.scheduledTaskService = scheduledTaskService;
|
|
51
|
+
this.sessionOrchestratorService = sessionOrchestratorService;
|
|
50
52
|
this.terminalService = terminalService;
|
|
51
53
|
}
|
|
52
54
|
/**
|
|
@@ -76,6 +78,10 @@ export class CommandHandler {
|
|
|
76
78
|
this.conversationService.releaseRevert(conversationId);
|
|
77
79
|
}
|
|
78
80
|
async handleCommand(command, sendToSocket, remoteAddress) {
|
|
81
|
+
if ("conversationId" in command && typeof command.conversationId === "string"
|
|
82
|
+
&& command.type !== "conversation.warm.delete" && this.conversationService.isWarmSession?.(command.conversationId)) {
|
|
83
|
+
throw new Error("预热快照只能通过项目派发使用");
|
|
84
|
+
}
|
|
79
85
|
if (command.type === "terminal.shell.set") {
|
|
80
86
|
if (!this.terminalService || !(await this.terminalService.setShell(command.command, remoteAddress)))
|
|
81
87
|
return;
|
|
@@ -235,6 +241,20 @@ export class CommandHandler {
|
|
|
235
241
|
}
|
|
236
242
|
return;
|
|
237
243
|
}
|
|
244
|
+
if (command.type === "conversation.warm.save") {
|
|
245
|
+
if (typeof command.title !== "string")
|
|
246
|
+
throw new Error("请输入预热会话名称");
|
|
247
|
+
const result = await this.conversationService.forkConversation(command.conversationId, { warmTitle: command.title });
|
|
248
|
+
if (!result.ok)
|
|
249
|
+
throw new Error(result.message);
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
252
|
+
if (command.type === "conversation.warm.delete") {
|
|
253
|
+
if (!this.sessionOrchestratorService)
|
|
254
|
+
throw new Error("会话编排服务未就绪");
|
|
255
|
+
await this.sessionOrchestratorService.removeWarmSession(command.conversationId);
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
238
258
|
if (command.type === "conversation.model") {
|
|
239
259
|
await this.conversationService.setModel(command.conversationId, command.provider, command.modelId);
|
|
240
260
|
return;
|
package/dist/server/index.js
CHANGED
|
@@ -277,7 +277,7 @@ runService.setFileIndexes(fileIndexes);
|
|
|
277
277
|
*/
|
|
278
278
|
const nameIndexes = new Map();
|
|
279
279
|
runService.setNameIndexes(nameIndexes);
|
|
280
|
-
const conversationService = new ConversationService(store, runtime, subagents, broadcaster, catalogService, runService, extensionUiService, initialAgentDirs);
|
|
280
|
+
const conversationService = new ConversationService(store, runtime, subagents, broadcaster, catalogService, runService, extensionUiService, initialAgentDirs, uploadsDir);
|
|
281
281
|
conversationService.setMemory(memory);
|
|
282
282
|
const workspaceService = new WorkspaceService(store, runtime, broadcaster, catalogService, runService, extensionUiService, initialAgentDirs);
|
|
283
283
|
/**
|
|
@@ -360,7 +360,7 @@ const serverContext = {
|
|
|
360
360
|
terminalEnabled: () => terminalService.enabled,
|
|
361
361
|
terminalDisabledReason: () => terminalDisabledReason(),
|
|
362
362
|
};
|
|
363
|
-
const commandHandler = new CommandHandler(workspaceService, conversationService, runService, extensionUiService, catalogService, terminalService, rootDir, providerService, scheduledTaskService);
|
|
363
|
+
const commandHandler = new CommandHandler(workspaceService, conversationService, runService, extensionUiService, catalogService, terminalService, rootDir, providerService, scheduledTaskService, sessionOrchestratorService);
|
|
364
364
|
// ------------------------------------------------------------- Lifecycle & shutdown
|
|
365
365
|
let shutdownPromise;
|
|
366
366
|
async function closeHttpServer() {
|
|
@@ -139,15 +139,22 @@ export declare function warmPiSdk(): Promise<boolean>;
|
|
|
139
139
|
export interface SdkCatalog {
|
|
140
140
|
/** Pi's own model objects, for the caller to reduce with the same helpers the RPC path used. */
|
|
141
141
|
models: unknown[];
|
|
142
|
-
/**
|
|
142
|
+
/**
|
|
143
|
+
* THE MODEL PI WOULD RUN, resolved by PI ITSELF.
|
|
144
|
+
*
|
|
145
|
+
* NOT "the pair Pi's settings name". Pi's settings are a WISH, and a wish is not always granted:
|
|
146
|
+
* the pair may be absent (nobody ever chose a default), it may name a model Pi no longer offers,
|
|
147
|
+
* and it may name a model whose provider has no credential. Pi's own resolver checks all three
|
|
148
|
+
* and, when the wish cannot be granted, picks a model it CAN run. This is that model's identity.
|
|
149
|
+
*
|
|
150
|
+
* UNDEFINED MEANS "PI HAS NO MODEL TO RUN", which is an honest answer and not a gap to paper over.
|
|
151
|
+
*/
|
|
143
152
|
defaultModel?: {
|
|
144
153
|
provider: string;
|
|
145
154
|
modelId: string;
|
|
146
155
|
};
|
|
147
|
-
/** The thinking level Pi would use by default, if settings name one. */
|
|
148
|
-
defaultThinkingLevel?: string;
|
|
149
156
|
/**
|
|
150
|
-
* The levels a model supports, read from a session running that model.
|
|
157
|
+
* The levels a model supports, AND the level in force for it, read from a session running that model.
|
|
151
158
|
*
|
|
152
159
|
* Separate from the models because it is the expensive half: it needs a session, so a caller that
|
|
153
160
|
* only wants the list does not pay for it.
|
|
@@ -155,11 +162,15 @@ export interface SdkCatalog {
|
|
|
155
162
|
* UNDEFINED MEANS "THIS RUNTIME DOES NOT KNOW THAT MODEL", and it is not the same answer as "that
|
|
156
163
|
* model has no levels but off". A caller that gets undefined asks whoever does know the model; a
|
|
157
164
|
* caller that got a list would be showing another model's levels.
|
|
165
|
+
*
|
|
166
|
+
* THE LEVEL IN FORCE COMES FROM THE SAME SESSION, because that is where Pi decides it: the
|
|
167
|
+
* per-model override, else the global default, CLAMPED to what this model actually offers.
|
|
168
|
+
* Reporting the unclamped preference would put a level on screen that the model does not have.
|
|
158
169
|
*/
|
|
159
170
|
thinkingLevelsFor(model: {
|
|
160
171
|
provider: string;
|
|
161
172
|
modelId: string;
|
|
162
|
-
}): Promise<
|
|
173
|
+
}): Promise<ModelThinking | undefined>;
|
|
163
174
|
/**
|
|
164
175
|
* WHAT PI SAYS IS WRONG WITH ITS OWN MODEL CONFIGURATION, verbatim.
|
|
165
176
|
*
|
|
@@ -170,6 +181,16 @@ export interface SdkCatalog {
|
|
|
170
181
|
*/
|
|
171
182
|
configError(): string | undefined;
|
|
172
183
|
}
|
|
184
|
+
/**
|
|
185
|
+
* What a session says about one model's thinking: the levels it offers, and the one in force.
|
|
186
|
+
*
|
|
187
|
+
* The level is Pi's own answer, already clamped to the model. A level that is not in `levels` is a
|
|
188
|
+
* level the model does not have, and putting it on screen would be a claim the model cannot back.
|
|
189
|
+
*/
|
|
190
|
+
export type ModelThinking = {
|
|
191
|
+
levels: string[];
|
|
192
|
+
level?: string;
|
|
193
|
+
};
|
|
173
194
|
/**
|
|
174
195
|
* Builds a zero-process catalog reader.
|
|
175
196
|
*
|
|
@@ -99,18 +99,17 @@ export async function createSdkCatalog(cwd) {
|
|
|
99
99
|
const settingsManager = sdk.SettingsManager.create(cwd, agentDir);
|
|
100
100
|
const models = (await modelRuntime.getAvailable?.()) ?? modelRuntime.getModels?.() ?? [];
|
|
101
101
|
const levelsByModel = new Map();
|
|
102
|
+
// THE DEFAULT MODEL IS PI'S TO DECIDE, SO PI IS ASKED. Not read out of the settings and not guessed:
|
|
103
|
+
// the settings say what the person WANTS, and Pi decides what will actually run.
|
|
104
|
+
const resolved = await resolveDefaultModel(sdk, { cwd, agentDir, modelRuntime, settingsManager });
|
|
105
|
+
// The default's own levels come from the session that resolved it, so the level list is not paid
|
|
106
|
+
// for twice: the next question about that model is a cache hit.
|
|
107
|
+
if (resolved)
|
|
108
|
+
levelsByModel.set(`${resolved.model.provider}/${resolved.model.modelId}`, resolved.thinking);
|
|
102
109
|
return {
|
|
103
110
|
models,
|
|
104
111
|
configError: () => modelRuntime.getError?.(),
|
|
105
|
-
...(
|
|
106
|
-
? {
|
|
107
|
-
defaultModel: {
|
|
108
|
-
provider: settingsManager.getDefaultProvider(),
|
|
109
|
-
modelId: settingsManager.getDefaultModel(),
|
|
110
|
-
},
|
|
111
|
-
}
|
|
112
|
-
: {}),
|
|
113
|
-
...(settingsManager.getDefaultThinkingLevel?.() ? { defaultThinkingLevel: settingsManager.getDefaultThinkingLevel() } : {}),
|
|
112
|
+
...(resolved ? { defaultModel: resolved.model } : {}),
|
|
114
113
|
thinkingLevelsFor: async (model) => {
|
|
115
114
|
const key = `${model.provider}/${model.modelId}`;
|
|
116
115
|
const cached = levelsByModel.get(key);
|
|
@@ -136,9 +135,9 @@ export async function createSdkCatalog(cwd) {
|
|
|
136
135
|
model: whole,
|
|
137
136
|
});
|
|
138
137
|
try {
|
|
139
|
-
const
|
|
140
|
-
levelsByModel.set(key,
|
|
141
|
-
return
|
|
138
|
+
const value = sessionThinking(session);
|
|
139
|
+
levelsByModel.set(key, value);
|
|
140
|
+
return value;
|
|
142
141
|
}
|
|
143
142
|
finally {
|
|
144
143
|
session.dispose?.();
|
|
@@ -146,11 +145,64 @@ export async function createSdkCatalog(cwd) {
|
|
|
146
145
|
},
|
|
147
146
|
};
|
|
148
147
|
}
|
|
148
|
+
/**
|
|
149
|
+
* THE MODEL PI WOULD RUN, AND WHAT IT CAN THINK - asked of Pi.
|
|
150
|
+
*
|
|
151
|
+
* THE SESSION IS BUILT WITH NO MODEL ON PURPOSE. That is the one way to make Pi do its own default
|
|
152
|
+
* resolution instead of Super Pi guessing at it: Pi's resolver prefers the settings' default, but
|
|
153
|
+
* only when that model still exists AND its provider has a credential, and otherwise it picks a
|
|
154
|
+
* model it can actually run - a preference Super Pi cannot read, because the table of "the default
|
|
155
|
+
* model per provider" is Pi's own and is not exported.
|
|
156
|
+
*
|
|
157
|
+
* The session that comes back is RUNNING ON the model Pi picked, so its levels and its thinking
|
|
158
|
+
* level are that model's - read from the same place Pi reads them from.
|
|
159
|
+
*
|
|
160
|
+
* NO INFERENCE IS SENT. A session that has not been prompted does not talk to the provider; it only
|
|
161
|
+
* resolves its configuration. And a session with NO MODEL reports every thinking level there is,
|
|
162
|
+
* which is Pi's way of saying "I have no model to level" - so a session without a model is not an
|
|
163
|
+
* answer at all, and the honest one is "Pi has no model to run".
|
|
164
|
+
*/
|
|
165
|
+
async function resolveDefaultModel(sdk, options) {
|
|
166
|
+
let session;
|
|
167
|
+
try {
|
|
168
|
+
const created = await sdk.createAgentSession({
|
|
169
|
+
cwd: options.cwd,
|
|
170
|
+
agentDir: options.agentDir,
|
|
171
|
+
modelRuntime: options.modelRuntime,
|
|
172
|
+
settingsManager: options.settingsManager,
|
|
173
|
+
sessionManager: sdk.SessionManager.inMemory(options.cwd, { id: "catalog-default" }),
|
|
174
|
+
// NO MODEL: THAT IS THE POINT. Pi resolves the one it would run.
|
|
175
|
+
});
|
|
176
|
+
session = created.session;
|
|
177
|
+
const model = session.model;
|
|
178
|
+
if (typeof model?.provider !== "string" || !model.provider || typeof model.id !== "string" || !model.id)
|
|
179
|
+
return undefined;
|
|
180
|
+
return { model: { provider: model.provider, modelId: model.id }, thinking: sessionThinking(session) };
|
|
181
|
+
}
|
|
182
|
+
catch (error) {
|
|
183
|
+
console.warn(`Pi's SDK could not resolve the default model: ${error instanceof Error ? error.message : String(error)}. The catalog will report no default model rather than a wrong one.`);
|
|
184
|
+
return undefined;
|
|
185
|
+
}
|
|
186
|
+
finally {
|
|
187
|
+
session?.dispose?.();
|
|
188
|
+
}
|
|
189
|
+
}
|
|
149
190
|
/** Reads the thinking levels off a session, tolerating a session that does not implement the call. */
|
|
150
191
|
function sessionLevels(session) {
|
|
151
192
|
const levels = session.getAvailableThinkingLevels?.();
|
|
152
193
|
return Array.isArray(levels) ? levels.filter((level) => typeof level === "string") : [];
|
|
153
194
|
}
|
|
195
|
+
/**
|
|
196
|
+
* The levels a session's model offers, AND the level in force on it.
|
|
197
|
+
*
|
|
198
|
+
* The level is read off the session because that is where Pi clamped it: the per-model override,
|
|
199
|
+
* else the global default, brought down to a level this model actually has.
|
|
200
|
+
*/
|
|
201
|
+
function sessionThinking(session) {
|
|
202
|
+
const levels = sessionLevels(session);
|
|
203
|
+
const level = session.thinkingLevel;
|
|
204
|
+
return { levels, ...(typeof level === "string" && level ? { level } : {}) };
|
|
205
|
+
}
|
|
154
206
|
/**
|
|
155
207
|
* The transcript file a conversation's session writes to, found WITHOUT starting a Pi process.
|
|
156
208
|
*
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { DiscoveredModel, PublicProvider } from "./types.js";
|
|
2
2
|
import type { SharedProviderProxySettings } from "../shared/provider-network.js";
|
|
3
|
+
import { type ThinkingLevelMap } from "../shared/thinking-levels.js";
|
|
3
4
|
/**
|
|
4
5
|
* THE PROVIDERS A PERSON ADDED, and the two files that make Pi know about them.
|
|
5
6
|
*
|
|
@@ -54,6 +55,18 @@ export type ProviderModelDefinition = {
|
|
|
54
55
|
*/
|
|
55
56
|
supportsDeveloperRole?: boolean;
|
|
56
57
|
supportsReasoningEffort?: boolean;
|
|
58
|
+
/**
|
|
59
|
+
* The thinking levels this model really offers, and what each one is sent as.
|
|
60
|
+
*
|
|
61
|
+
* THREE STATES, and the difference between them is the whole point:
|
|
62
|
+
* - ABSENT: nobody said anything about the levels. Whatever was saved for this model stays -
|
|
63
|
+
* a hand-written map in Pi's own file is not this form's to delete.
|
|
64
|
+
* - `null`: this model has NO map. The levels that were saved described an endpoint this model
|
|
65
|
+
* is no longer served by, so they go rather than travel to the new address.
|
|
66
|
+
* - A map: these are the levels, and every one of Pi's seven is named - `null` for the ones the
|
|
67
|
+
* model does not have, because Pi enables the ordinary ones when the map is silent.
|
|
68
|
+
*/
|
|
69
|
+
thinkingLevelMap?: ThinkingLevelMap | null;
|
|
57
70
|
};
|
|
58
71
|
/** One provider, as the settings window collects it. */
|
|
59
72
|
export type ProviderDefinition = {
|
|
@@ -308,5 +321,13 @@ export declare function fetchRemoteModels(input: {
|
|
|
308
321
|
*
|
|
309
322
|
* `fetchRemoteModels` is the transport; this is the reading. Keeping them apart means the reading can
|
|
310
323
|
* be pinned exactly, and a slow machine can never turn a parsing question into a timeout.
|
|
324
|
+
*
|
|
325
|
+
* THE CONTEXT IS THE ENDPOINT THAT ANSWERED, and it matters for exactly one thing: the thinking
|
|
326
|
+
* levels. A level is only true of the endpoint that published it, so the rules that depend on the
|
|
327
|
+
* address need it - and the rules that do not (a model that declares its own levels) work without
|
|
328
|
+
* it, which is why the context is optional.
|
|
311
329
|
*/
|
|
312
|
-
export declare function parseRemoteModels(payload: unknown
|
|
330
|
+
export declare function parseRemoteModels(payload: unknown, context?: {
|
|
331
|
+
baseUrl?: string;
|
|
332
|
+
api?: string;
|
|
333
|
+
}): DiscoveredModel[];
|
package/dist/server/providers.js
CHANGED
|
@@ -6,6 +6,8 @@ import { SUPER_PI_DEFAULT_MAX_TOKENS, SUPER_PI_GUESSED_MAX_TOKENS as GUESSED_MAX
|
|
|
6
6
|
import { providerProxyFetch, readSharedProviderProxy } from "./provider-proxy.js";
|
|
7
7
|
import { hasStoredCredential, publicProviderNetwork, updateProviderNetwork, ProviderNetworkInputError } from "./provider-network.js";
|
|
8
8
|
import { supportsProviderProxy } from "../shared/provider-network.js";
|
|
9
|
+
import { isThinkingLevel, readThinkingLevelMap } from "../shared/thinking-levels.js";
|
|
10
|
+
import { discoverThinkingLevels } from "./thinking-level-discovery.js";
|
|
9
11
|
const unsupportedProxy = (provider) => !supportsProviderProxy(provider);
|
|
10
12
|
/**
|
|
11
13
|
* The API adapters Pi ships, as the ids a provider may name.
|
|
@@ -220,6 +222,20 @@ function toPiProvider(provider, existing) {
|
|
|
220
222
|
...(model.supportsDeveloperRole === undefined ? {} : { supportsDeveloperRole: model.supportsDeveloperRole }),
|
|
221
223
|
...(model.supportsReasoningEffort === undefined ? {} : { supportsReasoningEffort: model.supportsReasoningEffort }),
|
|
222
224
|
};
|
|
225
|
+
// THE THINKING MAP, IN THREE STATES. A map is written when there is one; `null` REMOVES the one
|
|
226
|
+
// that was there (the levels described an endpoint this model is no longer served by); and
|
|
227
|
+
// ABSENT leaves the saved map alone - a map somebody wrote by hand in Pi's own file is not this
|
|
228
|
+
// form's to delete, and an import that knows nothing about the levels must not throw them away.
|
|
229
|
+
const thinkingLevelMap = model.thinkingLevelMap === null
|
|
230
|
+
? undefined
|
|
231
|
+
: (model.thinkingLevelMap ?? priorModel.thinkingLevelMap);
|
|
232
|
+
// A MAP MEANS THE MODEL THINKS - UNLESS SOMEBODY SAID OTHERWISE. Pi offers only `off` for a
|
|
233
|
+
// model that does not reason, so levels without `reasoning` would be levels that do nothing;
|
|
234
|
+
// but a model somebody turned off BY HAND stays off, because the map is not a licence to
|
|
235
|
+
// overrule the word that is already there.
|
|
236
|
+
const reasoning = thinkingLevelMap && model.reasoning === undefined
|
|
237
|
+
? true
|
|
238
|
+
: (model.reasoning ?? false);
|
|
223
239
|
return {
|
|
224
240
|
...priorModel,
|
|
225
241
|
id: model.id,
|
|
@@ -227,11 +243,14 @@ function toPiProvider(provider, existing) {
|
|
|
227
243
|
// invalidates the WHOLE models.json - which takes every custom provider out of every picker
|
|
228
244
|
// with nothing but "must not have fewer than 1 characters" to explain it.
|
|
229
245
|
name: model.name || model.id,
|
|
230
|
-
reasoning
|
|
246
|
+
reasoning,
|
|
231
247
|
input: model.imageInput ? ["text", "image"] : ["text"],
|
|
232
248
|
contextWindow: model.contextWindow ?? DEFAULT_CONTEXT_WINDOW,
|
|
233
249
|
maxTokens: model.maxTokens ?? DEFAULT_MAX_TOKENS,
|
|
234
250
|
...(Object.keys(compat).length ? { compat } : { compat: undefined }),
|
|
251
|
+
...(thinkingLevelMap === undefined
|
|
252
|
+
? (model.thinkingLevelMap === null ? { thinkingLevelMap: undefined } : {})
|
|
253
|
+
: { thinkingLevelMap }),
|
|
235
254
|
};
|
|
236
255
|
});
|
|
237
256
|
return {
|
|
@@ -369,18 +388,27 @@ export class ProviderRegistry {
|
|
|
369
388
|
const api = typeof rec.api === "string" ? rec.api : (backup?.api ?? "openai-completions");
|
|
370
389
|
const name = typeof rec.name === "string" ? rec.name : (backup?.name ?? pId);
|
|
371
390
|
const rawModels = Array.isArray(rec.models) ? rec.models : (backup?.models ?? []);
|
|
372
|
-
const models = rawModels.map((m) =>
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
391
|
+
const models = rawModels.map((m) => {
|
|
392
|
+
// THE THINKING MAP IS READ BACK, or the panel would show a model with no levels while Pi is
|
|
393
|
+
// offering exactly the ones the file says. What is in Pi's own file IS what the model has.
|
|
394
|
+
const thinkingLevelMap = readThinkingLevelMap(m?.thinkingLevelMap);
|
|
395
|
+
return {
|
|
396
|
+
id: typeof m?.id === "string" ? m.id : String(m),
|
|
397
|
+
name: typeof m?.name === "string" ? m.name : m?.id,
|
|
398
|
+
// THE MODEL'S OWN WORD ABOUT THINKING, kept as it was written. A model whose entry says
|
|
399
|
+
// nothing about it stays silent - so the layers below can tell "somebody turned the
|
|
400
|
+
// thinking off" from "nobody ever said" - and the panel fills the gap with false.
|
|
401
|
+
reasoning: typeof m?.reasoning === "boolean" ? m.reasoning : undefined,
|
|
402
|
+
imageInput: Array.isArray(m?.input) ? m.input.includes("image") : false,
|
|
403
|
+
contextWindow: typeof m?.contextWindow === "number" ? m.contextWindow : undefined,
|
|
404
|
+
maxTokens: typeof m?.maxTokens === "number" ? m.maxTokens : undefined,
|
|
405
|
+
// THE TWO COMPATIBILITY SWITCHES ARE READ BACK, or the form would show its own defaults for
|
|
406
|
+
// a setting the file explicitly turned off, and saving the form would silently turn it on.
|
|
407
|
+
...(typeof m?.compat?.supportsDeveloperRole === "boolean" ? { supportsDeveloperRole: m.compat.supportsDeveloperRole } : {}),
|
|
408
|
+
...(typeof m?.compat?.supportsReasoningEffort === "boolean" ? { supportsReasoningEffort: m.compat.supportsReasoningEffort } : {}),
|
|
409
|
+
...(thinkingLevelMap ? { thinkingLevelMap } : {}),
|
|
410
|
+
};
|
|
411
|
+
});
|
|
384
412
|
const apiKey = backup?.apiKey;
|
|
385
413
|
providers.push({
|
|
386
414
|
id: pId,
|
|
@@ -694,9 +722,37 @@ export function publicProviders(providers) {
|
|
|
694
722
|
imageInput: model.imageInput ?? false,
|
|
695
723
|
contextWindow: model.contextWindow ?? DEFAULT_CONTEXT_WINDOW,
|
|
696
724
|
maxTokens: model.maxTokens ?? DEFAULT_MAX_TOKENS,
|
|
725
|
+
// THE LEVELS TRAVEL TO THE BROWSER, because the panel shows them and the form sends them back.
|
|
726
|
+
// A model with no map simply has none - the browser must not invent one.
|
|
727
|
+
...(model.thinkingLevelMap ? { thinkingLevelMap: { ...model.thinkingLevelMap } } : {}),
|
|
697
728
|
})),
|
|
698
729
|
}));
|
|
699
730
|
}
|
|
731
|
+
/**
|
|
732
|
+
* Checks the thinking map a form carried, and returns it in the shape the registry stores.
|
|
733
|
+
*
|
|
734
|
+
* THREE ANSWERS. `undefined` means the form said nothing about the levels, so whatever is saved
|
|
735
|
+
* stays. `null` means the form said "this model has no map", and the saved one goes. A map means
|
|
736
|
+
* "these are the levels", and every one of Pi's seven has to be named - a level that is not a level
|
|
737
|
+
* Pi knows, or a value that is neither a string nor `null`, is refused rather than written into
|
|
738
|
+
* Pi's file, where one bad field takes every provider out of every picker.
|
|
739
|
+
*/
|
|
740
|
+
function checkedThinkingLevelMap(raw) {
|
|
741
|
+
if (raw === undefined)
|
|
742
|
+
return undefined;
|
|
743
|
+
if (raw === null)
|
|
744
|
+
return null;
|
|
745
|
+
if (typeof raw !== "object" || Array.isArray(raw))
|
|
746
|
+
throw new Error("思考档位必须是一个对象");
|
|
747
|
+
for (const [key, value] of Object.entries(raw)) {
|
|
748
|
+
if (!isThinkingLevel(key))
|
|
749
|
+
throw new Error(`思考档位「${key}」不是 Pi 的档位`);
|
|
750
|
+
if (value !== null && (typeof value !== "string" || !value.trim())) {
|
|
751
|
+
throw new Error(`思考档位「${key}」的值必须是非空字符串或 null`);
|
|
752
|
+
}
|
|
753
|
+
}
|
|
754
|
+
return readThinkingLevelMap(raw) ?? {};
|
|
755
|
+
}
|
|
700
756
|
/**
|
|
701
757
|
* Checks what the form collected and returns it in the shape the registry stores.
|
|
702
758
|
*
|
|
@@ -746,15 +802,23 @@ export function validateProvider(input) {
|
|
|
746
802
|
const maxTokens = typeof model.maxTokens === "number" ? Math.round(model.maxTokens) : undefined;
|
|
747
803
|
if (maxTokens !== undefined && (!Number.isFinite(maxTokens) || maxTokens <= 0))
|
|
748
804
|
throw new Error("最大输出 token 必须是一个正数");
|
|
805
|
+
// THE THINKING MAP IS CHECKED RATHER THAN TRUSTED, because it goes straight into Pi's file. A
|
|
806
|
+
// key Pi does not know, or a value that is neither a string nor `null`, is refused here - the
|
|
807
|
+
// same way an empty `baseUrl` is refused, because Pi rejects the WHOLE file over one bad field.
|
|
808
|
+
const thinkingLevelMap = checkedThinkingLevelMap(model.thinkingLevelMap);
|
|
749
809
|
return {
|
|
750
810
|
id: modelId,
|
|
751
811
|
...(modelName ? { name: modelName } : {}),
|
|
752
|
-
|
|
812
|
+
// BOTH WORDS ARE KEPT. A form that says the model does not think says it, and a form that
|
|
813
|
+
// says nothing says nothing - and the difference is the difference between "this model has
|
|
814
|
+
// its thinking switched off" and "nobody ever said".
|
|
815
|
+
...(typeof model.reasoning === "boolean" ? { reasoning: model.reasoning } : {}),
|
|
753
816
|
...(model.imageInput === true ? { imageInput: true } : {}),
|
|
754
817
|
...(contextWindow === undefined ? {} : { contextWindow }),
|
|
755
818
|
...(maxTokens === undefined ? {} : { maxTokens }),
|
|
756
819
|
...(model.supportsDeveloperRole === false ? { supportsDeveloperRole: false } : {}),
|
|
757
820
|
...(model.supportsReasoningEffort === false ? { supportsReasoningEffort: false } : {}),
|
|
821
|
+
...(thinkingLevelMap === undefined ? {} : { thinkingLevelMap }),
|
|
758
822
|
};
|
|
759
823
|
});
|
|
760
824
|
return {
|
|
@@ -805,6 +869,11 @@ export async function fetchRemoteModels(input) {
|
|
|
805
869
|
let lastError = "";
|
|
806
870
|
let lastCause;
|
|
807
871
|
let payload = null;
|
|
872
|
+
// THE URL THAT ANSWERED. A fetch follows redirects, so the endpoint that replied can be a
|
|
873
|
+
// different one from the address in the form - and it is the one that published whatever is
|
|
874
|
+
// being read. Deciding "is this the official endpoint?" from the address that was ASKED would
|
|
875
|
+
// call a redirect's destination the official one.
|
|
876
|
+
let answeredUrl = cleanBase;
|
|
808
877
|
for (const candidate of candidates) {
|
|
809
878
|
try {
|
|
810
879
|
const response = await (providerProxyFetch(input.proxyEnv) ?? fetch)(candidate, {
|
|
@@ -816,6 +885,7 @@ export async function fetchRemoteModels(input) {
|
|
|
816
885
|
continue;
|
|
817
886
|
}
|
|
818
887
|
payload = await response.json();
|
|
888
|
+
answeredUrl = response.url || candidate;
|
|
819
889
|
if (payload)
|
|
820
890
|
break;
|
|
821
891
|
}
|
|
@@ -835,7 +905,7 @@ export async function fetchRemoteModels(input) {
|
|
|
835
905
|
: undefined;
|
|
836
906
|
throw new Error(`无法从远程服务获取模型列表 (${lastError || "请求超时或无法连接"}${cause ? `:${cause}` : ""})`);
|
|
837
907
|
}
|
|
838
|
-
return parseRemoteModels(payload);
|
|
908
|
+
return parseRemoteModels(payload, { baseUrl: answeredUrl, api: input.api });
|
|
839
909
|
}
|
|
840
910
|
/**
|
|
841
911
|
* THE ANSWER, READ.
|
|
@@ -848,8 +918,13 @@ export async function fetchRemoteModels(input) {
|
|
|
848
918
|
*
|
|
849
919
|
* `fetchRemoteModels` is the transport; this is the reading. Keeping them apart means the reading can
|
|
850
920
|
* be pinned exactly, and a slow machine can never turn a parsing question into a timeout.
|
|
921
|
+
*
|
|
922
|
+
* THE CONTEXT IS THE ENDPOINT THAT ANSWERED, and it matters for exactly one thing: the thinking
|
|
923
|
+
* levels. A level is only true of the endpoint that published it, so the rules that depend on the
|
|
924
|
+
* address need it - and the rules that do not (a model that declares its own levels) work without
|
|
925
|
+
* it, which is why the context is optional.
|
|
851
926
|
*/
|
|
852
|
-
export function parseRemoteModels(payload) {
|
|
927
|
+
export function parseRemoteModels(payload, context) {
|
|
853
928
|
const rawList = Array.isArray(payload)
|
|
854
929
|
? payload
|
|
855
930
|
: Array.isArray(payload.data)
|
|
@@ -871,7 +946,20 @@ export function parseRemoteModels(payload) {
|
|
|
871
946
|
continue;
|
|
872
947
|
seen.add(id);
|
|
873
948
|
const lower = id.toLowerCase();
|
|
874
|
-
|
|
949
|
+
// THE THINKING LEVELS ARE READ FIRST, because they are part of the answer about the model.
|
|
950
|
+
const thinkingLevelMap = discoverThinkingLevels(rec, { baseUrl: context?.baseUrl ?? "", api: context?.api });
|
|
951
|
+
// THE PROVIDER'S OWN WORD WINS. A payload that says `reasoning: false` says the model does
|
|
952
|
+
// not think, and neither the model's NAME nor the levels it published may overrule that: a
|
|
953
|
+
// level that is switched off is a level that does nothing, and switching it on behind the
|
|
954
|
+
// provider's back would be writing a fact the provider did not give.
|
|
955
|
+
//
|
|
956
|
+
// When the payload says nothing about it, a published map is a fact about the model - Pi
|
|
957
|
+
// offers ONLY `off` for a model that does not reason, so levels on a "not a reasoning model"
|
|
958
|
+
// would be levels Pi never shows - and the NAME is still a reason for the models nobody
|
|
959
|
+
// described.
|
|
960
|
+
const reasoning = typeof rec.reasoning === "boolean"
|
|
961
|
+
? rec.reasoning
|
|
962
|
+
: (Boolean(thinkingLevelMap) || /r1|reason|o1|o3|thinking|qwq|deepseek-r1/i.test(lower));
|
|
875
963
|
const imageInput = /vision|vl|4o|gemini|claude-3|flash|pixtral/i.test(lower);
|
|
876
964
|
// THE CATALOGUE IS ASKED BEFORE THE DEFAULT IS GUESSED. A model the provider did not describe
|
|
877
965
|
// used to fall straight to the placeholder 128000/16384, and that stamp was later read back as
|
|
@@ -894,6 +982,7 @@ export function parseRemoteModels(payload) {
|
|
|
894
982
|
imageInput,
|
|
895
983
|
contextWindow,
|
|
896
984
|
maxTokens,
|
|
985
|
+
...(thinkingLevelMap ? { thinkingLevelMap } : {}),
|
|
897
986
|
});
|
|
898
987
|
}
|
|
899
988
|
return discovered.sort((a, b) => a.id.localeCompare(b.id));
|