@alpaca-editor/core 1.0.3942 → 1.0.3943
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/.prettierrc +3 -0
- package/build.css +3 -0
- package/components.json +21 -0
- package/dist/editor/ContentTree.d.ts +2 -1
- package/dist/editor/ContentTree.js +23 -21
- package/dist/editor/ContentTree.js.map +1 -1
- package/dist/editor/FieldActionsOverlay.js +0 -2
- package/dist/editor/FieldActionsOverlay.js.map +1 -1
- package/dist/editor/ScrollingContentTree.js +1 -1
- package/dist/editor/ScrollingContentTree.js.map +1 -1
- package/dist/editor/Titlebar.js +1 -1
- package/dist/editor/Titlebar.js.map +1 -1
- package/dist/editor/ai/GhostWriter.js +24 -3
- package/dist/editor/ai/GhostWriter.js.map +1 -1
- package/dist/editor/client/EditorClient.js +7 -7
- package/dist/editor/client/EditorClient.js.map +1 -1
- package/dist/editor/field-types/InternalLinkFieldEditor.js +60 -10
- package/dist/editor/field-types/InternalLinkFieldEditor.js.map +1 -1
- package/dist/editor/media-selector/MediaFolderBrowser.js +48 -1
- package/dist/editor/media-selector/MediaFolderBrowser.js.map +1 -1
- package/dist/editor/menubar/PageSelector.js +116 -65
- package/dist/editor/menubar/PageSelector.js.map +1 -1
- package/dist/editor/page-viewer/EditorForm.js +5 -2
- package/dist/editor/page-viewer/EditorForm.js.map +1 -1
- package/dist/editor/ui/ItemSearch.js +14 -8
- package/dist/editor/ui/ItemSearch.js.map +1 -1
- package/dist/editor/ui/PerfectTree.d.ts +4 -2
- package/dist/editor/ui/PerfectTree.js +78 -4
- package/dist/editor/ui/PerfectTree.js.map +1 -1
- package/dist/editor/ui/Splitter.js +1 -1
- package/dist/revision.d.ts +2 -2
- package/dist/revision.js +2 -2
- package/dist/styles.css +8 -2
- package/eslint.config.mjs +4 -0
- package/images/bg-shape-black.webp +0 -0
- package/images/wizard-bg.png +0 -0
- package/images/wizard-tour.png +0 -0
- package/images/wizard.png +0 -0
- package/package.json +2 -8
- package/src/client-components/api.ts +6 -0
- package/src/client-components/index.ts +19 -0
- package/src/components/ActionButton.tsx +50 -0
- package/src/components/Error.tsx +57 -0
- package/src/components/ui/CardConnector.tsx +56 -0
- package/src/components/ui/button.tsx +62 -0
- package/src/components/ui/card.tsx +372 -0
- package/src/components/ui/context-menu.tsx +250 -0
- package/src/config/config.tsx +917 -0
- package/src/config/types.ts +286 -0
- package/src/editor/ComponentInfo.tsx +90 -0
- package/src/editor/ConfirmationDialog.tsx +103 -0
- package/src/editor/ContentTree.tsx +733 -0
- package/src/editor/ContextMenu.tsx +230 -0
- package/src/editor/Editor.tsx +90 -0
- package/src/editor/EditorWarning.tsx +34 -0
- package/src/editor/EditorWarnings.tsx +33 -0
- package/src/editor/FieldActionsOverlay.tsx +296 -0
- package/src/editor/FieldEditorPopup.tsx +65 -0
- package/src/editor/FieldHistory.tsx +75 -0
- package/src/editor/FieldList.tsx +190 -0
- package/src/editor/FieldListField.tsx +391 -0
- package/src/editor/FieldListFieldWithFallbacks.tsx +217 -0
- package/src/editor/FloatingToolbar.tsx +163 -0
- package/src/editor/ImageEditor.tsx +128 -0
- package/src/editor/ItemInfo.tsx +90 -0
- package/src/editor/LinkEditorDialog.tsx +196 -0
- package/src/editor/MainLayout.tsx +95 -0
- package/src/editor/MobileLayout.tsx +68 -0
- package/src/editor/NewEditorClient.tsx +11 -0
- package/src/editor/PictureCropper.tsx +568 -0
- package/src/editor/PictureEditor.tsx +301 -0
- package/src/editor/PictureEditorDialog.tsx +381 -0
- package/src/editor/PublishDialog.ignore +74 -0
- package/src/editor/ScrollingContentTree.tsx +68 -0
- package/src/editor/Terminal.tsx +227 -0
- package/src/editor/Titlebar.tsx +104 -0
- package/src/editor/ai/AiPopup.tsx +59 -0
- package/src/editor/ai/AiResponseMessage.tsx +106 -0
- package/src/editor/ai/AiTerminal.tsx +503 -0
- package/src/editor/ai/AiToolCall.tsx +61 -0
- package/src/editor/ai/EditorAiTerminal.tsx +20 -0
- package/src/editor/ai/GhostWriter.tsx +480 -0
- package/src/editor/ai/aiPageModel.ts +108 -0
- package/src/editor/ai/editorAiContext.ts +18 -0
- package/src/editor/client/AboutDialog.tsx +44 -0
- package/src/editor/client/EditorClient.tsx +2241 -0
- package/src/editor/client/GenericDialog.tsx +50 -0
- package/src/editor/client/editContext.ts +416 -0
- package/src/editor/client/helpers.ts +44 -0
- package/src/editor/client/itemsRepository.ts +574 -0
- package/src/editor/client/operations.ts +768 -0
- package/src/editor/client/pageModelBuilder.ts +219 -0
- package/src/editor/commands/commands.ts +22 -0
- package/src/editor/commands/componentCommands.tsx +431 -0
- package/src/editor/commands/createVersionCommand.ts +33 -0
- package/src/editor/commands/deleteVersionCommand.ts +71 -0
- package/src/editor/commands/itemCommands.tsx +351 -0
- package/src/editor/commands/localizeItem/LocalizeItemDialog.tsx +201 -0
- package/src/editor/commands/localizeItem/LocalizeItemUtils.ts +27 -0
- package/src/editor/commands/undo.ts +39 -0
- package/src/editor/component-designer/ComponentDesigner.tsx +70 -0
- package/src/editor/component-designer/ComponentDesignerAiTerminal.tsx +11 -0
- package/src/editor/component-designer/ComponentDesignerMenu.tsx +91 -0
- package/src/editor/component-designer/ComponentEditor.tsx +97 -0
- package/src/editor/component-designer/ComponentRenderingCodeEditor.tsx +31 -0
- package/src/editor/component-designer/ComponentRenderingEditor.tsx +104 -0
- package/src/editor/component-designer/ComponentsDropdown.tsx +39 -0
- package/src/editor/component-designer/PlaceholdersEditor.tsx +179 -0
- package/src/editor/component-designer/RenderingsDropdown.tsx +36 -0
- package/src/editor/component-designer/TemplateEditor.tsx +236 -0
- package/src/editor/component-designer/aiContext.ts +23 -0
- package/src/editor/componentTreeHelper.tsx +116 -0
- package/src/editor/context-menu/CopyMoveMenu.tsx +103 -0
- package/src/editor/context-menu/InsertMenu.tsx +347 -0
- package/src/editor/control-center/About.tsx +342 -0
- package/src/editor/control-center/ControlCenterMenu.tsx +76 -0
- package/src/editor/control-center/IndexOverview.tsx +50 -0
- package/src/editor/control-center/IndexSettings.tsx +266 -0
- package/src/editor/control-center/Info.tsx +104 -0
- package/src/editor/control-center/QuotaInfo.tsx +301 -0
- package/src/editor/control-center/Status.tsx +113 -0
- package/src/editor/control-center/WebSocketMessages.tsx +155 -0
- package/src/editor/editor-warnings/ItemLocked.tsx +63 -0
- package/src/editor/editor-warnings/NoLanguageWriteAccess.tsx +22 -0
- package/src/editor/editor-warnings/NoWorkflowWriteAccess.tsx +23 -0
- package/src/editor/editor-warnings/NoWriteAccess.tsx +16 -0
- package/src/editor/editor-warnings/ValidationErrors.tsx +54 -0
- package/src/editor/field-types/AttachmentEditor.tsx +9 -0
- package/src/editor/field-types/CheckboxEditor.tsx +47 -0
- package/src/editor/field-types/DropLinkEditor.tsx +80 -0
- package/src/editor/field-types/DropListEditor.tsx +84 -0
- package/src/editor/field-types/ImageFieldEditor.tsx +65 -0
- package/src/editor/field-types/InternalLinkFieldEditor.tsx +188 -0
- package/src/editor/field-types/LinkFieldEditor.tsx +85 -0
- package/src/editor/field-types/MultiLineText.tsx +82 -0
- package/src/editor/field-types/PictureFieldEditor.tsx +121 -0
- package/src/editor/field-types/RawEditor.tsx +53 -0
- package/src/editor/field-types/ReactQuill.tsx +580 -0
- package/src/editor/field-types/RichTextEditor.tsx +22 -0
- package/src/editor/field-types/RichTextEditorComponent.tsx +127 -0
- package/src/editor/field-types/SingleLineText.tsx +174 -0
- package/src/editor/field-types/TreeListEditor.tsx +261 -0
- package/src/editor/fieldTypes.ts +140 -0
- package/src/editor/media-selector/AiImageSearch.tsx +185 -0
- package/src/editor/media-selector/AiImageSearchPrompt.tsx +94 -0
- package/src/editor/media-selector/MediaFolderBrowser.tsx +321 -0
- package/src/editor/media-selector/MediaSelector.tsx +42 -0
- package/src/editor/media-selector/Preview.tsx +14 -0
- package/src/editor/media-selector/Thumbnails.tsx +48 -0
- package/src/editor/media-selector/TreeSelector.tsx +292 -0
- package/src/editor/media-selector/UploadZone.tsx +137 -0
- package/src/editor/media-selector/index.ts +8 -0
- package/src/editor/menubar/ActionsMenu.tsx +94 -0
- package/src/editor/menubar/ActiveUsers.tsx +17 -0
- package/src/editor/menubar/ApproveAndPublish.tsx +18 -0
- package/src/editor/menubar/BrowseHistory.tsx +28 -0
- package/src/editor/menubar/ItemLanguageVersion.tsx +76 -0
- package/src/editor/menubar/LanguageSelector.tsx +226 -0
- package/src/editor/menubar/Menu.tsx +83 -0
- package/src/editor/menubar/NavButtons.tsx +74 -0
- package/src/editor/menubar/PageSelector.tsx +278 -0
- package/src/editor/menubar/PageViewerControls.tsx +120 -0
- package/src/editor/menubar/PreviewSecondaryControls.tsx +18 -0
- package/src/editor/menubar/SecondaryControls.tsx +45 -0
- package/src/editor/menubar/Separator.tsx +12 -0
- package/src/editor/menubar/SiteInfo.tsx +53 -0
- package/src/editor/menubar/User.tsx +27 -0
- package/src/editor/menubar/VersionSelector.tsx +142 -0
- package/src/editor/page-editor-chrome/CommentHighlighting.tsx +307 -0
- package/src/editor/page-editor-chrome/CommentHighlightings.tsx +35 -0
- package/src/editor/page-editor-chrome/FieldActionIndicator.tsx +59 -0
- package/src/editor/page-editor-chrome/FieldActionIndicators.tsx +23 -0
- package/src/editor/page-editor-chrome/FieldEditedIndicator.tsx +64 -0
- package/src/editor/page-editor-chrome/FieldEditedIndicators.tsx +35 -0
- package/src/editor/page-editor-chrome/FrameMenu.tsx +338 -0
- package/src/editor/page-editor-chrome/FrameMenus.tsx +48 -0
- package/src/editor/page-editor-chrome/InlineEditor.tsx +765 -0
- package/src/editor/page-editor-chrome/LockedFieldIndicator.tsx +61 -0
- package/src/editor/page-editor-chrome/NoLayout.tsx +36 -0
- package/src/editor/page-editor-chrome/PageEditorChrome.tsx +122 -0
- package/src/editor/page-editor-chrome/PictureEditorOverlay.tsx +161 -0
- package/src/editor/page-editor-chrome/PlaceholderDropZone.tsx +169 -0
- package/src/editor/page-editor-chrome/PlaceholderDropZones.tsx +315 -0
- package/src/editor/page-editor-chrome/SuggestionHighlighting.tsx +300 -0
- package/src/editor/page-editor-chrome/SuggestionHighlightings.tsx +40 -0
- package/src/editor/page-editor-chrome/useInlineAICompletion.tsx +828 -0
- package/src/editor/page-viewer/DeviceToolbar.tsx +70 -0
- package/src/editor/page-viewer/EditorForm.tsx +262 -0
- package/src/editor/page-viewer/MiniMap.tsx +362 -0
- package/src/editor/page-viewer/PageViewer.tsx +169 -0
- package/src/editor/page-viewer/PageViewerFrame.tsx +1022 -0
- package/src/editor/page-viewer/pageModelSkeletonBuilder.ts +412 -0
- package/src/editor/page-viewer/pageViewContext.ts +186 -0
- package/src/editor/pageModel.ts +220 -0
- package/src/editor/picture-shared.tsx +53 -0
- package/src/editor/reviews/Comment.tsx +308 -0
- package/src/editor/reviews/Comments.tsx +125 -0
- package/src/editor/reviews/DiffView.tsx +109 -0
- package/src/editor/reviews/PreviewInfo.tsx +35 -0
- package/src/editor/reviews/Reviews.tsx +280 -0
- package/src/editor/reviews/SuggestedEdit.tsx +316 -0
- package/src/editor/reviews/reviewCommands.tsx +47 -0
- package/src/editor/reviews/useReviews.tsx +70 -0
- package/src/editor/services/aiService.ts +173 -0
- package/src/editor/services/componentDesignerService.ts +151 -0
- package/src/editor/services/contentService.ts +180 -0
- package/src/editor/services/editService.ts +488 -0
- package/src/editor/services/indexService.ts +24 -0
- package/src/editor/services/reviewsService.ts +53 -0
- package/src/editor/services/serviceHelper.ts +95 -0
- package/src/editor/services/suggestedEditsService.ts +39 -0
- package/src/editor/services/systemService.ts +5 -0
- package/src/editor/services/translationService.ts +21 -0
- package/src/editor/services-server/api.ts +150 -0
- package/src/editor/services-server/graphQL.ts +106 -0
- package/src/editor/sidebar/ComponentPalette.tsx +161 -0
- package/src/editor/sidebar/ComponentTree.tsx +549 -0
- package/src/editor/sidebar/Debug.tsx +111 -0
- package/src/editor/sidebar/DictionaryEditor.tsx +261 -0
- package/src/editor/sidebar/EditHistory.tsx +134 -0
- package/src/editor/sidebar/GraphQL.tsx +164 -0
- package/src/editor/sidebar/Insert.tsx +35 -0
- package/src/editor/sidebar/MainContentTree.tsx +102 -0
- package/src/editor/sidebar/Performance.tsx +53 -0
- package/src/editor/sidebar/Sessions.tsx +35 -0
- package/src/editor/sidebar/Sidebar.tsx +20 -0
- package/src/editor/sidebar/SidebarView.tsx +152 -0
- package/src/editor/sidebar/Translations.tsx +295 -0
- package/src/editor/sidebar/Validation.tsx +102 -0
- package/src/editor/sidebar/ViewSelector.tsx +60 -0
- package/src/editor/sidebar/Workbox.tsx +209 -0
- package/src/editor/ui/CenteredMessage.tsx +7 -0
- package/src/editor/ui/CopyMoveTargetSelectorDialog.tsx +81 -0
- package/src/editor/ui/CopyToClipboardButton.tsx +24 -0
- package/src/editor/ui/DialogButtons.tsx +11 -0
- package/src/editor/ui/Icons.tsx +709 -0
- package/src/editor/ui/ItemList.tsx +76 -0
- package/src/editor/ui/ItemNameDialogNew.tsx +118 -0
- package/src/editor/ui/ItemSearch.tsx +159 -0
- package/src/editor/ui/PerfectTree.tsx +676 -0
- package/src/editor/ui/Section.tsx +35 -0
- package/src/editor/ui/SimpleIconButton.tsx +54 -0
- package/src/editor/ui/SimpleMenu.tsx +40 -0
- package/src/editor/ui/SimpleTable.tsx +60 -0
- package/src/editor/ui/SimpleTabs.tsx +60 -0
- package/src/editor/ui/SimpleToolbar.tsx +7 -0
- package/src/editor/ui/Spinner.tsx +9 -0
- package/src/editor/ui/Splitter.tsx +420 -0
- package/src/editor/ui/StackedPanels.tsx +134 -0
- package/src/editor/ui/Toolbar.tsx +7 -0
- package/src/editor/utils/id-helper.ts +3 -0
- package/src/editor/utils/insertOptions.ts +69 -0
- package/src/editor/utils/itemutils.ts +29 -0
- package/src/editor/utils/useMemoDebug.ts +28 -0
- package/src/editor/utils.ts +486 -0
- package/src/editor/views/CompareView.tsx +245 -0
- package/src/editor/views/EditView.tsx +27 -0
- package/src/editor/views/ItemEditor.tsx +58 -0
- package/src/editor/views/MediaFolderEditView.tsx +66 -0
- package/src/editor/views/SingleEditView.tsx +57 -0
- package/src/fonts/Geist-Black.woff2 +0 -0
- package/src/fonts/Geist-Bold.woff2 +0 -0
- package/src/fonts/Geist-ExtraBold.woff2 +0 -0
- package/src/fonts/Geist-ExtraLight.woff2 +0 -0
- package/src/fonts/Geist-Light.woff2 +0 -0
- package/src/fonts/Geist-Medium.woff2 +0 -0
- package/src/fonts/Geist-Regular.woff2 +0 -0
- package/src/fonts/Geist-SemiBold.woff2 +0 -0
- package/src/fonts/Geist-Thin.woff2 +0 -0
- package/src/fonts/Geist[wght].woff2 +0 -0
- package/src/fonts/index.ts +10 -0
- package/src/index.ts +23 -0
- package/src/lib/safelist.tsx +16 -0
- package/src/lib/utils.ts +6 -0
- package/src/page-wizard/PageWizard.tsx +139 -0
- package/src/page-wizard/WizardBox.tsx +4 -0
- package/src/page-wizard/WizardBoxConnector.tsx +56 -0
- package/src/page-wizard/WizardSteps.tsx +458 -0
- package/src/page-wizard/service.ts +35 -0
- package/src/page-wizard/startPageWizardCommand.ts +26 -0
- package/src/page-wizard/steps/BuildPageStep.tsx +259 -0
- package/src/page-wizard/steps/CollectStep.tsx +296 -0
- package/src/page-wizard/steps/ComponentTypesSelector.tsx +454 -0
- package/src/page-wizard/steps/Components.tsx +193 -0
- package/src/page-wizard/steps/ContentStep.tsx +890 -0
- package/src/page-wizard/steps/EditButton.tsx +34 -0
- package/src/page-wizard/steps/FieldEditor.tsx +102 -0
- package/src/page-wizard/steps/Generate.tsx +60 -0
- package/src/page-wizard/steps/ImagesStep.tsx +382 -0
- package/src/page-wizard/steps/LayoutStep.tsx +227 -0
- package/src/page-wizard/steps/MetaDataStep.tsx +173 -0
- package/src/page-wizard/steps/SelectStep.tsx +281 -0
- package/src/page-wizard/steps/schema.ts +180 -0
- package/src/page-wizard/steps/usePageCreator.ts +325 -0
- package/src/page-wizard/usePageWizard.ts +79 -0
- package/src/revision.ts +2 -0
- package/src/splash-screen/NewPage.tsx +294 -0
- package/src/splash-screen/OpenPage.tsx +113 -0
- package/src/splash-screen/RecentPages.tsx +123 -0
- package/src/splash-screen/SectionHeadline.tsx +21 -0
- package/src/splash-screen/SplashScreen.tsx +195 -0
- package/src/tour/Tour.tsx +566 -0
- package/src/tour/default-tour.tsx +301 -0
- package/src/tour/preview-tour.tsx +128 -0
- package/src/types.ts +335 -0
- package/styles.css +765 -0
- package/tsconfig.build.json +31 -0
- package/tsconfig.json +14 -0
|
@@ -0,0 +1,503 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { useEffect, useRef, useState } from "react";
|
|
4
|
+
|
|
5
|
+
import { TerminalService } from "primereact/terminalservice";
|
|
6
|
+
|
|
7
|
+
import { Terminal } from "../Terminal";
|
|
8
|
+
import { useEditContext } from "../client/editContext";
|
|
9
|
+
import { Dropdown } from "primereact/dropdown";
|
|
10
|
+
|
|
11
|
+
import Cookies from "universal-cookie";
|
|
12
|
+
import { WizardIcon } from "../ui/Icons";
|
|
13
|
+
import { AiResponseMessage } from "./AiResponseMessage";
|
|
14
|
+
import { AiProfile, loadAiProfiles } from "../services/aiService";
|
|
15
|
+
import { EditOperation } from "../../types";
|
|
16
|
+
import { SimpleIconButton } from "../ui/SimpleIconButton";
|
|
17
|
+
|
|
18
|
+
type Response = {
|
|
19
|
+
messages: Message[];
|
|
20
|
+
editOperations: EditOperation[];
|
|
21
|
+
numInputTokens: number;
|
|
22
|
+
numOutputTokens: number;
|
|
23
|
+
numCachedTokens: number;
|
|
24
|
+
state: string;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export type ToolCall = {
|
|
28
|
+
id: string;
|
|
29
|
+
displayName: string;
|
|
30
|
+
function: {
|
|
31
|
+
name: string;
|
|
32
|
+
arguments: string;
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export type Message = {
|
|
37
|
+
id: number;
|
|
38
|
+
content: string;
|
|
39
|
+
formattedContent?: string;
|
|
40
|
+
name: string;
|
|
41
|
+
role: string;
|
|
42
|
+
tool_calls?: ToolCall[];
|
|
43
|
+
tool_call_id?: string;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export type AiContext = {
|
|
47
|
+
promptData: any;
|
|
48
|
+
endpoint: string;
|
|
49
|
+
callback?: (response: Response) => void;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export type AiTerminalOptions = {
|
|
53
|
+
initialPrompt?: string;
|
|
54
|
+
hiddenSystemPrompt?: string;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
export function AiTerminal({
|
|
58
|
+
closeButton,
|
|
59
|
+
createAiContext,
|
|
60
|
+
defaultProfile,
|
|
61
|
+
options,
|
|
62
|
+
}: {
|
|
63
|
+
closeButton?: React.ReactNode;
|
|
64
|
+
createAiContext: ({ editContext }: { editContext: any }) => AiContext;
|
|
65
|
+
defaultProfile?: string;
|
|
66
|
+
options?: AiTerminalOptions;
|
|
67
|
+
}) {
|
|
68
|
+
const editContext = useEditContext();
|
|
69
|
+
const [showPredefined, setShowPredefined] = useState(false);
|
|
70
|
+
|
|
71
|
+
if (!editContext) return null;
|
|
72
|
+
|
|
73
|
+
const [messages, setMessages] = useState<Message[]>([]);
|
|
74
|
+
const [response, setResponse] = useState<Response>();
|
|
75
|
+
const [model, setModel] = useState<string>();
|
|
76
|
+
const [prompt, setPrompt] = useState("");
|
|
77
|
+
const [profiles, setProfiles] = useState<AiProfile[]>([]);
|
|
78
|
+
const [activeProfile, setActiveProfile] = useState<AiProfile>();
|
|
79
|
+
const [initialPromptExecuted, setInitialPromptExecuted] = useState(false);
|
|
80
|
+
const selection = editContext.selection;
|
|
81
|
+
const terminalRef = useRef<{ submit: () => void }>(null);
|
|
82
|
+
const [responseMessages, setResponseMessages] = useState<Message[]>([]);
|
|
83
|
+
|
|
84
|
+
useEffect(() => {
|
|
85
|
+
if (options?.initialPrompt && !initialPromptExecuted && model) {
|
|
86
|
+
// Set the initial prompt text into the terminal's state.
|
|
87
|
+
console.log("setting prompt", options.initialPrompt);
|
|
88
|
+
setPrompt(options.initialPrompt);
|
|
89
|
+
setInitialPromptExecuted(true);
|
|
90
|
+
// Wait for the Terminal to update, then programmatically submit.
|
|
91
|
+
setTimeout(() => {
|
|
92
|
+
terminalRef.current?.submit();
|
|
93
|
+
}, 100);
|
|
94
|
+
}
|
|
95
|
+
}, [options?.initialPrompt, initialPromptExecuted, model]);
|
|
96
|
+
|
|
97
|
+
useEffect(() => {
|
|
98
|
+
async function fetchProfiles() {
|
|
99
|
+
if (!editContext?.currentItemDescriptor) return;
|
|
100
|
+
const profiles = await loadAiProfiles(editContext.currentItemDescriptor);
|
|
101
|
+
setProfiles(profiles);
|
|
102
|
+
if (!activeProfile)
|
|
103
|
+
setActiveProfile(
|
|
104
|
+
profiles.find((x) => x.name == defaultProfile) || profiles[0],
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
fetchProfiles();
|
|
108
|
+
}, [editContext?.currentItemDescriptor]);
|
|
109
|
+
|
|
110
|
+
useEffect(() => {
|
|
111
|
+
if (activeProfile?.defaultModel) setModel(activeProfile.defaultModel);
|
|
112
|
+
}, [activeProfile]);
|
|
113
|
+
|
|
114
|
+
const messagesRef = useRef(messages);
|
|
115
|
+
useEffect(() => {
|
|
116
|
+
messagesRef.current = responseMessages;
|
|
117
|
+
}, [responseMessages]);
|
|
118
|
+
|
|
119
|
+
function handleResponse(
|
|
120
|
+
response: Response,
|
|
121
|
+
terminalCallback: (text: React.ReactNode, finished: boolean) => void,
|
|
122
|
+
isFinished: boolean,
|
|
123
|
+
) {
|
|
124
|
+
const updatedMessages = response.messages;
|
|
125
|
+
|
|
126
|
+
// Replace the conversation history with the authoritative response from AI
|
|
127
|
+
if (updatedMessages && Array.isArray(updatedMessages)) {
|
|
128
|
+
const formattedMessages = updatedMessages.map((message) => {
|
|
129
|
+
const formattedContent = message.content
|
|
130
|
+
.trim()
|
|
131
|
+
.replaceAll("\n", "<br>")
|
|
132
|
+
?.replace(/\*\*(.*?)\*\*/g, "<b>$1</b>");
|
|
133
|
+
|
|
134
|
+
return {
|
|
135
|
+
...message,
|
|
136
|
+
content: message.content,
|
|
137
|
+
formattedContent: formattedContent,
|
|
138
|
+
tool_calls: message.tool_calls || [],
|
|
139
|
+
};
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
// Update the messages state with the complete conversation from AI
|
|
143
|
+
setMessages([...formattedMessages]);
|
|
144
|
+
setResponseMessages([...formattedMessages]);
|
|
145
|
+
|
|
146
|
+
terminalCallback(
|
|
147
|
+
<AiResponseMessage
|
|
148
|
+
messages={formattedMessages}
|
|
149
|
+
editOperations={response.editOperations}
|
|
150
|
+
finished={isFinished}
|
|
151
|
+
/>,
|
|
152
|
+
isFinished,
|
|
153
|
+
);
|
|
154
|
+
} else {
|
|
155
|
+
// Fallback: if no messages in response, keep current state
|
|
156
|
+
terminalCallback(
|
|
157
|
+
<AiResponseMessage
|
|
158
|
+
messages={messagesRef.current}
|
|
159
|
+
editOperations={response.editOperations}
|
|
160
|
+
finished={isFinished}
|
|
161
|
+
/>,
|
|
162
|
+
isFinished,
|
|
163
|
+
);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
async function commandHandler(
|
|
168
|
+
text: string,
|
|
169
|
+
callback: (text: React.ReactNode, finished: boolean) => void,
|
|
170
|
+
) {
|
|
171
|
+
const userMessage = {
|
|
172
|
+
id: Date.now(), // Add unique id
|
|
173
|
+
content: text,
|
|
174
|
+
role: "user",
|
|
175
|
+
name: "user",
|
|
176
|
+
tool_calls: [], // Add empty toolCalls array
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
const context = createAiContext({ editContext });
|
|
180
|
+
|
|
181
|
+
let lastOpIndex = 0;
|
|
182
|
+
const selectedText = editContext?.selectedRange?.text || null;
|
|
183
|
+
if (!activeProfile || !model) return;
|
|
184
|
+
|
|
185
|
+
// Build complete message history for API call
|
|
186
|
+
const conversationHistory = [...messagesRef.current, userMessage];
|
|
187
|
+
const messages = [
|
|
188
|
+
...(options?.hiddenSystemPrompt
|
|
189
|
+
? [
|
|
190
|
+
{
|
|
191
|
+
role: "system",
|
|
192
|
+
name: "system",
|
|
193
|
+
content: options.hiddenSystemPrompt,
|
|
194
|
+
id: 0, // System message id
|
|
195
|
+
toolCalls: [],
|
|
196
|
+
},
|
|
197
|
+
]
|
|
198
|
+
: []),
|
|
199
|
+
...conversationHistory,
|
|
200
|
+
];
|
|
201
|
+
|
|
202
|
+
const response = await executePrompt(
|
|
203
|
+
activeProfile.id,
|
|
204
|
+
messages,
|
|
205
|
+
selection,
|
|
206
|
+
editContext!.sessionId,
|
|
207
|
+
model,
|
|
208
|
+
selectedText,
|
|
209
|
+
context,
|
|
210
|
+
(response: any) => {
|
|
211
|
+
setResponse(response);
|
|
212
|
+
handleResponse(response, callback, false);
|
|
213
|
+
// if (response.editOperations.length) {
|
|
214
|
+
// if (!editContext) return;
|
|
215
|
+
|
|
216
|
+
// const newOps = response.editOperations.slice(lastOpIndex);
|
|
217
|
+
|
|
218
|
+
// if (newOps.length === 0) return;
|
|
219
|
+
|
|
220
|
+
// const isEditTextFieldOp = (op: EditOperation) => {
|
|
221
|
+
// if (op.type !== "edit-field") return false;
|
|
222
|
+
// const editFieldOp = op as EditFieldOperation;
|
|
223
|
+
// return (
|
|
224
|
+
// editFieldOp.fieldType &&
|
|
225
|
+
// editFieldOp.fieldType.indexOf("text") !== -1
|
|
226
|
+
// );
|
|
227
|
+
// };
|
|
228
|
+
|
|
229
|
+
// const isEditTextField = isEditTextFieldOp(newOps[newOps.length - 1]);
|
|
230
|
+
|
|
231
|
+
// if (isEditTextField) lastOpIndex = response.editOperations.length - 1;
|
|
232
|
+
// else lastOpIndex = response.editOperations.length;
|
|
233
|
+
|
|
234
|
+
// newOps.forEach((op: EditOperation) => {
|
|
235
|
+
// if (isEditTextFieldOp(op)) {
|
|
236
|
+
// const editFieldOp = op as EditFieldOperation;
|
|
237
|
+
|
|
238
|
+
// if (editFieldOp.itemId) {
|
|
239
|
+
// const fieldDescriptor = {
|
|
240
|
+
// item: {
|
|
241
|
+
// ...editFieldOp.mainItem,
|
|
242
|
+
// id: editFieldOp.itemId,
|
|
243
|
+
// },
|
|
244
|
+
// fieldId: editFieldOp.fieldId,
|
|
245
|
+
// };
|
|
246
|
+
// editContext.itemsRepository.updateFieldValue(
|
|
247
|
+
// fieldDescriptor,
|
|
248
|
+
// editFieldOp.user ?? { name: "unknown", ai: false },
|
|
249
|
+
// false,
|
|
250
|
+
// editFieldOp.value,
|
|
251
|
+
// );
|
|
252
|
+
|
|
253
|
+
// editContext.select([editFieldOp.itemId]);
|
|
254
|
+
// editContext.setScrollIntoView(editFieldOp.itemId);
|
|
255
|
+
|
|
256
|
+
// editContext?.setFocusedField(fieldDescriptor, false);
|
|
257
|
+
// }
|
|
258
|
+
// } else {
|
|
259
|
+
// const addOp = op as AddComponentOperation;
|
|
260
|
+
// if (op.type === "add-component" && addOp.componentId) {
|
|
261
|
+
// const newComponentId = addOp.componentId;
|
|
262
|
+
// editContext.select([newComponentId]);
|
|
263
|
+
// editContext.setScrollIntoView(newComponentId);
|
|
264
|
+
// }
|
|
265
|
+
// }
|
|
266
|
+
// });
|
|
267
|
+
// }
|
|
268
|
+
},
|
|
269
|
+
);
|
|
270
|
+
|
|
271
|
+
if (response) {
|
|
272
|
+
handleResponse(response, callback, true);
|
|
273
|
+
if (context.callback) context.callback(response);
|
|
274
|
+
editContext?.requestRefresh("immediate");
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
// if (response?.responseText)
|
|
278
|
+
// newMessages.push({
|
|
279
|
+
// content: response.responseText,
|
|
280
|
+
// role: "assistant",
|
|
281
|
+
// name: "assistant",
|
|
282
|
+
// });
|
|
283
|
+
|
|
284
|
+
setResponse(response ? response : undefined);
|
|
285
|
+
|
|
286
|
+
// setMessages(newMessages);
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
useEffect(() => {
|
|
290
|
+
TerminalService.on("command", commandHandler);
|
|
291
|
+
|
|
292
|
+
return () => {
|
|
293
|
+
TerminalService.off("command", commandHandler);
|
|
294
|
+
};
|
|
295
|
+
}, []);
|
|
296
|
+
|
|
297
|
+
return (
|
|
298
|
+
<div
|
|
299
|
+
className="relative flex h-full flex-1 flex-col pl-1.5"
|
|
300
|
+
data-testid="ai-terminal"
|
|
301
|
+
>
|
|
302
|
+
<div className="relative flex-1">
|
|
303
|
+
<div className="tour-ai-terminal absolute inset-0">
|
|
304
|
+
<Terminal
|
|
305
|
+
disabled={!model}
|
|
306
|
+
ref={terminalRef}
|
|
307
|
+
onReset={() => {
|
|
308
|
+
setMessages([]);
|
|
309
|
+
setResponseMessages([]);
|
|
310
|
+
setResponse(undefined);
|
|
311
|
+
}}
|
|
312
|
+
infobar={
|
|
313
|
+
response?.numInputTokens && (
|
|
314
|
+
<div
|
|
315
|
+
className="text-right text-gray-400"
|
|
316
|
+
style={{ fontSize: "10px" }}
|
|
317
|
+
>
|
|
318
|
+
Tokens in: {response?.numInputTokens?.toLocaleString()} out:{" "}
|
|
319
|
+
{response?.numOutputTokens?.toLocaleString()}{" "}
|
|
320
|
+
{response?.numCachedTokens
|
|
321
|
+
? `cached: ${response?.numCachedTokens?.toLocaleString()} `
|
|
322
|
+
: ""}
|
|
323
|
+
{response?.state}
|
|
324
|
+
</div>
|
|
325
|
+
)
|
|
326
|
+
}
|
|
327
|
+
prompt={prompt}
|
|
328
|
+
setPrompt={setPrompt}
|
|
329
|
+
statusbar=<div className="flex flex-1 items-center justify-between gap-1">
|
|
330
|
+
<a
|
|
331
|
+
className="ml-1 flex cursor-pointer items-center gap-1 text-xs text-blue-300"
|
|
332
|
+
onClick={() => {
|
|
333
|
+
setShowPredefined(!showPredefined);
|
|
334
|
+
}}
|
|
335
|
+
>
|
|
336
|
+
<WizardIcon className="h-5 w-5" />
|
|
337
|
+
Predefined prompts
|
|
338
|
+
</a>
|
|
339
|
+
{editContext.selection?.length > 0 && (
|
|
340
|
+
<div className="mr-2 flex items-center text-xs text-red-400">
|
|
341
|
+
{editContext.selection.length} items selected
|
|
342
|
+
<SimpleIconButton
|
|
343
|
+
icon="pi pi-times"
|
|
344
|
+
label="Clear selection"
|
|
345
|
+
onClick={() => {
|
|
346
|
+
editContext.select([]);
|
|
347
|
+
}}
|
|
348
|
+
/>
|
|
349
|
+
</div>
|
|
350
|
+
)}
|
|
351
|
+
{showPredefined && (
|
|
352
|
+
<div className="absolute right-0 bottom-8 left-0 flex flex-col gap-1 overflow-y-auto bg-white p-3 pb-1 text-sm">
|
|
353
|
+
{activeProfile &&
|
|
354
|
+
activeProfile.prompts.map((p, index) => (
|
|
355
|
+
<div
|
|
356
|
+
key={index}
|
|
357
|
+
className="mb-1 cursor-pointer rounded-lg border border-gray-200 p-1.5 text-xs text-gray-700"
|
|
358
|
+
onClick={() => {
|
|
359
|
+
setPrompt(p.prompt);
|
|
360
|
+
setShowPredefined(false);
|
|
361
|
+
}}
|
|
362
|
+
>
|
|
363
|
+
{p.title}
|
|
364
|
+
</div>
|
|
365
|
+
))}
|
|
366
|
+
</div>
|
|
367
|
+
)}
|
|
368
|
+
</div>
|
|
369
|
+
toolbar=<div className="flex items-stretch gap-1">
|
|
370
|
+
<Dropdown
|
|
371
|
+
className="text-sm"
|
|
372
|
+
value={activeProfile}
|
|
373
|
+
onChange={(e) => setActiveProfile(e.value)}
|
|
374
|
+
optionLabel="name"
|
|
375
|
+
options={profiles}
|
|
376
|
+
/>
|
|
377
|
+
{activeProfile && (
|
|
378
|
+
<Dropdown
|
|
379
|
+
className="text-sm"
|
|
380
|
+
value={model}
|
|
381
|
+
onChange={(e) => setModel(e.value)}
|
|
382
|
+
options={activeProfile.models}
|
|
383
|
+
/>
|
|
384
|
+
)}
|
|
385
|
+
{closeButton}
|
|
386
|
+
</div>
|
|
387
|
+
commandHandler={(v, callback) => {
|
|
388
|
+
commandHandler(v, callback);
|
|
389
|
+
}}
|
|
390
|
+
/>
|
|
391
|
+
</div>
|
|
392
|
+
{activeProfile?.errorMessage && (
|
|
393
|
+
<div className="absolute inset-0 grid items-center justify-center p-2 text-sm text-red-500">
|
|
394
|
+
{activeProfile?.errorMessage}
|
|
395
|
+
</div>
|
|
396
|
+
)}
|
|
397
|
+
{!model && (
|
|
398
|
+
<div className="absolute inset-0 grid items-center justify-center text-sm text-gray-400">
|
|
399
|
+
{!activeProfile ? "No profile selected" : "No model selected"}
|
|
400
|
+
</div>
|
|
401
|
+
)}
|
|
402
|
+
</div>
|
|
403
|
+
</div>
|
|
404
|
+
);
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
async function executePrompt(
|
|
408
|
+
profileId: string,
|
|
409
|
+
messages: Message[],
|
|
410
|
+
selection: string[],
|
|
411
|
+
session: string | null,
|
|
412
|
+
model: string | null,
|
|
413
|
+
selectedText: string | null,
|
|
414
|
+
context: AiContext,
|
|
415
|
+
callback: (response: any) => void,
|
|
416
|
+
): Promise<Response | null> {
|
|
417
|
+
const response = await fetch(context.endpoint, {
|
|
418
|
+
method: "POST",
|
|
419
|
+
body: JSON.stringify({
|
|
420
|
+
...context.promptData,
|
|
421
|
+
profileId,
|
|
422
|
+
messages,
|
|
423
|
+
selection,
|
|
424
|
+
addSelectedComponents: true,
|
|
425
|
+
selectedText,
|
|
426
|
+
model,
|
|
427
|
+
sessionId: session,
|
|
428
|
+
}),
|
|
429
|
+
credentials: "include",
|
|
430
|
+
headers: {
|
|
431
|
+
"Content-Type": "application/json",
|
|
432
|
+
Cookie: new Cookies().getAll(),
|
|
433
|
+
},
|
|
434
|
+
});
|
|
435
|
+
|
|
436
|
+
if (!response.ok) {
|
|
437
|
+
const text = await response.text();
|
|
438
|
+
return {
|
|
439
|
+
messages: [
|
|
440
|
+
{
|
|
441
|
+
content: "There was an error processing your request: " + text,
|
|
442
|
+
id: 0,
|
|
443
|
+
name: "assistant",
|
|
444
|
+
role: "assistant",
|
|
445
|
+
},
|
|
446
|
+
],
|
|
447
|
+
editOperations: [],
|
|
448
|
+
numInputTokens: 0,
|
|
449
|
+
numOutputTokens: 0,
|
|
450
|
+
numCachedTokens: 0,
|
|
451
|
+
state: "error",
|
|
452
|
+
};
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
if (!response?.body) return null;
|
|
456
|
+
|
|
457
|
+
const reader = response.body.getReader();
|
|
458
|
+
const decoder = new TextDecoder();
|
|
459
|
+
let buffer = "";
|
|
460
|
+
|
|
461
|
+
let result = null;
|
|
462
|
+
|
|
463
|
+
while (true) {
|
|
464
|
+
const { done, value } = await reader.read();
|
|
465
|
+
|
|
466
|
+
if (done) {
|
|
467
|
+
break;
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
buffer += decoder.decode(value, { stream: true }); // 'stream: true' ensures that any incomplete multi-byte characters aren't malformed.
|
|
471
|
+
|
|
472
|
+
// Split the buffer by newline and keep the last partial line for the next iteration.
|
|
473
|
+
const lines = buffer.split("\n");
|
|
474
|
+
|
|
475
|
+
if (lines.length > 0) {
|
|
476
|
+
buffer = lines.pop() || ""; // Incomplete line (if any) is kept for the next iteration.
|
|
477
|
+
|
|
478
|
+
for (let line of lines) {
|
|
479
|
+
if (line.trim() === "") continue; // Skip empty lines if any.
|
|
480
|
+
|
|
481
|
+
try {
|
|
482
|
+
const jsonData = JSON.parse(line);
|
|
483
|
+
callback(jsonData);
|
|
484
|
+
result = jsonData;
|
|
485
|
+
} catch (e) {
|
|
486
|
+
console.error("Error parsing line:" + line, e);
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
// If there's any remaining content in the buffer after processing all chunks, try to process it.
|
|
493
|
+
if (buffer.trim() !== "") {
|
|
494
|
+
try {
|
|
495
|
+
const jsonData = JSON.parse(buffer);
|
|
496
|
+
result = jsonData;
|
|
497
|
+
} catch (e) {
|
|
498
|
+
console.error("Error parsing the final buffer content:", e);
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
return result;
|
|
503
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { useEffect, useState } from "react";
|
|
2
|
+
|
|
3
|
+
import { JsonView, defaultStyles } from "react-json-view-lite";
|
|
4
|
+
import { Message, ToolCall } from "./AiTerminal";
|
|
5
|
+
import { ProgressSpinner } from "primereact/progressspinner";
|
|
6
|
+
export function AiToolCall({
|
|
7
|
+
toolCall,
|
|
8
|
+
result,
|
|
9
|
+
}: {
|
|
10
|
+
toolCall: ToolCall;
|
|
11
|
+
result: Message | undefined;
|
|
12
|
+
}) {
|
|
13
|
+
const [expanded, setExpaded] = useState(false);
|
|
14
|
+
const [error, setError] = useState<string | undefined>(undefined);
|
|
15
|
+
|
|
16
|
+
useEffect(() => {
|
|
17
|
+
try {
|
|
18
|
+
const data = JSON.parse(result?.content || "{}");
|
|
19
|
+
setError(data.error);
|
|
20
|
+
} catch (err) {
|
|
21
|
+
console.error("Failed to parse tool call result:", err);
|
|
22
|
+
setError("Failed to parse response");
|
|
23
|
+
}
|
|
24
|
+
}, [result]);
|
|
25
|
+
|
|
26
|
+
return (
|
|
27
|
+
<div className="m-2">
|
|
28
|
+
<div
|
|
29
|
+
onClick={() => setExpaded(!expanded)}
|
|
30
|
+
className="flex cursor-pointer items-center"
|
|
31
|
+
>
|
|
32
|
+
<i className="pi pi-angle-right" />
|
|
33
|
+
<div className="flex items-center gap-2">
|
|
34
|
+
{!result && (
|
|
35
|
+
<ProgressSpinner style={{ width: "1rem", height: "1rem" }} />
|
|
36
|
+
)}
|
|
37
|
+
{toolCall.displayName}
|
|
38
|
+
</div>
|
|
39
|
+
</div>
|
|
40
|
+
{expanded && (
|
|
41
|
+
<div className="ml-4">
|
|
42
|
+
<div>{renderJsonOrText(toolCall.function.arguments)}</div>
|
|
43
|
+
{error && (
|
|
44
|
+
<div className="ml-4 text-red-500">
|
|
45
|
+
<div className="italic">Error:</div>
|
|
46
|
+
<div>{error}</div>
|
|
47
|
+
</div>
|
|
48
|
+
)}
|
|
49
|
+
</div>
|
|
50
|
+
)}
|
|
51
|
+
</div>
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function renderJsonOrText(json: string) {
|
|
56
|
+
try {
|
|
57
|
+
return <JsonView data={JSON.parse(json)} style={defaultStyles} />;
|
|
58
|
+
} catch (e) {
|
|
59
|
+
return <div>{json}</div>;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { AiTerminalOptions } from "./AiTerminal";
|
|
2
|
+
import { AiTerminal } from "./AiTerminal";
|
|
3
|
+
import { createEditorAiContext } from "./editorAiContext";
|
|
4
|
+
|
|
5
|
+
export function EditorAiTerminal({
|
|
6
|
+
closeButton,
|
|
7
|
+
options,
|
|
8
|
+
}: {
|
|
9
|
+
closeButton?: React.ReactNode;
|
|
10
|
+
options?: AiTerminalOptions;
|
|
11
|
+
}) {
|
|
12
|
+
return (
|
|
13
|
+
<AiTerminal
|
|
14
|
+
options={options}
|
|
15
|
+
closeButton={closeButton}
|
|
16
|
+
createAiContext={createEditorAiContext}
|
|
17
|
+
defaultProfile="Editor"
|
|
18
|
+
/>
|
|
19
|
+
);
|
|
20
|
+
}
|