This commit is contained in:
Timothy Jaeryang Baek committed 2026-06-11 13:38:55 +01:00
1 parent 74a1c26713
commit 046864f6e4
6 files changed
+184 -20

No files matched your search

+1 -1
View File
@@ -67,7 +67,7 @@ export const sendMessage = (
workspace: string,
chatId?: string,
parentId?: string | null,
params: { tool_approval_mode?: string } = {},
params: { tool_approval_mode?: string; plan_mode?: boolean; request_params?: Record<string, unknown> } = {},
regenerationPrompt?: string,
files?: { id: string; name: string; url: string; type: string }[]
) =>
@@ -29,7 +29,8 @@
toolApprovalMode,
planMode,
streamingBehavior,
selectedModelId
selectedModelId,
requestParams
} from '$lib/stores';
import ChatInput from './ChatInput.svelte';
@@ -552,7 +553,7 @@
workspace,
chatId,
parentId,
{ tool_approval_mode: mode, plan_mode: get(planMode) },
{ tool_approval_mode: mode, plan_mode: get(planMode), request_params: get(requestParams) },
undefined,
files
);
@@ -617,7 +618,7 @@
workspace,
chatId ?? undefined,
parentId,
{ tool_approval_mode: mode, plan_mode: get(planMode) },
{ tool_approval_mode: mode, plan_mode: get(planMode), request_params: get(requestParams) },
undefined,
files
);
@@ -778,7 +779,8 @@
const mode = get(toolApprovalMode);
const result = await apiSendMessage('', selectedModel, workspace, chatId, msg.parent_id, {
tool_approval_mode: mode,
plan_mode: get(planMode)
plan_mode: get(planMode),
request_params: get(requestParams)
});
if (result.assistant_message) {
allMessages = [...allMessages, result.assistant_message];
@@ -821,7 +823,7 @@
workspace,
chatId,
msg.parent_id,
{ tool_approval_mode: get(toolApprovalMode), plan_mode: get(planMode) }
{ tool_approval_mode: get(toolApprovalMode), plan_mode: get(planMode), request_params: get(requestParams) }
);
if (result.user_message && result.assistant_message) {
allMessages = [...allMessages, result.user_message, result.assistant_message];
@@ -1,6 +1,6 @@
<script lang="ts">
import { onMount } from 'svelte';
import { toolApprovalMode, planMode, type ToolApprovalMode } from '$lib/stores';
import { toolApprovalMode, planMode, requestParams, type ToolApprovalMode } from '$lib/stores';
import { tooltip } from '$lib/tooltip';
import Icon from '../Icon.svelte';
import ToggleSwitch from '../common/ToggleSwitch.svelte';
@@ -12,7 +12,7 @@
let { onfiles, oncapture }: Props = $props();
let open = $state(false);
let tab = $state<'' | 'tools'>('');
let tab = $state<'' | 'tools' | 'request_params'>('');
let btnEl: HTMLButtonElement | undefined = $state();
let menuEl: HTMLDivElement | undefined = $state();
let inputEl: HTMLInputElement | undefined = $state();
@@ -30,6 +30,44 @@
modes.find((m) => m.value === $toolApprovalMode)?.label ?? 'Tool permissions'
);
// ── Request params state ────────────────────────
let paramRows = $state<Array<{ key: string; value: string }>>(
Object.entries($requestParams).map(([key, value]) => ({
key,
value: typeof value === 'object' ? JSON.stringify(value) : String(value)
}))
);
const paramCount = $derived(
paramRows.filter((r) => r.key.trim()).length
);
const canAddParam = $derived(
paramRows.length === 0 || paramRows.every((r) => r.key.trim() || r.value.trim())
);
function addParamRow() {
paramRows = [...paramRows, { key: '', value: '' }];
}
function removeParamRow(index: number) {
paramRows = paramRows.filter((_, i) => i !== index);
syncParams();
}
function syncParams() {
const result: Record<string, unknown> = {};
for (const { key, value } of paramRows) {
if (!key.trim()) continue;
try {
result[key.trim()] = JSON.parse(value);
} catch {
result[key.trim()] = value;
}
}
requestParams.set(result);
}
function toggle() {
open = !open;
if (open) {
@@ -129,7 +167,15 @@
if (!open) {
ready = false;
tab = '';
return;
}
// Keep menu anchored on resize/scroll while open
window.addEventListener('resize', updatePosition);
window.addEventListener('scroll', updatePosition, true);
return () => {
window.removeEventListener('resize', updatePosition);
window.removeEventListener('scroll', updatePosition, true);
};
});
</script>
@@ -268,6 +314,31 @@
>
<Icon name="chevron-right" size={12} class="shrink-0 text-gray-400 dark:text-gray-500" />
</button>
<div class="h-px bg-gray-100/50 dark:bg-white/3 mx-1 my-0.5"></div>
<button
class="flex items-center gap-2 w-full h-7 px-2 rounded-xl text-xs text-gray-500 dark:text-gray-400 hover:bg-gray-50 dark:hover:bg-white/5 hover:text-gray-900 dark:hover:text-white transition-colors duration-75"
onclick={() => (tab = 'request_params')}
>
<svg
class="size-3.5 shrink-0"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.5"
stroke-linecap="round"
stroke-linejoin="round"
>
<circle cx="12" cy="12" r="3" />
<path d="M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 0 1 0 2.83 2 2 0 0 1-2.83 0l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-2 2 2 2 0 0 1-2-2v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 0 1-2.83 0 2 2 0 0 1 0-2.83l.06-.06A1.65 1.65 0 0 0 4.68 15a1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1-2-2 2 2 0 0 1 2-2h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 0 1 0-2.83 2 2 0 0 1 2.83 0l.06.06A1.65 1.65 0 0 0 9 4.68a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 2-2 2 2 0 0 1 2 2v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 0 1 2.83 0 2 2 0 0 1 0 2.83l-.06.06A1.65 1.65 0 0 0 19.4 9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 2 2 2 2 0 0 1-2 2h-.09a1.65 1.65 0 0 0-1.51 1z" />
</svg>
<span class="flex-1 text-left truncate">Parameters</span>
{#if paramCount > 0}
<span class="text-[10px] text-gray-400 dark:text-gray-500">{paramCount}</span>
{/if}
<Icon name="chevron-right" size={12} class="shrink-0 text-gray-400 dark:text-gray-500" />
</button>
</div>
{:else if tab === 'tools'}
<!-- Tool permissions submenu -->
@@ -308,6 +379,70 @@
</button>
{/each}
</div>
{:else if tab === 'request_params'}
<!-- Request params submenu -->
<div class="plus-menu-slide-in-right">
<button
class="flex items-center gap-2 w-full h-7 px-2 rounded-xl text-xs text-gray-500 dark:text-gray-400 hover:bg-gray-50 dark:hover:bg-white/5 hover:text-gray-900 dark:hover:text-white transition-colors duration-75"
onclick={() => (tab = '')}
>
<Icon name="chevron-left" size={12} />
<span class="flex-1 text-left font-medium">Parameters</span>
</button>
<div class="h-px bg-gray-100/50 dark:bg-white/3 mx-1 my-0.5"></div>
{#if paramRows.length === 0}
<p class="px-2 h-7 flex items-center justify-center text-[11px] text-gray-400 dark:text-gray-500">No parameters configured</p>
{:else}
<div class="px-0.5 py-0.5 flex flex-col max-h-48 overflow-y-auto">
{#each paramRows as row, i}
<div class="group flex items-center gap-1 px-1.5 h-7">
<input
type="text"
placeholder="key"
bind:value={row.key}
onblur={syncParams}
autocomplete="off"
spellcheck="false"
class="w-[72px] shrink-0 bg-transparent text-[11px] font-mono text-gray-700 dark:text-gray-300 placeholder:text-gray-300 dark:placeholder:text-gray-600 outline-none"
/>
<input
type="text"
placeholder="value"
bind:value={row.value}
onblur={syncParams}
autocomplete="off"
spellcheck="false"
class="flex-1 min-w-0 bg-transparent text-[11px] font-mono text-gray-700 dark:text-gray-300 placeholder:text-gray-300 dark:placeholder:text-gray-600 outline-none"
/>
<button
type="button"
onclick={() => removeParamRow(i)}
class="shrink-0 p-0.5 text-gray-300 dark:text-gray-700 opacity-0 group-hover:opacity-100 hover:text-gray-500 dark:hover:text-gray-400 transition-all"
aria-label="Remove parameter"
>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" class="size-3">
<path d="M6.28 5.22a.75.75 0 00-1.06 1.06L8.94 10l-3.72 3.72a.75.75 0 101.06 1.06L10 11.06l3.72 3.72a.75.75 0 101.06-1.06L11.06 10l3.72-3.72a.75.75 0 00-1.06-1.06L10 8.94 6.28 5.22z"/>
</svg>
</button>
</div>
{/each}
</div>
{/if}
<button
class="flex items-center gap-2 w-full h-7 px-2 rounded-xl text-xs text-gray-500 dark:text-gray-400 hover:bg-gray-50 dark:hover:bg-white/5 hover:text-gray-900 dark:hover:text-white transition-colors duration-75 disabled:opacity-30 disabled:pointer-events-none"
onclick={addParamRow}
disabled={!canAddParam}
>
<svg class="size-3 shrink-0" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<line x1="12" y1="5" x2="12" y2="19" />
<line x1="5" y1="12" x2="19" y2="12" />
</svg>
<span class="flex-1 text-left">Add parameter</span>
</button>
</div>
{/if}
</div>
{/if}
+8 -1
View File
@@ -76,6 +76,7 @@ export interface UserPreferences {
keybindings?: Record<string, string>; // user-customised keyboard shortcuts
version?: string; // last seen app version for changelog
selectedModelId?: string; // last selected chat model, synced across browsers
requestParams?: Record<string, unknown>; // arbitrary params merged into API request body
}
export type Theme = 'dark' | 'light' | 'system';
@@ -135,6 +136,7 @@ export const sidebarWidth = writable(220);
export const theme = writable<Theme>('dark');
export const toolApprovalMode = writable<ToolApprovalMode>('auto');
export const planMode = writable(false);
export const requestParams = writable<Record<string, unknown>>({});
export const appVersion = writable('');
export const lastSeenVersion = writable('');
export const showChangelog = writable(false);
@@ -285,7 +287,8 @@ function persistPreferences(): void {
workspaceOrder: get(workspaceOrder),
keybindings: get(keybindings),
version: get(lastSeenVersion),
selectedModelId: get(selectedModelId) || undefined
selectedModelId: get(selectedModelId) || undefined,
requestParams: Object.keys(get(requestParams)).length ? get(requestParams) : undefined
};
savePreferences(prefs as unknown as Record<string, unknown>).catch(() => {});
}, 300);
@@ -313,6 +316,9 @@ function subscribeForPersistence() {
planMode.subscribe(() => {
if (get(stateLoaded)) persistPreferences();
});
requestParams.subscribe(() => {
if (get(stateLoaded)) persistPreferences();
});
workspaceOrder.subscribe(() => {
if (get(stateLoaded)) persistPreferences();
});
@@ -351,6 +357,7 @@ export async function loadPreferences(): Promise<void> {
if (prefs.keybindings) loadKeybindings(prefs.keybindings as Record<string, string>);
if (prefs.version) lastSeenVersion.set(prefs.version as string);
if (prefs.selectedModelId) selectedModelId.set(prefs.selectedModelId as string);
if (prefs.requestParams) requestParams.set(prefs.requestParams as Record<string, unknown>);
} catch {
// First run, no preferences yet
}
+25 -8
View File
@@ -63,6 +63,7 @@ async def chat_completion(
system: str = "",
max_tokens: int = 100,
api_type: str = "chat_completions",
request_params: dict | None = None,
) -> str:
"""Simple non-streaming chat completion. Returns the text content.
@@ -78,6 +79,8 @@ async def chat_completion(
}
if system:
body["system"] = system
if request_params:
body.update(request_params)
resp = await client.post(
f"{base_url}/messages",
json=body,
@@ -95,6 +98,8 @@ async def chat_completion(
}
if system:
body_r["instructions"] = system
if request_params:
body_r.update(request_params)
resp = await client.post(
f"{base_url}/responses",
json=body_r,
@@ -105,13 +110,16 @@ async def chat_completion(
all_messages = messages[:]
if system:
all_messages.insert(0, {"role": "system", "content": system})
body_cc: dict = {
"model": model,
"messages": all_messages,
"max_completion_tokens": max_tokens,
}
if request_params:
body_cc.update(request_params)
resp = await client.post(
f"{base_url}/chat/completions",
json={
"model": model,
"messages": all_messages,
"max_completion_tokens": max_tokens,
},
json=body_cc,
headers={"Authorization": f"Bearer {api_key}"},
)
if resp.status_code >= 400:
@@ -200,7 +208,7 @@ def _to_anthropic_messages(messages: list[dict]) -> list[dict]:
async def stream_anthropic(
form_data: ChatCompletionForm, url: str, key: str
form_data: ChatCompletionForm, url: str, key: str, *, request_params: dict | None = None
) -> AsyncIterator[dict]:
tools = [
{
@@ -219,6 +227,8 @@ async def stream_anthropic(
"stream": True,
"max_tokens": 4096,
}
if request_params:
body.update(request_params)
# Remove None values
body = {k: v for k, v in body.items() if v is not None}
headers = {"x-api-key": key, "anthropic-version": "2023-06-01"}
@@ -245,6 +255,9 @@ async def stream_anthropic(
msg_usage = event.get("message", {}).get("usage", {})
if msg_usage:
usage_data["input_tokens"] = msg_usage.get("input_tokens", 0)
for cache_key in ("cache_read_input_tokens", "cache_creation_input_tokens"):
if msg_usage.get(cache_key):
usage_data[cache_key] = msg_usage[cache_key]
if etype == "content_block_start":
block = event["content_block"]
@@ -328,7 +341,7 @@ def _to_openai_messages(messages: list[dict], instructions: str) -> list[dict]:
async def stream_openai_completions(
form_data: ChatCompletionForm, url: str, key: str
form_data: ChatCompletionForm, url: str, key: str, *, request_params: dict | None = None
) -> AsyncIterator[dict]:
tools = [
{
@@ -350,6 +363,8 @@ async def stream_openai_completions(
}
if tools:
body["tools"] = tools
if request_params:
body.update(request_params)
headers = {"Authorization": f"Bearer {key}"}
emitted = False
@@ -472,7 +487,7 @@ def _to_responses_input(messages: list[dict], instructions: str) -> list[dict]:
async def stream_openai_responses(
form_data: ChatCompletionForm, url: str, key: str
form_data: ChatCompletionForm, url: str, key: str, *, request_params: dict | None = None
) -> AsyncIterator[dict]:
tools = [
{
@@ -493,6 +508,8 @@ async def stream_openai_responses(
body["instructions"] = form_data.instructions
if tools:
body["tools"] = tools
if request_params:
body.update(request_params)
headers = {"Authorization": f"Bearer {key}"}
emitted = False
+6 -3
View File
@@ -729,6 +729,9 @@ async def run_chat_task(
last_usage: dict | None = None # real usage from last API call
new_messages_since: int = 0 # messages appended since last API call
# Request params: arbitrary key-value pairs merged into the API request body
request_params = chat_params.get("request_params") or None
for _iteration in range(CHAT_MAX_ITERATIONS):
# ── Context compaction: summarize older messages if too large ──
if should_compact(messages, system, last_usage, new_messages_since):
@@ -768,11 +771,11 @@ async def run_chat_task(
)
if provider == "anthropic":
stream = stream_anthropic(form_data, base_url, api_key)
stream = stream_anthropic(form_data, base_url, api_key, request_params=request_params)
elif connection.get("api_type") == "responses":
stream = stream_openai_responses(form_data, base_url, api_key)
stream = stream_openai_responses(form_data, base_url, api_key, request_params=request_params)
else:
stream = stream_openai_completions(form_data, base_url, api_key)
stream = stream_openai_completions(form_data, base_url, api_key, request_params=request_params)
restart = False