goatchain 0.0.29 → 0.0.30
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 +244 -15
- package/dist/acp-adapter/history-normalizer.d.ts +10 -0
- package/dist/acp-adapter/index.d.ts +2 -0
- package/dist/acp-adapter/types.d.ts +4 -0
- package/dist/agent/agent.d.ts +14 -3
- package/dist/agent/hooks/index.d.ts +1 -1
- package/dist/agent/hooks/manager.d.ts +18 -1
- package/dist/agent/hooks/prompt-executor.d.ts +28 -0
- package/dist/agent/hooks/types.d.ts +32 -6
- package/dist/agent/index.d.ts +1 -1
- package/dist/agent/middleware.d.ts +10 -2
- package/dist/agent/types.d.ts +12 -0
- package/dist/index.d.ts +10 -10
- package/dist/index.js +510 -491
- package/dist/middleware/contextCompressionMiddleware.d.ts +27 -18
- package/dist/middleware/longRunningMiddleware.d.ts +6 -0
- package/dist/middleware/parallelSubagentMiddleware.d.ts +7 -1
- package/dist/model/anthropic/createAnthropicAdapter.d.ts +5 -0
- package/dist/session/executors/ToolExecutor.d.ts +4 -0
- package/dist/session/index.d.ts +1 -0
- package/dist/session/session.d.ts +36 -3
- package/dist/session/types/index.d.ts +1 -0
- package/dist/session/types/messageQueue.d.ts +29 -0
- package/dist/session/utils/MessageQueue.d.ts +23 -0
- package/dist/state/types.d.ts +62 -0
- package/dist/types/common.d.ts +12 -0
- package/dist/types/event.d.ts +63 -2
- package/dist/types/index.d.ts +1 -0
- package/dist/types/snapshot.d.ts +11 -0
- package/package.json +22 -22
|
@@ -14,11 +14,19 @@ export interface ContextCompressionOptions {
|
|
|
14
14
|
*/
|
|
15
15
|
maxTokens: number;
|
|
16
16
|
/**
|
|
17
|
-
*
|
|
17
|
+
* Compression strategy mode.
|
|
18
|
+
* - `smart` (default): use adaptive boundaries and multi-stage compression.
|
|
19
|
+
* - `legacy`: keep historical behavior based on `protectedTurns` and tool params.
|
|
20
|
+
*/
|
|
21
|
+
compressionMode?: 'smart' | 'legacy';
|
|
22
|
+
/**
|
|
23
|
+
* Number of recent conversation turns to always protect (default: 2, legacy mode only).
|
|
18
24
|
* A turn is a user message + assistant response pair.
|
|
19
25
|
* The last N turns will always be preserved from summary compression.
|
|
20
26
|
* Tool compression ignores this setting and only preserves tool results from
|
|
21
27
|
* the most recent completed turn.
|
|
28
|
+
*
|
|
29
|
+
* @deprecated Use smart mode (default) instead.
|
|
22
30
|
*/
|
|
23
31
|
protectedTurns?: number;
|
|
24
32
|
/**
|
|
@@ -32,11 +40,15 @@ export interface ContextCompressionOptions {
|
|
|
32
40
|
/**
|
|
33
41
|
* Tool compression target (default: 0.45, meaning compress to 45% of maxTokens).
|
|
34
42
|
* When tool compression is triggered at 50%, it will compress until reaching this target.
|
|
43
|
+
*
|
|
44
|
+
* @deprecated Use smart mode (default) instead.
|
|
35
45
|
*/
|
|
36
46
|
toolCompressionTarget?: number;
|
|
37
47
|
/**
|
|
38
|
-
* Minimum number of recent tool results to keep (default: 5).
|
|
48
|
+
* Minimum number of recent tool results to keep (default: 5, legacy mode only).
|
|
39
49
|
* The most recent N tool results will be protected from compression.
|
|
50
|
+
*
|
|
51
|
+
* @deprecated Use smart mode (default) instead.
|
|
40
52
|
*/
|
|
41
53
|
minKeepToolResults?: number;
|
|
42
54
|
/**
|
|
@@ -128,6 +140,10 @@ export interface ManualCompressionResult {
|
|
|
128
140
|
* Number of tool outputs found.
|
|
129
141
|
*/
|
|
130
142
|
toolOutputCount: number;
|
|
143
|
+
/**
|
|
144
|
+
* Committed compressed working view including the system message.
|
|
145
|
+
*/
|
|
146
|
+
compressedMessages: Message[];
|
|
131
147
|
}
|
|
132
148
|
/**
|
|
133
149
|
* Statistics about the compression operation.
|
|
@@ -149,21 +165,17 @@ export interface CompressionStats {
|
|
|
149
165
|
/**
|
|
150
166
|
* Create a context compression middleware.
|
|
151
167
|
*
|
|
152
|
-
* This middleware automatically compresses conversation history
|
|
168
|
+
* This middleware automatically compresses conversation history.
|
|
153
169
|
*
|
|
154
|
-
*
|
|
155
|
-
* -
|
|
156
|
-
* -
|
|
157
|
-
* -
|
|
158
|
-
* -
|
|
159
|
-
* -
|
|
160
|
-
*
|
|
170
|
+
* Smart mode uses a target-driven flow:
|
|
171
|
+
* - Triggers summary compression near 80% of maxTokens
|
|
172
|
+
* - Compresses toward a low-water target near 30% in the same iteration
|
|
173
|
+
* - Bounds the persisted rolling summary so it cannot silently grow forever
|
|
174
|
+
* - Applies cooldown to avoid repeated re-summary on tiny growth
|
|
175
|
+
* - Bypasses cooldown in emergency overflow cases, then hard-fails before model
|
|
176
|
+
* invocation if the prompt still cannot fit within maxTokens
|
|
161
177
|
*
|
|
162
|
-
*
|
|
163
|
-
* - Iteratively clears tool output content → `[Old tool result content cleared]`
|
|
164
|
-
* - Starts from oldest tool, clears until reaching target (default: 45% of maxTokens)
|
|
165
|
-
* - Protects last N tool results (default: 5)
|
|
166
|
-
* - NOT saved to state (transient compression)
|
|
178
|
+
* Legacy mode keeps the historical protected-turn / protected-tool behavior.
|
|
167
179
|
*
|
|
168
180
|
* @param options - Compression configuration options
|
|
169
181
|
* @returns Middleware function
|
|
@@ -174,11 +186,8 @@ export interface CompressionStats {
|
|
|
174
186
|
*
|
|
175
187
|
* agent.use(createContextCompressionMiddleware({
|
|
176
188
|
* maxTokens: 128000,
|
|
177
|
-
* protectedTurns: 2,
|
|
178
189
|
* model: model,
|
|
179
190
|
* stateStore: agent.stateStore,
|
|
180
|
-
* toolCompressionTarget: 0.45, // Compress to 45% of maxTokens
|
|
181
|
-
* minKeepToolResults: 5, // Keep last 5 tool results
|
|
182
191
|
* }))
|
|
183
192
|
* ```
|
|
184
193
|
*/
|
|
@@ -34,6 +34,12 @@ export interface SelfReflectionOptions {
|
|
|
34
34
|
* @default false
|
|
35
35
|
*/
|
|
36
36
|
debug?: boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Critic subagent context window / compression budget.
|
|
39
|
+
*
|
|
40
|
+
* @default 128000
|
|
41
|
+
*/
|
|
42
|
+
maxTokens?: number;
|
|
37
43
|
}
|
|
38
44
|
/**
|
|
39
45
|
* Options for the long_running middleware.
|
|
@@ -31,6 +31,12 @@ export interface ParallelSubagentMiddlewareOptions {
|
|
|
31
31
|
* 是否输出调试日志(默认: false)
|
|
32
32
|
*/
|
|
33
33
|
debug?: boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Subagent context window / compression budget.
|
|
36
|
+
*
|
|
37
|
+
* Defaults to 128000 when not provided.
|
|
38
|
+
*/
|
|
39
|
+
maxTokens?: number;
|
|
34
40
|
/**
|
|
35
41
|
* 可选:middleware 名称(默认: 'parallel_subagent')
|
|
36
42
|
*/
|
|
@@ -43,7 +49,7 @@ export interface ParallelSubagentMiddlewareOptions {
|
|
|
43
49
|
* 1. 自动创建并注册 TaskTool(包含 subagent 定义和 executor)
|
|
44
50
|
* 2. 启用并行执行模式:当 LLM 同时调用多个 Task 工具时自动并行执行
|
|
45
51
|
*
|
|
46
|
-
* TaskTool
|
|
52
|
+
* TaskTool 会以 `Task` 注册(本 middleware 使用无前缀注册,提高辨识度)
|
|
47
53
|
*
|
|
48
54
|
* @example 使用默认 executor(推荐)
|
|
49
55
|
* ```typescript
|
|
@@ -51,6 +51,11 @@ interface AnthropicThinkingBlock {
|
|
|
51
51
|
thinking: string;
|
|
52
52
|
}
|
|
53
53
|
type AnthropicContentBlock = AnthropicTextBlock | AnthropicImageBlock | AnthropicDocumentBlock | AnthropicToolUseBlock | AnthropicToolResultBlock | AnthropicThinkingBlock;
|
|
54
|
+
type AnthropicUsage = {
|
|
55
|
+
input_tokens?: number;
|
|
56
|
+
output_tokens?: number;
|
|
57
|
+
};
|
|
54
58
|
export declare function contentToBlocks(content: MessageContent): AnthropicContentBlock[];
|
|
59
|
+
export declare function mergeAnthropicUsage(base?: AnthropicUsage, next?: AnthropicUsage | null): AnthropicUsage | undefined;
|
|
55
60
|
export declare function createAnthropicAdapter(options: AnthropicAdapterOptions): ModelAdapter;
|
|
56
61
|
export {};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { AgentHooks } from '../../agent/hooks';
|
|
2
2
|
import type { AgentLoopState, ToolCallWithResult } from '../../agent/types';
|
|
3
|
+
import type { ModelClient } from '../../model/types';
|
|
3
4
|
import type { ToolExecutionContext, ToolExecutionContextInput, ToolRegistry } from '../../tool';
|
|
4
5
|
import type { AgentEvent, AgentLoopCheckpoint, CheckpointModelConfig, CheckpointRequestParams, ToolCall } from '../../types';
|
|
5
6
|
import type { ApprovalHandler } from '../handlers/ApprovalHandler';
|
|
@@ -21,6 +22,8 @@ interface ToolExecutorOptions {
|
|
|
21
22
|
addAssistantMessageWithToolCalls: (state: AgentLoopState) => void;
|
|
22
23
|
addToolResultToHistory: (state: AgentLoopState, tc: ToolCallWithResult) => void;
|
|
23
24
|
persistSessionState: (state: AgentLoopState) => Promise<void>;
|
|
25
|
+
modelClient?: ModelClient;
|
|
26
|
+
getSessionMetadata?: () => Record<string, unknown>;
|
|
24
27
|
log?: (...args: unknown[]) => void;
|
|
25
28
|
}
|
|
26
29
|
export declare class ToolExecutor {
|
|
@@ -28,6 +31,7 @@ export declare class ToolExecutor {
|
|
|
28
31
|
private toolEventQueue;
|
|
29
32
|
constructor(options: ToolExecutorOptions);
|
|
30
33
|
private _log;
|
|
34
|
+
private createHookManager;
|
|
31
35
|
createToolExecutionContext(state: AgentLoopState, signal?: AbortSignal, toolCallId?: string, toolName?: string): ToolExecutionContext;
|
|
32
36
|
executeToolCall(tc: ToolCallWithResult, ctx: ToolExecutionContext, signal?: AbortSignal, hooks?: AgentHooks, permissionRequestResult?: {
|
|
33
37
|
allow: boolean;
|
package/dist/session/index.d.ts
CHANGED
|
@@ -1,10 +1,19 @@
|
|
|
1
1
|
import type { Middleware } from '../agent/middleware';
|
|
2
2
|
import type { AgentLoopState, CreateSessionOptions, SendOptions } from '../agent/types';
|
|
3
|
-
import type { ModelClient } from '../model';
|
|
3
|
+
import type { ModelClient, ModelStreamEvent } from '../model';
|
|
4
4
|
import type { StateStore } from '../state';
|
|
5
5
|
import type { ToolApprovalResult, ToolRegistry } from '../tool';
|
|
6
|
-
import type { AgentEvent, Message, MessageContent, ModelConfig, SessionConfigOverride, SessionSnapshot, SessionStatus } from '../types';
|
|
6
|
+
import type { AgentEvent, CallModelOnceOptions, CallModelOnceResult, Message, MessageContent, ModelConfig, SessionConfigOverride, SessionSnapshot, SessionStatus } from '../types';
|
|
7
|
+
import type { MessageQueueConfig, MessageQueueStatus } from './types/messageQueue';
|
|
7
8
|
import { EventEmitter } from 'node:events';
|
|
9
|
+
type QueuedSendOptions = SendOptions & {
|
|
10
|
+
priority?: number;
|
|
11
|
+
};
|
|
12
|
+
interface BatchMessageInput {
|
|
13
|
+
input: MessageContent;
|
|
14
|
+
options?: SendOptions;
|
|
15
|
+
priority?: number;
|
|
16
|
+
}
|
|
8
17
|
interface SessionRuntimeOptions extends CreateSessionOptions {
|
|
9
18
|
modelClient?: ModelClient;
|
|
10
19
|
systemPrompt?: string;
|
|
@@ -54,6 +63,7 @@ export declare class Session extends EventEmitter {
|
|
|
54
63
|
private readonly _systemPrompt?;
|
|
55
64
|
private readonly _agentName?;
|
|
56
65
|
private readonly _onUsage?;
|
|
66
|
+
private _messageQueue;
|
|
57
67
|
private _pendingInput;
|
|
58
68
|
private _isReceiving;
|
|
59
69
|
private readonly _hooks?;
|
|
@@ -69,6 +79,9 @@ export declare class Session extends EventEmitter {
|
|
|
69
79
|
private _checkpointOriginalMessages?;
|
|
70
80
|
private _checkpointNewMessages;
|
|
71
81
|
private _checkpointSkipSnapshot?;
|
|
82
|
+
private _rawMessages;
|
|
83
|
+
private _rawOriginalMessages?;
|
|
84
|
+
private _rawNewMessages;
|
|
72
85
|
private getDisabledToolNames;
|
|
73
86
|
private isToolDisabled;
|
|
74
87
|
private collectBlockedTools;
|
|
@@ -85,6 +98,7 @@ export declare class Session extends EventEmitter {
|
|
|
85
98
|
* @private
|
|
86
99
|
*/
|
|
87
100
|
private _syncCwdToTools;
|
|
101
|
+
private getOrCreateSessionMetadata;
|
|
88
102
|
/**
|
|
89
103
|
* Create a new Session or load from StateStore.
|
|
90
104
|
*
|
|
@@ -98,7 +112,14 @@ export declare class Session extends EventEmitter {
|
|
|
98
112
|
* This is an idempotent check that reads from StateStore each time.
|
|
99
113
|
*/
|
|
100
114
|
hasCheckpoint(): Promise<boolean>;
|
|
101
|
-
send(input: MessageContent, options?:
|
|
115
|
+
send(input: MessageContent, options?: QueuedSendOptions): string;
|
|
116
|
+
sendBatch(messages: BatchMessageInput[]): string[];
|
|
117
|
+
cancelQueuedMessage(messageId: string): boolean;
|
|
118
|
+
getQueueStatus(): MessageQueueStatus;
|
|
119
|
+
clearQueue(): void;
|
|
120
|
+
updateQueueConfig(config: Partial<MessageQueueConfig>): void;
|
|
121
|
+
private _tryDequeueNext;
|
|
122
|
+
private _markCheckpointQueueMessageAsConsumed;
|
|
102
123
|
/**
|
|
103
124
|
* Cancel the current agent execution.
|
|
104
125
|
*
|
|
@@ -123,6 +144,8 @@ export declare class Session extends EventEmitter {
|
|
|
123
144
|
* ```
|
|
124
145
|
*/
|
|
125
146
|
cancel(): void;
|
|
147
|
+
callModelOnceStream(options: CallModelOnceOptions): AsyncIterable<ModelStreamEvent>;
|
|
148
|
+
callModelOnce(options: CallModelOnceOptions): Promise<CallModelOnceResult>;
|
|
126
149
|
receive(options?: SendOptions): AsyncIterable<AgentEvent>;
|
|
127
150
|
/**
|
|
128
151
|
* Convenience helper for "pause → decide → resume" flows.
|
|
@@ -144,16 +167,26 @@ export declare class Session extends EventEmitter {
|
|
|
144
167
|
* This prevents the session from being stuck waiting for responses that will never come.
|
|
145
168
|
*/
|
|
146
169
|
private buildAutoRejectToolContext;
|
|
170
|
+
private mergeToolContexts;
|
|
171
|
+
private hasMeaningfulToolContext;
|
|
147
172
|
private getRuntimeModelRoute;
|
|
173
|
+
getRawMessages(): Message[];
|
|
174
|
+
getFullRawMessages(): Message[];
|
|
175
|
+
applyCommittedWorkingMessages(messages: Message[]): Promise<void>;
|
|
148
176
|
private _ensureRuntimeConfigured;
|
|
149
177
|
private extractTextFromContent;
|
|
150
178
|
private stripLeadingMarkdownLinkPrefix;
|
|
151
179
|
private createTitle;
|
|
180
|
+
private buildRawMessagesForCompression;
|
|
181
|
+
private seedCompressionMetadata;
|
|
152
182
|
private _recordUsage;
|
|
183
|
+
private normalizeUsage;
|
|
153
184
|
private executeModelStream;
|
|
154
185
|
private mergeStateResults;
|
|
155
186
|
private appendMessage;
|
|
156
187
|
private getCheckpointMessages;
|
|
188
|
+
private commitRuntimeState;
|
|
189
|
+
private resetLoopSnapshots;
|
|
157
190
|
private saveCheckpointForState;
|
|
158
191
|
private addToolResultToHistory;
|
|
159
192
|
private addAssistantMessageWithToolCalls;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './messageQueue';
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { SendOptions } from '../../agent/types';
|
|
2
|
+
import type { MessageContent } from '../../types';
|
|
3
|
+
export interface PendingMessage {
|
|
4
|
+
id: string;
|
|
5
|
+
input: MessageContent;
|
|
6
|
+
options?: SendOptions;
|
|
7
|
+
priority: number;
|
|
8
|
+
enqueuedAt: number;
|
|
9
|
+
status: 'pending' | 'cancelled';
|
|
10
|
+
}
|
|
11
|
+
export interface MessageQueueConfig {
|
|
12
|
+
autoProcessQueue: boolean;
|
|
13
|
+
maxQueueSize?: number;
|
|
14
|
+
}
|
|
15
|
+
export interface MessageQueueSnapshot {
|
|
16
|
+
messages: PendingMessage[];
|
|
17
|
+
config: MessageQueueConfig;
|
|
18
|
+
}
|
|
19
|
+
export interface MessageQueueStatus {
|
|
20
|
+
length: number;
|
|
21
|
+
messages: Array<{
|
|
22
|
+
id: string;
|
|
23
|
+
priority: number;
|
|
24
|
+
enqueuedAt: number;
|
|
25
|
+
preview: string;
|
|
26
|
+
}>;
|
|
27
|
+
isProcessing: boolean;
|
|
28
|
+
config: MessageQueueConfig;
|
|
29
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { MessageContent } from '../../types';
|
|
2
|
+
import type { SendOptions } from '../../agent/types';
|
|
3
|
+
import type { MessageQueueConfig, MessageQueueSnapshot, MessageQueueStatus, PendingMessage } from '../types/messageQueue';
|
|
4
|
+
export declare class MessageQueue {
|
|
5
|
+
private _messages;
|
|
6
|
+
private _config;
|
|
7
|
+
private _isProcessing;
|
|
8
|
+
constructor(config?: Partial<MessageQueueConfig>);
|
|
9
|
+
get config(): MessageQueueConfig;
|
|
10
|
+
updateConfig(config: Partial<MessageQueueConfig>): void;
|
|
11
|
+
setProcessing(isProcessing: boolean): void;
|
|
12
|
+
enqueue(input: MessageContent, options?: SendOptions, priority?: number): string;
|
|
13
|
+
dequeue(): PendingMessage | null;
|
|
14
|
+
peek(): PendingMessage | null;
|
|
15
|
+
cancel(messageId: string): boolean;
|
|
16
|
+
clear(): void;
|
|
17
|
+
isEmpty(): boolean;
|
|
18
|
+
size(): number;
|
|
19
|
+
getStatus(): MessageQueueStatus;
|
|
20
|
+
toSnapshot(): MessageQueueSnapshot;
|
|
21
|
+
static fromSnapshot(snapshot: MessageQueueSnapshot): MessageQueue;
|
|
22
|
+
private _sort;
|
|
23
|
+
}
|
package/dist/state/types.d.ts
CHANGED
|
@@ -18,6 +18,8 @@ export declare const StateKeys: {
|
|
|
18
18
|
readonly CHECKPOINT: "checkpoint";
|
|
19
19
|
/** CompressionState data */
|
|
20
20
|
readonly COMPRESSION: "compression";
|
|
21
|
+
/** Persisted compressed working view used for runtime resume/looping */
|
|
22
|
+
readonly COMPRESSION_VIEW: "compression-view";
|
|
21
23
|
/** SessionSnapshot data */
|
|
22
24
|
readonly SESSION: "session";
|
|
23
25
|
/**
|
|
@@ -71,6 +73,27 @@ export interface CompressionState {
|
|
|
71
73
|
* This can be used when resuming from a checkpoint to provide context.
|
|
72
74
|
*/
|
|
73
75
|
summary?: string;
|
|
76
|
+
/**
|
|
77
|
+
* Timestamp of the last smart-mode summary compression (ms).
|
|
78
|
+
*/
|
|
79
|
+
lastSummaryAt?: number;
|
|
80
|
+
/**
|
|
81
|
+
* Estimated token count before the last persisted summary compression.
|
|
82
|
+
*/
|
|
83
|
+
lastSummaryInputTokens?: number;
|
|
84
|
+
/**
|
|
85
|
+
* Estimated token count for the persisted summary view after the last summary
|
|
86
|
+
* compression, before any temporary tool-output clearing for the live LLM call.
|
|
87
|
+
*/
|
|
88
|
+
lastSummaryOutputTokens?: number;
|
|
89
|
+
/**
|
|
90
|
+
* Number of messages removed by the last persisted summary compression.
|
|
91
|
+
*/
|
|
92
|
+
lastSummaryRemovedMessages?: number;
|
|
93
|
+
/**
|
|
94
|
+
* Whether the persisted summary was rewritten to fit the bounded summary budget.
|
|
95
|
+
*/
|
|
96
|
+
lastSummaryRewriteApplied?: boolean;
|
|
74
97
|
/**
|
|
75
98
|
* Last update timestamp (ms).
|
|
76
99
|
*/
|
|
@@ -96,3 +119,42 @@ export interface CompressionState {
|
|
|
96
119
|
totalMessagesAtCompression: number;
|
|
97
120
|
};
|
|
98
121
|
}
|
|
122
|
+
/**
|
|
123
|
+
* Persisted compressed working view.
|
|
124
|
+
*
|
|
125
|
+
* This is the runtime baseline used for future loop iterations, checkpointing,
|
|
126
|
+
* and resume after a successful compression commit. Raw history is stored
|
|
127
|
+
* separately by the session snapshot for audit/rebuild purposes.
|
|
128
|
+
*/
|
|
129
|
+
export interface CommittedCompressionView {
|
|
130
|
+
/**
|
|
131
|
+
* Number of full messages that were present in the raw view when this
|
|
132
|
+
* compressed working view was produced.
|
|
133
|
+
*/
|
|
134
|
+
baseMessageCount: number;
|
|
135
|
+
/**
|
|
136
|
+
* Deterministic signature of the raw base messages used to validate the
|
|
137
|
+
* committed view against rewrites/forks/truncation.
|
|
138
|
+
*/
|
|
139
|
+
baseMessagesSignature: string;
|
|
140
|
+
/**
|
|
141
|
+
* Compressed working view including system messages and any injected summary.
|
|
142
|
+
*/
|
|
143
|
+
messages: import('../types').Message[];
|
|
144
|
+
/**
|
|
145
|
+
* Rolling summary associated with this working view.
|
|
146
|
+
*/
|
|
147
|
+
summary?: string;
|
|
148
|
+
/**
|
|
149
|
+
* Estimated tokens of the committed working view after compression.
|
|
150
|
+
*/
|
|
151
|
+
tokensAfter: number;
|
|
152
|
+
/**
|
|
153
|
+
* Whether the view came from automatic or manual compression.
|
|
154
|
+
*/
|
|
155
|
+
mode: 'auto' | 'manual';
|
|
156
|
+
/**
|
|
157
|
+
* Creation timestamp (ms).
|
|
158
|
+
*/
|
|
159
|
+
createdAt: number;
|
|
160
|
+
}
|
package/dist/types/common.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { CallToolResult, ContentBlock, ImageContent, TextContent, Tool } from '@modelcontextprotocol/sdk/types.js';
|
|
2
|
+
import type { ModelStopReason } from '../model/types';
|
|
2
3
|
/**
|
|
3
4
|
* Re-export MCP types
|
|
4
5
|
*/
|
|
@@ -52,6 +53,17 @@ export interface Usage {
|
|
|
52
53
|
completionTokens: number;
|
|
53
54
|
totalTokens: number;
|
|
54
55
|
}
|
|
56
|
+
export interface CallModelOnceOptions {
|
|
57
|
+
input: string | MessageContent;
|
|
58
|
+
systemPrompt?: string;
|
|
59
|
+
temperature?: number;
|
|
60
|
+
maxTokens?: number;
|
|
61
|
+
}
|
|
62
|
+
export interface CallModelOnceResult {
|
|
63
|
+
text: string;
|
|
64
|
+
usage?: Usage;
|
|
65
|
+
stopReason: ModelStopReason;
|
|
66
|
+
}
|
|
55
67
|
/**
|
|
56
68
|
* Small reference stored in checkpoint metadata (JSON-safe).
|
|
57
69
|
*
|
package/dist/types/event.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ import type { AgentLoopCheckpoint } from './snapshot';
|
|
|
5
5
|
/**
|
|
6
6
|
* Event types for streaming responses
|
|
7
7
|
*/
|
|
8
|
-
export type AgentEventType = 'text_start' | 'text_delta' | 'text_end' | 'tool_call_start' | 'tool_call_delta' | 'tool_call_end' | 'tool_result' | 'tool_output_start' | 'tool_output_delta' | 'tool_approval_requested' | 'requires_action' | 'tool_skipped' | 'thinking_start' | 'thinking_delta' | 'thinking_end' | 'done' | 'iteration_start' | 'iteration_end' | 'session_created' | 'subagent_event' | 'completion_assessed' | 'compression_start' | 'compression_end';
|
|
8
|
+
export type AgentEventType = 'text_start' | 'text_delta' | 'text_end' | 'tool_call_start' | 'tool_call_delta' | 'tool_call_end' | 'tool_result' | 'tool_output_start' | 'tool_output_delta' | 'tool_approval_requested' | 'requires_action' | 'tool_skipped' | 'thinking_start' | 'thinking_delta' | 'thinking_end' | 'done' | 'iteration_start' | 'iteration_end' | 'session_created' | 'subagent_event' | 'completion_assessed' | 'compression_start' | 'compression_end' | 'hook_evaluation';
|
|
9
9
|
/**
|
|
10
10
|
* Base event interface
|
|
11
11
|
*/
|
|
@@ -13,6 +13,20 @@ export interface BaseEvent {
|
|
|
13
13
|
type: AgentEventType;
|
|
14
14
|
/** Session identifier for this event */
|
|
15
15
|
sessionId: string;
|
|
16
|
+
/**
|
|
17
|
+
* Stream identifier for this prompt/run.
|
|
18
|
+
* Optional for backward compatibility with existing emitters.
|
|
19
|
+
*/
|
|
20
|
+
streamId?: string;
|
|
21
|
+
/**
|
|
22
|
+
* Monotonic sequence number within a stream.
|
|
23
|
+
* Starts from 1 when present.
|
|
24
|
+
*/
|
|
25
|
+
seq?: number;
|
|
26
|
+
/**
|
|
27
|
+
* Whether this event is replayed history rather than live output.
|
|
28
|
+
*/
|
|
29
|
+
replayed?: boolean;
|
|
16
30
|
}
|
|
17
31
|
/**
|
|
18
32
|
* Text start event - marks beginning of a text response
|
|
@@ -107,6 +121,10 @@ export interface ToolApprovalRequestedEvent extends BaseEvent {
|
|
|
107
121
|
export interface RequiresActionEvent extends BaseEvent {
|
|
108
122
|
type: 'requires_action';
|
|
109
123
|
kind: 'tool_approval' | 'ask_user';
|
|
124
|
+
/**
|
|
125
|
+
* Stable action identifier used for resume routing.
|
|
126
|
+
*/
|
|
127
|
+
actionId?: string;
|
|
110
128
|
/**
|
|
111
129
|
* Checkpoint to resume from.
|
|
112
130
|
* If a checkpoint store is configured, this may be omitted in favor of `checkpointRef`.
|
|
@@ -134,6 +152,14 @@ export interface RequiresActionEvent extends BaseEvent {
|
|
|
134
152
|
}>;
|
|
135
153
|
multiSelect: boolean;
|
|
136
154
|
}>;
|
|
155
|
+
/**
|
|
156
|
+
* Structured action error.
|
|
157
|
+
*/
|
|
158
|
+
error?: {
|
|
159
|
+
code: string;
|
|
160
|
+
message: string;
|
|
161
|
+
details?: Record<string, unknown>;
|
|
162
|
+
};
|
|
137
163
|
}
|
|
138
164
|
/**
|
|
139
165
|
* Tool skipped event - emitted when a tool execution is skipped (e.g., approval denied)
|
|
@@ -266,6 +292,14 @@ export interface CompressionStartEvent extends BaseEvent {
|
|
|
266
292
|
tokensBefore: number;
|
|
267
293
|
/** Token threshold that triggered compression */
|
|
268
294
|
threshold: number;
|
|
295
|
+
lastTurnTokens?: number;
|
|
296
|
+
compressAfterLastUser?: boolean;
|
|
297
|
+
summaryProtectedStart?: number;
|
|
298
|
+
toolProtectedStart?: number;
|
|
299
|
+
protectedToolCount?: number;
|
|
300
|
+
latestToolIndex?: number;
|
|
301
|
+
latestToolTokens?: number;
|
|
302
|
+
latestToolOversized?: boolean;
|
|
269
303
|
}
|
|
270
304
|
/**
|
|
271
305
|
* Compression end event - emitted when AI-based summary compression completes.
|
|
@@ -287,7 +321,34 @@ export interface CompressionEndEvent extends BaseEvent {
|
|
|
287
321
|
/** Time taken for compression in milliseconds */
|
|
288
322
|
elapsedMs: number;
|
|
289
323
|
}
|
|
324
|
+
/**
|
|
325
|
+
* Hook evaluation event - emitted during prompt-based hook evaluation.
|
|
326
|
+
*
|
|
327
|
+
* Uses a single event type with `phase` for easier integration:
|
|
328
|
+
* - `start`: prompt evaluation request started
|
|
329
|
+
* - `stream`: incremental text delta from model
|
|
330
|
+
* - `end`: evaluation finished (success/error/timeout)
|
|
331
|
+
*/
|
|
332
|
+
export interface HookEvaluationEvent extends BaseEvent {
|
|
333
|
+
type: 'hook_evaluation';
|
|
334
|
+
evaluationId: string;
|
|
335
|
+
hookName: 'permissionRequest' | 'preToolUse' | 'postToolUse' | 'postToolUseFailure' | 'subagentStop' | 'userPromptSubmit';
|
|
336
|
+
phase: 'start' | 'stream' | 'end';
|
|
337
|
+
prompt?: string;
|
|
338
|
+
input?: unknown;
|
|
339
|
+
delta?: string;
|
|
340
|
+
rawResponse?: string;
|
|
341
|
+
result?: unknown;
|
|
342
|
+
usage?: Usage;
|
|
343
|
+
durationMs?: number;
|
|
344
|
+
status?: 'success' | 'error' | 'timeout';
|
|
345
|
+
error?: {
|
|
346
|
+
code?: string;
|
|
347
|
+
message: string;
|
|
348
|
+
};
|
|
349
|
+
toolCallId?: string;
|
|
350
|
+
}
|
|
290
351
|
/**
|
|
291
352
|
* Union type for all agent events
|
|
292
353
|
*/
|
|
293
|
-
export type AgentEvent = TextStartEvent | TextDeltaEvent | TextEndEvent | ToolCallStartEvent | ToolCallDeltaEvent | ToolCallEndEvent | ToolResultEvent | ToolOutputStartEvent | ToolOutputDeltaEvent | ToolApprovalRequestedEvent | RequiresActionEvent | ToolSkippedEvent | ThinkingStartEvent | ThinkingDeltaEvent | ThinkingEndEvent | DoneEvent | IterationStartEvent | IterationEndEvent | SessionCreatedEvent | SubagentEvent | CompletionAssessedEvent | CompressionStartEvent | CompressionEndEvent;
|
|
354
|
+
export type AgentEvent = TextStartEvent | TextDeltaEvent | TextEndEvent | ToolCallStartEvent | ToolCallDeltaEvent | ToolCallEndEvent | ToolResultEvent | ToolOutputStartEvent | ToolOutputDeltaEvent | ToolApprovalRequestedEvent | RequiresActionEvent | ToolSkippedEvent | ThinkingStartEvent | ThinkingDeltaEvent | ThinkingEndEvent | DoneEvent | IterationStartEvent | IterationEndEvent | SessionCreatedEvent | SubagentEvent | CompletionAssessedEvent | CompressionStartEvent | CompressionEndEvent | HookEvaluationEvent;
|
package/dist/types/index.d.ts
CHANGED
package/dist/types/snapshot.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { ToolCallWithResult } from '../agent/types';
|
|
2
2
|
import type { ModelStopReason } from '../model/types';
|
|
3
|
+
import type { MessageQueueSnapshot } from '../session/types';
|
|
3
4
|
import type { Usage } from './common';
|
|
4
5
|
import type { Message } from './message';
|
|
5
6
|
/**
|
|
@@ -141,6 +142,12 @@ export interface ConversationContext {
|
|
|
141
142
|
* Full message history
|
|
142
143
|
*/
|
|
143
144
|
messages: Message[];
|
|
145
|
+
/**
|
|
146
|
+
* Raw uncompressed message history kept for audit/rebuild.
|
|
147
|
+
* Absent in legacy snapshots, in which case `messages` is treated as both
|
|
148
|
+
* the working and raw view.
|
|
149
|
+
*/
|
|
150
|
+
rawMessages?: Message[];
|
|
144
151
|
/**
|
|
145
152
|
* Total message count
|
|
146
153
|
*/
|
|
@@ -207,6 +214,10 @@ export interface SessionSnapshot {
|
|
|
207
214
|
* User-defined metadata
|
|
208
215
|
*/
|
|
209
216
|
metadata?: Record<string, unknown>;
|
|
217
|
+
/**
|
|
218
|
+
* Optional message queue snapshot.
|
|
219
|
+
*/
|
|
220
|
+
messageQueue?: MessageQueueSnapshot;
|
|
210
221
|
}
|
|
211
222
|
/**
|
|
212
223
|
* Model configuration stored in checkpoint (serializable)
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "goatchain",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.30",
|
|
5
5
|
"workspaces": [
|
|
6
6
|
"packages/*"
|
|
7
7
|
],
|
|
8
|
-
"packageManager": "pnpm@10.
|
|
8
|
+
"packageManager": "pnpm@10.30.3",
|
|
9
9
|
"description": "",
|
|
10
10
|
"author": "Dim Code",
|
|
11
11
|
"keywords": [],
|
|
@@ -69,15 +69,15 @@
|
|
|
69
69
|
"dependencies": {
|
|
70
70
|
"@agentclientprotocol/sdk": "^0.12.0",
|
|
71
71
|
"@anthropic-ai/sdk": "^0.40.1",
|
|
72
|
-
"@google/genai": "^1.
|
|
73
|
-
"@modelcontextprotocol/sdk": "^1.
|
|
72
|
+
"@google/genai": "^1.43.0",
|
|
73
|
+
"@modelcontextprotocol/sdk": "^1.27.1",
|
|
74
74
|
"@simon_he/vue-tui": "^0.0.3",
|
|
75
|
-
"adm-zip": "^0.5.
|
|
75
|
+
"adm-zip": "^0.5.16",
|
|
76
76
|
"cheerio": "^1.2.0",
|
|
77
77
|
"fast-glob": "^3.3.3",
|
|
78
|
-
"file-type": "^19.
|
|
78
|
+
"file-type": "^19.6.0",
|
|
79
79
|
"mammoth": "^1.11.0",
|
|
80
|
-
"openai": "^6.
|
|
80
|
+
"openai": "^6.25.0",
|
|
81
81
|
"pdf-parse": "^2.4.5",
|
|
82
82
|
"picomatch": "^4.0.3",
|
|
83
83
|
"pptx-parser": "^1.1.7-beta.9",
|
|
@@ -86,27 +86,27 @@
|
|
|
86
86
|
"xlsx": "^0.18.5"
|
|
87
87
|
},
|
|
88
88
|
"devDependencies": {
|
|
89
|
-
"@antfu/eslint-config": "^6.7.
|
|
90
|
-
"@changesets/cli": "^2.29.
|
|
91
|
-
"@slidev/cli": "^52.
|
|
89
|
+
"@antfu/eslint-config": "^6.7.3",
|
|
90
|
+
"@changesets/cli": "^2.29.8",
|
|
91
|
+
"@slidev/cli": "^52.13.0",
|
|
92
92
|
"@slidev/theme-default": "^0.25.0",
|
|
93
|
-
"@sxzz/prettier-config": "^2.
|
|
94
|
-
"@tsconfig/recommended": "^1.0.
|
|
95
|
-
"@types/node": "^22.13
|
|
93
|
+
"@sxzz/prettier-config": "^2.3.1",
|
|
94
|
+
"@tsconfig/recommended": "^1.0.13",
|
|
95
|
+
"@types/node": "^22.19.13",
|
|
96
|
+
"@types/picomatch": "^4.0.2",
|
|
96
97
|
"@types/semver": "^7.7.1",
|
|
97
98
|
"@types/turndown": "^5.0.6",
|
|
98
|
-
"
|
|
99
|
-
"bumpp": "^10.3.2",
|
|
99
|
+
"bumpp": "^10.4.1",
|
|
100
100
|
"bun-types": "latest",
|
|
101
|
-
"chokidar": "^4.0.
|
|
102
|
-
"dotenv": "^17.
|
|
103
|
-
"eslint": "^9.
|
|
101
|
+
"chokidar": "^4.0.3",
|
|
102
|
+
"dotenv": "^17.3.1",
|
|
103
|
+
"eslint": "^9.39.3",
|
|
104
104
|
"esno": "^4.8.0",
|
|
105
105
|
"picocolors": "^1.1.1",
|
|
106
|
-
"prettier": "^3.
|
|
107
|
-
"tsx": "^4.
|
|
108
|
-
"typescript": "^5.9.
|
|
109
|
-
"typescript-eslint": "^8.
|
|
106
|
+
"prettier": "^3.8.1",
|
|
107
|
+
"tsx": "^4.21.0",
|
|
108
|
+
"typescript": "^5.9.3",
|
|
109
|
+
"typescript-eslint": "^8.56.1"
|
|
110
110
|
},
|
|
111
111
|
"trustedDependencies": [
|
|
112
112
|
"@ast-grep/cli",
|