openfox 2.0.0-beta.11 → 2.0.0-beta.14
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/{ask-5SSOA6SZ.js → ask-BRLFZKEW.js} +2 -1
- package/dist/{auth-56SIRACI.js → auth-OGGBJFJQ.js} +2 -1
- package/dist/{branch.api-PWFW26KC.js → branch.api-TCWNJXYA.js} +2 -1
- package/dist/{chat-handler-NMJCOCCB.js → chat-handler-ZFQIJIJT.js} +9 -8
- package/dist/chunk-7D4SUZUM.js +38 -0
- package/dist/{chunk-EZUR7OEP.js → chunk-BURBTNDG.js} +15 -9
- package/dist/{chunk-DMH6JVPF.js → chunk-BZJAO4VY.js} +47 -19
- package/dist/{chunk-NSBYORD5.js → chunk-DHAKJSE7.js} +4 -2
- package/dist/{chunk-4RLDN2LL.js → chunk-EYE2JMLA.js} +189 -61
- package/dist/{chunk-EQQDA4D3.js → chunk-IONKVOSF.js} +17 -19
- package/dist/{chunk-VIIRNJDT.js → chunk-LXX2CPM5.js} +203 -236
- package/dist/{chunk-EXYMWI7A.js → chunk-OKLV3ZNN.js} +9 -5
- package/dist/chunk-QD6U3BDD.js +25277 -0
- package/dist/{chunk-BU56QFHW.js → chunk-RUWSVV7U.js} +8 -9
- package/dist/{chunk-LCRJWUW7.js → chunk-YWYYRA2P.js} +11 -11
- package/dist/cli/dev.js +2 -1
- package/dist/cli/index.js +2 -1
- package/dist/{compactor-TDNRM3A7.js → compactor-WL33VHUF.js} +2 -1
- package/dist/{config-TDVA7MQN.js → config-MFKBDOOT.js} +6 -5
- package/dist/{events-UGTGGFG3.js → events-6UJR2NH4.js} +3 -2
- package/dist/{folding-YOCGTZYH.js → folding-GMO644G3.js} +2 -1
- package/dist/{inspect-proxy-42ZXL2R5.js → inspect-proxy-JZ54RBUN.js} +2 -1
- package/dist/{manager-W7N3XQ4Q.js → manager-NTL3MLGN.js} +2 -1
- package/dist/{orchestrator-75L5UGDU.js → orchestrator-HHF4UC3K.js} +8 -7
- package/dist/package.json +1 -1
- package/dist/{paths-X46PPOI2.js → paths-D7BBTOO5.js} +2 -1
- package/dist/{permissions-Z2IIV2V7.js → permissions-YGAJ47F5.js} +3 -1
- package/dist/{processor-GHESQ2YV.js → processor-EJJTSLRL.js} +11 -5
- package/dist/{project-creator-6DU7E75S.js → project-creator-GMS5YKEF.js} +2 -1
- package/dist/{projects-2HYIZC4Y.js → projects-QHGMUKWH.js} +2 -1
- package/dist/{protocol-CN24IKQN.js → protocol-QQNATDFM.js} +2 -1
- package/dist/{protocol-B9R1CUvt.d.ts → protocol-zn90yuIr.d.ts} +11 -2
- package/dist/{provider-BGH4MBLH.js → provider-APFZV234.js} +10 -9
- package/dist/provider-manager-2NFFVCX5.js +17 -0
- package/dist/{pwa-76XP2DY2.js → pwa-WYVG3NLS.js} +2 -1
- package/dist/{serve-I6T7V62Z.js → serve-GTH76EDG.js} +14 -13
- package/dist/server/index.d.ts +21 -15
- package/dist/server/index.js +10 -9
- package/dist/{service-GB7AIOG5.js → service-W43DAQ5K.js} +3 -1
- package/dist/{settings-6XX56F3F.js → settings-OAISIQVV.js} +2 -1
- package/dist/shared/index.d.ts +2 -2
- package/dist/shared/index.js +1 -0
- package/dist/{store-OQ45KONN.js → store-JZW6VPEK.js} +2 -1
- package/dist/{tools-D3WWIOQD.js → tools-2X2FC6W7.js} +7 -6
- package/dist/web/assets/index-DCu8wsRj.js +299 -0
- package/dist/web/assets/{index-CSOB8dwI.css → index-Sdax8ayU.css} +1 -1
- package/dist/web/index.html +2 -2
- package/dist/web/sw.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-UKTPL5ZG.js +0 -469
- package/dist/web/assets/index-tJDr1ODC.js +0 -299
package/dist/chunk-UKTPL5ZG.js
DELETED
|
@@ -1,469 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
buildModelsUrl,
|
|
3
|
-
buildNonStreamingCreateParams,
|
|
4
|
-
buildStreamingCreateParams,
|
|
5
|
-
ensureVersionPrefix,
|
|
6
|
-
extractThinking,
|
|
7
|
-
getBackendCapabilities,
|
|
8
|
-
getModelProfile,
|
|
9
|
-
mapFinishReason,
|
|
10
|
-
stripVersionPrefix
|
|
11
|
-
} from "./chunk-VIIRNJDT.js";
|
|
12
|
-
import {
|
|
13
|
-
logger
|
|
14
|
-
} from "./chunk-K44MW7JJ.js";
|
|
15
|
-
|
|
16
|
-
// src/server/llm/models.ts
|
|
17
|
-
var modelCache = /* @__PURE__ */ new Map();
|
|
18
|
-
var llmStatus = "unknown";
|
|
19
|
-
var lastActiveUrl = null;
|
|
20
|
-
var CACHE_TTL_MS = 3e4;
|
|
21
|
-
function getCacheKey(url) {
|
|
22
|
-
return stripVersionPrefix(url);
|
|
23
|
-
}
|
|
24
|
-
async function detectModel(llmBaseUrl, retries = 3, silent = false) {
|
|
25
|
-
const cacheKey = getCacheKey(llmBaseUrl);
|
|
26
|
-
const now = Date.now();
|
|
27
|
-
const cached = modelCache.get(cacheKey);
|
|
28
|
-
if (cached && now - cached.timestamp < CACHE_TTL_MS) {
|
|
29
|
-
lastActiveUrl = cacheKey;
|
|
30
|
-
llmStatus = "connected";
|
|
31
|
-
return cached.model;
|
|
32
|
-
}
|
|
33
|
-
const url = buildModelsUrl(llmBaseUrl);
|
|
34
|
-
for (let attempt = 1; attempt <= retries; attempt++) {
|
|
35
|
-
try {
|
|
36
|
-
if (silent) {
|
|
37
|
-
logger.debug("Fetching models from LLM server", { url, attempt });
|
|
38
|
-
}
|
|
39
|
-
const response = await fetch(url, {
|
|
40
|
-
signal: AbortSignal.timeout(1e4)
|
|
41
|
-
});
|
|
42
|
-
if (!response.ok) {
|
|
43
|
-
if (silent) {
|
|
44
|
-
logger.debug("Failed to fetch models from LLM server", { status: response.status, attempt });
|
|
45
|
-
} else {
|
|
46
|
-
logger.warn("Failed to fetch models from LLM server", { status: response.status, attempt });
|
|
47
|
-
}
|
|
48
|
-
if (attempt < retries) {
|
|
49
|
-
await new Promise((r) => setTimeout(r, 1e3 * attempt));
|
|
50
|
-
continue;
|
|
51
|
-
}
|
|
52
|
-
llmStatus = "disconnected";
|
|
53
|
-
return cached?.model ?? null;
|
|
54
|
-
}
|
|
55
|
-
const data = await response.json();
|
|
56
|
-
if (data.data && data.data.length > 0) {
|
|
57
|
-
const modelData = data.data[0];
|
|
58
|
-
const modelId = modelData.id;
|
|
59
|
-
modelCache.set(cacheKey, {
|
|
60
|
-
model: modelId,
|
|
61
|
-
modelInfo: modelData,
|
|
62
|
-
timestamp: now
|
|
63
|
-
});
|
|
64
|
-
lastActiveUrl = cacheKey;
|
|
65
|
-
llmStatus = "connected";
|
|
66
|
-
if (silent) {
|
|
67
|
-
logger.debug("Detected LLM model", {
|
|
68
|
-
model: modelId,
|
|
69
|
-
maxLen: modelData.max_model_len,
|
|
70
|
-
root: modelData.root
|
|
71
|
-
});
|
|
72
|
-
} else {
|
|
73
|
-
logger.info("Detected LLM model", {
|
|
74
|
-
model: modelId,
|
|
75
|
-
maxLen: modelData.max_model_len,
|
|
76
|
-
root: modelData.root
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
return modelId;
|
|
80
|
-
}
|
|
81
|
-
if (silent) {
|
|
82
|
-
logger.debug("LLM server returned empty models list");
|
|
83
|
-
} else {
|
|
84
|
-
logger.warn("LLM server returned empty models list");
|
|
85
|
-
}
|
|
86
|
-
llmStatus = "disconnected";
|
|
87
|
-
return null;
|
|
88
|
-
} catch (error) {
|
|
89
|
-
const errMsg = error instanceof Error ? error.message : String(error);
|
|
90
|
-
if (silent) {
|
|
91
|
-
logger.debug("Could not detect model from LLM server", { error: errMsg, attempt });
|
|
92
|
-
} else {
|
|
93
|
-
logger.warn("Could not detect model from LLM server", { error: errMsg, attempt });
|
|
94
|
-
}
|
|
95
|
-
if (attempt < retries) {
|
|
96
|
-
await new Promise((r) => setTimeout(r, 1e3 * attempt));
|
|
97
|
-
continue;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
llmStatus = "disconnected";
|
|
102
|
-
return cached?.model ?? null;
|
|
103
|
-
}
|
|
104
|
-
function getLlmStatus() {
|
|
105
|
-
return llmStatus;
|
|
106
|
-
}
|
|
107
|
-
function clearModelCache(url) {
|
|
108
|
-
if (url) {
|
|
109
|
-
modelCache.delete(getCacheKey(url));
|
|
110
|
-
} else {
|
|
111
|
-
modelCache.clear();
|
|
112
|
-
}
|
|
113
|
-
llmStatus = "unknown";
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
// src/server/llm/client.ts
|
|
117
|
-
import OpenAI from "openai";
|
|
118
|
-
|
|
119
|
-
// src/server/utils/errors.ts
|
|
120
|
-
var OpenFoxError = class extends Error {
|
|
121
|
-
constructor(message, code, details) {
|
|
122
|
-
super(message);
|
|
123
|
-
this.code = code;
|
|
124
|
-
this.details = details;
|
|
125
|
-
this.name = "OpenFoxError";
|
|
126
|
-
}
|
|
127
|
-
};
|
|
128
|
-
var SessionNotFoundError = class extends OpenFoxError {
|
|
129
|
-
constructor(sessionId) {
|
|
130
|
-
super(`Session not found: ${sessionId}`, "SESSION_NOT_FOUND", { sessionId });
|
|
131
|
-
this.name = "SessionNotFoundError";
|
|
132
|
-
}
|
|
133
|
-
};
|
|
134
|
-
var LLMError = class extends OpenFoxError {
|
|
135
|
-
constructor(message, details) {
|
|
136
|
-
super(message, "LLM_ERROR", details);
|
|
137
|
-
this.name = "LLMError";
|
|
138
|
-
}
|
|
139
|
-
};
|
|
140
|
-
|
|
141
|
-
// src/server/llm/client.ts
|
|
142
|
-
function createLLMClient(config, initialBackend = "unknown") {
|
|
143
|
-
const baseURL = ensureVersionPrefix(config.llm.baseUrl);
|
|
144
|
-
const openai = new OpenAI({
|
|
145
|
-
baseURL,
|
|
146
|
-
apiKey: config.llm.apiKey ?? "not-needed"
|
|
147
|
-
});
|
|
148
|
-
let model = config.llm.model;
|
|
149
|
-
let profile = getModelProfile(model);
|
|
150
|
-
let backend = initialBackend;
|
|
151
|
-
let capabilities = getBackendCapabilities(backend);
|
|
152
|
-
const disableThinking = config.llm.disableThinking ?? false;
|
|
153
|
-
const idleTimeout = config.llm.idleTimeout ?? 3e4;
|
|
154
|
-
return {
|
|
155
|
-
getModel() {
|
|
156
|
-
return model;
|
|
157
|
-
},
|
|
158
|
-
getProfile() {
|
|
159
|
-
return profile;
|
|
160
|
-
},
|
|
161
|
-
getBackend() {
|
|
162
|
-
return backend;
|
|
163
|
-
},
|
|
164
|
-
setBackend(newBackend) {
|
|
165
|
-
logger.debug("Setting LLM backend", { from: backend, to: newBackend });
|
|
166
|
-
backend = newBackend;
|
|
167
|
-
capabilities = getBackendCapabilities(newBackend);
|
|
168
|
-
},
|
|
169
|
-
setModel(newModel) {
|
|
170
|
-
const newProfile = getModelProfile(newModel);
|
|
171
|
-
logger.debug("Switching model", {
|
|
172
|
-
from: model,
|
|
173
|
-
to: newModel,
|
|
174
|
-
profile: newProfile.name,
|
|
175
|
-
temperature: newProfile.temperature,
|
|
176
|
-
supportsReasoning: newProfile.supportsReasoning
|
|
177
|
-
});
|
|
178
|
-
model = newModel;
|
|
179
|
-
profile = newProfile;
|
|
180
|
-
},
|
|
181
|
-
async complete(request) {
|
|
182
|
-
logger.debug("LLM complete request", {
|
|
183
|
-
messageCount: request.messages.length,
|
|
184
|
-
hasTools: !!request.tools?.length,
|
|
185
|
-
profile: profile.name,
|
|
186
|
-
disableThinking
|
|
187
|
-
});
|
|
188
|
-
try {
|
|
189
|
-
const shouldDisableThinking = disableThinking || request.disableThinking === true;
|
|
190
|
-
const { params: createParams } = await buildNonStreamingCreateParams({
|
|
191
|
-
model,
|
|
192
|
-
request,
|
|
193
|
-
profile,
|
|
194
|
-
capabilities,
|
|
195
|
-
disableThinking: shouldDisableThinking
|
|
196
|
-
});
|
|
197
|
-
const response = await openai.chat.completions.create(createParams, {
|
|
198
|
-
signal: request.signal
|
|
199
|
-
});
|
|
200
|
-
const choice = response.choices[0];
|
|
201
|
-
if (!choice) {
|
|
202
|
-
throw new LLMError("No completion choice returned");
|
|
203
|
-
}
|
|
204
|
-
const message = choice.message;
|
|
205
|
-
let content = message.content ?? "";
|
|
206
|
-
let thinkingContent = "";
|
|
207
|
-
if (profile.supportsReasoning) {
|
|
208
|
-
if (capabilities.supportsReasoningField) {
|
|
209
|
-
thinkingContent = message.reasoning_content ?? message.reasoning ?? "";
|
|
210
|
-
} else {
|
|
211
|
-
const extracted = extractThinking(content);
|
|
212
|
-
content = extracted.content;
|
|
213
|
-
thinkingContent = extracted.thinkingContent ?? "";
|
|
214
|
-
}
|
|
215
|
-
if (profile.reasoningAsContent && thinkingContent.trim()) {
|
|
216
|
-
content = thinkingContent;
|
|
217
|
-
thinkingContent = "";
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
if (!content.trim() && thinkingContent.trim()) {
|
|
221
|
-
content = thinkingContent;
|
|
222
|
-
thinkingContent = "";
|
|
223
|
-
}
|
|
224
|
-
const toolCalls = message.tool_calls?.map((tc) => ({
|
|
225
|
-
id: tc.id,
|
|
226
|
-
name: tc.function.name,
|
|
227
|
-
arguments: JSON.parse(tc.function.arguments)
|
|
228
|
-
}));
|
|
229
|
-
return {
|
|
230
|
-
id: response.id,
|
|
231
|
-
content,
|
|
232
|
-
...thinkingContent ? { thinkingContent } : {},
|
|
233
|
-
...toolCalls && toolCalls.length > 0 ? { toolCalls } : {},
|
|
234
|
-
finishReason: mapFinishReason(choice.finish_reason),
|
|
235
|
-
usage: {
|
|
236
|
-
promptTokens: response.usage?.prompt_tokens ?? 0,
|
|
237
|
-
completionTokens: response.usage?.completion_tokens ?? 0,
|
|
238
|
-
totalTokens: response.usage?.total_tokens ?? 0
|
|
239
|
-
}
|
|
240
|
-
};
|
|
241
|
-
} catch (error) {
|
|
242
|
-
logger.error("LLM complete error", { error: String(error) });
|
|
243
|
-
throw new LLMError(error instanceof Error ? error.message : "Unknown LLM error", {
|
|
244
|
-
originalError: error instanceof Error ? error : void 0
|
|
245
|
-
});
|
|
246
|
-
}
|
|
247
|
-
},
|
|
248
|
-
async *stream(request) {
|
|
249
|
-
logger.debug("LLM stream request", {
|
|
250
|
-
messageCount: request.messages.length,
|
|
251
|
-
hasTools: !!request.tools?.length,
|
|
252
|
-
profile: profile.name,
|
|
253
|
-
disableThinking,
|
|
254
|
-
idleTimeout
|
|
255
|
-
});
|
|
256
|
-
try {
|
|
257
|
-
const shouldDisableThinking = disableThinking || request.disableThinking === true;
|
|
258
|
-
const createParams = await buildStreamingCreateParams({
|
|
259
|
-
model,
|
|
260
|
-
request,
|
|
261
|
-
profile,
|
|
262
|
-
capabilities,
|
|
263
|
-
disableThinking: shouldDisableThinking
|
|
264
|
-
});
|
|
265
|
-
const { params: streamingParams } = createParams;
|
|
266
|
-
const stream = await openai.chat.completions.create(streamingParams, {
|
|
267
|
-
signal: request.signal
|
|
268
|
-
});
|
|
269
|
-
let fullContent = "";
|
|
270
|
-
let fullThinking = "";
|
|
271
|
-
let inThinking = false;
|
|
272
|
-
let tagBuffer = "";
|
|
273
|
-
const toolCalls = /* @__PURE__ */ new Map();
|
|
274
|
-
let finishReason = "stop";
|
|
275
|
-
let usage = { promptTokens: 0, completionTokens: 0, totalTokens: 0 };
|
|
276
|
-
let responseId = "";
|
|
277
|
-
let lastChunkTime = Date.now();
|
|
278
|
-
const idleTimeoutController = new AbortController();
|
|
279
|
-
const idleTimer = setInterval(() => {
|
|
280
|
-
const idleDuration = Date.now() - lastChunkTime;
|
|
281
|
-
if (idleDuration > idleTimeout) {
|
|
282
|
-
logger.warn("LLM stream idle timeout triggered", { idleDuration, idleTimeout });
|
|
283
|
-
idleTimeoutController.abort();
|
|
284
|
-
}
|
|
285
|
-
}, 100);
|
|
286
|
-
const onAbort = () => clearInterval(idleTimer);
|
|
287
|
-
request.signal?.addEventListener("abort", onAbort, { once: true });
|
|
288
|
-
try {
|
|
289
|
-
for await (const chunk of stream) {
|
|
290
|
-
if (idleTimeoutController.signal.aborted) {
|
|
291
|
-
throw new Error(`LLM stream idle timeout: no chunks received for ${idleTimeout}ms`);
|
|
292
|
-
}
|
|
293
|
-
lastChunkTime = Date.now();
|
|
294
|
-
responseId = chunk.id;
|
|
295
|
-
if (chunk.usage) {
|
|
296
|
-
usage = {
|
|
297
|
-
promptTokens: chunk.usage.prompt_tokens,
|
|
298
|
-
completionTokens: chunk.usage.completion_tokens,
|
|
299
|
-
totalTokens: chunk.usage.total_tokens
|
|
300
|
-
};
|
|
301
|
-
}
|
|
302
|
-
const choice = chunk.choices[0];
|
|
303
|
-
if (!choice) continue;
|
|
304
|
-
if (choice.finish_reason) {
|
|
305
|
-
finishReason = mapFinishReason(choice.finish_reason);
|
|
306
|
-
}
|
|
307
|
-
const delta = choice.delta;
|
|
308
|
-
if (capabilities.supportsReasoningField) {
|
|
309
|
-
const reasoning = delta.reasoning_content ?? delta.reasoning;
|
|
310
|
-
if (reasoning) {
|
|
311
|
-
if (profile.supportsReasoning && !profile.reasoningAsContent) {
|
|
312
|
-
fullThinking += reasoning;
|
|
313
|
-
yield { type: "thinking_delta", content: reasoning };
|
|
314
|
-
} else {
|
|
315
|
-
fullContent += reasoning;
|
|
316
|
-
yield { type: "text_delta", content: reasoning };
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
if (delta.content) {
|
|
321
|
-
fullContent += delta.content;
|
|
322
|
-
if (!capabilities.supportsReasoningField && profile.supportsReasoning && !profile.reasoningAsContent) {
|
|
323
|
-
tagBuffer += delta.content;
|
|
324
|
-
while (tagBuffer.length > 0) {
|
|
325
|
-
if (inThinking) {
|
|
326
|
-
const closeIdx = tagBuffer.indexOf("</think>");
|
|
327
|
-
if (closeIdx !== -1) {
|
|
328
|
-
const thinkText = tagBuffer.slice(0, closeIdx);
|
|
329
|
-
if (thinkText) {
|
|
330
|
-
fullThinking += thinkText;
|
|
331
|
-
yield { type: "thinking_delta", content: thinkText };
|
|
332
|
-
}
|
|
333
|
-
tagBuffer = tagBuffer.slice(closeIdx + "</think>".length);
|
|
334
|
-
inThinking = false;
|
|
335
|
-
} else if (tagBuffer.includes("</")) {
|
|
336
|
-
const partialIdx = tagBuffer.lastIndexOf("</");
|
|
337
|
-
const before = tagBuffer.slice(0, partialIdx);
|
|
338
|
-
if (before) {
|
|
339
|
-
fullThinking += before;
|
|
340
|
-
yield { type: "thinking_delta", content: before };
|
|
341
|
-
}
|
|
342
|
-
tagBuffer = tagBuffer.slice(partialIdx);
|
|
343
|
-
break;
|
|
344
|
-
} else {
|
|
345
|
-
fullThinking += tagBuffer;
|
|
346
|
-
yield { type: "thinking_delta", content: tagBuffer };
|
|
347
|
-
tagBuffer = "";
|
|
348
|
-
}
|
|
349
|
-
} else {
|
|
350
|
-
const openIdx = tagBuffer.indexOf("<think>");
|
|
351
|
-
if (openIdx !== -1) {
|
|
352
|
-
const textBefore = tagBuffer.slice(0, openIdx);
|
|
353
|
-
if (textBefore) {
|
|
354
|
-
yield { type: "text_delta", content: textBefore };
|
|
355
|
-
}
|
|
356
|
-
tagBuffer = tagBuffer.slice(openIdx + "<think>".length);
|
|
357
|
-
inThinking = true;
|
|
358
|
-
} else if (tagBuffer.includes("<")) {
|
|
359
|
-
const partialIdx = tagBuffer.lastIndexOf("<");
|
|
360
|
-
const before = tagBuffer.slice(0, partialIdx);
|
|
361
|
-
if (before) {
|
|
362
|
-
yield { type: "text_delta", content: before };
|
|
363
|
-
}
|
|
364
|
-
tagBuffer = tagBuffer.slice(partialIdx);
|
|
365
|
-
break;
|
|
366
|
-
} else {
|
|
367
|
-
yield { type: "text_delta", content: tagBuffer };
|
|
368
|
-
tagBuffer = "";
|
|
369
|
-
}
|
|
370
|
-
}
|
|
371
|
-
}
|
|
372
|
-
} else {
|
|
373
|
-
yield { type: "text_delta", content: delta.content };
|
|
374
|
-
}
|
|
375
|
-
}
|
|
376
|
-
if (delta.tool_calls) {
|
|
377
|
-
for (const tc of delta.tool_calls) {
|
|
378
|
-
const existing = toolCalls.get(tc.index);
|
|
379
|
-
if (!existing) {
|
|
380
|
-
toolCalls.set(tc.index, {
|
|
381
|
-
id: tc.id ?? "",
|
|
382
|
-
name: tc.function?.name ?? "",
|
|
383
|
-
arguments: tc.function?.arguments ?? ""
|
|
384
|
-
});
|
|
385
|
-
} else {
|
|
386
|
-
if (tc.id) existing.id = tc.id;
|
|
387
|
-
if (tc.function?.name) existing.name += tc.function.name;
|
|
388
|
-
if (tc.function?.arguments) existing.arguments += tc.function.arguments;
|
|
389
|
-
}
|
|
390
|
-
yield {
|
|
391
|
-
type: "tool_call_delta",
|
|
392
|
-
index: tc.index,
|
|
393
|
-
...tc.id ? { id: tc.id } : {},
|
|
394
|
-
...tc.function?.name ? { name: tc.function.name } : {},
|
|
395
|
-
...tc.function?.arguments ? { arguments: tc.function.arguments } : {}
|
|
396
|
-
};
|
|
397
|
-
}
|
|
398
|
-
}
|
|
399
|
-
}
|
|
400
|
-
} finally {
|
|
401
|
-
clearInterval(idleTimer);
|
|
402
|
-
request.signal?.removeEventListener("abort", onAbort);
|
|
403
|
-
}
|
|
404
|
-
if (tagBuffer) {
|
|
405
|
-
if (inThinking) {
|
|
406
|
-
fullThinking += tagBuffer;
|
|
407
|
-
}
|
|
408
|
-
tagBuffer = "";
|
|
409
|
-
}
|
|
410
|
-
let finalContent = fullContent.trim();
|
|
411
|
-
let finalThinking = fullThinking.trim();
|
|
412
|
-
if (!capabilities.supportsReasoningField && profile.supportsReasoning) {
|
|
413
|
-
const extracted = extractThinking(finalContent);
|
|
414
|
-
finalContent = extracted.content;
|
|
415
|
-
finalThinking = extracted.thinkingContent ?? "";
|
|
416
|
-
}
|
|
417
|
-
if (!finalContent && finalThinking) {
|
|
418
|
-
finalContent = finalThinking;
|
|
419
|
-
finalThinking = "";
|
|
420
|
-
}
|
|
421
|
-
const parsedToolCalls = [];
|
|
422
|
-
for (const [, tc] of toolCalls) {
|
|
423
|
-
try {
|
|
424
|
-
parsedToolCalls.push({
|
|
425
|
-
id: tc.id,
|
|
426
|
-
name: tc.name,
|
|
427
|
-
arguments: JSON.parse(tc.arguments)
|
|
428
|
-
});
|
|
429
|
-
} catch (error) {
|
|
430
|
-
logger.warn("Failed to parse tool call arguments", { name: tc.name, arguments: tc.arguments });
|
|
431
|
-
parsedToolCalls.push({
|
|
432
|
-
id: tc.id,
|
|
433
|
-
name: tc.name,
|
|
434
|
-
arguments: {},
|
|
435
|
-
parseError: error instanceof Error ? error.message : "Unknown JSON parse error",
|
|
436
|
-
rawArguments: tc.arguments
|
|
437
|
-
});
|
|
438
|
-
}
|
|
439
|
-
}
|
|
440
|
-
yield {
|
|
441
|
-
type: "done",
|
|
442
|
-
response: {
|
|
443
|
-
id: responseId,
|
|
444
|
-
content: finalContent,
|
|
445
|
-
...finalThinking ? { thinkingContent: finalThinking } : {},
|
|
446
|
-
...parsedToolCalls.length > 0 ? { toolCalls: parsedToolCalls } : {},
|
|
447
|
-
finishReason,
|
|
448
|
-
usage
|
|
449
|
-
}
|
|
450
|
-
};
|
|
451
|
-
} catch (error) {
|
|
452
|
-
logger.error("LLM stream error", { error });
|
|
453
|
-
yield {
|
|
454
|
-
type: "error",
|
|
455
|
-
error: error instanceof Error ? error.message : "Unknown LLM error"
|
|
456
|
-
};
|
|
457
|
-
}
|
|
458
|
-
}
|
|
459
|
-
};
|
|
460
|
-
}
|
|
461
|
-
|
|
462
|
-
export {
|
|
463
|
-
SessionNotFoundError,
|
|
464
|
-
createLLMClient,
|
|
465
|
-
detectModel,
|
|
466
|
-
getLlmStatus,
|
|
467
|
-
clearModelCache
|
|
468
|
-
};
|
|
469
|
-
//# sourceMappingURL=chunk-UKTPL5ZG.js.map
|