devanvil 0.0.0-stage → 2.1.1
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 +21 -0
- package/README.ar.md +113 -0
- package/README.md +272 -2
- package/SECURITY.md +49 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +664 -0
- package/dist/core/contract-drift.d.ts +49 -0
- package/dist/core/contract-drift.js +312 -0
- package/dist/core/converters.d.ts +18 -0
- package/dist/core/converters.js +989 -0
- package/dist/core/cron.d.ts +33 -0
- package/dist/core/cron.js +309 -0
- package/dist/core/crypto.d.ts +59 -0
- package/dist/core/crypto.js +260 -0
- package/dist/core/curl.d.ts +17 -0
- package/dist/core/curl.js +174 -0
- package/dist/core/diff.d.ts +36 -0
- package/dist/core/diff.js +148 -0
- package/dist/core/encoding.d.ts +3 -0
- package/dist/core/encoding.js +143 -0
- package/dist/core/importers.d.ts +65 -0
- package/dist/core/importers.js +361 -0
- package/dist/core/jwt.d.ts +39 -0
- package/dist/core/jwt.js +269 -0
- package/dist/core/llm-tokens.d.ts +38 -0
- package/dist/core/llm-tokens.js +125 -0
- package/dist/core/log-analyzer.d.ts +30 -0
- package/dist/core/log-analyzer.js +155 -0
- package/dist/core/network.d.ts +72 -0
- package/dist/core/network.js +185 -0
- package/dist/core/oauth-protobuf.d.ts +74 -0
- package/dist/core/oauth-protobuf.js +396 -0
- package/dist/core/openapi.d.ts +27 -0
- package/dist/core/openapi.js +257 -0
- package/dist/core/pipeline.d.ts +28 -0
- package/dist/core/pipeline.js +154 -0
- package/dist/core/regex.d.ts +50 -0
- package/dist/core/regex.js +360 -0
- package/dist/core/runner.d.ts +53 -0
- package/dist/core/runner.js +250 -0
- package/dist/core/secrets.d.ts +87 -0
- package/dist/core/secrets.js +603 -0
- package/dist/core/security.d.ts +34 -0
- package/dist/core/security.js +301 -0
- package/dist/core/sql-explain.d.ts +50 -0
- package/dist/core/sql-explain.js +259 -0
- package/dist/core/tls.d.ts +44 -0
- package/dist/core/tls.js +169 -0
- package/dist/index.d.ts +31 -0
- package/dist/index.js +31 -0
- package/dist/server/app.d.ts +31 -0
- package/dist/server/app.js +359 -0
- package/dist/server/http-proxy.d.ts +55 -0
- package/dist/server/http-proxy.js +373 -0
- package/dist/server/http-utils.d.ts +28 -0
- package/dist/server/http-utils.js +118 -0
- package/dist/server/load-tester.d.ts +53 -0
- package/dist/server/load-tester.js +137 -0
- package/dist/server/mcp.d.ts +35 -0
- package/dist/server/mcp.js +470 -0
- package/dist/server/mock-store.d.ts +38 -0
- package/dist/server/mock-store.js +238 -0
- package/dist/server/plugin-loader.d.ts +61 -0
- package/dist/server/plugin-loader.js +305 -0
- package/dist/server/recorder-store.d.ts +35 -0
- package/dist/server/recorder-store.js +147 -0
- package/dist/server/routes/network-routes.d.ts +3 -0
- package/dist/server/routes/network-routes.js +441 -0
- package/dist/server/routes/tools-routes.d.ts +3 -0
- package/dist/server/routes/tools-routes.js +299 -0
- package/dist/server/routes/workspace-routes.d.ts +3 -0
- package/dist/server/routes/workspace-routes.js +262 -0
- package/dist/server/webhook-store.d.ts +29 -0
- package/dist/server/webhook-store.js +100 -0
- package/dist/server/workspace-store.d.ts +91 -0
- package/dist/server/workspace-store.js +448 -0
- package/dist/server/ws-probe.d.ts +34 -0
- package/dist/server/ws-probe.js +291 -0
- package/dist/ui/app.js +290 -0
- package/dist/ui/favicon.svg +14 -0
- package/dist/ui/index.html +83 -0
- package/dist/ui/logo.png +0 -0
- package/dist/ui/styles.css +694 -0
- package/dist/ui/tools-data.js +719 -0
- package/dist/ui/tools-network.js +769 -0
- package/dist/ui/tools-ops.js +299 -0
- package/dist/ui/tools-pro.js +500 -0
- package/dist/ui/tools-security.js +397 -0
- package/dist/ui/tools-v12.js +765 -0
- package/dist/ui/tools-v13.js +321 -0
- package/dist/ui/tools-v20.js +563 -0
- package/dist/ui/tools-v21.js +411 -0
- package/package.json +75 -4
|
@@ -0,0 +1,500 @@
|
|
|
1
|
+
(function () {
|
|
2
|
+
'use strict';
|
|
3
|
+
const { h, api, toast, copyText, registerTool, openInApiStudio } = window.DevAnvil;
|
|
4
|
+
|
|
5
|
+
// ───────────────────────────────────────────────────────────────────────────
|
|
6
|
+
// 11. OpenAPI 3.x / Swagger -> Instant Live Mock Server Studio
|
|
7
|
+
// ───────────────────────────────────────────────────────────────────────────
|
|
8
|
+
registerTool({
|
|
9
|
+
id: 'openapi-mock',
|
|
10
|
+
group: 'Network & API',
|
|
11
|
+
name: 'OpenAPI -> Mock',
|
|
12
|
+
icon: '📜',
|
|
13
|
+
subtitle: 'Paste OpenAPI 3.x / Swagger (YAML or JSON) -> 1-click spin up live /mock/* endpoints',
|
|
14
|
+
keywords: ['openapi', 'swagger', 'spec', 'yaml', 'mock', 'generate', 'rest', 'schema'],
|
|
15
|
+
render(root) {
|
|
16
|
+
const sampleSpec = `openapi: 3.0.3
|
|
17
|
+
info:
|
|
18
|
+
title: Acme Cloud Billing API
|
|
19
|
+
version: 2.1.0
|
|
20
|
+
servers:
|
|
21
|
+
- url: https://api.acme.example/v2
|
|
22
|
+
paths:
|
|
23
|
+
/customers/{customerId}:
|
|
24
|
+
get:
|
|
25
|
+
summary: Fetch customer profile
|
|
26
|
+
tags: [Customers]
|
|
27
|
+
responses:
|
|
28
|
+
"200":
|
|
29
|
+
description: Customer found
|
|
30
|
+
content:
|
|
31
|
+
application/json:
|
|
32
|
+
schema:
|
|
33
|
+
$ref: "#/components/schemas/Customer"
|
|
34
|
+
/invoices:
|
|
35
|
+
post:
|
|
36
|
+
summary: Create draft invoice
|
|
37
|
+
tags: [Billing]
|
|
38
|
+
requestBody:
|
|
39
|
+
content:
|
|
40
|
+
application/json:
|
|
41
|
+
schema:
|
|
42
|
+
type: object
|
|
43
|
+
properties:
|
|
44
|
+
customerId:
|
|
45
|
+
type: string
|
|
46
|
+
example: cus_019374f1
|
|
47
|
+
amountCents:
|
|
48
|
+
type: integer
|
|
49
|
+
example: 4900
|
|
50
|
+
currency:
|
|
51
|
+
type: string
|
|
52
|
+
enum: [USD, EUR, GBP]
|
|
53
|
+
responses:
|
|
54
|
+
"201":
|
|
55
|
+
description: Invoice created
|
|
56
|
+
content:
|
|
57
|
+
application/json:
|
|
58
|
+
schema:
|
|
59
|
+
type: object
|
|
60
|
+
properties:
|
|
61
|
+
id:
|
|
62
|
+
type: string
|
|
63
|
+
format: uuid
|
|
64
|
+
status:
|
|
65
|
+
type: string
|
|
66
|
+
enum: [draft, open, paid]
|
|
67
|
+
createdAt:
|
|
68
|
+
type: string
|
|
69
|
+
format: date-time
|
|
70
|
+
components:
|
|
71
|
+
schemas:
|
|
72
|
+
Customer:
|
|
73
|
+
type: object
|
|
74
|
+
properties:
|
|
75
|
+
customerId:
|
|
76
|
+
type: string
|
|
77
|
+
example: cus_019374f1
|
|
78
|
+
name:
|
|
79
|
+
type: string
|
|
80
|
+
example: Ada Lovelace
|
|
81
|
+
email:
|
|
82
|
+
type: string
|
|
83
|
+
format: email
|
|
84
|
+
plan:
|
|
85
|
+
type: string
|
|
86
|
+
enum: [pro, enterprise]
|
|
87
|
+
active:
|
|
88
|
+
type: boolean
|
|
89
|
+
`;
|
|
90
|
+
|
|
91
|
+
const specInput = h('textarea', { rows: 16, value: sampleSpec });
|
|
92
|
+
const replaceChk = h('input', { type: 'checkbox' });
|
|
93
|
+
const summaryRow = h('div', { class: 'row' });
|
|
94
|
+
const endpointsList = h('div', { class: 'stack' });
|
|
95
|
+
const detailPre = h('pre', { class: 'code-box' }, 'Parse an OpenAPI spec to preview synthesized mocks & cURL snippets.');
|
|
96
|
+
|
|
97
|
+
function renderSpec(parsed) {
|
|
98
|
+
summaryRow.textContent = '';
|
|
99
|
+
summaryRow.appendChild(h('span', { class: 'badge badge-ok' }, `${parsed.title} v${parsed.version}`));
|
|
100
|
+
summaryRow.appendChild(h('span', { class: 'badge badge-info' }, `OpenAPI ${parsed.specVersion}`));
|
|
101
|
+
summaryRow.appendChild(h('span', { class: 'badge badge-subtle' }, `${parsed.endpointCount} operation(s)`));
|
|
102
|
+
|
|
103
|
+
endpointsList.textContent = '';
|
|
104
|
+
for (const ep of parsed.endpoints) {
|
|
105
|
+
const sampleMockUrl = `/mock${ep.mockPath.replace(/:([a-zA-Z0-9_]+)/g, 'cus_42')}`;
|
|
106
|
+
const item = h(
|
|
107
|
+
'div',
|
|
108
|
+
{ class: 'list-item' },
|
|
109
|
+
h(
|
|
110
|
+
'div',
|
|
111
|
+
{ class: 'row-between' },
|
|
112
|
+
h(
|
|
113
|
+
'div',
|
|
114
|
+
{ class: 'row' },
|
|
115
|
+
h('span', { class: 'badge badge-info' }, ep.method),
|
|
116
|
+
h('span', { class: 'mono', style: { fontWeight: '600' } }, ep.openApiPath),
|
|
117
|
+
h('span', { class: 'badge badge-ok' }, String(ep.responseStatus)),
|
|
118
|
+
),
|
|
119
|
+
h(
|
|
120
|
+
'div',
|
|
121
|
+
{ class: 'row' },
|
|
122
|
+
h(
|
|
123
|
+
'button',
|
|
124
|
+
{
|
|
125
|
+
type: 'button',
|
|
126
|
+
class: 'btn btn-xs',
|
|
127
|
+
onClick: () => {
|
|
128
|
+
detailPre.textContent = [
|
|
129
|
+
`Endpoint: ${ep.method} ${ep.openApiPath}`,
|
|
130
|
+
`Mock URL: ${window.location.origin}/mock${ep.mockPath}`,
|
|
131
|
+
`Status: ${ep.responseStatus}`,
|
|
132
|
+
'',
|
|
133
|
+
'--- Synthesized Mock Response ---',
|
|
134
|
+
JSON.stringify(ep.sampleResponse, null, 2),
|
|
135
|
+
'',
|
|
136
|
+
'--- Generated cURL ---',
|
|
137
|
+
ep.curlExample,
|
|
138
|
+
].join('\n');
|
|
139
|
+
},
|
|
140
|
+
},
|
|
141
|
+
'Inspect',
|
|
142
|
+
),
|
|
143
|
+
h(
|
|
144
|
+
'button',
|
|
145
|
+
{
|
|
146
|
+
type: 'button',
|
|
147
|
+
class: 'btn btn-ghost btn-xs',
|
|
148
|
+
onClick: () =>
|
|
149
|
+
openInApiStudio({
|
|
150
|
+
method: ep.method,
|
|
151
|
+
url: `${window.location.origin}${sampleMockUrl}`,
|
|
152
|
+
headers: ep.sampleRequestBody ? { 'Content-Type': 'application/json' } : { Accept: 'application/json' },
|
|
153
|
+
body: ep.sampleRequestBody ? JSON.stringify(ep.sampleRequestBody, null, 2) : '',
|
|
154
|
+
}),
|
|
155
|
+
},
|
|
156
|
+
'Open in API Studio',
|
|
157
|
+
),
|
|
158
|
+
),
|
|
159
|
+
),
|
|
160
|
+
h('div', { style: { fontSize: '12px', color: 'var(--text-muted)' } }, ep.summary),
|
|
161
|
+
);
|
|
162
|
+
endpointsList.appendChild(item);
|
|
163
|
+
}
|
|
164
|
+
if (parsed.endpoints[0]) {
|
|
165
|
+
const first = parsed.endpoints[0];
|
|
166
|
+
detailPre.textContent = JSON.stringify(first.sampleResponse, null, 2);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
async function doParse() {
|
|
171
|
+
try {
|
|
172
|
+
const parsed = await api('/api/openapi/parse', { body: { spec: specInput.value } });
|
|
173
|
+
renderSpec(parsed);
|
|
174
|
+
toast(`Parsed ${parsed.endpointCount} OpenAPI endpoint(s)`, 'ok');
|
|
175
|
+
} catch (err) {
|
|
176
|
+
toast(err.message, 'err');
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
async function doMountAll() {
|
|
181
|
+
try {
|
|
182
|
+
const res = await api('/api/openapi/mount', { body: { spec: specInput.value, replace: replaceChk.checked } });
|
|
183
|
+
renderSpec(res.spec);
|
|
184
|
+
toast(`Mounted ${res.mountedCount} live mock endpoint(s) at /mock/*`, 'ok');
|
|
185
|
+
} catch (err) {
|
|
186
|
+
toast(err.message, 'err');
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
const layout = h(
|
|
191
|
+
'div',
|
|
192
|
+
{ class: 'grid-2' },
|
|
193
|
+
h(
|
|
194
|
+
'div',
|
|
195
|
+
{ class: 'card' },
|
|
196
|
+
h(
|
|
197
|
+
'div',
|
|
198
|
+
{ class: 'row-between' },
|
|
199
|
+
h('h2', { class: 'card-title' }, 'OpenAPI 3.x / Swagger Spec (YAML or JSON)'),
|
|
200
|
+
h(
|
|
201
|
+
'div',
|
|
202
|
+
{ class: 'row' },
|
|
203
|
+
h('label', { class: 'row', style: { fontSize: '12px' } }, replaceChk, 'Replace existing mocks'),
|
|
204
|
+
h('button', { type: 'button', class: 'btn btn-sm', onClick: doParse }, 'Parse Spec'),
|
|
205
|
+
h('button', { type: 'button', class: 'btn btn-primary btn-sm', onClick: doMountAll }, 'Mount All -> Live Mock'),
|
|
206
|
+
),
|
|
207
|
+
),
|
|
208
|
+
specInput,
|
|
209
|
+
),
|
|
210
|
+
h(
|
|
211
|
+
'div',
|
|
212
|
+
{ class: 'stack' },
|
|
213
|
+
h('div', { class: 'card' }, h('h2', { class: 'card-title' }, 'Synthesized Endpoints'), summaryRow, endpointsList),
|
|
214
|
+
h(
|
|
215
|
+
'div',
|
|
216
|
+
{ class: 'card' },
|
|
217
|
+
h('div', { class: 'row-between' }, h('h2', { class: 'card-title' }, 'Response Schema & cURL Preview'), h('button', { type: 'button', class: 'btn btn-ghost btn-xs', onClick: () => copyText(detailPre.textContent) }, 'Copy')),
|
|
218
|
+
detailPre,
|
|
219
|
+
),
|
|
220
|
+
),
|
|
221
|
+
);
|
|
222
|
+
|
|
223
|
+
root.appendChild(layout);
|
|
224
|
+
void doParse();
|
|
225
|
+
},
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
// ───────────────────────────────────────────────────────────────────────────
|
|
229
|
+
// 12. Secret & Leak Scanner + .env Validator Studio
|
|
230
|
+
// ───────────────────────────────────────────────────────────────────────────
|
|
231
|
+
registerTool({
|
|
232
|
+
id: 'secret-scanner',
|
|
233
|
+
group: 'Security & Identity',
|
|
234
|
+
name: 'Secret & .env Guard',
|
|
235
|
+
icon: '🛡',
|
|
236
|
+
subtitle: '100% offline leaked-key detector (18 providers + entropy), 1-click redactor & .env diff',
|
|
237
|
+
keywords: ['secret', 'leak', 'redaction', 'scanner', 'env', 'api key', 'token', 'security', 'audit'],
|
|
238
|
+
render(root) {
|
|
239
|
+
const sampleText = [
|
|
240
|
+
'# Sample config snippet — safe synthetic values assembled for demo',
|
|
241
|
+
'DATABASE_URL=postgres://admin:SuperSecretPass99@db.internal:5432/prod',
|
|
242
|
+
`AWS_ACCESS_KEY_ID=${['AKIA', 'IOSFODNN7EXAMPLE'].join('')}`,
|
|
243
|
+
`STRIPE_SECRET=${['sk', 'live', '51DemoFixtureExample0000000000'].join('_')}`,
|
|
244
|
+
'APP_ENV=production',
|
|
245
|
+
].join('\n');
|
|
246
|
+
|
|
247
|
+
const scanIn = h('textarea', { rows: 9, value: sampleText });
|
|
248
|
+
const entropyChk = h('input', { type: 'checkbox', checked: true });
|
|
249
|
+
const scanBadges = h('div', { class: 'row' });
|
|
250
|
+
const findingsList = h('div', { class: 'stack' });
|
|
251
|
+
const redactedOut = h('pre', { class: 'code-box' }, '');
|
|
252
|
+
|
|
253
|
+
async function runScan() {
|
|
254
|
+
try {
|
|
255
|
+
const res = await api('/api/secrets/scan', {
|
|
256
|
+
body: { input: scanIn.value, checkHighEntropy: entropyChk.checked },
|
|
257
|
+
});
|
|
258
|
+
scanBadges.textContent = '';
|
|
259
|
+
if (res.clean) {
|
|
260
|
+
scanBadges.appendChild(h('span', { class: 'badge badge-ok' }, 'CLEAN — 0 leaks detected'));
|
|
261
|
+
} else {
|
|
262
|
+
scanBadges.appendChild(h('span', { class: 'badge badge-err' }, `${res.totalFindings} leak(s) detected`));
|
|
263
|
+
if (res.summary.critical) scanBadges.appendChild(h('span', { class: 'badge badge-err' }, `${res.summary.critical} critical`));
|
|
264
|
+
if (res.summary.high) scanBadges.appendChild(h('span', { class: 'badge badge-warn' }, `${res.summary.high} high`));
|
|
265
|
+
if (res.summary.medium) scanBadges.appendChild(h('span', { class: 'badge badge-info' }, `${res.summary.medium} medium`));
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
findingsList.textContent = '';
|
|
269
|
+
if (res.clean) {
|
|
270
|
+
findingsList.appendChild(h('div', { class: 'finding pass' }, 'No API keys, private keys, database passwords, or high-entropy secrets found.'));
|
|
271
|
+
} else {
|
|
272
|
+
for (const f of res.findings) {
|
|
273
|
+
const sevClass = f.severity === 'critical' ? 'critical' : f.severity === 'high' ? 'warning' : 'info';
|
|
274
|
+
findingsList.appendChild(
|
|
275
|
+
h(
|
|
276
|
+
'div',
|
|
277
|
+
{ class: `finding ${sevClass}` },
|
|
278
|
+
h('span', { class: 'mono', style: { fontWeight: '700' } }, `L${f.line}:${f.column}`),
|
|
279
|
+
h('span', { class: 'badge badge-subtle' }, f.ruleId),
|
|
280
|
+
h('span', {}, `${f.name} (${f.masked} · H=${f.entropy})`),
|
|
281
|
+
),
|
|
282
|
+
);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
redactedOut.textContent = res.redactedText;
|
|
286
|
+
} catch (err) {
|
|
287
|
+
toast(err.message, 'err');
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
// .env validator & diff against .env.example
|
|
292
|
+
const envTarget = h('textarea', { rows: 6, value: 'PORT=4321\nNODE_ENV=production\nAPP_NAME=My Local App\nPORT=8080' });
|
|
293
|
+
const envExample = h('textarea', { rows: 6, value: 'PORT=4321\nNODE_ENV=development\nJWT_SECRET=changeme\nDATABASE_URL=postgres://localhost/app' });
|
|
294
|
+
const envResult = h('div', { class: 'stack' });
|
|
295
|
+
|
|
296
|
+
async function runEnvCheck() {
|
|
297
|
+
try {
|
|
298
|
+
const res = await api('/api/secrets/env', { body: { env: envTarget.value, example: envExample.value } });
|
|
299
|
+
envResult.textContent = '';
|
|
300
|
+
envResult.appendChild(
|
|
301
|
+
h(
|
|
302
|
+
'div',
|
|
303
|
+
{ class: 'row' },
|
|
304
|
+
h('span', { class: 'badge badge-subtle' }, `${res.valuesCount} keys`),
|
|
305
|
+
h('span', { class: `badge ${res.missingFromTarget.length ? 'badge-err' : 'badge-ok'}` }, `${res.missingFromTarget.length} missing vs .env.example`),
|
|
306
|
+
h('span', { class: 'badge badge-info' }, `${res.extraInTarget.length} extra`),
|
|
307
|
+
),
|
|
308
|
+
);
|
|
309
|
+
if (!res.issues.length) {
|
|
310
|
+
envResult.appendChild(h('div', { class: 'finding pass' }, '.env matches schema with zero syntax issues!'));
|
|
311
|
+
} else {
|
|
312
|
+
for (const iss of res.issues) {
|
|
313
|
+
const cls = iss.severity === 'error' ? 'critical' : iss.severity === 'warning' ? 'warning' : 'info';
|
|
314
|
+
envResult.appendChild(h('div', { class: `finding ${cls}` }, `${iss.line ? `L${iss.line}: ` : ''}${iss.message}`));
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
} catch (err) {
|
|
318
|
+
toast(err.message, 'err');
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
const layout = h(
|
|
323
|
+
'div',
|
|
324
|
+
{ class: 'stack' },
|
|
325
|
+
h(
|
|
326
|
+
'div',
|
|
327
|
+
{ class: 'grid-2' },
|
|
328
|
+
h(
|
|
329
|
+
'div',
|
|
330
|
+
{ class: 'card' },
|
|
331
|
+
h(
|
|
332
|
+
'div',
|
|
333
|
+
{ class: 'row-between' },
|
|
334
|
+
h('h2', { class: 'card-title' }, 'Paste Code, Logs, Diff or Config'),
|
|
335
|
+
h(
|
|
336
|
+
'div',
|
|
337
|
+
{ class: 'row' },
|
|
338
|
+
h('label', { class: 'row', style: { fontSize: '12px' } }, entropyChk, 'Entropy scan'),
|
|
339
|
+
h('button', { type: 'button', class: 'btn btn-primary btn-sm', onClick: runScan }, 'Scan & Redact'),
|
|
340
|
+
),
|
|
341
|
+
),
|
|
342
|
+
scanIn,
|
|
343
|
+
scanBadges,
|
|
344
|
+
findingsList,
|
|
345
|
+
),
|
|
346
|
+
h(
|
|
347
|
+
'div',
|
|
348
|
+
{ class: 'card' },
|
|
349
|
+
h(
|
|
350
|
+
'div',
|
|
351
|
+
{ class: 'row-between' },
|
|
352
|
+
h('h2', { class: 'card-title' }, 'Redacted Output (Safe to Share / Paste to LLMs)'),
|
|
353
|
+
h('button', { type: 'button', class: 'btn btn-primary btn-xs', onClick: () => copyText(redactedOut.textContent, 'Copied redacted text!') }, 'Copy Safe Output'),
|
|
354
|
+
),
|
|
355
|
+
redactedOut,
|
|
356
|
+
),
|
|
357
|
+
),
|
|
358
|
+
h(
|
|
359
|
+
'div',
|
|
360
|
+
{ class: 'card' },
|
|
361
|
+
h('div', { class: 'row-between' }, h('h2', { class: 'card-title' }, '.env Validator & .env.example Drift Checker'), h('button', { type: 'button', class: 'btn btn-sm', onClick: runEnvCheck }, 'Validate .env')),
|
|
362
|
+
h('div', { class: 'grid-2' }, h('div', {}, h('label', { class: 'field-label' }, '.env'), envTarget), h('div', {}, h('label', { class: 'field-label' }, '.env.example (optional)'), envExample)),
|
|
363
|
+
envResult,
|
|
364
|
+
),
|
|
365
|
+
);
|
|
366
|
+
|
|
367
|
+
root.appendChild(layout);
|
|
368
|
+
void runScan();
|
|
369
|
+
void runEnvCheck();
|
|
370
|
+
},
|
|
371
|
+
});
|
|
372
|
+
|
|
373
|
+
// ───────────────────────────────────────────────────────────────────────────
|
|
374
|
+
// 13. LLM Token, Cost & Context Budget Studio
|
|
375
|
+
// ───────────────────────────────────────────────────────────────────────────
|
|
376
|
+
registerTool({
|
|
377
|
+
id: 'llm-tokens',
|
|
378
|
+
group: 'Data & Code',
|
|
379
|
+
name: 'LLM Token Studio',
|
|
380
|
+
icon: '🧠',
|
|
381
|
+
subtitle: 'Offline BPE token counter, multi-model cost & context budget estimator + context compactor',
|
|
382
|
+
keywords: ['llm', 'token', 'ai', 'prompt', 'claude', 'gpt', 'gemini', 'cost', 'context', 'compact'],
|
|
383
|
+
render(root) {
|
|
384
|
+
const promptIn = h('textarea', {
|
|
385
|
+
rows: 10,
|
|
386
|
+
value: `// System prompt + code context sample\nexport async function verifySession(token: string) {\n // Validate token signature & expiry locally\n const res = await fetch('/api/jwt/verify', {\n method: 'POST',\n body: JSON.stringify({ token }),\n });\n\n\n return res.json();\n}`,
|
|
387
|
+
});
|
|
388
|
+
const stripCommentsChk = h('input', { type: 'checkbox', checked: true });
|
|
389
|
+
const minifyJsonChk = h('input', { type: 'checkbox' });
|
|
390
|
+
const statsGrid = h('div', { class: 'kv-grid' });
|
|
391
|
+
const modelsBox = h('div', { class: 'stack' });
|
|
392
|
+
const compactOut = h('pre', { class: 'code-box' }, '');
|
|
393
|
+
const savingsBadge = h('span', { class: 'badge badge-subtle' }, '—');
|
|
394
|
+
|
|
395
|
+
async function analyze() {
|
|
396
|
+
try {
|
|
397
|
+
const res = await api('/api/llm/analyze', { body: { input: promptIn.value } });
|
|
398
|
+
statsGrid.textContent = '';
|
|
399
|
+
const tiles = [
|
|
400
|
+
['Est. Tokens (Base)', res.estimatedBaseTokens.toLocaleString()],
|
|
401
|
+
['Characters', res.characters.toLocaleString()],
|
|
402
|
+
['UTF-8 Bytes', res.bytes.toLocaleString()],
|
|
403
|
+
['Words / Lines', `${res.words} / ${res.lines}`],
|
|
404
|
+
['Content Density', res.codeDensity],
|
|
405
|
+
];
|
|
406
|
+
for (const [k, v] of tiles) {
|
|
407
|
+
statsGrid.appendChild(h('div', { class: 'stat-tile' }, h('div', { class: 'stat-label' }, k), h('div', { class: 'stat-val' }, v)));
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
modelsBox.textContent = '';
|
|
411
|
+
for (const m of res.models) {
|
|
412
|
+
const pct = Math.min(100, Math.max(0.5, m.contextUsagePct));
|
|
413
|
+
modelsBox.appendChild(
|
|
414
|
+
h(
|
|
415
|
+
'div',
|
|
416
|
+
{ class: 'list-item' },
|
|
417
|
+
h(
|
|
418
|
+
'div',
|
|
419
|
+
{ class: 'row-between' },
|
|
420
|
+
h('div', { class: 'row' }, h('strong', {}, m.model), h('span', { class: 'badge badge-subtle' }, m.provider)),
|
|
421
|
+
h(
|
|
422
|
+
'div',
|
|
423
|
+
{ class: 'row' },
|
|
424
|
+
h('span', { class: 'badge badge-info' }, `~${m.estimatedTokens.toLocaleString()} tok`),
|
|
425
|
+
h('span', { class: 'badge badge-ok' }, `$${m.inputCostPer1KCallsUsd.toFixed(4)} / 1k calls`),
|
|
426
|
+
),
|
|
427
|
+
),
|
|
428
|
+
h(
|
|
429
|
+
'div',
|
|
430
|
+
{ class: 'meter-track' },
|
|
431
|
+
h('div', { class: 'meter-fill', style: { width: `${pct}%` } }),
|
|
432
|
+
),
|
|
433
|
+
h('div', { style: { fontSize: '11px', color: 'var(--text-dim)' } }, `${m.contextUsagePct}% of ${(m.contextWindow / 1000).toLocaleString()}k context window`),
|
|
434
|
+
),
|
|
435
|
+
);
|
|
436
|
+
}
|
|
437
|
+
} catch (err) {
|
|
438
|
+
toast(err.message, 'err');
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
async function compact() {
|
|
443
|
+
try {
|
|
444
|
+
const res = await api('/api/llm/compact', {
|
|
445
|
+
body: { input: promptIn.value, stripLineComments: stripCommentsChk.checked, minifyJson: minifyJsonChk.checked },
|
|
446
|
+
});
|
|
447
|
+
compactOut.textContent = res.compacted;
|
|
448
|
+
savingsBadge.textContent = `Saved ${res.tokensSaved} tokens (${res.savingsPct}%)`;
|
|
449
|
+
savingsBadge.className = `badge ${res.tokensSaved > 0 ? 'badge-ok' : 'badge-subtle'}`;
|
|
450
|
+
} catch (err) {
|
|
451
|
+
toast(err.message, 'err');
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
const layout = h(
|
|
456
|
+
'div',
|
|
457
|
+
{ class: 'grid-2' },
|
|
458
|
+
h(
|
|
459
|
+
'div',
|
|
460
|
+
{ class: 'stack' },
|
|
461
|
+
h(
|
|
462
|
+
'div',
|
|
463
|
+
{ class: 'card' },
|
|
464
|
+
h(
|
|
465
|
+
'div',
|
|
466
|
+
{ class: 'row-between' },
|
|
467
|
+
h('h2', { class: 'card-title' }, 'Prompt / Code Input'),
|
|
468
|
+
h('button', { type: 'button', class: 'btn btn-primary btn-sm', onClick: () => { void analyze(); void compact(); } }, 'Analyze & Compact'),
|
|
469
|
+
),
|
|
470
|
+
promptIn,
|
|
471
|
+
statsGrid,
|
|
472
|
+
),
|
|
473
|
+
h(
|
|
474
|
+
'div',
|
|
475
|
+
{ class: 'card' },
|
|
476
|
+
h(
|
|
477
|
+
'div',
|
|
478
|
+
{ class: 'row-between' },
|
|
479
|
+
h('h2', { class: 'card-title' }, 'Context Compactor'),
|
|
480
|
+
h('div', { class: 'row' }, savingsBadge, h('button', { type: 'button', class: 'btn btn-ghost btn-xs', onClick: () => copyText(compactOut.textContent, 'Copied compacted context') }, 'Copy')),
|
|
481
|
+
),
|
|
482
|
+
h(
|
|
483
|
+
'div',
|
|
484
|
+
{ class: 'row' },
|
|
485
|
+
h('label', { class: 'row', style: { fontSize: '12px' } }, stripCommentsChk, 'Strip // comment lines'),
|
|
486
|
+
h('label', { class: 'row', style: { fontSize: '12px' } }, minifyJsonChk, 'Minify pure JSON'),
|
|
487
|
+
h('button', { type: 'button', class: 'btn btn-sm', onClick: compact }, 'Compact'),
|
|
488
|
+
),
|
|
489
|
+
compactOut,
|
|
490
|
+
),
|
|
491
|
+
),
|
|
492
|
+
h('div', { class: 'card' }, h('h2', { class: 'card-title' }, 'Model Token & Cost Breakdown'), modelsBox),
|
|
493
|
+
);
|
|
494
|
+
|
|
495
|
+
root.appendChild(layout);
|
|
496
|
+
void analyze();
|
|
497
|
+
void compact();
|
|
498
|
+
},
|
|
499
|
+
});
|
|
500
|
+
})();
|