@rowan-agent/agent 0.4.6 → 0.4.8
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.
- package/README.md +671 -48
- package/dist/chunk-2FIII4GP.js +142 -0
- package/dist/chunk-APSIAOUD.js +505 -0
- package/dist/index.cjs +3989 -3646
- package/dist/index.d.cts +484 -689
- package/dist/index.d.ts +484 -689
- package/dist/index.js +3372 -3687
- package/dist/loader-MVD5JAKM.js +13 -0
- package/dist/path-XORRK2EC.js +28 -0
- package/package.json +11 -4
package/dist/index.d.cts
CHANGED
|
@@ -1,13 +1,31 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import * as _rowan_agent_models from '@rowan-agent/models';
|
|
2
|
+
import { LlmRequest, LlmResponse, LlmModelRef, LlmModelUsage, StreamFn, AgentEventListener, ToolCall, ToolResult, AgentMessage, Outcome, Skill as Skill$1, ContentBlock, ProviderConfig, Protocol, ModelCost, AgentEvent, LlmMessage } from '@rowan-agent/models';
|
|
3
|
+
export { AgentEvent, AgentEventListener, AgentMessage, LlmModelRef, Outcome, Skill, StreamFn, ToolResult } from '@rowan-agent/models';
|
|
3
4
|
import Type from 'typebox';
|
|
4
5
|
|
|
5
|
-
type
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
type ExecutionTurn = {
|
|
7
|
+
id: string;
|
|
8
|
+
sessionId: string;
|
|
9
|
+
parentSessionId?: string;
|
|
10
|
+
phase: string;
|
|
11
|
+
requestedAtMs: number;
|
|
12
|
+
completedAtMs: number;
|
|
13
|
+
model: LlmModelRef;
|
|
14
|
+
usage?: LlmModelUsage;
|
|
15
|
+
};
|
|
16
|
+
type StepFilter = {
|
|
17
|
+
phase?: string;
|
|
18
|
+
afterMs?: number;
|
|
19
|
+
};
|
|
20
|
+
/** Raw model input/output for session persistence. */
|
|
21
|
+
type ModelTranscript = {
|
|
22
|
+
request: LlmRequest;
|
|
23
|
+
response: LlmResponse;
|
|
10
24
|
};
|
|
25
|
+
|
|
26
|
+
type BeforePhaseHook = (phaseId: string, input: PhaseContext) => Promise<BeforePhaseHookResult>;
|
|
27
|
+
type AfterPhaseHook = (phaseId: string, output: PhaseOutput) => Promise<AfterPhaseHookResult>;
|
|
28
|
+
type BeforePromptHook = (phaseId: string, input: PhaseContext) => Promise<PhaseContext>;
|
|
11
29
|
type LoopMetrics = {
|
|
12
30
|
/** Number of phase iterations executed. */
|
|
13
31
|
iterations: number;
|
|
@@ -30,103 +48,49 @@ type LoopMetrics = {
|
|
|
30
48
|
/** Total wall-clock duration in ms. */
|
|
31
49
|
durationMs?: number;
|
|
32
50
|
};
|
|
33
|
-
type
|
|
34
|
-
agentState: AgentState;
|
|
51
|
+
type SessionState = {
|
|
35
52
|
currentPhase: string;
|
|
36
53
|
attempt: number;
|
|
37
|
-
transcript: AgentMessage$1[];
|
|
38
|
-
/** Loop execution metrics. */
|
|
39
54
|
metrics: LoopMetrics;
|
|
55
|
+
status: "idle" | "running" | "completed" | "aborted" | "failed";
|
|
40
56
|
};
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
id: string;
|
|
45
|
-
parentSessionId?: string;
|
|
46
|
-
systemPrompt: string;
|
|
47
|
-
input: string;
|
|
48
|
-
messages: AgentContextMessage[];
|
|
49
|
-
skills: AgentContextSkill[];
|
|
50
|
-
createdAt: string;
|
|
51
|
-
updatedAt: string;
|
|
52
|
-
title?: string;
|
|
53
|
-
};
|
|
54
|
-
/** Unified phase output — model decides routing via route. */
|
|
55
|
-
type PhaseOutput = {
|
|
56
|
-
message: string;
|
|
57
|
-
/** Route to next phase, or "continue" to re-execute current phase, or "stop" to end */
|
|
58
|
-
route: string;
|
|
59
|
-
/** Tool calls from the model invocation (used by framework for route extraction) */
|
|
60
|
-
toolCalls?: Array<{
|
|
61
|
-
id: string;
|
|
62
|
-
name: string;
|
|
63
|
-
args: unknown;
|
|
64
|
-
}>;
|
|
65
|
-
/** Route reason extracted from route tool call (for hooks to inspect) */
|
|
66
|
-
routeReason?: string;
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
type LoopPhase = "chat" | "plan" | "execute" | "verify";
|
|
70
|
-
|
|
71
|
-
type ExecutionTurnEntry = {
|
|
72
|
-
kind: "prompt";
|
|
73
|
-
message: Pick<AgentContextMessage, "role" | "content">;
|
|
74
|
-
} | {
|
|
75
|
-
kind: "assistant_text";
|
|
76
|
-
text: string;
|
|
77
|
-
} | {
|
|
78
|
-
kind: "tool_call";
|
|
79
|
-
toolCall: ToolCall;
|
|
80
|
-
} | {
|
|
81
|
-
kind: "tool_result";
|
|
82
|
-
result: ToolResult;
|
|
83
|
-
};
|
|
84
|
-
type ExecutionTurn = {
|
|
85
|
-
id: string;
|
|
86
|
-
sessionId: string;
|
|
87
|
-
parentSessionId?: string;
|
|
88
|
-
phase: LoopPhase;
|
|
89
|
-
requestedAtMs: number;
|
|
90
|
-
completedAtMs: number;
|
|
57
|
+
type AgentConfig = {
|
|
58
|
+
context: AgentContext;
|
|
59
|
+
sessionId?: string;
|
|
91
60
|
model: LlmModelRef;
|
|
92
|
-
|
|
93
|
-
|
|
61
|
+
stream: StreamFn;
|
|
62
|
+
signal?: AbortSignal;
|
|
63
|
+
emit?: AgentEventListener;
|
|
64
|
+
phases?: PhaseRegistry;
|
|
65
|
+
runtime?: AgentRuntimePort;
|
|
66
|
+
beforeToolCall?: BeforeToolCall;
|
|
67
|
+
afterToolCall?: AfterToolCall;
|
|
68
|
+
beforePhase?: BeforePhaseHook;
|
|
69
|
+
afterPhase?: AfterPhaseHook;
|
|
70
|
+
beforePrompt?: BeforePromptHook;
|
|
71
|
+
maxAttempts?: number;
|
|
72
|
+
onModelTranscript?: (transcript: ModelTranscript, meta: {
|
|
73
|
+
phase: string;
|
|
74
|
+
model: LlmModelRef;
|
|
75
|
+
}) => Promise<void>;
|
|
76
|
+
onMessage?: (message: AgentMessage) => Promise<void>;
|
|
77
|
+
onOutcome?: (outcome: Outcome) => Promise<void>;
|
|
78
|
+
sessionState?: SessionState;
|
|
79
|
+
};
|
|
80
|
+
type ToolRunnerInput = {
|
|
81
|
+
config: AgentConfig;
|
|
82
|
+
toolCall: ToolCall;
|
|
94
83
|
};
|
|
95
|
-
type
|
|
96
|
-
|
|
97
|
-
|
|
84
|
+
type ToolRunner = (input: ToolRunnerInput) => Promise<ToolResult>;
|
|
85
|
+
type AgentRuntimePort = {
|
|
86
|
+
tools?: ToolRunner;
|
|
98
87
|
};
|
|
99
88
|
|
|
100
|
-
|
|
101
|
-
type AgentMessage$1 = AgentContextMessage;
|
|
102
|
-
type Skill$1 = AgentContextSkill;
|
|
103
|
-
type AgentState = {
|
|
104
|
-
version: string;
|
|
105
|
-
id: string;
|
|
106
|
-
parentSessionId?: string;
|
|
107
|
-
systemPrompt: string;
|
|
108
|
-
input: string;
|
|
109
|
-
messages: AgentMessage$1[];
|
|
110
|
-
skills: Skill$1[];
|
|
111
|
-
createdAt: string;
|
|
112
|
-
updatedAt: string;
|
|
113
|
-
title?: string;
|
|
114
|
-
};
|
|
115
|
-
type CreateAgentStateInput = {
|
|
116
|
-
id?: string;
|
|
117
|
-
systemPrompt: string;
|
|
118
|
-
input: string;
|
|
119
|
-
skills?: Skill$1[];
|
|
120
|
-
parentSessionId?: string;
|
|
121
|
-
title?: string;
|
|
122
|
-
messages?: AgentMessage$1[];
|
|
123
|
-
};
|
|
124
|
-
type ToolContext$1 = {
|
|
125
|
-
state: AgentState;
|
|
89
|
+
type ToolContext = Pick<AgentContext, "skills"> & {
|
|
126
90
|
toolCallId: string;
|
|
127
91
|
};
|
|
128
|
-
type ToolExecutionMode
|
|
129
|
-
type Tool
|
|
92
|
+
type ToolExecutionMode = "sequential" | "parallel";
|
|
93
|
+
type Tool<TArgs = unknown> = {
|
|
130
94
|
name: string;
|
|
131
95
|
description: string;
|
|
132
96
|
parameters: Type.TSchema;
|
|
@@ -135,22 +99,22 @@ type Tool$1<TArgs = unknown> = {
|
|
|
135
99
|
/** Additional guidelines appended to the system prompt when this tool is active. */
|
|
136
100
|
promptGuidelines?: string[];
|
|
137
101
|
/** Whether this tool can run concurrently with others. Default: "parallel". */
|
|
138
|
-
executionMode?: ToolExecutionMode
|
|
139
|
-
execute(args: TArgs, context: ToolContext
|
|
102
|
+
executionMode?: ToolExecutionMode;
|
|
103
|
+
execute(args: TArgs, context: ToolContext, signal?: AbortSignal): Promise<ToolResult>;
|
|
140
104
|
};
|
|
141
105
|
/** Context snapshot passed into the low-level agent loop. */
|
|
142
106
|
type AgentContext = {
|
|
143
107
|
/** System prompt included with the request. */
|
|
144
108
|
systemPrompt: string;
|
|
145
109
|
/** Transcript visible to the model. */
|
|
146
|
-
messages: AgentMessage
|
|
110
|
+
messages: AgentMessage[];
|
|
147
111
|
/** Tools available for this run. */
|
|
148
|
-
tools
|
|
112
|
+
tools: Tool[];
|
|
149
113
|
/** Skills available for this run. */
|
|
150
|
-
skills
|
|
114
|
+
skills: Skill$1[];
|
|
151
115
|
};
|
|
152
116
|
type BeforeToolCall = (input: {
|
|
153
|
-
tool: Tool
|
|
117
|
+
tool: Tool;
|
|
154
118
|
args: unknown;
|
|
155
119
|
}) => Promise<{
|
|
156
120
|
allow: true;
|
|
@@ -159,188 +123,158 @@ type BeforeToolCall = (input: {
|
|
|
159
123
|
reason: string;
|
|
160
124
|
}>;
|
|
161
125
|
type AfterToolCall = (input: {
|
|
162
|
-
tool: Tool
|
|
126
|
+
tool: Tool;
|
|
163
127
|
result: ToolResult;
|
|
164
128
|
}) => Promise<ToolResult>;
|
|
165
129
|
type RunResult = {
|
|
166
130
|
sessionId: string;
|
|
167
|
-
messages: AgentMessage
|
|
131
|
+
messages: AgentMessage[];
|
|
168
132
|
outcome: Outcome;
|
|
169
133
|
metrics: LoopMetrics;
|
|
170
134
|
};
|
|
171
135
|
type Unsubscribe = () => void;
|
|
172
|
-
declare function createMessage(role: AgentMessage
|
|
173
|
-
declare function
|
|
136
|
+
declare function createMessage(role: AgentMessage["role"], content: AgentMessage["content"], metadata?: Record<string, unknown>): AgentMessage;
|
|
137
|
+
declare function messageContentText(content: AgentMessage["content"]): string;
|
|
174
138
|
|
|
175
|
-
declare function createId(prefix: string): string;
|
|
176
|
-
declare function createTimestamp(date?: Date): string;
|
|
177
|
-
declare const createJson: {
|
|
178
|
-
"new"<T>(value: T): T;
|
|
179
|
-
stringify(value: unknown): string;
|
|
180
|
-
};
|
|
181
|
-
|
|
182
|
-
/** Unified phase input — contains everything the model needs. */
|
|
183
|
-
type PhaseInput = {
|
|
184
|
-
phase: string;
|
|
185
|
-
systemPrompt: string;
|
|
186
|
-
messages: AgentMessage$1[];
|
|
187
|
-
/** All tools (for systemPrompt display, cache-friendly) */
|
|
188
|
-
tools: Tool$1[];
|
|
189
|
-
/** All skills (for systemPrompt display) */
|
|
190
|
-
skills: Skill$1[];
|
|
191
|
-
/** Phase-specific filtered tools (for LlmRequest.tools) */
|
|
192
|
-
phaseTools?: Tool$1[];
|
|
193
|
-
/** Phase-specific filtered skills */
|
|
194
|
-
phaseSkills?: Skill$1[];
|
|
195
|
-
/** Additional guideline bullets appended to the system prompt. */
|
|
196
|
-
promptGuidelines?: string[];
|
|
197
|
-
/** Text to append after the system prompt. */
|
|
198
|
-
appendSystemPrompt?: string;
|
|
199
|
-
/** Tool choice configuration from phase definition */
|
|
200
|
-
toolChoice?: LlmToolChoice;
|
|
201
|
-
};
|
|
202
|
-
type PhaseManifest = {
|
|
203
|
-
id: string;
|
|
204
|
-
name: string;
|
|
205
|
-
description: string;
|
|
206
|
-
/** Tools available in this phase. If omitted, all tools are available. */
|
|
207
|
-
tools?: string[];
|
|
208
|
-
/** Skills available in this phase. If omitted, all skills are available. */
|
|
209
|
-
skills?: string[];
|
|
210
|
-
};
|
|
211
|
-
type PhaseRun = (context: PhaseContext, input: PhaseInput) => Promise<PhaseOutput | void>;
|
|
212
|
-
type PhaseDefinition = PhaseManifest & {
|
|
213
|
-
run?: PhaseRun;
|
|
214
|
-
buildPrompt?(input: PhaseInput): LlmRequest;
|
|
215
|
-
};
|
|
216
139
|
type ModelInvokeOutput = {
|
|
217
140
|
text: string;
|
|
218
141
|
contentBlocks: ContentBlock[];
|
|
219
142
|
toolCalls: ToolCall[];
|
|
220
143
|
stopReason?: string;
|
|
221
144
|
};
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
};
|
|
231
|
-
/** Message lifecycle manager for streaming updates */
|
|
232
|
-
/** Snapshot of message state, used for restore */
|
|
233
|
-
type MessageSnapshot = {
|
|
234
|
-
transcriptLength: number;
|
|
235
|
-
stateMessagesLength: number;
|
|
236
|
-
};
|
|
237
|
-
type PhaseMessageManager = {
|
|
238
|
-
/** Get all visible messages in the transcript */
|
|
239
|
-
visible(): AgentMessage$1[];
|
|
240
|
-
/** Start a new message stream, returns message id */
|
|
241
|
-
start(role: "assistant" | "tool", content: string, metadata?: Record<string, unknown>): string;
|
|
242
|
-
/** Stream a text delta */
|
|
243
|
-
update(messageId: string, delta: string): Promise<void>;
|
|
244
|
-
/** End the message stream, appends to transcript */
|
|
245
|
-
end(messageId: string): Promise<void>;
|
|
246
|
-
/** Delete a single message by id or index */
|
|
247
|
-
delete(target: string | number): void;
|
|
248
|
-
/** Insert a message before a target (by id or index) */
|
|
249
|
-
insert(target: string | number, message: AgentMessage$1): void;
|
|
250
|
-
/** Clear all messages from transcript and state */
|
|
251
|
-
clear(): void;
|
|
252
|
-
/** Capture current message state for later restore */
|
|
253
|
-
snapshot(): MessageSnapshot;
|
|
254
|
-
/** Restore message state to a previous snapshot, discarding messages added after it */
|
|
255
|
-
restore(snap: MessageSnapshot): void;
|
|
145
|
+
/** Snapshot of phase-level context for restore */
|
|
146
|
+
type PhaseContextSnapshot = {
|
|
147
|
+
systemPrompt: string;
|
|
148
|
+
messages: AgentMessage[];
|
|
149
|
+
currentPhase: string;
|
|
150
|
+
availablePhases: string[];
|
|
151
|
+
turnNumber: number;
|
|
152
|
+
payload?: unknown;
|
|
256
153
|
};
|
|
257
|
-
/**
|
|
258
|
-
type
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
/** End tool execution */
|
|
264
|
-
end(toolCallId: string, toolName: string, result: ToolResult, isError: boolean): Promise<void>;
|
|
154
|
+
/** Execution capabilities for a phase — operates on PhaseContext. */
|
|
155
|
+
type PhaseExecution = {
|
|
156
|
+
snapshot(): PhaseContextSnapshot;
|
|
157
|
+
restore(snapshot: PhaseContextSnapshot): void;
|
|
158
|
+
invokeModel(context: PhaseContext): Promise<ModelInvokeOutput>;
|
|
159
|
+
executeTool(context: AgentContext, toolCall: ToolCall): Promise<ToolResult>;
|
|
265
160
|
};
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
toolCall: ToolCall;
|
|
277
|
-
}): Promise<ToolResult>;
|
|
278
|
-
};
|
|
279
|
-
skills: AgentState["skills"];
|
|
280
|
-
turn<T>(fn: () => Promise<T>): Promise<T>;
|
|
281
|
-
maxAttempts?: number;
|
|
282
|
-
incrementAttempt(): void;
|
|
283
|
-
availablePhases: Array<{
|
|
161
|
+
|
|
162
|
+
/** Unified phase output — model decides routing via route. */
|
|
163
|
+
type PhaseOutput = {
|
|
164
|
+
message: string;
|
|
165
|
+
/** Route to next phase, or "continue" to re-execute current phase, or "stop" to end */
|
|
166
|
+
route: string;
|
|
167
|
+
/** Phase name that produced this output */
|
|
168
|
+
phase?: string;
|
|
169
|
+
/** Tool calls from the model invocation (used by framework for route extraction) */
|
|
170
|
+
toolCalls?: Array<{
|
|
284
171
|
id: string;
|
|
285
172
|
name: string;
|
|
286
|
-
|
|
173
|
+
args: unknown;
|
|
287
174
|
}>;
|
|
288
|
-
/**
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
} | undefined;
|
|
293
|
-
};
|
|
294
|
-
type PhaseRegistry = {
|
|
295
|
-
entryPhaseId: string;
|
|
296
|
-
phases: PhaseDefinition[];
|
|
297
|
-
};
|
|
298
|
-
type PhaseRegistryInput = {
|
|
299
|
-
entryPhaseId?: string;
|
|
300
|
-
phases?: PhaseDefinition[];
|
|
175
|
+
/** Route reason extracted from route tool call (for hooks to inspect) */
|
|
176
|
+
routeReason?: string;
|
|
177
|
+
/** Structured data from this phase, passed to the next phase */
|
|
178
|
+
payload?: unknown;
|
|
301
179
|
};
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
180
|
+
/** Phase machine state — tracks position and inter-phase data */
|
|
181
|
+
interface PhaseState {
|
|
182
|
+
current: string;
|
|
183
|
+
available: string[];
|
|
184
|
+
iterations: number;
|
|
185
|
+
payload?: unknown;
|
|
186
|
+
}
|
|
187
|
+
/** Everything a phase needs to execute */
|
|
188
|
+
interface PhaseContext {
|
|
189
|
+
systemPrompt: string;
|
|
190
|
+
messages: AgentMessage[];
|
|
191
|
+
/** Phase-filtered tools */
|
|
192
|
+
tools: Tool[];
|
|
193
|
+
/** Phase-filtered skills */
|
|
194
|
+
skills: Skill$1[];
|
|
195
|
+
/** Phase machine state */
|
|
196
|
+
state: PhaseState;
|
|
197
|
+
/** Additional guideline bullets appended to the system prompt */
|
|
198
|
+
promptGuidelines?: string[];
|
|
199
|
+
/** Text to append after the system prompt */
|
|
200
|
+
appendSystemPrompt?: string;
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Loaded Phase object
|
|
204
|
+
*/
|
|
205
|
+
interface Phase {
|
|
206
|
+
/** Unique identifier */
|
|
207
|
+
id: string;
|
|
208
|
+
/** Display name */
|
|
209
|
+
name: string;
|
|
210
|
+
/** Description */
|
|
211
|
+
description: string;
|
|
212
|
+
/** Restricted tools (undefined = all tools available) */
|
|
213
|
+
tools?: string[];
|
|
214
|
+
/** Restricted skills (undefined = all skills available) */
|
|
215
|
+
skills?: string[];
|
|
216
|
+
/** Forced next phase */
|
|
217
|
+
target?: string;
|
|
218
|
+
/** Expected input fields (key → description) */
|
|
219
|
+
input?: Record<string, string>;
|
|
220
|
+
/** If true, phase gets a fresh context when executed in parallel */
|
|
221
|
+
isolated?: boolean;
|
|
222
|
+
/** Path to PHASE.md file */
|
|
223
|
+
filePath: string;
|
|
224
|
+
/** Phase directory path */
|
|
225
|
+
baseDir: string;
|
|
226
|
+
/** PHASE.md body content */
|
|
227
|
+
content: string;
|
|
228
|
+
/** Model override for this phase (resolved from frontmatter) */
|
|
229
|
+
model?: LlmModelRef;
|
|
230
|
+
/** ExtensionAPI factory function (default export pattern) */
|
|
231
|
+
factory?: (api: ExtensionAPI) => Promise<void>;
|
|
232
|
+
/** Legacy run function */
|
|
233
|
+
run?: (context: PhaseContext, execution: PhaseExecution) => Promise<PhaseOutput | void>;
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Phase registry containing all loaded phases
|
|
237
|
+
*/
|
|
238
|
+
interface PhaseRegistry {
|
|
239
|
+
/** Map of phase id to Phase object */
|
|
240
|
+
phases: Map<string, Phase>;
|
|
241
|
+
/** Entry phase id (null if no phases defined) */
|
|
242
|
+
entryPhaseId: string | null;
|
|
243
|
+
}
|
|
305
244
|
|
|
306
245
|
/**
|
|
307
|
-
*
|
|
246
|
+
* Extension types — simplified for the new hook-based system.
|
|
308
247
|
*/
|
|
248
|
+
|
|
309
249
|
interface SourceInfo {
|
|
310
|
-
/** Source type: "local" for filesystem, "builtin" for built-in, etc. */
|
|
311
250
|
source: string;
|
|
312
|
-
/** Base directory for resolving relative paths. */
|
|
313
251
|
baseDir?: string;
|
|
314
|
-
/** Display name for error messages. */
|
|
315
252
|
displayName?: string;
|
|
316
253
|
}
|
|
317
254
|
declare function createSourceInfo(extensionPath: string, options?: {
|
|
318
255
|
source?: string;
|
|
319
256
|
baseDir?: string;
|
|
320
257
|
}): SourceInfo;
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
258
|
+
/** Phase run function type for extensions */
|
|
259
|
+
type PhaseRun = (context: PhaseContext, execution: PhaseExecution) => Promise<PhaseOutput | void>;
|
|
260
|
+
/** Phase definition shape used by extensions */
|
|
261
|
+
type PhaseDefinition = {
|
|
262
|
+
id: string;
|
|
263
|
+
name: string;
|
|
264
|
+
description: string;
|
|
265
|
+
run?: PhaseRun;
|
|
266
|
+
tools?: string[];
|
|
267
|
+
skills?: string[];
|
|
268
|
+
target?: string;
|
|
269
|
+
input?: Record<string, string>;
|
|
270
|
+
model?: string;
|
|
330
271
|
};
|
|
331
|
-
type PhaseRegistration = Partial<
|
|
272
|
+
type PhaseRegistration = Partial<Omit<PhaseDefinition, 'run'>> & {
|
|
332
273
|
/** Optional execution override — takes over model invocation */
|
|
333
274
|
run?: PhaseRun;
|
|
334
|
-
/** Declarative prompt config — framework generates buildPrompt from this */
|
|
335
|
-
prompt?: PhasePromptConfig;
|
|
336
|
-
/** Custom prompt builder — overrides prompt config if provided */
|
|
337
|
-
buildPrompt?: (input: PhaseInput) => LlmRequest;
|
|
338
275
|
};
|
|
339
276
|
type RegisteredPhase = {
|
|
340
277
|
definition: PhaseDefinition;
|
|
341
|
-
handler: {
|
|
342
|
-
buildPrompt?: (input: PhaseInput) => LlmRequest;
|
|
343
|
-
};
|
|
344
278
|
source: {
|
|
345
279
|
extensionPath: string;
|
|
346
280
|
};
|
|
@@ -348,7 +282,13 @@ type RegisteredPhase = {
|
|
|
348
282
|
type ExtensionPackageManifest = {
|
|
349
283
|
rowan?: {
|
|
350
284
|
extensions?: string[];
|
|
351
|
-
phase?:
|
|
285
|
+
phase?: {
|
|
286
|
+
id?: string;
|
|
287
|
+
name?: string;
|
|
288
|
+
description?: string;
|
|
289
|
+
tools?: string[];
|
|
290
|
+
skills?: string[];
|
|
291
|
+
};
|
|
352
292
|
};
|
|
353
293
|
};
|
|
354
294
|
/**
|
|
@@ -434,11 +374,11 @@ type BeforePhaseHookResult = {
|
|
|
434
374
|
route: string;
|
|
435
375
|
message: string;
|
|
436
376
|
};
|
|
437
|
-
input?:
|
|
377
|
+
input?: PhaseContext;
|
|
438
378
|
};
|
|
439
379
|
type AfterPhaseHookResult = {
|
|
440
380
|
abort?: Outcome;
|
|
441
|
-
retry?:
|
|
381
|
+
retry?: PhaseContext;
|
|
442
382
|
output?: PhaseOutput;
|
|
443
383
|
};
|
|
444
384
|
type HandlerFn = (...args: unknown[]) => Promise<unknown>;
|
|
@@ -521,7 +461,7 @@ interface LoadedExtension {
|
|
|
521
461
|
path: string;
|
|
522
462
|
resolvedPath: string;
|
|
523
463
|
name: string;
|
|
524
|
-
factory:
|
|
464
|
+
factory: ExtensionFactory;
|
|
525
465
|
manifest?: ExtensionManifest;
|
|
526
466
|
}
|
|
527
467
|
/** Extension manifest from package.json `rowan` field. */
|
|
@@ -656,7 +596,7 @@ interface BeforePhaseEvent {
|
|
|
656
596
|
/** Phase ID about to execute */
|
|
657
597
|
phaseId: string;
|
|
658
598
|
/** Phase input */
|
|
659
|
-
input:
|
|
599
|
+
input: PhaseContext;
|
|
660
600
|
}
|
|
661
601
|
/**
|
|
662
602
|
* after_phase event - triggered after phase execution
|
|
@@ -682,7 +622,7 @@ interface BeforePromptEvent {
|
|
|
682
622
|
/** Current phase ID */
|
|
683
623
|
phaseId: string;
|
|
684
624
|
/** Phase input (modifiable) */
|
|
685
|
-
input:
|
|
625
|
+
input: PhaseContext;
|
|
686
626
|
}
|
|
687
627
|
/**
|
|
688
628
|
* before_tool_call event - triggered before tool execution
|
|
@@ -693,7 +633,7 @@ interface BeforePromptEvent {
|
|
|
693
633
|
interface BeforeToolCallEvent {
|
|
694
634
|
type: "before_tool_call";
|
|
695
635
|
/** Tool definition */
|
|
696
|
-
tool: Tool
|
|
636
|
+
tool: Tool;
|
|
697
637
|
/** Tool arguments */
|
|
698
638
|
args: unknown;
|
|
699
639
|
}
|
|
@@ -705,7 +645,7 @@ interface BeforeToolCallEvent {
|
|
|
705
645
|
interface AfterToolCallEvent {
|
|
706
646
|
type: "after_tool_call";
|
|
707
647
|
/** Tool definition */
|
|
708
|
-
tool: Tool
|
|
648
|
+
tool: Tool;
|
|
709
649
|
/** Tool execution result */
|
|
710
650
|
result: ToolResult;
|
|
711
651
|
}
|
|
@@ -727,7 +667,7 @@ interface AgentEndEvent {
|
|
|
727
667
|
/** Execution outcome */
|
|
728
668
|
outcome: Outcome;
|
|
729
669
|
/** All messages */
|
|
730
|
-
messages: AgentMessage
|
|
670
|
+
messages: AgentMessage[];
|
|
731
671
|
}
|
|
732
672
|
/**
|
|
733
673
|
* turn_start event - triggered when conversation turn starts
|
|
@@ -735,7 +675,7 @@ interface AgentEndEvent {
|
|
|
735
675
|
interface TurnStartEvent {
|
|
736
676
|
type: "turn_start";
|
|
737
677
|
/** Current message list */
|
|
738
|
-
messages: AgentMessage
|
|
678
|
+
messages: AgentMessage[];
|
|
739
679
|
}
|
|
740
680
|
/**
|
|
741
681
|
* turn_end event - triggered when conversation turn ends
|
|
@@ -743,7 +683,7 @@ interface TurnStartEvent {
|
|
|
743
683
|
interface TurnEndEvent {
|
|
744
684
|
type: "turn_end";
|
|
745
685
|
/** Message list */
|
|
746
|
-
messages: AgentMessage
|
|
686
|
+
messages: AgentMessage[];
|
|
747
687
|
/** Turn outcome (optional) */
|
|
748
688
|
outcome?: Outcome;
|
|
749
689
|
}
|
|
@@ -753,7 +693,7 @@ interface TurnEndEvent {
|
|
|
753
693
|
interface MessageStartEvent {
|
|
754
694
|
type: "message_start";
|
|
755
695
|
/** Message object */
|
|
756
|
-
message: AgentMessage
|
|
696
|
+
message: AgentMessage;
|
|
757
697
|
}
|
|
758
698
|
/**
|
|
759
699
|
* message_update event - triggered on message streaming update
|
|
@@ -761,7 +701,7 @@ interface MessageStartEvent {
|
|
|
761
701
|
interface MessageUpdateEvent {
|
|
762
702
|
type: "message_update";
|
|
763
703
|
/** Message object */
|
|
764
|
-
message: AgentMessage
|
|
704
|
+
message: AgentMessage;
|
|
765
705
|
/** Delta text */
|
|
766
706
|
delta: string;
|
|
767
707
|
}
|
|
@@ -771,7 +711,7 @@ interface MessageUpdateEvent {
|
|
|
771
711
|
interface MessageEndEvent {
|
|
772
712
|
type: "message_end";
|
|
773
713
|
/** Message object */
|
|
774
|
-
message: AgentMessage
|
|
714
|
+
message: AgentMessage;
|
|
775
715
|
}
|
|
776
716
|
/**
|
|
777
717
|
* tool_execution_start event - triggered when tool execution starts
|
|
@@ -855,7 +795,7 @@ interface BeforePhaseResult {
|
|
|
855
795
|
message: string;
|
|
856
796
|
};
|
|
857
797
|
/** Replace phase input */
|
|
858
|
-
input?:
|
|
798
|
+
input?: PhaseContext;
|
|
859
799
|
}
|
|
860
800
|
/**
|
|
861
801
|
* after_phase hook return value
|
|
@@ -868,7 +808,7 @@ interface AfterPhaseResult {
|
|
|
868
808
|
/** Abort agent */
|
|
869
809
|
abort?: Outcome;
|
|
870
810
|
/** Re-execute phase */
|
|
871
|
-
retry?:
|
|
811
|
+
retry?: PhaseContext;
|
|
872
812
|
/** Replace phase output */
|
|
873
813
|
output?: PhaseOutput;
|
|
874
814
|
}
|
|
@@ -879,7 +819,7 @@ interface AfterPhaseResult {
|
|
|
879
819
|
*/
|
|
880
820
|
interface BeforePromptResult {
|
|
881
821
|
/** Replace phase input */
|
|
882
|
-
input?:
|
|
822
|
+
input?: PhaseContext;
|
|
883
823
|
}
|
|
884
824
|
/**
|
|
885
825
|
* before_tool_call hook return value
|
|
@@ -1008,16 +948,6 @@ declare class HooksManager {
|
|
|
1008
948
|
emit<K extends HookEventType>(eventType: K, event: Extract<HookEvent, {
|
|
1009
949
|
type: K;
|
|
1010
950
|
}>): Promise<void>;
|
|
1011
|
-
/**
|
|
1012
|
-
* Emit event and collect all non-undefined results.
|
|
1013
|
-
*
|
|
1014
|
-
* @param eventType - Event type
|
|
1015
|
-
* @param event - Event object
|
|
1016
|
-
* @returns Array of non-undefined results
|
|
1017
|
-
*/
|
|
1018
|
-
emitCollect<K extends HookEventType>(eventType: K, event: Extract<HookEvent, {
|
|
1019
|
-
type: K;
|
|
1020
|
-
}>): Promise<Array<NonNullable<HookResultMap[K]>>>;
|
|
1021
951
|
/**
|
|
1022
952
|
* Emit event and return first non-undefined result (short-circuit).
|
|
1023
953
|
*
|
|
@@ -1028,18 +958,6 @@ declare class HooksManager {
|
|
|
1028
958
|
emitFirst<K extends HookEventType>(eventType: K, event: Extract<HookEvent, {
|
|
1029
959
|
type: K;
|
|
1030
960
|
}>): Promise<HookResultMap[K] | undefined>;
|
|
1031
|
-
/**
|
|
1032
|
-
* Emit event and aggregate results with reducer.
|
|
1033
|
-
*
|
|
1034
|
-
* @param eventType - Event type
|
|
1035
|
-
* @param event - Event object
|
|
1036
|
-
* @param reducer - Aggregation function
|
|
1037
|
-
* @param initial - Initial value
|
|
1038
|
-
* @returns Aggregated result
|
|
1039
|
-
*/
|
|
1040
|
-
emitReduce<K extends HookEventType, T>(eventType: K, event: Extract<HookEvent, {
|
|
1041
|
-
type: K;
|
|
1042
|
-
}>, reducer: (acc: T, result: NonNullable<HookResultMap[K]>) => T, initial: T): Promise<T>;
|
|
1043
961
|
}
|
|
1044
962
|
/**
|
|
1045
963
|
* Get global hooks manager instance (singleton).
|
|
@@ -1053,227 +971,11 @@ declare function resetGlobalHooks(): void;
|
|
|
1053
971
|
/**
|
|
1054
972
|
* @module extensions/context
|
|
1055
973
|
*
|
|
1056
|
-
*
|
|
1057
|
-
*
|
|
1058
|
-
* ## Quick Start
|
|
1059
|
-
*
|
|
1060
|
-
* ```typescript
|
|
1061
|
-
* import type { ExtensionAPI } from "@rowan-agent/agent";
|
|
1062
|
-
*
|
|
1063
|
-
* export default function(api: ExtensionAPI) {
|
|
1064
|
-
* // 1. Subscribe to hooks
|
|
1065
|
-
* api.on("before_tool_call", (event) => {
|
|
1066
|
-
* console.log(`Tool: ${event.tool.name}`);
|
|
1067
|
-
* return { allow: true };
|
|
1068
|
-
* });
|
|
1069
|
-
*
|
|
1070
|
-
* // 2. Register custom tool
|
|
1071
|
-
* api.registerTool({
|
|
1072
|
-
* name: "search_docs",
|
|
1073
|
-
* description: "Search documentation",
|
|
1074
|
-
* parameters: { type: "object", properties: { query: { type: "string" } } },
|
|
1075
|
-
* execute: async (args) => {
|
|
1076
|
-
* return { content: [{ type: "text", text: "result" }] };
|
|
1077
|
-
* },
|
|
1078
|
-
* });
|
|
1079
|
-
*
|
|
1080
|
-
* // 3. Register custom phase
|
|
1081
|
-
* api.registerPhase({
|
|
1082
|
-
* ...api.manifest?.phase, // Read metadata from package.json
|
|
1083
|
-
* id: "my-phase",
|
|
1084
|
-
* run: async (context, input) => {
|
|
1085
|
-
* return { message: "Done", route: "stop" };
|
|
1086
|
-
* },
|
|
1087
|
-
* });
|
|
1088
|
-
*
|
|
1089
|
-
* // 4. Register model provider
|
|
1090
|
-
* api.registerProvider({
|
|
1091
|
-
* name: "custom",
|
|
1092
|
-
* baseUrl: "https://api.example.com",
|
|
1093
|
-
* api: "openai-completions",
|
|
1094
|
-
* models: [...],
|
|
1095
|
-
* });
|
|
974
|
+
* Extension context types — runtime state and phase execution context.
|
|
1096
975
|
*
|
|
1097
|
-
*
|
|
1098
|
-
* api.events.on("other-plugin:ready", (data) => {
|
|
1099
|
-
* console.log("Plugin ready:", data);
|
|
1100
|
-
* });
|
|
1101
|
-
* }
|
|
1102
|
-
* ```
|
|
1103
|
-
*
|
|
1104
|
-
* ## Available Hooks
|
|
1105
|
-
*
|
|
1106
|
-
* | Hook | Trigger | Return |
|
|
1107
|
-
* |------|---------|--------|
|
|
1108
|
-
* | `before_phase` | Before phase execution | `{ abort?, skip?, input? }` |
|
|
1109
|
-
* | `after_phase` | After phase execution | `{ abort?, retry?, output? }` |
|
|
1110
|
-
* | `before_prompt` | Before building LLM request | `{ input? }` |
|
|
1111
|
-
* | `before_tool_call` | Before tool execution | `{ allow, reason? }` |
|
|
1112
|
-
* | `after_tool_call` | After tool execution | `{ result? }` |
|
|
1113
|
-
* | `agent_start` | Agent starts | Listen only |
|
|
1114
|
-
* | `agent_end` | Agent ends | Listen only |
|
|
1115
|
-
* | `message_*` | Message lifecycle | Listen only |
|
|
1116
|
-
* | `tool_execution_*` | Tool execution lifecycle | Listen only |
|
|
976
|
+
* For ExtensionAPI and createExtensionAPI, see ./api.ts
|
|
1117
977
|
*/
|
|
1118
978
|
|
|
1119
|
-
/**
|
|
1120
|
-
* Extension API object passed to extension factory function.
|
|
1121
|
-
*
|
|
1122
|
-
* @example
|
|
1123
|
-
* ```typescript
|
|
1124
|
-
* export default function(api: ExtensionAPI) {
|
|
1125
|
-
* // api provides all extension APIs
|
|
1126
|
-
* }
|
|
1127
|
-
* ```
|
|
1128
|
-
*/
|
|
1129
|
-
interface ExtensionAPI {
|
|
1130
|
-
/**
|
|
1131
|
-
* Subscribe to a hook event.
|
|
1132
|
-
*
|
|
1133
|
-
* @param eventType - Hook type, e.g. "before_tool_call"
|
|
1134
|
-
* @param handler - Hook handler, can return result to modify behavior
|
|
1135
|
-
*
|
|
1136
|
-
* @example
|
|
1137
|
-
* ```typescript
|
|
1138
|
-
* ctx.on("before_tool_call", (event) => {
|
|
1139
|
-
* // event contains { tool, args }
|
|
1140
|
-
* if (event.tool.name === "bash") {
|
|
1141
|
-
* return { allow: false, reason: "Blocked" };
|
|
1142
|
-
* }
|
|
1143
|
-
* return { allow: true };
|
|
1144
|
-
* });
|
|
1145
|
-
* ```
|
|
1146
|
-
*/
|
|
1147
|
-
on<K extends HookEventType>(eventType: K, handler: HookHandler<K>): void;
|
|
1148
|
-
/**
|
|
1149
|
-
* Unsubscribe from a hook event.
|
|
1150
|
-
*/
|
|
1151
|
-
off<K extends HookEventType>(eventType: K, handler: HookHandler<K>): void;
|
|
1152
|
-
/**
|
|
1153
|
-
* Register a custom LLM-callable tool.
|
|
1154
|
-
*
|
|
1155
|
-
* @param tool - Tool definition with name, description, parameters, and execute function
|
|
1156
|
-
*
|
|
1157
|
-
* @example
|
|
1158
|
-
* ```typescript
|
|
1159
|
-
* api.registerTool({
|
|
1160
|
-
* name: "search_docs",
|
|
1161
|
-
* description: "Search project documentation",
|
|
1162
|
-
* parameters: {
|
|
1163
|
-
* type: "object",
|
|
1164
|
-
* properties: { query: { type: "string" } },
|
|
1165
|
-
* required: ["query"],
|
|
1166
|
-
* },
|
|
1167
|
-
* execute: async (args, signal) => {
|
|
1168
|
-
* const query = (args as any).query;
|
|
1169
|
-
* return { content: [{ type: "text", text: `Results for: ${query}` }] };
|
|
1170
|
-
* },
|
|
1171
|
-
* });
|
|
1172
|
-
* ```
|
|
1173
|
-
*/
|
|
1174
|
-
registerTool(tool: ToolDefinition): void;
|
|
1175
|
-
/**
|
|
1176
|
-
* Register a custom phase.
|
|
1177
|
-
*
|
|
1178
|
-
* Phases are state machine nodes that can be referenced by the routing system.
|
|
1179
|
-
*
|
|
1180
|
-
* @param registration - Phase registration info
|
|
1181
|
-
*
|
|
1182
|
-
* @example
|
|
1183
|
-
* ```typescript
|
|
1184
|
-
* ctx.registerPhase({
|
|
1185
|
-
* id: "review",
|
|
1186
|
-
* name: "Code Review",
|
|
1187
|
-
* description: "Review code changes",
|
|
1188
|
-
*
|
|
1189
|
-
* // Optional: declarative prompt config
|
|
1190
|
-
* prompt: {
|
|
1191
|
-
* instructions: [
|
|
1192
|
-
* "Phase: review",
|
|
1193
|
-
* "Review code changes, call route tool if looks good",
|
|
1194
|
-
* ],
|
|
1195
|
-
* },
|
|
1196
|
-
*
|
|
1197
|
-
* // Optional: custom execution logic
|
|
1198
|
-
* async run(context, input) {
|
|
1199
|
-
* const result = await context.model.invoke({ input });
|
|
1200
|
-
* return { message: result.text, route: "stop" };
|
|
1201
|
-
* },
|
|
1202
|
-
* });
|
|
1203
|
-
* ```
|
|
1204
|
-
*/
|
|
1205
|
-
registerPhase(registration: PhaseRegistration): void;
|
|
1206
|
-
/**
|
|
1207
|
-
* Register a model provider.
|
|
1208
|
-
*
|
|
1209
|
-
* @param config - Provider configuration
|
|
1210
|
-
*
|
|
1211
|
-
* @example
|
|
1212
|
-
* ```typescript
|
|
1213
|
-
* ctx.registerProvider({
|
|
1214
|
-
* name: "custom-llm",
|
|
1215
|
-
* baseUrl: "https://api.custom.com/v1",
|
|
1216
|
-
* api: "openai-completions",
|
|
1217
|
-
* models: [{
|
|
1218
|
-
* id: "custom-7b",
|
|
1219
|
-
* name: "Custom 7B",
|
|
1220
|
-
* api: "openai-completions",
|
|
1221
|
-
* reasoning: false,
|
|
1222
|
-
* input: ["text"],
|
|
1223
|
-
* cost: { input: 0.1, output: 0.2, cacheRead: 0, cacheWrite: 0 },
|
|
1224
|
-
* contextWindow: 8192,
|
|
1225
|
-
* maxTokens: 4096,
|
|
1226
|
-
* }],
|
|
1227
|
-
* });
|
|
1228
|
-
* ```
|
|
1229
|
-
*/
|
|
1230
|
-
registerProvider(config: ProviderConfig): void;
|
|
1231
|
-
/**
|
|
1232
|
-
* Unregister a model provider.
|
|
1233
|
-
*/
|
|
1234
|
-
unregisterProvider(name: string): void;
|
|
1235
|
-
/**
|
|
1236
|
-
* Extension manifest from package.json `rowan` field.
|
|
1237
|
-
*
|
|
1238
|
-
* Can be used to auto-fill phase metadata:
|
|
1239
|
-
* ```typescript
|
|
1240
|
-
* ctx.registerPhase({
|
|
1241
|
-
* ...ctx.manifest?.phase, // Auto-fill id, name, description
|
|
1242
|
-
* run: async (context, input) => { ... },
|
|
1243
|
-
* });
|
|
1244
|
-
* ```
|
|
1245
|
-
*/
|
|
1246
|
-
manifest?: ExtensionManifest;
|
|
1247
|
-
/**
|
|
1248
|
-
* Utility functions.
|
|
1249
|
-
*/
|
|
1250
|
-
utils: ExtensionUtils;
|
|
1251
|
-
/**
|
|
1252
|
-
* Runtime context — provides access to agent state, cwd, and utilities.
|
|
1253
|
-
*
|
|
1254
|
-
* Available after extension loading completes. Use for runtime operations
|
|
1255
|
-
* like executing shell commands or checking agent state.
|
|
1256
|
-
*/
|
|
1257
|
-
context: ExtensionContext;
|
|
1258
|
-
/**
|
|
1259
|
-
* Shared event bus for inter-extension communication.
|
|
1260
|
-
*
|
|
1261
|
-
* Extensions can emit and subscribe to arbitrary events to coordinate
|
|
1262
|
-
* without direct coupling.
|
|
1263
|
-
*
|
|
1264
|
-
* @example
|
|
1265
|
-
* ```typescript
|
|
1266
|
-
* // Extension A
|
|
1267
|
-
* api.events.on("my-plugin:ready", (data) => {
|
|
1268
|
-
* console.log("Plugin ready:", data);
|
|
1269
|
-
* });
|
|
1270
|
-
*
|
|
1271
|
-
* // Extension B
|
|
1272
|
-
* api.events.emit("my-plugin:ready", { version: "1.0" });
|
|
1273
|
-
* ```
|
|
1274
|
-
*/
|
|
1275
|
-
events: EventBus;
|
|
1276
|
-
}
|
|
1277
979
|
/**
|
|
1278
980
|
* Runtime context available to extensions during event handler execution.
|
|
1279
981
|
*
|
|
@@ -1281,9 +983,6 @@ interface ExtensionAPI {
|
|
|
1281
983
|
* Values are resolved lazily via getters, so changes via `runner.bind()` are
|
|
1282
984
|
* reflected immediately without recreating the context.
|
|
1283
985
|
*
|
|
1284
|
-
* This is distinct from ExtensionAPI (which is for registration) —
|
|
1285
|
-
* ExtensionContext gives runtime state during hook execution.
|
|
1286
|
-
*
|
|
1287
986
|
* @example
|
|
1288
987
|
* ```typescript
|
|
1289
988
|
* api.on("before_tool_call", (event, ctx) => {
|
|
@@ -1316,6 +1015,31 @@ interface ExtensionContext {
|
|
|
1316
1015
|
modelId?: string;
|
|
1317
1016
|
/** Get current system prompt */
|
|
1318
1017
|
getSystemPrompt?(): string;
|
|
1018
|
+
/** Set/override the system prompt */
|
|
1019
|
+
setSystemPrompt?(prompt: string): void;
|
|
1020
|
+
/** Get the full message history */
|
|
1021
|
+
getMessages?(): Array<{
|
|
1022
|
+
role: string;
|
|
1023
|
+
content: string;
|
|
1024
|
+
}>;
|
|
1025
|
+
/** Append a message to the history */
|
|
1026
|
+
addMessage?(role: "user" | "assistant" | "system", content: string): void;
|
|
1027
|
+
/** Get all available tools */
|
|
1028
|
+
getAvailableTools?(): Array<{
|
|
1029
|
+
name: string;
|
|
1030
|
+
description: string;
|
|
1031
|
+
}>;
|
|
1032
|
+
/** Get all available skills */
|
|
1033
|
+
getAvailableSkills?(): Array<{
|
|
1034
|
+
name: string;
|
|
1035
|
+
description: string;
|
|
1036
|
+
}>;
|
|
1037
|
+
/** Get skill content by name */
|
|
1038
|
+
getSkillContent?(skillName: string): string;
|
|
1039
|
+
/** Get all available phase IDs */
|
|
1040
|
+
getAvailablePhases?(): string[];
|
|
1041
|
+
/** Get phase content by ID */
|
|
1042
|
+
getPhaseContent?(phaseId: string): string;
|
|
1319
1043
|
}
|
|
1320
1044
|
/**
|
|
1321
1045
|
* Utility functions available to extensions.
|
|
@@ -1333,47 +1057,87 @@ interface ExtensionUtils {
|
|
|
1333
1057
|
* @returns JSON string
|
|
1334
1058
|
*/
|
|
1335
1059
|
formatJson(value: unknown): string;
|
|
1060
|
+
}
|
|
1061
|
+
|
|
1062
|
+
/**
|
|
1063
|
+
* Extension API object passed to extension factory function.
|
|
1064
|
+
*
|
|
1065
|
+
* @example
|
|
1066
|
+
* ```typescript
|
|
1067
|
+
* export default function(api: ExtensionAPI) {
|
|
1068
|
+
* // api provides all extension APIs
|
|
1069
|
+
* }
|
|
1070
|
+
* ```
|
|
1071
|
+
*/
|
|
1072
|
+
interface ExtensionAPI {
|
|
1336
1073
|
/**
|
|
1337
|
-
*
|
|
1338
|
-
* @param input - Phase input
|
|
1339
|
-
* @returns LLM request object
|
|
1340
|
-
*/
|
|
1341
|
-
buildModelRequest(input: PhaseInput): LlmRequest;
|
|
1342
|
-
/**
|
|
1343
|
-
* Create a prompt builder.
|
|
1344
|
-
* @param instructions - Instruction list
|
|
1345
|
-
* @returns Builder function
|
|
1346
|
-
*
|
|
1347
|
-
* @example
|
|
1348
|
-
* ```typescript
|
|
1349
|
-
* const builder = ctx.utils.createPromptBuilder([
|
|
1350
|
-
* "Phase: review",
|
|
1351
|
-
* "Review code changes",
|
|
1352
|
-
* ]);
|
|
1074
|
+
* Subscribe to a hook event.
|
|
1353
1075
|
*
|
|
1354
|
-
*
|
|
1355
|
-
*
|
|
1356
|
-
* id: "review",
|
|
1357
|
-
* buildPrompt: builder,
|
|
1358
|
-
* });
|
|
1359
|
-
* ```
|
|
1076
|
+
* @param eventType - Hook type, e.g. "before_tool_call"
|
|
1077
|
+
* @param handler - Hook handler, can return result to modify behavior
|
|
1360
1078
|
*/
|
|
1361
|
-
|
|
1079
|
+
on<K extends HookEventType>(eventType: K, handler: HookHandler<K>): void;
|
|
1080
|
+
/** Unsubscribe from a hook event. */
|
|
1081
|
+
off<K extends HookEventType>(eventType: K, handler: HookHandler<K>): void;
|
|
1082
|
+
/** Register a custom LLM-callable tool. */
|
|
1083
|
+
registerTool(tool: ToolDefinition): void;
|
|
1084
|
+
/** Register a custom phase. */
|
|
1085
|
+
registerPhase(registration: PhaseRegistration): void;
|
|
1086
|
+
/** Register a model provider. */
|
|
1087
|
+
registerProvider(config: _rowan_agent_models.ProviderConfig): void;
|
|
1088
|
+
/** Unregister a model provider. */
|
|
1089
|
+
unregisterProvider(name: string): void;
|
|
1090
|
+
/** Extension manifest from package.json `rowan` field. */
|
|
1091
|
+
manifest?: ExtensionManifest;
|
|
1092
|
+
/** Utility functions. */
|
|
1093
|
+
utils: ExtensionUtils;
|
|
1094
|
+
/** Runtime context — cwd, signal, exec, message access, etc. */
|
|
1095
|
+
context: ExtensionContext;
|
|
1096
|
+
/** Shared event bus for inter-extension communication. */
|
|
1097
|
+
events: EventBus;
|
|
1098
|
+
/** Session context — provides access to the session-level AgentContext. */
|
|
1099
|
+
session: {
|
|
1100
|
+
/** Get the current session AgentContext */
|
|
1101
|
+
getContext(): AgentContext;
|
|
1102
|
+
};
|
|
1103
|
+
/** Phase execution capabilities — rovides Phase In/Out, phase identity, and phase routing. */
|
|
1104
|
+
phase: {
|
|
1105
|
+
/** Phase In: get payload from previous phase */
|
|
1106
|
+
getPayload(): unknown;
|
|
1107
|
+
/** Phase Out: set payload for next phase */
|
|
1108
|
+
setPayload(payload: unknown): void;
|
|
1109
|
+
/** Phase Out: set outcome message */
|
|
1110
|
+
setMessage(message: string): void;
|
|
1111
|
+
/** Get current phase id */
|
|
1112
|
+
getCurrentPhase(): string;
|
|
1113
|
+
/** Set next phase (lower priority than PHASE.md target) */
|
|
1114
|
+
setNextPhase(phaseId: string): void;
|
|
1115
|
+
/** Get the next phase set by setNextPhase */
|
|
1116
|
+
getNextPhase(): string | undefined;
|
|
1117
|
+
/** Get the message set by setMessage */
|
|
1118
|
+
getMessage(): string | undefined;
|
|
1119
|
+
};
|
|
1362
1120
|
}
|
|
1363
1121
|
/**
|
|
1364
1122
|
* Extension factory function.
|
|
1365
1123
|
* Receives ExtensionAPI for registering hooks, phases, and providers.
|
|
1366
|
-
*
|
|
1367
|
-
* @param api - Extension API
|
|
1368
|
-
*
|
|
1369
|
-
* @example
|
|
1370
|
-
* ```typescript
|
|
1371
|
-
* const factory: ExtensionFactory = (api) => {
|
|
1372
|
-
* api.on("before_tool_call", handler);
|
|
1373
|
-
* };
|
|
1374
|
-
* ```
|
|
1375
1124
|
*/
|
|
1376
1125
|
type ExtensionFactory = (api: ExtensionAPI) => void | Promise<void>;
|
|
1126
|
+
/**
|
|
1127
|
+
* @internal
|
|
1128
|
+
* Create ExtensionAPI instance.
|
|
1129
|
+
* Works for both extension context (with hooks/runtime/eventBus) and phase context (without).
|
|
1130
|
+
*/
|
|
1131
|
+
declare function createExtensionAPI(hooks?: HooksManager, _extensionPath?: string, options?: {
|
|
1132
|
+
registerPhase?: (registration: PhaseRegistration) => void;
|
|
1133
|
+
registerProvider?: (config: _rowan_agent_models.ProviderConfig) => void;
|
|
1134
|
+
unregisterProvider?: (name: string) => void;
|
|
1135
|
+
registerTool?: (tool: ToolDefinition) => void;
|
|
1136
|
+
context?: ExtensionContext;
|
|
1137
|
+
manifest?: ExtensionManifest;
|
|
1138
|
+
phase?: PhaseContext;
|
|
1139
|
+
session?: AgentContext;
|
|
1140
|
+
}, runtime?: ExtensionRuntime, eventBus?: EventBus): ExtensionAPI;
|
|
1377
1141
|
|
|
1378
1142
|
/**
|
|
1379
1143
|
* Extension runner — manages extension loading and hook execution.
|
|
@@ -1387,8 +1151,7 @@ type ExtensionFactory = (api: ExtensionAPI) => void | Promise<void>;
|
|
|
1387
1151
|
*/
|
|
1388
1152
|
|
|
1389
1153
|
type ExtensionRunnerOptions = {
|
|
1390
|
-
entryPhaseId?: string;
|
|
1391
|
-
validatePhaseOverride?: (phaseId: string, extensionPath: string) => boolean;
|
|
1154
|
+
entryPhaseId?: string | null;
|
|
1392
1155
|
cwd?: string;
|
|
1393
1156
|
};
|
|
1394
1157
|
/**
|
|
@@ -1425,7 +1188,6 @@ declare class ExtensionRunner {
|
|
|
1425
1188
|
readonly hooks: HooksManager;
|
|
1426
1189
|
readonly runtime: ExtensionRuntime;
|
|
1427
1190
|
readonly events: EventBus;
|
|
1428
|
-
private readonly validatePhaseOverride?;
|
|
1429
1191
|
private readonly cwd;
|
|
1430
1192
|
private readonly abortController;
|
|
1431
1193
|
private _idle;
|
|
@@ -1436,6 +1198,8 @@ declare class ExtensionRunner {
|
|
|
1436
1198
|
private bound;
|
|
1437
1199
|
private readonly errorListeners;
|
|
1438
1200
|
private readonly loadedExtensions;
|
|
1201
|
+
/** Current agent context — set by the agent before each phase */
|
|
1202
|
+
currentContext?: AgentContext;
|
|
1439
1203
|
constructor(options?: ExtensionRunnerOptions);
|
|
1440
1204
|
/** Whether the agent is currently idle (not streaming). */
|
|
1441
1205
|
get isIdle(): boolean;
|
|
@@ -1509,12 +1273,13 @@ declare class ExtensionRunner {
|
|
|
1509
1273
|
* Get the number of handlers for specified event type.
|
|
1510
1274
|
*/
|
|
1511
1275
|
handlerCount(eventType: HookEventType): number;
|
|
1512
|
-
getPhase(id: string):
|
|
1513
|
-
getPhases():
|
|
1514
|
-
getPhaseHandler(id: string): RegisteredPhase["handler"] | undefined;
|
|
1276
|
+
getPhase(id: string): Phase | undefined;
|
|
1277
|
+
getPhases(): Phase[];
|
|
1515
1278
|
createPhaseRegistry(input?: {
|
|
1516
|
-
entryPhaseId?: string;
|
|
1279
|
+
entryPhaseId?: string | null;
|
|
1517
1280
|
}): PhaseRegistry;
|
|
1281
|
+
/** Adapt an extension RegisteredPhase to the core Phase type. */
|
|
1282
|
+
private adaptToPhase;
|
|
1518
1283
|
/**
|
|
1519
1284
|
* Bind the runner — flushes pending provider registrations and
|
|
1520
1285
|
* replaces runtime stubs with real implementations.
|
|
@@ -1528,22 +1293,22 @@ declare class ExtensionRunner {
|
|
|
1528
1293
|
* Unified hook emission — returns the first non-undefined result.
|
|
1529
1294
|
*/
|
|
1530
1295
|
private emitHook;
|
|
1531
|
-
emitBeforePhase(phaseId: string, input:
|
|
1296
|
+
emitBeforePhase(phaseId: string, input: PhaseContext): Promise<{
|
|
1532
1297
|
abort?: any;
|
|
1533
1298
|
skip?: any;
|
|
1534
|
-
input?:
|
|
1299
|
+
input?: PhaseContext;
|
|
1535
1300
|
}>;
|
|
1536
1301
|
emitAfterPhase(phaseId: string, output: PhaseOutput): Promise<{
|
|
1537
1302
|
abort?: any;
|
|
1538
|
-
retry?:
|
|
1303
|
+
retry?: PhaseContext;
|
|
1539
1304
|
output?: PhaseOutput;
|
|
1540
1305
|
}>;
|
|
1541
|
-
emitBeforePrompt(phaseId: string, input:
|
|
1542
|
-
emitBeforeToolCall(tool: Tool
|
|
1306
|
+
emitBeforePrompt(phaseId: string, input: PhaseContext): Promise<PhaseContext>;
|
|
1307
|
+
emitBeforeToolCall(tool: Tool, args: unknown): Promise<{
|
|
1543
1308
|
allow: boolean;
|
|
1544
1309
|
reason?: string;
|
|
1545
1310
|
}>;
|
|
1546
|
-
emitAfterToolCall(tool: Tool
|
|
1311
|
+
emitAfterToolCall(tool: Tool, result: ToolResult): Promise<ToolResult>;
|
|
1547
1312
|
emitAgentStart(sessionId: string): Promise<void>;
|
|
1548
1313
|
emitAgentEnd(sessionId: string, outcome: any, messages: any[]): Promise<void>;
|
|
1549
1314
|
emitTurnStart(messages: any[]): Promise<void>;
|
|
@@ -1577,21 +1342,6 @@ declare class ExtensionRunner {
|
|
|
1577
1342
|
}
|
|
1578
1343
|
declare function createExtensionRunner(options?: ExtensionRunnerOptions): ExtensionRunner;
|
|
1579
1344
|
|
|
1580
|
-
/** Check if a path is a built-in extension source (synthetic path). */
|
|
1581
|
-
declare function isBuiltinSource(path: string): boolean;
|
|
1582
|
-
/** Check if an external extension is attempting to override a built-in phase. */
|
|
1583
|
-
declare function isBuiltinPhaseOverride(phaseId: string, extensionPath: string): boolean;
|
|
1584
|
-
type CreateDefaultPhaseRegistryOptions = {
|
|
1585
|
-
cwd?: string;
|
|
1586
|
-
entryPhaseId?: string;
|
|
1587
|
-
};
|
|
1588
|
-
declare function getBuiltinExtensions(): Promise<LoadedExtension[]>;
|
|
1589
|
-
declare function getBuiltinRunner(): ExtensionRunner;
|
|
1590
|
-
declare function createBuiltinPhaseRegistry(input?: {
|
|
1591
|
-
entryPhaseId?: string;
|
|
1592
|
-
}): Promise<PhaseRegistry>;
|
|
1593
|
-
declare function createDefaultPhaseRegistry(options?: CreateDefaultPhaseRegistryOptions): Promise<PhaseRegistry>;
|
|
1594
|
-
|
|
1595
1345
|
/**
|
|
1596
1346
|
* Extension loader — discovers and loads extensions from the filesystem.
|
|
1597
1347
|
*
|
|
@@ -1602,7 +1352,6 @@ declare function createDefaultPhaseRegistry(options?: CreateDefaultPhaseRegistry
|
|
|
1602
1352
|
* Load a single extension from a factory function.
|
|
1603
1353
|
*/
|
|
1604
1354
|
declare function loadExtensionFromFactory(factory: ExtensionFactory, cwd: string, extensionPath?: string): LoadedExtension;
|
|
1605
|
-
declare const loadExtensionFromFactorySync: typeof loadExtensionFromFactory;
|
|
1606
1355
|
/**
|
|
1607
1356
|
* Load extensions from file paths.
|
|
1608
1357
|
*/
|
|
@@ -1632,22 +1381,26 @@ type AgentOptions = {
|
|
|
1632
1381
|
model: LlmModelRef;
|
|
1633
1382
|
stream: StreamFn;
|
|
1634
1383
|
cwd?: string;
|
|
1635
|
-
|
|
1384
|
+
rowanDir?: string;
|
|
1385
|
+
phases?: PhaseRegistry;
|
|
1636
1386
|
extensionRunnerRef?: ExtensionRunnerRef;
|
|
1637
1387
|
sessionId?: string;
|
|
1638
1388
|
maxAttempts?: number;
|
|
1639
|
-
limits?: AgentRunLimits;
|
|
1640
1389
|
beforeToolCall?: BeforeToolCall;
|
|
1641
1390
|
afterToolCall?: AfterToolCall;
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1391
|
+
onMessage?: (message: AgentMessage) => Promise<void>;
|
|
1392
|
+
onOutcome?: (outcome: Outcome) => Promise<void>;
|
|
1393
|
+
onModelTranscript?: (transcript: ModelTranscript, meta: {
|
|
1394
|
+
phase: string;
|
|
1395
|
+
model: LlmModelRef;
|
|
1396
|
+
}) => Promise<void>;
|
|
1397
|
+
};
|
|
1398
|
+
type RunOptions = Partial<AgentConfig> & Pick<AgentConfig, "context">;
|
|
1646
1399
|
type AgentStatus = {
|
|
1647
1400
|
sessionId?: string;
|
|
1648
1401
|
context: AgentContext;
|
|
1649
1402
|
model: LlmModelRef;
|
|
1650
|
-
tools: Tool
|
|
1403
|
+
tools: Tool[];
|
|
1651
1404
|
isRunning: boolean;
|
|
1652
1405
|
currentResult?: RunResult;
|
|
1653
1406
|
error?: string;
|
|
@@ -1685,67 +1438,58 @@ declare class Agent {
|
|
|
1685
1438
|
*/
|
|
1686
1439
|
private handleAfterPhase;
|
|
1687
1440
|
/**
|
|
1688
|
-
* Hook for before_prompt — called before
|
|
1689
|
-
* Extensions can transform the
|
|
1441
|
+
* Hook for before_prompt — called before model request, allowing extensions to transform PhaseContext.
|
|
1442
|
+
* Extensions can transform the PhaseContext (messages, tools, systemPrompt, etc.).
|
|
1690
1443
|
*/
|
|
1691
1444
|
private handleBeforePrompt;
|
|
1692
1445
|
private handleRunFailure;
|
|
1446
|
+
/**
|
|
1447
|
+
* Discover and load phases and skills from the workspace.
|
|
1448
|
+
*
|
|
1449
|
+
* - Auto-discovers file-based phases from .rowan/phases/
|
|
1450
|
+
* - Auto-discovers skills from .rowan/skills/
|
|
1451
|
+
* - Merges with CLI-provided phases and skills
|
|
1452
|
+
*/
|
|
1453
|
+
private discoverResources;
|
|
1693
1454
|
private runWithLifecycle;
|
|
1694
1455
|
private finishRun;
|
|
1695
1456
|
run(config?: RunOptions): Promise<RunResult>;
|
|
1696
1457
|
abort(reason?: string): void;
|
|
1458
|
+
/**
|
|
1459
|
+
* Get formatted skill content for LLM consumption.
|
|
1460
|
+
*
|
|
1461
|
+
* Finds the skill by name and returns the formatted content using `formatSkillInvocation`.
|
|
1462
|
+
* This is a programmatic API for developers to invoke skills directly.
|
|
1463
|
+
*
|
|
1464
|
+
* @param name - The skill name to look up
|
|
1465
|
+
* @param additionalInstructions - Optional additional instructions to append
|
|
1466
|
+
* @returns Formatted skill content string
|
|
1467
|
+
*/
|
|
1468
|
+
skill(name: string, additionalInstructions?: string): string;
|
|
1469
|
+
/**
|
|
1470
|
+
* Get formatted phase content for LLM consumption.
|
|
1471
|
+
*
|
|
1472
|
+
* Finds the phase by name and returns the formatted content.
|
|
1473
|
+
* This is a programmatic API for developers to invoke phases directly.
|
|
1474
|
+
*
|
|
1475
|
+
* @param name - The phase name to look up
|
|
1476
|
+
* @returns Formatted phase content string, or empty string if not found
|
|
1477
|
+
*/
|
|
1478
|
+
phase(name: string): Promise<string>;
|
|
1697
1479
|
waitForIdle(): Promise<void>;
|
|
1698
1480
|
private resolveRunConfig;
|
|
1699
1481
|
private createContextSnapshot;
|
|
1700
1482
|
}
|
|
1701
1483
|
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
*
|
|
1705
|
-
* Producers call `push(event)` to deliver events. Consumers iterate with
|
|
1706
|
-
* `for await (const event of stream)`. The stream terminates when an event
|
|
1707
|
-
* matches the `isComplete` predicate; `result()` resolves with the extracted
|
|
1708
|
-
* final value.
|
|
1709
|
-
*/
|
|
1710
|
-
declare class EventStream<T, R = T> implements AsyncIterable<T> {
|
|
1711
|
-
private queue;
|
|
1712
|
-
private waiting;
|
|
1713
|
-
private done;
|
|
1714
|
-
private finalResultPromise;
|
|
1715
|
-
private resolveFinalResult;
|
|
1716
|
-
private isComplete;
|
|
1717
|
-
private extractResult;
|
|
1718
|
-
constructor(isComplete: (event: T) => boolean, extractResult: (event: T) => R);
|
|
1719
|
-
push(event: T): void;
|
|
1720
|
-
end(result?: R): void;
|
|
1721
|
-
[Symbol.asyncIterator](): AsyncIterator<T>;
|
|
1722
|
-
result(): Promise<R>;
|
|
1723
|
-
}
|
|
1724
|
-
/**
|
|
1725
|
-
* Agent-level event stream that terminates on `agent_end`.
|
|
1726
|
-
* `result()` resolves with the final messages array.
|
|
1727
|
-
*/
|
|
1728
|
-
declare class AgentEventStream extends EventStream<AgentEvent, AgentMessage$1[]> {
|
|
1729
|
-
constructor();
|
|
1730
|
-
}
|
|
1484
|
+
declare function createId(prefix: string): string;
|
|
1485
|
+
declare function createTimestamp(date?: Date): string;
|
|
1731
1486
|
|
|
1732
|
-
declare const SESSION_SCHEMA_VERSION = "0.4.4";
|
|
1733
|
-
type AgentMessageMetadata = Record<string, unknown> & {
|
|
1734
|
-
phase?: string;
|
|
1735
|
-
};
|
|
1736
|
-
declare const AgentMessageSchema: Type.TObject<{
|
|
1737
|
-
id: Type.TString;
|
|
1738
|
-
role: Type.TUnion<[Type.TLiteral<"system">, Type.TLiteral<"user">, Type.TLiteral<"assistant">, Type.TLiteral<"tool">]>;
|
|
1739
|
-
content: Type.TString;
|
|
1740
|
-
createdAt: Type.TString;
|
|
1741
|
-
metadata: Type.TOptional<Type.TRecord<"^.*$", Type.TUnknown>>;
|
|
1742
|
-
}>;
|
|
1743
|
-
type AgentMessage = Type.Static<typeof AgentMessageSchema>;
|
|
1744
1487
|
declare const SkillSchema: Type.TObject<{
|
|
1745
1488
|
name: Type.TString;
|
|
1746
1489
|
description: Type.TString;
|
|
1747
1490
|
filePath: Type.TString;
|
|
1748
1491
|
baseDir: Type.TString;
|
|
1492
|
+
content: Type.TString;
|
|
1749
1493
|
disableModelInvocation: Type.TBoolean;
|
|
1750
1494
|
}>;
|
|
1751
1495
|
type Skill = Type.Static<typeof SkillSchema>;
|
|
@@ -1772,7 +1516,6 @@ declare function createSession<TLogEvent = never>(input: {
|
|
|
1772
1516
|
}): Session<TLogEvent>;
|
|
1773
1517
|
declare function appendUserTurn<TLogEvent>(session: Session<TLogEvent>, input: string): Session<TLogEvent>;
|
|
1774
1518
|
|
|
1775
|
-
declare const SESSION_MANAGER_SCHEMA_VERSION = "0.4.4";
|
|
1776
1519
|
type SessionHeader = {
|
|
1777
1520
|
type: "header";
|
|
1778
1521
|
id: string;
|
|
@@ -1822,8 +1565,17 @@ type CustomSessionEntry = SessionEntryBase & {
|
|
|
1822
1565
|
customType: string;
|
|
1823
1566
|
data: unknown;
|
|
1824
1567
|
};
|
|
1825
|
-
type
|
|
1826
|
-
type
|
|
1568
|
+
type SessionStateSessionEntry = SessionEntryBase & {
|
|
1569
|
+
type: "session_state";
|
|
1570
|
+
state: SessionState;
|
|
1571
|
+
};
|
|
1572
|
+
type ModelTranscriptSessionEntry = SessionEntryBase & {
|
|
1573
|
+
type: "model_transcript";
|
|
1574
|
+
transcript: ModelTranscript;
|
|
1575
|
+
phase?: string;
|
|
1576
|
+
model?: LlmModelRef;
|
|
1577
|
+
};
|
|
1578
|
+
type SessionEntry = MessageSessionEntry | OutcomeSessionEntry | ExecutionTurnSessionEntry | CompactionSessionEntry | BranchSummarySessionEntry | SessionInfoSessionEntry | CustomSessionEntry | SessionStateSessionEntry | ModelTranscriptSessionEntry;
|
|
1827
1579
|
type SessionAgentContext<TTool = unknown> = {
|
|
1828
1580
|
systemPrompt: string;
|
|
1829
1581
|
messages: AgentMessage[];
|
|
@@ -1873,48 +1625,17 @@ type SessionManager = {
|
|
|
1873
1625
|
customType: string;
|
|
1874
1626
|
data: unknown;
|
|
1875
1627
|
}): Promise<string>;
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
};
|
|
1881
|
-
declare function createSessionHeader(input: CreateSessionManagerInput): SessionHeader;
|
|
1882
|
-
declare class InMemorySessionManager implements SessionManager {
|
|
1883
|
-
private header;
|
|
1884
|
-
private readonly entries;
|
|
1885
|
-
private constructor();
|
|
1886
|
-
static create(input: CreateSessionManagerInput): InMemorySessionManager;
|
|
1887
|
-
static fromRecords(records: SessionRecord[]): InMemorySessionManager;
|
|
1888
|
-
getSessionId(): string;
|
|
1889
|
-
getSessionFile(): string | undefined;
|
|
1890
|
-
getHeader(): Promise<SessionHeader>;
|
|
1891
|
-
appendMessage(message: AgentMessage): Promise<string>;
|
|
1892
|
-
appendOutcome(outcome: Outcome): Promise<string>;
|
|
1893
|
-
appendExecutionTurn(turn: ExecutionTurn): Promise<string>;
|
|
1894
|
-
appendCompaction(input: {
|
|
1895
|
-
summary: string;
|
|
1896
|
-
firstKeptEntryId: string;
|
|
1897
|
-
}): Promise<string>;
|
|
1898
|
-
appendBranchSummary(input: {
|
|
1899
|
-
fromId: string;
|
|
1900
|
-
summary: string;
|
|
1901
|
-
}): Promise<string>;
|
|
1902
|
-
appendSessionInfo(input: {
|
|
1903
|
-
title: string;
|
|
1904
|
-
}): Promise<string>;
|
|
1905
|
-
appendCustom(input: {
|
|
1906
|
-
customType: string;
|
|
1907
|
-
data: unknown;
|
|
1628
|
+
appendSessionState(state: SessionState): Promise<string>;
|
|
1629
|
+
appendModelTranscript(transcript: ModelTranscript, meta?: {
|
|
1630
|
+
phase?: string;
|
|
1631
|
+
model?: LlmModelRef;
|
|
1908
1632
|
}): Promise<string>;
|
|
1633
|
+
getSessionState(): Promise<SessionState | undefined>;
|
|
1909
1634
|
branch(entryId: string | null): Promise<void>;
|
|
1910
1635
|
buildAgentContext<TTool = unknown>(input?: BuildAgentContextInput<TTool>): Promise<SessionAgentContext<TTool>>;
|
|
1911
1636
|
listEntries(): Promise<SessionEntry[]>;
|
|
1912
1637
|
loadExecutionTurns(filter?: StepFilter): Promise<ExecutionTurn[]>;
|
|
1913
|
-
|
|
1914
|
-
private appendEntry;
|
|
1915
|
-
private entriesForLeaf;
|
|
1916
|
-
}
|
|
1917
|
-
declare function summarizeSessionManagerRecords(records: readonly SessionRecord[]): SessionListItem;
|
|
1638
|
+
};
|
|
1918
1639
|
|
|
1919
1640
|
declare class LocalJsonlSessionManager implements SessionManager {
|
|
1920
1641
|
private readonly sessionsDir;
|
|
@@ -1946,6 +1667,12 @@ declare class LocalJsonlSessionManager implements SessionManager {
|
|
|
1946
1667
|
customType: string;
|
|
1947
1668
|
data: unknown;
|
|
1948
1669
|
}): Promise<string>;
|
|
1670
|
+
appendSessionState(state: SessionState): Promise<string>;
|
|
1671
|
+
appendModelTranscript(transcript: ModelTranscript, meta?: {
|
|
1672
|
+
phase?: string;
|
|
1673
|
+
model?: LlmModelRef;
|
|
1674
|
+
}): Promise<string>;
|
|
1675
|
+
getSessionState(): Promise<SessionState | undefined>;
|
|
1949
1676
|
branch(entryId: string | null): Promise<void>;
|
|
1950
1677
|
buildAgentContext<TTool = unknown>(input?: BuildAgentContextInput<TTool>): Promise<SessionAgentContext<TTool>>;
|
|
1951
1678
|
listEntries(): Promise<SessionEntry[]>;
|
|
@@ -1953,24 +1680,6 @@ declare class LocalJsonlSessionManager implements SessionManager {
|
|
|
1953
1680
|
private appendThroughInner;
|
|
1954
1681
|
}
|
|
1955
1682
|
|
|
1956
|
-
type ToolContext = {
|
|
1957
|
-
state: AgentContextState;
|
|
1958
|
-
toolCallId: string;
|
|
1959
|
-
};
|
|
1960
|
-
type ToolExecutionMode = "sequential" | "parallel";
|
|
1961
|
-
type Tool<TArgs = unknown> = {
|
|
1962
|
-
name: string;
|
|
1963
|
-
description: string;
|
|
1964
|
-
parameters: Type.TSchema;
|
|
1965
|
-
/** One-line snippet shown in the system prompt tool list. */
|
|
1966
|
-
promptSnippet?: string;
|
|
1967
|
-
/** Additional guidelines appended to the system prompt when this tool is active. */
|
|
1968
|
-
promptGuidelines?: string[];
|
|
1969
|
-
/** Whether this tool can run concurrently with others. Default: "parallel". */
|
|
1970
|
-
executionMode?: ToolExecutionMode;
|
|
1971
|
-
execute(args: TArgs, context: ToolContext, signal?: AbortSignal): Promise<ToolResult>;
|
|
1972
|
-
};
|
|
1973
|
-
|
|
1974
1683
|
type CoreToolContext = {
|
|
1975
1684
|
root?: string;
|
|
1976
1685
|
maxReadBytes?: number;
|
|
@@ -1992,13 +1701,92 @@ type ResolveWorkspaceOptions = {
|
|
|
1992
1701
|
entrypoint?: string;
|
|
1993
1702
|
homeDir?: string;
|
|
1994
1703
|
mode?: RuntimeMode;
|
|
1704
|
+
rowanDir?: string;
|
|
1995
1705
|
};
|
|
1996
1706
|
declare function resolveWorkspacePaths(options?: ResolveWorkspaceOptions): WorkspacePaths;
|
|
1997
1707
|
declare function resolveInWorkspace(path: string, rootOrPaths: string | Pick<WorkspacePaths, "cwd">): string;
|
|
1998
1708
|
|
|
1999
1709
|
declare function resolveSkillPath(input: string, workspace?: WorkspacePaths): string;
|
|
2000
|
-
declare function loadSkill(path: string, workspace?: WorkspacePaths): Promise<
|
|
2001
|
-
declare function loadSkills(paths?: string[]
|
|
1710
|
+
declare function loadSkill(path: string, workspace?: WorkspacePaths): Promise<Skill$1>;
|
|
1711
|
+
declare function loadSkills(workspace?: WorkspacePaths, paths?: string[]): Promise<Skill$1[]>;
|
|
1712
|
+
|
|
1713
|
+
type ModelConfigFromFile = {
|
|
1714
|
+
id: string;
|
|
1715
|
+
name?: string;
|
|
1716
|
+
primary?: boolean;
|
|
1717
|
+
reasoning?: boolean;
|
|
1718
|
+
input?: ("text" | "image")[];
|
|
1719
|
+
contextWindow?: number;
|
|
1720
|
+
maxTokens?: number;
|
|
1721
|
+
cost?: Partial<ModelCost>;
|
|
1722
|
+
};
|
|
1723
|
+
type ProviderConfigFromFile = {
|
|
1724
|
+
id: string;
|
|
1725
|
+
name?: string;
|
|
1726
|
+
baseUrl: string;
|
|
1727
|
+
apiKey: string;
|
|
1728
|
+
protocol: Protocol;
|
|
1729
|
+
timeoutMs?: number;
|
|
1730
|
+
maxRetries?: number;
|
|
1731
|
+
retryDelayMs?: number;
|
|
1732
|
+
headers?: Record<string, string>;
|
|
1733
|
+
models: ModelConfigFromFile[];
|
|
1734
|
+
};
|
|
1735
|
+
type AgentConfigFile = {
|
|
1736
|
+
model?: {
|
|
1737
|
+
provider: string;
|
|
1738
|
+
id: string;
|
|
1739
|
+
};
|
|
1740
|
+
logLevel?: "debug" | "info" | "warn" | "error" | "silent";
|
|
1741
|
+
providers: ProviderConfigFromFile[];
|
|
1742
|
+
};
|
|
1743
|
+
declare function interpolateEnvVars(value: string): string;
|
|
1744
|
+
declare function loadConfigFile(workspace: WorkspacePaths): Promise<AgentConfigFile | undefined>;
|
|
1745
|
+
declare function resolveDefaultModel(config: AgentConfigFile): LlmModelRef | undefined;
|
|
1746
|
+
declare function registerConfigModels(config: AgentConfigFile): void;
|
|
1747
|
+
declare function parseModelRef(input?: string): LlmModelRef | undefined;
|
|
1748
|
+
|
|
1749
|
+
/**
|
|
1750
|
+
* Push-based async iterable with a final result.
|
|
1751
|
+
*
|
|
1752
|
+
* Producers call `push(event)` to deliver events. Consumers iterate with
|
|
1753
|
+
* `for await (const event of stream)`. The stream terminates when an event
|
|
1754
|
+
* matches the `isComplete` predicate; `result()` resolves with the extracted
|
|
1755
|
+
* final value.
|
|
1756
|
+
*/
|
|
1757
|
+
declare class EventStream<T, R = T> implements AsyncIterable<T> {
|
|
1758
|
+
private queue;
|
|
1759
|
+
private waiting;
|
|
1760
|
+
private done;
|
|
1761
|
+
private finalResultPromise;
|
|
1762
|
+
private resolveFinalResult;
|
|
1763
|
+
private isComplete;
|
|
1764
|
+
private extractResult;
|
|
1765
|
+
constructor(isComplete: (event: T) => boolean, extractResult: (event: T) => R);
|
|
1766
|
+
push(event: T): void;
|
|
1767
|
+
end(result?: R): void;
|
|
1768
|
+
[Symbol.asyncIterator](): AsyncIterator<T>;
|
|
1769
|
+
result(): Promise<R>;
|
|
1770
|
+
}
|
|
1771
|
+
/**
|
|
1772
|
+
* Agent-level event stream that terminates on `agent_end`.
|
|
1773
|
+
* `result()` resolves with the final messages array.
|
|
1774
|
+
*/
|
|
1775
|
+
declare class AgentEventStream extends EventStream<AgentEvent, AgentMessage[]> {
|
|
1776
|
+
constructor();
|
|
1777
|
+
}
|
|
1778
|
+
|
|
1779
|
+
/**
|
|
1780
|
+
* Load all phases from .rowan/phases directory.
|
|
1781
|
+
*
|
|
1782
|
+
* Scans for subdirectories containing PHASE.md files.
|
|
1783
|
+
* Returns PhaseRegistry with entryPhaseId:
|
|
1784
|
+
* - null by default (caller must explicitly set to start from a specific phase)
|
|
1785
|
+
* - Set to a specific phase id to start from that phase
|
|
1786
|
+
*
|
|
1787
|
+
* When entryPhaseId is null, AgentLoop starts from "none" phase.
|
|
1788
|
+
*/
|
|
1789
|
+
declare function loadPhases(workspace?: WorkspacePaths, paths?: string[]): Promise<PhaseRegistry>;
|
|
2002
1790
|
|
|
2003
1791
|
interface SystemPromptOptions {
|
|
2004
1792
|
/** Base system prompt. */
|
|
@@ -2019,31 +1807,38 @@ interface SystemPromptOptions {
|
|
|
2019
1807
|
name: string;
|
|
2020
1808
|
description: string;
|
|
2021
1809
|
filePath: string;
|
|
1810
|
+
disableModelInvocation?: boolean;
|
|
2022
1811
|
}>;
|
|
2023
1812
|
/** Working directory. */
|
|
2024
1813
|
cwd?: string;
|
|
2025
1814
|
}
|
|
2026
1815
|
declare function buildSystemPrompt(options: SystemPromptOptions): string;
|
|
2027
1816
|
|
|
2028
|
-
|
|
2029
|
-
name: string;
|
|
2030
|
-
description: string;
|
|
2031
|
-
parameters: unknown;
|
|
2032
|
-
};
|
|
2033
|
-
type SerializableTool = {
|
|
2034
|
-
name: string;
|
|
2035
|
-
description: string;
|
|
2036
|
-
parameters: unknown;
|
|
2037
|
-
};
|
|
2038
|
-
declare function serializeSkills(skills: AgentContextSkill[]): Array<{
|
|
1817
|
+
declare function serializeSkills(skills: Skill$1[]): Array<{
|
|
2039
1818
|
name: string;
|
|
2040
1819
|
description: string;
|
|
2041
1820
|
filePath: string;
|
|
1821
|
+
disableModelInvocation?: boolean;
|
|
2042
1822
|
}>;
|
|
2043
|
-
declare function latestUserInput(
|
|
2044
|
-
declare function conversationMessages(messages:
|
|
2045
|
-
|
|
1823
|
+
declare function latestUserInput(messages: AgentMessage[]): string;
|
|
1824
|
+
declare function conversationMessages(messages: AgentMessage[]): LlmMessage[];
|
|
1825
|
+
/** Input for building an LLM request — generic, not phase-specific. */
|
|
1826
|
+
type ModelRequestInput = {
|
|
1827
|
+
systemPrompt: string;
|
|
1828
|
+
messages: AgentMessage[];
|
|
1829
|
+
tools: Array<{
|
|
1830
|
+
name: string;
|
|
1831
|
+
description: string;
|
|
1832
|
+
parameters: unknown;
|
|
1833
|
+
promptSnippet?: string;
|
|
1834
|
+
promptGuidelines?: string[];
|
|
1835
|
+
}>;
|
|
1836
|
+
skills: Skill$1[];
|
|
1837
|
+
promptGuidelines?: string[];
|
|
1838
|
+
appendSystemPrompt?: string;
|
|
1839
|
+
};
|
|
1840
|
+
declare function buildModelRequest(input: ModelRequestInput, options?: {
|
|
2046
1841
|
model?: LlmModelRef;
|
|
2047
1842
|
}): LlmRequest;
|
|
2048
1843
|
|
|
2049
|
-
export {
|
|
1844
|
+
export { type AbortEvent, type AfterPhaseEvent, type AfterPhaseHookResult, type AfterPhaseResult, type AfterToolCallEvent, type AfterToolCallResult, Agent, type AgentConfigFile, type AgentContext, type AgentEndEvent, AgentEventStream, type AgentOptions, type AgentStartEvent, type AgentStatus, type BeforePhaseEvent, type BeforePhaseHookResult, type BeforePhaseResult, type BeforePromptEvent, type BeforePromptResult, type BeforeToolCallEvent, type BeforeToolCallResult, type EventBus, EventStream, type ExecOptions, type ExecResult, type ExecutionTurn, type Extension, type ExtensionAPI, type ExtensionContext, type ExtensionError, type ExtensionErrorListener, type ExtensionFactory, type ExtensionManifest, type ExtensionPackageManifest, ExtensionRunner, type ExtensionRunnerOptions, type ExtensionRunnerRef, type ExtensionRuntime, type ExtensionUtils, HookError, type HookEvent, type HookEventType, type HookHandler, type HookResultMap, HooksManager, type LoadExtensionsResult, type LoadedExtension, LocalJsonlSessionManager, type LoopMetrics, type MessageEndEvent, type MessageStartEvent, type MessageUpdateEvent, type ModelConfigFromFile, type ModelTranscript, type Phase, type PhaseContext, type PhaseDefinition, type PhaseExecution, type PhaseOutput, type PhaseRegistration, type PhaseRegistry, type PhaseRun, type PhaseState, type ProviderConfigFromFile, type QueueUpdateEvent, type RegisteredPhase, type RegisteredTool, type RunOptions, type RunResult, type SavePointEvent, type Session, type SessionListItem, type SettledEvent, type SourceInfo, type Tool, type ToolDefinition, type ToolExecutionEndEvent, type ToolExecutionResult, type ToolExecutionStartEvent, type ToolExecutionUpdateEvent, type TurnEndEvent, type TurnStartEvent, type WorkspacePaths, appendUserTurn, buildModelRequest, buildSystemPrompt, conversationMessages, createCoreTools, createEventBus, createExtension, createExtensionAPI, createExtensionRunner, createExtensionRuntime, createId, createMessage, createSession, createSourceInfo, createTimestamp, discoverAndLoadExtensions, getGlobalHooks, interpolateEnvVars, latestUserInput, loadConfigFile, loadExtensionFromFactory, loadExtensions, loadPhases, loadSkill, loadSkills, messageContentText, parseModelRef, registerConfigModels, resetGlobalHooks, resolveDefaultModel, resolveInWorkspace, resolveSkillPath, resolveWorkspacePaths, serializeSkills };
|