@flutchai/flutch-sdk 0.7.12 → 0.7.14

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
@@ -5297,6 +5297,31 @@ exports.EventProcessor = class _EventProcessor {
5297
5297
  }
5298
5298
  logger = new common.Logger(_EventProcessor.name);
5299
5299
  /**
5300
+ * Sets a call's label on its `tool_use` block and tells the client. The block is the call's by id, else the latest
5301
+ * block of that tool with no label (a block opened from a model that gave no id, or by name at on_tool_start).
5302
+ */
5303
+ labelToolBlock(acc, channel, data, onPartial) {
5304
+ const state = acc.channels.get(channel);
5305
+ if (!state) return;
5306
+ const blocks = [
5307
+ ...state.contentChain,
5308
+ ...state.currentBlock ? [
5309
+ state.currentBlock
5310
+ ] : []
5311
+ ].filter((b) => b.type === "tool_use");
5312
+ const block = (data.id ? blocks.find((b) => b.id === data.id) : void 0) ?? [
5313
+ ...blocks
5314
+ ].reverse().find((b) => b.name === data.name && !b.labelled);
5315
+ if (!block) return;
5316
+ block.label = String(data.label);
5317
+ block.labelled = true;
5318
+ this.sendDelta(channel, {
5319
+ type: "tool_label",
5320
+ stepId: block.id,
5321
+ label: block.label
5322
+ }, onPartial);
5323
+ }
5324
+ /**
5300
5325
  * Create new accumulator for a stream
5301
5326
  */
5302
5327
  createAccumulator() {
@@ -5418,20 +5443,24 @@ exports.EventProcessor = class _EventProcessor {
5418
5443
  /**
5419
5444
  * Process content stream blocks (universal for all channels)
5420
5445
  */
5421
- processContentStream(acc, channel, blocks, onPartial) {
5446
+ processContentStream(acc, channel, blocks, onPartial, titles) {
5422
5447
  const state = acc.channels.get(channel);
5423
5448
  for (const block of blocks) {
5424
5449
  if (block.type === "tool_use" || block.type === "tool_call") {
5425
5450
  if (state.currentBlock) {
5426
5451
  state.contentChain.push(state.currentBlock);
5427
5452
  }
5453
+ const title = titles?.[String(block.name)];
5428
5454
  state.currentBlock = {
5429
5455
  index: state.contentChain.length,
5430
5456
  type: "tool_use",
5431
5457
  name: block.name,
5432
5458
  id: block.id,
5433
5459
  input: block.input || "",
5434
- output: ""
5460
+ output: "",
5461
+ ...typeof title === "string" && title ? {
5462
+ label: title
5463
+ } : {}
5435
5464
  };
5436
5465
  state.pendingToolBlocks.push(state.currentBlock);
5437
5466
  this.sendDelta(channel, {
@@ -5526,6 +5555,28 @@ exports.EventProcessor = class _EventProcessor {
5526
5555
  const blocks = this.normalizeContentBlocks(event.data.content);
5527
5556
  this.processContentStream(acc, channel, blocks, onPartial);
5528
5557
  }
5558
+ if (event.name === "tool_label" && event.data.label) {
5559
+ this.labelToolBlock(acc, channel, event.data, onPartial);
5560
+ }
5561
+ if (event.name === "update_attachment" && event.data.id) {
5562
+ const target = acc.attachments.find((a) => a.id === event.data.id);
5563
+ const patch = event.data.patch ?? {};
5564
+ if (target) {
5565
+ if (patch.value && typeof patch.value === "object") target.value = {
5566
+ ...target.value ?? {},
5567
+ ...patch.value
5568
+ };
5569
+ if (patch.metadata && typeof patch.metadata === "object") target.metadata = {
5570
+ ...target.metadata ?? {},
5571
+ ...patch.metadata
5572
+ };
5573
+ this.sendDelta(channel, {
5574
+ type: "attachment_updated",
5575
+ id: event.data.id,
5576
+ patch
5577
+ }, onPartial);
5578
+ }
5579
+ }
5529
5580
  if (event.name === "send_attachments" && event.data.attachments) {
5530
5581
  const attachments = event.data.attachments || [];
5531
5582
  acc.attachments = [
@@ -5569,7 +5620,7 @@ exports.EventProcessor = class _EventProcessor {
5569
5620
  blocks.push(...this.toolCallChunksToBlocks(chunk.tool_call_chunks));
5570
5621
  }
5571
5622
  if (blocks.length > 0) {
5572
- this.processContentStream(acc, channel, blocks, onPartial);
5623
+ this.processContentStream(acc, channel, blocks, onPartial, event.metadata?.tool_titles);
5573
5624
  }
5574
5625
  return;
5575
5626
  }
@@ -6399,6 +6450,21 @@ async function dispatchAttachments(attachments, config) {
6399
6450
  }, config);
6400
6451
  }
6401
6452
  __name(dispatchAttachments, "dispatchAttachments");
6453
+ async function dispatchToolLabel(call, label, config) {
6454
+ await dispatch.dispatchCustomEvent("tool_label", {
6455
+ id: call.id,
6456
+ name: call.name,
6457
+ label
6458
+ }, config);
6459
+ }
6460
+ __name(dispatchToolLabel, "dispatchToolLabel");
6461
+ async function dispatchAttachmentUpdate(id, patch, config) {
6462
+ await dispatch.dispatchCustomEvent("update_attachment", {
6463
+ id,
6464
+ patch
6465
+ }, config);
6466
+ }
6467
+ __name(dispatchAttachmentUpdate, "dispatchAttachmentUpdate");
6402
6468
 
6403
6469
  // src/core/universal-graph.module.ts
6404
6470
  init_builder_registry_service();
@@ -9371,7 +9437,9 @@ exports.createMongoClientAdapter = createMongoClientAdapter;
9371
9437
  exports.createStaticMessage = createStaticMessage;
9372
9438
  exports.createToolSearchTool = createToolSearchTool;
9373
9439
  exports.decryptTokens = decryptTokens;
9440
+ exports.dispatchAttachmentUpdate = dispatchAttachmentUpdate;
9374
9441
  exports.dispatchAttachments = dispatchAttachments;
9442
+ exports.dispatchToolLabel = dispatchToolLabel;
9375
9443
  exports.encryptTokens = encryptTokens;
9376
9444
  exports.executeToolWithAttachments = executeToolWithAttachments;
9377
9445
  exports.extractThinking = extractThinking;