pulse-coder-engine 0.0.1-alpha.1 → 0.0.1-alpha.11
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/dist/built-in/index.cjs +1778 -0
- package/dist/built-in/index.cjs.map +1 -0
- package/dist/built-in/index.d.cts +3 -0
- package/dist/built-in/index.d.ts +3 -0
- package/dist/built-in/index.js +1735 -0
- package/dist/built-in/index.js.map +1 -0
- package/dist/index-BeWyLfso.d.cts +308 -0
- package/dist/index-BeWyLfso.d.ts +308 -0
- package/dist/index.cjs +2422 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +573 -0
- package/dist/index.d.ts +573 -0
- package/dist/index.js +2363 -0
- package/dist/index.js.map +1 -0
- package/package.json +19 -11
- package/examples/new-engine-usage.ts +0 -52
- package/src/Engine.ts +0 -150
- package/src/ai/index.ts +0 -116
- package/src/built-in/index.ts +0 -27
- package/src/built-in/mcp-plugin/index.ts +0 -104
- package/src/built-in/skills-plugin/index.ts +0 -223
- package/src/built-in/sub-agent-plugin/index.ts +0 -203
- package/src/config/index.ts +0 -35
- package/src/context/index.ts +0 -134
- package/src/core/loop.ts +0 -147
- package/src/index.ts +0 -17
- package/src/plugin/EnginePlugin.ts +0 -60
- package/src/plugin/PluginManager.ts +0 -426
- package/src/plugin/UserConfigPlugin.ts +0 -183
- package/src/prompt/index.ts +0 -1
- package/src/prompt/system.ts +0 -126
- package/src/shared/types.ts +0 -50
- package/src/tools/bash.ts +0 -59
- package/src/tools/clarify.ts +0 -74
- package/src/tools/edit.ts +0 -79
- package/src/tools/grep.ts +0 -148
- package/src/tools/index.ts +0 -44
- package/src/tools/ls.ts +0 -20
- package/src/tools/read.ts +0 -69
- package/src/tools/tavily.ts +0 -55
- package/src/tools/utils.ts +0 -16
- package/src/tools/write.ts +0 -42
- package/tsconfig.json +0 -9
- package/tsup.config.ts +0 -11
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,573 @@
|
|
|
1
|
+
import { C as ClarificationRequest, T as Tool, L as LLMProviderFactory, S as SystemPromptOption, E as EngineHookMap, a as Context, b as ToolExecutionContext, c as EnginePluginLoadOptions, d as ToolHooks, I as ILogger, P as PlanMode, e as EngineHookName } from './index-BeWyLfso.cjs';
|
|
2
|
+
export { A as AfterLLMCallInput, f as AfterRunInput, g as AfterToolCallInput, h as AfterToolCallResult, B as BeforeLLMCallInput, i as BeforeLLMCallResult, j as BeforeRunInput, k as BeforeRunResult, l as BeforeToolCallInput, m as BeforeToolCallResult, n as BuiltInPlanModeService, o as BuiltInSkillRegistry, p as EnginePlugin, q as EnginePluginContext, M as ModePolicy, r as PlanIntentLabel, s as PlanModeEvent, t as PlanModeEventName, u as PlanModeService, v as PlanModeTransitionResult, w as ToolCategory, x as ToolMeta, y as ToolRisk, z as builtInMCPPlugin, D as builtInPlanModePlugin, F as builtInPlugins, G as builtInSkillsPlugin } from './index-BeWyLfso.cjs';
|
|
3
|
+
import { StepResult, ModelMessage, ToolSet, streamText, Tool as Tool$1 } from 'ai';
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
import 'events';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Hook arrays passed into the loop by Engine.
|
|
9
|
+
* Each array may contain handlers from multiple plugins + EngineOptions.
|
|
10
|
+
*/
|
|
11
|
+
interface LoopHooks {
|
|
12
|
+
beforeLLMCall?: Array<EngineHookMap['beforeLLMCall']>;
|
|
13
|
+
afterLLMCall?: Array<EngineHookMap['afterLLMCall']>;
|
|
14
|
+
beforeToolCall?: Array<EngineHookMap['beforeToolCall']>;
|
|
15
|
+
afterToolCall?: Array<EngineHookMap['afterToolCall']>;
|
|
16
|
+
}
|
|
17
|
+
interface LoopOptions {
|
|
18
|
+
onText?: (delta: string) => void;
|
|
19
|
+
onToolCall?: (toolCall: any) => void;
|
|
20
|
+
onToolResult?: (toolResult: any) => void;
|
|
21
|
+
onStepFinish?: (step: StepResult<any>) => void;
|
|
22
|
+
onClarificationRequest?: (request: ClarificationRequest) => Promise<string>;
|
|
23
|
+
onCompacted?: (newMessages: ModelMessage[]) => void;
|
|
24
|
+
onResponse?: (messages: StepResult<ToolSet>['response']['messages']) => void;
|
|
25
|
+
abortSignal?: AbortSignal;
|
|
26
|
+
tools?: Record<string, Tool>;
|
|
27
|
+
/** Custom LLM provider factory. Overrides the default provider when set. */
|
|
28
|
+
provider?: LLMProviderFactory;
|
|
29
|
+
/** Model name passed to the provider. Overrides DEFAULT_MODEL when set. */
|
|
30
|
+
model?: string;
|
|
31
|
+
/** Custom system prompt. See SystemPromptOption for the three supported forms. */
|
|
32
|
+
systemPrompt?: SystemPromptOption;
|
|
33
|
+
/** Engine hook arrays – managed by Engine, not by callers directly. */
|
|
34
|
+
hooks?: LoopHooks;
|
|
35
|
+
}
|
|
36
|
+
declare function loop(context: Context, options?: LoopOptions): Promise<string>;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* 用户配置插件接口 - 面向终端用户
|
|
40
|
+
* 使用声明式配置扩展引擎能力
|
|
41
|
+
*/
|
|
42
|
+
interface UserConfigPlugin {
|
|
43
|
+
version: string;
|
|
44
|
+
name?: string;
|
|
45
|
+
description?: string;
|
|
46
|
+
tools?: Record<string, ToolConfig>;
|
|
47
|
+
mcp?: {
|
|
48
|
+
servers: MCPServerConfig[];
|
|
49
|
+
};
|
|
50
|
+
prompts?: {
|
|
51
|
+
system?: string;
|
|
52
|
+
user?: string;
|
|
53
|
+
assistant?: string;
|
|
54
|
+
};
|
|
55
|
+
subAgents?: SubAgentConfig[];
|
|
56
|
+
skills?: {
|
|
57
|
+
directories?: string[];
|
|
58
|
+
autoScan?: boolean;
|
|
59
|
+
cache?: boolean;
|
|
60
|
+
};
|
|
61
|
+
env?: Record<string, string>;
|
|
62
|
+
conditions?: {
|
|
63
|
+
environment?: string;
|
|
64
|
+
features?: string[];
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* 工具配置接口
|
|
69
|
+
*/
|
|
70
|
+
declare const ToolConfigSchema: z.ZodObject<{
|
|
71
|
+
type: z.ZodEnum<{
|
|
72
|
+
bash: "bash";
|
|
73
|
+
http: "http";
|
|
74
|
+
javascript: "javascript";
|
|
75
|
+
skill: "skill";
|
|
76
|
+
custom: "custom";
|
|
77
|
+
}>;
|
|
78
|
+
command: z.ZodOptional<z.ZodString>;
|
|
79
|
+
args: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
80
|
+
cwd: z.ZodOptional<z.ZodString>;
|
|
81
|
+
env: z.ZodOptional<z.ZodAny>;
|
|
82
|
+
timeout: z.ZodOptional<z.ZodNumber>;
|
|
83
|
+
method: z.ZodOptional<z.ZodEnum<{
|
|
84
|
+
GET: "GET";
|
|
85
|
+
POST: "POST";
|
|
86
|
+
PUT: "PUT";
|
|
87
|
+
DELETE: "DELETE";
|
|
88
|
+
PATCH: "PATCH";
|
|
89
|
+
}>>;
|
|
90
|
+
url: z.ZodOptional<z.ZodString>;
|
|
91
|
+
baseUrl: z.ZodOptional<z.ZodString>;
|
|
92
|
+
headers: z.ZodOptional<z.ZodAny>;
|
|
93
|
+
params: z.ZodOptional<z.ZodAny>;
|
|
94
|
+
data: z.ZodOptional<z.ZodAny>;
|
|
95
|
+
code: z.ZodOptional<z.ZodString>;
|
|
96
|
+
description: z.ZodOptional<z.ZodString>;
|
|
97
|
+
enabled: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
98
|
+
conditions: z.ZodOptional<z.ZodObject<{
|
|
99
|
+
environment: z.ZodOptional<z.ZodString>;
|
|
100
|
+
platform: z.ZodOptional<z.ZodString>;
|
|
101
|
+
}, z.core.$strip>>;
|
|
102
|
+
}, z.core.$strip>;
|
|
103
|
+
type ToolConfig = z.infer<typeof ToolConfigSchema>;
|
|
104
|
+
/**
|
|
105
|
+
* MCP 服务器配置接口
|
|
106
|
+
*/
|
|
107
|
+
declare const MCPServerConfigSchema: z.ZodObject<{
|
|
108
|
+
name: z.ZodString;
|
|
109
|
+
command: z.ZodString;
|
|
110
|
+
args: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
111
|
+
env: z.ZodOptional<z.ZodAny>;
|
|
112
|
+
cwd: z.ZodOptional<z.ZodString>;
|
|
113
|
+
timeout: z.ZodOptional<z.ZodNumber>;
|
|
114
|
+
description: z.ZodOptional<z.ZodString>;
|
|
115
|
+
enabled: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
116
|
+
}, z.core.$strip>;
|
|
117
|
+
type MCPServerConfig = z.infer<typeof MCPServerConfigSchema>;
|
|
118
|
+
/**
|
|
119
|
+
* 子代理配置接口
|
|
120
|
+
*/
|
|
121
|
+
declare const SubAgentConfigSchema: z.ZodObject<{
|
|
122
|
+
name: z.ZodString;
|
|
123
|
+
trigger: z.ZodArray<z.ZodString>;
|
|
124
|
+
prompt: z.ZodString;
|
|
125
|
+
model: z.ZodOptional<z.ZodString>;
|
|
126
|
+
temperature: z.ZodOptional<z.ZodNumber>;
|
|
127
|
+
maxTokens: z.ZodOptional<z.ZodNumber>;
|
|
128
|
+
tools: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
129
|
+
enabled: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
130
|
+
}, z.core.$strip>;
|
|
131
|
+
type SubAgentConfig = z.infer<typeof SubAgentConfigSchema>;
|
|
132
|
+
/**
|
|
133
|
+
* 用户配置插件加载选项
|
|
134
|
+
*/
|
|
135
|
+
interface UserConfigPluginLoadOptions {
|
|
136
|
+
configs?: UserConfigPlugin[];
|
|
137
|
+
dirs?: string[];
|
|
138
|
+
scan?: boolean;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
interface StreamOptions {
|
|
142
|
+
abortSignal?: AbortSignal;
|
|
143
|
+
onStepFinish?: (event: StepResult<any>) => void;
|
|
144
|
+
onChunk?: (event: {
|
|
145
|
+
chunk: any;
|
|
146
|
+
}) => void;
|
|
147
|
+
toolExecutionContext?: ToolExecutionContext;
|
|
148
|
+
/** Custom LLM provider. Falls back to the default CoderAI provider when not set. */
|
|
149
|
+
provider?: LLMProviderFactory;
|
|
150
|
+
/** Model name to pass to the provider. Falls back to DEFAULT_MODEL when not set. */
|
|
151
|
+
model?: string;
|
|
152
|
+
/** Custom system prompt. See SystemPromptOption for the three supported forms. */
|
|
153
|
+
systemPrompt?: SystemPromptOption;
|
|
154
|
+
}
|
|
155
|
+
declare const streamTextAI: (messages: ModelMessage[], tools: Record<string, Tool>, options?: StreamOptions) => ReturnType<typeof streamText> & {
|
|
156
|
+
steps: StepResult<any>[];
|
|
157
|
+
finishReason: string;
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
type CompactResult = {
|
|
161
|
+
didCompact: boolean;
|
|
162
|
+
reason?: string;
|
|
163
|
+
newMessages?: ModelMessage[];
|
|
164
|
+
};
|
|
165
|
+
declare const maybeCompactContext: (context: Context, options?: {
|
|
166
|
+
force?: boolean;
|
|
167
|
+
provider?: LLMProviderFactory;
|
|
168
|
+
model?: string;
|
|
169
|
+
}) => Promise<CompactResult>;
|
|
170
|
+
|
|
171
|
+
interface ClarifyInput {
|
|
172
|
+
question: string;
|
|
173
|
+
context?: string;
|
|
174
|
+
defaultAnswer?: string;
|
|
175
|
+
timeout?: number;
|
|
176
|
+
}
|
|
177
|
+
interface ClarifyOutput {
|
|
178
|
+
answer: string;
|
|
179
|
+
timedOut: boolean;
|
|
180
|
+
}
|
|
181
|
+
declare const ClarifyTool: Tool<ClarifyInput, ClarifyOutput>;
|
|
182
|
+
|
|
183
|
+
declare const ReadTool: Tool<{
|
|
184
|
+
filePath: string;
|
|
185
|
+
offset?: number;
|
|
186
|
+
limit?: number;
|
|
187
|
+
}, {
|
|
188
|
+
content: string;
|
|
189
|
+
totalLines?: number;
|
|
190
|
+
}>;
|
|
191
|
+
|
|
192
|
+
declare const WriteTool: Tool<{
|
|
193
|
+
filePath: string;
|
|
194
|
+
content: string;
|
|
195
|
+
}, {
|
|
196
|
+
success: boolean;
|
|
197
|
+
created: boolean;
|
|
198
|
+
bytes: number;
|
|
199
|
+
}>;
|
|
200
|
+
|
|
201
|
+
declare const EditTool: Tool<{
|
|
202
|
+
filePath: string;
|
|
203
|
+
oldString: string;
|
|
204
|
+
newString: string;
|
|
205
|
+
replaceAll?: boolean;
|
|
206
|
+
}, {
|
|
207
|
+
success: boolean;
|
|
208
|
+
replacements: number;
|
|
209
|
+
preview?: string;
|
|
210
|
+
}>;
|
|
211
|
+
|
|
212
|
+
declare const GrepTool: Tool<{
|
|
213
|
+
pattern: string;
|
|
214
|
+
path?: string;
|
|
215
|
+
glob?: string;
|
|
216
|
+
type?: string;
|
|
217
|
+
outputMode?: 'content' | 'files_with_matches' | 'count';
|
|
218
|
+
context?: number;
|
|
219
|
+
caseInsensitive?: boolean;
|
|
220
|
+
headLimit?: number;
|
|
221
|
+
offset?: number;
|
|
222
|
+
multiline?: boolean;
|
|
223
|
+
}, {
|
|
224
|
+
output: string;
|
|
225
|
+
matches?: number;
|
|
226
|
+
}>;
|
|
227
|
+
|
|
228
|
+
declare const LsTool: Tool<{
|
|
229
|
+
path?: string;
|
|
230
|
+
}, {
|
|
231
|
+
files: string[];
|
|
232
|
+
}>;
|
|
233
|
+
|
|
234
|
+
declare const BashTool: Tool<{
|
|
235
|
+
command: string;
|
|
236
|
+
timeout?: number;
|
|
237
|
+
cwd?: string;
|
|
238
|
+
description?: string;
|
|
239
|
+
}, {
|
|
240
|
+
output: string;
|
|
241
|
+
error?: string;
|
|
242
|
+
exitCode?: number;
|
|
243
|
+
}>;
|
|
244
|
+
|
|
245
|
+
declare const TavilyTool: Tool<{
|
|
246
|
+
query: string;
|
|
247
|
+
maxResults?: number;
|
|
248
|
+
}, {
|
|
249
|
+
results: Array<{
|
|
250
|
+
title: string;
|
|
251
|
+
url: string;
|
|
252
|
+
content: string;
|
|
253
|
+
score?: number;
|
|
254
|
+
}>;
|
|
255
|
+
}>;
|
|
256
|
+
|
|
257
|
+
declare const BuiltinTools: readonly [Tool<{
|
|
258
|
+
filePath: string;
|
|
259
|
+
offset?: number;
|
|
260
|
+
limit?: number;
|
|
261
|
+
}, {
|
|
262
|
+
content: string;
|
|
263
|
+
totalLines?: number;
|
|
264
|
+
}>, Tool<{
|
|
265
|
+
filePath: string;
|
|
266
|
+
content: string;
|
|
267
|
+
}, {
|
|
268
|
+
success: boolean;
|
|
269
|
+
created: boolean;
|
|
270
|
+
bytes: number;
|
|
271
|
+
}>, Tool<{
|
|
272
|
+
filePath: string;
|
|
273
|
+
oldString: string;
|
|
274
|
+
newString: string;
|
|
275
|
+
replaceAll?: boolean;
|
|
276
|
+
}, {
|
|
277
|
+
success: boolean;
|
|
278
|
+
replacements: number;
|
|
279
|
+
preview?: string;
|
|
280
|
+
}>, Tool<{
|
|
281
|
+
pattern: string;
|
|
282
|
+
path?: string;
|
|
283
|
+
glob?: string;
|
|
284
|
+
type?: string;
|
|
285
|
+
outputMode?: "content" | "files_with_matches" | "count";
|
|
286
|
+
context?: number;
|
|
287
|
+
caseInsensitive?: boolean;
|
|
288
|
+
headLimit?: number;
|
|
289
|
+
offset?: number;
|
|
290
|
+
multiline?: boolean;
|
|
291
|
+
}, {
|
|
292
|
+
output: string;
|
|
293
|
+
matches?: number;
|
|
294
|
+
}>, Tool<{
|
|
295
|
+
path?: string;
|
|
296
|
+
}, {
|
|
297
|
+
files: string[];
|
|
298
|
+
}>, Tool<{
|
|
299
|
+
command: string;
|
|
300
|
+
timeout?: number;
|
|
301
|
+
cwd?: string;
|
|
302
|
+
description?: string;
|
|
303
|
+
}, {
|
|
304
|
+
output: string;
|
|
305
|
+
error?: string;
|
|
306
|
+
exitCode?: number;
|
|
307
|
+
}>, Tool<{
|
|
308
|
+
query: string;
|
|
309
|
+
maxResults?: number;
|
|
310
|
+
}, {
|
|
311
|
+
results: Array<{
|
|
312
|
+
title: string;
|
|
313
|
+
url: string;
|
|
314
|
+
content: string;
|
|
315
|
+
score?: number;
|
|
316
|
+
}>;
|
|
317
|
+
}>, Tool<ClarifyInput, ClarifyOutput>];
|
|
318
|
+
declare const BuiltinToolsMap: Record<string, any>;
|
|
319
|
+
declare const getFinalToolsMap: (customTools?: Record<string, Tool$1>) => Record<string, any>;
|
|
320
|
+
|
|
321
|
+
/**
|
|
322
|
+
* 引擎配置选项
|
|
323
|
+
*/
|
|
324
|
+
interface EngineOptions {
|
|
325
|
+
enginePlugins?: EnginePluginLoadOptions;
|
|
326
|
+
userConfigPlugins?: UserConfigPluginLoadOptions;
|
|
327
|
+
disableBuiltInPlugins?: boolean;
|
|
328
|
+
config?: Record<string, any>;
|
|
329
|
+
/**
|
|
330
|
+
* 自定义 LLM Provider。
|
|
331
|
+
* 接收模型名称,返回 Vercel AI SDK LanguageModel 实例。
|
|
332
|
+
* 未设置时使用环境变量配置的默认 Provider(OpenAI / Anthropic)。
|
|
333
|
+
*
|
|
334
|
+
* @example
|
|
335
|
+
* import { createOpenAI } from '@ai-sdk/openai';
|
|
336
|
+
* const engine = new Engine({
|
|
337
|
+
* llmProvider: createOpenAI({ apiKey: 'sk-...', baseURL: 'https://my-proxy/v1' }).chat,
|
|
338
|
+
* model: 'gpt-4o',
|
|
339
|
+
* });
|
|
340
|
+
*/
|
|
341
|
+
llmProvider?: LLMProviderFactory;
|
|
342
|
+
/**
|
|
343
|
+
* 模型名称,传递给 llmProvider。未设置时使用 DEFAULT_MODEL。
|
|
344
|
+
*/
|
|
345
|
+
model?: string;
|
|
346
|
+
/**
|
|
347
|
+
* 直接注册自定义工具,无需创建 EnginePlugin。
|
|
348
|
+
* 这些工具会与内置工具以及插件注册的工具合并。
|
|
349
|
+
* 若与内置工具同名,自定义工具优先级更高。
|
|
350
|
+
*
|
|
351
|
+
* @example
|
|
352
|
+
* import { z } from 'zod';
|
|
353
|
+
* const engine = new Engine({
|
|
354
|
+
* tools: {
|
|
355
|
+
* myTool: {
|
|
356
|
+
* name: 'myTool',
|
|
357
|
+
* description: '查询内部数据库',
|
|
358
|
+
* inputSchema: z.object({ query: z.string() }),
|
|
359
|
+
* execute: async ({ query }) => fetchFromDB(query),
|
|
360
|
+
* },
|
|
361
|
+
* },
|
|
362
|
+
* });
|
|
363
|
+
*/
|
|
364
|
+
tools?: Record<string, Tool>;
|
|
365
|
+
/**
|
|
366
|
+
* 自定义 System Prompt,三种形式:
|
|
367
|
+
* - `string` — 完全替换内置 prompt
|
|
368
|
+
* - `() => string` — 工厂函数,每次请求调用(支持动态 prompt)
|
|
369
|
+
* - `{ append: string }` — 在内置 prompt 末尾追加业务上下文
|
|
370
|
+
*
|
|
371
|
+
* @example
|
|
372
|
+
* const engine = new Engine({
|
|
373
|
+
* systemPrompt: { append: '公司规范:所有变量使用 camelCase。禁止使用 any 类型。' },
|
|
374
|
+
* });
|
|
375
|
+
*/
|
|
376
|
+
systemPrompt?: SystemPromptOption;
|
|
377
|
+
/**
|
|
378
|
+
* Tool 执行钩子,在每次工具调用前/后触发。
|
|
379
|
+
* - `onBeforeToolCall` 可以修改入参,或抛错来拦截调用。
|
|
380
|
+
* - `onAfterToolCall` 可以修改返回值(如脱敏、截断)。
|
|
381
|
+
*
|
|
382
|
+
* Backward-compatible shorthand — internally converted to
|
|
383
|
+
* beforeToolCall / afterToolCall engine hooks.
|
|
384
|
+
*
|
|
385
|
+
* @example
|
|
386
|
+
* const engine = new Engine({
|
|
387
|
+
* hooks: {
|
|
388
|
+
* onBeforeToolCall: (name, input) => {
|
|
389
|
+
* if (name === 'bash') throw new Error('bash 工具已被禁用');
|
|
390
|
+
* },
|
|
391
|
+
* onAfterToolCall: (name, input, output) => {
|
|
392
|
+
* auditLogger.log({ name, input, output });
|
|
393
|
+
* return output;
|
|
394
|
+
* },
|
|
395
|
+
* },
|
|
396
|
+
* });
|
|
397
|
+
*/
|
|
398
|
+
hooks?: ToolHooks;
|
|
399
|
+
/**
|
|
400
|
+
* 自定义日志实现。未设置时使用 console.*。
|
|
401
|
+
* 兼容 winston / pino 等主流日志库。
|
|
402
|
+
*
|
|
403
|
+
* @example
|
|
404
|
+
* import pino from 'pino';
|
|
405
|
+
* const logger = pino();
|
|
406
|
+
* const engine = new Engine({ logger });
|
|
407
|
+
*/
|
|
408
|
+
logger?: ILogger;
|
|
409
|
+
}
|
|
410
|
+
/**
|
|
411
|
+
* 重构后的引擎类
|
|
412
|
+
* 自动包含内置插件,支持可选禁用
|
|
413
|
+
*/
|
|
414
|
+
declare class Engine {
|
|
415
|
+
private pluginManager;
|
|
416
|
+
private tools;
|
|
417
|
+
private options;
|
|
418
|
+
private config;
|
|
419
|
+
constructor(options?: EngineOptions);
|
|
420
|
+
/**
|
|
421
|
+
* 初始化引擎和插件系统
|
|
422
|
+
* 自动包含内置插件
|
|
423
|
+
*/
|
|
424
|
+
initialize(): Promise<void>;
|
|
425
|
+
/**
|
|
426
|
+
* 准备引擎插件列表(包含内置插件)
|
|
427
|
+
*/
|
|
428
|
+
private prepareEnginePlugins;
|
|
429
|
+
/**
|
|
430
|
+
* Collect all hooks for a given loop invocation.
|
|
431
|
+
* Merges plugin hooks with the legacy EngineOptions.hooks (ToolHooks).
|
|
432
|
+
*/
|
|
433
|
+
private collectLoopHooks;
|
|
434
|
+
/**
|
|
435
|
+
* 运行AI循环
|
|
436
|
+
*/
|
|
437
|
+
run(context: Context, options?: LoopOptions): Promise<string>;
|
|
438
|
+
/**
|
|
439
|
+
* 获取插件状态
|
|
440
|
+
*/
|
|
441
|
+
getPluginStatus(): {
|
|
442
|
+
enginePlugins: string[];
|
|
443
|
+
userConfigPlugins: string[];
|
|
444
|
+
tools: string[];
|
|
445
|
+
hooks: {
|
|
446
|
+
[k: string]: number;
|
|
447
|
+
};
|
|
448
|
+
services: string[];
|
|
449
|
+
};
|
|
450
|
+
/**
|
|
451
|
+
* 获取工具
|
|
452
|
+
*/
|
|
453
|
+
getTools(): Record<string, any>;
|
|
454
|
+
/**
|
|
455
|
+
* 获取服务
|
|
456
|
+
*/
|
|
457
|
+
getService<T>(name: string): T | undefined;
|
|
458
|
+
/**
|
|
459
|
+
* 获取 plan mode 服务
|
|
460
|
+
*/
|
|
461
|
+
private getPlanModeService;
|
|
462
|
+
/**
|
|
463
|
+
* 获取当前模式
|
|
464
|
+
*/
|
|
465
|
+
getMode(): PlanMode | undefined;
|
|
466
|
+
/**
|
|
467
|
+
* 设置当前模式
|
|
468
|
+
*/
|
|
469
|
+
setMode(mode: PlanMode, reason?: string): boolean;
|
|
470
|
+
/**
|
|
471
|
+
* 获取配置
|
|
472
|
+
*/
|
|
473
|
+
getConfig<T>(key: string): T | undefined;
|
|
474
|
+
/**
|
|
475
|
+
* 设置配置
|
|
476
|
+
*/
|
|
477
|
+
setConfig<T>(key: string, value: T): void;
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
/**
|
|
481
|
+
* 插件管理器 - 管理双轨插件系统
|
|
482
|
+
*/
|
|
483
|
+
declare class PluginManager {
|
|
484
|
+
private enginePlugins;
|
|
485
|
+
private userConfigPlugins;
|
|
486
|
+
private tools;
|
|
487
|
+
private hooks;
|
|
488
|
+
private services;
|
|
489
|
+
private config;
|
|
490
|
+
private events;
|
|
491
|
+
private logger;
|
|
492
|
+
constructor(logger?: ILogger);
|
|
493
|
+
/**
|
|
494
|
+
* 初始化插件系统
|
|
495
|
+
*/
|
|
496
|
+
initialize(options?: {
|
|
497
|
+
enginePlugins?: EnginePluginLoadOptions;
|
|
498
|
+
userConfigPlugins?: UserConfigPluginLoadOptions;
|
|
499
|
+
}): Promise<void>;
|
|
500
|
+
/**
|
|
501
|
+
* 加载引擎插件
|
|
502
|
+
*/
|
|
503
|
+
private loadEnginePlugins;
|
|
504
|
+
/**
|
|
505
|
+
* 扫描引擎插件目录
|
|
506
|
+
*/
|
|
507
|
+
private scanEnginePlugins;
|
|
508
|
+
/**
|
|
509
|
+
* 加载单个引擎插件文件
|
|
510
|
+
*/
|
|
511
|
+
private loadEnginePluginFile;
|
|
512
|
+
/**
|
|
513
|
+
* 初始化单个引擎插件
|
|
514
|
+
*/
|
|
515
|
+
private initializeEnginePlugin;
|
|
516
|
+
/**
|
|
517
|
+
* 加载用户配置插件
|
|
518
|
+
*/
|
|
519
|
+
private loadUserConfigPlugins;
|
|
520
|
+
/**
|
|
521
|
+
* 扫描用户配置插件目录
|
|
522
|
+
*/
|
|
523
|
+
private scanUserConfigPlugins;
|
|
524
|
+
/**
|
|
525
|
+
* 加载单个用户配置文件
|
|
526
|
+
*/
|
|
527
|
+
private loadUserConfigFile;
|
|
528
|
+
/**
|
|
529
|
+
* 应用用户配置
|
|
530
|
+
*/
|
|
531
|
+
private applyUserConfig;
|
|
532
|
+
/**
|
|
533
|
+
* 验证核心能力
|
|
534
|
+
*
|
|
535
|
+
* - requiredCapabilities: 任意一个别名匹配即可,缺失时 **抛错** 阻止启动。
|
|
536
|
+
* - recommendedCapabilities: 缺失时仅 warn,不影响启动。
|
|
537
|
+
*/
|
|
538
|
+
private validateCoreCapabilities;
|
|
539
|
+
/**
|
|
540
|
+
* 插件依赖排序
|
|
541
|
+
*/
|
|
542
|
+
private sortPluginsByDependencies;
|
|
543
|
+
/**
|
|
544
|
+
* 工具获取
|
|
545
|
+
*/
|
|
546
|
+
getTools(): Record<string, any>;
|
|
547
|
+
/**
|
|
548
|
+
* 获取指定类型的 hook 处理函数数组
|
|
549
|
+
*/
|
|
550
|
+
getHooks<K extends EngineHookName>(hookName: K): Array<EngineHookMap[K]>;
|
|
551
|
+
/**
|
|
552
|
+
* 服务获取
|
|
553
|
+
*/
|
|
554
|
+
getService<T>(name: string): T | undefined;
|
|
555
|
+
/**
|
|
556
|
+
* 获取插件状态
|
|
557
|
+
*/
|
|
558
|
+
getStatus(): {
|
|
559
|
+
enginePlugins: string[];
|
|
560
|
+
userConfigPlugins: string[];
|
|
561
|
+
tools: string[];
|
|
562
|
+
hooks: {
|
|
563
|
+
[k: string]: number;
|
|
564
|
+
};
|
|
565
|
+
services: string[];
|
|
566
|
+
};
|
|
567
|
+
/**
|
|
568
|
+
* 解析路径(支持 ~ 和相对路径)
|
|
569
|
+
*/
|
|
570
|
+
private resolvePath;
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
export { BashTool, BuiltinTools, BuiltinToolsMap, ClarificationRequest, ClarifyTool, Context, EditTool, Engine, EngineHookMap, EngineHookName, GrepTool, ILogger, LLMProviderFactory, LsTool, PlanMode, PluginManager, Engine as PulseAgent, ReadTool, SystemPromptOption, TavilyTool, Tool, ToolExecutionContext, ToolHooks, type UserConfigPlugin, type UserConfigPluginLoadOptions, WriteTool, getFinalToolsMap, loop, maybeCompactContext, streamTextAI };
|