feat(desktop): attest and manage the owned Windows host lifecycle

This commit is contained in:
Agent Workbench Dev
2026-10-31 09:03:01 +08:00
parent e634a252dd
commit 249f191ebc
32 changed files with 1765 additions and 70 deletions
+18
View File
@@ -98,6 +98,22 @@ export class Provider {
constructor(options = {}) { this.apiKey = process.env.AGENT_WORKBENCH_API_KEY || ''; this.fetcher = options.fetch; this.retryPolicy = options.retryPolicy; }
hasKey() { return !!this.apiKey; }
setKey(value) { this.apiKey = String(value ?? '').trim(); }
requestOperation(signal) {
if (this.requestsClosing) throw new Error('执行宿主正在停止模型请求。');
const controller = new AbortController();
let settled; const done = new Promise(resolve => { settled = resolve; });
const operation = { controller, done, signal: signal ? AbortSignal.any([signal, controller.signal]) : controller.signal,
finish: () => { this.requestControllers.delete(operation); settled(); } };
(this.requestControllers ??= new Set()).add(operation);
return operation;
}
async abortRequests() {
this.requestsClosing = true;
const operations = [...(this.requestControllers ?? [])];
for (const operation of operations) operation.controller.abort(new Error('用户停止执行宿主。'));
await Promise.all(operations.map(operation => operation.done));
}
resumeRequests() { this.requestsClosing = false; }
modelHub(store) { return this.hub ??= new ModelHub(store, this); }
prepareConfig(config, store) { return this.modelHub(store).prepare(config); }
redact(value, key = this.apiKey) {
@@ -116,6 +132,7 @@ export class Provider {
const headers = { 'Content-Type': 'application/json' };
if (key) headers.Authorization = 'Bearer ' + key;
const policy = { attempts: 3, delays: [500, 1500], timeoutMs: signal ? 60000 : 20000, totalTimeoutMs: signal ? 90000 : 20000, ...this.retryPolicy, ...options };
const operation = this.requestOperation(signal); signal = operation.signal;
const deadline = Date.now() + policy.totalTimeoutMs;
const startedAt = Date.now();
let attempts = 0;
@@ -168,6 +185,7 @@ export class Provider {
throw new Error('模型请求未能完成。');
} finally {
this.activeRequests--;
operation.finish();
if (signal?.aborted) this.lastRequest = { source: 'model_connection', stage: 'model_request',
endpoint: base, route, model: config.model, status: 'interrupted', attempts,
durationMs: Date.now() - startedAt, occurredAt: new Date().toISOString() };