team-anya-cli 0.1.8 → 1.0.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 +1 -37
- package/package.json +6 -37
- package/anya/prompts/execution-guides/git-delivery.md +0 -38
- package/anya/prompts/execution-guides/testing-and-self-heal.md +0 -28
- package/anya/prompts/protocols/brief-assembly.md +0 -55
- package/anya/prompts/protocols/report.md +0 -175
- package/anya/prompts/protocols/review.md +0 -90
- package/anya/prompts/task-claude-md.template.md +0 -32
- package/apps/server/dist/broker/cc-broker.js +0 -261
- package/apps/server/dist/cli.js +0 -296
- package/apps/server/dist/config.js +0 -76
- package/apps/server/dist/daemon.js +0 -51
- package/apps/server/dist/franky/context-builder.js +0 -160
- package/apps/server/dist/franky/franky-mcp-server.js +0 -107
- package/apps/server/dist/franky/franky-orchestrator.js +0 -450
- package/apps/server/dist/franky/index.js +0 -5
- package/apps/server/dist/franky/topic-router.js +0 -16
- package/apps/server/dist/gateway/chat-sync.js +0 -135
- package/apps/server/dist/gateway/command-router.js +0 -114
- package/apps/server/dist/gateway/commands/cancel.js +0 -32
- package/apps/server/dist/gateway/commands/help.js +0 -16
- package/apps/server/dist/gateway/commands/index.js +0 -26
- package/apps/server/dist/gateway/commands/restart.js +0 -34
- package/apps/server/dist/gateway/commands/status.js +0 -34
- package/apps/server/dist/gateway/commands/tasks.js +0 -33
- package/apps/server/dist/gateway/feishu-sender.js +0 -410
- package/apps/server/dist/gateway/feishu-ws.js +0 -256
- package/apps/server/dist/gateway/http.js +0 -1019
- package/apps/server/dist/gateway/media-downloader.js +0 -149
- package/apps/server/dist/gateway/message-events.js +0 -10
- package/apps/server/dist/gateway/message-intake.js +0 -67
- package/apps/server/dist/gateway/message-queue.js +0 -118
- package/apps/server/dist/gateway/session-reader.js +0 -142
- package/apps/server/dist/gateway/ws-push.js +0 -115
- package/apps/server/dist/loid/brain.js +0 -105
- package/apps/server/dist/loid/clarifier.js +0 -162
- package/apps/server/dist/loid/context-builder.js +0 -413
- package/apps/server/dist/loid/mcp-server.js +0 -106
- package/apps/server/dist/loid/memory-settler.js +0 -189
- package/apps/server/dist/loid/opportunity-manager.js +0 -148
- package/apps/server/dist/loid/profile-updater.js +0 -179
- package/apps/server/dist/loid/reporter.js +0 -148
- package/apps/server/dist/loid/schemas.js +0 -117
- package/apps/server/dist/loid/self-calibrator.js +0 -314
- package/apps/server/dist/loid/session-manager.js +0 -301
- package/apps/server/dist/loid/session.js +0 -271
- package/apps/server/dist/loid/worktree-manager.js +0 -191
- package/apps/server/dist/main.js +0 -393
- package/apps/server/dist/tracing/index.js +0 -2
- package/apps/server/dist/tracing/trace-context.js +0 -92
- package/apps/server/dist/types/message.js +0 -2
- package/apps/server/dist/yor/yor-mcp-server.js +0 -104
- package/apps/server/dist/yor/yor-orchestrator.js +0 -233
- package/apps/web/dist/assets/index-BiiEB0qZ.css +0 -1
- package/apps/web/dist/assets/index-D1AK5ZEE.js +0 -798
- package/apps/web/dist/index.html +0 -13
- package/packages/cc-client/dist/claude-code-backend.js +0 -664
- package/packages/cc-client/dist/index.js +0 -2
- package/packages/cc-client/package.json +0 -11
- package/packages/core/dist/constants.js +0 -59
- package/packages/core/dist/errors.js +0 -35
- package/packages/core/dist/index.js +0 -7
- package/packages/core/dist/office-init.js +0 -101
- package/packages/core/dist/scope/checker.js +0 -114
- package/packages/core/dist/scope/defaults.js +0 -55
- package/packages/core/dist/scope/index.js +0 -3
- package/packages/core/dist/state-machine.js +0 -85
- package/packages/core/dist/types/audit.js +0 -12
- package/packages/core/dist/types/backend.js +0 -2
- package/packages/core/dist/types/commitment.js +0 -17
- package/packages/core/dist/types/communication.js +0 -18
- package/packages/core/dist/types/index.js +0 -8
- package/packages/core/dist/types/opportunity.js +0 -27
- package/packages/core/dist/types/org.js +0 -26
- package/packages/core/dist/types/task.js +0 -46
- package/packages/core/package.json +0 -10
- package/packages/db/dist/client.js +0 -69
- package/packages/db/dist/index.js +0 -691
- package/packages/db/dist/schema/audit-events.js +0 -13
- package/packages/db/dist/schema/cc-sessions.js +0 -14
- package/packages/db/dist/schema/chats.js +0 -33
- package/packages/db/dist/schema/commitments.js +0 -18
- package/packages/db/dist/schema/communication-events.js +0 -14
- package/packages/db/dist/schema/index.js +0 -13
- package/packages/db/dist/schema/message-log.js +0 -20
- package/packages/db/dist/schema/opportunities.js +0 -23
- package/packages/db/dist/schema/org.js +0 -36
- package/packages/db/dist/schema/projects.js +0 -23
- package/packages/db/dist/schema/tasks.js +0 -48
- package/packages/db/dist/schema/topics.js +0 -20
- package/packages/db/dist/schema/trace-spans.js +0 -19
- package/packages/db/package.json +0 -12
- package/packages/db/src/migrations/0000_baseline.sql +0 -251
- package/packages/db/src/migrations/meta/_journal.json +0 -13
- package/packages/mcp-tools/dist/index.js +0 -41
- package/packages/mcp-tools/dist/layer1/audit-append.js +0 -38
- package/packages/mcp-tools/dist/layer1/audit-query.js +0 -51
- package/packages/mcp-tools/dist/layer1/memory-brief.js +0 -168
- package/packages/mcp-tools/dist/layer1/memory-context.js +0 -124
- package/packages/mcp-tools/dist/layer1/memory-digest.js +0 -126
- package/packages/mcp-tools/dist/layer1/memory-forget.js +0 -108
- package/packages/mcp-tools/dist/layer1/memory-learn.js +0 -63
- package/packages/mcp-tools/dist/layer1/memory-recall.js +0 -287
- package/packages/mcp-tools/dist/layer1/memory-reflect.js +0 -80
- package/packages/mcp-tools/dist/layer1/memory-remember.js +0 -119
- package/packages/mcp-tools/dist/layer1/memory-search.js +0 -263
- package/packages/mcp-tools/dist/layer1/memory-write.js +0 -21
- package/packages/mcp-tools/dist/layer1/org-lookup.js +0 -47
- package/packages/mcp-tools/dist/layer1/project-get.js +0 -28
- package/packages/mcp-tools/dist/layer1/project-list.js +0 -20
- package/packages/mcp-tools/dist/layer1/report-daily.js +0 -68
- package/packages/mcp-tools/dist/layer1/task-get.js +0 -29
- package/packages/mcp-tools/dist/layer1/task-update.js +0 -34
- package/packages/mcp-tools/dist/layer2/franky/topic-checkpoint.js +0 -43
- package/packages/mcp-tools/dist/layer2/franky/topic-escalate.js +0 -19
- package/packages/mcp-tools/dist/layer2/loid/decision-log.js +0 -15
- package/packages/mcp-tools/dist/layer2/loid/decision-no-action.js +0 -15
- package/packages/mcp-tools/dist/layer2/loid/delivery-create-pr.js +0 -30
- package/packages/mcp-tools/dist/layer2/loid/delivery-share.js +0 -12
- package/packages/mcp-tools/dist/layer2/loid/delivery-submit.js +0 -77
- package/packages/mcp-tools/dist/layer2/loid/delivery-upload.js +0 -18
- package/packages/mcp-tools/dist/layer2/loid/project-remove.js +0 -16
- package/packages/mcp-tools/dist/layer2/loid/project-upsert.js +0 -33
- package/packages/mcp-tools/dist/layer2/loid/task-dispatch.js +0 -196
- package/packages/mcp-tools/dist/layer2/loid/task-lookup.js +0 -38
- package/packages/mcp-tools/dist/layer2/loid/topic-close.js +0 -22
- package/packages/mcp-tools/dist/layer2/loid/topic-create.js +0 -56
- package/packages/mcp-tools/dist/layer2/loid/yor-approve.js +0 -8
- package/packages/mcp-tools/dist/layer2/loid/yor-kill.js +0 -7
- package/packages/mcp-tools/dist/layer2/loid/yor-rework.js +0 -7
- package/packages/mcp-tools/dist/layer2/loid/yor-spawn.js +0 -15
- package/packages/mcp-tools/dist/layer2/loid/yor-status.js +0 -8
- package/packages/mcp-tools/dist/layer2/yor/task-block.js +0 -11
- package/packages/mcp-tools/dist/layer2/yor/task-deliver.js +0 -35
- package/packages/mcp-tools/dist/layer2/yor/task-progress.js +0 -21
- package/packages/mcp-tools/dist/layer3/adapters/feishu-adapter.js +0 -192
- package/packages/mcp-tools/dist/layer3/adapters/types.js +0 -28
- package/packages/mcp-tools/dist/layer3/channel-receive.js +0 -11
- package/packages/mcp-tools/dist/layer3/channel-send.js +0 -91
- package/packages/mcp-tools/dist/layer3/file-upload.js +0 -44
- package/packages/mcp-tools/dist/registry.js +0 -871
- package/packages/mcp-tools/package.json +0 -13
- package/workspace/.claude/settings.local.json +0 -9
- package/workspace/.mcp.json +0 -12
- package/workspace/CHARTER.md +0 -76
- package/workspace/CLAUDE.md +0 -58
- package/workspace/PROTOCOL.md +0 -160
- package/workspace/TOOLS.md +0 -470
- package/workspace/audit/.gitkeep +0 -0
- package/workspace/franky/CLAUDE.md +0 -37
- package/workspace/franky/PLAYBOOK.md +0 -215
- package/workspace/franky/PROFILE.md +0 -80
- package/workspace/loid/CLAUDE.md +0 -12
- package/workspace/loid/PLAYBOOK.md +0 -198
- package/workspace/loid/PROFILE.md +0 -78
- package/workspace/memory/commitments/.gitkeep +0 -0
- package/workspace/memory/execution/.gitkeep +0 -0
- package/workspace/memory/people/.gitkeep +0 -0
- package/workspace/memory/projects/.gitkeep +0 -0
- package/workspace/memory/self/.gitkeep +0 -0
- package/workspace/reference/identity/.gitkeep +0 -0
- package/workspace/reference/org/escalation.yaml +0 -24
- package/workspace/reference/org/ownership.yaml +0 -28
- package/workspace/reports/.gitkeep +0 -0
- package/workspace/yor/CLAUDE.md +0 -22
- package/workspace/yor/PLAYBOOK.md +0 -73
- package/workspace/yor/PROFILE.md +0 -52
- package/workspace/yor/SELF-HEAL.md +0 -39
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
import { readFile, readdir, writeFile } from 'node:fs/promises';
|
|
2
|
-
import { join } from 'node:path';
|
|
3
|
-
import { existsSync } from 'node:fs';
|
|
4
|
-
import { execSync } from 'node:child_process';
|
|
5
|
-
import { getTopic, getRecentMessages } from '@team-anya/db';
|
|
6
|
-
/**
|
|
7
|
-
* 为 Franky CC 实例重建上下文
|
|
8
|
-
* 按 checkpoint 截断策略:所有 checkpoint 标题 + 最近 2 个详情 + 末个 checkpoint 后对话
|
|
9
|
-
*/
|
|
10
|
-
export async function buildTopicContext(deps, topicId) {
|
|
11
|
-
const topic = getTopic(deps.db, topicId);
|
|
12
|
-
if (!topic)
|
|
13
|
-
throw new Error(`专项 ${topicId} 不存在`);
|
|
14
|
-
const topicDir = join(deps.workspacePath, 'franky', 'topics', topicId);
|
|
15
|
-
const sections = [];
|
|
16
|
-
// 1. Topic 元信息
|
|
17
|
-
sections.push(`# 专项上下文:${topic.title} (${topic.id})`);
|
|
18
|
-
sections.push('');
|
|
19
|
-
sections.push('## 目标');
|
|
20
|
-
sections.push(topic.description ?? '(未设定)');
|
|
21
|
-
sections.push('');
|
|
22
|
-
sections.push('## 通讯信息');
|
|
23
|
-
if (topic.chat_id)
|
|
24
|
-
sections.push(`- 群聊 ID:\`${topic.chat_id}\``);
|
|
25
|
-
if (topic.root_message_id)
|
|
26
|
-
sections.push(`- 话题根消息 ID:\`${topic.root_message_id}\``);
|
|
27
|
-
if (topic.thread_id)
|
|
28
|
-
sections.push(`- 话题 ID:\`${topic.thread_id}\`(仅供参考,channel.send 的 reply_to 请用根消息 ID)`);
|
|
29
|
-
sections.push('');
|
|
30
|
-
sections.push('## 项目信息');
|
|
31
|
-
sections.push(`- 专项 ID:${topic.id}`);
|
|
32
|
-
sections.push(`- 状态:${topic.status}`);
|
|
33
|
-
if (topic.project_id)
|
|
34
|
-
sections.push(`- 关联项目:${topic.project_id}`);
|
|
35
|
-
if (topic.branch_name)
|
|
36
|
-
sections.push(`- 分支:${topic.branch_name}`);
|
|
37
|
-
sections.push('');
|
|
38
|
-
// 1.5 代码工作区(worktree 信息)
|
|
39
|
-
if (topic.project_id && topic.workspace_path) {
|
|
40
|
-
try {
|
|
41
|
-
const entries = await readdir(topic.workspace_path, { withFileTypes: true });
|
|
42
|
-
const worktreeDirs = entries
|
|
43
|
-
.filter(e => e.isDirectory() && !e.name.startsWith('.') && e.name !== 'checkpoints')
|
|
44
|
-
.map(e => e.name);
|
|
45
|
-
if (worktreeDirs.length > 0) {
|
|
46
|
-
sections.push('## 代码工作区');
|
|
47
|
-
sections.push('');
|
|
48
|
-
for (const dir of worktreeDirs) {
|
|
49
|
-
const fullPath = join(topic.workspace_path, dir);
|
|
50
|
-
const branchInfo = topic.branch_name ? `分支 \`${topic.branch_name}\`,` : '';
|
|
51
|
-
sections.push(`- \`${dir}/\` → ${branchInfo}路径 \`${fullPath}\``);
|
|
52
|
-
}
|
|
53
|
-
sections.push('');
|
|
54
|
-
sections.push('> 代码在上述 worktree 子目录中,git 操作请进入对应子目录执行。');
|
|
55
|
-
sections.push('');
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
catch {
|
|
59
|
-
// workspace 不可读,跳过
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
// 2. Checkpoints
|
|
63
|
-
const checkpointsDir = join(topicDir, 'checkpoints');
|
|
64
|
-
let checkpointFiles = [];
|
|
65
|
-
if (existsSync(checkpointsDir)) {
|
|
66
|
-
const files = await readdir(checkpointsDir);
|
|
67
|
-
checkpointFiles = files.filter(f => f.match(/^\d{3}-.*\.md$/)).sort();
|
|
68
|
-
}
|
|
69
|
-
if (checkpointFiles.length > 0) {
|
|
70
|
-
sections.push('## Checkpoint 概览');
|
|
71
|
-
for (const file of checkpointFiles) {
|
|
72
|
-
const num = file.split('-')[0];
|
|
73
|
-
const name = file.replace(/^\d{3}-/, '').replace(/\.md$/, '');
|
|
74
|
-
sections.push(`${parseInt(num, 10)}. ${name}`);
|
|
75
|
-
}
|
|
76
|
-
sections.push('');
|
|
77
|
-
// 最近 2 个 checkpoint 的完整内容
|
|
78
|
-
const recentCheckpoints = checkpointFiles.slice(-2);
|
|
79
|
-
sections.push('## 最近 Checkpoint 详情');
|
|
80
|
-
sections.push('');
|
|
81
|
-
for (const file of recentCheckpoints) {
|
|
82
|
-
try {
|
|
83
|
-
const content = await readFile(join(checkpointsDir, file), 'utf-8');
|
|
84
|
-
sections.push(content.trim());
|
|
85
|
-
sections.push('');
|
|
86
|
-
}
|
|
87
|
-
catch {
|
|
88
|
-
// 文件读取失败,跳过
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
// 3. Git log(如果有 worktree)
|
|
93
|
-
const gitDir = join(topicDir);
|
|
94
|
-
try {
|
|
95
|
-
const gitLog = execSync('git log --oneline -10 2>/dev/null || true', {
|
|
96
|
-
cwd: gitDir,
|
|
97
|
-
encoding: 'utf-8',
|
|
98
|
-
timeout: 5000,
|
|
99
|
-
}).trim();
|
|
100
|
-
if (gitLog) {
|
|
101
|
-
sections.push('## 近期 Git 记录');
|
|
102
|
-
sections.push('```');
|
|
103
|
-
sections.push(gitLog);
|
|
104
|
-
sections.push('```');
|
|
105
|
-
sections.push('');
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
catch {
|
|
109
|
-
// 不是 git 仓库或命令失败,跳过
|
|
110
|
-
}
|
|
111
|
-
// 4. 最后一个 checkpoint 之后的对话(用 thread_id 所在的 chat_id + since 过滤)
|
|
112
|
-
if (topic.chat_id) {
|
|
113
|
-
try {
|
|
114
|
-
// 查找最后一个 checkpoint 的时间戳,只拉取其后的消息
|
|
115
|
-
let since;
|
|
116
|
-
if (checkpointFiles.length > 0) {
|
|
117
|
-
try {
|
|
118
|
-
const lastCheckpointPath = join(checkpointsDir, checkpointFiles[checkpointFiles.length - 1]);
|
|
119
|
-
const stat = await import('node:fs/promises').then(m => m.stat(lastCheckpointPath));
|
|
120
|
-
since = stat.mtime.toISOString().replace(/\.\d{3}Z$/, 'Z');
|
|
121
|
-
}
|
|
122
|
-
catch {
|
|
123
|
-
// stat 失败,不设 since 过滤
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
const messages = getRecentMessages(deps.db, {
|
|
127
|
-
chat_id: topic.chat_id,
|
|
128
|
-
limit: 30,
|
|
129
|
-
sort: 'asc',
|
|
130
|
-
...(since ? { since } : {}),
|
|
131
|
-
});
|
|
132
|
-
if (messages.length > 0) {
|
|
133
|
-
sections.push('## 近期对话');
|
|
134
|
-
sections.push('');
|
|
135
|
-
for (const msg of messages) {
|
|
136
|
-
const direction = msg.direction === 'outbound' ? 'Anya' : (msg.sender_name ?? msg.sender ?? '用户');
|
|
137
|
-
sections.push(`**${direction}** (${msg.created_at}):`);
|
|
138
|
-
// 截断过长的消息
|
|
139
|
-
const content = msg.content.length > 500 ? msg.content.slice(0, 500) + '...' : msg.content;
|
|
140
|
-
sections.push(content);
|
|
141
|
-
sections.push('');
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
catch (err) {
|
|
146
|
-
deps.logger?.error('[TopicContextBuilder] 查询对话历史失败:', err);
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
return sections.join('\n');
|
|
150
|
-
}
|
|
151
|
-
/**
|
|
152
|
-
* 生成并写入 context.md 文件
|
|
153
|
-
*/
|
|
154
|
-
export async function writeTopicContext(deps, topicId) {
|
|
155
|
-
const content = await buildTopicContext(deps, topicId);
|
|
156
|
-
const contextPath = join(deps.workspacePath, 'franky', 'topics', topicId, 'context.md');
|
|
157
|
-
await writeFile(contextPath, content, 'utf-8');
|
|
158
|
-
return contextPath;
|
|
159
|
-
}
|
|
160
|
-
//# sourceMappingURL=context-builder.js.map
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
import { createServer } from 'node:http';
|
|
2
|
-
import { randomUUID } from 'node:crypto';
|
|
3
|
-
import { Server } from '@modelcontextprotocol/sdk/server';
|
|
4
|
-
import { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/streamableHttp.js';
|
|
5
|
-
import { ListToolsRequestSchema, CallToolRequestSchema } from '@modelcontextprotocol/sdk/types.js';
|
|
6
|
-
import { zodToJsonSchema } from 'zod-to-json-schema';
|
|
7
|
-
import { createToolRouter } from '@team-anya/mcp-tools';
|
|
8
|
-
// ── MCP Server 创建(薄路由层) ──
|
|
9
|
-
function createFrankyMcpServer(deps) {
|
|
10
|
-
const logger = deps.logger ?? { info: console.log, error: console.error };
|
|
11
|
-
const routerDeps = {
|
|
12
|
-
db: deps.db,
|
|
13
|
-
workspacePath: deps.workspacePath,
|
|
14
|
-
currentTopicId: deps.topicId,
|
|
15
|
-
replyToThreadId: deps.replyToThreadId,
|
|
16
|
-
channelRegistry: deps.channelRegistry,
|
|
17
|
-
onMessageSent: deps.onMessageSent,
|
|
18
|
-
onTopicClosed: deps.onTopicClosed,
|
|
19
|
-
onTopicEscalated: deps.onTopicEscalated,
|
|
20
|
-
logger,
|
|
21
|
-
};
|
|
22
|
-
const router = createToolRouter('franky', routerDeps);
|
|
23
|
-
const server = new Server({ name: 'franky-mcp', version: '1.0.0' }, { capabilities: { tools: {} } });
|
|
24
|
-
server.setRequestHandler(ListToolsRequestSchema, async () => {
|
|
25
|
-
const tools = router.tools.map(def => ({
|
|
26
|
-
name: def.name,
|
|
27
|
-
description: def.description,
|
|
28
|
-
inputSchema: zodToJsonSchema(def.inputSchema),
|
|
29
|
-
}));
|
|
30
|
-
return { tools };
|
|
31
|
-
});
|
|
32
|
-
server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
33
|
-
const { name, arguments: args } = request.params;
|
|
34
|
-
return router.handleToolCall(name, args ?? {});
|
|
35
|
-
});
|
|
36
|
-
return server;
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* 启动 Franky MCP server(薄路由层)
|
|
40
|
-
*
|
|
41
|
-
* Franky 可以使用 Layer 1 全部共享工具 + Layer 3 Franky 专属工具(channel.send 等)。
|
|
42
|
-
* 不需要 Yor 的 deliver/block 工具。
|
|
43
|
-
*
|
|
44
|
-
* 所有工具实现来自 @team-anya/mcp-tools。
|
|
45
|
-
*/
|
|
46
|
-
export async function startFrankyMcpServer(deps) {
|
|
47
|
-
const sessions = new Map();
|
|
48
|
-
const httpServer = createServer(async (req, res) => {
|
|
49
|
-
const url = new URL(req.url ?? '/', `http://${req.headers.host ?? 'localhost'}`);
|
|
50
|
-
if (url.pathname !== '/mcp') {
|
|
51
|
-
res.writeHead(404);
|
|
52
|
-
res.end('Not Found');
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
55
|
-
const sessionId = req.headers['mcp-session-id'];
|
|
56
|
-
if (sessionId && sessions.has(sessionId)) {
|
|
57
|
-
const { transport } = sessions.get(sessionId);
|
|
58
|
-
await transport.handleRequest(req, res);
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
|
-
if (req.method === 'POST') {
|
|
62
|
-
const transport = new StreamableHTTPServerTransport({
|
|
63
|
-
sessionIdGenerator: () => randomUUID(),
|
|
64
|
-
});
|
|
65
|
-
const server = createFrankyMcpServer(deps);
|
|
66
|
-
transport.onclose = () => {
|
|
67
|
-
if (transport.sessionId) {
|
|
68
|
-
sessions.delete(transport.sessionId);
|
|
69
|
-
}
|
|
70
|
-
};
|
|
71
|
-
await server.connect(transport);
|
|
72
|
-
await transport.handleRequest(req, res);
|
|
73
|
-
if (transport.sessionId) {
|
|
74
|
-
sessions.set(transport.sessionId, { server, transport });
|
|
75
|
-
}
|
|
76
|
-
return;
|
|
77
|
-
}
|
|
78
|
-
res.writeHead(400);
|
|
79
|
-
res.end('Bad Request: No valid session');
|
|
80
|
-
});
|
|
81
|
-
await new Promise((resolve) => {
|
|
82
|
-
httpServer.listen(0, '127.0.0.1', resolve);
|
|
83
|
-
});
|
|
84
|
-
const addr = httpServer.address();
|
|
85
|
-
const port = typeof addr === 'object' && addr !== null ? addr.port : 0;
|
|
86
|
-
const serverUrl = `http://127.0.0.1:${port}/mcp`;
|
|
87
|
-
return {
|
|
88
|
-
port,
|
|
89
|
-
url: serverUrl,
|
|
90
|
-
close: async () => {
|
|
91
|
-
for (const { server, transport } of sessions.values()) {
|
|
92
|
-
await transport.close();
|
|
93
|
-
await server.close();
|
|
94
|
-
}
|
|
95
|
-
sessions.clear();
|
|
96
|
-
await new Promise((resolve, reject) => {
|
|
97
|
-
httpServer.close((err) => {
|
|
98
|
-
if (err)
|
|
99
|
-
reject(err);
|
|
100
|
-
else
|
|
101
|
-
resolve();
|
|
102
|
-
});
|
|
103
|
-
});
|
|
104
|
-
},
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
//# sourceMappingURL=franky-mcp-server.js.map
|