mirror of
https://github.com/jnsahaj/tweakcn.git
synced 2026-08-29 07:14:31 +08:00
5882f60c32
* update package locks to avoid conflict * Refactor AI Generation with AI SDK v5 (#210) * refactor(wip): Whole Chat implementation * fix: Deps * chore: Update types and create tool to handle theme generation * chore: Add hook and component to handle feedback text * chore: Check for themeStyles in asssiatant metadata * feat: Improve messages styles and feedback * chore: Update react-hook-form deps * chore: Improve Messages display * chore: Show a banner when theme is generating * chore: Optimize the Messages syncing * feat: Add debug button to MessageActions in dev mode * chore: messages * chore: Improve System prompt + tools + utils * fix: correctly display User messages with only images * feat: Handle errors in UI and adapt to AI sdk * feat: Use tool output instead of custom data parts * chore: System prompt and schema context * chore: Gemini 2.5 pro as the default model * refactor: Change name to Chat Context and apply generated theme automatically * chore: Update ai packages to latest version * feat: Stop ongoing request before starting a new chat * feat: Refactor logic for Scroll start/end sentinels * feat: Improve UI streaming with AI Elements and Stream Text utils * chore: Generate theme types and logic * feat: Allow customize the speed of streaming text * refactor: Theme generation utils * fix: Avoid duplicated Mention references * styles: Improve Chat error banner * feat: Enhance Prompt core implementation * feat: Implement enhance prompt in components * chore: Add TODOS comments * chore: Remove Openai provider * chore: Update AI adk packages * fix: Free request constant --------- Co-authored-by: Sahaj Jain <82111591+jnsahaj@users.noreply.github.com> * update lockfile * fix import * fix types * chore: Trigger theme generation before transitioning to editor page * refactor: Move AI sdk specific code into Lib and update imports * chore: Provide model ID to record usage util * refactor: Multi model provider convention * fix types * refactor: Use Zustand persist middleware versioning * feat: Improve prompts and context * feat: Optimize streaming JSONContent into text area * chore: Improve Theme Generation prompt * feat: Improve prompt * feat: Add subscription checks for enhancing prompt and Posthog tracking --------- Co-authored-by: Luis Llanes <137589205+llanesluis@users.noreply.github.com> Co-authored-by: Luis Llanes <luisllaboj@gmail.com>
80 lines
1.9 KiB
TypeScript
80 lines
1.9 KiB
TypeScript
import { authClient } from "@/lib/auth-client";
|
|
import { useAuthStore } from "@/store/auth-store";
|
|
import { useGetProDialogStore } from "@/store/get-pro-dialog-store";
|
|
import { PostLoginActionType } from "./use-post-login-action";
|
|
import { useSubscription } from "./use-subscription";
|
|
|
|
export function useGuards() {
|
|
const { checkValidSession } = useSessionGuard();
|
|
const { checkValidSubscription, checkValidProSubscription } = useSubscriptionGuard();
|
|
|
|
return {
|
|
checkValidSession,
|
|
checkValidSubscription,
|
|
checkValidProSubscription,
|
|
};
|
|
}
|
|
|
|
export function useSessionGuard() {
|
|
const { data: session } = authClient.useSession();
|
|
const { openAuthDialog } = useAuthStore();
|
|
|
|
const checkValidSession = (
|
|
mode: "signin" | "signup" = "signin",
|
|
postLoginActionType?: PostLoginActionType,
|
|
postLoginActionData?: any
|
|
) => {
|
|
if (!session) {
|
|
openAuthDialog(mode, postLoginActionType, postLoginActionData);
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
};
|
|
|
|
return {
|
|
checkValidSession,
|
|
};
|
|
}
|
|
|
|
export function useSubscriptionGuard() {
|
|
const { subscriptionStatus, isPending } = useSubscription();
|
|
const { openGetProDialog } = useGetProDialogStore();
|
|
|
|
const checkValidSubscription = () => {
|
|
if (isPending) return false;
|
|
|
|
if (!subscriptionStatus) return false;
|
|
|
|
const { isSubscribed, requestsRemaining } = subscriptionStatus;
|
|
|
|
if (isSubscribed) return true;
|
|
|
|
if (requestsRemaining <= 0) {
|
|
openGetProDialog();
|
|
return false;
|
|
}
|
|
|
|
return true; // Allow if not subscribed but still has requests left
|
|
};
|
|
|
|
// Use this guard for features that are Pro only, not including free pro usage
|
|
const checkValidProSubscription = () => {
|
|
if (isPending) return false;
|
|
|
|
if (!subscriptionStatus) return false;
|
|
|
|
const { isSubscribed } = subscriptionStatus;
|
|
|
|
if (isSubscribed) return true;
|
|
|
|
openGetProDialog();
|
|
return false;
|
|
};
|
|
|
|
return {
|
|
checkValidSubscription,
|
|
checkValidProSubscription,
|
|
};
|
|
}
|