Skip to content

migrate(chat): repoint /api/upload to recoup-api#1740

Open
arpitgupta1214 wants to merge 8 commits into
testfrom
feat/chat-upload-cutover
Open

migrate(chat): repoint /api/upload to recoup-api#1740
arpitgupta1214 wants to merge 8 commits into
testfrom
feat/chat-upload-cutover

Conversation

@arpitgupta1214
Copy link
Copy Markdown
Collaborator

@arpitgupta1214 arpitgupta1214 commented May 9, 2026

Summary

Cuts over usePureFileAttachments and lib/arweave/uploadFile.tsx to the new dedicated POST /api/upload on api, removes the local /api/upload route, and allows *.supabase.co in next.config.mjs images.remotePatterns so Next/Image can render the new public CDN URLs.

The api-side endpoint returns the same { success, fileName, fileType, fileSize, url } shape, so chat callers needed nothing more than a base-URL swap.

Depends on api PR landing on test first: recoupable/api#540.

Test plan

  • After api PR is on test: drop a PNG into chat input — attachment uploads successfully and renders inline
  • Profile-picture upload from Account settings (uses lib/arweave/uploadFile.tsx) succeeds

Summary by cubic

Repointed file uploads to the recoup API POST /api/upload, removed Arweave, and fixed the TXT result card to use txtUrl so generated files render correctly. Uploads now send a Privy Bearer token, and Supabase public URLs render via Next/Image.

  • Migration
    • Use ${getClientApiBaseUrl()}/api/upload with Authorization: Bearer <accessToken> in usePureFileAttachments and lib/files/uploadFile.tsx; fetch tokens via usePrivy().getAccessToken() in useUser, useOrgSettings, useArtistSetting, and useSaveKnowledgeEdit.
    • Remove local route app/api/upload/route.ts; move lib/arweave/uploadFile.tsxlib/files/uploadFile.tsx; improve upload error handling (safe JSON parse; check res.ok and data.success).
    • Remove Arweave and residuals: delete lib/arweave/*, lib/ai/generateImage.ts, lib/txtGeneration.ts, lib/generateAndProcessImage.ts, and lib/email/generateTxtFileEmail.ts; drop arweave from package.json; update TxtFileResult to txtUrl; trim Arweave wording from the system prompt.
    • Allow https://*.supabase.co/storage/v1/object/public/** in next.config.mjs images; keep arweave.net for legacy content.
    • Blocked by recoupable/api#540 on test (auth-required endpoint).

Written for commit 23e9e23. Summary will update on new commits.

Review in cubic

Summary by CodeRabbit

Release Notes

  • New Features

    • Implemented authenticated file uploads with access token-based security.
  • Bug Fixes

    • Improved file upload error handling with defensive JSON parsing.
  • Removed Features

    • Removed AI image generation functionality.
    • Removed decentralized storage integration for files.
    • Removed automated email generation for file sharing.
  • Documentation

    • Updated system prompts to clarify audio transcription handling.

Review Change Stack

Cuts over `usePureFileAttachments` and `lib/arweave/uploadFile.tsx` to
the new dedicated `POST /api/upload` on api (Arweave bytes proxy
parity), and removes the local route. The API response shape is 1:1, so
this is a base-URL swap. `lib/arweave/uploadToArweave.ts` is kept since
it's still imported by `lib/txtGeneration.ts` and `lib/ai/generateImage.ts`.
Phase-1 of the api-side Arweave→Supabase upload migration
(recoupable/api#492) returns Supabase public bucket URLs from
POST /api/upload. Add the hostname to next.config.mjs remotePatterns
so Next/Image can render them.
@vercel
Copy link
Copy Markdown
Contributor

vercel Bot commented May 9, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
chat Ready Ready Preview May 28, 2026 12:11am

Request Review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 9, 2026

📝 Walkthrough

Walkthrough

This PR migrates file uploads from unauthenticated Arweave storage to authenticated client API uploads secured with Privy access tokens. A new authenticated uploadFile handler replaces the old endpoint, all upload-calling hooks are updated to fetch and pass access tokens, and old Arweave/IPFS infrastructure is removed.

Changes

Authenticated File Upload Migration

Layer / File(s) Summary
New authenticated file upload handler
lib/files/uploadFile.tsx
Introduces uploadFile(file, accessToken) that requires authentication, POSTs to a client API endpoint with Bearer token header, and returns UploadFileResponse containing id and uri fields.
TxtFileResult component updated
components/ui/TxtFileResult.tsx
TxtFileGenerationResult interface replaces arweaveUrl with txtUrl: string | null. Fetch logic, dependencies, and download/display UI all updated to use the new txtUrl field.
Hooks updated with Privy authentication
hooks/useArtistSetting.tsx, hooks/useOrgSettings.ts, hooks/usePureFileAttachments.ts, hooks/useSaveKnowledgeEdit.ts, hooks/useUser.tsx
All hooks now call usePrivy().getAccessToken() and pass the token to uploadFile. Import sources updated to @/lib/files/uploadFile. Dependency arrays include getAccessToken where needed.
System prompt documentation
lib/prompts/getSystemPrompt.ts
Audio transcription instruction trigger reworded to remove Arweave-specific reference and use generic file-URL language.
Cleanup: Arweave integration removal
lib/arweave/uploadLinkToArweave.ts (+ full module deletions of uploadToArweave, uploadMetadataJson, uploadFile, gateway, IPFS utilities, AI/image/email generation modules, API upload route)
Removes old Arweave-based upload infrastructure and unused AI/email modules. Old API upload route no longer needed with authenticated client endpoint.

🎯 4 (Complex) | ⏱️ ~45 minutes

Suggested reviewers

  • sweetmantech

Poem

🔐 From Arweave chains to Auth tokens bright,
Privy gates the upload night—
Old hooks shed their keys and walls,
New authenticated endpoints call,
Clean code flows where trust installs. ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Solid & Clean Code ⚠️ Warning DRY violation: upload logic duplicated in uploadFile.tsx and usePureFileAttachments.ts; API contract mismatch: id field unused; security flaw: window.open lacks noopener,noreferrer. Consolidate upload logic; remove unused id from UploadFileResponse; add "noopener,noreferrer" to window.open in TxtFileResult.tsx line 61.
✅ Passed checks (2 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/chat-upload-cutover

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 4 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Requires human review: Migrates file uploads to external API; high blast radius if API not ready or fails. Dependency on api PR landing first. Requires human review for CORS, error handling, and fallback behavior.

The api migration broke every direct Arweave consumer in chat. The
remaining callers of lib/arweave/* were three orphans (lib/txtGeneration.ts,
lib/ai/generateImage.ts, lib/email/generateTxtFileEmail.ts) imported by
nothing, plus uploadFile.tsx itself which was repointed to api in this
PR and has nothing Arweave-specific left.

- Move lib/arweave/uploadFile.tsx → lib/files/uploadFile.tsx (and rename
  ArweaveUploadResponse → UploadFileResponse).
- Update the 4 hook imports (useUser, useOrgSettings, useSaveKnowledgeEdit,
  useArtistSetting).
- Delete the orphaned consumers.
- Delete lib/arweave/ entirely.

Net: -415 / +7 lines.
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0 issues found across 14 files (changes from recent commits).

Requires human review: This is a significant migration of file upload infrastructure from local Arweave to an external API, affecting multiple critical paths (chat, profile, settings). High-risk and requires human review to

Threads accessToken through lib/files/uploadFile, which now requires
it and attaches Authorization: Bearer to the cross-origin fetch.
Updates the five hooks that call uploadFile (useUser, useOrgSettings
× 2, useArtistSetting × 2, useSaveKnowledgeEdit) to grab the token
via usePrivy().getAccessToken() at call time.

Inline fetch in usePureFileAttachments gets the same Bearer header,
plus a robust error parse (json().catch(() => null), check both
!res.ok and !data.success) consistent with the rest of the upload
flow. Pairs with recoupable/api#540 which now requires auth and
stamps uploaded_by metadata onto the storage object.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 6 files (changes from recent commits).

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="hooks/useOrgSettings.ts">

<violation number="1" location="hooks/useOrgSettings.ts:98">
P2: Handle the null-token case before uploading knowledges to avoid throwing from `uploadFile` mid-loop.</violation>
</file>

Tip: Review your code locally with the cubic CLI to iterate faster.

Re-trigger cubic

Comment thread hooks/useOrgSettings.ts
try {
const { uri } = await uploadFile(file);
const accessToken = await getAccessToken();
const { uri } = await uploadFile(file, accessToken);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: Handle the null-token case before uploading knowledges to avoid throwing from uploadFile mid-loop.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At hooks/useOrgSettings.ts, line 98:

<comment>Handle the null-token case before uploading knowledges to avoid throwing from `uploadFile` mid-loop.</comment>

<file context>
@@ -94,13 +94,14 @@ const useOrgSettings = (orgId: string | null) => {
       try {
-        const { uri } = await uploadFile(file);
+        const accessToken = await getAccessToken();
+        const { uri } = await uploadFile(file, accessToken);
         setImage(uri);
       } finally {
</file context>

@arpitgupta1214
Copy link
Copy Markdown
Collaborator Author

End-to-end verification

Tested via the ?api=... query-string override pointing this preview at the api PR's preview (recoupable/api#540), signed in with Privy on the same origin. Both code paths in chat funnel through one of these two patterns:

Path Source Result
Path 1 lib/files/uploadFile.tsx (used by useUser, useOrgSettings ×2, useArtistSetting ×2, useSaveKnowledgeEdit) Browser POST with FormData + Authorization: Bearer <privy> 200, supabase.co URL reachable, MIME preserved, byte-perfect round-trip
Path 2 hooks/usePureFileAttachments.ts inline (dropzone) Same shape 200, supabase.co URL reachable
Unauth sanity from chat origin No Bearer header 401

next.config.mjs already allowlists *.supabase.co/storage/v1/object/public/** under images.remotePatterns, so next/image renders the new URLs without further changes.

API-side endpoint verification: recoupable/api#540.

After the migration to the dedicated /api/upload (api#540 +
chat#1740 Bundle A), no chat code uploads to Arweave anymore.
Removes the leftover code that still referenced it:

- delete lib/generateAndProcessImage.ts (orphan helper; only file
  importing the `arweave` npm package, no internal consumers)
- drop the `arweave` dep from package.json
- rename TxtFileGenerationResult.arweaveUrl → txtUrl to match the
  MCP tool's actual response shape (which returns { success, txtUrl,
  message }); also drop the now-unused smartAccountAddress /
  transactionHash / blockExplorerUrl fields it never populates. The
  card was rendering nothing before this fix because the prop name
  didn't match.
- strip the stale "e.g., arweave.net" example from the audio
  transcription prompt
- update the obsolete "Arweave URL" comment in usePureFileAttachments

Kept: next.config.mjs `arweave.net` entry in images.remotePatterns —
legacy ar:// URLs persisted in the DB (chat history, account avatars
predating the migration) still need to render via the api's
arweaveGatewayUrl read-side helper.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 issues found across 6 files (changes from recent commits).

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="components/ui/TxtFileResult.tsx">

<violation number="1" location="components/ui/TxtFileResult.tsx:24">
P2: A new `txtUrl` can be ignored because the fetch is blocked when prior `fileContent` exists, causing stale file preview data.</violation>

<violation number="2" location="components/ui/TxtFileResult.tsx:61">
P2: Use `noopener,noreferrer` when opening external URLs in a new tab to avoid opener-based tabnabbing risks.</violation>
</file>

Tip: Review your code locally with the cubic CLI to iterate faster.

Re-trigger cubic

if (result.arweaveUrl) {
window.open(result.arweaveUrl, "_blank");
if (result.txtUrl) {
window.open(result.txtUrl, "_blank");
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: Use noopener,noreferrer when opening external URLs in a new tab to avoid opener-based tabnabbing risks.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At components/ui/TxtFileResult.tsx, line 61:

<comment>Use `noopener,noreferrer` when opening external URLs in a new tab to avoid opener-based tabnabbing risks.</comment>

<file context>
@@ -60,13 +57,13 @@ export function TxtFileResult({ result }: TxtFileResultProps) {
-    if (result.arweaveUrl) {
-      window.open(result.arweaveUrl, "_blank");
+    if (result.txtUrl) {
+      window.open(result.txtUrl, "_blank");
     }
   };
</file context>
Suggested change
window.open(result.txtUrl, "_blank");
window.open(result.txtUrl, "_blank", "noopener,noreferrer");

Comment on lines +24 to 26
if (result.txtUrl && !fileContent) {
setLoading(true);
setFetchError(null);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: A new txtUrl can be ignored because the fetch is blocked when prior fileContent exists, causing stale file preview data.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At components/ui/TxtFileResult.tsx, line 24:

<comment>A new `txtUrl` can be ignored because the fetch is blocked when prior `fileContent` exists, causing stale file preview data.</comment>

<file context>
@@ -24,12 +21,12 @@ export function TxtFileResult({ result }: TxtFileResultProps) {
 
   useEffect(() => {
-    if (result.arweaveUrl && !fileContent) {
+    if (result.txtUrl && !fileContent) {
       setLoading(true);
       setFetchError(null);
</file context>
Suggested change
if (result.txtUrl && !fileContent) {
setLoading(true);
setFetchError(null);
if (result.txtUrl) {
setFileContent(null);
setLoading(true);
setFetchError(null);

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
components/ui/TxtFileResult.tsx (1)

24-42: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Fix stale TXT fetching and download security in TxtFileResult

  • The fetch effect is blocked by !fileContent, so when result.txtUrl changes while fileContent is already populated, the component won’t refetch and will display stale contents (lines 23-42).
  • window.open(result.txtUrl, "_blank") is missing noopener/noreferrer, enabling reverse-tabnabbing (lines 59-63).
💡 Proposed fix
  useEffect(() => {
-    if (result.txtUrl && !fileContent) {
-      setLoading(true);
-      setFetchError(null);
-      fetch(result.txtUrl)
+    if (!result.txtUrl) {
+      setFileContent(null);
+      setFetchError(null);
+      return;
+    }
+
+    setLoading(true);
+    setFetchError(null);
+    setFileContent(null);
+    fetch(result.txtUrl)
         .then((res) => {
           if (!res.ok) throw new Error("Failed to fetch file");
           return res.text();
         })
         .then((text) => {
           setFileContent(text);
           setLoading(false);
         })
         .catch((err) => {
           setFetchError(err.message || "Error fetching file");
           setLoading(false);
         });
-    }
-    // eslint-disable-next-line react-hooks/exhaustive-deps
   }, [result.txtUrl]);
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@components/ui/TxtFileResult.tsx` around lines 24 - 42, The effect in the
TxtFileResult component currently gates refetching on !fileContent and can
return stale text when result.txtUrl changes; change the useEffect so it depends
only on result.txtUrl (remove fileContent from the condition) and use an
AbortController to cancel any in-flight fetch when result.txtUrl changes or the
component unmounts, keeping the existing setFileContent/setLoading/setFetchError
flow for success/error; also fix the download/open logic that calls
window.open(result.txtUrl, "_blank") (used in the download handler for the
component) to open the URL safely by adding noopener/noreferrer (e.g., use
window.open(result.txtUrl, "_blank", "noopener,noreferrer") or create an anchor
with rel="noopener noreferrer" and click it) to prevent reverse-tabnabbing.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@components/ui/TxtFileResult.tsx`:
- Around line 60-62: The window.open calls in the TxtFileResult component
(window.open(result.txtUrl, "_blank")) and in TaskRecentRunsSection that open
links with "_blank" are vulnerable to reverse-tabnabbing; change each call to
include noopener and noreferrer and null out the opener as a fallback—e.g.,
replace window.open(url, "_blank") with: const w = window.open(url, "_blank",
"noopener,noreferrer"); if (w) w.opener = null;—update the calls in the
TxtFileResult component (result.txtUrl) and the TaskRecentRunsSection
window.open usage accordingly.

In `@lib/files/uploadFile.tsx`:
- Around line 30-33: The returned object in lib/files/uploadFile.tsx maps id to
json.id but the API now returns url (not id); update the mapping in the function
that constructs the UploadFileResponse so UploadFileResponse.id is populated
from json.url (or otherwise derive a stable id from json.url) and keep uri as
json.url; ensure references to UploadFileResponse.id use that json.url value
instead of json.id.

---

Outside diff comments:
In `@components/ui/TxtFileResult.tsx`:
- Around line 24-42: The effect in the TxtFileResult component currently gates
refetching on !fileContent and can return stale text when result.txtUrl changes;
change the useEffect so it depends only on result.txtUrl (remove fileContent
from the condition) and use an AbortController to cancel any in-flight fetch
when result.txtUrl changes or the component unmounts, keeping the existing
setFileContent/setLoading/setFetchError flow for success/error; also fix the
download/open logic that calls window.open(result.txtUrl, "_blank") (used in the
download handler for the component) to open the URL safely by adding
noopener/noreferrer (e.g., use window.open(result.txtUrl, "_blank",
"noopener,noreferrer") or create an anchor with rel="noopener noreferrer" and
click it) to prevent reverse-tabnabbing.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: bf08b845-4f66-4ea7-b544-2c45e7bcf1df

📥 Commits

Reviewing files that changed from the base of the PR and between 464ccb7 and 23e9e23.

⛔ Files ignored due to path filters (3)
  • next.config.mjs is excluded by none and included by none
  • package.json is excluded by none and included by none
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml and included by none
📒 Files selected for processing (20)
  • app/api/upload/route.ts
  • components/ui/TxtFileResult.tsx
  • hooks/useArtistSetting.tsx
  • hooks/useOrgSettings.ts
  • hooks/usePureFileAttachments.ts
  • hooks/useSaveKnowledgeEdit.ts
  • hooks/useUser.tsx
  • lib/ai/generateImage.ts
  • lib/arweave/arweave.ts
  • lib/arweave/gateway.ts
  • lib/arweave/ipfs.ts
  • lib/arweave/uploadFile.tsx
  • lib/arweave/uploadLinkToArweave.ts
  • lib/arweave/uploadMetadataJson.ts
  • lib/arweave/uploadToArweave.ts
  • lib/email/generateTxtFileEmail.ts
  • lib/files/uploadFile.tsx
  • lib/generateAndProcessImage.ts
  • lib/prompts/getSystemPrompt.ts
  • lib/txtGeneration.ts
💤 Files with no reviewable changes (12)
  • lib/email/generateTxtFileEmail.ts
  • app/api/upload/route.ts
  • lib/arweave/uploadToArweave.ts
  • lib/arweave/uploadFile.tsx
  • lib/arweave/ipfs.ts
  • lib/arweave/gateway.ts
  • lib/ai/generateImage.ts
  • lib/txtGeneration.ts
  • lib/generateAndProcessImage.ts
  • lib/arweave/uploadMetadataJson.ts
  • lib/arweave/arweave.ts
  • lib/arweave/uploadLinkToArweave.ts

Comment on lines +60 to 62
if (result.txtUrl) {
window.open(result.txtUrl, "_blank");
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Inspect the reported file around the target lines
echo "== TxtFileResult.tsx (around lines 40-90) =="
sed -n '40,90p' components/ui/TxtFileResult.tsx | cat -n

echo
echo "== Search for window.open in the repo (limit output) =="
rg -n "window\.open\(" --glob='**/*.{ts,tsx,js,jsx}' -S . || true

echo
echo "== Search for noopener/noreferrer usage patterns =="
rg -n "noopener|noreferrer" --glob='**/*.{ts,tsx,js,jsx}' -S components . || true

Repository: recoupable/chat

Length of output: 6895


Harden external window.open calls against reverse-tabnabbing.

components/ui/TxtFileResult.tsx opens result.txtUrl with window.open(result.txtUrl, "_blank") without noopener,noreferrer.

💡 Proposed fix
-      window.open(result.txtUrl, "_blank");
+      window.open(result.txtUrl, "_blank", "noopener,noreferrer");

Also found an unprotected window.open in components/VercelChat/dialogs/tasks/TaskRecentRunsSection.tsx ("_blank" without noopener/noreferrer).

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@components/ui/TxtFileResult.tsx` around lines 60 - 62, The window.open calls
in the TxtFileResult component (window.open(result.txtUrl, "_blank")) and in
TaskRecentRunsSection that open links with "_blank" are vulnerable to
reverse-tabnabbing; change each call to include noopener and noreferrer and null
out the opener as a fallback—e.g., replace window.open(url, "_blank") with:
const w = window.open(url, "_blank", "noopener,noreferrer"); if (w) w.opener =
null;—update the calls in the TxtFileResult component (result.txtUrl) and the
TaskRecentRunsSection window.open usage accordingly.

Comment thread lib/files/uploadFile.tsx
Comment on lines +30 to +33
return {
id: json.id,
uri: json.url,
};
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Return mapping doesn’t match the upload response contract.

At Line 31, id is read from json.id, but this migration’s API contract returns url (not id). That makes UploadFileResponse.id unreliable at runtime.

💡 Proposed fix
 export type UploadFileResponse = {
-  id: string;
   uri: string;
 };
@@
-    return {
-      id: json.id,
-      uri: json.url,
-    };
+    if (typeof json?.url !== "string") {
+      throw new Error("Upload failed");
+    }
+    return { uri: json.url };
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@lib/files/uploadFile.tsx` around lines 30 - 33, The returned object in
lib/files/uploadFile.tsx maps id to json.id but the API now returns url (not
id); update the mapping in the function that constructs the UploadFileResponse
so UploadFileResponse.id is populated from json.url (or otherwise derive a
stable id from json.url) and keep uri as json.url; ensure references to
UploadFileResponse.id use that json.url value instead of json.id.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant