@bacnh85/pi-subagent 0.9.1 → 0.9.2
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 +6 -0
- package/extensions/index.ts +3 -18
- package/extensions/runner.ts +12 -6
- package/extensions/service.ts +4 -7
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/extensions/index.ts
CHANGED
|
@@ -14,17 +14,14 @@
|
|
|
14
14
|
*/
|
|
15
15
|
|
|
16
16
|
import * as path from "node:path";
|
|
17
|
-
import type { Model } from "@earendil-works/pi-ai";
|
|
18
17
|
import { StringEnum } from "@earendil-works/pi-ai";
|
|
19
18
|
import {
|
|
20
|
-
AuthStorage,
|
|
21
19
|
CONFIG_DIR_NAME,
|
|
22
20
|
DynamicBorder,
|
|
23
21
|
type ExtensionAPI,
|
|
24
22
|
type ExtensionContext,
|
|
25
23
|
getAgentDir,
|
|
26
24
|
getMarkdownTheme,
|
|
27
|
-
ModelRegistry,
|
|
28
25
|
type ThemeColor,
|
|
29
26
|
} from "@earendil-works/pi-coding-agent";
|
|
30
27
|
import { Container, Markdown, SelectList, Spacer, Text } from "@earendil-works/pi-tui";
|
|
@@ -463,20 +460,9 @@ export default function (pi: ExtensionAPI) {
|
|
|
463
460
|
}
|
|
464
461
|
}
|
|
465
462
|
|
|
466
|
-
// Shared auth/model setup for SDK sessions
|
|
467
|
-
// ponytail: reuse parent modelRegistry instead of a fresh copy — avoids
|
|
468
|
-
// internal API casts (storeModelHeaders) and preserves env/headers/OAuth.
|
|
469
|
-
const authStorage = AuthStorage.inMemory();
|
|
470
463
|
const modelRegistry = ctx.modelRegistry;
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
async function injectApiKey(model: Model<any>): Promise<void> {
|
|
474
|
-
const auth = await ctx.modelRegistry.getApiKeyAndHeaders(model);
|
|
475
|
-
if (auth.ok) {
|
|
476
|
-
if (auth.apiKey) authStorage.setRuntimeApiKey(model.provider, auth.apiKey);
|
|
477
|
-
// ponytail: headers/env stay on the parent registry — no copy needed.
|
|
478
|
-
}
|
|
479
|
-
}
|
|
464
|
+
const modelRuntime = (modelRegistry as any).runtime;
|
|
465
|
+
const authStorage = (modelRegistry as any).authStorage;
|
|
480
466
|
|
|
481
467
|
// Helper: resolve a safe child working directory.
|
|
482
468
|
function resolveChildCwd(childCwd: string | undefined): string {
|
|
@@ -566,8 +552,6 @@ export default function (pi: ExtensionAPI) {
|
|
|
566
552
|
let effectiveTimeoutMs: number | undefined;
|
|
567
553
|
let safeCwd: string;
|
|
568
554
|
try {
|
|
569
|
-
// Inject parent's API key so --api-key and other runtime overrides work
|
|
570
|
-
await injectApiKey(resolved.model);
|
|
571
555
|
tools = resolveChildTools(agent.tools, agent.sandbox, isReadOnly);
|
|
572
556
|
effectiveTimeoutMs = resolveChildTimeout(timeoutMs, params.timeout);
|
|
573
557
|
safeCwd = resolveChildCwd(cwd);
|
|
@@ -599,6 +583,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
599
583
|
task,
|
|
600
584
|
tools,
|
|
601
585
|
model: resolved.model,
|
|
586
|
+
modelRuntime,
|
|
602
587
|
authStorage,
|
|
603
588
|
modelRegistry,
|
|
604
589
|
signal: parentSignal,
|
package/extensions/runner.ts
CHANGED
|
@@ -17,10 +17,8 @@
|
|
|
17
17
|
import type { Message, Model } from "@earendil-works/pi-ai";
|
|
18
18
|
import type { AgentMessage } from "@earendil-works/pi-agent-core";
|
|
19
19
|
import {
|
|
20
|
-
AuthStorage,
|
|
21
20
|
createAgentSession,
|
|
22
21
|
createExtensionRuntime,
|
|
23
|
-
ModelRegistry,
|
|
24
22
|
type ResourceLoader,
|
|
25
23
|
SessionManager,
|
|
26
24
|
SettingsManager,
|
|
@@ -87,8 +85,11 @@ export async function runSubAgent(options: {
|
|
|
87
85
|
task: string;
|
|
88
86
|
tools: string[];
|
|
89
87
|
model: Model<any>;
|
|
90
|
-
|
|
91
|
-
|
|
88
|
+
/** Pi 0.80.10's canonical credential/model runtime. */
|
|
89
|
+
modelRuntime?: unknown;
|
|
90
|
+
/** Legacy Pi SDK session options retained for 0.80.6 tests and hosts. */
|
|
91
|
+
authStorage?: unknown;
|
|
92
|
+
modelRegistry?: unknown;
|
|
92
93
|
signal?: AbortSignal;
|
|
93
94
|
agentName?: string;
|
|
94
95
|
thinkingLevel?: "off" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max";
|
|
@@ -98,7 +99,7 @@ export async function runSubAgent(options: {
|
|
|
98
99
|
hardTimeoutMs?: number;
|
|
99
100
|
}): Promise<SubAgentResult> {
|
|
100
101
|
const {
|
|
101
|
-
cwd, systemPrompt, task, tools, model, authStorage, modelRegistry, signal,
|
|
102
|
+
cwd, systemPrompt, task, tools, model, modelRuntime, authStorage, modelRegistry, signal,
|
|
102
103
|
agentName = "subagent", thinkingLevel = "off", onMessage, onProgress,
|
|
103
104
|
timeoutMs = DEFAULT_INACTIVITY_TIMEOUT_MS, hardTimeoutMs = HARD_TIMEOUT_MS,
|
|
104
105
|
} = options;
|
|
@@ -142,7 +143,12 @@ export async function runSubAgent(options: {
|
|
|
142
143
|
result.status = classifyStopReason(result.stopReason, !timedOut, timedOut);
|
|
143
144
|
return result;
|
|
144
145
|
}
|
|
145
|
-
const { session } = await createAgentSession({
|
|
146
|
+
const { session } = await createAgentSession({
|
|
147
|
+
cwd, model, thinkingLevel, resourceLoader, tools, sessionManager: SessionManager.inMemory(cwd), settingsManager,
|
|
148
|
+
...(modelRuntime ? { modelRuntime } : {}),
|
|
149
|
+
// Pi 0.80.10 owns credentials in ModelRuntime; older SDKs still accept these.
|
|
150
|
+
...(authStorage ? { authStorage, modelRegistry } : {}),
|
|
151
|
+
} as any);
|
|
146
152
|
let unsubscribe: (() => void) | undefined;
|
|
147
153
|
let removeAbort: (() => void) | undefined;
|
|
148
154
|
try {
|
package/extensions/service.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { type ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
2
2
|
import { type AgentConfig, getModelCandidates } from "./agents.ts";
|
|
3
3
|
import { runSubAgent, type SubAgentProgress, type SubAgentResult } from "./runner.ts";
|
|
4
4
|
import { resolveModel } from "./model.ts";
|
|
@@ -44,13 +44,9 @@ export async function runNamedAgent(options: {
|
|
|
44
44
|
const { model, attempted } = await resolveModel(getModelCandidates(options.agent), options.ctx.model, options.ctx.modelRegistry);
|
|
45
45
|
if (!model) throw new Error(`No model resolved for agent "${options.agent.name}" (tried: ${attempted.join(", ") || "none"})`);
|
|
46
46
|
|
|
47
|
-
const authStorage = AuthStorage.inMemory();
|
|
48
47
|
const modelRegistry = options.ctx.modelRegistry;
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
if (auth.apiKey) authStorage.setRuntimeApiKey(model.provider, auth.apiKey);
|
|
52
|
-
// ponytail: env and headers stay on the parent modelRegistry — reuse it directly.
|
|
53
|
-
}
|
|
48
|
+
const modelRuntime = (modelRegistry as any).runtime;
|
|
49
|
+
const authStorage = (modelRegistry as any).authStorage;
|
|
54
50
|
|
|
55
51
|
// Security: validate and normalise timeout.
|
|
56
52
|
const effectiveTimeoutMs = normalizeTimeout({ requested: options.timeout }).timeoutMs;
|
|
@@ -83,6 +79,7 @@ export async function runNamedAgent(options: {
|
|
|
83
79
|
task: options.task,
|
|
84
80
|
tools: toolValidation.tools,
|
|
85
81
|
model,
|
|
82
|
+
modelRuntime,
|
|
86
83
|
authStorage,
|
|
87
84
|
modelRegistry,
|
|
88
85
|
signal: options.signal,
|
package/package.json
CHANGED