Skip to content

AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.

feat(copilot): support prompt-in-URL for shareable prompt links (#12406)

Otto0b594a219c46
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/useChatInput.ts b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/useChatInput.ts
index 28ebb38ced..14ad5aed5b 100644
--- a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/useChatInput.ts
+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/useChatInput.ts
@@ -1,3 +1,4 @@
+import { useCopilotUIStore } from "@/app/(platform)/copilot/store";
import { ChangeEvent, FormEvent, useEffect, useState } from "react";
interface Args {
@@ -16,6 +17,16 @@ export function useChatInput({
}: Args) {
const [value, setValue] = useState("");
const [isSending, setIsSending] = useState(false);
+ const { initialPrompt, setInitialPrompt } = useCopilotUIStore();
+
+ useEffect(
+ function consumeInitialPrompt() {
+ if (!initialPrompt) return;
+ setValue((prev) => (prev.length === 0 ? initialPrompt : prev));
+ setInitialPrompt(null);
+ },
+ [initialPrompt, setInitialPrompt],
+ );
useEffect(
function focusOnMount() {
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/store.ts b/autogpt_platform/frontend/src/app/(platform)/copilot/store.ts
index e80543392b..7d8aeccde4 100644
--- a/autogpt_platform/frontend/src/app/(platform)/copilot/store.ts
+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/store.ts
@@ -7,6 +7,10 @@ export interface DeleteTarget {
}
interface CopilotUIState {
+ /** Prompt extracted from URL hash (e.g. /copilot#prompt=...) for input prefill. */
+ initialPrompt: string | null;
+ setInitialPrompt: (prompt: string | null) => void;
+
sessionToDelete: DeleteTarget | null;
setSessionToDelete: (target: DeleteTarget | null) => void;
@@ -31,6 +35,9 @@ interface CopilotUIState {
}
export const useCopilotUIStore = create<CopilotUIState>((set) => ({
+ initialPrompt: null,
+ setInitialPrompt: (prompt) => set({ initialPrompt: prompt }),
+
sessionToDelete: null,
setSessionToDelete: (target) => set({ sessionToDelete: target }),
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/useCopilotPage.ts b/autogpt_platform/frontend/src/app/(platform)/copilot/useCopilotPage.ts
index 3a54958609..e82423ee8a 100644
--- a/autogpt_platform/frontend/src/app/(platform)/copilot/useCopilotPage.ts
+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/useCopilotPage.ts
@@ -19,6 +19,42 @@ import { useCopilotStream } from "./useCopilotStream";
const TITLE_POLL_INTERVAL_MS = 2_000;
const TITLE_POLL_MAX_ATTEMPTS = 5;
+/**
+ * Extract a prompt from the URL hash fragment.
+ * Supports: /copilot#prompt=URL-encoded-text
+ * Optionally auto-submits if ?autosubmit=true is in the query string.
+ * Returns null if no prompt is present.
+ */
+function extractPromptFromUrl(): {
+ prompt: string;
+ autosubmit: boolean;
+} | null {
+ if (typeof window === "undefined") return null;
+
+ const hash = window.location.hash;
+ if (!hash) return null;
+
+ const hashParams = new URLSearchParams(hash.slice(1));
+ const prompt = hashParams.get("prompt");
+
+ if (!prompt || !prompt.trim()) return null;
+
+ const searchParams = new URLSearchParams(window.location.search);
+ const autosubmit = searchParams.get("autosubmit") === "true";
+
+ // Clean up hash + autosubmit param only (preserve other query params)
+ const cleanURL = new URL(window.location.href);
+ cleanURL.hash = "";
+ cleanURL.searchParams.delete("autosubmit");
+ window.history.replaceState(
+ null,
+ "",
+ `${cleanURL.pathname}${cleanURL.search}`,
+ );
+
+ return { prompt: prompt.trim(), autosubmit };
+}
+
interface UploadedFile {
file_id: string;
name: string;
@@ -127,6 +163,28 @@ export function useCopilotPage() {
}
}, [sessionId, pendingMessage, sendMessage]);
+ // --- Extract prompt from URL hash on mount (e.g. /copilot#prompt=Hello) ---
+ const { setInitialPrompt } = useCopilotUIStore();
+ const hasProcessedUrlPrompt = useRef(false);
+ useEffect(() => {
+ if (hasProcessedUrlPrompt.current) return;
+
+ const urlPrompt = extractPromptFromUrl();
+ if (!urlPrompt) return;
+
+ hasProcessedUrlPrompt.current = true;
+
+ if (urlPrompt.autosubmit) {
+ setPendingMessage(urlPrompt.prompt);
+ void createSession().catch(() => {
+ setPendingMessage(null);
+ setInitialPrompt(urlPrompt.prompt);
+ });
+ } else {
+ setInitialPrompt(urlPrompt.prompt);
+ }
+ }, [createSession, setInitialPrompt]);
+
async function uploadFiles(
files: File[],
sid: string,