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 });
5import { Form, hydrate } from "https://esm.town/v/stevekrouse/ssr_react_mini?v=75";
67export async function loader(req: Request) {
8const { sqlite } = await import("https://esm.town/v/std/sqlite?v=4");
9const [, { columns, rows }] = await sqlite.batch([
20}
2122export async function action(req: Request) {
23const { sqlite } = await import("https://esm.town/v/std/sqlite?v=4");
24const formData = await req.formData();
47}
4849export function Component({ initialTodos, initialLogs }) {
50const [todos, setTodos] = useState(initialTodos);
51const [logs, setLogs] = useState(initialLogs);
54useEffect(() => addLog(`Client rendered`), []);
5556function addTodo() {
57setTodos([...todos, { text: newTodo }]);
58setNewTodo("");
64}
6566function toggleTodo(e) {
67const formData = new FormData(e.target);
68const id = parseInt(formData.get("id") as string);
71}
7273function deleteTodo(e) {
74const formData = new FormData(e.target);
75const id = parseInt(formData.get("id") as string);
weatherBotmain.tsx11 matches
9"latLngOfCity": {
10openAiTool: {
11type: "function",
12function: {
13name: "latLngOfCity",
14description: "Get the latitude and longitude of a city",
34"weatherOfLatLon": {
35openAiTool: {
36type: "function",
37function: {
38name: "weatherOfLatLon",
39description: "Get the latitude and longitude of a city",
61"fetchWebpage": {
62openAiTool: {
63type: "function",
64function: {
65name: "fetchWebpage",
66description: "Fetch the weather forecast from the contents of a forecast URL",
87];
8889function truncate(response: string | object) {
90const TRUNCATE_LEN = 60
91const responseStr = typeof response === "string" ? response : JSON.stringify(response)
93}
9495async function runConversation() {
96const response = await openai.chat.completions.create({
97messages: transcript,
105if (message.tool_calls) {
106for (let i = 0; i < message.tool_calls.length; i++) {
107console.log("[CALLING]", message.tool_calls[i].function);
108const tool = toolbox[message.tool_calls[i].function.name];
109if (tool) {
110const result = await tool.call(JSON.parse(message.tool_calls[i].function.arguments));
111console.log("[RESULT]", truncate(result));
112transcript.push({