@rowan-agent/agent 0.10.1 → 0.11.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.
Files changed (3) hide show
  1. package/dist/index.d.ts +135 -99
  2. package/dist/index.js +611 -171
  3. package/package.json +1 -1
package/dist/index.d.ts CHANGED
@@ -55,78 +55,6 @@ type ToolResult = {
55
55
  error?: string;
56
56
  };
57
57
 
58
- interface BeforePhaseEvent {
59
- type: "before_phase";
60
- phaseId: string;
61
- input: PhaseContext;
62
- }
63
- interface AfterPhaseEvent {
64
- type: "after_phase";
65
- phaseId: string;
66
- output: PhaseOutput;
67
- }
68
- interface BeforePromptEvent {
69
- type: "before_prompt";
70
- phaseId: string;
71
- input: PhaseContext;
72
- }
73
- interface BeforeToolCallEvent {
74
- type: "before_tool_call";
75
- tool: Tool$1;
76
- args: unknown;
77
- }
78
- interface AfterToolCallEvent {
79
- type: "after_tool_call";
80
- tool: Tool$1;
81
- result: ToolResult;
82
- }
83
- type HookEvent = BeforePhaseEvent | AfterPhaseEvent | BeforePromptEvent | BeforeToolCallEvent | AfterToolCallEvent;
84
- interface BeforePhaseResult {
85
- abort?: Outcome$1;
86
- skip?: {
87
- route: string;
88
- message: string;
89
- };
90
- input?: PhaseContext;
91
- }
92
- interface AfterPhaseResult {
93
- abort?: Outcome$1;
94
- retry?: PhaseContext;
95
- output?: PhaseOutput;
96
- }
97
- interface BeforePromptResult {
98
- input?: PhaseContext;
99
- }
100
- interface BeforeToolCallResult {
101
- allow: boolean;
102
- reason?: string;
103
- }
104
- interface AfterToolCallResult {
105
- result?: ToolResult;
106
- }
107
- interface HookResultMap {
108
- before_phase: BeforePhaseResult | undefined;
109
- after_phase: AfterPhaseResult | undefined;
110
- before_prompt: BeforePromptResult | undefined;
111
- before_tool_call: BeforeToolCallResult | undefined;
112
- after_tool_call: AfterToolCallResult | undefined;
113
- }
114
- type HookEventType = HookEvent["type"];
115
- type HookHandler<K extends HookEventType> = (event: Extract<HookEvent, {
116
- type: K;
117
- }>) => HookResultMap[K] | Promise<HookResultMap[K]> | void | Promise<void>;
118
- declare class HooksManager {
119
- private handlers;
120
- on<K extends HookEventType>(eventType: K, handler: HookHandler<K>): void;
121
- off<K extends HookEventType>(eventType: K, handler: HookHandler<K>): void;
122
- emit<K extends HookEventType>(eventType: K, event: Extract<HookEvent, {
123
- type: K;
124
- }>): Promise<void>;
125
- emitFirst<K extends HookEventType>(eventType: K, event: Extract<HookEvent, {
126
- type: K;
127
- }>): Promise<HookResultMap[K] | undefined>;
128
- }
129
-
130
58
  type LoopMetrics = {
131
59
  /** Number of phase iterations executed. */
132
60
  iterations: number;
@@ -170,6 +98,7 @@ type ExecutionContinuationState = {
170
98
 
171
99
  type PhaseInteractionKind = "user_input" | "permission" | "elicitation" | "confirmation";
172
100
  type PhaseInteractionStatus = "pending" | "answered" | "denied" | "cancelled" | "expired";
101
+ type PhaseInteractionOrigin = "tool_call" | "phase";
173
102
  type PhaseInteraction = Readonly<{
174
103
  id: string;
175
104
  phase: string;
@@ -178,6 +107,8 @@ type PhaseInteraction = Readonly<{
178
107
  payload?: JsonValue;
179
108
  createdAt: string;
180
109
  status: PhaseInteractionStatus;
110
+ origin?: PhaseInteractionOrigin;
111
+ toolCallId?: string;
181
112
  }>;
182
113
  type PhaseInteractionState = Readonly<{
183
114
  requests: readonly PhaseInteraction[];
@@ -191,9 +122,13 @@ type PhaseInteractionDriver = Readonly<{
191
122
  kind: PhaseInteractionKind;
192
123
  prompt: string;
193
124
  payload?: JsonValue;
125
+ origin?: PhaseInteractionOrigin;
126
+ toolCallId?: string;
194
127
  }>): PhaseInteraction;
195
128
  pending(): readonly PhaseInteraction[];
196
129
  answers(): ReadonlyMap<string, JsonValue>;
130
+ checkpoint(): JsonValue | undefined;
131
+ clearCheckpoint(): void;
197
132
  suspend(input?: Readonly<{
198
133
  checkpoint?: JsonValue;
199
134
  }>): never;
@@ -418,10 +353,10 @@ type RunStateChanged = DurableEventBase & (Readonly<{
418
353
  kind: "run_state_changed";
419
354
  from: "running";
420
355
  to: "input_required";
421
- request: Readonly<{
356
+ request?: Readonly<{
422
357
  id: InputRequestId;
423
358
  phase: string;
424
- prompt: AssistantMessage;
359
+ prompt?: AssistantMessage;
425
360
  }>;
426
361
  interactions: readonly PhaseInteraction[];
427
362
  answers: Readonly<Record<string, JsonValue>>;
@@ -1115,6 +1050,95 @@ interface PhaseRegistry {
1115
1050
  entryPhaseId: string | null;
1116
1051
  }
1117
1052
 
1053
+ type ToolCallInteractionKind = PhaseInteractionKind;
1054
+ interface ToolCallInteractionRequest$1 {
1055
+ id?: string;
1056
+ kind: ToolCallInteractionKind;
1057
+ prompt: string;
1058
+ payload?: JsonValue;
1059
+ }
1060
+ interface BeforePhaseEvent {
1061
+ type: "before_phase";
1062
+ phaseId: string;
1063
+ input: PhaseContext;
1064
+ }
1065
+ interface AfterPhaseEvent {
1066
+ type: "after_phase";
1067
+ phaseId: string;
1068
+ output: PhaseOutput;
1069
+ }
1070
+ interface BeforePromptEvent {
1071
+ type: "before_prompt";
1072
+ phaseId: string;
1073
+ input: PhaseContext;
1074
+ }
1075
+ interface BeforeToolCallEvent {
1076
+ type: "before_tool_call";
1077
+ tool: Tool$1;
1078
+ args: unknown;
1079
+ readonly runId?: string;
1080
+ readonly agentId?: string;
1081
+ readonly toolCallId?: string;
1082
+ readonly metadata?: Readonly<Record<string, unknown>>;
1083
+ readonly answer?: unknown;
1084
+ }
1085
+ interface AfterToolCallEvent {
1086
+ type: "after_tool_call";
1087
+ tool: Tool$1;
1088
+ result: ToolResult;
1089
+ readonly runId?: string;
1090
+ readonly agentId?: string;
1091
+ readonly toolCallId?: string;
1092
+ readonly metadata?: Readonly<Record<string, unknown>>;
1093
+ }
1094
+ type HookEvent = BeforePhaseEvent | AfterPhaseEvent | BeforePromptEvent | BeforeToolCallEvent | AfterToolCallEvent;
1095
+ interface BeforePhaseResult {
1096
+ abort?: Outcome$1;
1097
+ skip?: {
1098
+ route: string;
1099
+ message: string;
1100
+ };
1101
+ input?: PhaseContext;
1102
+ }
1103
+ interface AfterPhaseResult {
1104
+ abort?: Outcome$1;
1105
+ retry?: PhaseContext;
1106
+ output?: PhaseOutput;
1107
+ }
1108
+ interface BeforePromptResult {
1109
+ input?: PhaseContext;
1110
+ }
1111
+ interface BeforeToolCallResult {
1112
+ allow?: boolean;
1113
+ reason?: string;
1114
+ interaction?: ToolCallInteractionRequest$1;
1115
+ }
1116
+ interface AfterToolCallResult {
1117
+ result?: ToolResult;
1118
+ }
1119
+ interface HookResultMap {
1120
+ before_phase: BeforePhaseResult | undefined;
1121
+ after_phase: AfterPhaseResult | undefined;
1122
+ before_prompt: BeforePromptResult | undefined;
1123
+ before_tool_call: BeforeToolCallResult | undefined;
1124
+ after_tool_call: AfterToolCallResult | undefined;
1125
+ }
1126
+ type HookEventType = HookEvent["type"];
1127
+ type HookHandler<K extends HookEventType> = (event: Extract<HookEvent, {
1128
+ type: K;
1129
+ }>) => HookResultMap[K] | Promise<HookResultMap[K]> | void | Promise<void>;
1130
+ declare class HooksManager {
1131
+ private handlers;
1132
+ on<K extends HookEventType>(eventType: K, handler: HookHandler<K>): void;
1133
+ off<K extends HookEventType>(eventType: K, handler: HookHandler<K>): void;
1134
+ emit<K extends HookEventType>(eventType: K, event: Extract<HookEvent, {
1135
+ type: K;
1136
+ }>): Promise<void>;
1137
+ emitFirst<K extends HookEventType>(eventType: K, event: Extract<HookEvent, {
1138
+ type: K;
1139
+ }>): Promise<HookResultMap[K] | undefined>;
1140
+ }
1141
+
1118
1142
  type ToolContext = Pick<AgentContext, "skills"> & {
1119
1143
  toolCallId: string;
1120
1144
  };
@@ -1406,11 +1430,19 @@ declare class ExtensionRunner {
1406
1430
  output?: PhaseOutput;
1407
1431
  }>;
1408
1432
  emitBeforePrompt(phaseId: string, input: PhaseContext): Promise<PhaseContext>;
1409
- emitBeforeToolCall(tool: Tool$1, args: unknown): Promise<{
1410
- allow: boolean;
1411
- reason?: string;
1412
- }>;
1413
- emitAfterToolCall(tool: Tool$1, result: ToolResult): Promise<ToolResult>;
1433
+ emitBeforeToolCall(tool: Tool$1, args: unknown, context?: {
1434
+ runId?: string;
1435
+ agentId?: string;
1436
+ toolCallId?: string;
1437
+ metadata?: Readonly<Record<string, unknown>>;
1438
+ answer?: unknown;
1439
+ }): Promise<BeforeToolCallResult>;
1440
+ emitAfterToolCall(tool: Tool$1, result: ToolResult, context?: {
1441
+ runId?: string;
1442
+ agentId?: string;
1443
+ toolCallId?: string;
1444
+ metadata?: Readonly<Record<string, unknown>>;
1445
+ }): Promise<ToolResult>;
1414
1446
  /**
1415
1447
  * Create an ExtensionAPI for a specific extension.
1416
1448
  * Registration methods write to the extension tracking object.
@@ -1574,22 +1606,27 @@ type ContextCandidate = Readonly<{
1574
1606
  name: string;
1575
1607
  value: JsonValue;
1576
1608
  }>;
1577
- type BeforeToolCall = (input: Readonly<{
1578
- tool: Tool;
1579
- args: JsonValue;
1580
- context: ToolInvocationContext;
1581
- signal: AbortSignal;
1582
- }>) => Readonly<{
1609
+ type ToolCallInteractionRequest = Readonly<{
1610
+ id?: string;
1611
+ kind: PhaseInteractionKind;
1612
+ prompt: string;
1613
+ payload?: JsonValue;
1614
+ }>;
1615
+ type BeforeToolCallDecision = Readonly<{
1583
1616
  allow: true;
1584
1617
  }> | Readonly<{
1585
1618
  allow: false;
1586
1619
  reason: string;
1587
- }> | Promise<Readonly<{
1588
- allow: true;
1589
1620
  }> | Readonly<{
1590
- allow: false;
1591
- reason: string;
1592
- }>>;
1621
+ interaction: ToolCallInteractionRequest;
1622
+ }>;
1623
+ type BeforeToolCall = (input: Readonly<{
1624
+ tool: Tool;
1625
+ args: JsonValue;
1626
+ context: ToolInvocationContext;
1627
+ signal: AbortSignal;
1628
+ answer?: JsonValue;
1629
+ }>) => BeforeToolCallDecision | Promise<BeforeToolCallDecision>;
1593
1630
  type AfterToolCall = (input: Readonly<{
1594
1631
  tool: Tool;
1595
1632
  result: ToolExecutionResult$1;
@@ -1634,7 +1671,7 @@ type ExecutionCheckpoint = Readonly<{
1634
1671
  type InputRequest = Readonly<{
1635
1672
  id: InputRequestId;
1636
1673
  phase: string;
1637
- messageId: MessageId;
1674
+ messageId?: MessageId;
1638
1675
  createdAt: string;
1639
1676
  }>;
1640
1677
  type OwnerLease = Readonly<{
@@ -1650,7 +1687,7 @@ type RunClaim = Readonly<{
1650
1687
  }>;
1651
1688
  type InputRequiredCommit = Readonly<{
1652
1689
  run: RunRecord;
1653
- prompt: AssistantMessage;
1690
+ prompt?: AssistantMessage;
1654
1691
  request: InputRequest;
1655
1692
  interactions: readonly PhaseInteraction[];
1656
1693
  }>;
@@ -1751,7 +1788,7 @@ type RunSnapshot = RunSnapshotBase & (Readonly<{
1751
1788
  request: Readonly<{
1752
1789
  id: InputRequestId;
1753
1790
  phase: string;
1754
- prompt: AssistantMessage;
1791
+ prompt?: AssistantMessage;
1755
1792
  }>;
1756
1793
  interactions: readonly PhaseInteraction[];
1757
1794
  answers: Readonly<Record<string, JsonValue>>;
@@ -1770,7 +1807,7 @@ type RunBoundary = Readonly<{
1770
1807
  type: "input_required";
1771
1808
  requestId: InputRequestId;
1772
1809
  phase: string;
1773
- prompt: AssistantMessage;
1810
+ prompt?: AssistantMessage;
1774
1811
  interactions: readonly PhaseInteraction[];
1775
1812
  answers: Readonly<Record<string, JsonValue>>;
1776
1813
  }> | Readonly<{
@@ -1870,7 +1907,7 @@ interface OwnedStore {
1870
1907
  expectedRevision: number;
1871
1908
  requestId?: InputRequestId;
1872
1909
  phase: string;
1873
- prompt: AssistantMessage;
1910
+ prompt?: AssistantMessage;
1874
1911
  checkpoint: ExecutionCheckpoint;
1875
1912
  interactions?: readonly PhaseInteraction[];
1876
1913
  interactionAnswers?: Readonly<Record<string, JsonValue>>;
@@ -2169,7 +2206,6 @@ declare class AgentRuntime implements AgentRuntime$1 {
2169
2206
  private resolveContextWindow;
2170
2207
  private executeTool;
2171
2208
  private executeToolBatch;
2172
- private executeReservedTool;
2173
2209
  private requireAgent;
2174
2210
  private archiveDirFor;
2175
2211
  private runConsumer;
@@ -2288,7 +2324,7 @@ declare class InMemoryStore implements DurableStore {
2288
2324
  expectedRevision: number;
2289
2325
  requestId?: InputRequestId;
2290
2326
  phase: string;
2291
- prompt: AssistantMessage;
2327
+ prompt?: AssistantMessage;
2292
2328
  checkpoint: ExecutionCheckpoint;
2293
2329
  interactions?: readonly PhaseInteraction[];
2294
2330
  interactionAnswers?: Readonly<Record<string, JsonValue>>;
@@ -2484,7 +2520,7 @@ declare class SqliteStore implements DurableStore {
2484
2520
  expectedRevision: number;
2485
2521
  requestId?: InputRequestId;
2486
2522
  phase: string;
2487
- prompt: AssistantMessage;
2523
+ prompt?: AssistantMessage;
2488
2524
  checkpoint: ExecutionCheckpoint;
2489
2525
  interactions?: readonly PhaseInteraction[];
2490
2526
  interactionAnswers?: Readonly<Record<string, JsonValue>>;
@@ -2782,4 +2818,4 @@ declare function parseFrontmatter<T = Record<string, unknown>>(raw: string): Fro
2782
2818
 
2783
2819
  declare function createCoreTools(input?: CoreToolContext): Tool[];
2784
2820
 
2785
- export { type AfterToolCall, type AgentConfiguration, type AgentDefinition, type AgentId, type AgentListCursor, type AgentRecord, type AgentRun, AgentRuntime, type AgentRuntimeOptions, type AgentSummary, type AnyRuntimeError, type AssistantContent, type AssistantMessage, type BeforeToolCall, COMPACT_PHASE_ID, type ConfigProvider, type ConfigPutResult, type ConfigResolution, type ConfigToken, type ConfigurationSnapshot, type ContextCandidate, type ContextCompactionRecord, type ContextStatus, type CoreToolContext, DEFAULT_PHASE_ID, type DefinitionLayer, type DurableConsumer, type DurableRunEvent, type DurableStore, type DurableToolResult, type EventCursor, type EventId, type ExecutionCheckpoint, type ExecutionId, type ExecutionToken, type ExtensionAPI, type ExtensionActivationError, type ExtensionActivationResult, type ExtensionContribution, type ExtensionDisposer, type ExtensionFactory, type ExtensionFactoryResult, ExtensionLifetimeError, type ExtensionLifetimeErrorCode, type ExtensionLoadInput, type FrontmatterResult, type HistorySeed, type HookEvent, type HookEventType, type HookHandler, InMemoryConfigProvider, InMemoryStore, type InputRequest, type InputRequestId, type InputRequiredCommit, type InvocationCatalogEntry, type InvocationSource, type JsonObject, type JsonPrimitive, type JsonValue, type LoadExtensionsResult, type LoadInput, type LoadResult, type LoadedExtension, type Message, type MessageBase, type MessageCommitted, type MessageContent, type MessageDelta, type MessageId, type MessageRevised, type MessageRevisionResult, type Metadata, type OpaqueId, type Outcome, type OwnerLease, type OwnerToken, type Page, type Phase, type PhaseContext, type PhaseContribution, type PhaseExecution, type PhaseExecutionIdentity, type PhaseInput, type PhaseInteraction, PhaseInteractionBoundary, PhaseInteractionCancelledError, type PhaseInteractionDriver, type PhaseInteractionKind, type PhaseInteractionState, type PhaseInteractionStatus, type PhaseInvocation, type PhaseMessageManager, type PhaseOutput, type PhaseRegistry, type PhaseRegistrySelection, type PhaseSettingsBadge, type PhaseSettingsContext, type PhaseSettingsControl, type PhaseSettingsDefinition, type PhaseSettingsItem, type PhaseSettingsOption, type PhaseSettingsProvider, type PhaseSettingsSection, type PhaseState, type PhaseStatus, type PhaseStatusState, type ResolvedResourceView, type ResourceDiagnostic, type ResourceKind, type ResourceRef, ResourceRegistry, ResourceRegistryError, type ResourceRegistryErrorCode, type ResourceSourceId, type ResourceView, type RetentionResult, type RunBoundary, type RunClaim, type RunEvent, type RunFailure, type RunId, type RunListCursor, type RunRecord, type RunSnapshot, type RunState, type RunStateChanged, type RunSummary, RuntimeBootstrapRegistry, RuntimeError, type RuntimeErrorCode, type RuntimeErrorDetails, RuntimeExtensionLifetime, STOP_PHASE_ID, type Skill, SqliteStore, type TextContent, type ThinkingContent, type ThinkingDelta, type Tool, type ToolCallId, type ToolCallSnapshot, type ToolCallState, type ToolContribution, type ToolDefinition, type ToolExecutionResult$1 as ToolExecutionResult, type ToolInvocationContext, type ToolMessage, type ToolMessageContent, type ToolProgress, type ToolResultContent, type ToolStateChanged, type ToolUseContent, type UserContent, type UserInput, type UserMessage, brandConfigToken, createCompactPhase, createCorePhases, createCoreTools, createDefaultPhase, createStopPhase, isConfigurationSnapshot, isRuntimeError, loadExtensionsFromPath as loadExtensions, loadPhase, loadPhaseSettings, loadPhases, loadSkill, loadSkills, parseAgentDefinition, parseFrontmatter, resolveConfigurationSnapshot };
2821
+ export { type AfterToolCall, type AgentConfiguration, type AgentDefinition, type AgentId, type AgentListCursor, type AgentRecord, type AgentRun, AgentRuntime, type AgentRuntimeOptions, type AgentSummary, type AnyRuntimeError, type AssistantContent, type AssistantMessage, type BeforeToolCall, COMPACT_PHASE_ID, type ConfigProvider, type ConfigPutResult, type ConfigResolution, type ConfigToken, type ConfigurationSnapshot, type ContextCandidate, type ContextCompactionRecord, type ContextStatus, type CoreToolContext, DEFAULT_PHASE_ID, type DefinitionLayer, type DurableConsumer, type DurableRunEvent, type DurableStore, type DurableToolResult, type EventCursor, type EventId, type ExecutionCheckpoint, type ExecutionId, type ExecutionToken, type ExtensionAPI, type ExtensionActivationError, type ExtensionActivationResult, type ExtensionContribution, type ExtensionDisposer, type ExtensionFactory, type ExtensionFactoryResult, ExtensionLifetimeError, type ExtensionLifetimeErrorCode, type ExtensionLoadInput, type FrontmatterResult, type HistorySeed, type HookEvent, type HookEventType, type HookHandler, InMemoryConfigProvider, InMemoryStore, type InputRequest, type InputRequestId, type InputRequiredCommit, type InvocationCatalogEntry, type InvocationSource, type JsonObject, type JsonPrimitive, type JsonValue, type LoadExtensionsResult, type LoadInput, type LoadResult, type LoadedExtension, type Message, type MessageBase, type MessageCommitted, type MessageContent, type MessageDelta, type MessageId, type MessageRevised, type MessageRevisionResult, type Metadata, type OpaqueId, type Outcome, type OwnerLease, type OwnerToken, type Page, type Phase, type PhaseContext, type PhaseContribution, type PhaseExecution, type PhaseExecutionIdentity, type PhaseInput, type PhaseInteraction, PhaseInteractionBoundary, PhaseInteractionCancelledError, type PhaseInteractionDriver, type PhaseInteractionKind, type PhaseInteractionOrigin, type PhaseInteractionState, type PhaseInteractionStatus, type PhaseInvocation, type PhaseMessageManager, type PhaseOutput, type PhaseRegistry, type PhaseRegistrySelection, type PhaseSettingsBadge, type PhaseSettingsContext, type PhaseSettingsControl, type PhaseSettingsDefinition, type PhaseSettingsItem, type PhaseSettingsOption, type PhaseSettingsProvider, type PhaseSettingsSection, type PhaseState, type PhaseStatus, type PhaseStatusState, type ResolvedResourceView, type ResourceDiagnostic, type ResourceKind, type ResourceRef, ResourceRegistry, ResourceRegistryError, type ResourceRegistryErrorCode, type ResourceSourceId, type ResourceView, type RetentionResult, type RunBoundary, type RunClaim, type RunEvent, type RunFailure, type RunId, type RunListCursor, type RunRecord, type RunSnapshot, type RunState, type RunStateChanged, type RunSummary, RuntimeBootstrapRegistry, RuntimeError, type RuntimeErrorCode, type RuntimeErrorDetails, RuntimeExtensionLifetime, STOP_PHASE_ID, type Skill, SqliteStore, type TextContent, type ThinkingContent, type ThinkingDelta, type Tool, type ToolCallId, type ToolCallInteractionRequest, type ToolCallSnapshot, type ToolCallState, type ToolContribution, type ToolDefinition, type ToolExecutionResult$1 as ToolExecutionResult, type ToolInvocationContext, type ToolMessage, type ToolMessageContent, type ToolProgress, type ToolResultContent, type ToolStateChanged, type ToolUseContent, type UserContent, type UserInput, type UserMessage, brandConfigToken, createCompactPhase, createCorePhases, createCoreTools, createDefaultPhase, createStopPhase, isConfigurationSnapshot, isRuntimeError, loadExtensionsFromPath as loadExtensions, loadPhase, loadPhaseSettings, loadPhases, loadSkill, loadSkills, parseAgentDefinition, parseFrontmatter, resolveConfigurationSnapshot };