5import { secp256k1 } from "npm:@noble/curves/secp256k1";
67export function decompressPoint(bytes: Uint8Array, curve: string) {
8if (curve === "P-256") {
9const point = p256.ProjectivePoint.fromHex(bytes);
17}
1819function pointToBytes<T>(point: ProjPointType<T>, Fp: IField<T>) {
20const x = Fp.toBytes(point.x);
21const y = Fp.toBytes(point.y);
2425// @see: https://stackoverflow.com/questions/17171542/algorithm-for-elliptic-curve-point-compression
26export function compressPoint({ x, y }: { x: Uint8Array; y: Uint8Array }) {
27const compressed = new Uint8Array(x.length + 1);
28compressed[0] = 2 + (y.at(-1) & 1);
counterscaleWeeklyReportmain.tsx2 matches
56// borrowed from: https://github.com/benvinegar/counterscale/blob/main/app/analytics/query.ts#L24
7function accumulateCountsFromRowResult(
8counts,
9row: {
22}
2324export default async function(interval: Interval) {
25// you need to declare these two environment variables:
26
roseDragonmain.tsx1 match
1import { fetch } from "https://esm.town/v/std/fetch";
23export async function uploadTo0x0(data, name) {
4const blob = new Blob([data]);
5const formData = new FormData();
11};
1213export async function prompt(
14text,
15{ mode = "text", model = "opus", max_tokens = 1024, messages = [] } = {},
viewSourcemain.tsx1 match
3import { escape } from "npm:html-sloppy-escaper";
45export default async function viewSource(req: Request) {
6const pathname = new URL(req.url).pathname;
7const html = await fetchText(
218];
219220async function migrate() {
221await std_sqlite.execute(`
222create table if not exists tracing_schema (
369}
370371export async function init(
372url: string | URL,
373): Promise<void> {
394}
395396export function tracer(): Tracer {
397return otelTrace.getTracer("val.town");
398}
399400export function attribute(name: string, value: string): void {
401otelTrace.getActiveSpan()?.setAttribute(name, value);
402}
403404export function event(name: string, attrs: Record<string, string>): void {
405otelTrace.getActiveSpan()?.addEvent(name, attrs);
406}
407408export function trace<
409// deno-lint-ignore no-explicit-any
410F extends (...args: any[]) => any,
428}
429430export async function traceAsync<
431// deno-lint-ignore no-explicit-any
432F extends (...args: any[]) => any,
454}
455456export function traced<
457// deno-lint-ignore no-explicit-any
458F extends (...args: any[]) => any,
459>(name: string, f: F) {
460return async function (
461...args: Parameters<F>
462): Promise<Awaited<ReturnType<F>>> {
470* be tied together.
471*/
472export async function fetch(
473input: string | URL,
474init?: RequestInit,
511}
512513async function tracedExecute(statement: InStatement): Promise<ResultSet> {
514return await tracer().startActiveSpan(
515`sqlite:execute`,
544}
545546async function tracedBatch(
547statements: InStatement[],
548mode?: TransactionMode,
603* Takes an http handler and returns a new handler that
604* traces the request.
605* @returns {Function} A new handler that traces the request.
606*/
607export function tracedHandler(
608handler: (req: Request) => Promise<Response>,
609): (req: Request) => Promise<Response> {
610async function _tracedHandler(req: Request): Promise<Response> {
611let active_context = null;
612const prop_header = req.headers.get("b3");
930931const render_spans: SelectSpan[] = [];
932function push_span(span_id: string) {
933const span = spans_by_id.get(span_id)!;
934render_spans.push(span);
10691070const render_spans: SelectSpan[] = [];
1071function push_span(span_id: string) {
1072const span = spans_by_id.get(span_id)!;
1073render_spans.push(span);
1246});
12471248export async function traceViewer(req: Request): Promise<Response> {
1249await migrate();
1250return await app.fetch(req);
message_processormain.tsx1 match
1import { command_processor } from "https://esm.town/v/curtcox/command_processor?v=14";
23function tail(text: string): string {
4const trimmed = text.trimStart();
5const index = trimmed.indexOf(" ");
19await init(import.meta.url);
2021async function handler(req: Request): Promise<Response> {
22// whatever else you do.
23return
63```
6465* `traced` wraps an async function in tracing.
6667```typescript
68import { traceAsync } from "https://esm.town/v/saolsen/telemetry";
6970const myTracedFunction: () => Promise<string> = traced(
71"myTracedFunction",
72async () => {
73// await sleep(100);
77```
7879* `fetch` is a traced version of the builtin `fetch` function that traces the request. Just import it and use it like you would use `fetch`.
8081* `sqlite` is a traced version of the val town sqlite client. Just import it and use it like you would use [https://www.val.town/v/std/sqlite](https://www.val.town/v/std/sqlite)
9user: "website that shows the current time",
10content: `/** @jsxImportSource npm:react */
11export default function() {
12return <h1>{new Date().toLocaleTimeString()}</h1>;
13}`,
66);
67});
68export async function compile(description: string) {
69const messages = [
70{
74You write Deno TypeScript.
75Reply ONLY with valid Typescript.
76Export the fetch function to run the server.
77Only use web standard fetch. Export the fetch function to start the server.
78Add extensive comments`,
79},
discordEventReceivermain.tsx1 match
1export default async function handler(req: Request) {
2if (req.method !== 'POST') {
3return new Response('Method not allowed', { status: 405 });