@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
|
@@ -2373,16 +2373,17 @@ var mapUsage = (usage) => {
|
|
|
2373
2373
|
providerMetadata: { openai: usage }
|
|
2374
2374
|
});
|
|
2375
2375
|
};
|
|
2376
|
-
var normaliseTextDelta = (prev, incoming) => {
|
|
2377
|
-
if (!incoming) return { emit: "", textAcc: prev };
|
|
2378
|
-
if (
|
|
2379
|
-
|
|
2380
|
-
|
|
2376
|
+
var normaliseTextDelta = (prev, incoming, mode = "unknown") => {
|
|
2377
|
+
if (!incoming) return { emit: "", textAcc: prev, mode };
|
|
2378
|
+
if (mode === "unknown") {
|
|
2379
|
+
if (prev.length === 0) return { emit: incoming, textAcc: incoming, mode };
|
|
2380
|
+
mode = incoming.length > prev.length && incoming.startsWith(prev) ? "cumulative" : "incremental";
|
|
2381
2381
|
}
|
|
2382
|
-
if (
|
|
2383
|
-
return { emit:
|
|
2382
|
+
if (mode === "cumulative") {
|
|
2383
|
+
if (incoming.startsWith(prev)) return { emit: incoming.slice(prev.length), textAcc: incoming, mode };
|
|
2384
|
+
if (prev.startsWith(incoming)) return { emit: "", textAcc: prev, mode };
|
|
2384
2385
|
}
|
|
2385
|
-
return { emit: incoming, textAcc: prev + incoming };
|
|
2386
|
+
return { emit: incoming, textAcc: prev + incoming, mode };
|
|
2386
2387
|
};
|
|
2387
2388
|
var step = (state, event) => effect$1.Effect.gen(function* () {
|
|
2388
2389
|
const events = [];
|
|
@@ -2393,13 +2394,15 @@ var step = (state, event) => effect$1.Effect.gen(function* () {
|
|
|
2393
2394
|
const toolDeltas = delta?.tool_calls ?? [];
|
|
2394
2395
|
let tools = state.tools;
|
|
2395
2396
|
let textAcc = state.textAcc;
|
|
2397
|
+
let textMode = state.textMode;
|
|
2396
2398
|
const reasoningChunk = delta?.reasoning_content ?? delta?.reasoning;
|
|
2397
2399
|
if (reasoningChunk) {
|
|
2398
2400
|
events.push(LLMEvent.reasoningDelta({ id: "reasoning-0", text: reasoningChunk }));
|
|
2399
2401
|
}
|
|
2400
2402
|
if (delta?.content) {
|
|
2401
|
-
const normalised = normaliseTextDelta(textAcc, delta.content);
|
|
2403
|
+
const normalised = normaliseTextDelta(textAcc, delta.content, textMode);
|
|
2402
2404
|
textAcc = normalised.textAcc;
|
|
2405
|
+
textMode = normalised.mode;
|
|
2403
2406
|
if (normalised.emit) {
|
|
2404
2407
|
events.push(LLMEvent.textDelta({ id: "text-0", text: normalised.emit }));
|
|
2405
2408
|
}
|
|
@@ -2423,7 +2426,8 @@ var step = (state, event) => effect$1.Effect.gen(function* () {
|
|
|
2423
2426
|
toolCallEvents: finished?.events ?? state.toolCallEvents,
|
|
2424
2427
|
usage,
|
|
2425
2428
|
finishReason,
|
|
2426
|
-
textAcc
|
|
2429
|
+
textAcc,
|
|
2430
|
+
textMode
|
|
2427
2431
|
},
|
|
2428
2432
|
events
|
|
2429
2433
|
];
|
|
@@ -2444,7 +2448,8 @@ var protocol = protocol_exports.make({
|
|
|
2444
2448
|
initial: () => ({
|
|
2445
2449
|
tools: tool_stream_exports.empty(),
|
|
2446
2450
|
toolCallEvents: [],
|
|
2447
|
-
textAcc: ""
|
|
2451
|
+
textAcc: "",
|
|
2452
|
+
textMode: "unknown"
|
|
2448
2453
|
}),
|
|
2449
2454
|
step,
|
|
2450
2455
|
onHalt: finishEvents
|