@codehz/ai 0.4.6 → 0.7.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.
Files changed (46) hide show
  1. package/README.md +221 -75
  2. package/dist/index.d.mts +662 -523
  3. package/dist/index.mjs +3626 -2202
  4. package/dist/index.mjs.map +1 -1
  5. package/package.json +19 -8
  6. package/.github/workflows/publish.yml +0 -56
  7. package/.oxfmtrc.json +0 -12
  8. package/.oxlintrc.json +0 -34
  9. package/AGENTS.md +0 -37
  10. package/src/adapters/chat-completions.ts +0 -624
  11. package/src/adapters/index.ts +0 -44
  12. package/src/adapters/messages.ts +0 -635
  13. package/src/adapters/mock.ts +0 -934
  14. package/src/adapters/ollama.ts +0 -526
  15. package/src/adapters/responses.ts +0 -818
  16. package/src/core/aggregator.ts +0 -428
  17. package/src/core/client.ts +0 -36
  18. package/src/core/collect-stream.ts +0 -19
  19. package/src/core/errors.ts +0 -105
  20. package/src/core/event-factory.ts +0 -151
  21. package/src/core/index.ts +0 -18
  22. package/src/core/merge-auxiliary.ts +0 -22
  23. package/src/core/normalize.ts +0 -65
  24. package/src/core/validation.ts +0 -404
  25. package/src/helpers/adapter-auxiliary.ts +0 -155
  26. package/src/helpers/adapter-base.ts +0 -218
  27. package/src/helpers/adapter-security.ts +0 -126
  28. package/src/helpers/auxiliary-collector.ts +0 -166
  29. package/src/helpers/incremental-stream-parser.ts +0 -142
  30. package/src/helpers/index.ts +0 -87
  31. package/src/helpers/mapping.ts +0 -192
  32. package/src/helpers/provider-request-options.ts +0 -25
  33. package/src/helpers/provider-stream.ts +0 -147
  34. package/src/helpers/reasoning-level.ts +0 -86
  35. package/src/helpers/request-mapper.ts +0 -94
  36. package/src/helpers/synthetic-stream.ts +0 -188
  37. package/src/helpers/usage-mapping.ts +0 -110
  38. package/src/index.ts +0 -17
  39. package/src/types/adapter.ts +0 -42
  40. package/src/types/content.ts +0 -15
  41. package/src/types/events.ts +0 -138
  42. package/src/types/index.ts +0 -49
  43. package/src/types/items.ts +0 -57
  44. package/src/types/request.ts +0 -52
  45. package/src/types/response.ts +0 -68
  46. package/tsdown.config.ts +0 -10
@@ -1,94 +0,0 @@
1
- import { AIRequestError } from "../core/errors.js";
2
- import { contentBlocksToText } from "./mapping.js";
3
-
4
- import type { ContentBlock, InstructionBlock, ToolCallItem, ToolChoice, ToolDefinition } from "../types/index.js";
5
-
6
- export class NormalizedRequestMapper {
7
- constructor(readonly kind: string) {}
8
-
9
- mapInstructions(instructions: string | InstructionBlock[]): string {
10
- return typeof instructions === "string"
11
- ? instructions
12
- : contentBlocksToText(this.ensureTextBlocks(instructions, "instructions"));
13
- }
14
-
15
- ensureTextBlocks(blocks: ContentBlock[], field: string): ContentBlock[] {
16
- return this.ensureBlocks(blocks, field, ["text", "json"], "only text/json blocks are supported");
17
- }
18
-
19
- ensureReasoningBlocks(blocks: ContentBlock[], field: string): Array<Extract<ContentBlock, { type: "text" }>> {
20
- return this.ensureBlocks(blocks, field, ["text"], "reasoning only supports text blocks") as Array<
21
- Extract<ContentBlock, { type: "text" }>
22
- >;
23
- }
24
-
25
- /** ensureTextBlocks + contentBlocksToText 的常见组合。 */
26
- textFromBlocks(blocks: ContentBlock[], field: string): string {
27
- return contentBlocksToText(this.ensureTextBlocks(blocks, field));
28
- }
29
-
30
- parseToolArguments(item: ToolCallItem): Record<string, unknown> {
31
- try {
32
- const parsed: unknown = JSON.parse(item.argumentsText);
33
- if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
34
- return parsed as Record<string, unknown>;
35
- }
36
- } catch {
37
- // handled below
38
- }
39
-
40
- throw new AIRequestError(
41
- `${this.kind} requires tool_call argumentsText to be a valid JSON object`,
42
- "TOOL_CALL_ARGUMENTS_INVALID",
43
- );
44
- }
45
-
46
- rollbackTrailingAssistantMessages<T extends { role: string }>(messages: T[]): void {
47
- while (messages.length > 0 && messages[messages.length - 1]?.role === "assistant") {
48
- messages.pop();
49
- }
50
- }
51
-
52
- mapToolsIfPresent<T>(tools: ToolDefinition[] | undefined, map: (tool: ToolDefinition) => T): T[] | undefined {
53
- if (!tools || tools.length === 0) return undefined;
54
- return tools.map(map);
55
- }
56
-
57
- /**
58
- * 将 canonical toolChoice 映射为 provider 形状。
59
- * 返回 undefined 表示调用方无需写入 body 字段。
60
- */
61
- mapToolChoice<T>(
62
- toolChoice: ToolChoice | undefined,
63
- mappers: {
64
- auto: T;
65
- none: T;
66
- tool: (name: string) => T;
67
- },
68
- ): T | undefined {
69
- if (!toolChoice) return undefined;
70
- if (toolChoice === "auto") return mappers.auto;
71
- if (toolChoice === "none") return mappers.none;
72
- if (toolChoice.type === "tool") return mappers.tool(toolChoice.name);
73
- return undefined;
74
- }
75
-
76
- private ensureBlocks(
77
- blocks: ContentBlock[],
78
- field: string,
79
- supportedTypes: ReadonlyArray<ContentBlock["type"]>,
80
- description: string,
81
- ): ContentBlock[] {
82
- for (let i = 0; i < blocks.length; i++) {
83
- const block = blocks[i];
84
- if (block && !supportedTypes.includes(block.type)) {
85
- throw new AIRequestError(
86
- `${this.kind} does not support ${field}[${i}] of type "${block.type}"; ${description}`,
87
- "UNSUPPORTED_CONTENT_BLOCK",
88
- );
89
- }
90
- }
91
-
92
- return blocks;
93
- }
94
- }
@@ -1,188 +0,0 @@
1
- /**
2
- * 模拟流式 (Synthetic Streaming)
3
- *
4
- * 将一组已解析的 canonical OutputItem 包装为规范事件流。
5
- * 适用于非原生流式后端:adapter 拿到完整响应后,调用此函数
6
- * 即可产出一致的事件序列,无需自己逐事件组装。
7
- *
8
- * 约束:
9
- * - 每个 item 只发一块完整 delta(不模拟逐 token)
10
- * - 保持 item 边界
11
- * - 保持后端原始顺序
12
- * - 不发明 reasoning
13
- * - 不改写工具参数
14
- */
15
-
16
- import { createEventFactory } from "../core/event-factory.js";
17
- import { replayFromOutput } from "./mapping.js";
18
-
19
- import type {
20
- OutputItem,
21
- ReplayItem,
22
- StopReason,
23
- Usage,
24
- BillingInfo,
25
- AIStreamEvent,
26
- MessageItem,
27
- ReasoningItem,
28
- ToolCallItem,
29
- OpaqueItem,
30
- } from "../types/index.js";
31
-
32
- // ── 输入参数 ──────────────────────────────────────────────────
33
-
34
- export type SyntheticStreamOptions = {
35
- model: string;
36
- responseId: string;
37
- backend: {
38
- kind: "chat-completions" | "messages" | "responses" | "mock";
39
- /** syntheticStream 强制设为 true */
40
- };
41
- output: OutputItem[];
42
- replay?: ReplayItem[];
43
- stopReason?: StopReason;
44
- usage?: Usage;
45
- billing?: BillingInfo;
46
- providerMetadata?: Record<string, unknown>;
47
- rawResponseId?: string;
48
- warnings?: string[];
49
- };
50
-
51
- // ── Synthetic Stream ──────────────────────────────────────────
52
-
53
- /**
54
- * 将已解析的 output items 包装为完整规范事件流。
55
- *
56
- * 用法示例(在 adapter 的 runStream 中):
57
- * ```ts
58
- * const result = parseNonStreamingResponse(data);
59
- * yield* syntheticStream({
60
- * model: request.model,
61
- * responseId: request.requestId,
62
- * backend: { kind: "chat-completions" },
63
- * output: result.output,
64
- * stopReason: result.stopReason,
65
- * usage: result.usage,
66
- * });
67
- * ```
68
- */
69
- export async function* syntheticStream(options: SyntheticStreamOptions): AsyncIterable<AIStreamEvent> {
70
- const {
71
- model,
72
- responseId,
73
- backend,
74
- output,
75
- replay,
76
- stopReason,
77
- usage,
78
- billing,
79
- providerMetadata,
80
- rawResponseId,
81
- warnings: extraWarnings,
82
- } = options;
83
-
84
- const factory = createEventFactory({
85
- responseId,
86
- backend: { kind: backend.kind, isSynthetic: true },
87
- });
88
-
89
- // 1. 响应开始
90
- yield factory.responseStarted(model);
91
-
92
- // 2. item 级事件 — 每个 item 只发一块完整 delta
93
- for (const item of output) {
94
- yield* emitItemEvents(item, factory);
95
- }
96
-
97
- // 3. auxiliary 事件(如有)
98
- if (usage || billing) {
99
- yield factory.responseAuxiliary({ usage, billing });
100
- }
101
-
102
- // 4. 构建最终 completion 并发射
103
- const finalReplay = replay ?? replayFromOutput(output);
104
-
105
- // 收集警告
106
- const allWarnings: string[] = [];
107
- allWarnings.push("Response is synthetically streamed; delta granularity may differ from native streaming");
108
- if (extraWarnings) allWarnings.push(...extraWarnings);
109
-
110
- yield factory.responseCompleted({
111
- replay: finalReplay,
112
- stopReason,
113
- usage,
114
- billing,
115
- auxiliary: providerMetadata ? { providerMetadata } : undefined,
116
- opaqueOutput: output.filter((item): item is OpaqueItem => item.type === "opaque"),
117
- warnings: allWarnings.length > 0 ? allWarnings : undefined,
118
- trace: {
119
- requestId: responseId,
120
- rawResponseId,
121
- adapter: backend.kind,
122
- isSyntheticStream: true,
123
- warnings: allWarnings.length > 0 ? allWarnings : undefined,
124
- },
125
- });
126
- }
127
-
128
- // ── Item 事件发射 ─────────────────────────────────────────────
129
-
130
- function* emitItemEvents(item: OutputItem, factory: ReturnType<typeof createEventFactory>): Generator<AIStreamEvent> {
131
- switch (item.type) {
132
- case "message":
133
- yield* emitMessageEvents(item, factory);
134
- break;
135
- case "reasoning":
136
- yield* emitReasoningEvents(item, factory);
137
- break;
138
- case "tool_call":
139
- yield* emitToolCallEvents(item, factory);
140
- break;
141
- case "opaque":
142
- // Opaque items in output have no streaming events
143
- break;
144
- }
145
- }
146
-
147
- function* emitMessageEvents(
148
- item: MessageItem,
149
- factory: ReturnType<typeof createEventFactory>,
150
- ): Generator<AIStreamEvent> {
151
- const id = item.id ?? `syn-msg-${crypto.randomUUID()}`;
152
- yield factory.messageStarted(id);
153
-
154
- for (const block of item.content) {
155
- yield factory.messageDelta(id, block);
156
- }
157
-
158
- yield factory.messageCompleted(id);
159
- }
160
-
161
- function* emitReasoningEvents(
162
- item: ReasoningItem,
163
- factory: ReturnType<typeof createEventFactory>,
164
- ): Generator<AIStreamEvent> {
165
- const id = item.id ?? `syn-reason-${crypto.randomUUID()}`;
166
- yield factory.reasoningStarted(id, item.visibility);
167
-
168
- for (const block of item.content) {
169
- yield factory.reasoningDelta(id, block);
170
- }
171
-
172
- yield factory.reasoningCompleted(id);
173
- }
174
-
175
- function* emitToolCallEvents(
176
- item: ToolCallItem,
177
- factory: ReturnType<typeof createEventFactory>,
178
- ): Generator<AIStreamEvent> {
179
- yield factory.toolCallStarted(item.id, item.name);
180
-
181
- if (item.argumentsText) {
182
- yield factory.toolCallDelta(item.id, { argumentsText: item.argumentsText });
183
- }
184
-
185
- yield factory.toolCallCompleted(item.id);
186
- }
187
-
188
- // ── Helper ────────────────────────────────────────────────────
@@ -1,110 +0,0 @@
1
- /**
2
- * Provider usage → canonical Usage 映射
3
- *
4
- * best-effort 提取 reasoning / cache 等扩展字段。
5
- */
6
-
7
- import type { Usage } from "../types/index.js";
8
-
9
- function num(value: unknown): number | undefined {
10
- return typeof value === "number" && Number.isFinite(value) ? value : undefined;
11
- }
12
-
13
- function record(obj: Record<string, number | undefined>): Partial<Usage> {
14
- const out: Partial<Usage> = {};
15
- for (const [key, value] of Object.entries(obj)) {
16
- if (value !== undefined) {
17
- (out as Record<string, number>)[key] = value;
18
- }
19
- }
20
- return out;
21
- }
22
-
23
- function withDerivedTotal(usage: {
24
- inputTokens?: number;
25
- outputTokens?: number;
26
- totalTokens?: number;
27
- cachedInputTokens?: number;
28
- reasoningTokens?: number;
29
- cacheWriteInputTokens?: number;
30
- }): Partial<Usage> {
31
- const { inputTokens, outputTokens, totalTokens, cachedInputTokens, reasoningTokens, cacheWriteInputTokens } = usage;
32
- return record({
33
- inputTokens,
34
- outputTokens,
35
- totalTokens:
36
- totalTokens ?? (inputTokens !== undefined && outputTokens !== undefined ? inputTokens + outputTokens : undefined),
37
- cachedInputTokens,
38
- reasoningTokens,
39
- cacheWriteInputTokens,
40
- });
41
- }
42
-
43
- /** OpenAI Chat Completions `usage` */
44
- export function usageFromChatCompletions(raw: {
45
- prompt_tokens?: number;
46
- completion_tokens?: number;
47
- total_tokens?: number;
48
- prompt_tokens_details?: { cached_tokens?: number; [key: string]: unknown };
49
- completion_tokens_details?: { reasoning_tokens?: number; [key: string]: unknown };
50
- }): Partial<Usage> {
51
- return withDerivedTotal({
52
- inputTokens: num(raw.prompt_tokens),
53
- outputTokens: num(raw.completion_tokens),
54
- totalTokens: num(raw.total_tokens),
55
- cachedInputTokens: num(raw.prompt_tokens_details?.cached_tokens),
56
- reasoningTokens: num(raw.completion_tokens_details?.reasoning_tokens),
57
- });
58
- }
59
-
60
- /** OpenAI Responses API `usage` */
61
- export function usageFromOpenAIResponses(raw: {
62
- input_tokens?: number;
63
- output_tokens?: number;
64
- total_tokens?: number;
65
- input_tokens_details?: { cached_tokens?: number; [key: string]: unknown };
66
- output_tokens_details?: { reasoning_tokens?: number; [key: string]: unknown };
67
- [key: string]: unknown;
68
- }): Partial<Usage> {
69
- return withDerivedTotal({
70
- inputTokens: num(raw.input_tokens),
71
- outputTokens: num(raw.output_tokens),
72
- totalTokens: num(raw.total_tokens),
73
- cachedInputTokens: num(raw.input_tokens_details?.cached_tokens),
74
- reasoningTokens: num(raw.output_tokens_details?.reasoning_tokens),
75
- });
76
- }
77
-
78
- /** Anthropic Messages `usage`(message_start / message_delta) */
79
- export function usageFromAnthropicMessages(raw: {
80
- input_tokens?: number;
81
- output_tokens?: number;
82
- cache_creation_input_tokens?: number;
83
- cache_read_input_tokens?: number;
84
- [key: string]: unknown;
85
- }): Partial<Usage> {
86
- const uncachedInputTokens = num(raw.input_tokens);
87
- const outputTokens = num(raw.output_tokens);
88
- const cacheWriteInputTokens = num(raw.cache_creation_input_tokens);
89
- const cachedInputTokens = num(raw.cache_read_input_tokens);
90
-
91
- const inputParts = [uncachedInputTokens, cacheWriteInputTokens, cachedInputTokens].filter(
92
- (n): n is number => n !== undefined,
93
- );
94
- const inputTokens = inputParts.length > 0 ? inputParts.reduce((sum, n) => sum + n, 0) : undefined;
95
-
96
- return withDerivedTotal({
97
- inputTokens,
98
- outputTokens,
99
- cachedInputTokens,
100
- cacheWriteInputTokens,
101
- });
102
- }
103
-
104
- /** Ollama 流式 chunk */
105
- export function usageFromOllama(raw: { prompt_eval_count?: number; eval_count?: number }): Partial<Usage> {
106
- return withDerivedTotal({
107
- inputTokens: num(raw.prompt_eval_count),
108
- outputTokens: num(raw.eval_count),
109
- });
110
- }
package/src/index.ts DELETED
@@ -1,17 +0,0 @@
1
- /**
2
- * @codehz/ai — 统一流式 AI 客户端
3
- *
4
- * 对外只暴露一个 canonical 主入口:client.stream()
5
- */
6
-
7
- // Re-export all canonical types
8
- export * from "./types/index.js";
9
-
10
- // Re-export core client API
11
- export * from "./core/index.js";
12
-
13
- // Re-export adapters
14
- export * from "./adapters/index.js";
15
-
16
- // Re-export helpers
17
- export * from "./helpers/index.js";
@@ -1,42 +0,0 @@
1
- /**
2
- * BackendAdapter — adapter 内部协议和 client 公开类型
3
- *
4
- * adapter 对前台只暴露一个统一适配点。
5
- */
6
-
7
- import type { AIRequest } from "./request.js";
8
- import type { AIStreamEvent } from "./events.js";
9
-
10
- // ── 公共工具类型 ──────────────────────────────────────────────
11
-
12
- /** HTTP fetch 函数签名,用于注入自定义请求实现(测试/代理) */
13
- export type FetchFn = (url: string, init: RequestInit) => Promise<Response>;
14
-
15
- // ── 归一化请求 ────────────────────────────────────────────────
16
-
17
- export type NormalizedRequest = AIRequest & {
18
- model: string;
19
- requestId: string;
20
- };
21
-
22
- // ── Adapter 接口 ──────────────────────────────────────────────
23
-
24
- export interface BackendAdapter {
25
- readonly kind: "chat-completions" | "messages" | "responses" | "ollama" | "mock";
26
- readonly isSyntheticStream: boolean;
27
- stream(request: NormalizedRequest): AsyncIterable<AIStreamEvent>;
28
- }
29
-
30
- // ── Client 公开类型 ───────────────────────────────────────────
31
-
32
- export type CreateAIClientOptions = {
33
- adapter: BackendAdapter;
34
- model: string;
35
- defaults?: Partial<AIRequest>;
36
- /** 全局默认 AbortSignal,当 request.signal 未设置时生效。 */
37
- signal?: AbortSignal;
38
- };
39
-
40
- export interface AIClient {
41
- stream(request: AIRequest): AsyncIterable<AIStreamEvent>;
42
- }
@@ -1,15 +0,0 @@
1
- /**
2
- * ContentBlock — 统一内容块类型
3
- *
4
- * 覆盖文本、JSON、图片、二进制引用和后端私有内容。
5
- */
6
-
7
- export type TextContentBlock = { type: "text"; text: string };
8
- export type JsonContentBlock = { type: "json"; json: unknown };
9
- export type InstructionBlock = TextContentBlock | JsonContentBlock;
10
-
11
- export type ContentBlock =
12
- | InstructionBlock
13
- | { type: "image"; imageUrl: string }
14
- | { type: "binary_ref"; ref: string }
15
- | { type: "opaque"; payload: unknown };
@@ -1,138 +0,0 @@
1
- /**
2
- * AIStreamEvent — 统一流事件模型
3
- *
4
- * 所有 adapter 都必须产出 AsyncIterable<AIStreamEvent>。
5
- * 无论后端是否支持原生流式,调用方看到的事件语义都一致:
6
- * 响应级开始 → item 级开始/增量/完成 → 响应级完成
7
- */
8
-
9
- import type { ContentBlock } from "./content.js";
10
- import type { Usage, BillingInfo, AuxiliaryInfo, BackendTrace, StopReason } from "./response.js";
11
- import type { OpaqueItem, ReplayItem } from "./items.js";
12
-
13
- // ── 事件基类 ──────────────────────────────────────────────────
14
-
15
- export type StreamEventBase = {
16
- type: string;
17
- responseId?: string;
18
- sequence: number;
19
- timestamp: string;
20
- backend: {
21
- kind: "chat-completions" | "messages" | "responses" | "ollama" | "mock";
22
- isSynthetic: boolean;
23
- };
24
- };
25
-
26
- // ── 响应级事件 ────────────────────────────────────────────────
27
-
28
- export type ResponseStartedEvent = StreamEventBase & {
29
- type: "response.started";
30
- model: string;
31
- };
32
-
33
- export type ResponseWarningEvent = StreamEventBase & {
34
- type: "response.warning";
35
- message: string;
36
- code?: string;
37
- };
38
-
39
- export type ResponseAuxiliaryEvent = StreamEventBase & {
40
- type: "response.auxiliary";
41
- usage?: Usage;
42
- billing?: BillingInfo;
43
- auxiliary?: Partial<AuxiliaryInfo>;
44
- };
45
-
46
- export type ResponseCompletedEvent = StreamEventBase & {
47
- type: "response.completed";
48
- replay: ReplayItem[];
49
- stopReason?: StopReason;
50
- usage?: Usage;
51
- billing?: BillingInfo;
52
- auxiliary?: AuxiliaryInfo;
53
- warnings?: string[];
54
- opaqueOutput?: OpaqueItem[];
55
- trace?: Partial<BackendTrace>;
56
- };
57
-
58
- // ── 消息流事件 ────────────────────────────────────────────────
59
-
60
- export type MessageStartedEvent = StreamEventBase & {
61
- type: "message.started";
62
- item: {
63
- id: string;
64
- role: "assistant";
65
- };
66
- };
67
-
68
- export type MessageDeltaEvent = StreamEventBase & {
69
- type: "message.delta";
70
- itemId: string;
71
- delta: ContentBlock;
72
- };
73
-
74
- export type MessageCompletedEvent = StreamEventBase & {
75
- type: "message.completed";
76
- itemId: string;
77
- };
78
-
79
- // ── 思维链流事件 ──────────────────────────────────────────────
80
-
81
- export type ReasoningStartedEvent = StreamEventBase & {
82
- type: "reasoning.started";
83
- item: {
84
- id: string;
85
- visibility: "full" | "summary" | "redacted" | "opaque";
86
- };
87
- };
88
-
89
- export type ReasoningDeltaEvent = StreamEventBase & {
90
- type: "reasoning.delta";
91
- itemId: string;
92
- delta: ContentBlock;
93
- };
94
-
95
- export type ReasoningCompletedEvent = StreamEventBase & {
96
- type: "reasoning.completed";
97
- itemId: string;
98
- };
99
-
100
- // ── 工具调用流事件 ────────────────────────────────────────────
101
-
102
- export type ToolCallStartedEvent = StreamEventBase & {
103
- type: "tool_call.started";
104
- item: {
105
- id: string;
106
- name: string;
107
- };
108
- };
109
-
110
- export type ToolCallDeltaEvent = StreamEventBase & {
111
- type: "tool_call.delta";
112
- itemId: string;
113
- delta: {
114
- argumentsText?: string;
115
- };
116
- };
117
-
118
- export type ToolCallCompletedEvent = StreamEventBase & {
119
- type: "tool_call.completed";
120
- itemId: string;
121
- };
122
-
123
- // ── 统一事件联合 ──────────────────────────────────────────────
124
-
125
- export type AIStreamEvent =
126
- | ResponseStartedEvent
127
- | ResponseWarningEvent
128
- | ResponseAuxiliaryEvent
129
- | MessageStartedEvent
130
- | MessageDeltaEvent
131
- | MessageCompletedEvent
132
- | ReasoningStartedEvent
133
- | ReasoningDeltaEvent
134
- | ReasoningCompletedEvent
135
- | ToolCallStartedEvent
136
- | ToolCallDeltaEvent
137
- | ToolCallCompletedEvent
138
- | ResponseCompletedEvent;
@@ -1,49 +0,0 @@
1
- /**
2
- * Canonical 类型系统
3
- *
4
- * 模块边界:统一请求、事件、响应模型的核心类型定义。
5
- * 所有公开类型最终从这里导出。
6
- */
7
-
8
- // 基础内容块
9
- export type { TextContentBlock, JsonContentBlock, InstructionBlock, ContentBlock } from "./content.js";
10
-
11
- // Item 类型体系
12
- export type {
13
- MessageItem,
14
- ReasoningItem,
15
- ToolCallItem,
16
- ToolResultItem,
17
- OpaqueItem,
18
- InputItem,
19
- OutputItem,
20
- ReplayItem,
21
- } from "./items.js";
22
-
23
- // 请求模型
24
- export type { AIRequest, ToolDefinition, ToolChoice, IncludeSettings, ReasoningLevel } from "./request.js";
25
-
26
- // 响应模型
27
- export type { AIResponse, StopReason, Usage, BillingInfo, AuxiliaryInfo, BackendTrace } from "./response.js";
28
-
29
- // 流事件模型
30
- export type {
31
- AIStreamEvent,
32
- StreamEventBase,
33
- ResponseStartedEvent,
34
- ResponseWarningEvent,
35
- ResponseAuxiliaryEvent,
36
- ResponseCompletedEvent,
37
- MessageStartedEvent,
38
- MessageDeltaEvent,
39
- MessageCompletedEvent,
40
- ReasoningStartedEvent,
41
- ReasoningDeltaEvent,
42
- ReasoningCompletedEvent,
43
- ToolCallStartedEvent,
44
- ToolCallDeltaEvent,
45
- ToolCallCompletedEvent,
46
- } from "./events.js";
47
-
48
- // Adapter 协议和 client 类型
49
- export type { BackendAdapter, FetchFn, NormalizedRequest, CreateAIClientOptions, AIClient } from "./adapter.js";