@blade-hq/agent-client 2610.0.0-beta.2 → 2610.0.0-beta.21

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.
@@ -0,0 +1,14 @@
1
+ export declare const PLATFORM_SERVICE_NAMES: readonly ["os", "hub", "agent", "oauth", "llmGateway", "gitea", "tile"];
2
+ export type PlatformServiceName = (typeof PLATFORM_SERVICE_NAMES)[number];
3
+ export interface PlatformEndpoints {
4
+ services: Partial<Record<PlatformServiceName, string>>;
5
+ }
6
+ export declare const EMPTY_PLATFORM_ENDPOINTS: PlatformEndpoints;
7
+ export interface LoadPlatformEndpointsOptions {
8
+ baseUrl?: string;
9
+ fetchImpl?: typeof fetch;
10
+ timeoutMs?: number;
11
+ }
12
+ export declare function parsePlatformEndpoints(value: unknown): PlatformEndpoints | null;
13
+ export declare function loadPlatformEndpoints(options?: LoadPlatformEndpointsOptions): Promise<PlatformEndpoints>;
14
+ export declare function resolveServiceUrl(endpoints: PlatformEndpoints, name: PlatformServiceName, path?: string): string | null;
@@ -0,0 +1,34 @@
1
+ export type ContextAction = "published" | "retained" | "removed";
2
+ /** Safe display-source metadata retained for headless consumers. */
3
+ export type ContextSourceInfo = Record<string, unknown>;
4
+ export interface ContextProjectionData {
5
+ context_kind: string;
6
+ context_key: string;
7
+ context_name: string;
8
+ context_order: number;
9
+ context_action: ContextAction;
10
+ context_revision: string;
11
+ display_title?: string | null;
12
+ display_summary?: string | null;
13
+ sources: ContextSourceInfo[];
14
+ }
15
+ export interface ContextProjectionFields {
16
+ context_kind?: string | null;
17
+ context_key?: string | null;
18
+ context_name?: string | null;
19
+ context_order?: number | null;
20
+ context_action?: ContextAction | null;
21
+ context_revision?: string | null;
22
+ display_title?: string | null;
23
+ display_summary?: string | null;
24
+ sources?: ContextSourceInfo[] | null;
25
+ }
26
+ export interface ContextDisplayState {
27
+ title: string;
28
+ summary: string;
29
+ detail: string;
30
+ isRemoved: boolean;
31
+ }
32
+ export declare function contextProjectionData(fields: ContextProjectionFields): ContextProjectionData | null;
33
+ /** The single status-to-display mapping used by both React chat surfaces. */
34
+ export declare function getContextDisplayState(context: ContextProjectionData): ContextDisplayState;
@@ -11,6 +11,15 @@ export interface ToolCallCreated {
11
11
  arguments: string;
12
12
  };
13
13
  }
14
+ export interface ToolCallArgumentsDelta {
15
+ index: number;
16
+ id: string;
17
+ loop_name?: string;
18
+ function: {
19
+ name: string;
20
+ };
21
+ arguments_delta: string;
22
+ }
14
23
  export interface ToolResultDone {
15
24
  tool_call_id: string;
16
25
  loop_name?: string;
@@ -1,4 +1,5 @@
1
1
  import type { ContentBlock, PendingQuestionRef, ToolBridgeContent } from "./projection";
2
+ import type { ContextProjectionData } from "./context";
2
3
  export interface TextContentPart {
3
4
  type: "text";
4
5
  text: string;
@@ -70,6 +71,8 @@ export interface ChatMessage {
70
71
  duration_ms?: number;
71
72
  timestamp?: string;
72
73
  entry_id?: string;
74
+ /** Stable React key retained when an optimistic user message is confirmed. */
75
+ render_id?: string;
73
76
  parent_id?: string | null;
74
77
  loop_name?: string;
75
78
  /** Entry kind from backend -- present for non-message entries like mode changes. */
@@ -80,4 +83,6 @@ export interface ChatMessage {
80
83
  blocks?: ContentBlock[];
81
84
  /** Compaction metadata for compaction turns. */
82
85
  compaction?: CompactionInfo;
86
+ /** Sourced Context metadata for rendering or headless consumers. */
87
+ context?: ContextProjectionData;
83
88
  }
@@ -47,7 +47,7 @@ export interface TurnProjection {
47
47
  sequence: number;
48
48
  turn_id: string;
49
49
  loop_id: string;
50
- kind?: "message" | "compaction";
50
+ kind?: "message" | "context" | "compaction";
51
51
  role: "user" | "assistant" | "system";
52
52
  status: "streaming" | "completed" | "paused" | "failed" | "interrupted";
53
53
  blocks: ContentBlock[];
@@ -59,6 +59,17 @@ export interface TurnProjection {
59
59
  context_window?: number;
60
60
  memory_refs?: MemoryRef[] | null;
61
61
  parent_fork_tool_call_id?: string | null;
62
+ context_kind?: string | null;
63
+ context_key?: string | null;
64
+ context_name?: string | null;
65
+ context_order?: number | null;
66
+ context_action?: import("./context").ContextAction | null;
67
+ context_revision?: string | null;
68
+ display_title?: string | null;
69
+ display_summary?: string | null;
70
+ sources?: import("./context").ContextSourceInfo[] | null;
71
+ /** Client-only stable identity for reconciling an optimistic user turn. */
72
+ client_render_id?: string | null;
62
73
  compaction_id?: string | null;
63
74
  summary_preview?: string | null;
64
75
  summary_full?: string | null;
@@ -53,6 +53,8 @@ export interface SendOptions {
53
53
  deprecate_entry_ids: string[];
54
54
  };
55
55
  replayDecision?: "keep_replay" | "continue_replay";
56
+ /** 用户 @ 的知识库 id:后端先用原话在这些库里预检索,本轮 kb_search 也默认限定在这些库。 */
57
+ kbIds?: number[];
56
58
  }
57
59
  export declare function sessionStatusFromChatEnd(status: string | undefined): SessionStatus;
58
60
  /**
@@ -1,10 +1,12 @@
1
1
  import type { ChatMessage, CompactionInfo, MessageContent } from "../schemas/message";
2
2
  import type { ContentBlock, PatchEnvelope, TurnProjection } from "../schemas/projection";
3
3
  import type { ReplaySpeed, ReplayState, SessionStatus } from "../schemas/session";
4
- /** 一次 AskUserQuestion 的用户作答(选项选择 + 自定义输入)。 */
4
+ /** 一次 AskUserQuestion 的用户作答(选项选择 + 自定义输入 + 可选补充)。 */
5
5
  export interface AskUserAnswerData {
6
6
  selections: Record<number, number[]>;
7
7
  custom: Record<number, string>;
8
+ /** 选完选项后的自由补充,空着就是没有。 */
9
+ note?: string;
8
10
  }
9
11
  export interface AgentLoopInfo {
10
12
  toolCallId: string;
@@ -55,6 +57,7 @@ export interface ReplaySnapshot {
55
57
  export declare function toReplaySnapshot(raw: ReplayState | null | undefined): ReplaySnapshot | null;
56
58
  export declare function createInitialSessionState(sessionId: string): SessionState;
57
59
  export declare function extractModeFromBlocks(blocks: ContentBlock[]): "planning" | "executing" | null;
60
+ export declare function reconcileOptimisticUserTurns(currentTurns: TurnProjection[], incomingTurns: TurnProjection[]): TurnProjection[];
58
61
  /**
59
62
  * 用一份新的 turn 列表重建会话状态。
60
63
  * addErrorMessage 注入的 role==="error" 消息不在 turns 里,默认会被物化过程抹掉;
@@ -37,6 +37,7 @@ export declare class ClientProjectionBuilder {
37
37
  seedSequence(maxSeq: number): void;
38
38
  _seedTurns(turns: TurnProjection[]): void;
39
39
  private onMemoryInject;
40
+ private onContextEntry;
40
41
  private onLoopTurn;
41
42
  private onModeChange;
42
43
  private onPlanStatusUpdate;
@@ -49,6 +50,7 @@ export declare class ClientProjectionBuilder {
49
50
  private onPostChatFollowup;
50
51
  private onDelta;
51
52
  private onToolCallCreated;
53
+ private onToolCallArgumentsDelta;
52
54
  private onResponseDone;
53
55
  private onToolResultDone;
54
56
  private onToolResultDelta;
@@ -0,0 +1,3 @@
1
+ import type { TurnProjection } from "../../schemas/projection";
2
+ /** Build one Context turn from the canonical entry used by live and history paths. */
3
+ export declare function buildContextTurn(entry: Record<string, unknown>, sequence: number): TurnProjection | null;
@@ -4,6 +4,7 @@ export interface RawHistoryEntry {
4
4
  kind?: string;
5
5
  loop_name?: string;
6
6
  message?: Record<string, unknown>;
7
+ source?: Record<string, unknown>;
7
8
  data?: Record<string, unknown>;
8
9
  timestamp?: string;
9
10
  [key: string]: unknown;
@@ -1,3 +1,4 @@
1
1
  export { acceptedPostChatFollowupCompletesLatestRun, ClientProjectionBuilder, type RawEvent, type ProjectionUpdate, } from "./builder";
2
2
  export { type TurnState, createTurnState, snapshot, PAUSE_TOOL_NAMES } from "./state";
3
3
  export { projectHistory, type RawHistoryEntry } from "./history";
4
+ export { buildContextTurn } from "./context";
@@ -32,6 +32,7 @@ export declare namespace ChatSendPayloadSchema {
32
32
  [k: string]: unknown;
33
33
  } | null);
34
34
  type CompactionRatio = (number | null);
35
+ type KbIds = (number[] | null);
35
36
  interface ChatSendPayload {
36
37
  session_id: SessionId;
37
38
  message: Message;
@@ -48,6 +49,7 @@ export declare namespace ChatSendPayloadSchema {
48
49
  runtime_env?: RuntimeEnv;
49
50
  app_context?: AppContext;
50
51
  compaction_ratio?: CompactionRatio;
52
+ kb_ids?: KbIds;
51
53
  [k: string]: unknown;
52
54
  }
53
55
  interface Message {
@@ -183,6 +185,14 @@ export declare namespace ChatEndPayloadSchema {
183
185
  }
184
186
  }
185
187
  export type ChatEndPayload = ChatEndPayloadSchema.ChatEndPayload;
188
+ export declare namespace SessionCreatedPayloadSchema {
189
+ type SessionId = string;
190
+ interface SessionCreatedPayload {
191
+ session_id: SessionId;
192
+ [k: string]: unknown;
193
+ }
194
+ }
195
+ export type SessionCreatedPayload = SessionCreatedPayloadSchema.SessionCreatedPayload;
186
196
  export declare namespace SessionUpdatedPayloadSchema {
187
197
  type SessionId = string;
188
198
  type Model = (string | null);
@@ -405,6 +415,7 @@ export interface ServerToClientEvents {
405
415
  "chat:start": (payload: ChatStartPayload) => void;
406
416
  "chat:end": (payload: ChatEndPayload) => void;
407
417
  "chat:append:ack": (payload: unknown) => void;
418
+ "session:created": (payload: SessionCreatedPayload) => void;
408
419
  "session:updated": (payload: SessionUpdatedPayload) => void;
409
420
  "workspace:files_changed": (payload: WorkspaceFilesChangedPayload) => void;
410
421
  "system:error": (payload: SystemErrorPayload) => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blade-hq/agent-client",
3
- "version": "2610.0.0-beta.2",
3
+ "version": "2610.0.0-beta.21",
4
4
  "description": "Blade Agent 框架无关客户端:会话实时状态机、REST 通道、弹窗登录、页面协作。浏览器与 Node.js 通用。",
5
5
  "repository": {
6
6
  "type": "git",
package/public-api.md CHANGED
@@ -3,7 +3,7 @@
3
3
  > 本文件由 `scripts/public-api-report.mjs` 生成,请勿手改。
4
4
  > 公共面变更时重新生成本报告,并同步更新 README 对应章节——CI 会校验两者。
5
5
 
6
- 136 个公开声明。
6
+ 150 个公开声明。
7
7
 
8
8
  ## `acceptedPostChatFollowupCompletesLatestRun` (function)
9
9
 
@@ -133,6 +133,7 @@ tool_name: string | null | undefined
133
133
 
134
134
  ```ts
135
135
  custom: Record<number, string>
136
+ note: string | undefined
136
137
  selections: Record<number, number[]>
137
138
  ```
138
139
 
@@ -263,6 +264,7 @@ buildMessageContent: (text: string, attachments: Array<{ kind: "file"; name: str
263
264
  blocks: ContentBlock[] | undefined
264
265
  compaction: CompactionInfo | undefined
265
266
  content: MessageContent
267
+ context: ContextProjectionData | undefined
266
268
  duration_ms: number | undefined
267
269
  entry_id: string | undefined
268
270
  kind: string | undefined
@@ -270,6 +272,7 @@ loop_name: string | undefined
270
272
  memory_refs: MemoryRefInfo[] | undefined
271
273
  parent_id: string | null | undefined
272
274
  reasoning: string | undefined
275
+ render_id: string | undefined
273
276
  role: "error" | "user" | "assistant" | "tool"
274
277
  status: "streaming" | "completed" | "paused" | "failed" | "interrupted" | undefined
275
278
  timestamp: string | undefined
@@ -345,6 +348,61 @@ type: "text" | "thinking" | "tool_use" | "tool_result" | "tool_ui" | "tool_bridg
345
348
  contentPreview: (content: MessageContent, maxLen?: number) => string
346
349
  ```
347
350
 
351
+ ## `ContextAction` (type)
352
+
353
+ ```ts
354
+ export type ContextAction = "published" | "retained" | "removed"
355
+ ```
356
+
357
+ ## `ContextDisplayState` (interface)
358
+
359
+ ```ts
360
+ detail: string
361
+ isRemoved: boolean
362
+ summary: string
363
+ title: string
364
+ ```
365
+
366
+ ## `contextProjectionData` (function)
367
+
368
+ ```ts
369
+ contextProjectionData: (fields: ContextProjectionFields) => ContextProjectionData | null
370
+ ```
371
+
372
+ ## `ContextProjectionData` (interface)
373
+
374
+ ```ts
375
+ context_action: ContextAction
376
+ context_key: string
377
+ context_kind: string
378
+ context_name: string
379
+ context_order: number
380
+ context_revision: string
381
+ display_summary: string | null | undefined
382
+ display_title: string | null | undefined
383
+ sources: ContextSourceInfo[]
384
+ ```
385
+
386
+ ## `ContextProjectionFields` (interface)
387
+
388
+ ```ts
389
+ context_action: ContextAction | null | undefined
390
+ context_key: string | null | undefined
391
+ context_kind: string | null | undefined
392
+ context_name: string | null | undefined
393
+ context_order: number | null | undefined
394
+ context_revision: string | null | undefined
395
+ display_summary: string | null | undefined
396
+ display_title: string | null | undefined
397
+ sources: ContextSourceInfo[] | null | undefined
398
+ ```
399
+
400
+ ## `ContextSourceInfo` (type)
401
+
402
+ ```ts
403
+ export type ContextSourceInfo = Record<string, unknown>
404
+ ```
405
+
348
406
  ## `createInitialSessionState` (function)
349
407
 
350
408
  ```ts
@@ -409,6 +467,12 @@ allowedOrigins: string[]
409
467
  iframe: HTMLIFrameElement | undefined
410
468
  ```
411
469
 
470
+ ## `EMPTY_PLATFORM_ENDPOINTS` (const)
471
+
472
+ ```ts
473
+ EMPTY_PLATFORM_ENDPOINTS: PlatformEndpoints
474
+ ```
475
+
412
476
  ## `ExchangeCodeParams` (interface)
413
477
 
414
478
  ```ts
@@ -465,6 +529,12 @@ label: string
465
529
  target: string
466
530
  ```
467
531
 
532
+ ## `getContextDisplayState` (function)
533
+
534
+ ```ts
535
+ getContextDisplayState: (context: ContextProjectionData) => ContextDisplayState
536
+ ```
537
+
468
538
  ## `getFileParts` (function)
469
539
 
470
540
  ```ts
@@ -601,6 +671,20 @@ export enum LayoutType {
601
671
  }
602
672
  ```
603
673
 
674
+ ## `loadPlatformEndpoints` (function)
675
+
676
+ ```ts
677
+ loadPlatformEndpoints: (options?: LoadPlatformEndpointsOptions) => Promise<PlatformEndpoints>
678
+ ```
679
+
680
+ ## `LoadPlatformEndpointsOptions` (interface)
681
+
682
+ ```ts
683
+ baseUrl: string | undefined
684
+ fetchImpl: { (input: RequestInfo | URL, init?: RequestInit): Promise<Response>; (input: string | URL | Request, init?: RequestInit): Promise<Response>; } | undefined
685
+ timeoutMs: number | undefined
686
+ ```
687
+
604
688
  ## `LoginOptions` (interface)
605
689
 
606
690
  ```ts
@@ -713,6 +797,18 @@ sequence: number
713
797
  turn_id: string
714
798
  ```
715
799
 
800
+ ## `PlatformEndpoints` (interface)
801
+
802
+ ```ts
803
+ services: Partial<Record<"os" | "hub" | "agent" | "oauth" | "llmGateway" | "gitea" | "tile", string>>
804
+ ```
805
+
806
+ ## `PlatformServiceName` (type)
807
+
808
+ ```ts
809
+ export type PlatformServiceName = (typeof PLATFORM_SERVICE_NAMES)[number]
810
+ ```
811
+
716
812
  ## `PostChatFollowup` (interface)
717
813
 
718
814
  ```ts
@@ -785,6 +881,12 @@ payload: Record<string, unknown>
785
881
  type: string
786
882
  ```
787
883
 
884
+ ## `reconcileOptimisticUserTurns` (function)
885
+
886
+ ```ts
887
+ reconcileOptimisticUserTurns: (currentTurns: TurnProjection[], incomingTurns: TurnProjection[]) => TurnProjection[]
888
+ ```
889
+
788
890
  ## `ReplayPreview` (interface)
789
891
 
790
892
  ```ts
@@ -819,6 +921,12 @@ speed: ReplaySpeed | undefined
819
921
  status: "replay" | "autonomous" | undefined
820
922
  ```
821
923
 
924
+ ## `resolveServiceUrl` (function)
925
+
926
+ ```ts
927
+ resolveServiceUrl: (endpoints: PlatformEndpoints, name: PlatformServiceName, path?: string) => string | null
928
+ ```
929
+
822
930
  ## `ResultFeedback` (interface)
823
931
 
824
932
  ```ts
@@ -890,6 +998,7 @@ SDK_VERSION: string
890
998
 
891
999
  ```ts
892
1000
  askUserAnswer: Record<string, unknown> | undefined
1001
+ kbIds: number[] | undefined
893
1002
  mode: string | undefined
894
1003
  model: string | undefined
895
1004
  replayDecision: "keep_replay" | "continue_replay" | undefined
@@ -1328,13 +1437,22 @@ archived_count: number | null | undefined
1328
1437
  archived_files: ArchivedFileInfo[] | null | undefined
1329
1438
  archived_tool_calls: ArchivedToolCallInfo[] | null | undefined
1330
1439
  blocks: ContentBlock[]
1440
+ client_render_id: string | null | undefined
1331
1441
  compaction_id: string | null | undefined
1442
+ context_action: ContextAction | null | undefined
1443
+ context_key: string | null | undefined
1444
+ context_kind: string | null | undefined
1445
+ context_name: string | null | undefined
1446
+ context_order: number | null | undefined
1447
+ context_revision: string | null | undefined
1332
1448
  context_window: number | undefined
1449
+ display_summary: string | null | undefined
1450
+ display_title: string | null | undefined
1333
1451
  duration_ms: number | undefined
1334
1452
  failure_reason: string | null | undefined
1335
1453
  fallback_applied: boolean | null | undefined
1336
1454
  id: string
1337
- kind: "message" | "compaction" | undefined
1455
+ kind: "message" | "context" | "compaction" | undefined
1338
1456
  loop_id: string
1339
1457
  memory_refs: MemoryRef[] | null | undefined
1340
1458
  model: string | null | undefined
@@ -1343,6 +1461,7 @@ post_chat_followup: PostChatFollowup | null | undefined
1343
1461
  role: "user" | "assistant" | "system"
1344
1462
  saved_ratio: number | null | undefined
1345
1463
  sequence: number
1464
+ sources: ContextSourceInfo[] | null | undefined
1346
1465
  started_at: string | null | undefined
1347
1466
  status: "streaming" | "completed" | "paused" | "failed" | "interrupted"
1348
1467
  summary_full: string | null | undefined