@skillmark/webapp 0.1.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/.wrangler/state/v3/d1/miniflare-D1DatabaseObject/cd45cc5264daa1c125545b5b4c0756df95d8b6ac5900ecf52323d90f61a47f2d.sqlite +0 -0
- package/.wrangler/state/v3/d1/miniflare-D1DatabaseObject/fc50b649db51ed0c303ff2c4b7c0eca2da269cc3dfc7ce40615fc37a7b53366c.sqlite +0 -0
- package/.wrangler/state/v3/d1/miniflare-D1DatabaseObject/fc50b649db51ed0c303ff2c4b7c0eca2da269cc3dfc7ce40615fc37a7b53366c.sqlite-shm +0 -0
- package/.wrangler/state/v3/d1/miniflare-D1DatabaseObject/fc50b649db51ed0c303ff2c4b7c0eca2da269cc3dfc7ce40615fc37a7b53366c.sqlite-wal +0 -0
- package/.wrangler/tmp/bundle-lfa2r7/checked-fetch.js +30 -0
- package/.wrangler/tmp/bundle-lfa2r7/middleware-insertion-facade.js +11 -0
- package/.wrangler/tmp/bundle-lfa2r7/middleware-loader.entry.ts +134 -0
- package/.wrangler/tmp/bundle-lfa2r7/strip-cf-connecting-ip-header.js +13 -0
- package/.wrangler/tmp/dev-IDqSK4/worker-entry-point.js +4918 -0
- package/.wrangler/tmp/dev-IDqSK4/worker-entry-point.js.map +8 -0
- package/package.json +22 -0
- package/src/assets/favicon.png +0 -0
- package/src/assets/skillmark-thumb.png +0 -0
- package/src/db/d1-database-schema.sql +69 -0
- package/src/db/migrations/001-add-github-oauth-and-user-session-tables.sql +40 -0
- package/src/db/migrations/002-add-security-benchmark-columns.sql +30 -0
- package/src/db/migrations/003-add-repo-url-and-update-composite-formula.sql +27 -0
- package/src/routes/api-endpoints-handler.ts +380 -0
- package/src/routes/github-oauth-authentication-handler.ts +427 -0
- package/src/routes/html-pages-renderer.ts +2263 -0
- package/src/routes/static-assets-handler.ts +58 -0
- package/src/worker-entry-point.ts +143 -0
- package/tsconfig.json +19 -0
- package/wrangler.toml +19 -0
|
@@ -0,0 +1,4918 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
|
|
4
|
+
// .wrangler/tmp/bundle-lfa2r7/checked-fetch.js
|
|
5
|
+
var urls = /* @__PURE__ */ new Set();
|
|
6
|
+
function checkURL(request, init) {
|
|
7
|
+
const url = request instanceof URL ? request : new URL(
|
|
8
|
+
(typeof request === "string" ? new Request(request, init) : request).url
|
|
9
|
+
);
|
|
10
|
+
if (url.port && url.port !== "443" && url.protocol === "https:") {
|
|
11
|
+
if (!urls.has(url.toString())) {
|
|
12
|
+
urls.add(url.toString());
|
|
13
|
+
console.warn(
|
|
14
|
+
`WARNING: known issue with \`fetch()\` requests to custom HTTPS ports in published Workers:
|
|
15
|
+
- ${url.toString()} - the custom port will be ignored when the Worker is published using the \`wrangler deploy\` command.
|
|
16
|
+
`
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
__name(checkURL, "checkURL");
|
|
22
|
+
globalThis.fetch = new Proxy(globalThis.fetch, {
|
|
23
|
+
apply(target, thisArg, argArray) {
|
|
24
|
+
const [request, init] = argArray;
|
|
25
|
+
checkURL(request, init);
|
|
26
|
+
return Reflect.apply(target, thisArg, argArray);
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
// .wrangler/tmp/bundle-lfa2r7/strip-cf-connecting-ip-header.js
|
|
31
|
+
function stripCfConnectingIPHeader(input, init) {
|
|
32
|
+
const request = new Request(input, init);
|
|
33
|
+
request.headers.delete("CF-Connecting-IP");
|
|
34
|
+
return request;
|
|
35
|
+
}
|
|
36
|
+
__name(stripCfConnectingIPHeader, "stripCfConnectingIPHeader");
|
|
37
|
+
globalThis.fetch = new Proxy(globalThis.fetch, {
|
|
38
|
+
apply(target, thisArg, argArray) {
|
|
39
|
+
return Reflect.apply(target, thisArg, [
|
|
40
|
+
stripCfConnectingIPHeader.apply(null, argArray)
|
|
41
|
+
]);
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
// ../../node_modules/.pnpm/hono@4.11.7/node_modules/hono/dist/compose.js
|
|
46
|
+
var compose = /* @__PURE__ */ __name((middleware, onError, onNotFound) => {
|
|
47
|
+
return (context, next) => {
|
|
48
|
+
let index = -1;
|
|
49
|
+
return dispatch(0);
|
|
50
|
+
async function dispatch(i) {
|
|
51
|
+
if (i <= index) {
|
|
52
|
+
throw new Error("next() called multiple times");
|
|
53
|
+
}
|
|
54
|
+
index = i;
|
|
55
|
+
let res;
|
|
56
|
+
let isError = false;
|
|
57
|
+
let handler;
|
|
58
|
+
if (middleware[i]) {
|
|
59
|
+
handler = middleware[i][0][0];
|
|
60
|
+
context.req.routeIndex = i;
|
|
61
|
+
} else {
|
|
62
|
+
handler = i === middleware.length && next || void 0;
|
|
63
|
+
}
|
|
64
|
+
if (handler) {
|
|
65
|
+
try {
|
|
66
|
+
res = await handler(context, () => dispatch(i + 1));
|
|
67
|
+
} catch (err) {
|
|
68
|
+
if (err instanceof Error && onError) {
|
|
69
|
+
context.error = err;
|
|
70
|
+
res = await onError(err, context);
|
|
71
|
+
isError = true;
|
|
72
|
+
} else {
|
|
73
|
+
throw err;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
} else {
|
|
77
|
+
if (context.finalized === false && onNotFound) {
|
|
78
|
+
res = await onNotFound(context);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
if (res && (context.finalized === false || isError)) {
|
|
82
|
+
context.res = res;
|
|
83
|
+
}
|
|
84
|
+
return context;
|
|
85
|
+
}
|
|
86
|
+
__name(dispatch, "dispatch");
|
|
87
|
+
};
|
|
88
|
+
}, "compose");
|
|
89
|
+
|
|
90
|
+
// ../../node_modules/.pnpm/hono@4.11.7/node_modules/hono/dist/request/constants.js
|
|
91
|
+
var GET_MATCH_RESULT = /* @__PURE__ */ Symbol();
|
|
92
|
+
|
|
93
|
+
// ../../node_modules/.pnpm/hono@4.11.7/node_modules/hono/dist/utils/body.js
|
|
94
|
+
var parseBody = /* @__PURE__ */ __name(async (request, options = /* @__PURE__ */ Object.create(null)) => {
|
|
95
|
+
const { all = false, dot = false } = options;
|
|
96
|
+
const headers = request instanceof HonoRequest ? request.raw.headers : request.headers;
|
|
97
|
+
const contentType = headers.get("Content-Type");
|
|
98
|
+
if (contentType?.startsWith("multipart/form-data") || contentType?.startsWith("application/x-www-form-urlencoded")) {
|
|
99
|
+
return parseFormData(request, { all, dot });
|
|
100
|
+
}
|
|
101
|
+
return {};
|
|
102
|
+
}, "parseBody");
|
|
103
|
+
async function parseFormData(request, options) {
|
|
104
|
+
const formData = await request.formData();
|
|
105
|
+
if (formData) {
|
|
106
|
+
return convertFormDataToBodyData(formData, options);
|
|
107
|
+
}
|
|
108
|
+
return {};
|
|
109
|
+
}
|
|
110
|
+
__name(parseFormData, "parseFormData");
|
|
111
|
+
function convertFormDataToBodyData(formData, options) {
|
|
112
|
+
const form = /* @__PURE__ */ Object.create(null);
|
|
113
|
+
formData.forEach((value, key) => {
|
|
114
|
+
const shouldParseAllValues = options.all || key.endsWith("[]");
|
|
115
|
+
if (!shouldParseAllValues) {
|
|
116
|
+
form[key] = value;
|
|
117
|
+
} else {
|
|
118
|
+
handleParsingAllValues(form, key, value);
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
if (options.dot) {
|
|
122
|
+
Object.entries(form).forEach(([key, value]) => {
|
|
123
|
+
const shouldParseDotValues = key.includes(".");
|
|
124
|
+
if (shouldParseDotValues) {
|
|
125
|
+
handleParsingNestedValues(form, key, value);
|
|
126
|
+
delete form[key];
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
return form;
|
|
131
|
+
}
|
|
132
|
+
__name(convertFormDataToBodyData, "convertFormDataToBodyData");
|
|
133
|
+
var handleParsingAllValues = /* @__PURE__ */ __name((form, key, value) => {
|
|
134
|
+
if (form[key] !== void 0) {
|
|
135
|
+
if (Array.isArray(form[key])) {
|
|
136
|
+
;
|
|
137
|
+
form[key].push(value);
|
|
138
|
+
} else {
|
|
139
|
+
form[key] = [form[key], value];
|
|
140
|
+
}
|
|
141
|
+
} else {
|
|
142
|
+
if (!key.endsWith("[]")) {
|
|
143
|
+
form[key] = value;
|
|
144
|
+
} else {
|
|
145
|
+
form[key] = [value];
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}, "handleParsingAllValues");
|
|
149
|
+
var handleParsingNestedValues = /* @__PURE__ */ __name((form, key, value) => {
|
|
150
|
+
let nestedForm = form;
|
|
151
|
+
const keys = key.split(".");
|
|
152
|
+
keys.forEach((key2, index) => {
|
|
153
|
+
if (index === keys.length - 1) {
|
|
154
|
+
nestedForm[key2] = value;
|
|
155
|
+
} else {
|
|
156
|
+
if (!nestedForm[key2] || typeof nestedForm[key2] !== "object" || Array.isArray(nestedForm[key2]) || nestedForm[key2] instanceof File) {
|
|
157
|
+
nestedForm[key2] = /* @__PURE__ */ Object.create(null);
|
|
158
|
+
}
|
|
159
|
+
nestedForm = nestedForm[key2];
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
}, "handleParsingNestedValues");
|
|
163
|
+
|
|
164
|
+
// ../../node_modules/.pnpm/hono@4.11.7/node_modules/hono/dist/utils/url.js
|
|
165
|
+
var splitPath = /* @__PURE__ */ __name((path) => {
|
|
166
|
+
const paths = path.split("/");
|
|
167
|
+
if (paths[0] === "") {
|
|
168
|
+
paths.shift();
|
|
169
|
+
}
|
|
170
|
+
return paths;
|
|
171
|
+
}, "splitPath");
|
|
172
|
+
var splitRoutingPath = /* @__PURE__ */ __name((routePath) => {
|
|
173
|
+
const { groups, path } = extractGroupsFromPath(routePath);
|
|
174
|
+
const paths = splitPath(path);
|
|
175
|
+
return replaceGroupMarks(paths, groups);
|
|
176
|
+
}, "splitRoutingPath");
|
|
177
|
+
var extractGroupsFromPath = /* @__PURE__ */ __name((path) => {
|
|
178
|
+
const groups = [];
|
|
179
|
+
path = path.replace(/\{[^}]+\}/g, (match2, index) => {
|
|
180
|
+
const mark = `@${index}`;
|
|
181
|
+
groups.push([mark, match2]);
|
|
182
|
+
return mark;
|
|
183
|
+
});
|
|
184
|
+
return { groups, path };
|
|
185
|
+
}, "extractGroupsFromPath");
|
|
186
|
+
var replaceGroupMarks = /* @__PURE__ */ __name((paths, groups) => {
|
|
187
|
+
for (let i = groups.length - 1; i >= 0; i--) {
|
|
188
|
+
const [mark] = groups[i];
|
|
189
|
+
for (let j = paths.length - 1; j >= 0; j--) {
|
|
190
|
+
if (paths[j].includes(mark)) {
|
|
191
|
+
paths[j] = paths[j].replace(mark, groups[i][1]);
|
|
192
|
+
break;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
return paths;
|
|
197
|
+
}, "replaceGroupMarks");
|
|
198
|
+
var patternCache = {};
|
|
199
|
+
var getPattern = /* @__PURE__ */ __name((label, next) => {
|
|
200
|
+
if (label === "*") {
|
|
201
|
+
return "*";
|
|
202
|
+
}
|
|
203
|
+
const match2 = label.match(/^\:([^\{\}]+)(?:\{(.+)\})?$/);
|
|
204
|
+
if (match2) {
|
|
205
|
+
const cacheKey = `${label}#${next}`;
|
|
206
|
+
if (!patternCache[cacheKey]) {
|
|
207
|
+
if (match2[2]) {
|
|
208
|
+
patternCache[cacheKey] = next && next[0] !== ":" && next[0] !== "*" ? [cacheKey, match2[1], new RegExp(`^${match2[2]}(?=/${next})`)] : [label, match2[1], new RegExp(`^${match2[2]}$`)];
|
|
209
|
+
} else {
|
|
210
|
+
patternCache[cacheKey] = [label, match2[1], true];
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
return patternCache[cacheKey];
|
|
214
|
+
}
|
|
215
|
+
return null;
|
|
216
|
+
}, "getPattern");
|
|
217
|
+
var tryDecode = /* @__PURE__ */ __name((str, decoder) => {
|
|
218
|
+
try {
|
|
219
|
+
return decoder(str);
|
|
220
|
+
} catch {
|
|
221
|
+
return str.replace(/(?:%[0-9A-Fa-f]{2})+/g, (match2) => {
|
|
222
|
+
try {
|
|
223
|
+
return decoder(match2);
|
|
224
|
+
} catch {
|
|
225
|
+
return match2;
|
|
226
|
+
}
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
}, "tryDecode");
|
|
230
|
+
var tryDecodeURI = /* @__PURE__ */ __name((str) => tryDecode(str, decodeURI), "tryDecodeURI");
|
|
231
|
+
var getPath = /* @__PURE__ */ __name((request) => {
|
|
232
|
+
const url = request.url;
|
|
233
|
+
const start = url.indexOf("/", url.indexOf(":") + 4);
|
|
234
|
+
let i = start;
|
|
235
|
+
for (; i < url.length; i++) {
|
|
236
|
+
const charCode = url.charCodeAt(i);
|
|
237
|
+
if (charCode === 37) {
|
|
238
|
+
const queryIndex = url.indexOf("?", i);
|
|
239
|
+
const path = url.slice(start, queryIndex === -1 ? void 0 : queryIndex);
|
|
240
|
+
return tryDecodeURI(path.includes("%25") ? path.replace(/%25/g, "%2525") : path);
|
|
241
|
+
} else if (charCode === 63) {
|
|
242
|
+
break;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
return url.slice(start, i);
|
|
246
|
+
}, "getPath");
|
|
247
|
+
var getPathNoStrict = /* @__PURE__ */ __name((request) => {
|
|
248
|
+
const result = getPath(request);
|
|
249
|
+
return result.length > 1 && result.at(-1) === "/" ? result.slice(0, -1) : result;
|
|
250
|
+
}, "getPathNoStrict");
|
|
251
|
+
var mergePath = /* @__PURE__ */ __name((base, sub, ...rest) => {
|
|
252
|
+
if (rest.length) {
|
|
253
|
+
sub = mergePath(sub, ...rest);
|
|
254
|
+
}
|
|
255
|
+
return `${base?.[0] === "/" ? "" : "/"}${base}${sub === "/" ? "" : `${base?.at(-1) === "/" ? "" : "/"}${sub?.[0] === "/" ? sub.slice(1) : sub}`}`;
|
|
256
|
+
}, "mergePath");
|
|
257
|
+
var checkOptionalParameter = /* @__PURE__ */ __name((path) => {
|
|
258
|
+
if (path.charCodeAt(path.length - 1) !== 63 || !path.includes(":")) {
|
|
259
|
+
return null;
|
|
260
|
+
}
|
|
261
|
+
const segments = path.split("/");
|
|
262
|
+
const results = [];
|
|
263
|
+
let basePath = "";
|
|
264
|
+
segments.forEach((segment) => {
|
|
265
|
+
if (segment !== "" && !/\:/.test(segment)) {
|
|
266
|
+
basePath += "/" + segment;
|
|
267
|
+
} else if (/\:/.test(segment)) {
|
|
268
|
+
if (/\?/.test(segment)) {
|
|
269
|
+
if (results.length === 0 && basePath === "") {
|
|
270
|
+
results.push("/");
|
|
271
|
+
} else {
|
|
272
|
+
results.push(basePath);
|
|
273
|
+
}
|
|
274
|
+
const optionalSegment = segment.replace("?", "");
|
|
275
|
+
basePath += "/" + optionalSegment;
|
|
276
|
+
results.push(basePath);
|
|
277
|
+
} else {
|
|
278
|
+
basePath += "/" + segment;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
});
|
|
282
|
+
return results.filter((v, i, a) => a.indexOf(v) === i);
|
|
283
|
+
}, "checkOptionalParameter");
|
|
284
|
+
var _decodeURI = /* @__PURE__ */ __name((value) => {
|
|
285
|
+
if (!/[%+]/.test(value)) {
|
|
286
|
+
return value;
|
|
287
|
+
}
|
|
288
|
+
if (value.indexOf("+") !== -1) {
|
|
289
|
+
value = value.replace(/\+/g, " ");
|
|
290
|
+
}
|
|
291
|
+
return value.indexOf("%") !== -1 ? tryDecode(value, decodeURIComponent_) : value;
|
|
292
|
+
}, "_decodeURI");
|
|
293
|
+
var _getQueryParam = /* @__PURE__ */ __name((url, key, multiple) => {
|
|
294
|
+
let encoded;
|
|
295
|
+
if (!multiple && key && !/[%+]/.test(key)) {
|
|
296
|
+
let keyIndex2 = url.indexOf("?", 8);
|
|
297
|
+
if (keyIndex2 === -1) {
|
|
298
|
+
return void 0;
|
|
299
|
+
}
|
|
300
|
+
if (!url.startsWith(key, keyIndex2 + 1)) {
|
|
301
|
+
keyIndex2 = url.indexOf(`&${key}`, keyIndex2 + 1);
|
|
302
|
+
}
|
|
303
|
+
while (keyIndex2 !== -1) {
|
|
304
|
+
const trailingKeyCode = url.charCodeAt(keyIndex2 + key.length + 1);
|
|
305
|
+
if (trailingKeyCode === 61) {
|
|
306
|
+
const valueIndex = keyIndex2 + key.length + 2;
|
|
307
|
+
const endIndex = url.indexOf("&", valueIndex);
|
|
308
|
+
return _decodeURI(url.slice(valueIndex, endIndex === -1 ? void 0 : endIndex));
|
|
309
|
+
} else if (trailingKeyCode == 38 || isNaN(trailingKeyCode)) {
|
|
310
|
+
return "";
|
|
311
|
+
}
|
|
312
|
+
keyIndex2 = url.indexOf(`&${key}`, keyIndex2 + 1);
|
|
313
|
+
}
|
|
314
|
+
encoded = /[%+]/.test(url);
|
|
315
|
+
if (!encoded) {
|
|
316
|
+
return void 0;
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
const results = {};
|
|
320
|
+
encoded ??= /[%+]/.test(url);
|
|
321
|
+
let keyIndex = url.indexOf("?", 8);
|
|
322
|
+
while (keyIndex !== -1) {
|
|
323
|
+
const nextKeyIndex = url.indexOf("&", keyIndex + 1);
|
|
324
|
+
let valueIndex = url.indexOf("=", keyIndex);
|
|
325
|
+
if (valueIndex > nextKeyIndex && nextKeyIndex !== -1) {
|
|
326
|
+
valueIndex = -1;
|
|
327
|
+
}
|
|
328
|
+
let name = url.slice(
|
|
329
|
+
keyIndex + 1,
|
|
330
|
+
valueIndex === -1 ? nextKeyIndex === -1 ? void 0 : nextKeyIndex : valueIndex
|
|
331
|
+
);
|
|
332
|
+
if (encoded) {
|
|
333
|
+
name = _decodeURI(name);
|
|
334
|
+
}
|
|
335
|
+
keyIndex = nextKeyIndex;
|
|
336
|
+
if (name === "") {
|
|
337
|
+
continue;
|
|
338
|
+
}
|
|
339
|
+
let value;
|
|
340
|
+
if (valueIndex === -1) {
|
|
341
|
+
value = "";
|
|
342
|
+
} else {
|
|
343
|
+
value = url.slice(valueIndex + 1, nextKeyIndex === -1 ? void 0 : nextKeyIndex);
|
|
344
|
+
if (encoded) {
|
|
345
|
+
value = _decodeURI(value);
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
if (multiple) {
|
|
349
|
+
if (!(results[name] && Array.isArray(results[name]))) {
|
|
350
|
+
results[name] = [];
|
|
351
|
+
}
|
|
352
|
+
;
|
|
353
|
+
results[name].push(value);
|
|
354
|
+
} else {
|
|
355
|
+
results[name] ??= value;
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
return key ? results[key] : results;
|
|
359
|
+
}, "_getQueryParam");
|
|
360
|
+
var getQueryParam = _getQueryParam;
|
|
361
|
+
var getQueryParams = /* @__PURE__ */ __name((url, key) => {
|
|
362
|
+
return _getQueryParam(url, key, true);
|
|
363
|
+
}, "getQueryParams");
|
|
364
|
+
var decodeURIComponent_ = decodeURIComponent;
|
|
365
|
+
|
|
366
|
+
// ../../node_modules/.pnpm/hono@4.11.7/node_modules/hono/dist/request.js
|
|
367
|
+
var tryDecodeURIComponent = /* @__PURE__ */ __name((str) => tryDecode(str, decodeURIComponent_), "tryDecodeURIComponent");
|
|
368
|
+
var HonoRequest = /* @__PURE__ */ __name(class {
|
|
369
|
+
/**
|
|
370
|
+
* `.raw` can get the raw Request object.
|
|
371
|
+
*
|
|
372
|
+
* @see {@link https://hono.dev/docs/api/request#raw}
|
|
373
|
+
*
|
|
374
|
+
* @example
|
|
375
|
+
* ```ts
|
|
376
|
+
* // For Cloudflare Workers
|
|
377
|
+
* app.post('/', async (c) => {
|
|
378
|
+
* const metadata = c.req.raw.cf?.hostMetadata?
|
|
379
|
+
* ...
|
|
380
|
+
* })
|
|
381
|
+
* ```
|
|
382
|
+
*/
|
|
383
|
+
raw;
|
|
384
|
+
#validatedData;
|
|
385
|
+
// Short name of validatedData
|
|
386
|
+
#matchResult;
|
|
387
|
+
routeIndex = 0;
|
|
388
|
+
/**
|
|
389
|
+
* `.path` can get the pathname of the request.
|
|
390
|
+
*
|
|
391
|
+
* @see {@link https://hono.dev/docs/api/request#path}
|
|
392
|
+
*
|
|
393
|
+
* @example
|
|
394
|
+
* ```ts
|
|
395
|
+
* app.get('/about/me', (c) => {
|
|
396
|
+
* const pathname = c.req.path // `/about/me`
|
|
397
|
+
* })
|
|
398
|
+
* ```
|
|
399
|
+
*/
|
|
400
|
+
path;
|
|
401
|
+
bodyCache = {};
|
|
402
|
+
constructor(request, path = "/", matchResult = [[]]) {
|
|
403
|
+
this.raw = request;
|
|
404
|
+
this.path = path;
|
|
405
|
+
this.#matchResult = matchResult;
|
|
406
|
+
this.#validatedData = {};
|
|
407
|
+
}
|
|
408
|
+
param(key) {
|
|
409
|
+
return key ? this.#getDecodedParam(key) : this.#getAllDecodedParams();
|
|
410
|
+
}
|
|
411
|
+
#getDecodedParam(key) {
|
|
412
|
+
const paramKey = this.#matchResult[0][this.routeIndex][1][key];
|
|
413
|
+
const param = this.#getParamValue(paramKey);
|
|
414
|
+
return param && /\%/.test(param) ? tryDecodeURIComponent(param) : param;
|
|
415
|
+
}
|
|
416
|
+
#getAllDecodedParams() {
|
|
417
|
+
const decoded = {};
|
|
418
|
+
const keys = Object.keys(this.#matchResult[0][this.routeIndex][1]);
|
|
419
|
+
for (const key of keys) {
|
|
420
|
+
const value = this.#getParamValue(this.#matchResult[0][this.routeIndex][1][key]);
|
|
421
|
+
if (value !== void 0) {
|
|
422
|
+
decoded[key] = /\%/.test(value) ? tryDecodeURIComponent(value) : value;
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
return decoded;
|
|
426
|
+
}
|
|
427
|
+
#getParamValue(paramKey) {
|
|
428
|
+
return this.#matchResult[1] ? this.#matchResult[1][paramKey] : paramKey;
|
|
429
|
+
}
|
|
430
|
+
query(key) {
|
|
431
|
+
return getQueryParam(this.url, key);
|
|
432
|
+
}
|
|
433
|
+
queries(key) {
|
|
434
|
+
return getQueryParams(this.url, key);
|
|
435
|
+
}
|
|
436
|
+
header(name) {
|
|
437
|
+
if (name) {
|
|
438
|
+
return this.raw.headers.get(name) ?? void 0;
|
|
439
|
+
}
|
|
440
|
+
const headerData = {};
|
|
441
|
+
this.raw.headers.forEach((value, key) => {
|
|
442
|
+
headerData[key] = value;
|
|
443
|
+
});
|
|
444
|
+
return headerData;
|
|
445
|
+
}
|
|
446
|
+
async parseBody(options) {
|
|
447
|
+
return this.bodyCache.parsedBody ??= await parseBody(this, options);
|
|
448
|
+
}
|
|
449
|
+
#cachedBody = (key) => {
|
|
450
|
+
const { bodyCache, raw: raw2 } = this;
|
|
451
|
+
const cachedBody = bodyCache[key];
|
|
452
|
+
if (cachedBody) {
|
|
453
|
+
return cachedBody;
|
|
454
|
+
}
|
|
455
|
+
const anyCachedKey = Object.keys(bodyCache)[0];
|
|
456
|
+
if (anyCachedKey) {
|
|
457
|
+
return bodyCache[anyCachedKey].then((body) => {
|
|
458
|
+
if (anyCachedKey === "json") {
|
|
459
|
+
body = JSON.stringify(body);
|
|
460
|
+
}
|
|
461
|
+
return new Response(body)[key]();
|
|
462
|
+
});
|
|
463
|
+
}
|
|
464
|
+
return bodyCache[key] = raw2[key]();
|
|
465
|
+
};
|
|
466
|
+
/**
|
|
467
|
+
* `.json()` can parse Request body of type `application/json`
|
|
468
|
+
*
|
|
469
|
+
* @see {@link https://hono.dev/docs/api/request#json}
|
|
470
|
+
*
|
|
471
|
+
* @example
|
|
472
|
+
* ```ts
|
|
473
|
+
* app.post('/entry', async (c) => {
|
|
474
|
+
* const body = await c.req.json()
|
|
475
|
+
* })
|
|
476
|
+
* ```
|
|
477
|
+
*/
|
|
478
|
+
json() {
|
|
479
|
+
return this.#cachedBody("text").then((text) => JSON.parse(text));
|
|
480
|
+
}
|
|
481
|
+
/**
|
|
482
|
+
* `.text()` can parse Request body of type `text/plain`
|
|
483
|
+
*
|
|
484
|
+
* @see {@link https://hono.dev/docs/api/request#text}
|
|
485
|
+
*
|
|
486
|
+
* @example
|
|
487
|
+
* ```ts
|
|
488
|
+
* app.post('/entry', async (c) => {
|
|
489
|
+
* const body = await c.req.text()
|
|
490
|
+
* })
|
|
491
|
+
* ```
|
|
492
|
+
*/
|
|
493
|
+
text() {
|
|
494
|
+
return this.#cachedBody("text");
|
|
495
|
+
}
|
|
496
|
+
/**
|
|
497
|
+
* `.arrayBuffer()` parse Request body as an `ArrayBuffer`
|
|
498
|
+
*
|
|
499
|
+
* @see {@link https://hono.dev/docs/api/request#arraybuffer}
|
|
500
|
+
*
|
|
501
|
+
* @example
|
|
502
|
+
* ```ts
|
|
503
|
+
* app.post('/entry', async (c) => {
|
|
504
|
+
* const body = await c.req.arrayBuffer()
|
|
505
|
+
* })
|
|
506
|
+
* ```
|
|
507
|
+
*/
|
|
508
|
+
arrayBuffer() {
|
|
509
|
+
return this.#cachedBody("arrayBuffer");
|
|
510
|
+
}
|
|
511
|
+
/**
|
|
512
|
+
* Parses the request body as a `Blob`.
|
|
513
|
+
* @example
|
|
514
|
+
* ```ts
|
|
515
|
+
* app.post('/entry', async (c) => {
|
|
516
|
+
* const body = await c.req.blob();
|
|
517
|
+
* });
|
|
518
|
+
* ```
|
|
519
|
+
* @see https://hono.dev/docs/api/request#blob
|
|
520
|
+
*/
|
|
521
|
+
blob() {
|
|
522
|
+
return this.#cachedBody("blob");
|
|
523
|
+
}
|
|
524
|
+
/**
|
|
525
|
+
* Parses the request body as `FormData`.
|
|
526
|
+
* @example
|
|
527
|
+
* ```ts
|
|
528
|
+
* app.post('/entry', async (c) => {
|
|
529
|
+
* const body = await c.req.formData();
|
|
530
|
+
* });
|
|
531
|
+
* ```
|
|
532
|
+
* @see https://hono.dev/docs/api/request#formdata
|
|
533
|
+
*/
|
|
534
|
+
formData() {
|
|
535
|
+
return this.#cachedBody("formData");
|
|
536
|
+
}
|
|
537
|
+
/**
|
|
538
|
+
* Adds validated data to the request.
|
|
539
|
+
*
|
|
540
|
+
* @param target - The target of the validation.
|
|
541
|
+
* @param data - The validated data to add.
|
|
542
|
+
*/
|
|
543
|
+
addValidatedData(target, data) {
|
|
544
|
+
this.#validatedData[target] = data;
|
|
545
|
+
}
|
|
546
|
+
valid(target) {
|
|
547
|
+
return this.#validatedData[target];
|
|
548
|
+
}
|
|
549
|
+
/**
|
|
550
|
+
* `.url()` can get the request url strings.
|
|
551
|
+
*
|
|
552
|
+
* @see {@link https://hono.dev/docs/api/request#url}
|
|
553
|
+
*
|
|
554
|
+
* @example
|
|
555
|
+
* ```ts
|
|
556
|
+
* app.get('/about/me', (c) => {
|
|
557
|
+
* const url = c.req.url // `http://localhost:8787/about/me`
|
|
558
|
+
* ...
|
|
559
|
+
* })
|
|
560
|
+
* ```
|
|
561
|
+
*/
|
|
562
|
+
get url() {
|
|
563
|
+
return this.raw.url;
|
|
564
|
+
}
|
|
565
|
+
/**
|
|
566
|
+
* `.method()` can get the method name of the request.
|
|
567
|
+
*
|
|
568
|
+
* @see {@link https://hono.dev/docs/api/request#method}
|
|
569
|
+
*
|
|
570
|
+
* @example
|
|
571
|
+
* ```ts
|
|
572
|
+
* app.get('/about/me', (c) => {
|
|
573
|
+
* const method = c.req.method // `GET`
|
|
574
|
+
* })
|
|
575
|
+
* ```
|
|
576
|
+
*/
|
|
577
|
+
get method() {
|
|
578
|
+
return this.raw.method;
|
|
579
|
+
}
|
|
580
|
+
get [GET_MATCH_RESULT]() {
|
|
581
|
+
return this.#matchResult;
|
|
582
|
+
}
|
|
583
|
+
/**
|
|
584
|
+
* `.matchedRoutes()` can return a matched route in the handler
|
|
585
|
+
*
|
|
586
|
+
* @deprecated
|
|
587
|
+
*
|
|
588
|
+
* Use matchedRoutes helper defined in "hono/route" instead.
|
|
589
|
+
*
|
|
590
|
+
* @see {@link https://hono.dev/docs/api/request#matchedroutes}
|
|
591
|
+
*
|
|
592
|
+
* @example
|
|
593
|
+
* ```ts
|
|
594
|
+
* app.use('*', async function logger(c, next) {
|
|
595
|
+
* await next()
|
|
596
|
+
* c.req.matchedRoutes.forEach(({ handler, method, path }, i) => {
|
|
597
|
+
* const name = handler.name || (handler.length < 2 ? '[handler]' : '[middleware]')
|
|
598
|
+
* console.log(
|
|
599
|
+
* method,
|
|
600
|
+
* ' ',
|
|
601
|
+
* path,
|
|
602
|
+
* ' '.repeat(Math.max(10 - path.length, 0)),
|
|
603
|
+
* name,
|
|
604
|
+
* i === c.req.routeIndex ? '<- respond from here' : ''
|
|
605
|
+
* )
|
|
606
|
+
* })
|
|
607
|
+
* })
|
|
608
|
+
* ```
|
|
609
|
+
*/
|
|
610
|
+
get matchedRoutes() {
|
|
611
|
+
return this.#matchResult[0].map(([[, route]]) => route);
|
|
612
|
+
}
|
|
613
|
+
/**
|
|
614
|
+
* `routePath()` can retrieve the path registered within the handler
|
|
615
|
+
*
|
|
616
|
+
* @deprecated
|
|
617
|
+
*
|
|
618
|
+
* Use routePath helper defined in "hono/route" instead.
|
|
619
|
+
*
|
|
620
|
+
* @see {@link https://hono.dev/docs/api/request#routepath}
|
|
621
|
+
*
|
|
622
|
+
* @example
|
|
623
|
+
* ```ts
|
|
624
|
+
* app.get('/posts/:id', (c) => {
|
|
625
|
+
* return c.json({ path: c.req.routePath })
|
|
626
|
+
* })
|
|
627
|
+
* ```
|
|
628
|
+
*/
|
|
629
|
+
get routePath() {
|
|
630
|
+
return this.#matchResult[0].map(([[, route]]) => route)[this.routeIndex].path;
|
|
631
|
+
}
|
|
632
|
+
}, "HonoRequest");
|
|
633
|
+
|
|
634
|
+
// ../../node_modules/.pnpm/hono@4.11.7/node_modules/hono/dist/utils/html.js
|
|
635
|
+
var HtmlEscapedCallbackPhase = {
|
|
636
|
+
Stringify: 1,
|
|
637
|
+
BeforeStream: 2,
|
|
638
|
+
Stream: 3
|
|
639
|
+
};
|
|
640
|
+
var raw = /* @__PURE__ */ __name((value, callbacks) => {
|
|
641
|
+
const escapedString = new String(value);
|
|
642
|
+
escapedString.isEscaped = true;
|
|
643
|
+
escapedString.callbacks = callbacks;
|
|
644
|
+
return escapedString;
|
|
645
|
+
}, "raw");
|
|
646
|
+
var resolveCallback = /* @__PURE__ */ __name(async (str, phase, preserveCallbacks, context, buffer) => {
|
|
647
|
+
if (typeof str === "object" && !(str instanceof String)) {
|
|
648
|
+
if (!(str instanceof Promise)) {
|
|
649
|
+
str = str.toString();
|
|
650
|
+
}
|
|
651
|
+
if (str instanceof Promise) {
|
|
652
|
+
str = await str;
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
const callbacks = str.callbacks;
|
|
656
|
+
if (!callbacks?.length) {
|
|
657
|
+
return Promise.resolve(str);
|
|
658
|
+
}
|
|
659
|
+
if (buffer) {
|
|
660
|
+
buffer[0] += str;
|
|
661
|
+
} else {
|
|
662
|
+
buffer = [str];
|
|
663
|
+
}
|
|
664
|
+
const resStr = Promise.all(callbacks.map((c) => c({ phase, buffer, context }))).then(
|
|
665
|
+
(res) => Promise.all(
|
|
666
|
+
res.filter(Boolean).map((str2) => resolveCallback(str2, phase, false, context, buffer))
|
|
667
|
+
).then(() => buffer[0])
|
|
668
|
+
);
|
|
669
|
+
if (preserveCallbacks) {
|
|
670
|
+
return raw(await resStr, callbacks);
|
|
671
|
+
} else {
|
|
672
|
+
return resStr;
|
|
673
|
+
}
|
|
674
|
+
}, "resolveCallback");
|
|
675
|
+
|
|
676
|
+
// ../../node_modules/.pnpm/hono@4.11.7/node_modules/hono/dist/context.js
|
|
677
|
+
var TEXT_PLAIN = "text/plain; charset=UTF-8";
|
|
678
|
+
var setDefaultContentType = /* @__PURE__ */ __name((contentType, headers) => {
|
|
679
|
+
return {
|
|
680
|
+
"Content-Type": contentType,
|
|
681
|
+
...headers
|
|
682
|
+
};
|
|
683
|
+
}, "setDefaultContentType");
|
|
684
|
+
var Context = /* @__PURE__ */ __name(class {
|
|
685
|
+
#rawRequest;
|
|
686
|
+
#req;
|
|
687
|
+
/**
|
|
688
|
+
* `.env` can get bindings (environment variables, secrets, KV namespaces, D1 database, R2 bucket etc.) in Cloudflare Workers.
|
|
689
|
+
*
|
|
690
|
+
* @see {@link https://hono.dev/docs/api/context#env}
|
|
691
|
+
*
|
|
692
|
+
* @example
|
|
693
|
+
* ```ts
|
|
694
|
+
* // Environment object for Cloudflare Workers
|
|
695
|
+
* app.get('*', async c => {
|
|
696
|
+
* const counter = c.env.COUNTER
|
|
697
|
+
* })
|
|
698
|
+
* ```
|
|
699
|
+
*/
|
|
700
|
+
env = {};
|
|
701
|
+
#var;
|
|
702
|
+
finalized = false;
|
|
703
|
+
/**
|
|
704
|
+
* `.error` can get the error object from the middleware if the Handler throws an error.
|
|
705
|
+
*
|
|
706
|
+
* @see {@link https://hono.dev/docs/api/context#error}
|
|
707
|
+
*
|
|
708
|
+
* @example
|
|
709
|
+
* ```ts
|
|
710
|
+
* app.use('*', async (c, next) => {
|
|
711
|
+
* await next()
|
|
712
|
+
* if (c.error) {
|
|
713
|
+
* // do something...
|
|
714
|
+
* }
|
|
715
|
+
* })
|
|
716
|
+
* ```
|
|
717
|
+
*/
|
|
718
|
+
error;
|
|
719
|
+
#status;
|
|
720
|
+
#executionCtx;
|
|
721
|
+
#res;
|
|
722
|
+
#layout;
|
|
723
|
+
#renderer;
|
|
724
|
+
#notFoundHandler;
|
|
725
|
+
#preparedHeaders;
|
|
726
|
+
#matchResult;
|
|
727
|
+
#path;
|
|
728
|
+
/**
|
|
729
|
+
* Creates an instance of the Context class.
|
|
730
|
+
*
|
|
731
|
+
* @param req - The Request object.
|
|
732
|
+
* @param options - Optional configuration options for the context.
|
|
733
|
+
*/
|
|
734
|
+
constructor(req, options) {
|
|
735
|
+
this.#rawRequest = req;
|
|
736
|
+
if (options) {
|
|
737
|
+
this.#executionCtx = options.executionCtx;
|
|
738
|
+
this.env = options.env;
|
|
739
|
+
this.#notFoundHandler = options.notFoundHandler;
|
|
740
|
+
this.#path = options.path;
|
|
741
|
+
this.#matchResult = options.matchResult;
|
|
742
|
+
}
|
|
743
|
+
}
|
|
744
|
+
/**
|
|
745
|
+
* `.req` is the instance of {@link HonoRequest}.
|
|
746
|
+
*/
|
|
747
|
+
get req() {
|
|
748
|
+
this.#req ??= new HonoRequest(this.#rawRequest, this.#path, this.#matchResult);
|
|
749
|
+
return this.#req;
|
|
750
|
+
}
|
|
751
|
+
/**
|
|
752
|
+
* @see {@link https://hono.dev/docs/api/context#event}
|
|
753
|
+
* The FetchEvent associated with the current request.
|
|
754
|
+
*
|
|
755
|
+
* @throws Will throw an error if the context does not have a FetchEvent.
|
|
756
|
+
*/
|
|
757
|
+
get event() {
|
|
758
|
+
if (this.#executionCtx && "respondWith" in this.#executionCtx) {
|
|
759
|
+
return this.#executionCtx;
|
|
760
|
+
} else {
|
|
761
|
+
throw Error("This context has no FetchEvent");
|
|
762
|
+
}
|
|
763
|
+
}
|
|
764
|
+
/**
|
|
765
|
+
* @see {@link https://hono.dev/docs/api/context#executionctx}
|
|
766
|
+
* The ExecutionContext associated with the current request.
|
|
767
|
+
*
|
|
768
|
+
* @throws Will throw an error if the context does not have an ExecutionContext.
|
|
769
|
+
*/
|
|
770
|
+
get executionCtx() {
|
|
771
|
+
if (this.#executionCtx) {
|
|
772
|
+
return this.#executionCtx;
|
|
773
|
+
} else {
|
|
774
|
+
throw Error("This context has no ExecutionContext");
|
|
775
|
+
}
|
|
776
|
+
}
|
|
777
|
+
/**
|
|
778
|
+
* @see {@link https://hono.dev/docs/api/context#res}
|
|
779
|
+
* The Response object for the current request.
|
|
780
|
+
*/
|
|
781
|
+
get res() {
|
|
782
|
+
return this.#res ||= new Response(null, {
|
|
783
|
+
headers: this.#preparedHeaders ??= new Headers()
|
|
784
|
+
});
|
|
785
|
+
}
|
|
786
|
+
/**
|
|
787
|
+
* Sets the Response object for the current request.
|
|
788
|
+
*
|
|
789
|
+
* @param _res - The Response object to set.
|
|
790
|
+
*/
|
|
791
|
+
set res(_res) {
|
|
792
|
+
if (this.#res && _res) {
|
|
793
|
+
_res = new Response(_res.body, _res);
|
|
794
|
+
for (const [k, v] of this.#res.headers.entries()) {
|
|
795
|
+
if (k === "content-type") {
|
|
796
|
+
continue;
|
|
797
|
+
}
|
|
798
|
+
if (k === "set-cookie") {
|
|
799
|
+
const cookies = this.#res.headers.getSetCookie();
|
|
800
|
+
_res.headers.delete("set-cookie");
|
|
801
|
+
for (const cookie of cookies) {
|
|
802
|
+
_res.headers.append("set-cookie", cookie);
|
|
803
|
+
}
|
|
804
|
+
} else {
|
|
805
|
+
_res.headers.set(k, v);
|
|
806
|
+
}
|
|
807
|
+
}
|
|
808
|
+
}
|
|
809
|
+
this.#res = _res;
|
|
810
|
+
this.finalized = true;
|
|
811
|
+
}
|
|
812
|
+
/**
|
|
813
|
+
* `.render()` can create a response within a layout.
|
|
814
|
+
*
|
|
815
|
+
* @see {@link https://hono.dev/docs/api/context#render-setrenderer}
|
|
816
|
+
*
|
|
817
|
+
* @example
|
|
818
|
+
* ```ts
|
|
819
|
+
* app.get('/', (c) => {
|
|
820
|
+
* return c.render('Hello!')
|
|
821
|
+
* })
|
|
822
|
+
* ```
|
|
823
|
+
*/
|
|
824
|
+
render = (...args) => {
|
|
825
|
+
this.#renderer ??= (content) => this.html(content);
|
|
826
|
+
return this.#renderer(...args);
|
|
827
|
+
};
|
|
828
|
+
/**
|
|
829
|
+
* Sets the layout for the response.
|
|
830
|
+
*
|
|
831
|
+
* @param layout - The layout to set.
|
|
832
|
+
* @returns The layout function.
|
|
833
|
+
*/
|
|
834
|
+
setLayout = (layout) => this.#layout = layout;
|
|
835
|
+
/**
|
|
836
|
+
* Gets the current layout for the response.
|
|
837
|
+
*
|
|
838
|
+
* @returns The current layout function.
|
|
839
|
+
*/
|
|
840
|
+
getLayout = () => this.#layout;
|
|
841
|
+
/**
|
|
842
|
+
* `.setRenderer()` can set the layout in the custom middleware.
|
|
843
|
+
*
|
|
844
|
+
* @see {@link https://hono.dev/docs/api/context#render-setrenderer}
|
|
845
|
+
*
|
|
846
|
+
* @example
|
|
847
|
+
* ```tsx
|
|
848
|
+
* app.use('*', async (c, next) => {
|
|
849
|
+
* c.setRenderer((content) => {
|
|
850
|
+
* return c.html(
|
|
851
|
+
* <html>
|
|
852
|
+
* <body>
|
|
853
|
+
* <p>{content}</p>
|
|
854
|
+
* </body>
|
|
855
|
+
* </html>
|
|
856
|
+
* )
|
|
857
|
+
* })
|
|
858
|
+
* await next()
|
|
859
|
+
* })
|
|
860
|
+
* ```
|
|
861
|
+
*/
|
|
862
|
+
setRenderer = (renderer) => {
|
|
863
|
+
this.#renderer = renderer;
|
|
864
|
+
};
|
|
865
|
+
/**
|
|
866
|
+
* `.header()` can set headers.
|
|
867
|
+
*
|
|
868
|
+
* @see {@link https://hono.dev/docs/api/context#header}
|
|
869
|
+
*
|
|
870
|
+
* @example
|
|
871
|
+
* ```ts
|
|
872
|
+
* app.get('/welcome', (c) => {
|
|
873
|
+
* // Set headers
|
|
874
|
+
* c.header('X-Message', 'Hello!')
|
|
875
|
+
* c.header('Content-Type', 'text/plain')
|
|
876
|
+
*
|
|
877
|
+
* return c.body('Thank you for coming')
|
|
878
|
+
* })
|
|
879
|
+
* ```
|
|
880
|
+
*/
|
|
881
|
+
header = (name, value, options) => {
|
|
882
|
+
if (this.finalized) {
|
|
883
|
+
this.#res = new Response(this.#res.body, this.#res);
|
|
884
|
+
}
|
|
885
|
+
const headers = this.#res ? this.#res.headers : this.#preparedHeaders ??= new Headers();
|
|
886
|
+
if (value === void 0) {
|
|
887
|
+
headers.delete(name);
|
|
888
|
+
} else if (options?.append) {
|
|
889
|
+
headers.append(name, value);
|
|
890
|
+
} else {
|
|
891
|
+
headers.set(name, value);
|
|
892
|
+
}
|
|
893
|
+
};
|
|
894
|
+
status = (status) => {
|
|
895
|
+
this.#status = status;
|
|
896
|
+
};
|
|
897
|
+
/**
|
|
898
|
+
* `.set()` can set the value specified by the key.
|
|
899
|
+
*
|
|
900
|
+
* @see {@link https://hono.dev/docs/api/context#set-get}
|
|
901
|
+
*
|
|
902
|
+
* @example
|
|
903
|
+
* ```ts
|
|
904
|
+
* app.use('*', async (c, next) => {
|
|
905
|
+
* c.set('message', 'Hono is hot!!')
|
|
906
|
+
* await next()
|
|
907
|
+
* })
|
|
908
|
+
* ```
|
|
909
|
+
*/
|
|
910
|
+
set = (key, value) => {
|
|
911
|
+
this.#var ??= /* @__PURE__ */ new Map();
|
|
912
|
+
this.#var.set(key, value);
|
|
913
|
+
};
|
|
914
|
+
/**
|
|
915
|
+
* `.get()` can use the value specified by the key.
|
|
916
|
+
*
|
|
917
|
+
* @see {@link https://hono.dev/docs/api/context#set-get}
|
|
918
|
+
*
|
|
919
|
+
* @example
|
|
920
|
+
* ```ts
|
|
921
|
+
* app.get('/', (c) => {
|
|
922
|
+
* const message = c.get('message')
|
|
923
|
+
* return c.text(`The message is "${message}"`)
|
|
924
|
+
* })
|
|
925
|
+
* ```
|
|
926
|
+
*/
|
|
927
|
+
get = (key) => {
|
|
928
|
+
return this.#var ? this.#var.get(key) : void 0;
|
|
929
|
+
};
|
|
930
|
+
/**
|
|
931
|
+
* `.var` can access the value of a variable.
|
|
932
|
+
*
|
|
933
|
+
* @see {@link https://hono.dev/docs/api/context#var}
|
|
934
|
+
*
|
|
935
|
+
* @example
|
|
936
|
+
* ```ts
|
|
937
|
+
* const result = c.var.client.oneMethod()
|
|
938
|
+
* ```
|
|
939
|
+
*/
|
|
940
|
+
// c.var.propName is a read-only
|
|
941
|
+
get var() {
|
|
942
|
+
if (!this.#var) {
|
|
943
|
+
return {};
|
|
944
|
+
}
|
|
945
|
+
return Object.fromEntries(this.#var);
|
|
946
|
+
}
|
|
947
|
+
#newResponse(data, arg, headers) {
|
|
948
|
+
const responseHeaders = this.#res ? new Headers(this.#res.headers) : this.#preparedHeaders ?? new Headers();
|
|
949
|
+
if (typeof arg === "object" && "headers" in arg) {
|
|
950
|
+
const argHeaders = arg.headers instanceof Headers ? arg.headers : new Headers(arg.headers);
|
|
951
|
+
for (const [key, value] of argHeaders) {
|
|
952
|
+
if (key.toLowerCase() === "set-cookie") {
|
|
953
|
+
responseHeaders.append(key, value);
|
|
954
|
+
} else {
|
|
955
|
+
responseHeaders.set(key, value);
|
|
956
|
+
}
|
|
957
|
+
}
|
|
958
|
+
}
|
|
959
|
+
if (headers) {
|
|
960
|
+
for (const [k, v] of Object.entries(headers)) {
|
|
961
|
+
if (typeof v === "string") {
|
|
962
|
+
responseHeaders.set(k, v);
|
|
963
|
+
} else {
|
|
964
|
+
responseHeaders.delete(k);
|
|
965
|
+
for (const v2 of v) {
|
|
966
|
+
responseHeaders.append(k, v2);
|
|
967
|
+
}
|
|
968
|
+
}
|
|
969
|
+
}
|
|
970
|
+
}
|
|
971
|
+
const status = typeof arg === "number" ? arg : arg?.status ?? this.#status;
|
|
972
|
+
return new Response(data, { status, headers: responseHeaders });
|
|
973
|
+
}
|
|
974
|
+
newResponse = (...args) => this.#newResponse(...args);
|
|
975
|
+
/**
|
|
976
|
+
* `.body()` can return the HTTP response.
|
|
977
|
+
* You can set headers with `.header()` and set HTTP status code with `.status`.
|
|
978
|
+
* This can also be set in `.text()`, `.json()` and so on.
|
|
979
|
+
*
|
|
980
|
+
* @see {@link https://hono.dev/docs/api/context#body}
|
|
981
|
+
*
|
|
982
|
+
* @example
|
|
983
|
+
* ```ts
|
|
984
|
+
* app.get('/welcome', (c) => {
|
|
985
|
+
* // Set headers
|
|
986
|
+
* c.header('X-Message', 'Hello!')
|
|
987
|
+
* c.header('Content-Type', 'text/plain')
|
|
988
|
+
* // Set HTTP status code
|
|
989
|
+
* c.status(201)
|
|
990
|
+
*
|
|
991
|
+
* // Return the response body
|
|
992
|
+
* return c.body('Thank you for coming')
|
|
993
|
+
* })
|
|
994
|
+
* ```
|
|
995
|
+
*/
|
|
996
|
+
body = (data, arg, headers) => this.#newResponse(data, arg, headers);
|
|
997
|
+
/**
|
|
998
|
+
* `.text()` can render text as `Content-Type:text/plain`.
|
|
999
|
+
*
|
|
1000
|
+
* @see {@link https://hono.dev/docs/api/context#text}
|
|
1001
|
+
*
|
|
1002
|
+
* @example
|
|
1003
|
+
* ```ts
|
|
1004
|
+
* app.get('/say', (c) => {
|
|
1005
|
+
* return c.text('Hello!')
|
|
1006
|
+
* })
|
|
1007
|
+
* ```
|
|
1008
|
+
*/
|
|
1009
|
+
text = (text, arg, headers) => {
|
|
1010
|
+
return !this.#preparedHeaders && !this.#status && !arg && !headers && !this.finalized ? new Response(text) : this.#newResponse(
|
|
1011
|
+
text,
|
|
1012
|
+
arg,
|
|
1013
|
+
setDefaultContentType(TEXT_PLAIN, headers)
|
|
1014
|
+
);
|
|
1015
|
+
};
|
|
1016
|
+
/**
|
|
1017
|
+
* `.json()` can render JSON as `Content-Type:application/json`.
|
|
1018
|
+
*
|
|
1019
|
+
* @see {@link https://hono.dev/docs/api/context#json}
|
|
1020
|
+
*
|
|
1021
|
+
* @example
|
|
1022
|
+
* ```ts
|
|
1023
|
+
* app.get('/api', (c) => {
|
|
1024
|
+
* return c.json({ message: 'Hello!' })
|
|
1025
|
+
* })
|
|
1026
|
+
* ```
|
|
1027
|
+
*/
|
|
1028
|
+
json = (object, arg, headers) => {
|
|
1029
|
+
return this.#newResponse(
|
|
1030
|
+
JSON.stringify(object),
|
|
1031
|
+
arg,
|
|
1032
|
+
setDefaultContentType("application/json", headers)
|
|
1033
|
+
);
|
|
1034
|
+
};
|
|
1035
|
+
html = (html, arg, headers) => {
|
|
1036
|
+
const res = /* @__PURE__ */ __name((html2) => this.#newResponse(html2, arg, setDefaultContentType("text/html; charset=UTF-8", headers)), "res");
|
|
1037
|
+
return typeof html === "object" ? resolveCallback(html, HtmlEscapedCallbackPhase.Stringify, false, {}).then(res) : res(html);
|
|
1038
|
+
};
|
|
1039
|
+
/**
|
|
1040
|
+
* `.redirect()` can Redirect, default status code is 302.
|
|
1041
|
+
*
|
|
1042
|
+
* @see {@link https://hono.dev/docs/api/context#redirect}
|
|
1043
|
+
*
|
|
1044
|
+
* @example
|
|
1045
|
+
* ```ts
|
|
1046
|
+
* app.get('/redirect', (c) => {
|
|
1047
|
+
* return c.redirect('/')
|
|
1048
|
+
* })
|
|
1049
|
+
* app.get('/redirect-permanently', (c) => {
|
|
1050
|
+
* return c.redirect('/', 301)
|
|
1051
|
+
* })
|
|
1052
|
+
* ```
|
|
1053
|
+
*/
|
|
1054
|
+
redirect = (location, status) => {
|
|
1055
|
+
const locationString = String(location);
|
|
1056
|
+
this.header(
|
|
1057
|
+
"Location",
|
|
1058
|
+
// Multibyes should be encoded
|
|
1059
|
+
// eslint-disable-next-line no-control-regex
|
|
1060
|
+
!/[^\x00-\xFF]/.test(locationString) ? locationString : encodeURI(locationString)
|
|
1061
|
+
);
|
|
1062
|
+
return this.newResponse(null, status ?? 302);
|
|
1063
|
+
};
|
|
1064
|
+
/**
|
|
1065
|
+
* `.notFound()` can return the Not Found Response.
|
|
1066
|
+
*
|
|
1067
|
+
* @see {@link https://hono.dev/docs/api/context#notfound}
|
|
1068
|
+
*
|
|
1069
|
+
* @example
|
|
1070
|
+
* ```ts
|
|
1071
|
+
* app.get('/notfound', (c) => {
|
|
1072
|
+
* return c.notFound()
|
|
1073
|
+
* })
|
|
1074
|
+
* ```
|
|
1075
|
+
*/
|
|
1076
|
+
notFound = () => {
|
|
1077
|
+
this.#notFoundHandler ??= () => new Response();
|
|
1078
|
+
return this.#notFoundHandler(this);
|
|
1079
|
+
};
|
|
1080
|
+
}, "Context");
|
|
1081
|
+
|
|
1082
|
+
// ../../node_modules/.pnpm/hono@4.11.7/node_modules/hono/dist/router.js
|
|
1083
|
+
var METHOD_NAME_ALL = "ALL";
|
|
1084
|
+
var METHOD_NAME_ALL_LOWERCASE = "all";
|
|
1085
|
+
var METHODS = ["get", "post", "put", "delete", "options", "patch"];
|
|
1086
|
+
var MESSAGE_MATCHER_IS_ALREADY_BUILT = "Can not add a route since the matcher is already built.";
|
|
1087
|
+
var UnsupportedPathError = /* @__PURE__ */ __name(class extends Error {
|
|
1088
|
+
}, "UnsupportedPathError");
|
|
1089
|
+
|
|
1090
|
+
// ../../node_modules/.pnpm/hono@4.11.7/node_modules/hono/dist/utils/constants.js
|
|
1091
|
+
var COMPOSED_HANDLER = "__COMPOSED_HANDLER";
|
|
1092
|
+
|
|
1093
|
+
// ../../node_modules/.pnpm/hono@4.11.7/node_modules/hono/dist/hono-base.js
|
|
1094
|
+
var notFoundHandler = /* @__PURE__ */ __name((c) => {
|
|
1095
|
+
return c.text("404 Not Found", 404);
|
|
1096
|
+
}, "notFoundHandler");
|
|
1097
|
+
var errorHandler = /* @__PURE__ */ __name((err, c) => {
|
|
1098
|
+
if ("getResponse" in err) {
|
|
1099
|
+
const res = err.getResponse();
|
|
1100
|
+
return c.newResponse(res.body, res);
|
|
1101
|
+
}
|
|
1102
|
+
console.error(err);
|
|
1103
|
+
return c.text("Internal Server Error", 500);
|
|
1104
|
+
}, "errorHandler");
|
|
1105
|
+
var Hono = /* @__PURE__ */ __name(class _Hono {
|
|
1106
|
+
get;
|
|
1107
|
+
post;
|
|
1108
|
+
put;
|
|
1109
|
+
delete;
|
|
1110
|
+
options;
|
|
1111
|
+
patch;
|
|
1112
|
+
all;
|
|
1113
|
+
on;
|
|
1114
|
+
use;
|
|
1115
|
+
/*
|
|
1116
|
+
This class is like an abstract class and does not have a router.
|
|
1117
|
+
To use it, inherit the class and implement router in the constructor.
|
|
1118
|
+
*/
|
|
1119
|
+
router;
|
|
1120
|
+
getPath;
|
|
1121
|
+
// Cannot use `#` because it requires visibility at JavaScript runtime.
|
|
1122
|
+
_basePath = "/";
|
|
1123
|
+
#path = "/";
|
|
1124
|
+
routes = [];
|
|
1125
|
+
constructor(options = {}) {
|
|
1126
|
+
const allMethods = [...METHODS, METHOD_NAME_ALL_LOWERCASE];
|
|
1127
|
+
allMethods.forEach((method) => {
|
|
1128
|
+
this[method] = (args1, ...args) => {
|
|
1129
|
+
if (typeof args1 === "string") {
|
|
1130
|
+
this.#path = args1;
|
|
1131
|
+
} else {
|
|
1132
|
+
this.#addRoute(method, this.#path, args1);
|
|
1133
|
+
}
|
|
1134
|
+
args.forEach((handler) => {
|
|
1135
|
+
this.#addRoute(method, this.#path, handler);
|
|
1136
|
+
});
|
|
1137
|
+
return this;
|
|
1138
|
+
};
|
|
1139
|
+
});
|
|
1140
|
+
this.on = (method, path, ...handlers) => {
|
|
1141
|
+
for (const p of [path].flat()) {
|
|
1142
|
+
this.#path = p;
|
|
1143
|
+
for (const m of [method].flat()) {
|
|
1144
|
+
handlers.map((handler) => {
|
|
1145
|
+
this.#addRoute(m.toUpperCase(), this.#path, handler);
|
|
1146
|
+
});
|
|
1147
|
+
}
|
|
1148
|
+
}
|
|
1149
|
+
return this;
|
|
1150
|
+
};
|
|
1151
|
+
this.use = (arg1, ...handlers) => {
|
|
1152
|
+
if (typeof arg1 === "string") {
|
|
1153
|
+
this.#path = arg1;
|
|
1154
|
+
} else {
|
|
1155
|
+
this.#path = "*";
|
|
1156
|
+
handlers.unshift(arg1);
|
|
1157
|
+
}
|
|
1158
|
+
handlers.forEach((handler) => {
|
|
1159
|
+
this.#addRoute(METHOD_NAME_ALL, this.#path, handler);
|
|
1160
|
+
});
|
|
1161
|
+
return this;
|
|
1162
|
+
};
|
|
1163
|
+
const { strict, ...optionsWithoutStrict } = options;
|
|
1164
|
+
Object.assign(this, optionsWithoutStrict);
|
|
1165
|
+
this.getPath = strict ?? true ? options.getPath ?? getPath : getPathNoStrict;
|
|
1166
|
+
}
|
|
1167
|
+
#clone() {
|
|
1168
|
+
const clone = new _Hono({
|
|
1169
|
+
router: this.router,
|
|
1170
|
+
getPath: this.getPath
|
|
1171
|
+
});
|
|
1172
|
+
clone.errorHandler = this.errorHandler;
|
|
1173
|
+
clone.#notFoundHandler = this.#notFoundHandler;
|
|
1174
|
+
clone.routes = this.routes;
|
|
1175
|
+
return clone;
|
|
1176
|
+
}
|
|
1177
|
+
#notFoundHandler = notFoundHandler;
|
|
1178
|
+
// Cannot use `#` because it requires visibility at JavaScript runtime.
|
|
1179
|
+
errorHandler = errorHandler;
|
|
1180
|
+
/**
|
|
1181
|
+
* `.route()` allows grouping other Hono instance in routes.
|
|
1182
|
+
*
|
|
1183
|
+
* @see {@link https://hono.dev/docs/api/routing#grouping}
|
|
1184
|
+
*
|
|
1185
|
+
* @param {string} path - base Path
|
|
1186
|
+
* @param {Hono} app - other Hono instance
|
|
1187
|
+
* @returns {Hono} routed Hono instance
|
|
1188
|
+
*
|
|
1189
|
+
* @example
|
|
1190
|
+
* ```ts
|
|
1191
|
+
* const app = new Hono()
|
|
1192
|
+
* const app2 = new Hono()
|
|
1193
|
+
*
|
|
1194
|
+
* app2.get("/user", (c) => c.text("user"))
|
|
1195
|
+
* app.route("/api", app2) // GET /api/user
|
|
1196
|
+
* ```
|
|
1197
|
+
*/
|
|
1198
|
+
route(path, app2) {
|
|
1199
|
+
const subApp = this.basePath(path);
|
|
1200
|
+
app2.routes.map((r) => {
|
|
1201
|
+
let handler;
|
|
1202
|
+
if (app2.errorHandler === errorHandler) {
|
|
1203
|
+
handler = r.handler;
|
|
1204
|
+
} else {
|
|
1205
|
+
handler = /* @__PURE__ */ __name(async (c, next) => (await compose([], app2.errorHandler)(c, () => r.handler(c, next))).res, "handler");
|
|
1206
|
+
handler[COMPOSED_HANDLER] = r.handler;
|
|
1207
|
+
}
|
|
1208
|
+
subApp.#addRoute(r.method, r.path, handler);
|
|
1209
|
+
});
|
|
1210
|
+
return this;
|
|
1211
|
+
}
|
|
1212
|
+
/**
|
|
1213
|
+
* `.basePath()` allows base paths to be specified.
|
|
1214
|
+
*
|
|
1215
|
+
* @see {@link https://hono.dev/docs/api/routing#base-path}
|
|
1216
|
+
*
|
|
1217
|
+
* @param {string} path - base Path
|
|
1218
|
+
* @returns {Hono} changed Hono instance
|
|
1219
|
+
*
|
|
1220
|
+
* @example
|
|
1221
|
+
* ```ts
|
|
1222
|
+
* const api = new Hono().basePath('/api')
|
|
1223
|
+
* ```
|
|
1224
|
+
*/
|
|
1225
|
+
basePath(path) {
|
|
1226
|
+
const subApp = this.#clone();
|
|
1227
|
+
subApp._basePath = mergePath(this._basePath, path);
|
|
1228
|
+
return subApp;
|
|
1229
|
+
}
|
|
1230
|
+
/**
|
|
1231
|
+
* `.onError()` handles an error and returns a customized Response.
|
|
1232
|
+
*
|
|
1233
|
+
* @see {@link https://hono.dev/docs/api/hono#error-handling}
|
|
1234
|
+
*
|
|
1235
|
+
* @param {ErrorHandler} handler - request Handler for error
|
|
1236
|
+
* @returns {Hono} changed Hono instance
|
|
1237
|
+
*
|
|
1238
|
+
* @example
|
|
1239
|
+
* ```ts
|
|
1240
|
+
* app.onError((err, c) => {
|
|
1241
|
+
* console.error(`${err}`)
|
|
1242
|
+
* return c.text('Custom Error Message', 500)
|
|
1243
|
+
* })
|
|
1244
|
+
* ```
|
|
1245
|
+
*/
|
|
1246
|
+
onError = (handler) => {
|
|
1247
|
+
this.errorHandler = handler;
|
|
1248
|
+
return this;
|
|
1249
|
+
};
|
|
1250
|
+
/**
|
|
1251
|
+
* `.notFound()` allows you to customize a Not Found Response.
|
|
1252
|
+
*
|
|
1253
|
+
* @see {@link https://hono.dev/docs/api/hono#not-found}
|
|
1254
|
+
*
|
|
1255
|
+
* @param {NotFoundHandler} handler - request handler for not-found
|
|
1256
|
+
* @returns {Hono} changed Hono instance
|
|
1257
|
+
*
|
|
1258
|
+
* @example
|
|
1259
|
+
* ```ts
|
|
1260
|
+
* app.notFound((c) => {
|
|
1261
|
+
* return c.text('Custom 404 Message', 404)
|
|
1262
|
+
* })
|
|
1263
|
+
* ```
|
|
1264
|
+
*/
|
|
1265
|
+
notFound = (handler) => {
|
|
1266
|
+
this.#notFoundHandler = handler;
|
|
1267
|
+
return this;
|
|
1268
|
+
};
|
|
1269
|
+
/**
|
|
1270
|
+
* `.mount()` allows you to mount applications built with other frameworks into your Hono application.
|
|
1271
|
+
*
|
|
1272
|
+
* @see {@link https://hono.dev/docs/api/hono#mount}
|
|
1273
|
+
*
|
|
1274
|
+
* @param {string} path - base Path
|
|
1275
|
+
* @param {Function} applicationHandler - other Request Handler
|
|
1276
|
+
* @param {MountOptions} [options] - options of `.mount()`
|
|
1277
|
+
* @returns {Hono} mounted Hono instance
|
|
1278
|
+
*
|
|
1279
|
+
* @example
|
|
1280
|
+
* ```ts
|
|
1281
|
+
* import { Router as IttyRouter } from 'itty-router'
|
|
1282
|
+
* import { Hono } from 'hono'
|
|
1283
|
+
* // Create itty-router application
|
|
1284
|
+
* const ittyRouter = IttyRouter()
|
|
1285
|
+
* // GET /itty-router/hello
|
|
1286
|
+
* ittyRouter.get('/hello', () => new Response('Hello from itty-router'))
|
|
1287
|
+
*
|
|
1288
|
+
* const app = new Hono()
|
|
1289
|
+
* app.mount('/itty-router', ittyRouter.handle)
|
|
1290
|
+
* ```
|
|
1291
|
+
*
|
|
1292
|
+
* @example
|
|
1293
|
+
* ```ts
|
|
1294
|
+
* const app = new Hono()
|
|
1295
|
+
* // Send the request to another application without modification.
|
|
1296
|
+
* app.mount('/app', anotherApp, {
|
|
1297
|
+
* replaceRequest: (req) => req,
|
|
1298
|
+
* })
|
|
1299
|
+
* ```
|
|
1300
|
+
*/
|
|
1301
|
+
mount(path, applicationHandler, options) {
|
|
1302
|
+
let replaceRequest;
|
|
1303
|
+
let optionHandler;
|
|
1304
|
+
if (options) {
|
|
1305
|
+
if (typeof options === "function") {
|
|
1306
|
+
optionHandler = options;
|
|
1307
|
+
} else {
|
|
1308
|
+
optionHandler = options.optionHandler;
|
|
1309
|
+
if (options.replaceRequest === false) {
|
|
1310
|
+
replaceRequest = /* @__PURE__ */ __name((request) => request, "replaceRequest");
|
|
1311
|
+
} else {
|
|
1312
|
+
replaceRequest = options.replaceRequest;
|
|
1313
|
+
}
|
|
1314
|
+
}
|
|
1315
|
+
}
|
|
1316
|
+
const getOptions = optionHandler ? (c) => {
|
|
1317
|
+
const options2 = optionHandler(c);
|
|
1318
|
+
return Array.isArray(options2) ? options2 : [options2];
|
|
1319
|
+
} : (c) => {
|
|
1320
|
+
let executionContext = void 0;
|
|
1321
|
+
try {
|
|
1322
|
+
executionContext = c.executionCtx;
|
|
1323
|
+
} catch {
|
|
1324
|
+
}
|
|
1325
|
+
return [c.env, executionContext];
|
|
1326
|
+
};
|
|
1327
|
+
replaceRequest ||= (() => {
|
|
1328
|
+
const mergedPath = mergePath(this._basePath, path);
|
|
1329
|
+
const pathPrefixLength = mergedPath === "/" ? 0 : mergedPath.length;
|
|
1330
|
+
return (request) => {
|
|
1331
|
+
const url = new URL(request.url);
|
|
1332
|
+
url.pathname = url.pathname.slice(pathPrefixLength) || "/";
|
|
1333
|
+
return new Request(url, request);
|
|
1334
|
+
};
|
|
1335
|
+
})();
|
|
1336
|
+
const handler = /* @__PURE__ */ __name(async (c, next) => {
|
|
1337
|
+
const res = await applicationHandler(replaceRequest(c.req.raw), ...getOptions(c));
|
|
1338
|
+
if (res) {
|
|
1339
|
+
return res;
|
|
1340
|
+
}
|
|
1341
|
+
await next();
|
|
1342
|
+
}, "handler");
|
|
1343
|
+
this.#addRoute(METHOD_NAME_ALL, mergePath(path, "*"), handler);
|
|
1344
|
+
return this;
|
|
1345
|
+
}
|
|
1346
|
+
#addRoute(method, path, handler) {
|
|
1347
|
+
method = method.toUpperCase();
|
|
1348
|
+
path = mergePath(this._basePath, path);
|
|
1349
|
+
const r = { basePath: this._basePath, path, method, handler };
|
|
1350
|
+
this.router.add(method, path, [handler, r]);
|
|
1351
|
+
this.routes.push(r);
|
|
1352
|
+
}
|
|
1353
|
+
#handleError(err, c) {
|
|
1354
|
+
if (err instanceof Error) {
|
|
1355
|
+
return this.errorHandler(err, c);
|
|
1356
|
+
}
|
|
1357
|
+
throw err;
|
|
1358
|
+
}
|
|
1359
|
+
#dispatch(request, executionCtx, env, method) {
|
|
1360
|
+
if (method === "HEAD") {
|
|
1361
|
+
return (async () => new Response(null, await this.#dispatch(request, executionCtx, env, "GET")))();
|
|
1362
|
+
}
|
|
1363
|
+
const path = this.getPath(request, { env });
|
|
1364
|
+
const matchResult = this.router.match(method, path);
|
|
1365
|
+
const c = new Context(request, {
|
|
1366
|
+
path,
|
|
1367
|
+
matchResult,
|
|
1368
|
+
env,
|
|
1369
|
+
executionCtx,
|
|
1370
|
+
notFoundHandler: this.#notFoundHandler
|
|
1371
|
+
});
|
|
1372
|
+
if (matchResult[0].length === 1) {
|
|
1373
|
+
let res;
|
|
1374
|
+
try {
|
|
1375
|
+
res = matchResult[0][0][0][0](c, async () => {
|
|
1376
|
+
c.res = await this.#notFoundHandler(c);
|
|
1377
|
+
});
|
|
1378
|
+
} catch (err) {
|
|
1379
|
+
return this.#handleError(err, c);
|
|
1380
|
+
}
|
|
1381
|
+
return res instanceof Promise ? res.then(
|
|
1382
|
+
(resolved) => resolved || (c.finalized ? c.res : this.#notFoundHandler(c))
|
|
1383
|
+
).catch((err) => this.#handleError(err, c)) : res ?? this.#notFoundHandler(c);
|
|
1384
|
+
}
|
|
1385
|
+
const composed = compose(matchResult[0], this.errorHandler, this.#notFoundHandler);
|
|
1386
|
+
return (async () => {
|
|
1387
|
+
try {
|
|
1388
|
+
const context = await composed(c);
|
|
1389
|
+
if (!context.finalized) {
|
|
1390
|
+
throw new Error(
|
|
1391
|
+
"Context is not finalized. Did you forget to return a Response object or `await next()`?"
|
|
1392
|
+
);
|
|
1393
|
+
}
|
|
1394
|
+
return context.res;
|
|
1395
|
+
} catch (err) {
|
|
1396
|
+
return this.#handleError(err, c);
|
|
1397
|
+
}
|
|
1398
|
+
})();
|
|
1399
|
+
}
|
|
1400
|
+
/**
|
|
1401
|
+
* `.fetch()` will be entry point of your app.
|
|
1402
|
+
*
|
|
1403
|
+
* @see {@link https://hono.dev/docs/api/hono#fetch}
|
|
1404
|
+
*
|
|
1405
|
+
* @param {Request} request - request Object of request
|
|
1406
|
+
* @param {Env} Env - env Object
|
|
1407
|
+
* @param {ExecutionContext} - context of execution
|
|
1408
|
+
* @returns {Response | Promise<Response>} response of request
|
|
1409
|
+
*
|
|
1410
|
+
*/
|
|
1411
|
+
fetch = (request, ...rest) => {
|
|
1412
|
+
return this.#dispatch(request, rest[1], rest[0], request.method);
|
|
1413
|
+
};
|
|
1414
|
+
/**
|
|
1415
|
+
* `.request()` is a useful method for testing.
|
|
1416
|
+
* You can pass a URL or pathname to send a GET request.
|
|
1417
|
+
* app will return a Response object.
|
|
1418
|
+
* ```ts
|
|
1419
|
+
* test('GET /hello is ok', async () => {
|
|
1420
|
+
* const res = await app.request('/hello')
|
|
1421
|
+
* expect(res.status).toBe(200)
|
|
1422
|
+
* })
|
|
1423
|
+
* ```
|
|
1424
|
+
* @see https://hono.dev/docs/api/hono#request
|
|
1425
|
+
*/
|
|
1426
|
+
request = (input, requestInit, Env, executionCtx) => {
|
|
1427
|
+
if (input instanceof Request) {
|
|
1428
|
+
return this.fetch(requestInit ? new Request(input, requestInit) : input, Env, executionCtx);
|
|
1429
|
+
}
|
|
1430
|
+
input = input.toString();
|
|
1431
|
+
return this.fetch(
|
|
1432
|
+
new Request(
|
|
1433
|
+
/^https?:\/\//.test(input) ? input : `http://localhost${mergePath("/", input)}`,
|
|
1434
|
+
requestInit
|
|
1435
|
+
),
|
|
1436
|
+
Env,
|
|
1437
|
+
executionCtx
|
|
1438
|
+
);
|
|
1439
|
+
};
|
|
1440
|
+
/**
|
|
1441
|
+
* `.fire()` automatically adds a global fetch event listener.
|
|
1442
|
+
* This can be useful for environments that adhere to the Service Worker API, such as non-ES module Cloudflare Workers.
|
|
1443
|
+
* @deprecated
|
|
1444
|
+
* Use `fire` from `hono/service-worker` instead.
|
|
1445
|
+
* ```ts
|
|
1446
|
+
* import { Hono } from 'hono'
|
|
1447
|
+
* import { fire } from 'hono/service-worker'
|
|
1448
|
+
*
|
|
1449
|
+
* const app = new Hono()
|
|
1450
|
+
* // ...
|
|
1451
|
+
* fire(app)
|
|
1452
|
+
* ```
|
|
1453
|
+
* @see https://hono.dev/docs/api/hono#fire
|
|
1454
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API
|
|
1455
|
+
* @see https://developers.cloudflare.com/workers/reference/migrate-to-module-workers/
|
|
1456
|
+
*/
|
|
1457
|
+
fire = () => {
|
|
1458
|
+
addEventListener("fetch", (event) => {
|
|
1459
|
+
event.respondWith(this.#dispatch(event.request, event, void 0, event.request.method));
|
|
1460
|
+
});
|
|
1461
|
+
};
|
|
1462
|
+
}, "_Hono");
|
|
1463
|
+
|
|
1464
|
+
// ../../node_modules/.pnpm/hono@4.11.7/node_modules/hono/dist/router/reg-exp-router/matcher.js
|
|
1465
|
+
var emptyParam = [];
|
|
1466
|
+
function match(method, path) {
|
|
1467
|
+
const matchers = this.buildAllMatchers();
|
|
1468
|
+
const match2 = /* @__PURE__ */ __name((method2, path2) => {
|
|
1469
|
+
const matcher = matchers[method2] || matchers[METHOD_NAME_ALL];
|
|
1470
|
+
const staticMatch = matcher[2][path2];
|
|
1471
|
+
if (staticMatch) {
|
|
1472
|
+
return staticMatch;
|
|
1473
|
+
}
|
|
1474
|
+
const match3 = path2.match(matcher[0]);
|
|
1475
|
+
if (!match3) {
|
|
1476
|
+
return [[], emptyParam];
|
|
1477
|
+
}
|
|
1478
|
+
const index = match3.indexOf("", 1);
|
|
1479
|
+
return [matcher[1][index], match3];
|
|
1480
|
+
}, "match2");
|
|
1481
|
+
this.match = match2;
|
|
1482
|
+
return match2(method, path);
|
|
1483
|
+
}
|
|
1484
|
+
__name(match, "match");
|
|
1485
|
+
|
|
1486
|
+
// ../../node_modules/.pnpm/hono@4.11.7/node_modules/hono/dist/router/reg-exp-router/node.js
|
|
1487
|
+
var LABEL_REG_EXP_STR = "[^/]+";
|
|
1488
|
+
var ONLY_WILDCARD_REG_EXP_STR = ".*";
|
|
1489
|
+
var TAIL_WILDCARD_REG_EXP_STR = "(?:|/.*)";
|
|
1490
|
+
var PATH_ERROR = /* @__PURE__ */ Symbol();
|
|
1491
|
+
var regExpMetaChars = new Set(".\\+*[^]$()");
|
|
1492
|
+
function compareKey(a, b) {
|
|
1493
|
+
if (a.length === 1) {
|
|
1494
|
+
return b.length === 1 ? a < b ? -1 : 1 : -1;
|
|
1495
|
+
}
|
|
1496
|
+
if (b.length === 1) {
|
|
1497
|
+
return 1;
|
|
1498
|
+
}
|
|
1499
|
+
if (a === ONLY_WILDCARD_REG_EXP_STR || a === TAIL_WILDCARD_REG_EXP_STR) {
|
|
1500
|
+
return 1;
|
|
1501
|
+
} else if (b === ONLY_WILDCARD_REG_EXP_STR || b === TAIL_WILDCARD_REG_EXP_STR) {
|
|
1502
|
+
return -1;
|
|
1503
|
+
}
|
|
1504
|
+
if (a === LABEL_REG_EXP_STR) {
|
|
1505
|
+
return 1;
|
|
1506
|
+
} else if (b === LABEL_REG_EXP_STR) {
|
|
1507
|
+
return -1;
|
|
1508
|
+
}
|
|
1509
|
+
return a.length === b.length ? a < b ? -1 : 1 : b.length - a.length;
|
|
1510
|
+
}
|
|
1511
|
+
__name(compareKey, "compareKey");
|
|
1512
|
+
var Node = /* @__PURE__ */ __name(class _Node {
|
|
1513
|
+
#index;
|
|
1514
|
+
#varIndex;
|
|
1515
|
+
#children = /* @__PURE__ */ Object.create(null);
|
|
1516
|
+
insert(tokens, index, paramMap, context, pathErrorCheckOnly) {
|
|
1517
|
+
if (tokens.length === 0) {
|
|
1518
|
+
if (this.#index !== void 0) {
|
|
1519
|
+
throw PATH_ERROR;
|
|
1520
|
+
}
|
|
1521
|
+
if (pathErrorCheckOnly) {
|
|
1522
|
+
return;
|
|
1523
|
+
}
|
|
1524
|
+
this.#index = index;
|
|
1525
|
+
return;
|
|
1526
|
+
}
|
|
1527
|
+
const [token, ...restTokens] = tokens;
|
|
1528
|
+
const pattern = token === "*" ? restTokens.length === 0 ? ["", "", ONLY_WILDCARD_REG_EXP_STR] : ["", "", LABEL_REG_EXP_STR] : token === "/*" ? ["", "", TAIL_WILDCARD_REG_EXP_STR] : token.match(/^\:([^\{\}]+)(?:\{(.+)\})?$/);
|
|
1529
|
+
let node;
|
|
1530
|
+
if (pattern) {
|
|
1531
|
+
const name = pattern[1];
|
|
1532
|
+
let regexpStr = pattern[2] || LABEL_REG_EXP_STR;
|
|
1533
|
+
if (name && pattern[2]) {
|
|
1534
|
+
if (regexpStr === ".*") {
|
|
1535
|
+
throw PATH_ERROR;
|
|
1536
|
+
}
|
|
1537
|
+
regexpStr = regexpStr.replace(/^\((?!\?:)(?=[^)]+\)$)/, "(?:");
|
|
1538
|
+
if (/\((?!\?:)/.test(regexpStr)) {
|
|
1539
|
+
throw PATH_ERROR;
|
|
1540
|
+
}
|
|
1541
|
+
}
|
|
1542
|
+
node = this.#children[regexpStr];
|
|
1543
|
+
if (!node) {
|
|
1544
|
+
if (Object.keys(this.#children).some(
|
|
1545
|
+
(k) => k !== ONLY_WILDCARD_REG_EXP_STR && k !== TAIL_WILDCARD_REG_EXP_STR
|
|
1546
|
+
)) {
|
|
1547
|
+
throw PATH_ERROR;
|
|
1548
|
+
}
|
|
1549
|
+
if (pathErrorCheckOnly) {
|
|
1550
|
+
return;
|
|
1551
|
+
}
|
|
1552
|
+
node = this.#children[regexpStr] = new _Node();
|
|
1553
|
+
if (name !== "") {
|
|
1554
|
+
node.#varIndex = context.varIndex++;
|
|
1555
|
+
}
|
|
1556
|
+
}
|
|
1557
|
+
if (!pathErrorCheckOnly && name !== "") {
|
|
1558
|
+
paramMap.push([name, node.#varIndex]);
|
|
1559
|
+
}
|
|
1560
|
+
} else {
|
|
1561
|
+
node = this.#children[token];
|
|
1562
|
+
if (!node) {
|
|
1563
|
+
if (Object.keys(this.#children).some(
|
|
1564
|
+
(k) => k.length > 1 && k !== ONLY_WILDCARD_REG_EXP_STR && k !== TAIL_WILDCARD_REG_EXP_STR
|
|
1565
|
+
)) {
|
|
1566
|
+
throw PATH_ERROR;
|
|
1567
|
+
}
|
|
1568
|
+
if (pathErrorCheckOnly) {
|
|
1569
|
+
return;
|
|
1570
|
+
}
|
|
1571
|
+
node = this.#children[token] = new _Node();
|
|
1572
|
+
}
|
|
1573
|
+
}
|
|
1574
|
+
node.insert(restTokens, index, paramMap, context, pathErrorCheckOnly);
|
|
1575
|
+
}
|
|
1576
|
+
buildRegExpStr() {
|
|
1577
|
+
const childKeys = Object.keys(this.#children).sort(compareKey);
|
|
1578
|
+
const strList = childKeys.map((k) => {
|
|
1579
|
+
const c = this.#children[k];
|
|
1580
|
+
return (typeof c.#varIndex === "number" ? `(${k})@${c.#varIndex}` : regExpMetaChars.has(k) ? `\\${k}` : k) + c.buildRegExpStr();
|
|
1581
|
+
});
|
|
1582
|
+
if (typeof this.#index === "number") {
|
|
1583
|
+
strList.unshift(`#${this.#index}`);
|
|
1584
|
+
}
|
|
1585
|
+
if (strList.length === 0) {
|
|
1586
|
+
return "";
|
|
1587
|
+
}
|
|
1588
|
+
if (strList.length === 1) {
|
|
1589
|
+
return strList[0];
|
|
1590
|
+
}
|
|
1591
|
+
return "(?:" + strList.join("|") + ")";
|
|
1592
|
+
}
|
|
1593
|
+
}, "_Node");
|
|
1594
|
+
|
|
1595
|
+
// ../../node_modules/.pnpm/hono@4.11.7/node_modules/hono/dist/router/reg-exp-router/trie.js
|
|
1596
|
+
var Trie = /* @__PURE__ */ __name(class {
|
|
1597
|
+
#context = { varIndex: 0 };
|
|
1598
|
+
#root = new Node();
|
|
1599
|
+
insert(path, index, pathErrorCheckOnly) {
|
|
1600
|
+
const paramAssoc = [];
|
|
1601
|
+
const groups = [];
|
|
1602
|
+
for (let i = 0; ; ) {
|
|
1603
|
+
let replaced = false;
|
|
1604
|
+
path = path.replace(/\{[^}]+\}/g, (m) => {
|
|
1605
|
+
const mark = `@\\${i}`;
|
|
1606
|
+
groups[i] = [mark, m];
|
|
1607
|
+
i++;
|
|
1608
|
+
replaced = true;
|
|
1609
|
+
return mark;
|
|
1610
|
+
});
|
|
1611
|
+
if (!replaced) {
|
|
1612
|
+
break;
|
|
1613
|
+
}
|
|
1614
|
+
}
|
|
1615
|
+
const tokens = path.match(/(?::[^\/]+)|(?:\/\*$)|./g) || [];
|
|
1616
|
+
for (let i = groups.length - 1; i >= 0; i--) {
|
|
1617
|
+
const [mark] = groups[i];
|
|
1618
|
+
for (let j = tokens.length - 1; j >= 0; j--) {
|
|
1619
|
+
if (tokens[j].indexOf(mark) !== -1) {
|
|
1620
|
+
tokens[j] = tokens[j].replace(mark, groups[i][1]);
|
|
1621
|
+
break;
|
|
1622
|
+
}
|
|
1623
|
+
}
|
|
1624
|
+
}
|
|
1625
|
+
this.#root.insert(tokens, index, paramAssoc, this.#context, pathErrorCheckOnly);
|
|
1626
|
+
return paramAssoc;
|
|
1627
|
+
}
|
|
1628
|
+
buildRegExp() {
|
|
1629
|
+
let regexp = this.#root.buildRegExpStr();
|
|
1630
|
+
if (regexp === "") {
|
|
1631
|
+
return [/^$/, [], []];
|
|
1632
|
+
}
|
|
1633
|
+
let captureIndex = 0;
|
|
1634
|
+
const indexReplacementMap = [];
|
|
1635
|
+
const paramReplacementMap = [];
|
|
1636
|
+
regexp = regexp.replace(/#(\d+)|@(\d+)|\.\*\$/g, (_, handlerIndex, paramIndex) => {
|
|
1637
|
+
if (handlerIndex !== void 0) {
|
|
1638
|
+
indexReplacementMap[++captureIndex] = Number(handlerIndex);
|
|
1639
|
+
return "$()";
|
|
1640
|
+
}
|
|
1641
|
+
if (paramIndex !== void 0) {
|
|
1642
|
+
paramReplacementMap[Number(paramIndex)] = ++captureIndex;
|
|
1643
|
+
return "";
|
|
1644
|
+
}
|
|
1645
|
+
return "";
|
|
1646
|
+
});
|
|
1647
|
+
return [new RegExp(`^${regexp}`), indexReplacementMap, paramReplacementMap];
|
|
1648
|
+
}
|
|
1649
|
+
}, "Trie");
|
|
1650
|
+
|
|
1651
|
+
// ../../node_modules/.pnpm/hono@4.11.7/node_modules/hono/dist/router/reg-exp-router/router.js
|
|
1652
|
+
var nullMatcher = [/^$/, [], /* @__PURE__ */ Object.create(null)];
|
|
1653
|
+
var wildcardRegExpCache = /* @__PURE__ */ Object.create(null);
|
|
1654
|
+
function buildWildcardRegExp(path) {
|
|
1655
|
+
return wildcardRegExpCache[path] ??= new RegExp(
|
|
1656
|
+
path === "*" ? "" : `^${path.replace(
|
|
1657
|
+
/\/\*$|([.\\+*[^\]$()])/g,
|
|
1658
|
+
(_, metaChar) => metaChar ? `\\${metaChar}` : "(?:|/.*)"
|
|
1659
|
+
)}$`
|
|
1660
|
+
);
|
|
1661
|
+
}
|
|
1662
|
+
__name(buildWildcardRegExp, "buildWildcardRegExp");
|
|
1663
|
+
function clearWildcardRegExpCache() {
|
|
1664
|
+
wildcardRegExpCache = /* @__PURE__ */ Object.create(null);
|
|
1665
|
+
}
|
|
1666
|
+
__name(clearWildcardRegExpCache, "clearWildcardRegExpCache");
|
|
1667
|
+
function buildMatcherFromPreprocessedRoutes(routes) {
|
|
1668
|
+
const trie = new Trie();
|
|
1669
|
+
const handlerData = [];
|
|
1670
|
+
if (routes.length === 0) {
|
|
1671
|
+
return nullMatcher;
|
|
1672
|
+
}
|
|
1673
|
+
const routesWithStaticPathFlag = routes.map(
|
|
1674
|
+
(route) => [!/\*|\/:/.test(route[0]), ...route]
|
|
1675
|
+
).sort(
|
|
1676
|
+
([isStaticA, pathA], [isStaticB, pathB]) => isStaticA ? 1 : isStaticB ? -1 : pathA.length - pathB.length
|
|
1677
|
+
);
|
|
1678
|
+
const staticMap = /* @__PURE__ */ Object.create(null);
|
|
1679
|
+
for (let i = 0, j = -1, len = routesWithStaticPathFlag.length; i < len; i++) {
|
|
1680
|
+
const [pathErrorCheckOnly, path, handlers] = routesWithStaticPathFlag[i];
|
|
1681
|
+
if (pathErrorCheckOnly) {
|
|
1682
|
+
staticMap[path] = [handlers.map(([h]) => [h, /* @__PURE__ */ Object.create(null)]), emptyParam];
|
|
1683
|
+
} else {
|
|
1684
|
+
j++;
|
|
1685
|
+
}
|
|
1686
|
+
let paramAssoc;
|
|
1687
|
+
try {
|
|
1688
|
+
paramAssoc = trie.insert(path, j, pathErrorCheckOnly);
|
|
1689
|
+
} catch (e) {
|
|
1690
|
+
throw e === PATH_ERROR ? new UnsupportedPathError(path) : e;
|
|
1691
|
+
}
|
|
1692
|
+
if (pathErrorCheckOnly) {
|
|
1693
|
+
continue;
|
|
1694
|
+
}
|
|
1695
|
+
handlerData[j] = handlers.map(([h, paramCount]) => {
|
|
1696
|
+
const paramIndexMap = /* @__PURE__ */ Object.create(null);
|
|
1697
|
+
paramCount -= 1;
|
|
1698
|
+
for (; paramCount >= 0; paramCount--) {
|
|
1699
|
+
const [key, value] = paramAssoc[paramCount];
|
|
1700
|
+
paramIndexMap[key] = value;
|
|
1701
|
+
}
|
|
1702
|
+
return [h, paramIndexMap];
|
|
1703
|
+
});
|
|
1704
|
+
}
|
|
1705
|
+
const [regexp, indexReplacementMap, paramReplacementMap] = trie.buildRegExp();
|
|
1706
|
+
for (let i = 0, len = handlerData.length; i < len; i++) {
|
|
1707
|
+
for (let j = 0, len2 = handlerData[i].length; j < len2; j++) {
|
|
1708
|
+
const map = handlerData[i][j]?.[1];
|
|
1709
|
+
if (!map) {
|
|
1710
|
+
continue;
|
|
1711
|
+
}
|
|
1712
|
+
const keys = Object.keys(map);
|
|
1713
|
+
for (let k = 0, len3 = keys.length; k < len3; k++) {
|
|
1714
|
+
map[keys[k]] = paramReplacementMap[map[keys[k]]];
|
|
1715
|
+
}
|
|
1716
|
+
}
|
|
1717
|
+
}
|
|
1718
|
+
const handlerMap = [];
|
|
1719
|
+
for (const i in indexReplacementMap) {
|
|
1720
|
+
handlerMap[i] = handlerData[indexReplacementMap[i]];
|
|
1721
|
+
}
|
|
1722
|
+
return [regexp, handlerMap, staticMap];
|
|
1723
|
+
}
|
|
1724
|
+
__name(buildMatcherFromPreprocessedRoutes, "buildMatcherFromPreprocessedRoutes");
|
|
1725
|
+
function findMiddleware(middleware, path) {
|
|
1726
|
+
if (!middleware) {
|
|
1727
|
+
return void 0;
|
|
1728
|
+
}
|
|
1729
|
+
for (const k of Object.keys(middleware).sort((a, b) => b.length - a.length)) {
|
|
1730
|
+
if (buildWildcardRegExp(k).test(path)) {
|
|
1731
|
+
return [...middleware[k]];
|
|
1732
|
+
}
|
|
1733
|
+
}
|
|
1734
|
+
return void 0;
|
|
1735
|
+
}
|
|
1736
|
+
__name(findMiddleware, "findMiddleware");
|
|
1737
|
+
var RegExpRouter = /* @__PURE__ */ __name(class {
|
|
1738
|
+
name = "RegExpRouter";
|
|
1739
|
+
#middleware;
|
|
1740
|
+
#routes;
|
|
1741
|
+
constructor() {
|
|
1742
|
+
this.#middleware = { [METHOD_NAME_ALL]: /* @__PURE__ */ Object.create(null) };
|
|
1743
|
+
this.#routes = { [METHOD_NAME_ALL]: /* @__PURE__ */ Object.create(null) };
|
|
1744
|
+
}
|
|
1745
|
+
add(method, path, handler) {
|
|
1746
|
+
const middleware = this.#middleware;
|
|
1747
|
+
const routes = this.#routes;
|
|
1748
|
+
if (!middleware || !routes) {
|
|
1749
|
+
throw new Error(MESSAGE_MATCHER_IS_ALREADY_BUILT);
|
|
1750
|
+
}
|
|
1751
|
+
if (!middleware[method]) {
|
|
1752
|
+
;
|
|
1753
|
+
[middleware, routes].forEach((handlerMap) => {
|
|
1754
|
+
handlerMap[method] = /* @__PURE__ */ Object.create(null);
|
|
1755
|
+
Object.keys(handlerMap[METHOD_NAME_ALL]).forEach((p) => {
|
|
1756
|
+
handlerMap[method][p] = [...handlerMap[METHOD_NAME_ALL][p]];
|
|
1757
|
+
});
|
|
1758
|
+
});
|
|
1759
|
+
}
|
|
1760
|
+
if (path === "/*") {
|
|
1761
|
+
path = "*";
|
|
1762
|
+
}
|
|
1763
|
+
const paramCount = (path.match(/\/:/g) || []).length;
|
|
1764
|
+
if (/\*$/.test(path)) {
|
|
1765
|
+
const re = buildWildcardRegExp(path);
|
|
1766
|
+
if (method === METHOD_NAME_ALL) {
|
|
1767
|
+
Object.keys(middleware).forEach((m) => {
|
|
1768
|
+
middleware[m][path] ||= findMiddleware(middleware[m], path) || findMiddleware(middleware[METHOD_NAME_ALL], path) || [];
|
|
1769
|
+
});
|
|
1770
|
+
} else {
|
|
1771
|
+
middleware[method][path] ||= findMiddleware(middleware[method], path) || findMiddleware(middleware[METHOD_NAME_ALL], path) || [];
|
|
1772
|
+
}
|
|
1773
|
+
Object.keys(middleware).forEach((m) => {
|
|
1774
|
+
if (method === METHOD_NAME_ALL || method === m) {
|
|
1775
|
+
Object.keys(middleware[m]).forEach((p) => {
|
|
1776
|
+
re.test(p) && middleware[m][p].push([handler, paramCount]);
|
|
1777
|
+
});
|
|
1778
|
+
}
|
|
1779
|
+
});
|
|
1780
|
+
Object.keys(routes).forEach((m) => {
|
|
1781
|
+
if (method === METHOD_NAME_ALL || method === m) {
|
|
1782
|
+
Object.keys(routes[m]).forEach(
|
|
1783
|
+
(p) => re.test(p) && routes[m][p].push([handler, paramCount])
|
|
1784
|
+
);
|
|
1785
|
+
}
|
|
1786
|
+
});
|
|
1787
|
+
return;
|
|
1788
|
+
}
|
|
1789
|
+
const paths = checkOptionalParameter(path) || [path];
|
|
1790
|
+
for (let i = 0, len = paths.length; i < len; i++) {
|
|
1791
|
+
const path2 = paths[i];
|
|
1792
|
+
Object.keys(routes).forEach((m) => {
|
|
1793
|
+
if (method === METHOD_NAME_ALL || method === m) {
|
|
1794
|
+
routes[m][path2] ||= [
|
|
1795
|
+
...findMiddleware(middleware[m], path2) || findMiddleware(middleware[METHOD_NAME_ALL], path2) || []
|
|
1796
|
+
];
|
|
1797
|
+
routes[m][path2].push([handler, paramCount - len + i + 1]);
|
|
1798
|
+
}
|
|
1799
|
+
});
|
|
1800
|
+
}
|
|
1801
|
+
}
|
|
1802
|
+
match = match;
|
|
1803
|
+
buildAllMatchers() {
|
|
1804
|
+
const matchers = /* @__PURE__ */ Object.create(null);
|
|
1805
|
+
Object.keys(this.#routes).concat(Object.keys(this.#middleware)).forEach((method) => {
|
|
1806
|
+
matchers[method] ||= this.#buildMatcher(method);
|
|
1807
|
+
});
|
|
1808
|
+
this.#middleware = this.#routes = void 0;
|
|
1809
|
+
clearWildcardRegExpCache();
|
|
1810
|
+
return matchers;
|
|
1811
|
+
}
|
|
1812
|
+
#buildMatcher(method) {
|
|
1813
|
+
const routes = [];
|
|
1814
|
+
let hasOwnRoute = method === METHOD_NAME_ALL;
|
|
1815
|
+
[this.#middleware, this.#routes].forEach((r) => {
|
|
1816
|
+
const ownRoute = r[method] ? Object.keys(r[method]).map((path) => [path, r[method][path]]) : [];
|
|
1817
|
+
if (ownRoute.length !== 0) {
|
|
1818
|
+
hasOwnRoute ||= true;
|
|
1819
|
+
routes.push(...ownRoute);
|
|
1820
|
+
} else if (method !== METHOD_NAME_ALL) {
|
|
1821
|
+
routes.push(
|
|
1822
|
+
...Object.keys(r[METHOD_NAME_ALL]).map((path) => [path, r[METHOD_NAME_ALL][path]])
|
|
1823
|
+
);
|
|
1824
|
+
}
|
|
1825
|
+
});
|
|
1826
|
+
if (!hasOwnRoute) {
|
|
1827
|
+
return null;
|
|
1828
|
+
} else {
|
|
1829
|
+
return buildMatcherFromPreprocessedRoutes(routes);
|
|
1830
|
+
}
|
|
1831
|
+
}
|
|
1832
|
+
}, "RegExpRouter");
|
|
1833
|
+
|
|
1834
|
+
// ../../node_modules/.pnpm/hono@4.11.7/node_modules/hono/dist/router/smart-router/router.js
|
|
1835
|
+
var SmartRouter = /* @__PURE__ */ __name(class {
|
|
1836
|
+
name = "SmartRouter";
|
|
1837
|
+
#routers = [];
|
|
1838
|
+
#routes = [];
|
|
1839
|
+
constructor(init) {
|
|
1840
|
+
this.#routers = init.routers;
|
|
1841
|
+
}
|
|
1842
|
+
add(method, path, handler) {
|
|
1843
|
+
if (!this.#routes) {
|
|
1844
|
+
throw new Error(MESSAGE_MATCHER_IS_ALREADY_BUILT);
|
|
1845
|
+
}
|
|
1846
|
+
this.#routes.push([method, path, handler]);
|
|
1847
|
+
}
|
|
1848
|
+
match(method, path) {
|
|
1849
|
+
if (!this.#routes) {
|
|
1850
|
+
throw new Error("Fatal error");
|
|
1851
|
+
}
|
|
1852
|
+
const routers = this.#routers;
|
|
1853
|
+
const routes = this.#routes;
|
|
1854
|
+
const len = routers.length;
|
|
1855
|
+
let i = 0;
|
|
1856
|
+
let res;
|
|
1857
|
+
for (; i < len; i++) {
|
|
1858
|
+
const router = routers[i];
|
|
1859
|
+
try {
|
|
1860
|
+
for (let i2 = 0, len2 = routes.length; i2 < len2; i2++) {
|
|
1861
|
+
router.add(...routes[i2]);
|
|
1862
|
+
}
|
|
1863
|
+
res = router.match(method, path);
|
|
1864
|
+
} catch (e) {
|
|
1865
|
+
if (e instanceof UnsupportedPathError) {
|
|
1866
|
+
continue;
|
|
1867
|
+
}
|
|
1868
|
+
throw e;
|
|
1869
|
+
}
|
|
1870
|
+
this.match = router.match.bind(router);
|
|
1871
|
+
this.#routers = [router];
|
|
1872
|
+
this.#routes = void 0;
|
|
1873
|
+
break;
|
|
1874
|
+
}
|
|
1875
|
+
if (i === len) {
|
|
1876
|
+
throw new Error("Fatal error");
|
|
1877
|
+
}
|
|
1878
|
+
this.name = `SmartRouter + ${this.activeRouter.name}`;
|
|
1879
|
+
return res;
|
|
1880
|
+
}
|
|
1881
|
+
get activeRouter() {
|
|
1882
|
+
if (this.#routes || this.#routers.length !== 1) {
|
|
1883
|
+
throw new Error("No active router has been determined yet.");
|
|
1884
|
+
}
|
|
1885
|
+
return this.#routers[0];
|
|
1886
|
+
}
|
|
1887
|
+
}, "SmartRouter");
|
|
1888
|
+
|
|
1889
|
+
// ../../node_modules/.pnpm/hono@4.11.7/node_modules/hono/dist/router/trie-router/node.js
|
|
1890
|
+
var emptyParams = /* @__PURE__ */ Object.create(null);
|
|
1891
|
+
var Node2 = /* @__PURE__ */ __name(class _Node2 {
|
|
1892
|
+
#methods;
|
|
1893
|
+
#children;
|
|
1894
|
+
#patterns;
|
|
1895
|
+
#order = 0;
|
|
1896
|
+
#params = emptyParams;
|
|
1897
|
+
constructor(method, handler, children) {
|
|
1898
|
+
this.#children = children || /* @__PURE__ */ Object.create(null);
|
|
1899
|
+
this.#methods = [];
|
|
1900
|
+
if (method && handler) {
|
|
1901
|
+
const m = /* @__PURE__ */ Object.create(null);
|
|
1902
|
+
m[method] = { handler, possibleKeys: [], score: 0 };
|
|
1903
|
+
this.#methods = [m];
|
|
1904
|
+
}
|
|
1905
|
+
this.#patterns = [];
|
|
1906
|
+
}
|
|
1907
|
+
insert(method, path, handler) {
|
|
1908
|
+
this.#order = ++this.#order;
|
|
1909
|
+
let curNode = this;
|
|
1910
|
+
const parts = splitRoutingPath(path);
|
|
1911
|
+
const possibleKeys = [];
|
|
1912
|
+
for (let i = 0, len = parts.length; i < len; i++) {
|
|
1913
|
+
const p = parts[i];
|
|
1914
|
+
const nextP = parts[i + 1];
|
|
1915
|
+
const pattern = getPattern(p, nextP);
|
|
1916
|
+
const key = Array.isArray(pattern) ? pattern[0] : p;
|
|
1917
|
+
if (key in curNode.#children) {
|
|
1918
|
+
curNode = curNode.#children[key];
|
|
1919
|
+
if (pattern) {
|
|
1920
|
+
possibleKeys.push(pattern[1]);
|
|
1921
|
+
}
|
|
1922
|
+
continue;
|
|
1923
|
+
}
|
|
1924
|
+
curNode.#children[key] = new _Node2();
|
|
1925
|
+
if (pattern) {
|
|
1926
|
+
curNode.#patterns.push(pattern);
|
|
1927
|
+
possibleKeys.push(pattern[1]);
|
|
1928
|
+
}
|
|
1929
|
+
curNode = curNode.#children[key];
|
|
1930
|
+
}
|
|
1931
|
+
curNode.#methods.push({
|
|
1932
|
+
[method]: {
|
|
1933
|
+
handler,
|
|
1934
|
+
possibleKeys: possibleKeys.filter((v, i, a) => a.indexOf(v) === i),
|
|
1935
|
+
score: this.#order
|
|
1936
|
+
}
|
|
1937
|
+
});
|
|
1938
|
+
return curNode;
|
|
1939
|
+
}
|
|
1940
|
+
#getHandlerSets(node, method, nodeParams, params) {
|
|
1941
|
+
const handlerSets = [];
|
|
1942
|
+
for (let i = 0, len = node.#methods.length; i < len; i++) {
|
|
1943
|
+
const m = node.#methods[i];
|
|
1944
|
+
const handlerSet = m[method] || m[METHOD_NAME_ALL];
|
|
1945
|
+
const processedSet = {};
|
|
1946
|
+
if (handlerSet !== void 0) {
|
|
1947
|
+
handlerSet.params = /* @__PURE__ */ Object.create(null);
|
|
1948
|
+
handlerSets.push(handlerSet);
|
|
1949
|
+
if (nodeParams !== emptyParams || params && params !== emptyParams) {
|
|
1950
|
+
for (let i2 = 0, len2 = handlerSet.possibleKeys.length; i2 < len2; i2++) {
|
|
1951
|
+
const key = handlerSet.possibleKeys[i2];
|
|
1952
|
+
const processed = processedSet[handlerSet.score];
|
|
1953
|
+
handlerSet.params[key] = params?.[key] && !processed ? params[key] : nodeParams[key] ?? params?.[key];
|
|
1954
|
+
processedSet[handlerSet.score] = true;
|
|
1955
|
+
}
|
|
1956
|
+
}
|
|
1957
|
+
}
|
|
1958
|
+
}
|
|
1959
|
+
return handlerSets;
|
|
1960
|
+
}
|
|
1961
|
+
search(method, path) {
|
|
1962
|
+
const handlerSets = [];
|
|
1963
|
+
this.#params = emptyParams;
|
|
1964
|
+
const curNode = this;
|
|
1965
|
+
let curNodes = [curNode];
|
|
1966
|
+
const parts = splitPath(path);
|
|
1967
|
+
const curNodesQueue = [];
|
|
1968
|
+
for (let i = 0, len = parts.length; i < len; i++) {
|
|
1969
|
+
const part = parts[i];
|
|
1970
|
+
const isLast = i === len - 1;
|
|
1971
|
+
const tempNodes = [];
|
|
1972
|
+
for (let j = 0, len2 = curNodes.length; j < len2; j++) {
|
|
1973
|
+
const node = curNodes[j];
|
|
1974
|
+
const nextNode = node.#children[part];
|
|
1975
|
+
if (nextNode) {
|
|
1976
|
+
nextNode.#params = node.#params;
|
|
1977
|
+
if (isLast) {
|
|
1978
|
+
if (nextNode.#children["*"]) {
|
|
1979
|
+
handlerSets.push(
|
|
1980
|
+
...this.#getHandlerSets(nextNode.#children["*"], method, node.#params)
|
|
1981
|
+
);
|
|
1982
|
+
}
|
|
1983
|
+
handlerSets.push(...this.#getHandlerSets(nextNode, method, node.#params));
|
|
1984
|
+
} else {
|
|
1985
|
+
tempNodes.push(nextNode);
|
|
1986
|
+
}
|
|
1987
|
+
}
|
|
1988
|
+
for (let k = 0, len3 = node.#patterns.length; k < len3; k++) {
|
|
1989
|
+
const pattern = node.#patterns[k];
|
|
1990
|
+
const params = node.#params === emptyParams ? {} : { ...node.#params };
|
|
1991
|
+
if (pattern === "*") {
|
|
1992
|
+
const astNode = node.#children["*"];
|
|
1993
|
+
if (astNode) {
|
|
1994
|
+
handlerSets.push(...this.#getHandlerSets(astNode, method, node.#params));
|
|
1995
|
+
astNode.#params = params;
|
|
1996
|
+
tempNodes.push(astNode);
|
|
1997
|
+
}
|
|
1998
|
+
continue;
|
|
1999
|
+
}
|
|
2000
|
+
const [key, name, matcher] = pattern;
|
|
2001
|
+
if (!part && !(matcher instanceof RegExp)) {
|
|
2002
|
+
continue;
|
|
2003
|
+
}
|
|
2004
|
+
const child = node.#children[key];
|
|
2005
|
+
const restPathString = parts.slice(i).join("/");
|
|
2006
|
+
if (matcher instanceof RegExp) {
|
|
2007
|
+
const m = matcher.exec(restPathString);
|
|
2008
|
+
if (m) {
|
|
2009
|
+
params[name] = m[0];
|
|
2010
|
+
handlerSets.push(...this.#getHandlerSets(child, method, node.#params, params));
|
|
2011
|
+
if (Object.keys(child.#children).length) {
|
|
2012
|
+
child.#params = params;
|
|
2013
|
+
const componentCount = m[0].match(/\//)?.length ?? 0;
|
|
2014
|
+
const targetCurNodes = curNodesQueue[componentCount] ||= [];
|
|
2015
|
+
targetCurNodes.push(child);
|
|
2016
|
+
}
|
|
2017
|
+
continue;
|
|
2018
|
+
}
|
|
2019
|
+
}
|
|
2020
|
+
if (matcher === true || matcher.test(part)) {
|
|
2021
|
+
params[name] = part;
|
|
2022
|
+
if (isLast) {
|
|
2023
|
+
handlerSets.push(...this.#getHandlerSets(child, method, params, node.#params));
|
|
2024
|
+
if (child.#children["*"]) {
|
|
2025
|
+
handlerSets.push(
|
|
2026
|
+
...this.#getHandlerSets(child.#children["*"], method, params, node.#params)
|
|
2027
|
+
);
|
|
2028
|
+
}
|
|
2029
|
+
} else {
|
|
2030
|
+
child.#params = params;
|
|
2031
|
+
tempNodes.push(child);
|
|
2032
|
+
}
|
|
2033
|
+
}
|
|
2034
|
+
}
|
|
2035
|
+
}
|
|
2036
|
+
curNodes = tempNodes.concat(curNodesQueue.shift() ?? []);
|
|
2037
|
+
}
|
|
2038
|
+
if (handlerSets.length > 1) {
|
|
2039
|
+
handlerSets.sort((a, b) => {
|
|
2040
|
+
return a.score - b.score;
|
|
2041
|
+
});
|
|
2042
|
+
}
|
|
2043
|
+
return [handlerSets.map(({ handler, params }) => [handler, params])];
|
|
2044
|
+
}
|
|
2045
|
+
}, "_Node");
|
|
2046
|
+
|
|
2047
|
+
// ../../node_modules/.pnpm/hono@4.11.7/node_modules/hono/dist/router/trie-router/router.js
|
|
2048
|
+
var TrieRouter = /* @__PURE__ */ __name(class {
|
|
2049
|
+
name = "TrieRouter";
|
|
2050
|
+
#node;
|
|
2051
|
+
constructor() {
|
|
2052
|
+
this.#node = new Node2();
|
|
2053
|
+
}
|
|
2054
|
+
add(method, path, handler) {
|
|
2055
|
+
const results = checkOptionalParameter(path);
|
|
2056
|
+
if (results) {
|
|
2057
|
+
for (let i = 0, len = results.length; i < len; i++) {
|
|
2058
|
+
this.#node.insert(method, results[i], handler);
|
|
2059
|
+
}
|
|
2060
|
+
return;
|
|
2061
|
+
}
|
|
2062
|
+
this.#node.insert(method, path, handler);
|
|
2063
|
+
}
|
|
2064
|
+
match(method, path) {
|
|
2065
|
+
return this.#node.search(method, path);
|
|
2066
|
+
}
|
|
2067
|
+
}, "TrieRouter");
|
|
2068
|
+
|
|
2069
|
+
// ../../node_modules/.pnpm/hono@4.11.7/node_modules/hono/dist/hono.js
|
|
2070
|
+
var Hono2 = /* @__PURE__ */ __name(class extends Hono {
|
|
2071
|
+
/**
|
|
2072
|
+
* Creates an instance of the Hono class.
|
|
2073
|
+
*
|
|
2074
|
+
* @param options - Optional configuration options for the Hono instance.
|
|
2075
|
+
*/
|
|
2076
|
+
constructor(options = {}) {
|
|
2077
|
+
super(options);
|
|
2078
|
+
this.router = options.router ?? new SmartRouter({
|
|
2079
|
+
routers: [new RegExpRouter(), new TrieRouter()]
|
|
2080
|
+
});
|
|
2081
|
+
}
|
|
2082
|
+
}, "Hono");
|
|
2083
|
+
|
|
2084
|
+
// ../../node_modules/.pnpm/hono@4.11.7/node_modules/hono/dist/middleware/cors/index.js
|
|
2085
|
+
var cors = /* @__PURE__ */ __name((options) => {
|
|
2086
|
+
const defaults = {
|
|
2087
|
+
origin: "*",
|
|
2088
|
+
allowMethods: ["GET", "HEAD", "PUT", "POST", "DELETE", "PATCH"],
|
|
2089
|
+
allowHeaders: [],
|
|
2090
|
+
exposeHeaders: []
|
|
2091
|
+
};
|
|
2092
|
+
const opts = {
|
|
2093
|
+
...defaults,
|
|
2094
|
+
...options
|
|
2095
|
+
};
|
|
2096
|
+
const findAllowOrigin = ((optsOrigin) => {
|
|
2097
|
+
if (typeof optsOrigin === "string") {
|
|
2098
|
+
if (optsOrigin === "*") {
|
|
2099
|
+
return () => optsOrigin;
|
|
2100
|
+
} else {
|
|
2101
|
+
return (origin) => optsOrigin === origin ? origin : null;
|
|
2102
|
+
}
|
|
2103
|
+
} else if (typeof optsOrigin === "function") {
|
|
2104
|
+
return optsOrigin;
|
|
2105
|
+
} else {
|
|
2106
|
+
return (origin) => optsOrigin.includes(origin) ? origin : null;
|
|
2107
|
+
}
|
|
2108
|
+
})(opts.origin);
|
|
2109
|
+
const findAllowMethods = ((optsAllowMethods) => {
|
|
2110
|
+
if (typeof optsAllowMethods === "function") {
|
|
2111
|
+
return optsAllowMethods;
|
|
2112
|
+
} else if (Array.isArray(optsAllowMethods)) {
|
|
2113
|
+
return () => optsAllowMethods;
|
|
2114
|
+
} else {
|
|
2115
|
+
return () => [];
|
|
2116
|
+
}
|
|
2117
|
+
})(opts.allowMethods);
|
|
2118
|
+
return /* @__PURE__ */ __name(async function cors2(c, next) {
|
|
2119
|
+
function set(key, value) {
|
|
2120
|
+
c.res.headers.set(key, value);
|
|
2121
|
+
}
|
|
2122
|
+
__name(set, "set");
|
|
2123
|
+
const allowOrigin = await findAllowOrigin(c.req.header("origin") || "", c);
|
|
2124
|
+
if (allowOrigin) {
|
|
2125
|
+
set("Access-Control-Allow-Origin", allowOrigin);
|
|
2126
|
+
}
|
|
2127
|
+
if (opts.credentials) {
|
|
2128
|
+
set("Access-Control-Allow-Credentials", "true");
|
|
2129
|
+
}
|
|
2130
|
+
if (opts.exposeHeaders?.length) {
|
|
2131
|
+
set("Access-Control-Expose-Headers", opts.exposeHeaders.join(","));
|
|
2132
|
+
}
|
|
2133
|
+
if (c.req.method === "OPTIONS") {
|
|
2134
|
+
if (opts.origin !== "*") {
|
|
2135
|
+
set("Vary", "Origin");
|
|
2136
|
+
}
|
|
2137
|
+
if (opts.maxAge != null) {
|
|
2138
|
+
set("Access-Control-Max-Age", opts.maxAge.toString());
|
|
2139
|
+
}
|
|
2140
|
+
const allowMethods = await findAllowMethods(c.req.header("origin") || "", c);
|
|
2141
|
+
if (allowMethods.length) {
|
|
2142
|
+
set("Access-Control-Allow-Methods", allowMethods.join(","));
|
|
2143
|
+
}
|
|
2144
|
+
let headers = opts.allowHeaders;
|
|
2145
|
+
if (!headers?.length) {
|
|
2146
|
+
const requestHeaders = c.req.header("Access-Control-Request-Headers");
|
|
2147
|
+
if (requestHeaders) {
|
|
2148
|
+
headers = requestHeaders.split(/\s*,\s*/);
|
|
2149
|
+
}
|
|
2150
|
+
}
|
|
2151
|
+
if (headers?.length) {
|
|
2152
|
+
set("Access-Control-Allow-Headers", headers.join(","));
|
|
2153
|
+
c.res.headers.append("Vary", "Access-Control-Request-Headers");
|
|
2154
|
+
}
|
|
2155
|
+
c.res.headers.delete("Content-Length");
|
|
2156
|
+
c.res.headers.delete("Content-Type");
|
|
2157
|
+
return new Response(null, {
|
|
2158
|
+
headers: c.res.headers,
|
|
2159
|
+
status: 204,
|
|
2160
|
+
statusText: "No Content"
|
|
2161
|
+
});
|
|
2162
|
+
}
|
|
2163
|
+
await next();
|
|
2164
|
+
if (opts.origin !== "*") {
|
|
2165
|
+
c.header("Vary", "Origin", { append: true });
|
|
2166
|
+
}
|
|
2167
|
+
}, "cors2");
|
|
2168
|
+
}, "cors");
|
|
2169
|
+
|
|
2170
|
+
// ../../node_modules/.pnpm/hono@4.11.7/node_modules/hono/dist/utils/color.js
|
|
2171
|
+
function getColorEnabled() {
|
|
2172
|
+
const { process, Deno } = globalThis;
|
|
2173
|
+
const isNoColor = typeof Deno?.noColor === "boolean" ? Deno.noColor : process !== void 0 ? (
|
|
2174
|
+
// eslint-disable-next-line no-unsafe-optional-chaining
|
|
2175
|
+
"NO_COLOR" in process?.env
|
|
2176
|
+
) : false;
|
|
2177
|
+
return !isNoColor;
|
|
2178
|
+
}
|
|
2179
|
+
__name(getColorEnabled, "getColorEnabled");
|
|
2180
|
+
async function getColorEnabledAsync() {
|
|
2181
|
+
const { navigator } = globalThis;
|
|
2182
|
+
const cfWorkers = "cloudflare:workers";
|
|
2183
|
+
const isNoColor = navigator !== void 0 && navigator.userAgent === "Cloudflare-Workers" ? await (async () => {
|
|
2184
|
+
try {
|
|
2185
|
+
return "NO_COLOR" in ((await import(cfWorkers)).env ?? {});
|
|
2186
|
+
} catch {
|
|
2187
|
+
return false;
|
|
2188
|
+
}
|
|
2189
|
+
})() : !getColorEnabled();
|
|
2190
|
+
return !isNoColor;
|
|
2191
|
+
}
|
|
2192
|
+
__name(getColorEnabledAsync, "getColorEnabledAsync");
|
|
2193
|
+
|
|
2194
|
+
// ../../node_modules/.pnpm/hono@4.11.7/node_modules/hono/dist/middleware/logger/index.js
|
|
2195
|
+
var humanize = /* @__PURE__ */ __name((times) => {
|
|
2196
|
+
const [delimiter, separator] = [",", "."];
|
|
2197
|
+
const orderTimes = times.map((v) => v.replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1" + delimiter));
|
|
2198
|
+
return orderTimes.join(separator);
|
|
2199
|
+
}, "humanize");
|
|
2200
|
+
var time = /* @__PURE__ */ __name((start) => {
|
|
2201
|
+
const delta = Date.now() - start;
|
|
2202
|
+
return humanize([delta < 1e3 ? delta + "ms" : Math.round(delta / 1e3) + "s"]);
|
|
2203
|
+
}, "time");
|
|
2204
|
+
var colorStatus = /* @__PURE__ */ __name(async (status) => {
|
|
2205
|
+
const colorEnabled = await getColorEnabledAsync();
|
|
2206
|
+
if (colorEnabled) {
|
|
2207
|
+
switch (status / 100 | 0) {
|
|
2208
|
+
case 5:
|
|
2209
|
+
return `\x1B[31m${status}\x1B[0m`;
|
|
2210
|
+
case 4:
|
|
2211
|
+
return `\x1B[33m${status}\x1B[0m`;
|
|
2212
|
+
case 3:
|
|
2213
|
+
return `\x1B[36m${status}\x1B[0m`;
|
|
2214
|
+
case 2:
|
|
2215
|
+
return `\x1B[32m${status}\x1B[0m`;
|
|
2216
|
+
}
|
|
2217
|
+
}
|
|
2218
|
+
return `${status}`;
|
|
2219
|
+
}, "colorStatus");
|
|
2220
|
+
async function log(fn, prefix, method, path, status = 0, elapsed) {
|
|
2221
|
+
const out = prefix === "<--" ? `${prefix} ${method} ${path}` : `${prefix} ${method} ${path} ${await colorStatus(status)} ${elapsed}`;
|
|
2222
|
+
fn(out);
|
|
2223
|
+
}
|
|
2224
|
+
__name(log, "log");
|
|
2225
|
+
var logger = /* @__PURE__ */ __name((fn = console.log) => {
|
|
2226
|
+
return /* @__PURE__ */ __name(async function logger2(c, next) {
|
|
2227
|
+
const { method, url } = c.req;
|
|
2228
|
+
const path = url.slice(url.indexOf("/", 8));
|
|
2229
|
+
await log(fn, "<--", method, path);
|
|
2230
|
+
const start = Date.now();
|
|
2231
|
+
await next();
|
|
2232
|
+
await log(fn, "-->", method, path, c.res.status, time(start));
|
|
2233
|
+
}, "logger2");
|
|
2234
|
+
}, "logger");
|
|
2235
|
+
|
|
2236
|
+
// src/routes/api-endpoints-handler.ts
|
|
2237
|
+
var apiRouter = new Hono2();
|
|
2238
|
+
apiRouter.post("/results", async (c) => {
|
|
2239
|
+
try {
|
|
2240
|
+
const authHeader = c.req.header("Authorization");
|
|
2241
|
+
if (!authHeader?.startsWith("Bearer ")) {
|
|
2242
|
+
return c.json({ error: "Missing or invalid API key" }, 401);
|
|
2243
|
+
}
|
|
2244
|
+
const apiKey = authHeader.slice(7);
|
|
2245
|
+
const keyInfo = await verifyApiKeyAndGetInfo(c.env.DB, apiKey);
|
|
2246
|
+
if (!keyInfo) {
|
|
2247
|
+
return c.json({ error: "Invalid API key" }, 401);
|
|
2248
|
+
}
|
|
2249
|
+
const payload = await c.req.json();
|
|
2250
|
+
if (!payload.skillId || !payload.skillName || !payload.model || !payload.hash) {
|
|
2251
|
+
return c.json({ error: "Missing required fields" }, 400);
|
|
2252
|
+
}
|
|
2253
|
+
if (!["haiku", "sonnet", "opus"].includes(payload.model)) {
|
|
2254
|
+
return c.json({ error: "Invalid model" }, 400);
|
|
2255
|
+
}
|
|
2256
|
+
if (payload.accuracy < 0 || payload.accuracy > 100) {
|
|
2257
|
+
return c.json({ error: "Accuracy must be between 0 and 100" }, 400);
|
|
2258
|
+
}
|
|
2259
|
+
await ensureSkillExists(c.env.DB, payload.skillId, payload.skillName, payload.source);
|
|
2260
|
+
const resultId = crypto.randomUUID();
|
|
2261
|
+
await c.env.DB.prepare(`
|
|
2262
|
+
INSERT INTO results (
|
|
2263
|
+
id, skill_id, model, accuracy, tokens_total, tokens_input, tokens_output,
|
|
2264
|
+
duration_ms, cost_usd, tool_count, runs, hash, raw_json,
|
|
2265
|
+
submitter_github, test_files, skillsh_link
|
|
2266
|
+
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
2267
|
+
`).bind(
|
|
2268
|
+
resultId,
|
|
2269
|
+
payload.skillId,
|
|
2270
|
+
payload.model,
|
|
2271
|
+
payload.accuracy,
|
|
2272
|
+
payload.tokensTotal,
|
|
2273
|
+
payload.tokensInput || null,
|
|
2274
|
+
payload.tokensOutput || null,
|
|
2275
|
+
payload.durationMs,
|
|
2276
|
+
payload.costUsd,
|
|
2277
|
+
payload.toolCount || null,
|
|
2278
|
+
payload.runs,
|
|
2279
|
+
payload.hash,
|
|
2280
|
+
payload.rawJson || null,
|
|
2281
|
+
keyInfo.githubUsername || null,
|
|
2282
|
+
payload.testFiles ? JSON.stringify(payload.testFiles) : null,
|
|
2283
|
+
payload.skillshLink || null
|
|
2284
|
+
).run();
|
|
2285
|
+
await updateApiKeyLastUsed(c.env.DB, apiKey);
|
|
2286
|
+
const rank = await getSkillRank(c.env.DB, payload.skillId);
|
|
2287
|
+
return c.json({
|
|
2288
|
+
success: true,
|
|
2289
|
+
resultId,
|
|
2290
|
+
leaderboardUrl: `https://skillmark.sh/?skill=${encodeURIComponent(payload.skillName)}`,
|
|
2291
|
+
rank,
|
|
2292
|
+
submitter: keyInfo.githubUsername ? {
|
|
2293
|
+
github: keyInfo.githubUsername,
|
|
2294
|
+
avatar: keyInfo.githubAvatar
|
|
2295
|
+
} : null
|
|
2296
|
+
});
|
|
2297
|
+
} catch (error) {
|
|
2298
|
+
console.error("Error submitting result:", error);
|
|
2299
|
+
return c.json({ error: "Internal server error" }, 500);
|
|
2300
|
+
}
|
|
2301
|
+
});
|
|
2302
|
+
apiRouter.get("/leaderboard", async (c) => {
|
|
2303
|
+
try {
|
|
2304
|
+
const limit = Math.min(parseInt(c.req.query("limit") || "20"), 100);
|
|
2305
|
+
const offset = parseInt(c.req.query("offset") || "0");
|
|
2306
|
+
const results = await c.env.DB.prepare(`
|
|
2307
|
+
SELECT
|
|
2308
|
+
skill_id as skillId,
|
|
2309
|
+
skill_name as skillName,
|
|
2310
|
+
source,
|
|
2311
|
+
best_accuracy as bestAccuracy,
|
|
2312
|
+
best_model as bestModel,
|
|
2313
|
+
avg_tokens as avgTokens,
|
|
2314
|
+
avg_cost as avgCost,
|
|
2315
|
+
last_tested as lastTested,
|
|
2316
|
+
total_runs as totalRuns
|
|
2317
|
+
FROM leaderboard
|
|
2318
|
+
LIMIT ? OFFSET ?
|
|
2319
|
+
`).bind(limit, offset).all();
|
|
2320
|
+
const entries = results.results?.map((row) => ({
|
|
2321
|
+
...row,
|
|
2322
|
+
lastTested: row.lastTested ? new Date(row.lastTested * 1e3).toISOString() : null
|
|
2323
|
+
})) || [];
|
|
2324
|
+
return c.json({ entries });
|
|
2325
|
+
} catch (error) {
|
|
2326
|
+
console.error("Error fetching leaderboard:", error);
|
|
2327
|
+
return c.json({ error: "Internal server error" }, 500);
|
|
2328
|
+
}
|
|
2329
|
+
});
|
|
2330
|
+
apiRouter.get("/skill/:name", async (c) => {
|
|
2331
|
+
try {
|
|
2332
|
+
const skillName = decodeURIComponent(c.req.param("name"));
|
|
2333
|
+
const skill = await c.env.DB.prepare(`
|
|
2334
|
+
SELECT
|
|
2335
|
+
skill_id as skillId,
|
|
2336
|
+
skill_name as skillName,
|
|
2337
|
+
source,
|
|
2338
|
+
best_accuracy as bestAccuracy,
|
|
2339
|
+
best_model as bestModel,
|
|
2340
|
+
avg_tokens as avgTokens,
|
|
2341
|
+
avg_cost as avgCost,
|
|
2342
|
+
last_tested as lastTested,
|
|
2343
|
+
total_runs as totalRuns
|
|
2344
|
+
FROM leaderboard
|
|
2345
|
+
WHERE skill_name = ?
|
|
2346
|
+
`).bind(skillName).first();
|
|
2347
|
+
if (!skill) {
|
|
2348
|
+
return c.json({ error: "Skill not found" }, 404);
|
|
2349
|
+
}
|
|
2350
|
+
const history = await c.env.DB.prepare(`
|
|
2351
|
+
SELECT
|
|
2352
|
+
accuracy,
|
|
2353
|
+
model,
|
|
2354
|
+
created_at as date
|
|
2355
|
+
FROM results
|
|
2356
|
+
WHERE skill_id = ?
|
|
2357
|
+
ORDER BY created_at DESC
|
|
2358
|
+
LIMIT 20
|
|
2359
|
+
`).bind(skill.skillId).all();
|
|
2360
|
+
const formattedHistory = history.results?.map((row) => ({
|
|
2361
|
+
accuracy: row.accuracy,
|
|
2362
|
+
model: row.model,
|
|
2363
|
+
date: row.date ? new Date(row.date * 1e3).toISOString() : null
|
|
2364
|
+
})) || [];
|
|
2365
|
+
return c.json({
|
|
2366
|
+
...skill,
|
|
2367
|
+
lastTested: skill.lastTested ? new Date(skill.lastTested * 1e3).toISOString() : null,
|
|
2368
|
+
history: formattedHistory
|
|
2369
|
+
});
|
|
2370
|
+
} catch (error) {
|
|
2371
|
+
console.error("Error fetching skill:", error);
|
|
2372
|
+
return c.json({ error: "Internal server error" }, 500);
|
|
2373
|
+
}
|
|
2374
|
+
});
|
|
2375
|
+
apiRouter.post("/verify", async (c) => {
|
|
2376
|
+
try {
|
|
2377
|
+
const authHeader = c.req.header("Authorization");
|
|
2378
|
+
if (!authHeader?.startsWith("Bearer ")) {
|
|
2379
|
+
return c.json({ valid: false }, 401);
|
|
2380
|
+
}
|
|
2381
|
+
const apiKey = authHeader.slice(7);
|
|
2382
|
+
const isValid = await verifyApiKey(c.env.DB, apiKey);
|
|
2383
|
+
return c.json({ valid: isValid });
|
|
2384
|
+
} catch (error) {
|
|
2385
|
+
return c.json({ valid: false }, 500);
|
|
2386
|
+
}
|
|
2387
|
+
});
|
|
2388
|
+
async function verifyApiKey(db, apiKey) {
|
|
2389
|
+
const keyHash = await hashApiKey(apiKey);
|
|
2390
|
+
const result = await db.prepare(`
|
|
2391
|
+
SELECT id FROM api_keys WHERE key_hash = ?
|
|
2392
|
+
`).bind(keyHash).first();
|
|
2393
|
+
return result !== null;
|
|
2394
|
+
}
|
|
2395
|
+
__name(verifyApiKey, "verifyApiKey");
|
|
2396
|
+
async function verifyApiKeyAndGetInfo(db, apiKey) {
|
|
2397
|
+
const keyHash = await hashApiKey(apiKey);
|
|
2398
|
+
const result = await db.prepare(`
|
|
2399
|
+
SELECT github_username, github_avatar FROM api_keys WHERE key_hash = ?
|
|
2400
|
+
`).bind(keyHash).first();
|
|
2401
|
+
if (!result) {
|
|
2402
|
+
return null;
|
|
2403
|
+
}
|
|
2404
|
+
return {
|
|
2405
|
+
githubUsername: result.github_username,
|
|
2406
|
+
githubAvatar: result.github_avatar
|
|
2407
|
+
};
|
|
2408
|
+
}
|
|
2409
|
+
__name(verifyApiKeyAndGetInfo, "verifyApiKeyAndGetInfo");
|
|
2410
|
+
async function updateApiKeyLastUsed(db, apiKey) {
|
|
2411
|
+
const keyHash = await hashApiKey(apiKey);
|
|
2412
|
+
await db.prepare(`
|
|
2413
|
+
UPDATE api_keys SET last_used_at = unixepoch() WHERE key_hash = ?
|
|
2414
|
+
`).bind(keyHash).run();
|
|
2415
|
+
}
|
|
2416
|
+
__name(updateApiKeyLastUsed, "updateApiKeyLastUsed");
|
|
2417
|
+
async function hashApiKey(apiKey) {
|
|
2418
|
+
const encoder = new TextEncoder();
|
|
2419
|
+
const data = encoder.encode(apiKey);
|
|
2420
|
+
const hashBuffer = await crypto.subtle.digest("SHA-256", data);
|
|
2421
|
+
const hashArray = Array.from(new Uint8Array(hashBuffer));
|
|
2422
|
+
return hashArray.map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
2423
|
+
}
|
|
2424
|
+
__name(hashApiKey, "hashApiKey");
|
|
2425
|
+
async function ensureSkillExists(db, skillId, skillName, source) {
|
|
2426
|
+
const existing = await db.prepare(`
|
|
2427
|
+
SELECT id FROM skills WHERE id = ?
|
|
2428
|
+
`).bind(skillId).first();
|
|
2429
|
+
if (!existing) {
|
|
2430
|
+
await db.prepare(`
|
|
2431
|
+
INSERT INTO skills (id, name, source) VALUES (?, ?, ?)
|
|
2432
|
+
`).bind(skillId, skillName, source).run();
|
|
2433
|
+
}
|
|
2434
|
+
}
|
|
2435
|
+
__name(ensureSkillExists, "ensureSkillExists");
|
|
2436
|
+
async function getSkillRank(db, skillId) {
|
|
2437
|
+
const result = await db.prepare(`
|
|
2438
|
+
SELECT COUNT(*) + 1 as rank
|
|
2439
|
+
FROM leaderboard
|
|
2440
|
+
WHERE best_accuracy > (
|
|
2441
|
+
SELECT best_accuracy FROM leaderboard WHERE skill_id = ?
|
|
2442
|
+
)
|
|
2443
|
+
`).bind(skillId).first();
|
|
2444
|
+
return result?.rank || null;
|
|
2445
|
+
}
|
|
2446
|
+
__name(getSkillRank, "getSkillRank");
|
|
2447
|
+
|
|
2448
|
+
// src/routes/html-pages-renderer.ts
|
|
2449
|
+
var pagesRouter = new Hono2();
|
|
2450
|
+
pagesRouter.get("/", async (c) => {
|
|
2451
|
+
try {
|
|
2452
|
+
const cookieHeader = c.req.header("Cookie") || "";
|
|
2453
|
+
const currentUser = await getCurrentUser(c.env.DB, cookieHeader);
|
|
2454
|
+
const results = await c.env.DB.prepare(`
|
|
2455
|
+
SELECT
|
|
2456
|
+
l.skill_id as skillId,
|
|
2457
|
+
l.skill_name as skillName,
|
|
2458
|
+
l.source,
|
|
2459
|
+
l.best_accuracy as bestAccuracy,
|
|
2460
|
+
l.best_model as bestModel,
|
|
2461
|
+
l.avg_tokens as avgTokens,
|
|
2462
|
+
l.avg_cost as avgCost,
|
|
2463
|
+
l.last_tested as lastTested,
|
|
2464
|
+
l.total_runs as totalRuns,
|
|
2465
|
+
(SELECT submitter_github FROM results WHERE skill_id = l.skill_id ORDER BY created_at DESC LIMIT 1) as submitterGithub,
|
|
2466
|
+
(SELECT skillsh_link FROM results WHERE skill_id = l.skill_id AND skillsh_link IS NOT NULL ORDER BY created_at DESC LIMIT 1) as skillshLink
|
|
2467
|
+
FROM leaderboard l
|
|
2468
|
+
LIMIT 50
|
|
2469
|
+
`).all();
|
|
2470
|
+
const entries = results.results || [];
|
|
2471
|
+
return c.html(renderLeaderboardPage(entries, currentUser));
|
|
2472
|
+
} catch (error) {
|
|
2473
|
+
console.error("Error rendering leaderboard:", error);
|
|
2474
|
+
return c.html(renderErrorPage("Failed to load leaderboard"));
|
|
2475
|
+
}
|
|
2476
|
+
});
|
|
2477
|
+
pagesRouter.get("/docs", (c) => {
|
|
2478
|
+
return c.html(renderDocsPage());
|
|
2479
|
+
});
|
|
2480
|
+
pagesRouter.get("/how-it-works", (c) => {
|
|
2481
|
+
return c.html(renderHowItWorksPage());
|
|
2482
|
+
});
|
|
2483
|
+
pagesRouter.get("/skill/:name", async (c) => {
|
|
2484
|
+
try {
|
|
2485
|
+
const skillName = decodeURIComponent(c.req.param("name"));
|
|
2486
|
+
const skill = await c.env.DB.prepare(`
|
|
2487
|
+
SELECT
|
|
2488
|
+
l.skill_id as skillId,
|
|
2489
|
+
l.skill_name as skillName,
|
|
2490
|
+
l.source,
|
|
2491
|
+
l.best_accuracy as bestAccuracy,
|
|
2492
|
+
l.best_model as bestModel,
|
|
2493
|
+
l.avg_tokens as avgTokens,
|
|
2494
|
+
l.avg_cost as avgCost,
|
|
2495
|
+
l.last_tested as lastTested,
|
|
2496
|
+
l.total_runs as totalRuns
|
|
2497
|
+
FROM leaderboard l
|
|
2498
|
+
WHERE l.skill_name = ?
|
|
2499
|
+
`).bind(skillName).first();
|
|
2500
|
+
if (!skill) {
|
|
2501
|
+
return c.html(renderErrorPage("Skill not found"), 404);
|
|
2502
|
+
}
|
|
2503
|
+
const results = await c.env.DB.prepare(`
|
|
2504
|
+
SELECT
|
|
2505
|
+
r.accuracy,
|
|
2506
|
+
r.model,
|
|
2507
|
+
r.tokens_total as tokensTotal,
|
|
2508
|
+
r.cost_usd as costUsd,
|
|
2509
|
+
r.created_at as createdAt,
|
|
2510
|
+
r.submitter_github as submitterGithub,
|
|
2511
|
+
r.skillsh_link as skillshLink,
|
|
2512
|
+
r.test_files as testFiles
|
|
2513
|
+
FROM results r
|
|
2514
|
+
WHERE r.skill_id = ?
|
|
2515
|
+
ORDER BY r.created_at DESC
|
|
2516
|
+
LIMIT 20
|
|
2517
|
+
`).bind(skill.skillId).all();
|
|
2518
|
+
const formattedResults = results.results?.map((r) => ({
|
|
2519
|
+
accuracy: r.accuracy,
|
|
2520
|
+
model: r.model,
|
|
2521
|
+
tokensTotal: r.tokensTotal,
|
|
2522
|
+
costUsd: r.costUsd,
|
|
2523
|
+
createdAt: r.createdAt ? new Date(r.createdAt * 1e3).toISOString() : null,
|
|
2524
|
+
submitterGithub: r.submitterGithub,
|
|
2525
|
+
skillshLink: r.skillshLink,
|
|
2526
|
+
testFiles: r.testFiles ? JSON.parse(r.testFiles) : null
|
|
2527
|
+
})) || [];
|
|
2528
|
+
return c.html(renderSkillDetailPage(skill, formattedResults));
|
|
2529
|
+
} catch (error) {
|
|
2530
|
+
console.error("Error rendering skill page:", error);
|
|
2531
|
+
return c.html(renderErrorPage("Failed to load skill details"));
|
|
2532
|
+
}
|
|
2533
|
+
});
|
|
2534
|
+
pagesRouter.get("/login", (c) => {
|
|
2535
|
+
const error = c.req.query("error");
|
|
2536
|
+
return c.html(renderLoginPage(error));
|
|
2537
|
+
});
|
|
2538
|
+
pagesRouter.get("/dashboard", async (c) => {
|
|
2539
|
+
const cookieHeader = c.req.header("Cookie") || "";
|
|
2540
|
+
const sessionId = parseCookie(cookieHeader, "skillmark_session");
|
|
2541
|
+
if (!sessionId) {
|
|
2542
|
+
return c.redirect("/login");
|
|
2543
|
+
}
|
|
2544
|
+
const session = await c.env.DB.prepare(`
|
|
2545
|
+
SELECT u.id, u.github_username, u.github_avatar
|
|
2546
|
+
FROM sessions s
|
|
2547
|
+
JOIN users u ON u.id = s.user_id
|
|
2548
|
+
WHERE s.id = ? AND s.expires_at > unixepoch()
|
|
2549
|
+
`).bind(sessionId).first();
|
|
2550
|
+
if (!session) {
|
|
2551
|
+
return c.redirect("/login");
|
|
2552
|
+
}
|
|
2553
|
+
const keys = await c.env.DB.prepare(`
|
|
2554
|
+
SELECT id, created_at, last_used_at
|
|
2555
|
+
FROM api_keys
|
|
2556
|
+
WHERE github_username = ?
|
|
2557
|
+
ORDER BY created_at DESC
|
|
2558
|
+
`).bind(session.github_username).all();
|
|
2559
|
+
const formattedKeys = keys.results?.map((key) => ({
|
|
2560
|
+
id: key.id,
|
|
2561
|
+
createdAt: key.created_at ? new Date(key.created_at * 1e3).toISOString() : null,
|
|
2562
|
+
lastUsedAt: key.last_used_at ? new Date(key.last_used_at * 1e3).toISOString() : null
|
|
2563
|
+
})) || [];
|
|
2564
|
+
return c.html(renderDashboardPage({
|
|
2565
|
+
username: session.github_username,
|
|
2566
|
+
avatar: session.github_avatar,
|
|
2567
|
+
keys: formattedKeys
|
|
2568
|
+
}));
|
|
2569
|
+
});
|
|
2570
|
+
function parseCookie(cookieHeader, name) {
|
|
2571
|
+
const cookies = cookieHeader.split(";");
|
|
2572
|
+
for (const cookie of cookies) {
|
|
2573
|
+
const [cookieName, ...rest] = cookie.trim().split("=");
|
|
2574
|
+
if (cookieName === name) {
|
|
2575
|
+
return rest.join("=");
|
|
2576
|
+
}
|
|
2577
|
+
}
|
|
2578
|
+
return null;
|
|
2579
|
+
}
|
|
2580
|
+
__name(parseCookie, "parseCookie");
|
|
2581
|
+
async function getCurrentUser(db, cookieHeader) {
|
|
2582
|
+
const sessionId = parseCookie(cookieHeader, "skillmark_session");
|
|
2583
|
+
if (!sessionId)
|
|
2584
|
+
return null;
|
|
2585
|
+
const session = await db.prepare(`
|
|
2586
|
+
SELECT u.github_username, u.github_avatar
|
|
2587
|
+
FROM sessions s
|
|
2588
|
+
JOIN users u ON u.id = s.user_id
|
|
2589
|
+
WHERE s.id = ? AND s.expires_at > unixepoch()
|
|
2590
|
+
`).bind(sessionId).first();
|
|
2591
|
+
if (!session)
|
|
2592
|
+
return null;
|
|
2593
|
+
return {
|
|
2594
|
+
username: session.github_username,
|
|
2595
|
+
avatar: session.github_avatar
|
|
2596
|
+
};
|
|
2597
|
+
}
|
|
2598
|
+
__name(getCurrentUser, "getCurrentUser");
|
|
2599
|
+
function renderNav(currentUser) {
|
|
2600
|
+
const userSection = currentUser ? `<a href="/dashboard" class="user-nav">
|
|
2601
|
+
<img src="${currentUser.avatar || `https://github.com/${currentUser.username}.png?size=32`}" alt="" class="user-avatar">
|
|
2602
|
+
<span>@${escapeHtml(currentUser.username)}</span>
|
|
2603
|
+
</a>` : `<a href="/login">Login</a>`;
|
|
2604
|
+
return `
|
|
2605
|
+
<nav>
|
|
2606
|
+
<div class="nav-left">
|
|
2607
|
+
<a href="/" class="nav-home">
|
|
2608
|
+
<svg class="nav-logo" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round">
|
|
2609
|
+
<path d="M22 12h-4l-3 9L9 3l-3 9H2"/>
|
|
2610
|
+
</svg>
|
|
2611
|
+
<span class="nav-divider">/</span>
|
|
2612
|
+
<span class="nav-title">Skillmark</span>
|
|
2613
|
+
</a>
|
|
2614
|
+
</div>
|
|
2615
|
+
<div class="nav-right">
|
|
2616
|
+
<a href="/docs">Docs</a>
|
|
2617
|
+
<a href="/how-it-works">How It Works</a>
|
|
2618
|
+
<a href="https://github.com/claudekit/skillmark" title="GitHub"><svg width="18" height="18" viewBox="0 0 24 24" fill="currentColor"><path d="M12 0c-6.626 0-12 5.373-12 12 0 5.302 3.438 9.8 8.207 11.387.599.111.793-.261.793-.577v-2.234c-3.338.726-4.033-1.416-4.033-1.416-.546-1.387-1.333-1.756-1.333-1.756-1.089-.745.083-.729.083-.729 1.205.084 1.839 1.237 1.839 1.237 1.07 1.834 2.807 1.304 3.492.997.107-.775.418-1.305.762-1.604-2.665-.305-5.467-1.334-5.467-5.931 0-1.311.469-2.381 1.236-3.221-.124-.303-.535-1.524.117-3.176 0 0 1.008-.322 3.301 1.23.957-.266 1.983-.399 3.003-.404 1.02.005 2.047.138 3.006.404 2.291-1.552 3.297-1.23 3.297-1.23.653 1.653.242 2.874.118 3.176.77.84 1.235 1.911 1.235 3.221 0 4.609-2.807 5.624-5.479 5.921.43.372.823 1.102.823 2.222v3.293c0 .319.192.694.801.576 4.765-1.589 8.199-6.086 8.199-11.386 0-6.627-5.373-12-12-12z"/></svg></a>
|
|
2619
|
+
${userSection}
|
|
2620
|
+
</div>
|
|
2621
|
+
</nav>`;
|
|
2622
|
+
}
|
|
2623
|
+
__name(renderNav, "renderNav");
|
|
2624
|
+
function renderLeaderboardPage(entries, currentUser = null) {
|
|
2625
|
+
const totalRuns = entries.reduce((sum, e) => sum + e.totalRuns, 0);
|
|
2626
|
+
const rows = entries.map((entry, index) => {
|
|
2627
|
+
const rank = index + 1;
|
|
2628
|
+
const accuracy = entry.bestAccuracy.toFixed(1);
|
|
2629
|
+
const source = entry.source || "";
|
|
2630
|
+
const repoPath = source.replace("https://github.com/", "").replace(/\.git$/, "");
|
|
2631
|
+
const submitter = entry.submitterGithub;
|
|
2632
|
+
const skillshLink = entry.skillshLink;
|
|
2633
|
+
return `
|
|
2634
|
+
<tr onclick="window.location='/skill/${encodeURIComponent(entry.skillName)}'" style="cursor: pointer;">
|
|
2635
|
+
<td class="rank">${rank}</td>
|
|
2636
|
+
<td class="skill">
|
|
2637
|
+
<div class="skill-info">
|
|
2638
|
+
<span class="skill-name">${escapeHtml(entry.skillName)}</span>
|
|
2639
|
+
${repoPath ? `<span class="skill-repo">${escapeHtml(repoPath)}</span>` : ""}
|
|
2640
|
+
${skillshLink ? `<a href="${escapeHtml(skillshLink)}" class="skillsh-link" onclick="event.stopPropagation()">skill.sh</a>` : ""}
|
|
2641
|
+
</div>
|
|
2642
|
+
</td>
|
|
2643
|
+
<td class="submitter">
|
|
2644
|
+
${submitter ? `
|
|
2645
|
+
<a href="https://github.com/${escapeHtml(submitter)}" class="submitter-link" onclick="event.stopPropagation()">
|
|
2646
|
+
<img src="https://github.com/${escapeHtml(submitter)}.png?size=24" alt="" class="submitter-avatar">
|
|
2647
|
+
<span>@${escapeHtml(submitter)}</span>
|
|
2648
|
+
</a>
|
|
2649
|
+
` : '<span class="no-submitter">-</span>'}
|
|
2650
|
+
</td>
|
|
2651
|
+
<td class="accuracy">${accuracy}%</td>
|
|
2652
|
+
</tr>
|
|
2653
|
+
`;
|
|
2654
|
+
}).join("");
|
|
2655
|
+
return `<!DOCTYPE html>
|
|
2656
|
+
<html lang="en">
|
|
2657
|
+
<head>
|
|
2658
|
+
<meta charset="UTF-8">
|
|
2659
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
2660
|
+
<title>Skillmark - Agent Skill Benchmarks</title>
|
|
2661
|
+
<meta name="description" content="The open agent skill benchmarking platform. Test and compare AI agent skills with detailed metrics.">
|
|
2662
|
+
|
|
2663
|
+
<!-- Favicon -->
|
|
2664
|
+
<link rel="icon" type="image/png" href="/favicon.png">
|
|
2665
|
+
<link rel="apple-touch-icon" href="/favicon.png">
|
|
2666
|
+
|
|
2667
|
+
<!-- Open Graph -->
|
|
2668
|
+
<meta property="og:type" content="website">
|
|
2669
|
+
<meta property="og:url" content="https://skillmark.sh/">
|
|
2670
|
+
<meta property="og:title" content="Skillmark - Agent Skill Benchmarks">
|
|
2671
|
+
<meta property="og:description" content="Benchmark your AI agent skills with detailed metrics. Compare accuracy, token usage, and cost across models.">
|
|
2672
|
+
<meta property="og:image" content="https://cdn.claudekit.cc/skillmark/og-image.png">
|
|
2673
|
+
<meta property="og:site_name" content="Skillmark">
|
|
2674
|
+
|
|
2675
|
+
<!-- Twitter Card -->
|
|
2676
|
+
<meta name="twitter:card" content="summary_large_image">
|
|
2677
|
+
<meta name="twitter:url" content="https://skillmark.sh/">
|
|
2678
|
+
<meta name="twitter:title" content="Skillmark - Agent Skill Benchmarks">
|
|
2679
|
+
<meta name="twitter:description" content="Benchmark your AI agent skills with detailed metrics. Compare accuracy, token usage, and cost across models.">
|
|
2680
|
+
<meta name="twitter:image" content="https://cdn.claudekit.cc/skillmark/og-image.png">
|
|
2681
|
+
|
|
2682
|
+
<link rel="preconnect" href="https://fonts.googleapis.com">
|
|
2683
|
+
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
|
2684
|
+
<link href="https://fonts.googleapis.com/css2?family=Geist:wght@400;500;600&family=Geist+Mono:wght@400;500&display=swap" rel="stylesheet">
|
|
2685
|
+
<style>
|
|
2686
|
+
* {
|
|
2687
|
+
box-sizing: border-box;
|
|
2688
|
+
margin: 0;
|
|
2689
|
+
padding: 0;
|
|
2690
|
+
}
|
|
2691
|
+
|
|
2692
|
+
:root {
|
|
2693
|
+
--bg: #000;
|
|
2694
|
+
--text: #ededed;
|
|
2695
|
+
--text-secondary: #888;
|
|
2696
|
+
--border: #333;
|
|
2697
|
+
--hover: #111;
|
|
2698
|
+
}
|
|
2699
|
+
|
|
2700
|
+
body {
|
|
2701
|
+
font-family: 'Geist', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
|
|
2702
|
+
background: var(--bg);
|
|
2703
|
+
color: var(--text);
|
|
2704
|
+
line-height: 1.6;
|
|
2705
|
+
min-height: 100vh;
|
|
2706
|
+
-webkit-font-smoothing: antialiased;
|
|
2707
|
+
}
|
|
2708
|
+
|
|
2709
|
+
/* Navigation */
|
|
2710
|
+
nav {
|
|
2711
|
+
display: flex;
|
|
2712
|
+
align-items: center;
|
|
2713
|
+
justify-content: space-between;
|
|
2714
|
+
padding: 1rem 1.5rem;
|
|
2715
|
+
border-bottom: 1px solid var(--border);
|
|
2716
|
+
}
|
|
2717
|
+
|
|
2718
|
+
.nav-left {
|
|
2719
|
+
display: flex;
|
|
2720
|
+
align-items: center;
|
|
2721
|
+
gap: 0.5rem;
|
|
2722
|
+
}
|
|
2723
|
+
|
|
2724
|
+
.nav-logo {
|
|
2725
|
+
font-size: 1.25rem;
|
|
2726
|
+
}
|
|
2727
|
+
|
|
2728
|
+
.nav-divider {
|
|
2729
|
+
color: var(--text-secondary);
|
|
2730
|
+
margin: 0 0.25rem;
|
|
2731
|
+
}
|
|
2732
|
+
|
|
2733
|
+
.nav-title {
|
|
2734
|
+
font-weight: 500;
|
|
2735
|
+
}
|
|
2736
|
+
|
|
2737
|
+
.nav-right {
|
|
2738
|
+
display: flex;
|
|
2739
|
+
gap: 1.5rem;
|
|
2740
|
+
}
|
|
2741
|
+
|
|
2742
|
+
.nav-right a {
|
|
2743
|
+
color: var(--text-secondary);
|
|
2744
|
+
text-decoration: none;
|
|
2745
|
+
font-size: 0.875rem;
|
|
2746
|
+
}
|
|
2747
|
+
|
|
2748
|
+
.nav-right a:hover {
|
|
2749
|
+
color: var(--text);
|
|
2750
|
+
}
|
|
2751
|
+
|
|
2752
|
+
.user-nav {
|
|
2753
|
+
display: flex;
|
|
2754
|
+
align-items: center;
|
|
2755
|
+
gap: 0.5rem;
|
|
2756
|
+
}
|
|
2757
|
+
|
|
2758
|
+
.user-avatar {
|
|
2759
|
+
width: 24px;
|
|
2760
|
+
height: 24px;
|
|
2761
|
+
border-radius: 50%;
|
|
2762
|
+
}
|
|
2763
|
+
|
|
2764
|
+
.nav-home {
|
|
2765
|
+
display: flex;
|
|
2766
|
+
align-items: center;
|
|
2767
|
+
text-decoration: none;
|
|
2768
|
+
color: inherit;
|
|
2769
|
+
}
|
|
2770
|
+
|
|
2771
|
+
/* Main container */
|
|
2772
|
+
.container {
|
|
2773
|
+
max-width: 1200px;
|
|
2774
|
+
margin: 0 auto;
|
|
2775
|
+
padding: 4rem 1.5rem;
|
|
2776
|
+
}
|
|
2777
|
+
|
|
2778
|
+
/* Hero section */
|
|
2779
|
+
.hero {
|
|
2780
|
+
display: grid;
|
|
2781
|
+
grid-template-columns: 1fr 1fr;
|
|
2782
|
+
gap: 4rem;
|
|
2783
|
+
margin-bottom: 4rem;
|
|
2784
|
+
align-items: start;
|
|
2785
|
+
}
|
|
2786
|
+
|
|
2787
|
+
.hero-left {
|
|
2788
|
+
display: flex;
|
|
2789
|
+
flex-direction: column;
|
|
2790
|
+
gap: 1.5rem;
|
|
2791
|
+
}
|
|
2792
|
+
|
|
2793
|
+
.logo-text {
|
|
2794
|
+
font-family: 'Geist Mono', monospace;
|
|
2795
|
+
font-size: 4rem;
|
|
2796
|
+
font-weight: 600;
|
|
2797
|
+
letter-spacing: -0.02em;
|
|
2798
|
+
line-height: 1;
|
|
2799
|
+
}
|
|
2800
|
+
|
|
2801
|
+
.logo-subtitle {
|
|
2802
|
+
font-size: 0.75rem;
|
|
2803
|
+
letter-spacing: 0.2em;
|
|
2804
|
+
text-transform: uppercase;
|
|
2805
|
+
color: var(--text-secondary);
|
|
2806
|
+
}
|
|
2807
|
+
|
|
2808
|
+
.hero-right p {
|
|
2809
|
+
font-size: 1.5rem;
|
|
2810
|
+
color: var(--text-secondary);
|
|
2811
|
+
line-height: 1.5;
|
|
2812
|
+
}
|
|
2813
|
+
|
|
2814
|
+
/* Install section */
|
|
2815
|
+
.install-section {
|
|
2816
|
+
display: grid;
|
|
2817
|
+
grid-template-columns: 1fr 1fr;
|
|
2818
|
+
gap: 4rem;
|
|
2819
|
+
margin-bottom: 5rem;
|
|
2820
|
+
}
|
|
2821
|
+
|
|
2822
|
+
.install-box h3 {
|
|
2823
|
+
font-size: 0.75rem;
|
|
2824
|
+
letter-spacing: 0.15em;
|
|
2825
|
+
text-transform: uppercase;
|
|
2826
|
+
color: var(--text-secondary);
|
|
2827
|
+
margin-bottom: 1rem;
|
|
2828
|
+
}
|
|
2829
|
+
|
|
2830
|
+
.install-command {
|
|
2831
|
+
display: flex;
|
|
2832
|
+
align-items: center;
|
|
2833
|
+
background: #0a0a0a;
|
|
2834
|
+
border: 1px solid var(--border);
|
|
2835
|
+
border-radius: 8px;
|
|
2836
|
+
padding: 0.875rem 1rem;
|
|
2837
|
+
font-family: 'Geist Mono', monospace;
|
|
2838
|
+
font-size: 0.875rem;
|
|
2839
|
+
}
|
|
2840
|
+
|
|
2841
|
+
.install-command .dollar {
|
|
2842
|
+
color: var(--text-secondary);
|
|
2843
|
+
margin-right: 0.5rem;
|
|
2844
|
+
user-select: none;
|
|
2845
|
+
}
|
|
2846
|
+
|
|
2847
|
+
.install-command code {
|
|
2848
|
+
flex: 1;
|
|
2849
|
+
}
|
|
2850
|
+
|
|
2851
|
+
.install-command .copy-btn {
|
|
2852
|
+
background: none;
|
|
2853
|
+
border: none;
|
|
2854
|
+
color: var(--text-secondary);
|
|
2855
|
+
cursor: pointer;
|
|
2856
|
+
padding: 0.25rem;
|
|
2857
|
+
}
|
|
2858
|
+
|
|
2859
|
+
.install-command .copy-btn:hover {
|
|
2860
|
+
color: var(--text);
|
|
2861
|
+
}
|
|
2862
|
+
|
|
2863
|
+
.agents-list {
|
|
2864
|
+
display: flex;
|
|
2865
|
+
gap: 1.5rem;
|
|
2866
|
+
align-items: center;
|
|
2867
|
+
}
|
|
2868
|
+
|
|
2869
|
+
.agent-icon {
|
|
2870
|
+
width: 32px;
|
|
2871
|
+
height: 32px;
|
|
2872
|
+
opacity: 0.6;
|
|
2873
|
+
}
|
|
2874
|
+
|
|
2875
|
+
.agent-icon:hover {
|
|
2876
|
+
opacity: 1;
|
|
2877
|
+
}
|
|
2878
|
+
|
|
2879
|
+
/* Leaderboard section */
|
|
2880
|
+
.leaderboard-section h2 {
|
|
2881
|
+
font-size: 0.75rem;
|
|
2882
|
+
letter-spacing: 0.15em;
|
|
2883
|
+
text-transform: uppercase;
|
|
2884
|
+
color: var(--text-secondary);
|
|
2885
|
+
margin-bottom: 1.5rem;
|
|
2886
|
+
}
|
|
2887
|
+
|
|
2888
|
+
/* Search bar */
|
|
2889
|
+
.search-container {
|
|
2890
|
+
position: relative;
|
|
2891
|
+
margin-bottom: 1.5rem;
|
|
2892
|
+
}
|
|
2893
|
+
|
|
2894
|
+
.search-icon {
|
|
2895
|
+
position: absolute;
|
|
2896
|
+
left: 1rem;
|
|
2897
|
+
top: 50%;
|
|
2898
|
+
transform: translateY(-50%);
|
|
2899
|
+
color: var(--text-secondary);
|
|
2900
|
+
}
|
|
2901
|
+
|
|
2902
|
+
.search-input {
|
|
2903
|
+
width: 100%;
|
|
2904
|
+
background: transparent;
|
|
2905
|
+
border: 1px solid var(--border);
|
|
2906
|
+
border-radius: 8px;
|
|
2907
|
+
padding: 0.875rem 1rem 0.875rem 2.75rem;
|
|
2908
|
+
font-family: 'Geist Mono', monospace;
|
|
2909
|
+
font-size: 0.875rem;
|
|
2910
|
+
color: var(--text);
|
|
2911
|
+
outline: none;
|
|
2912
|
+
}
|
|
2913
|
+
|
|
2914
|
+
.search-input::placeholder {
|
|
2915
|
+
color: var(--text-secondary);
|
|
2916
|
+
}
|
|
2917
|
+
|
|
2918
|
+
.search-input:focus {
|
|
2919
|
+
border-color: #555;
|
|
2920
|
+
}
|
|
2921
|
+
|
|
2922
|
+
.search-shortcut {
|
|
2923
|
+
position: absolute;
|
|
2924
|
+
right: 1rem;
|
|
2925
|
+
top: 50%;
|
|
2926
|
+
transform: translateY(-50%);
|
|
2927
|
+
color: var(--text-secondary);
|
|
2928
|
+
font-family: 'Geist Mono', monospace;
|
|
2929
|
+
font-size: 0.75rem;
|
|
2930
|
+
border: 1px solid var(--border);
|
|
2931
|
+
border-radius: 4px;
|
|
2932
|
+
padding: 0.125rem 0.375rem;
|
|
2933
|
+
}
|
|
2934
|
+
|
|
2935
|
+
/* Tabs */
|
|
2936
|
+
.tabs {
|
|
2937
|
+
display: flex;
|
|
2938
|
+
gap: 1.5rem;
|
|
2939
|
+
margin-bottom: 1rem;
|
|
2940
|
+
border-bottom: 1px solid var(--border);
|
|
2941
|
+
padding-bottom: 0.75rem;
|
|
2942
|
+
}
|
|
2943
|
+
|
|
2944
|
+
.tab {
|
|
2945
|
+
background: none;
|
|
2946
|
+
border: none;
|
|
2947
|
+
color: var(--text-secondary);
|
|
2948
|
+
font-family: inherit;
|
|
2949
|
+
font-size: 0.875rem;
|
|
2950
|
+
cursor: pointer;
|
|
2951
|
+
padding: 0;
|
|
2952
|
+
}
|
|
2953
|
+
|
|
2954
|
+
.tab:hover {
|
|
2955
|
+
color: var(--text);
|
|
2956
|
+
}
|
|
2957
|
+
|
|
2958
|
+
.tab.active {
|
|
2959
|
+
color: var(--text);
|
|
2960
|
+
text-decoration: underline;
|
|
2961
|
+
text-underline-offset: 0.5rem;
|
|
2962
|
+
}
|
|
2963
|
+
|
|
2964
|
+
.tab-count {
|
|
2965
|
+
color: var(--text-secondary);
|
|
2966
|
+
}
|
|
2967
|
+
|
|
2968
|
+
/* Table */
|
|
2969
|
+
.leaderboard-table {
|
|
2970
|
+
width: 100%;
|
|
2971
|
+
border-collapse: collapse;
|
|
2972
|
+
}
|
|
2973
|
+
|
|
2974
|
+
.leaderboard-table th {
|
|
2975
|
+
text-align: left;
|
|
2976
|
+
font-size: 0.75rem;
|
|
2977
|
+
letter-spacing: 0.1em;
|
|
2978
|
+
text-transform: uppercase;
|
|
2979
|
+
color: var(--text-secondary);
|
|
2980
|
+
font-weight: 500;
|
|
2981
|
+
padding: 0.75rem 0;
|
|
2982
|
+
border-bottom: 1px solid var(--border);
|
|
2983
|
+
}
|
|
2984
|
+
|
|
2985
|
+
.leaderboard-table th:last-child {
|
|
2986
|
+
text-align: right;
|
|
2987
|
+
}
|
|
2988
|
+
|
|
2989
|
+
.leaderboard-table td {
|
|
2990
|
+
padding: 1rem 0;
|
|
2991
|
+
border-bottom: 1px solid var(--border);
|
|
2992
|
+
vertical-align: middle;
|
|
2993
|
+
}
|
|
2994
|
+
|
|
2995
|
+
.leaderboard-table tr:hover td {
|
|
2996
|
+
background: var(--hover);
|
|
2997
|
+
}
|
|
2998
|
+
|
|
2999
|
+
.rank {
|
|
3000
|
+
width: 50px;
|
|
3001
|
+
color: var(--text-secondary);
|
|
3002
|
+
font-family: 'Geist Mono', monospace;
|
|
3003
|
+
}
|
|
3004
|
+
|
|
3005
|
+
.skill {
|
|
3006
|
+
display: flex;
|
|
3007
|
+
flex-direction: column;
|
|
3008
|
+
gap: 0.125rem;
|
|
3009
|
+
}
|
|
3010
|
+
|
|
3011
|
+
.skill-info {
|
|
3012
|
+
display: flex;
|
|
3013
|
+
flex-direction: column;
|
|
3014
|
+
gap: 0.125rem;
|
|
3015
|
+
}
|
|
3016
|
+
|
|
3017
|
+
.skill-name {
|
|
3018
|
+
font-weight: 500;
|
|
3019
|
+
}
|
|
3020
|
+
|
|
3021
|
+
.skill-repo {
|
|
3022
|
+
font-family: 'Geist Mono', monospace;
|
|
3023
|
+
font-size: 0.8125rem;
|
|
3024
|
+
color: var(--text-secondary);
|
|
3025
|
+
}
|
|
3026
|
+
|
|
3027
|
+
.skillsh-link {
|
|
3028
|
+
font-size: 0.75rem;
|
|
3029
|
+
color: #58a6ff;
|
|
3030
|
+
text-decoration: none;
|
|
3031
|
+
}
|
|
3032
|
+
|
|
3033
|
+
.skillsh-link:hover {
|
|
3034
|
+
text-decoration: underline;
|
|
3035
|
+
}
|
|
3036
|
+
|
|
3037
|
+
.submitter {
|
|
3038
|
+
width: 150px;
|
|
3039
|
+
}
|
|
3040
|
+
|
|
3041
|
+
.submitter-link {
|
|
3042
|
+
display: flex;
|
|
3043
|
+
align-items: center;
|
|
3044
|
+
gap: 0.5rem;
|
|
3045
|
+
color: var(--text-secondary);
|
|
3046
|
+
text-decoration: none;
|
|
3047
|
+
font-size: 0.8125rem;
|
|
3048
|
+
}
|
|
3049
|
+
|
|
3050
|
+
.submitter-link:hover {
|
|
3051
|
+
color: var(--text);
|
|
3052
|
+
}
|
|
3053
|
+
|
|
3054
|
+
.submitter-avatar {
|
|
3055
|
+
width: 20px;
|
|
3056
|
+
height: 20px;
|
|
3057
|
+
border-radius: 50%;
|
|
3058
|
+
}
|
|
3059
|
+
|
|
3060
|
+
.no-submitter {
|
|
3061
|
+
color: var(--text-secondary);
|
|
3062
|
+
}
|
|
3063
|
+
|
|
3064
|
+
.accuracy {
|
|
3065
|
+
text-align: right;
|
|
3066
|
+
font-family: 'Geist Mono', monospace;
|
|
3067
|
+
font-weight: 500;
|
|
3068
|
+
}
|
|
3069
|
+
|
|
3070
|
+
/* Empty state */
|
|
3071
|
+
.empty-state {
|
|
3072
|
+
text-align: center;
|
|
3073
|
+
padding: 4rem 2rem;
|
|
3074
|
+
color: var(--text-secondary);
|
|
3075
|
+
}
|
|
3076
|
+
|
|
3077
|
+
.empty-state p {
|
|
3078
|
+
margin-bottom: 2rem;
|
|
3079
|
+
}
|
|
3080
|
+
|
|
3081
|
+
.empty-cta {
|
|
3082
|
+
display: flex;
|
|
3083
|
+
flex-direction: column;
|
|
3084
|
+
align-items: center;
|
|
3085
|
+
gap: 0.75rem;
|
|
3086
|
+
}
|
|
3087
|
+
|
|
3088
|
+
.empty-cta code {
|
|
3089
|
+
background: #0a0a0a;
|
|
3090
|
+
border: 1px solid var(--border);
|
|
3091
|
+
padding: 0.75rem 1.25rem;
|
|
3092
|
+
border-radius: 8px;
|
|
3093
|
+
font-family: 'Geist Mono', monospace;
|
|
3094
|
+
font-size: 0.875rem;
|
|
3095
|
+
}
|
|
3096
|
+
|
|
3097
|
+
/* Footer */
|
|
3098
|
+
footer {
|
|
3099
|
+
margin-top: 4rem;
|
|
3100
|
+
padding: 2rem 0;
|
|
3101
|
+
border-top: 1px solid var(--border);
|
|
3102
|
+
text-align: center;
|
|
3103
|
+
color: var(--text-secondary);
|
|
3104
|
+
font-size: 0.8125rem;
|
|
3105
|
+
}
|
|
3106
|
+
|
|
3107
|
+
footer a {
|
|
3108
|
+
color: var(--text);
|
|
3109
|
+
text-decoration: none;
|
|
3110
|
+
}
|
|
3111
|
+
|
|
3112
|
+
footer a:hover {
|
|
3113
|
+
text-decoration: underline;
|
|
3114
|
+
}
|
|
3115
|
+
|
|
3116
|
+
/* Responsive */
|
|
3117
|
+
@media (max-width: 768px) {
|
|
3118
|
+
.hero {
|
|
3119
|
+
grid-template-columns: 1fr;
|
|
3120
|
+
gap: 2rem;
|
|
3121
|
+
}
|
|
3122
|
+
|
|
3123
|
+
.logo-text {
|
|
3124
|
+
font-size: 2.5rem;
|
|
3125
|
+
}
|
|
3126
|
+
|
|
3127
|
+
.hero-right p {
|
|
3128
|
+
font-size: 1.125rem;
|
|
3129
|
+
}
|
|
3130
|
+
|
|
3131
|
+
.install-section {
|
|
3132
|
+
grid-template-columns: 1fr;
|
|
3133
|
+
gap: 2rem;
|
|
3134
|
+
}
|
|
3135
|
+
|
|
3136
|
+
.agents-list {
|
|
3137
|
+
flex-wrap: wrap;
|
|
3138
|
+
}
|
|
3139
|
+
}
|
|
3140
|
+
</style>
|
|
3141
|
+
</head>
|
|
3142
|
+
<body>
|
|
3143
|
+
${renderNav(currentUser)}
|
|
3144
|
+
|
|
3145
|
+
<div class="container">
|
|
3146
|
+
<!-- Hero -->
|
|
3147
|
+
<section class="hero">
|
|
3148
|
+
<div class="hero-left">
|
|
3149
|
+
<div>
|
|
3150
|
+
<div class="logo-text">SKILLMARK</div>
|
|
3151
|
+
<div class="logo-subtitle">The Agent Skill Benchmarking Platform</div>
|
|
3152
|
+
</div>
|
|
3153
|
+
</div>
|
|
3154
|
+
<div class="hero-right">
|
|
3155
|
+
<p>Benchmark your AI agent skills with detailed metrics. Compare accuracy, token usage, and cost across models.</p>
|
|
3156
|
+
</div>
|
|
3157
|
+
</section>
|
|
3158
|
+
|
|
3159
|
+
<!-- Install -->
|
|
3160
|
+
<section class="install-section">
|
|
3161
|
+
<div class="install-box">
|
|
3162
|
+
<h3>Install in One Command</h3>
|
|
3163
|
+
<div class="install-command">
|
|
3164
|
+
<span class="dollar">$</span>
|
|
3165
|
+
<code>npx skillmark run <skill-path></code>
|
|
3166
|
+
<button class="copy-btn" onclick="navigator.clipboard.writeText('npx skillmark run')">
|
|
3167
|
+
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
3168
|
+
<rect x="9" y="9" width="13" height="13" rx="2" ry="2"></rect>
|
|
3169
|
+
<path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"></path>
|
|
3170
|
+
</svg>
|
|
3171
|
+
</button>
|
|
3172
|
+
</div>
|
|
3173
|
+
</div>
|
|
3174
|
+
<div class="install-box">
|
|
3175
|
+
<h3>Compatible with These Agents</h3>
|
|
3176
|
+
<div class="agents-list">
|
|
3177
|
+
<svg class="agent-icon" viewBox="0 0 24 24" fill="currentColor"><path d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm-1 17.93c-3.95-.49-7-3.85-7-7.93 0-.62.08-1.21.21-1.79L9 15v1c0 1.1.9 2 2 2v1.93zm6.9-2.54c-.26-.81-1-1.39-1.9-1.39h-1v-3c0-.55-.45-1-1-1H8v-2h2c.55 0 1-.45 1-1V7h2c1.1 0 2-.9 2-2v-.41c2.93 1.19 5 4.06 5 7.41 0 2.08-.8 3.97-2.1 5.39z"/></svg>
|
|
3178
|
+
<svg class="agent-icon" viewBox="0 0 24 24" fill="currentColor"><path d="M12 2L2 7l10 5 10-5-10-5zM2 17l10 5 10-5M2 12l10 5 10-5"/></svg>
|
|
3179
|
+
<svg class="agent-icon" viewBox="0 0 24 24" fill="currentColor"><path d="M20 4H4c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V6c0-1.1-.9-2-2-2zm0 14H4V6h16v12zM6 10h2v2H6zm0 4h8v2H6zm10 0h2v2h-2zm-6-4h8v2h-8z"/></svg>
|
|
3180
|
+
<svg class="agent-icon" viewBox="0 0 24 24" fill="currentColor"><path d="M12 17.27L18.18 21l-1.64-7.03L22 9.24l-7.19-.61L12 2 9.19 8.63 2 9.24l5.46 4.73L5.82 21z"/></svg>
|
|
3181
|
+
</div>
|
|
3182
|
+
</div>
|
|
3183
|
+
</section>
|
|
3184
|
+
|
|
3185
|
+
<!-- Leaderboard -->
|
|
3186
|
+
<section class="leaderboard-section">
|
|
3187
|
+
<h2>Skills Leaderboard</h2>
|
|
3188
|
+
|
|
3189
|
+
<div class="search-container">
|
|
3190
|
+
<svg class="search-icon" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
3191
|
+
<circle cx="11" cy="11" r="8"></circle>
|
|
3192
|
+
<line x1="21" y1="21" x2="16.65" y2="16.65"></line>
|
|
3193
|
+
</svg>
|
|
3194
|
+
<input type="text" class="search-input" placeholder="Search skills..." id="search">
|
|
3195
|
+
<span class="search-shortcut">/</span>
|
|
3196
|
+
</div>
|
|
3197
|
+
|
|
3198
|
+
<div class="tabs">
|
|
3199
|
+
<button class="tab active">All Time <span class="tab-count">(${entries.length.toLocaleString()})</span></button>
|
|
3200
|
+
<button class="tab">By Accuracy</button>
|
|
3201
|
+
<button class="tab">By Tokens</button>
|
|
3202
|
+
<button class="tab">By Cost</button>
|
|
3203
|
+
</div>
|
|
3204
|
+
|
|
3205
|
+
${entries.length > 0 ? `
|
|
3206
|
+
<table class="leaderboard-table">
|
|
3207
|
+
<thead>
|
|
3208
|
+
<tr>
|
|
3209
|
+
<th>#</th>
|
|
3210
|
+
<th>Skill</th>
|
|
3211
|
+
<th>Submitter</th>
|
|
3212
|
+
<th>Accuracy</th>
|
|
3213
|
+
</tr>
|
|
3214
|
+
</thead>
|
|
3215
|
+
<tbody>
|
|
3216
|
+
${rows}
|
|
3217
|
+
</tbody>
|
|
3218
|
+
</table>
|
|
3219
|
+
` : `
|
|
3220
|
+
<div class="empty-state">
|
|
3221
|
+
<p>No benchmark results yet.</p>
|
|
3222
|
+
<div class="empty-cta">
|
|
3223
|
+
<code>npx skillmark run <skill-path></code>
|
|
3224
|
+
<code>npx skillmark publish ./result.json --api-key <key></code>
|
|
3225
|
+
</div>
|
|
3226
|
+
</div>
|
|
3227
|
+
`}
|
|
3228
|
+
</section>
|
|
3229
|
+
|
|
3230
|
+
<footer>
|
|
3231
|
+
<p>
|
|
3232
|
+
Built with <a href="https://github.com/claudekit/skillmark">Skillmark</a> \xB7
|
|
3233
|
+
<a href="https://www.npmjs.com/package/skillmark">npm</a> \xB7
|
|
3234
|
+
<a href="https://github.com/claudekit/skillmark">GitHub</a> \xB7
|
|
3235
|
+
by <a href="https://claudekit.cc">ClaudeKit.cc</a>
|
|
3236
|
+
</p>
|
|
3237
|
+
</footer>
|
|
3238
|
+
</div>
|
|
3239
|
+
|
|
3240
|
+
<script>
|
|
3241
|
+
// Keyboard shortcut for search
|
|
3242
|
+
document.addEventListener('keydown', (e) => {
|
|
3243
|
+
if (e.key === '/' && document.activeElement.tagName !== 'INPUT') {
|
|
3244
|
+
e.preventDefault();
|
|
3245
|
+
document.getElementById('search').focus();
|
|
3246
|
+
}
|
|
3247
|
+
});
|
|
3248
|
+
|
|
3249
|
+
// Search functionality
|
|
3250
|
+
document.getElementById('search').addEventListener('input', (e) => {
|
|
3251
|
+
const query = e.target.value.toLowerCase();
|
|
3252
|
+
document.querySelectorAll('.leaderboard-table tbody tr').forEach(row => {
|
|
3253
|
+
const text = row.textContent.toLowerCase();
|
|
3254
|
+
row.style.display = text.includes(query) ? '' : 'none';
|
|
3255
|
+
});
|
|
3256
|
+
});
|
|
3257
|
+
<\/script>
|
|
3258
|
+
</body>
|
|
3259
|
+
</html>`;
|
|
3260
|
+
}
|
|
3261
|
+
__name(renderLeaderboardPage, "renderLeaderboardPage");
|
|
3262
|
+
function renderErrorPage(message) {
|
|
3263
|
+
return `<!DOCTYPE html>
|
|
3264
|
+
<html lang="en">
|
|
3265
|
+
<head>
|
|
3266
|
+
<meta charset="UTF-8">
|
|
3267
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
3268
|
+
<title>Error - Skillmark</title>
|
|
3269
|
+
<link rel="icon" type="image/png" href="/favicon.png">
|
|
3270
|
+
<link href="https://fonts.googleapis.com/css2?family=Geist:wght@400;500&display=swap" rel="stylesheet">
|
|
3271
|
+
<style>
|
|
3272
|
+
* { box-sizing: border-box; margin: 0; padding: 0; }
|
|
3273
|
+
body {
|
|
3274
|
+
font-family: 'Geist', -apple-system, sans-serif;
|
|
3275
|
+
background: #000;
|
|
3276
|
+
color: #ededed;
|
|
3277
|
+
display: flex;
|
|
3278
|
+
justify-content: center;
|
|
3279
|
+
align-items: center;
|
|
3280
|
+
min-height: 100vh;
|
|
3281
|
+
-webkit-font-smoothing: antialiased;
|
|
3282
|
+
}
|
|
3283
|
+
.error {
|
|
3284
|
+
text-align: center;
|
|
3285
|
+
padding: 2rem;
|
|
3286
|
+
}
|
|
3287
|
+
h1 {
|
|
3288
|
+
font-size: 1.5rem;
|
|
3289
|
+
font-weight: 500;
|
|
3290
|
+
margin-bottom: 0.5rem;
|
|
3291
|
+
}
|
|
3292
|
+
p { color: #888; margin-bottom: 1.5rem; }
|
|
3293
|
+
a {
|
|
3294
|
+
color: #ededed;
|
|
3295
|
+
text-decoration: underline;
|
|
3296
|
+
text-underline-offset: 4px;
|
|
3297
|
+
}
|
|
3298
|
+
</style>
|
|
3299
|
+
</head>
|
|
3300
|
+
<body>
|
|
3301
|
+
<div class="error">
|
|
3302
|
+
<h1>Something went wrong</h1>
|
|
3303
|
+
<p>${escapeHtml(message)}</p>
|
|
3304
|
+
<a href="/">Back to leaderboard</a>
|
|
3305
|
+
</div>
|
|
3306
|
+
</body>
|
|
3307
|
+
</html>`;
|
|
3308
|
+
}
|
|
3309
|
+
__name(renderErrorPage, "renderErrorPage");
|
|
3310
|
+
function renderDocsPage() {
|
|
3311
|
+
return renderDocLayout("Getting Started", `
|
|
3312
|
+
<section class="doc-section">
|
|
3313
|
+
<h2>Installation</h2>
|
|
3314
|
+
<p>Install Skillmark globally or use npx:</p>
|
|
3315
|
+
<pre><code>npm install -g skillmark
|
|
3316
|
+
# or
|
|
3317
|
+
npx skillmark</code></pre>
|
|
3318
|
+
</section>
|
|
3319
|
+
|
|
3320
|
+
<section class="doc-section">
|
|
3321
|
+
<h2>Requirements</h2>
|
|
3322
|
+
<ul>
|
|
3323
|
+
<li><strong>Claude Code CLI</strong> - Skillmark runs benchmarks using Claude Code locally</li>
|
|
3324
|
+
<li><strong>Claude Max subscription</strong> - Required for Claude Code API access</li>
|
|
3325
|
+
</ul>
|
|
3326
|
+
<p>All benchmarks run 100% locally on your machine.</p>
|
|
3327
|
+
</section>
|
|
3328
|
+
|
|
3329
|
+
<section class="doc-section">
|
|
3330
|
+
<h2>Quick Start</h2>
|
|
3331
|
+
<p>Run your first benchmark in 3 steps:</p>
|
|
3332
|
+
|
|
3333
|
+
<h3>1. Test Files (Auto-generated)</h3>
|
|
3334
|
+
<p>Skillmark auto-generates test files based on your skill's SKILL.md. Just run:</p>
|
|
3335
|
+
<pre><code>skillmark run ./my-skill</code></pre>
|
|
3336
|
+
<p>Or create tests manually with YAML frontmatter:</p>
|
|
3337
|
+
<pre><code>---
|
|
3338
|
+
name: my-first-test
|
|
3339
|
+
type: knowledge
|
|
3340
|
+
concepts:
|
|
3341
|
+
- concept-one
|
|
3342
|
+
- concept-two
|
|
3343
|
+
timeout: 120
|
|
3344
|
+
---
|
|
3345
|
+
|
|
3346
|
+
# Prompt
|
|
3347
|
+
Your question or task here.
|
|
3348
|
+
|
|
3349
|
+
# Expected
|
|
3350
|
+
- [ ] First expected outcome
|
|
3351
|
+
- [ ] Second expected outcome</code></pre>
|
|
3352
|
+
|
|
3353
|
+
<h3>2. Run the benchmark</h3>
|
|
3354
|
+
<pre><code>skillmark run ./my-skill --tests ./tests --model sonnet --runs 3</code></pre>
|
|
3355
|
+
|
|
3356
|
+
<h3>3. View results</h3>
|
|
3357
|
+
<p>Results are saved to <code>./skillmark-results/</code>:</p>
|
|
3358
|
+
<ul>
|
|
3359
|
+
<li><code>result.json</code> - Machine-readable metrics</li>
|
|
3360
|
+
<li><code>report.md</code> - Human-readable report</li>
|
|
3361
|
+
</ul>
|
|
3362
|
+
</section>
|
|
3363
|
+
|
|
3364
|
+
<section class="doc-section">
|
|
3365
|
+
<h2>CLI Commands</h2>
|
|
3366
|
+
<table>
|
|
3367
|
+
<tr><td><code>skillmark run <skill></code></td><td>Run benchmark against a skill</td></tr>
|
|
3368
|
+
<tr><td><code>skillmark publish <result></code></td><td>Upload results to leaderboard</td></tr>
|
|
3369
|
+
<tr><td><code>skillmark leaderboard</code></td><td>View skill rankings</td></tr>
|
|
3370
|
+
</table>
|
|
3371
|
+
</section>
|
|
3372
|
+
|
|
3373
|
+
<section class="doc-section">
|
|
3374
|
+
<h2>Options</h2>
|
|
3375
|
+
<table>
|
|
3376
|
+
<tr><td><code>--tests <path></code></td><td>Path to test suite (default: ./tests)</td></tr>
|
|
3377
|
+
<tr><td><code>--model <model></code></td><td>haiku | sonnet | opus (default: opus)</td></tr>
|
|
3378
|
+
<tr><td><code>--runs <n></code></td><td>Number of iterations (default: 3)</td></tr>
|
|
3379
|
+
<tr><td><code>--output <dir></code></td><td>Output directory (default: ./skillmark-results)</td></tr>
|
|
3380
|
+
<tr><td><code>--publish</code></td><td>Auto-publish results to leaderboard</td></tr>
|
|
3381
|
+
</table>
|
|
3382
|
+
</section>
|
|
3383
|
+
|
|
3384
|
+
<section class="doc-section">
|
|
3385
|
+
<h2>Publishing Results</h2>
|
|
3386
|
+
<h3>1. Get API Key</h3>
|
|
3387
|
+
<p><a href="/login">Login with GitHub</a> to get your API key from the dashboard.</p>
|
|
3388
|
+
|
|
3389
|
+
<h3>2. Save API Key</h3>
|
|
3390
|
+
<pre><code># Option 1: Environment variable
|
|
3391
|
+
export SKILLMARK_API_KEY=sk_your_key
|
|
3392
|
+
|
|
3393
|
+
# Option 2: Config file
|
|
3394
|
+
echo "api_key=sk_your_key" > ~/.skillmarkrc</code></pre>
|
|
3395
|
+
|
|
3396
|
+
<h3>3. Publish</h3>
|
|
3397
|
+
<pre><code># Auto-publish after benchmark
|
|
3398
|
+
skillmark run ./my-skill --publish
|
|
3399
|
+
|
|
3400
|
+
# Or publish existing results
|
|
3401
|
+
skillmark publish ./skillmark-results/result.json</code></pre>
|
|
3402
|
+
</section>
|
|
3403
|
+
`);
|
|
3404
|
+
}
|
|
3405
|
+
__name(renderDocsPage, "renderDocsPage");
|
|
3406
|
+
function renderHowItWorksPage() {
|
|
3407
|
+
return renderDocLayout("How It Works", `
|
|
3408
|
+
<section class="doc-section">
|
|
3409
|
+
<h2>Overview</h2>
|
|
3410
|
+
<p>Skillmark benchmarks AI agent skills by running standardized tests and measuring key metrics:</p>
|
|
3411
|
+
<ul>
|
|
3412
|
+
<li><strong>Accuracy</strong> - Percentage of expected concepts matched</li>
|
|
3413
|
+
<li><strong>Tokens</strong> - Total tokens consumed (input + output). Lower = more efficient</li>
|
|
3414
|
+
<li><strong>Duration</strong> - Wall-clock execution time</li>
|
|
3415
|
+
<li><strong>Cost</strong> - Estimated API cost in USD</li>
|
|
3416
|
+
<li><strong>Tool Calls</strong> - Number of tool invocations</li>
|
|
3417
|
+
<li><strong>Model</strong> - Claude model used (haiku, sonnet, opus)</li>
|
|
3418
|
+
</ul>
|
|
3419
|
+
</section>
|
|
3420
|
+
|
|
3421
|
+
<section class="doc-section">
|
|
3422
|
+
<h2>Test Types</h2>
|
|
3423
|
+
<table>
|
|
3424
|
+
<tr><td><code>knowledge</code></td><td>Q&A style tests checking if response covers expected concepts</td></tr>
|
|
3425
|
+
<tr><td><code>task</code></td><td>Execution tests verifying tool usage and task completion</td></tr>
|
|
3426
|
+
</table>
|
|
3427
|
+
</section>
|
|
3428
|
+
|
|
3429
|
+
<section class="doc-section">
|
|
3430
|
+
<h2>Scoring</h2>
|
|
3431
|
+
<p>Accuracy is calculated by matching response content against expected concepts:</p>
|
|
3432
|
+
<pre><code>accuracy = (matched_concepts / total_concepts) \xD7 100%</code></pre>
|
|
3433
|
+
<p>The scorer uses fuzzy matching to handle variations like plurals, hyphens, and common abbreviations.</p>
|
|
3434
|
+
</section>
|
|
3435
|
+
|
|
3436
|
+
<section class="doc-section">
|
|
3437
|
+
<h2>Token Efficiency</h2>
|
|
3438
|
+
<p>Token usage is captured from Claude Code CLI transcript after each run:</p>
|
|
3439
|
+
<ul>
|
|
3440
|
+
<li><strong>Input tokens</strong> - Prompt + context sent to Claude</li>
|
|
3441
|
+
<li><strong>Output tokens</strong> - Claude's response + tool calls</li>
|
|
3442
|
+
<li><strong>Total tokens</strong> - Input + Output (used for efficiency ranking)</li>
|
|
3443
|
+
</ul>
|
|
3444
|
+
<p>Skills achieving same accuracy with fewer tokens rank higher in token efficiency.</p>
|
|
3445
|
+
</section>
|
|
3446
|
+
|
|
3447
|
+
<section class="doc-section">
|
|
3448
|
+
<h2>Skill Sources</h2>
|
|
3449
|
+
<p>Skillmark supports multiple skill sources:</p>
|
|
3450
|
+
<table>
|
|
3451
|
+
<tr><td><strong>Local</strong></td><td><code>./my-skill</code> or <code>~/.claude/skills/my-skill</code></td></tr>
|
|
3452
|
+
<tr><td><strong>Git</strong></td><td><code>https://github.com/user/skill-repo</code></td></tr>
|
|
3453
|
+
<tr><td><strong>skill.sh</strong></td><td><code>skill.sh/user/skill-name</code></td></tr>
|
|
3454
|
+
</table>
|
|
3455
|
+
</section>
|
|
3456
|
+
|
|
3457
|
+
<section class="doc-section">
|
|
3458
|
+
<h2>Publishing Results</h2>
|
|
3459
|
+
<p>Share your benchmark results on the public leaderboard:</p>
|
|
3460
|
+
<pre><code>skillmark publish ./skillmark-results/result.json --api-key YOUR_KEY</code></pre>
|
|
3461
|
+
<p>Results include a verification hash to prevent tampering.</p>
|
|
3462
|
+
</section>
|
|
3463
|
+
|
|
3464
|
+
<section class="doc-section">
|
|
3465
|
+
<h2>Architecture</h2>
|
|
3466
|
+
<pre><code>\u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510 \u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510 \u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510
|
|
3467
|
+
\u2502 CLI \u2502\u2500\u2500\u2500\u2500\u25B6\u2502 Claude \u2502\u2500\u2500\u2500\u2500\u25B6\u2502 Results \u2502
|
|
3468
|
+
\u2502 skillmark \u2502 \u2502 Engine \u2502 \u2502 JSON + MD \u2502
|
|
3469
|
+
\u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518 \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518 \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u252C\u2500\u2500\u2500\u2500\u2500\u2500\u2518
|
|
3470
|
+
\u2502
|
|
3471
|
+
\u25BC
|
|
3472
|
+
\u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510
|
|
3473
|
+
\u2502 Cloudflare \u2502
|
|
3474
|
+
\u2502 Workers+D1 \u2502
|
|
3475
|
+
\u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518</code></pre>
|
|
3476
|
+
</section>
|
|
3477
|
+
|
|
3478
|
+
<section class="doc-section">
|
|
3479
|
+
<h2>Enhanced Test Generation</h2>
|
|
3480
|
+
<p>Skillmark uses an enhanced test generation flow when no tests exist:</p>
|
|
3481
|
+
<pre><code>\u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510 \u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510
|
|
3482
|
+
\u2502 SKILL.md \u2502\u2500\u2500\u2500\u2500\u25B6\u2502 skill-creator + @claude-code-guide \u2502
|
|
3483
|
+
\u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518 \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518
|
|
3484
|
+
\u2502
|
|
3485
|
+
\u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510
|
|
3486
|
+
\u25BC (success) \u25BC (fails) \u2502
|
|
3487
|
+
\u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510 \u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510 \u2502
|
|
3488
|
+
\u2502 Enhanced \u2502 \u2502 Basic \u2502 \u2502
|
|
3489
|
+
\u2502 Prompt \u2502 \u2502 Prompt \u2502 \u2502
|
|
3490
|
+
\u2514\u2500\u2500\u2500\u2500\u2500\u2500\u252C\u2500\u2500\u2500\u2500\u2500\u2500\u2518 \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u252C\u2500\u2500\u2500\u2500\u2500\u2500\u2518 \u2502
|
|
3491
|
+
\u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u252C\u2500\u2500\u2500\u2500\u2518 \u2502
|
|
3492
|
+
\u25BC \u2502
|
|
3493
|
+
\u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510 \u2502
|
|
3494
|
+
\u2502 Test Files \u2502\u25C0\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518
|
|
3495
|
+
\u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518</code></pre>
|
|
3496
|
+
</section>
|
|
3497
|
+
|
|
3498
|
+
<section class="doc-section">
|
|
3499
|
+
<h2>skill-creator Skill</h2>
|
|
3500
|
+
<p>The <code>skill-creator</code> skill analyzes SKILL.md to extract structured metadata:</p>
|
|
3501
|
+
<table>
|
|
3502
|
+
<tr><td><strong>capabilities</strong></td><td>Core capabilities (3-6 items)</td></tr>
|
|
3503
|
+
<tr><td><strong>keyConcepts</strong></td><td>Key topics/keywords (5-10 items)</td></tr>
|
|
3504
|
+
<tr><td><strong>edgeCases</strong></td><td>Failure scenarios to test (3-5 items)</td></tr>
|
|
3505
|
+
<tr><td><strong>testingPatterns</strong></td><td>Claude Code testing best practices</td></tr>
|
|
3506
|
+
<tr><td><strong>toolInvocations</strong></td><td>Expected tool calls</td></tr>
|
|
3507
|
+
</table>
|
|
3508
|
+
<p>If skill-creator is not installed, Skillmark auto-installs it via:</p>
|
|
3509
|
+
<pre><code>npx skills add https://github.com/anthropics/claudekit-skills --skill skill-creator</code></pre>
|
|
3510
|
+
</section>
|
|
3511
|
+
|
|
3512
|
+
<section class="doc-section">
|
|
3513
|
+
<h2>claude-code-guide Subagent</h2>
|
|
3514
|
+
<p>The <code>@claude-code-guide</code> subagent provides Claude Code-specific testing patterns:</p>
|
|
3515
|
+
<ul>
|
|
3516
|
+
<li>Skill invocation patterns and best practices</li>
|
|
3517
|
+
<li>Common failure modes and edge cases</li>
|
|
3518
|
+
<li>Tool usage expectations (Read, Write, Bash, etc.)</li>
|
|
3519
|
+
<li>Testing patterns for knowledge vs task tests</li>
|
|
3520
|
+
</ul>
|
|
3521
|
+
<p>It's referenced via prompt engineering in skill-creator:</p>
|
|
3522
|
+
<pre><code>Use @"claude-code-guide (agent)" to understand Claude Code CLI patterns...</code></pre>
|
|
3523
|
+
<p>Claude's built-in subagent routing handles the reference automatically.</p>
|
|
3524
|
+
</section>
|
|
3525
|
+
|
|
3526
|
+
<section class="doc-section">
|
|
3527
|
+
<h2>Error Handling</h2>
|
|
3528
|
+
<p>Skillmark uses retry-then-degrade pattern for robustness:</p>
|
|
3529
|
+
<table>
|
|
3530
|
+
<tr><td><strong>skill-creator succeeds</strong></td><td>Enhanced prompt with analysis</td></tr>
|
|
3531
|
+
<tr><td><strong>skill-creator fails (1 retry)</strong></td><td>Degrades to basic prompt</td></tr>
|
|
3532
|
+
<tr><td><strong>Claude CLI fails</strong></td><td>Generates single fallback test</td></tr>
|
|
3533
|
+
</table>
|
|
3534
|
+
<p>This ensures test generation always succeeds, even if enhanced analysis fails.</p>
|
|
3535
|
+
</section>
|
|
3536
|
+
`);
|
|
3537
|
+
}
|
|
3538
|
+
__name(renderHowItWorksPage, "renderHowItWorksPage");
|
|
3539
|
+
function renderDocLayout(title, content) {
|
|
3540
|
+
return `<!DOCTYPE html>
|
|
3541
|
+
<html lang="en">
|
|
3542
|
+
<head>
|
|
3543
|
+
<meta charset="UTF-8">
|
|
3544
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
3545
|
+
<title>${title} - Skillmark</title>
|
|
3546
|
+
<link rel="icon" type="image/png" href="/favicon.png">
|
|
3547
|
+
<link href="https://fonts.googleapis.com/css2?family=Geist:wght@400;500;600&family=Geist+Mono:wght@400;500&display=swap" rel="stylesheet">
|
|
3548
|
+
<style>
|
|
3549
|
+
* { box-sizing: border-box; margin: 0; padding: 0; }
|
|
3550
|
+
:root { --bg: #000; --text: #ededed; --text-secondary: #888; --border: #333; }
|
|
3551
|
+
body { font-family: 'Geist', -apple-system, sans-serif; background: var(--bg); color: var(--text); line-height: 1.6; -webkit-font-smoothing: antialiased; }
|
|
3552
|
+
nav { display: flex; align-items: center; justify-content: space-between; padding: 1rem 1.5rem; border-bottom: 1px solid var(--border); }
|
|
3553
|
+
.nav-left { display: flex; align-items: center; gap: 0.5rem; }
|
|
3554
|
+
.nav-left a { color: var(--text); text-decoration: none; display: flex; align-items: center; gap: 0.5rem; }
|
|
3555
|
+
.nav-divider { color: var(--text-secondary); }
|
|
3556
|
+
.nav-right { display: flex; gap: 1.5rem; }
|
|
3557
|
+
.nav-right a { color: var(--text-secondary); text-decoration: none; font-size: 0.875rem; }
|
|
3558
|
+
.nav-right a:hover, .nav-right a.active { color: var(--text); }
|
|
3559
|
+
.container { max-width: 800px; margin: 0 auto; padding: 3rem 1.5rem; }
|
|
3560
|
+
h1 { font-size: 2.5rem; font-weight: 600; margin-bottom: 2rem; }
|
|
3561
|
+
.doc-section { margin-bottom: 3rem; }
|
|
3562
|
+
.doc-section h2 { font-size: 1.25rem; font-weight: 600; margin-bottom: 1rem; color: var(--text); }
|
|
3563
|
+
.doc-section h3 { font-size: 1rem; font-weight: 500; margin: 1.5rem 0 0.5rem; color: var(--text); }
|
|
3564
|
+
.doc-section p { color: var(--text-secondary); margin-bottom: 1rem; }
|
|
3565
|
+
.doc-section ul { color: var(--text-secondary); margin-left: 1.5rem; margin-bottom: 1rem; }
|
|
3566
|
+
.doc-section li { margin-bottom: 0.5rem; }
|
|
3567
|
+
.doc-section strong { color: var(--text); }
|
|
3568
|
+
pre { background: #0a0a0a; border: 1px solid var(--border); border-radius: 8px; padding: 1rem; overflow-x: auto; margin-bottom: 1rem; }
|
|
3569
|
+
code { font-family: 'Geist Mono', monospace; font-size: 0.875rem; }
|
|
3570
|
+
p code { background: #1a1a1a; padding: 0.125rem 0.375rem; border-radius: 4px; }
|
|
3571
|
+
table { width: 100%; border-collapse: collapse; margin-bottom: 1rem; }
|
|
3572
|
+
table td { padding: 0.75rem 0; border-bottom: 1px solid var(--border); color: var(--text-secondary); }
|
|
3573
|
+
table td:first-child { color: var(--text); width: 40%; }
|
|
3574
|
+
footer { margin-top: 3rem; padding: 2rem 0; border-top: 1px solid var(--border); text-align: center; color: var(--text-secondary); font-size: 0.8125rem; }
|
|
3575
|
+
footer a { color: var(--text); text-decoration: none; }
|
|
3576
|
+
</style>
|
|
3577
|
+
</head>
|
|
3578
|
+
<body>
|
|
3579
|
+
<nav>
|
|
3580
|
+
<div class="nav-left">
|
|
3581
|
+
<a href="/">
|
|
3582
|
+
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5"><path d="M22 12h-4l-3 9L9 3l-3 9H2"/></svg>
|
|
3583
|
+
<span>Skillmark</span>
|
|
3584
|
+
</a>
|
|
3585
|
+
</div>
|
|
3586
|
+
<div class="nav-right">
|
|
3587
|
+
<a href="/docs">Docs</a>
|
|
3588
|
+
<a href="/how-it-works">How It Works</a>
|
|
3589
|
+
<a href="https://github.com/claudekit/skillmark" title="GitHub"><svg width="18" height="18" viewBox="0 0 24 24" fill="currentColor"><path d="M12 0c-6.626 0-12 5.373-12 12 0 5.302 3.438 9.8 8.207 11.387.599.111.793-.261.793-.577v-2.234c-3.338.726-4.033-1.416-4.033-1.416-.546-1.387-1.333-1.756-1.333-1.756-1.089-.745.083-.729.083-.729 1.205.084 1.839 1.237 1.839 1.237 1.07 1.834 2.807 1.304 3.492.997.107-.775.418-1.305.762-1.604-2.665-.305-5.467-1.334-5.467-5.931 0-1.311.469-2.381 1.236-3.221-.124-.303-.535-1.524.117-3.176 0 0 1.008-.322 3.301 1.23.957-.266 1.983-.399 3.003-.404 1.02.005 2.047.138 3.006.404 2.291-1.552 3.297-1.23 3.297-1.23.653 1.653.242 2.874.118 3.176.77.84 1.235 1.911 1.235 3.221 0 4.609-2.807 5.624-5.479 5.921.43.372.823 1.102.823 2.222v3.293c0 .319.192.694.801.576 4.765-1.589 8.199-6.086 8.199-11.386 0-6.627-5.373-12-12-12z"/></svg></a>
|
|
3590
|
+
<a href="/login">Login</a>
|
|
3591
|
+
</div>
|
|
3592
|
+
</nav>
|
|
3593
|
+
<div class="container">
|
|
3594
|
+
<h1>${title}</h1>
|
|
3595
|
+
${content}
|
|
3596
|
+
<footer>
|
|
3597
|
+
<a href="https://github.com/claudekit/skillmark">Skillmark</a> \xB7 Built for AI agent developers \xB7 by <a href="https://claudekit.cc">ClaudeKit.cc</a>
|
|
3598
|
+
</footer>
|
|
3599
|
+
</div>
|
|
3600
|
+
</body>
|
|
3601
|
+
</html>`;
|
|
3602
|
+
}
|
|
3603
|
+
__name(renderDocLayout, "renderDocLayout");
|
|
3604
|
+
function renderSkillDetailPage(skill, results) {
|
|
3605
|
+
const latestResult = results[0];
|
|
3606
|
+
const skillshLink = latestResult?.skillshLink || skill.skillshLink;
|
|
3607
|
+
const resultRows = results.map((r, i) => `
|
|
3608
|
+
<tr>
|
|
3609
|
+
<td class="result-date">${r.createdAt ? formatRelativeTime(new Date(r.createdAt).getTime() / 1e3) : "-"}</td>
|
|
3610
|
+
<td class="result-model">${escapeHtml(r.model)}</td>
|
|
3611
|
+
<td class="result-accuracy">${r.accuracy.toFixed(1)}%</td>
|
|
3612
|
+
<td class="result-tokens">${r.tokensTotal?.toLocaleString() || "-"}</td>
|
|
3613
|
+
<td class="result-cost">$${r.costUsd?.toFixed(4) || "-"}</td>
|
|
3614
|
+
<td class="result-submitter">
|
|
3615
|
+
${r.submitterGithub ? `
|
|
3616
|
+
<a href="https://github.com/${escapeHtml(r.submitterGithub)}" class="submitter-link">
|
|
3617
|
+
<img src="https://github.com/${escapeHtml(r.submitterGithub)}.png?size=20" alt="" class="submitter-avatar-sm">
|
|
3618
|
+
@${escapeHtml(r.submitterGithub)}
|
|
3619
|
+
</a>
|
|
3620
|
+
` : "-"}
|
|
3621
|
+
</td>
|
|
3622
|
+
</tr>
|
|
3623
|
+
`).join("");
|
|
3624
|
+
const testFilesSection = latestResult?.testFiles?.length ? `
|
|
3625
|
+
<section class="test-files-section">
|
|
3626
|
+
<h2>Test Files</h2>
|
|
3627
|
+
<div class="test-files-tabs">
|
|
3628
|
+
${latestResult.testFiles.map((f, i) => `
|
|
3629
|
+
<button class="test-file-tab ${i === 0 ? "active" : ""}" data-index="${i}">${escapeHtml(f.name)}</button>
|
|
3630
|
+
`).join("")}
|
|
3631
|
+
</div>
|
|
3632
|
+
<div class="test-files-content">
|
|
3633
|
+
${latestResult.testFiles.map((f, i) => `
|
|
3634
|
+
<pre class="test-file-content ${i === 0 ? "active" : ""}" data-index="${i}"><code>${escapeHtml(f.content)}</code></pre>
|
|
3635
|
+
`).join("")}
|
|
3636
|
+
</div>
|
|
3637
|
+
</section>
|
|
3638
|
+
` : "";
|
|
3639
|
+
return `<!DOCTYPE html>
|
|
3640
|
+
<html lang="en">
|
|
3641
|
+
<head>
|
|
3642
|
+
<meta charset="UTF-8">
|
|
3643
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
3644
|
+
<title>${escapeHtml(skill.skillName)} - Skillmark</title>
|
|
3645
|
+
<link rel="icon" type="image/png" href="/favicon.png">
|
|
3646
|
+
<link href="https://fonts.googleapis.com/css2?family=Geist:wght@400;500;600&family=Geist+Mono:wght@400;500&display=swap" rel="stylesheet">
|
|
3647
|
+
<style>
|
|
3648
|
+
* { box-sizing: border-box; margin: 0; padding: 0; }
|
|
3649
|
+
:root { --bg: #000; --text: #ededed; --text-secondary: #888; --border: #333; }
|
|
3650
|
+
body { font-family: 'Geist', -apple-system, sans-serif; background: var(--bg); color: var(--text); line-height: 1.6; -webkit-font-smoothing: antialiased; }
|
|
3651
|
+
nav { display: flex; align-items: center; justify-content: space-between; padding: 1rem 1.5rem; border-bottom: 1px solid var(--border); }
|
|
3652
|
+
.nav-left { display: flex; align-items: center; gap: 0.5rem; }
|
|
3653
|
+
.nav-left a { color: var(--text); text-decoration: none; display: flex; align-items: center; gap: 0.5rem; }
|
|
3654
|
+
.nav-right { display: flex; gap: 1.5rem; }
|
|
3655
|
+
.nav-right a { color: var(--text-secondary); text-decoration: none; font-size: 0.875rem; }
|
|
3656
|
+
.nav-right a:hover { color: var(--text); }
|
|
3657
|
+
.container { max-width: 1000px; margin: 0 auto; padding: 3rem 1.5rem; }
|
|
3658
|
+
.breadcrumb { color: var(--text-secondary); font-size: 0.875rem; margin-bottom: 1rem; }
|
|
3659
|
+
.breadcrumb a { color: var(--text-secondary); text-decoration: none; }
|
|
3660
|
+
.breadcrumb a:hover { color: var(--text); }
|
|
3661
|
+
h1 { font-size: 2.5rem; font-weight: 600; margin-bottom: 0.5rem; }
|
|
3662
|
+
.skill-meta { display: flex; gap: 1.5rem; color: var(--text-secondary); font-size: 0.875rem; margin-bottom: 2rem; }
|
|
3663
|
+
.skill-meta a { color: #58a6ff; text-decoration: none; }
|
|
3664
|
+
.skill-meta a:hover { text-decoration: underline; }
|
|
3665
|
+
.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1.5rem; margin-bottom: 3rem; }
|
|
3666
|
+
.stat-card { background: #0a0a0a; border: 1px solid var(--border); border-radius: 8px; padding: 1.25rem; }
|
|
3667
|
+
.stat-label { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.1em; color: var(--text-secondary); margin-bottom: 0.5rem; }
|
|
3668
|
+
.stat-value { font-family: 'Geist Mono', monospace; font-size: 1.5rem; font-weight: 500; }
|
|
3669
|
+
.section { margin-bottom: 3rem; }
|
|
3670
|
+
.section h2 { font-size: 1rem; text-transform: uppercase; letter-spacing: 0.1em; color: var(--text-secondary); margin-bottom: 1rem; }
|
|
3671
|
+
.results-table { width: 100%; border-collapse: collapse; }
|
|
3672
|
+
.results-table th { text-align: left; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.1em; color: var(--text-secondary); font-weight: 500; padding: 0.75rem 0; border-bottom: 1px solid var(--border); }
|
|
3673
|
+
.results-table td { padding: 0.75rem 0; border-bottom: 1px solid var(--border); font-size: 0.875rem; }
|
|
3674
|
+
.result-accuracy { font-family: 'Geist Mono', monospace; font-weight: 500; }
|
|
3675
|
+
.result-tokens, .result-cost { font-family: 'Geist Mono', monospace; color: var(--text-secondary); }
|
|
3676
|
+
.submitter-link { display: flex; align-items: center; gap: 0.375rem; color: var(--text-secondary); text-decoration: none; font-size: 0.8125rem; }
|
|
3677
|
+
.submitter-link:hover { color: var(--text); }
|
|
3678
|
+
.submitter-avatar-sm { width: 16px; height: 16px; border-radius: 50%; }
|
|
3679
|
+
.test-files-section { background: #0a0a0a; border: 1px solid var(--border); border-radius: 8px; padding: 1.5rem; }
|
|
3680
|
+
.test-files-section h2 { margin-bottom: 1rem; }
|
|
3681
|
+
.test-files-tabs { display: flex; gap: 0.5rem; margin-bottom: 1rem; flex-wrap: wrap; }
|
|
3682
|
+
.test-file-tab { background: transparent; border: 1px solid var(--border); color: var(--text-secondary); padding: 0.5rem 1rem; border-radius: 6px; cursor: pointer; font-family: 'Geist Mono', monospace; font-size: 0.8125rem; }
|
|
3683
|
+
.test-file-tab:hover { border-color: var(--text-secondary); }
|
|
3684
|
+
.test-file-tab.active { background: var(--text); color: var(--bg); border-color: var(--text); }
|
|
3685
|
+
.test-file-content { display: none; background: #000; border: 1px solid var(--border); border-radius: 6px; padding: 1rem; overflow-x: auto; max-height: 400px; overflow-y: auto; }
|
|
3686
|
+
.test-file-content.active { display: block; }
|
|
3687
|
+
.test-file-content code { font-family: 'Geist Mono', monospace; font-size: 0.8125rem; white-space: pre-wrap; }
|
|
3688
|
+
footer { margin-top: 3rem; padding: 2rem 0; border-top: 1px solid var(--border); text-align: center; color: var(--text-secondary); font-size: 0.8125rem; }
|
|
3689
|
+
footer a { color: var(--text); text-decoration: none; }
|
|
3690
|
+
@media (max-width: 768px) {
|
|
3691
|
+
.stats-grid { grid-template-columns: repeat(2, 1fr); }
|
|
3692
|
+
.results-table { font-size: 0.8125rem; }
|
|
3693
|
+
}
|
|
3694
|
+
</style>
|
|
3695
|
+
</head>
|
|
3696
|
+
<body>
|
|
3697
|
+
<nav>
|
|
3698
|
+
<div class="nav-left">
|
|
3699
|
+
<a href="/">
|
|
3700
|
+
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5"><path d="M22 12h-4l-3 9L9 3l-3 9H2"/></svg>
|
|
3701
|
+
<span>Skillmark</span>
|
|
3702
|
+
</a>
|
|
3703
|
+
</div>
|
|
3704
|
+
<div class="nav-right">
|
|
3705
|
+
<a href="/docs">Docs</a>
|
|
3706
|
+
<a href="/how-it-works">How It Works</a>
|
|
3707
|
+
<a href="https://github.com/claudekit/skillmark" title="GitHub"><svg width="18" height="18" viewBox="0 0 24 24" fill="currentColor"><path d="M12 0c-6.626 0-12 5.373-12 12 0 5.302 3.438 9.8 8.207 11.387.599.111.793-.261.793-.577v-2.234c-3.338.726-4.033-1.416-4.033-1.416-.546-1.387-1.333-1.756-1.333-1.756-1.089-.745.083-.729.083-.729 1.205.084 1.839 1.237 1.839 1.237 1.07 1.834 2.807 1.304 3.492.997.107-.775.418-1.305.762-1.604-2.665-.305-5.467-1.334-5.467-5.931 0-1.311.469-2.381 1.236-3.221-.124-.303-.535-1.524.117-3.176 0 0 1.008-.322 3.301 1.23.957-.266 1.983-.399 3.003-.404 1.02.005 2.047.138 3.006.404 2.291-1.552 3.297-1.23 3.297-1.23.653 1.653.242 2.874.118 3.176.77.84 1.235 1.911 1.235 3.221 0 4.609-2.807 5.624-5.479 5.921.43.372.823 1.102.823 2.222v3.293c0 .319.192.694.801.576 4.765-1.589 8.199-6.086 8.199-11.386 0-6.627-5.373-12-12-12z"/></svg></a>
|
|
3708
|
+
<a href="/login">Login</a>
|
|
3709
|
+
</div>
|
|
3710
|
+
</nav>
|
|
3711
|
+
<div class="container">
|
|
3712
|
+
<div class="breadcrumb">
|
|
3713
|
+
<a href="/">Leaderboard</a> / ${escapeHtml(skill.skillName)}
|
|
3714
|
+
</div>
|
|
3715
|
+
<h1>${escapeHtml(skill.skillName)}</h1>
|
|
3716
|
+
<div class="skill-meta">
|
|
3717
|
+
${skill.source ? `<span>Source: <a href="${escapeHtml(skill.source)}">${escapeHtml(skill.source.replace("https://github.com/", ""))}</a></span>` : ""}
|
|
3718
|
+
${skillshLink ? `<span><a href="${escapeHtml(skillshLink)}">View on skill.sh</a></span>` : ""}
|
|
3719
|
+
</div>
|
|
3720
|
+
|
|
3721
|
+
<div class="stats-grid">
|
|
3722
|
+
<div class="stat-card">
|
|
3723
|
+
<div class="stat-label">Best Accuracy</div>
|
|
3724
|
+
<div class="stat-value">${skill.bestAccuracy.toFixed(1)}%</div>
|
|
3725
|
+
</div>
|
|
3726
|
+
<div class="stat-card">
|
|
3727
|
+
<div class="stat-label">Best Model</div>
|
|
3728
|
+
<div class="stat-value">${escapeHtml(skill.bestModel)}</div>
|
|
3729
|
+
</div>
|
|
3730
|
+
<div class="stat-card">
|
|
3731
|
+
<div class="stat-label">Avg Tokens</div>
|
|
3732
|
+
<div class="stat-value">${Math.round(skill.avgTokens).toLocaleString()}</div>
|
|
3733
|
+
</div>
|
|
3734
|
+
<div class="stat-card">
|
|
3735
|
+
<div class="stat-label">Total Runs</div>
|
|
3736
|
+
<div class="stat-value">${skill.totalRuns}</div>
|
|
3737
|
+
</div>
|
|
3738
|
+
</div>
|
|
3739
|
+
|
|
3740
|
+
<section class="section">
|
|
3741
|
+
<h2>Result History</h2>
|
|
3742
|
+
<table class="results-table">
|
|
3743
|
+
<thead>
|
|
3744
|
+
<tr>
|
|
3745
|
+
<th>Date</th>
|
|
3746
|
+
<th>Model</th>
|
|
3747
|
+
<th>Accuracy</th>
|
|
3748
|
+
<th>Tokens</th>
|
|
3749
|
+
<th>Cost</th>
|
|
3750
|
+
<th>Submitter</th>
|
|
3751
|
+
</tr>
|
|
3752
|
+
</thead>
|
|
3753
|
+
<tbody>
|
|
3754
|
+
${resultRows}
|
|
3755
|
+
</tbody>
|
|
3756
|
+
</table>
|
|
3757
|
+
</section>
|
|
3758
|
+
|
|
3759
|
+
${testFilesSection}
|
|
3760
|
+
|
|
3761
|
+
<footer>
|
|
3762
|
+
<a href="https://github.com/claudekit/skillmark">Skillmark</a> \xB7 Built for AI agent developers \xB7 by <a href="https://claudekit.cc">ClaudeKit.cc</a>
|
|
3763
|
+
</footer>
|
|
3764
|
+
</div>
|
|
3765
|
+
|
|
3766
|
+
<script>
|
|
3767
|
+
// Test file tab switching
|
|
3768
|
+
document.querySelectorAll('.test-file-tab').forEach(tab => {
|
|
3769
|
+
tab.addEventListener('click', () => {
|
|
3770
|
+
const index = tab.dataset.index;
|
|
3771
|
+
document.querySelectorAll('.test-file-tab').forEach(t => t.classList.remove('active'));
|
|
3772
|
+
document.querySelectorAll('.test-file-content').forEach(c => c.classList.remove('active'));
|
|
3773
|
+
tab.classList.add('active');
|
|
3774
|
+
document.querySelector('.test-file-content[data-index="' + index + '"]').classList.add('active');
|
|
3775
|
+
});
|
|
3776
|
+
});
|
|
3777
|
+
<\/script>
|
|
3778
|
+
</body>
|
|
3779
|
+
</html>`;
|
|
3780
|
+
}
|
|
3781
|
+
__name(renderSkillDetailPage, "renderSkillDetailPage");
|
|
3782
|
+
function renderLoginPage(error) {
|
|
3783
|
+
const errorMessage = error ? `
|
|
3784
|
+
<div class="error-message">
|
|
3785
|
+
${error === "oauth_failed" ? "GitHub authentication failed. Please try again." : error === "token_failed" ? "Failed to authenticate with GitHub. Please try again." : "An error occurred. Please try again."}
|
|
3786
|
+
</div>
|
|
3787
|
+
` : "";
|
|
3788
|
+
return `<!DOCTYPE html>
|
|
3789
|
+
<html lang="en">
|
|
3790
|
+
<head>
|
|
3791
|
+
<meta charset="UTF-8">
|
|
3792
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
3793
|
+
<title>Login - Skillmark</title>
|
|
3794
|
+
<link rel="icon" type="image/png" href="/favicon.png">
|
|
3795
|
+
<link href="https://fonts.googleapis.com/css2?family=Geist:wght@400;500;600&family=Geist+Mono:wght@400;500&display=swap" rel="stylesheet">
|
|
3796
|
+
<style>
|
|
3797
|
+
* { box-sizing: border-box; margin: 0; padding: 0; }
|
|
3798
|
+
:root { --bg: #000; --text: #ededed; --text-secondary: #888; --border: #333; }
|
|
3799
|
+
body {
|
|
3800
|
+
font-family: 'Geist', -apple-system, sans-serif;
|
|
3801
|
+
background: var(--bg);
|
|
3802
|
+
color: var(--text);
|
|
3803
|
+
min-height: 100vh;
|
|
3804
|
+
display: flex;
|
|
3805
|
+
flex-direction: column;
|
|
3806
|
+
-webkit-font-smoothing: antialiased;
|
|
3807
|
+
}
|
|
3808
|
+
nav { display: flex; align-items: center; justify-content: space-between; padding: 1rem 1.5rem; border-bottom: 1px solid var(--border); }
|
|
3809
|
+
.nav-left { display: flex; align-items: center; gap: 0.5rem; }
|
|
3810
|
+
.nav-left a { color: var(--text); text-decoration: none; display: flex; align-items: center; gap: 0.5rem; }
|
|
3811
|
+
.login-container {
|
|
3812
|
+
flex: 1;
|
|
3813
|
+
display: flex;
|
|
3814
|
+
flex-direction: column;
|
|
3815
|
+
align-items: center;
|
|
3816
|
+
justify-content: center;
|
|
3817
|
+
padding: 2rem;
|
|
3818
|
+
}
|
|
3819
|
+
.login-box {
|
|
3820
|
+
max-width: 400px;
|
|
3821
|
+
width: 100%;
|
|
3822
|
+
text-align: center;
|
|
3823
|
+
}
|
|
3824
|
+
h1 { font-size: 2rem; font-weight: 600; margin-bottom: 0.5rem; }
|
|
3825
|
+
.subtitle { color: var(--text-secondary); margin-bottom: 2rem; }
|
|
3826
|
+
.github-btn {
|
|
3827
|
+
display: flex;
|
|
3828
|
+
align-items: center;
|
|
3829
|
+
justify-content: center;
|
|
3830
|
+
gap: 0.75rem;
|
|
3831
|
+
width: 100%;
|
|
3832
|
+
padding: 0.875rem 1.5rem;
|
|
3833
|
+
background: #ededed;
|
|
3834
|
+
color: #000;
|
|
3835
|
+
border: none;
|
|
3836
|
+
border-radius: 8px;
|
|
3837
|
+
font-family: inherit;
|
|
3838
|
+
font-size: 1rem;
|
|
3839
|
+
font-weight: 500;
|
|
3840
|
+
cursor: pointer;
|
|
3841
|
+
text-decoration: none;
|
|
3842
|
+
transition: background 0.15s;
|
|
3843
|
+
}
|
|
3844
|
+
.github-btn:hover { background: #fff; }
|
|
3845
|
+
.github-btn svg { width: 20px; height: 20px; }
|
|
3846
|
+
.error-message {
|
|
3847
|
+
background: rgba(248, 81, 73, 0.1);
|
|
3848
|
+
border: 1px solid rgba(248, 81, 73, 0.3);
|
|
3849
|
+
color: #f85149;
|
|
3850
|
+
padding: 0.75rem 1rem;
|
|
3851
|
+
border-radius: 8px;
|
|
3852
|
+
margin-bottom: 1.5rem;
|
|
3853
|
+
font-size: 0.875rem;
|
|
3854
|
+
}
|
|
3855
|
+
.info-text {
|
|
3856
|
+
margin-top: 2rem;
|
|
3857
|
+
color: var(--text-secondary);
|
|
3858
|
+
font-size: 0.875rem;
|
|
3859
|
+
}
|
|
3860
|
+
.info-text a { color: var(--text); }
|
|
3861
|
+
</style>
|
|
3862
|
+
</head>
|
|
3863
|
+
<body>
|
|
3864
|
+
<nav>
|
|
3865
|
+
<div class="nav-left">
|
|
3866
|
+
<a href="/">
|
|
3867
|
+
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5"><path d="M22 12h-4l-3 9L9 3l-3 9H2"/></svg>
|
|
3868
|
+
<span>Skillmark</span>
|
|
3869
|
+
</a>
|
|
3870
|
+
</div>
|
|
3871
|
+
</nav>
|
|
3872
|
+
<div class="login-container">
|
|
3873
|
+
<div class="login-box">
|
|
3874
|
+
<h1>Sign in</h1>
|
|
3875
|
+
<p class="subtitle">Get an API key to publish benchmark results</p>
|
|
3876
|
+
${errorMessage}
|
|
3877
|
+
<a href="/auth/github" class="github-btn">
|
|
3878
|
+
<svg viewBox="0 0 24 24" fill="currentColor">
|
|
3879
|
+
<path d="M12 0c-6.626 0-12 5.373-12 12 0 5.302 3.438 9.8 8.207 11.387.599.111.793-.261.793-.577v-2.234c-3.338.726-4.033-1.416-4.033-1.416-.546-1.387-1.333-1.756-1.333-1.756-1.089-.745.083-.729.083-.729 1.205.084 1.839 1.237 1.839 1.237 1.07 1.834 2.807 1.304 3.492.997.107-.775.418-1.305.762-1.604-2.665-.305-5.467-1.334-5.467-5.931 0-1.311.469-2.381 1.236-3.221-.124-.303-.535-1.524.117-3.176 0 0 1.008-.322 3.301 1.23.957-.266 1.983-.399 3.003-.404 1.02.005 2.047.138 3.006.404 2.291-1.552 3.297-1.23 3.297-1.23.653 1.653.242 2.874.118 3.176.77.84 1.235 1.911 1.235 3.221 0 4.609-2.807 5.624-5.479 5.921.43.372.823 1.102.823 2.222v3.293c0 .319.192.694.801.576 4.765-1.589 8.199-6.086 8.199-11.386 0-6.627-5.373-12-12-12z"/>
|
|
3880
|
+
</svg>
|
|
3881
|
+
Continue with GitHub
|
|
3882
|
+
</a>
|
|
3883
|
+
<p class="info-text">
|
|
3884
|
+
By signing in, you agree to our <a href="/docs">Terms of Service</a>.
|
|
3885
|
+
</p>
|
|
3886
|
+
</div>
|
|
3887
|
+
</div>
|
|
3888
|
+
</body>
|
|
3889
|
+
</html>`;
|
|
3890
|
+
}
|
|
3891
|
+
__name(renderLoginPage, "renderLoginPage");
|
|
3892
|
+
function renderDashboardPage(user) {
|
|
3893
|
+
const keyRows = user.keys.map((key) => `
|
|
3894
|
+
<tr data-key-id="${escapeHtml(key.id)}">
|
|
3895
|
+
<td class="key-id">
|
|
3896
|
+
<code>${escapeHtml(key.id.slice(0, 8))}...</code>
|
|
3897
|
+
</td>
|
|
3898
|
+
<td class="key-created">${key.createdAt ? formatRelativeTime(new Date(key.createdAt).getTime() / 1e3) : "Unknown"}</td>
|
|
3899
|
+
<td class="key-used">${key.lastUsedAt ? formatRelativeTime(new Date(key.lastUsedAt).getTime() / 1e3) : "Never"}</td>
|
|
3900
|
+
<td class="key-actions">
|
|
3901
|
+
<button class="revoke-btn" onclick="revokeKey('${escapeHtml(key.id)}')">Revoke</button>
|
|
3902
|
+
</td>
|
|
3903
|
+
</tr>
|
|
3904
|
+
`).join("");
|
|
3905
|
+
return `<!DOCTYPE html>
|
|
3906
|
+
<html lang="en">
|
|
3907
|
+
<head>
|
|
3908
|
+
<meta charset="UTF-8">
|
|
3909
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
3910
|
+
<title>Dashboard - Skillmark</title>
|
|
3911
|
+
<link rel="icon" type="image/png" href="/favicon.png">
|
|
3912
|
+
<link href="https://fonts.googleapis.com/css2?family=Geist:wght@400;500;600&family=Geist+Mono:wght@400;500&display=swap" rel="stylesheet">
|
|
3913
|
+
<style>
|
|
3914
|
+
* { box-sizing: border-box; margin: 0; padding: 0; }
|
|
3915
|
+
:root { --bg: #000; --text: #ededed; --text-secondary: #888; --border: #333; --success: #3fb950; }
|
|
3916
|
+
body {
|
|
3917
|
+
font-family: 'Geist', -apple-system, sans-serif;
|
|
3918
|
+
background: var(--bg);
|
|
3919
|
+
color: var(--text);
|
|
3920
|
+
min-height: 100vh;
|
|
3921
|
+
-webkit-font-smoothing: antialiased;
|
|
3922
|
+
}
|
|
3923
|
+
nav { display: flex; align-items: center; justify-content: space-between; padding: 1rem 1.5rem; border-bottom: 1px solid var(--border); }
|
|
3924
|
+
.nav-left { display: flex; align-items: center; gap: 0.5rem; }
|
|
3925
|
+
.nav-left a { color: var(--text); text-decoration: none; display: flex; align-items: center; gap: 0.5rem; }
|
|
3926
|
+
.nav-right { display: flex; align-items: center; gap: 1rem; }
|
|
3927
|
+
.nav-right a { color: var(--text-secondary); text-decoration: none; font-size: 0.875rem; }
|
|
3928
|
+
.nav-right a:hover { color: var(--text); }
|
|
3929
|
+
.user-info { display: flex; align-items: center; gap: 0.5rem; }
|
|
3930
|
+
.user-avatar { width: 28px; height: 28px; border-radius: 50%; }
|
|
3931
|
+
.user-name { font-size: 0.875rem; }
|
|
3932
|
+
.container { max-width: 800px; margin: 0 auto; padding: 3rem 1.5rem; }
|
|
3933
|
+
h1 { font-size: 2rem; font-weight: 600; margin-bottom: 0.5rem; }
|
|
3934
|
+
.subtitle { color: var(--text-secondary); margin-bottom: 2rem; }
|
|
3935
|
+
.section { margin-bottom: 3rem; }
|
|
3936
|
+
.section h2 { font-size: 1rem; font-weight: 500; margin-bottom: 1rem; text-transform: uppercase; letter-spacing: 0.1em; color: var(--text-secondary); }
|
|
3937
|
+
.generate-btn {
|
|
3938
|
+
display: inline-flex;
|
|
3939
|
+
align-items: center;
|
|
3940
|
+
gap: 0.5rem;
|
|
3941
|
+
padding: 0.75rem 1.25rem;
|
|
3942
|
+
background: var(--text);
|
|
3943
|
+
color: var(--bg);
|
|
3944
|
+
border: none;
|
|
3945
|
+
border-radius: 8px;
|
|
3946
|
+
font-family: inherit;
|
|
3947
|
+
font-size: 0.875rem;
|
|
3948
|
+
font-weight: 500;
|
|
3949
|
+
cursor: pointer;
|
|
3950
|
+
margin-bottom: 1.5rem;
|
|
3951
|
+
}
|
|
3952
|
+
.generate-btn:hover { background: #fff; }
|
|
3953
|
+
.generate-btn:disabled { opacity: 0.5; cursor: not-allowed; }
|
|
3954
|
+
.new-key-display {
|
|
3955
|
+
display: none;
|
|
3956
|
+
background: rgba(63, 185, 80, 0.1);
|
|
3957
|
+
border: 1px solid rgba(63, 185, 80, 0.3);
|
|
3958
|
+
border-radius: 8px;
|
|
3959
|
+
padding: 1rem;
|
|
3960
|
+
margin-bottom: 1.5rem;
|
|
3961
|
+
}
|
|
3962
|
+
.new-key-display.visible { display: block; }
|
|
3963
|
+
.new-key-display p { color: var(--text-secondary); font-size: 0.875rem; margin-bottom: 0.75rem; }
|
|
3964
|
+
.new-key-display .key-value {
|
|
3965
|
+
display: flex;
|
|
3966
|
+
align-items: center;
|
|
3967
|
+
gap: 0.5rem;
|
|
3968
|
+
background: #0a0a0a;
|
|
3969
|
+
padding: 0.75rem;
|
|
3970
|
+
border-radius: 6px;
|
|
3971
|
+
font-family: 'Geist Mono', monospace;
|
|
3972
|
+
font-size: 0.8125rem;
|
|
3973
|
+
word-break: break-all;
|
|
3974
|
+
}
|
|
3975
|
+
.copy-btn {
|
|
3976
|
+
flex-shrink: 0;
|
|
3977
|
+
background: none;
|
|
3978
|
+
border: 1px solid var(--border);
|
|
3979
|
+
color: var(--text-secondary);
|
|
3980
|
+
padding: 0.25rem 0.5rem;
|
|
3981
|
+
border-radius: 4px;
|
|
3982
|
+
cursor: pointer;
|
|
3983
|
+
font-size: 0.75rem;
|
|
3984
|
+
}
|
|
3985
|
+
.copy-btn:hover { color: var(--text); border-color: var(--text-secondary); }
|
|
3986
|
+
.done-btn {
|
|
3987
|
+
flex-shrink: 0;
|
|
3988
|
+
background: var(--success);
|
|
3989
|
+
border: none;
|
|
3990
|
+
color: #000;
|
|
3991
|
+
padding: 0.25rem 0.75rem;
|
|
3992
|
+
border-radius: 4px;
|
|
3993
|
+
cursor: pointer;
|
|
3994
|
+
font-size: 0.75rem;
|
|
3995
|
+
font-weight: 500;
|
|
3996
|
+
}
|
|
3997
|
+
.done-btn:hover { opacity: 0.9; }
|
|
3998
|
+
.keys-table { width: 100%; border-collapse: collapse; }
|
|
3999
|
+
.keys-table th {
|
|
4000
|
+
text-align: left;
|
|
4001
|
+
font-size: 0.75rem;
|
|
4002
|
+
text-transform: uppercase;
|
|
4003
|
+
letter-spacing: 0.1em;
|
|
4004
|
+
color: var(--text-secondary);
|
|
4005
|
+
font-weight: 500;
|
|
4006
|
+
padding: 0.75rem 0;
|
|
4007
|
+
border-bottom: 1px solid var(--border);
|
|
4008
|
+
}
|
|
4009
|
+
.keys-table td { padding: 1rem 0; border-bottom: 1px solid var(--border); }
|
|
4010
|
+
.keys-table code { font-family: 'Geist Mono', monospace; font-size: 0.8125rem; }
|
|
4011
|
+
.key-created, .key-used { color: var(--text-secondary); font-size: 0.875rem; }
|
|
4012
|
+
.revoke-btn {
|
|
4013
|
+
background: none;
|
|
4014
|
+
border: 1px solid #f85149;
|
|
4015
|
+
color: #f85149;
|
|
4016
|
+
padding: 0.375rem 0.75rem;
|
|
4017
|
+
border-radius: 6px;
|
|
4018
|
+
font-size: 0.8125rem;
|
|
4019
|
+
cursor: pointer;
|
|
4020
|
+
}
|
|
4021
|
+
.revoke-btn:hover { background: rgba(248, 81, 73, 0.1); }
|
|
4022
|
+
.empty-state { color: var(--text-secondary); padding: 2rem 0; }
|
|
4023
|
+
.usage-section { background: #0a0a0a; border: 1px solid var(--border); border-radius: 8px; padding: 1.5rem; }
|
|
4024
|
+
.usage-section h3 { font-size: 0.875rem; font-weight: 500; margin-bottom: 1rem; }
|
|
4025
|
+
.usage-section pre { background: #000; border: 1px solid var(--border); border-radius: 6px; padding: 1rem; overflow-x: auto; margin-bottom: 0.75rem; }
|
|
4026
|
+
.usage-section code { font-family: 'Geist Mono', monospace; font-size: 0.8125rem; }
|
|
4027
|
+
.usage-section p { color: var(--text-secondary); font-size: 0.8125rem; }
|
|
4028
|
+
</style>
|
|
4029
|
+
</head>
|
|
4030
|
+
<body>
|
|
4031
|
+
<nav>
|
|
4032
|
+
<div class="nav-left">
|
|
4033
|
+
<a href="/">
|
|
4034
|
+
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5"><path d="M22 12h-4l-3 9L9 3l-3 9H2"/></svg>
|
|
4035
|
+
<span>Skillmark</span>
|
|
4036
|
+
</a>
|
|
4037
|
+
</div>
|
|
4038
|
+
<div class="nav-right">
|
|
4039
|
+
<div class="user-info">
|
|
4040
|
+
${user.avatar ? `<img src="${escapeHtml(user.avatar)}" alt="" class="user-avatar">` : ""}
|
|
4041
|
+
<span class="user-name">${escapeHtml(user.username)}</span>
|
|
4042
|
+
</div>
|
|
4043
|
+
<a href="/auth/logout">Sign out</a>
|
|
4044
|
+
</div>
|
|
4045
|
+
</nav>
|
|
4046
|
+
<div class="container">
|
|
4047
|
+
<h1>Dashboard</h1>
|
|
4048
|
+
<p class="subtitle">Manage your API keys for publishing benchmark results</p>
|
|
4049
|
+
|
|
4050
|
+
<div class="section">
|
|
4051
|
+
<h2>API Keys</h2>
|
|
4052
|
+
<button class="generate-btn" id="generateBtn" onclick="generateKey()">
|
|
4053
|
+
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><line x1="12" y1="5" x2="12" y2="19"></line><line x1="5" y1="12" x2="19" y2="12"></line></svg>
|
|
4054
|
+
Generate New Key
|
|
4055
|
+
</button>
|
|
4056
|
+
|
|
4057
|
+
<div class="new-key-display" id="newKeyDisplay">
|
|
4058
|
+
<p><strong>New API key created!</strong> Copy it now - you won't see it again.</p>
|
|
4059
|
+
<div class="key-value">
|
|
4060
|
+
<code id="newKeyValue"></code>
|
|
4061
|
+
<button class="copy-btn" onclick="copyKey()">Copy</button>
|
|
4062
|
+
<button class="done-btn" onclick="location.reload()">Done</button>
|
|
4063
|
+
</div>
|
|
4064
|
+
</div>
|
|
4065
|
+
|
|
4066
|
+
${user.keys.length > 0 ? `
|
|
4067
|
+
<table class="keys-table">
|
|
4068
|
+
<thead>
|
|
4069
|
+
<tr>
|
|
4070
|
+
<th>Key ID</th>
|
|
4071
|
+
<th>Created</th>
|
|
4072
|
+
<th>Last Used</th>
|
|
4073
|
+
<th></th>
|
|
4074
|
+
</tr>
|
|
4075
|
+
</thead>
|
|
4076
|
+
<tbody id="keysTableBody">
|
|
4077
|
+
${keyRows}
|
|
4078
|
+
</tbody>
|
|
4079
|
+
</table>
|
|
4080
|
+
` : `
|
|
4081
|
+
<p class="empty-state">No API keys yet. Generate one to start publishing benchmarks.</p>
|
|
4082
|
+
`}
|
|
4083
|
+
</div>
|
|
4084
|
+
|
|
4085
|
+
<div class="section">
|
|
4086
|
+
<h2>Usage</h2>
|
|
4087
|
+
<div class="usage-section">
|
|
4088
|
+
<h3>Save your API key</h3>
|
|
4089
|
+
<pre><code># Option 1: Environment variable
|
|
4090
|
+
export SKILLMARK_API_KEY=sk_your_key_here
|
|
4091
|
+
|
|
4092
|
+
# Option 2: Config file (~/.skillmarkrc)
|
|
4093
|
+
echo "api_key=sk_your_key_here" > ~/.skillmarkrc</code></pre>
|
|
4094
|
+
<p>The CLI reads from env var first, then ~/.skillmarkrc.</p>
|
|
4095
|
+
</div>
|
|
4096
|
+
</div>
|
|
4097
|
+
|
|
4098
|
+
<div class="section">
|
|
4099
|
+
<div class="usage-section">
|
|
4100
|
+
<h3>Publish with auto-publish flag</h3>
|
|
4101
|
+
<pre><code># Run benchmark and auto-publish results
|
|
4102
|
+
skillmark run ./my-skill --publish
|
|
4103
|
+
|
|
4104
|
+
# Or publish existing results
|
|
4105
|
+
skillmark publish ./skillmark-results/result.json</code></pre>
|
|
4106
|
+
</div>
|
|
4107
|
+
</div>
|
|
4108
|
+
</div>
|
|
4109
|
+
|
|
4110
|
+
<script>
|
|
4111
|
+
async function generateKey() {
|
|
4112
|
+
const btn = document.getElementById('generateBtn');
|
|
4113
|
+
btn.disabled = true;
|
|
4114
|
+
btn.textContent = 'Generating...';
|
|
4115
|
+
|
|
4116
|
+
try {
|
|
4117
|
+
const res = await fetch('/auth/keys', { method: 'POST' });
|
|
4118
|
+
const data = await res.json();
|
|
4119
|
+
|
|
4120
|
+
if (data.apiKey) {
|
|
4121
|
+
document.getElementById('newKeyValue').textContent = data.apiKey;
|
|
4122
|
+
document.getElementById('newKeyDisplay').classList.add('visible');
|
|
4123
|
+
btn.style.display = 'none';
|
|
4124
|
+
} else {
|
|
4125
|
+
alert('Failed to generate key: ' + (data.error || 'Unknown error'));
|
|
4126
|
+
}
|
|
4127
|
+
} catch (err) {
|
|
4128
|
+
alert('Failed to generate key: ' + err.message);
|
|
4129
|
+
} finally {
|
|
4130
|
+
btn.disabled = false;
|
|
4131
|
+
btn.innerHTML = '<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><line x1="12" y1="5" x2="12" y2="19"></line><line x1="5" y1="12" x2="19" y2="12"></line></svg> Generate New Key';
|
|
4132
|
+
}
|
|
4133
|
+
}
|
|
4134
|
+
|
|
4135
|
+
function copyKey() {
|
|
4136
|
+
const key = document.getElementById('newKeyValue').textContent;
|
|
4137
|
+
navigator.clipboard.writeText(key).then(() => {
|
|
4138
|
+
const btn = event.target;
|
|
4139
|
+
btn.textContent = 'Copied!';
|
|
4140
|
+
setTimeout(() => btn.textContent = 'Copy', 2000);
|
|
4141
|
+
});
|
|
4142
|
+
}
|
|
4143
|
+
|
|
4144
|
+
async function revokeKey(keyId) {
|
|
4145
|
+
if (!confirm('Are you sure you want to revoke this API key? This cannot be undone.')) {
|
|
4146
|
+
return;
|
|
4147
|
+
}
|
|
4148
|
+
|
|
4149
|
+
try {
|
|
4150
|
+
const res = await fetch('/auth/keys/' + keyId, { method: 'DELETE' });
|
|
4151
|
+
const data = await res.json();
|
|
4152
|
+
|
|
4153
|
+
if (data.success) {
|
|
4154
|
+
document.querySelector('tr[data-key-id="' + keyId + '"]').remove();
|
|
4155
|
+
} else {
|
|
4156
|
+
alert('Failed to revoke key: ' + (data.error || 'Unknown error'));
|
|
4157
|
+
}
|
|
4158
|
+
} catch (err) {
|
|
4159
|
+
alert('Failed to revoke key: ' + err.message);
|
|
4160
|
+
}
|
|
4161
|
+
}
|
|
4162
|
+
<\/script>
|
|
4163
|
+
</body>
|
|
4164
|
+
</html>`;
|
|
4165
|
+
}
|
|
4166
|
+
__name(renderDashboardPage, "renderDashboardPage");
|
|
4167
|
+
function formatRelativeTime(timestamp) {
|
|
4168
|
+
if (!timestamp)
|
|
4169
|
+
return "Never";
|
|
4170
|
+
const now = Math.floor(Date.now() / 1e3);
|
|
4171
|
+
const diff = now - timestamp;
|
|
4172
|
+
if (diff < 60)
|
|
4173
|
+
return "just now";
|
|
4174
|
+
if (diff < 3600)
|
|
4175
|
+
return `${Math.floor(diff / 60)}m ago`;
|
|
4176
|
+
if (diff < 86400)
|
|
4177
|
+
return `${Math.floor(diff / 3600)}h ago`;
|
|
4178
|
+
if (diff < 604800)
|
|
4179
|
+
return `${Math.floor(diff / 86400)}d ago`;
|
|
4180
|
+
if (diff < 2592e3)
|
|
4181
|
+
return `${Math.floor(diff / 604800)}w ago`;
|
|
4182
|
+
if (diff < 31536e3)
|
|
4183
|
+
return `${Math.floor(diff / 2592e3)}mo ago`;
|
|
4184
|
+
return `${Math.floor(diff / 31536e3)}y ago`;
|
|
4185
|
+
}
|
|
4186
|
+
__name(formatRelativeTime, "formatRelativeTime");
|
|
4187
|
+
function escapeHtml(str) {
|
|
4188
|
+
if (!str)
|
|
4189
|
+
return "";
|
|
4190
|
+
return str.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
4191
|
+
}
|
|
4192
|
+
__name(escapeHtml, "escapeHtml");
|
|
4193
|
+
|
|
4194
|
+
// ../../node_modules/.pnpm/hono@4.11.7/node_modules/hono/dist/utils/cookie.js
|
|
4195
|
+
var validCookieNameRegEx = /^[\w!#$%&'*.^`|~+-]+$/;
|
|
4196
|
+
var validCookieValueRegEx = /^[ !#-:<-[\]-~]*$/;
|
|
4197
|
+
var parse = /* @__PURE__ */ __name((cookie, name) => {
|
|
4198
|
+
if (name && cookie.indexOf(name) === -1) {
|
|
4199
|
+
return {};
|
|
4200
|
+
}
|
|
4201
|
+
const pairs = cookie.trim().split(";");
|
|
4202
|
+
const parsedCookie = {};
|
|
4203
|
+
for (let pairStr of pairs) {
|
|
4204
|
+
pairStr = pairStr.trim();
|
|
4205
|
+
const valueStartPos = pairStr.indexOf("=");
|
|
4206
|
+
if (valueStartPos === -1) {
|
|
4207
|
+
continue;
|
|
4208
|
+
}
|
|
4209
|
+
const cookieName = pairStr.substring(0, valueStartPos).trim();
|
|
4210
|
+
if (name && name !== cookieName || !validCookieNameRegEx.test(cookieName)) {
|
|
4211
|
+
continue;
|
|
4212
|
+
}
|
|
4213
|
+
let cookieValue = pairStr.substring(valueStartPos + 1).trim();
|
|
4214
|
+
if (cookieValue.startsWith('"') && cookieValue.endsWith('"')) {
|
|
4215
|
+
cookieValue = cookieValue.slice(1, -1);
|
|
4216
|
+
}
|
|
4217
|
+
if (validCookieValueRegEx.test(cookieValue)) {
|
|
4218
|
+
parsedCookie[cookieName] = cookieValue.indexOf("%") !== -1 ? tryDecode(cookieValue, decodeURIComponent_) : cookieValue;
|
|
4219
|
+
if (name) {
|
|
4220
|
+
break;
|
|
4221
|
+
}
|
|
4222
|
+
}
|
|
4223
|
+
}
|
|
4224
|
+
return parsedCookie;
|
|
4225
|
+
}, "parse");
|
|
4226
|
+
var _serialize = /* @__PURE__ */ __name((name, value, opt = {}) => {
|
|
4227
|
+
let cookie = `${name}=${value}`;
|
|
4228
|
+
if (name.startsWith("__Secure-") && !opt.secure) {
|
|
4229
|
+
throw new Error("__Secure- Cookie must have Secure attributes");
|
|
4230
|
+
}
|
|
4231
|
+
if (name.startsWith("__Host-")) {
|
|
4232
|
+
if (!opt.secure) {
|
|
4233
|
+
throw new Error("__Host- Cookie must have Secure attributes");
|
|
4234
|
+
}
|
|
4235
|
+
if (opt.path !== "/") {
|
|
4236
|
+
throw new Error('__Host- Cookie must have Path attributes with "/"');
|
|
4237
|
+
}
|
|
4238
|
+
if (opt.domain) {
|
|
4239
|
+
throw new Error("__Host- Cookie must not have Domain attributes");
|
|
4240
|
+
}
|
|
4241
|
+
}
|
|
4242
|
+
if (opt && typeof opt.maxAge === "number" && opt.maxAge >= 0) {
|
|
4243
|
+
if (opt.maxAge > 3456e4) {
|
|
4244
|
+
throw new Error(
|
|
4245
|
+
"Cookies Max-Age SHOULD NOT be greater than 400 days (34560000 seconds) in duration."
|
|
4246
|
+
);
|
|
4247
|
+
}
|
|
4248
|
+
cookie += `; Max-Age=${opt.maxAge | 0}`;
|
|
4249
|
+
}
|
|
4250
|
+
if (opt.domain && opt.prefix !== "host") {
|
|
4251
|
+
cookie += `; Domain=${opt.domain}`;
|
|
4252
|
+
}
|
|
4253
|
+
if (opt.path) {
|
|
4254
|
+
cookie += `; Path=${opt.path}`;
|
|
4255
|
+
}
|
|
4256
|
+
if (opt.expires) {
|
|
4257
|
+
if (opt.expires.getTime() - Date.now() > 3456e7) {
|
|
4258
|
+
throw new Error(
|
|
4259
|
+
"Cookies Expires SHOULD NOT be greater than 400 days (34560000 seconds) in the future."
|
|
4260
|
+
);
|
|
4261
|
+
}
|
|
4262
|
+
cookie += `; Expires=${opt.expires.toUTCString()}`;
|
|
4263
|
+
}
|
|
4264
|
+
if (opt.httpOnly) {
|
|
4265
|
+
cookie += "; HttpOnly";
|
|
4266
|
+
}
|
|
4267
|
+
if (opt.secure) {
|
|
4268
|
+
cookie += "; Secure";
|
|
4269
|
+
}
|
|
4270
|
+
if (opt.sameSite) {
|
|
4271
|
+
cookie += `; SameSite=${opt.sameSite.charAt(0).toUpperCase() + opt.sameSite.slice(1)}`;
|
|
4272
|
+
}
|
|
4273
|
+
if (opt.priority) {
|
|
4274
|
+
cookie += `; Priority=${opt.priority.charAt(0).toUpperCase() + opt.priority.slice(1)}`;
|
|
4275
|
+
}
|
|
4276
|
+
if (opt.partitioned) {
|
|
4277
|
+
if (!opt.secure) {
|
|
4278
|
+
throw new Error("Partitioned Cookie must have Secure attributes");
|
|
4279
|
+
}
|
|
4280
|
+
cookie += "; Partitioned";
|
|
4281
|
+
}
|
|
4282
|
+
return cookie;
|
|
4283
|
+
}, "_serialize");
|
|
4284
|
+
var serialize = /* @__PURE__ */ __name((name, value, opt) => {
|
|
4285
|
+
value = encodeURIComponent(value);
|
|
4286
|
+
return _serialize(name, value, opt);
|
|
4287
|
+
}, "serialize");
|
|
4288
|
+
|
|
4289
|
+
// ../../node_modules/.pnpm/hono@4.11.7/node_modules/hono/dist/helper/cookie/index.js
|
|
4290
|
+
var getCookie = /* @__PURE__ */ __name((c, key, prefix) => {
|
|
4291
|
+
const cookie = c.req.raw.headers.get("Cookie");
|
|
4292
|
+
if (typeof key === "string") {
|
|
4293
|
+
if (!cookie) {
|
|
4294
|
+
return void 0;
|
|
4295
|
+
}
|
|
4296
|
+
let finalKey = key;
|
|
4297
|
+
if (prefix === "secure") {
|
|
4298
|
+
finalKey = "__Secure-" + key;
|
|
4299
|
+
} else if (prefix === "host") {
|
|
4300
|
+
finalKey = "__Host-" + key;
|
|
4301
|
+
}
|
|
4302
|
+
const obj2 = parse(cookie, finalKey);
|
|
4303
|
+
return obj2[finalKey];
|
|
4304
|
+
}
|
|
4305
|
+
if (!cookie) {
|
|
4306
|
+
return {};
|
|
4307
|
+
}
|
|
4308
|
+
const obj = parse(cookie);
|
|
4309
|
+
return obj;
|
|
4310
|
+
}, "getCookie");
|
|
4311
|
+
var generateCookie = /* @__PURE__ */ __name((name, value, opt) => {
|
|
4312
|
+
let cookie;
|
|
4313
|
+
if (opt?.prefix === "secure") {
|
|
4314
|
+
cookie = serialize("__Secure-" + name, value, { path: "/", ...opt, secure: true });
|
|
4315
|
+
} else if (opt?.prefix === "host") {
|
|
4316
|
+
cookie = serialize("__Host-" + name, value, {
|
|
4317
|
+
...opt,
|
|
4318
|
+
path: "/",
|
|
4319
|
+
secure: true,
|
|
4320
|
+
domain: void 0
|
|
4321
|
+
});
|
|
4322
|
+
} else {
|
|
4323
|
+
cookie = serialize(name, value, { path: "/", ...opt });
|
|
4324
|
+
}
|
|
4325
|
+
return cookie;
|
|
4326
|
+
}, "generateCookie");
|
|
4327
|
+
var setCookie = /* @__PURE__ */ __name((c, name, value, opt) => {
|
|
4328
|
+
const cookie = generateCookie(name, value, opt);
|
|
4329
|
+
c.header("Set-Cookie", cookie, { append: true });
|
|
4330
|
+
}, "setCookie");
|
|
4331
|
+
var deleteCookie = /* @__PURE__ */ __name((c, name, opt) => {
|
|
4332
|
+
const deletedCookie = getCookie(c, name, opt?.prefix);
|
|
4333
|
+
setCookie(c, name, "", { ...opt, maxAge: 0 });
|
|
4334
|
+
return deletedCookie;
|
|
4335
|
+
}, "deleteCookie");
|
|
4336
|
+
|
|
4337
|
+
// src/routes/github-oauth-authentication-handler.ts
|
|
4338
|
+
var authRouter = new Hono2();
|
|
4339
|
+
var GITHUB_OAUTH_URL = "https://github.com/login/oauth/authorize";
|
|
4340
|
+
var GITHUB_TOKEN_URL = "https://github.com/login/oauth/access_token";
|
|
4341
|
+
var GITHUB_USER_URL = "https://api.github.com/user";
|
|
4342
|
+
var SESSION_COOKIE = "skillmark_session";
|
|
4343
|
+
var SESSION_DURATION_DAYS = 30;
|
|
4344
|
+
authRouter.get("/github", (c) => {
|
|
4345
|
+
const clientId = c.env.GITHUB_CLIENT_ID;
|
|
4346
|
+
const baseUrl = getBaseUrl(c.req.url, c.env.ENVIRONMENT);
|
|
4347
|
+
const redirectUri = `${baseUrl}/auth/github/callback`;
|
|
4348
|
+
const params = new URLSearchParams({
|
|
4349
|
+
client_id: clientId,
|
|
4350
|
+
redirect_uri: redirectUri,
|
|
4351
|
+
scope: "read:user user:email",
|
|
4352
|
+
state: generateState()
|
|
4353
|
+
});
|
|
4354
|
+
return c.redirect(`${GITHUB_OAUTH_URL}?${params.toString()}`);
|
|
4355
|
+
});
|
|
4356
|
+
authRouter.get("/github/callback", async (c) => {
|
|
4357
|
+
const code = c.req.query("code");
|
|
4358
|
+
const error = c.req.query("error");
|
|
4359
|
+
if (error || !code) {
|
|
4360
|
+
return c.redirect("/login?error=oauth_failed");
|
|
4361
|
+
}
|
|
4362
|
+
try {
|
|
4363
|
+
const baseUrl = getBaseUrl(c.req.url, c.env.ENVIRONMENT);
|
|
4364
|
+
const tokenResponse = await fetch(GITHUB_TOKEN_URL, {
|
|
4365
|
+
method: "POST",
|
|
4366
|
+
headers: {
|
|
4367
|
+
"Content-Type": "application/json",
|
|
4368
|
+
"Accept": "application/json"
|
|
4369
|
+
},
|
|
4370
|
+
body: JSON.stringify({
|
|
4371
|
+
client_id: c.env.GITHUB_CLIENT_ID,
|
|
4372
|
+
client_secret: c.env.GITHUB_CLIENT_SECRET,
|
|
4373
|
+
code,
|
|
4374
|
+
redirect_uri: `${baseUrl}/auth/github/callback`
|
|
4375
|
+
})
|
|
4376
|
+
});
|
|
4377
|
+
const tokenData = await tokenResponse.json();
|
|
4378
|
+
if (!tokenData.access_token) {
|
|
4379
|
+
console.error("Failed to get access token:", tokenData);
|
|
4380
|
+
return c.redirect("/login?error=token_failed");
|
|
4381
|
+
}
|
|
4382
|
+
const userResponse = await fetch(GITHUB_USER_URL, {
|
|
4383
|
+
headers: {
|
|
4384
|
+
"Authorization": `Bearer ${tokenData.access_token}`,
|
|
4385
|
+
"Accept": "application/vnd.github.v3+json",
|
|
4386
|
+
"User-Agent": "Skillmark-OAuth"
|
|
4387
|
+
}
|
|
4388
|
+
});
|
|
4389
|
+
const githubUser = await userResponse.json();
|
|
4390
|
+
const userId = await upsertUser(c.env.DB, githubUser);
|
|
4391
|
+
const sessionId = await createSession(c.env.DB, userId);
|
|
4392
|
+
setCookie(c, SESSION_COOKIE, sessionId, {
|
|
4393
|
+
httpOnly: true,
|
|
4394
|
+
secure: c.env.ENVIRONMENT === "production",
|
|
4395
|
+
sameSite: "Lax",
|
|
4396
|
+
maxAge: SESSION_DURATION_DAYS * 24 * 60 * 60,
|
|
4397
|
+
path: "/"
|
|
4398
|
+
});
|
|
4399
|
+
return c.redirect("/dashboard");
|
|
4400
|
+
} catch (err) {
|
|
4401
|
+
console.error("OAuth callback error:", err);
|
|
4402
|
+
return c.redirect("/login?error=oauth_failed");
|
|
4403
|
+
}
|
|
4404
|
+
});
|
|
4405
|
+
authRouter.get("/logout", async (c) => {
|
|
4406
|
+
const sessionId = getCookie(c, SESSION_COOKIE);
|
|
4407
|
+
if (sessionId) {
|
|
4408
|
+
await c.env.DB.prepare("DELETE FROM sessions WHERE id = ?").bind(sessionId).run();
|
|
4409
|
+
}
|
|
4410
|
+
deleteCookie(c, SESSION_COOKIE, { path: "/" });
|
|
4411
|
+
return c.redirect("/");
|
|
4412
|
+
});
|
|
4413
|
+
authRouter.get("/me", async (c) => {
|
|
4414
|
+
const user = await getCurrentUser2(c);
|
|
4415
|
+
if (!user) {
|
|
4416
|
+
return c.json({ error: "Not authenticated" }, 401);
|
|
4417
|
+
}
|
|
4418
|
+
return c.json({
|
|
4419
|
+
id: user.id,
|
|
4420
|
+
githubUsername: user.githubUsername,
|
|
4421
|
+
githubAvatar: user.githubAvatar
|
|
4422
|
+
});
|
|
4423
|
+
});
|
|
4424
|
+
authRouter.post("/keys", async (c) => {
|
|
4425
|
+
const user = await getCurrentUser2(c);
|
|
4426
|
+
if (!user) {
|
|
4427
|
+
return c.json({ error: "Not authenticated" }, 401);
|
|
4428
|
+
}
|
|
4429
|
+
const apiKey = generateApiKey();
|
|
4430
|
+
const keyHash = await hashApiKey2(apiKey);
|
|
4431
|
+
const keyId = crypto.randomUUID();
|
|
4432
|
+
await c.env.DB.prepare(`
|
|
4433
|
+
INSERT INTO api_keys (id, key_hash, user_name, github_username, github_avatar, github_id)
|
|
4434
|
+
VALUES (?, ?, ?, ?, ?, ?)
|
|
4435
|
+
`).bind(
|
|
4436
|
+
keyId,
|
|
4437
|
+
keyHash,
|
|
4438
|
+
user.githubUsername,
|
|
4439
|
+
user.githubUsername,
|
|
4440
|
+
user.githubAvatar,
|
|
4441
|
+
user.githubId
|
|
4442
|
+
).run();
|
|
4443
|
+
return c.json({
|
|
4444
|
+
apiKey,
|
|
4445
|
+
keyId,
|
|
4446
|
+
message: "API key generated. Store it securely - it cannot be retrieved again."
|
|
4447
|
+
});
|
|
4448
|
+
});
|
|
4449
|
+
authRouter.get("/keys", async (c) => {
|
|
4450
|
+
const user = await getCurrentUser2(c);
|
|
4451
|
+
if (!user) {
|
|
4452
|
+
return c.json({ error: "Not authenticated" }, 401);
|
|
4453
|
+
}
|
|
4454
|
+
const keys = await c.env.DB.prepare(`
|
|
4455
|
+
SELECT id, created_at, last_used_at
|
|
4456
|
+
FROM api_keys
|
|
4457
|
+
WHERE github_id = ?
|
|
4458
|
+
ORDER BY created_at DESC
|
|
4459
|
+
`).bind(user.githubId).all();
|
|
4460
|
+
const formattedKeys = keys.results?.map((key) => ({
|
|
4461
|
+
id: key.id,
|
|
4462
|
+
createdAt: key.created_at ? new Date(key.created_at * 1e3).toISOString() : null,
|
|
4463
|
+
lastUsedAt: key.last_used_at ? new Date(key.last_used_at * 1e3).toISOString() : null
|
|
4464
|
+
})) || [];
|
|
4465
|
+
return c.json({ keys: formattedKeys });
|
|
4466
|
+
});
|
|
4467
|
+
authRouter.delete("/keys/:id", async (c) => {
|
|
4468
|
+
const user = await getCurrentUser2(c);
|
|
4469
|
+
if (!user) {
|
|
4470
|
+
return c.json({ error: "Not authenticated" }, 401);
|
|
4471
|
+
}
|
|
4472
|
+
const keyId = c.req.param("id");
|
|
4473
|
+
const key = await c.env.DB.prepare(`
|
|
4474
|
+
SELECT id FROM api_keys WHERE id = ? AND github_id = ?
|
|
4475
|
+
`).bind(keyId, user.githubId).first();
|
|
4476
|
+
if (!key) {
|
|
4477
|
+
return c.json({ error: "Key not found" }, 404);
|
|
4478
|
+
}
|
|
4479
|
+
await c.env.DB.prepare("DELETE FROM api_keys WHERE id = ?").bind(keyId).run();
|
|
4480
|
+
return c.json({ success: true });
|
|
4481
|
+
});
|
|
4482
|
+
authRouter.post("/verify-key", async (c) => {
|
|
4483
|
+
const authHeader = c.req.header("Authorization");
|
|
4484
|
+
if (!authHeader?.startsWith("Bearer ")) {
|
|
4485
|
+
return c.json({ valid: false }, 401);
|
|
4486
|
+
}
|
|
4487
|
+
const apiKey = authHeader.slice(7);
|
|
4488
|
+
const keyHash = await hashApiKey2(apiKey);
|
|
4489
|
+
const keyRecord = await c.env.DB.prepare(`
|
|
4490
|
+
SELECT github_username, github_avatar, github_id
|
|
4491
|
+
FROM api_keys
|
|
4492
|
+
WHERE key_hash = ?
|
|
4493
|
+
`).bind(keyHash).first();
|
|
4494
|
+
if (!keyRecord) {
|
|
4495
|
+
return c.json({ valid: false }, 401);
|
|
4496
|
+
}
|
|
4497
|
+
await c.env.DB.prepare(`
|
|
4498
|
+
UPDATE api_keys SET last_used_at = unixepoch() WHERE key_hash = ?
|
|
4499
|
+
`).bind(keyHash).run();
|
|
4500
|
+
return c.json({
|
|
4501
|
+
valid: true,
|
|
4502
|
+
user: {
|
|
4503
|
+
githubUsername: keyRecord.github_username,
|
|
4504
|
+
githubAvatar: keyRecord.github_avatar
|
|
4505
|
+
}
|
|
4506
|
+
});
|
|
4507
|
+
});
|
|
4508
|
+
async function getCurrentUser2(c) {
|
|
4509
|
+
const cookieHeader = c.req.header("Cookie") || "";
|
|
4510
|
+
const cookies = parseCookies(cookieHeader);
|
|
4511
|
+
const sessionId = cookies[SESSION_COOKIE];
|
|
4512
|
+
if (!sessionId) {
|
|
4513
|
+
return null;
|
|
4514
|
+
}
|
|
4515
|
+
const session = await c.env.DB.prepare(`
|
|
4516
|
+
SELECT u.id, u.github_id, u.github_username, u.github_avatar
|
|
4517
|
+
FROM sessions s
|
|
4518
|
+
JOIN users u ON u.id = s.user_id
|
|
4519
|
+
WHERE s.id = ? AND s.expires_at > unixepoch()
|
|
4520
|
+
`).bind(sessionId).first();
|
|
4521
|
+
if (!session) {
|
|
4522
|
+
return null;
|
|
4523
|
+
}
|
|
4524
|
+
return {
|
|
4525
|
+
id: session.id,
|
|
4526
|
+
githubId: session.github_id,
|
|
4527
|
+
githubUsername: session.github_username,
|
|
4528
|
+
githubAvatar: session.github_avatar
|
|
4529
|
+
};
|
|
4530
|
+
}
|
|
4531
|
+
__name(getCurrentUser2, "getCurrentUser");
|
|
4532
|
+
function parseCookies(cookieHeader) {
|
|
4533
|
+
const cookies = {};
|
|
4534
|
+
cookieHeader.split(";").forEach((cookie) => {
|
|
4535
|
+
const [name, ...rest] = cookie.trim().split("=");
|
|
4536
|
+
if (name) {
|
|
4537
|
+
cookies[name] = rest.join("=");
|
|
4538
|
+
}
|
|
4539
|
+
});
|
|
4540
|
+
return cookies;
|
|
4541
|
+
}
|
|
4542
|
+
__name(parseCookies, "parseCookies");
|
|
4543
|
+
async function upsertUser(db, githubUser) {
|
|
4544
|
+
const existingUser = await db.prepare(`
|
|
4545
|
+
SELECT id FROM users WHERE github_id = ?
|
|
4546
|
+
`).bind(githubUser.id).first();
|
|
4547
|
+
if (existingUser) {
|
|
4548
|
+
await db.prepare(`
|
|
4549
|
+
UPDATE users
|
|
4550
|
+
SET github_username = ?, github_avatar = ?, github_email = ?, updated_at = unixepoch()
|
|
4551
|
+
WHERE github_id = ?
|
|
4552
|
+
`).bind(
|
|
4553
|
+
githubUser.login,
|
|
4554
|
+
githubUser.avatar_url,
|
|
4555
|
+
githubUser.email,
|
|
4556
|
+
githubUser.id
|
|
4557
|
+
).run();
|
|
4558
|
+
return existingUser.id;
|
|
4559
|
+
}
|
|
4560
|
+
const userId = crypto.randomUUID();
|
|
4561
|
+
await db.prepare(`
|
|
4562
|
+
INSERT INTO users (id, github_id, github_username, github_avatar, github_email)
|
|
4563
|
+
VALUES (?, ?, ?, ?, ?)
|
|
4564
|
+
`).bind(
|
|
4565
|
+
userId,
|
|
4566
|
+
githubUser.id,
|
|
4567
|
+
githubUser.login,
|
|
4568
|
+
githubUser.avatar_url,
|
|
4569
|
+
githubUser.email
|
|
4570
|
+
).run();
|
|
4571
|
+
return userId;
|
|
4572
|
+
}
|
|
4573
|
+
__name(upsertUser, "upsertUser");
|
|
4574
|
+
async function createSession(db, userId) {
|
|
4575
|
+
const sessionId = crypto.randomUUID();
|
|
4576
|
+
const expiresAt = Math.floor(Date.now() / 1e3) + SESSION_DURATION_DAYS * 24 * 60 * 60;
|
|
4577
|
+
await db.prepare(`
|
|
4578
|
+
INSERT INTO sessions (id, user_id, expires_at)
|
|
4579
|
+
VALUES (?, ?, ?)
|
|
4580
|
+
`).bind(sessionId, userId, expiresAt).run();
|
|
4581
|
+
return sessionId;
|
|
4582
|
+
}
|
|
4583
|
+
__name(createSession, "createSession");
|
|
4584
|
+
function generateApiKey() {
|
|
4585
|
+
const array = new Uint8Array(32);
|
|
4586
|
+
crypto.getRandomValues(array);
|
|
4587
|
+
return "sk_" + Array.from(array, (b) => b.toString(16).padStart(2, "0")).join("");
|
|
4588
|
+
}
|
|
4589
|
+
__name(generateApiKey, "generateApiKey");
|
|
4590
|
+
async function hashApiKey2(apiKey) {
|
|
4591
|
+
const encoder = new TextEncoder();
|
|
4592
|
+
const data = encoder.encode(apiKey);
|
|
4593
|
+
const hashBuffer = await crypto.subtle.digest("SHA-256", data);
|
|
4594
|
+
const hashArray = Array.from(new Uint8Array(hashBuffer));
|
|
4595
|
+
return hashArray.map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
4596
|
+
}
|
|
4597
|
+
__name(hashApiKey2, "hashApiKey");
|
|
4598
|
+
function generateState() {
|
|
4599
|
+
const array = new Uint8Array(16);
|
|
4600
|
+
crypto.getRandomValues(array);
|
|
4601
|
+
return Array.from(array, (b) => b.toString(16).padStart(2, "0")).join("");
|
|
4602
|
+
}
|
|
4603
|
+
__name(generateState, "generateState");
|
|
4604
|
+
function getBaseUrl(requestUrl, environment) {
|
|
4605
|
+
const url = new URL(requestUrl);
|
|
4606
|
+
if (environment === "production") {
|
|
4607
|
+
return "https://skillmark.sh";
|
|
4608
|
+
}
|
|
4609
|
+
return `${url.protocol}//${url.host}`;
|
|
4610
|
+
}
|
|
4611
|
+
__name(getBaseUrl, "getBaseUrl");
|
|
4612
|
+
|
|
4613
|
+
// src/routes/static-assets-handler.ts
|
|
4614
|
+
var assetsRouter = new Hono2();
|
|
4615
|
+
var FAVICON_BASE64 = "iVBORw0KGgoAAAANSUhEUgAAACQAAAAjCAYAAAD8BaggAAAKq2lDQ1BJQ0MgUHJvZmlsZQAASImVlwdUk8kWx+f70kNCCyAgJfQmvQWQEkILvTdRCUmAUGIMBBGxIYsrsKKISFMWdJWi4KoUWSsWLCwKCtg3yKKirosFGyrvAw5hd9957513z5nM7/xz586de2ZybgAgK7MEgjRYFoB0fqYw1NudGh0TS8U9BxCgABlAACYsdoaAHhzsDxCbn/9u74cQb8Rumc7E+vfv/6vJcbgZbACgYIQTOBnsdIRPIOMNWyDMBADVgOg6azIFM9yLsIIQSRBh8QwnzfG7GU6YZTR+1ic8lIGwGgB4EoslTAKAZIjo1Cx2EhKH5IOwBZ/D4yOcjbBLevoqDsKdCBsiPgKEZ+LTEv4SJ+lvMRMkMVmsJAnPnWXW8B68DEEaa+3/WY7/belpovk9DJBBShb6hCKzNFKz31NX+UmYnxAYNM88zqz/LCeLfCLmmZ3BiJ3njLQw5jxzWB5+kjhpgf7znMjzkvjwMpnh88zN8AybZ+GqUMm+iUIGfZ5ZwoUcRKkREj2Zy5TEz0kOj5rnLF5koCS31DC/BR+GRBeKQiVn4fK93Rf29ZLUIT3jL2fnMSVrM5PDfSR1YC3kz+XTF2JmREty43A9PBd8IiT+gkx3yV6CtGCJPzfNW6JnZIVJ1mYil3NhbbCkhiks3+B5Bt4gAFgDG2AKGACpSCY3O3PmEIxVgrVCXlJyJpWOvDQulclnmy2hWllY2QEw827nrsXbO7PvEVLCL2gbcpHrrI5A9oLGLALgyHEAZOMWNLMbAKhaANAdwxYJs+Y09MwHBhCR3wMFoAI0gA4wRDKzAnbACbgBT+ALgkA4iAErABskg3QgBGtALtgMCkAR2AF2gypQC/aDBnAEHAMd4BQ4Dy6D6+AmGAT3gRiMgRdgArwHUxAE4SAyRIFUIE1IDzKBrCAa5AJ5Qv5QKBQDxUNJEB8SQbnQFqgIKoWqoDqoEfoZOgmdh65C/dBdaAQah95An2EUTIIVYHVYHzaHaTAd9oPD4eVwErwazoHz4O1wBVwPH4bb4fPwdXgQFsMv4EkUQEmhlFBaKFMUDcVABaFiUYkoIWoDqhBVjqpHtaC6UD2oWygx6iXqExqLpqCpaFO0E9oHHYFmo1ejN6CL0VXoBnQ7+iL6FnoEPYH+hiFj1DAmGEcMExONScKswRRgyjEHMW2YS5hBzBjmPRaLVcIaYO2xPtgYbAp2HbYYuxfbij2H7ceOYidxOJwKzgTnjAvCsXCZuAJcJe4w7ixuADeG+4iXwmvirfBe+Fg8H5+HL8c34c/gB/BP8VMEWYIewZEQROAQ1hJKCAcIXYQbhDHCFFGOaEB0JoYTU4ibiRXEFuIl4gPiWykpKW0pB6kQKZ7UJqkKqaNSV6RGpD6R5EnGJAYpjiQibScdIp0j3SW9JZPJ+mQ3ciw5k7yd3Ei+QH5E/ihNkTaTZkpzpDdKV0u3Sw9Iv5IhyOjJ0GVWyOTIlMscl7kh81KWIKsvy5BlyW6QrZY9KTssOylHkbOUC5JLlyuWa5K7KvdMHievL+8pz5HPl98vf0F+lIKi6FAYFDZlC+UA5RJlTAGrYKDAVEhRKFI4otCnMKEor2ijGKmYrViteFpRrIRS0ldiKqUplSgdUxpS+rxIfRF9EXfRtkUtiwYWfVBerOymzFUuVG5VHlT+rEJV8VRJVdmp0qHyUBWtaqwaorpGdZ/qJdWXixUWOy1mLy5cfGzxPTVYzVgtVG2d2n61XrVJdQ11b3WBeqX6BfWXGkoabhopGmUaZzTGNSmaLpo8zTLNs5rPqYpUOjWNWkG9SJ3QUtPy0RJp1Wn1aU1pG2hHaOdpt2o/1CHq0HQSdcp0unUmdDV1A3RzdZt17+kR9Gh6yXp79Hr0Pugb6Efpb9Xv0H9moGzANMgxaDZ4YEg2dDVcbVhveNsIa0QzSjXaa3TTGDa2NU42rja+YQKb2JnwTPaa9C/BLHFYwl9Sv2TYlGRKN80ybTYdMVMy8zfLM+swe2Wuax5rvtO8x/ybha1FmsUBi/uW8pa+lnmWXZZvrIyt2FbVVretydZe1hutO61f25jYcG322dyxpdgG2G617bb9amdvJ7RrsRu317WPt6+xH6Yp0IJpxbQrDhgHd4eNDqccPjnaOWY6HnP808nUKdWpyenZUoOl3KUHlo46azuznOucxS5Ul3iXH13ErlquLNd618duOm4ct4NuT+lG9BT6Yfordwt3oXub+weGI2M945wHysPbo9Cjz1PeM8KzyvORl7ZXklez14S3rfc673M+GB8/n50+w0x1JpvZyJzwtfdd73vRj+QX5lfl99jf2F/o3xUAB/gG7Ap4EKgXyA/sCAJBzKBdQQ+DDYJXB/8Sgg0JDqkOeRJqGZob2hNGCVsZ1hT2Ptw9vCT8foRhhCiiO1ImMi6yMfJDlEdUaZQ42jx6ffT1GNUYXkxnLC42MvZg7OQyz2W7l43F2cYVxA0tN1ievfzqCtUVaStOr5RZyVp5PB4THxXfFP+FFcSqZ00mMBNqEibYDPYe9guOG6eMM8515pZynyY6J5YmPktyTtqVNJ7smlye/JLH4FXxXqf4pNSmfEgNSj2UOp0Wldaajk+PTz/Jl+en8i+u0liVvapfYCIoEIhXO67evXpC6Cc8mAFlLM/ozFRAGqRekaHoO9FIlktWddbHNZFrjmfLZfOze9car9269mmOV85P69Dr2Ou6c7VyN+eOrKevr9sAbUjY0L1RZ2P+xrFN3psaNhM3p27+Nc8irzTv3ZaoLV356vmb8ke/8/6uuUC6QFgwvNVpa+336O953/dts95Wue1bIafwWpFFUXnRl2J28bUfLH+o+GF6e+L2vhK7kn07sDv4O4Z2uu5sKJUrzSkd3RWwq72MWlZY9m73yt1Xy23Ka/cQ94j2iCv8KzordSt3VH6pSq4arHavbq1Rq9lW82EvZ+/APrd9LbXqtUW1n3/k/XinzruuvV6/vnw/dn/W/icHIg/0/ET7qfGg6sGig98P8Q+JG0IbLjbaNzY2qTWVNMPNoubxw3GHbx7xONLZYtpS16rUWnQUHBUdff5z/M9Dx/yOdR+nHW85oXeipo3SVtgOta9tn+hI7hB3xnT2n/Q92d3l1NX2i9kvh05pnao+rXi65AzxTP6Z6bM5ZyfPCc69PJ90frR7Zff9C9EXbl8Mudh3ye/Slctely/00HvOXnG+cuqq49WT12jXOq7bXW/vte1t+9X217Y+u772G/Y3Om463OzqX9p/ZsB14Pwtj1uXbzNvXx8MHOwfihi6Mxw3LL7DufPsbtrd1/ey7k3d3/QA86DwoezD8kdqj+p/M/qtVWwnPj3iMdL7OOzx/VH26IvfM37/Mpb/hPyk/Knm08ZnVs9OjXuN33y+7PnYC8GLqZcFf8j9UfPK8NWJP93+7J2Inhh7LXw9/ab4rcrbQ+9s3nVPBk8+ep/+fupD4UeVjw2faJ96Pkd9fjq15gvuS8VXo69d3/y+PZhOn54WsISs2VYAhQw4MRGAN4cAIMcAQLkJAHHZXF89a9Bcf4FZAv+J53rvWUM6l6NuAAQiw30TAE3nADBGZEVkDka0cDcAW1tLxnwPPNuvzxi5ESBt0ozdraksAP+wuV7+L3n/cwaSqH+b/wU37QX8G4OYsAAAAFZlWElmTU0AKgAAAAgAAYdpAAQAAAABAAAAGgAAAAAAA5KGAAcAAAASAAAARKACAAQAAAABAAAAJKADAAQAAAABAAAAIwAAAABBU0NJSQAAAFNjcmVlbnNob3Qa73x3AAAB1GlUWHRYTUw6Y29tLmFkb2JlLnhtcAAAAAAAPHg6eG1wbWV0YSB4bWxuczp4PSJhZG9iZTpuczptZXRhLyIgeDp4bXB0az0iWE1QIENvcmUgNi4wLjAiPgogICA8cmRmOlJERiB4bWxuczpyZGY9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkvMDIvMjItcmRmLXN5bnRheC1ucyMiPgogICAgICA8cmRmOkRlc2NyaXB0aW9uIHJkZjphYm91dD0iIgogICAgICAgICAgICB4bWxuczpleGlmPSJodHRwOi8vbnMuYWRvYmUuY29tL2V4aWYvMS4wLyI+CiAgICAgICAgIDxleGlmOlBpeGVsWURpbWVuc2lvbj4zNTwvZXhpZjpQaXhlbFlEaW1lbnNpb24+CiAgICAgICAgIDxleGlmOlBpeGVsWERpbWVuc2lvbj4zNjwvZXhpZjpQaXhlbFhEaW1lbnNpb24+CiAgICAgICAgIDxleGlmOlVzZXJDb21tZW50PlNjcmVlbnNob3Q8L2V4aWY6VXNlckNvbW1lbnQ+CiAgICAgIDwvcmRmOkRlc2NyaXB0aW9uPgogICA8L3JkZjpSREY+CjwveDp4bXBtZXRhPgpJaYwnAAABRElEQVRYCe1U0RGDIAy1ncFpdAfH0Rl0HIdwGnewPM9HKfVMCfnwenDHCQkhj/dMHlVVbW7eZjxvg+QAUgBJihSGCkMSA5L/v/6htm2lB6v86NTJs+/7bV3XbZ7n5NirfI/DmfwSB8bH1HXt17kL1T/k2PnIaymdCtAHGrcZhiE2qfcqySjXsixV0zR7civZkhkK5eq6zjNhJVsyICKYpmlfgiUMS9nEskVpo8TDibJ3ODbHjLdjz3kWg7P0X3zfl5wdChMSUNx7aGdC9ija8Y1jznIdtmtAF4H+tWSDSQmILP5yR3AmH1DIIi4mMxpAqrJ3Sb+GA7HbcluBuspiRKw29iVWYXxO2psBGsdRyvWT30wyZKNsWGs7txlDAEHZtHLhDgxfvhZr9iLtXaaS4XW5w1SyXDCIL4AkFgtDhSGJAcn/AqbFa8IIHwjUAAAAAElFTkSuQmCC";
|
|
4616
|
+
assetsRouter.get("/favicon.ico", (c) => {
|
|
4617
|
+
const buffer = Uint8Array.from(atob(FAVICON_BASE64), (c2) => c2.charCodeAt(0));
|
|
4618
|
+
return new Response(buffer, {
|
|
4619
|
+
headers: {
|
|
4620
|
+
"Content-Type": "image/png",
|
|
4621
|
+
"Cache-Control": "public, max-age=31536000"
|
|
4622
|
+
}
|
|
4623
|
+
});
|
|
4624
|
+
});
|
|
4625
|
+
assetsRouter.get("/favicon.png", (c) => {
|
|
4626
|
+
const buffer = Uint8Array.from(atob(FAVICON_BASE64), (c2) => c2.charCodeAt(0));
|
|
4627
|
+
return new Response(buffer, {
|
|
4628
|
+
headers: {
|
|
4629
|
+
"Content-Type": "image/png",
|
|
4630
|
+
"Cache-Control": "public, max-age=31536000"
|
|
4631
|
+
}
|
|
4632
|
+
});
|
|
4633
|
+
});
|
|
4634
|
+
assetsRouter.get("/og-image.png", async (c) => {
|
|
4635
|
+
const svg = `<svg width="1200" height="630" xmlns="http://www.w3.org/2000/svg">
|
|
4636
|
+
<rect width="100%" height="100%" fill="#0a0a0a"/>
|
|
4637
|
+
<text x="100" y="150" font-family="monospace" font-size="72" font-weight="bold" fill="#fff">SKILLMARK</text>
|
|
4638
|
+
<text x="100" y="210" font-family="monospace" font-size="24" fill="#888">THE AGENT SKILL BENCHMARKING PLATFORM</text>
|
|
4639
|
+
<text x="100" y="320" font-family="sans-serif" font-size="36" fill="#ccc">Benchmark your AI agent skills with detailed</text>
|
|
4640
|
+
<text x="100" y="370" font-family="sans-serif" font-size="36" fill="#ccc">metrics. Compare accuracy, token usage, and</text>
|
|
4641
|
+
<text x="100" y="420" font-family="sans-serif" font-size="36" fill="#ccc">cost across models.</text>
|
|
4642
|
+
<text x="100" y="540" font-family="monospace" font-size="20" fill="#666">$ npx skillmark run <skill-path></text>
|
|
4643
|
+
</svg>`;
|
|
4644
|
+
return new Response(svg, {
|
|
4645
|
+
headers: {
|
|
4646
|
+
"Content-Type": "image/svg+xml",
|
|
4647
|
+
"Cache-Control": "public, max-age=86400"
|
|
4648
|
+
}
|
|
4649
|
+
});
|
|
4650
|
+
});
|
|
4651
|
+
|
|
4652
|
+
// src/worker-entry-point.ts
|
|
4653
|
+
var app = new Hono2();
|
|
4654
|
+
app.use("*", cors({
|
|
4655
|
+
origin: "*",
|
|
4656
|
+
allowMethods: ["GET", "POST", "OPTIONS"],
|
|
4657
|
+
allowHeaders: ["Content-Type", "Authorization", "X-Skillmark-Version"]
|
|
4658
|
+
}));
|
|
4659
|
+
app.use("*", async (c, next) => {
|
|
4660
|
+
if (c.env.ENVIRONMENT !== "production") {
|
|
4661
|
+
return logger()(c, next);
|
|
4662
|
+
}
|
|
4663
|
+
return next();
|
|
4664
|
+
});
|
|
4665
|
+
app.get("/health", (c) => {
|
|
4666
|
+
return c.json({ status: "ok", timestamp: (/* @__PURE__ */ new Date()).toISOString() });
|
|
4667
|
+
});
|
|
4668
|
+
app.route("/", assetsRouter);
|
|
4669
|
+
app.route("/auth", authRouter);
|
|
4670
|
+
app.route("/api", apiRouter);
|
|
4671
|
+
app.route("/", pagesRouter);
|
|
4672
|
+
app.notFound((c) => {
|
|
4673
|
+
const accept = c.req.header("Accept") || "";
|
|
4674
|
+
if (accept.includes("application/json")) {
|
|
4675
|
+
return c.json({ error: "Not found" }, 404);
|
|
4676
|
+
}
|
|
4677
|
+
return c.html(`
|
|
4678
|
+
<!DOCTYPE html>
|
|
4679
|
+
<html>
|
|
4680
|
+
<head>
|
|
4681
|
+
<title>404 - Skillmark</title>
|
|
4682
|
+
<style>
|
|
4683
|
+
body {
|
|
4684
|
+
font-family: system-ui, sans-serif;
|
|
4685
|
+
background: #0d1117;
|
|
4686
|
+
color: #c9d1d9;
|
|
4687
|
+
display: flex;
|
|
4688
|
+
justify-content: center;
|
|
4689
|
+
align-items: center;
|
|
4690
|
+
min-height: 100vh;
|
|
4691
|
+
margin: 0;
|
|
4692
|
+
}
|
|
4693
|
+
.container { text-align: center; }
|
|
4694
|
+
h1 { color: #58a6ff; }
|
|
4695
|
+
a { color: #58a6ff; }
|
|
4696
|
+
</style>
|
|
4697
|
+
</head>
|
|
4698
|
+
<body>
|
|
4699
|
+
<div class="container">
|
|
4700
|
+
<h1>404</h1>
|
|
4701
|
+
<p>Page not found</p>
|
|
4702
|
+
<p><a href="/">Back to leaderboard</a></p>
|
|
4703
|
+
</div>
|
|
4704
|
+
</body>
|
|
4705
|
+
</html>
|
|
4706
|
+
`, 404);
|
|
4707
|
+
});
|
|
4708
|
+
app.onError((err, c) => {
|
|
4709
|
+
console.error("Unhandled error:", err);
|
|
4710
|
+
const accept = c.req.header("Accept") || "";
|
|
4711
|
+
if (accept.includes("application/json")) {
|
|
4712
|
+
return c.json({ error: "Internal server error" }, 500);
|
|
4713
|
+
}
|
|
4714
|
+
return c.html(`
|
|
4715
|
+
<!DOCTYPE html>
|
|
4716
|
+
<html>
|
|
4717
|
+
<head>
|
|
4718
|
+
<title>Error - Skillmark</title>
|
|
4719
|
+
<style>
|
|
4720
|
+
body {
|
|
4721
|
+
font-family: system-ui, sans-serif;
|
|
4722
|
+
background: #0d1117;
|
|
4723
|
+
color: #c9d1d9;
|
|
4724
|
+
display: flex;
|
|
4725
|
+
justify-content: center;
|
|
4726
|
+
align-items: center;
|
|
4727
|
+
min-height: 100vh;
|
|
4728
|
+
margin: 0;
|
|
4729
|
+
}
|
|
4730
|
+
.container { text-align: center; }
|
|
4731
|
+
h1 { color: #f85149; }
|
|
4732
|
+
a { color: #58a6ff; }
|
|
4733
|
+
</style>
|
|
4734
|
+
</head>
|
|
4735
|
+
<body>
|
|
4736
|
+
<div class="container">
|
|
4737
|
+
<h1>Error</h1>
|
|
4738
|
+
<p>Something went wrong</p>
|
|
4739
|
+
<p><a href="/">Back to leaderboard</a></p>
|
|
4740
|
+
</div>
|
|
4741
|
+
</body>
|
|
4742
|
+
</html>
|
|
4743
|
+
`, 500);
|
|
4744
|
+
});
|
|
4745
|
+
var worker_entry_point_default = app;
|
|
4746
|
+
|
|
4747
|
+
// ../../node_modules/.pnpm/wrangler@3.114.17_@cloudflare+workers-types@4.20260203.0/node_modules/wrangler/templates/middleware/middleware-ensure-req-body-drained.ts
|
|
4748
|
+
var drainBody = /* @__PURE__ */ __name(async (request, env, _ctx, middlewareCtx) => {
|
|
4749
|
+
try {
|
|
4750
|
+
return await middlewareCtx.next(request, env);
|
|
4751
|
+
} finally {
|
|
4752
|
+
try {
|
|
4753
|
+
if (request.body !== null && !request.bodyUsed) {
|
|
4754
|
+
const reader = request.body.getReader();
|
|
4755
|
+
while (!(await reader.read()).done) {
|
|
4756
|
+
}
|
|
4757
|
+
}
|
|
4758
|
+
} catch (e) {
|
|
4759
|
+
console.error("Failed to drain the unused request body.", e);
|
|
4760
|
+
}
|
|
4761
|
+
}
|
|
4762
|
+
}, "drainBody");
|
|
4763
|
+
var middleware_ensure_req_body_drained_default = drainBody;
|
|
4764
|
+
|
|
4765
|
+
// ../../node_modules/.pnpm/wrangler@3.114.17_@cloudflare+workers-types@4.20260203.0/node_modules/wrangler/templates/middleware/middleware-miniflare3-json-error.ts
|
|
4766
|
+
function reduceError(e) {
|
|
4767
|
+
return {
|
|
4768
|
+
name: e?.name,
|
|
4769
|
+
message: e?.message ?? String(e),
|
|
4770
|
+
stack: e?.stack,
|
|
4771
|
+
cause: e?.cause === void 0 ? void 0 : reduceError(e.cause)
|
|
4772
|
+
};
|
|
4773
|
+
}
|
|
4774
|
+
__name(reduceError, "reduceError");
|
|
4775
|
+
var jsonError = /* @__PURE__ */ __name(async (request, env, _ctx, middlewareCtx) => {
|
|
4776
|
+
try {
|
|
4777
|
+
return await middlewareCtx.next(request, env);
|
|
4778
|
+
} catch (e) {
|
|
4779
|
+
const error = reduceError(e);
|
|
4780
|
+
return Response.json(error, {
|
|
4781
|
+
status: 500,
|
|
4782
|
+
headers: { "MF-Experimental-Error-Stack": "true" }
|
|
4783
|
+
});
|
|
4784
|
+
}
|
|
4785
|
+
}, "jsonError");
|
|
4786
|
+
var middleware_miniflare3_json_error_default = jsonError;
|
|
4787
|
+
|
|
4788
|
+
// .wrangler/tmp/bundle-lfa2r7/middleware-insertion-facade.js
|
|
4789
|
+
var __INTERNAL_WRANGLER_MIDDLEWARE__ = [
|
|
4790
|
+
middleware_ensure_req_body_drained_default,
|
|
4791
|
+
middleware_miniflare3_json_error_default
|
|
4792
|
+
];
|
|
4793
|
+
var middleware_insertion_facade_default = worker_entry_point_default;
|
|
4794
|
+
|
|
4795
|
+
// ../../node_modules/.pnpm/wrangler@3.114.17_@cloudflare+workers-types@4.20260203.0/node_modules/wrangler/templates/middleware/common.ts
|
|
4796
|
+
var __facade_middleware__ = [];
|
|
4797
|
+
function __facade_register__(...args) {
|
|
4798
|
+
__facade_middleware__.push(...args.flat());
|
|
4799
|
+
}
|
|
4800
|
+
__name(__facade_register__, "__facade_register__");
|
|
4801
|
+
function __facade_invokeChain__(request, env, ctx, dispatch, middlewareChain) {
|
|
4802
|
+
const [head, ...tail] = middlewareChain;
|
|
4803
|
+
const middlewareCtx = {
|
|
4804
|
+
dispatch,
|
|
4805
|
+
next(newRequest, newEnv) {
|
|
4806
|
+
return __facade_invokeChain__(newRequest, newEnv, ctx, dispatch, tail);
|
|
4807
|
+
}
|
|
4808
|
+
};
|
|
4809
|
+
return head(request, env, ctx, middlewareCtx);
|
|
4810
|
+
}
|
|
4811
|
+
__name(__facade_invokeChain__, "__facade_invokeChain__");
|
|
4812
|
+
function __facade_invoke__(request, env, ctx, dispatch, finalMiddleware) {
|
|
4813
|
+
return __facade_invokeChain__(request, env, ctx, dispatch, [
|
|
4814
|
+
...__facade_middleware__,
|
|
4815
|
+
finalMiddleware
|
|
4816
|
+
]);
|
|
4817
|
+
}
|
|
4818
|
+
__name(__facade_invoke__, "__facade_invoke__");
|
|
4819
|
+
|
|
4820
|
+
// .wrangler/tmp/bundle-lfa2r7/middleware-loader.entry.ts
|
|
4821
|
+
var __Facade_ScheduledController__ = class {
|
|
4822
|
+
constructor(scheduledTime, cron, noRetry) {
|
|
4823
|
+
this.scheduledTime = scheduledTime;
|
|
4824
|
+
this.cron = cron;
|
|
4825
|
+
this.#noRetry = noRetry;
|
|
4826
|
+
}
|
|
4827
|
+
#noRetry;
|
|
4828
|
+
noRetry() {
|
|
4829
|
+
if (!(this instanceof __Facade_ScheduledController__)) {
|
|
4830
|
+
throw new TypeError("Illegal invocation");
|
|
4831
|
+
}
|
|
4832
|
+
this.#noRetry();
|
|
4833
|
+
}
|
|
4834
|
+
};
|
|
4835
|
+
__name(__Facade_ScheduledController__, "__Facade_ScheduledController__");
|
|
4836
|
+
function wrapExportedHandler(worker) {
|
|
4837
|
+
if (__INTERNAL_WRANGLER_MIDDLEWARE__ === void 0 || __INTERNAL_WRANGLER_MIDDLEWARE__.length === 0) {
|
|
4838
|
+
return worker;
|
|
4839
|
+
}
|
|
4840
|
+
for (const middleware of __INTERNAL_WRANGLER_MIDDLEWARE__) {
|
|
4841
|
+
__facade_register__(middleware);
|
|
4842
|
+
}
|
|
4843
|
+
const fetchDispatcher = /* @__PURE__ */ __name(function(request, env, ctx) {
|
|
4844
|
+
if (worker.fetch === void 0) {
|
|
4845
|
+
throw new Error("Handler does not export a fetch() function.");
|
|
4846
|
+
}
|
|
4847
|
+
return worker.fetch(request, env, ctx);
|
|
4848
|
+
}, "fetchDispatcher");
|
|
4849
|
+
return {
|
|
4850
|
+
...worker,
|
|
4851
|
+
fetch(request, env, ctx) {
|
|
4852
|
+
const dispatcher = /* @__PURE__ */ __name(function(type, init) {
|
|
4853
|
+
if (type === "scheduled" && worker.scheduled !== void 0) {
|
|
4854
|
+
const controller = new __Facade_ScheduledController__(
|
|
4855
|
+
Date.now(),
|
|
4856
|
+
init.cron ?? "",
|
|
4857
|
+
() => {
|
|
4858
|
+
}
|
|
4859
|
+
);
|
|
4860
|
+
return worker.scheduled(controller, env, ctx);
|
|
4861
|
+
}
|
|
4862
|
+
}, "dispatcher");
|
|
4863
|
+
return __facade_invoke__(request, env, ctx, dispatcher, fetchDispatcher);
|
|
4864
|
+
}
|
|
4865
|
+
};
|
|
4866
|
+
}
|
|
4867
|
+
__name(wrapExportedHandler, "wrapExportedHandler");
|
|
4868
|
+
function wrapWorkerEntrypoint(klass) {
|
|
4869
|
+
if (__INTERNAL_WRANGLER_MIDDLEWARE__ === void 0 || __INTERNAL_WRANGLER_MIDDLEWARE__.length === 0) {
|
|
4870
|
+
return klass;
|
|
4871
|
+
}
|
|
4872
|
+
for (const middleware of __INTERNAL_WRANGLER_MIDDLEWARE__) {
|
|
4873
|
+
__facade_register__(middleware);
|
|
4874
|
+
}
|
|
4875
|
+
return class extends klass {
|
|
4876
|
+
#fetchDispatcher = (request, env, ctx) => {
|
|
4877
|
+
this.env = env;
|
|
4878
|
+
this.ctx = ctx;
|
|
4879
|
+
if (super.fetch === void 0) {
|
|
4880
|
+
throw new Error("Entrypoint class does not define a fetch() function.");
|
|
4881
|
+
}
|
|
4882
|
+
return super.fetch(request);
|
|
4883
|
+
};
|
|
4884
|
+
#dispatcher = (type, init) => {
|
|
4885
|
+
if (type === "scheduled" && super.scheduled !== void 0) {
|
|
4886
|
+
const controller = new __Facade_ScheduledController__(
|
|
4887
|
+
Date.now(),
|
|
4888
|
+
init.cron ?? "",
|
|
4889
|
+
() => {
|
|
4890
|
+
}
|
|
4891
|
+
);
|
|
4892
|
+
return super.scheduled(controller);
|
|
4893
|
+
}
|
|
4894
|
+
};
|
|
4895
|
+
fetch(request) {
|
|
4896
|
+
return __facade_invoke__(
|
|
4897
|
+
request,
|
|
4898
|
+
this.env,
|
|
4899
|
+
this.ctx,
|
|
4900
|
+
this.#dispatcher,
|
|
4901
|
+
this.#fetchDispatcher
|
|
4902
|
+
);
|
|
4903
|
+
}
|
|
4904
|
+
};
|
|
4905
|
+
}
|
|
4906
|
+
__name(wrapWorkerEntrypoint, "wrapWorkerEntrypoint");
|
|
4907
|
+
var WRAPPED_ENTRY;
|
|
4908
|
+
if (typeof middleware_insertion_facade_default === "object") {
|
|
4909
|
+
WRAPPED_ENTRY = wrapExportedHandler(middleware_insertion_facade_default);
|
|
4910
|
+
} else if (typeof middleware_insertion_facade_default === "function") {
|
|
4911
|
+
WRAPPED_ENTRY = wrapWorkerEntrypoint(middleware_insertion_facade_default);
|
|
4912
|
+
}
|
|
4913
|
+
var middleware_loader_entry_default = WRAPPED_ENTRY;
|
|
4914
|
+
export {
|
|
4915
|
+
__INTERNAL_WRANGLER_MIDDLEWARE__,
|
|
4916
|
+
middleware_loader_entry_default as default
|
|
4917
|
+
};
|
|
4918
|
+
//# sourceMappingURL=worker-entry-point.js.map
|