添加注释以说明工具和会话的上下文处理

This commit is contained in:
2026-04-29 11:58:13 +08:00
parent d3e7baca99
commit b857ca543d
11 changed files with 15 additions and 0 deletions
+3
View File
@@ -12,6 +12,7 @@ const app = express();
const registry = new SessionRegistry(config.SESSION_TTL_SECONDS);
const sessionBridge = new ChatSessionBridge(registry, opencodeRuntime);
const internalToken = config.AGENT_INTERNAL_TOKEN ?? randomUUID();
// 这个 token 只用于 .opencode/tools 回调本服务,避免把 internal endpoint 暴露成无鉴权入口。
process.env.TJWATER_AGENT_INTERNAL_TOKEN = internalToken;
app.use(cors());
app.use(express.json({ limit: "1mb" }));
@@ -49,6 +50,7 @@ app.post("/internal/tools/dynamic-http-call", async (req, res) => {
return;
}
try {
// opencode 工具运行在 .opencode 侧,这里负责把工具调用重新绑定到当前用户/项目上下文。
const result = await dynamicHttpExecutor.execute({
path: req.body?.path,
method: req.body?.method,
@@ -71,6 +73,7 @@ const server = app.listen(config.PORT, config.HOST, () => {
const shutdown = async () => {
logger.info("shutting down TJWaterAgent");
server.close();
// 同步关闭 embedded opencode server,避免本服务退出后留下孤儿进程。
await opencodeRuntime.dispose();
};
process.on("SIGINT", () => {