Migrate Worker to Cloudflare-native AI; fix truncated replies; auto-close threads on send#30
Draft
Copilot wants to merge 11 commits into
Draft
Migrate Worker to Cloudflare-native AI; fix truncated replies; auto-close threads on send#30Copilot wants to merge 11 commits into
Copilot wants to merge 11 commits into
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Co-authored-by: harshithpabbati <43822585+harshithpabbati@users.noreply.github.com>
Co-authored-by: harshithpabbati <43822585+harshithpabbati@users.noreply.github.com>
…ler, sub-address reply routing Co-authored-by: harshithpabbati <43822585+harshithpabbati@users.noreply.github.com>
…tags Co-authored-by: harshithpabbati <43822585+harshithpabbati@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Assess potential benefits of Cloudflare agents
Add Cloudflare Agents Worker with native Email Routing integration
Mar 1, 2026
Co-authored-by: harshithpabbati <43822585+harshithpabbati@users.noreply.github.com>
Copilot
AI
changed the title
Add Cloudflare Agents Worker with native Email Routing integration
Use Cloudflare native email.reply() for autopilot sends
Mar 1, 2026
4c3754d to
8796d08
Compare
…cf/zai-org/glm-4.7-flash Co-authored-by: harshithpabbati <43822585+harshithpabbati@users.noreply.github.com>
…URL fetching Co-authored-by: harshithpabbati <43822585+harshithpabbati@users.noreply.github.com>
Copilot
AI
changed the title
Use Cloudflare native email.reply() for autopilot sends
Replace Gemini + Resend with Cloudflare-native primitives throughout the Worker
Mar 1, 2026
Co-authored-by: harshithpabbati <43822585+harshithpabbati@users.noreply.github.com>
Copilot
AI
changed the title
Replace Gemini + Resend with Cloudflare-native primitives throughout the Worker
Migrate Worker to Cloudflare-native AI; fix truncated replies; auto-close threads on send
Mar 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The AI pipeline was truncating long multi-part answers (1 024-token ceiling), using Gemini for both agents (external API dependency + cost), and leaving threads open after autopilot auto-sent a reply.
Truncation fix
maxOutputTokens1 024 → 2 048maxOutputTokens1 024 →MAX_WRITING_TOKENS(4 096)Writing Agent →
@cf/zai-org/glm-4.7-flashReplaced
geminiGenerateContentcall withcfAiGenerateText()via the Workers AIAIbinding. Added[ai] binding = "AI"towrangler.toml. No external API key needed.Research Agent → Workers AI +
HTMLRewriterGemini's proprietary
urlContexttool replaced with manual URL fetching fed into the same CF model. Up to 5 deduplicated datasource URLs are fetched in parallel (5 s timeout, 3 000 chars/URL cap).Script/style blocks are stripped with
HTMLRewriter(Cloudflare's built-in streaming HTML parser) before a catch-all tag regex runs — avoids thejs/incomplete-multi-character-sanitizationCodeQL alerts that regex-only stripping triggers:Confidence is
URL_FETCH_SUCCESS_CONFIDENCE(0.7) when at least one URL returned content — same value as the previous Gemini URL-context fallback. Citations become the list of successfully fetched URLs.Removed entirely
geminiGenerateContent,GEMINI_API_BASE,computeConfidence,extractCitations,GEMINI_API_KEYfromEnv,MAX_GEMINI_URLS,deduplicateForGemini. No external AI service or API keys required by the Worker.Thread auto-close on send
After autopilot sends a reply, the thread is
PATCHed tostatus: 'closed'. This is fire-and-forget (.catch()logs the error) so a Supabase hiccup at this step cannot retroactively revert a reply that was already delivered to the customer. Threads are already re-opened when a customer replies again, so the lifecycle is complete.🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.