@flutchai/flutch-sdk 0.7.11 → 0.7.12

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.cjs CHANGED
@@ -5202,6 +5202,45 @@ function sanitizeTraceError(error, options) {
5202
5202
  };
5203
5203
  }
5204
5204
  __name(sanitizeTraceError, "sanitizeTraceError");
5205
+
5206
+ // src/engines/langgraph/stream-thinking.ts
5207
+ function splitThinking(blocks) {
5208
+ const thoughts = [];
5209
+ const rest = [];
5210
+ for (const block of blocks) {
5211
+ const part = block;
5212
+ if (part?.type === "thinking" || part?.type === "reasoning") {
5213
+ const text = part.type === "thinking" ? part.thinking : part.reasoning;
5214
+ if (typeof text === "string" && text) thoughts.push({
5215
+ text,
5216
+ index: part.index
5217
+ });
5218
+ continue;
5219
+ }
5220
+ rest.push(block);
5221
+ }
5222
+ return {
5223
+ thoughts,
5224
+ rest
5225
+ };
5226
+ }
5227
+ __name(splitThinking, "splitThinking");
5228
+ function thinkingTexts(state, runId, deltas) {
5229
+ const out = [];
5230
+ for (const delta of deltas) {
5231
+ const another = runId !== state.runId || state.index !== void 0 && delta.index !== state.index;
5232
+ out.push(state.shown && another ? `
5233
+
5234
+ ${delta.text}` : delta.text);
5235
+ state.runId = runId;
5236
+ state.index = delta.index;
5237
+ state.shown = true;
5238
+ }
5239
+ return out;
5240
+ }
5241
+ __name(thinkingTexts, "thinkingTexts");
5242
+
5243
+ // src/engines/langgraph/event-processor.utils.ts
5205
5244
  function _ts_decorate21(decorators, target, key, desc) {
5206
5245
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
5207
5246
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -5509,7 +5548,21 @@ exports.EventProcessor = class _EventProcessor {
5509
5548
  const chunk = event.data.chunk;
5510
5549
  const blocks = [];
5511
5550
  if (chunk.content) {
5512
- blocks.push(...this.normalizeContentBlocks(chunk.content));
5551
+ const { thoughts, rest } = splitThinking(this.normalizeContentBlocks(chunk.content));
5552
+ blocks.push(...rest);
5553
+ if (thoughts.length && event.metadata?.stream_thinking === true) {
5554
+ acc.thinking ??= {
5555
+ runId: null,
5556
+ index: void 0,
5557
+ shown: false
5558
+ };
5559
+ for (const text of thinkingTexts(acc.thinking, event.run_id ?? null, thoughts)) this.processContentStream(acc, StreamChannel.PROCESSING, [
5560
+ {
5561
+ type: "text",
5562
+ text
5563
+ }
5564
+ ], onPartial);
5565
+ }
5513
5566
  }
5514
5567
  const contentHasToolBlocks = blocks.some((block) => block?.type === "tool_use" || block?.type === "tool_call" || block?.type === "input_json_delta");
5515
5568
  if (!contentHasToolBlocks && Array.isArray(chunk.tool_call_chunks) && chunk.tool_call_chunks.length > 0) {