@tinyweb_dev/agent-framework-llm 0.4.0 → 0.4.1
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 +17 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +17 -11
- package/dist/index.js.map +1 -1
- package/dist/protocols/openai-chat.cjs +18 -11
- package/dist/protocols/openai-chat.cjs.map +1 -1
- package/dist/protocols/openai-chat.d.ts +23 -0
- package/dist/protocols/openai-chat.d.ts.map +1 -1
- package/dist/protocols/openai-chat.js +18 -12
- package/dist/protocols/openai-chat.js.map +1 -1
- package/dist/protocols/openai-compatible-chat.cjs +16 -11
- package/dist/protocols/openai-compatible-chat.cjs.map +1 -1
- package/dist/protocols/openai-compatible-chat.js +16 -11
- package/dist/protocols/openai-compatible-chat.js.map +1 -1
- package/dist/providers/openai-compatible.cjs +16 -11
- package/dist/providers/openai-compatible.cjs.map +1 -1
- package/dist/providers/openai-compatible.js +16 -11
- package/dist/providers/openai-compatible.js.map +1 -1
- package/dist/providers/openai.cjs +16 -11
- package/dist/providers/openai.cjs.map +1 -1
- package/dist/providers/openai.js +16 -11
- package/dist/providers/openai.js.map +1 -1
- package/package.json +2 -2
package/dist/providers/openai.js
CHANGED
|
@@ -2351,16 +2351,17 @@ var mapUsage = (usage) => {
|
|
|
2351
2351
|
providerMetadata: { openai: usage }
|
|
2352
2352
|
});
|
|
2353
2353
|
};
|
|
2354
|
-
var normaliseTextDelta = (prev, incoming) => {
|
|
2355
|
-
if (!incoming) return { emit: "", textAcc: prev };
|
|
2356
|
-
if (
|
|
2357
|
-
|
|
2358
|
-
|
|
2354
|
+
var normaliseTextDelta = (prev, incoming, mode = "unknown") => {
|
|
2355
|
+
if (!incoming) return { emit: "", textAcc: prev, mode };
|
|
2356
|
+
if (mode === "unknown") {
|
|
2357
|
+
if (prev.length === 0) return { emit: incoming, textAcc: incoming, mode };
|
|
2358
|
+
mode = incoming.length > prev.length && incoming.startsWith(prev) ? "cumulative" : "incremental";
|
|
2359
2359
|
}
|
|
2360
|
-
if (
|
|
2361
|
-
return { emit:
|
|
2360
|
+
if (mode === "cumulative") {
|
|
2361
|
+
if (incoming.startsWith(prev)) return { emit: incoming.slice(prev.length), textAcc: incoming, mode };
|
|
2362
|
+
if (prev.startsWith(incoming)) return { emit: "", textAcc: prev, mode };
|
|
2362
2363
|
}
|
|
2363
|
-
return { emit: incoming, textAcc: prev + incoming };
|
|
2364
|
+
return { emit: incoming, textAcc: prev + incoming, mode };
|
|
2364
2365
|
};
|
|
2365
2366
|
var step = (state, event) => Effect.gen(function* () {
|
|
2366
2367
|
const events = [];
|
|
@@ -2371,13 +2372,15 @@ var step = (state, event) => Effect.gen(function* () {
|
|
|
2371
2372
|
const toolDeltas = delta?.tool_calls ?? [];
|
|
2372
2373
|
let tools = state.tools;
|
|
2373
2374
|
let textAcc = state.textAcc;
|
|
2375
|
+
let textMode = state.textMode;
|
|
2374
2376
|
const reasoningChunk = delta?.reasoning_content ?? delta?.reasoning;
|
|
2375
2377
|
if (reasoningChunk) {
|
|
2376
2378
|
events.push(LLMEvent.reasoningDelta({ id: "reasoning-0", text: reasoningChunk }));
|
|
2377
2379
|
}
|
|
2378
2380
|
if (delta?.content) {
|
|
2379
|
-
const normalised = normaliseTextDelta(textAcc, delta.content);
|
|
2381
|
+
const normalised = normaliseTextDelta(textAcc, delta.content, textMode);
|
|
2380
2382
|
textAcc = normalised.textAcc;
|
|
2383
|
+
textMode = normalised.mode;
|
|
2381
2384
|
if (normalised.emit) {
|
|
2382
2385
|
events.push(LLMEvent.textDelta({ id: "text-0", text: normalised.emit }));
|
|
2383
2386
|
}
|
|
@@ -2401,7 +2404,8 @@ var step = (state, event) => Effect.gen(function* () {
|
|
|
2401
2404
|
toolCallEvents: finished?.events ?? state.toolCallEvents,
|
|
2402
2405
|
usage,
|
|
2403
2406
|
finishReason,
|
|
2404
|
-
textAcc
|
|
2407
|
+
textAcc,
|
|
2408
|
+
textMode
|
|
2405
2409
|
},
|
|
2406
2410
|
events
|
|
2407
2411
|
];
|
|
@@ -2422,7 +2426,8 @@ var protocol = protocol_exports.make({
|
|
|
2422
2426
|
initial: () => ({
|
|
2423
2427
|
tools: tool_stream_exports.empty(),
|
|
2424
2428
|
toolCallEvents: [],
|
|
2425
|
-
textAcc: ""
|
|
2429
|
+
textAcc: "",
|
|
2430
|
+
textMode: "unknown"
|
|
2426
2431
|
}),
|
|
2427
2432
|
step,
|
|
2428
2433
|
onHalt: finishEvents
|