@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
|
@@ -2343,16 +2343,17 @@ var mapUsage = (usage) => {
|
|
|
2343
2343
|
providerMetadata: { openai: usage }
|
|
2344
2344
|
});
|
|
2345
2345
|
};
|
|
2346
|
-
var normaliseTextDelta = (prev, incoming) => {
|
|
2347
|
-
if (!incoming) return { emit: "", textAcc: prev };
|
|
2348
|
-
if (
|
|
2349
|
-
|
|
2350
|
-
|
|
2346
|
+
var normaliseTextDelta = (prev, incoming, mode = "unknown") => {
|
|
2347
|
+
if (!incoming) return { emit: "", textAcc: prev, mode };
|
|
2348
|
+
if (mode === "unknown") {
|
|
2349
|
+
if (prev.length === 0) return { emit: incoming, textAcc: incoming, mode };
|
|
2350
|
+
mode = incoming.length > prev.length && incoming.startsWith(prev) ? "cumulative" : "incremental";
|
|
2351
2351
|
}
|
|
2352
|
-
if (
|
|
2353
|
-
return { emit:
|
|
2352
|
+
if (mode === "cumulative") {
|
|
2353
|
+
if (incoming.startsWith(prev)) return { emit: incoming.slice(prev.length), textAcc: incoming, mode };
|
|
2354
|
+
if (prev.startsWith(incoming)) return { emit: "", textAcc: prev, mode };
|
|
2354
2355
|
}
|
|
2355
|
-
return { emit: incoming, textAcc: prev + incoming };
|
|
2356
|
+
return { emit: incoming, textAcc: prev + incoming, mode };
|
|
2356
2357
|
};
|
|
2357
2358
|
var step = (state, event) => Effect.gen(function* () {
|
|
2358
2359
|
const events = [];
|
|
@@ -2363,13 +2364,15 @@ var step = (state, event) => Effect.gen(function* () {
|
|
|
2363
2364
|
const toolDeltas = delta?.tool_calls ?? [];
|
|
2364
2365
|
let tools = state.tools;
|
|
2365
2366
|
let textAcc = state.textAcc;
|
|
2367
|
+
let textMode = state.textMode;
|
|
2366
2368
|
const reasoningChunk = delta?.reasoning_content ?? delta?.reasoning;
|
|
2367
2369
|
if (reasoningChunk) {
|
|
2368
2370
|
events.push(LLMEvent.reasoningDelta({ id: "reasoning-0", text: reasoningChunk }));
|
|
2369
2371
|
}
|
|
2370
2372
|
if (delta?.content) {
|
|
2371
|
-
const normalised = normaliseTextDelta(textAcc, delta.content);
|
|
2373
|
+
const normalised = normaliseTextDelta(textAcc, delta.content, textMode);
|
|
2372
2374
|
textAcc = normalised.textAcc;
|
|
2375
|
+
textMode = normalised.mode;
|
|
2373
2376
|
if (normalised.emit) {
|
|
2374
2377
|
events.push(LLMEvent.textDelta({ id: "text-0", text: normalised.emit }));
|
|
2375
2378
|
}
|
|
@@ -2393,7 +2396,8 @@ var step = (state, event) => Effect.gen(function* () {
|
|
|
2393
2396
|
toolCallEvents: finished?.events ?? state.toolCallEvents,
|
|
2394
2397
|
usage,
|
|
2395
2398
|
finishReason,
|
|
2396
|
-
textAcc
|
|
2399
|
+
textAcc,
|
|
2400
|
+
textMode
|
|
2397
2401
|
},
|
|
2398
2402
|
events
|
|
2399
2403
|
];
|
|
@@ -2414,7 +2418,8 @@ var protocol = protocol_exports.make({
|
|
|
2414
2418
|
initial: () => ({
|
|
2415
2419
|
tools: tool_stream_exports.empty(),
|
|
2416
2420
|
toolCallEvents: [],
|
|
2417
|
-
textAcc: ""
|
|
2421
|
+
textAcc: "",
|
|
2422
|
+
textMode: "unknown"
|
|
2418
2423
|
}),
|
|
2419
2424
|
step,
|
|
2420
2425
|
onHalt: finishEvents
|