@blade-hq/agent-client 1.2.1-beta.9 → 2608.0.1

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.
@@ -16,7 +16,11 @@ export interface SessionRuntime {
16
16
  countFiles(sessionId: string, dirPath?: string): Promise<number>;
17
17
  downloadFile(sessionId: string, filePath: string, downloadName?: string): Promise<void>;
18
18
  attachAppCli(sessionId: string, definition: AppCliDefinition): Promise<AppCliAttachment>;
19
- onDispose(session: AgentSession): void;
19
+ /**
20
+ * 归还一份持有。返回 true 表示这是最后一份、实例可以真正释放;
21
+ * 返回 false 表示还有别的持有者,实例必须继续工作。
22
+ */
23
+ onDispose(session: AgentSession): boolean;
20
24
  }
21
25
  export interface AttachAppOptions {
22
26
  /** 可选;只需要页面上下文时无需提供 CLI。 */
@@ -123,7 +127,10 @@ export declare class AgentSession {
123
127
  countFiles(dirPath?: string): Promise<number>;
124
128
  /** 在浏览器中下载一个工作区文件。 */
125
129
  downloadFile(filePath: string, downloadName?: string): Promise<void>;
126
- /** 释放订阅与监听器。之后该实例不再接收任何事件。 */
130
+ /**
131
+ * 归还一份持有。同一个会话被多处 connect 时按引用计数释放:只有最后
132
+ * 一份归还才真正断开订阅与监听器,之前的归还不影响仍在使用的一方。
133
+ */
127
134
  dispose(): void;
128
135
  get isDisposed(): boolean;
129
136
  /** @internal 连接状态变化(同 client 下所有会话共享一条连接)。 */
@@ -9,6 +9,8 @@ export declare class SessionHub {
9
9
  private readonly client;
10
10
  private readonly sessions;
11
11
  private readonly bootstrapPending;
12
+ /** 每个会话当前有多少方持有(connect 一次 +1,dispose 一次 -1)。 */
13
+ private readonly holdCounts;
12
14
  private connection;
13
15
  private readonly connectionListeners;
14
16
  private bound;
@@ -18,7 +20,13 @@ export declare class SessionHub {
18
20
  getConnection(): ConnectionStatus;
19
21
  /** 订阅连接状态变化。 */
20
22
  onConnectionChange(listener: (status: ConnectionStatus) => void): () => void;
21
- /** 取得(或复用)一个会话的 AgentSession,并完成历史加载 + 房间订阅。 */
23
+ /**
24
+ * 取得(或复用)一个会话的 AgentSession,并完成历史加载 + 房间订阅。
25
+ *
26
+ * 每次调用都算一份持有,调用方用完必须 `dispose()` 归还。复用同一实例时
27
+ * 只有最后一份归还才退订房间——否则 StrictMode 双跑、路由抖动这类"连两次
28
+ * 只释放一次"的场景会把仍在用的会话退订掉,之后所有 turn/chat 事件静默丢失。
29
+ */
22
30
  connect(sessionId: string): Promise<AgentSession>;
23
31
  /** 已有实例则返回,不触发网络请求。 */
24
32
  peek(sessionId: string): AgentSession | undefined;
@@ -35,6 +43,15 @@ export declare class SessionHub {
35
43
  */
36
44
  _handleSocketReplaced(): void;
37
45
  private runtimeFor;
46
+ /** 记一份持有。 */
47
+ private hold;
48
+ /**
49
+ * 归还一份持有;还剩别的持有者时返回 false,让 AgentSession 保持可用。
50
+ * 归零才退订房间并从路由表移除。
51
+ */
52
+ private release;
53
+ /** 不管还有几方持有都立即释放(启动失败、切换身份)。 */
54
+ private forceRelease;
38
55
  private ensureConnected;
39
56
  private setConnection;
40
57
  /** 事件带 session_id 时精确路由;缺省时按当前唯一活跃会话兜底。 */
@@ -26,6 +26,15 @@ export declare function sourceLoopFor(loopId: string, loopDescriptions: Map<stri
26
26
  loop_name: string;
27
27
  description: string;
28
28
  } | null;
29
+ /**
30
+ * Shared by the streaming and history channels — both must decide "is this
31
+ * follow-up showable" identically. Returns null when there is nothing to show.
32
+ */
33
+ export declare function normalizePostChatFollowup(data: Record<string, unknown>, assistantEntryId: string): {
34
+ assistant_entry_id: string;
35
+ recaption: string;
36
+ suggestions: string[];
37
+ } | null;
29
38
  export declare function normalizeChildPause(pausePayload: Record<string, unknown>): {
30
39
  pauseToolData: Record<string, unknown>;
31
40
  childLoopName: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blade-hq/agent-client",
3
- "version": "1.2.1-beta.9",
3
+ "version": "2608.0.1",
4
4
  "description": "Blade Agent 框架无关客户端:会话实时状态机、REST 通道、弹窗登录、页面协作。浏览器与 Node.js 通用。",
5
5
  "repository": {
6
6
  "type": "git",