@sanqianx/claude-ai-workbench 0.13.2 → 0.13.4

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 (122) hide show
  1. package/LICENSE +201 -201
  2. package/README.md +156 -156
  3. package/apps/agent-terminal/app.css +652 -613
  4. package/apps/agent-terminal/app.js +143 -67
  5. package/apps/agent-terminal/conversation-composer.js +44 -0
  6. package/apps/agent-terminal/index.html +172 -170
  7. package/apps/agent-terminal/panel-host-proof.html +152 -152
  8. package/apps/agent-terminal/panel-proof-content.html +41 -41
  9. package/apps/agent-terminal/right-workspace-dock.css +189 -159
  10. package/apps/agent-terminal/right-workspace-dock.js +652 -521
  11. package/apps/agent-terminal/user-question-card.js +68 -0
  12. package/apps/ai-profile-settings-host/index.html +25 -25
  13. package/apps/ai-profile-settings-host/page.css +1 -1
  14. package/apps/ai-profile-settings-host/page.js +113 -113
  15. package/apps/minimal-test-host/README.md +15 -15
  16. package/apps/minimal-test-host/host.css +2 -2
  17. package/apps/minimal-test-host/host.js +35 -35
  18. package/apps/minimal-test-host/index.html +58 -58
  19. package/apps/minimal-test-host/optional-mock/fault-injection.js +15 -15
  20. package/docs/sdk/FILE_LAYOUT.md +31 -31
  21. package/docs/sdk/INTEGRATION.md +126 -126
  22. package/docs/sdk/README.md +21 -21
  23. package/docs/sdk/SESSION_EVENTS.md +15 -13
  24. package/docs/sdk/openapi.yaml +16 -1
  25. package/package.json +1 -1
  26. package/packages/client/README.md +29 -29
  27. package/packages/client/index.d.ts +122 -122
  28. package/packages/client/index.js +260 -260
  29. package/packages/client/package.json +2 -2
  30. package/packages/contracts/README.md +9 -9
  31. package/packages/contracts/index.d.ts +519 -517
  32. package/packages/contracts/index.js +312 -312
  33. package/packages/contracts/package.json +1 -1
  34. package/packages/core/README.md +8 -8
  35. package/packages/core/index.d.ts +76 -76
  36. package/packages/core/index.js +222 -222
  37. package/packages/core/package.json +2 -2
  38. package/packages/server/README.md +17 -17
  39. package/packages/server/bin/agent-terminal-server.js +42 -42
  40. package/packages/server/bin/claude-workbench.js +225 -225
  41. package/packages/server/index.d.ts +171 -171
  42. package/packages/server/index.js +230 -230
  43. package/packages/server/lib/agent-discovery.js +133 -133
  44. package/packages/server/lib/agent-registry.js +143 -143
  45. package/packages/server/lib/agent-spawn-env.js +17 -17
  46. package/packages/server/lib/attachment-store.js +78 -78
  47. package/packages/server/lib/bridges/app-server-bridge.js +373 -373
  48. package/packages/server/lib/bridges/opencode-server-bridge.js +506 -506
  49. package/packages/server/lib/capture-settings-store.js +35 -35
  50. package/packages/server/lib/claude-history-recovery.js +87 -87
  51. package/packages/server/lib/cli-session-recovery.js +28 -28
  52. package/packages/server/lib/context-resolver.js +55 -55
  53. package/packages/server/lib/conversation-capture.js +51 -51
  54. package/packages/server/lib/delegation-phase-store.js +357 -357
  55. package/packages/server/lib/delegation-store.js +474 -468
  56. package/packages/server/lib/diagnostics.js +32 -32
  57. package/packages/server/lib/drivers/cli-json-runner.js +974 -974
  58. package/packages/server/lib/drivers/codex-driver.js +1461 -1442
  59. package/packages/server/lib/drivers/opencode-driver.js +1554 -1554
  60. package/packages/server/lib/drivers/zcode-driver.js +1250 -1250
  61. package/packages/server/lib/drivers/zcode-profile-runtime.js +71 -71
  62. package/packages/server/lib/event-stream.js +138 -138
  63. package/packages/server/lib/folder-picker.js +623 -623
  64. package/packages/server/lib/http-handler.js +339 -339
  65. package/packages/server/lib/json-file.js +26 -26
  66. package/packages/server/lib/knowledge-context.js +33 -33
  67. package/packages/server/lib/model-detection.js +295 -295
  68. package/packages/server/lib/parent-context.js +44 -0
  69. package/packages/server/lib/profile-store.js +283 -283
  70. package/packages/server/lib/project-store.js +102 -102
  71. package/packages/server/lib/runtime-loader.js +120 -120
  72. package/packages/server/lib/session-archive-store.js +53 -53
  73. package/packages/server/lib/session-history.js +612 -612
  74. package/packages/server/lib/system-doctor.js +125 -125
  75. package/packages/server/lib/ui-preferences-store.js +48 -48
  76. package/packages/server/lib/user-questions.js +67 -0
  77. package/packages/server/lib/workbench-service.js +1696 -1675
  78. package/packages/server/package.json +2 -2
  79. package/packages/ui/README.md +30 -30
  80. package/packages/ui/ai-profile-settings.d.ts +45 -45
  81. package/packages/ui/ai-profile-settings.js +283 -283
  82. package/packages/ui/claude-terminal.d.ts +31 -31
  83. package/packages/ui/claude-terminal.js +343 -343
  84. package/packages/ui/index.d.ts +18 -18
  85. package/packages/ui/index.js +51 -51
  86. package/packages/ui/package.json +2 -2
  87. package/packages/ui/theme.css +13 -13
  88. package/src/assets/claude-prompts.json +21 -21
  89. package/src/backend/http/ai-profile-routes.js +61 -61
  90. package/src/backend/http/claude-routes.js +170 -170
  91. package/src/backend/http/node-helpers.js +45 -45
  92. package/src/backend/index.js +21 -21
  93. package/src/backend/lib/ai-adapter.js +144 -144
  94. package/src/backend/lib/ai-profile-store.js +259 -259
  95. package/src/backend/lib/ai-vendor-presets.js +83 -83
  96. package/src/backend/lib/ai-workspace.js +140 -140
  97. package/src/backend/lib/automation-config.js +253 -253
  98. package/src/backend/lib/claude-cli-runner.js +2408 -2392
  99. package/src/backend/lib/data-dir.js +169 -169
  100. package/src/backend/lib/llm-client.js +176 -176
  101. package/src/backend/lib/model-context-windows.js +82 -82
  102. package/src/backend/lib/native-task-control.js +217 -217
  103. package/src/backend/lib/native-task-history-index.js +475 -475
  104. package/src/backend/lib/native-task-history-reader.js +526 -526
  105. package/src/backend/lib/native-task-messages.js +457 -457
  106. package/src/backend/lib/native-task-registry.js +325 -325
  107. package/src/backend/lib/native-task-runtime.js +242 -242
  108. package/src/backend/lib/native-task-trace.js +440 -440
  109. package/src/backend/lib/native-task-transcript.js +393 -393
  110. package/src/backend/lib/prompt-registry.js +166 -166
  111. package/src/backend/lib/runtime-config.js +121 -121
  112. package/src/backend/lib/sdk-session-stream.js +143 -143
  113. package/src/backend/lib/sdk-turn-stream.js +16 -16
  114. package/src/backend/lib/store-scope.js +131 -131
  115. package/src/backend/lib/task-identity.js +104 -104
  116. package/src/backend/lib/task-state-projection.js +58 -58
  117. package/src/index.js +7 -7
  118. package/src/sdk-wave-a.ts +1 -1
  119. package/src/sdk-wave-b.ts +1 -1
  120. package/src/sdk-wave-c.ts +1 -1
  121. package/src/sdk-wave-d.ts +1 -1
  122. package/src/sdk-wave-e.ts +1 -1
@@ -1,517 +1,519 @@
1
- export type PermissionMode = "default" | "acceptEdits" | "plan" | "bypassPermissions";
2
- export type ProfileProtocol = "anthropic-compatible" | "openai-compatible" | string;
3
- export type AgentId = "claude-code" | "codex" | "opencode" | "zcode";
4
- export type EffortLevel = "low" | "medium" | "high" | "max";
5
-
6
- export interface AgentCapabilities {
7
- backgroundTasks?: boolean;
8
- thinking: boolean;
9
- permissions: boolean;
10
- toolStream: boolean;
11
- images: boolean;
12
- resume: true;
13
- modelOverride: boolean;
14
- generationParams: readonly string[];
15
- }
16
-
17
- export interface AgentDefinition {
18
- id: AgentId;
19
- label: string;
20
- transport: string;
21
- authModes: readonly string[];
22
- capabilities: AgentCapabilities;
23
- }
24
-
25
- export interface AgentStatus extends AgentDefinition {
26
- scanState?: 'unknown' | 'ready' | 'error';
27
- checkedAt?: string;
28
- errorCode?: string | null;
29
- capabilities: { generationParams: string[] } & Omit<AgentCapabilities, "generationParams">;
30
- available: boolean;
31
- version: string | null;
32
- }
33
-
34
- export interface Project {
35
- id: string;
36
- name: string;
37
- rootPath: string;
38
- createdAt: string;
39
- updatedAt: string;
40
- defaultAiProfileId?: string | null;
41
- defaultModel?: string | null;
42
- defaultAgentId?: AgentId;
43
- }
44
-
45
- export interface ProjectInput {
46
- name: string;
47
- rootPath: string;
48
- defaultAiProfileId?: string | null;
49
- defaultModel?: string | null;
50
- defaultAgentId?: AgentId;
51
- }
52
-
53
- export type ProjectPatch = Partial<Omit<ProjectInput, "rootPath">>;
54
-
55
- export interface ModelListEntry {
56
- id: string;
57
- openaiId?: string;
58
- label: string;
59
- tags: string[];
60
- }
61
-
62
- export interface WorkbenchContext {
63
- contextId: string;
64
- contextType?: string;
65
- displayName?: string;
66
- workspaceRef?: string;
67
- aiProfileId?: string | null;
68
- model?: string | null;
69
- metadata?: Record<string, unknown>;
70
- }
71
-
72
- export interface AiProfileModels {
73
- default: string;
74
- fast?: string;
75
- reasoning?: string;
76
- coding?: string;
77
- largeContext?: string;
78
- list?: ModelListEntry[];
79
- [role: string]: string | undefined | ModelListEntry[];
80
- }
81
-
82
- export interface AiProfileInput {
83
- id: string;
84
- name?: string;
85
- provider: string;
86
- protocol?: ProfileProtocol;
87
- runtime?: "claude-code";
88
- baseUrl: string;
89
- openaiBaseUrl?: string;
90
- credentialRef?: string;
91
- models: AiProfileModels;
92
- contextWindow?: number;
93
- timeoutMs?: number;
94
- permissionMode?: PermissionMode;
95
- systemPrompt?: Record<string, unknown> | string;
96
- enabled?: boolean;
97
- }
98
-
99
- export interface AiProfile extends AiProfileInput {
100
- name: string;
101
- protocol: ProfileProtocol;
102
- runtime: "claude-code";
103
- credentialRef: string;
104
- contextWindow: number;
105
- timeoutMs: number;
106
- permissionMode: PermissionMode;
107
- systemPrompt: Record<string, unknown>;
108
- enabled: boolean;
109
- credentialConfigured?: boolean;
110
- credentialMasked?: string;
111
- }
112
-
113
- export interface CredentialInput { secret: string; }
114
-
115
- export interface ProfileTestResult {
116
- ok: true;
117
- runtime: "claude-code";
118
- runtimeVerified: true;
119
- profileId: string;
120
- model: string;
121
- firstEventMs: number;
122
- durationMs: number;
123
- resultPreview: string;
124
- }
125
-
126
- export interface HealthResult {
127
- status: "ok";
128
- version: string;
129
- apiVersion: string;
130
- activeProcesses: number;
131
- sessions: number;
132
- time: string;
133
- /** Absent on servers built before task identity existed. */
134
- taskIdentity?: TaskRuntimeIdentity;
135
- }
136
-
137
- // Task identity reported via /health. storeScope is the persistent store id
138
- // (null when the store file could not be established); runtimeEpoch is a
139
- // per-service-instance generation that is never persisted.
140
- export interface TaskRuntimeIdentity {
141
- storeScope: string | null;
142
- runtimeEpoch: string;
143
- available: boolean;
144
- errorCode: string | null;
145
- }
146
-
147
- export interface RuntimeInfo {
148
- runtime: "claude-code";
149
- available: boolean;
150
- executable: string | null;
151
- transport: string;
152
- }
153
-
154
- export interface SessionSummary {
155
- tasks?: BackgroundTask[];
156
- backgroundTaskCount?: number;
157
- sessionId: string;
158
- contextId: string;
159
- projectId: string;
160
- agentId: AgentId;
161
- title: string;
162
- active: boolean;
163
- state: string;
164
- model: string | null;
165
- aiProfileId: string | null;
166
- providerName?: string | null;
167
- authSource?: "profile-injected" | "agent-owned";
168
- selectedModel?: string | null;
169
- permissionMode: PermissionMode;
170
- archived: boolean;
171
- turns: number;
172
- startedAt: string;
173
- updatedAt: string;
174
- connectionState: string;
175
- }
176
-
177
- export type ResyncReason = "stale-cursor" | "history-gap";
178
-
179
- export interface BackgroundTask {
180
- taskId: string;
181
- parentSessionId: string;
182
- toolUseId?: string;
183
- status: 'pending' | 'running' | 'completed' | 'failed' | 'stopped';
184
- description?: string;
185
- summary?: string;
186
- lastToolName?: string;
187
- usage?: {total_tokens?: number; tool_uses?: number; duration_ms?: number};
188
- }
189
-
190
- // Task identity: opaque, already-resolved ids. storeScope is the stable storage
191
- // identity - never a port, PID or runtime epoch.
192
- export interface TaskScope {
193
- storeScope: string;
194
- contextId: string;
195
- parentSessionId: string;
196
- }
197
-
198
- export interface NativeTaskRef extends TaskScope {
199
- kind: "native-task";
200
- ownerRunId: string;
201
- taskId: string;
202
- }
203
-
204
- // Native task-history reads (GET /sessions/:id/native-tasks and POST
205
- // /sessions/:id/native-tasks/history). Every field mirrors what the reviewed
206
- // reader actually returns; null means "not observed in the journal", never a
207
- // fabricated placeholder.
208
- export type NativeTaskAssociation = "bound" | "main-command" | "unassigned";
209
- export type NativeTaskStatus = "pending" | "running" | "completed" | "failed" | "stopped";
210
-
211
- export interface NativeTaskDiagnosticItem {
212
- code: string;
213
- source: "reader" | "index" | "service";
214
- [key: string]: unknown;
215
- }
216
-
217
- export interface NativeTaskDiagnostics {
218
- items: NativeTaskDiagnosticItem[];
219
- total: number;
220
- truncated: boolean;
221
- }
222
-
223
- // One task out of the session's durable journal. taskRef is null until a
224
- // bound state row established ownership; status/statusSource are null until
225
- // a lifecycle row was observed. firstOffset/lastOffset are byte offsets into
226
- // the history file, useful only for diagnostics.
227
- export interface NativeTaskSummary {
228
- sdkSessionId: string;
229
- taskId: string;
230
- taskKind: string | null;
231
- taskType: string | null;
232
- typeConflict: boolean;
233
- status: NativeTaskStatus | null;
234
- statusSource: string | null;
235
- association: NativeTaskAssociation;
236
- taskRef: NativeTaskRef | null;
237
- ownerRunId: string | null;
238
- owner: Record<string, unknown> | null;
239
- mainToolUseId: string | null;
240
- rowCount: number;
241
- firstOffset: number;
242
- lastOffset: number;
243
- }
244
-
245
- // Verbatim journal row: type plus whatever the collector stamped. Row bodies
246
- // are not normalized by the read path. Observed row types: claude/task-*,
247
- // claude/native-trace, claude/native-task-state and
248
- // claude/native-task-transcript (see NativeTaskTranscriptRow).
249
- export interface NativeTaskHistoryRow {
250
- type: string;
251
- sequence?: number;
252
- at?: string;
253
- [key: string]: unknown;
254
- }
255
-
256
- // One claude/native-task-transcript journal row: a snapshot of a bound
257
- // agent's transcript read through the SDK's public getSubagentMessages at a
258
- // real terminal signal (SubagentStop, an SDK terminal task event, or the
259
- // bounded turn-end sweep). entries/toolSteps/usage/diagnostics carry the
260
- // normalized, redacted content; read.status carries fixed codes
261
- // ('ok' | 'unavailable' | 'failed') with content-free reason codes instead
262
- // of SDK error text; chunk marks byte-bounded slicing and whether the
263
- // snapshot read completed. source is always 'sdk-public-read'. This is a
264
- // snapshot read, never a claim of per-token streaming, and the row attaches
265
- // to the bound agent task only - never to the main reply.
266
- export interface NativeTaskTranscriptRow {
267
- type: "claude/native-task-transcript";
268
- source: "sdk-public-read";
269
- scope: TaskScope;
270
- sdkSessionId: string;
271
- taskId: string;
272
- taskRef: NativeTaskRef | null;
273
- ownerRunId: string | null;
274
- capture: string;
275
- read: { status: "ok" | "unavailable" | "failed"; reason?: string; at: string };
276
- entries: unknown[];
277
- toolSteps: unknown[];
278
- usage: { records: unknown[]; summary: unknown | null };
279
- diagnostics: unknown[];
280
- stats: unknown | null;
281
- chunk: { index: number; count: number; complete: boolean };
282
- sequence?: number;
283
- at?: string;
284
- [key: string]: unknown;
285
- }
286
-
287
- export interface NativeTaskListPage {
288
- fileId: string;
289
- tasks: NativeTaskSummary[];
290
- incomplete: string[];
291
- diagnostics: NativeTaskDiagnostics;
292
- scope: TaskScope;
293
- }
294
-
295
- export interface NativeTaskEventsPage {
296
- events: NativeTaskHistoryRow[];
297
- nextCursor: string | null;
298
- hasMore: boolean;
299
- fileId: string;
300
- incomplete: string[];
301
- diagnostics: NativeTaskDiagnostics;
302
- taskRef: NativeTaskRef;
303
- scope: TaskScope;
304
- }
305
-
306
- // Delegated sessions (POST/GET /sessions/:id/delegations). delegationId is a
307
- // Workbench server-command identity - it is NOT an SDK ownerRunId and implies
308
- // no SDK tool causality (sdkRunIdClaimed/inputCausalityClaimed stay false).
309
- // initiator states the honestly observed origin of the command; it is never
310
- // an authentication claim about a model or leader.
311
- export type DelegationPhase =
312
- | "reserved"
313
- | "child-created"
314
- | "child-create-failed"
315
- | "dispatching"
316
- | "dispatched"
317
- | "dispatch-unknown";
318
-
319
- export type DelegationOutcome =
320
- | "not-started"
321
- | "not-dispatched"
322
- | "pending"
323
- | "dispatched"
324
- | "unknown";
325
-
326
- export interface DelegatedSessionRef {
327
- kind: "delegated-session";
328
- storeScope: string;
329
- contextId: string;
330
- parentSessionId: string;
331
- delegationId: string;
332
- childSessionId: string;
333
- workspaceRef: string;
334
- }
335
-
336
- export interface DelegationCommandRecord extends DelegatedSessionRef {
337
- requestId: string;
338
- issuedAt: string;
339
- source: "workbench-delegation-command";
340
- basis: "server-command";
341
- sdkRunIdClaimed: false;
342
- inputCausalityClaimed: false;
343
- initiator: {type: "external-api"; authenticatedAs: string | null};
344
- selection: {profileId: string | null; model: string | null};
345
- }
346
-
347
- export interface DelegationDispatchState {
348
- state: "not-dispatched" | "awaiting-dispatch" | "dispatching" | "dispatched" | "dispatch-unknown";
349
- attemptId?: string;
350
- at?: string;
351
- reason?: string;
352
- code?: string;
353
- errorCode?: string;
354
- }
355
-
356
- export interface DelegationChildStatus {
357
- sessionId: string;
358
- present: boolean;
359
- state: string;
360
- agentId?: string;
361
- model?: string | null;
362
- active?: boolean;
363
- turns?: number;
364
- archived?: boolean;
365
- }
366
-
367
- export interface DelegationView {
368
- delegation: DelegationCommandRecord;
369
- phase: DelegationPhase;
370
- outcome: DelegationOutcome;
371
- dispatch: DelegationDispatchState;
372
- child: DelegationChildStatus;
373
- }
374
-
375
- export interface DelegationAcceptResult extends DelegationView {
376
- accepted: boolean;
377
- }
378
-
379
- export interface DelegationListPage {
380
- scope: TaskScope;
381
- delegations: DelegationView[];
382
- }
383
-
384
- // POST /sessions/:id/delegations request body. parentSessionId comes from the
385
- // route only; delegationId/childSessionId/workspaceRef are server-generated.
386
- export interface DelegationCommandInput {
387
- scope: {storeScope: string; contextId: string};
388
- requestId: string;
389
- text: string;
390
- agentId?: string;
391
- aiProfileId?: string | null;
392
- model?: string | null;
393
- permissionMode?: PermissionMode;
394
- effort?: EffortLevel;
395
- }
396
-
397
- export interface SessionChangeEvent {
398
- type: 'workbench/session-changed' | 'workbench/sessions-snapshot' | 'workbench/resync';
399
- revision: number;
400
- contextId?: string;
401
- session?: SessionSummary;
402
- sessions?: SessionSummary[];
403
- deleted?: boolean;
404
- }
405
-
406
- export interface WorkbenchResyncEvent {
407
- type: "workbench/resync";
408
- sessionId: string;
409
- contextId: string;
410
- at?: string;
411
- reason: ResyncReason;
412
- from: number;
413
- highWater: number;
414
- firstSequence: number;
415
- }
416
-
417
- export interface WorkbenchEvent {
418
- type: string;
419
- sessionId: string;
420
- contextId: string;
421
- sequence?: number;
422
- at: string;
423
- [key: string]: unknown;
424
- }
425
-
426
- export interface ImageAttachmentInput {
427
- id?: string;
428
- name: string;
429
- mediaType: "image/jpeg" | "image/png" | "image/gif" | "image/webp";
430
- data: string;
431
- size?: number;
432
- width?: number;
433
- height?: number;
434
- }
435
-
436
- export interface ImageAttachment {
437
- id: string;
438
- name: string;
439
- mediaType: ImageAttachmentInput["mediaType"];
440
- size: number;
441
- width?: number;
442
- height?: number;
443
- url: string;
444
- }
445
-
446
- export interface TextAttachmentInput {
447
- id?: string;
448
- name: string;
449
- mediaType: "text/plain" | "text/markdown" | "application/json" | "text/csv";
450
- data: string;
451
- size?: number;
452
- }
453
-
454
- export type AttachmentInput = ImageAttachmentInput | TextAttachmentInput;
455
- export interface TextAttachment {
456
- id: string;
457
- name: string;
458
- mediaType: TextAttachmentInput["mediaType"];
459
- size: number;
460
- url: string;
461
- }
462
- export type Attachment = ImageAttachment | TextAttachment;
463
-
464
- export interface SlashCommand {
465
- name: string;
466
- description: string;
467
- argumentHint?: string;
468
- aliases?: string[];
469
- source?: string;
470
- }
471
-
472
- export interface SessionSnapshot {
473
- session: SessionSummary;
474
- events: WorkbenchEvent[];
475
- permission: Record<string, unknown> | null;
476
- permissionMode: PermissionMode;
477
- tokenUsage: Record<string, unknown>;
478
- }
479
-
480
- export interface SessionHistoryPage {
481
- events: WorkbenchEvent[];
482
- nextCursor: string | null;
483
- incomplete: boolean;
484
- highWater: number;
485
- }
486
-
487
- export declare const API_VERSION: "v1";
488
- export declare const DEFAULT_API_PREFIX: "/api/claude-workbench/v1";
489
- export declare const RUNTIME: "claude-code";
490
- export declare const DEFAULT_AGENT: AgentId;
491
- export declare const AGENT_IDS: readonly AgentId[];
492
- export declare const EFFORT_LEVELS: readonly EffortLevel[];
493
- export declare const AGENTS: Record<AgentId, AgentDefinition>;
494
- export declare const PERMISSION_MODES: readonly PermissionMode[];
495
- export declare const IMAGE_MEDIA_TYPES: readonly ImageAttachmentInput["mediaType"][];
496
- export declare const TEXT_MEDIA_TYPES: readonly TextAttachmentInput["mediaType"][];
497
- export declare const TEXT_FILE_TYPES: Readonly<Record<string, TextAttachmentInput["mediaType"]>>;
498
- export declare const MAX_IMAGE_BYTES: number;
499
- export declare const MAX_IMAGES_PER_MESSAGE: number;
500
- export declare const MAX_IMAGE_MESSAGE_BYTES: number;
501
- export declare const MAX_TEXT_BYTES: number;
502
- export declare const MAX_ATTACHMENTS_PER_MESSAGE: number;
503
- export declare const MAX_ATTACHMENT_MESSAGE_BYTES: number;
504
- export declare const EVENT_TYPES: readonly string[];
505
- export declare function cleanId(value: unknown, field?: string): string;
506
- export declare function normalizeContext(input: unknown): WorkbenchContext;
507
- export declare function normalizeProfile(input: unknown, idOverride?: string): AiProfile;
508
- export declare function normalizeProject(input: unknown, idOverride?: string): Project;
509
- export declare function normalizeAgentId(value: unknown): AgentId;
510
- export declare function normalizeEffort(value: unknown): EffortLevel | undefined;
511
- export declare function normalizeModelEntries(input: unknown): ModelListEntry[];
512
- export declare function normalizeImageAttachments(input: unknown): Array<ImageAttachmentInput & { size: number }>;
513
- export declare function normalizeAttachments(input: unknown): Array<AttachmentInput & { size: number }>;
514
- export declare function appendTextAttachments(text: string, attachments?: AttachmentInput[]): string;
515
- export declare function resolveOpenAIBaseUrl(profile?: Partial<AiProfileInput>): string;
516
- export declare function resolveOpenAIModel(profile?: Partial<AiProfileInput> & { mainModel?: string }, model?: string): string;
517
- export declare function positiveInt(value: unknown, fallback: number): number;
1
+ export type PermissionMode = "default" | "acceptEdits" | "plan" | "bypassPermissions";
2
+ export type ProfileProtocol = "anthropic-compatible" | "openai-compatible" | string;
3
+ export type AgentId = "claude-code" | "codex" | "opencode" | "zcode";
4
+ export type EffortLevel = "low" | "medium" | "high" | "max";
5
+
6
+ export interface AgentCapabilities {
7
+ backgroundTasks?: boolean;
8
+ thinking: boolean;
9
+ permissions: boolean;
10
+ toolStream: boolean;
11
+ images: boolean;
12
+ resume: true;
13
+ modelOverride: boolean;
14
+ generationParams: readonly string[];
15
+ }
16
+
17
+ export interface AgentDefinition {
18
+ id: AgentId;
19
+ label: string;
20
+ transport: string;
21
+ authModes: readonly string[];
22
+ capabilities: AgentCapabilities;
23
+ }
24
+
25
+ export interface AgentStatus extends AgentDefinition {
26
+ scanState?: 'unknown' | 'ready' | 'error';
27
+ checkedAt?: string;
28
+ errorCode?: string | null;
29
+ capabilities: { generationParams: string[] } & Omit<AgentCapabilities, "generationParams">;
30
+ available: boolean;
31
+ version: string | null;
32
+ }
33
+
34
+ export interface Project {
35
+ id: string;
36
+ name: string;
37
+ rootPath: string;
38
+ createdAt: string;
39
+ updatedAt: string;
40
+ defaultAiProfileId?: string | null;
41
+ defaultModel?: string | null;
42
+ defaultAgentId?: AgentId;
43
+ }
44
+
45
+ export interface ProjectInput {
46
+ name: string;
47
+ rootPath: string;
48
+ defaultAiProfileId?: string | null;
49
+ defaultModel?: string | null;
50
+ defaultAgentId?: AgentId;
51
+ }
52
+
53
+ export type ProjectPatch = Partial<Omit<ProjectInput, "rootPath">>;
54
+
55
+ export interface ModelListEntry {
56
+ id: string;
57
+ openaiId?: string;
58
+ label: string;
59
+ tags: string[];
60
+ }
61
+
62
+ export interface WorkbenchContext {
63
+ contextId: string;
64
+ contextType?: string;
65
+ displayName?: string;
66
+ workspaceRef?: string;
67
+ aiProfileId?: string | null;
68
+ model?: string | null;
69
+ metadata?: Record<string, unknown>;
70
+ }
71
+
72
+ export interface AiProfileModels {
73
+ default: string;
74
+ fast?: string;
75
+ reasoning?: string;
76
+ coding?: string;
77
+ largeContext?: string;
78
+ list?: ModelListEntry[];
79
+ [role: string]: string | undefined | ModelListEntry[];
80
+ }
81
+
82
+ export interface AiProfileInput {
83
+ id: string;
84
+ name?: string;
85
+ provider: string;
86
+ protocol?: ProfileProtocol;
87
+ runtime?: "claude-code";
88
+ baseUrl: string;
89
+ openaiBaseUrl?: string;
90
+ credentialRef?: string;
91
+ models: AiProfileModels;
92
+ contextWindow?: number;
93
+ timeoutMs?: number;
94
+ permissionMode?: PermissionMode;
95
+ systemPrompt?: Record<string, unknown> | string;
96
+ enabled?: boolean;
97
+ }
98
+
99
+ export interface AiProfile extends AiProfileInput {
100
+ name: string;
101
+ protocol: ProfileProtocol;
102
+ runtime: "claude-code";
103
+ credentialRef: string;
104
+ contextWindow: number;
105
+ timeoutMs: number;
106
+ permissionMode: PermissionMode;
107
+ systemPrompt: Record<string, unknown>;
108
+ enabled: boolean;
109
+ credentialConfigured?: boolean;
110
+ credentialMasked?: string;
111
+ }
112
+
113
+ export interface CredentialInput { secret: string; }
114
+
115
+ export interface ProfileTestResult {
116
+ ok: true;
117
+ runtime: "claude-code";
118
+ runtimeVerified: true;
119
+ profileId: string;
120
+ model: string;
121
+ firstEventMs: number;
122
+ durationMs: number;
123
+ resultPreview: string;
124
+ }
125
+
126
+ export interface HealthResult {
127
+ status: "ok";
128
+ version: string;
129
+ apiVersion: string;
130
+ activeProcesses: number;
131
+ sessions: number;
132
+ time: string;
133
+ /** Absent on servers built before task identity existed. */
134
+ taskIdentity?: TaskRuntimeIdentity;
135
+ }
136
+
137
+ // Task identity reported via /health. storeScope is the persistent store id
138
+ // (null when the store file could not be established); runtimeEpoch is a
139
+ // per-service-instance generation that is never persisted.
140
+ export interface TaskRuntimeIdentity {
141
+ storeScope: string | null;
142
+ runtimeEpoch: string;
143
+ available: boolean;
144
+ errorCode: string | null;
145
+ }
146
+
147
+ export interface RuntimeInfo {
148
+ runtime: "claude-code";
149
+ available: boolean;
150
+ executable: string | null;
151
+ transport: string;
152
+ }
153
+
154
+ export interface SessionSummary {
155
+ tasks?: BackgroundTask[];
156
+ backgroundTaskCount?: number;
157
+ sessionId: string;
158
+ contextId: string;
159
+ projectId: string;
160
+ agentId: AgentId;
161
+ title: string;
162
+ active: boolean;
163
+ state: string;
164
+ model: string | null;
165
+ aiProfileId: string | null;
166
+ providerName?: string | null;
167
+ authSource?: "profile-injected" | "agent-owned";
168
+ selectedModel?: string | null;
169
+ permissionMode: PermissionMode;
170
+ archived: boolean;
171
+ turns: number;
172
+ startedAt: string;
173
+ updatedAt: string;
174
+ connectionState: string;
175
+ }
176
+
177
+ export type ResyncReason = "stale-cursor" | "history-gap";
178
+
179
+ export interface BackgroundTask {
180
+ taskId: string;
181
+ parentSessionId: string;
182
+ toolUseId?: string;
183
+ status: 'pending' | 'running' | 'completed' | 'failed' | 'stopped';
184
+ description?: string;
185
+ summary?: string;
186
+ lastToolName?: string;
187
+ usage?: {total_tokens?: number; tool_uses?: number; duration_ms?: number};
188
+ }
189
+
190
+ // Task identity: opaque, already-resolved ids. storeScope is the stable storage
191
+ // identity - never a port, PID or runtime epoch.
192
+ export interface TaskScope {
193
+ storeScope: string;
194
+ contextId: string;
195
+ parentSessionId: string;
196
+ }
197
+
198
+ export interface NativeTaskRef extends TaskScope {
199
+ kind: "native-task";
200
+ ownerRunId: string;
201
+ taskId: string;
202
+ }
203
+
204
+ // Native task-history reads (GET /sessions/:id/native-tasks and POST
205
+ // /sessions/:id/native-tasks/history). Every field mirrors what the reviewed
206
+ // reader actually returns; null means "not observed in the journal", never a
207
+ // fabricated placeholder.
208
+ export type NativeTaskAssociation = "bound" | "main-command" | "unassigned";
209
+ export type NativeTaskStatus = "pending" | "running" | "completed" | "failed" | "stopped";
210
+
211
+ export interface NativeTaskDiagnosticItem {
212
+ code: string;
213
+ source: "reader" | "index" | "service";
214
+ [key: string]: unknown;
215
+ }
216
+
217
+ export interface NativeTaskDiagnostics {
218
+ items: NativeTaskDiagnosticItem[];
219
+ total: number;
220
+ truncated: boolean;
221
+ }
222
+
223
+ // One task out of the session's durable journal. taskRef is null until a
224
+ // bound state row established ownership; status/statusSource are null until
225
+ // a lifecycle row was observed. firstOffset/lastOffset are byte offsets into
226
+ // the history file, useful only for diagnostics.
227
+ export interface NativeTaskSummary {
228
+ sdkSessionId: string;
229
+ taskId: string;
230
+ taskKind: string | null;
231
+ taskType: string | null;
232
+ typeConflict: boolean;
233
+ status: NativeTaskStatus | null;
234
+ statusSource: string | null;
235
+ association: NativeTaskAssociation;
236
+ taskRef: NativeTaskRef | null;
237
+ ownerRunId: string | null;
238
+ owner: Record<string, unknown> | null;
239
+ mainToolUseId: string | null;
240
+ rowCount: number;
241
+ firstOffset: number;
242
+ lastOffset: number;
243
+ }
244
+
245
+ // Verbatim journal row: type plus whatever the collector stamped. Row bodies
246
+ // are not normalized by the read path. Observed row types: claude/task-*,
247
+ // claude/native-trace, claude/native-task-state and
248
+ // claude/native-task-transcript (see NativeTaskTranscriptRow).
249
+ export interface NativeTaskHistoryRow {
250
+ type: string;
251
+ sequence?: number;
252
+ at?: string;
253
+ [key: string]: unknown;
254
+ }
255
+
256
+ // One claude/native-task-transcript journal row: a snapshot of a bound
257
+ // agent's transcript read through the SDK's public getSubagentMessages at a
258
+ // real terminal signal (SubagentStop, an SDK terminal task event, or the
259
+ // bounded turn-end sweep). entries/toolSteps/usage/diagnostics carry the
260
+ // normalized, redacted content; read.status carries fixed codes
261
+ // ('ok' | 'unavailable' | 'failed') with content-free reason codes instead
262
+ // of SDK error text; chunk marks byte-bounded slicing and whether the
263
+ // snapshot read completed. source is always 'sdk-public-read'. This is a
264
+ // snapshot read, never a claim of per-token streaming, and the row attaches
265
+ // to the bound agent task only - never to the main reply.
266
+ export interface NativeTaskTranscriptRow {
267
+ type: "claude/native-task-transcript";
268
+ source: "sdk-public-read";
269
+ scope: TaskScope;
270
+ sdkSessionId: string;
271
+ taskId: string;
272
+ taskRef: NativeTaskRef | null;
273
+ ownerRunId: string | null;
274
+ capture: string;
275
+ read: { status: "ok" | "unavailable" | "failed"; reason?: string; at: string };
276
+ entries: unknown[];
277
+ toolSteps: unknown[];
278
+ usage: { records: unknown[]; summary: unknown | null };
279
+ diagnostics: unknown[];
280
+ stats: unknown | null;
281
+ chunk: { index: number; count: number; complete: boolean };
282
+ sequence?: number;
283
+ at?: string;
284
+ [key: string]: unknown;
285
+ }
286
+
287
+ export interface NativeTaskListPage {
288
+ fileId: string;
289
+ tasks: NativeTaskSummary[];
290
+ incomplete: string[];
291
+ diagnostics: NativeTaskDiagnostics;
292
+ scope: TaskScope;
293
+ }
294
+
295
+ export interface NativeTaskEventsPage {
296
+ events: NativeTaskHistoryRow[];
297
+ nextCursor: string | null;
298
+ hasMore: boolean;
299
+ fileId: string;
300
+ incomplete: string[];
301
+ diagnostics: NativeTaskDiagnostics;
302
+ taskRef: NativeTaskRef;
303
+ scope: TaskScope;
304
+ }
305
+
306
+ // Delegated sessions (POST/GET /sessions/:id/delegations). delegationId is a
307
+ // Workbench server-command identity - it is NOT an SDK ownerRunId and implies
308
+ // no SDK tool causality (sdkRunIdClaimed/inputCausalityClaimed stay false).
309
+ // initiator states the honestly observed origin of the command; it is never
310
+ // an authentication claim about a model or leader.
311
+ export type DelegationPhase =
312
+ | "reserved"
313
+ | "child-created"
314
+ | "child-create-failed"
315
+ | "dispatching"
316
+ | "dispatched"
317
+ | "dispatch-unknown";
318
+
319
+ export type DelegationOutcome =
320
+ | "not-started"
321
+ | "not-dispatched"
322
+ | "pending"
323
+ | "dispatched"
324
+ | "unknown";
325
+
326
+ export interface DelegatedSessionRef {
327
+ kind: "delegated-session";
328
+ storeScope: string;
329
+ contextId: string;
330
+ parentSessionId: string;
331
+ delegationId: string;
332
+ childSessionId: string;
333
+ workspaceRef: string;
334
+ }
335
+
336
+ export interface DelegationCommandRecord extends DelegatedSessionRef {
337
+ requestId: string;
338
+ issuedAt: string;
339
+ source: "workbench-delegation-command";
340
+ basis: "server-command";
341
+ sdkRunIdClaimed: false;
342
+ inputCausalityClaimed: false;
343
+ initiator: {type: "external-api"; authenticatedAs: string | null};
344
+ selection: {profileId: string | null; model: string | null};
345
+ }
346
+
347
+ export interface DelegationDispatchState {
348
+ state: "not-dispatched" | "awaiting-dispatch" | "dispatching" | "dispatched" | "dispatch-unknown";
349
+ attemptId?: string;
350
+ at?: string;
351
+ reason?: string;
352
+ code?: string;
353
+ errorCode?: string;
354
+ }
355
+
356
+ export interface DelegationChildStatus {
357
+ sessionId: string;
358
+ present: boolean;
359
+ state: string;
360
+ agentId?: string;
361
+ model?: string | null;
362
+ active?: boolean;
363
+ turns?: number;
364
+ archived?: boolean;
365
+ }
366
+
367
+ export interface DelegationView {
368
+ context?: { mode: 'parent-snapshot'; truncated: boolean };
369
+ delegation: DelegationCommandRecord;
370
+ phase: DelegationPhase;
371
+ outcome: DelegationOutcome;
372
+ dispatch: DelegationDispatchState;
373
+ child: DelegationChildStatus;
374
+ }
375
+
376
+ export interface DelegationAcceptResult extends DelegationView {
377
+ accepted: boolean;
378
+ }
379
+
380
+ export interface DelegationListPage {
381
+ scope: TaskScope;
382
+ delegations: DelegationView[];
383
+ }
384
+
385
+ // POST /sessions/:id/delegations request body. parentSessionId comes from the
386
+ // route only; delegationId/childSessionId/workspaceRef are server-generated.
387
+ export interface DelegationCommandInput {
388
+ contextMode?: 'parent-snapshot';
389
+ scope: {storeScope: string; contextId: string};
390
+ requestId: string;
391
+ text: string;
392
+ agentId?: string;
393
+ aiProfileId?: string | null;
394
+ model?: string | null;
395
+ permissionMode?: PermissionMode;
396
+ effort?: EffortLevel;
397
+ }
398
+
399
+ export interface SessionChangeEvent {
400
+ type: 'workbench/session-changed' | 'workbench/sessions-snapshot' | 'workbench/resync';
401
+ revision: number;
402
+ contextId?: string;
403
+ session?: SessionSummary;
404
+ sessions?: SessionSummary[];
405
+ deleted?: boolean;
406
+ }
407
+
408
+ export interface WorkbenchResyncEvent {
409
+ type: "workbench/resync";
410
+ sessionId: string;
411
+ contextId: string;
412
+ at?: string;
413
+ reason: ResyncReason;
414
+ from: number;
415
+ highWater: number;
416
+ firstSequence: number;
417
+ }
418
+
419
+ export interface WorkbenchEvent {
420
+ type: string;
421
+ sessionId: string;
422
+ contextId: string;
423
+ sequence?: number;
424
+ at: string;
425
+ [key: string]: unknown;
426
+ }
427
+
428
+ export interface ImageAttachmentInput {
429
+ id?: string;
430
+ name: string;
431
+ mediaType: "image/jpeg" | "image/png" | "image/gif" | "image/webp";
432
+ data: string;
433
+ size?: number;
434
+ width?: number;
435
+ height?: number;
436
+ }
437
+
438
+ export interface ImageAttachment {
439
+ id: string;
440
+ name: string;
441
+ mediaType: ImageAttachmentInput["mediaType"];
442
+ size: number;
443
+ width?: number;
444
+ height?: number;
445
+ url: string;
446
+ }
447
+
448
+ export interface TextAttachmentInput {
449
+ id?: string;
450
+ name: string;
451
+ mediaType: "text/plain" | "text/markdown" | "application/json" | "text/csv";
452
+ data: string;
453
+ size?: number;
454
+ }
455
+
456
+ export type AttachmentInput = ImageAttachmentInput | TextAttachmentInput;
457
+ export interface TextAttachment {
458
+ id: string;
459
+ name: string;
460
+ mediaType: TextAttachmentInput["mediaType"];
461
+ size: number;
462
+ url: string;
463
+ }
464
+ export type Attachment = ImageAttachment | TextAttachment;
465
+
466
+ export interface SlashCommand {
467
+ name: string;
468
+ description: string;
469
+ argumentHint?: string;
470
+ aliases?: string[];
471
+ source?: string;
472
+ }
473
+
474
+ export interface SessionSnapshot {
475
+ session: SessionSummary;
476
+ events: WorkbenchEvent[];
477
+ permission: Record<string, unknown> | null;
478
+ permissionMode: PermissionMode;
479
+ tokenUsage: Record<string, unknown>;
480
+ }
481
+
482
+ export interface SessionHistoryPage {
483
+ events: WorkbenchEvent[];
484
+ nextCursor: string | null;
485
+ incomplete: boolean;
486
+ highWater: number;
487
+ }
488
+
489
+ export declare const API_VERSION: "v1";
490
+ export declare const DEFAULT_API_PREFIX: "/api/claude-workbench/v1";
491
+ export declare const RUNTIME: "claude-code";
492
+ export declare const DEFAULT_AGENT: AgentId;
493
+ export declare const AGENT_IDS: readonly AgentId[];
494
+ export declare const EFFORT_LEVELS: readonly EffortLevel[];
495
+ export declare const AGENTS: Record<AgentId, AgentDefinition>;
496
+ export declare const PERMISSION_MODES: readonly PermissionMode[];
497
+ export declare const IMAGE_MEDIA_TYPES: readonly ImageAttachmentInput["mediaType"][];
498
+ export declare const TEXT_MEDIA_TYPES: readonly TextAttachmentInput["mediaType"][];
499
+ export declare const TEXT_FILE_TYPES: Readonly<Record<string, TextAttachmentInput["mediaType"]>>;
500
+ export declare const MAX_IMAGE_BYTES: number;
501
+ export declare const MAX_IMAGES_PER_MESSAGE: number;
502
+ export declare const MAX_IMAGE_MESSAGE_BYTES: number;
503
+ export declare const MAX_TEXT_BYTES: number;
504
+ export declare const MAX_ATTACHMENTS_PER_MESSAGE: number;
505
+ export declare const MAX_ATTACHMENT_MESSAGE_BYTES: number;
506
+ export declare const EVENT_TYPES: readonly string[];
507
+ export declare function cleanId(value: unknown, field?: string): string;
508
+ export declare function normalizeContext(input: unknown): WorkbenchContext;
509
+ export declare function normalizeProfile(input: unknown, idOverride?: string): AiProfile;
510
+ export declare function normalizeProject(input: unknown, idOverride?: string): Project;
511
+ export declare function normalizeAgentId(value: unknown): AgentId;
512
+ export declare function normalizeEffort(value: unknown): EffortLevel | undefined;
513
+ export declare function normalizeModelEntries(input: unknown): ModelListEntry[];
514
+ export declare function normalizeImageAttachments(input: unknown): Array<ImageAttachmentInput & { size: number }>;
515
+ export declare function normalizeAttachments(input: unknown): Array<AttachmentInput & { size: number }>;
516
+ export declare function appendTextAttachments(text: string, attachments?: AttachmentInput[]): string;
517
+ export declare function resolveOpenAIBaseUrl(profile?: Partial<AiProfileInput>): string;
518
+ export declare function resolveOpenAIModel(profile?: Partial<AiProfileInput> & { mainModel?: string }, model?: string): string;
519
+ export declare function positiveInt(value: unknown, fallback: number): number;