@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.
Files changed (62) hide show
  1. package/agents/project-leader.md +1 -1
  2. package/agents/super-pi-task/core.ts +1 -1
  3. package/agents/super-pi-task/index.ts +4 -2
  4. package/dist/client/.super-pi-client-sources.json +7 -7
  5. package/dist/client/assets/{CodeMirrorEditor-Bu2HpCg6.js → CodeMirrorEditor-BoRBaVec.js} +2 -2
  6. package/dist/client/assets/{dist-DeUjsvtg.js → dist-BOC9yjsN.js} +1 -1
  7. package/dist/client/assets/{dist-2N8cRAr1.js → dist-BOF4T7jI.js} +1 -1
  8. package/dist/client/assets/{dist-CaSc7b5q.js → dist-BVVJTFYw.js} +1 -1
  9. package/dist/client/assets/{dist-CgcNjGWq.js → dist-BXOV_xtI.js} +1 -1
  10. package/dist/client/assets/{dist-cckoD98D.js → dist-Bh20DSAa.js} +1 -1
  11. package/dist/client/assets/{dist-BhKjqL1a.js → dist-CIv6vCdn.js} +1 -1
  12. package/dist/client/assets/{dist-CcBbs6jt.js → dist-CMdO3YzL.js} +1 -1
  13. package/dist/client/assets/{dist-BUqWmkxx.js → dist-CPjKkcyd.js} +1 -1
  14. package/dist/client/assets/{dist-CygI57SH.js → dist-CYpk6fXT.js} +1 -1
  15. package/dist/client/assets/{dist-CfdUiqMV.js → dist-CiRgPe6t.js} +1 -1
  16. package/dist/client/assets/{dist-D-HE23hj.js → dist-CjhpwEGf.js} +1 -1
  17. package/dist/client/assets/{dist-D68xvrk-.js → dist-Cp3XgqJR.js} +1 -1
  18. package/dist/client/assets/{dist-CpZQNnTs.js → dist-D1hdxSH6.js} +1 -1
  19. package/dist/client/assets/{dist-CWdNmsfe.js → dist-DLYLxwOe.js} +1 -1
  20. package/dist/client/assets/{dist-WWllmrHS.js → dist-DQ_C0DEU.js} +1 -1
  21. package/dist/client/assets/{dist-Oe-g6uQR.js → dist-DUbHNa35.js} +1 -1
  22. package/dist/client/assets/{dist-DFwdzVqB.js → dist-Digy2Mj0.js} +1 -1
  23. package/dist/client/assets/{dist-CX_2RyPQ.js → dist-DvWgfLRt.js} +1 -1
  24. package/dist/client/assets/{dist-BHl8lGVB.js → dist-Dwsqs8C-.js} +1 -1
  25. package/dist/client/assets/{dist-BgzW1ukH.js → dist-gRtmlyhZ.js} +1 -1
  26. package/dist/client/assets/{dist-BdSsUofL.js → dist-mAA5Fw0-.js} +1 -1
  27. package/dist/client/assets/{dist-DjNZcW3s.js → dist-xb23AFcT.js} +1 -1
  28. package/dist/client/assets/{index-BuAaKh0Q.js → index-DmxXnVfN.js} +20 -20
  29. package/dist/client/assets/index-Nu--gcBs.css +1 -0
  30. package/dist/client/index.html +2 -2
  31. package/dist/server/application/conversation-service.d.ts +7 -2
  32. package/dist/server/application/conversation-service.js +45 -5
  33. package/dist/server/application/project-service.d.ts +8 -4
  34. package/dist/server/application/project-service.js +76 -34
  35. package/dist/server/application/provider-service.js +50 -7
  36. package/dist/server/application/run-service.js +2 -0
  37. package/dist/server/application/session-orchestrator-service.d.ts +3 -0
  38. package/dist/server/application/session-orchestrator-service.js +53 -21
  39. package/dist/server/command-handler.d.ts +3 -1
  40. package/dist/server/command-handler.js +21 -1
  41. package/dist/server/index.js +2 -2
  42. package/dist/server/pi-session.d.ts +26 -5
  43. package/dist/server/pi-session.js +64 -12
  44. package/dist/server/providers.d.ts +22 -1
  45. package/dist/server/providers.js +106 -17
  46. package/dist/server/runtime.js +19 -3
  47. package/dist/server/store.d.ts +7 -1
  48. package/dist/server/store.js +47 -8
  49. package/dist/server/thinking-level-discovery.d.ts +38 -0
  50. package/dist/server/thinking-level-discovery.js +159 -0
  51. package/dist/server/types.d.ts +42 -1
  52. package/dist/server/upload.d.ts +2 -0
  53. package/dist/server/upload.js +19 -2
  54. package/dist/shared/project-overview.d.ts +9 -0
  55. package/dist/shared/project-overview.js +21 -7
  56. package/dist/shared/project-presentation.d.ts +3 -0
  57. package/dist/shared/project-presentation.js +13 -5
  58. package/dist/shared/team-context.d.ts +1 -1
  59. package/dist/shared/thinking-levels.d.ts +53 -0
  60. package/dist/shared/thinking-levels.js +85 -0
  61. package/package.json +1 -1
  62. package/dist/client/assets/index-BGgKzf3Y.css +0 -1
@@ -2865,8 +2865,22 @@ export class PiRpcRuntime {
2865
2865
  const pick = (model) => (model ? { provider: model.provider, modelId: model.modelId, label: model.label } : undefined);
2866
2866
  // Unknown levels do not invalidate the SDK model list or imply an external Pi.
2867
2867
  // Keep the catalog usable without spawning a process or borrowing another model's levels.
2868
+ //
2869
+ // THE MODEL IN FORCE IS PI'S ANSWER. With no selection the conversation runs on the model Pi
2870
+ // resolved for itself - not on the pair Pi's settings happen to name, which may be missing,
2871
+ // stale, or unauthenticated. Asking for THAT model's levels is what puts a real list on screen
2872
+ // instead of an empty one.
2868
2873
  const forModel = selection ?? reader.defaultModel;
2869
- const levelNames = (forModel ? await reader.thinkingLevelsFor(forModel) : undefined) ?? [];
2874
+ const thinking = forModel ? await reader.thinkingLevelsFor(forModel) : undefined;
2875
+ const levelNames = thinking?.levels ?? [];
2876
+ // THE DEFAULT MODEL, TAKEN FROM THE LIST RATHER THAN REBUILT. The list carries Pi's own fields
2877
+ // - the window, the output limit, whether the model reasons - and a pair rebuilt from a
2878
+ // provider and an id would carry none of them.
2879
+ const wanted = reader.defaultModel;
2880
+ const defaultOption = wanted
2881
+ ? models.find((model) => model.provider === wanted.provider && model.modelId === wanted.modelId)
2882
+ ?? describeModel({ provider: wanted.provider, id: wanted.modelId, name: wanted.modelId })
2883
+ : undefined;
2870
2884
  const value = {
2871
2885
  source: "pi",
2872
2886
  models,
@@ -2876,8 +2890,10 @@ export class PiRpcRuntime {
2876
2890
  // hardest kind of missing: Pi rejects a whole models.json over one bad field, so EVERY
2877
2891
  // custom provider disappears at once and the only explanation is somewhere else entirely.
2878
2892
  ...(reader.configError?.() ? { configError: reader.configError() } : {}),
2879
- defaultModel: pick(reader.defaultModel ? describeModel({ provider: reader.defaultModel.provider, id: reader.defaultModel.modelId, name: reader.defaultModel.modelId }) : undefined),
2880
- defaultThinkingLevel: reader.defaultThinkingLevel ?? levelNames[0],
2893
+ defaultModel: pick(defaultOption),
2894
+ // THE LEVEL IN FORCE, AS PI RESOLVED IT FOR THIS MODEL. It is already clamped to the level
2895
+ // list above, so the button on screen always names a level the model actually has.
2896
+ defaultThinkingLevel: thinking?.level ?? levelNames[0],
2881
2897
  fetchedAt: new Date().toISOString(),
2882
2898
  };
2883
2899
  return value;
@@ -304,6 +304,8 @@ export declare class Store {
304
304
  * for a message that was never allowed to be sent.
305
305
  */
306
306
  childLockUnlocked(conversationId: string): boolean;
307
+ listWarmSessions(workspaceId: string): NonNullable<AppState["warmSessions"]>;
308
+ isWarmSession(conversationId: string): boolean;
307
309
  /**
308
310
  * Opens (or re-closes) one child session's composer, and persists it.
309
311
  *
@@ -371,7 +373,11 @@ export declare class Store {
371
373
  * (`byRecency`) puts a fork at the TOP of its workspace group, because `updatedAt` is now - which is the
372
374
  * same position a newly created conversation takes, and the same reason.
373
375
  */
374
- forkConversation(sourceConversationId: string, forkedConversationId: string): Promise<Conversation>;
376
+ forkConversation(sourceConversationId: string, forkedConversationId: string, options?: {
377
+ parentConversationId?: string;
378
+ warmTitle?: string;
379
+ piSessionFile?: string;
380
+ }): Promise<Conversation>;
375
381
  /**
376
382
  * Archive is a marker, not a move: the conversation keeps its id, workspace, messages and position.
377
383
  * `updatedAt` is deliberately NOT touched, because it drives the sidebar's live timestamp and recency -
@@ -690,6 +690,17 @@ export class Store {
690
690
  delete state.scheduledTasks;
691
691
  if (state.projects !== undefined && !Array.isArray(state.projects))
692
692
  delete state.projects;
693
+ let migratedProjects = false;
694
+ for (const project of state.projects ?? []) {
695
+ if (String(project.status) !== "completed")
696
+ continue;
697
+ project.status = project.ownerConversationId ? "active" : "awaiting_start";
698
+ const delivery = [...(project.reports ?? [])].reverse().find((report) => report.kind === "delivery" && !report.taskId);
699
+ if (delivery && !delivery.createdAt)
700
+ delivery.createdAt = project.closedAt ?? project.updatedAt;
701
+ delete project.closedAt;
702
+ migratedProjects = true;
703
+ }
693
704
  // Every sweep runs before the store is constructed, so a single persist below publishes them together.
694
705
  // Reconciling them in separate writes would put a file on disk in which one kind of orphan was fixed
695
706
  // and the other was not - a half-repaired state that still needs a second restart to finish.
@@ -707,7 +718,7 @@ export class Store {
707
718
  // Persisted here, in `open`, rather than left for the first unrelated write: a reconciled record that
708
719
  // is only rewritten by a later mutation would still read `running` to anything that opened the file
709
720
  // in the meantime, and would be reconciled a SECOND time on the next restart.
710
- if (defaulted || orphaned.length || orphanedWorkflows.length || orphanedTasks.changed || interrupted.length || requeued.recovered.length || requeued.changed || todos.changed || foldedUsage) {
721
+ if (defaulted || migratedProjects || orphaned.length || orphanedWorkflows.length || orphanedTasks.changed || interrupted.length || requeued.recovered.length || requeued.changed || todos.changed || foldedUsage) {
711
722
  for (const run of orphaned)
712
723
  console.warn(`Super Pi: sub-agent run ${run.id} was still marked running when the last server stopped - it is now failed, because no child process survived it.`);
713
724
  for (const plan of orphanedWorkflows)
@@ -923,7 +934,7 @@ export class Store {
923
934
  conversationsForWorkspace(workspaceId) {
924
935
  const openEscalations = this.openEscalationConversationIds();
925
936
  const pendingResults = this.pendingResultConversationIds();
926
- return structuredClone(this.state.conversations.filter((item) => item.workspaceId === workspaceId)).map((c) => {
937
+ return structuredClone(this.state.conversations.filter((item) => item.workspaceId === workspaceId && !item.warmSession)).map((c) => {
927
938
  const hasOpenEscalation = openEscalations.has(c.id);
928
939
  const hasPendingResult = pendingResults.has(c.id);
929
940
  if (!hasOpenEscalation && !hasPendingResult)
@@ -1199,7 +1210,9 @@ export class Store {
1199
1210
  const { projects: _projects, ...publicState } = this.state;
1200
1211
  const closed = new Set(this.state.workspaces.filter((item) => item.closedAt).map((item) => item.id));
1201
1212
  const workspaces = this.state.workspaces.filter((item) => !closed.has(item.id));
1202
- const visible = this.state.conversations.filter((item) => !closed.has(item.workspaceId));
1213
+ const visible = this.state.conversations.filter((item) => !closed.has(item.workspaceId) && !item.warmSession);
1214
+ const warmSessions = workspaces.flatMap((workspace) => this.listWarmSessions(workspace.id));
1215
+ const presets = warmSessions.length ? { warmSessions } : {};
1203
1216
  const openEscalations = this.openEscalationConversationIds();
1204
1217
  const pendingResults = this.pendingResultConversationIds();
1205
1218
  // Legacy sockets still receive complete visible transcripts. Project before cloning so a closed
@@ -1207,6 +1220,7 @@ export class Store {
1207
1220
  if (scope === undefined) {
1208
1221
  return structuredClone({
1209
1222
  ...publicState,
1223
+ ...presets,
1210
1224
  workspaces,
1211
1225
  conversations: visible.map((c) => {
1212
1226
  const hasOpenEscalation = openEscalations.has(c.id);
@@ -1235,6 +1249,7 @@ export class Store {
1235
1249
  }));
1236
1250
  return structuredClone({
1237
1251
  ...publicState,
1252
+ ...presets,
1238
1253
  workspaces,
1239
1254
  conversations,
1240
1255
  // THE CLOCK THE SERVER SCHEDULES BY, NAMED. The scheduled-task panel renders 「每天 09:00」 and
@@ -1356,6 +1371,13 @@ export class Store {
1356
1371
  childLockUnlocked(conversationId) {
1357
1372
  return Boolean(this.state.unlockedChildConversationIds?.includes(conversationId));
1358
1373
  }
1374
+ listWarmSessions(workspaceId) {
1375
+ return this.state.conversations.filter((item) => item.warmSession && item.workspaceId === workspaceId)
1376
+ .map(({ id, title, workspaceId, cwd, archivedAt, updatedAt }) => ({ id, title, workspaceId, cwd, savedAt: archivedAt ?? updatedAt }));
1377
+ }
1378
+ isWarmSession(conversationId) {
1379
+ return this.state.conversations.some((item) => item.id === conversationId && item.warmSession);
1380
+ }
1359
1381
  /**
1360
1382
  * Opens (or re-closes) one child session's composer, and persists it.
1361
1383
  *
@@ -1445,14 +1467,21 @@ export class Store {
1445
1467
  * (`byRecency`) puts a fork at the TOP of its workspace group, because `updatedAt` is now - which is the
1446
1468
  * same position a newly created conversation takes, and the same reason.
1447
1469
  */
1448
- async forkConversation(sourceConversationId, forkedConversationId) {
1470
+ async forkConversation(sourceConversationId, forkedConversationId, options = {}) {
1449
1471
  const source = this.requireConversation(sourceConversationId);
1450
1472
  if (source.id === forkedConversationId)
1451
1473
  throw new Error("Cannot fork a conversation into itself");
1474
+ const parent = options.parentConversationId ? this.requireConversation(options.parentConversationId) : undefined;
1475
+ if (parent && (parent.workspaceId !== source.workspaceId || parent.archivedAt || (!source.warmSession && source.parentConversationId !== parent.id))) {
1476
+ throw new Error("分叉会话必须与来源保留同一个直属上级和工作区");
1477
+ }
1452
1478
  const conversation = {
1453
1479
  id: forkedConversationId,
1454
- treeId: forkedConversationId,
1455
- title: source.title,
1480
+ treeId: parent ? memoryTreeId(source.warmSession ? parent : source, this.state.conversations) : forkedConversationId,
1481
+ ...(parent ? { parentConversationId: parent.id, origin: "orchestrator" } : {}),
1482
+ ...(options.warmTitle ? { warmSession: true, archivedAt: now() } : {}),
1483
+ ...(options.piSessionFile ? { piSessionFile: options.piSessionFile } : {}),
1484
+ title: options.warmTitle ?? source.title,
1456
1485
  workspaceId: source.workspaceId,
1457
1486
  updatedAt: now(),
1458
1487
  status: "idle",
@@ -1475,7 +1504,13 @@ export class Store {
1475
1504
  if (source.cwd)
1476
1505
  conversation.cwd = source.cwd;
1477
1506
  this.state.conversations.unshift(conversation);
1478
- await this.persist();
1507
+ try {
1508
+ await this.persist();
1509
+ }
1510
+ catch (error) {
1511
+ this.state.conversations = this.state.conversations.filter((item) => item.id !== conversation.id);
1512
+ throw error;
1513
+ }
1479
1514
  return structuredClone(conversation);
1480
1515
  }
1481
1516
  /**
@@ -1501,6 +1536,8 @@ export class Store {
1501
1536
  * byte-identically to one that was never archived. `delete` is legal here because the field is optional. */
1502
1537
  async unarchiveConversation(conversationId) {
1503
1538
  const conversation = this.requireConversation(conversationId);
1539
+ if (conversation.warmSession)
1540
+ throw new Error("预热快照只能通过项目派发使用");
1504
1541
  if (!conversation.archivedAt)
1505
1542
  return;
1506
1543
  delete conversation.archivedAt;
@@ -1530,6 +1567,8 @@ export class Store {
1530
1567
  /** Restores one archived tree in one write; active descendants are already restored by definition. */
1531
1568
  async unarchiveConversationTree(conversationId) {
1532
1569
  const root = this.requireConversation(conversationId);
1570
+ if (root.warmSession)
1571
+ throw new Error("预热快照只能通过项目派发使用");
1533
1572
  const parent = root.parentConversationId
1534
1573
  ? this.state.conversations.find(item => item.id === root.parentConversationId)
1535
1574
  : undefined;
@@ -1562,7 +1601,7 @@ export class Store {
1562
1601
  const root = this.state.conversations.find((item) => item.id === conversationId);
1563
1602
  if (!root)
1564
1603
  return { destroyed: [] };
1565
- if (!root.parentConversationId) {
1604
+ if (!root.parentConversationId && !root.warmSession) {
1566
1605
  throw new Error("顶层会话不能销毁,只能由用户归档。");
1567
1606
  }
1568
1607
  const subtree = this.conversationSubtree(root);
@@ -0,0 +1,38 @@
1
+ import { type ThinkingLevelMap } from "../shared/thinking-levels.js";
2
+ /**
3
+ * WHICH THINKING LEVELS A MODEL REALLY OFFERS, and who is allowed to say.
4
+ *
5
+ * THE PROBLEM THIS SOLVES. A model that only does `low`/`medium`/`high` looks exactly like one that
6
+ * does everything, because Pi ENABLES the ordinary levels when nobody says otherwise. So the picker
7
+ * offers a level the provider does not have, the request carries a `reasoning_effort` the provider
8
+ * refuses, and the turn fails on a setting nobody chose.
9
+ *
10
+ * THE RULE THIS FILE ENFORCES. A level may only be written into a model when somebody SAID it, in
11
+ * a form that names the level. Three things do NOT count as saying it, and all three are refused
12
+ * here:
13
+ *
14
+ * 1. A model whose NAME looks like a reasoning model (`o3`, `deepseek-r1`, `thinking`).
15
+ * 2. A provider that only says it supports the PARAMETER (`supports_reasoning_effort: true`,
16
+ * `supported_parameters: ["reasoning_effort"]`). That says a field exists, not which values
17
+ * the model accepts.
18
+ * 3. `reasoning: true`, which says the model thinks, not how hard it can think.
19
+ *
20
+ * AND THE RULE ABOUT COPIES. A level belongs to ONE endpoint's answer about ONE model. A proxy that
21
+ * serves a model with the same name as somebody else's model does NOT get that model's levels, and
22
+ * an answer about one API is never carried over to another. That is why the only endpoint-specific
23
+ * rule below matches the OFFICIAL host exactly.
24
+ */
25
+ /** What the endpoint that answered is, so a rule can be about it and not about the model alone. */
26
+ export type ThinkingLevelContext = {
27
+ /** The endpoint, exactly as the person typed it. */
28
+ baseUrl: string;
29
+ /** The API that endpoint is spoken with. */
30
+ api?: string;
31
+ };
32
+ /**
33
+ * THE LEVELS A MODEL OFFERS, or `undefined` when nobody said.
34
+ *
35
+ * `undefined` is not "no levels" - it is "nobody said", and the caller keeps whatever behaviour it
36
+ * had. A model that nobody described keeps Pi's own defaults, exactly as before.
37
+ */
38
+ export declare function discoverThinkingLevels(entry: Record<string, unknown>, context: ThinkingLevelContext): ThinkingLevelMap | undefined;
@@ -0,0 +1,159 @@
1
+ import { PI_THINKING_LEVELS } from "../shared/thinking-levels.js";
2
+ /**
3
+ * THE API THE LEVELS BELONG TO, and the one the form means when it says nothing.
4
+ *
5
+ * The form's API list starts with `openai-completions`, and an empty field is that one - which is
6
+ * why an absent API is read as this one rather than as "unknown".
7
+ */
8
+ const DEFAULT_API = "openai-completions";
9
+ /**
10
+ * THE EFFORT NAME Pi KNOWS, AND THE Pi LEVEL IT IS.
11
+ *
12
+ * The provider's `reasoning_effort` values and Pi's levels are the same words, with one addition:
13
+ * OpenAI's `none` is Pi's `off` (thinking switched off, sent as `none`). A value that is not in
14
+ * this table is NOT translated - a provider that calls its levels `ultra` or `high_intensity` gets
15
+ * no map at all rather than a map that guesses what `ultra` means.
16
+ *
17
+ * A MAP, NOT AN OBJECT, because the keys come from a provider's answer. An object literal would
18
+ * answer `EFFORT_TO_LEVEL["constructor"]` with `Object.prototype.constructor` - a function, which
19
+ * is truthy - and `__proto__` with the prototype itself, so a provider that published the word
20
+ * "constructor" would have been believed about a level Pi does not have. A Map has no prototype to
21
+ * inherit from, and `has` asks whether the KEY is one of ours.
22
+ */
23
+ const EFFORT_TO_LEVEL = new Map([
24
+ ["none", "off"],
25
+ ["minimal", "minimal"],
26
+ ["low", "low"],
27
+ ["medium", "medium"],
28
+ ["high", "high"],
29
+ ["xhigh", "xhigh"],
30
+ ["max", "max"],
31
+ ]);
32
+ /**
33
+ * MiniMax's OFFICIAL OpenAI-compatible endpoint.
34
+ *
35
+ * The reference is MiniMax's own documentation for the OpenAI-compatible text API
36
+ * (https://platform.minimax.io/docs/api-reference/text-openai-api), which publishes the base URL
37
+ * `https://api.minimax.io/v1` and the `reasoning_effort` values of `MiniMax-M3.1-Flash`.
38
+ *
39
+ * EXACTLY THIS ORIGIN. A proxy that serves a model called `MiniMax-M3.1-Flash` is a different
40
+ * endpoint with a different answer, and it does not get these levels. The path is part of the
41
+ * match too, because the same host serves other paths - `/anthropic` is a different API with
42
+ * different parameters.
43
+ */
44
+ const MINIMAX_ORIGIN = "https://api.minimax.io";
45
+ /**
46
+ * THE PATHS THAT ARE THE OFFICIAL OPENAI-COMPATIBLE TEXT API.
47
+ *
48
+ * `/v1` is the documented base URL, and `/v1/models` is the URL the model list is actually
49
+ * requested from - the discovery is told which URL ANSWERED, and that is the one that ends in
50
+ * `/models`. The bare origin is the same endpoint with the `/v1` left off.
51
+ */
52
+ const MINIMAX_PATHS = new Set(["", "/v1", "/v1/models"]);
53
+ /** The model MiniMax's documentation names for these levels. */
54
+ const MINIMAX_FLASH_MODEL = "minimax-m3.1-flash";
55
+ /**
56
+ * MiniMax-M3.1-Flash's levels, as its documentation states them: `low`, `medium`, `high`, `xhigh`,
57
+ * `max`, and nothing else. `off` is `null` because the same documentation says `none` is NOT
58
+ * supported and returns 400 - there is no way to switch this model's thinking off.
59
+ *
60
+ * `minimal` is `null` because MiniMax does not publish it. And MiniMax-M3 - the general model -
61
+ * is NOT here: its documentation does not give it these levels, so copying them onto it would be
62
+ * exactly the "copy a same-named model's levels" mistake this file exists to prevent.
63
+ */
64
+ const MINIMAX_FLASH_LEVELS = {
65
+ off: null,
66
+ minimal: null,
67
+ low: "low",
68
+ medium: "medium",
69
+ high: "high",
70
+ xhigh: "xhigh",
71
+ max: "max",
72
+ };
73
+ /**
74
+ * The official endpoint, or undefined.
75
+ *
76
+ * THE URL THAT ANSWERED, NOT THE ONE THAT WAS ASKED FOR. A fetch follows redirects, so the URL
77
+ * that answered can be a different endpoint from the one in the form - and it is the one that
78
+ * published whatever is being read.
79
+ */
80
+ function officialMinimaxEndpoint(baseUrl) {
81
+ try {
82
+ const parsed = new URL(baseUrl.trim());
83
+ if (parsed.origin !== MINIMAX_ORIGIN)
84
+ return false;
85
+ const path = parsed.pathname.replace(/\/+$/, "");
86
+ return MINIMAX_PATHS.has(path);
87
+ }
88
+ catch {
89
+ return false;
90
+ }
91
+ }
92
+ /**
93
+ * The levels a provider DECLARED for a model, when it declared them properly.
94
+ *
95
+ * THE DECLARATION IS A LIST OF LEVEL NAMES - `supported_reasoning_efforts: ["low","medium","high"]`
96
+ * on the model's own entry in the model list. That is the endpoint naming the values its model
97
+ * accepts, in the parameter's own vocabulary.
98
+ */
99
+ function declaredLevels(entry) {
100
+ const raw = entry.supported_reasoning_efforts;
101
+ if (!Array.isArray(raw))
102
+ return undefined;
103
+ const names = raw
104
+ .filter((value) => typeof value === "string")
105
+ .map((value) => value.trim())
106
+ .filter((value) => value.length > 0);
107
+ // AN EMPTY LIST IS NOT A DECLARATION. It is a field nobody filled in, and reading it as "this
108
+ // model has no levels" would switch off thinking for a model that has it.
109
+ if (!names.length)
110
+ return undefined;
111
+ const found = {};
112
+ for (const name of names) {
113
+ // ONLY THE EXACT NAMES Pi KNOWS. A name that is not one of them is DROPPED, not translated:
114
+ // guessing what a provider means by `ultra` is how a picker ends up offering a level the
115
+ // model does not have.
116
+ const level = EFFORT_TO_LEVEL.get(name);
117
+ if (!level)
118
+ continue;
119
+ found[level] = name;
120
+ }
121
+ if (!Object.keys(found).length)
122
+ return undefined;
123
+ // ALL SEVEN, every one of them. The levels nobody declared are `null`, because Pi enables the
124
+ // ordinary ones when the map is silent about them.
125
+ const map = {};
126
+ for (const level of PI_THINKING_LEVELS)
127
+ map[level] = found[level] ?? null;
128
+ return map;
129
+ }
130
+ /**
131
+ * THE LEVELS A MODEL OFFERS, or `undefined` when nobody said.
132
+ *
133
+ * `undefined` is not "no levels" - it is "nobody said", and the caller keeps whatever behaviour it
134
+ * had. A model that nobody described keeps Pi's own defaults, exactly as before.
135
+ */
136
+ export function discoverThinkingLevels(entry, context) {
137
+ // ONLY THE COMPATIBLE API. A level belongs to the API that published it: the same word means
138
+ // different things over different APIs, so an answer about one is never read as an answer about
139
+ // another. The API the form leaves empty is the default one, which is this one.
140
+ const api = (context.api ?? "").trim() || DEFAULT_API;
141
+ if (api !== DEFAULT_API)
142
+ return undefined;
143
+ // A PAYLOAD THAT SAYS THE MODEL DOES NOT THINK, AND ALSO PUBLISHES LEVELS, CONTRADICTS ITSELF.
144
+ // The explicit answer wins: the levels are dropped, because a map on a model that does not
145
+ // reason would offer levels Pi never shows (it offers `off` and nothing else).
146
+ if (entry.reasoning === false)
147
+ return undefined;
148
+ const declared = declaredLevels(entry);
149
+ if (declared)
150
+ return declared;
151
+ // THE OFFICIAL MINIMAX ENDPOINT, AND ONLY THAT ONE - the origin and the path both, because a map
152
+ // is only true of the endpoint it was learned from.
153
+ if (!officialMinimaxEndpoint(context.baseUrl))
154
+ return undefined;
155
+ const id = typeof entry.id === "string" ? entry.id.trim().toLowerCase() : "";
156
+ if (id !== MINIMAX_FLASH_MODEL)
157
+ return undefined;
158
+ return { ...MINIMAX_FLASH_LEVELS };
159
+ }
@@ -6,6 +6,7 @@ export type ModelFilterRule = {
6
6
  };
7
7
  import type { WorkflowRun } from "./workflow.js";
8
8
  import type { ScheduledTask } from "./scheduled-tasks.js";
9
+ import type { ThinkingLevelMap } from "../shared/thinking-levels.js";
9
10
  /**
10
11
  * The lifecycle states a `Conversation.status` moves through while a turn is in flight. `waiting` is the
11
12
  * gap between "prompt handed to the LLM" and "the first response token arrived" - holding it apart from
@@ -409,6 +410,14 @@ export type PublicProviderModel = {
409
410
  imageInput: boolean;
410
411
  contextWindow: number;
411
412
  maxTokens: number;
413
+ /**
414
+ * The thinking levels this model really offers, and what each one is sent as.
415
+ *
416
+ * ABSENT means "nobody said" - the map was never written, so Pi's own defaults apply. It is not
417
+ * the same as an empty map, because Pi reads a level the map does not mention as "the model has
418
+ * it".
419
+ */
420
+ thinkingLevelMap?: ThinkingLevelMap;
412
421
  };
413
422
  export type PublicProvider = {
414
423
  id: string;
@@ -448,6 +457,14 @@ export type DiscoveredModel = {
448
457
  imageInput: boolean;
449
458
  contextWindow: number;
450
459
  maxTokens: number;
460
+ /**
461
+ * The thinking levels the provider PUBLISHED for this model, and what each one is sent as.
462
+ *
463
+ * ABSENT when nobody published them, and that is the common case: a provider that lists a model
464
+ * without saying which effort levels it accepts has said nothing, and this must not pretend
465
+ * otherwise. The map names all seven levels, with `null` for the ones the model does not have.
466
+ */
467
+ thinkingLevelMap?: ThinkingLevelMap;
451
468
  };
452
469
  export type ModelCatalog = {
453
470
  source: "pi" | "unavailable";
@@ -474,6 +491,7 @@ export type Conversation = {
474
491
  status: RunStatus;
475
492
  messages: Message[];
476
493
  archivedAt?: string;
494
+ warmSession?: true;
477
495
  /**
478
496
  * Cumulative usage observed for this conversation: its OWN assistant messages AND the one-shot
479
497
  * (sub-agent) calls it dispatched.
@@ -963,7 +981,7 @@ export type TerminalShell = {
963
981
  file: string;
964
982
  args: string[];
965
983
  };
966
- export type ProjectStatus = "planning" | "awaiting_start" | "active" | "blocked" | "awaiting_approval" | "awaiting_review" | "completed" | "failed" | "cancelled";
984
+ export type ProjectStatus = "planning" | "awaiting_start" | "active" | "blocked" | "awaiting_approval" | "awaiting_review" | "failed" | "cancelled";
967
985
  /**
968
986
  * THE STATES A TASK CAN BE IN.
969
987
  *
@@ -1057,6 +1075,7 @@ export type ProjectReport = {
1057
1075
  id: string;
1058
1076
  projectId: string;
1059
1077
  taskId?: string;
1078
+ acceptedTaskIds?: string[];
1060
1079
  authorConversationId?: string;
1061
1080
  kind: "progress" | "blocked" | "delivery" | "decision_request" | "review";
1062
1081
  progress: string;
@@ -1231,6 +1250,13 @@ export type AppState = {
1231
1250
  * decision nobody has made yet.
1232
1251
  */
1233
1252
  unlockedChildConversationIds?: string[];
1253
+ warmSessions?: Array<{
1254
+ id: string;
1255
+ title: string;
1256
+ workspaceId: string;
1257
+ cwd?: string;
1258
+ savedAt: string;
1259
+ }>;
1234
1260
  /**
1235
1261
  * THE CLOCK THIS SERVER SCHEDULES BY. A scheduled task's 「每天 09:00」 is the SERVER's wall clock,
1236
1262
  * and the panel has to say so, because browser rendering 「下次」 may be on a different clock
@@ -1417,6 +1443,14 @@ export type ClientCommandBody =
1417
1443
  maxTokens?: number;
1418
1444
  supportsDeveloperRole?: boolean;
1419
1445
  supportsReasoningEffort?: boolean;
1446
+ /**
1447
+ * The thinking levels to write for this model.
1448
+ *
1449
+ * THE SAME THREE STATES THE FORM MEANS BY THEM: absent means "the form knows nothing", so
1450
+ * the saved levels stay; `null` means "this model has no levels", so the saved ones go; a
1451
+ * map means "these are the levels", and every one of Pi's seven is named.
1452
+ */
1453
+ thinkingLevelMap?: ThinkingLevelMap | null;
1420
1454
  }[];
1421
1455
  };
1422
1456
  }
@@ -1534,6 +1568,13 @@ export type ClientCommandBody =
1534
1568
  } | {
1535
1569
  type: "conversation.archive";
1536
1570
  conversationId: string;
1571
+ } | {
1572
+ type: "conversation.warm.save";
1573
+ conversationId: string;
1574
+ title: string;
1575
+ } | {
1576
+ type: "conversation.warm.delete";
1577
+ conversationId: string;
1537
1578
  } | {
1538
1579
  type: "conversation.unarchive";
1539
1580
  conversationId: string;
@@ -30,4 +30,6 @@ export declare function findUploadFile(uploadsDir: string, conversationId: strin
30
30
  size: number;
31
31
  } | null>;
32
32
  export declare function deleteConversationUploads(uploadsDir: string, conversationId: string): Promise<void>;
33
+ /** Gives each fork its own copy of the local images referenced by its history. */
34
+ export declare function copyForkUploads(uploadsDir: string, conversationId: string, forkedId: string, images: MessageImage[]): Promise<void>;
33
35
  export declare function loadConversationImages(uploadsDir: string, conversationId: string, images: MessageImage[]): Promise<PiImageContent[]>;
@@ -1,6 +1,6 @@
1
1
  import { existsSync } from "node:fs";
2
- import { mkdir, readdir, readFile, rm, stat, writeFile } from "node:fs/promises";
3
- import { extname, join } from "node:path";
2
+ import { copyFile, mkdir, readdir, readFile, realpath, rm, stat, writeFile } from "node:fs/promises";
3
+ import { basename, extname, isAbsolute, join, relative, sep } from "node:path";
4
4
  /** 5MB maximum decoded image payload, matching the source-file size ceiling in files.ts. */
5
5
  export const MAX_UPLOAD_BYTES = 5 * 1024 * 1024;
6
6
  /** 10MB maximum HTTP request body to safely handle base64 overhead before JSON parsing. */
@@ -141,6 +141,23 @@ export async function deleteConversationUploads(uploadsDir, conversationId) {
141
141
  const dir = join(uploadsDir, conversationId);
142
142
  await rm(dir, { recursive: true, force: true }).catch(() => { });
143
143
  }
144
+ /** Gives each fork its own copy of the local images referenced by its history. */
145
+ export async function copyForkUploads(uploadsDir, conversationId, forkedId, images) {
146
+ const root = await realpath(uploadsDir);
147
+ const target = join(root, forkedId);
148
+ await mkdir(target);
149
+ for (const id of new Set(images.map((image) => image.id))) {
150
+ const file = await findUploadFile(root, conversationId, id);
151
+ if (!file)
152
+ throw new Error("无法找到历史消息的附件,分叉未保存");
153
+ const source = await realpath(file.filePath);
154
+ const scoped = relative(join(root, conversationId), source);
155
+ if (!scoped || scoped === ".." || scoped.startsWith(`..${sep}`) || isAbsolute(scoped)) {
156
+ throw new Error("历史附件越出了上传目录,分叉未保存");
157
+ }
158
+ await copyFile(source, join(target, basename(file.filePath)));
159
+ }
160
+ }
144
161
  export async function loadConversationImages(uploadsDir, conversationId, images) {
145
162
  const result = [];
146
163
  for (const img of images) {
@@ -6,6 +6,7 @@ export type OverviewReport = {
6
6
  progress?: string;
7
7
  summary?: string;
8
8
  evidenceRefs?: string[];
9
+ acceptedTaskIds?: string[];
9
10
  createdAt?: string;
10
11
  };
11
12
  export type OverviewDecision = {
@@ -39,6 +40,14 @@ export type OverviewProject = {
39
40
  /** Internal coordination is not a request for the user's attention. */
40
41
  export declare function userProjectDecisions(project: OverviewProject): OverviewDecision[];
41
42
  export declare function ownerProjectReports(project: OverviewProject): OverviewReport[];
43
+ export declare function latestProjectDelivery<T extends OverviewReport>(project: {
44
+ ownerConversationId?: string;
45
+ reports?: T[];
46
+ }): T | undefined;
47
+ export declare function deliveryCoversTasks(delivery: OverviewReport | undefined, tasks: {
48
+ id: string;
49
+ updatedAt?: string;
50
+ }[]): boolean;
42
51
  export declare function projectUserOverview(project: OverviewProject): {
43
52
  label: string;
44
53
  summary: string;
@@ -5,20 +5,34 @@ export function userProjectDecisions(project) {
5
5
  export function ownerProjectReports(project) {
6
6
  return (project.reports ?? []).filter(report => !report.taskId && ["progress", "delivery"].includes(report.kind ?? "")
7
7
  && (report.authorConversationId === project.ownerConversationId && Boolean(project.ownerConversationId)
8
- || project.status === "completed" && report.kind === "delivery" && !report.authorConversationId));
8
+ || report.kind === "delivery" && !report.authorConversationId));
9
+ }
10
+ export function latestProjectDelivery(project) {
11
+ return [...(project.reports ?? [])].reverse().find(report => report.kind === "delivery" && !report.taskId
12
+ && (!report.authorConversationId || report.authorConversationId === project.ownerConversationId));
13
+ }
14
+ export function deliveryCoversTasks(delivery, tasks) {
15
+ if (!delivery)
16
+ return false;
17
+ if (delivery.acceptedTaskIds) {
18
+ const accepted = new Set(delivery.acceptedTaskIds);
19
+ return tasks.every(task => accepted.has(task.id));
20
+ }
21
+ const deliveredAt = delivery.createdAt ? Date.parse(delivery.createdAt) : NaN;
22
+ return Number.isFinite(deliveredAt) && tasks.every(task => !task.updatedAt || Date.parse(task.updatedAt) <= deliveredAt);
9
23
  }
10
24
  export function projectUserOverview(project) {
11
25
  const decisions = userProjectDecisions(project);
12
26
  const reports = ownerProjectReports(project);
13
27
  const progress = [...reports].reverse().find(report => report.kind === "progress");
14
- const delivery = [...reports].reverse().find(report => report.kind === "delivery");
15
- const ended = ["completed", "cancelled", "failed"].includes(project.status);
28
+ const delivery = latestProjectDelivery(project);
29
+ const ended = ["cancelled", "failed"].includes(project.status);
16
30
  const owner = project.resources?.sessions?.find(session => session.id === project.ownerConversationId);
17
31
  const busy = (project.resources?.activeWorkers ?? 0) > 0 || ["running", "waiting", "awaiting_background"].includes(owner?.status ?? "");
18
- const label = project.status === "completed" ? "已交付" : project.status === "cancelled" ? "已取消" : project.status === "failed" ? "执行暂停"
19
- : decisions.length ? "需要你决定" : busy ? "正在推进" : !project.ownerConversationId ? "待启动" : ["failed", "stopped"].includes(owner?.status ?? "") ? "执行暂停" : "未交付";
20
- const summary = project.status === "completed" ? project.summary?.trim() || delivery?.progress?.trim() || delivery?.summary?.trim() || "交付已完成,成果与验证记录见下方。"
21
- : progress?.progress?.trim() || progress?.summary?.trim() || (ended ? "项目已结束,已有记录会保留。" : "已交由负责人推进,进展和成果会在这里汇总。");
32
+ const label = project.status === "cancelled" ? "已取消" : project.status === "failed" ? "执行暂停"
33
+ : decisions.length ? "需要你决定" : busy ? "正在推进" : !project.ownerConversationId ? "待启动" : ["failed", "stopped"].includes(owner?.status ?? "") ? "执行暂停" : delivery ? "待继续" : "未交付";
34
+ const summary = progress?.progress?.trim() || progress?.summary?.trim() || (ended ? "项目已结束,已有记录会保留。"
35
+ : delivery ? "可继续安排新任务或追加验证。" : "已交由负责人推进,进展和成果会在这里汇总。");
22
36
  return { label, summary, progress, delivery, decisions, ended,
23
37
  deliveryLabel: project.mode === "lightweight" ? "自评交付" : "交付成果" };
24
38
  }
@@ -1,3 +1,4 @@
1
+ import { type OverviewReport } from "./project-overview.js";
1
2
  /** Business phases are persisted; activity is a read-only projection of current execution. */
2
3
  export type ProjectActivity = {
3
4
  kind: string;
@@ -19,6 +20,7 @@ export type ActivityTask = {
19
20
  ownerConversationId?: string;
20
21
  reviewerConversationId?: string;
21
22
  dependencies?: string[];
23
+ updatedAt?: string;
22
24
  review?: {
23
25
  verdict?: string;
24
26
  lightweight?: boolean;
@@ -29,6 +31,7 @@ export type ActivityProject = {
29
31
  mode?: string;
30
32
  ownerConversationId?: string;
31
33
  tasks?: ActivityTask[];
34
+ reports?: OverviewReport[];
32
35
  resources?: {
33
36
  activeWorkers?: number;
34
37
  sessions?: ActivitySession[];