6 * This includes a fallback to inference calls data when usage data is missing
7 */
8export async function getUserSummary() {
9 // First, get the standard grouped data from the usage table
10 const groupedUsageData = await sqlite.execute(`
5const FILES_ENDPOINT = "/api/project-files";
6
7export function useProject (projectId: string, branchId?: string) {
8 const { token } = useAuth();
9 const [data, setData] = useState<any>(null);
4const ENDPOINT = "/api/projects-loader";
5
6export function useProjects () {
7 const { token } = useAuth();
8 const [data, setData] = useState<any>(null);
1import { useEffect } from "https://esm.sh/react@18.2.0?dev";
2
3function setLoadingFavicon() {
4 document.querySelector('link[rel="icon"]').href = "/favicon-loading.svg";
5}
6function resetFavicon () {
7 document.querySelector('link[rel="icon"]').href = "/favicon.svg";
8}
9
10export function useLoadingFavicon (loading: boolean) {
11 useEffect(() => {
12 if (loading) setLoadingFavicon();
5const ENDPOINT = "/api/create-project";
6
7export function useCreateProject () {
8 const { token } = useAuth();
9 const [data, setData] = useState<any>(null);
4const ENDPOINT = "/api/create-branch";
5
6export function useCreateBranch (projectId: string) {
7 const { token } = useAuth();
8 const [data, setData] = useState<any>(null);
13}
14
15export function useChatLogic({
16 project,
17 branchId,
4const ENDPOINT = "/api/project-branches";
5
6export function useBranches (projectId: string) {
7 const { token } = useAuth();
8 const [data, setData] = useState<any>(null);
5const ANTHROPIC_KEY = "anthropic_api_key";
6
7export function useAuth() {
8 const [token, setToken, removeToken] = useLocalStorage(TOKEN_KEY, "");
9 const [anthropicApiKey, setAnthropicApiKey, removeAnthropicApiKey] = useLocalStorage(ANTHROPIC_KEY, "");
3import fileWithLinesNumbers from "../utils/fileWithLinesNumbers.ts";
4
5function printFileType(file: any){
6 if (file.type === "interval")
7 return " (cron)"
14 * View a file or directory in a Val Town project
15 */
16async function view(
17 vt: ValTown,
18 project: any,
71 * Replace a string in a file in a Val Town project
72 */
73async function str_replace(
74 vt: ValTown,
75 project: any,
133 * Create a new file in a Val Town project
134 */
135async function create(vt: ValTown, project: any, branch_id: string | undefined, path: string, file_text?: string) {
136 let type_: "file" | "http" | "script";
137 if (path.includes("backend/index.ts")) type_ = "http";
167 * Insert a string at a specific line in a file in a Val Town project
168 */
169async function insert(
170 vt: ValTown,
171 project: any,
210 * Undo the last edit to a file in a Val Town project (not implemented)
211 */
212async function undo_edit(vt: ValTown, project: any, branch_id: string | undefined) {
213 return {
214 type: "error",
220 * Creates a text editor tool for editing files in a Val Town project
221 */
222export function getTextEditorTool(bearerToken: string, project: any, branch_id: string | undefined) {
223 const vt = new ValTown({ bearerToken });
224 return anthropic.tools.textEditor_20250124({
A helper function to build a file's email
Simple functional CSS library for Val Town
import { OpenAI } from "https://esm.town/v/std/openai";
export default async function(req: Request): Promise<Response> {
if (req.method === "OPTIONS") {
return new Response(null, {
headers: {
"Access-Control-Allow-Origin": "*",
LangChain (https://langchain.com) Ambassador, KubeSphere (https://kubesphere.io) Ambassador, CNCF OpenFunction (https://openfunction.dev) TOC Member.