Add a model picker and support for the OpenAI API

This commit is contained in:
James Babcock committed 2026-07-26 13:09:28 -07:00
1 parent 1c2e445519
commit ccdeedd687
13 files changed
+688 -131

No files matched your search

+21 -6
View File
@@ -7,13 +7,16 @@ import { MenuLayer, type MenuItem } from "../menu";
import { VoiceInputLayer, type VoiceSendTarget } from "../apps/voice-input";
import { AssistantLayer } from "../apps/assistant";
import { AssistantSession } from "../../assistant/session";
import { resolveAssistantModel, type ResolvedAssistantModel } from "../../assistant/models";
import type { AssistantContext } from "../../assistant/types";
import { SingleNotificationLayer } from "../notifications";
import {
anthropicApiKeySetting,
assistantModelSetting,
assistantSkipConfirmationSetting,
batteryDisplayModeSetting,
onAnySettingChanged,
openAiApiKeySetting,
timeFormatSetting,
wakeWordActionSetting,
} from "../dashboard-settings";
@@ -673,18 +676,30 @@ class Shell {
}
private isAssistantAvailable(): boolean {
return anthropicApiKeySetting.get().trim().length > 0;
return this.resolveAssistantConfiguration() !== null;
}
private ensureAssistantSession(): AssistantSession | null {
const apiKey = anthropicApiKeySetting.get().trim();
if (!apiKey) return null;
if (!this.assistantSession || this.assistantSession.isExpired()) {
this.assistantSession = new AssistantSession(apiKey);
const llm = this.resolveAssistantConfiguration();
if (!llm) return null;
if (
!this.assistantSession ||
this.assistantSession.isExpired() ||
!this.assistantSession.matchesConfiguration(llm)
) {
this.assistantSession?.cancel();
this.assistantSession = new AssistantSession(llm);
}
return this.assistantSession;
}
private resolveAssistantConfiguration(): ResolvedAssistantModel | null {
return resolveAssistantModel(assistantModelSetting.get(), {
anthropic: anthropicApiKeySetting.get(),
openai: openAiApiKeySetting.get(),
});
}
private buildAssistantContext(): AssistantContext {
const foreground = this.getForegroundApp();
return {
@@ -704,7 +719,7 @@ class Shell {
sendToAssistant(text: string): void {
const session = this.ensureAssistantSession();
if (!session) {
this.showAlert("Set an Anthropic API key in Settings to use the assistant.");
this.showAlert("Set an API key for the selected assistant model in Settings.");
return;
}
if (!this.screenOn) this.wake("sidebar");