1export function runValAPI(name, ...args) {
2 return fetch(`https://api.val.town/v1/run/${name.replace("@", "")}`, {
3 method: "POST",
4 body: JSON.stringify({
7// Make an authenticated request to another user's val
8// Example usage: https://www.val.town/v/stevekrouse.authRequestEx
9export const runValAPIAuth = async ({ val, args, handle, privateKey, keys }: {
10 val: string;
11 args: any;
1import { runValAPIAuth } from "https://esm.town/v/stevekrouse/runValAPIAuth";
2
3// grab the types off turso's client without importing it
6
7export function turso(keys, handle?) {
8 let val = "@std.tursoAPI";
9 let f = (method) => (...args) =>
10 runValAPIAuth({
11 val,
12 args: [method, args],
2import { OpenAI } from "npm:openai";
3
4const openai = new OpenAI({ apiKey: process.env.openai });
5let chatCompletion = await openai.chat.completions.create({
6 messages: [{ role: "user", content: "Make a short joke or pun" }],
1import { saveToTana } from "https://esm.town/v/nbbaier/saveToTana";
2import { APIPlainNode } from "https://esm.town/v/nbbaier/tanaTypes";
3import { Hono } from "npm:hono";
4
5const token = Deno.env.get("tanaInputAPI");
6
7export const tanaSave = async (req: Request) => {
10 let { text, url } = c.req.query();
11
12 const payload: APIPlainNode = {
13 name: text,
14 children: [
1import { TanaAPIHelper } from "https://esm.town/v/nbbaier/TanaAPIHelper";
2import { tanaConstants } from "https://esm.town/v/nbbaier/tanaConstants";
3import { APIPlainNode } from "https://esm.town/v/nbbaier/tanaTypes";
4
5/** saveToTana - creates a node in Tana via the Tana Input API
6 * @param {string} token - Token for accessing the API.
7 * @param {APIPlainNode} node - Data node to be created in Tana.
8 * @param {string} targetNodeId - ID of the target node where the new node will be attached (defaults to the inbox)
9 * @returns {Promise<APIPlainNode>} - A promise that resolves to the created node.
10 */
11export const saveToTana = async (
12 token: string,
13 node: APIPlainNode,
14 targetNodeId: string = tanaConstants.inboxNodeId,
15) => {
16 const client = new TanaAPIHelper(token);
17 const createdNode = await client.createNode(node, targetNodeId);
18 return createdNode;
1export type APIDataType = "boolean" | "plain" | "date" | "url" | "reference";
2
3export type NodeType = "node" | undefined;
4
5export type CommonNodeProps = {
6 dataType?: APIDataType;
7 type?: NodeType;
8};
9
10export type APICheckboxNode = {
11 value: boolean;
12} & CommonNodeProps;
13
14export type APIDateNode = {
15 name: string;
16} & CommonNodeProps;
17
18export type APIReferenceNode = {
19 id: string;
20} & CommonNodeProps;
21
22export type APIFileNode = {
23 file: string;
24 contentType: string;
26} & CommonNodeProps;
27
28export type APINode = APIPlainNode | APIDateNode | APIReferenceNode | APIFileNode;
29export type APIFieldValue = APINode | APICheckboxNode;
30
31export type APIPlainNode = {
32 name: string;
33 description?: string;
34 supertags?: { id: string }[];
35 children?: (APIField | APINode)[];
36} & CommonNodeProps;
37
38export type APIField = {
39 type: "field";
40 attributeId: string;
41 children?: (APIPlainNode | APINode | APICheckboxNode)[];
42};
43
1# Save To Tana
2
3This val provides a function `saveToTana` allows the creation of nodes in [Tana](https://tana.inc/) via their [Input API](https://github.com/tanainc/tana-input-api-samples). The parameters are as follows:
4- **Token:** to access the Tana Input API, you must pass an API token to the function. Obtain an API token from the Tana app and save it as a secret in Val Town.
5- **Node:** the node that is created within Tana is passed as the second argument and must conform to the shape of an Input API node (see the [documentation](https://github.com/tanainc/tana-input-api-samples) on github for details.
6- **Target node:** optionally, you can specify a specific target node by passing a node ID to the function as it's third argument.
7
12```ts
13import { saveToTana } from "https://esm.town/v/nbbaier/saveToTana";
14import { APIPlainNode } from "https://esm.town/v/nbbaier/tanaTypes";
15import { Hono } from "npm:hono";
16
17const token = Deno.env.get("tanaInputAPI");
18
19export const honoTanaEndpoint = async (req: Request) => {
22 let { text, url } = c.req.query();
23
24 const payload: APIPlainNode = {
25 name: text,
26 children: [
3export const rateArticleRelevance = async (interests: string, article: any) => {
4 const { default: OpenAI } = await import("npm:openai");
5 const openai = new OpenAI({ apiKey: process.env.OPENAI_KEY });
6
7 try {
1export async function isSupported(jsInterface) {
2 const caniuse = await import("npm:caniuse-api");
3 return caniuse.getSupport("border-radius");
4}