@cuylabs/agent-server 0.10.0

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,893 @@
1
+ import * as _cuylabs_agent_core from '@cuylabs/agent-core';
2
+ import { PluginCommandMetadata, FileEntry, Message, TokenUsage, QueuedFollowUpRecord, FollowUpStatus, AgentEvent, ApprovalAction, ApprovalRememberScope, HumanInputResponse, ApprovalRequest, HumanInputRequest, SteeringResponse, FollowUpResponse, FollowUpDecisionAction, FollowUpPolicy, PendingIntervention, SessionInfo, SessionStorage, Agent } from '@cuylabs/agent-core';
3
+ import { CoordinatorNotificationKind, CoordinatorNotification } from '@cuylabs/agent-core/team';
4
+ import { EventBus } from '@cuylabs/agent-core/events';
5
+ import { Readable, Writable } from 'node:stream';
6
+ import { Server } from 'node:http';
7
+ import { Server as Server$1 } from 'node:https';
8
+
9
+ type Unsubscribe = () => void;
10
+ type AgentServerTransportKind = "in-process" | "stdio" | "websocket" | "http";
11
+ type AgentServerExecutionMode = "local" | "remote" | "hybrid";
12
+ type AgentServerDurabilityMode = "process" | "workflow";
13
+ type AgentServerOrchestrationBackend = "direct" | "agent-runtime" | "agent-runtime-dapr";
14
+ interface AppPluginCommandInfo {
15
+ pluginId?: string;
16
+ name: string;
17
+ alias: string[];
18
+ summary: string;
19
+ metadata?: PluginCommandMetadata;
20
+ }
21
+ interface AgentServerPluginCommand extends AppPluginCommandInfo {
22
+ execute(args: string): Promise<string | null> | string | null;
23
+ }
24
+ interface AppToolInfo {
25
+ id: string;
26
+ }
27
+ interface AppSkillInfo {
28
+ name: string;
29
+ description: string;
30
+ scope: string;
31
+ filePath?: string;
32
+ tags: string[];
33
+ }
34
+ interface AppSubAgentProfileInfo {
35
+ name: string;
36
+ description: string;
37
+ source: "builtin" | "user" | "project" | "config";
38
+ filePath?: string;
39
+ maxSteps?: number;
40
+ allowFurtherDispatch?: boolean;
41
+ }
42
+ interface AppModelState {
43
+ label: string;
44
+ switchable: boolean;
45
+ }
46
+ interface AppWorkspaceSummarySnapshot {
47
+ workspace: {
48
+ cwd: string;
49
+ sessionCount: number;
50
+ };
51
+ agent: {
52
+ modelLabel: string;
53
+ switchable: boolean;
54
+ toolCount: number;
55
+ skillCount: number;
56
+ subAgentCount: number;
57
+ };
58
+ }
59
+ interface AppRuntimeStatusSnapshot {
60
+ session: {
61
+ selectedId: string;
62
+ loadedId?: string;
63
+ messageCount: number;
64
+ leafId?: string;
65
+ cwd?: string;
66
+ title?: string;
67
+ };
68
+ model: {
69
+ id: string;
70
+ provider?: string;
71
+ };
72
+ context: {
73
+ tokens: number;
74
+ limit: number;
75
+ available: number;
76
+ utilizationPercent: number;
77
+ isOverflowing: boolean;
78
+ shouldPrune: boolean;
79
+ };
80
+ }
81
+ type AppModelSwitchResult = {
82
+ ok: true;
83
+ label: string;
84
+ } | {
85
+ ok: false;
86
+ error?: string;
87
+ };
88
+ interface AppContextCompactionResult {
89
+ removedCount: number;
90
+ tokensRemoved: number;
91
+ summarized: boolean;
92
+ summary?: string;
93
+ }
94
+ interface AppUndoFailure {
95
+ path: string;
96
+ reason: string;
97
+ }
98
+ interface AppUndoResult {
99
+ restored: string[];
100
+ failed: AppUndoFailure[];
101
+ }
102
+ type AppSessionRuntimeStatus = "idle" | "running";
103
+ type AppTurnStatus = "running" | "completed" | "failed" | "interrupted";
104
+ interface AppSessionRuntime {
105
+ status: AppSessionRuntimeStatus;
106
+ activeTurnCount: number;
107
+ activeTurnIds: string[];
108
+ lastTurnId?: string;
109
+ }
110
+ interface AppSessionSummary {
111
+ id: string;
112
+ cwd: string;
113
+ createdAt: string;
114
+ updatedAt: string;
115
+ messageCount: number;
116
+ title?: string;
117
+ name?: string;
118
+ parentSessionId?: string;
119
+ preview?: string;
120
+ runtime: AppSessionRuntime;
121
+ }
122
+ interface AppSessionDetail extends AppSessionSummary {
123
+ leafId?: string;
124
+ entries: FileEntry[];
125
+ messages: Message[];
126
+ }
127
+ interface AppTurnEventRecord {
128
+ sequence: number;
129
+ timestamp: string;
130
+ event: AgentEvent;
131
+ }
132
+ interface AppTurnSnapshot {
133
+ id: string;
134
+ sessionId: string;
135
+ message: string;
136
+ startedAt: string;
137
+ status: AppTurnStatus;
138
+ completedAt?: string;
139
+ output?: string;
140
+ usage?: TokenUsage;
141
+ error?: string;
142
+ queuedFollowUps?: QueuedFollowUpRecord[];
143
+ }
144
+ interface AppTurnDetail extends AppTurnSnapshot {
145
+ events: AppTurnEventRecord[];
146
+ }
147
+ interface CreateSessionOptions {
148
+ id?: string;
149
+ cwd?: string;
150
+ title?: string;
151
+ }
152
+ interface BranchSessionOptions {
153
+ leafId?: string;
154
+ summary?: string;
155
+ }
156
+ interface StartTurnOptions {
157
+ system?: string;
158
+ }
159
+ interface AppApprovalInputRequest {
160
+ id: string;
161
+ kind: "approval";
162
+ sessionId: string;
163
+ turnId?: string;
164
+ createdAt: string;
165
+ request: ApprovalRequest;
166
+ }
167
+ interface AppHumanInputRequest {
168
+ id: string;
169
+ kind: "human";
170
+ sessionId: string;
171
+ turnId?: string;
172
+ createdAt: string;
173
+ request: HumanInputRequest;
174
+ }
175
+ interface ResolveApprovalInputPayload {
176
+ kind: "approval";
177
+ action: ApprovalAction;
178
+ feedback?: string;
179
+ rememberScope?: ApprovalRememberScope;
180
+ }
181
+ interface ResolveHumanInputPayload {
182
+ kind: "human";
183
+ response: HumanInputResponse;
184
+ }
185
+ type AppInputRequest = AppApprovalInputRequest | AppHumanInputRequest;
186
+ type ResolveInputRequestPayload = ResolveApprovalInputPayload | ResolveHumanInputPayload;
187
+ type AppTeamNotification = CoordinatorNotification;
188
+ interface AppTeamNotificationListOptions {
189
+ teamId?: string;
190
+ memberId?: string;
191
+ kind?: CoordinatorNotificationKind | CoordinatorNotificationKind[];
192
+ }
193
+ interface WaitForTurnOptions {
194
+ timeoutMs?: number;
195
+ }
196
+ interface AppFollowUpListOptions {
197
+ sessionId?: string;
198
+ sourceTurnId?: string;
199
+ status?: FollowUpStatus | FollowUpStatus[];
200
+ }
201
+
202
+ interface AgentServerCapabilities {
203
+ protocol: {
204
+ version: 1;
205
+ transport: AgentServerTransportKind;
206
+ reconnectable: boolean;
207
+ multiClient: boolean;
208
+ };
209
+ sessions: {
210
+ persistent: boolean;
211
+ list: boolean;
212
+ create: boolean;
213
+ read: boolean;
214
+ delete: boolean;
215
+ branch: boolean;
216
+ };
217
+ turns: {
218
+ start: boolean;
219
+ wait: boolean;
220
+ interrupt: boolean;
221
+ steer: boolean;
222
+ followUp: boolean;
223
+ followUpManagement: boolean;
224
+ eventStreaming: boolean;
225
+ concurrentTurnsPerSession: boolean;
226
+ };
227
+ interactive: {
228
+ approvalRequests: boolean;
229
+ humanRequests: boolean;
230
+ };
231
+ runtime: {
232
+ execution: AgentServerExecutionMode;
233
+ orchestration: AgentServerOrchestrationBackend;
234
+ durability: AgentServerDurabilityMode;
235
+ dapr: {
236
+ available: boolean;
237
+ delegatedTurns: boolean;
238
+ workflowBacked: boolean;
239
+ };
240
+ };
241
+ agent: {
242
+ workspaceSummary: boolean;
243
+ toolInventory: boolean;
244
+ skillInspection: boolean;
245
+ subAgentInspection: boolean;
246
+ modelInspection: boolean;
247
+ modelSwitch: boolean;
248
+ runtimeStatus: boolean;
249
+ contextCompaction: boolean;
250
+ turnUndo: boolean;
251
+ turnDiff: boolean;
252
+ };
253
+ plugins: {
254
+ headlessOnly: boolean;
255
+ commandMetadata: boolean;
256
+ commandDiscovery: boolean;
257
+ commandExecution: boolean;
258
+ clientExtensions: boolean;
259
+ };
260
+ events: {
261
+ eventBus: boolean;
262
+ pubSubBridge: boolean;
263
+ sseStreaming: boolean;
264
+ eventReplay: boolean;
265
+ };
266
+ }
267
+ interface AgentServerCapabilitiesPatch {
268
+ protocol?: Partial<AgentServerCapabilities["protocol"]>;
269
+ sessions?: Partial<AgentServerCapabilities["sessions"]>;
270
+ turns?: Partial<AgentServerCapabilities["turns"]>;
271
+ interactive?: Partial<AgentServerCapabilities["interactive"]>;
272
+ runtime?: Partial<Omit<AgentServerCapabilities["runtime"], "dapr">> & {
273
+ dapr?: Partial<AgentServerCapabilities["runtime"]["dapr"]>;
274
+ };
275
+ agent?: Partial<AgentServerCapabilities["agent"]>;
276
+ plugins?: Partial<AgentServerCapabilities["plugins"]>;
277
+ events?: Partial<AgentServerCapabilities["events"]>;
278
+ }
279
+ declare function createDefaultAgentServerCapabilities(): AgentServerCapabilities;
280
+ declare function mergeAgentServerCapabilities(base: AgentServerCapabilities, override?: AgentServerCapabilitiesPatch): AgentServerCapabilities;
281
+
282
+ interface AgentServerSubscriptionOptions {
283
+ sessionId?: string;
284
+ turnId?: string;
285
+ teamId?: string;
286
+ }
287
+ type AgentServerNotification = {
288
+ type: "session/created";
289
+ session: AppSessionSummary;
290
+ } | {
291
+ type: "session/deleted";
292
+ sessionId: string;
293
+ } | {
294
+ type: "session/branched";
295
+ sessionId: string;
296
+ leafId: string;
297
+ summary?: string;
298
+ } | {
299
+ type: "session/runtime";
300
+ sessionId: string;
301
+ runtime: AppSessionRuntime;
302
+ } | {
303
+ type: "turn/started";
304
+ turn: AppTurnSnapshot;
305
+ } | {
306
+ type: "turn/event";
307
+ sessionId: string;
308
+ turnId: string;
309
+ sequence: number;
310
+ timestamp: string;
311
+ event: AgentEvent;
312
+ } | {
313
+ type: "input/request";
314
+ request: AppInputRequest;
315
+ } | {
316
+ type: "input/resolved";
317
+ requestId: string;
318
+ sessionId: string;
319
+ turnId?: string;
320
+ } | {
321
+ type: "team/notification";
322
+ teamId: string;
323
+ notification: AppTeamNotification;
324
+ } | {
325
+ type: "turn/completed";
326
+ turn: AppTurnSnapshot;
327
+ };
328
+ /**
329
+ * Returns true when `notification` matches the given subscription filter.
330
+ * Used by both the in-process server and the remote client.
331
+ */
332
+ declare function matchesNotificationSubscription(notification: AgentServerNotification, options?: AgentServerSubscriptionOptions): boolean;
333
+
334
+ interface AgentServerAdapter {
335
+ readonly cwd: string;
336
+ getCapabilities?(): AgentServerCapabilitiesPatch;
337
+ getModelState?(): Promise<AppModelState> | AppModelState;
338
+ switchModel?(spec: string): Promise<AppModelSwitchResult> | AppModelSwitchResult;
339
+ getSessionRuntimeStatus?(sessionId: string): Promise<AppRuntimeStatusSnapshot> | AppRuntimeStatusSnapshot;
340
+ listTools?(): Promise<AppToolInfo[]> | AppToolInfo[];
341
+ listSkills?(): Promise<AppSkillInfo[]> | AppSkillInfo[];
342
+ listSubAgents?(): Promise<AppSubAgentProfileInfo[]> | AppSubAgentProfileInfo[];
343
+ compactSessionContext?(sessionId: string): Promise<AppContextCompactionResult> | AppContextCompactionResult;
344
+ undoSessionTurn?(sessionId: string): Promise<AppUndoResult> | AppUndoResult;
345
+ getSessionTurnDiff?(sessionId: string): Promise<string | null> | string | null;
346
+ chat(sessionId: string, message: string, options?: StartTurnOptions & {
347
+ abort?: AbortSignal;
348
+ }): AsyncGenerator<AgentEvent>;
349
+ followUpPolicy?: FollowUpPolicy;
350
+ steer?(request: {
351
+ sessionId: string;
352
+ turnId: string;
353
+ message: string;
354
+ }): SteeringResponse;
355
+ followUp?(request: {
356
+ sessionId: string;
357
+ turnId: string;
358
+ message: string;
359
+ }): FollowUpResponse;
360
+ interruptTurn?(request: {
361
+ sessionId: string;
362
+ turnId: string;
363
+ }): void | Promise<void>;
364
+ respondToInputRequest?(requestId: string, payload: ResolveInputRequestPayload): void | Promise<void>;
365
+ drainQueuedFollowUps?(): PendingIntervention[];
366
+ listFollowUps?(options?: AppFollowUpListOptions): Promise<QueuedFollowUpRecord[]> | QueuedFollowUpRecord[];
367
+ getFollowUp?(followUpId: string): Promise<QueuedFollowUpRecord | null> | QueuedFollowUpRecord | null;
368
+ resolveFollowUp?(followUpId: string, action: FollowUpDecisionAction): Promise<QueuedFollowUpRecord | null> | QueuedFollowUpRecord | null;
369
+ listTeamNotifications?(options?: AppTeamNotificationListOptions): Promise<AppTeamNotification[]> | AppTeamNotification[];
370
+ subscribeTeamNotifications?(listener: (notification: AppTeamNotification) => void): Unsubscribe;
371
+ listSessions(): Promise<SessionInfo[]>;
372
+ deleteSession(sessionId: string): Promise<boolean>;
373
+ getSessionStorage(): SessionStorage;
374
+ listPluginCommands?(): Promise<AppPluginCommandInfo[]> | AppPluginCommandInfo[];
375
+ executePluginCommand?(name: string, args: string): Promise<string | null> | string | null;
376
+ }
377
+ interface AgentServer {
378
+ getCapabilities(): AgentServerCapabilities;
379
+ getWorkspaceSummary(): Promise<AppWorkspaceSummarySnapshot>;
380
+ getModelState(): Promise<AppModelState>;
381
+ switchModel(spec: string): Promise<AppModelSwitchResult>;
382
+ getSessionRuntimeStatus(sessionId: string): Promise<AppRuntimeStatusSnapshot>;
383
+ listTools(): Promise<AppToolInfo[]>;
384
+ listSkills(): Promise<AppSkillInfo[]>;
385
+ listSubAgents(): Promise<AppSubAgentProfileInfo[]>;
386
+ compactSessionContext(sessionId: string): Promise<AppContextCompactionResult>;
387
+ undoSessionTurn(sessionId: string): Promise<AppUndoResult>;
388
+ getSessionTurnDiff(sessionId: string): Promise<string | null>;
389
+ listPluginCommands(): Promise<AppPluginCommandInfo[]>;
390
+ executePluginCommand(name: string, args: string): Promise<string | null>;
391
+ listSessions(): Promise<AppSessionSummary[]>;
392
+ createSession(options?: CreateSessionOptions): Promise<AppSessionDetail>;
393
+ readSession(sessionId: string): Promise<AppSessionDetail | null>;
394
+ deleteSession(sessionId: string): Promise<boolean>;
395
+ branchSession(sessionId: string, options?: BranchSessionOptions): Promise<{
396
+ sessionId: string;
397
+ leafId: string;
398
+ }>;
399
+ startTurn(sessionId: string, message: string, options?: StartTurnOptions): Promise<AppTurnSnapshot>;
400
+ steerTurn(turnId: string, message: string): SteeringResponse;
401
+ followUpTurn(turnId: string, message: string): FollowUpResponse;
402
+ listFollowUps(options?: AppFollowUpListOptions): Promise<QueuedFollowUpRecord[]>;
403
+ getFollowUp(followUpId: string): Promise<QueuedFollowUpRecord | null>;
404
+ resolveFollowUp(followUpId: string, action: FollowUpDecisionAction): Promise<QueuedFollowUpRecord | null>;
405
+ listTeamNotifications(options?: AppTeamNotificationListOptions): Promise<AppTeamNotification[]>;
406
+ getTurn(turnId: string): AppTurnDetail | null;
407
+ waitForTurn(turnId: string, options?: WaitForTurnOptions): Promise<AppTurnSnapshot>;
408
+ interruptTurn(turnId: string): boolean;
409
+ respondToInputRequest(requestId: string, payload: ResolveInputRequestPayload): boolean;
410
+ subscribe(listener: (notification: AgentServerNotification) => void, options?: AgentServerSubscriptionOptions): Unsubscribe;
411
+ close(): Promise<void>;
412
+ }
413
+ interface AgentServerClient extends AgentServer {
414
+ disconnect(): Promise<void>;
415
+ }
416
+
417
+ declare function createAgentServerAdapter(agent: Agent, options?: {
418
+ pluginCommands?: AgentServerPluginCommand[];
419
+ currentModelLabel?: string;
420
+ switchModel?: (spec: string) => Promise<AppModelSwitchResult> | AppModelSwitchResult;
421
+ listSkills?: () => Promise<AppSkillInfo[]> | AppSkillInfo[];
422
+ listSubAgents?: () => Promise<AppSubAgentProfileInfo[]> | AppSubAgentProfileInfo[];
423
+ listTeamNotifications?: (options?: AppTeamNotificationListOptions) => Promise<AppTeamNotification[]> | AppTeamNotification[];
424
+ subscribeTeamNotifications?: (listener: (notification: AppTeamNotification) => void) => Unsubscribe;
425
+ capabilities?: AgentServerCapabilitiesPatch;
426
+ }): AgentServerAdapter;
427
+
428
+ type AgentServerWireRequestMethod = "initialize" | "capabilities/get" | "workspace/summary" | "agent/model/get" | "agent/model/switch" | "session/status" | "agent/tools" | "agent/skills" | "agent/sub-agents" | "plugin-command/list" | "plugin-command/execute" | "session/compact" | "session/undo" | "session/diff" | "session/list" | "session/create" | "session/read" | "session/delete" | "session/branch" | "turn/start" | "turn/get" | "turn/wait" | "turn/interrupt" | "turn/steer" | "turn/follow-up" | "follow-up/list" | "follow-up/get" | "follow-up/resolve" | "team/notification/list" | "input/respond";
429
+ type AgentServerWireRequest = {
430
+ method: "initialize";
431
+ params?: Record<string, never>;
432
+ } | {
433
+ method: "capabilities/get";
434
+ params?: Record<string, never>;
435
+ } | {
436
+ method: "workspace/summary";
437
+ params?: Record<string, never>;
438
+ } | {
439
+ method: "agent/model/get";
440
+ params?: Record<string, never>;
441
+ } | {
442
+ method: "agent/model/switch";
443
+ params: {
444
+ spec: string;
445
+ };
446
+ } | {
447
+ method: "session/status";
448
+ params: {
449
+ sessionId: string;
450
+ };
451
+ } | {
452
+ method: "agent/tools";
453
+ params?: Record<string, never>;
454
+ } | {
455
+ method: "agent/skills";
456
+ params?: Record<string, never>;
457
+ } | {
458
+ method: "agent/sub-agents";
459
+ params?: Record<string, never>;
460
+ } | {
461
+ method: "plugin-command/list";
462
+ params?: Record<string, never>;
463
+ } | {
464
+ method: "plugin-command/execute";
465
+ params: {
466
+ name: string;
467
+ args?: string;
468
+ };
469
+ } | {
470
+ method: "session/compact";
471
+ params: {
472
+ sessionId: string;
473
+ };
474
+ } | {
475
+ method: "session/undo";
476
+ params: {
477
+ sessionId: string;
478
+ };
479
+ } | {
480
+ method: "session/diff";
481
+ params: {
482
+ sessionId: string;
483
+ };
484
+ } | {
485
+ method: "session/list";
486
+ params?: Record<string, never>;
487
+ } | {
488
+ method: "session/create";
489
+ params?: CreateSessionOptions;
490
+ } | {
491
+ method: "session/read";
492
+ params: {
493
+ sessionId: string;
494
+ };
495
+ } | {
496
+ method: "session/delete";
497
+ params: {
498
+ sessionId: string;
499
+ };
500
+ } | {
501
+ method: "session/branch";
502
+ params: {
503
+ sessionId: string;
504
+ options?: BranchSessionOptions;
505
+ };
506
+ } | {
507
+ method: "turn/start";
508
+ params: {
509
+ sessionId: string;
510
+ message: string;
511
+ options?: StartTurnOptions;
512
+ };
513
+ } | {
514
+ method: "turn/get";
515
+ params: {
516
+ turnId: string;
517
+ };
518
+ } | {
519
+ method: "turn/wait";
520
+ params: {
521
+ turnId: string;
522
+ options?: WaitForTurnOptions;
523
+ };
524
+ } | {
525
+ method: "turn/interrupt";
526
+ params: {
527
+ turnId: string;
528
+ };
529
+ } | {
530
+ method: "turn/steer";
531
+ params: {
532
+ turnId: string;
533
+ message: string;
534
+ };
535
+ } | {
536
+ method: "turn/follow-up";
537
+ params: {
538
+ turnId: string;
539
+ message: string;
540
+ };
541
+ } | {
542
+ method: "follow-up/list";
543
+ params?: {
544
+ options?: AppFollowUpListOptions;
545
+ };
546
+ } | {
547
+ method: "follow-up/get";
548
+ params: {
549
+ followUpId: string;
550
+ };
551
+ } | {
552
+ method: "follow-up/resolve";
553
+ params: {
554
+ followUpId: string;
555
+ action: _cuylabs_agent_core.FollowUpDecisionAction;
556
+ };
557
+ } | {
558
+ method: "team/notification/list";
559
+ params?: {
560
+ options?: AppTeamNotificationListOptions;
561
+ };
562
+ } | {
563
+ method: "input/respond";
564
+ params: {
565
+ requestId: string;
566
+ payload: ResolveInputRequestPayload;
567
+ };
568
+ };
569
+ interface AgentServerInitializeResponse {
570
+ protocolVersion: 1;
571
+ capabilities: AgentServerCapabilities;
572
+ }
573
+ type AgentServerWireResponse = AgentServerInitializeResponse | AgentServerCapabilities | Awaited<ReturnType<AgentServer["getWorkspaceSummary"]>> | Awaited<ReturnType<AgentServer["getModelState"]>> | Awaited<ReturnType<AgentServer["switchModel"]>> | Awaited<ReturnType<AgentServer["getSessionRuntimeStatus"]>> | Awaited<ReturnType<AgentServer["listTools"]>> | Awaited<ReturnType<AgentServer["listSkills"]>> | Awaited<ReturnType<AgentServer["listSubAgents"]>> | Awaited<ReturnType<AgentServer["listPluginCommands"]>> | Awaited<ReturnType<AgentServer["executePluginCommand"]>> | Awaited<ReturnType<AgentServer["compactSessionContext"]>> | Awaited<ReturnType<AgentServer["undoSessionTurn"]>> | Awaited<ReturnType<AgentServer["getSessionTurnDiff"]>> | Awaited<ReturnType<AgentServer["listSessions"]>> | Awaited<ReturnType<AgentServer["createSession"]>> | Awaited<ReturnType<AgentServer["readSession"]>> | Awaited<ReturnType<AgentServer["deleteSession"]>> | Awaited<ReturnType<AgentServer["branchSession"]>> | Awaited<ReturnType<AgentServer["startTurn"]>> | ReturnType<AgentServer["getTurn"]> | Awaited<ReturnType<AgentServer["waitForTurn"]>> | ReturnType<AgentServer["interruptTurn"]> | ReturnType<AgentServer["steerTurn"]> | ReturnType<AgentServer["followUpTurn"]> | Awaited<ReturnType<AgentServer["listFollowUps"]>> | Awaited<ReturnType<AgentServer["getFollowUp"]>> | Awaited<ReturnType<AgentServer["resolveFollowUp"]>> | Awaited<ReturnType<AgentServer["listTeamNotifications"]>> | ReturnType<AgentServer["respondToInputRequest"]>;
574
+ interface AgentServerWireRequestEnvelope {
575
+ kind: "request";
576
+ id: string;
577
+ method: AgentServerWireRequestMethod;
578
+ params?: unknown;
579
+ }
580
+ interface AgentServerWireResponseEnvelope {
581
+ kind: "response";
582
+ id: string;
583
+ ok: boolean;
584
+ result?: AgentServerWireResponse;
585
+ error?: {
586
+ message: string;
587
+ };
588
+ }
589
+ interface AgentServerWireNotificationEnvelope {
590
+ kind: "notification";
591
+ notification: AgentServerNotification;
592
+ }
593
+ type AgentServerWireEnvelope = AgentServerWireRequestEnvelope | AgentServerWireResponseEnvelope | AgentServerWireNotificationEnvelope;
594
+ declare function isAgentServerWireEnvelope(value: unknown): value is AgentServerWireEnvelope;
595
+
596
+ interface ResolvedApprovalDecision$1 {
597
+ action: ApprovalAction;
598
+ feedback?: string;
599
+ rememberScope?: ApprovalRememberScope;
600
+ }
601
+
602
+ interface InProcessAgentServerOptions {
603
+ followUpPolicy?: FollowUpPolicy;
604
+ eventBus?: EventBus;
605
+ }
606
+ declare class InProcessAgentServer implements AgentServer {
607
+ private readonly adapter;
608
+ private readonly capabilities;
609
+ private readonly followUpPolicy;
610
+ private readonly eventBus;
611
+ private readonly turns;
612
+ private readonly followUps;
613
+ private readonly sessionRuntime;
614
+ private readonly listeners;
615
+ private readonly pendingInputs;
616
+ private teamNotificationUnsubscribe;
617
+ constructor(adapter: AgentServerAdapter, options?: InProcessAgentServerOptions);
618
+ getCapabilities(): AgentServerCapabilities;
619
+ getWorkspaceSummary(): Promise<AppWorkspaceSummarySnapshot>;
620
+ getSessionRuntimeStatus(sessionId: string): Promise<AppRuntimeStatusSnapshot>;
621
+ getModelState(): Promise<AppModelState>;
622
+ switchModel(spec: string): Promise<AppModelSwitchResult>;
623
+ listTools(): Promise<AppToolInfo[]>;
624
+ listSkills(): Promise<AppSkillInfo[]>;
625
+ listSubAgents(): Promise<AppSubAgentProfileInfo[]>;
626
+ listPluginCommands(): Promise<AppPluginCommandInfo[]>;
627
+ executePluginCommand(name: string, args: string): Promise<string | null>;
628
+ compactSessionContext(sessionId: string): Promise<AppContextCompactionResult>;
629
+ undoSessionTurn(sessionId: string): Promise<AppUndoResult>;
630
+ getSessionTurnDiff(sessionId: string): Promise<string | null>;
631
+ listSessions(): Promise<AppSessionSummary[]>;
632
+ createSession(options?: CreateSessionOptions): Promise<AppSessionDetail>;
633
+ readSession(sessionId: string): Promise<AppSessionDetail | null>;
634
+ deleteSession(sessionId: string): Promise<boolean>;
635
+ branchSession(sessionId: string, options?: BranchSessionOptions): Promise<{
636
+ sessionId: string;
637
+ leafId: string;
638
+ }>;
639
+ startTurn(sessionId: string, message: string, options?: StartTurnOptions): Promise<AppTurnSnapshot>;
640
+ getTurn(turnId: string): AppTurnDetail | null;
641
+ waitForTurn(turnId: string, options?: WaitForTurnOptions): Promise<AppTurnSnapshot>;
642
+ steerTurn(turnId: string, message: string): SteeringResponse;
643
+ followUpTurn(turnId: string, message: string): FollowUpResponse;
644
+ listFollowUps(options?: AppFollowUpListOptions): Promise<QueuedFollowUpRecord[]>;
645
+ getFollowUp(followUpId: string): Promise<QueuedFollowUpRecord | null>;
646
+ resolveFollowUp(followUpId: string, action: FollowUpDecisionAction): Promise<QueuedFollowUpRecord | null>;
647
+ listTeamNotifications(options?: AppTeamNotificationListOptions): Promise<AppTeamNotification[]>;
648
+ interruptTurn(turnId: string): boolean;
649
+ respondToInputRequest(requestId: string, payload: ResolveInputRequestPayload): boolean;
650
+ subscribe(listener: (notification: AgentServerNotification) => void, options?: AgentServerSubscriptionOptions): Unsubscribe;
651
+ close(): Promise<void>;
652
+ requestApproval(request: ApprovalRequest): Promise<ResolvedApprovalDecision$1>;
653
+ requestHumanInput(request: HumanInputRequest): Promise<HumanInputResponse>;
654
+ private runTurn;
655
+ private ensureSessionExists;
656
+ private getOrCreateRuntimeRecord;
657
+ private getRuntimeSnapshot;
658
+ private hasRunningTurnForSession;
659
+ private findRunningTurnIdForSession;
660
+ private resolveInteractiveRequestRoute;
661
+ private findSessionInfo;
662
+ private readSessionOrThrow;
663
+ private emit;
664
+ private captureDeferredFollowUps;
665
+ private seedQueuedFollowUps;
666
+ private toTurnSnapshot;
667
+ private toTurnDetail;
668
+ private resolvePendingInputsForTurn;
669
+ private resolveAllPendingInputs;
670
+ private resolveMatchingApprovalRequests;
671
+ private resolvePendingInput;
672
+ private registerEventInputRequest;
673
+ private resolveEventInputRequest;
674
+ }
675
+
676
+ interface ResolvedApprovalDecision {
677
+ action: "allow" | "deny" | "remember";
678
+ feedback?: string;
679
+ rememberScope?: ApprovalRememberScope;
680
+ }
681
+ interface InteractiveRequestBridge {
682
+ requestApproval?(request: ApprovalRequest): Promise<ResolvedApprovalDecision>;
683
+ requestHumanInput?(request: HumanInputRequest): Promise<HumanInputResponse>;
684
+ }
685
+ declare function createServerApprovalRequestHandler(bridge: InteractiveRequestBridge): (request: ApprovalRequest) => Promise<ResolvedApprovalDecision>;
686
+ declare function createServerHumanInputRequestHandler(bridge: InteractiveRequestBridge): (request: HumanInputRequest) => Promise<HumanInputResponse>;
687
+ declare function createServerInteractiveHandlers(bridge: InteractiveRequestBridge): {
688
+ approval: (request: ApprovalRequest) => Promise<ResolvedApprovalDecision>;
689
+ humanInput: (request: HumanInputRequest) => Promise<HumanInputResponse>;
690
+ };
691
+
692
+ interface AgentServerRpcConnectionOptions {
693
+ server: AgentServer;
694
+ send: (envelope: AgentServerWireEnvelope) => void | Promise<void>;
695
+ capabilityOverride?: AgentServerCapabilitiesPatch;
696
+ }
697
+ declare class AgentServerRpcConnection {
698
+ private readonly server;
699
+ private readonly capabilities;
700
+ private readonly sendEnvelope;
701
+ private unsubscribe;
702
+ constructor(options: AgentServerRpcConnectionOptions);
703
+ close(): Promise<void>;
704
+ handleRequest(envelope: AgentServerWireRequestEnvelope): Promise<void>;
705
+ private dispatchRequest;
706
+ }
707
+
708
+ interface RemoteAgentServerTransport {
709
+ connect(): Promise<void>;
710
+ send(envelope: AgentServerWireEnvelope): void | Promise<void>;
711
+ close(): Promise<void>;
712
+ setMessageHandler(handler: (envelope: AgentServerWireEnvelope) => void): void;
713
+ setCloseHandler(handler: (error?: Error) => void): void;
714
+ }
715
+ declare class RemoteAgentServerClient implements AgentServerClient {
716
+ private readonly transport;
717
+ private readonly requestTimeoutMs;
718
+ private readonly pending;
719
+ private readonly listeners;
720
+ private readonly turns;
721
+ private capabilities;
722
+ private counter;
723
+ private connected;
724
+ constructor(transport: RemoteAgentServerTransport, options?: {
725
+ requestTimeoutMs?: number;
726
+ });
727
+ connect(): Promise<void>;
728
+ getCapabilities(): AgentServerCapabilities;
729
+ getWorkspaceSummary(): Promise<AppWorkspaceSummarySnapshot>;
730
+ getSessionRuntimeStatus(sessionId: string): Promise<AppRuntimeStatusSnapshot>;
731
+ getModelState(): Promise<AppModelState>;
732
+ switchModel(spec: string): Promise<AppModelSwitchResult>;
733
+ listTools(): Promise<AppToolInfo[]>;
734
+ listSkills(): Promise<AppSkillInfo[]>;
735
+ listSubAgents(): Promise<AppSubAgentProfileInfo[]>;
736
+ listPluginCommands(): Promise<AppPluginCommandInfo[]>;
737
+ executePluginCommand(name: string, args: string): Promise<string | null>;
738
+ compactSessionContext(sessionId: string): Promise<AppContextCompactionResult>;
739
+ undoSessionTurn(sessionId: string): Promise<AppUndoResult>;
740
+ getSessionTurnDiff(sessionId: string): Promise<string | null>;
741
+ listSessions(): Promise<AppSessionSummary[]>;
742
+ createSession(options?: CreateSessionOptions): Promise<AppSessionDetail>;
743
+ readSession(sessionId: string): Promise<AppSessionDetail | null>;
744
+ deleteSession(sessionId: string): Promise<boolean>;
745
+ branchSession(sessionId: string, options?: BranchSessionOptions): Promise<{
746
+ sessionId: string;
747
+ leafId: string;
748
+ }>;
749
+ startTurn(sessionId: string, message: string, options?: StartTurnOptions): Promise<AppTurnSnapshot>;
750
+ steerTurn(turnId: string, message: string): SteeringResponse;
751
+ followUpTurn(turnId: string, message: string): FollowUpResponse;
752
+ listFollowUps(options?: AppFollowUpListOptions): Promise<QueuedFollowUpRecord[]>;
753
+ getFollowUp(followUpId: string): Promise<QueuedFollowUpRecord | null>;
754
+ resolveFollowUp(followUpId: string, action: FollowUpDecisionAction): Promise<QueuedFollowUpRecord | null>;
755
+ listTeamNotifications(options?: AppTeamNotificationListOptions): Promise<AppTeamNotification[]>;
756
+ getTurn(turnId: string): AppTurnDetail | null;
757
+ waitForTurn(turnId: string, options?: WaitForTurnOptions): Promise<AppTurnSnapshot>;
758
+ interruptTurn(turnId: string): boolean;
759
+ respondToInputRequest(requestId: string, payload: ResolveInputRequestPayload): boolean;
760
+ subscribe(listener: (notification: AgentServerNotification) => void, options?: AgentServerSubscriptionOptions): Unsubscribe;
761
+ close(): Promise<void>;
762
+ disconnect(): Promise<void>;
763
+ private request;
764
+ private handleEnvelope;
765
+ private failPending;
766
+ private trackNotification;
767
+ }
768
+
769
+ interface StdioAgentServerOptions {
770
+ input?: Readable;
771
+ output?: Writable;
772
+ onError?: (error: Error) => void;
773
+ }
774
+ interface SpawnStdioAgentServerClientOptions {
775
+ command: string;
776
+ args?: string[];
777
+ cwd?: string;
778
+ env?: NodeJS.ProcessEnv;
779
+ requestTimeoutMs?: number;
780
+ }
781
+ declare function attachAgentServerStdio(server: AgentServer, options?: StdioAgentServerOptions): {
782
+ close: () => Promise<void>;
783
+ };
784
+ declare function connectStdioAgentServerClient(options: SpawnStdioAgentServerClientOptions): Promise<RemoteAgentServerClient>;
785
+
786
+ interface AgentServerWebSocketServerOptions {
787
+ /**
788
+ * TCP port for the WebSocket server.
789
+ * Required when `httpServer` is not provided.
790
+ */
791
+ port?: number;
792
+ /** Bind hostname. Only used with `port`. */
793
+ host?: string;
794
+ /**
795
+ * Attach to an existing HTTP/S server instead of binding a new port.
796
+ * When set, `port` and `host` are ignored.
797
+ *
798
+ * This enables running WebSocket alongside REST/SSE on the same port,
799
+ * e.g. when composing with `@cuylabs/agent-runtime-dapr`.
800
+ */
801
+ httpServer?: Server | Server$1;
802
+ }
803
+ interface ConnectWebSocketAgentServerClientOptions {
804
+ url: string;
805
+ headers?: Record<string, string>;
806
+ requestTimeoutMs?: number;
807
+ }
808
+ declare function startAgentServerWebSocketServer(server: AgentServer, options: AgentServerWebSocketServerOptions): {
809
+ ready: Promise<void>;
810
+ close: () => Promise<void>;
811
+ address: () => string;
812
+ };
813
+ declare function connectWebSocketAgentServerClient(options: ConnectWebSocketAgentServerClientOptions): Promise<RemoteAgentServerClient>;
814
+
815
+ /**
816
+ * Create an SSE `ReadableStream` that yields server notifications
817
+ * for a specific session as `text/event-stream` frames.
818
+ *
819
+ * Use the returned stream as the body of an HTTP `Response`:
820
+ *
821
+ * ```ts
822
+ * new Response(createAgentServerSSEStream(server, sessionId), {
823
+ * headers: { "Content-Type": "text/event-stream", "Cache-Control": "no-cache" },
824
+ * });
825
+ * ```
826
+ */
827
+ declare function createAgentServerSSEStream(server: AgentServer, sessionId: string, options?: {
828
+ signal?: AbortSignal;
829
+ }): ReadableStream<Uint8Array>;
830
+ /**
831
+ * Create an SSE `ReadableStream` backed by an `EventBus` channel.
832
+ *
833
+ * Supports replay via `lastEventId` — messages with a sequence
834
+ * number greater than `lastEventId` are replayed from the channel
835
+ * history before live events begin.
836
+ */
837
+ declare function createEventBusSSEStream(eventBus: EventBus, channel: string, options?: {
838
+ lastEventId?: string;
839
+ signal?: AbortSignal;
840
+ }): ReadableStream<Uint8Array>;
841
+ /**
842
+ * Convenience: build a standard `Response` for an SSE endpoint.
843
+ */
844
+ declare function createAgentServerSSEResponse(server: AgentServer, sessionId: string, options?: {
845
+ signal?: AbortSignal;
846
+ headers?: Record<string, string>;
847
+ }): Response;
848
+
849
+ declare function streamTurn(client: AgentServerClient, sessionId: string, message: string, options?: StartTurnOptions): AsyncGenerator<AgentServerNotification>;
850
+
851
+ declare class InProcessAgentServerClient implements AgentServerClient {
852
+ private readonly server;
853
+ constructor(server: AgentServer);
854
+ getCapabilities(): AgentServerCapabilities;
855
+ getWorkspaceSummary(): Promise<AppWorkspaceSummarySnapshot>;
856
+ getSessionRuntimeStatus(sessionId: string): Promise<AppRuntimeStatusSnapshot>;
857
+ getModelState(): Promise<AppModelState>;
858
+ switchModel(spec: string): Promise<AppModelSwitchResult>;
859
+ listTools(): Promise<AppToolInfo[]>;
860
+ listSkills(): Promise<AppSkillInfo[]>;
861
+ listSubAgents(): Promise<AppSubAgentProfileInfo[]>;
862
+ listPluginCommands(): Promise<AppPluginCommandInfo[]>;
863
+ executePluginCommand(name: string, args: string): Promise<string | null>;
864
+ compactSessionContext(sessionId: string): Promise<AppContextCompactionResult>;
865
+ undoSessionTurn(sessionId: string): Promise<AppUndoResult>;
866
+ getSessionTurnDiff(sessionId: string): Promise<string | null>;
867
+ listSessions(): Promise<AppSessionSummary[]>;
868
+ createSession(options?: CreateSessionOptions): Promise<AppSessionDetail>;
869
+ readSession(sessionId: string): Promise<AppSessionDetail | null>;
870
+ deleteSession(sessionId: string): Promise<boolean>;
871
+ branchSession(sessionId: string, options?: BranchSessionOptions): Promise<{
872
+ sessionId: string;
873
+ leafId: string;
874
+ }>;
875
+ startTurn(sessionId: string, message: string, options?: StartTurnOptions): Promise<AppTurnSnapshot>;
876
+ steerTurn(turnId: string, message: string): SteeringResponse;
877
+ followUpTurn(turnId: string, message: string): FollowUpResponse;
878
+ listFollowUps(options?: AppFollowUpListOptions): Promise<QueuedFollowUpRecord[]>;
879
+ getFollowUp(followUpId: string): Promise<QueuedFollowUpRecord | null>;
880
+ resolveFollowUp(followUpId: string, action: FollowUpDecisionAction): Promise<QueuedFollowUpRecord | null>;
881
+ listTeamNotifications(options?: AppTeamNotificationListOptions): Promise<AppTeamNotification[]>;
882
+ getTurn(turnId: string): AppTurnDetail | null;
883
+ waitForTurn(turnId: string, options?: WaitForTurnOptions): Promise<AppTurnSnapshot>;
884
+ interruptTurn(turnId: string): boolean;
885
+ respondToInputRequest(requestId: string, payload: ResolveInputRequestPayload): boolean;
886
+ subscribe(listener: (notification: AgentServerNotification) => void, options?: AgentServerSubscriptionOptions): Unsubscribe;
887
+ close(): Promise<void>;
888
+ disconnect(): Promise<void>;
889
+ }
890
+ declare function createInProcessAgentServer(agent: Agent): InProcessAgentServer;
891
+ declare function createInProcessAgentServerClient(agent: Agent): InProcessAgentServerClient;
892
+
893
+ export { type AgentServer, type AgentServerAdapter, type AgentServerCapabilities, type AgentServerCapabilitiesPatch, type AgentServerClient, type AgentServerDurabilityMode, type AgentServerExecutionMode, type AgentServerInitializeResponse, type AgentServerNotification, type AgentServerOrchestrationBackend, type AgentServerPluginCommand, AgentServerRpcConnection, type AgentServerRpcConnectionOptions, type AgentServerSubscriptionOptions, type AgentServerTransportKind, type AgentServerWebSocketServerOptions, type AgentServerWireEnvelope, type AgentServerWireNotificationEnvelope, type AgentServerWireRequest, type AgentServerWireRequestEnvelope, type AgentServerWireRequestMethod, type AgentServerWireResponse, type AgentServerWireResponseEnvelope, type AppApprovalInputRequest, type AppContextCompactionResult, type AppFollowUpListOptions, type AppHumanInputRequest, type AppInputRequest, type AppModelState, type AppModelSwitchResult, type AppPluginCommandInfo, type AppRuntimeStatusSnapshot, type AppSessionDetail, type AppSessionRuntime, type AppSessionRuntimeStatus, type AppSessionSummary, type AppSkillInfo, type AppSubAgentProfileInfo, type AppTeamNotification, type AppTeamNotificationListOptions, type AppToolInfo, type AppTurnDetail, type AppTurnEventRecord, type AppTurnSnapshot, type AppTurnStatus, type AppUndoFailure, type AppUndoResult, type AppWorkspaceSummarySnapshot, type BranchSessionOptions, type ConnectWebSocketAgentServerClientOptions, type CreateSessionOptions, InProcessAgentServer, InProcessAgentServerClient, type InProcessAgentServerOptions, type InteractiveRequestBridge, RemoteAgentServerClient, type RemoteAgentServerTransport, type ResolveApprovalInputPayload, type ResolveHumanInputPayload, type ResolveInputRequestPayload, type SpawnStdioAgentServerClientOptions, type StartTurnOptions, type StdioAgentServerOptions, type Unsubscribe, type WaitForTurnOptions, attachAgentServerStdio, connectStdioAgentServerClient, connectWebSocketAgentServerClient, createAgentServerAdapter, createAgentServerSSEResponse, createAgentServerSSEStream, createDefaultAgentServerCapabilities, createEventBusSSEStream, createInProcessAgentServer, createInProcessAgentServerClient, createServerApprovalRequestHandler, createServerHumanInputRequestHandler, createServerInteractiveHandlers, isAgentServerWireEnvelope, matchesNotificationSubscription, mergeAgentServerCapabilities, startAgentServerWebSocketServer, streamTurn };