fix: complete unrestricted waits catalog and network flows

This commit is contained in:
Agent Workbench Dev
2026-11-06 06:21:59 +08:00
parent c93c434808
commit c9c77c7ee6
32 changed files with 295 additions and 84 deletions
+9 -6
View File
@@ -1,6 +1,7 @@
import { randomUUID } from 'node:crypto';
import { ModelTransport } from './transport.mjs';
import { probeNetwork } from './network-probe.mjs';
import { unrestricted, ceiling } from '../../shared/contracts/execution-policy.mjs';
const problem = (message, status = 409) => Object.assign(new Error(message), { status });
const terminal = new Set(['passed', 'partial', 'failed', 'cancelled', 'interrupted']);
@@ -23,7 +24,7 @@ export class NetworkDiagnostics {
const connection = this.hub.connections().find(row => row.id === job.connectionId);
return { ...structuredClone(job), stale: !connection || connection.revision !== job.connectionRevision,
currentConnectionRevision: connection?.revision ?? null };
}).reverse(), active: this.active.size, retained: 30, httpRequests: 0, modelRequests: 0 };
}).reverse(), active: this.active.size, retained: unrestricted(this.hub.store) ? null : 30, httpRequests: 0, modelRequests: 0 };
}
start(input) {
if (!input || Object.keys(input).length !== 2 || Object.keys(input).some(key => !['id', 'revision'].includes(key)) || !Number.isSafeInteger(input.revision)) throw problem('连接诊断需要所选连接及其原修订。', 400);
@@ -38,20 +39,22 @@ export class NetworkDiagnostics {
const profile = structuredClone(transport.profile);
const target = { endpoint: connection.baseUrl, origin: url.origin, host: url.hostname.replace(/^\[|\]$/g, ''),
port: Number(url.port || (url.protocol === 'https:' ? 443 : 80)), scheme: url.protocol };
const budgetMs = this.options.budgetMs ?? Math.min(12000, profile.connectTimeoutMs + 2000);
const open = unrestricted(this.hub.store);
const stageTimeoutMs = this.options.stageTimeoutMs ?? (profile.connectTimeoutMs || (open ? 0 : 10000));
const budgetMs = this.options.budgetMs ?? (open ? 0 : Math.min(12000, (profile.connectTimeoutMs || 10000) + 2000));
const job = { schemaVersion: 1, id: randomUUID(), connectionId: connection.id, connectionRevision: connection.revision,
connectionName: connection.name, status: 'running', startedAt: new Date().toISOString(), finishedAt: null,
target, transport: profile, route: { kind: 'direct-endpoint-only', proxyConfigured: profile.httpProxyConfigured || profile.httpsProxyConfigured,
noProxyConfigured: profile.noProxyConfigured, customTransport, modelApiRouteVerified: false },
budgetMs, stages: {}, trials: [], elapsedMs: 0, httpRequests: 0, modelRequests: 0, credentialAccess: false };
budgetMs, stageTimeoutMs, stages: {}, trials: [], elapsedMs: 0, httpRequests: 0, modelRequests: 0, credentialAccess: false };
const previous = this.jobs;
this.jobs = [...this.jobs.slice(-29), job];
this.jobs = [...(open ? this.jobs : this.jobs.slice(-29)), job];
try { this.save(); } catch (error) { this.jobs = previous; throw error; }
const controller = new AbortController(), operation = { job, controller, promise: null };
this.active.set(job.id, operation);
const timer = setTimeout(() => controller.abort({ code: 'DIAGNOSTIC_DEADLINE' }), budgetMs);
const timer = budgetMs > 0 ? setTimeout(() => controller.abort({ code: 'DIAGNOSTIC_DEADLINE' }), budgetMs) : null;
operation.promise = Promise.resolve().then(async () => {
const result = await probeNetwork(target, profile, { ...this.options,
const result = await probeNetwork(target, profile, { ...this.options, stageTimeoutMs, maxAddresses: ceiling(this.hub.store, 32),
...(transport.connect?.lookup ? { lookup: transport.connect.lookup } : {}), signal: controller.signal,
update: result => { Object.assign(job, result); this.save(); } });
Object.assign(job, result);