@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
|
@@ -2321,16 +2321,17 @@ var mapUsage = (usage) => {
|
|
|
2321
2321
|
providerMetadata: { openai: usage }
|
|
2322
2322
|
});
|
|
2323
2323
|
};
|
|
2324
|
-
var normaliseTextDelta = (prev, incoming) => {
|
|
2325
|
-
if (!incoming) return { emit: "", textAcc: prev };
|
|
2326
|
-
if (
|
|
2327
|
-
|
|
2328
|
-
|
|
2324
|
+
var normaliseTextDelta = (prev, incoming, mode = "unknown") => {
|
|
2325
|
+
if (!incoming) return { emit: "", textAcc: prev, mode };
|
|
2326
|
+
if (mode === "unknown") {
|
|
2327
|
+
if (prev.length === 0) return { emit: incoming, textAcc: incoming, mode };
|
|
2328
|
+
mode = incoming.length > prev.length && incoming.startsWith(prev) ? "cumulative" : "incremental";
|
|
2329
2329
|
}
|
|
2330
|
-
if (
|
|
2331
|
-
return { emit:
|
|
2330
|
+
if (mode === "cumulative") {
|
|
2331
|
+
if (incoming.startsWith(prev)) return { emit: incoming.slice(prev.length), textAcc: incoming, mode };
|
|
2332
|
+
if (prev.startsWith(incoming)) return { emit: "", textAcc: prev, mode };
|
|
2332
2333
|
}
|
|
2333
|
-
return { emit: incoming, textAcc: prev + incoming };
|
|
2334
|
+
return { emit: incoming, textAcc: prev + incoming, mode };
|
|
2334
2335
|
};
|
|
2335
2336
|
var step = (state, event) => Effect.gen(function* () {
|
|
2336
2337
|
const events = [];
|
|
@@ -2341,13 +2342,15 @@ var step = (state, event) => Effect.gen(function* () {
|
|
|
2341
2342
|
const toolDeltas = delta?.tool_calls ?? [];
|
|
2342
2343
|
let tools = state.tools;
|
|
2343
2344
|
let textAcc = state.textAcc;
|
|
2345
|
+
let textMode = state.textMode;
|
|
2344
2346
|
const reasoningChunk = delta?.reasoning_content ?? delta?.reasoning;
|
|
2345
2347
|
if (reasoningChunk) {
|
|
2346
2348
|
events.push(LLMEvent.reasoningDelta({ id: "reasoning-0", text: reasoningChunk }));
|
|
2347
2349
|
}
|
|
2348
2350
|
if (delta?.content) {
|
|
2349
|
-
const normalised = normaliseTextDelta(textAcc, delta.content);
|
|
2351
|
+
const normalised = normaliseTextDelta(textAcc, delta.content, textMode);
|
|
2350
2352
|
textAcc = normalised.textAcc;
|
|
2353
|
+
textMode = normalised.mode;
|
|
2351
2354
|
if (normalised.emit) {
|
|
2352
2355
|
events.push(LLMEvent.textDelta({ id: "text-0", text: normalised.emit }));
|
|
2353
2356
|
}
|
|
@@ -2371,7 +2374,8 @@ var step = (state, event) => Effect.gen(function* () {
|
|
|
2371
2374
|
toolCallEvents: finished?.events ?? state.toolCallEvents,
|
|
2372
2375
|
usage,
|
|
2373
2376
|
finishReason,
|
|
2374
|
-
textAcc
|
|
2377
|
+
textAcc,
|
|
2378
|
+
textMode
|
|
2375
2379
|
},
|
|
2376
2380
|
events
|
|
2377
2381
|
];
|
|
@@ -2392,7 +2396,8 @@ var protocol = protocol_exports.make({
|
|
|
2392
2396
|
initial: () => ({
|
|
2393
2397
|
tools: tool_stream_exports.empty(),
|
|
2394
2398
|
toolCallEvents: [],
|
|
2395
|
-
textAcc: ""
|
|
2399
|
+
textAcc: "",
|
|
2400
|
+
textMode: "unknown"
|
|
2396
2401
|
}),
|
|
2397
2402
|
step,
|
|
2398
2403
|
onHalt: finishEvents
|