feat: add Pi subagent scheduler and child runtime

This commit is contained in:
2026-08-23 12:40:22 +08:00
parent b806c78139
commit f1c7cd8ad4
21 changed files with 1986 additions and 53 deletions

View File

@@ -75,6 +75,7 @@ import {
projectPiSessionSnapshot,
} from './session-projector';
import { PiManagedExtensionHost } from './extension-host';
import type { PiSubagentScheduler } from './subagent';
import {
PiInteractionStore,
type PiInteractionResponse,
@@ -98,6 +99,7 @@ export interface PiConversationRuntimeOptions {
isAuthenticationError?(error: unknown): boolean;
refreshCredential?(accountId: string): Promise<void>;
extensionHost?: PiManagedExtensionHost;
subagentScheduler?: PiSubagentScheduler;
getDraftRevision?(conversationId: string): number;
knownExtensionWidgetKeys?: readonly string[];
onExtensionUiProjection?(projection: PiExtensionUiProjection): void;
@@ -480,6 +482,15 @@ export class PiConversationRuntime implements CodingConversationRuntime {
this.isAuthenticationError = options.isAuthenticationError;
this.refreshCredential = options.refreshCredential;
this.extensionHost = options.extensionHost;
if (options.subagentScheduler && !this.extensionHost) {
throw new Error('Subagent scheduler requires the managed extension host');
}
if (options.subagentScheduler) {
this.extensionHost?.configureSubagents({
scheduler: options.subagentScheduler,
trackGenerationResource: (input) => this.pool.trackGenerationResource(input),
});
}
this.interactions = new PiInteractionStore(this.pool, (interaction) => {
this.emit(interaction.conversationId, { op: 'interaction.upsert', interaction }, interaction.runId);
});