@rowan-agent/agent 0.9.9 → 0.9.10
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/dist/index.d.ts +12 -2
- package/dist/index.js +56 -6
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -359,6 +359,16 @@ type MessageDelta = Readonly<{
|
|
|
359
359
|
offset: number;
|
|
360
360
|
text: string;
|
|
361
361
|
}>;
|
|
362
|
+
type ThinkingDelta = Readonly<{
|
|
363
|
+
kind: "thinking_delta";
|
|
364
|
+
durability: "transient";
|
|
365
|
+
runId: RunId;
|
|
366
|
+
executionId: ExecutionId;
|
|
367
|
+
messageId: MessageId;
|
|
368
|
+
blockIndex: number;
|
|
369
|
+
offset: number;
|
|
370
|
+
text: string;
|
|
371
|
+
}>;
|
|
362
372
|
type ToolProgress = Readonly<{
|
|
363
373
|
kind: "tool_progress";
|
|
364
374
|
durability: "transient";
|
|
@@ -375,7 +385,7 @@ type PhaseStatusEvent = Readonly<{
|
|
|
375
385
|
phaseId: string;
|
|
376
386
|
status: PhaseStatus;
|
|
377
387
|
}>;
|
|
378
|
-
type RunEvent = DurableRunEvent | MessageDelta | ToolProgress | PhaseStatusEvent;
|
|
388
|
+
type RunEvent = DurableRunEvent | MessageDelta | ThinkingDelta | ToolProgress | PhaseStatusEvent;
|
|
379
389
|
|
|
380
390
|
interface BeforePhaseEvent {
|
|
381
391
|
type: "before_phase";
|
|
@@ -2657,4 +2667,4 @@ declare function parseFrontmatter<T = Record<string, unknown>>(raw: string): Fro
|
|
|
2657
2667
|
|
|
2658
2668
|
declare function createCoreTools(input?: CoreToolContext): Tool[];
|
|
2659
2669
|
|
|
2660
|
-
export { type AfterToolCall, type AgentConfig, type AgentConfigRequest, type AgentConfiguration, type AgentDefinition, type AgentId, type AgentListCursor, type AgentRecord, type AgentResources, type AgentRun, AgentRuntime, type AgentRuntimeOptions, type AgentSummary, type AnyRuntimeError, type AssistantContent, type AssistantMessage, type BeforeToolCall, COMPACT_PHASE_ID, type ConfigProvider, type ConfigPutResult, type ConfigResolution, type ConfigToken, type ConfigurationSnapshot, type ContextCandidate, type ContextCompactionRecord, type ContextStatus, type CoreToolContext, DEFAULT_PHASE_ID, type DefinitionLayer, type DurableConsumer, type DurableRunEvent, type DurableStore, type DurableToolResult, type EventCursor, type EventId, type ExecutionCheckpoint, type ExecutionId, type ExecutionToken, type ExtensionAPI, type ExtensionActivationError, type ExtensionActivationResult, type ExtensionContribution, type ExtensionDisposer, type ExtensionFactory, type ExtensionFactoryResult, ExtensionLifetimeError, type ExtensionLifetimeErrorCode, type ExtensionLoadInput, type FrontmatterResult, type HistorySeed, type HookEvent, type HookEventType, type HookHandler, InMemoryConfigProvider, InMemoryStore, type InputRequest, type InputRequestId, type InputRequiredCommit, type InvocationCatalogEntry, type InvocationSource, type JsonObject, type JsonPrimitive, type JsonValue, type LoadExtensionsResult, type LoadInput, type LoadResult, type LoadedExtension, type Message, type MessageBase, type MessageCommitted, type MessageContent, type MessageDelta, type MessageId, type MessageRevised, type MessageRevisionResult, type Metadata, type OpaqueId, type Outcome, type OwnerLease, type OwnerToken, type Page, type Phase, type PhaseContext, type PhaseContribution, type PhaseExecution, type PhaseExecutionIdentity, type PhaseInteraction, PhaseInteractionBoundary, PhaseInteractionCancelledError, type PhaseInteractionDriver, type PhaseInteractionKind, type PhaseInteractionState, type PhaseInteractionStatus, type PhaseInvocation, type PhaseOutput, type PhaseRegistry, type PhaseRegistrySelection, type PhaseState, type PhaseStatus, type PhaseStatusState, type ResolvedResourceView, type ResourceDiagnostic, type ResourceKind, type ResourceRef, ResourceRegistry, ResourceRegistryError, type ResourceRegistryErrorCode, type ResourceSourceId, type ResourceView, type RetentionResult, type RunBoundary, type RunClaim, type RunEvent, type RunFailure, type RunId, type RunListCursor, type RunRecord, type RunSnapshot, type RunState, type RunStateChanged, type RunSummary, RuntimeBootstrapRegistry, RuntimeError, type RuntimeErrorCode, type RuntimeErrorDetails, RuntimeExtensionLifetime, STOP_PHASE_ID, type Skill, SqliteStore, type TextContent, type ThinkingContent, type 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, isRuntimeError, loadExtensionsFromPath as loadExtensions, loadPhase, loadPhases, loadSkill, loadSkills, materializeConfigurationSnapshot, parseAgentDefinition, parseFrontmatter, resolveConfigurationSnapshot };
|
|
2670
|
+
export { type AfterToolCall, type AgentConfig, type AgentConfigRequest, type AgentConfiguration, type AgentDefinition, type AgentId, type AgentListCursor, type AgentRecord, type AgentResources, type AgentRun, AgentRuntime, type AgentRuntimeOptions, type AgentSummary, type AnyRuntimeError, type AssistantContent, type AssistantMessage, type BeforeToolCall, COMPACT_PHASE_ID, type ConfigProvider, type ConfigPutResult, type ConfigResolution, type ConfigToken, type ConfigurationSnapshot, type ContextCandidate, type ContextCompactionRecord, type ContextStatus, type CoreToolContext, DEFAULT_PHASE_ID, type DefinitionLayer, type DurableConsumer, type DurableRunEvent, type DurableStore, type DurableToolResult, type EventCursor, type EventId, type ExecutionCheckpoint, type ExecutionId, type ExecutionToken, type ExtensionAPI, type ExtensionActivationError, type ExtensionActivationResult, type ExtensionContribution, type ExtensionDisposer, type ExtensionFactory, type ExtensionFactoryResult, ExtensionLifetimeError, type ExtensionLifetimeErrorCode, type ExtensionLoadInput, type FrontmatterResult, type HistorySeed, type HookEvent, type HookEventType, type HookHandler, InMemoryConfigProvider, InMemoryStore, type InputRequest, type InputRequestId, type InputRequiredCommit, type InvocationCatalogEntry, type InvocationSource, type JsonObject, type JsonPrimitive, type JsonValue, type LoadExtensionsResult, type LoadInput, type LoadResult, type LoadedExtension, type Message, type MessageBase, type MessageCommitted, type MessageContent, type MessageDelta, type MessageId, type MessageRevised, type MessageRevisionResult, type Metadata, type OpaqueId, type Outcome, type OwnerLease, type OwnerToken, type Page, type Phase, type PhaseContext, type PhaseContribution, type PhaseExecution, type PhaseExecutionIdentity, type PhaseInteraction, PhaseInteractionBoundary, PhaseInteractionCancelledError, type PhaseInteractionDriver, type PhaseInteractionKind, type PhaseInteractionState, type PhaseInteractionStatus, type PhaseInvocation, type PhaseOutput, type PhaseRegistry, type PhaseRegistrySelection, type PhaseState, type PhaseStatus, type PhaseStatusState, type ResolvedResourceView, type ResourceDiagnostic, type ResourceKind, type ResourceRef, ResourceRegistry, ResourceRegistryError, type ResourceRegistryErrorCode, type ResourceSourceId, type ResourceView, type RetentionResult, type RunBoundary, type RunClaim, type RunEvent, type RunFailure, type RunId, type RunListCursor, type RunRecord, type RunSnapshot, type RunState, type RunStateChanged, type RunSummary, RuntimeBootstrapRegistry, RuntimeError, type RuntimeErrorCode, type RuntimeErrorDetails, RuntimeExtensionLifetime, STOP_PHASE_ID, type Skill, SqliteStore, type TextContent, type ThinkingContent, type ThinkingDelta, type Tool, type ToolCallId, type ToolCallSnapshot, type ToolCallState, type ToolContribution, type ToolDefinition, type ToolExecutionResult$1 as ToolExecutionResult, type ToolInvocationContext, type ToolMessage, type ToolMessageContent, type ToolProgress, type ToolResultContent, type ToolStateChanged, type ToolUseContent, type UserContent, type UserInput, type UserMessage, brandConfigToken, createCompactPhase, createCorePhases, createCoreTools, createDefaultPhase, createStopPhase, isRuntimeError, loadExtensionsFromPath as loadExtensions, loadPhase, loadPhases, loadSkill, loadSkills, materializeConfigurationSnapshot, parseAgentDefinition, parseFrontmatter, resolveConfigurationSnapshot };
|
package/dist/index.js
CHANGED
|
@@ -858,7 +858,8 @@ async function invokeModel(input) {
|
|
|
858
858
|
message: input.message,
|
|
859
859
|
events,
|
|
860
860
|
metadataPhase: input.phaseId,
|
|
861
|
-
output: input.output
|
|
861
|
+
output: input.output,
|
|
862
|
+
onThinkingDelta: input.onThinkingDelta
|
|
862
863
|
});
|
|
863
864
|
const response = result.doneResponse ?? {
|
|
864
865
|
content: result.text,
|
|
@@ -888,6 +889,7 @@ async function collectStreamResult(input) {
|
|
|
888
889
|
let doneResponse;
|
|
889
890
|
let streamedOutputCharacters = 0;
|
|
890
891
|
const toolCallsWithDeltas = /* @__PURE__ */ new Set();
|
|
892
|
+
const thinkingOffsets = /* @__PURE__ */ new Map();
|
|
891
893
|
for await (const event of input.events) {
|
|
892
894
|
if (event.type === "text_delta") {
|
|
893
895
|
streamedOutputCharacters += event.text.length;
|
|
@@ -939,7 +941,29 @@ async function collectStreamResult(input) {
|
|
|
939
941
|
lastPartial = event.partial;
|
|
940
942
|
}
|
|
941
943
|
if (event.type === "thinking_delta") {
|
|
944
|
+
if (persistAssistant && !activeMessageId) {
|
|
945
|
+
activeMessageId = input.message.reserve("assistant", {
|
|
946
|
+
phase: input.metadataPhase
|
|
947
|
+
});
|
|
948
|
+
}
|
|
942
949
|
lastPartial = event.partial;
|
|
950
|
+
if (persistAssistant && activeMessageId) {
|
|
951
|
+
let blockIndex = 0;
|
|
952
|
+
for (let index = event.partial.contentBlocks.length - 1; index >= 0; index -= 1) {
|
|
953
|
+
if (event.partial.contentBlocks[index]?.type === "thinking") {
|
|
954
|
+
blockIndex = index;
|
|
955
|
+
break;
|
|
956
|
+
}
|
|
957
|
+
}
|
|
958
|
+
const offset = thinkingOffsets.get(blockIndex) ?? 0;
|
|
959
|
+
input.onThinkingDelta?.({
|
|
960
|
+
messageId: activeMessageId,
|
|
961
|
+
blockIndex,
|
|
962
|
+
offset,
|
|
963
|
+
text: event.thinking
|
|
964
|
+
});
|
|
965
|
+
thinkingOffsets.set(blockIndex, offset + event.thinking.length);
|
|
966
|
+
}
|
|
943
967
|
}
|
|
944
968
|
if (event.type === "done") {
|
|
945
969
|
doneResponse = event.response;
|
|
@@ -2875,7 +2899,8 @@ function createPhaseExecution(config, state, phase, messageManager, toolExecutio
|
|
|
2875
2899
|
message: messageManager,
|
|
2876
2900
|
request,
|
|
2877
2901
|
phaseId: phase.name,
|
|
2878
|
-
output: options.output
|
|
2902
|
+
output: options.output,
|
|
2903
|
+
onThinkingDelta: config.onThinkingDelta
|
|
2879
2904
|
}),
|
|
2880
2905
|
{
|
|
2881
2906
|
signal: config.signal,
|
|
@@ -3139,6 +3164,7 @@ async function executeOnce(input) {
|
|
|
3139
3164
|
beforePrompt: input.beforePrompt,
|
|
3140
3165
|
onMessage: input.onMessage,
|
|
3141
3166
|
onMessageDelta: input.onMessageDelta,
|
|
3167
|
+
onThinkingDelta: input.onThinkingDelta,
|
|
3142
3168
|
onOutcome: input.onOutcome,
|
|
3143
3169
|
onModelTranscript: input.onModelTranscript,
|
|
3144
3170
|
onPhaseStatus: input.onPhaseStatus,
|
|
@@ -4051,6 +4077,11 @@ var TransientRunEventSubscription = class {
|
|
|
4051
4077
|
...previous,
|
|
4052
4078
|
text: previous.text + event.text
|
|
4053
4079
|
};
|
|
4080
|
+
} else if (previous?.kind === "thinking_delta" && event.kind === "thinking_delta" && previous.executionId === event.executionId && previous.messageId === event.messageId && previous.blockIndex === event.blockIndex && previous.offset + previous.text.length === event.offset) {
|
|
4081
|
+
this.queue[this.queue.length - 1] = {
|
|
4082
|
+
...previous,
|
|
4083
|
+
text: previous.text + event.text
|
|
4084
|
+
};
|
|
4054
4085
|
} else {
|
|
4055
4086
|
if (this.queue.length >= MAX_BUFFERED_EVENTS) this.queue.shift();
|
|
4056
4087
|
this.queue.push(event);
|
|
@@ -4076,7 +4107,7 @@ var TransientRunEventSubscription = class {
|
|
|
4076
4107
|
clearMessage(messageId) {
|
|
4077
4108
|
for (let index = this.queue.length - 1; index >= 0; index -= 1) {
|
|
4078
4109
|
const event = this.queue[index];
|
|
4079
|
-
if (event?.kind === "message_delta" && event.messageId === messageId) this.queue.splice(index, 1);
|
|
4110
|
+
if ((event?.kind === "message_delta" || event?.kind === "thinking_delta") && event.messageId === messageId) this.queue.splice(index, 1);
|
|
4080
4111
|
}
|
|
4081
4112
|
this.notify();
|
|
4082
4113
|
}
|
|
@@ -4108,11 +4139,11 @@ var TransientRunEventSubscription = class {
|
|
|
4108
4139
|
}
|
|
4109
4140
|
trimText() {
|
|
4110
4141
|
let buffered = this.queue.reduce(
|
|
4111
|
-
(length, event) => length + (event.kind === "message_delta" ? event.text.length : 0),
|
|
4142
|
+
(length, event) => length + (event.kind === "message_delta" || event.kind === "thinking_delta" ? event.text.length : 0),
|
|
4112
4143
|
0
|
|
4113
4144
|
);
|
|
4114
4145
|
while (buffered > MAX_BUFFERED_TEXT) {
|
|
4115
|
-
const index = this.queue.findIndex((event2) => event2.kind === "message_delta");
|
|
4146
|
+
const index = this.queue.findIndex((event2) => event2.kind === "message_delta" || event2.kind === "thinking_delta");
|
|
4116
4147
|
if (index < 0) return;
|
|
4117
4148
|
const event = this.queue[index];
|
|
4118
4149
|
const overflow = buffered - MAX_BUFFERED_TEXT;
|
|
@@ -6036,6 +6067,20 @@ ${instructions}`,
|
|
|
6036
6067
|
text: event.text
|
|
6037
6068
|
});
|
|
6038
6069
|
},
|
|
6070
|
+
onThinkingDelta: (event) => {
|
|
6071
|
+
const active = this.executions.get(run.id);
|
|
6072
|
+
if (this.closed || controller.signal.aborted || active?.executionId !== claim.execution.executionId) return;
|
|
6073
|
+
this.transientEvents.publish({
|
|
6074
|
+
kind: "thinking_delta",
|
|
6075
|
+
durability: "transient",
|
|
6076
|
+
runId: run.id,
|
|
6077
|
+
executionId: claim.execution.executionId,
|
|
6078
|
+
messageId: event.messageId,
|
|
6079
|
+
blockIndex: event.blockIndex,
|
|
6080
|
+
offset: event.offset,
|
|
6081
|
+
text: event.text
|
|
6082
|
+
});
|
|
6083
|
+
},
|
|
6039
6084
|
onContext: assembly.setContext,
|
|
6040
6085
|
runtime: {
|
|
6041
6086
|
tools: ({ toolCall }) => {
|
|
@@ -6106,7 +6151,12 @@ ${instructions}`,
|
|
|
6106
6151
|
return;
|
|
6107
6152
|
}
|
|
6108
6153
|
if (result.type === "input_required") {
|
|
6109
|
-
const
|
|
6154
|
+
const output = latestAssistant(
|
|
6155
|
+
run,
|
|
6156
|
+
result.messages.slice(modelMessages.length),
|
|
6157
|
+
modelMessages.length
|
|
6158
|
+
);
|
|
6159
|
+
const prompt = output ?? promptMessage(run, result.request.prompt, result.messages.length);
|
|
6110
6160
|
await this.owned.commitInputRequired({
|
|
6111
6161
|
runId: run.id,
|
|
6112
6162
|
execution: claim.execution,
|