@h-ai/ai 0.1.0-alpha.12 → 0.1.0-alpha.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +20 -34
- package/dist/{ai-reasoning-types-DvnIDR7a.d.ts → ai-reasoning-types-C1uvQosU.d.ts} +23 -6
- package/dist/{ai-types-B8jZlb4E.d.ts → ai-types-GOmowSTF.d.ts} +1 -1
- package/dist/browser.d.ts +2 -2
- package/dist/browser.js +1 -1
- package/dist/{chunk-ABP7RKIP.js → chunk-Y5BQR7QA.js} +2 -2
- package/dist/chunk-Y5BQR7QA.js.map +1 -0
- package/dist/client/index.d.ts +10 -10
- package/dist/client/index.js +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +25 -0
- package/dist/index.js.map +1 -1
- package/package.json +5 -9
- package/dist/api/index.d.ts +0 -628
- package/dist/api/index.js +0 -243
- package/dist/api/index.js.map +0 -1
- package/dist/chunk-ABP7RKIP.js.map +0 -1
package/README.md
CHANGED
|
@@ -1404,76 +1404,62 @@ const prompt = await ai.mcp.getPrompt('greet', { name: '张三' })
|
|
|
1404
1404
|
|
|
1405
1405
|
---
|
|
1406
1406
|
|
|
1407
|
-
## 前端客户端 —
|
|
1407
|
+
## 前端客户端 — typed API client
|
|
1408
1408
|
|
|
1409
|
-
>
|
|
1409
|
+
> 浏览器 / App 端通过 `@h-ai/api-client` 调用由 `@h-ai/api-contract` 定义、`@h-ai/serv` 挂载的 AI HTTP API。`@h-ai/ai/client` 中的低层 helper 只适用于应用自定义了 `post/stream` 适配器的场景;标准公共 API 请优先使用 typed client。
|
|
1410
1410
|
|
|
1411
1411
|
```ts
|
|
1412
|
-
import {
|
|
1413
|
-
import { api } from '@h-ai/api-client'
|
|
1412
|
+
import { apiClient } from '@h-ai/api-client'
|
|
1414
1413
|
|
|
1415
|
-
await
|
|
1416
|
-
const client = createAIClient({ api })
|
|
1414
|
+
await apiClient.init({ baseUrl: '/api/v1', auth: {} })
|
|
1417
1415
|
```
|
|
1418
1416
|
|
|
1419
1417
|
### 非流式对话
|
|
1420
1418
|
|
|
1421
1419
|
```ts
|
|
1422
|
-
const response = await
|
|
1420
|
+
const response = await apiClient.ai.chats.createCompletion({
|
|
1423
1421
|
messages: [{ role: 'user', content: '你好' }],
|
|
1424
1422
|
})
|
|
1425
|
-
|
|
1423
|
+
if (response.success) {
|
|
1424
|
+
// response.data: ChatCompletionResponse(同服务端返回结构)
|
|
1425
|
+
}
|
|
1426
1426
|
```
|
|
1427
1427
|
|
|
1428
1428
|
### 流式对话
|
|
1429
1429
|
|
|
1430
|
-
|
|
1431
|
-
for await (const chunk of client.chatStream({ messages }, {
|
|
1432
|
-
onProgress: (progress) => {
|
|
1433
|
-
// progress.content — 已累积的内容
|
|
1434
|
-
// progress.done — 是否结束
|
|
1435
|
-
// progress.finishReason — 结束原因
|
|
1436
|
-
},
|
|
1437
|
-
})) {
|
|
1438
|
-
const delta = chunk.choices[0]?.delta?.content
|
|
1439
|
-
if (delta) {
|
|
1440
|
-
updateUI(delta)
|
|
1441
|
-
}
|
|
1442
|
-
}
|
|
1443
|
-
```
|
|
1430
|
+
标准 `api-client` 不提供旧式通用流式方法;如需 SSE 流式输出,请在应用服务端显式暴露自定义流式 endpoint,再用 `fetch` / `apiFetch` 消费。
|
|
1444
1431
|
|
|
1445
1432
|
### 便捷方式
|
|
1446
1433
|
|
|
1447
1434
|
```ts
|
|
1448
1435
|
// 发送单条消息,返回回复文本
|
|
1449
|
-
const reply = await
|
|
1450
|
-
|
|
1451
|
-
// 流式发送,返回完整回复文本
|
|
1452
|
-
const reply = await client.sendMessageStream('写一首诗', {
|
|
1453
|
-
onProgress: p => updateUI(p.content),
|
|
1454
|
-
})
|
|
1436
|
+
const reply = await apiClient.ai.chats.sendMessage({ message: '你好', systemPrompt: '你是一个翻译助手' })
|
|
1455
1437
|
```
|
|
1456
1438
|
|
|
1457
1439
|
### 记忆与会话查询
|
|
1458
1440
|
|
|
1459
1441
|
```ts
|
|
1460
1442
|
// 检索相关记忆
|
|
1461
|
-
const memories = await
|
|
1443
|
+
const memories = await apiClient.ai.memories.recall({
|
|
1444
|
+
query: '用户偏好',
|
|
1462
1445
|
topK: 5,
|
|
1463
1446
|
objectId: 'user-001',
|
|
1464
1447
|
})
|
|
1465
1448
|
|
|
1466
1449
|
// 分页列出记忆
|
|
1467
|
-
const page = await
|
|
1450
|
+
const page = await apiClient.ai.memories.list({
|
|
1468
1451
|
objectId: 'user-001',
|
|
1469
|
-
offset: 0,
|
|
1470
1452
|
limit: 20,
|
|
1471
1453
|
})
|
|
1472
|
-
|
|
1454
|
+
if (page.success) {
|
|
1455
|
+
// page.data.items: MemoryEntry[]
|
|
1456
|
+
}
|
|
1473
1457
|
|
|
1474
1458
|
// 列出某对象的所有会话
|
|
1475
|
-
const sessions = await
|
|
1476
|
-
|
|
1459
|
+
const sessions = await apiClient.ai.sessions.list({ objectId: 'user-001' })
|
|
1460
|
+
if (sessions.success) {
|
|
1461
|
+
// sessions.data.items: SessionInfo[]
|
|
1462
|
+
}
|
|
1477
1463
|
```
|
|
1478
1464
|
|
|
1479
1465
|
---
|
|
@@ -631,8 +631,8 @@ interface A2ACallResult {
|
|
|
631
631
|
* @module ai-llm-types
|
|
632
632
|
*/
|
|
633
633
|
|
|
634
|
-
/** 消息角色枚举:`'system'` | `'user'` | `'assistant'` | `'tool'` */
|
|
635
|
-
type MessageRole = 'system' | 'user' | 'assistant' | 'tool';
|
|
634
|
+
/** 消息角色枚举:`'system'` | `'developer'` | `'user'` | `'assistant'` | `'tool'` */
|
|
635
|
+
type MessageRole = 'system' | 'developer' | 'user' | 'assistant' | 'tool';
|
|
636
636
|
/** 文本内容块(多模态消息中的纯文本部分) */
|
|
637
637
|
type TextContent = OpenAI.Chat.Completions.ChatCompletionContentPartText;
|
|
638
638
|
/** 图片内容块(多模态消息中的图片部分) */
|
|
@@ -641,16 +641,29 @@ type ImageContent = OpenAI.Chat.Completions.ChatCompletionContentPartImage;
|
|
|
641
641
|
type MessageContent = string | OpenAI.Chat.Completions.ChatCompletionContentPart[];
|
|
642
642
|
/** 系统消息,用于设定对话的行为规则 */
|
|
643
643
|
type SystemMessage = OpenAI.Chat.Completions.ChatCompletionSystemMessageParam;
|
|
644
|
+
/** 开发者消息(高优先级运行时约束) */
|
|
645
|
+
interface DeveloperMessage {
|
|
646
|
+
role: 'developer';
|
|
647
|
+
content: string | TextContent[];
|
|
648
|
+
name?: string;
|
|
649
|
+
}
|
|
644
650
|
/** 用户消息 */
|
|
645
651
|
type UserMessage = OpenAI.Chat.Completions.ChatCompletionUserMessageParam;
|
|
646
652
|
/** 工具调用描述,由助手消息中的 `tool_calls` 字段携带 */
|
|
647
653
|
type ToolCall = OpenAI.Chat.Completions.ChatCompletionMessageToolCall;
|
|
648
654
|
/** 助手消息(模型生成的回复,或传入对话上下文的助手轮次) */
|
|
649
|
-
type AssistantMessage = OpenAI.Chat.Completions.ChatCompletionAssistantMessageParam
|
|
655
|
+
type AssistantMessage = OpenAI.Chat.Completions.ChatCompletionAssistantMessageParam & {
|
|
656
|
+
/**
|
|
657
|
+
* 推理模型额外返回的思维链内容。
|
|
658
|
+
*
|
|
659
|
+
* DeepSeek thinking mode 在 function calling 多轮续写时要求回传该字段。
|
|
660
|
+
*/
|
|
661
|
+
reasoning_content?: string | null;
|
|
662
|
+
};
|
|
650
663
|
/** 工具消息(工具执行结果,用于回传给模型) */
|
|
651
664
|
type ToolMessage = OpenAI.Chat.Completions.ChatCompletionToolMessageParam;
|
|
652
665
|
/** 聊天消息联合类型,涵盖对话中所有角色的消息 */
|
|
653
|
-
type ChatMessage = OpenAI.Chat.Completions.ChatCompletionMessageParam;
|
|
666
|
+
type ChatMessage = OpenAI.Chat.Completions.ChatCompletionMessageParam | DeveloperMessage;
|
|
654
667
|
/** OpenAI function calling 工具定义格式 */
|
|
655
668
|
type ToolDefinition = OpenAI.Chat.Completions.ChatCompletionTool;
|
|
656
669
|
/**
|
|
@@ -660,7 +673,9 @@ type ToolDefinition = OpenAI.Chat.Completions.ChatCompletionTool;
|
|
|
660
673
|
* `model` 改为可选(未指定时使用配置中的默认模型)。
|
|
661
674
|
* `stream` 字段由框架内部控制,不对外暴露。
|
|
662
675
|
*/
|
|
663
|
-
type ChatCompletionRequest = Omit<OpenAI.Chat.ChatCompletionCreateParamsNonStreaming, 'model' | 'stream'> & {
|
|
676
|
+
type ChatCompletionRequest = Omit<OpenAI.Chat.ChatCompletionCreateParamsNonStreaming, 'model' | 'stream' | 'messages'> & {
|
|
677
|
+
/** 对话消息列表 */
|
|
678
|
+
messages: ChatMessage[];
|
|
664
679
|
/** 模型名称(可选,未指定时使用配置中的默认模型) */
|
|
665
680
|
model?: string;
|
|
666
681
|
/** 交互主体 ID(传入后 LLM 会自动关联到该主体) */
|
|
@@ -684,6 +699,8 @@ type ChatCompletionChunk = OpenAI.Chat.ChatCompletionChunk;
|
|
|
684
699
|
interface StreamResult {
|
|
685
700
|
/** 累积的完整文本内容 */
|
|
686
701
|
content: string;
|
|
702
|
+
/** 累积的完整 reasoning 内容 */
|
|
703
|
+
reasoningContent: string;
|
|
687
704
|
/** 累积的完整工具调用列表 */
|
|
688
705
|
toolCalls: ToolCall[];
|
|
689
706
|
/** 完成原因(流未结束时为 `null`) */
|
|
@@ -2822,4 +2839,4 @@ interface ReasoningOperations {
|
|
|
2822
2839
|
runStream: (query: string, options?: ReasoningOptions) => AsyncIterable<ReasoningStreamEvent>;
|
|
2823
2840
|
}
|
|
2824
2841
|
|
|
2825
|
-
export { type A2AOperations as $, type A2AConfig as A, type RetrievalConfig as B, type CompressConfig as C, RetrievalConfigSchema as D, type EmbeddingConfig as E, type FileConfig as F, type RetrievalSourceConfig as G, RetrievalSourceSchema as H, SummaryConfigSchema as I, TokenConfigSchema as J, type KnowledgeConfig as K, type LLMConfig as L, type MCPConfig as M, resolveModelEntry as N, type A2AAgentCardConfig as O, type A2AApiKeySecurity as P, type A2AAuthenticator as Q, type ResolveRequiredModelEntryOptions as R, type SummaryConfig as S, type TokenConfig as T, type A2ACallOptions as U, type A2ACallResult as V, type A2ACallerIdentity as W, type A2AClientCallRecord as X, type A2AContextInfo as Y, type A2AHandleResult as Z, type A2AMessageRecord as _, A2AConfigSchema as a, type
|
|
2842
|
+
export { type A2AOperations as $, type A2AConfig as A, type RetrievalConfig as B, type CompressConfig as C, RetrievalConfigSchema as D, type EmbeddingConfig as E, type FileConfig as F, type RetrievalSourceConfig as G, RetrievalSourceSchema as H, SummaryConfigSchema as I, TokenConfigSchema as J, type KnowledgeConfig as K, type LLMConfig as L, type MCPConfig as M, resolveModelEntry as N, type A2AAgentCardConfig as O, type A2AApiKeySecurity as P, type A2AAuthenticator as Q, type ResolveRequiredModelEntryOptions as R, type SummaryConfig as S, type TokenConfig as T, type A2ACallOptions as U, type A2ACallResult as V, type A2ACallerIdentity as W, type A2AClientCallRecord as X, type A2AContextInfo as Y, type A2AHandleResult as Z, type A2AMessageRecord as _, A2AConfigSchema as a, type ReasoningOperations as a$, type A2ASecurityConfig as a0, type A2ATaskFilter as a1, type AILLMFunctionsDeps as a2, type AIRelStore as a3, type AIRelStoreOptions as a4, type AIStoreProvider as a5, type AIVectorStore as a6, type AskOptions as a7, type AssistantMessage as a8, type ChatCompletionChoice as a9, type KnowledgeIngestResult as aA, type KnowledgeOperations as aB, type KnowledgeRetrieveItem as aC, type KnowledgeRetrieveOptions as aD, type KnowledgeRetrieveResult as aE, type KnowledgeSetupOptions as aF, type KnowledgeStore as aG, type LLMOperations as aH, type LLMProvider as aI, type MemoryClearOptions as aJ, type MemoryEntry as aK, type MemoryEntryInput as aL, type MemoryExtractOptions as aM, type MemoryInjectionOptions as aN, type MemoryListOptions as aO, type MemoryListPageOptions as aP, type MemoryOperations as aQ, type MemoryRecallOptions as aR, type MemoryUpdateInput as aS, type MessageContent as aT, type MessageRole as aU, type ObjectRef as aV, type RagContextItem as aW, type RagOperations as aX, type RagOptions as aY, type RagResult as aZ, type RagStreamEvent as a_, type ChatCompletionChunk as aa, type ChatCompletionDelta as ab, type ChatCompletionRequest as ac, type ChatCompletionResponse as ad, type ChatHistoryOptions as ae, type ChatMessage as af, type ChatRecord as ag, type Citation as ah, type DefineToolOptions as ai, type DeveloperMessage as aj, type EntityDocumentRelation as ak, type EntityDocumentResult as al, type EntityListOptions as am, type EntityQueryOptions as an, type ImageContent as ao, type InteractionScope as ap, type KnowledgeAskOptions as aq, type KnowledgeAskResult as ar, type KnowledgeDocumentInfo as as, type KnowledgeDocumentListOptions as at, type KnowledgeDocumentRemoveOptions as au, type KnowledgeEntity as av, type KnowledgeIngestBatchProgress as aw, type KnowledgeIngestBatchResult as ax, type KnowledgeIngestFileInput as ay, type KnowledgeIngestInput as az, A2ASkillConfigSchema as b, type ReasoningOptions as b0, type ReasoningResult as b1, type ReasoningStep as b2, type ReasoningStepType as b3, type ReasoningStrategy as b4, type ReasoningStreamEvent as b5, type RetrievalOperations as b6, type RetrievalRequest as b7, type RetrievalResult as b8, type RetrievalResultItem as b9, type RetrievalSource as ba, type SSEDecoder as bb, type SSEEvent as bc, type SessionInfo as bd, type StoreFilter as be, type StorePage as bf, type StoreScope as bg, type StreamOperations as bh, type StreamProcessor as bi, type StreamResult as bj, type SystemMessage as bk, type TextContent as bl, type TokenUsage as bm, type Tool as bn, type ToolCall as bo, type ToolDefinition as bp, type ToolErrorType as bq, type ToolMessage as br, type ToolRegistryOperations as bs, type ToolsOperations as bt, type UserMessage as bu, type WhereClause as bv, type WhereOperator as bw, type WhereValue as bx, type AIConfig as c, type AIConfigInput as d, AIConfigSchema as e, CompressConfigSchema as f, EmbeddingConfigSchema as g, type EntityType as h, EntityTypeSchema as i, FileConfigSchema as j, KnowledgeConfigSchema as k, LLMConfigSchema as l, MCPConfigSchema as m, type MCPServerCapabilities as n, MCPServerCapabilitiesSchema as o, type MCPServerConfig as p, MCPServerConfigSchema as q, type MemoryConfig as r, MemoryConfigSchema as s, type MemoryType as t, MemoryTypeSchema as u, type ModelEntry as v, ModelEntrySchema as w, type ModelScenario as x, ModelScenarioSchema as y, type ResolvedModelConfig as z };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as _h_ai_core from '@h-ai/core';
|
|
2
2
|
import { HaiResult } from '@h-ai/core';
|
|
3
|
-
import { af as ChatMessage,
|
|
3
|
+
import { af as ChatMessage, ap as InteractionScope, aN as MemoryInjectionOptions, aY as RagOptions, b0 as ReasoningOptions, bs as ToolRegistryOperations, bd as SessionInfo, aH as LLMOperations, aQ as MemoryOperations, aX as RagOperations, a$ as ReasoningOperations, c as AIConfig, d as AIConfigInput, a5 as AIStoreProvider, bt as ToolsOperations, bh as StreamOperations, b6 as RetrievalOperations, aB as KnowledgeOperations, $ as A2AOperations } from './ai-reasoning-types-C1uvQosU.js';
|
|
4
4
|
import { z } from 'zod';
|
|
5
5
|
import { Buffer } from 'node:buffer';
|
|
6
6
|
|
package/dist/browser.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { A as A2AConfig, a as A2AConfigSchema, b as A2ASkillConfigSchema, c as AIConfig, d as AIConfigInput, e as AIConfigSchema, C as CompressConfig, f as CompressConfigSchema, E as EmbeddingConfig, g as EmbeddingConfigSchema, h as EntityType, i as EntityTypeSchema, F as FileConfig, j as FileConfigSchema, K as KnowledgeConfig, k as KnowledgeConfigSchema, L as LLMConfig, l as LLMConfigSchema, M as MCPConfig, m as MCPConfigSchema, n as MCPServerCapabilities, o as MCPServerCapabilitiesSchema, p as MCPServerConfig, q as MCPServerConfigSchema, r as MemoryConfig, s as MemoryConfigSchema, t as MemoryType, u as MemoryTypeSchema, v as ModelEntry, w as ModelEntrySchema, x as ModelScenario, y as ModelScenarioSchema, R as ResolveRequiredModelEntryOptions, z as ResolvedModelConfig, B as RetrievalConfig, D as RetrievalConfigSchema, G as RetrievalSourceConfig, H as RetrievalSourceSchema, S as SummaryConfig, I as SummaryConfigSchema, T as TokenConfig, J as TokenConfigSchema, N as resolveModelEntry } from './ai-reasoning-types-
|
|
2
|
-
export { A as AIFunctions, a as AIInitOptions, C as CompressionStrategy, b as CompressionStrategySchema, H as HaiAIError } from './ai-types-
|
|
1
|
+
export { A as A2AConfig, a as A2AConfigSchema, b as A2ASkillConfigSchema, c as AIConfig, d as AIConfigInput, e as AIConfigSchema, C as CompressConfig, f as CompressConfigSchema, E as EmbeddingConfig, g as EmbeddingConfigSchema, h as EntityType, i as EntityTypeSchema, F as FileConfig, j as FileConfigSchema, K as KnowledgeConfig, k as KnowledgeConfigSchema, L as LLMConfig, l as LLMConfigSchema, M as MCPConfig, m as MCPConfigSchema, n as MCPServerCapabilities, o as MCPServerCapabilitiesSchema, p as MCPServerConfig, q as MCPServerConfigSchema, r as MemoryConfig, s as MemoryConfigSchema, t as MemoryType, u as MemoryTypeSchema, v as ModelEntry, w as ModelEntrySchema, x as ModelScenario, y as ModelScenarioSchema, R as ResolveRequiredModelEntryOptions, z as ResolvedModelConfig, B as RetrievalConfig, D as RetrievalConfigSchema, G as RetrievalSourceConfig, H as RetrievalSourceSchema, S as SummaryConfig, I as SummaryConfigSchema, T as TokenConfig, J as TokenConfigSchema, N as resolveModelEntry } from './ai-reasoning-types-C1uvQosU.js';
|
|
2
|
+
export { A as AIFunctions, a as AIInitOptions, C as CompressionStrategy, b as CompressionStrategySchema, H as HaiAIError } from './ai-types-GOmowSTF.js';
|
|
3
3
|
export { A2AClientOperations, AIApiAdapter, AIClient, AIClientConfig, StreamOptions, StreamProgress, collectStreamContent, createA2AClient, createAIClient, parseSSE } from './client/index.js';
|
|
4
4
|
import '@a2a-js/sdk/server';
|
|
5
5
|
import '@h-ai/core';
|
package/dist/browser.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { A2AConfigSchema, A2ASkillConfigSchema, AIConfigSchema, CompressConfigSchema, CompressionStrategySchema, EmbeddingConfigSchema, EntityTypeSchema, FileConfigSchema, HaiAIError, KnowledgeConfigSchema, LLMConfigSchema, MCPConfigSchema, MCPServerCapabilitiesSchema, MCPServerConfigSchema, MemoryConfigSchema, MemoryTypeSchema, ModelEntrySchema, ModelScenarioSchema, RetrievalConfigSchema, RetrievalSourceSchema, SummaryConfigSchema, TokenConfigSchema, resolveModelEntry } from './chunk-UCG4OLAP.js';
|
|
2
|
-
export { collectStreamContent, createA2AClient, createAIClient, parseSSE } from './chunk-
|
|
2
|
+
export { collectStreamContent, createA2AClient, createAIClient, parseSSE } from './chunk-Y5BQR7QA.js';
|
|
3
3
|
//# sourceMappingURL=browser.js.map
|
|
4
4
|
//# sourceMappingURL=browser.js.map
|
|
@@ -307,5 +307,5 @@ async function collectStreamContent(stream) {
|
|
|
307
307
|
}
|
|
308
308
|
|
|
309
309
|
export { collectStreamContent, createA2AClient, createAIClient, parseSSE };
|
|
310
|
-
//# sourceMappingURL=chunk-
|
|
311
|
-
//# sourceMappingURL=chunk-
|
|
310
|
+
//# sourceMappingURL=chunk-Y5BQR7QA.js.map
|
|
311
|
+
//# sourceMappingURL=chunk-Y5BQR7QA.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/client/ai-a2a-client.ts","../src/client/ai-client.ts"],"names":[],"mappings":";AAiCA,IAAM,QAAA,GAAW;AAAA,EACf,SAAA,EAAW,iBAAA;AAAA,EACX,QAAA,EAAU,eAAA;AAAA,EACV,UAAA,EAAY;AACd,CAAA;AAUO,SAAS,gBAAgB,GAAA,EAAwC;AACtE,EAAA,OAAO;AAAA,IACL,MAAM,YAAA,GAA4C;AAChD,MAAA,MAAM,MAAA,GAAS,MAAM,GAAA,CAAI,IAAA,CAAyB,SAAS,SAAS,CAAA;AACpE,MAAA,IAAI,CAAC,OAAO,OAAA,EAAS;AACnB,QAAA,MAAM,IAAI,KAAA,CAAM,CAAA,2BAAA,EAA8B,MAAA,CAAO,KAAA,CAAM,OAAO,CAAA,CAAE,CAAA;AAAA,MACtE;AACA,MAAA,OAAO,MAAA,CAAO,IAAA;AAAA,IAChB,CAAA;AAAA,IAEA,MAAM,aAAa,M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AA,MAAM,IAAA;AAAA,UACR;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,EACF,CAAA,SACA;AACE,IAAA,MAAA,CAAO,WAAA,EAAY;AAAA,EACrB;AACF;AAiBA,eAAsB,qBACpB,MAAA,EACiB;AACjB,EAAA,IAAI,OAAA,GAAU,EAAA;AACd,EAAA,WAAA,MAAiB,SAAS,MAAA,EAAQ;AAChC,IAAA,MAAM,KAAA,GAAQ,KAAA,CAAM,OAAA,CAAQ,CAAC,GAAG,KAAA,EAAO,OAAA;AACvC,IAAA,IAAI,KAAA,EAAO;AACT,MAAA,OAAA,IAAW,KAAA;AAAA,IACb;AAAA,EACF;AACA,EAAA,OAAO,OAAA;AACT","file":"chunk-Y5BQR7QA.js","sourcesContent":["/**\n * @h-ai/ai — 前端 A2A 客户端\n *\n * 浏览器端 A2A 操作客户端,通过 API 服务调用后端 A2A 能力。\n * @module ai-a2a-client\n */\n\nimport type {\n A2AAgentCardConfig,\n A2ACallResult,\n A2AMessageRecord,\n} from '../a2a/ai-a2a-types.js'\nimport type { StorePage } from '../store/ai-store-types.js'\nimport type { AIApiAdapter } from './ai-client.js'\n\n// ─── A2A 客户端接口 ───\n\n/**\n * A2A 客户端接口\n *\n * 提供浏览器端调用后端 A2A API 的能力。\n */\nexport interface A2AClientOperations {\n /** 获取当前 Agent Card 配置 */\n getAgentCard: () => Promise<A2AAgentCardConfig>\n /** 查询 A2A 消息记录 */\n listMessages: (filter?: { contextId?: string, status?: string, limit?: number, offset?: number }) => Promise<StorePage<A2AMessageRecord>>\n /** 作为客户端调用远端 Agent */\n callRemoteAgent: (remoteUrl: string, message: string, options?: { timeout?: number }) => Promise<A2ACallResult>\n}\n\n// ─── A2A API 路径 ───\n\nconst A2A_PATH = {\n agentCard: '/a2a/agent-card',\n messages: '/a2a/messages',\n callRemote: '/a2a/call',\n} as const\n\n// ─── 工厂函数 ───\n\n/**\n * 创建 A2A 客户端\n *\n * @param api - API 适配器(来自 @h-ai/api-client)\n * @returns A2A 客户端操作实例\n */\nexport function createA2AClient(api: AIApiAdapter): A2AClientOperations {\n return {\n async getAgentCard(): Promise<A2AAgentCardConfig> {\n const result = await api.post<A2AAgentCardConfig>(A2A_PATH.agentCard)\n if (!result.success) {\n throw new Error(`A2A get agent card failed: ${result.error.message}`)\n }\n return result.data\n },\n\n async listMessages(filter?: { contextId?: string, status?: string, limit?: number, offset?: number }): Promise<StorePage<A2AMessageRecord>> {\n const result = await api.post<StorePage<A2AMessageRecord>>(A2A_PATH.messages, filter ?? {})\n if (!result.success) {\n throw new Error(`A2A list messages failed: ${result.error.message}`)\n }\n return result.data\n },\n\n async callRemoteAgent(remoteUrl: string, message: string, options?: { timeout?: number }): Promise<A2ACallResult> {\n const result = await api.post<A2ACallResult>(A2A_PATH.callRemote, {\n remoteUrl,\n message,\n ...options,\n })\n if (!result.success) {\n throw new Error(`A2A remote call failed: ${result.error.message}`)\n }\n return result.data\n },\n }\n}\n","/**\n * @h-ai/ai — 前端 AI 客户端\n *\n * 基于 @h-ai/api-client 的 AI 领域客户端。\n * 通过 `createAIClient()` 工厂函数创建,消除自建 HTTP 层,\n * 复用 api-client 提供的 Token 管理、超时、拦截器等基础能力。\n * @module ai-client\n */\n\nimport type { HaiResult } from '@h-ai/core'\nimport type { KnowledgeAskResult, KnowledgeDocumentInfo, KnowledgeIngestResult, KnowledgeRetrieveResult } from '../knowledge/ai-knowledge-types.js'\nimport type {\n ChatCompletionChunk,\n ChatCompletionRequest,\n ChatCompletionResponse,\n ChatMessage,\n ChatRecord,\n} from '../llm/ai-llm-types.js'\nimport type { MemoryEntry, MemoryEntryInput, MemoryUpdateInput } from '../memory/ai-memory-types.js'\nimport type { RagResult } from '../rag/ai-rag-types.js'\nimport type { ReasoningResult } from '../reasoning/ai-reasoning-types.js'\nimport type { SessionInfo, StorePage } from '../store/ai-store-types.js'\n\n// ─── API 适配器接口 ───\n\n/**\n * AI 客户端所需的 API 调用能力\n *\n * 结构兼容 `@h-ai/api-client` 的 `apiClient` 默认单例(鸭子类型)。\n * 传入 `apiClient` 默认单例即可,无需额外适配。\n */\nexport interface AIApiAdapter {\n /** POST 请求(返回 HaiResult) */\n post: <T>(path: string, body?: unknown) => Promise<HaiResult<T>>\n /** 流式请求(返回 SSE data 行的 AsyncIterable) */\n stream: (path: string, body?: unknown) => AsyncIterable<string>\n}\n\n// ─── 客户端配置 ───\n\n/**\n * AI 客户端配置\n *\n * @example\n * ```ts\n * import { apiClient } from '@h-ai/api-client'\n * import { createAIClient } from '@h-ai/ai/client'\n *\n * await apiClient.init({ baseUrl: '/api', auth: { ... } })\n * const aiClient = createAIClient({ api: apiClient })\n * ```\n */\nexport interface AIClientConfig {\n /**\n * API 调用适配器\n *\n * 传入 `apiClient` 默认单例(初始化后)。\n * baseUrl、Token 管理、超时等通过 api-client 配置。\n */\n api: AIApiAdapter\n}\n\n/** 流式响应进度(`onProgress` 回调参数) */\nexport interface StreamProgress {\n /** 当前累积的文本内容 */\n content: string\n /** 是否已完成 */\n done: boolean\n /** 完成原因(仅 `done=true` 时有值,如 `'stop'`) */\n finishReason?: string\n}\n\n/** 流式响应选项 */\nexport interface StreamOptions {\n /** 进度回调(每次收到 chunk 时触发) */\n onProgress?: (progress: StreamProgress) => void\n}\n\n// ─── 客户端接口 ───\n\n/**\n * AI 客户端接口\n *\n * 提供浏览器端调用 AI API 的能力,HTTP 基础设施委托给 @h-ai/api-client。\n */\nexport interface AIClient {\n // ─── LLM ───\n /** 发送对话请求(非流式) */\n chat: (request: ChatCompletionRequest) => Promise<ChatCompletionResponse>\n /** 发送流式对话请求,返回异步迭代器 */\n chatStream: (request: ChatCompletionRequest, options?: StreamOptions) => AsyncIterable<ChatCompletionChunk>\n /** 便捷方法:发送纯文本消息并返回回复文本 */\n sendMessage: (message: string, systemPrompt?: string) => Promise<string>\n /** 便捷方法:流式发送纯文本消息并返回完整回复 */\n sendMessageStream: (message: string, options?: StreamOptions, systemPrompt?: string) => Promise<string>\n /** 简单问答(单轮,自动构造 messages) */\n ask: (question: string, options?: { systemPrompt?: string, model?: string }) => Promise<string>\n /** 流式简单问答,返回异步文本流 */\n askStream: (question: string, options?: { systemPrompt?: string, model?: string }) => AsyncIterable<string>\n\n // ─── Knowledge ───\n /** 知识检索(向量 + 实体增强) */\n knowledgeRetrieve: (query: string, options?: { topK?: number, collection?: string }) => Promise<KnowledgeRetrieveResult>\n /** 知识问答(RAG + 信源) */\n knowledgeAsk: (query: string, options?: { model?: string, collection?: string }) => Promise<KnowledgeAskResult>\n /** 导入文档 */\n knowledgeIngest: (input: { documentId: string, content: string, title?: string, collection?: string, metadata?: Record<string, unknown> }) => Promise<KnowledgeIngestResult>\n /** 列出已导入文档 */\n knowledgeListDocuments: (options?: { collection?: string, offset?: number, limit?: number }) => Promise<KnowledgeDocumentInfo[]>\n /** 删除已导入文档 */\n knowledgeRemoveDocument: (documentId: string, options?: { collection?: string }) => Promise<void>\n\n // ─── Memory ───\n /** 检索相关记忆 */\n recallMemories: (query: string, options?: { topK?: number, types?: string[], minImportance?: number, objectId?: string }) => Promise<MemoryEntry[]>\n /** 列出记忆(分页) */\n listMemories: (options?: { types?: string[], objectId?: string, offset?: number, limit?: number }) => Promise<StorePage<MemoryEntry>>\n /** 添加记忆 */\n addMemory: (entry: MemoryEntryInput) => Promise<MemoryEntry>\n /** 更新记忆 */\n updateMemory: (memoryId: string, updates: MemoryUpdateInput) => Promise<MemoryEntry>\n /** 删除记忆 */\n removeMemory: (memoryId: string) => Promise<void>\n\n // ─── Session ───\n /** 列出会话 */\n listSessions: (objectId: string) => Promise<SessionInfo[]>\n /** 重命名会话 */\n renameSession: (sessionId: string, title: string) => Promise<void>\n /** 删除会话 */\n removeSession: (sessionId: string) => Promise<void>\n /** 获取对话历史 */\n chatHistory: (objectId: string, sessionId: string, options?: { limit?: number, order?: 'asc' | 'desc' }) => Promise<ChatRecord[]>\n\n // ─── RAG ───\n /** RAG 查询(检索 + 生成) */\n ragQuery: (query: string, options?: { collection?: string, topK?: number, model?: string }) => Promise<RagResult>\n /** RAG 流式查询,返回 SSE 数据行 */\n ragQueryStream: (query: string, options?: { collection?: string, topK?: number, model?: string }) => AsyncIterable<string>\n\n // ─── Reasoning ───\n /** 推理(多步思考) */\n reasoningRun: (query: string, options?: { model?: string, maxSteps?: number }) => Promise<ReasoningResult>\n /** 推理流式,返回 SSE 数据行 */\n reasoningRunStream: (query: string, options?: { model?: string, maxSteps?: number }) => AsyncIterable<string>\n\n // ─── Token ───\n /** 估算文本的 Token 数 */\n estimateTokens: (text: string) => Promise<{ tokens: number }>\n}\n\n// ─── AI API 路径(与 ai-api-contract 保持一致) ───\n\nconst AI_PATH = {\n // LLM\n chat: '/ai/chat',\n chatStream: '/ai/chat/stream',\n chatHistory: '/ai/chat/history',\n ask: '/ai/ask',\n askStream: '/ai/ask/stream',\n // Knowledge\n knowledgeRetrieve: '/ai/knowledge/retrieve',\n knowledgeAsk: '/ai/knowledge/ask',\n knowledgeIngest: '/ai/knowledge/ingest',\n knowledgeDocuments: '/ai/knowledge/documents',\n knowledgeRemoveDocument: '/ai/knowledge/documents/remove',\n // Memory\n memoryRecall: '/ai/memory/recall',\n memoryList: '/ai/memory/list',\n memoryAdd: '/ai/memory/add',\n memoryUpdate: '/ai/memory/update',\n memoryRemove: '/ai/memory/remove',\n // Session\n sessions: '/ai/sessions',\n sessionRename: '/ai/sessions/rename',\n sessionRemove: '/ai/sessions/remove',\n // RAG\n ragQuery: '/ai/rag/query',\n ragQueryStream: '/ai/rag/query/stream',\n // Reasoning\n reasoningRun: '/ai/reasoning/run',\n reasoningRunStream: '/ai/reasoning/run/stream',\n // Token\n tokenEstimate: '/ai/token/estimate',\n} as const\n\n// ─── 工厂函数 ───\n\n/**\n * 创建 AI 客户端\n *\n * 通过 @h-ai/api-client 的 ApiClient 实例调用后端 AI API。\n * HTTP 层(Token、超时、拦截器)全部复用 api-client,本模块仅负责:\n * - 非流式 / 流式 ChatCompletion 协议适配\n * - SSE 解析与 ChatCompletionChunk 类型化\n * - onProgress 进度回调\n *\n * @param config - 客户端配置\n * @returns AI 客户端实例\n *\n * @example\n * ```ts\n * import { apiClient } from '@h-ai/api-client'\n * import { createAIClient } from '@h-ai/ai/client'\n *\n * await apiClient.init({ baseUrl: '/api' })\n * const client = createAIClient({ api: apiClient })\n * const reply = await client.sendMessage('你好')\n * ```\n */\nexport function createAIClient(config: AIClientConfig): AIClient {\n const { api } = config\n\n return {\n async chat(req: ChatCompletionRequest): Promise<ChatCompletionResponse> {\n const result = await api.post<ChatCompletionResponse>(AI_PATH.chat, { ...req, stream: false })\n if (!result.success) {\n throw new Error(`AI chat request failed: ${result.error.message}`)\n }\n return result.data\n },\n\n async* chatStream(\n req: ChatCompletionRequest,\n options?: StreamOptions,\n ): AsyncIterable<ChatCompletionChunk> {\n let content = ''\n\n for await (const data of api.stream(AI_PATH.chatStream, { ...req, stream: true })) {\n try {\n const chunk: ChatCompletionChunk = JSON.parse(data)\n const delta = chunk.choices[0]?.delta?.content\n if (delta) {\n content += delta\n }\n const finishReason = chunk.choices[0]?.finish_reason\n if (finishReason) {\n options?.onProgress?.({ content, done: true, finishReason })\n }\n else {\n options?.onProgress?.({ content, done: false })\n }\n yield chunk\n }\n catch {\n // 忽略解析错误的行\n }\n }\n },\n\n async sendMessage(message: string, systemPrompt?: string): Promise<string> {\n const messages: ChatMessage[] = []\n if (systemPrompt) {\n messages.push({ role: 'system', content: systemPrompt })\n }\n messages.push({ role: 'user', content: message })\n const response = await this.chat({ messages })\n return response.choices[0]?.message?.content ?? ''\n },\n\n async sendMessageStream(\n message: string,\n options?: StreamOptions,\n systemPrompt?: string,\n ): Promise<string> {\n const messages: ChatMessage[] = []\n if (systemPrompt) {\n messages.push({ role: 'system', content: systemPrompt })\n }\n messages.push({ role: 'user', content: message })\n\n let content = ''\n for await (const chunk of this.chatStream({ messages }, options)) {\n const delta = chunk.choices[0]?.delta?.content\n if (delta) {\n content += delta\n }\n }\n return content\n },\n\n async recallMemories(query: string, options?: { topK?: number, types?: string[], minImportance?: number, objectId?: string }): Promise<MemoryEntry[]> {\n const result = await api.post<{ items: MemoryEntry[] }>(AI_PATH.memoryRecall, { query, ...options })\n if (!result.success) {\n throw new Error(`Memory recall failed: ${result.error.message}`)\n }\n return result.data.items\n },\n\n async listMemories(options?: { types?: string[], objectId?: string, offset?: number, limit?: number }): Promise<StorePage<MemoryEntry>> {\n const result = await api.post<StorePage<MemoryEntry>>(AI_PATH.memoryList, options ?? {})\n if (!result.success) {\n throw new Error(`Memory list failed: ${result.error.message}`)\n }\n return result.data\n },\n\n async listSessions(objectId: string): Promise<SessionInfo[]> {\n const result = await api.post<{ items: SessionInfo[] }>(AI_PATH.sessions, { objectId })\n if (!result.success) {\n throw new Error(`Session list failed: ${result.error.message}`)\n }\n return result.data.items\n },\n\n async chatHistory(objectId: string, sessionId: string, options?: { limit?: number, order?: 'asc' | 'desc' }): Promise<ChatRecord[]> {\n const result = await api.post<{ items: ChatRecord[] }>(AI_PATH.chatHistory, { objectId, sessionId, ...options })\n if (!result.success) {\n throw new Error(`Chat history failed: ${result.error.message}`)\n }\n return result.data.items\n },\n\n // ─── LLM ask/askStream ───\n\n async ask(question: string, options?: { systemPrompt?: string, model?: string }): Promise<string> {\n const result = await api.post<{ text: string }>(AI_PATH.ask, { question, ...options })\n if (!result.success) {\n throw new Error(`AI ask failed: ${result.error.message}`)\n }\n return result.data.text\n },\n\n async* askStream(question: string, options?: { systemPrompt?: string, model?: string }): AsyncIterable<string> {\n for await (const data of api.stream(AI_PATH.askStream, { question, ...options })) {\n yield data\n }\n },\n\n // ─── Knowledge ───\n\n async knowledgeRetrieve(query: string, options?: { topK?: number, collection?: string }): Promise<KnowledgeRetrieveResult> {\n const result = await api.post<KnowledgeRetrieveResult>(AI_PATH.knowledgeRetrieve, { query, ...options })\n if (!result.success) {\n throw new Error(`Knowledge retrieve failed: ${result.error.message}`)\n }\n return result.data\n },\n\n async knowledgeAsk(query: string, options?: { model?: string, collection?: string }): Promise<KnowledgeAskResult> {\n const result = await api.post<KnowledgeAskResult>(AI_PATH.knowledgeAsk, { query, ...options })\n if (!result.success) {\n throw new Error(`Knowledge ask failed: ${result.error.message}`)\n }\n return result.data\n },\n\n async knowledgeIngest(input: { documentId: string, content: string, title?: string, collection?: string, metadata?: Record<string, unknown> }): Promise<KnowledgeIngestResult> {\n const result = await api.post<KnowledgeIngestResult>(AI_PATH.knowledgeIngest, input)\n if (!result.success) {\n throw new Error(`Knowledge ingest failed: ${result.error.message}`)\n }\n return result.data\n },\n\n async knowledgeListDocuments(options?: { collection?: string, offset?: number, limit?: number }): Promise<KnowledgeDocumentInfo[]> {\n const result = await api.post<{ items: KnowledgeDocumentInfo[] }>(AI_PATH.knowledgeDocuments, options ?? {})\n if (!result.success) {\n throw new Error(`Knowledge list documents failed: ${result.error.message}`)\n }\n return result.data.items\n },\n\n async knowledgeRemoveDocument(documentId: string, options?: { collection?: string }): Promise<void> {\n const result = await api.post<void>(AI_PATH.knowledgeRemoveDocument, { documentId, ...options })\n if (!result.success) {\n throw new Error(`Knowledge remove document failed: ${result.error.message}`)\n }\n },\n\n // ─── Memory (extended) ───\n\n async addMemory(entry: MemoryEntryInput): Promise<MemoryEntry> {\n const result = await api.post<MemoryEntry>(AI_PATH.memoryAdd, entry)\n if (!result.success) {\n throw new Error(`Memory add failed: ${result.error.message}`)\n }\n return result.data\n },\n\n async updateMemory(memoryId: string, updates: MemoryUpdateInput): Promise<MemoryEntry> {\n const result = await api.post<MemoryEntry>(AI_PATH.memoryUpdate, { memoryId, ...updates })\n if (!result.success) {\n throw new Error(`Memory update failed: ${result.error.message}`)\n }\n return result.data\n },\n\n async removeMemory(memoryId: string): Promise<void> {\n const result = await api.post<void>(AI_PATH.memoryRemove, { memoryId })\n if (!result.success) {\n throw new Error(`Memory remove failed: ${result.error.message}`)\n }\n },\n\n // ─── Session (extended) ───\n\n async renameSession(sessionId: string, title: string): Promise<void> {\n const result = await api.post<void>(AI_PATH.sessionRename, { sessionId, title })\n if (!result.success) {\n throw new Error(`Session rename failed: ${result.error.message}`)\n }\n },\n\n async removeSession(sessionId: string): Promise<void> {\n const result = await api.post<void>(AI_PATH.sessionRemove, { sessionId })\n if (!result.success) {\n throw new Error(`Session remove failed: ${result.error.message}`)\n }\n },\n\n // ─── RAG ───\n\n async ragQuery(query: string, options?: { collection?: string, topK?: number, model?: string }): Promise<RagResult> {\n const result = await api.post<RagResult>(AI_PATH.ragQuery, { query, ...options })\n if (!result.success) {\n throw new Error(`RAG query failed: ${result.error.message}`)\n }\n return result.data\n },\n\n async* ragQueryStream(query: string, options?: { collection?: string, topK?: number, model?: string }): AsyncIterable<string> {\n for await (const data of api.stream(AI_PATH.ragQueryStream, { query, ...options })) {\n yield data\n }\n },\n\n // ─── Reasoning ───\n\n async reasoningRun(query: string, options?: { model?: string, maxSteps?: number }): Promise<ReasoningResult> {\n const result = await api.post<ReasoningResult>(AI_PATH.reasoningRun, { query, ...options })\n if (!result.success) {\n throw new Error(`Reasoning run failed: ${result.error.message}`)\n }\n return result.data\n },\n\n async* reasoningRunStream(query: string, options?: { model?: string, maxSteps?: number }): AsyncIterable<string> {\n for await (const data of api.stream(AI_PATH.reasoningRunStream, { query, ...options })) {\n yield data\n }\n },\n\n // ─── Token ───\n\n async estimateTokens(text: string): Promise<{ tokens: number }> {\n const result = await api.post<{ tokens: number }>(AI_PATH.tokenEstimate, { text })\n if (!result.success) {\n throw new Error(`Token estimate failed: ${result.error.message}`)\n }\n return result.data\n },\n }\n}\n\n// ─── SSE 解析工具 ───\n\n/**\n * 从 fetch Response 中解析 SSE data 字段\n *\n * 自动处理分片缓冲和 `[DONE]` 结束标记。\n *\n * @param response - fetch 响应对象\n * @yields SSE data 字符串(不含 `[DONE]`)\n *\n * @example\n * ```ts\n * const resp = await fetch('/api/chat', { method: 'POST', body })\n * for await (const data of parseSSE(resp)) {\n * const chunk = JSON.parse(data) // ChatCompletionChunk\n * }\n * ```\n */\nexport async function* parseSSE(response: Response): AsyncIterable<string> {\n const reader = response.body?.getReader()\n if (!reader) {\n throw new Error('Response body is not readable')\n }\n\n const decoder = new TextDecoder()\n let buffer = ''\n\n try {\n while (true) {\n const { done, value } = await reader.read()\n if (done)\n break\n\n buffer += decoder.decode(value, { stream: true })\n const lines = buffer.split('\\n')\n buffer = lines.pop() ?? ''\n\n for (const line of lines) {\n if (line.startsWith('data: ')) {\n const data = line.slice(6)\n if (data !== '[DONE]') {\n yield data\n }\n }\n }\n }\n }\n finally {\n reader.releaseLock()\n }\n}\n\n/**\n * 收集流式响应的完整文本内容\n *\n * 完整消费流并拼接所有 `delta.content` 片段。\n *\n * @param stream - 聊天响应块流\n * @returns 完整文本\n *\n * @example\n * ```ts\n * const client = createAIClient({ api })\n * const stream = client.chatStream({ messages })\n * const fullText = await collectStreamContent(stream)\n * ```\n */\nexport async function collectStreamContent(\n stream: AsyncIterable<ChatCompletionChunk>,\n): Promise<string> {\n let content = ''\n for await (const chunk of stream) {\n const delta = chunk.choices[0]?.delta?.content\n if (delta) {\n content += delta\n }\n }\n return content\n}\n"]}
|
package/dist/client/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ac as ChatCompletionRequest, ad as ChatCompletionResponse, aa as ChatCompletionChunk,
|
|
1
|
+
import { ac as ChatCompletionRequest, ad as ChatCompletionResponse, aa as ChatCompletionChunk, aE as KnowledgeRetrieveResult, ar as KnowledgeAskResult, aA as KnowledgeIngestResult, as as KnowledgeDocumentInfo, aK as MemoryEntry, bf as StorePage, aL as MemoryEntryInput, aS as MemoryUpdateInput, bd as SessionInfo, ag as ChatRecord, aZ as RagResult, b1 as ReasoningResult, O as A2AAgentCardConfig, _ as A2AMessageRecord, V as A2ACallResult } from '../ai-reasoning-types-C1uvQosU.js';
|
|
2
2
|
import { HaiResult } from '@h-ai/core';
|
|
3
3
|
import '@a2a-js/sdk/server';
|
|
4
4
|
import '@h-ai/datapipe';
|
|
@@ -17,8 +17,8 @@ import 'openai';
|
|
|
17
17
|
/**
|
|
18
18
|
* AI 客户端所需的 API 调用能力
|
|
19
19
|
*
|
|
20
|
-
* 结构兼容 `@h-ai/api-client` 的 `
|
|
21
|
-
* 传入 `
|
|
20
|
+
* 结构兼容 `@h-ai/api-client` 的 `apiClient` 默认单例(鸭子类型)。
|
|
21
|
+
* 传入 `apiClient` 默认单例即可,无需额外适配。
|
|
22
22
|
*/
|
|
23
23
|
interface AIApiAdapter {
|
|
24
24
|
/** POST 请求(返回 HaiResult) */
|
|
@@ -31,18 +31,18 @@ interface AIApiAdapter {
|
|
|
31
31
|
*
|
|
32
32
|
* @example
|
|
33
33
|
* ```ts
|
|
34
|
-
* import {
|
|
34
|
+
* import { apiClient } from '@h-ai/api-client'
|
|
35
35
|
* import { createAIClient } from '@h-ai/ai/client'
|
|
36
36
|
*
|
|
37
|
-
* await
|
|
38
|
-
* const aiClient = createAIClient({ api })
|
|
37
|
+
* await apiClient.init({ baseUrl: '/api', auth: { ... } })
|
|
38
|
+
* const aiClient = createAIClient({ api: apiClient })
|
|
39
39
|
* ```
|
|
40
40
|
*/
|
|
41
41
|
interface AIClientConfig {
|
|
42
42
|
/**
|
|
43
43
|
* API 调用适配器
|
|
44
44
|
*
|
|
45
|
-
* 传入 `
|
|
45
|
+
* 传入 `apiClient` 默认单例(初始化后)。
|
|
46
46
|
* baseUrl、Token 管理、超时等通过 api-client 配置。
|
|
47
47
|
*/
|
|
48
48
|
api: AIApiAdapter;
|
|
@@ -185,11 +185,11 @@ interface AIClient {
|
|
|
185
185
|
*
|
|
186
186
|
* @example
|
|
187
187
|
* ```ts
|
|
188
|
-
* import {
|
|
188
|
+
* import { apiClient } from '@h-ai/api-client'
|
|
189
189
|
* import { createAIClient } from '@h-ai/ai/client'
|
|
190
190
|
*
|
|
191
|
-
* await
|
|
192
|
-
* const client = createAIClient({ api })
|
|
191
|
+
* await apiClient.init({ baseUrl: '/api' })
|
|
192
|
+
* const client = createAIClient({ api: apiClient })
|
|
193
193
|
* const reply = await client.sendMessage('你好')
|
|
194
194
|
* ```
|
|
195
195
|
*/
|
package/dist/client/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { collectStreamContent, createA2AClient, createAIClient, parseSSE } from '../chunk-
|
|
1
|
+
export { collectStreamContent, createA2AClient, createAIClient, parseSSE } from '../chunk-Y5BQR7QA.js';
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
|
3
3
|
//# sourceMappingURL=index.js.map
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export { O as A2AAgentCardConfig, P as A2AApiKeySecurity, Q as A2AAuthenticator, U as A2ACallOptions, V as A2ACallResult, W as A2ACallerIdentity, X as A2AClientCallRecord, A as A2AConfig, a as A2AConfigSchema, Y as A2AContextInfo, Z as A2AHandleResult, _ as A2AMessageRecord, $ as A2AOperations, a0 as A2ASecurityConfig, b as A2ASkillConfigSchema, a1 as A2ATaskFilter, c as AIConfig, d as AIConfigInput, e as AIConfigSchema, a2 as AILLMFunctionsDeps, a3 as AIRelStore, a4 as AIRelStoreOptions, a5 as AIStoreProvider, a6 as AIVectorStore, a7 as AskOptions, a8 as AssistantMessage, a9 as ChatCompletionChoice, aa as ChatCompletionChunk, ab as ChatCompletionDelta, ac as ChatCompletionRequest, ad as ChatCompletionResponse, ae as ChatHistoryOptions, af as ChatMessage, ag as ChatRecord, ah as Citation, C as CompressConfig, f as CompressConfigSchema, ai as DefineToolOptions, E as EmbeddingConfig, g as EmbeddingConfigSchema,
|
|
2
|
-
import { A as AIFunctions } from './ai-types-
|
|
3
|
-
export { a as AIInitOptions, c as AIMCPFunctionsDeps, d as CompressOperations, e as CompressOptions, f as CompressResult, C as CompressionStrategy, b as CompressionStrategySchema, g as ContextChatOptions, h as ContextChatResult, i as ContextDeps, j as ContextManager, k as ContextManagerOptions, l as ContextOperations, m as ContextStreamEvent, E as EmbeddingItem, n as EmbeddingOperations, o as EmbeddingProvider, p as EmbeddingRequest, q as EmbeddingResponse, F as FileOperations, r as FileParseMethod, s as FileParseOptions, t as FileParseRequest, u as FileParseResult, H as HaiAIError, M as MCPContext, v as MCPOperations, w as MCPPrompt, x as MCPPromptArgument, y as MCPPromptContent, z as MCPPromptMessage, B as MCPProvider, D as MCPResource, G as MCPResourceContent, I as MCPToolDefinition, J as MCPToolHandler, K as McpServerOptions, O as OutputFormat, R as RerankDocument, L as RerankItem, N as RerankOperations, P as RerankRequest, Q as RerankResponse, S as SummaryOperations, T as SummaryOptions, U as SummaryResult, V as TokenOperations } from './ai-types-
|
|
1
|
+
export { O as A2AAgentCardConfig, P as A2AApiKeySecurity, Q as A2AAuthenticator, U as A2ACallOptions, V as A2ACallResult, W as A2ACallerIdentity, X as A2AClientCallRecord, A as A2AConfig, a as A2AConfigSchema, Y as A2AContextInfo, Z as A2AHandleResult, _ as A2AMessageRecord, $ as A2AOperations, a0 as A2ASecurityConfig, b as A2ASkillConfigSchema, a1 as A2ATaskFilter, c as AIConfig, d as AIConfigInput, e as AIConfigSchema, a2 as AILLMFunctionsDeps, a3 as AIRelStore, a4 as AIRelStoreOptions, a5 as AIStoreProvider, a6 as AIVectorStore, a7 as AskOptions, a8 as AssistantMessage, a9 as ChatCompletionChoice, aa as ChatCompletionChunk, ab as ChatCompletionDelta, ac as ChatCompletionRequest, ad as ChatCompletionResponse, ae as ChatHistoryOptions, af as ChatMessage, ag as ChatRecord, ah as Citation, C as CompressConfig, f as CompressConfigSchema, ai as DefineToolOptions, aj as DeveloperMessage, E as EmbeddingConfig, g as EmbeddingConfigSchema, ak as EntityDocumentRelation, al as EntityDocumentResult, am as EntityListOptions, an as EntityQueryOptions, h as EntityType, i as EntityTypeSchema, F as FileConfig, j as FileConfigSchema, ao as ImageContent, ap as InteractionScope, aq as KnowledgeAskOptions, ar as KnowledgeAskResult, K as KnowledgeConfig, k as KnowledgeConfigSchema, as as KnowledgeDocumentInfo, at as KnowledgeDocumentListOptions, au as KnowledgeDocumentRemoveOptions, av as KnowledgeEntity, aw as KnowledgeIngestBatchProgress, ax as KnowledgeIngestBatchResult, ay as KnowledgeIngestFileInput, az as KnowledgeIngestInput, aA as KnowledgeIngestResult, aB as KnowledgeOperations, aC as KnowledgeRetrieveItem, aD as KnowledgeRetrieveOptions, aE as KnowledgeRetrieveResult, aF as KnowledgeSetupOptions, aG as KnowledgeStore, L as LLMConfig, l as LLMConfigSchema, aH as LLMOperations, aI as LLMProvider, M as MCPConfig, m as MCPConfigSchema, n as MCPServerCapabilities, o as MCPServerCapabilitiesSchema, p as MCPServerConfig, q as MCPServerConfigSchema, aJ as MemoryClearOptions, r as MemoryConfig, s as MemoryConfigSchema, aK as MemoryEntry, aL as MemoryEntryInput, aM as MemoryExtractOptions, aN as MemoryInjectionOptions, aO as MemoryListOptions, aP as MemoryListPageOptions, aQ as MemoryOperations, aR as MemoryRecallOptions, t as MemoryType, u as MemoryTypeSchema, aS as MemoryUpdateInput, aT as MessageContent, aU as MessageRole, v as ModelEntry, w as ModelEntrySchema, x as ModelScenario, y as ModelScenarioSchema, aV as ObjectRef, aW as RagContextItem, aX as RagOperations, aY as RagOptions, aZ as RagResult, a_ as RagStreamEvent, a$ as ReasoningOperations, b0 as ReasoningOptions, b1 as ReasoningResult, b2 as ReasoningStep, b3 as ReasoningStepType, b4 as ReasoningStrategy, b5 as ReasoningStreamEvent, R as ResolveRequiredModelEntryOptions, z as ResolvedModelConfig, B as RetrievalConfig, D as RetrievalConfigSchema, b6 as RetrievalOperations, b7 as RetrievalRequest, b8 as RetrievalResult, b9 as RetrievalResultItem, ba as RetrievalSource, G as RetrievalSourceConfig, H as RetrievalSourceSchema, bb as SSEDecoder, bc as SSEEvent, bd as SessionInfo, be as StoreFilter, bf as StorePage, bg as StoreScope, bh as StreamOperations, bi as StreamProcessor, bj as StreamResult, S as SummaryConfig, I as SummaryConfigSchema, bk as SystemMessage, bl as TextContent, T as TokenConfig, J as TokenConfigSchema, bm as TokenUsage, bn as Tool, bo as ToolCall, bp as ToolDefinition, bq as ToolErrorType, br as ToolMessage, bs as ToolRegistryOperations, bt as ToolsOperations, bu as UserMessage, bv as WhereClause, bw as WhereOperator, bx as WhereValue, N as resolveModelEntry } from './ai-reasoning-types-C1uvQosU.js';
|
|
2
|
+
import { A as AIFunctions } from './ai-types-GOmowSTF.js';
|
|
3
|
+
export { a as AIInitOptions, c as AIMCPFunctionsDeps, d as CompressOperations, e as CompressOptions, f as CompressResult, C as CompressionStrategy, b as CompressionStrategySchema, g as ContextChatOptions, h as ContextChatResult, i as ContextDeps, j as ContextManager, k as ContextManagerOptions, l as ContextOperations, m as ContextStreamEvent, E as EmbeddingItem, n as EmbeddingOperations, o as EmbeddingProvider, p as EmbeddingRequest, q as EmbeddingResponse, F as FileOperations, r as FileParseMethod, s as FileParseOptions, t as FileParseRequest, u as FileParseResult, H as HaiAIError, M as MCPContext, v as MCPOperations, w as MCPPrompt, x as MCPPromptArgument, y as MCPPromptContent, z as MCPPromptMessage, B as MCPProvider, D as MCPResource, G as MCPResourceContent, I as MCPToolDefinition, J as MCPToolHandler, K as McpServerOptions, O as OutputFormat, R as RerankDocument, L as RerankItem, N as RerankOperations, P as RerankRequest, Q as RerankResponse, S as SummaryOperations, T as SummaryOptions, U as SummaryResult, V as TokenOperations } from './ai-types-GOmowSTF.js';
|
|
4
4
|
export { TaskStore as A2ATaskStore, AgentExecutor, ExecutionEventBus, RequestContext, ServerCallContext } from '@a2a-js/sdk/server';
|
|
5
5
|
export { AgentCapabilities, AgentCard, AgentProvider, AgentSkill, Artifact, DataPart, FilePart, FileWithBytes, FileWithUri, Message, MessageSendParams, Part, PushNotificationConfig, Task, TaskArtifactUpdateEvent, TaskIdParams, TaskQueryParams, TaskState, TaskStatus, TaskStatusUpdateEvent, TextPart } from '@a2a-js/sdk';
|
|
6
6
|
import '@h-ai/core';
|
package/dist/index.js
CHANGED
|
@@ -437,6 +437,7 @@ ${summaryText}`
|
|
|
437
437
|
// src/llm/ai-llm-stream.ts
|
|
438
438
|
function createStreamProcessor() {
|
|
439
439
|
let content = "";
|
|
440
|
+
let reasoningContent = "";
|
|
440
441
|
let toolCalls = /* @__PURE__ */ new Map();
|
|
441
442
|
let finishReason = null;
|
|
442
443
|
return {
|
|
@@ -449,6 +450,10 @@ function createStreamProcessor() {
|
|
|
449
450
|
if (delta.content) {
|
|
450
451
|
content += delta.content;
|
|
451
452
|
}
|
|
453
|
+
const reasoningDelta = "reasoning_content" in delta && typeof delta.reasoning_content === "string" ? delta.reasoning_content : "";
|
|
454
|
+
if (reasoningDelta) {
|
|
455
|
+
reasoningContent += reasoningDelta;
|
|
456
|
+
}
|
|
452
457
|
if (delta.tool_calls) {
|
|
453
458
|
for (const tc of delta.tool_calls) {
|
|
454
459
|
const existing = toolCalls.get(tc.index);
|
|
@@ -477,6 +482,7 @@ function createStreamProcessor() {
|
|
|
477
482
|
getResult() {
|
|
478
483
|
return {
|
|
479
484
|
content,
|
|
485
|
+
reasoningContent,
|
|
480
486
|
toolCalls: Array.from(toolCalls.values()).map((tc) => ({
|
|
481
487
|
id: tc.id,
|
|
482
488
|
type: "function",
|
|
@@ -495,6 +501,9 @@ function createStreamProcessor() {
|
|
|
495
501
|
role: "assistant",
|
|
496
502
|
content: result.toolCalls.length > 0 ? null : result.content
|
|
497
503
|
};
|
|
504
|
+
if (result.reasoningContent) {
|
|
505
|
+
message.reasoning_content = result.reasoningContent;
|
|
506
|
+
}
|
|
498
507
|
if (result.toolCalls.length > 0) {
|
|
499
508
|
message.tool_calls = result.toolCalls;
|
|
500
509
|
}
|
|
@@ -503,6 +512,7 @@ function createStreamProcessor() {
|
|
|
503
512
|
/** 重置所有状态,可复用处理器处理下一次流 */
|
|
504
513
|
reset() {
|
|
505
514
|
content = "";
|
|
515
|
+
reasoningContent = "";
|
|
506
516
|
toolCalls = /* @__PURE__ */ new Map();
|
|
507
517
|
finishReason = null;
|
|
508
518
|
}
|
|
@@ -2353,6 +2363,17 @@ function toAIError(error) {
|
|
|
2353
2363
|
cause: sanitizeErrorCause(error)
|
|
2354
2364
|
};
|
|
2355
2365
|
}
|
|
2366
|
+
function toOpenAIMessage(message) {
|
|
2367
|
+
if (message.role === "developer") {
|
|
2368
|
+
const developerMessage = {
|
|
2369
|
+
role: "developer",
|
|
2370
|
+
content: message.content,
|
|
2371
|
+
...message.name ? { name: message.name } : {}
|
|
2372
|
+
};
|
|
2373
|
+
return developerMessage;
|
|
2374
|
+
}
|
|
2375
|
+
return message;
|
|
2376
|
+
}
|
|
2356
2377
|
function createOpenAIProvider(deps) {
|
|
2357
2378
|
const { config } = deps;
|
|
2358
2379
|
const clientCache = /* @__PURE__ */ new Map();
|
|
@@ -2381,9 +2402,11 @@ function createOpenAIProvider(deps) {
|
|
|
2381
2402
|
return clientResult;
|
|
2382
2403
|
const { client, model } = clientResult.data;
|
|
2383
2404
|
const { objectId: _objectId, sessionId: _sessionId, ...openaiRequest } = request;
|
|
2405
|
+
const openaiMessages = request.messages.map(toOpenAIMessage);
|
|
2384
2406
|
try {
|
|
2385
2407
|
const response = await client.chat.completions.create({
|
|
2386
2408
|
...openaiRequest,
|
|
2409
|
+
messages: openaiMessages,
|
|
2387
2410
|
model,
|
|
2388
2411
|
stream: false
|
|
2389
2412
|
});
|
|
@@ -2399,8 +2422,10 @@ function createOpenAIProvider(deps) {
|
|
|
2399
2422
|
throw new Error(clientResult.error.message);
|
|
2400
2423
|
const { client, model } = clientResult.data;
|
|
2401
2424
|
const { objectId: _objectId, sessionId: _sessionId, ...openaiRequest } = request;
|
|
2425
|
+
const openaiMessages = request.messages.map(toOpenAIMessage);
|
|
2402
2426
|
const stream = await client.chat.completions.create({
|
|
2403
2427
|
...openaiRequest,
|
|
2428
|
+
messages: openaiMessages,
|
|
2404
2429
|
model,
|
|
2405
2430
|
stream: true
|
|
2406
2431
|
});
|