-
Notifications
You must be signed in to change notification settings - Fork 19
Streaming output and webhook-based completion when run in workflow #118
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
pranaygp
wants to merge
29
commits into
main
Choose a base branch
from
pranay/serde-review
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 26 commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
ad0fe67
simplify example: use Sandbox methods directly in workflow
pranaygp fea1505
stream sandbox output to UI via workflow named streams
pranaygp 6642456
accept Web WritableStream in runCommand stdout/stderr
pranaygp 1341002
fix typecheck: guard .emit() call for WritableStream compatibility
pranaygp f7a8871
fix: ensure client before calling logs() in getCachedOutput
pranaygp bcd25eb
remove manual stream close — workflow runtime handles it
pranaygp e6cee90
return result instead of throwing on code failure
pranaygp 3573942
show live status with current phase and attempt number
pranaygp c20ae44
fix: write to status stream inside a step function
pranaygp cb558d3
accept string in writeFiles content, avoid Buffer in workflow context
pranaygp eb849f6
stream generated code to UI via status updates
pranaygp 1868043
add onCompleteUrl to runCommand for webhook-based completion
pranaygp 536b7b4
auto-create workflow webhook for detached runCommand
pranaygp d005345
revert auto-webhook: use explicit createWebhook at workflow level
pranaygp 45444ec
transparent webhook integration for detached runCommand
pranaygp d4a5307
fix: use regular import("workflow") so bundler can resolve it
pranaygp 5568329
use workflow tarball for example app
pranaygp c303030
update workflow tarball for example app
pranaygp 5780020
fix: include status stream in SSE endpoint
pranaygp a4707d1
add cmd+enter shortcut to submit
pranaygp 51f187d
add sandbox lifecycle status updates
pranaygp 79d055c
add syntax highlighting and terminal UI components
pranaygp 256facd
split-pane layout: code left, terminal output right
pranaygp 2a53951
vercel/black theme with line numbers
pranaygp d93d588
add runtime selector (Node.js 24/22, Python 3.13)
pranaygp 0d286fa
add Bash runtime option
pranaygp 36e8a9e
remove generated workflow manifest and gitignore it
pranaygp 99190b4
Merge branch 'main' into pranay/serde-review
VaguelySerious 4d09ce4
Merge branch 'main' into pranay/serde-review
VaguelySerious File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,4 @@ | ||
| /.next | ||
| /next-env.d.ts | ||
| .vercel | ||
| .env*.local |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| # Problems with current implementation | ||
|
|
||
| * webhook resumption doesn't work when running this locally because sandbox can't resume a localhost webhook | ||
| * deployment protection needs to be disabled for webhook resumption to happen in a preview branch |
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
49 changes: 49 additions & 0 deletions
49
examples/workflow-code-runner/app/components/code-block.tsx
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| "use client"; | ||
|
|
||
| import { useEffect, useState } from "react"; | ||
| import { codeToHtml } from "shiki"; | ||
|
|
||
| export function CodeBlock({ | ||
| code, | ||
| lang = "javascript", | ||
| }: { | ||
| code: string; | ||
| lang?: string; | ||
| }) { | ||
| const [html, setHtml] = useState<string>(""); | ||
|
|
||
| useEffect(() => { | ||
| let cancelled = false; | ||
| codeToHtml(code, { | ||
| lang, | ||
| theme: "github-dark-default", | ||
| }).then((result) => { | ||
| if (!cancelled) setHtml(result); | ||
| }); | ||
| return () => { | ||
| cancelled = true; | ||
| }; | ||
| }, [code, lang]); | ||
|
|
||
| if (!html) { | ||
| return ( | ||
| <pre className="line-numbers bg-black p-4 font-mono text-sm leading-relaxed text-[#e6edf3]"> | ||
| {code.split("\n").map((line, i) => ( | ||
| <div key={i} className="table-row"> | ||
| <span className="table-cell w-8 select-none pr-4 text-right tabular-nums text-[#484f58]"> | ||
| {i + 1} | ||
| </span> | ||
| <span className="table-cell">{line}</span> | ||
| </div> | ||
| ))} | ||
| </pre> | ||
| ); | ||
| } | ||
|
|
||
| return ( | ||
| <div | ||
| className="code-block [&_pre]:!bg-black [&_pre]:p-4 [&_pre]:leading-relaxed [&_pre]:text-sm [&_code]:text-sm [&_code]:leading-relaxed" | ||
| dangerouslySetInnerHTML={{ __html: html }} | ||
| /> | ||
| ); | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| "use client"; | ||
|
|
||
| import Ansi from "ansi-to-react"; | ||
| import { useEffect, useRef } from "react"; | ||
|
|
||
| export function Terminal({ | ||
| title, | ||
| children, | ||
| variant = "default", | ||
| }: { | ||
| title: string; | ||
| children: string; | ||
| variant?: "default" | "error"; | ||
| }) { | ||
| const scrollRef = useRef<HTMLPreElement>(null); | ||
|
|
||
| useEffect(() => { | ||
| if (scrollRef.current) { | ||
| scrollRef.current.scrollTop = scrollRef.current.scrollHeight; | ||
| } | ||
| }, [children]); | ||
|
|
||
| return ( | ||
| <div className="flex h-full flex-col"> | ||
| <div className="flex items-center gap-2 border-b border-[rgba(255,255,255,0.1)] bg-black px-4 py-2"> | ||
| <div className="flex gap-1.5"> | ||
| <div className="h-2.5 w-2.5 rounded-full bg-[#484f58]" /> | ||
| <div className="h-2.5 w-2.5 rounded-full bg-[#484f58]" /> | ||
| <div className="h-2.5 w-2.5 rounded-full bg-[#484f58]" /> | ||
| </div> | ||
| <span className="ml-2 text-xs text-[#484f58]">{title}</span> | ||
| </div> | ||
| <pre | ||
| ref={scrollRef} | ||
| className={`flex-1 overflow-auto bg-black p-4 font-mono text-sm leading-relaxed ${ | ||
| variant === "error" ? "text-[#f85149]" : "text-[#e6edf3]" | ||
| }`} | ||
| > | ||
| <Ansi>{children}</Ansi> | ||
| </pre> | ||
| </div> | ||
| ); | ||
| } |
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The SSE
ReadableStreamdoesn’t implementcancel(). If the client disconnects, the server-side loop may keep reading from the workflow stream and attempting to enqueue, wasting resources. Consider adding acancel()handler that cancels/releases thereaderand stops the loop when the response is aborted.