cueapril 0.0.0-stage → 1.2.0
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 +173 -2
- package/agents.mjs +996 -0
- package/cli.mjs +4 -0
- package/client.mjs +360 -0
- package/commands.mjs +1273 -0
- package/doctor.mjs +186 -0
- package/http.mjs +263 -0
- package/init.mjs +635 -0
- package/io.mjs +379 -0
- package/key-store.mjs +287 -0
- package/login.mjs +601 -0
- package/package.json +39 -4
- package/skill/cueapril-qa/SKILL.md +90 -0
package/cli.mjs
ADDED
package/client.mjs
ADDED
|
@@ -0,0 +1,360 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
|
|
3
|
+
export const CLI_VERSION = '1.2.0';
|
|
4
|
+
export const CLIENT_IDENTIFIER = `cli/${CLI_VERSION}`;
|
|
5
|
+
export const USER_AGENT = `cueapril-cli/${CLI_VERSION}`;
|
|
6
|
+
export const DEFAULT_BASE_URL = 'https://app.cueapril.com';
|
|
7
|
+
/** The public package-manager entry point for people and coding agents. */
|
|
8
|
+
export const RUN_COMMAND = 'npx -y cueapril@latest';
|
|
9
|
+
export const AGENT_TOOL_PREFIX = 'cueapril_';
|
|
10
|
+
/** Older clients called tools with this prefix; the server still accepts it on calls. */
|
|
11
|
+
export const LEGACY_AGENT_TOOL_PREFIX = 'tenhaw_';
|
|
12
|
+
/** Mirrors AGENT_CLIENT_HEADER in the API's agent contract (header names are case-insensitive). */
|
|
13
|
+
export const AGENT_CLIENT_HEADER = 'X-CueApril-Client';
|
|
14
|
+
export const RESPONSE_LIMIT_BYTES = 10_000_000;
|
|
15
|
+
/** Rate limits and gateway or origin outages: worth retrying for a read. */
|
|
16
|
+
export const TRANSIENT_STATUSES = Object.freeze([429, 502, 503, 504, 522, 524]);
|
|
17
|
+
const LOCAL_HOSTS = new Set(['localhost', '127.0.0.1', '[::1]']);
|
|
18
|
+
const TOOL_NAME = /^[a-z][a-z0-9_]{0,127}$/;
|
|
19
|
+
const HEADER_SAFE = /^[\x21-\x7e]+$/;
|
|
20
|
+
// Redirects and certificate failures do not heal on their own.
|
|
21
|
+
const PERMANENT_NETWORK = /redirect|certificate|CERT_|ERR_TLS|SELF_SIGNED|UNABLE_TO_VERIFY|ERR_INVALID_URL/i;
|
|
22
|
+
|
|
23
|
+
export function normalizeBaseUrl(baseUrl) {
|
|
24
|
+
let url;
|
|
25
|
+
try {
|
|
26
|
+
url = new URL(baseUrl);
|
|
27
|
+
} catch {
|
|
28
|
+
throw new Error('The API URL is not a valid URL');
|
|
29
|
+
}
|
|
30
|
+
if (
|
|
31
|
+
url.username ||
|
|
32
|
+
url.password ||
|
|
33
|
+
!['https:', 'http:'].includes(url.protocol) ||
|
|
34
|
+
(url.protocol === 'http:' && !LOCAL_HOSTS.has(url.hostname)) ||
|
|
35
|
+
url.search ||
|
|
36
|
+
url.hash
|
|
37
|
+
)
|
|
38
|
+
throw new Error('Use HTTPS, or HTTP on localhost, for the API URL, without credentials, query or fragment');
|
|
39
|
+
return url.origin + url.pathname.replace(/\/+$/, '');
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** Accepts `get_run`, `cueapril_get_run` or the legacy `tenhaw_get_run`. */
|
|
43
|
+
export function agentToolName(name) {
|
|
44
|
+
const value = String(name ?? '');
|
|
45
|
+
const canonical = value.startsWith(LEGACY_AGENT_TOOL_PREFIX)
|
|
46
|
+
? AGENT_TOOL_PREFIX + value.slice(LEGACY_AGENT_TOOL_PREFIX.length)
|
|
47
|
+
: value;
|
|
48
|
+
const full = canonical.startsWith(AGENT_TOOL_PREFIX) ? canonical : AGENT_TOOL_PREFIX + canonical;
|
|
49
|
+
if (!TOOL_NAME.test(full)) throw new Error('Tool names use lowercase letters, digits and underscores');
|
|
50
|
+
return full;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function errorDetail(body) {
|
|
54
|
+
if (!body || typeof body !== 'object' || Array.isArray(body)) return '';
|
|
55
|
+
const parts = [];
|
|
56
|
+
const add = (value) => {
|
|
57
|
+
if ((typeof value === 'string' || typeof value === 'number') && String(value) && !parts.includes(String(value))) parts.push(String(value));
|
|
58
|
+
};
|
|
59
|
+
if (body.error && typeof body.error === 'object') {
|
|
60
|
+
add(body.error.code);
|
|
61
|
+
add(body.error.message);
|
|
62
|
+
} else add(body.error);
|
|
63
|
+
for (const key of ['errorCode', 'code', 'message', 'error_description']) add(body[key]);
|
|
64
|
+
return parts
|
|
65
|
+
.join(': ')
|
|
66
|
+
.replace(/[\u0000-\u001f\u007f-\u009f]+/g, ' ')
|
|
67
|
+
.slice(0, 300);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export class QualityApiError extends Error {
|
|
71
|
+
constructor(status, body, { retryAfterMs } = {}) {
|
|
72
|
+
const detail = errorDetail(body);
|
|
73
|
+
super(`CueApril API rejected the request (${status}${detail ? `: ${detail}` : ''})`);
|
|
74
|
+
this.name = 'QualityApiError';
|
|
75
|
+
this.status = status;
|
|
76
|
+
this.body = body;
|
|
77
|
+
this.detail = detail;
|
|
78
|
+
if (retryAfterMs !== undefined) this.retryAfterMs = retryAfterMs;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export class QualityNetworkError extends Error {
|
|
83
|
+
constructor(cause, transient) {
|
|
84
|
+
const timedOut = cause?.name === 'TimeoutError';
|
|
85
|
+
const reason = timedOut ? 'the request timed out' : networkReason(cause);
|
|
86
|
+
super(
|
|
87
|
+
/redirect/i.test(reason)
|
|
88
|
+
? 'The API answered with a redirect, which the CLI does not follow. Check CUEAPRIL_URL.'
|
|
89
|
+
: `Could not reach the CueApril API (${reason})`,
|
|
90
|
+
);
|
|
91
|
+
this.name = 'QualityNetworkError';
|
|
92
|
+
this.transient = transient;
|
|
93
|
+
this.timedOut = timedOut;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function networkReason(error) {
|
|
98
|
+
if (error?.name === 'AbortError') return 'the request was aborted';
|
|
99
|
+
const cause = error?.cause;
|
|
100
|
+
const code = typeof cause?.code === 'string' ? cause.code : '';
|
|
101
|
+
const message = typeof cause?.message === 'string' ? cause.message : typeof error?.message === 'string' ? error.message : '';
|
|
102
|
+
return (
|
|
103
|
+
[code, message === code ? '' : message]
|
|
104
|
+
.filter(Boolean)
|
|
105
|
+
.join(' ')
|
|
106
|
+
.replace(/[\u0000-\u001f\u007f-\u009f]+/g, ' ')
|
|
107
|
+
.slice(0, 200) || 'network error'
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function asNetworkError(error) {
|
|
112
|
+
if (error?.name === 'TimeoutError' || error?.name === 'AbortError') return new QualityNetworkError(error, true);
|
|
113
|
+
if (error instanceof TypeError && ['fetch failed', 'terminated'].includes(error.message))
|
|
114
|
+
return new QualityNetworkError(error, !PERMANENT_NETWORK.test(networkReason(error)));
|
|
115
|
+
return error;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export function retryAfterMs(value, now = Date.now()) {
|
|
119
|
+
if (typeof value !== 'string' || !value.trim()) return undefined;
|
|
120
|
+
if (/^\d+$/.test(value.trim())) return Number(value.trim()) * 1000;
|
|
121
|
+
const date = Date.parse(value);
|
|
122
|
+
return Number.isNaN(date) ? undefined : Math.max(0, date - now);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
async function readBounded(response, limit) {
|
|
126
|
+
const declared = Number(response.headers?.get?.('content-length'));
|
|
127
|
+
if (Number.isFinite(declared) && declared > limit) {
|
|
128
|
+
response.body?.cancel?.().catch(() => {});
|
|
129
|
+
throw new Error('API response exceeds client limit');
|
|
130
|
+
}
|
|
131
|
+
if (!response.body) return '';
|
|
132
|
+
const reader = response.body.getReader();
|
|
133
|
+
const chunks = [];
|
|
134
|
+
let total = 0;
|
|
135
|
+
for (;;) {
|
|
136
|
+
let chunk;
|
|
137
|
+
try {
|
|
138
|
+
chunk = await reader.read();
|
|
139
|
+
} catch (error) {
|
|
140
|
+
throw asNetworkError(error);
|
|
141
|
+
}
|
|
142
|
+
if (chunk.done) break;
|
|
143
|
+
total += chunk.value.byteLength;
|
|
144
|
+
if (total > limit) {
|
|
145
|
+
reader.cancel().catch(() => {});
|
|
146
|
+
throw new Error('API response exceeds client limit');
|
|
147
|
+
}
|
|
148
|
+
chunks.push(chunk.value);
|
|
149
|
+
}
|
|
150
|
+
return Buffer.concat(chunks).toString('utf8');
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
export function isTransientError(error) {
|
|
154
|
+
if (error instanceof QualityApiError) return TRANSIENT_STATUSES.includes(error.status);
|
|
155
|
+
return error instanceof QualityNetworkError && error.transient;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/** Capped exponential backoff: 1, 2, 4, 8, 16, 30, 30 ... seconds, raised to a Retry-After hint up to 60 s. */
|
|
159
|
+
export function retryDelayMs(attempt, error) {
|
|
160
|
+
const backoff = Math.min(30_000, 1000 * 2 ** Math.max(0, attempt - 1));
|
|
161
|
+
const hinted = error?.retryAfterMs;
|
|
162
|
+
return typeof hinted === 'number' && hinted > backoff ? Math.min(60_000, hinted) : backoff;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Repeats an operation after transient failures. Only reads, or a start that
|
|
167
|
+
* resends the same idempotency key, may be passed here: a retried mutation
|
|
168
|
+
* without one could act twice.
|
|
169
|
+
*/
|
|
170
|
+
export async function retrying(operation, { attempts = 5, sleep, onRetry } = {}) {
|
|
171
|
+
for (let attempt = 1; ; attempt += 1) {
|
|
172
|
+
try {
|
|
173
|
+
return await operation(attempt);
|
|
174
|
+
} catch (error) {
|
|
175
|
+
if (!isTransientError(error) || attempt >= attempts) throw error;
|
|
176
|
+
const delay = retryDelayMs(attempt, error);
|
|
177
|
+
onRetry?.(error, delay, attempt);
|
|
178
|
+
await sleep(delay);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
export class QualityClient {
|
|
184
|
+
constructor({
|
|
185
|
+
baseUrl,
|
|
186
|
+
token,
|
|
187
|
+
fetch: transport = (url, init) => globalThis.fetch(url, init),
|
|
188
|
+
timeoutMs = 30000,
|
|
189
|
+
authMode = 'human',
|
|
190
|
+
client = CLIENT_IDENTIFIER,
|
|
191
|
+
userAgent = USER_AGENT,
|
|
192
|
+
}) {
|
|
193
|
+
this.baseUrl = normalizeBaseUrl(baseUrl);
|
|
194
|
+
if (!token) throw new Error('An API key or token is required');
|
|
195
|
+
// Never echo the value: a rejected header would print it in the error.
|
|
196
|
+
if (!HEADER_SAFE.test(token)) throw new Error('The API key or token contains characters that cannot be sent in a header');
|
|
197
|
+
this.token = token;
|
|
198
|
+
this.transport = transport;
|
|
199
|
+
this.timeoutMs = timeoutMs;
|
|
200
|
+
this.authMode = authMode;
|
|
201
|
+
this.client = client;
|
|
202
|
+
this.userAgent = userAgent;
|
|
203
|
+
}
|
|
204
|
+
async request(path, { method = 'GET', body, idempotencyKey, timeoutMs = this.timeoutMs } = {}) {
|
|
205
|
+
const headers = {
|
|
206
|
+
Authorization: `Bearer ${this.token}`,
|
|
207
|
+
Accept: 'application/json',
|
|
208
|
+
'User-Agent': this.userAgent,
|
|
209
|
+
[AGENT_CLIENT_HEADER]: this.client,
|
|
210
|
+
...(body !== undefined ? { 'Content-Type': 'application/json' } : {}),
|
|
211
|
+
...(idempotencyKey ? { 'Idempotency-Key': idempotencyKey } : {}),
|
|
212
|
+
};
|
|
213
|
+
let response;
|
|
214
|
+
try {
|
|
215
|
+
response = await this.transport(`${this.baseUrl}/api/v1/quality${path}`, {
|
|
216
|
+
method,
|
|
217
|
+
redirect: 'error',
|
|
218
|
+
signal: AbortSignal.timeout(timeoutMs),
|
|
219
|
+
headers,
|
|
220
|
+
...(body !== undefined ? { body: JSON.stringify(body) } : {}),
|
|
221
|
+
});
|
|
222
|
+
} catch (error) {
|
|
223
|
+
throw asNetworkError(error);
|
|
224
|
+
}
|
|
225
|
+
const raw = await readBounded(response, RESPONSE_LIMIT_BYTES);
|
|
226
|
+
let value = null;
|
|
227
|
+
if (raw) {
|
|
228
|
+
try {
|
|
229
|
+
value = JSON.parse(raw);
|
|
230
|
+
} catch {
|
|
231
|
+
// Gateways answer outages with HTML; the status still decides retries.
|
|
232
|
+
if (response.ok) throw new Error('API returned invalid JSON');
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
if (!response.ok)
|
|
236
|
+
throw new QualityApiError(response.status, value, { retryAfterMs: retryAfterMs(response.headers?.get?.('retry-after') ?? undefined) });
|
|
237
|
+
return value;
|
|
238
|
+
}
|
|
239
|
+
/** POST /api/v1/quality/agent-tools/<name>: the REST adapter over the MCP tool catalogue. */
|
|
240
|
+
callTool(name, args = {}, { idempotencyKey, timeoutMs } = {}) {
|
|
241
|
+
if (!TOOL_NAME.test(name)) throw new Error('Invalid tool name');
|
|
242
|
+
return this.request(`/agent-tools/${name}`, { method: 'POST', body: args, idempotencyKey, timeoutMs });
|
|
243
|
+
}
|
|
244
|
+
async call(action,args={}) {
|
|
245
|
+
if(this.authMode==='oauth'){const mapping={'runner_pools.keys.get':'get_runner_keys','runs.telemetry':'get_run_telemetry','reuse.inspect':'inspect_evidence_reuse','reuse.record':'record_evidence_reuse','reuse.list':'list_evidence_reuse','reuse.policies.list':'list_reuse_policies','reruns.propose':'propose_rerun','reruns.draft':'draft_rerun','reruns.start':'start_rerun','library.lineage':'get_library_lineage','quarantines.list':'list_quarantines','performance.compare':'compare_performance','first_assessments.readiness':'read_first_assessment','first_assessments.start':'start_first_assessment','first_assessments.report':'get_first_assessment_report','samples.list':'list_samples','performance.browser_quote':'quote_browser_performance','performance.weighted_http_quote':'quote_weighted_http_performance','clarifications.assess':'assess_clarifications','clarifications.assessments':'get_clarification_assessments','performance.campaign_quote':'quote_performance_campaign','locator_repairs.list':'list_locator_repairs','locator_repairs.get':'get_locator_repair','locator_repairs.export':'export_locator_repair','evaluations.list':'list_evaluations','evaluations.get':'get_evaluation','evaluations.export':'export_evaluation','context.impacts':'get_context_impacts','forecast.scenario':'forecast_scenario','resources.list':'list_test_resources','waivers.list':'list_waivers','waivers.get':'get_waiver','setup.get':'get_setup_proposal','setup.propose':'propose_setup','setup.apply':'apply_setup_proposal','reports.catalog':'get_report_catalog','reports.list':'list_reports','reports.get':'get_report','reports.export':'export_report','reports.assemble':'assemble_reports','releases.components.get':'get_release_components','releases.components.verify':'verify_release_components','knowledge.overview':'get_knowledge_overview','knowledge.search':'search_knowledge','knowledge.get':'get_knowledge','missions.readiness':'read_mission_readiness','missions.start':'start_mission','missions.report':'get_mission_report','connections.assignee_routing':'get_assignee_routing','projects.list':'list_projects','projects.get':'get_project','library.list':'list_library','library.get':'get_library_item','library.create':'upsert_test_draft','standards.list':'get_standards','plans.get':'get_plan','plans.propose':'propose_plan','plans.create':'plan_run','estimates.create':'estimate_run','runs.create':'start_run','runs.get':'get_run','runs.events':'get_run_events','runs.cancel':'cancel_run','findings.list':'list_findings','findings.retest':'retest_finding','findings.verify':'verify_finding','findings.regression':'draft_finding_regression','evidence.get':'get_evidence','coverage.get':'get_coverage','costs.get':'get_costs','performance.quote':'quote_performance','performance.purchase':'purchase_performance'};if(!Object.hasOwn(mapping,action))throw new Error('Unsupported delegated operation');return this.request('/agent-tools/'+AGENT_TOOL_PREFIX+mapping[action],{method:'POST',body:args,idempotencyKey:args.idempotency_key});}
|
|
246
|
+
const {idempotency_key,...body}=args;const enc=encodeURIComponent;const id=body.id||body.run_id;
|
|
247
|
+
if(action.startsWith('developer_review.')) {
|
|
248
|
+
const operation=action.split('.')[1];
|
|
249
|
+
if(operation==='list')return this.request('/developer-review?'+new URLSearchParams(Object.entries(body).map(([key,value])=>[key,String(value)])));
|
|
250
|
+
if(operation==='context')return this.request('/developer-review/context',{method:'POST',body});
|
|
251
|
+
if(operation==='export') {if(typeof body.id!=='string'||!body.id)throw new Error('Patch ID is required');delete body.id;return this.request('/developer-review/patches/'+enc(id)+'/export',{method:'POST',body});}
|
|
252
|
+
if(!['thread','comment','patch','approve'].includes(operation))throw new Error('Unsupported source review operation');
|
|
253
|
+
if(!idempotency_key)throw new Error('An explicit stable idempotency_key is required for source review writes');
|
|
254
|
+
let path=operation==='thread'?'/developer-review/threads':operation==='patch'?'/developer-review/patches':undefined;
|
|
255
|
+
if(!path){if(typeof body.id!=='string'||!body.id)throw new Error('Review record ID is required');delete body.id;path=operation==='comment'?'/developer-review/threads/'+enc(id)+'/comments':'/developer-review/patches/'+enc(id)+'/approve';}
|
|
256
|
+
return this.request(path,{method:'POST',body,idempotencyKey:idempotency_key});
|
|
257
|
+
}
|
|
258
|
+
if(action.startsWith('connections.entra.')){if(typeof body.connection_id!=='string'||!body.connection_id)throw new Error('connection_id is required');const operation=action.split('.')[2];if(!['get','enroll-certificate','prepare','activate','rollback','retire','graph-add','graph-remove','reconcile'].includes(operation))throw new Error('Unsupported Entra rotation operation');const path='/integrations/connections/'+enc(body.connection_id)+'/entra-rotation';delete body.connection_id;if(operation==='get')return this.request(path);if(!idempotency_key)throw new Error('An explicit stable idempotency_key is required for credential operations');return this.request(path+'/'+operation,{method:'POST',body,idempotencyKey:idempotency_key});}
|
|
259
|
+
if(action.startsWith('credentials.keys.')){const operation=action.split('.')[2];if(operation==='get')return this.request('/integrations/credential-keys');if(!['prepare','activate','rewrap','retire'].includes(operation))throw new Error('Unsupported wrapping-key operation');return this.request('/integrations/credential-keys/'+operation,{method:'POST',body,idempotencyKey:idempotency_key||randomUUID()});}
|
|
260
|
+
if(action.startsWith('rollout.')){const operation=action.split('.')[1];if(operation==='get')return this.request('/rollout');if(!['inventory','checklist','connections','transition','deprecations'].includes(operation))throw new Error('Unsupported rollout operation');return this.request('/rollout/'+operation,{method:'POST',body,idempotencyKey:idempotency_key||randomUUID()});}
|
|
261
|
+
if(action.startsWith('runner_pools.keys.')){if(typeof id!=='string'||!id)throw new Error('Runner pool ID is required');const operation=action.split('.')[2];if(!['get','prepare','activate','retire','cancel'].includes(operation))throw new Error('Unsupported runner key operation');const path='/runner-pools/'+enc(id)+'/keys';if(operation==='get')return this.request(path);delete body.id;return this.request(path+'/'+operation,{method:'POST',body,idempotencyKey:idempotency_key||randomUUID()});}
|
|
262
|
+
if(action==='runs.telemetry'){if(typeof id!=='string'||!id)throw new Error('Run ID is required');return this.request('/runs/'+enc(id)+'/telemetry');}
|
|
263
|
+
if(action.startsWith('telemetry.sessions.')){const operation=action.split('.')[2];if(!['start','pause','resume','finish'].includes(operation))throw new Error('Unsupported recorded session operation');if(operation==='start')return this.request('/telemetry/sessions',{method:'POST',body,idempotencyKey:idempotency_key||randomUUID()});if(typeof id!=='string'||!id)throw new Error('Recorded session ID is required');delete body.id;return this.request('/telemetry/sessions/'+enc(id)+'/'+operation,{method:'POST',body,idempotencyKey:idempotency_key||randomUUID()});}
|
|
264
|
+
if(action==='reuse.inspect')return this.request('/reuse/inspect',{method:'POST',body});
|
|
265
|
+
if(action==='reuse.record')return this.request('/reuse',{method:'POST',body,idempotencyKey:idempotency_key||randomUUID()});
|
|
266
|
+
if(action==='reuse.list'||action==='reuse.policies.list'){const params=new URLSearchParams();for(const key of ['project_id','source_run_id','id'])if(body[key]!==undefined)params.set(key,String(body[key]));return this.request((action==='reuse.list'?'/reuse':'/reuse/policies')+'?'+params);}
|
|
267
|
+
if(action.startsWith('reuse.policies.')){const operation=action.split('.')[2];if(operation==='create')return this.request('/reuse/policies',{method:'POST',body,idempotencyKey:idempotency_key||randomUUID()});if(!['revise','pause','resume'].includes(operation))throw new Error('Unsupported reuse policy operation');if(typeof body.id!=='string'||!body.id)throw new Error('Reuse policy ID is required');const policy=body.id;delete body.id;return this.request('/reuse/policies/'+enc(policy)+'/'+operation,{method:'POST',body,idempotencyKey:idempotency_key||randomUUID()});}
|
|
268
|
+
if(action.startsWith('reruns.')){const operation=action.split('.')[1];if(!['propose','draft','start'].includes(operation))throw new Error('Unsupported rerun operation');return this.request('/reruns/'+operation,{method:'POST',body,...(operation==='propose'?{}:{idempotencyKey:idempotency_key||randomUUID()})});}
|
|
269
|
+
if(action==='library.lineage'){const params=new URLSearchParams();for(const key of ['project_id','id'])if(body[key]!==undefined)params.set(key,String(body[key]));return this.request('/library/lineage?'+params);}
|
|
270
|
+
if(action==='library.replacement')return this.request('/library/replacement',{method:'POST',body,idempotencyKey:idempotency_key||randomUUID()});
|
|
271
|
+
if(action.startsWith('quarantines.')){const operation=action.split('.')[1];if(operation==='list'){const params=new URLSearchParams();for(const key of ['project_id','id'])if(body[key]!==undefined)params.set(key,String(body[key]));return this.request('/quarantines?'+params);}if(operation==='create')return this.request('/quarantines',{method:'POST',body,idempotencyKey:idempotency_key||randomUUID()});if(!['revise','reassign','pause','resume','close'].includes(operation))throw new Error('Unsupported quarantine operation');if(typeof body.id!=='string'||!body.id)throw new Error('Quarantine ID is required');const policy=body.id;delete body.id;return this.request('/quarantines/'+enc(policy)+'/'+operation,{method:'POST',body,idempotencyKey:idempotency_key||randomUUID()});}
|
|
272
|
+
if(action==='performance.compare'){const params=new URLSearchParams();for(const key of ['run_id','task_id','baseline_id','baseline_task_id'])if(body[key]!==undefined)params.set(key,String(body[key]));return this.request('/performance/comparison?'+params);}
|
|
273
|
+
if(action==='first_assessments.readiness'){const params=new URLSearchParams();for(const key of ['project_id','plan_id'])if(body[key]!==undefined)params.set(key,String(body[key]));return this.request('/first-assessments/readiness?'+params);}
|
|
274
|
+
if(action==='first_assessments.start')return this.request('/first-assessments/start',{method:'POST',body,idempotencyKey:idempotency_key||randomUUID()});
|
|
275
|
+
if(action==='first_assessments.report'){if(typeof id!=='string'||!id)throw new Error('Assessment run ID is required');return this.request('/first-assessments/'+enc(id));}
|
|
276
|
+
if(action==='samples.list')return this.request('/samples');
|
|
277
|
+
if(action==='samples.activate'){if(typeof body.sample_id!=='string'||!body.sample_id)throw new Error('Sample ID is required');const sample=body.sample_id;delete body.sample_id;return this.request('/samples/'+enc(sample)+'/activate',{method:'POST',body,idempotencyKey:idempotency_key||randomUUID()});}
|
|
278
|
+
if(action==='clarifications.assess')return this.request('/clarifications/assess',{method:'POST',body,idempotencyKey:idempotency_key||randomUUID()});
|
|
279
|
+
if(action==='clarifications.assessments'){const params=new URLSearchParams();for(const key of ['project_id','plan_id','setup_proposal_id','impact_id'])if(body[key]!==undefined)params.set(key,String(body[key]));return this.request('/clarifications/assessments?'+params);}
|
|
280
|
+
if(['performance.campaign_quote','performance.browser_quote','performance.weighted_http_quote'].includes(action))return this.request('/performance/quote',{method:'POST',body,idempotencyKey:idempotency_key||randomUUID()});
|
|
281
|
+
if(action.startsWith('locator_repairs.')){const operation=action.split('.')[1];if(operation==='list')return this.request('/locator-repairs?run_id='+enc(body.run_id));if(operation==='create')return this.request('/locator-repairs',{method:'POST',body,idempotencyKey:idempotency_key||randomUUID()});if(typeof body.id!=='string'||!body.id)throw new Error('Locator repair ID is required');if(operation==='get')return this.request('/locator-repairs/'+enc(body.id));if(operation==='export')return this.request('/locator-repairs/'+enc(body.id)+'/export?format='+enc(body.format||'json'));if(!['approve','validate','revoke'].includes(operation))throw new Error('Unsupported locator repair operation');const repair=body.id;delete body.id;return this.request('/locator-repairs/'+enc(repair)+'/'+operation,{method:'POST',body,idempotencyKey:idempotency_key||randomUUID()});}
|
|
282
|
+
if(action==='context.impacts')return this.request('/context/impacts?'+new URLSearchParams(Object.entries(body).map(([key,value])=>[key,String(value)])));
|
|
283
|
+
if(action==='context.impacts.repair')return this.request('/context/impacts/repair',{method:'POST',body,idempotencyKey:idempotency_key||randomUUID()});
|
|
284
|
+
if(action==='sources.withdraw'){if(typeof body.id!=='string'||!body.id)throw new Error('Source ID is required');delete body.id;return this.request('/sources/'+enc(id)+'/withdraw',{method:'POST',body:{...body,idempotency_key:idempotency_key||randomUUID()}});}
|
|
285
|
+
if(action.startsWith('evaluations.')) {
|
|
286
|
+
const operation=action.split('.')[1];
|
|
287
|
+
if(operation==='list')return this.request('/evaluations?project_id='+enc(body.project_id));
|
|
288
|
+
if(operation==='create')return this.request('/evaluations',{method:'POST',body,idempotencyKey:idempotency_key||randomUUID()});
|
|
289
|
+
if(typeof id!=='string'||!id)throw new Error('Evaluation ID is required');
|
|
290
|
+
if(operation==='get')return this.request('/evaluations/'+enc(id));
|
|
291
|
+
if(operation==='export')return this.request('/evaluations/'+enc(id)+'/export?format='+enc(body.format||'json'));
|
|
292
|
+
if(!['revise','approve','observe','close'].includes(operation))throw new Error('Unsupported evaluation operation');
|
|
293
|
+
delete body.id;return this.request('/evaluations/'+enc(id)+'/'+operation,{method:'POST',body,idempotencyKey:idempotency_key||randomUUID()});
|
|
294
|
+
}
|
|
295
|
+
if(action==='forecast.scenario'){const params=new URLSearchParams();for(const [key,value] of Object.entries(body))if(value!==undefined)params.set(key,String(value));return this.request('/costs/forecast?'+params);}
|
|
296
|
+
if(action==='resources.list')return this.request('/resources'+(body.project_id?'?project_id='+enc(body.project_id):''));
|
|
297
|
+
if(action==='resources.resolve'){if(typeof body.id!=='string'||!body.id)throw new Error('Resource lease ID is required');const lease=body.id;delete body.id;return this.request('/resources/'+enc(lease)+'/resolve',{method:'POST',body,idempotencyKey:idempotency_key||randomUUID()});}
|
|
298
|
+
if(action.startsWith('setup.')) {
|
|
299
|
+
if(action==='setup.propose')return this.request('/setup/proposals',{method:'POST',body,idempotencyKey:idempotency_key||randomUUID()});
|
|
300
|
+
if(typeof id!=='string'||!id)throw new Error('Setup proposal ID is required');
|
|
301
|
+
if(action==='setup.get')return this.request('/setup/proposals/'+enc(id));
|
|
302
|
+
if(action!=='setup.apply')throw new Error('Unsupported setup operation');
|
|
303
|
+
delete body.id;
|
|
304
|
+
return this.request('/setup/proposals/'+enc(id)+'/apply',{method:'POST',body,idempotencyKey:idempotency_key||randomUUID()});
|
|
305
|
+
}
|
|
306
|
+
if(action.startsWith('reports.')) {
|
|
307
|
+
const operation=action.split('.')[1];
|
|
308
|
+
if(operation==='catalog')return this.request('/reports/catalog');
|
|
309
|
+
if(operation==='list')return this.request('/reports?run_id='+enc(body.run_id));
|
|
310
|
+
if(operation==='assemble')return this.request('/reports/assemble',{method:'POST',body,idempotencyKey:idempotency_key||randomUUID()});
|
|
311
|
+
if(typeof id!=='string'||!id)throw new Error('Report ID is required');
|
|
312
|
+
if(operation==='get')return this.request('/reports/'+enc(id));
|
|
313
|
+
if(operation==='export')return this.request('/reports/'+enc(id)+'/export?format='+enc(body.format||'json'));
|
|
314
|
+
if(!['revise','sign','revoke'].includes(operation))throw new Error('Unsupported report operation');
|
|
315
|
+
delete body.id;
|
|
316
|
+
return this.request('/reports/'+enc(id)+'/'+operation,{method:'POST',body,idempotencyKey:idempotency_key||randomUUID()});
|
|
317
|
+
}
|
|
318
|
+
if(action.startsWith('waivers.')) {
|
|
319
|
+
const operation=action.split('.')[1];
|
|
320
|
+
if(operation==='list'){const query=new URLSearchParams();for(const field of ['release_id','project_id'])if(body[field]!==undefined)query.set(field,String(body[field]));return this.request('/waivers'+(query.size?'?'+query:''));}
|
|
321
|
+
if(operation==='get')return this.request('/waivers/'+enc(id));
|
|
322
|
+
if(!['request','approve','revoke','close'].includes(operation))throw new Error('Unsupported waiver operation');
|
|
323
|
+
if(operation!=='request'&&(!id||typeof id!=='string'))throw new Error('Waiver ID is required');
|
|
324
|
+
delete body.id;
|
|
325
|
+
return this.request(operation==='request'?'/waivers/request':'/waivers/'+enc(id)+'/'+operation,{method:'POST',body,idempotencyKey:idempotency_key||randomUUID()});
|
|
326
|
+
}
|
|
327
|
+
if(['releases.components.get','releases.components.approve','releases.components.verify'].includes(action)) {
|
|
328
|
+
if(typeof id!=='string'||!id)throw new Error('Release ID is required');
|
|
329
|
+
const path='/releases/'+enc(id)+'/components';
|
|
330
|
+
if(action.endsWith('.get'))return this.request(path);
|
|
331
|
+
delete body.id;delete body.run_id;
|
|
332
|
+
return this.request(path+'/'+action.split('.').at(-1),{method:'POST',body,idempotencyKey:idempotency_key||randomUUID()});
|
|
333
|
+
}
|
|
334
|
+
if(action==='knowledge.overview')return this.request('/knowledge/overview');
|
|
335
|
+
if(action==='knowledge.search'){const query=new URLSearchParams();for(const field of ['query','domain','limit'])if(body[field]!==undefined)query.set(field,String(body[field]));return this.request('/knowledge/search?'+query.toString());}
|
|
336
|
+
if(action==='knowledge.get')return this.request('/knowledge/'+enc(id));
|
|
337
|
+
if(action==='missions.readiness'){const query=new URLSearchParams();for(const field of ['project_id','plan_id','environment_id','scope_id'])if(body[field]!==undefined)query.set(field,String(body[field]));return this.request('/missions/readiness'+(query.size?'?'+query.toString():''));}
|
|
338
|
+
if(action==='missions.report')return this.request('/missions/'+enc(id)+'/report');
|
|
339
|
+
if(action==='missions.start')return this.request('/missions/start',{method:'POST',body,idempotencyKey:idempotency_key||randomUUID()});
|
|
340
|
+
if(action==='plans.propose')return this.request('/plans/propose',{method:'POST',body});
|
|
341
|
+
if(action==='workspace.get')return this.request('/workspace');
|
|
342
|
+
if(action==='costs.get')return this.request('/costs/forecast'+(body.project_id?'?project_id='+enc(body.project_id):''));
|
|
343
|
+
if(action==='runs.get')return this.request('/runs/'+enc(id));
|
|
344
|
+
if(action==='runs.events')return this.request(`/runs/${enc(id)}/events${body.cursor?'?after='+enc(body.cursor):''}`);
|
|
345
|
+
if(action==='evidence.get')return this.request(`/runs/${enc(id)}/evidence`);
|
|
346
|
+
if(action.endsWith('.get')||action.endsWith('.list')||action==='coverage.get'||action==='estimates.create') {
|
|
347
|
+
const state=await this.request('/workspace');
|
|
348
|
+
if(action==='estimates.create'){const plan=state.plans.find(p=>p.id===body.plan_id);if(!plan)throw new Error('Plan not found');return {plan_id:plan.id,plan_version:plan.version,maximum_allowance_pence:plan.budget_pence,currency:'GBP',status:'approved_ceiling'};}
|
|
349
|
+
if(action==='coverage.get')return {library:state.library.filter(p=>!body.project_id||p.project_id===body.project_id),runs:state.runs.filter(p=>!body.project_id||p.project_id===body.project_id)};
|
|
350
|
+
const collection=action.split('.')[0];if(!Array.isArray(state[collection]))throw new Error('Unsupported collection');let list=state[collection].filter(p=>!body.project_id||p.project_id===body.project_id||collection==='projects'&&p.id===body.project_id);
|
|
351
|
+
if(body.kind)list=list.filter(p=>p.kind===body.kind);
|
|
352
|
+
if(action.endsWith('.get')){const row=list.find(p=>p.id===(id||body.project_id));if(!row)throw new Error('Resource not found');return row;}return {items:list.slice(0,body.limit||100)};
|
|
353
|
+
}
|
|
354
|
+
if(action.startsWith('connections.')) {if(!body.connection_id)throw new Error('connection_id is required');const path='/integrations/connections/'+enc(body.connection_id)+'/assignee-routing';if(action==='connections.assignee_routing')return this.request(path);if(action==='connections.enroll_assignee'){const {connection_id,...input}=body;return this.request(path,{method:'POST',body:input});}if(action==='connections.revoke_assignee'&&body.resourceId)return this.request(path+'/'+enc(body.resourceId),{method:'DELETE'});throw new Error('Unsupported connection operation');}
|
|
355
|
+
const key=idempotency_key||randomUUID();let path;
|
|
356
|
+
if(action==='performance.quote')path='/performance/quote';else if(action==='performance.purchase')path='/performance/purchase';else if(action.endsWith('.create'))path='/'+action.split('.')[0];else {const [resource,operation]=action.split('.');if(!['runs','findings','plans','standards'].includes(resource)||!['cancel','rerun','retest','verify','regression','update','approve'].includes(operation)||!id)throw new Error('Unsupported command');path=`/${resource}/${enc(id)}/${operation}`;delete body.id;}
|
|
357
|
+
if(action==='runs.create'&&body.expected_head_sha){body.build_identity=body.expected_head_sha;delete body.expected_head_sha;}
|
|
358
|
+
return this.request(path,{method:'POST',body,idempotencyKey:key});
|
|
359
|
+
}
|
|
360
|
+
}
|