@kenkaiiii/gg-ai 4.2.2 → 4.2.4
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/dist/index.cjs +1093 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +235 -0
- package/dist/index.d.ts +235 -5
- package/dist/index.js +1051 -5
- package/dist/index.js.map +1 -1
- package/package.json +7 -3
- package/dist/errors.d.ts +0 -12
- package/dist/errors.d.ts.map +0 -1
- package/dist/errors.js +0 -17
- package/dist/errors.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/providers/anthropic.d.ts +0 -4
- package/dist/providers/anthropic.d.ts.map +0 -1
- package/dist/providers/anthropic.js +0 -207
- package/dist/providers/anthropic.js.map +0 -1
- package/dist/providers/openai-codex.d.ts +0 -4
- package/dist/providers/openai-codex.d.ts.map +0 -1
- package/dist/providers/openai-codex.js +0 -338
- package/dist/providers/openai-codex.js.map +0 -1
- package/dist/providers/openai.d.ts +0 -4
- package/dist/providers/openai.d.ts.map +0 -1
- package/dist/providers/openai.js +0 -182
- package/dist/providers/openai.js.map +0 -1
- package/dist/providers/transform.d.ts +0 -30
- package/dist/providers/transform.d.ts.map +0 -1
- package/dist/providers/transform.js +0 -323
- package/dist/providers/transform.js.map +0 -1
- package/dist/stream.d.ts +0 -19
- package/dist/stream.d.ts.map +0 -1
- package/dist/stream.js +0 -44
- package/dist/stream.js.map +0 -1
- package/dist/types.d.ts +0 -167
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -2
- package/dist/types.js.map +0 -1
- package/dist/utils/event-stream.d.ts +0 -38
- package/dist/utils/event-stream.d.ts.map +0 -1
- package/dist/utils/event-stream.js +0 -100
- package/dist/utils/event-stream.js.map +0 -1
- package/dist/utils/zod-to-json-schema.d.ts +0 -7
- package/dist/utils/zod-to-json-schema.d.ts.map +0 -1
- package/dist/utils/zod-to-json-schema.js +0 -12
- package/dist/utils/zod-to-json-schema.js.map +0 -1
|
@@ -1,323 +0,0 @@
|
|
|
1
|
-
import { zodToJsonSchema } from "../utils/zod-to-json-schema.js";
|
|
2
|
-
// ── Anthropic Transforms ───────────────────────────────────
|
|
3
|
-
export function toAnthropicCacheControl(retention, baseUrl) {
|
|
4
|
-
const resolved = retention ?? "short";
|
|
5
|
-
if (resolved === "none")
|
|
6
|
-
return undefined;
|
|
7
|
-
const ttl = resolved === "long" && (!baseUrl || baseUrl.includes("api.anthropic.com")) ? "1h" : undefined;
|
|
8
|
-
return { type: "ephemeral", ...(ttl && { ttl }) };
|
|
9
|
-
}
|
|
10
|
-
export function toAnthropicMessages(messages, cacheControl) {
|
|
11
|
-
let systemText;
|
|
12
|
-
const out = [];
|
|
13
|
-
for (const msg of messages) {
|
|
14
|
-
if (msg.role === "system") {
|
|
15
|
-
systemText = msg.content;
|
|
16
|
-
continue;
|
|
17
|
-
}
|
|
18
|
-
if (msg.role === "user") {
|
|
19
|
-
out.push({
|
|
20
|
-
role: "user",
|
|
21
|
-
content: typeof msg.content === "string"
|
|
22
|
-
? msg.content
|
|
23
|
-
: msg.content.map((part) => {
|
|
24
|
-
if (part.type === "text")
|
|
25
|
-
return { type: "text", text: part.text };
|
|
26
|
-
return {
|
|
27
|
-
type: "image",
|
|
28
|
-
source: {
|
|
29
|
-
type: "base64",
|
|
30
|
-
media_type: part.mediaType,
|
|
31
|
-
data: part.data,
|
|
32
|
-
},
|
|
33
|
-
};
|
|
34
|
-
}),
|
|
35
|
-
});
|
|
36
|
-
continue;
|
|
37
|
-
}
|
|
38
|
-
if (msg.role === "assistant") {
|
|
39
|
-
const content = typeof msg.content === "string"
|
|
40
|
-
? msg.content
|
|
41
|
-
: msg.content
|
|
42
|
-
.filter((part) => {
|
|
43
|
-
// Strip thinking blocks without a valid signature (e.g. from GLM/OpenAI)
|
|
44
|
-
// — Anthropic rejects empty signatures
|
|
45
|
-
if (part.type === "thinking" && !part.signature)
|
|
46
|
-
return false;
|
|
47
|
-
return true;
|
|
48
|
-
})
|
|
49
|
-
.map((part) => {
|
|
50
|
-
if (part.type === "text")
|
|
51
|
-
return { type: "text", text: part.text };
|
|
52
|
-
if (part.type === "thinking")
|
|
53
|
-
return { type: "thinking", thinking: part.text, signature: part.signature };
|
|
54
|
-
if (part.type === "tool_call")
|
|
55
|
-
return {
|
|
56
|
-
type: "tool_use",
|
|
57
|
-
id: part.id,
|
|
58
|
-
name: part.name,
|
|
59
|
-
input: part.args,
|
|
60
|
-
};
|
|
61
|
-
if (part.type === "server_tool_call")
|
|
62
|
-
return {
|
|
63
|
-
type: "server_tool_use",
|
|
64
|
-
id: part.id,
|
|
65
|
-
name: part.name,
|
|
66
|
-
input: part.input,
|
|
67
|
-
};
|
|
68
|
-
if (part.type === "server_tool_result")
|
|
69
|
-
return part.data;
|
|
70
|
-
if (part.type === "raw")
|
|
71
|
-
return part.data;
|
|
72
|
-
// image content shouldn't appear in assistant messages
|
|
73
|
-
return { type: "text", text: "" };
|
|
74
|
-
});
|
|
75
|
-
out.push({ role: "assistant", content });
|
|
76
|
-
continue;
|
|
77
|
-
}
|
|
78
|
-
if (msg.role === "tool") {
|
|
79
|
-
out.push({
|
|
80
|
-
role: "user",
|
|
81
|
-
content: msg.content.map((result) => ({
|
|
82
|
-
type: "tool_result",
|
|
83
|
-
tool_use_id: result.toolCallId,
|
|
84
|
-
content: result.content,
|
|
85
|
-
is_error: result.isError,
|
|
86
|
-
})),
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
// Add cache_control to the last user message to cache conversation history
|
|
91
|
-
if (cacheControl && out.length > 0) {
|
|
92
|
-
for (let i = out.length - 1; i >= 0; i--) {
|
|
93
|
-
if (out[i].role === "user") {
|
|
94
|
-
const content = out[i].content;
|
|
95
|
-
if (typeof content === "string") {
|
|
96
|
-
out[i] = {
|
|
97
|
-
role: "user",
|
|
98
|
-
content: [
|
|
99
|
-
{
|
|
100
|
-
type: "text",
|
|
101
|
-
text: content,
|
|
102
|
-
cache_control: cacheControl,
|
|
103
|
-
},
|
|
104
|
-
],
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
else if (Array.isArray(content) && content.length > 0) {
|
|
108
|
-
const last = content[content.length - 1];
|
|
109
|
-
content[content.length - 1] = {
|
|
110
|
-
...last,
|
|
111
|
-
cache_control: cacheControl,
|
|
112
|
-
};
|
|
113
|
-
}
|
|
114
|
-
break;
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
// Build system as block array (supports cache_control).
|
|
119
|
-
// Split on "<!-- uncached -->" marker: text before is cached, text after is not.
|
|
120
|
-
let system;
|
|
121
|
-
if (systemText) {
|
|
122
|
-
const marker = "<!-- uncached -->";
|
|
123
|
-
const markerIdx = systemText.indexOf(marker);
|
|
124
|
-
if (markerIdx !== -1 && cacheControl) {
|
|
125
|
-
const cachedPart = systemText.slice(0, markerIdx).trimEnd();
|
|
126
|
-
const uncachedPart = systemText.slice(markerIdx + marker.length).trimStart();
|
|
127
|
-
system = [
|
|
128
|
-
{ type: "text", text: cachedPart, cache_control: cacheControl },
|
|
129
|
-
...(uncachedPart ? [{ type: "text", text: uncachedPart }] : []),
|
|
130
|
-
];
|
|
131
|
-
}
|
|
132
|
-
else {
|
|
133
|
-
system = [
|
|
134
|
-
{
|
|
135
|
-
type: "text",
|
|
136
|
-
text: systemText,
|
|
137
|
-
...(cacheControl && { cache_control: cacheControl }),
|
|
138
|
-
},
|
|
139
|
-
];
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
return { system, messages: out };
|
|
143
|
-
}
|
|
144
|
-
export function toAnthropicTools(tools) {
|
|
145
|
-
return tools.map((tool) => ({
|
|
146
|
-
name: tool.name,
|
|
147
|
-
description: tool.description,
|
|
148
|
-
input_schema: (tool.rawInputSchema ??
|
|
149
|
-
zodToJsonSchema(tool.parameters)),
|
|
150
|
-
}));
|
|
151
|
-
}
|
|
152
|
-
export function toAnthropicToolChoice(choice) {
|
|
153
|
-
if (choice === "auto")
|
|
154
|
-
return { type: "auto" };
|
|
155
|
-
if (choice === "none")
|
|
156
|
-
return { type: "none" };
|
|
157
|
-
if (choice === "required")
|
|
158
|
-
return { type: "any" };
|
|
159
|
-
return { type: "tool", name: choice.name };
|
|
160
|
-
}
|
|
161
|
-
function supportsAdaptiveThinking(model) {
|
|
162
|
-
return /opus-4-6|sonnet-4-6/.test(model);
|
|
163
|
-
}
|
|
164
|
-
export function toAnthropicThinking(level, maxTokens, model) {
|
|
165
|
-
if (supportsAdaptiveThinking(model)) {
|
|
166
|
-
// Adaptive thinking — model decides when/how much to think.
|
|
167
|
-
// budget_tokens is deprecated on Opus 4.6 / Sonnet 4.6.
|
|
168
|
-
// "max" effort is Opus-only; downgrade to "high" for Sonnet
|
|
169
|
-
let effort = level;
|
|
170
|
-
if (level === "max" && !model.includes("opus")) {
|
|
171
|
-
effort = "high";
|
|
172
|
-
}
|
|
173
|
-
return {
|
|
174
|
-
thinking: { type: "adaptive" },
|
|
175
|
-
maxTokens,
|
|
176
|
-
outputConfig: { effort },
|
|
177
|
-
};
|
|
178
|
-
}
|
|
179
|
-
// Legacy budget-based thinking for older models ("max" treated as "high")
|
|
180
|
-
const effectiveLevel = level === "max" ? "high" : level;
|
|
181
|
-
const budgetMap = {
|
|
182
|
-
low: Math.max(1024, Math.floor(maxTokens * 0.25)),
|
|
183
|
-
medium: Math.max(2048, Math.floor(maxTokens * 0.5)),
|
|
184
|
-
high: Math.max(4096, maxTokens),
|
|
185
|
-
};
|
|
186
|
-
const budget = budgetMap[effectiveLevel];
|
|
187
|
-
return {
|
|
188
|
-
thinking: { type: "enabled", budget_tokens: budget },
|
|
189
|
-
maxTokens: maxTokens + budget,
|
|
190
|
-
};
|
|
191
|
-
}
|
|
192
|
-
// ── OpenAI Transforms ──────────────────────────────────────
|
|
193
|
-
export function toOpenAIMessages(messages) {
|
|
194
|
-
const out = [];
|
|
195
|
-
for (const msg of messages) {
|
|
196
|
-
if (msg.role === "system") {
|
|
197
|
-
out.push({ role: "system", content: msg.content });
|
|
198
|
-
continue;
|
|
199
|
-
}
|
|
200
|
-
if (msg.role === "user") {
|
|
201
|
-
if (typeof msg.content === "string") {
|
|
202
|
-
out.push({ role: "user", content: msg.content });
|
|
203
|
-
}
|
|
204
|
-
else {
|
|
205
|
-
out.push({
|
|
206
|
-
role: "user",
|
|
207
|
-
content: msg.content.map((part) => {
|
|
208
|
-
if (part.type === "text")
|
|
209
|
-
return { type: "text", text: part.text };
|
|
210
|
-
return {
|
|
211
|
-
type: "image_url",
|
|
212
|
-
image_url: {
|
|
213
|
-
url: `data:${part.mediaType};base64,${part.data}`,
|
|
214
|
-
},
|
|
215
|
-
};
|
|
216
|
-
}),
|
|
217
|
-
});
|
|
218
|
-
}
|
|
219
|
-
continue;
|
|
220
|
-
}
|
|
221
|
-
if (msg.role === "assistant") {
|
|
222
|
-
const parts = typeof msg.content === "string" ? msg.content : undefined;
|
|
223
|
-
const toolCalls = typeof msg.content !== "string"
|
|
224
|
-
? msg.content
|
|
225
|
-
.filter((p) => p.type === "tool_call")
|
|
226
|
-
.map((tc) => ({
|
|
227
|
-
id: tc.id,
|
|
228
|
-
type: "function",
|
|
229
|
-
function: { name: tc.name, arguments: JSON.stringify(tc.args) },
|
|
230
|
-
}))
|
|
231
|
-
: undefined;
|
|
232
|
-
const textParts = typeof msg.content !== "string"
|
|
233
|
-
? msg.content
|
|
234
|
-
.filter((p) => p.type === "text")
|
|
235
|
-
.map((p) => p.text)
|
|
236
|
-
.join("")
|
|
237
|
-
: undefined;
|
|
238
|
-
// Roundtrip thinking content as reasoning_content (GLM, Moonshot)
|
|
239
|
-
const thinkingParts = typeof msg.content !== "string"
|
|
240
|
-
? msg.content
|
|
241
|
-
.filter((p) => p.type === "thinking")
|
|
242
|
-
.map((p) => p.text)
|
|
243
|
-
.join("")
|
|
244
|
-
: undefined;
|
|
245
|
-
const assistantMsg = {
|
|
246
|
-
role: "assistant",
|
|
247
|
-
content: parts ?? textParts ?? null,
|
|
248
|
-
...(toolCalls?.length ? { tool_calls: toolCalls } : {}),
|
|
249
|
-
};
|
|
250
|
-
// Attach reasoning_content for multi-turn coherence (non-standard field).
|
|
251
|
-
// Moonshot requires reasoning_content on ALL assistant messages with tool_calls
|
|
252
|
-
// when thinking is enabled — even if empty.
|
|
253
|
-
if (thinkingParts || toolCalls?.length) {
|
|
254
|
-
assistantMsg.reasoning_content =
|
|
255
|
-
thinkingParts || " ";
|
|
256
|
-
}
|
|
257
|
-
out.push(assistantMsg);
|
|
258
|
-
continue;
|
|
259
|
-
}
|
|
260
|
-
if (msg.role === "tool") {
|
|
261
|
-
for (const result of msg.content) {
|
|
262
|
-
out.push({
|
|
263
|
-
role: "tool",
|
|
264
|
-
tool_call_id: result.toolCallId,
|
|
265
|
-
content: result.content,
|
|
266
|
-
});
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
return out;
|
|
271
|
-
}
|
|
272
|
-
export function toOpenAITools(tools) {
|
|
273
|
-
return tools.map((tool) => ({
|
|
274
|
-
type: "function",
|
|
275
|
-
function: {
|
|
276
|
-
name: tool.name,
|
|
277
|
-
description: tool.description,
|
|
278
|
-
parameters: tool.rawInputSchema ?? zodToJsonSchema(tool.parameters),
|
|
279
|
-
},
|
|
280
|
-
}));
|
|
281
|
-
}
|
|
282
|
-
export function toOpenAIToolChoice(choice) {
|
|
283
|
-
if (choice === "auto")
|
|
284
|
-
return "auto";
|
|
285
|
-
if (choice === "none")
|
|
286
|
-
return "none";
|
|
287
|
-
if (choice === "required")
|
|
288
|
-
return "required";
|
|
289
|
-
return { type: "function", function: { name: choice.name } };
|
|
290
|
-
}
|
|
291
|
-
export function toOpenAIReasoningEffort(level) {
|
|
292
|
-
return level === "max" ? "high" : level;
|
|
293
|
-
}
|
|
294
|
-
// ── Response Normalization ─────────────────────────────────
|
|
295
|
-
export function normalizeAnthropicStopReason(reason) {
|
|
296
|
-
switch (reason) {
|
|
297
|
-
case "tool_use":
|
|
298
|
-
return "tool_use";
|
|
299
|
-
case "max_tokens":
|
|
300
|
-
return "max_tokens";
|
|
301
|
-
case "pause_turn":
|
|
302
|
-
return "pause_turn";
|
|
303
|
-
case "stop_sequence":
|
|
304
|
-
return "stop_sequence";
|
|
305
|
-
case "refusal":
|
|
306
|
-
return "refusal";
|
|
307
|
-
default:
|
|
308
|
-
return "end_turn";
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
export function normalizeOpenAIStopReason(reason) {
|
|
312
|
-
switch (reason) {
|
|
313
|
-
case "tool_calls":
|
|
314
|
-
return "tool_use";
|
|
315
|
-
case "length":
|
|
316
|
-
return "max_tokens";
|
|
317
|
-
case "stop":
|
|
318
|
-
return "stop_sequence";
|
|
319
|
-
default:
|
|
320
|
-
return "end_turn";
|
|
321
|
-
}
|
|
322
|
-
}
|
|
323
|
-
//# sourceMappingURL=transform.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"transform.js","sourceRoot":"","sources":["../../src/providers/transform.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AAEjE,8DAA8D;AAE9D,MAAM,UAAU,uBAAuB,CACrC,SAAqC,EACrC,OAA2B;IAE3B,MAAM,QAAQ,GAAG,SAAS,IAAI,OAAO,CAAC;IACtC,IAAI,QAAQ,KAAK,MAAM;QAAE,OAAO,SAAS,CAAC;IAC1C,MAAM,GAAG,GACP,QAAQ,KAAK,MAAM,IAAI,CAAC,CAAC,OAAO,IAAI,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC;IAChG,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,GAAG,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,CAAC,EAAuC,CAAC;AACzF,CAAC;AAED,MAAM,UAAU,mBAAmB,CACjC,QAAmB,EACnB,YAAgD;IAKhD,IAAI,UAA8B,CAA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AK,MAAM;YACT,OAAO,eAAe,CAAC;QACzB;YACE,OAAO,UAAU,CAAC;IACtB,CAAC;AACH,CAAC"}
|
package/dist/stream.d.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import type { StreamOptions } from "./types.js";
|
|
2
|
-
import type { StreamResult } from "./utils/event-stream.js";
|
|
3
|
-
/**
|
|
4
|
-
* Unified streaming entry point. Returns a StreamResult that is both
|
|
5
|
-
* an async iterable (for streaming events) and thenable (await for
|
|
6
|
-
* the final response).
|
|
7
|
-
*
|
|
8
|
-
* ```ts
|
|
9
|
-
* // Stream events
|
|
10
|
-
* for await (const event of stream({ provider: "anthropic", model: "claude-sonnet-4-6", messages })) {
|
|
11
|
-
* if (event.type === "text_delta") process.stdout.write(event.text);
|
|
12
|
-
* }
|
|
13
|
-
*
|
|
14
|
-
* // Or just await the final message
|
|
15
|
-
* const response = await stream({ provider: "openai", model: "gpt-4.1", messages });
|
|
16
|
-
* ```
|
|
17
|
-
*/
|
|
18
|
-
export declare function stream(options: StreamOptions): StreamResult;
|
|
19
|
-
//# sourceMappingURL=stream.d.ts.map
|
package/dist/stream.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../src/stream.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEhD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAK5D;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,MAAM,CAAC,OAAO,EAAE,aAAa,GAAG,YAAY,CAyB3D"}
|
package/dist/stream.js
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { GGAIError } from "./errors.js";
|
|
2
|
-
import { streamAnthropic } from "./providers/anthropic.js";
|
|
3
|
-
import { streamOpenAI } from "./providers/openai.js";
|
|
4
|
-
import { streamOpenAICodex } from "./providers/openai-codex.js";
|
|
5
|
-
/**
|
|
6
|
-
* Unified streaming entry point. Returns a StreamResult that is both
|
|
7
|
-
* an async iterable (for streaming events) and thenable (await for
|
|
8
|
-
* the final response).
|
|
9
|
-
*
|
|
10
|
-
* ```ts
|
|
11
|
-
* // Stream events
|
|
12
|
-
* for await (const event of stream({ provider: "anthropic", model: "claude-sonnet-4-6", messages })) {
|
|
13
|
-
* if (event.type === "text_delta") process.stdout.write(event.text);
|
|
14
|
-
* }
|
|
15
|
-
*
|
|
16
|
-
* // Or just await the final message
|
|
17
|
-
* const response = await stream({ provider: "openai", model: "gpt-4.1", messages });
|
|
18
|
-
* ```
|
|
19
|
-
*/
|
|
20
|
-
export function stream(options) {
|
|
21
|
-
switch (options.provider) {
|
|
22
|
-
case "anthropic":
|
|
23
|
-
return streamAnthropic(options);
|
|
24
|
-
case "openai":
|
|
25
|
-
// Use codex endpoint for OAuth tokens (have accountId)
|
|
26
|
-
if (options.accountId) {
|
|
27
|
-
return streamOpenAICodex(options);
|
|
28
|
-
}
|
|
29
|
-
return streamOpenAI(options);
|
|
30
|
-
case "glm":
|
|
31
|
-
return streamOpenAI({
|
|
32
|
-
...options,
|
|
33
|
-
baseUrl: options.baseUrl ?? "https://api.z.ai/api/paas/v4",
|
|
34
|
-
});
|
|
35
|
-
case "moonshot":
|
|
36
|
-
return streamOpenAI({
|
|
37
|
-
...options,
|
|
38
|
-
baseUrl: options.baseUrl ?? "https://api.moonshot.ai/v1",
|
|
39
|
-
});
|
|
40
|
-
default:
|
|
41
|
-
throw new GGAIError(`Unknown provider: ${options.provider}. Supported: "anthropic", "openai", "glm", "moonshot"`);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
//# sourceMappingURL=stream.js.map
|
package/dist/stream.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"stream.js","sourceRoot":"","sources":["../src/stream.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAEhE;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,MAAM,CAAC,OAAsB;IAC3C,QAAQ,OAAO,CAAC,QAAQ,EAAE,CAAC;QACzB,KAAK,WAAW;YACd,OAAO,eAAe,CAAC,OAAO,CAAC,CAAC;QAClC,KAAK,QAAQ;YACX,uDAAuD;YACvD,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;gBACtB,OAAO,iBAAiB,CAAC,OAAO,CAAC,CAAC;YACpC,CAAC;YACD,OAAO,YAAY,CAAC,OAAO,CAAC,CAAC;QAC/B,KAAK,KAAK;YACR,OAAO,YAAY,CAAC;gBAClB,GAAG,OAAO;gBACV,OAAO,EAAE,OAAO,CAAC,OAAO,IAAI,8BAA8B;aAC3D,CAAC,CAAC;QACL,KAAK,UAAU;YACb,OAAO,YAAY,CAAC;gBAClB,GAAG,OAAO;gBACV,OAAO,EAAE,OAAO,CAAC,OAAO,IAAI,4BAA4B;aACzD,CAAC,CAAC;QACL;YACE,MAAM,IAAI,SAAS,CACjB,qBAAqB,OAAO,CAAC,QAAkB,uDAAuD,CACvG,CAAC;IACN,CAAC;AACH,CAAC"}
|
package/dist/types.d.ts
DELETED
|
@@ -1,167 +0,0 @@
|
|
|
1
|
-
import type { z } from "zod";
|
|
2
|
-
export type Provider = "anthropic" | "openai" | "glm" | "moonshot";
|
|
3
|
-
export type ThinkingLevel = "low" | "medium" | "high" | "max";
|
|
4
|
-
export type CacheRetention = "none" | "short" | "long";
|
|
5
|
-
export interface TextContent {
|
|
6
|
-
type: "text";
|
|
7
|
-
text: string;
|
|
8
|
-
}
|
|
9
|
-
export interface ThinkingContent {
|
|
10
|
-
type: "thinking";
|
|
11
|
-
text: string;
|
|
12
|
-
signature?: string;
|
|
13
|
-
}
|
|
14
|
-
export interface ImageContent {
|
|
15
|
-
type: "image";
|
|
16
|
-
mediaType: string;
|
|
17
|
-
data: string;
|
|
18
|
-
}
|
|
19
|
-
export interface ToolCall {
|
|
20
|
-
type: "tool_call";
|
|
21
|
-
id: string;
|
|
22
|
-
name: string;
|
|
23
|
-
args: Record<string, unknown>;
|
|
24
|
-
}
|
|
25
|
-
export interface ToolResult {
|
|
26
|
-
type: "tool_result";
|
|
27
|
-
toolCallId: string;
|
|
28
|
-
content: string;
|
|
29
|
-
isError?: boolean;
|
|
30
|
-
}
|
|
31
|
-
export interface ServerToolCall {
|
|
32
|
-
type: "server_tool_call";
|
|
33
|
-
id: string;
|
|
34
|
-
name: string;
|
|
35
|
-
input: unknown;
|
|
36
|
-
}
|
|
37
|
-
export interface ServerToolResult {
|
|
38
|
-
type: "server_tool_result";
|
|
39
|
-
toolUseId: string;
|
|
40
|
-
resultType: string;
|
|
41
|
-
data: unknown;
|
|
42
|
-
}
|
|
43
|
-
/** Opaque content block preserved for round-tripping (e.g. compaction blocks). */
|
|
44
|
-
export interface RawContent {
|
|
45
|
-
type: "raw";
|
|
46
|
-
data: Record<string, unknown>;
|
|
47
|
-
}
|
|
48
|
-
export type ContentPart = TextContent | ThinkingContent | ImageContent | ToolCall | ServerToolCall | ServerToolResult | RawContent;
|
|
49
|
-
export interface SystemMessage {
|
|
50
|
-
role: "system";
|
|
51
|
-
content: string;
|
|
52
|
-
}
|
|
53
|
-
export interface UserMessage {
|
|
54
|
-
role: "user";
|
|
55
|
-
content: string | (TextContent | ImageContent)[];
|
|
56
|
-
}
|
|
57
|
-
export interface AssistantMessage {
|
|
58
|
-
role: "assistant";
|
|
59
|
-
content: string | ContentPart[];
|
|
60
|
-
}
|
|
61
|
-
export interface ToolResultMessage {
|
|
62
|
-
role: "tool";
|
|
63
|
-
content: ToolResult[];
|
|
64
|
-
}
|
|
65
|
-
export type Message = SystemMessage | UserMessage | AssistantMessage | ToolResultMessage;
|
|
66
|
-
export interface Tool {
|
|
67
|
-
name: string;
|
|
68
|
-
description: string;
|
|
69
|
-
parameters: z.ZodType;
|
|
70
|
-
/** Raw JSON Schema — bypasses zodToJsonSchema when set (used by MCP tools) */
|
|
71
|
-
rawInputSchema?: Record<string, unknown>;
|
|
72
|
-
}
|
|
73
|
-
export type ToolChoice = "auto" | "none" | "required" | {
|
|
74
|
-
name: string;
|
|
75
|
-
};
|
|
76
|
-
export interface ServerToolDefinition {
|
|
77
|
-
type: string;
|
|
78
|
-
name: string;
|
|
79
|
-
[key: string]: unknown;
|
|
80
|
-
}
|
|
81
|
-
export interface TextDeltaEvent {
|
|
82
|
-
type: "text_delta";
|
|
83
|
-
text: string;
|
|
84
|
-
}
|
|
85
|
-
export interface ThinkingDeltaEvent {
|
|
86
|
-
type: "thinking_delta";
|
|
87
|
-
text: string;
|
|
88
|
-
}
|
|
89
|
-
export interface ToolCallDeltaEvent {
|
|
90
|
-
type: "toolcall_delta";
|
|
91
|
-
id: string;
|
|
92
|
-
name: string;
|
|
93
|
-
argsJson: string;
|
|
94
|
-
}
|
|
95
|
-
export interface ToolCallDoneEvent {
|
|
96
|
-
type: "toolcall_done";
|
|
97
|
-
id: string;
|
|
98
|
-
name: string;
|
|
99
|
-
args: Record<string, unknown>;
|
|
100
|
-
}
|
|
101
|
-
export interface DoneEvent {
|
|
102
|
-
type: "done";
|
|
103
|
-
stopReason: StopReason;
|
|
104
|
-
}
|
|
105
|
-
export interface ErrorEvent {
|
|
106
|
-
type: "error";
|
|
107
|
-
error: Error;
|
|
108
|
-
}
|
|
109
|
-
export interface ServerToolCallEvent {
|
|
110
|
-
type: "server_toolcall";
|
|
111
|
-
id: string;
|
|
112
|
-
name: string;
|
|
113
|
-
input: unknown;
|
|
114
|
-
}
|
|
115
|
-
export interface ServerToolResultEvent {
|
|
116
|
-
type: "server_toolresult";
|
|
117
|
-
toolUseId: string;
|
|
118
|
-
resultType: string;
|
|
119
|
-
data: unknown;
|
|
120
|
-
}
|
|
121
|
-
export type StreamEvent = TextDeltaEvent | ThinkingDeltaEvent | ToolCallDeltaEvent | ToolCallDoneEvent | ServerToolCallEvent | ServerToolResultEvent | DoneEvent | ErrorEvent;
|
|
122
|
-
export type StopReason = "end_turn" | "tool_use" | "max_tokens" | "pause_turn" | "stop_sequence" | "refusal" | "error";
|
|
123
|
-
export interface StreamResponse {
|
|
124
|
-
message: AssistantMessage;
|
|
125
|
-
stopReason: StopReason;
|
|
126
|
-
usage: Usage;
|
|
127
|
-
}
|
|
128
|
-
export interface Usage {
|
|
129
|
-
inputTokens: number;
|
|
130
|
-
outputTokens: number;
|
|
131
|
-
cacheRead?: number;
|
|
132
|
-
cacheWrite?: number;
|
|
133
|
-
serverToolUse?: {
|
|
134
|
-
webSearchRequests?: number;
|
|
135
|
-
webFetchRequests?: number;
|
|
136
|
-
};
|
|
137
|
-
}
|
|
138
|
-
export interface StreamOptions {
|
|
139
|
-
provider: Provider;
|
|
140
|
-
model: string;
|
|
141
|
-
messages: Message[];
|
|
142
|
-
tools?: Tool[];
|
|
143
|
-
toolChoice?: ToolChoice;
|
|
144
|
-
serverTools?: ServerToolDefinition[];
|
|
145
|
-
maxTokens?: number;
|
|
146
|
-
temperature?: number;
|
|
147
|
-
topP?: number;
|
|
148
|
-
stop?: string[];
|
|
149
|
-
thinking?: ThinkingLevel;
|
|
150
|
-
apiKey?: string;
|
|
151
|
-
baseUrl?: string;
|
|
152
|
-
signal?: AbortSignal;
|
|
153
|
-
/** Prompt cache retention preference. Providers map this to their supported values. Default: "short". */
|
|
154
|
-
cacheRetention?: CacheRetention;
|
|
155
|
-
/** OpenAI ChatGPT account ID (from OAuth JWT) for codex endpoint */
|
|
156
|
-
accountId?: string;
|
|
157
|
-
/** Enable provider-native web search. Each provider uses its own format:
|
|
158
|
-
* - Anthropic: server tool `web_search_20250305`
|
|
159
|
-
* - Moonshot: `builtin_function` `$web_search`
|
|
160
|
-
* - GLM: web search via MCP servers (not inline — this flag is a no-op)
|
|
161
|
-
* - OpenAI/Codex: not supported (Chat Completions / Codex APIs lack web search) */
|
|
162
|
-
webSearch?: boolean;
|
|
163
|
-
/** Enable server-side compaction (Anthropic only, beta). Automatically
|
|
164
|
-
* summarizes earlier context when approaching the context window limit. */
|
|
165
|
-
compaction?: boolean;
|
|
166
|
-
}
|
|
167
|
-
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAI7B,MAAM,MAAM,QAAQ,GAAG,WAAW,GAAG,QAAQ,GAAG,KAAK,GAAG,UAAU,CAAC;AAInE,MAAM,MAAM,aAAa,GAAG,KAAK,GAAG,QAAQ,GAAG,MAAM,GAAG,KAAK,CAAC;AAI9D,MAAM,MAAM,cAAc,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,CAAC;AAIvD,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,UAAU,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,OAAO,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,WAAW,CAAC;IAClB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC/B;AAED,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,aAAa,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MA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CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,yGAAyG;IACzG,cAAc,CAAC,EAAE,cAAc,CAAC;IAChC,oEAAoE;IACpE,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;;wFAIoF;IACpF,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB;gFAC4E;IAC5E,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB"}
|
package/dist/types.js
DELETED
package/dist/types.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import type { StreamEvent, StreamResponse } from "../types.js";
|
|
2
|
-
/**
|
|
3
|
-
* Push-based async iterable. Producers push events, consumers
|
|
4
|
-
* iterate with `for await`. Also supports thenable so you can
|
|
5
|
-
* `await stream(...)` directly to get the final response.
|
|
6
|
-
*/
|
|
7
|
-
export declare class EventStream<T = StreamEvent> implements AsyncIterable<T> {
|
|
8
|
-
private queue;
|
|
9
|
-
private resolve;
|
|
10
|
-
private done;
|
|
11
|
-
private error;
|
|
12
|
-
push(event: T): void;
|
|
13
|
-
close(): void;
|
|
14
|
-
abort(error: Error): void;
|
|
15
|
-
[Symbol.asyncIterator](): AsyncIterator<T>;
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* Wraps EventStream and adds a `.response` promise that resolves
|
|
19
|
-
* to the final StreamResponse. Also implements thenable so:
|
|
20
|
-
*
|
|
21
|
-
* const msg = await stream({...}) // awaits response
|
|
22
|
-
* for await (const e of stream({...})) {} // iterates events
|
|
23
|
-
*/
|
|
24
|
-
export declare class StreamResult implements AsyncIterable<StreamEvent> {
|
|
25
|
-
readonly events: EventStream<StreamEvent>;
|
|
26
|
-
readonly response: Promise<StreamResponse>;
|
|
27
|
-
private resolveResponse;
|
|
28
|
-
private rejectResponse;
|
|
29
|
-
private hasConsumer;
|
|
30
|
-
constructor();
|
|
31
|
-
push(event: StreamEvent): void;
|
|
32
|
-
complete(response: StreamResponse): void;
|
|
33
|
-
abort(error: Error): void;
|
|
34
|
-
[Symbol.asyncIterator](): AsyncIterator<StreamEvent>;
|
|
35
|
-
then<TResult1 = StreamResponse, TResult2 = never>(onfulfilled?: ((value: StreamResponse) => TResult1 | PromiseLike<TResult1>) | null, onrejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null): Promise<TResult1 | TResult2>;
|
|
36
|
-
private drainEvents;
|
|
37
|
-
}
|
|
38
|
-
//# sourceMappingURL=event-stream.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"event-stream.d.ts","sourceRoot":"","sources":["../../src/utils/event-stream.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAE/D;;;;GAIG;AACH,qBAAa,WAAW,CAAC,CAAC,GAAG,WAAW,CAAE,YAAW,aAAa,CAAC,CAAC,CAAC;IACnE,OAAO,CAAC,KAAK,CAAW;IACxB,OAAO,CAAC,OAAO,CAA6B;IAC5C,OAAO,CAAC,IAAI,CAAS;IACrB,OAAO,CAAC,KAAK,CAAsB;IAEnC,IAAI,CAAC,KAAK,EAAE,CAAC,GAAG,IAAI;IAWpB,KAAK,IAAI,IAAI;IAMb,KAAK,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI;IAOlB,CAAC,MAAM,CAAC,aAAa,CAAC,IAAI,aAAa,CAAC,CAAC,CAAC;CAgBlD;AAED;;;;;;GAMG;AACH,qBAAa,YAAa,YAAW,aAAa,CAAC,WAAW,CAAC;IAC7D,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC,WAAW,CAAC,CAAC;IAC1C,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC,cAAc,CAAC,CAAC;IAC3C,OAAO,CAAC,eAAe,CAA+B;IACtD,OAAO,CAAC,cAAc,C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