@avasis-ai/synthcode 1.0.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/LICENSE +21 -0
- package/README.md +292 -0
- package/dist/chunk-53ZOIXM4.js +624 -0
- package/dist/chunk-53ZOIXM4.js.map +1 -0
- package/dist/chunk-BWXHO6UJ.js +115 -0
- package/dist/chunk-BWXHO6UJ.js.map +1 -0
- package/dist/chunk-CARUMOML.js +123 -0
- package/dist/chunk-CARUMOML.js.map +1 -0
- package/dist/chunk-DGUM43GV.js +11 -0
- package/dist/chunk-DGUM43GV.js.map +1 -0
- package/dist/chunk-F34HO4RA.js +487 -0
- package/dist/chunk-F34HO4RA.js.map +1 -0
- package/dist/chunk-FK7S2S7V.js +132 -0
- package/dist/chunk-FK7S2S7V.js.map +1 -0
- package/dist/chunk-MQ7XP6VT.js +174 -0
- package/dist/chunk-MQ7XP6VT.js.map +1 -0
- package/dist/chunk-TLPOO6C3.js +176 -0
- package/dist/chunk-TLPOO6C3.js.map +1 -0
- package/dist/chunk-W6OLZ2OI.js +56 -0
- package/dist/chunk-W6OLZ2OI.js.map +1 -0
- package/dist/cli/index.cjs +151 -0
- package/dist/cli/index.cjs.map +1 -0
- package/dist/cli/index.d.cts +1 -0
- package/dist/cli/index.d.ts +1 -0
- package/dist/cli/index.js +8 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/run.cjs +128 -0
- package/dist/cli/run.cjs.map +1 -0
- package/dist/cli/run.d.cts +1 -0
- package/dist/cli/run.d.ts +1 -0
- package/dist/cli/run.js +126 -0
- package/dist/cli/run.js.map +1 -0
- package/dist/index-D-K6sx8s.d.cts +8 -0
- package/dist/index-D-K6sx8s.d.ts +8 -0
- package/dist/index.cjs +2909 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +274 -0
- package/dist/index.d.ts +274 -0
- package/dist/index.js +1048 -0
- package/dist/index.js.map +1 -0
- package/dist/llm/index.cjs +531 -0
- package/dist/llm/index.cjs.map +1 -0
- package/dist/llm/index.d.cts +70 -0
- package/dist/llm/index.d.ts +70 -0
- package/dist/llm/index.js +24 -0
- package/dist/llm/index.js.map +1 -0
- package/dist/mcp/index.cjs +323 -0
- package/dist/mcp/index.cjs.map +1 -0
- package/dist/mcp/index.d.cts +39 -0
- package/dist/mcp/index.d.ts +39 -0
- package/dist/mcp/index.js +11 -0
- package/dist/mcp/index.js.map +1 -0
- package/dist/memory/index.cjs +146 -0
- package/dist/memory/index.cjs.map +1 -0
- package/dist/memory/index.d.cts +51 -0
- package/dist/memory/index.d.ts +51 -0
- package/dist/memory/index.js +10 -0
- package/dist/memory/index.js.map +1 -0
- package/dist/tools/fuzzy-edit.cjs +200 -0
- package/dist/tools/fuzzy-edit.cjs.map +1 -0
- package/dist/tools/fuzzy-edit.d.cts +9 -0
- package/dist/tools/fuzzy-edit.d.ts +9 -0
- package/dist/tools/fuzzy-edit.js +12 -0
- package/dist/tools/fuzzy-edit.js.map +1 -0
- package/dist/tools/index.cjs +1032 -0
- package/dist/tools/index.cjs.map +1 -0
- package/dist/tools/index.d.cts +4 -0
- package/dist/tools/index.d.ts +4 -0
- package/dist/tools/index.js +39 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/types-C11cw5ZD.d.cts +177 -0
- package/dist/types-C11cw5ZD.d.ts +177 -0
- package/dist/utils-TF4TBXQJ.js +10 -0
- package/dist/utils-TF4TBXQJ.js.map +1 -0
- package/dist/web-fetch-B42QzYD2.d.cts +85 -0
- package/dist/web-fetch-EDdhxmEf.d.ts +85 -0
- package/package.json +134 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
import { g as Message, h as CompactionResult, i as AgentConfig, T as Tool, L as LoopEvent, j as ContextConfig, k as PermissionConfig, f as Provider, e as TokenUsage } from './types-C11cw5ZD.cjs';
|
|
2
|
+
export { A as APIToolDefinition, l as AssistantMessage, B as BaseProvider, c as ChatMessage, C as ChatRequest, m as ContentBlock, D as DEFAULT_COMPACT_THRESHOLD, n as DEFAULT_CONTEXT_WINDOW, o as DEFAULT_MAX_OUTPUT_TOKENS, p as DEFAULT_MAX_TURNS, q as MAX_CONCURRENT_TOOLS, M as ModelResponse, R as RetryableError, r as TextBlock, s as ThinkingBlock, t as ToolContext, a as ToolExecuteOptions, u as ToolResultMessage, v as ToolUseBlock, U as UserMessage, d as defineTool, b as defineToolFromClass } from './types-C11cw5ZD.cjs';
|
|
3
|
+
import { MemoryStore } from './memory/index.cjs';
|
|
4
|
+
export { InMemoryStore, SQLiteStore } from './memory/index.cjs';
|
|
5
|
+
import { d as ToolRegistry } from './web-fetch-B42QzYD2.cjs';
|
|
6
|
+
export { B as BashTool, F as FileEditTool, a as FileReadTool, b as FileWriteTool, G as GlobTool, c as GrepTool, T as ToolExecutionResult, W as WebFetchTool, o as orchestrateTools } from './web-fetch-B42QzYD2.cjs';
|
|
7
|
+
export { AnthropicProvider, OllamaProvider, OpenAIProvider, anthropic, createProvider, ollama, openai } from './llm/index.cjs';
|
|
8
|
+
export { MCPClient, MCPServerConfig, MCPToolDefinition, loadMCPTools } from './mcp/index.cjs';
|
|
9
|
+
export { I as InitOptions, i as init } from './index-D-K6sx8s.cjs';
|
|
10
|
+
import 'zod';
|
|
11
|
+
|
|
12
|
+
interface AgentHooks {
|
|
13
|
+
onTurnStart?: (turn: number, messages: Message[]) => Promise<Message[] | void>;
|
|
14
|
+
onTurnEnd?: (turn: number, messages: Message[]) => Promise<void>;
|
|
15
|
+
onToolUse?: (name: string, input: Record<string, unknown>) => Promise<{
|
|
16
|
+
allow?: boolean;
|
|
17
|
+
input?: Record<string, unknown>;
|
|
18
|
+
} | void>;
|
|
19
|
+
onToolResult?: (result: {
|
|
20
|
+
id: string;
|
|
21
|
+
name: string;
|
|
22
|
+
output: string;
|
|
23
|
+
isError: boolean;
|
|
24
|
+
durationMs: number;
|
|
25
|
+
}) => Promise<string | void>;
|
|
26
|
+
onError?: (error: Error, turn: number) => Promise<{
|
|
27
|
+
retry?: boolean;
|
|
28
|
+
message?: string;
|
|
29
|
+
} | void>;
|
|
30
|
+
onCompact?: (result: CompactionResult) => Promise<void>;
|
|
31
|
+
}
|
|
32
|
+
declare class HookRunner {
|
|
33
|
+
private hooks;
|
|
34
|
+
constructor(hooks?: AgentHooks);
|
|
35
|
+
runOnTurnStart(turn: number, messages: Message[]): Promise<Message[]>;
|
|
36
|
+
runOnTurnEnd(turn: number, messages: Message[]): Promise<void>;
|
|
37
|
+
runOnToolUse(name: string, input: Record<string, unknown>): Promise<{
|
|
38
|
+
allow: boolean;
|
|
39
|
+
input: Record<string, unknown>;
|
|
40
|
+
}>;
|
|
41
|
+
runOnToolResult(result: {
|
|
42
|
+
id: string;
|
|
43
|
+
name: string;
|
|
44
|
+
output: string;
|
|
45
|
+
isError: boolean;
|
|
46
|
+
durationMs: number;
|
|
47
|
+
}): Promise<string>;
|
|
48
|
+
runOnError(error: Error, turn: number): Promise<{
|
|
49
|
+
retry: boolean;
|
|
50
|
+
message?: string;
|
|
51
|
+
}>;
|
|
52
|
+
runOnCompact(result: CompactionResult): Promise<void>;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
interface CostRecord {
|
|
56
|
+
model: string;
|
|
57
|
+
inputTokens: number;
|
|
58
|
+
outputTokens: number;
|
|
59
|
+
cacheReadTokens: number;
|
|
60
|
+
cacheWriteTokens: number;
|
|
61
|
+
inputCost: number;
|
|
62
|
+
outputCost: number;
|
|
63
|
+
timestamp: number;
|
|
64
|
+
turn: number;
|
|
65
|
+
toolName?: string;
|
|
66
|
+
}
|
|
67
|
+
interface ModelPricing {
|
|
68
|
+
inputCostPer1k: number;
|
|
69
|
+
outputCostPer1k: number;
|
|
70
|
+
}
|
|
71
|
+
declare const DEFAULT_PRICING: Record<string, ModelPricing>;
|
|
72
|
+
declare class CostTracker {
|
|
73
|
+
private records;
|
|
74
|
+
private pricing;
|
|
75
|
+
constructor(customPricing?: Record<string, ModelPricing>);
|
|
76
|
+
record(model: string, usage: {
|
|
77
|
+
inputTokens: number;
|
|
78
|
+
outputTokens: number;
|
|
79
|
+
cacheReadTokens?: number;
|
|
80
|
+
cacheWriteTokens?: number;
|
|
81
|
+
}, turn: number, toolName?: string): void;
|
|
82
|
+
getTotal(): {
|
|
83
|
+
cost: number;
|
|
84
|
+
inputTokens: number;
|
|
85
|
+
outputTokens: number;
|
|
86
|
+
cacheReadTokens: number;
|
|
87
|
+
cacheWriteTokens: number;
|
|
88
|
+
};
|
|
89
|
+
getByModel(): Record<string, {
|
|
90
|
+
cost: number;
|
|
91
|
+
calls: number;
|
|
92
|
+
}>;
|
|
93
|
+
getByTool(): Record<string, {
|
|
94
|
+
cost: number;
|
|
95
|
+
calls: number;
|
|
96
|
+
}>;
|
|
97
|
+
getRecords(): CostRecord[];
|
|
98
|
+
reset(): void;
|
|
99
|
+
setPricing(model: string, pricing: ModelPricing): void;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
interface AgentConfigV2 extends AgentConfig {
|
|
103
|
+
hooks?: AgentHooks;
|
|
104
|
+
memory?: MemoryStore;
|
|
105
|
+
threadId?: string;
|
|
106
|
+
costTracker?: CostTracker;
|
|
107
|
+
title?: string;
|
|
108
|
+
disableTitle?: boolean;
|
|
109
|
+
}
|
|
110
|
+
declare class Agent {
|
|
111
|
+
private model;
|
|
112
|
+
private tools;
|
|
113
|
+
private systemPrompt;
|
|
114
|
+
private maxTurns;
|
|
115
|
+
private contextManager;
|
|
116
|
+
private permissionEngine;
|
|
117
|
+
private permissionConfig?;
|
|
118
|
+
private cwd;
|
|
119
|
+
private maxRetries;
|
|
120
|
+
private messages;
|
|
121
|
+
private hooks?;
|
|
122
|
+
private memory?;
|
|
123
|
+
private threadId?;
|
|
124
|
+
private costTracker;
|
|
125
|
+
private _loaded;
|
|
126
|
+
private _title?;
|
|
127
|
+
private _titleFetched;
|
|
128
|
+
private _disableTitle;
|
|
129
|
+
constructor(config: AgentConfig | AgentConfigV2);
|
|
130
|
+
addTool(tool: Tool): void;
|
|
131
|
+
addMessage(message: Message): void;
|
|
132
|
+
reset(): void;
|
|
133
|
+
getMessages(): Message[];
|
|
134
|
+
getCostTracker(): CostTracker;
|
|
135
|
+
get title(): string | undefined;
|
|
136
|
+
private loadMemory;
|
|
137
|
+
private saveMemory;
|
|
138
|
+
fork(newThreadId?: string): Agent;
|
|
139
|
+
run(prompt: string, options?: {
|
|
140
|
+
abortSignal?: AbortSignal;
|
|
141
|
+
}): AsyncGenerator<LoopEvent>;
|
|
142
|
+
chat(prompt: string, options?: {
|
|
143
|
+
abortSignal?: AbortSignal;
|
|
144
|
+
}): Promise<{
|
|
145
|
+
text: string;
|
|
146
|
+
usage: {
|
|
147
|
+
inputTokens: number;
|
|
148
|
+
outputTokens: number;
|
|
149
|
+
};
|
|
150
|
+
messages: Message[];
|
|
151
|
+
cost: number;
|
|
152
|
+
}>;
|
|
153
|
+
structured<T>(prompt: string, schema: {
|
|
154
|
+
safeParse: (data: unknown) => {
|
|
155
|
+
success: boolean;
|
|
156
|
+
data?: T;
|
|
157
|
+
error?: {
|
|
158
|
+
issues: Array<{
|
|
159
|
+
path: (string | number)[];
|
|
160
|
+
message: string;
|
|
161
|
+
}>;
|
|
162
|
+
};
|
|
163
|
+
};
|
|
164
|
+
}, options?: {
|
|
165
|
+
abortSignal?: AbortSignal;
|
|
166
|
+
maxRetries?: number;
|
|
167
|
+
}): Promise<T>;
|
|
168
|
+
structuredViaTool<T>(prompt: string, schema: {
|
|
169
|
+
safeParse: (data: unknown) => {
|
|
170
|
+
success: boolean;
|
|
171
|
+
data?: T;
|
|
172
|
+
error?: {
|
|
173
|
+
issues: Array<{
|
|
174
|
+
path: (string | number)[];
|
|
175
|
+
message: string;
|
|
176
|
+
}>;
|
|
177
|
+
};
|
|
178
|
+
};
|
|
179
|
+
}, options?: {
|
|
180
|
+
abortSignal?: AbortSignal;
|
|
181
|
+
maxRetries?: number;
|
|
182
|
+
}): Promise<T>;
|
|
183
|
+
asTool(options?: {
|
|
184
|
+
allowSubAgents?: boolean;
|
|
185
|
+
name?: string;
|
|
186
|
+
description?: string;
|
|
187
|
+
}): Promise<Tool>;
|
|
188
|
+
private generateTitle;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
interface ContextCheck {
|
|
192
|
+
totalTokens: number;
|
|
193
|
+
availableTokens: number;
|
|
194
|
+
usagePercent: number;
|
|
195
|
+
needsCompact: boolean;
|
|
196
|
+
recommendedMethod: "snip" | "compact";
|
|
197
|
+
}
|
|
198
|
+
declare class ContextManager {
|
|
199
|
+
readonly maxTokens: number;
|
|
200
|
+
readonly maxOutputTokens: number;
|
|
201
|
+
readonly compactThreshold: number;
|
|
202
|
+
constructor(config?: ContextConfig);
|
|
203
|
+
check(messages: Message[]): ContextCheck;
|
|
204
|
+
compact(messages: Message[], summaryFn?: (messages: Message[]) => Promise<string>): Promise<CompactionResult>;
|
|
205
|
+
pruneToolOutputs(messages: Message[]): Message[];
|
|
206
|
+
getAvailableTokens(messages: Message[]): number;
|
|
207
|
+
getUsagePercent(messages: Message[]): number;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
interface PermissionResult {
|
|
211
|
+
allowed: boolean;
|
|
212
|
+
reason?: string;
|
|
213
|
+
}
|
|
214
|
+
declare class PermissionEngine {
|
|
215
|
+
private allowedPatterns;
|
|
216
|
+
private deniedPatterns;
|
|
217
|
+
private askPatterns;
|
|
218
|
+
private defaultAction;
|
|
219
|
+
constructor(config?: PermissionConfig);
|
|
220
|
+
check(toolName: string, _input?: Record<string, unknown>): PermissionResult;
|
|
221
|
+
addAllowed(pattern: string): void;
|
|
222
|
+
addDenied(pattern: string): void;
|
|
223
|
+
addAsk(pattern: string): void;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
interface AgentLoopConfig {
|
|
227
|
+
model: Provider;
|
|
228
|
+
tools: ToolRegistry;
|
|
229
|
+
messages: Message[];
|
|
230
|
+
systemPrompt?: string;
|
|
231
|
+
maxTurns?: number;
|
|
232
|
+
contextManager: ContextManager;
|
|
233
|
+
permissionEngine: PermissionEngine;
|
|
234
|
+
cwd?: string;
|
|
235
|
+
abortSignal?: AbortSignal;
|
|
236
|
+
maxRetries?: number;
|
|
237
|
+
hooks?: AgentHooks;
|
|
238
|
+
costTracker?: CostTracker;
|
|
239
|
+
}
|
|
240
|
+
declare function agentLoop(config: AgentLoopConfig): AsyncGenerator<LoopEvent>;
|
|
241
|
+
|
|
242
|
+
interface TokenCount {
|
|
243
|
+
total: number;
|
|
244
|
+
byRole: Record<string, number>;
|
|
245
|
+
}
|
|
246
|
+
declare function estimateTokens(text: string): number;
|
|
247
|
+
declare function estimateMessageTokens(message: Message): number;
|
|
248
|
+
declare function estimateConversationTokens(messages: Message[]): TokenCount;
|
|
249
|
+
|
|
250
|
+
interface StreamEvent {
|
|
251
|
+
type: "text_delta" | "tool_use_start" | "tool_use_delta" | "tool_result" | "done" | "error";
|
|
252
|
+
text?: string;
|
|
253
|
+
id?: string;
|
|
254
|
+
name?: string;
|
|
255
|
+
input?: string;
|
|
256
|
+
output?: string;
|
|
257
|
+
usage?: TokenUsage;
|
|
258
|
+
error?: Error;
|
|
259
|
+
}
|
|
260
|
+
declare function createStreamAggregator(): {
|
|
261
|
+
push: (event: StreamEvent) => void;
|
|
262
|
+
getResponse: () => {
|
|
263
|
+
text: string;
|
|
264
|
+
toolCalls: {
|
|
265
|
+
id: string;
|
|
266
|
+
name: string;
|
|
267
|
+
input: string;
|
|
268
|
+
}[];
|
|
269
|
+
usage?: TokenUsage;
|
|
270
|
+
stopReason: string;
|
|
271
|
+
};
|
|
272
|
+
};
|
|
273
|
+
|
|
274
|
+
export { Agent, AgentConfig, type AgentConfigV2, type AgentHooks, type AgentLoopConfig, CompactionResult, type ContextCheck, ContextConfig, ContextManager, type CostRecord, CostTracker, DEFAULT_PRICING, HookRunner, LoopEvent, MemoryStore, Message, type ModelPricing, PermissionConfig, PermissionEngine, type PermissionResult, Provider, type StreamEvent, type TokenCount, TokenUsage, Tool, ToolRegistry, agentLoop, createStreamAggregator, estimateConversationTokens, estimateMessageTokens, estimateTokens };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
import { g as Message, h as CompactionResult, i as AgentConfig, T as Tool, L as LoopEvent, j as ContextConfig, k as PermissionConfig, f as Provider, e as TokenUsage } from './types-C11cw5ZD.js';
|
|
2
|
+
export { A as APIToolDefinition, l as AssistantMessage, B as BaseProvider, c as ChatMessage, C as ChatRequest, m as ContentBlock, D as DEFAULT_COMPACT_THRESHOLD, n as DEFAULT_CONTEXT_WINDOW, o as DEFAULT_MAX_OUTPUT_TOKENS, p as DEFAULT_MAX_TURNS, q as MAX_CONCURRENT_TOOLS, M as ModelResponse, R as RetryableError, r as TextBlock, s as ThinkingBlock, t as ToolContext, a as ToolExecuteOptions, u as ToolResultMessage, v as ToolUseBlock, U as UserMessage, d as defineTool, b as defineToolFromClass } from './types-C11cw5ZD.js';
|
|
3
|
+
import { MemoryStore } from './memory/index.js';
|
|
4
|
+
export { InMemoryStore, SQLiteStore } from './memory/index.js';
|
|
5
|
+
import { d as ToolRegistry } from './web-fetch-EDdhxmEf.js';
|
|
6
|
+
export { B as BashTool, F as FileEditTool, a as FileReadTool, b as FileWriteTool, G as GlobTool, c as GrepTool, T as ToolExecutionResult, W as WebFetchTool, o as orchestrateTools } from './web-fetch-EDdhxmEf.js';
|
|
7
|
+
export { AnthropicProvider, OllamaProvider, OpenAIProvider, anthropic, createProvider, ollama, openai } from './llm/index.js';
|
|
8
|
+
export { MCPClient, MCPServerConfig, MCPToolDefinition, loadMCPTools } from './mcp/index.js';
|
|
9
|
+
export { I as InitOptions, i as init } from './index-D-K6sx8s.js';
|
|
10
|
+
import 'zod';
|
|
11
|
+
|
|
12
|
+
interface AgentHooks {
|
|
13
|
+
onTurnStart?: (turn: number, messages: Message[]) => Promise<Message[] | void>;
|
|
14
|
+
onTurnEnd?: (turn: number, messages: Message[]) => Promise<void>;
|
|
15
|
+
onToolUse?: (name: string, input: Record<string, unknown>) => Promise<{
|
|
16
|
+
allow?: boolean;
|
|
17
|
+
input?: Record<string, unknown>;
|
|
18
|
+
} | void>;
|
|
19
|
+
onToolResult?: (result: {
|
|
20
|
+
id: string;
|
|
21
|
+
name: string;
|
|
22
|
+
output: string;
|
|
23
|
+
isError: boolean;
|
|
24
|
+
durationMs: number;
|
|
25
|
+
}) => Promise<string | void>;
|
|
26
|
+
onError?: (error: Error, turn: number) => Promise<{
|
|
27
|
+
retry?: boolean;
|
|
28
|
+
message?: string;
|
|
29
|
+
} | void>;
|
|
30
|
+
onCompact?: (result: CompactionResult) => Promise<void>;
|
|
31
|
+
}
|
|
32
|
+
declare class HookRunner {
|
|
33
|
+
private hooks;
|
|
34
|
+
constructor(hooks?: AgentHooks);
|
|
35
|
+
runOnTurnStart(turn: number, messages: Message[]): Promise<Message[]>;
|
|
36
|
+
runOnTurnEnd(turn: number, messages: Message[]): Promise<void>;
|
|
37
|
+
runOnToolUse(name: string, input: Record<string, unknown>): Promise<{
|
|
38
|
+
allow: boolean;
|
|
39
|
+
input: Record<string, unknown>;
|
|
40
|
+
}>;
|
|
41
|
+
runOnToolResult(result: {
|
|
42
|
+
id: string;
|
|
43
|
+
name: string;
|
|
44
|
+
output: string;
|
|
45
|
+
isError: boolean;
|
|
46
|
+
durationMs: number;
|
|
47
|
+
}): Promise<string>;
|
|
48
|
+
runOnError(error: Error, turn: number): Promise<{
|
|
49
|
+
retry: boolean;
|
|
50
|
+
message?: string;
|
|
51
|
+
}>;
|
|
52
|
+
runOnCompact(result: CompactionResult): Promise<void>;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
interface CostRecord {
|
|
56
|
+
model: string;
|
|
57
|
+
inputTokens: number;
|
|
58
|
+
outputTokens: number;
|
|
59
|
+
cacheReadTokens: number;
|
|
60
|
+
cacheWriteTokens: number;
|
|
61
|
+
inputCost: number;
|
|
62
|
+
outputCost: number;
|
|
63
|
+
timestamp: number;
|
|
64
|
+
turn: number;
|
|
65
|
+
toolName?: string;
|
|
66
|
+
}
|
|
67
|
+
interface ModelPricing {
|
|
68
|
+
inputCostPer1k: number;
|
|
69
|
+
outputCostPer1k: number;
|
|
70
|
+
}
|
|
71
|
+
declare const DEFAULT_PRICING: Record<string, ModelPricing>;
|
|
72
|
+
declare class CostTracker {
|
|
73
|
+
private records;
|
|
74
|
+
private pricing;
|
|
75
|
+
constructor(customPricing?: Record<string, ModelPricing>);
|
|
76
|
+
record(model: string, usage: {
|
|
77
|
+
inputTokens: number;
|
|
78
|
+
outputTokens: number;
|
|
79
|
+
cacheReadTokens?: number;
|
|
80
|
+
cacheWriteTokens?: number;
|
|
81
|
+
}, turn: number, toolName?: string): void;
|
|
82
|
+
getTotal(): {
|
|
83
|
+
cost: number;
|
|
84
|
+
inputTokens: number;
|
|
85
|
+
outputTokens: number;
|
|
86
|
+
cacheReadTokens: number;
|
|
87
|
+
cacheWriteTokens: number;
|
|
88
|
+
};
|
|
89
|
+
getByModel(): Record<string, {
|
|
90
|
+
cost: number;
|
|
91
|
+
calls: number;
|
|
92
|
+
}>;
|
|
93
|
+
getByTool(): Record<string, {
|
|
94
|
+
cost: number;
|
|
95
|
+
calls: number;
|
|
96
|
+
}>;
|
|
97
|
+
getRecords(): CostRecord[];
|
|
98
|
+
reset(): void;
|
|
99
|
+
setPricing(model: string, pricing: ModelPricing): void;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
interface AgentConfigV2 extends AgentConfig {
|
|
103
|
+
hooks?: AgentHooks;
|
|
104
|
+
memory?: MemoryStore;
|
|
105
|
+
threadId?: string;
|
|
106
|
+
costTracker?: CostTracker;
|
|
107
|
+
title?: string;
|
|
108
|
+
disableTitle?: boolean;
|
|
109
|
+
}
|
|
110
|
+
declare class Agent {
|
|
111
|
+
private model;
|
|
112
|
+
private tools;
|
|
113
|
+
private systemPrompt;
|
|
114
|
+
private maxTurns;
|
|
115
|
+
private contextManager;
|
|
116
|
+
private permissionEngine;
|
|
117
|
+
private permissionConfig?;
|
|
118
|
+
private cwd;
|
|
119
|
+
private maxRetries;
|
|
120
|
+
private messages;
|
|
121
|
+
private hooks?;
|
|
122
|
+
private memory?;
|
|
123
|
+
private threadId?;
|
|
124
|
+
private costTracker;
|
|
125
|
+
private _loaded;
|
|
126
|
+
private _title?;
|
|
127
|
+
private _titleFetched;
|
|
128
|
+
private _disableTitle;
|
|
129
|
+
constructor(config: AgentConfig | AgentConfigV2);
|
|
130
|
+
addTool(tool: Tool): void;
|
|
131
|
+
addMessage(message: Message): void;
|
|
132
|
+
reset(): void;
|
|
133
|
+
getMessages(): Message[];
|
|
134
|
+
getCostTracker(): CostTracker;
|
|
135
|
+
get title(): string | undefined;
|
|
136
|
+
private loadMemory;
|
|
137
|
+
private saveMemory;
|
|
138
|
+
fork(newThreadId?: string): Agent;
|
|
139
|
+
run(prompt: string, options?: {
|
|
140
|
+
abortSignal?: AbortSignal;
|
|
141
|
+
}): AsyncGenerator<LoopEvent>;
|
|
142
|
+
chat(prompt: string, options?: {
|
|
143
|
+
abortSignal?: AbortSignal;
|
|
144
|
+
}): Promise<{
|
|
145
|
+
text: string;
|
|
146
|
+
usage: {
|
|
147
|
+
inputTokens: number;
|
|
148
|
+
outputTokens: number;
|
|
149
|
+
};
|
|
150
|
+
messages: Message[];
|
|
151
|
+
cost: number;
|
|
152
|
+
}>;
|
|
153
|
+
structured<T>(prompt: string, schema: {
|
|
154
|
+
safeParse: (data: unknown) => {
|
|
155
|
+
success: boolean;
|
|
156
|
+
data?: T;
|
|
157
|
+
error?: {
|
|
158
|
+
issues: Array<{
|
|
159
|
+
path: (string | number)[];
|
|
160
|
+
message: string;
|
|
161
|
+
}>;
|
|
162
|
+
};
|
|
163
|
+
};
|
|
164
|
+
}, options?: {
|
|
165
|
+
abortSignal?: AbortSignal;
|
|
166
|
+
maxRetries?: number;
|
|
167
|
+
}): Promise<T>;
|
|
168
|
+
structuredViaTool<T>(prompt: string, schema: {
|
|
169
|
+
safeParse: (data: unknown) => {
|
|
170
|
+
success: boolean;
|
|
171
|
+
data?: T;
|
|
172
|
+
error?: {
|
|
173
|
+
issues: Array<{
|
|
174
|
+
path: (string | number)[];
|
|
175
|
+
message: string;
|
|
176
|
+
}>;
|
|
177
|
+
};
|
|
178
|
+
};
|
|
179
|
+
}, options?: {
|
|
180
|
+
abortSignal?: AbortSignal;
|
|
181
|
+
maxRetries?: number;
|
|
182
|
+
}): Promise<T>;
|
|
183
|
+
asTool(options?: {
|
|
184
|
+
allowSubAgents?: boolean;
|
|
185
|
+
name?: string;
|
|
186
|
+
description?: string;
|
|
187
|
+
}): Promise<Tool>;
|
|
188
|
+
private generateTitle;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
interface ContextCheck {
|
|
192
|
+
totalTokens: number;
|
|
193
|
+
availableTokens: number;
|
|
194
|
+
usagePercent: number;
|
|
195
|
+
needsCompact: boolean;
|
|
196
|
+
recommendedMethod: "snip" | "compact";
|
|
197
|
+
}
|
|
198
|
+
declare class ContextManager {
|
|
199
|
+
readonly maxTokens: number;
|
|
200
|
+
readonly maxOutputTokens: number;
|
|
201
|
+
readonly compactThreshold: number;
|
|
202
|
+
constructor(config?: ContextConfig);
|
|
203
|
+
check(messages: Message[]): ContextCheck;
|
|
204
|
+
compact(messages: Message[], summaryFn?: (messages: Message[]) => Promise<string>): Promise<CompactionResult>;
|
|
205
|
+
pruneToolOutputs(messages: Message[]): Message[];
|
|
206
|
+
getAvailableTokens(messages: Message[]): number;
|
|
207
|
+
getUsagePercent(messages: Message[]): number;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
interface PermissionResult {
|
|
211
|
+
allowed: boolean;
|
|
212
|
+
reason?: string;
|
|
213
|
+
}
|
|
214
|
+
declare class PermissionEngine {
|
|
215
|
+
private allowedPatterns;
|
|
216
|
+
private deniedPatterns;
|
|
217
|
+
private askPatterns;
|
|
218
|
+
private defaultAction;
|
|
219
|
+
constructor(config?: PermissionConfig);
|
|
220
|
+
check(toolName: string, _input?: Record<string, unknown>): PermissionResult;
|
|
221
|
+
addAllowed(pattern: string): void;
|
|
222
|
+
addDenied(pattern: string): void;
|
|
223
|
+
addAsk(pattern: string): void;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
interface AgentLoopConfig {
|
|
227
|
+
model: Provider;
|
|
228
|
+
tools: ToolRegistry;
|
|
229
|
+
messages: Message[];
|
|
230
|
+
systemPrompt?: string;
|
|
231
|
+
maxTurns?: number;
|
|
232
|
+
contextManager: ContextManager;
|
|
233
|
+
permissionEngine: PermissionEngine;
|
|
234
|
+
cwd?: string;
|
|
235
|
+
abortSignal?: AbortSignal;
|
|
236
|
+
maxRetries?: number;
|
|
237
|
+
hooks?: AgentHooks;
|
|
238
|
+
costTracker?: CostTracker;
|
|
239
|
+
}
|
|
240
|
+
declare function agentLoop(config: AgentLoopConfig): AsyncGenerator<LoopEvent>;
|
|
241
|
+
|
|
242
|
+
interface TokenCount {
|
|
243
|
+
total: number;
|
|
244
|
+
byRole: Record<string, number>;
|
|
245
|
+
}
|
|
246
|
+
declare function estimateTokens(text: string): number;
|
|
247
|
+
declare function estimateMessageTokens(message: Message): number;
|
|
248
|
+
declare function estimateConversationTokens(messages: Message[]): TokenCount;
|
|
249
|
+
|
|
250
|
+
interface StreamEvent {
|
|
251
|
+
type: "text_delta" | "tool_use_start" | "tool_use_delta" | "tool_result" | "done" | "error";
|
|
252
|
+
text?: string;
|
|
253
|
+
id?: string;
|
|
254
|
+
name?: string;
|
|
255
|
+
input?: string;
|
|
256
|
+
output?: string;
|
|
257
|
+
usage?: TokenUsage;
|
|
258
|
+
error?: Error;
|
|
259
|
+
}
|
|
260
|
+
declare function createStreamAggregator(): {
|
|
261
|
+
push: (event: StreamEvent) => void;
|
|
262
|
+
getResponse: () => {
|
|
263
|
+
text: string;
|
|
264
|
+
toolCalls: {
|
|
265
|
+
id: string;
|
|
266
|
+
name: string;
|
|
267
|
+
input: string;
|
|
268
|
+
}[];
|
|
269
|
+
usage?: TokenUsage;
|
|
270
|
+
stopReason: string;
|
|
271
|
+
};
|
|
272
|
+
};
|
|
273
|
+
|
|
274
|
+
export { Agent, AgentConfig, type AgentConfigV2, type AgentHooks, type AgentLoopConfig, CompactionResult, type ContextCheck, ContextConfig, ContextManager, type CostRecord, CostTracker, DEFAULT_PRICING, HookRunner, LoopEvent, MemoryStore, Message, type ModelPricing, PermissionConfig, PermissionEngine, type PermissionResult, Provider, type StreamEvent, type TokenCount, TokenUsage, Tool, ToolRegistry, agentLoop, createStreamAggregator, estimateConversationTokens, estimateMessageTokens, estimateTokens };
|