@alpaca-editor/core 1.0.4187 → 1.0.4190
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agents-view/AgentCard.js +1 -1
- package/dist/agents-view/AgentCard.js.map +1 -1
- package/dist/agents-view/AgentsView.js +7 -5
- package/dist/agents-view/AgentsView.js.map +1 -1
- package/dist/components/ui/PlaceholderInput.d.ts +41 -0
- package/dist/components/ui/PlaceholderInput.js +160 -0
- package/dist/components/ui/PlaceholderInput.js.map +1 -0
- package/dist/components/ui/PlaceholderInputTypes.d.ts +41 -0
- package/dist/components/ui/PlaceholderInputTypes.js +48 -0
- package/dist/components/ui/PlaceholderInputTypes.js.map +1 -0
- package/dist/components/ui/PlaceholderItemSelector.d.ts +7 -0
- package/dist/components/ui/PlaceholderItemSelector.js +154 -0
- package/dist/components/ui/PlaceholderItemSelector.js.map +1 -0
- package/dist/config/config.js +7 -14
- package/dist/config/config.js.map +1 -1
- package/dist/editor/ItemInfo.js +3 -3
- package/dist/editor/ItemInfo.js.map +1 -1
- package/dist/editor/QuickItemSwitcher.js +1 -1
- package/dist/editor/QuickItemSwitcher.js.map +1 -1
- package/dist/editor/ai/AgentTerminal.d.ts +7 -1
- package/dist/editor/ai/AgentTerminal.js +256 -382
- package/dist/editor/ai/AgentTerminal.js.map +1 -1
- package/dist/editor/ai/Agents.js +198 -84
- package/dist/editor/ai/Agents.js.map +1 -1
- package/dist/editor/ai/AiResponseMessage.d.ts +3 -1
- package/dist/editor/ai/AiResponseMessage.js +63 -12
- package/dist/editor/ai/AiResponseMessage.js.map +1 -1
- package/dist/editor/ai/ToolCallDisplay.d.ts +2 -1
- package/dist/editor/ai/ToolCallDisplay.js +13 -5
- package/dist/editor/ai/ToolCallDisplay.js.map +1 -1
- package/dist/editor/client/EditorShell.js +6 -5
- package/dist/editor/client/EditorShell.js.map +1 -1
- package/dist/editor/client/hooks/useSocketMessageHandler.js +6 -4
- package/dist/editor/client/hooks/useSocketMessageHandler.js.map +1 -1
- package/dist/editor/commands/componentCommands.js +2 -0
- package/dist/editor/commands/componentCommands.js.map +1 -1
- package/dist/editor/control-center/About.js +1 -1
- package/dist/editor/control-center/About.js.map +1 -1
- package/dist/editor/control-center/AllAgentsPanel.js +1 -1
- package/dist/editor/field-types/MultiLineText.js +1 -1
- package/dist/editor/field-types/MultiLineText.js.map +1 -1
- package/dist/editor/services/aiService.d.ts +1 -0
- package/dist/editor/services/aiService.js.map +1 -1
- package/dist/editor/sidebar/Validation.js +1 -1
- package/dist/editor/sidebar/Validation.js.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/page-wizard/PageWizard.js +3 -3
- package/dist/page-wizard/PageWizard.js.map +1 -1
- package/dist/page-wizard/WizardSteps.js +1 -1
- package/dist/page-wizard/WizardSteps.js.map +1 -1
- package/dist/revision.d.ts +2 -2
- package/dist/revision.js +2 -2
- package/dist/splash-screen/ModernSplashScreen.d.ts +8 -0
- package/dist/splash-screen/ModernSplashScreen.js +36 -0
- package/dist/splash-screen/ModernSplashScreen.js.map +1 -0
- package/dist/splash-screen/OpenPage.js +10 -6
- package/dist/splash-screen/OpenPage.js.map +1 -1
- package/dist/splash-screen/ParheliaAssistantChat.d.ts +8 -0
- package/dist/splash-screen/ParheliaAssistantChat.js +155 -0
- package/dist/splash-screen/ParheliaAssistantChat.js.map +1 -0
- package/dist/splash-screen/RecentAgents.d.ts +7 -0
- package/dist/splash-screen/RecentAgents.js +76 -0
- package/dist/splash-screen/RecentAgents.js.map +1 -0
- package/dist/splash-screen/RecentPages.js +2 -2
- package/dist/splash-screen/RecentPages.js.map +1 -1
- package/dist/splash-screen/SplashScreen.js +1 -1
- package/dist/splash-screen/SplashScreen.js.map +1 -1
- package/dist/styles.css +241 -12
- package/package.json +1 -1
- package/src/agents-view/AgentCard.tsx +1 -6
- package/src/agents-view/AgentsView.tsx +18 -30
- package/src/components/ui/PlaceholderInput.tsx +290 -0
- package/src/components/ui/PlaceholderInputTypes.tsx +97 -0
- package/src/components/ui/PlaceholderItemSelector.tsx +253 -0
- package/src/config/config.tsx +8 -17
- package/src/editor/ItemInfo.tsx +3 -2
- package/src/editor/QuickItemSwitcher.tsx +1 -1
- package/src/editor/ai/AgentTerminal.tsx +544 -649
- package/src/editor/ai/Agents.tsx +464 -250
- package/src/editor/ai/AiResponseMessage.tsx +154 -29
- package/src/editor/ai/ToolCallDisplay.tsx +18 -4
- package/src/editor/client/EditorShell.tsx +9 -6
- package/src/editor/client/hooks/useSocketMessageHandler.ts +6 -7
- package/src/editor/commands/componentCommands.tsx +1 -0
- package/src/editor/control-center/About.tsx +2 -2
- package/src/editor/control-center/AllAgentsPanel.tsx +1 -1
- package/src/editor/field-types/MultiLineText.tsx +1 -1
- package/src/editor/services/aiService.ts +2 -0
- package/src/editor/sidebar/Validation.tsx +1 -1
- package/src/index.ts +5 -0
- package/src/page-wizard/PageWizard.tsx +3 -3
- package/src/page-wizard/WizardSteps.tsx +1 -1
- package/src/revision.ts +2 -2
- package/src/splash-screen/ModernSplashScreen.tsx +158 -0
- package/src/splash-screen/OpenPage.tsx +12 -4
- package/src/splash-screen/ParheliaAssistantChat.tsx +273 -0
- package/src/splash-screen/RecentAgents.tsx +151 -0
- package/src/splash-screen/RecentPages.tsx +58 -61
- package/src/splash-screen/SplashScreen.tsx +1 -1
- package/styles.css +20 -0
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import React, { useState } from "react";
|
|
4
|
+
import { useEditContext } from "../editor/client/editContext";
|
|
5
|
+
import { AnimatedSunIcon } from "../editor/ui/Icons";
|
|
6
|
+
import { ActionButton } from "../components/ActionButton";
|
|
7
|
+
import { RecentPages } from "./RecentPages";
|
|
8
|
+
import { ParheliaAssistantChat } from "./ParheliaAssistantChat";
|
|
9
|
+
import { RecentAgents } from "./RecentAgents";
|
|
10
|
+
import { Agent } from "../editor/services/agentService";
|
|
11
|
+
import { FileText, FolderOpen, ExternalLink, Bot, Layers } from "lucide-react";
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Modern splash screen with clean design featuring:
|
|
15
|
+
* - Parhelia logo and branding
|
|
16
|
+
* - Functional AI assistant chat interface
|
|
17
|
+
* - Quick action buttons
|
|
18
|
+
* - Recent pages overview
|
|
19
|
+
*/
|
|
20
|
+
export function ModernSplashScreen() {
|
|
21
|
+
const editContext = useEditContext();
|
|
22
|
+
const [selectedAgent, setSelectedAgent] = useState<Agent | null>(null);
|
|
23
|
+
|
|
24
|
+
const handleSelectAgent = (agent: Agent) => {
|
|
25
|
+
setSelectedAgent(agent);
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
return (
|
|
29
|
+
<div className="relative flex h-screen w-full flex-col overflow-y-auto bg-gradient-to-br from-purple-50/30 via-pink-50/20 to-blue-50/30">
|
|
30
|
+
{/* Background decoration */}
|
|
31
|
+
<div className="bg-wizard absolute inset-0 opacity-20" />
|
|
32
|
+
|
|
33
|
+
{/* Main Content */}
|
|
34
|
+
<div className="relative z-10 flex flex-1 flex-col items-center px-4 py-8 md:py-12">
|
|
35
|
+
{/* Hero Section */}
|
|
36
|
+
<div className="mb-8 flex flex-col items-center gap-4 md:mb-12">
|
|
37
|
+
<div className="flex items-center gap-3">
|
|
38
|
+
<AnimatedSunIcon />
|
|
39
|
+
<h1 className="text-3xl font-extralight tracking-wide text-gray-900 md:text-4xl">
|
|
40
|
+
parhelia
|
|
41
|
+
</h1>
|
|
42
|
+
</div>
|
|
43
|
+
<p className="text-center text-sm text-gray-600 md:text-base">
|
|
44
|
+
Where brilliant ideas become brilliant content
|
|
45
|
+
</p>
|
|
46
|
+
</div>
|
|
47
|
+
|
|
48
|
+
{/* Chat Interface Section */}
|
|
49
|
+
<div className="mb-8 w-full max-w-3xl md:mb-12">
|
|
50
|
+
<ParheliaAssistantChat className="w-full" externalAgent={selectedAgent} />
|
|
51
|
+
</div>
|
|
52
|
+
|
|
53
|
+
{/* Recent Agents Section */}
|
|
54
|
+
<div className="mb-8 w-full max-w-3xl md:mb-12">
|
|
55
|
+
<RecentAgents onSelectAgent={handleSelectAgent} />
|
|
56
|
+
</div>
|
|
57
|
+
|
|
58
|
+
{/* Quick Actions Section */}
|
|
59
|
+
<div className="mb-8 w-full max-w-5xl md:mb-12">
|
|
60
|
+
<h2 className="mb-4 text-center text-sm font-medium text-gray-700">
|
|
61
|
+
Quick Actions
|
|
62
|
+
</h2>
|
|
63
|
+
<div className="grid grid-cols-2 gap-3 md:grid-cols-4 md:gap-4">
|
|
64
|
+
<ActionCard
|
|
65
|
+
icon={<FileText strokeWidth={1} />}
|
|
66
|
+
title="Create Page"
|
|
67
|
+
description="Start building"
|
|
68
|
+
onClick={() => editContext?.switchView("new-page")}
|
|
69
|
+
dataTestId="create-new-page-button"
|
|
70
|
+
/>
|
|
71
|
+
<ActionCard
|
|
72
|
+
icon={<FolderOpen strokeWidth={1} />}
|
|
73
|
+
title="Open Page"
|
|
74
|
+
description="Browse content"
|
|
75
|
+
onClick={() => editContext?.switchView("open-page")}
|
|
76
|
+
/>
|
|
77
|
+
<ActionCard
|
|
78
|
+
icon={<Bot strokeWidth={1} />}
|
|
79
|
+
title="My Agents"
|
|
80
|
+
description="AI assistants"
|
|
81
|
+
onClick={() => {
|
|
82
|
+
editContext?.switchView("agents-overview");
|
|
83
|
+
editContext?.setShowAgentsPanel?.(true);
|
|
84
|
+
}}
|
|
85
|
+
/>
|
|
86
|
+
<ActionCard
|
|
87
|
+
icon={<ExternalLink strokeWidth={1} />}
|
|
88
|
+
title="Launchpad"
|
|
89
|
+
description="Sitecore tools"
|
|
90
|
+
onClick={() => {
|
|
91
|
+
window.open(
|
|
92
|
+
"/sitecore/shell/sitecore/client/Applications/Launchpad",
|
|
93
|
+
"_blank",
|
|
94
|
+
);
|
|
95
|
+
}}
|
|
96
|
+
/>
|
|
97
|
+
</div>
|
|
98
|
+
</div>
|
|
99
|
+
|
|
100
|
+
{/* Recent Pages Section */}
|
|
101
|
+
<div className="w-full max-w-5xl">
|
|
102
|
+
<RecentPages />
|
|
103
|
+
</div>
|
|
104
|
+
|
|
105
|
+
{/* Footer Actions */}
|
|
106
|
+
<div className="mt-8 flex flex-col gap-3 md:mt-12">
|
|
107
|
+
<ActionButton
|
|
108
|
+
variant="ghost"
|
|
109
|
+
onClick={() => {
|
|
110
|
+
editContext?.switchView("page-editor");
|
|
111
|
+
}}
|
|
112
|
+
className="text-gray-600 hover:text-gray-900"
|
|
113
|
+
>
|
|
114
|
+
<Layers strokeWidth={1} className="mr-2 h-4 w-4" />
|
|
115
|
+
Return to editor
|
|
116
|
+
</ActionButton>
|
|
117
|
+
</div>
|
|
118
|
+
</div>
|
|
119
|
+
</div>
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Action card component for quick actions grid
|
|
125
|
+
*/
|
|
126
|
+
interface ActionCardProps {
|
|
127
|
+
icon: React.ReactNode;
|
|
128
|
+
title: string;
|
|
129
|
+
description: string;
|
|
130
|
+
onClick: () => void;
|
|
131
|
+
dataTestId?: string;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
const ActionCard: React.FC<ActionCardProps> = ({
|
|
135
|
+
icon,
|
|
136
|
+
title,
|
|
137
|
+
description,
|
|
138
|
+
onClick,
|
|
139
|
+
dataTestId,
|
|
140
|
+
}) => {
|
|
141
|
+
return (
|
|
142
|
+
<button
|
|
143
|
+
onClick={onClick}
|
|
144
|
+
data-testid={dataTestId}
|
|
145
|
+
className="group flex flex-col items-center gap-3 rounded-lg bg-white p-6 shadow-sm transition-all duration-200 hover:scale-[1.02] hover:shadow-md active:scale-[0.98] md:p-8"
|
|
146
|
+
>
|
|
147
|
+
<div className="flex h-12 w-12 items-center justify-center rounded-full bg-gradient-to-br from-purple-100 to-pink-100 text-purple-600 transition-colors group-hover:from-purple-500 group-hover:to-pink-500 group-hover:text-white md:h-14 md:w-14">
|
|
148
|
+
{icon}
|
|
149
|
+
</div>
|
|
150
|
+
<div className="flex flex-col items-center gap-1">
|
|
151
|
+
<h3 className="text-sm font-semibold text-gray-900 md:text-base">
|
|
152
|
+
{title}
|
|
153
|
+
</h3>
|
|
154
|
+
<p className="text-xs text-gray-500">{description}</p>
|
|
155
|
+
</div>
|
|
156
|
+
</button>
|
|
157
|
+
);
|
|
158
|
+
};
|
|
@@ -11,6 +11,7 @@ import { Logo, MagicEditIcon } from "../editor/ui/Icons";
|
|
|
11
11
|
import { ActionButton } from "../components/ActionButton";
|
|
12
12
|
import { RecentPages } from "./RecentPages";
|
|
13
13
|
import { X, Network } from "lucide-react";
|
|
14
|
+
import ItemSearch, { ResultItem } from "../editor/ui/ItemSearch";
|
|
14
15
|
|
|
15
16
|
export function OpenPage() {
|
|
16
17
|
const savedHistory =
|
|
@@ -25,6 +26,7 @@ export function OpenPage() {
|
|
|
25
26
|
: [];
|
|
26
27
|
|
|
27
28
|
const [isLoading, setIsLoading] = useState(false);
|
|
29
|
+
const [hoveredItem, setHoveredItem] = useState<ResultItem>();
|
|
28
30
|
|
|
29
31
|
useEffect(() => {
|
|
30
32
|
if (recentPages.length > 0 && recentPages[0])
|
|
@@ -95,10 +97,16 @@ export function OpenPage() {
|
|
|
95
97
|
noPadding
|
|
96
98
|
className="h-full"
|
|
97
99
|
>
|
|
98
|
-
<div className="h-full px-4">
|
|
99
|
-
<
|
|
100
|
-
|
|
101
|
-
|
|
100
|
+
<div className="flex h-full flex-col gap-2 px-4 py-2">
|
|
101
|
+
<ItemSearch
|
|
102
|
+
setHoveredItem={setHoveredItem}
|
|
103
|
+
itemSelected={(item) => {
|
|
104
|
+
loadItem(item);
|
|
105
|
+
}}
|
|
106
|
+
/>
|
|
107
|
+
<div className="relative flex-1">
|
|
108
|
+
<ScrollingContentTree
|
|
109
|
+
selectedItemId={hoveredItem?.id ?? selectedPage?.id}
|
|
102
110
|
hideRootNodes={true}
|
|
103
111
|
onSelectionChange={(selection) => {
|
|
104
112
|
const selectedItem = selection[0];
|
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import React, { useState, useEffect, useCallback, startTransition, ViewTransition } from "react";
|
|
4
|
+
import { Loader2, RotateCcw, MessageSquare, X } from "lucide-react";
|
|
5
|
+
import { useEditContext } from "../editor/client/editContext";
|
|
6
|
+
import { AiProfile, loadAiProfiles } from "../editor/services/aiService";
|
|
7
|
+
import { Agent, getActiveAgents, closeAgent } from "../editor/services/agentService";
|
|
8
|
+
import { AgentTerminal } from "../editor/ai/AgentTerminal";
|
|
9
|
+
import { cn } from "../lib/utils";
|
|
10
|
+
import { Button } from "../components/ui/button";
|
|
11
|
+
|
|
12
|
+
interface ParheliaAssistantChatProps {
|
|
13
|
+
className?: string;
|
|
14
|
+
externalAgent?: Agent | null;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const ParheliaAssistantChat: React.FC<ParheliaAssistantChatProps> = ({
|
|
18
|
+
className,
|
|
19
|
+
externalAgent,
|
|
20
|
+
}) => {
|
|
21
|
+
const editContext = useEditContext();
|
|
22
|
+
const [profile, setProfile] = useState<AiProfile | null>(null);
|
|
23
|
+
const [profiles, setProfiles] = useState<AiProfile[]>([]);
|
|
24
|
+
const [isLoading, setIsLoading] = useState(true);
|
|
25
|
+
const [agent, setAgent] = useState<Agent | null>(null);
|
|
26
|
+
const [agentKey, setAgentKey] = useState(0); // Force re-render of AgentTerminal
|
|
27
|
+
const [isTerminalVisible, setIsTerminalVisible] = useState(false);
|
|
28
|
+
|
|
29
|
+
// Create a new agent
|
|
30
|
+
const createNewAgent = useCallback((selectedProfile: AiProfile) => {
|
|
31
|
+
const agentDisplayName = selectedProfile.agentName || "Parhelia";
|
|
32
|
+
const agentId = crypto.randomUUID();
|
|
33
|
+
|
|
34
|
+
const newAgent: Agent = {
|
|
35
|
+
status: "new",
|
|
36
|
+
id: agentId,
|
|
37
|
+
name: agentDisplayName,
|
|
38
|
+
updatedDate: new Date().toISOString(),
|
|
39
|
+
userId: "",
|
|
40
|
+
profileId: selectedProfile.id,
|
|
41
|
+
profileName: selectedProfile.name,
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
setAgent(newAgent);
|
|
45
|
+
return newAgent;
|
|
46
|
+
}, []);
|
|
47
|
+
|
|
48
|
+
// Load AI profiles on mount
|
|
49
|
+
useEffect(() => {
|
|
50
|
+
const loadProfile = async () => {
|
|
51
|
+
try {
|
|
52
|
+
setIsLoading(true);
|
|
53
|
+
const profileList = await loadAiProfiles();
|
|
54
|
+
|
|
55
|
+
// Try to find Parhelia profile with multiple strategies
|
|
56
|
+
let assistantProfile: AiProfile | undefined;
|
|
57
|
+
|
|
58
|
+
// Strategy 1: Look for exact ID match
|
|
59
|
+
assistantProfile = profileList.find(
|
|
60
|
+
(p) => p.id === "7d45ab97-f253-4915-8b32-f9e8c762c5e9",
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
// Strategy 2: Look for exact name match (case-insensitive)
|
|
64
|
+
if (!assistantProfile) {
|
|
65
|
+
assistantProfile = profileList.find(
|
|
66
|
+
(p) => p.name.toLowerCase() === "parhelia",
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// Strategy 3: Look for profile containing "parhelia" in name or displayTitle
|
|
71
|
+
if (!assistantProfile) {
|
|
72
|
+
assistantProfile = profileList.find(
|
|
73
|
+
(p) =>
|
|
74
|
+
p.name.toLowerCase().includes("parhelia") ||
|
|
75
|
+
p.displayTitle?.toLowerCase().includes("parhelia"),
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// Strategy 4: Fallback to first available profile
|
|
80
|
+
const selectedProfile = assistantProfile || profileList[0];
|
|
81
|
+
|
|
82
|
+
if (selectedProfile) {
|
|
83
|
+
setProfile(selectedProfile);
|
|
84
|
+
setProfiles(profileList);
|
|
85
|
+
|
|
86
|
+
// Try to find latest idle Parhelia agent
|
|
87
|
+
try {
|
|
88
|
+
const response = await getActiveAgents({ limit: 50 });
|
|
89
|
+
|
|
90
|
+
// Filter for Parhelia agents (by profileId) that are idle/completed
|
|
91
|
+
// Exclude agents that are "running" (1) or "waitingForApproval" (2) to avoid showing stuck dancing dots
|
|
92
|
+
const parheliaAgents = response.agents.filter(
|
|
93
|
+
(a) =>
|
|
94
|
+
a.profileId === selectedProfile.id &&
|
|
95
|
+
a.status !== "running" &&
|
|
96
|
+
a.status !== 1 &&
|
|
97
|
+
a.status !== "waitingForApproval" &&
|
|
98
|
+
a.status !== 2,
|
|
99
|
+
);
|
|
100
|
+
|
|
101
|
+
if (parheliaAgents.length > 0 && parheliaAgents[0]) {
|
|
102
|
+
// Use the most recent idle agent (agents are typically ordered by updatedDate)
|
|
103
|
+
const latestAgent = parheliaAgents[0];
|
|
104
|
+
setAgent(latestAgent);
|
|
105
|
+
// Show terminal immediately for existing agents
|
|
106
|
+
setIsTerminalVisible(true);
|
|
107
|
+
} else {
|
|
108
|
+
// No existing idle agent, create new one
|
|
109
|
+
createNewAgent(selectedProfile);
|
|
110
|
+
// Terminal stays hidden for new agents
|
|
111
|
+
}
|
|
112
|
+
} catch (err) {
|
|
113
|
+
// Failed to fetch active agents, create new one
|
|
114
|
+
createNewAgent(selectedProfile);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
} catch (err) {
|
|
118
|
+
console.error("Failed to load AI profile:", err);
|
|
119
|
+
} finally {
|
|
120
|
+
setIsLoading(false);
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
loadProfile();
|
|
125
|
+
}, [createNewAgent]);
|
|
126
|
+
|
|
127
|
+
// Handle external agent selection
|
|
128
|
+
useEffect(() => {
|
|
129
|
+
if (externalAgent) {
|
|
130
|
+
setAgent(externalAgent);
|
|
131
|
+
setAgentKey((prev) => prev + 1);
|
|
132
|
+
setIsTerminalVisible(true);
|
|
133
|
+
}
|
|
134
|
+
}, [externalAgent]);
|
|
135
|
+
|
|
136
|
+
// Handle revealing the terminal when user clicks into chat
|
|
137
|
+
const handleRevealTerminal = useCallback(() => {
|
|
138
|
+
startTransition(() => {
|
|
139
|
+
setIsTerminalVisible(true);
|
|
140
|
+
});
|
|
141
|
+
}, []);
|
|
142
|
+
|
|
143
|
+
// Handle start over
|
|
144
|
+
const handleStartOver = useCallback(async () => {
|
|
145
|
+
if (!profile || !agent) return;
|
|
146
|
+
|
|
147
|
+
try {
|
|
148
|
+
// Close the current agent first
|
|
149
|
+
await closeAgent(agent.id);
|
|
150
|
+
} catch (error) {
|
|
151
|
+
console.error("Failed to close agent:", error);
|
|
152
|
+
// Continue anyway to create new agent
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// Create new agent and force re-render
|
|
156
|
+
createNewAgent(profile);
|
|
157
|
+
setAgentKey((prev) => prev + 1);
|
|
158
|
+
// Keep terminal visible when starting over
|
|
159
|
+
}, [profile, agent, createNewAgent]);
|
|
160
|
+
|
|
161
|
+
// Handle close
|
|
162
|
+
const handleClose = useCallback(async () => {
|
|
163
|
+
if (!agent) return;
|
|
164
|
+
|
|
165
|
+
try {
|
|
166
|
+
await closeAgent(agent.id);
|
|
167
|
+
} catch (error) {
|
|
168
|
+
console.error("Failed to close agent:", error);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// Hide the terminal
|
|
172
|
+
setIsTerminalVisible(false);
|
|
173
|
+
}, [agent]);
|
|
174
|
+
|
|
175
|
+
if (isLoading) {
|
|
176
|
+
return (
|
|
177
|
+
<div
|
|
178
|
+
className={cn(
|
|
179
|
+
"flex items-center justify-center rounded-lg bg-white p-8 shadow-md",
|
|
180
|
+
className,
|
|
181
|
+
)}
|
|
182
|
+
>
|
|
183
|
+
<Loader2 className="h-6 w-6 animate-spin text-gray-400" />
|
|
184
|
+
</div>
|
|
185
|
+
);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
if (!agent || !profile) {
|
|
189
|
+
return (
|
|
190
|
+
<div
|
|
191
|
+
className={cn(
|
|
192
|
+
"flex items-center justify-center rounded-lg bg-white p-8 shadow-md",
|
|
193
|
+
className,
|
|
194
|
+
)}
|
|
195
|
+
>
|
|
196
|
+
<p className="text-sm text-gray-500">
|
|
197
|
+
Assistant unavailable. Please try again later.
|
|
198
|
+
</p>
|
|
199
|
+
</div>
|
|
200
|
+
);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
return (
|
|
204
|
+
<div
|
|
205
|
+
onClick={handleRevealTerminal}
|
|
206
|
+
className={cn(
|
|
207
|
+
"flex flex-col overflow-hidden rounded-lg bg-white shadow-md",
|
|
208
|
+
!isTerminalVisible && "cursor-pointer",
|
|
209
|
+
className,
|
|
210
|
+
)}
|
|
211
|
+
>
|
|
212
|
+
{/* Header with Start Over and Close buttons */}
|
|
213
|
+
<div className="flex items-center justify-between border-b border-gray-200 px-4 py-2">
|
|
214
|
+
<div className="text-sm font-medium text-gray-700">
|
|
215
|
+
Chat with {agent.name || profile.agentName || "Parhelia"}
|
|
216
|
+
</div>
|
|
217
|
+
{isTerminalVisible && (
|
|
218
|
+
<div className="flex items-center gap-1">
|
|
219
|
+
<Button
|
|
220
|
+
variant="ghost"
|
|
221
|
+
size="sm"
|
|
222
|
+
onClick={handleStartOver}
|
|
223
|
+
className="h-7 gap-1.5 text-xs"
|
|
224
|
+
>
|
|
225
|
+
<RotateCcw className="h-3.5 w-3.5" strokeWidth={1} />
|
|
226
|
+
Start Over
|
|
227
|
+
</Button>
|
|
228
|
+
<Button
|
|
229
|
+
variant="ghost"
|
|
230
|
+
size="sm"
|
|
231
|
+
onClick={handleClose}
|
|
232
|
+
className="h-7 w-7 p-0"
|
|
233
|
+
aria-label="Close"
|
|
234
|
+
>
|
|
235
|
+
<X className="h-4 w-4" strokeWidth={1.5} />
|
|
236
|
+
</Button>
|
|
237
|
+
</div>
|
|
238
|
+
)}
|
|
239
|
+
</div>
|
|
240
|
+
|
|
241
|
+
{/* Agent Terminal or Placeholder */}
|
|
242
|
+
<div className="flex-1 overflow-hidden">
|
|
243
|
+
{isTerminalVisible && (
|
|
244
|
+
|
|
245
|
+
<ViewTransition enter="slide-fade-in">
|
|
246
|
+
<div className="h-[600px]">
|
|
247
|
+
<AgentTerminal
|
|
248
|
+
|
|
249
|
+
key={agentKey}
|
|
250
|
+
agentStub={agent}
|
|
251
|
+
initialMetadata={{
|
|
252
|
+
profile: profile.name,
|
|
253
|
+
additionalData: {
|
|
254
|
+
profileId: profile.id,
|
|
255
|
+
profileName: profile.name,
|
|
256
|
+
},
|
|
257
|
+
}}
|
|
258
|
+
profiles={profiles}
|
|
259
|
+
isActive={true}
|
|
260
|
+
compact={true}
|
|
261
|
+
hideContext={true}
|
|
262
|
+
hideBottomControls={true}
|
|
263
|
+
hideGreeting={false}
|
|
264
|
+
className="h-full"
|
|
265
|
+
initialPrompt={agent.status === "new" ? "" : undefined}
|
|
266
|
+
/>
|
|
267
|
+
</div>
|
|
268
|
+
</ViewTransition>
|
|
269
|
+
) }
|
|
270
|
+
</div>
|
|
271
|
+
</div>
|
|
272
|
+
);
|
|
273
|
+
};
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import React, { useState, useEffect } from "react";
|
|
4
|
+
import { MessageSquare } from "lucide-react";
|
|
5
|
+
import { AiProfile, loadAiProfiles } from "../editor/services/aiService";
|
|
6
|
+
import { Agent, getAgentsGrouped } from "../editor/services/agentService";
|
|
7
|
+
import { useEditContext } from "../editor/client/editContext";
|
|
8
|
+
import { Button } from "../components/ui/button";
|
|
9
|
+
|
|
10
|
+
interface RecentAgentsProps {
|
|
11
|
+
onSelectAgent?: (agent: Agent) => void;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export const RecentAgents: React.FC<RecentAgentsProps> = ({ onSelectAgent }) => {
|
|
15
|
+
const editContext = useEditContext();
|
|
16
|
+
const [agents, setAgents] = useState<Agent[]>([]);
|
|
17
|
+
const [profile, setProfile] = useState<AiProfile | null>(null);
|
|
18
|
+
const [isLoading, setIsLoading] = useState(true);
|
|
19
|
+
const [showExpanded, setShowExpanded] = useState(false);
|
|
20
|
+
|
|
21
|
+
useEffect(() => {
|
|
22
|
+
const loadData = async () => {
|
|
23
|
+
try {
|
|
24
|
+
setIsLoading(true);
|
|
25
|
+
|
|
26
|
+
// Load Parhelia profile
|
|
27
|
+
const profileList = await loadAiProfiles();
|
|
28
|
+
let assistantProfile: AiProfile | undefined;
|
|
29
|
+
|
|
30
|
+
assistantProfile = profileList.find(
|
|
31
|
+
(p) => p.id === "7d45ab97-f253-4915-8b32-f9e8c762c5e9",
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
if (!assistantProfile) {
|
|
35
|
+
assistantProfile = profileList.find(
|
|
36
|
+
(p) => p.name.toLowerCase() === "parhelia",
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (!assistantProfile) {
|
|
41
|
+
assistantProfile = profileList.find(
|
|
42
|
+
(p) =>
|
|
43
|
+
p.name.toLowerCase().includes("parhelia") ||
|
|
44
|
+
p.displayTitle?.toLowerCase().includes("parhelia"),
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const selectedProfile = assistantProfile || profileList[0] || null;
|
|
49
|
+
setProfile(selectedProfile);
|
|
50
|
+
|
|
51
|
+
// Fetch all agents (both active and closed) for this profile
|
|
52
|
+
if (selectedProfile) {
|
|
53
|
+
const response = await getAgentsGrouped();
|
|
54
|
+
|
|
55
|
+
// Combine active agents with closed agents
|
|
56
|
+
const allAgents: Agent[] = [...response.activeAgents];
|
|
57
|
+
|
|
58
|
+
// Add closed agents from all profiles
|
|
59
|
+
response.closedAgentsByProfile.forEach(group => {
|
|
60
|
+
allAgents.push(...group.agents);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
// Filter for Parhelia agents only
|
|
64
|
+
const parheliaAgents = allAgents.filter(
|
|
65
|
+
(a) => a.profileId === selectedProfile.id
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
// Take the most recent 15 agents
|
|
69
|
+
setAgents(parheliaAgents.slice(0, 15));
|
|
70
|
+
}
|
|
71
|
+
} catch (err) {
|
|
72
|
+
console.error("Failed to load agents:", err);
|
|
73
|
+
} finally {
|
|
74
|
+
setIsLoading(false);
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
loadData();
|
|
79
|
+
}, []);
|
|
80
|
+
|
|
81
|
+
const handleOpenAgent = (agent: Agent) => {
|
|
82
|
+
// Use the callback to set the selected agent in the parent component
|
|
83
|
+
if (onSelectAgent) {
|
|
84
|
+
onSelectAgent(agent);
|
|
85
|
+
// Scroll to the top to show the chat interface
|
|
86
|
+
window.scrollTo({ top: 0, behavior: "smooth" });
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
const handleShowAll = () => {
|
|
91
|
+
editContext?.switchView("agents-overview");
|
|
92
|
+
editContext?.setShowAgentsPanel?.(true);
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
if (isLoading || agents.length === 0) {
|
|
96
|
+
return null;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// Show 3 agents by default, or 15 when expanded
|
|
100
|
+
const displayedAgents = showExpanded ? agents : agents.slice(0, 3);
|
|
101
|
+
const hasMoreAgents = agents.length > 3;
|
|
102
|
+
|
|
103
|
+
return (
|
|
104
|
+
<div className="w-full">
|
|
105
|
+
<h2 className="mb-3 text-center text-sm font-medium text-gray-700">
|
|
106
|
+
Recent Conversations
|
|
107
|
+
</h2>
|
|
108
|
+
<div className="space-y-1.5">
|
|
109
|
+
{displayedAgents.map((agent) => (
|
|
110
|
+
<button
|
|
111
|
+
key={agent.id}
|
|
112
|
+
onClick={() => handleOpenAgent(agent)}
|
|
113
|
+
className="flex w-full items-center gap-2 px-2 py-1.5 text-left transition-colors hover:bg-white/50 rounded"
|
|
114
|
+
>
|
|
115
|
+
<MessageSquare className="h-3.5 w-3.5 flex-shrink-0 text-gray-400" strokeWidth={1.5} />
|
|
116
|
+
<div className="flex-1 min-w-0">
|
|
117
|
+
<span className="text-xs text-gray-700 truncate block">
|
|
118
|
+
{agent.name}
|
|
119
|
+
</span>
|
|
120
|
+
</div>
|
|
121
|
+
</button>
|
|
122
|
+
))}
|
|
123
|
+
</div>
|
|
124
|
+
|
|
125
|
+
{hasMoreAgents && (
|
|
126
|
+
<div className="mt-3 flex gap-2">
|
|
127
|
+
{!showExpanded ? (
|
|
128
|
+
<Button
|
|
129
|
+
variant="outline"
|
|
130
|
+
size="sm"
|
|
131
|
+
onClick={() => setShowExpanded(true)}
|
|
132
|
+
className="flex-1 text-xs"
|
|
133
|
+
>
|
|
134
|
+
Show More
|
|
135
|
+
</Button>
|
|
136
|
+
) : (
|
|
137
|
+
<Button
|
|
138
|
+
variant="outline"
|
|
139
|
+
size="sm"
|
|
140
|
+
onClick={handleShowAll}
|
|
141
|
+
className="flex-1 text-xs"
|
|
142
|
+
>
|
|
143
|
+
Show All
|
|
144
|
+
</Button>
|
|
145
|
+
)}
|
|
146
|
+
</div>
|
|
147
|
+
)}
|
|
148
|
+
</div>
|
|
149
|
+
);
|
|
150
|
+
};
|
|
151
|
+
|