@codehz/ai 0.7.1 → 0.8.1

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 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; // 温度 (0–2)
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
@@ -836,11 +836,7 @@ type HttpAdapterOptions = {
836
836
  baseUrl?: string; /** 可注入自定义 fetch 实现(测试 / 代理) */
837
837
  fetch?: FetchFn; /** 额外请求头;后写覆盖内置鉴权 / Content-Type 等 */
838
838
  headers?: Record<string, string>; /** 额外 body 顶层字段;浅层合并,同名键可覆盖 */
839
- extraBody?: Record<string, unknown>;
840
- /**
841
- * 单条 opaque replay payload 体积上限(JSON.stringify 码元长度)。
842
- * 默认 1 MiB;夹到 [1, 8 MiB] 硬顶。emit 与 accept 共用。
843
- */
839
+ extraBody?: Record<string, unknown>; /** Deprecated compatibility option; opaque replay is not size-limited. */
844
840
  maxOpaquePayloadBytes?: number;
845
841
  };
846
842
  type HttpAdapterDefaults = {
@@ -855,7 +851,7 @@ declare abstract class HttpAdapterBase extends AdapterBase {
855
851
  protected fetchFn: FetchFn;
856
852
  protected headers: Record<string, string> | undefined;
857
853
  protected extraBody: Record<string, unknown> | undefined;
858
- /** clamp opaque 体积上限(emit / accept 共用)。 */
854
+ /** Deprecated compatibility field; opaque replay is not size-limited. */
859
855
  protected maxOpaquePayloadBytes: number;
860
856
  constructor(options: HttpAdapterOptions, defaults: HttpAdapterDefaults);
861
857
  /** 合并内置 headers 与构造期自定义 headers。 */
@@ -923,7 +919,7 @@ type ResponsesFunctionCall = {
923
919
  type ResponsesFunctionCallOutput = {
924
920
  type: "function_call_output";
925
921
  call_id: string;
926
- output: string;
922
+ output: string | ResponsesInputContentPart[];
927
923
  id?: string;
928
924
  status?: "in_progress" | "completed" | "incomplete";
929
925
  };
@@ -1050,9 +1046,21 @@ type MessagesAPIMessage = {
1050
1046
  role: "user" | "assistant";
1051
1047
  content: string | MessagesAPIContentBlock[];
1052
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
+ };
1053
1058
  type MessagesAPIContentBlock = {
1054
1059
  type: "text";
1055
1060
  text: string;
1061
+ } | {
1062
+ type: "image";
1063
+ source: MessagesAPIImageSource;
1056
1064
  } | {
1057
1065
  type: "thinking";
1058
1066
  thinking: string;
@@ -1109,9 +1117,21 @@ type ChatRequest = {
1109
1117
  stream: true;
1110
1118
  n: 1;
1111
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;
1112
1132
  type ChatMessage = {
1113
1133
  role: "system" | "user" | "assistant" | "tool";
1114
- content: string | null;
1134
+ content: string | null | ChatContentPart[];
1115
1135
  tool_calls?: ChatToolCall[];
1116
1136
  tool_call_id?: string;
1117
1137
  name?: string;
@@ -1199,6 +1219,10 @@ type GeminiPart = {
1199
1219
  text?: string;
1200
1220
  thought?: boolean;
1201
1221
  thoughtSignature?: string;
1222
+ inlineData?: {
1223
+ mimeType: string;
1224
+ data: string;
1225
+ };
1202
1226
  functionCall?: {
1203
1227
  name: string;
1204
1228
  args?: Record<string, unknown>;