From 58c3dc798ae659f441e05c315e9931f8d5a144c5 Mon Sep 17 00:00:00 2001 From: "Jose F. Romaniello" Date: Thu, 10 Oct 2024 12:40:54 -0300 Subject: [PATCH] remove all Google Task related code --- app/actions.tsx | 2 - components/auth0/user-profile.tsx | 9 +-- database/market0/V014__remove_reminders.sql | 4 + lib/db/index.ts | 1 - lib/db/reminders.ts | 75 ------------------- lib/examples.tsx | 5 -- llm/actions/continue-conversation.tsx | 2 - llm/actions/reminders.ts | 61 ---------------- llm/components/reminder.tsx | 81 --------------------- llm/components/serialization.tsx | 2 - llm/tools/schedule/add-reminder.tsx | 48 ------------ sdk/auth0/3rd-party-apis/index.tsx | 8 +- 12 files changed, 7 insertions(+), 291 deletions(-) create mode 100644 database/market0/V014__remove_reminders.sql delete mode 100644 lib/db/reminders.ts delete mode 100644 llm/actions/reminders.ts delete mode 100644 llm/components/reminder.tsx delete mode 100644 llm/tools/schedule/add-reminder.tsx diff --git a/app/actions.tsx b/app/actions.tsx index bd7aac9..f7de385 100644 --- a/app/actions.tsx +++ b/app/actions.tsx @@ -7,7 +7,6 @@ import { saveAIStateToStore } from "@/lib/db"; import { confirmPurchase } from "@/llm/actions/confirm-purchase"; import { continueConversation } from "@/llm/actions/continue-conversation"; import { checkEnrollment } from "@/llm/actions/newsletter"; -import { createGoogleTask } from "@/llm/actions/reminders"; import * as serialization from "@/llm/components/serialization"; import { ClientMessage, ServerMessage } from "@/llm/types"; import { getUser as fetchUser } from "@/sdk/auth0/mgmt"; @@ -24,7 +23,6 @@ export const AI = (p: Props) => { actions: { continueConversation, confirmPurchase, - createGoogleTask, checkEnrollment, }, onSetAIState: async ({ state, done }) => { diff --git a/components/auth0/user-profile.tsx b/components/auth0/user-profile.tsx index d4dedee..45b031a 100644 --- a/components/auth0/user-profile.tsx +++ b/components/auth0/user-profile.tsx @@ -68,17 +68,12 @@ export default function UserProfile({ user }: { user: KeyValueMap }) { {currentItem === "connected-accounts" && ( ({ - ...reminder, - due: new Date(reminder.due), - created_at: new Date(reminder.created_at), - updated_at: new Date(reminder.updated_at), -}); - -export const create = async ({ - user_id, - title, - due, - notes, - google_task_id, - link -}: CreateReminderParams): Promise => { - const result = await sql` - INSERT INTO reminders (user_id, title, due, notes, google_task_id, link) - VALUES (${user_id}, ${title}, ${due}, ${notes}, ${google_task_id ?? null}, ${link ?? null}) - RETURNING * - `; - - return mapReminderFromDB(result[0]); -}; - -export const update = async ( - id: string, - params: Omit, "id" | "user_id" | "created_at" | "updated_at"> -) => { - // ${sql(params, "title", "due", "notes", "google_task_id", "link")} - - const result = await sql` - UPDATE reminders - SET title = COALESCE(${params.title ?? null}, title), - due = COALESCE(${params.due ?? null}, due), - notes = COALESCE(${params.notes ?? null}, notes), - google_task_id = COALESCE(${params.google_task_id ?? null}, google_task_id), - link = COALESCE(${params.link ?? null}, link) - WHERE id = ${id} - RETURNING * - `; - - return result.length > 0 ? mapReminderFromDB(result[0]) : null; -} - -export const getByID = async (user_id: string, id: string): Promise => { - const result = await sql` - SELECT * FROM reminders - WHERE user_id = ${user_id} AND id = ${id} - `; - - return result.length > 0 ? mapReminderFromDB(result[0]) : null; -} diff --git a/lib/examples.tsx b/lib/examples.tsx index 940d139..bc69f97 100644 --- a/lib/examples.tsx +++ b/lib/examples.tsx @@ -59,9 +59,4 @@ export const menuItems = [ message: "Buy 10 ZEKO when P/E ratio is above 0", icon: , }, - { - id: generateId(), - message: "Remind me to buy ZEKO in two weeks", - icon: , - }, ]; diff --git a/llm/actions/continue-conversation.tsx b/llm/actions/continue-conversation.tsx index 3570a69..48b6e7f 100644 --- a/llm/actions/continue-conversation.tsx +++ b/llm/actions/continue-conversation.tsx @@ -12,7 +12,6 @@ import checkSubscription from "@/llm/tools/newsletter/check-subscription"; import setSubscription from "@/llm/tools/newsletter/set-subscription"; import setEmployeer from "@/llm/tools/profile/set-employeer"; import setProfileAttributes from "@/llm/tools/profile/set-profile-attributes"; -import addReminder from "@/llm/tools/schedule/add-reminder"; import getEvents from "@/llm/tools/schedule/get-events"; import addConditionalPurchase from "@/llm/tools/trading/add-conditional-purchase"; import getForecasts from "@/llm/tools/trading/get-forecasts"; @@ -87,7 +86,6 @@ export async function continueConversation( }, tools: await composeTools( showStockPurchaseUI, - addReminder, addConditionalPurchase, showStockPrice, showCurrentPositions, diff --git a/llm/actions/reminders.ts b/llm/actions/reminders.ts deleted file mode 100644 index a72e0cd..0000000 --- a/llm/actions/reminders.ts +++ /dev/null @@ -1,61 +0,0 @@ -"use server"; - -import { getByID, Reminder, update } from "@/lib/db/reminders"; -import { withGoogleApi } from "@/sdk/auth0/3rd-party-apis/providers/google"; -import { getUser } from "@/sdk/fga"; - -/** - * Create the reminder in google tasks. - * - * @param reminder - The reminder to create. - * @returns - */ -export async function createGoogleTask(reminder: Reminder) { - return withGoogleApi(async function (accessToken: string) { - const reminderFromDB = await getByID(reminder.user_id, reminder.id); - if (reminderFromDB && reminderFromDB.google_task_id) { - return reminderFromDB; - } - const url = 'https://tasks.googleapis.com/tasks/v1/lists/@default/tasks'; - - const res = await fetch( - url, - { - method: "POST", - headers: { - Authorization: `Bearer ${accessToken}`, - "Content-Type": "application/json", - }, - body: JSON.stringify({ - title: reminder.title, - due: reminder.due.toISOString(), - notes: reminder.notes, - links: reminder.link ? [ - { - type: "email", - description: "Conversation link", - link: reminder.link - } - ] : undefined - }), - } - ); - - if (!res.ok) { - throw new Error(`Error creating event: ${await res.text()}`); - } - - const response = await res.json(); - - console.log(`reminders created ${JSON.stringify(response)}`); - return await update(reminder.id, { google_task_id: response.id }); - }) -} - -export async function getReminderById(reminderId: string): Promise { - 'use server'; - const user = await getUser(); - const reminder = await getByID(user.sub, reminderId); - if (!reminder) { return null; } - return reminder; -} diff --git a/llm/components/reminder.tsx b/llm/components/reminder.tsx deleted file mode 100644 index 30bc1e2..0000000 --- a/llm/components/reminder.tsx +++ /dev/null @@ -1,81 +0,0 @@ -"use client"; - -import { format } from "date-fns"; -import { useCallback, useEffect, useState } from "react"; - -import { ExternalLink } from "@/components/icons"; -import Loader from "@/components/loader"; -import { Reminder as ReminderType } from "@/lib/db/reminders"; -import { createGoogleTask, getReminderById } from "@/llm/actions/reminders"; -import { EnsureAPIAccess } from "@/sdk/components/ensure-api-access"; - -export function Reminder({ reminderID }: { reminderID: string }) { - const [isWorking, setIsWorking] = useState(true); - const [reminder, setReminder] = useState(null); - - const shouldCheckAuthorization = useCallback(() => { - return !!reminder && !reminder.google_task_id; - }, [reminder]); - - const onUserAuthorized = useCallback(async () => { - if (reminder && !reminder.google_task_id) { - setReminder(await createGoogleTask(reminder)); - } - }, [reminder]); - - useEffect(() => { - (async () => { - let reminder = await getReminderById(reminderID); - - if (!reminder) { - setIsWorking(false); - return; - } - - setReminder(reminder); - setIsWorking(false); - })(); - }, [reminderID]); - - if (isWorking) { - return ; - } - - return ( - - {reminder && ( -
-
-

{reminder.title}

-

- Google Task created at {format(reminder.due, "dd LLL, yyyy")}. -

-
- -
- )} - {!reminder &&
Reminder not found
} -
- ); -} diff --git a/llm/components/serialization.tsx b/llm/components/serialization.tsx index 3ee2c51..d7bcbfa 100644 --- a/llm/components/serialization.tsx +++ b/llm/components/serialization.tsx @@ -3,7 +3,6 @@ import { Documents } from "./documents"; import { Events } from "./events"; import { FormattedText } from "./FormattedText"; import { Positions } from "./positions"; -import { Reminder } from "./reminder"; import { SimpleMessage } from "./simple-message"; import { Stock } from "./stock"; import { StockPurchase } from "./stock-purchase"; @@ -17,7 +16,6 @@ export const components = { Stocks, SimpleMessage, StockPurchase, - Reminder, ConditionalPurchase, FormattedText, }; diff --git a/llm/tools/schedule/add-reminder.tsx b/llm/tools/schedule/add-reminder.tsx deleted file mode 100644 index 1c294e2..0000000 --- a/llm/tools/schedule/add-reminder.tsx +++ /dev/null @@ -1,48 +0,0 @@ -import { headers } from "next/headers"; -import { z } from "zod"; - -import Loader from "@/components/loader"; -import { reminders } from "@/lib/db"; -import { defineTool } from "@/llm/ai-helpers"; -import { Reminder } from "@/llm/components/reminder"; -import * as serialization from "@/llm/components/serialization"; -import { getHistory } from "@/llm/utils"; -import { getUser } from "@/sdk/fga"; - -export default defineTool("add_reminder", async () => { - const history = getHistory(); - - return { - description: `Add a reminder to the current user's calendar`, - parameters: z.object({ - due: z - .string() - .describe("The due date of the reminder, in ISO-8601 format"), - title: z.string().describe("The title of the reminder"), - }), - generate: async function* ({ due, title }: { due: string; title: string }) { - yield ; - - const user = await getUser(); - const hs = headers(); - - //Store the reminder in Market0 db - let reminder = await reminders.create({ - due: new Date(due), - title, - user_id: user.sub, - notes: `Created from Market0`, - link: hs.get("referer") ?? undefined, - }); - - history.update({ - role: "assistant", - content: `Added reminder to Google Tasks`, - componentName: serialization.names.get(Reminder)!, - params: { reminderID: reminder.id }, - }); - - return ; - }, - }; -}); diff --git a/sdk/auth0/3rd-party-apis/index.tsx b/sdk/auth0/3rd-party-apis/index.tsx index 728074b..9ce3b1a 100644 --- a/sdk/auth0/3rd-party-apis/index.tsx +++ b/sdk/auth0/3rd-party-apis/index.tsx @@ -1,7 +1,7 @@ import { getSession } from "@auth0/nextjs-auth0"; -import * as google from "./providers/google"; import * as box from "./providers/box"; +import * as google from "./providers/google"; const PROVIDERS_APIS = [ { @@ -9,17 +9,11 @@ const PROVIDERS_APIS = [ api: "google-calendar", requiredScopes: ["https://www.googleapis.com/auth/calendar.events"], }, - { - name: "google", - api: "google-tasks", - requiredScopes: ["https://www.googleapis.com/auth/tasks"], - }, { name: "google", api: "google-all", requiredScopes: [ "https://www.googleapis.com/auth/calendar.events", - "https://www.googleapis.com/auth/tasks", ], }, {