Skip to content

Commit

Permalink
~/modules
Browse files Browse the repository at this point in the history
  • Loading branch information
enricoros committed May 13, 2023
1 parent 37ae23a commit 54b2d28
Show file tree
Hide file tree
Showing 53 changed files with 151 additions and 146 deletions.
6 changes: 3 additions & 3 deletions pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import { CacheProvider, EmotionCache } from '@emotion/react';
import { CssBaseline, CssVarsProvider } from '@mui/joy';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';

import '@/common/styles/GithubMarkdown.css';
import { Brand } from '@/common/brand';
import { createEmotionCache, theme } from '@/common/theme';
import '~/common/styles/GithubMarkdown.css';
import { Brand } from '~/common/brand';
import { createEmotionCache, theme } from '~/common/theme';


// Client-side cache, shared for the whole session of the user in the browser.
Expand Down
5 changes: 3 additions & 2 deletions pages/_document.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import { default as Document, DocumentContext, DocumentProps, Head, Html, Main,
import createEmotionServer from '@emotion/server/create-instance';
import { getInitColorSchemeScript } from '@mui/joy/styles';

import { Brand } from '@/common/brand';
import { Brand } from '~/common/brand';
import { bodyFontClassName, createEmotionCache } from '~/common/theme';

import { MyAppProps } from './_app';
import { bodyFontClassName, createEmotionCache } from '@/common/theme';


interface MyDocumentProps extends DocumentProps {
Expand Down
4 changes: 2 additions & 2 deletions pages/api/elevenlabs/speech.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { NextRequest, NextResponse } from 'next/server';

import { ElevenLabs } from '@/modules/elevenlabs/elevenlabs.types';
import { postToElevenLabs } from '@/modules/elevenlabs/elevenlabs.server';
import { ElevenLabs } from '~/modules/elevenlabs/elevenlabs.types';
import { postToElevenLabs } from '~/modules/elevenlabs/elevenlabs.server';


export default async function handler(req: NextRequest) {
Expand Down
4 changes: 2 additions & 2 deletions pages/api/elevenlabs/voices.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { NextRequest, NextResponse } from 'next/server';

import { ElevenLabs } from '@/modules/elevenlabs/elevenlabs.types';
import { getFromElevenLabs } from '@/modules/elevenlabs/elevenlabs.server';
import { ElevenLabs } from '~/modules/elevenlabs/elevenlabs.types';
import { getFromElevenLabs } from '~/modules/elevenlabs/elevenlabs.server';


export default async function handler(req: NextRequest) {
Expand Down
4 changes: 2 additions & 2 deletions pages/api/openai/chat.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { NextRequest, NextResponse } from 'next/server';

import { OpenAI } from '@/modules/openai/openai.types';
import { openaiPost, toApiChatRequest, toWireCompletionRequest } from '@/modules/openai/openai.server';
import { OpenAI } from '~/modules/openai/openai.types';
import { openaiPost, toApiChatRequest, toWireCompletionRequest } from '~/modules/openai/openai.server';



Expand Down
4 changes: 2 additions & 2 deletions pages/api/openai/models.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { NextRequest, NextResponse } from 'next/server';

import { OpenAI } from '@/modules/openai/openai.types';
import { openaiGet, toApiChatRequest } from '@/modules/openai/openai.server';
import { OpenAI } from '~/modules/openai/openai.types';
import { openaiGet, toApiChatRequest } from '~/modules/openai/openai.server';


export default async function handler(req: NextRequest): Promise<NextResponse> {
Expand Down
4 changes: 2 additions & 2 deletions pages/api/openai/stream-chat.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { NextRequest, NextResponse } from 'next/server';
import { createParser } from 'eventsource-parser';

import { OpenAI } from '@/modules/openai/openai.types';
import { openaiPostResponse, toApiChatRequest, toWireCompletionRequest } from '@/modules/openai/openai.server';
import { OpenAI } from '~/modules/openai/openai.types';
import { openaiPostResponse, toApiChatRequest, toWireCompletionRequest } from '~/modules/openai/openai.server';


async function chatStreamRepeater(api: OpenAI.API.Configuration, rest: Omit<OpenAI.API.Chat.Request, 'api'>, signal: AbortSignal): Promise<ReadableStream> {
Expand Down
2 changes: 1 addition & 1 deletion pages/api/prodia/imagine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import { NextRequest, NextResponse } from 'next/server';

import { Prodia } from '@/modules/prodia/prodia.types';
import { Prodia } from '~/modules/prodia/prodia.types';


export const prodiaHeaders = (apiKey: string): Record<string, string> => ({
Expand Down
2 changes: 1 addition & 1 deletion pages/api/prodia/models.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { NextRequest, NextResponse } from 'next/server';

import { Prodia } from '@/modules/prodia/prodia.types';
import { Prodia } from '~/modules/prodia/prodia.types';


// for lack of an API
Expand Down
4 changes: 2 additions & 2 deletions pages/api/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import { NextRequest, NextResponse } from 'next/server';

import { PasteGG } from '@/modules/pastegg/pastegg.types';
import { pasteGgPost } from '@/modules/pastegg/pastegg.server';
import { PasteGG } from '~/modules/pastegg/pastegg.types';
import { pasteGgPost } from '~/modules/pastegg/pastegg.server';


/**
Expand Down
4 changes: 2 additions & 2 deletions pages/api/search/google.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { NextRequest, NextResponse } from 'next/server';

import { Search } from '@/modules/search/search.types';
import { objectToQueryString } from '@/modules/search/search.client';
import { Search } from '~/modules/search/search.types';
import { objectToQueryString } from '~/modules/search/search.client';


export default async function handler(req: NextRequest): Promise<NextResponse> {
Expand Down
2 changes: 1 addition & 1 deletion pages/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';

import { AppLayout } from '@/common/layouts/AppLayout';
import { AppLayout } from '~/common/layouts/AppLayout';

import { Chat } from '../src/apps/chat/Chat';

Expand Down
28 changes: 14 additions & 14 deletions src/apps/chat/Chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@ import { shallow } from 'zustand/shallow';

import { useTheme } from '@mui/joy';

import { CmdRunProdia } from '@/modules/prodia/prodia.client';
import { CmdRunReact } from '@/modules/search/search.client';
import { PasteGG } from '@/modules/pastegg/pastegg.types';
import { PublishedModal } from '@/modules/pastegg/PublishedModal';
import { callPublish } from '@/modules/pastegg/pastegg.client';

import { ConfirmationModal } from '@/common/components/ConfirmationModal';
import { Link } from '@/common/components/Link';
import { conversationToMarkdown } from '@/common/util/conversationToMarkdown';
import { createDMessage, DMessage, restoreConversationFromJson, useChatStore } from '@/common/state/store-chats';
import { extractCommands } from '@/common/util/extractCommands';
import { useApplicationBarStore } from '@/common/layouts/appbar/useApplicationBarStore';
import { useComposerStore } from '@/common/state/store-composer';
import { useSettingsStore } from '@/common/state/store-settings';
import { CmdRunProdia } from '~/modules/prodia/prodia.client';
import { CmdRunReact } from '~/modules/search/search.client';
import { PasteGG } from '~/modules/pastegg/pastegg.types';
import { PublishedModal } from '~/modules/pastegg/PublishedModal';
import { callPublish } from '~/modules/pastegg/pastegg.client';

import { ConfirmationModal } from '~/common/components/ConfirmationModal';
import { Link } from '~/common/components/Link';
import { conversationToMarkdown } from '~/common/util/conversationToMarkdown';
import { createDMessage, DMessage, restoreConversationFromJson, useChatStore } from '~/common/state/store-chats';
import { extractCommands } from '~/common/util/extractCommands';
import { useApplicationBarStore } from '~/common/layouts/appbar/useApplicationBarStore';
import { useComposerStore } from '~/common/state/store-composer';
import { useSettingsStore } from '~/common/state/store-settings';

import { ActionItems } from './components/appbar/ActionItems';
import { ChatMessageList } from './components/ChatMessageList';
Expand Down
4 changes: 2 additions & 2 deletions src/apps/chat/components/ChatMessageList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { shallow } from 'zustand/shallow';
import { Box, List } from '@mui/joy';
import { SxProps } from '@mui/joy/styles/types';

import { createDMessage, DMessage, useChatStore } from '@/common/state/store-chats';
import { useSettingsStore } from '@/common/state/store-settings';
import { createDMessage, DMessage, useChatStore } from '~/common/state/store-chats';
import { useSettingsStore } from '~/common/state/store-settings';

import { ChatMessage } from './message/ChatMessage';
import { ChatMessageSelectable, MessagesSelectionHeader } from './message/ChatMessageSelectable';
Expand Down
6 changes: 3 additions & 3 deletions src/apps/chat/components/PurposeSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import ClearIcon from '@mui/icons-material/Clear';
import SearchIcon from '@mui/icons-material/Search';

import { SystemPurposeId, SystemPurposes } from '../../../data';
import { useChatStore } from '@/common/state/store-chats';
import { usePurposeStore } from '@/common/state/store-purposes';
import { useSettingsStore } from '@/common/state/store-settings';
import { useChatStore } from '~/common/state/store-chats';
import { usePurposeStore } from '~/common/state/store-purposes';
import { useSettingsStore } from '~/common/state/store-settings';


// Constants for tile sizes / grid width - breakpoints need to be computed here to work around
Expand Down
4 changes: 2 additions & 2 deletions src/apps/chat/components/appbar/ActionItems.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import ExitToAppIcon from '@mui/icons-material/ExitToApp';
import FileDownloadIcon from '@mui/icons-material/FileDownload';
import SettingsSuggestIcon from '@mui/icons-material/SettingsSuggest';

import { downloadConversationJson, useChatStore } from '@/common/state/store-chats';
import { useSettingsStore } from '@/common/state/store-settings';
import { downloadConversationJson, useChatStore } from '~/common/state/store-chats';
import { useSettingsStore } from '~/common/state/store-settings';


export function ActionItems(props: {
Expand Down
4 changes: 2 additions & 2 deletions src/apps/chat/components/appbar/ConversationItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import { SxProps } from '@mui/joy/styles/types';
import CloseIcon from '@mui/icons-material/Close';
import DeleteOutlineIcon from '@mui/icons-material/DeleteOutline';

import { InlineTextarea } from '@/common/components/InlineTextarea';
import { InlineTextarea } from '~/common/components/InlineTextarea';
import { SystemPurposes } from '../../../../data';
import { conversationTitle, useChatStore } from '@/common/state/store-chats';
import { conversationTitle, useChatStore } from '~/common/state/store-chats';


const DEBUG_CONVERSATION_IDs = false;
Expand Down
4 changes: 2 additions & 2 deletions src/apps/chat/components/appbar/ConversationItems.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import AddIcon from '@mui/icons-material/Add';
import DeleteOutlineIcon from '@mui/icons-material/DeleteOutline';
import FileUploadIcon from '@mui/icons-material/FileUpload';

import { MAX_CONVERSATIONS, useChatStore } from '@/common/state/store-chats';
import { useSettingsStore } from '@/common/state/store-settings';
import { MAX_CONVERSATIONS, useChatStore } from '~/common/state/store-chats';
import { useSettingsStore } from '~/common/state/store-settings';

import { ConversationItem } from './ConversationItem';

Expand Down
6 changes: 3 additions & 3 deletions src/apps/chat/components/appbar/Dropdowns.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import * as React from 'react';
import { shallow } from 'zustand/shallow';

import { AppBarDropdown } from '@/common/layouts/appbar/AppBarDropdown';
import { useChatStore } from '@/common/state/store-chats';
import { useSettingsStore } from '@/common/state/store-settings';
import { AppBarDropdown } from '~/common/layouts/appbar/AppBarDropdown';
import { useChatStore } from '~/common/state/store-chats';
import { useSettingsStore } from '~/common/state/store-settings';

import { ChatModelId, ChatModels, SystemPurposeId, SystemPurposes } from '../../../../data';

Expand Down
19 changes: 9 additions & 10 deletions src/apps/chat/components/composer/Composer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,19 @@ import TelegramIcon from '@mui/icons-material/Telegram';
import UploadFileIcon from '@mui/icons-material/UploadFile';

import { ChatModels, SendModeId, SendModes } from '../../../../data';
import { ConfirmationModal } from '@/common/components/ConfirmationModal';
import { countModelTokens } from '@/common/llm-util/token-counter';
import { htmlTableToMarkdown } from '@/common/util/htmlTableToMarkdown';
import { pdfToText } from '@/common/util/pdfToText';
import { useChatStore } from '@/common/state/store-chats';
import { useComposerStore } from '@/common/state/store-composer';
import { useSettingsStore } from '@/common/state/store-settings';
import { useSpeechRecognition } from '@/common/components/useSpeechRecognition';
import { ConfirmationModal } from '~/common/components/ConfirmationModal';
import { countModelTokens } from '~/common/llm-util/token-counter';
import { hideOnDesktop, hideOnMobile } from '~/common/theme';
import { htmlTableToMarkdown } from '~/common/util/htmlTableToMarkdown';
import { pdfToText } from '~/common/util/pdfToText';
import { useChatStore } from '~/common/state/store-chats';
import { useComposerStore } from '~/common/state/store-composer';
import { useSettingsStore } from '~/common/state/store-settings';
import { useSpeechRecognition } from '~/common/components/useSpeechRecognition';

import { ContentReducerModal } from './ContentReducerModal';
import { TokenBadge } from './TokenBadge';
import { TokenProgressbar } from './TokenProgressbar';
import { hideOnDesktop, hideOnMobile } from '@/common/theme';
// import { isValidProdiaApiKey, requireUserKeyProdia } from '@/modules/prodia/prodia.client';


/// Text template helpers
Expand Down
6 changes: 3 additions & 3 deletions src/apps/chat/components/composer/ContentReducerModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import * as React from 'react';
import { Alert, Box, Button, CircularProgress, Divider, FormControl, FormHelperText, FormLabel, Modal, ModalClose, ModalDialog, Option, Select, Slider, Stack, Textarea, Typography } from '@mui/joy';

import { ChatModelId, ChatModels, fastChatModelId } from '../../../../data';
import { Section } from '@/common/components/Section';
import { countModelTokens } from '@/common/llm-util/token-counter';
import { summerizeToFitContextBudget } from '@/common/llm-util/summerize';
import { Section } from '~/common/components/Section';
import { countModelTokens } from '~/common/llm-util/token-counter';
import { summerizeToFitContextBudget } from '~/common/llm-util/summerize';

import { TokenBadge } from './TokenBadge';

Expand Down
6 changes: 3 additions & 3 deletions src/apps/chat/components/ephemerals/Ephemerals.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Box, Grid, IconButton, Sheet, Stack, styled, Typography, useTheme } fro
import { SxProps } from '@mui/joy/styles/types';
import CloseIcon from '@mui/icons-material/Close';

import { DEphemeral, useChatStore } from '@/common/state/store-chats';
import { DEphemeral, useChatStore } from '~/common/state/store-chats';


const StateLine = styled(Typography)(({ theme }) => ({
Expand Down Expand Up @@ -42,7 +42,7 @@ function ListRenderer({ name, list }: { name: string, list: any[] }) {
return <StateLine><b>{name}</b>[{list.length ? list.length : ''}]: {list.length ? '(not displayed)' : 'empty'}</StateLine>;
}

function ObjectRenderer({ name, value }: { name: string, value: object }) {
function ObjectRenderer({ name }: { name: string }) {
return <StateLine><b>{name}</b>: <i>object not displayed</i></StateLine>;
}

Expand All @@ -66,7 +66,7 @@ function StateRenderer(props: { state: object }) {
: Array.isArray(value)
? <ListRenderer key={'state-' + key} name={key} list={value} />
: typeof value === 'object'
? <ObjectRenderer key={'state-' + key} name={key} value={value} />
? <ObjectRenderer key={'state-' + key} name={key} />
: <Typography key={'state-' + key} level='body2'>{key}: {value}</Typography>,
)}
</Sheet>
Expand Down
18 changes: 9 additions & 9 deletions src/apps/chat/components/message/ChatMessage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@ import ReplayIcon from '@mui/icons-material/Replay';
import SettingsSuggestIcon from '@mui/icons-material/SettingsSuggest';
import SmartToyOutlinedIcon from '@mui/icons-material/SmartToyOutlined';

import { requireUserKeyElevenLabs, speakText } from '@/modules/elevenlabs/elevenlabs.client';
import { requireUserKeyProdia } from '@/modules/prodia/prodia.client';
import { requireUserKeyElevenLabs, speakText } from '~/modules/elevenlabs/elevenlabs.client';
import { requireUserKeyProdia } from '~/modules/prodia/prodia.client';

import { DMessage } from '@/common/state/store-chats';
import { InlineTextarea } from '@/common/components/InlineTextarea';
import { Link } from '@/common/components/Link';
import { DMessage } from '~/common/state/store-chats';
import { InlineTextarea } from '~/common/components/InlineTextarea';
import { Link } from '~/common/components/Link';
import { SystemPurposeId, SystemPurposes } from '../../../../data';
import { copyToClipboard } from '@/common/util/copyToClipboard';
import { cssRainbowColorKeyframes } from '@/common/theme';
import { prettyBaseModel } from '@/common/util/conversationToMarkdown';
import { useSettingsStore } from '@/common/state/store-settings';
import { copyToClipboard } from '~/common/util/copyToClipboard';
import { cssRainbowColorKeyframes } from '~/common/theme';
import { prettyBaseModel } from '~/common/util/conversationToMarkdown';
import { useSettingsStore } from '~/common/state/store-settings';

import { RenderCode } from './RenderCode';
import { RenderHtml } from './RenderHtml';
Expand Down
2 changes: 1 addition & 1 deletion src/apps/chat/components/message/ChatMessageSelectable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Box, Button, Checkbox, IconButton, ListItem, Sheet, Typography, useThem
import ClearIcon from '@mui/icons-material/Clear';
import DeleteOutlineIcon from '@mui/icons-material/DeleteOutline';

import { DMessage } from '@/common/state/store-chats';
import { DMessage } from '~/common/state/store-chats';

import { TokenBadge } from '../composer/TokenBadge';
import { makeAvatar, messageBackground } from './ChatMessage';
Expand Down
2 changes: 1 addition & 1 deletion src/apps/chat/components/message/RenderCode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import ContentCopyIcon from '@mui/icons-material/ContentCopy';
import SchemaIcon from '@mui/icons-material/Schema';
import ShapeLineOutlinedIcon from '@mui/icons-material/ShapeLineOutlined';

import { copyToClipboard } from '@/common/util/copyToClipboard';
import { copyToClipboard } from '~/common/util/copyToClipboard';

import { CodeBlock } from './Block';
import { OpenInCodepen } from './OpenInCodepen';
Expand Down
2 changes: 1 addition & 1 deletion src/apps/chat/components/message/RenderImage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Box, IconButton, Tooltip } from '@mui/joy';
import ReplayIcon from '@mui/icons-material/Replay';
import ZoomOutMapIcon from '@mui/icons-material/ZoomOutMap';

import { Link } from '@/common/components/Link';
import { Link } from '~/common/components/Link';

import { ImageBlock } from './Block';

Expand Down
2 changes: 1 addition & 1 deletion src/apps/chat/components/message/RenderText.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as React from 'react';
import { Chip, Typography } from '@mui/joy';
import { SxProps } from '@mui/joy/styles/types';

import { extractCommands } from '@/common/util/extractCommands';
import { extractCommands } from '~/common/util/extractCommands';

import { TextBlock } from './Block';

Expand Down
11 changes: 6 additions & 5 deletions src/apps/chat/util/agi-immediate.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { ChatModelId, SystemPurposeId, SystemPurposes } from '../../../data';
import { createDMessage, DMessage, useChatStore } from '@/common/state/store-chats';

import { OpenAI } from '@/modules/openai/openai.types';
import { getOpenAISettings } from '@/modules/openai/openai.client';
import { speakText } from '@/modules/elevenlabs/elevenlabs.client';
import { useSettingsStore } from '@/common/state/store-settings';
import { OpenAI } from '~/modules/openai/openai.types';
import { getOpenAISettings } from '~/modules/openai/openai.client';
import { speakText } from '~/modules/elevenlabs/elevenlabs.client';

import { createDMessage, DMessage, useChatStore } from '~/common/state/store-chats';
import { useSettingsStore } from '~/common/state/store-settings';

import { updateAutoConversationTitle } from './ai-functions';

Expand Down
4 changes: 2 additions & 2 deletions src/apps/chat/util/agi-react.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Agent } from '@/common/llm-util/react';
import { Agent } from '~/common/llm-util/react';
import { ChatModelId } from '../../../data';
import { createEphemeral, DMessage, useChatStore } from '@/common/state/store-chats';
import { createEphemeral, DMessage, useChatStore } from '~/common/state/store-chats';

import { createAssistantTypingMessage } from './agi-immediate';

Expand Down
5 changes: 3 additions & 2 deletions src/apps/chat/util/ai-functions.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { callChat } from '~/modules/openai/openai.client';

import { ChatModelId, fastChatModelId } from '../../../data';
import { callChat } from '@/modules/openai/openai.client';
import { useChatStore } from '@/common/state/store-chats';
import { useChatStore } from '~/common/state/store-chats';


/**
Expand Down
Loading

0 comments on commit 54b2d28

Please sign in to comment.