History

refactor(v2): rename PM runtime surface to runtime host

Align runtime naming with the current architecture by replacing PM-prefixed runtime services/env wiring with runtime-host terminology while keeping legacy PM env vars as fallbacks for compatibility.

Rhys Sullivan committed 8 months ago

Commit be4adee1 parent 7b46af718 files · +113 −312Browse files

Showing the changes to apps/cli/src (1 of 18 files). Show all

Unified · Split

apps/cli/src/main.ts+5−227
@@ -36,20 +36,6 @@ type WorkspaceRecord = { · 35 unmodified lines
3636 id: string;
3737 };
3838
39−type SourceRecord = {
40− id: string;
41− name: string;
42− endpoint: string;
43− configJson: string;
44−};
45−
46−type SourceToolSummaryRecord = {
47− toolId: string;
48− method: string;
49− path: string;
50− name: string;
51−};
52−
5339 type DeviceAuthorizationResponse = {
5440 device_code: string;
5541 user_code: string;
@@ -78,10 +64,6 @@ type CommonTargetOptions = { · 22 unmodified lines
7864
7965 const DEFAULT_LOCAL_BASE_URL = "http://127.0.0.1:8788";
8066 const DEFAULT_WORKOS_AUTH_BASE_URL = "https://api.workos.com";
81−const DEFAULT_GITHUB_OPENAPI_SPEC_URL =
82− "https://raw.githubusercontent.com/github/rest-api-description/main/descriptions/api.github.com/api.github.com.json";
83−const DEFAULT_GITHUB_API_BASE_URL = "https://api.github.com";
84−const DEFAULT_GITHUB_OPENAPI_SOURCE_ID = "src_github_openapi";
8567 const CONFIG_PATH = join(homedir(), ".config", "executor", "cli.json");
8668
8769 const toErrorMessage = (cause: unknown): string =>
@@ -518,6 +500,8 @@ class ExecutorServerClient { · 430 unmodified lines
518500 const childEnv = {
519501 ...cleanEnv(),
520502 PORT: localPort,
503+ EXECUTOR_RUNTIME_KIND:
504+ process.env.EXECUTOR_LOCAL_RUNTIME_KIND?.trim() || "local-inproc",
521505 PM_RUNTIME_KIND:
522506 process.env.EXECUTOR_LOCAL_RUNTIME_KIND?.trim() || "local-inproc",
523507 };
@@ -597,87 +581,6 @@ const ensureWorkspaceId = async ( · 73 unmodified lines
597581 return workspaceId;
598582 };
599583
600−const deriveSourceName = (kind: string, endpoint: string): string => {
601− try {
602− const url = new URL(endpoint);
603− const host = url.hostname.replace(/^api\./, "");
604− return `${kind}:${host}`;
605− } catch {
606− return `${kind}:source`;
607− }
608−};
609−
610−const bootstrapOpenApiSource = async (input: {
611− client: ExecutorServerClient;
612− config: ExecutorCliConfig;
613− workspaceOverride?: string;
614− specUrl: string;
615− baseUrl: string;
616− name?: string;
617− sourceId?: string;
618−}): Promise<{
619− workspaceId: string;
620− source: SourceRecord;
621− tools: Array<SourceToolSummaryRecord>;
622− sampleToolPath: string | null;
623−}> => {
624− const workspaceId = await ensureWorkspaceId(
625− input.client,
626− input.config,
627− input.workspaceOverride,
628− );
629− const normalizedSpecUrl = input.specUrl.trim();
630− const normalizedBaseUrl = input.baseUrl.trim();
631−
632− if (normalizedSpecUrl.length === 0) {
633− throw new Error("OpenAPI bootstrap requires --spec-url.");
634− }
635−
636− if (normalizedBaseUrl.length === 0) {
637− throw new Error("OpenAPI bootstrap requires --source-base-url.");
638− }
639−
640− const source = await input.client.runControlPlane((api) =>
641− api.sources.upsert({
642− path: { workspaceId },
643− payload: {
644− ...(input.sourceId && input.sourceId.trim().length > 0
645− ? { id: input.sourceId.trim() }
646− : {}),
647− name:
648− input.name && input.name.trim().length > 0
649− ? input.name.trim()
650− : deriveSourceName("openapi", normalizedBaseUrl),
651− kind: "openapi",
652− endpoint: normalizedSpecUrl,
653− status: "connected",
654− enabled: true,
655− configJson: JSON.stringify({ baseUrl: normalizedBaseUrl }),
656− },
657− }),
658− ) as SourceRecord;
659−
660− const tools = await input.client.runControlPlane((api) =>
661− api.tools.listSourceTools({
662− path: {
663− workspaceId,
664− sourceId: source.id,
665− },
666− }),
667− ) as Array<SourceToolSummaryRecord>;
668−
669− const sampleToolPath = tools[0]?.toolId
670− ? `source.${source.id}.${tools[0].toolId}`
671− : null;
672−
673− return {
674− workspaceId,
675− source,
676− tools,
677− sampleToolPath,
678− };
679−};
680−
681584 const postForm = async (
682585 url: string,
683586 params: Record<string, string>,
@@ -859,8 +762,9 @@ const commonTargetOptions = () => ({ · 175 unmodified lines
859762 });
860763
861764 const startEmbeddedLocalServer = async (port: number): Promise<void> => {
862− process.env.PM_RUNTIME_KIND =
765+ process.env.EXECUTOR_RUNTIME_KIND =
863766 process.env.EXECUTOR_LOCAL_RUNTIME_KIND?.trim() || "local-inproc";
767+ process.env.PM_RUNTIME_KIND = process.env.EXECUTOR_RUNTIME_KIND;
864768
865769 const {
866770 createLocalPrincipal,
@@ -1254,134 +1158,8 @@ const runExecuteCommand = Command.make( · 387 unmodified lines
12541158 Command.withDescription("Execute TypeScript code through Executor runtime"),
12551159 );
12561160
1257−const runBootstrapOpenApiCommand = Command.make(
1258− "openapi",
1259− {
1260− ...commonTargetOptions(),
1261− specUrl: Options.text("spec-url"),
1262− sourceBaseUrl: Options.text("source-base-url"),
1263− name: Options.text("name").pipe(Options.optional),
1264− sourceId: Options.text("source-id").pipe(Options.optional),
1265− },
1266− (input) =>
1267− Effect.tryPromise({
1268− try: async () => {
1269− const common: CommonTargetOptions = {
1270− target: input.target,
1271− workspace: input.workspace,
1272− baseUrl: input.baseUrl,
1273− json: input.json,
1274− };
1275−
1276− await withClient(common, async ({ client, config, workspaceOverride, asJson }) => {
1277− const setup = await bootstrapOpenApiSource({
1278− client,
1279− config,
1280− workspaceOverride,
1281− specUrl: input.specUrl,
1282− baseUrl: input.sourceBaseUrl,
1283− name: optionToUndefined(input.name),
1284− sourceId: optionToUndefined(input.sourceId),
1285− });
1286−
1287− printOutput(
1288− {
1289− ok: true,
1290− workspaceId: setup.workspaceId,
1291− source: {
1292− id: setup.source.id,
1293− name: setup.source.name,
1294− endpoint: setup.source.endpoint,
1295− configJson: setup.source.configJson,
1296− },
1297− toolCount: setup.tools.length,
1298− sampleToolPath: setup.sampleToolPath,
1299− },
1300− asJson,
1301− );
1302− });
1303− },
1304− catch: toErrorMessage,
1305− }),
1306−).pipe(
1307− Command.withDescription("Bootstrap an OpenAPI source with runtime base URL"),
1308−);
1309−
1310−const runBootstrapGithubCommand = Command.make(
1311− "github",
1312− {
1313− ...commonTargetOptions(),
1314− name: Options.text("name").pipe(Options.optional),
1315− sourceId: Options.text("source-id").pipe(Options.optional),
1316− specUrl: Options.text("spec-url").pipe(Options.withDefault(DEFAULT_GITHUB_OPENAPI_SPEC_URL)),
1317− sourceBaseUrl: Options.text("source-base-url").pipe(Options.withDefault(DEFAULT_GITHUB_API_BASE_URL)),
1318− },
1319− (input) =>
1320− Effect.tryPromise({
1321− try: async () => {
1322− const common: CommonTargetOptions = {
1323− target: input.target,
1324− workspace: input.workspace,
1325− baseUrl: input.baseUrl,
1326− json: input.json,
1327− };
1328−
1329− await withClient(common, async ({ client, config, workspaceOverride, asJson }) => {
1330− const setup = await bootstrapOpenApiSource({
1331− client,
1332− config,
1333− workspaceOverride,
1334− specUrl: input.specUrl,
1335− baseUrl: input.sourceBaseUrl,
1336− name: optionToUndefined(input.name) ?? "github:openapi",
1337− sourceId: optionToUndefined(input.sourceId) ?? DEFAULT_GITHUB_OPENAPI_SOURCE_ID,
1338− });
1339−
1340− const suggestedTool =
1341− setup.tools.find((tool) =>
1342− tool.toolId.includes("issues-and-pull-requests"),
1343− )
1344− ?? setup.tools[0]
1345− ?? null;
1346−
1347− printOutput(
1348− {
1349− ok: true,
1350− workspaceId: setup.workspaceId,
1351− source: {
1352− id: setup.source.id,
1353− name: setup.source.name,
1354− endpoint: setup.source.endpoint,
1355− configJson: setup.source.configJson,
1356− },
1357− toolCount: setup.tools.length,
1358− suggestedToolPath: suggestedTool
1359− ? `source.${setup.source.id}.${suggestedTool.toolId}`
1360− : null,
1361− executeHint: suggestedTool
1362− ? `executor run execute --code \"return await tools['source.${setup.source.id}.${suggestedTool.toolId}']({ q: 'repo:owner/repo is:issue state:open', per_page: 5 });\"`
1363− : null,
1364− },
1365− asJson,
1366− );
1367− });
1368− },
1369− catch: toErrorMessage,
1370− }),
1371−).pipe(
1372− Command.withDescription("Bootstrap GitHub OpenAPI source for public issue queries"),
1373−);
1374−
1375−const runBootstrapCommand = Command.make("bootstrap").pipe(
1376− Command.withSubcommands([
1377− runBootstrapOpenApiCommand,
1378− runBootstrapGithubCommand,
1379− ] as any),
1380− Command.withDescription("Bootstrap source setup shortcuts for execution workflows"),
1381−);
1382−
13831161 const runCommand = Command.make("run").pipe(
1384− Command.withSubcommands([runExecuteCommand, runBootstrapCommand] as any),
1162+ Command.withSubcommands([runExecuteCommand] as any),
13851163 Command.withDescription("Code execution commands"),
13861164 );
13871165