<script lang="ts">
  // Content for the "new-task" window slot (windows.ts openNewTaskWindow) —
  // a real ChatThread in its empty state rather than a separate compose
  // screen, so starting a task looks and feels exactly like the task chat
  // it becomes. Submitting the first message starts the task via
  // startTask() and hands off to the real session window (see windows.ts's
  // openTaskWindow) the moment the backend assigns an id.
  import { startTask } from '$lib/stores/chat'
  import { openTaskWindow, wm, NEW_TASK_WINDOW_ID } from '$lib/stores/windows'
  import { truncateMiddle } from '$lib/utils'
  import ChatThread from '$lib/components/ChatThread.svelte'

  // Seeded by openNewTaskWindow when a caller (the entity window's "Ask Nomos")
  // knows what the task is about.
  let { initialDraft = '' }: { initialDraft?: string } = $props()

  function onSend(text: string) {
    startTask(text, (sessionId) => {
      openTaskWindow(sessionId, truncateMiddle(text, 60))
      wm.close(NEW_TASK_WINDOW_ID)
    })
  }
</script>

<ChatThread
  {initialDraft}
  messages={[]}
  streaming={false}
  working={false}
  connectionState="connected"
  {onSend}
  onCancel={() => {}}
  onReconnect={() => {}}
  onDismissError={() => {}}
/>
