@codehz/ai 0.4.5 → 0.4.6

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
@@ -45,12 +45,12 @@ type AIRequest = {
45
45
  toolChoice?: ToolChoice; // 工具选择策略
46
46
  temperature?: number; // 温度 (0–2)
47
47
  maxOutputTokens?: number; // 最大输出 token
48
- reasoningLevel?: "none" | "minimal" | "low" | "medium" | "high" | "xhigh"; // 可移植思考力度
48
+ reasoningLevel?: "none" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max"; // 可移植思考力度
49
49
  include?: { usage?; billing?; providerMetadata? };
50
50
  };
51
51
  ```
52
52
 
53
- `reasoningLevel` 是 portable 枚举,由各 adapter 映射到 provider 原生字段;未设置时不写相关 wire 字段。adapter 无法映射的 level(如 Ollama 的 `minimal` / `xhigh`)会抛 `AIRequestError`(`UNSUPPORTED_REASONING_LEVEL`)。需要 budget / summary 等特化参数时,仍可用构造期 `extraBody` 覆盖同名顶层键。
53
+ `reasoningLevel` 是 portable 枚举,由各 adapter 映射到 provider 原生字段;未设置时不写相关 wire 字段。adapter 无法映射的 level(如 Ollama 的 `minimal` / `xhigh` / `max`)会抛 `AIRequestError`(`UNSUPPORTED_REASONING_LEVEL`)。需要 budget / summary 等特化参数时,仍可用构造期 `extraBody` 覆盖同名顶层键。
54
54
 
55
55
  | Adapter | 映射 |
56
56
  | --- | --- |
package/dist/index.d.mts CHANGED
@@ -80,7 +80,7 @@ type IncludeSettings = {
80
80
  providerMetadata?: "off" | "best_effort";
81
81
  };
82
82
  /** Portable reasoning / thinking effort. Mapped per-adapter to provider wire fields. */
83
- type ReasoningLevel = "none" | "minimal" | "low" | "medium" | "high" | "xhigh";
83
+ type ReasoningLevel = "none" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max";
84
84
  type AIRequest = {
85
85
  instructions?: string | InstructionBlock[];
86
86
  input: InputItem[];
@@ -806,7 +806,7 @@ type OllamaChatRequest = {
806
806
  model: string;
807
807
  messages: OllamaMessage[];
808
808
  stream: true;
809
- tools?: OllamaTool[]; /** Portable reasoningLevel → think;minimal/xhigh 不支持 */
809
+ tools?: OllamaTool[]; /** Portable reasoningLevel → think;minimal/xhigh/max 不支持 */
810
810
  think?: boolean | "low" | "medium" | "high";
811
811
  options?: {
812
812
  temperature?: number;
@@ -1249,7 +1249,7 @@ declare function mergeProviderHeaders(base: Record<string, string>, custom?: Rec
1249
1249
  declare function applyExtraBody<T extends object>(body: T, extraBody?: Record<string, unknown>): T;
1250
1250
  //#endregion
1251
1251
  //#region src/helpers/reasoning-level.d.ts
1252
- declare const REASONING_LEVELS: readonly ["none", "minimal", "low", "medium", "high", "xhigh"];
1252
+ declare const REASONING_LEVELS: readonly ["none", "minimal", "low", "medium", "high", "xhigh", "max"];
1253
1253
  declare const REASONING_LEVEL_SET: ReadonlySet<string>;
1254
1254
  type OpenAIReasoningEffort = ReasoningLevel;
1255
1255
  type MessagesThinkingConfig = {
@@ -1275,7 +1275,7 @@ declare function mapChatCompletionsReasoningEffort(level: ReasoningLevel): OpenA
1275
1275
  declare function mapMessagesThinkingBudget(level: Exclude<ReasoningLevel, "none">, maxTokens: number): number;
1276
1276
  /** Messages API:`thinking` 字段 */
1277
1277
  declare function mapMessagesThinking(level: ReasoningLevel, maxTokens: number): MessagesThinkingConfig;
1278
- /** Ollama:`think` 字段;minimal/xhigh 不支持 */
1278
+ /** Ollama:`think` 字段;minimal/xhigh/max 不支持 */
1279
1279
  declare function mapOllamaThink(level: ReasoningLevel): OllamaThinkValue;
1280
1280
  //#endregion
1281
1281
  //#region src/helpers/request-mapper.d.ts
package/dist/index.mjs CHANGED
@@ -86,7 +86,8 @@ const REASONING_LEVELS$1 = /* @__PURE__ */ new Set([
86
86
  "low",
87
87
  "medium",
88
88
  "high",
89
- "xhigh"
89
+ "xhigh",
90
+ "max"
90
91
  ]);
91
92
  function isRecord(value) {
92
93
  return typeof value === "object" && value !== null;
@@ -257,7 +258,7 @@ function validateRequest(request) {
257
258
  });
258
259
  }
259
260
  if (request.reasoningLevel !== void 0) {
260
- if (typeof request.reasoningLevel !== "string" || !REASONING_LEVELS$1.has(request.reasoningLevel)) pushIssue(issues, "reasoningLevel", "REASONING_LEVEL_INVALID", "reasoningLevel must be one of: none, minimal, low, medium, high, xhigh");
261
+ if (typeof request.reasoningLevel !== "string" || !REASONING_LEVELS$1.has(request.reasoningLevel)) pushIssue(issues, "reasoningLevel", "REASONING_LEVEL_INVALID", "reasoningLevel must be one of: none, minimal, low, medium, high, xhigh, max");
261
262
  }
262
263
  if (request.include !== void 0) validateInclude(request.include, issues);
263
264
  if (request.metadata !== void 0) {
@@ -1712,7 +1713,8 @@ const REASONING_LEVELS = [
1712
1713
  "low",
1713
1714
  "medium",
1714
1715
  "high",
1715
- "xhigh"
1716
+ "xhigh",
1717
+ "max"
1716
1718
  ];
1717
1719
  const REASONING_LEVEL_SET = new Set(REASONING_LEVELS);
1718
1720
  const MESSAGES_BUDGET_RATIOS = {
@@ -1720,7 +1722,8 @@ const MESSAGES_BUDGET_RATIOS = {
1720
1722
  low: .1,
1721
1723
  medium: .3,
1722
1724
  high: .6,
1723
- xhigh: .9
1725
+ xhigh: .9,
1726
+ max: .95
1724
1727
  };
1725
1728
  const OLLAMA_SUPPORTED = /* @__PURE__ */ new Set([
1726
1729
  "none",
@@ -1760,7 +1763,7 @@ function mapMessagesThinking(level, maxTokens) {
1760
1763
  budget_tokens: mapMessagesThinkingBudget(level, maxTokens)
1761
1764
  };
1762
1765
  }
1763
- /** Ollama:`think` 字段;minimal/xhigh 不支持 */
1766
+ /** Ollama:`think` 字段;minimal/xhigh/max 不支持 */
1764
1767
  function mapOllamaThink(level) {
1765
1768
  assertSupportedReasoningLevel(level, OLLAMA_SUPPORTED, "ollama");
1766
1769
  if (level === "none") return false;