@blade-hq/agent-kit 1.0.17 → 1.0.18

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-5TKSNSAW.js";
4
+ } from "./chunk-TLB4ORQT.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"]);
@@ -117,4 +117,4 @@ export {
117
117
  resolveTextPreviewType,
118
118
  resolveSessionFilePreviewTarget
119
119
  };
120
- //# sourceMappingURL=chunk-CDOBBZKQ.js.map
120
+ //# sourceMappingURL=chunk-MKZ4VTJ2.js.map
@@ -3454,6 +3454,7 @@ var AgentSocket = class {
3454
3454
  joinedSessions = /* @__PURE__ */ new Set();
3455
3455
  requestedJoins = /* @__PURE__ */ new Set();
3456
3456
  pendingJoins = /* @__PURE__ */ new Map();
3457
+ recentChatEndAt = /* @__PURE__ */ new Map();
3457
3458
  boardProjectRefCounts = /* @__PURE__ */ new Map();
3458
3459
  patchFlushHandle = null;
3459
3460
  patchFlushCancel = null;
@@ -3621,6 +3622,7 @@ var AgentSocket = class {
3621
3622
  useChatStore.getState().markFailed(sessionId);
3622
3623
  }
3623
3624
  useChatStore.getState().setStreaming(sessionId, false);
3625
+ this.recentChatEndAt.set(sessionId, Date.now());
3624
3626
  invalidateContextStats(sessionId);
3625
3627
  void this._syncSessionTurnsFromHistory(sessionId);
3626
3628
  useRuntimeStore.getState().addEvent(sessionId, {
@@ -3646,6 +3648,7 @@ var AgentSocket = class {
3646
3648
  useSessionStore.getState().setErrorMessage(sessionId, message);
3647
3649
  useChatStore.getState().markFailed(sessionId);
3648
3650
  useChatStore.getState().setStreaming(sessionId, false);
3651
+ this.recentChatEndAt.set(sessionId, Date.now());
3649
3652
  useRuntimeStore.getState().addEvent(sessionId, {
3650
3653
  type: "system:error",
3651
3654
  title: "Runtime error",
@@ -4159,8 +4162,17 @@ var AgentSocket = class {
4159
4162
  _shouldWaitForJoinBeforeSend(sessionId) {
4160
4163
  return this.subscribedSession === sessionId || this.joinedSessions.has(sessionId) || this.pendingJoins.has(sessionId) || this.requestedJoins.has(sessionId);
4161
4164
  }
4162
- send(sessionId, message, mode, askuserAnswer, extras) {
4165
+ async send(sessionId, message, mode, askuserAnswer, extras) {
4163
4166
  this._ensureConnected();
4167
+ if (useChatStore.getState().isStreaming[sessionId]) {
4168
+ useChatStore.getState().addErrorMessage(sessionId, "\u5F53\u524D\u56DE\u590D\u5C1A\u672A\u7ED3\u675F\uFF0C\u8BF7\u7A0D\u540E\u518D\u53D1\u9001\u3002");
4169
+ return;
4170
+ }
4171
+ await this._ensureSessionIdleBeforeSend(sessionId);
4172
+ if (useChatStore.getState().isStreaming[sessionId]) {
4173
+ useChatStore.getState().addErrorMessage(sessionId, "\u5F53\u524D\u56DE\u590D\u5C1A\u672A\u7ED3\u675F\uFF0C\u8BF7\u7A0D\u540E\u518D\u53D1\u9001\u3002");
4174
+ return;
4175
+ }
4164
4176
  if (!(askuserAnswer && typeof askuserAnswer.tool_call_id === "string")) {
4165
4177
  useChatStore.getState().addUserMessage(sessionId, message);
4166
4178
  }
@@ -4217,6 +4229,24 @@ var AgentSocket = class {
4217
4229
  });
4218
4230
  }
4219
4231
  }
4232
+ async _ensureSessionIdleBeforeSend(sessionId) {
4233
+ const lastEndedAt = this.recentChatEndAt.get(sessionId) ?? 0;
4234
+ if (Date.now() - lastEndedAt > 3e3) {
4235
+ return;
4236
+ }
4237
+ const deadline = Date.now() + 3e3;
4238
+ while (Date.now() < deadline) {
4239
+ const response = await this.stop(sessionId);
4240
+ const status = String(response.status ?? "");
4241
+ if (status === "idle" || status === "done" || status === "interrupted") {
4242
+ return;
4243
+ }
4244
+ if (status !== "stopping") {
4245
+ return;
4246
+ }
4247
+ await new Promise((resolve) => globalThis.setTimeout(resolve, 150));
4248
+ }
4249
+ }
4220
4250
  /**
4221
4251
  * 在 agent loop 运行期间追加补充消息。
4222
4252
  * 消息会在下一轮 LLM 调用前以 user-supplement 形式注入。
@@ -4505,4 +4535,4 @@ export {
4505
4535
  bootstrapBladeClient,
4506
4536
  getBootstrappedClient
4507
4537
  };
4508
- //# sourceMappingURL=chunk-5TKSNSAW.js.map
4538
+ //# sourceMappingURL=chunk-TLB4ORQT.js.map