From 3c6b4f86cbc3125a0af45a71e1759ecfa0babc81 Mon Sep 17 00:00:00 2001 From: Josh Pinto Date: Sat, 16 Aug 2025 22:28:35 -0400 Subject: [PATCH] :sparkles: Add AI auto-tagging --- package.json | 7 +++---- src/create-destination.tsx | 35 ++++++++++++++++++++++++++++++++++- 2 files changed, 37 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 3c8aedc..4e50490 100644 --- a/package.json +++ b/package.json @@ -32,8 +32,8 @@ "preferences": [ { "name": "ai-tagging", - "title": "AI Tagging", - "description": "Enable AI-tagging for new destinations using your LLM instance.", + "title": "Enable AI Tagging", + "description": "Automatically tag new destinations using AI (requires AI Instance URL)", "type": "checkbox", "required": true, "default": false @@ -44,8 +44,7 @@ "description": "The URL of your LLM instance for AI-tagging", "type": "textfield", "required": false, - "placeholder": "https://ai.hackclub.com", - "default": "https://ai.hackclub.com" + "placeholder": "https://ai.hackclub.com" } ] }, diff --git a/src/create-destination.tsx b/src/create-destination.tsx index 6716d44..88e5c1f 100644 --- a/src/create-destination.tsx +++ b/src/create-destination.tsx @@ -3,7 +3,7 @@ import { useState, useEffect, useRef } from "react"; import { Action, ActionPanel, Form, popToRoot, LaunchProps, Toast, showToast, getPreferenceValues } from "@raycast/api"; import { useForm } from "@raycast/utils"; -import { getWebDetails } from "@regreso/utils"; +import { getWebDetails, SiteTagger } from "@regreso/utils"; import { handleAuthStuff } from "./utils/auth"; import { createDestination } from "./utils/destination"; @@ -32,6 +32,7 @@ export default function CreateDestination( props: LaunchProps<{ arguments: Arguments.CreateDestination; draftValues: DestinationFormValues }>, ) { const preferences = getPreferenceValues(); + const [sessionToken, setSessionToken] = useState(""); const [defaultWorkspace, setDefaultWorkspace] = useState(0); @@ -159,6 +160,7 @@ export default function CreateDestination( { + if ( destinationTypeProps.type.value == "location" && destinationTypeProps.location.value != destinationProps.location.value && @@ -177,6 +179,7 @@ export default function CreateDestination( return; } destinationProps.type.onChange("location"); + destinationProps.headline.onChange( webDetails.title[0] ?? webDetails.title[1] ?? @@ -189,7 +192,37 @@ export default function CreateDestination( ); destinationProps.location.onChange(webDetails.url); destinationTypeProps.location.onChange(webDetails.url); + tagsInputRef.current?.focus(); + + if ( + preferences["ai-tagging"] && + preferences["ai-instance"] != undefined && + preferences["ai-instance"] != "" + ) { + const tagger = new SiteTagger({ + maxTags: 3, + + aiInstance: preferences["ai-instance"], + + maxRetries: 2, + }); + + const result = await tagger.generateTags({ + url: destinationTypeProps.location.value, + headline: destinationProps.headline.value, + description: destinationProps.body.value, + }); + if (result.success) { + destinationProps.tags.onChange(result.tags.join(", ")); + } else { + showToast({ + style: Toast.Style.Failure, + title: "Failed to generate tags", + message: "Error: " + result.error, + }); + } + } } }} /> -- 2.51.2