16
17/**
18 * Simplified proof-of-concept function to test API connectivity
19 * This should return an immediate result we can inspect
20 */
21export default async function generateFeed() {
22 // First, let's return something immediately to confirm the function runs
23 console.log("Function started");
24
25 // Create a debug log to capture all outputs
26 let debugLog = [];
27 function log(message, data = null) {
28 let logEntry = { timestamp: new Date().toISOString(), message };
29 if (data) logEntry.data = data;
85 };
86 } catch (error) {
87 log("Error in test function", error.message);
88 log("Error stack", error.stack);
89
21import { AgentRegistry } from "https://esm.town/v/salon/mandate/agentRegistry.ts";
22import { MemoryLogger } from "https://esm.town/v/salon/mandate/logger.ts";
23// import { generateHtmlShellV2 } from "https://esm.town/v/salon/mandate/ui.ts"; // Will replace with new UI function
24import { WorkflowDefinition } from "https://esm.town/v/salon/mandate/interfaces.ts";
25import {
69};
70
71// Simple UI generation function (can be moved to a separate ui.ts file)
72// This will now pass workflow schemas to the client for dynamic form building.
73function generateHtmlWithWorkflowSelector(
74 workflows: Record<string, WorkflowDefinition>,
75 currentValUrl: string,
151 const workflowSchemas = JSON.parse(document.getElementById('workflowSchemasData').textContent);
152
153 workflowSelector.addEventListener('change', function() {
154 const selectedWorkflowId = this.value;
155 dynamicInputsContainer.innerHTML = ''; // Clear previous inputs
279
280// Main HTTP request handler
281export default async function(req: Request): Promise<Response> {
282 globalLogger.clear(); // Clear logs for each new request
283 const requestStartTime = Date.now();
284 // Using import.meta.url to get the current val's URL for the view source link
285 const currentValUrl = import.meta.url;
286 const requestLog = globalLogger.createLogFunction(`REQ-${requestStartTime}`, "RequestHandler");
287
288 requestLog("INFO", "RequestReceived", `${req.method} ${req.url}`);
16
17/** Main entry */
18export default async function generateFeed() {
19 try {
20 // Using hard-coded token instead of environment variable
3import { useEffect, useState } from "https://esm.sh/react@19";
4
5export function Section({ children, ...props }: any) {
6 const sectionClass = `p-5 rounded-3xl bg-neutral-400/15 ${props.className || ""}`;
7 return <div class={sectionClass}>{children}</div>;
93};
94
95// export function Input(props: any) {
96// const inputClass = "dark:bg-white dark:text-black bg-black text-white rounded-md px-3 py-1 ";
97// return <input class={inputClass} {...props} />;
98// }
99
100// export function Button(props: any) {
101// const buttonClass = "dark:bg-white dark:text-black bg-black text-white rounded-md px-3 py-1 ";
102// return <button class={buttonClass} {...props} />;
103// }
104
105export function MonoButton(props: any) {
106 return (
107 <Button {...props}>
111}
112
113export function MonoButtonWithStatus(props: any) {
114 const [status, setStatus] = useState<any>();
115 const handleClick = async () => {
132}
133
134export function formatJSON(json: any) {
135 return JSON.stringify(json, null, 2);
136}
146};
147
148export function BackButton({}) {
149 return <ArrowLeft className="w-5 h-5 m-2 cursor-pointer opacity-50" onClick={() => window.location.href = "/"} />;
150}
151
152export function ShareButton({ onClick }) {
153 return <Share className="w-5 h-5 m-2 cursor-pointer opacity-50" onClick={onClick} />;
154}
1const baseUrl = "https://api.neynar.com/v2/farcaster/";
2
3export async function fetchNeynarGet(path: string) {
4 const res = await fetch(baseUrl + path, {
5 method: "GET",
14}
15
16export function fetchUser(username: string) {
17 return fetchNeynarGet(`user/by_username?username=${username}`).then(r => r.user);
18}
19export function fetchUsersById(fids: string) {
20 return fetchNeynarGet(`user/bulk?fids=${fids}`).then(r => r.users);
21}
22
23export function fetchUserFeed(fid: number) {
24 return fetchNeynarGet(
25 `feed?feed_type=filter&filter_type=fids&fids=${fid}&with_recasts=false&with_replies=false&limit=100&cursor=`,
27}
28
29export function fetchChannel(channelId: string) {
30 return fetchNeynarGet(`channel?id=${channelId}`).then(r => r.channel);
31}
32
33export function fetchChannelFeed(channelId: string) {
34 return fetchNeynarGet(
35 `feed/channels?channel_ids=${channelId}&with_recasts=false&limit=100`,
37}
38
39export function fetchChannelsFeed(channelIds: array) {
40 return fetchNeynarGet(
41 `feed/channels?channel_ids=${channelIds.join(",")}&with_recasts=false&limit=100`,
35});
36
37function generateHtml(baseUrl: string, path: string = "/"): any {
38 return (
39 <html>
5import satori from "npm:satori";
6
7export function handleImageEndpoints(app: Hono) {
8 const headers = {
9 "Content-Type": "image/png",
18}
19
20export async function homeImage() {
21 return await ogImage(
22 <div tw="w-full h-full flex justify-start items-end text-[100px] bg-black text-white p-[50px]">
31}
32
33export async function iconImage() {
34 return await ogImage(
35 <div tw="w-full h-full flex justify-center items-center text-[100px] bg-black text-white p-[50px]">
45//////////
46
47export async function ogImage(body, options = {}) {
48 const svg = await satori(
49 body,
9import { fetchUsersById } from "../util/neynar.ts";
10
11export function Home() {
12 return (
13 <div class="p-5 mb-8">
7// export const ogImageUrl = "https://imgur.com/xKVOVUE.png";
8
9export function embedMetadata(baseUrl: string, path: string = "/") {
10 return {
11 version: "next",
24}
25
26export function handleFarcasterEndpoints(app: Hono) {
27 app.get("/.well-known/farcaster.json", (c) => {
28 const baseUrl = c.req.url.replace(c.req.path, "");
90const decodeBase64Json = (str: string) => JSON.parse(Buffer.from(str, "base64").toString("utf-8"));
91
92async function sendWelcomeNotification(fid: number, baseUrl: string) {
93 return await sendNotificationToUser(fid, {
94 title: name + " installed!",
3const dbKey = "fc-notification-details-by-fid";
4
5export async function saveUserNotificationsDetails(fid: number, notificationDetails: any) {
6 let notificationDetailsByFid: any = await db.get(dbKey) || {};
7 notificationDetailsByFid[fid] = notificationDetails;
10}
11
12export async function getUserNotificationsDetails(fid: number) {
13 let notificationDetailsByFid: any = await db.get(dbKey) || {};
14 return notificationDetailsByFid[fid];
15}
16
17export async function sendNotificationToUser(fid: number, payload: any) {
18 const notificationDetails = await getUserNotificationsDetails(fid);
19 if (!notificationDetails) {
26}
27
28export async function sendNotificationToAllUsers(payload: any) {
29 let notificationDetailsByFid: any = await db.get(dbKey) || {};
30
40}
41
42async function sendNotification(notificationDetails: any, payload: any) {
43 return await fetch(notificationDetails.url, {
44 method: "POST",