History

Preserve streaming spec format refresh

Rhys Sullivan committed 4 months ago

Commit d94baf51 parent 8b66dd01 file · +26 −8Browse files

Unified · Split

packages/plugins/openapi/src/sdk/plugin.ts+26−8
@@ -878,11 +878,12 @@ export const openApiPlugin = definePlugin< · 877 unmodified lines
878878 },
879879 httpClientLayer,
880880 );
881− const compiled = yield* compileOpenApiSpec(resolved.specText);
881+ const compiled = resolved.keepPathItem
882+ ? undefined
883+ : yield* compileOpenApiSpec(resolved.specText);
882884
883885 const previousOperations = yield* ctx.storage.listOperations(rawSlug);
884886 const previousNames = new Set(previousOperations.map((op) => op.toolName));
885− const nextNames = new Set(compiled.definitions.map((def) => def.toolPath));
886887
887888 // The resolved spec text lives in the plugin blob store keyed by its
888889 // content hash (`spec/<hash>`); the config carries only the hash. Put
@@ -890,7 +891,9 @@ export const openApiPlugin = definePlugin< · 1 unmodified line
890891 // aborted config update just leaves an unreferenced blob.
891892 const specHash = yield* sha256Hex(resolved.specText);
892893 yield* ctx.storage.putSpec(specHash, resolved.specText);
893− yield* ctx.storage.putDefs(specHash, JSON.stringify(compiled.hoistedDefs));
894+ if (compiled) {
895+ yield* ctx.storage.putDefs(specHash, JSON.stringify(compiled.hoistedDefs));
896+ }
894897
895898 const nextConfig: OpenApiIntegrationConfig = {
896899 ...current,
@@ -905,13 +908,28 @@ export const openApiPlugin = definePlugin< · 8 unmodified lines
905908 yield* ctx.core.integrations.update(slug, {
906909 config: nextConfig satisfies OpenApiIntegrationConfig as IntegrationConfig,
907910 });
908− yield* ctx.storage.putOperations(
909− rawSlug,
910− openApiStoredOperationsFromCompiled(rawSlug, compiled),
911− );
911+ if (compiled) {
912+ yield* ctx.storage.putOperations(
913+ rawSlug,
914+ openApiStoredOperationsFromCompiled(rawSlug, compiled),
915+ );
916+ } else {
917+ yield* compileAndPersistOpenApiSpecStreaming({
918+ specText: resolved.specText,
919+ integration: rawSlug,
920+ storage: ctx.storage,
921+ specHash,
922+ keepPathItem: resolved.keepPathItem,
923+ });
924+ }
912925 }),
913926 );
914927
928+ const nextOperations = compiled
929+ ? openApiStoredOperationsFromCompiled(rawSlug, compiled)
930+ : yield* ctx.storage.listOperations(rawSlug);
931+ const nextNames = new Set(nextOperations.map((op) => op.toolName));
932+
915933 // Rebuild each connection's tool rows from the new spec. Outside the
916934 // transaction: refresh opens its own, and a half-refreshed catalog
917935 // self-heals on the next refresh anyway.
@@ -936,7 +954,7 @@ export const openApiPlugin = definePlugin< · 18 unmodified lines
936954
937955 return {
938956 slug,
939− toolCount: compiled.definitions.length,
957+ toolCount: nextNames.size,
940958 addedTools: [...nextNames].filter((name) => !previousNames.has(name)).sort(),
941959 removedTools: [...previousNames].filter((name) => !nextNames.has(name)).sort(),
942960 } satisfies UpdateSpecResult;