@evandu/super-pi 0.1.323 → 0.1.324
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/agents/super-pi-managed-model/index.ts +8 -1
- package/dist/.super-pi-check-inputs.json +2 -2
- package/dist/client/.super-pi-client-sources.json +16 -11
- package/dist/client/assets/{CodeMirrorEditor-Di528QwW.js → CodeMirrorEditor-eVHUQY8Y.js} +1 -1
- package/dist/client/assets/{GitDiffEditor-CkuipKc9.js → GitDiffEditor-Cebgkg-9.js} +1 -1
- package/dist/client/assets/index-A2acEU1u.css +1 -0
- package/dist/client/assets/index-D9r6d2wH.js +363 -0
- package/dist/client/index.html +2 -2
- package/dist/server/application/group-chat-service.js +54 -4
- package/dist/server/application/provider-service.d.ts +2 -0
- package/dist/server/application/provider-service.js +28 -0
- package/dist/server/application/run-service.d.ts +2 -0
- package/dist/server/application/run-service.js +14 -2
- package/dist/server/group-primary-executor.js +9 -1
- package/dist/server/http-server.js +2 -2
- package/dist/server/managed-http.js +87 -18
- package/dist/server/managed-model-adapter.d.ts +8 -0
- package/dist/server/managed-model-adapter.js +46 -2
- package/dist/server/managed-model-gateway.d.ts +38 -0
- package/dist/server/managed-model-gateway.js +24 -3
- package/dist/server/managed-servers.d.ts +1 -0
- package/dist/server/managed-servers.js +15 -8
- package/dist/server/runtime.d.ts +1 -0
- package/dist/server/shared-model-catalog.d.ts +8 -0
- package/dist/server/shared-model-catalog.js +45 -0
- package/dist/server/store.d.ts +11 -1
- package/dist/server/store.js +85 -1
- package/dist/server/types.d.ts +9 -0
- package/dist/server/ws-server.d.ts +2 -2
- package/dist/server/ws-server.js +19 -5
- package/dist/shared/group-chat.d.ts +2 -0
- package/dist/shared/managed-servers.d.ts +1 -0
- package/dist/shared/model-configuration.d.ts +12 -0
- package/dist/shared/model-configuration.js +3 -0
- package/dist/shared/request-timing.d.ts +8 -0
- package/dist/shared/request-timing.js +1 -0
- package/package.json +1 -1
- package/dist/client/assets/index-CjV5_OmA.css +0 -1
- package/dist/client/assets/index-DLXLkcyw.js +0 -363
|
@@ -14,6 +14,7 @@ import { proxyThroughSsh, proxyWebSocketThroughSsh, tunnelJson } from "./managed
|
|
|
14
14
|
import { installRemote, startRemote, stopRemote } from "./remote-bootstrap.js";
|
|
15
15
|
import { discoverManagedInstallations, recoverySummary } from "./managed-recovery.js";
|
|
16
16
|
import { isServiceListenHost } from "../shared/managed-servers.js";
|
|
17
|
+
import { isModelConfigurationMode } from "../shared/model-configuration.js";
|
|
17
18
|
import { discoverExistingInstallation } from "./existing-service.js";
|
|
18
19
|
import { publishedServerUpdate } from "./published-server-update.js";
|
|
19
20
|
import { directJson, serviceOrigin, defaultServiceOrigin, probeServiceEndpoint, proxyThroughDirect, proxyWebSocketThroughDirect } from "./managed-http-direct.js";
|
|
@@ -417,7 +418,7 @@ export class ManagedServers {
|
|
|
417
418
|
if (reload && entry.profile.modelTransport === "direct" && relay?.readyState !== WebSocket.OPEN)
|
|
418
419
|
throw new Error("服务端口的模型通道正在连接,请稍后重试");
|
|
419
420
|
if (reload && entry.installation && secret && relay?.readyState === WebSocket.OPEN && entry.profile.serviceUrl) {
|
|
420
|
-
const body = JSON.stringify({
|
|
421
|
+
const body = JSON.stringify({ ...await this.gateway.catalogBundle(force), defaultModel: this.defaultModel(), entryIntegrations: this.integrations?.available() });
|
|
421
422
|
const hash = createHash("sha256").update(body).digest("hex");
|
|
422
423
|
if (!force && this.syncedRelays.get(relay) === hash)
|
|
423
424
|
return;
|
|
@@ -435,16 +436,19 @@ export class ManagedServers {
|
|
|
435
436
|
const directBootstrap = !reload && entry.profile.modelTransport === "direct";
|
|
436
437
|
if (!entry.installation || (!entry.reversePort && !directBootstrap) || !client || !secret)
|
|
437
438
|
throw new Error("请先部署并连接此服务器");
|
|
438
|
-
const
|
|
439
|
+
const catalog = await this.gateway.catalogBundle(force);
|
|
439
440
|
const endpoint = directBootstrap ? `http://127.0.0.1:${entry.profile.servicePort}/api/managed-model/invoke` : `http://127.0.0.1:${entry.reversePort}/model`;
|
|
440
|
-
const
|
|
441
|
-
const hash = createHash("sha256").update(
|
|
442
|
-
if (hash === entry.modelHash)
|
|
441
|
+
const config = { endpoint, token: secret.modelToken, ...catalog, defaultModel: this.defaultModel(), entryIntegrations: this.integrations?.available() };
|
|
442
|
+
const hash = createHash("sha256").update(JSON.stringify(config)).digest("hex");
|
|
443
|
+
if (!force && hash === entry.modelHash)
|
|
443
444
|
return;
|
|
445
|
+
const content = JSON.stringify({ ...config, sharedCatalogAt: new Date().toISOString() });
|
|
444
446
|
await sshWrite(client, posix.join(entry.installation.root, "models.json"), content);
|
|
445
|
-
const defaultModel = this.defaultModel() ?? (models[0] ? { provider: models[0].provider, modelId: models[0].id } : undefined);
|
|
446
|
-
|
|
447
|
-
|
|
447
|
+
const defaultModel = this.defaultModel() ?? (catalog.models[0] ? { provider: catalog.models[0].provider, modelId: catalog.models[0].id } : undefined);
|
|
448
|
+
const settingsPath = posix.join(entry.installation.root, "agent", "settings.json");
|
|
449
|
+
if (!reload && defaultModel && (await sshExec(client, `test -e ${sh(settingsPath)} && echo present || true`)).trim() !== "present") {
|
|
450
|
+
await sshWrite(client, settingsPath, JSON.stringify({ defaultProvider: defaultModel.provider, defaultModel: defaultModel.modelId }));
|
|
451
|
+
}
|
|
448
452
|
if (reload)
|
|
449
453
|
await this.serviceJson(entry, "/api/managed-model/reload", "POST");
|
|
450
454
|
entry.modelHash = hash;
|
|
@@ -514,6 +518,8 @@ export class ManagedServers {
|
|
|
514
518
|
profile.transport = "direct";
|
|
515
519
|
profile.service = "online";
|
|
516
520
|
delete profile.serviceError;
|
|
521
|
+
if (isModelConfigurationMode(health.modelMode))
|
|
522
|
+
profile.modelMode = health.modelMode;
|
|
517
523
|
if (entry.installation && health.modelRelay === true && !this.stopped) {
|
|
518
524
|
profile.modelTransport = "direct";
|
|
519
525
|
delete profile.modelChannelPaused;
|
|
@@ -1019,6 +1025,7 @@ export class ManagedServers {
|
|
|
1019
1025
|
else if (action === "sync") {
|
|
1020
1026
|
try {
|
|
1021
1027
|
await this.syncModels(id, true);
|
|
1028
|
+
delete entry.profile.modelError;
|
|
1022
1029
|
}
|
|
1023
1030
|
catch (error) {
|
|
1024
1031
|
entry.profile.modelError = error instanceof Error ? error.message : "模型同步失败";
|
package/dist/server/runtime.d.ts
CHANGED
|
@@ -277,6 +277,7 @@ export type GroupExecutionLifecycle = {
|
|
|
277
277
|
export type IsolatedCompletionInput = {
|
|
278
278
|
images?: import("./types.js").PiImageContent[];
|
|
279
279
|
onConversation?(conversationId: string): Promise<void> | void;
|
|
280
|
+
onRequest?(messageId: string): Promise<void> | void;
|
|
280
281
|
userToolContext?: {
|
|
281
282
|
id: string;
|
|
282
283
|
workspaceId: string;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Model } from "@earendil-works/pi-ai";
|
|
2
|
+
export type SharedCatalogModel = Pick<Model<string>, "provider" | "id" | "name" | "api" | "baseUrl" | "reasoning" | "input" | "cost" | "contextWindow" | "maxTokens" | "thinkingLevelMap"> & {
|
|
3
|
+
compat?: Record<string, boolean | string>;
|
|
4
|
+
};
|
|
5
|
+
export declare const validSharedProviderId: (id: unknown) => id is string;
|
|
6
|
+
/** Project only model definitions. URLs with embedded authentication or query parameters stay local. */
|
|
7
|
+
export declare function sharedCatalogModels(models: readonly unknown[]): SharedCatalogModel[];
|
|
8
|
+
export declare function sharedProviderModels(models: readonly SharedCatalogModel[]): Map<string, Omit<SharedCatalogModel, "provider">[]>;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { PI_THINKING_LEVELS } from "../shared/thinking-levels.js";
|
|
2
|
+
export const validSharedProviderId = (id) => typeof id === "string" && /^[a-z0-9_.-]{1,160}$/i.test(id) && !Object.hasOwn(Object.prototype, id) && id !== "prototype";
|
|
3
|
+
const compatibilityFlags = ["supportsDeveloperRole", "supportsReasoningEffort", "supportsStore", "supportsStrictMode", "requiresToolResultName", "requiresAssistantAfterToolResult", "requiresThinkingAsText", "supportsUsageInStreaming"];
|
|
4
|
+
const compatibilityChoices = {
|
|
5
|
+
maxTokensField: ["max_tokens", "max_completion_tokens"],
|
|
6
|
+
thinkingFormat: ["ant-ling", "baseten", "chat-template", "deepseek", "openai", "openrouter", "qwen", "qwen-chat-template", "string-thinking", "together", "zai"],
|
|
7
|
+
};
|
|
8
|
+
/** Project only model definitions. URLs with embedded authentication or query parameters stay local. */
|
|
9
|
+
export function sharedCatalogModels(models) {
|
|
10
|
+
return models.flatMap(value => {
|
|
11
|
+
const model = value;
|
|
12
|
+
if (!model || !validSharedProviderId(model.provider) || typeof model.id !== "string" || !model.id ||
|
|
13
|
+
typeof model.api !== "string" || typeof model.baseUrl !== "string" || typeof model.name !== "string")
|
|
14
|
+
return [];
|
|
15
|
+
try {
|
|
16
|
+
const url = new URL(model.baseUrl);
|
|
17
|
+
if (!["http:", "https:"].includes(url.protocol) || url.username || url.password || url.search || url.hash)
|
|
18
|
+
return [];
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
return [];
|
|
22
|
+
}
|
|
23
|
+
const number = (value) => typeof value === "number" && Number.isFinite(value) && value >= 0 ? value : 0;
|
|
24
|
+
const cost = { input: number(model.cost?.input), output: number(model.cost?.output), cacheRead: number(model.cost?.cacheRead), cacheWrite: number(model.cost?.cacheWrite) };
|
|
25
|
+
const thinkingLevelMap = Object.fromEntries(PI_THINKING_LEVELS.flatMap(level => {
|
|
26
|
+
const value = model.thinkingLevelMap?.[level];
|
|
27
|
+
return value === null || typeof value === "number" || (typeof value === "string" && /^[a-z0-9_-]{1,32}$/i.test(value)) ? [[level, value]] : [];
|
|
28
|
+
}));
|
|
29
|
+
const compat = model.compat && Object.fromEntries(Object.entries(model.compat).filter(([key, value]) => typeof value === "boolean" ? compatibilityFlags.includes(key) :
|
|
30
|
+
typeof value === "string" && Object.hasOwn(compatibilityChoices, key) && compatibilityChoices[key].includes(value)));
|
|
31
|
+
const input = Array.isArray(model.input) && model.input.includes("image") ? ["text", "image"] : ["text"];
|
|
32
|
+
return [{ provider: model.provider, id: model.id, name: model.name, api: model.api, baseUrl: model.baseUrl,
|
|
33
|
+
reasoning: model.reasoning === true, input, cost, contextWindow: number(model.contextWindow), maxTokens: number(model.maxTokens),
|
|
34
|
+
...(Object.keys(thinkingLevelMap).length ? { thinkingLevelMap } : {}), ...(compat && Object.keys(compat).length ? { compat } : {}) }];
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
export function sharedProviderModels(models) {
|
|
38
|
+
const providers = new Map();
|
|
39
|
+
for (const { provider, ...model } of models) {
|
|
40
|
+
const group = providers.get(provider) ?? [];
|
|
41
|
+
group.push(model);
|
|
42
|
+
providers.set(provider, group);
|
|
43
|
+
}
|
|
44
|
+
return providers;
|
|
45
|
+
}
|
package/dist/server/store.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ import type { WorkflowRun } from "./workflow.js";
|
|
|
7
7
|
import type { AppState, BackgroundTaskSummary, Conversation, Message, MessageDelivery, MessageImage, ModelSelection, Project, SubagentRun, SubagentRunUpdate, TodoItem, ToolCallQuestion, ToolCallArg, ToolCallBlock, ToolResultSummary, Workspace } from "./types.js";
|
|
8
8
|
import { type BackgroundCompletion } from "../shared/background-task.js";
|
|
9
9
|
import type { TurnUsageReadout } from "./conversation-usage.js";
|
|
10
|
+
import type { RequestOutcome } from "../shared/request-timing.js";
|
|
10
11
|
/** Mints the id a forked conversation will have, BEFORE its Pi transcript exists.
|
|
11
12
|
*
|
|
12
13
|
* Exported because the ordering demands it and no other arrangement provides it. Pi's copied file's header
|
|
@@ -499,7 +500,7 @@ export declare class Store {
|
|
|
499
500
|
* `composePrompt` in the run service). So the instruction reaches the model the same way, and the
|
|
500
501
|
* reader sees who spoke.
|
|
501
502
|
*/
|
|
502
|
-
addAgentMessage(conversationId: string, content: string, options?: Pick<Message, "delivery" | "source" | "images">): Promise<Message>;
|
|
503
|
+
addAgentMessage(conversationId: string, content: string, options?: Pick<Message, "delivery" | "source" | "images" | "requestTiming" | "timingRequestIds">): Promise<Message>;
|
|
503
504
|
addUserMessage(conversationId: string, content: string, images?: MessageImage[], attachments?: import("./types.js").MessageAttachments, options?: {
|
|
504
505
|
clientId?: string;
|
|
505
506
|
delivery?: Message["delivery"];
|
|
@@ -773,6 +774,15 @@ export declare class Store {
|
|
|
773
774
|
private waitingMessages;
|
|
774
775
|
private requireWaitingMessage;
|
|
775
776
|
private persistMessages;
|
|
777
|
+
requestTiming(conversationId: string, messageId: string): {
|
|
778
|
+
startedAt?: string;
|
|
779
|
+
responseEndedAt?: string;
|
|
780
|
+
endedAt?: string;
|
|
781
|
+
outcome?: RequestOutcome;
|
|
782
|
+
} | undefined;
|
|
783
|
+
private linkRequestTiming;
|
|
784
|
+
private settleRequests;
|
|
785
|
+
finishRequestReply(conversationId: string, replyId: string, promptId: string, outcome: RequestOutcome): Promise<void>;
|
|
776
786
|
/**
|
|
777
787
|
* Claims one waiting message for delivery to the live Pi process: `waiting` becomes `sending`, and the
|
|
778
788
|
* message STAYS WHERE IT IS - still on screen, still in the transcript, still at the same index.
|
package/dist/server/store.js
CHANGED
|
@@ -624,6 +624,7 @@ function backgroundTaskMessage(conversation, task, outcome, content, deliver) {
|
|
|
624
624
|
content,
|
|
625
625
|
createdAt: finished.finishedAt,
|
|
626
626
|
backgroundTask: anchored ? { ...finished, output: undefined } : finished,
|
|
627
|
+
...(origin?.timingRequestIds?.length ? { timingRequestIds: origin.timingRequestIds } : {}),
|
|
627
628
|
...(deliver && !conversation.archivedAt ? { delivery: "waiting" } : {}),
|
|
628
629
|
};
|
|
629
630
|
conversation.messages.push(message);
|
|
@@ -759,6 +760,15 @@ export class Store {
|
|
|
759
760
|
const orphanedTasks = reconcileBackgroundTasks(state);
|
|
760
761
|
const interrupted = reconcileConversations(state);
|
|
761
762
|
const requeued = reconcileWaitingMessages(state);
|
|
763
|
+
let interruptedTiming = false;
|
|
764
|
+
for (const conversation of state.conversations)
|
|
765
|
+
for (const message of conversation?.messages ?? []) {
|
|
766
|
+
const timing = message.requestTiming;
|
|
767
|
+
if (timing?.startedAt && !timing.outcome) {
|
|
768
|
+
timing.outcome = "interrupted";
|
|
769
|
+
interruptedTiming = true;
|
|
770
|
+
}
|
|
771
|
+
}
|
|
762
772
|
const todos = reconcileTodos(state);
|
|
763
773
|
// THE USAGE SWEEP. A run recorded before the conversation ledger existed has its money sitting in
|
|
764
774
|
// the run record and nowhere else, so the ledger is brought up to date here - once, and only
|
|
@@ -768,7 +778,7 @@ export class Store {
|
|
|
768
778
|
// Persisted here, in `open`, rather than left for the first unrelated write: a reconciled record that
|
|
769
779
|
// is only rewritten by a later mutation would still read `running` to anything that opened the file
|
|
770
780
|
// in the meantime, and would be reconciled a SECOND time on the next restart.
|
|
771
|
-
if (defaulted || migratedProjects || orphaned.length || orphanedWorkflows.length || orphanedTasks.changed || interrupted.length || requeued.recovered.length || requeued.changed || todos.changed || foldedUsage) {
|
|
781
|
+
if (defaulted || migratedProjects || orphaned.length || orphanedWorkflows.length || orphanedTasks.changed || interrupted.length || interruptedTiming || requeued.recovered.length || requeued.changed || todos.changed || foldedUsage) {
|
|
772
782
|
for (const run of orphaned)
|
|
773
783
|
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.`);
|
|
774
784
|
for (const plan of orphanedWorkflows)
|
|
@@ -1987,6 +1997,10 @@ export class Store {
|
|
|
1987
1997
|
message.images = structuredClone(options.images);
|
|
1988
1998
|
if (options?.delivery)
|
|
1989
1999
|
message.delivery = options.delivery;
|
|
2000
|
+
if (options?.requestTiming)
|
|
2001
|
+
message.requestTiming = {};
|
|
2002
|
+
if (options?.timingRequestIds?.length)
|
|
2003
|
+
message.timingRequestIds = [...options.timingRequestIds];
|
|
1990
2004
|
conversation.messages.push(message);
|
|
1991
2005
|
if (message.source === "session-reminder" && !message.delivery)
|
|
1992
2006
|
await this.persistIncomingTurn(conversation, message);
|
|
@@ -2731,6 +2745,71 @@ export class Store {
|
|
|
2731
2745
|
async persistMessages(conversation, acceptedSendId, metadata) {
|
|
2732
2746
|
await this.persistTransaction({ kind: "conversation.messages", conversationId: conversation.id, messages: structuredClone(conversation.messages), updatedAt: conversation.updatedAt, ...(acceptedSendId ? { acceptedSendId } : {}), ...(metadata ? { metadata: structuredClone(metadata) } : {}) });
|
|
2733
2747
|
}
|
|
2748
|
+
requestTiming(conversationId, messageId) {
|
|
2749
|
+
const timing = this.state.conversations.find(item => item.id === conversationId)?.messages.find(item => item.id === messageId)?.requestTiming;
|
|
2750
|
+
return timing && { ...timing };
|
|
2751
|
+
}
|
|
2752
|
+
linkRequestTiming(conversation, prompts, assistant) {
|
|
2753
|
+
const ids = new Set(prompts.flatMap(message => {
|
|
2754
|
+
if (message.role === "user" || message.requestTiming) {
|
|
2755
|
+
message.requestTiming ??= {};
|
|
2756
|
+
message.requestTiming.startedAt ??= assistant.createdAt;
|
|
2757
|
+
return [message.id];
|
|
2758
|
+
}
|
|
2759
|
+
return message.timingRequestIds ?? [];
|
|
2760
|
+
}));
|
|
2761
|
+
if (!ids.size)
|
|
2762
|
+
return;
|
|
2763
|
+
assistant.timingRequestIds = [...ids];
|
|
2764
|
+
for (const message of conversation.messages)
|
|
2765
|
+
if (ids.has(message.id) && message.requestTiming?.outcome === "incomplete") {
|
|
2766
|
+
delete message.requestTiming.endedAt;
|
|
2767
|
+
delete message.requestTiming.outcome;
|
|
2768
|
+
}
|
|
2769
|
+
}
|
|
2770
|
+
settleRequests(conversation, ids, outcome = "completed") {
|
|
2771
|
+
if (!ids.length)
|
|
2772
|
+
return;
|
|
2773
|
+
const requested = new Set(ids);
|
|
2774
|
+
const messagesById = new Map(conversation.messages.map(message => [message.id, message]));
|
|
2775
|
+
const pending = new Set();
|
|
2776
|
+
if (outcome === "completed") {
|
|
2777
|
+
for (const message of conversation.messages) {
|
|
2778
|
+
if (message.delivery || (message.role === "assistant" && !message.timingReplyEnded)) {
|
|
2779
|
+
for (const id of message.timingRequestIds ?? [])
|
|
2780
|
+
if (requested.has(id))
|
|
2781
|
+
pending.add(id);
|
|
2782
|
+
}
|
|
2783
|
+
}
|
|
2784
|
+
for (const task of this.state.backgroundTasks) {
|
|
2785
|
+
if (task.conversationId !== conversation.id || !task.originMessageId)
|
|
2786
|
+
continue;
|
|
2787
|
+
for (const id of messagesById.get(task.originMessageId)?.timingRequestIds ?? [])
|
|
2788
|
+
if (requested.has(id))
|
|
2789
|
+
pending.add(id);
|
|
2790
|
+
}
|
|
2791
|
+
}
|
|
2792
|
+
const endedAt = now();
|
|
2793
|
+
for (const id of requested) {
|
|
2794
|
+
const timing = messagesById.get(id)?.requestTiming;
|
|
2795
|
+
if (!timing?.responseEndedAt || timing.outcome || pending.has(id))
|
|
2796
|
+
continue;
|
|
2797
|
+
timing.endedAt = endedAt;
|
|
2798
|
+
timing.outcome = outcome;
|
|
2799
|
+
}
|
|
2800
|
+
}
|
|
2801
|
+
async finishRequestReply(conversationId, replyId, promptId, outcome) {
|
|
2802
|
+
const conversation = this.requireConversation(conversationId);
|
|
2803
|
+
const assistant = conversation.messages.find(message => message.id === replyId);
|
|
2804
|
+
if (!assistant?.timingRequestIds?.length || assistant.timingReplyEnded)
|
|
2805
|
+
return;
|
|
2806
|
+
assistant.timingReplyEnded = true;
|
|
2807
|
+
const prompt = conversation.messages.find(message => message.id === promptId);
|
|
2808
|
+
if (prompt?.requestTiming)
|
|
2809
|
+
prompt.requestTiming.responseEndedAt ??= now();
|
|
2810
|
+
this.settleRequests(conversation, assistant.timingRequestIds, outcome);
|
|
2811
|
+
await this.persistMessages(conversation);
|
|
2812
|
+
}
|
|
2734
2813
|
/**
|
|
2735
2814
|
* Claims one waiting message for delivery to the live Pi process: `waiting` becomes `sending`, and the
|
|
2736
2815
|
* message STAYS WHERE IT IS - still on screen, still in the transcript, still at the same index.
|
|
@@ -2843,6 +2922,7 @@ export class Store {
|
|
|
2843
2922
|
if (message.delivery === "sending")
|
|
2844
2923
|
throw new Error("这条消息已经交给 Agent 了,取消不掉(Pi 没有撤回单条队列消息的能力)");
|
|
2845
2924
|
const [removed] = conversation.messages.splice(index, 1);
|
|
2925
|
+
this.settleRequests(conversation, removed.timingRequestIds ?? []);
|
|
2846
2926
|
await this.persistMessages(conversation);
|
|
2847
2927
|
return structuredClone(removed);
|
|
2848
2928
|
}
|
|
@@ -2942,6 +3022,7 @@ export class Store {
|
|
|
2942
3022
|
conversation.messages.splice(deliveryIndex, 0, user);
|
|
2943
3023
|
delete user.delivery;
|
|
2944
3024
|
const assistant = { id: id("message"), role: "assistant", content: "", createdAt: now(), ...(agentIdentity ? { agentIdentity: structuredClone(agentIdentity) } : {}) };
|
|
3025
|
+
this.linkRequestTiming(conversation, [user], assistant);
|
|
2945
3026
|
conversation.messages.splice(deliveryIndex + 1, 0, assistant);
|
|
2946
3027
|
await this.persistMessages(conversation);
|
|
2947
3028
|
return { user: structuredClone(user), assistant: structuredClone(assistant) };
|
|
@@ -2998,6 +3079,7 @@ export class Store {
|
|
|
2998
3079
|
}
|
|
2999
3080
|
conversation.messages.splice(deliveryIndex, 0, ...batch);
|
|
3000
3081
|
const assistant = { id: id("message"), role: "assistant", content: "", createdAt: now(), ...(agentIdentity ? { agentIdentity: structuredClone(agentIdentity) } : {}) };
|
|
3082
|
+
this.linkRequestTiming(conversation, batch, assistant);
|
|
3001
3083
|
conversation.messages.splice(deliveryIndex + batch.length, 0, assistant);
|
|
3002
3084
|
const firstUser = conversation.messages.find((item) => item.role === "user");
|
|
3003
3085
|
const autoTitle = firstUser?.content.trim()
|
|
@@ -3162,6 +3244,8 @@ export class Store {
|
|
|
3162
3244
|
const conversation = this.state.conversations.find(item => item.id === task.conversationId);
|
|
3163
3245
|
this.state.backgroundTasks = this.state.backgroundTasks.filter(item => item.id !== taskId);
|
|
3164
3246
|
const message = conversation && backgroundTaskMessage(conversation, task, outcome, content, deliver);
|
|
3247
|
+
if (conversation && message && !message.delivery)
|
|
3248
|
+
this.settleRequests(conversation, message.timingRequestIds ?? []);
|
|
3165
3249
|
if (message?.delivery === "waiting" && conversation) {
|
|
3166
3250
|
const waiting = this.waitingMessages(conversation);
|
|
3167
3251
|
const lastSending = waiting.reduce((last, item, index) => item.delivery === "sending" ? index : last, -1);
|
package/dist/server/types.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ export type ModelFilterRule = {
|
|
|
7
7
|
import type { WorkflowRun } from "./workflow.js";
|
|
8
8
|
import type { BackgroundTaskDetails } from "../shared/background-task.js";
|
|
9
9
|
import type { GroupActivityUpdate } from "../shared/group-chat.js";
|
|
10
|
+
import type { RequestTiming } from "../shared/request-timing.js";
|
|
10
11
|
import type { ScheduledTask } from "./scheduled-tasks.js";
|
|
11
12
|
import type { ThinkingLevelMap } from "../shared/thinking-levels.js";
|
|
12
13
|
import type { ConversationCompaction } from "../shared/context-compaction.js";
|
|
@@ -114,6 +115,9 @@ export type ToolCallQuestion = {
|
|
|
114
115
|
answers?: QuestionAnswer[];
|
|
115
116
|
};
|
|
116
117
|
export type Message = {
|
|
118
|
+
requestTiming?: RequestTiming;
|
|
119
|
+
timingRequestIds?: string[];
|
|
120
|
+
timingReplyEnded?: boolean;
|
|
117
121
|
actualModel?: ModelSelection;
|
|
118
122
|
backgroundBatch?: Pick<Message, "id" | "content" | "createdAt" | "backgroundTask">[];
|
|
119
123
|
batchedInto?: string;
|
|
@@ -1737,6 +1741,7 @@ export type ClientCommandBody =
|
|
|
1737
1741
|
} | {
|
|
1738
1742
|
type: "state.subscribe";
|
|
1739
1743
|
conversationId?: string;
|
|
1744
|
+
transcriptRevision?: string;
|
|
1740
1745
|
}
|
|
1741
1746
|
/** Asks for the agent catalog read from disk. Answered by `agent.catalog`. */
|
|
1742
1747
|
| {
|
|
@@ -2096,6 +2101,10 @@ export type ServerEvent = {
|
|
|
2096
2101
|
} | {
|
|
2097
2102
|
type: "state";
|
|
2098
2103
|
state: AppState;
|
|
2104
|
+
retainedTranscript?: {
|
|
2105
|
+
conversationId: string;
|
|
2106
|
+
revision: string;
|
|
2107
|
+
};
|
|
2099
2108
|
} | {
|
|
2100
2109
|
type: "message.delta";
|
|
2101
2110
|
conversationId: string;
|
|
@@ -74,8 +74,8 @@ export declare class WsBroadcaster implements EventBroadcaster {
|
|
|
74
74
|
conversationId?: string;
|
|
75
75
|
}): void;
|
|
76
76
|
unregister(socket: WebSocket): void;
|
|
77
|
-
subscribe(socket: WebSocket, conversationId?: string): void;
|
|
78
|
-
sendState(socket: WebSocket): void;
|
|
77
|
+
subscribe(socket: WebSocket, conversationId?: string, transcriptRevision?: string): void;
|
|
78
|
+
sendState(socket: WebSocket, transcriptRevision?: string): void;
|
|
79
79
|
private scheduleRuntimeReplay;
|
|
80
80
|
private clearRuntimeReplay;
|
|
81
81
|
subscribeFileIndex(socket: WebSocket, workspaceId?: string, cwd?: string): void;
|
package/dist/server/ws-server.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { isBrowserAuthorized } from "./browser-access.js";
|
|
2
|
+
import { createHash } from "node:crypto";
|
|
2
3
|
import { WebSocket, WebSocketServer } from "ws";
|
|
3
4
|
import { remoteModelRelay } from "./managed-model-relay.js";
|
|
4
5
|
import { isAuthorized, isLoopbackAddress } from "./http-server.js";
|
|
@@ -110,14 +111,14 @@ export class WsBroadcaster {
|
|
|
110
111
|
this.fileIndexScopes.delete(socket);
|
|
111
112
|
this.sockets.delete(socket);
|
|
112
113
|
}
|
|
113
|
-
subscribe(socket, conversationId) {
|
|
114
|
+
subscribe(socket, conversationId, transcriptRevision) {
|
|
114
115
|
// Finish the old transcript before replacing it. A later delta then belongs to the new scope,
|
|
115
116
|
// and the authoritative snapshot reconstructs anything not streamed while it was unselected.
|
|
116
117
|
this.flushStreaming(socket);
|
|
117
118
|
this.scopes.set(socket, conversationId ? { conversationId } : {});
|
|
118
|
-
this.sendState(socket);
|
|
119
|
+
this.sendState(socket, transcriptRevision);
|
|
119
120
|
}
|
|
120
|
-
sendState(socket) {
|
|
121
|
+
sendState(socket, transcriptRevision) {
|
|
121
122
|
if (socket.readyState !== WebSocket.OPEN)
|
|
122
123
|
return;
|
|
123
124
|
if (socket.bufferedAmount > MAX_WS_BUFFERED_BYTES) {
|
|
@@ -133,7 +134,18 @@ export class WsBroadcaster {
|
|
|
133
134
|
if (!safeSend(socket, JSON.stringify(event)))
|
|
134
135
|
this.scheduleRuntimeReplay(socket);
|
|
135
136
|
}
|
|
136
|
-
|
|
137
|
+
let event = { type: "state", state };
|
|
138
|
+
if (transcriptRevision && scope?.conversationId) {
|
|
139
|
+
const selected = state.conversations.find(item => item.id === scope.conversationId && item.messagesLoaded === true && !item.archivedAt);
|
|
140
|
+
if (selected && createHash("sha256").update(JSON.stringify(selected.messages)).digest("hex") === transcriptRevision) {
|
|
141
|
+
event = {
|
|
142
|
+
type: "state",
|
|
143
|
+
state: { ...state, conversations: state.conversations.map(item => item === selected ? { ...item, messages: [] } : item) },
|
|
144
|
+
retainedTranscript: { conversationId: selected.id, revision: transcriptRevision },
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
if (!safeSend(socket, JSON.stringify(event))) {
|
|
137
149
|
this.scheduleRuntimeReplay(socket);
|
|
138
150
|
}
|
|
139
151
|
}
|
|
@@ -579,7 +591,9 @@ export class WsServer {
|
|
|
579
591
|
safeSend(socket, JSON.stringify({ type: "error", message: "会话订阅标识必须是字符串。" }));
|
|
580
592
|
return;
|
|
581
593
|
}
|
|
582
|
-
|
|
594
|
+
const revision = typeof parsed.transcriptRevision === "string" && /^[a-f0-9]{64}$/.test(parsed.transcriptRevision)
|
|
595
|
+
? parsed.transcriptRevision : undefined;
|
|
596
|
+
this.broadcaster.subscribe(socket, parsed.conversationId, revision);
|
|
583
597
|
return;
|
|
584
598
|
}
|
|
585
599
|
// A send or selected queued turn is a streaming operation. It must leave the socket's command
|
|
@@ -155,6 +155,7 @@ export type MeetingAgenda = {
|
|
|
155
155
|
todos: MeetingTodo[];
|
|
156
156
|
};
|
|
157
157
|
export type GroupUserPost = GroupPost & {
|
|
158
|
+
requestTiming?: import("./request-timing.js").RequestTiming;
|
|
158
159
|
role: "user";
|
|
159
160
|
memberIds: string[];
|
|
160
161
|
replyTo?: string;
|
|
@@ -173,6 +174,7 @@ export type GroupUserPost = GroupPost & {
|
|
|
173
174
|
};
|
|
174
175
|
export type GroupReply = GroupPost & {
|
|
175
176
|
executionConversationId?: string;
|
|
177
|
+
executionRequestId?: string;
|
|
176
178
|
role: "assistant";
|
|
177
179
|
memberId: string;
|
|
178
180
|
memberName?: string;
|
|
@@ -59,6 +59,7 @@ export interface ManagedServerProfile {
|
|
|
59
59
|
ssh: "offline" | "connecting" | "online" | "needsTrust" | "awaitingVerification";
|
|
60
60
|
service: "unknown" | "offline" | "online";
|
|
61
61
|
modelChannel: "offline" | "online";
|
|
62
|
+
modelMode?: import("./model-configuration.js").ModelConfigurationMode;
|
|
62
63
|
modelTransport?: "direct";
|
|
63
64
|
modelChannelPaused?: boolean;
|
|
64
65
|
phase: "idle" | "connecting" | "needsTrust" | "awaitingVerification" | "deploying" | "ready" | "failed";
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export type ModelConfigurationMode = "independent" | "shared-catalog" | "unified";
|
|
2
|
+
export declare function isModelConfigurationMode(value: unknown): value is ModelConfigurationMode;
|
|
3
|
+
export interface ModelConfigurationStatus {
|
|
4
|
+
paired: boolean;
|
|
5
|
+
mode: ModelConfigurationMode;
|
|
6
|
+
syncedAt?: string;
|
|
7
|
+
skippedModels?: number;
|
|
8
|
+
providers: {
|
|
9
|
+
id: string;
|
|
10
|
+
modelCount: number;
|
|
11
|
+
}[];
|
|
12
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export type RequestOutcome = "completed" | "failed" | "stopped" | "incomplete" | "interrupted";
|
|
2
|
+
/** Lifecycle timestamps recorded by the backend. The enclosing message owns the accepted timestamp. */
|
|
3
|
+
export type RequestTiming = {
|
|
4
|
+
startedAt?: string;
|
|
5
|
+
responseEndedAt?: string;
|
|
6
|
+
endedAt?: string;
|
|
7
|
+
outcome?: RequestOutcome;
|
|
8
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|