21</html>`;
22
23export function redirect(location: string): Response {
24 return new Response(null, {
25 headers: {
35};
36
37async function fetchUser(token: string): Promise<User> {
38 const resp = await fetch("https://api.val.town/v1/me", {
39 headers: {
49}
50
51async function isCurrentUser(userID: string) {
52 const currentUser = await fetchUser(Deno.env.get("valtown"));
53 return userID == currentUser.id;
54}
55
56function signout() {
57 const res = redirect("/");
58 cookie.setCookie(res.headers, {
67}
68
69export function auth(handler) {
70 const secretKey = Deno.env.get("AUTH_SECRET_KEY");
71 if (!secretKey) {
1import { OpenAI } from "https://esm.town/v/std/openai";
2
3export default async function(req: Request): Promise<Response> {
4 if (req.method === "OPTIONS") {
5 return new Response(null, {
2import { getWeather } from "https://esm.town/v/stevekrouse/getWeather?v=2";
3
4export default async function(interval: Interval) {
5 let weather = await getWeather("Brooklyn, NY");
6 let temperature = weather.current_condition[0].FeelsLikeF;
5const BASE_URL = "https://stevekrouse-cors_example_backend.web.val.run";
6
7export function App() {
8 const [logs, setLogs] = useState([]);
9 async function request(url, options) {
10 try {
11 const response = await fetch(url, options);
3import { OpenAI } from "https://esm.town/v/std/OpenAI";
4
5async function getValByAlias({ author, name }: { author: string; name: string }) {
6 const { id, code, readme } = await api(`/v1/alias/${author}/${name}`, {
7 authenticated: true,
11}
12
13async function updateValCode({ id, code }: { id: string; code: string }) {
14 console.log({ id, code });
15 await api(`/v1/vals/${id}/versions`, {
25}
26
27async function sendEmail({ subject, text }: { subject: string; text: string }) {
28 await email({
29 subject,
66
67Do not communicate with the user directly.
68Instead, use the provided functions to accomplish your task on the behalf of the user.
69
70For example, if you need to modify the code of a val, use the updateValCode function.
71`;
72
73type Tool = {
74 type: "function";
75 function: {
76 function: (...args: any[]) => any;
77 description: string;
78 parse: (...args: any[]) => any;
87};
88
89export function askAI(content: string) {
90 const client = new OpenAI();
91 const runner = client.beta.chat.completions.runTools({
96 }],
97 tools: [{
98 type: "function",
99 function: {
100 function: getValByAlias,
101 description: "Get val info (id, code) from it's alias",
102 parse: JSON.parse,
115 },
116 }, {
117 type: "function",
118 function: {
119 function: updateValCode,
120 description: "update the javascript code of a val",
121 parse: JSON.parse,
134 },
135 }, {
136 type: "function",
137 function: {
138 function: sendEmail,
139 description: "send an email",
140 parse: JSON.parse,