feat(coding): add core host api composition
This commit is contained in:
@@ -12,7 +12,11 @@ import {
|
||||
import { PiProviderRefreshCoordinator } from './provider-refresh';
|
||||
import type {
|
||||
CodingConversationRuntime,
|
||||
CodingRuntimeCommand,
|
||||
CodingRuntimeDiagnostics,
|
||||
CodingRuntimePublicError,
|
||||
ConversationInteraction,
|
||||
ConversationInteractionResponse,
|
||||
ConversationModelState,
|
||||
ConversationPatch,
|
||||
ConversationPatchEnvelope,
|
||||
@@ -78,7 +82,6 @@ import { PiManagedExtensionHost } from './extension-host';
|
||||
import type { PiSubagentScheduler } from './subagent';
|
||||
import {
|
||||
PiInteractionStore,
|
||||
type PiInteractionResponse,
|
||||
} from './interaction';
|
||||
import {
|
||||
PiExtensionUiProjector,
|
||||
@@ -836,6 +839,52 @@ export class PiConversationRuntime implements CodingConversationRuntime {
|
||||
this.hydrationFlights.delete(conversationId);
|
||||
}
|
||||
|
||||
async listCommands(conversationId: string): Promise<CodingRuntimeCommand[]> {
|
||||
const state = this.pool.getState(conversationId);
|
||||
if (!state || state.state === 'spawning' || state.state === 'crashed') return [];
|
||||
const response = await this.pool.request<unknown>(
|
||||
conversationId,
|
||||
{ type: 'get_commands' },
|
||||
{ retry: 'read-only-once' },
|
||||
);
|
||||
const record = response.data && typeof response.data === 'object' && !Array.isArray(response.data)
|
||||
? response.data as Record<string, unknown>
|
||||
: null;
|
||||
const candidates = Array.isArray(response.data)
|
||||
? response.data
|
||||
: Array.isArray(record?.commands)
|
||||
? record.commands
|
||||
: [];
|
||||
return candidates.flatMap((candidate) => {
|
||||
if (!candidate || typeof candidate !== 'object' || Array.isArray(candidate)) return [];
|
||||
const command = candidate as Record<string, unknown>;
|
||||
const name = typeof command.name === 'string' ? command.name.trim() : '';
|
||||
if (!name) return [];
|
||||
return [{
|
||||
name,
|
||||
...(typeof command.description === 'string'
|
||||
? { description: command.description }
|
||||
: {}),
|
||||
}];
|
||||
});
|
||||
}
|
||||
|
||||
async listInteractions(conversationId?: string): Promise<ConversationInteraction[]> {
|
||||
return this.interactions.list(conversationId);
|
||||
}
|
||||
|
||||
getDiagnostics(): CodingRuntimeDiagnostics {
|
||||
return this.pool.getDiagnostics();
|
||||
}
|
||||
|
||||
markProviderStale(): void {
|
||||
this.pool.markProviderStale();
|
||||
}
|
||||
|
||||
markResourcesStale(): void {
|
||||
this.pool.markResourcesStale();
|
||||
}
|
||||
|
||||
subscribe(listener: (patch: ConversationPatchEnvelope) => void): () => void {
|
||||
this.listeners.add(listener);
|
||||
return () => this.listeners.delete(listener);
|
||||
@@ -843,7 +892,7 @@ export class PiConversationRuntime implements CodingConversationRuntime {
|
||||
|
||||
async respondInteraction(
|
||||
conversationId: string,
|
||||
response: PiInteractionResponse,
|
||||
response: ConversationInteractionResponse,
|
||||
): Promise<void> {
|
||||
await this.interactions.respond(conversationId, response);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user