@blade-hq/agent-kit 0.5.21 → 0.5.22

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.
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  apiFetchResponse,
3
3
  getAuthedUrl
4
- } from "./chunk-RNSHL4GA.js";
4
+ } from "./chunk-CCMNSYPI.js";
5
5
 
6
6
  // src/react/lib/session-file-preview.ts
7
7
  var IMAGE_EXTS = /* @__PURE__ */ new Set(["png", "jpg", "jpeg", "gif", "svg", "webp", "ico", "bmp"]);
@@ -124,4 +124,4 @@ export {
124
124
  CollapsibleTrigger,
125
125
  CollapsibleContent
126
126
  };
127
- //# sourceMappingURL=chunk-YJ7GDLMH.js.map
127
+ //# sourceMappingURL=chunk-3YAZYX2V.js.map
@@ -248,6 +248,7 @@ function invalidateSkillStats(sessionId) {
248
248
  void queryClient.invalidateQueries({ queryKey: ["skill-stats", sessionId] });
249
249
  }
250
250
  var HOST_BRIDGE_ACTIONS = ["addContext", "appendInput", "sendMessage"];
251
+ var bridgeHandlers = /* @__PURE__ */ new Set();
251
252
  function isRecord2(value) {
252
253
  return typeof value === "object" && value !== null && !Array.isArray(value);
253
254
  }
@@ -277,13 +278,28 @@ function toBridgeActionEnvelope(value) {
277
278
  function isInsideIframe() {
278
279
  return typeof window !== "undefined" && window.parent !== window;
279
280
  }
281
+ function subscribeBladeBridge(handler) {
282
+ bridgeHandlers.add(handler);
283
+ return () => {
284
+ bridgeHandlers.delete(handler);
285
+ };
286
+ }
287
+ function dispatchBladeBridge(envelope) {
288
+ for (const handler of bridgeHandlers) {
289
+ try {
290
+ handler(envelope);
291
+ } catch (error) {
292
+ console.debug("[parent-bridge] bridge handler failed", error);
293
+ }
294
+ }
295
+ }
280
296
  function postToParent(envelope) {
281
297
  if (!isInsideIframe()) {
282
298
  return;
283
299
  }
284
300
  tapBridgeEvent({
285
301
  side: "agent",
286
- direction: "agent-to-host",
302
+ direction: envelope.direction,
287
303
  action: envelope.action,
288
304
  payload: envelope.payload,
289
305
  meta: envelope.meta
@@ -2240,6 +2256,17 @@ function isGisResourceListPayload(value) {
2240
2256
  function isGisTargetListPayload(value) {
2241
2257
  return isRecord4(value) && Array.isArray(value.targets);
2242
2258
  }
2259
+ function buildToolBridgeDeliveryKey(sessionId, turn, block) {
2260
+ const content = isToolBridgeContent(block.content) ? block.content : null;
2261
+ const action = content?.action ?? "";
2262
+ let payloadKey = "";
2263
+ try {
2264
+ payloadKey = JSON.stringify(content?.payload ?? null);
2265
+ } catch {
2266
+ payloadKey = String(content?.payload ?? "");
2267
+ }
2268
+ return [sessionId, block.tool_call_id ?? turn.id, action, payloadKey].join("\0");
2269
+ }
2243
2270
  var AgentSocket = class {
2244
2271
  constructor(client) {
2245
2272
  this.client = client;
@@ -2267,6 +2294,7 @@ var AgentSocket = class {
2267
2294
  socket;
2268
2295
  subscribedSession = null;
2269
2296
  previewArtifactsByToolCall = /* @__PURE__ */ new Map();
2297
+ deliveredBridgeKeys = /* @__PURE__ */ new Set();
2270
2298
  pendingReplayMessages = /* @__PURE__ */ new Map();
2271
2299
  pendingReplayModes = /* @__PURE__ */ new Map();
2272
2300
  oomNotifiedKeys = /* @__PURE__ */ new Set();
@@ -2630,7 +2658,12 @@ var AgentSocket = class {
2630
2658
  });
2631
2659
  continue;
2632
2660
  }
2633
- postToParent({
2661
+ const deliveryKey = buildToolBridgeDeliveryKey(sessionId, turn, block);
2662
+ if (this.deliveredBridgeKeys.has(deliveryKey)) {
2663
+ continue;
2664
+ }
2665
+ this.deliveredBridgeKeys.add(deliveryKey);
2666
+ const envelope = {
2634
2667
  __bladeBridge: true,
2635
2668
  direction: "agent-to-host",
2636
2669
  action: block.content.action,
@@ -2640,7 +2673,9 @@ var AgentSocket = class {
2640
2673
  ...block.tool_call_id ? { toolCallId: block.tool_call_id } : {},
2641
2674
  timestamp: Date.now()
2642
2675
  }
2643
- });
2676
+ };
2677
+ dispatchBladeBridge(envelope);
2678
+ postToParent(envelope);
2644
2679
  continue;
2645
2680
  }
2646
2681
  if (block.type !== "tool_ui" || !block.tool_call_id || !isUiMeta(block.content)) {
@@ -2741,6 +2776,7 @@ var AgentSocket = class {
2741
2776
  this.subscribedSession = sessionId;
2742
2777
  if (!isSameSession) {
2743
2778
  this.previewArtifactsByToolCall.clear();
2779
+ this.deliveredBridgeKeys.clear();
2744
2780
  useUiStore.getState().clearArtifacts();
2745
2781
  useCardStateStore.getState().clearAllStates();
2746
2782
  }
@@ -2757,6 +2793,7 @@ var AgentSocket = class {
2757
2793
  this.pendingJoins.delete(previousSessionId);
2758
2794
  }
2759
2795
  this.previewArtifactsByToolCall.clear();
2796
+ this.deliveredBridgeKeys.clear();
2760
2797
  }
2761
2798
  /**
2762
2799
  * 附加订阅:仅把当前 sid 加进 sessionId 的 room,不切 subscribedSession,
@@ -3085,6 +3122,9 @@ export {
3085
3122
  useUiBridgeStore,
3086
3123
  resourceBridgeDispatch,
3087
3124
  isInsideIframe,
3125
+ subscribeBladeBridge,
3126
+ dispatchBladeBridge,
3127
+ postToParent,
3088
3128
  attachHostBridgeListener,
3089
3129
  getTextContent,
3090
3130
  isHiddenInternalMessage,
@@ -3141,4 +3181,4 @@ export {
3141
3181
  bootstrapBladeClient,
3142
3182
  getBootstrappedClient
3143
3183
  };
3144
- //# sourceMappingURL=chunk-RNSHL4GA.js.map
3184
+ //# sourceMappingURL=chunk-CCMNSYPI.js.map