start-weather-session.sh 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #!/usr/bin/env bash
  2. set -euo pipefail
  3. BASE_URL="${BASE_URL:-http://127.0.0.1:8787}"
  4. TOKEN="${TOKEN:-dev-token}"
  5. SESSION_ID="${SESSION_ID:-p2}"
  6. create_payload() {
  7. cat <<JSON
  8. {
  9. "session-id": "${SESSION_ID}",
  10. "node-id": "task-node-1",
  11. "node-title": "Check weather in Hangzhou",
  12. "content": "Tell me the weather today in Hangzhou.",
  13. "attachments": [],
  14. "project": {
  15. "id": "project-weather",
  16. "title": "Weather Demo",
  17. "repo-url": "https://github.com/logseq/logseq"
  18. },
  19. "agent": {
  20. "provider": "codex",
  21. "mode": "build",
  22. "permission-mode": "default"
  23. }
  24. }
  25. JSON
  26. }
  27. message_payload() {
  28. cat <<JSON
  29. {
  30. "message": "Tell me the weather today in Hangzhou.",
  31. "kind": "user"
  32. }
  33. JSON
  34. }
  35. echo "Creating session: ${SESSION_ID}"
  36. curl -sS -X POST "${BASE_URL}/sessions" \
  37. -H "authorization: Bearer ${TOKEN}" \
  38. -H "content-type: application/json" \
  39. -d "$(create_payload)"
  40. echo
  41. echo "Sending message to session: ${SESSION_ID}"
  42. curl -sS -X POST "${BASE_URL}/sessions/${SESSION_ID}/messages" \
  43. -H "authorization: Bearer ${TOKEN}" \
  44. -H "content-type: application/json" \
  45. -d "$(message_payload)"
  46. echo
  47. echo "Streaming events (Ctrl+C to stop):"
  48. curl -N -sS -H "authorization: Bearer ${TOKEN}" "${BASE_URL}/sessions/${SESSION_ID}/stream"