@@ -4,6 +4,8 @@ import type {
44} from "@rivetkit/engine-runner" ;
55import { Runner } from "@rivetkit/engine-runner" ;
66import * as cbor from "cbor-x" ;
7+ import type { Context as HonoContext } from "hono" ;
8+ import { streamSSE } from "hono/streaming" ;
79import { WSContext } from "hono/ws" ;
810import invariant from "invariant" ;
911import { lookupInRegistry } from "@/actor/definition" ;
@@ -63,6 +65,9 @@ export class EngineActorDriver implements ActorDriver {
6365 #actorRouter: ActorRouter ;
6466 #version: number = 1 ; // Version for the runner protocol
6567
68+ #runnerStarted: PromiseWithResolvers < undefined > = Promise . withResolvers ( ) ;
69+ #runnerStopped: PromiseWithResolvers < undefined > = Promise . withResolvers ( ) ;
70+
6671 constructor (
6772 registryConfig : RegistryConfig ,
6873 runConfig : RunConfig ,
@@ -111,6 +116,8 @@ export class EngineActorDriver implements ActorDriver {
111116 runnerName : this . #config. runnerName ,
112117 } ) ;
113118 }
119+
120+ this . #runnerStarted. resolve ( undefined ) ;
114121 } ,
115122 onDisconnected : ( ) => {
116123 logger ( ) . warn ( {
@@ -120,7 +127,9 @@ export class EngineActorDriver implements ActorDriver {
120127 } ) ;
121128 hasDisconnected = true ;
122129 } ,
123- onShutdown : ( ) => { } ,
130+ onShutdown : ( ) => {
131+ this . #runnerStopped. resolve ( undefined ) ;
132+ } ,
124133 fetch : this . #runnerFetch. bind ( this ) ,
125134 websocket : this . #runnerWebSocket. bind ( this ) ,
126135 onActorStart : this . #runnerOnActorStart. bind ( this ) ,
@@ -381,4 +390,17 @@ export class EngineActorDriver implements ActorDriver {
381390 logger ( ) . info ( { msg : "stopping engine actor driver" } ) ;
382391 await this . #runner. shutdown ( immediate ) ;
383392 }
393+
394+ async serverlessHandleStart ( c : HonoContext ) : Promise < Response > {
395+ await this . #runnerStarted. promise ;
396+
397+ return streamSSE ( c , async ( stream ) => {
398+ // Runner id should be set if the runner started
399+ const runnerId = this . #runner. runnerId ;
400+ invariant ( runnerId , "runnerId not set" ) ;
401+ stream . writeSSE ( { data : runnerId } ) ;
402+
403+ return this . #runnerStopped. promise ;
404+ } ) ;
405+ }
384406}
0 commit comments