@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.
@@ -40,6 +40,7 @@ __export(openai_chat_exports, {
40
40
  bodyFields: () => bodyFields,
41
41
  httpTransport: () => httpTransport,
42
42
  model: () => model2,
43
+ normaliseTextDelta: () => normaliseTextDelta,
43
44
  protocol: () => protocol,
44
45
  route: () => route
45
46
  });
@@ -2184,6 +2185,14 @@ var OpenAIChatToolCallDelta = effect$1.Schema.Struct({
2184
2185
  });
2185
2186
  var OpenAIChatDelta = effect$1.Schema.Struct({
2186
2187
  content: optionalNull(effect$1.Schema.String),
2188
+ /**
2189
+ * Thinking / chain-of-thought stream. DeepSeek + MiniMax native and
2190
+ * LiteLLM-normalized gateways use `reasoning_content`; OpenRouter (and some
2191
+ * Grok mirrors) use `reasoning`. Either must become `reasoning-delta` so
2192
+ * UIs are not stuck on a pre-text thinking spinner while the wire is live.
2193
+ */
2194
+ reasoning_content: optionalNull(effect$1.Schema.String),
2195
+ reasoning: optionalNull(effect$1.Schema.String),
2187
2196
  tool_calls: optionalNull(effect$1.Schema.Array(OpenAIChatToolCallDelta))
2188
2197
  });
2189
2198
  var OpenAIChatChoice = effect$1.Schema.Struct({
@@ -2340,16 +2349,17 @@ var mapUsage = (usage) => {
2340
2349
  providerMetadata: { openai: usage }
2341
2350
  });
2342
2351
  };
2343
- var normaliseTextDelta = (prev, incoming) => {
2344
- if (!incoming) return { emit: "", textAcc: prev };
2345
- if (incoming === prev) return { emit: "", textAcc: prev };
2346
- if (prev.length > 0 && incoming.startsWith(prev)) {
2347
- return { emit: incoming.slice(prev.length), textAcc: incoming };
2352
+ var normaliseTextDelta = (prev, incoming, mode = "unknown") => {
2353
+ if (!incoming) return { emit: "", textAcc: prev, mode };
2354
+ if (mode === "unknown") {
2355
+ if (prev.length === 0) return { emit: incoming, textAcc: incoming, mode };
2356
+ mode = incoming.length > prev.length && incoming.startsWith(prev) ? "cumulative" : "incremental";
2348
2357
  }
2349
- if (prev.length > 0 && prev.startsWith(incoming)) {
2350
- return { emit: "", textAcc: prev };
2358
+ if (mode === "cumulative") {
2359
+ if (incoming.startsWith(prev)) return { emit: incoming.slice(prev.length), textAcc: incoming, mode };
2360
+ if (prev.startsWith(incoming)) return { emit: "", textAcc: prev, mode };
2351
2361
  }
2352
- return { emit: incoming, textAcc: prev + incoming };
2362
+ return { emit: incoming, textAcc: prev + incoming, mode };
2353
2363
  };
2354
2364
  var step = (state, event) => effect$1.Effect.gen(function* () {
2355
2365
  const events = [];
@@ -2360,9 +2370,15 @@ var step = (state, event) => effect$1.Effect.gen(function* () {
2360
2370
  const toolDeltas = delta?.tool_calls ?? [];
2361
2371
  let tools = state.tools;
2362
2372
  let textAcc = state.textAcc;
2373
+ let textMode = state.textMode;
2374
+ const reasoningChunk = delta?.reasoning_content ?? delta?.reasoning;
2375
+ if (reasoningChunk) {
2376
+ events.push(LLMEvent.reasoningDelta({ id: "reasoning-0", text: reasoningChunk }));
2377
+ }
2363
2378
  if (delta?.content) {
2364
- const normalised = normaliseTextDelta(textAcc, delta.content);
2379
+ const normalised = normaliseTextDelta(textAcc, delta.content, textMode);
2365
2380
  textAcc = normalised.textAcc;
2381
+ textMode = normalised.mode;
2366
2382
  if (normalised.emit) {
2367
2383
  events.push(LLMEvent.textDelta({ id: "text-0", text: normalised.emit }));
2368
2384
  }
@@ -2386,7 +2402,8 @@ var step = (state, event) => effect$1.Effect.gen(function* () {
2386
2402
  toolCallEvents: finished?.events ?? state.toolCallEvents,
2387
2403
  usage,
2388
2404
  finishReason,
2389
- textAcc
2405
+ textAcc,
2406
+ textMode
2390
2407
  },
2391
2408
  events
2392
2409
  ];
@@ -2407,7 +2424,8 @@ var protocol = protocol_exports.make({
2407
2424
  initial: () => ({
2408
2425
  tools: tool_stream_exports.empty(),
2409
2426
  toolCallEvents: [],
2410
- textAcc: ""
2427
+ textAcc: "",
2428
+ textMode: "unknown"
2411
2429
  }),
2412
2430
  step,
2413
2431
  onHalt: finishEvents
@@ -2437,6 +2455,7 @@ exports.PATH = PATH;
2437
2455
  exports.bodyFields = bodyFields;
2438
2456
  exports.httpTransport = httpTransport;
2439
2457
  exports.model = model2;
2458
+ exports.normaliseTextDelta = normaliseTextDelta;
2440
2459
  exports.protocol = protocol;
2441
2460
  exports.route = route;
2442
2461
  //# sourceMappingURL=openai-chat.cjs.map