@acosmi/sdk-ts 2.19.0 → 2.19.2
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/CHANGELOG.md +16 -0
- package/README.md +2 -1
- package/dist/browser/index.mjs +1205 -160
- package/dist/browser/index.mjs.map +1 -1
- package/dist/index.mjs +1205 -160
- package/dist/index.mjs.map +1 -1
- package/dist/node/adapters/anthropic.cjs +2 -0
- package/dist/node/adapters/anthropic.cjs.map +1 -1
- package/dist/node/adapters/anthropic.d.cts +1 -1
- package/dist/node/adapters/anthropic.d.ts +1 -1
- package/dist/node/adapters/anthropic.mjs +2 -0
- package/dist/node/adapters/anthropic.mjs.map +1 -1
- package/dist/node/adapters/openai.cjs +122 -49
- package/dist/node/adapters/openai.cjs.map +1 -1
- package/dist/node/adapters/openai.d.cts +2 -2
- package/dist/node/adapters/openai.d.ts +2 -2
- package/dist/node/adapters/openai.mjs +122 -49
- package/dist/node/adapters/openai.mjs.map +1 -1
- package/dist/node/{index-C2oh157O.d.cts → index-CqxPqbsl.d.cts} +2 -1
- package/dist/node/{index-C2oh157O.d.ts → index-CqxPqbsl.d.ts} +2 -1
- package/dist/node/index.cjs +1206 -159
- package/dist/node/index.cjs.map +1 -1
- package/dist/node/index.d.cts +346 -151
- package/dist/node/index.d.ts +346 -151
- package/dist/node/index.mjs +1205 -160
- package/dist/node/index.mjs.map +1 -1
- package/dist/node/{openai-DR_KhEdM.d.cts → openai-Ce85qh14.d.cts} +30 -3
- package/dist/node/{openai-Cyvi8g6B.d.ts → openai-mkTSir6E.d.ts} +30 -3
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { P as ProviderAdapter, p as ProviderFormat, n as ModelCapabilities, e as ChatRequest, f as ChatResponse, y as StreamEvent } from './index-
|
|
1
|
+
import { P as ProviderAdapter, p as ProviderFormat, n as ModelCapabilities, e as ChatRequest, f as ChatResponse, y as StreamEvent } from './index-CqxPqbsl.cjs';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Anthropic 内容块
|
|
@@ -88,7 +88,7 @@ declare class OpenAIAdapter implements ProviderAdapter {
|
|
|
88
88
|
* 把 Anthropic 心智模型的 thinking/effort 翻译成 OpenAI `reasoning_effort` 字段值
|
|
89
89
|
* 返回空串表示不设置
|
|
90
90
|
*/
|
|
91
|
-
declare function resolveOpenAIReasoningEffort(req: ChatRequest): string;
|
|
91
|
+
declare function resolveOpenAIReasoningEffort(req: ChatRequest, supportsMax?: boolean): string;
|
|
92
92
|
/**
|
|
93
93
|
* 把 outputConfig 翻译成 OpenAI response_format
|
|
94
94
|
* 返回 null 表示不设置
|
|
@@ -111,9 +111,36 @@ declare class OpenAIStreamConverter {
|
|
|
111
111
|
* 可能已被 text/tool 推进的 this.blockIndex (否则 content_block_stop 索引错配)。 */
|
|
112
112
|
private thinkingBlockIndex;
|
|
113
113
|
private textStarted;
|
|
114
|
-
/** OpenAI tool_call
|
|
114
|
+
/** OpenAI tool_call 键 → Anthropic block index。键正常是 `tc.index`;上游省略
|
|
115
|
+
* index 时退化为 `id:<tool_call_id>`,两者都没有时沿用上一个键(见
|
|
116
|
+
* {@link resolveToolKey})。 */
|
|
115
117
|
private toolBlockIndex;
|
|
116
118
|
private blockIndex;
|
|
119
|
+
/** 每个 tool block 已发出的 `partial_json` 累积,用于识别「每片重发全量参数」
|
|
120
|
+
* 的上游(见 tool_calls 分支的累计判别)。 */
|
|
121
|
+
private toolArgsAccum;
|
|
122
|
+
/** 上一次解析出的 tool 键,供缺 index 且缺 id 的后续增量沿用。 */
|
|
123
|
+
private lastToolKey;
|
|
124
|
+
/** 已发出 message_delta/message_stop,避免 finish_reason 与 `[DONE]` 各收一次。 */
|
|
125
|
+
private messageClosed;
|
|
126
|
+
/**
|
|
127
|
+
* 解析一条 tool_call delta 归属的块键。
|
|
128
|
+
*
|
|
129
|
+
* OpenAI 流式规范里 `index` 是必填,但兼容实现常有省略。此前这里直接用
|
|
130
|
+
* `tc.index` 做 Map 键:两个都省略 index 的 tool_call 会共用键 `undefined`,
|
|
131
|
+
* 于是只开一个块、两段参数拼进同一条 `partial_json` 流,产出 `{…}{…}` 这种
|
|
132
|
+
* 必然非法的 JSON。这里按「index → id → 沿用上一个」三级降级,让至少一种
|
|
133
|
+
* 稳定标识生效。
|
|
134
|
+
*/
|
|
135
|
+
private resolveToolKey;
|
|
136
|
+
/**
|
|
137
|
+
* 关闭仍打开的 text / thinking / tool 块,并收口 message。
|
|
138
|
+
*
|
|
139
|
+
* 由 `finish_reason` 分支与 `[DONE]` 分支共用:上游断流或只发 `[DONE]` 而不发
|
|
140
|
+
* `finish_reason` 时,此前一个 `content_block_stop` 都不会发,下游拿到的是一个
|
|
141
|
+
* 永不闭合的 tool_use 块。
|
|
142
|
+
*/
|
|
143
|
+
private closeOpenBlocks;
|
|
117
144
|
/**
|
|
118
145
|
* 将一行 OpenAI SSE data 转换为零或多个 Anthropic 格式 StreamEvent
|
|
119
146
|
* 返回 { events, done }
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { P as ProviderAdapter, p as ProviderFormat, n as ModelCapabilities, e as ChatRequest, f as ChatResponse, y as StreamEvent } from './index-
|
|
1
|
+
import { P as ProviderAdapter, p as ProviderFormat, n as ModelCapabilities, e as ChatRequest, f as ChatResponse, y as StreamEvent } from './index-CqxPqbsl.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Anthropic 内容块
|
|
@@ -88,7 +88,7 @@ declare class OpenAIAdapter implements ProviderAdapter {
|
|
|
88
88
|
* 把 Anthropic 心智模型的 thinking/effort 翻译成 OpenAI `reasoning_effort` 字段值
|
|
89
89
|
* 返回空串表示不设置
|
|
90
90
|
*/
|
|
91
|
-
declare function resolveOpenAIReasoningEffort(req: ChatRequest): string;
|
|
91
|
+
declare function resolveOpenAIReasoningEffort(req: ChatRequest, supportsMax?: boolean): string;
|
|
92
92
|
/**
|
|
93
93
|
* 把 outputConfig 翻译成 OpenAI response_format
|
|
94
94
|
* 返回 null 表示不设置
|
|
@@ -111,9 +111,36 @@ declare class OpenAIStreamConverter {
|
|
|
111
111
|
* 可能已被 text/tool 推进的 this.blockIndex (否则 content_block_stop 索引错配)。 */
|
|
112
112
|
private thinkingBlockIndex;
|
|
113
113
|
private textStarted;
|
|
114
|
-
/** OpenAI tool_call
|
|
114
|
+
/** OpenAI tool_call 键 → Anthropic block index。键正常是 `tc.index`;上游省略
|
|
115
|
+
* index 时退化为 `id:<tool_call_id>`,两者都没有时沿用上一个键(见
|
|
116
|
+
* {@link resolveToolKey})。 */
|
|
115
117
|
private toolBlockIndex;
|
|
116
118
|
private blockIndex;
|
|
119
|
+
/** 每个 tool block 已发出的 `partial_json` 累积,用于识别「每片重发全量参数」
|
|
120
|
+
* 的上游(见 tool_calls 分支的累计判别)。 */
|
|
121
|
+
private toolArgsAccum;
|
|
122
|
+
/** 上一次解析出的 tool 键,供缺 index 且缺 id 的后续增量沿用。 */
|
|
123
|
+
private lastToolKey;
|
|
124
|
+
/** 已发出 message_delta/message_stop,避免 finish_reason 与 `[DONE]` 各收一次。 */
|
|
125
|
+
private messageClosed;
|
|
126
|
+
/**
|
|
127
|
+
* 解析一条 tool_call delta 归属的块键。
|
|
128
|
+
*
|
|
129
|
+
* OpenAI 流式规范里 `index` 是必填,但兼容实现常有省略。此前这里直接用
|
|
130
|
+
* `tc.index` 做 Map 键:两个都省略 index 的 tool_call 会共用键 `undefined`,
|
|
131
|
+
* 于是只开一个块、两段参数拼进同一条 `partial_json` 流,产出 `{…}{…}` 这种
|
|
132
|
+
* 必然非法的 JSON。这里按「index → id → 沿用上一个」三级降级,让至少一种
|
|
133
|
+
* 稳定标识生效。
|
|
134
|
+
*/
|
|
135
|
+
private resolveToolKey;
|
|
136
|
+
/**
|
|
137
|
+
* 关闭仍打开的 text / thinking / tool 块,并收口 message。
|
|
138
|
+
*
|
|
139
|
+
* 由 `finish_reason` 分支与 `[DONE]` 分支共用:上游断流或只发 `[DONE]` 而不发
|
|
140
|
+
* `finish_reason` 时,此前一个 `content_block_stop` 都不会发,下游拿到的是一个
|
|
141
|
+
* 永不闭合的 tool_use 块。
|
|
142
|
+
*/
|
|
143
|
+
private closeOpenBlocks;
|
|
117
144
|
/**
|
|
118
145
|
* 将一行 OpenAI SSE data 转换为零或多个 Anthropic 格式 StreamEvent
|
|
119
146
|
* 返回 { events, done }
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@acosmi/sdk-ts",
|
|
3
|
-
"version": "2.19.
|
|
3
|
+
"version": "2.19.2",
|
|
4
4
|
"description": "Acosmi TypeScript SDK:模型网关、Agent Run Gateway 与 Compliance(电子证据、时间章、报告、签署 envelope)统一客户端,支持浏览器 / Node ≥18 / Deno / Bun。",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/node/index.cjs",
|