Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions src/main/providerService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,15 +147,15 @@ export class ProviderService {
checkedAt: number;
}>();

private readonly contextProviders: Array<import("./context/types").ContextProvider>;

constructor(
private readonly storage: AppStorage,
private readonly secureConfig: SecureConfig
) {}

private get contextProviders() {
return [
new TodoContextProvider(this.storage),
new NotesContextProvider(this.storage)
) {
this.contextProviders = [
new TodoContextProvider(storage),
new NotesContextProvider(storage)
];
}

Expand Down Expand Up @@ -495,10 +495,11 @@ export class ProviderService {
});

let finalCitations: Citation[] = [];
const systemPrompt = await buildSystemPrompt(this.contextProviders, request.prompt);
const braveApiKey = await this.secureConfig.getToolApiKey("brave");
const toolToggles = (await this.storage.getSettings()).toolToggles;
const toolExecutors = buildToolExecutors(braveApiKey, toolToggles);
const [systemPrompt, braveApiKey] = await Promise.all([
buildSystemPrompt(this.contextProviders, request.prompt),
this.secureConfig.getToolApiKey("brave")
]);
const toolExecutors = buildToolExecutors(braveApiKey, settings.toolToggles);
const toolDefs = getToolDefinitions(toolExecutors);

const onDelta = (delta: string) => {
Expand Down
4 changes: 1 addition & 3 deletions src/main/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,7 @@ export class AppStorage {

async getSettings(): Promise<SettingsData> {
const raw = await this.readJson<unknown>(this.settingsPath, DEFAULT_SETTINGS);
const normalized = normalizeSettings(raw);
await this.writeJson(this.settingsPath, normalized);
return normalized;
return normalizeSettings(raw);
}

async saveSettings(updater: (current: SettingsData) => SettingsData): Promise<SettingsData> {
Expand Down
2 changes: 1 addition & 1 deletion src/main/tools/fetchUrl.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ToolExecutor } from "./types";

const MAX_CONTENT_CHARS = 30_000;
const FETCH_TIMEOUT_MS = 15_000;
const FETCH_TIMEOUT_MS = 8_000;
const USER_AGENT = "Robin/1.0 (Personal AI Assistant)";

function stripHtml(html: string): string {
Expand Down
2 changes: 1 addition & 1 deletion src/main/tools/webSearch.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ToolExecutor } from "./types";

const SEARCH_TIMEOUT_MS = 10_000;
const SEARCH_TIMEOUT_MS = 6_000;

interface BraveWebResult {
title?: string;
Expand Down
30 changes: 19 additions & 11 deletions src/renderer/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import "@fontsource/gochi-hand";
import "@fontsource/dm-sans/500.css";
import ReactMarkdown from "react-markdown";
import remarkGfm from "remark-gfm";

const REMARK_PLUGINS = [remarkGfm];
import {
AssistantMode,
CLOUD_PROVIDER_IDS,
Expand Down Expand Up @@ -738,8 +740,13 @@ export function App() {
});
}

const scrollTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);
useEffect(() => {
chatEndRef.current?.scrollIntoView({ behavior: "smooth" });
if (scrollTimerRef.current) clearTimeout(scrollTimerRef.current);
scrollTimerRef.current = setTimeout(() => {
chatEndRef.current?.scrollIntoView({ behavior: "smooth" });
}, 80);
return () => { if (scrollTimerRef.current) clearTimeout(scrollTimerRef.current); };
}, [messages.length, messages[messages.length - 1]?.content]);

const localModels = ollamaStatus?.models ?? [];
Expand Down Expand Up @@ -1665,15 +1672,14 @@ export function App() {
setError(null);
const streamToken = streamSequenceRef.current + 1;
streamSequenceRef.current = streamToken;
if (streamWatchdogRef.current) {
clearTimeout(streamWatchdogRef.current);
}
streamWatchdogRef.current = setTimeout(() => {
if (streamToken !== streamSequenceRef.current) {
return;
}
void stopPendingResponse("Model response timed out. Press Stop and retry.");
}, 30000);
const resetWatchdog = () => {
if (streamWatchdogRef.current) clearTimeout(streamWatchdogRef.current);
streamWatchdogRef.current = setTimeout(() => {
if (streamToken !== streamSequenceRef.current) return;
void stopPendingResponse("Model response timed out. Press Stop and retry.");
}, 60000);
};
resetWatchdog();
setIsStreaming(true);
const text = prompt.trim();
const outgoingAttachments = pendingAttachments;
Expand Down Expand Up @@ -1701,6 +1707,7 @@ export function App() {
if (streamToken !== streamSequenceRef.current) {
return;
}
resetWatchdog();
queueDelta(messageId, delta);
},
onCitations: ({ messageId, citations }) => {
Expand All @@ -1720,6 +1727,7 @@ export function App() {
setTodos(updatedTodos);
},
onToolStatus: ({ toolName, status }) => {
resetWatchdog();
if (status === "calling") {
setToolStatus({ toolName, status });
} else {
Expand Down Expand Up @@ -2699,7 +2707,7 @@ export function App() {
) : null}
{message.role === "assistant" ? (
<div className="md-content">
<ReactMarkdown remarkPlugins={[remarkGfm]}>
<ReactMarkdown remarkPlugins={REMARK_PLUGINS}>
{message.content}
</ReactMarkdown>
</div>
Expand Down
Loading