Skip to content

armgit / kwant

Public Imported from GitHub
0

Your own team of AI bots in one self-hosted binary: spaces, every account you have, handoffs, approvals and routines. Open-source, self-hosted alternative to Grok Bot, Claude Duet and OpenAI dots. Rust + React.

Chat: team-aware suggested prompts and a phone layout pass

Pixel (kwant bot)00dffe8ea25f
diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx
index df2a7a60..ffcb2886 100644
--- a/frontend/src/App.tsx
+++ b/frontend/src/App.tsx
@@ -92,6 +92,7 @@ import { useEngines } from './useEngines';
import { claudeNeedsSignIn } from './claudeLogin';
import { personFetch } from './auth';
import { teamChannelOf, teamOfChannel } from './teamChannel';
+import { PromptContext, suggestedPrompts } from './suggestedPrompts';
// Kwant and Tools editors are their own chunks. They stay mounted (rendering nothing while closed),
// so both load right after start-up and opening them never waits.
@@ -2146,6 +2147,40 @@ export const SpaceApp: React.FC<SpaceAppProps> = ({
? `Laya picks who answers, from the ${kwants.length} ${kwants.length === 1 ? 'bot' : 'bots'} in ${space.name}`
: currentTeam?.description || currentChannel?.description || `A team in ${space.name}`;
+ // "Suggested:" prompts from who is in this chat, so a kitchen team isn't offered developer prompts
+ const idsOf = (v: string[] | string | undefined): string[] => {
+ if (Array.isArray(v)) return v;
+ try {
+ const parsed = JSON.parse(v || '[]');
+ return Array.isArray(parsed) ? parsed : [];
+ } catch {
+ return [];
+ }
+ };
+ const channelMembers = currentChannel
+ ? kwants.filter((k) => k.id === currentChannel.lead_kwant_id || idsOf(currentChannel.member_kwants).includes(k.id))
+ : [];
+ const promptContext: PromptContext | null = currentKwant
+ ? { kind: 'bot', bot: currentKwant }
+ : isGeneral
+ ? { kind: 'general', bots: kwants }
+ : currentTeam
+ ? {
+ kind: 'team',
+ members: currentTeamMembers,
+ lead: kwants.find((k) => k.id === currentTeam.lead_kwant_id)?.name,
+ purpose: currentTeam.description,
+ }
+ : currentChannel
+ ? {
+ kind: 'team',
+ members: channelMembers,
+ lead: kwants.find((k) => k.id === currentChannel.lead_kwant_id)?.name,
+ purpose: currentChannel.description,
+ }
+ : null;
+ const chatSuggestions = promptContext ? suggestedPrompts(promptContext) : [];
+
// A different team or bot: forget the last one's page
useEffect(() => {
setScreenshotBase64(null);
@@ -2670,6 +2705,7 @@ export const SpaceApp: React.FC<SpaceAppProps> = ({
onResolveApproval={handleResolveApproval}
kwants={kwants}
teams={teams}
+ suggestions={chatSuggestions}
discussionState={isDiscussionActiveHere ? discussionState : { inProgress: false }}
routingState={isCurrentContextStreaming ? routingState : null}
onCancelDiscussion={handleCancelDiscussion}
diff --git a/frontend/src/components/ChatView.tsx b/frontend/src/components/ChatView.tsx
index 7a99efa6..126813f5 100644
--- a/frontend/src/components/ChatView.tsx
+++ b/frontend/src/components/ChatView.tsx
@@ -120,6 +120,8 @@ export interface ChatViewProps {
onResolveApproval: (id: string, decision: 'allow_once' | 'always_allow' | 'deny') => void;
kwants?: Array<{ id: string; name: string; title: string; avatar_sprite: string }>;
teams?: Array<{ id: string; name: string; description?: string; member_kwants?: string[] }>;
+ /** Prompts offered above an empty chat, made from who is in it; none hides the bar. */
+ suggestions?: string[];
discussionState?: DiscussionState;
routingState?: RoutingState | null;
onCancelDiscussion?: () => void;
@@ -205,6 +207,36 @@ export const renderFormattedText = (text: string): React.ReactNode => {
});
};
+/** "24.2k" for a token count, so it fits on a phone's line. */
+export const compactTokens = (n: number): string =>
+ n >= 1000 ? `${(n / 1000).toFixed(n >= 100_000 ? 0 : 1).replace(/\.0$/, '')}k` : String(n);
+
+/** Why Laya picked this bot. Phones show one line and open the rest on a tap. */
+const RoutingLine: React.FC<{ text: string; fallback: boolean }> = ({ text, fallback }) => {
+ const [open, setOpen] = useState(false);
+ const tone = fallback ? 'text-amber-300/80' : 'text-violet-300/80';
+ const icon = <Sparkles size={10} className="inline -mt-0.5 mr-1" aria-hidden="true" />;
+ return (
+ <>
+ <p className={`hidden sm:block -mt-1 mb-1.5 text-[11px] ${tone} break-words`} data-routing-line>
+ {icon}
+ {text}
+ </p>
+ <button
+ type="button"
+ data-compact
+ onClick={() => setOpen((v) => !v)}
+ aria-expanded={open}
+ title={open ? undefined : text}
+ className={`sm:hidden -mt-3.5 -mb-1.5 py-3.5 max-w-full text-left text-[11px] ${tone} ${open ? 'break-words' : 'truncate'} rounded focus-visible:outline focus-visible:outline-2 focus-visible:outline-sky-500`}
+ >
+ {icon}
+ {text}
+ </button>
+ </>
+ );
+};
+
const LayaRoutingCard: React.FC<{ routing: RoutingState; spaceName?: string }> = ({ routing, spaceName }) => {
const deciding = routing.phase === 'deciding';
const isDiscuss = routing.mode === 'discuss';
@@ -296,6 +328,7 @@ export const ChatView: React.FC<ChatViewProps> = ({
onResolveApproval,
kwants: kwantsProp,
teams: teamsProp,
+ suggestions = [],
discussionState,
routingState,
onCancelDiscussion,
@@ -735,33 +768,36 @@ export const ChatView: React.FC<ChatViewProps> = ({
flashId === msg.id ? 'kw-flash' : ''
}`}
>
- <ModernAvatar
- role={isUser ? 'user' : title}
- name={displayName}
- size={34}
- />
+ {/* Phones show the avatar inside the name line instead, so the bubble gets the full width */}
+ <span className="hidden sm:contents">
+ <ModernAvatar
+ role={isUser ? 'user' : title}
+ name={displayName}
+ size={34}
+ />
+ </span>
- <div className={`flex flex-col min-w-0 ${isUser ? 'max-w-2xl items-end' : 'flex-1 max-w-4xl items-start'}`}>
- {/* Header info */}
- <div className="flex items-center gap-2 mb-1.5 text-[11px] text-zinc-400 font-medium">
- <span className="text-zinc-200">{displayName}</span>
+ <div className={`flex flex-col min-w-0 ${isUser ? 'max-w-[85%] sm:max-w-2xl items-end' : 'flex-1 max-w-4xl items-start'}`}>
+ {/* Header info: one line on phones; the account and token count move under the reply there */}
+ <div className="flex items-center gap-2 mb-1.5 text-[11px] text-zinc-400 font-medium max-w-full min-w-0 whitespace-nowrap">
+ {!isUser && (
+ <span className="sm:hidden shrink-0 inline-flex">
+ <ModernAvatar role={title} name={displayName} size={20} />
+ </span>
+ )}
+ <span className="text-zinc-200 shrink-0">{displayName}</span>
{ranOn && (
- <span className="text-zinc-500 font-mono text-[10px]" title={`Answered with ${ranOn}`}>
+ <span className="text-zinc-500 font-mono text-[10px] truncate min-w-0" title={`Answered with ${ranOn}`}>
{ranOn}
</span>
)}
- {account && <span className="text-zinc-500 text-[10px] truncate max-w-[12rem]">ran on {account}</span>}
+ {account && <span className="hidden sm:inline text-zinc-500 text-[10px] truncate max-w-[12rem]">ran on {account}</span>}
{msg.tokens_used ? (
- <span className="text-zinc-500 font-mono text-[10px]">({msg.tokens_used} tokens)</span>
+ <span className="hidden sm:inline text-zinc-500 font-mono text-[10px]">({msg.tokens_used} tokens)</span>
) : null}
</div>
- {routed && (
- <p className={`-mt-1 mb-1.5 text-[11px] ${routed.fallback ? 'text-amber-300/80' : 'text-violet-300/80'} break-words`} data-routing-line>
- <Sparkles size={10} className="inline -mt-0.5 mr-1" aria-hidden="true" />
- {routingLine(routed, spaceName ?? 'this space')}
- </p>
- )}
+ {routed && <RoutingLine text={routingLine(routed, spaceName ?? 'this space')} fallback={!!routed.fallback} />}
{/* What the reply did: "12 steps · 41s", opening to the steps (tool calls go inside) */}
{savedActivity && (
@@ -800,7 +836,7 @@ export const ChatView: React.FC<ChatViewProps> = ({
{/* Message Body Bubble */}
{!filesOnly && (msg.text.trim() || !files.length) && (
<div
- className={`p-4 sm:p-5 rounded-2xl text-sm leading-relaxed shadow-sm w-full ${
+ className={`px-3.5 py-3 sm:p-5 rounded-2xl text-sm leading-relaxed shadow-sm w-full ${
isUser
? 'bg-zinc-800 text-zinc-100 rounded-tr-sm border border-zinc-700/60 max-w-2xl'
: 'bg-zinc-900/60 text-zinc-200 rounded-tl-sm border border-zinc-800/80'
@@ -819,7 +855,7 @@ export const ChatView: React.FC<ChatViewProps> = ({
{/* Copy action */}
{!isUser && !filesOnly && (
- <div className="mt-1.5 flex items-center gap-2 text-zinc-500 text-xs">
+ <div className="mt-1.5 flex items-center gap-2 text-zinc-500 text-xs max-w-full min-w-0">
<button
type="button"
onClick={() => handleCopy(msg.text, msg.id)}
@@ -834,10 +870,16 @@ export const ChatView: React.FC<ChatViewProps> = ({
) : (
<>
<Copy size={12} />
- <span>Copy markdown</span>
+ <span className="sm:hidden">Copy</span>
+ <span className="hidden sm:inline">Copy markdown</span>
</>
)}
</button>
+ {(account || msg.tokens_used) && (
+ <span className="sm:hidden min-w-0 truncate text-[10px]">
+ {[account && `ran on ${account}`, msg.tokens_used && `${compactTokens(msg.tokens_used)} tokens`].filter(Boolean).join(' · ')}
+ </span>
+ )}
</div>
)}
</div>
@@ -867,7 +909,7 @@ export const ChatView: React.FC<ChatViewProps> = ({
<p className="text-[11px] text-zinc-400 truncate max-w-lg mt-0.5">{subtitle}</p>
</div>
- <div className="flex items-center gap-1.5 sm:gap-3 shrink-0">
+ <div className="flex items-center gap-0.5 sm:gap-3 shrink-0">
{/* Active Team Workspace Badge */}
{(workspacePath || repoUrl) && (
<div
@@ -888,7 +930,7 @@ export const ChatView: React.FC<ChatViewProps> = ({
)}
{teamMembers && teamMembers.length > 0 && (
- <div className="flex items-center gap-2 sm:pl-3 sm:border-l border-zinc-800">
+ <div className="flex items-center gap-0.5 sm:gap-2 sm:pl-3 sm:border-l border-zinc-800">
<div className="hidden sm:flex -space-x-2 items-center px-1 py-1 -my-0.5">
{teamMembers.map((member) => (
<div
@@ -904,7 +946,7 @@ export const ChatView: React.FC<ChatViewProps> = ({
<button
type="button"
onClick={onManageTeam}
- className="flex items-center gap-1.5 px-2.5 py-1 rounded-lg text-xs font-medium text-zinc-300 bg-zinc-800/80 hover:bg-zinc-700/80 hover:text-zinc-100 border border-zinc-700/60 transition-colors shadow-sm cursor-pointer"
+ className="kw-head-btn flex items-center justify-center gap-1.5 max-sm:min-w-11 px-2.5 py-1 rounded-lg text-xs font-medium text-zinc-300 bg-zinc-800/80 hover:bg-zinc-700/80 hover:text-zinc-100 border border-zinc-700/60 transition-colors shadow-sm cursor-pointer"
title="Team members and settings"
aria-label="Manage team"
>
@@ -919,7 +961,7 @@ export const ChatView: React.FC<ChatViewProps> = ({
<button
type="button"
onClick={onEditInstructions}
- className="flex items-center justify-center gap-1.5 max-md:min-w-11 px-2.5 py-1 rounded-lg text-xs font-medium text-zinc-300 bg-zinc-800/80 hover:bg-zinc-700/80 hover:text-zinc-100 border border-zinc-700/60 transition-colors shadow-sm cursor-pointer"
+ className="kw-head-btn flex items-center justify-center gap-1.5 max-md:min-w-11 px-2.5 py-1 rounded-lg text-xs font-medium text-zinc-300 bg-zinc-800/80 hover:bg-zinc-700/80 hover:text-zinc-100 border border-zinc-700/60 transition-colors shadow-sm cursor-pointer"
title="Pin instructions every bot reads in this channel"
aria-label="Pin instructions"
>
@@ -932,7 +974,7 @@ export const ChatView: React.FC<ChatViewProps> = ({
<button
type="button"
onClick={onEditKwant}
- className="flex items-center gap-1.5 px-2.5 py-1 rounded-lg text-xs font-medium text-zinc-300 bg-zinc-800/80 hover:bg-zinc-700/80 hover:text-zinc-100 border border-zinc-700/60 transition-colors shadow-sm cursor-pointer"
+ className="kw-head-btn flex items-center gap-1.5 px-2.5 py-1 rounded-lg text-xs font-medium text-zinc-300 bg-zinc-800/80 hover:bg-zinc-700/80 hover:text-zinc-100 border border-zinc-700/60 transition-colors shadow-sm cursor-pointer"
title={`Edit ${title}'s name, avatar, model and persona`}
aria-label={`Edit ${title}`}
>
@@ -959,7 +1001,7 @@ export const ChatView: React.FC<ChatViewProps> = ({
playSfx('click');
toggleVm();
}}
- className={`flex items-center justify-center gap-1.5 max-md:min-w-11 px-2.5 py-1 rounded-full text-xs font-medium transition-colors border shadow-sm cursor-pointer ${
+ className={`kw-head-btn flex items-center justify-center gap-1.5 max-md:min-w-11 px-2.5 py-1 rounded-full text-xs font-medium transition-colors border shadow-sm cursor-pointer ${
vmOpen
? 'text-sky-300 bg-sky-500/20 border-sky-500/40'
: 'text-zinc-300 bg-zinc-900 hover:bg-zinc-800 border-zinc-700/60 hover:text-zinc-100'
@@ -980,11 +1022,11 @@ export const ChatView: React.FC<ChatViewProps> = ({
{/* Discussion In-Flight Banner */}
{discussionState?.inProgress && (
- <div className="px-6 pt-3 select-none flex-shrink-0">
- <div className="flex items-center justify-between px-4 py-2 bg-sky-950/40 border border-sky-800/40 rounded-xl mb-3 text-xs">
- <div className="flex items-center gap-2 text-sky-200">
- <Users size={14} className="text-sky-400 animate-pulse" />
- <span>
+ <div className="px-3 sm:px-6 pt-3 select-none flex-shrink-0">
+ <div className="flex items-center justify-between gap-2 px-3 sm:px-4 py-2 bg-sky-950/40 border border-sky-800/40 rounded-xl mb-3 text-xs">
+ <div className="flex items-center gap-2 text-sky-200 min-w-0">
+ <Users size={14} className="text-sky-400 animate-pulse shrink-0" />
+ <span className="min-w-0">
{discussionState.kind === 'handoff' ? (
<>
Handoff: <strong>{discussionState.currentSpeaker || 'Teammate'}</strong> is replying
@@ -1012,10 +1054,10 @@ export const ChatView: React.FC<ChatViewProps> = ({
<button
type="button"
onClick={onCancelDiscussion}
- className="flex items-center gap-1 px-2.5 py-1 bg-red-500/20 hover:bg-red-500/30 text-red-300 rounded border border-red-500/30 transition-colors cursor-pointer"
+ className="shrink-0 flex items-center gap-1 px-2.5 py-1 bg-red-500/20 hover:bg-red-500/30 text-red-300 rounded border border-red-500/30 transition-colors cursor-pointer"
>
<Square size={11} fill="currentColor" />
- <span>Stop Discussion</span>
+ <span>Stop<span className="hidden sm:inline"> Discussion</span></span>
</button>
)}
</div>
@@ -1029,7 +1071,7 @@ export const ChatView: React.FC<ChatViewProps> = ({
<div
ref={scrollRef}
onScroll={onScroll}
- className="flex-1 overflow-y-auto p-4 sm:p-6 space-y-6"
+ className="flex-1 overflow-y-auto px-3 py-4 sm:p-6 space-y-5 sm:space-y-6"
role="log"
aria-label={`Messages in ${title}`}
aria-busy={isStreaming}
@@ -1043,7 +1085,7 @@ export const ChatView: React.FC<ChatViewProps> = ({
<button
type="button"
onClick={() => toggleThought(threadKey)}
- className="ml-[48px] flex items-center gap-2.5 px-3 py-1.5 rounded-xl text-xs text-zinc-400 hover:text-zinc-200 bg-zinc-900/60 hover:bg-zinc-900 border border-zinc-800 hover:border-zinc-700/80 transition-all cursor-pointer"
+ className="sm:ml-[48px] max-w-full flex items-center gap-2.5 px-3 py-1.5 rounded-xl text-xs text-zinc-400 hover:text-zinc-200 bg-zinc-900/60 hover:bg-zinc-900 border border-zinc-800 hover:border-zinc-700/80 transition-all cursor-pointer"
>
{isThreadOpen ? <ChevronDown size={13} className="text-zinc-500" /> : <ChevronRight size={13} className="text-zinc-500" />}
<span className="flex -space-x-1.5">
@@ -1051,12 +1093,12 @@ export const ChatView: React.FC<ChatViewProps> = ({
<ModernAvatar key={name} role={name} name={name} size={18} />
))}
</span>
- <span>
+ <span className="min-w-0 truncate">
Team discussed • {item.turns.length} {item.turns.length === 1 ? 'turn' : 'turns'} • {item.speakers.join(', ')}
</span>
</button>
{isThreadOpen && (
- <div className="mt-4 ml-[30px] pl-4 border-l border-zinc-800 space-y-6">
+ <div className="mt-4 ml-2 pl-3 sm:ml-[30px] sm:pl-4 border-l border-zinc-800 space-y-6">
{item.turns.map(renderMessage)}
</div>
)}
@@ -1157,19 +1199,20 @@ export const ChatView: React.FC<ChatViewProps> = ({
))}
</div>
- {/* Suggestion Prompts Pill Bar */}
- {messages.length <= 1 && (
- <div className="px-6 py-2 flex flex-wrap items-center gap-2 select-none">
- <span className="text-[11px] font-medium text-zinc-500">Suggested:</span>
- {[
- "Analyze system architecture tradeoffs",
- "Write a fast Python script for data processing",
- "Review git status and security policies",
- ].map((prompt, idx) => (
+ {/* Suggested prompts for who is in this chat: one swipeable row on phones */}
+ {messages.length <= 1 && suggestions.length > 0 && (
+ <div
+ className="kw-scroll-row px-3 sm:px-6 py-2 flex flex-nowrap sm:flex-wrap items-center gap-2 overflow-x-auto sm:overflow-visible select-none"
+ role="group"
+ aria-label="Suggested prompts"
+ >
+ <span className="shrink-0 text-[11px] font-medium text-zinc-500">Suggested:</span>
+ {suggestions.map((prompt) => (
<button
- key={idx}
+ key={prompt}
+ type="button"
onClick={() => handlePromptSuggestion(prompt)}
- className="px-2.5 py-1 rounded-full text-xs text-zinc-400 bg-zinc-900 border border-zinc-800 hover:border-zinc-700 hover:text-zinc-200 transition-all shadow-sm"
+ className="shrink-0 whitespace-nowrap px-2.5 py-1 rounded-full text-xs text-zinc-400 bg-zinc-900 border border-zinc-800 hover:border-zinc-700 hover:text-zinc-200 transition-all shadow-sm focus-visible:outline focus-visible:outline-2 focus-visible:outline-sky-500"
>
{prompt}
</button>
@@ -1178,16 +1221,16 @@ export const ChatView: React.FC<ChatViewProps> = ({
)}
{/* Modern Composer Input Bar */}
- <div className="p-4 border-t border-zinc-800/80 bg-zinc-900/30">
+ <div className="px-3 pt-3 pb-[max(0.75rem,env(safe-area-inset-bottom))] sm:p-4 border-t border-zinc-800/80 bg-zinc-900/30">
{teamMembers && teamMembers.length > 0 && (
- <div className="max-w-4xl mx-auto mb-2.5 flex items-center gap-1.5 overflow-x-auto text-xs select-none">
- <span className="text-[11px] font-medium text-zinc-500 whitespace-nowrap">Ask:</span>
+ <div className="kw-scroll-row max-w-4xl mx-auto mb-2.5 flex items-center gap-1.5 overflow-x-auto text-xs select-none" role="group" aria-label="Ask a member">
+ <span className="shrink-0 text-[11px] font-medium text-zinc-500 whitespace-nowrap">Ask:</span>
{teamMembers.map((m) => (
<button
key={m.id}
type="button"
onClick={() => handleInsertTag(`@${m.name}`)}
- className="flex items-center gap-1.5 px-2.5 py-1 rounded-full bg-zinc-800/90 hover:bg-zinc-700 text-zinc-300 hover:text-zinc-100 border border-zinc-700/60 transition-all text-xs cursor-pointer shadow-sm active:scale-95"
+ className="shrink-0 whitespace-nowrap flex items-center gap-1.5 px-2.5 py-1 rounded-full bg-zinc-800/90 hover:bg-zinc-700 text-zinc-300 hover:text-zinc-100 border border-zinc-700/60 transition-all text-xs cursor-pointer shadow-sm active:scale-95"
title={`Ask ${m.name}`}
>
<ModernAvatar role={m.avatar_sprite} name={m.name} size={14} kwantId={m.id} />
@@ -1198,7 +1241,7 @@ export const ChatView: React.FC<ChatViewProps> = ({
<button
type="button"
onClick={() => handleInsertTag(`@${teamName}`)}
- className="flex items-center gap-1.5 px-2.5 py-1 rounded-full bg-sky-950/60 hover:bg-sky-900/60 text-sky-300 hover:text-sky-200 border border-sky-800/60 transition-all text-xs cursor-pointer shadow-sm active:scale-95"
+ className="shrink-0 whitespace-nowrap flex items-center gap-1.5 px-2.5 py-1 rounded-full bg-sky-950/60 hover:bg-sky-900/60 text-sky-300 hover:text-sky-200 border border-sky-800/60 transition-all text-xs cursor-pointer shadow-sm active:scale-95"
title={`Ask whole team @${teamName}`}
>
<Users size={12} className="text-sky-400" />
diff --git a/frontend/src/components/ModernApprovalCard.tsx b/frontend/src/components/ModernApprovalCard.tsx
index c136cfc9..bb406713 100644
--- a/frontend/src/components/ModernApprovalCard.tsx
+++ b/frontend/src/components/ModernApprovalCard.tsx
@@ -118,7 +118,7 @@ export const ModernApprovalCard: React.FC<ModernApprovalCardProps> = ({
return (
<div
- className={`my-3 border rounded-xl p-4 text-zinc-100 max-w-2xl shadow-lg backdrop-blur-sm ${
+ className={`my-3 border rounded-xl p-3 sm:p-4 text-zinc-100 max-w-2xl shadow-lg backdrop-blur-sm ${
waiting ? 'border-sky-500/30 bg-sky-950/20' : 'border-amber-500/30 bg-amber-950/20'
}`}
>
diff --git a/frontend/src/styles/modern.css b/frontend/src/styles/modern.css
index 28e421cb..bada18c8 100644
--- a/frontend/src/styles/modern.css
+++ b/frontend/src/styles/modern.css
@@ -171,3 +171,23 @@
font-size: 16px;
}
}
+
+/* Phone-width chat: swipeable chip rows without a scrollbar, fading at the right edge, and the
+ header's action buttons as plain icons so they don't crowd the title. */
+@media (max-width: 639px) {
+ .kw-scroll-row {
+ scrollbar-width: none;
+ -webkit-overflow-scrolling: touch;
+ overscroll-behavior-x: contain;
+ mask-image: linear-gradient(to right, #000 calc(100% - 28px), transparent);
+ -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 28px), transparent);
+ }
+ .kw-scroll-row::-webkit-scrollbar {
+ display: none;
+ }
+ .kw-head-btn:not([aria-pressed='true']) {
+ background-color: transparent;
+ border-color: transparent;
+ box-shadow: none;
+ }
+}
diff --git a/frontend/src/suggestedPrompts.ts b/frontend/src/suggestedPrompts.ts
new file mode 100644
index 00000000..6b5ac973
--- /dev/null
+++ b/frontend/src/suggestedPrompts.ts
@@ -0,0 +1,107 @@
+// The "Suggested:" prompts above an empty chat, made from who is in it: a kitchen team gets
+// "@HeadChef plan this week's dinners", not developer prompts. No model call, so they show at once.
+
+export interface PromptBot {
+ name: string;
+ title?: string;
+ persona_prompt?: string;
+}
+
+export type PromptContext =
+ /** A team's chat, or any channel with a fixed set of members. `lead` is a member's name. */
+ | { kind: 'team'; members: PromptBot[]; lead?: string; purpose?: string }
+ /** A chat with one bot. */
+ | { kind: 'bot'; bot: PromptBot }
+ /** #general: Laya picks who answers, so prompts don't name anyone. */
+ | { kind: 'general'; bots: PromptBot[] };
+
+export const MAX_PROMPTS = 3;
+
+interface Role {
+ match: RegExp;
+ /** Lower-case asks that read after "@Name ", the first one being the most typical. */
+ asks: [string, string];
+}
+
+// Most specific first: "Sous Chef" is a sous chef before it is a chef, "DevOps" before "dev".
+const ROLES: Role[] = [
+ { match: /\bsous\b|\bline cook\b|\bprep\b/i, asks: ['write a prep list for tonight', 'suggest a quick weeknight dinner'] },
+ { match: /\bpastry\b|\bbak(er|ing)\b|\bdessert/i, asks: ['suggest a dessert for this weekend', 'bake something with what I have'] },
+ { match: /\bnutrition|\bdiet|\bdietitian\b/i, asks: ["check this week's meals are balanced", 'make a high-protein meal plan'] },
+ { match: /\bchef\b|\bcook\b|\bculinary\b|\bkitchen\b|\bmenu\b|\brecipe/i, asks: ["plan this week's dinners", 'turn my fridge into a recipe'] },
+ { match: /\bgrocer|\bshopping\b|\bpantry\b/i, asks: ["make this week's shopping list", 'keep my groceries under budget'] },
+ { match: /\bsommelier\b|\bwine\b|\bbartender\b|\bmixolog/i, asks: ['pair a drink with dinner', 'suggest a cocktail for Friday'] },
+ { match: /\bfitness\b|\btrainer\b|\bcoach\b|\bworkout\b/i, asks: ['plan my workouts for the week', 'make a 20-minute home routine'] },
+ { match: /\bdevops\b|\bsre\b|\bsecurity\b|\binfra(structure)?\b|\bsysadmin\b|\bplatform\b/i, asks: ["check my server's security", 'set up backups for my server'] },
+ { match: /\bqa\b|\btest(er|ing)?\b|\bquality\b|\brelease\b/i, asks: ['write a test plan for the next release', 'find the riskiest part of this change'] },
+ { match: /\bdesign(er)?\b|\bux\b|\bui\b|\bfrontend\b|\bfront-end\b/i, asks: ['review the sign-up screen', 'make this page work on phones'] },
+ { match: /\bbackend\b|\bback-end\b|\bdatabase\b|\bapi\b|\bdata engineer/i, asks: ['design the API for a new feature', 'speed up a slow database query'] },
+ { match: /\barchitect\b/i, asks: ['sketch the architecture for a new feature', 'weigh two ways to build this'] },
+ { match: /\bengineer\b|\bdeveloper\b|\bdev\b|\bprogrammer\b|\bcoder\b|\bprototyp/i, asks: ['build a quick prototype', 'review my latest changes'] },
+ { match: /\bseo\b|\bkeyword/i, asks: ['find keywords I could rank for', 'audit my homepage for SEO'] },
+ { match: /\bmarketing\b|\bmarketer\b|\bgrowth\b|\bcampaign\b|\bsocial media\b|\bbrand\b/i, asks: ['draft a launch post', 'plan a two-week campaign'] },
+ { match: /\bwriter\b|\bcopy(writer|writing)?\b|\bcontent\b|\beditor\b|\bauthor\b|\bblog/i, asks: ['outline a blog post', 'tighten this paragraph'] },
+ { match: /\bresearch|\banalyst\b|\bscout\b|\binvestigat/i, asks: ['research my top 3 competitors', 'summarise what people say about this'] },
+ { match: /\bsales\b|\bbusiness development\b|\blead gen/i, asks: ['draft a follow-up email to a lead', 'write a short sales pitch'] },
+ { match: /\bsupport\b|\bcustomer\b|\bcommunity\b/i, asks: ['draft a reply to an upset customer', 'write an FAQ answer'] },
+ { match: /\bfinance\b|\baccount(ant|ing)\b|\bbookkeep|\bbudget\b|\bcfo\b/i, asks: ["summarise this month's spending", 'make a simple budget'] },
+ { match: /\blegal\b|\blawyer\b|\bcounsel\b|\bcompliance\b/i, asks: ['check this contract for risks', 'explain this clause simply'] },
+ { match: /\brecruit|\bhr\b|\bhiring\b|\bpeople ops\b/i, asks: ['write a job post', 'draft interview questions'] },
+ { match: /\bteacher\b|\btutor\b|\beducat|\binstructor\b/i, asks: ['explain this topic simply', 'quiz me on this'] },
+ { match: /\btravel\b|\btrip\b/i, asks: ['plan a weekend trip', 'make a packing list'] },
+ { match: /\bproduct manager\b|\bproduct owner\b|\bpm\b|\bproduct\b/i, asks: ['turn this idea into a short spec', 'prioritise these features'] },
+ { match: /\bassistant\b|\bsecretary\b|\bplanner\b|\bscheduler\b|\borgani[sz]er\b/i, asks: ['plan my week', 'turn these notes into a to-do list'] },
+ { match: /\bvideo\b|\bfilm\b|\byoutube\b|\btiktok\b/i, asks: ['script a 30-second video', 'suggest video ideas for this week'] },
+ { match: /\bphotograph|\billustrat|\bartist\b/i, asks: ['describe a cover image idea', 'critique this image'] },
+];
+
+const capitalize = (s: string) => (s ? s[0].toUpperCase() + s.slice(1) : s);
+
+/** The role a bot's title says it has, else its persona's opening, else null. */
+export function roleOf(bot: PromptBot): Role | null {
+ const byText = (text: string | undefined) => (text ? ROLES.find((r) => r.match.test(text)) ?? null : null);
+ return byText(bot.title) ?? byText(bot.persona_prompt?.slice(0, 240));
+}
+
+/** A name that works after "@": the composer's mentions are single words. */
+const mentionable = (name: string) => /^[A-Za-z0-9_-]+$/.test(name);
+
+/** Asks for different roles, in the order given, one per role: [bot, ask] pairs. */
+function distinctAsks(bots: PromptBot[], limit: number): Array<[PromptBot, string]> {
+ const seen = new Set<Role>();
+ const out: Array<[PromptBot, string]> = [];
+ for (const bot of bots) {
+ const role = roleOf(bot);
+ if (!role || seen.has(role)) continue;
+ seen.add(role);
+ out.push([bot, role.asks[0]]);
+ if (out.length >= limit) break;
+ }
+ return out;
+}
+
+export function suggestedPrompts(ctx: PromptContext): string[] {
+ if (ctx.kind === 'bot') {
+ const role = roleOf(ctx.bot);
+ if (!role) return ['What can you help me with?'];
+ return [capitalize(role.asks[0]), capitalize(role.asks[1]), 'What can you help me with?'];
+ }
+
+ if (ctx.kind === 'general') {
+ if (!ctx.bots.length) return [];
+ const asks = distinctAsks(ctx.bots, MAX_PROMPTS - 1).map(([, ask]) => capitalize(ask));
+ return [...asks, 'Who here can help me with what?'];
+ }
+
+ const members = ctx.members.filter((m) => m.name.trim());
+ if (!members.length) return [];
+ const lead = members.find((m) => m.name === ctx.lead);
+ const ordered = lead ? [lead, ...members.filter((m) => m !== lead)] : members;
+ const asks = distinctAsks(ordered.filter((m) => mentionable(m.name)), MAX_PROMPTS - 1).map(([bot, ask]) => `@${bot.name} ${ask}`);
+ // Nobody's title says what they do: the team's purpose may, and the lead takes it.
+ if (!asks.length && lead && mentionable(lead.name) && ctx.purpose) {
+ const role = ROLES.find((r) => r.match.test(ctx.purpose!));
+ if (role) asks.push(`@${lead.name} ${role.asks[0]}`);
+ }
+ return [...asks, members.length > 1 ? 'What can each of you help me with?' : 'What can you help me with?'];
+}
diff --git a/frontend/tests/suggestedPrompts.test.mjs b/frontend/tests/suggestedPrompts.test.mjs
new file mode 100644
index 00000000..b8d1d838
--- /dev/null
+++ b/frontend/tests/suggestedPrompts.test.mjs
@@ -0,0 +1,101 @@
+import assert from 'node:assert/strict';
+import test from 'node:test';
+import { readFileSync } from 'node:fs';
+import { loadBundled } from './bundle.mjs';
+
+const { suggestedPrompts, roleOf, MAX_PROMPTS } = await loadBundled(`export * from './src/suggestedPrompts';`);
+
+const DEV_PROMPTS = ['Analyze system architecture tradeoffs', 'Write a fast Python script for data processing', 'Review git status and security policies'];
+const kitchen = [
+ { name: 'HeadChef', title: 'Head Chef' },
+ { name: 'Nutritionist', title: 'Nutritionist' },
+ { name: 'Sous', title: 'Sous Chef' },
+ { name: 'Pastry', title: 'Pastry Chef' },
+ { name: 'Grocer', title: 'Grocery Planner' },
+];
+
+test("a kitchen team gets the lead's and a teammate's cooking asks, never developer prompts", () => {
+ // What Oleks saw: a freshly hired Kitchen team offered "Analyze system architecture tradeoffs".
+ const out = suggestedPrompts({ kind: 'team', members: kitchen, lead: 'HeadChef', purpose: 'Hired together: a team of 5.' });
+ assert.deepEqual(out, ["@HeadChef plan this week's dinners", "@Nutritionist check this week's meals are balanced", 'What can each of you help me with?']);
+ for (const p of DEV_PROMPTS) assert.ok(!out.includes(p));
+});
+
+test('the lead goes first even when listed last, and two bots with one role get one ask', () => {
+ const out = suggestedPrompts({
+ kind: 'team',
+ members: [{ name: 'Cook2', title: 'Chef' }, { name: 'Cook1', title: 'Chef de cuisine' }, { name: 'Boss', title: 'Head Chef' }],
+ lead: 'Boss',
+ });
+ assert.deepEqual(out, ["@Boss plan this week's dinners", 'What can each of you help me with?']);
+});
+
+test('an engineering team still gets engineering asks', () => {
+ const out = suggestedPrompts({
+ kind: 'team',
+ members: [
+ { name: 'Architect', title: 'Systems Architect' },
+ { name: 'TechLead', title: 'Staff Engineer & Prototyper' },
+ { name: 'DevOps', title: 'Systems & Security Engineer' },
+ ],
+ lead: 'Architect',
+ });
+ assert.deepEqual(out, ['@Architect sketch the architecture for a new feature', '@TechLead build a quick prototype', 'What can each of you help me with?']);
+});
+
+test("unknown titles fall back to the team's purpose for the lead, else just the open question", () => {
+ const members = [{ name: 'Ann', title: 'Wizard' }, { name: 'Bo', title: 'Sidekick' }];
+ assert.deepEqual(suggestedPrompts({ kind: 'team', members, lead: 'Ann', purpose: 'Plans our weekly menu' }), [
+ "@Ann plan this week's dinners",
+ 'What can each of you help me with?',
+ ]);
+ assert.deepEqual(suggestedPrompts({ kind: 'team', members, lead: 'Ann' }), ['What can each of you help me with?']);
+ assert.deepEqual(suggestedPrompts({ kind: 'team', members: [members[0]] }), ['What can you help me with?']);
+ assert.deepEqual(suggestedPrompts({ kind: 'team', members: [] }), []);
+});
+
+test('names that cannot be @mentioned are not used in a mention', () => {
+ const out = suggestedPrompts({ kind: 'team', members: [{ name: 'Head Chef', title: 'Head Chef' }, { name: 'Sous', title: 'Sous Chef' }], lead: 'Head Chef' });
+ assert.deepEqual(out, ['@Sous write a prep list for tonight', 'What can each of you help me with?']);
+});
+
+test("a one-to-one chat uses that bot's role, or its persona when the title says nothing", () => {
+ assert.deepEqual(suggestedPrompts({ kind: 'bot', bot: { name: 'Nutritionist', title: 'Nutritionist' } }), [
+ "Check this week's meals are balanced",
+ 'Make a high-protein meal plan',
+ 'What can you help me with?',
+ ]);
+ assert.equal(suggestedPrompts({ kind: 'bot', bot: { name: 'X', title: 'Helper', persona_prompt: 'You are a seasoned SEO strategist.' } })[0], 'Find keywords I could rank for');
+ assert.deepEqual(suggestedPrompts({ kind: 'bot', bot: { name: 'X', title: 'Helper' } }), ['What can you help me with?']);
+});
+
+test("#general draws on the space's bots without naming them, and is empty with no bots", () => {
+ const out = suggestedPrompts({ kind: 'general', bots: [{ name: 'DevOps', title: 'Systems & Security Engineer' }, ...kitchen] });
+ assert.deepEqual(out, ["Check my server's security", "Plan this week's dinners", 'Who here can help me with what?']);
+ assert.ok(out.every((p) => !p.includes('@')));
+ assert.deepEqual(suggestedPrompts({ kind: 'general', bots: [] }), []);
+});
+
+test('never more than three, each short enough for a phone chip', () => {
+ const many = Array.from({ length: 30 }, (_, i) => ({ name: `B${i}`, title: ['Chef', 'Writer', 'Lawyer', 'Tutor', 'SEO lead'][i % 5] }));
+ for (const ctx of [{ kind: 'team', members: many }, { kind: 'general', bots: many }, { kind: 'bot', bot: many[0] }]) {
+ const out = suggestedPrompts(ctx);
+ assert.ok(out.length <= MAX_PROMPTS, JSON.stringify(out));
+ assert.ok(out.every((p) => p.length <= 50), JSON.stringify(out));
+ }
+});
+
+test('specific roles win over general ones', () => {
+ assert.equal(roleOf({ name: 'a', title: 'Sous Chef' }).asks[0], 'write a prep list for tonight');
+ assert.equal(roleOf({ name: 'a', title: 'DevOps Engineer' }).asks[0], "check my server's security");
+ assert.equal(roleOf({ name: 'a', title: 'QA and Release Engineer' }).asks[0], 'write a test plan for the next release');
+ assert.equal(roleOf({ name: 'a', title: 'Frontend Engineer' }).asks[0], 'review the sign-up screen');
+ assert.equal(roleOf({ name: 'a', title: 'Wizard' }), null);
+});
+
+test('the chat no longer hardcodes developer prompts', () => {
+ const src = readFileSync(new URL('../src/components/ChatView.tsx', import.meta.url), 'utf8');
+ for (const p of DEV_PROMPTS) assert.ok(!src.includes(p), p);
+ const app = readFileSync(new URL('../src/App.tsx', import.meta.url), 'utf8');
+ assert.match(app, /suggestedPrompts\(/);
+});