@njuptlzf/agent-chat-server 0.1.1 → 0.2.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/dist/audit.d.ts +54 -0
- package/dist/audit.js +133 -0
- package/dist/authz.d.ts +134 -0
- package/dist/authz.js +238 -0
- package/dist/events.d.ts +33 -0
- package/dist/events.js +169 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +4 -0
- package/dist/main.d.ts +1 -0
- package/dist/main.js +126 -0
- package/dist/manifest.d.ts +147 -0
- package/dist/manifest.js +491 -0
- package/dist/mcp-config.d.ts +87 -0
- package/dist/mcp-config.js +353 -0
- package/dist/model-config.d.ts +123 -0
- package/dist/model-config.js +371 -0
- package/dist/model-failover.d.ts +42 -0
- package/dist/model-failover.js +82 -0
- package/dist/models-api.d.ts +98 -0
- package/dist/models-api.js +326 -0
- package/dist/persona-config.d.ts +112 -0
- package/dist/persona-config.js +368 -0
- package/dist/persona-trial.d.ts +50 -0
- package/dist/persona-trial.js +77 -0
- package/dist/product-routes.d.ts +35 -0
- package/dist/product-routes.js +92 -0
- package/dist/server.d.ts +162 -0
- package/dist/server.js +2572 -0
- package/dist/session.d.ts +218 -0
- package/dist/session.js +545 -0
- package/dist/sqlite-stores.d.ts +173 -0
- package/dist/sqlite-stores.js +921 -0
- package/dist/stores.d.ts +506 -0
- package/dist/stores.js +614 -0
- package/dist/testing.d.ts +42 -0
- package/dist/testing.js +47 -0
- package/dist/trial-grant.d.ts +40 -0
- package/dist/trial-grant.js +24 -0
- package/dist/usage-report.d.ts +23 -0
- package/dist/usage-report.js +68 -0
- package/dist/util.d.ts +3 -0
- package/dist/util.js +5 -0
- package/package.json +64 -58
- package/scripts/agentchat-integrate.mjs +607 -601
- package/src/audit.ts +169 -169
- package/src/authz.ts +307 -307
- package/src/events.ts +206 -206
- package/src/index.ts +26 -26
- package/src/main.ts +142 -142
- package/src/manifest.ts +562 -562
- package/src/mcp-config.ts +385 -385
- package/src/model-config.ts +424 -424
- package/src/model-failover.ts +95 -95
- package/src/models-api.ts +360 -360
- package/src/persona-config.ts +436 -436
- package/src/persona-trial.ts +121 -121
- package/src/product-routes.ts +102 -102
- package/src/server.ts +2647 -2647
- package/src/session.ts +688 -688
- package/src/sqlite-stores.ts +1040 -1040
- package/src/stores.ts +899 -899
- package/src/testing.ts +80 -80
- package/src/trial-grant.ts +62 -62
- package/src/usage-report.ts +86 -86
- package/src/util.ts +6 -6
package/src/main.ts
CHANGED
|
@@ -1,142 +1,142 @@
|
|
|
1
|
-
import { mkdirSync } from "node:fs";
|
|
2
|
-
import path from "node:path";
|
|
3
|
-
import { Authz, UnavailableAuthz } from "./authz.ts";
|
|
4
|
-
import { loadProduct, loadToolFactory } from "./manifest.ts";
|
|
5
|
-
import { createModelConfigStore } from "./model-config.ts";
|
|
6
|
-
import { createMcpConfigStore } from "./mcp-config.ts";
|
|
7
|
-
import { createPersonaConfigStore } from "./persona-config.ts";
|
|
8
|
-
import { initProductRoutes, loadProductAssembly, loadProductRoutes } from "./product-routes.ts";
|
|
9
|
-
import { createChatServer } from "./server.ts";
|
|
10
|
-
import { createModelRuntime } from "./session.ts";
|
|
11
|
-
import { createAdminAuth, createJwtAuth, insecureHeaderAuth } from "./stores.ts";
|
|
12
|
-
import { openDatabase, SqliteAccountState, SqliteAudit, SqliteBilling, SqliteHistoryStore, SqliteMembership, SqliteMemberPool, SqliteQuotaGate, SqliteRunLog } from "./sqlite-stores.ts";
|
|
13
|
-
import { billingUsage } from "./usage-report.ts";
|
|
14
|
-
|
|
15
|
-
const productDir = process.env.PRODUCT_DIR;
|
|
16
|
-
if (!productDir) {
|
|
17
|
-
console.error("Set PRODUCT_DIR to a product directory, e.g. PRODUCT_DIR=<product-dir>");
|
|
18
|
-
process.exit(1);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
const product = loadProduct(productDir);
|
|
22
|
-
const dataDir = path.resolve(process.env.DATA_DIR ?? ".data", product.manifest.id);
|
|
23
|
-
mkdirSync(dataDir, { recursive: true });
|
|
24
|
-
|
|
25
|
-
const modelRuntime = await createModelRuntime(dataDir, product.manifest.agent.model.provider);
|
|
26
|
-
// 运营配置(provider 白名单、档位候选序列)落在 data 目录的 model-config.json,
|
|
27
|
-
// 不进 git、不重启生效;缺文件或坏 JSON 一律回落 manifest(设计稿 /)。
|
|
28
|
-
const modelConfig = createModelConfigStore(dataDir, product);
|
|
29
|
-
const initialModelConfig = modelConfig.get();
|
|
30
|
-
console.log(
|
|
31
|
-
`[agent-chat] model config: ${initialModelConfig.source === "file" ? modelConfig.path : "manifest 兜底(无 model-config.json)"} · maxCandidates ${initialModelConfig.maxCandidates}`,
|
|
32
|
-
);
|
|
33
|
-
// 业务接入配置同款(mcp-config.json 为准、manifest `mcp:` 段是种子,设计稿)。
|
|
34
|
-
const mcpConfig = createMcpConfigStore(dataDir, product);
|
|
35
|
-
const initialMcpConfig = mcpConfig.get();
|
|
36
|
-
console.log(
|
|
37
|
-
`[agent-chat] mcp config: ${initialMcpConfig.source === "file" ? mcpConfig.path : "manifest 兜底(无 mcp-config.json)"} · ${Object.keys(initialMcpConfig.servers).length} 个接入`,
|
|
38
|
-
);
|
|
39
|
-
// 人格配置(persona-config.json 为准、manifest 是种子)。改完不用重启——
|
|
40
|
-
// 每次建会话读一次,写接口 save 后 invalidate 即生效(设计稿)。
|
|
41
|
-
const personaConfig = createPersonaConfigStore(dataDir, product);
|
|
42
|
-
const initialPersonaConfig = personaConfig.get();
|
|
43
|
-
console.log(
|
|
44
|
-
`[agent-chat] persona config: ${initialPersonaConfig.source === "file" ? personaConfig.path : "manifest 兜底(无 persona-config.json)"} · ${Object.keys(initialPersonaConfig.personas).length} 个人格有覆盖`,
|
|
45
|
-
);
|
|
46
|
-
const toolFactory = await loadToolFactory(product);
|
|
47
|
-
|
|
48
|
-
// Pre-scope rows belong to the qualification this deployment used to serve.
|
|
49
|
-
const db = openDatabase(path.join(dataDir, "agent-chat.db"), product.defaultQual, product.defaultPersona);
|
|
50
|
-
// S4:产品 Store 由产品仓自己装配(manifest server.assembly 动态 import,形状不对即启动失败)。
|
|
51
|
-
const productAssembly = await loadProductAssembly(product);
|
|
52
|
-
|
|
53
|
-
const jwtSecret = process.env.AUTH_JWT_SECRET;
|
|
54
|
-
if (!jwtSecret) {
|
|
55
|
-
console.warn("[agent-chat] WARNING: AUTH_JWT_SECRET is not set; trusting the x-user-id header (development only).");
|
|
56
|
-
}
|
|
57
|
-
if (!process.env.ADMIN_TOKEN) {
|
|
58
|
-
console.warn("[agent-chat] ADMIN_TOKEN not set; GET /api/usage/report is disabled.");
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
// 权限内核:策略种子来自 manifest 的 agent.authz.seedPolicies(出核,
|
|
62
|
-
// core 不内置业务行),空表才种、幂等;enforcer 从 casbin_rule 载策略。加载失败不拦启动——
|
|
63
|
-
// 拿到 UnavailableAuthz 后业务数据 fail-closed(503)、其余闸 fail-open,运维可用 ADMIN_TOKEN 通道修库。
|
|
64
|
-
const membership = new SqliteMembership(db);
|
|
65
|
-
let authz: Authz | UnavailableAuthz;
|
|
66
|
-
try {
|
|
67
|
-
authz = await Authz.create(db, membership, undefined, product.manifest.agent.authz?.seedPolicies ?? []);
|
|
68
|
-
} catch (err) {
|
|
69
|
-
console.error("[agent-chat] casbin 授权内核加载失败(业务数据将 503,其余闸放行):", err);
|
|
70
|
-
authz = new UnavailableAuthz();
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
// 开发身份自举(「运维通道」的本地替代):AUTH_JWT_SECRET 未设 =
|
|
74
|
-
// insecureHeaderAuth,身份由 x-user-id 声明,token 里没有任何可信的「谁是管理员」。
|
|
75
|
-
// 不种这一行,本地永远没有 admin → #/admin 进不去、会员也没人发放,整个权限与
|
|
76
|
-
// 会员体系看起来像没做(实际是首任管理员只能靠 ADMIN_TOKEN 或手写 SQL)。
|
|
77
|
-
// 只在开发模式生效,id 可用 DEV_ADMIN_USERS=alice,bob 覆盖;授角色幂等。
|
|
78
|
-
if (!jwtSecret && authz.ready()) {
|
|
79
|
-
const devAdmins = (process.env.DEV_ADMIN_USERS ?? "dev-admin")
|
|
80
|
-
.split(",")
|
|
81
|
-
.map((s) => s.trim())
|
|
82
|
-
.filter((s) => /^[\w.@-]{1,64}$/.test(s));
|
|
83
|
-
for (const id of devAdmins) await authz.assignRole(id, "admin");
|
|
84
|
-
console.log(
|
|
85
|
-
`[agent-chat] dev identity: x-user-id ${devAdmins.join(" / ")} = admin(浏览器侧栏可切换;会员请在 #/admin 发放)`,
|
|
86
|
-
);
|
|
87
|
-
// 旧库补种子:casbin 种子**只在空表种**,所以给 manifest 新增一行
|
|
88
|
-
// (如 admin-api:models)不会自动出现在旧 dev 库里——模型页会 403,看起来像功能没做。
|
|
89
|
-
// 这里按 manifest 补齐缺的 p 行(只加不删;生产零影响,生产该走策略矩阵勾选或
|
|
90
|
-
// ADMIN_TOKEN 通道)。代价:dev 里手删的种子行重启会回来——开发环境要的就是这个。
|
|
91
|
-
const existing = new Set((await authz.listPolicies()).map((p) => `${p.sub}|${p.obj}|${p.act}`));
|
|
92
|
-
let backfilled = 0;
|
|
93
|
-
for (const r of product.manifest.agent.authz?.seedPolicies ?? []) {
|
|
94
|
-
if (existing.has(`${r.sub}|${r.obj}|${r.act}`)) continue;
|
|
95
|
-
await authz.addPolicy(r.sub, r.obj, r.act);
|
|
96
|
-
backfilled++;
|
|
97
|
-
}
|
|
98
|
-
if (backfilled > 0) console.log(`[agent-chat] dev policy backfill: +${backfilled} 行(旧库补 manifest 种子,仅 dev)`);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
// 产品业务路由(manifest `server.routes` 声明,core 不认识任何具体路径)。
|
|
102
|
-
// 装配逻辑抽到 core 的 product-routes.ts(形状校验 + fail-closed),
|
|
103
|
-
// 这样接缝的失败语义能被进程内测试覆盖——入口脚本里的代码没人测得到。
|
|
104
|
-
// 动态 import 放在服务监听前:文件缺失/形状不对=启动失败;init() 立即装配业务数据,
|
|
105
|
-
// 坏卷单/坏 taxonomy 仍是启动期红(fail-closed 不随搬家降级)。
|
|
106
|
-
const productRoutes = await loadProductRoutes(product);
|
|
107
|
-
|
|
108
|
-
const deps = {
|
|
109
|
-
product,
|
|
110
|
-
modelRuntime,
|
|
111
|
-
modelConfig,
|
|
112
|
-
mcpConfig,
|
|
113
|
-
personaConfig,
|
|
114
|
-
toolFactory,
|
|
115
|
-
history: new SqliteHistoryStore(db),
|
|
116
|
-
quota: new SqliteQuotaGate(db, product.manifest.agent.limits?.dailyTokenQuota),
|
|
117
|
-
authenticate: jwtSecret ? createJwtAuth(jwtSecret) : insecureHeaderAuth,
|
|
118
|
-
dataDir,
|
|
119
|
-
runLog: new SqliteRunLog(db),
|
|
120
|
-
billing: new SqliteBilling(db),
|
|
121
|
-
authz,
|
|
122
|
-
membership,
|
|
123
|
-
accountState: new SqliteAccountState(db),
|
|
124
|
-
memberPool: new SqliteMemberPool(db),
|
|
125
|
-
// 审计哈希链:主链恒装配;写点接线在 ,读端点在 。
|
|
126
|
-
audit: new SqliteAudit(db),
|
|
127
|
-
billingUsage: async (userId: string, days: number, tzOffset?: number) => billingUsage(db, userId, days, tzOffset),
|
|
128
|
-
adminAuth: process.env.ADMIN_TOKEN ? createAdminAuth(process.env.ADMIN_TOKEN) : undefined,
|
|
129
|
-
...(productAssembly ? productAssembly(db) : {}),
|
|
130
|
-
productRoutes: productRoutes?.routes,
|
|
131
|
-
productAdminRoutes: productRoutes?.admin,
|
|
132
|
-
};
|
|
133
|
-
|
|
134
|
-
// 坏卷单/坏 taxonomy ⇒ 这里就抛(启动失败),而不是首个请求 500。
|
|
135
|
-
await initProductRoutes(productRoutes, deps);
|
|
136
|
-
|
|
137
|
-
const server = createChatServer(deps);
|
|
138
|
-
|
|
139
|
-
const port = Number(process.env.PORT ?? 8787);
|
|
140
|
-
server.listen(port, () => {
|
|
141
|
-
console.log(`[agent-chat] ${product.manifest.id} listening on http://localhost:${port}`);
|
|
142
|
-
});
|
|
1
|
+
import { mkdirSync } from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { Authz, UnavailableAuthz } from "./authz.ts";
|
|
4
|
+
import { loadProduct, loadToolFactory } from "./manifest.ts";
|
|
5
|
+
import { createModelConfigStore } from "./model-config.ts";
|
|
6
|
+
import { createMcpConfigStore } from "./mcp-config.ts";
|
|
7
|
+
import { createPersonaConfigStore } from "./persona-config.ts";
|
|
8
|
+
import { initProductRoutes, loadProductAssembly, loadProductRoutes } from "./product-routes.ts";
|
|
9
|
+
import { createChatServer } from "./server.ts";
|
|
10
|
+
import { createModelRuntime } from "./session.ts";
|
|
11
|
+
import { createAdminAuth, createJwtAuth, insecureHeaderAuth } from "./stores.ts";
|
|
12
|
+
import { openDatabase, SqliteAccountState, SqliteAudit, SqliteBilling, SqliteHistoryStore, SqliteMembership, SqliteMemberPool, SqliteQuotaGate, SqliteRunLog } from "./sqlite-stores.ts";
|
|
13
|
+
import { billingUsage } from "./usage-report.ts";
|
|
14
|
+
|
|
15
|
+
const productDir = process.env.PRODUCT_DIR;
|
|
16
|
+
if (!productDir) {
|
|
17
|
+
console.error("Set PRODUCT_DIR to a product directory, e.g. PRODUCT_DIR=<product-dir>");
|
|
18
|
+
process.exit(1);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const product = loadProduct(productDir);
|
|
22
|
+
const dataDir = path.resolve(process.env.DATA_DIR ?? ".data", product.manifest.id);
|
|
23
|
+
mkdirSync(dataDir, { recursive: true });
|
|
24
|
+
|
|
25
|
+
const modelRuntime = await createModelRuntime(dataDir, product.manifest.agent.model.provider);
|
|
26
|
+
// 运营配置(provider 白名单、档位候选序列)落在 data 目录的 model-config.json,
|
|
27
|
+
// 不进 git、不重启生效;缺文件或坏 JSON 一律回落 manifest(设计稿 /)。
|
|
28
|
+
const modelConfig = createModelConfigStore(dataDir, product);
|
|
29
|
+
const initialModelConfig = modelConfig.get();
|
|
30
|
+
console.log(
|
|
31
|
+
`[agent-chat] model config: ${initialModelConfig.source === "file" ? modelConfig.path : "manifest 兜底(无 model-config.json)"} · maxCandidates ${initialModelConfig.maxCandidates}`,
|
|
32
|
+
);
|
|
33
|
+
// 业务接入配置同款(mcp-config.json 为准、manifest `mcp:` 段是种子,设计稿)。
|
|
34
|
+
const mcpConfig = createMcpConfigStore(dataDir, product);
|
|
35
|
+
const initialMcpConfig = mcpConfig.get();
|
|
36
|
+
console.log(
|
|
37
|
+
`[agent-chat] mcp config: ${initialMcpConfig.source === "file" ? mcpConfig.path : "manifest 兜底(无 mcp-config.json)"} · ${Object.keys(initialMcpConfig.servers).length} 个接入`,
|
|
38
|
+
);
|
|
39
|
+
// 人格配置(persona-config.json 为准、manifest 是种子)。改完不用重启——
|
|
40
|
+
// 每次建会话读一次,写接口 save 后 invalidate 即生效(设计稿)。
|
|
41
|
+
const personaConfig = createPersonaConfigStore(dataDir, product);
|
|
42
|
+
const initialPersonaConfig = personaConfig.get();
|
|
43
|
+
console.log(
|
|
44
|
+
`[agent-chat] persona config: ${initialPersonaConfig.source === "file" ? personaConfig.path : "manifest 兜底(无 persona-config.json)"} · ${Object.keys(initialPersonaConfig.personas).length} 个人格有覆盖`,
|
|
45
|
+
);
|
|
46
|
+
const toolFactory = await loadToolFactory(product);
|
|
47
|
+
|
|
48
|
+
// Pre-scope rows belong to the qualification this deployment used to serve.
|
|
49
|
+
const db = openDatabase(path.join(dataDir, "agent-chat.db"), product.defaultQual, product.defaultPersona);
|
|
50
|
+
// S4:产品 Store 由产品仓自己装配(manifest server.assembly 动态 import,形状不对即启动失败)。
|
|
51
|
+
const productAssembly = await loadProductAssembly(product);
|
|
52
|
+
|
|
53
|
+
const jwtSecret = process.env.AUTH_JWT_SECRET;
|
|
54
|
+
if (!jwtSecret) {
|
|
55
|
+
console.warn("[agent-chat] WARNING: AUTH_JWT_SECRET is not set; trusting the x-user-id header (development only).");
|
|
56
|
+
}
|
|
57
|
+
if (!process.env.ADMIN_TOKEN) {
|
|
58
|
+
console.warn("[agent-chat] ADMIN_TOKEN not set; GET /api/usage/report is disabled.");
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// 权限内核:策略种子来自 manifest 的 agent.authz.seedPolicies(出核,
|
|
62
|
+
// core 不内置业务行),空表才种、幂等;enforcer 从 casbin_rule 载策略。加载失败不拦启动——
|
|
63
|
+
// 拿到 UnavailableAuthz 后业务数据 fail-closed(503)、其余闸 fail-open,运维可用 ADMIN_TOKEN 通道修库。
|
|
64
|
+
const membership = new SqliteMembership(db);
|
|
65
|
+
let authz: Authz | UnavailableAuthz;
|
|
66
|
+
try {
|
|
67
|
+
authz = await Authz.create(db, membership, undefined, product.manifest.agent.authz?.seedPolicies ?? []);
|
|
68
|
+
} catch (err) {
|
|
69
|
+
console.error("[agent-chat] casbin 授权内核加载失败(业务数据将 503,其余闸放行):", err);
|
|
70
|
+
authz = new UnavailableAuthz();
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// 开发身份自举(「运维通道」的本地替代):AUTH_JWT_SECRET 未设 =
|
|
74
|
+
// insecureHeaderAuth,身份由 x-user-id 声明,token 里没有任何可信的「谁是管理员」。
|
|
75
|
+
// 不种这一行,本地永远没有 admin → #/admin 进不去、会员也没人发放,整个权限与
|
|
76
|
+
// 会员体系看起来像没做(实际是首任管理员只能靠 ADMIN_TOKEN 或手写 SQL)。
|
|
77
|
+
// 只在开发模式生效,id 可用 DEV_ADMIN_USERS=alice,bob 覆盖;授角色幂等。
|
|
78
|
+
if (!jwtSecret && authz.ready()) {
|
|
79
|
+
const devAdmins = (process.env.DEV_ADMIN_USERS ?? "dev-admin")
|
|
80
|
+
.split(",")
|
|
81
|
+
.map((s) => s.trim())
|
|
82
|
+
.filter((s) => /^[\w.@-]{1,64}$/.test(s));
|
|
83
|
+
for (const id of devAdmins) await authz.assignRole(id, "admin");
|
|
84
|
+
console.log(
|
|
85
|
+
`[agent-chat] dev identity: x-user-id ${devAdmins.join(" / ")} = admin(浏览器侧栏可切换;会员请在 #/admin 发放)`,
|
|
86
|
+
);
|
|
87
|
+
// 旧库补种子:casbin 种子**只在空表种**,所以给 manifest 新增一行
|
|
88
|
+
// (如 admin-api:models)不会自动出现在旧 dev 库里——模型页会 403,看起来像功能没做。
|
|
89
|
+
// 这里按 manifest 补齐缺的 p 行(只加不删;生产零影响,生产该走策略矩阵勾选或
|
|
90
|
+
// ADMIN_TOKEN 通道)。代价:dev 里手删的种子行重启会回来——开发环境要的就是这个。
|
|
91
|
+
const existing = new Set((await authz.listPolicies()).map((p) => `${p.sub}|${p.obj}|${p.act}`));
|
|
92
|
+
let backfilled = 0;
|
|
93
|
+
for (const r of product.manifest.agent.authz?.seedPolicies ?? []) {
|
|
94
|
+
if (existing.has(`${r.sub}|${r.obj}|${r.act}`)) continue;
|
|
95
|
+
await authz.addPolicy(r.sub, r.obj, r.act);
|
|
96
|
+
backfilled++;
|
|
97
|
+
}
|
|
98
|
+
if (backfilled > 0) console.log(`[agent-chat] dev policy backfill: +${backfilled} 行(旧库补 manifest 种子,仅 dev)`);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// 产品业务路由(manifest `server.routes` 声明,core 不认识任何具体路径)。
|
|
102
|
+
// 装配逻辑抽到 core 的 product-routes.ts(形状校验 + fail-closed),
|
|
103
|
+
// 这样接缝的失败语义能被进程内测试覆盖——入口脚本里的代码没人测得到。
|
|
104
|
+
// 动态 import 放在服务监听前:文件缺失/形状不对=启动失败;init() 立即装配业务数据,
|
|
105
|
+
// 坏卷单/坏 taxonomy 仍是启动期红(fail-closed 不随搬家降级)。
|
|
106
|
+
const productRoutes = await loadProductRoutes(product);
|
|
107
|
+
|
|
108
|
+
const deps = {
|
|
109
|
+
product,
|
|
110
|
+
modelRuntime,
|
|
111
|
+
modelConfig,
|
|
112
|
+
mcpConfig,
|
|
113
|
+
personaConfig,
|
|
114
|
+
toolFactory,
|
|
115
|
+
history: new SqliteHistoryStore(db),
|
|
116
|
+
quota: new SqliteQuotaGate(db, product.manifest.agent.limits?.dailyTokenQuota),
|
|
117
|
+
authenticate: jwtSecret ? createJwtAuth(jwtSecret) : insecureHeaderAuth,
|
|
118
|
+
dataDir,
|
|
119
|
+
runLog: new SqliteRunLog(db),
|
|
120
|
+
billing: new SqliteBilling(db),
|
|
121
|
+
authz,
|
|
122
|
+
membership,
|
|
123
|
+
accountState: new SqliteAccountState(db),
|
|
124
|
+
memberPool: new SqliteMemberPool(db),
|
|
125
|
+
// 审计哈希链:主链恒装配;写点接线在 ,读端点在 。
|
|
126
|
+
audit: new SqliteAudit(db),
|
|
127
|
+
billingUsage: async (userId: string, days: number, tzOffset?: number) => billingUsage(db, userId, days, tzOffset),
|
|
128
|
+
adminAuth: process.env.ADMIN_TOKEN ? createAdminAuth(process.env.ADMIN_TOKEN) : undefined,
|
|
129
|
+
...(productAssembly ? productAssembly(db) : {}),
|
|
130
|
+
productRoutes: productRoutes?.routes,
|
|
131
|
+
productAdminRoutes: productRoutes?.admin,
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
// 坏卷单/坏 taxonomy ⇒ 这里就抛(启动失败),而不是首个请求 500。
|
|
135
|
+
await initProductRoutes(productRoutes, deps);
|
|
136
|
+
|
|
137
|
+
const server = createChatServer(deps);
|
|
138
|
+
|
|
139
|
+
const port = Number(process.env.PORT ?? 8787);
|
|
140
|
+
server.listen(port, () => {
|
|
141
|
+
console.log(`[agent-chat] ${product.manifest.id} listening on http://localhost:${port}`);
|
|
142
|
+
});
|