@h-ai/ai 1.0.0-beta.23 → 1.0.0-beta.25
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.en.md +308 -141
- package/README.ja.md +308 -141
- package/README.md +306 -141
- package/dist/{ai-acp-types-BNeA1j0P.d.ts → ai-acp-types-Bwp6PcL8.d.ts} +2265 -230
- package/dist/browser.d.ts +3 -1
- package/dist/browser.js +3 -3
- package/dist/{chunk-WSH2246H.js → chunk-3R5SMLSJ.js} +3 -3
- package/dist/{chunk-WSH2246H.js.map → chunk-3R5SMLSJ.js.map} +1 -1
- package/dist/{chunk-M77C3VAP.js → chunk-NRDLMUSY.js} +4 -2
- package/dist/chunk-NRDLMUSY.js.map +1 -0
- package/dist/{chunk-CCXG2S7O.js → chunk-VEWBD2J4.js} +157 -9
- package/dist/chunk-VEWBD2J4.js.map +1 -0
- package/dist/client/index.js +2 -2
- package/dist/index.d.ts +4 -2
- package/dist/index.js +3088 -879
- package/dist/index.js.map +1 -1
- package/models/agents/README.md +30 -18
- package/models/agents/build.mjs +158 -55
- package/models/agents/codex-acp/Dockerfile +8 -13
- package/models/agents/deepseek-harness/Dockerfile +8 -13
- package/models/agents/goose/Dockerfile +8 -13
- package/models/agents/goose/agent.json +1 -1
- package/package.json +11 -8
- package/tools/.dockerignore +4 -0
- package/tools/README.md +111 -0
- package/tools/archives.py +56 -0
- package/tools/browser/Dockerfile +19 -0
- package/tools/browser/operation.py +50 -0
- package/tools/browser/render.mjs +40 -0
- package/tools/documents/Dockerfile +20 -0
- package/tools/documents/operation.py +80 -0
- package/tools/ocr/Dockerfile +19 -0
- package/tools/ocr/operation.py +18 -0
- package/tools/office/Dockerfile +21 -0
- package/tools/office/office_job.py +65 -0
- package/tools/office/operation.py +43 -0
- package/tools/tests/image-smoke.mjs +83 -0
- package/tools/tests/test_hai_tool.py +82 -0
- package/tools/tool.py +145 -0
- package/dist/chunk-CCXG2S7O.js.map +0 -1
- package/dist/chunk-M77C3VAP.js.map +0 -1
package/README.ja.md
CHANGED
|
@@ -49,146 +49,148 @@ direct・AsyncIterable・直接の Promise 値と記載したもの以外、出
|
|
|
49
49
|
|
|
50
50
|
呼出し断片は本ページで初期化したサービスを使います。変数はアプリ側で用意する要求・Schema・リソース定義・設定を表します。初期化と失敗処理は各機能の例を参照し、HaiResult.success の確認と非同期処理の await を行ってください。
|
|
51
51
|
|
|
52
|
-
| 入口 | 用途
|
|
53
|
-
| --------------------------------- |
|
|
54
|
-
| `ai.llm.chat` | 単発応答
|
|
55
|
-
| `ai.llm.chatStream` | 増分応答
|
|
56
|
-
| `ai.llm.ask` | テキスト応答
|
|
57
|
-
| `ai.llm.askStream` | テキストストリーム
|
|
58
|
-
| `ai.llm.generateObject` | Schema 制約付き応答
|
|
59
|
-
| `ai.llm.listModels` | モデル一覧
|
|
60
|
-
| `ai.llm.getHistory` | 会話履歴
|
|
61
|
-
| `ai.llm.listSessions` | 主体の会話一覧
|
|
62
|
-
| `ai.tools.define` | ツールを定義
|
|
63
|
-
| `ai.tools.createRegistry` | ツール一覧を管理
|
|
64
|
-
| `ai.stream.createProcessor` | 増分を蓄積
|
|
65
|
-
| `ai.stream.collect` | 対話ストリームを消費
|
|
66
|
-
| `ai.stream.createSSEDecoder` | 分割 SSE の復号
|
|
67
|
-
| `ai.stream.encodeSSE` | SSE を符号化
|
|
68
|
-
| `ai.embedding.embed` | 埋め込み要求
|
|
69
|
-
| `ai.embedding.embedText` | 一文のベクトル
|
|
70
|
-
| `ai.embedding.embedBatch` | 複数文のベクトル
|
|
71
|
-
| `ai.mcp.registerTool` | ローカルツール登録
|
|
72
|
-
| `ai.mcp.registerResource` | 資源登録
|
|
73
|
-
| `ai.mcp.registerPrompt` | プロンプト登録
|
|
74
|
-
| `ai.mcp.callTool` | 登録済みツール呼出し
|
|
75
|
-
| `ai.mcp.readResource` | 資源読取
|
|
76
|
-
| `ai.mcp.getPrompt` | プロンプト生成
|
|
77
|
-
| `ai.
|
|
78
|
-
| `ai.
|
|
79
|
-
| `ai.retrieval.
|
|
80
|
-
| `ai.retrieval.
|
|
81
|
-
| `ai.
|
|
82
|
-
| `ai.
|
|
83
|
-
| `ai.
|
|
84
|
-
| `ai.
|
|
85
|
-
| `ai.knowledge.
|
|
86
|
-
| `ai.knowledge.
|
|
87
|
-
| `ai.knowledge.
|
|
88
|
-
| `ai.knowledge.
|
|
89
|
-
| `ai.knowledge.
|
|
90
|
-
| `ai.knowledge.
|
|
91
|
-
| `ai.knowledge.
|
|
92
|
-
| `ai.knowledge.
|
|
93
|
-
| `ai.knowledge.
|
|
94
|
-
| `ai.knowledge.
|
|
95
|
-
| `ai.
|
|
96
|
-
| `ai.
|
|
97
|
-
| `ai.memory.
|
|
98
|
-
| `ai.memory.
|
|
99
|
-
| `ai.memory.
|
|
100
|
-
| `ai.memory.
|
|
101
|
-
| `ai.memory.
|
|
102
|
-
| `ai.memory.
|
|
103
|
-
| `ai.memory.
|
|
104
|
-
| `ai.memory.
|
|
105
|
-
| `ai.memory.
|
|
106
|
-
| `ai.memory.
|
|
107
|
-
| `ai.
|
|
108
|
-
| `ai.
|
|
109
|
-
| `ai.persona.
|
|
110
|
-
| `ai.persona.
|
|
111
|
-
| `ai.persona.
|
|
112
|
-
| `ai.persona.
|
|
113
|
-
| `ai.
|
|
114
|
-
| `ai.
|
|
115
|
-
| `ai.
|
|
116
|
-
| `ai.
|
|
117
|
-
| `ai.
|
|
118
|
-
| `ai.
|
|
119
|
-
| `ai.
|
|
120
|
-
| `ai.context.
|
|
121
|
-
| `ai.context.
|
|
122
|
-
| `ai.context.
|
|
123
|
-
| `ai.
|
|
124
|
-
| `ai.
|
|
125
|
-
| `ai.
|
|
126
|
-
| `ai.
|
|
127
|
-
| `ai.
|
|
128
|
-
| `ai.
|
|
129
|
-
| `ai.
|
|
130
|
-
| `ai.
|
|
131
|
-
| `ai.audio.
|
|
132
|
-
| `ai.audio.
|
|
133
|
-
| `ai.audio.
|
|
134
|
-
| `ai.
|
|
135
|
-
| `ai.
|
|
136
|
-
| `ai.
|
|
137
|
-
| `ai.a2a.
|
|
138
|
-
| `ai.a2a.
|
|
139
|
-
| `ai.a2a.
|
|
140
|
-
| `ai.
|
|
141
|
-
| `ai.
|
|
142
|
-
| `ai.
|
|
143
|
-
| `ai.
|
|
144
|
-
| `ai.
|
|
145
|
-
| `ai.
|
|
146
|
-
| `ai.llm.models.
|
|
147
|
-
| `ai.llm.models.
|
|
148
|
-
| `ai.llm.models.
|
|
149
|
-
| `ai.
|
|
150
|
-
| `ai.
|
|
151
|
-
| `ai.audio.models.
|
|
152
|
-
| `ai.audio.models.
|
|
153
|
-
| `ai.audio.models.
|
|
154
|
-
| `ai.
|
|
155
|
-
| `ai.
|
|
156
|
-
| `ai.image.models.
|
|
157
|
-
| `ai.image.models.
|
|
158
|
-
| `ai.image.models.
|
|
159
|
-
| `ai.
|
|
160
|
-
| `ai.
|
|
161
|
-
| `ai.mcp.servers.
|
|
162
|
-
| `ai.mcp.servers.
|
|
163
|
-
| `ai.mcp.servers.
|
|
164
|
-
| `ai.
|
|
165
|
-
| `ai.
|
|
166
|
-
| `ai.retrieval.sources.
|
|
167
|
-
| `ai.retrieval.sources.
|
|
168
|
-
| `ai.retrieval.sources.
|
|
169
|
-
| `ai.
|
|
170
|
-
| `ai.
|
|
171
|
-
| `ai.acp.agents.
|
|
172
|
-
| `ai.acp.agents.
|
|
173
|
-
| `ai.acp.agents.
|
|
174
|
-
| `ai.acp.
|
|
175
|
-
| `ai.acp.
|
|
176
|
-
| `ai.acp.workspaces.
|
|
177
|
-
| `ai.acp.workspaces.
|
|
178
|
-
| `ai.acp.workspaces.
|
|
179
|
-
| `ai.acp.
|
|
180
|
-
| `ai.acp.
|
|
181
|
-
| `ai.acp.
|
|
182
|
-
| `ai.acp.
|
|
183
|
-
| `ai.acp.
|
|
184
|
-
| `ai.acp.
|
|
185
|
-
| `ai.acp.sessions.
|
|
186
|
-
| `ai.acp.sessions.
|
|
187
|
-
| `ai.acp.sessions.
|
|
188
|
-
| `ai.acp.sessions.
|
|
189
|
-
| `ai.acp.sessions.
|
|
190
|
-
| `ai.acp.
|
|
191
|
-
| `ai.acp.
|
|
52
|
+
| 入口 | 用途 | 入力 | 出力 | 呼出し断片 |
|
|
53
|
+
| --------------------------------- | -------------------------------------- | --------------------------------------------------------------------------------- | ------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------- |
|
|
54
|
+
| `ai.llm.chat` | 単発応答 | `ChatCompletionRequest: messages, model?, signal?, tools?` | `ChatCompletionResponse: choices, model, usage?` | `ai.llm.chat({ messages: [{ role: "user", content: "你好" }] })` |
|
|
55
|
+
| `ai.llm.chatStream` | 増分応答 | `same ChatCompletionRequest` | `AsyncIterable<ChatCompletionChunk>; iteration may throw` | `ai.llm.chatStream({ messages })` |
|
|
56
|
+
| `ai.llm.ask` | テキスト応答 | `question: string, AskOptions?` | `string answer` | `ai.llm.ask("解释共享状态")` |
|
|
57
|
+
| `ai.llm.askStream` | テキストストリーム | `question: string, AskOptions?` | `AsyncIterable<string>` | `ai.llm.askStream("解释共享状态")` |
|
|
58
|
+
| `ai.llm.generateObject` | Schema 制約付き応答 | `Zod schema, messages, model?, responseFormat?, maxRepairs?, signal?` | `schema-inferred T` | `ai.llm.generateObject({ schema: AnswerSchema, messages })` |
|
|
59
|
+
| `ai.llm.listModels` | モデル一覧 | `none` | `string[] model IDs` | `ai.llm.listModels()` |
|
|
60
|
+
| `ai.llm.getHistory` | 会話履歴 | `{ objectId, sessionId }, { limit?, order? }?` | `ChatRecord[]` | `ai.llm.getHistory({ objectId: "u1", sessionId: "s1" })` |
|
|
61
|
+
| `ai.llm.listSessions` | 主体の会話一覧 | `objectId: string` | `SessionInfo[]` | `ai.llm.listSessions("u1")` |
|
|
62
|
+
| `ai.tools.define` | ツールを定義 | `{ name, description, parameters: Zod schema, handler, timeoutMs? }` | `direct Tool<TInput,TOutput>; no init required` | `ai.tools.define(toolDefinition)` |
|
|
63
|
+
| `ai.tools.createRegistry` | ツール一覧を管理 | `{ authorize? }?` | `direct ToolRegistryOperations; no init required` | `ai.tools.createRegistry({ authorize })` |
|
|
64
|
+
| `ai.stream.createProcessor` | 増分を蓄積 | `none` | `direct StreamProcessor` | `ai.stream.createProcessor()` |
|
|
65
|
+
| `ai.stream.collect` | 対話ストリームを消費 | `AsyncIterable<ChatCompletionChunk>` | `Promise<StreamResult>; stream failure rejects` | `ai.stream.collect(ai.llm.chatStream({ messages }))` |
|
|
66
|
+
| `ai.stream.createSSEDecoder` | 分割 SSE の復号 | `none` | `direct SSEDecoder with decode/reset` | `ai.stream.createSSEDecoder()` |
|
|
67
|
+
| `ai.stream.encodeSSE` | SSE を符号化 | `SSEEvent: data, event?, id?, retry?` | `direct string; invalid metadata throws` | `ai.stream.encodeSSE({ data: "Hello" })` |
|
|
68
|
+
| `ai.embedding.embed` | 埋め込み要求 | `EmbeddingRequest with input/model?` | `EmbeddingResponse` | `ai.embedding.embed({ input: "产品说明" })` |
|
|
69
|
+
| `ai.embedding.embedText` | 一文のベクトル | `text: string` | `number[]` | `ai.embedding.embedText("产品说明")` |
|
|
70
|
+
| `ai.embedding.embedBatch` | 複数文のベクトル | `texts: string[]` | `number[][] in input order` | `ai.embedding.embedBatch(["简介", "部署"])` |
|
|
71
|
+
| `ai.mcp.registerTool` | ローカルツール登録 | `MCPToolDefinition, typed handler` | `void` | `ai.mcp.registerTool(mcpToolDefinition, toolHandler)` |
|
|
72
|
+
| `ai.mcp.registerResource` | 資源登録 | `MCPResource, async content handler` | `void` | `ai.mcp.registerResource(resourceDefinition, readContent)` |
|
|
73
|
+
| `ai.mcp.registerPrompt` | プロンプト登録 | `MCPPrompt, args => Promise<MCPPromptMessage[]>` | `void` | `ai.mcp.registerPrompt(promptDefinition, buildMessages)` |
|
|
74
|
+
| `ai.mcp.callTool` | 登録済みツール呼出し | `name, arguments, MCPContext?` | `unknown tool result` | `ai.mcp.callTool("search", { query: "配置" })` |
|
|
75
|
+
| `ai.mcp.readResource` | 資源読取 | `resource URI` | `MCPResourceContent with exactly text or blob` | `ai.mcp.readResource("docs://intro")` |
|
|
76
|
+
| `ai.mcp.getPrompt` | プロンプト生成 | `name, Record<string,string> arguments` | `MCPPromptMessage[]` | `ai.mcp.getPrompt("review", { topic: "API" })` |
|
|
77
|
+
| `ai.mcp.services.invoke` | 許可されたリモートツールの呼び出し | リクエスト、認証済み主体、認可関数 | `HaiResult<CallToolResult>` | `ai.mcp.services.invoke(request, authorization)` |
|
|
78
|
+
| `ai.mcp.services.createBroker` | ACP セッション用ツールのエンドポイント | 固定 URL と呼び出しごとの認可関数 | `HaiResult<MCPServiceBroker>` | `ai.mcp.services.createBroker(brokerOptions)` |
|
|
79
|
+
| `ai.retrieval.addSource` | 検索元を登録 | `RetrievalSource: id, collection, optional metadata` | `void` | `ai.retrieval.addSource({ id: "docs", collection: "manual" })` |
|
|
80
|
+
| `ai.retrieval.removeSource` | 検索元を解除 | `sourceId: string` | `void` | `ai.retrieval.removeSource("docs")` |
|
|
81
|
+
| `ai.retrieval.listSources` | 検索元一覧 | `none` | `direct Promise<RetrievalSource[]>` | `ai.retrieval.listSources()` |
|
|
82
|
+
| `ai.retrieval.retrieve` | 候補検索 | `RetrievalRequest: query, sources?, topK?, minScore?, enableRerank?` | `RetrievalResult` | `ai.retrieval.retrieve({ query: "部署" })` |
|
|
83
|
+
| `ai.rag.query` | 根拠付き応答 | `query: string, RagOptions?` | `RagResult: answer, context, citations, query, model` | `ai.rag.query("如何部署?", { sources: ["docs"] })` |
|
|
84
|
+
| `ai.rag.queryStream` | 根拠付きストリーム | `query: string, RagOptions?` | `AsyncIterable<RagStreamEvent>` | `ai.rag.queryStream("如何部署?", { sources: ["docs"] })` |
|
|
85
|
+
| `ai.knowledge.setup` | コレクションを準備 | `KnowledgeSetupOptions?` | `void; collection ready for ingest` | `ai.knowledge.setup()` |
|
|
86
|
+
| `ai.knowledge.ingest` | 文書を公開 | `{ documentId, content, title?, collection?, ...metadata }` | `KnowledgeIngestResult with revision/cleanupPending` | `ai.knowledge.ingest({ documentId: "intro", content: "入门正文" })` |
|
|
87
|
+
| `ai.knowledge.ingestFile` | ファイルを取込 | `KnowledgeIngestFileInput including file bytes and document identity` | `KnowledgeIngestResult` | `ai.knowledge.ingestFile(fileInput)` |
|
|
88
|
+
| `ai.knowledge.ingestBatch` | 一括取込 | `KnowledgeIngestInput[], onProgress?` | `KnowledgeIngestBatchResult with per-document outcomes` | `ai.knowledge.ingestBatch(documentInputs, onProgress)` |
|
|
89
|
+
| `ai.knowledge.retrieve` | 公開版の検索 | `query: string, KnowledgeRetrieveOptions?` | `KnowledgeRetrieveResult` | `ai.knowledge.retrieve("部署说明")` |
|
|
90
|
+
| `ai.knowledge.ask` | 知識に基づく応答 | `query: string, KnowledgeAskOptions?` | `KnowledgeAskResult` | `ai.knowledge.ask("如何恢复备份?")` |
|
|
91
|
+
| `ai.knowledge.findByEntity` | 実体から資料検索 | `entityName: string, EntityQueryOptions?` | `EntityDocumentResult[]` | `ai.knowledge.findByEntity("订单")` |
|
|
92
|
+
| `ai.knowledge.listEntities` | 実体一覧 | `EntityListOptions?` | `KnowledgeEntity[]` | `ai.knowledge.listEntities()` |
|
|
93
|
+
| `ai.knowledge.listDocuments` | 文書一覧 | `KnowledgeDocumentListOptions?` | `KnowledgeDocumentInfo[]` | `ai.knowledge.listDocuments()` |
|
|
94
|
+
| `ai.knowledge.removeDocument` | 文書の公開解除 | `documentId, KnowledgeDocumentRemoveOptions?` | `void; may fail after visibility revocation if cleanup fails` | `ai.knowledge.removeDocument("intro")` |
|
|
95
|
+
| `ai.knowledge.repair` | 残留ベクトルの補償 | `{ collection?, offset?, limit? }` | `KnowledgeRepairResult with progress` | `ai.knowledge.repair({ offset: 0, limit: 100 })` |
|
|
96
|
+
| `ai.knowledge.deleteCollection` | コレクションを解除 | `collection name?` | `void; cleanup tombstone remains` | `ai.knowledge.deleteCollection("retired-manual")` |
|
|
97
|
+
| `ai.memory.scoped` | 信頼する主体を束縛 | `{ objectId: nonempty string, scope? }` | `direct ScopedMemoryOperations; invalid binding throws TypeError` | `ai.memory.scoped({ objectId: "u1", scope: { topicId: "orders" } })` |
|
|
98
|
+
| `ai.memory.extract` | 記憶を抽出 | `ChatMessage[], { objectId, scope?, model?, signal?, ...options }` | `MemoryEntry[]` | `ai.memory.extract(messages, { objectId: "u1" })` |
|
|
99
|
+
| `ai.memory.add` | 明示的記憶を保存 | `MemoryEntryInput: objectId, content, type, scope?` | `MemoryEntry` | `ai.memory.add({ objectId: "u1", content: "偏好中文", type: "preference" })` |
|
|
100
|
+
| `ai.memory.get` | 所有者の記憶を読取 | `memoryId, { objectId, scope? } for untrusted IDs` | `MemoryEntry` | `ai.memory.get(memoryId, { objectId: "u1" })` |
|
|
101
|
+
| `ai.memory.update` | 記憶を更新 | `memoryId, MemoryUpdateInput, trusted access scope` | `MemoryEntry` | `ai.memory.update(memoryId, { content: "偏好日文" }, { objectId: "u1" })` |
|
|
102
|
+
| `ai.memory.remove` | 所有者の記憶を削除 | `memoryId, trusted access scope` | `void` | `ai.memory.remove(memoryId, { objectId: "u1" })` |
|
|
103
|
+
| `ai.memory.recall` | 関連記憶の検索 | `query, { objectId, scope?, topK?, types?, ...options }` | `MemoryEntry[]` | `ai.memory.recall("语言偏好", { objectId: "u1" })` |
|
|
104
|
+
| `ai.memory.injectMemories` | 会話の文脈を補足 | `ChatMessage[], { objectId, scope?, topK?, ...options }` | `ChatMessage[]` | `ai.memory.injectMemories(messages, { objectId: "u1" })` |
|
|
105
|
+
| `ai.memory.list` | 記憶一覧 | `MemoryListOptions with objectId/scope filters` | `MemoryEntry[]; incomplete scan fails` | `ai.memory.list({ objectId: "u1" })` |
|
|
106
|
+
| `ai.memory.listPage` | 記憶のページ表示 | `MemoryListPageOptions with objectId/pagination` | `StorePage<MemoryEntry>` | `ai.memory.listPage({ objectId: "u1", offset: 0, limit: 20 })` |
|
|
107
|
+
| `ai.memory.clear` | 指定範囲を解除 | `nonempty MemoryClearOptions` | `void; empty filters are rejected` | `ai.memory.clear({ objectId: "u1" })` |
|
|
108
|
+
| `ai.memory.admin.clearAll` | 信頼された管理者の全解除 | `{ confirm: true }; require host administrator authorization` | `void; destructive across subjects` | `ai.memory.admin.clearAll({ confirm: true })` |
|
|
109
|
+
| `ai.persona.save` | ペルソナを保存 | `PersonaProfileInput: id, name, systemPrompt, objectId?, traits?` | `PersonaProfile` | `ai.persona.save(personaProfile)` |
|
|
110
|
+
| `ai.persona.get` | ペルソナを読取 | `id, { objectId }?; omitted subject selects system profile` | `PersonaProfile` | `ai.persona.get("tutor", { objectId: "u1" })` |
|
|
111
|
+
| `ai.persona.update` | ペルソナを更新 | `id, PersonaProfileUpdate, { objectId }?` | `PersonaProfile` | `ai.persona.update("tutor", updates, { objectId: "u1" })` |
|
|
112
|
+
| `ai.persona.remove` | ペルソナを削除 | `id, { objectId }?` | `void` | `ai.persona.remove("tutor", { objectId: "u1" })` |
|
|
113
|
+
| `ai.persona.list` | ペルソナ一覧 | `{ objectId }?` | `PersonaProfile[]` | `ai.persona.list({ objectId: "u1" })` |
|
|
114
|
+
| `ai.persona.compose` | システム指示を合成 | `id, { objectId }?` | `string prompt` | `ai.persona.compose("tutor", { objectId: "u1" })` |
|
|
115
|
+
| `ai.token.estimateText` | 文章 Token の推定 | `text: string` | `direct number; estimate, not billing usage` | `ai.token.estimateText("Hello 世界")` |
|
|
116
|
+
| `ai.token.estimateMessages` | メッセージ Token の推定 | `ChatMessage[]` | `direct number including protocol overhead` | `ai.token.estimateMessages(messages)` |
|
|
117
|
+
| `ai.summary.generate` | 要約本文を生成 | `ChatMessage[], SummaryOptions?` | `string` | `ai.summary.generate(messages)` |
|
|
118
|
+
| `ai.summary.summarize` | 要約と対象情報 | `ChatMessage[], SummaryOptions?` | `{ summary, tokenCount, coveredMessages }` | `ai.summary.summarize(messages)` |
|
|
119
|
+
| `ai.compress.tryCompress` | 予算に合わせて圧縮 | `ChatMessage[], { strategy?, maxTokens?, preserveLastN?, ...options }` | `CompressResult: messages and original/compressed token counts` | `ai.compress.tryCompress(messages, { maxTokens: 4000 })` |
|
|
120
|
+
| `ai.context.createManager` | 複数回対話を開始 | `ContextManagerOptions with scope { objectId, sessionId }` | `ContextManager` | `ai.context.createManager({ scope: { objectId: "u1", sessionId: "s1" } })` |
|
|
121
|
+
| `ai.context.restoreManager` | 対話を復元 | `{ objectId, sessionId }, options?` | `ContextManager` | `ai.context.restoreManager({ objectId: "u1", sessionId: "s1" })` |
|
|
122
|
+
| `ai.context.listSessions` | 保存会話を一覧 | `objectId` | `SessionInfo[]` | `ai.context.listSessions("u1")` |
|
|
123
|
+
| `ai.context.renameSession` | 会話名を変更 | `scope, title` | `void` | `ai.context.renameSession({ objectId: "u1", sessionId: "s1" }, "订单讨论")` |
|
|
124
|
+
| `ai.context.removeSession` | 会話を削除 | `scope` | `void; tombstone prevents scope reuse` | `ai.context.removeSession({ objectId: "u1", sessionId: "s1" })` |
|
|
125
|
+
| `ai.rerank.rerank` | 文書の順位付け | `RerankRequest: query, documents, model?, topN?` | `RerankResponse with model/results` | `ai.rerank.rerank({ query: "部署", documents: ["配置说明"] })` |
|
|
126
|
+
| `ai.rerank.rerankTexts` | テキストの順位付け | `query, string[] texts, topN?` | `RerankItem[] with index/relevanceScore` | `ai.rerank.rerankTexts("部署", ["配置说明"], 1)` |
|
|
127
|
+
| `ai.file.parse` | ファイル解析 | `FileParseRequest with content, filename, options?` | `FileParseResult; extraction is not HTML sanitization` | `ai.file.parse({ content: "<p>正文</p>", filename: "intro.html" })` |
|
|
128
|
+
| `ai.file.parseText` | 本文抽出 | `Buffer\|string content, filename?` | `string` | `ai.file.parseText("Hello", "intro.txt")` |
|
|
129
|
+
| `ai.reasoning.run` | 多段推論 | `query, ReasoningOptions including strategy/tools?` | `ReasoningResult` | `ai.reasoning.run("审查方案", { strategy: "cot" })` |
|
|
130
|
+
| `ai.reasoning.runStream` | 推論過程を観察 | `query, ReasoningOptions?` | `AsyncIterable<ReasoningStreamEvent>` | `ai.reasoning.runStream("审查方案", { strategy: "react" })` |
|
|
131
|
+
| `ai.audio.transcribe` | 音声認識 | `TranscriptionRequest: audio, language?, model?, signal?` | `TranscriptionResult: text, language?, segments?` | `ai.audio.transcribe({ audio: { data: wavBytes, format: "wav" } })` |
|
|
132
|
+
| `ai.audio.transcribeStream` | 連続音声認識 | `TranscriptionStreamRequest: chunks or complete audio` | `AsyncIterable<TranscriptionEvent>` | `ai.audio.transcribeStream(transcriptionInput)` |
|
|
133
|
+
| `ai.audio.synthesize` | 音声合成 | `SynthesisRequest: text, language?, model?, signal?` | `SynthesisResult: audio and duration metadata` | `ai.audio.synthesize({ text: "你好" })` |
|
|
134
|
+
| `ai.audio.synthesizeStream` | 区間ごとの音声合成 | `SynthesisStreamRequest: text segment or async segments` | `AsyncIterable<SynthesisEvent>` | `ai.audio.synthesizeStream(synthesisInput)` |
|
|
135
|
+
| `ai.audio.getCapabilities` | 能力を先に確認 | `{ operation: transcribe\|synthesize, model? }` | `AudioModelCapabilities` | `ai.audio.getCapabilities({ operation: "synthesize" })` |
|
|
136
|
+
| `ai.image.generate` | 画像生成 | `{ prompt, referenceImages?, model?, size?, signal? }` | `{ images: GeneratedImage[] } with bytes/MIME` | `ai.image.generate({ prompt: "一座灯塔" })` |
|
|
137
|
+
| `ai.a2a.registerExecutor` | 実行器の登録 | `SDK AgentExecutor` | `void` | `ai.a2a.registerExecutor(executor)` |
|
|
138
|
+
| `ai.a2a.getAgentCard` | 標準発見文書 | `none; configured a2a card` | `A2AAgentCardDocument (A2A 1.0 ProtoJSON)` | `ai.a2a.getAgentCard()` |
|
|
139
|
+
| `ai.a2a.handleRequest` | 認証済み要求を処理 | `unknown JSON-RPC body, trusted context.agentId?` | `direct Promise<A2AHandleResult>; JSON-RPC/SSE outcome` | `ai.a2a.handleRequest(body, { agentId: trustedAgentId })` |
|
|
140
|
+
| `ai.a2a.listMessages` | 管理用メッセージ検索 | `A2ATaskFilter: callerId?, contextId?, since?, pagination?` | `StorePage<A2AMessageRecord>` | `ai.a2a.listMessages(messageFilter)` |
|
|
141
|
+
| `ai.a2a.callRemoteAgent` | 許可された遠隔を呼出し | `allowlisted HTTPS URL, message, A2ACallOptions?` | `A2ACallResult` | `ai.a2a.callRemoteAgent("https://agent.example.com/a2a", "请分析订单")` |
|
|
142
|
+
| `ai.init` | サービス準備 | `AIConfigInput?, AIInitOptions?` | `HaiResult<void>; validate dependencies before use` | `ai.init({ llm: { apiKey: process.env.HAI_AI_LLM_APIKEY } })` |
|
|
143
|
+
| `ai.close` | サービス解放 | `none` | `Promise<void>; wait for cleanup` | `ai.close()` |
|
|
144
|
+
| `ai.config` | 安全な設定参照 | `none` | `redacted AIConfig or null` | `ai.config` |
|
|
145
|
+
| `ai.isInitialized` | 状態確認 | `none` | `boolean` | `ai.isInitialized` |
|
|
146
|
+
| `ai.llm.models.list` | 統合した一覧 | `none` | `HaiResult<AIResourceEntry[]>; config wins, list has no database version` | `ai.llm.models.list()` |
|
|
147
|
+
| `ai.llm.models.get` | 出所と版を参照 | `id: string` | `HaiResult<AIResourceEntry> with value/source/version?` | `ai.llm.models.get("coding")` |
|
|
148
|
+
| `ai.llm.models.register` | DB 定義を登録 | `ModelEntry input (id/model/protocol/credentials/capabilities)` | `HaiResult<AIResourceEntry>; config entries are read-only` | `ai.llm.models.register(modelDefinition)` |
|
|
149
|
+
| `ai.llm.models.update` | 版を条件に置換 | `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` | DB 定義を削除 | `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` | 統合した一覧 | `none` | `HaiResult<AIResourceEntry[]>; config wins, list has no database version` | `ai.audio.models.list()` |
|
|
152
|
+
| `ai.audio.models.get` | 出所と版を参照 | `id: string` | `HaiResult<AIResourceEntry> with value/source/version?` | `ai.audio.models.get("speech")` |
|
|
153
|
+
| `ai.audio.models.register` | DB 定義を登録 | `AudioModelEntry input (id/provider/model/operations)` | `HaiResult<AIResourceEntry>; config entries are read-only` | `ai.audio.models.register(audioModelDefinition)` |
|
|
154
|
+
| `ai.audio.models.update` | 版を条件に置換 | `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` | DB 定義を削除 | `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` | 統合した一覧 | `none` | `HaiResult<AIResourceEntry[]>; config wins, list has no database version` | `ai.image.models.list()` |
|
|
157
|
+
| `ai.image.models.get` | 出所と版を参照 | `id: string` | `HaiResult<AIResourceEntry> with value/source/version?` | `ai.image.models.get("poster")` |
|
|
158
|
+
| `ai.image.models.register` | DB 定義を登録 | `ImageModelEntry input (id/provider/model)` | `HaiResult<AIResourceEntry>; config entries are read-only` | `ai.image.models.register(imageModelDefinition)` |
|
|
159
|
+
| `ai.image.models.update` | 版を条件に置換 | `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` | DB 定義を削除 | `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` | 統合した一覧 | `none` | `HaiResult<AIResourceEntry[]>; config wins, list has no database version` | `ai.mcp.servers.list()` |
|
|
162
|
+
| `ai.mcp.servers.get` | 出所と版を参照 | `id: string` | `HaiResult<AIResourceEntry> with value/source/version?` | `ai.mcp.servers.get("tools")` |
|
|
163
|
+
| `ai.mcp.servers.register` | DB 定義を登録 | `MCPExternalServer input (id/transport/url or command)` | `HaiResult<AIResourceEntry>; config entries are read-only` | `ai.mcp.servers.register(mcpServerDefinition)` |
|
|
164
|
+
| `ai.mcp.servers.update` | 版を条件に置換 | `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` | DB 定義を削除 | `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` | 統合した一覧 | `none` | `HaiResult<AIResourceEntry[]>; config wins, list has no database version` | `ai.retrieval.sources.list()` |
|
|
167
|
+
| `ai.retrieval.sources.get` | 出所と版を参照 | `id: string` | `HaiResult<AIResourceEntry> with value/source/version?` | `ai.retrieval.sources.get("docs")` |
|
|
168
|
+
| `ai.retrieval.sources.register` | DB 定義を登録 | `RetrievalSource input (id/collection)` | `HaiResult<AIResourceEntry>; config entries are read-only` | `ai.retrieval.sources.register(sourceDefinition)` |
|
|
169
|
+
| `ai.retrieval.sources.update` | 版を条件に置換 | `RetrievalSource input (id/collection), expectedVersion?` | `HaiResult<AIResourceEntry>; full replacement, conflict fails` | `ai.retrieval.sources.update(sourceDefinition, current.data.version)` |
|
|
170
|
+
| `ai.retrieval.sources.remove` | DB 定義を削除 | `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` | 統合した一覧 | `none` | `HaiResult<AIResourceEntry[]>; config wins, list has no database version` | `ai.acp.agents.list()` |
|
|
172
|
+
| `ai.acp.agents.get` | 出所と版を参照 | `id: string` | `HaiResult<AIResourceEntry> with value/source/version?` | `ai.acp.agents.get("coder")` |
|
|
173
|
+
| `ai.acp.agents.register` | DB 定義を登録 | `ACPAgent input (id/mode/adapter/modelIds)` | `HaiResult<AIResourceEntry>; config entries are read-only` | `ai.acp.agents.register(agentDefinition)` |
|
|
174
|
+
| `ai.acp.agents.update` | 版を条件に置換 | `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` | DB 定義を削除 | `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` | 統合した一覧 | `none` | `HaiResult<AIResourceEntry[]>; config wins, list has no database version` | `ai.acp.workspaces.list()` |
|
|
177
|
+
| `ai.acp.workspaces.get` | 出所と版を参照 | `id: string` | `HaiResult<AIResourceEntry> with value/source/version?` | `ai.acp.workspaces.get("project")` |
|
|
178
|
+
| `ai.acp.workspaces.register` | DB 定義を登録 | `ACPWorkspace input (id/storage/repositories)` | `HaiResult<AIResourceEntry>; config entries are read-only` | `ai.acp.workspaces.register(workspaceDefinition)` |
|
|
179
|
+
| `ai.acp.workspaces.update` | 版を条件に置換 | `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` | DB 定義を削除 | `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` | エージェント事前確認 | `agentId, modelId?` | `HaiResult<{ agentId, mode, modelIds }>; no credentials` | `ai.acp.agents.initialize("coder")` |
|
|
182
|
+
| `ai.acp.agents.check` | 実接続と握手 | `agentId, { workspaceId?, ...ACPClientOptions }` | `HaiResult<native initialize response>; owned connection is closed` | `ai.acp.agents.check("coder", { workspaceId: "project" })` |
|
|
183
|
+
| `ai.acp.workspaces.prepare` | 作業領域を準備 | `workspaceId` | `HaiResult<main absolute path>; dirty content is retained` | `ai.acp.workspaces.prepare("project")` |
|
|
184
|
+
| `ai.acp.workspaces.importFiles` | 制御ファイル取込 | `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` | 管理会話を開始 | `ACPCreateSessionOptions: agentId/workspaceId/newWorktree?` | `HaiResult<managed session handle>` | `ai.acp.sessions.create({ agentId: "coder", workspaceId: "project", newWorktree: true })` |
|
|
186
|
+
| `ai.acp.sessions.get` | 会話ハンドル参照 | `framework session id` | `HaiResult<managed session handle>; does not resume` | `ai.acp.sessions.get("task-1")` |
|
|
187
|
+
| `ai.acp.sessions.list` | 管理会話一覧 | `workspaceId?` | `HaiResult<ACPSessionInfo[]>` | `ai.acp.sessions.list("project")` |
|
|
188
|
+
| `ai.acp.sessions.resume` | ネイティブ会話再開 | `framework session id, ACPClientOptions?` | `HaiResult<managed session handle>; definition changes may reject` | `ai.acp.sessions.resume("task-1")` |
|
|
189
|
+
| `ai.acp.sessions.close` | 所有する実行を停止 | `framework session id` | `HaiResult<void>; source and native history retained` | `ai.acp.sessions.close("task-1")` |
|
|
190
|
+
| `ai.acp.sessions.reclaimWorktree` | 清浄な 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` | 会話記録を削除 | `closed or failed framework session id` | `HaiResult<void>; worktree and native history retained` | `ai.acp.sessions.remove("task-1")` |
|
|
192
|
+
| `ai.acp.connect` | 原生転送へ接続 | `ACPTransport: stdio/http/ws, ACPClientOptions?` | `HaiResult<connection handle>` | `ai.acp.connect({ type: "http", url: "https://agent.example.com/acp" })` |
|
|
193
|
+
| `ai.acp.close` | サブシステムを閉じる | `none; normally call ai.close()` | `Promise<void>; cleanup may throw` | `ai.acp.close()` |
|
|
192
194
|
|
|
193
195
|
- `ai.tools`:ツール定義・登録・一括実行。初期化不要。
|
|
194
196
|
- `ai.stream`:ChatCompletion のストリーミング chunk 処理。初期化不要。
|
|
@@ -321,6 +323,29 @@ const temp = await ai.llm.chat({
|
|
|
321
323
|
|
|
322
324
|
SSE は [WHATWG のイベントストリーム規則](https://html.spec.whatwg.org/multipage/server-sent-events.html#event-stream-interpretation)に従い、分割された LF/CRLF/CR、複数 data 行、コロン直後の空白一つ、id/retry の継承、既定の message を扱います。EOF の未完了イベントは配信しません。encodeSSE は data の改行を正規化し、不正なメタデータは明示的に例外を返します。Anthropic/MiMo は UTF-8 reader を共有し、終了・取消・失敗時に本文を取消して解放します。自動再接続や業務再実行は行わず、Anthropic の timeout は本文まで、MiMo は各 HTTP リクエスト単位で適用します。
|
|
323
325
|
|
|
326
|
+
##### `ai.llm.generateObject` で構造化出力を得る
|
|
327
|
+
|
|
328
|
+
モデルまたはゲートウェイの対応機能に合わせて `responseFormat` を選びます。既定の `json_schema` は厳密な JSON Schema を上流へ送ります。`schemaName` はこの方式だけで使い、既定値は `result` です。汎用 JSON モードの Chat ゲートウェイには `json_object` を指定し、フレームワークが Schema をプロンプトに含めます。両方式とも同じ Zod Schema でローカル検証を行います。解析・検証に失敗したときの修復回数は `maxRepairs` で制御し、既定は 1 回です。
|
|
329
|
+
|
|
330
|
+
```ts
|
|
331
|
+
import { ai } from '@h-ai/ai'
|
|
332
|
+
import { z } from 'zod'
|
|
333
|
+
|
|
334
|
+
// 汎用 JSON モードに対応するテキストモデルで AI を初期化済み。
|
|
335
|
+
const result = await ai.llm.generateObject({
|
|
336
|
+
schema: z.object({
|
|
337
|
+
title: z.string()
|
|
338
|
+
}), // title 文字列を持つオブジェクトを要求する。
|
|
339
|
+
messages: [
|
|
340
|
+
{ role: 'user', content: 'リリース確認表のタイトルを考えてください。' }
|
|
341
|
+
], // 今回の入力。
|
|
342
|
+
responseFormat: 'json_object', // 汎用 JSON を要求し、Zod でローカル検証する。
|
|
343
|
+
maxRepairs: 1, // 解析または検証の失敗後に 1 回だけ修復を試す。
|
|
344
|
+
})
|
|
345
|
+
if (result.success)
|
|
346
|
+
process.stdout.write(result.data.title) // 例: リリース確認表。
|
|
347
|
+
```
|
|
348
|
+
|
|
324
349
|
#### ツール呼び出し
|
|
325
350
|
|
|
326
351
|
```ts
|
|
@@ -375,10 +400,75 @@ Goose 1.57.0 イメージは `goose serve` のネイティブ HTTP/WS `/acp` を
|
|
|
375
400
|
|
|
376
401
|
確認済み容量、モダリティ、推論能力は `llm.models[].capabilities` に設定します。Codex は Responses を必要とし、既存 Hai 変換は逆方向ゲートウェイではありません。close 後もコード/状態を保持し、所有プロセス停止を確認後 CAS 占有を解放します。worktree はセキュリティサンドボックスではありません。
|
|
377
402
|
|
|
378
|
-
|
|
403
|
+
Agent イメージのビルドでは `minimal`、`documents`、`office`、`browser`、`developer` を選択できます。既定のイメージには Git、Node、ネイティブ Agent が含まれ、Codex には bubblewrap も含まれます。実行環境にはローカルのイメージ ID またはリモートのマニフェスト digest を登録します。[Agent イメージ](models/agents/README.md)
|
|
404
|
+
|
|
405
|
+
ACP は Node サービスで実行します。通常の API は HaiResult を返し、ストリームの失敗は例外になります。[ACP ガイド](../cli/templates/skills/hai-ai/acp.md)
|
|
379
406
|
|
|
380
407
|
管理対象 Git でサブモジュールや Git LFS 属性を検出すると ACP_UNSUPPORTED を返し、不完全な内容を準備完了として扱いません。
|
|
381
408
|
|
|
409
|
+
##### 認証済みユーザーの管理対象 ACP を実行する
|
|
410
|
+
|
|
411
|
+
RelDB と [Runner](../runner/README.ja.md) を起動し、起動済みのインスタンスを `ai.init(config, { runner, acpPolicy })` に渡します。`acp.agents` に Agent を登録し、`environmentIds` で固定イメージの Runner 環境を、`modelIds` で `llm.models` のモデルを指定します。Codex には Responses ゲートウェイが必要です。API ノードと実行ノードではデータベースと環境定義を揃えます。終了時は AI、Runner、データベースの順に閉じます。
|
|
412
|
+
|
|
413
|
+
`task` はそのセッション用の専用 Worker を起動します。`user` は主体と起動設定が一致する場合に Worker を再利用できます。`auto` はアプリのポリシーに基づいて選択します。`shared` を利用できるのは、共有を明示的に承認した読み取り専用アダプターで、非公開コンテキスト、ワークスペース、ツールを要求しない場合です。組み込みの Codex、DeepSeek Harness、Goose は専用モードを使用します。[ACP 設定例](../../docs/usage/configuration/ai.md#acp-接入与模型能力)
|
|
414
|
+
|
|
415
|
+
```ts
|
|
416
|
+
import type { RunnerScope } from '@h-ai/runner' // 認証済みアプリセッションから tenantId と userId を取得する。
|
|
417
|
+
import { ai } from '@h-ai/ai' // Runner を渡して初期化済みのサーバーインスタンス。
|
|
418
|
+
|
|
419
|
+
async function summarize(identity: RunnerScope, requestId: string) {
|
|
420
|
+
const agent = ai.acp.scoped(identity) // 以降のジョブ、セッション、承認をこの主体に紐づける。
|
|
421
|
+
const options = {
|
|
422
|
+
agentId: 'assistant',
|
|
423
|
+
execution: { mode: 'auto' as const }
|
|
424
|
+
} // assistant は登録済み Agent。
|
|
425
|
+
const plan = await agent.plan(options) // コンテナを取得せず、有効なモード、環境、モデル、リソースを返す。
|
|
426
|
+
if (!plan.success)
|
|
427
|
+
return plan // 環境や権限が合わない場合は投入しない。
|
|
428
|
+
const result = await agent.run({ ...options, prompt: 'リリースの確認項目を三つ挙げて', idempotencyKey: requestId }) // taskId、output、有効なオプションを返す。
|
|
429
|
+
if (!result.success)
|
|
430
|
+
return result // 投入、実行、後片付けの失敗を HaiResult として返す。
|
|
431
|
+
const events = await agent.tasks.events(result.data.taskId, 0, 20) // 最初の 20 イベントを読み、空なら []。
|
|
432
|
+
if (!events.success)
|
|
433
|
+
return events
|
|
434
|
+
return { result: result.data, events: events.data } // 例として output.text に回答、events に順序付きのイベントが入る。
|
|
435
|
+
}
|
|
436
|
+
```
|
|
437
|
+
|
|
438
|
+
```ts
|
|
439
|
+
import type { RunnerScope } from '@h-ai/runner' // サーバーで認証した主体。
|
|
440
|
+
import { ai } from '@h-ai/ai' // assistant を登録し、同じユーザー内の Worker 再利用が可能とする。
|
|
441
|
+
|
|
442
|
+
async function continueWork(identity: RunnerScope) {
|
|
443
|
+
const agent = ai.acp.scoped(identity) // アクセスをこの主体に紐づける。
|
|
444
|
+
const created = await agent.sessions.create({
|
|
445
|
+
agentId: 'assistant',
|
|
446
|
+
execution: { mode: 'user' }
|
|
447
|
+
}) // 成功時は id 付きのセッションハンドル。
|
|
448
|
+
if (!created.success)
|
|
449
|
+
return created
|
|
450
|
+
const session = created.data // prompt、stream、changeExecution、close が使える。
|
|
451
|
+
const run = async () => {
|
|
452
|
+
const first = await session.prompt('受け入れ条件を記録して') // このターンの taskId、output、有効なオプションを返す。
|
|
453
|
+
if (!first.success)
|
|
454
|
+
return first
|
|
455
|
+
const switched = await session.changeExecution({ mode: 'task', acceptNewSession: true }) // 業務上の id を維持し、新しいネイティブセッションを開始する。
|
|
456
|
+
if (!switched.success)
|
|
457
|
+
return switched
|
|
458
|
+
return await session.prompt('独立した受け入れチェックリストを出して') // 成功時の回答は data.output。
|
|
459
|
+
}
|
|
460
|
+
return run().finally(async () => {
|
|
461
|
+
const closed = await session.close() // 成功時の data は undefined。セッションまたは専用環境を解放する。
|
|
462
|
+
if (!closed.success)
|
|
463
|
+
throw new Error(closed.error.message)
|
|
464
|
+
})
|
|
465
|
+
}
|
|
466
|
+
```
|
|
467
|
+
|
|
468
|
+
`agents.describe(agentId)` で組み込みアダプターの機能を確認できます。`sessions.get(id)` は同じ主体が別の API ノードからハンドルを取得するために使います。`session.stream(prompt, options)` は保存済みイベントを順に返し、失敗時は例外を送出します。`tasks.get(taskId)` は実行受付票、`tasks.cancel(taskId)` はキャンセル受理後の状態を返します。`run` や `prompt` の `onEvent` に届く `accepted` イベントから `taskId` を取得し、別のリクエストで照会やキャンセルを行えます。
|
|
469
|
+
|
|
470
|
+
`acpPolicy` で `workspaceId` のスナップショット、ナレッジ、メモリ、ファイル、スキル、ツールを認可します。下記の MCP 入口には `allowTools` と `bindTools` を使います。`approval` イベントの `approvalId` に対して、同じ主体で `approvals.respond(id, 'allow-once' | 'allow-session' | 'always-allow' | 'deny')` を呼びます。成功時は `undefined` です。`approvals.rules(offset, limit)` は `expiresAt` を持つ有効なルールをページ取得し、`approvals.revoke(ruleId)` は主体自身のルールを取り消します。`full-access` にはアプリの明示的な承認と `task` モードが必要です。ワークスペースは読み取り専用スナップショットです。モード切り替え時にユーザーが確認した `historySummary` を渡せます。[管理対象 ACP の利用例](../../docs/usage/development/ai-acp.md#多用户应用的受管调用)
|
|
471
|
+
|
|
382
472
|
#### 設定とデータベースのリソース一覧
|
|
383
473
|
|
|
384
474
|
`llm.models`、`audio.models`、`image.models`、`mcp.servers`、`retrieval.sources`、`acp.agents/workspaces` は設定と DB を統合します。同じ ID は設定を優先し、設定は読み取り専用です。DB は list/get/register/update/remove に対応し、value/source/version と任意のバージョン照合を使用します。非同期呼び出しは最新の定義を読み、同期音声機能照会は直近のローカル情報を使います。エラーは 090–094。定義には認証情報が含まれるため、信頼できるサーバー管理 API として使用します。
|
|
@@ -423,6 +513,81 @@ await server.connect(new StreamableHTTPServerTransport({
|
|
|
423
513
|
}))
|
|
424
514
|
```
|
|
425
515
|
|
|
516
|
+
##### リモート MCP と独立ツールジョブを呼び出す
|
|
517
|
+
|
|
518
|
+
`mcp.servers` の `transport: http` に外部 Streamable HTTP の URL と `allowedTools` を登録します。認証には `headerEnv` からサーバーの環境変数を参照します。`transport: job` では同じ API からオフラインの文書、Office、OCR を実行できます。`environmentId`、許可する操作、任意の `pool` を設定し、Runner と `mcpJobFiles` を `ai.init` に渡します。ジョブには認可済みの `fileId` を渡します。実行ノードがアクセス権を再確認し、成果物をオブジェクト ID で返します。ブラウザーイメージは独立して運用します。[MCP の設定](../../docs/usage/configuration/ai.md#mcp和a2a) · [ツールイメージ](tools/README.md)
|
|
519
|
+
|
|
520
|
+
```ts
|
|
521
|
+
import type { MCPServiceAuthorization } from '@h-ai/ai' // IAM に基づく主体と、実際の引数を検証する認可コールバックを渡す。
|
|
522
|
+
import { ai } from '@h-ai/ai' // manual と office を登録済みのサーバーインスタンス。
|
|
523
|
+
|
|
524
|
+
async function searchManual(access: MCPServiceAuthorization, query: string) {
|
|
525
|
+
const result = await ai.mcp.services.invoke({
|
|
526
|
+
serviceId: 'manual',
|
|
527
|
+
tool: 'search_manual',
|
|
528
|
+
arguments: { query }
|
|
529
|
+
}, access) // 登録と認可を確認し、標準の MCP ツール結果を返す。
|
|
530
|
+
if (!result.success)
|
|
531
|
+
return result // 拒否または上流サービスの失敗を返す。
|
|
532
|
+
return result.data.content // 例: [{ type: 'text', text: '...' }]。
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
async function convertDocument(access: MCPServiceAuthorization, fileId: string) {
|
|
536
|
+
const result = await ai.mcp.services.invoke({
|
|
537
|
+
serviceId: 'office',
|
|
538
|
+
tool: 'office.convert',
|
|
539
|
+
arguments: { fileId }
|
|
540
|
+
}, access) // 認可済みオブジェクト ID でオフライン変換を投入する。
|
|
541
|
+
if (!result.success)
|
|
542
|
+
return result
|
|
543
|
+
return result.data.structuredContent // 例: { fileId: 'pdf-123', name: 'result.pdf' }。ダウンロード時に再認可する。
|
|
544
|
+
}
|
|
545
|
+
```
|
|
546
|
+
|
|
547
|
+
```ts
|
|
548
|
+
import type { MCPServiceAuthorization, MCPServiceBrokerOptions } from '@h-ai/ai' // デプロイ時の URL と、主体・ジョブ・引数を再確認する authorize を渡す。
|
|
549
|
+
import { createServer } from 'node:http' // 例の HTTP 入口を作成する。
|
|
550
|
+
import { ai } from '@h-ai/ai' // manual を登録済みのサーバーインスタンス。
|
|
551
|
+
|
|
552
|
+
function mountTools(options: MCPServiceBrokerOptions) {
|
|
553
|
+
const result = ai.mcp.services.createBroker(options) // 成功時は bind、handleRequest、close を提供する。
|
|
554
|
+
if (!result.success)
|
|
555
|
+
throw new Error(result.error.message)
|
|
556
|
+
const broker = result.data // 各実行ノードで Broker を作る。
|
|
557
|
+
const server = createServer((req, res) => {
|
|
558
|
+
void broker.handleRequest(req, res)
|
|
559
|
+
}) // 入口の MCP リクエストを処理する。
|
|
560
|
+
return { broker, server } // ホストが固定アドレスを待ち受け、通信を保護し、終了時に broker.close() と server.close() を呼ぶ。
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
async function bindManual(broker: ReturnType<typeof mountTools>['broker'], principal: MCPServiceAuthorization['principal'], sessionId: string, signal: AbortSignal) {
|
|
564
|
+
const result = await broker.bind({
|
|
565
|
+
principal,
|
|
566
|
+
taskId: sessionId,
|
|
567
|
+
signal,
|
|
568
|
+
tools: [
|
|
569
|
+
{
|
|
570
|
+
id: 'manual_search',
|
|
571
|
+
serviceId: 'manual',
|
|
572
|
+
tool: 'search_manual', // モデルに表示する名前と登録済みの操作名を設定する。
|
|
573
|
+
description: 'Search authorized manuals', // モデルに渡す説明。
|
|
574
|
+
inputSchema: {
|
|
575
|
+
type: 'object',
|
|
576
|
+
properties: {
|
|
577
|
+
query: { type: 'string' }
|
|
578
|
+
},
|
|
579
|
+
required: ['query'],
|
|
580
|
+
additionalProperties: false
|
|
581
|
+
}, // 呼び出し時に引数を検証する。
|
|
582
|
+
}
|
|
583
|
+
]
|
|
584
|
+
}) // 成功時は { servers, revoke }。servers に現在のセッション用の短期 Bearer が入る。
|
|
585
|
+
if (!result.success)
|
|
586
|
+
throw new Error(result.error.message)
|
|
587
|
+
return result.data // ACPPlatformPolicy.bindTools から返す。セッション終了時に資格情報が無効になる。
|
|
588
|
+
}
|
|
589
|
+
```
|
|
590
|
+
|
|
426
591
|
#### Memory / RAG / Knowledge
|
|
427
592
|
|
|
428
593
|
native 記憶の削除は管理者の全削除を含め、先にベクトルを削除してから権威レコードを削除します。ベクトル削除失敗時は再試行用にレコードを保持します。SQL とベクトルは同じトランザクションではないため、後段の失敗時も状態確認が必要です。
|
|
@@ -928,6 +1093,8 @@ const memories = await ai.memory.recall('经济发展', {
|
|
|
928
1093
|
|
|
929
1094
|
`ai.config` はマスク済み設定を返し、`apiKey`、`privateKey`、URL 内認証情報などをそのまま公開しません。
|
|
930
1095
|
|
|
1096
|
+
ネイティブメモリの追加は、共有データベースのトランザクション内で主体別と全体の上限を確認します。古い候補を一度に最大 64 件読み出し、重要度と経過時間から削除対象を選びます。既存データが上限を超えている間は、追加前に分割して整理します。カスタム共有 Store では `AIRelStore.withWriteLock` によって同じノード間の保証を提供できます。
|
|
1097
|
+
|
|
931
1098
|
## エラー処理
|
|
932
1099
|
|
|
933
1100
|
```ts
|