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:
@@ -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
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -27,6 +27,7 @@ export type WorkerMessageType =
|
||||
| 'tool.result'
|
||||
| 'agent.cancel'
|
||||
| 'agent.ping'
|
||||
| 'llm.response'
|
||||
// Worker → Parent
|
||||
| 'worker.ready'
|
||||
| 'tool.call'
|
||||
@@ -35,6 +36,7 @@ export type WorkerMessageType =
|
||||
| 'worker.heartbeat'
|
||||
| 'worker.error'
|
||||
| 'event'
|
||||
| 'llm.request'
|
||||
|
||||
const PROTOCOL_VERSION = 1
|
||||
|
||||
@@ -44,13 +46,15 @@ const DIRECTION_RULES: Record<string, WorkerMessageDirection> = {
|
||||
'tool.result': 'parent_to_worker',
|
||||
'agent.cancel': 'parent_to_worker',
|
||||
'agent.ping': 'parent_to_worker',
|
||||
'llm.response': 'parent_to_worker',
|
||||
'worker.ready': 'worker_to_parent',
|
||||
'tool.call': 'worker_to_parent',
|
||||
'worker.result': 'worker_to_parent',
|
||||
'worker.checkpoint': 'worker_to_parent',
|
||||
'worker.heartbeat': 'worker_to_parent',
|
||||
'worker.error': 'worker_to_parent',
|
||||
'event': 'worker_to_parent'
|
||||
'event': 'worker_to_parent',
|
||||
'llm.request': 'worker_to_parent'
|
||||
}
|
||||
|
||||
export class WorkerProtocol {
|
||||
|
||||
Reference in New Issue
Block a user