@codehz/ai 0.7.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -1
- package/dist/index.d.mts +35 -3
- package/dist/index.mjs +417 -526
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -25,12 +25,20 @@ type StreamWarning = { message: string; code?: WarningCode };
|
|
|
25
25
|
|
|
26
26
|
入站 opaque 仅接受 `messages` 形(`{ messages: ChatMessage[] }`)。单条 `{ role, content }` 已 **deprecate**(有效 envelope 下未识别 shape 会被跳过,不再当完整 assistant turn 还原)。出站仍写 `messages: [assistantReplayMessage]`。
|
|
27
27
|
|
|
28
|
+
opaque replay 只检查 object 和 JSON 可序列化性;客户端不再强制 1MiB/8MiB 大小或嵌套深度上限,也不会因这些通用限制丢弃 replay。实际请求大小和 provider 可接受的 payload 由 provider / transport 决定。
|
|
29
|
+
|
|
28
30
|
### 其余行为(0.6 一并落地,多为兼容增强)
|
|
29
31
|
|
|
30
32
|
- HTTP adapter 错误码与 incomplete 流完成路径收敛;Chat Completions 支持 arguments-before-id 与 `function_call`/`tool_calls` 互斥 warning。
|
|
31
33
|
- Aggregator 在 finalize 时从 `output` 派生 `text` / `toolCalls` / `serverTool*`;`argumentsText` 分块累积。
|
|
32
34
|
- 四家厚 adapter 拆为 `map-request` / `map-stream`(对齐 `responses`);opaque 恒尾置。
|
|
33
35
|
|
|
36
|
+
### 请求校验边界
|
|
37
|
+
|
|
38
|
+
`normalizeRequest` 和 `createAIClient` 不再自动运行通用 `validateRequest`。客户端只做默认值合并、`include` 归一化和 request id 生成;`temperature`、`maxOutputTokens`、tool 名称及其他 provider/model policy 交给目标 provider。adapter 仍保留构造合法 wire request 所需的 capability、shape 和 JSON object 检查。
|
|
39
|
+
|
|
40
|
+
通用校验器不再从 runtime 入口导出;应用如果需要严格输入检查,应在自己的信任边界显式实现。
|
|
41
|
+
|
|
34
42
|
## 0.5.0 迁移说明(摘要)
|
|
35
43
|
|
|
36
44
|
`0.5.0` 收紧了根入口公开面:`AdapterBase`、`createEventFactory`、`aggregateEvents`、`normalizeRequest`、transport / `syntheticStream` 等**不再**从 `@codehz/ai` 根导出(内部模块)。
|
|
@@ -86,7 +94,7 @@ type AIRequest = {
|
|
|
86
94
|
tools?: ToolDefinition[]; // 客户端函数工具(由调用方执行)
|
|
87
95
|
serverTools?: ServerToolDefinition[]; // Provider 托管工具(web_search / code_execution / mcp)
|
|
88
96
|
toolChoice?: ToolChoice; // 客户端工具选择策略
|
|
89
|
-
temperature?: number; //
|
|
97
|
+
temperature?: number; // provider/model-defined generation parameter
|
|
90
98
|
maxOutputTokens?: number; // 最大输出 token
|
|
91
99
|
reasoningLevel?: "none" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max"; // 可移植思考力度
|
|
92
100
|
include?: { usage?; billing?; providerMetadata? };
|
package/dist/index.d.mts
CHANGED
|
@@ -227,7 +227,8 @@ declare const WarningCode: {
|
|
|
227
227
|
readonly CONTENT_FILTER: "CONTENT_FILTER"; /** 多 choice 仅支持 index 0,其余忽略 */
|
|
228
228
|
readonly MULTIPLE_CHOICES_IGNORED: "MULTIPLE_CHOICES_IGNORED"; /** MCP 审批流不被支持 */
|
|
229
229
|
readonly MCP_APPROVAL_REQUIRED: "MCP_APPROVAL_REQUIRED"; /** provider 侧 response.failed 等失败 */
|
|
230
|
-
readonly PROVIDER_FAILURE: "PROVIDER_FAILURE";
|
|
230
|
+
readonly PROVIDER_FAILURE: "PROVIDER_FAILURE"; /** 出站 opaque 超限被省略(避免下一轮 accept 自产毒) */
|
|
231
|
+
readonly OPAQUE_REPLAY_OMITTED: "OPAQUE_REPLAY_OMITTED";
|
|
231
232
|
};
|
|
232
233
|
type WarningCodeName = (typeof WarningCode)[keyof typeof WarningCode];
|
|
233
234
|
/** 与 WarningCodeName 同义;保留以兼容既有 KnownWarningCode 命名 */
|
|
@@ -835,7 +836,8 @@ type HttpAdapterOptions = {
|
|
|
835
836
|
baseUrl?: string; /** 可注入自定义 fetch 实现(测试 / 代理) */
|
|
836
837
|
fetch?: FetchFn; /** 额外请求头;后写覆盖内置鉴权 / Content-Type 等 */
|
|
837
838
|
headers?: Record<string, string>; /** 额外 body 顶层字段;浅层合并,同名键可覆盖 */
|
|
838
|
-
extraBody?: Record<string, unknown>;
|
|
839
|
+
extraBody?: Record<string, unknown>; /** Deprecated compatibility option; opaque replay is not size-limited. */
|
|
840
|
+
maxOpaquePayloadBytes?: number;
|
|
839
841
|
};
|
|
840
842
|
type HttpAdapterDefaults = {
|
|
841
843
|
baseUrl: string;
|
|
@@ -849,6 +851,8 @@ declare abstract class HttpAdapterBase extends AdapterBase {
|
|
|
849
851
|
protected fetchFn: FetchFn;
|
|
850
852
|
protected headers: Record<string, string> | undefined;
|
|
851
853
|
protected extraBody: Record<string, unknown> | undefined;
|
|
854
|
+
/** Deprecated compatibility field; opaque replay is not size-limited. */
|
|
855
|
+
protected maxOpaquePayloadBytes: number;
|
|
852
856
|
constructor(options: HttpAdapterOptions, defaults: HttpAdapterDefaults);
|
|
853
857
|
/** 合并内置 headers 与构造期自定义 headers。 */
|
|
854
858
|
protected mergeHeaders(base: Record<string, string>): Record<string, string>;
|
|
@@ -1042,9 +1046,21 @@ type MessagesAPIMessage = {
|
|
|
1042
1046
|
role: "user" | "assistant";
|
|
1043
1047
|
content: string | MessagesAPIContentBlock[];
|
|
1044
1048
|
};
|
|
1049
|
+
type MessagesAPIImageMediaType = "image/jpeg" | "image/png" | "image/gif" | "image/webp";
|
|
1050
|
+
type MessagesAPIImageSource = {
|
|
1051
|
+
type: "base64";
|
|
1052
|
+
media_type: MessagesAPIImageMediaType;
|
|
1053
|
+
data: string;
|
|
1054
|
+
} | {
|
|
1055
|
+
type: "url";
|
|
1056
|
+
url: string;
|
|
1057
|
+
};
|
|
1045
1058
|
type MessagesAPIContentBlock = {
|
|
1046
1059
|
type: "text";
|
|
1047
1060
|
text: string;
|
|
1061
|
+
} | {
|
|
1062
|
+
type: "image";
|
|
1063
|
+
source: MessagesAPIImageSource;
|
|
1048
1064
|
} | {
|
|
1049
1065
|
type: "thinking";
|
|
1050
1066
|
thinking: string;
|
|
@@ -1101,9 +1117,21 @@ type ChatRequest = {
|
|
|
1101
1117
|
stream: true;
|
|
1102
1118
|
n: 1;
|
|
1103
1119
|
};
|
|
1120
|
+
type ChatTextPart = {
|
|
1121
|
+
type: "text";
|
|
1122
|
+
text: string;
|
|
1123
|
+
};
|
|
1124
|
+
type ChatImagePart = {
|
|
1125
|
+
type: "image_url";
|
|
1126
|
+
image_url: {
|
|
1127
|
+
url: string;
|
|
1128
|
+
detail?: "auto" | "low" | "high";
|
|
1129
|
+
};
|
|
1130
|
+
};
|
|
1131
|
+
type ChatContentPart = ChatTextPart | ChatImagePart;
|
|
1104
1132
|
type ChatMessage = {
|
|
1105
1133
|
role: "system" | "user" | "assistant" | "tool";
|
|
1106
|
-
content: string | null;
|
|
1134
|
+
content: string | null | ChatContentPart[];
|
|
1107
1135
|
tool_calls?: ChatToolCall[];
|
|
1108
1136
|
tool_call_id?: string;
|
|
1109
1137
|
name?: string;
|
|
@@ -1191,6 +1219,10 @@ type GeminiPart = {
|
|
|
1191
1219
|
text?: string;
|
|
1192
1220
|
thought?: boolean;
|
|
1193
1221
|
thoughtSignature?: string;
|
|
1222
|
+
inlineData?: {
|
|
1223
|
+
mimeType: string;
|
|
1224
|
+
data: string;
|
|
1225
|
+
};
|
|
1194
1226
|
functionCall?: {
|
|
1195
1227
|
name: string;
|
|
1196
1228
|
args?: Record<string, unknown>;
|