History

refactor: consolidate runtime tools into shared "built-in" source

OpenAPI and GraphQL plugins now register their runtime tools under a single "built-in" source instead of separate executor.openapi / executor.graphql sources. Tool names are namespaced (openapi.addSource, graphql.addSource) so the tree UI nests them properly.

Rhys Sullivan committed 7 months ago

Commit 9b1beaa1 parent ee768286 files · +34 −29Browse files

Unified · Split

6 files
  1. packages/core/sdk/src/index.test.ts +4 −4
  2. packages/plugins/graphql/src/sdk/plugin.test.ts +5 −2
  3. packages/plugins/graphql/src/sdk/plugin.ts +5 −4
  4. packages/plugins/openapi/src/sdk/plugin.test.ts +11 −11
  5. packages/plugins/openapi/src/sdk/plugin.ts +7 −6
  6. packages/plugins/openapi/src/sdk/real-specs.test.ts +2 −2
packages/core/sdk/src/index.test.ts+4−4
@@ -47,9 +47,9 @@ describe("SDK Executor", () => { · 46 unmodified lines
4747 const sources = makeInMemorySourceRegistry();
4848
4949 yield* sources.registerRuntime(new Source({
50− id: "executor.openapi",
51− name: "OpenAPI",
52− kind: "openapi",
50+ id: "built-in",
51+ name: "Built In",
52+ kind: "built-in",
5353 runtime: true,
5454 canRemove: false,
5555 canRefresh: false,
@@ -72,7 +72,7 @@ describe("SDK Executor", () => { · 16 unmodified lines
7272 });
7373
7474 expect((yield* sources.list()).map((source) => source.id)).toEqual([
75− "executor.openapi",
75+ "built-in",
7676 "vercel",
7777 ]);
7878 }),
packages/plugins/graphql/src/sdk/plugin.test.ts+5−2
@@ -153,12 +153,15 @@ describe("graphqlPlugin", () => { · 152 unmodified lines
153153 );
154154
155155 const sources = await Effect.runPromise(executor.sources.list());
156− // 1 user source + 1 runtime source (executor.graphql)
156+ // 1 user source + 1 built-in runtime source
157157 const gqlSources = sources.filter((s) => s.kind === "graphql");
158− expect(gqlSources).toHaveLength(2);
158+ expect(gqlSources).toHaveLength(1);
159159 const userSource = gqlSources.find((s) => s.id === "my_gql");
160160 expect(userSource).toBeDefined();
161161 expect(userSource!.canRemove).toBe(true);
162+ const builtIn = sources.find((s) => s.id === "built-in");
163+ expect(builtIn).toBeDefined();
164+ expect(builtIn!.runtime).toBe(true);
162165
163166 await Effect.runPromise(executor.close());
164167 });
packages/plugins/graphql/src/sdk/plugin.ts+5−4
@@ -371,13 +371,14 @@ export const graphqlPlugin = (options?: { · 370 unmodified lines
371371 sources: ctx.sources,
372372 pluginKey: "graphql",
373373 source: {
374− id: "executor.graphql",
375− name: "GraphQL",
374+ id: "built-in",
375+ name: "Built In",
376+ kind: "built-in",
376377 },
377378 tools: [
378379 runtimeTool({
379− id: "executor.graphql.addSource",
380− name: "addSource",
380+ id: "graphql.addSource",
381+ name: "graphql.addSource",
381382 description:
382383 "Add a GraphQL endpoint and register its operations as tools",
383384 inputSchema: AddSourceInputSchema,
packages/plugins/openapi/src/sdk/plugin.test.ts+11−11
@@ -128,7 +128,7 @@ layer(TestLayer)("OpenAPI Plugin", (it) => { · 127 unmodified lines
128128 }),
129129 );
130130
131− it.effect("registers runtime executor.openapi tools", () =>
131+ it.effect("registers runtime openapi tools under built-in source", () =>
132132 Effect.gen(function* () {
133133 const httpClient = yield* HttpClient.HttpClient;
134134 const clientLayer = Layer.succeed(HttpClient.HttpClient, httpClient);
@@ -143,12 +143,12 @@ layer(TestLayer)("OpenAPI Plugin", (it) => { · 8 unmodified lines
143143
144144 const tools = yield* executor.tools.list();
145145 const ids = tools.map((t) => t.id);
146− expect(ids).toContain("executor.openapi.previewSpec");
147− expect(ids).toContain("executor.openapi.addSource");
146+ expect(ids).toContain("openapi.previewSpec");
147+ expect(ids).toContain("openapi.addSource");
148148 }),
149149 );
150150
151− it.effect("lists executor.openapi as a runtime source", () =>
151+ it.effect("lists built-in as a runtime source", () =>
152152 Effect.gen(function* () {
153153 const httpClient = yield* HttpClient.HttpClient;
154154 const clientLayer = Layer.succeed(HttpClient.HttpClient, httpClient);
@@ -164,9 +164,9 @@ layer(TestLayer)("OpenAPI Plugin", (it) => { · 9 unmodified lines
164164 const sources = yield* executor.sources.list();
165165
166166 expect(sources).toContainEqual(expect.objectContaining({
167− id: "executor.openapi",
168− name: "OpenAPI",
169− kind: "openapi",
167+ id: "built-in",
168+ name: "Built In",
169+ kind: "built-in",
170170 runtime: true,
171171 canRemove: false,
172172 canRefresh: false,
@@ -239,7 +239,7 @@ layer(TestLayer)("OpenAPI Plugin", (it) => { · 66 unmodified lines
239239 );
240240
241241 const result = yield* executor.tools.invoke(
242− "executor.openapi.previewSpec",
242+ "openapi.previewSpec",
243243 { spec: specJson },
244244 autoApprove,
245245 );
@@ -263,7 +263,7 @@ layer(TestLayer)("OpenAPI Plugin", (it) => { · 17 unmodified lines
263263 );
264264
265265 const result = yield* executor.tools.invoke(
266− "executor.openapi.addSource",
266+ "openapi.addSource",
267267 { spec: specJson, namespace: "runtime" },
268268 autoApprove,
269269 );
@@ -459,8 +459,8 @@ layer(TestLayer)("OpenAPI Plugin", (it) => { · 189 unmodified lines
459459
460460 const remaining = yield* executor.tools.list();
461461 expect(remaining.map((tool) => tool.id)).toEqual([
462− "executor.openapi.previewSpec",
463− "executor.openapi.addSource",
462+ "openapi.previewSpec",
463+ "openapi.addSource",
464464 ]);
465465 }),
466466 );
packages/plugins/openapi/src/sdk/plugin.ts+7−6
@@ -295,13 +295,14 @@ export const openApiPlugin = (options?: { · 294 unmodified lines
295295 sources: ctx.sources,
296296 pluginKey: "openapi",
297297 source: {
298− id: "executor.openapi",
299− name: "OpenAPI",
298+ id: "built-in",
299+ name: "Built In",
300+ kind: "built-in",
300301 },
301302 tools: [
302303 runtimeTool({
303− id: "executor.openapi.previewSpec",
304− name: "previewSpec",
304+ id: "openapi.previewSpec",
305+ name: "openapi.previewSpec",
305306 description:
306307 "Preview an OpenAPI document before adding it as a source",
307308 inputSchema: PreviewSpecInputSchema,
@@ -309,8 +310,8 @@ export const openApiPlugin = (options?: { · 1 unmodified line
309310 handler: ({ spec }: PreviewSpecInput) => previewSpec(spec),
310311 }),
311312 runtimeTool({
312− id: "executor.openapi.addSource",
313− name: "addSource",
313+ id: "openapi.addSource",
314+ name: "openapi.addSource",
314315 description:
315316 "Add an OpenAPI source and register its operations as tools",
316317 inputSchema: AddSourceInputSchema,
packages/plugins/openapi/src/sdk/real-specs.test.ts+2−2
@@ -217,8 +217,8 @@ describe("Real specs: Cloudflare API", () => { · 216 unmodified lines
217217
218218 const remaining = yield* executor.tools.list();
219219 expect(remaining.map((tool) => tool.id)).toEqual([
220− "executor.openapi.previewSpec",
221− "executor.openapi.addSource",
220+ "openapi.previewSpec",
221+ "openapi.addSource",
222222 ]);
223223 }),
224224 );