Skip to content

AI Agents & MCPs & AI Workflow Automation • (~400 MCP servers for AI agents) • AI Automation / AI Agent with MCPs • AI Workflows & AI Agents • MCPs for AI Agents

feat(agents): describe an agent on the agents page and the chat builds it (#15667)

Hazem Adel8d21bce2919b
diff --git a/packages/web/public/locales/en/translation.json b/packages/web/public/locales/en/translation.json
index bc37ea26420..8f0499542da 100644
--- a/packages/web/public/locales/en/translation.json
+++ b/packages/web/public/locales/en/translation.json
@@ -2597,6 +2597,9 @@
"No agents match that search": "No agents match that search",
"No agents in this project yet": "No agents in this project yet",
"Describe one above, or pick another project.": "Describe one above, or pick another project.",
+ "Add one with New agent, or pick another project.": "Add one with New agent, or pick another project.",
+ "Build me an agent for this: {task}": "Build me an agent for this: {task}",
+ "An agent follows instructions you write and does the work using the apps you have connected.": "An agent follows instructions you write and does the work using the apps you have connected.",
"Only you and the people you shared it with": "Only you and the people you shared it with",
"Agent deleted": "Agent deleted",
"Agents": "Agents",
diff --git a/packages/web/src/app/routes/agents/index.tsx b/packages/web/src/app/routes/agents/index.tsx
index a46fe619031..fc2e84dd8cb 100644
--- a/packages/web/src/app/routes/agents/index.tsx
+++ b/packages/web/src/app/routes/agents/index.tsx
@@ -3,7 +3,7 @@ import {
AgentListSort,
AgentSummary,
ColorName,
- MAX_DRAFT_PROMPT_LENGTH,
+ DEFAULT_AGENT_MAX_STEPS,
PROJECT_COLOR_PALETTE,
} from '@activepieces/shared';
import { t } from 'i18next';
@@ -12,13 +12,10 @@ import {
ChevronsUpDown,
LayoutGrid,
List,
- Pencil,
Plus,
Search,
SearchX,
- Settings2,
} from 'lucide-react';
-import { AnimatePresence, motion } from 'motion/react';
import { useMemo, useState } from 'react';
import { useNavigate } from 'react-router-dom';
import { useDebounce } from 'use-debounce';
@@ -51,18 +48,14 @@ import {
agentsQueries,
useAgentsAvailable,
} from '@/features/agents/hooks/agents-hooks';
-import { createAgentUtils } from '@/features/agents/lib/create-agent-utils';
import { NewBlankAgentButton } from '@/features/agents/new-blank-agent-button';
-import { aiProviderQueries } from '@/features/platform-admin/hooks/ai-provider-hooks';
import { getProjectName, projectCollectionUtils } from '@/features/projects';
-import { useIsPlatformAdmin } from '@/hooks/authorization-hooks';
-import { api } from '@/lib/api';
+import { platformHooks } from '@/hooks/platform-hooks';
+import { CHAT_ROUTE } from '@/lib/route-utils';
import { cn } from '@/lib/utils';
import {
- acceptsDraftPrompt,
showsAgentList,
- shownDestination,
showsFirstRun,
showsNoMatchNotice,
} from './lib/agents-list-state';
@@ -124,18 +117,13 @@ const AgentsPageContent = () => {
const [sort, setSort] = useState<AgentListSort>(AgentListSort.UPDATED);
const [prompt, setPrompt] = useState('');
const [viewProjectId, setViewProjectId] = useState<string>(ALL_PROJECTS);
- const [pickedProjectId, setPickedProjectId] = useState<string | null>(null);
- const [buildingInProjectId, setBuildingInProjectId] = useState<string | null>(
- null,
- );
const navigate = useNavigate();
const { project } = projectCollectionUtils.useCurrentProject();
const { data: allProjects } = projectCollectionUtils.useAll();
+ const { platform } = platformHooks.useCurrentPlatform();
const agentsAvailable = useAgentsAvailable();
- const isPlatformAdmin = useIsPlatformAdmin();
+ const chatEnabled = platform.plan.chatEnabled;
const projectFiltered = viewProjectId !== ALL_PROJECTS;
- const createInProjectId =
- pickedProjectId ?? (projectFiltered ? viewProjectId : project.id);
const [debouncedSearch] = useDebounce(search.trim(), 300);
const {
data,
@@ -158,32 +146,11 @@ const AgentsPageContent = () => {
[data],
);
- const draftAgent = agentsMutations.useDraftAgent();
const createAgent = agentsMutations.useCreateAgent({
onSuccess: (agent) =>
navigate(`/projects/${agent.projectId}/agents/${agent.id}`),
onError: () => undefined,
});
- const {
- data: chatProvider,
- isLoading: isLoadingProvider,
- isError: providerLookupFailed,
- } = aiProviderQueries.useChatProvider(createInProjectId);
- const { data: projectProviders } =
- aiProviderQueries.useProjectAiProviders(createInProjectId);
- const needsProvider =
- !isLoadingProvider && !providerLookupFailed && chatProvider === undefined;
- const chatIsOffOnEveryProvider =
- needsProvider && (projectProviders?.length ?? 0) > 0;
- const isBuilding = draftAgent.isPending || createAgent.isPending;
- const destinationReadinessUnknown = isLoadingProvider;
- const buildError = draftAgent.error ?? createAgent.error ?? null;
-
- const shownDestinationId = shownDestination({
- isBuilding,
- buildingIn: buildingInProjectId,
- picked: createInProjectId,
- });
const projectOptions = useMemo(
() =>
@@ -194,50 +161,38 @@ const AgentsPageContent = () => {
[allProjects],
);
- const buildAgent = (text?: string) => {
+ const askChat = (text?: string) => {
const trimmed = (text ?? prompt).trim();
- if (
- !acceptsDraftPrompt({
- prompt: trimmed,
- isBuilding,
- readinessUnknown: destinationReadinessUnknown,
- })
- ) {
+ if (trimmed.length === 0) {
return;
}
- setPrompt(trimmed);
- const destination = createInProjectId;
- setBuildingInProjectId(destination);
- draftAgent.mutate(
- { projectId: destination, prompt: trimmed },
- {
- onSuccess: (draft) =>
- createAgent.mutate(
- createAgentUtils.buildCreateRequest({
- draft,
- projectId: destination,
- }),
- ),
+ if (projectFiltered && viewProjectId !== project.id) {
+ projectCollectionUtils.setCurrentProject(viewProjectId);
+ }
+ navigate(CHAT_ROUTE, {
+ state: {
+ prompt: t('Build me an agent for this: {task}', { task: trimmed }),
},
- );
+ });
};
const createBlankAgent = (projectId: string) => {
if (createAgent.isPending) {
return;
}
- createAgent.mutate(
- createAgentUtils.buildCreateRequest({
- draft: {
- displayName: t('New agent'),
- description: '',
- icon: AgentIcon.BOT,
- color: ColorName.PURPLE,
- instructions: '',
- },
- projectId,
- }),
- );
+ createAgent.mutate({
+ projectId,
+ displayName: t('New agent'),
+ description: null,
+ icon: AgentIcon.BOT,
+ color: ColorName.PURPLE,
+ draft: {
+ instructions: '',
+ maxSteps: DEFAULT_AGENT_MAX_STEPS,
+ tools: [],
+ structuredOutput: [],
+ },
+ });
};
const projectDotColorFor = (agent: AgentSummary) =>
@@ -248,8 +203,6 @@ const AgentsPageContent = () => {
const openAgent = (agent: AgentSummary) =>
navigate(`/projects/${agent.projectId}/agents/${agent.id}`);
- const hasPrompt = prompt.trim().length > 0;
-
const projectById = useMemo(
() => new Map((allProjects ?? []).map((entry) => [entry.id, entry])),
[allProjects],
@@ -262,230 +215,170 @@ const AgentsPageContent = () => {
projectFiltered,
});
+ const showsHero = chatEnabled || firstRun;
+
return (
<div className="flex min-h-full w-full flex-col">
- <section
- className={cn(
- 'flex flex-col items-center gap-2 px-12 pt-8',
- firstRun &&
- 'relative flex-1 justify-center gap-3 overflow-hidden py-16',
- )}
- >
- {firstRun && (
- <>
- <div
- aria-hidden
- className="pointer-events-none absolute left-1/2 top-1/2 h-[360px] w-[520px] -translate-x-1/2 -translate-y-[230px]"
- style={{
- backgroundImage:
- 'radial-gradient(ellipse at center, hsl(var(--primary) / 0.1) 0%, hsl(var(--primary) / 0) 70%)',
- }}
- />
- <AgentTrioMark className="mb-[22px]" />
- </>
- )}
- <h1
+ {showsHero && (
+ <section
className={cn(
- 'text-2xl leading-[30px] tracking-[-0.01em]',
+ 'flex flex-col items-center gap-2 px-12 pt-8',
firstRun &&
- 'text-[32px] font-bold leading-[38px] tracking-[-0.02em]',
- )}
- >
- {isBuilding
- ? t('Building your agent')
- : chatIsOffOnEveryProvider
- ? t('No provider is turned on for chat')
- : needsProvider
- ? t('Agents need an AI provider')
- : firstRun
- ? t('Create your first agent')
- : t('What should your agent do?')}
- </h1>
- <p
- className={cn(
- 'text-[15px] leading-[18px] text-muted-foreground',
- firstRun && 'max-w-[468px] text-center text-base leading-6',
+ 'relative flex-1 justify-center gap-3 overflow-hidden py-16',
)}
>
- {chatIsOffOnEveryProvider
- ? t(
- 'Your project has a provider, but writing an agent for you needs one turned on for chat.',
- )
- : needsProvider
- ? t('Add a provider once, then I can build agents from a sentence.')
- : isBuilding
- ? t('Picking the tools and writing its instructions')
- : firstRun
- ? t(
- 'Your most reliable teammate for getting work done, powered by your tools and guided by your words.',
- )
- : t(
- "An agent is an assistant with instructions and tools. Describe the job and I'll write both.",
- )}
- </p>
- {needsProvider &&
- (isPlatformAdmin ? (
- <Button
- className="mt-4 gap-2"
- onClick={() => navigate('/platform/setup/ai')}
- >
- <Settings2 size={16} />
- {chatIsOffOnEveryProvider
- ? t('Turn on a provider for chat')
- : t('Connect an AI provider')}
- </Button>
- ) : (
- <p className="mt-4 text-[13px] leading-4 text-muted-foreground">
- {chatIsOffOnEveryProvider
- ? t('Ask your platform admin to turn on a provider for chat.')
- : t('Ask your platform admin to connect an AI provider.')}
- </p>
- ))}
- {chatIsOffOnEveryProvider && (
- <NewBlankAgentButton
- projects={allProjects ?? []}
- pending={createAgent.isPending}
- onCreate={createBlankAgent}
- className="mt-4 gap-2"
- icon={<Pencil size={16} />}
- label={t('Write one by hand instead')}
- />
- )}
- <div
- className={cn(
- 'mt-4 flex min-h-14 w-full max-w-[680px] items-end gap-3.5 rounded-[28px] border bg-muted ps-5 pe-2 py-2 transition-colors',
- isBuilding ? 'border-primary/40' : 'border-border',
- needsProvider && 'hidden',
- firstRun &&
- 'relative mt-6 max-w-[632px] flex-col items-stretch gap-4 rounded-xl bg-background px-[18px] pb-[14px] pt-[18px] shadow-[0_2px_12px_rgba(0,0,0,0.06)]',
+ {firstRun && (
+ <>
+ <div
+ aria-hidden
+ className="pointer-events-none absolute left-1/2 top-1/2 h-[360px] w-[520px] -translate-x-1/2 -translate-y-[230px]"
+ style={{
+ backgroundImage:
+ 'radial-gradient(ellipse at center, hsl(var(--primary) / 0.1) 0%, hsl(var(--primary) / 0) 70%)',
+ }}
+ />
+ <AgentTrioMark className="mb-[22px]" />
+ </>
)}
- >
- <Textarea
- value={prompt}
- minRows={1}
- maxRows={8}
- maxLength={MAX_DRAFT_PROMPT_LENGTH}
- disabled={isBuilding}
- onChange={(event) => setPrompt(event.target.value)}
- onKeyDown={(event) => {
- if (event.key === 'Enter' && !event.shiftKey) {
- event.preventDefault();
- buildAgent();
- }
- }}
- placeholder={
- firstRun
- ? t(
- 'Describe a task for your agent… e.g. research our competitors and send me a weekly brief',
- )
- : t('Draft weekly launch posts and file them in Notion…')
- }
+ <h1
className={cn(
- 'min-h-10 resize-none border-0 bg-transparent px-0 py-2.5 text-base leading-5 shadow-none focus-visible:ring-0 placeholder:text-neutral-400',
- firstRun && 'min-h-11 px-1 py-1 text-[15px] leading-[22px]',
- )}
- />
- <div className={cn(firstRun && 'flex justify-end')}>
- <Button
- size="icon"
- loading={isBuilding || destinationReadinessUnknown}
- onClick={() => buildAgent()}
- className={cn(
- 'size-10 shrink-0 rounded-full',
- firstRun && 'size-9',
- )}
- >
- <ArrowUp size={16} strokeWidth={2.2} />
- </Button>
- </div>
- </div>
- <AnimatePresence initial={false}>
- {!needsProvider && hasPrompt && (allProjects ?? []).length > 1 && (
- <motion.div
- className="overflow-hidden"
- initial={{ height: 0, opacity: 0 }}
- animate={{ height: 'auto', opacity: 1 }}
- exit={{ height: 0, opacity: 0 }}
- transition={{ duration: 0.18, ease: 'easeOut' }}
- >
- <div className="mt-[10px] flex items-center gap-1.5 text-[13px] leading-4 text-muted-foreground">
- <span>{t('New agents go to')}</span>
- <SearchableSelect
- value={shownDestinationId}
- onChange={(value) => setPickedProjectId(value)}
- options={projectOptions}
- disabled={isBuilding}
- placeholder={t('Search projects')}
- contentWidth="260px"
- triggerClassName="h-7 w-auto max-w-[220px] gap-1 border-0 bg-transparent px-1.5 text-[13px] font-medium shadow-none hover:bg-accent"
- />
- </div>
- </motion.div>
- )}
- </AnimatePresence>
- {buildError !== null && (
- <p className="max-w-[680px] text-center text-[13px] leading-4 text-destructive">
- {api.extractServerErrorMessage(
- buildError,
- t("That didn't work. Try describing the agent another way."),
+ 'text-2xl leading-[30px] tracking-[-0.01em]',
+ firstRun &&
+ 'text-[32px] font-bold leading-[38px] tracking-[-0.02em]',
)}
- </p>
- )}
- {!needsProvider && (
- <div
+ >
+ {firstRun
+ ? t('Create your first agent')
+ : t('What should your agent do?')}
+ </h1>
+ <p
className={cn(
- 'mt-[14px] flex flex-wrap items-center justify-center gap-2',
- firstRun && 'mt-[22px] flex-col gap-[14px]',
+ 'text-[15px] leading-[18px] text-muted-foreground',
+ firstRun && 'max-w-[468px] text-center text-base leading-6',
)}
>
- <span
- className={cn(
- 'text-[13px] leading-4 text-muted-foreground',
- firstRun && 'font-medium',
- )}
- >
- {firstRun ? t('Popular starting points') : t('Try:')}
- </span>
- <div className="flex flex-wrap items-center justify-center gap-[10px]">
- {firstRun
- ? TEMPLATE_STARTERS.map((starter) => (
- <button
- key={starter.label}
- type="button"
- disabled={isBuilding || destinationReadinessUnknown}
- onClick={() => buildAgent(t(starter.prompt))}
- className="flex items-center gap-2 rounded-full border border-border py-[9px] pe-4 ps-[14px] text-sm font-medium leading-4 text-neutral-700 transition-colors hover:bg-accent disabled:opacity-50"
- >
- <span
- aria-hidden
- className="size-[11px] shrink-0 rounded-sm"
- style={{ backgroundColor: starter.dot }}
- />
- {t(starter.label)}
- </button>
- ))
- : SUGGESTIONS.map((suggestion) => (
- <button
- key={suggestion}
- type="button"
- disabled={isBuilding || destinationReadinessUnknown}
- onClick={() => buildAgent(t(suggestion))}
- className="rounded-full border border-border px-3 py-[5px] text-[13px] leading-4 transition-colors hover:bg-accent disabled:opacity-50"
- >
- {t(suggestion)}
- </button>
- ))}
- </div>
- </div>
- )}
- </section>
+ {firstRun
+ ? t(
+ 'An agent follows instructions you write and does the work using the apps you have connected.',
+ )
+ : t(
+ "An agent is an assistant with instructions and tools. Describe the job and I'll write both.",
+ )}
+ </p>
+ {!chatEnabled ? (
+ <NewBlankAgentButton
+ projects={allProjects ?? []}
+ pending={createAgent.isPending}
+ onCreate={createBlankAgent}
+ variant="default"
+ className="mt-6 gap-2"
+ icon={<Plus size={16} />}
+ label={t('New agent')}
+ />
+ ) : (
+ <>
+ <div
+ className={cn(
+ 'mt-4 flex min-h-14 w-full max-w-[680px] items-end gap-3.5 rounded-[28px] border border-border bg-muted ps-5 pe-2 py-2 transition-colors',
+ firstRun &&
+ 'relative mt-6 max-w-[632px] flex-col items-stretch gap-4 rounded-xl bg-background px-[18px] pb-[14px] pt-[18px] shadow-[0_2px_12px_rgba(0,0,0,0.06)]',
+ )}
+ >
+ <Textarea
+ value={prompt}
+ minRows={1}
+ maxRows={8}
+ onChange={(event) => setPrompt(event.target.value)}
+ onKeyDown={(event) => {
+ if (event.key === 'Enter' && !event.shiftKey) {
+ event.preventDefault();
+ askChat();
+ }
+ }}
+ placeholder={
+ firstRun
+ ? t(
+ 'Describe a task for your agent… e.g. research our competitors and send me a weekly brief',
+ )
+ : t('Draft weekly launch posts and file them in Notion…')
+ }
+ className={cn(
+ 'min-h-10 resize-none border-0 bg-transparent px-0 py-2.5 text-base leading-5 shadow-none focus-visible:ring-0 placeholder:text-neutral-400',
+ firstRun && 'min-h-11 px-1 py-1 text-[15px] leading-[22px]',
+ )}
+ />
+ <div className={cn(firstRun && 'flex justify-end')}>
+ <Button
+ size="icon"
+ onClick={() => askChat()}
+ className={cn(
+ 'size-10 shrink-0 rounded-full',
+ firstRun && 'size-9',
+ )}
+ >
+ <ArrowUp size={16} strokeWidth={2.2} />
+ </Button>
+ </div>
+ </div>
+ <div
+ className={cn(
+ 'mt-[14px] flex flex-wrap items-center justify-center gap-2',
+ firstRun && 'mt-[22px] flex-col gap-[14px]',
+ )}
+ >
+ <span
+ className={cn(
+ 'text-[13px] leading-4 text-muted-foreground',
+ firstRun && 'font-medium',
+ )}
+ >
+ {firstRun ? t('Popular starting points') : t('Try:')}
+ </span>
+ <div className="flex flex-wrap items-center justify-center gap-[10px]">
+ {firstRun
+ ? TEMPLATE_STARTERS.map((starter) => (
+ <button
+ key={starter.label}
+ type="button"
+ onClick={() => askChat(t(starter.prompt))}
+ className="flex items-center gap-2 rounded-full border border-border py-[9px] pe-4 ps-[14px] text-sm font-medium leading-4 text-neutral-700 transition-colors hover:bg-accent"
+ >
+ <span
+ aria-hidden
+ className="size-[11px] shrink-0 rounded-sm"
+ style={{ backgroundColor: starter.dot }}
+ />
+ {t(starter.label)}
+ </button>
+ ))
+ : SUGGESTIONS.map((suggestion) => (
+ <button
+ key={suggestion}
+ type="button"
+ onClick={() => askChat(t(suggestion))}
+ className="rounded-full border border-border px-3 py-[5px] text-[13px] leading-4 transition-colors hover:bg-accent"
+ >
+ {t(suggestion)}
+ </button>
+ ))}
+ </div>
+ </div>
+ </>
+ )}
+ </section>
+ )}
{showsAgentList({
listLoading: isLoading,
hasList: data !== undefined,
firstRun,
}) && (
- <section className="flex w-full flex-col gap-5 px-12 pt-11 pb-12">
+ <section
+ className={cn(
+ 'flex w-full flex-col gap-5 px-12 pb-12 pt-11',
+ !chatEnabled && 'pt-8',
+ )}
+ >
<div className="flex flex-wrap items-center gap-3">
<div className="flex items-baseline gap-2">
<h2 className="text-xl font-semibold leading-6 tracking-[-0.01em]">
@@ -606,6 +499,7 @@ const AgentsPageContent = () => {
}) ? (
<AgentsEmptyState
narrowedByProject={search.trim().length === 0}
+ chatEnabled={chatEnabled}
/>
) : null
) : layout === 'list' ? (
@@ -645,8 +539,10 @@ const AgentsPageContent = () => {
const AgentsEmptyState = ({
narrowedByProject,
+ chatEnabled,
}: {
narrowedByProject: boolean;
+ chatEnabled: boolean;
}) => (
<Empty className="min-h-[240px]">
<EmptyHeader className="max-w-xl">
@@ -660,7 +556,9 @@ const AgentsEmptyState = ({
</EmptyTitle>
<EmptyDescription>
{narrowedByProject
- ? t('Describe one above, or pick another project.')
+ ? chatEnabled
+ ? t('Describe one above, or pick another project.')
+ : t('Add one with New agent, or pick another project.')
: t('Try another name, or clear the search.')}
</EmptyDescription>
</EmptyHeader>
diff --git a/packages/web/src/app/routes/agents/lib/agents-list-state.ts b/packages/web/src/app/routes/agents/lib/agents-list-state.ts
index d52324a4ca3..4c5b1d0c569 100644
--- a/packages/web/src/app/routes/agents/lib/agents-list-state.ts
+++ b/packages/web/src/app/routes/agents/lib/agents-list-state.ts
@@ -29,30 +29,6 @@ export function showsAgentList({
return listLoading || (hasList && !firstRun);
}
-export function shownDestination({
- isBuilding,
- buildingIn,
- picked,
-}: {
- isBuilding: boolean;
- buildingIn: string | null;
- picked: string;
-}): string {
- return isBuilding && buildingIn !== null ? buildingIn : picked;
-}
-
-export function acceptsDraftPrompt({
- prompt,
- isBuilding,
- readinessUnknown,
-}: {
- prompt: string;
- isBuilding: boolean;
- readinessUnknown: boolean;
-}): boolean {
- return prompt.trim().length > 0 && !isBuilding && !readinessUnknown;
-}
-
export function showsNoMatchNotice({
matchCount,
search,
diff --git a/packages/web/src/app/routes/chat-with-ai/ai-chat-box.tsx b/packages/web/src/app/routes/chat-with-ai/ai-chat-box.tsx
index 444368e62c0..fd453f4fe0f 100644
--- a/packages/web/src/app/routes/chat-with-ai/ai-chat-box.tsx
+++ b/packages/web/src/app/routes/chat-with-ai/ai-chat-box.tsx
@@ -9,7 +9,7 @@ import { useQueryClient } from '@tanstack/react-query';
import { t } from 'i18next';
import { AlertTriangle, RefreshCw, Square } from 'lucide-react';
import { AnimatePresence, motion } from 'motion/react';
-import { useCallback, useEffect, useMemo, useState } from 'react';
+import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
import {
ChatContainerContent,
@@ -53,6 +53,7 @@ import { getTextFromParts } from './lib/message-parsers';
export function AIChatBox({
incognito,
+ initialPrompt,
agentId,
builder,
onTurnEnd,
@@ -74,6 +75,7 @@ export function AIChatBox({
<ChatStoreProvider>
<ChatBoxContent
incognito={incognito}
+ initialPrompt={isLoadingProviders ? undefined : initialPrompt}
agentId={agentId}
builder={builder}
onTurnEnd={onTurnEnd}
@@ -90,6 +92,7 @@ export function AIChatBox({
function ChatBoxContent({
incognito,
+ initialPrompt,
agentId,
builder,
onTurnEnd,
@@ -181,6 +184,19 @@ function ChatBoxContent({
[sendMessage],
);
+ const sentInitialPrompt = useRef(false);
+
+ useEffect(() => {
+ const shouldSendInitialPrompt =
+ initialPrompt !== undefined &&
+ initialPrompt.trim().length > 0 &&
+ !initialConversationId &&
+ !sentInitialPrompt.current;
+ if (!shouldSendInitialPrompt) return;
+ sentInitialPrompt.current = true;
+ handleSend(initialPrompt).catch(() => undefined);
+ }, [initialPrompt, initialConversationId, handleSend]);
+
const handleRetry = useCallback(() => {
const lastUser = messages.findLast((m) => m.role === 'user');
if (lastUser) void sendMessage(getTextFromParts(lastUser.parts));
@@ -509,6 +525,7 @@ function computeClaimedBuildIds(
type AIChatBoxProps = {
incognito: boolean;
+ initialPrompt?: string;
agentId?: string;
builder?: boolean;
onTurnEnd?: () => void;
diff --git a/packages/web/src/app/routes/chat-with-ai/index.tsx b/packages/web/src/app/routes/chat-with-ai/index.tsx
index 94ce8bd358d..89fac8dd6f2 100644
--- a/packages/web/src/app/routes/chat-with-ai/index.tsx
+++ b/packages/web/src/app/routes/chat-with-ai/index.tsx
@@ -1,10 +1,10 @@
-import { SeekPage } from '@activepieces/core-utils';
+import { isNil, isObject, SeekPage } from '@activepieces/core-utils';
import { AgentConversation } from '@activepieces/shared';
import { useQueryClient } from '@tanstack/react-query';
import { t } from 'i18next';
import { Ellipsis, Pencil, Trash2 } from 'lucide-react';
import { useState, useEffect, useCallback, useRef, useMemo } from 'react';
-import { useNavigate, useParams } from 'react-router-dom';
+import { useLocation, useNavigate, useParams } from 'react-router-dom';
import { toast } from 'sonner';
import { PlusIcon } from '@/components/icons/plus';
@@ -40,6 +40,12 @@ export function ChatWithAIPage() {
const { conversationId: urlConversationId } = useParams<{
conversationId: string;
}>();
+ const location = useLocation();
+ const handedOverPrompt =
+ isObject(location.state) && typeof location.state.prompt === 'string'
+ ? location.state.prompt
+ : undefined;
+ const [initialPrompt, setInitialPrompt] = useState(handedOverPrompt);
const [resetKey, setResetKey] = useState(0);
const [pendingConversationId, setPendingConversationId] = useState<
string | null
@@ -62,6 +68,13 @@ export function ChatWithAIPage() {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
+ useEffect(() => {
+ if (isNil(handedOverPrompt)) {
+ return;
+ }
+ navigate(location.pathname, { replace: true, state: null });
+ }, [handedOverPrompt, location.pathname, navigate]);
+
const toggleSidebar = useCallback(() => {
setSidebarPinned((prev) => {
const next = !prev;
@@ -73,6 +86,7 @@ export function ChatWithAIPage() {
const selectedConversationId = urlConversationId ?? null;
const handleNewChat = useCallback(() => {
+ setInitialPrompt(undefined);
setResetKey((k) => k + 1);
setPendingConversationId(null);
setConversationTitle(null);
@@ -94,6 +108,7 @@ export function ChatWithAIPage() {
const handleConversationCreated = useCallback(
(conversationId: string) => {
+ setInitialPrompt(undefined);
setPendingConversationId(conversationId);
window.history.replaceState(null, '', `/chat/${conversationId}`);
void queryClient.invalidateQueries({
@@ -329,6 +344,7 @@ export function ChatWithAIPage() {
<AIChatBox
key={`${selectedConversationId ?? 'new'}-${resetKey}`}
incognito={false}
+ initialPrompt={initialPrompt}
conversationId={selectedConversationId}
onTitleUpdate={handleTitleUpdate}
onConversationCreated={handleConversationCreated}
diff --git a/packages/web/src/features/agents/lib/create-agent-utils.ts b/packages/web/src/features/agents/lib/create-agent-utils.ts
deleted file mode 100644
index 2b60c9524e0..00000000000
--- a/packages/web/src/features/agents/lib/create-agent-utils.ts
+++ /dev/null
@@ -1,30 +0,0 @@
-import {
- AgentDraftFields,
- CreateAgentRequest,
- DEFAULT_AGENT_MAX_STEPS,
- DraftAgentResponse,
-} from '@activepieces/shared';
-
-const buildCreateRequest = ({
- draft,
- projectId,
-}: {
- draft: AgentDraftFields & Partial<DraftAgentResponse>;
- projectId: string;
-}): CreateAgentRequest => ({
- projectId,
- displayName: draft.displayName,
- description: draft.description.length > 0 ? draft.description : null,
- icon: draft.icon,
- color: draft.color,
- draft: {
- instructions: draft.instructions,
- provider: draft.provider ?? null,
- modelName: draft.modelName ?? null,
- maxSteps: DEFAULT_AGENT_MAX_STEPS,
- tools: draft.tools ?? [],
- structuredOutput: [],
- },
-});
-
-export const createAgentUtils = { buildCreateRequest };
diff --git a/packages/web/src/features/agents/new-blank-agent-button.tsx b/packages/web/src/features/agents/new-blank-agent-button.tsx
index 8c103e443c5..85ae9338de3 100644
--- a/packages/web/src/features/agents/new-blank-agent-button.tsx
+++ b/packages/web/src/features/agents/new-blank-agent-button.tsx
@@ -75,7 +75,7 @@ type NewBlankAgentButtonProps = {
projects: Project[];
pending: boolean;
onCreate: (projectId: string) => void;
- variant?: 'outline';
+ variant?: 'outline' | 'default';
size?: 'sm';
className?: string;
icon: ReactNode;
diff --git a/packages/web/src/features/platform-admin/hooks/ai-provider-hooks.ts b/packages/web/src/features/platform-admin/hooks/ai-provider-hooks.ts
index e76b691116f..53beba242d7 100644
--- a/packages/web/src/features/platform-admin/hooks/ai-provider-hooks.ts
+++ b/packages/web/src/features/platform-admin/hooks/ai-provider-hooks.ts
@@ -29,8 +29,8 @@ export const aiProviderQueries = {
queryKey: aiProviderKeys.configs,
queryFn: () => aiProviderApi.listConfigs(),
}),
- useProjectAiProviders: (forProjectId?: string) => {
- const projectId = forProjectId ?? authenticationSession.getProjectId();
+ useProjectAiProviders: () => {
+ const projectId = authenticationSession.getProjectId();
return useQuery({
queryKey: aiProviderKeys.forProject(projectId),
queryFn: () =>
@@ -38,9 +38,9 @@ export const aiProviderQueries = {
enabled: !isNil(projectId),
});
},
- useChatProvider: (forProjectId?: string) => {
+ useChatProvider: () => {
const { data: providers, ...rest } =
- aiProviderQueries.useProjectAiProviders(forProjectId);
+ aiProviderQueries.useProjectAiProviders();
return { ...rest, data: providers?.find((p) => p.enabledForChat) };
},
};
diff --git a/packages/web/test/app/routes/agents/lib/agents-list-state.test.ts b/packages/web/test/app/routes/agents/lib/agents-list-state.test.ts
index 4cc1e967f94..c8d276367bc 100644
--- a/packages/web/test/app/routes/agents/lib/agents-list-state.test.ts
+++ b/packages/web/test/app/routes/agents/lib/agents-list-state.test.ts
@@ -2,11 +2,9 @@ import { QueryClient } from '@tanstack/react-query';
import { describe, expect, it } from 'vitest';
import {
- acceptsDraftPrompt,
showsAgentList,
showsFirstRun,
showsNoMatchNotice,
- shownDestination,
} from '@/app/routes/agents/lib/agents-list-state';
const loaded = { listLoaded: true, hasAnyAgents: false, search: '' };
@@ -172,61 +170,3 @@ describe('showsFirstRun with a project filter', () => {
).toBe(true);
});
});
-
-describe('acceptsDraftPrompt', () => {
- const ready = {
- prompt: 'summarise my inbox',
- isBuilding: false,
- readinessUnknown: false,
- };
-
- it('accepts a prompt once the destination is known to be ready', () => {
- expect(acceptsDraftPrompt(ready)).toBe(true);
- });
-
- it('refuses while the destination project has not answered about its provider', () => {
- expect(acceptsDraftPrompt({ ...ready, readinessUnknown: true })).toBe(
- false,
- );
- });
-
- it('refuses a second submit while one is already building', () => {
- expect(acceptsDraftPrompt({ ...ready, isBuilding: true })).toBe(false);
- });
-
- it('refuses whitespace', () => {
- expect(acceptsDraftPrompt({ ...ready, prompt: ' ' })).toBe(false);
- });
-});
-
-describe('shownDestination', () => {
- it('holds the project a build started in, even after the pick changes', () => {
- expect(
- shownDestination({
- isBuilding: true,
- buildingIn: 'project_a',
- picked: 'project_b',
- }),
- ).toBe('project_a');
- });
-
- it('follows the pick again once the build is over', () => {
- expect(
- shownDestination({
- isBuilding: false,
- buildingIn: 'project_a',
- picked: 'project_b',
- }),
- ).toBe('project_b');
- });
-
- it('falls back to the pick when nothing was captured', () => {
- expect(
- shownDestination({
- isBuilding: true,
- buildingIn: null,
- picked: 'project_b',
- }),
- ).toBe('project_b');
- });
-});