@rowan-agent/agent 0.6.0 → 0.6.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 (4) hide show
  1. package/README.md +132 -55
  2. package/dist/index.d.ts +209 -145
  3. package/dist/index.js +455 -175
  4. package/package.json +2 -2
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as _rowan_agent_models from '@rowan-agent/models';
2
- import { LlmRequest, LlmResponse, LlmModelRef, LlmModelUsage, StreamFn, AgentEventListener, AgentMessage, Outcome, ToolCall, ToolResult, Skill as Skill$1, ContentBlock } from '@rowan-agent/models';
3
- export { AgentEvent, AgentEventListener, AgentMessage, LlmModelRef, Outcome, Skill, StreamFn, ToolResult } from '@rowan-agent/models';
2
+ import { LlmRequest, LlmResponse, ModelRef, LlmModelUsage, Outcome, AgentMessage, ToolResult, StreamFn, AgentEventListener, ToolCall, Skill as Skill$1, ContentBlock, ModelConfig } from '@rowan-agent/models';
3
+ export { AgentEvent, AgentEventListener, AgentMessage, ModelConfig, ModelRef, Outcome, Skill, StreamFn, ToolResult } from '@rowan-agent/models';
4
4
  import Type from 'typebox';
5
5
 
6
6
  type ExecutionTurn = {
@@ -10,7 +10,7 @@ type ExecutionTurn = {
10
10
  phase: string;
11
11
  requestedAtMs: number;
12
12
  completedAtMs: number;
13
- model: LlmModelRef;
13
+ model: ModelRef;
14
14
  usage?: LlmModelUsage;
15
15
  };
16
16
  /** Raw model input/output for session persistence. */
@@ -19,6 +19,106 @@ type ModelTranscript = {
19
19
  response: LlmResponse;
20
20
  };
21
21
 
22
+ declare const opaqueIdBrand: unique symbol;
23
+ type OpaqueId<Kind extends string> = string & {
24
+ readonly [opaqueIdBrand]: Kind;
25
+ };
26
+ type AgentId = OpaqueId<"AgentId">;
27
+ type AgentRunId = OpaqueId<"AgentRunId">;
28
+ type RuntimeMessageId = OpaqueId<"RuntimeMessageId">;
29
+ type RuntimeEventId = OpaqueId<"RuntimeEventId">;
30
+ type LeaseId = OpaqueId<"LeaseId">;
31
+ type RuntimeToolCallId = OpaqueId<"RuntimeToolCallId">;
32
+ type AgentLifecycleState = "active" | "paused";
33
+ type RuntimeMessageState = "queued" | "leased" | "acknowledged" | "dead_lettered";
34
+ type AgentRunState = "queued" | "running" | "suspended" | "completed" | "failed" | "cancelled";
35
+ /** Opaque execution checkpoint owned by the Agent loop and persisted by Runtime. */
36
+ type AgentRunExecutionState = Readonly<Record<string, unknown>>;
37
+ /** Host-owned correlation data persisted with a Run and echoed by Runtime Events. */
38
+ type AgentRunMetadata = Readonly<Record<string, unknown>>;
39
+ type AgentInputRequest = {
40
+ phase: string;
41
+ prompt: string;
42
+ requestedAt: string;
43
+ };
44
+ type RuntimeToolCallState = "queued" | "running" | "completed" | "failed" | "indeterminate";
45
+ type AgentRecord = {
46
+ id: AgentId;
47
+ sessionId: string;
48
+ state: AgentLifecycleState;
49
+ createdAt: string;
50
+ updatedAt: string;
51
+ };
52
+ type RuntimeLease = {
53
+ id: LeaseId;
54
+ runId: AgentRunId;
55
+ workerId: string;
56
+ leasedAt: string;
57
+ expiresAt: string;
58
+ };
59
+ type RuntimeMessage = {
60
+ id: RuntimeMessageId;
61
+ agentId: AgentId;
62
+ kind: "agent_input";
63
+ input: AgentMessage;
64
+ state: RuntimeMessageState;
65
+ attempts: number;
66
+ runId?: AgentRunId;
67
+ lease?: RuntimeLease;
68
+ deadLetterReason?: string;
69
+ createdAt: string;
70
+ updatedAt: string;
71
+ };
72
+ type AgentRunRecord = {
73
+ id: AgentRunId;
74
+ agentId: AgentId;
75
+ messageId: RuntimeMessageId;
76
+ state: AgentRunState;
77
+ attempt: number;
78
+ leaseId?: LeaseId;
79
+ outcome?: Outcome;
80
+ suspensionReason?: string;
81
+ inputRequest?: AgentInputRequest;
82
+ executionState?: AgentRunExecutionState;
83
+ metadata?: AgentRunMetadata;
84
+ createdAt: string;
85
+ updatedAt: string;
86
+ };
87
+ type RuntimeEventKind = "agent_created" | "agent_paused" | "agent_resumed" | "message_enqueued" | "run_enqueued" | "run_leased" | "lease_expired" | "lease_recovered" | "run_suspended" | "run_retry_scheduled" | "run_completed" | "run_aborted" | "message_acknowledged" | "message_dead_lettered" | "tool_call_created" | "tool_call_started" | "tool_call_failed" | "tool_call_completed" | "tool_call_indeterminate";
88
+ type RuntimeEvent = {
89
+ id: RuntimeEventId;
90
+ sequence: number;
91
+ kind: RuntimeEventKind;
92
+ agentId?: AgentId;
93
+ messageId?: RuntimeMessageId;
94
+ runId?: AgentRunId;
95
+ toolCallId?: RuntimeToolCallId;
96
+ payload?: unknown;
97
+ createdAt: string;
98
+ };
99
+ type RuntimeEventCursor = {
100
+ after?: RuntimeEventId;
101
+ limit?: number;
102
+ };
103
+ type RuntimeEventCheckpoint = {
104
+ consumerId: string;
105
+ sequence: number;
106
+ eventId?: RuntimeEventId;
107
+ updatedAt: string;
108
+ };
109
+ type RuntimeToolCall = {
110
+ id: RuntimeToolCallId;
111
+ agentId: AgentId;
112
+ runId: AgentRunId;
113
+ name: string;
114
+ args: unknown;
115
+ state: RuntimeToolCallState;
116
+ result?: ToolResult;
117
+ indeterminateReason?: string;
118
+ createdAt: string;
119
+ updatedAt: string;
120
+ };
121
+
22
122
  type BeforePhaseHook = (phaseId: string, input: PhaseContext) => Promise<BeforePhaseHookResult>;
23
123
  type AfterPhaseHook = (phaseId: string, output: PhaseOutput) => Promise<AfterPhaseHookResult>;
24
124
  type BeforePromptHook = (phaseId: string, input: PhaseContext) => Promise<PhaseContext>;
@@ -48,10 +148,21 @@ type SessionState = {
48
148
  currentPhase: string;
49
149
  attempt: number;
50
150
  metrics: LoopMetrics;
51
- status: "idle" | "running" | "completed" | "aborted" | "failed";
151
+ status: "idle" | "running" | "suspended" | "completed" | "aborted" | "failed";
152
+ continuation?: SessionContinuationState;
153
+ };
154
+ type SessionContinuationState = {
155
+ isContinuing: boolean;
156
+ previousPayload?: unknown;
157
+ previousResults: Array<{
158
+ name: string;
159
+ output?: unknown;
160
+ }>;
161
+ pendingInstruction?: string;
162
+ previousPhaseMessageId?: string;
52
163
  };
53
164
  type AgentConfig = {
54
- model: LlmModelRef;
165
+ model: ModelRef;
55
166
  stream: StreamFn;
56
167
  context: AgentContext;
57
168
  sessionId?: string;
@@ -67,12 +178,12 @@ type AgentConfig = {
67
178
  beforePrompt?: BeforePromptHook;
68
179
  onModelTranscript?: (transcript: ModelTranscript, meta: {
69
180
  phase: string;
70
- model: LlmModelRef;
181
+ model: ModelRef;
71
182
  }) => Promise<void>;
72
183
  onMessage?: (message: AgentMessage) => Promise<void>;
73
184
  onOutcome?: (outcome: Outcome) => Promise<void>;
74
185
  /** Internal: await next user messages before retrying the same phase. */
75
- waitForInput?: () => Promise<AgentMessage[]>;
186
+ waitForInput?: (state?: SessionState, inputRequest?: AgentInputRequest) => Promise<AgentMessage[]>;
76
187
  };
77
188
  type ToolRunnerInput = {
78
189
  config: AgentConfig;
@@ -182,6 +293,17 @@ interface PhaseState {
182
293
  iterations: number;
183
294
  payload?: unknown;
184
295
  }
296
+ type PhaseInvocation = {
297
+ mode: "serial";
298
+ instanceId: string;
299
+ } | {
300
+ mode: "parallel";
301
+ instanceId: string;
302
+ groupId: string;
303
+ index: number;
304
+ count: number;
305
+ sourcePhaseId: string;
306
+ };
185
307
  /** Everything a phase needs to execute */
186
308
  interface PhaseContext {
187
309
  systemPrompt: string;
@@ -192,6 +314,8 @@ interface PhaseContext {
192
314
  skills: Skill$1[];
193
315
  /** Phase machine state */
194
316
  state: PhaseState;
317
+ /** Identity and dispatch metadata for this phase execution */
318
+ readonly invocation: PhaseInvocation;
195
319
  /** Additional guideline bullets appended to the system prompt */
196
320
  promptGuidelines?: string[];
197
321
  /** Text to append after the system prompt */
@@ -224,10 +348,10 @@ interface Phase {
224
348
  /** PHASE.md body content */
225
349
  content: string;
226
350
  /** Model override for this phase (resolved from frontmatter) */
227
- model?: LlmModelRef;
351
+ model?: ModelRef;
228
352
  /** ExtensionAPI factory function (default export pattern) */
229
353
  factory?: (api: ExtensionAPI) => Promise<void>;
230
- /** Legacy run function */
354
+ /** Direct run function */
231
355
  run?: (context: PhaseContext, execution: PhaseExecution) => Promise<PhaseOutput | void>;
232
356
  }
233
357
  /**
@@ -925,95 +1049,6 @@ interface ExtensionAPI {
925
1049
  */
926
1050
  type ExtensionFactory = (api: ExtensionAPI) => void | Promise<void>;
927
1051
 
928
- declare const opaqueIdBrand: unique symbol;
929
- type OpaqueId<Kind extends string> = string & {
930
- readonly [opaqueIdBrand]: Kind;
931
- };
932
- type AgentId = OpaqueId<"AgentId">;
933
- type AgentRunId = OpaqueId<"AgentRunId">;
934
- type RuntimeMessageId = OpaqueId<"RuntimeMessageId">;
935
- type RuntimeEventId = OpaqueId<"RuntimeEventId">;
936
- type LeaseId = OpaqueId<"LeaseId">;
937
- type RuntimeToolCallId = OpaqueId<"RuntimeToolCallId">;
938
- type AgentLifecycleState = "active" | "paused";
939
- type RuntimeMessageState = "queued" | "leased" | "acknowledged" | "dead_lettered";
940
- type AgentRunState = "queued" | "running" | "suspended" | "completed" | "failed" | "cancelled";
941
- type RuntimeToolCallState = "queued" | "running" | "completed" | "failed" | "indeterminate";
942
- type AgentRecord = {
943
- id: AgentId;
944
- sessionId: string;
945
- factoryId?: string;
946
- state: AgentLifecycleState;
947
- createdAt: string;
948
- updatedAt: string;
949
- };
950
- type RuntimeLease = {
951
- id: LeaseId;
952
- runId: AgentRunId;
953
- workerId: string;
954
- leasedAt: string;
955
- expiresAt: string;
956
- };
957
- type RuntimeMessage = {
958
- id: RuntimeMessageId;
959
- agentId: AgentId;
960
- kind: "agent_input";
961
- input: AgentMessage;
962
- state: RuntimeMessageState;
963
- attempts: number;
964
- runId?: AgentRunId;
965
- lease?: RuntimeLease;
966
- deadLetterReason?: string;
967
- createdAt: string;
968
- updatedAt: string;
969
- };
970
- type AgentRunRecord = {
971
- id: AgentRunId;
972
- agentId: AgentId;
973
- messageId: RuntimeMessageId;
974
- state: AgentRunState;
975
- attempt: number;
976
- leaseId?: LeaseId;
977
- outcome?: Outcome;
978
- suspensionReason?: string;
979
- createdAt: string;
980
- updatedAt: string;
981
- };
982
- type RuntimeEventKind = "agent_created" | "agent_paused" | "agent_resumed" | "agent_recovered" | "agent_recovery_failed" | "factory_missing" | "message_enqueued" | "run_enqueued" | "run_leased" | "lease_expired" | "lease_recovered" | "run_suspended" | "run_retry_scheduled" | "run_completed" | "run_aborted" | "message_acknowledged" | "message_dead_lettered" | "tool_call_created" | "tool_call_started" | "tool_call_failed" | "tool_call_completed" | "tool_call_indeterminate";
983
- type RuntimeEvent = {
984
- id: RuntimeEventId;
985
- sequence: number;
986
- kind: RuntimeEventKind;
987
- agentId?: AgentId;
988
- messageId?: RuntimeMessageId;
989
- runId?: AgentRunId;
990
- toolCallId?: RuntimeToolCallId;
991
- payload?: unknown;
992
- createdAt: string;
993
- };
994
- type RuntimeEventCursor = {
995
- after?: RuntimeEventId;
996
- limit?: number;
997
- };
998
- type RuntimeEventCheckpoint = {
999
- consumerId: string;
1000
- sequence: number;
1001
- eventId?: RuntimeEventId;
1002
- updatedAt: string;
1003
- };
1004
- type RuntimeToolCall = {
1005
- id: RuntimeToolCallId;
1006
- agentId: AgentId;
1007
- runId: AgentRunId;
1008
- name: string;
1009
- args: unknown;
1010
- state: RuntimeToolCallState;
1011
- result?: ToolResult;
1012
- indeterminateReason?: string;
1013
- createdAt: string;
1014
- updatedAt: string;
1015
- };
1016
-
1017
1052
  /**
1018
1053
  * Load all phases from the target directory.
1019
1054
  *
@@ -1026,21 +1061,22 @@ type RuntimeToolCall = {
1026
1061
  */
1027
1062
  declare function loadPhases(targetPath: string): Promise<PhaseRegistry>;
1028
1063
 
1029
- type AgentExecutionOptions = AgentOptions & {
1064
+ type AgentExecutionOptions = StreamAgentOptions & {
1030
1065
  sessionId?: string;
1031
1066
  agentId?: AgentId;
1067
+ sessionState?: SessionState;
1032
1068
  onInput?: (message: AgentMessage) => Promise<void>;
1033
1069
  runtime?: AgentRuntimePort;
1034
1070
  };
1035
1071
  type RunOptions = Partial<AgentExecutionOptions>;
1036
1072
  type RuntimeRunHooks = {
1037
- onSuspend?: (reason?: string) => Promise<void> | void;
1073
+ onSuspend?: (reason?: string, state?: SessionState, inputRequest?: AgentInputRequest) => Promise<void> | void;
1038
1074
  };
1039
1075
  type AgentStatus = {
1040
1076
  agentId?: AgentId;
1041
1077
  sessionId?: string;
1042
1078
  context: AgentContext;
1043
- model: LlmModelRef;
1079
+ model: ModelRef;
1044
1080
  tools: Tool[];
1045
1081
  initialized: boolean;
1046
1082
  running: boolean;
@@ -1071,7 +1107,7 @@ declare class AgentExecution {
1071
1107
  runWithUserInput(input: string, options?: RunOptions): Promise<RunResult>;
1072
1108
  runWithMessage(message: AgentMessage, options?: RunOptions, internalHooks?: RuntimeRunHooks): Promise<RunResult>;
1073
1109
  /** Internal Runtime seam: executes one leased Agent Input. */
1074
- executeAgentInput(input: AgentMessage, runId: AgentRunId, control: AgentRunControl): Promise<Outcome>;
1110
+ executeAgentInput(input: AgentMessage, runId: AgentRunId, control: AgentRunControl, executionState?: AgentRunExecutionState): Promise<Outcome>;
1075
1111
  resetInitialization(): void;
1076
1112
  getContext(): AgentContext;
1077
1113
  setContext(context: AgentContext): void;
@@ -1090,13 +1126,13 @@ declare class AgentExecution {
1090
1126
  getAgentId(): AgentId | undefined;
1091
1127
  /** Internal Runtime hook for associating Tool Calls with the leased Run. */
1092
1128
  getRuntimeRunId(): AgentRunId | undefined;
1093
- setModel(model: LlmModelRef): void;
1129
+ setModel(model: ModelRef): void;
1094
1130
  setTools(tools: Tool[]): void;
1095
1131
  setSkills(skills: Skill$1[]): void;
1096
1132
  setPhases(phases: PhaseRegistry): void;
1097
1133
  setCwd(cwd: string): void;
1098
1134
  setStream(stream: StreamFn): void;
1099
- getModel(): LlmModelRef;
1135
+ getModel(): ModelRef;
1100
1136
  getTools(): Tool[];
1101
1137
  getSkills(): Skill$1[];
1102
1138
  getPhases(): PhaseRegistry | undefined;
@@ -1135,6 +1171,7 @@ declare class AgentExecution {
1135
1171
  private loadExtensions;
1136
1172
  run(config?: RunOptions, internalHooks?: RuntimeRunHooks): Promise<RunResult>;
1137
1173
  abort(reason?: string): void;
1174
+ isSuspended(): boolean;
1138
1175
  private abortLocal;
1139
1176
  /** Internal Runtime hook; public callers abort a precise AgentRun. */
1140
1177
  abortFromRuntime(reason?: string): void;
@@ -1208,7 +1245,7 @@ type SessionManager = {
1208
1245
  appendOutcome(outcome: Outcome): Promise<string>;
1209
1246
  appendModelTranscript(transcript: ModelTranscript, meta?: {
1210
1247
  phase?: string;
1211
- model?: LlmModelRef;
1248
+ model?: ModelRef;
1212
1249
  }): Promise<string>;
1213
1250
  buildAgentContext<TTool = unknown>(input?: BuildAgentContextInput<TTool>): Promise<SessionAgentContext<TTool>>;
1214
1251
  };
@@ -1219,12 +1256,24 @@ type SessionManagerProvider = {
1219
1256
 
1220
1257
  type CreateAgentInput = {
1221
1258
  sessionId: string;
1222
- factoryId?: string;
1223
1259
  };
1224
1260
  type EnqueueAgentInput = {
1225
1261
  agentId: AgentId;
1226
1262
  input: AgentMessage;
1227
1263
  };
1264
+ type AcknowledgeEventAndEnqueueAgentInput = EnqueueAgentInput & {
1265
+ consumerId: string;
1266
+ eventId: RuntimeEventId;
1267
+ };
1268
+ type EnqueuedAgentInput = {
1269
+ message: RuntimeMessage;
1270
+ run: AgentRunRecord;
1271
+ resumed: boolean;
1272
+ };
1273
+ type AcknowledgeEventAndEnqueueAgentInputResult = {
1274
+ checkpoint: RuntimeEventCheckpoint;
1275
+ enqueued?: EnqueuedAgentInput;
1276
+ };
1228
1277
  type ListRunsInput = {
1229
1278
  agentId?: AgentId;
1230
1279
  states?: AgentRunRecord["state"][];
@@ -1254,6 +1303,8 @@ type RenewLeaseInput = {
1254
1303
  type SuspendRunInput = {
1255
1304
  runId: AgentRunId;
1256
1305
  reason?: string;
1306
+ inputRequest?: AgentInputRequest;
1307
+ executionState?: AgentRunExecutionState;
1257
1308
  };
1258
1309
  type CompleteRunInput = {
1259
1310
  runId: AgentRunId;
@@ -1293,14 +1344,11 @@ interface RuntimeStateStore {
1293
1344
  getAgent(agentId: AgentId): Promise<AgentRecord | undefined>;
1294
1345
  listAgents(): Promise<AgentRecord[]>;
1295
1346
  setAgentState(agentId: AgentId, state: AgentLifecycleState): Promise<AgentRecord>;
1296
- enqueueAgentInput(input: EnqueueAgentInput): Promise<{
1297
- message: RuntimeMessage;
1298
- run: AgentRunRecord;
1299
- resumed: boolean;
1300
- }>;
1347
+ enqueueAgentInput(input: EnqueueAgentInput): Promise<EnqueuedAgentInput>;
1301
1348
  getMessage(messageId: RuntimeMessageId): Promise<RuntimeMessage | undefined>;
1302
1349
  getRun(runId: AgentRunId): Promise<AgentRunRecord | undefined>;
1303
1350
  listRuns(input?: ListRunsInput): Promise<AgentRunRecord[]>;
1351
+ listActiveRuns(): Promise<AgentRunRecord[]>;
1304
1352
  leaseRun(input: LeaseRunInput): Promise<LeasedRun>;
1305
1353
  renewLease(input: RenewLeaseInput): Promise<RuntimeLease>;
1306
1354
  suspendRun(input: SuspendRunInput): Promise<AgentRunRecord>;
@@ -1319,6 +1367,7 @@ interface RuntimeStateStore {
1319
1367
  recordEvent(input: RecordRuntimeEventInput): Promise<RuntimeEvent>;
1320
1368
  getEventCheckpoint(consumerId: string): Promise<RuntimeEventCheckpoint>;
1321
1369
  acknowledgeEvent(consumerId: string, eventId: RuntimeEventId): Promise<RuntimeEventCheckpoint>;
1370
+ acknowledgeEventAndEnqueueAgentInput(input: AcknowledgeEventAndEnqueueAgentInput): Promise<AcknowledgeEventAndEnqueueAgentInputResult>;
1322
1371
  }
1323
1372
 
1324
1373
  type ToolRuntimePolicy = {
@@ -1328,16 +1377,9 @@ type ToolRuntimePolicy = {
1328
1377
  perToolMaxConcurrent?: Readonly<Record<string, number>>;
1329
1378
  };
1330
1379
 
1331
- type AgentFactoryIdentity = {
1332
- agentId: AgentId;
1333
- sessionId: string;
1334
- factoryId: string;
1335
- };
1336
- type AgentFactory = (identity: AgentFactoryIdentity) => Promise<AgentOptions | undefined> | AgentOptions | undefined;
1337
1380
  type AgentRuntimeOptions = {
1338
1381
  stateStore: RuntimeStateStore;
1339
1382
  sessionProvider?: SessionManagerProvider;
1340
- factories?: ReadonlyMap<string, AgentFactory> | Readonly<Record<string, AgentFactory>>;
1341
1383
  toolPolicy?: ToolRuntimePolicy;
1342
1384
  maxConcurrentRuns?: number;
1343
1385
  maxInfrastructureAttempts?: number;
@@ -1347,7 +1389,16 @@ type AgentRuntimeOptions = {
1347
1389
  type RuntimeRunHandle = {
1348
1390
  notify(run: AgentRunRecord): void;
1349
1391
  };
1350
- type RuntimeEventListener = (event: RuntimeEvent) => void | Promise<void>;
1392
+ type RuntimeEventDisposition = {
1393
+ type: "enqueue";
1394
+ agentId: AgentId;
1395
+ input: AgentMessage;
1396
+ };
1397
+ type RuntimeEventListener = (event: RuntimeEvent) => RuntimeEventDisposition | void | Promise<RuntimeEventDisposition | void>;
1398
+ type RuntimeEventConsumer = {
1399
+ caughtUp: Promise<void>;
1400
+ stop(): void;
1401
+ };
1351
1402
  declare class AgentRuntime {
1352
1403
  private readonly stateStore;
1353
1404
  private readonly sessionProvider?;
@@ -1356,8 +1407,8 @@ declare class AgentRuntime {
1356
1407
  private readonly leaseDurationMs;
1357
1408
  private readonly leaseRenewalIntervalMs;
1358
1409
  private readonly toolRuntime;
1359
- private readonly factories;
1360
1410
  private readonly bindings;
1411
+ private readonly agents;
1361
1412
  private readonly runHandles;
1362
1413
  private readonly runWaiters;
1363
1414
  private readonly pendingRuns;
@@ -1372,7 +1423,7 @@ declare class AgentRuntime {
1372
1423
  private stopped;
1373
1424
  private constructor();
1374
1425
  static start(options: AgentRuntimeOptions): Promise<AgentRuntime>;
1375
- createAgent(options: AgentCreateOptions): Promise<Agent>;
1426
+ createAgent(options: AgentOptions): Promise<Agent>;
1376
1427
  reconstructAgent(agentId: AgentId, options: AgentOptions): Promise<Agent>;
1377
1428
  stop(): Promise<void>;
1378
1429
  private bindAgent;
@@ -1381,8 +1432,15 @@ declare class AgentRuntime {
1381
1432
  private scheduleRun;
1382
1433
  pauseAgent(agentId: AgentId): Promise<void>;
1383
1434
  resumeAgent(agentId: AgentId): Promise<void>;
1435
+ getRun(runId: AgentRunId): Promise<AgentRunRecord | undefined>;
1436
+ listActiveRuns(): Promise<AgentRunRecord[]>;
1437
+ listRuns(input?: ListRunsInput): Promise<AgentRunRecord[]>;
1438
+ getAgent(agentId: AgentId): Agent | undefined;
1439
+ getMessage(messageId: RuntimeMessageId): Promise<RuntimeMessage | undefined>;
1440
+ getToolCall(toolCallId: RuntimeToolCallId): Promise<RuntimeToolCall | undefined>;
1384
1441
  abortRun(runId: AgentRunId, reason?: string): Promise<void>;
1385
- consumeEvents(consumerId: string, listener: RuntimeEventListener): () => void;
1442
+ consumeEvents(consumerId: string, listener: RuntimeEventListener): RuntimeEventConsumer;
1443
+ private registerEventConsumer;
1386
1444
  listEvents(cursor?: RuntimeEventCursor): Promise<RuntimeEvent[]>;
1387
1445
  private recover;
1388
1446
  private scheduleQueuedRuns;
@@ -1404,7 +1462,7 @@ type AgentRunHost = {
1404
1462
  getRun(runId: AgentRunId): Promise<AgentRunRecord | undefined>;
1405
1463
  waitForRunChange(runId: AgentRunId, state: AgentRunState, updatedAt: string): Promise<void>;
1406
1464
  abortRun(runId: AgentRunId, reason: string): Promise<void>;
1407
- consumeEvents(consumerId: string, listener: RuntimeEventListener): () => void;
1465
+ consumeEvents(consumerId: string, listener: RuntimeEventListener): RuntimeEventConsumer;
1408
1466
  };
1409
1467
  declare const CREATE_AGENT_RUN: unique symbol;
1410
1468
  declare class AgentRun implements RuntimeRunHandle {
@@ -1418,18 +1476,17 @@ declare class AgentRun implements RuntimeRunHandle {
1418
1476
  get messageId(): string;
1419
1477
  get status(): AgentRunState;
1420
1478
  get state(): AgentRunState;
1479
+ get inputRequest(): AgentInputRequest | undefined;
1421
1480
  getStatus(): Promise<AgentRunState>;
1422
1481
  subscribe(listener: AgentRunListener): () => void;
1423
- consumeRuntimeEvents(consumerId: string, listener: RuntimeEventListener): () => void;
1482
+ consumeRuntimeEvents(consumerId: string, listener: RuntimeEventListener): RuntimeEventConsumer;
1424
1483
  result(): Promise<Outcome>;
1425
1484
  abort(reason?: string): Promise<void>;
1426
1485
  notify(run: AgentRunRecord): void;
1427
1486
  }
1428
1487
 
1429
- type AgentOptions = {
1488
+ type AgentCommonOptions = {
1430
1489
  context: AgentContext;
1431
- model: LlmModelRef;
1432
- stream: StreamFn;
1433
1490
  cwd?: string;
1434
1491
  extensions?: LoadedExtension[];
1435
1492
  maxAttempts?: number;
@@ -1439,15 +1496,23 @@ type AgentOptions = {
1439
1496
  onOutcome?: (outcome: Outcome) => Promise<void>;
1440
1497
  onModelTranscript?: (transcript: ModelTranscript, meta: {
1441
1498
  phase: string;
1442
- model: LlmModelRef;
1499
+ model: ModelRef;
1443
1500
  }) => Promise<void>;
1444
1501
  };
1445
- type AgentCreateOptions = AgentOptions & {
1446
- input?: string;
1447
- factoryId?: string;
1502
+ type AgentModelOptions = {
1503
+ model: ModelConfig;
1504
+ stream?: never;
1505
+ } | {
1506
+ model: ModelRef;
1507
+ stream: StreamFn;
1508
+ };
1509
+ type AgentOptions = AgentCommonOptions & AgentModelOptions;
1510
+ type StreamAgentOptions = AgentCommonOptions & {
1511
+ model: ModelRef;
1512
+ stream: StreamFn;
1448
1513
  };
1449
1514
  type AgentRunControl = {
1450
- suspend(reason?: string): Promise<void>;
1515
+ suspend(reason?: string, state?: AgentRunExecutionState, inputRequest?: AgentInputRequest): Promise<void>;
1451
1516
  };
1452
1517
  declare const ATTACH_AGENT: unique symbol;
1453
1518
  declare class Agent {
@@ -1465,12 +1530,12 @@ declare class Agent {
1465
1530
  send(input: string | AgentMessage): Promise<AgentRun>;
1466
1531
  }
1467
1532
 
1468
- declare class InMemorySessionProvider implements SessionManagerProvider {
1533
+ declare class InMemorySessionStore implements SessionManagerProvider {
1469
1534
  private readonly sessions;
1470
1535
  create(input: CreateSessionManagerInput): Promise<SessionManager>;
1471
1536
  open(sessionId: string): Promise<SessionManager | undefined>;
1472
1537
  }
1473
- declare class LocalJsonlSessionProvider implements SessionManagerProvider {
1538
+ declare class JsonlSessionStore implements SessionManagerProvider {
1474
1539
  private readonly sessionsDir;
1475
1540
  constructor(sessionsDir: string);
1476
1541
  create(input: CreateSessionManagerInput): Promise<SessionManager>;
@@ -1497,14 +1562,12 @@ declare class InMemoryRuntimeStateStore implements RuntimeStateStore {
1497
1562
  getAgent(agentId: AgentId): Promise<AgentRecord | undefined>;
1498
1563
  listAgents(): Promise<AgentRecord[]>;
1499
1564
  setAgentState(agentId: AgentId, state: AgentRecord["state"]): Promise<AgentRecord>;
1500
- enqueueAgentInput(input: EnqueueAgentInput): Promise<{
1501
- message: RuntimeMessage;
1502
- run: AgentRunRecord;
1503
- resumed: boolean;
1504
- }>;
1565
+ enqueueAgentInput(input: EnqueueAgentInput): Promise<EnqueuedAgentInput>;
1566
+ private enqueueAgentInputState;
1505
1567
  getMessage(messageId: RuntimeMessageId): Promise<RuntimeMessage | undefined>;
1506
1568
  getRun(runId: AgentRunId): Promise<AgentRunRecord | undefined>;
1507
1569
  listRuns(input?: ListRunsInput): Promise<AgentRunRecord[]>;
1570
+ listActiveRuns(): Promise<AgentRunRecord[]>;
1508
1571
  leaseRun(input: LeaseRunInput): Promise<LeasedRun>;
1509
1572
  renewLease(input: RenewLeaseInput): Promise<RuntimeLease>;
1510
1573
  suspendRun(input: SuspendRunInput): Promise<AgentRunRecord>;
@@ -1523,6 +1586,7 @@ declare class InMemoryRuntimeStateStore implements RuntimeStateStore {
1523
1586
  recordEvent(input: RecordRuntimeEventInput | RuntimeEventKind, related?: Pick<RuntimeEvent, "agentId" | "messageId" | "runId" | "toolCallId">, payload?: unknown): Promise<RuntimeEvent>;
1524
1587
  getEventCheckpoint(consumerId: string): Promise<RuntimeEventCheckpoint>;
1525
1588
  acknowledgeEvent(consumerId: string, eventId: RuntimeEventId): Promise<RuntimeEventCheckpoint>;
1589
+ acknowledgeEventAndEnqueueAgentInput(input: AcknowledgeEventAndEnqueueAgentInput): Promise<AcknowledgeEventAndEnqueueAgentInputResult>;
1526
1590
  private requireAgent;
1527
1591
  private requireMessage;
1528
1592
  private requireRun;
@@ -1538,14 +1602,12 @@ declare class SqliteRuntimeStateStore implements RuntimeStateStore {
1538
1602
  getAgent(agentId: AgentId): Promise<AgentRecord | undefined>;
1539
1603
  listAgents(): Promise<AgentRecord[]>;
1540
1604
  setAgentState(agentId: AgentId, state: AgentRecord["state"]): Promise<AgentRecord>;
1541
- enqueueAgentInput(input: EnqueueAgentInput): Promise<{
1542
- message: RuntimeMessage;
1543
- run: AgentRunRecord;
1544
- resumed: boolean;
1545
- }>;
1605
+ enqueueAgentInput(input: EnqueueAgentInput): Promise<EnqueuedAgentInput>;
1606
+ private enqueueAgentInputState;
1546
1607
  getMessage(messageId: RuntimeMessageId): Promise<RuntimeMessage | undefined>;
1547
1608
  getRun(runId: AgentRunId): Promise<AgentRunRecord | undefined>;
1548
1609
  listRuns(input?: ListRunsInput): Promise<AgentRunRecord[]>;
1610
+ listActiveRuns(): Promise<AgentRunRecord[]>;
1549
1611
  leaseRun(input: LeaseRunInput): Promise<LeasedRun>;
1550
1612
  renewLease(input: RenewLeaseInput): Promise<RuntimeLease>;
1551
1613
  suspendRun(input: SuspendRunInput): Promise<AgentRunRecord>;
@@ -1564,6 +1626,8 @@ declare class SqliteRuntimeStateStore implements RuntimeStateStore {
1564
1626
  recordEvent(input: RecordRuntimeEventInput | RuntimeEventKind, related?: Pick<RuntimeEvent, "agentId" | "messageId" | "runId" | "toolCallId">, payload?: unknown): Promise<RuntimeEvent>;
1565
1627
  getEventCheckpoint(consumerId: string): Promise<RuntimeEventCheckpoint>;
1566
1628
  acknowledgeEvent(consumerId: string, eventId: RuntimeEventId): Promise<RuntimeEventCheckpoint>;
1629
+ acknowledgeEventAndEnqueueAgentInput(input: AcknowledgeEventAndEnqueueAgentInput): Promise<AcknowledgeEventAndEnqueueAgentInputResult>;
1630
+ private acknowledgeEventState;
1567
1631
  private insertMessage;
1568
1632
  private agentFromRow;
1569
1633
  private messageFromRow;
@@ -1581,4 +1645,4 @@ declare class SqliteRuntimeStateStore implements RuntimeStateStore {
1581
1645
  private recordEventInternal;
1582
1646
  }
1583
1647
 
1584
- export { type AfterToolCall, Agent, type AgentContext, type AgentCreateOptions, type AgentFactory, type AgentFactoryIdentity, type AgentId, type AgentOptions, AgentRun, type AgentRunId, type AgentRunListener, type AgentRunState, AgentRuntime, type AgentRuntimeOptions, type BeforeToolCall, type CoreToolContext, type ExecutionTurn, type ExtensionAPI, type ExtensionFactory, type HookEvent, type HookEventType, type HookHandler, InMemoryRuntimeStateStore, InMemorySessionProvider, type LoadExtensionsResult, type LoadedExtension, LocalJsonlSessionProvider, type LoopMetrics, type ModelTranscript, type Phase, type PhaseContext, type PhaseExecution, type PhaseOutput, type PhaseRegistration, type PhaseRegistry, type PhaseState, type RuntimeEvent, type RuntimeEventCursor, type RuntimeEventKind, type RuntimeEventListener, type SessionManagerProvider, SqliteRuntimeStateStore, type Tool, type ToolContext, type ToolDefinition, type ToolExecutionMode, type ToolExecutionResult, type ToolRuntimePolicy, type Unsubscribe, createCoreTools, createMessage };
1648
+ export { type AfterToolCall, Agent, type AgentContext, type AgentId, type AgentInputRequest, type AgentOptions, AgentRun, type AgentRunExecutionState, type AgentRunId, type AgentRunListener, type AgentRunMetadata, type AgentRunRecord, type AgentRunState, AgentRuntime, type AgentRuntimeOptions, type BeforeToolCall, type CoreToolContext, type ExecutionTurn, type ExtensionAPI, type ExtensionFactory, type HookEvent, type HookEventType, type HookHandler, InMemoryRuntimeStateStore, InMemorySessionStore, JsonlSessionStore, type LoadExtensionsResult, type LoadedExtension, type LoopMetrics, type ModelTranscript, type Phase, type PhaseContext, type PhaseExecution, type PhaseInvocation, type PhaseOutput, type PhaseRegistration, type PhaseRegistry, type PhaseState, type RuntimeEvent, type RuntimeEventConsumer, type RuntimeEventCursor, type RuntimeEventDisposition, type RuntimeEventKind, type RuntimeEventListener, type RuntimeMessage, type RuntimeMessageId, type RuntimeToolCall, type RuntimeToolCallId, type SessionManagerProvider, SqliteRuntimeStateStore, type Tool, type ToolContext, type ToolDefinition, type ToolExecutionMode, type ToolExecutionResult, type ToolRuntimePolicy, type Unsubscribe, createCoreTools, createMessage };