feat(coding): add core host api composition

This commit is contained in:
2026-08-23 20:00:35 +08:00
parent 98bac20639
commit 22b4a9f9c4
23 changed files with 2258 additions and 59 deletions

View File

@@ -1,4 +1,7 @@
import type { ConversationInteraction } from '../contracts';
import type {
ConversationInteraction,
ConversationInteractionResponse,
} from '../contracts';
import type { PiRpcCommand, PiRpcEvent } from './rpc-client';
import type { PiGenerationResourceInput, PiWorkerPoolState } from './worker-pool';
@@ -17,12 +20,6 @@ interface StoredInteraction {
untrack(): void;
}
export type PiInteractionResponse =
| { interactionId: string; cancelled: true }
| { interactionId: string; optionId: string }
| { interactionId: string; confirmed: boolean }
| { interactionId: string; value: string };
function dialogEvent(event: PiRpcEvent): event is PiRpcEvent & {
id: string;
method: 'select' | 'confirm' | 'input' | 'editor';
@@ -101,7 +98,7 @@ export class PiInteractionStore {
return structuredClone(interaction);
}
async respond(conversationId: string, response: PiInteractionResponse): Promise<ConversationInteraction> {
async respond(conversationId: string, response: ConversationInteractionResponse): Promise<ConversationInteraction> {
const stored = this.pending.get(this.key(conversationId, response.interactionId));
if (!stored) throw new Error('Pi interaction is not pending');
if (stored.phase === 'responding') throw new Error('Pi interaction response is already in progress');