@tinyweb_dev/agent-framework-llm 0.3.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 +29 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +29 -11
- package/dist/index.js.map +1 -1
- package/dist/protocols/openai-chat.cjs +30 -11
- package/dist/protocols/openai-chat.cjs.map +1 -1
- package/dist/protocols/openai-chat.d.ts +25 -0
- package/dist/protocols/openai-chat.d.ts.map +1 -1
- package/dist/protocols/openai-chat.js +30 -12
- package/dist/protocols/openai-chat.js.map +1 -1
- package/dist/protocols/openai-compatible-chat.cjs +28 -11
- package/dist/protocols/openai-compatible-chat.cjs.map +1 -1
- package/dist/protocols/openai-compatible-chat.js +28 -11
- package/dist/protocols/openai-compatible-chat.js.map +1 -1
- package/dist/providers/openai-compatible.cjs +28 -11
- package/dist/providers/openai-compatible.cjs.map +1 -1
- package/dist/providers/openai-compatible.js +28 -11
- package/dist/providers/openai-compatible.js.map +1 -1
- package/dist/providers/openai.cjs +28 -11
- package/dist/providers/openai.cjs.map +1 -1
- package/dist/providers/openai.js +28 -11
- package/dist/providers/openai.js.map +1 -1
- package/package.json +2 -2
package/dist/providers/openai.js
CHANGED
|
@@ -2187,6 +2187,14 @@ var OpenAIChatToolCallDelta = Schema.Struct({
|
|
|
2187
2187
|
});
|
|
2188
2188
|
var OpenAIChatDelta = Schema.Struct({
|
|
2189
2189
|
content: optionalNull(Schema.String),
|
|
2190
|
+
/**
|
|
2191
|
+
* Thinking / chain-of-thought stream. DeepSeek + MiniMax native and
|
|
2192
|
+
* LiteLLM-normalized gateways use `reasoning_content`; OpenRouter (and some
|
|
2193
|
+
* Grok mirrors) use `reasoning`. Either must become `reasoning-delta` so
|
|
2194
|
+
* UIs are not stuck on a pre-text thinking spinner while the wire is live.
|
|
2195
|
+
*/
|
|
2196
|
+
reasoning_content: optionalNull(Schema.String),
|
|
2197
|
+
reasoning: optionalNull(Schema.String),
|
|
2190
2198
|
tool_calls: optionalNull(Schema.Array(OpenAIChatToolCallDelta))
|
|
2191
2199
|
});
|
|
2192
2200
|
var OpenAIChatChoice = Schema.Struct({
|
|
@@ -2343,16 +2351,17 @@ var mapUsage = (usage) => {
|
|
|
2343
2351
|
providerMetadata: { openai: usage }
|
|
2344
2352
|
});
|
|
2345
2353
|
};
|
|
2346
|
-
var normaliseTextDelta = (prev, incoming) => {
|
|
2347
|
-
if (!incoming) return { emit: "", textAcc: prev };
|
|
2348
|
-
if (
|
|
2349
|
-
|
|
2350
|
-
|
|
2354
|
+
var normaliseTextDelta = (prev, incoming, mode = "unknown") => {
|
|
2355
|
+
if (!incoming) return { emit: "", textAcc: prev, mode };
|
|
2356
|
+
if (mode === "unknown") {
|
|
2357
|
+
if (prev.length === 0) return { emit: incoming, textAcc: incoming, mode };
|
|
2358
|
+
mode = incoming.length > prev.length && incoming.startsWith(prev) ? "cumulative" : "incremental";
|
|
2351
2359
|
}
|
|
2352
|
-
if (
|
|
2353
|
-
return { emit:
|
|
2360
|
+
if (mode === "cumulative") {
|
|
2361
|
+
if (incoming.startsWith(prev)) return { emit: incoming.slice(prev.length), textAcc: incoming, mode };
|
|
2362
|
+
if (prev.startsWith(incoming)) return { emit: "", textAcc: prev, mode };
|
|
2354
2363
|
}
|
|
2355
|
-
return { emit: incoming, textAcc: prev + incoming };
|
|
2364
|
+
return { emit: incoming, textAcc: prev + incoming, mode };
|
|
2356
2365
|
};
|
|
2357
2366
|
var step = (state, event) => Effect.gen(function* () {
|
|
2358
2367
|
const events = [];
|
|
@@ -2363,9 +2372,15 @@ var step = (state, event) => Effect.gen(function* () {
|
|
|
2363
2372
|
const toolDeltas = delta?.tool_calls ?? [];
|
|
2364
2373
|
let tools = state.tools;
|
|
2365
2374
|
let textAcc = state.textAcc;
|
|
2375
|
+
let textMode = state.textMode;
|
|
2376
|
+
const reasoningChunk = delta?.reasoning_content ?? delta?.reasoning;
|
|
2377
|
+
if (reasoningChunk) {
|
|
2378
|
+
events.push(LLMEvent.reasoningDelta({ id: "reasoning-0", text: reasoningChunk }));
|
|
2379
|
+
}
|
|
2366
2380
|
if (delta?.content) {
|
|
2367
|
-
const normalised = normaliseTextDelta(textAcc, delta.content);
|
|
2381
|
+
const normalised = normaliseTextDelta(textAcc, delta.content, textMode);
|
|
2368
2382
|
textAcc = normalised.textAcc;
|
|
2383
|
+
textMode = normalised.mode;
|
|
2369
2384
|
if (normalised.emit) {
|
|
2370
2385
|
events.push(LLMEvent.textDelta({ id: "text-0", text: normalised.emit }));
|
|
2371
2386
|
}
|
|
@@ -2389,7 +2404,8 @@ var step = (state, event) => Effect.gen(function* () {
|
|
|
2389
2404
|
toolCallEvents: finished?.events ?? state.toolCallEvents,
|
|
2390
2405
|
usage,
|
|
2391
2406
|
finishReason,
|
|
2392
|
-
textAcc
|
|
2407
|
+
textAcc,
|
|
2408
|
+
textMode
|
|
2393
2409
|
},
|
|
2394
2410
|
events
|
|
2395
2411
|
];
|
|
@@ -2410,7 +2426,8 @@ var protocol = protocol_exports.make({
|
|
|
2410
2426
|
initial: () => ({
|
|
2411
2427
|
tools: tool_stream_exports.empty(),
|
|
2412
2428
|
toolCallEvents: [],
|
|
2413
|
-
textAcc: ""
|
|
2429
|
+
textAcc: "",
|
|
2430
|
+
textMode: "unknown"
|
|
2414
2431
|
}),
|
|
2415
2432
|
step,
|
|
2416
2433
|
onHalt: finishEvents
|