@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.
@@ -2179,6 +2179,14 @@ var OpenAIChatToolCallDelta = effect$1.Schema.Struct({
2179
2179
  });
2180
2180
  var OpenAIChatDelta = effect$1.Schema.Struct({
2181
2181
  content: optionalNull(effect$1.Schema.String),
2182
+ /**
2183
+ * Thinking / chain-of-thought stream. DeepSeek + MiniMax native and
2184
+ * LiteLLM-normalized gateways use `reasoning_content`; OpenRouter (and some
2185
+ * Grok mirrors) use `reasoning`. Either must become `reasoning-delta` so
2186
+ * UIs are not stuck on a pre-text thinking spinner while the wire is live.
2187
+ */
2188
+ reasoning_content: optionalNull(effect$1.Schema.String),
2189
+ reasoning: optionalNull(effect$1.Schema.String),
2182
2190
  tool_calls: optionalNull(effect$1.Schema.Array(OpenAIChatToolCallDelta))
2183
2191
  });
2184
2192
  var OpenAIChatChoice = effect$1.Schema.Struct({
@@ -2335,16 +2343,17 @@ var mapUsage = (usage) => {
2335
2343
  providerMetadata: { openai: usage }
2336
2344
  });
2337
2345
  };
2338
- var normaliseTextDelta = (prev, incoming) => {
2339
- if (!incoming) return { emit: "", textAcc: prev };
2340
- if (incoming === prev) return { emit: "", textAcc: prev };
2341
- if (prev.length > 0 && incoming.startsWith(prev)) {
2342
- return { emit: incoming.slice(prev.length), textAcc: incoming };
2346
+ var normaliseTextDelta = (prev, incoming, mode = "unknown") => {
2347
+ if (!incoming) return { emit: "", textAcc: prev, mode };
2348
+ if (mode === "unknown") {
2349
+ if (prev.length === 0) return { emit: incoming, textAcc: incoming, mode };
2350
+ mode = incoming.length > prev.length && incoming.startsWith(prev) ? "cumulative" : "incremental";
2343
2351
  }
2344
- if (prev.length > 0 && prev.startsWith(incoming)) {
2345
- return { emit: "", textAcc: prev };
2352
+ if (mode === "cumulative") {
2353
+ if (incoming.startsWith(prev)) return { emit: incoming.slice(prev.length), textAcc: incoming, mode };
2354
+ if (prev.startsWith(incoming)) return { emit: "", textAcc: prev, mode };
2346
2355
  }
2347
- return { emit: incoming, textAcc: prev + incoming };
2356
+ return { emit: incoming, textAcc: prev + incoming, mode };
2348
2357
  };
2349
2358
  var step = (state, event) => effect$1.Effect.gen(function* () {
2350
2359
  const events = [];
@@ -2355,9 +2364,15 @@ var step = (state, event) => effect$1.Effect.gen(function* () {
2355
2364
  const toolDeltas = delta?.tool_calls ?? [];
2356
2365
  let tools = state.tools;
2357
2366
  let textAcc = state.textAcc;
2367
+ let textMode = state.textMode;
2368
+ const reasoningChunk = delta?.reasoning_content ?? delta?.reasoning;
2369
+ if (reasoningChunk) {
2370
+ events.push(LLMEvent.reasoningDelta({ id: "reasoning-0", text: reasoningChunk }));
2371
+ }
2358
2372
  if (delta?.content) {
2359
- const normalised = normaliseTextDelta(textAcc, delta.content);
2373
+ const normalised = normaliseTextDelta(textAcc, delta.content, textMode);
2360
2374
  textAcc = normalised.textAcc;
2375
+ textMode = normalised.mode;
2361
2376
  if (normalised.emit) {
2362
2377
  events.push(LLMEvent.textDelta({ id: "text-0", text: normalised.emit }));
2363
2378
  }
@@ -2381,7 +2396,8 @@ var step = (state, event) => effect$1.Effect.gen(function* () {
2381
2396
  toolCallEvents: finished?.events ?? state.toolCallEvents,
2382
2397
  usage,
2383
2398
  finishReason,
2384
- textAcc
2399
+ textAcc,
2400
+ textMode
2385
2401
  },
2386
2402
  events
2387
2403
  ];
@@ -2402,7 +2418,8 @@ var protocol = protocol_exports.make({
2402
2418
  initial: () => ({
2403
2419
  tools: tool_stream_exports.empty(),
2404
2420
  toolCallEvents: [],
2405
- textAcc: ""
2421
+ textAcc: "",
2422
+ textMode: "unknown"
2406
2423
  }),
2407
2424
  step,
2408
2425
  onHalt: finishEvents