@codehz/ai 0.4.3 → 0.4.5
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/.github/workflows/publish.yml +56 -0
- package/README.md +32 -4
- package/dist/index.d.mts +133 -32
- package/dist/index.mjs +209 -52
- package/dist/index.mjs.map +1 -1
- package/package.json +9 -1
- package/src/adapters/chat-completions.ts +24 -5
- package/src/adapters/messages.ts +24 -7
- package/src/adapters/mock.ts +7 -3
- package/src/adapters/ollama.ts +19 -2
- package/src/adapters/responses.ts +189 -55
- package/src/core/validation.ts +13 -0
- package/src/helpers/index.ts +14 -0
- package/src/helpers/provider-request-options.ts +25 -0
- package/src/helpers/reasoning-level.ts +85 -0
- package/src/types/index.ts +1 -1
- package/src/types/request.ts +11 -0
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
name: Publish Package
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
tags:
|
|
6
|
+
- "v*"
|
|
7
|
+
|
|
8
|
+
permissions:
|
|
9
|
+
contents: read
|
|
10
|
+
id-token: write # required for npm trusted publishing (OIDC)
|
|
11
|
+
|
|
12
|
+
jobs:
|
|
13
|
+
publish:
|
|
14
|
+
runs-on: ubuntu-latest
|
|
15
|
+
steps:
|
|
16
|
+
- uses: actions/checkout@v6
|
|
17
|
+
|
|
18
|
+
- name: Verify tag matches package.json version
|
|
19
|
+
run: |
|
|
20
|
+
tag="${GITHUB_REF_NAME#v}"
|
|
21
|
+
version="$(node -p "require('./package.json').version")"
|
|
22
|
+
if [ "$tag" != "$version" ]; then
|
|
23
|
+
echo "Tag v${tag} does not match package.json version ${version}"
|
|
24
|
+
exit 1
|
|
25
|
+
fi
|
|
26
|
+
|
|
27
|
+
- uses: oven-sh/setup-bun@v2
|
|
28
|
+
with:
|
|
29
|
+
bun-version: latest
|
|
30
|
+
|
|
31
|
+
- name: Install dependencies
|
|
32
|
+
run: bun install --frozen-lockfile
|
|
33
|
+
|
|
34
|
+
- name: Typecheck
|
|
35
|
+
run: bun run typecheck
|
|
36
|
+
|
|
37
|
+
- name: Lint
|
|
38
|
+
run: bun run lint
|
|
39
|
+
|
|
40
|
+
- name: Test
|
|
41
|
+
run: bun test
|
|
42
|
+
|
|
43
|
+
# Trusted publishing requires npm CLI (OIDC); other package managers cannot publish this way.
|
|
44
|
+
- uses: actions/setup-node@v6
|
|
45
|
+
with:
|
|
46
|
+
node-version: "24"
|
|
47
|
+
registry-url: "https://registry.npmjs.org"
|
|
48
|
+
package-manager-cache: false # never cache package manager state for release builds
|
|
49
|
+
|
|
50
|
+
- name: Ensure npm CLI supports trusted publishing
|
|
51
|
+
run: npm install -g npm@latest
|
|
52
|
+
|
|
53
|
+
- name: Publish to npm
|
|
54
|
+
# No NPM_TOKEN: npm CLI exchanges the GitHub OIDC token automatically.
|
|
55
|
+
# Provenance is generated automatically for trusted publishing from public repos.
|
|
56
|
+
run: npm publish --access public
|
package/README.md
CHANGED
|
@@ -45,10 +45,21 @@ 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
49
|
include?: { usage?; billing?; providerMetadata? };
|
|
49
50
|
};
|
|
50
51
|
```
|
|
51
52
|
|
|
53
|
+
`reasoningLevel` 是 portable 枚举,由各 adapter 映射到 provider 原生字段;未设置时不写相关 wire 字段。adapter 无法映射的 level(如 Ollama 的 `minimal` / `xhigh`)会抛 `AIRequestError`(`UNSUPPORTED_REASONING_LEVEL`)。需要 budget / summary 等特化参数时,仍可用构造期 `extraBody` 覆盖同名顶层键。
|
|
54
|
+
|
|
55
|
+
| Adapter | 映射 |
|
|
56
|
+
| --- | --- |
|
|
57
|
+
| `ResponsesAdapter` | `reasoning: { effort }` |
|
|
58
|
+
| `ChatCompletionsAdapter` | 顶层 `reasoning_effort` |
|
|
59
|
+
| `MessagesAdapter` | `thinking: { type: "disabled" }` 或 `{ type: "enabled", budget_tokens }`(由 `maxOutputTokens` 按比例推导,默认 4096) |
|
|
60
|
+
| `OllamaAdapter` | `think: false \| "low" \| "medium" \| "high"` |
|
|
61
|
+
| `MockAdapter` | 透传到 `MockHandlerContext.reasoningLevel` |
|
|
62
|
+
|
|
52
63
|
`input` 是 item 数组,每个 item 可以是:
|
|
53
64
|
|
|
54
65
|
| Item 类型 | 用途 |
|
|
@@ -133,16 +144,33 @@ import {
|
|
|
133
144
|
} from "@codehz/ai";
|
|
134
145
|
|
|
135
146
|
// OpenAI Responses API
|
|
136
|
-
const responses = new ResponsesAdapter({
|
|
147
|
+
const responses = new ResponsesAdapter({
|
|
148
|
+
apiKey: "sk-...",
|
|
149
|
+
// 可选:自定义请求头 / body 额外顶层字段(构造期静态,后写覆盖内置鉴权头与同名 body 键)
|
|
150
|
+
headers: { "OpenAI-Organization": "org-..." },
|
|
151
|
+
extraBody: { top_p: 0.9 },
|
|
152
|
+
});
|
|
137
153
|
|
|
138
154
|
// Anthropic Messages API
|
|
139
|
-
const messages = new MessagesAdapter({
|
|
155
|
+
const messages = new MessagesAdapter({
|
|
156
|
+
apiKey: "sk-ant-...",
|
|
157
|
+
headers: { "anthropic-beta": "..." },
|
|
158
|
+
extraBody: { top_p: 0.9 },
|
|
159
|
+
});
|
|
140
160
|
|
|
141
161
|
// OpenAI Chat Completions
|
|
142
|
-
const chat = new ChatCompletionsAdapter({
|
|
162
|
+
const chat = new ChatCompletionsAdapter({
|
|
163
|
+
apiKey: "sk-...",
|
|
164
|
+
headers: { "OpenAI-Organization": "org-..." },
|
|
165
|
+
extraBody: { top_p: 0.9 },
|
|
166
|
+
});
|
|
143
167
|
|
|
144
168
|
// Ollama
|
|
145
|
-
const ollama = new OllamaAdapter({
|
|
169
|
+
const ollama = new OllamaAdapter({
|
|
170
|
+
baseUrl: "http://localhost:11434",
|
|
171
|
+
headers: { "X-Custom": "..." },
|
|
172
|
+
extraBody: { keep_alive: "10m" },
|
|
173
|
+
});
|
|
146
174
|
|
|
147
175
|
// 面向测试的回调驱动 mock backend
|
|
148
176
|
const mock = new MockAdapter({
|
package/dist/index.d.mts
CHANGED
|
@@ -79,6 +79,8 @@ type IncludeSettings = {
|
|
|
79
79
|
billing?: "off" | "best_effort";
|
|
80
80
|
providerMetadata?: "off" | "best_effort";
|
|
81
81
|
};
|
|
82
|
+
/** Portable reasoning / thinking effort. Mapped per-adapter to provider wire fields. */
|
|
83
|
+
type ReasoningLevel = "none" | "minimal" | "low" | "medium" | "high" | "xhigh";
|
|
82
84
|
type AIRequest = {
|
|
83
85
|
instructions?: string | InstructionBlock[];
|
|
84
86
|
input: InputItem[];
|
|
@@ -87,7 +89,13 @@ type AIRequest = {
|
|
|
87
89
|
include?: IncludeSettings;
|
|
88
90
|
metadata?: Record<string, string>;
|
|
89
91
|
temperature?: number;
|
|
90
|
-
maxOutputTokens?: number;
|
|
92
|
+
maxOutputTokens?: number;
|
|
93
|
+
/**
|
|
94
|
+
* Portable reasoning effort. Adapters map this to provider-native fields
|
|
95
|
+
* (e.g. Responses `reasoning.effort`, Chat Completions `reasoning_effort`,
|
|
96
|
+
* Messages `thinking`, Ollama `think`). Unsupported levels throw.
|
|
97
|
+
*/
|
|
98
|
+
reasoningLevel?: ReasoningLevel; /** AbortSignal 用于打断请求。abort 时 fetch 调用会被取消,流迭代器抛出 AbortError。 */
|
|
91
99
|
signal?: AbortSignal;
|
|
92
100
|
};
|
|
93
101
|
//#endregion
|
|
@@ -551,7 +559,9 @@ declare abstract class AdapterBase implements BackendAdapter {
|
|
|
551
559
|
type ResponsesAdapterOptions = {
|
|
552
560
|
apiKey: string;
|
|
553
561
|
baseUrl?: string; /** 可注入自定义 fetch 实现(用于测试/代理) */
|
|
554
|
-
fetch?: FetchFn;
|
|
562
|
+
fetch?: FetchFn; /** 额外请求头;后写覆盖内置 Authorization / Content-Type */
|
|
563
|
+
headers?: Record<string, string>; /** 额外 body 顶层字段;浅层合并,同名键可覆盖 */
|
|
564
|
+
extraBody?: Record<string, unknown>;
|
|
555
565
|
};
|
|
556
566
|
type ResponsesAPIRequest = {
|
|
557
567
|
model: string;
|
|
@@ -564,49 +574,75 @@ type ResponsesAPIRequest = {
|
|
|
564
574
|
};
|
|
565
575
|
metadata?: Record<string, string>;
|
|
566
576
|
temperature?: number;
|
|
567
|
-
max_output_tokens?: number;
|
|
577
|
+
max_output_tokens?: number; /** Portable reasoningLevel → effort;summary 等特化字段不在此层 */
|
|
578
|
+
reasoning?: {
|
|
579
|
+
effort: string;
|
|
580
|
+
}; /** 服务端多轮续写;opaque replay 的 response id 映射到此字段,而非 item_reference */
|
|
581
|
+
previous_response_id?: string;
|
|
568
582
|
stream: true;
|
|
569
583
|
};
|
|
570
|
-
|
|
584
|
+
/** EasyInputMessage:content 可为 string,或 input_* content parts */
|
|
585
|
+
type ResponsesEasyMessage = {
|
|
571
586
|
type: "message";
|
|
572
|
-
role: "user" | "assistant";
|
|
573
|
-
content: string;
|
|
587
|
+
role: "user" | "assistant" | "system" | "developer";
|
|
588
|
+
content: string | ResponsesInputContentPart[];
|
|
589
|
+
};
|
|
590
|
+
type ResponsesInputContentPart = {
|
|
591
|
+
type: "input_text";
|
|
592
|
+
text: string;
|
|
574
593
|
} | {
|
|
575
|
-
type: "
|
|
576
|
-
|
|
577
|
-
|
|
594
|
+
type: "input_image";
|
|
595
|
+
image_url: string;
|
|
596
|
+
detail?: "auto" | "low" | "high";
|
|
578
597
|
} | {
|
|
598
|
+
type: "input_file";
|
|
599
|
+
file_url?: string;
|
|
600
|
+
file_id?: string;
|
|
601
|
+
filename?: string;
|
|
602
|
+
};
|
|
603
|
+
/** function_call:call_id 必填;id 是可选的 item id */
|
|
604
|
+
type ResponsesFunctionCall = {
|
|
579
605
|
type: "function_call";
|
|
580
|
-
|
|
606
|
+
call_id: string;
|
|
581
607
|
name: string;
|
|
582
608
|
arguments: string;
|
|
583
|
-
|
|
584
|
-
|
|
609
|
+
id?: string;
|
|
610
|
+
status?: "in_progress" | "completed" | "incomplete";
|
|
611
|
+
};
|
|
612
|
+
type ResponsesFunctionCallOutput = {
|
|
585
613
|
type: "function_call_output";
|
|
586
614
|
call_id: string;
|
|
587
615
|
output: string;
|
|
588
|
-
|
|
616
|
+
id?: string;
|
|
617
|
+
status?: "in_progress" | "completed" | "incomplete";
|
|
618
|
+
};
|
|
619
|
+
/** reasoning:id + summary/content/encrypted_content,不是任意 content blocks */
|
|
620
|
+
type ResponsesReasoningInput = {
|
|
589
621
|
type: "reasoning";
|
|
590
|
-
content: ResponsesContentBlock[];
|
|
591
|
-
} | {
|
|
592
|
-
type: "item_reference";
|
|
593
622
|
id: string;
|
|
623
|
+
summary: Array<{
|
|
624
|
+
type: "summary_text";
|
|
625
|
+
text: string;
|
|
626
|
+
}>;
|
|
627
|
+
content?: Array<{
|
|
628
|
+
type: "reasoning_text";
|
|
629
|
+
text: string;
|
|
630
|
+
}>;
|
|
631
|
+
encrypted_content?: string | null;
|
|
632
|
+
status?: "in_progress" | "completed" | "incomplete";
|
|
594
633
|
};
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
type: "reasoning";
|
|
600
|
-
text: string;
|
|
601
|
-
} | {
|
|
602
|
-
type: "refusal";
|
|
603
|
-
refusal: string;
|
|
634
|
+
/** 引用既有 item(不是 response id) */
|
|
635
|
+
type ResponsesItemReference = {
|
|
636
|
+
type: "item_reference";
|
|
637
|
+
id: string;
|
|
604
638
|
};
|
|
639
|
+
type ResponsesInputItem = ResponsesEasyMessage | ResponsesFunctionCall | ResponsesFunctionCallOutput | ResponsesReasoningInput | ResponsesItemReference;
|
|
605
640
|
type ResponsesTool = {
|
|
606
641
|
type: "function";
|
|
607
642
|
name: string;
|
|
608
643
|
description?: string;
|
|
609
644
|
parameters: Record<string, unknown>;
|
|
645
|
+
strict?: boolean | null;
|
|
610
646
|
};
|
|
611
647
|
declare class ResponsesAdapter extends AdapterBase {
|
|
612
648
|
readonly kind: "responses";
|
|
@@ -614,6 +650,8 @@ declare class ResponsesAdapter extends AdapterBase {
|
|
|
614
650
|
private apiKey;
|
|
615
651
|
private baseUrl;
|
|
616
652
|
private fetchFn;
|
|
653
|
+
private headers;
|
|
654
|
+
private extraBody;
|
|
617
655
|
constructor(options: ResponsesAdapterOptions);
|
|
618
656
|
protected buildRequest(request: NormalizedRequest): ResponsesAPIRequest;
|
|
619
657
|
protected runStream(providerRequest: ResponsesAPIRequest, factory: EventFactory, request: NormalizedRequest): AsyncIterable<AIStreamEvent>;
|
|
@@ -625,7 +663,9 @@ type MessagesAdapterOptions = {
|
|
|
625
663
|
apiKey: string;
|
|
626
664
|
apiVersion?: string;
|
|
627
665
|
baseUrl?: string; /** 可注入自定义 fetch 实现(用于测试/代理) */
|
|
628
|
-
fetch?: FetchFn;
|
|
666
|
+
fetch?: FetchFn; /** 额外请求头;后写覆盖内置 x-api-key / Content-Type / anthropic-version */
|
|
667
|
+
headers?: Record<string, string>; /** 额外 body 顶层字段;浅层合并,同名键可覆盖 */
|
|
668
|
+
extraBody?: Record<string, unknown>;
|
|
629
669
|
};
|
|
630
670
|
type MessagesAPIRequest = {
|
|
631
671
|
model: string;
|
|
@@ -643,6 +683,8 @@ type MessagesAPIRequest = {
|
|
|
643
683
|
thinking?: {
|
|
644
684
|
type: "enabled";
|
|
645
685
|
budget_tokens: number;
|
|
686
|
+
} | {
|
|
687
|
+
type: "disabled";
|
|
646
688
|
};
|
|
647
689
|
stream: true;
|
|
648
690
|
};
|
|
@@ -683,6 +725,8 @@ declare class MessagesAdapter extends AdapterBase {
|
|
|
683
725
|
private apiVersion;
|
|
684
726
|
private baseUrl;
|
|
685
727
|
private fetchFn;
|
|
728
|
+
private headers;
|
|
729
|
+
private extraBody;
|
|
686
730
|
constructor(options: MessagesAdapterOptions);
|
|
687
731
|
protected buildRequest(request: NormalizedRequest): MessagesAPIRequest;
|
|
688
732
|
protected runStream(providerRequest: MessagesAPIRequest, factory: EventFactory, request: NormalizedRequest): AsyncIterable<AIStreamEvent>;
|
|
@@ -692,7 +736,9 @@ declare class MessagesAdapter extends AdapterBase {
|
|
|
692
736
|
type ChatCompletionsAdapterOptions = {
|
|
693
737
|
apiKey: string;
|
|
694
738
|
baseUrl?: string;
|
|
695
|
-
fetch?: FetchFn;
|
|
739
|
+
fetch?: FetchFn; /** 额外请求头;后写覆盖内置 Authorization / Content-Type */
|
|
740
|
+
headers?: Record<string, string>; /** 额外 body 顶层字段;浅层合并,同名键可覆盖 */
|
|
741
|
+
extraBody?: Record<string, unknown>;
|
|
696
742
|
};
|
|
697
743
|
type ChatRequest = {
|
|
698
744
|
model: string;
|
|
@@ -706,7 +752,8 @@ type ChatRequest = {
|
|
|
706
752
|
};
|
|
707
753
|
metadata?: Record<string, string>;
|
|
708
754
|
temperature?: number;
|
|
709
|
-
max_tokens?: number;
|
|
755
|
+
max_tokens?: number; /** Portable reasoningLevel → reasoning_effort */
|
|
756
|
+
reasoning_effort?: string;
|
|
710
757
|
stream: true;
|
|
711
758
|
n: 1;
|
|
712
759
|
};
|
|
@@ -740,6 +787,8 @@ declare class ChatCompletionsAdapter extends AdapterBase {
|
|
|
740
787
|
private apiKey;
|
|
741
788
|
private baseUrl;
|
|
742
789
|
private fetchFn;
|
|
790
|
+
private headers;
|
|
791
|
+
private extraBody;
|
|
743
792
|
constructor(options: ChatCompletionsAdapterOptions);
|
|
744
793
|
protected buildRequest(request: NormalizedRequest): ChatRequest;
|
|
745
794
|
protected runStream(providerRequest: ChatRequest, factory: EventFactory, request: NormalizedRequest): AsyncIterable<AIStreamEvent>;
|
|
@@ -749,13 +798,16 @@ declare class ChatCompletionsAdapter extends AdapterBase {
|
|
|
749
798
|
type OllamaAdapterOptions = {
|
|
750
799
|
/** Ollama 服务地址,默认 http://localhost:11434 */baseUrl?: string; /** 可选 API key(用于需要认证的代理场景) */
|
|
751
800
|
apiKey?: string; /** 可注入自定义 fetch 实现 */
|
|
752
|
-
fetch?: FetchFn;
|
|
801
|
+
fetch?: FetchFn; /** 额外请求头;后写覆盖内置 Content-Type / Authorization */
|
|
802
|
+
headers?: Record<string, string>; /** 额外 body 顶层字段;浅层合并,同名键可覆盖 */
|
|
803
|
+
extraBody?: Record<string, unknown>;
|
|
753
804
|
};
|
|
754
805
|
type OllamaChatRequest = {
|
|
755
806
|
model: string;
|
|
756
807
|
messages: OllamaMessage[];
|
|
757
808
|
stream: true;
|
|
758
|
-
tools?: OllamaTool[];
|
|
809
|
+
tools?: OllamaTool[]; /** Portable reasoningLevel → think;minimal/xhigh 不支持 */
|
|
810
|
+
think?: boolean | "low" | "medium" | "high";
|
|
759
811
|
options?: {
|
|
760
812
|
temperature?: number;
|
|
761
813
|
num_predict?: number;
|
|
@@ -788,6 +840,8 @@ declare class OllamaAdapter extends AdapterBase {
|
|
|
788
840
|
private baseUrl;
|
|
789
841
|
private apiKey;
|
|
790
842
|
private fetchFn;
|
|
843
|
+
private headers;
|
|
844
|
+
private extraBody;
|
|
791
845
|
constructor(options?: OllamaAdapterOptions);
|
|
792
846
|
protected buildRequest(request: NormalizedRequest): OllamaChatRequest;
|
|
793
847
|
protected runStream(providerRequest: OllamaChatRequest, factory: EventFactory, request: NormalizedRequest): AsyncIterable<AIStreamEvent>;
|
|
@@ -834,7 +888,8 @@ type MockHandlerContext = {
|
|
|
834
888
|
previousReplay: ReplayItem[];
|
|
835
889
|
pendingToolCalls: readonly ToolCallItem[];
|
|
836
890
|
history: readonly MockHistoryRecord[]; /** 请求的 AbortSignal,handler 可检查 signal.aborted 提前退出。 */
|
|
837
|
-
signal?: AbortSignal;
|
|
891
|
+
signal?: AbortSignal; /** 当前请求的 portable reasoningLevel(若设置)。 */
|
|
892
|
+
reasoningLevel?: ReasoningLevel;
|
|
838
893
|
};
|
|
839
894
|
type MockWarningStep = {
|
|
840
895
|
type: "warning";
|
|
@@ -1177,6 +1232,52 @@ declare function createCompletionGate(): {
|
|
|
1177
1232
|
tryComplete(): boolean;
|
|
1178
1233
|
};
|
|
1179
1234
|
//#endregion
|
|
1235
|
+
//#region src/helpers/provider-request-options.d.ts
|
|
1236
|
+
/**
|
|
1237
|
+
* Provider 请求 headers / body 扩展合并
|
|
1238
|
+
*
|
|
1239
|
+
* 供真实后端 adapter 构造选项 `headers` / `extraBody` 使用:
|
|
1240
|
+
* - headers:内置鉴权头为基,自定义后写覆盖
|
|
1241
|
+
* - extraBody:已构建 body 为基,额外字段浅层 spread,同名顶层键可覆盖
|
|
1242
|
+
*/
|
|
1243
|
+
/** 合并内置 headers 与自定义 headers;自定义后写覆盖同名键。 */
|
|
1244
|
+
declare function mergeProviderHeaders(base: Record<string, string>, custom?: Record<string, string>): Record<string, string>;
|
|
1245
|
+
/**
|
|
1246
|
+
* 将构造期 extraBody 浅层合并到已构建的 provider body。
|
|
1247
|
+
* 无 extraBody 时原样返回;有则允许覆盖同名顶层键。
|
|
1248
|
+
*/
|
|
1249
|
+
declare function applyExtraBody<T extends object>(body: T, extraBody?: Record<string, unknown>): T;
|
|
1250
|
+
//#endregion
|
|
1251
|
+
//#region src/helpers/reasoning-level.d.ts
|
|
1252
|
+
declare const REASONING_LEVELS: readonly ["none", "minimal", "low", "medium", "high", "xhigh"];
|
|
1253
|
+
declare const REASONING_LEVEL_SET: ReadonlySet<string>;
|
|
1254
|
+
type OpenAIReasoningEffort = ReasoningLevel;
|
|
1255
|
+
type MessagesThinkingConfig = {
|
|
1256
|
+
type: "disabled";
|
|
1257
|
+
} | {
|
|
1258
|
+
type: "enabled";
|
|
1259
|
+
budget_tokens: number;
|
|
1260
|
+
};
|
|
1261
|
+
type OllamaThinkValue = false | "low" | "medium" | "high";
|
|
1262
|
+
/** 若 level 不在 supported 集合内则抛 AIRequestError。 */
|
|
1263
|
+
declare function assertSupportedReasoningLevel(level: ReasoningLevel, supported: ReadonlySet<ReasoningLevel>, adapterKind: string): void;
|
|
1264
|
+
/** Responses API:`reasoning: { effort }` */
|
|
1265
|
+
declare function mapResponsesReasoning(level: ReasoningLevel): {
|
|
1266
|
+
effort: OpenAIReasoningEffort;
|
|
1267
|
+
};
|
|
1268
|
+
/** Chat Completions:顶层 `reasoning_effort` */
|
|
1269
|
+
declare function mapChatCompletionsReasoningEffort(level: ReasoningLevel): OpenAIReasoningEffort;
|
|
1270
|
+
/**
|
|
1271
|
+
* Messages thinking budget。
|
|
1272
|
+
* 基于 maxTokens 按比例推导,clamp 到 [1024, max(1024, maxTokens - 1)],
|
|
1273
|
+
* 满足 Anthropic budget_tokens < max_tokens。
|
|
1274
|
+
*/
|
|
1275
|
+
declare function mapMessagesThinkingBudget(level: Exclude<ReasoningLevel, "none">, maxTokens: number): number;
|
|
1276
|
+
/** Messages API:`thinking` 字段 */
|
|
1277
|
+
declare function mapMessagesThinking(level: ReasoningLevel, maxTokens: number): MessagesThinkingConfig;
|
|
1278
|
+
/** Ollama:`think` 字段;minimal/xhigh 不支持 */
|
|
1279
|
+
declare function mapOllamaThink(level: ReasoningLevel): OllamaThinkValue;
|
|
1280
|
+
//#endregion
|
|
1180
1281
|
//#region src/helpers/request-mapper.d.ts
|
|
1181
1282
|
declare class NormalizedRequestMapper {
|
|
1182
1283
|
readonly kind: string;
|
|
@@ -1205,5 +1306,5 @@ declare class NormalizedRequestMapper {
|
|
|
1205
1306
|
private ensureBlocks;
|
|
1206
1307
|
}
|
|
1207
1308
|
//#endregion
|
|
1208
|
-
export { type AIClient, AIError, AIMappingError, AIProviderError, type AIRequest, AIRequestError, type AIResponse, AIStreamError, type AIStreamEvent, AdapterAuxiliaryState, AdapterBase, AuxiliaryCollector, type AuxiliaryFinalizeOptions, type AuxiliaryFinalizeResult, type AuxiliaryInfo, type BackendAdapter, type BackendTrace, type BillingInfo, type BillingPostprocessHook, type BillingSource, ChatCompletionsAdapter, type ChatCompletionsAdapterOptions, type ContentBlock, type CreateAIClientOptions, type EventFactory, type EventFactoryBackend, type EventFactoryState, type FetchFn, type IncludeSettings, IncrementalStreamParser, type InputItem, type InstructionBlock, type JsonContentBlock, type LookupResult, MAX_OPAQUE_JSON_DEPTH, MAX_OPAQUE_PAYLOAD_BYTES, type MessageCompletedEvent, type MessageDeltaEvent, type MessageItem, type MessageStartedEvent, MessagesAdapter, type MessagesAdapterOptions, MockAdapter, type MockAdapterOptions, type MockAuxiliaryStep, type MockCompleteStep, type MockErrorStep, type MockHandler, type MockHandlerContext, type MockHistoryRecord, type MockInputExpectation, type MockInterruptStep, type MockMessageStep, type MockOutputStep, type MockReasoningStep, type MockRequestExpectation, type MockStaticHandler, type MockStep, type MockTextStreamOptions, type MockThrowStep, type MockToolCallStep, type MockWarningStep, type NormalizeOptions, type NormalizedRequest, NormalizedRequestMapper, OllamaAdapter, type OllamaAdapterOptions, type OpaqueEnvelopeResult, type OpaqueItem, type OpenProviderJsonStreamOptions, type OpenedProviderStream, type OutputItem, PROVIDER_ERROR_MESSAGE_MAX_LEN, PROVIDER_ERROR_RAW_BODY_THRESHOLD, type ProviderStreamBatch, type ProviderStreamBatchOptions, type ReasoningCompletedEvent, type ReasoningDeltaEvent, type ReasoningItem, type ReasoningStartedEvent, type ReplayItem, type ResponseAuxiliaryEvent, type ResponseCompletedEvent, type ResponseStartedEvent, type ResponseWarningEvent, ResponsesAdapter, type ResponsesAdapterOptions, type SseJsonEvent, type StopReason, type StreamEventBase, type StreamParseResult, type StreamResult, type StreamSplitResult, type SyntheticStreamOptions, type TextContentBlock, type ToolCallCompletedEvent, type ToolCallDeltaEvent, type ToolCallItem, type ToolCallStartedEvent, type ToolChoice, type ToolDefinition, type ToolResultItem, type Usage, type UsageSource, type ValidationIssue, WarningCode, aggregateEvents, assertMockRequest, assertOpaqueReplayEnvelope, assertValidRequest, blockToText, collectStream, contentBlocksToText, createAIClient, createChatCompletionsSseParser, createCompletionGate, createEventFactory, createNdjsonLineParser, createSseJsonParser, emitMalformedStreamWarning, extractProviderErrorMessage, extractText, imageBlock, iterateProviderStreamBatches, jsonBlock, mapReasoningVisibility, mapStopReason, measureJsonDepth, messageItem, normalizeRequest, opaqueBlock, opaqueItem, openProviderJsonStream, parseChatCompletionsDataLine, parseSseJsonFrame, providerHttpError, reasoningItem, replayFromOutput, splitLines, splitSSEFrames, syntheticStream, textBlock, toolCallItem, toolResultItem, usageFromAnthropicMessages, usageFromChatCompletions, usageFromOllama, usageFromOpenAIResponses, validateOpaqueReplayEnvelope, validateRequest, withMockStreaming };
|
|
1309
|
+
export { type AIClient, AIError, AIMappingError, AIProviderError, type AIRequest, AIRequestError, type AIResponse, AIStreamError, type AIStreamEvent, AdapterAuxiliaryState, AdapterBase, AuxiliaryCollector, type AuxiliaryFinalizeOptions, type AuxiliaryFinalizeResult, type AuxiliaryInfo, type BackendAdapter, type BackendTrace, type BillingInfo, type BillingPostprocessHook, type BillingSource, ChatCompletionsAdapter, type ChatCompletionsAdapterOptions, type ContentBlock, type CreateAIClientOptions, type EventFactory, type EventFactoryBackend, type EventFactoryState, type FetchFn, type IncludeSettings, IncrementalStreamParser, type InputItem, type InstructionBlock, type JsonContentBlock, type LookupResult, MAX_OPAQUE_JSON_DEPTH, MAX_OPAQUE_PAYLOAD_BYTES, type MessageCompletedEvent, type MessageDeltaEvent, type MessageItem, type MessageStartedEvent, MessagesAdapter, type MessagesAdapterOptions, type MessagesThinkingConfig, MockAdapter, type MockAdapterOptions, type MockAuxiliaryStep, type MockCompleteStep, type MockErrorStep, type MockHandler, type MockHandlerContext, type MockHistoryRecord, type MockInputExpectation, type MockInterruptStep, type MockMessageStep, type MockOutputStep, type MockReasoningStep, type MockRequestExpectation, type MockStaticHandler, type MockStep, type MockTextStreamOptions, type MockThrowStep, type MockToolCallStep, type MockWarningStep, type NormalizeOptions, type NormalizedRequest, NormalizedRequestMapper, OllamaAdapter, type OllamaAdapterOptions, type OllamaThinkValue, type OpaqueEnvelopeResult, type OpaqueItem, type OpenAIReasoningEffort, type OpenProviderJsonStreamOptions, type OpenedProviderStream, type OutputItem, PROVIDER_ERROR_MESSAGE_MAX_LEN, PROVIDER_ERROR_RAW_BODY_THRESHOLD, type ProviderStreamBatch, type ProviderStreamBatchOptions, REASONING_LEVELS, REASONING_LEVEL_SET, type ReasoningCompletedEvent, type ReasoningDeltaEvent, type ReasoningItem, type ReasoningLevel, type ReasoningStartedEvent, type ReplayItem, type ResponseAuxiliaryEvent, type ResponseCompletedEvent, type ResponseStartedEvent, type ResponseWarningEvent, ResponsesAdapter, type ResponsesAdapterOptions, type SseJsonEvent, type StopReason, type StreamEventBase, type StreamParseResult, type StreamResult, type StreamSplitResult, type SyntheticStreamOptions, type TextContentBlock, type ToolCallCompletedEvent, type ToolCallDeltaEvent, type ToolCallItem, type ToolCallStartedEvent, type ToolChoice, type ToolDefinition, type ToolResultItem, type Usage, type UsageSource, type ValidationIssue, WarningCode, aggregateEvents, applyExtraBody, assertMockRequest, assertOpaqueReplayEnvelope, assertSupportedReasoningLevel, assertValidRequest, blockToText, collectStream, contentBlocksToText, createAIClient, createChatCompletionsSseParser, createCompletionGate, createEventFactory, createNdjsonLineParser, createSseJsonParser, emitMalformedStreamWarning, extractProviderErrorMessage, extractText, imageBlock, iterateProviderStreamBatches, jsonBlock, mapChatCompletionsReasoningEffort, mapMessagesThinking, mapMessagesThinkingBudget, mapOllamaThink, mapReasoningVisibility, mapResponsesReasoning, mapStopReason, measureJsonDepth, mergeProviderHeaders, messageItem, normalizeRequest, opaqueBlock, opaqueItem, openProviderJsonStream, parseChatCompletionsDataLine, parseSseJsonFrame, providerHttpError, reasoningItem, replayFromOutput, splitLines, splitSSEFrames, syntheticStream, textBlock, toolCallItem, toolResultItem, usageFromAnthropicMessages, usageFromChatCompletions, usageFromOllama, usageFromOpenAIResponses, validateOpaqueReplayEnvelope, validateRequest, withMockStreaming };
|
|
1209
1310
|
//# sourceMappingURL=index.d.mts.map
|