@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/index.cjs
CHANGED
|
@@ -2051,6 +2051,7 @@ __export(openai_chat_exports, {
|
|
|
2051
2051
|
bodyFields: () => bodyFields,
|
|
2052
2052
|
httpTransport: () => httpTransport,
|
|
2053
2053
|
model: () => model2,
|
|
2054
|
+
normaliseTextDelta: () => normaliseTextDelta,
|
|
2054
2055
|
protocol: () => protocol,
|
|
2055
2056
|
route: () => route
|
|
2056
2057
|
});
|
|
@@ -2448,16 +2449,17 @@ var mapUsage = (usage) => {
|
|
|
2448
2449
|
providerMetadata: { openai: usage }
|
|
2449
2450
|
});
|
|
2450
2451
|
};
|
|
2451
|
-
var normaliseTextDelta = (prev, incoming) => {
|
|
2452
|
-
if (!incoming) return { emit: "", textAcc: prev };
|
|
2453
|
-
if (
|
|
2454
|
-
|
|
2455
|
-
|
|
2452
|
+
var normaliseTextDelta = (prev, incoming, mode = "unknown") => {
|
|
2453
|
+
if (!incoming) return { emit: "", textAcc: prev, mode };
|
|
2454
|
+
if (mode === "unknown") {
|
|
2455
|
+
if (prev.length === 0) return { emit: incoming, textAcc: incoming, mode };
|
|
2456
|
+
mode = incoming.length > prev.length && incoming.startsWith(prev) ? "cumulative" : "incremental";
|
|
2456
2457
|
}
|
|
2457
|
-
if (
|
|
2458
|
-
return { emit:
|
|
2458
|
+
if (mode === "cumulative") {
|
|
2459
|
+
if (incoming.startsWith(prev)) return { emit: incoming.slice(prev.length), textAcc: incoming, mode };
|
|
2460
|
+
if (prev.startsWith(incoming)) return { emit: "", textAcc: prev, mode };
|
|
2459
2461
|
}
|
|
2460
|
-
return { emit: incoming, textAcc: prev + incoming };
|
|
2462
|
+
return { emit: incoming, textAcc: prev + incoming, mode };
|
|
2461
2463
|
};
|
|
2462
2464
|
var step = (state, event) => effect$1.Effect.gen(function* () {
|
|
2463
2465
|
const events = [];
|
|
@@ -2468,13 +2470,15 @@ var step = (state, event) => effect$1.Effect.gen(function* () {
|
|
|
2468
2470
|
const toolDeltas = delta?.tool_calls ?? [];
|
|
2469
2471
|
let tools = state.tools;
|
|
2470
2472
|
let textAcc = state.textAcc;
|
|
2473
|
+
let textMode = state.textMode;
|
|
2471
2474
|
const reasoningChunk = delta?.reasoning_content ?? delta?.reasoning;
|
|
2472
2475
|
if (reasoningChunk) {
|
|
2473
2476
|
events.push(LLMEvent.reasoningDelta({ id: "reasoning-0", text: reasoningChunk }));
|
|
2474
2477
|
}
|
|
2475
2478
|
if (delta?.content) {
|
|
2476
|
-
const normalised = normaliseTextDelta(textAcc, delta.content);
|
|
2479
|
+
const normalised = normaliseTextDelta(textAcc, delta.content, textMode);
|
|
2477
2480
|
textAcc = normalised.textAcc;
|
|
2481
|
+
textMode = normalised.mode;
|
|
2478
2482
|
if (normalised.emit) {
|
|
2479
2483
|
events.push(LLMEvent.textDelta({ id: "text-0", text: normalised.emit }));
|
|
2480
2484
|
}
|
|
@@ -2498,7 +2502,8 @@ var step = (state, event) => effect$1.Effect.gen(function* () {
|
|
|
2498
2502
|
toolCallEvents: finished?.events ?? state.toolCallEvents,
|
|
2499
2503
|
usage,
|
|
2500
2504
|
finishReason,
|
|
2501
|
-
textAcc
|
|
2505
|
+
textAcc,
|
|
2506
|
+
textMode
|
|
2502
2507
|
},
|
|
2503
2508
|
events
|
|
2504
2509
|
];
|
|
@@ -2519,7 +2524,8 @@ var protocol = protocol_exports.make({
|
|
|
2519
2524
|
initial: () => ({
|
|
2520
2525
|
tools: tool_stream_exports.empty(),
|
|
2521
2526
|
toolCallEvents: [],
|
|
2522
|
-
textAcc: ""
|
|
2527
|
+
textAcc: "",
|
|
2528
|
+
textMode: "unknown"
|
|
2523
2529
|
}),
|
|
2524
2530
|
step,
|
|
2525
2531
|
onHalt: finishEvents
|