@h-ai/ai 1.0.0-beta.23 → 1.0.0-beta.24

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.
Files changed (41) hide show
  1. package/README.en.md +145 -141
  2. package/README.ja.md +145 -141
  3. package/README.md +143 -141
  4. package/dist/{ai-acp-types-BNeA1j0P.d.ts → ai-acp-types-B99Oa7WD.d.ts} +2242 -233
  5. package/dist/browser.d.ts +3 -1
  6. package/dist/browser.js +3 -3
  7. package/dist/{chunk-CCXG2S7O.js → chunk-3G4ZLXH4.js} +154 -9
  8. package/dist/chunk-3G4ZLXH4.js.map +1 -0
  9. package/dist/{chunk-WSH2246H.js → chunk-3R5SMLSJ.js} +3 -3
  10. package/dist/{chunk-WSH2246H.js.map → chunk-3R5SMLSJ.js.map} +1 -1
  11. package/dist/{chunk-M77C3VAP.js → chunk-NRDLMUSY.js} +4 -2
  12. package/dist/chunk-NRDLMUSY.js.map +1 -0
  13. package/dist/client/index.js +2 -2
  14. package/dist/index.d.ts +4 -2
  15. package/dist/index.js +2492 -593
  16. package/dist/index.js.map +1 -1
  17. package/models/agents/README.md +30 -18
  18. package/models/agents/build.mjs +158 -55
  19. package/models/agents/codex-acp/Dockerfile +8 -13
  20. package/models/agents/deepseek-harness/Dockerfile +8 -13
  21. package/models/agents/goose/Dockerfile +8 -13
  22. package/models/agents/goose/agent.json +1 -1
  23. package/package.json +11 -8
  24. package/tools/.dockerignore +4 -0
  25. package/tools/README.md +74 -0
  26. package/tools/archives.py +56 -0
  27. package/tools/browser/Dockerfile +19 -0
  28. package/tools/browser/operation.py +50 -0
  29. package/tools/browser/render.mjs +40 -0
  30. package/tools/documents/Dockerfile +20 -0
  31. package/tools/documents/operation.py +80 -0
  32. package/tools/ocr/Dockerfile +19 -0
  33. package/tools/ocr/operation.py +18 -0
  34. package/tools/office/Dockerfile +21 -0
  35. package/tools/office/office_job.py +65 -0
  36. package/tools/office/operation.py +43 -0
  37. package/tools/tests/image-smoke.mjs +83 -0
  38. package/tools/tests/test_hai_tool.py +82 -0
  39. package/tools/tool.py +145 -0
  40. package/dist/chunk-CCXG2S7O.js.map +0 -1
  41. package/dist/chunk-M77C3VAP.js.map +0 -1
package/README.en.md CHANGED
@@ -49,146 +49,148 @@ Unless marked direct, AsyncIterable or a direct Promise value, the output column
49
49
 
50
50
  Call fragments reuse the initialized service from this page. Named variables stand for application-provided requests, schemas, resource definitions or options. Follow the corresponding examples for setup and failure handling. Check HaiResult.success and await asynchronous calls.
51
51
 
52
- | Entry | Use case | Input | Output | Call fragment |
53
- | --------------------------------- | ---------------------------- | --------------------------------------------------------------------------------- | ------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------- |
54
- | `ai.llm.chat` | Single answer | `ChatCompletionRequest: messages, model?, signal?, tools?` | `ChatCompletionResponse: choices, model, usage?` | `ai.llm.chat({ messages: [{ role: "user", content: "你好" }] })` |
55
- | `ai.llm.chatStream` | Stream completion | `same ChatCompletionRequest` | `AsyncIterable<ChatCompletionChunk>; iteration may throw` | `ai.llm.chatStream({ messages })` |
56
- | `ai.llm.ask` | Text answer | `question: string, AskOptions?` | `string answer` | `ai.llm.ask("解释共享状态")` |
57
- | `ai.llm.askStream` | Text stream | `question: string, AskOptions?` | `AsyncIterable<string>` | `ai.llm.askStream("解释共享状态")` |
58
- | `ai.llm.generateObject` | Schema-constrained answer | `Zod schema, messages, model?, maxRepairs?, signal?` | `schema-inferred T` | `ai.llm.generateObject({ schema: AnswerSchema, messages })` |
59
- | `ai.llm.listModels` | List models | `none` | `string[] model IDs` | `ai.llm.listModels()` |
60
- | `ai.llm.getHistory` | Read history | `{ objectId, sessionId }, { limit?, order? }?` | `ChatRecord[]` | `ai.llm.getHistory({ objectId: "u1", sessionId: "s1" })` |
61
- | `ai.llm.listSessions` | Subject sessions | `objectId: string` | `SessionInfo[]` | `ai.llm.listSessions("u1")` |
62
- | `ai.tools.define` | Define a tool | `{ name, description, parameters: Zod schema, handler, timeoutMs? }` | `direct Tool<TInput,TOutput>; no init required` | `ai.tools.define(toolDefinition)` |
63
- | `ai.tools.createRegistry` | Create tool registry | `{ authorize? }?` | `direct ToolRegistryOperations; no init required` | `ai.tools.createRegistry({ authorize })` |
64
- | `ai.stream.createProcessor` | Accumulate chunks | `none` | `direct StreamProcessor` | `ai.stream.createProcessor()` |
65
- | `ai.stream.collect` | Consume a chat stream | `AsyncIterable<ChatCompletionChunk>` | `Promise<StreamResult>; stream failure rejects` | `ai.stream.collect(ai.llm.chatStream({ messages }))` |
66
- | `ai.stream.createSSEDecoder` | Decode split SSE | `none` | `direct SSEDecoder with decode/reset` | `ai.stream.createSSEDecoder()` |
67
- | `ai.stream.encodeSSE` | Encode SSE | `SSEEvent: data, event?, id?, retry?` | `direct string; invalid metadata throws` | `ai.stream.encodeSSE({ data: "Hello" })` |
68
- | `ai.embedding.embed` | Embedding request | `EmbeddingRequest with input/model?` | `EmbeddingResponse` | `ai.embedding.embed({ input: "产品说明" })` |
69
- | `ai.embedding.embedText` | Embed one text | `text: string` | `number[]` | `ai.embedding.embedText("产品说明")` |
70
- | `ai.embedding.embedBatch` | Embed many texts | `texts: string[]` | `number[][] in input order` | `ai.embedding.embedBatch(["简介", "部署"])` |
71
- | `ai.mcp.registerTool` | Register local tool | `MCPToolDefinition, typed handler` | `void` | `ai.mcp.registerTool(mcpToolDefinition, toolHandler)` |
72
- | `ai.mcp.registerResource` | Register resource | `MCPResource, async content handler` | `void` | `ai.mcp.registerResource(resourceDefinition, readContent)` |
73
- | `ai.mcp.registerPrompt` | Register prompt | `MCPPrompt, args => Promise<MCPPromptMessage[]>` | `void` | `ai.mcp.registerPrompt(promptDefinition, buildMessages)` |
74
- | `ai.mcp.callTool` | Call local tool | `name, arguments, MCPContext?` | `unknown tool result` | `ai.mcp.callTool("search", { query: "配置" })` |
75
- | `ai.mcp.readResource` | Read resource | `resource URI` | `MCPResourceContent with exactly text or blob` | `ai.mcp.readResource("docs://intro")` |
76
- | `ai.mcp.getPrompt` | Build prompt | `name, Record<string,string> arguments` | `MCPPromptMessage[]` | `ai.mcp.getPrompt("review", { topic: "API" })` |
77
- | `ai.retrieval.addSource` | Register source | `RetrievalSource: id, collection, optional metadata` | `void` | `ai.retrieval.addSource({ id: "docs", collection: "manual" })` |
78
- | `ai.retrieval.removeSource` | Remove source | `sourceId: string` | `void` | `ai.retrieval.removeSource("docs")` |
79
- | `ai.retrieval.listSources` | List sources | `none` | `direct Promise<RetrievalSource[]>` | `ai.retrieval.listSources()` |
80
- | `ai.retrieval.retrieve` | Retrieve candidates | `RetrievalRequest: query, sources?, topK?, minScore?, enableRerank?` | `RetrievalResult` | `ai.retrieval.retrieve({ query: "部署" })` |
81
- | `ai.rag.query` | Grounded answer | `query: string, RagOptions?` | `RagResult: answer, context, citations, query, model` | `ai.rag.query("如何部署?", { sources: ["docs"] })` |
82
- | `ai.rag.queryStream` | Grounded stream | `query: string, RagOptions?` | `AsyncIterable<RagStreamEvent>` | `ai.rag.queryStream("如何部署?", { sources: ["docs"] })` |
83
- | `ai.knowledge.setup` | Prepare collection | `KnowledgeSetupOptions?` | `void; collection ready for ingest` | `ai.knowledge.setup()` |
84
- | `ai.knowledge.ingest` | Publish document | `{ documentId, content, title?, collection?, ...metadata }` | `KnowledgeIngestResult with revision/cleanupPending` | `ai.knowledge.ingest({ documentId: "intro", content: "入门正文" })` |
85
- | `ai.knowledge.ingestFile` | Ingest a file | `KnowledgeIngestFileInput including file bytes and document identity` | `KnowledgeIngestResult` | `ai.knowledge.ingestFile(fileInput)` |
86
- | `ai.knowledge.ingestBatch` | Ingest batch | `KnowledgeIngestInput[], onProgress?` | `KnowledgeIngestBatchResult with per-document outcomes` | `ai.knowledge.ingestBatch(documentInputs, onProgress)` |
87
- | `ai.knowledge.retrieve` | Retrieve published revision | `query: string, KnowledgeRetrieveOptions?` | `KnowledgeRetrieveResult` | `ai.knowledge.retrieve("部署说明")` |
88
- | `ai.knowledge.ask` | Answer from knowledge | `query: string, KnowledgeAskOptions?` | `KnowledgeAskResult` | `ai.knowledge.ask("如何恢复备份?")` |
89
- | `ai.knowledge.findByEntity` | Find by entity | `entityName: string, EntityQueryOptions?` | `EntityDocumentResult[]` | `ai.knowledge.findByEntity("订单")` |
90
- | `ai.knowledge.listEntities` | List entities | `EntityListOptions?` | `KnowledgeEntity[]` | `ai.knowledge.listEntities()` |
91
- | `ai.knowledge.listDocuments` | List documents | `KnowledgeDocumentListOptions?` | `KnowledgeDocumentInfo[]` | `ai.knowledge.listDocuments()` |
92
- | `ai.knowledge.removeDocument` | Remove document | `documentId, KnowledgeDocumentRemoveOptions?` | `void; may fail after visibility revocation if cleanup fails` | `ai.knowledge.removeDocument("intro")` |
93
- | `ai.knowledge.repair` | Repair cleanup | `{ collection?, offset?, limit? }` | `KnowledgeRepairResult with progress` | `ai.knowledge.repair({ offset: 0, limit: 100 })` |
94
- | `ai.knowledge.deleteCollection` | Remove collection | `collection name?` | `void; cleanup tombstone remains` | `ai.knowledge.deleteCollection("retired-manual")` |
95
- | `ai.memory.scoped` | Bind trusted subject | `{ objectId: nonempty string, scope? }` | `direct ScopedMemoryOperations; invalid binding throws TypeError` | `ai.memory.scoped({ objectId: "u1", scope: { topicId: "orders" } })` |
96
- | `ai.memory.extract` | Extract memories | `ChatMessage[], { objectId, scope?, model?, signal?, ...options }` | `MemoryEntry[]` | `ai.memory.extract(messages, { objectId: "u1" })` |
97
- | `ai.memory.add` | Store explicit memory | `MemoryEntryInput: objectId, content, type, scope?` | `MemoryEntry` | `ai.memory.add({ objectId: "u1", content: "偏好中文", type: "preference" })` |
98
- | `ai.memory.get` | Read owned memory | `memoryId, { objectId, scope? } for untrusted IDs` | `MemoryEntry` | `ai.memory.get(memoryId, { objectId: "u1" })` |
99
- | `ai.memory.update` | Update memory | `memoryId, MemoryUpdateInput, trusted access scope` | `MemoryEntry` | `ai.memory.update(memoryId, { content: "偏好日文" }, { objectId: "u1" })` |
100
- | `ai.memory.remove` | Remove owned memory | `memoryId, trusted access scope` | `void` | `ai.memory.remove(memoryId, { objectId: "u1" })` |
101
- | `ai.memory.recall` | Recall memories | `query, { objectId, scope?, topK?, types?, ...options }` | `MemoryEntry[]` | `ai.memory.recall("语言偏好", { objectId: "u1" })` |
102
- | `ai.memory.injectMemories` | Enrich messages | `ChatMessage[], { objectId, scope?, topK?, ...options }` | `ChatMessage[]` | `ai.memory.injectMemories(messages, { objectId: "u1" })` |
103
- | `ai.memory.list` | List memories | `MemoryListOptions with objectId/scope filters` | `MemoryEntry[]; incomplete scan fails` | `ai.memory.list({ objectId: "u1" })` |
104
- | `ai.memory.listPage` | Page memories | `MemoryListPageOptions with objectId/pagination` | `StorePage<MemoryEntry>` | `ai.memory.listPage({ objectId: "u1", offset: 0, limit: 20 })` |
105
- | `ai.memory.clear` | Clear selected scope | `nonempty MemoryClearOptions` | `void; empty filters are rejected` | `ai.memory.clear({ objectId: "u1" })` |
106
- | `ai.memory.admin.clearAll` | Trusted administrator clear | `{ confirm: true }; require host administrator authorization` | `void; destructive across subjects` | `ai.memory.admin.clearAll({ confirm: true })` |
107
- | `ai.persona.save` | Save persona | `PersonaProfileInput: id, name, systemPrompt, objectId?, traits?` | `PersonaProfile` | `ai.persona.save(personaProfile)` |
108
- | `ai.persona.get` | Get persona | `id, { objectId }?; omitted subject selects system profile` | `PersonaProfile` | `ai.persona.get("tutor", { objectId: "u1" })` |
109
- | `ai.persona.update` | Update persona | `id, PersonaProfileUpdate, { objectId }?` | `PersonaProfile` | `ai.persona.update("tutor", updates, { objectId: "u1" })` |
110
- | `ai.persona.remove` | Remove persona | `id, { objectId }?` | `void` | `ai.persona.remove("tutor", { objectId: "u1" })` |
111
- | `ai.persona.list` | List personas | `{ objectId }?` | `PersonaProfile[]` | `ai.persona.list({ objectId: "u1" })` |
112
- | `ai.persona.compose` | Compose system prompt | `id, { objectId }?` | `string prompt` | `ai.persona.compose("tutor", { objectId: "u1" })` |
113
- | `ai.token.estimateText` | Estimate text tokens | `text: string` | `direct number; estimate, not billing usage` | `ai.token.estimateText("Hello 世界")` |
114
- | `ai.token.estimateMessages` | Estimate message tokens | `ChatMessage[]` | `direct number including protocol overhead` | `ai.token.estimateMessages(messages)` |
115
- | `ai.summary.generate` | Generate summary text | `ChatMessage[], SummaryOptions?` | `string` | `ai.summary.generate(messages)` |
116
- | `ai.summary.summarize` | Summary metadata | `ChatMessage[], SummaryOptions?` | `{ summary, tokenCount, coveredMessages }` | `ai.summary.summarize(messages)` |
117
- | `ai.compress.tryCompress` | Compress to budget | `ChatMessage[], { strategy?, maxTokens?, preserveLastN?, ...options }` | `CompressResult: messages and original/compressed token counts` | `ai.compress.tryCompress(messages, { maxTokens: 4000 })` |
118
- | `ai.context.createManager` | Create context | `ContextManagerOptions with scope { objectId, sessionId }` | `ContextManager` | `ai.context.createManager({ scope: { objectId: "u1", sessionId: "s1" } })` |
119
- | `ai.context.restoreManager` | Restore context | `{ objectId, sessionId }, options?` | `ContextManager` | `ai.context.restoreManager({ objectId: "u1", sessionId: "s1" })` |
120
- | `ai.context.listSessions` | List stored sessions | `objectId` | `SessionInfo[]` | `ai.context.listSessions("u1")` |
121
- | `ai.context.renameSession` | Rename session | `scope, title` | `void` | `ai.context.renameSession({ objectId: "u1", sessionId: "s1" }, "订单讨论")` |
122
- | `ai.context.removeSession` | Remove session | `scope` | `void; tombstone prevents scope reuse` | `ai.context.removeSession({ objectId: "u1", sessionId: "s1" })` |
123
- | `ai.rerank.rerank` | Rerank documents | `RerankRequest: query, documents, model?, topN?` | `RerankResponse with model/results` | `ai.rerank.rerank({ query: "部署", documents: ["配置说明"] })` |
124
- | `ai.rerank.rerankTexts` | Rerank texts | `query, string[] texts, topN?` | `RerankItem[] with index/relevanceScore` | `ai.rerank.rerankTexts("部署", ["配置说明"], 1)` |
125
- | `ai.file.parse` | Parse a file | `FileParseRequest with content, filename, options?` | `FileParseResult; extraction is not HTML sanitization` | `ai.file.parse({ content: "<p>正文</p>", filename: "intro.html" })` |
126
- | `ai.file.parseText` | Extract plain text | `Buffer\|string content, filename?` | `string` | `ai.file.parseText("Hello", "intro.txt")` |
127
- | `ai.reasoning.run` | Multistep reasoning | `query, ReasoningOptions including strategy/tools?` | `ReasoningResult` | `ai.reasoning.run("审查方案", { strategy: "cot" })` |
128
- | `ai.reasoning.runStream` | Observe reasoning stream | `query, ReasoningOptions?` | `AsyncIterable<ReasoningStreamEvent>` | `ai.reasoning.runStream("审查方案", { strategy: "react" })` |
129
- | `ai.audio.transcribe` | Transcribe audio | `TranscriptionRequest: audio, language?, model?, signal?` | `TranscriptionResult: text, language?, segments?` | `ai.audio.transcribe({ audio: { data: wavBytes, format: "wav" } })` |
130
- | `ai.audio.transcribeStream` | Stream transcription | `TranscriptionStreamRequest: chunks or complete audio` | `AsyncIterable<TranscriptionEvent>` | `ai.audio.transcribeStream(transcriptionInput)` |
131
- | `ai.audio.synthesize` | Synthesize audio | `SynthesisRequest: text, language?, model?, signal?` | `SynthesisResult: audio and duration metadata` | `ai.audio.synthesize({ text: "你好" })` |
132
- | `ai.audio.synthesizeStream` | Synthesize segments | `SynthesisStreamRequest: text segment or async segments` | `AsyncIterable<SynthesisEvent>` | `ai.audio.synthesizeStream(synthesisInput)` |
133
- | `ai.audio.getCapabilities` | Inspect capabilities | `{ operation: transcribe\|synthesize, model? }` | `AudioModelCapabilities` | `ai.audio.getCapabilities({ operation: "synthesize" })` |
134
- | `ai.image.generate` | Generate images | `{ prompt, referenceImages?, model?, size?, signal? }` | `{ images: GeneratedImage[] } with bytes/MIME` | `ai.image.generate({ prompt: "一座灯塔" })` |
135
- | `ai.a2a.registerExecutor` | Register executor | `SDK AgentExecutor` | `void` | `ai.a2a.registerExecutor(executor)` |
136
- | `ai.a2a.getAgentCard` | Agent discovery | `none; configured a2a card` | `A2AAgentCardDocument (A2A 1.0 ProtoJSON)` | `ai.a2a.getAgentCard()` |
137
- | `ai.a2a.handleRequest` | Handle protocol request | `unknown JSON-RPC body, trusted context.agentId?` | `direct Promise<A2AHandleResult>; JSON-RPC/SSE outcome` | `ai.a2a.handleRequest(body, { agentId: trustedAgentId })` |
138
- | `ai.a2a.listMessages` | Administrative message query | `A2ATaskFilter: callerId?, contextId?, since?, pagination?` | `StorePage<A2AMessageRecord>` | `ai.a2a.listMessages(messageFilter)` |
139
- | `ai.a2a.callRemoteAgent` | Call approved remote agent | `allowlisted HTTPS URL, message, A2ACallOptions?` | `A2ACallResult` | `ai.a2a.callRemoteAgent("https://agent.example.com/a2a", "请分析订单")` |
140
- | `ai.init` | Initialize service | `AIConfigInput?, AIInitOptions?` | `HaiResult<void>; validate dependencies before use` | `ai.init({ llm: { apiKey: process.env.HAI_AI_LLM_APIKEY } })` |
141
- | `ai.close` | Release service | `none` | `Promise<void>; wait for cleanup` | `ai.close()` |
142
- | `ai.config` | Read safe config | `none` | `redacted AIConfig or null` | `ai.config` |
143
- | `ai.isInitialized` | Check lifecycle | `none` | `boolean` | `ai.isInitialized` |
144
- | `ai.llm.models.list` | List merged definitions | `none` | `HaiResult<AIResourceEntry[]>; config wins, list has no database version` | `ai.llm.models.list()` |
145
- | `ai.llm.models.get` | Read source and version | `id: string` | `HaiResult<AIResourceEntry> with value/source/version?` | `ai.llm.models.get("coding")` |
146
- | `ai.llm.models.register` | Register database definition | `ModelEntry input (id/model/protocol/credentials/capabilities)` | `HaiResult<AIResourceEntry>; config entries are read-only` | `ai.llm.models.register(modelDefinition)` |
147
- | `ai.llm.models.update` | Replace using a version | `ModelEntry input (id/model/protocol/credentials/capabilities), expectedVersion?` | `HaiResult<AIResourceEntry>; full replacement, conflict fails` | `ai.llm.models.update(modelDefinition, current.data.version)` |
148
- | `ai.llm.models.remove` | Remove database definition | `id, expectedVersion?; ACP definitions must have no session references` | `HaiResult<void>; external files/services are retained` | `ai.llm.models.remove("coding", current.data.version)` |
149
- | `ai.audio.models.list` | List merged definitions | `none` | `HaiResult<AIResourceEntry[]>; config wins, list has no database version` | `ai.audio.models.list()` |
150
- | `ai.audio.models.get` | Read source and version | `id: string` | `HaiResult<AIResourceEntry> with value/source/version?` | `ai.audio.models.get("speech")` |
151
- | `ai.audio.models.register` | Register database definition | `AudioModelEntry input (id/provider/model/operations)` | `HaiResult<AIResourceEntry>; config entries are read-only` | `ai.audio.models.register(audioModelDefinition)` |
152
- | `ai.audio.models.update` | Replace using a version | `AudioModelEntry input (id/provider/model/operations), expectedVersion?` | `HaiResult<AIResourceEntry>; full replacement, conflict fails` | `ai.audio.models.update(audioModelDefinition, current.data.version)` |
153
- | `ai.audio.models.remove` | Remove database definition | `id, expectedVersion?; ACP definitions must have no session references` | `HaiResult<void>; external files/services are retained` | `ai.audio.models.remove("speech", current.data.version)` |
154
- | `ai.image.models.list` | List merged definitions | `none` | `HaiResult<AIResourceEntry[]>; config wins, list has no database version` | `ai.image.models.list()` |
155
- | `ai.image.models.get` | Read source and version | `id: string` | `HaiResult<AIResourceEntry> with value/source/version?` | `ai.image.models.get("poster")` |
156
- | `ai.image.models.register` | Register database definition | `ImageModelEntry input (id/provider/model)` | `HaiResult<AIResourceEntry>; config entries are read-only` | `ai.image.models.register(imageModelDefinition)` |
157
- | `ai.image.models.update` | Replace using a version | `ImageModelEntry input (id/provider/model), expectedVersion?` | `HaiResult<AIResourceEntry>; full replacement, conflict fails` | `ai.image.models.update(imageModelDefinition, current.data.version)` |
158
- | `ai.image.models.remove` | Remove database definition | `id, expectedVersion?; ACP definitions must have no session references` | `HaiResult<void>; external files/services are retained` | `ai.image.models.remove("poster", current.data.version)` |
159
- | `ai.mcp.servers.list` | List merged definitions | `none` | `HaiResult<AIResourceEntry[]>; config wins, list has no database version` | `ai.mcp.servers.list()` |
160
- | `ai.mcp.servers.get` | Read source and version | `id: string` | `HaiResult<AIResourceEntry> with value/source/version?` | `ai.mcp.servers.get("tools")` |
161
- | `ai.mcp.servers.register` | Register database definition | `MCPExternalServer input (id/transport/url or command)` | `HaiResult<AIResourceEntry>; config entries are read-only` | `ai.mcp.servers.register(mcpServerDefinition)` |
162
- | `ai.mcp.servers.update` | Replace using a version | `MCPExternalServer input (id/transport/url or command), expectedVersion?` | `HaiResult<AIResourceEntry>; full replacement, conflict fails` | `ai.mcp.servers.update(mcpServerDefinition, current.data.version)` |
163
- | `ai.mcp.servers.remove` | Remove database definition | `id, expectedVersion?; ACP definitions must have no session references` | `HaiResult<void>; external files/services are retained` | `ai.mcp.servers.remove("tools", current.data.version)` |
164
- | `ai.retrieval.sources.list` | List merged definitions | `none` | `HaiResult<AIResourceEntry[]>; config wins, list has no database version` | `ai.retrieval.sources.list()` |
165
- | `ai.retrieval.sources.get` | Read source and version | `id: string` | `HaiResult<AIResourceEntry> with value/source/version?` | `ai.retrieval.sources.get("docs")` |
166
- | `ai.retrieval.sources.register` | Register database definition | `RetrievalSource input (id/collection)` | `HaiResult<AIResourceEntry>; config entries are read-only` | `ai.retrieval.sources.register(sourceDefinition)` |
167
- | `ai.retrieval.sources.update` | Replace using a version | `RetrievalSource input (id/collection), expectedVersion?` | `HaiResult<AIResourceEntry>; full replacement, conflict fails` | `ai.retrieval.sources.update(sourceDefinition, current.data.version)` |
168
- | `ai.retrieval.sources.remove` | Remove database definition | `id, expectedVersion?; ACP definitions must have no session references` | `HaiResult<void>; external files/services are retained` | `ai.retrieval.sources.remove("docs", current.data.version)` |
169
- | `ai.acp.agents.list` | List merged definitions | `none` | `HaiResult<AIResourceEntry[]>; config wins, list has no database version` | `ai.acp.agents.list()` |
170
- | `ai.acp.agents.get` | Read source and version | `id: string` | `HaiResult<AIResourceEntry> with value/source/version?` | `ai.acp.agents.get("coder")` |
171
- | `ai.acp.agents.register` | Register database definition | `ACPAgent input (id/mode/adapter/modelIds)` | `HaiResult<AIResourceEntry>; config entries are read-only` | `ai.acp.agents.register(agentDefinition)` |
172
- | `ai.acp.agents.update` | Replace using a version | `ACPAgent input (id/mode/adapter/modelIds), expectedVersion?` | `HaiResult<AIResourceEntry>; full replacement, conflict fails` | `ai.acp.agents.update(agentDefinition, current.data.version)` |
173
- | `ai.acp.agents.remove` | Remove database definition | `id, expectedVersion?; ACP definitions must have no session references` | `HaiResult<void>; external files/services are retained` | `ai.acp.agents.remove("coder", current.data.version)` |
174
- | `ai.acp.workspaces.list` | List merged definitions | `none` | `HaiResult<AIResourceEntry[]>; config wins, list has no database version` | `ai.acp.workspaces.list()` |
175
- | `ai.acp.workspaces.get` | Read source and version | `id: string` | `HaiResult<AIResourceEntry> with value/source/version?` | `ai.acp.workspaces.get("project")` |
176
- | `ai.acp.workspaces.register` | Register database definition | `ACPWorkspace input (id/storage/repositories)` | `HaiResult<AIResourceEntry>; config entries are read-only` | `ai.acp.workspaces.register(workspaceDefinition)` |
177
- | `ai.acp.workspaces.update` | Replace using a version | `ACPWorkspace input (id/storage/repositories), expectedVersion?` | `HaiResult<AIResourceEntry>; full replacement, conflict fails` | `ai.acp.workspaces.update(workspaceDefinition, current.data.version)` |
178
- | `ai.acp.workspaces.remove` | Remove database definition | `id, expectedVersion?; ACP definitions must have no session references` | `HaiResult<void>; external files/services are retained` | `ai.acp.workspaces.remove("project", current.data.version)` |
179
- | `ai.acp.agents.initialize` | Preflight agent | `agentId, modelId?` | `HaiResult<{ agentId, mode, modelIds }>; no credentials` | `ai.acp.agents.initialize("coder")` |
180
- | `ai.acp.agents.check` | Connect and handshake | `agentId, { workspaceId?, ...ACPClientOptions }` | `HaiResult<native initialize response>; owned connection is closed` | `ai.acp.agents.check("coder", { workspaceId: "project" })` |
181
- | `ai.acp.workspaces.prepare` | Prepare workspace | `workspaceId` | `HaiResult<main absolute path>; dirty content is retained` | `ai.acp.workspaces.prepare("project")` |
182
- | `ai.acp.workspaces.importFiles` | Import controlled files | `workspaceId, { path: relative path, content: string\|Uint8Array }[]` | `HaiResult<{ imported: string[] }>; no overwrite` | `ai.acp.workspaces.importFiles("project", [{ path: "notes.txt", content: "需求" }])` |
183
- | `ai.acp.sessions.create` | Start managed session | `ACPCreateSessionOptions: agentId/workspaceId/newWorktree?` | `HaiResult<managed session handle>` | `ai.acp.sessions.create({ agentId: "coder", workspaceId: "project", newWorktree: true })` |
184
- | `ai.acp.sessions.get` | Get session handle | `framework session id` | `HaiResult<managed session handle>; does not resume` | `ai.acp.sessions.get("task-1")` |
185
- | `ai.acp.sessions.list` | List managed sessions | `workspaceId?` | `HaiResult<ACPSessionInfo[]>` | `ai.acp.sessions.list("project")` |
186
- | `ai.acp.sessions.resume` | Resume native session | `framework session id, ACPClientOptions?` | `HaiResult<managed session handle>; definition changes may reject` | `ai.acp.sessions.resume("task-1")` |
187
- | `ai.acp.sessions.close` | Stop owned execution | `framework session id` | `HaiResult<void>; source and native history retained` | `ai.acp.sessions.close("task-1")` |
188
- | `ai.acp.sessions.reclaimWorktree` | Reclaim clean worktree | `closed framework session id; preview stopped and changes saved` | `HaiResult<void>; branch and normal files retained` | `ai.acp.sessions.reclaimWorktree("task-1")` |
189
- | `ai.acp.sessions.remove` | Remove session record | `closed or failed framework session id` | `HaiResult<void>; worktree and native history retained` | `ai.acp.sessions.remove("task-1")` |
190
- | `ai.acp.connect` | Connect native transport | `ACPTransport: stdio/http/ws, ACPClientOptions?` | `HaiResult<connection handle>` | `ai.acp.connect({ type: "http", url: "https://agent.example.com/acp" })` |
191
- | `ai.acp.close` | Close subsystem | `none; normally call ai.close()` | `Promise<void>; cleanup may throw` | `ai.acp.close()` |
52
+ | Entry | Use case | Input | Output | Call fragment |
53
+ | --------------------------------- | -------------------------------------- | --------------------------------------------------------------------------------- | ------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------- |
54
+ | `ai.llm.chat` | Single answer | `ChatCompletionRequest: messages, model?, signal?, tools?` | `ChatCompletionResponse: choices, model, usage?` | `ai.llm.chat({ messages: [{ role: "user", content: "你好" }] })` |
55
+ | `ai.llm.chatStream` | Stream completion | `same ChatCompletionRequest` | `AsyncIterable<ChatCompletionChunk>; iteration may throw` | `ai.llm.chatStream({ messages })` |
56
+ | `ai.llm.ask` | Text answer | `question: string, AskOptions?` | `string answer` | `ai.llm.ask("解释共享状态")` |
57
+ | `ai.llm.askStream` | Text stream | `question: string, AskOptions?` | `AsyncIterable<string>` | `ai.llm.askStream("解释共享状态")` |
58
+ | `ai.llm.generateObject` | Schema-constrained answer | `Zod schema, messages, model?, maxRepairs?, signal?` | `schema-inferred T` | `ai.llm.generateObject({ schema: AnswerSchema, messages })` |
59
+ | `ai.llm.listModels` | List models | `none` | `string[] model IDs` | `ai.llm.listModels()` |
60
+ | `ai.llm.getHistory` | Read history | `{ objectId, sessionId }, { limit?, order? }?` | `ChatRecord[]` | `ai.llm.getHistory({ objectId: "u1", sessionId: "s1" })` |
61
+ | `ai.llm.listSessions` | Subject sessions | `objectId: string` | `SessionInfo[]` | `ai.llm.listSessions("u1")` |
62
+ | `ai.tools.define` | Define a tool | `{ name, description, parameters: Zod schema, handler, timeoutMs? }` | `direct Tool<TInput,TOutput>; no init required` | `ai.tools.define(toolDefinition)` |
63
+ | `ai.tools.createRegistry` | Create tool registry | `{ authorize? }?` | `direct ToolRegistryOperations; no init required` | `ai.tools.createRegistry({ authorize })` |
64
+ | `ai.stream.createProcessor` | Accumulate chunks | `none` | `direct StreamProcessor` | `ai.stream.createProcessor()` |
65
+ | `ai.stream.collect` | Consume a chat stream | `AsyncIterable<ChatCompletionChunk>` | `Promise<StreamResult>; stream failure rejects` | `ai.stream.collect(ai.llm.chatStream({ messages }))` |
66
+ | `ai.stream.createSSEDecoder` | Decode split SSE | `none` | `direct SSEDecoder with decode/reset` | `ai.stream.createSSEDecoder()` |
67
+ | `ai.stream.encodeSSE` | Encode SSE | `SSEEvent: data, event?, id?, retry?` | `direct string; invalid metadata throws` | `ai.stream.encodeSSE({ data: "Hello" })` |
68
+ | `ai.embedding.embed` | Embedding request | `EmbeddingRequest with input/model?` | `EmbeddingResponse` | `ai.embedding.embed({ input: "产品说明" })` |
69
+ | `ai.embedding.embedText` | Embed one text | `text: string` | `number[]` | `ai.embedding.embedText("产品说明")` |
70
+ | `ai.embedding.embedBatch` | Embed many texts | `texts: string[]` | `number[][] in input order` | `ai.embedding.embedBatch(["简介", "部署"])` |
71
+ | `ai.mcp.registerTool` | Register local tool | `MCPToolDefinition, typed handler` | `void` | `ai.mcp.registerTool(mcpToolDefinition, toolHandler)` |
72
+ | `ai.mcp.registerResource` | Register resource | `MCPResource, async content handler` | `void` | `ai.mcp.registerResource(resourceDefinition, readContent)` |
73
+ | `ai.mcp.registerPrompt` | Register prompt | `MCPPrompt, args => Promise<MCPPromptMessage[]>` | `void` | `ai.mcp.registerPrompt(promptDefinition, buildMessages)` |
74
+ | `ai.mcp.callTool` | Call local tool | `name, arguments, MCPContext?` | `unknown tool result` | `ai.mcp.callTool("search", { query: "配置" })` |
75
+ | `ai.mcp.readResource` | Read resource | `resource URI` | `MCPResourceContent with exactly text or blob` | `ai.mcp.readResource("docs://intro")` |
76
+ | `ai.mcp.getPrompt` | Build prompt | `name, Record<string,string> arguments` | `MCPPromptMessage[]` | `ai.mcp.getPrompt("review", { topic: "API" })` |
77
+ | `ai.mcp.services.invoke` | Call an authorized remote tool | Request, authenticated principal, and authorization function | `HaiResult<CallToolResult>` | `ai.mcp.services.invoke(request, authorization)` |
78
+ | `ai.mcp.services.createBroker` | Mount a tool endpoint for ACP sessions | Fixed URL and live authorization function | `HaiResult<MCPServiceBroker>` | `ai.mcp.services.createBroker(brokerOptions)` |
79
+ | `ai.retrieval.addSource` | Register source | `RetrievalSource: id, collection, optional metadata` | `void` | `ai.retrieval.addSource({ id: "docs", collection: "manual" })` |
80
+ | `ai.retrieval.removeSource` | Remove source | `sourceId: string` | `void` | `ai.retrieval.removeSource("docs")` |
81
+ | `ai.retrieval.listSources` | List sources | `none` | `direct Promise<RetrievalSource[]>` | `ai.retrieval.listSources()` |
82
+ | `ai.retrieval.retrieve` | Retrieve candidates | `RetrievalRequest: query, sources?, topK?, minScore?, enableRerank?` | `RetrievalResult` | `ai.retrieval.retrieve({ query: "部署" })` |
83
+ | `ai.rag.query` | Grounded answer | `query: string, RagOptions?` | `RagResult: answer, context, citations, query, model` | `ai.rag.query("如何部署?", { sources: ["docs"] })` |
84
+ | `ai.rag.queryStream` | Grounded stream | `query: string, RagOptions?` | `AsyncIterable<RagStreamEvent>` | `ai.rag.queryStream("如何部署?", { sources: ["docs"] })` |
85
+ | `ai.knowledge.setup` | Prepare collection | `KnowledgeSetupOptions?` | `void; collection ready for ingest` | `ai.knowledge.setup()` |
86
+ | `ai.knowledge.ingest` | Publish document | `{ documentId, content, title?, collection?, ...metadata }` | `KnowledgeIngestResult with revision/cleanupPending` | `ai.knowledge.ingest({ documentId: "intro", content: "入门正文" })` |
87
+ | `ai.knowledge.ingestFile` | Ingest a file | `KnowledgeIngestFileInput including file bytes and document identity` | `KnowledgeIngestResult` | `ai.knowledge.ingestFile(fileInput)` |
88
+ | `ai.knowledge.ingestBatch` | Ingest batch | `KnowledgeIngestInput[], onProgress?` | `KnowledgeIngestBatchResult with per-document outcomes` | `ai.knowledge.ingestBatch(documentInputs, onProgress)` |
89
+ | `ai.knowledge.retrieve` | Retrieve published revision | `query: string, KnowledgeRetrieveOptions?` | `KnowledgeRetrieveResult` | `ai.knowledge.retrieve("部署说明")` |
90
+ | `ai.knowledge.ask` | Answer from knowledge | `query: string, KnowledgeAskOptions?` | `KnowledgeAskResult` | `ai.knowledge.ask("如何恢复备份?")` |
91
+ | `ai.knowledge.findByEntity` | Find by entity | `entityName: string, EntityQueryOptions?` | `EntityDocumentResult[]` | `ai.knowledge.findByEntity("订单")` |
92
+ | `ai.knowledge.listEntities` | List entities | `EntityListOptions?` | `KnowledgeEntity[]` | `ai.knowledge.listEntities()` |
93
+ | `ai.knowledge.listDocuments` | List documents | `KnowledgeDocumentListOptions?` | `KnowledgeDocumentInfo[]` | `ai.knowledge.listDocuments()` |
94
+ | `ai.knowledge.removeDocument` | Remove document | `documentId, KnowledgeDocumentRemoveOptions?` | `void; may fail after visibility revocation if cleanup fails` | `ai.knowledge.removeDocument("intro")` |
95
+ | `ai.knowledge.repair` | Repair cleanup | `{ collection?, offset?, limit? }` | `KnowledgeRepairResult with progress` | `ai.knowledge.repair({ offset: 0, limit: 100 })` |
96
+ | `ai.knowledge.deleteCollection` | Remove collection | `collection name?` | `void; cleanup tombstone remains` | `ai.knowledge.deleteCollection("retired-manual")` |
97
+ | `ai.memory.scoped` | Bind trusted subject | `{ objectId: nonempty string, scope? }` | `direct ScopedMemoryOperations; invalid binding throws TypeError` | `ai.memory.scoped({ objectId: "u1", scope: { topicId: "orders" } })` |
98
+ | `ai.memory.extract` | Extract memories | `ChatMessage[], { objectId, scope?, model?, signal?, ...options }` | `MemoryEntry[]` | `ai.memory.extract(messages, { objectId: "u1" })` |
99
+ | `ai.memory.add` | Store explicit memory | `MemoryEntryInput: objectId, content, type, scope?` | `MemoryEntry` | `ai.memory.add({ objectId: "u1", content: "偏好中文", type: "preference" })` |
100
+ | `ai.memory.get` | Read owned memory | `memoryId, { objectId, scope? } for untrusted IDs` | `MemoryEntry` | `ai.memory.get(memoryId, { objectId: "u1" })` |
101
+ | `ai.memory.update` | Update memory | `memoryId, MemoryUpdateInput, trusted access scope` | `MemoryEntry` | `ai.memory.update(memoryId, { content: "偏好日文" }, { objectId: "u1" })` |
102
+ | `ai.memory.remove` | Remove owned memory | `memoryId, trusted access scope` | `void` | `ai.memory.remove(memoryId, { objectId: "u1" })` |
103
+ | `ai.memory.recall` | Recall memories | `query, { objectId, scope?, topK?, types?, ...options }` | `MemoryEntry[]` | `ai.memory.recall("语言偏好", { objectId: "u1" })` |
104
+ | `ai.memory.injectMemories` | Enrich messages | `ChatMessage[], { objectId, scope?, topK?, ...options }` | `ChatMessage[]` | `ai.memory.injectMemories(messages, { objectId: "u1" })` |
105
+ | `ai.memory.list` | List memories | `MemoryListOptions with objectId/scope filters` | `MemoryEntry[]; incomplete scan fails` | `ai.memory.list({ objectId: "u1" })` |
106
+ | `ai.memory.listPage` | Page memories | `MemoryListPageOptions with objectId/pagination` | `StorePage<MemoryEntry>` | `ai.memory.listPage({ objectId: "u1", offset: 0, limit: 20 })` |
107
+ | `ai.memory.clear` | Clear selected scope | `nonempty MemoryClearOptions` | `void; empty filters are rejected` | `ai.memory.clear({ objectId: "u1" })` |
108
+ | `ai.memory.admin.clearAll` | Trusted administrator clear | `{ confirm: true }; require host administrator authorization` | `void; destructive across subjects` | `ai.memory.admin.clearAll({ confirm: true })` |
109
+ | `ai.persona.save` | Save persona | `PersonaProfileInput: id, name, systemPrompt, objectId?, traits?` | `PersonaProfile` | `ai.persona.save(personaProfile)` |
110
+ | `ai.persona.get` | Get persona | `id, { objectId }?; omitted subject selects system profile` | `PersonaProfile` | `ai.persona.get("tutor", { objectId: "u1" })` |
111
+ | `ai.persona.update` | Update persona | `id, PersonaProfileUpdate, { objectId }?` | `PersonaProfile` | `ai.persona.update("tutor", updates, { objectId: "u1" })` |
112
+ | `ai.persona.remove` | Remove persona | `id, { objectId }?` | `void` | `ai.persona.remove("tutor", { objectId: "u1" })` |
113
+ | `ai.persona.list` | List personas | `{ objectId }?` | `PersonaProfile[]` | `ai.persona.list({ objectId: "u1" })` |
114
+ | `ai.persona.compose` | Compose system prompt | `id, { objectId }?` | `string prompt` | `ai.persona.compose("tutor", { objectId: "u1" })` |
115
+ | `ai.token.estimateText` | Estimate text tokens | `text: string` | `direct number; estimate, not billing usage` | `ai.token.estimateText("Hello 世界")` |
116
+ | `ai.token.estimateMessages` | Estimate message tokens | `ChatMessage[]` | `direct number including protocol overhead` | `ai.token.estimateMessages(messages)` |
117
+ | `ai.summary.generate` | Generate summary text | `ChatMessage[], SummaryOptions?` | `string` | `ai.summary.generate(messages)` |
118
+ | `ai.summary.summarize` | Summary metadata | `ChatMessage[], SummaryOptions?` | `{ summary, tokenCount, coveredMessages }` | `ai.summary.summarize(messages)` |
119
+ | `ai.compress.tryCompress` | Compress to budget | `ChatMessage[], { strategy?, maxTokens?, preserveLastN?, ...options }` | `CompressResult: messages and original/compressed token counts` | `ai.compress.tryCompress(messages, { maxTokens: 4000 })` |
120
+ | `ai.context.createManager` | Create context | `ContextManagerOptions with scope { objectId, sessionId }` | `ContextManager` | `ai.context.createManager({ scope: { objectId: "u1", sessionId: "s1" } })` |
121
+ | `ai.context.restoreManager` | Restore context | `{ objectId, sessionId }, options?` | `ContextManager` | `ai.context.restoreManager({ objectId: "u1", sessionId: "s1" })` |
122
+ | `ai.context.listSessions` | List stored sessions | `objectId` | `SessionInfo[]` | `ai.context.listSessions("u1")` |
123
+ | `ai.context.renameSession` | Rename session | `scope, title` | `void` | `ai.context.renameSession({ objectId: "u1", sessionId: "s1" }, "订单讨论")` |
124
+ | `ai.context.removeSession` | Remove session | `scope` | `void; tombstone prevents scope reuse` | `ai.context.removeSession({ objectId: "u1", sessionId: "s1" })` |
125
+ | `ai.rerank.rerank` | Rerank documents | `RerankRequest: query, documents, model?, topN?` | `RerankResponse with model/results` | `ai.rerank.rerank({ query: "部署", documents: ["配置说明"] })` |
126
+ | `ai.rerank.rerankTexts` | Rerank texts | `query, string[] texts, topN?` | `RerankItem[] with index/relevanceScore` | `ai.rerank.rerankTexts("部署", ["配置说明"], 1)` |
127
+ | `ai.file.parse` | Parse a file | `FileParseRequest with content, filename, options?` | `FileParseResult; extraction is not HTML sanitization` | `ai.file.parse({ content: "<p>正文</p>", filename: "intro.html" })` |
128
+ | `ai.file.parseText` | Extract plain text | `Buffer\|string content, filename?` | `string` | `ai.file.parseText("Hello", "intro.txt")` |
129
+ | `ai.reasoning.run` | Multistep reasoning | `query, ReasoningOptions including strategy/tools?` | `ReasoningResult` | `ai.reasoning.run("审查方案", { strategy: "cot" })` |
130
+ | `ai.reasoning.runStream` | Observe reasoning stream | `query, ReasoningOptions?` | `AsyncIterable<ReasoningStreamEvent>` | `ai.reasoning.runStream("审查方案", { strategy: "react" })` |
131
+ | `ai.audio.transcribe` | Transcribe audio | `TranscriptionRequest: audio, language?, model?, signal?` | `TranscriptionResult: text, language?, segments?` | `ai.audio.transcribe({ audio: { data: wavBytes, format: "wav" } })` |
132
+ | `ai.audio.transcribeStream` | Stream transcription | `TranscriptionStreamRequest: chunks or complete audio` | `AsyncIterable<TranscriptionEvent>` | `ai.audio.transcribeStream(transcriptionInput)` |
133
+ | `ai.audio.synthesize` | Synthesize audio | `SynthesisRequest: text, language?, model?, signal?` | `SynthesisResult: audio and duration metadata` | `ai.audio.synthesize({ text: "你好" })` |
134
+ | `ai.audio.synthesizeStream` | Synthesize segments | `SynthesisStreamRequest: text segment or async segments` | `AsyncIterable<SynthesisEvent>` | `ai.audio.synthesizeStream(synthesisInput)` |
135
+ | `ai.audio.getCapabilities` | Inspect capabilities | `{ operation: transcribe\|synthesize, model? }` | `AudioModelCapabilities` | `ai.audio.getCapabilities({ operation: "synthesize" })` |
136
+ | `ai.image.generate` | Generate images | `{ prompt, referenceImages?, model?, size?, signal? }` | `{ images: GeneratedImage[] } with bytes/MIME` | `ai.image.generate({ prompt: "一座灯塔" })` |
137
+ | `ai.a2a.registerExecutor` | Register executor | `SDK AgentExecutor` | `void` | `ai.a2a.registerExecutor(executor)` |
138
+ | `ai.a2a.getAgentCard` | Agent discovery | `none; configured a2a card` | `A2AAgentCardDocument (A2A 1.0 ProtoJSON)` | `ai.a2a.getAgentCard()` |
139
+ | `ai.a2a.handleRequest` | Handle protocol request | `unknown JSON-RPC body, trusted context.agentId?` | `direct Promise<A2AHandleResult>; JSON-RPC/SSE outcome` | `ai.a2a.handleRequest(body, { agentId: trustedAgentId })` |
140
+ | `ai.a2a.listMessages` | Administrative message query | `A2ATaskFilter: callerId?, contextId?, since?, pagination?` | `StorePage<A2AMessageRecord>` | `ai.a2a.listMessages(messageFilter)` |
141
+ | `ai.a2a.callRemoteAgent` | Call approved remote agent | `allowlisted HTTPS URL, message, A2ACallOptions?` | `A2ACallResult` | `ai.a2a.callRemoteAgent("https://agent.example.com/a2a", "请分析订单")` |
142
+ | `ai.init` | Initialize service | `AIConfigInput?, AIInitOptions?` | `HaiResult<void>; validate dependencies before use` | `ai.init({ llm: { apiKey: process.env.HAI_AI_LLM_APIKEY } })` |
143
+ | `ai.close` | Release service | `none` | `Promise<void>; wait for cleanup` | `ai.close()` |
144
+ | `ai.config` | Read safe config | `none` | `redacted AIConfig or null` | `ai.config` |
145
+ | `ai.isInitialized` | Check lifecycle | `none` | `boolean` | `ai.isInitialized` |
146
+ | `ai.llm.models.list` | List merged definitions | `none` | `HaiResult<AIResourceEntry[]>; config wins, list has no database version` | `ai.llm.models.list()` |
147
+ | `ai.llm.models.get` | Read source and version | `id: string` | `HaiResult<AIResourceEntry> with value/source/version?` | `ai.llm.models.get("coding")` |
148
+ | `ai.llm.models.register` | Register database definition | `ModelEntry input (id/model/protocol/credentials/capabilities)` | `HaiResult<AIResourceEntry>; config entries are read-only` | `ai.llm.models.register(modelDefinition)` |
149
+ | `ai.llm.models.update` | Replace using a version | `ModelEntry input (id/model/protocol/credentials/capabilities), expectedVersion?` | `HaiResult<AIResourceEntry>; full replacement, conflict fails` | `ai.llm.models.update(modelDefinition, current.data.version)` |
150
+ | `ai.llm.models.remove` | Remove database definition | `id, expectedVersion?; ACP definitions must have no session references` | `HaiResult<void>; external files/services are retained` | `ai.llm.models.remove("coding", current.data.version)` |
151
+ | `ai.audio.models.list` | List merged definitions | `none` | `HaiResult<AIResourceEntry[]>; config wins, list has no database version` | `ai.audio.models.list()` |
152
+ | `ai.audio.models.get` | Read source and version | `id: string` | `HaiResult<AIResourceEntry> with value/source/version?` | `ai.audio.models.get("speech")` |
153
+ | `ai.audio.models.register` | Register database definition | `AudioModelEntry input (id/provider/model/operations)` | `HaiResult<AIResourceEntry>; config entries are read-only` | `ai.audio.models.register(audioModelDefinition)` |
154
+ | `ai.audio.models.update` | Replace using a version | `AudioModelEntry input (id/provider/model/operations), expectedVersion?` | `HaiResult<AIResourceEntry>; full replacement, conflict fails` | `ai.audio.models.update(audioModelDefinition, current.data.version)` |
155
+ | `ai.audio.models.remove` | Remove database definition | `id, expectedVersion?; ACP definitions must have no session references` | `HaiResult<void>; external files/services are retained` | `ai.audio.models.remove("speech", current.data.version)` |
156
+ | `ai.image.models.list` | List merged definitions | `none` | `HaiResult<AIResourceEntry[]>; config wins, list has no database version` | `ai.image.models.list()` |
157
+ | `ai.image.models.get` | Read source and version | `id: string` | `HaiResult<AIResourceEntry> with value/source/version?` | `ai.image.models.get("poster")` |
158
+ | `ai.image.models.register` | Register database definition | `ImageModelEntry input (id/provider/model)` | `HaiResult<AIResourceEntry>; config entries are read-only` | `ai.image.models.register(imageModelDefinition)` |
159
+ | `ai.image.models.update` | Replace using a version | `ImageModelEntry input (id/provider/model), expectedVersion?` | `HaiResult<AIResourceEntry>; full replacement, conflict fails` | `ai.image.models.update(imageModelDefinition, current.data.version)` |
160
+ | `ai.image.models.remove` | Remove database definition | `id, expectedVersion?; ACP definitions must have no session references` | `HaiResult<void>; external files/services are retained` | `ai.image.models.remove("poster", current.data.version)` |
161
+ | `ai.mcp.servers.list` | List merged definitions | `none` | `HaiResult<AIResourceEntry[]>; config wins, list has no database version` | `ai.mcp.servers.list()` |
162
+ | `ai.mcp.servers.get` | Read source and version | `id: string` | `HaiResult<AIResourceEntry> with value/source/version?` | `ai.mcp.servers.get("tools")` |
163
+ | `ai.mcp.servers.register` | Register database definition | `MCPExternalServer input (id/transport/url or command)` | `HaiResult<AIResourceEntry>; config entries are read-only` | `ai.mcp.servers.register(mcpServerDefinition)` |
164
+ | `ai.mcp.servers.update` | Replace using a version | `MCPExternalServer input (id/transport/url or command), expectedVersion?` | `HaiResult<AIResourceEntry>; full replacement, conflict fails` | `ai.mcp.servers.update(mcpServerDefinition, current.data.version)` |
165
+ | `ai.mcp.servers.remove` | Remove database definition | `id, expectedVersion?; ACP definitions must have no session references` | `HaiResult<void>; external files/services are retained` | `ai.mcp.servers.remove("tools", current.data.version)` |
166
+ | `ai.retrieval.sources.list` | List merged definitions | `none` | `HaiResult<AIResourceEntry[]>; config wins, list has no database version` | `ai.retrieval.sources.list()` |
167
+ | `ai.retrieval.sources.get` | Read source and version | `id: string` | `HaiResult<AIResourceEntry> with value/source/version?` | `ai.retrieval.sources.get("docs")` |
168
+ | `ai.retrieval.sources.register` | Register database definition | `RetrievalSource input (id/collection)` | `HaiResult<AIResourceEntry>; config entries are read-only` | `ai.retrieval.sources.register(sourceDefinition)` |
169
+ | `ai.retrieval.sources.update` | Replace using a version | `RetrievalSource input (id/collection), expectedVersion?` | `HaiResult<AIResourceEntry>; full replacement, conflict fails` | `ai.retrieval.sources.update(sourceDefinition, current.data.version)` |
170
+ | `ai.retrieval.sources.remove` | Remove database definition | `id, expectedVersion?; ACP definitions must have no session references` | `HaiResult<void>; external files/services are retained` | `ai.retrieval.sources.remove("docs", current.data.version)` |
171
+ | `ai.acp.agents.list` | List merged definitions | `none` | `HaiResult<AIResourceEntry[]>; config wins, list has no database version` | `ai.acp.agents.list()` |
172
+ | `ai.acp.agents.get` | Read source and version | `id: string` | `HaiResult<AIResourceEntry> with value/source/version?` | `ai.acp.agents.get("coder")` |
173
+ | `ai.acp.agents.register` | Register database definition | `ACPAgent input (id/mode/adapter/modelIds)` | `HaiResult<AIResourceEntry>; config entries are read-only` | `ai.acp.agents.register(agentDefinition)` |
174
+ | `ai.acp.agents.update` | Replace using a version | `ACPAgent input (id/mode/adapter/modelIds), expectedVersion?` | `HaiResult<AIResourceEntry>; full replacement, conflict fails` | `ai.acp.agents.update(agentDefinition, current.data.version)` |
175
+ | `ai.acp.agents.remove` | Remove database definition | `id, expectedVersion?; ACP definitions must have no session references` | `HaiResult<void>; external files/services are retained` | `ai.acp.agents.remove("coder", current.data.version)` |
176
+ | `ai.acp.workspaces.list` | List merged definitions | `none` | `HaiResult<AIResourceEntry[]>; config wins, list has no database version` | `ai.acp.workspaces.list()` |
177
+ | `ai.acp.workspaces.get` | Read source and version | `id: string` | `HaiResult<AIResourceEntry> with value/source/version?` | `ai.acp.workspaces.get("project")` |
178
+ | `ai.acp.workspaces.register` | Register database definition | `ACPWorkspace input (id/storage/repositories)` | `HaiResult<AIResourceEntry>; config entries are read-only` | `ai.acp.workspaces.register(workspaceDefinition)` |
179
+ | `ai.acp.workspaces.update` | Replace using a version | `ACPWorkspace input (id/storage/repositories), expectedVersion?` | `HaiResult<AIResourceEntry>; full replacement, conflict fails` | `ai.acp.workspaces.update(workspaceDefinition, current.data.version)` |
180
+ | `ai.acp.workspaces.remove` | Remove database definition | `id, expectedVersion?; ACP definitions must have no session references` | `HaiResult<void>; external files/services are retained` | `ai.acp.workspaces.remove("project", current.data.version)` |
181
+ | `ai.acp.agents.initialize` | Preflight agent | `agentId, modelId?` | `HaiResult<{ agentId, mode, modelIds }>; no credentials` | `ai.acp.agents.initialize("coder")` |
182
+ | `ai.acp.agents.check` | Connect and handshake | `agentId, { workspaceId?, ...ACPClientOptions }` | `HaiResult<native initialize response>; owned connection is closed` | `ai.acp.agents.check("coder", { workspaceId: "project" })` |
183
+ | `ai.acp.workspaces.prepare` | Prepare workspace | `workspaceId` | `HaiResult<main absolute path>; dirty content is retained` | `ai.acp.workspaces.prepare("project")` |
184
+ | `ai.acp.workspaces.importFiles` | Import controlled files | `workspaceId, { path: relative path, content: string\|Uint8Array }[]` | `HaiResult<{ imported: string[] }>; no overwrite` | `ai.acp.workspaces.importFiles("project", [{ path: "notes.txt", content: "需求" }])` |
185
+ | `ai.acp.sessions.create` | Start managed session | `ACPCreateSessionOptions: agentId/workspaceId/newWorktree?` | `HaiResult<managed session handle>` | `ai.acp.sessions.create({ agentId: "coder", workspaceId: "project", newWorktree: true })` |
186
+ | `ai.acp.sessions.get` | Get session handle | `framework session id` | `HaiResult<managed session handle>; does not resume` | `ai.acp.sessions.get("task-1")` |
187
+ | `ai.acp.sessions.list` | List managed sessions | `workspaceId?` | `HaiResult<ACPSessionInfo[]>` | `ai.acp.sessions.list("project")` |
188
+ | `ai.acp.sessions.resume` | Resume native session | `framework session id, ACPClientOptions?` | `HaiResult<managed session handle>; definition changes may reject` | `ai.acp.sessions.resume("task-1")` |
189
+ | `ai.acp.sessions.close` | Stop owned execution | `framework session id` | `HaiResult<void>; source and native history retained` | `ai.acp.sessions.close("task-1")` |
190
+ | `ai.acp.sessions.reclaimWorktree` | Reclaim clean worktree | `closed framework session id; preview stopped and changes saved` | `HaiResult<void>; branch and normal files retained` | `ai.acp.sessions.reclaimWorktree("task-1")` |
191
+ | `ai.acp.sessions.remove` | Remove session record | `closed or failed framework session id` | `HaiResult<void>; worktree and native history retained` | `ai.acp.sessions.remove("task-1")` |
192
+ | `ai.acp.connect` | Connect native transport | `ACPTransport: stdio/http/ws, ACPClientOptions?` | `HaiResult<connection handle>` | `ai.acp.connect({ type: "http", url: "https://agent.example.com/acp" })` |
193
+ | `ai.acp.close` | Close subsystem | `none; normally call ai.close()` | `Promise<void>; cleanup may throw` | `ai.acp.close()` |
192
194
 
193
195
  - `ai.tools`: tool definitions, registries, and batch execution; no initialization required.
194
196
  - `ai.stream`: ChatCompletion stream chunk processing; no initialization required.
@@ -375,7 +377,9 @@ The Goose 1.57.0 image exposes its native `goose serve` HTTP/WS `/acp` service t
375
377
 
376
378
  Declare verified capacity, modalities and reasoning in `llm.models[].capabilities`. Codex needs native Responses; the existing Hai adapter is not a reverse gateway. Code and state persist after close. CAS ownership is released only after owned processes stop; worktrees are not security sandboxes.
377
379
 
378
- See the [ACP guide](../cli/templates/skills/hai-ai/acp.md) and [agent images](models/agents/README.md). Images include Git/Node/Python, optional Java/Rust/Go, and both codex-acp and codex in the Codex image. Errors use `hai:ai:070`–`084`; ordinary methods return HaiResult, while stream failures throw.
380
+ Build an Agent image with `minimal`, `documents`, `office`, `browser`, or `developer`. The default includes Git, Node, and the native Agent. Codex also includes bubblewrap. Register a local image ID or remote manifest digest for the execution environment. [Agent images](models/agents/README.md)
381
+
382
+ ACP runs in the Node service. Ordinary methods return HaiResult and stream failures throw. [ACP guide](../cli/templates/skills/hai-ai/acp.md)
379
383
 
380
384
  Managed Git rejects submodules and Git LFS attributes with ACP_UNSUPPORTED instead of reporting incomplete checkouts as ready.
381
385