Skip to content

Commit 3dba810

Browse files
committed
Consolidate custom tools plugin wiring
1 parent aeb4833 commit 3dba810

18 files changed

Lines changed: 497 additions & 310 deletions

apps/host-selfhost/executor.config.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ import { mcpHttpPlugin } from "@executor-js/plugin-mcp/api";
66
import { graphqlHttpPlugin } from "@executor-js/plugin-graphql/api";
77
import { encryptedSecretsPlugin } from "@executor-js/plugin-encrypted-secrets";
88
import { toolkitsPlugin } from "@executor-js/plugin-toolkits/server";
9+
import { appsPlugin } from "@executor-js/plugin-apps/api";
910

1011
import { resolveSecretKey } from "./src/config";
11-
import { getSelfHostAppsSubsystem } from "./src/apps";
12+
import { getSelfHostAppsBackings } from "./src/apps-backings";
1213

1314
// ---------------------------------------------------------------------------
1415
// Single source of truth for the self-hosted app's plugin list.
@@ -37,7 +38,7 @@ export default defineExecutorConfig({
3738
mcpHttpPlugin({ dangerouslyAllowStdioMCP: false }),
3839
graphqlHttpPlugin(),
3940
toolkitsPlugin({ activeToolkitSlug }),
40-
getSelfHostAppsSubsystem().plugin,
41+
appsPlugin({ backings: getSelfHostAppsBackings() }),
4142
// First writable secret provider -> the default for `secrets.set`.
4243
encryptedSecretsPlugin({ key: resolveSecretKey() }),
4344
] as const,

apps/host-selfhost/src/app.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ import { makeSelfHostMcpSeams } from "./mcp";
2222
import { selfHostPlugins } from "./plugins";
2323
import { ErrorCaptureLive } from "./observability";
2424
import { oauthCallbackSignInRedirectLocation } from "./auth/oauth-callback-login";
25-
import { closeSelfHostAppsSubsystem } from "./apps";
26-
import { makeSelfHostAppsSyncRoute } from "./apps-route";
25+
import { closeSelfHostAppsBackings } from "./apps-backings";
2726

2827
// ===========================================================================
2928
// The self-hosted Executor app, as ONE `ExecutorApp.make` call.
@@ -121,7 +120,6 @@ export const makeSelfHostApp = async (options: MakeSelfHostAppOptions = {}) => {
121120
makeSelfHostAdminApiLayer({ betterAuth, db: dbHandle, mountPrefix: "/api" }),
122121
// Public system API: /api/health + /api/setup-status (unauthenticated).
123122
makeSelfHostSystemApiLayer({ betterAuth, db: dbHandle, mountPrefix: "/api" }),
124-
makeSelfHostAppsSyncRoute({ identity: identityLayer, db: dbHandle }),
125123
// Swagger UI at /docs, over the /api-prefixed spec (matches the served paths).
126124
HttpApiSwagger.layer(composePluginApi(selfHostPlugins).prefix("/api"), { path: "/docs" }),
127125
],
@@ -142,7 +140,7 @@ export const makeSelfHostApp = async (options: MakeSelfHostAppOptions = {}) => {
142140
toWebHandler,
143141
betterAuth,
144142
closeDb: async () => {
145-
await closeSelfHostAppsSubsystem();
143+
await closeSelfHostAppsBackings();
146144
await mcp.close();
147145
await dbHandle.close();
148146
},
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import { join } from "node:path";
2+
3+
import { Effect } from "effect";
4+
5+
import {
6+
makeGitArtifactStore,
7+
makeLibsqlScopeDb,
8+
makeQuickjsToolSandbox,
9+
makeSqliteAppsStore,
10+
type AppsBackings,
11+
} from "@executor-js/plugin-apps/api";
12+
13+
import { resolveDataDir } from "./config";
14+
15+
interface SelfHostAppsBackings {
16+
readonly backings: AppsBackings;
17+
readonly close: () => Promise<void>;
18+
}
19+
20+
const createBackings = (dataDir: string): SelfHostAppsBackings => {
21+
const appsDir = join(dataDir, "apps");
22+
const scopeDb = makeLibsqlScopeDb({
23+
root: join(appsDir, "scope-db"),
24+
});
25+
return {
26+
backings: {
27+
artifactStore: makeGitArtifactStore({ root: join(appsDir, "artifacts") }),
28+
scopeDb,
29+
sandbox: makeQuickjsToolSandbox(),
30+
store: makeSqliteAppsStore({ path: join(appsDir, "store.sqlite") }),
31+
},
32+
close: async () => {
33+
await Effect.runPromise(scopeDb.close().pipe(Effect.orElseSucceed(() => undefined)));
34+
},
35+
};
36+
};
37+
38+
let current: { readonly dataDir: string; readonly value: SelfHostAppsBackings } | undefined;
39+
40+
export const getSelfHostAppsBackings = (): AppsBackings => {
41+
const dataDir = resolveDataDir();
42+
if (current && current.dataDir === dataDir) return current.value.backings;
43+
const value = createBackings(dataDir);
44+
current = { dataDir, value };
45+
return value.backings;
46+
};
47+
48+
export const closeSelfHostAppsBackings = async (): Promise<void> => {
49+
const value = current?.value;
50+
current = undefined;
51+
await value?.close();
52+
};

apps/host-selfhost/src/apps-route.ts

Lines changed: 0 additions & 166 deletions
This file was deleted.

apps/host-selfhost/src/apps.ts

Lines changed: 0 additions & 71 deletions
This file was deleted.

apps/host-selfhost/src/testing/test-app.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ import {
3030
} from "../mcp/session-store";
3131
import { selfHostPlugins } from "../plugins";
3232
import { ErrorCaptureLive } from "../observability";
33-
import { closeSelfHostAppsSubsystem } from "../apps";
34-
import { makeSelfHostAppsSyncRoute } from "../apps-route";
33+
import { closeSelfHostAppsBackings } from "../apps-backings";
3534

3635
// ===========================================================================
3736
// Self-host TEST harness — the throwaway composition tests use to exercise the
@@ -204,7 +203,6 @@ export const makeSelfHostTestApp = async (
204203
},
205204
extensions: {
206205
routes: [
207-
makeSelfHostAppsSyncRoute({ identity: options.identity, db: dbHandle }),
208206
HttpApiSwagger.layer(composePluginApi(selfHostPlugins).prefix("/api"), { path: "/docs" }),
209207
],
210208
},
@@ -220,7 +218,7 @@ export const makeSelfHostTestApp = async (
220218
handler: web.handler,
221219
dispose: async () => {
222220
await web.dispose();
223-
await closeSelfHostAppsSubsystem();
221+
await closeSelfHostAppsBackings();
224222
await sessionStore.close();
225223
await dbHandle.close();
226224
},

bun.lock

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)