@@ -9,7 +9,6 @@ import { createBackends, createNotificationService } from "./notifications/index
99import { createDefaultDriver } from "./driver.js" ;
1010import { createProviderRegistry } from "./providers/index.js" ;
1111import { createClient } from "rivetkit/client" ;
12- import type { FoundryBillingPlanId } from "@sandbox-agent/foundry-shared" ;
1312import { initBetterAuthService } from "./services/better-auth.js" ;
1413import { createDefaultAppShellServices } from "./services/app-shell-runtime.js" ;
1514import { APP_SHELL_WORKSPACE_ID } from "./actors/workspace/app-shell.js" ;
@@ -205,23 +204,6 @@ export async function startBackend(options: BackendStartOptions = {}): Promise<v
205204 }
206205 } ;
207206
208- const appWorkspaceAction = async < T > ( action : string , run : ( workspace : any ) => Promise < T > , context : AppWorkspaceLogContext = { } ) : Promise < T > => {
209- try {
210- return await run ( await appWorkspace ( { ...context , action } ) ) ;
211- } catch ( error ) {
212- logger . error (
213- {
214- ...context ,
215- action,
216- errorMessage : error instanceof Error ? error . message : String ( error ) ,
217- errorStack : error instanceof Error ? error . stack : undefined ,
218- } ,
219- "app_workspace_action_failed" ,
220- ) ;
221- throw error ;
222- }
223- } ;
224-
225207 const requestLogContext = ( c : any , sessionId ?: string ) : AppWorkspaceLogContext => ( {
226208 ...requestHeaderContext ( c ) ,
227209 method : c . req . method ,
@@ -235,30 +217,6 @@ export async function startBackend(options: BackendStartOptions = {}): Promise<v
235217 return session ?. session ?. id ?? null ;
236218 } ;
237219
238- app . get ( "/v1/app/snapshot" , async ( c ) => {
239- const sessionId = await resolveSessionId ( c ) ;
240- if ( ! sessionId ) {
241- return c . json ( {
242- auth : { status : "signed_out" , currentUserId : null } ,
243- activeOrganizationId : null ,
244- onboarding : {
245- starterRepo : {
246- repoFullName : "rivet-dev/sandbox-agent" ,
247- repoUrl : "https://github.com/rivet-dev/sandbox-agent" ,
248- status : "pending" ,
249- starredAt : null ,
250- skippedAt : null ,
251- } ,
252- } ,
253- users : [ ] ,
254- organizations : [ ] ,
255- } ) ;
256- }
257- return c . json (
258- await appWorkspaceAction ( "getAppSnapshot" , async ( workspace ) => await workspace . getAppSnapshot ( { sessionId } ) , requestLogContext ( c , sessionId ) ) ,
259- ) ;
260- } ) ;
261-
262220 app . all ( "/v1/auth/*" , async ( c ) => {
263221 return await betterAuth . auth . handler ( c . req . raw ) ;
264222 } ) ;
@@ -289,126 +247,6 @@ export async function startBackend(options: BackendStartOptions = {}): Promise<v
289247 } ) ;
290248 } ) ;
291249
292- app . post ( "/v1/app/onboarding/starter-repo/skip" , async ( c ) => {
293- const sessionId = await resolveSessionId ( c ) ;
294- if ( ! sessionId ) {
295- return c . text ( "Unauthorized" , 401 ) ;
296- }
297- return c . json (
298- await appWorkspaceAction ( "skipAppStarterRepo" , async ( workspace ) => await workspace . skipAppStarterRepo ( { sessionId } ) , requestLogContext ( c , sessionId ) ) ,
299- ) ;
300- } ) ;
301-
302- app . post ( "/v1/app/organizations/:organizationId/starter-repo/star" , async ( c ) => {
303- const sessionId = await resolveSessionId ( c ) ;
304- if ( ! sessionId ) {
305- return c . text ( "Unauthorized" , 401 ) ;
306- }
307- return c . json (
308- await appWorkspaceAction (
309- "starAppStarterRepo" ,
310- async ( workspace ) =>
311- await workspace . starAppStarterRepo ( {
312- sessionId,
313- organizationId : c . req . param ( "organizationId" ) ,
314- } ) ,
315- requestLogContext ( c , sessionId ) ,
316- ) ,
317- ) ;
318- } ) ;
319-
320- app . post ( "/v1/app/organizations/:organizationId/select" , async ( c ) => {
321- const sessionId = await resolveSessionId ( c ) ;
322- if ( ! sessionId ) {
323- return c . text ( "Unauthorized" , 401 ) ;
324- }
325- return c . json (
326- await appWorkspaceAction (
327- "selectAppOrganization" ,
328- async ( workspace ) =>
329- await workspace . selectAppOrganization ( {
330- sessionId,
331- organizationId : c . req . param ( "organizationId" ) ,
332- } ) ,
333- requestLogContext ( c , sessionId ) ,
334- ) ,
335- ) ;
336- } ) ;
337-
338- app . patch ( "/v1/app/organizations/:organizationId/profile" , async ( c ) => {
339- const sessionId = await resolveSessionId ( c ) ;
340- if ( ! sessionId ) {
341- return c . text ( "Unauthorized" , 401 ) ;
342- }
343- const body = await c . req . json ( ) ;
344- return c . json (
345- await appWorkspaceAction (
346- "updateAppOrganizationProfile" ,
347- async ( workspace ) =>
348- await workspace . updateAppOrganizationProfile ( {
349- sessionId,
350- organizationId : c . req . param ( "organizationId" ) ,
351- displayName : typeof body ?. displayName === "string" ? body . displayName : "" ,
352- slug : typeof body ?. slug === "string" ? body . slug : "" ,
353- primaryDomain : typeof body ?. primaryDomain === "string" ? body . primaryDomain : "" ,
354- } ) ,
355- requestLogContext ( c , sessionId ) ,
356- ) ,
357- ) ;
358- } ) ;
359-
360- app . post ( "/v1/app/organizations/:organizationId/import" , async ( c ) => {
361- const sessionId = await resolveSessionId ( c ) ;
362- if ( ! sessionId ) {
363- return c . text ( "Unauthorized" , 401 ) ;
364- }
365- return c . json (
366- await appWorkspaceAction (
367- "triggerAppRepoImport" ,
368- async ( workspace ) =>
369- await workspace . triggerAppRepoImport ( {
370- sessionId,
371- organizationId : c . req . param ( "organizationId" ) ,
372- } ) ,
373- requestLogContext ( c , sessionId ) ,
374- ) ,
375- ) ;
376- } ) ;
377-
378- app . post ( "/v1/app/organizations/:organizationId/reconnect" , async ( c ) => {
379- const sessionId = await resolveSessionId ( c ) ;
380- if ( ! sessionId ) {
381- return c . text ( "Unauthorized" , 401 ) ;
382- }
383- return c . json (
384- await appWorkspaceAction (
385- "beginAppGithubInstall" ,
386- async ( workspace ) =>
387- await workspace . beginAppGithubInstall ( {
388- sessionId,
389- organizationId : c . req . param ( "organizationId" ) ,
390- } ) ,
391- requestLogContext ( c , sessionId ) ,
392- ) ,
393- ) ;
394- } ) ;
395-
396- app . post ( "/v1/app/organizations/:organizationId/billing/checkout" , async ( c ) => {
397- const sessionId = await resolveSessionId ( c ) ;
398- if ( ! sessionId ) {
399- return c . text ( "Unauthorized" , 401 ) ;
400- }
401- const body = await c . req . json ( ) . catch ( ( ) => ( { } ) ) ;
402- const planId = body ?. planId === "free" || body ?. planId === "team" ? ( body . planId as FoundryBillingPlanId ) : "team" ;
403- return c . json (
404- await ( await appWorkspace ( requestLogContext ( c , sessionId ) ) ) . createAppCheckoutSession ( {
405- sessionId,
406- organizationId : c . req . param ( "organizationId" ) ,
407- planId,
408- } ) ,
409- ) ;
410- } ) ;
411-
412250 app . get ( "/v1/billing/checkout/complete" , async ( c ) => {
413251 const organizationId = c . req . query ( "organizationId" ) ;
414252 const checkoutSessionId = c . req . query ( "session_id" ) ;
@@ -427,58 +265,6 @@ export async function startBackend(options: BackendStartOptions = {}): Promise<v
427265 return Response . redirect ( result . redirectTo , 302 ) ;
428266 } ) ;
429267
430- app . post ( "/v1/app/organizations/:organizationId/billing/portal" , async ( c ) => {
431- const sessionId = await resolveSessionId ( c ) ;
432- if ( ! sessionId ) {
433- return c . text ( "Unauthorized" , 401 ) ;
434- }
435- return c . json (
436- await ( await appWorkspace ( requestLogContext ( c , sessionId ) ) ) . createAppBillingPortalSession ( {
437- sessionId,
438- organizationId : c . req . param ( "organizationId" ) ,
439- } ) ,
440- ) ;
441- } ) ;
442-
443- app . post ( "/v1/app/organizations/:organizationId/billing/cancel" , async ( c ) => {
444- const sessionId = await resolveSessionId ( c ) ;
445- if ( ! sessionId ) {
446- return c . text ( "Unauthorized" , 401 ) ;
447- }
448- return c . json (
449- await ( await appWorkspace ( requestLogContext ( c , sessionId ) ) ) . cancelAppScheduledRenewal ( {
450- sessionId,
451- organizationId : c . req . param ( "organizationId" ) ,
452- } ) ,
453- ) ;
454- } ) ;
455-
456- app . post ( "/v1/app/organizations/:organizationId/billing/resume" , async ( c ) => {
457- const sessionId = await resolveSessionId ( c ) ;
458- if ( ! sessionId ) {
459- return c . text ( "Unauthorized" , 401 ) ;
460- }
461- return c . json (
462- await ( await appWorkspace ( requestLogContext ( c , sessionId ) ) ) . resumeAppSubscription ( {
463- sessionId,
464- organizationId : c . req . param ( "organizationId" ) ,
465- } ) ,
466- ) ;
467- } ) ;
468-
469- app . post ( "/v1/app/workspaces/:workspaceId/seat-usage" , async ( c ) => {
470- const sessionId = await resolveSessionId ( c ) ;
471- if ( ! sessionId ) {
472- return c . text ( "Unauthorized" , 401 ) ;
473- }
474- return c . json (
475- await ( await appWorkspace ( requestLogContext ( c , sessionId ) ) ) . recordAppSeatUsage ( {
476- sessionId,
477- workspaceId : c . req . param ( "workspaceId" ) ,
478- } ) ,
479- ) ;
480- } ) ;
481-
482268 const handleStripeWebhook = async ( c : any ) => {
483269 const payload = await c . req . text ( ) ;
484270 await ( await appWorkspace ( requestLogContext ( c ) ) ) . handleAppStripeWebhook ( {
0 commit comments