Skip to content

Commit

Permalink
Merge branch 'main' into add-mail-labels
Browse files Browse the repository at this point in the history
  • Loading branch information
RicSala committed Feb 23, 2025
2 parents 743c3d9 + fa52f9c commit 32f1db4
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 13 deletions.
4 changes: 4 additions & 0 deletions apps/web/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ NEXTAUTH_URL=http://localhost:3000
GOOGLE_CLIENT_ID=
GOOGLE_CLIENT_SECRET=

GOOGLE_API_KEY=

GROQ_API_KEY=

OPENAI_API_KEY=

BEDROCK_ACCESS_KEY=
Expand Down
4 changes: 2 additions & 2 deletions apps/web/app/(app)/mail/BetaBanner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ export function BetaBanner() {
if (bannerVisible && typeof window !== "undefined")
return (
<Banner
title="Alpha"
description="Mail is currently in alpha. It is not intended to be a full replacement for your email client yet."
title="Beta"
description="Mail is currently in beta. It is not intended to be a full replacement for your email client yet."
onClose={() => setBannerVisible(false)}
/>
);
Expand Down
1 change: 1 addition & 0 deletions apps/web/components/EmailViewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export function ThreadContent({
autoOpenReplyForMessageId={autoOpenReplyForMessageId}
topRightComponent={topRightComponent}
onSendSuccess={onSendSuccess}
withHeader
/>
)}
</LoadingContent>
Expand Down
2 changes: 1 addition & 1 deletion apps/web/components/TopNav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const userNavigation = [
]),
{ name: "Usage", href: "/usage", icon: BarChartIcon },
{
name: "Mail (Alpha)",
name: "Mail (Beta)",
href: "/mail",
icon: InboxIcon,
},
Expand Down
18 changes: 11 additions & 7 deletions apps/web/components/email-list/EmailThread.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ export function EmailThread({
autoOpenReplyForMessageId,
topRightComponent,
onSendSuccess,
withHeader,
}: {
messages: ThreadMessage[];
refetch: () => void;
showReplyButton: boolean;
autoOpenReplyForMessageId?: string;
topRightComponent?: React.ReactNode;
onSendSuccess?: (messageId: string, threadId: string) => void;
withHeader?: boolean;
}) {
// Place draft messages as replies to their parent message
const organizedMessages = useMemo(() => {
Expand Down Expand Up @@ -50,14 +52,16 @@ export function EmailThread({

return (
<div className="flex-1 overflow-auto bg-muted p-4">
<div className="flex items-center justify-between">
<div className="text-2xl font-semibold text-foreground">
{messages[0]?.headers.subject}
{withHeader && (
<div className="flex items-center justify-between">
<div className="text-2xl font-semibold text-foreground">
{messages[0]?.headers.subject}
</div>
{topRightComponent && (
<div className="flex items-center gap-2">{topRightComponent}</div>
)}
</div>
{topRightComponent && (
<div className="flex items-center gap-2">{topRightComponent}</div>
)}
</div>
)}
<ul className="mt-4 space-y-2 sm:space-y-4">
{organizedMessages.map(({ message, draftMessage }) => {
const defaultShowReply =
Expand Down
2 changes: 2 additions & 0 deletions apps/web/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ export const env = createEnv({
BEDROCK_ACCESS_KEY: z.string().optional(),
BEDROCK_SECRET_KEY: z.string().optional(),
BEDROCK_REGION: z.string().default("us-west-2"),
GOOGLE_API_KEY: z.string().optional(),
GROQ_API_KEY: z.string().optional(),
UPSTASH_REDIS_URL: z.string().optional(),
UPSTASH_REDIS_TOKEN: z.string().optional(),
OLLAMA_BASE_URL: z.string().optional(),
Expand Down
2 changes: 1 addition & 1 deletion apps/web/utils/llms/config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { env } from "@/env";

const supportsOllama = env.NEXT_PUBLIC_OLLAMA_MODEL;
export const supportsOllama = !!env.NEXT_PUBLIC_OLLAMA_MODEL;

export const Provider = {
OPEN_AI: "openai",
Expand Down
16 changes: 14 additions & 2 deletions apps/web/utils/llms/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { createGroq } from "@ai-sdk/groq";
import { createOllama } from "ollama-ai-provider";
import { env } from "@/env";
import { saveAiUsage } from "@/utils/usage";
import { Model, Provider } from "@/utils/llms/config";
import { Model, Provider, supportsOllama } from "@/utils/llms/config";
import type { UserAIFields } from "@/utils/llms/types";
import { addUserErrorMessage, ErrorType } from "@/utils/error-messages";
import {
Expand All @@ -30,8 +30,20 @@ import {
} from "@/utils/error";
import { sleep } from "@/utils/sleep";

function getDefaultProvider(): string {
if (env.BEDROCK_ACCESS_KEY) return Provider.ANTHROPIC;
if (env.ANTHROPIC_API_KEY) return Provider.ANTHROPIC;
if (env.OPENAI_API_KEY) return Provider.OPEN_AI;
if (env.GOOGLE_API_KEY) return Provider.GOOGLE;
if (env.GROQ_API_KEY) return Provider.GROQ;
if (supportsOllama && env.OLLAMA_BASE_URL) return Provider.OLLAMA!;
throw new Error(
"No AI provider found. Please set at least one API key in env variables.",
);
}

function getModel({ aiProvider, aiModel, aiApiKey }: UserAIFields) {
const provider = aiProvider || Provider.ANTHROPIC;
const provider = aiProvider || getDefaultProvider();

if (provider === Provider.OPEN_AI) {
const model = aiModel || Model.GPT_4O;
Expand Down

0 comments on commit 32f1db4

Please sign in to comment.