wire home ai chat

This commit is contained in:
Diego Imbert
2026-07-09 13:58:09 +02:00
parent 696e7670b3
commit cd3138163f
2 changed files with 39 additions and 4 deletions
@@ -1,13 +1,32 @@
<script lang="ts">
import TextInput from '$lib/components/text_input/TextInput.svelte'
import { ArrowRight, PlusIcon, Sparkles } from 'lucide-svelte'
import { ArrowRight } from 'lucide-svelte'
import Button from '../common/button/Button.svelte'
import ProviderModelSelector from '../copilot/chat/ProviderModelSelector.svelte'
import { startSessionWithPrompt } from '../sessions/sessionSwitch.svelte'
// UI only for now — no submit wiring yet.
let value = $state('')
let placeholder = $state('')
let starting = $state(false)
async function start() {
if (starting || !value.trim()) return
starting = true
try {
await startSessionWithPrompt(value)
} finally {
starting = false
}
}
// Enter starts the session; Shift+Enter keeps inserting a newline.
function onKeydown(e: KeyboardEvent) {
if (e.key === 'Enter' && !e.shiftKey) {
e.preventDefault()
start()
}
}
const prompts = [
'Sync new Salesforce leads into a postgres table every hour',
'Build a workflow that triggers on a Discord message, checks for offensive language using an LLM, and possibly block them'
@@ -60,13 +79,15 @@
bind:value
class="resize-none px-4 py-3 pb-9 shadow-lg"
underlyingInputEl="textarea"
inputProps={{ rows: 4, placeholder }}
inputProps={{ rows: 4, placeholder, onkeydown: onKeydown }}
/>
<Button
endIcon={{ icon: ArrowRight }}
wrapperClasses="absolute right-2 bottom-3.5"
variant="default"
variant={value.trim() ? 'accent' : 'default'}
iconOnly
disabled={!value.trim() || starting}
onclick={start}
></Button>
<div
class="absolute left-3 bottom-4 flex items-center border rounded-md bg-surface-tertiary px-1"
@@ -3,6 +3,7 @@ import { goto } from '$lib/navigation'
import { workspaceStore } from '$lib/stores'
import {
createSession,
queueTransientDraftPrompt,
selectSession,
sessionInCurrentFamily,
sessionState,
@@ -49,6 +50,19 @@ export async function enterSessionMode(opts?: { replace?: boolean }): Promise<vo
})
}
// Start a fresh AI session seeded with a prompt composed elsewhere (e.g. the
// home page composer), then route into session mode. The prompt is queued onto
// the transient draft so the session's chat input restores it on mount — the
// same path a reload uses — leaving it composed-but-unsent for the user to
// review and send. No-op routing is fine for a blank prompt; callers guard.
export async function startSessionWithPrompt(prompt: string): Promise<void> {
const session = createSession()
const text = prompt.trim()
if (text) queueTransientDraftPrompt(session.id, text)
selectSession(session.id)
await goto(`/sessions?session_name=${encodeURIComponent(session.name)}`)
}
// Exit session mode: back to the last navigation route (home as a fallback).
export async function exitSessionMode(): Promise<void> {
let target = lastNavRoute || '/'