@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.js CHANGED
@@ -2029,6 +2029,7 @@ __export(openai_chat_exports, {
2029
2029
  bodyFields: () => bodyFields,
2030
2030
  httpTransport: () => httpTransport,
2031
2031
  model: () => model2,
2032
+ normaliseTextDelta: () => normaliseTextDelta,
2032
2033
  protocol: () => protocol,
2033
2034
  route: () => route
2034
2035
  });
@@ -2262,6 +2263,14 @@ var OpenAIChatToolCallDelta = Schema.Struct({
2262
2263
  });
2263
2264
  var OpenAIChatDelta = Schema.Struct({
2264
2265
  content: optionalNull(Schema.String),
2266
+ /**
2267
+ * Thinking / chain-of-thought stream. DeepSeek + MiniMax native and
2268
+ * LiteLLM-normalized gateways use `reasoning_content`; OpenRouter (and some
2269
+ * Grok mirrors) use `reasoning`. Either must become `reasoning-delta` so
2270
+ * UIs are not stuck on a pre-text thinking spinner while the wire is live.
2271
+ */
2272
+ reasoning_content: optionalNull(Schema.String),
2273
+ reasoning: optionalNull(Schema.String),
2265
2274
  tool_calls: optionalNull(Schema.Array(OpenAIChatToolCallDelta))
2266
2275
  });
2267
2276
  var OpenAIChatChoice = Schema.Struct({
@@ -2418,16 +2427,17 @@ var mapUsage = (usage) => {
2418
2427
  providerMetadata: { openai: usage }
2419
2428
  });
2420
2429
  };
2421
- var normaliseTextDelta = (prev, incoming) => {
2422
- if (!incoming) return { emit: "", textAcc: prev };
2423
- if (incoming === prev) return { emit: "", textAcc: prev };
2424
- if (prev.length > 0 && incoming.startsWith(prev)) {
2425
- return { emit: incoming.slice(prev.length), textAcc: incoming };
2430
+ var normaliseTextDelta = (prev, incoming, mode = "unknown") => {
2431
+ if (!incoming) return { emit: "", textAcc: prev, mode };
2432
+ if (mode === "unknown") {
2433
+ if (prev.length === 0) return { emit: incoming, textAcc: incoming, mode };
2434
+ mode = incoming.length > prev.length && incoming.startsWith(prev) ? "cumulative" : "incremental";
2426
2435
  }
2427
- if (prev.length > 0 && prev.startsWith(incoming)) {
2428
- return { emit: "", textAcc: prev };
2436
+ if (mode === "cumulative") {
2437
+ if (incoming.startsWith(prev)) return { emit: incoming.slice(prev.length), textAcc: incoming, mode };
2438
+ if (prev.startsWith(incoming)) return { emit: "", textAcc: prev, mode };
2429
2439
  }
2430
- return { emit: incoming, textAcc: prev + incoming };
2440
+ return { emit: incoming, textAcc: prev + incoming, mode };
2431
2441
  };
2432
2442
  var step = (state, event) => Effect.gen(function* () {
2433
2443
  const events = [];
@@ -2438,9 +2448,15 @@ var step = (state, event) => Effect.gen(function* () {
2438
2448
  const toolDeltas = delta?.tool_calls ?? [];
2439
2449
  let tools = state.tools;
2440
2450
  let textAcc = state.textAcc;
2451
+ let textMode = state.textMode;
2452
+ const reasoningChunk = delta?.reasoning_content ?? delta?.reasoning;
2453
+ if (reasoningChunk) {
2454
+ events.push(LLMEvent.reasoningDelta({ id: "reasoning-0", text: reasoningChunk }));
2455
+ }
2441
2456
  if (delta?.content) {
2442
- const normalised = normaliseTextDelta(textAcc, delta.content);
2457
+ const normalised = normaliseTextDelta(textAcc, delta.content, textMode);
2443
2458
  textAcc = normalised.textAcc;
2459
+ textMode = normalised.mode;
2444
2460
  if (normalised.emit) {
2445
2461
  events.push(LLMEvent.textDelta({ id: "text-0", text: normalised.emit }));
2446
2462
  }
@@ -2464,7 +2480,8 @@ var step = (state, event) => Effect.gen(function* () {
2464
2480
  toolCallEvents: finished?.events ?? state.toolCallEvents,
2465
2481
  usage,
2466
2482
  finishReason,
2467
- textAcc
2483
+ textAcc,
2484
+ textMode
2468
2485
  },
2469
2486
  events
2470
2487
  ];
@@ -2485,7 +2502,8 @@ var protocol = protocol_exports.make({
2485
2502
  initial: () => ({
2486
2503
  tools: tool_stream_exports.empty(),
2487
2504
  toolCallEvents: [],
2488
- textAcc: ""
2505
+ textAcc: "",
2506
+ textMode: "unknown"
2489
2507
  }),
2490
2508
  step,
2491
2509
  onHalt: finishEvents