@blade-hq/agent-client 1.1.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.
Files changed (39) hide show
  1. package/README.md +351 -0
  2. package/dist/auth-login.d.ts +29 -0
  3. package/dist/auth.d.ts +8 -0
  4. package/dist/blade-client.d.ts +113 -0
  5. package/dist/commands/embedded.d.ts +32 -0
  6. package/dist/commands/protocol.d.ts +38 -0
  7. package/dist/commands/registry.d.ts +21 -0
  8. package/dist/index.d.ts +37 -0
  9. package/dist/index.js +4182 -0
  10. package/dist/index.js.map +1 -0
  11. package/dist/resources/auth.d.ts +34 -0
  12. package/dist/resources/headless.d.ts +33 -0
  13. package/dist/resources/sessions.d.ts +263 -0
  14. package/dist/rest.d.ts +21 -0
  15. package/dist/schemas/background.d.ts +16 -0
  16. package/dist/schemas/event.d.ts +51 -0
  17. package/dist/schemas/message-utils.d.ts +48 -0
  18. package/dist/schemas/message.d.ts +83 -0
  19. package/dist/schemas/projection.d.ts +87 -0
  20. package/dist/schemas/session.d.ts +126 -0
  21. package/dist/schemas/solution.d.ts +101 -0
  22. package/dist/schemas/task.d.ts +12 -0
  23. package/dist/session/agent-session.d.ts +179 -0
  24. package/dist/session/events.d.ts +143 -0
  25. package/dist/session/hub.d.ts +44 -0
  26. package/dist/session/state.d.ts +57 -0
  27. package/dist/shared/projection/builder.d.ts +59 -0
  28. package/dist/shared/projection/helpers.d.ts +34 -0
  29. package/dist/shared/projection/history.d.ts +12 -0
  30. package/dist/shared/projection/index.d.ts +3 -0
  31. package/dist/shared/projection/state.d.ts +22 -0
  32. package/dist/socket.d.ts +9 -0
  33. package/dist/types/index.d.ts +8 -0
  34. package/dist/types/rest.d.ts +17315 -0
  35. package/dist/types/sdk-profile.d.ts +47 -0
  36. package/dist/types/socket-events.d.ts +401 -0
  37. package/dist/version.d.ts +45 -0
  38. package/package.json +29 -0
  39. package/public-api.md +1103 -0
@@ -0,0 +1,34 @@
1
+ import type { BladeClient } from "../blade-client";
2
+ import type { LoginOptions, LoginResult } from "../auth-login";
3
+ export interface UserInfo {
4
+ id: string;
5
+ username: string;
6
+ display_name?: string | null;
7
+ avatar_url: string | null;
8
+ token: string;
9
+ auth_type: "casdoor";
10
+ is_admin?: boolean;
11
+ }
12
+ export interface ProvidersResponse {
13
+ providers: Array<{
14
+ name: string;
15
+ authorize_url: string;
16
+ }>;
17
+ password_enabled: boolean;
18
+ }
19
+ export declare class AuthResource {
20
+ private client;
21
+ constructor(client: BladeClient);
22
+ /**
23
+ * 弹窗授权登录(浏览器专用):弹出后端授权页,用户点击"许可授权"后
24
+ * 自动取得 PAT 并热挂载到当前 client。等价于 client.login()。
25
+ */
26
+ login(options?: LoginOptions): Promise<LoginResult>;
27
+ /** 清除 login() 存储的令牌。 */
28
+ logoutToken(): void;
29
+ getProviders(): Promise<ProvidersResponse>;
30
+ getMe(): Promise<UserInfo>;
31
+ logout(): Promise<{
32
+ logout_url: string;
33
+ }>;
34
+ }
@@ -0,0 +1,33 @@
1
+ import type { BladeClient } from "../blade-client";
2
+ export type JsonSchemaObject = Record<string, unknown>;
3
+ export interface HeadlessRunOptions {
4
+ schema?: JsonSchemaObject | null;
5
+ model?: string | null;
6
+ timeoutMs?: number;
7
+ }
8
+ export interface HeadlessRunInSessionResult<T = unknown> {
9
+ session_id: string;
10
+ chat_run_id: string | null;
11
+ result: T | string;
12
+ }
13
+ export declare class HeadlessError extends Error {
14
+ readonly detail?: unknown;
15
+ constructor(message: string, detail?: unknown);
16
+ }
17
+ export declare class HeadlessResource {
18
+ private client;
19
+ constructor(client: BladeClient);
20
+ run<T = unknown>(prompt: string, options: HeadlessRunOptions & {
21
+ schema: JsonSchemaObject;
22
+ }): Promise<T>;
23
+ run(prompt: string, options?: HeadlessRunOptions): Promise<string>;
24
+ runInSession<T = unknown>(sessionId: string, prompt: string, options: HeadlessRunOptions & {
25
+ schema: JsonSchemaObject;
26
+ }): Promise<T>;
27
+ runInSession(sessionId: string, prompt: string, options?: HeadlessRunOptions): Promise<string>;
28
+ runWithSession<T = unknown>(prompt: string, options: HeadlessRunOptions & {
29
+ schema: JsonSchemaObject;
30
+ }): Promise<HeadlessRunInSessionResult<T>>;
31
+ runWithSession(prompt: string, options?: HeadlessRunOptions): Promise<HeadlessRunInSessionResult<string>>;
32
+ private runTracked;
33
+ }
@@ -0,0 +1,263 @@
1
+ import type { BackgroundTask } from "../schemas/background";
2
+ import type { TurnProjection } from "../schemas/projection";
3
+ import type { SessionDetail, SessionInfo, TemplateId } from "../schemas/session";
4
+ import type { Task } from "../schemas/task";
5
+ import type { BladeClient, UploadProgress } from "../blade-client";
6
+ import type { AgentSession } from "../session/agent-session";
7
+ import type { SessionProfile } from "../types/sdk-profile";
8
+ export interface CreateSessionRequest {
9
+ intent?: string;
10
+ template_id?: TemplateId;
11
+ solution_id?: string;
12
+ biz_role_id?: string | null;
13
+ primary_skill_id?: string | null;
14
+ model?: string | null;
15
+ enable_thinking?: boolean | null;
16
+ memory_enabled?: boolean | null;
17
+ env?: Record<string, string>;
18
+ disable_tools?: string[] | null;
19
+ session_solution_asset_id?: string | null;
20
+ compaction_ratio?: number | null;
21
+ runtime_type?: "sandbox" | "daemon" | null;
22
+ daemon_id?: string | null;
23
+ }
24
+ export interface CheckpointNode {
25
+ id: string;
26
+ parent_id: string | null;
27
+ content_preview: string;
28
+ content: string;
29
+ timestamp: string;
30
+ }
31
+ export type ContentPart = {
32
+ type: "text";
33
+ text: string;
34
+ } | {
35
+ type: "image_url";
36
+ image_url: {
37
+ url: string;
38
+ detail?: string;
39
+ };
40
+ };
41
+ export interface HistoryNode {
42
+ id: string;
43
+ parent_id: string | null;
44
+ kind: string;
45
+ role: string;
46
+ timestamp: string;
47
+ preview: string;
48
+ content: string | ContentPart[];
49
+ tool_calls: Array<{
50
+ id?: string;
51
+ type?: string;
52
+ function?: {
53
+ name?: string;
54
+ arguments?: string;
55
+ };
56
+ }> | null;
57
+ usage: {
58
+ prompt_tokens?: number;
59
+ completion_tokens?: number;
60
+ total_tokens?: number;
61
+ } | null;
62
+ total_tokens: number;
63
+ token_diff: number;
64
+ is_deprecated: boolean;
65
+ loop_name: string;
66
+ }
67
+ export interface SessionHistory {
68
+ nodes: HistoryNode[];
69
+ active_branch: string | null;
70
+ branches: string[];
71
+ system_prompt_tokens?: number | null;
72
+ tools_tokens?: number | null;
73
+ tokenizer_model?: string | null;
74
+ }
75
+ export interface TokenizeResult {
76
+ model: string;
77
+ prompt_tokens: number;
78
+ prompt: string;
79
+ }
80
+ export interface PaginatedSessionsResult {
81
+ items: SessionInfo[];
82
+ total: number;
83
+ limit: number;
84
+ offset: number;
85
+ content_match_truncated?: boolean;
86
+ }
87
+ export interface SkillDevSession {
88
+ session: SessionInfo;
89
+ skill_id: string;
90
+ display_name: string;
91
+ skill_description: string;
92
+ }
93
+ export interface ShareLinkResult {
94
+ token: string;
95
+ url: string;
96
+ expires_at: string | null;
97
+ }
98
+ export interface SessionContextStats {
99
+ tokens_used: number;
100
+ context_window: number;
101
+ compaction_ratio: number;
102
+ }
103
+ export interface FileEntry {
104
+ name: string;
105
+ path: string;
106
+ is_dir: boolean;
107
+ created_at: number;
108
+ tags?: string[];
109
+ }
110
+ export type UploadFileEntry = File | {
111
+ file: File;
112
+ name: string;
113
+ };
114
+ export interface UploadFilesOptions {
115
+ onProgress?: (progress: UploadProgress) => void;
116
+ }
117
+ export interface ImportPreviewSkill {
118
+ name: string;
119
+ description: string;
120
+ path: string;
121
+ }
122
+ export interface ImportPreviewScenario {
123
+ scenario?: {
124
+ name?: string;
125
+ };
126
+ skills?: string[];
127
+ preview_urls?: string[];
128
+ init_script?: string;
129
+ generated_at?: string;
130
+ }
131
+ export interface ImportPreview {
132
+ user_messages: string[];
133
+ turn_count: number;
134
+ skills: ImportPreviewSkill[];
135
+ scenario: ImportPreviewScenario | null;
136
+ }
137
+ export declare class SessionsResource {
138
+ private client;
139
+ constructor(client: BladeClient);
140
+ /**
141
+ * 连接一个已存在的会话,返回实时会话对象 AgentSession
142
+ * (自动完成历史加载、Socket.IO 订阅、断线重连补数)。
143
+ */
144
+ connect(sessionId: string): Promise<AgentSession>;
145
+ /** 创建新会话并直接连接,返回可收发消息的 AgentSession。 */
146
+ create(request?: CreateSessionRequest): Promise<AgentSession>;
147
+ private fetchSessionsPage;
148
+ listSessions(template_id_prefix?: string, solution_id?: string): Promise<SessionInfo[]>;
149
+ listSessionsPaginated(params: {
150
+ limit: number;
151
+ offset: number;
152
+ template_id_prefix?: string;
153
+ solution_id?: string;
154
+ q?: string;
155
+ }): Promise<PaginatedSessionsResult>;
156
+ listSessionsWithSkillData(): Promise<SkillDevSession[]>;
157
+ createSession(intent?: string, template_id?: TemplateId, primary_skill_id?: string | null): Promise<{
158
+ session_id: string;
159
+ }>;
160
+ createSessionWithRequest(request: CreateSessionRequest): Promise<{
161
+ session_id: string;
162
+ }>;
163
+ createWithProfile(params: {
164
+ intent: string;
165
+ profile: SessionProfile;
166
+ }): Promise<{
167
+ session_id: string;
168
+ }>;
169
+ getSession(sessionId: string, init?: RequestInit): Promise<SessionDetail>;
170
+ updateSession(sessionId: string, payload: {
171
+ intent?: string;
172
+ }): Promise<SessionDetail>;
173
+ setSessionEnv(sessionId: string, env: Record<string, string>): Promise<SessionDetail>;
174
+ pinSession(sessionId: string, pinned: boolean): Promise<SessionInfo>;
175
+ startReplaySession(sourceSessionId: string, speed?: 1 | 2 | 5): Promise<{
176
+ session_id: string;
177
+ }>;
178
+ updateReplaySession(sessionId: string, payload: {
179
+ speed?: 1 | 2 | 5;
180
+ status?: "autonomous";
181
+ }): Promise<{
182
+ replay_state: SessionInfo["replay_state"];
183
+ }>;
184
+ updateSharing(sessionId: string, shared: boolean): Promise<{
185
+ shared: boolean;
186
+ }>;
187
+ updateSessionMemory(sessionId: string, memoryEnabled: boolean): Promise<{
188
+ memory_enabled: boolean;
189
+ }>;
190
+ createShare(sessionId: string): Promise<ShareLinkResult>;
191
+ revokeShare(sessionId: string, token: string): Promise<{
192
+ revoked: boolean;
193
+ }>;
194
+ getSharedSession(token: string): Promise<TurnProjection[]>;
195
+ getSessionTasks(sessionId: string): Promise<Task[]>;
196
+ getSessionTurns(sessionId: string): Promise<TurnProjection[]>;
197
+ getSessionContextStats(sessionId: string, init?: RequestInit): Promise<SessionContextStats>;
198
+ getSessionHistory(sessionId: string, init?: RequestInit): Promise<SessionHistory>;
199
+ tokenizePrompt(prompt: string, model?: string): Promise<TokenizeResult>;
200
+ tokenizeMessages(messages: Array<Record<string, unknown>>, options?: {
201
+ model?: string;
202
+ add_generation_prompt?: boolean;
203
+ enable_thinking?: boolean | null;
204
+ tools?: Array<Record<string, unknown>>;
205
+ }): Promise<TokenizeResult>;
206
+ getSessionCheckpoints(sessionId: string, init?: RequestInit): Promise<{
207
+ nodes: CheckpointNode[];
208
+ leaf_id: string | null;
209
+ }>;
210
+ checkoutSession(sessionId: string, checkpointId: string, position: "before" | "turn_end", mode?: "both" | "conversation" | "code", linear?: boolean): Promise<{
211
+ id: string;
212
+ content: string;
213
+ position: string;
214
+ mode?: string;
215
+ files_restored?: boolean;
216
+ linear?: boolean;
217
+ }>;
218
+ rewindSession(sessionId: string, checkpointId: string): Promise<{
219
+ id: string;
220
+ content: string;
221
+ }>;
222
+ switchBranch(sessionId: string, checkpointId: string): Promise<{
223
+ id: string;
224
+ leaf_id: string;
225
+ }>;
226
+ deleteSession(sessionId: string): Promise<{
227
+ deleted: boolean;
228
+ }>;
229
+ listBackgroundTasks(sessionId: string, init?: RequestInit): Promise<BackgroundTask[]>;
230
+ getBackgroundTask(sessionId: string, taskId: string, tail?: number, init?: RequestInit): Promise<BackgroundTask>;
231
+ stopBackgroundTask(sessionId: string, taskId: string): Promise<{
232
+ message: string;
233
+ task?: BackgroundTask | null;
234
+ }>;
235
+ probeSessionUrl(sessionId: string, url: string): Promise<{
236
+ reachable: boolean;
237
+ }>;
238
+ listDir(sessionId: string, dirPath: string): Promise<FileEntry[]>;
239
+ uploadFiles(sessionId: string, dirPath: string, files: FileList | File[] | UploadFileEntry[], options?: UploadFilesOptions): Promise<{
240
+ uploaded: string[];
241
+ failed: string[];
242
+ }>;
243
+ deleteFile(sessionId: string, filePath: string): Promise<void>;
244
+ writeFile(sessionId: string, filePath: string, content: string): Promise<{
245
+ success: boolean;
246
+ }>;
247
+ renameFile(sessionId: string, filePath: string, newName: string): Promise<{
248
+ path: string;
249
+ }>;
250
+ copyFile(sessionId: string, filePath: string): Promise<{
251
+ path: string;
252
+ }>;
253
+ shareFile(sessionId: string, sourcePath: string, linkName?: string, shareFolder?: string): Promise<{
254
+ path: string;
255
+ target: string;
256
+ }>;
257
+ getDownloadDirUrl(sessionId: string, dirPath: string): string;
258
+ exportSession(sessionId: string): Promise<void>;
259
+ previewImport(file: File): Promise<ImportPreview>;
260
+ importSession(file: File, name?: string, solutionId?: string | null): Promise<{
261
+ session_id: string;
262
+ }>;
263
+ }
package/dist/rest.d.ts ADDED
@@ -0,0 +1,21 @@
1
+ export declare class BladeApiError extends Error {
2
+ readonly response: Response;
3
+ readonly status: number;
4
+ readonly statusText: string;
5
+ constructor(response: Response, message?: string);
6
+ }
7
+ /**
8
+ * 从 FastAPI 风格的错误响应中提取 detail 字段,作为用户可读的中文错误文案。
9
+ * 失败时返回 undefined,调用方会回退到默认提示。
10
+ */
11
+ export declare function extractErrorDetail(response: Response): Promise<string | undefined>;
12
+ /** 401/403 补充"怎么办"的指引,避免初级开发者对着裸状态码发呆。 */
13
+ export declare function decorateAuthError(error: unknown): unknown;
14
+ export type HttpMethod = "DELETE" | "GET" | "PATCH" | "POST" | "PUT" | (string & {});
15
+ export interface BladeFetchInit {
16
+ body?: BodyInit | null;
17
+ credentials?: RequestCredentials;
18
+ expectOk?: boolean;
19
+ headers?: HeadersInit;
20
+ signal?: AbortSignal | null;
21
+ }
@@ -0,0 +1,16 @@
1
+ export interface BackgroundTask {
2
+ id: string;
3
+ command: string;
4
+ description?: string;
5
+ status: "queued" | "starting" | "running" | "succeeded" | "done" | "failed" | "timeout" | "cancelled" | "lost";
6
+ legacy_status?: "running" | "done" | "failed";
7
+ exit_code?: number | null;
8
+ elapsed_seconds: number;
9
+ output_lines_count?: number;
10
+ output_preview?: string[];
11
+ output?: string;
12
+ log_path?: string | null;
13
+ started_at?: number | null;
14
+ finished_at?: number | null;
15
+ heartbeat_at?: number | null;
16
+ }
@@ -0,0 +1,51 @@
1
+ export interface ContentDelta {
2
+ content: string;
3
+ loop_name?: string;
4
+ }
5
+ export interface ToolCallCreated {
6
+ index: number;
7
+ id: string;
8
+ loop_name?: string;
9
+ function: {
10
+ name: string;
11
+ arguments: string;
12
+ };
13
+ }
14
+ export interface ToolResultDone {
15
+ tool_call_id: string;
16
+ loop_name?: string;
17
+ function: {
18
+ name: string;
19
+ };
20
+ content: string;
21
+ }
22
+ export interface ToolResultDelta {
23
+ tool_call_id: string;
24
+ loop_name?: string;
25
+ content: string;
26
+ stream?: "stdout" | "stderr";
27
+ }
28
+ export interface LlmResponseDone {
29
+ role: string;
30
+ content?: string | null;
31
+ reasoning?: string | null;
32
+ loop_name?: string;
33
+ tool_calls?: {
34
+ id: string;
35
+ function: {
36
+ name: string;
37
+ arguments: string;
38
+ };
39
+ }[];
40
+ }
41
+ export interface ChatEnd {
42
+ status: string;
43
+ duration_ms: number;
44
+ }
45
+ export interface SystemError {
46
+ message: string;
47
+ }
48
+ export interface SessionStatusEvent {
49
+ session_id: string;
50
+ status: string;
51
+ }
@@ -0,0 +1,48 @@
1
+ import type { ChatMessage, FileContentPart, ImageUrlContentPart, MessageContent } from "./message";
2
+ export declare function normalizeMessageContent(content: unknown): MessageContent;
3
+ export declare function getTextContent(content: MessageContent): string;
4
+ export declare function isSystemReminderText(text: string): boolean;
5
+ export declare function isLegacyForkContextText(text: string): boolean;
6
+ export declare function isHiddenInternalMessage(message: Pick<ChatMessage, "role" | "content">): boolean;
7
+ export declare function buildMessageContent(text: string, attachments: Array<{
8
+ kind: "file";
9
+ name: string;
10
+ uploadedPath?: string;
11
+ textContent?: string | null;
12
+ mimeType?: string;
13
+ }>): MessageContent;
14
+ export declare function contentPreview(content: MessageContent, maxLen?: number): string;
15
+ /**
16
+ * Transform a skill mention into a natural language skill invocation.
17
+ * Strips the `<skill>name</skill>` tag from the raw input and prepends the instruction.
18
+ */
19
+ export declare function transformSlashCommand(skillName: string, rawInput: string): string;
20
+ export interface ParsedTextAttachment {
21
+ name: string;
22
+ uploadedPath?: string;
23
+ }
24
+ export interface ParsedTextContext {
25
+ label: string;
26
+ content: string;
27
+ }
28
+ /**
29
+ * Extract `[附件: name]` and `[上下文: label]` tags from text parts and return
30
+ * the cleaned text plus the collected attachment / context metadata. 每个 text
31
+ * part 独立匹配,以避免跨 part 拼接打乱正则。
32
+ */
33
+ export declare function extractTextAttachments(content: MessageContent): {
34
+ cleanText: string;
35
+ attachments: ParsedTextAttachment[];
36
+ contexts: ParsedTextContext[];
37
+ };
38
+ export declare function getImageParts(content: MessageContent): ImageUrlContentPart[];
39
+ export declare function getFileParts(content: MessageContent): FileContentPart[];
40
+ interface MessageGroup {
41
+ root: ChatMessage | null;
42
+ childLoops: {
43
+ loopName: string;
44
+ messages: ChatMessage[];
45
+ }[];
46
+ }
47
+ export declare function groupMessagesByLoop(messages: ChatMessage[]): MessageGroup[];
48
+ export {};
@@ -0,0 +1,83 @@
1
+ import type { ContentBlock, PendingQuestionRef, ToolBridgeContent } from "./projection";
2
+ export interface TextContentPart {
3
+ type: "text";
4
+ text: string;
5
+ }
6
+ export interface ImageUrlContentPart {
7
+ type: "image_url";
8
+ image_url: {
9
+ url: string;
10
+ };
11
+ }
12
+ export interface FileContentPart {
13
+ type: "file";
14
+ name: string;
15
+ data: string;
16
+ }
17
+ export type MessageContentPart = TextContentPart | ImageUrlContentPart | FileContentPart;
18
+ export type MessageContent = string | MessageContentPart[];
19
+ export interface ToolCallInfo {
20
+ id: string;
21
+ name: string;
22
+ display_name?: string | null;
23
+ arguments: string;
24
+ result?: unknown;
25
+ status?: "pending" | "done" | "error" | "cancelled" | "awaiting_answer";
26
+ duration_ms?: number | null;
27
+ pending_question_ref?: PendingQuestionRef | null;
28
+ }
29
+ export type { ToolBridgeContent };
30
+ /** Derive tool status from the result content string. */
31
+ export declare function inferToolStatus(resultStr: string): "done" | "error" | "cancelled";
32
+ export interface MemoryRefInfo {
33
+ id: number;
34
+ content_preview: string;
35
+ skill_name?: string | null;
36
+ }
37
+ export interface CompactionInfo {
38
+ compaction_id: string;
39
+ summary_preview?: string | null;
40
+ summary_full?: string | null;
41
+ archived_count?: number | null;
42
+ archived_files?: ArchivedFileInfo[] | null;
43
+ archived_tool_calls?: ArchivedToolCallInfo[] | null;
44
+ tokens_before?: number | null;
45
+ tokens_after?: number | null;
46
+ saved_ratio?: number | null;
47
+ trigger?: "auto" | "manual" | "forced_retry" | null;
48
+ failure_reason?: string | null;
49
+ fallback_applied?: boolean | null;
50
+ }
51
+ export interface ArchivedFileInfo {
52
+ tool_name?: string | null;
53
+ filename?: string | null;
54
+ relative_path?: string | null;
55
+ size_bytes?: number | null;
56
+ }
57
+ export interface ArchivedToolCallInfo {
58
+ tool_call_id?: string | null;
59
+ tool_name?: string | null;
60
+ archive_path?: string | null;
61
+ replacement_content?: string | null;
62
+ entry_id?: string | null;
63
+ }
64
+ export interface ChatMessage {
65
+ role: "user" | "assistant" | "tool" | "error";
66
+ content: MessageContent;
67
+ reasoning?: string;
68
+ tool_calls?: ToolCallInfo[];
69
+ status?: "streaming" | "completed" | "paused" | "failed" | "interrupted";
70
+ duration_ms?: number;
71
+ timestamp?: string;
72
+ entry_id?: string;
73
+ parent_id?: string | null;
74
+ loop_name?: string;
75
+ /** Entry kind from backend -- present for non-message entries like mode changes. */
76
+ kind?: string;
77
+ /** Memory references injected into this turn's context */
78
+ memory_refs?: MemoryRefInfo[];
79
+ /** Raw projection blocks for block-level UI rendering. */
80
+ blocks?: ContentBlock[];
81
+ /** Compaction metadata for compaction turns. */
82
+ compaction?: CompactionInfo;
83
+ }
@@ -0,0 +1,87 @@
1
+ export interface ToolBridgeContent {
2
+ action: string;
3
+ payload?: unknown;
4
+ }
5
+ export interface ContentBlock {
6
+ type: "text" | "thinking" | "tool_use" | "tool_result" | "tool_ui" | "tool_bridge" | "system_notification" | "mode_change" | "plan_status" | "ask_user_answer";
7
+ content: unknown;
8
+ tool_call_id?: string | null;
9
+ tool_name?: string | null;
10
+ display_name?: string | null;
11
+ }
12
+ export interface PendingQuestionRef {
13
+ child_loop_name: string;
14
+ child_tool_call_id: string;
15
+ description?: string | null;
16
+ }
17
+ export interface ToolCallProjection {
18
+ id: string;
19
+ tool_name: string;
20
+ display_name: string;
21
+ arguments: string;
22
+ status: "pending" | "done" | "error" | "cancelled" | "awaiting_answer" | string;
23
+ result?: unknown;
24
+ duration_ms?: number | null;
25
+ pending_question_ref?: PendingQuestionRef | null;
26
+ }
27
+ export interface MemoryRef {
28
+ id: number;
29
+ content_preview: string;
30
+ skill_name?: string | null;
31
+ }
32
+ export interface TurnProjection {
33
+ id: string;
34
+ sequence: number;
35
+ turn_id: string;
36
+ loop_id: string;
37
+ kind?: "message" | "compaction";
38
+ role: "user" | "assistant" | "system";
39
+ status: "streaming" | "completed" | "paused" | "failed" | "interrupted";
40
+ blocks: ContentBlock[];
41
+ tool_calls: ToolCallProjection[];
42
+ model?: string | null;
43
+ usage?: Record<string, unknown> | null;
44
+ duration_ms?: number;
45
+ started_at?: string | null;
46
+ context_window?: number;
47
+ memory_refs?: MemoryRef[] | null;
48
+ parent_fork_tool_call_id?: string | null;
49
+ compaction_id?: string | null;
50
+ summary_preview?: string | null;
51
+ summary_full?: string | null;
52
+ archived_count?: number | null;
53
+ archived_files?: ArchivedFileInfo[] | null;
54
+ archived_tool_calls?: ArchivedToolCallInfo[] | null;
55
+ tokens_before?: number | null;
56
+ tokens_after?: number | null;
57
+ saved_ratio?: number | null;
58
+ trigger?: "auto" | "manual" | "forced_retry" | null;
59
+ failure_reason?: string | null;
60
+ fallback_applied?: boolean | null;
61
+ }
62
+ export interface ArchivedFileInfo {
63
+ tool_name?: string | null;
64
+ filename?: string | null;
65
+ relative_path?: string | null;
66
+ size_bytes?: number | null;
67
+ }
68
+ export interface ArchivedToolCallInfo {
69
+ tool_call_id?: string | null;
70
+ tool_name?: string | null;
71
+ archive_path?: string | null;
72
+ replacement_content?: string | null;
73
+ entry_id?: string | null;
74
+ }
75
+ export interface PatchEnvelope {
76
+ sequence: number;
77
+ turn_id: string;
78
+ loop_id: string;
79
+ patch_type: string;
80
+ data: {
81
+ turn?: TurnProjection;
82
+ workspace_changed?: {
83
+ tool_call_id?: string;
84
+ tool_name?: string;
85
+ };
86
+ };
87
+ }