@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
|
@@ -40,6 +40,7 @@ __export(openai_chat_exports, {
|
|
|
40
40
|
bodyFields: () => bodyFields,
|
|
41
41
|
httpTransport: () => httpTransport,
|
|
42
42
|
model: () => model2,
|
|
43
|
+
normaliseTextDelta: () => normaliseTextDelta,
|
|
43
44
|
protocol: () => protocol,
|
|
44
45
|
route: () => route
|
|
45
46
|
});
|
|
@@ -2348,16 +2349,17 @@ var mapUsage = (usage) => {
|
|
|
2348
2349
|
providerMetadata: { openai: usage }
|
|
2349
2350
|
});
|
|
2350
2351
|
};
|
|
2351
|
-
var normaliseTextDelta = (prev, incoming) => {
|
|
2352
|
-
if (!incoming) return { emit: "", textAcc: prev };
|
|
2353
|
-
if (
|
|
2354
|
-
|
|
2355
|
-
|
|
2352
|
+
var normaliseTextDelta = (prev, incoming, mode = "unknown") => {
|
|
2353
|
+
if (!incoming) return { emit: "", textAcc: prev, mode };
|
|
2354
|
+
if (mode === "unknown") {
|
|
2355
|
+
if (prev.length === 0) return { emit: incoming, textAcc: incoming, mode };
|
|
2356
|
+
mode = incoming.length > prev.length && incoming.startsWith(prev) ? "cumulative" : "incremental";
|
|
2356
2357
|
}
|
|
2357
|
-
if (
|
|
2358
|
-
return { emit:
|
|
2358
|
+
if (mode === "cumulative") {
|
|
2359
|
+
if (incoming.startsWith(prev)) return { emit: incoming.slice(prev.length), textAcc: incoming, mode };
|
|
2360
|
+
if (prev.startsWith(incoming)) return { emit: "", textAcc: prev, mode };
|
|
2359
2361
|
}
|
|
2360
|
-
return { emit: incoming, textAcc: prev + incoming };
|
|
2362
|
+
return { emit: incoming, textAcc: prev + incoming, mode };
|
|
2361
2363
|
};
|
|
2362
2364
|
var step = (state, event) => effect$1.Effect.gen(function* () {
|
|
2363
2365
|
const events = [];
|
|
@@ -2368,13 +2370,15 @@ var step = (state, event) => effect$1.Effect.gen(function* () {
|
|
|
2368
2370
|
const toolDeltas = delta?.tool_calls ?? [];
|
|
2369
2371
|
let tools = state.tools;
|
|
2370
2372
|
let textAcc = state.textAcc;
|
|
2373
|
+
let textMode = state.textMode;
|
|
2371
2374
|
const reasoningChunk = delta?.reasoning_content ?? delta?.reasoning;
|
|
2372
2375
|
if (reasoningChunk) {
|
|
2373
2376
|
events.push(LLMEvent.reasoningDelta({ id: "reasoning-0", text: reasoningChunk }));
|
|
2374
2377
|
}
|
|
2375
2378
|
if (delta?.content) {
|
|
2376
|
-
const normalised = normaliseTextDelta(textAcc, delta.content);
|
|
2379
|
+
const normalised = normaliseTextDelta(textAcc, delta.content, textMode);
|
|
2377
2380
|
textAcc = normalised.textAcc;
|
|
2381
|
+
textMode = normalised.mode;
|
|
2378
2382
|
if (normalised.emit) {
|
|
2379
2383
|
events.push(LLMEvent.textDelta({ id: "text-0", text: normalised.emit }));
|
|
2380
2384
|
}
|
|
@@ -2398,7 +2402,8 @@ var step = (state, event) => effect$1.Effect.gen(function* () {
|
|
|
2398
2402
|
toolCallEvents: finished?.events ?? state.toolCallEvents,
|
|
2399
2403
|
usage,
|
|
2400
2404
|
finishReason,
|
|
2401
|
-
textAcc
|
|
2405
|
+
textAcc,
|
|
2406
|
+
textMode
|
|
2402
2407
|
},
|
|
2403
2408
|
events
|
|
2404
2409
|
];
|
|
@@ -2419,7 +2424,8 @@ var protocol = protocol_exports.make({
|
|
|
2419
2424
|
initial: () => ({
|
|
2420
2425
|
tools: tool_stream_exports.empty(),
|
|
2421
2426
|
toolCallEvents: [],
|
|
2422
|
-
textAcc: ""
|
|
2427
|
+
textAcc: "",
|
|
2428
|
+
textMode: "unknown"
|
|
2423
2429
|
}),
|
|
2424
2430
|
step,
|
|
2425
2431
|
onHalt: finishEvents
|
|
@@ -2449,6 +2455,7 @@ exports.PATH = PATH;
|
|
|
2449
2455
|
exports.bodyFields = bodyFields;
|
|
2450
2456
|
exports.httpTransport = httpTransport;
|
|
2451
2457
|
exports.model = model2;
|
|
2458
|
+
exports.normaliseTextDelta = normaliseTextDelta;
|
|
2452
2459
|
exports.protocol = protocol;
|
|
2453
2460
|
exports.route = route;
|
|
2454
2461
|
//# sourceMappingURL=openai-chat.cjs.map
|