Skip to content

Open-source, local-first social media research agent for Instagram, TikTok, and LinkedIn. Jev routes read-only steps; socai CLI captures cited browser evidence.

feat(ui): add example research prompt buttons and modern bottom-right alert (#16)

Barshan Majumdarf5a36e4ae4c1
diff --git a/package.json b/package.json
index f38aa28..fdc17ff 100644
--- a/package.json
+++ b/package.json
@@ -27,7 +27,7 @@
"scripts": {
"start": "node ./bin/jev-social.js",
"dev": "node --watch ./bin/jev-social.js serve --no-open",
- "check": "node --check ./bin/jev-social.js && node --check ./src/server.js && node --check ./public/app.js && node --check ./public/report-download.js",
+ "check": "node --check ./bin/jev-social.js && node --check ./src/server.js && node --check ./public/app.js && node --check ./public/report-download.js && node --check ./public/prompts.js",
"test": "node --test"
},
"engines": {
diff --git a/public/app.js b/public/app.js
index 6cfbc20..9a6f5e3 100644
--- a/public/app.js
+++ b/public/app.js
@@ -3,6 +3,7 @@ import {
getReportMarkdown,
isReportDownloadable,
} from "./report-download.js";
+import { bindPromptButtons } from "./prompts.js";
const $ = (selector) => document.querySelector(selector);
const elements = {
@@ -13,6 +14,8 @@ const elements = {
activityTitle: $("#activity-title"),
activityMessage: $("#activity-message"),
error: $("#error"),
+ errorMessage: $("#error-message"),
+ errorClose: $("#close-error"),
result: $("#result"),
cards: $("#cards"),
evidenceHeading: $("#evidence-heading"),
@@ -73,6 +76,7 @@ if (typeof window !== "undefined") {
window.downloadReport = downloadReport;
}
$("#close-detail").addEventListener("click", () => elements.dialog.close());
+$("#close-error")?.addEventListener("click", clearError);
elements.dialog.addEventListener("click", (event) => {
if (event.target === elements.dialog) elements.dialog.close();
});
@@ -83,6 +87,11 @@ window.addEventListener("popstate", () => {
});
void refreshStatus();
+bindPromptButtons({
+ buttons: document.querySelectorAll(".prompt-example-btn"),
+ queryElement: $("#query"),
+ platformElement: $("#platform"),
+});
function handleStreamEvent(event) {
if (event.stage === "result") return;
@@ -187,13 +196,22 @@ function showActivity(title, message) {
function showError(error) {
elements.activity.classList.add("hidden");
- elements.error.textContent = error.message;
+ const message = error?.message || String(error || "An unexpected error occurred.");
+ if (elements.errorMessage) {
+ elements.errorMessage.textContent = message;
+ } else {
+ elements.error.textContent = message;
+ }
elements.error.classList.remove("hidden");
}
function clearError() {
elements.error.classList.add("hidden");
- elements.error.textContent = "";
+ if (elements.errorMessage) {
+ elements.errorMessage.textContent = "";
+ } else {
+ elements.error.textContent = "";
+ }
}
function renderRun(run) {
diff --git a/public/index.html b/public/index.html
index 6059954..1dba4eb 100644
--- a/public/index.html
+++ b/public/index.html
@@ -8,7 +8,7 @@
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&family=Roboto+Mono:wght@500;700;800&display=swap" />
- <link rel="stylesheet" href="/styles.css" />
+ <link rel="stylesheet" href="/styles.css?v=2" />
</head>
<body>
<div class="app-shell">
@@ -23,7 +23,10 @@
</nav>
</header>
- <section id="error" class="error-box hidden" role="alert"></section>
+ <section id="error" class="error-box hidden" role="alert">
+ <span id="error-message" class="error-message"></span>
+ <button id="close-error" class="error-close" type="button" aria-label="Dismiss error">×</button>
+ </section>
<main class="app-main">
<section id="search-view" class="view search-view">
@@ -57,6 +60,24 @@
</div>
</form>
+ <div class="prompt-examples" aria-label="Example research goals">
+ <span class="prompt-examples-label">Examples</span>
+ <div class="prompt-examples-list">
+ <button type="button" class="prompt-example-btn" data-platform="instagram" data-query="Find handmade art creators and inspect their most engaging posts">
+ <span class="prompt-platform">Instagram</span>
+ <span class="prompt-text">Handmade art creators</span>
+ </button>
+ <button type="button" class="prompt-example-btn" data-platform="tiktok" data-query="Find emerging AI creators and inspect their most engaging videos">
+ <span class="prompt-platform">TikTok</span>
+ <span class="prompt-text">Emerging AI creators</span>
+ </button>
+ <button type="button" class="prompt-example-btn" data-platform="linkedin" data-query="Find AI product managers and examine their recent shared posts">
+ <span class="prompt-platform">LinkedIn</span>
+ <span class="prompt-text">AI product managers</span>
+ </button>
+ </div>
+ </div>
+
<div class="pipeline" aria-label="Execution pipeline">
<span>one goal</span><i>→</i><span>Jev chooses a step</span><i>→</i><span>socai executes</span><i>↻</i><span>review evidence</span>
</div>
diff --git a/public/prompts.js b/public/prompts.js
new file mode 100644
index 0000000..e0f566b
--- /dev/null
+++ b/public/prompts.js
@@ -0,0 +1,84 @@
+export const SUPPORTED_PLATFORMS = Object.freeze(["instagram", "tiktok", "linkedin"]);
+
+export const RESEARCH_PROMPT_EXAMPLES = Object.freeze([
+ {
+ platform: "instagram",
+ platformLabel: "Instagram",
+ title: "Handmade art creators",
+ query: "Find handmade art creators and inspect their most engaging posts",
+ },
+ {
+ platform: "tiktok",
+ platformLabel: "TikTok",
+ title: "Emerging AI creators",
+ query: "Find emerging AI creators and inspect their most engaging videos",
+ },
+ {
+ platform: "linkedin",
+ platformLabel: "LinkedIn",
+ title: "AI product managers",
+ query: "Find AI product managers and examine their recent shared posts",
+ },
+]);
+
+export function getPromptForPlatform(platform) {
+ if (!platform || typeof platform !== "string") return null;
+ const target = platform.trim().toLowerCase();
+ return RESEARCH_PROMPT_EXAMPLES.find((item) => item.platform === target) || null;
+}
+
+export function applyPromptSelection(prompt, elements = {}) {
+ if (!prompt) return false;
+ const query = typeof prompt === "string" ? prompt : prompt.query;
+ const platform = typeof prompt === "object" ? prompt.platform : undefined;
+
+ const queryEl = elements.queryElement || elements.queryInput || elements.query;
+ const platformEl = elements.platformElement || elements.platformSelect || elements.platform;
+
+ if (queryEl && typeof queryEl === "object") {
+ queryEl.value = query || "";
+ if (typeof queryEl.dispatchEvent === "function" && typeof Event !== "undefined") {
+ queryEl.dispatchEvent(new Event("input", { bubbles: true }));
+ }
+ }
+
+ if (platformEl && typeof platformEl === "object" && platform) {
+ platformEl.value = platform;
+ if (typeof platformEl.dispatchEvent === "function" && typeof Event !== "undefined") {
+ platformEl.dispatchEvent(new Event("change", { bubbles: true }));
+ }
+ }
+
+ if (queryEl && typeof queryEl.focus === "function") {
+ queryEl.focus();
+ }
+
+ return true;
+}
+
+export function bindPromptButtons({ buttons, queryElement, platformElement, onSelect } = {}) {
+ if (!buttons) return () => {};
+ const list = Array.from(buttons);
+ const cleanups = [];
+
+ for (const button of list) {
+ const handler = (event) => {
+ if (event && typeof event.preventDefault === "function") {
+ event.preventDefault();
+ }
+ const platform = button.dataset?.platform;
+ const query = button.dataset?.query;
+ const prompt = getPromptForPlatform(platform) || { platform, query };
+ applyPromptSelection(prompt, { queryElement, platformElement });
+ if (typeof onSelect === "function") {
+ onSelect(prompt);
+ }
+ };
+ button.addEventListener("click", handler);
+ cleanups.push(() => button.removeEventListener("click", handler));
+ }
+
+ return () => {
+ for (const cleanup of cleanups) cleanup();
+ };
+}
diff --git a/public/styles.css b/public/styles.css
index 940605e..68f1bbd 100644
--- a/public/styles.css
+++ b/public/styles.css
@@ -62,10 +62,24 @@ h1 em { color: transparent; font-style: normal; -webkit-text-stroke: 1.5px var(-
.button.primary { margin-left: auto; color: #fff; background: var(--ink); }
.button.primary:hover { color: var(--ink); background: var(--pink); }
.button:disabled { opacity: .55; cursor: wait; }
+.prompt-examples { display: flex; align-items: center; gap: 10px; margin-top: 14px; }
+.prompt-examples-label { color: var(--muted); font: 700 9px/1 var(--mono); letter-spacing: .12em; text-transform: uppercase; white-space: nowrap; }
+.prompt-examples-list { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
+.prompt-example-btn { display: inline-flex; align-items: center; gap: 7px; min-height: 28px; padding: 4px 10px; border: 1px solid var(--line); background: #fff; color: var(--ink); font: 500 12px/1.3 var(--sans); cursor: pointer; transition: transform .12s ease, border-color .12s ease, box-shadow .12s ease; }
+.prompt-example-btn:hover { border-color: var(--ink); transform: translate(-1px, -1px); box-shadow: 2px 2px 0 var(--ink); }
+.prompt-example-btn:active { transform: translate(0, 0); box-shadow: 1px 1px 0 var(--ink); }
+.prompt-example-btn:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; box-shadow: 0 0 0 3px var(--pink); }
+.prompt-example-btn .prompt-platform { color: var(--pink); font: 700 9px var(--mono); letter-spacing: .06em; text-transform: uppercase; }
+.prompt-example-btn .prompt-text { color: var(--ink); }
+
.pipeline { display: flex; align-items: center; justify-content: center; gap: 10px; margin-top: 21px; color: #6f7480; font: 8px var(--mono); letter-spacing: .08em; text-transform: uppercase; }
.pipeline i { color: var(--pink); font-style: normal; }
-.error-box { position: fixed; z-index: 50; top: 76px; right: 14px; width: min(560px, calc(100% - 28px)); padding: 14px 16px; border: 1px solid var(--ink); background: #fff; box-shadow: 6px 6px 0 var(--pink); white-space: pre-wrap; font: 11px/1.6 var(--mono); }
+.error-box { position: fixed; z-index: 999; bottom: 24px; right: 24px; top: auto; width: min(480px, calc(100% - 32px)); padding: 13px 38px 13px 16px; border: 1px solid var(--ink); background: #fff; box-shadow: 6px 6px 0 var(--pink); font: 11px/1.6 var(--mono); }
+.error-message { display: block; white-space: pre-wrap; word-break: break-word; color: var(--ink); }
+.error-close { position: absolute; top: 8px; right: 8px; width: 22px; height: 22px; display: grid; place-items: center; border: 0; background: transparent; color: #717682; font-size: 18px; line-height: 1; cursor: pointer; padding: 0; border-radius: 4px; transition: color .12s ease, transform .12s ease; }
+.error-close:hover { color: var(--pink); transform: scale(1.15); }
+.error-close:focus-visible { outline: 2px solid var(--pink); outline-offset: 1px; }
.result-view { min-height: 0; display: flex; flex-direction: column; background: #fff; }
.result-toolbar { flex: 0 0 76px; display: grid; grid-template-columns: 180px 1fr 180px; align-items: center; gap: 20px; padding: 0 22px; border-bottom: 1px solid var(--ink); background: var(--ice); }
.result-heading { min-width: 0; text-align: center; }
@@ -176,6 +190,8 @@ tr:last-child td { border-bottom: 0; }
.search-view { place-items: start center; padding: 42px 14px; }
h1 { font-size: 55px; }
.composer-controls { align-items: stretch; flex-wrap: wrap; }
+ .prompt-examples { flex-direction: column; align-items: flex-start; gap: 8px; margin-top: 12px; }
+ .prompt-examples-list { width: 100%; gap: 6px; }
.readiness { order: 3; width: 100%; }
.button.primary { flex: 1; }
.pipeline { flex-wrap: wrap; }
@@ -185,10 +201,12 @@ tr:last-child td { border-bottom: 0; }
.detail-content { grid-template-columns: 1fr; }
.detail-content .detail-media { min-height: 360px; }
.report-section .section-head { flex-wrap: wrap; gap: 12px; }
+ .error-box { bottom: 12px; right: 12px; width: calc(100% - 24px); }
}
@media (max-width: 500px) {
.top-actions a { padding: 0 9px; font-size: 8px; }
.result-heading .eyebrow { display: none; }
+ .prompt-example-btn { font-size: 11px; padding: 4px 8px; }
.time-readout strong { font-size: 15px; }
.cards { grid-template-columns: 1fr; }
.report-section .section-head { flex-direction: column; align-items: stretch; gap: 10px; }
diff --git a/src/server.js b/src/server.js
index a09335a..f3e13ce 100644
--- a/src/server.js
+++ b/src/server.js
@@ -19,6 +19,7 @@ const MEDIA_TTL_MS = 60 * 60_000;
const STATIC_FILES = {
"/": ["index.html", "text/html; charset=utf-8"],
"/app.js": ["app.js", "text/javascript; charset=utf-8"],
+ "/prompts.js": ["prompts.js", "text/javascript; charset=utf-8"],
"/styles.css": ["styles.css", "text/css; charset=utf-8"],
"/report-download.js": ["report-download.js", "text/javascript; charset=utf-8"],
"/platforms/instagram.png": ["platforms/instagram.png", "image/png"],
diff --git a/test/prompts.test.js b/test/prompts.test.js
new file mode 100644
index 0000000..a40c98a
--- /dev/null
+++ b/test/prompts.test.js
@@ -0,0 +1,134 @@
+import test from "node:test";
+import assert from "node:assert/strict";
+import {
+ SUPPORTED_PLATFORMS,
+ RESEARCH_PROMPT_EXAMPLES,
+ getPromptForPlatform,
+ applyPromptSelection,
+ bindPromptButtons,
+} from "../public/prompts.js";
+
+test("RESEARCH_PROMPT_EXAMPLES provides exactly one concise example for each supported platform", () => {
+ assert.equal(SUPPORTED_PLATFORMS.length, 3);
+ assert.deepEqual([...SUPPORTED_PLATFORMS].sort(), ["instagram", "linkedin", "tiktok"]);
+ assert.equal(RESEARCH_PROMPT_EXAMPLES.length, 3);
+
+ for (const platform of SUPPORTED_PLATFORMS) {
+ const matching = RESEARCH_PROMPT_EXAMPLES.filter((p) => p.platform === platform);
+ assert.equal(matching.length, 1, `Expected exactly 1 prompt for platform: ${platform}`);
+ const prompt = matching[0];
+ assert.ok(prompt.query && prompt.query.trim().length > 0, `Query missing for ${platform}`);
+ assert.ok(prompt.title && prompt.title.trim().length > 0, `Title missing for ${platform}`);
+ assert.ok(prompt.platformLabel && prompt.platformLabel.trim().length > 0, `Platform label missing for ${platform}`);
+ }
+});
+
+test("getPromptForPlatform finds prompt case-insensitively and returns null for unknown platforms", () => {
+ assert.equal(getPromptForPlatform("instagram")?.platform, "instagram");
+ assert.equal(getPromptForPlatform("INSTAGRAM")?.platform, "instagram");
+ assert.equal(getPromptForPlatform("TikTok")?.platform, "tiktok");
+ assert.equal(getPromptForPlatform("LINKEDIN")?.platform, "linkedin");
+ assert.equal(getPromptForPlatform("youtube"), null);
+ assert.equal(getPromptForPlatform(""), null);
+ assert.equal(getPromptForPlatform(null), null);
+});
+
+test("applyPromptSelection populates query and platform, and focuses the query field", () => {
+ let focused = false;
+ let inputDispatched = false;
+ let changeDispatched = false;
+
+ const mockQuery = {
+ value: "",
+ focus() {
+ focused = true;
+ },
+ dispatchEvent(event) {
+ if (event?.type === "input") inputDispatched = true;
+ },
+ };
+
+ const mockPlatform = {
+ value: "auto",
+ dispatchEvent(event) {
+ if (event?.type === "change") changeDispatched = true;
+ },
+ };
+
+ const prompt = RESEARCH_PROMPT_EXAMPLES[0];
+ const result = applyPromptSelection(prompt, {
+ queryElement: mockQuery,
+ platformElement: mockPlatform,
+ });
+
+ assert.equal(result, true);
+ assert.equal(mockQuery.value, prompt.query);
+ assert.equal(mockPlatform.value, prompt.platform);
+ assert.equal(focused, true);
+ assert.equal(inputDispatched, true);
+ assert.equal(changeDispatched, true);
+});
+
+test("applyPromptSelection handles missing or minimal parameters gracefully", () => {
+ assert.equal(applyPromptSelection(null), false);
+ assert.equal(applyPromptSelection(undefined), false);
+
+ const mockQuery = { value: "" };
+ assert.equal(applyPromptSelection("Plain query text", { queryElement: mockQuery }), true);
+ assert.equal(mockQuery.value, "Plain query text");
+});
+
+test("bindPromptButtons registers click listeners, prevents default submit, and supports cleanup", () => {
+ let clickListener = null;
+ const mockButton = {
+ dataset: {
+ platform: "tiktok",
+ query: "Find emerging AI creators and inspect their most engaging videos",
+ },
+ addEventListener(type, listener) {
+ if (type === "click") clickListener = listener;
+ },
+ removeEventListener(type, listener) {
+ if (type === "click" && clickListener === listener) {
+ clickListener = null;
+ }
+ },
+ };
+
+ let focused = false;
+ const mockQuery = {
+ value: "",
+ focus() {
+ focused = true;
+ },
+ };
+ const mockPlatform = { value: "auto" };
+ let selectedPrompt = null;
+
+ const cleanup = bindPromptButtons({
+ buttons: [mockButton],
+ queryElement: mockQuery,
+ platformElement: mockPlatform,
+ onSelect(prompt) {
+ selectedPrompt = prompt;
+ },
+ });
+
+ assert.ok(typeof clickListener === "function");
+
+ let defaultPrevented = false;
+ clickListener({
+ preventDefault() {
+ defaultPrevented = true;
+ },
+ });
+
+ assert.equal(defaultPrevented, true);
+ assert.equal(mockQuery.value, "Find emerging AI creators and inspect their most engaging videos");
+ assert.equal(mockPlatform.value, "tiktok");
+ assert.equal(focused, true);
+ assert.equal(selectedPrompt?.platform, "tiktok");
+
+ cleanup();
+ assert.equal(clickListener, null);
+});