Skip to content

armgit / qm

Public Imported from GitHub
0

Multiplayer agent harness for work.

Open a drafted new chat from a ?q= link (#1682)

Joshua France0d452428f5a1
diff --git a/plugins/web-ui/src/shell.ts b/plugins/web-ui/src/shell.ts
index b2bf2ed1a..662de6059 100644
--- a/plugins/web-ui/src/shell.ts
+++ b/plugins/web-ui/src/shell.ts
@@ -48,7 +48,7 @@ import { PHONE_MAX_WIDTH, trackVisualViewport } from "./viewport";
import { markConnectorConnected } from "./chat";
import { clearSkillsCache, resyncModelSelection } from "./composer";
import { allConversations, ensureDeliveryStream, mainConversation, onExitCanvas } from "./conversations";
-import { clearAllDrafts, saveDraft, storedDraft } from "./drafts";
+import { clearAllDrafts, newChatDraftKey, saveDraft, storedDraft } from "./drafts";
import { deepLinkPath, isPlainLeftClick, parseDeepLink, UI_BASE } from "./deep-link";
import {
adoptRemoteSplit,
@@ -1023,6 +1023,8 @@ export async function boot(): Promise<void> {
item: wantedItem,
} = parseDeepLink(UI_BASE, location.pathname, location.search);
document.body.classList.toggle("app-edit-embed", wanted === "app-edit" && params.get("embed") === "1");
+ const prefillRoute = wanted === null || wanted === "new";
+ const prefill = prefillRoute && !wantedSession ? (params.get("q")?.slice(0, 20_000) ?? null) : null;
const chatsLink = wanted === null || wanted === "chats";
const linkedId = wantedSession && chatsLink ? wantedSession : null;
let transcriptUnavailable = false;
@@ -1084,7 +1086,7 @@ export async function boot(): Promise<void> {
if (connectedProvider) markConnectorConnected(connectedProvider);
const viewIntent = isView(wanted) && canView(wanted) && wanted !== "chats";
loadPersistedSplit();
- if (!wantedSession && wanted !== "app-edit") {
+ if (!wantedSession && wanted !== "app-edit" && prefill === null) {
const restore = adoptRemoteSplit(remoteSplitFetch).then(async () => {
if (viewIntent && restoredCanvasNeedsSessionList()) await sessions;
});
@@ -1147,6 +1149,14 @@ export async function boot(): Promise<void> {
await sessions;
+ if (prefill !== null) {
+ history.replaceState(null, "", deepLinkPath(UI_BASE, "chats", null));
+ saveDraft(newChatDraftKey(appState.me.user), prefill);
+ exitSplitIfActive();
+ mainConversation().newChat();
+ return;
+ }
+
if (wanted === "app-edit") {
const slug = (params.get("slug") ?? "").toLowerCase();
if (/^[a-z0-9-]{1,63}$/.test(slug)) {
diff --git a/plugins/web-ui/test/prompt-link-boot.test.ts b/plugins/web-ui/test/prompt-link-boot.test.ts
new file mode 100644
index 000000000..c4d9b04e1
--- /dev/null
+++ b/plugins/web-ui/test/prompt-link-boot.test.ts
@@ -0,0 +1,19 @@
+import assert from "node:assert/strict";
+import test from "node:test";
+import { harness } from "./deep-link-boot-fixture.ts";
+
+for (const path of ["/new?q=summarize%20my%20inbox", "/?q=summarize%20my%20inbox"]) {
+ test(`${path} opens a new chat with the prompt drafted but not sent`, async () => {
+ const h = await harness({ path });
+ try {
+ const booted = h.boot();
+ h.releaseSessions();
+ await booted;
+ assert.equal(h.visibleConversation().composer.state.draft, "summarize my inbox");
+ assert.equal(h.visibleConversation().state.sessionId, null, "nothing was sent");
+ assert.equal(location.pathname + location.search, "/", "the prompt leaves the address bar");
+ } finally {
+ await h.close();
+ }
+ });
+}