@agentspec/sdk 0.2.3 → 0.3.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/LICENSE +183 -0
- package/dist/index.cjs +168 -22
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +50 -15
- package/dist/index.d.ts +50 -15
- package/dist/index.js +168 -23
- package/dist/index.js.map +1 -1
- package/package.json +11 -12
package/LICENSE
ADDED
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship made available under
|
|
36
|
+
the License, as indicated by a copyright notice that is included in
|
|
37
|
+
or attached to the work (an example is provided in the Appendix below).
|
|
38
|
+
|
|
39
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
40
|
+
form, that is based on (or derived from) the Work and for which the
|
|
41
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
42
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
43
|
+
of this License, Derivative Works shall not include works that remain
|
|
44
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
45
|
+
the Work and Derivative Works thereof.
|
|
46
|
+
|
|
47
|
+
"Contribution" shall mean, as submitted to the Licensor for inclusion
|
|
48
|
+
in the Work by the copyright owner or by an individual or Legal Entity
|
|
49
|
+
authorized to submit on behalf of the copyright owner. For the purposes
|
|
50
|
+
of this definition, "submit" means any form of electronic, verbal, or
|
|
51
|
+
written communication sent to the Licensor or its representatives,
|
|
52
|
+
including but not limited to communication on electronic mailing lists,
|
|
53
|
+
source code control systems, and issue tracking systems that are managed
|
|
54
|
+
by, or on behalf of, the Licensor for the purpose of discussing and
|
|
55
|
+
improving the Work, but excluding communication that is conspicuously
|
|
56
|
+
marked or designated in writing by the copyright owner as "Not a
|
|
57
|
+
Contribution."
|
|
58
|
+
|
|
59
|
+
"Contributor" shall mean Licensor and any Legal Entity on behalf of
|
|
60
|
+
whom a Contribution has been received by the Licensor and included
|
|
61
|
+
within the Work.
|
|
62
|
+
|
|
63
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
64
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
65
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
66
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
67
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
68
|
+
Work and such Derivative Works in Source or Object form.
|
|
69
|
+
|
|
70
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
71
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
72
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
73
|
+
(except as stated in this section) patent license to make, have made,
|
|
74
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
75
|
+
where such license applies only to those patent claims licensable
|
|
76
|
+
by such Contributor that are necessarily infringed by their
|
|
77
|
+
Contribution(s) alone or by the combination of their Contribution(s)
|
|
78
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
79
|
+
institute patent litigation against any entity (including a cross-claim
|
|
80
|
+
or counterclaim in a lawsuit) alleging that the Work or any
|
|
81
|
+
Contribution embodied within the Work constitutes direct or
|
|
82
|
+
contributory patent infringement, then any patent licenses granted
|
|
83
|
+
to You under this License for that Work shall terminate as of the
|
|
84
|
+
date such litigation is filed.
|
|
85
|
+
|
|
86
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
87
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
88
|
+
modifications, and in Source or Object form, provided that You
|
|
89
|
+
meet the following conditions:
|
|
90
|
+
|
|
91
|
+
(a) You must give any other recipients of the Work or Derivative
|
|
92
|
+
Works a copy of this License; and
|
|
93
|
+
|
|
94
|
+
(b) You must cause any modified files to carry prominent notices
|
|
95
|
+
stating that You changed the files; and
|
|
96
|
+
|
|
97
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
98
|
+
that You distribute, all copyright, patent, trademark, and
|
|
99
|
+
attribution notices from the Source form of the Work,
|
|
100
|
+
excluding those notices that do not pertain to any part of
|
|
101
|
+
the Derivative Works; and
|
|
102
|
+
|
|
103
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
104
|
+
distribution, You must include a readable copy of the
|
|
105
|
+
attribution notices contained within such NOTICE file, in
|
|
106
|
+
at least one of the following places: within a NOTICE text
|
|
107
|
+
file distributed as part of the Derivative Works; within
|
|
108
|
+
the Source form or documentation, if provided along with the
|
|
109
|
+
Derivative Works; or, within a display generated by the
|
|
110
|
+
Derivative Works, if and wherever such third-party notices
|
|
111
|
+
normally appear. The contents of the NOTICE file are for
|
|
112
|
+
informational purposes only and do not modify the License.
|
|
113
|
+
You may add Your own attribution notices within Derivative
|
|
114
|
+
Works that You distribute, alongside or as an addendum to
|
|
115
|
+
the NOTICE text from the Work, provided that such additional
|
|
116
|
+
attribution notices cannot be construed as modifying the License.
|
|
117
|
+
|
|
118
|
+
You may add Your own license statement for Your modifications and
|
|
119
|
+
may provide additional grant of rights to use, copy, modify, merge,
|
|
120
|
+
publish, distribute, sublicense, and/or sell copies of the
|
|
121
|
+
Derivative Works, as these terms may be expanded or clarified.
|
|
122
|
+
|
|
123
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
124
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
125
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
126
|
+
this License, without any additional terms or conditions.
|
|
127
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
128
|
+
the terms of any separate license agreement you may have executed
|
|
129
|
+
with Licensor regarding such Contributions.
|
|
130
|
+
|
|
131
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
132
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
133
|
+
except as required for reasonable and customary use in describing the
|
|
134
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
135
|
+
|
|
136
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
137
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
138
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
139
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
140
|
+
implied, including, without limitation, any warranties or conditions
|
|
141
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
142
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
143
|
+
appropriateness of using or reproducing the Work and assume any
|
|
144
|
+
risks associated with Your exercise of permissions under this License.
|
|
145
|
+
|
|
146
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
147
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
148
|
+
unless required by applicable law (such as deliberate and grossly
|
|
149
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
150
|
+
liable to You for damages, including any direct, indirect, special,
|
|
151
|
+
incidental, or exemplary damages of any character arising as a
|
|
152
|
+
result of this License or out of the use or inability to use the
|
|
153
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
154
|
+
work stoppage, computer failure or malfunction, or all other
|
|
155
|
+
commercial damages or losses), even if such Contributor has been
|
|
156
|
+
advised of the possibility of such damages.
|
|
157
|
+
|
|
158
|
+
9. Accepting Warranty or Liability. While redistributing the Work or
|
|
159
|
+
Derivative Works thereof, You may choose to offer, and charge a fee
|
|
160
|
+
for, acceptance of support, warranty, indemnity, or other liability
|
|
161
|
+
obligations and/or rights consistent with this License. However, in
|
|
162
|
+
accepting such obligations, You may offer such conditions only on
|
|
163
|
+
Your own behalf and on Your sole responsibility, not on behalf of
|
|
164
|
+
any other Contributor, and only if You agree to indemnify, defend,
|
|
165
|
+
and hold each Contributor harmless for any liability incurred by,
|
|
166
|
+
or claims asserted against, such Contributor by reason of your
|
|
167
|
+
accepting any such warranty or additional liability.
|
|
168
|
+
|
|
169
|
+
END OF TERMS AND CONDITIONS
|
|
170
|
+
|
|
171
|
+
Copyright 2026 Sallah Kokaina
|
|
172
|
+
|
|
173
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
174
|
+
you may not use this file except in compliance with the License.
|
|
175
|
+
You may obtain a copy of the License at
|
|
176
|
+
|
|
177
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
178
|
+
|
|
179
|
+
Unless required by applicable law or agreed to in writing, software
|
|
180
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
181
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
182
|
+
implied. See the License for the specific language governing
|
|
183
|
+
permissions and limitations under the License.
|
package/dist/index.cjs
CHANGED
|
@@ -5,6 +5,7 @@ var zodToJsonSchema = require('zod-to-json-schema');
|
|
|
5
5
|
var fs = require('fs');
|
|
6
6
|
var path = require('path');
|
|
7
7
|
var yaml = require('js-yaml');
|
|
8
|
+
var net = require('net');
|
|
8
9
|
|
|
9
10
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
10
11
|
|
|
@@ -300,7 +301,8 @@ var ComplianceSchema = zod.z.object({
|
|
|
300
301
|
"memory-hygiene",
|
|
301
302
|
"model-resilience",
|
|
302
303
|
"evaluation-coverage",
|
|
303
|
-
"observability"
|
|
304
|
+
"observability",
|
|
305
|
+
"metadata-quality"
|
|
304
306
|
])
|
|
305
307
|
).optional().describe('Compliance rule packs to evaluate during "agentspec audit". Each pack groups related rules. Omit to run all packs.'),
|
|
306
308
|
suppressions: zod.z.array(ComplianceSuppressionSchema).optional().describe("Rules to suppress in audit output. Each suppression requires a reason and optional expiry date. Over-suppression is itself flagged."),
|
|
@@ -508,7 +510,7 @@ function loadManifest(filePath, opts = {}) {
|
|
|
508
510
|
}
|
|
509
511
|
let parsed;
|
|
510
512
|
try {
|
|
511
|
-
parsed = yaml__default.default.load(raw);
|
|
513
|
+
parsed = yaml__default.default.load(raw, { schema: yaml__default.default.JSON_SCHEMA });
|
|
512
514
|
} catch (err) {
|
|
513
515
|
throw new Error(`Invalid YAML in ${absPath}
|
|
514
516
|
${String(err)}`);
|
|
@@ -1072,8 +1074,6 @@ async function checkAws() {
|
|
|
1072
1074
|
clearTimeout(timer);
|
|
1073
1075
|
}
|
|
1074
1076
|
}
|
|
1075
|
-
|
|
1076
|
-
// src/health/checks/service.check.ts
|
|
1077
1077
|
var TIMEOUT_MS = 3e3;
|
|
1078
1078
|
async function runServiceChecks(services) {
|
|
1079
1079
|
return Promise.all(services.map((svc) => checkService(svc)));
|
|
@@ -1149,11 +1149,25 @@ function parseConnectionUrl(connection) {
|
|
|
1149
1149
|
}
|
|
1150
1150
|
function classifyHost(host) {
|
|
1151
1151
|
const h = host.replace(/^\[(.+)\]$/, "$1").toLowerCase();
|
|
1152
|
-
if (h === "
|
|
1153
|
-
|
|
1154
|
-
if (
|
|
1155
|
-
|
|
1156
|
-
|
|
1152
|
+
if (h === "localhost") return "loopback address is not probed from service checks";
|
|
1153
|
+
const ipVersion = net.isIP(h);
|
|
1154
|
+
if (ipVersion === 4) {
|
|
1155
|
+
if (h === "0.0.0.0") return "unspecified address 0.0.0.0 is not a valid service host";
|
|
1156
|
+
if (h.startsWith("127.")) return "IPv4 loopback (127.x.x.x) is not probed from service checks";
|
|
1157
|
+
if (h.startsWith("169.254.")) return "link-local address (169.254.x.x) blocked to prevent instance-metadata SSRF";
|
|
1158
|
+
if (h.startsWith("10.")) return "RFC 1918 private address (10.0.0.0/8) blocked to prevent internal SSRF";
|
|
1159
|
+
if (h.startsWith("192.168.")) return "RFC 1918 private address (192.168.0.0/16) blocked to prevent internal SSRF";
|
|
1160
|
+
if (h.startsWith("172.")) {
|
|
1161
|
+
const second = parseInt(h.split(".")[1] ?? "0", 10);
|
|
1162
|
+
if (second >= 16 && second <= 31) {
|
|
1163
|
+
return "RFC 1918 private address (172.16.0.0/12) blocked to prevent internal SSRF";
|
|
1164
|
+
}
|
|
1165
|
+
}
|
|
1166
|
+
}
|
|
1167
|
+
if (ipVersion === 6) {
|
|
1168
|
+
if (h === "::1") return "loopback address is not probed from service checks";
|
|
1169
|
+
if (h.startsWith("fe80:")) return "IPv6 link-local (fe80::/10) blocked to prevent SSRF";
|
|
1170
|
+
}
|
|
1157
1171
|
return null;
|
|
1158
1172
|
}
|
|
1159
1173
|
function getDefaultPort(scheme) {
|
|
@@ -1948,6 +1962,49 @@ var observabilityRules = [
|
|
|
1948
1962
|
}
|
|
1949
1963
|
];
|
|
1950
1964
|
|
|
1965
|
+
// src/audit/rules/metadata.rules.ts
|
|
1966
|
+
var metadataRules = [
|
|
1967
|
+
{
|
|
1968
|
+
id: "META-01",
|
|
1969
|
+
pack: "metadata-quality",
|
|
1970
|
+
title: "Agent description declared",
|
|
1971
|
+
description: "Agents should have a non-empty description for fleet discovery and documentation",
|
|
1972
|
+
severity: "low",
|
|
1973
|
+
evidenceLevel: "declarative",
|
|
1974
|
+
check(manifest) {
|
|
1975
|
+
const desc = manifest.metadata.description;
|
|
1976
|
+
const pass = typeof desc === "string" && desc.trim().length > 0;
|
|
1977
|
+
return {
|
|
1978
|
+
pass,
|
|
1979
|
+
message: pass ? void 0 : "No description declared in metadata. Agents without descriptions are hard to discover in a fleet.",
|
|
1980
|
+
path: "/metadata/description",
|
|
1981
|
+
recommendation: "Add a concise metadata.description explaining what the agent does",
|
|
1982
|
+
references: []
|
|
1983
|
+
};
|
|
1984
|
+
}
|
|
1985
|
+
},
|
|
1986
|
+
{
|
|
1987
|
+
id: "META-02",
|
|
1988
|
+
pack: "metadata-quality",
|
|
1989
|
+
title: "Model temperature is production-safe",
|
|
1990
|
+
description: "Temperature above 1.5 causes unpredictable outputs that are unsuitable for production",
|
|
1991
|
+
severity: "medium",
|
|
1992
|
+
evidenceLevel: "declarative",
|
|
1993
|
+
check(manifest) {
|
|
1994
|
+
const temperature = manifest.spec.model.parameters?.temperature;
|
|
1995
|
+
if (temperature === void 0) return { pass: true };
|
|
1996
|
+
const pass = temperature <= 1.5;
|
|
1997
|
+
return {
|
|
1998
|
+
pass,
|
|
1999
|
+
message: pass ? void 0 : `Model temperature is ${temperature} \u2014 values above 1.5 produce unreliable outputs in production.`,
|
|
2000
|
+
path: "/spec/model/parameters/temperature",
|
|
2001
|
+
recommendation: "Set spec.model.parameters.temperature to 1.0 or lower for production agents",
|
|
2002
|
+
references: []
|
|
2003
|
+
};
|
|
2004
|
+
}
|
|
2005
|
+
}
|
|
2006
|
+
];
|
|
2007
|
+
|
|
1951
2008
|
// src/audit/index.ts
|
|
1952
2009
|
var SEVERITY_WEIGHTS = {
|
|
1953
2010
|
critical: 4,
|
|
@@ -1961,7 +2018,8 @@ var ALL_RULES = [
|
|
|
1961
2018
|
...securityRules,
|
|
1962
2019
|
...memoryRules,
|
|
1963
2020
|
...evaluationRules,
|
|
1964
|
-
...observabilityRules
|
|
2021
|
+
...observabilityRules,
|
|
2022
|
+
...metadataRules
|
|
1965
2023
|
];
|
|
1966
2024
|
var AUDIT_RULE_IDS = new Set(ALL_RULES.map((r) => r.id));
|
|
1967
2025
|
function isProofRecord(r) {
|
|
@@ -2125,6 +2183,62 @@ function generateAdapter(manifest, framework, options) {
|
|
|
2125
2183
|
return adapter.generate(manifest, options);
|
|
2126
2184
|
}
|
|
2127
2185
|
|
|
2186
|
+
// src/agent/usage-ledger.ts
|
|
2187
|
+
function createEmptyEntry(modelId) {
|
|
2188
|
+
return { modelId, promptTokens: 0, completionTokens: 0, totalTokens: 0, callCount: 0 };
|
|
2189
|
+
}
|
|
2190
|
+
function buildSnapshot(counters, windowStart) {
|
|
2191
|
+
const models = [...counters.values()].map((e) => ({ ...e }));
|
|
2192
|
+
let totalTokens = 0;
|
|
2193
|
+
let totalCalls = 0;
|
|
2194
|
+
for (const m of models) {
|
|
2195
|
+
totalTokens += m.totalTokens;
|
|
2196
|
+
totalCalls += m.callCount;
|
|
2197
|
+
}
|
|
2198
|
+
return {
|
|
2199
|
+
windowStartedAt: windowStart.toISOString(),
|
|
2200
|
+
models,
|
|
2201
|
+
totalTokens,
|
|
2202
|
+
totalCalls
|
|
2203
|
+
};
|
|
2204
|
+
}
|
|
2205
|
+
var UsageLedger = class {
|
|
2206
|
+
counters = /* @__PURE__ */ new Map();
|
|
2207
|
+
windowStart = /* @__PURE__ */ new Date();
|
|
2208
|
+
/**
|
|
2209
|
+
* Record token usage for a single LLM call.
|
|
2210
|
+
* Call this once per LLM invocation with the model ID and token counts.
|
|
2211
|
+
*/
|
|
2212
|
+
record(modelId, promptTokens, completionTokens) {
|
|
2213
|
+
const p = Math.max(0, promptTokens);
|
|
2214
|
+
const c = Math.max(0, completionTokens);
|
|
2215
|
+
let entry = this.counters.get(modelId);
|
|
2216
|
+
if (!entry) {
|
|
2217
|
+
entry = createEmptyEntry(modelId);
|
|
2218
|
+
this.counters.set(modelId, entry);
|
|
2219
|
+
}
|
|
2220
|
+
entry.promptTokens += p;
|
|
2221
|
+
entry.completionTokens += c;
|
|
2222
|
+
entry.totalTokens += p + c;
|
|
2223
|
+
entry.callCount += 1;
|
|
2224
|
+
}
|
|
2225
|
+
/**
|
|
2226
|
+
* Return a frozen snapshot of the current usage window.
|
|
2227
|
+
*
|
|
2228
|
+
* @param reset - When true (default), clears all counters and starts a new
|
|
2229
|
+
* window. Use reset=true in the heartbeat push so each window is shipped
|
|
2230
|
+
* exactly once. Use reset=false for inspection without draining.
|
|
2231
|
+
*/
|
|
2232
|
+
snapshot(reset = true) {
|
|
2233
|
+
const snap = buildSnapshot(this.counters, this.windowStart);
|
|
2234
|
+
if (reset) {
|
|
2235
|
+
this.counters = /* @__PURE__ */ new Map();
|
|
2236
|
+
this.windowStart = /* @__PURE__ */ new Date();
|
|
2237
|
+
}
|
|
2238
|
+
return snap;
|
|
2239
|
+
}
|
|
2240
|
+
};
|
|
2241
|
+
|
|
2128
2242
|
// src/agent/reporter.ts
|
|
2129
2243
|
var AgentSpecReporter = class {
|
|
2130
2244
|
constructor(manifest, opts = {}) {
|
|
@@ -2141,6 +2255,8 @@ var AgentSpecReporter = class {
|
|
|
2141
2255
|
refreshing = false;
|
|
2142
2256
|
stopped = false;
|
|
2143
2257
|
registeredTools = /* @__PURE__ */ new Set();
|
|
2258
|
+
/** In-process token usage accumulator. */
|
|
2259
|
+
usage = new UsageLedger();
|
|
2144
2260
|
/**
|
|
2145
2261
|
* Register a tool handler by name.
|
|
2146
2262
|
* Only registered tools report status: 'pass' in the live health check.
|
|
@@ -2230,12 +2346,13 @@ var AgentSpecReporter = class {
|
|
|
2230
2346
|
try {
|
|
2231
2347
|
const health = await this.getReport();
|
|
2232
2348
|
const gap = runAudit(this.manifest);
|
|
2349
|
+
const usage = this.usage.snapshot(false);
|
|
2233
2350
|
const trimmedChecks = [...health.checks];
|
|
2234
|
-
let body = JSON.stringify({ health, gap });
|
|
2351
|
+
let body = JSON.stringify({ health, gap, usage });
|
|
2235
2352
|
if (body.length > 65536) {
|
|
2236
2353
|
while (trimmedChecks.length > 0) {
|
|
2237
2354
|
trimmedChecks.pop();
|
|
2238
|
-
body = JSON.stringify({ health: { ...health, checks: trimmedChecks }, gap });
|
|
2355
|
+
body = JSON.stringify({ health: { ...health, checks: trimmedChecks }, gap, usage });
|
|
2239
2356
|
if (body.length <= 65536) break;
|
|
2240
2357
|
}
|
|
2241
2358
|
}
|
|
@@ -2254,7 +2371,9 @@ var AgentSpecReporter = class {
|
|
|
2254
2371
|
opts.onError?.(new Error(sanitized));
|
|
2255
2372
|
return;
|
|
2256
2373
|
}
|
|
2257
|
-
if (
|
|
2374
|
+
if (res.ok) {
|
|
2375
|
+
this.usage.snapshot(true);
|
|
2376
|
+
} else {
|
|
2258
2377
|
opts.onError?.(new Error(`Heartbeat failed: HTTP ${res.status}`));
|
|
2259
2378
|
}
|
|
2260
2379
|
} catch (err) {
|
|
@@ -2345,6 +2464,14 @@ function agentSpecFastifyPlugin(reporter) {
|
|
|
2345
2464
|
reply.status(500).send({ error: String(err) });
|
|
2346
2465
|
}
|
|
2347
2466
|
});
|
|
2467
|
+
app.get("/agentspec/usage", async (_req, reply) => {
|
|
2468
|
+
try {
|
|
2469
|
+
const snapshot = reporter.usage.snapshot(false);
|
|
2470
|
+
reply.status(200).send(snapshot);
|
|
2471
|
+
} catch (err) {
|
|
2472
|
+
reply.status(500).send({ error: String(err) });
|
|
2473
|
+
}
|
|
2474
|
+
});
|
|
2348
2475
|
};
|
|
2349
2476
|
}
|
|
2350
2477
|
|
|
@@ -2353,23 +2480,41 @@ function agentSpecExpressRouter(reporter) {
|
|
|
2353
2480
|
const handler = async (req, res, next) => {
|
|
2354
2481
|
const method = req.method?.toUpperCase() ?? "GET";
|
|
2355
2482
|
const path = req.path ?? req.url ?? "";
|
|
2356
|
-
if (method !== "GET"
|
|
2483
|
+
if (method !== "GET") {
|
|
2357
2484
|
next();
|
|
2358
2485
|
return;
|
|
2359
2486
|
}
|
|
2360
|
-
|
|
2361
|
-
const report = await reporter.getReport();
|
|
2362
|
-
res.status(200).json(report);
|
|
2363
|
-
} catch (err) {
|
|
2487
|
+
if (path === "/health") {
|
|
2364
2488
|
try {
|
|
2365
|
-
|
|
2366
|
-
|
|
2367
|
-
|
|
2489
|
+
const report = await reporter.getReport();
|
|
2490
|
+
res.status(200).json(report);
|
|
2491
|
+
} catch (err) {
|
|
2492
|
+
try {
|
|
2493
|
+
res.status(500).json({ error: String(err) });
|
|
2494
|
+
} catch {
|
|
2495
|
+
next(err);
|
|
2496
|
+
}
|
|
2368
2497
|
}
|
|
2498
|
+
return;
|
|
2499
|
+
}
|
|
2500
|
+
if (path === "/usage") {
|
|
2501
|
+
try {
|
|
2502
|
+
const snapshot = reporter.usage.snapshot(false);
|
|
2503
|
+
res.status(200).json(snapshot);
|
|
2504
|
+
} catch (err) {
|
|
2505
|
+
try {
|
|
2506
|
+
res.status(500).json({ error: String(err) });
|
|
2507
|
+
} catch {
|
|
2508
|
+
next(err);
|
|
2509
|
+
}
|
|
2510
|
+
}
|
|
2511
|
+
return;
|
|
2369
2512
|
}
|
|
2513
|
+
next();
|
|
2370
2514
|
};
|
|
2371
2515
|
handler._routes = [
|
|
2372
|
-
{ path: "/health" }
|
|
2516
|
+
{ path: "/health" },
|
|
2517
|
+
{ path: "/usage" }
|
|
2373
2518
|
];
|
|
2374
2519
|
return handler;
|
|
2375
2520
|
}
|
|
@@ -2378,6 +2523,7 @@ exports.AUDIT_RULE_IDS = AUDIT_RULE_IDS;
|
|
|
2378
2523
|
exports.AgentSpecReporter = AgentSpecReporter;
|
|
2379
2524
|
exports.LATEST_API_VERSION = LATEST_API_VERSION;
|
|
2380
2525
|
exports.ManifestSchema = ManifestSchema;
|
|
2526
|
+
exports.UsageLedger = UsageLedger;
|
|
2381
2527
|
exports.agentSpecExpressRouter = agentSpecExpressRouter;
|
|
2382
2528
|
exports.agentSpecFastifyPlugin = agentSpecFastifyPlugin;
|
|
2383
2529
|
exports.collectEnvRefs = collectEnvRefs;
|