@blade-hq/agent-client 2610.0.0-beta.55 → 2610.0.0-beta.57

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.js CHANGED
@@ -3562,7 +3562,7 @@ function parseQueueAck(response, fallbackSessionId) {
3562
3562
  }
3563
3563
  const message = typeof response.message === "string" && response.message ? response.message : null;
3564
3564
  const status = response.status;
3565
- if (status !== "ok" && status !== "conflict") {
3565
+ if (status !== "ok" && status !== "conflict" && status !== "queued") {
3566
3566
  return { ok: false, conflict: false, snapshot: null, message: message ?? QUEUE_FAILURE_MESSAGE };
3567
3567
  }
3568
3568
  const snapshot2 = toQueueSnapshot(response, fallbackSessionId);
@@ -4647,7 +4647,7 @@ var AgentSession = class _AgentSession {
4647
4647
  /** 发送一条消息。字符串或多模态内容均可。 */
4648
4648
  async send(content, options = {}) {
4649
4649
  this.runtime.ensureConnected();
4650
- if (this.state.isStreaming || this.state.activeCompaction || this.sendPending || this.manualCompactionPending) {
4650
+ if (this.state.isStreaming && options.queueWhenRunning !== true || this.state.activeCompaction || this.sendPending || this.manualCompactionPending) {
4651
4651
  this.update(
4652
4652
  (s) => addErrorMessage(s, "\u5F53\u524D\u56DE\u590D\u5C1A\u672A\u7ED3\u675F\u6216\u5BF9\u8BDD\u6B63\u5728\u6574\u7406\uFF0C\u8BF7\u7A0D\u540E\u518D\u53D1\u9001\u3002")
4653
4653
  );
@@ -4752,7 +4752,7 @@ var AgentSession = class _AgentSession {
4752
4752
  }
4753
4753
  async sendUnlocked(content, options) {
4754
4754
  await this.ensureIdleBeforeSend();
4755
- if (this.state.isStreaming || this.state.activeCompaction || this.manualCompactionPending) {
4755
+ if (this.state.isStreaming && options.queueWhenRunning !== true || this.state.activeCompaction || this.manualCompactionPending) {
4756
4756
  this.update(
4757
4757
  (s) => addErrorMessage(s, "\u5F53\u524D\u56DE\u590D\u5C1A\u672A\u7ED3\u675F\u6216\u5BF9\u8BDD\u6B63\u5728\u6574\u7406\uFF0C\u8BF7\u7A0D\u540E\u518D\u53D1\u9001\u3002")
4758
4758
  );
@@ -4817,7 +4817,9 @@ var AgentSession = class _AgentSession {
4817
4817
  whatif: options.whatif,
4818
4818
  replay_decision: options.replayDecision,
4819
4819
  app_context: appContext,
4820
- kb_ids: options.kbIds && options.kbIds.length > 0 ? options.kbIds : void 0
4820
+ kb_ids: options.kbIds && options.kbIds.length > 0 ? options.kbIds : void 0,
4821
+ // 运行中提交不必由客户端挑命令:服务端按会话运行状态决定直接执行还是入队。
4822
+ queue_when_running: options.queueWhenRunning === true
4821
4823
  };
4822
4824
  try {
4823
4825
  await this.ensureJoined();
@@ -4833,6 +4835,21 @@ var AgentSession = class _AgentSession {
4833
4835
  }
4834
4836
  try {
4835
4837
  const response = await this.runtime.emitWithAck("chat:send", payload, 3e4);
4838
+ if (response?.status === "queued") {
4839
+ this.discardOptimisticSend(
4840
+ optimisticTurnId,
4841
+ askUserAnswer,
4842
+ optimisticAskAnswer,
4843
+ previousAskAnswer
4844
+ );
4845
+ const snapshot2 = parseQueueAck(response, this.sessionId).snapshot;
4846
+ const running = response.running === true;
4847
+ this.update((current) => {
4848
+ const next = running ? current : { ...current, isStreaming: false };
4849
+ return snapshot2 ? withQueue(next, snapshot2) : next;
4850
+ });
4851
+ return true;
4852
+ }
4836
4853
  if (response?.status !== "accepted") {
4837
4854
  throw new Error(
4838
4855
  typeof response?.message === "string" ? response.message : "\u6D88\u606F\u672A\u88AB\u670D\u52A1\u7AEF\u63A5\u53D7"
@@ -4851,6 +4868,16 @@ var AgentSession = class _AgentSession {
4851
4868
  }
4852
4869
  }
4853
4870
  rollbackOptimisticSend(optimisticTurnId, askUserAnswer, optimisticAskAnswer, previousAskAnswer, message) {
4871
+ this.discardOptimisticSend(
4872
+ optimisticTurnId,
4873
+ askUserAnswer,
4874
+ optimisticAskAnswer,
4875
+ previousAskAnswer
4876
+ );
4877
+ this.update((current) => addErrorMessage({ ...current, isStreaming: false }, message));
4878
+ }
4879
+ /** 撤回一次乐观提交:移除乐观消息、恢复提问作答、清掉回放草稿。 */
4880
+ discardOptimisticSend(optimisticTurnId, askUserAnswer, optimisticAskAnswer, previousAskAnswer) {
4854
4881
  this.pendingReplayMessage = null;
4855
4882
  this.pendingReplayMode = void 0;
4856
4883
  this.pendingReplayKbIds = void 0;
@@ -4869,7 +4896,7 @@ var AgentSession = class _AgentSession {
4869
4896
  }
4870
4897
  next = { ...next, askAnswers };
4871
4898
  }
4872
- return addErrorMessage({ ...next, isStreaming: false }, message);
4899
+ return next;
4873
4900
  });
4874
4901
  if (optimisticTurnId) {
4875
4902
  this.pendingOptimisticTurnIds.delete(optimisticTurnId);
@@ -5627,6 +5654,7 @@ var AgentSession = class _AgentSession {
5627
5654
  return join;
5628
5655
  }
5629
5656
  async ensureIdleBeforeSend() {
5657
+ if (this.state.isStreaming) return;
5630
5658
  if (Date.now() - this.recentChatEndAt > 3e3) return;
5631
5659
  const deadline = Date.now() + 3e3;
5632
5660
  while (Date.now() < deadline) {
@@ -6560,7 +6588,7 @@ function resolveServiceUrl(endpoints, name, path = "") {
6560
6588
 
6561
6589
  // src/version.ts
6562
6590
  var SDK_NAME = "agent-client";
6563
- var SDK_VERSION = true ? "2610.0.0-beta.55" : "1.1.1";
6591
+ var SDK_VERSION = true ? "2610.0.0-beta.57" : "1.1.1";
6564
6592
 
6565
6593
  // src/commands/protocol.ts
6566
6594
  function isCommandEnvelope(value) {