{"_id":"@aotui/agent-driver-v2","_rev":"3-8d8b531ac8ec2818777feb64194c3756","name":"@aotui/agent-driver-v2","dist-tags":{"latest":"0.2.2"},"versions":{"0.2.0":{"name":"@aotui/agent-driver-v2","version":"0.2.0","keywords":["aotui","agent","llm","ai-sdk","tool-call"],"license":"Apache-2.0","_id":"@aotui/agent-driver-v2@0.2.0","maintainers":[{"name":"johnnyzhang.agentina","email":"waynezhang.luck@gmail.com"}],"dist":{"shasum":"5a40638b09fba97a464850d837820e51ca2424dc","tarball":"https://registry.npmjs.org/@aotui/agent-driver-v2/-/agent-driver-v2-0.2.0.tgz","fileCount":16,"integrity":"sha512-BHNNUwoda4hpXlpdPHnXD1CBYFKCDiaavO+rpjgviOoIHCcIHE8viNRNkmT+e+QrBv48qVKIPPRV/pjxQ6U6Jw==","signatures":[{"sig":"MEYCIQD0V3UPDJ5HWF7296CBs7XK7KcPCw5ZMS9P5K/PSBaOgwIhANn4ujW9NswKrnv0JOoYWJXHiopyxy/KbH+Xm2LELY4Y","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":74865},"main":"./dist/index.js","type":"module","types":"./dist/index.d.ts","gitHead":"4cbcf3b94841b47eff4635949984b0ddeb49bee7","scripts":{"dev":"tsc --watch","test":"vitest","build":"tsc","test:coverage":"vitest --coverage","prepublishOnly":"npm run build"},"_npmUser":{"name":"johnnyzhang.agentina","email":"waynezhang.luck@gmail.com"},"_npmVersion":"10.9.2","description":"AOTUI Agent Driver V2 - Multi-source message aggregator for LLM","directories":{},"_nodeVersion":"23.11.0","dependencies":{"ai":"^6.0.77","@ai-sdk/xai":"^3.0.48","@ai-sdk/google":"^3.0.22","@ai-sdk/openai":"^3.0.26","@ai-sdk/deepseek":"^1.0.4","@ai-sdk/anthropic":"^3.0.39","zod-to-json-schema":"^3.25.1","@ai-sdk/openai-compatible":"^2.0.28","@openrouter/ai-sdk-provider":"^2.2.3"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"vitest":"^1.2.0","typescript":"^5.3.0","@types/node":"^20.0.0"},"_npmOperationalInternal":{"tmp":"tmp/agent-driver-v2_0.2.0_1772620613990_0.22702751505549057","host":"s3://npm-registry-packages-npm-production"}},"0.2.1":{"name":"@aotui/agent-driver-v2","version":"0.2.1","keywords":["aotui","agent","llm","ai-sdk","tool-call"],"license":"Apache-2.0","_id":"@aotui/agent-driver-v2@0.2.1","maintainers":[{"name":"johnnyzhang.agentina","email":"waynezhang.luck@gmail.com"}],"dist":{"shasum":"60bd62d56806e4e23a0a9b65562e4cad198edb4d","tarball":"https://registry.npmjs.org/@aotui/agent-driver-v2/-/agent-driver-v2-0.2.1.tgz","fileCount":16,"integrity":"sha512-4F+wpjQg43qj1Mb4m3YrszMQymxr8t/krhkVP9dWih4Z8O1P0aBeVnjchCM2I6UQJaGVVyWJ/C5YoaAppmrt1Q==","signatures":[{"sig":"MEQCICunGOOXQm6S2KPHL8ePXoi8PPdslCKOjSLTWogNKDU2AiA1Mxu4QGXttqGMViFueTWiDkeGDOGv9M9QGwIqArwJLg==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":74854},"main":"./dist/index.js","type":"module","types":"./dist/index.d.ts","gitHead":"c9e13c0e57383cc86e5e8511580c9d147f08d749","scripts":{"dev":"tsc --watch","test":"vitest","build":"tsc","test:coverage":"vitest --coverage","prepublishOnly":"npm run build"},"_npmUser":{"name":"johnnyzhang.agentina","email":"waynezhang.luck@gmail.com"},"_npmVersion":"10.9.2","description":"AOTUI Agent Driver V2 - Multi-source message aggregator for LLM","directories":{},"_nodeVersion":"23.11.0","dependencies":{"ai":"^6.0.77","@ai-sdk/xai":"^3.0.48","@ai-sdk/google":"^3.0.22","@ai-sdk/openai":"^3.0.26","@ai-sdk/deepseek":"^1.0.4","@ai-sdk/anthropic":"^3.0.39","zod-to-json-schema":"^3.25.1","@ai-sdk/openai-compatible":"^2.0.28","@openrouter/ai-sdk-provider":"^2.2.3"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"vitest":"^1.2.0","typescript":"^5.3.0","@types/node":"^20.0.0"},"_npmOperationalInternal":{"tmp":"tmp/agent-driver-v2_0.2.1_1772785300162_0.730898217095177","host":"s3://npm-registry-packages-npm-production"}},"0.2.2":{"name":"@aotui/agent-driver-v2","version":"0.2.2","description":"AOTUI Agent Driver V2 - Multi-source message aggregator for LLM","type":"module","main":"./dist/index.js","types":"./dist/index.d.ts","scripts":{"build":"tsc","dev":"tsc --watch","test":"vitest","test:coverage":"vitest --coverage","prepublishOnly":"npm run build"},"dependencies":{"@ai-sdk/anthropic":"^3.0.39","@ai-sdk/deepseek":"^1.0.4","@ai-sdk/google":"^3.0.22","@ai-sdk/openai":"^3.0.26","@ai-sdk/openai-compatible":"^2.0.28","@ai-sdk/xai":"^3.0.48","@openrouter/ai-sdk-provider":"^2.2.3","ai":"^6.0.77","zod-to-json-schema":"^3.25.1"},"devDependencies":{"@types/node":"^20.0.0","typescript":"^5.3.0","vitest":"^1.2.0"},"keywords":["aotui","agent","llm","ai-sdk","tool-call"],"license":"Apache-2.0","publishConfig":{"access":"public"},"_id":"@aotui/agent-driver-v2@0.2.2","gitHead":"4cb8d553a7ef49b5b842f3423ceefedce89b8b27","_nodeVersion":"23.11.0","_npmVersion":"10.9.2","dist":{"integrity":"sha512-Amk2SRJfu11CpUsWM41+FcRmyX4rOGSrIznjiKPQnLAyUl2hag9uQeJRgeQ8lA3DbDqBGGht6p6c1LwMnkneWQ==","shasum":"44125b267e23acf65d022a43ffc65d4c18419319","tarball":"https://registry.npmjs.org/@aotui/agent-driver-v2/-/agent-driver-v2-0.2.2.tgz","fileCount":16,"unpackedSize":74865,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQDz0cN3dNnPGZqy+P3tn7x2Iz5GOGIp/UWrMzbweGfv1wIgZz7UNGgBDmp/nms0Ll+ggrYrKctRTxRJoGoWI6fHVTE="}]},"_npmUser":{"name":"johnnyzhang.agentina","email":"waynezhang.luck@gmail.com"},"directories":{},"maintainers":[{"name":"johnnyzhang.agentina","email":"waynezhang.luck@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/agent-driver-v2_0.2.2_1773318687682_0.811298694943015"},"_hasShrinkwrap":false}},"time":{"created":"2026-03-04T10:36:53.822Z","modified":"2026-03-12T12:31:28.046Z","0.2.0":"2026-03-04T10:36:54.137Z","0.2.1":"2026-03-06T08:21:40.310Z","0.2.2":"2026-03-12T12:31:27.915Z"},"license":"Apache-2.0","keywords":["aotui","agent","llm","ai-sdk","tool-call"],"description":"AOTUI Agent Driver V2 - Multi-source message aggregator for LLM","maintainers":[{"name":"johnnyzhang.agentina","email":"waynezhang.luck@gmail.com"}],"readme":"# @aotui/agent-driver-v2\n\n多源消息聚合器，用于整合 AOTUI Runtime 和 Host 的消息和工具，发送给 LLM。\n\n## 特性\n\n- **多源聚合**: 支持多个 DrivenSource（AOTUI、Host 等）\n- **时间戳排序**: 自动按时间戳排序来自不同源的消息\n- **ToolCall 路由**: 根据 Tool 来源自动路由执行\n- **类型安全**: 基于 Vercel AI SDK v6，全程 TypeScript\n- **Provider 支持**: 支持 OpenAI、Anthropic、Google、xAI 等主流 LLM Provider\n\n## 架构\n\n```\n┌─────────────────────────────────────┐\n│      AgentDriver V2                 │\n│                                     │\n│  ┌───────────────────────────────┐ │\n│  │  Messages (sorted)            │ │\n│  │  - AOTUI Snapshots            │ │\n│  │  - Host Messages              │ │\n│  └───────────────────────────────┘ │\n│                                     │\n│  ┌───────────────────────────────┐ │\n│  │  Tools                        │ │\n│  │  - AOTUI Operations           │ │\n│  │  - (Future: Other Tools)      │ │\n│  └───────────────────────────────┘ │\n│                                     │\n│  ┌───────────────────────────────┐ │\n│  │  ToolCall Router              │ │\n│  │  → Find DrivenSource          │ │\n│  │  → Execute Tool               │ │\n│  └───────────────────────────────┘ │\n└─────────────────────────────────────┘\n           ↓\n      LLM (Vercel AI SDK)\n```\n\n## API\n\n### IDrivenSource 接口\n\n每个 DrivenSource 需要实现以下接口：\n\n```typescript\ninterface IDrivenSource {\n  readonly name: string;\n  getMessages(): Promise<MessageWithTimestamp[]>;\n  getTools(): Promise<Record<string, CoreTool>>;\n  executeTool(toolName: string, args: unknown, toolCallId: string): Promise<ToolResult | undefined>;\n  onUpdate(callback: () => void): () => void;\n}\n```\n\n### 实现位置\n\n- `IDrivenSource` 接口: `agent-driver-v2/src/core/interfaces.ts`\n- `AOTUIDrivenSource`: `runtime/src/adapters/aotui-driven-source.ts`\n- `HostDrivenSource`: `host/src/adapters/host-driven-source.ts`\n\n## 使用示例\n\n### 基本用法\n\n```typescript\nimport { AgentDriverV2 } from '@aotui/agent-driver-v2';\nimport { AOTUIDrivenSource } from '@aotui/runtime';\nimport { HostDrivenSource } from './host';\n\nconst driver = new AgentDriverV2({\n  sources: [\n    new AOTUIDrivenSource(desktop, kernel),\n    new HostDrivenSource(messageRepo)\n  ],\n  llm: {\n    model: 'openai:gpt-4',  // 格式: \"providerId:modelId\"\n    apiKey: process.env.OPENAI_API_KEY,\n    temperature: 0.7,\n    maxSteps: 10\n  },\n  workLoop: {\n    debounceMs: 300,\n    toolCallTimeoutMs: 30000\n  },\n  onAssistantMessage: (message) => {\n    console.log('LLM response:', message);\n  },\n  onToolResult: (message) => {\n    console.log('Tool executed:', message);\n  }\n});\n\n// 运行工作循环（自动触发，当有更新信号时）\n// 或手动触发\nawait driver.trigger();\n```\n\n### LLM 配置格式\n\nAgentDriverV2 支持灵活的 LLM 配置格式：\n\n```typescript\n// 格式 1: 简单格式（自动推断 Provider）\nconst config: LLMConfig = {\n  model: 'gpt-4',  // 自动推断为 openai\n};\n\n// 格式 2: 显式指定 Provider\nconst config: LLMConfig = {\n  model: 'openai:gpt-4',  // 使用冒号分隔\n};\n\n// 格式 3: 自定义 Provider 配置\nconst config: LLMConfig = {\n  model: 'anthropic:claude-3-5-sonnet-20241022',\n  provider: {\n    id: 'anthropic',\n    baseURL: 'https://api.anthropic.com',  // 可选\n  },\n  apiKey: process.env.ANTHROPIC_API_KEY,\n  temperature: 0.7,\n  maxSteps: 10,\n};\n\n// 格式 4: 使用 OpenRouter\nconst config: LLMConfig = {\n  model: 'meta-llama/llama-4-scout-17b-16e-instruct',\n  provider: {\n    id: 'openrouter',\n    baseURL: 'https://openrouter.ai/api/v1',\n  },\n  apiKey: process.env.OPENROUTER_API_KEY,\n};\n```\n\n### 支持的 Provider\n\n- **OpenAI**: `openai:gpt-4`, `openai:gpt-4-turbo`\n- **Anthropic**: `anthropic:claude-3-5-sonnet-20241022`\n- **Google**: `google:gemini-2.5-flash`\n- **xAI**: `xai:grok-beta`\n- **自定义**: 任何 OpenAI 兼容的 API（通过 `provider.baseURL` 配置）\n\n## 迁移指南\n\n### 从旧版本迁移\n\n如果你之前使用 ModelRegistry，现在需要改为直接传递完整的 LLMConfig：\n\n**之前（使用 ModelRegistry）：**\n\n```typescript\nimport { AgentDriverV2, ModelRegistry } from '@aotui/agent-driver-v2';\n\nconst registry = new ModelRegistry();\nconst driver = new AgentDriverV2({\n  sources: [...],\n  llm: {\n    model: 'gpt-4',\n  },\n  // ModelRegistry 会自动注入\n});\n```\n\n**现在（直接配置）：**\n\n```typescript\nimport { AgentDriverV2 } from '@aotui/agent-driver-v2';\n\nconst driver = new AgentDriverV2({\n  sources: [...],\n  llm: {\n    model: 'openai:gpt-4',  // 需要包含 provider 前缀\n    apiKey: process.env.OPENAI_API_KEY,  // 需要显式提供 API Key\n    temperature: 0.7,\n    maxSteps: 10,\n  },\n});\n```\n\n**关键变化：**\n\n1. **ModelRegistry 已移除**: 不再从 `@aotui/agent-driver-v2` 导出\n2. **完整配置**: LLMConfig 需要包含所有必要字段（model, apiKey, provider 等）\n3. **Model 格式**: 推荐使用 `providerId:modelId` 格式（如 `openai:gpt-4`）\n4. **API Key**: 需要显式提供或通过环境变量设置\n\n### 在 Host 应用中使用\n\n如果你在 Host 应用中使用 AgentDriverV2，应该通过 LLMConfigService 获取配置：\n\n```typescript\nimport { HostManagerV2 } from '@aotui/host';\n\nconst hostManager = new HostManagerV2(topicId, modelRegistry);\n\n// LLMConfigService 会自动从 ModelRegistry 获取配置\n// 并转换为完整的 LLMConfig\nhostManager.initAgentDriver(desktop, kernel);\n```\n\n## 环境变量\n\nAgentDriverV2 支持从环境变量自动读取 API Key：\n\n- `OPENAI_API_KEY`: OpenAI API Key\n- `ANTHROPIC_API_KEY`: Anthropic API Key\n- `GOOGLE_API_KEY`: Google AI API Key\n- `XAI_API_KEY`: xAI API Key\n\n如果在 LLMConfig 中没有提供 `apiKey`，会自动从对应的环境变量读取。\n\n## 下一步\n\n- [x] 实现完整的 LLM ReAct 循环 (streamText)\n- [x] 添加 ToolCall 超时机制\n- [x] 添加单元测试\n- [x] 实现 AOTUIDrivenSource (在 runtime 中)\n- [x] 实现 HostDrivenSource (在 host 中)\n- [x] 移除 ModelRegistry 依赖（迁移到 Host 主进程）\n\n","readmeFilename":"README.md"}