@averyyy/pi-coding-agent 1.3.0-piclient.5 → 1.4.0-piclient.10
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/CHANGELOG.md +61 -1
- package/dist/bundle/chunks/anthropic-messages-3TZAX2CL.js +6 -0
- package/dist/bundle/chunks/azure-openai-responses-5OV6AS44.js +2 -0
- package/dist/bundle/chunks/bedrock-converse-stream.js +8 -8
- package/dist/bundle/chunks/{chunk-27EJF7XV.js → chunk-3EGEEHMN.js} +1 -1
- package/dist/bundle/chunks/{chunk-VBIW3SGN.js → chunk-3LTMO2WY.js} +1 -1
- package/dist/bundle/chunks/{chunk-PYGXRV27.js → chunk-3V45WARH.js} +1 -1
- package/dist/bundle/chunks/{chunk-S3GGRYIO.js → chunk-5AGIVGSV.js} +1 -1
- package/dist/bundle/chunks/{chunk-F5ZABL6Z.js → chunk-7CBJINYJ.js} +2 -2
- package/dist/bundle/chunks/{chunk-DRQDKNXA.js → chunk-7DDKXS2Q.js} +1 -1
- package/dist/bundle/chunks/{chunk-JBOKZR45.js → chunk-BRYV63PL.js} +2 -2
- package/dist/bundle/chunks/{chunk-H3QXYIF7.js → chunk-CF5GWZHW.js} +1 -1
- package/dist/bundle/chunks/chunk-D3OXAPLU.js +11 -0
- package/dist/bundle/chunks/{chunk-WALKIYXG.js → chunk-GA3MDGH3.js} +1 -1
- package/dist/bundle/chunks/chunk-H2AI7MFJ.js +9 -0
- package/dist/bundle/chunks/{chunk-XDNB4NV2.js → chunk-H2UJDH5M.js} +10 -9
- package/dist/bundle/chunks/chunk-H76KZMOI.js +2 -0
- package/dist/bundle/chunks/chunk-HZG4C6GI.js +2 -0
- package/dist/bundle/chunks/{chunk-WEGEKOLF.js → chunk-J5XSJ6CW.js} +1 -1
- package/dist/bundle/chunks/{chunk-4L3WN2XY.js → chunk-JXWJOIH4.js} +1 -1
- package/dist/bundle/chunks/{chunk-6CYCI3EJ.js → chunk-LVVZS2NO.js} +1 -1
- package/dist/bundle/chunks/{chunk-A5PVA2BG.js → chunk-MKWEYCNF.js} +4 -3
- package/dist/bundle/chunks/{chunk-PT5WCDHM.js → chunk-PG7P2LUM.js} +2 -2
- package/dist/bundle/chunks/chunk-TLSZ4DWU.js +16 -0
- package/dist/bundle/chunks/{chunk-ZBURYEWF.js → chunk-TMTOQ7H7.js} +1 -1
- package/dist/bundle/chunks/{chunk-22CYIUS4.js → chunk-UKVNB6C4.js} +1 -1
- package/dist/bundle/chunks/{chunk-6AK3I2ZG.js → chunk-UZLVOWHH.js} +44 -40
- package/dist/bundle/chunks/chunk-VHUVVKJM.js +2 -0
- package/dist/bundle/chunks/{chunk-32OQRHU5.js → chunk-VYYRESZJ.js} +1 -1
- package/dist/bundle/chunks/chunk-WVXVPMMO.js +2 -0
- package/dist/bundle/chunks/{cli-C7ZYV7NI.js → cli-QUNA6INU.js} +1 -1
- package/dist/bundle/chunks/cloudflare-workers-ai-system-one-QIIM6OB4.js +2 -0
- package/dist/bundle/chunks/{easter-egg-3d-JPU5ICBY.js → easter-egg-3d-4L2AVJKX.js} +1 -1
- package/dist/bundle/chunks/{execute-ZWI524ZI.js → execute-UNST3ORJ.js} +9 -3
- package/dist/bundle/chunks/google-antigravity-runtime.js +8 -7
- package/dist/bundle/chunks/google-generative-ai-PNRT4EAN.js +2 -0
- package/dist/bundle/chunks/google-vertex-ZLSXUSEM.js +2 -0
- package/dist/bundle/chunks/{https-proxy-agent-UDEHOBGS.js → https-proxy-agent-LVOO5TPL.js} +1 -1
- package/dist/bundle/chunks/{jiti-loader-C3NU2SDH.js → jiti-loader-GL4HJFAD.js} +1 -1
- package/dist/bundle/chunks/{jiti-static-loader-E6ANQD5T.js → jiti-static-loader-2RCDI6B4.js} +1 -1
- package/dist/bundle/chunks/{lib-TEDK3E5I.js → lib-4AVRLBHM.js} +1 -1
- package/dist/bundle/chunks/{llama-cpp-classify-FYN623RH.js → llama-cpp-classify-U4EH6TAM.js} +2 -2
- package/dist/bundle/chunks/{mistral-conversations-IDNVOMLP.js → mistral-conversations-OJFHLO4F.js} +1 -1
- package/dist/bundle/chunks/{multipart-parser-SQ6GDJL7.js → multipart-parser-FMGQ7342.js} +1 -1
- package/dist/bundle/chunks/{node-TWVVAGPO.js → node-AUOGOBCN.js} +1 -1
- package/dist/bundle/chunks/{node-N5BSDOA5.js → node-KCMANYC2.js} +1 -1
- package/dist/bundle/chunks/openai-codex-responses-UIB63WGM.js +10 -0
- package/dist/bundle/chunks/openai-completions-T5JB7LUM.js +7 -0
- package/dist/bundle/chunks/{openai-decisions-CWANEVXX.js → openai-decisions-Q46R33J3.js} +1 -1
- package/dist/bundle/chunks/openai-responses-FGTD6NDJ.js +4 -0
- package/dist/bundle/chunks/openrouter-images-WBAVKHHY.js +2 -0
- package/dist/bundle/chunks/pi-messages-S7RKCD5K.js +8 -0
- package/dist/bundle/chunks/{runtime-RTNZQVM5.js → runtime-SITSZTHV.js} +1 -1
- package/dist/bundle/chunks/{src-UK77SYZE.js → src-QKGKDFSU.js} +1 -1
- package/dist/bundle/chunks/typesafe-system-one-DFEHTLK5.js +2 -0
- package/dist/bundle/chunks/virtual-modules-G5A4RNVO.js +2 -0
- package/dist/bundle/cli-runtime.js +1 -1
- package/dist/bundle/index.js +1 -1
- package/dist/bundle/rpc-entry.js +1 -1
- package/dist/core/agent-session.d.ts +5 -1
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +42 -13
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/client-identity.d.ts +8 -0
- package/dist/core/client-identity.d.ts.map +1 -0
- package/dist/core/client-identity.js +15 -0
- package/dist/core/client-identity.js.map +1 -0
- package/dist/core/compaction/branch-summarization.d.ts.map +1 -1
- package/dist/core/compaction/branch-summarization.js +2 -3
- package/dist/core/compaction/branch-summarization.js.map +1 -1
- package/dist/core/compaction/compaction.d.ts +3 -3
- package/dist/core/compaction/compaction.d.ts.map +1 -1
- package/dist/core/compaction/compaction.js +35 -30
- package/dist/core/compaction/compaction.js.map +1 -1
- package/dist/core/export-html/index.d.ts.map +1 -1
- package/dist/core/export-html/index.js +2 -0
- package/dist/core/export-html/index.js.map +1 -1
- package/dist/core/export-html/template.html +1 -0
- package/dist/core/export-html/template.js +2 -1
- package/dist/core/export-html/vendor/marked-cjk-friendly.min.js +6 -0
- package/dist/core/export-html/vendor/marked.min.js +30 -29
- package/dist/core/extensions/loader.d.ts.map +1 -1
- package/dist/core/extensions/loader.js +3 -0
- package/dist/core/extensions/loader.js.map +1 -1
- package/dist/core/extensions/virtual-modules.d.ts.map +1 -1
- package/dist/core/extensions/virtual-modules.js +3 -0
- package/dist/core/extensions/virtual-modules.js.map +1 -1
- package/dist/core/model-config.d.ts +915 -0
- package/dist/core/model-config.d.ts.map +1 -1
- package/dist/core/model-config.js +48 -24
- package/dist/core/model-config.js.map +1 -1
- package/dist/core/model-resolver.js +2 -2
- package/dist/core/model-resolver.js.map +1 -1
- package/dist/core/model-runtime.d.ts.map +1 -1
- package/dist/core/model-runtime.js +6 -3
- package/dist/core/model-runtime.js.map +1 -1
- package/dist/core/package-manager.js +2 -2
- package/dist/core/package-manager.js.map +1 -1
- package/dist/core/pi-server-client.d.ts.map +1 -1
- package/dist/core/pi-server-client.js +4 -1
- package/dist/core/pi-server-client.js.map +1 -1
- package/dist/core/pi-server-observer.d.ts +7 -1
- package/dist/core/pi-server-observer.d.ts.map +1 -1
- package/dist/core/pi-server-observer.js +43 -4
- package/dist/core/pi-server-observer.js.map +1 -1
- package/dist/core/pi-server-subagents.d.ts +26 -0
- package/dist/core/pi-server-subagents.d.ts.map +1 -0
- package/dist/core/pi-server-subagents.js +112 -0
- package/dist/core/pi-server-subagents.js.map +1 -0
- package/dist/core/provider-composer.d.ts +2 -1
- package/dist/core/provider-composer.d.ts.map +1 -1
- package/dist/core/provider-composer.js +7 -3
- package/dist/core/provider-composer.js.map +1 -1
- package/dist/core/resource-loader.d.ts +2 -0
- package/dist/core/resource-loader.d.ts.map +1 -1
- package/dist/core/resource-loader.js +3 -0
- package/dist/core/resource-loader.js.map +1 -1
- package/dist/core/sdk.d.ts.map +1 -1
- package/dist/core/sdk.js +15 -10
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/tools/grep.d.ts.map +1 -1
- package/dist/core/tools/grep.js +3 -1
- package/dist/core/tools/grep.js.map +1 -1
- package/dist/extensions/codemode/execute.d.ts.map +1 -1
- package/dist/extensions/codemode/execute.js +99 -24
- package/dist/extensions/codemode/execute.js.map +1 -1
- package/dist/extensions/mcp/config.d.ts.map +1 -1
- package/dist/extensions/mcp/config.js +3 -2
- package/dist/extensions/mcp/config.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts +11 -15
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +73 -115
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/package-manager-cli.d.ts.map +1 -1
- package/dist/package-manager-cli.js +2 -1
- package/dist/package-manager-cli.js.map +1 -1
- package/dist/utils/clipboard-command.d.ts.map +1 -1
- package/dist/utils/clipboard-command.js +3 -0
- package/dist/utils/clipboard-command.js.map +1 -1
- package/dist/utils/pi-user-agent.d.ts +1 -0
- package/dist/utils/pi-user-agent.d.ts.map +1 -1
- package/dist/utils/pi-user-agent.js +3 -2
- package/dist/utils/pi-user-agent.js.map +1 -1
- package/dist/utils/shell.d.ts.map +1 -1
- package/dist/utils/shell.js +45 -13
- package/dist/utils/shell.js.map +1 -1
- package/dist/utils/tools-manager.d.ts.map +1 -1
- package/dist/utils/tools-manager.js +4 -3
- package/dist/utils/tools-manager.js.map +1 -1
- package/docs/codemode.md +2 -2
- package/docs/compaction.md +3 -3
- package/docs/custom-provider.md +53 -1
- package/docs/docs.json +4 -0
- package/docs/environment-variables.md +1 -0
- package/docs/extensions.md +133 -10
- package/docs/models-configuration.md +196 -0
- package/docs/models.md +21 -5
- package/docs/settings.md +1 -1
- package/docs/tui.md +70 -0
- package/docs/windows.md +16 -2
- package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
- package/examples/extensions/custom-provider-anthropic/package.json +1 -1
- package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
- package/examples/extensions/gondolin/package-lock.json +2 -2
- package/examples/extensions/gondolin/package.json +1 -1
- package/examples/extensions/sandbox/package-lock.json +2 -2
- package/examples/extensions/sandbox/package.json +1 -1
- package/examples/extensions/with-deps/package-lock.json +2 -2
- package/examples/extensions/with-deps/package.json +1 -1
- package/package.json +7 -6
- package/schemas/models.schema.json +83 -29
- package/dist/bundle/chunks/anthropic-messages-JKZEYO3X.js +0 -6
- package/dist/bundle/chunks/azure-openai-responses-CALHHRO4.js +0 -2
- package/dist/bundle/chunks/chunk-2TBKESBE.js +0 -2
- package/dist/bundle/chunks/chunk-3IAHLZM6.js +0 -2
- package/dist/bundle/chunks/chunk-KO7M2ZFM.js +0 -11
- package/dist/bundle/chunks/chunk-NAPMJL5U.js +0 -11
- package/dist/bundle/chunks/chunk-VZZDG22Y.js +0 -9
- package/dist/bundle/chunks/chunk-XIQJS2WK.js +0 -2
- package/dist/bundle/chunks/cloudflare-workers-ai-system-one-W3JVUOXV.js +0 -2
- package/dist/bundle/chunks/google-generative-ai-4YEPBKDH.js +0 -2
- package/dist/bundle/chunks/google-vertex-5HD3H47T.js +0 -2
- package/dist/bundle/chunks/openai-codex-responses-TWAB375R.js +0 -10
- package/dist/bundle/chunks/openai-completions-3LCSEI2J.js +0 -7
- package/dist/bundle/chunks/openai-responses-JEQACBMR.js +0 -3
- package/dist/bundle/chunks/openrouter-images-DUPG5DZO.js +0 -2
- package/dist/bundle/chunks/pi-messages-V27DSLVC.js +0 -8
- package/dist/bundle/chunks/typesafe-system-one-JJVDHYHL.js +0 -2
- package/dist/bundle/chunks/virtual-modules-2YGWEC7J.js +0 -2
- package/dist/core/provider-attribution.d.ts +0 -4
- package/dist/core/provider-attribution.d.ts.map +0 -1
- package/dist/core/provider-attribution.js +0 -72
- package/dist/core/provider-attribution.js.map +0 -1
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { TextSignatureV1 } from "@earendil-works/pi-ai";
|
|
2
2
|
import type { AgentSession } from "./agent-session.ts";
|
|
3
|
+
import { type ObserverSubagent } from "./pi-server-subagents.ts";
|
|
3
4
|
import type { SessionEntry } from "./session-manager.ts";
|
|
4
5
|
export declare function closePiServerObserver(session: AgentSession): Promise<void>;
|
|
5
6
|
type ViewerContent = {
|
|
@@ -40,6 +41,7 @@ export interface ObserverUpdate {
|
|
|
40
41
|
sequence: number;
|
|
41
42
|
cwd: string;
|
|
42
43
|
title: string;
|
|
44
|
+
subagents?: ObserverSubagent[];
|
|
43
45
|
replace?: ObserverMessage[];
|
|
44
46
|
append?: ObserverMessage[];
|
|
45
47
|
status: "running" | "idle";
|
|
@@ -49,7 +51,7 @@ export interface ObserverUpdate {
|
|
|
49
51
|
};
|
|
50
52
|
}
|
|
51
53
|
export declare function projectObserverEntries(entries: SessionEntry[]): ObserverMessage[];
|
|
52
|
-
/** Publishes
|
|
54
|
+
/** Publishes transcript updates independently of provider requests and durable server trees. */
|
|
53
55
|
export declare class PiServerObserver {
|
|
54
56
|
private readonly session;
|
|
55
57
|
private readonly unsubscribe;
|
|
@@ -76,8 +78,12 @@ export declare class PiServerObserver {
|
|
|
76
78
|
private liveMessageId;
|
|
77
79
|
private readonly tools;
|
|
78
80
|
private disconnected;
|
|
81
|
+
private observedSessionId?;
|
|
82
|
+
private readonly subagents;
|
|
83
|
+
private sentSubagentVersion;
|
|
79
84
|
constructor(session: AgentSession);
|
|
80
85
|
private handleEvent;
|
|
86
|
+
private syncSession;
|
|
81
87
|
private schedule;
|
|
82
88
|
private reportError;
|
|
83
89
|
private stopDeletedSession;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pi-server-observer.d.ts","sourceRoot":"","sources":["../../src/core/pi-server-observer.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAA6B,eAAe,EAA6B,MAAM,uBA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{ raceWithAbortSignal } from "../utils/abort.js";
|
|
3
3
|
import { bashExecutionToText } from "./messages.js";
|
|
4
4
|
import { ChunkRequest } from "./pi-server-request.js";
|
|
5
|
+
import { PiServerSubagents, resolvePiServerSubagents } from "./pi-server-subagents.js";
|
|
5
6
|
const observers = new WeakMap();
|
|
6
7
|
export async function closePiServerObserver(session) {
|
|
7
8
|
await observers.get(session)?.close();
|
|
@@ -34,7 +35,7 @@ function projectContent(content) {
|
|
|
34
35
|
return { type: "attachment", label: part.mimeType };
|
|
35
36
|
});
|
|
36
37
|
}
|
|
37
|
-
function projectMessage(id, message) {
|
|
38
|
+
function projectMessage(id, message, timestamp = message.timestamp) {
|
|
38
39
|
if (message.role === "system" || (message.role === "custom" && !message.display))
|
|
39
40
|
return undefined;
|
|
40
41
|
let content;
|
|
@@ -44,7 +45,7 @@ function projectMessage(id, message) {
|
|
|
44
45
|
content = message.summary;
|
|
45
46
|
else
|
|
46
47
|
content = projectContent(message.content);
|
|
47
|
-
const projected = { id, role: message.role, content, timestamp
|
|
48
|
+
const projected = { id, role: message.role, content, timestamp };
|
|
48
49
|
if (message.role === "assistant") {
|
|
49
50
|
projected.stopReason = message.stopReason;
|
|
50
51
|
projected.errorMessage = message.errorMessage;
|
|
@@ -61,7 +62,7 @@ export function projectObserverEntries(entries) {
|
|
|
61
62
|
for (const entry of entries) {
|
|
62
63
|
let message;
|
|
63
64
|
if (entry.type === "message")
|
|
64
|
-
message = projectMessage(entry.id, entry.message);
|
|
65
|
+
message = projectMessage(entry.id, entry.message, Date.parse(entry.timestamp));
|
|
65
66
|
else if (entry.type === "custom_message" && entry.display) {
|
|
66
67
|
message = {
|
|
67
68
|
id: entry.id,
|
|
@@ -78,7 +79,7 @@ export function projectObserverEntries(entries) {
|
|
|
78
79
|
}
|
|
79
80
|
return messages;
|
|
80
81
|
}
|
|
81
|
-
/** Publishes
|
|
82
|
+
/** Publishes transcript updates independently of provider requests and durable server trees. */
|
|
82
83
|
export class PiServerObserver {
|
|
83
84
|
session;
|
|
84
85
|
unsubscribe;
|
|
@@ -105,8 +106,17 @@ export class PiServerObserver {
|
|
|
105
106
|
liveMessageId = "";
|
|
106
107
|
tools = new Map();
|
|
107
108
|
disconnected = false;
|
|
109
|
+
observedSessionId;
|
|
110
|
+
subagents;
|
|
111
|
+
sentSubagentVersion = -1;
|
|
108
112
|
constructor(session) {
|
|
109
113
|
this.session = session;
|
|
114
|
+
this.subagents = new PiServerSubagents(session, () => {
|
|
115
|
+
this.dirty = true;
|
|
116
|
+
this.historyDirty = true;
|
|
117
|
+
this.schedule(0);
|
|
118
|
+
});
|
|
119
|
+
this.syncSession();
|
|
110
120
|
observers.set(session, this);
|
|
111
121
|
this.unsubscribe = session.subscribe((event) => {
|
|
112
122
|
try {
|
|
@@ -119,11 +129,13 @@ export class PiServerObserver {
|
|
|
119
129
|
void this.connect();
|
|
120
130
|
}
|
|
121
131
|
handleEvent(event) {
|
|
132
|
+
this.syncSession();
|
|
122
133
|
switch (event.type) {
|
|
123
134
|
case "session_disposed":
|
|
124
135
|
this.dispose();
|
|
125
136
|
return;
|
|
126
137
|
case "run_state_changed":
|
|
138
|
+
resolvePiServerSubagents();
|
|
127
139
|
if (!event.running) {
|
|
128
140
|
this.liveMessage = null;
|
|
129
141
|
this.tools.clear();
|
|
@@ -153,6 +165,7 @@ export class PiServerObserver {
|
|
|
153
165
|
break;
|
|
154
166
|
case "history_reconciled":
|
|
155
167
|
case "session_tree_changed":
|
|
168
|
+
this.subagents.restore();
|
|
156
169
|
if (this.deletedSessionId && this.deletedSessionId !== this.session.sessionId) {
|
|
157
170
|
this.deletedSessionId = undefined;
|
|
158
171
|
void this.connect();
|
|
@@ -201,6 +214,18 @@ export class PiServerObserver {
|
|
|
201
214
|
? 0
|
|
202
215
|
: 80);
|
|
203
216
|
}
|
|
217
|
+
syncSession() {
|
|
218
|
+
if (this.observedSessionId === this.session.sessionId)
|
|
219
|
+
return;
|
|
220
|
+
this.observedSessionId = this.session.sessionId;
|
|
221
|
+
this.subagents.syncSession();
|
|
222
|
+
this.sentSubagentVersion = -1;
|
|
223
|
+
this.sentEntryId = undefined;
|
|
224
|
+
this.pendingEntries = [];
|
|
225
|
+
this.firstUserTitle = "";
|
|
226
|
+
this.liveMessage = null;
|
|
227
|
+
this.tools.clear();
|
|
228
|
+
}
|
|
204
229
|
schedule(delay) {
|
|
205
230
|
if (this.disposed ||
|
|
206
231
|
this.closing ||
|
|
@@ -246,6 +271,7 @@ export class PiServerObserver {
|
|
|
246
271
|
async connect() {
|
|
247
272
|
if (this.disposed || this.deletedSessionId === this.session.sessionId)
|
|
248
273
|
return;
|
|
274
|
+
this.syncSession();
|
|
249
275
|
const controller = new AbortController();
|
|
250
276
|
this.controller = controller;
|
|
251
277
|
const sessionId = this.session.sessionId;
|
|
@@ -258,6 +284,10 @@ export class PiServerObserver {
|
|
|
258
284
|
timeout.unref();
|
|
259
285
|
try {
|
|
260
286
|
const response = await this.request(controller.signal).getJson(`/api/observer/connect?sessionId=${encodeURIComponent(sessionId)}`);
|
|
287
|
+
if (response.status === 410) {
|
|
288
|
+
this.stopDeletedSession(sessionId, controller);
|
|
289
|
+
return;
|
|
290
|
+
}
|
|
261
291
|
if (!response.ok || !response.headers.get("content-type")?.includes("text/event-stream") || !response.body) {
|
|
262
292
|
throw new Error(`connection failed (HTTP ${response.status})`);
|
|
263
293
|
}
|
|
@@ -285,6 +315,7 @@ export class PiServerObserver {
|
|
|
285
315
|
const connected = JSON.parse(line.slice(5));
|
|
286
316
|
this.connectionId = connected.connectionId;
|
|
287
317
|
this.sequence = 0;
|
|
318
|
+
this.sentSubagentVersion = -1;
|
|
288
319
|
clearTimeout(timeout);
|
|
289
320
|
this.replace = true;
|
|
290
321
|
this.historyDirty = true;
|
|
@@ -331,11 +362,13 @@ export class PiServerObserver {
|
|
|
331
362
|
return promise;
|
|
332
363
|
}
|
|
333
364
|
async sendUpdate() {
|
|
365
|
+
this.subagents.resolve();
|
|
334
366
|
const connectionId = this.connectionId;
|
|
335
367
|
const sessionId = this.connectedSessionId;
|
|
336
368
|
const controller = this.controller;
|
|
337
369
|
if (!connectionId ||
|
|
338
370
|
!sessionId ||
|
|
371
|
+
sessionId !== this.session.sessionId ||
|
|
339
372
|
!controller ||
|
|
340
373
|
this.disposed ||
|
|
341
374
|
this.deletedSessionId === sessionId ||
|
|
@@ -364,12 +397,14 @@ export class PiServerObserver {
|
|
|
364
397
|
.map((part) => part.text)
|
|
365
398
|
.join("") ?? "")).slice(0, 120);
|
|
366
399
|
}
|
|
400
|
+
const subagentVersion = this.subagents.version;
|
|
367
401
|
const update = {
|
|
368
402
|
sessionId,
|
|
369
403
|
connectionId,
|
|
370
404
|
sequence: ++this.sequence,
|
|
371
405
|
cwd: this.session.sessionManager.getCwd(),
|
|
372
406
|
title: this.session.sessionManager.getSessionName() ?? this.firstUserTitle,
|
|
407
|
+
...(subagentVersion !== this.sentSubagentVersion ? { subagents: this.subagents.snapshot() } : {}),
|
|
373
408
|
...(replace ? { replace: messages } : messages.length ? { append: messages } : {}),
|
|
374
409
|
status: this.session.isIdle ? "idle" : "running",
|
|
375
410
|
live: {
|
|
@@ -387,6 +422,9 @@ export class PiServerObserver {
|
|
|
387
422
|
const result = (await response.json());
|
|
388
423
|
if (!result.accepted)
|
|
389
424
|
throw new Error("update was not accepted");
|
|
425
|
+
if (sessionId !== this.session.sessionId)
|
|
426
|
+
return;
|
|
427
|
+
this.sentSubagentVersion = subagentVersion;
|
|
390
428
|
if (entries.length > 0)
|
|
391
429
|
this.sentEntryId = entries.at(-1)?.id;
|
|
392
430
|
else if (replace)
|
|
@@ -443,6 +481,7 @@ export class PiServerObserver {
|
|
|
443
481
|
dispose() {
|
|
444
482
|
this.disposed = true;
|
|
445
483
|
this.unsubscribe();
|
|
484
|
+
this.subagents.dispose();
|
|
446
485
|
clearTimeout(this.timer);
|
|
447
486
|
clearTimeout(this.reconnectTimer);
|
|
448
487
|
this.controller?.abort();
|
|
@@ -1 +1 @@
|
|
|
1
|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,cAAc,CAAC,CAAC;QAClC,IAAI,CAAC,UAAU,EAAE,KAAK,EAAE,CAAC;QACzB,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAChC,CAAC;CACD","sourcesContent":["import { randomUUID } from \"node:crypto\";\nimport type { AgentMessage } from \"@earendil-works/pi-agent-core\";\nimport type { ImageContent, TextContent, TextSignatureV1, ThinkingContent, ToolCall } from \"@earendil-works/pi-ai\";\nimport { raceWithAbortSignal } from \"../utils/abort.ts\";\nimport type { AgentSession, AgentSessionEvent } from \"./agent-session.ts\";\nimport { bashExecutionToText } from \"./messages.ts\";\nimport { ChunkRequest } from \"./pi-server-request.ts\";\nimport type { SessionEntry } from \"./session-manager.ts\";\n\nconst observers = new WeakMap<AgentSession, PiServerObserver>();\n\nexport async function closePiServerObserver(session: AgentSession): Promise<void> {\n\tawait observers.get(session)?.close();\n}\n\ntype ViewerContent =\n\t| { type: \"text\"; text: string; phase?: TextSignatureV1[\"phase\"] }\n\t| { type: \"thinking\"; thinking: string }\n\t| { type: \"toolCall\"; id: string; name: string; arguments: unknown }\n\t| { type: \"attachment\"; label: string };\n\nexport interface ObserverMessage {\n\tid: string;\n\trole: string;\n\tcontent: string | ViewerContent[];\n\ttimestamp: number;\n\tstopReason?: string;\n\tphase?: string;\n\terrorMessage?: string;\n}\n\ninterface ObserverTool {\n\tid: string;\n\tname: string;\n\targuments: unknown;\n\tresult?: unknown;\n\tstatus: \"running\" | \"completed\" | \"error\";\n}\n\nexport interface ObserverUpdate {\n\tsessionId: string;\n\tconnectionId: string;\n\tsequence: number;\n\tcwd: string;\n\ttitle: string;\n\treplace?: ObserverMessage[];\n\tappend?: ObserverMessage[];\n\tstatus: \"running\" | \"idle\";\n\tlive: { message: ObserverMessage | null; tools: ObserverTool[] };\n}\n\nfunction textPhase(signature: string | undefined): TextSignatureV1[\"phase\"] {\n\tif (!signature?.startsWith(\"{\")) return undefined;\n\ttry {\n\t\tconst parsed = JSON.parse(signature) as Partial<TextSignatureV1>;\n\t\tif (\n\t\t\tparsed.v === 1 &&\n\t\t\ttypeof parsed.id === \"string\" &&\n\t\t\t(parsed.phase === \"commentary\" || parsed.phase === \"final_answer\")\n\t\t)\n\t\t\treturn parsed.phase;\n\t} catch {\n\t\t// Provider signatures outside TextSignatureV1 have no display phase.\n\t}\n\treturn undefined;\n}\n\nfunction projectContent(\n\tcontent: string | (TextContent | ThinkingContent | ImageContent | ToolCall)[],\n): ObserverMessage[\"content\"] {\n\tif (typeof content === \"string\") return content;\n\treturn content.map((part): ViewerContent => {\n\t\tif (part.type === \"text\") return { type: \"text\", text: part.text, phase: textPhase(part.textSignature) };\n\t\tif (part.type === \"thinking\") return { type: \"thinking\", thinking: part.thinking };\n\t\tif (part.type === \"toolCall\")\n\t\t\treturn { type: \"toolCall\", id: part.id, name: part.name, arguments: part.arguments };\n\t\treturn { type: \"attachment\", label: part.mimeType };\n\t});\n}\n\nfunction projectMessage(id: string, message: AgentMessage): ObserverMessage | undefined {\n\tif (message.role === \"system\" || (message.role === \"custom\" && !message.display)) return undefined;\n\tlet content: ObserverMessage[\"content\"];\n\tif (message.role === \"bashExecution\") content = bashExecutionToText(message);\n\telse if (message.role === \"compactionSummary\" || message.role === \"branchSummary\") content = message.summary;\n\telse content = projectContent(message.content);\n\tconst projected: ObserverMessage = { id, role: message.role, content, timestamp: message.timestamp };\n\tif (message.role === \"assistant\") {\n\t\tprojected.stopReason = message.stopReason;\n\t\tprojected.errorMessage = message.errorMessage;\n\t\tfor (const part of message.content) {\n\t\t\tconst phase = part.type === \"text\" ? textPhase(part.textSignature) : undefined;\n\t\t\tif (phase) projected.phase = phase;\n\t\t}\n\t}\n\treturn projected;\n}\n\nexport function projectObserverEntries(entries: SessionEntry[]): ObserverMessage[] {\n\tconst messages: ObserverMessage[] = [];\n\tfor (const entry of entries) {\n\t\tlet message: ObserverMessage | undefined;\n\t\tif (entry.type === \"message\") message = projectMessage(entry.id, entry.message);\n\t\telse if (entry.type === \"custom_message\" && entry.display) {\n\t\t\tmessage = {\n\t\t\t\tid: entry.id,\n\t\t\t\trole: \"custom\",\n\t\t\t\tcontent: projectContent(entry.content),\n\t\t\t\ttimestamp: Date.parse(entry.timestamp),\n\t\t\t};\n\t\t} else if (entry.type === \"compaction\" || entry.type === \"branch_summary\") {\n\t\t\tmessage = { id: entry.id, role: entry.type, content: entry.summary, timestamp: Date.parse(entry.timestamp) };\n\t\t}\n\t\tif (message) messages.push(message);\n\t}\n\treturn messages;\n}\n\n/** Publishes a read-only transcript independently of provider requests and durable server trees. */\nexport class PiServerObserver {\n\tprivate readonly session: AgentSession;\n\tprivate readonly unsubscribe: () => void;\n\tprivate controller?: AbortController;\n\tprivate timer?: ReturnType<typeof setTimeout>;\n\tprivate reconnectTimer?: ReturnType<typeof setTimeout>;\n\tprivate disposed = false;\n\tprivate closing = false;\n\tprivate closePromise?: Promise<void>;\n\tprivate connectionReady?: Promise<void>;\n\tprivate deletedSessionId?: string;\n\tprivate connectionId?: string;\n\tprivate connectedSessionId?: string;\n\tprivate sequence = 0;\n\tprivate sending = false;\n\tprivate flushPromise?: Promise<void>;\n\tprivate dirty = true;\n\tprivate historyDirty = true;\n\tprivate replace = true;\n\tprivate sentEntryId?: string;\n\tprivate pendingEntries: SessionEntry[] = [];\n\tprivate firstUserTitle = \"\";\n\tprivate liveMessage: AgentMessage | null = null;\n\tprivate liveMessageId = \"\";\n\tprivate readonly tools = new Map<string, ObserverTool>();\n\tprivate disconnected = false;\n\n\tconstructor(session: AgentSession) {\n\t\tthis.session = session;\n\t\tobservers.set(session, this);\n\t\tthis.unsubscribe = session.subscribe((event) => {\n\t\t\ttry {\n\t\t\t\tthis.handleEvent(event);\n\t\t\t} catch (error) {\n\t\t\t\tthis.reportError(error);\n\t\t\t}\n\t\t});\n\t\tvoid this.connect();\n\t}\n\n\tprivate handleEvent(event: AgentSessionEvent): void {\n\t\tswitch (event.type) {\n\t\t\tcase \"session_disposed\":\n\t\t\t\tthis.dispose();\n\t\t\t\treturn;\n\t\t\tcase \"run_state_changed\":\n\t\t\t\tif (!event.running) {\n\t\t\t\t\tthis.liveMessage = null;\n\t\t\t\t\tthis.tools.clear();\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tcase \"message_start\":\n\t\t\t\tif (event.message.role !== \"assistant\") return;\n\t\t\t\tthis.tools.clear();\n\t\t\t\tthis.liveMessageId = randomUUID();\n\t\t\t\tthis.liveMessage = event.message;\n\t\t\t\tbreak;\n\t\t\tcase \"message_update\":\n\t\t\t\tthis.liveMessage = event.message;\n\t\t\t\tbreak;\n\t\t\tcase \"entry_appended\":\n\t\t\tcase \"message_committed\":\n\t\t\t\tif (this.connectionId && !this.historyDirty) {\n\t\t\t\t\tthis.pendingEntries.push(event.entry);\n\t\t\t\t\tif (this.pendingEntries.length > 64) {\n\t\t\t\t\t\tthis.pendingEntries = [];\n\t\t\t\t\t\tthis.historyDirty = true;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (event.entry.type === \"message\" && event.entry.message.role === \"assistant\") this.liveMessage = null;\n\t\t\t\tbreak;\n\t\t\tcase \"history_reconciled\":\n\t\t\tcase \"session_tree_changed\":\n\t\t\t\tif (this.deletedSessionId && this.deletedSessionId !== this.session.sessionId) {\n\t\t\t\t\tthis.deletedSessionId = undefined;\n\t\t\t\t\tvoid this.connect();\n\t\t\t\t}\n\t\t\t\tif (this.connectedSessionId && this.connectedSessionId !== this.session.sessionId) {\n\t\t\t\t\tthis.connectionId = undefined;\n\t\t\t\t\tthis.controller?.abort();\n\t\t\t\t}\n\t\t\t\tthis.replace = true;\n\t\t\t\tthis.historyDirty = true;\n\t\t\t\tbreak;\n\t\t\tcase \"compaction_end\":\n\t\t\t\tthis.historyDirty = true;\n\t\t\t\tbreak;\n\t\t\tcase \"compaction_start\":\n\t\t\t\tbreak;\n\t\t\tcase \"session_info_changed\":\n\t\t\t\tbreak;\n\t\t\tcase \"tool_execution_start\":\n\t\t\t\tthis.tools.set(event.toolCallId, {\n\t\t\t\t\tid: event.toolCallId,\n\t\t\t\t\tname: event.toolName,\n\t\t\t\t\targuments: event.args,\n\t\t\t\t\tstatus: \"running\",\n\t\t\t\t});\n\t\t\t\tbreak;\n\t\t\tcase \"tool_execution_update\": {\n\t\t\t\tconst tool = this.tools.get(event.toolCallId);\n\t\t\t\tif (tool) tool.result = { content: projectContent(event.partialResult.content) };\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase \"tool_execution_end\": {\n\t\t\t\tconst tool = this.tools.get(event.toolCallId);\n\t\t\t\tif (tool) {\n\t\t\t\t\ttool.result = { content: projectContent(event.result.content), isError: event.isError };\n\t\t\t\t\ttool.status = event.isError ? \"error\" : \"completed\";\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tdefault:\n\t\t\t\treturn;\n\t\t}\n\t\tthis.dirty = true;\n\t\tthis.schedule(\n\t\t\tevent.type === \"run_state_changed\" || event.type === \"compaction_start\" || event.type === \"compaction_end\"\n\t\t\t\t? 0\n\t\t\t\t: 80,\n\t\t);\n\t}\n\n\tprivate schedule(delay: number): void {\n\t\tif (\n\t\t\tthis.disposed ||\n\t\t\tthis.closing ||\n\t\t\tthis.deletedSessionId === this.session.sessionId ||\n\t\t\t!this.dirty ||\n\t\t\t!this.connectionId ||\n\t\t\tthis.sending ||\n\t\t\tthis.timer\n\t\t)\n\t\t\treturn;\n\t\tthis.timer = setTimeout(() => {\n\t\t\tthis.timer = undefined;\n\t\t\tvoid this.flush();\n\t\t}, delay);\n\t\tthis.timer.unref();\n\t}\n\n\tprivate reportError(error: unknown): void {\n\t\tif (this.disposed || this.disconnected) return;\n\t\tthis.disconnected = true;\n\t\tconsole.error(`pi-server observer disconnected: ${error instanceof Error ? error.message : String(error)}`);\n\t}\n\n\tprivate stopDeletedSession(sessionId: string, controller: AbortController): void {\n\t\tif (sessionId === this.session.sessionId) {\n\t\t\tthis.deletedSessionId = sessionId;\n\t\t\tthis.connectionId = undefined;\n\t\t\tthis.pendingEntries = [];\n\t\t\tthis.liveMessage = null;\n\t\t\tthis.tools.clear();\n\t\t\tclearTimeout(this.timer);\n\t\t\tthis.timer = undefined;\n\t\t\tclearTimeout(this.reconnectTimer);\n\t\t\tthis.reconnectTimer = undefined;\n\t\t}\n\t\tcontroller.abort();\n\t}\n\n\tprivate request(signal: AbortSignal): ChunkRequest {\n\t\treturn new ChunkRequest({\n\t\t\tserverUrl: process.env.PI_SERVER_URL ?? \"http://127.0.0.1:4217\",\n\t\t\tauthToken: process.env.PI_SERVER_AUTH_TOKEN ?? \"\",\n\t\t\tsignal,\n\t\t});\n\t}\n\n\tprivate async connect(): Promise<void> {\n\t\tif (this.disposed || this.deletedSessionId === this.session.sessionId) return;\n\t\tconst controller = new AbortController();\n\t\tthis.controller = controller;\n\t\tconst sessionId = this.session.sessionId;\n\t\tthis.connectedSessionId = sessionId;\n\t\tlet resolveConnection: (() => void) | undefined;\n\t\tthis.connectionReady = new Promise<void>((resolve) => {\n\t\t\tresolveConnection = resolve;\n\t\t});\n\t\tconst timeout = setTimeout(() => controller.abort(new Error(\"connection timed out\")), 10000);\n\t\ttimeout.unref();\n\t\ttry {\n\t\t\tconst response = await this.request(controller.signal).getJson(\n\t\t\t\t`/api/observer/connect?sessionId=${encodeURIComponent(sessionId)}`,\n\t\t\t);\n\t\t\tif (!response.ok || !response.headers.get(\"content-type\")?.includes(\"text/event-stream\") || !response.body) {\n\t\t\t\tthrow new Error(`connection failed (HTTP ${response.status})`);\n\t\t\t}\n\t\t\tconst reader = response.body.getReader();\n\t\t\tconst decoder = new TextDecoder();\n\t\t\tlet buffer = \"\";\n\t\t\tlet event = \"\";\n\t\t\ttry {\n\t\t\t\twhile (!this.disposed) {\n\t\t\t\t\tconst { done, value } = await reader.read();\n\t\t\t\t\tif (done) throw new Error(\"connection closed\");\n\t\t\t\t\tbuffer += decoder.decode(value, { stream: true });\n\t\t\t\t\tlet newline = buffer.indexOf(\"\\n\");\n\t\t\t\t\twhile (newline !== -1) {\n\t\t\t\t\t\tconst line = buffer.slice(0, newline).replace(/\\r$/, \"\");\n\t\t\t\t\t\tbuffer = buffer.slice(newline + 1);\n\t\t\t\t\t\tif (line.startsWith(\"event:\")) event = line.slice(6).trim();\n\t\t\t\t\t\tif (event === \"deleted\" && line.startsWith(\"data:\")) {\n\t\t\t\t\t\t\tthis.stopDeletedSession(sessionId, controller);\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (event === \"connected\" && !this.connectionId && line.startsWith(\"data:\")) {\n\t\t\t\t\t\t\tconst connected = JSON.parse(line.slice(5)) as { connectionId: string };\n\t\t\t\t\t\t\tthis.connectionId = connected.connectionId;\n\t\t\t\t\t\t\tthis.sequence = 0;\n\t\t\t\t\t\t\tclearTimeout(timeout);\n\t\t\t\t\t\t\tthis.replace = true;\n\t\t\t\t\t\t\tthis.historyDirty = true;\n\t\t\t\t\t\t\tthis.dirty = true;\n\t\t\t\t\t\t\tthis.schedule(0);\n\t\t\t\t\t\t\tresolveConnection?.();\n\t\t\t\t\t\t}\n\t\t\t\t\t\tnewline = buffer.indexOf(\"\\n\");\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} finally {\n\t\t\t\tawait reader.cancel();\n\t\t\t\treader.releaseLock();\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tif (sessionId === this.session.sessionId && this.deletedSessionId !== sessionId) this.reportError(error);\n\t\t} finally {\n\t\t\tresolveConnection?.();\n\t\t\tclearTimeout(timeout);\n\t\t\tcontroller.abort();\n\t\t\tif (this.controller === controller) this.connectionId = undefined;\n\t\t\tif (this.controller === controller && !this.disposed && !this.closing && this.deletedSessionId !== sessionId) {\n\t\t\t\tthis.reconnectTimer = setTimeout(\n\t\t\t\t\t() => {\n\t\t\t\t\t\tthis.reconnectTimer = undefined;\n\t\t\t\t\t\tvoid this.connect();\n\t\t\t\t\t},\n\t\t\t\t\tsessionId === this.session.sessionId ? 2000 : 0,\n\t\t\t\t);\n\t\t\t\tthis.reconnectTimer.unref();\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate flush(): Promise<void> {\n\t\tif (this.flushPromise) return this.flushPromise;\n\t\tconst promise = this.sendUpdate();\n\t\tthis.flushPromise = promise;\n\t\tvoid promise.finally(() => {\n\t\t\tthis.flushPromise = undefined;\n\t\t});\n\t\treturn promise;\n\t}\n\n\tprivate async sendUpdate(): Promise<void> {\n\t\tconst connectionId = this.connectionId;\n\t\tconst sessionId = this.connectedSessionId;\n\t\tconst controller = this.controller;\n\t\tif (\n\t\t\t!connectionId ||\n\t\t\t!sessionId ||\n\t\t\t!controller ||\n\t\t\tthis.disposed ||\n\t\t\tthis.deletedSessionId === sessionId ||\n\t\t\tthis.sending ||\n\t\t\t!this.dirty\n\t\t)\n\t\t\treturn;\n\t\tthis.sending = true;\n\t\tthis.dirty = false;\n\t\ttry {\n\t\t\tconst branch = this.historyDirty ? this.session.sessionManager.getBranch() : undefined;\n\t\t\tconst sentIndex = branch && this.sentEntryId ? branch.findIndex((entry) => entry.id === this.sentEntryId) : -1;\n\t\t\tconst replace = this.replace || (branch !== undefined && this.sentEntryId !== undefined && sentIndex === -1);\n\t\t\tthis.historyDirty = false;\n\t\t\tthis.replace = false;\n\t\t\tconst entries = branch ? (replace ? branch : branch.slice(sentIndex + 1)) : this.pendingEntries;\n\t\t\tthis.pendingEntries = [];\n\t\t\tconst messages = projectObserverEntries(entries);\n\t\t\tif (replace) this.firstUserTitle = \"\";\n\t\t\tif (!this.firstUserTitle) {\n\t\t\t\tconst firstUserContent = messages.find((message) => message.role === \"user\")?.content;\n\t\t\t\tthis.firstUserTitle = (\n\t\t\t\t\ttypeof firstUserContent === \"string\"\n\t\t\t\t\t\t? firstUserContent\n\t\t\t\t\t\t: (firstUserContent\n\t\t\t\t\t\t\t\t?.filter((part) => part.type === \"text\")\n\t\t\t\t\t\t\t\t.map((part) => part.text)\n\t\t\t\t\t\t\t\t.join(\"\") ?? \"\")\n\t\t\t\t).slice(0, 120);\n\t\t\t}\n\t\t\tconst update: ObserverUpdate = {\n\t\t\t\tsessionId,\n\t\t\t\tconnectionId,\n\t\t\t\tsequence: ++this.sequence,\n\t\t\t\tcwd: this.session.sessionManager.getCwd(),\n\t\t\t\ttitle: this.session.sessionManager.getSessionName() ?? this.firstUserTitle,\n\t\t\t\t...(replace ? { replace: messages } : messages.length ? { append: messages } : {}),\n\t\t\t\tstatus: this.session.isIdle ? \"idle\" : \"running\",\n\t\t\t\tlive: {\n\t\t\t\t\tmessage: this.liveMessage ? (projectMessage(this.liveMessageId, this.liveMessage) ?? null) : null,\n\t\t\t\t\ttools: [...this.tools.values()],\n\t\t\t\t},\n\t\t\t};\n\t\t\tconst response = await this.request(controller.signal).postJson(\"/api/observer\", update);\n\t\t\tif (response.status === 410) {\n\t\t\t\tthis.stopDeletedSession(sessionId, controller);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (!response.ok) throw new Error(`update failed (HTTP ${response.status})`);\n\t\t\tconst result = (await response.json()) as { accepted: boolean };\n\t\t\tif (!result.accepted) throw new Error(\"update was not accepted\");\n\t\t\tif (entries.length > 0) this.sentEntryId = entries.at(-1)?.id;\n\t\t\telse if (replace) this.sentEntryId = undefined;\n\t\t\tif (this.disconnected) {\n\t\t\t\tthis.disconnected = false;\n\t\t\t\tconsole.error(\"pi-server observer connected\");\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tif (sessionId === this.session.sessionId && this.deletedSessionId !== sessionId) this.reportError(error);\n\t\t\tcontroller.abort();\n\t\t} finally {\n\t\t\tthis.sending = false;\n\t\t\tthis.schedule(80);\n\t\t}\n\t}\n\n\tclose(): Promise<void> {\n\t\tthis.closePromise ??= this.drainAndClose();\n\t\treturn this.closePromise;\n\t}\n\n\tprivate async drainAndClose(): Promise<void> {\n\t\tif (this.disposed) return;\n\t\tthis.closing = true;\n\t\tclearTimeout(this.timer);\n\t\tthis.timer = undefined;\n\t\tclearTimeout(this.reconnectTimer);\n\t\ttry {\n\t\t\tawait raceWithAbortSignal(\n\t\t\t\t(async () => {\n\t\t\t\t\tif (this.deletedSessionId === this.session.sessionId) return;\n\t\t\t\t\tif (!this.connectionId && this.controller?.signal.aborted) void this.connect();\n\t\t\t\t\tawait this.connectionReady;\n\t\t\t\t\tawait this.flushPromise;\n\t\t\t\t\tif (!this.connectionId) throw new Error(\"final transcript was not delivered: observer is disconnected\");\n\t\t\t\t\twhile (this.dirty && this.connectionId && !this.disposed) await this.flush();\n\t\t\t\t\tif (this.controller?.signal.aborted && this.deletedSessionId !== this.session.sessionId)\n\t\t\t\t\t\tthrow new Error(\"final transcript was not delivered: observer update failed\");\n\t\t\t\t})(),\n\t\t\t\tAbortSignal.timeout(10000),\n\t\t\t);\n\t\t} catch (error) {\n\t\t\tconsole.error(`pi-server observer shutdown failed: ${error instanceof Error ? error.message : String(error)}`);\n\t\t} finally {\n\t\t\tthis.dispose();\n\t\t}\n\t}\n\n\tdispose(): void {\n\t\tthis.disposed = true;\n\t\tthis.unsubscribe();\n\t\tclearTimeout(this.timer);\n\t\tclearTimeout(this.reconnectTimer);\n\t\tthis.controller?.abort();\n\t\tobservers.delete(this.session);\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"pi-server-observer.js","sourceRoot":"","sources":["../../src/core/pi-server-observer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAGzC,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAExD,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,EAAyB,iBAAiB,EAAE,wBAAwB,EAAE,MAAM,0BAA0B,CAAC;AAG9G,MAAM,SAAS,GAAG,IAAI,OAAO,EAAkC,CAAC;AAEhE,MAAM,CAAC,KAAK,UAAU,qBAAqB,CAAC,OAAqB;IAChE,MAAM,SAAS,CAAC,GAAG,CAAC,OAAO,CAAC,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,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACzB,YAAY,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;QAClC,IAAI,CAAC,UAAU,EAAE,KAAK,EAAE,CAAC;QACzB,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAChC,CAAC;CACD","sourcesContent":["import { randomUUID } from \"node:crypto\";\nimport type { AgentMessage } from \"@earendil-works/pi-agent-core\";\nimport type { ImageContent, TextContent, TextSignatureV1, ThinkingContent, ToolCall } from \"@earendil-works/pi-ai\";\nimport { raceWithAbortSignal } from \"../utils/abort.ts\";\nimport type { AgentSession, AgentSessionEvent } from \"./agent-session.ts\";\nimport { bashExecutionToText } from \"./messages.ts\";\nimport { ChunkRequest } from \"./pi-server-request.ts\";\nimport { type ObserverSubagent, PiServerSubagents, resolvePiServerSubagents } from \"./pi-server-subagents.ts\";\nimport type { SessionEntry } from \"./session-manager.ts\";\n\nconst observers = new WeakMap<AgentSession, PiServerObserver>();\n\nexport async function closePiServerObserver(session: AgentSession): Promise<void> {\n\tawait observers.get(session)?.close();\n}\n\ntype ViewerContent =\n\t| { type: \"text\"; text: string; phase?: TextSignatureV1[\"phase\"] }\n\t| { type: \"thinking\"; thinking: string }\n\t| { type: \"toolCall\"; id: string; name: string; arguments: unknown }\n\t| { type: \"attachment\"; label: string };\n\nexport interface ObserverMessage {\n\tid: string;\n\trole: string;\n\tcontent: string | ViewerContent[];\n\ttimestamp: number;\n\tstopReason?: string;\n\tphase?: string;\n\terrorMessage?: string;\n}\n\ninterface ObserverTool {\n\tid: string;\n\tname: string;\n\targuments: unknown;\n\tresult?: unknown;\n\tstatus: \"running\" | \"completed\" | \"error\";\n}\n\nexport interface ObserverUpdate {\n\tsessionId: string;\n\tconnectionId: string;\n\tsequence: number;\n\tcwd: string;\n\ttitle: string;\n\tsubagents?: ObserverSubagent[];\n\treplace?: ObserverMessage[];\n\tappend?: ObserverMessage[];\n\tstatus: \"running\" | \"idle\";\n\tlive: { message: ObserverMessage | null; tools: ObserverTool[] };\n}\n\nfunction textPhase(signature: string | undefined): TextSignatureV1[\"phase\"] {\n\tif (!signature?.startsWith(\"{\")) return undefined;\n\ttry {\n\t\tconst parsed = JSON.parse(signature) as Partial<TextSignatureV1>;\n\t\tif (\n\t\t\tparsed.v === 1 &&\n\t\t\ttypeof parsed.id === \"string\" &&\n\t\t\t(parsed.phase === \"commentary\" || parsed.phase === \"final_answer\")\n\t\t)\n\t\t\treturn parsed.phase;\n\t} catch {\n\t\t// Provider signatures outside TextSignatureV1 have no display phase.\n\t}\n\treturn undefined;\n}\n\nfunction projectContent(\n\tcontent: string | (TextContent | ThinkingContent | ImageContent | ToolCall)[],\n): ObserverMessage[\"content\"] {\n\tif (typeof content === \"string\") return content;\n\treturn content.map((part): ViewerContent => {\n\t\tif (part.type === \"text\") return { type: \"text\", text: part.text, phase: textPhase(part.textSignature) };\n\t\tif (part.type === \"thinking\") return { type: \"thinking\", thinking: part.thinking };\n\t\tif (part.type === \"toolCall\")\n\t\t\treturn { type: \"toolCall\", id: part.id, name: part.name, arguments: part.arguments };\n\t\treturn { type: \"attachment\", label: part.mimeType };\n\t});\n}\n\nfunction projectMessage(id: string, message: AgentMessage, timestamp = message.timestamp): ObserverMessage | undefined {\n\tif (message.role === \"system\" || (message.role === \"custom\" && !message.display)) return undefined;\n\tlet content: ObserverMessage[\"content\"];\n\tif (message.role === \"bashExecution\") content = bashExecutionToText(message);\n\telse if (message.role === \"compactionSummary\" || message.role === \"branchSummary\") content = message.summary;\n\telse content = projectContent(message.content);\n\tconst projected: ObserverMessage = { id, role: message.role, content, timestamp };\n\tif (message.role === \"assistant\") {\n\t\tprojected.stopReason = message.stopReason;\n\t\tprojected.errorMessage = message.errorMessage;\n\t\tfor (const part of message.content) {\n\t\t\tconst phase = part.type === \"text\" ? textPhase(part.textSignature) : undefined;\n\t\t\tif (phase) projected.phase = phase;\n\t\t}\n\t}\n\treturn projected;\n}\n\nexport function projectObserverEntries(entries: SessionEntry[]): ObserverMessage[] {\n\tconst messages: ObserverMessage[] = [];\n\tfor (const entry of entries) {\n\t\tlet message: ObserverMessage | undefined;\n\t\tif (entry.type === \"message\") message = projectMessage(entry.id, entry.message, Date.parse(entry.timestamp));\n\t\telse if (entry.type === \"custom_message\" && entry.display) {\n\t\t\tmessage = {\n\t\t\t\tid: entry.id,\n\t\t\t\trole: \"custom\",\n\t\t\t\tcontent: projectContent(entry.content),\n\t\t\t\ttimestamp: Date.parse(entry.timestamp),\n\t\t\t};\n\t\t} else if (entry.type === \"compaction\" || entry.type === \"branch_summary\") {\n\t\t\tmessage = { id: entry.id, role: entry.type, content: entry.summary, timestamp: Date.parse(entry.timestamp) };\n\t\t}\n\t\tif (message) messages.push(message);\n\t}\n\treturn messages;\n}\n\n/** Publishes transcript updates independently of provider requests and durable server trees. */\nexport class PiServerObserver {\n\tprivate readonly session: AgentSession;\n\tprivate readonly unsubscribe: () => void;\n\tprivate controller?: AbortController;\n\tprivate timer?: ReturnType<typeof setTimeout>;\n\tprivate reconnectTimer?: ReturnType<typeof setTimeout>;\n\tprivate disposed = false;\n\tprivate closing = false;\n\tprivate closePromise?: Promise<void>;\n\tprivate connectionReady?: Promise<void>;\n\tprivate deletedSessionId?: string;\n\tprivate connectionId?: string;\n\tprivate connectedSessionId?: string;\n\tprivate sequence = 0;\n\tprivate sending = false;\n\tprivate flushPromise?: Promise<void>;\n\tprivate dirty = true;\n\tprivate historyDirty = true;\n\tprivate replace = true;\n\tprivate sentEntryId?: string;\n\tprivate pendingEntries: SessionEntry[] = [];\n\tprivate firstUserTitle = \"\";\n\tprivate liveMessage: AgentMessage | null = null;\n\tprivate liveMessageId = \"\";\n\tprivate readonly tools = new Map<string, ObserverTool>();\n\tprivate disconnected = false;\n\tprivate observedSessionId?: string;\n\tprivate readonly subagents: PiServerSubagents;\n\tprivate sentSubagentVersion = -1;\n\n\tconstructor(session: AgentSession) {\n\t\tthis.session = session;\n\t\tthis.subagents = new PiServerSubagents(session, () => {\n\t\t\tthis.dirty = true;\n\t\t\tthis.historyDirty = true;\n\t\t\tthis.schedule(0);\n\t\t});\n\t\tthis.syncSession();\n\t\tobservers.set(session, this);\n\t\tthis.unsubscribe = session.subscribe((event) => {\n\t\t\ttry {\n\t\t\t\tthis.handleEvent(event);\n\t\t\t} catch (error) {\n\t\t\t\tthis.reportError(error);\n\t\t\t}\n\t\t});\n\t\tvoid this.connect();\n\t}\n\n\tprivate handleEvent(event: AgentSessionEvent): void {\n\t\tthis.syncSession();\n\t\tswitch (event.type) {\n\t\t\tcase \"session_disposed\":\n\t\t\t\tthis.dispose();\n\t\t\t\treturn;\n\t\t\tcase \"run_state_changed\":\n\t\t\t\tresolvePiServerSubagents();\n\t\t\t\tif (!event.running) {\n\t\t\t\t\tthis.liveMessage = null;\n\t\t\t\t\tthis.tools.clear();\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tcase \"message_start\":\n\t\t\t\tif (event.message.role !== \"assistant\") return;\n\t\t\t\tthis.tools.clear();\n\t\t\t\tthis.liveMessageId = randomUUID();\n\t\t\t\tthis.liveMessage = event.message;\n\t\t\t\tbreak;\n\t\t\tcase \"message_update\":\n\t\t\t\tthis.liveMessage = event.message;\n\t\t\t\tbreak;\n\t\t\tcase \"entry_appended\":\n\t\t\tcase \"message_committed\":\n\t\t\t\tif (this.connectionId && !this.historyDirty) {\n\t\t\t\t\tthis.pendingEntries.push(event.entry);\n\t\t\t\t\tif (this.pendingEntries.length > 64) {\n\t\t\t\t\t\tthis.pendingEntries = [];\n\t\t\t\t\t\tthis.historyDirty = true;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (event.entry.type === \"message\" && event.entry.message.role === \"assistant\") this.liveMessage = null;\n\t\t\t\tbreak;\n\t\t\tcase \"history_reconciled\":\n\t\t\tcase \"session_tree_changed\":\n\t\t\t\tthis.subagents.restore();\n\t\t\t\tif (this.deletedSessionId && this.deletedSessionId !== this.session.sessionId) {\n\t\t\t\t\tthis.deletedSessionId = undefined;\n\t\t\t\t\tvoid this.connect();\n\t\t\t\t}\n\t\t\t\tif (this.connectedSessionId && this.connectedSessionId !== this.session.sessionId) {\n\t\t\t\t\tthis.connectionId = undefined;\n\t\t\t\t\tthis.controller?.abort();\n\t\t\t\t}\n\t\t\t\tthis.replace = true;\n\t\t\t\tthis.historyDirty = true;\n\t\t\t\tbreak;\n\t\t\tcase \"compaction_end\":\n\t\t\t\tthis.historyDirty = true;\n\t\t\t\tbreak;\n\t\t\tcase \"compaction_start\":\n\t\t\t\tbreak;\n\t\t\tcase \"session_info_changed\":\n\t\t\t\tbreak;\n\t\t\tcase \"tool_execution_start\":\n\t\t\t\tthis.tools.set(event.toolCallId, {\n\t\t\t\t\tid: event.toolCallId,\n\t\t\t\t\tname: event.toolName,\n\t\t\t\t\targuments: event.args,\n\t\t\t\t\tstatus: \"running\",\n\t\t\t\t});\n\t\t\t\tbreak;\n\t\t\tcase \"tool_execution_update\": {\n\t\t\t\tconst tool = this.tools.get(event.toolCallId);\n\t\t\t\tif (tool) tool.result = { content: projectContent(event.partialResult.content) };\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase \"tool_execution_end\": {\n\t\t\t\tconst tool = this.tools.get(event.toolCallId);\n\t\t\t\tif (tool) {\n\t\t\t\t\ttool.result = { content: projectContent(event.result.content), isError: event.isError };\n\t\t\t\t\ttool.status = event.isError ? \"error\" : \"completed\";\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tdefault:\n\t\t\t\treturn;\n\t\t}\n\t\tthis.dirty = true;\n\t\tthis.schedule(\n\t\t\tevent.type === \"run_state_changed\" || event.type === \"compaction_start\" || event.type === \"compaction_end\"\n\t\t\t\t? 0\n\t\t\t\t: 80,\n\t\t);\n\t}\n\n\tprivate syncSession(): void {\n\t\tif (this.observedSessionId === this.session.sessionId) return;\n\t\tthis.observedSessionId = this.session.sessionId;\n\t\tthis.subagents.syncSession();\n\t\tthis.sentSubagentVersion = -1;\n\t\tthis.sentEntryId = undefined;\n\t\tthis.pendingEntries = [];\n\t\tthis.firstUserTitle = \"\";\n\t\tthis.liveMessage = null;\n\t\tthis.tools.clear();\n\t}\n\n\tprivate schedule(delay: number): void {\n\t\tif (\n\t\t\tthis.disposed ||\n\t\t\tthis.closing ||\n\t\t\tthis.deletedSessionId === this.session.sessionId ||\n\t\t\t!this.dirty ||\n\t\t\t!this.connectionId ||\n\t\t\tthis.sending ||\n\t\t\tthis.timer\n\t\t)\n\t\t\treturn;\n\t\tthis.timer = setTimeout(() => {\n\t\t\tthis.timer = undefined;\n\t\t\tvoid this.flush();\n\t\t}, delay);\n\t\tthis.timer.unref();\n\t}\n\n\tprivate reportError(error: unknown): void {\n\t\tif (this.disposed || this.disconnected) return;\n\t\tthis.disconnected = true;\n\t\tconsole.error(`pi-server observer disconnected: ${error instanceof Error ? error.message : String(error)}`);\n\t}\n\n\tprivate stopDeletedSession(sessionId: string, controller: AbortController): void {\n\t\tif (sessionId === this.session.sessionId) {\n\t\t\tthis.deletedSessionId = sessionId;\n\t\t\tthis.connectionId = undefined;\n\t\t\tthis.pendingEntries = [];\n\t\t\tthis.liveMessage = null;\n\t\t\tthis.tools.clear();\n\t\t\tclearTimeout(this.timer);\n\t\t\tthis.timer = undefined;\n\t\t\tclearTimeout(this.reconnectTimer);\n\t\t\tthis.reconnectTimer = undefined;\n\t\t}\n\t\tcontroller.abort();\n\t}\n\n\tprivate request(signal: AbortSignal): ChunkRequest {\n\t\treturn new ChunkRequest({\n\t\t\tserverUrl: process.env.PI_SERVER_URL ?? \"http://127.0.0.1:4217\",\n\t\t\tauthToken: process.env.PI_SERVER_AUTH_TOKEN ?? \"\",\n\t\t\tsignal,\n\t\t});\n\t}\n\n\tprivate async connect(): Promise<void> {\n\t\tif (this.disposed || this.deletedSessionId === this.session.sessionId) return;\n\t\tthis.syncSession();\n\t\tconst controller = new AbortController();\n\t\tthis.controller = controller;\n\t\tconst sessionId = this.session.sessionId;\n\t\tthis.connectedSessionId = sessionId;\n\t\tlet resolveConnection: (() => void) | undefined;\n\t\tthis.connectionReady = new Promise<void>((resolve) => {\n\t\t\tresolveConnection = resolve;\n\t\t});\n\t\tconst timeout = setTimeout(() => controller.abort(new Error(\"connection timed out\")), 10000);\n\t\ttimeout.unref();\n\t\ttry {\n\t\t\tconst response = await this.request(controller.signal).getJson(\n\t\t\t\t`/api/observer/connect?sessionId=${encodeURIComponent(sessionId)}`,\n\t\t\t);\n\t\t\tif (response.status === 410) {\n\t\t\t\tthis.stopDeletedSession(sessionId, controller);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (!response.ok || !response.headers.get(\"content-type\")?.includes(\"text/event-stream\") || !response.body) {\n\t\t\t\tthrow new Error(`connection failed (HTTP ${response.status})`);\n\t\t\t}\n\t\t\tconst reader = response.body.getReader();\n\t\t\tconst decoder = new TextDecoder();\n\t\t\tlet buffer = \"\";\n\t\t\tlet event = \"\";\n\t\t\ttry {\n\t\t\t\twhile (!this.disposed) {\n\t\t\t\t\tconst { done, value } = await reader.read();\n\t\t\t\t\tif (done) throw new Error(\"connection closed\");\n\t\t\t\t\tbuffer += decoder.decode(value, { stream: true });\n\t\t\t\t\tlet newline = buffer.indexOf(\"\\n\");\n\t\t\t\t\twhile (newline !== -1) {\n\t\t\t\t\t\tconst line = buffer.slice(0, newline).replace(/\\r$/, \"\");\n\t\t\t\t\t\tbuffer = buffer.slice(newline + 1);\n\t\t\t\t\t\tif (line.startsWith(\"event:\")) event = line.slice(6).trim();\n\t\t\t\t\t\tif (event === \"deleted\" && line.startsWith(\"data:\")) {\n\t\t\t\t\t\t\tthis.stopDeletedSession(sessionId, controller);\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (event === \"connected\" && !this.connectionId && line.startsWith(\"data:\")) {\n\t\t\t\t\t\t\tconst connected = JSON.parse(line.slice(5)) as { connectionId: string };\n\t\t\t\t\t\t\tthis.connectionId = connected.connectionId;\n\t\t\t\t\t\t\tthis.sequence = 0;\n\t\t\t\t\t\t\tthis.sentSubagentVersion = -1;\n\t\t\t\t\t\t\tclearTimeout(timeout);\n\t\t\t\t\t\t\tthis.replace = true;\n\t\t\t\t\t\t\tthis.historyDirty = true;\n\t\t\t\t\t\t\tthis.dirty = true;\n\t\t\t\t\t\t\tthis.schedule(0);\n\t\t\t\t\t\t\tresolveConnection?.();\n\t\t\t\t\t\t}\n\t\t\t\t\t\tnewline = buffer.indexOf(\"\\n\");\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} finally {\n\t\t\t\tawait reader.cancel();\n\t\t\t\treader.releaseLock();\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tif (sessionId === this.session.sessionId && this.deletedSessionId !== sessionId) this.reportError(error);\n\t\t} finally {\n\t\t\tresolveConnection?.();\n\t\t\tclearTimeout(timeout);\n\t\t\tcontroller.abort();\n\t\t\tif (this.controller === controller) this.connectionId = undefined;\n\t\t\tif (this.controller === controller && !this.disposed && !this.closing && this.deletedSessionId !== sessionId) {\n\t\t\t\tthis.reconnectTimer = setTimeout(\n\t\t\t\t\t() => {\n\t\t\t\t\t\tthis.reconnectTimer = undefined;\n\t\t\t\t\t\tvoid this.connect();\n\t\t\t\t\t},\n\t\t\t\t\tsessionId === this.session.sessionId ? 2000 : 0,\n\t\t\t\t);\n\t\t\t\tthis.reconnectTimer.unref();\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate flush(): Promise<void> {\n\t\tif (this.flushPromise) return this.flushPromise;\n\t\tconst promise = this.sendUpdate();\n\t\tthis.flushPromise = promise;\n\t\tvoid promise.finally(() => {\n\t\t\tthis.flushPromise = undefined;\n\t\t});\n\t\treturn promise;\n\t}\n\n\tprivate async sendUpdate(): Promise<void> {\n\t\tthis.subagents.resolve();\n\t\tconst connectionId = this.connectionId;\n\t\tconst sessionId = this.connectedSessionId;\n\t\tconst controller = this.controller;\n\t\tif (\n\t\t\t!connectionId ||\n\t\t\t!sessionId ||\n\t\t\tsessionId !== this.session.sessionId ||\n\t\t\t!controller ||\n\t\t\tthis.disposed ||\n\t\t\tthis.deletedSessionId === sessionId ||\n\t\t\tthis.sending ||\n\t\t\t!this.dirty\n\t\t)\n\t\t\treturn;\n\t\tthis.sending = true;\n\t\tthis.dirty = false;\n\t\ttry {\n\t\t\tconst branch = this.historyDirty ? this.session.sessionManager.getBranch() : undefined;\n\t\t\tconst sentIndex = branch && this.sentEntryId ? branch.findIndex((entry) => entry.id === this.sentEntryId) : -1;\n\t\t\tconst replace = this.replace || (branch !== undefined && this.sentEntryId !== undefined && sentIndex === -1);\n\t\t\tthis.historyDirty = false;\n\t\t\tthis.replace = false;\n\t\t\tconst entries = branch ? (replace ? branch : branch.slice(sentIndex + 1)) : this.pendingEntries;\n\t\t\tthis.pendingEntries = [];\n\t\t\tconst messages = projectObserverEntries(entries);\n\t\t\tif (replace) this.firstUserTitle = \"\";\n\t\t\tif (!this.firstUserTitle) {\n\t\t\t\tconst firstUserContent = messages.find((message) => message.role === \"user\")?.content;\n\t\t\t\tthis.firstUserTitle = (\n\t\t\t\t\ttypeof firstUserContent === \"string\"\n\t\t\t\t\t\t? firstUserContent\n\t\t\t\t\t\t: (firstUserContent\n\t\t\t\t\t\t\t\t?.filter((part) => part.type === \"text\")\n\t\t\t\t\t\t\t\t.map((part) => part.text)\n\t\t\t\t\t\t\t\t.join(\"\") ?? \"\")\n\t\t\t\t).slice(0, 120);\n\t\t\t}\n\t\t\tconst subagentVersion = this.subagents.version;\n\t\t\tconst update: ObserverUpdate = {\n\t\t\t\tsessionId,\n\t\t\t\tconnectionId,\n\t\t\t\tsequence: ++this.sequence,\n\t\t\t\tcwd: this.session.sessionManager.getCwd(),\n\t\t\t\ttitle: this.session.sessionManager.getSessionName() ?? this.firstUserTitle,\n\t\t\t\t...(subagentVersion !== this.sentSubagentVersion ? { subagents: this.subagents.snapshot() } : {}),\n\t\t\t\t...(replace ? { replace: messages } : messages.length ? { append: messages } : {}),\n\t\t\t\tstatus: this.session.isIdle ? \"idle\" : \"running\",\n\t\t\t\tlive: {\n\t\t\t\t\tmessage: this.liveMessage ? (projectMessage(this.liveMessageId, this.liveMessage) ?? null) : null,\n\t\t\t\t\ttools: [...this.tools.values()],\n\t\t\t\t},\n\t\t\t};\n\t\t\tconst response = await this.request(controller.signal).postJson(\"/api/observer\", update);\n\t\t\tif (response.status === 410) {\n\t\t\t\tthis.stopDeletedSession(sessionId, controller);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (!response.ok) throw new Error(`update failed (HTTP ${response.status})`);\n\t\t\tconst result = (await response.json()) as { accepted: boolean };\n\t\t\tif (!result.accepted) throw new Error(\"update was not accepted\");\n\t\t\tif (sessionId !== this.session.sessionId) return;\n\t\t\tthis.sentSubagentVersion = subagentVersion;\n\t\t\tif (entries.length > 0) this.sentEntryId = entries.at(-1)?.id;\n\t\t\telse if (replace) this.sentEntryId = undefined;\n\t\t\tif (this.disconnected) {\n\t\t\t\tthis.disconnected = false;\n\t\t\t\tconsole.error(\"pi-server observer connected\");\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tif (sessionId === this.session.sessionId && this.deletedSessionId !== sessionId) this.reportError(error);\n\t\t\tcontroller.abort();\n\t\t} finally {\n\t\t\tthis.sending = false;\n\t\t\tthis.schedule(80);\n\t\t}\n\t}\n\n\tclose(): Promise<void> {\n\t\tthis.closePromise ??= this.drainAndClose();\n\t\treturn this.closePromise;\n\t}\n\n\tprivate async drainAndClose(): Promise<void> {\n\t\tif (this.disposed) return;\n\t\tthis.closing = true;\n\t\tclearTimeout(this.timer);\n\t\tthis.timer = undefined;\n\t\tclearTimeout(this.reconnectTimer);\n\t\ttry {\n\t\t\tawait raceWithAbortSignal(\n\t\t\t\t(async () => {\n\t\t\t\t\tif (this.deletedSessionId === this.session.sessionId) return;\n\t\t\t\t\tif (!this.connectionId && this.controller?.signal.aborted) void this.connect();\n\t\t\t\t\tawait this.connectionReady;\n\t\t\t\t\tawait this.flushPromise;\n\t\t\t\t\tif (!this.connectionId) throw new Error(\"final transcript was not delivered: observer is disconnected\");\n\t\t\t\t\twhile (this.dirty && this.connectionId && !this.disposed) await this.flush();\n\t\t\t\t\tif (this.controller?.signal.aborted && this.deletedSessionId !== this.session.sessionId)\n\t\t\t\t\t\tthrow new Error(\"final transcript was not delivered: observer update failed\");\n\t\t\t\t})(),\n\t\t\t\tAbortSignal.timeout(10000),\n\t\t\t);\n\t\t} catch (error) {\n\t\t\tconsole.error(`pi-server observer shutdown failed: ${error instanceof Error ? error.message : String(error)}`);\n\t\t} finally {\n\t\t\tthis.dispose();\n\t\t}\n\t}\n\n\tdispose(): void {\n\t\tthis.disposed = true;\n\t\tthis.unsubscribe();\n\t\tthis.subagents.dispose();\n\t\tclearTimeout(this.timer);\n\t\tclearTimeout(this.reconnectTimer);\n\t\tthis.controller?.abort();\n\t\tobservers.delete(this.session);\n\t}\n}\n"]}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { AgentSession } from "./agent-session.ts";
|
|
2
|
+
export interface ObserverSubagent {
|
|
3
|
+
agentId: string;
|
|
4
|
+
sessionId: string;
|
|
5
|
+
title: string;
|
|
6
|
+
taskStatus: "queued" | "running" | "completed" | "steered" | "error" | "stopped" | "aborted";
|
|
7
|
+
}
|
|
8
|
+
/** Child sessions begin running after pi-subagents attaches them to their task record. */
|
|
9
|
+
export declare function resolvePiServerSubagents(): void;
|
|
10
|
+
/** Adapts tintinweb's exact task identities and lifecycle to viewer session identities. */
|
|
11
|
+
export declare class PiServerSubagents {
|
|
12
|
+
private readonly session;
|
|
13
|
+
private readonly onChange;
|
|
14
|
+
private readonly pending;
|
|
15
|
+
private readonly tasks;
|
|
16
|
+
private subscriptions;
|
|
17
|
+
private sessionId?;
|
|
18
|
+
version: number;
|
|
19
|
+
constructor(session: AgentSession, onChange: () => void);
|
|
20
|
+
syncSession(): void;
|
|
21
|
+
restore(): void;
|
|
22
|
+
resolve(): void;
|
|
23
|
+
snapshot(): ObserverSubagent[];
|
|
24
|
+
dispose(): void;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=pi-server-subagents.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pi-server-subagents.d.ts","sourceRoot":"","sources":["../../src/core/pi-server-subagents.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAEvD,MAAM,WAAW,gBAAgB;IAChC,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,QAAQ,GAAG,SAAS,GAAG,WAAW,GAAG,SAAS,GAAG,OAAO,GAAG,SAAS,GAAG,SAAS,CAAC;CAC7F;AAgBD,0FAA0F;AAC1F,wBAAgB,wBAAwB,IAAI,IAAI,CAE/C;AAED,2FAA2F;AAC3F,qBAAa,iBAAiB;IAC7B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAe;IACvC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAa;IACtC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAqB;IAC7C,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAuC;IAC7D,OAAO,CAAC,aAAa,CAAsB;IAC3C,OAAO,CAAC,SAAS,CAAC,CAAS;IAC3B,OAAO,SAAK;IAEZ,YAAY,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,IAAI,EAItD;IAED,WAAW,IAAI,IAAI,CAiBlB;IAED,OAAO,IAAI,IAAI,CAqBd;IAED,OAAO,IAAI,IAAI,CAqCd;IAED,QAAQ,IAAI,gBAAgB,EAAE,CAE7B;IAED,OAAO,IAAI,IAAI,CAKd;CACD"}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
const registryKey = Symbol.for("pi-subagents:manager");
|
|
2
|
+
const pendingBridges = new Set();
|
|
3
|
+
/** Child sessions begin running after pi-subagents attaches them to their task record. */
|
|
4
|
+
export function resolvePiServerSubagents() {
|
|
5
|
+
for (const bridge of pendingBridges)
|
|
6
|
+
bridge.resolve();
|
|
7
|
+
}
|
|
8
|
+
/** Adapts tintinweb's exact task identities and lifecycle to viewer session identities. */
|
|
9
|
+
export class PiServerSubagents {
|
|
10
|
+
session;
|
|
11
|
+
onChange;
|
|
12
|
+
pending = new Set();
|
|
13
|
+
tasks = new Map();
|
|
14
|
+
subscriptions = [];
|
|
15
|
+
sessionId;
|
|
16
|
+
version = 0;
|
|
17
|
+
constructor(session, onChange) {
|
|
18
|
+
this.session = session;
|
|
19
|
+
this.onChange = onChange;
|
|
20
|
+
this.syncSession();
|
|
21
|
+
}
|
|
22
|
+
syncSession() {
|
|
23
|
+
if (this.sessionId === this.session.sessionId)
|
|
24
|
+
return;
|
|
25
|
+
this.dispose();
|
|
26
|
+
this.sessionId = this.session.sessionId;
|
|
27
|
+
this.restore();
|
|
28
|
+
const events = this.session.resourceLoader.getEventBus?.();
|
|
29
|
+
if (!events)
|
|
30
|
+
return;
|
|
31
|
+
const sessionId = this.sessionId;
|
|
32
|
+
this.subscriptions = ["started", "created", "completed", "failed"].map((event) => events.on(`subagents:${event}`, (data) => {
|
|
33
|
+
if (this.session.sessionId !== sessionId)
|
|
34
|
+
return;
|
|
35
|
+
const { id } = data;
|
|
36
|
+
this.pending.add(id);
|
|
37
|
+
pendingBridges.add(this);
|
|
38
|
+
this.resolve();
|
|
39
|
+
}));
|
|
40
|
+
}
|
|
41
|
+
restore() {
|
|
42
|
+
let snapshot = [];
|
|
43
|
+
for (const entry of this.session.sessionManager.getEntries()) {
|
|
44
|
+
if (entry.type !== "custom" || entry.customType !== "pi-server-subagent")
|
|
45
|
+
continue;
|
|
46
|
+
snapshot = entry.data.subagents;
|
|
47
|
+
}
|
|
48
|
+
if (snapshot.length === this.tasks.size &&
|
|
49
|
+
snapshot.every((task) => {
|
|
50
|
+
const current = this.tasks.get(task.sessionId);
|
|
51
|
+
return (current?.agentId === task.agentId &&
|
|
52
|
+
current.title === task.title &&
|
|
53
|
+
current.taskStatus === task.taskStatus);
|
|
54
|
+
}))
|
|
55
|
+
return;
|
|
56
|
+
this.tasks.clear();
|
|
57
|
+
for (const task of snapshot)
|
|
58
|
+
this.tasks.set(task.sessionId, task);
|
|
59
|
+
this.version++;
|
|
60
|
+
}
|
|
61
|
+
resolve() {
|
|
62
|
+
if (this.sessionId !== this.session.sessionId) {
|
|
63
|
+
this.syncSession();
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
const registry = globalThis[registryKey];
|
|
67
|
+
let changed = false;
|
|
68
|
+
for (const agentId of this.pending) {
|
|
69
|
+
const record = registry?.getRecord(agentId);
|
|
70
|
+
if (!record)
|
|
71
|
+
continue;
|
|
72
|
+
const active = record.status === "running" || record.status === "queued";
|
|
73
|
+
if (!record.session) {
|
|
74
|
+
if (!active)
|
|
75
|
+
this.pending.delete(agentId);
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
const task = {
|
|
79
|
+
agentId,
|
|
80
|
+
sessionId: record.session.sessionId,
|
|
81
|
+
title: record.description || record.type,
|
|
82
|
+
taskStatus: record.status,
|
|
83
|
+
};
|
|
84
|
+
this.pending.delete(agentId);
|
|
85
|
+
const previous = this.tasks.get(task.sessionId);
|
|
86
|
+
if (previous?.agentId === task.agentId &&
|
|
87
|
+
previous.title === task.title &&
|
|
88
|
+
previous.taskStatus === task.taskStatus)
|
|
89
|
+
continue;
|
|
90
|
+
this.tasks.set(task.sessionId, task);
|
|
91
|
+
changed = true;
|
|
92
|
+
}
|
|
93
|
+
if (this.pending.size === 0)
|
|
94
|
+
pendingBridges.delete(this);
|
|
95
|
+
if (!changed)
|
|
96
|
+
return;
|
|
97
|
+
this.version++;
|
|
98
|
+
this.session.sessionManager.appendCustomEntry("pi-server-subagent", { subagents: this.snapshot() });
|
|
99
|
+
this.onChange();
|
|
100
|
+
}
|
|
101
|
+
snapshot() {
|
|
102
|
+
return [...this.tasks.values()];
|
|
103
|
+
}
|
|
104
|
+
dispose() {
|
|
105
|
+
for (const unsubscribe of this.subscriptions)
|
|
106
|
+
unsubscribe();
|
|
107
|
+
this.subscriptions = [];
|
|
108
|
+
this.pending.clear();
|
|
109
|
+
pendingBridges.delete(this);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
//# sourceMappingURL=pi-server-subagents.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pi-server-subagents.js","sourceRoot":"","sources":["../../src/core/pi-server-subagents.ts"],"names":[],"mappings":"AAoBA,MAAM,WAAW,GAAG,MAAM,CAAC,GAAG,CAAC,sBAAsB,CAAC,CAAC;AACvD,MAAM,cAAc,GAAG,IAAI,GAAG,EAAqB,CAAC;AAEpD,0FAA0F;AAC1F,MAAM,UAAU,wBAAwB;IACvC,KAAK,MAAM,MAAM,IAAI,cAAc;QAAE,MAAM,CAAC,OAAO,EAAE,CAAC;AACvD,CAAC;AAED,2FAA2F;AAC3F,MAAM,OAAO,iBAAiB;IACZ,OAAO,CAAe;IACtB,QAAQ,CAAa;IACrB,OAAO,GAAG,IAAI,GAAG,EAAU,CAAC;IAC5B,KAAK,GAAG,IAAI,GAAG,EAA4B,CAAC;IACrD,aAAa,GAAmB,EAAE,CAAC;IACnC,SAAS,CAAU;IAC3B,OAAO,GAAG,CAAC,CAAC;IAEZ,YAAY,OAAqB,EAAE,QAAoB;QACtD,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,WAAW,EAAE,CAAC;IACpB,CAAC;IAED,WAAW;QACV,IAAI,IAAI,CAAC,SAAS,KAAK,IAAI,CAAC,OAAO,CAAC,SAAS;YAAE,OAAO;QACtD,IAAI,CAAC,OAAO,EAAE,CAAC;QACf,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC;QACxC,IAAI,CAAC,OAAO,EAAE,CAAC;QACf,MAAM,MAAM,GAAG,I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AAO,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;YAC7B,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;YAChD,IACC,QAAQ,EAAE,OAAO,KAAK,IAAI,CAAC,OAAO;gBAClC,QAAQ,CAAC,KAAK,KAAK,IAAI,CAAC,KAAK;gBAC7B,QAAQ,CAAC,UAAU,KAAK,IAAI,CAAC,UAAU;gBAEvC,SAAS;YACV,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;YACrC,OAAO,GAAG,IAAI,CAAC;QAChB,CAAC;QACD,IAAI,IAAI,CAAC,OAAO,CAAC,IAAI,KAAK,CAAC;YAAE,cAAc,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QACzD,IAAI,CAAC,OAAO;YAAE,OAAO;QACrB,IAAI,CAAC,OAAO,EAAE,CAAC;QACf,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,iBAAiB,CAAC,oBAAoB,EAAE,EAAE,SAAS,EAAE,IAAI,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;QACpG,IAAI,CAAC,QAAQ,EAAE,CAAC;IACjB,CAAC;IAED,QAAQ;QACP,OAAO,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC;IACjC,CAAC;IAED,OAAO;QACN,KAAK,MAAM,WAAW,IAAI,IAAI,CAAC,aAAa;YAAE,WAAW,EAAE,CAAC;QAC5D,IAAI,CAAC,aAAa,GAAG,EAAE,CAAC;QACxB,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;QACrB,cAAc,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAC7B,CAAC;CACD","sourcesContent":["import type { AgentSession } from \"./agent-session.ts\";\n\nexport interface ObserverSubagent {\n\tagentId: string;\n\tsessionId: string;\n\ttitle: string;\n\ttaskStatus: \"queued\" | \"running\" | \"completed\" | \"steered\" | \"error\" | \"stopped\" | \"aborted\";\n}\n\ninterface SubagentRecord {\n\ttype: string;\n\tdescription: string;\n\tstatus: ObserverSubagent[\"taskStatus\"];\n\tsession?: { sessionId: string };\n}\n\ninterface SubagentRegistry {\n\tgetRecord(id: string): SubagentRecord | undefined;\n}\n\nconst registryKey = Symbol.for(\"pi-subagents:manager\");\nconst pendingBridges = new Set<PiServerSubagents>();\n\n/** Child sessions begin running after pi-subagents attaches them to their task record. */\nexport function resolvePiServerSubagents(): void {\n\tfor (const bridge of pendingBridges) bridge.resolve();\n}\n\n/** Adapts tintinweb's exact task identities and lifecycle to viewer session identities. */\nexport class PiServerSubagents {\n\tprivate readonly session: AgentSession;\n\tprivate readonly onChange: () => void;\n\tprivate readonly pending = new Set<string>();\n\tprivate readonly tasks = new Map<string, ObserverSubagent>();\n\tprivate subscriptions: (() => void)[] = [];\n\tprivate sessionId?: string;\n\tversion = 0;\n\n\tconstructor(session: AgentSession, onChange: () => void) {\n\t\tthis.session = session;\n\t\tthis.onChange = onChange;\n\t\tthis.syncSession();\n\t}\n\n\tsyncSession(): void {\n\t\tif (this.sessionId === this.session.sessionId) return;\n\t\tthis.dispose();\n\t\tthis.sessionId = this.session.sessionId;\n\t\tthis.restore();\n\t\tconst events = this.session.resourceLoader.getEventBus?.();\n\t\tif (!events) return;\n\t\tconst sessionId = this.sessionId;\n\t\tthis.subscriptions = [\"started\", \"created\", \"completed\", \"failed\"].map((event) =>\n\t\t\tevents.on(`subagents:${event}`, (data) => {\n\t\t\t\tif (this.session.sessionId !== sessionId) return;\n\t\t\t\tconst { id } = data as { id: string };\n\t\t\t\tthis.pending.add(id);\n\t\t\t\tpendingBridges.add(this);\n\t\t\t\tthis.resolve();\n\t\t\t}),\n\t\t);\n\t}\n\n\trestore(): void {\n\t\tlet snapshot: ObserverSubagent[] = [];\n\t\tfor (const entry of this.session.sessionManager.getEntries()) {\n\t\t\tif (entry.type !== \"custom\" || entry.customType !== \"pi-server-subagent\") continue;\n\t\t\tsnapshot = (entry.data as { subagents: ObserverSubagent[] }).subagents;\n\t\t}\n\t\tif (\n\t\t\tsnapshot.length === this.tasks.size &&\n\t\t\tsnapshot.every((task) => {\n\t\t\t\tconst current = this.tasks.get(task.sessionId);\n\t\t\t\treturn (\n\t\t\t\t\tcurrent?.agentId === task.agentId &&\n\t\t\t\t\tcurrent.title === task.title &&\n\t\t\t\t\tcurrent.taskStatus === task.taskStatus\n\t\t\t\t);\n\t\t\t})\n\t\t)\n\t\t\treturn;\n\t\tthis.tasks.clear();\n\t\tfor (const task of snapshot) this.tasks.set(task.sessionId, task);\n\t\tthis.version++;\n\t}\n\n\tresolve(): void {\n\t\tif (this.sessionId !== this.session.sessionId) {\n\t\t\tthis.syncSession();\n\t\t\treturn;\n\t\t}\n\t\tconst registry = (globalThis as Record<symbol, SubagentRegistry | undefined>)[registryKey];\n\t\tlet changed = false;\n\t\tfor (const agentId of this.pending) {\n\t\t\tconst record = registry?.getRecord(agentId);\n\t\t\tif (!record) continue;\n\t\t\tconst active = record.status === \"running\" || record.status === \"queued\";\n\t\t\tif (!record.session) {\n\t\t\t\tif (!active) this.pending.delete(agentId);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst task: ObserverSubagent = {\n\t\t\t\tagentId,\n\t\t\t\tsessionId: record.session.sessionId,\n\t\t\t\ttitle: record.description || record.type,\n\t\t\t\ttaskStatus: record.status,\n\t\t\t};\n\t\t\tthis.pending.delete(agentId);\n\t\t\tconst previous = this.tasks.get(task.sessionId);\n\t\t\tif (\n\t\t\t\tprevious?.agentId === task.agentId &&\n\t\t\t\tprevious.title === task.title &&\n\t\t\t\tprevious.taskStatus === task.taskStatus\n\t\t\t)\n\t\t\t\tcontinue;\n\t\t\tthis.tasks.set(task.sessionId, task);\n\t\t\tchanged = true;\n\t\t}\n\t\tif (this.pending.size === 0) pendingBridges.delete(this);\n\t\tif (!changed) return;\n\t\tthis.version++;\n\t\tthis.session.sessionManager.appendCustomEntry(\"pi-server-subagent\", { subagents: this.snapshot() });\n\t\tthis.onChange();\n\t}\n\n\tsnapshot(): ObserverSubagent[] {\n\t\treturn [...this.tasks.values()];\n\t}\n\n\tdispose(): void {\n\t\tfor (const unsubscribe of this.subscriptions) unsubscribe();\n\t\tthis.subscriptions = [];\n\t\tthis.pending.clear();\n\t\tpendingBridges.delete(this);\n\t}\n}\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type AnyModel, type Api, type AssistantMessageEventStream, type ClassifierApi, type ImageApi, type Model, type OAuthCredentials, type OAuthLoginCallbacks, type Provider, type ProviderClassifier, type ProviderHeaders, type ProviderImages, type RefreshModelsContext, type SimpleStreamOptions, type TranscriptContext } from "@earendil-works/pi-ai";
|
|
1
|
+
import { type AnyModel, type Api, type AssistantMessageEventStream, type ClassifierApi, type ClassifierModel, type ImageApi, type Model, type OAuthCredentials, type OAuthLoginCallbacks, type Provider, type ProviderClassifier, type ProviderHeaders, type ProviderImages, type RefreshModelsContext, type SimpleStreamOptions, type TranscriptContext } from "@earendil-works/pi-ai";
|
|
2
2
|
import type { ModelConfig, ModelsJsonProvider } from "./model-config.ts";
|
|
3
3
|
import { clearConfigValueCache } from "./resolve-config-value.ts";
|
|
4
4
|
export interface ExtensionOAuthConfig {
|
|
@@ -43,6 +43,7 @@ export interface ProviderClassifierModelConfig extends ProviderModelConfigBase {
|
|
|
43
43
|
type: "classifier";
|
|
44
44
|
api?: ClassifierApi;
|
|
45
45
|
contextWindow: number;
|
|
46
|
+
compat?: ClassifierModel<ClassifierApi>["compat"];
|
|
46
47
|
}
|
|
47
48
|
export type ProviderModelConfig = ProviderChatModelConfig | ProviderImageModelConfig | ProviderClassifierModelConfig;
|
|
48
49
|
/** Input type for the extension registerProvider API. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider-composer.d.ts","sourceRoot":"","sources":["../../src/core/provider-composer.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,KAAK,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AAQ,GAAG,SAAS,EAC1B,YAAY,EAAE,kBAAkB,GAAG,SAAS,EAC5C,SAAS,EAAE,mBAAmB,GAC5B,IAAI,CAKN;AAED,uFAAuF;AACvF,wBAAgB,oBAAoB,CACnC,UAAU,EAAE,MAAM,EAClB,IAAI,EAAE,QAAQ,GAAG,SAAS,EAC1B,WAAW,EAAE,WAAW,EACxB,SAAS,EAAE,mBAAmB,GAAG,SAAS,GACxC,QAAQ,CAwIV;AAED,wBAAgB,6BAA6B,CAC5C,KAAK,EAAE,QAAQ,EACf,MAAM,EAAE,kBAAkB,GAAG,SAAS,EACtC,SAAS,EAAE,mBAAmB,GAAG,SAAS,EAC1C,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC1B,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,CAMpC;AAED,MAAM,WAAW,0BAA0B;IAC1C,OAAO,CAAC,EAAE,eAAe,CAAC;IAC1B,UAAU,EAAE,OAAO,CAAC;CACpB;AAED,wBAAgB,iCAAiC,CAChD,KAAK,EAAE,QAAQ,EACf,MAAM,EAAE,kBAAkB,GAAG,SAAS,EACtC,SAAS,EAAE,mBAAmB,GAAG,SAAS,GACxC,0BAA0B,CAS5B;AAED,wBAAgB,2BAA2B,CAC1C,MAAM,EAAE,kBAAkB,GAAG,SAAS,EACtC,SAAS,EAAE,mBAAmB,GAAG,SAAS,GACxC,UAAU,GAAG,SAAS,CAWxB"}
|
|
@@ -166,9 +166,13 @@ function applyModelsJson(providerId, baseModels, config) {
|
|
|
166
166
|
}
|
|
167
167
|
const models = baseModels.map((model) => {
|
|
168
168
|
const baseUrl = config.oauth === "radius" ? model.baseUrl : (config.baseUrl ?? model.baseUrl);
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
169
|
+
if (isModelType(model, "chat"))
|
|
170
|
+
return { ...model, baseUrl, compat: mergeCompat(model.compat, config.compat) };
|
|
171
|
+
// Classifier APIs read their own compat fields, such as how a System One service takes images.
|
|
172
|
+
if (isModelType(model, "classifier") && config.compat) {
|
|
173
|
+
return { ...model, baseUrl, compat: { ...model.compat, ...config.compat } };
|
|
174
|
+
}
|
|
175
|
+
return { ...model, baseUrl };
|
|
172
176
|
});
|
|
173
177
|
for (const definition of config.models ?? []) {
|
|
174
178
|
const existingIndex = models.findIndex((model) => isModelType(model, "chat") && model.id === definition.id);
|