@eoasmxd/freya 0.3.0 → 0.4.1
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 +9 -3
- package/core/dist/command/commands/skill-commands.js +5 -4
- package/core/dist/config/config-manager.d.ts +5 -1
- package/core/dist/config/config-manager.js +13 -1
- package/core/dist/kernel.js +2 -2
- package/core/dist/skill/skill-registry.d.ts +12 -2
- package/core/dist/skill/skill-registry.js +89 -8
- package/core/dist/tools/meta/index.d.ts +3 -1
- package/core/dist/tools/meta/index.js +9 -1
- package/core/dist/web/config-api.js +18 -0
- package/core/package.json +2 -2
- package/doc/_index.md +20 -7
- package/doc/getting-started.md +1 -1
- package/doc/installation-guide.md +2 -2
- package/doc/{architecture-design.md → specifications/architecture-design.md} +7 -4
- package/doc/{config-spec.md → specifications/config-spec.md} +1 -1
- package/doc/{llm-interface-params.md → specifications/llm-interface-params.md} +8 -8
- package/doc/{prompt-system.md → specifications/prompt-system.md} +1 -1
- package/doc/tutorials/_index.md +96 -0
- package/doc/tutorials/part0_basic/0.1_probability_prediction.md +155 -0
- package/doc/tutorials/part0_basic/0.2_attention_and_context.md +145 -0
- package/doc/tutorials/part0_basic/0.3_generation_parameters.md +132 -0
- package/doc/tutorials/part0_basic/0.4_debugging_token.md +99 -0
- package/doc/tutorials/part0_basic/1.1_stateless_and_history.md +143 -0
- package/doc/tutorials/part0_basic/1.2_chat_data_structure.md +179 -0
- package/doc/tutorials/part0_basic/1.3_system_user_assistant.md +147 -0
- package/doc/tutorials/part0_basic/1.4_freya_model_proxy.md +203 -0
- package/doc/tutorials/part0_basic/_index.md +28 -0
- package/doc/tutorials/part1_react/2.1_agency_vs_chatbot.md +127 -0
- package/doc/tutorials/part1_react/2.2_react_mind_model.md +144 -0
- package/doc/tutorials/part1_react/2.3_freya_agent_executor.md +233 -0
- package/doc/tutorials/part1_react/2.4_debugging_loop_deadlock.md +160 -0
- package/doc/tutorials/part1_react/3.1_hardcoded_prompt_pain.md +104 -0
- package/doc/tutorials/part1_react/3.2_decoupled_architecture.md +138 -0
- package/doc/tutorials/part1_react/3.3_freya_dual_read_probe.md +152 -0
- package/doc/tutorials/part1_react/3.4_debugging_composition_placeholder.md +97 -0
- package/doc/tutorials/part1_react/_index.md +28 -0
- package/doc/tutorials/part2_tools/4.1_json_schema_mapping.md +119 -0
- package/doc/tutorials/part2_tools/4.2_tool_call_raw_packet.md +105 -0
- package/doc/tutorials/part2_tools/4.3_freya_tool_execution.md +145 -0
- package/doc/tutorials/part2_tools/4.4_debugging_observation_fix.md +154 -0
- package/doc/tutorials/part2_tools/5.1_observation_injection.md +131 -0
- package/doc/tutorials/part2_tools/5.2_openai_vs_gemini_protocol.md +125 -0
- package/doc/tutorials/part2_tools/5.3_freya_llm_proxy_mapping.md +162 -0
- package/doc/tutorials/part2_tools/5.4_debugging_parallel_call_chaos.md +135 -0
- package/doc/tutorials/part2_tools/_index.md +28 -0
- package/doc/tutorials/part3_memory/6.1_session_state_lifecycle.md +143 -0
- package/doc/tutorials/part3_memory/6.2_physical_sandbox_separation.md +108 -0
- package/doc/tutorials/part3_memory/6.3_freya_session_storage.md +139 -0
- package/doc/tutorials/part3_memory/6.4_debugging_session_concurrency.md +161 -0
- package/doc/tutorials/part3_memory/7.1_context_overflow_loss.md +109 -0
- package/doc/tutorials/part3_memory/7.2_sliding_window_vs_summary.md +85 -0
- package/doc/tutorials/part3_memory/7.3_freya_compactor_impl.md +142 -0
- package/doc/tutorials/part3_memory/7.4_debugging_summarize_deadlock.md +160 -0
- package/doc/tutorials/part3_memory/_index.md +28 -0
- package/doc/tutorials/part4_streaming/8.1_sse_protocol_basics.md +119 -0
- package/doc/tutorials/part4_streaming/8.2_hiding_thoughts_in_stream.md +132 -0
- package/doc/tutorials/part4_streaming/8.3_freya_event_bus.md +104 -0
- package/doc/tutorials/part4_streaming/8.4_debugging_stream_decoder.md +158 -0
- package/doc/tutorials/part4_streaming/9.1_abort_signal_braking.md +162 -0
- package/doc/tutorials/part4_streaming/9.2_async_event_channels.md +142 -0
- package/doc/tutorials/part4_streaming/9.3_freya_abort_billing.md +122 -0
- package/doc/tutorials/part4_streaming/9.4_debugging_abort_lock_deadlock.md +187 -0
- package/doc/tutorials/part4_streaming/_index.md +28 -0
- package/doc/tutorials/part5_plugins/10.1_microkernel_decoupling.md +142 -0
- package/doc/tutorials/part5_plugins/10.2_plugin_metadata_security.md +125 -0
- package/doc/tutorials/part5_plugins/10.3_channel_plugin_development.md +149 -0
- package/doc/tutorials/part5_plugins/10.4_debugging_channel_reconnection.md +160 -0
- package/doc/tutorials/part5_plugins/_index.md +21 -0
- package/doc/tutorials/part6_advanced/11.1_react_model_flaws.md +111 -0
- package/doc/tutorials/part6_advanced/11.2_reflexion_mind_model.md +103 -0
- package/doc/tutorials/part6_advanced/11.3_reflexion_hands_on.md +182 -0
- package/doc/tutorials/part6_advanced/11.4_debugging_reflexion_convergence.md +108 -0
- package/doc/tutorials/part6_advanced/12.1_single_agent_limits.md +100 -0
- package/doc/tutorials/part6_advanced/12.2_multi_agent_patterns.md +121 -0
- package/doc/tutorials/part6_advanced/12.3_freya_multi_agent_routing.md +143 -0
- package/doc/tutorials/part6_advanced/12.4_multi_agent_hands_on.md +176 -0
- package/doc/tutorials/part6_advanced/_index.md +28 -0
- package/doc/tutorials/preface.md +30 -0
- package/package.json +3 -2
- package/plugins/plugin-gemini/package.json +1 -1
- package/plugins/plugin-openai/package.json +1 -1
- package/plugins/plugin-telegram-channel/package.json +1 -1
- package/plugins/plugin-tool-fs/package.json +1 -1
- package/plugins/plugin-tool-memory/package.json +1 -1
- package/plugins/plugin-tool-mysql/config/prompts/plugin.prompt.mysql.md +9 -0
- package/plugins/plugin-tool-mysql/config/prompts/plugin.prompt.mysql.select.audit.md +26 -0
- package/plugins/plugin-tool-mysql/dist/audit.d.ts +13 -0
- package/plugins/plugin-tool-mysql/dist/audit.js +87 -0
- package/plugins/plugin-tool-mysql/dist/index.d.ts +14 -0
- package/plugins/plugin-tool-mysql/dist/index.js +34 -0
- package/plugins/plugin-tool-mysql/dist/pool-manager.d.ts +32 -0
- package/plugins/plugin-tool-mysql/dist/pool-manager.js +113 -0
- package/plugins/plugin-tool-mysql/dist/tools.d.ts +11 -0
- package/plugins/plugin-tool-mysql/dist/tools.js +88 -0
- package/plugins/plugin-tool-mysql/package.json +33 -0
- package/plugins/plugin-tool-mysql/schema.json +83 -0
- package/plugins/plugin-tool-web/package.json +1 -1
- package/plugins/plugin-wecom-channel/package.json +1 -1
- package/plugins/plugin-weixin-channel/package.json +1 -1
- package/src/packages/core/src/command/commands/skill-commands.ts +6 -5
- package/src/packages/core/src/config/config-manager.ts +15 -1
- package/src/packages/core/src/kernel.ts +3 -2
- package/src/packages/core/src/skill/skill-registry.ts +100 -8
- package/src/packages/core/src/tools/meta/index.ts +9 -1
- package/src/packages/core/src/web/config-api.ts +20 -0
- package/src/packages/ui/src/features/config/ConfigModal.tsx +13 -1
- package/src/packages/ui/src/features/config/panels/SkillConfigPanel.tsx +137 -0
- package/src/plugins/plugin-tool-mysql/src/audit.ts +103 -0
- package/src/plugins/plugin-tool-mysql/src/index.ts +44 -0
- package/src/plugins/plugin-tool-mysql/src/pool-manager.ts +132 -0
- package/src/plugins/plugin-tool-mysql/src/tools.ts +100 -0
- package/ui/assets/{index-Be0cAgdB.js → index-BqPQMflk.js} +14 -14
- package/ui/index.html +1 -1
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import type { FreyaContext, ToolDefinition, FreyaTool } from '@eoasmxd/freya-sdk';
|
|
2
|
+
import type { MysqlPoolManager } from './pool-manager.js';
|
|
3
|
+
import type { SqlAuditService } from './audit.js';
|
|
4
|
+
|
|
5
|
+
/** 脱敏错误信息中的敏感凭据 */
|
|
6
|
+
function sanitizeErrorMessage(err: any, password?: string): string {
|
|
7
|
+
let message = err?.message || String(err);
|
|
8
|
+
if (password) {
|
|
9
|
+
message = message.replaceAll(password, '******');
|
|
10
|
+
}
|
|
11
|
+
return message;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** MySQL 数据库查询执行工具 */
|
|
15
|
+
export class MysqlQueryTool implements FreyaTool {
|
|
16
|
+
constructor(
|
|
17
|
+
private poolManager: MysqlPoolManager,
|
|
18
|
+
private auditService: SqlAuditService
|
|
19
|
+
) {}
|
|
20
|
+
|
|
21
|
+
getDefinition(): ToolDefinition {
|
|
22
|
+
return {
|
|
23
|
+
name: 'mysql_query',
|
|
24
|
+
description: '执行 MySQL SELECT 查询语句并返回结构化数据。执行前会进行独立 LLM 安全与完整性审核,支持通过 connection 指定目标连接。',
|
|
25
|
+
parameters: {
|
|
26
|
+
type: 'object',
|
|
27
|
+
properties: {
|
|
28
|
+
sql: {
|
|
29
|
+
type: 'string',
|
|
30
|
+
description: '待执行的 SQL 查询语句'
|
|
31
|
+
},
|
|
32
|
+
connection: {
|
|
33
|
+
type: 'string',
|
|
34
|
+
description: '目标数据库连接名称(可选,若未指定则使用系统默认连接)'
|
|
35
|
+
},
|
|
36
|
+
params: {
|
|
37
|
+
type: 'array',
|
|
38
|
+
items: {},
|
|
39
|
+
description: '可选的参数化查询参数列表'
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
required: ['sql']
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
async execute(args: Record<string, any>, ctx: FreyaContext): Promise<string> {
|
|
48
|
+
const rawSql = typeof args.sql === 'string' ? args.sql.trim() : '';
|
|
49
|
+
if (!rawSql) {
|
|
50
|
+
return '❌ 参数错误: sql 语句不能为空。';
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const connectionName = typeof args.connection === 'string' && args.connection.trim()
|
|
54
|
+
? args.connection.trim()
|
|
55
|
+
: undefined;
|
|
56
|
+
|
|
57
|
+
const queryParams = Array.isArray(args.params) ? args.params : undefined;
|
|
58
|
+
|
|
59
|
+
const auditResult = await this.auditService.audit(rawSql, connectionName || 'default', ctx);
|
|
60
|
+
if (!auditResult.passed) {
|
|
61
|
+
return `❌ SQL 审查未通过,已拒绝执行。\n原因: ${auditResult.reason}`;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
let currentPassword = '';
|
|
65
|
+
try {
|
|
66
|
+
const { pool, config } = this.poolManager.getPool(connectionName);
|
|
67
|
+
currentPassword = config.password || '';
|
|
68
|
+
|
|
69
|
+
const maxRows = Number(ctx.config?.mysql?.maxRows ?? ctx.config?.['mysql.maxRows']) || 100;
|
|
70
|
+
const [rows] = await pool.query(rawSql, queryParams);
|
|
71
|
+
|
|
72
|
+
if (!Array.isArray(rows)) {
|
|
73
|
+
return JSON.stringify({
|
|
74
|
+
connection: config.name,
|
|
75
|
+
database: config.database || null,
|
|
76
|
+
affectedRows: (rows as any).affectedRows ?? 0,
|
|
77
|
+
info: (rows as any).info || '查询已完成'
|
|
78
|
+
}, null, 2);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const totalCount = rows.length;
|
|
82
|
+
const truncated = totalCount > maxRows;
|
|
83
|
+
const data = truncated ? rows.slice(0, maxRows) : rows;
|
|
84
|
+
|
|
85
|
+
return JSON.stringify({
|
|
86
|
+
connection: config.name,
|
|
87
|
+
database: config.database || null,
|
|
88
|
+
totalCount,
|
|
89
|
+
returnedCount: data.length,
|
|
90
|
+
truncated,
|
|
91
|
+
notice: truncated ? `结果集超过最大限制 ${maxRows} 条,已自动截断返回前 ${maxRows} 条记录。` : undefined,
|
|
92
|
+
data
|
|
93
|
+
}, null, 2);
|
|
94
|
+
} catch (err: any) {
|
|
95
|
+
const safeMessage = sanitizeErrorMessage(err, currentPassword);
|
|
96
|
+
ctx.logger.error(`MySQL 查询执行异常: ${safeMessage}`);
|
|
97
|
+
return `❌ MySQL 查询执行失败: ${safeMessage}`;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|