agents-relay 2.0.11 → 2.0.12
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/dist/decision-audit.js +85 -1
- package/dist/execution-routing.js +6 -6
- package/package.json +1 -1
package/dist/decision-audit.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { appendFile, mkdir, readFile } from 'node:fs/promises';
|
|
2
2
|
import { dirname } from 'node:path';
|
|
3
3
|
import { randomUUID, createHash } from 'node:crypto';
|
|
4
|
-
export const DECISION_AUDIT_SCHEMA_VERSION =
|
|
4
|
+
export const DECISION_AUDIT_SCHEMA_VERSION = 3;
|
|
5
5
|
export class JsonlDecisionAuditStore {
|
|
6
6
|
path;
|
|
7
7
|
constructor(path) {
|
|
@@ -59,3 +59,87 @@ export function makeDecisionAudit(input) {
|
|
|
59
59
|
});
|
|
60
60
|
return { record_type: 'decision', schema_version: DECISION_AUDIT_SCHEMA_VERSION, decision_id: decisionAuditId(), prior_decision_id: input.priorDecisionId, timestamp: input.routing.decidedAt, correlation: { job_id: input.task?.jobId, task_id: input.task?.id, execution_id: input.task?.executionId, attempt: input.task?.attempt }, task: taskAuditFacts(input.task), worker: input.worker, contract: input.contract, policy: { path: input.policy.path, hash: input.policy.hash, snapshot: input.policy.snapshot, rules: input.policy.rules }, candidates: input.candidates.map(candidate), gate_results, eligible_candidates: input.eligibleCandidates.map(candidate), selected: candidate(input.selected), engine: input.routing.decidedBy, fallback: { used: input.routing.decisionEvidence?.fallback ?? false, reason: input.routing.decisionEvidence?.error }, decision_evidence: input.routing.decisionEvidence, prior_failure: input.priorFailure };
|
|
61
61
|
}
|
|
62
|
+
function workerAuditCandidate(worker) {
|
|
63
|
+
return {
|
|
64
|
+
id: worker.workerId,
|
|
65
|
+
adapter: worker.adapter,
|
|
66
|
+
runtime: worker.runtime ?? null,
|
|
67
|
+
availability: worker.availability ?? null,
|
|
68
|
+
capabilities: [...worker.capabilities],
|
|
69
|
+
trustDomains: worker.trustDomains ?? [],
|
|
70
|
+
region: worker.region ?? null,
|
|
71
|
+
labels: worker.labels ?? {},
|
|
72
|
+
resourceProvider: worker.resourceProvider ?? null,
|
|
73
|
+
resourceHealthy: worker.resourceHealthy ?? null,
|
|
74
|
+
resourceUsedPercent: worker.resourceUsedPercent ?? null,
|
|
75
|
+
resourceRemainingPercent: worker.resourceRemainingPercent ?? null,
|
|
76
|
+
resourceResetAt: worker.resourceResetAt ?? null,
|
|
77
|
+
resourceResetInMinutes: worker.resourceResetInMinutes ?? null,
|
|
78
|
+
resourceWindows: worker.resourceWindows ?? null,
|
|
79
|
+
browserWorkspaceCapacity: worker.browserWorkspaceCapacity ?? null,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
function workerGateResult(worker, requirements) {
|
|
83
|
+
const rejectionReasons = [];
|
|
84
|
+
if (worker.availability === 'offline')
|
|
85
|
+
rejectionReasons.push('worker_offline');
|
|
86
|
+
if (requirements.runtime && worker.runtime !== requirements.runtime)
|
|
87
|
+
rejectionReasons.push('runtime_constraint');
|
|
88
|
+
if (worker.adapter === 'chatgpt' && worker.browserWorkspaceCapacity?.available === 0)
|
|
89
|
+
rejectionReasons.push('browser_workspace_exhausted');
|
|
90
|
+
return { worker_id: worker.workerId, eligible: rejectionReasons.length === 0, rejection_reasons: rejectionReasons };
|
|
91
|
+
}
|
|
92
|
+
function executionRouteAuditCandidate(route) {
|
|
93
|
+
return {
|
|
94
|
+
id: route.id,
|
|
95
|
+
worker: workerAuditCandidate(route.worker),
|
|
96
|
+
model: {
|
|
97
|
+
id: route.model.id,
|
|
98
|
+
provider: route.model.provider,
|
|
99
|
+
model: route.model.model,
|
|
100
|
+
profile: route.model.profile ?? null,
|
|
101
|
+
reasoning: route.model.reasoning ?? null,
|
|
102
|
+
resourceHealthy: route.model.resourceHealthy ?? null,
|
|
103
|
+
resourceUsedPercent: route.model.resourceUsedPercent ?? null,
|
|
104
|
+
resourceRemainingPercent: route.model.resourceRemainingPercent ?? null,
|
|
105
|
+
resourceResetAt: route.model.resourceResetAt ?? null,
|
|
106
|
+
resourceResetInMinutes: route.model.resourceResetInMinutes ?? null,
|
|
107
|
+
resourceWindows: route.model.resourceWindows ?? null,
|
|
108
|
+
},
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
export function makeExecutionDecisionAudit(input) {
|
|
112
|
+
const routeRecords = input.routes.map(executionRouteAuditCandidate);
|
|
113
|
+
const selectedRecord = executionRouteAuditCandidate(input.selected);
|
|
114
|
+
const workerGateResults = input.workers.map(worker => workerGateResult(worker, input.requirements));
|
|
115
|
+
return {
|
|
116
|
+
record_type: 'decision',
|
|
117
|
+
schema_version: DECISION_AUDIT_SCHEMA_VERSION,
|
|
118
|
+
decision_id: decisionAuditId(),
|
|
119
|
+
timestamp: input.routing.decidedAt,
|
|
120
|
+
correlation: {
|
|
121
|
+
job_id: input.task?.jobId,
|
|
122
|
+
task_id: input.task?.id,
|
|
123
|
+
execution_id: input.task?.executionId,
|
|
124
|
+
attempt: input.task?.attempt,
|
|
125
|
+
},
|
|
126
|
+
task: taskAuditFacts(input.task),
|
|
127
|
+
worker: workerAuditCandidate(input.selected.worker),
|
|
128
|
+
contract: input.contract,
|
|
129
|
+
policy: {
|
|
130
|
+
path: input.policy.path,
|
|
131
|
+
hash: input.policy.hash,
|
|
132
|
+
snapshot: input.policy.snapshot,
|
|
133
|
+
rules: input.policy.rules,
|
|
134
|
+
},
|
|
135
|
+
candidates: routeRecords,
|
|
136
|
+
gate_results: routeRecords.map(record => ({ candidate_id: String(record.id), eligible: true, rejection_reasons: [] })),
|
|
137
|
+
eligible_candidates: routeRecords,
|
|
138
|
+
selected: selectedRecord,
|
|
139
|
+
engine: input.routing.decidedBy,
|
|
140
|
+
fallback: { used: input.routing.decisionEvidence?.fallback ?? false, reason: input.routing.decisionEvidence?.error },
|
|
141
|
+
decision_evidence: input.routing.decisionEvidence,
|
|
142
|
+
worker_candidates: input.workers.map(workerAuditCandidate),
|
|
143
|
+
worker_gate_results: workerGateResults,
|
|
144
|
+
};
|
|
145
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { chooseWithDecision } from './decision.js';
|
|
2
|
-
import {
|
|
2
|
+
import { makeExecutionDecisionAudit } from './decision-audit.js';
|
|
3
3
|
import { discoverModelCandidates } from './model-routing.js';
|
|
4
4
|
import { loadExecutionRouterRules, loadRoutingPolicy, policyAllows } from './routing-policy.js';
|
|
5
5
|
import { DEFAULT_CHATGPT_PREFERRED_CONCURRENCY, eligibleWorkerCandidates } from './worker-routing.js';
|
|
@@ -134,9 +134,12 @@ export async function routeExecution(workers, requirements, options = {}) {
|
|
|
134
134
|
decidedAt: new Date().toISOString(),
|
|
135
135
|
decisionEvidence: choice.evidence,
|
|
136
136
|
};
|
|
137
|
-
const audit =
|
|
137
|
+
const audit = makeExecutionDecisionAudit({
|
|
138
138
|
task: options.auditTask,
|
|
139
|
-
|
|
139
|
+
workers,
|
|
140
|
+
requirements,
|
|
141
|
+
routes,
|
|
142
|
+
selected,
|
|
140
143
|
contract: {
|
|
141
144
|
question: 'execution-route-selection',
|
|
142
145
|
task: options.taskFacts ?? {},
|
|
@@ -146,9 +149,6 @@ export async function routeExecution(workers, requirements, options = {}) {
|
|
|
146
149
|
candidateRoutes: routes.map(route => ({ id: route.id, workerId: route.worker.workerId, adapter: route.worker.adapter })),
|
|
147
150
|
},
|
|
148
151
|
policy,
|
|
149
|
-
candidates: routes.map(route => ({ ...route.model, id: route.id })),
|
|
150
|
-
eligibleCandidates: routes.map(route => ({ ...route.model, id: route.id })),
|
|
151
|
-
selected: { ...selected.model, id: selected.id },
|
|
152
152
|
routing,
|
|
153
153
|
});
|
|
154
154
|
routing.decisionId = audit.decision_id;
|