@rowan-agent/agent 0.12.1 → 0.13.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.
- package/README.md +2 -2
- package/dist/index.d.ts +1471 -1443
- package/dist/index.js +586 -269
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -83,7 +83,8 @@ type ExecutionState = {
|
|
|
83
83
|
metrics: LoopMetrics;
|
|
84
84
|
status: "idle" | "running" | "suspended" | "completed" | "aborted" | "failed";
|
|
85
85
|
continuation?: ExecutionContinuationState;
|
|
86
|
-
|
|
86
|
+
runInteractions?: RunInteractionState;
|
|
87
|
+
phaseInteractions?: RunInteractionState;
|
|
87
88
|
};
|
|
88
89
|
type ExecutionContinuationState = {
|
|
89
90
|
isContinuing: boolean;
|
|
@@ -96,36 +97,46 @@ type ExecutionContinuationState = {
|
|
|
96
97
|
previousPhaseMessageId?: string;
|
|
97
98
|
};
|
|
98
99
|
|
|
99
|
-
type
|
|
100
|
-
type
|
|
101
|
-
type
|
|
102
|
-
type PhaseInteraction = Readonly<{
|
|
100
|
+
type RunInteractionKind = "user_input" | "permission" | "elicitation" | "confirmation";
|
|
101
|
+
type RunInteractionStatus = "pending" | "answered" | "replied" | "cancelled";
|
|
102
|
+
type RunInteraction = Readonly<{
|
|
103
103
|
id: string;
|
|
104
104
|
phase: string;
|
|
105
|
-
kind:
|
|
105
|
+
kind: RunInteractionKind;
|
|
106
106
|
prompt: string;
|
|
107
107
|
payload?: JsonValue;
|
|
108
108
|
createdAt: string;
|
|
109
|
-
status:
|
|
110
|
-
|
|
109
|
+
status: RunInteractionStatus;
|
|
110
|
+
answer?: JsonValue;
|
|
111
|
+
reply?: string;
|
|
112
|
+
toolCallId?: string;
|
|
113
|
+
result?: Readonly<{
|
|
114
|
+
answered?: string;
|
|
115
|
+
replied?: string;
|
|
116
|
+
cancelled?: string;
|
|
117
|
+
}>;
|
|
118
|
+
}>;
|
|
119
|
+
type RunInteractionRequest = Readonly<{
|
|
120
|
+
id?: string;
|
|
121
|
+
kind: RunInteractionKind;
|
|
122
|
+
prompt: string;
|
|
123
|
+
payload?: JsonValue;
|
|
111
124
|
toolCallId?: string;
|
|
125
|
+
result?: Readonly<{
|
|
126
|
+
answered?: string;
|
|
127
|
+
replied?: string;
|
|
128
|
+
cancelled?: string;
|
|
129
|
+
}>;
|
|
112
130
|
}>;
|
|
113
|
-
type
|
|
114
|
-
requests: readonly
|
|
131
|
+
type RunInteractionState = Readonly<{
|
|
132
|
+
requests: readonly RunInteraction[];
|
|
115
133
|
answers: Readonly<Record<string, JsonValue>>;
|
|
116
134
|
checkpoint?: JsonValue;
|
|
117
135
|
}>;
|
|
118
|
-
type
|
|
136
|
+
type RunInteractionDriver = Readonly<{
|
|
119
137
|
signal: AbortSignal;
|
|
120
|
-
request(input:
|
|
121
|
-
|
|
122
|
-
kind: PhaseInteractionKind;
|
|
123
|
-
prompt: string;
|
|
124
|
-
payload?: JsonValue;
|
|
125
|
-
origin?: PhaseInteractionOrigin;
|
|
126
|
-
toolCallId?: string;
|
|
127
|
-
}>): PhaseInteraction;
|
|
128
|
-
pending(): readonly PhaseInteraction[];
|
|
138
|
+
request(input: RunInteractionRequest): RunInteraction;
|
|
139
|
+
pending(): readonly RunInteraction[];
|
|
129
140
|
answers(): ReadonlyMap<string, JsonValue>;
|
|
130
141
|
checkpoint(): JsonValue | undefined;
|
|
131
142
|
clearCheckpoint(): void;
|
|
@@ -133,18 +144,16 @@ type PhaseInteractionDriver = Readonly<{
|
|
|
133
144
|
checkpoint?: JsonValue;
|
|
134
145
|
}>): never;
|
|
135
146
|
}>;
|
|
136
|
-
declare class
|
|
137
|
-
readonly code: "
|
|
147
|
+
declare class RunInteractionCancelledError extends Error {
|
|
148
|
+
readonly code: "run_interaction_cancelled";
|
|
138
149
|
constructor();
|
|
139
150
|
}
|
|
140
|
-
declare class
|
|
151
|
+
declare class RunInteractionBoundary extends Error {
|
|
141
152
|
readonly state: ExecutionState;
|
|
142
|
-
readonly interactions: readonly
|
|
143
|
-
constructor(state: ExecutionState, interactions: readonly
|
|
153
|
+
readonly interactions: readonly RunInteraction[];
|
|
154
|
+
constructor(state: ExecutionState, interactions: readonly RunInteraction[]);
|
|
144
155
|
}
|
|
145
156
|
|
|
146
|
-
/** Durable and transient DTOs owned by the event-driven Agent Runtime. */
|
|
147
|
-
|
|
148
157
|
declare const opaqueIdBrand: unique symbol;
|
|
149
158
|
type OpaqueId<Kind extends string> = string & {
|
|
150
159
|
readonly [opaqueIdBrand]: Kind;
|
|
@@ -152,7 +161,6 @@ type OpaqueId<Kind extends string> = string & {
|
|
|
152
161
|
type AgentId = OpaqueId<"AgentId">;
|
|
153
162
|
type RunId = OpaqueId<"RunId">;
|
|
154
163
|
type MessageId = OpaqueId<"MessageId">;
|
|
155
|
-
type InputRequestId = OpaqueId<"InputRequestId">;
|
|
156
164
|
type ToolCallId = OpaqueId<"ToolCallId">;
|
|
157
165
|
type EventId = OpaqueId<"EventId">;
|
|
158
166
|
type ExecutionId = OpaqueId<"ExecutionId">;
|
|
@@ -236,7 +244,23 @@ type ToolMessage = MessageBase & Readonly<{
|
|
|
236
244
|
role: "tool";
|
|
237
245
|
content: ToolMessageContent;
|
|
238
246
|
}>;
|
|
239
|
-
type
|
|
247
|
+
type InteractionRecord = MessageBase & Readonly<{
|
|
248
|
+
role: "interaction";
|
|
249
|
+
interactionId: string;
|
|
250
|
+
kind: "user_input" | "permission" | "elicitation" | "confirmation";
|
|
251
|
+
prompt: string;
|
|
252
|
+
phase: string;
|
|
253
|
+
status: "answered" | "replied" | "cancelled";
|
|
254
|
+
answer?: JsonValue;
|
|
255
|
+
reply?: string;
|
|
256
|
+
toolCallId?: ToolCallId;
|
|
257
|
+
result?: Readonly<{
|
|
258
|
+
answered?: string;
|
|
259
|
+
replied?: string;
|
|
260
|
+
cancelled?: string;
|
|
261
|
+
}>;
|
|
262
|
+
}>;
|
|
263
|
+
type Message = UserMessage | AssistantMessage | ToolMessage | InteractionRecord;
|
|
240
264
|
type Outcome = Readonly<{
|
|
241
265
|
id: OutcomeId;
|
|
242
266
|
message: string;
|
|
@@ -325,6 +349,12 @@ type DurableEventBase = Readonly<{
|
|
|
325
349
|
metadata?: Metadata;
|
|
326
350
|
createdAt: string;
|
|
327
351
|
}>;
|
|
352
|
+
type PhaseEntered = DurableEventBase & Readonly<{
|
|
353
|
+
kind: "phase_entered";
|
|
354
|
+
executionId: ExecutionId;
|
|
355
|
+
phaseId: string;
|
|
356
|
+
visit: number;
|
|
357
|
+
}>;
|
|
328
358
|
type MessageCommitted = DurableEventBase & Readonly<{
|
|
329
359
|
kind: "message_committed";
|
|
330
360
|
message: Message;
|
|
@@ -353,12 +383,7 @@ type RunStateChanged = DurableEventBase & (Readonly<{
|
|
|
353
383
|
kind: "run_state_changed";
|
|
354
384
|
from: "running";
|
|
355
385
|
to: "input_required";
|
|
356
|
-
|
|
357
|
-
id: InputRequestId;
|
|
358
|
-
phase: string;
|
|
359
|
-
prompt?: AssistantMessage;
|
|
360
|
-
}>;
|
|
361
|
-
interactions: readonly PhaseInteraction[];
|
|
386
|
+
interactions: readonly RunInteraction[];
|
|
362
387
|
answers: Readonly<Record<string, JsonValue>>;
|
|
363
388
|
}> | Readonly<{
|
|
364
389
|
kind: "run_state_changed";
|
|
@@ -409,6 +434,24 @@ type ToolStateChanged = DurableEventBase & (Readonly<{
|
|
|
409
434
|
toolCall: Extract<ToolCallSnapshot, {
|
|
410
435
|
state: "failed";
|
|
411
436
|
}>;
|
|
437
|
+
}> | Readonly<{
|
|
438
|
+
kind: "tool_state_changed";
|
|
439
|
+
transition: Readonly<{
|
|
440
|
+
from: "running";
|
|
441
|
+
to: "pending";
|
|
442
|
+
}>;
|
|
443
|
+
toolCall: Extract<ToolCallSnapshot, {
|
|
444
|
+
state: "pending";
|
|
445
|
+
}>;
|
|
446
|
+
}> | Readonly<{
|
|
447
|
+
kind: "tool_state_changed";
|
|
448
|
+
transition: Readonly<{
|
|
449
|
+
from: "running";
|
|
450
|
+
to: "pending";
|
|
451
|
+
}>;
|
|
452
|
+
toolCall: Extract<ToolCallSnapshot, {
|
|
453
|
+
state: "pending";
|
|
454
|
+
}>;
|
|
412
455
|
}> | Readonly<{
|
|
413
456
|
kind: "tool_state_changed";
|
|
414
457
|
transition: Readonly<{
|
|
@@ -437,7 +480,7 @@ type ToolStateChanged = DurableEventBase & (Readonly<{
|
|
|
437
480
|
state: "indeterminate";
|
|
438
481
|
}>;
|
|
439
482
|
}>);
|
|
440
|
-
type DurableRunEvent = MessageCommitted | MessageRevised | RunStateChanged | ToolStateChanged;
|
|
483
|
+
type DurableRunEvent = PhaseEntered | MessageCommitted | MessageRevised | RunStateChanged | ToolStateChanged;
|
|
441
484
|
type MessageDelta = Readonly<{
|
|
442
485
|
kind: "message_delta";
|
|
443
486
|
durability: "transient";
|
|
@@ -500,7 +543,7 @@ type PhaseExecution = {
|
|
|
500
543
|
reportStatus(status: PhaseStatus): Promise<void>;
|
|
501
544
|
executeTool(context: AgentContext, toolCall: ToolCall): Promise<ToolResult>;
|
|
502
545
|
executeTools(context: AgentContext, toolCalls: readonly ToolCall[]): Promise<readonly ToolResult[]>;
|
|
503
|
-
interaction:
|
|
546
|
+
interaction: RunInteractionDriver;
|
|
504
547
|
/** Message lifecycle manager for streaming updates from programmatic phases */
|
|
505
548
|
messages: PhaseMessageManager;
|
|
506
549
|
};
|
|
@@ -522,131 +565,108 @@ type PhaseMessageManager = {
|
|
|
522
565
|
discard(messageId: string): void;
|
|
523
566
|
};
|
|
524
567
|
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
source: string;
|
|
531
|
-
baseDir?: string;
|
|
532
|
-
displayName?: string;
|
|
533
|
-
}
|
|
534
|
-
/** Register a Phase by directory path or Phase object; PHASE.md and direct child Skills are loaded atomically when a path is supplied. */
|
|
535
|
-
type PhaseRegistration = string | Phase;
|
|
536
|
-
/**
|
|
537
|
-
* Tool definition for registering LLM-callable tools via `api.tool.register()`.
|
|
538
|
-
*
|
|
539
|
-
* @example
|
|
540
|
-
* ```typescript
|
|
541
|
-
* api.tool.register({
|
|
542
|
-
* name: "search_docs",
|
|
543
|
-
* description: "Search documentation",
|
|
544
|
-
* parameters: { type: "object", properties: { query: { type: "string" } } },
|
|
545
|
-
* execute: async (args, ctx) => {
|
|
546
|
-
* return { content: [{ type: "text", text: "result" }] };
|
|
547
|
-
* },
|
|
548
|
-
* });
|
|
549
|
-
* ```
|
|
550
|
-
*/
|
|
551
|
-
interface ToolDefinition {
|
|
552
|
-
/** Tool name (used in LLM tool calls) */
|
|
568
|
+
type PhaseRegistrySelection = Readonly<{
|
|
569
|
+
entryPhaseId: string | null;
|
|
570
|
+
phaseIds: readonly string[];
|
|
571
|
+
}>;
|
|
572
|
+
type AgentDefinition = Readonly<{
|
|
553
573
|
name: string;
|
|
554
|
-
/** Description for LLM */
|
|
555
574
|
description: string;
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
*/
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
575
|
+
prompt: string;
|
|
576
|
+
tools?: readonly string[];
|
|
577
|
+
skills?: readonly string[];
|
|
578
|
+
/** Host-supplied Skills private to this Agent Definition/Bundle. */
|
|
579
|
+
bundledSkills?: readonly Skill[];
|
|
580
|
+
phases?: PhaseRegistrySelection;
|
|
581
|
+
contexts?: readonly string[];
|
|
582
|
+
model?: ModelRef;
|
|
583
|
+
}>;
|
|
584
|
+
/** Parse one Markdown definition using the same frontmatter vocabulary as Phase resources. */
|
|
585
|
+
declare function parseAgentDefinition(raw: string): AgentDefinition;
|
|
586
|
+
|
|
587
|
+
type ResourceKind = "agent" | "tool" | "skill" | "phase";
|
|
588
|
+
type ResourceSourceId = string;
|
|
589
|
+
/** Rowan-native contribution aliases. Hosts may adapt their domain handlers to
|
|
590
|
+
* these existing Tool/Phase lifecycles without importing host Scope types. */
|
|
591
|
+
type ToolContribution = Tool$1;
|
|
592
|
+
type PhaseContribution = Phase;
|
|
593
|
+
type ResourceView = Readonly<{
|
|
594
|
+
agents: readonly ResourceSourceId[];
|
|
595
|
+
tools: readonly ResourceSourceId[];
|
|
596
|
+
skills: readonly ResourceSourceId[];
|
|
597
|
+
phases: readonly ResourceSourceId[];
|
|
598
|
+
}>;
|
|
599
|
+
type ResourceRef = Readonly<{
|
|
600
|
+
kind: ResourceKind;
|
|
601
|
+
sourceId: ResourceSourceId;
|
|
602
|
+
name: string;
|
|
603
|
+
}>;
|
|
604
|
+
type ResourceDiagnostic = Readonly<{
|
|
605
|
+
kind: "invalid" | "missing" | "collision";
|
|
606
|
+
sourceId: ResourceSourceId;
|
|
607
|
+
message: string;
|
|
608
|
+
path?: string;
|
|
609
|
+
}>;
|
|
610
|
+
type LoadResult = Readonly<{
|
|
611
|
+
revision: string;
|
|
612
|
+
registered: readonly ResourceRef[];
|
|
613
|
+
skipped: readonly ResourceDiagnostic[];
|
|
614
|
+
}>;
|
|
615
|
+
type LoadInput<T> = Readonly<{
|
|
616
|
+
sourceId: ResourceSourceId;
|
|
617
|
+
directory?: string;
|
|
618
|
+
values?: readonly T[];
|
|
619
|
+
}>;
|
|
620
|
+
type ResolvedResourceView = Readonly<{
|
|
621
|
+
agents: readonly AgentDefinition[];
|
|
622
|
+
tools: readonly Tool$1[];
|
|
623
|
+
skills: readonly Skill[];
|
|
624
|
+
phases: readonly Phase[];
|
|
625
|
+
revisions: Readonly<Record<ResourceKind, readonly string[]>>;
|
|
626
|
+
refs: Readonly<Record<ResourceKind, readonly ResourceRef[]>>;
|
|
627
|
+
}>;
|
|
628
|
+
type ResourceRegistryErrorCode = "invalid_source_id" | "invalid_resource_name" | "resource_collision" | "resource_input_missing" | "resource_directory_not_supported" | "unknown_resource_source" | "implicit_source_protected";
|
|
629
|
+
declare class ResourceRegistryError extends Error {
|
|
630
|
+
readonly code: ResourceRegistryErrorCode;
|
|
631
|
+
constructor(code: ResourceRegistryErrorCode, message: string);
|
|
595
632
|
}
|
|
596
|
-
|
|
597
|
-
type ExtensionErrorListener = (error: ExtensionError) => void;
|
|
598
|
-
type ExecOptions = {
|
|
599
|
-
/** Working directory for the command. Defaults to cwd passed to runtime. */
|
|
600
|
-
cwd?: string;
|
|
601
|
-
/** Environment variables to add/override. */
|
|
602
|
-
env?: Record<string, string>;
|
|
603
|
-
/** Timeout in milliseconds. */
|
|
604
|
-
timeout?: number;
|
|
605
|
-
/** AbortSignal for cancellation. */
|
|
606
|
-
signal?: AbortSignal;
|
|
607
|
-
};
|
|
608
|
-
type ExecResult = {
|
|
609
|
-
exitCode: number;
|
|
610
|
-
stdout: string;
|
|
611
|
-
stderr: string;
|
|
612
|
-
};
|
|
633
|
+
type RegistryValue = AgentDefinition | Tool$1 | Skill | Phase;
|
|
613
634
|
/**
|
|
614
|
-
*
|
|
615
|
-
* All ExtensionAPI instances reference this shared state.
|
|
635
|
+
* Runtime Resource Registry source transaction and view resolver.
|
|
616
636
|
*
|
|
617
|
-
*
|
|
618
|
-
|
|
619
|
-
interface ExtensionRuntime {
|
|
620
|
-
/** Throws when this extension instance is stale after runtime replacement. */
|
|
621
|
-
assertActive: () => void;
|
|
622
|
-
/** Marks this extension instance as stale after runtime replacement or reload. */
|
|
623
|
-
invalidate: (message?: string) => void;
|
|
624
|
-
}
|
|
625
|
-
/**
|
|
626
|
-
* Result of loading extensions from filesystem.
|
|
627
|
-
* The runner takes these and creates Extension tracking objects.
|
|
628
|
-
*/
|
|
629
|
-
type LoadExtensionsResult = {
|
|
630
|
-
extensions: LoadedExtension[];
|
|
631
|
-
errors: Array<{
|
|
632
|
-
path: string;
|
|
633
|
-
error: string;
|
|
634
|
-
}>;
|
|
635
|
-
};
|
|
636
|
-
/**
|
|
637
|
-
* Pre-initialization extension form — factory + metadata.
|
|
638
|
-
* Runner.loadExtensions() calls the factory and creates the full Extension object.
|
|
637
|
+
* Directory normalization is intentionally added by the typed loader slice;
|
|
638
|
+
* this first module owns only the atomic source/revision/collision semantics.
|
|
639
639
|
*/
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
640
|
+
declare class ResourceRegistry {
|
|
641
|
+
private readonly sources;
|
|
642
|
+
/** Sources registered by the bootstrap boundary (currently Extensions). */
|
|
643
|
+
private readonly implicitSources;
|
|
644
|
+
private revisionSequence;
|
|
645
|
+
loadAgents(input: LoadInput<AgentDefinition>): Promise<LoadResult>;
|
|
646
|
+
loadSkills(input: LoadInput<Skill>): Promise<LoadResult>;
|
|
647
|
+
loadPhases(input: LoadInput<Phase>): Promise<LoadResult>;
|
|
648
|
+
loadTools(input: Readonly<{
|
|
649
|
+
sourceId: ResourceSourceId;
|
|
650
|
+
values: readonly ToolContribution[];
|
|
651
|
+
}>): Promise<LoadResult>;
|
|
652
|
+
unload(input: Readonly<{
|
|
653
|
+
kind: ResourceKind;
|
|
654
|
+
sourceId: ResourceSourceId;
|
|
655
|
+
}>): Promise<LoadResult>;
|
|
656
|
+
resolveView(view: ResourceView): ResolvedResourceView;
|
|
657
|
+
/** Mark one already-loaded source as implicit for every Resource View. */
|
|
658
|
+
protected markImplicit(kind: ResourceKind, sourceId: ResourceSourceId): void;
|
|
659
|
+
/** Bootstrap-only helper for replacing an implicit contribution source. */
|
|
660
|
+
protected replaceImplicit<T extends RegistryValue>(kind: ResourceKind, sourceId: ResourceSourceId, values: readonly T[]): Promise<LoadResult>;
|
|
661
|
+
protected hasImplicit(kind: ResourceKind, sourceId: ResourceSourceId): boolean;
|
|
662
|
+
private withImplicit;
|
|
663
|
+
private collect;
|
|
664
|
+
private commit;
|
|
665
|
+
private resolveKind;
|
|
666
|
+
private resolveRevisions;
|
|
667
|
+
private resolveRefs;
|
|
668
|
+
private sourcesFor;
|
|
669
|
+
private nextRevision;
|
|
650
670
|
}
|
|
651
671
|
|
|
652
672
|
/**
|
|
@@ -772,1332 +792,1326 @@ interface ExtensionUtils {
|
|
|
772
792
|
}
|
|
773
793
|
|
|
774
794
|
/**
|
|
775
|
-
* Extension
|
|
795
|
+
* Extension runner — manages extension loading and hook execution.
|
|
776
796
|
*
|
|
777
|
-
*
|
|
778
|
-
*
|
|
779
|
-
*
|
|
780
|
-
*
|
|
781
|
-
*
|
|
797
|
+
* Architecture reference: PI's ExtensionRunner
|
|
798
|
+
* - Per-extension tracking via Extension objects
|
|
799
|
+
* - Shared ExtensionRuntime with invalidate/assertActive
|
|
800
|
+
* - Direct `on()` API for hook registration
|
|
801
|
+
* - Error listener pattern for structured error handling
|
|
802
|
+
* - Tool registration support
|
|
803
|
+
*/
|
|
804
|
+
|
|
805
|
+
type ExtensionRunnerOptions = {
|
|
806
|
+
entryPhaseId?: string | null;
|
|
807
|
+
cwd?: string;
|
|
808
|
+
};
|
|
809
|
+
/**
|
|
810
|
+
* Manages extensions and provides hooks for the agent loop.
|
|
811
|
+
*
|
|
812
|
+
* Features:
|
|
813
|
+
* - Per-extension tracking (handlers, tools, phases)
|
|
814
|
+
* - Shared runtime with lifecycle protection (invalidate/assertActive)
|
|
815
|
+
* - Error listener pattern for structured error handling
|
|
816
|
+
* - Direct hook API and extension-loaded hook API
|
|
817
|
+
* - Tool registration for LLM-callable tools
|
|
818
|
+
* - EventBus for inter-extension communication
|
|
819
|
+
*
|
|
820
|
+
* @example
|
|
821
|
+
* ```ts
|
|
822
|
+
* const runner = createExtensionRunner();
|
|
823
|
+
*
|
|
824
|
+
* // Direct hook registration
|
|
825
|
+
* const unsub = runner.on("before_tool_call", (event) => {
|
|
826
|
+
* return { allow: false, reason: "Blocked" };
|
|
827
|
+
* });
|
|
828
|
+
*
|
|
829
|
+
* // Error handling
|
|
830
|
+
* runner.onError((error) => {
|
|
831
|
+
* console.error(`Extension error in ${error.extensionPath}:`, error.error);
|
|
832
|
+
* });
|
|
833
|
+
*
|
|
834
|
+
* // Load extensions
|
|
835
|
+
* await runner.loadExtensions(extensions);
|
|
836
|
+
* runner.bind();
|
|
782
837
|
* ```
|
|
783
838
|
*/
|
|
784
|
-
|
|
839
|
+
declare class ExtensionRunner {
|
|
840
|
+
readonly hooks: HooksManager;
|
|
841
|
+
readonly runtime: ExtensionRuntime;
|
|
842
|
+
readonly events: EventBus;
|
|
843
|
+
private readonly cwd;
|
|
844
|
+
private readonly abortController;
|
|
845
|
+
private _idle;
|
|
846
|
+
private readonly extensions;
|
|
847
|
+
private readonly phases;
|
|
848
|
+
private _phaseCache;
|
|
849
|
+
private readonly pendingProviders;
|
|
850
|
+
private bound;
|
|
851
|
+
private readonly errorListeners;
|
|
852
|
+
/** Current agent context — set by the agent before each phase */
|
|
853
|
+
currentContext?: AgentContext;
|
|
854
|
+
constructor(options?: ExtensionRunnerOptions);
|
|
855
|
+
/** Whether the agent is currently idle (not streaming). */
|
|
856
|
+
get isIdle(): boolean;
|
|
857
|
+
/** Set idle state — called by the agent loop. */
|
|
858
|
+
setIdle(idle: boolean): void;
|
|
859
|
+
/** Abort signal for the current runner instance. */
|
|
860
|
+
get signal(): AbortSignal;
|
|
861
|
+
/** Abort the current runner operation. */
|
|
862
|
+
abort(): void;
|
|
785
863
|
/**
|
|
786
|
-
*
|
|
864
|
+
* Register an error listener.
|
|
865
|
+
* Returns an unsubscribe function.
|
|
866
|
+
*/
|
|
867
|
+
onError(listener: ExtensionErrorListener): () => void;
|
|
868
|
+
/**
|
|
869
|
+
* Emit a structured extension error to all listeners.
|
|
870
|
+
*/
|
|
871
|
+
emitError(error: ExtensionError): void;
|
|
872
|
+
/**
|
|
873
|
+
* Mark all extension contexts as stale.
|
|
874
|
+
* After calling this, any captured ExtensionAPI or ExtensionContext will throw
|
|
875
|
+
* on use. Used during runtime replacement or reload.
|
|
876
|
+
*/
|
|
877
|
+
invalidate(message?: string): void;
|
|
878
|
+
/**
|
|
879
|
+
* Subscribe to a specific hook event type.
|
|
880
|
+
* Returns an unsubscribe function.
|
|
787
881
|
*
|
|
788
|
-
* @
|
|
789
|
-
*
|
|
882
|
+
* @example
|
|
883
|
+
* ```ts
|
|
884
|
+
* const unsub = runner.on("before_tool_call", (event) => {
|
|
885
|
+
* return { allow: false, reason: "Blocked" };
|
|
886
|
+
* });
|
|
887
|
+
* unsub(); // Cancel subscription
|
|
888
|
+
* ```
|
|
790
889
|
*/
|
|
791
|
-
on<K extends HookEventType>(
|
|
792
|
-
/**
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
/**
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
890
|
+
on<K extends HookEventType>(type: K, handler: HookHandler<K>): () => void;
|
|
891
|
+
/**
|
|
892
|
+
* Load and initialize extensions.
|
|
893
|
+
* Creates Extension tracking objects and calls each factory with an ExtensionAPI.
|
|
894
|
+
*/
|
|
895
|
+
loadExtensions(extensions: LoadedExtension[]): Promise<void>;
|
|
896
|
+
/** Dispose all active Extensions in reverse activation order. */
|
|
897
|
+
close(): Promise<void>;
|
|
898
|
+
/** Get all registered tools from all extensions. */
|
|
899
|
+
getAllRegisteredTools(): RegisteredTool[];
|
|
900
|
+
/**
|
|
901
|
+
* Get a tool definition by name. Returns undefined if not found.
|
|
902
|
+
*/
|
|
903
|
+
getToolDefinition(toolName: string): RegisteredTool["definition"] | undefined;
|
|
904
|
+
getPhase(name: string): Phase | undefined;
|
|
905
|
+
getPhases(): Phase[];
|
|
906
|
+
createPhaseRegistry(input?: {
|
|
907
|
+
entryPhaseId?: string | null;
|
|
908
|
+
}): PhaseRegistry;
|
|
909
|
+
/** Adapt an extension RegisteredPhase to the core Phase type. */
|
|
910
|
+
private adaptToPhase;
|
|
911
|
+
/**
|
|
912
|
+
* Bind the runner — flushes pending provider registrations and
|
|
913
|
+
* replaces runtime stubs with real implementations.
|
|
914
|
+
*/
|
|
915
|
+
bind(): void;
|
|
916
|
+
/**
|
|
917
|
+
* Generic emit — fire-and-forget for any event type.
|
|
918
|
+
*/
|
|
919
|
+
emit<K extends HookEventType>(eventType: K, event: Parameters<HookHandler<K>>[0]): Promise<void>;
|
|
920
|
+
/**
|
|
921
|
+
* Unified hook emission — returns the first non-undefined result.
|
|
922
|
+
*/
|
|
923
|
+
private emitHook;
|
|
924
|
+
emitBeforePhase(phaseId: string, input: PhaseContext): Promise<{
|
|
925
|
+
abort?: any;
|
|
926
|
+
skip?: any;
|
|
927
|
+
input?: PhaseContext;
|
|
928
|
+
}>;
|
|
929
|
+
emitAfterPhase(phaseId: string, output: PhaseOutput): Promise<{
|
|
930
|
+
abort?: any;
|
|
931
|
+
retry?: PhaseContext;
|
|
932
|
+
output?: PhaseOutput;
|
|
933
|
+
}>;
|
|
934
|
+
emitBeforePrompt(phaseId: string, input: PhaseContext): Promise<PhaseContext>;
|
|
935
|
+
emitBeforeToolCall(tool: Tool, args: unknown, context?: {
|
|
936
|
+
runId?: string;
|
|
937
|
+
agentId?: string;
|
|
938
|
+
toolCallId?: string;
|
|
939
|
+
metadata?: Readonly<Record<string, unknown>>;
|
|
940
|
+
answer?: unknown;
|
|
941
|
+
}): Promise<BeforeToolCallResult>;
|
|
942
|
+
emitAfterToolCall(tool: Tool, result: ToolResult, context?: {
|
|
943
|
+
runId?: string;
|
|
944
|
+
agentId?: string;
|
|
945
|
+
toolCallId?: string;
|
|
946
|
+
metadata?: Readonly<Record<string, unknown>>;
|
|
947
|
+
}): Promise<ToolResult>;
|
|
948
|
+
/**
|
|
949
|
+
* Create an ExtensionAPI for a specific extension.
|
|
950
|
+
* Registration methods write to the extension tracking object.
|
|
951
|
+
* Action methods delegate to the shared runtime.
|
|
952
|
+
*/
|
|
953
|
+
private createExtensionAPI;
|
|
954
|
+
private registerTool;
|
|
955
|
+
private unregisterTool;
|
|
956
|
+
private registerPhase;
|
|
957
|
+
private registerPhaseDefinition;
|
|
958
|
+
private unregisterPhase;
|
|
959
|
+
private loadRegisteredPhase;
|
|
960
|
+
private registerProvider;
|
|
961
|
+
private unregisterProvider;
|
|
962
|
+
private flushPendingProviders;
|
|
963
|
+
private getRegisteredPhase;
|
|
964
|
+
private collectRegisteredPhases;
|
|
965
|
+
private rollbackExtension;
|
|
966
|
+
private disposeExtension;
|
|
838
967
|
}
|
|
839
|
-
/**
|
|
840
|
-
* Extension factory function.
|
|
841
|
-
* Receives ExtensionAPI for registering hooks, phases, and providers.
|
|
842
|
-
*/
|
|
843
|
-
type ExtensionDisposer = () => void | Promise<void>;
|
|
844
|
-
type ExtensionFactoryResult = void | ExtensionDisposer;
|
|
845
|
-
type ExtensionFactory = (api: ExtensionAPI) => ExtensionFactoryResult | Promise<ExtensionFactoryResult>;
|
|
846
968
|
|
|
847
|
-
type
|
|
848
|
-
|
|
849
|
-
type
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
kind: string;
|
|
853
|
-
/** Optional human-readable detail for UI/status consumers. */
|
|
854
|
-
message?: string;
|
|
855
|
-
/** Structured status payload. */
|
|
856
|
-
payload?: unknown;
|
|
969
|
+
type ExtensionContribution = LoadedExtension;
|
|
970
|
+
type ExtensionLoadInput = LoadInput<ExtensionContribution>;
|
|
971
|
+
type ExtensionActivationError = Readonly<{
|
|
972
|
+
path: string;
|
|
973
|
+
error: string;
|
|
857
974
|
}>;
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
/** Route to next phase, or "continue" to re-execute current phase, or "stop" to end. Undefined means no model route. */
|
|
865
|
-
route?: string;
|
|
866
|
-
/** Phase name that produced this output */
|
|
867
|
-
phase?: string;
|
|
868
|
-
/** Tool calls from the model invocation (used by framework for route extraction) */
|
|
869
|
-
toolCalls?: Array<{
|
|
870
|
-
id: string;
|
|
871
|
-
name: string;
|
|
872
|
-
args: unknown;
|
|
873
|
-
}>;
|
|
874
|
-
/** Route reason extracted from route tool call (for hooks to inspect) */
|
|
875
|
-
routeReason?: string;
|
|
876
|
-
/** Structured data from this phase, passed to the next phase */
|
|
877
|
-
payload?: unknown;
|
|
878
|
-
};
|
|
879
|
-
/** Phase machine state — tracks position and inter-phase data */
|
|
880
|
-
interface PhaseState {
|
|
881
|
-
current: string;
|
|
882
|
-
available: string[];
|
|
883
|
-
iterations: number;
|
|
884
|
-
payload?: unknown;
|
|
885
|
-
}
|
|
886
|
-
type PhaseInvocation = {
|
|
887
|
-
mode: "serial";
|
|
888
|
-
instanceId: string;
|
|
889
|
-
} | {
|
|
890
|
-
mode: "parallel";
|
|
891
|
-
instanceId: string;
|
|
892
|
-
groupId: string;
|
|
893
|
-
index: number;
|
|
894
|
-
count: number;
|
|
895
|
-
sourcePhaseId: string;
|
|
896
|
-
};
|
|
897
|
-
/** Durable identity of the Run execution currently invoking a Phase. */
|
|
898
|
-
type PhaseExecutionIdentity = Readonly<{
|
|
899
|
-
agentId: string;
|
|
900
|
-
runId: string;
|
|
901
|
-
executionId: string;
|
|
902
|
-
/** Original durable Run input, before any Phase-local interpretation. */
|
|
903
|
-
input?: UserContent;
|
|
904
|
-
/** Opaque metadata captured at the durable boundary; Rowan does not decode it. */
|
|
905
|
-
agentMetadata?: Readonly<Record<string, unknown>>;
|
|
906
|
-
runMetadata?: Readonly<Record<string, unknown>>;
|
|
975
|
+
type ExtensionActivationResult = Readonly<{
|
|
976
|
+
active: readonly string[];
|
|
977
|
+
errors: readonly ExtensionActivationError[];
|
|
978
|
+
revision?: string;
|
|
979
|
+
registered?: readonly string[];
|
|
980
|
+
skipped?: readonly ResourceDiagnostic[];
|
|
907
981
|
}>;
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
/** Phase-filtered tools */
|
|
913
|
-
tools: Tool$1[];
|
|
914
|
-
/** Phase-filtered skills */
|
|
915
|
-
skills: Skill[];
|
|
916
|
-
/** Phase machine state */
|
|
917
|
-
state: PhaseState;
|
|
918
|
-
/** Identity and dispatch metadata for this phase execution */
|
|
919
|
-
readonly invocation: PhaseInvocation;
|
|
920
|
-
/** Durable Run identity for cross-store integrations and idempotent commands. */
|
|
921
|
-
readonly execution: PhaseExecutionIdentity;
|
|
922
|
-
/** Additional guideline bullets appended to the system prompt */
|
|
923
|
-
promptGuidelines?: string[];
|
|
924
|
-
/** Text to append after the system prompt */
|
|
925
|
-
appendSystemPrompt?: string;
|
|
926
|
-
}
|
|
927
|
-
/** JSON-safe structural defaults declared by a Phase's `input` mapping. */
|
|
928
|
-
type PhaseInput = Readonly<Record<string, JsonValue>>;
|
|
929
|
-
/** JSON-safe option metadata exposed by a Phase to a host Settings surface. */
|
|
930
|
-
interface PhaseSettingsOption {
|
|
931
|
-
value: string;
|
|
932
|
-
label: string;
|
|
933
|
-
description?: string;
|
|
934
|
-
disabled?: boolean;
|
|
982
|
+
type ExtensionLifetimeErrorCode = "extensions_frozen" | "extensions_closed";
|
|
983
|
+
declare class ExtensionLifetimeError extends Error {
|
|
984
|
+
readonly code: ExtensionLifetimeErrorCode;
|
|
985
|
+
constructor(code: ExtensionLifetimeErrorCode, message: string);
|
|
935
986
|
}
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
987
|
+
/** Runtime-global Extension activation and lifetime boundary. */
|
|
988
|
+
declare class RuntimeExtensionLifetime {
|
|
989
|
+
private readonly runner;
|
|
990
|
+
private frozen;
|
|
991
|
+
private closed;
|
|
992
|
+
constructor(options?: {
|
|
993
|
+
cwd?: string;
|
|
994
|
+
});
|
|
995
|
+
activate(extensions: readonly LoadedExtension[]): Promise<ExtensionActivationResult>;
|
|
996
|
+
tools(): readonly RegisteredTool[];
|
|
997
|
+
phases(): readonly Phase[];
|
|
998
|
+
get extensionRunner(): ExtensionRunner;
|
|
999
|
+
close(): Promise<void>;
|
|
939
1000
|
}
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
1001
|
+
/** Bootstrap-only Registry facade; its Extension method disappears after init. */
|
|
1002
|
+
declare class RuntimeBootstrapRegistry extends ResourceRegistry {
|
|
1003
|
+
private readonly extensions;
|
|
1004
|
+
private readonly extensionSourceId;
|
|
1005
|
+
constructor(extensions?: RuntimeExtensionLifetime);
|
|
1006
|
+
/** Install Rowan-owned implicit resources before any host source is read. */
|
|
1007
|
+
ensureCoreResources(): Promise<void>;
|
|
1008
|
+
loadExtensions(input: readonly LoadedExtension[] | ExtensionLoadInput): Promise<ExtensionActivationResult>;
|
|
1009
|
+
get extensionRunner(): ExtensionRunner;
|
|
1010
|
+
get extensionTools(): readonly RegisteredTool[];
|
|
1011
|
+
get extensionPhases(): readonly Phase[];
|
|
1012
|
+
closeExtensions(): Promise<void>;
|
|
945
1013
|
}
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
path: string;
|
|
949
|
-
label: string;
|
|
950
|
-
description?: string;
|
|
951
|
-
} | {
|
|
952
|
-
type: "number";
|
|
953
|
-
path: string;
|
|
954
|
-
label: string;
|
|
955
|
-
description?: string;
|
|
956
|
-
min?: number;
|
|
957
|
-
max?: number;
|
|
958
|
-
step?: number;
|
|
959
|
-
unit?: string;
|
|
960
|
-
scale?: number;
|
|
961
|
-
} | {
|
|
962
|
-
type: "select";
|
|
963
|
-
path: string;
|
|
964
|
-
label: string;
|
|
965
|
-
description?: string;
|
|
966
|
-
options: readonly PhaseSettingsOption[];
|
|
967
|
-
} | {
|
|
968
|
-
type: "text";
|
|
969
|
-
path: string;
|
|
970
|
-
label: string;
|
|
971
|
-
description?: string;
|
|
972
|
-
placeholder?: string;
|
|
973
|
-
format?: "string" | "string-array" | "key-value";
|
|
974
|
-
multiline?: boolean;
|
|
975
|
-
} | {
|
|
976
|
-
type: "collection";
|
|
977
|
-
path: string;
|
|
978
|
-
label: string;
|
|
1014
|
+
|
|
1015
|
+
type DefinitionLayer = Readonly<{
|
|
979
1016
|
description?: string;
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
1017
|
+
prompt?: string;
|
|
1018
|
+
model?: ModelRef;
|
|
1019
|
+
tools?: readonly string[];
|
|
1020
|
+
skills?: readonly string[];
|
|
1021
|
+
phases?: PhaseRegistrySelection;
|
|
1022
|
+
}>;
|
|
1023
|
+
type AgentConfiguration = Readonly<{
|
|
1024
|
+
identity: string;
|
|
1025
|
+
definition: Readonly<{
|
|
1026
|
+
name: string;
|
|
1027
|
+
layer?: DefinitionLayer;
|
|
1028
|
+
}>;
|
|
1029
|
+
resourceView: ResourceView;
|
|
1030
|
+
contexts?: readonly ContextCandidate[];
|
|
1031
|
+
/** Trusted Host-owned Contexts rendered as durable user messages. */
|
|
1032
|
+
additionalContexts?: readonly ContextCandidate[];
|
|
1033
|
+
cwd?: string;
|
|
1034
|
+
maxAttempts?: number;
|
|
1035
|
+
model: ModelConfig | ModelRef;
|
|
1036
|
+
stream?: StreamFn;
|
|
1037
|
+
}>;
|
|
1038
|
+
type ConfigurationSnapshot = Readonly<{
|
|
1039
|
+
identity: string;
|
|
1040
|
+
definition: AgentDefinition;
|
|
1041
|
+
resources: Readonly<{
|
|
1042
|
+
tools: readonly Tool$1[];
|
|
1043
|
+
skills: readonly Skill[];
|
|
1044
|
+
phases?: PhaseRegistry;
|
|
1045
|
+
revisions: Readonly<Record<ResourceKind, readonly string[]>>;
|
|
1046
|
+
refs: Readonly<Record<ResourceKind, readonly ResourceRef[]>>;
|
|
1047
|
+
}>;
|
|
1048
|
+
contexts: readonly ContextCandidate[];
|
|
1049
|
+
additionalContexts: readonly ContextCandidate[];
|
|
1050
|
+
resourceView: ResourceView;
|
|
1051
|
+
cwd?: string;
|
|
1052
|
+
maxAttempts?: number;
|
|
1053
|
+
model: ModelConfig | ModelRef;
|
|
1054
|
+
stream?: StreamFn;
|
|
1055
|
+
}>;
|
|
1056
|
+
/** Resolve one Definition request into one immutable, source-qualified snapshot. */
|
|
1057
|
+
declare function resolveConfigurationSnapshot(registry: ResourceRegistry, input: AgentConfiguration): ConfigurationSnapshot;
|
|
1058
|
+
/** Whether one stored configuration is already a resolved snapshot. A snapshot
|
|
1059
|
+
* is used as it stands; a request is resolved against the current sources. */
|
|
1060
|
+
declare function isConfigurationSnapshot(config: AgentConfiguration | ConfigurationSnapshot): config is ConfigurationSnapshot;
|
|
1061
|
+
|
|
1062
|
+
type UserInput = string | Readonly<{
|
|
1063
|
+
content: UserContent;
|
|
1064
|
+
metadata?: Metadata;
|
|
1065
|
+
}>;
|
|
1066
|
+
type HistorySeed = readonly Message[];
|
|
1067
|
+
type ContextStatus = Readonly<{
|
|
1068
|
+
tokens: number;
|
|
1069
|
+
contextWindow: number;
|
|
1070
|
+
percent: number;
|
|
1071
|
+
thresholdTokens: number;
|
|
1072
|
+
estimated: boolean;
|
|
1073
|
+
coveredThrough?: Readonly<{
|
|
1074
|
+
messageId: MessageId;
|
|
1075
|
+
sequence: number;
|
|
1076
|
+
}>;
|
|
1077
|
+
}>;
|
|
1078
|
+
type ContextCompactionRecord = Readonly<{
|
|
990
1079
|
id: string;
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
}
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
metadata
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1080
|
+
agentId: AgentId;
|
|
1081
|
+
summary: string;
|
|
1082
|
+
coveredThrough?: Readonly<{
|
|
1083
|
+
messageId: MessageId;
|
|
1084
|
+
sequence: number;
|
|
1085
|
+
}>;
|
|
1086
|
+
instructions?: string;
|
|
1087
|
+
createdAt: string;
|
|
1088
|
+
}>;
|
|
1089
|
+
type ToolInvocationContext = Readonly<{
|
|
1090
|
+
agentId: AgentId;
|
|
1091
|
+
runId: RunId;
|
|
1092
|
+
/** Opaque JSON metadata captured from the Agent and Run records. Rowan does
|
|
1093
|
+
* not interpret host/domain fields. */
|
|
1094
|
+
agentMetadata?: Metadata;
|
|
1095
|
+
runMetadata?: Metadata;
|
|
1096
|
+
toolCallId: ToolCallId;
|
|
1097
|
+
reportProgress(progress: JsonValue): void;
|
|
1098
|
+
interaction: RunInteractionDriver;
|
|
1099
|
+
}>;
|
|
1100
|
+
type Tool$1 = Readonly<{
|
|
1011
1101
|
name: string;
|
|
1012
|
-
/** Rowan-owned
|
|
1013
|
-
core?: boolean;
|
|
1014
|
-
/** Description */
|
|
1015
|
-
description: string;
|
|
1016
|
-
/** Restricted tools (undefined = all tools available) */
|
|
1017
|
-
tools?: string[];
|
|
1018
|
-
/** Skills bundled directly inside this phase directory. Inline phases may omit this (equivalent to []). */
|
|
1019
|
-
skills?: Skill[];
|
|
1020
|
-
/** Forced next phase */
|
|
1021
|
-
target?: string;
|
|
1022
|
-
/** Structural JSON-safe input defaults */
|
|
1023
|
-
input?: PhaseInput;
|
|
1024
|
-
/** If true, phase gets a fresh context when executed in parallel */
|
|
1025
|
-
isolated?: boolean;
|
|
1026
|
-
/** Path to PHASE.md file */
|
|
1027
|
-
filePath: string;
|
|
1028
|
-
/** Phase directory path */
|
|
1029
|
-
baseDir: string;
|
|
1030
|
-
/** PHASE.md body content */
|
|
1031
|
-
content: string;
|
|
1032
|
-
/** Model override for this phase (resolved from frontmatter) */
|
|
1033
|
-
model?: ModelRef;
|
|
1034
|
-
/** Do not automatically inject this Phase into the model route catalog/context. */
|
|
1035
|
-
disableAutoInvocation?: boolean;
|
|
1036
|
-
/** Do not expose this Phase to direct user invocation. */
|
|
1037
|
-
disableImplicitInvocation?: boolean;
|
|
1038
|
-
/** ExtensionAPI factory function used for registration or programmatic execution. */
|
|
1039
|
-
factory?: (api: ExtensionAPI) => Promise<void>;
|
|
1040
|
-
/** Direct run function */
|
|
1041
|
-
run?: (context: PhaseContext, execution: PhaseExecution) => Promise<PhaseOutput | void>;
|
|
1042
|
-
}
|
|
1043
|
-
/**
|
|
1044
|
-
* Phase registry containing all loaded phases
|
|
1045
|
-
*/
|
|
1046
|
-
interface PhaseRegistry {
|
|
1047
|
-
/** Map of phase name to Phase object */
|
|
1048
|
-
phases: Map<string, Phase>;
|
|
1049
|
-
/** Entry phase name (null until Agent applies its default phase) */
|
|
1050
|
-
entryPhaseId: string | null;
|
|
1051
|
-
}
|
|
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
|
-
|
|
1142
|
-
type ToolContext = Pick<AgentContext, "skills"> & {
|
|
1143
|
-
toolCallId: string;
|
|
1144
|
-
};
|
|
1145
|
-
type ToolExecutionMode = "sequential" | "parallel";
|
|
1146
|
-
type Tool$1<TArgs = unknown> = {
|
|
1147
|
-
name: string;
|
|
1148
|
-
/** Rowan-owned Core Tool; Core Tools bypass Phase filtering. */
|
|
1102
|
+
/** Rowan-owned Core Tool; Core Tools bypass Definition/Phase filtering. */
|
|
1149
1103
|
core?: boolean;
|
|
1150
1104
|
description: string;
|
|
1151
1105
|
parameters: Type.TSchema;
|
|
1152
|
-
|
|
1153
|
-
promptSnippet?: string;
|
|
1154
|
-
/** Additional guidelines appended to the system prompt when this tool is active. */
|
|
1155
|
-
promptGuidelines?: string[];
|
|
1156
|
-
/** Whether this tool can run concurrently with others. Default: "parallel". */
|
|
1157
|
-
executionMode?: ToolExecutionMode;
|
|
1158
|
-
execute(args: TArgs, context: ToolContext, signal?: AbortSignal): Promise<ToolResult>;
|
|
1159
|
-
};
|
|
1160
|
-
/** Context snapshot passed into the low-level agent loop. */
|
|
1161
|
-
type AgentContext = {
|
|
1162
|
-
/** System prompt included with the request. */
|
|
1163
|
-
systemPrompt: string;
|
|
1164
|
-
/** Transcript visible to the model. */
|
|
1165
|
-
messages: AgentMessage[];
|
|
1166
|
-
/** Tools available for this run. */
|
|
1167
|
-
tools: Tool$1[];
|
|
1168
|
-
/** Skills available for this run. */
|
|
1169
|
-
skills: Skill[];
|
|
1170
|
-
/** Custom phases for this run. Agent normalizes this with the built-in default phase. */
|
|
1171
|
-
phases?: PhaseRegistry;
|
|
1172
|
-
};
|
|
1173
|
-
|
|
1174
|
-
/**
|
|
1175
|
-
* `root` anchors relative paths and the Bash working directory. It is not a
|
|
1176
|
-
* filesystem sandbox: core Tools use the permissions of the host process.
|
|
1177
|
-
*/
|
|
1178
|
-
type CoreToolContext = {
|
|
1179
|
-
root?: string;
|
|
1180
|
-
/** Directory for complete Tool Result spill files. */
|
|
1181
|
-
archiveDir?: string;
|
|
1182
|
-
maxReadBytes?: number;
|
|
1183
|
-
maxReadLines?: number;
|
|
1184
|
-
bashTimeoutMs?: number;
|
|
1185
|
-
maxBashOutputBytes?: number;
|
|
1186
|
-
};
|
|
1187
|
-
|
|
1188
|
-
type PhaseRegistrySelection = Readonly<{
|
|
1189
|
-
entryPhaseId: string | null;
|
|
1190
|
-
phaseIds: readonly string[];
|
|
1106
|
+
execute(args: JsonValue, context: ToolInvocationContext, signal: AbortSignal): Promise<ToolExecutionResult$1>;
|
|
1191
1107
|
}>;
|
|
1192
|
-
type
|
|
1108
|
+
type ContextCandidate = Readonly<{
|
|
1193
1109
|
name: string;
|
|
1194
|
-
|
|
1195
|
-
prompt: string;
|
|
1196
|
-
tools?: readonly string[];
|
|
1197
|
-
skills?: readonly string[];
|
|
1198
|
-
/** Host-supplied Skills private to this Agent Definition/Bundle. */
|
|
1199
|
-
bundledSkills?: readonly Skill[];
|
|
1200
|
-
phases?: PhaseRegistrySelection;
|
|
1201
|
-
contexts?: readonly string[];
|
|
1202
|
-
model?: ModelRef;
|
|
1110
|
+
value: JsonValue;
|
|
1203
1111
|
}>;
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
type ToolContribution = Tool;
|
|
1212
|
-
type PhaseContribution = Phase;
|
|
1213
|
-
type ResourceView = Readonly<{
|
|
1214
|
-
agents: readonly ResourceSourceId[];
|
|
1215
|
-
tools: readonly ResourceSourceId[];
|
|
1216
|
-
skills: readonly ResourceSourceId[];
|
|
1217
|
-
phases: readonly ResourceSourceId[];
|
|
1112
|
+
type BeforeToolCallDecision = Readonly<{
|
|
1113
|
+
allow: true;
|
|
1114
|
+
}> | Readonly<{
|
|
1115
|
+
allow: false;
|
|
1116
|
+
reason: string;
|
|
1117
|
+
}> | Readonly<{
|
|
1118
|
+
interaction: RunInteractionRequest;
|
|
1218
1119
|
}>;
|
|
1219
|
-
type
|
|
1220
|
-
|
|
1221
|
-
|
|
1120
|
+
type BeforeToolCall = (input: Readonly<{
|
|
1121
|
+
tool: Tool$1;
|
|
1122
|
+
args: JsonValue;
|
|
1123
|
+
context: ToolInvocationContext;
|
|
1124
|
+
signal: AbortSignal;
|
|
1125
|
+
answer?: JsonValue;
|
|
1126
|
+
}>) => BeforeToolCallDecision | Promise<BeforeToolCallDecision>;
|
|
1127
|
+
type AfterToolCall = (input: Readonly<{
|
|
1128
|
+
tool: Tool$1;
|
|
1129
|
+
result: ToolExecutionResult$1;
|
|
1130
|
+
context: ToolInvocationContext;
|
|
1131
|
+
signal: AbortSignal;
|
|
1132
|
+
}>) => ToolExecutionResult$1 | Promise<ToolExecutionResult$1>;
|
|
1133
|
+
type InvocationSource = "auto" | "implicit" | "external";
|
|
1134
|
+
type InvocationCatalogEntry = Readonly<{
|
|
1135
|
+
kind: "phase" | "skill";
|
|
1222
1136
|
name: string;
|
|
1137
|
+
description: string;
|
|
1138
|
+
input?: Phase["input"];
|
|
1139
|
+
core?: boolean;
|
|
1140
|
+
disableAutoInvocation: boolean;
|
|
1141
|
+
disableImplicitInvocation: boolean;
|
|
1142
|
+
filePath: string;
|
|
1223
1143
|
}>;
|
|
1224
|
-
type
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1144
|
+
type AgentRecord = Readonly<{
|
|
1145
|
+
id: AgentId;
|
|
1146
|
+
metadata?: Metadata;
|
|
1147
|
+
currentConfigToken?: ConfigToken;
|
|
1148
|
+
currentConfigIdentity?: string;
|
|
1149
|
+
createdAt: string;
|
|
1150
|
+
activatedAt?: string;
|
|
1151
|
+
updatedAt: string;
|
|
1229
1152
|
}>;
|
|
1230
|
-
type
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1153
|
+
type AgentDeletionRequest = Readonly<{
|
|
1154
|
+
agentId: AgentId;
|
|
1155
|
+
expectedRunIds: readonly RunId[];
|
|
1156
|
+
confirmation: "agent-delete-v1";
|
|
1234
1157
|
}>;
|
|
1235
|
-
type
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1158
|
+
type ExecutionToken = Readonly<{
|
|
1159
|
+
runId: RunId;
|
|
1160
|
+
ownerEpoch: number;
|
|
1161
|
+
executionId: ExecutionId;
|
|
1239
1162
|
}>;
|
|
1240
|
-
type
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
phases: readonly Phase[];
|
|
1245
|
-
revisions: Readonly<Record<ResourceKind, readonly string[]>>;
|
|
1246
|
-
refs: Readonly<Record<ResourceKind, readonly ResourceRef[]>>;
|
|
1163
|
+
type ExecutionCheckpoint = Readonly<{
|
|
1164
|
+
codec: string;
|
|
1165
|
+
version: number;
|
|
1166
|
+
data: JsonValue;
|
|
1247
1167
|
}>;
|
|
1248
|
-
type
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
type RegistryValue = AgentDefinition | Tool | Skill | Phase;
|
|
1254
|
-
/**
|
|
1255
|
-
* Runtime Resource Registry source transaction and view resolver.
|
|
1256
|
-
*
|
|
1257
|
-
* Directory normalization is intentionally added by the typed loader slice;
|
|
1258
|
-
* this first module owns only the atomic source/revision/collision semantics.
|
|
1259
|
-
*/
|
|
1260
|
-
declare class ResourceRegistry {
|
|
1261
|
-
private readonly sources;
|
|
1262
|
-
/** Sources registered by the bootstrap boundary (currently Extensions). */
|
|
1263
|
-
private readonly implicitSources;
|
|
1264
|
-
private revisionSequence;
|
|
1265
|
-
loadAgents(input: LoadInput<AgentDefinition>): Promise<LoadResult>;
|
|
1266
|
-
loadSkills(input: LoadInput<Skill>): Promise<LoadResult>;
|
|
1267
|
-
loadPhases(input: LoadInput<Phase>): Promise<LoadResult>;
|
|
1268
|
-
loadTools(input: Readonly<{
|
|
1269
|
-
sourceId: ResourceSourceId;
|
|
1270
|
-
values: readonly ToolContribution[];
|
|
1271
|
-
}>): Promise<LoadResult>;
|
|
1272
|
-
unload(input: Readonly<{
|
|
1273
|
-
kind: ResourceKind;
|
|
1274
|
-
sourceId: ResourceSourceId;
|
|
1275
|
-
}>): Promise<LoadResult>;
|
|
1276
|
-
resolveView(view: ResourceView): ResolvedResourceView;
|
|
1277
|
-
/** Mark one already-loaded source as implicit for every Resource View. */
|
|
1278
|
-
protected markImplicit(kind: ResourceKind, sourceId: ResourceSourceId): void;
|
|
1279
|
-
/** Bootstrap-only helper for replacing an implicit contribution source. */
|
|
1280
|
-
protected replaceImplicit<T extends RegistryValue>(kind: ResourceKind, sourceId: ResourceSourceId, values: readonly T[]): Promise<LoadResult>;
|
|
1281
|
-
protected hasImplicit(kind: ResourceKind, sourceId: ResourceSourceId): boolean;
|
|
1282
|
-
private withImplicit;
|
|
1283
|
-
private collect;
|
|
1284
|
-
private commit;
|
|
1285
|
-
private resolveKind;
|
|
1286
|
-
private resolveRevisions;
|
|
1287
|
-
private resolveRefs;
|
|
1288
|
-
private sourcesFor;
|
|
1289
|
-
private nextRevision;
|
|
1290
|
-
}
|
|
1291
|
-
|
|
1292
|
-
/**
|
|
1293
|
-
* Extension runner — manages extension loading and hook execution.
|
|
1294
|
-
*
|
|
1295
|
-
* Architecture reference: PI's ExtensionRunner
|
|
1296
|
-
* - Per-extension tracking via Extension objects
|
|
1297
|
-
* - Shared ExtensionRuntime with invalidate/assertActive
|
|
1298
|
-
* - Direct `on()` API for hook registration
|
|
1299
|
-
* - Error listener pattern for structured error handling
|
|
1300
|
-
* - Tool registration support
|
|
1301
|
-
*/
|
|
1302
|
-
|
|
1303
|
-
type ExtensionRunnerOptions = {
|
|
1304
|
-
entryPhaseId?: string | null;
|
|
1305
|
-
cwd?: string;
|
|
1306
|
-
};
|
|
1307
|
-
/**
|
|
1308
|
-
* Manages extensions and provides hooks for the agent loop.
|
|
1309
|
-
*
|
|
1310
|
-
* Features:
|
|
1311
|
-
* - Per-extension tracking (handlers, tools, phases)
|
|
1312
|
-
* - Shared runtime with lifecycle protection (invalidate/assertActive)
|
|
1313
|
-
* - Error listener pattern for structured error handling
|
|
1314
|
-
* - Direct hook API and extension-loaded hook API
|
|
1315
|
-
* - Tool registration for LLM-callable tools
|
|
1316
|
-
* - EventBus for inter-extension communication
|
|
1317
|
-
*
|
|
1318
|
-
* @example
|
|
1319
|
-
* ```ts
|
|
1320
|
-
* const runner = createExtensionRunner();
|
|
1321
|
-
*
|
|
1322
|
-
* // Direct hook registration
|
|
1323
|
-
* const unsub = runner.on("before_tool_call", (event) => {
|
|
1324
|
-
* return { allow: false, reason: "Blocked" };
|
|
1325
|
-
* });
|
|
1326
|
-
*
|
|
1327
|
-
* // Error handling
|
|
1328
|
-
* runner.onError((error) => {
|
|
1329
|
-
* console.error(`Extension error in ${error.extensionPath}:`, error.error);
|
|
1330
|
-
* });
|
|
1331
|
-
*
|
|
1332
|
-
* // Load extensions
|
|
1333
|
-
* await runner.loadExtensions(extensions);
|
|
1334
|
-
* runner.bind();
|
|
1335
|
-
* ```
|
|
1336
|
-
*/
|
|
1337
|
-
declare class ExtensionRunner {
|
|
1338
|
-
readonly hooks: HooksManager;
|
|
1339
|
-
readonly runtime: ExtensionRuntime;
|
|
1340
|
-
readonly events: EventBus;
|
|
1341
|
-
private readonly cwd;
|
|
1342
|
-
private readonly abortController;
|
|
1343
|
-
private _idle;
|
|
1344
|
-
private readonly extensions;
|
|
1345
|
-
private readonly phases;
|
|
1346
|
-
private _phaseCache;
|
|
1347
|
-
private readonly pendingProviders;
|
|
1348
|
-
private bound;
|
|
1349
|
-
private readonly errorListeners;
|
|
1350
|
-
/** Current agent context — set by the agent before each phase */
|
|
1351
|
-
currentContext?: AgentContext;
|
|
1352
|
-
constructor(options?: ExtensionRunnerOptions);
|
|
1353
|
-
/** Whether the agent is currently idle (not streaming). */
|
|
1354
|
-
get isIdle(): boolean;
|
|
1355
|
-
/** Set idle state — called by the agent loop. */
|
|
1356
|
-
setIdle(idle: boolean): void;
|
|
1357
|
-
/** Abort signal for the current runner instance. */
|
|
1358
|
-
get signal(): AbortSignal;
|
|
1359
|
-
/** Abort the current runner operation. */
|
|
1360
|
-
abort(): void;
|
|
1361
|
-
/**
|
|
1362
|
-
* Register an error listener.
|
|
1363
|
-
* Returns an unsubscribe function.
|
|
1364
|
-
*/
|
|
1365
|
-
onError(listener: ExtensionErrorListener): () => void;
|
|
1366
|
-
/**
|
|
1367
|
-
* Emit a structured extension error to all listeners.
|
|
1368
|
-
*/
|
|
1369
|
-
emitError(error: ExtensionError): void;
|
|
1370
|
-
/**
|
|
1371
|
-
* Mark all extension contexts as stale.
|
|
1372
|
-
* After calling this, any captured ExtensionAPI or ExtensionContext will throw
|
|
1373
|
-
* on use. Used during runtime replacement or reload.
|
|
1374
|
-
*/
|
|
1375
|
-
invalidate(message?: string): void;
|
|
1376
|
-
/**
|
|
1377
|
-
* Subscribe to a specific hook event type.
|
|
1378
|
-
* Returns an unsubscribe function.
|
|
1379
|
-
*
|
|
1380
|
-
* @example
|
|
1381
|
-
* ```ts
|
|
1382
|
-
* const unsub = runner.on("before_tool_call", (event) => {
|
|
1383
|
-
* return { allow: false, reason: "Blocked" };
|
|
1384
|
-
* });
|
|
1385
|
-
* unsub(); // Cancel subscription
|
|
1386
|
-
* ```
|
|
1387
|
-
*/
|
|
1388
|
-
on<K extends HookEventType>(type: K, handler: HookHandler<K>): () => void;
|
|
1389
|
-
/**
|
|
1390
|
-
* Load and initialize extensions.
|
|
1391
|
-
* Creates Extension tracking objects and calls each factory with an ExtensionAPI.
|
|
1392
|
-
*/
|
|
1393
|
-
loadExtensions(extensions: LoadedExtension[]): Promise<void>;
|
|
1394
|
-
/** Dispose all active Extensions in reverse activation order. */
|
|
1395
|
-
close(): Promise<void>;
|
|
1396
|
-
/** Get all registered tools from all extensions. */
|
|
1397
|
-
getAllRegisteredTools(): RegisteredTool[];
|
|
1398
|
-
/**
|
|
1399
|
-
* Get a tool definition by name. Returns undefined if not found.
|
|
1400
|
-
*/
|
|
1401
|
-
getToolDefinition(toolName: string): RegisteredTool["definition"] | undefined;
|
|
1402
|
-
getPhase(name: string): Phase | undefined;
|
|
1403
|
-
getPhases(): Phase[];
|
|
1404
|
-
createPhaseRegistry(input?: {
|
|
1405
|
-
entryPhaseId?: string | null;
|
|
1406
|
-
}): PhaseRegistry;
|
|
1407
|
-
/** Adapt an extension RegisteredPhase to the core Phase type. */
|
|
1408
|
-
private adaptToPhase;
|
|
1409
|
-
/**
|
|
1410
|
-
* Bind the runner — flushes pending provider registrations and
|
|
1411
|
-
* replaces runtime stubs with real implementations.
|
|
1412
|
-
*/
|
|
1413
|
-
bind(): void;
|
|
1414
|
-
/**
|
|
1415
|
-
* Generic emit — fire-and-forget for any event type.
|
|
1416
|
-
*/
|
|
1417
|
-
emit<K extends HookEventType>(eventType: K, event: Parameters<HookHandler<K>>[0]): Promise<void>;
|
|
1418
|
-
/**
|
|
1419
|
-
* Unified hook emission — returns the first non-undefined result.
|
|
1420
|
-
*/
|
|
1421
|
-
private emitHook;
|
|
1422
|
-
emitBeforePhase(phaseId: string, input: PhaseContext): Promise<{
|
|
1423
|
-
abort?: any;
|
|
1424
|
-
skip?: any;
|
|
1425
|
-
input?: PhaseContext;
|
|
1426
|
-
}>;
|
|
1427
|
-
emitAfterPhase(phaseId: string, output: PhaseOutput): Promise<{
|
|
1428
|
-
abort?: any;
|
|
1429
|
-
retry?: PhaseContext;
|
|
1430
|
-
output?: PhaseOutput;
|
|
1431
|
-
}>;
|
|
1432
|
-
emitBeforePrompt(phaseId: string, input: PhaseContext): Promise<PhaseContext>;
|
|
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>;
|
|
1446
|
-
/**
|
|
1447
|
-
* Create an ExtensionAPI for a specific extension.
|
|
1448
|
-
* Registration methods write to the extension tracking object.
|
|
1449
|
-
* Action methods delegate to the shared runtime.
|
|
1450
|
-
*/
|
|
1451
|
-
private createExtensionAPI;
|
|
1452
|
-
private registerTool;
|
|
1453
|
-
private unregisterTool;
|
|
1454
|
-
private registerPhase;
|
|
1455
|
-
private registerPhaseDefinition;
|
|
1456
|
-
private unregisterPhase;
|
|
1457
|
-
private loadRegisteredPhase;
|
|
1458
|
-
private registerProvider;
|
|
1459
|
-
private unregisterProvider;
|
|
1460
|
-
private flushPendingProviders;
|
|
1461
|
-
private getRegisteredPhase;
|
|
1462
|
-
private collectRegisteredPhases;
|
|
1463
|
-
private rollbackExtension;
|
|
1464
|
-
private disposeExtension;
|
|
1465
|
-
}
|
|
1466
|
-
|
|
1467
|
-
type ExtensionContribution = LoadedExtension;
|
|
1468
|
-
type ExtensionLoadInput = LoadInput<ExtensionContribution>;
|
|
1469
|
-
type ExtensionActivationError = Readonly<{
|
|
1470
|
-
path: string;
|
|
1471
|
-
error: string;
|
|
1472
|
-
}>;
|
|
1473
|
-
type ExtensionActivationResult = Readonly<{
|
|
1474
|
-
active: readonly string[];
|
|
1475
|
-
errors: readonly ExtensionActivationError[];
|
|
1476
|
-
revision?: string;
|
|
1477
|
-
registered?: readonly string[];
|
|
1478
|
-
skipped?: readonly ResourceDiagnostic[];
|
|
1479
|
-
}>;
|
|
1480
|
-
type ExtensionLifetimeErrorCode = "extensions_frozen" | "extensions_closed";
|
|
1481
|
-
declare class ExtensionLifetimeError extends Error {
|
|
1482
|
-
readonly code: ExtensionLifetimeErrorCode;
|
|
1483
|
-
constructor(code: ExtensionLifetimeErrorCode, message: string);
|
|
1484
|
-
}
|
|
1485
|
-
/** Runtime-global Extension activation and lifetime boundary. */
|
|
1486
|
-
declare class RuntimeExtensionLifetime {
|
|
1487
|
-
private readonly runner;
|
|
1488
|
-
private frozen;
|
|
1489
|
-
private closed;
|
|
1490
|
-
constructor(options?: {
|
|
1491
|
-
cwd?: string;
|
|
1492
|
-
});
|
|
1493
|
-
activate(extensions: readonly LoadedExtension[]): Promise<ExtensionActivationResult>;
|
|
1494
|
-
tools(): readonly RegisteredTool[];
|
|
1495
|
-
phases(): readonly Phase[];
|
|
1496
|
-
get extensionRunner(): ExtensionRunner;
|
|
1497
|
-
close(): Promise<void>;
|
|
1498
|
-
}
|
|
1499
|
-
/** Bootstrap-only Registry facade; its Extension method disappears after init. */
|
|
1500
|
-
declare class RuntimeBootstrapRegistry extends ResourceRegistry {
|
|
1501
|
-
private readonly extensions;
|
|
1502
|
-
private readonly extensionSourceId;
|
|
1503
|
-
constructor(extensions?: RuntimeExtensionLifetime);
|
|
1504
|
-
/** Install Rowan-owned implicit resources before any host source is read. */
|
|
1505
|
-
ensureCoreResources(): Promise<void>;
|
|
1506
|
-
loadExtensions(input: readonly LoadedExtension[] | ExtensionLoadInput): Promise<ExtensionActivationResult>;
|
|
1507
|
-
get extensionRunner(): ExtensionRunner;
|
|
1508
|
-
get extensionTools(): readonly RegisteredTool[];
|
|
1509
|
-
get extensionPhases(): readonly Phase[];
|
|
1510
|
-
closeExtensions(): Promise<void>;
|
|
1511
|
-
}
|
|
1512
|
-
|
|
1513
|
-
type DefinitionLayer = Readonly<{
|
|
1514
|
-
description?: string;
|
|
1515
|
-
prompt?: string;
|
|
1516
|
-
model?: ModelRef;
|
|
1517
|
-
tools?: readonly string[];
|
|
1518
|
-
skills?: readonly string[];
|
|
1519
|
-
phases?: PhaseRegistrySelection;
|
|
1168
|
+
type OwnerLease = Readonly<{
|
|
1169
|
+
ownerId: string;
|
|
1170
|
+
token: OwnerToken;
|
|
1171
|
+
epoch: number;
|
|
1172
|
+
expiresAt: string;
|
|
1520
1173
|
}>;
|
|
1521
|
-
type
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
layer?: DefinitionLayer;
|
|
1526
|
-
}>;
|
|
1527
|
-
resourceView: ResourceView;
|
|
1528
|
-
contexts?: readonly ContextCandidate[];
|
|
1529
|
-
/** Trusted Host-owned Contexts rendered as durable user messages. */
|
|
1530
|
-
additionalContexts?: readonly ContextCandidate[];
|
|
1531
|
-
cwd?: string;
|
|
1532
|
-
maxAttempts?: number;
|
|
1533
|
-
model: ModelConfig | ModelRef;
|
|
1534
|
-
stream?: StreamFn;
|
|
1174
|
+
type RunClaim = Readonly<{
|
|
1175
|
+
run: RunRecord;
|
|
1176
|
+
execution: ExecutionToken;
|
|
1177
|
+
history: readonly Message[];
|
|
1535
1178
|
}>;
|
|
1536
|
-
type
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
skills: readonly Skill[];
|
|
1542
|
-
phases?: PhaseRegistry;
|
|
1543
|
-
revisions: Readonly<Record<ResourceKind, readonly string[]>>;
|
|
1544
|
-
refs: Readonly<Record<ResourceKind, readonly ResourceRef[]>>;
|
|
1545
|
-
}>;
|
|
1546
|
-
contexts: readonly ContextCandidate[];
|
|
1547
|
-
additionalContexts: readonly ContextCandidate[];
|
|
1548
|
-
resourceView: ResourceView;
|
|
1549
|
-
cwd?: string;
|
|
1550
|
-
maxAttempts?: number;
|
|
1551
|
-
model: ModelConfig | ModelRef;
|
|
1552
|
-
stream?: StreamFn;
|
|
1179
|
+
type ToolCallReservation = Readonly<{
|
|
1180
|
+
providerToolCallId: string;
|
|
1181
|
+
name: string;
|
|
1182
|
+
args: JsonValue;
|
|
1183
|
+
toolCallId?: ToolCallId;
|
|
1553
1184
|
}>;
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
* is used as it stands; a request is resolved against the current sources. */
|
|
1558
|
-
declare function isConfigurationSnapshot(config: AgentConfiguration | ConfigurationSnapshot): config is ConfigurationSnapshot;
|
|
1559
|
-
|
|
1560
|
-
type UserInput = string | Readonly<{
|
|
1561
|
-
content: UserContent;
|
|
1562
|
-
metadata?: Metadata;
|
|
1185
|
+
type ToolCommit = Readonly<{
|
|
1186
|
+
run: RunRecord;
|
|
1187
|
+
toolCall: ToolCallSnapshot;
|
|
1563
1188
|
}>;
|
|
1564
|
-
type
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
contextWindow: number;
|
|
1568
|
-
percent: number;
|
|
1569
|
-
thresholdTokens: number;
|
|
1570
|
-
estimated: boolean;
|
|
1571
|
-
coveredThrough?: Readonly<{
|
|
1572
|
-
messageId: MessageId;
|
|
1573
|
-
sequence: number;
|
|
1574
|
-
}>;
|
|
1189
|
+
type ToolBatchCommit = Readonly<{
|
|
1190
|
+
run: RunRecord;
|
|
1191
|
+
toolCalls: readonly ToolCallSnapshot[];
|
|
1575
1192
|
}>;
|
|
1576
|
-
type
|
|
1577
|
-
id:
|
|
1193
|
+
type RunRecord = Readonly<{
|
|
1194
|
+
id: RunId;
|
|
1578
1195
|
agentId: AgentId;
|
|
1579
|
-
|
|
1580
|
-
|
|
1196
|
+
agentSequence: number;
|
|
1197
|
+
readySequence: number;
|
|
1198
|
+
revision: number;
|
|
1199
|
+
state: RunState;
|
|
1200
|
+
input: UserInput;
|
|
1201
|
+
initialMessageId?: MessageId;
|
|
1202
|
+
invalidatedBy?: Readonly<{
|
|
1581
1203
|
messageId: MessageId;
|
|
1582
|
-
|
|
1204
|
+
messageRevision: number;
|
|
1583
1205
|
}>;
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
}>;
|
|
1597
|
-
type Tool = Readonly<{
|
|
1598
|
-
name: string;
|
|
1599
|
-
/** Rowan-owned Core Tool; Core Tools bypass Definition/Phase filtering. */
|
|
1600
|
-
core?: boolean;
|
|
1601
|
-
description: string;
|
|
1602
|
-
parameters: Type.TSchema;
|
|
1603
|
-
execute(args: JsonValue, context: ToolInvocationContext, signal: AbortSignal): Promise<ToolExecutionResult$1>;
|
|
1604
|
-
}>;
|
|
1605
|
-
type ContextCandidate = Readonly<{
|
|
1606
|
-
name: string;
|
|
1607
|
-
value: JsonValue;
|
|
1608
|
-
}>;
|
|
1609
|
-
type ToolCallInteractionRequest = Readonly<{
|
|
1610
|
-
id?: string;
|
|
1611
|
-
kind: PhaseInteractionKind;
|
|
1612
|
-
prompt: string;
|
|
1613
|
-
payload?: JsonValue;
|
|
1614
|
-
}>;
|
|
1615
|
-
type BeforeToolCallDecision = Readonly<{
|
|
1616
|
-
allow: true;
|
|
1617
|
-
}> | Readonly<{
|
|
1618
|
-
allow: false;
|
|
1619
|
-
reason: string;
|
|
1620
|
-
}> | Readonly<{
|
|
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>;
|
|
1630
|
-
type AfterToolCall = (input: Readonly<{
|
|
1631
|
-
tool: Tool;
|
|
1632
|
-
result: ToolExecutionResult$1;
|
|
1633
|
-
context: ToolInvocationContext;
|
|
1634
|
-
signal: AbortSignal;
|
|
1635
|
-
}>) => ToolExecutionResult$1 | Promise<ToolExecutionResult$1>;
|
|
1636
|
-
type InvocationSource = "auto" | "implicit" | "external";
|
|
1637
|
-
type InvocationCatalogEntry = Readonly<{
|
|
1638
|
-
kind: "phase" | "skill";
|
|
1639
|
-
name: string;
|
|
1640
|
-
description: string;
|
|
1641
|
-
input?: Phase["input"];
|
|
1642
|
-
core?: boolean;
|
|
1643
|
-
disableAutoInvocation: boolean;
|
|
1644
|
-
disableImplicitInvocation: boolean;
|
|
1645
|
-
filePath: string;
|
|
1206
|
+
metadata?: Metadata;
|
|
1207
|
+
pinnedConfigToken?: ConfigToken;
|
|
1208
|
+
checkpoint?: ExecutionCheckpoint;
|
|
1209
|
+
currentPhaseId?: string;
|
|
1210
|
+
openInteractions?: readonly RunInteraction[];
|
|
1211
|
+
interactionAnswers?: Readonly<Record<string, JsonValue>>;
|
|
1212
|
+
execution?: ExecutionToken;
|
|
1213
|
+
outcome?: Outcome;
|
|
1214
|
+
failure?: RunFailure;
|
|
1215
|
+
cancellationReason?: string;
|
|
1216
|
+
createdAt: string;
|
|
1217
|
+
updatedAt: string;
|
|
1646
1218
|
}>;
|
|
1647
|
-
type
|
|
1219
|
+
type MessageRevisionResult = Readonly<{
|
|
1220
|
+
message: UserMessage & Readonly<{
|
|
1221
|
+
messageRevision: number;
|
|
1222
|
+
}>;
|
|
1223
|
+
replacementRun: RunRecord;
|
|
1224
|
+
invalidatedRunIds: readonly RunId[];
|
|
1225
|
+
affectedToolCallIds: readonly ToolCallId[];
|
|
1226
|
+
effectDigest?: string;
|
|
1227
|
+
}>;
|
|
1228
|
+
type RetentionResult = Readonly<{
|
|
1229
|
+
deletedRunIds: readonly RunId[];
|
|
1230
|
+
deletedToolCallIds: readonly ToolCallId[];
|
|
1231
|
+
deletedEventCount: number;
|
|
1232
|
+
retentionFloor: EventCursor;
|
|
1233
|
+
skipped?: "active_consumers" | "no_eligible_events";
|
|
1234
|
+
}>;
|
|
1235
|
+
type AgentSummary = Readonly<{
|
|
1648
1236
|
id: AgentId;
|
|
1649
1237
|
metadata?: Metadata;
|
|
1650
|
-
currentConfigToken?: ConfigToken;
|
|
1651
1238
|
currentConfigIdentity?: string;
|
|
1652
1239
|
createdAt: string;
|
|
1653
|
-
activatedAt
|
|
1240
|
+
activatedAt: string;
|
|
1654
1241
|
updatedAt: string;
|
|
1655
1242
|
}>;
|
|
1656
|
-
type
|
|
1243
|
+
type RunSummary = Readonly<{
|
|
1244
|
+
id: RunId;
|
|
1657
1245
|
agentId: AgentId;
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
ownerEpoch: number;
|
|
1664
|
-
executionId: ExecutionId;
|
|
1246
|
+
agentSequence: number;
|
|
1247
|
+
state: RunState;
|
|
1248
|
+
metadata?: Metadata;
|
|
1249
|
+
createdAt: string;
|
|
1250
|
+
updatedAt: string;
|
|
1665
1251
|
}>;
|
|
1666
|
-
type
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
data: JsonValue;
|
|
1252
|
+
type Page<T, Cursor> = Readonly<{
|
|
1253
|
+
items: readonly T[];
|
|
1254
|
+
next?: Cursor;
|
|
1670
1255
|
}>;
|
|
1671
|
-
type
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1256
|
+
type RunSnapshotBase = Readonly<{
|
|
1257
|
+
runId: RunId;
|
|
1258
|
+
agentId: AgentId;
|
|
1259
|
+
agentSequence: number;
|
|
1260
|
+
revision: number;
|
|
1261
|
+
input: UserInput;
|
|
1262
|
+
metadata?: Metadata;
|
|
1263
|
+
messageCount: number;
|
|
1264
|
+
toolCallCount: number;
|
|
1265
|
+
currentPhaseId?: string;
|
|
1675
1266
|
createdAt: string;
|
|
1267
|
+
updatedAt: string;
|
|
1268
|
+
cursor: EventCursor;
|
|
1676
1269
|
}>;
|
|
1677
|
-
type
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1270
|
+
type RunSnapshot = RunSnapshotBase & (Readonly<{
|
|
1271
|
+
state: "queued" | "running";
|
|
1272
|
+
currentPhaseId?: string;
|
|
1273
|
+
}> | Readonly<{
|
|
1274
|
+
state: "input_required";
|
|
1275
|
+
interactions: readonly RunInteraction[];
|
|
1276
|
+
answers: Readonly<Record<string, JsonValue>>;
|
|
1277
|
+
}> | Readonly<{
|
|
1278
|
+
state: "completed";
|
|
1279
|
+
outcome: Outcome;
|
|
1280
|
+
output?: AssistantMessage;
|
|
1281
|
+
}> | Readonly<{
|
|
1282
|
+
state: "failed";
|
|
1283
|
+
failure: RunFailure;
|
|
1284
|
+
}> | Readonly<{
|
|
1285
|
+
state: "cancelled";
|
|
1286
|
+
reason?: string;
|
|
1287
|
+
}>);
|
|
1288
|
+
type RunBoundary = Readonly<{
|
|
1289
|
+
type: "input_required";
|
|
1290
|
+
interactions: readonly RunInteraction[];
|
|
1291
|
+
answers: Readonly<Record<string, JsonValue>>;
|
|
1292
|
+
}> | Readonly<{
|
|
1293
|
+
type: "completed";
|
|
1294
|
+
outcome: Outcome;
|
|
1295
|
+
output?: AssistantMessage;
|
|
1296
|
+
}> | Readonly<{
|
|
1297
|
+
type: "failed";
|
|
1298
|
+
failure: RunFailure;
|
|
1299
|
+
}> | Readonly<{
|
|
1300
|
+
type: "cancelled";
|
|
1301
|
+
reason?: string;
|
|
1687
1302
|
}>;
|
|
1688
|
-
type
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1303
|
+
type ConfigResolution = Readonly<{
|
|
1304
|
+
kind: "available";
|
|
1305
|
+
config: AgentConfiguration | ConfigurationSnapshot;
|
|
1306
|
+
} | {
|
|
1307
|
+
kind: "deferred";
|
|
1308
|
+
retryAfterMs?: number;
|
|
1309
|
+
} | {
|
|
1310
|
+
kind: "unavailable";
|
|
1311
|
+
reason: string;
|
|
1693
1312
|
}>;
|
|
1694
|
-
type
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1313
|
+
type ConfigPutResult = Readonly<{
|
|
1314
|
+
kind: "stored";
|
|
1315
|
+
token: string;
|
|
1316
|
+
} | {
|
|
1317
|
+
kind: "identity_conflict";
|
|
1699
1318
|
}>;
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1319
|
+
interface ConfigProvider {
|
|
1320
|
+
put(input: {
|
|
1321
|
+
agentId: AgentId;
|
|
1322
|
+
agentMetadata?: Metadata;
|
|
1323
|
+
config: AgentConfiguration | ConfigurationSnapshot;
|
|
1324
|
+
operationId: string;
|
|
1325
|
+
signal: AbortSignal;
|
|
1326
|
+
}): Promise<ConfigPutResult>;
|
|
1327
|
+
resolve(input: {
|
|
1328
|
+
agentId: AgentId;
|
|
1329
|
+
agentMetadata?: Metadata;
|
|
1330
|
+
token: ConfigToken;
|
|
1331
|
+
signal: AbortSignal;
|
|
1332
|
+
}): Promise<ConfigResolution>;
|
|
1333
|
+
}
|
|
1334
|
+
interface OwnedStore {
|
|
1335
|
+
readonly lease: OwnerLease;
|
|
1336
|
+
reserveAgent(input: {
|
|
1337
|
+
idempotencyKey: string;
|
|
1338
|
+
metadata?: Metadata;
|
|
1339
|
+
configIdentity?: string;
|
|
1340
|
+
historySeed?: HistorySeed;
|
|
1341
|
+
}): Promise<AgentRecord>;
|
|
1342
|
+
activateAgent(agentId: AgentId, configToken?: ConfigToken, configIdentity?: string): Promise<AgentRecord>;
|
|
1343
|
+
updateAgentConfigToken(input: {
|
|
1344
|
+
agentId: AgentId;
|
|
1345
|
+
token: ConfigToken;
|
|
1346
|
+
configIdentity?: string;
|
|
1347
|
+
idempotencyKey: string;
|
|
1348
|
+
}): Promise<AgentRecord>;
|
|
1349
|
+
deleteAgent(input: AgentDeletionRequest): Promise<void>;
|
|
1350
|
+
reviseMessage(input: {
|
|
1351
|
+
agentId: AgentId;
|
|
1352
|
+
messageId: MessageId;
|
|
1353
|
+
expectedMessageRevision: number;
|
|
1354
|
+
content: UserContent;
|
|
1355
|
+
operationId: string;
|
|
1356
|
+
effectDigestConfirmation?: string;
|
|
1357
|
+
}): Promise<MessageRevisionResult>;
|
|
1358
|
+
compact(input?: {
|
|
1359
|
+
now?: string;
|
|
1360
|
+
retentionMs?: number;
|
|
1361
|
+
}): Promise<RetentionResult>;
|
|
1362
|
+
contextStatus(agentId: AgentId, contextWindow: number): Promise<ContextStatus>;
|
|
1363
|
+
contextMessages(agentId: AgentId, recentTokenBudget?: number): Promise<readonly Message[]>;
|
|
1364
|
+
commitContextCompaction(record: ContextCompactionRecord): Promise<ContextCompactionRecord>;
|
|
1365
|
+
createRun(input: {
|
|
1366
|
+
agentId: AgentId;
|
|
1367
|
+
input: UserInput;
|
|
1368
|
+
metadata?: Metadata;
|
|
1369
|
+
idempotencyKey: string;
|
|
1370
|
+
}): Promise<RunRecord>;
|
|
1371
|
+
claimRun(input: {
|
|
1372
|
+
runId: RunId;
|
|
1373
|
+
expectedRevision: number;
|
|
1374
|
+
executionId?: ExecutionId;
|
|
1375
|
+
messageId?: MessageId;
|
|
1376
|
+
configToken?: ConfigToken;
|
|
1377
|
+
}): Promise<RunClaim>;
|
|
1378
|
+
failQueuedRun(input: {
|
|
1379
|
+
runId: RunId;
|
|
1380
|
+
expectedRevision: number;
|
|
1381
|
+
failure: QueuedRunFailure;
|
|
1382
|
+
}): Promise<RunRecord>;
|
|
1383
|
+
commitPhaseEntered(input: {
|
|
1384
|
+
runId: RunId;
|
|
1385
|
+
execution: ExecutionToken;
|
|
1386
|
+
expectedRevision: number;
|
|
1387
|
+
phaseId: string;
|
|
1388
|
+
visit: number;
|
|
1389
|
+
}): Promise<RunRecord>;
|
|
1390
|
+
commitInputRequired(input: {
|
|
1391
|
+
runId: RunId;
|
|
1392
|
+
execution: ExecutionToken;
|
|
1393
|
+
expectedRevision: number;
|
|
1394
|
+
phase: string;
|
|
1395
|
+
prompt?: AssistantMessage;
|
|
1396
|
+
checkpoint: ExecutionCheckpoint;
|
|
1397
|
+
interactions?: readonly RunInteraction[];
|
|
1398
|
+
interactionAnswers?: Readonly<Record<string, JsonValue>>;
|
|
1399
|
+
pendingToolCallIds?: readonly ToolCallId[];
|
|
1400
|
+
}): Promise<RunRecord>;
|
|
1401
|
+
answerInteraction(input: {
|
|
1402
|
+
runId: RunId;
|
|
1403
|
+
interactionId: string;
|
|
1404
|
+
expectedRevision: number;
|
|
1405
|
+
input?: JsonValue;
|
|
1406
|
+
cancel?: boolean;
|
|
1407
|
+
}): Promise<RunRecord>;
|
|
1408
|
+
commitOutcome(input: {
|
|
1409
|
+
runId: RunId;
|
|
1410
|
+
execution: ExecutionToken;
|
|
1411
|
+
expectedRevision: number;
|
|
1412
|
+
outcome?: Outcome;
|
|
1413
|
+
failure?: RunFailure;
|
|
1414
|
+
output?: AssistantMessage;
|
|
1415
|
+
}): Promise<RunRecord>;
|
|
1416
|
+
reserveToolCall(input: {
|
|
1417
|
+
runId: RunId;
|
|
1418
|
+
execution: ExecutionToken;
|
|
1419
|
+
expectedRevision: number;
|
|
1420
|
+
requestMessageId: MessageId;
|
|
1421
|
+
name: string;
|
|
1422
|
+
args: JsonValue;
|
|
1423
|
+
toolCallId?: ToolCallId;
|
|
1424
|
+
providerToolCallId?: string;
|
|
1425
|
+
}): Promise<ToolCommit>;
|
|
1426
|
+
reserveToolCalls(input: {
|
|
1427
|
+
runId: RunId;
|
|
1428
|
+
execution: ExecutionToken;
|
|
1429
|
+
expectedRevision: number;
|
|
1430
|
+
requestMessageId: MessageId;
|
|
1431
|
+
calls: readonly ToolCallReservation[];
|
|
1432
|
+
}): Promise<ToolBatchCommit>;
|
|
1433
|
+
startToolCall(input: {
|
|
1434
|
+
runId: RunId;
|
|
1435
|
+
execution: ExecutionToken;
|
|
1436
|
+
expectedRevision: number;
|
|
1437
|
+
toolCallId: ToolCallId;
|
|
1438
|
+
}): Promise<ToolCommit>;
|
|
1439
|
+
suspendToolCall(input: {
|
|
1440
|
+
runId: RunId;
|
|
1441
|
+
execution: ExecutionToken;
|
|
1442
|
+
expectedRevision: number;
|
|
1443
|
+
toolCallId: ToolCallId;
|
|
1444
|
+
}): Promise<ToolCommit>;
|
|
1445
|
+
commitToolResult(input: {
|
|
1446
|
+
runId: RunId;
|
|
1447
|
+
execution: ExecutionToken;
|
|
1448
|
+
expectedRevision: number;
|
|
1449
|
+
toolCallId: ToolCallId;
|
|
1450
|
+
result: ToolExecutionResult$1;
|
|
1451
|
+
state: "completed" | "failed" | "indeterminate";
|
|
1452
|
+
reason?: string;
|
|
1453
|
+
}): Promise<ToolCommit>;
|
|
1454
|
+
cancelRun(input: {
|
|
1455
|
+
runId: RunId;
|
|
1456
|
+
expectedRevision?: number;
|
|
1457
|
+
reason?: string;
|
|
1458
|
+
output?: AssistantMessage;
|
|
1459
|
+
}): Promise<RunRecord>;
|
|
1460
|
+
snapshotRun(runId: RunId): Promise<RunSnapshot>;
|
|
1461
|
+
history(agentId: AgentId): Promise<readonly Message[]>;
|
|
1462
|
+
listAgents(): Promise<readonly AgentRecord[]>;
|
|
1463
|
+
listRuns(input?: {
|
|
1464
|
+
agentId?: AgentId;
|
|
1465
|
+
states?: readonly RunState[];
|
|
1466
|
+
}): Promise<readonly RunRecord[]>;
|
|
1467
|
+
listEvents(input?: {
|
|
1468
|
+
after?: EventCursor;
|
|
1469
|
+
}): Promise<readonly DurableRunEvent[]>;
|
|
1470
|
+
openConsumer(consumerId: string): Promise<ConsumerRegistration>;
|
|
1471
|
+
advanceConsumerCheckpoint(input: {
|
|
1472
|
+
consumerId: string;
|
|
1473
|
+
cursor: EventCursor;
|
|
1474
|
+
}): Promise<void>;
|
|
1475
|
+
renewOwner(leaseMs: number): Promise<OwnerLease>;
|
|
1476
|
+
sealAndReleaseOwner(): Promise<void>;
|
|
1477
|
+
}
|
|
1478
|
+
interface DurableStore {
|
|
1479
|
+
openOwner(input: {
|
|
1480
|
+
ownerId: string;
|
|
1481
|
+
leaseMs: number;
|
|
1482
|
+
}): Promise<OwnedStore>;
|
|
1483
|
+
}
|
|
1484
|
+
type AgentRuntimeOptions = Readonly<{
|
|
1485
|
+
store: DurableStore;
|
|
1486
|
+
configs?: ConfigProvider;
|
|
1487
|
+
concurrency?: number;
|
|
1488
|
+
bootstrap?: (registry: RuntimeBootstrapRegistry) => void | Promise<void>;
|
|
1703
1489
|
}>;
|
|
1704
|
-
type
|
|
1705
|
-
|
|
1706
|
-
|
|
1490
|
+
type DurableConsumer = Readonly<{
|
|
1491
|
+
caughtUp: Promise<void>;
|
|
1492
|
+
done: Promise<void>;
|
|
1493
|
+
stop(): void;
|
|
1707
1494
|
}>;
|
|
1708
|
-
|
|
1709
|
-
id: RunId;
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1495
|
+
interface AgentRun {
|
|
1496
|
+
readonly id: RunId;
|
|
1497
|
+
snapshot(): Promise<RunSnapshot>;
|
|
1498
|
+
observe(options?: {
|
|
1499
|
+
after?: EventCursor;
|
|
1500
|
+
signal?: AbortSignal;
|
|
1501
|
+
}): AsyncIterable<RunEvent>;
|
|
1502
|
+
wait(options?: {
|
|
1503
|
+
signal?: AbortSignal;
|
|
1504
|
+
}): Promise<RunBoundary>;
|
|
1505
|
+
respondInteraction(input: {
|
|
1506
|
+
interactionId: string;
|
|
1507
|
+
input?: JsonValue;
|
|
1508
|
+
cancel?: boolean;
|
|
1509
|
+
}): Promise<void>;
|
|
1510
|
+
cancel(reason?: string): Promise<RunBoundary>;
|
|
1511
|
+
}
|
|
1512
|
+
interface AgentRuntime$1 {
|
|
1513
|
+
loadAgents(input: LoadInput<AgentDefinition>): Promise<LoadResult>;
|
|
1514
|
+
loadSkills(input: LoadInput<Skill>): Promise<LoadResult>;
|
|
1515
|
+
loadPhases(input: LoadInput<Phase>): Promise<LoadResult>;
|
|
1516
|
+
loadTools(input: Readonly<{
|
|
1517
|
+
sourceId: string;
|
|
1518
|
+
values: readonly Tool$1[];
|
|
1519
|
+
}>): Promise<LoadResult>;
|
|
1520
|
+
unload(input: Readonly<{
|
|
1521
|
+
kind: ResourceKind;
|
|
1522
|
+
sourceId: string;
|
|
1523
|
+
}>): Promise<LoadResult>;
|
|
1524
|
+
createAgent(config: AgentConfiguration, options?: {
|
|
1525
|
+
idempotencyKey?: string;
|
|
1526
|
+
metadata?: Metadata;
|
|
1527
|
+
historySeed?: HistorySeed;
|
|
1528
|
+
}): Promise<AgentId>;
|
|
1529
|
+
updateAgentConfig(agentId: AgentId, config: AgentConfiguration, options: {
|
|
1530
|
+
idempotencyKey: string;
|
|
1531
|
+
}): Promise<void>;
|
|
1532
|
+
deleteAgent(input: AgentDeletionRequest): Promise<void>;
|
|
1533
|
+
revise(agentId: AgentId, input: {
|
|
1718
1534
|
messageId: MessageId;
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1535
|
+
expectedMessageRevision: number;
|
|
1536
|
+
content: UserContent;
|
|
1537
|
+
operationId: string;
|
|
1538
|
+
effectDigestConfirmation?: string;
|
|
1539
|
+
}): Promise<MessageRevisionResult>;
|
|
1540
|
+
compact(input?: {
|
|
1541
|
+
now?: string;
|
|
1542
|
+
retentionMs?: number;
|
|
1543
|
+
}): Promise<RetentionResult>;
|
|
1544
|
+
start(agentId: AgentId, input: UserInput, options: {
|
|
1545
|
+
idempotencyKey: string;
|
|
1546
|
+
metadata?: Metadata;
|
|
1547
|
+
}): Promise<AgentRun>;
|
|
1548
|
+
run(runId: RunId): AgentRun;
|
|
1549
|
+
contextStatus(agentId: AgentId, options?: {
|
|
1550
|
+
contextWindow?: number;
|
|
1551
|
+
}): Promise<ContextStatus>;
|
|
1552
|
+
compactContext(agentId: AgentId, options?: {
|
|
1553
|
+
input?: UserInput;
|
|
1554
|
+
instructions?: string;
|
|
1555
|
+
idempotencyKey?: string;
|
|
1556
|
+
}): Promise<AgentRun>;
|
|
1557
|
+
listInvocations(agentId: AgentId, options: {
|
|
1558
|
+
source: InvocationSource;
|
|
1559
|
+
}): Promise<readonly InvocationCatalogEntry[]>;
|
|
1560
|
+
history(agentId: AgentId): Promise<readonly Message[]>;
|
|
1561
|
+
listAgents(input?: {
|
|
1562
|
+
after?: AgentListCursor;
|
|
1563
|
+
limit?: number;
|
|
1564
|
+
}): Promise<Page<AgentSummary, AgentListCursor>>;
|
|
1565
|
+
listRuns(input?: {
|
|
1566
|
+
agentId?: AgentId;
|
|
1567
|
+
states?: readonly RunState[];
|
|
1568
|
+
after?: RunListCursor;
|
|
1569
|
+
limit?: number;
|
|
1570
|
+
}): Promise<Page<RunSummary, RunListCursor>>;
|
|
1571
|
+
consume(input: {
|
|
1572
|
+
consumerId: string;
|
|
1573
|
+
signal: AbortSignal;
|
|
1574
|
+
onEvent(event: DurableRunEvent, context: Readonly<{
|
|
1575
|
+
signal: AbortSignal;
|
|
1576
|
+
}>): void | Promise<void>;
|
|
1577
|
+
}): Promise<DurableConsumer>;
|
|
1578
|
+
close(): Promise<void>;
|
|
1579
|
+
}
|
|
1580
|
+
type ConsumerRegistration = Readonly<{
|
|
1581
|
+
cursor?: EventCursor;
|
|
1582
|
+
waterline: EventCursor;
|
|
1733
1583
|
}>;
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1584
|
+
|
|
1585
|
+
interface SourceInfo {
|
|
1586
|
+
source: string;
|
|
1587
|
+
baseDir?: string;
|
|
1588
|
+
displayName?: string;
|
|
1589
|
+
}
|
|
1590
|
+
/** Register a Phase by directory path or Phase object; PHASE.md and direct child Skills are loaded atomically when a path is supplied. */
|
|
1591
|
+
type PhaseRegistration = string | Phase;
|
|
1592
|
+
/**
|
|
1593
|
+
* Tool definition for registering LLM-callable tools via `api.tool.register()`.
|
|
1594
|
+
*
|
|
1595
|
+
* @example
|
|
1596
|
+
* ```typescript
|
|
1597
|
+
* api.tool.register({
|
|
1598
|
+
* name: "search_docs",
|
|
1599
|
+
* description: "Search documentation",
|
|
1600
|
+
* parameters: { type: "object", properties: { query: { type: "string" } } },
|
|
1601
|
+
* execute: async (args, ctx) => {
|
|
1602
|
+
* return { content: [{ type: "text", text: "result" }] };
|
|
1603
|
+
* },
|
|
1604
|
+
* });
|
|
1605
|
+
* ```
|
|
1606
|
+
*/
|
|
1607
|
+
interface ToolDefinition {
|
|
1608
|
+
/** Tool name (used in LLM tool calls) */
|
|
1609
|
+
name: string;
|
|
1610
|
+
/** Description for LLM */
|
|
1611
|
+
description: string;
|
|
1612
|
+
/** Parameter schema (JSON Schema) */
|
|
1613
|
+
parameters: Record<string, unknown>;
|
|
1614
|
+
/** Execute the tool */
|
|
1615
|
+
execute: (args: unknown, context: ToolInvocationContext, signal?: AbortSignal) => Promise<ToolExecutionResult>;
|
|
1616
|
+
/** Optional: per-tool execution mode override */
|
|
1617
|
+
executionMode?: "sequential" | "parallel";
|
|
1618
|
+
}
|
|
1619
|
+
/**
|
|
1620
|
+
* Result from tool execution.
|
|
1621
|
+
*/
|
|
1622
|
+
interface ToolExecutionResult {
|
|
1623
|
+
/** Content blocks to return to the LLM */
|
|
1624
|
+
content: Array<{
|
|
1625
|
+
type: string;
|
|
1626
|
+
text?: string;
|
|
1627
|
+
[key: string]: unknown;
|
|
1737
1628
|
}>;
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1629
|
+
/** Whether this is an error result */
|
|
1630
|
+
isError?: boolean;
|
|
1631
|
+
}
|
|
1632
|
+
/**
|
|
1633
|
+
* Registered tool with source metadata.
|
|
1634
|
+
*/
|
|
1635
|
+
interface RegisteredTool {
|
|
1636
|
+
definition: ToolDefinition;
|
|
1637
|
+
sourceInfo: SourceInfo;
|
|
1638
|
+
}
|
|
1639
|
+
/**
|
|
1640
|
+
* Structured extension error with attribution.
|
|
1641
|
+
*/
|
|
1642
|
+
interface ExtensionError {
|
|
1643
|
+
/** Path of the extension that caused the error */
|
|
1644
|
+
extensionPath: string;
|
|
1645
|
+
/** Event or operation that caused the error */
|
|
1646
|
+
event: string;
|
|
1647
|
+
/** Error message */
|
|
1648
|
+
error: string;
|
|
1649
|
+
/** Optional stack trace */
|
|
1650
|
+
stack?: string;
|
|
1651
|
+
}
|
|
1652
|
+
/** Error listener callback type. */
|
|
1653
|
+
type ExtensionErrorListener = (error: ExtensionError) => void;
|
|
1654
|
+
type ExecOptions = {
|
|
1655
|
+
/** Working directory for the command. Defaults to cwd passed to runtime. */
|
|
1656
|
+
cwd?: string;
|
|
1657
|
+
/** Environment variables to add/override. */
|
|
1658
|
+
env?: Record<string, string>;
|
|
1659
|
+
/** Timeout in milliseconds. */
|
|
1660
|
+
timeout?: number;
|
|
1661
|
+
/** AbortSignal for cancellation. */
|
|
1662
|
+
signal?: AbortSignal;
|
|
1663
|
+
};
|
|
1664
|
+
type ExecResult = {
|
|
1665
|
+
exitCode: number;
|
|
1666
|
+
stdout: string;
|
|
1667
|
+
stderr: string;
|
|
1668
|
+
};
|
|
1669
|
+
/**
|
|
1670
|
+
* Shared runtime state created by loader, used during registration and runtime.
|
|
1671
|
+
* All ExtensionAPI instances reference this shared state.
|
|
1672
|
+
*
|
|
1673
|
+
* It only owns the lifetime guard shared by captured Extension API objects.
|
|
1674
|
+
*/
|
|
1675
|
+
interface ExtensionRuntime {
|
|
1676
|
+
/** Throws when this extension instance is stale after runtime replacement. */
|
|
1677
|
+
assertActive: () => void;
|
|
1678
|
+
/** Marks this extension instance as stale after runtime replacement or reload. */
|
|
1679
|
+
invalidate: (message?: string) => void;
|
|
1680
|
+
}
|
|
1681
|
+
/**
|
|
1682
|
+
* Result of loading extensions from filesystem.
|
|
1683
|
+
* The runner takes these and creates Extension tracking objects.
|
|
1684
|
+
*/
|
|
1685
|
+
type LoadExtensionsResult = {
|
|
1686
|
+
extensions: LoadedExtension[];
|
|
1687
|
+
errors: Array<{
|
|
1688
|
+
path: string;
|
|
1689
|
+
error: string;
|
|
1690
|
+
}>;
|
|
1691
|
+
};
|
|
1692
|
+
/**
|
|
1693
|
+
* Pre-initialization extension form — factory + metadata.
|
|
1694
|
+
* Runner.loadExtensions() calls the factory and creates the full Extension object.
|
|
1695
|
+
*/
|
|
1696
|
+
interface LoadedExtension {
|
|
1697
|
+
path: string;
|
|
1698
|
+
name: string;
|
|
1699
|
+
factory: ExtensionFactory;
|
|
1700
|
+
manifest?: ExtensionManifest;
|
|
1701
|
+
}
|
|
1702
|
+
/** Extension manifest from package.json `rowan` field. */
|
|
1703
|
+
interface ExtensionManifest {
|
|
1704
|
+
entry?: string;
|
|
1705
|
+
name?: string;
|
|
1706
|
+
}
|
|
1707
|
+
|
|
1708
|
+
/**
|
|
1709
|
+
* Extension API object passed to extension factory function.
|
|
1710
|
+
*
|
|
1711
|
+
* @example
|
|
1712
|
+
* ```typescript
|
|
1713
|
+
* export default function(api: ExtensionAPI) {
|
|
1714
|
+
* // api provides all extension APIs
|
|
1715
|
+
* }
|
|
1716
|
+
* ```
|
|
1717
|
+
*/
|
|
1718
|
+
interface ExtensionAPI {
|
|
1719
|
+
/**
|
|
1720
|
+
* Subscribe to a hook event.
|
|
1721
|
+
*
|
|
1722
|
+
* @param eventType - Hook type, e.g. "before_tool_call"
|
|
1723
|
+
* @param handler - Hook handler, can return result to modify behavior
|
|
1724
|
+
*/
|
|
1725
|
+
on<K extends HookEventType>(eventType: K, handler: HookHandler<K>): void;
|
|
1726
|
+
/** Unsubscribe from a hook event. */
|
|
1727
|
+
off<K extends HookEventType>(eventType: K, handler: HookHandler<K>): void;
|
|
1728
|
+
/** Tool capabilities — register and unregister custom tools. */
|
|
1729
|
+
tool: {
|
|
1730
|
+
/** Register a custom LLM-callable tool. */
|
|
1731
|
+
register(tool: ToolDefinition): void;
|
|
1732
|
+
/** Unregister a previously registered tool by name. */
|
|
1733
|
+
unregister(toolName: string): void;
|
|
1734
|
+
};
|
|
1735
|
+
/** Register a model provider. */
|
|
1736
|
+
registerProvider(config: _rowan_agent_models.ProviderConfig): void;
|
|
1737
|
+
/** Unregister a model provider. */
|
|
1738
|
+
unregisterProvider(name: string): void;
|
|
1739
|
+
/** Extension manifest from package.json `rowan` field. */
|
|
1740
|
+
manifest?: ExtensionManifest;
|
|
1741
|
+
/** Utility functions. */
|
|
1742
|
+
utils: ExtensionUtils;
|
|
1743
|
+
/** Runtime context — cwd, signal, exec, message access, etc. */
|
|
1744
|
+
context: ExtensionContext;
|
|
1745
|
+
/** Shared event bus for inter-extension communication. */
|
|
1746
|
+
events: EventBus;
|
|
1747
|
+
/** Phase execution capabilities — provides Phase In/Out, phase identity, phase routing, and registration. */
|
|
1748
|
+
phase: {
|
|
1749
|
+
/** Register a Phase directory bundle or Phase object. */
|
|
1750
|
+
register(phase: PhaseRegistration): Promise<void>;
|
|
1751
|
+
/** Unregister a previously registered phase by name. */
|
|
1752
|
+
unregister(phaseName: string): void;
|
|
1753
|
+
/** Phase In: get payload from previous phase */
|
|
1754
|
+
getPayload(): unknown;
|
|
1755
|
+
/** Phase Out: set payload for next phase */
|
|
1756
|
+
setPayload(payload: unknown): void;
|
|
1757
|
+
/** Phase Out: set outcome message */
|
|
1758
|
+
setMessage(message: string): void;
|
|
1759
|
+
/** Get current phase name */
|
|
1760
|
+
getCurrentPhase(): string;
|
|
1761
|
+
/** Set next phase (lower priority than PHASE.md target) */
|
|
1762
|
+
setNextPhase(phaseName: string): void;
|
|
1763
|
+
/** Get the next phase set by setNextPhase */
|
|
1764
|
+
getNextPhase(): string | undefined;
|
|
1765
|
+
/** Get the message set by setMessage */
|
|
1766
|
+
getMessage(): string | undefined;
|
|
1767
|
+
/** Phase Settings contributions registered by the Phase extension. */
|
|
1768
|
+
settings: {
|
|
1769
|
+
register(provider: PhaseSettingsProvider): void;
|
|
1770
|
+
};
|
|
1771
|
+
};
|
|
1772
|
+
}
|
|
1773
|
+
/**
|
|
1774
|
+
* Extension factory function.
|
|
1775
|
+
* Receives ExtensionAPI for registering hooks, phases, and providers.
|
|
1776
|
+
*/
|
|
1777
|
+
type ExtensionDisposer = () => void | Promise<void>;
|
|
1778
|
+
type ExtensionFactoryResult = void | ExtensionDisposer;
|
|
1779
|
+
type ExtensionFactory = (api: ExtensionAPI) => ExtensionFactoryResult | Promise<ExtensionFactoryResult>;
|
|
1780
|
+
|
|
1781
|
+
type PhaseStatusState = "running" | "completed";
|
|
1782
|
+
/** Normalized status event exposed to Runtime consumers. */
|
|
1783
|
+
type PhaseStatus = Readonly<{
|
|
1784
|
+
state: PhaseStatusState;
|
|
1785
|
+
/** Stable consumer-facing status identifier, e.g. `compacting`. */
|
|
1786
|
+
kind: string;
|
|
1787
|
+
/** Optional human-readable detail for UI/status consumers. */
|
|
1788
|
+
message?: string;
|
|
1789
|
+
/** Structured status payload. */
|
|
1790
|
+
payload?: unknown;
|
|
1783
1791
|
}>;
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
+
/** Unified phase output — model-driven routing is optional; programmatic phases may normalize omission to stop. */
|
|
1793
|
+
type PhaseOutput = {
|
|
1794
|
+
/** User-visible assistant message. */
|
|
1795
|
+
message?: string;
|
|
1796
|
+
/** Final status update for non-conversational consumers. */
|
|
1797
|
+
status?: PhaseStatus;
|
|
1798
|
+
/** Route to next phase, or "continue" to re-execute current phase, or "stop" to end. Undefined means no model route. */
|
|
1799
|
+
route?: string;
|
|
1800
|
+
/** Phase name that produced this output */
|
|
1801
|
+
phase?: string;
|
|
1802
|
+
/** Tool calls from the model invocation (used by framework for route extraction) */
|
|
1803
|
+
toolCalls?: Array<{
|
|
1804
|
+
id: string;
|
|
1805
|
+
name: string;
|
|
1806
|
+
args: unknown;
|
|
1792
1807
|
}>;
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1808
|
+
/** Route reason extracted from route tool call (for hooks to inspect) */
|
|
1809
|
+
routeReason?: string;
|
|
1810
|
+
/** Structured data from this phase, passed to the next phase */
|
|
1811
|
+
payload?: unknown;
|
|
1812
|
+
};
|
|
1813
|
+
/** Phase machine state — tracks position and inter-phase data */
|
|
1814
|
+
interface PhaseState {
|
|
1815
|
+
current: string;
|
|
1816
|
+
available: string[];
|
|
1817
|
+
iterations: number;
|
|
1818
|
+
payload?: unknown;
|
|
1819
|
+
}
|
|
1820
|
+
type PhaseInvocation = {
|
|
1821
|
+
mode: "serial";
|
|
1822
|
+
instanceId: string;
|
|
1823
|
+
} | {
|
|
1824
|
+
mode: "parallel";
|
|
1825
|
+
instanceId: string;
|
|
1826
|
+
groupId: string;
|
|
1827
|
+
index: number;
|
|
1828
|
+
count: number;
|
|
1829
|
+
sourcePhaseId: string;
|
|
1830
|
+
};
|
|
1831
|
+
/** Durable identity of the Run execution currently invoking a Phase. */
|
|
1832
|
+
type PhaseExecutionIdentity = Readonly<{
|
|
1833
|
+
agentId: string;
|
|
1834
|
+
runId: string;
|
|
1835
|
+
executionId: string;
|
|
1836
|
+
/** Original durable Run input, before any Phase-local interpretation. */
|
|
1837
|
+
input?: UserContent;
|
|
1838
|
+
/** Opaque metadata captured at the durable boundary; Rowan does not decode it. */
|
|
1839
|
+
agentMetadata?: Readonly<Record<string, unknown>>;
|
|
1840
|
+
runMetadata?: Readonly<Record<string, unknown>>;
|
|
1823
1841
|
}>;
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1842
|
+
/** Everything a phase needs to execute */
|
|
1843
|
+
interface PhaseContext {
|
|
1844
|
+
systemPrompt: string;
|
|
1845
|
+
messages: AgentMessage[];
|
|
1846
|
+
/** Phase-filtered tools */
|
|
1847
|
+
tools: Tool[];
|
|
1848
|
+
/** Phase-filtered skills */
|
|
1849
|
+
skills: Skill[];
|
|
1850
|
+
/** Phase machine state */
|
|
1851
|
+
state: PhaseState;
|
|
1852
|
+
/** Identity and dispatch metadata for this phase execution */
|
|
1853
|
+
readonly invocation: PhaseInvocation;
|
|
1854
|
+
/** Durable Run identity for cross-store integrations and idempotent commands. */
|
|
1855
|
+
readonly execution: PhaseExecutionIdentity;
|
|
1856
|
+
/** Additional guideline bullets appended to the system prompt */
|
|
1857
|
+
promptGuidelines?: string[];
|
|
1858
|
+
/** Text to append after the system prompt */
|
|
1859
|
+
appendSystemPrompt?: string;
|
|
1860
|
+
}
|
|
1861
|
+
/** JSON-safe structural defaults declared by a Phase's `input` mapping. */
|
|
1862
|
+
type PhaseInput = Readonly<Record<string, JsonValue>>;
|
|
1863
|
+
/** JSON-safe option metadata exposed by a Phase to a host Settings surface. */
|
|
1864
|
+
interface PhaseSettingsOption {
|
|
1865
|
+
value: string;
|
|
1866
|
+
label: string;
|
|
1867
|
+
description?: string;
|
|
1868
|
+
disabled?: boolean;
|
|
1869
|
+
}
|
|
1870
|
+
interface PhaseSettingsBadge {
|
|
1871
|
+
label: string;
|
|
1872
|
+
tone?: "neutral" | "success" | "review" | "danger";
|
|
1873
|
+
}
|
|
1874
|
+
interface PhaseSettingsItem {
|
|
1875
|
+
id: string;
|
|
1876
|
+
title: string;
|
|
1877
|
+
description?: string;
|
|
1878
|
+
badges?: readonly PhaseSettingsBadge[];
|
|
1879
|
+
}
|
|
1880
|
+
type PhaseSettingsControl = {
|
|
1881
|
+
type: "boolean";
|
|
1882
|
+
path: string;
|
|
1883
|
+
label: string;
|
|
1884
|
+
description?: string;
|
|
1827
1885
|
} | {
|
|
1828
|
-
|
|
1829
|
-
|
|
1886
|
+
type: "number";
|
|
1887
|
+
path: string;
|
|
1888
|
+
label: string;
|
|
1889
|
+
description?: string;
|
|
1890
|
+
min?: number;
|
|
1891
|
+
max?: number;
|
|
1892
|
+
step?: number;
|
|
1893
|
+
unit?: string;
|
|
1894
|
+
scale?: number;
|
|
1830
1895
|
} | {
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
token: string;
|
|
1896
|
+
type: "select";
|
|
1897
|
+
path: string;
|
|
1898
|
+
label: string;
|
|
1899
|
+
description?: string;
|
|
1900
|
+
options: readonly PhaseSettingsOption[];
|
|
1837
1901
|
} | {
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1902
|
+
type: "text";
|
|
1903
|
+
path: string;
|
|
1904
|
+
label: string;
|
|
1905
|
+
description?: string;
|
|
1906
|
+
placeholder?: string;
|
|
1907
|
+
format?: "string" | "string-array" | "key-value";
|
|
1908
|
+
multiline?: boolean;
|
|
1909
|
+
} | {
|
|
1910
|
+
type: "collection";
|
|
1911
|
+
path: string;
|
|
1912
|
+
label: string;
|
|
1913
|
+
description?: string;
|
|
1914
|
+
items: readonly PhaseSettingsItem[];
|
|
1915
|
+
fields: readonly PhaseSettingsControl[];
|
|
1916
|
+
add?: {
|
|
1917
|
+
label: string;
|
|
1918
|
+
idLabel?: string;
|
|
1919
|
+
fields: readonly PhaseSettingsControl[];
|
|
1920
|
+
};
|
|
1921
|
+
removeLabel?: string;
|
|
1922
|
+
};
|
|
1923
|
+
interface PhaseSettingsSection {
|
|
1924
|
+
id: string;
|
|
1925
|
+
title: string;
|
|
1926
|
+
description?: string;
|
|
1927
|
+
controls: readonly PhaseSettingsControl[];
|
|
1854
1928
|
}
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
checkpoint: ExecutionCheckpoint;
|
|
1912
|
-
interactions?: readonly PhaseInteraction[];
|
|
1913
|
-
interactionAnswers?: Readonly<Record<string, JsonValue>>;
|
|
1914
|
-
}): Promise<InputRequiredCommit>;
|
|
1915
|
-
answerInput(input: {
|
|
1916
|
-
runId: RunId;
|
|
1917
|
-
requestId: InputRequestId;
|
|
1918
|
-
expectedRevision: number;
|
|
1919
|
-
input: UserInput;
|
|
1920
|
-
messageId?: MessageId;
|
|
1921
|
-
}): Promise<RunRecord>;
|
|
1922
|
-
answerInteraction(input: {
|
|
1923
|
-
runId: RunId;
|
|
1924
|
-
interactionId: string;
|
|
1925
|
-
expectedRevision: number;
|
|
1926
|
-
input: JsonValue;
|
|
1927
|
-
}): Promise<RunRecord>;
|
|
1928
|
-
commitOutcome(input: {
|
|
1929
|
-
runId: RunId;
|
|
1930
|
-
execution: ExecutionToken;
|
|
1931
|
-
expectedRevision: number;
|
|
1932
|
-
outcome?: Outcome;
|
|
1933
|
-
failure?: RunFailure;
|
|
1934
|
-
output?: AssistantMessage;
|
|
1935
|
-
}): Promise<RunRecord>;
|
|
1936
|
-
reserveToolCall(input: {
|
|
1937
|
-
runId: RunId;
|
|
1938
|
-
execution: ExecutionToken;
|
|
1939
|
-
expectedRevision: number;
|
|
1940
|
-
requestMessageId: MessageId;
|
|
1941
|
-
name: string;
|
|
1942
|
-
args: JsonValue;
|
|
1943
|
-
toolCallId?: ToolCallId;
|
|
1944
|
-
providerToolCallId?: string;
|
|
1945
|
-
}): Promise<ToolCommit>;
|
|
1946
|
-
reserveToolCalls(input: {
|
|
1947
|
-
runId: RunId;
|
|
1948
|
-
execution: ExecutionToken;
|
|
1949
|
-
expectedRevision: number;
|
|
1950
|
-
requestMessageId: MessageId;
|
|
1951
|
-
calls: readonly ToolCallReservation[];
|
|
1952
|
-
}): Promise<ToolBatchCommit>;
|
|
1953
|
-
startToolCall(input: {
|
|
1954
|
-
runId: RunId;
|
|
1955
|
-
execution: ExecutionToken;
|
|
1956
|
-
expectedRevision: number;
|
|
1957
|
-
toolCallId: ToolCallId;
|
|
1958
|
-
}): Promise<ToolCommit>;
|
|
1959
|
-
commitToolResult(input: {
|
|
1960
|
-
runId: RunId;
|
|
1961
|
-
execution: ExecutionToken;
|
|
1962
|
-
expectedRevision: number;
|
|
1963
|
-
toolCallId: ToolCallId;
|
|
1964
|
-
result: ToolExecutionResult$1;
|
|
1965
|
-
state: "completed" | "failed" | "indeterminate";
|
|
1966
|
-
reason?: string;
|
|
1967
|
-
}): Promise<ToolCommit>;
|
|
1968
|
-
cancelRun(input: {
|
|
1969
|
-
runId: RunId;
|
|
1970
|
-
expectedRevision?: number;
|
|
1971
|
-
reason?: string;
|
|
1972
|
-
output?: AssistantMessage;
|
|
1973
|
-
}): Promise<RunRecord>;
|
|
1974
|
-
snapshotRun(runId: RunId): Promise<RunSnapshot>;
|
|
1975
|
-
history(agentId: AgentId): Promise<readonly Message[]>;
|
|
1976
|
-
listAgents(): Promise<readonly AgentRecord[]>;
|
|
1977
|
-
listRuns(input?: {
|
|
1978
|
-
agentId?: AgentId;
|
|
1979
|
-
states?: readonly RunState[];
|
|
1980
|
-
}): Promise<readonly RunRecord[]>;
|
|
1981
|
-
listEvents(input?: {
|
|
1982
|
-
after?: EventCursor;
|
|
1983
|
-
}): Promise<readonly DurableRunEvent[]>;
|
|
1984
|
-
openConsumer(consumerId: string): Promise<ConsumerRegistration>;
|
|
1985
|
-
advanceConsumerCheckpoint(input: {
|
|
1986
|
-
consumerId: string;
|
|
1987
|
-
cursor: EventCursor;
|
|
1988
|
-
}): Promise<void>;
|
|
1989
|
-
renewOwner(leaseMs: number): Promise<OwnerLease>;
|
|
1990
|
-
sealAndReleaseOwner(): Promise<void>;
|
|
1929
|
+
/** Declarative, host-neutral Settings surface contributed by a Phase. */
|
|
1930
|
+
interface PhaseSettingsDefinition {
|
|
1931
|
+
description?: string;
|
|
1932
|
+
sections: readonly PhaseSettingsSection[];
|
|
1933
|
+
}
|
|
1934
|
+
/** Host context is intentionally opaque beyond the effective configuration. */
|
|
1935
|
+
interface PhaseSettingsContext {
|
|
1936
|
+
configuration: Readonly<Record<string, unknown>>;
|
|
1937
|
+
metadata?: Readonly<Record<string, unknown>>;
|
|
1938
|
+
}
|
|
1939
|
+
type PhaseSettingsProvider = (context: PhaseSettingsContext) => PhaseSettingsDefinition | Promise<PhaseSettingsDefinition>;
|
|
1940
|
+
/**
|
|
1941
|
+
* Loaded Phase object
|
|
1942
|
+
*/
|
|
1943
|
+
interface Phase {
|
|
1944
|
+
/** Unique phase identity and display name. */
|
|
1945
|
+
name: string;
|
|
1946
|
+
/** Rowan-owned built-in Phase; built-ins are never filtered or disabled. */
|
|
1947
|
+
core?: boolean;
|
|
1948
|
+
/** Description */
|
|
1949
|
+
description: string;
|
|
1950
|
+
/** Restricted tools (undefined = all tools available) */
|
|
1951
|
+
tools?: string[];
|
|
1952
|
+
/** Skills bundled directly inside this phase directory. Inline phases may omit this (equivalent to []). */
|
|
1953
|
+
skills?: Skill[];
|
|
1954
|
+
/** Forced next phase */
|
|
1955
|
+
target?: string;
|
|
1956
|
+
/** Structural JSON-safe input defaults */
|
|
1957
|
+
input?: PhaseInput;
|
|
1958
|
+
/** If true, phase gets a fresh context when executed in parallel */
|
|
1959
|
+
isolated?: boolean;
|
|
1960
|
+
/** Path to PHASE.md file */
|
|
1961
|
+
filePath: string;
|
|
1962
|
+
/** Phase directory path */
|
|
1963
|
+
baseDir: string;
|
|
1964
|
+
/** PHASE.md body content */
|
|
1965
|
+
content: string;
|
|
1966
|
+
/** Model override for this phase (resolved from frontmatter) */
|
|
1967
|
+
model?: ModelRef;
|
|
1968
|
+
/** Do not automatically inject this Phase into the model route catalog/context. */
|
|
1969
|
+
disableAutoInvocation?: boolean;
|
|
1970
|
+
/** Do not expose this Phase to direct user invocation. */
|
|
1971
|
+
disableImplicitInvocation?: boolean;
|
|
1972
|
+
/** ExtensionAPI factory function used for registration or programmatic execution. */
|
|
1973
|
+
factory?: (api: ExtensionAPI) => Promise<void>;
|
|
1974
|
+
/** Direct run function */
|
|
1975
|
+
run?: (context: PhaseContext, execution: PhaseExecution) => Promise<PhaseOutput | void>;
|
|
1976
|
+
}
|
|
1977
|
+
/**
|
|
1978
|
+
* Phase registry containing all loaded phases
|
|
1979
|
+
*/
|
|
1980
|
+
interface PhaseRegistry {
|
|
1981
|
+
/** Map of phase name to Phase object */
|
|
1982
|
+
phases: Map<string, Phase>;
|
|
1983
|
+
/** Entry phase name (null until Agent applies its default phase) */
|
|
1984
|
+
entryPhaseId: string | null;
|
|
1991
1985
|
}
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1986
|
+
|
|
1987
|
+
interface BeforePhaseEvent {
|
|
1988
|
+
type: "before_phase";
|
|
1989
|
+
phaseId: string;
|
|
1990
|
+
input: PhaseContext;
|
|
1997
1991
|
}
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
bootstrap?: (registry: RuntimeBootstrapRegistry) => void | Promise<void>;
|
|
2003
|
-
}>;
|
|
2004
|
-
type DurableConsumer = Readonly<{
|
|
2005
|
-
caughtUp: Promise<void>;
|
|
2006
|
-
done: Promise<void>;
|
|
2007
|
-
stop(): void;
|
|
2008
|
-
}>;
|
|
2009
|
-
interface AgentRun {
|
|
2010
|
-
readonly id: RunId;
|
|
2011
|
-
snapshot(): Promise<RunSnapshot>;
|
|
2012
|
-
observe(options?: {
|
|
2013
|
-
after?: EventCursor;
|
|
2014
|
-
signal?: AbortSignal;
|
|
2015
|
-
}): AsyncIterable<RunEvent>;
|
|
2016
|
-
wait(options?: {
|
|
2017
|
-
signal?: AbortSignal;
|
|
2018
|
-
}): Promise<RunBoundary>;
|
|
2019
|
-
respond(input: {
|
|
2020
|
-
requestId: InputRequestId;
|
|
2021
|
-
input: UserInput;
|
|
2022
|
-
}): Promise<void>;
|
|
2023
|
-
respondInteraction(input: {
|
|
2024
|
-
interactionId: string;
|
|
2025
|
-
input: JsonValue;
|
|
2026
|
-
}): Promise<void>;
|
|
2027
|
-
cancel(reason?: string): Promise<RunBoundary>;
|
|
1992
|
+
interface AfterPhaseEvent {
|
|
1993
|
+
type: "after_phase";
|
|
1994
|
+
phaseId: string;
|
|
1995
|
+
output: PhaseOutput;
|
|
2028
1996
|
}
|
|
2029
|
-
interface
|
|
2030
|
-
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
loadTools(input: Readonly<{
|
|
2034
|
-
sourceId: string;
|
|
2035
|
-
values: readonly Tool[];
|
|
2036
|
-
}>): Promise<LoadResult>;
|
|
2037
|
-
unload(input: Readonly<{
|
|
2038
|
-
kind: ResourceKind;
|
|
2039
|
-
sourceId: string;
|
|
2040
|
-
}>): Promise<LoadResult>;
|
|
2041
|
-
createAgent(config: AgentConfiguration, options?: {
|
|
2042
|
-
idempotencyKey?: string;
|
|
2043
|
-
metadata?: Metadata;
|
|
2044
|
-
historySeed?: HistorySeed;
|
|
2045
|
-
}): Promise<AgentId>;
|
|
2046
|
-
updateAgentConfig(agentId: AgentId, config: AgentConfiguration, options: {
|
|
2047
|
-
idempotencyKey: string;
|
|
2048
|
-
}): Promise<void>;
|
|
2049
|
-
deleteAgent(input: AgentDeletionRequest): Promise<void>;
|
|
2050
|
-
revise(agentId: AgentId, input: {
|
|
2051
|
-
messageId: MessageId;
|
|
2052
|
-
expectedMessageRevision: number;
|
|
2053
|
-
content: UserContent;
|
|
2054
|
-
operationId: string;
|
|
2055
|
-
effectDigestConfirmation?: string;
|
|
2056
|
-
}): Promise<MessageRevisionResult>;
|
|
2057
|
-
compact(input?: {
|
|
2058
|
-
now?: string;
|
|
2059
|
-
retentionMs?: number;
|
|
2060
|
-
}): Promise<RetentionResult>;
|
|
2061
|
-
start(agentId: AgentId, input: UserInput, options: {
|
|
2062
|
-
idempotencyKey: string;
|
|
2063
|
-
metadata?: Metadata;
|
|
2064
|
-
}): Promise<AgentRun>;
|
|
2065
|
-
run(runId: RunId): AgentRun;
|
|
2066
|
-
contextStatus(agentId: AgentId, options?: {
|
|
2067
|
-
contextWindow?: number;
|
|
2068
|
-
}): Promise<ContextStatus>;
|
|
2069
|
-
compactContext(agentId: AgentId, options?: {
|
|
2070
|
-
input?: UserInput;
|
|
2071
|
-
instructions?: string;
|
|
2072
|
-
idempotencyKey?: string;
|
|
2073
|
-
}): Promise<AgentRun>;
|
|
2074
|
-
listInvocations(agentId: AgentId, options: {
|
|
2075
|
-
source: InvocationSource;
|
|
2076
|
-
}): Promise<readonly InvocationCatalogEntry[]>;
|
|
2077
|
-
history(agentId: AgentId): Promise<readonly Message[]>;
|
|
2078
|
-
listAgents(input?: {
|
|
2079
|
-
after?: AgentListCursor;
|
|
2080
|
-
limit?: number;
|
|
2081
|
-
}): Promise<Page<AgentSummary, AgentListCursor>>;
|
|
2082
|
-
listRuns(input?: {
|
|
2083
|
-
agentId?: AgentId;
|
|
2084
|
-
states?: readonly RunState[];
|
|
2085
|
-
after?: RunListCursor;
|
|
2086
|
-
limit?: number;
|
|
2087
|
-
}): Promise<Page<RunSummary, RunListCursor>>;
|
|
2088
|
-
consume(input: {
|
|
2089
|
-
consumerId: string;
|
|
2090
|
-
signal: AbortSignal;
|
|
2091
|
-
onEvent(event: DurableRunEvent, context: Readonly<{
|
|
2092
|
-
signal: AbortSignal;
|
|
2093
|
-
}>): void | Promise<void>;
|
|
2094
|
-
}): Promise<DurableConsumer>;
|
|
2095
|
-
close(): Promise<void>;
|
|
1997
|
+
interface BeforePromptEvent {
|
|
1998
|
+
type: "before_prompt";
|
|
1999
|
+
phaseId: string;
|
|
2000
|
+
input: PhaseContext;
|
|
2096
2001
|
}
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
|
|
2002
|
+
interface BeforeToolCallEvent {
|
|
2003
|
+
type: "before_tool_call";
|
|
2004
|
+
tool: Tool;
|
|
2005
|
+
args: unknown;
|
|
2006
|
+
readonly runId?: string;
|
|
2007
|
+
readonly agentId?: string;
|
|
2008
|
+
readonly toolCallId?: string;
|
|
2009
|
+
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
2010
|
+
readonly answer?: unknown;
|
|
2011
|
+
}
|
|
2012
|
+
interface AfterToolCallEvent {
|
|
2013
|
+
type: "after_tool_call";
|
|
2014
|
+
tool: Tool;
|
|
2015
|
+
result: ToolResult;
|
|
2016
|
+
readonly runId?: string;
|
|
2017
|
+
readonly agentId?: string;
|
|
2018
|
+
readonly toolCallId?: string;
|
|
2019
|
+
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
2020
|
+
}
|
|
2021
|
+
type HookEvent = BeforePhaseEvent | AfterPhaseEvent | BeforePromptEvent | BeforeToolCallEvent | AfterToolCallEvent;
|
|
2022
|
+
interface BeforePhaseResult {
|
|
2023
|
+
abort?: Outcome$1;
|
|
2024
|
+
skip?: {
|
|
2025
|
+
route: string;
|
|
2026
|
+
message: string;
|
|
2027
|
+
};
|
|
2028
|
+
input?: PhaseContext;
|
|
2029
|
+
}
|
|
2030
|
+
interface AfterPhaseResult {
|
|
2031
|
+
abort?: Outcome$1;
|
|
2032
|
+
retry?: PhaseContext;
|
|
2033
|
+
output?: PhaseOutput;
|
|
2034
|
+
}
|
|
2035
|
+
interface BeforePromptResult {
|
|
2036
|
+
input?: PhaseContext;
|
|
2037
|
+
}
|
|
2038
|
+
interface BeforeToolCallResult {
|
|
2039
|
+
allow?: boolean;
|
|
2040
|
+
reason?: string;
|
|
2041
|
+
interaction?: RunInteractionRequest;
|
|
2042
|
+
}
|
|
2043
|
+
interface AfterToolCallResult {
|
|
2044
|
+
result?: ToolResult;
|
|
2045
|
+
}
|
|
2046
|
+
interface HookResultMap {
|
|
2047
|
+
before_phase: BeforePhaseResult | undefined;
|
|
2048
|
+
after_phase: AfterPhaseResult | undefined;
|
|
2049
|
+
before_prompt: BeforePromptResult | undefined;
|
|
2050
|
+
before_tool_call: BeforeToolCallResult | undefined;
|
|
2051
|
+
after_tool_call: AfterToolCallResult | undefined;
|
|
2052
|
+
}
|
|
2053
|
+
type HookEventType = HookEvent["type"];
|
|
2054
|
+
type HookHandler<K extends HookEventType> = (event: Extract<HookEvent, {
|
|
2055
|
+
type: K;
|
|
2056
|
+
}>) => HookResultMap[K] | Promise<HookResultMap[K]> | void | Promise<void>;
|
|
2057
|
+
declare class HooksManager {
|
|
2058
|
+
private handlers;
|
|
2059
|
+
on<K extends HookEventType>(eventType: K, handler: HookHandler<K>): void;
|
|
2060
|
+
off<K extends HookEventType>(eventType: K, handler: HookHandler<K>): void;
|
|
2061
|
+
emit<K extends HookEventType>(eventType: K, event: Extract<HookEvent, {
|
|
2062
|
+
type: K;
|
|
2063
|
+
}>): Promise<void>;
|
|
2064
|
+
emitFirst<K extends HookEventType>(eventType: K, event: Extract<HookEvent, {
|
|
2065
|
+
type: K;
|
|
2066
|
+
}>): Promise<HookResultMap[K] | undefined>;
|
|
2067
|
+
}
|
|
2068
|
+
|
|
2069
|
+
type ToolContext = Pick<AgentContext, "skills"> & {
|
|
2070
|
+
toolCallId: string;
|
|
2071
|
+
interaction?: RunInteractionDriver;
|
|
2072
|
+
};
|
|
2073
|
+
type ToolExecutionMode = "sequential" | "parallel";
|
|
2074
|
+
type Tool<TArgs = unknown> = {
|
|
2075
|
+
name: string;
|
|
2076
|
+
/** Rowan-owned Core Tool; Core Tools bypass Phase filtering. */
|
|
2077
|
+
core?: boolean;
|
|
2078
|
+
description: string;
|
|
2079
|
+
parameters: Type.TSchema;
|
|
2080
|
+
/** One-line snippet shown in the system prompt tool list. */
|
|
2081
|
+
promptSnippet?: string;
|
|
2082
|
+
/** Additional guidelines appended to the system prompt when this tool is active. */
|
|
2083
|
+
promptGuidelines?: string[];
|
|
2084
|
+
/** Whether this tool can run concurrently with others. Default: "parallel". */
|
|
2085
|
+
executionMode?: ToolExecutionMode;
|
|
2086
|
+
execute(args: TArgs, context: ToolContext, signal?: AbortSignal): Promise<ToolResult>;
|
|
2087
|
+
};
|
|
2088
|
+
/** Context snapshot passed into the low-level agent loop. */
|
|
2089
|
+
type AgentContext = {
|
|
2090
|
+
/** System prompt included with the request. */
|
|
2091
|
+
systemPrompt: string;
|
|
2092
|
+
/** Transcript visible to the model. */
|
|
2093
|
+
messages: AgentMessage[];
|
|
2094
|
+
/** Tools available for this run. */
|
|
2095
|
+
tools: Tool[];
|
|
2096
|
+
/** Skills available for this run. */
|
|
2097
|
+
skills: Skill[];
|
|
2098
|
+
/** Custom phases for this run. Agent normalizes this with the built-in default phase. */
|
|
2099
|
+
phases?: PhaseRegistry;
|
|
2100
|
+
};
|
|
2101
|
+
|
|
2102
|
+
/**
|
|
2103
|
+
* `root` anchors relative paths and the Bash working directory. It is not a
|
|
2104
|
+
* filesystem sandbox: core Tools use the permissions of the host process.
|
|
2105
|
+
*/
|
|
2106
|
+
type CoreToolContext = {
|
|
2107
|
+
root?: string;
|
|
2108
|
+
/** Directory for complete Tool Result spill files. */
|
|
2109
|
+
archiveDir?: string;
|
|
2110
|
+
maxReadBytes?: number;
|
|
2111
|
+
maxReadLines?: number;
|
|
2112
|
+
bashTimeoutMs?: number;
|
|
2113
|
+
maxBashOutputBytes?: number;
|
|
2114
|
+
};
|
|
2101
2115
|
|
|
2102
2116
|
declare class AgentRuntime implements AgentRuntime$1 {
|
|
2103
2117
|
private readonly concurrency;
|
|
@@ -2123,7 +2137,7 @@ declare class AgentRuntime implements AgentRuntime$1 {
|
|
|
2123
2137
|
loadPhases(input: LoadInput<Phase>): Promise<LoadResult>;
|
|
2124
2138
|
loadTools(input: Readonly<{
|
|
2125
2139
|
sourceId: string;
|
|
2126
|
-
values: readonly Tool[];
|
|
2140
|
+
values: readonly Tool$1[];
|
|
2127
2141
|
}>): Promise<LoadResult>;
|
|
2128
2142
|
unload(input: Readonly<{
|
|
2129
2143
|
kind: ResourceKind;
|
|
@@ -2191,13 +2205,10 @@ declare class AgentRuntime implements AgentRuntime$1 {
|
|
|
2191
2205
|
close(): Promise<void>;
|
|
2192
2206
|
snapshot(runId: RunId): Promise<RunSnapshot>;
|
|
2193
2207
|
history(agentId: AgentId): Promise<readonly Message[]>;
|
|
2194
|
-
respond(runId: RunId, input: {
|
|
2195
|
-
requestId: InputRequestId;
|
|
2196
|
-
input: UserInput;
|
|
2197
|
-
}): Promise<void>;
|
|
2198
2208
|
respondInteraction(runId: RunId, input: {
|
|
2199
2209
|
interactionId: string;
|
|
2200
|
-
input
|
|
2210
|
+
input?: JsonValue;
|
|
2211
|
+
cancel?: boolean;
|
|
2201
2212
|
}): Promise<void>;
|
|
2202
2213
|
cancel(runId: RunId, reason?: string): Promise<RunBoundary>;
|
|
2203
2214
|
private pump;
|
|
@@ -2206,6 +2217,7 @@ declare class AgentRuntime implements AgentRuntime$1 {
|
|
|
2206
2217
|
private resolveContextWindow;
|
|
2207
2218
|
private executeTool;
|
|
2208
2219
|
private executeToolBatch;
|
|
2220
|
+
private foldToolInteractionRecords;
|
|
2209
2221
|
private requireAgent;
|
|
2210
2222
|
private archiveDirFor;
|
|
2211
2223
|
private runConsumer;
|
|
@@ -2298,6 +2310,7 @@ declare class InMemoryStore implements DurableStore {
|
|
|
2298
2310
|
operationId: string;
|
|
2299
2311
|
effectDigestConfirmation?: string;
|
|
2300
2312
|
}): MessageRevisionResult;
|
|
2313
|
+
private commitInteractionRecord;
|
|
2301
2314
|
createRun(lease: OwnerLease, input: {
|
|
2302
2315
|
agentId: AgentId;
|
|
2303
2316
|
input: UserInput;
|
|
@@ -2318,29 +2331,30 @@ declare class InMemoryStore implements DurableStore {
|
|
|
2318
2331
|
code: "configuration_unavailable" | "checkpoint_incompatible";
|
|
2319
2332
|
}>;
|
|
2320
2333
|
}): RunRecord;
|
|
2334
|
+
commitPhaseEntered(lease: OwnerLease, input: {
|
|
2335
|
+
runId: RunId;
|
|
2336
|
+
execution: ExecutionToken;
|
|
2337
|
+
expectedRevision: number;
|
|
2338
|
+
phaseId: string;
|
|
2339
|
+
visit: number;
|
|
2340
|
+
}): RunRecord;
|
|
2321
2341
|
commitInputRequired(lease: OwnerLease, input: {
|
|
2322
2342
|
runId: RunId;
|
|
2323
2343
|
execution: ExecutionToken;
|
|
2324
2344
|
expectedRevision: number;
|
|
2325
|
-
requestId?: InputRequestId;
|
|
2326
2345
|
phase: string;
|
|
2327
2346
|
prompt?: AssistantMessage;
|
|
2328
2347
|
checkpoint: ExecutionCheckpoint;
|
|
2329
|
-
interactions?: readonly
|
|
2348
|
+
interactions?: readonly RunInteraction[];
|
|
2330
2349
|
interactionAnswers?: Readonly<Record<string, JsonValue>>;
|
|
2331
|
-
|
|
2332
|
-
answerInput(lease: OwnerLease, input: {
|
|
2333
|
-
runId: RunId;
|
|
2334
|
-
requestId: InputRequestId;
|
|
2335
|
-
expectedRevision: number;
|
|
2336
|
-
input: UserInput;
|
|
2337
|
-
messageId?: MessageId;
|
|
2350
|
+
pendingToolCallIds?: readonly ToolCallId[];
|
|
2338
2351
|
}): RunRecord;
|
|
2339
2352
|
answerInteraction(lease: OwnerLease, input: {
|
|
2340
2353
|
runId: RunId;
|
|
2341
2354
|
interactionId: string;
|
|
2342
2355
|
expectedRevision: number;
|
|
2343
|
-
input
|
|
2356
|
+
input?: JsonValue;
|
|
2357
|
+
cancel?: boolean;
|
|
2344
2358
|
}): RunRecord;
|
|
2345
2359
|
reserveToolCall(lease: OwnerLease, input: {
|
|
2346
2360
|
runId: RunId;
|
|
@@ -2370,6 +2384,12 @@ declare class InMemoryStore implements DurableStore {
|
|
|
2370
2384
|
expectedRevision: number;
|
|
2371
2385
|
toolCallId: ToolCallId;
|
|
2372
2386
|
}): ToolCommit;
|
|
2387
|
+
suspendToolCall(lease: OwnerLease, input: {
|
|
2388
|
+
runId: RunId;
|
|
2389
|
+
execution: ExecutionToken;
|
|
2390
|
+
expectedRevision: number;
|
|
2391
|
+
toolCallId: ToolCallId;
|
|
2392
|
+
}): ToolCommit;
|
|
2373
2393
|
commitToolResult(lease: OwnerLease, input: {
|
|
2374
2394
|
runId: RunId;
|
|
2375
2395
|
execution: ExecutionToken;
|
|
@@ -2514,29 +2534,30 @@ declare class SqliteStore implements DurableStore {
|
|
|
2514
2534
|
code: "configuration_unavailable" | "checkpoint_incompatible";
|
|
2515
2535
|
}>;
|
|
2516
2536
|
}): Promise<RunRecord>;
|
|
2537
|
+
commitPhaseEntered(lease: OwnerLease, input: {
|
|
2538
|
+
runId: RunId;
|
|
2539
|
+
execution: ExecutionToken;
|
|
2540
|
+
expectedRevision: number;
|
|
2541
|
+
phaseId: string;
|
|
2542
|
+
visit: number;
|
|
2543
|
+
}): Promise<RunRecord>;
|
|
2517
2544
|
commitInputRequired(lease: OwnerLease, input: {
|
|
2518
2545
|
runId: RunId;
|
|
2519
2546
|
execution: ExecutionToken;
|
|
2520
2547
|
expectedRevision: number;
|
|
2521
|
-
requestId?: InputRequestId;
|
|
2522
2548
|
phase: string;
|
|
2523
2549
|
prompt?: AssistantMessage;
|
|
2524
2550
|
checkpoint: ExecutionCheckpoint;
|
|
2525
|
-
interactions?: readonly
|
|
2551
|
+
interactions?: readonly RunInteraction[];
|
|
2526
2552
|
interactionAnswers?: Readonly<Record<string, JsonValue>>;
|
|
2527
|
-
|
|
2528
|
-
answerInput(lease: OwnerLease, input: {
|
|
2529
|
-
runId: RunId;
|
|
2530
|
-
requestId: InputRequestId;
|
|
2531
|
-
expectedRevision: number;
|
|
2532
|
-
input: UserInput;
|
|
2533
|
-
messageId?: MessageId;
|
|
2553
|
+
pendingToolCallIds?: readonly ToolCallId[];
|
|
2534
2554
|
}): Promise<RunRecord>;
|
|
2535
2555
|
answerInteraction(lease: OwnerLease, input: {
|
|
2536
2556
|
runId: RunId;
|
|
2537
2557
|
interactionId: string;
|
|
2538
2558
|
expectedRevision: number;
|
|
2539
|
-
input
|
|
2559
|
+
input?: JsonValue;
|
|
2560
|
+
cancel?: boolean;
|
|
2540
2561
|
}): Promise<RunRecord>;
|
|
2541
2562
|
commitOutcome(lease: OwnerLease, input: {
|
|
2542
2563
|
runId: RunId;
|
|
@@ -2574,6 +2595,12 @@ declare class SqliteStore implements DurableStore {
|
|
|
2574
2595
|
expectedRevision: number;
|
|
2575
2596
|
toolCallId: ToolCallId;
|
|
2576
2597
|
}): Promise<ToolCommit>;
|
|
2598
|
+
suspendToolCall(lease: OwnerLease, input: {
|
|
2599
|
+
runId: RunId;
|
|
2600
|
+
execution: ExecutionToken;
|
|
2601
|
+
expectedRevision: number;
|
|
2602
|
+
toolCallId: ToolCallId;
|
|
2603
|
+
}): Promise<ToolCommit>;
|
|
2577
2604
|
commitToolResult(lease: OwnerLease, input: {
|
|
2578
2605
|
runId: RunId;
|
|
2579
2606
|
execution: ExecutionToken;
|
|
@@ -2699,7 +2726,8 @@ type RuntimeErrorDetails = {
|
|
|
2699
2726
|
}>;
|
|
2700
2727
|
input_request_conflict: Readonly<{
|
|
2701
2728
|
runId: RunId;
|
|
2702
|
-
|
|
2729
|
+
interactionId?: string;
|
|
2730
|
+
requestId?: string;
|
|
2703
2731
|
reason: "not_found" | "wrong_run" | "different_answer";
|
|
2704
2732
|
}>;
|
|
2705
2733
|
idempotency_conflict: Readonly<{
|
|
@@ -2816,6 +2844,6 @@ interface FrontmatterResult<T = Record<string, unknown>> {
|
|
|
2816
2844
|
*/
|
|
2817
2845
|
declare function parseFrontmatter<T = Record<string, unknown>>(raw: string): FrontmatterResult<T>;
|
|
2818
2846
|
|
|
2819
|
-
declare function createCoreTools(input?: CoreToolContext): Tool[];
|
|
2847
|
+
declare function createCoreTools(input?: CoreToolContext): Tool$1[];
|
|
2820
2848
|
|
|
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
|
|
2849
|
+
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 InteractionRecord, 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 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 RunInteraction, RunInteractionBoundary, RunInteractionCancelledError, type RunInteractionDriver, type RunInteractionKind, type RunInteractionRequest, type RunInteractionState, type RunInteractionStatus, 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$1 as 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 };
|