René's URL Explorer Experiment


Title: feat(sdk): return lastEventId from writeTurnComplete and typed capture result by matt-aitken · Pull Request #4304 · triggerdotdev/trigger.dev · GitHub

Open Graph Title: feat(sdk): return lastEventId from writeTurnComplete and typed capture result by matt-aitken · Pull Request #4304 · triggerdotdev/trigger.dev

X Title: feat(sdk): return lastEventId from writeTurnComplete and typed capture result by matt-aitken · Pull Request #4304 · triggerdotdev/trigger.dev

Description: Summary Two ergonomic additions for custom chat-agent loops that own the turn loop (chat.customAgent, chat.createSession, and the hand-rolled primitives). chat.writeTurnComplete() now resolves to { lastEventId }, the resume cursor for the start of the next turn. A custom loop can persist it straight from the task instead of round-tripping it back from the client after the turn ends. The value was already produced internally by the turn-complete write; the public wrapper simply discarded it. chat.pipeAndCapture() no longer throws when a stream is stopped or fails. It now resolves to a PipeAndCaptureResult carrying any partial message captured before the stop or failure, a typed status ("complete" | "aborted" | "error"), and the error on failure. Previously a failed stream threw and the partial was lost, and an abort was captured only when the AI SDK happened to fire onFinish in time. const { message, status, error } = await chat.pipeAndCapture(result, { signal }); if (message) conversation.addResponse(message); if (status === "error") logger.error("turn failed", { error }); const { lastEventId } = await chat.writeTurnComplete(); await db.chats.update(chatId, { lastEventId }); Design pipeAndCapture wraps the pipe in a try/catch and classifies the outcome from the abort signal (a stop drains the source stream cleanly rather than throwing) versus a thrown error. It also races the onFinish capture against a timeout so a hard stop that prevents onFinish from firing can't hang the caller. This mirrors the capture path chat.agent already uses internally. The finishReason from onFinish is surfaced too, since it was already captured on the built-in path. The internal turn.complete() helper keeps its existing contract: it still returns UIMessage | undefined, still throws on a genuine stream failure, and still discards output on a full run cancel. Breaking change chat.pipeAndCapture previously resolved to UIMessage | undefined. Call sites now read .message off the result. This is a young, low-level API; the docs examples are updated in this PR.

Open Graph Description: Summary Two ergonomic additions for custom chat-agent loops that own the turn loop (chat.customAgent, chat.createSession, and the hand-rolled primitives). chat.writeTurnComplete() now resolves to {...

X Description: Summary Two ergonomic additions for custom chat-agent loops that own the turn loop (chat.customAgent, chat.createSession, and the hand-rolled primitives). chat.writeTurnComplete() now resolves to {...

Opengraph URL: https://github.com/triggerdotdev/trigger.dev/pull/4304

X: @github

direct link

Domain: github.com

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react-reconciler,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@d5750093facf
route-pattern/:user_id/:repository/pull/:id/files(.:format)
route-controllerpull_requests
route-actionfiles
fetch-noncev2:699dcf60-0ab1-8a07-9de5-3777f31a5cd6
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-idE80A:1F5D:EDF36E:15A2D46:6AFAF304
html-safe-nonceceda5b755e866fe7d9ba6238fbb6cd6c5bf820953529dca5e7fd6868b39eeebc
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFODBBOjFGNUQ6RURGMzZFOjE1QTJENDY6NkFGQUYzMDQiLCJ2aXNpdG9yX2lkIjoiNzA4MDQ5Nzc3MTAyNjUxMDU5NiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmac50e434401e7b2ef56214974775464e9c4888d77bd9fa8b5b8c668a9916463996
hovercard-subject-tagpull_request:4090252463
github-keyboard-shortcutsrepository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///pull_requests/show/files
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/triggerdotdev/trigger.dev/pull/4304/files
twitter:imagehttps://avatars.githubusercontent.com/u/10635986?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/10635986?s=400&v=4
og:image:altSummary Two ergonomic additions for custom chat-agent loops that own the turn loop (chat.customAgent, chat.createSession, and the hand-rolled primitives). chat.writeTurnComplete() now resolves to {...
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
None0178036d8230524a18422872393ab7e708443ae4c2047f758560a2db870c1913
turbo-cache-controlno-preview
diff-viewunified
go-importgithub.com/triggerdotdev/trigger.dev git https://github.com/triggerdotdev/trigger.dev.git
octolytics-dimension-user_id95297378
octolytics-dimension-user_logintriggerdotdev
octolytics-dimension-repository_id572570113
octolytics-dimension-repository_nwotriggerdotdev/trigger.dev
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id572570113
octolytics-dimension-repository_network_root_nwotriggerdotdev/trigger.dev
turbo-body-classeslogged-out env-production page-responsive full-width
disable-turbotrue
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
releasea85e96a83bed7871993e6b1ffda24105928eee17
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/triggerdotdev/trigger.dev/pull/4304/files#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Ftriggerdotdev%2Ftrigger.dev%2Fpull%2F4304%2Ffiles
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Ftriggerdotdev%2Ftrigger.dev%2Fpull%2F4304%2Ffiles
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fpull_requests%2Fshow%2Ffiles&source=header-repo&source_repo=triggerdotdev%2Ftrigger.dev
Reloadhttps://github.com/triggerdotdev/trigger.dev/pull/4304/files
Reloadhttps://github.com/triggerdotdev/trigger.dev/pull/4304/files
Reloadhttps://github.com/triggerdotdev/trigger.dev/pull/4304/files
triggerdotdevhttps://github.com/triggerdotdev
trigger.devhttps://github.com/triggerdotdev/trigger.dev
Codehttps://github.com/triggerdotdev/trigger.dev
Issues203 (203)https://github.com/triggerdotdev/trigger.dev/issues
Pull requests67 (67)https://github.com/triggerdotdev/trigger.dev/pulls
Discussionshttps://github.com/triggerdotdev/trigger.dev/discussions
Actionshttps://github.com/triggerdotdev/trigger.dev/actions
Projectshttps://github.com/triggerdotdev/trigger.dev/projects
Security and quality39 (39)https://github.com/triggerdotdev/trigger.dev/security
Insightshttps://github.com/triggerdotdev/trigger.dev/pulse
Sign up for GitHub https://github.com/signup?return_to=%2Ftriggerdotdev%2Ftrigger.dev%2Fissues%2Fnew%2Fchoose
terms of servicehttps://docs.github.com/terms
privacy statementhttps://docs.github.com/privacy
Sign inhttps://github.com/login?return_to=%2Ftriggerdotdev%2Ftrigger.dev%2Fissues%2Fnew%2Fchoose
matt-aitkenhttps://github.com/matt-aitken
mainhttps://github.com/triggerdotdev/trigger.dev/tree/main
feat/sdk-chat-turn-complete-and-capturehttps://github.com/triggerdotdev/trigger.dev/tree/feat/sdk-chat-turn-complete-and-capture
Conversation 18 https://github.com/triggerdotdev/trigger.dev/pull/4304
Commits 3 https://github.com/triggerdotdev/trigger.dev/pull/4304/commits
Checks 58 https://github.com/triggerdotdev/trigger.dev/pull/4304/checks
Files changed https://github.com/triggerdotdev/trigger.dev/pull/4304/files
Please reload this pagehttps://github.com/triggerdotdev/trigger.dev/pull/4304/files
feat(sdk): return lastEventId from writeTurnComplete and typed capture result https://github.com/triggerdotdev/trigger.dev/pull/4304/files#top
Show all changes 3 commits https://github.com/triggerdotdev/trigger.dev/pull/4304/files
335c087 feat(sdk): return lastEventId from writeTurnComplete and typed captur… matt-aitken Jul 20, 2026 https://github.com/triggerdotdev/trigger.dev/pull/4304/commits/335c08742590a0fa31fd246698a428cd0c62c605
a83bfbd test(sdk): cover pipeAndCapture status/partial-capture and writeTurnC… matt-aitken Jul 20, 2026 https://github.com/triggerdotdev/trigger.dev/pull/4304/commits/a83bfbd941509e103a369d47fa640cfb7219dab9
a6d0ddb fix(sdk): preserve partial on hard-error, return sessionInEventId, ha… matt-aitken Jul 21, 2026 https://github.com/triggerdotdev/trigger.dev/pull/4304/commits/a6d0ddbe59c24769e8068c09d1eed2567cff903a
Clear filters https://github.com/triggerdotdev/trigger.dev/pull/4304/files
Please reload this pagehttps://github.com/triggerdotdev/trigger.dev/pull/4304/files
Please reload this pagehttps://github.com/triggerdotdev/trigger.dev/pull/4304/files
chat-custom-agent-capture.md https://github.com/triggerdotdev/trigger.dev/pull/4304/files#diff-99aba57846bc8c81f25a6e06ef117af9a968902746a0e2214305dc0b9c0dbb11
changelog.mdx https://github.com/triggerdotdev/trigger.dev/pull/4304/files#diff-a9d88d1cce91d9f879391c4736b619d4c211cc00c0a1cfd5c7db7e4119725132
compaction.mdx https://github.com/triggerdotdev/trigger.dev/pull/4304/files#diff-6b560d73c160d780e8e7d8a5e0e40e7037cac8c5130caf1c83c87045c52dd235
custom-agents.mdx https://github.com/triggerdotdev/trigger.dev/pull/4304/files#diff-aa22c9fedc21c400cd9c3eba314803d27850039367de1469b442a2bba7c96650
fast-starts.mdx https://github.com/triggerdotdev/trigger.dev/pull/4304/files#diff-08c505bdbdd4d7c4e8227461df62a19bcf73ffee36f392fbed504190c435c6f7
pending-messages.mdx https://github.com/triggerdotdev/trigger.dev/pull/4304/files#diff-8221029e3926d4ab845c60011262851aa8c6f10af9790210471963d1cc4c3bec
reference.mdx https://github.com/triggerdotdev/trigger.dev/pull/4304/files#diff-58e648685c48d39e8d19f714ccdb9a6eca84024f3490b656f62a0ff535a22f3d
ai.ts https://github.com/triggerdotdev/trigger.dev/pull/4304/files#diff-1a41664a01679e09d7182b5d113a193cea9eaad0f2092f68b4beca081617a53a
test-session-handle.ts https://github.com/triggerdotdev/trigger.dev/pull/4304/files#diff-4a1d5a2e027987bf49c6900bfcb998aa70db61b3bdd364306c06f3b7302c099a
chat-pipe-and-capture.test.ts https://github.com/triggerdotdev/trigger.dev/pull/4304/files#diff-d3a3169d1ffa588a80317867d0d496e9c19517babfa25941c17763ef34f411ad
.changeset/chat-custom-agent-capture.mdhttps://github.com/triggerdotdev/trigger.dev/pull/4304/files#diff-99aba57846bc8c81f25a6e06ef117af9a968902746a0e2214305dc0b9c0dbb11
View file https://github.com/triggerdotdev/trigger.dev/blob/a6d0ddbe59c24769e8068c09d1eed2567cff903a/.changeset/chat-custom-agent-capture.md
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/triggerdotdev/trigger.dev/pull/4304/{{ revealButtonHref }}
Please reload this pagehttps://github.com/triggerdotdev/trigger.dev/pull/4304/files
docs/ai-chat/changelog.mdxhttps://github.com/triggerdotdev/trigger.dev/pull/4304/files#diff-a9d88d1cce91d9f879391c4736b619d4c211cc00c0a1cfd5c7db7e4119725132
View file https://github.com/triggerdotdev/trigger.dev/blob/a6d0ddbe59c24769e8068c09d1eed2567cff903a/docs/ai-chat/changelog.mdx
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/triggerdotdev/trigger.dev/pull/4304/{{ revealButtonHref }}
https://github.com/triggerdotdev/trigger.dev/pull/4304/files#diff-a9d88d1cce91d9f879391c4736b619d4c211cc00c0a1cfd5c7db7e4119725132
https://github.com/triggerdotdev/trigger.dev/pull/4304/files#diff-a9d88d1cce91d9f879391c4736b619d4c211cc00c0a1cfd5c7db7e4119725132
docs/ai-chat/compaction.mdxhttps://github.com/triggerdotdev/trigger.dev/pull/4304/files#diff-6b560d73c160d780e8e7d8a5e0e40e7037cac8c5130caf1c83c87045c52dd235
View file https://github.com/triggerdotdev/trigger.dev/blob/a6d0ddbe59c24769e8068c09d1eed2567cff903a/docs/ai-chat/compaction.mdx
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/triggerdotdev/trigger.dev/pull/4304/{{ revealButtonHref }}
https://github.com/triggerdotdev/trigger.dev/pull/4304/files#diff-6b560d73c160d780e8e7d8a5e0e40e7037cac8c5130caf1c83c87045c52dd235
https://github.com/triggerdotdev/trigger.dev/pull/4304/files#diff-6b560d73c160d780e8e7d8a5e0e40e7037cac8c5130caf1c83c87045c52dd235
docs/ai-chat/custom-agents.mdxhttps://github.com/triggerdotdev/trigger.dev/pull/4304/files#diff-aa22c9fedc21c400cd9c3eba314803d27850039367de1469b442a2bba7c96650
View file https://github.com/triggerdotdev/trigger.dev/blob/a6d0ddbe59c24769e8068c09d1eed2567cff903a/docs/ai-chat/custom-agents.mdx
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/triggerdotdev/trigger.dev/pull/4304/{{ revealButtonHref }}
https://github.com/triggerdotdev/trigger.dev/pull/4304/files#diff-aa22c9fedc21c400cd9c3eba314803d27850039367de1469b442a2bba7c96650
https://github.com/triggerdotdev/trigger.dev/pull/4304/files#diff-aa22c9fedc21c400cd9c3eba314803d27850039367de1469b442a2bba7c96650
https://github.com/triggerdotdev/trigger.dev/pull/4304/files#diff-aa22c9fedc21c400cd9c3eba314803d27850039367de1469b442a2bba7c96650
https://github.com/triggerdotdev/trigger.dev/pull/4304/files#diff-aa22c9fedc21c400cd9c3eba314803d27850039367de1469b442a2bba7c96650
https://github.com/triggerdotdev/trigger.dev/pull/4304/files#diff-aa22c9fedc21c400cd9c3eba314803d27850039367de1469b442a2bba7c96650
https://github.com/triggerdotdev/trigger.dev/pull/4304/files#diff-aa22c9fedc21c400cd9c3eba314803d27850039367de1469b442a2bba7c96650
https://github.com/triggerdotdev/trigger.dev/pull/4304/files#diff-aa22c9fedc21c400cd9c3eba314803d27850039367de1469b442a2bba7c96650
https://github.com/triggerdotdev/trigger.dev/pull/4304/files#diff-aa22c9fedc21c400cd9c3eba314803d27850039367de1469b442a2bba7c96650
docs/ai-chat/fast-starts.mdxhttps://github.com/triggerdotdev/trigger.dev/pull/4304/files#diff-08c505bdbdd4d7c4e8227461df62a19bcf73ffee36f392fbed504190c435c6f7
View file https://github.com/triggerdotdev/trigger.dev/blob/a6d0ddbe59c24769e8068c09d1eed2567cff903a/docs/ai-chat/fast-starts.mdx
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/triggerdotdev/trigger.dev/pull/4304/{{ revealButtonHref }}
https://github.com/triggerdotdev/trigger.dev/pull/4304/files#diff-08c505bdbdd4d7c4e8227461df62a19bcf73ffee36f392fbed504190c435c6f7
https://github.com/triggerdotdev/trigger.dev/pull/4304/files#diff-08c505bdbdd4d7c4e8227461df62a19bcf73ffee36f392fbed504190c435c6f7
docs/ai-chat/pending-messages.mdxhttps://github.com/triggerdotdev/trigger.dev/pull/4304/files#diff-8221029e3926d4ab845c60011262851aa8c6f10af9790210471963d1cc4c3bec
View file https://github.com/triggerdotdev/trigger.dev/blob/a6d0ddbe59c24769e8068c09d1eed2567cff903a/docs/ai-chat/pending-messages.mdx
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/triggerdotdev/trigger.dev/pull/4304/{{ revealButtonHref }}
https://github.com/triggerdotdev/trigger.dev/pull/4304/files#diff-8221029e3926d4ab845c60011262851aa8c6f10af9790210471963d1cc4c3bec
https://github.com/triggerdotdev/trigger.dev/pull/4304/files#diff-8221029e3926d4ab845c60011262851aa8c6f10af9790210471963d1cc4c3bec
docs/ai-chat/reference.mdxhttps://github.com/triggerdotdev/trigger.dev/pull/4304/files#diff-58e648685c48d39e8d19f714ccdb9a6eca84024f3490b656f62a0ff535a22f3d
View file https://github.com/triggerdotdev/trigger.dev/blob/a6d0ddbe59c24769e8068c09d1eed2567cff903a/docs/ai-chat/reference.mdx
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/triggerdotdev/trigger.dev/pull/4304/{{ revealButtonHref }}
https://github.com/triggerdotdev/trigger.dev/pull/4304/files#diff-58e648685c48d39e8d19f714ccdb9a6eca84024f3490b656f62a0ff535a22f3d
https://github.com/triggerdotdev/trigger.dev/pull/4304/files#diff-58e648685c48d39e8d19f714ccdb9a6eca84024f3490b656f62a0ff535a22f3d
Please reload this pagehttps://github.com/triggerdotdev/trigger.dev/pull/4304/files
Please reload this pagehttps://github.com/triggerdotdev/trigger.dev/pull/4304/files
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.