@lsamien/yaoyao 0.4.76 → 0.4.78
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 +7 -5
- package/THIRD_PARTY_NOTICES.md +8 -0
- package/bin/hermes-yaoyao.mjs +15 -2
- package/build-info.json +35 -3
- package/desktop/main.mjs +12 -4
- package/dist/assets/{AboutDialog-fbm5CG09.js → AboutDialog-jvhTP8-J.js} +2 -2
- package/dist/assets/AboutDialog-jvhTP8-J.js.map +1 -0
- package/dist/assets/BotAutomationsView-ktoci79V.js +2 -0
- package/dist/assets/{BotAutomationsView-DPAAYyuy.js.map → BotAutomationsView-ktoci79V.js.map} +1 -1
- package/dist/assets/{BotPluginsDialog-MwGpwjgu.js → BotPluginsDialog-H85RI-7P.js} +2 -2
- package/dist/assets/{BotPluginsDialog-MwGpwjgu.js.map → BotPluginsDialog-H85RI-7P.js.map} +1 -1
- package/dist/assets/{BotSettingsDialog-DXtsSzi8.js → BotSettingsDialog-Ci_DZL4m.js} +5 -5
- package/dist/assets/{BotSettingsDialog-DXtsSzi8.js.map → BotSettingsDialog-Ci_DZL4m.js.map} +1 -1
- package/dist/assets/ChatView-6cdLMsuy.js +2 -0
- package/dist/assets/ChatView-6cdLMsuy.js.map +1 -0
- package/dist/assets/ChatView-C_7_7olu.css +1 -0
- package/dist/assets/{ComputerPanel-B0QyKQkF.js → ComputerPanel-Dbwgx5n8.js} +2 -2
- package/dist/assets/{ComputerPanel-B0QyKQkF.js.map → ComputerPanel-Dbwgx5n8.js.map} +1 -1
- package/dist/assets/{ComputerViewerView-CaOkTXpc.js → ComputerViewerView-csnhRedK.js} +2 -2
- package/dist/assets/{ComputerViewerView-CaOkTXpc.js.map → ComputerViewerView-csnhRedK.js.map} +1 -1
- package/dist/assets/ConversationsView-CEO2SVGT.js +6 -0
- package/dist/assets/ConversationsView-CEO2SVGT.js.map +1 -0
- package/dist/assets/{ConversationsView-C_VZl5g2.css → ConversationsView-CHLGKsJt.css} +1 -1
- package/dist/assets/FilesView-t5jA-H2-.js +2 -0
- package/dist/assets/{FilesView-CluNyIk8.js.map → FilesView-t5jA-H2-.js.map} +1 -1
- package/dist/assets/FloatingResourceSearch-3GOuDkuO.css +1 -0
- package/dist/assets/FloatingResourceSearch-BAYymuJV.js +9 -0
- package/dist/assets/FloatingResourceSearch-BAYymuJV.js.map +1 -0
- package/dist/assets/HistoryView-BqMSV9iC.js +2 -0
- package/dist/assets/HistoryView-BqMSV9iC.js.map +1 -0
- package/dist/assets/HistoryView-DlVfSP_p.css +1 -0
- package/dist/assets/KanbanView-CWwrwH9S.js +2 -0
- package/dist/assets/{KanbanView-D5AdRwqi.js.map → KanbanView-CWwrwH9S.js.map} +1 -1
- package/dist/assets/{LocalVmSettingsPanel-BILcGHmu.js → LocalVmSettingsPanel-BXvZwFQP.js} +2 -2
- package/dist/assets/{LocalVmSettingsPanel-BILcGHmu.js.map → LocalVmSettingsPanel-BXvZwFQP.js.map} +1 -1
- package/dist/assets/{RunnerSettingsPanel-IHLAFIh8.js → RunnerSettingsPanel-KkpIkkob.js} +2 -2
- package/dist/assets/{RunnerSettingsPanel-IHLAFIh8.js.map → RunnerSettingsPanel-KkpIkkob.js.map} +1 -1
- package/dist/assets/{StandaloneDialog-DdcL_wV2.js → StandaloneDialog-D4BQqjpB.js} +2 -2
- package/dist/assets/{StandaloneDialog-DdcL_wV2.js.map → StandaloneDialog-D4BQqjpB.js.map} +1 -1
- package/dist/assets/{UpdateCheckDialog-CJQezkXo.js → UpdateCheckDialog-Ct0bT6xU.js} +2 -2
- package/dist/assets/{UpdateCheckDialog-CJQezkXo.js.map → UpdateCheckDialog-Ct0bT6xU.js.map} +1 -1
- package/dist/assets/{WorkspaceKnowledgePanel-DS0kOQgg.js → WorkspaceKnowledgePanel-WBcPB49x.js} +2 -2
- package/dist/assets/{WorkspaceKnowledgePanel-DS0kOQgg.js.map → WorkspaceKnowledgePanel-WBcPB49x.js.map} +1 -1
- package/dist/assets/{WorkspaceRoutinesPanel-DpVAtnDX.js → WorkspaceRoutinesPanel-JubUwGsV.js} +2 -2
- package/dist/assets/{WorkspaceRoutinesPanel-DpVAtnDX.js.map → WorkspaceRoutinesPanel-JubUwGsV.js.map} +1 -1
- package/dist/assets/WorkspaceShell-0m4gg6AW.css +1 -0
- package/dist/assets/WorkspaceShell-Do2VAwIz.js +44 -0
- package/dist/assets/WorkspaceShell-Do2VAwIz.js.map +1 -0
- package/dist/assets/{WorkspaceView-Cco3Umfn.js → WorkspaceView-DTanioWW.js} +2 -2
- package/dist/assets/{WorkspaceView-Cco3Umfn.js.map → WorkspaceView-DTanioWW.js.map} +1 -1
- package/dist/assets/{docx-preview-C6qrP-g2.js → docx-preview-B1SjJgD_.js} +2 -2
- package/dist/assets/{docx-preview-C6qrP-g2.js.map → docx-preview-B1SjJgD_.js.map} +1 -1
- package/dist/assets/index-CWamgtSb.js +17 -0
- package/dist/assets/index-CWamgtSb.js.map +1 -0
- package/dist/assets/{pdf-G3DUsfMb.js → pdf-DVDddcFC.js} +2 -2
- package/dist/assets/{pdf-G3DUsfMb.js.map → pdf-DVDddcFC.js.map} +1 -1
- package/dist/assets/sessionOwnership-0hdKcwOs.js +4 -0
- package/dist/assets/sessionOwnership-0hdKcwOs.js.map +1 -0
- package/dist/assets/{sessionOwnership-BTz0Fyp5.css → sessionOwnership-CfO8CfmZ.css} +1 -1
- package/dist/assets/{viewModels-DfaKvI0x.js → viewModels-DKBqaDRg.js} +12 -12
- package/dist/assets/{viewModels-DfaKvI0x.js.map → viewModels-DKBqaDRg.js.map} +1 -1
- package/dist/index.html +1 -1
- package/dist-server/runner/agent.js +15 -4
- package/dist-server/runner/hermes-bots-bridge/README.md +4 -2
- package/dist-server/runner/hermes-bots-bridge/bridge_runtime.py +21 -2
- package/dist-server/runner/hermes-bots-bridge/plugin.yaml +1 -1
- package/dist-server/runner/worker/gateway.js +52 -22
- package/dist-server/runner/worker/profileSession.js +2 -12
- package/dist-server/server/app.js +15 -1
- package/dist-server/server/chatTranscriptApi.js +2 -2
- package/dist-server/server/chatTranscriptStore.js +16 -0
- package/dist-server/server/config.js +3 -0
- package/dist-server/server/credentialVault/broker.js +272 -0
- package/dist-server/server/credentialVault/coordinator.js +297 -0
- package/dist-server/server/credentialVault/executor.js +1 -0
- package/dist-server/server/credentialVault/fixtureWebsiteExecutor.js +51 -0
- package/dist-server/server/credentialVault/index.js +49 -0
- package/dist-server/server/credentialVault/isolation.js +37 -0
- package/dist-server/server/credentialVault/privateFiles.js +17 -0
- package/dist-server/server/credentialVault/protectedExecutor.js +21 -0
- package/dist-server/server/credentialVault/schema.js +45 -0
- package/dist-server/server/credentialVault/sshExecutor.js +135 -0
- package/dist-server/server/credentialVault/store.js +308 -0
- package/dist-server/server/credentialVault/transport.js +127 -0
- package/dist-server/server/credentialVault/websiteExecutor.js +102 -0
- package/dist-server/server/desktopEnvironments.js +2 -2
- package/dist-server/server/hermesRuntimeEnvironment.js +14 -0
- package/dist-server/server/localAuth.js +5 -0
- package/dist-server/server/openVikingMemoryProvider.js +29 -10
- package/dist-server/server/openVikingService.js +44 -14
- package/dist-server/server/openVikingSessionSync.js +148 -37
- package/dist-server/server/pushCoordinator.js +7 -4
- package/dist-server/server/realtimeApi.js +11 -2
- package/dist-server/server/realtimeBroker.js +1 -1
- package/dist-server/server/realtimeReceipts.js +39 -8
- package/dist-server/server/routes.js +18 -0
- package/dist-server/server/runnerHub.js +17 -4
- package/dist-server/server/sessionStop.js +19 -0
- package/dist-server/server/subaccountAccess.js +12 -0
- package/dist-server/server/taskCoordinator.js +3 -1
- package/dist-server/server/unreadCenter.js +61 -0
- package/dist-server/server/uploads.js +4 -1
- package/dist-server/server/workspaceAssets.js +56 -12
- package/dist-server/server/workspaceEnvironment.js +1 -0
- package/dist-server/server/workspaceMemorySynthesis.js +5 -1
- package/dist-server/server/workspacePrompt.js +5 -1
- package/dist-server/server/workspaceRoutes.js +26 -21
- package/dist-server/server/workspaceRuntime.js +89 -8
- package/dist-server/server/workspaceScheduler.js +5 -1
- package/dist-server/server/workspaceStore.js +125 -47
- package/dist-server/server/workspaceSync.js +4 -1
- package/dist-server/shared/botEnvironment.js +3 -3
- package/dist-server/shared/credentialVault.js +2 -0
- package/dist-server/shared/unread.js +6 -0
- package/dist-server/shared/uploadNames.js +14 -0
- package/licenses/libsodium.js/LICENSE +16 -0
- package/licenses/ssh2/LICENSE +19 -0
- package/package.json +8 -5
- package/release.json +3 -3
- package/dist/assets/AboutDialog-fbm5CG09.js.map +0 -1
- package/dist/assets/BotAutomationsView-DPAAYyuy.js +0 -2
- package/dist/assets/ChatView-BNqHa6Ma.js +0 -2
- package/dist/assets/ChatView-BNqHa6Ma.js.map +0 -1
- package/dist/assets/ChatView-Dx8YlcPr.css +0 -1
- package/dist/assets/ConversationsView-CYNc59hv.js +0 -6
- package/dist/assets/ConversationsView-CYNc59hv.js.map +0 -1
- package/dist/assets/FilesView-CluNyIk8.js +0 -2
- package/dist/assets/FloatingResourceSearch-BF2XOLd-.css +0 -1
- package/dist/assets/FloatingResourceSearch-Bg5rUZMy.js +0 -9
- package/dist/assets/FloatingResourceSearch-Bg5rUZMy.js.map +0 -1
- package/dist/assets/HistoryView-DSbSDzsB.js +0 -2
- package/dist/assets/HistoryView-DSbSDzsB.js.map +0 -1
- package/dist/assets/HistoryView-DvuCAjlo.css +0 -1
- package/dist/assets/KanbanView-D5AdRwqi.js +0 -2
- package/dist/assets/WorkspaceShell-7wn8iTne.css +0 -1
- package/dist/assets/WorkspaceShell-Bykfy3AR.js +0 -44
- package/dist/assets/WorkspaceShell-Bykfy3AR.js.map +0 -1
- package/dist/assets/index-CEqMqiJr.js +0 -17
- package/dist/assets/index-CEqMqiJr.js.map +0 -1
- package/dist/assets/sessionOwnership-DMfBRINe.js +0 -6
- package/dist/assets/sessionOwnership-DMfBRINe.js.map +0 -1
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { createServer, request } from 'node:http';
|
|
2
|
+
import { createHash, timingSafeEqual, randomUUID } from 'node:crypto';
|
|
3
|
+
import { lstatSync } from 'node:fs';
|
|
4
|
+
import { isAbsolute } from 'node:path';
|
|
5
|
+
import { z } from 'zod';
|
|
6
|
+
import { parse } from './schema.js';
|
|
7
|
+
import { HttpError } from '../errors.js';
|
|
8
|
+
import { readPrivateUtf8 } from './privateFiles.js';
|
|
9
|
+
const MAX_BYTES = 3 * 1024 * 1024;
|
|
10
|
+
export function serveCredentialVault(broker, token) {
|
|
11
|
+
if (token.length < 32)
|
|
12
|
+
throw new Error('密码库控制凭据格式无效');
|
|
13
|
+
const expected = createHash('sha256').update(token).digest();
|
|
14
|
+
const server = createServer((req, res) => {
|
|
15
|
+
void (async () => {
|
|
16
|
+
res.setHeader('Cache-Control', 'no-store');
|
|
17
|
+
if (req.method !== 'POST' || req.url !== '/v1' || req.headers.origin)
|
|
18
|
+
throw new HttpError(403, '密码库只接受私有控制请求', 'vault_control_forbidden');
|
|
19
|
+
const received = createHash('sha256').update(String(req.headers.authorization ?? '').replace(/^Bearer /, '')).digest();
|
|
20
|
+
if (!req.headers.authorization?.startsWith('Bearer ') || !timingSafeEqual(expected, received))
|
|
21
|
+
throw new HttpError(403, '密码库控制授权无效', 'vault_control_forbidden');
|
|
22
|
+
const chunks = [];
|
|
23
|
+
let size = 0;
|
|
24
|
+
for await (const chunk of req) {
|
|
25
|
+
size += chunk.length;
|
|
26
|
+
if (size > MAX_BYTES)
|
|
27
|
+
throw new HttpError(413, '密码库请求过大', 'vault_size_limit');
|
|
28
|
+
chunks.push(Buffer.from(chunk));
|
|
29
|
+
}
|
|
30
|
+
const body = parse(z.object({ epoch: z.string().uuid(), owner: z.string().min(1).max(256), session: z.string().regex(/^[a-f0-9]{64}$/),
|
|
31
|
+
command: z.string().max(64), value: z.unknown().optional() }).strict(), JSON.parse(Buffer.concat(chunks).toString('utf8')));
|
|
32
|
+
const result = body.command === 'hello' ? broker.hello(body.epoch) : body.command === 'execute'
|
|
33
|
+
? await (() => { const v = parse(z.object({ id: z.string().uuid(), input: z.unknown() }).strict(), body.value); res.once('close', () => { if (!res.writableEnded)
|
|
34
|
+
broker.connectionClosed(body.owner, body.session, v.id); }); return broker.execute(body.epoch, body.owner, body.session, v.id, v.input); })()
|
|
35
|
+
: broker.dispatch(body.epoch, body.owner, body.session, body.command, body.value);
|
|
36
|
+
res.setHeader('Content-Type', 'application/json');
|
|
37
|
+
res.end(JSON.stringify({ result }));
|
|
38
|
+
})().catch(error => {
|
|
39
|
+
// Never forward parser, sodium, filesystem or executor exception messages.
|
|
40
|
+
res.statusCode = error instanceof HttpError ? error.status : 400;
|
|
41
|
+
res.setHeader('Content-Type', 'application/json');
|
|
42
|
+
res.end(JSON.stringify({ error: error instanceof HttpError ? error.message : '密码库请求失败', code: error instanceof HttpError ? error.code : 'vault_request_failed' }));
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
server.requestTimeout = 15000;
|
|
46
|
+
server.headersTimeout = 10000;
|
|
47
|
+
server.keepAliveTimeout = 1000;
|
|
48
|
+
server.on('close', () => broker.close());
|
|
49
|
+
server.on('clientError', (_e, socket) => socket.destroy());
|
|
50
|
+
return server;
|
|
51
|
+
}
|
|
52
|
+
/** Private IPC; no global fetch proxy, environment/argv secret or general Runner payload. */
|
|
53
|
+
export class CredentialVaultClient {
|
|
54
|
+
config;
|
|
55
|
+
epoch = randomUUID();
|
|
56
|
+
hello;
|
|
57
|
+
onDisconnect = () => { };
|
|
58
|
+
constructor(config) {
|
|
59
|
+
this.config = config;
|
|
60
|
+
}
|
|
61
|
+
get configured() { return !!this.config; }
|
|
62
|
+
async send(owner, session, command, value) {
|
|
63
|
+
const c = this.config;
|
|
64
|
+
if (!c)
|
|
65
|
+
throw new HttpError(503, '执行节点密码库尚未连接', 'vault_offline');
|
|
66
|
+
if (!process.getuid || process.getuid() === 0 || !Number.isSafeInteger(c.hermesUid) || c.hermesUid < 1 || process.getuid() === c.hermesUid)
|
|
67
|
+
throw new HttpError(503, '密码库控制面需要与 Hermes 分离的非 root OS 身份', 'vault_offline');
|
|
68
|
+
if (!isAbsolute(c.socket) || !isAbsolute(c.tokenFile))
|
|
69
|
+
throw new HttpError(503, '密码库控制配置无效', 'vault_offline');
|
|
70
|
+
let token;
|
|
71
|
+
try {
|
|
72
|
+
const socket = lstatSync(c.socket);
|
|
73
|
+
if (!socket.isSocket() || (socket.mode & 0o077) || socket.uid !== process.getuid?.())
|
|
74
|
+
throw new Error();
|
|
75
|
+
token = readPrivateUtf8(c.tokenFile, 4096).trim();
|
|
76
|
+
if (token.length < 32)
|
|
77
|
+
throw new Error();
|
|
78
|
+
}
|
|
79
|
+
catch {
|
|
80
|
+
throw new HttpError(503, '密码库私有连接不可用,请检查部署', 'vault_offline');
|
|
81
|
+
}
|
|
82
|
+
return new Promise((done, reject) => {
|
|
83
|
+
const req = request({ socketPath: c.socket, path: '/v1', method: 'POST', headers: { Authorization: 'Bearer ' + token, 'Content-Type': 'application/json' } }, res => {
|
|
84
|
+
const chunks = [];
|
|
85
|
+
let size = 0;
|
|
86
|
+
res.on('data', chunk => { size += chunk.length; if (size > MAX_BYTES)
|
|
87
|
+
req.destroy();
|
|
88
|
+
else
|
|
89
|
+
chunks.push(Buffer.from(chunk)); });
|
|
90
|
+
res.on('error', () => reject(new HttpError(503, '密码库连接中断', 'vault_offline')));
|
|
91
|
+
res.on('aborted', () => reject(new HttpError(503, '密码库连接中断', 'vault_offline')));
|
|
92
|
+
res.on('end', () => {
|
|
93
|
+
try {
|
|
94
|
+
const body = JSON.parse(Buffer.concat(chunks).toString());
|
|
95
|
+
if (res.statusCode !== 200)
|
|
96
|
+
reject(new HttpError(res.statusCode ?? 503, '密码库操作未完成,请检查解锁和任务授权', typeof body.code === 'string' && /^vault_[a-z_]+$/.test(body.code) ? body.code : 'vault_request_failed'));
|
|
97
|
+
else
|
|
98
|
+
done(body.result);
|
|
99
|
+
}
|
|
100
|
+
catch {
|
|
101
|
+
reject(new HttpError(503, '密码库响应无效', 'vault_offline'));
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
req.setTimeout(command === 'execute' ? 40000 : 15000, () => req.destroy());
|
|
106
|
+
req.on('error', () => reject(new HttpError(503, '密码库连接中断', 'vault_offline')));
|
|
107
|
+
req.end(JSON.stringify({ epoch: this.epoch, owner, session, command, value }));
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
async call(owner, session, command, value) {
|
|
111
|
+
try {
|
|
112
|
+
this.hello ??= this.send(owner, session, 'hello');
|
|
113
|
+
await this.hello;
|
|
114
|
+
return await this.send(owner, session, command, value);
|
|
115
|
+
}
|
|
116
|
+
catch (e) {
|
|
117
|
+
if (e instanceof HttpError && (e.code === 'vault_offline' || e.code === 'vault_control_changed')) {
|
|
118
|
+
this.hello = undefined;
|
|
119
|
+
this.epoch = randomUUID();
|
|
120
|
+
this.onDisconnect();
|
|
121
|
+
if (command === 'execute')
|
|
122
|
+
throw new HttpError(409, '执行连接中断,结果不确定,禁止自动重试', 'vault_operation_uncertain');
|
|
123
|
+
}
|
|
124
|
+
throw e;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { chromium } from 'playwright';
|
|
2
|
+
import { resolve } from 'node:path';
|
|
3
|
+
/** Standard HTML POST form only. One private browser/context per lease; no
|
|
4
|
+
* persistent profile, public CDP port, fill/JS API, screenshots or page output. */
|
|
5
|
+
export class WebsiteFormExecutor {
|
|
6
|
+
home;
|
|
7
|
+
gate;
|
|
8
|
+
testCA;
|
|
9
|
+
constructor(home, gate, testCA) {
|
|
10
|
+
this.home = home;
|
|
11
|
+
this.gate = gate;
|
|
12
|
+
this.testCA = testCA;
|
|
13
|
+
}
|
|
14
|
+
async execute(entry, input, signal) {
|
|
15
|
+
this.gate.assert();
|
|
16
|
+
signal.throwIfAborted();
|
|
17
|
+
const plan = entry.usage;
|
|
18
|
+
if (entry.target.kind !== 'website' || input.target.kind !== 'website' || input.operation !== 'website.login' || entry.target.origin !== input.target.origin || plan?.kind !== 'website.form')
|
|
19
|
+
return { status: 'manual_takeover_required', reason: 'usage_policy_required', submitted: false };
|
|
20
|
+
// Test-only custom CA is not a TLS bypass: Chromium explicitly trusts this
|
|
21
|
+
// certificate's SPKI. It is restricted to loopback and never set by CLI.
|
|
22
|
+
const base = new URL(entry.target.origin);
|
|
23
|
+
if (this.testCA && base.hostname !== '127.0.0.1')
|
|
24
|
+
throw new Error('fixture CA is loopback only');
|
|
25
|
+
let browser, context, page, unsafe = false, submitted = false;
|
|
26
|
+
const abort = () => { void context?.close().catch(() => { }); void browser?.close().catch(() => { }); };
|
|
27
|
+
signal.addEventListener('abort', abort, { once: true });
|
|
28
|
+
try {
|
|
29
|
+
const args = ['--force-webrtc-ip-handling-policy=disable_non_proxied_udp', '--disable-background-networking'];
|
|
30
|
+
if (this.testCA) {
|
|
31
|
+
const { X509Certificate, createHash } = await import('node:crypto');
|
|
32
|
+
args.push('--ignore-certificate-errors-spki-list=' + createHash('sha256').update(new X509Certificate(this.testCA).publicKey.export({ type: 'spki', format: 'der' })).digest('base64'));
|
|
33
|
+
}
|
|
34
|
+
browser = await chromium.launch({ headless: true, chromiumSandbox: true, timeout: 10000, args, env: { PATH: process.env.PATH ?? '/usr/bin:/bin', HOME: resolve(this.home), TMPDIR: resolve(this.home), LANG: 'en_US.UTF-8' } });
|
|
35
|
+
signal.throwIfAborted();
|
|
36
|
+
this.gate.assert();
|
|
37
|
+
context = await browser.newContext({ acceptDownloads: false, serviceWorkers: 'block', permissions: [] });
|
|
38
|
+
context.setDefaultTimeout(5000);
|
|
39
|
+
context.setDefaultNavigationTimeout(5000);
|
|
40
|
+
await context.routeWebSocket('**/*', route => route.close());
|
|
41
|
+
page = await context.newPage();
|
|
42
|
+
context.on('page', other => { if (other !== page) {
|
|
43
|
+
unsafe = true;
|
|
44
|
+
void other.close().catch(() => { });
|
|
45
|
+
} });
|
|
46
|
+
page.on('dialog', dialog => { unsafe = true; void dialog.dismiss().catch(() => { }); });
|
|
47
|
+
page.on('frameattached', () => { unsafe = true; });
|
|
48
|
+
await context.route('**/*', async (route) => {
|
|
49
|
+
const request = route.request(), url = new URL(request.url());
|
|
50
|
+
const main = request.isNavigationRequest() && request.frame() === page.mainFrame();
|
|
51
|
+
const approvedNavigation = main && [plan.loginPath, plan.submitPath, plan.successPath, ...(plan.logoutPath ? [plan.logoutPath] : [])].includes(url.pathname) && !url.search && !url.hash;
|
|
52
|
+
const resource = !request.isNavigationRequest() && request.method() === 'GET' && ['script', 'stylesheet', 'image', 'font'].includes(request.resourceType());
|
|
53
|
+
const allowed = url.origin === base.origin && (approvedNavigation || resource) && (!request.redirectedFrom() || request.method() === 'GET' && url.pathname === plan.successPath)
|
|
54
|
+
&& (request.method() === 'GET' || main && request.method() === 'POST' && url.pathname === plan.submitPath) && !signal.aborted;
|
|
55
|
+
if (!allowed) {
|
|
56
|
+
unsafe = true;
|
|
57
|
+
await route.abort();
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
await route.continue();
|
|
61
|
+
});
|
|
62
|
+
await page.goto(new URL(plan.loginPath, base).href, { waitUntil: 'domcontentloaded' });
|
|
63
|
+
const form = page.locator(`form[id="${plan.formId}"]`), user = form.locator(`input[name="${plan.usernameName}"]`), password = form.locator(`input[name="${plan.passwordName}"]`), submit = form.locator('button[type="submit"],input[type="submit"]');
|
|
64
|
+
if (unsafe || page.frames().length !== 1 || await form.count() !== 1 || await user.count() !== 1 || await password.count() !== 1 || await submit.count() !== 1 || plan.usernameName === plan.passwordName)
|
|
65
|
+
return { status: 'manual_takeover_required', reason: 'unsupported_form_flow', submitted: false };
|
|
66
|
+
const metadata = await form.evaluate(el => { const f = el; return { method: f.method, action: f.action, enctype: f.enctype }; });
|
|
67
|
+
const action = new URL(metadata.action);
|
|
68
|
+
if (metadata.method.toLowerCase() !== 'post' || metadata.enctype !== 'application/x-www-form-urlencoded' || action.origin !== base.origin || action.pathname !== plan.submitPath || action.search || action.hash || await password.getAttribute('type') !== 'password')
|
|
69
|
+
return { status: 'manual_takeover_required', reason: 'unsupported_form_flow', submitted: false };
|
|
70
|
+
this.gate.assert();
|
|
71
|
+
signal.throwIfAborted();
|
|
72
|
+
await user.fill(entry.username);
|
|
73
|
+
await password.fill(entry.secret);
|
|
74
|
+
if (unsafe)
|
|
75
|
+
return { status: 'manual_takeover_required', reason: 'unsupported_form_flow', submitted: false };
|
|
76
|
+
submitted = true;
|
|
77
|
+
await Promise.all([page.waitForURL(url => url.origin === base.origin && url.pathname === plan.successPath && !url.search && !url.hash, { waitUntil: 'domcontentloaded' }), submit.click()]);
|
|
78
|
+
signal.throwIfAborted();
|
|
79
|
+
this.gate.assert();
|
|
80
|
+
if (unsafe || page.frames().length !== 1 || await page.locator(plan.successSelector).count() !== 1 || !await page.locator(plan.successSelector).isVisible())
|
|
81
|
+
return { status: 'manual_takeover_required', reason: 'unsupported_form_flow', submitted: true };
|
|
82
|
+
if (plan.logoutPath) {
|
|
83
|
+
const response = await page.goto(new URL(plan.logoutPath, base).href, { waitUntil: 'domcontentloaded' });
|
|
84
|
+
if (!response || response.status() >= 300 || unsafe)
|
|
85
|
+
return { status: 'manual_takeover_required', reason: 'unsupported_form_flow', submitted: true };
|
|
86
|
+
}
|
|
87
|
+
// The authenticated context is destroyed below. Cookies/DOM/network output
|
|
88
|
+
// are never handed to generic tools or included in the model receipt.
|
|
89
|
+
return { status: 'complete', operation: 'website.login' };
|
|
90
|
+
}
|
|
91
|
+
catch {
|
|
92
|
+
signal.throwIfAborted();
|
|
93
|
+
return { status: 'manual_takeover_required', reason: 'unsupported_form_flow', submitted };
|
|
94
|
+
}
|
|
95
|
+
finally {
|
|
96
|
+
signal.removeEventListener('abort', abort);
|
|
97
|
+
await context?.clearCookies().catch(() => { });
|
|
98
|
+
await context?.close().catch(() => { });
|
|
99
|
+
await browser?.close().catch(() => { });
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
@@ -48,11 +48,11 @@ export const DESKTOP_ENVIRONMENT_TOOLS = [
|
|
|
48
48
|
{ id: 'desktop_shell', name: 'desktop_shell', description: '在这台电脑的用户主目录执行一条 shell 命令,返回 stdout、stderr 与退出码。长任务会超时终止;不要用它代替文件工具读写大文件。可用 host 指定目标电脑。', inputSchema: { type: 'object', properties: { command: { type: 'string' }, cwd: { type: 'string' }, timeoutMs: { type: 'integer' }, host: { type: 'string' } }, required: ['command'], additionalProperties: false } },
|
|
49
49
|
];
|
|
50
50
|
export const DESKTOP_FILE_TOOL_IDS = new Set(['desktop_file_list', 'desktop_file_read', 'desktop_file_write', 'desktop_file_copy', 'desktop_shell']);
|
|
51
|
-
export const DESKTOP_FILE_TRANSFER_RULES = '电脑间传文件用 desktop_file_copy,一次指定 sourceHost、sourcePath、targetHost、targetPath
|
|
51
|
+
export const DESKTOP_FILE_TRANSFER_RULES = '电脑间传文件用 desktop_file_copy,一次指定 sourceHost、sourcePath、targetHost、targetPath;服务器桌面代理用 server,当前 Bot 的虚拟机用 vm,设备名用设置里的名字,「本机」只指本轮消息来源电脑。例:把 mac1 桌面的 a.txt 放到 mac2 桌面,调用 {sourceHost:"mac1",sourcePath:"Desktop/a.txt",targetHost:"mac2",targetPath:"Desktop/a.txt"}。这是复制,保留原文件;只有用户明确要求覆盖时才传 overwrite:true。无需先截图,不要读取 base64 给模型、上传聊天附件或假设不同电脑共享文件路径。最大 25 MiB;工具返回已校验的成功结果后才报告完成。';
|
|
52
52
|
/** Macs connected to the server as computers. */
|
|
53
53
|
export const DESKTOP_ENVIRONMENT_RULES = '操作连接服务器的电脑时,使用本轮提供的 desktop_* 工具,并用 host 指定电脑名称或编号。Hermes 原生终端和文件工具不能代替该电脑上的操作。';
|
|
54
54
|
/** Yaoyao host Mac — same look-then-act pattern as the cloud computer. */
|
|
55
|
-
export const SERVER_COMPUTER_RULES = '
|
|
55
|
+
export const SERVER_COMPUTER_RULES = '操作客户端提供的服务器桌面代理时,使用本轮提供的 desktop_* 工具并明确指定 host="server"。处理 Hermes 原生工具实际控制的运行环境时,优先使用对应原生工具;处理服务器桌面代理用户主目录内的文件时,使用已授权的 desktop_file_* 或 desktop_shell,不假定两者共享路径或能力。';
|
|
56
56
|
/** The loopback native transport is admitted only by serviceInstance's
|
|
57
57
|
* private capability; remote hosts are admitted by DesktopHostHub's bearer
|
|
58
58
|
* pairing. Browser/desktop authority never crosses into the renderer. */
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
const text = z.string().min(1).max(256).refine(value => !/[\u0000-\u001f]/.test(value));
|
|
3
|
+
const tools = z.array(z.string().regex(/^[A-Za-z0-9_.:-]{1,128}$/)).max(256);
|
|
4
|
+
const metadata = z.object({
|
|
5
|
+
version: z.literal(1), profile: text, platform: text, osRelease: text, arch: text,
|
|
6
|
+
nativeTools: z.object({ terminal: tools, files: tools, desktop: tools, browser: tools }),
|
|
7
|
+
});
|
|
8
|
+
/** Optional protocol extension: old or incompatible bridges leave facts unknown. */
|
|
9
|
+
export function parseHermesRuntimeMetadata(value, profile) {
|
|
10
|
+
const parsed = metadata.safeParse(value);
|
|
11
|
+
if (!parsed.success || parsed.data.profile !== profile)
|
|
12
|
+
return undefined;
|
|
13
|
+
return parsed.data;
|
|
14
|
+
}
|
|
@@ -154,6 +154,11 @@ export class LocalAuthStore {
|
|
|
154
154
|
return injected;
|
|
155
155
|
return this.currentFromCookieHeader(ctx.get('cookie'));
|
|
156
156
|
}
|
|
157
|
+
/** Opaque vault binding; callers must separately validate the session. */
|
|
158
|
+
sessionBinding(cookieHeader) {
|
|
159
|
+
const token = parse(cookieHeader ?? '')[SESSION_COOKIE];
|
|
160
|
+
return token ? createHash('sha256').update('yaoyao-vault-session-v1\0').update(token).digest('hex') : undefined;
|
|
161
|
+
}
|
|
157
162
|
/** Resolve the same authenticated user for non-Koa transports such as WS Upgrade. */
|
|
158
163
|
currentFromCookieHeader(cookieHeader) {
|
|
159
164
|
const token = parse(cookieHeader ?? '')[SESSION_COOKIE];
|
|
@@ -7,6 +7,7 @@ const json = (value) => `${JSON.stringify(value, null, 2)}\n`;
|
|
|
7
7
|
const isUuid = (value) => /^[0-9a-f]{32}$/.test(value);
|
|
8
8
|
const memoryId = (requestId) => requestId.replaceAll('-', '');
|
|
9
9
|
const MEMORY_TAG = 'yaoyao_memory=true';
|
|
10
|
+
const MEMORY_READ_CONCURRENCY = 8;
|
|
10
11
|
const activeUri = (scope, id) => `viking://~/memories/yaoyao/${scope.scope}/${id}.json`;
|
|
11
12
|
const revisionsUri = (scope, id, revision) => `viking://resources/yaoyao/${scope.scope}/${id}/revisions/${revision}.json`;
|
|
12
13
|
const tombstoneUri = (scope, fingerprint) => `viking://resources/yaoyao/${scope.scope}/tombstones/${fingerprint}.json`;
|
|
@@ -98,18 +99,36 @@ export class OpenVikingMemoryProvider {
|
|
|
98
99
|
const client = this.service.userClient(owner, scope.agentId);
|
|
99
100
|
const directory = `viking://~/memories/yaoyao/${scope.scope}`;
|
|
100
101
|
const entries = await notFoundAsUndefined(() => client.list(directory, { recursive: true })) ?? [];
|
|
101
|
-
const
|
|
102
|
-
for (const entry of entries) {
|
|
102
|
+
const ids = entries.flatMap(entry => {
|
|
103
103
|
const name = uriName(entry);
|
|
104
104
|
const match = /([0-9a-f]{32})\.json$/.exec(name ?? '');
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
105
|
+
return match ? [match[1]] : [];
|
|
106
|
+
});
|
|
107
|
+
const records = new Array(ids.length);
|
|
108
|
+
let next = 0, failed = false;
|
|
109
|
+
// Preserve directory order and per-record scope checks without N serial round trips.
|
|
110
|
+
const reads = await Promise.allSettled(Array.from({ length: Math.min(ids.length, MEMORY_READ_CONCURRENCY) }, async () => {
|
|
111
|
+
while (!failed) {
|
|
112
|
+
const index = next++;
|
|
113
|
+
if (index >= ids.length)
|
|
114
|
+
return;
|
|
115
|
+
let record;
|
|
116
|
+
try {
|
|
117
|
+
record = await this.readRecord(owner, scope, ids[index]);
|
|
118
|
+
}
|
|
119
|
+
catch (error) {
|
|
120
|
+
failed = true;
|
|
121
|
+
throw error;
|
|
122
|
+
}
|
|
123
|
+
if (record && record.memory.scope === scope.scope && record.memory.agentId === scope.agentId
|
|
124
|
+
&& record.memory.projectId === scope.projectId)
|
|
125
|
+
records[index] = record.memory;
|
|
126
|
+
}
|
|
127
|
+
}));
|
|
128
|
+
const failure = reads.find(read => read.status === 'rejected');
|
|
129
|
+
if (failure?.status === 'rejected')
|
|
130
|
+
throw failure.reason;
|
|
131
|
+
return records.filter((memory) => memory !== undefined);
|
|
113
132
|
}
|
|
114
133
|
async list(owner, scopes) {
|
|
115
134
|
const result = [];
|
|
@@ -22,6 +22,8 @@ export class OpenVikingService {
|
|
|
22
22
|
#clients = new Map();
|
|
23
23
|
#adminClients = new Map();
|
|
24
24
|
#registrations = new Map();
|
|
25
|
+
#removals = new Map();
|
|
26
|
+
onConfigurationChanged = () => { };
|
|
25
27
|
#configuration;
|
|
26
28
|
#clientFactory;
|
|
27
29
|
constructor(store, configurationManager, clientFactory) {
|
|
@@ -37,11 +39,14 @@ export class OpenVikingService {
|
|
|
37
39
|
}
|
|
38
40
|
configure(config) {
|
|
39
41
|
const signature = config ? `${config.url}\0${config.accountId}\0${config.adminKey}` : '';
|
|
40
|
-
|
|
42
|
+
const changed = signature !== this.#signature;
|
|
43
|
+
if (changed) {
|
|
41
44
|
this.#clients.clear();
|
|
42
45
|
this.#adminClients.clear();
|
|
43
46
|
}
|
|
44
47
|
this.#configuration = config;
|
|
48
|
+
if (changed)
|
|
49
|
+
this.onConfigurationChanged();
|
|
45
50
|
}
|
|
46
51
|
get #signature() { return this.#configuration ? `${this.#configuration.url}\0${this.#configuration.accountId}\0${this.#configuration.adminKey}` : ''; }
|
|
47
52
|
binding(owner, agentId) {
|
|
@@ -83,6 +88,8 @@ export class OpenVikingService {
|
|
|
83
88
|
return client;
|
|
84
89
|
}
|
|
85
90
|
userClient(owner, agentId) {
|
|
91
|
+
if (this.store.get(owner, 'agent-deletion', agentId))
|
|
92
|
+
throw new HttpError(410, 'Bot 已删除,记忆用户不可使用', 'openviking_user_removed');
|
|
86
93
|
const config = this.#configuration;
|
|
87
94
|
if (!config)
|
|
88
95
|
throw new HttpError(409, 'OpenViking 记忆服务未启用', 'openviking_disabled');
|
|
@@ -100,6 +107,8 @@ export class OpenVikingService {
|
|
|
100
107
|
}
|
|
101
108
|
async ensureUser(owner, agent) {
|
|
102
109
|
const key = `${this.namespace}:${owner}:${agent.id}`;
|
|
110
|
+
if (this.#removals.has(key) || this.store.get(owner, 'agent-deletion', agent.id) || this.binding(owner, agent.id)?.status === 'removed')
|
|
111
|
+
throw new HttpError(410, 'Bot 已删除或正在移除记忆用户,不能重新注册', 'openviking_user_removed');
|
|
103
112
|
const existing = this.#registrations.get(key);
|
|
104
113
|
if (existing)
|
|
105
114
|
return existing;
|
|
@@ -151,22 +160,43 @@ export class OpenVikingService {
|
|
|
151
160
|
}
|
|
152
161
|
}
|
|
153
162
|
async removeUser(owner, agent) {
|
|
154
|
-
const
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
163
|
+
const namespace = this.namespace, key = `${namespace}:${owner}:${agent.id}`;
|
|
164
|
+
const existing = this.#removals.get(key);
|
|
165
|
+
if (existing)
|
|
166
|
+
return existing;
|
|
167
|
+
const registrations = [...this.#registrations.entries()].filter(([registrationKey]) => registrationKey.endsWith(`:${owner}:${agent.id}`)).map(([, registration]) => registration);
|
|
168
|
+
const config = this.#configuration, admin = config ? this.adminClient() : undefined;
|
|
169
|
+
const pending = Promise.resolve().then(async () => {
|
|
170
|
+
// Registration can already have reached the remote server. Finish it before
|
|
171
|
+
// removal so its late receipt cannot recreate the deleted user's binding.
|
|
172
|
+
await Promise.allSettled(registrations);
|
|
173
|
+
// Keep the deletion attached to the configuration captured at admission.
|
|
174
|
+
const legacy = this.store.get(owner, 'openviking-binding', agent.id);
|
|
175
|
+
const binding = config
|
|
176
|
+
? this.store.get(owner, 'openviking-binding', `${namespace}:${agent.id}`) ?? (legacy && (!legacy.namespace || legacy.namespace === namespace) ? legacy : undefined)
|
|
177
|
+
: legacy;
|
|
178
|
+
if (binding?.status === 'removed' && !binding.pendingRemoval)
|
|
179
|
+
return;
|
|
180
|
+
const removed = { ...(binding ?? { provider: 'openviking', owner, agentId: agent.id, userId: openVikingUserId(agent.id), encryptedUserKey: '', namespace }), status: 'removed', pendingRemoval: true, updatedAt: Date.now() };
|
|
181
|
+
this.saveBinding(removed);
|
|
182
|
+
if (!config || !admin)
|
|
183
|
+
return; // Keep a durable pending removal while disabled.
|
|
184
|
+
try {
|
|
185
|
+
await admin.adminRemoveUser(config.accountId, removed.userId);
|
|
186
|
+
}
|
|
187
|
+
catch (error) {
|
|
188
|
+
if (!(error instanceof OpenVikingError) || !(error.statusCode === 404 || error.code === 'NOT_FOUND'))
|
|
189
|
+
mapError(error, 'user 删除');
|
|
190
|
+
}
|
|
191
|
+
this.saveBinding({ ...removed, pendingRemoval: false, updatedAt: Date.now() });
|
|
192
|
+
});
|
|
193
|
+
this.#removals.set(key, pending);
|
|
162
194
|
try {
|
|
163
|
-
await
|
|
195
|
+
await pending;
|
|
164
196
|
}
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
mapError(error, 'user 删除');
|
|
197
|
+
finally {
|
|
198
|
+
this.#removals.delete(key);
|
|
168
199
|
}
|
|
169
|
-
this.saveBinding({ ...binding, status: 'removed', pendingRemoval: false, updatedAt: Date.now() });
|
|
170
200
|
}
|
|
171
201
|
}
|
|
172
202
|
function encryptUserKey(home, value) {
|