Skip to content

Commit ba5f2dc

Browse files
authored
Merge pull request #7588 from sagemathinc/ai-doc-gen-7578
AI Generator tweaks
2 parents bd23cda + 720ce70 commit ba5f2dc

File tree

11 files changed

+167
-84
lines changed

11 files changed

+167
-84
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
export const SEARCH_COMMANDS = "search_commands";
22
export const APPLICATION_MENU = "__title__";
3+
export const AI_GEN_TEXT = "Help me write...";

src/packages/frontend/frame-editors/frame-tree/commands/editor-menus.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ This is basically a more user friendly and compact interface to the addMenus
66
and addCommands functions.
77
*/
88

9+
import { capitalize } from "@cocalc/util/misc";
910
import { addCommands } from "./commands";
1011
import { addMenus } from "./menus";
1112
import type { Command, Menus } from "./types";
12-
import { capitalize } from "@cocalc/util/misc";
1313

1414
type Command0 = {
1515
icon?: string;

src/packages/frontend/frame-editors/frame-tree/commands/generic-commands.tsx

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,26 @@
1-
import { get_default_font_size } from "@cocalc/frontend/frame-editors/generic/client";
2-
import {
3-
undo as chatUndo,
4-
redo as chatRedo,
5-
} from "@cocalc/frontend/frame-editors/generic/chat";
6-
import { Icon } from "@cocalc/frontend/components";
7-
import { redux } from "@cocalc/frontend/app-framework";
1+
import { Input } from "antd";
82
import { debounce } from "lodash";
93
import { useEffect, useRef } from "react";
10-
import { FORMAT_SOURCE_ICON } from "@cocalc/frontend/frame-editors/frame-tree/config";
11-
import { IS_MACOS } from "@cocalc/frontend/feature";
12-
import userTracking from "@cocalc/frontend/user-tracking";
13-
import openSupportTab from "@cocalc/frontend/support/open";
14-
import { Input } from "antd";
15-
import { SEARCH_COMMANDS } from "./const";
16-
import { addCommands } from "./commands";
4+
175
import { set_account_table } from "@cocalc/frontend/account/util";
6+
import { redux } from "@cocalc/frontend/app-framework";
7+
import { Icon } from "@cocalc/frontend/components";
188
import AIAvatar from "@cocalc/frontend/components/ai-avatar";
9+
import { IS_MACOS } from "@cocalc/frontend/feature";
10+
import { FORMAT_SOURCE_ICON } from "@cocalc/frontend/frame-editors/frame-tree/config";
11+
import {
12+
redo as chatRedo,
13+
undo as chatUndo,
14+
} from "@cocalc/frontend/frame-editors/generic/chat";
15+
import { get_default_font_size } from "@cocalc/frontend/frame-editors/generic/client";
1916
import { open_new_tab as openNewTab } from "@cocalc/frontend/misc/open-browser-tab";
17+
import { isSupportedExtension } from "@cocalc/frontend/project/page/home-page/ai-generate-examples";
18+
import { AI_GENERATE_DOC_TAG } from "@cocalc/frontend/project/page/home-page/ai-generate-utils";
19+
import openSupportTab from "@cocalc/frontend/support/open";
20+
import userTracking from "@cocalc/frontend/user-tracking";
21+
import { filename_extension } from "@cocalc/util/misc";
22+
import { addCommands } from "./commands";
23+
import { AI_GEN_TEXT, SEARCH_COMMANDS } from "./const";
2024

2125
addCommands({
2226
"split-row": {
@@ -628,6 +632,22 @@ addCommands({
628632
label: "New File",
629633
...fileAction("new"),
630634
},
635+
new_ai: {
636+
pos: 0.5,
637+
group: "new-open",
638+
icon: <AIAvatar size={16} />,
639+
title: "Create a new file with the help of AI",
640+
label: AI_GEN_TEXT,
641+
onClick: ({ setShowNewAI }) => setShowNewAI?.(true),
642+
isVisible: ({ props }) => {
643+
const { path, project_id } = props;
644+
const ext = filename_extension(path);
645+
if (!isSupportedExtension(ext)) return false;
646+
return redux
647+
.getStore("projects")
648+
.hasLanguageModelEnabled(project_id, AI_GENERATE_DOC_TAG);
649+
},
650+
},
631651
open: {
632652
pos: 1,
633653
group: "new-open",

src/packages/frontend/frame-editors/frame-tree/commands/manage.tsx

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1-
import { COMMANDS } from "./commands";
2-
import { GROUPS, MENUS } from "./menus";
3-
import { APPLICATION_MENU, SEARCH_COMMANDS } from "./const";
4-
import type { Command } from "./types";
5-
import { Icon, IconName } from "@cocalc/frontend/components/icon";
6-
import { cmp, filename_extension, trunc_middle } from "@cocalc/util/misc";
71
import { Button, Tooltip } from "antd";
8-
import { STAY_OPEN_ON_CLICK } from "@cocalc/frontend/components/dropdown-menu";
9-
import type { MenuItem } from "@cocalc/frontend/components/dropdown-menu";
2+
103
import { set_account_table } from "@cocalc/frontend/account/util";
114
import { redux } from "@cocalc/frontend/app-framework";
5+
import type { MenuItem } from "@cocalc/frontend/components/dropdown-menu";
6+
import { STAY_OPEN_ON_CLICK } from "@cocalc/frontend/components/dropdown-menu";
7+
import { Icon, IconName } from "@cocalc/frontend/components/icon";
128
import { IS_MOBILE } from "@cocalc/frontend/feature";
9+
import { cmp, filename_extension, trunc_middle } from "@cocalc/util/misc";
10+
import { COMMANDS } from "./commands";
11+
import { APPLICATION_MENU, SEARCH_COMMANDS } from "./const";
12+
import { GROUPS, MENUS } from "./menus";
13+
import type { Command } from "./types";
1314

1415
const MAX_TITLE_WIDTH = 20;
1516
const MAX_SEARCH_RESULTS = 10;
@@ -18,7 +19,8 @@ const ICON_WIDTH = "24px";
1819
export class ManageCommands {
1920
readonly props;
2021
readonly studentProjectFunctionality;
21-
readonly setShowAI;
22+
readonly setShowAI: (val: boolean) => void;
23+
readonly setShowNewAI: (val: boolean) => void;
2224
readonly helpSearch: string;
2325
readonly setHelpSearch;
2426
readonly readOnly: boolean;
@@ -30,6 +32,7 @@ export class ManageCommands {
3032
props,
3133
studentProjectFunctionality,
3234
setShowAI,
35+
setShowNewAI,
3336
helpSearch,
3437
setHelpSearch,
3538
readOnly,
@@ -38,6 +41,7 @@ export class ManageCommands {
3841
this.props = props;
3942
this.studentProjectFunctionality = studentProjectFunctionality;
4043
this.setShowAI = setShowAI;
44+
this.setShowNewAI = setShowNewAI;
4145
this.helpSearch = helpSearch;
4246
this.setHelpSearch = setHelpSearch;
4347
this.readOnly = readOnly;

src/packages/frontend/frame-editors/frame-tree/commands/menus.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ export function addMenus(menus: Menus) {
2828
}
2929
}
3030
}
31-
// window.x = { MENUS };
3231

3332
export function addCommandsToMenus(commands: { [command: string]: Command }) {
3433
for (const name in commands) {

src/packages/frontend/frame-editors/frame-tree/commands/types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import { MENUS } from "./menus";
21
import type { ReactNode } from "react";
2+
33
import type { ManageCommands } from "./manage";
4+
import { MENUS } from "./menus";
45

56
interface MenuSpec {
67
label: string;

src/packages/frontend/frame-editors/frame-tree/title-bar.tsx

Lines changed: 45 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ FrameTitleBar - title bar in a frame, in the frame tree
1111
import { Button, Input, InputNumber, Popover, Tooltip } from "antd";
1212
import { List } from "immutable";
1313
import { useMemo, useRef } from "react";
14+
1415
import { ButtonGroup } from "@cocalc/frontend/antd-bootstrap";
1516
import {
1617
CSS,
@@ -20,37 +21,46 @@ import {
2021
useState,
2122
} from "@cocalc/frontend/app-framework";
2223
import {
24+
Gap,
2325
Icon,
2426
MenuItem,
2527
MenuItems,
2628
r_join,
27-
Gap,
2829
VisibleMDLG,
2930
} from "@cocalc/frontend/components";
3031
import { DropdownMenu } from "@cocalc/frontend/components/dropdown-menu";
32+
import { computeServersEnabled } from "@cocalc/frontend/compute/config";
33+
import SelectComputeServerForFile from "@cocalc/frontend/compute/select-server-for-file";
34+
import { StandaloneComputeServerDocStatus } from "@cocalc/frontend/compute/standalone-doc-status";
3135
import { useStudentProjectFunctionality } from "@cocalc/frontend/course";
32-
import { copy, path_split, trunc_middle, field_cmp } from "@cocalc/util/misc";
36+
import { IS_MOBILE } from "@cocalc/frontend/feature";
37+
import { excludeFromComputeServer } from "@cocalc/frontend/file-associations";
38+
import { AIGenerateDocumentModal } from "@cocalc/frontend/project/page/home-page/ai-generate-document";
39+
import { isSupportedExtension } from "@cocalc/frontend/project/page/home-page/ai-generate-examples";
40+
import { AvailableFeatures } from "@cocalc/frontend/project_configuration";
41+
import userTracking from "@cocalc/frontend/user-tracking";
42+
import {
43+
copy,
44+
field_cmp,
45+
filename_extension,
46+
path_split,
47+
trunc_middle,
48+
} from "@cocalc/util/misc";
49+
import { COLORS } from "@cocalc/util/theme";
3350
import { Actions } from "../code-editor/actions";
3451
import { is_safari } from "../generic/browser";
35-
import { SaveButton } from "./save-button";
36-
import { ConnectionStatus, EditorDescription, EditorSpec } from "./types";
3752
import LanguageModelTitleBarButton from "../llm/title-bar-button";
38-
import userTracking from "@cocalc/frontend/user-tracking";
39-
import TitleBarTour from "./title-bar-tour";
40-
import { IS_MOBILE } from "@cocalc/frontend/feature";
41-
import SelectComputeServerForFile from "@cocalc/frontend/compute/select-server-for-file";
42-
import { computeServersEnabled } from "@cocalc/frontend/compute/config";
43-
import { excludeFromComputeServer } from "@cocalc/frontend/file-associations";
4453
import {
4554
APPLICATION_MENU,
4655
COMMANDS,
47-
MENUS,
4856
GROUPS,
49-
SEARCH_COMMANDS,
5057
ManageCommands,
58+
MENUS,
59+
SEARCH_COMMANDS,
5160
} from "./commands";
52-
const MAX_SEARCH_RESULTS = 10;
53-
import { StandaloneComputeServerDocStatus } from "@cocalc/frontend/compute/standalone-doc-status";
61+
import { SaveButton } from "./save-button";
62+
import TitleBarTour from "./title-bar-tour";
63+
import { ConnectionStatus, EditorDescription, EditorSpec } from "./types";
5464

5565
// Certain special frame editors (e.g., for latex) have extra
5666
// actions that are not defined in the base code editor actions.
@@ -75,8 +85,7 @@ interface EditorActions extends Actions {
7585
halt_jupyter?: () => void;
7686
}
7787

78-
import { AvailableFeatures } from "@cocalc/frontend/project_configuration";
79-
import { COLORS } from "@cocalc/util/theme";
88+
const MAX_SEARCH_RESULTS = 10;
8089

8190
const COL_BAR_BACKGROUND = "#f8f8f8";
8291
const COL_BAR_BACKGROUND_DARK = COL_BAR_BACKGROUND;
@@ -183,6 +192,7 @@ export function FrameTitleBar(props: Props) {
183192
useState<boolean>(false);
184193

185194
const [showAI, setShowAI] = useState<boolean>(false);
195+
const [showNewAI, setShowNewAI] = useState<boolean>(false);
186196

187197
const [helpSearch, setHelpSearch] = useState<string>("");
188198

@@ -212,6 +222,7 @@ export function FrameTitleBar(props: Props) {
212222
props,
213223
studentProjectFunctionality: student_project_functionality,
214224
setShowAI,
225+
setShowNewAI,
215226
helpSearch,
216227
setHelpSearch,
217228
readOnly: read_only,
@@ -223,11 +234,11 @@ export function FrameTitleBar(props: Props) {
223234
helpSearch,
224235
setHelpSearch,
225236
setShowAI,
237+
setShowNewAI,
226238
read_only,
227239
editorSettings,
228240
],
229241
);
230-
// window.x = { manageCommands };
231242

232243
const has_unsaved_changes: boolean = useRedux([
233244
props.editor_actions.name,
@@ -511,6 +522,22 @@ export function FrameTitleBar(props: Props) {
511522
);
512523
}
513524

525+
function renderNewAI() {
526+
const { path, project_id } = props;
527+
const ext = filename_extension(path);
528+
if (!isSupportedExtension(ext)) return;
529+
530+
return (
531+
<AIGenerateDocumentModal
532+
key={"new-ai"}
533+
ext={ext}
534+
show={showNewAI}
535+
setShow={setShowNewAI}
536+
project_id={project_id}
537+
/>
538+
);
539+
}
540+
514541
function renderAssistant(noLabel): Rendered {
515542
if (
516543
!manageCommands.isVisible("chatgpt") ||
@@ -716,6 +743,7 @@ export function FrameTitleBar(props: Props) {
716743
v.push(renderTitle());
717744
}
718745
v.push(renderPage());
746+
v.push(renderNewAI());
719747
v.push(renderMenus());
720748
v.push(renderSwitchToFile());
721749

src/packages/frontend/frame-editors/jupyter-editor/editor.ts

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,29 @@ Spec for editing Jupyter notebooks via a frame tree.
88
*/
99

1010
import { createElement } from "react";
11+
12+
import type { Command } from "@cocalc/frontend/frame-editors/frame-tree/commands";
13+
import { addEditorMenus } from "@cocalc/frontend/frame-editors/frame-tree/commands";
14+
import { FORMAT_SOURCE_ICON } from "@cocalc/frontend/frame-editors/frame-tree/config";
15+
import { AllActions, commands } from "@cocalc/frontend/jupyter/commands";
16+
import { shortcut_to_string } from "@cocalc/frontend/jupyter/keyboard-shortcuts";
1117
import { capitalize, field_cmp, set } from "@cocalc/util/misc";
1218
import { createEditor } from "../frame-tree/editor";
1319
import { EditorDescription } from "../frame-tree/types";
1420
import { terminal } from "../terminal-editor/editor";
1521
import { time_travel } from "../time-travel-editor/editor";
1622
import { CellNotebook } from "./cell-notebook/cell-notebook";
17-
import { RawIPynb } from "./raw-ipynb";
23+
import { Introspect } from "./introspect/introspect";
1824
import JSONIPynb from "./json-ipynb";
25+
import KernelMenuItem from "./kernel-menu-item";
26+
import { RawIPynb } from "./raw-ipynb";
1927
import { Slideshow } from "./slideshow-revealjs/slideshow";
20-
import { TableOfContents } from "./table-of-contents";
21-
import { Introspect } from "./introspect/introspect";
22-
const SNIPPET_ICON_NAME =
23-
require("@cocalc/frontend/assistant/common").ICON_NAME;
2428
import { JupyterSnippets } from "./snippets";
25-
import { addEditorMenus } from "@cocalc/frontend/frame-editors/frame-tree/commands";
26-
import type { Command } from "@cocalc/frontend/frame-editors/frame-tree/commands";
27-
import { commands, AllActions } from "@cocalc/frontend/jupyter/commands";
28-
import { shortcut_to_string } from "@cocalc/frontend/jupyter/keyboard-shortcuts";
29-
import KernelMenuItem from "./kernel-menu-item";
30-
import { FORMAT_SOURCE_ICON } from "@cocalc/frontend/frame-editors/frame-tree/config";
29+
import { TableOfContents } from "./table-of-contents";
30+
31+
const {
32+
ICON_NAME: SNIPPET_ICON_NAME,
33+
} = require("@cocalc/frontend/assistant/common");
3134

3235
const jupyterCommands = set([
3336
"about",

0 commit comments

Comments
 (0)