@lsamien/yaoyao 0.4.78 → 0.4.80
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 +5 -5
- package/THIRD_PARTY_NOTICES.md +4 -0
- package/build-info.json +11 -3
- package/dist/assets/{AboutDialog-jvhTP8-J.js → AboutDialog-on4AME1V.js} +2 -2
- package/dist/assets/{AboutDialog-jvhTP8-J.js.map → AboutDialog-on4AME1V.js.map} +1 -1
- package/dist/assets/{BotAutomationsView-ktoci79V.js → BotAutomationsView-Bmb14qI5.js} +2 -2
- package/dist/assets/{BotAutomationsView-ktoci79V.js.map → BotAutomationsView-Bmb14qI5.js.map} +1 -1
- package/dist/assets/BotPluginsDialog-6WPFFQnG.js +2 -0
- package/dist/assets/BotPluginsDialog-6WPFFQnG.js.map +1 -0
- package/dist/assets/BotPluginsDialog-B0iR4Jy2.css +1 -0
- package/dist/assets/{BotSettingsDialog-Ci_DZL4m.js → BotSettingsDialog-wWHnGtBg.js} +4 -4
- package/dist/assets/{BotSettingsDialog-Ci_DZL4m.js.map → BotSettingsDialog-wWHnGtBg.js.map} +1 -1
- package/dist/assets/ChatView-BKNyjhWf.js +2 -0
- package/dist/assets/ChatView-BKNyjhWf.js.map +1 -0
- package/dist/assets/ChatView-ClK12dmT.css +1 -0
- package/dist/assets/{ComputerPanel-Dbwgx5n8.js → ComputerPanel-DP9Sge1E.js} +2 -2
- package/dist/assets/{ComputerPanel-Dbwgx5n8.js.map → ComputerPanel-DP9Sge1E.js.map} +1 -1
- package/dist/assets/{ComputerViewerView-csnhRedK.js → ComputerViewerView-WjPHo035.js} +2 -2
- package/dist/assets/{ComputerViewerView-csnhRedK.js.map → ComputerViewerView-WjPHo035.js.map} +1 -1
- package/dist/assets/{ConversationsView-CEO2SVGT.js → ConversationsView-BRNIpK57.js} +4 -4
- package/dist/assets/{ConversationsView-CEO2SVGT.js.map → ConversationsView-BRNIpK57.js.map} +1 -1
- package/dist/assets/{ConversationsView-CHLGKsJt.css → ConversationsView-CbArO1v2.css} +1 -1
- package/dist/assets/{FilesView-t5jA-H2-.js → FilesView-ETwEkBC-.js} +2 -2
- package/dist/assets/{FilesView-t5jA-H2-.js.map → FilesView-ETwEkBC-.js.map} +1 -1
- package/dist/assets/{FloatingResourceSearch-BAYymuJV.js → FloatingResourceSearch-CxF6Ko17.js} +2 -2
- package/dist/assets/{FloatingResourceSearch-BAYymuJV.js.map → FloatingResourceSearch-CxF6Ko17.js.map} +1 -1
- package/dist/assets/{HistoryView-BqMSV9iC.js → HistoryView-uwkxvrTT.js} +2 -2
- package/dist/assets/{HistoryView-BqMSV9iC.js.map → HistoryView-uwkxvrTT.js.map} +1 -1
- package/dist/assets/{KanbanView-CWwrwH9S.js → KanbanView-BjiWhQiB.js} +2 -2
- package/dist/assets/{KanbanView-CWwrwH9S.js.map → KanbanView-BjiWhQiB.js.map} +1 -1
- package/dist/assets/{LocalVmSettingsPanel-BXvZwFQP.js → LocalVmSettingsPanel-BAVywgEJ.js} +2 -2
- package/dist/assets/{LocalVmSettingsPanel-BXvZwFQP.js.map → LocalVmSettingsPanel-BAVywgEJ.js.map} +1 -1
- package/dist/assets/{RunnerSettingsPanel-KkpIkkob.js → RunnerSettingsPanel-spsPiohB.js} +2 -2
- package/dist/assets/{RunnerSettingsPanel-KkpIkkob.js.map → RunnerSettingsPanel-spsPiohB.js.map} +1 -1
- package/dist/assets/{StandaloneDialog-D4BQqjpB.js → StandaloneDialog-Ctcd4omg.js} +2 -2
- package/dist/assets/{StandaloneDialog-D4BQqjpB.js.map → StandaloneDialog-Ctcd4omg.js.map} +1 -1
- package/dist/assets/{UpdateCheckDialog-Ct0bT6xU.js → UpdateCheckDialog-C43LDN1t.js} +2 -2
- package/dist/assets/{UpdateCheckDialog-Ct0bT6xU.js.map → UpdateCheckDialog-C43LDN1t.js.map} +1 -1
- package/dist/assets/{WorkspaceKnowledgePanel-WBcPB49x.js → WorkspaceKnowledgePanel-CDbdIzXZ.js} +2 -2
- package/dist/assets/{WorkspaceKnowledgePanel-WBcPB49x.js.map → WorkspaceKnowledgePanel-CDbdIzXZ.js.map} +1 -1
- package/dist/assets/{WorkspaceRoutinesPanel-JubUwGsV.js → WorkspaceRoutinesPanel-h7wcBTnK.js} +2 -2
- package/dist/assets/{WorkspaceRoutinesPanel-JubUwGsV.js.map → WorkspaceRoutinesPanel-h7wcBTnK.js.map} +1 -1
- package/dist/assets/WorkspaceShell-Bx8se0l7.js +44 -0
- package/dist/assets/WorkspaceShell-Bx8se0l7.js.map +1 -0
- package/dist/assets/WorkspaceShell-DXti6BpF.css +1 -0
- package/dist/assets/{WorkspaceView-DTanioWW.js → WorkspaceView-zDyCd5Ys.js} +2 -2
- package/dist/assets/{WorkspaceView-DTanioWW.js.map → WorkspaceView-zDyCd5Ys.js.map} +1 -1
- package/dist/assets/{docx-preview-B1SjJgD_.js → docx-preview-DOVGRYbk.js} +2 -2
- package/dist/assets/{docx-preview-B1SjJgD_.js.map → docx-preview-DOVGRYbk.js.map} +1 -1
- package/dist/assets/{index-CWamgtSb.js → index-CRBIQ5t6.js} +4 -4
- package/dist/assets/index-CRBIQ5t6.js.map +1 -0
- package/dist/assets/{pdf-DVDddcFC.js → pdf-CyfBRmEm.js} +2 -2
- package/dist/assets/{pdf-DVDddcFC.js.map → pdf-CyfBRmEm.js.map} +1 -1
- package/dist/assets/{sessionOwnership-0hdKcwOs.js → sessionOwnership-BhbWRxbS.js} +2 -2
- package/dist/assets/{sessionOwnership-0hdKcwOs.js.map → sessionOwnership-BhbWRxbS.js.map} +1 -1
- package/dist/assets/{viewModels-DKBqaDRg.js → viewModels-DNhmBuoz.js} +4 -4
- package/dist/assets/{viewModels-DKBqaDRg.js.map → viewModels-DNhmBuoz.js.map} +1 -1
- package/dist/index.html +1 -1
- package/dist/provider-logos/airtable.svg +13 -0
- package/dist/provider-logos/discord.svg +15 -0
- package/dist/provider-logos/github.svg +10 -0
- package/dist/provider-logos/gmail.svg +1 -0
- package/dist/provider-logos/googlecalendar.svg +148 -0
- package/dist/provider-logos/googledrive.svg +25 -0
- package/dist/provider-logos/linear.svg +5 -0
- package/dist/provider-logos/notion.svg +11 -0
- package/dist/provider-logos/outlook.svg +76 -0
- package/dist/provider-logos/slack.svg +22 -0
- package/dist/provider-logos/trello.svg +19 -0
- package/dist/provider-logos/twitter.svg +128 -0
- package/dist-server/server/app.js +2 -2
- package/dist-server/server/botPlugins/connectedApps.js +3 -2
- package/dist-server/server/credentialVault/coordinator.js +3 -1
- package/dist-server/server/credentialVault/localClient.js +70 -0
- package/dist-server/server/credentialVault/transport.js +1 -0
- package/dist-server/server/dashboardCommand.js +62 -0
- package/dist-server/server/dashboardController.js +117 -25
- package/dist-server/server/routes.js +5 -0
- package/dist-server/server/security.js +2 -1
- package/dist-server/shared/botProviderLogos.js +61 -0
- package/package.json +1 -1
- package/release.json +3 -3
- package/dist/assets/BotPluginsDialog-Db5dTqvg.css +0 -1
- package/dist/assets/BotPluginsDialog-H85RI-7P.js +0 -2
- package/dist/assets/BotPluginsDialog-H85RI-7P.js.map +0 -1
- package/dist/assets/ChatView-6cdLMsuy.js +0 -2
- package/dist/assets/ChatView-6cdLMsuy.js.map +0 -1
- package/dist/assets/ChatView-C_7_7olu.css +0 -1
- package/dist/assets/WorkspaceShell-0m4gg6AW.css +0 -1
- package/dist/assets/WorkspaceShell-Do2VAwIz.js +0 -44
- package/dist/assets/WorkspaceShell-Do2VAwIz.js.map +0 -1
- package/dist/assets/index-CWamgtSb.js.map +0 -1
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { join } from 'node:path';
|
|
2
|
+
import { randomUUID } from 'node:crypto';
|
|
3
|
+
import { CredentialVaultClient } from './transport.js';
|
|
4
|
+
import { CredentialVaultStore } from './store.js';
|
|
5
|
+
import { CredentialVaultBroker } from './broker.js';
|
|
6
|
+
import { HttpError } from '../errors.js';
|
|
7
|
+
import { acquireServiceInstance } from '../serviceInstance.js';
|
|
8
|
+
/** Default encrypted storage. It never supplies an executor or issues Bot leases.
|
|
9
|
+
* Automatic credential use still requires the explicitly configured isolated broker. */
|
|
10
|
+
export class LocalCredentialVaultClient extends CredentialVaultClient {
|
|
11
|
+
home;
|
|
12
|
+
controlEpoch = randomUUID();
|
|
13
|
+
broker;
|
|
14
|
+
instance;
|
|
15
|
+
closed = false;
|
|
16
|
+
constructor(home) {
|
|
17
|
+
super();
|
|
18
|
+
this.home = home;
|
|
19
|
+
}
|
|
20
|
+
async call(owner, session, command, value) {
|
|
21
|
+
if (this.closed)
|
|
22
|
+
throw new HttpError(503, '密码保险箱已关闭', 'vault_offline');
|
|
23
|
+
if (['grant', 'execute'].includes(command))
|
|
24
|
+
throw new HttpError(409, '本机保险箱只保存凭据;Bot 自动使用需要连接独立密码库服务', 'vault_executor_not_enabled');
|
|
25
|
+
this.broker ??= CredentialVaultStore.create(join(this.home, 'credential-vault')).then(store => {
|
|
26
|
+
if (this.closed)
|
|
27
|
+
throw new Error('closed');
|
|
28
|
+
this.instance = acquireServiceInstance(store.root, 'credential-vault-v1');
|
|
29
|
+
const broker = new CredentialVaultBroker(store);
|
|
30
|
+
broker.hello(this.controlEpoch);
|
|
31
|
+
return broker;
|
|
32
|
+
}).catch(() => {
|
|
33
|
+
this.instance?.release();
|
|
34
|
+
this.instance = undefined;
|
|
35
|
+
this.broker = undefined;
|
|
36
|
+
throw new HttpError(503, '无法打开本机密码保险箱,请检查数据目录权限或是否已被其他服务使用', 'vault_offline');
|
|
37
|
+
});
|
|
38
|
+
const broker = await this.broker;
|
|
39
|
+
if (this.closed)
|
|
40
|
+
throw new HttpError(503, '密码保险箱已关闭', 'vault_offline');
|
|
41
|
+
try {
|
|
42
|
+
const result = broker.dispatch(this.controlEpoch, owner, session, command, value);
|
|
43
|
+
return ['status', 'initialize', 'unlock', 'restore'].includes(command)
|
|
44
|
+
? { ...result, storageMode: 'local' }
|
|
45
|
+
: result;
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
if (error instanceof HttpError)
|
|
49
|
+
throw error;
|
|
50
|
+
broker.disconnect();
|
|
51
|
+
throw new HttpError(409, '密码保险箱操作未完成,请刷新状态后重新解锁', 'vault_request_failed');
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
close() {
|
|
55
|
+
this.closed = true;
|
|
56
|
+
void this.broker?.then(broker => {
|
|
57
|
+
try {
|
|
58
|
+
broker.close();
|
|
59
|
+
}
|
|
60
|
+
finally {
|
|
61
|
+
this.instance?.release();
|
|
62
|
+
this.instance = undefined;
|
|
63
|
+
}
|
|
64
|
+
}).catch(() => { });
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
export function createCredentialVaultClient(config, home) {
|
|
68
|
+
// An unavailable explicit deployment must never fall back to a different vault.
|
|
69
|
+
return config ? new CredentialVaultClient(config) : new LocalCredentialVaultClient(home);
|
|
70
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { basename, dirname, isAbsolute } from 'node:path';
|
|
2
|
+
const profile = /^[a-z0-9][a-z0-9_-]{0,63}$/;
|
|
3
|
+
/** Recognize Hermes' executable, script and module entry points, including serve. */
|
|
4
|
+
export function dashboardCommandIndex(args) {
|
|
5
|
+
let index;
|
|
6
|
+
const executable = basename(args[0] ?? '');
|
|
7
|
+
if (executable === 'hermes')
|
|
8
|
+
index = 1;
|
|
9
|
+
else if (/^python(?:\d+(?:\.\d+)*)?$/i.test(executable)) {
|
|
10
|
+
const script = args[1] ?? '';
|
|
11
|
+
if (basename(script) === 'hermes' || (basename(script) === 'main.py' && basename(dirname(script)) === 'hermes_cli'))
|
|
12
|
+
index = 2;
|
|
13
|
+
else if (script === '-m' && args[2] === 'hermes_cli.main')
|
|
14
|
+
index = 3;
|
|
15
|
+
else
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
else
|
|
19
|
+
return;
|
|
20
|
+
if (args[index] === '--profile' || args[index] === '-p') {
|
|
21
|
+
if (!profile.test(args[index + 1] ?? ''))
|
|
22
|
+
return;
|
|
23
|
+
index += 2;
|
|
24
|
+
}
|
|
25
|
+
else if (args[index]?.startsWith('--profile=')) {
|
|
26
|
+
if (!profile.test(args[index].slice(10)))
|
|
27
|
+
return;
|
|
28
|
+
index++;
|
|
29
|
+
}
|
|
30
|
+
else if (profile.test(args[index] ?? '') && ['dashboard', 'serve'].includes(args[index + 1] ?? ''))
|
|
31
|
+
index++;
|
|
32
|
+
return ['dashboard', 'serve'].includes(args[index] ?? '') ? index : undefined;
|
|
33
|
+
}
|
|
34
|
+
/** ps does not preserve argv boundaries. Only simple, bounded runtime flags can
|
|
35
|
+
* be replayed; shell wrappers, SSH backends and ambiguous paths are rejected. */
|
|
36
|
+
export function standaloneDashboardCommand(command) {
|
|
37
|
+
if (command.length > 8192 || /[\n\r'"\\]/.test(command))
|
|
38
|
+
return;
|
|
39
|
+
const args = command.trim().split(/\s+/), index = dashboardCommandIndex(args);
|
|
40
|
+
if (index === undefined || !isAbsolute(args[0]) || args.length > 32)
|
|
41
|
+
return;
|
|
42
|
+
if (index >= 2 && args[1] !== '-m' && !isAbsolute(args[1]))
|
|
43
|
+
return;
|
|
44
|
+
for (let i = index + 1; i < args.length; i++) {
|
|
45
|
+
const flag = args[i];
|
|
46
|
+
if (['--no-open', '--skip-build', '--insecure', '--isolated'].includes(flag))
|
|
47
|
+
continue;
|
|
48
|
+
const match = /^(--host|--port|--profile)(?:=(.*))?$/.exec(flag);
|
|
49
|
+
if (!match)
|
|
50
|
+
return;
|
|
51
|
+
const value = match[2] ?? args[++i];
|
|
52
|
+
if (!value)
|
|
53
|
+
return;
|
|
54
|
+
if (match[1] === '--host' && !['127.0.0.1', 'localhost', '0.0.0.0', '::', '::1'].includes(value))
|
|
55
|
+
return;
|
|
56
|
+
if (match[1] === '--port' && value !== '9119')
|
|
57
|
+
return;
|
|
58
|
+
if (match[1] === '--profile' && !profile.test(value))
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
return { command: args[0], args: args.slice(1) };
|
|
62
|
+
}
|
|
@@ -1,19 +1,34 @@
|
|
|
1
|
-
import { execFile } from 'node:child_process';
|
|
2
|
-
import { basename } from 'node:path';
|
|
1
|
+
import { execFile, spawn } from 'node:child_process';
|
|
3
2
|
import { promisify } from 'node:util';
|
|
3
|
+
import { isAbsolute } from 'node:path';
|
|
4
|
+
import { dashboardCommandIndex, standaloneDashboardCommand } from './dashboardCommand.js';
|
|
5
|
+
import { LoopbackTransport } from './loopbackAuthorization.js';
|
|
4
6
|
const execFileAsync = promisify(execFile);
|
|
5
7
|
const labels = ['com.samien.hermes.dashboard.local', 'ai.hermes.dashboard'];
|
|
6
8
|
const localOrigin = 'http://127.0.0.1:9119';
|
|
7
9
|
async function healthy(origin) {
|
|
10
|
+
const transport = new LoopbackTransport();
|
|
8
11
|
try {
|
|
9
|
-
const response = await fetch(`${origin}/api/health
|
|
12
|
+
const response = await transport.fetch(new URL(`${origin}/api/health`), { signal: AbortSignal.timeout(1000) });
|
|
10
13
|
await response.body?.cancel();
|
|
11
14
|
return response.ok;
|
|
12
15
|
}
|
|
13
16
|
catch {
|
|
14
17
|
return false;
|
|
15
18
|
}
|
|
19
|
+
finally {
|
|
20
|
+
transport.close();
|
|
21
|
+
}
|
|
16
22
|
}
|
|
23
|
+
const launch = (command, args, cwd) => new Promise((resolve, reject) => {
|
|
24
|
+
const env = { ...process.env };
|
|
25
|
+
for (const key of Object.keys(env))
|
|
26
|
+
if (key.startsWith('HERMES_YAOYAO_') || key.startsWith('ELECTRON_'))
|
|
27
|
+
delete env[key];
|
|
28
|
+
const child = spawn(command, args, { cwd, env, detached: true, stdio: 'ignore' });
|
|
29
|
+
child.once('error', reject);
|
|
30
|
+
child.once('spawn', () => { child.unref(); child.pid ? resolve(child.pid) : reject(new Error('Hermes Dashboard 启动失败。')); });
|
|
31
|
+
});
|
|
17
32
|
/** Runs only in the Yaoyao server. No browser, desktop IPC or client-supplied target is used. */
|
|
18
33
|
export class ServerDashboardController {
|
|
19
34
|
upstream;
|
|
@@ -24,6 +39,8 @@ export class ServerDashboardController {
|
|
|
24
39
|
healthy;
|
|
25
40
|
timeout;
|
|
26
41
|
interval;
|
|
42
|
+
launch;
|
|
43
|
+
launchedPid;
|
|
27
44
|
service;
|
|
28
45
|
restarting = false;
|
|
29
46
|
stopped = false;
|
|
@@ -34,8 +51,9 @@ export class ServerDashboardController {
|
|
|
34
51
|
this.uid = options.uid ?? process.getuid?.();
|
|
35
52
|
this.run = options.run ?? (async (command, args) => (await execFileAsync(command, args, { timeout: 3000, maxBuffer: 256 * 1024 })).stdout);
|
|
36
53
|
this.healthy = options.healthy ?? healthy;
|
|
37
|
-
this.timeout = options.readyTimeoutMs ??
|
|
54
|
+
this.timeout = options.readyTimeoutMs ?? 30000;
|
|
38
55
|
this.interval = options.pollIntervalMs ?? 250;
|
|
56
|
+
this.launch = options.launch ?? launch;
|
|
39
57
|
}
|
|
40
58
|
get canRestart() {
|
|
41
59
|
return !this.stopped && this.upstream.origin === localOrigin && (!!this.owned?.canRestart || !!this.service);
|
|
@@ -45,7 +63,7 @@ export class ServerDashboardController {
|
|
|
45
63
|
return '此 Hermes 不在夭夭服务端可管理的本机地址,请在 Hermes 所在节点重启。';
|
|
46
64
|
if (this.platform !== 'darwin')
|
|
47
65
|
return '夭夭服务端尚未支持此系统的外部 Dashboard 服务管理,请在 Hermes 所在节点重启。';
|
|
48
|
-
return '
|
|
66
|
+
return '夭夭服务端未识别到当前账号可管理的 9119 Hermes Dashboard 进程;请确认由本机 Hermes 命令启动且与夭夭使用同一系统账号。';
|
|
49
67
|
}
|
|
50
68
|
async refresh() {
|
|
51
69
|
if (this.restarting || this.stopped)
|
|
@@ -58,25 +76,94 @@ export class ServerDashboardController {
|
|
|
58
76
|
async discover() {
|
|
59
77
|
if (this.stopped || this.upstream.origin !== localOrigin || this.platform !== 'darwin' || this.uid === undefined)
|
|
60
78
|
return;
|
|
79
|
+
const pids = await this.listeners().catch(() => []);
|
|
80
|
+
if (pids.length !== 1)
|
|
81
|
+
return;
|
|
82
|
+
const pid = pids[0];
|
|
61
83
|
for (const label of labels) {
|
|
62
|
-
const
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
84
|
+
const service = await this.launchAgent(label, pid);
|
|
85
|
+
if (service)
|
|
86
|
+
return service;
|
|
87
|
+
}
|
|
88
|
+
// Custom labels are common in manual installs. The listener PID, rather than
|
|
89
|
+
// a label alone, identifies the only candidate we may inspect and restart.
|
|
90
|
+
let jobs;
|
|
91
|
+
try {
|
|
92
|
+
const listing = await this.run('/bin/launchctl', ['list']);
|
|
93
|
+
jobs = [...listing.matchAll(/^\s*(\d+)\s+-?\d+\s+(\S+)\s*$/gm)].map(m => ({ pid: Number(m[1]), label: m[2] }));
|
|
94
|
+
}
|
|
95
|
+
catch {
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
const job = jobs.find(job => job.pid === pid);
|
|
99
|
+
if (job)
|
|
100
|
+
return this.launchAgent(job.label, pid);
|
|
101
|
+
const process = await this.process(pid);
|
|
102
|
+
if (!process || process.uid !== this.uid || this.uid === 0 || (pid !== this.launchedPid && jobs.some(job => job.pid === process.parent)))
|
|
103
|
+
return;
|
|
104
|
+
const invocation = standaloneDashboardCommand(process.command);
|
|
105
|
+
if (!invocation)
|
|
106
|
+
return;
|
|
107
|
+
if (process.parent !== 1 && pid !== this.launchedPid) {
|
|
108
|
+
const parent = await this.process(process.parent);
|
|
109
|
+
if (!parent || parent.uid !== this.uid || !/^(?:\S*\/)?-?(?:zsh|bash|sh|fish)(?:\s|$)/.test(parent.command))
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
// Module entry points can depend on the original working directory.
|
|
113
|
+
try {
|
|
114
|
+
const detail = await this.run('/usr/sbin/lsof', ['-a', '-p', String(pid), '-d', 'cwd', '-Fn']);
|
|
115
|
+
const paths = detail.split('\n').filter(line => line.startsWith('n')).map(line => line.slice(1));
|
|
116
|
+
const cwd = paths[0];
|
|
117
|
+
if (paths.length === 1 && cwd && isAbsolute(cwd) && !/[\r\0]/.test(cwd))
|
|
118
|
+
return { kind: 'standalone', pid, cwd, ...invocation };
|
|
119
|
+
}
|
|
120
|
+
catch { /* Do not stop a process we cannot reliably relaunch. */ }
|
|
121
|
+
}
|
|
122
|
+
async listeners() {
|
|
123
|
+
try {
|
|
124
|
+
const listeners = await this.run('/usr/sbin/lsof', ['-nP', '-a', '-iTCP:9119', '-sTCP:LISTEN', '-Fp']);
|
|
125
|
+
return [...new Set([...listeners.matchAll(/^p(\d+)$/gm)].map(match => Number(match[1])))];
|
|
126
|
+
}
|
|
127
|
+
catch (error) {
|
|
128
|
+
if (error.code === 1)
|
|
129
|
+
return [];
|
|
130
|
+
throw error;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
async launchAgent(label, listener) {
|
|
134
|
+
if (!/^[A-Za-z0-9_.-]+$/.test(label))
|
|
135
|
+
return;
|
|
136
|
+
const target = `gui/${this.uid}/${label}`;
|
|
137
|
+
try {
|
|
138
|
+
const detail = await this.run('/bin/launchctl', ['print', target]);
|
|
139
|
+
const pid = Number(detail.match(/^\s*pid = (\d+)\s*$/m)?.[1]);
|
|
140
|
+
const args = detail.match(/^\s*arguments = \{\n([\s\S]*?)^\s*\}/m)?.[1]?.trim().split('\n').map(line => line.trim()) ?? [];
|
|
141
|
+
if (pid === listener && dashboardCommandIndex(args) !== undefined)
|
|
142
|
+
return { kind: 'launchagent', target, pid };
|
|
143
|
+
}
|
|
144
|
+
catch { /* Missing job or unknown command: fail closed. */ }
|
|
145
|
+
}
|
|
146
|
+
async process(pid) {
|
|
147
|
+
try {
|
|
148
|
+
const detail = await this.run('/bin/ps', ['-p', String(pid), '-o', 'uid=', '-o', 'ppid=', '-o', 'command=']);
|
|
149
|
+
const match = /^\s*(\d+)\s+(\d+)\s+([^\r\n]+)\s*$/.exec(detail);
|
|
150
|
+
if (match)
|
|
151
|
+
return { uid: Number(match[1]), parent: Number(match[2]), command: match[3].trim() };
|
|
152
|
+
}
|
|
153
|
+
catch { /* Process has exited or is unreadable. */ }
|
|
154
|
+
}
|
|
155
|
+
async restartStandalone(service) {
|
|
156
|
+
// discover() has just checked the owner, executable and sole listener.
|
|
157
|
+
await this.run('/bin/kill', ['-TERM', String(service.pid)]);
|
|
158
|
+
const deadline = Date.now() + this.timeout;
|
|
159
|
+
while (!this.stopped && await this.process(service.pid)) {
|
|
160
|
+
if (Date.now() >= deadline)
|
|
161
|
+
throw new Error('Hermes Dashboard 未能停止,请在所在节点检查。');
|
|
162
|
+
await new Promise(resolve => setTimeout(resolve, this.interval));
|
|
79
163
|
}
|
|
164
|
+
if (this.stopped || (await this.listeners()).length)
|
|
165
|
+
throw new Error('9119 已被其他进程占用,未启动新的 Dashboard。');
|
|
166
|
+
this.launchedPid = await this.launch(service.command, service.args, service.cwd);
|
|
80
167
|
}
|
|
81
168
|
async restart() {
|
|
82
169
|
if (this.restarting)
|
|
@@ -97,13 +184,18 @@ export class ServerDashboardController {
|
|
|
97
184
|
previous = await this.discover();
|
|
98
185
|
if (!previous || this.stopped)
|
|
99
186
|
throw new Error(this.unavailableReason);
|
|
100
|
-
|
|
187
|
+
if (previous.kind === 'launchagent')
|
|
188
|
+
await this.run('/bin/launchctl', ['kickstart', '-k', previous.target]);
|
|
189
|
+
else
|
|
190
|
+
await this.restartStandalone(previous);
|
|
101
191
|
}
|
|
102
192
|
const deadline = Date.now() + this.timeout;
|
|
103
193
|
while (!this.stopped && Date.now() < deadline) {
|
|
104
194
|
const replacement = owned ? undefined : await this.discover();
|
|
105
|
-
const replaced = owned ? this.owned?.canRestart
|
|
106
|
-
|
|
195
|
+
const replaced = owned ? this.owned?.canRestart : replacement && previous && replacement.pid !== previous.pid
|
|
196
|
+
&& (replacement.kind === 'launchagent' && previous.kind === 'launchagent' ? replacement.target === previous.target
|
|
197
|
+
: replacement.kind === 'standalone' && previous.kind === 'standalone' && replacement.pid === this.launchedPid
|
|
198
|
+
&& replacement.command === previous.command && replacement.cwd === previous.cwd && JSON.stringify(replacement.args) === JSON.stringify(previous.args));
|
|
107
199
|
if (replaced && await this.healthy(this.upstream.origin) && !this.stopped) {
|
|
108
200
|
this.service = replacement;
|
|
109
201
|
return;
|
|
@@ -270,6 +270,9 @@ function isMissingSessionResponse(response) {
|
|
|
270
270
|
if (payload.code === 'session_not_found')
|
|
271
271
|
return true;
|
|
272
272
|
const detail = payload.detail;
|
|
273
|
+
// Hermes also uses this detail for a stored session absent from its history.
|
|
274
|
+
if (typeof detail === 'string' && /^not found[.!]?$/i.test(detail.trim()))
|
|
275
|
+
return true;
|
|
273
276
|
const message = [payload.error, payload.message, detail,
|
|
274
277
|
detail && typeof detail === 'object' && 'message' in detail ? detail.message : undefined]
|
|
275
278
|
.find(value => typeof value === 'string');
|
|
@@ -2069,6 +2072,7 @@ export function createApiRouter(dependencies) {
|
|
|
2069
2072
|
if (isMissingSessionResponse(existing)) {
|
|
2070
2073
|
// Only this account's cached copy remains; no upstream mutation is needed.
|
|
2071
2074
|
dependencies.chatCache?.store.deleteSession(owner, profile, id);
|
|
2075
|
+
dependencies.onChatListChanged?.(owner, profile, id);
|
|
2072
2076
|
ctx.body = { ok: true };
|
|
2073
2077
|
return;
|
|
2074
2078
|
}
|
|
@@ -2077,6 +2081,7 @@ export function createApiRouter(dependencies) {
|
|
|
2077
2081
|
const alreadyMissing = isMissingSessionResponse(response);
|
|
2078
2082
|
if ((response.status >= 200 && response.status < 300) || alreadyMissing) {
|
|
2079
2083
|
dependencies.chatCache?.store.deleteSession(owner, profile, id);
|
|
2084
|
+
dependencies.onChatListChanged?.(owner, profile, id);
|
|
2080
2085
|
}
|
|
2081
2086
|
if (alreadyMissing) {
|
|
2082
2087
|
ctx.body = { ok: true };
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { createHmac, randomBytes, timingSafeEqual } from 'node:crypto';
|
|
2
2
|
import { parse, serialize } from 'cookie';
|
|
3
3
|
import { isLoopbackHost, isPrivateHost } from './config.js';
|
|
4
|
+
import { BOT_LOGO_ORIGINS } from '../shared/botProviderLogos.js';
|
|
4
5
|
export const CSRF_COOKIE = 'hermes_yaoyao_csrf';
|
|
5
6
|
function splitHostPort(value) {
|
|
6
7
|
const trimmed = value.trim().toLowerCase();
|
|
@@ -179,7 +180,7 @@ export function applySecurityHeaders(ctx, tls, allowedHosts = new Set()) {
|
|
|
179
180
|
"object-src 'none'",
|
|
180
181
|
"script-src 'self'",
|
|
181
182
|
"style-src 'self' 'unsafe-inline'",
|
|
182
|
-
|
|
183
|
+
`img-src 'self' data: blob: ${BOT_LOGO_ORIGINS.join(' ')}`,
|
|
183
184
|
"media-src 'self' blob:",
|
|
184
185
|
`connect-src 'self' ${socketOrigin} ${proxySocketOrigins.join(' ')}`.trim(),
|
|
185
186
|
].join('; '));
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/** Bundled logos keep the built-in directory usable without a third-party request. */
|
|
2
|
+
const providers = {
|
|
3
|
+
gmail: { hosts: ['gmail.com'] },
|
|
4
|
+
googledrive: { hosts: ['drive.google.com'] },
|
|
5
|
+
googlecalendar: { hosts: ['calendar.google.com'] },
|
|
6
|
+
github: { hosts: ['github.com', 'githubcopilot.com'] },
|
|
7
|
+
notion: { hosts: ['notion.so', 'notion.com'] },
|
|
8
|
+
slack: { hosts: ['slack.com'] },
|
|
9
|
+
linear: { hosts: ['linear.app'] },
|
|
10
|
+
discord: { hosts: ['discord.com'] },
|
|
11
|
+
outlook: { hosts: ['outlook.com', 'outlook.office.com'] },
|
|
12
|
+
trello: { hosts: ['trello.com'] },
|
|
13
|
+
airtable: { hosts: ['airtable.com'] },
|
|
14
|
+
twitter: { hosts: ['twitter.com', 'x.com'] },
|
|
15
|
+
};
|
|
16
|
+
const aliases = { gdrive: 'googledrive', x: 'twitter', microsoftoutlook: 'outlook' };
|
|
17
|
+
export const BOT_LOGO_ORIGINS = ['https://logos.composio.dev', 'https://assets.composio.dev'];
|
|
18
|
+
export function bundledProviderLogo(slug) {
|
|
19
|
+
const key = slug.toLowerCase().replace(/[\s_-]/g, '');
|
|
20
|
+
const provider = aliases[key] ?? key;
|
|
21
|
+
return Object.hasOwn(providers, provider) ? `/provider-logos/${provider}.svg` : undefined;
|
|
22
|
+
}
|
|
23
|
+
/** Match the image CSP; never forward credentials or arbitrary image origins. */
|
|
24
|
+
export function safeProviderLogo(value) {
|
|
25
|
+
if (typeof value !== 'string' || value.length > 2048)
|
|
26
|
+
return undefined;
|
|
27
|
+
if (Object.keys(providers).some(slug => value === bundledProviderLogo(slug)))
|
|
28
|
+
return value;
|
|
29
|
+
try {
|
|
30
|
+
const url = new URL(value);
|
|
31
|
+
if (url.username || url.password || !BOT_LOGO_ORIGINS.some(origin => url.origin === origin))
|
|
32
|
+
return undefined;
|
|
33
|
+
return url.href;
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
return undefined;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
export function mcpProviderLogo(plugin) {
|
|
40
|
+
if (plugin.transport === 'http' && plugin.url) {
|
|
41
|
+
try {
|
|
42
|
+
const host = new URL(plugin.url).hostname.toLowerCase();
|
|
43
|
+
const provider = Object.entries(providers).find(([, { hosts }]) => hosts.some(domain => host === domain || host.endsWith(`.${domain}`)));
|
|
44
|
+
if (provider)
|
|
45
|
+
return bundledProviderLogo(provider[0]);
|
|
46
|
+
}
|
|
47
|
+
catch { /* Older invalid definitions still get a readable placeholder. */ }
|
|
48
|
+
}
|
|
49
|
+
if (plugin.transport === 'stdio') {
|
|
50
|
+
for (const arg of [plugin.command ?? '', ...(plugin.args ?? [])]) {
|
|
51
|
+
const packageName = arg.toLowerCase().replace(/^--package=/, '').replace(/@[^/@]+$/, '');
|
|
52
|
+
if (packageName === '@notionhq/notion-mcp-server')
|
|
53
|
+
return bundledProviderLogo('notion');
|
|
54
|
+
const slug = /^@modelcontextprotocol\/server-([a-z-]+)$/.exec(packageName)?.[1];
|
|
55
|
+
const logo = slug && bundledProviderLogo(slug);
|
|
56
|
+
if (logo)
|
|
57
|
+
return logo;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return bundledProviderLogo(plugin.name.replace(/\s*(?:mcp(?:\s*(?:server|服务))?|server|服务)$/i, '').trim());
|
|
61
|
+
}
|
package/package.json
CHANGED
package/release.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
.bot-plugins[data-v-9850b6a3]{color:var(--text-primary);gap:16px;font-size:13px;display:grid}.intro[data-v-9850b6a3],.hint[data-v-9850b6a3]{color:var(--text-secondary);margin:0;line-height:1.6}.hint[data-v-9850b6a3]{font-size:12px}.plugin-tabs[data-v-9850b6a3],.view-tabs[data-v-9850b6a3],.plugin-toolbar[data-v-9850b6a3],.card-heading[data-v-9850b6a3],.card-actions[data-v-9850b6a3],.editor-actions[data-v-9850b6a3]{align-items:center;gap:8px;display:flex}.plugin-tabs[data-v-9850b6a3]{border-bottom:1px solid var(--line);padding-bottom:8px}.plugin-tabs button[aria-selected=true][data-v-9850b6a3],.view-tabs button[aria-selected=true][data-v-9850b6a3]{background:var(--surface-soft);font-weight:650}.plugin-toolbar[data-v-9850b6a3]{justify-content:space-between}.plugin-toolbar p[data-v-9850b6a3]{margin:0;font-weight:650}.card-heading h4[data-v-9850b6a3]{overflow-wrap:anywhere;flex:1;min-width:0;margin:0;font-size:14px}.card-actions[data-v-9850b6a3]{flex-wrap:wrap}.bot-plugins button[data-v-9850b6a3]{border:1px solid var(--line);background:var(--surface-raised);min-height:36px;color:inherit;font:inherit;cursor:pointer;border-radius:8px;justify-content:center;align-items:center;gap:6px;padding:6px 10px;display:inline-flex}.bot-plugins button[data-v-9850b6a3]:hover{background:var(--surface-hover)}.bot-plugins button[data-v-9850b6a3]:disabled{opacity:.45;cursor:not-allowed}.bot-plugins[data-v-9850b6a3] :is(button,input,select,textarea,a,summary):focus-visible{outline:2px solid var(--accent);outline-offset:2px}.bot-plugins a[data-v-9850b6a3]{color:var(--accent);align-items:center;gap:4px;display:inline-flex}.bot-plugins .danger[data-v-9850b6a3]{color:var(--danger)}.bot-plugins .primary[data-v-9850b6a3]{background:var(--accent);color:var(--text-on-solid);border-color:var(--accent)}.bot-plugins label[data-v-9850b6a3]{gap:6px;font-size:12px;line-height:1.6;display:grid}.bot-plugins input[data-v-9850b6a3]:not([type=checkbox]),.bot-plugins select[data-v-9850b6a3],.bot-plugins textarea[data-v-9850b6a3]{box-sizing:border-box;border:1px solid var(--line);width:100%;min-width:0;color:var(--text-primary);background:var(--surface);font:inherit;border-radius:8px;padding:9px 10px}.bot-plugins textarea[data-v-9850b6a3]{resize:vertical;font-family:var(--font-mono,monospace)}.plugin-search[data-v-9850b6a3]{position:relative}.plugin-search>svg[data-v-9850b6a3]{color:var(--text-muted);position:absolute;top:11px;left:10px}.plugin-search input[data-v-9850b6a3]{padding-left:34px!important}.plugin-editor[data-v-9850b6a3],.mcp-card[data-v-9850b6a3],.app-card[data-v-9850b6a3],.connection-settings[data-v-9850b6a3]{border:1px solid var(--line);background:var(--surface);border-radius:12px;gap:12px;padding:14px;display:grid}.plugin-editor h4[data-v-9850b6a3]{margin:0}.plugin-editor[data-v-9850b6a3]{background:var(--surface-soft)}.editor-actions[data-v-9850b6a3]{justify-content:flex-end}.bot-plugins fieldset[data-v-9850b6a3]{border:1px solid var(--line);border-radius:8px;gap:4px;max-height:180px;display:grid;overflow:auto}.bot-plugins .check-row[data-v-9850b6a3]{align-items:center;gap:8px;min-height:32px;display:flex}.check-row input[data-v-9850b6a3]{accent-color:var(--accent)}.app-grid[data-v-9850b6a3]{grid-template-columns:repeat(auto-fill,minmax(240px,1fr));gap:12px;display:grid}.app-card[data-v-9850b6a3]{align-content:start}.app-monogram[data-v-9850b6a3]{background:var(--surface-soft);border-radius:9px;flex-shrink:0;place-items:center;width:34px;height:34px;font-size:17px;font-weight:650;display:grid}.app-account[data-v-9850b6a3]{border-top:1px solid var(--line);justify-content:space-between;align-items:center;gap:8px;padding-top:8px;display:flex}.app-account span[data-v-9850b6a3]{overflow-wrap:anywhere;min-width:0}.app-account small[data-v-9850b6a3]{color:var(--text-muted);margin-top:3px;display:block}.badge[data-v-9850b6a3]{color:var(--text-muted);white-space:nowrap;font-size:11px}.badge.enabled[data-v-9850b6a3]{color:var(--accent)}.endpoint[data-v-9850b6a3]{overflow-wrap:anywhere}.plugin-error[data-v-9850b6a3],.plugin-notice[data-v-9850b6a3]{background:var(--surface-soft);border-radius:8px;margin:0;padding:12px;line-height:1.6}.plugin-error[data-v-9850b6a3]{color:var(--danger)}.plugin-empty[data-v-9850b6a3]{text-align:center;color:var(--text-secondary);padding:28px 12px;line-height:1.8}.connection-settings[data-v-9850b6a3]{display:block}.connection-settings summary[data-v-9850b6a3]{cursor:pointer;font-weight:600;line-height:1.8}.connection-settings summary span[data-v-9850b6a3]{float:right;color:var(--text-muted);font-weight:400}.connection-settings p[data-v-9850b6a3]{margin:12px 0}.connection-settings form[data-v-9850b6a3]{gap:12px;display:grid}.grant-editor[data-v-9850b6a3]{gap:8px;display:grid}@media (width<=767px){.app-grid[data-v-9850b6a3]{grid-template-columns:1fr}.bot-plugins button[data-v-9850b6a3],.bot-plugins .check-row[data-v-9850b6a3]{min-height:44px}}
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{A as e,F as t,G as n,H as r,L as i,M as a,Q as o,W as ee,_ as s,ct as c,d as l,et as u,g as d,h as te,i as f,m as p,o as ne,ot as re,p as ie,s as m,t as h,u as g,v as _,x as v,y}from"./_plugin-vue_export-helper-CscYwSBt.js";import{F as b,X as x}from"./index-CWamgtSb.js";import{t as S}from"./StandaloneDialog-D4BQqjpB.js";var ae={class:`bot-plugins`,"aria-label":`Bot 插件管理`},oe={class:`plugin-tabs`,role:`tablist`,"aria-label":`插件类型`},se=[`aria-selected`],ce=[`aria-selected`],le={key:0,class:`plugin-error`,role:`alert`},ue=[`disabled`],de={key:1,class:`plugin-notice`,role:`status`},fe={key:2,role:`status`},pe={class:`plugin-toolbar`},me=[`disabled`],he={key:0,class:`hint`},ge=[`value`],_e={key:0,class:`hint`},ve={class:`editor-actions`},ye=[`disabled`],be=[`disabled`],xe={key:2,class:`plugin-empty`},Se={class:`card-heading`},Ce={class:`hint endpoint`},we={class:`hint`},Te={key:0,class:`hint`},Ee={key:1,class:`hint`},De={class:`card-actions`},Oe=[`disabled`,`onClick`],ke=[`disabled`,`onClick`],Ae=[`disabled`,`onClick`],je=[`disabled`,`onClick`],Me=[`disabled`,`onClick`],Ne=[`value`,`disabled`],Pe={key:0,class:`hint`},Fe={class:`card-actions`},Ie=[`disabled`],Le=[`disabled`],Re={class:`plugin-toolbar`},ze={class:`view-tabs`,role:`tablist`,"aria-label":`应用列表`},Be=[`aria-selected`],Ve=[`aria-selected`],He=[`disabled`],Ue={class:`plugin-search`},We={key:0,class:`plugin-notice`},Ge={class:`app-grid`},Ke={class:`card-heading`},qe={class:`app-monogram`,"aria-hidden":`true`},Je={class:`hint`},Ye={key:0},Xe=[`disabled`,`aria-label`,`onClick`],Ze={key:0},Qe={class:`card-actions`},$e=[`disabled`,`onClick`],et=[`disabled`,`onClick`],tt=[`href`],nt={key:2,class:`hint`},rt=[`value`],it={class:`card-actions`},at=[`disabled`],ot=[`disabled`],st={key:2,class:`plugin-empty`},ct=[`open`],lt=[`placeholder`],ut={class:`card-actions`},dt=[`disabled`],ft=[`disabled`],pt=`/api/app/bot-tools`,C=h(v({__name:`BotPluginsPanel`,emits:[`dirty-change`],setup(ee,{emit:te}){let h=te,v=u(`apps`),S=u(`marketplace`),C=u({configured:!1,revision:0}),w=u(!1),T=u([]),mt=u([]),E=u([]),ht=u([]),D=u(!1),gt=u(!0),O=u(!1),k=u(``),A=u(``),j=u(``),M=u(``),N=u(`{}`),P=u(null),F=u(!1),I=u(``),L=u([]),R=u(``),z=u(``),B=u(``),V=u([]),_t=u(0),H=o({name:``,transport:`stdio`,command:`npx`,args:`[]`,url:``,env:`{}`,headers:`{}`,agentIds:[],revision:0}),U=u({}),W=u(40);r([j,S],()=>{W.value=40});let G=!1,vt=0,K,q=(e,t,n)=>b(pt+e,{method:t,...n===void 0?{}:{body:n}}),J=ie(()=>ht.value.filter(e=>!e.archived&&!e.remoteAgentId&&!e.temporaryGoalId)),Y=e=>e.filter(e=>J.value.some(t=>t.id===e)),X=ie(()=>{let e=new Map(mt.value.map(e=>[e.slug,e]));for(let t of E.value)e.has(t.slug)||e.set(t.slug,{slug:t.slug,name:t.slug,description:``});let t=j.value.trim().toLowerCase();return[...e.values()].filter(e=>(S.value!==`connected`||E.value.some(t=>t.slug===e.slug))&&`${e.name} ${e.slug} ${e.description}`.toLowerCase().includes(t))}),Z=e=>E.value.find(t=>t.slug===e),yt=e=>({ACTIVE:`已连接`,INITIATED:`待授权`,INITIALIZING:`连接中`,PENDING:`待授权`,EXPIRED:`已过期`,FAILED:`连接失败`,INACTIVE:`未启用`})[e.toUpperCase()]??e,bt=e=>D.value?e.map(e=>J.value.find(t=>t.id===e)?.name).filter(Boolean).join(`、`)||`尚未授权 Bot`:`Bot 授权暂不可读`;async function Q(){let e=++vt,t=await Promise.allSettled([b(`/api/app/bot-tools/settings`),b(`/api/app/bot-tools/mcp`),b(`/api/app/bot-tools/apps/catalog`),b(`/api/app/bot-tools/apps`),b(`/api/app/agents`)]);if(G||e!==vt)return;let[n,r,i,a,o]=t;n.status===`fulfilled`&&(C.value=n.value,w.value=n.value.canManageMcp),r.status===`fulfilled`&&(T.value=r.value.plugins),i.status===`fulfilled`&&(mt.value=i.value.cards),a.status===`fulfilled`&&a.value.authoritative&&(E.value=a.value.connections),D.value=o.status===`fulfilled`,o.status===`fulfilled`&&(ht.value=o.value.agents),k.value=t.filter(e=>e.status===`rejected`).map(e=>e.reason instanceof Error?e.reason.message:`读取失败,请重试`).join(`;`),gt.value=!1}async function $(e){if(!O.value){O.value=!0,k.value=``,A.value=``;try{await e(),G||await Q()}catch(e){G||(k.value=e instanceof Error?e.message:`操作失败,请重试`)}finally{O.value=!1}}}function xt(e){B.value=``,P.value=e?.id??null,Object.assign(H,{name:e?.name??``,transport:e?.transport??`stdio`,command:e?.command??`npx`,args:JSON.stringify(e?.args??[],null,2),url:e?.url??``,env:JSON.stringify(Object.fromEntries((e?.envKeys??[]).map(e=>[e,!0])),null,2),headers:JSON.stringify(Object.fromEntries((e?.headerKeys??[]).map(e=>[e,!0])),null,2),agentIds:Y(e?.agentIds??[]),revision:e?.revision??0}),F.value=!0,h(`dirty-change`,!1)}function St(){F.value=!1,h(`dirty-change`,!1)}async function Ct(){await $(async()=>{let e,t,n;try{e=JSON.parse(H.args),t=JSON.parse(H.env),n=JSON.parse(H.headers)}catch{throw Error(`参数、环境变量和请求头必须是有效 JSON`)}let r={name:H.name,transport:H.transport,command:H.command,args:e,url:H.url,env:t,headers:n,agentIds:H.agentIds};await q(P.value?`/mcp/`+P.value:`/mcp`,P.value?`PUT`:`POST`,P.value?{definition:r,revision:H.revision}:r),St(),A.value=`已保存。测试连接成功后即可启用。`})}async function wt(e){await $(async()=>{let t=await q(`/mcp/`+e.id+`/test`,`POST`,{});A.value=`服务器连接成功,发现 ${t.plugin.toolCount} 个工具。服务登录状态需另行确认。`})}async function Tt(e){await $(async()=>{await q(`/mcp/`+e.id,`PATCH`,{enabled:!e.enabled,revision:e.revision})})}async function Et(e){window.confirm(`移除插件“${e.name}”?此插件将不再提供给 Bot。`)&&await $(async()=>{await q(`/mcp/`+e.id,`DELETE`),B.value===e.id&&Ot()})}function Dt(e){St(),B.value=e.id,V.value=Y(e.agentIds),_t.value=e.revision}function Ot(){B.value=``,h(`dirty-change`,!1)}async function kt(){await $(async()=>{await q(`/mcp/`+B.value,`PATCH`,{agentIds:V.value,revision:_t.value}),Ot(),A.value=`Bot 授权已保存,将用于下一轮对话。`})}async function At(e=!1){e&&!window.confirm(`清除当前账号的应用连接服务配置?Bot 将暂时无法使用这些应用。`)||await $(async()=>{let t;try{t=JSON.parse(N.value)}catch{throw Error(`Auth Config 映射必须是有效 JSON`)}await q(`/settings`,`PUT`,{apiKey:e?``:M.value,revision:C.value.revision,authConfigs:t}),M.value=``,N.value=`{}`,h(`dirty-change`,!1),A.value=e?`已清除连接服务配置。`:`应用连接服务已配置。`})}async function jt(e){if(O.value)return;if(Z(e.slug)?.accounts.length&&R.value!==e.slug){R.value=e.slug,z.value=``;return}let t=window.open(`about:blank`,`_blank`);t&&(t.opener=null);let n=new Set(Z(e.slug)?.accounts.map(e=>e.id)??[]);await $(async()=>{try{let r=await q(`/apps/`+e.slug+`/authorize`,`POST`,z.value.trim()&&R.value===e.slug?{alias:z.value.trim()}:{});U.value[e.slug]=r.url,t&&(t.location.href=r.url),R.value=``,z.value=``,A.value=`请在新窗口完成授权,然后刷新连接状态。`,clearTimeout(K);let i=0,a=async()=>{G||(await Q(),Z(e.slug)?.accounts.some(e=>!n.has(e.id)&&e.status.toUpperCase()===`ACTIVE`)?(delete U.value[e.slug],A.value=`${e.name} 已连接。`):!G&&++i<24&&(K=setTimeout(a,5e3)))};K=setTimeout(a,5e3)}catch(e){throw t?.close(),e}})}async function Mt(e,t){window.confirm(`断开这个应用账号?其他账号的连接会保留。`)&&await $(async()=>{await q(`/apps/`+e+`/accounts/`+encodeURIComponent(t),`DELETE`),delete U.value[e]})}function Nt(e){I.value=e,L.value=[...Z(e)?.agentIds??[]]}async function Pt(){await $(async()=>{await q(`/apps/`+I.value+`/agents`,`PUT`,{agentIds:L.value,revision:Z(I.value)?.revision??0}),I.value=``,h(`dirty-change`,!1)})}return a(Q),e(()=>{G=!0,vt++,clearTimeout(K)}),(e,r)=>(t(),s(`section`,ae,[r[55]||=p(`p`,{class:`intro`},`为 Bot 连接应用和工具,按需选择可使用它们的机器人。`,-1),p(`div`,oe,[p(`button`,{type:`button`,role:`tab`,"aria-selected":v.value===`apps`,onClick:r[0]||=e=>v.value=`apps`},[y(x,{name:`link`,size:17}),r[28]||=_(`应用`,-1)],8,se),p(`button`,{type:`button`,role:`tab`,"aria-selected":v.value===`mcp`,onClick:r[1]||=e=>v.value=`mcp`},[y(x,{name:`tools`,size:17}),r[29]||=_(`MCP 服务`,-1)],8,ce)]),k.value?(t(),s(`p`,le,[_(c(k.value)+` `,1),p(`button`,{type:`button`,disabled:O.value,onClick:Q},`重试`,8,ue)])):d(``,!0),A.value?(t(),s(`p`,de,c(A.value),1)):d(``,!0),gt.value?(t(),s(`p`,fe,`正在读取插件…`)):v.value===`mcp`?(t(),s(l,{key:3},[p(`div`,pe,[r[31]||=p(`p`,null,`自定义 MCP 服务`,-1),p(`button`,{disabled:!w.value||O.value||!D.value,onClick:r[2]||=e=>xt()},[y(x,{name:`plus`,size:16}),r[30]||=_(`添加服务`,-1)],8,me)]),r[45]||=p(`p`,{class:`hint`},`stdio 程序及其路径在当前连接的夭夭服务器上运行和读取;HTTP / HTTPS 地址也由服务器连接。客户端通过服务器使用已授权的工具,无需安装 MCP 程序。`,-1),w.value?d(``,!0):(t(),s(`p`,he,`自定义 MCP 服务由管理员管理。`)),F.value?(t(),s(`form`,{key:1,class:`plugin-editor`,"aria-label":`MCP 服务配置`,onSubmit:g(Ct,[`prevent`]),onInput:r[11]||=e=>h(`dirty-change`,!0),onChange:r[12]||=e=>h(`dirty-change`,!0)},[p(`h4`,null,c(P.value?`编辑 MCP 服务`:`添加 MCP 服务`),1),p(`label`,null,[r[32]||=_(`名称`,-1),n(p(`input`,{"onUpdate:modelValue":r[3]||=e=>H.name=e,required:``,maxlength:`80`},null,512),[[m,H.name]])]),p(`label`,null,[r[34]||=_(`连接方式`,-1),n(p(`select`,{"onUpdate:modelValue":r[4]||=e=>H.transport=e},[...r[33]||=[p(`option`,{value:`stdio`},`服务器程序(stdio)`,-1),p(`option`,{value:`http`},`远程地址(HTTP / HTTPS)`,-1)]],512),[[ne,H.transport]])]),H.transport===`stdio`?(t(),s(l,{key:0},[p(`label`,null,[r[35]||=_(`服务器程序`,-1),n(p(`input`,{"onUpdate:modelValue":r[5]||=e=>H.command=e,required:``,placeholder:`服务器上的 npx 或程序完整路径`},null,512),[[m,H.command]])]),p(`label`,null,[r[36]||=_(`参数(JSON 数组)`,-1),n(p(`textarea`,{"onUpdate:modelValue":r[6]||=e=>H.args=e,rows:`3`,spellcheck:`false`},null,512),[[m,H.args]])]),p(`label`,null,[r[37]||=_(`环境变量(JSON)`,-1),n(p(`textarea`,{"onUpdate:modelValue":r[7]||=e=>H.env=e,rows:`3`,spellcheck:`false`,autocomplete:`off`},null,512),[[m,H.env]])]),r[38]||=p(`p`,{class:`hint`},`程序和参数中的文件路径须在服务器上可用。所需账号配置和环境变量也须提供给服务器上的 MCP 进程。`,-1)],64)):(t(),s(l,{key:1},[p(`label`,null,[r[39]||=_(`MCP 地址`,-1),n(p(`input`,{"onUpdate:modelValue":r[8]||=e=>H.url=e,type:`url`,required:``,placeholder:`https://example.com/mcp`},null,512),[[m,H.url]])]),p(`label`,null,[r[40]||=_(`请求头(JSON)`,-1),n(p(`textarea`,{"onUpdate:modelValue":r[9]||=e=>H.headers=e,rows:`3`,spellcheck:`false`,autocomplete:`off`},null,512),[[m,H.headers]])])],64)),r[42]||=p(`p`,{class:`hint`},`凭据请放在环境变量或请求头中。已保存的值用 true 表示保留,不会回显。`,-1),p(`fieldset`,null,[r[41]||=p(`legend`,null,`允许使用的 Bot`,-1),(t(!0),s(l,null,i(J.value,e=>(t(),s(`label`,{key:e.id,class:`check-row`},[n(p(`input`,{"onUpdate:modelValue":r[10]||=e=>H.agentIds=e,type:`checkbox`,value:e.id},null,8,ge),[[f,H.agentIds]]),_(c(e.name),1)]))),128)),J.value.length?d(``,!0):(t(),s(`p`,_e,`创建 Bot 后可在这里授权。`))]),p(`div`,ve,[p(`button`,{type:`button`,disabled:O.value,onClick:St},`取消`,8,ye),p(`button`,{type:`submit`,class:`primary`,disabled:O.value||!D.value},c(O.value?`保存中…`:`保存服务`),9,be)])],32)):d(``,!0),!T.value.length&&!F.value?(t(),s(`p`,xe,`还没有 MCP 服务。添加服务并测试连接后,即可授权 Bot 使用。`)):d(``,!0),(t(!0),s(l,null,i(T.value,e=>(t(),s(`article`,{key:e.id,class:`mcp-card`},[p(`div`,Se,[y(x,{name:`tools`,size:20}),p(`h4`,null,c(e.name),1),p(`span`,{class:re([`badge`,{enabled:e.enabled}])},c(e.enabled?`已启用`:`未启用`),3)]),p(`p`,Ce,c(e.transport===`stdio`?e.command:e.url),1),p(`p`,we,c(e.transport===`stdio`?`运行于夭夭服务器`:`由夭夭服务器连接`)+` · `+c(e.testedAt?`已发现 ${e.toolCount} 个工具`:`尚未测试连接`)+` · `+c(bt(e.agentIds)),1),D.value&&Y(e.agentIds).length!==e.agentIds.length?(t(),s(`p`,Te,`部分 Bot 授权已失效,请重新选择可使用此服务的 Bot。`)):d(``,!0),D.value&&e.enabled&&!Y(e.agentIds).length?(t(),s(`p`,Ee,`服务已启用,尚无可使用它的 Bot。请先授权 Bot。`)):d(``,!0),p(`div`,De,[p(`button`,{disabled:O.value||!w.value,onClick:t=>wt(e)},`测试连接`,8,Oe),p(`button`,{disabled:O.value||!w.value||!e.enabled&&!e.testedAt,onClick:t=>Tt(e)},c(e.enabled?`停用`:`启用`),9,ke),p(`button`,{disabled:O.value||!w.value||!D.value,onClick:t=>Dt(e)},`授权 Bot`,8,Ae),p(`button`,{disabled:O.value||!w.value||!D.value,onClick:t=>xt(e)},`编辑`,8,je),p(`button`,{class:`danger`,disabled:O.value||!w.value,onClick:t=>Et(e)},`移除`,8,Me)]),B.value===e.id?(t(),s(`form`,{key:2,class:`grant-editor`,"aria-label":`MCP Bot 授权`,onSubmit:g(kt,[`prevent`]),onChange:r[14]||=e=>h(`dirty-change`,!0)},[p(`fieldset`,null,[r[43]||=p(`legend`,null,`允许使用的 Bot`,-1),(t(!0),s(l,null,i(J.value,e=>(t(),s(`label`,{key:e.id,class:`check-row`},[n(p(`input`,{"onUpdate:modelValue":r[13]||=e=>V.value=e,type:`checkbox`,value:e.id,disabled:O.value},null,8,Ne),[[f,V.value]]),_(c(e.name),1)]))),128)),J.value.length?d(``,!0):(t(),s(`p`,Pe,`创建 Bot 后可在这里授权。`))]),r[44]||=p(`p`,{class:`hint`},`授权按 Bot 保存,同一账号在各客户端均可使用。更改授权后,连接验证结果和服务启用状态会保留。`,-1),p(`div`,Fe,[p(`button`,{type:`button`,disabled:O.value,onClick:Ot},`取消`,8,Ie),p(`button`,{type:`submit`,disabled:O.value||!w.value||!D.value},`保存授权`,8,Le)])],32)):d(``,!0)]))),128))],64)):gt.value?d(``,!0):(t(),s(l,{key:4},[p(`div`,Re,[p(`div`,ze,[p(`button`,{role:`tab`,"aria-selected":S.value===`marketplace`,onClick:r[15]||=e=>S.value=`marketplace`},`应用目录`,8,Be),p(`button`,{role:`tab`,"aria-selected":S.value===`connected`,onClick:r[16]||=e=>S.value=`connected`},`已连接 `+c(E.value.length||``),9,Ve)]),p(`button`,{disabled:O.value,"aria-label":`刷新应用连接`,onClick:Q},[y(x,{name:`refresh`,size:17})],8,He)]),p(`label`,Ue,[y(x,{name:`search`,size:17}),n(p(`input`,{"onUpdate:modelValue":r[17]||=e=>j.value=e,type:`search`,"aria-label":`搜索应用`,placeholder:`搜索应用`},null,512),[[m,j.value]])]),C.value.configured?d(``,!0):(t(),s(`p`,We,`配置 Composio 连接服务后,即可连接应用。`)),p(`div`,Ge,[(t(!0),s(l,null,i(X.value.slice(0,W.value),e=>(t(),s(`article`,{key:e.slug,class:`app-card`},[p(`div`,Ke,[p(`span`,qe,c(e.name.slice(0,1)),1),p(`h4`,null,c(e.name),1)]),p(`p`,Je,c(e.description),1),(t(!0),s(l,null,i(Z(e.slug)?.accounts??[],n=>(t(),s(`div`,{key:n.id,class:`app-account`},[p(`span`,null,[_(c(n.alias||yt(n.status)),1),n.alias?(t(),s(`small`,Ye,c(yt(n.status)),1)):d(``,!0)]),p(`button`,{class:`danger`,disabled:O.value,"aria-label":`断开 ${e.name} ${n.alias||`账号`}`,onClick:t=>Mt(e.slug,n.id)},`断开`,8,Xe)]))),128)),R.value===e.slug?(t(),s(`label`,Ze,[r[46]||=_(`账号别名`,-1),n(p(`input`,{"onUpdate:modelValue":r[18]||=e=>z.value=e,placeholder:`例如:工作账号`,maxlength:`64`},null,512),[[m,z.value]])])):d(``,!0),p(`div`,Qe,[p(`button`,{disabled:O.value||!C.value.configured||R.value===e.slug&&!z.value.trim(),onClick:t=>jt(e)},c(R.value===e.slug?`继续连接`:Z(e.slug)?.accounts.length?`添加账号`:`连接`),9,$e),Z(e.slug)?.accounts.length?(t(),s(`button`,{key:0,disabled:O.value,onClick:t=>Nt(e.slug)},`授权 Bot`,8,et)):d(``,!0)]),U.value[e.slug]?(t(),s(`a`,{key:1,href:U.value[e.slug],target:`_blank`,rel:`noopener noreferrer`},[r[47]||=_(`继续授权 `,-1),y(x,{name:`external`,size:13})],8,tt)):d(``,!0),Z(e.slug)?(t(),s(`p`,nt,c(bt(Z(e.slug).agentIds)),1)):d(``,!0),I.value===e.slug?(t(),s(`form`,{key:3,class:`grant-editor`,onSubmit:g(Pt,[`prevent`]),onChange:r[21]||=e=>h(`dirty-change`,!0)},[p(`fieldset`,null,[r[48]||=p(`legend`,null,`允许使用的 Bot`,-1),(t(!0),s(l,null,i(J.value,e=>(t(),s(`label`,{key:e.id,class:`check-row`},[n(p(`input`,{"onUpdate:modelValue":r[19]||=e=>L.value=e,type:`checkbox`,value:e.id},null,8,rt),[[f,L.value]]),_(c(e.name),1)]))),128))]),p(`div`,it,[p(`button`,{type:`button`,disabled:O.value,onClick:r[20]||=e=>{I.value=``,h(`dirty-change`,!1)}},`取消`,8,at),p(`button`,{type:`submit`,disabled:O.value},`保存授权`,8,ot)])],32)):d(``,!0)]))),128))]),X.value.length>W.value?(t(),s(`button`,{key:1,type:`button`,onClick:r[22]||=e=>W.value+=40},`显示更多应用(`+c(X.value.length-W.value)+`)`,1)):d(``,!0),X.value.length?d(``,!0):(t(),s(`p`,st,c(j.value?`没有匹配的应用。`:`还没有已连接的应用。可前往应用目录添加。`),1)),p(`details`,{class:`connection-settings`,open:!C.value.configured},[p(`summary`,null,[r[49]||=_(`应用连接服务 `,-1),p(`span`,null,c(C.value.configured?`已配置`:`未配置`),1)]),r[54]||=p(`p`,{class:`hint`},`使用你的 Composio 项目连接应用。密钥加密保存在服务器,仅用于当前账号。`,-1),p(`form`,{onSubmit:r[26]||=g(e=>At(),[`prevent`]),onInput:r[27]||=e=>h(`dirty-change`,!0)},[p(`label`,null,[r[50]||=_(`Composio API Key`,-1),n(p(`input`,{"onUpdate:modelValue":r[23]||=e=>M.value=e,type:`password`,autocomplete:`new-password`,placeholder:C.value.configured?`已保存,输入新密钥可替换`:`ak_…`},null,8,lt),[[m,M.value]])]),p(`details`,null,[r[52]||=p(`summary`,null,`自定义 Auth Config(可选)`,-1),p(`label`,null,[r[51]||=_(`应用与 Auth Config 映射(JSON)`,-1),n(p(`textarea`,{"onUpdate:modelValue":r[24]||=e=>N.value=e,rows:`3`,spellcheck:`false`},null,512),[[m,N.value]])])]),p(`div`,ut,[p(`button`,{type:`submit`,disabled:O.value||!M.value.trim()},`保存连接服务`,8,dt),C.value.configured?(t(),s(`button`,{key:0,type:`button`,class:`danger`,disabled:O.value,onClick:r[25]||=e=>At(!0)},`清除配置`,8,ft)):d(``,!0),r[53]||=p(`a`,{href:`https://dashboard.composio.dev`,target:`_blank`,rel:`noopener noreferrer`},`获取 API Key`,-1)])],32)],8,ct)],64))]))}}),[[`__scopeId`,`data-v-9850b6a3`]]),w=v({__name:`BotPluginsDialog`,emits:[`close`],setup(e,{emit:n}){let r=n,i=u(!1),a=()=>!i.value||window.confirm(`放弃尚未保存的插件更改?`);return(e,n)=>(t(),te(S,{title:`已连接应用`,"before-close":a,onClose:n[1]||=e=>r(`close`)},{default:ee(()=>[y(C,{onDirtyChange:n[0]||=e=>i.value=e})]),_:1}))}});export{w as default};
|
|
2
|
-
//# sourceMappingURL=BotPluginsDialog-H85RI-7P.js.map
|