@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.
@@ -2157,6 +2157,14 @@ var OpenAIChatToolCallDelta = Schema.Struct({
2157
2157
  });
2158
2158
  var OpenAIChatDelta = Schema.Struct({
2159
2159
  content: optionalNull(Schema.String),
2160
+ /**
2161
+ * Thinking / chain-of-thought stream. DeepSeek + MiniMax native and
2162
+ * LiteLLM-normalized gateways use `reasoning_content`; OpenRouter (and some
2163
+ * Grok mirrors) use `reasoning`. Either must become `reasoning-delta` so
2164
+ * UIs are not stuck on a pre-text thinking spinner while the wire is live.
2165
+ */
2166
+ reasoning_content: optionalNull(Schema.String),
2167
+ reasoning: optionalNull(Schema.String),
2160
2168
  tool_calls: optionalNull(Schema.Array(OpenAIChatToolCallDelta))
2161
2169
  });
2162
2170
  var OpenAIChatChoice = Schema.Struct({
@@ -2313,16 +2321,17 @@ var mapUsage = (usage) => {
2313
2321
  providerMetadata: { openai: usage }
2314
2322
  });
2315
2323
  };
2316
- var normaliseTextDelta = (prev, incoming) => {
2317
- if (!incoming) return { emit: "", textAcc: prev };
2318
- if (incoming === prev) return { emit: "", textAcc: prev };
2319
- if (prev.length > 0 && incoming.startsWith(prev)) {
2320
- return { emit: incoming.slice(prev.length), textAcc: incoming };
2324
+ var normaliseTextDelta = (prev, incoming, mode = "unknown") => {
2325
+ if (!incoming) return { emit: "", textAcc: prev, mode };
2326
+ if (mode === "unknown") {
2327
+ if (prev.length === 0) return { emit: incoming, textAcc: incoming, mode };
2328
+ mode = incoming.length > prev.length && incoming.startsWith(prev) ? "cumulative" : "incremental";
2321
2329
  }
2322
- if (prev.length > 0 && prev.startsWith(incoming)) {
2323
- return { emit: "", textAcc: prev };
2330
+ if (mode === "cumulative") {
2331
+ if (incoming.startsWith(prev)) return { emit: incoming.slice(prev.length), textAcc: incoming, mode };
2332
+ if (prev.startsWith(incoming)) return { emit: "", textAcc: prev, mode };
2324
2333
  }
2325
- return { emit: incoming, textAcc: prev + incoming };
2334
+ return { emit: incoming, textAcc: prev + incoming, mode };
2326
2335
  };
2327
2336
  var step = (state, event) => Effect.gen(function* () {
2328
2337
  const events = [];
@@ -2333,9 +2342,15 @@ var step = (state, event) => Effect.gen(function* () {
2333
2342
  const toolDeltas = delta?.tool_calls ?? [];
2334
2343
  let tools = state.tools;
2335
2344
  let textAcc = state.textAcc;
2345
+ let textMode = state.textMode;
2346
+ const reasoningChunk = delta?.reasoning_content ?? delta?.reasoning;
2347
+ if (reasoningChunk) {
2348
+ events.push(LLMEvent.reasoningDelta({ id: "reasoning-0", text: reasoningChunk }));
2349
+ }
2336
2350
  if (delta?.content) {
2337
- const normalised = normaliseTextDelta(textAcc, delta.content);
2351
+ const normalised = normaliseTextDelta(textAcc, delta.content, textMode);
2338
2352
  textAcc = normalised.textAcc;
2353
+ textMode = normalised.mode;
2339
2354
  if (normalised.emit) {
2340
2355
  events.push(LLMEvent.textDelta({ id: "text-0", text: normalised.emit }));
2341
2356
  }
@@ -2359,7 +2374,8 @@ var step = (state, event) => Effect.gen(function* () {
2359
2374
  toolCallEvents: finished?.events ?? state.toolCallEvents,
2360
2375
  usage,
2361
2376
  finishReason,
2362
- textAcc
2377
+ textAcc,
2378
+ textMode
2363
2379
  },
2364
2380
  events
2365
2381
  ];
@@ -2380,7 +2396,8 @@ var protocol = protocol_exports.make({
2380
2396
  initial: () => ({
2381
2397
  tools: tool_stream_exports.empty(),
2382
2398
  toolCallEvents: [],
2383
- textAcc: ""
2399
+ textAcc: "",
2400
+ textMode: "unknown"
2384
2401
  }),
2385
2402
  step,
2386
2403
  onHalt: finishEvents