@blade-hq/agent-client 2610.0.0-beta.87 → 2610.0.0-beta.88

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/README.md CHANGED
@@ -85,6 +85,10 @@ new BladeClient({
85
85
  })
86
86
  ```
87
87
 
88
+ 高级宿主可通过 `BladeClientOptions.commandTransport(event, payload, send)` 接管带回执的命令传输,例如浏览器插件让后台持有发送请求,面板关闭后仍能等待请求结束并停止任务。返回原始服务端 ack,失败时抛错;不接管的命令调用 `send()` 使用默认 Socket.IO。事件订阅仍使用原 socket。`client.requestCommand(event, payload, timeoutMs)` 是同一通道的低层入口,普通应用继续使用类型化的 `AgentSession` 方法。
89
+
90
+ 底层 `createSocket` 允许指定 `transports`;MV3 service worker 没有 XMLHttpRequest,可使用 `["websocket"]`。不指定时保持 Socket.IO 默认选择。
91
+
88
92
  SDK 会固定订阅普通聊天所需的完整实时事件。产品内置 Web 的精简/开发者展示模式不属于
89
93
  公共 SDK 契约,也没有对应的构造参数或 Socket.IO 字段。
90
94
 
@@ -25,6 +25,8 @@ export interface BladeClientOptions {
25
25
  socketToken?: string | (() => string | null | undefined);
26
26
  /** login() 取得的令牌存放位置,默认 "local"(localStorage,刷新页面不掉登录)。 */
27
27
  tokenStorage?: TokenStorageMode;
28
+ /** Host-owned command transport; event subscriptions stay on the normal socket. */
29
+ commandTransport?: (event: string, payload: Record<string, unknown>, send: () => Promise<Record<string, unknown>>) => Promise<Record<string, unknown>>;
28
30
  fetchImpl?: typeof fetch;
29
31
  onRefreshSuccess?: () => void | Promise<void>;
30
32
  }
@@ -81,6 +83,7 @@ export declare class BladeClient {
81
83
  /** 底层 Socket.IO 实例因后端地址变化而被替换时通知高级集成层。 */
82
84
  onSocketReplaced(listener: () => void): () => void;
83
85
  socket(): TypedSocket;
86
+ requestCommand(event: string, payload: Record<string, unknown>, timeoutMs: number): Promise<Record<string, unknown>>;
84
87
  json<T>(method: HttpMethod, path: string, body?: unknown): Promise<T>;
85
88
  jsonFromInit<T>(path: string, init?: RequestInit): Promise<T>;
86
89
  text(method: HttpMethod, path: string): Promise<string>;
package/dist/index.js CHANGED
@@ -6096,16 +6096,7 @@ var SessionHub = class {
6096
6096
  ;
6097
6097
  this.client.socket().emit(event, data);
6098
6098
  },
6099
- emitWithAck: (event, data, timeoutMs) => new Promise((resolve, reject) => {
6100
- ;
6101
- this.client.socket().timeout(timeoutMs).emit(event, data, (err, response) => {
6102
- if (err) {
6103
- reject(err);
6104
- return;
6105
- }
6106
- resolve(response);
6107
- });
6108
- }),
6099
+ emitWithAck: (event, data, timeoutMs) => this.client.requestCommand(event, data, timeoutMs),
6109
6100
  ensureConnected: () => this.ensureConnected(),
6110
6101
  fetchTurnsPage: (sessionId, query, init) => this.client.sessions.getSessionTurnsPage(sessionId, query, init),
6111
6102
  fetchTurnIndex: (sessionId) => this.client.sessions.getSessionTurnIndex(sessionId),
@@ -6386,6 +6377,7 @@ function createSocket(options) {
6386
6377
  return io(options.baseUrl, {
6387
6378
  path: options.path ?? "/socket.io",
6388
6379
  withCredentials: true,
6380
+ ...options.transports ? { transports: options.transports } : {},
6389
6381
  query: token ? { token } : void 0,
6390
6382
  auth: typeof options.token === "function" ? (cb) => cb(buildSocketAuth(options) ?? {}) : buildSocketAuth(options) ?? {},
6391
6383
  autoConnect: false
@@ -6523,6 +6515,16 @@ var BladeClient = class {
6523
6515
  }
6524
6516
  return this.socketInstance;
6525
6517
  }
6518
+ requestCommand(event, payload, timeoutMs) {
6519
+ const send = () => new Promise((resolve, reject) => {
6520
+ ;
6521
+ this.socket().timeout(timeoutMs).emit(event, payload, (error, ack) => {
6522
+ if (error) reject(error);
6523
+ else resolve(ack ?? {});
6524
+ });
6525
+ });
6526
+ return this.options.commandTransport?.(event, payload, send) ?? send();
6527
+ }
6526
6528
  async json(method, path, body) {
6527
6529
  const response = await this.fetch(method, path, {
6528
6530
  body: body === void 0 ? void 0 : JSON.stringify(body),
@@ -6917,7 +6919,7 @@ function resolveServiceUrl(endpoints, name, path = "") {
6917
6919
 
6918
6920
  // src/version.ts
6919
6921
  var SDK_NAME = "agent-client";
6920
- var SDK_VERSION = true ? "2610.0.0-beta.87" : "1.1.1";
6922
+ var SDK_VERSION = true ? "2610.0.0-beta.88" : "1.1.1";
6921
6923
 
6922
6924
  // src/commands/protocol.ts
6923
6925
  function isCommandEnvelope(value) {