@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.
@@ -2209,6 +2209,14 @@ var OpenAIChatToolCallDelta = effect$1.Schema.Struct({
2209
2209
  });
2210
2210
  var OpenAIChatDelta = effect$1.Schema.Struct({
2211
2211
  content: optionalNull(effect$1.Schema.String),
2212
+ /**
2213
+ * Thinking / chain-of-thought stream. DeepSeek + MiniMax native and
2214
+ * LiteLLM-normalized gateways use `reasoning_content`; OpenRouter (and some
2215
+ * Grok mirrors) use `reasoning`. Either must become `reasoning-delta` so
2216
+ * UIs are not stuck on a pre-text thinking spinner while the wire is live.
2217
+ */
2218
+ reasoning_content: optionalNull(effect$1.Schema.String),
2219
+ reasoning: optionalNull(effect$1.Schema.String),
2212
2220
  tool_calls: optionalNull(effect$1.Schema.Array(OpenAIChatToolCallDelta))
2213
2221
  });
2214
2222
  var OpenAIChatChoice = effect$1.Schema.Struct({
@@ -2365,16 +2373,17 @@ var mapUsage = (usage) => {
2365
2373
  providerMetadata: { openai: usage }
2366
2374
  });
2367
2375
  };
2368
- var normaliseTextDelta = (prev, incoming) => {
2369
- if (!incoming) return { emit: "", textAcc: prev };
2370
- if (incoming === prev) return { emit: "", textAcc: prev };
2371
- if (prev.length > 0 && incoming.startsWith(prev)) {
2372
- return { emit: incoming.slice(prev.length), textAcc: incoming };
2376
+ var normaliseTextDelta = (prev, incoming, mode = "unknown") => {
2377
+ if (!incoming) return { emit: "", textAcc: prev, mode };
2378
+ if (mode === "unknown") {
2379
+ if (prev.length === 0) return { emit: incoming, textAcc: incoming, mode };
2380
+ mode = incoming.length > prev.length && incoming.startsWith(prev) ? "cumulative" : "incremental";
2373
2381
  }
2374
- if (prev.length > 0 && prev.startsWith(incoming)) {
2375
- return { emit: "", textAcc: prev };
2382
+ if (mode === "cumulative") {
2383
+ if (incoming.startsWith(prev)) return { emit: incoming.slice(prev.length), textAcc: incoming, mode };
2384
+ if (prev.startsWith(incoming)) return { emit: "", textAcc: prev, mode };
2376
2385
  }
2377
- return { emit: incoming, textAcc: prev + incoming };
2386
+ return { emit: incoming, textAcc: prev + incoming, mode };
2378
2387
  };
2379
2388
  var step = (state, event) => effect$1.Effect.gen(function* () {
2380
2389
  const events = [];
@@ -2385,9 +2394,15 @@ var step = (state, event) => effect$1.Effect.gen(function* () {
2385
2394
  const toolDeltas = delta?.tool_calls ?? [];
2386
2395
  let tools = state.tools;
2387
2396
  let textAcc = state.textAcc;
2397
+ let textMode = state.textMode;
2398
+ const reasoningChunk = delta?.reasoning_content ?? delta?.reasoning;
2399
+ if (reasoningChunk) {
2400
+ events.push(LLMEvent.reasoningDelta({ id: "reasoning-0", text: reasoningChunk }));
2401
+ }
2388
2402
  if (delta?.content) {
2389
- const normalised = normaliseTextDelta(textAcc, delta.content);
2403
+ const normalised = normaliseTextDelta(textAcc, delta.content, textMode);
2390
2404
  textAcc = normalised.textAcc;
2405
+ textMode = normalised.mode;
2391
2406
  if (normalised.emit) {
2392
2407
  events.push(LLMEvent.textDelta({ id: "text-0", text: normalised.emit }));
2393
2408
  }
@@ -2411,7 +2426,8 @@ var step = (state, event) => effect$1.Effect.gen(function* () {
2411
2426
  toolCallEvents: finished?.events ?? state.toolCallEvents,
2412
2427
  usage,
2413
2428
  finishReason,
2414
- textAcc
2429
+ textAcc,
2430
+ textMode
2415
2431
  },
2416
2432
  events
2417
2433
  ];
@@ -2432,7 +2448,8 @@ var protocol = protocol_exports.make({
2432
2448
  initial: () => ({
2433
2449
  tools: tool_stream_exports.empty(),
2434
2450
  toolCallEvents: [],
2435
- textAcc: ""
2451
+ textAcc: "",
2452
+ textMode: "unknown"
2436
2453
  }),
2437
2454
  step,
2438
2455
  onHalt: finishEvents