feat(llm): add LLM call support to worker IPC chain

- ProviderManager: align API with contracts ProviderAdapter
- WorkerProtocol: add llm.request/llm.response message types
- WorkerRuntime: add call_llm() for worker→parent→LLM flow
- WorkerManager: support tool_registry and provider_manager injection

P1-1 complete, P1-2 protocol layer complete.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
AirCoding
2026-06-04 18:42:06 +08:00
parent df36c43829
commit 8fd680cf84
4 changed files with 198 additions and 23 deletions

View File

@@ -13,6 +13,8 @@ import type { ChildProcess } from 'child_process'
import { WorkerProcess, type WorkerExitCode } from './WorkerProcess.js'
import { WorkerProtocol, type WorkerMessage, type WorkerMessageType } from './WorkerProtocol.js'
import type { WorkerResult, WorkerStatus, AgentType } from '@aircoding/contracts'
import type { ToolRegistry } from '../tools/ToolRegistry.js'
import type { ProviderManager } from '@aircoding/llm'
export interface WorkerConfig {
entrypoint: string // Path to worker main.ts
@@ -36,9 +38,36 @@ export interface WorkerHandle {
export class WorkerManager {
private protocol: WorkerProtocol
private workers: Map<string, WorkerHandle> = new Map()
private tool_registry?: ToolRegistry
private provider_manager?: ProviderManager
private execution_context?: { session_id: string; project_id: string; project_root: string }
constructor() {
constructor(tool_registry?: ToolRegistry, provider_manager?: ProviderManager) {
this.protocol = new WorkerProtocol()
this.tool_registry = tool_registry
this.provider_manager = provider_manager
}
/**
* Set execution context (session_id, project_id, project_root).
* Required for tool/LLM calls from workers.
*/
set_context(ctx: { session_id: string; project_id: string; project_root: string }): void {
this.execution_context = ctx
}
/**
* Set tool registry (can be injected after construction).
*/
set_tool_registry(registry: ToolRegistry): void {
this.tool_registry = registry
}
/**
* Set provider manager (can be injected after construction).
*/
set_provider_manager(pm: ProviderManager): void {
this.provider_manager = pm
}
/**