@agenticc/core 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 +370 -0
- package/README.zh-CN.md +372 -0
- package/dist/audit/index.d.ts +9 -0
- package/dist/audit/index.d.ts.map +1 -0
- package/dist/audit/index.js +9 -0
- package/dist/audit/index.js.map +1 -0
- package/dist/audit/logger.d.ts +211 -0
- package/dist/audit/logger.d.ts.map +1 -0
- package/dist/audit/logger.js +268 -0
- package/dist/audit/logger.js.map +1 -0
- package/dist/audit/query.d.ts +164 -0
- package/dist/audit/query.d.ts.map +1 -0
- package/dist/audit/query.js +250 -0
- package/dist/audit/query.js.map +1 -0
- package/dist/conversation/context-builder.d.ts +119 -0
- package/dist/conversation/context-builder.d.ts.map +1 -0
- package/dist/conversation/context-builder.js +252 -0
- package/dist/conversation/context-builder.js.map +1 -0
- package/dist/conversation/index.d.ts +10 -0
- package/dist/conversation/index.d.ts.map +1 -0
- package/dist/conversation/index.js +10 -0
- package/dist/conversation/index.js.map +1 -0
- package/dist/conversation/message-store.d.ts +231 -0
- package/dist/conversation/message-store.d.ts.map +1 -0
- package/dist/conversation/message-store.js +404 -0
- package/dist/conversation/message-store.js.map +1 -0
- package/dist/conversation/session.d.ts +201 -0
- package/dist/conversation/session.d.ts.map +1 -0
- package/dist/conversation/session.js +285 -0
- package/dist/conversation/session.js.map +1 -0
- package/dist/core/agent.d.ts +277 -0
- package/dist/core/agent.d.ts.map +1 -0
- package/dist/core/agent.js +674 -0
- package/dist/core/agent.js.map +1 -0
- package/dist/core/agentic-loop.d.ts +98 -0
- package/dist/core/agentic-loop.d.ts.map +1 -0
- package/dist/core/agentic-loop.js +496 -0
- package/dist/core/agentic-loop.js.map +1 -0
- package/dist/core/index.d.ts +14 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +14 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/intent-parser.d.ts +101 -0
- package/dist/core/intent-parser.d.ts.map +1 -0
- package/dist/core/intent-parser.js +221 -0
- package/dist/core/intent-parser.js.map +1 -0
- package/dist/core/plan-generator.d.ts +133 -0
- package/dist/core/plan-generator.d.ts.map +1 -0
- package/dist/core/plan-generator.js +294 -0
- package/dist/core/plan-generator.js.map +1 -0
- package/dist/core/plugin-manager.d.ts +120 -0
- package/dist/core/plugin-manager.d.ts.map +1 -0
- package/dist/core/plugin-manager.js +369 -0
- package/dist/core/plugin-manager.js.map +1 -0
- package/dist/core/response-handler.d.ts +141 -0
- package/dist/core/response-handler.d.ts.map +1 -0
- package/dist/core/response-handler.js +384 -0
- package/dist/core/response-handler.js.map +1 -0
- package/dist/core/tool-executor.d.ts +143 -0
- package/dist/core/tool-executor.d.ts.map +1 -0
- package/dist/core/tool-executor.js +354 -0
- package/dist/core/tool-executor.js.map +1 -0
- package/dist/core/tool-registry.d.ts +133 -0
- package/dist/core/tool-registry.d.ts.map +1 -0
- package/dist/core/tool-registry.js +252 -0
- package/dist/core/tool-registry.js.map +1 -0
- package/dist/index.d.ts +44 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +47 -0
- package/dist/index.js.map +1 -0
- package/dist/knowledge/chunker.d.ts +78 -0
- package/dist/knowledge/chunker.d.ts.map +1 -0
- package/dist/knowledge/chunker.js +233 -0
- package/dist/knowledge/chunker.js.map +1 -0
- package/dist/knowledge/embedder.d.ts +93 -0
- package/dist/knowledge/embedder.d.ts.map +1 -0
- package/dist/knowledge/embedder.js +205 -0
- package/dist/knowledge/embedder.js.map +1 -0
- package/dist/knowledge/index.d.ts +10 -0
- package/dist/knowledge/index.d.ts.map +1 -0
- package/dist/knowledge/index.js +11 -0
- package/dist/knowledge/index.js.map +1 -0
- package/dist/knowledge/loaders/index.d.ts +10 -0
- package/dist/knowledge/loaders/index.d.ts.map +1 -0
- package/dist/knowledge/loaders/index.js +10 -0
- package/dist/knowledge/loaders/index.js.map +1 -0
- package/dist/knowledge/loaders/markdown.d.ts +88 -0
- package/dist/knowledge/loaders/markdown.d.ts.map +1 -0
- package/dist/knowledge/loaders/markdown.js +205 -0
- package/dist/knowledge/loaders/markdown.js.map +1 -0
- package/dist/knowledge/loaders/yaml.d.ts +112 -0
- package/dist/knowledge/loaders/yaml.d.ts.map +1 -0
- package/dist/knowledge/loaders/yaml.js +368 -0
- package/dist/knowledge/loaders/yaml.js.map +1 -0
- package/dist/knowledge/retriever.d.ts +144 -0
- package/dist/knowledge/retriever.d.ts.map +1 -0
- package/dist/knowledge/retriever.js +399 -0
- package/dist/knowledge/retriever.js.map +1 -0
- package/dist/knowledge/store.d.ts +146 -0
- package/dist/knowledge/store.d.ts.map +1 -0
- package/dist/knowledge/store.js +420 -0
- package/dist/knowledge/store.js.map +1 -0
- package/dist/llm/adapter.d.ts +194 -0
- package/dist/llm/adapter.d.ts.map +1 -0
- package/dist/llm/adapter.js +42 -0
- package/dist/llm/adapter.js.map +1 -0
- package/dist/llm/adapters/anyrouter.d.ts +84 -0
- package/dist/llm/adapters/anyrouter.d.ts.map +1 -0
- package/dist/llm/adapters/anyrouter.js +372 -0
- package/dist/llm/adapters/anyrouter.js.map +1 -0
- package/dist/llm/adapters/claude.d.ts +66 -0
- package/dist/llm/adapters/claude.d.ts.map +1 -0
- package/dist/llm/adapters/claude.js +323 -0
- package/dist/llm/adapters/claude.js.map +1 -0
- package/dist/llm/adapters/index.d.ts +12 -0
- package/dist/llm/adapters/index.d.ts.map +1 -0
- package/dist/llm/adapters/index.js +12 -0
- package/dist/llm/adapters/index.js.map +1 -0
- package/dist/llm/adapters/mimo.d.ts +85 -0
- package/dist/llm/adapters/mimo.d.ts.map +1 -0
- package/dist/llm/adapters/mimo.js +316 -0
- package/dist/llm/adapters/mimo.js.map +1 -0
- package/dist/llm/adapters/openai.d.ts +53 -0
- package/dist/llm/adapters/openai.d.ts.map +1 -0
- package/dist/llm/adapters/openai.js +293 -0
- package/dist/llm/adapters/openai.js.map +1 -0
- package/dist/llm/adapters/qwen.d.ts +53 -0
- package/dist/llm/adapters/qwen.d.ts.map +1 -0
- package/dist/llm/adapters/qwen.js +299 -0
- package/dist/llm/adapters/qwen.js.map +1 -0
- package/dist/llm/adapters/siliconflow.d.ts +69 -0
- package/dist/llm/adapters/siliconflow.d.ts.map +1 -0
- package/dist/llm/adapters/siliconflow.js +331 -0
- package/dist/llm/adapters/siliconflow.js.map +1 -0
- package/dist/llm/index.d.ts +9 -0
- package/dist/llm/index.d.ts.map +1 -0
- package/dist/llm/index.js +12 -0
- package/dist/llm/index.js.map +1 -0
- package/dist/llm/manager.d.ts +97 -0
- package/dist/llm/manager.d.ts.map +1 -0
- package/dist/llm/manager.js +337 -0
- package/dist/llm/manager.js.map +1 -0
- package/dist/test-utils/arbitraries.d.ts +230 -0
- package/dist/test-utils/arbitraries.d.ts.map +1 -0
- package/dist/test-utils/arbitraries.js +280 -0
- package/dist/test-utils/arbitraries.js.map +1 -0
- package/dist/test-utils/cleanup.d.ts +184 -0
- package/dist/test-utils/cleanup.d.ts.map +1 -0
- package/dist/test-utils/cleanup.js +282 -0
- package/dist/test-utils/cleanup.js.map +1 -0
- package/dist/test-utils/config.d.ts +80 -0
- package/dist/test-utils/config.d.ts.map +1 -0
- package/dist/test-utils/config.js +94 -0
- package/dist/test-utils/config.js.map +1 -0
- package/dist/test-utils/index.d.ts +10 -0
- package/dist/test-utils/index.d.ts.map +1 -0
- package/dist/test-utils/index.js +36 -0
- package/dist/test-utils/index.js.map +1 -0
- package/dist/test-utils/mocks.d.ts +170 -0
- package/dist/test-utils/mocks.d.ts.map +1 -0
- package/dist/test-utils/mocks.js +281 -0
- package/dist/test-utils/mocks.js.map +1 -0
- package/dist/types/config.d.ts +170 -0
- package/dist/types/config.d.ts.map +1 -0
- package/dist/types/config.js +120 -0
- package/dist/types/config.js.map +1 -0
- package/dist/types/knowledge.d.ts +95 -0
- package/dist/types/knowledge.d.ts.map +1 -0
- package/dist/types/knowledge.js +7 -0
- package/dist/types/knowledge.js.map +1 -0
- package/dist/types/loop.d.ts +148 -0
- package/dist/types/loop.d.ts.map +1 -0
- package/dist/types/loop.js +16 -0
- package/dist/types/loop.js.map +1 -0
- package/dist/types/plugin.d.ts +137 -0
- package/dist/types/plugin.d.ts.map +1 -0
- package/dist/types/plugin.js +15 -0
- package/dist/types/plugin.js.map +1 -0
- package/dist/types/response.d.ts +186 -0
- package/dist/types/response.d.ts.map +1 -0
- package/dist/types/response.js +99 -0
- package/dist/types/response.js.map +1 -0
- package/dist/types/streaming.d.ts +478 -0
- package/dist/types/streaming.d.ts.map +1 -0
- package/dist/types/streaming.js +483 -0
- package/dist/types/streaming.js.map +1 -0
- package/dist/types/tool.d.ts +118 -0
- package/dist/types/tool.d.ts.map +1 -0
- package/dist/types/tool.js +42 -0
- package/dist/types/tool.js.map +1 -0
- package/dist/utils/error.d.ts +22 -0
- package/dist/utils/error.d.ts.map +1 -0
- package/dist/utils/error.js +36 -0
- package/dist/utils/error.js.map +1 -0
- package/package.json +102 -0
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core Module
|
|
3
|
+
*
|
|
4
|
+
* Contains the core components of the Agent system including
|
|
5
|
+
* tool registry, tool executor, intent parser, plan generator,
|
|
6
|
+
* response handler, and the main Agent class.
|
|
7
|
+
*/
|
|
8
|
+
export * from './tool-registry.js';
|
|
9
|
+
export * from './tool-executor.js';
|
|
10
|
+
export * from './intent-parser.js';
|
|
11
|
+
export * from './plan-generator.js';
|
|
12
|
+
export * from './response-handler.js';
|
|
13
|
+
export * from './agent.js';
|
|
14
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;AACtC,cAAc,YAAY,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core Module
|
|
3
|
+
*
|
|
4
|
+
* Contains the core components of the Agent system including
|
|
5
|
+
* tool registry, tool executor, intent parser, plan generator,
|
|
6
|
+
* response handler, and the main Agent class.
|
|
7
|
+
*/
|
|
8
|
+
export * from './tool-registry.js';
|
|
9
|
+
export * from './tool-executor.js';
|
|
10
|
+
export * from './intent-parser.js';
|
|
11
|
+
export * from './plan-generator.js';
|
|
12
|
+
export * from './response-handler.js';
|
|
13
|
+
export * from './agent.js';
|
|
14
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;AACtC,cAAc,YAAY,CAAC"}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Intent Parser
|
|
3
|
+
*
|
|
4
|
+
* Parses user messages to extract intent, entities, and operation type.
|
|
5
|
+
* Uses LLM to understand natural language and determine appropriate actions.
|
|
6
|
+
*
|
|
7
|
+
* _Requirements: 1.1_
|
|
8
|
+
*/
|
|
9
|
+
import type { LLMManager } from '../llm/manager.js';
|
|
10
|
+
import type { ChatMessage } from '../llm/adapter.js';
|
|
11
|
+
/**
|
|
12
|
+
* Parsed intent from user message
|
|
13
|
+
*/
|
|
14
|
+
export interface Intent {
|
|
15
|
+
/** The main action or operation type */
|
|
16
|
+
action: string;
|
|
17
|
+
/** Key entities mentioned in the message */
|
|
18
|
+
entities: string[];
|
|
19
|
+
/** Required knowledge topics to fulfill the intent */
|
|
20
|
+
requiredTopics?: string[];
|
|
21
|
+
/** Confidence level of the parsing */
|
|
22
|
+
confidence: number;
|
|
23
|
+
/** Original user message */
|
|
24
|
+
originalMessage: string;
|
|
25
|
+
/** Additional context extracted from the message */
|
|
26
|
+
context?: Record<string, unknown>;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Operation types that the agent can perform
|
|
30
|
+
*/
|
|
31
|
+
export type OperationType = 'query' | 'create' | 'update' | 'delete' | 'execute' | 'configure' | 'unknown';
|
|
32
|
+
/**
|
|
33
|
+
* Detailed intent with operation classification
|
|
34
|
+
*/
|
|
35
|
+
export interface DetailedIntent extends Intent {
|
|
36
|
+
/** Classified operation type */
|
|
37
|
+
operationType: OperationType;
|
|
38
|
+
/** Target resource or entity */
|
|
39
|
+
target?: string;
|
|
40
|
+
/** Parameters extracted from the message */
|
|
41
|
+
parameters?: Record<string, unknown>;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Intent parser configuration
|
|
45
|
+
*/
|
|
46
|
+
export interface IntentParserConfig {
|
|
47
|
+
/** System prompt for intent parsing */
|
|
48
|
+
systemPrompt?: string;
|
|
49
|
+
/** Whether to include conversation history */
|
|
50
|
+
includeHistory?: boolean;
|
|
51
|
+
/** Maximum history messages to include */
|
|
52
|
+
maxHistoryMessages?: number;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Intent Parser
|
|
56
|
+
*
|
|
57
|
+
* Uses LLM to parse user messages and extract structured intent information.
|
|
58
|
+
*/
|
|
59
|
+
export declare class IntentParser {
|
|
60
|
+
private llmManager;
|
|
61
|
+
private config;
|
|
62
|
+
constructor(llmManager: LLMManager, config?: IntentParserConfig);
|
|
63
|
+
/**
|
|
64
|
+
* Parse a user message to extract intent
|
|
65
|
+
*
|
|
66
|
+
* @param message - User message to parse
|
|
67
|
+
* @param history - Optional conversation history
|
|
68
|
+
* @returns Parsed intent
|
|
69
|
+
*/
|
|
70
|
+
parse(message: string, _history?: ChatMessage[]): Promise<DetailedIntent>;
|
|
71
|
+
/**
|
|
72
|
+
* Build messages for LLM call
|
|
73
|
+
*/
|
|
74
|
+
private buildMessages;
|
|
75
|
+
/**
|
|
76
|
+
* Parse LLM response into DetailedIntent
|
|
77
|
+
*/
|
|
78
|
+
private parseResponse;
|
|
79
|
+
/**
|
|
80
|
+
* Validate and normalize operation type
|
|
81
|
+
*/
|
|
82
|
+
private validateOperationType;
|
|
83
|
+
/**
|
|
84
|
+
* Create a fallback intent when parsing fails
|
|
85
|
+
*/
|
|
86
|
+
private createFallbackIntent;
|
|
87
|
+
/**
|
|
88
|
+
* Extract entities from a message using simple pattern matching
|
|
89
|
+
* Used as a supplement to LLM parsing
|
|
90
|
+
*/
|
|
91
|
+
extractEntities(message: string): string[];
|
|
92
|
+
/**
|
|
93
|
+
* Update the system prompt
|
|
94
|
+
*/
|
|
95
|
+
setSystemPrompt(prompt: string): void;
|
|
96
|
+
/**
|
|
97
|
+
* Get current configuration
|
|
98
|
+
*/
|
|
99
|
+
getConfig(): Required<IntentParserConfig>;
|
|
100
|
+
}
|
|
101
|
+
//# sourceMappingURL=intent-parser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"intent-parser.d.ts","sourceRoot":"","sources":["../../src/core/intent-parser.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAErD;;GAEG;AACH,MAAM,WAAW,MAAM;IACrB,wCAAwC;IACxC,MAAM,EAAE,MAAM,CAAC;IACf,4CAA4C;IAC5C,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,sDAAsD;IACtD,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAC1B,sCAAsC;IACtC,UAAU,EAAE,MAAM,CAAC;IACnB,4BAA4B;IAC5B,eAAe,EAAE,MAAM,CAAC;IACxB,oDAAoD;IACpD,OAAO,CA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,CAAC;CAG1C"}
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Intent Parser
|
|
3
|
+
*
|
|
4
|
+
* Parses user messages to extract intent, entities, and operation type.
|
|
5
|
+
* Uses LLM to understand natural language and determine appropriate actions.
|
|
6
|
+
*
|
|
7
|
+
* _Requirements: 1.1_
|
|
8
|
+
*/
|
|
9
|
+
const DEFAULT_SYSTEM_PROMPT = `你是一个游戏服务器管理系统的意图解析器。
|
|
10
|
+
你的任务是分析用户消息并提取结构化信息。
|
|
11
|
+
|
|
12
|
+
【重要】你必须且只能返回一个 JSON 对象,不要包含任何其他文字或解释。
|
|
13
|
+
|
|
14
|
+
JSON 格式如下:
|
|
15
|
+
{
|
|
16
|
+
"action": "用户想要执行的主要操作描述",
|
|
17
|
+
"entities": ["提到的实体名称数组,如怪物名、Boss名、玩家名等"],
|
|
18
|
+
"requiredTopics": ["需要的知识主题数组"],
|
|
19
|
+
"operationType": "query|create|update|delete|execute|configure|unknown",
|
|
20
|
+
"target": "目标资源(可选)",
|
|
21
|
+
"parameters": {},
|
|
22
|
+
"confidence": 0.8
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
operationType 说明:
|
|
26
|
+
- query: 查询信息
|
|
27
|
+
- create: 创建新资源
|
|
28
|
+
- update: 修改现有资源
|
|
29
|
+
- delete: 删除资源
|
|
30
|
+
- execute: 执行操作
|
|
31
|
+
- configure: 配置设置
|
|
32
|
+
- unknown: 无法确定(如简单问候)
|
|
33
|
+
|
|
34
|
+
示例:
|
|
35
|
+
用户: "你好"
|
|
36
|
+
返回: {"action":"问候","entities":[],"requiredTopics":[],"operationType":"unknown","confidence":0.9}
|
|
37
|
+
|
|
38
|
+
用户: "查看所有Boss"
|
|
39
|
+
返回: {"action":"查询Boss列表","entities":["Boss"],"requiredTopics":["boss"],"operationType":"query","target":"boss","confidence":0.95}`;
|
|
40
|
+
/**
|
|
41
|
+
* Intent Parser
|
|
42
|
+
*
|
|
43
|
+
* Uses LLM to parse user messages and extract structured intent information.
|
|
44
|
+
*/
|
|
45
|
+
export class IntentParser {
|
|
46
|
+
llmManager;
|
|
47
|
+
config;
|
|
48
|
+
constructor(llmManager, config) {
|
|
49
|
+
this.llmManager = llmManager;
|
|
50
|
+
this.config = {
|
|
51
|
+
systemPrompt: config?.systemPrompt ?? DEFAULT_SYSTEM_PROMPT,
|
|
52
|
+
includeHistory: config?.includeHistory ?? true,
|
|
53
|
+
maxHistoryMessages: config?.maxHistoryMessages ?? 5,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Parse a user message to extract intent
|
|
58
|
+
*
|
|
59
|
+
* @param message - User message to parse
|
|
60
|
+
* @param history - Optional conversation history
|
|
61
|
+
* @returns Parsed intent
|
|
62
|
+
*/
|
|
63
|
+
async parse(message, _history) {
|
|
64
|
+
// Skip LLM call for intent parsing - use keyword-based fallback directly
|
|
65
|
+
// This is more reliable for Chinese language models that don't follow JSON format
|
|
66
|
+
return this.createFallbackIntent(message);
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Build messages for LLM call
|
|
70
|
+
*/
|
|
71
|
+
buildMessages(message, history) {
|
|
72
|
+
const messages = [{ role: 'system', content: this.config.systemPrompt }];
|
|
73
|
+
// Add conversation history if enabled
|
|
74
|
+
if (this.config.includeHistory && history && history.length > 0) {
|
|
75
|
+
const recentHistory = history.slice(-this.config.maxHistoryMessages);
|
|
76
|
+
messages.push(...recentHistory);
|
|
77
|
+
}
|
|
78
|
+
// Add current user message
|
|
79
|
+
messages.push({ role: 'user', content: message });
|
|
80
|
+
return messages;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Parse LLM response into DetailedIntent
|
|
84
|
+
*/
|
|
85
|
+
parseResponse(response, originalMessage) {
|
|
86
|
+
try {
|
|
87
|
+
// Extract JSON from response (handle markdown code blocks)
|
|
88
|
+
const jsonMatch = response.match(/```(?:json)?\s*([\s\S]*?)```/) || response.match(/\{[\s\S]*\}/);
|
|
89
|
+
const jsonStr = jsonMatch ? (jsonMatch[1] || jsonMatch[0]).trim() : response.trim();
|
|
90
|
+
const parsed = JSON.parse(jsonStr);
|
|
91
|
+
return {
|
|
92
|
+
action: parsed.action || 'unknown',
|
|
93
|
+
entities: Array.isArray(parsed.entities) ? parsed.entities : [],
|
|
94
|
+
requiredTopics: Array.isArray(parsed.requiredTopics) ? parsed.requiredTopics : [],
|
|
95
|
+
confidence: typeof parsed.confidence === 'number' ? Math.max(0, Math.min(1, parsed.confidence)) : 0.5,
|
|
96
|
+
originalMessage,
|
|
97
|
+
operationType: this.validateOperationType(parsed.operationType),
|
|
98
|
+
target: parsed.target,
|
|
99
|
+
parameters: typeof parsed.parameters === 'object' ? parsed.parameters : undefined,
|
|
100
|
+
context: parsed.context,
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
catch (error) {
|
|
104
|
+
console.warn('Failed to parse intent response:', error);
|
|
105
|
+
return this.createFallbackIntent(originalMessage);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Validate and normalize operation type
|
|
110
|
+
*/
|
|
111
|
+
validateOperationType(type) {
|
|
112
|
+
const validTypes = [
|
|
113
|
+
'query',
|
|
114
|
+
'create',
|
|
115
|
+
'update',
|
|
116
|
+
'delete',
|
|
117
|
+
'execute',
|
|
118
|
+
'configure',
|
|
119
|
+
'unknown',
|
|
120
|
+
];
|
|
121
|
+
if (typeof type === 'string' && validTypes.includes(type)) {
|
|
122
|
+
return type;
|
|
123
|
+
}
|
|
124
|
+
return 'unknown';
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Create a fallback intent when parsing fails
|
|
128
|
+
*/
|
|
129
|
+
createFallbackIntent(message) {
|
|
130
|
+
// Simple heuristic-based fallback
|
|
131
|
+
const lowerMessage = message.toLowerCase();
|
|
132
|
+
let operationType = 'unknown';
|
|
133
|
+
const entities = [];
|
|
134
|
+
// Detect operation type from keywords
|
|
135
|
+
if (lowerMessage.includes('查询') ||
|
|
136
|
+
lowerMessage.includes('获取') ||
|
|
137
|
+
lowerMessage.includes('查看') ||
|
|
138
|
+
lowerMessage.includes('显示') ||
|
|
139
|
+
lowerMessage.includes('what') ||
|
|
140
|
+
lowerMessage.includes('show') ||
|
|
141
|
+
lowerMessage.includes('get') ||
|
|
142
|
+
lowerMessage.includes('list')) {
|
|
143
|
+
operationType = 'query';
|
|
144
|
+
}
|
|
145
|
+
else if (lowerMessage.includes('创建') ||
|
|
146
|
+
lowerMessage.includes('新建') ||
|
|
147
|
+
lowerMessage.includes('添加') ||
|
|
148
|
+
lowerMessage.includes('create') ||
|
|
149
|
+
lowerMessage.includes('add') ||
|
|
150
|
+
lowerMessage.includes('new')) {
|
|
151
|
+
operationType = 'create';
|
|
152
|
+
}
|
|
153
|
+
else if (lowerMessage.includes('修改') ||
|
|
154
|
+
lowerMessage.includes('更新') ||
|
|
155
|
+
lowerMessage.includes('编辑') ||
|
|
156
|
+
lowerMessage.includes('update') ||
|
|
157
|
+
lowerMessage.includes('modify') ||
|
|
158
|
+
lowerMessage.includes('edit')) {
|
|
159
|
+
operationType = 'update';
|
|
160
|
+
}
|
|
161
|
+
else if (lowerMessage.includes('删除') ||
|
|
162
|
+
lowerMessage.includes('移除') ||
|
|
163
|
+
lowerMessage.includes('delete') ||
|
|
164
|
+
lowerMessage.includes('remove')) {
|
|
165
|
+
operationType = 'delete';
|
|
166
|
+
}
|
|
167
|
+
else if (lowerMessage.includes('执行') ||
|
|
168
|
+
lowerMessage.includes('运行') ||
|
|
169
|
+
lowerMessage.includes('execute') ||
|
|
170
|
+
lowerMessage.includes('run')) {
|
|
171
|
+
operationType = 'execute';
|
|
172
|
+
}
|
|
173
|
+
else if (lowerMessage.includes('配置') ||
|
|
174
|
+
lowerMessage.includes('设置') ||
|
|
175
|
+
lowerMessage.includes('configure') ||
|
|
176
|
+
lowerMessage.includes('set')) {
|
|
177
|
+
operationType = 'configure';
|
|
178
|
+
}
|
|
179
|
+
// Higher confidence if we detected a known operation type
|
|
180
|
+
const confidence = operationType !== 'unknown' ? 0.6 : 0.3;
|
|
181
|
+
return {
|
|
182
|
+
action: message.slice(0, 100), // Use first 100 chars as action
|
|
183
|
+
entities,
|
|
184
|
+
requiredTopics: [],
|
|
185
|
+
confidence,
|
|
186
|
+
originalMessage: message,
|
|
187
|
+
operationType,
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Extract entities from a message using simple pattern matching
|
|
192
|
+
* Used as a supplement to LLM parsing
|
|
193
|
+
*/
|
|
194
|
+
extractEntities(message) {
|
|
195
|
+
const entities = [];
|
|
196
|
+
// Extract quoted strings
|
|
197
|
+
const quotedMatches = message.match(/["'](.*?)["']/g);
|
|
198
|
+
if (quotedMatches) {
|
|
199
|
+
entities.push(...quotedMatches.map((m) => m.slice(1, -1)));
|
|
200
|
+
}
|
|
201
|
+
// Extract potential identifiers (CamelCase or snake_case)
|
|
202
|
+
const identifierMatches = message.match(/\b[A-Z][a-zA-Z0-9]*(?:_[a-zA-Z0-9]+)*\b/g);
|
|
203
|
+
if (identifierMatches) {
|
|
204
|
+
entities.push(...identifierMatches);
|
|
205
|
+
}
|
|
206
|
+
return [...new Set(entities)]; // Remove duplicates
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Update the system prompt
|
|
210
|
+
*/
|
|
211
|
+
setSystemPrompt(prompt) {
|
|
212
|
+
this.config.systemPrompt = prompt;
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Get current configuration
|
|
216
|
+
*/
|
|
217
|
+
getConfig() {
|
|
218
|
+
return { ...this.config };
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
//# sourceMappingURL=intent-parser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"intent-parser.js","sourceRoot":"","sources":["../../src/core/intent-parser.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AA2D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an Generator
|
|
3
|
+
*
|
|
4
|
+
* Generates execution plans based on parsed intent and retrieved knowledge.
|
|
5
|
+
* Determines which tools to call and in what order.
|
|
6
|
+
*
|
|
7
|
+
* _Requirements: 1.3_
|
|
8
|
+
*/
|
|
9
|
+
import type { LLMManager } from '../llm/manager.js';
|
|
10
|
+
import type { ChatMessage } from '../llm/adapter.js';
|
|
11
|
+
import type { SearchResult } from '../types/knowledge.js';
|
|
12
|
+
import type { DetailedIntent } from './intent-parser.js';
|
|
13
|
+
import type { ToolRegistry } from './tool-registry.js';
|
|
14
|
+
/**
|
|
15
|
+
* A single step in an execution plan
|
|
16
|
+
*/
|
|
17
|
+
export interface PlanStep {
|
|
18
|
+
/** Step number (1-based) */
|
|
19
|
+
stepNumber: number;
|
|
20
|
+
/** Tool to call */
|
|
21
|
+
toolName: string;
|
|
22
|
+
/** Arguments to pass to the tool */
|
|
23
|
+
arguments: Record<string, unknown>;
|
|
24
|
+
/** Description of what this step does */
|
|
25
|
+
description: string;
|
|
26
|
+
/** Whether this step depends on previous step results */
|
|
27
|
+
dependsOnPrevious: boolean;
|
|
28
|
+
/** Condition for executing this step (optional) */
|
|
29
|
+
condition?: string;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Complete execution plan
|
|
33
|
+
*/
|
|
34
|
+
export interface ExecutionPlan {
|
|
35
|
+
/** Unique plan ID */
|
|
36
|
+
id: string;
|
|
37
|
+
/** Steps to execute */
|
|
38
|
+
steps: PlanStep[];
|
|
39
|
+
/** Overall plan description */
|
|
40
|
+
description: string;
|
|
41
|
+
/** Estimated risk level */
|
|
42
|
+
riskLevel: 'low' | 'medium' | 'high';
|
|
43
|
+
/** Whether the plan requires user confirmation */
|
|
44
|
+
requiresConfirmation: boolean;
|
|
45
|
+
/** Confidence in the plan */
|
|
46
|
+
confidence: number;
|
|
47
|
+
/** Original intent that generated this plan */
|
|
48
|
+
intent: DetailedIntent;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Plan generation result
|
|
52
|
+
*/
|
|
53
|
+
export interface PlanGenerationResult {
|
|
54
|
+
/** Whether plan generation was successful */
|
|
55
|
+
success: boolean;
|
|
56
|
+
/** Generated plan (if successful) */
|
|
57
|
+
plan?: ExecutionPlan;
|
|
58
|
+
/** Reason for failure (if unsuccessful) */
|
|
59
|
+
failureReason?: string;
|
|
60
|
+
/** Missing information needed to generate plan */
|
|
61
|
+
missingInfo?: string[];
|
|
62
|
+
/** Alternative suggestions */
|
|
63
|
+
suggestions?: string[];
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Plan generator configuration
|
|
67
|
+
*/
|
|
68
|
+
export interface PlanGeneratorConfig {
|
|
69
|
+
/** System prompt for plan generation */
|
|
70
|
+
systemPrompt?: string;
|
|
71
|
+
/** Maximum steps allowed in a plan */
|
|
72
|
+
maxSteps?: number;
|
|
73
|
+
/** Whether to require confirmation for high-risk operations */
|
|
74
|
+
requireConfirmationForHighRisk?: boolean;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Plan Generator
|
|
78
|
+
*
|
|
79
|
+
* Uses LLM to generate execution plans based on intent and available tools.
|
|
80
|
+
*/
|
|
81
|
+
export declare class PlanGenerator {
|
|
82
|
+
private llmManager;
|
|
83
|
+
private toolRegistry;
|
|
84
|
+
private config;
|
|
85
|
+
private planCounter;
|
|
86
|
+
constructor(llmManager: LLMManager, toolRegistry: ToolRegistry, config?: PlanGeneratorConfig);
|
|
87
|
+
/**
|
|
88
|
+
* Generate an execution plan based on intent and knowledge
|
|
89
|
+
*
|
|
90
|
+
* @param intent - Parsed user intent
|
|
91
|
+
* @param knowledge - Retrieved knowledge results
|
|
92
|
+
* @param history - Optional conversation history
|
|
93
|
+
* @returns Plan generation result
|
|
94
|
+
*/
|
|
95
|
+
generate(intent: DetailedIntent, knowledge: SearchResult[], history?: ChatMessage[]): Promise<PlanGenerationResult>;
|
|
96
|
+
/**
|
|
97
|
+
* Build messages for LLM call
|
|
98
|
+
*/
|
|
99
|
+
private buildMessages;
|
|
100
|
+
/**
|
|
101
|
+
* Build the user message with all context
|
|
102
|
+
*/
|
|
103
|
+
private buildUserMessage;
|
|
104
|
+
/**
|
|
105
|
+
* Parse LLM response into PlanGenerationResult
|
|
106
|
+
*/
|
|
107
|
+
private parseResponse;
|
|
108
|
+
/**
|
|
109
|
+
* Validate and build execution plan from parsed response
|
|
110
|
+
*/
|
|
111
|
+
private validateAndBuildPlan;
|
|
112
|
+
/**
|
|
113
|
+
* Validate risk level
|
|
114
|
+
*/
|
|
115
|
+
private validateRiskLevel;
|
|
116
|
+
/**
|
|
117
|
+
* Generate unique plan ID
|
|
118
|
+
*/
|
|
119
|
+
private generatePlanId;
|
|
120
|
+
/**
|
|
121
|
+
* Create a simple single-step plan for direct tool calls
|
|
122
|
+
*/
|
|
123
|
+
createDirectPlan(toolName: string, args: Record<string, unknown>, intent: DetailedIntent): ExecutionPlan;
|
|
124
|
+
/**
|
|
125
|
+
* Estimate risk level based on operation type and tools
|
|
126
|
+
*/
|
|
127
|
+
estimateRiskLevel(intent: DetailedIntent, toolNames: string[]): 'low' | 'medium' | 'high';
|
|
128
|
+
/**
|
|
129
|
+
* Get current configuration
|
|
130
|
+
*/
|
|
131
|
+
getConfig(): Required<PlanGeneratorConfig>;
|
|
132
|
+
}
|
|
133
|
+
//# sourceMappingURL=plan-generator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plan-generator.d.ts","sourceRoot":"","sources":["../../src/core/plan-generator.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAErD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAC1D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,KAAK,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