@alpaca-editor/core 1.0.4013 → 1.0.4014
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/editor/Terminal.d.ts +6 -0
- package/dist/editor/Terminal.js +10 -4
- package/dist/editor/Terminal.js.map +1 -1
- package/dist/editor/ai/Agents.js +133 -13
- package/dist/editor/ai/Agents.js.map +1 -1
- package/dist/editor/ai/AiTerminal.d.ts +2 -1
- package/dist/editor/ai/AiTerminal.js +86 -139
- package/dist/editor/ai/AiTerminal.js.map +1 -1
- package/dist/editor/media-selector/AiImageSearch.js +2 -1
- package/dist/editor/media-selector/AiImageSearch.js.map +1 -1
- package/dist/editor/media-selector/AiImageSearchPrompt.js +2 -1
- package/dist/editor/media-selector/AiImageSearchPrompt.js.map +1 -1
- package/dist/editor/page-editor-chrome/useInlineAICompletion.js +4 -2
- package/dist/editor/page-editor-chrome/useInlineAICompletion.js.map +1 -1
- package/dist/editor/services/agentService.d.ts +59 -0
- package/dist/editor/services/agentService.js +26 -0
- package/dist/editor/services/agentService.js.map +1 -0
- package/dist/editor/services/aiService.d.ts +22 -4
- package/dist/editor/services/aiService.js +131 -20
- package/dist/editor/services/aiService.js.map +1 -1
- package/dist/editor/services/contextService.js +6 -4
- package/dist/editor/services/contextService.js.map +1 -1
- package/dist/editor/sidebar/SidebarView.js +2 -5
- package/dist/editor/sidebar/SidebarView.js.map +1 -1
- package/dist/editor/sidebar/ViewSelector.js +1 -1
- package/dist/editor/sidebar/ViewSelector.js.map +1 -1
- package/dist/editor/ui/SimpleIconButton.d.ts +2 -2
- package/dist/editor/ui/SimpleIconButton.js +5 -3
- package/dist/editor/ui/SimpleIconButton.js.map +1 -1
- package/dist/editor/utils/jsonCleaner.d.ts +8 -0
- package/dist/editor/utils/jsonCleaner.js +76 -0
- package/dist/editor/utils/jsonCleaner.js.map +1 -0
- package/dist/editor/views/CompareView.js +2 -2
- package/dist/editor/views/CompareView.js.map +1 -1
- package/dist/page-wizard/steps/ContentStep.js +7 -2
- package/dist/page-wizard/steps/ContentStep.js.map +1 -1
- package/dist/page-wizard/steps/FindItemsStep.js +4 -1
- package/dist/page-wizard/steps/FindItemsStep.js.map +1 -1
- package/dist/page-wizard/steps/ImagesStep.js +13 -7
- package/dist/page-wizard/steps/ImagesStep.js.map +1 -1
- package/dist/page-wizard/steps/LayoutStep.d.ts +1 -1
- package/dist/page-wizard/steps/LayoutStep.js +22 -20
- package/dist/page-wizard/steps/LayoutStep.js.map +1 -1
- package/dist/page-wizard/steps/MetaDataStep.js +8 -15
- package/dist/page-wizard/steps/MetaDataStep.js.map +1 -1
- package/dist/page-wizard/steps/SelectStep.js +9 -4
- package/dist/page-wizard/steps/SelectStep.js.map +1 -1
- package/dist/page-wizard/steps/StructureStep.js +3 -1
- package/dist/page-wizard/steps/StructureStep.js.map +1 -1
- package/dist/revision.d.ts +2 -2
- package/dist/revision.js +2 -2
- package/dist/styles.css +10 -11
- package/package.json +1 -1
- package/src/editor/Terminal.tsx +12 -3
- package/src/editor/ai/Agents.tsx +212 -16
- package/src/editor/ai/AiTerminal.tsx +113 -173
- package/src/editor/ai/GhostWriter.tsx_ +3 -3
- package/src/editor/media-selector/AiImageSearch.tsx +2 -2
- package/src/editor/media-selector/AiImageSearchPrompt.tsx +2 -2
- package/src/editor/page-editor-chrome/useInlineAICompletion.tsx +5 -5
- package/src/editor/services/agentService.ts +83 -0
- package/src/editor/services/aiService.ts +176 -33
- package/src/editor/services/contextService.ts +5 -6
- package/src/editor/sidebar/SidebarView.tsx +10 -6
- package/src/editor/sidebar/ViewSelector.tsx +2 -2
- package/src/editor/ui/SimpleIconButton.tsx +20 -14
- package/src/editor/utils/jsonCleaner.ts +92 -0
- package/src/editor/views/CompareView.tsx +2 -2
- package/src/page-wizard/steps/ContentStep.tsx +10 -9
- package/src/page-wizard/steps/FindItemsStep.tsx +7 -5
- package/src/page-wizard/steps/ImagesStep.tsx +16 -11
- package/src/page-wizard/steps/LayoutStep.tsx +24 -28
- package/src/page-wizard/steps/MetaDataStep.tsx +11 -21
- package/src/page-wizard/steps/SelectStep.tsx +11 -8
- package/src/page-wizard/steps/StructureStep.tsx +4 -5
- package/src/revision.ts +2 -2
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
+
type Message = {
|
|
3
|
+
text: React.ReactNode;
|
|
4
|
+
type: "command" | "response";
|
|
5
|
+
};
|
|
2
6
|
export declare const Terminal: React.ForwardRefExoticComponent<{
|
|
3
7
|
commandHandler: (text: string, callback: (text: React.ReactNode, finished: boolean) => void) => void;
|
|
4
8
|
prompt: string;
|
|
@@ -9,6 +13,8 @@ export declare const Terminal: React.ForwardRefExoticComponent<{
|
|
|
9
13
|
infobar?: React.ReactNode;
|
|
10
14
|
disabled?: boolean;
|
|
11
15
|
className?: string;
|
|
16
|
+
initialMessages?: Message[];
|
|
12
17
|
} & React.RefAttributes<{
|
|
13
18
|
submit: () => void;
|
|
14
19
|
}>>;
|
|
20
|
+
export {};
|
package/dist/editor/Terminal.js
CHANGED
|
@@ -5,7 +5,7 @@ import { classNames } from "primereact/utils";
|
|
|
5
5
|
import { SimpleIconButton } from "./ui/SimpleIconButton";
|
|
6
6
|
import { Trash2, Send } from "lucide-react";
|
|
7
7
|
export const Terminal = forwardRef((props, ref) => {
|
|
8
|
-
const { commandHandler, prompt, setPrompt, onReset, toolbar, statusbar, infobar, disabled, className, } = props;
|
|
8
|
+
const { commandHandler, prompt, setPrompt, onReset, toolbar, statusbar, infobar, disabled, className, initialMessages, } = props;
|
|
9
9
|
const [response, setResponse] = useState();
|
|
10
10
|
const [messages, setMessages] = useState([]);
|
|
11
11
|
const bottomRef = useRef(null);
|
|
@@ -29,6 +29,12 @@ export const Terminal = forwardRef((props, ref) => {
|
|
|
29
29
|
useEffect(() => {
|
|
30
30
|
messageRef.current = messages;
|
|
31
31
|
}, [messages]);
|
|
32
|
+
// Set initial messages if provided
|
|
33
|
+
useEffect(() => {
|
|
34
|
+
if (initialMessages && initialMessages.length > 0 && messages.length === 0) {
|
|
35
|
+
setMessages(initialMessages);
|
|
36
|
+
}
|
|
37
|
+
}, [initialMessages]);
|
|
32
38
|
const callback = (text, finished) => {
|
|
33
39
|
if (!finished)
|
|
34
40
|
setResponse(text);
|
|
@@ -81,11 +87,11 @@ export const Terminal = forwardRef((props, ref) => {
|
|
|
81
87
|
// Scroll to bottom every time messages or response changes.
|
|
82
88
|
bottomRef.current?.scrollIntoView({ behavior: "smooth" });
|
|
83
89
|
}, [messages, response]);
|
|
84
|
-
const responseBoxClasses = "text-xs self-stretch text-gray-700 p-2 rounded
|
|
90
|
+
const responseBoxClasses = "text-xs self-stretch text-gray-700 p-2 rounded border border-theme-secondary bg-theme-secondary-light";
|
|
85
91
|
const getClasses = (m) => {
|
|
86
92
|
if (m.type === "response")
|
|
87
93
|
return responseBoxClasses;
|
|
88
|
-
return "text-xs text-gray-700 bg-indigo-100 p-2 rounded prompt";
|
|
94
|
+
return "text-xs text-gray-700 bg-indigo-100 border border-indigo-300 p-2 rounded prompt";
|
|
89
95
|
};
|
|
90
96
|
// Expose the submit function via the ref.
|
|
91
97
|
const submit = () => {
|
|
@@ -98,7 +104,7 @@ export const Terminal = forwardRef((props, ref) => {
|
|
|
98
104
|
}
|
|
99
105
|
setMessages([...messages, { type: "command", text: prompt }]);
|
|
100
106
|
setPrompt("");
|
|
101
|
-
setResponse("
|
|
107
|
+
setResponse("");
|
|
102
108
|
commandHandler(prompt, callback);
|
|
103
109
|
};
|
|
104
110
|
useImperativeHandle(ref, () => ({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Terminal.js","sourceRoot":"","sources":["../../src/editor/Terminal.tsx"],"names":[],"mappings":";AAAA,OAAc,EACZ,UAAU,EACV,SAAS,EACT,MAAM,EACN,QAAQ,EACR,mBAAmB,GACpB,MAAM,OAAO,CAAC;AAEf,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,EAAE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QAAQ,GAAO,EAC9C,eAAK,SAAS,EAAC,oEAAoE,aACjF,cAAK,SAAS,EAAC,yEAAyE,GAAO,EAC/F,cAAK,SAAS,EAAC,0EAA0E,GAAO,EAChG,cAAK,SAAS,EAAC,iDAAiD,GAAO,IACnE,IACF,CACP,EACD,cAAK,GAAG,EAAE,SAAS,GAAI,IACnB,GACF,EACN,eAAK,SAAS,EAAC,wBAAwB,aACpC,OAAO,EACR,KAAC,aAAa,IACZ,GAAG,EAAE,QAAQ,EACb,KAAK,EAAE,MAAM,EACb,SAAS,EAAC,wEAAwE,EAClF,SAAS,EAAE,cAAc,EACzB,QAAQ,EAAE,CAAC,CAAC,EAAE,EAAE;4BACd,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;4BAC1B,8CAA8C;4BAC9C,IAAI,mBAAmB,KAAK,CAAC,CAAC,EAAE,CAAC;gCAC/B,sBAAsB,CAAC,CAAC,CAAC,CAAC,CAAC;4BAC7B,CAAC;wBACH,CAAC,EACD,IAAI,EAAE,CAAC,EACP,IAAI,EAAE,EAAE,EACR,QAAQ,EAAE,QAAQ,GAClB,EACF,eAAK,SAAS,EAAC,wCAAwC,aACpD,SAAS,EACV,KAAC,gBAAgB,IACf,IAAI,EAAE,KAAC,IAAI,IAAC,IAAI,EAAE,EAAE,EAAE,WAAW,EAAE,CAAC,GAAI,EACxC,SAAS,EAAC,kBAAkB,EAC5B,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,MAAM,CAAC,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC,EACpC,KAAK,EAAC,MAAM,GACZ,IACE,IACF,IACF,CACP,CAAC;AACJ,CAAC,CAAC,CAAC"}
|
package/dist/editor/ai/Agents.js
CHANGED
|
@@ -1,19 +1,109 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { useState, useRef } from "react";
|
|
2
|
+
import { useState, useRef, useEffect } from "react";
|
|
3
3
|
import { EditorAiTerminal } from "./EditorAiTerminal";
|
|
4
4
|
import { SimpleIconButton } from "../ui/SimpleIconButton";
|
|
5
|
-
import { Plus, X } from "lucide-react";
|
|
5
|
+
import { Plus, X, History } from "lucide-react";
|
|
6
6
|
import { cn } from "../../lib/utils";
|
|
7
|
+
import { getAgents, getAgent, getChatHistory } from "../services/agentService";
|
|
8
|
+
import { Popover, PopoverContent, PopoverTrigger, } from "../../components/ui/popover";
|
|
9
|
+
function convertAgentMessagesToTerminalMessages(agentMessages) {
|
|
10
|
+
return agentMessages.map(msg => ({
|
|
11
|
+
id: msg.id,
|
|
12
|
+
content: msg.content,
|
|
13
|
+
name: msg.name,
|
|
14
|
+
role: msg.role,
|
|
15
|
+
tool_calls: msg.functionName ? [{
|
|
16
|
+
id: msg.toolCallId || msg.id,
|
|
17
|
+
displayName: msg.functionName,
|
|
18
|
+
function: {
|
|
19
|
+
name: msg.functionName,
|
|
20
|
+
arguments: msg.functionArguments || ""
|
|
21
|
+
}
|
|
22
|
+
}] : [],
|
|
23
|
+
tool_call_id: msg.toolCallId
|
|
24
|
+
}));
|
|
25
|
+
}
|
|
7
26
|
export function Agents({ closeButton, initialOptions, }) {
|
|
8
|
-
const [terminals, setTerminals] = useState([
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
27
|
+
const [terminals, setTerminals] = useState([]);
|
|
28
|
+
const [activeTerminalId, setActiveTerminalId] = useState(null);
|
|
29
|
+
const [inactiveAgents, setInactiveAgents] = useState([]);
|
|
30
|
+
const [historyPopoverOpen, setHistoryPopoverOpen] = useState(false);
|
|
31
|
+
const [loadingAgents, setLoadingAgents] = useState(true);
|
|
32
|
+
const nextTerminalNumber = useRef(1);
|
|
33
|
+
// Load agents from backend on mount
|
|
34
|
+
useEffect(() => {
|
|
35
|
+
loadAgentsFromBackend();
|
|
36
|
+
}, []);
|
|
37
|
+
const loadAgentsFromBackend = async () => {
|
|
38
|
+
try {
|
|
39
|
+
setLoadingAgents(true);
|
|
40
|
+
// Load active agents
|
|
41
|
+
const activeAgentsResult = await getAgents("active");
|
|
42
|
+
// Load inactive agents for history
|
|
43
|
+
const inactiveAgentsResult = await getChatHistory("completed", 20);
|
|
44
|
+
if (activeAgentsResult.type === "success" && activeAgentsResult.data) {
|
|
45
|
+
const activeAgents = activeAgentsResult.data;
|
|
46
|
+
// Create terminals for active agents
|
|
47
|
+
const activeTerminals = await Promise.all(activeAgents.map(async (agent, index) => {
|
|
48
|
+
// Load messages for each active agent
|
|
49
|
+
const agentWithMessages = await loadAgentMessages(agent.id);
|
|
50
|
+
return {
|
|
51
|
+
id: `agent-${agent.id}`,
|
|
52
|
+
title: agent.name || `Agent ${index + 1}`,
|
|
53
|
+
agentId: agent.id,
|
|
54
|
+
options: initialOptions,
|
|
55
|
+
messages: agentWithMessages?.messages ? convertAgentMessagesToTerminalMessages(agentWithMessages.messages) : []
|
|
56
|
+
};
|
|
57
|
+
}));
|
|
58
|
+
setTerminals(activeTerminals);
|
|
59
|
+
// Set the first active terminal as active, or create a new one if none exist
|
|
60
|
+
if (activeTerminals.length > 0) {
|
|
61
|
+
setActiveTerminalId(activeTerminals[0].id);
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
// Create a default terminal if no active agents
|
|
65
|
+
const defaultTerminal = {
|
|
66
|
+
id: `terminal-${nextTerminalNumber.current}`,
|
|
67
|
+
title: `Agent ${nextTerminalNumber.current}`,
|
|
68
|
+
options: initialOptions,
|
|
69
|
+
};
|
|
70
|
+
setTerminals([defaultTerminal]);
|
|
71
|
+
setActiveTerminalId(defaultTerminal.id);
|
|
72
|
+
nextTerminalNumber.current++;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
if (inactiveAgentsResult.type === "success" && inactiveAgentsResult.data) {
|
|
76
|
+
setInactiveAgents(inactiveAgentsResult.data);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
catch (error) {
|
|
80
|
+
console.error("Failed to load agents:", error);
|
|
81
|
+
// Create a default terminal on error
|
|
82
|
+
const defaultTerminal = {
|
|
83
|
+
id: `terminal-${nextTerminalNumber.current}`,
|
|
84
|
+
title: `Agent ${nextTerminalNumber.current}`,
|
|
85
|
+
options: initialOptions,
|
|
86
|
+
};
|
|
87
|
+
setTerminals([defaultTerminal]);
|
|
88
|
+
setActiveTerminalId(defaultTerminal.id);
|
|
89
|
+
nextTerminalNumber.current++;
|
|
90
|
+
}
|
|
91
|
+
finally {
|
|
92
|
+
setLoadingAgents(false);
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
const loadAgentMessages = async (agentId) => {
|
|
96
|
+
try {
|
|
97
|
+
const result = await getAgent(agentId);
|
|
98
|
+
if (result.type === "success" && result.data) {
|
|
99
|
+
return result.data;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
catch (error) {
|
|
103
|
+
console.error(`Failed to load messages for agent ${agentId}:`, error);
|
|
104
|
+
}
|
|
105
|
+
return null;
|
|
106
|
+
};
|
|
17
107
|
const addTerminal = () => {
|
|
18
108
|
const newTerminal = {
|
|
19
109
|
id: `terminal-${nextTerminalNumber.current}`,
|
|
@@ -38,11 +128,41 @@ export function Agents({ closeButton, initialOptions, }) {
|
|
|
38
128
|
return filtered;
|
|
39
129
|
});
|
|
40
130
|
};
|
|
41
|
-
|
|
131
|
+
const openAgentFromHistory = async (agent) => {
|
|
132
|
+
// Check if this agent is already open as a terminal
|
|
133
|
+
const existingTerminal = terminals.find(t => t.agentId === agent.id);
|
|
134
|
+
if (existingTerminal) {
|
|
135
|
+
// Switch to existing terminal
|
|
136
|
+
setActiveTerminalId(existingTerminal.id);
|
|
137
|
+
setHistoryPopoverOpen(false);
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
// Load the agent with messages
|
|
141
|
+
const agentWithMessages = await loadAgentMessages(agent.id);
|
|
142
|
+
// Create new terminal for this agent
|
|
143
|
+
const newTerminal = {
|
|
144
|
+
id: `agent-${agent.id}`,
|
|
145
|
+
title: agent.name,
|
|
146
|
+
agentId: agent.id,
|
|
147
|
+
options: initialOptions,
|
|
148
|
+
messages: agentWithMessages?.messages ? convertAgentMessagesToTerminalMessages(agentWithMessages.messages) : []
|
|
149
|
+
};
|
|
150
|
+
setTerminals((prev) => [...prev, newTerminal]);
|
|
151
|
+
setActiveTerminalId(newTerminal.id);
|
|
152
|
+
setHistoryPopoverOpen(false);
|
|
153
|
+
};
|
|
154
|
+
if (loadingAgents) {
|
|
155
|
+
return (_jsx("div", { className: "flex h-full items-center justify-center", children: _jsx("div", { className: "text-sm text-gray-500", children: "Loading agents..." }) }));
|
|
156
|
+
}
|
|
157
|
+
return (_jsxs("div", { className: "flex h-full flex-col", children: [_jsxs("div", { className: "flex items-center border-b border-gray-200 bg-gray-50", children: [_jsx("div", { className: "flex flex-1 overflow-x-auto", children: terminals.map((terminal) => (_jsxs("div", { className: cn("flex min-w-0 cursor-pointer items-center gap-1 border-r border-gray-200 px-3 py-2 text-xs", activeTerminalId === terminal.id
|
|
42
158
|
? "border-b-white bg-white"
|
|
43
159
|
: "hover:bg-gray-100"), onClick: () => setActiveTerminalId(terminal.id), children: [_jsx("span", { className: "truncate", children: terminal.title }), terminals.length > 1 && (_jsx(SimpleIconButton, { onClick: (e) => {
|
|
44
160
|
e.stopPropagation();
|
|
45
161
|
closeTerminal(terminal.id);
|
|
46
|
-
}, icon: _jsx(X, { className: "size-
|
|
162
|
+
}, icon: _jsx(X, { className: "size-2" }), label: "Close", className: "ml-1 opacity-60 hover:opacity-100" }))] }, terminal.id))) }), _jsx("div", { className: "flex items-center px-1", children: _jsxs(Popover, { open: historyPopoverOpen, onOpenChange: setHistoryPopoverOpen, children: [_jsx(PopoverTrigger, { asChild: true, children: _jsx(SimpleIconButton, { onClick: () => { }, icon: _jsx(History, { className: "size-4" }), label: "Agent History", className: "text-gray-600 hover:text-gray-800" }) }), _jsxs(PopoverContent, { className: "w-64 p-0", align: "end", children: [_jsx("div", { className: "px-3 py-2 text-xs font-medium text-gray-500 border-b border-gray-100", children: "Agent History" }), _jsx("div", { className: "max-h-80 overflow-y-auto", children: inactiveAgents.length === 0 ? (_jsx("div", { className: "px-3 py-2 text-xs text-gray-500", children: "No previous agents found" })) : (inactiveAgents.map((agent) => (_jsxs("div", { className: "cursor-pointer px-3 py-2 text-xs hover:bg-gray-50 border-b border-gray-50", onClick: () => openAgentFromHistory(agent), children: [_jsx("div", { className: "font-medium text-gray-900 truncate", children: agent.name }), _jsx("div", { className: "text-gray-500 truncate", children: agent.profileName }), _jsx("div", { className: "text-gray-400 text-xs", children: new Date(agent.updatedDate).toLocaleString() })] }, agent.id)))) })] })] }) }), _jsx("div", { className: "flex items-center px-1", children: _jsx(SimpleIconButton, { onClick: addTerminal, icon: _jsx(Plus, { className: "size-4" }), label: "Add Terminal", className: "text-gray-600 hover:text-gray-800" }) }), closeButton && (_jsx("div", { className: "flex items-center px-2", children: closeButton }))] }), _jsx("div", { className: "relative flex-1", children: terminals.map((terminal) => (_jsx("div", { className: cn("absolute inset-0", activeTerminalId === terminal.id ? "block" : "hidden"), children: _jsx(EditorAiTerminal, { options: {
|
|
163
|
+
...terminal.options,
|
|
164
|
+
// Pass the pre-loaded messages to the terminal
|
|
165
|
+
initialMessages: terminal.messages
|
|
166
|
+
} }) }, terminal.id))) })] }));
|
|
47
167
|
}
|
|
48
168
|
//# sourceMappingURL=Agents.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Agents.js","sourceRoot":"","sources":["../../../src/editor/ai/Agents.tsx"],"names":[],"mappings":";AAAA,OAAc,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"Agents.js","sourceRoot":"","sources":["../../../src/editor/ai/Agents.tsx"],"names":[],"mappings":";AAAA,OAAc,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;A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C,CAC3B,cAEE,SAAS,EAAE,EAAE,CACX,kBAAkB,EAClB,gBAAgB,KAAK,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,QAAQ,CACtD,YAED,KAAC,gBAAgB,IACf,OAAO,EAAE;4BACP,GAAG,QAAQ,CAAC,OAAO;4BACnB,+CAA+C;4BAC/C,eAAe,EAAE,QAAQ,CAAC,QAAQ;yBACnC,GACD,IAZG,QAAQ,CAAC,EAAE,CAaZ,CACP,CAAC,GACE,IACF,CACP,CAAC;AACJ,CAAC"}
|
|
@@ -16,7 +16,7 @@ export type ToolCall = {
|
|
|
16
16
|
};
|
|
17
17
|
};
|
|
18
18
|
export type Message = {
|
|
19
|
-
id:
|
|
19
|
+
id: string;
|
|
20
20
|
content: string;
|
|
21
21
|
formattedContent?: string;
|
|
22
22
|
name: string;
|
|
@@ -32,6 +32,7 @@ export type AiContext = {
|
|
|
32
32
|
export type AiTerminalOptions = {
|
|
33
33
|
initialPrompt?: string;
|
|
34
34
|
hiddenSystemPrompt?: string;
|
|
35
|
+
initialMessages?: Message[];
|
|
35
36
|
};
|
|
36
37
|
export declare function AiTerminal({ closeButton, createAiContext, defaultProfile, options, }: {
|
|
37
38
|
closeButton?: React.ReactNode;
|
|
@@ -5,10 +5,9 @@ import { TerminalService } from "primereact/terminalservice";
|
|
|
5
5
|
import { Terminal } from "../Terminal";
|
|
6
6
|
import { useEditContext } from "../client/editContext";
|
|
7
7
|
import { Dropdown } from "primereact/dropdown";
|
|
8
|
-
import Cookies from "universal-cookie";
|
|
9
8
|
import { WizardIcon } from "../ui/Icons";
|
|
10
9
|
import { AiResponseMessage } from "./AiResponseMessage";
|
|
11
|
-
import { loadAiProfiles } from "../services/aiService";
|
|
10
|
+
import { loadAiProfiles, executePrompt, } from "../services/aiService";
|
|
12
11
|
import { SimpleIconButton } from "../ui/SimpleIconButton";
|
|
13
12
|
import { Settings } from "lucide-react";
|
|
14
13
|
export function AiTerminal({ closeButton, createAiContext, defaultProfile, options, }) {
|
|
@@ -16,7 +15,7 @@ export function AiTerminal({ closeButton, createAiContext, defaultProfile, optio
|
|
|
16
15
|
const [showPredefined, setShowPredefined] = useState(false);
|
|
17
16
|
if (!editContext)
|
|
18
17
|
return null;
|
|
19
|
-
const [messages, setMessages] = useState([]);
|
|
18
|
+
const [messages, setMessages] = useState(options?.initialMessages || []);
|
|
20
19
|
const [response, setResponse] = useState();
|
|
21
20
|
const [model, setModel] = useState();
|
|
22
21
|
const [prompt, setPrompt] = useState("");
|
|
@@ -26,7 +25,7 @@ export function AiTerminal({ closeButton, createAiContext, defaultProfile, optio
|
|
|
26
25
|
const [agentId] = useState(() => crypto.randomUUID());
|
|
27
26
|
const selection = editContext.selection;
|
|
28
27
|
const terminalRef = useRef(null);
|
|
29
|
-
const [responseMessages, setResponseMessages] = useState([]);
|
|
28
|
+
const [responseMessages, setResponseMessages] = useState(options?.initialMessages || []);
|
|
30
29
|
const [showSettings, setShowSettings] = useState(false);
|
|
31
30
|
const settingsRef = useRef(null);
|
|
32
31
|
useEffect(() => {
|
|
@@ -60,6 +59,71 @@ export function AiTerminal({ closeButton, createAiContext, defaultProfile, optio
|
|
|
60
59
|
useEffect(() => {
|
|
61
60
|
messagesRef.current = responseMessages;
|
|
62
61
|
}, [responseMessages]);
|
|
62
|
+
const [initialTerminalMessages, setInitialTerminalMessages] = useState(undefined);
|
|
63
|
+
// Effect to set up initial messages for display
|
|
64
|
+
useEffect(() => {
|
|
65
|
+
if (options?.initialMessages && options.initialMessages.length > 0) {
|
|
66
|
+
console.log("AiTerminal: Loading initial messages", options.initialMessages);
|
|
67
|
+
// Format the initial messages for display
|
|
68
|
+
const formattedMessages = options.initialMessages.map((message) => {
|
|
69
|
+
const formattedContent = message.content
|
|
70
|
+
?.trim()
|
|
71
|
+
?.replaceAll("\n", "<br>")
|
|
72
|
+
?.replace(/\*\*(.*?)\*\*/g, "<b>$1</b>") || "";
|
|
73
|
+
return {
|
|
74
|
+
...message,
|
|
75
|
+
content: message.content || "",
|
|
76
|
+
formattedContent: formattedContent,
|
|
77
|
+
tool_calls: message.tool_calls || [],
|
|
78
|
+
};
|
|
79
|
+
});
|
|
80
|
+
console.log("AiTerminal: Formatted messages", formattedMessages);
|
|
81
|
+
// Update the internal message states
|
|
82
|
+
setMessages(formattedMessages);
|
|
83
|
+
setResponseMessages(formattedMessages);
|
|
84
|
+
// Create a response object for internal state
|
|
85
|
+
const initialResponse = {
|
|
86
|
+
messages: formattedMessages,
|
|
87
|
+
editOperations: [],
|
|
88
|
+
numInputTokens: 0,
|
|
89
|
+
numOutputTokens: 0,
|
|
90
|
+
numCachedTokens: 0,
|
|
91
|
+
state: "loaded"
|
|
92
|
+
};
|
|
93
|
+
console.log("AiTerminal: Setting response", initialResponse);
|
|
94
|
+
setResponse(initialResponse);
|
|
95
|
+
// Create individual Terminal messages for each conversation message
|
|
96
|
+
const terminalMessages = [];
|
|
97
|
+
formattedMessages.forEach((message) => {
|
|
98
|
+
if (message.role === "user") {
|
|
99
|
+
// User messages appear as commands
|
|
100
|
+
terminalMessages.push({
|
|
101
|
+
type: "command",
|
|
102
|
+
text: message.content
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
else if (message.role === "assistant") {
|
|
106
|
+
// Assistant messages appear as responses
|
|
107
|
+
terminalMessages.push({
|
|
108
|
+
type: "response",
|
|
109
|
+
text: (_jsx("div", { dangerouslySetInnerHTML: {
|
|
110
|
+
__html: message.formattedContent || message.content || "",
|
|
111
|
+
} }))
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
// Add tool calls if present
|
|
115
|
+
if (message.tool_calls && message.tool_calls.length > 0) {
|
|
116
|
+
message.tool_calls.forEach((toolCall) => {
|
|
117
|
+
terminalMessages.push({
|
|
118
|
+
type: "response",
|
|
119
|
+
text: (_jsxs("div", { className: "text-xs text-gray-400", children: ["\uD83D\uDD27 ", toolCall.displayName] }))
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
setInitialTerminalMessages(terminalMessages);
|
|
125
|
+
}
|
|
126
|
+
}, [options?.initialMessages]);
|
|
63
127
|
// Handle click outside for settings popover
|
|
64
128
|
useEffect(() => {
|
|
65
129
|
function handleClickOutside(event) {
|
|
@@ -81,12 +145,12 @@ export function AiTerminal({ closeButton, createAiContext, defaultProfile, optio
|
|
|
81
145
|
if (updatedMessages && Array.isArray(updatedMessages)) {
|
|
82
146
|
const formattedMessages = updatedMessages.map((message) => {
|
|
83
147
|
const formattedContent = message.content
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
?.replace(/\*\*(.*?)\*\*/g, "<b>$1</b>");
|
|
148
|
+
?.trim()
|
|
149
|
+
?.replaceAll("\n", "<br>")
|
|
150
|
+
?.replace(/\*\*(.*?)\*\*/g, "<b>$1</b>") || "";
|
|
87
151
|
return {
|
|
88
152
|
...message,
|
|
89
|
-
content: message.content,
|
|
153
|
+
content: message.content || "",
|
|
90
154
|
formattedContent: formattedContent,
|
|
91
155
|
tool_calls: message.tool_calls || [],
|
|
92
156
|
};
|
|
@@ -103,7 +167,7 @@ export function AiTerminal({ closeButton, createAiContext, defaultProfile, optio
|
|
|
103
167
|
}
|
|
104
168
|
async function commandHandler(text, callback) {
|
|
105
169
|
const userMessage = {
|
|
106
|
-
id:
|
|
170
|
+
id: crypto.randomUUID(), // Add unique id
|
|
107
171
|
content: text,
|
|
108
172
|
role: "user",
|
|
109
173
|
name: "user",
|
|
@@ -123,62 +187,24 @@ export function AiTerminal({ closeButton, createAiContext, defaultProfile, optio
|
|
|
123
187
|
role: "system",
|
|
124
188
|
name: "system",
|
|
125
189
|
content: options.hiddenSystemPrompt,
|
|
126
|
-
id:
|
|
190
|
+
id: crypto.randomUUID(), // Use UUID instead of hardcoded 0
|
|
127
191
|
toolCalls: [],
|
|
128
192
|
},
|
|
129
193
|
]
|
|
130
194
|
: []),
|
|
131
195
|
...conversationHistory,
|
|
132
196
|
];
|
|
133
|
-
const response = await executePrompt(
|
|
197
|
+
const response = await executePrompt(messages, context, {
|
|
198
|
+
profileId: activeProfile.id,
|
|
199
|
+
selection,
|
|
200
|
+
selectedText,
|
|
201
|
+
model,
|
|
202
|
+
sessionId: editContext.sessionId,
|
|
203
|
+
agentId,
|
|
204
|
+
addSelectedComponents: true,
|
|
205
|
+
}, undefined, (response) => {
|
|
134
206
|
setResponse(response);
|
|
135
207
|
handleResponse(response, callback, false);
|
|
136
|
-
// if (response.editOperations.length) {
|
|
137
|
-
// if (!editContext) return;
|
|
138
|
-
// const newOps = response.editOperations.slice(lastOpIndex);
|
|
139
|
-
// if (newOps.length === 0) return;
|
|
140
|
-
// const isEditTextFieldOp = (op: EditOperation) => {
|
|
141
|
-
// if (op.type !== "edit-field") return false;
|
|
142
|
-
// const editFieldOp = op as EditFieldOperation;
|
|
143
|
-
// return (
|
|
144
|
-
// editFieldOp.fieldType &&
|
|
145
|
-
// editFieldOp.fieldType.indexOf("text") !== -1
|
|
146
|
-
// );
|
|
147
|
-
// };
|
|
148
|
-
// const isEditTextField = isEditTextFieldOp(newOps[newOps.length - 1]);
|
|
149
|
-
// if (isEditTextField) lastOpIndex = response.editOperations.length - 1;
|
|
150
|
-
// else lastOpIndex = response.editOperations.length;
|
|
151
|
-
// newOps.forEach((op: EditOperation) => {
|
|
152
|
-
// if (isEditTextFieldOp(op)) {
|
|
153
|
-
// const editFieldOp = op as EditFieldOperation;
|
|
154
|
-
// if (editFieldOp.itemId) {
|
|
155
|
-
// const fieldDescriptor = {
|
|
156
|
-
// item: {
|
|
157
|
-
// ...editFieldOp.mainItem,
|
|
158
|
-
// id: editFieldOp.itemId,
|
|
159
|
-
// },
|
|
160
|
-
// fieldId: editFieldOp.fieldId,
|
|
161
|
-
// };
|
|
162
|
-
// editContext.itemsRepository.updateFieldValue(
|
|
163
|
-
// fieldDescriptor,
|
|
164
|
-
// editFieldOp.user ?? { name: "unknown", ai: false },
|
|
165
|
-
// false,
|
|
166
|
-
// editFieldOp.value,
|
|
167
|
-
// );
|
|
168
|
-
// editContext.select([editFieldOp.itemId]);
|
|
169
|
-
// editContext.setScrollIntoView(editFieldOp.itemId);
|
|
170
|
-
// editContext?.setFocusedField(fieldDescriptor, false);
|
|
171
|
-
// }
|
|
172
|
-
// } else {
|
|
173
|
-
// const addOp = op as AddComponentOperation;
|
|
174
|
-
// if (op.type === "add-component" && addOp.componentId) {
|
|
175
|
-
// const newComponentId = addOp.componentId;
|
|
176
|
-
// editContext.select([newComponentId]);
|
|
177
|
-
// editContext.setScrollIntoView(newComponentId);
|
|
178
|
-
// }
|
|
179
|
-
// }
|
|
180
|
-
// });
|
|
181
|
-
// }
|
|
182
208
|
});
|
|
183
209
|
if (response) {
|
|
184
210
|
handleResponse(response, callback, true);
|
|
@@ -201,11 +227,12 @@ export function AiTerminal({ closeButton, createAiContext, defaultProfile, optio
|
|
|
201
227
|
TerminalService.off("command", commandHandler);
|
|
202
228
|
};
|
|
203
229
|
}, []);
|
|
204
|
-
return (_jsx("div", { className: "relative flex h-full flex-1 flex-col
|
|
230
|
+
return (_jsx("div", { className: "relative flex h-full flex-1 flex-col", "data-testid": "ai-terminal", children: _jsxs("div", { className: "relative flex-1", children: [_jsx("div", { className: "tour-ai-terminal absolute inset-0", children: _jsx(Terminal, { disabled: !model, ref: terminalRef, onReset: () => {
|
|
205
231
|
setMessages([]);
|
|
206
232
|
setResponseMessages([]);
|
|
207
233
|
setResponse(undefined);
|
|
208
|
-
|
|
234
|
+
setInitialTerminalMessages(undefined);
|
|
235
|
+
}, initialMessages: initialTerminalMessages, infobar: response?.numInputTokens && (_jsxs("div", { className: "text-right text-gray-400", style: { fontSize: "10px" }, children: ["Tokens in: ", response?.numInputTokens?.toLocaleString(), " out:", " ", response?.numOutputTokens?.toLocaleString(), " ", response?.numCachedTokens
|
|
209
236
|
? `cached: ${response?.numCachedTokens?.toLocaleString()} `
|
|
210
237
|
: "", response?.state] })), prompt: prompt, setPrompt: setPrompt, statusbar: _jsxs("div", { className: "flex flex-1 items-center justify-between gap-1", children: [_jsxs("a", { className: "ml-1 flex cursor-pointer items-center gap-1 text-xs", onClick: () => {
|
|
211
238
|
setShowPredefined(!showPredefined);
|
|
@@ -219,84 +246,4 @@ export function AiTerminal({ closeButton, createAiContext, defaultProfile, optio
|
|
|
219
246
|
commandHandler(v, callback);
|
|
220
247
|
} }) }), activeProfile?.errorMessage && (_jsx("div", { className: "absolute inset-0 grid items-center justify-center p-2 text-sm text-red-500", children: activeProfile?.errorMessage })), !model && (_jsx("div", { className: "absolute inset-0 grid items-center justify-center text-sm text-gray-400", children: !activeProfile ? "No profile selected" : "No model selected" }))] }) }));
|
|
221
248
|
}
|
|
222
|
-
async function executePrompt(profileId, messages, selection, session, model, selectedText, context, agentId, callback) {
|
|
223
|
-
const response = await fetch(context.endpoint, {
|
|
224
|
-
method: "POST",
|
|
225
|
-
body: JSON.stringify({
|
|
226
|
-
...context.promptData,
|
|
227
|
-
profileId,
|
|
228
|
-
messages,
|
|
229
|
-
selection,
|
|
230
|
-
addSelectedComponents: true,
|
|
231
|
-
selectedText,
|
|
232
|
-
model,
|
|
233
|
-
sessionId: session,
|
|
234
|
-
agentId,
|
|
235
|
-
}),
|
|
236
|
-
credentials: "include",
|
|
237
|
-
headers: {
|
|
238
|
-
"Content-Type": "application/json",
|
|
239
|
-
Cookie: new Cookies().getAll(),
|
|
240
|
-
},
|
|
241
|
-
});
|
|
242
|
-
if (!response.ok) {
|
|
243
|
-
const text = await response.text();
|
|
244
|
-
return {
|
|
245
|
-
messages: [
|
|
246
|
-
{
|
|
247
|
-
content: "There was an error processing your request: " + text,
|
|
248
|
-
id: 0,
|
|
249
|
-
name: "assistant",
|
|
250
|
-
role: "assistant",
|
|
251
|
-
},
|
|
252
|
-
],
|
|
253
|
-
editOperations: [],
|
|
254
|
-
numInputTokens: 0,
|
|
255
|
-
numOutputTokens: 0,
|
|
256
|
-
numCachedTokens: 0,
|
|
257
|
-
state: "error",
|
|
258
|
-
};
|
|
259
|
-
}
|
|
260
|
-
if (!response?.body)
|
|
261
|
-
return null;
|
|
262
|
-
const reader = response.body.getReader();
|
|
263
|
-
const decoder = new TextDecoder();
|
|
264
|
-
let buffer = "";
|
|
265
|
-
let result = null;
|
|
266
|
-
while (true) {
|
|
267
|
-
const { done, value } = await reader.read();
|
|
268
|
-
if (done) {
|
|
269
|
-
break;
|
|
270
|
-
}
|
|
271
|
-
buffer += decoder.decode(value, { stream: true }); // 'stream: true' ensures that any incomplete multi-byte characters aren't malformed.
|
|
272
|
-
// Split the buffer by newline and keep the last partial line for the next iteration.
|
|
273
|
-
const lines = buffer.split("\n");
|
|
274
|
-
if (lines.length > 0) {
|
|
275
|
-
buffer = lines.pop() || ""; // Incomplete line (if any) is kept for the next iteration.
|
|
276
|
-
for (let line of lines) {
|
|
277
|
-
if (line.trim() === "")
|
|
278
|
-
continue; // Skip empty lines if any.
|
|
279
|
-
try {
|
|
280
|
-
const jsonData = JSON.parse(line);
|
|
281
|
-
callback(jsonData);
|
|
282
|
-
result = jsonData;
|
|
283
|
-
}
|
|
284
|
-
catch (e) {
|
|
285
|
-
console.error("Error parsing line:" + line, e);
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
// If there's any remaining content in the buffer after processing all chunks, try to process it.
|
|
291
|
-
if (buffer.trim() !== "") {
|
|
292
|
-
try {
|
|
293
|
-
const jsonData = JSON.parse(buffer);
|
|
294
|
-
result = jsonData;
|
|
295
|
-
}
|
|
296
|
-
catch (e) {
|
|
297
|
-
console.error("Error parsing the final buffer content:", e);
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
return result;
|
|
301
|
-
}
|
|
302
249
|
//# sourceMappingURL=AiTerminal.js.map
|