@howaboua/pi-subagent-review 0.2.3 → 0.2.4
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/package.json +5 -5
- package/src/conversation-summary.ts +172 -14
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@howaboua/pi-subagent-review",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.4",
|
|
4
4
|
"description": "Pi extension that adds /review via an isolated review subagent.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "index.ts",
|
|
@@ -38,8 +38,8 @@
|
|
|
38
38
|
]
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {
|
|
41
|
-
"@earendil-works/pi-ai": "
|
|
42
|
-
"@earendil-works/pi-coding-agent": "
|
|
41
|
+
"@earendil-works/pi-ai": "*",
|
|
42
|
+
"@earendil-works/pi-coding-agent": "*"
|
|
43
43
|
},
|
|
44
44
|
"scripts": {
|
|
45
45
|
"check": "bun run lint && bun run typecheck",
|
|
@@ -49,8 +49,8 @@
|
|
|
49
49
|
"format": "biome check --write ."
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
|
-
"@earendil-works/pi-ai": "
|
|
53
|
-
"@earendil-works/pi-coding-agent": "
|
|
52
|
+
"@earendil-works/pi-ai": "0.80.1",
|
|
53
|
+
"@earendil-works/pi-coding-agent": "0.80.1",
|
|
54
54
|
"@types/node": "^24.10.0",
|
|
55
55
|
"typescript": "^5.9.3",
|
|
56
56
|
"@biomejs/biome": "^2.4.16"
|
|
@@ -1,10 +1,177 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type {
|
|
2
|
+
Api,
|
|
3
|
+
AssistantMessage,
|
|
4
|
+
AssistantMessageEventStream,
|
|
5
|
+
Context,
|
|
6
|
+
Model,
|
|
7
|
+
SimpleStreamOptions,
|
|
8
|
+
} from "@earendil-works/pi-ai";
|
|
9
|
+
import { streamSimple as streamAnthropicMessages } from "@earendil-works/pi-ai/api/anthropic-messages";
|
|
10
|
+
import { streamSimple as streamAzureOpenAIResponses } from "@earendil-works/pi-ai/api/azure-openai-responses";
|
|
11
|
+
import { streamSimple as streamBedrockConverseStream } from "@earendil-works/pi-ai/api/bedrock-converse-stream";
|
|
12
|
+
import { streamSimple as streamGoogleGenerativeAI } from "@earendil-works/pi-ai/api/google-generative-ai";
|
|
13
|
+
import { streamSimple as streamGoogleVertex } from "@earendil-works/pi-ai/api/google-vertex";
|
|
14
|
+
import { streamSimple as streamMistralConversations } from "@earendil-works/pi-ai/api/mistral-conversations";
|
|
15
|
+
import { streamSimple as streamOpenAICodexResponses } from "@earendil-works/pi-ai/api/openai-codex-responses";
|
|
16
|
+
import { streamSimple as streamOpenAICompletions } from "@earendil-works/pi-ai/api/openai-completions";
|
|
17
|
+
import { streamSimple as streamOpenAIResponses } from "@earendil-works/pi-ai/api/openai-responses";
|
|
2
18
|
import type {
|
|
3
19
|
ExtensionCommandContext,
|
|
4
20
|
SessionEntry,
|
|
5
21
|
} from "@earendil-works/pi-coding-agent";
|
|
6
22
|
import type { ResolvedReviewConfig } from "./types.js";
|
|
7
23
|
|
|
24
|
+
type RegisteredProviderConfig = {
|
|
25
|
+
api?: Api;
|
|
26
|
+
authHeader?: boolean;
|
|
27
|
+
streamSimple?: (
|
|
28
|
+
model: Model<Api>,
|
|
29
|
+
context: Context,
|
|
30
|
+
options?: SimpleStreamOptions,
|
|
31
|
+
) => AssistantMessageEventStream;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
type ModelRegistryInternals = {
|
|
35
|
+
providerRequestConfigs?: Map<
|
|
36
|
+
string,
|
|
37
|
+
Pick<RegisteredProviderConfig, "authHeader">
|
|
38
|
+
>;
|
|
39
|
+
registeredProviders?: Map<string, RegisteredProviderConfig>;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
function getModelRegistryInternals(
|
|
43
|
+
modelRegistry: ExtensionCommandContext["modelRegistry"],
|
|
44
|
+
): ModelRegistryInternals {
|
|
45
|
+
return modelRegistry as unknown as ModelRegistryInternals;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function getRegisteredStreamSimple(
|
|
49
|
+
modelRegistry: ExtensionCommandContext["modelRegistry"],
|
|
50
|
+
model: Model<Api>,
|
|
51
|
+
): RegisteredProviderConfig["streamSimple"] {
|
|
52
|
+
const providerConfig = getModelRegistryInternals(
|
|
53
|
+
modelRegistry,
|
|
54
|
+
).registeredProviders?.get(model.provider);
|
|
55
|
+
if (providerConfig?.api !== model.api) return undefined;
|
|
56
|
+
return providerConfig.streamSimple;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function isMissingApiKeyError(error: string, provider: string): boolean {
|
|
60
|
+
return error === `No API key found for "${provider}"`;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
async function getSummaryOptions(
|
|
64
|
+
ctx: ExtensionCommandContext,
|
|
65
|
+
model: Model<Api>,
|
|
66
|
+
config: ResolvedReviewConfig,
|
|
67
|
+
): Promise<SimpleStreamOptions> {
|
|
68
|
+
const auth = await ctx.modelRegistry.getApiKeyAndHeaders(model);
|
|
69
|
+
const fallbackApiKey =
|
|
70
|
+
auth.ok && auth.apiKey
|
|
71
|
+
? undefined
|
|
72
|
+
: await ctx.modelRegistry.getApiKeyForProvider(model.provider);
|
|
73
|
+
if (!auth.ok && !isMissingApiKeyError(auth.error, model.provider)) {
|
|
74
|
+
throw new Error(`Summary model unavailable: ${auth.error}`);
|
|
75
|
+
}
|
|
76
|
+
if (!auth.ok && !fallbackApiKey) {
|
|
77
|
+
throw new Error(`Summary model unavailable: ${auth.error}`);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
let headers = auth.ok ? auth.headers : undefined;
|
|
81
|
+
if (
|
|
82
|
+
fallbackApiKey &&
|
|
83
|
+
getModelRegistryInternals(ctx.modelRegistry).providerRequestConfigs?.get(
|
|
84
|
+
model.provider,
|
|
85
|
+
)?.authHeader
|
|
86
|
+
) {
|
|
87
|
+
headers = { ...headers, Authorization: `Bearer ${fallbackApiKey}` };
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const options: SimpleStreamOptions = {};
|
|
91
|
+
const apiKey = auth.ok && auth.apiKey ? auth.apiKey : fallbackApiKey;
|
|
92
|
+
const env = auth.ok
|
|
93
|
+
? auth.env
|
|
94
|
+
: ctx.modelRegistry.authStorage.getProviderEnv(model.provider);
|
|
95
|
+
if (apiKey) options.apiKey = apiKey;
|
|
96
|
+
if (headers) options.headers = headers;
|
|
97
|
+
if (env) options.env = env;
|
|
98
|
+
if (model.reasoning && config.summary.thinking !== "off") {
|
|
99
|
+
options.reasoning = config.summary.thinking;
|
|
100
|
+
}
|
|
101
|
+
if (ctx.signal) options.signal = ctx.signal;
|
|
102
|
+
return options;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
async function completeSummaryWithModelApi(
|
|
106
|
+
model: Model<Api>,
|
|
107
|
+
context: Context,
|
|
108
|
+
options: SimpleStreamOptions,
|
|
109
|
+
registeredStreamSimple: RegisteredProviderConfig["streamSimple"],
|
|
110
|
+
): Promise<AssistantMessage> {
|
|
111
|
+
if (registeredStreamSimple) {
|
|
112
|
+
return registeredStreamSimple(model, context, options).result();
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
switch (model.api) {
|
|
116
|
+
case "anthropic-messages":
|
|
117
|
+
return streamAnthropicMessages(
|
|
118
|
+
model as Model<"anthropic-messages">,
|
|
119
|
+
context,
|
|
120
|
+
options,
|
|
121
|
+
).result();
|
|
122
|
+
case "azure-openai-responses":
|
|
123
|
+
return streamAzureOpenAIResponses(
|
|
124
|
+
model as Model<"azure-openai-responses">,
|
|
125
|
+
context,
|
|
126
|
+
options,
|
|
127
|
+
).result();
|
|
128
|
+
case "bedrock-converse-stream":
|
|
129
|
+
return streamBedrockConverseStream(
|
|
130
|
+
model as Model<"bedrock-converse-stream">,
|
|
131
|
+
context,
|
|
132
|
+
options,
|
|
133
|
+
).result();
|
|
134
|
+
case "google-generative-ai":
|
|
135
|
+
return streamGoogleGenerativeAI(
|
|
136
|
+
model as Model<"google-generative-ai">,
|
|
137
|
+
context,
|
|
138
|
+
options,
|
|
139
|
+
).result();
|
|
140
|
+
case "google-vertex":
|
|
141
|
+
return streamGoogleVertex(
|
|
142
|
+
model as Model<"google-vertex">,
|
|
143
|
+
context,
|
|
144
|
+
options,
|
|
145
|
+
).result();
|
|
146
|
+
case "mistral-conversations":
|
|
147
|
+
return streamMistralConversations(
|
|
148
|
+
model as Model<"mistral-conversations">,
|
|
149
|
+
context,
|
|
150
|
+
options,
|
|
151
|
+
).result();
|
|
152
|
+
case "openai-codex-responses":
|
|
153
|
+
return streamOpenAICodexResponses(
|
|
154
|
+
model as Model<"openai-codex-responses">,
|
|
155
|
+
context,
|
|
156
|
+
options,
|
|
157
|
+
).result();
|
|
158
|
+
case "openai-completions":
|
|
159
|
+
return streamOpenAICompletions(
|
|
160
|
+
model as Model<"openai-completions">,
|
|
161
|
+
context,
|
|
162
|
+
options,
|
|
163
|
+
).result();
|
|
164
|
+
case "openai-responses":
|
|
165
|
+
return streamOpenAIResponses(
|
|
166
|
+
model as Model<"openai-responses">,
|
|
167
|
+
context,
|
|
168
|
+
options,
|
|
169
|
+
).result();
|
|
170
|
+
default:
|
|
171
|
+
throw new Error(`Summary model API is unsupported: ${model.api}`);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
8
175
|
function textFromContent(content: unknown): string {
|
|
9
176
|
if (typeof content === "string") return content;
|
|
10
177
|
if (!Array.isArray(content)) return "";
|
|
@@ -113,19 +280,9 @@ export async function buildReviewConversationSummary(
|
|
|
113
280
|
const model = ctx.modelRegistry.find(parsed.provider, parsed.modelId);
|
|
114
281
|
if (!model)
|
|
115
282
|
throw new Error(`Summary model not found: ${config.summary.model}`);
|
|
116
|
-
const
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
const options = {
|
|
120
|
-
...(auth.apiKey ? { apiKey: auth.apiKey } : {}),
|
|
121
|
-
...(auth.headers ? { headers: auth.headers } : {}),
|
|
122
|
-
...(model.reasoning && config.summary.thinking !== "off"
|
|
123
|
-
? { reasoning: config.summary.thinking }
|
|
124
|
-
: {}),
|
|
125
|
-
...(ctx.signal ? { signal: ctx.signal } : {}),
|
|
126
|
-
};
|
|
127
|
-
|
|
128
|
-
const response = await completeSimple(
|
|
283
|
+
const options = await getSummaryOptions(ctx, model, config);
|
|
284
|
+
|
|
285
|
+
const response = await completeSummaryWithModelApi(
|
|
129
286
|
model,
|
|
130
287
|
{
|
|
131
288
|
messages: [
|
|
@@ -137,6 +294,7 @@ export async function buildReviewConversationSummary(
|
|
|
137
294
|
],
|
|
138
295
|
},
|
|
139
296
|
options,
|
|
297
|
+
getRegisteredStreamSimple(ctx.modelRegistry, model),
|
|
140
298
|
);
|
|
141
299
|
|
|
142
300
|
const summary = response.content
|