#!/usr/bin/env bash
set -eu
home="$PWD/.t3/manual"
workspace="$home/workspaces/demo"
mkdir -p "$workspace"
git -C "$workspace" init --quiet --initial-branch=main
printf 'Synthetic request and queue demonstration.\n' > "$workspace/README.md"
git -C "$workspace" add README.md
git -C "$workspace" -c user.name=Scenario -c user.email=scenario@example.invalid commit --quiet -m 'Initial commit'
node apps/server/src/bin.ts project add "$workspace" --title 'Request demo' --base-dir "$home"
node apps/server/src/bin.ts thread start "$workspace" 'Ask me a question' --title 'Pending question' --provider devReplay --model question --wait --json --base-dir "$home" > "$home/question.json" || test "$?" = 2
thread=$(node -e 'console.log(JSON.parse(require("fs").readFileSync(process.argv[1],"utf8")).threadId)' "$home/question.json")
node apps/server/src/bin.ts thread send "$thread" 'First queued follow-up' --base-dir "$home"
node apps/server/src/bin.ts thread send "$thread" 'Promoted queued follow-up' --base-dir "$home"
