|
|
@@ -11,9 +11,11 @@ import { Session } from "../../session"
|
|
|
import { Config } from "../../config/config"
|
|
|
import { ConsoleState } from "../../config/console-state"
|
|
|
import { Account, AccountID, OrgID } from "../../account"
|
|
|
+import { AppRuntime } from "../../effect/app-runtime"
|
|
|
import { zodToJsonSchema } from "zod-to-json-schema"
|
|
|
import { errors } from "../error"
|
|
|
import { lazy } from "../../util/lazy"
|
|
|
+import { Effect, Option } from "effect"
|
|
|
import { WorkspaceRoutes } from "./workspace"
|
|
|
import { Agent } from "@/agent/agent"
|
|
|
|
|
|
@@ -55,11 +57,18 @@ export const ExperimentalRoutes = lazy(() =>
|
|
|
},
|
|
|
}),
|
|
|
async (c) => {
|
|
|
- const [consoleState, groups] = await Promise.all([Config.getConsoleState(), Account.orgsByAccount()])
|
|
|
- return c.json({
|
|
|
- ...consoleState,
|
|
|
- switchableOrgCount: groups.reduce((count, group) => count + group.orgs.length, 0),
|
|
|
- })
|
|
|
+ const result = await AppRuntime.runPromise(
|
|
|
+ Effect.gen(function* () {
|
|
|
+ const config = yield* Config.Service
|
|
|
+ const account = yield* Account.Service
|
|
|
+ const [state, groups] = yield* Effect.all([config.getConsoleState(), account.orgsByAccount()], { concurrency: "unbounded" })
|
|
|
+ return {
|
|
|
+ ...state,
|
|
|
+ switchableOrgCount: groups.reduce((count, group) => count + group.orgs.length, 0),
|
|
|
+ }
|
|
|
+ }),
|
|
|
+ )
|
|
|
+ return c.json(result)
|
|
|
},
|
|
|
)
|
|
|
.get(
|
|
|
@@ -80,17 +89,22 @@ export const ExperimentalRoutes = lazy(() =>
|
|
|
},
|
|
|
}),
|
|
|
async (c) => {
|
|
|
- const [groups, active] = await Promise.all([Account.orgsByAccount(), Account.active()])
|
|
|
-
|
|
|
- const orgs = groups.flatMap((group) =>
|
|
|
- group.orgs.map((org) => ({
|
|
|
- accountID: group.account.id,
|
|
|
- accountEmail: group.account.email,
|
|
|
- accountUrl: group.account.url,
|
|
|
- orgID: org.id,
|
|
|
- orgName: org.name,
|
|
|
- active: !!active && active.id === group.account.id && active.active_org_id === org.id,
|
|
|
- })),
|
|
|
+ const orgs = await AppRuntime.runPromise(
|
|
|
+ Effect.gen(function* () {
|
|
|
+ const account = yield* Account.Service
|
|
|
+ const [groups, active] = yield* Effect.all([account.orgsByAccount(), account.active()], { concurrency: "unbounded" })
|
|
|
+ const info = Option.getOrUndefined(active)
|
|
|
+ return groups.flatMap((group) =>
|
|
|
+ group.orgs.map((org) => ({
|
|
|
+ accountID: group.account.id,
|
|
|
+ accountEmail: group.account.email,
|
|
|
+ accountUrl: group.account.url,
|
|
|
+ orgID: org.id,
|
|
|
+ orgName: org.name,
|
|
|
+ active: !!info && info.id === group.account.id && info.active_org_id === org.id,
|
|
|
+ })),
|
|
|
+ )
|
|
|
+ }),
|
|
|
)
|
|
|
return c.json({ orgs })
|
|
|
},
|
|
|
@@ -115,7 +129,12 @@ export const ExperimentalRoutes = lazy(() =>
|
|
|
validator("json", ConsoleSwitchBody),
|
|
|
async (c) => {
|
|
|
const body = c.req.valid("json")
|
|
|
- await Account.switchOrg(AccountID.make(body.accountID), OrgID.make(body.orgID))
|
|
|
+ await AppRuntime.runPromise(
|
|
|
+ Effect.gen(function* () {
|
|
|
+ const account = yield* Account.Service
|
|
|
+ yield* account.use(AccountID.make(body.accountID), Option.some(OrgID.make(body.orgID)))
|
|
|
+ }),
|
|
|
+ )
|
|
|
return c.json(true)
|
|
|
},
|
|
|
)
|