@arhen/pi-core-subagent 1.1.9 → 1.1.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/package.json +1 -1
- package/src/index.ts +35 -13
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arhen/pi-core-subagent",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.10",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "pi extension: fast in-process subagents with single/parallel/chain, background runs, intercom and agent-to-agent mailbox. Leader defines agents inline.",
|
|
6
6
|
"license": "MIT",
|
package/src/index.ts
CHANGED
|
@@ -12,12 +12,13 @@
|
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
14
|
import type { AgentSessionEvent, ExtensionAPI, ExtensionContext, Theme, ToolDefinition } from "@earendil-works/pi-coding-agent";
|
|
15
|
-
import { createAgentSession, DefaultResourceLoader, getAgentDir, SessionManager } from "@earendil-works/pi-coding-agent";
|
|
15
|
+
import { createAgentSession, DefaultResourceLoader, getAgentDir, ModelRuntime, SessionManager } from "@earendil-works/pi-coding-agent";
|
|
16
16
|
import type { ThinkingLevel } from "@earendil-works/pi-agent-core";
|
|
17
17
|
import { StringEnum, type Api, type AssistantMessage, type Model } from "@earendil-works/pi-ai";
|
|
18
18
|
import { Text, truncateToWidth } from "@earendil-works/pi-tui";
|
|
19
19
|
import type { Component, TUI } from "@earendil-works/pi-tui";
|
|
20
20
|
import { Type } from "typebox";
|
|
21
|
+
import { join } from "node:path";
|
|
21
22
|
import { CHILD_TALK_TOOLS, createChildTools, createWatchdog, type ChildHandlers } from "./child.ts";
|
|
22
23
|
import { createMailbox, type Mailbox } from "./mailbox.ts";
|
|
23
24
|
|
|
@@ -341,20 +342,40 @@ function cloneRun(run: RunSnapshot): RunSnapshot {
|
|
|
341
342
|
* Order: explicit "provider/model-id" or bare id (searched across available
|
|
342
343
|
* models) → agent file model → parent's current model (ctx.model) → undefined
|
|
343
344
|
* (createAgentSession falls back to settings). */
|
|
344
|
-
function resolveChildModel(ctx: ExtensionContext, explicit: string | undefined) {
|
|
345
|
-
if (explicit?.trim())
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
345
|
+
export function resolveChildModel(ctx: ExtensionContext, explicit: string | undefined) {
|
|
346
|
+
if (!explicit?.trim()) return ctx.model; // inherit the parent's active model
|
|
347
|
+
const ref = explicit.trim();
|
|
348
|
+
const available = ctx.modelRegistry.getAvailable();
|
|
349
|
+
// Model ids can contain slashes (e.g. 9router/cc/claude-opus-5), so a bare id
|
|
350
|
+
// match and every provider/id split point must be tried, not just the first.
|
|
351
|
+
const byId = available.find((m) => m.id === ref);
|
|
352
|
+
if (byId) return byId;
|
|
353
|
+
for (let slash = ref.indexOf("/"); slash > 0; slash = ref.indexOf("/", slash + 1)) {
|
|
354
|
+
const model = ctx.modelRegistry.find(ref.slice(0, slash), ref.slice(slash + 1));
|
|
355
|
+
if (model) return model;
|
|
356
|
+
}
|
|
357
|
+
throw new Error(`Model not found: ${ref}`);
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
/** Extension-registered providers (e.g. 9router) live only in the parent's
|
|
361
|
+
* in-memory runtime. A child builds its runtime from disk and would lose them,
|
|
362
|
+
* so replay the parent's registrations before the child resolves auth. */
|
|
363
|
+
async function createChildModelRuntime(ctx: ExtensionContext) {
|
|
364
|
+
const ids = ctx.modelRegistry.getRegisteredProviderIds?.() ?? [];
|
|
365
|
+
if (ids.length === 0) return undefined; // no extension providers: disk runtime is enough
|
|
366
|
+
const agentDir = getAgentDir();
|
|
367
|
+
const runtime = await ModelRuntime.create({ authPath: join(agentDir, "auth.json"), modelsPath: join(agentDir, "models.json") });
|
|
368
|
+
for (const id of ids) {
|
|
369
|
+
const native = ctx.modelRegistry.getRegisteredNativeProvider?.(id);
|
|
370
|
+
if (native) {
|
|
371
|
+
runtime.registerNativeProvider(native);
|
|
372
|
+
continue;
|
|
352
373
|
}
|
|
353
|
-
const
|
|
354
|
-
if (
|
|
355
|
-
return byId;
|
|
374
|
+
const config = ctx.modelRegistry.getRegisteredProviderConfig?.(id);
|
|
375
|
+
if (config) runtime.registerProvider(id, config);
|
|
356
376
|
}
|
|
357
|
-
|
|
377
|
+
await runtime.refresh({ allowNetwork: false });
|
|
378
|
+
return runtime;
|
|
358
379
|
}
|
|
359
380
|
|
|
360
381
|
/** Validate a thinking level against the RESOLVED model's registry entry.
|
|
@@ -731,6 +752,7 @@ class SubagentManager {
|
|
|
731
752
|
const created = await createAgentSession({
|
|
732
753
|
cwd: task.cwd,
|
|
733
754
|
agentDir: getAgentDir(),
|
|
755
|
+
modelRuntime: await createChildModelRuntime(ctx),
|
|
734
756
|
resourceLoader: loader,
|
|
735
757
|
sessionManager: SessionManager.create(task.cwd, undefined, { parentSession: getParentSessionFile(ctx) }),
|
|
736
758
|
model,
|