agentxjs 2.2.0 → 2.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -0
- package/dist/{chunk-ZFL27HK7.js → chunk-X44CQZPK.js} +103 -1
- package/dist/chunk-X44CQZPK.js.map +1 -0
- package/dist/index.d.ts +87 -1
- package/dist/index.js +111 -2
- package/dist/index.js.map +1 -1
- package/dist/server-BWI5JE4B.js +7 -0
- package/package.json +6 -6
- package/src/CommandHandler.ts +133 -0
- package/src/LocalClient.ts +4 -0
- package/src/RemoteClient.ts +4 -0
- package/src/index.ts +10 -0
- package/src/namespaces/llm.ts +140 -0
- package/src/types.ts +95 -0
- package/dist/chunk-ZFL27HK7.js.map +0 -1
- package/dist/server-IFVYHIJF.js +0 -7
- /package/dist/{server-IFVYHIJF.js.map → server-BWI5JE4B.js.map} +0 -0
package/README.md
CHANGED
|
@@ -89,6 +89,7 @@ interface AgentX {
|
|
|
89
89
|
readonly agent: AgentNamespace;
|
|
90
90
|
readonly session: SessionNamespace;
|
|
91
91
|
readonly presentation: PresentationNamespace;
|
|
92
|
+
readonly llm: LLMNamespace;
|
|
92
93
|
|
|
93
94
|
// Universal RPC
|
|
94
95
|
rpc<T = unknown>(method: string, params?: unknown): Promise<T>;
|
|
@@ -146,6 +147,20 @@ interface AgentXBuilder extends AgentX {
|
|
|
146
147
|
|
|
147
148
|
- `create(agentId: string, options?: PresentationOptions): Promise<Presentation>`
|
|
148
149
|
|
|
150
|
+
**llm**:
|
|
151
|
+
|
|
152
|
+
- `create(params: { containerId, name, vendor, protocol, apiKey, baseUrl?, model? }): Promise<LLMProviderCreateResponse>`
|
|
153
|
+
- `get(id: string): Promise<LLMProviderGetResponse>`
|
|
154
|
+
- `list(containerId: string): Promise<LLMProviderListResponse>`
|
|
155
|
+
- `update(id: string, updates: { name?, apiKey?, baseUrl?, model? }): Promise<LLMProviderUpdateResponse>`
|
|
156
|
+
- `delete(id: string): Promise<BaseResponse>`
|
|
157
|
+
- `setDefault(id: string): Promise<BaseResponse>`
|
|
158
|
+
- `getDefault(containerId: string): Promise<LLMProviderDefaultResponse>`
|
|
159
|
+
|
|
160
|
+
Each LLM provider has a **vendor** (who provides the service — `anthropic`, `openai`, `deepseek`, `ollama`) and a **protocol** (API format — `anthropic` or `openai`). These are separate dimensions: e.g., Deepseek uses vendor `"deepseek"` with protocol `"openai"`.
|
|
161
|
+
|
|
162
|
+
When creating an agent, the runtime validates that the container's default LLM provider protocol is supported by the driver.
|
|
163
|
+
|
|
149
164
|
### Universal RPC
|
|
150
165
|
|
|
151
166
|
Transport-agnostic JSON-RPC entry point. Works in all modes — local dispatches to CommandHandler, remote forwards via WebSocket.
|
|
@@ -71,6 +71,19 @@ var CommandHandler = class {
|
|
|
71
71
|
// Message
|
|
72
72
|
case "message.send":
|
|
73
73
|
return await this.handleMessageSend(params);
|
|
74
|
+
// LLM Provider
|
|
75
|
+
case "llm.create":
|
|
76
|
+
return await this.handleLLMCreate(params);
|
|
77
|
+
case "llm.get":
|
|
78
|
+
return await this.handleLLMGet(params);
|
|
79
|
+
case "llm.list":
|
|
80
|
+
return await this.handleLLMList(params);
|
|
81
|
+
case "llm.update":
|
|
82
|
+
return await this.handleLLMUpdate(params);
|
|
83
|
+
case "llm.delete":
|
|
84
|
+
return await this.handleLLMDelete(params);
|
|
85
|
+
case "llm.default":
|
|
86
|
+
return await this.handleLLMDefault(params);
|
|
74
87
|
default:
|
|
75
88
|
return err(-32601, `Method not found: ${method}`);
|
|
76
89
|
}
|
|
@@ -288,6 +301,95 @@ var CommandHandler = class {
|
|
|
288
301
|
await this.runtime.receive(targetAgentId, content);
|
|
289
302
|
return ok({ agentId: targetAgentId, imageId });
|
|
290
303
|
}
|
|
304
|
+
// ==================== LLM Provider Commands ====================
|
|
305
|
+
async handleLLMCreate(params) {
|
|
306
|
+
const { containerId, name, vendor, protocol, apiKey, baseUrl, model } = params;
|
|
307
|
+
const repo = this.runtime.platform.llmProviderRepository;
|
|
308
|
+
if (!repo) {
|
|
309
|
+
return err(-32e3, "LLM provider repository not available");
|
|
310
|
+
}
|
|
311
|
+
const { generateId } = await import("@deepracticex/id");
|
|
312
|
+
const now = Date.now();
|
|
313
|
+
const record = {
|
|
314
|
+
id: generateId("llm"),
|
|
315
|
+
containerId,
|
|
316
|
+
name,
|
|
317
|
+
vendor,
|
|
318
|
+
protocol,
|
|
319
|
+
apiKey,
|
|
320
|
+
baseUrl,
|
|
321
|
+
model,
|
|
322
|
+
isDefault: false,
|
|
323
|
+
createdAt: now,
|
|
324
|
+
updatedAt: now
|
|
325
|
+
};
|
|
326
|
+
await repo.saveLLMProvider(record);
|
|
327
|
+
return ok({ record });
|
|
328
|
+
}
|
|
329
|
+
async handleLLMGet(params) {
|
|
330
|
+
const { id } = params;
|
|
331
|
+
const repo = this.runtime.platform.llmProviderRepository;
|
|
332
|
+
if (!repo) {
|
|
333
|
+
return err(-32e3, "LLM provider repository not available");
|
|
334
|
+
}
|
|
335
|
+
const record = await repo.findLLMProviderById(id);
|
|
336
|
+
return ok({ record });
|
|
337
|
+
}
|
|
338
|
+
async handleLLMList(params) {
|
|
339
|
+
const { containerId } = params;
|
|
340
|
+
const repo = this.runtime.platform.llmProviderRepository;
|
|
341
|
+
if (!repo) {
|
|
342
|
+
return err(-32e3, "LLM provider repository not available");
|
|
343
|
+
}
|
|
344
|
+
const records = await repo.findLLMProvidersByContainerId(containerId);
|
|
345
|
+
return ok({ records });
|
|
346
|
+
}
|
|
347
|
+
async handleLLMUpdate(params) {
|
|
348
|
+
const { id, updates } = params;
|
|
349
|
+
const repo = this.runtime.platform.llmProviderRepository;
|
|
350
|
+
if (!repo) {
|
|
351
|
+
return err(-32e3, "LLM provider repository not available");
|
|
352
|
+
}
|
|
353
|
+
const existing = await repo.findLLMProviderById(id);
|
|
354
|
+
if (!existing) {
|
|
355
|
+
return err(404, `LLM provider not found: ${id}`);
|
|
356
|
+
}
|
|
357
|
+
const updated = {
|
|
358
|
+
...existing,
|
|
359
|
+
...updates,
|
|
360
|
+
id: existing.id,
|
|
361
|
+
containerId: existing.containerId,
|
|
362
|
+
createdAt: existing.createdAt,
|
|
363
|
+
updatedAt: Date.now()
|
|
364
|
+
};
|
|
365
|
+
await repo.saveLLMProvider(updated);
|
|
366
|
+
return ok({ record: updated });
|
|
367
|
+
}
|
|
368
|
+
async handleLLMDelete(params) {
|
|
369
|
+
const { id } = params;
|
|
370
|
+
const repo = this.runtime.platform.llmProviderRepository;
|
|
371
|
+
if (!repo) {
|
|
372
|
+
return err(-32e3, "LLM provider repository not available");
|
|
373
|
+
}
|
|
374
|
+
await repo.deleteLLMProvider(id);
|
|
375
|
+
return ok({ id });
|
|
376
|
+
}
|
|
377
|
+
async handleLLMDefault(params) {
|
|
378
|
+
const { id, containerId } = params;
|
|
379
|
+
const repo = this.runtime.platform.llmProviderRepository;
|
|
380
|
+
if (!repo) {
|
|
381
|
+
return err(-32e3, "LLM provider repository not available");
|
|
382
|
+
}
|
|
383
|
+
if (id) {
|
|
384
|
+
await repo.setDefaultLLMProvider(id);
|
|
385
|
+
return ok({ id });
|
|
386
|
+
}
|
|
387
|
+
if (containerId) {
|
|
388
|
+
const record = await repo.findDefaultLLMProvider(containerId);
|
|
389
|
+
return ok({ record });
|
|
390
|
+
}
|
|
391
|
+
return err(-32602, "Either id or containerId is required");
|
|
392
|
+
}
|
|
291
393
|
// ==================== Lifecycle ====================
|
|
292
394
|
dispose() {
|
|
293
395
|
logger.debug("CommandHandler disposed");
|
|
@@ -464,4 +566,4 @@ export {
|
|
|
464
566
|
CommandHandler,
|
|
465
567
|
createServer
|
|
466
568
|
};
|
|
467
|
-
//# sourceMappingURL=chunk-
|
|
569
|
+
//# sourceMappingURL=chunk-X44CQZPK.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/server.ts","../src/CommandHandler.ts"],"sourcesContent":["/**\n * AgentX Server Implementation (JSON-RPC 2.0)\n *\n * Creates a WebSocket server that:\n * 1. Accepts client connections\n * 2. Handles JSON-RPC requests directly via CommandHandler\n * 3. Broadcasts stream events as JSON-RPC notifications\n *\n * Message Types:\n * - RPC Request (has id): Client → Server → Client (direct response)\n * - RPC Notification (no id): Server → Client (stream events)\n */\n\nimport type { CreateDriver } from \"@agentxjs/core/driver\";\nimport type { BusEvent, SystemEvent } from \"@agentxjs/core/event\";\nimport type { ChannelConnection } from \"@agentxjs/core/network\";\nimport {\n createErrorResponse,\n createStreamEvent,\n createSuccessResponse,\n isNotification,\n isRequest,\n parseMessage,\n RpcErrorCodes,\n type RpcMethod,\n} from \"@agentxjs/core/network\";\nimport type { AgentXPlatform } from \"@agentxjs/core/runtime\";\nimport { createAgentXRuntime } from \"@agentxjs/core/runtime\";\nimport { createLogger } from \"@deepracticex/logger\";\nimport { CommandHandler } from \"./CommandHandler\";\nimport type { AgentXServer } from \"./types\";\n\nconst logger = createLogger(\"server/Server\");\n\n/**\n * Connection state\n */\ninterface ConnectionState {\n connection: ChannelConnection;\n subscribedTopics: Set<string>;\n}\n\n/**\n * Server configuration (supports both immediate and deferred platforms)\n */\nexport interface ServerConfig {\n /**\n * AgentX Platform — must provide `channelServer` for accepting WebSocket connections.\n */\n platform: AgentXPlatform;\n\n /**\n * LLM Driver factory function - creates Driver per Agent\n */\n createDriver: CreateDriver;\n\n /**\n * Port to listen on (standalone mode)\n */\n port?: number;\n\n /**\n * Host to bind to (default: \"0.0.0.0\")\n */\n host?: string;\n\n /**\n * Existing HTTP server to attach to (attached mode)\n */\n server?: import(\"@agentxjs/core/network\").MinimalHTTPServer;\n\n /**\n * WebSocket path when attached (default: \"/ws\")\n */\n wsPath?: string;\n\n /**\n * Enable debug logging\n */\n debug?: boolean;\n}\n\n/**\n * Create an AgentX server\n */\nexport async function createServer(config: ServerConfig): Promise<AgentXServer> {\n const { wsPath = \"/ws\" } = config;\n const platform = config.platform;\n\n // Create runtime from platform + driver\n const runtime = createAgentXRuntime(platform, config.createDriver);\n\n // Get channel server from platform\n const wsServer = platform.channelServer;\n if (!wsServer) {\n throw new Error(\"Platform must provide channelServer for server mode\");\n }\n\n // Create command handler (no longer needs eventBus)\n const commandHandler = new CommandHandler(runtime);\n\n // Track connections\n const connections = new Map<string, ConnectionState>();\n\n /**\n * Subscribe connection to a topic\n */\n function subscribeToTopic(connectionId: string, topic: string): void {\n const state = connections.get(connectionId);\n if (!state || state.subscribedTopics.has(topic)) return;\n\n state.subscribedTopics.add(topic);\n logger.debug(\"Connection subscribed to topic\", { connectionId, topic });\n }\n\n /**\n * Check if event should be sent to connection based on subscriptions\n */\n function shouldSendToConnection(state: ConnectionState, event: BusEvent): boolean {\n // Skip internal driver events\n if (event.source === \"driver\" && event.intent !== \"notification\") {\n return false;\n }\n\n // Skip command events (they are handled via RPC, not broadcast)\n if (event.source === \"command\") {\n return false;\n }\n\n // Check if subscribed to event's session\n const eventWithContext = event as BusEvent & { context?: { sessionId?: string } };\n const sessionId = eventWithContext.context?.sessionId;\n if (sessionId && state.subscribedTopics.has(sessionId)) {\n return true;\n }\n\n // Send to global subscribers\n return state.subscribedTopics.has(\"global\");\n }\n\n /**\n * Send JSON-RPC response to a specific connection\n */\n function sendResponse(connection: ChannelConnection, id: string | number, result: unknown): void {\n const response = createSuccessResponse(id, result);\n connection.send(JSON.stringify(response));\n }\n\n /**\n * Send JSON-RPC error to a specific connection\n */\n function sendError(\n connection: ChannelConnection,\n id: string | number | null,\n code: number,\n message: string\n ): void {\n const response = createErrorResponse(id, code, message);\n connection.send(JSON.stringify(response));\n }\n\n // Handle new connections\n wsServer.onConnection((connection) => {\n const state: ConnectionState = {\n connection,\n subscribedTopics: new Set([\"global\"]),\n };\n connections.set(connection.id, state);\n\n logger.info(\"Client connected\", {\n connectionId: connection.id,\n totalConnections: connections.size,\n });\n\n // Handle messages from client\n connection.onMessage(async (message) => {\n try {\n const parsed = parseMessage(message);\n\n // Handle single message (not batch)\n if (!Array.isArray(parsed)) {\n await handleParsedMessage(connection, state, parsed);\n } else {\n // Handle batch (not common, but supported by JSON-RPC 2.0)\n for (const item of parsed) {\n await handleParsedMessage(connection, state, item);\n }\n }\n } catch (err) {\n logger.error(\"Failed to parse message\", { error: (err as Error).message });\n sendError(connection, null, RpcErrorCodes.PARSE_ERROR, \"Parse error\");\n }\n });\n\n // Cleanup on disconnect\n connection.onClose(() => {\n connections.delete(connection.id);\n logger.info(\"Client disconnected\", {\n connectionId: connection.id,\n totalConnections: connections.size,\n });\n });\n });\n\n /**\n * Handle a parsed JSON-RPC message\n */\n async function handleParsedMessage(\n connection: ChannelConnection,\n state: ConnectionState,\n parsed: import(\"jsonrpc-lite\").IParsedObject\n ): Promise<void> {\n if (isRequest(parsed)) {\n // JSON-RPC Request - handle and respond directly\n const payload = parsed.payload as {\n id: string | number;\n method: string;\n params: unknown;\n };\n const { id, method, params } = payload;\n\n logger.debug(\"Received RPC request\", { id, method });\n\n // Call command handler\n const result = await commandHandler.handle(method as RpcMethod, params);\n\n if (result.success) {\n sendResponse(connection, id, result.data);\n } else {\n sendError(connection, id, result.code, result.message);\n }\n } else if (isNotification(parsed)) {\n // JSON-RPC Notification - control messages\n const payload = parsed.payload as {\n method: string;\n params: unknown;\n };\n const { method, params } = payload;\n\n logger.debug(\"Received notification\", { method });\n\n if (method === \"subscribe\") {\n const { topic } = params as { topic: string };\n subscribeToTopic(connection.id, topic);\n } else if (method === \"unsubscribe\") {\n const { topic } = params as { topic: string };\n state.subscribedTopics.delete(topic);\n logger.debug(\"Connection unsubscribed from topic\", { connectionId: connection.id, topic });\n } else if (method === \"control.ack\") {\n // ACK for reliable delivery - handled by network layer\n logger.debug(\"Received ACK notification\");\n }\n } else {\n // Invalid message\n logger.warn(\"Received invalid JSON-RPC message\");\n }\n }\n\n // Route internal events to connected clients as JSON-RPC notifications\n platform.eventBus.onAny((event) => {\n // Only broadcast broadcastable events\n if (!shouldBroadcastEvent(event)) {\n return;\n }\n\n // Get topic from event context\n const eventWithContext = event as BusEvent & { context?: { sessionId?: string } };\n const topic = eventWithContext.context?.sessionId || \"global\";\n\n // Wrap as JSON-RPC notification\n const notification = createStreamEvent(topic, event as SystemEvent);\n const message = JSON.stringify(notification);\n\n for (const [connectionId, state] of connections) {\n if (shouldSendToConnection(state, event)) {\n state.connection.sendReliable(message, {\n timeout: 10000,\n onTimeout: () => {\n logger.warn(\"Event ACK timeout\", {\n connectionId,\n eventType: event.type,\n });\n },\n });\n }\n }\n });\n\n /**\n * Check if event should be broadcast\n */\n function shouldBroadcastEvent(event: BusEvent): boolean {\n // Skip internal driver events\n if (event.source === \"driver\" && event.intent !== \"notification\") {\n return false;\n }\n\n // Skip command events (handled via RPC)\n if (event.source === \"command\") {\n return false;\n }\n\n // Check broadcastable flag\n const systemEvent = event as SystemEvent;\n if (systemEvent.broadcastable === false) {\n return false;\n }\n\n return true;\n }\n\n // Attach to existing server if provided\n if (config.server) {\n wsServer.attach(config.server, wsPath);\n logger.info(\"WebSocket attached to existing server\", { path: wsPath });\n }\n\n return {\n async listen(port?: number, host?: string) {\n if (config.server) {\n throw new Error(\n \"Cannot listen when attached to existing server. The server should call listen() instead.\"\n );\n }\n\n const listenPort = port ?? config.port ?? 5200;\n const listenHost = host ?? config.host ?? \"0.0.0.0\";\n\n await wsServer.listen(listenPort, listenHost);\n logger.info(\"Server listening\", { port: listenPort, host: listenHost });\n },\n\n async close() {\n await wsServer.close();\n logger.info(\"Server closed\");\n },\n\n async dispose() {\n // Cleanup in order\n await wsServer.dispose();\n commandHandler.dispose();\n await runtime.shutdown();\n logger.info(\"Server disposed\");\n },\n };\n}\n","/**\n * CommandHandler - Handles JSON-RPC requests directly\n *\n * No longer uses EventBus for request/response. Instead:\n * - Receives RPC requests directly\n * - Returns RPC responses directly\n * - EventBus is only used for stream events (notifications)\n */\n\nimport type { UserContentPart } from \"@agentxjs/core/agent\";\nimport type { RpcMethod } from \"@agentxjs/core/network\";\nimport type { AgentXRuntime } from \"@agentxjs/core/runtime\";\nimport { createLogger } from \"@deepracticex/logger\";\n\nconst logger = createLogger(\"server/CommandHandler\");\n\n/**\n * RPC Result type\n */\nexport interface RpcResult<T = unknown> {\n success: true;\n data: T;\n}\n\nexport interface RpcError {\n success: false;\n code: number;\n message: string;\n}\n\nexport type RpcResponse<T = unknown> = RpcResult<T> | RpcError;\n\n/**\n * Helper to create success result\n */\nfunction ok<T>(data: T): RpcResult<T> {\n return { success: true, data };\n}\n\n/**\n * Helper to create error result\n */\nfunction err(code: number, message: string): RpcError {\n return { success: false, code, message };\n}\n\n/**\n * CommandHandler - Processes RPC requests directly\n */\nexport class CommandHandler {\n private readonly runtime: AgentXRuntime;\n\n constructor(runtime: AgentXRuntime) {\n this.runtime = runtime;\n logger.debug(\"CommandHandler created\");\n }\n\n /**\n * Handle an RPC request and return response\n */\n async handle(method: RpcMethod, params: unknown): Promise<RpcResponse> {\n logger.debug(\"Handling RPC request\", { method });\n\n try {\n switch (method) {\n // Container\n case \"container.create\":\n return await this.handleContainerCreate(params);\n case \"container.get\":\n return await this.handleContainerGet(params);\n case \"container.list\":\n return await this.handleContainerList(params);\n\n // Image\n case \"image.create\":\n return await this.handleImageCreate(params);\n case \"image.get\":\n return await this.handleImageGet(params);\n case \"image.list\":\n return await this.handleImageList(params);\n case \"image.delete\":\n return await this.handleImageDelete(params);\n case \"image.run\":\n return await this.handleImageRun(params);\n case \"image.stop\":\n return await this.handleImageStop(params);\n case \"image.update\":\n return await this.handleImageUpdate(params);\n case \"image.messages\":\n return await this.handleImageMessages(params);\n\n // Agent\n case \"agent.get\":\n return await this.handleAgentGet(params);\n case \"agent.list\":\n return await this.handleAgentList(params);\n case \"agent.destroy\":\n return await this.handleAgentDestroy(params);\n case \"agent.destroyAll\":\n return await this.handleAgentDestroyAll(params);\n case \"agent.interrupt\":\n return await this.handleAgentInterrupt(params);\n\n // Message\n case \"message.send\":\n return await this.handleMessageSend(params);\n\n // LLM Provider\n case \"llm.create\":\n return await this.handleLLMCreate(params);\n case \"llm.get\":\n return await this.handleLLMGet(params);\n case \"llm.list\":\n return await this.handleLLMList(params);\n case \"llm.update\":\n return await this.handleLLMUpdate(params);\n case \"llm.delete\":\n return await this.handleLLMDelete(params);\n case \"llm.default\":\n return await this.handleLLMDefault(params);\n\n default:\n return err(-32601, `Method not found: ${method}`);\n }\n } catch (error) {\n logger.error(\"RPC handler error\", { method, error });\n return err(-32000, error instanceof Error ? error.message : String(error));\n }\n }\n\n // ==================== Container Commands ====================\n\n private async handleContainerCreate(params: unknown): Promise<RpcResponse> {\n const { containerId } = params as { containerId: string };\n const { getOrCreateContainer } = await import(\"@agentxjs/core/container\");\n const { containerRepository, imageRepository, sessionRepository } = this.runtime.platform;\n\n const container = await getOrCreateContainer(containerId, {\n containerRepository,\n imageRepository,\n sessionRepository,\n });\n\n return ok({ containerId: container.containerId });\n }\n\n private async handleContainerGet(params: unknown): Promise<RpcResponse> {\n const { containerId } = params as { containerId: string };\n const exists = await this.runtime.platform.containerRepository.containerExists(containerId);\n return ok({ containerId, exists });\n }\n\n private async handleContainerList(_params: unknown): Promise<RpcResponse> {\n const containers = await this.runtime.platform.containerRepository.findAllContainers();\n return ok({ containerIds: containers.map((c) => c.containerId) });\n }\n\n // ==================== Image Commands ====================\n\n private async handleImageCreate(params: unknown): Promise<RpcResponse> {\n const { containerId, name, description, systemPrompt, mcpServers, customData } = params as {\n containerId: string;\n name?: string;\n description?: string;\n systemPrompt?: string;\n mcpServers?: Record<string, unknown>;\n customData?: Record<string, unknown>;\n };\n\n const { imageRepository, sessionRepository } = this.runtime.platform;\n const { createImage } = await import(\"@agentxjs/core/image\");\n\n const image = await createImage(\n { containerId, name, description, systemPrompt, mcpServers: mcpServers as any, customData },\n { imageRepository, sessionRepository }\n );\n\n return ok({\n record: image.toRecord(),\n __subscriptions: [image.sessionId],\n });\n }\n\n private async handleImageGet(params: unknown): Promise<RpcResponse> {\n const { imageId } = params as { imageId: string };\n const record = await this.runtime.platform.imageRepository.findImageById(imageId);\n return ok({\n record,\n __subscriptions: record?.sessionId ? [record.sessionId] : undefined,\n });\n }\n\n private async handleImageList(params: unknown): Promise<RpcResponse> {\n const { containerId } = params as { containerId?: string };\n const records = containerId\n ? await this.runtime.platform.imageRepository.findImagesByContainerId(containerId)\n : await this.runtime.platform.imageRepository.findAllImages();\n\n return ok({\n records,\n __subscriptions: records.map((r) => r.sessionId),\n });\n }\n\n private async handleImageDelete(params: unknown): Promise<RpcResponse> {\n const { imageId } = params as { imageId: string };\n const { loadImage } = await import(\"@agentxjs/core/image\");\n const { imageRepository, sessionRepository } = this.runtime.platform;\n\n const image = await loadImage(imageId, { imageRepository, sessionRepository });\n if (image) {\n await image.delete();\n }\n\n return ok({ imageId });\n }\n\n private async handleImageRun(params: unknown): Promise<RpcResponse> {\n const { imageId, agentId: requestedAgentId } = params as {\n imageId: string;\n agentId?: string;\n };\n\n // Check if already have a running agent for this image\n const existingAgent = this.runtime\n .getAgents()\n .find((a) => a.imageId === imageId && a.lifecycle === \"running\");\n\n if (existingAgent) {\n logger.debug(\"Reusing existing agent for image\", {\n imageId,\n agentId: existingAgent.agentId,\n });\n return ok({\n imageId,\n agentId: existingAgent.agentId,\n sessionId: existingAgent.sessionId,\n containerId: existingAgent.containerId,\n reused: true,\n });\n }\n\n // Create new agent (with optional custom agentId)\n const agent = await this.runtime.createAgent({\n imageId,\n agentId: requestedAgentId,\n });\n logger.info(\"Created new agent for image\", {\n imageId,\n agentId: agent.agentId,\n });\n\n return ok({\n imageId,\n agentId: agent.agentId,\n sessionId: agent.sessionId,\n containerId: agent.containerId,\n reused: false,\n });\n }\n\n private async handleImageStop(params: unknown): Promise<RpcResponse> {\n const { imageId } = params as { imageId: string };\n\n // Find running agent for this image\n const agent = this.runtime\n .getAgents()\n .find((a) => a.imageId === imageId && a.lifecycle === \"running\");\n\n if (agent) {\n await this.runtime.stopAgent(agent.agentId);\n logger.info(\"Stopped agent for image\", { imageId, agentId: agent.agentId });\n } else {\n logger.debug(\"No running agent found for image\", { imageId });\n }\n\n return ok({ imageId });\n }\n\n private async handleImageUpdate(params: unknown): Promise<RpcResponse> {\n const { imageId, updates } = params as {\n imageId: string;\n updates: { name?: string; description?: string; customData?: Record<string, unknown> };\n };\n\n // Get existing image\n const imageRecord = await this.runtime.platform.imageRepository.findImageById(imageId);\n if (!imageRecord) {\n return err(404, `Image not found: ${imageId}`);\n }\n\n // Update image record\n const updatedRecord = {\n ...imageRecord,\n ...updates,\n updatedAt: Date.now(),\n };\n\n await this.runtime.platform.imageRepository.saveImage(updatedRecord);\n\n logger.info(\"Updated image\", { imageId, updates });\n\n return ok({ record: updatedRecord });\n }\n\n private async handleImageMessages(params: unknown): Promise<RpcResponse> {\n const { imageId } = params as { imageId: string };\n\n // Get image record to find sessionId\n const imageRecord = await this.runtime.platform.imageRepository.findImageById(imageId);\n if (!imageRecord) {\n return err(404, `Image not found: ${imageId}`);\n }\n\n // Get messages from session\n const messages = await this.runtime.platform.sessionRepository.getMessages(\n imageRecord.sessionId\n );\n\n logger.debug(\"Got messages for image\", { imageId, count: messages.length });\n\n return ok({ imageId, messages });\n }\n\n // ==================== Agent Commands ====================\n\n private async handleAgentGet(params: unknown): Promise<RpcResponse> {\n const { agentId } = params as { agentId: string };\n const agent = this.runtime.getAgent(agentId);\n\n return ok({\n agent: agent\n ? {\n agentId: agent.agentId,\n imageId: agent.imageId,\n containerId: agent.containerId,\n sessionId: agent.sessionId,\n lifecycle: agent.lifecycle,\n }\n : null,\n exists: !!agent,\n });\n }\n\n private async handleAgentList(params: unknown): Promise<RpcResponse> {\n const { containerId } = params as { containerId?: string };\n const agents = containerId\n ? this.runtime.getAgentsByContainer(containerId)\n : this.runtime.getAgents();\n\n return ok({\n agents: agents.map((a) => ({\n agentId: a.agentId,\n imageId: a.imageId,\n containerId: a.containerId,\n sessionId: a.sessionId,\n lifecycle: a.lifecycle,\n })),\n });\n }\n\n private async handleAgentDestroy(params: unknown): Promise<RpcResponse> {\n const { agentId } = params as { agentId: string };\n\n // Check if agent exists first\n const agent = this.runtime.getAgent(agentId);\n if (!agent) {\n return ok({ agentId, success: false });\n }\n\n await this.runtime.destroyAgent(agentId);\n return ok({ agentId, success: true });\n }\n\n private async handleAgentDestroyAll(params: unknown): Promise<RpcResponse> {\n const { containerId } = params as { containerId: string };\n const agents = this.runtime.getAgentsByContainer(containerId);\n for (const agent of agents) {\n await this.runtime.destroyAgent(agent.agentId);\n }\n return ok({ containerId });\n }\n\n private async handleAgentInterrupt(params: unknown): Promise<RpcResponse> {\n const { agentId } = params as { agentId: string };\n this.runtime.interrupt(agentId);\n return ok({ agentId });\n }\n\n // ==================== Message Commands ====================\n\n private async handleMessageSend(params: unknown): Promise<RpcResponse> {\n const { agentId, imageId, content } = params as {\n agentId?: string;\n imageId?: string;\n content: string | UserContentPart[];\n };\n\n let targetAgentId: string;\n\n if (agentId) {\n // Direct agent reference\n targetAgentId = agentId;\n } else if (imageId) {\n // Auto-activate image: find or create agent\n const existingAgent = this.runtime\n .getAgents()\n .find((a) => a.imageId === imageId && a.lifecycle === \"running\");\n\n if (existingAgent) {\n targetAgentId = existingAgent.agentId;\n logger.debug(\"Using existing agent for message\", {\n imageId,\n agentId: targetAgentId,\n });\n } else {\n // Create new agent for this image\n const agent = await this.runtime.createAgent({ imageId });\n targetAgentId = agent.agentId;\n logger.info(\"Auto-created agent for message\", {\n imageId,\n agentId: targetAgentId,\n });\n }\n } else {\n return err(-32602, \"Either agentId or imageId is required\");\n }\n\n await this.runtime.receive(targetAgentId, content);\n return ok({ agentId: targetAgentId, imageId });\n }\n\n // ==================== LLM Provider Commands ====================\n\n private async handleLLMCreate(params: unknown): Promise<RpcResponse> {\n const { containerId, name, vendor, protocol, apiKey, baseUrl, model } = params as {\n containerId: string;\n name: string;\n vendor: string;\n protocol: string;\n apiKey: string;\n baseUrl?: string;\n model?: string;\n };\n\n const repo = this.runtime.platform.llmProviderRepository;\n if (!repo) {\n return err(-32000, \"LLM provider repository not available\");\n }\n\n const { generateId } = await import(\"@deepracticex/id\");\n const now = Date.now();\n const record = {\n id: generateId(\"llm\"),\n containerId,\n name,\n vendor,\n protocol: protocol as \"anthropic\" | \"openai\",\n apiKey,\n baseUrl,\n model,\n isDefault: false,\n createdAt: now,\n updatedAt: now,\n };\n\n await repo.saveLLMProvider(record);\n return ok({ record });\n }\n\n private async handleLLMGet(params: unknown): Promise<RpcResponse> {\n const { id } = params as { id: string };\n const repo = this.runtime.platform.llmProviderRepository;\n if (!repo) {\n return err(-32000, \"LLM provider repository not available\");\n }\n\n const record = await repo.findLLMProviderById(id);\n return ok({ record });\n }\n\n private async handleLLMList(params: unknown): Promise<RpcResponse> {\n const { containerId } = params as { containerId: string };\n const repo = this.runtime.platform.llmProviderRepository;\n if (!repo) {\n return err(-32000, \"LLM provider repository not available\");\n }\n\n const records = await repo.findLLMProvidersByContainerId(containerId);\n return ok({ records });\n }\n\n private async handleLLMUpdate(params: unknown): Promise<RpcResponse> {\n const { id, updates } = params as {\n id: string;\n updates: Record<string, unknown>;\n };\n const repo = this.runtime.platform.llmProviderRepository;\n if (!repo) {\n return err(-32000, \"LLM provider repository not available\");\n }\n\n const existing = await repo.findLLMProviderById(id);\n if (!existing) {\n return err(404, `LLM provider not found: ${id}`);\n }\n\n const updated = {\n ...existing,\n ...updates,\n id: existing.id,\n containerId: existing.containerId,\n createdAt: existing.createdAt,\n updatedAt: Date.now(),\n };\n\n await repo.saveLLMProvider(updated);\n return ok({ record: updated });\n }\n\n private async handleLLMDelete(params: unknown): Promise<RpcResponse> {\n const { id } = params as { id: string };\n const repo = this.runtime.platform.llmProviderRepository;\n if (!repo) {\n return err(-32000, \"LLM provider repository not available\");\n }\n\n await repo.deleteLLMProvider(id);\n return ok({ id });\n }\n\n private async handleLLMDefault(params: unknown): Promise<RpcResponse> {\n const { id, containerId } = params as { id?: string; containerId?: string };\n const repo = this.runtime.platform.llmProviderRepository;\n if (!repo) {\n return err(-32000, \"LLM provider repository not available\");\n }\n\n if (id) {\n // Set default\n await repo.setDefaultLLMProvider(id);\n return ok({ id });\n }\n if (containerId) {\n // Get default\n const record = await repo.findDefaultLLMProvider(containerId);\n return ok({ record });\n }\n return err(-32602, \"Either id or containerId is required\");\n }\n\n // ==================== Lifecycle ====================\n\n dispose(): void {\n logger.debug(\"CommandHandler disposed\");\n }\n}\n"],"mappings":";AAgBA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AAEP,SAAS,2BAA2B;AACpC,SAAS,gBAAAA,qBAAoB;;;AChB7B,SAAS,oBAAoB;AAE7B,IAAM,SAAS,aAAa,uBAAuB;AAqBnD,SAAS,GAAM,MAAuB;AACpC,SAAO,EAAE,SAAS,MAAM,KAAK;AAC/B;AAKA,SAAS,IAAI,MAAc,SAA2B;AACpD,SAAO,EAAE,SAAS,OAAO,MAAM,QAAQ;AACzC;AAKO,IAAM,iBAAN,MAAqB;AAAA,EACT;AAAA,EAEjB,YAAY,SAAwB;AAClC,SAAK,UAAU;AACf,WAAO,MAAM,wBAAwB;AAAA,EACvC;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,OAAO,QAAmB,QAAuC;AACrE,WAAO,MAAM,wBAAwB,EAAE,OAAO,CAAC;AAE/C,QAAI;AACF,cAAQ,QAAQ;AAAA;AAAA,QAEd,KAAK;AACH,iBAAO,MAAM,KAAK,sBAAsB,MAAM;AAAA,QAChD,KAAK;AACH,iBAAO,MAAM,KAAK,mBAAmB,MAAM;AAAA,QAC7C,KAAK;AACH,iBAAO,MAAM,KAAK,oBAAoB,MAAM;AAAA;AAAA,QAG9C,KAAK;AACH,iBAAO,MAAM,KAAK,kBAAkB,MAAM;AAAA,QAC5C,KAAK;AACH,iBAAO,MAAM,KAAK,eAAe,MAAM;AAAA,QACzC,KAAK;AACH,iBAAO,MAAM,KAAK,gBAAgB,MAAM;AAAA,QAC1C,KAAK;AACH,iBAAO,MAAM,KAAK,kBAAkB,MAAM;AAAA,QAC5C,KAAK;AACH,iBAAO,MAAM,KAAK,eAAe,MAAM;A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M;AACrC,IAAAA,QAAO,KAAK,yCAAyC,EAAE,MAAM,OAAO,CAAC;AAAA,EACvE;AAEA,SAAO;AAAA,IACL,MAAM,OAAO,MAAe,MAAe;AACzC,UAAI,OAAO,QAAQ;AACjB,cAAM,IAAI;AAAA,UACR;AAAA,QACF;AAAA,MACF;AAEA,YAAM,aAAa,QAAQ,OAAO,QAAQ;AAC1C,YAAM,aAAa,QAAQ,OAAO,QAAQ;AAE1C,YAAM,SAAS,OAAO,YAAY,UAAU;AAC5C,MAAAA,QAAO,KAAK,oBAAoB,EAAE,MAAM,YAAY,MAAM,WAAW,CAAC;AAAA,IACxE;AAAA,IAEA,MAAM,QAAQ;AACZ,YAAM,SAAS,MAAM;AACrB,MAAAA,QAAO,KAAK,eAAe;AAAA,IAC7B;AAAA,IAEA,MAAM,UAAU;AAEd,YAAM,SAAS,QAAQ;AACvB,qBAAe,QAAQ;AACvB,YAAM,QAAQ,SAAS;AACvB,MAAAA,QAAO,KAAK,iBAAiB;AAAA,IAC/B;AAAA,EACF;AACF;","names":["createLogger","logger","createLogger","err"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { Message } from '@agentxjs/core/agent';
|
|
|
4
4
|
import { AgentXError } from '@agentxjs/core/error';
|
|
5
5
|
export { AgentXError, AgentXErrorCategory, AgentXErrorCode, AgentXErrorContext } from '@agentxjs/core/error';
|
|
6
6
|
import { Unsubscribe, BusEvent, EventBus, BusEventHandler } from '@agentxjs/core/event';
|
|
7
|
+
import { LLMProtocol, LLMProviderRecord } from '@agentxjs/core/persistence';
|
|
7
8
|
import * as _agentxjs_core_network from '@agentxjs/core/network';
|
|
8
9
|
import { RpcMethod } from '@agentxjs/core/network';
|
|
9
10
|
|
|
@@ -329,6 +330,36 @@ interface ContainerListResponse extends BaseResponse {
|
|
|
329
330
|
interface MessageSendResponse extends BaseResponse {
|
|
330
331
|
agentId: string;
|
|
331
332
|
}
|
|
333
|
+
/**
|
|
334
|
+
* LLM provider create response
|
|
335
|
+
*/
|
|
336
|
+
interface LLMProviderCreateResponse extends BaseResponse {
|
|
337
|
+
record: LLMProviderRecord;
|
|
338
|
+
}
|
|
339
|
+
/**
|
|
340
|
+
* LLM provider get response
|
|
341
|
+
*/
|
|
342
|
+
interface LLMProviderGetResponse extends BaseResponse {
|
|
343
|
+
record: LLMProviderRecord | null;
|
|
344
|
+
}
|
|
345
|
+
/**
|
|
346
|
+
* LLM provider list response
|
|
347
|
+
*/
|
|
348
|
+
interface LLMProviderListResponse extends BaseResponse {
|
|
349
|
+
records: LLMProviderRecord[];
|
|
350
|
+
}
|
|
351
|
+
/**
|
|
352
|
+
* LLM provider update response
|
|
353
|
+
*/
|
|
354
|
+
interface LLMProviderUpdateResponse extends BaseResponse {
|
|
355
|
+
record: LLMProviderRecord;
|
|
356
|
+
}
|
|
357
|
+
/**
|
|
358
|
+
* LLM provider default response
|
|
359
|
+
*/
|
|
360
|
+
interface LLMProviderDefaultResponse extends BaseResponse {
|
|
361
|
+
record: LLMProviderRecord | null;
|
|
362
|
+
}
|
|
332
363
|
/**
|
|
333
364
|
* Container operations namespace
|
|
334
365
|
*/
|
|
@@ -427,6 +458,54 @@ interface SessionNamespace {
|
|
|
427
458
|
*/
|
|
428
459
|
getMessages(agentId: string): Promise<Message[]>;
|
|
429
460
|
}
|
|
461
|
+
/**
|
|
462
|
+
* LLM provider operations namespace
|
|
463
|
+
*/
|
|
464
|
+
interface LLMNamespace {
|
|
465
|
+
/**
|
|
466
|
+
* Create a new LLM provider configuration
|
|
467
|
+
*/
|
|
468
|
+
create(params: {
|
|
469
|
+
containerId: string;
|
|
470
|
+
name: string;
|
|
471
|
+
vendor: string;
|
|
472
|
+
protocol: LLMProtocol;
|
|
473
|
+
apiKey: string;
|
|
474
|
+
baseUrl?: string;
|
|
475
|
+
model?: string;
|
|
476
|
+
}): Promise<LLMProviderCreateResponse>;
|
|
477
|
+
/**
|
|
478
|
+
* Get LLM provider by ID
|
|
479
|
+
*/
|
|
480
|
+
get(id: string): Promise<LLMProviderGetResponse>;
|
|
481
|
+
/**
|
|
482
|
+
* List LLM providers for a container
|
|
483
|
+
*/
|
|
484
|
+
list(containerId: string): Promise<LLMProviderListResponse>;
|
|
485
|
+
/**
|
|
486
|
+
* Update LLM provider
|
|
487
|
+
*/
|
|
488
|
+
update(id: string, updates: {
|
|
489
|
+
name?: string;
|
|
490
|
+
vendor?: string;
|
|
491
|
+
protocol?: LLMProtocol;
|
|
492
|
+
apiKey?: string;
|
|
493
|
+
baseUrl?: string;
|
|
494
|
+
model?: string;
|
|
495
|
+
}): Promise<LLMProviderUpdateResponse>;
|
|
496
|
+
/**
|
|
497
|
+
* Delete LLM provider
|
|
498
|
+
*/
|
|
499
|
+
delete(id: string): Promise<BaseResponse>;
|
|
500
|
+
/**
|
|
501
|
+
* Set default LLM provider for a container
|
|
502
|
+
*/
|
|
503
|
+
setDefault(id: string): Promise<BaseResponse>;
|
|
504
|
+
/**
|
|
505
|
+
* Get default LLM provider for a container
|
|
506
|
+
*/
|
|
507
|
+
getDefault(containerId: string): Promise<LLMProviderDefaultResponse>;
|
|
508
|
+
}
|
|
430
509
|
/**
|
|
431
510
|
* Presentation operations namespace
|
|
432
511
|
*/
|
|
@@ -464,6 +543,7 @@ interface AgentX {
|
|
|
464
543
|
readonly agent: AgentNamespace;
|
|
465
544
|
readonly session: SessionNamespace;
|
|
466
545
|
readonly presentation: PresentationNamespace;
|
|
546
|
+
readonly llm: LLMNamespace;
|
|
467
547
|
on<T extends string>(type: T, handler: BusEventHandler<BusEvent & {
|
|
468
548
|
type: T;
|
|
469
549
|
}>): Unsubscribe;
|
|
@@ -615,6 +695,12 @@ declare class CommandHandler {
|
|
|
615
695
|
private handleAgentDestroyAll;
|
|
616
696
|
private handleAgentInterrupt;
|
|
617
697
|
private handleMessageSend;
|
|
698
|
+
private handleLLMCreate;
|
|
699
|
+
private handleLLMGet;
|
|
700
|
+
private handleLLMList;
|
|
701
|
+
private handleLLMUpdate;
|
|
702
|
+
private handleLLMDelete;
|
|
703
|
+
private handleLLMDefault;
|
|
618
704
|
dispose(): void;
|
|
619
705
|
}
|
|
620
706
|
|
|
@@ -698,4 +784,4 @@ interface PlatformConfig {
|
|
|
698
784
|
*/
|
|
699
785
|
declare function createAgentX(config?: PlatformConfig): AgentXBuilder;
|
|
700
786
|
|
|
701
|
-
export { type AgentCreateResponse, type AgentGetResponse, type AgentInfo, type AgentListResponse, type AgentNamespace, type AgentX, type AgentXBuilder, type AgentXServer, type AssistantConversation, type BaseResponse, type Block, CommandHandler, type ConnectOptions, type ContainerCreateResponse, type ContainerGetResponse, type ContainerInfo, type ContainerListResponse, type ContainerNamespace, type Conversation, type ErrorConversation, type ImageBlock, type ImageCreateResponse, type ImageGetResponse, type ImageListResponse, type ImageNamespace, type ImageRecord, type MaybeAsync, type MessageSendResponse, type PlatformConfig, Presentation, type PresentationErrorHandler, type PresentationNamespace, type PresentationOptions, type PresentationState, type PresentationUpdateHandler, type ServeConfig, type ServerConfig, type SessionNamespace, type TextBlock, type ToolBlock, type UserConversation, addUserConversation, createAgentX, createInitialState, createServer, initialPresentationState, messagesToConversations, presentationReducer };
|
|
787
|
+
export { type AgentCreateResponse, type AgentGetResponse, type AgentInfo, type AgentListResponse, type AgentNamespace, type AgentX, type AgentXBuilder, type AgentXServer, type AssistantConversation, type BaseResponse, type Block, CommandHandler, type ConnectOptions, type ContainerCreateResponse, type ContainerGetResponse, type ContainerInfo, type ContainerListResponse, type ContainerNamespace, type Conversation, type ErrorConversation, type ImageBlock, type ImageCreateResponse, type ImageGetResponse, type ImageListResponse, type ImageNamespace, type ImageRecord, type LLMNamespace, type LLMProviderCreateResponse, type LLMProviderDefaultResponse, type LLMProviderGetResponse, type LLMProviderListResponse, type LLMProviderUpdateResponse, type MaybeAsync, type MessageSendResponse, type PlatformConfig, Presentation, type PresentationErrorHandler, type PresentationNamespace, type PresentationOptions, type PresentationState, type PresentationUpdateHandler, type ServeConfig, type ServerConfig, type SessionNamespace, type TextBlock, type ToolBlock, type UserConversation, addUserConversation, createAgentX, createInitialState, createServer, initialPresentationState, messagesToConversations, presentationReducer };
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
CommandHandler,
|
|
3
3
|
createServer
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-X44CQZPK.js";
|
|
5
5
|
|
|
6
6
|
// src/index.ts
|
|
7
7
|
import { createAgentXRuntime } from "@agentxjs/core/runtime";
|
|
@@ -251,6 +251,108 @@ function createRemoteImages(rpcClient, subscribeFn) {
|
|
|
251
251
|
};
|
|
252
252
|
}
|
|
253
253
|
|
|
254
|
+
// src/namespaces/llm.ts
|
|
255
|
+
import { generateId } from "@deepracticex/id";
|
|
256
|
+
function createLocalLLM(platform) {
|
|
257
|
+
const repo = platform.llmProviderRepository;
|
|
258
|
+
if (!repo) {
|
|
259
|
+
throw new Error("LLM provider repository not available on this platform");
|
|
260
|
+
}
|
|
261
|
+
return {
|
|
262
|
+
async create(params) {
|
|
263
|
+
const now = Date.now();
|
|
264
|
+
const record = {
|
|
265
|
+
id: generateId("llm"),
|
|
266
|
+
containerId: params.containerId,
|
|
267
|
+
name: params.name,
|
|
268
|
+
vendor: params.vendor,
|
|
269
|
+
protocol: params.protocol,
|
|
270
|
+
apiKey: params.apiKey,
|
|
271
|
+
baseUrl: params.baseUrl,
|
|
272
|
+
model: params.model,
|
|
273
|
+
isDefault: false,
|
|
274
|
+
createdAt: now,
|
|
275
|
+
updatedAt: now
|
|
276
|
+
};
|
|
277
|
+
await repo.saveLLMProvider(record);
|
|
278
|
+
return { record, requestId: "" };
|
|
279
|
+
},
|
|
280
|
+
async get(id) {
|
|
281
|
+
const record = await repo.findLLMProviderById(id);
|
|
282
|
+
return { record, requestId: "" };
|
|
283
|
+
},
|
|
284
|
+
async list(containerId) {
|
|
285
|
+
const records = await repo.findLLMProvidersByContainerId(containerId);
|
|
286
|
+
return { records, requestId: "" };
|
|
287
|
+
},
|
|
288
|
+
async update(id, updates) {
|
|
289
|
+
const existing = await repo.findLLMProviderById(id);
|
|
290
|
+
if (!existing) {
|
|
291
|
+
throw new Error(`LLM provider not found: ${id}`);
|
|
292
|
+
}
|
|
293
|
+
const updated = {
|
|
294
|
+
...existing,
|
|
295
|
+
...updates,
|
|
296
|
+
id: existing.id,
|
|
297
|
+
containerId: existing.containerId,
|
|
298
|
+
createdAt: existing.createdAt,
|
|
299
|
+
updatedAt: Date.now()
|
|
300
|
+
};
|
|
301
|
+
await repo.saveLLMProvider(updated);
|
|
302
|
+
return { record: updated, requestId: "" };
|
|
303
|
+
},
|
|
304
|
+
async delete(id) {
|
|
305
|
+
await repo.deleteLLMProvider(id);
|
|
306
|
+
return { requestId: "" };
|
|
307
|
+
},
|
|
308
|
+
async setDefault(id) {
|
|
309
|
+
await repo.setDefaultLLMProvider(id);
|
|
310
|
+
return { requestId: "" };
|
|
311
|
+
},
|
|
312
|
+
async getDefault(containerId) {
|
|
313
|
+
const record = await repo.findDefaultLLMProvider(containerId);
|
|
314
|
+
return { record, requestId: "" };
|
|
315
|
+
}
|
|
316
|
+
};
|
|
317
|
+
}
|
|
318
|
+
function createRemoteLLM(rpcClient) {
|
|
319
|
+
return {
|
|
320
|
+
async create(params) {
|
|
321
|
+
const result = await rpcClient.call("llm.create", params);
|
|
322
|
+
return { ...result, requestId: "" };
|
|
323
|
+
},
|
|
324
|
+
async get(id) {
|
|
325
|
+
const result = await rpcClient.call("llm.get", { id });
|
|
326
|
+
return { ...result, requestId: "" };
|
|
327
|
+
},
|
|
328
|
+
async list(containerId) {
|
|
329
|
+
const result = await rpcClient.call("llm.list", { containerId });
|
|
330
|
+
return { ...result, requestId: "" };
|
|
331
|
+
},
|
|
332
|
+
async update(id, updates) {
|
|
333
|
+
const result = await rpcClient.call("llm.update", {
|
|
334
|
+
id,
|
|
335
|
+
updates
|
|
336
|
+
});
|
|
337
|
+
return { ...result, requestId: "" };
|
|
338
|
+
},
|
|
339
|
+
async delete(id) {
|
|
340
|
+
const result = await rpcClient.call("llm.delete", { id });
|
|
341
|
+
return { ...result, requestId: "" };
|
|
342
|
+
},
|
|
343
|
+
async setDefault(id) {
|
|
344
|
+
const result = await rpcClient.call("llm.default", { id });
|
|
345
|
+
return { ...result, requestId: "" };
|
|
346
|
+
},
|
|
347
|
+
async getDefault(containerId) {
|
|
348
|
+
const result = await rpcClient.call("llm.default", {
|
|
349
|
+
containerId
|
|
350
|
+
});
|
|
351
|
+
return { ...result, requestId: "" };
|
|
352
|
+
}
|
|
353
|
+
};
|
|
354
|
+
}
|
|
355
|
+
|
|
254
356
|
// src/presentation/types.ts
|
|
255
357
|
var initialPresentationState = {
|
|
256
358
|
conversations: [],
|
|
@@ -735,6 +837,7 @@ var LocalClient = class {
|
|
|
735
837
|
agent;
|
|
736
838
|
session;
|
|
737
839
|
presentation;
|
|
840
|
+
llm;
|
|
738
841
|
constructor(runtime) {
|
|
739
842
|
this.runtime = runtime;
|
|
740
843
|
const platform = runtime.platform;
|
|
@@ -743,6 +846,7 @@ var LocalClient = class {
|
|
|
743
846
|
this.agent = createLocalAgents(runtime);
|
|
744
847
|
this.session = createLocalSessions(runtime);
|
|
745
848
|
this.presentation = createPresentations(this);
|
|
849
|
+
this.llm = createLocalLLM(platform);
|
|
746
850
|
logger.info("LocalClient initialized");
|
|
747
851
|
}
|
|
748
852
|
// ==================== Properties ====================
|
|
@@ -803,6 +907,7 @@ var RemoteClient = class {
|
|
|
803
907
|
agent;
|
|
804
908
|
session;
|
|
805
909
|
presentation;
|
|
910
|
+
llm;
|
|
806
911
|
constructor(config) {
|
|
807
912
|
this.config = config;
|
|
808
913
|
this.eventBus = new EventBusImpl();
|
|
@@ -823,6 +928,7 @@ var RemoteClient = class {
|
|
|
823
928
|
this.agent = createRemoteAgents(this.rpcClient);
|
|
824
929
|
this.session = createRemoteSessions(this.rpcClient);
|
|
825
930
|
this.presentation = createPresentations(this);
|
|
931
|
+
this.llm = createRemoteLLM(this.rpcClient);
|
|
826
932
|
}
|
|
827
933
|
// ==================== Properties ====================
|
|
828
934
|
get connected() {
|
|
@@ -908,6 +1014,9 @@ function createAgentX(config) {
|
|
|
908
1014
|
get presentation() {
|
|
909
1015
|
return getLocalClient().presentation;
|
|
910
1016
|
},
|
|
1017
|
+
get llm() {
|
|
1018
|
+
return getLocalClient().llm;
|
|
1019
|
+
},
|
|
911
1020
|
on(type, handler) {
|
|
912
1021
|
return getLocalClient().on(type, handler);
|
|
913
1022
|
},
|
|
@@ -948,7 +1057,7 @@ function createAgentX(config) {
|
|
|
948
1057
|
"serve() requires platform.channelServer. Ensure your platform supports server mode."
|
|
949
1058
|
);
|
|
950
1059
|
}
|
|
951
|
-
const { createServer: createServer2 } = await import("./server-
|
|
1060
|
+
const { createServer: createServer2 } = await import("./server-BWI5JE4B.js");
|
|
952
1061
|
return createServer2({
|
|
953
1062
|
platform: config.platform,
|
|
954
1063
|
createDriver: config.createDriver,
|