@axiom-lattice/examples-deep_research 1.0.26 → 1.0.28

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.
Files changed (34) hide show
  1. package/.env +6 -0
  2. package/.turbo/turbo-build.log +5 -5
  3. package/CHANGELOG.md +22 -0
  4. package/DATABASE_CONFIG_SETUP.md +290 -0
  5. package/dist/index.js +146 -22
  6. package/dist/index.js.map +1 -1
  7. package/package.json +5 -5
  8. package/src/agents/data_agent/skills/business-analytics/README.md +121 -0
  9. package/src/agents/data_agent/skills/business-analytics/SKILL.md +230 -0
  10. package/src/agents/data_agent/skills/business-analytics/examples.md +295 -0
  11. package/src/agents/data_agent/skills/business-analytics/reference.md +240 -0
  12. package/src/agents/data_agent/skills/business-analytics/resources/data/sample.json +66 -0
  13. package/src/agents/data_agent/skills/business-analytics/resources/prompts/analyze.txt +128 -0
  14. package/src/agents/data_agent/skills/business-analytics/resources/templates/report-template.md +260 -0
  15. package/src/agents/data_agent/skills/chart-markdown/SKILL.md +91 -0
  16. package/src/agents/data_agent/skills/chart-markdown/resources/best-practices/README.md +16 -0
  17. package/src/agents/data_agent/skills/chart-markdown/resources/best-practices/data-patterns.md +14 -0
  18. package/src/agents/data_agent/skills/chart-markdown/resources/best-practices/finance.md +7 -0
  19. package/src/agents/data_agent/skills/chart-markdown/resources/best-practices/formatting.md +14 -0
  20. package/src/agents/data_agent/skills/chart-markdown/resources/best-practices/hr-people.md +7 -0
  21. package/src/agents/data_agent/skills/chart-markdown/resources/best-practices/marketing-growth.md +7 -0
  22. package/src/agents/data_agent/skills/chart-markdown/resources/best-practices/operations-supply-chain.md +7 -0
  23. package/src/agents/data_agent/skills/chart-markdown/resources/best-practices/sales-retail.md +8 -0
  24. package/src/agents/data_agent/skills/chart-markdown/resources/examples.md +80 -0
  25. package/src/agents/data_agent/skills/financial-analysis/SKILL.md +268 -0
  26. package/src/agents/data_agent/skills/metrics-query/SKILL.md +296 -0
  27. package/src/agents/data_agent/skills/operations-analysis/SKILL.md +432 -0
  28. package/src/agents/data_agent/skills/sales-analysis/SKILL.md +350 -0
  29. package/src/agents/index.ts +1 -0
  30. package/src/agents/research_team/index.ts +93 -0
  31. package/src/index-with-auth.ts +122 -0
  32. package/src/index.ts +93 -3
  33. package/src/agents/data_agent/skills/sql-query/SKILL.md +0 -58
  34. package/src/agents/data_agent/skills/test/SKILL.md +0 -9
@@ -0,0 +1,350 @@
1
+ ---
2
+ name: sales-analysis
3
+ description: 执行销售数据分析,包括销售业绩、客户分析、产品分析、区域分析四大模块。适用于评估销售团队绩效和市场表现。
4
+ metadata:
5
+ category: sales_analysis
6
+ parentSkill: business-analytics
7
+ ---
8
+
9
+ ## 分析模块
10
+
11
+ ### 模块一:销售业绩分析
12
+
13
+ #### 分析维度
14
+ - **人员维度**:销售人员/团队业绩排名
15
+ - **时间维度**:日/周/月/季度/年度业绩趋势
16
+ - **目标维度**:目标达成率分析
17
+ - **渠道维度**:直销/分销/电商等渠道对比
18
+
19
+ #### 关键指标
20
+ ```
21
+ 销售额 = 销售数量 × 单价
22
+ 目标达成率 = 实际销售额 / 目标销售额 × 100%
23
+ 同比增长率 = (本期销售额 - 同期销售额) / 同期销售额 × 100%
24
+ 环比增长率 = (本期销售额 - 上期销售额) / 上期销售额 × 100%
25
+ 人均销售额 = 总销售额 / 销售人员数量
26
+ 平均客单价 = 总销售额 / 订单数量
27
+ ```
28
+
29
+ #### 分析流程
30
+
31
+ 1. **业绩总览**
32
+ - 统计总体销售数据
33
+ - 对比目标完成情况
34
+ - 分析同比/环比变化
35
+
36
+ 2. **排名分析**
37
+ - 销售人员业绩排名
38
+ - 识别 Top/Bottom Performers
39
+ - 分析业绩分布
40
+
41
+ 3. **趋势分析**
42
+ - 绘制销售趋势图
43
+ - 识别季节性规律
44
+ - 预测未来走势
45
+
46
+ 4. **达成分析**
47
+ - 目标达成率计算
48
+ - 差距分析
49
+ - 原因探究
50
+
51
+ #### 输出模板
52
+
53
+ ```markdown
54
+ ## 销售业绩分析报告
55
+
56
+ ### 执行摘要
57
+ - 总销售额:[X]万元,达成率[X]%,同比[增长/下降][X]%
58
+ - Top 3 销售人员:[姓名]、[姓名]、[姓名]
59
+ - 关键发现:[核心发现]
60
+
61
+ ### 业绩排名
62
+ | 排名 | 销售人员 | 销售额 | 目标 | 达成率 | 同比 |
63
+ |-----|---------|-------|-----|-------|-----|
64
+ | 1 | | | | | |
65
+ | 2 | | | | | |
66
+
67
+ ### 趋势分析
68
+ - 图表:销售额月度趋势图
69
+ - 季节性分析:[分析结果]
70
+
71
+ ### 改进建议
72
+ 1. [针对低业绩人员的改进建议]
73
+ 2. [针对高业绩人员的激励建议]
74
+ ```
75
+
76
+ ---
77
+
78
+ ### 模块二:客户分析
79
+
80
+ #### 分析维度
81
+ - **价值维度**:按销售额/利润贡献分层
82
+ - **行为维度**:购买频率、购买周期、客单价
83
+ - **生命周期维度**:新客户、活跃客户、流失客户
84
+ - **属性维度**:行业、规模、地域
85
+
86
+ #### 客户分层模型(RFM)
87
+ ```
88
+ R (Recency):最近一次购买时间
89
+ F (Frequency):购买频率
90
+ M (Monetary):购买金额
91
+
92
+ 分层标准:
93
+ - VIP客户:高价值、高频次、近期活跃
94
+ - 重要客户:高价值、中频次
95
+ - 潜力客户:中价值、高频次
96
+ - 一般客户:中低价值
97
+ - 流失风险客户:长期未购买
98
+ ```
99
+
100
+ #### 关键指标
101
+ ```
102
+ 客户总数 = 统计期间内的客户数量
103
+ 活跃客户数 = 有购买行为的客户数
104
+ 客户流失率 = 流失客户数 / 期初客户数 × 100%
105
+ 客户留存率 = 留存客户数 / 期初客户数 × 100%
106
+ 客户生命周期价值(LTV) = 平均客单价 × 购买频率 × 客户平均生命周期
107
+ 客户获取成本(CAC) = 营销费用 / 新增客户数
108
+ ```
109
+
110
+ #### 分析流程
111
+
112
+ 1. **客户画像**
113
+ - 客户基本属性分布
114
+ - 购买行为特征
115
+ - 偏好分析
116
+
117
+ 2. **价值分层**
118
+ - 按销售额分层
119
+ - 按利润贡献分层
120
+ - 按战略重要性分层
121
+
122
+ 3. **TOP 20 分析**
123
+ - 识别 TOP 20 客户
124
+ - 分析贡献度占比
125
+ - 评估集中度风险
126
+
127
+ 4. **流失预警**
128
+ - 识别流失风险客户
129
+ - 分析流失原因
130
+ - 制定挽回策略
131
+
132
+ #### 输出模板
133
+
134
+ ```markdown
135
+ ## 客户分析报告
136
+
137
+ ### 执行摘要
138
+ - 客户总数:[X]家,活跃客户[X]家,流失率[X]%
139
+ - TOP 20 客户贡献度:[X]%
140
+ - 关键发现:[核心发现]
141
+
142
+ ### 客户分层
143
+ | 层级 | 客户数 | 销售额占比 | 特征描述 |
144
+ |-----|-------|-----------|---------|
145
+ | VIP | | | |
146
+ | 重要 | | | |
147
+ | 潜力 | | | |
148
+ | 一般 | | | |
149
+
150
+ ### TOP 20 客户
151
+ | 排名 | 客户名称 | 销售额 | 利润 | 贡献占比 | 流失风险 |
152
+ |-----|---------|-------|-----|---------|---------|
153
+ | 1 | | | | | |
154
+ | 2 | | | | | |
155
+
156
+ ### 流失风险客户
157
+ | 客户名称 | 上次购买日期 | 历史销售额 | 风险等级 | 建议措施 |
158
+ |---------|------------|-----------|---------|---------|
159
+ | | | | | |
160
+
161
+ ### 客户策略建议
162
+ 1. [VIP客户维护策略]
163
+ 2. [潜力客户培育策略]
164
+ 3. [流失客户挽回策略]
165
+ ```
166
+
167
+ ---
168
+
169
+ ### 模块三:产品分析
170
+
171
+ #### 分析维度
172
+ - **销售维度**:销量、销售额排名
173
+ - **增长维度**:增长率、增长贡献
174
+ - **盈利维度**:毛利贡献、毛利率
175
+ - **生命周期维度**:新品、成长期、成熟期、衰退期
176
+
177
+ #### 波士顿矩阵分类
178
+ ```
179
+ 明星产品:高增长、高市场份额 → 加大投资
180
+ 金牛产品:低增长、高市场份额 → 维持现状
181
+ 问题产品:高增长、低市场份额 → 选择性投资
182
+ 瘦狗产品:低增长、低市场份额 → 淘汰或重组
183
+ ```
184
+
185
+ #### 关键指标
186
+ ```
187
+ 产品销售占比 = 产品销售额 / 总销售额 × 100%
188
+ 同比增长率 = (本期销量 - 同期销量) / 同期销量 × 100%
189
+ 市场增长率 = 行业增长率
190
+ 相对市场份额 = 本公司产品份额 / 最大竞争对手份额
191
+ ```
192
+
193
+ #### 分析流程
194
+
195
+ 1. **销售表现**
196
+ - 销量/销售额排名
197
+ - 增长趋势分析
198
+ - 季节性分析
199
+
200
+ 2. **盈利贡献**
201
+ - 毛利贡献排名
202
+ - 毛利率分析
203
+ - 交叉补贴分析
204
+
205
+ 3. **产品结构**
206
+ - 产品组合分析
207
+ - 波士顿矩阵定位
208
+ - 优化建议
209
+
210
+ 4. **新品分析**
211
+ - 新品销售表现
212
+ - 市场接受度
213
+ - 推广效果评估
214
+
215
+ #### 输出模板
216
+
217
+ ```markdown
218
+ ## 产品分析报告
219
+
220
+ ### 执行摘要
221
+ - 产品总数:[X]款,销售额[X]万元
222
+ - TOP 5 产品:[产品名称列表]
223
+ - 新品表现:[核心发现]
224
+
225
+ ### 产品销售排名
226
+ | 排名 | 产品名称 | 销售额 | 销量 | 增长率 | 毛利率 |
227
+ |-----|---------|-------|-----|-------|-------|
228
+ | 1 | | | | | |
229
+ | 2 | | | | | |
230
+
231
+ ### 波士顿矩阵
232
+ - 图表:产品波士顿矩阵图
233
+ - 明星产品:[列表]
234
+ - 金牛产品:[列表]
235
+ - 问题产品:[列表]
236
+ - 瘦狗产品:[列表]
237
+
238
+ ### 产品策略建议
239
+ 1. [明星产品策略]
240
+ 2. [金牛产品策略]
241
+ 3. [问题产品策略]
242
+ ```
243
+
244
+ ---
245
+
246
+ ### 模块四:区域分析
247
+
248
+ #### 分析维度
249
+ - **业绩维度**:各区域销售额、达成率
250
+ - **增长维度**:各区域增长率对比
251
+ - **潜力维度**:市场渗透率、增长空间
252
+ - **资源维度**:投入产出比
253
+
254
+ #### 关键指标
255
+ ```
256
+ 区域销售占比 = 区域销售额 / 总销售额 × 100%
257
+ 区域增长率 = (本期区域销售额 - 同期区域销售额) / 同期区域销售额 × 100%
258
+ 市场渗透率 = 现有客户数 / 区域潜在客户数 × 100%
259
+ 人均产出 = 区域销售额 / 区域销售人员数
260
+ ```
261
+
262
+ #### 分析流程
263
+
264
+ 1. **业绩对比**
265
+ - 各区域销售额对比
266
+ - 目标达成率对比
267
+ - 排名分析
268
+
269
+ 2. **增长分析**
270
+ - 同比增长率
271
+ - 增长贡献度
272
+ - 增长驱动因素
273
+
274
+ 3. **潜力评估**
275
+ - 市场规模估算
276
+ - 渗透率分析
277
+ - 增长空间评估
278
+
279
+ 4. **资源效率**
280
+ - 投入产出分析
281
+ - 人均产出对比
282
+ - 优化建议
283
+
284
+ #### 输出模板
285
+
286
+ ```markdown
287
+ ## 区域分析报告
288
+
289
+ ### 执行摘要
290
+ - 最佳区域:[区域名称],销售额[X]万元
291
+ - 增长最快区域:[区域名称],增长率[X]%
292
+ - 潜力区域:[区域名称]
293
+
294
+ ### 区域业绩对比
295
+ | 区域 | 销售额 | 目标 | 达成率 | 同比增长 | 占比 |
296
+ |-----|-------|-----|-------|---------|-----|
297
+ | 华东 | | | | | |
298
+ | 华南 | | | | | |
299
+ | 华北 | | | | | |
300
+
301
+ ### 区域潜力分析
302
+ | 区域 | 市场规模 | 现有客户 | 渗透率 | 增长空间 |
303
+ |-----|---------|---------|-------|---------|
304
+ | | | | | |
305
+
306
+ ### 区域策略建议
307
+ 1. [重点投入区域策略]
308
+ 2. [潜力开发区域策略]
309
+ 3. [效率优化区域策略]
310
+ ```
311
+
312
+ ---
313
+
314
+ ## 通用分析流程
315
+
316
+ ### 步骤 1:问题理解
317
+ - 确定分析类型(业绩/客户/产品/区域)
318
+ - 明确分析维度
319
+ - 确定时间范围
320
+
321
+ ### 步骤 2:数据准备
322
+ - 销售数据检索
323
+ - 客户数据检索
324
+ - 产品数据检索
325
+ - 区域数据检索
326
+
327
+ ### 步骤 3:指标计算
328
+ - 计算关键指标
329
+ - 进行排名和对比
330
+ - 识别异常值
331
+
332
+ ### 步骤 4:可视化
333
+ - 趋势图:展示时间变化
334
+ - 对比图:展示维度差异
335
+ - 结构图:展示占比关系
336
+ - 矩阵图:展示战略定位
337
+
338
+ ### 步骤 5:洞察与建议
339
+ - 总结关键发现
340
+ - 分析根本原因
341
+ - 提出行动建议
342
+
343
+ ## 常见问题与解决方案
344
+
345
+ | 问题 | 解决方案 |
346
+ |-----|---------|
347
+ | 销售数据与财务数据不一致 | 核对数据口径,统一统计标准 |
348
+ | 客户信息不完整 | 完善客户档案,建立数据治理机制 |
349
+ | 区域划分不明确 | 明确区域边界和归属规则 |
350
+ | 重复计算问题 | 建立去重规则,确保数据准确性 |
@@ -1,5 +1,6 @@
1
1
  //import "./todo";
2
2
  import "./research";
3
+ import "./research_team";
3
4
  import "./data_agent";
4
5
  // import "./inventory_doctor";
5
6
  import "./sandbox_agent";
@@ -0,0 +1,93 @@
1
+ /**
2
+ * Team-based Deep Research Agent
3
+ *
4
+ * This is the TEAM version of the deep_research_agent, designed to be
5
+ * compared side-by-side with the original DEEP_AGENT version.
6
+ *
7
+ * Architecture difference:
8
+ * - DEEP_AGENT version: Leader calls sub-agents sequentially/parallel,
9
+ * each sub-agent completes a single invocation and returns.
10
+ * - TEAM version: Leader creates a team with a shared task list and mailbox.
11
+ * Teammates are persistent workers that claim tasks from the list,
12
+ * report back via messages, and keep working until all tasks are done.
13
+ * The leader can dynamically add/modify tasks based on user feedback
14
+ * or teammate discoveries.
15
+ */
16
+
17
+ import {
18
+ registerAgentLattices,
19
+ AgentType,
20
+ } from "@axiom-lattice/core";
21
+ import type { AgentConfig, TeamAgentConfig } from "@axiom-lattice/protocols";
22
+ import z from "zod";
23
+
24
+ // ---------------------------------------------------------------------------
25
+ // Team Lead prompt -- the orchestrator
26
+ // ---------------------------------------------------------------------------
27
+
28
+ const teamLeadPrompt = `You are an expert research team lead. You coordinate a team of specialized agents to produce a thorough, polished research report.
29
+
30
+ ## Workflow
31
+
32
+ 1. When given a research topic, break it down into concrete research tasks:
33
+ - Multiple focused research sub-topics (assign to "researcher" teammates)
34
+ - A final critique pass (assign to "critic" teammate)
35
+ - A writing/synthesis task (you will handle this yourself after research is done)
36
+
37
+ 2. Call \`create_team\` with the initial tasks and teammates. Tasks can have dependencies (e.g. critique depends on all research tasks completing).
38
+
39
+ 3. While tasks are NOT all completed: You MUST periodically call \`check_tasks\` and \`read_messages\` to monitor progress. Do not assume tasks are done without checking. Keep polling until all research tasks show completed or failed.
40
+ - If a teammate reports new findings that require additional research, use \`add_tasks\` to add follow-up tasks.
41
+
42
+ 4. Once all research tasks are complete (verify via \`check_tasks\`), synthesize the results into a final report.
43
+
44
+ 5. After the critic reviews, incorporate feedback and produce the final version.
45
+
46
+ ## Report Writing Guidelines
47
+
48
+ CRITICAL: Write the report in the SAME language as the user's message.
49
+
50
+ The final report should:
51
+ - Be well-organized with proper headings (# for title, ## for sections, ### for subsections)
52
+ - Include specific facts and insights from the research
53
+ - Reference relevant sources using [Title](URL) format
54
+ - Provide a balanced, thorough analysis
55
+ - Include a "Sources" section at the end
56
+ - Be text-heavy -- not just bullet points
57
+ - Be comprehensive and detailed
58
+
59
+ <Citation Rules>
60
+ - Assign each unique URL a single citation number
61
+ - End with ### Sources listing each source with numbers
62
+ - Number sources sequentially (1,2,3,4...)
63
+ - Each source as a separate list item: [1] Source Title: URL
64
+ </Citation Rules>
65
+
66
+ ## Available Teammates
67
+
68
+ - **researcher**: Can search the internet for information. Assign one research sub-topic per task. You can create multiple researcher tasks to run in parallel.
69
+ - **critic**: Reviews research results and the draft report for quality, completeness, and accuracy. The critic does NOT have search tools -- only reviews text.`;
70
+
71
+ // ---------------------------------------------------------------------------
72
+ // Team Agent Config
73
+ // ---------------------------------------------------------------------------
74
+
75
+ const teamResearchAgent: TeamAgentConfig = {
76
+ key: "team_research_agent",
77
+ name: "Team Research Agent",
78
+ description:
79
+ "Team-based deep research agent. Uses a team of persistent researcher and critic " +
80
+ "agents that work in parallel via a shared task list and mailbox. " +
81
+ "Compare with deep_research_agent (DEEP_AGENT version) for architectural differences.",
82
+ type: AgentType.TEAM,
83
+ prompt: teamLeadPrompt,
84
+ tools: ["internet_search"], // Team lead also has search capability
85
+ schema: z.object({
86
+ test: z.string().optional(),
87
+ }),
88
+ scheduleLatticeKey: "default", // Use ScheduleLattice for polling task list
89
+ pollIntervalMs: 5000, // Poll every 5 seconds
90
+ };
91
+
92
+ // Register the team research agent
93
+ registerAgentLattices([teamResearchAgent] as AgentConfig[]);
@@ -0,0 +1,122 @@
1
+ import dotenv from "dotenv";
2
+ import path from "path";
3
+ import { LatticeGateway } from "@axiom-lattice/gateway";
4
+ import {
5
+ storeLatticeManager,
6
+ registerStoreLattice,
7
+ } from "@axiom-lattice/core";
8
+ import { LoggerConfig, LoggerType } from "@axiom-lattice/protocols";
9
+ import {
10
+ PostgreSQLThreadStore,
11
+ PostgreSQLDatabaseConfigStore,
12
+ PostgreSQLWorkspaceStore,
13
+ PostgreSQLProjectStore,
14
+ PostgreSQLUserStore,
15
+ PostgreSQLTenantStore,
16
+ } from "@axiom-lattice/pg-stores";
17
+ import "./agents";
18
+
19
+ // Load environment variables
20
+ dotenv.config({ path: path.resolve(__dirname, "../.env") });
21
+
22
+ console.log(`
23
+ ╔════════════════════════════════════════════════╗
24
+ ║ Lattice Deep Research Server ║
25
+ ║ With Multi-Tenant Auth Support ║
26
+ ╚════════════════════════════════════════════════╝
27
+ `);
28
+
29
+ // Auth Configuration
30
+ const AUTH_CONFIG = {
31
+ // Auto approve new user registrations (true = no admin approval needed)
32
+ autoApproveUsers: process.env.AUTO_APPROVE_USERS !== "false",
33
+
34
+ // Allow users to create new tenants during registration
35
+ allowTenantRegistration: process.env.ALLOW_TENANT_REGISTRATION !== "false",
36
+
37
+ // JWT secret for token signing (change in production!)
38
+ jwtSecret: process.env.JWT_SECRET || "your-secret-key-change-in-production",
39
+
40
+ // Token expiration in seconds (default: 24 hours)
41
+ tokenExpiration: parseInt(process.env.TOKEN_EXPIRATION || "86400", 10),
42
+ };
43
+
44
+ console.log("Auth Configuration:");
45
+ console.log(` - Auto Approve Users: ${AUTH_CONFIG.autoApproveUsers}`);
46
+ console.log(` - Allow Tenant Registration: ${AUTH_CONFIG.allowTenantRegistration}`);
47
+ console.log(` - Token Expiration: ${AUTH_CONFIG.tokenExpiration}s`);
48
+
49
+ // Initialize PostgreSQL Stores with multi-tenant support
50
+ const dbConfig = process.env.DATABASE_URL || "";
51
+
52
+ // 1. User Store (NEW - for authentication)
53
+ const userStore = new PostgreSQLUserStore({
54
+ poolConfig: dbConfig,
55
+ autoMigrate: true,
56
+ });
57
+ storeLatticeManager.removeLattice("default", "user");
58
+ registerStoreLattice("default", "user", userStore);
59
+ console.log("✓ PostgreSQL UserStore initialized");
60
+
61
+ // 2. Tenant Store (NEW - for multi-tenancy)
62
+ const tenantStore = new PostgreSQLTenantStore({
63
+ poolConfig: dbConfig,
64
+ autoMigrate: true,
65
+ });
66
+ storeLatticeManager.removeLattice("default", "tenant");
67
+ registerStoreLattice("default", "tenant", tenantStore);
68
+ console.log("✓ PostgreSQL TenantStore initialized");
69
+
70
+ // 3. Existing stores...
71
+ const threadStore = new PostgreSQLThreadStore({ poolConfig: dbConfig });
72
+ storeLatticeManager.removeLattice("default", "thread");
73
+ registerStoreLattice("default", "thread", threadStore);
74
+
75
+ const databaseConfigStore = new PostgreSQLDatabaseConfigStore({
76
+ poolConfig: dbConfig,
77
+ autoMigrate: true,
78
+ });
79
+ storeLatticeManager.removeLattice("default", "database");
80
+ registerStoreLattice("default", "database", databaseConfigStore);
81
+
82
+ const workspaceStore = new PostgreSQLWorkspaceStore({
83
+ poolConfig: dbConfig,
84
+ autoMigrate: true,
85
+ });
86
+ storeLatticeManager.removeLattice("default", "workspace");
87
+ registerStoreLattice("default", "workspace", workspaceStore);
88
+
89
+ const projectStore = new PostgreSQLProjectStore({
90
+ poolConfig: dbConfig,
91
+ autoMigrate: true,
92
+ });
93
+ storeLatticeManager.removeLattice("default", "project");
94
+ registerStoreLattice("default", "project", projectStore);
95
+
96
+ // Parse port
97
+ const port = parseInt(process.env.PORT || "4001", 10);
98
+
99
+ // Logger config
100
+ const loggerConfig: LoggerConfig = {
101
+ name: "default",
102
+ description: "Default logger for lattice-gateway",
103
+ type: LoggerType.PINO,
104
+ serviceName: "lattice/deep_research",
105
+ loggerName: "lattice/deep_research",
106
+ };
107
+
108
+ // Start server with auth routes enabled
109
+ LatticeGateway.startAsHttpEndpoint({
110
+ port,
111
+ queueServiceConfig: { type: "memory", defaultStartPollingQueue: true },
112
+ loggerConfig,
113
+ });
114
+
115
+ console.log(`\n🚀 Server running at http://localhost:${port}`);
116
+ console.log("\nAuth Endpoints:");
117
+ console.log(` POST http://localhost:${port}/api/auth/register`);
118
+ console.log(` POST http://localhost:${port}/api/auth/login`);
119
+ console.log(` GET http://localhost:${port}/api/auth/pending`);
120
+ console.log(` POST http://localhost:${port}/api/auth/approve`);
121
+ console.log(` GET http://localhost:${port}/api/tenants`);
122
+ console.log(` GET http://localhost:${port}/api/users`);
package/src/index.ts CHANGED
@@ -14,6 +14,8 @@ import {
14
14
  toolLatticeManager,
15
15
  registerStoreLattice,
16
16
  sandboxLatticeManager,
17
+ sqlDatabaseManager,
18
+ metricsServerManager,
17
19
  } from "@axiom-lattice/core";
18
20
  import { McpServerConfig } from "@axiom-lattice/protocols";
19
21
  import "./agents";
@@ -24,7 +26,7 @@ import {
24
26
  LoggerType,
25
27
  ScheduleType,
26
28
  } from "@axiom-lattice/protocols";
27
- import { PostgreSQLAssistantStore, PostgreSQLScheduleStorage, PostgreSQLThreadStore } from "@axiom-lattice/pg-stores";
29
+ import { PostgreSQLAssistantStore, PostgreSQLScheduleStorage, PostgreSQLThreadStore, PostgreSQLDatabaseConfigStore, PostgreSQLMetricsServerConfigStore, PostgreSQLWorkspaceStore, PostgreSQLProjectStore, PostgreSQLUserStore, PostgreSQLTenantStore, PostgreSQLUserTenantLinkStore } from "@axiom-lattice/pg-stores";
28
30
 
29
31
  // 在文件开头添加
30
32
  const fs = require("fs");
@@ -55,6 +57,94 @@ const threadStore = new PostgreSQLThreadStore({
55
57
  storeLatticeManager.removeLattice("default", "thread");
56
58
  registerStoreLattice("default", "thread", threadStore);
57
59
 
60
+ // Initialize and register PostgreSQL DatabaseConfigStore
61
+ // This stores database connection configurations with encryption
62
+ const databaseConfigStore = new PostgreSQLDatabaseConfigStore({
63
+ poolConfig: process.env.DATABASE_URL || "",
64
+ autoMigrate: true,
65
+ });
66
+
67
+ // Register databaseConfigStore to replace the default in-memory store
68
+ storeLatticeManager.removeLattice("default", "database");
69
+ registerStoreLattice("default", "database", databaseConfigStore);
70
+ sqlDatabaseManager.loadAllConfigsFromStore(databaseConfigStore)
71
+ console.log("PostgreSQL DatabaseConfigStore initialized with auto-migration");
72
+
73
+ // Initialize and register PostgreSQL MetricsServerConfigStore
74
+ // This stores metrics server configurations with apiKey and password encryption
75
+ const metricsConfigStore = new PostgreSQLMetricsServerConfigStore({
76
+ poolConfig: process.env.DATABASE_URL || "",
77
+ autoMigrate: true,
78
+ });
79
+
80
+ // Register metricsConfigStore to replace the default in-memory store
81
+ storeLatticeManager.removeLattice("default", "metrics");
82
+ registerStoreLattice("default", "metrics", metricsConfigStore);
83
+ metricsServerManager.loadAllConfigsFromStore(metricsConfigStore)
84
+ console.log("PostgreSQL MetricsServerConfigStore initialized with auto-migration");
85
+
86
+ // Initialize and register PostgreSQL WorkspaceStore
87
+ const workspaceStore = new PostgreSQLWorkspaceStore({
88
+ poolConfig: process.env.DATABASE_URL || "",
89
+ autoMigrate: true,
90
+ });
91
+
92
+ // Register workspaceStore to replace the default in-memory store
93
+ storeLatticeManager.removeLattice("default", "workspace");
94
+ registerStoreLattice("default", "workspace", workspaceStore);
95
+ console.log("PostgreSQL WorkspaceStore initialized with auto-migration");
96
+
97
+ // Initialize and register PostgreSQL ProjectStore
98
+ const projectStore = new PostgreSQLProjectStore({
99
+ poolConfig: process.env.DATABASE_URL || "",
100
+ autoMigrate: true,
101
+ });
102
+
103
+ // Register projectStore to replace the default in-memory store
104
+ storeLatticeManager.removeLattice("default", "project");
105
+ registerStoreLattice("default", "project", projectStore);
106
+ console.log("PostgreSQL ProjectStore initialized with auto-migration");
107
+
108
+ // Initialize and register PostgreSQL UserStore (for authentication)
109
+ const userStore = new PostgreSQLUserStore({
110
+ poolConfig: process.env.DATABASE_URL || "",
111
+ autoMigrate: true,
112
+ });
113
+ storeLatticeManager.removeLattice("default", "user");
114
+ registerStoreLattice("default", "user", userStore);
115
+ console.log("PostgreSQL UserStore initialized with auto-migration");
116
+
117
+ // Initialize and register PostgreSQL TenantStore (for multi-tenancy)
118
+ const tenantStore = new PostgreSQLTenantStore({
119
+ poolConfig: process.env.DATABASE_URL || "",
120
+ autoMigrate: true,
121
+ });
122
+ storeLatticeManager.removeLattice("default", "tenant");
123
+ registerStoreLattice("default", "tenant", tenantStore);
124
+ console.log("PostgreSQL TenantStore initialized with auto-migration");
125
+
126
+ // Initialize and register PostgreSQL UserTenantLinkStore (for user-tenant relationships)
127
+ const userTenantLinkStore = new PostgreSQLUserTenantLinkStore({
128
+ poolConfig: process.env.DATABASE_URL || "",
129
+ autoMigrate: true,
130
+ });
131
+ storeLatticeManager.removeLattice("default", "userTenantLink");
132
+ registerStoreLattice("default", "userTenantLink", userTenantLinkStore);
133
+ console.log("PostgreSQL UserTenantLinkStore initialized with auto-migration");
134
+
135
+ // Auth configuration
136
+ const AUTH_CONFIG = {
137
+ autoApproveUsers: process.env.AUTO_APPROVE_USERS !== "false",
138
+ allowTenantRegistration: process.env.ALLOW_TENANT_REGISTRATION !== "false",
139
+ jwtSecret: process.env.JWT_SECRET || "your-secret-key-change-in-production",
140
+ tokenExpiration: parseInt(process.env.TOKEN_EXPIRATION || "86400", 10),
141
+ };
142
+
143
+ console.log("Auth Configuration:");
144
+ console.log(` - Auto Approve Users: ${AUTH_CONFIG.autoApproveUsers}`);
145
+ console.log(` - Allow Tenant Registration: ${AUTH_CONFIG.allowTenantRegistration}`);
146
+ console.log(` - Token Expiration: ${AUTH_CONFIG.tokenExpiration}s`);
147
+
58
148
  // Parse command line arguments for port configuration
59
149
  function parsePort(): number {
60
150
  const args = process.argv.slice(2);
@@ -246,8 +336,8 @@ skillLatticeManager.configureStore("default");
246
336
 
247
337
  //Register Sandbox Manager Lattice
248
338
  sandboxLatticeManager.registerLattice("default", {
249
- baseURL: "http://100.64.0.2:9080" //"https://demo.alphafina.cn"
250
-
339
+ // baseURL: "http://100.64.0.2:9080"
340
+ baseURL: "https://demo.alphafina.cn"
251
341
  })
252
342
 
253
343
  // Register MCP servers