An open-source, faster Devin alternative
TypeScript
Opencode in DO: Show Workerd session and sandbox progress in the playground (#716)
Mohamed Habibe70ea8fec7da
diff --git a/cloudflare-workers/api-edge/src/managed_agents.test.ts b/cloudflare-workers/api-edge/src/managed_agents.test.tsindex 64803f8a..c79882a0 100644--- a/cloudflare-workers/api-edge/src/managed_agents.test.ts+++ b/cloudflare-workers/api-edge/src/managed_agents.test.ts@@ -1763,6 +1763,7 @@ describe("managed agents proxy", () => {{session: {id: "session_test",+ executionMode: "workerd",status: "connecting",createdAt: "2026-07-30T00:00:00.000Z",accountId: "org_test",@@ -1800,6 +1801,7 @@ describe("managed agents proxy", () => {expect(response.status).toBe(201);expect(serialized).toContain("research-assistant");+ expect(serialized).toContain('"executionMode":"workerd"');expect(serialized).not.toMatch(/runtimeToken|microvm|artifact|bucket|imageArn|arn:aws/i,);diff --git a/cloudflare-workers/api-edge/src/managed_agents.ts b/cloudflare-workers/api-edge/src/managed_agents.tsindex 5f398608..a916bb5d 100644--- a/cloudflare-workers/api-edge/src/managed_agents.ts+++ b/cloudflare-workers/api-edge/src/managed_agents.ts@@ -917,6 +917,7 @@ function publicSuccessBody(return {session: {id: session.id,+ executionMode: session.executionMode,status: session.status,createdAt: session.createdAt,},diff --git a/web/src/managed-agents/DebugInspector.tsx b/web/src/managed-agents/DebugInspector.tsxindex e06342fa..f28f190d 100644--- a/web/src/managed-agents/DebugInspector.tsx+++ b/web/src/managed-agents/DebugInspector.tsx@@ -31,9 +31,23 @@ function eventSummary(event: ManagedAgentEvent) {return `${method} ${path}${status}`.trim()}if (event.type.startsWith('tool.')) {- return typeof event.data.tool === 'string'- ? event.data.tool- : 'Tool activity'+ const tool = typeof event.data.tool === 'string' ? event.data.tool : 'Tool'+ if (event.type === 'tool.progress') {+ if (+ typeof event.data.stream === 'string' &&+ typeof event.data.chunk === 'string'+ ) {+ return `${tool} · ${event.data.stream}\n${event.data.chunk}`+ }+ const detail =+ typeof event.data.message === 'string'+ ? event.data.message+ : typeof event.data.stage === 'string'+ ? event.data.stage+ : 'running'+ return `${tool} · ${detail}`+ }+ return tool}if (event.type === 'turn.failed' || event.type === 'session.failed') {return typeof event.data.message === 'string'diff --git a/web/src/managed-agents/Detail.tsx b/web/src/managed-agents/Detail.tsxindex 5d6a39a4..3b7faede 100644--- a/web/src/managed-agents/Detail.tsx+++ b/web/src/managed-agents/Detail.tsx@@ -93,6 +93,8 @@ type DetailTab =| 'secrets'| 'byok'+const EMPTY_MANAGED_AGENT_EVENTS: ManagedAgentEvent[] = []+function formatDate(value: string) {return new Date(value).toLocaleString()}@@ -198,6 +200,7 @@ function MessageActivity({}function PlaygroundChat({+ chatId,agentId,session,events,@@ -205,6 +208,7 @@ function PlaygroundChat({onInitialPromptConsumed,onSessionFinished,}: {+ chatId: stringagentId: stringsession?: ManagedAgentSessionevents: ManagedAgentEvent[]@@ -217,10 +221,10 @@ function PlaygroundChat({const [inputMode, setInputMode] = useState<ManagedAgentInputMode>('queue')const [admitting, setAdmitting] = useState(false)const [admissionNotice, setAdmissionNotice] = useState<string>()- const [liveSessionId, setLiveSessionId] = useState(session?.id)- const liveSessionIdRef = useRef(session?.id)+ const [startingSessionId] = useState(session?.id)+ const [liveSessionId, setLiveSessionId] = useState(startingSessionId)+ const liveSessionIdRef = useRef(startingSessionId)const timelineRef = useRef<HTMLDivElement>(null)- const composerRef = useRef<HTMLDivElement>(null)const followOutputRef = useRef(true)const initializedScrollRef = useRef(false)const initialPromptSentRef = useRef(false)@@ -230,11 +234,12 @@ function PlaygroundChat({)const transport = useMemo(() =>- new ManagedAgentChatTransport(agentId, session?.id, (sessionId) => {- setLiveSessionId(sessionId)- liveSessionIdRef.current = sessionId- }),- [agentId, session?.id],+ new ManagedAgentChatTransport(+ agentId,+ startingSessionId,+ setLiveSessionId,+ ),+ [agentId, startingSessionId],)const debugEvents = useQuery({queryKey: ['managed-agent-session-events', liveSessionId],@@ -242,8 +247,11 @@ function PlaygroundChat({enabled: Boolean(liveSessionId),refetchInterval: 1_000,})+ useEffect(() => {+ liveSessionIdRef.current = liveSessionId+ }, [liveSessionId])const { messages, sendMessage, status, error } = useChat({- id: session?.id ?? `new-${agentId}`,+ id: chatId,messages: initialMessages,transport,throttle: 30,@@ -289,7 +297,7 @@ function PlaygroundChat({const input = prompt.trim()if (!input || admitting) returnif (agentWorking) {- const sessionId = liveSessionIdRef.current+ const sessionId = liveSessionIdif (!sessionId) {notifyError("Couldn't direct this run.",@@ -326,9 +334,6 @@ function PlaygroundChat({setPrompt('')setAdmissionNotice(undefined)void sendMessage({ text: input })- requestAnimationFrame(() =>- composerRef.current?.querySelector('textarea')?.focus(),- )}return (@@ -424,10 +429,7 @@ function PlaygroundChat({{admissionNotice}</p>) : null}- <div- ref={composerRef}- className="bg-background focus-within:border-ring/60 rounded-lg border p-2 transition-colors"- >+ <div className="bg-background focus-within:border-ring/60 rounded-lg border p-2 transition-colors"><ChatTextareavalue={prompt}onChange={(event) => setPrompt(event.target.value)}@@ -525,6 +527,7 @@ export default function ManagedAgentDetail({const requestedPlaygroundId = playgroundSessionIdFromSearch(location.search)const firstRunPrompt = templateFirstRunPrompt(location.state)const [newSessionKey, setNewSessionKey] = useState(() => crypto.randomUUID())+ const [adoptedPlaygroundId, setAdoptedPlaygroundId] = useState<string>()const agents = useQuery({queryKey: ['managed-agents'],@@ -588,10 +591,15 @@ export default function ManagedAgentDetail({(session) => session.id === requestedPlaygroundId,)const selectedPlaygroundId = selectedPlayground?.id+ const requestedPlaygroundIdRef = useRef(requestedPlaygroundId)+ useEffect(() => {+ requestedPlaygroundIdRef.current = requestedPlaygroundId+ }, [requestedPlaygroundId])const selectedPlaygroundEvents = useQuery({queryKey: ['managed-agent-session-events', selectedPlaygroundId],queryFn: () => getManagedAgentSessionEvents(selectedPlaygroundId!),enabled: Boolean(selectedPlaygroundId),+ refetchInterval: 1_000,})const continuationCommand =project?.templateSource?.cloneReady &&@@ -600,11 +608,16 @@ export default function ManagedAgentDetail({project?.templateSource && !project.templateSource.cloneReadyconst selectPlaygroundSession = (sessionId?: string) => {+ setAdoptedPlaygroundId(undefined)void navigate({pathname: location.pathname,search: playgroundSessionSearch(location.search, sessionId),})}+ const playgroundChatId =+ selectedPlaygroundId && selectedPlaygroundId !== adoptedPlaygroundId+ ? selectedPlaygroundId+ : newSessionKeyconst activeAliasChannels = (channels.data ?? []).filter((channel) =>channel.agentId === agentId &&@@ -927,16 +940,21 @@ export default function ManagedAgentDetail({))}</div></aside>- {selectedPlaygroundId && selectedPlaygroundEvents.isLoading ? (+ {selectedPlaygroundId &&+ selectedPlaygroundId !== adoptedPlaygroundId &&+ selectedPlaygroundEvents.isLoading ? (<div className="text-muted-foreground flex min-h-0 items-center justify-center gap-2 text-sm"><Loader2 className="size-4 animate-spin" /> Loading session…</div>) : (<PlaygroundChat- key={`${environment}:${selectedPlaygroundId ?? newSessionKey}`}+ key={`${environment}:${playgroundChatId}`}+ chatId={`${environment}:${playgroundChatId}`}agentId={project ? `${agentId}@${environment}` : agentId}session={selectedPlayground}- events={selectedPlaygroundEvents.data ?? []}+ events={+ selectedPlaygroundEvents.data ?? EMPTY_MANAGED_AGENT_EVENTS+ }initialPrompt={firstRunPrompt}onInitialPromptConsumed={() => {void navigate(@@ -944,7 +962,18 @@ export default function ManagedAgentDetail({{ replace: true, state: null },)}}- onSessionFinished={selectPlaygroundSession}+ onSessionFinished={(sessionId) => {+ if (!requestedPlaygroundIdRef.current) {+ setAdoptedPlaygroundId(sessionId)+ void navigate({+ pathname: location.pathname,+ search: playgroundSessionSearch(+ location.search,+ sessionId,+ ),+ })+ }+ }}/>)}</div>diff --git a/web/src/managed-agents/api.ts b/web/src/managed-agents/api.tsindex 120e07d1..ce65e820 100644--- a/web/src/managed-agents/api.ts+++ b/web/src/managed-agents/api.ts@@ -397,7 +397,10 @@ const slackManifestResponseSchema = z.object({})const sessionCreateSchema = z.object({- session: z.object({ id: z.string() }),+ session: z.object({+ id: z.string(),+ executionMode: z.enum(['microvm', 'workerd']).optional().default('microvm'),+ }),deployment: deploymentSchema.optional(),})@@ -462,6 +465,7 @@ const sessionSchema = z.object({id: z.string(),agentId: z.string(),deploymentId: z.string(),+ executionMode: z.enum(['microvm', 'workerd']).optional().default('microvm'),status: z.string(),source: z.enum(['api', 'channel', 'playground', 'schedule', 'webhook'])@@ -1110,7 +1114,7 @@ export async function admitManagedAgentInput(async function suspendManagedAgentIfIdle(sessionId: string) {const session = await getManagedAgentSession(sessionId).catch(() => undefined)- if (session?.status !== 'idle') return+ if (session?.executionMode !== 'microvm' || session.status !== 'idle') returnawait apiFetch(`/managed-agents/sessions/${encodeURIComponent(sessionId)}/suspend`,{ method: 'POST' },@@ -1213,14 +1217,18 @@ export async function runManagedAgent(const sessionId = created.session.idoptions.onSession?.(sessionId)try {- const connected = await waitForAgentEvent(- sessionId,- 0,- (event) => event.type === 'runtime.connected',- onEvent,- 90_000,- options.signal,- )+ let cursor = 0+ if (created.session.executionMode === 'microvm') {+ const connected = await waitForAgentEvent(+ sessionId,+ cursor,+ (event) => event.type === 'runtime.connected',+ onEvent,+ 90_000,+ options.signal,+ )+ cursor = connected.cursor+ }const turn = await admitManagedAgentInput(sessionId,input,@@ -1229,7 +1237,7 @@ export async function runManagedAgent()const completed = await waitForAgentEvent(sessionId,- connected.cursor,+ cursor,(event) =>event.turnId === turn.turnId &&(event.type === 'turn.completed' ||@@ -1264,7 +1272,10 @@ export async function continueManagedAgentSession(if (session.microvmState === 'terminated' || session.status === 'ended') {throw new Error('This playground session has ended. Start a new session.')}- if (session.microvmState === 'suspended') {+ if (+ session.executionMode === 'microvm' &&+ session.microvmState === 'suspended'+ ) {await apiFetch(`/managed-agents/sessions/${encodeURIComponent(sessionId)}/resume`,{ method: 'POST', signal },@@ -1318,19 +1329,23 @@ export async function invokeManagedAgent(agentId: string, input: string) {)const sessionId = created.session.idtry {- const connected = await waitForAgentEvent(- sessionId,- 0,- (event) => event.type === 'runtime.connected',- () => undefined,- 90_000,- )+ let cursor = 0+ if (created.session.executionMode === 'microvm') {+ const connected = await waitForAgentEvent(+ sessionId,+ cursor,+ (event) => event.type === 'runtime.connected',+ () => undefined,+ 90_000,+ )+ cursor = connected.cursor+ }const turn = await admitManagedAgentInput(sessionId, input, 'queue')let streamedText = ''let completedText = ''const completed = await waitForAgentEvent(sessionId,- connected.cursor,+ cursor,(event) =>event.turnId === turn.turnId &&(event.type === 'turn.completed' ||diff --git a/web/src/managed-agents/session-history.test.ts b/web/src/managed-agents/session-history.test.tsindex b24dec33..6dc2a7d7 100644--- a/web/src/managed-agents/session-history.test.ts+++ b/web/src/managed-agents/session-history.test.ts@@ -31,6 +31,7 @@ function session(id: string, deploymentId: string): ManagedAgentSession {id,agentId: 'reviewer',deploymentId,+ executionMode: 'microvm',status: 'idle',source: 'playground',createdAt: '2026-08-15T00:00:00.000Z',