feat: add bounded connection network diagnostics

This commit is contained in:
Agent Workbench Dev
2026-11-03 23:11:33 +08:00
parent dca6cbdb2c
commit 54dbe3d6fc
30 changed files with 683 additions and 40 deletions
+8 -1
View File
@@ -187,6 +187,13 @@ return async (request, response) => {
const hub = provider.modelHub(store);
const importer = () => hub.importer ??= new ConfigImporter(hub);
if (method === 'GET' && route === '/api/model-center') return json(response, hub.view());
if (method === 'GET' && route === '/api/model-center/network-diagnostics') return json(response, hub.networkDiagnostics().view());
const networkStop = route.match(/^\/api\/model-center\/network-diagnostics\/([a-f0-9-]{36})\/stop$/i);
if (method === 'POST' && networkStop) return json(response, await hub.networkDiagnostics().stop(networkStop[1], await body(request)));
if (method === 'POST' && route === '/api/model-center/network-diagnostics') {
if (runtime.hasActivity()) throw Object.assign(new Error('请等待当前任务或诊断结束,再开始新的连接诊断。'), { status: 409 });
return json(response, hub.networkDiagnostics().start(await body(request)), 201);
}
if (method === 'GET' && route === '/api/model-center/selection') return json(response, {
config: { ...store.config, hasKey: provider.hasKey() }, modelSelection: hub.selectionView(),
});
@@ -195,7 +202,7 @@ return async (request, response) => {
if (method === 'POST') {
const input = await body(request);
if (route === '/api/model-center/toggle') return json(response, hub.toggle(input.id, input.enabled));
if (runtime.hasActivity()) throw Object.assign(new Error('请先停止正在运行的任务,再修改或测试模型配置。'), { status: 409 });
if (runtime.hasActivity() || hub.networkChecks?.active.size) throw Object.assign(new Error('请等待正在运行的任务或连接诊断结束,再修改或测试模型配置。'), { status: 409 });
if (route === '/api/model-center/runtime-budgets') {
store.saveConfig(validateRuntimeBudgets(input));
return json(response, { config: { ...store.config, hasKey: provider.hasKey() }, modelSelection: hub.selectionView() });
+1 -1
View File
@@ -1,6 +1,6 @@
import { randomUUID, createHash } from 'node:crypto';
export const APP_VERSION = '1.24.5';
export const APP_VERSION = '1.24.6';
export function executionEnvironment() {
const windows = process.platform === 'win32';
+6 -1
View File
@@ -10,6 +10,7 @@ import { createRequestHandler, createSessionPublisher } from './app.mjs';
import { APP_VERSION } from './diagnostics.mjs';
import { hostAuthority } from '../core/desktop/host-authority.mjs';
import { CredentialVault } from '../core/models/credential-vault.mjs';
import { NetworkDiagnostics } from '../core/models/network-diagnostics.mjs';
// Keep the existing objects and their in-memory connection. No credential is
// extracted, transferred, returned, or persisted by this operation.
@@ -22,6 +23,7 @@ export function installUpgrade(context, { appDirectory, updateServiceInfo = true
if (runtime.filePreviews?.active.size || runtime.filePreviews?.pending) throw new Error('Close local HTML previews before upgrading.');
if (runtime.browsing?.active.size || runtime.previews?.active.size || runtime.evaluations?.active.size || runtime.environments?.active.size || runtime.active.size || runtime.waiters.size || runtime.workers?.active.size || runtime.controlledEngines?.drivers.size || runtime.mcp?.active.size || runtime.checks?.active.size || runtime.deliveries?.active.size || runtime.changeSets?.projects.size || runtime.workspaces?.projects.size || runtime.workspaces?.pending.size || runtime.research?.active.size || runtime.engines?.active.size || runtime.browser?.active.size || runtime.taskPlans?.active.size) throw new Error('Wait for active evaluations, environments, tasks, workers, controlled engines, MCP operations, checks, Git deliveries, file batches, workspaces, research, engines, browsers, task plans and approvals to finish before upgrading.');
if (provider.activeRequests || provider.hub?.waiting || [...(provider.hub?.leases.values() ?? [])].some(count => count > 0)) throw new Error('Wait for active model requests and probes before upgrading.');
if (provider.hub?.networkChecks?.active.size) throw new Error('Wait for active connection diagnostics before upgrading.');
const root = fs.realpathSync.native(path.resolve(appDirectory));
if (!fs.existsSync(path.join(root, 'dist-client', 'index.html'))) throw new Error('The new client bundle is missing.');
const oldHandlers = server.listeners('request');
@@ -31,7 +33,8 @@ export function installUpgrade(context, { appDirectory, updateServiceInfo = true
const oldPrototypes = [Object.getPrototypeOf(store), Object.getPrototypeOf(provider), Object.getPrototypeOf(runtime)];
const oldModelPrototypes = { hub: provider.hub ? Object.getPrototypeOf(provider.hub) : null,
importer: provider.hub?.importer ? Object.getPrototypeOf(provider.hub.importer) : null,
vault: provider.hub?.credentialVault ? Object.getPrototypeOf(provider.hub.credentialVault) : null };
vault: provider.hub?.credentialVault ? Object.getPrototypeOf(provider.hub.credentialVault) : null,
network: provider.hub?.networkChecks ? Object.getPrototypeOf(provider.hub.networkChecks) : null };
const oldStoreProperties = { ...store };
const oldRuntimeProperties = { filePreviews: runtime.filePreviews, browsing: runtime.browsing, previews: runtime.previews, evaluations:runtime.evaluations, environments: runtime.environments, appDirectory: runtime.appDirectory, workers: runtime.workers, controlledEngines: runtime.controlledEngines, checks: runtime.checks, deliveries: runtime.deliveries, codeIndex: runtime.codeIndex, changeSets: runtime.changeSets, contextPlans: runtime.contextPlans, workspaces: runtime.workspaces, research: runtime.research, engines: runtime.engines, browser: runtime.browser, taskPlans: runtime.taskPlans, projectMemories: runtime.projectMemories, taskCheckpoints: runtime.taskCheckpoints, skills: runtime.skills, mcp: runtime.mcp };
const oldUpdates = store.listeners('update');
@@ -49,6 +52,7 @@ export function installUpgrade(context, { appDirectory, updateServiceInfo = true
Object.setPrototypeOf(provider.hub, ModelHub.prototype);
if (provider.hub.importer) Object.setPrototypeOf(provider.hub.importer, ConfigImporter.prototype);
if (provider.hub.credentialVault) Object.setPrototypeOf(provider.hub.credentialVault, CredentialVault.prototype);
if (provider.hub.networkChecks) Object.setPrototypeOf(provider.hub.networkChecks, NetworkDiagnostics.prototype);
}
runtime.filePreviews = null; runtime.appDirectory = root; runtime.previews = null; runtime.browsing = null; runtime.evaluations = null; runtime.environments = null; runtime.workers = null; runtime.controlledEngines = null; runtime.checks = null; runtime.deliveries = null; runtime.codeIndex = null; runtime.changeSets = null; runtime.contextPlans = null; runtime.workspaces = null; runtime.research = null; runtime.engines = null; runtime.browser = null; runtime.taskPlans = null; runtime.projectMemories = null; runtime.taskCheckpoints = null; runtime.skills = null; runtime.mcp = null;
delete server.workbenchCompanion;
@@ -93,6 +97,7 @@ export function installUpgrade(context, { appDirectory, updateServiceInfo = true
if (oldModelPrototypes.hub) Object.setPrototypeOf(provider.hub, oldModelPrototypes.hub);
if (oldModelPrototypes.importer) Object.setPrototypeOf(provider.hub.importer, oldModelPrototypes.importer);
if (oldModelPrototypes.vault) Object.setPrototypeOf(provider.hub.credentialVault, oldModelPrototypes.vault);
if (oldModelPrototypes.network) Object.setPrototypeOf(provider.hub.networkChecks, oldModelPrototypes.network);
store.removeAllListeners('update'); for (const observer of oldUpdates) store.on('update', observer);
server.removeAllListeners('request'); for (const previous of oldHandlers) server.on('request', previous);
throw error;
+2 -1
View File
@@ -130,12 +130,13 @@ export class Provider {
}
async abortRequests() {
this.requestsClosing = true;
await this.hub?.networkChecks?.stopAll();
const operations = [...(this.requestControllers ?? [])];
for (const operation of operations) operation.controller.abort(new Error('用户停止执行宿主。'));
await Promise.all(operations.map(operation => operation.done));
const transport=this.transport;this.transport=null;await transport?.close();
}
resumeRequests() { this.requestsClosing = false; }
resumeRequests() { this.requestsClosing = false; if (this.hub?.networkChecks) this.hub.networkChecks.closing = false; }
modelHub(store) { return this.hub ??= new ModelHub(store, this); }
prepareConfig(config, store) { return this.modelHub(store).prepare(config); }
redact(value, key = this.apiKey) {
+2 -1
View File
@@ -133,7 +133,7 @@ export class Runtime {
this.active = new Map(); this.waiters = new Map();
}
isActive(id) { return !!this.browsing?.isActive(id) || !!this.previews?.isActive(id) || !!this.environments?.isActive(id) || !!this.evaluations?.isActive(id) || this.active.has(id) || !!this.workers?.isActive(id) || !!this.controlledEngines?.isActive(id) || !!this.checks?.isActive(id) || !!this.deliveries?.isActive(id) || !!this.changeSets?.isActive(id) || !!this.workspaces?.isActive(id) || !!this.research?.isActive(id) || !!this.engines?.isActive(id) || !!this.browser?.isActive(id) || !!this.taskPlans?.isActive(id); }
hasActivity() { return (this.browsing?.active.size ?? 0) > 0 || (this.previews?.active.size ?? 0) > 0 || (this.environments?.active.size ?? 0) > 0 || (this.evaluations?.active.size ?? 0) > 0 || (this.provider.activeRequests ?? 0) > 0 || (this.provider.hub?.waiting ?? 0) > 0 || this.active.size > 0 || (this.workers?.active.size ?? 0) > 0 || (this.controlledEngines?.drivers.size ?? 0) > 0 || (this.mcp?.active.size ?? 0) > 0 || (this.checks?.active.size ?? 0) > 0 || (this.deliveries?.active.size ?? 0) > 0 || (this.changeSets?.projects.size ?? 0) > 0 || (this.workspaces?.projects.size ?? 0) > 0 || (this.workspaces?.pending.size ?? 0) > 0 || (this.research?.active.size ?? 0) > 0 || (this.engines?.active.size ?? 0) > 0 || (this.browser?.active.size ?? 0) > 0 || (this.taskPlans?.active.size ?? 0) > 0; }
hasActivity() { return (this.provider.hub?.networkChecks?.active.size ?? 0) > 0 || (this.browsing?.active.size ?? 0) > 0 || (this.previews?.active.size ?? 0) > 0 || (this.environments?.active.size ?? 0) > 0 || (this.evaluations?.active.size ?? 0) > 0 || (this.provider.activeRequests ?? 0) > 0 || (this.provider.hub?.waiting ?? 0) > 0 || this.active.size > 0 || (this.workers?.active.size ?? 0) > 0 || (this.controlledEngines?.drivers.size ?? 0) > 0 || (this.mcp?.active.size ?? 0) > 0 || (this.checks?.active.size ?? 0) > 0 || (this.deliveries?.active.size ?? 0) > 0 || (this.changeSets?.projects.size ?? 0) > 0 || (this.workspaces?.projects.size ?? 0) > 0 || (this.workspaces?.pending.size ?? 0) > 0 || (this.research?.active.size ?? 0) > 0 || (this.engines?.active.size ?? 0) > 0 || (this.browser?.active.size ?? 0) > 0 || (this.taskPlans?.active.size ?? 0) > 0; }
evaluationManager() { return this.evaluations ??= new EvaluationManager(this.store, this); }
workerManager() { return this.workers ??= new WorkerManager(this.store, this); }
projectIndexer() { return this.codeIndex ??= new ProjectIndex({ cacheDirectory: path.join(this.store.directory, 'cache', 'project-index') }); }
@@ -231,6 +231,7 @@ export class Runtime {
return this.start(session.id, worker.goal, true, { workerAuthorization: workerAuthority, worker, workerConfig: config });
}
start(id, content, resume = false, { instructionSource = null, workerAuthorization = null, worker = null, workerConfig = null, attachmentIds=[],resumePlan=null } = {}) {
if (this.provider.hub?.networkChecks?.active.size) throw Object.assign(new Error('连接诊断正在执行,请等待结束或在模型中心停止诊断,再开始任务。'), { status: 409 });
const session = this.store.session(id);
assertWorkersResolved(this.store, session.projectId);
const boundWorker = workerForSession(this.store, session);