@alpaca-editor/core 1.0.4065 → 1.0.4066
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/ImageEditButton.js +10 -3
- package/dist/editor/ImageEditButton.js.map +1 -1
- package/dist/editor/ai/AgentTerminal.d.ts +3 -2
- package/dist/editor/ai/AgentTerminal.js +386 -94
- package/dist/editor/ai/AgentTerminal.js.map +1 -1
- package/dist/editor/ai/Agents.js +36 -19
- package/dist/editor/ai/Agents.js.map +1 -1
- package/dist/editor/ai/AiResponseMessage.d.ts +6 -1
- package/dist/editor/ai/AiResponseMessage.js +63 -3
- package/dist/editor/ai/AiResponseMessage.js.map +1 -1
- package/dist/editor/ai/AiTerminal.js +27 -2
- package/dist/editor/ai/AiTerminal.js.map +1 -1
- package/dist/editor/client/EditorClient.js +15 -0
- package/dist/editor/client/EditorClient.js.map +1 -1
- package/dist/editor/client/editContext.d.ts +2 -0
- package/dist/editor/client/editContext.js.map +1 -1
- package/dist/editor/commands/componentCommands.js +56 -6
- package/dist/editor/commands/componentCommands.js.map +1 -1
- package/dist/editor/page-editor-chrome/CommentHighlighting.js +6 -4
- package/dist/editor/page-editor-chrome/CommentHighlighting.js.map +1 -1
- package/dist/editor/page-editor-chrome/CommentHighlightings.js +1 -1
- package/dist/editor/page-editor-chrome/CommentHighlightings.js.map +1 -1
- package/dist/editor/page-editor-chrome/FrameMenu.js +6 -8
- package/dist/editor/page-editor-chrome/FrameMenu.js.map +1 -1
- package/dist/editor/reviews/Comment.js +3 -58
- package/dist/editor/reviews/Comment.js.map +1 -1
- package/dist/editor/reviews/CommentDisplayPopover.js +2 -3
- package/dist/editor/reviews/CommentDisplayPopover.js.map +1 -1
- package/dist/editor/reviews/Comments.js +4 -0
- package/dist/editor/reviews/Comments.js.map +1 -1
- package/dist/editor/reviews/commentAi.d.ts +7 -0
- package/dist/editor/reviews/commentAi.js +86 -0
- package/dist/editor/reviews/commentAi.js.map +1 -0
- package/dist/revision.d.ts +2 -2
- package/dist/revision.js +2 -2
- package/dist/styles.css +10 -0
- package/package.json +1 -1
- package/src/editor/ImageEditButton.tsx +36 -8
- package/src/editor/ai/AgentTerminal.tsx +436 -65
- package/src/editor/ai/Agents.tsx +193 -140
- package/src/editor/ai/AiResponseMessage.tsx +106 -2
- package/src/editor/ai/AiTerminal.tsx +27 -0
- package/src/editor/client/EditorClient.tsx +23 -0
- package/src/editor/client/editContext.ts +2 -0
- package/src/editor/commands/componentCommands.tsx +60 -12
- package/src/editor/page-editor-chrome/CommentHighlighting.tsx +6 -4
- package/src/editor/page-editor-chrome/CommentHighlightings.tsx +3 -1
- package/src/editor/page-editor-chrome/FrameMenu.tsx +6 -8
- package/src/editor/reviews/Comment.tsx +4 -66
- package/src/editor/reviews/CommentDisplayPopover.tsx +2 -3
- package/src/editor/reviews/Comments.tsx +12 -0
- package/src/editor/reviews/commentAi.ts +106 -0
- package/src/revision.ts +2 -2
- package/dist/editor/ai/AiPromptPopover.d.ts +0 -7
- package/dist/editor/ai/AiPromptPopover.js +0 -111
- package/dist/editor/ai/AiPromptPopover.js.map +0 -1
- package/src/editor/ai/AiPromptPopover.tsx +0 -206
|
@@ -1,206 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
|
|
3
|
-
import { useState } from "react";
|
|
4
|
-
import { Sparkles, Send } from "lucide-react";
|
|
5
|
-
import {
|
|
6
|
-
Popover,
|
|
7
|
-
PopoverContent,
|
|
8
|
-
PopoverTrigger,
|
|
9
|
-
} from "../../components/ui/popover";
|
|
10
|
-
import { Button } from "../../components/ui/button";
|
|
11
|
-
import { Textarea } from "../../components/ui/textarea";
|
|
12
|
-
import { useEditContext } from "../client/editContext";
|
|
13
|
-
import { Component } from "../pageModel";
|
|
14
|
-
import { startAgent, StartAgentRequest } from "../services/agentService";
|
|
15
|
-
import { createEditorAiContext } from "./editorAiContext";
|
|
16
|
-
|
|
17
|
-
interface AiPromptPopoverProps {
|
|
18
|
-
children: React.ReactNode;
|
|
19
|
-
components?: Component[];
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export function AiPromptPopover({
|
|
23
|
-
children,
|
|
24
|
-
components = [],
|
|
25
|
-
}: AiPromptPopoverProps) {
|
|
26
|
-
const [isOpen, setIsOpen] = useState(false);
|
|
27
|
-
const [prompt, setPrompt] = useState("");
|
|
28
|
-
const editContext = useEditContext();
|
|
29
|
-
|
|
30
|
-
const handleSubmit = async () => {
|
|
31
|
-
if (!prompt.trim()) return;
|
|
32
|
-
|
|
33
|
-
// Close the popover
|
|
34
|
-
setIsOpen(false);
|
|
35
|
-
|
|
36
|
-
// Create comprehensive AI options with component context
|
|
37
|
-
let finalPrompt = prompt.trim();
|
|
38
|
-
let hiddenSystemPrompt: string | undefined;
|
|
39
|
-
|
|
40
|
-
if (components.length > 0) {
|
|
41
|
-
// Create detailed component context for the agent
|
|
42
|
-
const componentInfo = components
|
|
43
|
-
.map((comp) => {
|
|
44
|
-
const componentType = comp.type || comp.name || "Unknown";
|
|
45
|
-
const componentId = comp.id;
|
|
46
|
-
const hasContent = comp.items && comp.items.length > 0;
|
|
47
|
-
|
|
48
|
-
return `- ${componentType} (ID: ${componentId})${hasContent ? " with data" : " (empty)"}`;
|
|
49
|
-
})
|
|
50
|
-
.join("\n");
|
|
51
|
-
|
|
52
|
-
finalPrompt = `I'm working with the following ${components.length === 1 ? "component" : "components"}:
|
|
53
|
-
${componentInfo}
|
|
54
|
-
|
|
55
|
-
User request: ${prompt.trim()}`;
|
|
56
|
-
|
|
57
|
-
// Add hidden system prompt with component details for agent context
|
|
58
|
-
const componentDetails = components.map((comp) => ({
|
|
59
|
-
id: comp.id,
|
|
60
|
-
name: comp.name,
|
|
61
|
-
type: comp.type,
|
|
62
|
-
renderingId: comp.rendering?.id,
|
|
63
|
-
items: comp.items?.length || 0,
|
|
64
|
-
placeholder: comp.parentPlaceholder?.name,
|
|
65
|
-
isShared: comp.isShared,
|
|
66
|
-
}));
|
|
67
|
-
|
|
68
|
-
hiddenSystemPrompt = `Working with components: ${JSON.stringify(componentDetails, null, 2)}`;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
try {
|
|
72
|
-
await startAgentExecution(finalPrompt, hiddenSystemPrompt);
|
|
73
|
-
// Switch to agents view after agent has been created so it appears on initial load
|
|
74
|
-
editContext?.switchView("agents");
|
|
75
|
-
} catch (error) {
|
|
76
|
-
console.error("Failed to start agent:", error);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
// Reset the prompt
|
|
80
|
-
setPrompt("");
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
const startAgentExecution = async (
|
|
84
|
-
initialPrompt: string,
|
|
85
|
-
hiddenSystemPrompt?: string,
|
|
86
|
-
) => {
|
|
87
|
-
if (!editContext) return;
|
|
88
|
-
if (!editContext.currentItemDescriptor?.id) {
|
|
89
|
-
console.error("Cannot start agent: no current item selected");
|
|
90
|
-
return;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
const newAgentId = crypto.randomUUID();
|
|
94
|
-
|
|
95
|
-
const userMessage = {
|
|
96
|
-
id: crypto.randomUUID(),
|
|
97
|
-
content: initialPrompt,
|
|
98
|
-
role: "user",
|
|
99
|
-
name: "user",
|
|
100
|
-
};
|
|
101
|
-
|
|
102
|
-
const messages = [
|
|
103
|
-
...(hiddenSystemPrompt
|
|
104
|
-
? [
|
|
105
|
-
{
|
|
106
|
-
role: "system",
|
|
107
|
-
name: "system",
|
|
108
|
-
content: hiddenSystemPrompt,
|
|
109
|
-
id: crypto.randomUUID(),
|
|
110
|
-
},
|
|
111
|
-
]
|
|
112
|
-
: []),
|
|
113
|
-
userMessage,
|
|
114
|
-
];
|
|
115
|
-
|
|
116
|
-
const aiContext = createEditorAiContext({ editContext });
|
|
117
|
-
|
|
118
|
-
const startRequest: StartAgentRequest = {
|
|
119
|
-
agentId: newAgentId,
|
|
120
|
-
message: initialPrompt,
|
|
121
|
-
sessionId: editContext.sessionId,
|
|
122
|
-
profileId: "Editor",
|
|
123
|
-
itemid: editContext.currentItemDescriptor.id,
|
|
124
|
-
language: editContext.currentItemDescriptor?.language || "en",
|
|
125
|
-
version: editContext.currentItemDescriptor?.version || 1,
|
|
126
|
-
selection: components?.map((c) => c.id),
|
|
127
|
-
addSelectedComponents: components?.length > 0,
|
|
128
|
-
profile: "Editor",
|
|
129
|
-
};
|
|
130
|
-
|
|
131
|
-
await startAgent(startRequest);
|
|
132
|
-
// Agents view will reflect the new agent via its own refresh mechanisms
|
|
133
|
-
};
|
|
134
|
-
|
|
135
|
-
const handleKeyDown = (e: React.KeyboardEvent) => {
|
|
136
|
-
if (e.key === "Enter" && !e.shiftKey) {
|
|
137
|
-
e.preventDefault();
|
|
138
|
-
handleSubmit();
|
|
139
|
-
}
|
|
140
|
-
};
|
|
141
|
-
|
|
142
|
-
return (
|
|
143
|
-
<Popover
|
|
144
|
-
open={isOpen}
|
|
145
|
-
onOpenChange={setIsOpen}
|
|
146
|
-
enableIframeClickDetection={false}
|
|
147
|
-
>
|
|
148
|
-
<PopoverTrigger asChild>{children}</PopoverTrigger>
|
|
149
|
-
<PopoverContent
|
|
150
|
-
className="w-96 p-4"
|
|
151
|
-
side="bottom"
|
|
152
|
-
align="start"
|
|
153
|
-
onMouseDown={(e) => e.stopPropagation()}
|
|
154
|
-
onClick={(e) => e.stopPropagation()}
|
|
155
|
-
>
|
|
156
|
-
<div className="space-y-3">
|
|
157
|
-
<div className="flex items-center gap-2">
|
|
158
|
-
<Sparkles size={16} strokeWidth={1} className="text-blue-500" />
|
|
159
|
-
<h3 className="font-medium">AI Assistant</h3>
|
|
160
|
-
</div>
|
|
161
|
-
|
|
162
|
-
<div className="space-y-2">
|
|
163
|
-
<label htmlFor="ai-prompt" className="text-sm text-gray-700">
|
|
164
|
-
What would you like AI to help you with?
|
|
165
|
-
{components.length > 0 && (
|
|
166
|
-
<span className="mt-1 block text-xs text-gray-500">
|
|
167
|
-
Working with {components.length} selected component
|
|
168
|
-
{components.length === 1 ? "" : "s"}
|
|
169
|
-
</span>
|
|
170
|
-
)}
|
|
171
|
-
</label>
|
|
172
|
-
<Textarea
|
|
173
|
-
id="ai-prompt"
|
|
174
|
-
value={prompt}
|
|
175
|
-
onChange={(e) => setPrompt(e.target.value)}
|
|
176
|
-
onKeyDown={handleKeyDown}
|
|
177
|
-
placeholder="Enter your prompt here..."
|
|
178
|
-
className="mt-2 resize-none"
|
|
179
|
-
rows={3}
|
|
180
|
-
autoFocus
|
|
181
|
-
/>
|
|
182
|
-
</div>
|
|
183
|
-
|
|
184
|
-
<div className="flex justify-end gap-2">
|
|
185
|
-
<Button
|
|
186
|
-
variant="outline"
|
|
187
|
-
size="sm"
|
|
188
|
-
onClick={() => setIsOpen(false)}
|
|
189
|
-
>
|
|
190
|
-
Cancel
|
|
191
|
-
</Button>
|
|
192
|
-
<Button
|
|
193
|
-
size="sm"
|
|
194
|
-
onClick={handleSubmit}
|
|
195
|
-
disabled={!prompt.trim()}
|
|
196
|
-
className="flex items-center gap-1"
|
|
197
|
-
>
|
|
198
|
-
<Send size={14} strokeWidth={1} />
|
|
199
|
-
Start Agent
|
|
200
|
-
</Button>
|
|
201
|
-
</div>
|
|
202
|
-
</div>
|
|
203
|
-
</PopoverContent>
|
|
204
|
-
</Popover>
|
|
205
|
-
);
|
|
206
|
-
}
|