@ai-zen/agents-host 0.0.0-stage → 0.1.0-alpha.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/CHANGELOG.md +39 -0
- package/LICENSE +21 -0
- package/README.md +759 -2
- package/dist/app.d.ts +384 -0
- package/dist/app.js +1148 -0
- package/dist/cli.d.ts +22 -0
- package/dist/cli.js +354 -0
- package/dist/config.d.ts +97 -0
- package/dist/config.js +171 -0
- package/dist/handlers/agentHandlers.d.ts +18 -0
- package/dist/handlers/agentHandlers.js +20 -0
- package/dist/handlers/assetHandlers.d.ts +29 -0
- package/dist/handlers/assetHandlers.js +35 -0
- package/dist/handlers/capabilities.d.ts +26 -0
- package/dist/handlers/capabilities.js +138 -0
- package/dist/handlers/completionHandlers.d.ts +18 -0
- package/dist/handlers/completionHandlers.js +13 -0
- package/dist/handlers/configHandlers.d.ts +31 -0
- package/dist/handlers/configHandlers.js +59 -0
- package/dist/handlers/conversationHandlers.d.ts +118 -0
- package/dist/handlers/conversationHandlers.js +314 -0
- package/dist/handlers/handoffHandlers.d.ts +17 -0
- package/dist/handlers/handoffHandlers.js +14 -0
- package/dist/handlers/hostHandlers.d.ts +39 -0
- package/dist/handlers/hostHandlers.js +56 -0
- package/dist/handlers/index.d.ts +128 -0
- package/dist/handlers/index.js +92 -0
- package/dist/handlers/messageHandlers.d.ts +11 -0
- package/dist/handlers/messageHandlers.js +10 -0
- package/dist/handlers/modelHandlers.d.ts +17 -0
- package/dist/handlers/modelHandlers.js +19 -0
- package/dist/handlers/noticeHandlers.d.ts +24 -0
- package/dist/handlers/noticeHandlers.js +24 -0
- package/dist/handlers/questionHandlers.d.ts +16 -0
- package/dist/handlers/questionHandlers.js +16 -0
- package/dist/handlers/searchHandlers.d.ts +12 -0
- package/dist/handlers/searchHandlers.js +12 -0
- package/dist/handlers/workspaceHandlers.d.ts +29 -0
- package/dist/handlers/workspaceHandlers.js +47 -0
- package/dist/i18n/en.d.ts +243 -0
- package/dist/i18n/en.js +270 -0
- package/dist/i18n/index.d.ts +43 -0
- package/dist/i18n/index.js +72 -0
- package/dist/i18n/zh.d.ts +240 -0
- package/dist/i18n/zh.js +257 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.js +15 -0
- package/dist/net/UploadReceiver.d.ts +186 -0
- package/dist/net/UploadReceiver.js +494 -0
- package/dist/net/WsHub.d.ts +231 -0
- package/dist/net/WsHub.js +689 -0
- package/dist/net/auth.d.ts +73 -0
- package/dist/net/auth.js +74 -0
- package/dist/net/discovery.d.ts +72 -0
- package/dist/net/discovery.js +171 -0
- package/dist/net/index.d.ts +14 -0
- package/dist/net/index.js +10 -0
- package/dist/runtime/ChatRunner.d.ts +374 -0
- package/dist/runtime/ChatRunner.js +1204 -0
- package/dist/runtime/ConversationDrafts.d.ts +43 -0
- package/dist/runtime/ConversationDrafts.js +47 -0
- package/dist/runtime/RunRegistry.d.ts +79 -0
- package/dist/runtime/RunRegistry.js +108 -0
- package/dist/runtime/ScopeRegistry.d.ts +153 -0
- package/dist/runtime/ScopeRegistry.js +259 -0
- package/dist/runtime/TransientRunner.d.ts +90 -0
- package/dist/runtime/TransientRunner.js +179 -0
- package/dist/runtime/index.d.ts +14 -0
- package/dist/runtime/index.js +10 -0
- package/dist/services/AgentService.d.ts +150 -0
- package/dist/services/AgentService.js +718 -0
- package/dist/services/AssetService.d.ts +338 -0
- package/dist/services/AssetService.js +739 -0
- package/dist/services/AutoNaming.d.ts +92 -0
- package/dist/services/AutoNaming.js +235 -0
- package/dist/services/CompletionService.d.ts +122 -0
- package/dist/services/CompletionService.js +442 -0
- package/dist/services/ConfigService.d.ts +171 -0
- package/dist/services/ConfigService.js +695 -0
- package/dist/services/ConversationService.d.ts +274 -0
- package/dist/services/ConversationService.js +902 -0
- package/dist/services/CredentialService.d.ts +33 -0
- package/dist/services/CredentialService.js +86 -0
- package/dist/services/DiscoveryService.d.ts +182 -0
- package/dist/services/DiscoveryService.js +998 -0
- package/dist/services/HandoffService.d.ts +189 -0
- package/dist/services/HandoffService.js +414 -0
- package/dist/services/Logger.d.ts +130 -0
- package/dist/services/Logger.js +256 -0
- package/dist/services/MessageService.d.ts +88 -0
- package/dist/services/MessageService.js +280 -0
- package/dist/services/ModelService.d.ts +89 -0
- package/dist/services/ModelService.js +489 -0
- package/dist/services/NoticeService.d.ts +93 -0
- package/dist/services/NoticeService.js +217 -0
- package/dist/services/QuestionService.d.ts +184 -0
- package/dist/services/QuestionService.js +457 -0
- package/dist/services/SearchService.d.ts +54 -0
- package/dist/services/SearchService.js +117 -0
- package/dist/services/WorkspaceService.d.ts +96 -0
- package/dist/services/WorkspaceService.js +213 -0
- package/dist/services/imageSize.d.ts +41 -0
- package/dist/services/imageSize.js +146 -0
- package/dist/services/index.d.ts +20 -0
- package/dist/services/index.js +15 -0
- package/dist/services/secretMask.d.ts +24 -0
- package/dist/services/secretMask.js +34 -0
- package/dist/storage/AssetRepository.d.ts +87 -0
- package/dist/storage/AssetRepository.js +180 -0
- package/dist/storage/ConversationRepository.d.ts +55 -0
- package/dist/storage/ConversationRepository.js +128 -0
- package/dist/storage/CredentialRepository.d.ts +28 -0
- package/dist/storage/CredentialRepository.js +47 -0
- package/dist/storage/Database.d.ts +95 -0
- package/dist/storage/Database.js +180 -0
- package/dist/storage/MessageRepository.d.ts +104 -0
- package/dist/storage/MessageRepository.js +323 -0
- package/dist/storage/MetaRepository.d.ts +21 -0
- package/dist/storage/MetaRepository.js +33 -0
- package/dist/storage/NoticeRepository.d.ts +31 -0
- package/dist/storage/NoticeRepository.js +89 -0
- package/dist/storage/QuestionRepository.d.ts +34 -0
- package/dist/storage/QuestionRepository.js +96 -0
- package/dist/storage/WorkspaceRepository.d.ts +25 -0
- package/dist/storage/WorkspaceRepository.js +44 -0
- package/dist/storage/dbWorker.d.ts +10 -0
- package/dist/storage/dbWorker.js +132 -0
- package/dist/storage/index.d.ts +20 -0
- package/dist/storage/index.js +16 -0
- package/dist/storage/migrations.d.ts +26 -0
- package/dist/storage/migrations.js +207 -0
- package/dist/storage/types.d.ts +298 -0
- package/dist/storage/types.js +14 -0
- package/dist/wire/errors.d.ts +105 -0
- package/dist/wire/errors.js +143 -0
- package/dist/wire/events.d.ts +102 -0
- package/dist/wire/events.js +13 -0
- package/dist/wire/frames.d.ts +106 -0
- package/dist/wire/frames.js +156 -0
- package/dist/wire/index.d.ts +31 -0
- package/dist/wire/index.js +31 -0
- package/dist/wire/methods.d.ts +1896 -0
- package/dist/wire/methods.js +99 -0
- package/dist/wire/states.d.ts +487 -0
- package/dist/wire/states.js +61 -0
- package/package.json +63 -3
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 凭证服务:多串访问凭证的列出、新建、吊销。
|
|
3
|
+
*
|
|
4
|
+
* 对应能力编号:L11(凭证靠复制 + 手动输入、可以有多串、创建时带备注、权限相同、可单独吊销)、
|
|
5
|
+
* F-E4(直达入口里的一项)。不做账号与按人分权限(L12)—— 凭证代表的是「一台设备」。
|
|
6
|
+
*
|
|
7
|
+
* 明文的去处只有一处:`create` 的返回值。库里存的是 `hashCredential` 算出的摘要,服务层
|
|
8
|
+
* 拿不到明文也就无法再吐出来第二次(吊销用 id,不用明文)。
|
|
9
|
+
*/
|
|
10
|
+
import type { CredentialRepository } from "../storage/CredentialRepository.js";
|
|
11
|
+
import type { CredentialCreateParams, CredentialCreateResult, CredentialListResult, CredentialRevokeParams, CredentialRevokeResult } from "../wire/index.js";
|
|
12
|
+
/** 凭证服务依赖 */
|
|
13
|
+
export interface CredentialServiceDeps {
|
|
14
|
+
credentials: CredentialRepository;
|
|
15
|
+
/** 时钟,测试注入用;缺省 `Date.now` */
|
|
16
|
+
now?: () => number;
|
|
17
|
+
}
|
|
18
|
+
export declare class CredentialService {
|
|
19
|
+
private readonly credentials;
|
|
20
|
+
private readonly now;
|
|
21
|
+
constructor(deps: CredentialServiceDeps);
|
|
22
|
+
/** 列出全部凭证(含已吊销的,吊销状态在 `revokedAt` 上) */
|
|
23
|
+
list(): Promise<CredentialListResult>;
|
|
24
|
+
/** 新建一串:备注自己写,明文只在这个返回值里出现一次 */
|
|
25
|
+
create(params: CredentialCreateParams): Promise<CredentialCreateResult>;
|
|
26
|
+
/**
|
|
27
|
+
* 吊销一串(置 `revokedAt`,不删行:留着能看出这串曾经存在过)。
|
|
28
|
+
*
|
|
29
|
+
* `revoked` 表示这次调用是否真的改动了库:对一串已经吊销过的凭证再吊销一次,返回 false
|
|
30
|
+
* 而不是报错(端状态一样是「已吊销」)。
|
|
31
|
+
*/
|
|
32
|
+
revoke(params: CredentialRevokeParams): Promise<CredentialRevokeResult>;
|
|
33
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 凭证服务:多串访问凭证的列出、新建、吊销。
|
|
3
|
+
*
|
|
4
|
+
* 对应能力编号:L11(凭证靠复制 + 手动输入、可以有多串、创建时带备注、权限相同、可单独吊销)、
|
|
5
|
+
* F-E4(直达入口里的一项)。不做账号与按人分权限(L12)—— 凭证代表的是「一台设备」。
|
|
6
|
+
*
|
|
7
|
+
* 明文的去处只有一处:`create` 的返回值。库里存的是 `hashCredential` 算出的摘要,服务层
|
|
8
|
+
* 拿不到明文也就无法再吐出来第二次(吊销用 id,不用明文)。
|
|
9
|
+
*/
|
|
10
|
+
import { randomBytes, randomUUID } from "node:crypto";
|
|
11
|
+
import { hashCredential } from "../storage/CredentialRepository.js";
|
|
12
|
+
import { HostError } from "../wire/errors.js";
|
|
13
|
+
/** 明文凭证的字节数(base64url 编码后 43 个字符) */
|
|
14
|
+
const TOKEN_BYTES = 32;
|
|
15
|
+
/** 时间戳转 wire 上的 ISO 8601 */
|
|
16
|
+
function iso(ms) {
|
|
17
|
+
return new Date(ms).toISOString();
|
|
18
|
+
}
|
|
19
|
+
/** 库里的一行 → 对外视图(不含摘要) */
|
|
20
|
+
function toView(row) {
|
|
21
|
+
return {
|
|
22
|
+
id: row.id,
|
|
23
|
+
note: row.note,
|
|
24
|
+
createdAt: iso(row.createdAt),
|
|
25
|
+
revokedAt: row.revokedAt === null ? null : iso(row.revokedAt),
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
export class CredentialService {
|
|
29
|
+
credentials;
|
|
30
|
+
now;
|
|
31
|
+
constructor(deps) {
|
|
32
|
+
this.credentials = deps.credentials;
|
|
33
|
+
this.now = deps.now ?? Date.now;
|
|
34
|
+
}
|
|
35
|
+
/** 列出全部凭证(含已吊销的,吊销状态在 `revokedAt` 上) */
|
|
36
|
+
async list() {
|
|
37
|
+
const rows = await this.credentials.list();
|
|
38
|
+
return { credentials: rows.map((row) => toView(row)) };
|
|
39
|
+
}
|
|
40
|
+
/** 新建一串:备注自己写,明文只在这个返回值里出现一次 */
|
|
41
|
+
async create(params) {
|
|
42
|
+
const note = typeof params.note === "string" ? params.note.trim() : "";
|
|
43
|
+
const token = randomBytes(TOKEN_BYTES).toString("base64url");
|
|
44
|
+
const id = randomUUID();
|
|
45
|
+
const createdAt = this.now();
|
|
46
|
+
await this.credentials.create({
|
|
47
|
+
id,
|
|
48
|
+
note,
|
|
49
|
+
hash: hashCredential(token),
|
|
50
|
+
createdAt,
|
|
51
|
+
});
|
|
52
|
+
const row = await this.credentials.get(id);
|
|
53
|
+
if (!row) {
|
|
54
|
+
throw new HostError("internal", { detail: { reason: "credential vanished after insert", id } });
|
|
55
|
+
}
|
|
56
|
+
return {
|
|
57
|
+
credential: {
|
|
58
|
+
id: row.id,
|
|
59
|
+
note: row.note,
|
|
60
|
+
createdAt: iso(row.createdAt),
|
|
61
|
+
revokedAt: row.revokedAt === null ? null : iso(row.revokedAt),
|
|
62
|
+
},
|
|
63
|
+
token,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* 吊销一串(置 `revokedAt`,不删行:留着能看出这串曾经存在过)。
|
|
68
|
+
*
|
|
69
|
+
* `revoked` 表示这次调用是否真的改动了库:对一串已经吊销过的凭证再吊销一次,返回 false
|
|
70
|
+
* 而不是报错(端状态一样是「已吊销」)。
|
|
71
|
+
*/
|
|
72
|
+
async revoke(params) {
|
|
73
|
+
const id = typeof params.credentialId === "string" ? params.credentialId.trim() : "";
|
|
74
|
+
const row = id.length === 0 ? undefined : await this.credentials.get(id);
|
|
75
|
+
if (!row) {
|
|
76
|
+
throw new HostError("not_found", {
|
|
77
|
+
params: { entity: "credential" },
|
|
78
|
+
detail: { credentialId: params.credentialId },
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
if (row.revokedAt !== null)
|
|
82
|
+
return { revoked: false };
|
|
83
|
+
const changes = await this.credentials.revoke(row.id, this.now());
|
|
84
|
+
return { revoked: changes > 0 };
|
|
85
|
+
}
|
|
86
|
+
}
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 能力发现服务:把「这个项目现在能用哪些 MCP / Skill / 工具 / 子 Agent」摊成分层清单。
|
|
3
|
+
*
|
|
4
|
+
* 对应能力编号:F-G1(MCP 5 层链,可编辑的只有 2 个作用域)、F-G2(Skill 4 层、工具与子 Agent
|
|
5
|
+
* 各 2 层,只发现真实存在的目录,离项目越近越优先)、F-F6(坏文件要能看见、能修)、
|
|
6
|
+
* L9(MCP 的 5 层链)、R54(5 层链与各能力目录由本服务算好交给 ScopeRegistry)。
|
|
7
|
+
*
|
|
8
|
+
* 三件事分开:
|
|
9
|
+
*
|
|
10
|
+
* 1. **路径**({@link DiscoveryService.scopeAbilityPaths} 等):只有「按 cwd 推出各能力应该去
|
|
11
|
+
* 哪些目录 / 文件找」这一件事,与有没有东西在里面无关。组装层(ScopeRegistry 的
|
|
12
|
+
* `createWorkspaceScopeFactory`)拿的就是这些路径。
|
|
13
|
+
* 2. **读**({@link DiscoveryService.discover}):把每一层的 `missing | ok | broken` 与条目
|
|
14
|
+
* 报出来。`missing` 与 `broken` 必须分开(F-F6):以前两者都当空配置,一保存就把用户的
|
|
15
|
+
* 文件覆盖掉了。
|
|
16
|
+
* 3. **写**({@link DiscoveryService.writeMcpEntry} / {@link DiscoveryService.deleteMcpEntry}):
|
|
17
|
+
* 只写 MCP 的两个可编辑作用域,一次只动一条;写回时保留这一版不认识的字段与 `oauth`
|
|
18
|
+
* (F-F6),其中 `oauth.clientSecret` 省略就按磁盘原文保留(F-F2:读出去的是掩码,
|
|
19
|
+
* 回写掩码就是把掩码当密钥存下来)。
|
|
20
|
+
*
|
|
21
|
+
* 判断「近的优先」用的是层序 `depth`(0 最靠近项目):合并时同 id 取 depth 小的那一层,
|
|
22
|
+
* 被盖住的条目仍然出现在它自己那一层里,只是带上一条「被谁覆盖」的问题说明。
|
|
23
|
+
*/
|
|
24
|
+
import type { ConfigManager, McpServerConfig } from "@ai-zen/agents-sdk";
|
|
25
|
+
import type { ConfigGetDiscoveryParams, ConfigGetDiscoveryResult, DiscoveryLayerView, McpEditableScope, McpServerEntryInput } from "../wire/index.js";
|
|
26
|
+
/** 一层发现来源:层序、绝对路径、能不能写、属于谁 */
|
|
27
|
+
export interface DiscoveryLayerPath {
|
|
28
|
+
/** 层序:0 最靠近项目,数字越大越远(合并时近的优先) */
|
|
29
|
+
depth: number;
|
|
30
|
+
/** 这一层对应的文件或目录的绝对路径 */
|
|
31
|
+
path: string;
|
|
32
|
+
/** 本契约的写方法能不能改这一层(F-G1:MCP 只有 2 层可以) */
|
|
33
|
+
editable: boolean;
|
|
34
|
+
/** 写入时用哪个作用域;不能写时为 `null` */
|
|
35
|
+
scope: McpEditableScope | null;
|
|
36
|
+
/** 这一层归谁:项目、用户数据根、还是别的工具约定的目录 */
|
|
37
|
+
owner: "workspace" | "user" | "other";
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* 组装一个 Scope 需要的全部能力路径(R54)。
|
|
41
|
+
*
|
|
42
|
+
* `ScopeRegistry` 的 `createWorkspaceScopeFactory` 就是按这份形状装配
|
|
43
|
+
* `new Scope({ agentsDir, ... })` 与 `allInOne({ skillsPaths, toolsPaths, subAgentsPaths, mcpPaths })`。
|
|
44
|
+
*/
|
|
45
|
+
export interface ScopeAbilityPaths {
|
|
46
|
+
/** 助手定义目录(SDK 的 `createAgent` 从这里读 `<id>.json`) */
|
|
47
|
+
agentsDir: string;
|
|
48
|
+
/** Skill 目录,近的在前 */
|
|
49
|
+
skillsPaths: string[];
|
|
50
|
+
/** 用户工具目录,近的在前 */
|
|
51
|
+
toolsPaths: string[];
|
|
52
|
+
/** 子 Agent 目录,近的在前 */
|
|
53
|
+
subAgentsPaths: string[];
|
|
54
|
+
/** MCP 配置文件的 5 层链,近的在前(SDK 的 `discoverMcpServers` 按这个顺序先到先得) */
|
|
55
|
+
mcpPaths: string[];
|
|
56
|
+
}
|
|
57
|
+
/** 按 workspaceId 取工作目录;项目不存在时回 `undefined` */
|
|
58
|
+
export type WorkspaceCwdLookup = (workspaceId: string) => Promise<{
|
|
59
|
+
cwd: string;
|
|
60
|
+
} | undefined> | {
|
|
61
|
+
cwd: string;
|
|
62
|
+
} | undefined;
|
|
63
|
+
/** 发现服务的依赖;由单根组装后注入 */
|
|
64
|
+
export interface DiscoveryServiceOptions {
|
|
65
|
+
/** 配置唯一入口(SDK):数据根、`agents/`、`mcp.json` 都从它的 `basePath` 推出 */
|
|
66
|
+
configManager: ConfigManager;
|
|
67
|
+
/** 按 workspaceId 取 cwd;不给时带 `workspaceId` 的调用按「项目不存在」处理 */
|
|
68
|
+
findWorkspace?: WorkspaceCwdLookup;
|
|
69
|
+
/** 用户主目录(`~/.agents/` 那一层),缺省 `os.homedir()`;测试注入临时目录 */
|
|
70
|
+
homeDir?: string;
|
|
71
|
+
}
|
|
72
|
+
export declare class DiscoveryService {
|
|
73
|
+
private readonly configManager;
|
|
74
|
+
private readonly findWorkspace?;
|
|
75
|
+
private readonly homeDir;
|
|
76
|
+
constructor(options: DiscoveryServiceOptions);
|
|
77
|
+
/** 数据根(SDK 的 `basePath`:`config.json` 所在目录) */
|
|
78
|
+
get basePath(): string;
|
|
79
|
+
/** 助手定义目录(`<basePath>/agents/`,一实体一文件,F-G3) */
|
|
80
|
+
get agentsDir(): string;
|
|
81
|
+
/**
|
|
82
|
+
* MCP 的 5 层链(L9):`<ws>/.mcp.json` → `<ws>/.ai-zen/mcp.json` → `<ws>/.agents/mcp.json`
|
|
83
|
+
* → `<aiZenDir>/mcp.json` → `~/.agents/mcp.json`。
|
|
84
|
+
*
|
|
85
|
+
* `cwd` 为 `null`(还没打开项目)时只给后两层:项目侧那三层的路径得先有项目才算得出来。
|
|
86
|
+
*/
|
|
87
|
+
mcpLayers(cwd: string | null): DiscoveryLayerPath[];
|
|
88
|
+
/** Skill 的 4 层目录:`<ws>/.ai-zen/skills` → `<ws>/.agents/skills` → `<aiZenDir>/skills` → `~/.agents/skills` */
|
|
89
|
+
skillLayers(cwd: string | null): DiscoveryLayerPath[];
|
|
90
|
+
/** 用户工具的 2 层目录:`<ws>/.agents/tools` → `<aiZenDir>/tools` */
|
|
91
|
+
toolLayers(cwd: string | null): DiscoveryLayerPath[];
|
|
92
|
+
/** 子 Agent 的 2 层目录:`<ws>/.agents/sub-agents` → `<aiZenDir>/sub-agents` */
|
|
93
|
+
subAgentLayers(cwd: string | null): DiscoveryLayerPath[];
|
|
94
|
+
/**
|
|
95
|
+
* 组装一个 Scope 要的全部路径(R54)。
|
|
96
|
+
*
|
|
97
|
+
* `agentsDir` 只有一处(数据根下的 `agents/`):助手定义是全局配置,与项目无关。
|
|
98
|
+
* 其余四个按「近的在前」排好,直接喂给 SDK 的 `allInOne`。
|
|
99
|
+
*/
|
|
100
|
+
scopeAbilityPaths(cwd: string): ScopeAbilityPaths;
|
|
101
|
+
/** 只取 MCP 的 5 层路径(喂给 SDK 的 `discoverMcpServers` / `McpScopePlugin`) */
|
|
102
|
+
mcpPaths(cwd: string): string[];
|
|
103
|
+
/** 按作用域找那一层的路径(写入时用) */
|
|
104
|
+
mcpLayer(scope: McpEditableScope, cwd: string | null): DiscoveryLayerPath;
|
|
105
|
+
/**
|
|
106
|
+
* `config.getDiscovery`(F-G1 / F-G2 / F-F6)。
|
|
107
|
+
*
|
|
108
|
+
* 给了 `workspaceId` 就带上项目侧的三层(与项目无关的两层也照常给);没给就只报「用户级」
|
|
109
|
+
* 与「别的工具约定的」那几层 —— 客户端在没打开项目时也能看 MCP 屏。
|
|
110
|
+
*/
|
|
111
|
+
discover(params?: ConfigGetDiscoveryParams): Promise<ConfigGetDiscoveryResult>;
|
|
112
|
+
/** 只读一层(`config.saveMcp` / `config.deleteMcp` 写回之后回报那一层时也用它) */
|
|
113
|
+
readMcpLayerView(layer: DiscoveryLayerPath): Promise<DiscoveryLayerView>;
|
|
114
|
+
/**
|
|
115
|
+
* 5 层 MCP 链的合并结果(SDK 的 `discoverMcpServers`,先到先得)。
|
|
116
|
+
*
|
|
117
|
+
* 这个方法是「client 侧看到的分层清单」与「Scope 实际连的那些 server」之间的对照点:
|
|
118
|
+
* 两者应当一致,不一致就说明某一层的文件坏了或者被近的层盖住了。
|
|
119
|
+
*/
|
|
120
|
+
effectiveMcpServers(cwd: string): Promise<McpServerConfig[]>;
|
|
121
|
+
/**
|
|
122
|
+
* 存一条 MCP 条目(F-G1 / F-F6):`entry.id` 在这一层里就改那一条,没有就建。
|
|
123
|
+
*
|
|
124
|
+
* 写回的口径(与 `deleteMcpEntry` 共用同一份合并规则):
|
|
125
|
+
* - 这个 id 的磁盘原文是底,覆盖入参里明确给了的字段,`extra` 最后叠上去 ——
|
|
126
|
+
* 于是这一版不认识的键与没被提到的 `oauth` 都原样留着(F-F6);
|
|
127
|
+
* - `oauth.clientSecret` 跟端点密钥同一套:省略 / 等于当前掩码 → 保留原文,空串才清掉
|
|
128
|
+
* (见 `mergeOauth`);
|
|
129
|
+
* - 层里别的条目一个字节都不动:改一条不会把另一条读不全的字段覆盖掉;
|
|
130
|
+
* - 文件里 `mcpServers` 之外的顶层键也原样带上。
|
|
131
|
+
*/
|
|
132
|
+
writeMcpEntry(scope: McpEditableScope, entry: McpServerEntryInput, cwd: string | null): Promise<DiscoveryLayerView>;
|
|
133
|
+
/**
|
|
134
|
+
* 删一条 MCP 条目(F-F6)。
|
|
135
|
+
*
|
|
136
|
+
* 这个 id 本来就不在这一层里时落盘内容不变,回报 `removed: false`(不是失败)。
|
|
137
|
+
* 文件坏了但用户要清掉一个条目时,`readRawMcpFile` 把读不出来的那份当空 —— 于是这次写入
|
|
138
|
+
* 会用一份合法 JSON 覆盖它,这与「坏文件要能修」(F-F6)是同一个动作。
|
|
139
|
+
*/
|
|
140
|
+
deleteMcpEntry(scope: McpEditableScope, id: string, cwd: string | null): Promise<{
|
|
141
|
+
layer: DiscoveryLayerView;
|
|
142
|
+
removed: boolean;
|
|
143
|
+
}>;
|
|
144
|
+
/** 可写作用域 → 那一层;`workspace` 作用域必须能落到某个项目里 */
|
|
145
|
+
private writableMcpLayer;
|
|
146
|
+
private readMcpLayers;
|
|
147
|
+
/** 读一个 mcp.json:不存在 / 坏了 / 能读 三种结论分开(F-F6) */
|
|
148
|
+
private readMcpFile;
|
|
149
|
+
/**
|
|
150
|
+
* 读 mcp.json 的原文。
|
|
151
|
+
*
|
|
152
|
+
* `broken` 与 `missing` 必须分开:`missing` 是「这里没有这一层」(正常),`broken` 是
|
|
153
|
+
* 「文件在,但读不成配置」(用户改了、改坏了,界面要能看见并修)。
|
|
154
|
+
*/
|
|
155
|
+
private readRawMcpFile;
|
|
156
|
+
private readDirectoryLayers;
|
|
157
|
+
/** 按种类读一个目录;目录不存在就是 `missing`,不是目录或读不了就是 `broken` */
|
|
158
|
+
private readDirectory;
|
|
159
|
+
/**
|
|
160
|
+
* 一层的 Skill。
|
|
161
|
+
*
|
|
162
|
+
* 有效条目交给 SDK 的 `discoverSkills`(frontmatter 的解析口径只该有一份);
|
|
163
|
+
* 另外再读一次目录,把「有 SKILL.md 却没被认成 Skill」的那些也报出来 —— 用户手改坏了要看得见。
|
|
164
|
+
*/
|
|
165
|
+
private readSkillLayer;
|
|
166
|
+
/**
|
|
167
|
+
* 一层的用户工具。
|
|
168
|
+
*
|
|
169
|
+
* 以 SDK 的 `discoverUserToolFiles` 为「能不能真的变成一个工具」的判据(它自带 import 护栏与
|
|
170
|
+
* 超时);没能加载上的 `.js` / `.mjs` 也列出来并说明原因。
|
|
171
|
+
*/
|
|
172
|
+
private readToolLayer;
|
|
173
|
+
/**
|
|
174
|
+
* 一层的子 Agent。
|
|
175
|
+
*
|
|
176
|
+
* 「什么算子 Agent」由 SDK 的 `discoverSubAgents` 说了算(有 `function` 定义的那些);
|
|
177
|
+
* 这里自己再读一遍文件,是为了拿到每个定义来自哪个文件(`source`)以及读不出来的那几个。
|
|
178
|
+
*/
|
|
179
|
+
private readSubAgentLayer;
|
|
180
|
+
/** 入参的 workspaceId → cwd;没给就是 `null`(只报与项目无关的那几层) */
|
|
181
|
+
private resolveCwd;
|
|
182
|
+
}
|