@rowan-agent/agent 0.8.0 → 0.8.2
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 +18 -11
- package/dist/index.js +28 -11
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -84,7 +84,7 @@ JSON-safe value. Progress is live-only and may be dropped.
|
|
|
84
84
|
|
|
85
85
|
- transient `message_delta` and `tool_progress` events are live-only and
|
|
86
86
|
best-effort;
|
|
87
|
-
- durable `message_committed`, `
|
|
87
|
+
- durable `message_committed`, `run_state_changed`, and `tool_state_changed`
|
|
88
88
|
events are replayable;
|
|
89
89
|
- a durable `message_committed` event is the authoritative full content if a
|
|
90
90
|
transient delta was coalesced or dropped.
|
|
@@ -92,7 +92,7 @@ JSON-safe value. Progress is live-only and may be dropped.
|
|
|
92
92
|
`runtime.consume()` delivers only `DurableRunEvent` values:
|
|
93
93
|
|
|
94
94
|
- `message_committed`
|
|
95
|
-
- `
|
|
95
|
+
- `run_state_changed`
|
|
96
96
|
- `tool_state_changed`
|
|
97
97
|
|
|
98
98
|
Durable events and their corresponding Run aggregate changes commit in one
|
package/dist/index.d.ts
CHANGED
|
@@ -747,44 +747,45 @@ type MessageCommitted = DurableEventBase & Readonly<{
|
|
|
747
747
|
kind: "message_committed";
|
|
748
748
|
message: Message;
|
|
749
749
|
}>;
|
|
750
|
-
type
|
|
751
|
-
kind: "
|
|
750
|
+
type RunStateChanged = DurableEventBase & (Readonly<{
|
|
751
|
+
kind: "run_state_changed";
|
|
752
752
|
from: null;
|
|
753
753
|
to: "queued";
|
|
754
754
|
}> | Readonly<{
|
|
755
|
-
kind: "
|
|
755
|
+
kind: "run_state_changed";
|
|
756
756
|
from: "input_required";
|
|
757
757
|
to: "queued";
|
|
758
758
|
}> | Readonly<{
|
|
759
|
-
kind: "
|
|
759
|
+
kind: "run_state_changed";
|
|
760
760
|
from: "queued";
|
|
761
761
|
to: "running";
|
|
762
762
|
}> | Readonly<{
|
|
763
|
-
kind: "
|
|
763
|
+
kind: "run_state_changed";
|
|
764
764
|
from: "running";
|
|
765
765
|
to: "input_required";
|
|
766
766
|
request: Readonly<{
|
|
767
767
|
id: InputRequestId;
|
|
768
|
+
phase: string;
|
|
768
769
|
prompt: AssistantMessage;
|
|
769
770
|
}>;
|
|
770
771
|
}> | Readonly<{
|
|
771
|
-
kind: "
|
|
772
|
+
kind: "run_state_changed";
|
|
772
773
|
from: "running";
|
|
773
774
|
to: "completed";
|
|
774
775
|
outcome: Outcome;
|
|
775
776
|
output?: AssistantMessage;
|
|
776
777
|
}> | Readonly<{
|
|
777
|
-
kind: "
|
|
778
|
+
kind: "run_state_changed";
|
|
778
779
|
from: "queued";
|
|
779
780
|
to: "failed";
|
|
780
781
|
failure: QueuedRunFailure;
|
|
781
782
|
}> | Readonly<{
|
|
782
|
-
kind: "
|
|
783
|
+
kind: "run_state_changed";
|
|
783
784
|
from: "running";
|
|
784
785
|
to: "failed";
|
|
785
786
|
failure: RunningRunFailure;
|
|
786
787
|
}> | Readonly<{
|
|
787
|
-
kind: "
|
|
788
|
+
kind: "run_state_changed";
|
|
788
789
|
from: "queued" | "running" | "input_required";
|
|
789
790
|
to: "cancelled";
|
|
790
791
|
reason?: string;
|
|
@@ -844,7 +845,7 @@ type ToolStateChanged = DurableEventBase & (Readonly<{
|
|
|
844
845
|
state: "indeterminate";
|
|
845
846
|
}>;
|
|
846
847
|
}>);
|
|
847
|
-
type DurableRunEvent = MessageCommitted |
|
|
848
|
+
type DurableRunEvent = MessageCommitted | RunStateChanged | ToolStateChanged;
|
|
848
849
|
type MessageDelta = Readonly<{
|
|
849
850
|
kind: "message_delta";
|
|
850
851
|
durability: "transient";
|
|
@@ -944,6 +945,7 @@ type ExecutionCheckpoint = Readonly<{
|
|
|
944
945
|
}>;
|
|
945
946
|
type InputRequest = Readonly<{
|
|
946
947
|
id: InputRequestId;
|
|
948
|
+
phase: string;
|
|
947
949
|
messageId: MessageId;
|
|
948
950
|
createdAt: string;
|
|
949
951
|
}>;
|
|
@@ -1036,6 +1038,7 @@ type RunSnapshot = RunSnapshotBase & (Readonly<{
|
|
|
1036
1038
|
state: "input_required";
|
|
1037
1039
|
request: Readonly<{
|
|
1038
1040
|
id: InputRequestId;
|
|
1041
|
+
phase: string;
|
|
1039
1042
|
prompt: AssistantMessage;
|
|
1040
1043
|
}>;
|
|
1041
1044
|
}> | Readonly<{
|
|
@@ -1052,6 +1055,7 @@ type RunSnapshot = RunSnapshotBase & (Readonly<{
|
|
|
1052
1055
|
type RunBoundary = Readonly<{
|
|
1053
1056
|
type: "input_required";
|
|
1054
1057
|
requestId: InputRequestId;
|
|
1058
|
+
phase: string;
|
|
1055
1059
|
prompt: AssistantMessage;
|
|
1056
1060
|
}> | Readonly<{
|
|
1057
1061
|
type: "completed";
|
|
@@ -1132,6 +1136,7 @@ interface OwnedStore {
|
|
|
1132
1136
|
execution: ExecutionToken;
|
|
1133
1137
|
expectedRevision: number;
|
|
1134
1138
|
requestId?: InputRequestId;
|
|
1139
|
+
phase: string;
|
|
1135
1140
|
prompt: AssistantMessage;
|
|
1136
1141
|
checkpoint: ExecutionCheckpoint;
|
|
1137
1142
|
}): Promise<InputRequiredCommit>;
|
|
@@ -1426,6 +1431,7 @@ declare class InMemoryStore implements DurableStore {
|
|
|
1426
1431
|
execution: ExecutionToken;
|
|
1427
1432
|
expectedRevision: number;
|
|
1428
1433
|
requestId?: InputRequestId;
|
|
1434
|
+
phase: string;
|
|
1429
1435
|
prompt: AssistantMessage;
|
|
1430
1436
|
checkpoint: ExecutionCheckpoint;
|
|
1431
1437
|
}): InputRequiredCommit;
|
|
@@ -1572,6 +1578,7 @@ declare class SqliteStore implements DurableStore {
|
|
|
1572
1578
|
execution: ExecutionToken;
|
|
1573
1579
|
expectedRevision: number;
|
|
1574
1580
|
requestId?: InputRequestId;
|
|
1581
|
+
phase: string;
|
|
1575
1582
|
prompt: AssistantMessage;
|
|
1576
1583
|
checkpoint: ExecutionCheckpoint;
|
|
1577
1584
|
}): Promise<InputRequiredCommit>;
|
|
@@ -1800,4 +1807,4 @@ declare function loadExtensionsFromPath(path: string): Promise<{
|
|
|
1800
1807
|
|
|
1801
1808
|
declare function createCoreTools(input?: CoreToolContext): Tool[];
|
|
1802
1809
|
|
|
1803
|
-
export { type AfterToolCall, type AgentConfig, type AgentDefinitionContext, type AgentId, type AgentListCursor, type AgentRecord, type AgentRun, AgentRuntime, type AgentRuntimeOptions, type AgentSummary, type AnyRuntimeError, type AssistantContent, type AssistantMessage, type BeforeToolCall, type ConfigProvider, type ConfigPutResult, type ConfigResolution, type ConfigToken, type CoreToolContext, type DurableConsumer, type DurableRunEvent, type DurableStore, type DurableToolResult, type EventCursor, type EventId, type ExecutionCheckpoint, type ExecutionId, type ExecutionToken, type ExtensionAPI, type ExtensionFactory, type HookEvent, type HookEventType, type HookHandler, InMemoryConfigProvider, InMemoryStore, type InputRequest, type InputRequestId, type InputRequiredCommit, type JsonObject, type JsonPrimitive, type JsonValue, type LoadExtensionsResult, type LoadedExtension, type Message, type MessageBase, type MessageCommitted, type MessageContent, type MessageDelta, type MessageId, type Metadata, type OpaqueId, type Outcome, type OwnerLease, type OwnerToken, type Page, type Phase, type PhaseContext, type PhaseExecutionIdentity, type PhaseInvocation, type PhaseOutput, type PhaseRegistry, type PhaseState, type RunBoundary, type RunClaim, type RunEvent, type RunFailure, type RunId, type RunListCursor, type RunRecord, type RunSnapshot, type RunState, type
|
|
1810
|
+
export { type AfterToolCall, type AgentConfig, type AgentDefinitionContext, type AgentId, type AgentListCursor, type AgentRecord, type AgentRun, AgentRuntime, type AgentRuntimeOptions, type AgentSummary, type AnyRuntimeError, type AssistantContent, type AssistantMessage, type BeforeToolCall, type ConfigProvider, type ConfigPutResult, type ConfigResolution, type ConfigToken, type CoreToolContext, type DurableConsumer, type DurableRunEvent, type DurableStore, type DurableToolResult, type EventCursor, type EventId, type ExecutionCheckpoint, type ExecutionId, type ExecutionToken, type ExtensionAPI, type ExtensionFactory, type HookEvent, type HookEventType, type HookHandler, InMemoryConfigProvider, InMemoryStore, type InputRequest, type InputRequestId, type InputRequiredCommit, type JsonObject, type JsonPrimitive, type JsonValue, type LoadExtensionsResult, type LoadedExtension, type Message, type MessageBase, type MessageCommitted, type MessageContent, type MessageDelta, type MessageId, type Metadata, type OpaqueId, type Outcome, type OwnerLease, type OwnerToken, type Page, type Phase, type PhaseContext, type PhaseExecutionIdentity, type PhaseInvocation, type PhaseOutput, type PhaseRegistry, type PhaseState, type RunBoundary, type RunClaim, type RunEvent, type RunFailure, type RunId, type RunListCursor, type RunRecord, type RunSnapshot, type RunState, type RunStateChanged, type RunSummary, RuntimeError, type RuntimeErrorCode, type RuntimeErrorDetails, type Skill, SqliteStore, type TextContent, type ThinkingContent, type Tool, type ToolCallId, type ToolCallSnapshot, type ToolCallState, type ToolDefinition, type ToolExecutionResult, type ToolInvocationContext, type ToolMessage, type ToolMessageContent, type ToolProgress, type ToolResultContent, type ToolStateChanged, type ToolUseContent, type UserContent, type UserInput, type UserMessage, brandConfigToken, createCoreTools, isRuntimeError, loadExtensionsFromPath as loadExtensions, loadPhases, loadSkills };
|
package/dist/index.js
CHANGED
|
@@ -3947,6 +3947,12 @@ var AgentRuntime = class _AgentRuntime {
|
|
|
3947
3947
|
});
|
|
3948
3948
|
void task;
|
|
3949
3949
|
}
|
|
3950
|
+
} catch (error) {
|
|
3951
|
+
if (error instanceof RuntimeError && error.code === "runtime_ownership_lost") {
|
|
3952
|
+
for (const execution of this.executions.values()) execution.controller.abort();
|
|
3953
|
+
return;
|
|
3954
|
+
}
|
|
3955
|
+
throw error;
|
|
3950
3956
|
} finally {
|
|
3951
3957
|
this.pumping = false;
|
|
3952
3958
|
}
|
|
@@ -3995,10 +4001,7 @@ var AgentRuntime = class _AgentRuntime {
|
|
|
3995
4001
|
const executionContext = projectModelContext({
|
|
3996
4002
|
context: {
|
|
3997
4003
|
...executionConfig.context,
|
|
3998
|
-
phases: executionConfig.context.phases
|
|
3999
|
-
phases: /* @__PURE__ */ new Map([[DEFAULT_PHASE_ID, createDefaultPhase()]]),
|
|
4000
|
-
entryPhaseId: DEFAULT_PHASE_ID
|
|
4001
|
-
}
|
|
4004
|
+
phases: normalizePhaseRegistry(executionConfig.context.phases)
|
|
4002
4005
|
},
|
|
4003
4006
|
messages: claim.history,
|
|
4004
4007
|
agentId: run.agentId,
|
|
@@ -4071,7 +4074,7 @@ var AgentRuntime = class _AgentRuntime {
|
|
|
4071
4074
|
});
|
|
4072
4075
|
if (result.type === "input_required") {
|
|
4073
4076
|
const prompt = promptMessage(run, result.request.prompt, result.messages.length);
|
|
4074
|
-
await this.owned.commitInputRequired({ runId: run.id, execution: claim.execution, expectedRevision: executionRevision, requestId: createId("input"), prompt, checkpoint: result.checkpoint });
|
|
4077
|
+
await this.owned.commitInputRequired({ runId: run.id, execution: claim.execution, expectedRevision: executionRevision, requestId: createId("input"), phase: result.request.phase, prompt, checkpoint: result.checkpoint });
|
|
4075
4078
|
this.transientEvents.clear(run.id, claim.execution.executionId);
|
|
4076
4079
|
return;
|
|
4077
4080
|
}
|
|
@@ -4266,7 +4269,7 @@ var AgentRuntime = class _AgentRuntime {
|
|
|
4266
4269
|
subscription.clearTool(event.toolCall.id);
|
|
4267
4270
|
}
|
|
4268
4271
|
yield event;
|
|
4269
|
-
if (event.kind === "
|
|
4272
|
+
if (event.kind === "run_state_changed" && ["completed", "failed", "cancelled"].includes(event.to)) return;
|
|
4270
4273
|
}
|
|
4271
4274
|
const transient = subscription.shift();
|
|
4272
4275
|
if (transient) {
|
|
@@ -4341,7 +4344,7 @@ function durableOutcome(outcome) {
|
|
|
4341
4344
|
function boundaryFromSnapshot(snapshot) {
|
|
4342
4345
|
switch (snapshot.state) {
|
|
4343
4346
|
case "input_required":
|
|
4344
|
-
return { type: "input_required", requestId: snapshot.request.id, prompt: snapshot.request.prompt };
|
|
4347
|
+
return { type: "input_required", requestId: snapshot.request.id, phase: snapshot.request.phase, prompt: snapshot.request.prompt };
|
|
4345
4348
|
case "completed":
|
|
4346
4349
|
return { type: "completed", outcome: snapshot.outcome, ...snapshot.output ? { output: snapshot.output } : {} };
|
|
4347
4350
|
case "failed":
|
|
@@ -4355,6 +4358,18 @@ function boundaryFromSnapshot(snapshot) {
|
|
|
4355
4358
|
function delay(ms) {
|
|
4356
4359
|
return new Promise((resolve6) => setTimeout(resolve6, ms));
|
|
4357
4360
|
}
|
|
4361
|
+
function normalizePhaseRegistry(registry) {
|
|
4362
|
+
if (registry?.phases.has(DEFAULT_PHASE_ID)) {
|
|
4363
|
+
throw new TypeError(`Configured Phase collides with Rowan built-in Phase "${DEFAULT_PHASE_ID}".`);
|
|
4364
|
+
}
|
|
4365
|
+
return {
|
|
4366
|
+
phases: new Map([
|
|
4367
|
+
[DEFAULT_PHASE_ID, createDefaultPhase()],
|
|
4368
|
+
...registry?.phases ?? []
|
|
4369
|
+
]),
|
|
4370
|
+
entryPhaseId: registry?.entryPhaseId ?? DEFAULT_PHASE_ID
|
|
4371
|
+
};
|
|
4372
|
+
}
|
|
4358
4373
|
function cursorSequence(cursor) {
|
|
4359
4374
|
return Number(String(cursor).split(":").at(-1) ?? 0);
|
|
4360
4375
|
}
|
|
@@ -4634,9 +4649,10 @@ var InMemoryStore = class _InMemoryStore {
|
|
|
4634
4649
|
}
|
|
4635
4650
|
commitInputRequired(lease, input) {
|
|
4636
4651
|
this.assertOwner(lease);
|
|
4652
|
+
if (typeof input.phase !== "string" || input.phase.length === 0) throw new TypeError("phase must be non-empty");
|
|
4637
4653
|
const requestId = input.requestId ?? createId("input");
|
|
4638
4654
|
const operationKey = `input_required:${requestId}`;
|
|
4639
|
-
const operationPayload = canonicalJson([input.runId, input.expectedRevision, input.prompt.id, input.checkpoint]);
|
|
4655
|
+
const operationPayload = canonicalJson([input.runId, input.expectedRevision, input.phase, input.prompt.id, input.checkpoint]);
|
|
4640
4656
|
const replay = this.replayOperation(operationKey, operationPayload);
|
|
4641
4657
|
if (replay) return clone(replay);
|
|
4642
4658
|
const run = this.requireRun(input.runId);
|
|
@@ -4649,6 +4665,7 @@ var InMemoryStore = class _InMemoryStore {
|
|
|
4649
4665
|
};
|
|
4650
4666
|
const request = {
|
|
4651
4667
|
id: requestId,
|
|
4668
|
+
phase: input.phase,
|
|
4652
4669
|
messageId: prompt.id,
|
|
4653
4670
|
createdAt: createTimestamp()
|
|
4654
4671
|
};
|
|
@@ -4971,7 +4988,7 @@ var InMemoryStore = class _InMemoryStore {
|
|
|
4971
4988
|
const request = run.openInputRequest;
|
|
4972
4989
|
const prompt = request && this.messages.get(request.messageId);
|
|
4973
4990
|
if (!prompt || prompt.role !== "assistant") throw new Error(`Run ${run.id} has an invalid input prompt.`);
|
|
4974
|
-
return { ...base, state: "input_required", request: { id: request.id, prompt: clone(prompt) } };
|
|
4991
|
+
return { ...base, state: "input_required", request: { id: request.id, phase: request.phase, prompt: clone(prompt) } };
|
|
4975
4992
|
}
|
|
4976
4993
|
case "completed": {
|
|
4977
4994
|
const output = this.messagesForRun(run.id).filter((message) => message.role === "assistant").at(-1);
|
|
@@ -5124,10 +5141,10 @@ var InMemoryStore = class _InMemoryStore {
|
|
|
5124
5141
|
appendTransition(run, from, to, request, prompt, outcome, failure, reason) {
|
|
5125
5142
|
const transition = {
|
|
5126
5143
|
...this.baseEvent(run),
|
|
5127
|
-
kind: "
|
|
5144
|
+
kind: "run_state_changed",
|
|
5128
5145
|
from,
|
|
5129
5146
|
to,
|
|
5130
|
-
...to === "input_required" && request && prompt ? { request: { id: request.id, prompt } } : {},
|
|
5147
|
+
...to === "input_required" && request && prompt ? { request: { id: request.id, phase: request.phase, prompt } } : {},
|
|
5131
5148
|
...to === "completed" && outcome ? { outcome } : {},
|
|
5132
5149
|
...to === "failed" && failure ? { failure } : {},
|
|
5133
5150
|
...to === "cancelled" && reason ? { reason } : {}
|