Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions packages/ui/src/components/toolbar/copy-for-ai.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,8 @@ function buildChatGPTUrl(prompt: string): string {
return `https://chatgpt.com/?q=${encodeURIComponent(prompt)}`;
}

const MAX_SAFE_CHATGPT_URL_LENGTH = 7500;

function buildCursorUrl(prompt: string): string {
return `cursor://prompt?text=${encodeURIComponent(prompt)}`;
}
Expand Down Expand Up @@ -254,7 +256,12 @@ export const CopyForAI = ({
}, [markdown]);

const claudeUrl = buildClaudeUrl(markdown);
const chatGPTUrl = buildChatGPTUrl(markdown);
const directChatGPTUrl = buildChatGPTUrl(markdown);
const isChatGPTPromptTooLong =
directChatGPTUrl.length > MAX_SAFE_CHATGPT_URL_LENGTH;
const chatGPTUrl = isChatGPTPromptTooLong
? 'https://chatgpt.com/'
: directChatGPTUrl;
const cursorUrl = buildCursorUrl(markdown);

return (
Expand Down Expand Up @@ -356,6 +363,10 @@ export const CopyForAI = ({
href={chatGPTUrl}
target="_blank"
rel="noreferrer noopener"
onClick={() => {
if (!isChatGPTPromptTooLong) return;
void navigator.clipboard.writeText(markdown);
}}
className="flex items-center gap-2.5 p-2 rounded-lg cursor-pointer outline-none transition-colors hover:bg-white/5"
>
<span
Expand All @@ -368,7 +379,11 @@ export const CopyForAI = ({
<span className="text-sm font-medium text-white">
Open in ChatGPT
</span>
<span className="text-xs text-white/40">{linkDescription}</span>
<span className="text-xs text-white/40">
{isChatGPTPromptTooLong
? 'Long prompt: copied to clipboard. Paste with Ctrl+V / Cmd+V'
: linkDescription}
</span>
</div>
<IconArrowUpRight size={16} className="shrink-0 text-white/30" />
</a>
Expand Down
Loading