28const projectUrl = `https://www.val.town/x/${username}/${projectName}`;
2930// First, get the project ID by fetching the project details
31let projectId;
32let endpointUrl: string | undefined; // Initialize as undefined, explicitly type
33try {
34const projectResponse = await fetch(`https://api.val.town/v1/alias/projects/${username}/${projectName}`, {
35headers: {
36"Authorization": `Bearer ${apiKey}`,
49}
5051// Fetch the project files to get the endpoint URL
52const filesResponse = await fetch(`https://api.val.town/v1/projects/${projectId}/files?path=`, {
53headers: {
54"Authorization": `Bearer ${apiKey}`,
5758if (!filesResponse.ok) {
59// Still throw if fetching files fails
60throw new Error(`Failed to get project files: ${filesResponse.status}`);
61}
73}
74} catch (error) {
75// Catch errors from fetching project details or files (but not the missing endpoint specifically)
76console.error("Error getting project details or files:", error);
77// Rethrow because fetching project details is critical for proceeding
78throw new Error(`Error preparing project details: ${error.message}`);
79}
97try {
98// First, get the val ID
99const valResponse = await fetch(`https://api.val.town/v1/alias/${valOwner}/${valName}`, {
100headers: {
101"Authorization": `Bearer ${apiKey}`,
104105if (!valResponse.ok) {
106throw new Error(`Failed to fetch val details: ${valResponse.status}`);
107}
108122const redirectCode = `export default async function(req: Request): Promise<Response> {
123const url = new URL(req.url);
124return fetch(new URL(url.pathname + url.search, "${endpointUrl}"), {
125method: req.method,
126headers: req.headers,
148console.log(`Version update body for ${valOwner}/${valName}:`, JSON.stringify(versionUpdateBody).substring(0, 200) + "...");
149150const versionUpdateResponse = await fetch(versionUpdateUrl, {
151method: "POST",
152headers: {
174};
175176const readmeUpdateResponse = await fetch(readmeUpdateUrl, {
177method: "PUT", // Use PUT as documented for updating val properties
178headers: {
3// Define an intermediate type for the processing array
4interface ProcessingValInfo extends ValInfo {
5val?: any; // Store the fetched val data here
6success: boolean;
7error?: string;
34// Use existing project
35projectId = existingProjectId;
36// Fetch existing project details to get name and author
37const projectDetailsResponse = await fetch(`https://api.val.town/v1/projects/${projectId}`, {
38headers: { "Authorization": `Bearer ${apiKey}` },
39});
40if (!projectDetailsResponse.ok) {
41const errorText = await projectDetailsResponse.text();
42throw new Error(`Failed to fetch existing project details: ${errorText}`);
43}
44const projectDetails = await projectDetailsResponse.json();
6768// Create the new project
69const projectResponse = await fetch("https://api.val.town/v1/projects", {
70method: "POST",
71headers: {
100const convertedVals: ProcessingValInfo[] = []; // Use the defined type here
101102// First pass: fetch all vals and track them
103for (const valInfo of vals) {
104try {
105// Fetch the val details
106const valResponse = await fetch(`https://api.val.town/v1/alias/${valInfo.username}/${valInfo.valName}`, {
107headers: { "Authorization": `Bearer ${apiKey}` },
108});
115valName: valInfo.valName,
116success: false,
117error: `Failed to fetch val: ${errorText}`,
118});
119continue;
131username: valInfo.username,
132valName: valInfo.valName,
133val: val, // Store the fetched val
134success: true,
135});
155156// Add the file to the project (use the determined projectId)
157const fileResponse = await fetch(`https://api.val.town/v1/projects/${projectId}/files?path=${filePath}`, {
158method: "POST",
159headers: {
188// Generate and add README.md
189const readmeContent = generateReadme(finalProjectName, vals, convertedVals);
190await fetch(`https://api.val.town/v1/projects/${projectId}/files/README.md`, {
191method: "POST",
192headers: {
32let func = `(async () => {
33try {
34await fetch(import.meta.url, {
35method: "POST",
36headers: {
cerebras_coderindex.ts1 match
181182try {
183const response = await fetch("/", {
184method: "POST",
185body: JSON.stringify({
cerebras_coderindex.ts1 match
181182try {
183const response = await fetch("/", {
184method: "POST",
185body: JSON.stringify({
2829// create http request
30const res = await fetch("https://api.capacities.io/save-to-daily-note", {
31method: "POST",
32headers: {
2829// create http request
30const res = await fetch("https://api.capacities.io/save-to-daily-note", {
31method: "POST",
32headers: {
stevensDemosendDailyBrief.ts1 match
135const lastSunday = today.startOf("week").minus({ days: 1 });
136137// Fetch relevant memories using the utility function
138const memories = await getRelevantMemories();
139
stevensDemoNotebookView.tsx12 matches
67const [currentPage, setCurrentPage] = useState(1);
6869const fetchMemories = useCallback(async () => {
70setLoading(true);
71setError(null);
72try {
73const response = await fetch(API_BASE);
74if (!response.ok) {
75throw new Error(`HTTP error! status: ${response.status}`);
78setMemories(data);
79} catch (e) {
80console.error("Failed to fetch memories:", e);
81setError(e.message || "Failed to fetch memories.");
82} finally {
83setLoading(false);
8687useEffect(() => {
88fetchMemories();
89}, [fetchMemories]);
9091const handleAddMemory = async (e: React.FormEvent) => {
100101try {
102const response = await fetch(API_BASE, {
103method: "POST",
104headers: { "Content-Type": "application/json" },
112setNewMemoryTags("");
113setShowAddForm(false);
114await fetchMemories();
115} catch (e) {
116console.error("Failed to add memory:", e);
123124try {
125const response = await fetch(`${API_BASE}/${id}`, {
126method: "DELETE",
127});
129throw new Error(`HTTP error! status: ${response.status}`);
130}
131await fetchMemories();
132} catch (e) {
133console.error("Failed to delete memory:", e);
155156try {
157const response = await fetch(`${API_BASE}/${editingMemory.id}`, {
158method: "PUT",
159headers: { "Content-Type": "application/json" },
164}
165setEditingMemory(null);
166await fetchMemories();
167} catch (e) {
168console.error("Failed to update memory:", e);
stevensDemoindex.ts2 matches
135));
136137// HTTP vals expect an exported "fetch handler"
138export default app.fetch;