trigger-realtime-and-frontend

โดย triggerdotdev

พื้นผิว client/frontend ของ Trigger.dev: สมัครรับข้อมูลรันแบบเรียลไทม์ (runs.subscribeToRun และ hook useRealtimeRun จาก @trigger.dev/react-hooks) ใช้ข้อมูลเมตาดาต้า…

npx skills add https://github.com/triggerdotdev/trigger.dev --skill trigger-realtime-and-frontend

Realtime and Frontend

The full, version-pinned reference ships inside your installed @trigger.dev/sdk. Read it before writing code — it always matches the SDK version in this project, so it never drifts:

  • Skill: node_modules/@trigger.dev/sdk/skills/trigger-realtime-and-frontend/SKILL.md — run subscriptions, @trigger.dev/react-hooks, streams, frontend triggering, and scoped tokens.
  • Docs: the full, version-pinned docs ship bundled at node_modules/@trigger.dev/sdk/docs/realtime/; the skill above lists the exact pages it draws from in its sources: frontmatter. Grep for a hook, e.g. grep -rl "useRealtimeRun" node_modules/@trigger.dev/sdk/docs/.

If those paths don't exist, @trigger.dev/sdk isn't installed yet — install it first. In a non-hoisted layout, resolve the package with node -p "require.resolve('@trigger.dev/sdk/package.json')" and read skills/ + docs/ beside it.

Common mistakes

  1. CRITICAL: Triggering from the browser with a Public Access Token. The read token from createPublicToken cannot trigger tasks.

    • Wrong: useTaskTrigger("my-task", { accessToken: publicAccessTokenFromCreatePublicToken })
    • Correct: mint a single-use Trigger Token with auth.createTriggerPublicToken("my-task") and pass that.
  2. Token with no scopes. A scopeless token authorizes nothing, so every subscribe 403s.

    • Wrong: await auth.createPublicToken()
    • Correct: await auth.createPublicToken({ scopes: { read: { runs: ["run_1234"] } } })
  3. Polling with useRun/SWR for live updates. useRun is the SWR-based management-API hook (not recommended for live state); set refreshInterval: 0 to stop polling if you do use it.

    • Wrong: useRun(runId, { refreshInterval: 1000 }) to track progress
    • Correct: useRealtimeRun(runId, { accessToken }) (no polling, no WebSocket setup)
  4. Forgetting "use client". Realtime/trigger hooks cannot run in a server component.

    • Wrong: a Next.js App Router server component using useRealtimeRun
    • Correct: put "use client"; at the top of any component using these hooks.
  5. Shipping payload/output you do not render.

    • Wrong: useRealtimeRun(runId, { accessToken }) for a status badge (large payloads over the wire)
    • Correct: useRealtimeRun(runId, { accessToken, skipColumns: ["payload", "output"] })
  6. Subscribing before the handle exists.

    • Wrong: useRealtimeRun(handle, { accessToken: handle?.publicAccessToken }) with no guard
    • Correct: add enabled: !!handle so it subscribes only once the trigger returns a handle.

References

Sibling skills: trigger-authoring-tasks (the task side: streams.define(), metadata.set(), wait.createToken), trigger-authoring-chat-agent and trigger-chat-agent-advanced (chat agents build on these realtime streams).

Skills เพิ่มเติมจาก triggerdotdev

trigger-dev-tasks
triggerdotdev
ใช้ทักษะนี้เมื่อเขียน ออกแบบ หรือปรับปรุงงานเบื้องหลังและเวิร์กโฟลว์ของ Trigger.dev ซึ่งรวมถึงการสร้างงานแบบอะซิงโครนัสที่เชื่อถือได้ การนำ AI ไปใช้...
agents
triggerdotdev
รูปแบบเอเจนต์ AI ด้วย Trigger.dev - การจัดลำดับ, การทำงานแบบขนาน, การกำหนดเส้นทาง, ผู้ประเมิน-ผู้ปรับแต่ง, และมนุษย์ในวงจร ใช้เมื่อสร้างงานที่ขับเคลื่อนด้วย LLM…
config
triggerdotdev
กำหนดค่าโปรเจกต์ Trigger.dev ด้วย trigger.config.ts ใช้เมื่อตั้งค่า build extensions สำหรับ Prisma, Playwright, FFmpeg, Python หรือปรับแต่งการปรับใช้…
realtime
triggerdotdev
สมัครรับข้อมูลการทำงานของ Trigger.dev แบบเรียลไทม์จากฟร้อนท์เอนด์และแบ็คเอนด์ ใช้เมื่อสร้างตัวบ่งชี้ความคืบหน้า แดชบอร์ดสด การสตรีมการตอบสนองของ AI/LLM,…
setup
triggerdotdev
ตั้งค่า Trigger.dev ในโปรเจกต์ของคุณ ใช้เมื่อเพิ่ม Trigger.dev เป็นครั้งแรก สร้าง trigger.config.ts หรือเริ่มต้นไดเรกทอรี trigger
tasks
triggerdotdev
สร้างเอเจนต์ AI, เวิร์กโฟลว์ และงานพื้นหลังที่ทนทานด้วย Trigger.dev ใช้เมื่อสร้าง tasks, ทริกเกอร์งาน, จัดการการลองใหม่, กำหนดเวลางาน cron, หรือ...
trigger-agents
triggerdotdev
รูปแบบเอเจนต์ AI กับ Trigger.dev - การจัดระบบ การทำงานแบบขนาน การจัดเส้นทาง ตัวประเมิน-ตัวปรับให้เหมาะสม และมนุษย์ในวงจรการทำงาน ใช้เมื่อสร้างงานที่ขับเคลื่อนด้วย LLM…
trigger-chat-agent-advanced
triggerdotdev
ความสามารถ chat.agent ขั้นสูงและพร้อมใช้งานจริงสำหรับ Trigger.dev โหลดตามความต้องการ ใช้เมื่อทำงานกับ Sessions primitive ดิบ (sessions /…