Skip to content
Merged

Dev #15

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion app/api/chat/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,6 @@ export async function POST(req: Request) {
const result = streamText({
...getModel(model, modelParams),
system: systemPrompt,
maxSteps: 2,
messages: messages.map((m) => ({ role: m.role, content: m.content })),
tools,
onFinish: async ({ providerMetadata }) => {
Expand Down
26 changes: 20 additions & 6 deletions app/api/stripe/webhook/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,26 @@ export async function POST(req: NextRequest) {
subscriptionStatus: subscriptionStatus,
});

await updateUser(userFromDb.id, {
planName: subscriptionStatus === "active" ? "pro" : "free",
stripeCustomerId: subscriptionCustomerId,
stripeSubscriptionId: subscription.id,
subscriptionStatus: subscriptionStatus,
});
// Only update the plan if the subscription is canceled or active
// Ignore other statuses like "incomplete", "past_due", etc.
// As they shouldn't trigger a plan change
if (
subscriptionStatus === "canceled" ||
subscriptionStatus === "active"
) {
await updateUser(userFromDb.id, {
planName: subscriptionStatus === "active" ? "pro" : "free",
stripeCustomerId: subscriptionCustomerId,
stripeSubscriptionId: subscription.id,
subscriptionStatus: subscriptionStatus,
});
} else {
await updateUser(userFromDb.id, {
stripeCustomerId: subscriptionCustomerId,
stripeSubscriptionId: subscription.id,
subscriptionStatus: subscriptionStatus,
});
}
break;
}
} catch (error) {
Expand Down
4 changes: 4 additions & 0 deletions app/chat/[[...chatId]]/chat-container.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export default function ChatContainer({
const [suggestion, setSuggestion] = useState<string | undefined>(undefined);
const { threadId, navigateToChat } = useChatRouter();
const { state, isMobile } = useSidebar();
const [isStreaming, setIsStreaming] = useState(false);
const syncEngine = useContext(SyncDataContext);

// When the user selects a new chat, let's clear the remaining limits
Expand All @@ -40,7 +41,9 @@ export default function ChatContainer({
}, [threadId]);

async function onProcessPegnaAIStream(ask: AskModel) {
setIsStreaming(true);
const response = await processPegnaAIStream(ask);
setIsStreaming(false);
// Sync after sending a message
syncEngine?.start();
// Set the remaining limits
Expand Down Expand Up @@ -138,6 +141,7 @@ export default function ChatContainer({
)}

<ChatForm
isStreaming={isStreaming}
isLoggedIn={isLoggedIn}
userPlan={userPlan}
threadId={threadId}
Expand Down
9 changes: 8 additions & 1 deletion app/chat/[[...chatId]]/chat-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type Props = {
defaultModel?: LlmModel;
defaultModelParams?: ModelParams;
defaultText?: string;
isStreaming: boolean;
isLoggedIn: boolean;
userPlan?: string;
onProcessPegnaAIStream: (ask: AskModel) => Promise<void>;
Expand All @@ -34,6 +35,7 @@ type ChatFormInputs = {
};

export default function ChatForm({
isStreaming,
threadId,
defaultModel,
defaultModelParams,
Expand Down Expand Up @@ -148,7 +150,12 @@ export default function ChatForm({
}}
{...register("content", { required: true })}
/>
<Button type="submit" variant="default" size="icon">
<Button
type="submit"
variant="default"
size="icon"
disabled={isStreaming}
>
<Send className="size-5 -ml-0.5 -mb-0.5" />
</Button>
</div>
Expand Down
35 changes: 34 additions & 1 deletion app/settings/account/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export default async function SubscriptionPage() {
<CardDescription>
{isFreePlan(user?.planName)
? "You're currently on the free plan"
: "Your subscription renews on June 15, 2024"}
: "You're currently subscribed to the Pro plan"}
</CardDescription>
</div>
</div>
Expand Down Expand Up @@ -80,6 +80,15 @@ export default async function SubscriptionPage() {
month
</span>
</li>
<li className="flex items-center">
<div className="mr-3 rounded-full p-1">
<Check className="h-4 w-4" />
</div>
<span>
Access to advanced features like web search, high reasoning,
and image generation.
</span>
</li>
<li className="flex items-center">
<div className="mr-3 rounded-full p-1">
<Check className="h-4 w-4" />
Expand All @@ -94,6 +103,30 @@ export default async function SubscriptionPage() {
</li>
</ul>
</div>
<Separator className="my-6" />
<div>
<div className="mb-4">
<h4 className="text-base font-medium">Premium models:</h4>
<p className="text-sm text-muted-foreground">
The following features and models count towards your premium
quota.
</p>
</div>
<ul className="space-y-3">
<li className="flex items-center">
<div className="mr-3 rounded-full p-1">
<Check className="h-4 w-4" />
</div>
<span>Code generation model</span>
</li>
<li className="flex items-center">
<div className="mr-3 rounded-full p-1">
<Check className="h-4 w-4" />
</div>
<span>Image generation model</span>
</li>
</ul>
</div>

{/*TODO: Implement this when required
<div className="mt-6 rounded-lg p-4">
Expand Down
2 changes: 1 addition & 1 deletion lib/chat/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Here are some of the things you can do:
- Assist with learning and education.

When interacting with me, please follow these guidelines:
- Before doing a tool call, make sure you say something about what you are about to do.
- Before doing a tool call, make sure you say something about what you are about to do, but don't explicitly call out tool execution or tool names.
`;

const name = aiExperience?.name || userName;
Expand Down
1 change: 1 addition & 0 deletions lib/chat/tools/generateImage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export default function createGenerateImageTool(
const { image } = await experimental_generateImage({
model: openai.image("dall-e-3"),
prompt,
size: "1024x1024",
});
// Increment the usage for a premium model for the user
if (userId) {
Expand Down