feat: load available AI models from Raycast

This commit is contained in:
muena
2026-12-02 08:53:37 +01:00
parent 019f6b6d7c
commit b630093075
6 changed files with 28 additions and 82 deletions

View File

@@ -141,7 +141,7 @@ Alle Werte sind in den Raycast-Einstellungen pro Extension einstellbar.
- `Ausgabe der Schnellbefehle` — `In die Zwischenablage kopieren` (Default) oder `Am Cursor einfügen` - `Ausgabe der Schnellbefehle` — `In die Zwischenablage kopieren` (Default) oder `Am Cursor einfügen`
- `Eigener Name` — Default-Signatur für AI-generierte Email-Antworten, im Antwort-Befehl pro Aufruf überschreibbar - `Eigener Name` — Default-Signatur für AI-generierte Email-Antworten, im Antwort-Befehl pro Aufruf überschreibbar
Das KI-Modell ist keine Preference: jeder AI-Befehl zeigt ein `KI-Modell`-Dropdown mit dem aktuellen Modell-Katalog aus `src/ai.ts`. Die Auswahl wird in `LocalStorage` (`velum.ai.last-model`) persistiert und ist beim nächsten Aufruf in jedem AI-Befehl vorausgewählt. Jeder KI-Befehl bezieht die Auswahl im Feld **KI-Modell** aus `AI.Model` der installierten Raycast-Version. Mit **Raycast-Standard** verwendet Velum das Standardmodell der Raycast-API. Velum merkt sich die letzte Auswahl für alle KI-Befehle. Fehlt das gespeicherte Modell im API-Katalog, ist beim nächsten Aufruf **Raycast-Standard** ausgewählt.
- `Maximale Anzahl gespeicherter Sitzungen` — älteste werden geprunt (Default 20) - `Maximale Anzahl gespeicherter Sitzungen` — älteste werden geprunt (Default 20)
- `Raycast nach Kopieren/Einfügen schließen` — Auto-Close und Pop-To-Root nach AI-Workflow-Abschluss (Default an) - `Raycast nach Kopieren/Einfügen schließen` — Auto-Close und Pop-To-Root nach AI-Workflow-Abschluss (Default an)

View File

@@ -15,7 +15,7 @@ import {
} from "@raycast/api"; } from "@raycast/api";
import { marked } from "marked"; import { marked } from "marked";
import { type ReactNode, useEffect, useRef, useState } from "react"; import { type ReactNode, useEffect, useRef, useState } from "react";
import type { Creativity } from "./ai"; import { resolveRaycastModel, type Creativity } from "./ai";
import { getPreferences } from "./preferences"; import { getPreferences } from "./preferences";
import type { VelumSession } from "./types"; import type { VelumSession } from "./types";
import { markdownCodeBlock, mappingDetailTable, sessionSubtitle } from "./ui"; import { markdownCodeBlock, mappingDetailTable, sessionSubtitle } from "./ui";
@@ -143,7 +143,7 @@ export function AiStreamResult(props: PseudoStageProps) {
try { try {
const prompt = buildPrompt(pseudonymizedText, instructions); const prompt = buildPrompt(pseudonymizedText, instructions);
const stream = AI.ask(prompt, { const stream = AI.ask(prompt, {
model: model as AI.Model, model: resolveRaycastModel(model),
creativity, creativity,
signal: controller.signal, signal: controller.signal,
}); });

View File

@@ -1,4 +1,4 @@
import { LocalStorage } from "@raycast/api"; import { AI, LocalStorage } from "@raycast/api";
export type Creativity = "none" | "low" | "medium" | "high"; export type Creativity = "none" | "low" | "medium" | "high";
@@ -9,86 +9,29 @@ export const CREATIVITY_OPTIONS: Creativity[] = [
"high", "high",
]; ];
export type ModelOption = { value: string; title: string }; export const DEFAULT_MODEL = "__raycast_default__";
export const MODEL_OPTIONS: ModelOption[] = [
{ value: "anthropic-claude-opus-4-7", title: "Claude 4.7 Opus" },
{ value: "anthropic-claude-sonnet-4-6", title: "Claude 4.6 Sonnet" },
{ value: "anthropic-claude-opus-4-6", title: "Claude 4.6 Opus" },
{ value: "anthropic-claude-sonnet-4-5", title: "Claude 4.5 Sonnet" },
{ value: "anthropic-claude-opus-4-5", title: "Claude 4.5 Opus" },
{ value: "anthropic-claude-4-5-haiku", title: "Claude 4.5 Haiku" },
{ value: "anthropic-claude-sonnet-4", title: "Claude 4 Sonnet" },
{ value: "openai-gpt-5.4", title: "OpenAI GPT-5.4" },
{ value: "openai-gpt-5.4-mini", title: "OpenAI GPT-5.4 Mini" },
{ value: "openai-gpt-5.4-nano", title: "OpenAI GPT-5.4 Nano" },
{ value: "openai-gpt-5.3-instant", title: "OpenAI GPT-5.3 Instant" },
{ value: "openai-gpt-5.3-codex", title: "OpenAI GPT-5.3 Codex" },
{ value: "openai-gpt-5.2", title: "OpenAI GPT-5.2" },
{ value: "openai-gpt-5.2-instant", title: "OpenAI GPT-5.2 Instant" },
{ value: "openai-gpt-5.1", title: "OpenAI GPT-5.1" },
{ value: "openai-gpt-5.1-instant", title: "OpenAI GPT-5.1 Instant" },
{ value: "openai-gpt-5.1-codex", title: "OpenAI GPT-5.1 Codex" },
{ value: "openai_o1-gpt-5", title: "OpenAI GPT-5" },
{ value: "openai-gpt-5-mini", title: "OpenAI GPT-5 Mini" },
{ value: "openai-gpt-5-nano", title: "OpenAI GPT-5 Nano" },
{ value: "openai-gpt-4.1", title: "OpenAI GPT-4.1" },
{ value: "openai-gpt-4.1-mini", title: "OpenAI GPT-4.1 Mini" },
{ value: "openai-gpt-4.1-nano", title: "OpenAI GPT-4.1 Nano" },
{ value: "openai-gpt-4o", title: "OpenAI GPT-4o" },
{ value: "openai-gpt-4o-mini", title: "OpenAI GPT-4o mini" },
{ value: "openai_o1-o3", title: "OpenAI o3" },
{ value: "openai_o1-o3-mini", title: "OpenAI o3-mini" },
{ value: "openai_o1-o4-mini", title: "OpenAI o4-mini" },
{ value: "openai_o1-o1", title: "OpenAI o1" },
{ value: "google-gemini-3.1-pro", title: "Google Gemini 3.1 Pro" },
{ value: "google-gemini-3-flash", title: "Google Gemini 3 Flash" },
{
value: "google-gemini-3.1-flash-lite",
title: "Google Gemini 3.1 Flash Lite",
},
{ value: "google-gemini-2.5-pro", title: "Google Gemini 2.5 Pro" },
{ value: "google-gemini-2.5-flash", title: "Google Gemini 2.5 Flash" },
{
value: "google-gemini-2.5-flash-lite",
title: "Google Gemini 2.5 Flash Lite",
},
{ value: "xai-grok-4.20", title: "xAI Grok 4.20" },
{ value: "xai-grok-4", title: "xAI Grok 4" },
{ value: "xai-grok-4-fast", title: "xAI Grok 4 Fast" },
{ value: "xai-grok-4-1-fast", title: "xAI Grok 4.1 Fast" },
{ value: "xai-grok-code-fast", title: "xAI Grok Code Fast" },
{ value: "perplexity-sonar-pro", title: "Perplexity Sonar Pro" },
{ value: "perplexity-sonar", title: "Perplexity Sonar" },
{ value: "mistral-mistral-large-latest", title: "Mistral Large" },
{ value: "mistral-mistral-medium-latest", title: "Mistral Medium" },
{ value: "mistral-mistral-small-latest", title: "Mistral Small" },
{ value: "mistral-codestral-latest", title: "Mistral Codestral" },
{ value: "mistral-open-mistral-nemo", title: "Mistral Nemo" },
{ value: "groq-llama-3.3-70b-versatile", title: "Groq Llama 3.3 70B" },
{
value: "groq-meta-llama/llama-4-scout-17b-16e-instruct",
title: "Groq Llama 4 Scout",
},
{ value: "groq-llama-3.1-8b-instant", title: "Groq Llama 3.1 8B" },
{ value: "groq-qwen/qwen3-32b", title: "Groq Qwen3 32B" },
{ value: "groq-openai/gpt-oss-120b", title: "Groq GPT-OSS 120B" },
{ value: "groq-openai/gpt-oss-20b", title: "Groq GPT-OSS 20B" },
{ value: "together-deepseek-ai/DeepSeek-R1", title: "DeepSeek R1" },
{ value: "together-deepseek-ai/DeepSeek-V3", title: "DeepSeek V3" },
{ value: "together-moonshotai/Kimi-K2.5", title: "Kimi K2.5" },
];
const LAST_MODEL_STORAGE_KEY = "velum.ai.last-model"; const LAST_MODEL_STORAGE_KEY = "velum.ai.last-model";
export const DEFAULT_MODEL: string = MODEL_OPTIONS[0].value; // Raycast lists current names before compatibility aliases for the same model ID.
const raycastModels = new Map<string, { value: AI.Model; title: string }>();
for (const [name, value] of Object.entries(AI.Model)) {
if (!raycastModels.has(value)) {
raycastModels.set(value, { value, title: name.replaceAll("_", " ") });
}
}
export const MODEL_OPTIONS = [
{ value: DEFAULT_MODEL, title: "Raycast-Standard" },
...raycastModels.values(),
];
export function resolveRaycastModel(selection: string): AI.Model | undefined {
return raycastModels.get(selection)?.value;
}
export async function getLastUsedModel(): Promise<string> { export async function getLastUsedModel(): Promise<string> {
const stored = await LocalStorage.getItem<string>(LAST_MODEL_STORAGE_KEY); const stored = await LocalStorage.getItem<string>(LAST_MODEL_STORAGE_KEY);
if (stored && MODEL_OPTIONS.some((option) => option.value === stored)) { return stored && raycastModels.has(stored) ? stored : DEFAULT_MODEL;
return stored;
}
return DEFAULT_MODEL;
} }
export async function setLastUsedModel(model: string): Promise<void> { export async function setLastUsedModel(model: string): Promise<void> {

View File

@@ -20,6 +20,7 @@ import {
DEFAULT_MODEL, DEFAULT_MODEL,
getLastUsedModel, getLastUsedModel,
MODEL_OPTIONS, MODEL_OPTIONS,
resolveRaycastModel,
setLastUsedModel, setLastUsedModel,
} from "./ai"; } from "./ai";
import { getPreferences } from "./preferences"; import { getPreferences } from "./preferences";
@@ -560,7 +561,7 @@ function ReplyResult(props: StageProps) {
instructions: props.instructions, instructions: props.instructions,
}); });
const stream = AI.ask(prompt, { const stream = AI.ask(prompt, {
model: props.model as AI.Model, model: resolveRaycastModel(props.model),
creativity: props.creativity, creativity: props.creativity,
signal: controller.signal, signal: controller.signal,
}); });

View File

@@ -27,6 +27,7 @@ import {
DEFAULT_MODEL, DEFAULT_MODEL,
getLastUsedModel, getLastUsedModel,
MODEL_OPTIONS, MODEL_OPTIONS,
resolveRaycastModel,
setLastUsedModel, setLastUsedModel,
} from "./ai"; } from "./ai";
import { buildSummaryPrompt, type Creativity } from "./summarize"; import { buildSummaryPrompt, type Creativity } from "./summarize";
@@ -354,7 +355,7 @@ function SummarizeEmailResult({
try { try {
const prompt = buildSummaryPrompt(pseudonymizedText, instructions); const prompt = buildSummaryPrompt(pseudonymizedText, instructions);
const stream = AI.ask(prompt, { const stream = AI.ask(prompt, {
model: model as AI.Model, model: resolveRaycastModel(model),
creativity, creativity,
signal: controller.signal, signal: controller.signal,
}); });

View File

@@ -1,4 +1,5 @@
import { AI } from "@raycast/api"; import { AI } from "@raycast/api";
import { resolveRaycastModel } from "./ai";
export type Creativity = "none" | "low" | "medium" | "high"; export type Creativity = "none" | "low" | "medium" | "high";
@@ -54,7 +55,7 @@ export async function runSummaryStream(
): Promise<string> { ): Promise<string> {
let buffer = ""; let buffer = "";
const stream = AI.ask(options.prompt, { const stream = AI.ask(options.prompt, {
model: options.model as AI.Model, model: resolveRaycastModel(options.model),
creativity: options.creativity, creativity: options.creativity,
signal: options.signal, signal: options.signal,
}); });