@ank1015/providers 0.0.36 → 0.0.37
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/debug-conversation.d.ts +2 -0
- package/dist/debug-conversation.d.ts.map +1 -0
- package/dist/debug-conversation.js +98 -0
- package/dist/debug-conversation.js.map +1 -0
- package/dist/debug-minimal-test.d.ts +2 -0
- package/dist/debug-minimal-test.d.ts.map +1 -0
- package/dist/debug-minimal-test.js +47 -0
- package/dist/debug-minimal-test.js.map +1 -0
- package/dist/debug-sdk-tool.d.ts +2 -0
- package/dist/debug-sdk-tool.d.ts.map +1 -0
- package/dist/debug-sdk-tool.js +99 -0
- package/dist/debug-sdk-tool.js.map +1 -0
- package/dist/debug-sdk.d.ts +2 -0
- package/dist/debug-sdk.d.ts.map +1 -0
- package/dist/debug-sdk.js +59 -0
- package/dist/debug-sdk.js.map +1 -0
- package/dist/debug-session-flow.d.ts +2 -0
- package/dist/debug-session-flow.d.ts.map +1 -0
- package/dist/debug-session-flow.js +134 -0
- package/dist/debug-session-flow.js.map +1 -0
- package/dist/debug-session-hack.d.ts +2 -0
- package/dist/debug-session-hack.d.ts.map +1 -0
- package/dist/debug-session-hack.js +143 -0
- package/dist/debug-session-hack.js.map +1 -0
- package/dist/llm.d.ts.map +1 -1
- package/dist/llm.js +10 -1
- package/dist/llm.js.map +1 -1
- package/dist/models.generated.d.ts +19 -0
- package/dist/models.generated.d.ts.map +1 -1
- package/dist/models.generated.js +19 -0
- package/dist/models.generated.js.map +1 -1
- package/dist/providers/anthropic-agents-sdk/complete.d.ts +3 -0
- package/dist/providers/anthropic-agents-sdk/complete.d.ts.map +1 -0
- package/dist/providers/anthropic-agents-sdk/complete.js +246 -0
- package/dist/providers/anthropic-agents-sdk/complete.js.map +1 -0
- package/dist/providers/anthropic-agents-sdk/index.d.ts +4 -0
- package/dist/providers/anthropic-agents-sdk/index.d.ts.map +1 -0
- package/dist/providers/anthropic-agents-sdk/index.js +4 -0
- package/dist/providers/anthropic-agents-sdk/index.js.map +1 -0
- package/dist/providers/anthropic-agents-sdk/session.d.ts +37 -0
- package/dist/providers/anthropic-agents-sdk/session.d.ts.map +1 -0
- package/dist/providers/anthropic-agents-sdk/session.js +188 -0
- package/dist/providers/anthropic-agents-sdk/session.js.map +1 -0
- package/dist/providers/anthropic-agents-sdk/stream.d.ts +3 -0
- package/dist/providers/anthropic-agents-sdk/stream.d.ts.map +1 -0
- package/dist/providers/anthropic-agents-sdk/stream.js +402 -0
- package/dist/providers/anthropic-agents-sdk/stream.js.map +1 -0
- package/dist/providers/anthropic-agents-sdk/types.d.ts +22 -0
- package/dist/providers/anthropic-agents-sdk/types.d.ts.map +1 -0
- package/dist/providers/anthropic-agents-sdk/types.js +3 -0
- package/dist/providers/anthropic-agents-sdk/types.js.map +1 -0
- package/dist/providers/anthropic-agents-sdk/utils.d.ts +39 -0
- package/dist/providers/anthropic-agents-sdk/utils.d.ts.map +1 -0
- package/dist/providers/anthropic-agents-sdk/utils.js +251 -0
- package/dist/providers/anthropic-agents-sdk/utils.js.map +1 -0
- package/dist/providers/google/utils.d.ts.map +1 -1
- package/dist/providers/google/utils.js +2 -0
- package/dist/providers/google/utils.js.map +1 -1
- package/dist/providers/google-interactions/complete.d.ts +3 -0
- package/dist/providers/google-interactions/complete.d.ts.map +1 -0
- package/dist/providers/google-interactions/complete.js +63 -0
- package/dist/providers/google-interactions/complete.js.map +1 -0
- package/dist/providers/google-interactions/index.d.ts +5 -0
- package/dist/providers/google-interactions/index.d.ts.map +1 -0
- package/dist/providers/google-interactions/index.js +4 -0
- package/dist/providers/google-interactions/index.js.map +1 -0
- package/dist/providers/google-interactions/poll.d.ts +59 -0
- package/dist/providers/google-interactions/poll.d.ts.map +1 -0
- package/dist/providers/google-interactions/poll.js +161 -0
- package/dist/providers/google-interactions/poll.js.map +1 -0
- package/dist/providers/google-interactions/stream.d.ts +3 -0
- package/dist/providers/google-interactions/stream.d.ts.map +1 -0
- package/dist/providers/google-interactions/stream.js +242 -0
- package/dist/providers/google-interactions/stream.js.map +1 -0
- package/dist/providers/google-interactions/types.d.ts +10 -0
- package/dist/providers/google-interactions/types.d.ts.map +1 -0
- package/dist/providers/google-interactions/types.js +2 -0
- package/dist/providers/google-interactions/types.js.map +1 -0
- package/dist/providers/google-interactions/utils.d.ts +61 -0
- package/dist/providers/google-interactions/utils.d.ts.map +1 -0
- package/dist/providers/google-interactions/utils.js +252 -0
- package/dist/providers/google-interactions/utils.js.map +1 -0
- package/dist/providers/zai/complete.d.ts +3 -0
- package/dist/providers/zai/complete.d.ts.map +1 -0
- package/dist/providers/zai/complete.js +58 -0
- package/dist/providers/zai/complete.js.map +1 -0
- package/dist/providers/zai/index.d.ts +5 -0
- package/dist/providers/zai/index.d.ts.map +1 -0
- package/dist/providers/zai/index.js +4 -0
- package/dist/providers/zai/index.js.map +1 -0
- package/dist/providers/zai/stream.d.ts +3 -0
- package/dist/providers/zai/stream.d.ts.map +1 -0
- package/dist/providers/zai/stream.js +321 -0
- package/dist/providers/zai/stream.js.map +1 -0
- package/dist/providers/zai/types.d.ts +13 -0
- package/dist/providers/zai/types.d.ts.map +1 -0
- package/dist/providers/zai/types.js +2 -0
- package/dist/providers/zai/types.js.map +1 -0
- package/dist/providers/zai/utils.d.ts +19 -0
- package/dist/providers/zai/utils.d.ts.map +1 -0
- package/dist/providers/zai/utils.js +253 -0
- package/dist/providers/zai/utils.js.map +1 -0
- package/dist/test-sdk-direct.d.ts +2 -0
- package/dist/test-sdk-direct.d.ts.map +1 -0
- package/dist/test-sdk-direct.js +41 -0
- package/dist/test-sdk-direct.js.map +1 -0
- package/dist/test.d.ts +2 -0
- package/dist/test.d.ts.map +1 -0
- package/dist/test.js +213 -0
- package/dist/test.js.map +1 -0
- package/dist/types.d.ts +4 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +1 -1
- package/dist/types.js.map +1 -1
- package/dist/utils/oauth/google-antigravity.d.ts +25 -0
- package/dist/utils/oauth/google-antigravity.d.ts.map +1 -0
- package/dist/utils/oauth/google-antigravity.js +337 -0
- package/dist/utils/oauth/google-antigravity.js.map +1 -0
- package/dist/utils/oauth/pkce.d.ts +13 -0
- package/dist/utils/oauth/pkce.d.ts.map +1 -0
- package/dist/utils/oauth/pkce.js +31 -0
- package/dist/utils/oauth/pkce.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
import { GoogleGenAI } from "@google/genai";
|
|
2
|
+
import { calculateCost } from "../../models.js";
|
|
3
|
+
import { sanitizeSurrogates } from "../../utils/sanitize-unicode.js";
|
|
4
|
+
export function createClient(model, apiKey) {
|
|
5
|
+
if (!apiKey) {
|
|
6
|
+
if (!process.env.GEMINI_API_KEY) {
|
|
7
|
+
throw new Error("Gemini API key is required. Set GEMINI_API_KEY environment variable or pass it as an argument.");
|
|
8
|
+
}
|
|
9
|
+
apiKey = process.env.GEMINI_API_KEY;
|
|
10
|
+
}
|
|
11
|
+
return new GoogleGenAI({
|
|
12
|
+
apiKey,
|
|
13
|
+
httpOptions: model.headers ? { headers: model.headers } : undefined,
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
export function getResponseAssistantResponse(interaction) {
|
|
17
|
+
const assistantResponse = [];
|
|
18
|
+
if (!interaction.outputs)
|
|
19
|
+
return assistantResponse;
|
|
20
|
+
for (const output of interaction.outputs) {
|
|
21
|
+
const outputType = output.type;
|
|
22
|
+
// Handle text content
|
|
23
|
+
if (outputType === 'text') {
|
|
24
|
+
const textOutput = output;
|
|
25
|
+
if (textOutput.text) {
|
|
26
|
+
assistantResponse.push({
|
|
27
|
+
type: 'response',
|
|
28
|
+
content: [{ type: 'text', content: textOutput.text }]
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
// Handle thinking/thought content
|
|
33
|
+
else if (outputType === 'thought') {
|
|
34
|
+
const thoughtOutput = output;
|
|
35
|
+
const thinkingText = thoughtOutput.summary
|
|
36
|
+
?.filter(s => s.type === 'text')
|
|
37
|
+
.map(s => s.text || '')
|
|
38
|
+
.join('\n\n') || '';
|
|
39
|
+
if (thinkingText) {
|
|
40
|
+
assistantResponse.push({
|
|
41
|
+
type: 'thinking',
|
|
42
|
+
thinkingText
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
// Handle function calls
|
|
47
|
+
else if (outputType === 'function_call') {
|
|
48
|
+
const fnOutput = output;
|
|
49
|
+
assistantResponse.push({
|
|
50
|
+
type: 'toolCall',
|
|
51
|
+
toolCallId: fnOutput.id,
|
|
52
|
+
name: fnOutput.name,
|
|
53
|
+
arguments: fnOutput.arguments
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
// Handle image content
|
|
57
|
+
else if (outputType === 'image') {
|
|
58
|
+
const imgOutput = output;
|
|
59
|
+
if (imgOutput.data) {
|
|
60
|
+
assistantResponse.push({
|
|
61
|
+
type: 'response',
|
|
62
|
+
content: [{
|
|
63
|
+
type: 'image',
|
|
64
|
+
data: imgOutput.data,
|
|
65
|
+
mimeType: imgOutput.mime_type || 'image/png'
|
|
66
|
+
}]
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
// Other output types (google_search_result, url_context_result, etc.)
|
|
71
|
+
// are typically intermediate and not directly surfaced
|
|
72
|
+
}
|
|
73
|
+
return assistantResponse;
|
|
74
|
+
}
|
|
75
|
+
export function getResponseUsage(interaction, model) {
|
|
76
|
+
const interactionUsage = interaction.usage;
|
|
77
|
+
const usage = {
|
|
78
|
+
input: (interactionUsage?.total_input_tokens || 0) - (interactionUsage?.total_cached_tokens || 0),
|
|
79
|
+
output: (interactionUsage?.total_output_tokens || 0) + (interactionUsage?.total_reasoning_tokens || 0),
|
|
80
|
+
cacheRead: interactionUsage?.total_cached_tokens || 0,
|
|
81
|
+
cacheWrite: 0,
|
|
82
|
+
totalTokens: interactionUsage?.total_tokens || 0,
|
|
83
|
+
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 }
|
|
84
|
+
};
|
|
85
|
+
calculateCost(model, usage);
|
|
86
|
+
return usage;
|
|
87
|
+
}
|
|
88
|
+
export function mapInteractionStatus(status) {
|
|
89
|
+
switch (status) {
|
|
90
|
+
case 'completed':
|
|
91
|
+
return 'stop';
|
|
92
|
+
case 'in_progress':
|
|
93
|
+
return 'stop'; // Still processing, but not an error
|
|
94
|
+
case 'requires_action':
|
|
95
|
+
return 'toolUse';
|
|
96
|
+
case 'failed':
|
|
97
|
+
return 'error';
|
|
98
|
+
case 'cancelled':
|
|
99
|
+
return 'aborted';
|
|
100
|
+
default:
|
|
101
|
+
return 'stop';
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
export function buildParams(model, context, options) {
|
|
105
|
+
const input = buildInteractionInput(model, context);
|
|
106
|
+
const { apiKey, signal, ...interactionOptions } = options;
|
|
107
|
+
// Build base params
|
|
108
|
+
const params = {
|
|
109
|
+
...interactionOptions,
|
|
110
|
+
input,
|
|
111
|
+
};
|
|
112
|
+
// Set model or agent based on isAgent flag
|
|
113
|
+
if (model.isAgent) {
|
|
114
|
+
params.agent = model.id;
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
params.model = model.id;
|
|
118
|
+
}
|
|
119
|
+
// Add system instruction if present
|
|
120
|
+
if (context.systemPrompt) {
|
|
121
|
+
params.system_instruction = sanitizeSurrogates(context.systemPrompt);
|
|
122
|
+
}
|
|
123
|
+
// Add tools if present and supported
|
|
124
|
+
if (context.tools && context.tools.length > 0 && model.tools.includes('function_calling')) {
|
|
125
|
+
params.tools = convertTools(context.tools);
|
|
126
|
+
}
|
|
127
|
+
return params;
|
|
128
|
+
}
|
|
129
|
+
export function buildInteractionInput(model, context) {
|
|
130
|
+
// If no messages, return empty
|
|
131
|
+
if (context.messages.length === 0) {
|
|
132
|
+
return [];
|
|
133
|
+
}
|
|
134
|
+
// If single user message with only text, can return string
|
|
135
|
+
if (context.messages.length === 1 && context.messages[0].role === 'user') {
|
|
136
|
+
const msg = context.messages[0];
|
|
137
|
+
if (msg.role === 'user' && msg.content.length === 1 && msg.content[0].type === 'text') {
|
|
138
|
+
return sanitizeSurrogates(msg.content[0].content);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
// Build full conversation as turns
|
|
142
|
+
const turns = [];
|
|
143
|
+
for (const message of context.messages) {
|
|
144
|
+
if (message.role === 'user') {
|
|
145
|
+
const content = [];
|
|
146
|
+
for (const c of message.content) {
|
|
147
|
+
if (c.type === 'text') {
|
|
148
|
+
content.push({ type: 'text', text: sanitizeSurrogates(c.content) });
|
|
149
|
+
}
|
|
150
|
+
else if (c.type === 'image' && model.input.includes('image')) {
|
|
151
|
+
content.push({
|
|
152
|
+
type: 'image',
|
|
153
|
+
data: c.data,
|
|
154
|
+
mime_type: c.mimeType
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
else if (c.type === 'file' && model.input.includes('file')) {
|
|
158
|
+
content.push({
|
|
159
|
+
type: 'document',
|
|
160
|
+
data: c.data,
|
|
161
|
+
mime_type: c.mimeType
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
if (content.length > 0) {
|
|
166
|
+
turns.push({ role: 'user', content });
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
else if (message.role === 'toolResult') {
|
|
170
|
+
// Tool results go as user turn with function_result content
|
|
171
|
+
const result = {
|
|
172
|
+
type: 'function_result',
|
|
173
|
+
call_id: message.toolCallId,
|
|
174
|
+
name: message.toolName,
|
|
175
|
+
result: message.content
|
|
176
|
+
.filter(c => c.type === 'text')
|
|
177
|
+
.map(c => c.content)
|
|
178
|
+
.join('\n') || '',
|
|
179
|
+
is_error: message.isError
|
|
180
|
+
};
|
|
181
|
+
turns.push({ role: 'user', content: [result] });
|
|
182
|
+
}
|
|
183
|
+
else if (message.role === 'assistant') {
|
|
184
|
+
// Convert assistant message to model turn
|
|
185
|
+
const content = [];
|
|
186
|
+
// Check if this is a google-interactions native message
|
|
187
|
+
if (message.model.api === 'google-interactions') {
|
|
188
|
+
const baseMessage = message;
|
|
189
|
+
// Use outputs directly if available
|
|
190
|
+
if (baseMessage.message?.outputs) {
|
|
191
|
+
turns.push({
|
|
192
|
+
role: 'model',
|
|
193
|
+
content: baseMessage.message.outputs
|
|
194
|
+
});
|
|
195
|
+
continue;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
// Convert from normalized content
|
|
199
|
+
for (const block of message.content) {
|
|
200
|
+
if (block.type === 'thinking') {
|
|
201
|
+
// Wrap thinking in tags for cross-provider context
|
|
202
|
+
content.push({
|
|
203
|
+
type: 'text',
|
|
204
|
+
text: `<thinking>${sanitizeSurrogates(block.thinkingText)}</thinking>`
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
else if (block.type === 'response') {
|
|
208
|
+
const textContent = block.content
|
|
209
|
+
.filter(c => c.type === 'text')
|
|
210
|
+
.map(c => sanitizeSurrogates(c.content))
|
|
211
|
+
.join('');
|
|
212
|
+
if (textContent) {
|
|
213
|
+
content.push({ type: 'text', text: textContent });
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
else if (block.type === 'toolCall') {
|
|
217
|
+
content.push({
|
|
218
|
+
type: 'function_call',
|
|
219
|
+
id: block.toolCallId,
|
|
220
|
+
name: block.name,
|
|
221
|
+
arguments: block.arguments
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
if (content.length > 0) {
|
|
226
|
+
turns.push({ role: 'model', content });
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
return turns;
|
|
231
|
+
}
|
|
232
|
+
export function convertTools(tools) {
|
|
233
|
+
return tools.map((tool) => ({
|
|
234
|
+
type: 'function',
|
|
235
|
+
name: tool.name,
|
|
236
|
+
description: tool.description,
|
|
237
|
+
parameters: tool.parameters, // TypeBox already generates JSON Schema
|
|
238
|
+
}));
|
|
239
|
+
}
|
|
240
|
+
export function getMockInteraction() {
|
|
241
|
+
return {
|
|
242
|
+
id: 'interaction_mock',
|
|
243
|
+
status: 'completed',
|
|
244
|
+
outputs: [],
|
|
245
|
+
usage: {
|
|
246
|
+
total_input_tokens: 0,
|
|
247
|
+
total_output_tokens: 0,
|
|
248
|
+
total_tokens: 0
|
|
249
|
+
}
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/providers/google-interactions/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAgB,MAAM,eAAe,CAAC;AAW1D,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD,OAAO,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AAuBrE,MAAM,UAAU,YAAY,CAAC,KAAmC,EAAE,MAAe;IAChF,IAAI,CAAC,MAAM,EAAE,CAAC;QACb,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,cAAc,EAAE,CAAC;YACjC,MAAM,IAAI,KAAK,CACd,gGAAgG,CAChG,CAAC;QACH,CAAC;QACD,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC;IACrC,CAAC;IACD,OAAO,IAAI,WAAW,CAAC;QACtB,MAAM;QACN,WAAW,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,SAAS;KACnE,CAAC,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,4BAA4B,CAAC,WAAwB;IACpE,MAAM,iBAAiB,GAAsB,EAAE,CAAC;IAEhD,IAAI,CAAC,WAAW,CAAC,OAAO;QAAE,OAAO,iBAAiB,CAAC;IAEnD,KAAK,MAAM,MAAM,IAAI,WAAW,CAAC,OAAO,EAAE,CAAC;QAC1C,MAAM,UAAU,GAA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C;wBACZ,IAAI,EAAE,eAAe;wBACrB,EAAE,EAAE,KAAK,CAAC,UAAU;wBACpB,IAAI,EAAE,KAAK,CAAC,IAAI;wBAChB,SAAS,EAAE,KAAK,CAAC,SAAS;qBAC1B,CAAC,CAAC;gBACJ,CAAC;YACF,CAAC;YAED,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBACxB,KAAK,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,CAAC;YACxC,CAAC;QACF,CAAC;IACF,CAAC;IAED,OAAO,KAAK,CAAC;AACd,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,KAAsB;IAClD,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;QAC3B,IAAI,EAAE,UAAmB;QACzB,IAAI,EAAE,IAAI,CAAC,IAAI;QACf,WAAW,EAAE,IAAI,CAAC,WAAW;QAC7B,UAAU,EAAE,IAAI,CAAC,UAAU,EAAE,wCAAwC;KACrE,CAAC,CAAC,CAAC;AACL,CAAC;AAED,MAAM,UAAU,kBAAkB;IACjC,OAAO;QACN,EAAE,EAAE,kBAAkB;QACtB,MAAM,EAAE,WAAW;QACnB,OAAO,EAAE,EAAE;QACX,KAAK,EAAE;YACN,kBAAkB,EAAE,CAAC;YACrB,mBAAmB,EAAE,CAAC;YACtB,YAAY,EAAE,CAAC;SACf;KACc,CAAC;AAClB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"complete.d.ts","sourceRoot":"","sources":["../../../src/providers/zai/complete.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAA4B,MAAM,gBAAgB,CAAC;AAM5E,eAAO,MAAM,WAAW,EAAE,gBAAgB,CAAC,KAAK,CAoE/C,CAAC"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { createClient, buildParams, getResponseAssistantResponse, getResponseUsage, getAssistantStopReason } from "./utils.js";
|
|
2
|
+
export const completeZai = async (model, context, options, id) => {
|
|
3
|
+
const startTimestamp = Date.now();
|
|
4
|
+
const client = createClient(model, options?.apiKey);
|
|
5
|
+
const params = buildParams(model, context, options);
|
|
6
|
+
try {
|
|
7
|
+
const response = await client.chat.completions.create(params, { signal: options?.signal });
|
|
8
|
+
// Cache processed content for performance and consistency
|
|
9
|
+
const content = getResponseAssistantResponse(response);
|
|
10
|
+
const usage = getResponseUsage(response, model);
|
|
11
|
+
let stopReason = getAssistantStopReason(response);
|
|
12
|
+
// Ensure stopReason is toolUse if we have tool calls
|
|
13
|
+
const hasToolCall = content.some(c => c.type === 'toolCall');
|
|
14
|
+
if (hasToolCall && stopReason === 'stop') {
|
|
15
|
+
stopReason = 'toolUse';
|
|
16
|
+
}
|
|
17
|
+
return {
|
|
18
|
+
role: "assistant",
|
|
19
|
+
message: response,
|
|
20
|
+
id,
|
|
21
|
+
api: model.api,
|
|
22
|
+
model,
|
|
23
|
+
timestamp: Date.now(),
|
|
24
|
+
duration: Date.now() - startTimestamp,
|
|
25
|
+
stopReason,
|
|
26
|
+
content,
|
|
27
|
+
usage
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
catch (error) {
|
|
31
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
32
|
+
const isAborted = options.signal?.aborted;
|
|
33
|
+
const stopReason = isAborted ? "aborted" : "error";
|
|
34
|
+
// Return error response with empty content and zero usage
|
|
35
|
+
const emptyUsage = {
|
|
36
|
+
input: 0,
|
|
37
|
+
output: 0,
|
|
38
|
+
cacheRead: 0,
|
|
39
|
+
cacheWrite: 0,
|
|
40
|
+
totalTokens: 0,
|
|
41
|
+
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 }
|
|
42
|
+
};
|
|
43
|
+
return {
|
|
44
|
+
role: "assistant",
|
|
45
|
+
message: {}, // Empty response object for error case
|
|
46
|
+
id,
|
|
47
|
+
api: model.api,
|
|
48
|
+
model,
|
|
49
|
+
errorMessage,
|
|
50
|
+
timestamp: Date.now(),
|
|
51
|
+
duration: Date.now() - startTimestamp,
|
|
52
|
+
stopReason,
|
|
53
|
+
content: [],
|
|
54
|
+
usage: emptyUsage
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
//# sourceMappingURL=complete.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"complete.js","sourceRoot":"","sources":["../../../src/providers/zai/complete.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,4BAA4B,EAAE,gBAAgB,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AAG/H,MAAM,CAAC,MAAM,WAAW,GAA4B,KAAK,EACxD,KAAmB,EACnB,OAAO,EACP,OAA2B,EAC3B,EAAU,EACT,EAAE;IACH,MAAM,cAAc,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IAClC,MAAM,MAAM,GAAG,YAAY,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;IACpD,MAAM,MAAM,GAAG,WAAW,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;IAEpD,IAAI,CAAC;QACJ,MAAM,QAAQ,GAAmB,MAAM,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,CACpE,MAAM,EACN,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,CAC3B,CAAC;QAEF,0DAA0D;QAC1D,MAAM,OAAO,GAAG,4BAA4B,CAAC,QAAQ,CAAC,CAAC;QACvD,MAAM,KAAK,GAAG,gBAAgB,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;QAChD,IAAI,UAAU,GAAG,sBAAsB,CAAC,QAAQ,CAAC,CAAC;QAElD,qDAAqD;QACrD,MAAM,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,UAAU,CAAC,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rC,UAAU;YACV,OAAO,EAAE,EAAE;YACX,KAAK,EAAE,UAAU;SACjB,CAAC;IACH,CAAC;AACF,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/providers/zai/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AACnE,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/providers/zai/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../../../src/providers/zai/stream.ts"],"names":[],"mappings":"AAAA,OAAO,EAA0I,cAAc,EAAe,MAAM,gBAAgB,CAAA;AAoBpM,eAAO,MAAM,SAAS,EAAE,cAAc,CAAC,KAAK,CA4W3C,CAAA"}
|