feat(core): add embedded v2 session runtime and tool foundation (#30632)

This commit is contained in:
Kit Langton
2026-06-03 23:02:17 -04:00
committed by GitHub
parent c35267776a
commit 76ee87ead8
215 changed files with 31344 additions and 3278 deletions

View File

@@ -40,7 +40,15 @@ export function callAuthProbe(scenario: ActiveScenario, credentials: "missing" |
})
}
const appCache: Partial<Record<string, BackendApp>> = {}
type CachedApp = BackendApp & { readonly dispose: () => Promise<void> }
const appCache: Partial<Record<string, CachedApp>> = {}
export async function disposeApps() {
const apps = Object.values(appCache)
for (const key of Object.keys(appCache)) delete appCache[key]
await Promise.all(apps.flatMap((app) => app === undefined ? [] : [app.dispose()]))
}
function app(modules: Runtime, options: CallOptions) {
const username = options.auth?.username
@@ -48,7 +56,7 @@ function app(modules: Runtime, options: CallOptions) {
const cacheKey = `${username ?? ""}:${password ?? ""}`
if (appCache[cacheKey]) return appCache[cacheKey]
const handler = HttpRouter.toWebHandler(
const web = HttpRouter.toWebHandler(
modules.HttpApiApp.routes.pipe(
Layer.provide(
ConfigProvider.layer(
@@ -57,10 +65,11 @@ function app(modules: Runtime, options: CallOptions) {
),
),
{ disableLogger: true, memoMap: modules.memoMap },
).handler
)
return (appCache[cacheKey] = {
dispose: web.dispose,
request(input: string | URL | Request, init?: RequestInit) {
return handler(
return web.handler(
input instanceof Request ? input : new Request(new URL(input, "http://localhost"), init),
modules.HttpApiApp.context,
)