Unified · Split
| @@ -38,6 +38,7 @@ · 37 unmodified lines | ||
| 38 | 38 | "@effect/platform-node": "catalog:", |
| 39 | 39 | "@executor/codemode-core": "workspace:*", |
| 40 | 40 | "@executor/executor-mcp": "workspace:*", |
| 41 | + "@executor/plugin-openapi-sdk": "workspace:*", | |
| 41 | 42 | "@executor/platform-api": "workspace:*", |
| 42 | 43 | "@executor/platform-internal": "workspace:*", |
| 43 | 44 | "@executor/platform-sdk": "workspace:*", |
| @@ -14,11 +14,13 @@ import { · 13 unmodified lines | ||
| 14 | 14 | type ExecutorApiEffectClient as ExecutorApiClient, |
| 15 | 15 | } from "@executor/platform-api/effect"; |
| 16 | 16 | import { runExecutorMcpStdioServer } from "@executor/executor-mcp"; |
| 17 | +import { | |
| 18 | + openApiSdkPlugin, | |
| 19 | +} from "@executor/plugin-openapi-sdk"; | |
| 17 | 20 | import { createWorkspaceExecutorAdminToolMap } from "@executor/platform-internal"; |
| 18 | 21 | import { |
| 19 | 22 | EXECUTOR_SOURCES_ADD_HELP_LINES, |
| 20 | 23 | RuntimeExecutionResolverService, |
| 21 | − hasRegisteredExecutorAddableSourceAdapters, | |
| 22 | 24 | } from "@executor/platform-sdk/runtime"; |
| 23 | 25 | import { |
| 24 | 26 | createExecutorEffect, |
| @@ -38,6 +40,7 @@ import * as Option from "effect/Option"; · 13 unmodified lines | ||
| 38 | 40 | import * as Cause from "effect/Cause"; |
| 39 | 41 | |
| 40 | 42 | import { |
| 43 | + createFileOpenApiSourceStorage, | |
| 41 | 44 | createLocalExecutorServer, |
| 42 | 45 | DEFAULT_SERVER_BASE_URL, |
| 43 | 46 | DEFAULT_SERVER_HOST, |
| @@ -71,7 +74,6 @@ import { · 27 unmodified lines | ||
| 71 | 74 | |
| 72 | 75 | const toError = (cause: unknown): Error => |
| 73 | 76 | cause instanceof Error ? cause : new Error(String(cause)); |
| 74 | − | |
| 75 | 77 | const sleep = (ms: number) => |
| 76 | 78 | Effect.promise(() => new Promise<void>((resolve) => setTimeout(resolve, ms))); |
| 77 | 79 | |
| @@ -214,16 +216,9 @@ const buildWorkflowText = (namespaces: readonly string[] = []): string => · 136 unmodified lines | ||
| 214 | 216 | '1) const matches = await tools.discover({ query: "<intent>", limit: 12 });', |
| 215 | 217 | "2) const details = await tools.describe.tool({ path, includeSchemas: true });", |
| 216 | 218 | "3) Call selected tools.<path>(input).", |
| 217 | − ...(hasRegisteredExecutorAddableSourceAdapters | |
| 218 | − ? [ | |
| 219 | − "4) To connect a source plugin, call tools.executor.sources.add(...).", | |
| 220 | − ...EXECUTOR_SOURCES_ADD_HELP_LINES, | |
| 221 | − "5) If execution pauses for interaction, resume it with `executor resume --execution-id ...`.", | |
| 222 | − ] | |
| 223 | − : [ | |
| 224 | − "4) Source plugins are not registered in this build.", | |
| 225 | − "5) If execution pauses for interaction, resume it with `executor resume --execution-id ...`.", | |
| 226 | − ]), | |
| 219 | + "4) Source plugins are not registered in this build.", | |
| 220 | + ...EXECUTOR_SOURCES_ADD_HELP_LINES, | |
| 221 | + "5) If execution pauses for interaction, resume it with `executor resume --execution-id ...`.", | |
| 227 | 222 | "Do not use fetch; use tools.* only.", |
| 228 | 223 | ].join("\n"); |
| 229 | 224 | |
| @@ -293,6 +288,13 @@ const loadRunWorkflowText = (): Effect.Effect<string, Error, never> => · 63 unmodified lines | ||
| 293 | 288 | backend: createLocalExecutorBackend({ |
| 294 | 289 | localDataDir: DEFAULT_LOCAL_DATA_DIR, |
| 295 | 290 | }), |
| 291 | + plugins: [ | |
| 292 | + openApiSdkPlugin({ | |
| 293 | + storage: createFileOpenApiSourceStorage({ | |
| 294 | + rootDir: `${DEFAULT_LOCAL_DATA_DIR}/plugins/openapi/sources`, | |
| 295 | + }), | |
| 296 | + }), | |
| 297 | + ] as const, | |
| 296 | 298 | createInternalToolMap: createWorkspaceExecutorAdminToolMap, |
| 297 | 299 | }).pipe(Effect.mapError(toError)), |
| 298 | 300 | (executor) => |
| @@ -420,7 +422,6 @@ const getLocalAuthedClient = (baseUrl: string = DEFAULT_SERVER_BASE_URL) => · 121 unmodified lines | ||
| 420 | 422 | const installation = yield* bootstrapClient.local.installation({}); |
| 421 | 423 | const client = yield* createExecutorApiClient({ |
| 422 | 424 | baseUrl, |
| 423 | − accountId: installation.actorScopeId, | |
| 424 | 425 | }); |
| 425 | 426 | |
| 426 | 427 | return { |
| @@ -1,113 +0,0 @@ | ||
| 1 | −import { describe, expect, it } from "@effect/vitest"; | |
| 2 | −import type { ExecutionInteraction } from "@executor/platform-sdk/schema"; | |
| 3 | − | |
| 4 | −import { | |
| 5 | − buildPausedExecutionOutput, | |
| 6 | − parseInteractionPayload, | |
| 7 | −} from "./pending-interaction-output"; | |
| 8 | − | |
| 9 | −const makeInteraction = (patch: Partial<ExecutionInteraction> = {}): ExecutionInteraction => ({ | |
| 10 | − id: "exec_123:tool_execution_gate:call_1" as never, | |
| 11 | − executionId: "exec_123" as never, | |
| 12 | − status: "pending", | |
| 13 | − kind: "form", | |
| 14 | − purpose: "tool_execution_gate", | |
| 15 | − payloadJson: JSON.stringify({ | |
| 16 | − elicitation: { | |
| 17 | − mode: "form", | |
| 18 | − message: "Allow DELETE /v2/domains/{domain}/records/{recordId}?", | |
| 19 | − requestedSchema: { | |
| 20 | − type: "object", | |
| 21 | − properties: { | |
| 22 | − approve: { | |
| 23 | − type: "boolean", | |
| 24 | − description: "Whether to approve the tool call", | |
| 25 | − }, | |
| 26 | − }, | |
| 27 | − required: ["approve"], | |
| 28 | − additionalProperties: false, | |
| 29 | − }, | |
| 30 | − }, | |
| 31 | − }), | |
| 32 | − responseJson: null, | |
| 33 | − responsePrivateJson: null, | |
| 34 | − createdAt: 1, | |
| 35 | − updatedAt: 1, | |
| 36 | − ...patch, | |
| 37 | −}); | |
| 38 | − | |
| 39 | −describe("pending-interaction-output", () => { | |
| 40 | − it("parses requested schema from interaction payload", () => { | |
| 41 | − const parsed = parseInteractionPayload(makeInteraction()); | |
| 42 | − | |
| 43 | − expect(parsed).not.toBeNull(); | |
| 44 | − expect(parsed?.mode).toBe("form"); | |
| 45 | − expect(parsed?.requestedSchema).toEqual({ | |
| 46 | − type: "object", | |
| 47 | − properties: { | |
| 48 | − approve: { | |
| 49 | − type: "boolean", | |
| 50 | − description: "Whether to approve the tool call", | |
| 51 | − }, | |
| 52 | − }, | |
| 53 | − required: ["approve"], | |
| 54 | − additionalProperties: false, | |
| 55 | − }); | |
| 56 | − }); | |
| 57 | − | |
| 58 | − it("builds a structured paused execution instruction with full resume command", () => { | |
| 59 | − const output = buildPausedExecutionOutput({ | |
| 60 | − executionId: "exec_123", | |
| 61 | − interaction: makeInteraction(), | |
| 62 | − baseUrl: "http://127.0.0.1:8788", | |
| 63 | − shouldOpenUrls: false, | |
| 64 | − }); | |
| 65 | − | |
| 66 | − expect(output.resumeCommand).toBe( | |
| 67 | − "executor resume --execution-id exec_123 --base-url http://127.0.0.1:8788 --no-open", | |
| 68 | − ); | |
| 69 | − expect(output.interaction.requestedSchema).toEqual({ | |
| 70 | − type: "object", | |
| 71 | − properties: { | |
| 72 | − approve: { | |
| 73 | − type: "boolean", | |
| 74 | − description: "Whether to approve the tool call", | |
| 75 | − }, | |
| 76 | − }, | |
| 77 | − required: ["approve"], | |
| 78 | − additionalProperties: false, | |
| 79 | − }); | |
| 80 | − expect(output.instruction).toContain("requires approval"); | |
| 81 | − expect(output.instruction).toContain("Allow DELETE /v2/domains/{domain}/records/{recordId}?"); | |
| 82 | − expect(output.instruction).toContain(output.resumeCommand); | |
| 83 | − expect(output.instruction).toContain("interaction.requestedSchema"); | |
| 84 | − }); | |
| 85 | − | |
| 86 | − it("describes URL interactions with the next command to run", () => { | |
| 87 | − const output = buildPausedExecutionOutput({ | |
| 88 | − executionId: "exec_456", | |
| 89 | − interaction: makeInteraction({ | |
| 90 | − id: "exec_456:source_connect_oauth2:call_1" as never, | |
| 91 | − executionId: "exec_456" as never, | |
| 92 | − kind: "url", | |
| 93 | − purpose: "source_connect_oauth2", | |
| 94 | − payloadJson: JSON.stringify({ | |
| 95 | − elicitation: { | |
| 96 | − mode: "url", | |
| 97 | − message: "Finish connecting Vercel", | |
| 98 | − url: "https://vercel.com/oauth/start", | |
| 99 | − }, | |
| 100 | − }), | |
| 101 | − }), | |
| 102 | − baseUrl: "http://127.0.0.1:8788", | |
| 103 | − shouldOpenUrls: true, | |
| 104 | − }); | |
| 105 | − | |
| 106 | − expect(output.interaction.mode).toBe("url"); | |
| 107 | − expect(output.interaction.url).toBe("https://vercel.com/oauth/start"); | |
| 108 | − expect(output.instruction).toContain("https://vercel.com/oauth/start"); | |
| 109 | − expect(output.instruction).toContain( | |
| 110 | − "executor resume --execution-id exec_456 --base-url http://127.0.0.1:8788", | |
| 111 | − ); | |
| 112 | − }); | |
| 113 | −}); | |
| @@ -55,10 +55,6 @@ const describePauseReason = (interaction: ExecutionInteraction): string => { · 54 unmodified lines | ||
| 55 | 55 | switch (interaction.purpose) { |
| 56 | 56 | case "tool_execution_gate": |
| 57 | 57 | return "this tool call requires approval before executor can continue"; |
| 58 | − case "source_connect_oauth2": | |
| 59 | − return "executor needs browser authentication to finish connecting the source"; | |
| 60 | − case "source_connect_secret": | |
| 61 | − return "executor needs credentials to finish connecting the source"; | |
| 62 | 58 | default: |
| 63 | 59 | return "executor needs additional input before it can continue"; |
| 64 | 60 | } |
| @@ -9,6 +9,7 @@ · 8 unmodified lines | ||
| 9 | 9 | "start": "NODE_ENV=production bun src/server.ts" |
| 10 | 10 | }, |
| 11 | 11 | "dependencies": { |
| 12 | + "@executor/plugin-openapi-react": "workspace:*", | |
| 12 | 13 | "@executor/react": "workspace:*", |
| 13 | 14 | "@executor/server": "workspace:*", |
| 14 | 15 | "@shikijs/langs": "^4.0.1", |
| @@ -257,7 +257,11 @@ export function AppShell() { · 256 unmodified lines | ||
| 257 | 257 | </div> |
| 258 | 258 | <LoadableBlock loadable={sources} loading="Loading..."> |
| 259 | 259 | {(items) => |
| 260 | − items.length === 0 ? ( | |
| 260 | + !Array.isArray(items) ? ( | |
| 261 | + <div className="px-2.5 py-2 text-[11px] leading-relaxed text-destructive"> | |
| 262 | + Sources returned an unexpected payload. | |
| 263 | + </div> | |
| 264 | + ) : items.length === 0 ? ( | |
| 261 | 265 | <div className="px-2.5 py-2 text-[11px] leading-relaxed text-muted-foreground/40"> |
| 262 | 266 | No sources yet |
| 263 | 267 | </div> |
| @@ -12,21 +12,19 @@ import "./globals.css"; · 11 unmodified lines | ||
| 12 | 12 | |
| 13 | 13 | import { AppShell } from "./components/shell"; |
| 14 | 14 | import { HomePage } from "./views/home"; |
| 15 | −import { EditSourcePage, NewSourcePage } from "./views/source-editor"; | |
| 16 | −import { SourceDetailPage } from "./views/source-detail"; | |
| 17 | 15 | import { SecretsPage } from "./views/secrets"; |
| 18 | −import { AddSourcePage } from "./views/add-source"; | |
| 16 | +import { | |
| 17 | + SourcePluginAddPage, | |
| 18 | + SourcePluginCreatePage, | |
| 19 | + SourcePluginDetailPage, | |
| 20 | + SourcePluginEditPage, | |
| 21 | + type SourcePluginRouteSearch, | |
| 22 | +} from "./source-plugins/pages"; | |
| 19 | 23 | |
| 20 | 24 | // --------------------------------------------------------------------------- |
| 21 | 25 | // Route search schema |
| 22 | 26 | // --------------------------------------------------------------------------- |
| 23 | 27 | |
| 24 | −type SourceRouteSearch = { | |
| 25 | − tab: "model" | "discover"; | |
| 26 | − tool?: string; | |
| 27 | − query?: string; | |
| 28 | −}; | |
| 29 | − | |
| 30 | 28 | const sourceTabs = ["model", "discover"] as const; |
| 31 | 29 | |
| 32 | 30 | // --------------------------------------------------------------------------- |
| @@ -46,22 +44,22 @@ const homeRoute = createRoute({ · 13 unmodified lines | ||
| 46 | 44 | const newSourceRoute = createRoute({ |
| 47 | 45 | getParentRoute: () => rootRoute, |
| 48 | 46 | path: "/sources/new", |
| 49 | − component: NewSourcePage, | |
| 47 | + component: SourcePluginCreatePage, | |
| 50 | 48 | }); |
| 51 | 49 | |
| 52 | 50 | const addSourceRoute = createRoute({ |
| 53 | 51 | getParentRoute: () => rootRoute, |
| 54 | 52 | path: "/sources/add", |
| 55 | − component: AddSourcePage, | |
| 53 | + component: SourcePluginAddPage, | |
| 56 | 54 | }); |
| 57 | 55 | |
| 58 | 56 | const sourceRoute = createRoute({ |
| 59 | 57 | getParentRoute: () => rootRoute, |
| 60 | 58 | path: "/sources/$sourceId", |
| 61 | − validateSearch: (search: Record<string, unknown>): SourceRouteSearch => ({ | |
| 59 | + validateSearch: (search: Record<string, unknown>): SourcePluginRouteSearch => ({ | |
| 62 | 60 | tab: |
| 63 | − typeof search.tab === "string" && sourceTabs.includes(search.tab as SourceRouteSearch["tab"]) | |
| 64 | − ? (search.tab as SourceRouteSearch["tab"]) | |
| 61 | + typeof search.tab === "string" && sourceTabs.includes(search.tab as SourcePluginRouteSearch["tab"]) | |
| 62 | + ? (search.tab as SourcePluginRouteSearch["tab"]) | |
| 65 | 63 | : "model", |
| 66 | 64 | tool: typeof search.tool === "string" && search.tool.length > 0 ? search.tool : undefined, |
| 67 | 65 | query: typeof search.query === "string" ? search.query : undefined, |
| @@ -88,7 +86,7 @@ function SourceDetailPageWrapper() { · 20 unmodified lines | ||
| 88 | 86 | const navigate = useNavigate({ from: sourceRoute.fullPath }); |
| 89 | 87 | |
| 90 | 88 | return ( |
| 91 | − <SourceDetailPage | |
| 89 | + <SourcePluginDetailPage | |
| 92 | 90 | sourceId={sourceId} |
| 93 | 91 | search={search} |
| 94 | 92 | navigate={navigate as any} |
| @@ -98,7 +96,7 @@ function SourceDetailPageWrapper() { · 3 unmodified lines | ||
| 98 | 96 | |
| 99 | 97 | function EditSourcePageWrapper() { |
| 100 | 98 | const { sourceId } = editSourceRoute.useParams(); |
| 101 | − return <EditSourcePage sourceId={sourceId} />; | |
| 99 | + return <SourcePluginEditPage sourceId={sourceId} />; | |
| 102 | 100 | } |
| 103 | 101 | |
| 104 | 102 | // --------------------------------------------------------------------------- |
| @@ -0,0 +1,31 @@ | ||
| 1 | +import { | |
| 2 | + OpenApiReactPlugin, | |
| 3 | +} from "@executor/plugin-openapi-react"; | |
| 4 | +import type { | |
| 5 | + ExecutorFrontendPlugin, | |
| 6 | + FrontendSourceTypeDefinition, | |
| 7 | +} from "./types"; | |
| 8 | + | |
| 9 | +const frontendPlugins = [ | |
| 10 | + OpenApiReactPlugin, | |
| 11 | +] as const satisfies readonly ExecutorFrontendPlugin[]; | |
| 12 | + | |
| 13 | +const sourceTypeDefinitions = new Map<string, FrontendSourceTypeDefinition>(); | |
| 14 | + | |
| 15 | +for (const plugin of frontendPlugins) { | |
| 16 | + plugin.register({ | |
| 17 | + sources: { | |
| 18 | + registerType(definition) { | |
| 19 | + sourceTypeDefinitions.set(definition.kind, definition); | |
| 20 | + }, | |
| 21 | + }, | |
| 22 | + }); | |
| 23 | +} | |
| 24 | + | |
| 25 | +export const registeredSourceFrontendTypes = [...sourceTypeDefinitions.values()]; | |
| 26 | + | |
| 27 | +export const getSourceFrontendType = (kind: string) => | |
| 28 | + sourceTypeDefinitions.get(kind) ?? null; | |
| 29 | + | |
| 30 | +export const getDefaultSourceFrontendType = () => | |
| 31 | + registeredSourceFrontendTypes[0] ?? null; | |
| @@ -0,0 +1,121 @@ | ||
| 1 | +import { useSource } from "@executor/react"; | |
| 2 | +import { LoadableBlock } from "../components/loadable"; | |
| 3 | +import { SourcePluginsResetState } from "../components/source-plugins-reset-state"; | |
| 4 | +import { | |
| 5 | + getDefaultSourceFrontendType, | |
| 6 | + getSourceFrontendType, | |
| 7 | +} from "./index"; | |
| 8 | + | |
| 9 | +export type SourcePluginRouteSearch = { | |
| 10 | + tab: "model" | "discover"; | |
| 11 | + tool?: string; | |
| 12 | + query?: string; | |
| 13 | +}; | |
| 14 | + | |
| 15 | +export function SourcePluginAddPage() { | |
| 16 | + const definition = getDefaultSourceFrontendType(); | |
| 17 | + if (definition === null) { | |
| 18 | + return ( | |
| 19 | + <SourcePluginsResetState | |
| 20 | + title="Add Source is intentionally blank" | |
| 21 | + message="No source plugins are registered in this build." | |
| 22 | + /> | |
| 23 | + ); | |
| 24 | + } | |
| 25 | + | |
| 26 | + return ( | |
| 27 | + <div className="mx-auto max-w-4xl px-6 py-10 lg:px-10 lg:py-14"> | |
| 28 | + <div className="mb-8"> | |
| 29 | + <div className="inline-flex rounded-full border border-border bg-muted px-3 py-1 text-[11px] font-medium uppercase tracking-[0.2em] text-muted-foreground"> | |
| 30 | + Source Plugin | |
| 31 | + </div> | |
| 32 | + <h1 className="mt-5 font-display text-3xl tracking-tight text-foreground lg:text-4xl"> | |
| 33 | + {definition.displayName} | |
| 34 | + </h1> | |
| 35 | + </div> | |
| 36 | + {definition.renderAddPage()} | |
| 37 | + </div> | |
| 38 | + ); | |
| 39 | +} | |
| 40 | + | |
| 41 | +export function SourcePluginCreatePage() { | |
| 42 | + const definition = getDefaultSourceFrontendType(); | |
| 43 | + if (definition === null) { | |
| 44 | + return ( | |
| 45 | + <SourcePluginsResetState | |
| 46 | + title="New source creation is disabled" | |
| 47 | + message="No source plugins are registered in this build." | |
| 48 | + /> | |
| 49 | + ); | |
| 50 | + } | |
| 51 | + | |
| 52 | + return ( | |
| 53 | + <div className="mx-auto max-w-4xl px-6 py-10 lg:px-10 lg:py-14"> | |
| 54 | + {definition.renderAddPage()} | |
| 55 | + </div> | |
| 56 | + ); | |
| 57 | +} | |
| 58 | + | |
| 59 | +export function SourcePluginEditPage(input: { | |
| 60 | + sourceId: string; | |
| 61 | +}) { | |
| 62 | + const source = useSource(input.sourceId); | |
| 63 | + | |
| 64 | + return ( | |
| 65 | + <LoadableBlock loadable={source} loading="Loading source..."> | |
| 66 | + {(loadedSource) => { | |
| 67 | + const definition = getSourceFrontendType(loadedSource.kind); | |
| 68 | + if (definition?.renderEditPage === undefined) { | |
| 69 | + return ( | |
| 70 | + <SourcePluginsResetState | |
| 71 | + title="Source editing is disabled" | |
| 72 | + message={`No frontend source plugin is registered for kind "${loadedSource.kind}".`} | |
| 73 | + /> | |
| 74 | + ); | |
| 75 | + } | |
| 76 | + | |
| 77 | + return ( | |
| 78 | + <div className="mx-auto max-w-4xl px-6 py-10 lg:px-10 lg:py-14"> | |
| 79 | + {definition.renderEditPage({ source: loadedSource })} | |
| 80 | + </div> | |
| 81 | + ); | |
| 82 | + }} | |
| 83 | + </LoadableBlock> | |
| 84 | + ); | |
| 85 | +} | |
| 86 | + | |
| 87 | +export function SourcePluginDetailPage(input: { | |
| 88 | + sourceId: string; | |
| 89 | + search: SourcePluginRouteSearch; | |
| 90 | + navigate: unknown; | |
| 91 | +}) { | |
| 92 | + const source = useSource(input.sourceId); | |
| 93 | + | |
| 94 | + return ( | |
| 95 | + <LoadableBlock loadable={source} loading="Loading source..."> | |
| 96 | + {(loadedSource) => { | |
| 97 | + const definition = getSourceFrontendType(loadedSource.kind); | |
| 98 | + if (definition?.renderDetailPage === undefined) { | |
| 99 | + return ( | |
| 100 | + <SourcePluginsResetState | |
| 101 | + title="Source detail is disabled" | |
| 102 | + message={`No frontend source plugin is registered for kind "${loadedSource.kind}".`} | |
| 103 | + /> | |
| 104 | + ); | |
| 105 | + } | |
| 106 | + | |
| 107 | + return ( | |
| 108 | + <div className="mx-auto max-w-4xl px-6 py-10 lg:px-10 lg:py-14"> | |
| 109 | + {definition.renderDetailPage({ | |
| 110 | + source: loadedSource, | |
| 111 | + route: { | |
| 112 | + search: input.search, | |
| 113 | + navigate: input.navigate, | |
| 114 | + }, | |
| 115 | + })} | |
| 116 | + </div> | |
| 117 | + ); | |
| 118 | + }} | |
| 119 | + </LoadableBlock> | |
| 120 | + ); | |
| 121 | +} | |
| @@ -0,0 +1,109 @@ | ||
| 1 | +import type { Source } from "@executor/react"; | |
| 2 | +import type { ComponentType, ReactNode } from "react"; | |
| 3 | + | |
| 4 | +export type ExecutorFrontendPlugin = { | |
| 5 | + key: string; | |
| 6 | + register: (api: ExecutorFrontendPluginApi) => void; | |
| 7 | +}; | |
| 8 | + | |
| 9 | +export type ExecutorFrontendPluginApi = { | |
| 10 | + sources: { | |
| 11 | + registerType: ( | |
| 12 | + definition: FrontendSourceTypeDefinition, | |
| 13 | + ) => void; | |
| 14 | + }; | |
| 15 | +}; | |
| 16 | + | |
| 17 | +export type SourcePluginDetailRouteContext = { | |
| 18 | + search?: unknown; | |
| 19 | + navigate?: unknown; | |
| 20 | +}; | |
| 21 | + | |
| 22 | +export type SourcePluginAddScreenProps<Input, Client = unknown> = { | |
| 23 | + initialValue: Input; | |
| 24 | + client: Client; | |
| 25 | + onSubmit: (input: Input) => Promise<void>; | |
| 26 | +}; | |
| 27 | + | |
| 28 | +export type SourcePluginEditScreenProps<Config, Client = unknown> = { | |
| 29 | + sourceId: string; | |
| 30 | + config: Config; | |
| 31 | + client: Client; | |
| 32 | + onSubmit: (config: Config) => Promise<void>; | |
| 33 | +}; | |
| 34 | + | |
| 35 | +export type SourcePluginDetailScreenProps<Config, Client = unknown> = { | |
| 36 | + sourceId: string; | |
| 37 | + config: Config; | |
| 38 | + client: Client; | |
| 39 | +}; | |
| 40 | + | |
| 41 | +export type FrontendSourceTypeDefinition = { | |
| 42 | + kind: string; | |
| 43 | + displayName: string; | |
| 44 | + renderAddPage: () => ReactNode; | |
| 45 | + renderEditPage?: (input: { source: Source }) => ReactNode; | |
| 46 | + renderDetailPage?: (input: { | |
| 47 | + source: Source; | |
| 48 | + route: SourcePluginDetailRouteContext; | |
| 49 | + }) => ReactNode; | |
| 50 | +}; | |
| 51 | + | |
| 52 | +export const defineFrontendSourceType = <Input, Config, Client>(input: { | |
| 53 | + kind: string; | |
| 54 | + displayName: string; | |
| 55 | + createInitialInput: () => Input; | |
| 56 | + client: Client; | |
| 57 | + addScreen: ComponentType<SourcePluginAddScreenProps<Input, Client>>; | |
| 58 | + editScreen?: ComponentType<SourcePluginEditScreenProps<Config, Client>>; | |
| 59 | + detailScreen?: ComponentType<SourcePluginDetailScreenProps<Config, Client>>; | |
| 60 | + configFromSource?: (source: Source) => Config; | |
| 61 | +}): FrontendSourceTypeDefinition => { | |
| 62 | + const renderEditPage = (() => { | |
| 63 | + if (input.editScreen === undefined || input.configFromSource === undefined) { | |
| 64 | + return undefined; | |
| 65 | + } | |
| 66 | + | |
| 67 | + const EditScreen = input.editScreen; | |
| 68 | + const configFromSource = input.configFromSource; | |
| 69 | + return ({ source }: { source: Source }) => ( | |
| 70 | + <EditScreen | |
| 71 | + sourceId={source.id} | |
| 72 | + config={configFromSource(source)} | |
| 73 | + client={input.client} | |
| 74 | + onSubmit={async () => {}} | |
| 75 | + /> | |
| 76 | + ); | |
| 77 | + })(); | |
| 78 | + | |
| 79 | + const renderDetailPage = (() => { | |
| 80 | + if (input.detailScreen === undefined || input.configFromSource === undefined) { | |
| 81 | + return undefined; | |
| 82 | + } | |
| 83 | + | |
| 84 | + const DetailScreen = input.detailScreen; | |
| 85 | + const configFromSource = input.configFromSource; | |
| 86 | + return ({ source }: { source: Source }) => ( | |
| 87 | + <DetailScreen | |
| 88 | + sourceId={source.id} | |
| 89 | + config={configFromSource(source)} | |
| 90 | + client={input.client} | |
| 91 | + /> | |
| 92 | + ); | |
| 93 | + })(); | |
| 94 | + | |
| 95 | + return { | |
| 96 | + kind: input.kind, | |
| 97 | + displayName: input.displayName, | |
| 98 | + renderAddPage: () => | |
| 99 | + <input.addScreen | |
| 100 | + initialValue={input.createInitialInput()} | |
| 101 | + client={input.client} | |
| 102 | + onSubmit={async () => {}} | |
| 103 | + />, | |
| 104 | + renderEditPage, | |
| 105 | + renderDetailPage: renderDetailPage | |
| 106 | + ? ({ source }) => renderDetailPage({ source }) | |
| 107 | + : undefined, | |
| 108 | + }; | |
| 109 | +}; | |
| @@ -1,19 +0,0 @@ | ||
| 1 | −import { Link } from "@tanstack/react-router"; | |
| 2 | −import { SourcePluginsResetState } from "../components/source-plugins-reset-state"; | |
| 3 | −import { Button } from "../components/ui/button"; | |
| 4 | − | |
| 5 | −export function AddSourcePage() { | |
| 6 | − return ( | |
| 7 | − <SourcePluginsResetState | |
| 8 | − title="Add Source is intentionally blank" | |
| 9 | − message="The previous OpenAPI, GraphQL, MCP, and Google Discovery source onboarding flows were removed so the product can be rebuilt around explicit source plugins." | |
| 10 | − action={( | |
| 11 | − <Link to="/"> | |
| 12 | − <Button size="sm" variant="outline"> | |
| 13 | − Back to sources | |
| 14 | − </Button> | |
| 15 | − </Link> | |
| 16 | − )} | |
| 17 | − /> | |
| 18 | − ); | |
| 19 | −} | |
| @@ -1,6 +1,8 @@ | ||
| 1 | +import { Link } from "@tanstack/react-router"; | |
| 1 | 2 | import { useSources } from "@executor/react"; |
| 2 | 3 | import { LoadableBlock } from "../components/loadable"; |
| 3 | 4 | import { Badge } from "../components/ui/badge"; |
| 5 | +import { Button } from "../components/ui/button"; | |
| 4 | 6 | import { SourcePluginsResetState } from "../components/source-plugins-reset-state"; |
| 5 | 7 | |
| 6 | 8 | export function HomePage() { |
| @@ -14,22 +16,34 @@ export function HomePage() { · 7 unmodified lines | ||
| 14 | 16 | Sources |
| 15 | 17 | </div> |
| 16 | 18 | <h1 className="mt-5 font-display text-3xl tracking-tight text-foreground lg:text-4xl"> |
| 17 | − Source plugins have been removed from the product shell | |
| 19 | + OpenAPI is now mounted as a source plugin | |
| 18 | 20 | </h1> |
| 19 | 21 | <p className="mt-3 max-w-3xl text-sm leading-6 text-muted-foreground"> |
| 20 | − The built-in OpenAPI, GraphQL, MCP, and Google Discovery flows are | |
| 21 | − intentionally stripped out. This leaves the workspace UI in a clean | |
| 22 | − slate state while the plugin registration model is rebuilt. | |
| 22 | + The product shell is still in transition, but the first plugin-backed | |
| 23 | + surface is wired in for OpenAPI so the frontend and backend boundaries | |
| 24 | + are visible in the app again. | |
| 23 | 25 | </p> |
| 24 | 26 | </div> |
| 25 | 27 | |
| 26 | 28 | <div className="mt-8"> |
| 27 | 29 | <LoadableBlock loadable={sources} loading="Loading sources..."> |
| 28 | 30 | {(items) => |
| 29 | − items.length === 0 ? ( | |
| 31 | + !Array.isArray(items) ? ( | |
| 30 | 32 | <SourcePluginsResetState |
| 31 | − title="No registered source plugins" | |
| 32 | − message="No source plugins are registered in this build, so new sources cannot be added from the UI yet." | |
| 33 | + title="Unexpected sources payload" | |
| 34 | + message="The sources list returned data in an unexpected shape." | |
| 35 | + /> | |
| 36 | + ) : items.length === 0 ? ( | |
| 37 | + <SourcePluginsResetState | |
| 38 | + title="No sources connected yet" | |
| 39 | + message="The OpenAPI source plugin is registered. Use the add flow to inspect the plugin-owned UI surface." | |
| 40 | + action={( | |
| 41 | + <Link to="/sources/add"> | |
| 42 | + <Button size="sm" variant="outline"> | |
| 43 | + Open OpenAPI Plugin | |
| 44 | + </Button> | |
| 45 | + </Link> | |
| 46 | + )} | |
| 33 | 47 | /> |
| 34 | 48 | ) : ( |
| 35 | 49 | <div className="grid gap-3"> |
| @@ -1,29 +0,0 @@ | ||
| 1 | −import { Link } from "@tanstack/react-router"; | |
| 2 | −import { SourcePluginsResetState } from "../components/source-plugins-reset-state"; | |
| 3 | −import { Button } from "../components/ui/button"; | |
| 4 | − | |
| 5 | −type SourceRouteSearch = { | |
| 6 | − tab: "model" | "discover"; | |
| 7 | − tool?: string; | |
| 8 | − query?: string; | |
| 9 | −}; | |
| 10 | − | |
| 11 | −export function SourceDetailPage(_input: { | |
| 12 | − sourceId: string; | |
| 13 | − search: SourceRouteSearch; | |
| 14 | − navigate: unknown; | |
| 15 | −}) { | |
| 16 | − return ( | |
| 17 | − <SourcePluginsResetState | |
| 18 | − title="Source detail is disabled" | |
| 19 | − message="The source-specific detail experience was removed with the old built-in OpenAPI, GraphQL, MCP, and Google Discovery product wiring. This route remains only as a placeholder while plugin-backed detail modules are designed." | |
| 20 | − action={( | |
| 21 | − <Link to="/"> | |
| 22 | − <Button size="sm" variant="outline"> | |
| 23 | − Back to sources | |
| 24 | − </Button> | |
| 25 | − </Link> | |
| 26 | − )} | |
| 27 | − /> | |
| 28 | − ); | |
| 29 | −} | |
| @@ -1,37 +0,0 @@ | ||
| 1 | −import { Link } from "@tanstack/react-router"; | |
| 2 | −import { SourcePluginsResetState } from "../components/source-plugins-reset-state"; | |
| 3 | −import { Button } from "../components/ui/button"; | |
| 4 | − | |
| 5 | −export function NewSourcePage() { | |
| 6 | − return ( | |
| 7 | − <SourcePluginsResetState | |
| 8 | − title="New source creation is disabled" | |
| 9 | − message="The old source creation form was removed as part of the clean-slate plugin reset. New source creation will come back through registered plugin modules instead of hard-coded source kinds." | |
| 10 | − action={( | |
| 11 | − <Link to="/"> | |
| 12 | − <Button size="sm" variant="outline"> | |
| 13 | − Back to sources | |
| 14 | − </Button> | |
| 15 | − </Link> | |
| 16 | − )} | |
| 17 | − /> | |
| 18 | − ); | |
| 19 | −} | |
| 20 | − | |
| 21 | −export function EditSourcePage(_input: { | |
| 22 | − sourceId: string; | |
| 23 | −}) { | |
| 24 | − return ( | |
| 25 | − <SourcePluginsResetState | |
| 26 | − title="Source editing is disabled" | |
| 27 | − message="The previous source editor contained hard-coded OpenAPI, GraphQL, MCP, and Google Discovery behavior. That editor has been removed so a plugin-defined editor surface can replace it." | |
| 28 | − action={( | |
| 29 | − <Link to="/"> | |
| 30 | − <Button size="sm" variant="outline"> | |
| 31 | − Back to sources | |
| 32 | − </Button> | |
| 33 | − </Link> | |
| 34 | − )} | |
| 35 | − /> | |
| 36 | − ); | |
| 37 | −} | |
| @@ -32,6 +32,7 @@ · 31 unmodified lines | ||
| 32 | 32 | "@executor/platform-internal": "workspace:*", |
| 33 | 33 | "@executor/platform-sdk": "workspace:*", |
| 34 | 34 | "@executor/platform-sdk-file": "workspace:*", |
| 35 | + "@executor/plugin-openapi-sdk": "workspace:*", | |
| 35 | 36 | "@executor/server": "workspace:*", |
| 36 | 37 | "effect": "catalog:", |
| 37 | 38 | }, |
| @@ -51,6 +52,7 @@ · 13 unmodified lines | ||
| 51 | 52 | "name": "@executor/web", |
| 52 | 53 | "version": "0.0.0", |
| 53 | 54 | "dependencies": { |
| 55 | + "@executor/plugin-openapi-react": "workspace:*", | |
| 54 | 56 | "@executor/react": "workspace:*", |
| 55 | 57 | "@executor/server": "workspace:*", |
| 56 | 58 | "@shikijs/langs": "^4.0.1", |
| @@ -343,7 +345,6 @@ · 286 unmodified lines | ||
| 343 | 345 | "@executor/runtime-deno-subprocess": "workspace:*", |
| 344 | 346 | "@executor/runtime-quickjs": "workspace:*", |
| 345 | 347 | "@executor/runtime-ses": "workspace:*", |
| 346 | − "@executor/source-builtins": "workspace:*", | |
| 347 | 348 | "@executor/source-core": "workspace:*", |
| 348 | 349 | "effect": "catalog:", |
| 349 | 350 | }, |
| @@ -393,6 +394,9 @@ · 43 unmodified lines | ||
| 393 | 394 | "@executor/platform-internal": "workspace:*", |
| 394 | 395 | "@executor/platform-sdk": "workspace:*", |
| 395 | 396 | "@executor/platform-sdk-file": "workspace:*", |
| 397 | + "@executor/plugin-openapi-http": "workspace:*", | |
| 398 | + "@executor/plugin-openapi-sdk": "workspace:*", | |
| 399 | + "@executor/plugin-openapi-shared": "workspace:*", | |
| 396 | 400 | "@opentelemetry/api": "^1.9.0", |
| 397 | 401 | "@opentelemetry/exporter-trace-otlp-grpc": "^0.213.0", |
| 398 | 402 | "@opentelemetry/resources": "^2.6.0", |
| @@ -406,26 +410,73 @@ · 7 unmodified lines | ||
| 406 | 410 | "bun-types": "catalog:", |
| 407 | 411 | }, |
| 408 | 412 | }, |
| 409 | − "packages/sources/builtins": { | |
| 410 | − "name": "@executor/source-builtins", | |
| 413 | + "packages/sources/core": { | |
| 414 | + "name": "@executor/source-core", | |
| 415 | + "version": "0.0.0", | |
| 416 | + "dependencies": { | |
| 417 | + "@executor/auth-oauth2": "workspace:*", | |
| 418 | + "@executor/codemode-core": "workspace:*", | |
| 419 | + "@executor/ir": "workspace:*", | |
| 420 | + "@modelcontextprotocol/sdk": "^1.26.0", | |
| 421 | + "effect": "catalog:", | |
| 422 | + }, | |
| 423 | + "devDependencies": { | |
| 424 | + "@types/node": "catalog:", | |
| 425 | + "bun-types": "catalog:", | |
| 426 | + }, | |
| 427 | + }, | |
| 428 | + "plugins/openapi/http": { | |
| 429 | + "name": "@executor/plugin-openapi-http", | |
| 430 | + "version": "0.0.0", | |
| 431 | + "dependencies": { | |
| 432 | + "@effect/platform": "catalog:", | |
| 433 | + "@executor/platform-api": "workspace:*", | |
| 434 | + "@executor/platform-sdk": "workspace:*", | |
| 435 | + "@executor/plugin-openapi-shared": "workspace:*", | |
| 436 | + "effect": "catalog:", | |
| 437 | + }, | |
| 438 | + "devDependencies": { | |
| 439 | + "@types/node": "catalog:", | |
| 440 | + "bun-types": "catalog:", | |
| 441 | + }, | |
| 442 | + }, | |
| 443 | + "plugins/openapi/react": { | |
| 444 | + "name": "@executor/plugin-openapi-react", | |
| 411 | 445 | "version": "0.0.0", |
| 412 | 446 | "dependencies": { |
| 447 | + "@executor/plugin-openapi-http": "workspace:*", | |
| 448 | + "@executor/plugin-openapi-shared": "workspace:*", | |
| 449 | + "@executor/react": "workspace:*", | |
| 450 | + "@tanstack/react-router": "^1.132.7", | |
| 451 | + "react": "^19.2.0", | |
| 452 | + }, | |
| 453 | + "devDependencies": { | |
| 454 | + "@types/node": "catalog:", | |
| 455 | + "@types/react": "^19.2.10", | |
| 456 | + "bun-types": "catalog:", | |
| 457 | + }, | |
| 458 | + }, | |
| 459 | + "plugins/openapi/sdk": { | |
| 460 | + "name": "@executor/plugin-openapi-sdk", | |
| 461 | + "version": "0.0.0", | |
| 462 | + "dependencies": { | |
| 463 | + "@executor/platform-sdk": "workspace:*", | |
| 464 | + "@executor/plugin-openapi-shared": "workspace:*", | |
| 413 | 465 | "@executor/source-core": "workspace:*", |
| 466 | + "effect": "catalog:", | |
| 414 | 467 | }, |
| 415 | 468 | "devDependencies": { |
| 416 | 469 | "@types/node": "catalog:", |
| 417 | 470 | "bun-types": "catalog:", |
| 418 | 471 | }, |
| 419 | 472 | }, |
| 420 | − "packages/sources/core": { | |
| 421 | − "name": "@executor/source-core", | |
| 473 | + "plugins/openapi/shared": { | |
| 474 | + "name": "@executor/plugin-openapi-shared", | |
| 422 | 475 | "version": "0.0.0", |
| 423 | 476 | "dependencies": { |
| 424 | − "@executor/auth-oauth2": "workspace:*", | |
| 425 | − "@executor/codemode-core": "workspace:*", | |
| 426 | − "@executor/ir": "workspace:*", | |
| 427 | − "@modelcontextprotocol/sdk": "^1.26.0", | |
| 477 | + "@executor/source-core": "workspace:*", | |
| 428 | 478 | "effect": "catalog:", |
| 479 | + "yaml": "^2.8.1", | |
| 429 | 480 | }, |
| 430 | 481 | "devDependencies": { |
| 431 | 482 | "@types/node": "catalog:", |
| @@ -663,6 +714,14 @@ · 231 unmodified lines | ||
| 663 | 714 | |
| 664 | 715 | "@executor/platform-sdk-file": ["@executor/platform-sdk-file@workspace:packages/platform/sdk-file"], |
| 665 | 716 | |
| 717 | + "@executor/plugin-openapi-http": ["@executor/plugin-openapi-http@workspace:plugins/openapi/http"], | |
| 718 | + | |
| 719 | + "@executor/plugin-openapi-react": ["@executor/plugin-openapi-react@workspace:plugins/openapi/react"], | |
| 720 | + | |
| 721 | + "@executor/plugin-openapi-sdk": ["@executor/plugin-openapi-sdk@workspace:plugins/openapi/sdk"], | |
| 722 | + | |
| 723 | + "@executor/plugin-openapi-shared": ["@executor/plugin-openapi-shared@workspace:plugins/openapi/shared"], | |
| 724 | + | |
| 666 | 725 | "@executor/react": ["@executor/react@workspace:packages/clients/react"], |
| 667 | 726 | |
| 668 | 727 | "@executor/runtime-deno-subprocess": ["@executor/runtime-deno-subprocess@workspace:packages/kernel/runtime-deno-subprocess"], |
| @@ -675,8 +734,6 @@ · 6 unmodified lines | ||
| 675 | 734 | |
| 676 | 735 | "@executor/server": ["@executor/server@workspace:packages/platform/server"], |
| 677 | 736 | |
| 678 | − "@executor/source-builtins": ["@executor/source-builtins@workspace:packages/sources/builtins"], | |
| 679 | − | |
| 680 | 737 | "@executor/source-core": ["@executor/source-core@workspace:packages/sources/core"], |
| 681 | 738 | |
| 682 | 739 | "@executor/sqlite-sdk-consumer-example": ["@executor/sqlite-sdk-consumer-example@workspace:examples/sqlite-sdk-consumer"], |
| @@ -20,19 +20,13 @@ import { · 19 unmodified lines | ||
| 20 | 20 | type ExecutorWorkspaceSourceArtifactRepository, |
| 21 | 21 | } from "@executor/platform-sdk"; |
| 22 | 22 | import type { |
| 23 | − AuthArtifact, | |
| 24 | − AuthLease, | |
| 25 | 23 | Execution, |
| 26 | 24 | ExecutionInteraction, |
| 27 | 25 | ExecutionStep, |
| 28 | 26 | LocalExecutorConfig, |
| 29 | 27 | LocalInstallation, |
| 30 | − ProviderAuthGrant, | |
| 31 | − ScopeOauthClient, | |
| 32 | − ScopedSourceOauthClient, | |
| 33 | 28 | SecretMaterial, |
| 34 | 29 | SecretRef, |
| 35 | − SourceAuthSession, | |
| 36 | 30 | } from "@executor/platform-sdk/schema"; |
| 37 | 31 | import { |
| 38 | 32 | ScopeIdSchema, |
| @@ -94,54 +88,6 @@ const sourceArtifacts = sqliteTable("source_artifacts", { · 55 unmodified lines | ||
| 94 | 88 | artifactJson: text("artifact_json").notNull(), |
| 95 | 89 | }); |
| 96 | 90 | |
| 97 | −const authArtifacts = sqliteTable("auth_artifacts", { | |
| 98 | − id: text("id").primaryKey(), | |
| 99 | − scopeId: text("scope_id").notNull(), | |
| 100 | − sourceId: text("source_id").notNull(), | |
| 101 | − actorScopeId: text("actor_scope_id"), | |
| 102 | − slot: text("slot").notNull(), | |
| 103 | − json: text("json").notNull(), | |
| 104 | −}); | |
| 105 | − | |
| 106 | −const authLeases = sqliteTable("auth_leases", { | |
| 107 | − authArtifactId: text("auth_artifact_id").primaryKey(), | |
| 108 | − json: text("json").notNull(), | |
| 109 | −}); | |
| 110 | − | |
| 111 | −const sourceOauthClients = sqliteTable("source_oauth_clients", { | |
| 112 | − id: text("id").primaryKey(), | |
| 113 | − scopeId: text("scope_id").notNull(), | |
| 114 | − sourceId: text("source_id").notNull(), | |
| 115 | − providerKey: text("provider_key").notNull(), | |
| 116 | − json: text("json").notNull(), | |
| 117 | −}); | |
| 118 | − | |
| 119 | −const scopeOauthClients = sqliteTable("scope_oauth_clients", { | |
| 120 | − id: text("id").primaryKey(), | |
| 121 | − scopeId: text("scope_id").notNull(), | |
| 122 | − providerKey: text("provider_key").notNull(), | |
| 123 | − json: text("json").notNull(), | |
| 124 | −}); | |
| 125 | − | |
| 126 | −const providerAuthGrants = sqliteTable("provider_auth_grants", { | |
| 127 | − id: text("id").primaryKey(), | |
| 128 | − scopeId: text("scope_id").notNull(), | |
| 129 | − actorScopeId: text("actor_scope_id"), | |
| 130 | − providerKey: text("provider_key").notNull(), | |
| 131 | − json: text("json").notNull(), | |
| 132 | −}); | |
| 133 | − | |
| 134 | −const sourceAuthSessions = sqliteTable("source_auth_sessions", { | |
| 135 | − id: text("id").primaryKey(), | |
| 136 | − scopeId: text("scope_id").notNull(), | |
| 137 | − sourceId: text("source_id").notNull(), | |
| 138 | − actorScopeId: text("actor_scope_id"), | |
| 139 | − state: text("state").notNull(), | |
| 140 | − status: text("status").notNull(), | |
| 141 | − credentialSlot: text("credential_slot"), | |
| 142 | − json: text("json").notNull(), | |
| 143 | −}); | |
| 144 | − | |
| 145 | 91 | const secretMaterials = sqliteTable("secret_materials", { |
| 146 | 92 | id: text("id").primaryKey(), |
| 147 | 93 | providerId: text("provider_id").notNull(), |
| @@ -175,11 +121,6 @@ const executionSteps = sqliteTable("execution_steps", { · 27 unmodified lines | ||
| 175 | 121 | const makeHash = (value: string): string => |
| 176 | 122 | createHash("sha256").update(value).digest("hex").slice(0, 24); |
| 177 | 123 | |
| 178 | −const sameActor = ( | |
| 179 | − left: string | null | undefined, | |
| 180 | − right: string | null | undefined, | |
| 181 | −): boolean => (left ?? null) === (right ?? null); | |
| 182 | − | |
| 183 | 124 | const parseJson = <T>(value: string): T => JSON.parse(value) as T; |
| 184 | 125 | |
| 185 | 126 | const createSourceArtifact = (input: SourceArtifactBuildInput): SourceArtifact => { |
| @@ -190,10 +131,7 @@ const createSourceArtifact = (input: SourceArtifactBuildInput): SourceArtifact = · 4 unmodified lines | ||
| 190 | 131 | namespace: input.source.namespace, |
| 191 | 132 | name: input.source.name, |
| 192 | 133 | enabled: input.source.enabled, |
| 193 | − binding: input.source.binding, | |
| 194 | − auth: input.source.auth, | |
| 195 | − importAuth: input.source.importAuth, | |
| 196 | − importAuthPolicy: input.source.importAuthPolicy, | |
| 134 | + sourceHash: input.source.sourceHash, | |
| 197 | 135 | }); |
| 198 | 136 | const importMetadataJson = JSON.stringify(snapshot.import); |
| 199 | 137 | const catalogId = SourceCatalogIdSchema.make(`src_catalog_${makeHash(sourceConfigJson)}`); |
| @@ -273,54 +211,6 @@ const openSqliteStore = (databasePath: string) => { · 73 unmodified lines | ||
| 273 | 211 | artifact_json TEXT NOT NULL |
| 274 | 212 | ); |
| 275 | 213 | |
| 276 | − CREATE TABLE IF NOT EXISTS auth_artifacts ( | |
| 277 | − id TEXT PRIMARY KEY NOT NULL, | |
| 278 | − scope_id TEXT NOT NULL, | |
| 279 | − source_id TEXT NOT NULL, | |
| 280 | − actor_scope_id TEXT, | |
| 281 | − slot TEXT NOT NULL, | |
| 282 | − json TEXT NOT NULL | |
| 283 | − ); | |
| 284 | − | |
| 285 | − CREATE TABLE IF NOT EXISTS auth_leases ( | |
| 286 | − auth_artifact_id TEXT PRIMARY KEY NOT NULL, | |
| 287 | − json TEXT NOT NULL | |
| 288 | − ); | |
| 289 | − | |
| 290 | − CREATE TABLE IF NOT EXISTS source_oauth_clients ( | |
| 291 | − id TEXT PRIMARY KEY NOT NULL, | |
| 292 | − scope_id TEXT NOT NULL, | |
| 293 | − source_id TEXT NOT NULL, | |
| 294 | − provider_key TEXT NOT NULL, | |
| 295 | − json TEXT NOT NULL | |
| 296 | − ); | |
| 297 | − | |
| 298 | − CREATE TABLE IF NOT EXISTS scope_oauth_clients ( | |
| 299 | − id TEXT PRIMARY KEY NOT NULL, | |
| 300 | − scope_id TEXT NOT NULL, | |
| 301 | − provider_key TEXT NOT NULL, | |
| 302 | − json TEXT NOT NULL | |
| 303 | − ); | |
| 304 | − | |
| 305 | − CREATE TABLE IF NOT EXISTS provider_auth_grants ( | |
| 306 | − id TEXT PRIMARY KEY NOT NULL, | |
| 307 | − scope_id TEXT NOT NULL, | |
| 308 | − actor_scope_id TEXT, | |
| 309 | − provider_key TEXT NOT NULL, | |
| 310 | − json TEXT NOT NULL | |
| 311 | − ); | |
| 312 | − | |
| 313 | − CREATE TABLE IF NOT EXISTS source_auth_sessions ( | |
| 314 | − id TEXT PRIMARY KEY NOT NULL, | |
| 315 | − scope_id TEXT NOT NULL, | |
| 316 | − source_id TEXT NOT NULL, | |
| 317 | − actor_scope_id TEXT, | |
| 318 | − state TEXT NOT NULL, | |
| 319 | − status TEXT NOT NULL, | |
| 320 | − credential_slot TEXT, | |
| 321 | − json TEXT NOT NULL | |
| 322 | − ); | |
| 323 | − | |
| 324 | 214 | CREATE TABLE IF NOT EXISTS secret_materials ( |
| 325 | 215 | id TEXT PRIMARY KEY NOT NULL, |
| 326 | 216 | provider_id TEXT NOT NULL, |
| @@ -363,358 +253,6 @@ const openSqliteStore = (databasePath: string) => { · 36 unmodified lines | ||
| 363 | 253 | type SqliteStore = ReturnType<typeof openSqliteStore>; |
| 364 | 254 | |
| 365 | 255 | const createStorageDomains = (store: SqliteStore) => ({ |
| 366 | − auth: { | |
| 367 | − artifacts: { | |
| 368 | − listByScopeId: (scopeId: AuthArtifact["scopeId"]) => | |
| 369 | − store.db.select().from(authArtifacts).where(eq(authArtifacts.scopeId, scopeId)).all() | |
| 370 | − .map((row) => parseJson<AuthArtifact>(row.json)), | |
| 371 | − listByScopeAndSourceId: (input: { | |
| 372 | − scopeId: AuthArtifact["scopeId"]; | |
| 373 | − sourceId: AuthArtifact["sourceId"]; | |
| 374 | − }) => | |
| 375 | − store.db.select().from(authArtifacts).where( | |
| 376 | − and( | |
| 377 | − eq(authArtifacts.scopeId, input.scopeId), | |
| 378 | − eq(authArtifacts.sourceId, input.sourceId), | |
| 379 | − ), | |
| 380 | − ).all().map((row) => parseJson<AuthArtifact>(row.json)), | |
| 381 | − getByScopeSourceAndActor: (input: { | |
| 382 | − scopeId: AuthArtifact["scopeId"]; | |
| 383 | − sourceId: AuthArtifact["sourceId"]; | |
| 384 | − actorScopeId: AuthArtifact["actorScopeId"]; | |
| 385 | − slot: AuthArtifact["slot"]; | |
| 386 | − }) => | |
| 387 | − store.db.select().from(authArtifacts).where( | |
| 388 | − and( | |
| 389 | − eq(authArtifacts.scopeId, input.scopeId), | |
| 390 | − eq(authArtifacts.sourceId, input.sourceId), | |
| 391 | − eq(authArtifacts.slot, input.slot), | |
| 392 | − ), | |
| 393 | − ).all().map((row) => parseJson<AuthArtifact>(row.json)) | |
| 394 | − .find((item) => sameActor(item.actorScopeId, input.actorScopeId)) ?? null, | |
| 395 | − upsert: (artifact: AuthArtifact) => | |
| 396 | − store.db.insert(authArtifacts).values({ | |
| 397 | − id: artifact.id, | |
| 398 | − scopeId: artifact.scopeId, | |
| 399 | − sourceId: artifact.sourceId, | |
| 400 | − actorScopeId: artifact.actorScopeId, | |
| 401 | − slot: artifact.slot, | |
| 402 | − json: JSON.stringify(artifact), | |
| 403 | − }).onConflictDoUpdate({ | |
| 404 | − target: authArtifacts.id, | |
| 405 | − set: { | |
| 406 | − scopeId: artifact.scopeId, | |
| 407 | − sourceId: artifact.sourceId, | |
| 408 | − actorScopeId: artifact.actorScopeId, | |
| 409 | − slot: artifact.slot, | |
| 410 | − json: JSON.stringify(artifact), | |
| 411 | − }, | |
| 412 | − }).run(), | |
| 413 | − removeByScopeSourceAndActor: (input: { | |
| 414 | − scopeId: AuthArtifact["scopeId"]; | |
| 415 | − sourceId: AuthArtifact["sourceId"]; | |
| 416 | − actorScopeId: AuthArtifact["actorScopeId"]; | |
| 417 | − slot?: AuthArtifact["slot"]; | |
| 418 | − }) => { | |
| 419 | − const rows = store.db.select().from(authArtifacts).where( | |
| 420 | − and( | |
| 421 | − eq(authArtifacts.scopeId, input.scopeId), | |
| 422 | − eq(authArtifacts.sourceId, input.sourceId), | |
| 423 | − ), | |
| 424 | − ).all(); | |
| 425 | − const match = rows.find((row) => { | |
| 426 | − const item = parseJson<AuthArtifact>(row.json); | |
| 427 | − return sameActor(item.actorScopeId, input.actorScopeId) | |
| 428 | − && (input.slot === undefined || item.slot === input.slot); | |
| 429 | − }); | |
| 430 | − if (!match) return false; | |
| 431 | − store.db.delete(authArtifacts).where(eq(authArtifacts.id, match.id)).run(); | |
| 432 | − return true; | |
| 433 | − }, | |
| 434 | − removeByScopeAndSourceId: (input: { | |
| 435 | − scopeId: AuthArtifact["scopeId"]; | |
| 436 | − sourceId: AuthArtifact["sourceId"]; | |
| 437 | − }) => { | |
| 438 | − const rows = store.db.select({ id: authArtifacts.id }).from(authArtifacts).where( | |
| 439 | − and( | |
| 440 | − eq(authArtifacts.scopeId, input.scopeId), | |
| 441 | − eq(authArtifacts.sourceId, input.sourceId), | |
| 442 | − ), | |
| 443 | − ).all(); | |
| 444 | − store.db.delete(authArtifacts).where( | |
| 445 | − and( | |
| 446 | − eq(authArtifacts.scopeId, input.scopeId), | |
| 447 | − eq(authArtifacts.sourceId, input.sourceId), | |
| 448 | − ), | |
| 449 | − ).run(); | |
| 450 | − return rows.length; | |
| 451 | − }, | |
| 452 | − }, | |
| 453 | − leases: { | |
| 454 | − listAll: () => | |
| 455 | − store.db.select().from(authLeases).all().map((row) => parseJson<AuthLease>(row.json)), | |
| 456 | − getByAuthArtifactId: (authArtifactId: AuthLease["authArtifactId"]) => { | |
| 457 | − const row = store.db.select().from(authLeases).where( | |
| 458 | − eq(authLeases.authArtifactId, authArtifactId), | |
| 459 | − ).get(); | |
| 460 | − return row ? parseJson<AuthLease>(row.json) : null; | |
| 461 | − }, | |
| 462 | − upsert: (lease: AuthLease) => | |
| 463 | − store.db.insert(authLeases).values({ | |
| 464 | − authArtifactId: lease.authArtifactId, | |
| 465 | − json: JSON.stringify(lease), | |
| 466 | − }).onConflictDoUpdate({ | |
| 467 | − target: authLeases.authArtifactId, | |
| 468 | − set: { json: JSON.stringify(lease) }, | |
| 469 | − }).run(), | |
| 470 | − removeByAuthArtifactId: (authArtifactId: AuthLease["authArtifactId"]) => { | |
| 471 | − const row = store.db.select({ id: authLeases.authArtifactId }).from(authLeases).where( | |
| 472 | − eq(authLeases.authArtifactId, authArtifactId), | |
| 473 | − ).get(); | |
| 474 | − if (!row) return false; | |
| 475 | − store.db.delete(authLeases).where(eq(authLeases.authArtifactId, authArtifactId)).run(); | |
| 476 | − return true; | |
| 477 | − }, | |
| 478 | − }, | |
| 479 | − sourceOauthClients: { | |
| 480 | − getByScopeSourceAndProvider: (input: { | |
| 481 | − scopeId: ScopedSourceOauthClient["scopeId"]; | |
| 482 | − sourceId: ScopedSourceOauthClient["sourceId"]; | |
| 483 | − providerKey: string; | |
| 484 | − }) => { | |
| 485 | − const row = store.db.select().from(sourceOauthClients).where( | |
| 486 | − and( | |
| 487 | − eq(sourceOauthClients.scopeId, input.scopeId), | |
| 488 | − eq(sourceOauthClients.sourceId, input.sourceId), | |
| 489 | − eq(sourceOauthClients.providerKey, input.providerKey), | |
| 490 | − ), | |
| 491 | − ).get(); | |
| 492 | − return row ? parseJson<ScopedSourceOauthClient>(row.json) : null; | |
| 493 | − }, | |
| 494 | − upsert: (oauthClient: ScopedSourceOauthClient) => | |
| 495 | − store.db.insert(sourceOauthClients).values({ | |
| 496 | − id: oauthClient.id, | |
| 497 | − scopeId: oauthClient.scopeId, | |
| 498 | − sourceId: oauthClient.sourceId, | |
| 499 | − providerKey: oauthClient.providerKey, | |
| 500 | − json: JSON.stringify(oauthClient), | |
| 501 | − }).onConflictDoUpdate({ | |
| 502 | − target: sourceOauthClients.id, | |
| 503 | − set: { | |
| 504 | − scopeId: oauthClient.scopeId, | |
| 505 | − sourceId: oauthClient.sourceId, | |
| 506 | − providerKey: oauthClient.providerKey, | |
| 507 | − json: JSON.stringify(oauthClient), | |
| 508 | − }, | |
| 509 | − }).run(), | |
| 510 | − removeByScopeAndSourceId: (input: { | |
| 511 | − scopeId: ScopedSourceOauthClient["scopeId"]; | |
| 512 | − sourceId: ScopedSourceOauthClient["sourceId"]; | |
| 513 | − }) => { | |
| 514 | − const rows = store.db.select({ id: sourceOauthClients.id }).from(sourceOauthClients).where( | |
| 515 | − and( | |
| 516 | − eq(sourceOauthClients.scopeId, input.scopeId), | |
| 517 | − eq(sourceOauthClients.sourceId, input.sourceId), | |
| 518 | − ), | |
| 519 | − ).all(); | |
| 520 | − store.db.delete(sourceOauthClients).where( | |
| 521 | − and( | |
| 522 | − eq(sourceOauthClients.scopeId, input.scopeId), | |
| 523 | − eq(sourceOauthClients.sourceId, input.sourceId), | |
| 524 | − ), | |
| 525 | − ).run(); | |
| 526 | − return rows.length; | |
| 527 | − }, | |
| 528 | − }, | |
| 529 | − scopeOauthClients: { | |
| 530 | − listByScopeAndProvider: (input: { | |
| 531 | − scopeId: ScopeOauthClient["scopeId"]; | |
| 532 | − providerKey: string; | |
| 533 | − }) => | |
| 534 | − store.db.select().from(scopeOauthClients).where( | |
| 535 | − and( | |
| 536 | − eq(scopeOauthClients.scopeId, input.scopeId), | |
| 537 | − eq(scopeOauthClients.providerKey, input.providerKey), | |
| 538 | − ), | |
| 539 | − ).all().map((row) => parseJson<ScopeOauthClient>(row.json)), | |
| 540 | − getById: (id: ScopeOauthClient["id"]) => { | |
| 541 | − const row = store.db.select().from(scopeOauthClients).where(eq(scopeOauthClients.id, id)).get(); | |
| 542 | − return row ? parseJson<ScopeOauthClient>(row.json) : null; | |
| 543 | − }, | |
| 544 | − upsert: (oauthClient: ScopeOauthClient) => | |
| 545 | − store.db.insert(scopeOauthClients).values({ | |
| 546 | − id: oauthClient.id, | |
| 547 | − scopeId: oauthClient.scopeId, | |
| 548 | − providerKey: oauthClient.providerKey, | |
| 549 | − json: JSON.stringify(oauthClient), | |
| 550 | − }).onConflictDoUpdate({ | |
| 551 | − target: scopeOauthClients.id, | |
| 552 | − set: { | |
| 553 | − scopeId: oauthClient.scopeId, | |
| 554 | − providerKey: oauthClient.providerKey, | |
| 555 | − json: JSON.stringify(oauthClient), | |
| 556 | − }, | |
| 557 | − }).run(), | |
| 558 | − removeById: (id: ScopeOauthClient["id"]) => { | |
| 559 | − const row = store.db.select({ id: scopeOauthClients.id }).from(scopeOauthClients).where( | |
| 560 | − eq(scopeOauthClients.id, id), | |
| 561 | − ).get(); | |
| 562 | − if (!row) return false; | |
| 563 | − store.db.delete(scopeOauthClients).where(eq(scopeOauthClients.id, id)).run(); | |
| 564 | − return true; | |
| 565 | − }, | |
| 566 | − }, | |
| 567 | − providerGrants: { | |
| 568 | − listByScopeId: (scopeId: ProviderAuthGrant["scopeId"]) => | |
| 569 | − store.db.select().from(providerAuthGrants).where( | |
| 570 | − eq(providerAuthGrants.scopeId, scopeId), | |
| 571 | − ).all().map((row) => parseJson<ProviderAuthGrant>(row.json)), | |
| 572 | − listByScopeActorAndProvider: (input: { | |
| 573 | − scopeId: ProviderAuthGrant["scopeId"]; | |
| 574 | − actorScopeId: ProviderAuthGrant["actorScopeId"]; | |
| 575 | − providerKey: string; | |
| 576 | − }) => | |
| 577 | − store.db.select().from(providerAuthGrants).where( | |
| 578 | − and( | |
| 579 | − eq(providerAuthGrants.scopeId, input.scopeId), | |
| 580 | − eq(providerAuthGrants.providerKey, input.providerKey), | |
| 581 | − ), | |
| 582 | − ).all().map((row) => parseJson<ProviderAuthGrant>(row.json)) | |
| 583 | − .filter((item) => sameActor(item.actorScopeId, input.actorScopeId)), | |
| 584 | − getById: (id: ProviderAuthGrant["id"]) => { | |
| 585 | − const row = store.db.select().from(providerAuthGrants).where( | |
| 586 | − eq(providerAuthGrants.id, id), | |
| 587 | − ).get(); | |
| 588 | − return row ? parseJson<ProviderAuthGrant>(row.json) : null; | |
| 589 | − }, | |
| 590 | − upsert: (grant: ProviderAuthGrant) => | |
| 591 | − store.db.insert(providerAuthGrants).values({ | |
| 592 | − id: grant.id, | |
| 593 | − scopeId: grant.scopeId, | |
| 594 | − actorScopeId: grant.actorScopeId, | |
| 595 | − providerKey: grant.providerKey, | |
| 596 | − json: JSON.stringify(grant), | |
| 597 | − }).onConflictDoUpdate({ | |
| 598 | − target: providerAuthGrants.id, | |
| 599 | − set: { | |
| 600 | − scopeId: grant.scopeId, | |
| 601 | − actorScopeId: grant.actorScopeId, | |
| 602 | − providerKey: grant.providerKey, | |
| 603 | − json: JSON.stringify(grant), | |
| 604 | − }, | |
| 605 | − }).run(), | |
| 606 | − removeById: (id: ProviderAuthGrant["id"]) => { | |
| 607 | − const row = store.db.select({ id: providerAuthGrants.id }).from(providerAuthGrants).where( | |
| 608 | − eq(providerAuthGrants.id, id), | |
| 609 | − ).get(); | |
| 610 | − if (!row) return false; | |
| 611 | − store.db.delete(providerAuthGrants).where(eq(providerAuthGrants.id, id)).run(); | |
| 612 | − return true; | |
| 613 | − }, | |
| 614 | − }, | |
| 615 | − sourceSessions: { | |
| 616 | − listAll: () => | |
| 617 | − store.db.select().from(sourceAuthSessions).all().map((row) => parseJson<SourceAuthSession>(row.json)), | |
| 618 | − listByScopeId: (scopeId: SourceAuthSession["scopeId"]) => | |
| 619 | − store.db.select().from(sourceAuthSessions).where( | |
| 620 | − eq(sourceAuthSessions.scopeId, scopeId), | |
| 621 | − ).all().map((row) => parseJson<SourceAuthSession>(row.json)), | |
| 622 | − getById: (id: SourceAuthSession["id"]) => { | |
| 623 | − const row = store.db.select().from(sourceAuthSessions).where(eq(sourceAuthSessions.id, id)).get(); | |
| 624 | − return row ? parseJson<SourceAuthSession>(row.json) : null; | |
| 625 | − }, | |
| 626 | − getByState: (state: SourceAuthSession["state"]) => { | |
| 627 | − const row = store.db.select().from(sourceAuthSessions).where( | |
| 628 | − eq(sourceAuthSessions.state, state), | |
| 629 | − ).get(); | |
| 630 | − return row ? parseJson<SourceAuthSession>(row.json) : null; | |
| 631 | − }, | |
| 632 | − getPendingByScopeSourceAndActor: (input: { | |
| 633 | − scopeId: SourceAuthSession["scopeId"]; | |
| 634 | − sourceId: SourceAuthSession["sourceId"]; | |
| 635 | − actorScopeId: SourceAuthSession["actorScopeId"]; | |
| 636 | − credentialSlot?: SourceAuthSession["credentialSlot"]; | |
| 637 | − }) => | |
| 638 | − store.db.select().from(sourceAuthSessions).where( | |
| 639 | − and( | |
| 640 | − eq(sourceAuthSessions.scopeId, input.scopeId), | |
| 641 | − eq(sourceAuthSessions.sourceId, input.sourceId), | |
| 642 | − eq(sourceAuthSessions.status, "pending"), | |
| 643 | − ), | |
| 644 | − ).all().map((row) => parseJson<SourceAuthSession>(row.json)) | |
| 645 | − .find((item) => | |
| 646 | − sameActor(item.actorScopeId, input.actorScopeId) | |
| 647 | − && (input.credentialSlot === undefined || item.credentialSlot === input.credentialSlot) | |
| 648 | − ) ?? null, | |
| 649 | − insert: (session: SourceAuthSession) => | |
| 650 | − store.db.insert(sourceAuthSessions).values({ | |
| 651 | − id: session.id, | |
| 652 | − scopeId: session.scopeId, | |
| 653 | − sourceId: session.sourceId, | |
| 654 | − actorScopeId: session.actorScopeId, | |
| 655 | − state: session.state, | |
| 656 | − status: session.status, | |
| 657 | − credentialSlot: session.credentialSlot, | |
| 658 | − json: JSON.stringify(session), | |
| 659 | − }).run(), | |
| 660 | − update: ( | |
| 661 | − id: SourceAuthSession["id"], | |
| 662 | − patch: Partial<Omit<SourceAuthSession, "id" | "scopeId" | "sourceId" | "createdAt">>, | |
| 663 | − ) => { | |
| 664 | − const current = store.db.select().from(sourceAuthSessions).where(eq(sourceAuthSessions.id, id)).get(); | |
| 665 | − if (!current) return null; | |
| 666 | − const next = { ...parseJson<SourceAuthSession>(current.json), ...patch }; | |
| 667 | − store.db.update(sourceAuthSessions).set({ | |
| 668 | − state: next.state, | |
| 669 | − status: next.status, | |
| 670 | − credentialSlot: next.credentialSlot, | |
| 671 | − actorScopeId: next.actorScopeId, | |
| 672 | − json: JSON.stringify(next), | |
| 673 | − }).where(eq(sourceAuthSessions.id, id)).run(); | |
| 674 | − return next; | |
| 675 | − }, | |
| 676 | − upsert: (session: SourceAuthSession) => | |
| 677 | − store.db.insert(sourceAuthSessions).values({ | |
| 678 | − id: session.id, | |
| 679 | − scopeId: session.scopeId, | |
| 680 | − sourceId: session.sourceId, | |
| 681 | − actorScopeId: session.actorScopeId, | |
| 682 | − state: session.state, | |
| 683 | − status: session.status, | |
| 684 | − credentialSlot: session.credentialSlot, | |
| 685 | − json: JSON.stringify(session), | |
| 686 | − }).onConflictDoUpdate({ | |
| 687 | − target: sourceAuthSessions.id, | |
| 688 | − set: { | |
| 689 | − scopeId: session.scopeId, | |
| 690 | − sourceId: session.sourceId, | |
| 691 | − actorScopeId: session.actorScopeId, | |
| 692 | − state: session.state, | |
| 693 | − status: session.status, | |
| 694 | − credentialSlot: session.credentialSlot, | |
| 695 | − json: JSON.stringify(session), | |
| 696 | − }, | |
| 697 | − }).run(), | |
| 698 | − removeByScopeAndSourceId: ( | |
| 699 | − scopeId: SourceAuthSession["scopeId"], | |
| 700 | − sourceId: SourceAuthSession["sourceId"], | |
| 701 | − ) => { | |
| 702 | − const rows = store.db.select({ id: sourceAuthSessions.id }).from(sourceAuthSessions).where( | |
| 703 | − and( | |
| 704 | − eq(sourceAuthSessions.scopeId, scopeId), | |
| 705 | − eq(sourceAuthSessions.sourceId, sourceId), | |
| 706 | − ), | |
| 707 | − ).all(); | |
| 708 | − store.db.delete(sourceAuthSessions).where( | |
| 709 | − and( | |
| 710 | − eq(sourceAuthSessions.scopeId, scopeId), | |
| 711 | − eq(sourceAuthSessions.sourceId, sourceId), | |
| 712 | − ), | |
| 713 | − ).run(); | |
| 714 | − return rows.length > 0; | |
| 715 | − }, | |
| 716 | − }, | |
| 717 | − }, | |
| 718 | 256 | secrets: { |
| 719 | 257 | getById: (id: SecretMaterial["id"]) => { |
| 720 | 258 | const row = store.db.select().from(secretMaterials).where(eq(secretMaterials.id, id)).get(); |
| @@ -929,7 +467,7 @@ export const createSqliteExecutorBackend = ( · 208 unmodified lines | ||
| 929 | 467 | return createExecutorBackend({ |
| 930 | 468 | loadRepositories: () => { |
| 931 | 469 | const store = openSqliteStore(databasePath); |
| 932 | − const { auth, secrets, executions } = createStorageDomains(store); | |
| 470 | + const { secrets, executions } = createStorageDomains(store); | |
| 933 | 471 | |
| 934 | 472 | return { |
| 935 | 473 | scope: { |
| @@ -1042,7 +580,6 @@ export const createSqliteExecutorBackend = ( · 106 unmodified lines | ||
| 1042 | 580 | store.db.delete(sourceArtifacts).where(eq(sourceArtifacts.sourceId, sourceId)).run(); |
| 1043 | 581 | }, |
| 1044 | 582 | }, |
| 1045 | − sourceAuth: auth, | |
| 1046 | 583 | }, |
| 1047 | 584 | secrets: { |
| 1048 | 585 | ...secrets, |
| @@ -5,6 +5,7 @@ · 4 unmodified lines | ||
| 5 | 5 | "packageManager": "bun@1.2.22", |
| 6 | 6 | "workspaces": [ |
| 7 | 7 | "packages/*/*", |
| 8 | + "plugins/*/*", | |
| 8 | 9 | "apps/*", |
| 9 | 10 | "examples/*", |
| 10 | 11 | "apps/docs" |
| @@ -13,6 +13,7 @@ · 12 unmodified lines | ||
| 13 | 13 | "dependencies": { |
| 14 | 14 | "@effect-atom/atom": "0.5.3", |
| 15 | 15 | "@effect-atom/atom-react": "0.5.0", |
| 16 | + "@effect/platform": "catalog:", | |
| 16 | 17 | "@executor/platform-api": "workspace:*", |
| 17 | 18 | "@executor/platform-sdk": "workspace:*", |
| 18 | 19 | "effect": "catalog:" |
| @@ -21,7 +22,6 @@ · 2 unmodified lines | ||
| 21 | 22 | "react": ">=18 <20" |
| 22 | 23 | }, |
| 23 | 24 | "devDependencies": { |
| 24 | − "@effect/platform": "catalog:", | |
| 25 | 25 | "@effect/platform-node": "catalog:", |
| 26 | 26 | "@effect/vitest": "catalog:", |
| 27 | 27 | "@executor/effect-test-utils": "workspace:*", |
| @@ -1,21 +1,30 @@ | ||
| 1 | −import { Atom, Result } from "@effect-atom/atom"; | |
| 2 | −import type * as Registry from "@effect-atom/atom/Registry"; | |
| 3 | −import { RegistryContext, RegistryProvider, useAtomValue } from "@effect-atom/atom-react"; | |
| 4 | 1 | import { |
| 5 | − createExecutorApiClient, | |
| 6 | − type ExecutorApiClient, | |
| 7 | −} from "@executor/platform-api/client"; | |
| 8 | −import type { | |
| 9 | − CreateSecretPayload, | |
| 10 | − CreateSecretResult, | |
| 11 | − CreateSourcePayload, | |
| 12 | − DeleteSecretResult, | |
| 13 | − InstanceConfig, | |
| 14 | − LocalInstallation, | |
| 15 | − SecretListItem, | |
| 16 | − UpdateSecretPayload, | |
| 17 | − UpdateSecretResult, | |
| 18 | − UpdateSourcePayload, | |
| 2 | + Atom, | |
| 3 | + AtomHttpApi, | |
| 4 | + RegistryContext, | |
| 5 | + RegistryProvider, | |
| 6 | + Result, | |
| 7 | + useAtomRefresh, | |
| 8 | + useAtomSet, | |
| 9 | + useAtomValue, | |
| 10 | +} from "@effect-atom/atom-react"; | |
| 11 | +import { | |
| 12 | + FetchHttpClient, | |
| 13 | +} from "@effect/platform"; | |
| 14 | +import type * as HttpApi from "@effect/platform/HttpApi"; | |
| 15 | +import type * as HttpApiGroup from "@effect/platform/HttpApiGroup"; | |
| 16 | +import { | |
| 17 | + ExecutorApi, | |
| 18 | + createExecutorApi, | |
| 19 | + type CreateSecretPayload, | |
| 20 | + type CreateSecretResult, | |
| 21 | + type DeleteSecretResult, | |
| 22 | + type ExecutorHttpApiExtension, | |
| 23 | + type InstanceConfig, | |
| 24 | + type LocalInstallation, | |
| 25 | + type SecretListItem, | |
| 26 | + type UpdateSecretPayload, | |
| 27 | + type UpdateSecretResult, | |
| 19 | 28 | } from "@executor/platform-api"; |
| 20 | 29 | import type { |
| 21 | 30 | Source, |
| @@ -25,16 +34,14 @@ import type { · 3 unmodified lines | ||
| 25 | 34 | } from "@executor/platform-sdk/schema"; |
| 26 | 35 | import * as Cause from "effect/Cause"; |
| 27 | 36 | import * as Effect from "effect/Effect"; |
| 28 | −import * as Option from "effect/Option"; | |
| 29 | −import * as Runtime from "effect/Runtime"; | |
| 30 | 37 | import * as React from "react"; |
| 31 | 38 | |
| 32 | 39 | const DEFAULT_EXECUTOR_API_BASE_URL = "http://127.0.0.1:8788"; |
| 33 | 40 | const PLACEHOLDER_WORKSPACE_ID = "ws_placeholder" as Source["scopeId"]; |
| 34 | −const PLACEHOLDER_ACCOUNT_ID = "acc_placeholder"; | |
| 35 | −const PLACEHOLDER_SOURCE_ID = "src_placeholder" as Source["id"]; | |
| 36 | 41 | |
| 37 | −type SourceMutationState<T> = { | |
| 42 | +type ReactivityKeys = Readonly<Record<string, ReadonlyArray<unknown>>>; | |
| 43 | + | |
| 44 | +type SecretMutationState<T> = { | |
| 38 | 45 | status: "idle" | "pending" | "success" | "error"; |
| 39 | 46 | data: T | null; |
| 40 | 47 | error: Error | null; |
| @@ -44,76 +51,14 @@ export type SourceRemoveResult = { · 3 unmodified lines | ||
| 44 | 51 | removed: boolean; |
| 45 | 52 | }; |
| 46 | 53 | |
| 47 | −type AtomKeyPart = string | number | boolean | null | undefined; | |
| 48 | − | |
| 49 | −type SourcesKeyParts = readonly [boolean, Source["scopeId"], string]; | |
| 50 | −type SourceKeyParts = readonly [boolean, Source["scopeId"], string, Source["id"]]; | |
| 51 | −type SourceToolDetailKeyParts = readonly [ | |
| 52 | − boolean, | |
| 53 | − Source["scopeId"], | |
| 54 | − string, | |
| 55 | − Source["id"], | |
| 56 | − string | null, | |
| 57 | −]; | |
| 58 | −type SourceDiscoveryKeyParts = readonly [ | |
| 59 | − boolean, | |
| 60 | − Source["scopeId"], | |
| 61 | − string, | |
| 62 | − Source["id"], | |
| 63 | − string, | |
| 64 | − number | null, | |
| 65 | −]; | |
| 66 | −type InvalidationTarget = { | |
| 67 | − workspaceId?: Source["scopeId"]; | |
| 68 | − accountId?: string; | |
| 69 | − sourceId?: Source["id"]; | |
| 70 | −}; | |
| 71 | − | |
| 72 | −type ActiveQueryCollections = { | |
| 73 | − sourceLists: Set<string>; | |
| 74 | − sources: Set<string>; | |
| 75 | − inspections: Set<string>; | |
| 76 | − toolDetails: Set<string>; | |
| 77 | − discoveries: Set<string>; | |
| 78 | −}; | |
| 79 | − | |
| 80 | −type ExecutorQueryContextValue = { | |
| 81 | − registry: Registry.Registry; | |
| 82 | − activeQueries: ActiveQueryCollections; | |
| 83 | − invalidateQueries: (target?: InvalidationTarget) => void; | |
| 84 | −}; | |
| 54 | +export type Loadable<T> = | |
| 55 | + | { status: "loading" } | |
| 56 | + | { status: "error"; error: Error } | |
| 57 | + | { status: "ready"; data: T }; | |
| 85 | 58 | |
| 86 | −type MutationExecutionContext = { | |
| 59 | +type WorkspaceContext = { | |
| 60 | + installation: LocalInstallation; | |
| 87 | 61 | workspaceId: Source["scopeId"]; |
| 88 | − accountId: string; | |
| 89 | − registry: Registry.Registry; | |
| 90 | − invalidateQueries: (target?: InvalidationTarget) => void; | |
| 91 | −}; | |
| 92 | − | |
| 93 | −type OptimisticMutationResult<T> = | |
| 94 | − | void | |
| 95 | − | (() => void) | |
| 96 | − | { | |
| 97 | − rollback?: () => void; | |
| 98 | − value?: T; | |
| 99 | − }; | |
| 100 | − | |
| 101 | −type MutationOptions<TInput, TOutput, TOptimistic = never> = { | |
| 102 | − optimisticUpdate?: ( | |
| 103 | − context: MutationExecutionContext, | |
| 104 | − payload: TInput, | |
| 105 | − ) => OptimisticMutationResult<TOptimistic>; | |
| 106 | − onSuccess?: ( | |
| 107 | − context: MutationExecutionContext, | |
| 108 | − payload: TInput, | |
| 109 | − data: TOutput, | |
| 110 | − optimisticValue: TOptimistic | undefined, | |
| 111 | − ) => void; | |
| 112 | −}; | |
| 113 | − | |
| 114 | −type InternalNode<A> = { | |
| 115 | − setValue: (value: A) => void; | |
| 116 | − valueOption?: () => Option.Option<A>; | |
| 117 | 62 | }; |
| 118 | 63 | |
| 119 | 64 | let apiBaseUrl = |
| @@ -121,266 +66,14 @@ let apiBaseUrl = · 1 unmodified line | ||
| 121 | 66 | ? window.location.origin |
| 122 | 67 | : DEFAULT_EXECUTOR_API_BASE_URL; |
| 123 | 68 | |
| 124 | −const ExecutorQueryContext = React.createContext<ExecutorQueryContextValue | null>(null); | |
| 125 | − | |
| 126 | −const encodeAtomKey = (parts: ReadonlyArray<AtomKeyPart>): string => JSON.stringify(parts); | |
| 127 | − | |
| 128 | −const decodeAtomKey = <T extends ReadonlyArray<AtomKeyPart>>(key: string): T => JSON.parse(key) as T; | |
| 129 | − | |
| 130 | −const encodeSourcesKey = ( | |
| 131 | − enabled: boolean, | |
| 132 | − workspaceId: Source["scopeId"], | |
| 133 | − accountId: string, | |
| 134 | −): string => encodeAtomKey([enabled, workspaceId, accountId] satisfies SourcesKeyParts); | |
| 135 | − | |
| 136 | −const encodeSourceKey = ( | |
| 137 | − enabled: boolean, | |
| 138 | − workspaceId: Source["scopeId"], | |
| 139 | − accountId: string, | |
| 140 | − sourceId: Source["id"], | |
| 141 | −): string => encodeAtomKey([enabled, workspaceId, accountId, sourceId] satisfies SourceKeyParts); | |
| 142 | − | |
| 143 | −const encodeToolDetailKey = ( | |
| 144 | − enabled: boolean, | |
| 145 | − workspaceId: Source["scopeId"], | |
| 146 | − accountId: string, | |
| 147 | − sourceId: Source["id"], | |
| 148 | − toolPath: string | null, | |
| 149 | −): string => | |
| 150 | − encodeAtomKey([enabled, workspaceId, accountId, sourceId, toolPath] satisfies SourceToolDetailKeyParts); | |
| 151 | − | |
| 152 | −const encodeDiscoveryKey = ( | |
| 153 | − enabled: boolean, | |
| 154 | − workspaceId: Source["scopeId"], | |
| 155 | − accountId: string, | |
| 156 | − sourceId: Source["id"], | |
| 157 | − query: string, | |
| 158 | − limit: number | null, | |
| 159 | −): string => | |
| 160 | − encodeAtomKey([enabled, workspaceId, accountId, sourceId, query, limit] satisfies SourceDiscoveryKeyParts); | |
| 161 | − | |
| 162 | −const toError = (cause: unknown): Error => | |
| 163 | − cause instanceof Error ? cause : new Error(String(cause)); | |
| 69 | +const pendingResultAtom = Atom.make( | |
| 70 | + Effect.never as Effect.Effect<never, Error>, | |
| 71 | +).pipe(Atom.keepAlive); | |
| 164 | 72 | |
| 165 | 73 | const causeMessage = (cause: Cause.Cause<unknown>): Error => |
| 166 | 74 | new Error(Cause.pretty(cause)); |
| 167 | 75 | |
| 168 | −const shouldLogExecutorDevErrors = (): boolean => { | |
| 169 | − if (typeof window === "undefined") { | |
| 170 | − return false; | |
| 171 | − } | |
| 172 | − | |
| 173 | − const hostname = window.location.hostname; | |
| 174 | − return hostname === "localhost" || hostname === "127.0.0.1"; | |
| 175 | −}; | |
| 176 | − | |
| 177 | −const describeExecutorDevError = (cause: unknown): Record<string, unknown> => { | |
| 178 | − if (Runtime.isFiberFailure(cause)) { | |
| 179 | − const inner = cause[Runtime.FiberFailureCauseId]; | |
| 180 | − return { | |
| 181 | − name: cause.name, | |
| 182 | − message: cause.message, | |
| 183 | − cause: Cause.pretty(inner), | |
| 184 | − }; | |
| 185 | − } | |
| 186 | − | |
| 187 | − if (cause instanceof Error) { | |
| 188 | − return { | |
| 189 | − name: cause.name, | |
| 190 | − message: cause.message, | |
| 191 | − stack: cause.stack, | |
| 192 | − }; | |
| 193 | − } | |
| 194 | − | |
| 195 | − return { | |
| 196 | − message: String(cause), | |
| 197 | − }; | |
| 198 | −}; | |
| 199 | − | |
| 200 | −const logExecutorDevError = (label: string, details: Record<string, unknown>): void => { | |
| 201 | − if (!shouldLogExecutorDevErrors()) { | |
| 202 | − return; | |
| 203 | − } | |
| 204 | − | |
| 205 | − console.error(`[executor react] ${label}`, details); | |
| 206 | −}; | |
| 207 | − | |
| 208 | −const runControlPlane = async <A>(input: { | |
| 209 | − baseUrl?: string; | |
| 210 | − accountId?: string; | |
| 211 | − execute: (client: ExecutorApiClient) => Promise<A>; | |
| 212 | −}): Promise<A> => { | |
| 213 | − const baseUrl = input.baseUrl ?? apiBaseUrl; | |
| 214 | − const accountId = input.accountId; | |
| 215 | − | |
| 216 | − try { | |
| 217 | − const client = await createExecutorApiClient({ | |
| 218 | − baseUrl, | |
| 219 | − ...(accountId !== undefined ? { accountId } : {}), | |
| 220 | − }); | |
| 221 | − return await input.execute(client); | |
| 222 | − } catch (cause) { | |
| 223 | − const error = toError(cause); | |
| 224 | − logExecutorDevError("control-plane request failed", { | |
| 225 | − baseUrl, | |
| 226 | − accountId, | |
| 227 | − error: describeExecutorDevError(error), | |
| 228 | − }); | |
| 229 | − throw error; | |
| 230 | − } | |
| 231 | −}; | |
| 232 | − | |
| 233 | −const controlPlaneRequest = <A>(input: { | |
| 234 | − baseUrl?: string; | |
| 235 | − accountId?: string; | |
| 236 | − execute: (client: ExecutorApiClient) => Promise<A>; | |
| 237 | −}): Effect.Effect<A, Error> => | |
| 238 | − Effect.tryPromise({ | |
| 239 | − try: () => runControlPlane(input), | |
| 240 | − catch: toError, | |
| 241 | − }); | |
| 242 | − | |
| 243 | −const localInstallationAtom = Atom.family((baseUrl: string) => | |
| 244 | − Atom.make( | |
| 245 | − controlPlaneRequest({ | |
| 246 | − baseUrl, | |
| 247 | − execute: (client) => client.local.installation({}), | |
| 248 | − }), | |
| 249 | − ).pipe(Atom.keepAlive), | |
| 250 | −); | |
| 251 | − | |
| 252 | −const instanceConfigAtom = Atom.family((baseUrl: string) => | |
| 253 | − Atom.make( | |
| 254 | − controlPlaneRequest({ | |
| 255 | − baseUrl, | |
| 256 | − execute: (client) => client.local.config({}), | |
| 257 | − }), | |
| 258 | − ).pipe(Atom.keepAlive), | |
| 259 | −); | |
| 260 | − | |
| 261 | −const secretsAtom = Atom.family((baseUrl: string) => | |
| 262 | − Atom.make( | |
| 263 | − controlPlaneRequest({ | |
| 264 | − baseUrl, | |
| 265 | − execute: (client) => client.local.listSecrets({}), | |
| 266 | − }), | |
| 267 | − ).pipe(Atom.keepAlive), | |
| 268 | −); | |
| 269 | − | |
| 270 | −const sourcesAtom = Atom.family((key: string) => { | |
| 271 | − const [enabled, workspaceId, accountId] = decodeAtomKey<SourcesKeyParts>(key); | |
| 272 | − | |
| 273 | − return Atom.make( | |
| 274 | − enabled | |
| 275 | − ? controlPlaneRequest({ | |
| 276 | − accountId, | |
| 277 | − execute: (client) => client.sources.list({ | |
| 278 | − path: { | |
| 279 | − workspaceId, | |
| 280 | − }, | |
| 281 | − }), | |
| 282 | − }) | |
| 283 | − : Effect.never, | |
| 284 | − ).pipe(Atom.keepAlive); | |
| 285 | −}); | |
| 286 | − | |
| 287 | −const sourceAtom = Atom.family((key: string) => { | |
| 288 | − const [enabled, workspaceId, accountId, sourceId] = decodeAtomKey<SourceKeyParts>(key); | |
| 289 | − | |
| 290 | − return Atom.make( | |
| 291 | − enabled | |
| 292 | − ? controlPlaneRequest({ | |
| 293 | − accountId, | |
| 294 | − execute: (client) => client.sources.get({ | |
| 295 | − path: { | |
| 296 | − workspaceId, | |
| 297 | − sourceId, | |
| 298 | − }, | |
| 299 | − }), | |
| 300 | − }) | |
| 301 | − : Effect.never, | |
| 302 | − ).pipe(Atom.keepAlive); | |
| 303 | −}); | |
| 304 | − | |
| 305 | −const sourceInspectionAtom = Atom.family((key: string) => { | |
| 306 | − const [enabled, workspaceId, accountId, sourceId] = decodeAtomKey<SourceKeyParts>(key); | |
| 307 | − | |
| 308 | − return Atom.make( | |
| 309 | − enabled | |
| 310 | − ? controlPlaneRequest({ | |
| 311 | − accountId, | |
| 312 | − execute: (client) => client.sources.inspection({ | |
| 313 | − path: { | |
| 314 | − workspaceId, | |
| 315 | − sourceId, | |
| 316 | − }, | |
| 317 | − }), | |
| 318 | − }) | |
| 319 | − : Effect.never, | |
| 320 | − ).pipe(Atom.keepAlive); | |
| 321 | −}); | |
| 322 | − | |
| 323 | −const sourceInspectionToolAtom = Atom.family((key: string) => { | |
| 324 | − const [enabled, workspaceId, accountId, sourceId, toolPath] = decodeAtomKey<SourceToolDetailKeyParts>(key); | |
| 325 | − | |
| 326 | − return Atom.make( | |
| 327 | − enabled && toolPath | |
| 328 | − ? controlPlaneRequest({ | |
| 329 | − accountId, | |
| 330 | − execute: (client) => client.sources.inspectionTool({ | |
| 331 | − path: { | |
| 332 | − workspaceId, | |
| 333 | − sourceId, | |
| 334 | − toolPath, | |
| 335 | − }, | |
| 336 | − }), | |
| 337 | − }) | |
| 338 | − : Effect.succeed<SourceInspectionToolDetail | null>(null), | |
| 339 | − ).pipe(Atom.keepAlive); | |
| 340 | −}); | |
| 341 | − | |
| 342 | −const sourceDiscoveryAtom = Atom.family((key: string) => { | |
| 343 | − const [enabled, workspaceId, accountId, sourceId, query, limit] = decodeAtomKey<SourceDiscoveryKeyParts>(key); | |
| 344 | − | |
| 345 | − return Atom.make( | |
| 346 | − !enabled | |
| 347 | − ? Effect.never | |
| 348 | − : query.trim().length === 0 | |
| 349 | − ? Effect.succeed<SourceInspectionDiscoverResult>({ | |
| 350 | − query: "", | |
| 351 | − queryTokens: [], | |
| 352 | − bestPath: null, | |
| 353 | − total: 0, | |
| 354 | − results: [], | |
| 355 | − }) | |
| 356 | − : controlPlaneRequest({ | |
| 357 | − accountId, | |
| 358 | − execute: (client) => client.sources.inspectionDiscover({ | |
| 359 | − path: { | |
| 360 | − workspaceId, | |
| 361 | − sourceId, | |
| 362 | − }, | |
| 363 | − payload: { | |
| 364 | − query, | |
| 365 | − ...(limit !== null ? { limit } : {}), | |
| 366 | − }, | |
| 367 | − }), | |
| 368 | − }), | |
| 369 | − ).pipe(Atom.keepAlive); | |
| 370 | −}); | |
| 371 | − | |
| 372 | −export type Loadable<T> = | |
| 373 | − | { status: "loading" } | |
| 374 | − | { status: "error"; error: Error } | |
| 375 | − | { status: "ready"; data: T }; | |
| 376 | − | |
| 377 | −type WorkspaceContext = { | |
| 378 | − installation: LocalInstallation; | |
| 379 | − workspaceId: Source["scopeId"]; | |
| 380 | − accountId: string; | |
| 381 | −}; | |
| 382 | − | |
| 383 | −const toLoadable = <T>(result: Result.Result<T, Error>): Loadable<T> => { | |
| 76 | +const toLoadable = <T>(result: Result.Result<T, unknown>): Loadable<T> => { | |
| 384 | 77 | if (Result.isSuccess(result)) { |
| 385 | 78 | return { |
| 386 | 79 | status: "ready", |
| @@ -412,310 +105,298 @@ const pendingLoadable = <T>(workspace: Loadable<WorkspaceContext>): Loadable<T> · 25 unmodified lines | ||
| 412 | 105 | throw new Error("Expected workspace loadable to be pending or errored"); |
| 413 | 106 | }; |
| 414 | 107 | |
| 415 | −const useLoadableAtom = <T>(atom: Atom.Atom<Result.Result<T, Error>>): Loadable<T> => { | |
| 108 | +const useLoadableAtom = <T>(atom: Atom.Atom<Result.Result<T, unknown>>): Loadable<T> => { | |
| 416 | 109 | const result = useAtomValue(atom); |
| 417 | 110 | return React.useMemo(() => toLoadable(result), [result]); |
| 418 | 111 | }; |
| 419 | 112 | |
| 420 | −const useWorkspaceContext = (): Loadable<WorkspaceContext> => { | |
| 421 | − const installation = useLoadableAtom(localInstallationAtom(apiBaseUrl)); | |
| 113 | +const disabledAtom = <T>() => | |
| 114 | + pendingResultAtom as unknown as Atom.Atom<Result.Result<T, unknown>>; | |
| 422 | 115 | |
| 423 | − return React.useMemo(() => { | |
| 424 | − if (installation.status !== "ready") { | |
| 425 | − return installation; | |
| 426 | − } | |
| 116 | +export const getExecutorApiBaseUrl = (): string => apiBaseUrl; | |
| 427 | 117 | |
| 428 | − return { | |
| 429 | − status: "ready", | |
| 430 | − data: { | |
| 431 | − installation: installation.data, | |
| 432 | − workspaceId: installation.data.scopeId, | |
| 433 | − accountId: installation.data.actorScopeId, | |
| 434 | − }, | |
| 435 | − } satisfies Loadable<WorkspaceContext>; | |
| 436 | − }, [installation]); | |
| 118 | +export const setExecutorApiBaseUrl = (baseUrl: string): void => { | |
| 119 | + apiBaseUrl = baseUrl; | |
| 437 | 120 | }; |
| 438 | 121 | |
| 439 | −const useWorkspaceRequestContext = () => { | |
| 440 | − const workspace = useWorkspaceContext(); | |
| 441 | − const enabled = workspace.status === "ready"; | |
| 122 | +export const defineExecutorHttpApiClient = | |
| 123 | + <Self>() => | |
| 124 | + < | |
| 125 | + const Id extends string, | |
| 126 | + ApiId extends string, | |
| 127 | + Groups extends HttpApiGroup.HttpApiGroup.Any, | |
| 128 | + ApiE, | |
| 129 | + R, | |
| 130 | + >( | |
| 131 | + id: Id, | |
| 132 | + api: HttpApi.HttpApi<ApiId, Groups, ApiE, R>, | |
| 133 | + ) => { | |
| 134 | + const build = (baseUrl: string | URL) => | |
| 135 | + AtomHttpApi.Tag<Self>()(id, { | |
| 136 | + api, | |
| 137 | + httpClient: FetchHttpClient.layer as any, | |
| 138 | + baseUrl, | |
| 139 | + }); | |
| 442 | 140 | |
| 443 | − const workspaceId = enabled | |
| 444 | − ? workspace.data.workspaceId | |
| 445 | − : PLACEHOLDER_WORKSPACE_ID; | |
| 446 | − const accountId = enabled | |
| 447 | − ? workspace.data.accountId | |
| 448 | − : PLACEHOLDER_ACCOUNT_ID; | |
| 141 | + const cache = new Map<string, ReturnType<typeof build>>(); | |
| 449 | 142 | |
| 450 | − return React.useMemo( | |
| 451 | − () => ({ | |
| 452 | − workspace, | |
| 453 | − enabled, | |
| 454 | − workspaceId, | |
| 455 | − accountId, | |
| 456 | − }), | |
| 457 | − [accountId, enabled, workspace, workspaceId], | |
| 458 | − ); | |
| 459 | −}; | |
| 143 | + return (baseUrl: string | URL = getExecutorApiBaseUrl()) => { | |
| 144 | + const key = String(baseUrl); | |
| 145 | + const cached = cache.get(key); | |
| 146 | + if (cached !== undefined) { | |
| 147 | + return cached; | |
| 148 | + } | |
| 460 | 149 | |
| 461 | −const getCachedAtomValue = <A>( | |
| 462 | − registry: Registry.Registry, | |
| 463 | − atom: Atom.Atom<Result.Result<A, Error>>, | |
| 464 | −): A | undefined => { | |
| 465 | − const node = (registry.getNodes().get(atom) ?? null) as InternalNode<Result.Result<A, Error>> | null; | |
| 466 | − if (node === null || typeof node.valueOption !== "function") { | |
| 467 | − return undefined; | |
| 468 | − } | |
| 150 | + const client = build(baseUrl); | |
| 151 | + cache.set(key, client); | |
| 152 | + return client; | |
| 153 | + }; | |
| 154 | + }; | |
| 469 | 155 | |
| 470 | − const option = node.valueOption(); | |
| 471 | − if (Option.isNone(option)) { | |
| 472 | − return undefined; | |
| 473 | − } | |
| 156 | +export const defineExecutorPluginHttpApiClient = | |
| 157 | + <Self>() => | |
| 158 | + < | |
| 159 | + const Id extends string, | |
| 160 | + TExtensions extends readonly ExecutorHttpApiExtension[], | |
| 161 | + >( | |
| 162 | + id: Id, | |
| 163 | + extensions: TExtensions, | |
| 164 | + ) => | |
| 165 | + defineExecutorHttpApiClient<Self>()( | |
| 166 | + id, | |
| 167 | + createExecutorApi({ | |
| 168 | + plugins: extensions, | |
| 169 | + }), | |
| 170 | + ); | |
| 171 | + | |
| 172 | +const getExecutorApiHttpClient = defineExecutorHttpApiClient<"ExecutorReactHttpClient">()( | |
| 173 | + "ExecutorReactHttpClient", | |
| 174 | + ExecutorApi, | |
| 175 | +); | |
| 474 | 176 | |
| 475 | − if (!Result.isSuccess(option.value)) { | |
| 476 | − return undefined; | |
| 477 | − } | |
| 177 | +const localInstallationReactivityKey = (): ReactivityKeys => ({ | |
| 178 | + localInstallation: [], | |
| 179 | +}); | |
| 478 | 180 | |
| 479 | − return option.value.value; | |
| 480 | −}; | |
| 181 | +const instanceConfigReactivityKey = (): ReactivityKeys => ({ | |
| 182 | + instanceConfig: [], | |
| 183 | +}); | |
| 481 | 184 | |
| 482 | −const setCachedAtomValue = <A>( | |
| 483 | − registry: Registry.Registry, | |
| 484 | − atom: Atom.Atom<Result.Result<A, Error>>, | |
| 485 | − value: A, | |
| 486 | −): void => { | |
| 487 | − const ensureNode = (registry as { | |
| 488 | − ensureNode?: (atom: Atom.Atom<Result.Result<A, Error>>) => InternalNode<Result.Result<A, Error>>; | |
| 489 | − }).ensureNode; | |
| 490 | − if (typeof ensureNode !== "function") { | |
| 491 | − return; | |
| 492 | − } | |
| 185 | +const secretsReactivityKey = (): ReactivityKeys => ({ | |
| 186 | + secrets: [], | |
| 187 | +}); | |
| 493 | 188 | |
| 494 | − ensureNode.call(registry, atom).setValue(Result.success(value)); | |
| 495 | −}; | |
| 189 | +const sourcesReactivityKey = (workspaceId: Source["scopeId"]): ReactivityKeys => ({ | |
| 190 | + sources: [workspaceId], | |
| 191 | +}); | |
| 496 | 192 | |
| 497 | −const createActiveQueryCollections = (): ActiveQueryCollections => ({ | |
| 498 | − sourceLists: new Set(), | |
| 499 | − sources: new Set(), | |
| 500 | − inspections: new Set(), | |
| 501 | − toolDetails: new Set(), | |
| 502 | − discoveries: new Set(), | |
| 193 | +const sourceReactivityKey = ( | |
| 194 | + workspaceId: Source["scopeId"], | |
| 195 | + sourceId: Source["id"], | |
| 196 | +): ReactivityKeys => ({ | |
| 197 | + source: [workspaceId, sourceId], | |
| 503 | 198 | }); |
| 504 | 199 | |
| 505 | −const targetMatches = ( | |
| 506 | − target: InvalidationTarget | undefined, | |
| 200 | +const sourceInspectionReactivityKey = ( | |
| 507 | 201 | workspaceId: Source["scopeId"], |
| 508 | − accountId: string, | |
| 509 | − sourceId?: Source["id"], | |
| 510 | −): boolean => { | |
| 511 | − if (target?.workspaceId !== undefined && target.workspaceId !== workspaceId) { | |
| 512 | − return false; | |
| 513 | − } | |
| 514 | − if (target?.accountId !== undefined && target.accountId !== accountId) { | |
| 515 | − return false; | |
| 516 | − } | |
| 517 | − if (target?.sourceId !== undefined && target.sourceId !== sourceId) { | |
| 518 | − return false; | |
| 519 | − } | |
| 520 | − return true; | |
| 521 | −}; | |
| 202 | + sourceId: Source["id"], | |
| 203 | +): ReactivityKeys => ({ | |
| 204 | + sourceInspection: [workspaceId, sourceId], | |
| 205 | +}); | |
| 522 | 206 | |
| 523 | −const invalidateTrackedQueries = ( | |
| 524 | − registry: Registry.Registry, | |
| 525 | − activeQueries: ActiveQueryCollections, | |
| 526 | − target?: InvalidationTarget, | |
| 527 | −): void => { | |
| 528 | − activeQueries.sourceLists.forEach((key) => { | |
| 529 | − const [enabled, workspaceId, accountId] = decodeAtomKey<SourcesKeyParts>(key); | |
| 530 | − if (enabled && targetMatches(target, workspaceId, accountId)) { | |
| 531 | − registry.refresh(sourcesAtom(key)); | |
| 532 | − } | |
| 533 | − }); | |
| 207 | +const sourceInspectionToolReactivityKey = ( | |
| 208 | + workspaceId: Source["scopeId"], | |
| 209 | + sourceId: Source["id"], | |
| 210 | + toolPath?: string | null, | |
| 211 | +): ReactivityKeys => ({ | |
| 212 | + sourceInspectionTool: | |
| 213 | + toolPath === undefined || toolPath === null | |
| 214 | + ? [workspaceId, sourceId] | |
| 215 | + : [workspaceId, sourceId, toolPath], | |
| 216 | +}); | |
| 534 | 217 | |
| 535 | − activeQueries.sources.forEach((key) => { | |
| 536 | − const [enabled, workspaceId, accountId, sourceId] = decodeAtomKey<SourceKeyParts>(key); | |
| 537 | − if (enabled && targetMatches(target, workspaceId, accountId, sourceId)) { | |
| 538 | − registry.refresh(sourceAtom(key)); | |
| 539 | − } | |
| 540 | − }); | |
| 218 | +const sourceDiscoveryReactivityKey = ( | |
| 219 | + workspaceId: Source["scopeId"], | |
| 220 | + sourceId: Source["id"], | |
| 221 | + query?: string, | |
| 222 | + limit?: number | null, | |
| 223 | +): ReactivityKeys => ({ | |
| 224 | + sourceDiscovery: | |
| 225 | + query === undefined | |
| 226 | + ? [workspaceId, sourceId] | |
| 227 | + : [workspaceId, sourceId, query, limit ?? null], | |
| 228 | +}); | |
| 541 | 229 | |
| 542 | − activeQueries.inspections.forEach((key) => { | |
| 543 | − const [enabled, workspaceId, accountId, sourceId] = decodeAtomKey<SourceKeyParts>(key); | |
| 544 | − if (enabled && targetMatches(target, workspaceId, accountId, sourceId)) { | |
| 545 | − registry.refresh(sourceInspectionAtom(key)); | |
| 546 | − } | |
| 230 | +const localInstallationAtom = (baseUrl: string) => | |
| 231 | + getExecutorApiHttpClient(baseUrl).query("local", "installation", { | |
| 232 | + reactivityKeys: localInstallationReactivityKey(), | |
| 233 | + timeToLive: "5 minutes", | |
| 547 | 234 | }); |
| 548 | 235 | |
| 549 | − activeQueries.toolDetails.forEach((key) => { | |
| 550 | − const [enabled, workspaceId, accountId, sourceId] = decodeAtomKey<SourceToolDetailKeyParts>(key); | |
| 551 | − if (enabled && targetMatches(target, workspaceId, accountId, sourceId)) { | |
| 552 | − registry.refresh(sourceInspectionToolAtom(key)); | |
| 553 | − } | |
| 236 | +const instanceConfigAtom = (baseUrl: string) => | |
| 237 | + getExecutorApiHttpClient(baseUrl).query("local", "config", { | |
| 238 | + reactivityKeys: instanceConfigReactivityKey(), | |
| 239 | + timeToLive: "5 minutes", | |
| 554 | 240 | }); |
| 555 | 241 | |
| 556 | − activeQueries.discoveries.forEach((key) => { | |
| 557 | − const [enabled, workspaceId, accountId, sourceId] = decodeAtomKey<SourceDiscoveryKeyParts>(key); | |
| 558 | − if (enabled && targetMatches(target, workspaceId, accountId, sourceId)) { | |
| 559 | − registry.refresh(sourceDiscoveryAtom(key)); | |
| 560 | − } | |
| 242 | +const secretsAtom = (baseUrl: string) => | |
| 243 | + getExecutorApiHttpClient(baseUrl).query("local", "listSecrets", { | |
| 244 | + reactivityKeys: secretsReactivityKey(), | |
| 245 | + timeToLive: "1 minute", | |
| 561 | 246 | }); |
| 562 | −}; | |
| 563 | 247 | |
| 564 | −const useExecutorQueryContext = (): ExecutorQueryContextValue => { | |
| 565 | − const context = React.useContext(ExecutorQueryContext); | |
| 566 | − if (context === null) { | |
| 567 | − throw new Error("ExecutorReactProvider is missing from the React tree"); | |
| 568 | − } | |
| 569 | − return context; | |
| 570 | −}; | |
| 571 | − | |
| 572 | −const useTrackActiveKey = ( | |
| 573 | − collection: keyof ActiveQueryCollections, | |
| 574 | − key: string, | |
| 575 | − enabled: boolean, | |
| 576 | −): void => { | |
| 577 | − const { activeQueries } = useExecutorQueryContext(); | |
| 248 | +const sourcesAtom = (workspaceId: Source["scopeId"]) => | |
| 249 | + getExecutorApiHttpClient().query("sources", "list", { | |
| 250 | + path: { | |
| 251 | + workspaceId, | |
| 252 | + }, | |
| 253 | + reactivityKeys: sourcesReactivityKey(workspaceId), | |
| 254 | + timeToLive: "30 seconds", | |
| 255 | + }); | |
| 578 | 256 | |
| 579 | − React.useEffect(() => { | |
| 580 | − if (!enabled) { | |
| 581 | − return; | |
| 582 | − } | |
| 257 | +const sourceAtom = ( | |
| 258 | + workspaceId: Source["scopeId"], | |
| 259 | + sourceId: Source["id"], | |
| 260 | +) => | |
| 261 | + getExecutorApiHttpClient().query("sources", "get", { | |
| 262 | + path: { | |
| 263 | + workspaceId, | |
| 264 | + sourceId, | |
| 265 | + }, | |
| 266 | + reactivityKeys: sourceReactivityKey(workspaceId, sourceId), | |
| 267 | + timeToLive: "30 seconds", | |
| 268 | + }); | |
| 583 | 269 | |
| 584 | − const bucket = activeQueries[collection]; | |
| 585 | − bucket.add(key); | |
| 586 | − return () => { | |
| 587 | − bucket.delete(key); | |
| 588 | − }; | |
| 589 | − }, [activeQueries, collection, enabled, key]); | |
| 590 | −}; | |
| 270 | +const sourceInspectionAtom = ( | |
| 271 | + workspaceId: Source["scopeId"], | |
| 272 | + sourceId: Source["id"], | |
| 273 | +) => | |
| 274 | + getExecutorApiHttpClient().query("sources", "inspection", { | |
| 275 | + path: { | |
| 276 | + workspaceId, | |
| 277 | + sourceId, | |
| 278 | + }, | |
| 279 | + reactivityKeys: sourceInspectionReactivityKey(workspaceId, sourceId), | |
| 280 | + timeToLive: "30 seconds", | |
| 281 | + }); | |
| 591 | 282 | |
| 592 | −const upsertSourceInList = ( | |
| 593 | − sources: ReadonlyArray<Source>, | |
| 594 | − nextSource: Source, | |
| 595 | −): ReadonlyArray<Source> => { | |
| 596 | − const index = sources.findIndex((source) => source.id === nextSource.id); | |
| 597 | − if (index === -1) { | |
| 598 | − return [nextSource, ...sources]; | |
| 599 | − } | |
| 283 | +const sourceInspectionToolAtom = ( | |
| 284 | + workspaceId: Source["scopeId"], | |
| 285 | + sourceId: Source["id"], | |
| 286 | + toolPath: string | null, | |
| 287 | +) => | |
| 288 | + toolPath === null | |
| 289 | + ? disabledAtom<SourceInspectionToolDetail | null>() | |
| 290 | + : getExecutorApiHttpClient().query("sources", "inspectionTool", { | |
| 291 | + path: { | |
| 292 | + workspaceId, | |
| 293 | + sourceId, | |
| 294 | + toolPath, | |
| 295 | + }, | |
| 296 | + reactivityKeys: sourceInspectionToolReactivityKey( | |
| 297 | + workspaceId, | |
| 298 | + sourceId, | |
| 299 | + toolPath, | |
| 300 | + ), | |
| 301 | + timeToLive: "30 seconds", | |
| 302 | + }); | |
| 600 | 303 | |
| 601 | − const next = sources.slice(); | |
| 602 | − next[index] = nextSource; | |
| 603 | − return next; | |
| 304 | +const emptyDiscoveryResult: SourceInspectionDiscoverResult = { | |
| 305 | + query: "", | |
| 306 | + queryTokens: [], | |
| 307 | + bestPath: null, | |
| 308 | + total: 0, | |
| 309 | + results: [], | |
| 604 | 310 | }; |
| 605 | 311 | |
| 606 | −const removeSourceFromList = ( | |
| 607 | − sources: ReadonlyArray<Source>, | |
| 312 | +const sourceDiscoveryAtom = ( | |
| 313 | + workspaceId: Source["scopeId"], | |
| 608 | 314 | sourceId: Source["id"], |
| 609 | −): ReadonlyArray<Source> => sources.filter((source) => source.id !== sourceId); | |
| 315 | + query: string, | |
| 316 | + limit: number | null, | |
| 317 | +) => | |
| 318 | + query.trim().length === 0 | |
| 319 | + ? Atom.make( | |
| 320 | + Effect.succeed(emptyDiscoveryResult), | |
| 321 | + ).pipe(Atom.keepAlive) | |
| 322 | + : getExecutorApiHttpClient().query("sources", "inspectionDiscover", { | |
| 323 | + path: { | |
| 324 | + workspaceId, | |
| 325 | + sourceId, | |
| 326 | + }, | |
| 327 | + payload: { | |
| 328 | + query, | |
| 329 | + ...(limit !== null ? { limit } : {}), | |
| 330 | + }, | |
| 331 | + reactivityKeys: sourceDiscoveryReactivityKey( | |
| 332 | + workspaceId, | |
| 333 | + sourceId, | |
| 334 | + query, | |
| 335 | + limit, | |
| 336 | + ), | |
| 337 | + timeToLive: "15 seconds", | |
| 338 | + }); | |
| 610 | 339 | |
| 611 | −const createOptimisticSource = (input: { | |
| 612 | − workspaceId: Source["scopeId"]; | |
| 613 | − payload: CreateSourcePayload; | |
| 614 | −}): Source => { | |
| 615 | − const now = Date.now(); | |
| 340 | +const useWorkspaceContext = (): Loadable<WorkspaceContext> => { | |
| 341 | + const installation = useLoadableAtom(localInstallationAtom(getExecutorApiBaseUrl())); | |
| 616 | 342 | |
| 617 | − return { | |
| 618 | − id: `src_optimistic_${crypto.randomUUID()}` as Source["id"], | |
| 619 | − scopeId: input.workspaceId, | |
| 620 | − name: input.payload.name, | |
| 621 | − kind: input.payload.kind, | |
| 622 | − endpoint: input.payload.endpoint, | |
| 623 | − status: input.payload.status ?? "draft", | |
| 624 | − enabled: input.payload.enabled ?? true, | |
| 625 | − namespace: input.payload.namespace ?? null, | |
| 626 | − bindingVersion: 1, | |
| 627 | − binding: input.payload.binding ?? {}, | |
| 628 | − importAuthPolicy: input.payload.importAuthPolicy ?? "reuse_runtime", | |
| 629 | − importAuth: input.payload.importAuth ?? { kind: "none" }, | |
| 630 | − auth: input.payload.auth ?? { kind: "none" }, | |
| 631 | − sourceHash: input.payload.sourceHash ?? null, | |
| 632 | − lastError: input.payload.lastError ?? null, | |
| 633 | − createdAt: now, | |
| 634 | − updatedAt: now, | |
| 635 | − }; | |
| 343 | + return React.useMemo(() => { | |
| 344 | + if (installation.status !== "ready") { | |
| 345 | + return installation; | |
| 346 | + } | |
| 347 | + | |
| 348 | + return { | |
| 349 | + status: "ready", | |
| 350 | + data: { | |
| 351 | + installation: installation.data, | |
| 352 | + workspaceId: installation.data.scopeId, | |
| 353 | + }, | |
| 354 | + } satisfies Loadable<WorkspaceContext>; | |
| 355 | + }, [installation]); | |
| 636 | 356 | }; |
| 637 | 357 | |
| 638 | −const applyUpdatePayloadToSource = (source: Source, payload: UpdateSourcePayload): Source => ({ | |
| 639 | − ...source, | |
| 640 | − name: payload.name ?? source.name, | |
| 641 | − endpoint: payload.endpoint ?? source.endpoint, | |
| 642 | − status: payload.status ?? source.status, | |
| 643 | − enabled: payload.enabled ?? source.enabled, | |
| 644 | − namespace: payload.namespace !== undefined ? payload.namespace : source.namespace, | |
| 645 | − binding: payload.binding !== undefined ? payload.binding : source.binding, | |
| 646 | − auth: payload.auth !== undefined ? payload.auth : source.auth, | |
| 647 | − sourceHash: payload.sourceHash !== undefined ? payload.sourceHash : source.sourceHash, | |
| 648 | − lastError: payload.lastError !== undefined ? payload.lastError : source.lastError, | |
| 649 | − updatedAt: Date.now(), | |
| 650 | −}); | |
| 358 | +const useWorkspaceRequestContext = () => { | |
| 359 | + const workspace = useWorkspaceContext(); | |
| 360 | + const enabled = workspace.status === "ready"; | |
| 651 | 361 | |
| 652 | −const useSourceMutation = <TInput, TOutput, TOptimistic = never>( | |
| 653 | − execute: (input: { | |
| 654 | − workspaceId: Source["scopeId"]; | |
| 655 | − accountId: string; | |
| 656 | − payload: TInput; | |
| 657 | − }) => Promise<TOutput>, | |
| 658 | − options?: MutationOptions<TInput, TOutput, TOptimistic>, | |
| 362 | + return React.useMemo( | |
| 363 | + () => ({ | |
| 364 | + workspace, | |
| 365 | + enabled, | |
| 366 | + workspaceId: enabled | |
| 367 | + ? workspace.data.workspaceId | |
| 368 | + : PLACEHOLDER_WORKSPACE_ID, | |
| 369 | + }), | |
| 370 | + [enabled, workspace], | |
| 371 | + ); | |
| 372 | +}; | |
| 373 | + | |
| 374 | +export const useExecutorMutation = <TInput, TOutput>( | |
| 375 | + execute: (input: TInput) => Promise<TOutput>, | |
| 659 | 376 | ) => { |
| 660 | − const workspace = useWorkspaceRequestContext(); | |
| 661 | − const { registry, invalidateQueries } = useExecutorQueryContext(); | |
| 662 | − const [state, setState] = React.useState<SourceMutationState<TOutput>>({ | |
| 377 | + const [state, setState] = React.useState<SecretMutationState<TOutput>>({ | |
| 663 | 378 | status: "idle", |
| 664 | 379 | data: null, |
| 665 | 380 | error: null, |
| 666 | 381 | }); |
| 667 | 382 | |
| 668 | 383 | const mutateAsync = React.useCallback(async (payload: TInput) => { |
| 669 | − if (!workspace.enabled) { | |
| 670 | − const error = new Error("Executor workspace context is not ready"); | |
| 671 | − setState({ status: "error", data: null, error }); | |
| 672 | − throw error; | |
| 673 | − } | |
| 674 | − | |
| 675 | − const executionContext: MutationExecutionContext = { | |
| 676 | − workspaceId: workspace.workspaceId, | |
| 677 | − accountId: workspace.accountId, | |
| 678 | − registry, | |
| 679 | − invalidateQueries, | |
| 680 | − }; | |
| 681 | − | |
| 682 | 384 | setState((current) => ({ |
| 683 | 385 | status: "pending", |
| 684 | 386 | data: current.data, |
| 685 | 387 | error: null, |
| 686 | 388 | })); |
| 687 | 389 | |
| 688 | − const optimistic = options?.optimisticUpdate?.(executionContext, payload); | |
| 689 | − const rollback = typeof optimistic === "function" | |
| 690 | − ? optimistic | |
| 691 | − : optimistic?.rollback; | |
| 692 | − const optimisticValue = typeof optimistic === "function" | |
| 693 | − ? undefined | |
| 694 | − : optimistic?.value; | |
| 695 | − | |
| 696 | 390 | try { |
| 697 | − const data = await execute({ | |
| 698 | − workspaceId: workspace.workspaceId, | |
| 699 | − accountId: workspace.accountId, | |
| 700 | − payload, | |
| 701 | − }); | |
| 702 | − options?.onSuccess?.(executionContext, payload, data, optimisticValue); | |
| 391 | + const data = await execute(payload); | |
| 703 | 392 | setState({ status: "success", data, error: null }); |
| 704 | 393 | return data; |
| 705 | 394 | } catch (cause) { |
| 706 | − rollback?.(); | |
| 707 | − logExecutorDevError("source mutation failed", { | |
| 708 | − workspaceId: workspace.workspaceId, | |
| 709 | − accountId: workspace.accountId, | |
| 710 | − payload, | |
| 711 | − error: describeExecutorDevError(cause), | |
| 712 | − cause, | |
| 713 | − }); | |
| 714 | 395 | const error = cause instanceof Error ? cause : new Error(String(cause)); |
| 715 | 396 | setState({ status: "error", data: null, error }); |
| 716 | 397 | throw error; |
| 717 | 398 | } |
| 718 | − }, [execute, invalidateQueries, options, registry, workspace.accountId, workspace.enabled, workspace.workspaceId]); | |
| 399 | + }, [execute]); | |
| 719 | 400 | |
| 720 | 401 | const reset = React.useCallback(() => { |
| 721 | 402 | setState({ status: "idle", data: null, error: null }); |
| @@ -731,184 +412,105 @@ const useSourceMutation = <TInput, TOutput, TOptimistic = never>( · 9 unmodified lines | ||
| 731 | 412 | ); |
| 732 | 413 | }; |
| 733 | 414 | |
| 734 | −const ExecutorReactProviderInner = (props: React.PropsWithChildren) => { | |
| 735 | − const registry = React.useContext(RegistryContext); | |
| 736 | − const activeQueries = React.useMemo(createActiveQueryCollections, []); | |
| 737 | − const invalidateQueries = React.useCallback((target?: InvalidationTarget) => { | |
| 738 | − invalidateTrackedQueries(registry, activeQueries, target); | |
| 739 | − }, [activeQueries, registry]); | |
| 740 | − | |
| 741 | − const value = React.useMemo<ExecutorQueryContextValue>(() => ({ | |
| 742 | − registry, | |
| 743 | − activeQueries, | |
| 744 | − invalidateQueries, | |
| 745 | − }), [activeQueries, invalidateQueries, registry]); | |
| 746 | − | |
| 747 | − return React.createElement(ExecutorQueryContext.Provider, { value }, props.children); | |
| 748 | −}; | |
| 749 | − | |
| 750 | −export const setExecutorApiBaseUrl = (baseUrl: string): void => { | |
| 751 | − apiBaseUrl = baseUrl; | |
| 752 | −}; | |
| 753 | − | |
| 754 | 415 | export const ExecutorReactProvider = (props: React.PropsWithChildren) => |
| 755 | − React.createElement( | |
| 756 | − RegistryProvider, | |
| 757 | − null, | |
| 758 | − React.createElement(ExecutorReactProviderInner, null, props.children), | |
| 759 | − ); | |
| 760 | − | |
| 761 | −export const useInvalidateExecutorQueries = (): (() => void) => { | |
| 762 | − const { invalidateQueries } = useExecutorQueryContext(); | |
| 763 | − return React.useCallback(() => { | |
| 764 | − invalidateQueries(); | |
| 765 | − }, [invalidateQueries]); | |
| 766 | −}; | |
| 416 | + React.createElement(RegistryProvider, null, props.children); | |
| 767 | 417 | |
| 768 | 418 | export const useLocalInstallation = (): Loadable<LocalInstallation> => |
| 769 | − useLoadableAtom(localInstallationAtom(apiBaseUrl)); | |
| 419 | + useLoadableAtom(localInstallationAtom(getExecutorApiBaseUrl())); | |
| 770 | 420 | |
| 771 | 421 | export const useInstanceConfig = (): Loadable<InstanceConfig> => |
| 772 | − useLoadableAtom(instanceConfigAtom(apiBaseUrl)); | |
| 422 | + useLoadableAtom(instanceConfigAtom(getExecutorApiBaseUrl())); | |
| 773 | 423 | |
| 774 | 424 | export const useSecrets = (): Loadable<ReadonlyArray<SecretListItem>> => |
| 775 | − useLoadableAtom(secretsAtom(apiBaseUrl)); | |
| 776 | − | |
| 777 | −export const useRefreshSecrets = (): (() => void) => { | |
| 778 | − const registry = React.useContext(RegistryContext); | |
| 779 | − return React.useCallback(() => { | |
| 780 | − registry.refresh(secretsAtom(apiBaseUrl)); | |
| 781 | − }, [registry]); | |
| 782 | −}; | |
| 783 | − | |
| 784 | −type SecretMutationState<T> = { | |
| 785 | − status: "idle" | "pending" | "success" | "error"; | |
| 786 | − data: T | null; | |
| 787 | − error: Error | null; | |
| 788 | −}; | |
| 789 | − | |
| 790 | −const useSecretMutation = <TInput, TOutput>( | |
| 791 | − execute: (input: TInput) => Promise<TOutput>, | |
| 792 | −) => { | |
| 793 | − const registry = React.useContext(RegistryContext); | |
| 794 | − const [state, setState] = React.useState<SecretMutationState<TOutput>>({ | |
| 795 | − status: "idle", | |
| 796 | − data: null, | |
| 797 | − error: null, | |
| 798 | − }); | |
| 799 | − | |
| 800 | − const mutateAsync = React.useCallback(async (payload: TInput) => { | |
| 801 | − setState((current) => ({ | |
| 802 | − status: "pending", | |
| 803 | − data: current.data, | |
| 804 | − error: null, | |
| 805 | − })); | |
| 806 | − | |
| 807 | − try { | |
| 808 | − const data = await execute(payload); | |
| 809 | − registry.refresh(secretsAtom(apiBaseUrl)); | |
| 810 | − setState({ status: "success", data, error: null }); | |
| 811 | − return data; | |
| 812 | − } catch (cause) { | |
| 813 | − const error = cause instanceof Error ? cause : new Error(String(cause)); | |
| 814 | − setState({ status: "error", data: null, error }); | |
| 815 | − throw error; | |
| 816 | − } | |
| 817 | − }, [execute, registry]); | |
| 425 | + useLoadableAtom(secretsAtom(getExecutorApiBaseUrl())); | |
| 818 | 426 | |
| 819 | − const reset = React.useCallback(() => { | |
| 820 | − setState({ status: "idle", data: null, error: null }); | |
| 821 | − }, []); | |
| 427 | +export const useRefreshSecrets = (): (() => void) => | |
| 428 | + useAtomRefresh(secretsAtom(getExecutorApiBaseUrl())); | |
| 822 | 429 | |
| 823 | − return React.useMemo( | |
| 824 | − () => ({ | |
| 825 | − ...state, | |
| 826 | − mutateAsync, | |
| 827 | − reset, | |
| 828 | − }), | |
| 829 | − [mutateAsync, reset, state], | |
| 430 | +export const useCreateSecret = () => { | |
| 431 | + const mutate = useAtomSet( | |
| 432 | + getExecutorApiHttpClient().mutation("local", "createSecret"), | |
| 433 | + { mode: "promise" }, | |
| 830 | 434 | ); |
| 831 | −}; | |
| 832 | 435 | |
| 833 | −export const useCreateSecret = () => | |
| 834 | − useSecretMutation<CreateSecretPayload, CreateSecretResult>( | |
| 436 | + return useExecutorMutation<CreateSecretPayload, CreateSecretResult>( | |
| 835 | 437 | React.useCallback( |
| 836 | 438 | (payload) => |
| 837 | − runControlPlane({ | |
| 838 | − execute: (client) => client.local.createSecret({ | |
| 839 | − payload, | |
| 840 | − }), | |
| 439 | + mutate({ | |
| 440 | + payload, | |
| 441 | + reactivityKeys: secretsReactivityKey(), | |
| 841 | 442 | }), |
| 842 | − [], | |
| 443 | + [mutate], | |
| 843 | 444 | ), |
| 844 | 445 | ); |
| 446 | +}; | |
| 845 | 447 | |
| 846 | −export const useUpdateSecret = () => | |
| 847 | − useSecretMutation<{ secretId: string; payload: UpdateSecretPayload }, UpdateSecretResult>( | |
| 448 | +export const useUpdateSecret = () => { | |
| 449 | + const mutate = useAtomSet( | |
| 450 | + getExecutorApiHttpClient().mutation("local", "updateSecret"), | |
| 451 | + { mode: "promise" }, | |
| 452 | + ); | |
| 453 | + | |
| 454 | + return useExecutorMutation< | |
| 455 | + { secretId: string; payload: UpdateSecretPayload }, | |
| 456 | + UpdateSecretResult | |
| 457 | + >( | |
| 848 | 458 | React.useCallback( |
| 849 | 459 | (input) => |
| 850 | − runControlPlane({ | |
| 851 | − execute: (client) => client.local.updateSecret({ | |
| 852 | − path: { secretId: input.secretId }, | |
| 853 | − payload: input.payload, | |
| 854 | − }), | |
| 460 | + mutate({ | |
| 461 | + path: { secretId: input.secretId }, | |
| 462 | + payload: input.payload, | |
| 463 | + reactivityKeys: secretsReactivityKey(), | |
| 855 | 464 | }), |
| 856 | − [], | |
| 465 | + [mutate], | |
| 857 | 466 | ), |
| 858 | 467 | ); |
| 468 | +}; | |
| 859 | 469 | |
| 860 | −export const useDeleteSecret = () => | |
| 861 | − useSecretMutation<string, DeleteSecretResult>( | |
| 470 | +export const useDeleteSecret = () => { | |
| 471 | + const mutate = useAtomSet( | |
| 472 | + getExecutorApiHttpClient().mutation("local", "deleteSecret"), | |
| 473 | + { mode: "promise" }, | |
| 474 | + ); | |
| 475 | + | |
| 476 | + return useExecutorMutation<string, DeleteSecretResult>( | |
| 862 | 477 | React.useCallback( |
| 863 | 478 | (secretId) => |
| 864 | − runControlPlane({ | |
| 865 | − execute: (client) => client.local.deleteSecret({ | |
| 866 | − path: { secretId }, | |
| 867 | − }), | |
| 479 | + mutate({ | |
| 480 | + path: { secretId }, | |
| 481 | + reactivityKeys: secretsReactivityKey(), | |
| 868 | 482 | }), |
| 869 | − [], | |
| 483 | + [mutate], | |
| 870 | 484 | ), |
| 871 | 485 | ); |
| 486 | +}; | |
| 872 | 487 | |
| 873 | 488 | export const useSources = (): Loadable<ReadonlyArray<Source>> => { |
| 874 | 489 | const workspace = useWorkspaceRequestContext(); |
| 875 | − const key = encodeSourcesKey(workspace.enabled, workspace.workspaceId, workspace.accountId); | |
| 876 | − useTrackActiveKey("sourceLists", key, workspace.enabled); | |
| 877 | − const sources = useLoadableAtom(sourcesAtom(key)); | |
| 490 | + const atom = workspace.enabled | |
| 491 | + ? sourcesAtom(workspace.workspaceId) | |
| 492 | + : disabledAtom<ReadonlyArray<Source>>(); | |
| 493 | + const sources = useLoadableAtom(atom); | |
| 878 | 494 | |
| 879 | 495 | return workspace.enabled ? sources : pendingLoadable(workspace.workspace); |
| 880 | 496 | }; |
| 881 | 497 | |
| 882 | 498 | export const useSource = (sourceId: string): Loadable<Source> => { |
| 883 | 499 | const workspace = useWorkspaceRequestContext(); |
| 884 | − const requestedSourceId = workspace.enabled | |
| 885 | − ? (sourceId as Source["id"]) | |
| 886 | − : PLACEHOLDER_SOURCE_ID; | |
| 887 | − const key = encodeSourceKey( | |
| 888 | − workspace.enabled, | |
| 889 | − workspace.workspaceId, | |
| 890 | − workspace.accountId, | |
| 891 | − requestedSourceId, | |
| 892 | − ); | |
| 893 | − useTrackActiveKey("sources", key, workspace.enabled); | |
| 894 | − const source = useLoadableAtom(sourceAtom(key)); | |
| 500 | + const atom = workspace.enabled | |
| 501 | + ? sourceAtom(workspace.workspaceId, sourceId as Source["id"]) | |
| 502 | + : disabledAtom<Source>(); | |
| 503 | + const source = useLoadableAtom(atom); | |
| 895 | 504 | |
| 896 | 505 | return workspace.enabled ? source : pendingLoadable(workspace.workspace); |
| 897 | 506 | }; |
| 898 | 507 | |
| 899 | 508 | export const useSourceInspection = (sourceId: string): Loadable<SourceInspection> => { |
| 900 | 509 | const workspace = useWorkspaceRequestContext(); |
| 901 | − const requestedSourceId = workspace.enabled | |
| 902 | − ? (sourceId as Source["id"]) | |
| 903 | − : PLACEHOLDER_SOURCE_ID; | |
| 904 | − const key = encodeSourceKey( | |
| 905 | − workspace.enabled, | |
| 906 | − workspace.workspaceId, | |
| 907 | − workspace.accountId, | |
| 908 | − requestedSourceId, | |
| 909 | − ); | |
| 910 | − useTrackActiveKey("inspections", key, workspace.enabled); | |
| 911 | − const inspection = useLoadableAtom(sourceInspectionAtom(key)); | |
| 510 | + const atom = workspace.enabled | |
| 511 | + ? sourceInspectionAtom(workspace.workspaceId, sourceId as Source["id"]) | |
| 512 | + : disabledAtom<SourceInspection>(); | |
| 513 | + const inspection = useLoadableAtom(atom); | |
| 912 | 514 | |
| 913 | 515 | return workspace.enabled ? inspection : pendingLoadable(workspace.workspace); |
| 914 | 516 | }; |
| @@ -918,18 +520,14 @@ export const useSourceToolDetail = ( · 3 unmodified lines | ||
| 918 | 520 | toolPath: string | null, |
| 919 | 521 | ): Loadable<SourceInspectionToolDetail | null> => { |
| 920 | 522 | const workspace = useWorkspaceRequestContext(); |
| 921 | − const requestedSourceId = workspace.enabled | |
| 922 | − ? (sourceId as Source["id"]) | |
| 923 | − : PLACEHOLDER_SOURCE_ID; | |
| 924 | − const key = encodeToolDetailKey( | |
| 925 | − workspace.enabled, | |
| 926 | − workspace.workspaceId, | |
| 927 | − workspace.accountId, | |
| 928 | − requestedSourceId, | |
| 929 | − toolPath, | |
| 930 | − ); | |
| 931 | − useTrackActiveKey("toolDetails", key, workspace.enabled && toolPath !== null); | |
| 932 | − const detail = useLoadableAtom(sourceInspectionToolAtom(key)); | |
| 523 | + const atom = workspace.enabled | |
| 524 | + ? sourceInspectionToolAtom( | |
| 525 | + workspace.workspaceId, | |
| 526 | + sourceId as Source["id"], | |
| 527 | + toolPath, | |
| 528 | + ) | |
| 529 | + : disabledAtom<SourceInspectionToolDetail | null>(); | |
| 530 | + const detail = useLoadableAtom(atom); | |
| 933 | 531 | |
| 934 | 532 | return workspace.enabled ? detail : pendingLoadable(workspace.workspace); |
| 935 | 533 | }; |
| @@ -940,19 +538,15 @@ export const useSourceDiscovery = (input: { · 4 unmodified lines | ||
| 940 | 538 | limit?: number; |
| 941 | 539 | }): Loadable<SourceInspectionDiscoverResult> => { |
| 942 | 540 | const workspace = useWorkspaceRequestContext(); |
| 943 | − const requestedSourceId = workspace.enabled | |
| 944 | − ? (input.sourceId as Source["id"]) | |
| 945 | − : PLACEHOLDER_SOURCE_ID; | |
| 946 | − const key = encodeDiscoveryKey( | |
| 947 | − workspace.enabled, | |
| 948 | − workspace.workspaceId, | |
| 949 | − workspace.accountId, | |
| 950 | − requestedSourceId, | |
| 951 | − input.query, | |
| 952 | − input.limit ?? null, | |
| 953 | − ); | |
| 954 | − useTrackActiveKey("discoveries", key, workspace.enabled); | |
| 955 | − const results = useLoadableAtom(sourceDiscoveryAtom(key)); | |
| 541 | + const atom = workspace.enabled | |
| 542 | + ? sourceDiscoveryAtom( | |
| 543 | + workspace.workspaceId, | |
| 544 | + input.sourceId as Source["id"], | |
| 545 | + input.query, | |
| 546 | + input.limit ?? null, | |
| 547 | + ) | |
| 548 | + : disabledAtom<SourceInspectionDiscoverResult>(); | |
| 549 | + const results = useLoadableAtom(atom); | |
| 956 | 550 | |
| 957 | 551 | return workspace.enabled ? results : pendingLoadable(workspace.workspace); |
| 958 | 552 | }; |
| @@ -963,184 +557,74 @@ export const usePrefetchToolDetail = () => { · 4 unmodified lines | ||
| 963 | 557 | |
| 964 | 558 | return React.useCallback( |
| 965 | 559 | (sourceId: string, toolPath: string): (() => void) => { |
| 966 | − if (!workspace.enabled) return () => {}; | |
| 967 | − const requestedSourceId = sourceId as Source["id"]; | |
| 968 | − const atom = sourceInspectionToolAtom( | |
| 969 | − encodeToolDetailKey( | |
| 970 | − workspace.enabled, | |
| 560 | + if (!workspace.enabled) { | |
| 561 | + return () => {}; | |
| 562 | + } | |
| 563 | + | |
| 564 | + return registry.mount( | |
| 565 | + sourceInspectionToolAtom( | |
| 971 | 566 | workspace.workspaceId, |
| 972 | − workspace.accountId, | |
| 973 | − requestedSourceId, | |
| 567 | + sourceId as Source["id"], | |
| 974 | 568 | toolPath, |
| 975 | 569 | ), |
| 976 | 570 | ); |
| 977 | − return registry.mount(atom); | |
| 978 | 571 | }, |
| 979 | − [registry, workspace.accountId, workspace.enabled, workspace.workspaceId], | |
| 572 | + [registry, workspace.enabled, workspace.workspaceId], | |
| 980 | 573 | ); |
| 981 | 574 | }; |
| 982 | 575 | |
| 983 | −export const useCreateSource = () => | |
| 984 | − useSourceMutation<CreateSourcePayload, Source, Source>( | |
| 985 | − React.useCallback( | |
| 986 | − ({ workspaceId, accountId, payload }) => | |
| 987 | − runControlPlane({ | |
| 988 | − accountId, | |
| 989 | − execute: (client) => client.sources.create({ | |
| 990 | − path: { | |
| 991 | − workspaceId, | |
| 992 | − }, | |
| 993 | − payload, | |
| 994 | − }), | |
| 995 | − }), | |
| 996 | − [], | |
| 997 | − ), | |
| 998 | − { | |
| 999 | − optimisticUpdate: (context, payload) => { | |
| 1000 | − const listAtom = sourcesAtom(encodeSourcesKey(true, context.workspaceId, context.accountId)); | |
| 1001 | − const previousList = getCachedAtomValue(context.registry, listAtom); | |
| 1002 | − if (previousList === undefined) { | |
| 1003 | − return; | |
| 1004 | − } | |
| 1005 | − | |
| 1006 | − const optimisticSource = createOptimisticSource({ | |
| 1007 | − workspaceId: context.workspaceId, | |
| 1008 | − payload, | |
| 1009 | − }); | |
| 1010 | − setCachedAtomValue(context.registry, listAtom, [optimisticSource, ...previousList]); | |
| 1011 | − return { | |
| 1012 | − value: optimisticSource, | |
| 1013 | − rollback: () => { | |
| 1014 | − setCachedAtomValue(context.registry, listAtom, previousList); | |
| 1015 | − }, | |
| 1016 | − }; | |
| 1017 | − }, | |
| 1018 | − onSuccess: (context, _payload, source, optimisticSource) => { | |
| 1019 | − const listAtom = sourcesAtom(encodeSourcesKey(true, context.workspaceId, context.accountId)); | |
| 1020 | − const currentList = getCachedAtomValue(context.registry, listAtom); | |
| 1021 | − if (currentList !== undefined) { | |
| 1022 | − const withoutOptimistic = optimisticSource | |
| 1023 | − ? currentList.filter((candidate) => candidate.id !== optimisticSource.id) | |
| 1024 | − : currentList; | |
| 1025 | − setCachedAtomValue(context.registry, listAtom, upsertSourceInList(withoutOptimistic, source)); | |
| 1026 | − } | |
| 1027 | − | |
| 1028 | − setCachedAtomValue( | |
| 1029 | − context.registry, | |
| 1030 | − sourceAtom(encodeSourceKey(true, context.workspaceId, context.accountId, source.id)), | |
| 1031 | − source, | |
| 1032 | − ); | |
| 1033 | − context.invalidateQueries({ | |
| 1034 | − workspaceId: context.workspaceId, | |
| 1035 | − accountId: context.accountId, | |
| 1036 | − }); | |
| 1037 | − }, | |
| 1038 | − }, | |
| 576 | +export const useRemoveSource = () => { | |
| 577 | + const workspace = useWorkspaceRequestContext(); | |
| 578 | + const mutate = useAtomSet( | |
| 579 | + getExecutorApiHttpClient().mutation("sources", "remove"), | |
| 580 | + { mode: "promise" }, | |
| 1039 | 581 | ); |
| 1040 | 582 | |
| 1041 | −export const useUpdateSource = () => | |
| 1042 | − useSourceMutation<{ sourceId: Source["id"]; payload: UpdateSourcePayload }, Source>( | |
| 583 | + return useExecutorMutation<Source["id"], SourceRemoveResult>( | |
| 1043 | 584 | React.useCallback( |
| 1044 | − ({ workspaceId, accountId, payload }) => | |
| 1045 | − runControlPlane({ | |
| 1046 | − accountId, | |
| 1047 | − execute: (client) => client.sources.update({ | |
| 1048 | − path: { | |
| 1049 | − workspaceId, | |
| 1050 | − sourceId: payload.sourceId, | |
| 1051 | − }, | |
| 1052 | − payload: payload.payload, | |
| 1053 | − }), | |
| 1054 | − }), | |
| 1055 | − [], | |
| 1056 | − ), | |
| 1057 | − { | |
| 1058 | − optimisticUpdate: (context, input) => { | |
| 1059 | − const listAtom = sourcesAtom(encodeSourcesKey(true, context.workspaceId, context.accountId)); | |
| 1060 | − const detailAtom = sourceAtom(encodeSourceKey(true, context.workspaceId, context.accountId, input.sourceId)); | |
| 1061 | − const previousList = getCachedAtomValue(context.registry, listAtom); | |
| 1062 | − const previousSource = getCachedAtomValue(context.registry, detailAtom) | |
| 1063 | − ?? previousList?.find((source) => source.id === input.sourceId); | |
| 1064 | − if (previousSource === undefined) { | |
| 1065 | − return; | |
| 585 | + (sourceId) => { | |
| 586 | + if (!workspace.enabled) { | |
| 587 | + return Promise.reject( | |
| 588 | + new Error("Executor workspace context is not ready"), | |
| 589 | + ); | |
| 1066 | 590 | } |
| 1067 | 591 | |
| 1068 | − const optimisticSource = applyUpdatePayloadToSource(previousSource, input.payload); | |
| 1069 | − if (previousList !== undefined) { | |
| 1070 | − setCachedAtomValue(context.registry, listAtom, upsertSourceInList(previousList, optimisticSource)); | |
| 1071 | − } | |
| 1072 | − setCachedAtomValue(context.registry, detailAtom, optimisticSource); | |
| 1073 | − | |
| 1074 | − return () => { | |
| 1075 | − if (previousList !== undefined) { | |
| 1076 | − setCachedAtomValue(context.registry, listAtom, previousList); | |
| 1077 | − } | |
| 1078 | − setCachedAtomValue(context.registry, detailAtom, previousSource); | |
| 1079 | − }; | |
| 1080 | − }, | |
| 1081 | − onSuccess: (context, input, source) => { | |
| 1082 | − const listAtom = sourcesAtom(encodeSourcesKey(true, context.workspaceId, context.accountId)); | |
| 1083 | − const detailAtom = sourceAtom(encodeSourceKey(true, context.workspaceId, context.accountId, input.sourceId)); | |
| 1084 | − const currentList = getCachedAtomValue(context.registry, listAtom); | |
| 1085 | − if (currentList !== undefined) { | |
| 1086 | − setCachedAtomValue(context.registry, listAtom, upsertSourceInList(currentList, source)); | |
| 1087 | − } | |
| 1088 | − setCachedAtomValue(context.registry, detailAtom, source); | |
| 1089 | − context.invalidateQueries({ | |
| 1090 | − workspaceId: context.workspaceId, | |
| 1091 | − accountId: context.accountId, | |
| 1092 | − sourceId: input.sourceId, | |
| 592 | + return mutate({ | |
| 593 | + path: { | |
| 594 | + workspaceId: workspace.workspaceId, | |
| 595 | + sourceId, | |
| 596 | + }, | |
| 597 | + reactivityKeys: { | |
| 598 | + ...sourcesReactivityKey(workspace.workspaceId), | |
| 599 | + ...sourceReactivityKey(workspace.workspaceId, sourceId), | |
| 600 | + ...sourceInspectionReactivityKey(workspace.workspaceId, sourceId), | |
| 601 | + ...sourceInspectionToolReactivityKey(workspace.workspaceId, sourceId), | |
| 602 | + ...sourceDiscoveryReactivityKey(workspace.workspaceId, sourceId), | |
| 603 | + }, | |
| 1093 | 604 | }); |
| 1094 | 605 | }, |
| 1095 | − }, | |
| 1096 | − ); | |
| 1097 | − | |
| 1098 | −export const useRemoveSource = () => | |
| 1099 | − useSourceMutation<Source["id"], SourceRemoveResult>( | |
| 1100 | − React.useCallback( | |
| 1101 | − ({ workspaceId, accountId, payload }) => | |
| 1102 | − runControlPlane({ | |
| 1103 | − accountId, | |
| 1104 | − execute: (client) => client.sources.remove({ | |
| 1105 | − path: { | |
| 1106 | − workspaceId, | |
| 1107 | − sourceId: payload, | |
| 1108 | − }, | |
| 1109 | − }), | |
| 1110 | − }), | |
| 1111 | − [], | |
| 606 | + [mutate, workspace.enabled, workspace.workspaceId], | |
| 1112 | 607 | ), |
| 1113 | − { | |
| 1114 | − optimisticUpdate: (context, sourceId) => { | |
| 1115 | − const listAtom = sourcesAtom(encodeSourcesKey(true, context.workspaceId, context.accountId)); | |
| 1116 | − const previousList = getCachedAtomValue(context.registry, listAtom); | |
| 1117 | − if (previousList === undefined) { | |
| 1118 | − return; | |
| 1119 | − } | |
| 1120 | − | |
| 1121 | − setCachedAtomValue(context.registry, listAtom, removeSourceFromList(previousList, sourceId)); | |
| 1122 | − return () => { | |
| 1123 | − setCachedAtomValue(context.registry, listAtom, previousList); | |
| 1124 | − }; | |
| 1125 | − }, | |
| 1126 | − onSuccess: (context, sourceId) => { | |
| 1127 | − context.invalidateQueries({ | |
| 1128 | − workspaceId: context.workspaceId, | |
| 1129 | − accountId: context.accountId, | |
| 1130 | − sourceId, | |
| 1131 | − }); | |
| 1132 | − }, | |
| 1133 | − }, | |
| 1134 | 608 | ); |
| 609 | +}; | |
| 610 | + | |
| 611 | +export { | |
| 612 | + Atom, | |
| 613 | + AtomHttpApi, | |
| 614 | + RegistryContext, | |
| 615 | + RegistryProvider, | |
| 616 | + Result, | |
| 617 | + useAtomRefresh, | |
| 618 | + useAtomSet, | |
| 619 | + useAtomValue, | |
| 620 | +}; | |
| 1135 | 621 | |
| 1136 | 622 | export type { |
| 1137 | 623 | CreateSecretPayload, |
| 1138 | 624 | CreateSecretResult, |
| 1139 | − CreateSourcePayload, | |
| 1140 | 625 | DeleteSecretResult, |
| 1141 | 626 | InstanceConfig, |
| 1142 | 627 | LocalInstallation, |
| 1143 | − | |
| 1144 | 628 | SecretListItem, |
| 1145 | 629 | Source, |
| 1146 | 630 | SourceInspection, |
| @@ -1148,5 +632,4 @@ export type { · 1 unmodified line | ||
| 1148 | 632 | SourceInspectionToolDetail, |
| 1149 | 633 | UpdateSecretPayload, |
| 1150 | 634 | UpdateSecretResult, |
| 1151 | − UpdateSourcePayload, | |
| 1152 | 635 | }; |
| @@ -6,7 +6,6 @@ import { · 5 unmodified lines | ||
| 6 | 6 | RuntimeSourceCatalogStoreService, |
| 7 | 7 | createExecution, |
| 8 | 8 | getExecution, |
| 9 | − hasRegisteredExecutorAddableSourceAdapters, | |
| 10 | 9 | resumeExecution, |
| 11 | 10 | type ExecutorRuntime, |
| 12 | 11 | } from "@executor/platform-sdk/runtime"; |
| @@ -173,16 +172,9 @@ const buildExecuteWorkflowText = ( · 160 unmodified lines | ||
| 173 | 172 | '1) const matches = await tools.discover({ query: "<intent>", limit: 12 });', |
| 174 | 173 | "2) const details = await tools.describe.tool({ path, includeSchemas: true });", |
| 175 | 174 | "3) Call selected tools.<path>(input).", |
| 176 | − ...(hasRegisteredExecutorAddableSourceAdapters | |
| 177 | − ? [ | |
| 178 | − "4) To connect a source plugin, call tools.executor.sources.add(...).", | |
| 179 | − ...EXECUTOR_SOURCES_ADD_HELP_LINES, | |
| 180 | − "5) If execution pauses for interaction, resume it with the returned resumePayload or the available resume flow.", | |
| 181 | − ] | |
| 182 | − : [ | |
| 183 | − "4) Source plugins are not registered in this build.", | |
| 184 | − "5) If execution pauses for interaction, resume it with the returned resumePayload or the available resume flow.", | |
| 185 | − ]), | |
| 175 | + "4) Source plugins are not registered in this build.", | |
| 176 | + ...EXECUTOR_SOURCES_ADD_HELP_LINES, | |
| 177 | + "5) If execution pauses for interaction, resume it with the returned resumePayload or the available resume flow.", | |
| 186 | 178 | "Do not use fetch; use tools.* only.", |
| 187 | 179 | ].join("\n"); |
| 188 | 180 | |
| @@ -1,101 +0,0 @@ | ||
| 1 | −import { describe, expect, it } from "@effect/vitest"; | |
| 2 | −import type { | |
| 3 | − ExecutionEnvelope, | |
| 4 | − ExecutionInteraction, | |
| 5 | −} from "@executor/platform-sdk/schema"; | |
| 6 | − | |
| 7 | −import { | |
| 8 | − buildPausedResultText, | |
| 9 | − parseInteractionPayload, | |
| 10 | −} from "./paused-result"; | |
| 11 | − | |
| 12 | −const makeInteraction = (patch: Partial<ExecutionInteraction> = {}): ExecutionInteraction => ({ | |
| 13 | − id: "exec_123:source_connect_oauth2:call_1" as never, | |
| 14 | − executionId: "exec_123" as never, | |
| 15 | − status: "pending", | |
| 16 | − kind: "url", | |
| 17 | − purpose: "source_connect_oauth2", | |
| 18 | − payloadJson: JSON.stringify({ | |
| 19 | − elicitation: { | |
| 20 | − mode: "url", | |
| 21 | − message: "Finish connecting Axiom", | |
| 22 | − url: "https://mcp.axiom.co/authorize", | |
| 23 | − elicitationId: "oauth-session-123", | |
| 24 | − }, | |
| 25 | − }), | |
| 26 | − responseJson: null, | |
| 27 | − responsePrivateJson: null, | |
| 28 | − createdAt: 1, | |
| 29 | − updatedAt: 1, | |
| 30 | − ...patch, | |
| 31 | −}); | |
| 32 | − | |
| 33 | −const makeEnvelope = ( | |
| 34 | − patch: Partial<ExecutionEnvelope> = {}, | |
| 35 | −): ExecutionEnvelope => ({ | |
| 36 | − execution: { | |
| 37 | − id: "exec_123" as never, | |
| 38 | − scopeId: "ws_123" as never, | |
| 39 | − createdByScopeId: "acct_123" as never, | |
| 40 | − status: "waiting_for_interaction", | |
| 41 | − code: "return await tools.executor.sources.add({ endpoint: 'https://mcp.axiom.co/mcp' });", | |
| 42 | − resultJson: null, | |
| 43 | − errorText: null, | |
| 44 | − logsJson: null, | |
| 45 | − startedAt: 1, | |
| 46 | − completedAt: null, | |
| 47 | − createdAt: 1, | |
| 48 | − updatedAt: 1, | |
| 49 | − }, | |
| 50 | − pendingInteraction: makeInteraction(), | |
| 51 | − ...patch, | |
| 52 | −}); | |
| 53 | − | |
| 54 | −describe("paused-result", () => { | |
| 55 | − it("parses the browser URL from a paused interaction payload", () => { | |
| 56 | − const parsed = parseInteractionPayload(makeInteraction()); | |
| 57 | − | |
| 58 | − expect(parsed).not.toBeNull(); | |
| 59 | − expect(parsed?.mode).toBe("url"); | |
| 60 | − expect(parsed?.url).toBe("https://mcp.axiom.co/authorize"); | |
| 61 | − expect(parsed?.elicitationId).toBe("oauth-session-123"); | |
| 62 | − }); | |
| 63 | − | |
| 64 | − it("includes URL and resume instructions in the paused text for browser auth", () => { | |
| 65 | − const text = buildPausedResultText(makeEnvelope()); | |
| 66 | − | |
| 67 | − expect(text).toContain("Finish connecting Axiom"); | |
| 68 | − expect(text).toContain("Open this URL in a browser:"); | |
| 69 | − expect(text).toContain("https://mcp.axiom.co/authorize"); | |
| 70 | − expect(text).toContain("executor.resume"); | |
| 71 | − expect(text).toContain('"executionId": "exec_123"'); | |
| 72 | − }); | |
| 73 | − | |
| 74 | − it("includes resume guidance for form interactions", () => { | |
| 75 | − const text = buildPausedResultText( | |
| 76 | − makeEnvelope({ | |
| 77 | − pendingInteraction: makeInteraction({ | |
| 78 | − kind: "form", | |
| 79 | − purpose: "tool_execution_gate", | |
| 80 | − payloadJson: JSON.stringify({ | |
| 81 | − elicitation: { | |
| 82 | − mode: "form", | |
| 83 | − message: "Approve the tool call", | |
| 84 | − requestedSchema: { | |
| 85 | − type: "object", | |
| 86 | − properties: { | |
| 87 | − approve: { type: "boolean" }, | |
| 88 | − }, | |
| 89 | − required: ["approve"], | |
| 90 | − }, | |
| 91 | − }, | |
| 92 | − }), | |
| 93 | − }), | |
| 94 | − }), | |
| 95 | − ); | |
| 96 | − | |
| 97 | − expect(text).toContain("Approve the tool call"); | |
| 98 | − expect(text).toContain("include a response object matching the requested schema"); | |
| 99 | − expect(text).toContain('"executionId": "exec_123"'); | |
| 100 | − }); | |
| 101 | −}); | |
| @@ -448,9 +448,9 @@ export function toolDescriptorsFromTools(input: { · 447 unmodified lines | ||
| 448 | 448 | interaction: metadata?.interaction, |
| 449 | 449 | elicitation: metadata?.elicitation, |
| 450 | 450 | contract, |
| 451 | − ...(metadata?.providerKind ? { providerKind: metadata.providerKind } : {}), | |
| 452 | − ...(metadata?.providerData !== undefined | |
| 453 | − ? { providerData: metadata.providerData } | |
| 451 | + ...(metadata?.pluginKind ? { pluginKind: metadata.pluginKind } : {}), | |
| 452 | + ...(metadata?.pluginData !== undefined | |
| 453 | + ? { pluginData: metadata.pluginData } | |
| 454 | 454 | : {}), |
| 455 | 455 | } satisfies ToolDescriptor; |
| 456 | 456 | }); |
| @@ -98,8 +98,8 @@ export type ToolMetadata = { · 97 unmodified lines | ||
| 98 | 98 | elicitation?: ElicitationRequest; |
| 99 | 99 | contract?: ToolContract; |
| 100 | 100 | sourceKey?: string; |
| 101 | − providerKind?: string; | |
| 102 | − providerData?: unknown; | |
| 101 | + pluginKind?: string; | |
| 102 | + pluginData?: unknown; | |
| 103 | 103 | }; |
| 104 | 104 | |
| 105 | 105 | export type ToolExecutionContext = { |
| @@ -145,8 +145,8 @@ export type ToolDescriptor = { · 39 unmodified lines | ||
| 145 | 145 | interaction?: "auto" | "required"; |
| 146 | 146 | elicitation?: ElicitationRequest; |
| 147 | 147 | contract?: ToolContract; |
| 148 | − providerKind?: string; | |
| 149 | − providerData?: unknown; | |
| 148 | + pluginKind?: string; | |
| 149 | + pluginData?: unknown; | |
| 150 | 150 | }; |
| 151 | 151 | |
| 152 | 152 | export const ToolDescriptorSchema = Schema.Struct({ |
| @@ -158,8 +158,8 @@ export const ToolDescriptorSchema = Schema.Struct({ · 5 unmodified lines | ||
| 158 | 158 | ), |
| 159 | 159 | elicitation: Schema.optional(Schema.Unknown), |
| 160 | 160 | contract: Schema.optional(ToolContractSchema), |
| 161 | − providerKind: Schema.optional(Schema.String), | |
| 162 | − providerData: Schema.optional(Schema.Unknown), | |
| 161 | + pluginKind: Schema.optional(Schema.String), | |
| 162 | + pluginData: Schema.optional(Schema.Unknown), | |
| 163 | 163 | }); |
| 164 | 164 | |
| 165 | 165 | export type ToolNamespace = { |
| @@ -845,7 +845,7 @@ const searchDoc = ( · 844 unmodified lines | ||
| 845 | 845 | capability.executableIds |
| 846 | 846 | .map((executableId: ExecutableId) => |
| 847 | 847 | catalog.executables[executableId]?.display?.protocol |
| 848 | − ?? catalog.executables[executableId]?.adapterKey | |
| 848 | + ?? catalog.executables[executableId]?.pluginKey | |
| 849 | 849 | ) |
| 850 | 850 | .filter((protocol): protocol is string => protocol !== undefined), |
| 851 | 851 | ), |
| @@ -158,7 +158,7 @@ export const EntityBaseSchema = Schema.Struct({ · 157 unmodified lines | ||
| 158 | 158 | |
| 159 | 159 | export const ImportMetadataSchema = Schema.Struct({ |
| 160 | 160 | sourceKind: SourceKindSchema, |
| 161 | − adapterKey: Schema.String, | |
| 161 | + pluginKey: Schema.String, | |
| 162 | 162 | importerVersion: Schema.String, |
| 163 | 163 | importedAt: Schema.String, |
| 164 | 164 | sourceConfigHash: Schema.String, |
| @@ -696,7 +696,7 @@ export const ExecutableSchema = Schema.extend( · 531 unmodified lines | ||
| 696 | 696 | id: ExecutableIdSchema, |
| 697 | 697 | capabilityId: CapabilityIdSchema, |
| 698 | 698 | scopeId: ScopeIdSchema, |
| 699 | − adapterKey: Schema.String, | |
| 699 | + pluginKey: Schema.String, | |
| 700 | 700 | bindingVersion: Schema.Number, |
| 701 | 701 | binding: Schema.Unknown, |
| 702 | 702 | projection: ExecutableProjectionSchema, |
| @@ -5,9 +5,9 @@ · 4 unmodified lines | ||
| 5 | 5 | "exports": { |
| 6 | 6 | ".": "./src/index.ts", |
| 7 | 7 | "./api": "./src/api.ts", |
| 8 | − "./client": "./src/client.ts", | |
| 9 | 8 | "./effect": "./src/effect.ts", |
| 10 | 9 | "./http": "./src/http.ts", |
| 10 | + "./plugins": "./src/plugins.ts", | |
| 11 | 11 | "./errors": "./src/errors.ts", |
| 12 | 12 | "./local/api": "./src/local/api.ts", |
| 13 | 13 | "./local/http": "./src/local/http.ts", |
| @@ -1,11 +1,17 @@ | ||
| 1 | 1 | import { HttpApi, OpenApi } from "@effect/platform"; |
| 2 | +import type { HttpApiGroup } from "@effect/platform"; | |
| 2 | 3 | |
| 3 | 4 | import { ExecutionsApi } from "./executions/api"; |
| 4 | 5 | import { LocalApi } from "./local/api"; |
| 5 | 6 | import { PoliciesApi } from "./policies/api"; |
| 6 | 7 | import { SourcesApi } from "./sources/api"; |
| 8 | +import type { | |
| 9 | + ExecutorHttpApiExtension, | |
| 10 | + ExecutorHttpPlugin, | |
| 11 | + ExecutorHttpPluginGroups, | |
| 12 | +} from "./plugins"; | |
| 7 | 13 | |
| 8 | −export class ExecutorApi extends HttpApi.make("executor") | |
| 14 | +export const CoreExecutorApi = HttpApi.make("executor") | |
| 9 | 15 | .add(LocalApi) |
| 10 | 16 | .add(SourcesApi) |
| 11 | 17 | .add(PoliciesApi) |
| @@ -15,6 +21,54 @@ export class ExecutorApi extends HttpApi.make("executor") · 3 unmodified lines | ||
| 15 | 21 | title: "Executor API", |
| 16 | 22 | description: "Local-first API for workspace sources, policies, auth, and execution", |
| 17 | 23 | }), |
| 18 | − ) {} | |
| 24 | + ); | |
| 19 | 25 | |
| 20 | −export const executorOpenApiSpec = OpenApi.fromApi(ExecutorApi); | |
| 26 | +type HttpApiGroupsOf<TApi> = TApi extends HttpApi.HttpApi<any, infer TGroups, any, any> | |
| 27 | + ? TGroups | |
| 28 | + : never; | |
| 29 | +type HttpApiErrorOf<TApi> = TApi extends HttpApi.HttpApi<any, any, infer TError, any> | |
| 30 | + ? TError | |
| 31 | + : never; | |
| 32 | +type HttpApiContextOf<TApi> = TApi extends HttpApi.HttpApi<any, any, any, infer TContext> | |
| 33 | + ? TContext | |
| 34 | + : never; | |
| 35 | + | |
| 36 | +export type CoreExecutorApiGroups = HttpApiGroupsOf<typeof CoreExecutorApi>; | |
| 37 | +export type ExecutorApiWithPlugins< | |
| 38 | + TPlugins extends readonly ExecutorHttpApiExtension[] = [], | |
| 39 | +> = HttpApi.HttpApi< | |
| 40 | + "executor", | |
| 41 | + CoreExecutorApiGroups | ExecutorHttpPluginGroups<TPlugins>, | |
| 42 | + HttpApiErrorOf<typeof CoreExecutorApi>, | |
| 43 | + HttpApiContextOf<typeof CoreExecutorApi> | |
| 44 | +>; | |
| 45 | + | |
| 46 | +export const createExecutorApi = < | |
| 47 | + const TPlugins extends readonly ExecutorHttpApiExtension[] = [], | |
| 48 | +>( | |
| 49 | + options: { | |
| 50 | + plugins?: TPlugins; | |
| 51 | + } = {}, | |
| 52 | +): ExecutorApiWithPlugins<TPlugins> => | |
| 53 | + (options.plugins ?? []).reduce( | |
| 54 | + (api, plugin) => | |
| 55 | + api.add(plugin.group as HttpApiGroup.HttpApiGroup.Any), | |
| 56 | + CoreExecutorApi as HttpApi.HttpApi< | |
| 57 | + "executor", | |
| 58 | + CoreExecutorApiGroups | ExecutorHttpPluginGroups<TPlugins>, | |
| 59 | + HttpApiErrorOf<typeof CoreExecutorApi>, | |
| 60 | + HttpApiContextOf<typeof CoreExecutorApi> | |
| 61 | + >, | |
| 62 | + ); | |
| 63 | + | |
| 64 | +export const ExecutorApi = createExecutorApi(); | |
| 65 | + | |
| 66 | +export const createExecutorOpenApiSpec = < | |
| 67 | + const TPlugins extends readonly ExecutorHttpPlugin[] = [], | |
| 68 | +>( | |
| 69 | + options: { | |
| 70 | + plugins?: TPlugins; | |
| 71 | + } = {}, | |
| 72 | +) => OpenApi.fromApi(createExecutorApi(options)); | |
| 73 | + | |
| 74 | +export const executorOpenApiSpec = createExecutorOpenApiSpec(); | |
| @@ -1,134 +0,0 @@ | ||
| 1 | −import * as Effect from "effect/Effect"; | |
| 2 | − | |
| 3 | −import { | |
| 4 | − createExecutorApiEffectClient, | |
| 5 | − type ExecutorApiEffectClient, | |
| 6 | −} from "./effect"; | |
| 7 | − | |
| 8 | −type StripResponse<T> = T extends readonly [infer Value, unknown] ? Value : T; | |
| 9 | −type RemoveWithResponse<T> = T extends object ? Omit<T, "withResponse"> : T; | |
| 10 | −type MethodInput<F extends (input: any) => Effect.Effect<any, any, any>> = RemoveWithResponse< | |
| 11 | − Parameters<F>[0] | |
| 12 | −>; | |
| 13 | −type MethodOutput<F extends (input: any) => Effect.Effect<any, any, any>> = StripResponse< | |
| 14 | − Effect.Effect.Success<ReturnType<F>> | |
| 15 | −>; | |
| 16 | −type PromiseMethod<F extends (input: any) => Effect.Effect<any, any, any>> = ( | |
| 17 | − input: MethodInput<F>, | |
| 18 | −) => Promise<MethodOutput<F>>; | |
| 19 | − | |
| 20 | −export type ExecutorApiClient = { | |
| 21 | − local: { | |
| 22 | − installation: PromiseMethod<ExecutorApiEffectClient["local"]["installation"]>; | |
| 23 | − config: PromiseMethod<ExecutorApiEffectClient["local"]["config"]>; | |
| 24 | − listSecrets: PromiseMethod<ExecutorApiEffectClient["local"]["listSecrets"]>; | |
| 25 | − createSecret: PromiseMethod<ExecutorApiEffectClient["local"]["createSecret"]>; | |
| 26 | − updateSecret: PromiseMethod<ExecutorApiEffectClient["local"]["updateSecret"]>; | |
| 27 | − deleteSecret: PromiseMethod<ExecutorApiEffectClient["local"]["deleteSecret"]>; | |
| 28 | − }; | |
| 29 | − policies: { | |
| 30 | − list: PromiseMethod<ExecutorApiEffectClient["policies"]["list"]>; | |
| 31 | − create: PromiseMethod<ExecutorApiEffectClient["policies"]["create"]>; | |
| 32 | − get: PromiseMethod<ExecutorApiEffectClient["policies"]["get"]>; | |
| 33 | − update: PromiseMethod<ExecutorApiEffectClient["policies"]["update"]>; | |
| 34 | − remove: PromiseMethod<ExecutorApiEffectClient["policies"]["remove"]>; | |
| 35 | − }; | |
| 36 | − sources: { | |
| 37 | − list: PromiseMethod<ExecutorApiEffectClient["sources"]["list"]>; | |
| 38 | − create: PromiseMethod<ExecutorApiEffectClient["sources"]["create"]>; | |
| 39 | − get: PromiseMethod<ExecutorApiEffectClient["sources"]["get"]>; | |
| 40 | − update: PromiseMethod<ExecutorApiEffectClient["sources"]["update"]>; | |
| 41 | − remove: PromiseMethod<ExecutorApiEffectClient["sources"]["remove"]>; | |
| 42 | − inspection: PromiseMethod<ExecutorApiEffectClient["sources"]["inspection"]>; | |
| 43 | − inspectionTool: PromiseMethod<ExecutorApiEffectClient["sources"]["inspectionTool"]>; | |
| 44 | − inspectionDiscover: PromiseMethod< | |
| 45 | − ExecutorApiEffectClient["sources"]["inspectionDiscover"] | |
| 46 | − >; | |
| 47 | − credentialPage: PromiseMethod<ExecutorApiEffectClient["sources"]["credentialPage"]>; | |
| 48 | − credentialSubmit: PromiseMethod<ExecutorApiEffectClient["sources"]["credentialSubmit"]>; | |
| 49 | − }; | |
| 50 | − executions: { | |
| 51 | − create: PromiseMethod<ExecutorApiEffectClient["executions"]["create"]>; | |
| 52 | − get: PromiseMethod<ExecutorApiEffectClient["executions"]["get"]>; | |
| 53 | − resume: PromiseMethod<ExecutorApiEffectClient["executions"]["resume"]>; | |
| 54 | − }; | |
| 55 | −}; | |
| 56 | − | |
| 57 | −const isResponseTuple = <Value>( | |
| 58 | − value: Value | readonly [Value, unknown], | |
| 59 | −): value is readonly [Value, unknown] => | |
| 60 | − Array.isArray(value) && value.length === 2; | |
| 61 | − | |
| 62 | −function stripResponse<Value>(value: Value | readonly [Value, unknown]): Value { | |
| 63 | − return isResponseTuple(value) ? value[0] : value; | |
| 64 | −} | |
| 65 | − | |
| 66 | −const wrapMethod = < | |
| 67 | − F extends (input: any) => Effect.Effect<any, unknown, never>, | |
| 68 | −>( | |
| 69 | − effectClientPromise: Promise<ExecutorApiEffectClient>, | |
| 70 | − select: (client: ExecutorApiEffectClient) => F, | |
| 71 | −): PromiseMethod<F> => { | |
| 72 | − const wrapped = (input: MethodInput<F>): Promise<MethodOutput<F>> => | |
| 73 | − effectClientPromise | |
| 74 | − .then((client) => Effect.runPromise(select(client)(input))) | |
| 75 | − .then(stripResponse); | |
| 76 | − | |
| 77 | − return wrapped; | |
| 78 | −}; | |
| 79 | − | |
| 80 | −export const createExecutorApiClient = async (input: { | |
| 81 | − baseUrl: string; | |
| 82 | − accountId?: string; | |
| 83 | −}): Promise<ExecutorApiClient> => { | |
| 84 | − const effectClientPromise = Effect.runPromise( | |
| 85 | − createExecutorApiEffectClient(input), | |
| 86 | − ); | |
| 87 | − | |
| 88 | − return { | |
| 89 | − local: { | |
| 90 | − installation: wrapMethod(effectClientPromise, (client) => client.local.installation), | |
| 91 | − config: wrapMethod(effectClientPromise, (client) => client.local.config), | |
| 92 | − listSecrets: wrapMethod(effectClientPromise, (client) => client.local.listSecrets), | |
| 93 | − createSecret: wrapMethod(effectClientPromise, (client) => client.local.createSecret), | |
| 94 | − updateSecret: wrapMethod(effectClientPromise, (client) => client.local.updateSecret), | |
| 95 | − deleteSecret: wrapMethod(effectClientPromise, (client) => client.local.deleteSecret), | |
| 96 | − }, | |
| 97 | − policies: { | |
| 98 | − list: wrapMethod(effectClientPromise, (client) => client.policies.list), | |
| 99 | − create: wrapMethod(effectClientPromise, (client) => client.policies.create), | |
| 100 | − get: wrapMethod(effectClientPromise, (client) => client.policies.get), | |
| 101 | − update: wrapMethod(effectClientPromise, (client) => client.policies.update), | |
| 102 | − remove: wrapMethod(effectClientPromise, (client) => client.policies.remove), | |
| 103 | − }, | |
| 104 | − sources: { | |
| 105 | − list: wrapMethod(effectClientPromise, (client) => client.sources.list), | |
| 106 | − create: wrapMethod(effectClientPromise, (client) => client.sources.create), | |
| 107 | − get: wrapMethod(effectClientPromise, (client) => client.sources.get), | |
| 108 | − update: wrapMethod(effectClientPromise, (client) => client.sources.update), | |
| 109 | − remove: wrapMethod(effectClientPromise, (client) => client.sources.remove), | |
| 110 | − inspection: wrapMethod(effectClientPromise, (client) => client.sources.inspection), | |
| 111 | − inspectionTool: wrapMethod( | |
| 112 | − effectClientPromise, | |
| 113 | − (client) => client.sources.inspectionTool, | |
| 114 | − ), | |
| 115 | − inspectionDiscover: wrapMethod( | |
| 116 | − effectClientPromise, | |
| 117 | − (client) => client.sources.inspectionDiscover, | |
| 118 | − ), | |
| 119 | − credentialPage: wrapMethod( | |
| 120 | − effectClientPromise, | |
| 121 | − (client) => client.sources.credentialPage, | |
| 122 | − ), | |
| 123 | − credentialSubmit: wrapMethod( | |
| 124 | − effectClientPromise, | |
| 125 | − (client) => client.sources.credentialSubmit, | |
| 126 | − ), | |
| 127 | − }, | |
| 128 | − executions: { | |
| 129 | − create: wrapMethod(effectClientPromise, (client) => client.executions.create), | |
| 130 | − get: wrapMethod(effectClientPromise, (client) => client.executions.get), | |
| 131 | − resume: wrapMethod(effectClientPromise, (client) => client.executions.resume), | |
| 132 | − }, | |
| 133 | − }; | |
| 134 | −}; | |
| @@ -4,13 +4,16 @@ import { · 3 unmodified lines | ||
| 4 | 4 | } from "@effect/platform"; |
| 5 | 5 | import * as Effect from "effect/Effect"; |
| 6 | 6 | |
| 7 | −import { ExecutorApi } from "./api"; | |
| 7 | +import { createExecutorApi } from "./api"; | |
| 8 | +import type { ExecutorHttpPlugin } from "./plugins"; | |
| 8 | 9 | |
| 9 | −export const createExecutorApiEffectClient = (input: { | |
| 10 | +export const createExecutorApiEffectClient = < | |
| 11 | + const TPlugins extends readonly ExecutorHttpPlugin[] = [], | |
| 12 | +>(input: { | |
| 10 | 13 | baseUrl: string; |
| 11 | − accountId?: string; | |
| 14 | + plugins?: TPlugins; | |
| 12 | 15 | }) => |
| 13 | − HttpApiClient.make(ExecutorApi, { | |
| 16 | + HttpApiClient.make(createExecutorApi({ plugins: input.plugins }), { | |
| 14 | 17 | baseUrl: input.baseUrl, |
| 15 | 18 | }).pipe(Effect.provide(FetchHttpClient.layer)); |
| 16 | 19 | |
| @@ -2,24 +2,46 @@ import { HttpApiBuilder } from "@effect/platform"; · 1 unmodified line | ||
| 2 | 2 | import * as Layer from "effect/Layer"; |
| 3 | 3 | import type { ExecutorEffect } from "@executor/platform-sdk/effect"; |
| 4 | 4 | |
| 5 | −import { ExecutorApi } from "./api"; | |
| 5 | +import { createExecutorApi } from "./api"; | |
| 6 | 6 | import { createControlPlaneExecutorLayer } from "./executor-context"; |
| 7 | 7 | import { ExecutorExecutionsLive } from "./executions/http"; |
| 8 | 8 | import { ExecutorLocalLive } from "./local/http"; |
| 9 | 9 | import { ExecutorPoliciesLive } from "./policies/http"; |
| 10 | +import type { ExecutorHttpPlugin } from "./plugins"; | |
| 10 | 11 | import { ExecutorSourcesLive } from "./sources/http"; |
| 11 | 12 | |
| 12 | −export const ExecutorApiLive = HttpApiBuilder.api(ExecutorApi).pipe( | |
| 13 | − Layer.provide(ExecutorLocalLive), | |
| 14 | − Layer.provide(ExecutorSourcesLive), | |
| 15 | − Layer.provide(ExecutorPoliciesLive), | |
| 16 | − Layer.provide(ExecutorExecutionsLive), | |
| 17 | −); | |
| 13 | +const createExecutorApiLive = ( | |
| 14 | + executor: ExecutorEffect, | |
| 15 | + plugins: readonly ExecutorHttpPlugin[] = [], | |
| 16 | +) => { | |
| 17 | + const api = createExecutorApi({ plugins }); | |
| 18 | + let live: Layer.Layer<any, any, any> = HttpApiBuilder.api(api as any).pipe( | |
| 19 | + Layer.provide(ExecutorLocalLive), | |
| 20 | + Layer.provide(ExecutorSourcesLive), | |
| 21 | + Layer.provide(ExecutorPoliciesLive), | |
| 22 | + Layer.provide(ExecutorExecutionsLive), | |
| 23 | + ); | |
| 24 | + | |
| 25 | + for (const plugin of plugins) { | |
| 26 | + live = live.pipe( | |
| 27 | + Layer.provide( | |
| 28 | + plugin.build({ | |
| 29 | + executor, | |
| 30 | + }), | |
| 31 | + ), | |
| 32 | + ); | |
| 33 | + } | |
| 18 | 34 | |
| 19 | −export type ExecutorApiRuntimeContext = Layer.Layer.Context<typeof ExecutorApiLive>; | |
| 35 | + return live; | |
| 36 | +}; | |
| 20 | 37 | |
| 21 | −export const createExecutorApiLayer = (executor: ExecutorEffect) => | |
| 22 | − ExecutorApiLive.pipe( | |
| 38 | +export const createExecutorApiLayer = ( | |
| 39 | + executor: ExecutorEffect, | |
| 40 | + options: { | |
| 41 | + plugins?: readonly ExecutorHttpPlugin[]; | |
| 42 | + } = {}, | |
| 43 | +) => | |
| 44 | + createExecutorApiLive(executor, options.plugins).pipe( | |
| 23 | 45 | Layer.provide(createControlPlaneExecutorLayer(executor)), |
| 24 | 46 | ); |
| 25 | 47 | |
| @@ -1,11 +1,15 @@ | ||
| 1 | 1 | export { |
| 2 | + CoreExecutorApi, | |
| 3 | + createExecutorApi, | |
| 4 | + createExecutorOpenApiSpec, | |
| 2 | 5 | ExecutorApi, |
| 3 | 6 | executorOpenApiSpec, |
| 4 | 7 | } from "./api"; |
| 5 | −export { | |
| 6 | − createExecutorApiClient, | |
| 7 | − type ExecutorApiClient, | |
| 8 | −} from "./client"; | |
| 8 | +export type { | |
| 9 | + ExecutorHttpApiExtension, | |
| 10 | + ExecutorHttpPlugin, | |
| 11 | + ExecutorHttpPluginGroups, | |
| 12 | +} from "./plugins"; | |
| 9 | 13 | |
| 10 | 14 | export type { LocalInstallation } from "@executor/platform-sdk/schema"; |
| 11 | 15 | |
| @@ -38,11 +42,7 @@ export { · 26 unmodified lines | ||
| 38 | 42 | } from "./local/api"; |
| 39 | 43 | |
| 40 | 44 | export { |
| 41 | − CreateSourcePayloadSchema, | |
| 42 | 45 | SourcesApi, |
| 43 | − UpdateSourcePayloadSchema, | |
| 44 | − type CreateSourcePayload, | |
| 45 | − type UpdateSourcePayload, | |
| 46 | 46 | } from "./sources/api"; |
| 47 | 47 | |
| 48 | 48 | export { |
| @@ -0,0 +1,23 @@ | ||
| 1 | +import type { HttpApiGroup } from "@effect/platform"; | |
| 2 | +import type * as Layer from "effect/Layer"; | |
| 3 | +import type { ExecutorEffect } from "@executor/platform-sdk/effect"; | |
| 4 | + | |
| 5 | +export type ExecutorHttpApiExtension< | |
| 6 | + TGroup extends HttpApiGroup.HttpApiGroup.Any = HttpApiGroup.HttpApiGroup.Any, | |
| 7 | +> = { | |
| 8 | + key: string; | |
| 9 | + group: TGroup; | |
| 10 | +}; | |
| 11 | + | |
| 12 | +export type ExecutorHttpPlugin< | |
| 13 | + TGroup extends HttpApiGroup.HttpApiGroup.Any = HttpApiGroup.HttpApiGroup.Any, | |
| 14 | + TExecutorExtension extends object = {}, | |
| 15 | +> = ExecutorHttpApiExtension<TGroup> & { | |
| 16 | + build(input: { | |
| 17 | + executor: ExecutorEffect & TExecutorExtension; | |
| 18 | + }): Layer.Layer<any, any, any>; | |
| 19 | +}; | |
| 20 | + | |
| 21 | +export type ExecutorHttpPluginGroups< | |
| 22 | + TPlugins extends readonly ExecutorHttpApiExtension[], | |
| 23 | +> = TPlugins[number]["group"]; | |
| @@ -1,10 +1,4 @@ | ||
| 1 | 1 | import { HttpApiEndpoint, HttpApiGroup, HttpApiSchema } from "@effect/platform"; |
| 2 | −import { | |
| 3 | − CreateSourcePayloadSchema, | |
| 4 | − CredentialPageUrlParamsSchema, | |
| 5 | − CredentialSubmitPayloadSchema, | |
| 6 | − UpdateSourcePayloadSchema, | |
| 7 | −} from "@executor/platform-sdk/contracts"; | |
| 8 | 2 | import { |
| 9 | 3 | ControlPlaneBadRequestError, |
| 10 | 4 | ControlPlaneForbiddenError, |
| @@ -23,24 +17,10 @@ import { · 12 unmodified lines | ||
| 23 | 17 | } from "@executor/platform-sdk/schema"; |
| 24 | 18 | import * as Schema from "effect/Schema"; |
| 25 | 19 | |
| 26 | −export type { | |
| 27 | − CreateSourcePayload, | |
| 28 | − UpdateSourcePayload, | |
| 29 | −} from "@executor/platform-sdk/contracts"; | |
| 30 | − | |
| 31 | −export { | |
| 32 | − CreateSourcePayloadSchema, | |
| 33 | − UpdateSourcePayloadSchema, | |
| 34 | −}; | |
| 35 | − | |
| 36 | 20 | const workspaceIdParam = HttpApiSchema.param("workspaceId", WorkspaceIdSchema); |
| 37 | 21 | const sourceIdParam = HttpApiSchema.param("sourceId", SourceIdSchema); |
| 38 | 22 | const toolPathParam = HttpApiSchema.param("toolPath", Schema.String); |
| 39 | 23 | |
| 40 | −const HtmlSchema = HttpApiSchema.Text({ | |
| 41 | − contentType: "text/html", | |
| 42 | −}); | |
| 43 | − | |
| 44 | 24 | export class SourcesApi extends HttpApiGroup.make("sources") |
| 45 | 25 | .add( |
| 46 | 26 | HttpApiEndpoint.get("list")`/workspaces/${workspaceIdParam}/sources` |
| @@ -50,15 +30,6 @@ export class SourcesApi extends HttpApiGroup.make("sources") · 3 unmodified lines | ||
| 50 | 30 | .addError(ControlPlaneForbiddenError) |
| 51 | 31 | .addError(ControlPlaneStorageError), |
| 52 | 32 | ) |
| 53 | − .add( | |
| 54 | − HttpApiEndpoint.post("create")`/workspaces/${workspaceIdParam}/sources` | |
| 55 | − .setPayload(CreateSourcePayloadSchema) | |
| 56 | − .addSuccess(SourceSchema) | |
| 57 | − .addError(ControlPlaneBadRequestError) | |
| 58 | − .addError(ControlPlaneUnauthorizedError) | |
| 59 | − .addError(ControlPlaneForbiddenError) | |
| 60 | − .addError(ControlPlaneStorageError), | |
| 61 | − ) | |
| 62 | 33 | .add( |
| 63 | 34 | HttpApiEndpoint.get("get")`/workspaces/${workspaceIdParam}/sources/${sourceIdParam}` |
| 64 | 35 | .addSuccess(SourceSchema) |
| @@ -68,16 +39,6 @@ export class SourcesApi extends HttpApiGroup.make("sources") · 3 unmodified lines | ||
| 68 | 39 | .addError(ControlPlaneNotFoundError) |
| 69 | 40 | .addError(ControlPlaneStorageError), |
| 70 | 41 | ) |
| 71 | − .add( | |
| 72 | − HttpApiEndpoint.patch("update")`/workspaces/${workspaceIdParam}/sources/${sourceIdParam}` | |
| 73 | − .setPayload(UpdateSourcePayloadSchema) | |
| 74 | − .addSuccess(SourceSchema) | |
| 75 | − .addError(ControlPlaneBadRequestError) | |
| 76 | − .addError(ControlPlaneUnauthorizedError) | |
| 77 | − .addError(ControlPlaneForbiddenError) | |
| 78 | − .addError(ControlPlaneNotFoundError) | |
| 79 | − .addError(ControlPlaneStorageError), | |
| 80 | − ) | |
| 81 | 42 | .add( |
| 82 | 43 | HttpApiEndpoint.del("remove")`/workspaces/${workspaceIdParam}/sources/${sourceIdParam}` |
| 83 | 44 | .addSuccess(Schema.Struct({ removed: Schema.Boolean })) |
| @@ -86,23 +47,6 @@ export class SourcesApi extends HttpApiGroup.make("sources") · 2 unmodified lines | ||
| 86 | 47 | .addError(ControlPlaneForbiddenError) |
| 87 | 48 | .addError(ControlPlaneStorageError), |
| 88 | 49 | ) |
| 89 | − .add( | |
| 90 | − HttpApiEndpoint.get("credentialPage")`/workspaces/${workspaceIdParam}/sources/${sourceIdParam}/credentials` | |
| 91 | − .setUrlParams(CredentialPageUrlParamsSchema) | |
| 92 | − .addSuccess(HtmlSchema) | |
| 93 | − .addError(ControlPlaneBadRequestError) | |
| 94 | − .addError(ControlPlaneNotFoundError) | |
| 95 | − .addError(ControlPlaneStorageError), | |
| 96 | − ) | |
| 97 | − .add( | |
| 98 | − HttpApiEndpoint.post("credentialSubmit")`/workspaces/${workspaceIdParam}/sources/${sourceIdParam}/credentials` | |
| 99 | − .setUrlParams(CredentialPageUrlParamsSchema) | |
| 100 | − .setPayload(CredentialSubmitPayloadSchema) | |
| 101 | − .addSuccess(HtmlSchema) | |
| 102 | − .addError(ControlPlaneBadRequestError) | |
| 103 | − .addError(ControlPlaneNotFoundError) | |
| 104 | − .addError(ControlPlaneStorageError), | |
| 105 | − ) | |
| 106 | 50 | .add( |
| 107 | 51 | HttpApiEndpoint.get("inspection")`/workspaces/${workspaceIdParam}/sources/${sourceIdParam}/inspection` |
| 108 | 52 | .addSuccess(SourceInspectionSchema) |
| @@ -1,7 +1,4 @@ | ||
| 1 | −import { | |
| 2 | − HttpApiBuilder, | |
| 3 | − HttpServerResponse, | |
| 4 | −} from "@effect/platform"; | |
| 1 | +import { HttpApiBuilder } from "@effect/platform"; | |
| 5 | 2 | import type { |
| 6 | 3 | ExecutionInteraction, |
| 7 | 4 | Source, |
| @@ -29,453 +26,6 @@ const toBadRequestError = (operation: string, cause: unknown) => { · 21 unmodified lines | ||
| 29 | 26 | }); |
| 30 | 27 | }; |
| 31 | 28 | |
| 32 | −const escapeHtml = (value: string): string => | |
| 33 | − value | |
| 34 | − .replaceAll("&", "&") | |
| 35 | − .replaceAll("<", "<") | |
| 36 | − .replaceAll(">", ">") | |
| 37 | − .replaceAll('"', """) | |
| 38 | − .replaceAll("'", "'"); | |
| 39 | − | |
| 40 | −const credentialPageDocument = (input: { | |
| 41 | − title: string; | |
| 42 | − eyebrow: string; | |
| 43 | − message: string; | |
| 44 | − sourceLabel: string; | |
| 45 | − endpoint: string; | |
| 46 | − interactionId: string; | |
| 47 | − error?: string; | |
| 48 | − state?: "pending" | "stored" | "continued" | "cancelled" | "inactive"; | |
| 49 | −}) => `<!doctype html> | |
| 50 | −<html lang="en"> | |
| 51 | − <head> | |
| 52 | − <meta charset="utf-8" /> | |
| 53 | − <meta name="viewport" content="width=device-width, initial-scale=1" /> | |
| 54 | − <title>${escapeHtml(input.title)}</title> | |
| 55 | − <link rel="preconnect" href="https://fonts.googleapis.com" /> | |
| 56 | − <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin /> | |
| 57 | − <link href="https://fonts.googleapis.com/css2?family=DM+Sans:ital,opsz,wght@0,9..40,400;0,9..40,500;0,9..40,600;1,9..40,400&family=DM+Mono:wght@400;500&display=swap" rel="stylesheet" /> | |
| 58 | − <style> | |
| 59 | − :root { | |
| 60 | − --bg: #fafaf9; | |
| 61 | − --surface: #ffffff; | |
| 62 | − --text: #1c1917; | |
| 63 | − --text-secondary: #78716c; | |
| 64 | − --text-tertiary: #a8a29e; | |
| 65 | − --border: #e7e5e4; | |
| 66 | − --accent: #1d4ed8; | |
| 67 | − --accent-light: #eff6ff; | |
| 68 | − --green: #16a34a; | |
| 69 | − --green-light: #f0fdf4; | |
| 70 | − --green-border: #bbf7d0; | |
| 71 | − --red: #dc2626; | |
| 72 | − --red-light: #fef2f2; | |
| 73 | − --red-border: #fecaca; | |
| 74 | − --amber: #d97706; | |
| 75 | − --amber-light: #fffbeb; | |
| 76 | − --amber-border: #fde68a; | |
| 77 | − } | |
| 78 | − | |
| 79 | − * { box-sizing: border-box; margin: 0; padding: 0; } | |
| 80 | − | |
| 81 | − body { | |
| 82 | − min-height: 100vh; | |
| 83 | − background: var(--bg); | |
| 84 | − color: var(--text); | |
| 85 | − font-family: 'DM Sans', system-ui, -apple-system, sans-serif; | |
| 86 | − display: flex; | |
| 87 | − justify-content: center; | |
| 88 | − padding: 80px 24px 48px; | |
| 89 | − -webkit-font-smoothing: antialiased; | |
| 90 | − } | |
| 91 | − | |
| 92 | − .page { | |
| 93 | − width: 100%; | |
| 94 | − max-width: 540px; | |
| 95 | − } | |
| 96 | − | |
| 97 | − /* Status pill at the very top */ | |
| 98 | − .status-pill { | |
| 99 | − display: inline-flex; | |
| 100 | − align-items: center; | |
| 101 | − gap: 7px; | |
| 102 | − padding: 5px 14px 5px 10px; | |
| 103 | − border-radius: 999px; | |
| 104 | − font-family: 'DM Mono', monospace; | |
| 105 | − font-size: 12px; | |
| 106 | − font-weight: 500; | |
| 107 | − letter-spacing: 0.01em; | |
| 108 | − margin-bottom: 28px; | |
| 109 | − } | |
| 110 | − | |
| 111 | − .status-pill::before { | |
| 112 | − content: ''; | |
| 113 | − width: 7px; | |
| 114 | − height: 7px; | |
| 115 | − border-radius: 50%; | |
| 116 | − flex-shrink: 0; | |
| 117 | − } | |
| 118 | − | |
| 119 | − .status-pill[data-state='pending'] { | |
| 120 | − background: var(--amber-light); | |
| 121 | − color: var(--amber); | |
| 122 | − border: 1px solid var(--amber-border); | |
| 123 | − } | |
| 124 | − .status-pill[data-state='pending']::before { background: var(--amber); } | |
| 125 | − | |
| 126 | − .status-pill[data-state='stored'] { | |
| 127 | − background: var(--green-light); | |
| 128 | − color: var(--green); | |
| 129 | − border: 1px solid var(--green-border); | |
| 130 | − } | |
| 131 | − .status-pill[data-state='stored']::before { background: var(--green); } | |
| 132 | − | |
| 133 | − .status-pill[data-state='continued'] { | |
| 134 | − background: var(--green-light); | |
| 135 | − color: var(--green); | |
| 136 | − border: 1px solid var(--green-border); | |
| 137 | − } | |
| 138 | − .status-pill[data-state='continued']::before { background: var(--green); } | |
| 139 | − | |
| 140 | − .status-pill[data-state='cancelled'], | |
| 141 | − .status-pill[data-state='inactive'] { | |
| 142 | − background: #f5f5f4; | |
| 143 | − color: var(--text-secondary); | |
| 144 | − border: 1px solid var(--border); | |
| 145 | − } | |
| 146 | − .status-pill[data-state='cancelled']::before, | |
| 147 | − .status-pill[data-state='inactive']::before { background: var(--text-tertiary); } | |
| 148 | − | |
| 149 | − /* Title area */ | |
| 150 | − h1 { | |
| 151 | − font-size: 28px; | |
| 152 | − font-weight: 600; | |
| 153 | − letter-spacing: -0.025em; | |
| 154 | − line-height: 1.2; | |
| 155 | − margin-bottom: 10px; | |
| 156 | − } | |
| 157 | − | |
| 158 | − .subtitle { | |
| 159 | − font-size: 15px; | |
| 160 | − line-height: 1.6; | |
| 161 | − color: var(--text-secondary); | |
| 162 | − } | |
| 163 | − | |
| 164 | − /* Divider */ | |
| 165 | − hr { | |
| 166 | − border: none; | |
| 167 | − height: 1px; | |
| 168 | − background: var(--border); | |
| 169 | − margin: 36px 0; | |
| 170 | − } | |
| 171 | − | |
| 172 | − /* Source detail rows */ | |
| 173 | − .detail { | |
| 174 | − display: flex; | |
| 175 | − flex-direction: column; | |
| 176 | − gap: 6px; | |
| 177 | − margin-bottom: 24px; | |
| 178 | − } | |
| 179 | − | |
| 180 | − .detail-label { | |
| 181 | − font-size: 13px; | |
| 182 | − font-weight: 500; | |
| 183 | − color: var(--text-secondary); | |
| 184 | − } | |
| 185 | − | |
| 186 | − .detail-value { | |
| 187 | − font-size: 15px; | |
| 188 | − line-height: 1.5; | |
| 189 | − word-break: break-word; | |
| 190 | − } | |
| 191 | − | |
| 192 | − .detail-mono { | |
| 193 | − font-family: 'DM Mono', monospace; | |
| 194 | − font-size: 13px; | |
| 195 | − line-height: 1.5; | |
| 196 | − padding: 10px 14px; | |
| 197 | − background: #f5f5f4; | |
| 198 | − border: 1px solid var(--border); | |
| 199 | − border-radius: 8px; | |
| 200 | − word-break: break-all; | |
| 201 | − color: var(--text); | |
| 202 | − } | |
| 203 | − | |
| 204 | − .detail-id { | |
| 205 | − font-family: 'DM Mono', monospace; | |
| 206 | − font-size: 12px; | |
| 207 | − color: var(--text-tertiary); | |
| 208 | − } | |
| 209 | − | |
| 210 | − /* Result card for stored/cancelled/inactive */ | |
| 211 | − .result-card { | |
| 212 | − padding: 32px; | |
| 213 | − border-radius: 12px; | |
| 214 | − text-align: center; | |
| 215 | − } | |
| 216 | − | |
| 217 | − .result-card.success { | |
| 218 | − background: var(--green-light); | |
| 219 | − border: 1px solid var(--green-border); | |
| 220 | − } | |
| 221 | − | |
| 222 | − .result-card.neutral { | |
| 223 | − background: #f5f5f4; | |
| 224 | − border: 1px solid var(--border); | |
| 225 | − } | |
| 226 | − | |
| 227 | − .result-card p { | |
| 228 | − font-size: 15px; | |
| 229 | − line-height: 1.6; | |
| 230 | − color: var(--text-secondary); | |
| 231 | − } | |
| 232 | − | |
| 233 | − .result-card .result-heading { | |
| 234 | − font-weight: 600; | |
| 235 | − font-size: 15px; | |
| 236 | − color: var(--text); | |
| 237 | − margin-bottom: 6px; | |
| 238 | − } | |
| 239 | − | |
| 240 | − /* Form */ | |
| 241 | − .alert { | |
| 242 | − padding: 12px 14px; | |
| 243 | − border-radius: 8px; | |
| 244 | − background: var(--red-light); | |
| 245 | − border: 1px solid var(--red-border); | |
| 246 | − color: var(--red); | |
| 247 | − font-size: 14px; | |
| 248 | − line-height: 1.5; | |
| 249 | − margin-bottom: 20px; | |
| 250 | − } | |
| 251 | − | |
| 252 | − .field { margin-bottom: 20px; } | |
| 253 | − | |
| 254 | − label { | |
| 255 | − display: block; | |
| 256 | − font-size: 14px; | |
| 257 | − font-weight: 500; | |
| 258 | − margin-bottom: 6px; | |
| 259 | − } | |
| 260 | − | |
| 261 | − input[type='password'] { | |
| 262 | − width: 100%; | |
| 263 | − padding: 10px 14px; | |
| 264 | − background: var(--surface); | |
| 265 | − border: 1px solid var(--border); | |
| 266 | − border-radius: 8px; | |
| 267 | − font-family: 'DM Mono', monospace; | |
| 268 | − font-size: 14px; | |
| 269 | − color: var(--text); | |
| 270 | − transition: border-color 0.15s, box-shadow 0.15s; | |
| 271 | − } | |
| 272 | − | |
| 273 | − input[type='password']::placeholder { color: var(--text-tertiary); } | |
| 274 | − | |
| 275 | − input[type='password']:focus { | |
| 276 | − outline: none; | |
| 277 | − border-color: var(--accent); | |
| 278 | − box-shadow: 0 0 0 3px rgba(29, 78, 216, 0.1); | |
| 279 | − } | |
| 280 | − | |
| 281 | − .hint { | |
| 282 | − margin-top: 8px; | |
| 283 | − font-size: 13px; | |
| 284 | − line-height: 1.5; | |
| 285 | − color: var(--text-tertiary); | |
| 286 | − } | |
| 287 | − | |
| 288 | − .actions { | |
| 289 | − display: flex; | |
| 290 | − gap: 10px; | |
| 291 | − margin-top: 24px; | |
| 292 | − } | |
| 293 | − | |
| 294 | − button { | |
| 295 | − appearance: none; | |
| 296 | − border: none; | |
| 297 | − border-radius: 8px; | |
| 298 | − padding: 10px 20px; | |
| 299 | − font-family: inherit; | |
| 300 | − font-size: 14px; | |
| 301 | − font-weight: 500; | |
| 302 | − cursor: pointer; | |
| 303 | − transition: background 0.15s; | |
| 304 | − } | |
| 305 | − | |
| 306 | − .primary { | |
| 307 | − background: var(--text); | |
| 308 | − color: var(--surface); | |
| 309 | − } | |
| 310 | − .primary:hover { background: #292524; } | |
| 311 | − | |
| 312 | − .secondary { | |
| 313 | − background: transparent; | |
| 314 | − color: var(--text-secondary); | |
| 315 | − border: 1px solid var(--border); | |
| 316 | − } | |
| 317 | − .secondary:hover { background: #f5f5f4; } | |
| 318 | − | |
| 319 | − @media (max-width: 540px) { | |
| 320 | − body { padding: 48px 20px 32px; } | |
| 321 | − h1 { font-size: 24px; } | |
| 322 | − } | |
| 323 | − </style> | |
| 324 | − </head> | |
| 325 | − <body> | |
| 326 | − <main class="page"> | |
| 327 | − <div class="status-pill" data-state="${escapeHtml(input.state ?? "pending")}">${escapeHtml(input.state ?? "pending")}</div> | |
| 328 | − | |
| 329 | − <h1>${escapeHtml(input.title)}</h1> | |
| 330 | − <p class="subtitle">${escapeHtml(input.message)}</p> | |
| 331 | − | |
| 332 | − <hr /> | |
| 333 | − | |
| 334 | − <div class="detail"> | |
| 335 | − <span class="detail-label">Source</span> | |
| 336 | − <span class="detail-value">${escapeHtml(input.sourceLabel)}</span> | |
| 337 | − </div> | |
| 338 | − | |
| 339 | − <div class="detail"> | |
| 340 | − <span class="detail-label">API endpoint</span> | |
| 341 | − <div class="detail-mono">${escapeHtml(input.endpoint)}</div> | |
| 342 | − </div> | |
| 343 | − | |
| 344 | − <div class="detail"> | |
| 345 | − <span class="detail-label">Interaction</span> | |
| 346 | − <span class="detail-id">${escapeHtml(input.interactionId)}</span> | |
| 347 | − </div> | |
| 348 | − | |
| 349 | − <hr /> | |
| 350 | − | |
| 351 | − ${input.error ? `<p class="alert">${escapeHtml(input.error)}</p>` : ""} | |
| 352 | − ${ | |
| 353 | − input.state === "stored" | |
| 354 | − ? `<div class="result-card success"> | |
| 355 | − <p class="result-heading">Credential stored</p> | |
| 356 | − <p>Executor resumed the source connection request. You can close this window.</p> | |
| 357 | − </div>` | |
| 358 | − : input.state === "continued" | |
| 359 | − ? `<div class="result-card success"> | |
| 360 | − <p class="result-heading">Continuing without auth</p> | |
| 361 | − <p>Executor resumed the source connection without stored credentials. You can close this window.</p> | |
| 362 | − </div>` | |
| 363 | − : input.state === "cancelled" | |
| 364 | − ? `<div class="result-card neutral"> | |
| 365 | − <p class="result-heading">Request cancelled</p> | |
| 366 | − <p>Executor was notified. You can close this window.</p> | |
| 367 | − </div>` | |
| 368 | − : input.state === "inactive" | |
| 369 | − ? `<div class="result-card neutral"> | |
| 370 | − <p class="result-heading">No longer active</p> | |
| 371 | − <p>This credential request has expired. Start a new source connection flow if needed.</p> | |
| 372 | − </div>` | |
| 373 | − : `<form method="post"> | |
| 374 | − <div class="field"> | |
| 375 | − <label for="token">Personal access token</label> | |
| 376 | − <input | |
| 377 | − id="token" | |
| 378 | − name="token" | |
| 379 | − type="password" | |
| 380 | − autocomplete="off" | |
| 381 | − spellcheck="false" | |
| 382 | − placeholder="ghp_..." | |
| 383 | − /> | |
| 384 | − <p class="hint"> | |
| 385 | − Add a token to enable authenticated requests, or continue without auth if this API supports public access. | |
| 386 | − </p> | |
| 387 | − </div> | |
| 388 | − <div class="actions"> | |
| 389 | − <button class="primary" type="submit" name="action" value="submit">Connect token</button> | |
| 390 | − <button class="secondary" type="submit" name="action" value="continue" formnovalidate>Continue without auth</button> | |
| 391 | − <button class="secondary" type="submit" name="action" value="cancel" formnovalidate>Cancel</button> | |
| 392 | − </div> | |
| 393 | − </form>` | |
| 394 | − } | |
| 395 | − </main> | |
| 396 | − </body> | |
| 397 | −</html>`; | |
| 398 | − | |
| 399 | −const htmlResponse = ( | |
| 400 | − html: string, | |
| 401 | − status = 200, | |
| 402 | −): ReturnType<typeof HttpServerResponse.html> => | |
| 403 | − HttpServerResponse.html(html).pipe( | |
| 404 | − HttpServerResponse.setStatus(status), | |
| 405 | − ) as ReturnType<typeof HttpServerResponse.html>; | |
| 406 | − | |
| 407 | −const credentialErrorResponse = (input: { | |
| 408 | − title: string; | |
| 409 | − message: string; | |
| 410 | − status: number; | |
| 411 | −}) => | |
| 412 | − htmlResponse( | |
| 413 | − credentialPageDocument({ | |
| 414 | − title: input.title, | |
| 415 | − eyebrow: "Executor", | |
| 416 | − message: input.message, | |
| 417 | − sourceLabel: "Unavailable", | |
| 418 | − endpoint: "Unavailable", | |
| 419 | − interactionId: "unavailable", | |
| 420 | − state: "inactive", | |
| 421 | − error: input.message, | |
| 422 | − }), | |
| 423 | − input.status, | |
| 424 | − ); | |
| 425 | − | |
| 426 | −const credentialErrorStatus = ( | |
| 427 | − error: | |
| 428 | − | ControlPlaneBadRequestError | |
| 429 | − | ControlPlaneNotFoundError | |
| 430 | − | ControlPlaneStorageError, | |
| 431 | −) => | |
| 432 | − error instanceof ControlPlaneNotFoundError | |
| 433 | − ? 404 | |
| 434 | − : error instanceof ControlPlaneBadRequestError | |
| 435 | − ? 400 | |
| 436 | − : 500; | |
| 437 | − | |
| 438 | −const credentialSubmitErrorResponse = (input: { | |
| 439 | − workspaceId: WorkspaceId; | |
| 440 | − sourceId: Source["id"]; | |
| 441 | − interactionId: ExecutionInteraction["id"]; | |
| 442 | − message: string; | |
| 443 | − status: number; | |
| 444 | −}) => | |
| 445 | − resolveRequestedLocalWorkspace( | |
| 446 | − "sources.credentialSubmit", | |
| 447 | − input.workspaceId, | |
| 448 | − ).pipe( | |
| 449 | − Effect.flatMap((executor) => | |
| 450 | − executor.local.credentials.get({ | |
| 451 | − sourceId: input.sourceId, | |
| 452 | − interactionId: input.interactionId, | |
| 453 | − }), | |
| 454 | − ), | |
| 455 | − Effect.match({ | |
| 456 | − onFailure: () => | |
| 457 | − credentialErrorResponse({ | |
| 458 | − title: "Source Credential Request Failed", | |
| 459 | − message: input.message, | |
| 460 | − status: input.status, | |
| 461 | − }), | |
| 462 | − onSuccess: (interaction) => | |
| 463 | − htmlResponse( | |
| 464 | − credentialPageDocument({ | |
| 465 | − title: "Configure Source Access", | |
| 466 | − eyebrow: "Executor", | |
| 467 | − message: interaction.message, | |
| 468 | − sourceLabel: interaction.sourceLabel, | |
| 469 | − endpoint: interaction.endpoint, | |
| 470 | − interactionId: interaction.interactionId, | |
| 471 | − error: input.message, | |
| 472 | − state: "pending", | |
| 473 | − }), | |
| 474 | − input.status, | |
| 475 | − ), | |
| 476 | − }), | |
| 477 | − ); | |
| 478 | − | |
| 479 | 29 | export const ExecutorSourcesLive = HttpApiBuilder.group( |
| 480 | 30 | ExecutorApi, |
| 481 | 31 | "sources", |
| @@ -486,11 +36,6 @@ export const ExecutorSourcesLive = HttpApiBuilder.group( · 4 unmodified lines | ||
| 486 | 36 | Effect.flatMap((executor) => executor.sources.list()), |
| 487 | 37 | ), |
| 488 | 38 | ) |
| 489 | − .handle("create", ({ path, payload }) => | |
| 490 | − resolveRequestedLocalWorkspace("sources.create", path.workspaceId).pipe( | |
| 491 | − Effect.flatMap((executor) => executor.sources.create(payload)), | |
| 492 | − ), | |
| 493 | − ) | |
| 494 | 39 | .handle("get", ({ path }) => |
| 495 | 40 | resolveRequestedLocalWorkspace("sources.get", path.workspaceId).pipe( |
| 496 | 41 | Effect.flatMap((executor) => executor.sources.get(path.sourceId)), |
| @@ -530,135 +75,10 @@ export const ExecutorSourcesLive = HttpApiBuilder.group( · 33 unmodified lines | ||
| 530 | 75 | ), |
| 531 | 76 | ), |
| 532 | 77 | ) |
| 533 | − .handle("update", ({ path, payload }) => | |
| 534 | − resolveRequestedLocalWorkspace("sources.update", path.workspaceId).pipe( | |
| 535 | − Effect.flatMap((executor) => executor.sources.update(path.sourceId, payload)), | |
| 536 | − ), | |
| 537 | − ) | |
| 538 | 78 | .handle("remove", ({ path }) => |
| 539 | 79 | resolveRequestedLocalWorkspace("sources.remove", path.workspaceId).pipe( |
| 540 | 80 | Effect.flatMap((executor) => executor.sources.remove(path.sourceId)), |
| 541 | 81 | Effect.map((removed) => ({ removed })), |
| 542 | 82 | ), |
| 543 | 83 | ) |
| 544 | − .handle("credentialPage", ({ path, urlParams }) => | |
| 545 | − resolveRequestedLocalWorkspace( | |
| 546 | − "sources.credentialPage", | |
| 547 | − path.workspaceId, | |
| 548 | − ).pipe( | |
| 549 | − Effect.flatMap((executor) => | |
| 550 | − executor.local.credentials.get({ | |
| 551 | − sourceId: path.sourceId, | |
| 552 | − interactionId: urlParams.interactionId, | |
| 553 | − }), | |
| 554 | − ), | |
| 555 | − Effect.map((interaction) => | |
| 556 | − htmlResponse( | |
| 557 | − credentialPageDocument({ | |
| 558 | − title: "Configure Source Access", | |
| 559 | − eyebrow: "Executor", | |
| 560 | − message: interaction.message, | |
| 561 | − sourceLabel: interaction.sourceLabel, | |
| 562 | − endpoint: interaction.endpoint, | |
| 563 | − interactionId: interaction.interactionId, | |
| 564 | − state: | |
| 565 | − interaction.status === "pending" ? "pending" : "inactive", | |
| 566 | − }), | |
| 567 | − ), | |
| 568 | − ), | |
| 569 | − Effect.catchAll((error) => | |
| 570 | − Effect.succeed( | |
| 571 | − credentialErrorResponse({ | |
| 572 | − title: | |
| 573 | − error instanceof ControlPlaneNotFoundError | |
| 574 | − ? "Source Credential Request Unavailable" | |
| 575 | − : "Source Credential Request Failed", | |
| 576 | − message: | |
| 577 | − error instanceof Error ? error.message : "Source credential request failed", | |
| 578 | − status: | |
| 579 | − error instanceof ControlPlaneNotFoundError | |
| 580 | − || error instanceof ControlPlaneStorageError | |
| 581 | − || error instanceof ControlPlaneBadRequestError | |
| 582 | − ? credentialErrorStatus(error) | |
| 583 | − : 500, | |
| 584 | − }), | |
| 585 | − ), | |
| 586 | − ), | |
| 587 | − ), | |
| 588 | − ) | |
| 589 | − .handle("credentialSubmit", ({ path, urlParams, payload }) => | |
| 590 | − resolveRequestedLocalWorkspace( | |
| 591 | − "sources.credentialSubmit", | |
| 592 | − path.workspaceId, | |
| 593 | − ).pipe( | |
| 594 | − Effect.flatMap((executor) => | |
| 595 | − executor.local.credentials.submit({ | |
| 596 | − sourceId: path.sourceId, | |
| 597 | − interactionId: urlParams.interactionId, | |
| 598 | − action: | |
| 599 | − payload.action === "cancel" | |
| 600 | − ? "cancel" | |
| 601 | − : payload.action === "continue" | |
| 602 | − ? "continue" | |
| 603 | − : "submit", | |
| 604 | − token: payload.token, | |
| 605 | − }), | |
| 606 | − ), | |
| 607 | − Effect.map((result) => | |
| 608 | − htmlResponse( | |
| 609 | − credentialPageDocument({ | |
| 610 | − title: | |
| 611 | − result.kind === "stored" | |
| 612 | − ? "Source Credential Stored" | |
| 613 | − : result.kind === "continued" | |
| 614 | − ? "Source Access Updated" | |
| 615 | − : "Source Credential Request Cancelled", | |
| 616 | − eyebrow: "Executor", | |
| 617 | − message: | |
| 618 | − result.kind === "stored" | |
| 619 | − ? "Executor stored the credential and resumed the source connection." | |
| 620 | − : result.kind === "continued" | |
| 621 | − ? "Executor resumed the source connection without stored credentials." | |
| 622 | − : "Executor cancelled the source credential request.", | |
| 623 | − sourceLabel: result.sourceLabel, | |
| 624 | − endpoint: result.endpoint, | |
| 625 | − interactionId: urlParams.interactionId, | |
| 626 | − state: | |
| 627 | − result.kind === "stored" | |
| 628 | − ? "stored" | |
| 629 | − : result.kind === "continued" | |
| 630 | − ? "continued" | |
| 631 | − : "cancelled", | |
| 632 | − }), | |
| 633 | − ), | |
| 634 | − ), | |
| 635 | − Effect.catchAll((error) => { | |
| 636 | − if (error instanceof ControlPlaneBadRequestError) { | |
| 637 | − return credentialSubmitErrorResponse({ | |
| 638 | − workspaceId: path.workspaceId, | |
| 639 | − sourceId: path.sourceId, | |
| 640 | − interactionId: urlParams.interactionId, | |
| 641 | − message: error.message, | |
| 642 | − status: credentialErrorStatus(error), | |
| 643 | − }); | |
| 644 | − } | |
| 645 | − | |
| 646 | − return Effect.succeed( | |
| 647 | − credentialErrorResponse({ | |
| 648 | − title: | |
| 649 | − error instanceof ControlPlaneNotFoundError | |
| 650 | − ? "Source Credential Request Unavailable" | |
| 651 | − : "Source Credential Request Failed", | |
| 652 | − message: | |
| 653 | − error instanceof Error ? error.message : "Source credential request failed", | |
| 654 | − status: | |
| 655 | − error instanceof ControlPlaneNotFoundError | |
| 656 | − || error instanceof ControlPlaneStorageError | |
| 657 | − ? credentialErrorStatus(error) | |
| 658 | − : 500, | |
| 659 | − }), | |
| 660 | − ); | |
| 661 | − }), | |
| 662 | − ), | |
| 663 | − ) | |
| 664 | 84 | ); |
| @@ -24,7 +24,6 @@ import { · 23 unmodified lines | ||
| 24 | 24 | SecretMaterialUpdaterService, |
| 25 | 25 | type ExecutorStateStoreShape, |
| 26 | 26 | type ScopeInternalToolContext as WorkspaceInternalToolContext, |
| 27 | − RuntimeSourceAuthService, | |
| 28 | 27 | RuntimeSourceCatalogSyncService, |
| 29 | 28 | RuntimeSourceStore, |
| 30 | 29 | RuntimeSourceStoreService, |
| @@ -69,7 +68,6 @@ import { · 38 unmodified lines | ||
| 69 | 68 | removeSource, |
| 70 | 69 | updateLocalSecret, |
| 71 | 70 | updatePolicy, |
| 72 | − updateSource, | |
| 73 | 71 | } from "@executor/platform-sdk/operations"; |
| 74 | 72 | import { |
| 75 | 73 | CreatePolicyPayloadSchema, |
| @@ -77,10 +75,6 @@ import { · 1 unmodified line | ||
| 77 | 75 | type UpdatePolicyPayload, |
| 78 | 76 | UpdatePolicyPayloadSchema, |
| 79 | 77 | } from "@executor/platform-sdk/contracts"; |
| 80 | −import { | |
| 81 | − UpdateSourcePayloadSchema, | |
| 82 | −} from "@executor/platform-sdk/contracts"; | |
| 83 | − | |
| 84 | 78 | const emptyInputSchema = Schema.standardSchemaV1(Schema.Struct({})); |
| 85 | 79 | const localInstallationOutputSchema = Schema.standardSchemaV1( |
| 86 | 80 | LocalInstallationSchema, |
| @@ -117,12 +111,6 @@ const getSourceInputSchema = Schema.standardSchemaV1( · 30 unmodified lines | ||
| 117 | 111 | sourceId: SourceIdSchema, |
| 118 | 112 | }), |
| 119 | 113 | ); |
| 120 | −const updateSourceInputSchema = Schema.standardSchemaV1( | |
| 121 | − Schema.Struct({ | |
| 122 | − sourceId: SourceIdSchema, | |
| 123 | − payload: UpdateSourcePayloadSchema, | |
| 124 | − }), | |
| 125 | −); | |
| 126 | 114 | const inspectToolInputSchema = Schema.standardSchemaV1( |
| 127 | 115 | Schema.Struct({ |
| 128 | 116 | sourceId: SourceIdSchema, |
| @@ -386,28 +374,6 @@ export const createWorkspaceExecutorAdminToolMap = ( · 257 unmodified lines | ||
| 386 | 374 | }, |
| 387 | 375 | metadata, |
| 388 | 376 | }), |
| 389 | − "executor.sources.update": toTool({ | |
| 390 | − tool: { | |
| 391 | − description: "Update a source definition in the current workspace.", | |
| 392 | − inputSchema: updateSourceInputSchema, | |
| 393 | − outputSchema: sourceOutputSchema, | |
| 394 | − execute: (payload: { | |
| 395 | − sourceId: string; | |
| 396 | − payload: Record<string, unknown>; | |
| 397 | − }) => | |
| 398 | − runRuntimeEffect({ | |
| 399 | − effect: updateSource({ | |
| 400 | − scopeId: input.scopeId, | |
| 401 | − sourceId: payload.sourceId as never, | |
| 402 | − actorScopeId: input.actorScopeId as never, | |
| 403 | − payload: payload.payload as never, | |
| 404 | − }), | |
| 405 | − runtimeLayer, | |
| 406 | − runtimeLocalScope: input.runtimeLocalScope, | |
| 407 | − }), | |
| 408 | − }, | |
| 409 | − metadata, | |
| 410 | − }), | |
| 411 | 377 | "executor.sources.remove": toTool({ |
| 412 | 378 | tool: { |
| 413 | 379 | description: "Remove a source from the current workspace.", |
| @@ -674,22 +640,6 @@ export const createExecutorAdminToolMap = (input: { · 260 unmodified lines | ||
| 674 | 640 | }, |
| 675 | 641 | metadata, |
| 676 | 642 | }), |
| 677 | − "executor.sources.update": toTool({ | |
| 678 | − tool: { | |
| 679 | − description: "Update a source definition in the current workspace.", | |
| 680 | − inputSchema: updateSourceInputSchema, | |
| 681 | − outputSchema: sourceOutputSchema, | |
| 682 | − execute: (payload: { | |
| 683 | − sourceId: string; | |
| 684 | − payload: Record<string, unknown>; | |
| 685 | − }) => | |
| 686 | − input.executor.sources.update( | |
| 687 | − payload.sourceId as never, | |
| 688 | − payload.payload as never, | |
| 689 | − ), | |
| 690 | − }, | |
| 691 | − metadata, | |
| 692 | − }), | |
| 693 | 643 | "executor.sources.remove": toTool({ |
| 694 | 644 | tool: { |
| 695 | 645 | description: "Remove a source from the current workspace.", |
| @@ -188,10 +188,9 @@ const copyRecursive = ( · 187 unmodified lines | ||
| 188 | 188 | const sanitizeSourceConfig = ( |
| 189 | 189 | sourceConfig: NonNullable<LocalExecutorConfig["sources"]>[string], |
| 190 | 190 | ): NonNullable<LocalExecutorConfig["sources"]>[string] => { |
| 191 | − const { auth: _ignoredAuth, ...connection } = sourceConfig.connection; | |
| 192 | 191 | return { |
| 193 | 192 | ...sourceConfig, |
| 194 | − connection, | |
| 193 | + connection: sourceConfig.connection, | |
| 195 | 194 | }; |
| 196 | 195 | }; |
| 197 | 196 | |
| @@ -1,166 +0,0 @@ | ||
| 1 | −import { tmpdir } from "node:os"; | |
| 2 | −import { dirname, join } from "node:path"; | |
| 3 | −import { FileSystem } from "@effect/platform"; | |
| 4 | −import { NodeFileSystem } from "@effect/platform-node"; | |
| 5 | −import { describe, expect, it } from "@effect/vitest"; | |
| 6 | −import * as Effect from "effect/Effect"; | |
| 7 | − | |
| 8 | −import type { ResolvedLocalWorkspaceContext } from "./config"; | |
| 9 | −import { | |
| 10 | − loadLocalExecutorStateSnapshot, | |
| 11 | − localExecutorStatePath, | |
| 12 | − writeLocalExecutorStateSnapshot, | |
| 13 | −} from "./executor-state-store"; | |
| 14 | − | |
| 15 | −const makeContext = (): Effect.Effect< | |
| 16 | − ResolvedLocalWorkspaceContext, | |
| 17 | − never, | |
| 18 | − FileSystem.FileSystem | |
| 19 | −> => | |
| 20 | − Effect.gen(function* () { | |
| 21 | − const fs = yield* FileSystem.FileSystem; | |
| 22 | − const workspaceRoot = yield* fs.makeTempDirectory({ | |
| 23 | − directory: tmpdir(), | |
| 24 | − prefix: "executor-state-store-", | |
| 25 | − }).pipe(Effect.orDie); | |
| 26 | − | |
| 27 | − return { | |
| 28 | − cwd: workspaceRoot, | |
| 29 | − workspaceRoot, | |
| 30 | − workspaceName: "executor-state-store", | |
| 31 | − configDirectory: join(workspaceRoot, ".executor"), | |
| 32 | − projectConfigPath: join(workspaceRoot, ".executor", "executor.jsonc"), | |
| 33 | − homeConfigPath: join(workspaceRoot, ".executor-home.jsonc"), | |
| 34 | − homeStateDirectory: join(workspaceRoot, ".executor-home-state"), | |
| 35 | − artifactsDirectory: join(workspaceRoot, ".executor", "artifacts"), | |
| 36 | − stateDirectory: join(workspaceRoot, ".executor", "state"), | |
| 37 | − }; | |
| 38 | − }); | |
| 39 | − | |
| 40 | −describe("local-executor-state-store", () => { | |
| 41 | − it.effect("stores secret-bearing executor state outside the workspace", () => | |
| 42 | − Effect.gen(function* () { | |
| 43 | − const fs = yield* FileSystem.FileSystem; | |
| 44 | − const context = yield* makeContext(); | |
| 45 | − const expectedPath = localExecutorStatePath(context); | |
| 46 | − const workspacePath = join(context.stateDirectory, "executor-state.json"); | |
| 47 | − | |
| 48 | − yield* writeLocalExecutorStateSnapshot({ | |
| 49 | − context, | |
| 50 | − state: { | |
| 51 | − version: 1, | |
| 52 | − authArtifacts: [], | |
| 53 | − authLeases: [], | |
| 54 | − sourceOauthClients: [], | |
| 55 | − scopeOauthClients: [], | |
| 56 | − providerAuthGrants: [], | |
| 57 | − sourceAuthSessions: [], | |
| 58 | − secretMaterials: [], | |
| 59 | − executions: [], | |
| 60 | − executionInteractions: [], | |
| 61 | − executionSteps: [], | |
| 62 | − }, | |
| 63 | − }); | |
| 64 | − | |
| 65 | − expect(expectedPath.startsWith(context.homeStateDirectory)).toBe(true); | |
| 66 | − expect(yield* fs.exists(expectedPath)).toBe(true); | |
| 67 | − expect(yield* fs.exists(workspacePath)).toBe(false); | |
| 68 | − | |
| 69 | − const loaded = yield* loadLocalExecutorStateSnapshot(context); | |
| 70 | − expect(loaded.version).toBe(1); | |
| 71 | − expect(loaded.secretMaterials).toEqual([]); | |
| 72 | − | |
| 73 | − if (process.platform !== "win32") { | |
| 74 | − expect((yield* fs.stat(expectedPath)).mode & 0o777).toBe(0o600); | |
| 75 | − } | |
| 76 | − }).pipe(Effect.provide(NodeFileSystem.layer)), | |
| 77 | − ); | |
| 78 | − | |
| 79 | − it.effect("migrates legacy workspace-shaped executor state on load", () => | |
| 80 | − Effect.gen(function* () { | |
| 81 | − const fs = yield* FileSystem.FileSystem; | |
| 82 | − const context = yield* makeContext(); | |
| 83 | − const path = localExecutorStatePath(context); | |
| 84 | − | |
| 85 | − yield* fs.makeDirectory(dirname(path), { recursive: true }).pipe( | |
| 86 | − Effect.orDie, | |
| 87 | − ); | |
| 88 | − yield* fs.writeFileString( | |
| 89 | − path, | |
| 90 | − `${JSON.stringify({ | |
| 91 | − version: 1, | |
| 92 | − authArtifacts: [ | |
| 93 | − { | |
| 94 | − id: "auth_art_test", | |
| 95 | − workspaceId: "ws_test", | |
| 96 | − sourceId: "github", | |
| 97 | − actorAccountId: "acc_test", | |
| 98 | − slot: "runtime", | |
| 99 | − artifactKind: "static_bearer", | |
| 100 | − configJson: | |
| 101 | − "{\"headerName\":\"Authorization\",\"prefix\":\"Bearer \",\"token\":{\"providerId\":\"test\",\"handle\":\"secret_test\"}}", | |
| 102 | − grantSetJson: null, | |
| 103 | − createdAt: 1, | |
| 104 | − updatedAt: 1, | |
| 105 | − }, | |
| 106 | − ], | |
| 107 | − authLeases: [], | |
| 108 | − sourceOauthClients: [], | |
| 109 | − workspaceOauthClients: [], | |
| 110 | − providerAuthGrants: [], | |
| 111 | − sourceAuthSessions: [], | |
| 112 | − secretMaterials: [ | |
| 113 | − { | |
| 114 | − id: "secret_test", | |
| 115 | − providerId: "test", | |
| 116 | − handle: "secret_test", | |
| 117 | − name: null, | |
| 118 | − purpose: "auth_material", | |
| 119 | − value: null, | |
| 120 | − createdAt: 1, | |
| 121 | − updatedAt: 1, | |
| 122 | − }, | |
| 123 | − ], | |
| 124 | − executions: [ | |
| 125 | − { | |
| 126 | − id: "exec_test", | |
| 127 | − workspaceId: "ws_test", | |
| 128 | − createdByAccountId: "acc_test", | |
| 129 | − status: "completed", | |
| 130 | − code: "return 1;", | |
| 131 | − resultJson: "1", | |
| 132 | − errorText: null, | |
| 133 | − logsJson: null, | |
| 134 | − startedAt: 1, | |
| 135 | − completedAt: 1, | |
| 136 | − createdAt: 1, | |
| 137 | − updatedAt: 1, | |
| 138 | − }, | |
| 139 | − ], | |
| 140 | − executionInteractions: [], | |
| 141 | − executionSteps: [], | |
| 142 | − }, null, 2)}\n`, | |
| 143 | − { mode: 0o600 }, | |
| 144 | − ).pipe(Effect.orDie); | |
| 145 | − | |
| 146 | − const loaded = yield* loadLocalExecutorStateSnapshot(context); | |
| 147 | − expect(loaded.authArtifacts[0]?.scopeId).toBe("ws_test"); | |
| 148 | − expect(loaded.authArtifacts[0]?.actorScopeId).toBe("acc_test"); | |
| 149 | − expect(loaded.executions[0]?.scopeId).toBe("ws_test"); | |
| 150 | − expect(loaded.executions[0]?.createdByScopeId).toBe("acc_test"); | |
| 151 | − expect(loaded.scopeOauthClients).toEqual([]); | |
| 152 | − | |
| 153 | − const migratedContent = yield* fs.readFileString(path, "utf8").pipe( | |
| 154 | − Effect.orDie, | |
| 155 | − ); | |
| 156 | − expect(migratedContent.includes("\"workspaceId\"")).toBe(false); | |
| 157 | − expect(migratedContent.includes("\"actorAccountId\"")).toBe(false); | |
| 158 | − expect(migratedContent.includes("\"createdByAccountId\"")).toBe(false); | |
| 159 | − expect(migratedContent.includes("\"workspaceOauthClients\"")).toBe(false); | |
| 160 | − expect(migratedContent.includes("\"scopeId\"")).toBe(true); | |
| 161 | − expect(migratedContent.includes("\"actorScopeId\"")).toBe(true); | |
| 162 | − expect(migratedContent.includes("\"createdByScopeId\"")).toBe(true); | |
| 163 | − expect(migratedContent.includes("\"scopeOauthClients\"")).toBe(true); | |
| 164 | − }).pipe(Effect.provide(NodeFileSystem.layer)), | |
| 165 | − ); | |
| 166 | −}); | |
| @@ -4,26 +4,14 @@ import { FileSystem } from "@effect/platform"; · 3 unmodified lines | ||
| 4 | 4 | import { NodeFileSystem } from "@effect/platform-node"; |
| 5 | 5 | |
| 6 | 6 | import { |
| 7 | − AuthArtifactSchema, | |
| 8 | − AuthLeaseSchema, | |
| 9 | − type AuthArtifact, | |
| 10 | − type AuthLease, | |
| 11 | 7 | type Execution, |
| 12 | 8 | type ExecutionInteraction, |
| 13 | 9 | type ExecutionStep, |
| 14 | 10 | ExecutionInteractionSchema, |
| 15 | 11 | ExecutionSchema, |
| 16 | 12 | ExecutionStepSchema, |
| 17 | − type ProviderAuthGrant, | |
| 18 | − ProviderAuthGrantSchema, | |
| 19 | 13 | SecretMaterialSchema, |
| 20 | 14 | type SecretMaterial, |
| 21 | − type SourceAuthSession, | |
| 22 | − SourceAuthSessionSchema, | |
| 23 | − type ScopeOauthClient, | |
| 24 | − ScopeOauthClientSchema, | |
| 25 | − type ScopedSourceOauthClient, | |
| 26 | − ScopedSourceOauthClientSchema, | |
| 27 | 15 | } from "@executor/platform-sdk/schema"; |
| 28 | 16 | import * as Effect from "effect/Effect"; |
| 29 | 17 | import * as Option from "effect/Option"; |
| @@ -41,12 +29,6 @@ const LOCAL_EXECUTOR_STATE_BASENAME = "executor-state.json"; · 11 unmodified lines | ||
| 41 | 29 | |
| 42 | 30 | const LocalExecutorStateSnapshotSchema = Schema.Struct({ |
| 43 | 31 | version: Schema.Literal(LOCAL_EXECUTOR_STATE_VERSION), |
| 44 | − authArtifacts: Schema.Array(AuthArtifactSchema), | |
| 45 | − authLeases: Schema.Array(AuthLeaseSchema), | |
| 46 | − sourceOauthClients: Schema.Array(ScopedSourceOauthClientSchema), | |
| 47 | − scopeOauthClients: Schema.Array(ScopeOauthClientSchema), | |
| 48 | − providerAuthGrants: Schema.Array(ProviderAuthGrantSchema), | |
| 49 | − sourceAuthSessions: Schema.Array(SourceAuthSessionSchema), | |
| 50 | 32 | secretMaterials: Schema.Array(SecretMaterialSchema), |
| 51 | 33 | executions: Schema.Array(ExecutionSchema), |
| 52 | 34 | executionInteractions: Schema.Array(ExecutionInteractionSchema), |
| @@ -66,12 +48,6 @@ const decodeLocalExecutorStateSnapshot = Schema.decodeUnknown( · 13 unmodified lines | ||
| 66 | 48 | |
| 67 | 49 | const defaultLocalExecutorStateSnapshot = (): LocalExecutorStateSnapshot => ({ |
| 68 | 50 | version: LOCAL_EXECUTOR_STATE_VERSION, |
| 69 | − authArtifacts: [], | |
| 70 | − authLeases: [], | |
| 71 | − sourceOauthClients: [], | |
| 72 | − scopeOauthClients: [], | |
| 73 | − providerAuthGrants: [], | |
| 74 | − sourceAuthSessions: [], | |
| 75 | 51 | secretMaterials: [], |
| 76 | 52 | executions: [], |
| 77 | 53 | executionInteractions: [], |
| @@ -144,18 +120,6 @@ const mapFileSystemError = (path: string, action: string) => (cause: unknown) => · 66 unmodified lines | ||
| 144 | 120 | details: unknownLocalErrorDetails(cause), |
| 145 | 121 | }); |
| 146 | 122 | |
| 147 | −const actorEquals = ( | |
| 148 | − left: string | null | undefined, | |
| 149 | − right: string | null | undefined, | |
| 150 | −): boolean => (left ?? null) === (right ?? null); | |
| 151 | − | |
| 152 | −const sortByUpdatedAtAndIdAsc = <T extends { updatedAt: number; id: string }>( | |
| 153 | − values: readonly T[], | |
| 154 | −): T[] => | |
| 155 | − [...values].sort((left, right) => | |
| 156 | − left.updatedAt - right.updatedAt || left.id.localeCompare(right.id), | |
| 157 | − ); | |
| 158 | − | |
| 159 | 123 | const sortByUpdatedAtAndIdDesc = <T extends { updatedAt: number; id: string }>( |
| 160 | 124 | values: readonly T[], |
| 161 | 125 | ): T[] => |
| @@ -264,140 +228,11 @@ const mergeById = <T extends { id: string }>( · 102 unmodified lines | ||
| 264 | 228 | return [...merged.values()]; |
| 265 | 229 | }; |
| 266 | 230 | |
| 267 | −const mergeAuthLeases = ( | |
| 268 | − current: readonly AuthLease[], | |
| 269 | − imported: readonly AuthLease[], | |
| 270 | −): AuthLease[] => { | |
| 271 | − const merged = new Map<string, AuthLease>(); | |
| 272 | − | |
| 273 | − for (const lease of imported) { | |
| 274 | − merged.set(lease.authArtifactId, cloneValue(lease)); | |
| 275 | − } | |
| 276 | − | |
| 277 | − for (const lease of current) { | |
| 278 | − merged.set(lease.authArtifactId, cloneValue(lease)); | |
| 279 | − } | |
| 280 | − | |
| 281 | − return [...merged.values()]; | |
| 282 | −}; | |
| 283 | − | |
| 284 | −const mergeAuthArtifacts = ( | |
| 285 | − current: readonly AuthArtifact[], | |
| 286 | − imported: readonly AuthArtifact[], | |
| 287 | −): AuthArtifact[] => { | |
| 288 | − const merged = new Map<string, AuthArtifact>(); | |
| 289 | − | |
| 290 | − for (const artifact of imported) { | |
| 291 | − merged.set( | |
| 292 | − [ | |
| 293 | − artifact.scopeId, | |
| 294 | − artifact.sourceId, | |
| 295 | − artifact.actorScopeId ?? "", | |
| 296 | − artifact.slot, | |
| 297 | − ].join("::"), | |
| 298 | − cloneValue(artifact), | |
| 299 | − ); | |
| 300 | − } | |
| 301 | − | |
| 302 | − for (const artifact of current) { | |
| 303 | − merged.set( | |
| 304 | − [ | |
| 305 | − artifact.scopeId, | |
| 306 | − artifact.sourceId, | |
| 307 | − artifact.actorScopeId ?? "", | |
| 308 | − artifact.slot, | |
| 309 | − ].join("::"), | |
| 310 | − cloneValue(artifact), | |
| 311 | − ); | |
| 312 | − } | |
| 313 | − | |
| 314 | − return [...merged.values()]; | |
| 315 | −}; | |
| 316 | − | |
| 317 | −const mergeSourceOauthClients = ( | |
| 318 | − current: readonly ScopedSourceOauthClient[], | |
| 319 | − imported: readonly ScopedSourceOauthClient[], | |
| 320 | −): ScopedSourceOauthClient[] => { | |
| 321 | − const merged = new Map<string, ScopedSourceOauthClient>(); | |
| 322 | − | |
| 323 | − for (const oauthClient of imported) { | |
| 324 | − merged.set( | |
| 325 | − [oauthClient.scopeId, oauthClient.sourceId, oauthClient.providerKey].join( | |
| 326 | − "::", | |
| 327 | − ), | |
| 328 | − cloneValue(oauthClient), | |
| 329 | − ); | |
| 330 | − } | |
| 331 | − | |
| 332 | − for (const oauthClient of current) { | |
| 333 | − merged.set( | |
| 334 | − [oauthClient.scopeId, oauthClient.sourceId, oauthClient.providerKey].join( | |
| 335 | − "::", | |
| 336 | − ), | |
| 337 | − cloneValue(oauthClient), | |
| 338 | − ); | |
| 339 | − } | |
| 340 | − | |
| 341 | − return [...merged.values()]; | |
| 342 | −}; | |
| 343 | − | |
| 344 | −const mergeWorkspaceOauthClients = ( | |
| 345 | − current: readonly ScopeOauthClient[], | |
| 346 | − imported: readonly ScopeOauthClient[], | |
| 347 | −): ScopeOauthClient[] => { | |
| 348 | − const merged = new Map<string, ScopeOauthClient>(); | |
| 349 | − | |
| 350 | − for (const oauthClient of imported) { | |
| 351 | − merged.set( | |
| 352 | − [oauthClient.scopeId, oauthClient.providerKey, oauthClient.id].join("::"), | |
| 353 | − cloneValue(oauthClient), | |
| 354 | − ); | |
| 355 | − } | |
| 356 | − | |
| 357 | − for (const oauthClient of current) { | |
| 358 | − merged.set( | |
| 359 | − [oauthClient.scopeId, oauthClient.providerKey, oauthClient.id].join("::"), | |
| 360 | − cloneValue(oauthClient), | |
| 361 | − ); | |
| 362 | − } | |
| 363 | − | |
| 364 | − return [...merged.values()]; | |
| 365 | −}; | |
| 366 | − | |
| 367 | −const mergeProviderAuthGrants = ( | |
| 368 | − current: readonly ProviderAuthGrant[], | |
| 369 | − imported: readonly ProviderAuthGrant[], | |
| 370 | −): ProviderAuthGrant[] => mergeById(current, imported); | |
| 371 | − | |
| 372 | 231 | export const mergeImportedLocalExecutorStateSnapshot = (input: { |
| 373 | 232 | current: LocalExecutorStateSnapshot; |
| 374 | 233 | imported: Partial<Omit<LocalExecutorStateSnapshot, "version">>; |
| 375 | 234 | }): LocalExecutorStateSnapshot => ({ |
| 376 | 235 | version: LOCAL_EXECUTOR_STATE_VERSION, |
| 377 | − authArtifacts: mergeAuthArtifacts( | |
| 378 | − input.current.authArtifacts, | |
| 379 | − input.imported.authArtifacts ?? [], | |
| 380 | − ), | |
| 381 | − authLeases: mergeAuthLeases( | |
| 382 | − input.current.authLeases, | |
| 383 | − input.imported.authLeases ?? [], | |
| 384 | − ), | |
| 385 | − sourceOauthClients: mergeSourceOauthClients( | |
| 386 | − input.current.sourceOauthClients, | |
| 387 | − input.imported.sourceOauthClients ?? [], | |
| 388 | − ), | |
| 389 | − scopeOauthClients: mergeWorkspaceOauthClients( | |
| 390 | − input.current.scopeOauthClients, | |
| 391 | − input.imported.scopeOauthClients ?? [], | |
| 392 | − ), | |
| 393 | − providerAuthGrants: mergeProviderAuthGrants( | |
| 394 | − input.current.providerAuthGrants, | |
| 395 | − input.imported.providerAuthGrants ?? [], | |
| 396 | − ), | |
| 397 | − sourceAuthSessions: mergeById( | |
| 398 | − input.current.sourceAuthSessions, | |
| 399 | − input.imported.sourceAuthSessions ?? [], | |
| 400 | − ), | |
| 401 | 236 | secretMaterials: mergeById( |
| 402 | 237 | input.current.secretMaterials, |
| 403 | 238 | input.imported.secretMaterials ?? [], |
| @@ -499,474 +334,6 @@ export const createLocalExecutorStateStore = ( · 95 unmodified lines | ||
| 499 | 334 | const stateManager = createStateManager(context, fileSystem); |
| 500 | 335 | |
| 501 | 336 | return { |
| 502 | − authArtifacts: { | |
| 503 | − listByScopeId: (scopeId: AuthArtifact["scopeId"]) => | |
| 504 | − stateManager.read((state) => | |
| 505 | − sortByUpdatedAtAndIdAsc( | |
| 506 | − state.authArtifacts.filter((artifact) => artifact.scopeId === scopeId), | |
| 507 | − ), | |
| 508 | − ), | |
| 509 | − | |
| 510 | − listByScopeAndSourceId: (input: { | |
| 511 | − scopeId: AuthArtifact["scopeId"]; | |
| 512 | − sourceId: AuthArtifact["sourceId"]; | |
| 513 | − }) => | |
| 514 | − stateManager.read((state) => | |
| 515 | − sortByUpdatedAtAndIdAsc( | |
| 516 | − state.authArtifacts.filter( | |
| 517 | − (artifact) => | |
| 518 | − artifact.scopeId === input.scopeId | |
| 519 | − && artifact.sourceId === input.sourceId, | |
| 520 | − ), | |
| 521 | − ), | |
| 522 | − ), | |
| 523 | − | |
| 524 | − getByScopeSourceAndActor: (input: { | |
| 525 | − scopeId: AuthArtifact["scopeId"]; | |
| 526 | − sourceId: AuthArtifact["sourceId"]; | |
| 527 | − actorScopeId: AuthArtifact["actorScopeId"]; | |
| 528 | − slot: AuthArtifact["slot"]; | |
| 529 | − }) => | |
| 530 | − stateManager.read((state) => { | |
| 531 | − const artifact = state.authArtifacts.find( | |
| 532 | − (candidate) => | |
| 533 | − candidate.scopeId === input.scopeId | |
| 534 | − && candidate.sourceId === input.sourceId | |
| 535 | − && candidate.slot === input.slot | |
| 536 | − && actorEquals(candidate.actorScopeId, input.actorScopeId), | |
| 537 | − ); | |
| 538 | − | |
| 539 | − return artifact ? Option.some(cloneValue(artifact)) : Option.none<AuthArtifact>(); | |
| 540 | − }), | |
| 541 | − | |
| 542 | − upsert: (artifact: AuthArtifact) => | |
| 543 | − stateManager.mutate((state) => { | |
| 544 | − const nextArtifacts = state.authArtifacts.filter( | |
| 545 | − (candidate) => | |
| 546 | − !( | |
| 547 | − candidate.scopeId === artifact.scopeId | |
| 548 | − && candidate.sourceId === artifact.sourceId | |
| 549 | − && candidate.slot === artifact.slot | |
| 550 | − && actorEquals(candidate.actorScopeId, artifact.actorScopeId) | |
| 551 | − ), | |
| 552 | − ); | |
| 553 | − nextArtifacts.push(cloneValue(artifact)); | |
| 554 | − | |
| 555 | − return { | |
| 556 | − state: { | |
| 557 | − ...state, | |
| 558 | − authArtifacts: nextArtifacts, | |
| 559 | − }, | |
| 560 | − value: undefined, | |
| 561 | − } satisfies StateMutationResult<void>; | |
| 562 | − }), | |
| 563 | − | |
| 564 | − removeByScopeSourceAndActor: (input: { | |
| 565 | − scopeId: AuthArtifact["scopeId"]; | |
| 566 | − sourceId: AuthArtifact["sourceId"]; | |
| 567 | − actorScopeId: AuthArtifact["actorScopeId"]; | |
| 568 | − slot?: AuthArtifact["slot"]; | |
| 569 | − }) => | |
| 570 | − stateManager.mutate((state) => { | |
| 571 | − const nextArtifacts = state.authArtifacts.filter( | |
| 572 | − (candidate) => | |
| 573 | − candidate.scopeId !== input.scopeId | |
| 574 | − || candidate.sourceId !== input.sourceId | |
| 575 | − || !actorEquals(candidate.actorScopeId, input.actorScopeId) | |
| 576 | − || (input.slot !== undefined && candidate.slot !== input.slot), | |
| 577 | − ); | |
| 578 | − | |
| 579 | − return { | |
| 580 | − state: { | |
| 581 | − ...state, | |
| 582 | − authArtifacts: nextArtifacts, | |
| 583 | − }, | |
| 584 | − value: nextArtifacts.length !== state.authArtifacts.length, | |
| 585 | − } satisfies StateMutationResult<boolean>; | |
| 586 | − }), | |
| 587 | − | |
| 588 | − removeByScopeAndSourceId: (input: { | |
| 589 | − scopeId: AuthArtifact["scopeId"]; | |
| 590 | − sourceId: AuthArtifact["sourceId"]; | |
| 591 | − }) => | |
| 592 | − stateManager.mutate((state) => { | |
| 593 | − const nextArtifacts = state.authArtifacts.filter( | |
| 594 | − (candidate) => | |
| 595 | − candidate.scopeId !== input.scopeId | |
| 596 | − || candidate.sourceId !== input.sourceId, | |
| 597 | − ); | |
| 598 | − | |
| 599 | − return { | |
| 600 | − state: { | |
| 601 | − ...state, | |
| 602 | − authArtifacts: nextArtifacts, | |
| 603 | − }, | |
| 604 | − value: state.authArtifacts.length - nextArtifacts.length, | |
| 605 | − } satisfies StateMutationResult<number>; | |
| 606 | − }), | |
| 607 | − }, | |
| 608 | − | |
| 609 | − authLeases: { | |
| 610 | − listAll: () => | |
| 611 | − stateManager.read((state) => sortByUpdatedAtAndIdAsc(state.authLeases)), | |
| 612 | − | |
| 613 | − getByAuthArtifactId: (authArtifactId: AuthLease["authArtifactId"]) => | |
| 614 | − stateManager.read((state) => { | |
| 615 | − const lease = state.authLeases.find( | |
| 616 | − (candidate) => candidate.authArtifactId === authArtifactId, | |
| 617 | − ); | |
| 618 | − return lease ? Option.some(cloneValue(lease)) : Option.none<AuthLease>(); | |
| 619 | − }), | |
| 620 | − | |
| 621 | − upsert: (lease: AuthLease) => | |
| 622 | − stateManager.mutate((state) => { | |
| 623 | − const nextLeases = state.authLeases.filter( | |
| 624 | − (candidate) => candidate.authArtifactId !== lease.authArtifactId, | |
| 625 | − ); | |
| 626 | − nextLeases.push(cloneValue(lease)); | |
| 627 | − | |
| 628 | − return { | |
| 629 | − state: { | |
| 630 | − ...state, | |
| 631 | − authLeases: nextLeases, | |
| 632 | − }, | |
| 633 | − value: undefined, | |
| 634 | − } satisfies StateMutationResult<void>; | |
| 635 | − }), | |
| 636 | − | |
| 637 | − removeByAuthArtifactId: (authArtifactId: AuthLease["authArtifactId"]) => | |
| 638 | − stateManager.mutate((state) => { | |
| 639 | − const nextLeases = state.authLeases.filter( | |
| 640 | − (candidate) => candidate.authArtifactId !== authArtifactId, | |
| 641 | − ); | |
| 642 | − | |
| 643 | − return { | |
| 644 | − state: { | |
| 645 | − ...state, | |
| 646 | − authLeases: nextLeases, | |
| 647 | − }, | |
| 648 | − value: nextLeases.length !== state.authLeases.length, | |
| 649 | − } satisfies StateMutationResult<boolean>; | |
| 650 | − }), | |
| 651 | − }, | |
| 652 | − | |
| 653 | − sourceOauthClients: { | |
| 654 | − getByScopeSourceAndProvider: (input: { | |
| 655 | − scopeId: ScopedSourceOauthClient["scopeId"]; | |
| 656 | − sourceId: ScopedSourceOauthClient["sourceId"]; | |
| 657 | − providerKey: string; | |
| 658 | − }) => | |
| 659 | − stateManager.read((state) => { | |
| 660 | − const oauthClient = state.sourceOauthClients.find( | |
| 661 | − (candidate) => | |
| 662 | − candidate.scopeId === input.scopeId | |
| 663 | − && candidate.sourceId === input.sourceId | |
| 664 | − && candidate.providerKey === input.providerKey, | |
| 665 | − ); | |
| 666 | − | |
| 667 | − return oauthClient | |
| 668 | − ? Option.some(cloneValue(oauthClient)) | |
| 669 | − : Option.none<ScopedSourceOauthClient>(); | |
| 670 | − }), | |
| 671 | − | |
| 672 | − upsert: (oauthClient: ScopedSourceOauthClient) => | |
| 673 | − stateManager.mutate((state) => { | |
| 674 | − const nextOauthClients = state.sourceOauthClients.filter( | |
| 675 | − (candidate) => | |
| 676 | − !( | |
| 677 | − candidate.scopeId === oauthClient.scopeId | |
| 678 | − && candidate.sourceId === oauthClient.sourceId | |
| 679 | − && candidate.providerKey === oauthClient.providerKey | |
| 680 | − ), | |
| 681 | − ); | |
| 682 | − nextOauthClients.push(cloneValue(oauthClient)); | |
| 683 | − | |
| 684 | − return { | |
| 685 | − state: { | |
| 686 | − ...state, | |
| 687 | − sourceOauthClients: nextOauthClients, | |
| 688 | − }, | |
| 689 | − value: undefined, | |
| 690 | − } satisfies StateMutationResult<void>; | |
| 691 | − }), | |
| 692 | − | |
| 693 | − removeByScopeAndSourceId: (input: { | |
| 694 | − scopeId: ScopedSourceOauthClient["scopeId"]; | |
| 695 | − sourceId: ScopedSourceOauthClient["sourceId"]; | |
| 696 | − }) => | |
| 697 | − stateManager.mutate((state) => { | |
| 698 | − const nextOauthClients = state.sourceOauthClients.filter( | |
| 699 | − (candidate) => | |
| 700 | − candidate.scopeId !== input.scopeId | |
| 701 | − || candidate.sourceId !== input.sourceId, | |
| 702 | − ); | |
| 703 | − | |
| 704 | − return { | |
| 705 | − state: { | |
| 706 | − ...state, | |
| 707 | − sourceOauthClients: nextOauthClients, | |
| 708 | − }, | |
| 709 | − value: state.sourceOauthClients.length - nextOauthClients.length, | |
| 710 | − } satisfies StateMutationResult<number>; | |
| 711 | − }), | |
| 712 | − }, | |
| 713 | − | |
| 714 | − scopeOauthClients: { | |
| 715 | − listByScopeAndProvider: (input: { | |
| 716 | − scopeId: ScopeOauthClient["scopeId"]; | |
| 717 | − providerKey: string; | |
| 718 | − }) => | |
| 719 | − stateManager.read((state) => | |
| 720 | − sortByUpdatedAtAndIdAsc( | |
| 721 | − state.scopeOauthClients.filter( | |
| 722 | − (candidate) => | |
| 723 | − candidate.scopeId === input.scopeId | |
| 724 | − && candidate.providerKey === input.providerKey, | |
| 725 | − ), | |
| 726 | − ), | |
| 727 | − ), | |
| 728 | − | |
| 729 | − getById: (id: ScopeOauthClient["id"]) => | |
| 730 | − stateManager.read((state) => { | |
| 731 | − const oauthClient = state.scopeOauthClients.find( | |
| 732 | − (candidate) => candidate.id === id, | |
| 733 | − ); | |
| 734 | − | |
| 735 | − return oauthClient | |
| 736 | − ? Option.some(cloneValue(oauthClient)) | |
| 737 | − : Option.none<ScopeOauthClient>(); | |
| 738 | − }), | |
| 739 | − | |
| 740 | − upsert: (oauthClient: ScopeOauthClient) => | |
| 741 | − stateManager.mutate((state) => { | |
| 742 | − const nextOauthClients = state.scopeOauthClients.filter( | |
| 743 | − (candidate) => candidate.id !== oauthClient.id, | |
| 744 | − ); | |
| 745 | − nextOauthClients.push(cloneValue(oauthClient)); | |
| 746 | − | |
| 747 | − return { | |
| 748 | − state: { | |
| 749 | − ...state, | |
| 750 | − scopeOauthClients: nextOauthClients, | |
| 751 | − }, | |
| 752 | − value: undefined, | |
| 753 | − } satisfies StateMutationResult<void>; | |
| 754 | − }), | |
| 755 | − | |
| 756 | − removeById: (id: ScopeOauthClient["id"]) => | |
| 757 | − stateManager.mutate((state) => { | |
| 758 | − const nextOauthClients = state.scopeOauthClients.filter( | |
| 759 | − (candidate) => candidate.id !== id, | |
| 760 | − ); | |
| 761 | − | |
| 762 | − return { | |
| 763 | − state: { | |
| 764 | − ...state, | |
| 765 | − scopeOauthClients: nextOauthClients, | |
| 766 | − }, | |
| 767 | − value: nextOauthClients.length !== state.scopeOauthClients.length, | |
| 768 | − } satisfies StateMutationResult<boolean>; | |
| 769 | − }), | |
| 770 | − }, | |
| 771 | − | |
| 772 | − providerAuthGrants: { | |
| 773 | − listByScopeId: (scopeId: ProviderAuthGrant["scopeId"]) => | |
| 774 | − stateManager.read((state) => | |
| 775 | − sortByUpdatedAtAndIdAsc( | |
| 776 | − state.providerAuthGrants.filter( | |
| 777 | − (grant) => grant.scopeId === scopeId, | |
| 778 | − ), | |
| 779 | − ), | |
| 780 | − ), | |
| 781 | − | |
| 782 | − listByScopeActorAndProvider: (input: { | |
| 783 | − scopeId: ProviderAuthGrant["scopeId"]; | |
| 784 | − actorScopeId: ProviderAuthGrant["actorScopeId"]; | |
| 785 | − providerKey: string; | |
| 786 | − }) => | |
| 787 | − stateManager.read((state) => | |
| 788 | − sortByUpdatedAtAndIdAsc( | |
| 789 | − state.providerAuthGrants.filter( | |
| 790 | − (grant) => | |
| 791 | − grant.scopeId === input.scopeId | |
| 792 | − && grant.providerKey === input.providerKey | |
| 793 | − && actorEquals(grant.actorScopeId, input.actorScopeId), | |
| 794 | − ), | |
| 795 | − ), | |
| 796 | − ), | |
| 797 | − | |
| 798 | − getById: (id: ProviderAuthGrant["id"]) => | |
| 799 | − stateManager.read((state) => { | |
| 800 | − const grant = state.providerAuthGrants.find( | |
| 801 | − (candidate) => candidate.id === id, | |
| 802 | − ); | |
| 803 | − | |
| 804 | − return grant | |
| 805 | − ? Option.some(cloneValue(grant)) | |
| 806 | − : Option.none<ProviderAuthGrant>(); | |
| 807 | − }), | |
| 808 | − | |
| 809 | − upsert: (grant: ProviderAuthGrant) => | |
| 810 | − stateManager.mutate((state) => { | |
| 811 | − const nextGrants = state.providerAuthGrants.filter( | |
| 812 | − (candidate) => candidate.id !== grant.id, | |
| 813 | − ); | |
| 814 | − nextGrants.push(cloneValue(grant)); | |
| 815 | − | |
| 816 | − return { | |
| 817 | − state: { | |
| 818 | − ...state, | |
| 819 | − providerAuthGrants: nextGrants, | |
| 820 | − }, | |
| 821 | − value: undefined, | |
| 822 | − } satisfies StateMutationResult<void>; | |
| 823 | − }), | |
| 824 | − | |
| 825 | − removeById: (id: ProviderAuthGrant["id"]) => | |
| 826 | − stateManager.mutate((state) => { | |
| 827 | − const nextGrants = state.providerAuthGrants.filter( | |
| 828 | − (candidate) => candidate.id !== id, | |
| 829 | − ); | |
| 830 | − | |
| 831 | − return { | |
| 832 | − state: { | |
| 833 | − ...state, | |
| 834 | − providerAuthGrants: nextGrants, | |
| 835 | − }, | |
| 836 | − value: nextGrants.length !== state.providerAuthGrants.length, | |
| 837 | − } satisfies StateMutationResult<boolean>; | |
| 838 | − }), | |
| 839 | − }, | |
| 840 | − | |
| 841 | − sourceAuthSessions: { | |
| 842 | − listAll: () => | |
| 843 | − stateManager.read((state) => sortByUpdatedAtAndIdAsc(state.sourceAuthSessions)), | |
| 844 | − | |
| 845 | − listByScopeId: (scopeId: SourceAuthSession["scopeId"]) => | |
| 846 | − stateManager.read((state) => | |
| 847 | − sortByUpdatedAtAndIdAsc( | |
| 848 | − state.sourceAuthSessions.filter( | |
| 849 | − (session) => session.scopeId === scopeId, | |
| 850 | − ), | |
| 851 | − ), | |
| 852 | − ), | |
| 853 | − | |
| 854 | − getById: (id: SourceAuthSession["id"]) => | |
| 855 | − stateManager.read((state) => { | |
| 856 | − const session = state.sourceAuthSessions.find( | |
| 857 | − (candidate) => candidate.id === id, | |
| 858 | − ); | |
| 859 | − return session | |
| 860 | − ? Option.some(cloneValue(session)) | |
| 861 | − : Option.none<SourceAuthSession>(); | |
| 862 | − }), | |
| 863 | − | |
| 864 | − getByState: (stateValue: SourceAuthSession["state"]) => | |
| 865 | − stateManager.read((state) => { | |
| 866 | − const session = state.sourceAuthSessions.find( | |
| 867 | − (candidate) => candidate.state === stateValue, | |
| 868 | − ); | |
| 869 | − return session | |
| 870 | − ? Option.some(cloneValue(session)) | |
| 871 | − : Option.none<SourceAuthSession>(); | |
| 872 | − }), | |
| 873 | − | |
| 874 | − getPendingByScopeSourceAndActor: (input: { | |
| 875 | − scopeId: SourceAuthSession["scopeId"]; | |
| 876 | − sourceId: SourceAuthSession["sourceId"]; | |
| 877 | − actorScopeId: SourceAuthSession["actorScopeId"]; | |
| 878 | − credentialSlot?: SourceAuthSession["credentialSlot"]; | |
| 879 | − }) => | |
| 880 | − stateManager.read((state) => { | |
| 881 | − const session = sortByUpdatedAtAndIdAsc( | |
| 882 | − state.sourceAuthSessions.filter( | |
| 883 | − (candidate) => | |
| 884 | − candidate.scopeId === input.scopeId | |
| 885 | − && candidate.sourceId === input.sourceId | |
| 886 | − && candidate.status === "pending" | |
| 887 | − && actorEquals(candidate.actorScopeId, input.actorScopeId) | |
| 888 | − && (input.credentialSlot === undefined | |
| 889 | − || candidate.credentialSlot === input.credentialSlot), | |
| 890 | − ), | |
| 891 | − )[0] ?? null; | |
| 892 | − | |
| 893 | − return session | |
| 894 | − ? Option.some(cloneValue(session)) | |
| 895 | − : Option.none<SourceAuthSession>(); | |
| 896 | − }), | |
| 897 | − | |
| 898 | − insert: (session: SourceAuthSession) => | |
| 899 | − stateManager.mutate((state) => ({ | |
| 900 | − state: { | |
| 901 | − ...state, | |
| 902 | − sourceAuthSessions: [...state.sourceAuthSessions, cloneValue(session)], | |
| 903 | − }, | |
| 904 | − value: undefined, | |
| 905 | − } satisfies StateMutationResult<void>)), | |
| 906 | − | |
| 907 | − update: ( | |
| 908 | − id: SourceAuthSession["id"], | |
| 909 | − patch: Partial<Omit<SourceAuthSession, "id" | "scopeId" | "sourceId" | "createdAt">>, | |
| 910 | − ) => | |
| 911 | − stateManager.mutate((state) => { | |
| 912 | − let updated: SourceAuthSession | null = null; | |
| 913 | − const nextSessions = state.sourceAuthSessions.map((session) => { | |
| 914 | − if (session.id !== id) { | |
| 915 | − return session; | |
| 916 | − } | |
| 917 | − | |
| 918 | − updated = { | |
| 919 | − ...session, | |
| 920 | − ...cloneValue(patch), | |
| 921 | − } satisfies SourceAuthSession; | |
| 922 | − return updated; | |
| 923 | − }); | |
| 924 | − | |
| 925 | − return { | |
| 926 | − state: { | |
| 927 | − ...state, | |
| 928 | − sourceAuthSessions: nextSessions, | |
| 929 | − }, | |
| 930 | − value: updated ? Option.some(cloneValue(updated)) : Option.none<SourceAuthSession>(), | |
| 931 | − } satisfies StateMutationResult<Option.Option<SourceAuthSession>>; | |
| 932 | − }), | |
| 933 | − | |
| 934 | − upsert: (session: SourceAuthSession) => | |
| 935 | − stateManager.mutate((state) => { | |
| 936 | − const nextSessions = state.sourceAuthSessions.filter( | |
| 937 | − (candidate) => candidate.id !== session.id, | |
| 938 | − ); | |
| 939 | − nextSessions.push(cloneValue(session)); | |
| 940 | − | |
| 941 | − return { | |
| 942 | − state: { | |
| 943 | − ...state, | |
| 944 | − sourceAuthSessions: nextSessions, | |
| 945 | − }, | |
| 946 | − value: undefined, | |
| 947 | − } satisfies StateMutationResult<void>; | |
| 948 | − }), | |
| 949 | − | |
| 950 | − removeByScopeAndSourceId: ( | |
| 951 | − scopeId: SourceAuthSession["scopeId"], | |
| 952 | − sourceId: SourceAuthSession["sourceId"], | |
| 953 | − ) => | |
| 954 | − stateManager.mutate((state) => { | |
| 955 | − const nextSessions = state.sourceAuthSessions.filter( | |
| 956 | − (candidate) => | |
| 957 | − candidate.scopeId !== scopeId || candidate.sourceId !== sourceId, | |
| 958 | − ); | |
| 959 | − | |
| 960 | − return { | |
| 961 | − state: { | |
| 962 | − ...state, | |
| 963 | − sourceAuthSessions: nextSessions, | |
| 964 | − }, | |
| 965 | − value: nextSessions.length !== state.sourceAuthSessions.length, | |
| 966 | − } satisfies StateMutationResult<boolean>; | |
| 967 | − }), | |
| 968 | − }, | |
| 969 | − | |
| 970 | 337 | secretMaterials: { |
| 971 | 338 | getById: (id: SecretMaterial["id"]) => |
| 972 | 339 | stateManager.read((state) => { |
| @@ -1041,7 +408,6 @@ export const createLocalExecutorStateStore = ( · 68 unmodified lines | ||
| 1041 | 408 | } satisfies StateMutationResult<boolean>; |
| 1042 | 409 | }), |
| 1043 | 410 | }, |
| 1044 | − | |
| 1045 | 411 | executions: { |
| 1046 | 412 | getById: (executionId: Execution["id"]) => |
| 1047 | 413 | stateManager.read((state) => { |
| @@ -12,9 +12,13 @@ import { · 11 unmodified lines | ||
| 12 | 12 | } from "@executor/platform-sdk"; |
| 13 | 13 | import { |
| 14 | 14 | createExecutorEffect, |
| 15 | + type CreateExecutorEffectOptions, | |
| 15 | 16 | type ExecutorEffect, |
| 16 | − type CreateExecutorEffectOptions as CreateExecutorOptions, | |
| 17 | 17 | } from "@executor/platform-sdk/effect"; |
| 18 | +import type { | |
| 19 | + ExecutorSdkPlugin, | |
| 20 | + ExecutorSdkPluginExtensions, | |
| 21 | +} from "@executor/platform-sdk/plugins"; | |
| 18 | 22 | import type { |
| 19 | 23 | LocalExecutorConfig, |
| 20 | 24 | LocalInstallation, |
| @@ -263,18 +267,6 @@ export const createLocalExecutorRepositoriesEffect = ( · 242 unmodified lines | ||
| 263 | 267 | workspaceContext, |
| 264 | 268 | fileSystem, |
| 265 | 269 | ), |
| 266 | − sourceAuth: { | |
| 267 | − artifacts: executorStateStorage.executorState.authArtifacts, | |
| 268 | − leases: executorStateStorage.executorState.authLeases, | |
| 269 | − sourceOauthClients: | |
| 270 | − executorStateStorage.executorState.sourceOauthClients, | |
| 271 | − scopeOauthClients: | |
| 272 | − executorStateStorage.executorState.scopeOauthClients, | |
| 273 | − providerGrants: | |
| 274 | − executorStateStorage.executorState.providerAuthGrants, | |
| 275 | − sourceSessions: | |
| 276 | − executorStateStorage.executorState.sourceAuthSessions, | |
| 277 | − }, | |
| 278 | 270 | localTools: createBoundLocalToolRuntimeLoader( |
| 279 | 271 | workspaceContext, |
| 280 | 272 | fileSystem, |
| @@ -326,22 +318,37 @@ export const createLocalExecutorRuntime = ( · 45 unmodified lines | ||
| 326 | 318 | getLocalServerBaseUrl: options.getLocalServerBaseUrl, |
| 327 | 319 | }); |
| 328 | 320 | |
| 329 | −export const createLocalExecutorEffect = ( | |
| 330 | − options: CreateLocalExecutorBackendOptions & ExecutorRuntimeOptions = {}, | |
| 331 | −): Effect.Effect<ExecutorEffect, Error> => | |
| 321 | +type CreateLocalExecutorOptions< | |
| 322 | + TPlugins extends readonly ExecutorSdkPlugin<any, any>[] = [], | |
| 323 | +> = CreateLocalExecutorBackendOptions & ExecutorRuntimeOptions & { | |
| 324 | + plugins?: TPlugins; | |
| 325 | +}; | |
| 326 | + | |
| 327 | +export const createLocalExecutorEffect = < | |
| 328 | + const TPlugins extends readonly ExecutorSdkPlugin<any, any>[] = [], | |
| 329 | +>( | |
| 330 | + options: CreateLocalExecutorOptions<TPlugins> = {}, | |
| 331 | +): Effect.Effect< | |
| 332 | + ExecutorEffect & ExecutorSdkPluginExtensions<TPlugins>, | |
| 333 | + Error | |
| 334 | +> => | |
| 332 | 335 | createExecutorEffect({ |
| 333 | 336 | backend: createLocalExecutorBackend(options), |
| 337 | + plugins: options.plugins, | |
| 334 | 338 | executionResolver: options.executionResolver, |
| 335 | 339 | createInternalToolMap: options.createInternalToolMap, |
| 336 | 340 | resolveSecretMaterial: options.resolveSecretMaterial, |
| 337 | 341 | getLocalServerBaseUrl: options.getLocalServerBaseUrl, |
| 338 | − } satisfies CreateExecutorOptions); | |
| 342 | + } satisfies CreateExecutorEffectOptions & { plugins?: TPlugins }); | |
| 339 | 343 | |
| 340 | −export const createLocalExecutor = ( | |
| 341 | − options: CreateLocalExecutorBackendOptions & ExecutorRuntimeOptions = {}, | |
| 342 | −): Promise<Executor> => | |
| 344 | +export const createLocalExecutor = < | |
| 345 | + const TPlugins extends readonly ExecutorSdkPlugin<any, any>[] = [], | |
| 346 | +>( | |
| 347 | + options: CreateLocalExecutorOptions<TPlugins> = {}, | |
| 348 | +): Promise<Executor<TPlugins>> => | |
| 343 | 349 | createExecutor({ |
| 344 | 350 | backend: createLocalExecutorBackend(options), |
| 351 | + plugins: options.plugins, | |
| 345 | 352 | executionResolver: options.executionResolver, |
| 346 | 353 | createInternalToolMap: options.createInternalToolMap, |
| 347 | 354 | resolveSecretMaterial: options.resolveSecretMaterial, |
| @@ -10,6 +10,7 @@ · 9 unmodified lines | ||
| 10 | 10 | "./executor": "./src/executor.ts", |
| 11 | 11 | "./errors": "./src/errors.ts", |
| 12 | 12 | "./operations": "./src/operations.ts", |
| 13 | + "./plugins": "./src/plugins.ts", | |
| 13 | 14 | "./string-schemas": "./src/string-schemas.ts", |
| 14 | 15 | "./schema": "./src/schema/index.ts", |
| 15 | 16 | "./runtime": "./src/runtime/index.ts" |
| @@ -34,7 +35,6 @@ · 18 unmodified lines | ||
| 34 | 35 | "@executor/runtime-quickjs": "workspace:*", |
| 35 | 36 | "@executor/runtime-ses": "workspace:*", |
| 36 | 37 | "@executor/source-core": "workspace:*", |
| 37 | − "@executor/source-builtins": "workspace:*", | |
| 38 | 38 | "effect": "catalog:" |
| 39 | 39 | }, |
| 40 | 40 | "devDependencies": { |
| @@ -11,7 +11,6 @@ import { · 10 unmodified lines | ||
| 11 | 11 | type BoundScopeStateStore, |
| 12 | 12 | type ExecutorRuntime, |
| 13 | 13 | type ExecutorRuntimeOptions, |
| 14 | − type RuntimeAuthStorageServices, | |
| 15 | 14 | type RuntimeExecutionStorageServices, |
| 16 | 15 | type RuntimeInstanceConfigService, |
| 17 | 16 | type RuntimeSecretsStorageServices, |
| @@ -59,14 +58,6 @@ export type ExecutorWorkspaceLocalToolRepository = PublicizeObject< · 41 unmodified lines | ||
| 59 | 58 | export type ExecutorWorkspaceSourceTypeDeclarationsRepository = PublicizeObject< |
| 60 | 59 | BoundSourceTypeDeclarationsRefresher |
| 61 | 60 | >; |
| 62 | −export type ExecutorWorkspaceSourceAuthRepository = { | |
| 63 | − artifacts: PublicizeObject<RuntimeAuthStorageServices["artifacts"]>; | |
| 64 | − leases: PublicizeObject<RuntimeAuthStorageServices["leases"]>; | |
| 65 | − sourceOauthClients: PublicizeObject<RuntimeAuthStorageServices["sourceOauthClients"]>; | |
| 66 | − scopeOauthClients: PublicizeObject<RuntimeAuthStorageServices["scopeOauthClients"]>; | |
| 67 | − providerGrants: PublicizeObject<RuntimeAuthStorageServices["providerGrants"]>; | |
| 68 | − sourceSessions: PublicizeObject<RuntimeAuthStorageServices["sourceSessions"]>; | |
| 69 | −}; | |
| 70 | 61 | export type ExecutorSecretRepository = PublicizeObject<RuntimeSecretsStorageServices>; |
| 71 | 62 | export type ExecutorExecutionRepository = { |
| 72 | 63 | runs: PublicizeObject<RuntimeExecutionStorageServices["runs"]>; |
| @@ -81,7 +72,6 @@ export type ExecutorWorkspaceRepository = { · 8 unmodified lines | ||
| 81 | 72 | config: ExecutorWorkspaceConfigRepository; |
| 82 | 73 | state: ExecutorWorkspaceStateRepository; |
| 83 | 74 | sourceArtifacts: ExecutorWorkspaceSourceArtifactRepository; |
| 84 | − sourceAuth: ExecutorWorkspaceSourceAuthRepository; | |
| 85 | 75 | localTools?: ExecutorWorkspaceLocalToolRepository; |
| 86 | 76 | sourceTypeDeclarations?: ExecutorWorkspaceSourceTypeDeclarationsRepository; |
| 87 | 77 | }; |
| @@ -175,66 +165,6 @@ const toSourceTypeDeclarationsBackend = ( · 87 unmodified lines | ||
| 175 | 165 | toEffect(input.refreshSourceInBackground(payload)).pipe(Effect.orDie), |
| 176 | 166 | }); |
| 177 | 167 | |
| 178 | −const toAuthBackend = ( | |
| 179 | − input: ExecutorWorkspaceSourceAuthRepository, | |
| 180 | −): RuntimeAuthStorageServices => ({ | |
| 181 | − artifacts: { | |
| 182 | − listByScopeId: (scopeId) => toEffect(input.artifacts.listByScopeId(scopeId)), | |
| 183 | − listByScopeAndSourceId: (payload) => | |
| 184 | − toEffect(input.artifacts.listByScopeAndSourceId(payload)), | |
| 185 | − getByScopeSourceAndActor: (payload) => | |
| 186 | − toOptionEffect(input.artifacts.getByScopeSourceAndActor(payload)), | |
| 187 | − upsert: (artifact) => toEffect(input.artifacts.upsert(artifact)), | |
| 188 | − removeByScopeSourceAndActor: (payload) => | |
| 189 | − toEffect(input.artifacts.removeByScopeSourceAndActor(payload)), | |
| 190 | − removeByScopeAndSourceId: (payload) => | |
| 191 | − toEffect(input.artifacts.removeByScopeAndSourceId(payload)), | |
| 192 | − }, | |
| 193 | − leases: { | |
| 194 | − listAll: () => toEffect(input.leases.listAll()), | |
| 195 | − getByAuthArtifactId: (authArtifactId) => | |
| 196 | − toOptionEffect(input.leases.getByAuthArtifactId(authArtifactId)), | |
| 197 | − upsert: (lease) => toEffect(input.leases.upsert(lease)), | |
| 198 | − removeByAuthArtifactId: (authArtifactId) => | |
| 199 | − toEffect(input.leases.removeByAuthArtifactId(authArtifactId)), | |
| 200 | − }, | |
| 201 | − sourceOauthClients: { | |
| 202 | − getByScopeSourceAndProvider: (payload) => | |
| 203 | − toOptionEffect(input.sourceOauthClients.getByScopeSourceAndProvider(payload)), | |
| 204 | − upsert: (oauthClient) => toEffect(input.sourceOauthClients.upsert(oauthClient)), | |
| 205 | − removeByScopeAndSourceId: (payload) => | |
| 206 | − toEffect(input.sourceOauthClients.removeByScopeAndSourceId(payload)), | |
| 207 | − }, | |
| 208 | − scopeOauthClients: { | |
| 209 | − listByScopeAndProvider: (payload) => | |
| 210 | − toEffect(input.scopeOauthClients.listByScopeAndProvider(payload)), | |
| 211 | − getById: (id) => toOptionEffect(input.scopeOauthClients.getById(id)), | |
| 212 | − upsert: (oauthClient) => toEffect(input.scopeOauthClients.upsert(oauthClient)), | |
| 213 | − removeById: (id) => toEffect(input.scopeOauthClients.removeById(id)), | |
| 214 | − }, | |
| 215 | − providerGrants: { | |
| 216 | − listByScopeId: (scopeId) => toEffect(input.providerGrants.listByScopeId(scopeId)), | |
| 217 | − listByScopeActorAndProvider: (payload) => | |
| 218 | − toEffect(input.providerGrants.listByScopeActorAndProvider(payload)), | |
| 219 | − getById: (id) => toOptionEffect(input.providerGrants.getById(id)), | |
| 220 | − upsert: (grant) => toEffect(input.providerGrants.upsert(grant)), | |
| 221 | − removeById: (id) => toEffect(input.providerGrants.removeById(id)), | |
| 222 | − }, | |
| 223 | − sourceSessions: { | |
| 224 | − listAll: () => toEffect(input.sourceSessions.listAll()), | |
| 225 | − listByScopeId: (scopeId) => toEffect(input.sourceSessions.listByScopeId(scopeId)), | |
| 226 | − getById: (id) => toOptionEffect(input.sourceSessions.getById(id)), | |
| 227 | − getByState: (state) => toOptionEffect(input.sourceSessions.getByState(state)), | |
| 228 | − getPendingByScopeSourceAndActor: (payload) => | |
| 229 | − toOptionEffect(input.sourceSessions.getPendingByScopeSourceAndActor(payload)), | |
| 230 | − insert: (session) => toEffect(input.sourceSessions.insert(session)), | |
| 231 | − update: (id, patch) => toOptionEffect(input.sourceSessions.update(id, patch)), | |
| 232 | − upsert: (session) => toEffect(input.sourceSessions.upsert(session)), | |
| 233 | − removeByScopeAndSourceId: (scopeId, sourceId) => | |
| 234 | − toEffect(input.sourceSessions.removeByScopeAndSourceId(scopeId, sourceId)), | |
| 235 | − }, | |
| 236 | −}); | |
| 237 | − | |
| 238 | 168 | const toSecretsBackend = ( |
| 239 | 169 | input: ExecutorSecretRepository, |
| 240 | 170 | ): RuntimeSecretsStorageServices => ({ |
| @@ -308,7 +238,6 @@ export const createExecutorBackend = (input: { · 67 unmodified lines | ||
| 308 | 238 | sourceArtifacts: toSourceArtifactBackend( |
| 309 | 239 | repositories.workspace.sourceArtifacts, |
| 310 | 240 | ), |
| 311 | − auth: toAuthBackend(repositories.workspace.sourceAuth), | |
| 312 | 241 | secrets: toSecretsBackend(repositories.secrets), |
| 313 | 242 | executions: toExecutionsBackend(repositories.executions), |
| 314 | 243 | close: repositories.close, |
| @@ -1,4 +1,3 @@ | ||
| 1 | 1 | export * from "./executions/contracts"; |
| 2 | 2 | export * from "./local/contracts"; |
| 3 | 3 | export * from "./policies/contracts"; |
| 4 | −export * from "./sources/contracts"; | |
| @@ -4,12 +4,10 @@ import type { · 3 unmodified lines | ||
| 4 | 4 | ScopeId, |
| 5 | 5 | Execution, |
| 6 | 6 | ExecutionEnvelope, |
| 7 | − ExecutionInteraction, | |
| 8 | 7 | LocalInstallation, |
| 9 | 8 | LocalScopePolicy, |
| 10 | 9 | Source, |
| 11 | 10 | } from "./schema"; |
| 12 | −import { ExecutionIdSchema } from "./schema"; | |
| 13 | 11 | import type { |
| 14 | 12 | CreateExecutionPayload, |
| 15 | 13 | ResumeExecutionPayload, |
| @@ -24,10 +22,7 @@ import type { · 8 unmodified lines | ||
| 24 | 22 | UpdateSecretResult, |
| 25 | 23 | } from "./local/contracts"; |
| 26 | 24 | import { |
| 27 | − completeSourceCredentialSetup, | |
| 28 | 25 | getLocalInstallation, |
| 29 | − getSourceCredentialInteraction, | |
| 30 | − submitSourceCredentialInteraction, | |
| 31 | 26 | } from "./local/operations"; |
| 32 | 27 | import { |
| 33 | 28 | createLocalSecret, |
| @@ -47,21 +42,17 @@ import { · 13 unmodified lines | ||
| 47 | 42 | removePolicy, |
| 48 | 43 | updatePolicy, |
| 49 | 44 | } from "./policies/operations"; |
| 50 | −import type { | |
| 51 | − CreateSourcePayload, | |
| 52 | − UpdateSourcePayload, | |
| 53 | −} from "./sources/contracts"; | |
| 54 | 45 | import { |
| 55 | 46 | discoverSourceInspectionTools, |
| 56 | 47 | getSourceInspection, |
| 57 | 48 | getSourceInspectionToolDetail, |
| 58 | 49 | } from "./sources/inspection"; |
| 59 | 50 | import { |
| 60 | − createSource, | |
| 51 | + createManagedSource, | |
| 61 | 52 | getSource, |
| 62 | 53 | listSources, |
| 63 | 54 | removeSource, |
| 64 | − updateSource, | |
| 55 | + saveManagedSource, | |
| 65 | 56 | } from "./sources/operations"; |
| 66 | 57 | import type { ExecutorBackend } from "./backend"; |
| 67 | 58 | import { |
| @@ -71,7 +62,6 @@ import { · 3 unmodified lines | ||
| 71 | 62 | type ExecutorRuntimeOptions, |
| 72 | 63 | type ResolveExecutionEnvironment, |
| 73 | 64 | type ResolveSecretMaterial, |
| 74 | − RuntimeSourceAuthServiceTag, | |
| 75 | 65 | } from "./runtime"; |
| 76 | 66 | import { |
| 77 | 67 | createExecution, |
| @@ -79,14 +69,14 @@ import { · 1 unmodified line | ||
| 79 | 69 | resumeExecution, |
| 80 | 70 | } from "./runtime/execution/service"; |
| 81 | 71 | import type { |
| 82 | − CompleteSourceCredentialSetupResult, | |
| 83 | − ExecutorAddSourceInput, | |
| 84 | − ExecutorSourceAddResult, | |
| 85 | −} from "./runtime/sources/source-auth-service"; | |
| 72 | + ExecutorSdkPluginHost, | |
| 73 | + ExecutorSdkPlugin, | |
| 74 | + ExecutorSdkPluginExtensions, | |
| 75 | +} from "./plugins"; | |
| 76 | +import { | |
| 77 | + configureExecutorSourcePlugins, | |
| 78 | +} from "./runtime/sources/source-plugins"; | |
| 86 | 79 | |
| 87 | −type DistributiveOmit<T, Keys extends PropertyKey> = T extends unknown | |
| 88 | − ? Omit<T, Keys> | |
| 89 | − : never; | |
| 90 | 80 | type ProvidedEffect<T extends Effect.Effect<any, any, any>> = Effect.Effect< |
| 91 | 81 | Effect.Effect.Success<T>, |
| 92 | 82 | Effect.Effect.Error<T>, |
| @@ -97,11 +87,6 @@ type MappedProvidedEffect< · 4 unmodified lines | ||
| 97 | 87 | A, |
| 98 | 88 | > = Effect.Effect<A, Effect.Effect.Error<T>, never>; |
| 99 | 89 | |
| 100 | −export type ExecutorSourceInput = DistributiveOmit< | |
| 101 | − ExecutorAddSourceInput, | |
| 102 | − "scopeId" | "actorScopeId" | "executionId" | "interactionId" | |
| 103 | −>; | |
| 104 | − | |
| 105 | 90 | export type ExecutorEffect = { |
| 106 | 91 | runtime: ExecutorRuntime; |
| 107 | 92 | installation: LocalInstallation; |
| @@ -112,30 +97,6 @@ export type ExecutorEffect = { · 4 unmodified lines | ||
| 112 | 97 | local: { |
| 113 | 98 | installation: () => ProvidedEffect<ReturnType<typeof getLocalInstallation>>; |
| 114 | 99 | config: () => ProvidedEffect<ReturnType<typeof getLocalInstanceConfig>>; |
| 115 | − credentials: { | |
| 116 | − get: (input: { | |
| 117 | − sourceId: Source["id"]; | |
| 118 | − interactionId: ExecutionInteraction["id"]; | |
| 119 | − }) => ProvidedEffect<ReturnType<typeof getSourceCredentialInteraction>>; | |
| 120 | − submit: (input: { | |
| 121 | − sourceId: Source["id"]; | |
| 122 | − interactionId: ExecutionInteraction["id"]; | |
| 123 | − action: "submit" | "continue" | "cancel"; | |
| 124 | − token?: string | null; | |
| 125 | − }) => ProvidedEffect< | |
| 126 | − ReturnType<typeof submitSourceCredentialInteraction> | |
| 127 | − >; | |
| 128 | − complete: (input: { | |
| 129 | − sourceId: Source["id"]; | |
| 130 | − state: string; | |
| 131 | − code?: string | null; | |
| 132 | − error?: string | null; | |
| 133 | − errorDescription?: string | null; | |
| 134 | − }) => MappedProvidedEffect< | |
| 135 | − ReturnType<typeof completeSourceCredentialSetup>, | |
| 136 | − CompleteSourceCredentialSetupResult | |
| 137 | − >; | |
| 138 | − }; | |
| 139 | 100 | }; |
| 140 | 101 | secrets: { |
| 141 | 102 | list: () => ProvidedEffect<ReturnType<typeof listLocalSecrets>>; |
| @@ -168,21 +129,8 @@ export type ExecutorEffect = { · 26 unmodified lines | ||
| 168 | 129 | ) => MappedProvidedEffect<ReturnType<typeof removePolicy>, boolean>; |
| 169 | 130 | }; |
| 170 | 131 | sources: { |
| 171 | − add: ( | |
| 172 | − input: ExecutorSourceInput, | |
| 173 | − options?: { | |
| 174 | − baseUrl?: string | null; | |
| 175 | − }, | |
| 176 | − ) => Effect.Effect<ExecutorSourceAddResult, Error, never>; | |
| 177 | 132 | list: () => ProvidedEffect<ReturnType<typeof listSources>>; |
| 178 | − create: ( | |
| 179 | − payload: CreateSourcePayload, | |
| 180 | − ) => ProvidedEffect<ReturnType<typeof createSource>>; | |
| 181 | 133 | get: (sourceId: Source["id"]) => ProvidedEffect<ReturnType<typeof getSource>>; |
| 182 | − update: ( | |
| 183 | − sourceId: Source["id"], | |
| 184 | − payload: UpdateSourcePayload, | |
| 185 | − ) => ProvidedEffect<ReturnType<typeof updateSource>>; | |
| 186 | 134 | remove: ( |
| 187 | 135 | sourceId: Source["id"], |
| 188 | 136 | ) => MappedProvidedEffect<ReturnType<typeof removeSource>, boolean>; |
| @@ -220,24 +168,18 @@ export type CreateExecutorEffectOptions = ExecutorRuntimeOptions & { · 31 unmodified lines | ||
| 220 | 168 | backend: ExecutorBackend; |
| 221 | 169 | }; |
| 222 | 170 | |
| 171 | +type CreateExecutorEffectOptionsWithPlugins< | |
| 172 | + TPlugins extends readonly ExecutorSdkPlugin<any, any>[], | |
| 173 | +> = CreateExecutorEffectOptions & { | |
| 174 | + plugins?: TPlugins; | |
| 175 | +}; | |
| 176 | + | |
| 223 | 177 | const fromRuntime = (runtime: ExecutorRuntime): ExecutorEffect => { |
| 224 | 178 | const installation = runtime.localInstallation; |
| 225 | 179 | const scopeId = installation.scopeId; |
| 226 | 180 | const actorScopeId = installation.actorScopeId; |
| 227 | 181 | const provide = <A, E, R>(effect: Effect.Effect<A, E, R>) => |
| 228 | 182 | provideExecutorRuntime(effect, runtime); |
| 229 | − const provideSourceAuth = <A, E>( | |
| 230 | − execute: ( | |
| 231 | − service: Effect.Effect.Success<typeof RuntimeSourceAuthServiceTag>, | |
| 232 | − ) => Effect.Effect<A, E, any>, | |
| 233 | − ) => provide(Effect.flatMap(RuntimeSourceAuthServiceTag, execute)); | |
| 234 | − const createSdkSourceSession = () => { | |
| 235 | − const id = crypto.randomUUID(); | |
| 236 | − return { | |
| 237 | − executionId: ExecutionIdSchema.make(`exec_sdk_${id}`), | |
| 238 | − interactionId: `executor.sdk.${id}` as never, | |
| 239 | − }; | |
| 240 | − }; | |
| 241 | 183 | |
| 242 | 184 | return { |
| 243 | 185 | runtime, |
| @@ -249,37 +191,6 @@ const fromRuntime = (runtime: ExecutorRuntime): ExecutorEffect => { · 5 unmodified lines | ||
| 249 | 191 | local: { |
| 250 | 192 | installation: () => provide(getLocalInstallation()), |
| 251 | 193 | config: () => provide(getLocalInstanceConfig()), |
| 252 | − credentials: { | |
| 253 | − get: ({ sourceId, interactionId }) => | |
| 254 | − provide( | |
| 255 | − getSourceCredentialInteraction({ | |
| 256 | − scopeId, | |
| 257 | − sourceId, | |
| 258 | − interactionId, | |
| 259 | − }), | |
| 260 | − ), | |
| 261 | − submit: ({ sourceId, interactionId, action, token }) => | |
| 262 | − provide( | |
| 263 | − submitSourceCredentialInteraction({ | |
| 264 | − scopeId, | |
| 265 | − sourceId, | |
| 266 | − interactionId, | |
| 267 | − action, | |
| 268 | − token, | |
| 269 | − }), | |
| 270 | − ), | |
| 271 | − complete: ({ sourceId, state, code, error, errorDescription }) => | |
| 272 | − provide( | |
| 273 | − completeSourceCredentialSetup({ | |
| 274 | − scopeId, | |
| 275 | − sourceId, | |
| 276 | − state, | |
| 277 | − code, | |
| 278 | − error, | |
| 279 | − errorDescription, | |
| 280 | − }), | |
| 281 | − ), | |
| 282 | − }, | |
| 283 | 194 | }, |
| 284 | 195 | secrets: { |
| 285 | 196 | list: () => provide(listLocalSecrets()), |
| @@ -300,25 +211,8 @@ const fromRuntime = (runtime: ExecutorRuntime): ExecutorEffect => { · 14 unmodified lines | ||
| 300 | 211 | ), |
| 301 | 212 | }, |
| 302 | 213 | sources: { |
| 303 | − add: (input, options) => | |
| 304 | − provideSourceAuth((service) => { | |
| 305 | − const session = createSdkSourceSession(); | |
| 306 | − return service.addExecutorSource( | |
| 307 | − { | |
| 308 | − ...input, | |
| 309 | − scopeId, | |
| 310 | − actorScopeId, | |
| 311 | − executionId: session.executionId, | |
| 312 | − interactionId: session.interactionId, | |
| 313 | − }, | |
| 314 | − options, | |
| 315 | − ); | |
| 316 | − }), | |
| 317 | 214 | list: () => provide(listSources({ scopeId, actorScopeId })), |
| 318 | − create: (payload) => provide(createSource({ scopeId, actorScopeId, payload })), | |
| 319 | 215 | get: (sourceId) => provide(getSource({ scopeId, sourceId, actorScopeId })), |
| 320 | − update: (sourceId, payload) => | |
| 321 | − provide(updateSource({ scopeId, sourceId, actorScopeId, payload })), | |
| 322 | 216 | remove: (sourceId) => |
| 323 | 217 | provide(removeSource({ scopeId, sourceId })).pipe( |
| 324 | 218 | Effect.map((result) => result.removed), |
| @@ -366,15 +260,78 @@ const fromRuntime = (runtime: ExecutorRuntime): ExecutorEffect => { · 41 unmodified lines | ||
| 366 | 260 | }; |
| 367 | 261 | }; |
| 368 | 262 | |
| 369 | −export const createExecutorEffect = ( | |
| 370 | − options: CreateExecutorEffectOptions, | |
| 371 | −): Effect.Effect<ExecutorEffect, Error> => | |
| 372 | − Effect.map( | |
| 263 | +export const createExecutorEffect = < | |
| 264 | + const TPlugins extends readonly ExecutorSdkPlugin<any, any>[] = [], | |
| 265 | +>( | |
| 266 | + options: CreateExecutorEffectOptionsWithPlugins<TPlugins>, | |
| 267 | +): Effect.Effect<ExecutorEffect & ExecutorSdkPluginExtensions<TPlugins>, Error> => { | |
| 268 | + configureExecutorSourcePlugins(options.plugins ?? []); | |
| 269 | + | |
| 270 | + return Effect.map( | |
| 373 | 271 | options.backend.createRuntime({ |
| 374 | 272 | executionResolver: options.executionResolver, |
| 375 | 273 | createInternalToolMap: options.createInternalToolMap, |
| 376 | 274 | resolveSecretMaterial: options.resolveSecretMaterial, |
| 377 | 275 | getLocalServerBaseUrl: options.getLocalServerBaseUrl, |
| 378 | 276 | }), |
| 379 | − fromRuntime, | |
| 277 | + (runtime) => { | |
| 278 | + const executor = fromRuntime(runtime); | |
| 279 | + const providePluginHostEffect = <A>( | |
| 280 | + effect: Effect.Effect<A, unknown, any>, | |
| 281 | + ): Effect.Effect<A, Error, never> => | |
| 282 | + provideExecutorRuntime(effect, runtime).pipe( | |
| 283 | + Effect.mapError((cause) => | |
| 284 | + cause instanceof Error ? cause : new Error(String(cause)), | |
| 285 | + ), | |
| 286 | + ); | |
| 287 | + const host: ExecutorSdkPluginHost = { | |
| 288 | + sources: { | |
| 289 | + create: ({ source }) => | |
| 290 | + providePluginHostEffect( | |
| 291 | + createManagedSource({ | |
| 292 | + scopeId: executor.scopeId, | |
| 293 | + actorScopeId: executor.actorScopeId, | |
| 294 | + source, | |
| 295 | + }), | |
| 296 | + ), | |
| 297 | + get: (sourceId) => | |
| 298 | + providePluginHostEffect( | |
| 299 | + getSource({ | |
| 300 | + scopeId: executor.scopeId, | |
| 301 | + sourceId, | |
| 302 | + actorScopeId: executor.actorScopeId, | |
| 303 | + }), | |
| 304 | + ), | |
| 305 | + save: (source) => | |
| 306 | + providePluginHostEffect( | |
| 307 | + saveManagedSource({ | |
| 308 | + actorScopeId: executor.actorScopeId, | |
| 309 | + source, | |
| 310 | + }), | |
| 311 | + ), | |
| 312 | + remove: (sourceId) => | |
| 313 | + providePluginHostEffect( | |
| 314 | + removeSource({ | |
| 315 | + scopeId: executor.scopeId, | |
| 316 | + sourceId, | |
| 317 | + }).pipe(Effect.map((result) => result.removed)), | |
| 318 | + ), | |
| 319 | + }, | |
| 320 | + }; | |
| 321 | + const extensions = Object.fromEntries( | |
| 322 | + (options.plugins ?? []).map((plugin) => [ | |
| 323 | + plugin.key, | |
| 324 | + plugin.extendExecutor?.({ | |
| 325 | + executor, | |
| 326 | + host, | |
| 327 | + }) ?? {}, | |
| 328 | + ]), | |
| 329 | + ); | |
| 330 | + | |
| 331 | + return Object.assign( | |
| 332 | + executor, | |
| 333 | + extensions, | |
| 334 | + ) as ExecutorEffect & ExecutorSdkPluginExtensions<TPlugins>; | |
| 335 | + }, | |
| 380 | 336 | ); |
| 337 | +}; | |
| @@ -4,8 +4,11 @@ import { · 3 unmodified lines | ||
| 4 | 4 | createExecutorEffect, |
| 5 | 5 | type CreateExecutorEffectOptions, |
| 6 | 6 | type ExecutorEffect, |
| 7 | − type ExecutorSourceInput, | |
| 8 | 7 | } from "./executor-effect"; |
| 8 | +import type { | |
| 9 | + ExecutorSdkPlugin, | |
| 10 | + ExecutorSdkPluginExtensions, | |
| 11 | +} from "./plugins"; | |
| 9 | 12 | |
| 10 | 13 | type Promiseify<T> = T extends Effect.Effect<infer A, any, any> |
| 11 | 14 | ? Promise<A> |
| @@ -17,17 +20,56 @@ type Promiseify<T> = T extends Effect.Effect<infer A, any, any> · 5 unmodified lines | ||
| 17 | 20 | ? { [Key in keyof T]: Promiseify<T[Key]> } |
| 18 | 21 | : T; |
| 19 | 22 | |
| 20 | −export type Executor = Omit<Promiseify<ExecutorEffect>, "runtime">; | |
| 21 | −export type CreateExecutorOptions = CreateExecutorEffectOptions; | |
| 22 | −export type { | |
| 23 | − ExecutorSourceInput, | |
| 23 | +export type Executor< | |
| 24 | + TPlugins extends readonly ExecutorSdkPlugin<any, any>[] = [], | |
| 25 | +> = Omit< | |
| 26 | + Promiseify<ExecutorEffect & ExecutorSdkPluginExtensions<TPlugins>>, | |
| 27 | + "runtime" | |
| 28 | +>; | |
| 29 | +export type CreateExecutorOptions< | |
| 30 | + TPlugins extends readonly ExecutorSdkPlugin<any, any>[] = [], | |
| 31 | +> = CreateExecutorEffectOptions & { | |
| 32 | + plugins?: TPlugins; | |
| 24 | 33 | }; |
| 25 | 34 | |
| 26 | −const toPromiseExecutor = (executor: ExecutorEffect): Executor => { | |
| 27 | − const run = <A, E>(effect: Effect.Effect<A, E, never>) => | |
| 28 | − Effect.runPromise(effect); | |
| 35 | +const toPromiseExecutor = < | |
| 36 | + TPlugins extends readonly ExecutorSdkPlugin<any, any>[], | |
| 37 | +>( | |
| 38 | + executor: ExecutorEffect & ExecutorSdkPluginExtensions<TPlugins>, | |
| 39 | +): Executor<TPlugins> => { | |
| 40 | + const run = <A, E, R>(effect: Effect.Effect<A, E, R>) => | |
| 41 | + Effect.runPromise(effect as Effect.Effect<A, E, never>); | |
| 42 | + const promiseifyValue = (value: unknown): unknown => { | |
| 43 | + if (Effect.isEffect(value)) { | |
| 44 | + return run(value); | |
| 45 | + } | |
| 29 | 46 | |
| 30 | − return { | |
| 47 | + if (value instanceof Promise) { | |
| 48 | + return value; | |
| 49 | + } | |
| 50 | + | |
| 51 | + if (typeof value === "function") { | |
| 52 | + return (...args: Array<unknown>) => | |
| 53 | + promiseifyValue(value(...args)); | |
| 54 | + } | |
| 55 | + | |
| 56 | + if (Array.isArray(value)) { | |
| 57 | + return value.map(promiseifyValue); | |
| 58 | + } | |
| 59 | + | |
| 60 | + if (value !== null && typeof value === "object") { | |
| 61 | + return Object.fromEntries( | |
| 62 | + Object.entries(value).map(([key, nestedValue]) => [ | |
| 63 | + key, | |
| 64 | + promiseifyValue(nestedValue), | |
| 65 | + ]), | |
| 66 | + ); | |
| 67 | + } | |
| 68 | + | |
| 69 | + return value; | |
| 70 | + }; | |
| 71 | + | |
| 72 | + const base = { | |
| 31 | 73 | installation: executor.installation, |
| 32 | 74 | scopeId: executor.scopeId, |
| 33 | 75 | actorScopeId: executor.actorScopeId, |
| @@ -36,49 +78,87 @@ const toPromiseExecutor = (executor: ExecutorEffect): Executor => { · 2 unmodified lines | ||
| 36 | 78 | local: { |
| 37 | 79 | installation: () => run(executor.local.installation()), |
| 38 | 80 | config: () => run(executor.local.config()), |
| 39 | − credentials: { | |
| 40 | − get: (input) => run(executor.local.credentials.get(input)), | |
| 41 | − submit: (input) => run(executor.local.credentials.submit(input)), | |
| 42 | − complete: (input) => run(executor.local.credentials.complete(input)), | |
| 43 | − }, | |
| 44 | 81 | }, |
| 45 | 82 | secrets: { |
| 46 | 83 | list: () => run(executor.secrets.list()), |
| 47 | − create: (payload) => run(executor.secrets.create(payload)), | |
| 48 | − update: (input) => run(executor.secrets.update(input)), | |
| 49 | − remove: (secretId) => run(executor.secrets.remove(secretId)), | |
| 84 | + create: (payload: Parameters<typeof executor.secrets.create>[0]) => | |
| 85 | + run(executor.secrets.create(payload)), | |
| 86 | + update: (input: Parameters<typeof executor.secrets.update>[0]) => | |
| 87 | + run(executor.secrets.update(input)), | |
| 88 | + remove: (secretId: Parameters<typeof executor.secrets.remove>[0]) => | |
| 89 | + run(executor.secrets.remove(secretId)), | |
| 50 | 90 | }, |
| 51 | 91 | policies: { |
| 52 | 92 | list: () => run(executor.policies.list()), |
| 53 | − create: (payload) => run(executor.policies.create(payload)), | |
| 54 | − get: (policyId) => run(executor.policies.get(policyId)), | |
| 55 | − update: (policyId, payload) => | |
| 93 | + create: (payload: Parameters<typeof executor.policies.create>[0]) => | |
| 94 | + run(executor.policies.create(payload)), | |
| 95 | + get: (policyId: Parameters<typeof executor.policies.get>[0]) => | |
| 96 | + run(executor.policies.get(policyId)), | |
| 97 | + update: ( | |
| 98 | + policyId: Parameters<typeof executor.policies.update>[0], | |
| 99 | + payload: Parameters<typeof executor.policies.update>[1], | |
| 100 | + ) => | |
| 56 | 101 | run(executor.policies.update(policyId, payload)), |
| 57 | − remove: (policyId) => run(executor.policies.remove(policyId)), | |
| 102 | + remove: (policyId: Parameters<typeof executor.policies.remove>[0]) => | |
| 103 | + run(executor.policies.remove(policyId)), | |
| 58 | 104 | }, |
| 59 | 105 | sources: { |
| 60 | − add: (input, options) => run(executor.sources.add(input, options)), | |
| 61 | 106 | list: () => run(executor.sources.list()), |
| 62 | − create: (payload) => run(executor.sources.create(payload)), | |
| 63 | − get: (sourceId) => run(executor.sources.get(sourceId)), | |
| 64 | − update: (sourceId, payload) => | |
| 65 | − run(executor.sources.update(sourceId, payload)), | |
| 66 | − remove: (sourceId) => run(executor.sources.remove(sourceId)), | |
| 107 | + get: (sourceId: Parameters<typeof executor.sources.get>[0]) => | |
| 108 | + run(executor.sources.get(sourceId)), | |
| 109 | + remove: (sourceId: Parameters<typeof executor.sources.remove>[0]) => | |
| 110 | + run(executor.sources.remove(sourceId)), | |
| 67 | 111 | inspection: { |
| 68 | − get: (sourceId) => run(executor.sources.inspection.get(sourceId)), | |
| 69 | − tool: (input) => run(executor.sources.inspection.tool(input)), | |
| 70 | − discover: (input) => run(executor.sources.inspection.discover(input)), | |
| 112 | + get: (sourceId: Parameters<typeof executor.sources.inspection.get>[0]) => | |
| 113 | + run(executor.sources.inspection.get(sourceId)), | |
| 114 | + tool: (input: Parameters<typeof executor.sources.inspection.tool>[0]) => | |
| 115 | + run(executor.sources.inspection.tool(input)), | |
| 116 | + discover: ( | |
| 117 | + input: Parameters<typeof executor.sources.inspection.discover>[0], | |
| 118 | + ) => run(executor.sources.inspection.discover(input)), | |
| 71 | 119 | }, |
| 72 | 120 | }, |
| 73 | 121 | executions: { |
| 74 | − create: (payload) => run(executor.executions.create(payload)), | |
| 75 | − get: (executionId) => run(executor.executions.get(executionId)), | |
| 76 | − resume: (executionId, payload) => | |
| 122 | + create: (payload: Parameters<typeof executor.executions.create>[0]) => | |
| 123 | + run(executor.executions.create(payload)), | |
| 124 | + get: (executionId: Parameters<typeof executor.executions.get>[0]) => | |
| 125 | + run(executor.executions.get(executionId)), | |
| 126 | + resume: ( | |
| 127 | + executionId: Parameters<typeof executor.executions.resume>[0], | |
| 128 | + payload: Parameters<typeof executor.executions.resume>[1], | |
| 129 | + ) => | |
| 77 | 130 | run(executor.executions.resume(executionId, payload)), |
| 78 | 131 | }, |
| 79 | 132 | }; |
| 133 | + | |
| 134 | + const coreKeys = new Set([ | |
| 135 | + "runtime", | |
| 136 | + "installation", | |
| 137 | + "scopeId", | |
| 138 | + "actorScopeId", | |
| 139 | + "resolutionScopeIds", | |
| 140 | + "close", | |
| 141 | + "local", | |
| 142 | + "secrets", | |
| 143 | + "policies", | |
| 144 | + "sources", | |
| 145 | + "executions", | |
| 146 | + ]); | |
| 147 | + | |
| 148 | + const pluginExtensions = Object.fromEntries( | |
| 149 | + Object.entries(executor) | |
| 150 | + .filter(([key]) => !coreKeys.has(key)) | |
| 151 | + .map(([key, value]) => [key, promiseifyValue(value)]), | |
| 152 | + ); | |
| 153 | + | |
| 154 | + return Object.assign(base, pluginExtensions) as unknown as Executor<TPlugins>; | |
| 80 | 155 | }; |
| 81 | 156 | |
| 82 | −export const createExecutor = async ( | |
| 83 | − options: CreateExecutorOptions, | |
| 84 | −): Promise<Executor> => toPromiseExecutor(await Effect.runPromise(createExecutorEffect(options))); | |
| 157 | +export const createExecutor = async < | |
| 158 | + const TPlugins extends readonly ExecutorSdkPlugin<any, any>[] = [], | |
| 159 | +>( | |
| 160 | + options: CreateExecutorOptions<TPlugins>, | |
| 161 | +): Promise<Executor<TPlugins>> => | |
| 162 | + toPromiseExecutor( | |
| 163 | + await Effect.runPromise(createExecutorEffect(options)), | |
| 164 | + ); | |
| @@ -1,2 +1,3 @@ | ||
| 1 | 1 | export * from "./backend"; |
| 2 | 2 | export * from "./executor"; |
| 3 | +export * from "./plugins"; | |
| @@ -1,200 +1,16 @@ | ||
| 1 | −import type { | |
| 2 | − Execution, | |
| 3 | − ExecutionInteraction, | |
| 4 | − Source, | |
| 5 | − ScopeId, | |
| 6 | −} from "../schema"; | |
| 7 | −import { | |
| 8 | − SourceIdSchema, | |
| 9 | − ScopeIdSchema, | |
| 10 | −} from "../schema"; | |
| 11 | 1 | import * as Effect from "effect/Effect"; |
| 12 | −import * as Option from "effect/Option"; | |
| 13 | 2 | |
| 14 | −import { | |
| 15 | − submitExecutionInteractionResponse, | |
| 16 | −} from "../runtime/execution/service"; | |
| 17 | −import { | |
| 18 | − LiveExecutionManagerService, | |
| 19 | −} from "../runtime/execution/live"; | |
| 20 | −import { | |
| 21 | − operationErrors, | |
| 22 | −} from "../runtime/policy/operation-errors"; | |
| 23 | 3 | import { |
| 24 | 4 | InstallationStore, |
| 25 | 5 | } from "../runtime/scope/storage"; |
| 26 | 6 | import { |
| 27 | − RuntimeSourceAuthServiceTag, | |
| 28 | −} from "../runtime/sources/source-auth-service"; | |
| 29 | −import { | |
| 30 | − createSourceCredentialSelectionBearerContent, | |
| 31 | − createSourceCredentialSelectionNoneContent, | |
| 32 | −} from "../runtime/sources/source-credential-interactions"; | |
| 33 | −import { | |
| 34 | − ExecutorStateStore, | |
| 35 | −} from "../runtime/executor-state-store"; | |
| 7 | + operationErrors, | |
| 8 | +} from "../runtime/policy/operation-errors"; | |
| 36 | 9 | |
| 37 | 10 | const localOps = { |
| 38 | 11 | installation: operationErrors("local.installation.get"), |
| 39 | − sourceCredentialComplete: operationErrors("sources.credentials.complete"), | |
| 40 | − sourceCredentialPage: operationErrors("sources.credentials.page"), | |
| 41 | − sourceCredentialSubmit: operationErrors("sources.credentials.submit"), | |
| 42 | 12 | } as const; |
| 43 | 13 | |
| 44 | −type SourceCredentialInteraction = { | |
| 45 | − interactionId: ExecutionInteraction["id"]; | |
| 46 | − executionId: Execution["id"]; | |
| 47 | − status: ExecutionInteraction["status"]; | |
| 48 | − message: string; | |
| 49 | − scopeId: ScopeId; | |
| 50 | − sourceId: Source["id"]; | |
| 51 | − sourceLabel: string; | |
| 52 | − endpoint: string; | |
| 53 | −}; | |
| 54 | − | |
| 55 | −const isRecord = (value: unknown): value is Record<string, unknown> => | |
| 56 | − typeof value === "object" && value !== null; | |
| 57 | − | |
| 58 | −const asString = (value: unknown): string | null => | |
| 59 | − typeof value === "string" ? value : null; | |
| 60 | − | |
| 61 | −const trimOrNull = (value: string | null | undefined): string | null => { | |
| 62 | − if (value === null || value === undefined) { | |
| 63 | − return null; | |
| 64 | − } | |
| 65 | − | |
| 66 | − const trimmed = value.trim(); | |
| 67 | − return trimmed.length > 0 ? trimmed : null; | |
| 68 | −}; | |
| 69 | − | |
| 70 | −export const decodeSourceCredentialInteraction = ( | |
| 71 | − interaction: ExecutionInteraction, | |
| 72 | −): Omit<SourceCredentialInteraction, "sourceLabel" | "endpoint"> | null => { | |
| 73 | − try { | |
| 74 | − if ( | |
| 75 | − interaction.purpose !== "source_connect_oauth2" && | |
| 76 | − interaction.purpose !== "source_connect_secret" && | |
| 77 | − interaction.purpose !== "elicitation" | |
| 78 | − ) { | |
| 79 | − return null; | |
| 80 | − } | |
| 81 | − | |
| 82 | − const payload = JSON.parse(interaction.payloadJson) as unknown; | |
| 83 | − if (!isRecord(payload)) { | |
| 84 | − return null; | |
| 85 | − } | |
| 86 | − | |
| 87 | − const args = payload.args; | |
| 88 | − const elicitation = payload.elicitation; | |
| 89 | − if (!isRecord(args) || !isRecord(elicitation)) { | |
| 90 | − return null; | |
| 91 | − } | |
| 92 | − | |
| 93 | − if (payload.path !== "executor.sources.add") { | |
| 94 | − return null; | |
| 95 | − } | |
| 96 | − const effectivePurpose = | |
| 97 | − interaction.purpose === "elicitation" | |
| 98 | − ? elicitation.mode === "url" | |
| 99 | − ? "source_connect_oauth2" | |
| 100 | − : "source_connect_secret" | |
| 101 | − : interaction.purpose; | |
| 102 | − if ( | |
| 103 | − effectivePurpose === "source_connect_oauth2" && | |
| 104 | − elicitation.mode !== "url" | |
| 105 | − ) { | |
| 106 | − return null; | |
| 107 | − } | |
| 108 | − if ( | |
| 109 | − effectivePurpose === "source_connect_secret" && | |
| 110 | − elicitation.mode !== "form" | |
| 111 | − ) { | |
| 112 | − return null; | |
| 113 | − } | |
| 114 | − | |
| 115 | − const scopeId = trimOrNull(asString(args.scopeId)); | |
| 116 | − const sourceId = trimOrNull(asString(args.sourceId)); | |
| 117 | − const message = trimOrNull(asString(elicitation.message)); | |
| 118 | − if (scopeId === null || sourceId === null || message === null) { | |
| 119 | − return null; | |
| 120 | − } | |
| 121 | − | |
| 122 | − return { | |
| 123 | − interactionId: interaction.id, | |
| 124 | − executionId: interaction.executionId, | |
| 125 | − status: interaction.status, | |
| 126 | − message, | |
| 127 | − scopeId: ScopeIdSchema.make(scopeId), | |
| 128 | − sourceId: SourceIdSchema.make(sourceId), | |
| 129 | − }; | |
| 130 | − } catch { | |
| 131 | − return null; | |
| 132 | − } | |
| 133 | −}; | |
| 134 | − | |
| 135 | −const loadSourceCredentialInteraction = (input: { | |
| 136 | − scopeId: ScopeId; | |
| 137 | − sourceId: Source["id"]; | |
| 138 | − interactionId: ExecutionInteraction["id"]; | |
| 139 | − operation: | |
| 140 | − | typeof localOps.sourceCredentialPage | |
| 141 | − | typeof localOps.sourceCredentialSubmit; | |
| 142 | −}) => | |
| 143 | − Effect.gen(function* () { | |
| 144 | − const store = yield* ExecutorStateStore; | |
| 145 | − const sourceAuthService = yield* RuntimeSourceAuthServiceTag; | |
| 146 | − | |
| 147 | − const stored = yield* store.executionInteractions | |
| 148 | − .getById(input.interactionId) | |
| 149 | − .pipe( | |
| 150 | − Effect.mapError((error) => | |
| 151 | − input.operation.unknownStorage( | |
| 152 | − error, | |
| 153 | − `Failed loading execution interaction ${input.interactionId}`, | |
| 154 | − ), | |
| 155 | − ), | |
| 156 | − ); | |
| 157 | − | |
| 158 | − if (Option.isNone(stored)) { | |
| 159 | − return yield* input.operation.notFound( | |
| 160 | − "Source credential request not found", | |
| 161 | − `interactionId=${input.interactionId}`, | |
| 162 | − ); | |
| 163 | − } | |
| 164 | − | |
| 165 | − const decoded = decodeSourceCredentialInteraction(stored.value); | |
| 166 | − if ( | |
| 167 | − decoded === null || | |
| 168 | − decoded.scopeId !== input.scopeId || | |
| 169 | − decoded.sourceId !== input.sourceId | |
| 170 | − ) { | |
| 171 | − return yield* input.operation.notFound( | |
| 172 | − "Source credential request not found", | |
| 173 | − `scopeId=${input.scopeId} sourceId=${input.sourceId} interactionId=${input.interactionId}`, | |
| 174 | − ); | |
| 175 | − } | |
| 176 | − | |
| 177 | − const source = yield* sourceAuthService | |
| 178 | − .getSourceById({ | |
| 179 | − scopeId: input.scopeId, | |
| 180 | − sourceId: input.sourceId, | |
| 181 | − }) | |
| 182 | − .pipe( | |
| 183 | − Effect.mapError((error) => | |
| 184 | − input.operation.unknownStorage( | |
| 185 | − error, | |
| 186 | − `Failed loading source ${input.sourceId}`, | |
| 187 | − ), | |
| 188 | − ), | |
| 189 | − ); | |
| 190 | − | |
| 191 | − return { | |
| 192 | − ...decoded, | |
| 193 | − sourceLabel: source.name, | |
| 194 | − endpoint: source.endpoint, | |
| 195 | − } satisfies SourceCredentialInteraction; | |
| 196 | − }); | |
| 197 | − | |
| 198 | 14 | export const getLocalInstallation = () => |
| 199 | 15 | Effect.gen(function* () { |
| 200 | 16 | const installationStore = yield* InstallationStore; |
| @@ -207,199 +23,3 @@ export const getLocalInstallation = () => · 6 unmodified lines | ||
| 207 | 23 | ), |
| 208 | 24 | ); |
| 209 | 25 | }); |
| 210 | − | |
| 211 | −export const getSourceCredentialInteraction = (input: { | |
| 212 | − scopeId: ScopeId; | |
| 213 | − sourceId: Source["id"]; | |
| 214 | − interactionId: ExecutionInteraction["id"]; | |
| 215 | −}) => | |
| 216 | − loadSourceCredentialInteraction({ | |
| 217 | − ...input, | |
| 218 | − operation: localOps.sourceCredentialPage, | |
| 219 | − }); | |
| 220 | − | |
| 221 | −export const submitSourceCredentialInteraction = (input: { | |
| 222 | − scopeId: ScopeId; | |
| 223 | − sourceId: Source["id"]; | |
| 224 | − interactionId: ExecutionInteraction["id"]; | |
| 225 | − action: "submit" | "continue" | "cancel"; | |
| 226 | − token?: string | null; | |
| 227 | −}) => | |
| 228 | − Effect.gen(function* () { | |
| 229 | − const interaction = yield* loadSourceCredentialInteraction({ | |
| 230 | − scopeId: input.scopeId, | |
| 231 | − sourceId: input.sourceId, | |
| 232 | − interactionId: input.interactionId, | |
| 233 | − operation: localOps.sourceCredentialSubmit, | |
| 234 | − }); | |
| 235 | − | |
| 236 | − if (interaction.status !== "pending") { | |
| 237 | − return yield* localOps.sourceCredentialSubmit.badRequest( | |
| 238 | − "Source credential request is no longer active", | |
| 239 | − `interactionId=${interaction.interactionId} status=${interaction.status}`, | |
| 240 | − ); | |
| 241 | − } | |
| 242 | − | |
| 243 | − const liveExecutionManager = yield* LiveExecutionManagerService; | |
| 244 | − | |
| 245 | − if (input.action === "cancel") { | |
| 246 | − const resumed = yield* liveExecutionManager.resolveInteraction({ | |
| 247 | − executionId: interaction.executionId, | |
| 248 | − response: { | |
| 249 | − action: "cancel", | |
| 250 | − }, | |
| 251 | − }); | |
| 252 | − | |
| 253 | − if (!resumed) { | |
| 254 | − const persisted = yield* submitExecutionInteractionResponse({ | |
| 255 | − executionId: interaction.executionId, | |
| 256 | − response: { | |
| 257 | − action: "cancel", | |
| 258 | − }, | |
| 259 | − }).pipe( | |
| 260 | − Effect.mapError((error) => | |
| 261 | − localOps.sourceCredentialSubmit.unknownStorage( | |
| 262 | − error, | |
| 263 | − `Failed resuming execution for interaction ${interaction.interactionId}`, | |
| 264 | − ), | |
| 265 | − ), | |
| 266 | − ); | |
| 267 | − | |
| 268 | − if (!persisted) { | |
| 269 | − return yield* localOps.sourceCredentialSubmit.badRequest( | |
| 270 | − "Source credential request is no longer resumable", | |
| 271 | − `interactionId=${interaction.interactionId}`, | |
| 272 | − ); | |
| 273 | − } | |
| 274 | − } | |
| 275 | − | |
| 276 | − return { | |
| 277 | − kind: "cancelled" as const, | |
| 278 | − sourceLabel: interaction.sourceLabel, | |
| 279 | − endpoint: interaction.endpoint, | |
| 280 | − }; | |
| 281 | − } | |
| 282 | − | |
| 283 | − if (input.action === "continue") { | |
| 284 | − const resumed = yield* liveExecutionManager.resolveInteraction({ | |
| 285 | − executionId: interaction.executionId, | |
| 286 | − response: { | |
| 287 | − action: "accept", | |
| 288 | − content: createSourceCredentialSelectionNoneContent(), | |
| 289 | − }, | |
| 290 | − }); | |
| 291 | − | |
| 292 | − if (!resumed) { | |
| 293 | − const persisted = yield* submitExecutionInteractionResponse({ | |
| 294 | − executionId: interaction.executionId, | |
| 295 | − response: { | |
| 296 | − action: "accept", | |
| 297 | − content: createSourceCredentialSelectionNoneContent(), | |
| 298 | − }, | |
| 299 | − }).pipe( | |
| 300 | − Effect.mapError((error) => | |
| 301 | − localOps.sourceCredentialSubmit.unknownStorage( | |
| 302 | − error, | |
| 303 | − `Failed resuming execution for interaction ${interaction.interactionId}`, | |
| 304 | − ), | |
| 305 | − ), | |
| 306 | − ); | |
| 307 | − | |
| 308 | − if (!persisted) { | |
| 309 | − return yield* localOps.sourceCredentialSubmit.badRequest( | |
| 310 | − "Source credential request is no longer resumable", | |
| 311 | − `interactionId=${interaction.interactionId}`, | |
| 312 | − ); | |
| 313 | − } | |
| 314 | − } | |
| 315 | − | |
| 316 | − return { | |
| 317 | − kind: "continued" as const, | |
| 318 | − sourceLabel: interaction.sourceLabel, | |
| 319 | − endpoint: interaction.endpoint, | |
| 320 | − }; | |
| 321 | − } | |
| 322 | − | |
| 323 | − const token = trimOrNull(input.token); | |
| 324 | − if (token === null) { | |
| 325 | − return yield* localOps.sourceCredentialSubmit.badRequest( | |
| 326 | − "Missing token", | |
| 327 | − `interactionId=${interaction.interactionId}`, | |
| 328 | − ); | |
| 329 | − } | |
| 330 | − | |
| 331 | − const sourceAuthService = yield* RuntimeSourceAuthServiceTag; | |
| 332 | − const tokenRef = yield* sourceAuthService | |
| 333 | − .storeSecretMaterial({ | |
| 334 | − purpose: "auth_material", | |
| 335 | − value: token, | |
| 336 | − }) | |
| 337 | − .pipe( | |
| 338 | − Effect.mapError((error) => | |
| 339 | − localOps.sourceCredentialSubmit.unknownStorage( | |
| 340 | − error, | |
| 341 | − `Failed storing credential material for interaction ${interaction.interactionId}`, | |
| 342 | − ), | |
| 343 | − ), | |
| 344 | − ); | |
| 345 | − const resumed = yield* liveExecutionManager.resolveInteraction({ | |
| 346 | − executionId: interaction.executionId, | |
| 347 | − response: { | |
| 348 | − action: "accept", | |
| 349 | − content: createSourceCredentialSelectionBearerContent(tokenRef), | |
| 350 | − }, | |
| 351 | − }); | |
| 352 | − | |
| 353 | − if (!resumed) { | |
| 354 | − const persisted = yield* submitExecutionInteractionResponse({ | |
| 355 | − executionId: interaction.executionId, | |
| 356 | − response: { | |
| 357 | − action: "accept", | |
| 358 | − content: createSourceCredentialSelectionBearerContent(tokenRef), | |
| 359 | − }, | |
| 360 | − }).pipe( | |
| 361 | − Effect.mapError((error) => | |
| 362 | − localOps.sourceCredentialSubmit.unknownStorage( | |
| 363 | − error, | |
| 364 | − `Failed resuming execution for interaction ${interaction.interactionId}`, | |
| 365 | − ), | |
| 366 | − ), | |
| 367 | − ); | |
| 368 | − | |
| 369 | − if (!persisted) { | |
| 370 | − return yield* localOps.sourceCredentialSubmit.badRequest( | |
| 371 | − "Source credential request is no longer resumable", | |
| 372 | − `interactionId=${interaction.interactionId}`, | |
| 373 | − ); | |
| 374 | − } | |
| 375 | − } | |
| 376 | − | |
| 377 | − return { | |
| 378 | − kind: "stored" as const, | |
| 379 | − sourceLabel: interaction.sourceLabel, | |
| 380 | − endpoint: interaction.endpoint, | |
| 381 | − }; | |
| 382 | − }); | |
| 383 | − | |
| 384 | −export const completeSourceCredentialSetup = (input: { | |
| 385 | − scopeId: ScopeId; | |
| 386 | − sourceId: Source["id"]; | |
| 387 | − state: string; | |
| 388 | − code?: string | null; | |
| 389 | − error?: string | null; | |
| 390 | − errorDescription?: string | null; | |
| 391 | −}) => | |
| 392 | − Effect.gen(function* () { | |
| 393 | − const sourceAuthService = yield* RuntimeSourceAuthServiceTag; | |
| 394 | − | |
| 395 | − return yield* sourceAuthService | |
| 396 | − .completeSourceCredentialSetup(input) | |
| 397 | − .pipe( | |
| 398 | − Effect.mapError((error) => | |
| 399 | − localOps.sourceCredentialComplete.unknownStorage( | |
| 400 | − error, | |
| 401 | − "Failed completing source credential setup", | |
| 402 | − ), | |
| 403 | − ), | |
| 404 | − ); | |
| 405 | − }); | |
| @@ -0,0 +1,98 @@ | ||
| 1 | +import type { SourceCatalogSyncResult } from "@executor/source-core"; | |
| 2 | +import type { | |
| 3 | + Source, | |
| 4 | + SourceCatalogKind, | |
| 5 | +} from "@executor/source-core"; | |
| 6 | +import type { ExecutorEffect } from "./executor-effect"; | |
| 7 | +import type { Source as ExecutorSource } from "./schema"; | |
| 8 | +import type { | |
| 9 | + SourceInvokeInput, | |
| 10 | + SourceInvokeResult, | |
| 11 | + SourceSyncInput, | |
| 12 | +} from "@executor/source-core"; | |
| 13 | +import * as Effect from "effect/Effect"; | |
| 14 | + | |
| 15 | +export type ExecutorSdkPlugin< | |
| 16 | + TKey extends string = string, | |
| 17 | + TExtension extends object = {}, | |
| 18 | +> = { | |
| 19 | + key: TKey; | |
| 20 | + sources?: readonly SourcePluginRuntime[]; | |
| 21 | + extendExecutor?: (input: { | |
| 22 | + executor: ExecutorEffect & Record<string, unknown>; | |
| 23 | + host: ExecutorSdkPluginHost; | |
| 24 | + }) => TExtension; | |
| 25 | +}; | |
| 26 | + | |
| 27 | +export type ExecutorSdkPluginHost = { | |
| 28 | + sources: { | |
| 29 | + create: (input: { | |
| 30 | + source: Omit< | |
| 31 | + ExecutorSource, | |
| 32 | + "id" | "scopeId" | "createdAt" | "updatedAt" | |
| 33 | + >; | |
| 34 | + }) => Effect.Effect<ExecutorSource, Error, never>; | |
| 35 | + get: (sourceId: ExecutorSource["id"]) => Effect.Effect<ExecutorSource, Error, never>; | |
| 36 | + save: (source: ExecutorSource) => Effect.Effect<ExecutorSource, Error, never>; | |
| 37 | + remove: (sourceId: ExecutorSource["id"]) => Effect.Effect<boolean, Error, never>; | |
| 38 | + }; | |
| 39 | +}; | |
| 40 | + | |
| 41 | +export type ExecutorSdkPluginExtensions< | |
| 42 | + TPlugins extends readonly ExecutorSdkPlugin<any, any>[], | |
| 43 | +> = { | |
| 44 | + [TPlugin in TPlugins[number] as TPlugin["key"]]: | |
| 45 | + TPlugin extends ExecutorSdkPlugin<any, infer TExtension> | |
| 46 | + ? TExtension | |
| 47 | + : never; | |
| 48 | +}; | |
| 49 | + | |
| 50 | +export type SourcePluginRuntime = { | |
| 51 | + kind: string; | |
| 52 | + displayName: string; | |
| 53 | + catalogKind: SourceCatalogKind; | |
| 54 | + catalogIdentity?: (input: { | |
| 55 | + source: Source; | |
| 56 | + }) => Record<string, unknown>; | |
| 57 | + getIrModel: ( | |
| 58 | + input: SourceSyncInput, | |
| 59 | + ) => Effect.Effect<SourceCatalogSyncResult, Error, never>; | |
| 60 | + invoke: ( | |
| 61 | + input: SourceInvokeInput, | |
| 62 | + ) => Effect.Effect<SourceInvokeResult, Error, never>; | |
| 63 | +}; | |
| 64 | + | |
| 65 | +export const registerExecutorSdkPlugins = ( | |
| 66 | + plugins: readonly ExecutorSdkPlugin[], | |
| 67 | +) => { | |
| 68 | + const sourcePlugins = new Map<string, SourcePluginRuntime>(); | |
| 69 | + | |
| 70 | + for (const plugin of plugins) { | |
| 71 | + for (const source of plugin.sources ?? []) { | |
| 72 | + sourcePlugins.set(source.kind, source); | |
| 73 | + } | |
| 74 | + } | |
| 75 | + | |
| 76 | + const getSourcePlugin = (kind: string) => { | |
| 77 | + const definition = sourcePlugins.get(kind); | |
| 78 | + if (!definition) { | |
| 79 | + throw new Error(`Unsupported source plugin: ${kind}`); | |
| 80 | + } | |
| 81 | + | |
| 82 | + return definition; | |
| 83 | + }; | |
| 84 | + | |
| 85 | + const getSourcePluginForSource = (source: Pick<Source, "kind">) => | |
| 86 | + getSourcePlugin(source.kind); | |
| 87 | + | |
| 88 | + return { | |
| 89 | + plugins, | |
| 90 | + sourcePlugins: [...sourcePlugins.values()], | |
| 91 | + getSourcePlugin, | |
| 92 | + getSourcePluginForSource, | |
| 93 | + sourcePluginCatalogKind: (kind: string): SourceCatalogKind => | |
| 94 | + getSourcePlugin(kind).catalogKind, | |
| 95 | + isInternalSourcePluginKind: (kind: string): boolean => | |
| 96 | + getSourcePlugin(kind).catalogKind === "internal", | |
| 97 | + }; | |
| 98 | +}; | |
| @@ -1,514 +0,0 @@ | ||
| 1 | −import type { | |
| 2 | − OAuthClientProvider, | |
| 3 | −} from "@modelcontextprotocol/sdk/client/auth.js"; | |
| 4 | −import { | |
| 5 | − type ScopeId, | |
| 6 | − AuthGrantSetJsonSchema, | |
| 7 | − McpOAuthAuthArtifactConfigJsonSchema, | |
| 8 | − McpOAuthAuthArtifactKind, | |
| 9 | − ProviderGrantRefAuthArtifactConfigJsonSchema, | |
| 10 | − ProviderGrantRefAuthArtifactKind, | |
| 11 | − RequestPlacementTemplatesJsonSchema, | |
| 12 | − RefreshableOAuth2AuthorizedUserAuthArtifactConfigJsonSchema, | |
| 13 | − RefreshableOAuth2AuthorizedUserAuthArtifactKind, | |
| 14 | − StaticBearerAuthArtifactConfigJsonSchema, | |
| 15 | − StaticBearerAuthArtifactKind, | |
| 16 | − StaticOAuth2AuthArtifactConfigJsonSchema, | |
| 17 | − StaticOAuth2AuthArtifactKind, | |
| 18 | − StaticPlacementsAuthArtifactConfigJsonSchema, | |
| 19 | − StaticPlacementsAuthArtifactKind, | |
| 20 | − authArtifactSecretRefs, | |
| 21 | − decodeAuthGrantSet, | |
| 22 | − decodeBuiltInAuthArtifactConfig, | |
| 23 | − decodeMcpOAuthAuthArtifactConfig, | |
| 24 | − decodeProviderGrantRefAuthArtifactConfig, | |
| 25 | − type AuthArtifact, | |
| 26 | − type CredentialSlot, | |
| 27 | − type RequestPlacement, | |
| 28 | − type RequestPlacementPart, | |
| 29 | − type SecretRef, | |
| 30 | − type Source, | |
| 31 | − type SourceAuth, | |
| 32 | −} from "#schema"; | |
| 33 | −import * as Either from "effect/Either"; | |
| 34 | −import * as Effect from "effect/Effect"; | |
| 35 | −import * as Schema from "effect/Schema"; | |
| 36 | − | |
| 37 | −import type { | |
| 38 | − ResolveSecretMaterial, | |
| 39 | − SecretMaterialResolveContext, | |
| 40 | −} from "../scope/secret-material-providers"; | |
| 41 | −import { | |
| 42 | − runtimeEffectError, | |
| 43 | −} from "../effect-errors"; | |
| 44 | − | |
| 45 | −export type ResolvedSourceAuthMaterial = { | |
| 46 | − placements: ReadonlyArray<RequestPlacement>; | |
| 47 | − headers: Readonly<Record<string, string>>; | |
| 48 | − queryParams: Readonly<Record<string, string>>; | |
| 49 | − cookies: Readonly<Record<string, string>>; | |
| 50 | − bodyValues: Readonly<Record<string, string>>; | |
| 51 | − expiresAt: number | null; | |
| 52 | − refreshAfter: number | null; | |
| 53 | − authProvider?: OAuthClientProvider | undefined; | |
| 54 | −}; | |
| 55 | − | |
| 56 | −const emptyResolvedAuthMaterial: ResolvedSourceAuthMaterial = { | |
| 57 | − placements: [], | |
| 58 | − headers: {}, | |
| 59 | − queryParams: {}, | |
| 60 | − cookies: {}, | |
| 61 | − bodyValues: {}, | |
| 62 | − expiresAt: null, | |
| 63 | − refreshAfter: null, | |
| 64 | − authProvider: undefined, | |
| 65 | −}; | |
| 66 | − | |
| 67 | −const encodeStaticBearerAuthArtifactConfig = Schema.encodeSync( | |
| 68 | − StaticBearerAuthArtifactConfigJsonSchema, | |
| 69 | −); | |
| 70 | − | |
| 71 | −const encodeStaticOAuth2AuthArtifactConfig = Schema.encodeSync( | |
| 72 | − StaticOAuth2AuthArtifactConfigJsonSchema, | |
| 73 | −); | |
| 74 | − | |
| 75 | −const encodeStaticPlacementsAuthArtifactConfig = Schema.encodeSync( | |
| 76 | − StaticPlacementsAuthArtifactConfigJsonSchema, | |
| 77 | −); | |
| 78 | −const encodeRefreshableOAuth2AuthorizedUserAuthArtifactConfig = Schema.encodeSync( | |
| 79 | − RefreshableOAuth2AuthorizedUserAuthArtifactConfigJsonSchema, | |
| 80 | −); | |
| 81 | −const encodeProviderGrantRefAuthArtifactConfig = Schema.encodeSync( | |
| 82 | − ProviderGrantRefAuthArtifactConfigJsonSchema, | |
| 83 | −); | |
| 84 | −const encodeMcpOAuthAuthArtifactConfig = Schema.encodeSync( | |
| 85 | − McpOAuthAuthArtifactConfigJsonSchema, | |
| 86 | −); | |
| 87 | − | |
| 88 | −const decodeRequestPlacementTemplates = Schema.decodeUnknownEither( | |
| 89 | − RequestPlacementTemplatesJsonSchema, | |
| 90 | −); | |
| 91 | −const encodeAuthGrantSet = Schema.encodeSync(AuthGrantSetJsonSchema); | |
| 92 | − | |
| 93 | −const mergePlacement = (acc: { | |
| 94 | − headers: Record<string, string>; | |
| 95 | − queryParams: Record<string, string>; | |
| 96 | − cookies: Record<string, string>; | |
| 97 | − bodyValues: Record<string, string>; | |
| 98 | −}, placement: RequestPlacement) => { | |
| 99 | − switch (placement.location) { | |
| 100 | − case "header": | |
| 101 | − acc.headers[placement.name] = placement.value; | |
| 102 | − break; | |
| 103 | − case "query": | |
| 104 | − acc.queryParams[placement.name] = placement.value; | |
| 105 | − break; | |
| 106 | − case "cookie": | |
| 107 | − acc.cookies[placement.name] = placement.value; | |
| 108 | − break; | |
| 109 | − case "body": | |
| 110 | − acc.bodyValues[placement.path] = placement.value; | |
| 111 | − break; | |
| 112 | − } | |
| 113 | −}; | |
| 114 | − | |
| 115 | −const summarizeResolvedPlacements = (placements: ReadonlyArray<RequestPlacement>, input: { | |
| 116 | − expiresAt?: number | null; | |
| 117 | − refreshAfter?: number | null; | |
| 118 | −} = {}): ResolvedSourceAuthMaterial => { | |
| 119 | − const acc = { | |
| 120 | − headers: {} as Record<string, string>, | |
| 121 | − queryParams: {} as Record<string, string>, | |
| 122 | − cookies: {} as Record<string, string>, | |
| 123 | − bodyValues: {} as Record<string, string>, | |
| 124 | − }; | |
| 125 | − | |
| 126 | − for (const placement of placements) { | |
| 127 | − mergePlacement(acc, placement); | |
| 128 | − } | |
| 129 | − | |
| 130 | − return { | |
| 131 | − placements, | |
| 132 | − headers: acc.headers, | |
| 133 | − queryParams: acc.queryParams, | |
| 134 | − cookies: acc.cookies, | |
| 135 | − bodyValues: acc.bodyValues, | |
| 136 | − expiresAt: input.expiresAt ?? null, | |
| 137 | − refreshAfter: input.refreshAfter ?? null, | |
| 138 | − }; | |
| 139 | −}; | |
| 140 | − | |
| 141 | −const resolvePlacementParts = (input: { | |
| 142 | − parts: ReadonlyArray<RequestPlacementPart>; | |
| 143 | − resolveSecretMaterial: ResolveSecretMaterial; | |
| 144 | − context?: SecretMaterialResolveContext; | |
| 145 | −}): Effect.Effect<string, Error, never> => | |
| 146 | − Effect.map( | |
| 147 | − Effect.forEach(input.parts, (part) => | |
| 148 | − part.kind === "literal" | |
| 149 | − ? Effect.succeed(part.value) | |
| 150 | − : input.resolveSecretMaterial({ | |
| 151 | − ref: part.ref, | |
| 152 | − context: input.context, | |
| 153 | − }), { discard: false }), | |
| 154 | − (values) => values.join(""), | |
| 155 | − ); | |
| 156 | − | |
| 157 | −export const authArtifactFromSourceAuth = (input: { | |
| 158 | − source: Source; | |
| 159 | − auth: SourceAuth; | |
| 160 | − slot: CredentialSlot; | |
| 161 | − actorScopeId?: ScopeId | null; | |
| 162 | − existingAuthArtifactId?: AuthArtifact["id"] | null; | |
| 163 | −}): AuthArtifact | null => { | |
| 164 | − if (input.auth.kind === "none") { | |
| 165 | − return null; | |
| 166 | − } | |
| 167 | − | |
| 168 | − const id = input.existingAuthArtifactId ?? `auth_art_${crypto.randomUUID()}` as AuthArtifact["id"]; | |
| 169 | − const grantSetJson = | |
| 170 | − input.auth.kind === "oauth2_authorized_user" | |
| 171 | − ? encodeAuthGrantSetJson(input.auth.grantSet) | |
| 172 | − : null; | |
| 173 | − | |
| 174 | − if (input.auth.kind === "bearer") { | |
| 175 | − return { | |
| 176 | − id, | |
| 177 | − scopeId: input.source.scopeId, | |
| 178 | − sourceId: input.source.id, | |
| 179 | − actorScopeId: input.actorScopeId ?? null, | |
| 180 | − slot: input.slot, | |
| 181 | − artifactKind: StaticBearerAuthArtifactKind, | |
| 182 | − configJson: encodeStaticBearerAuthArtifactConfig({ | |
| 183 | − headerName: input.auth.headerName, | |
| 184 | − prefix: input.auth.prefix, | |
| 185 | − token: input.auth.token, | |
| 186 | − }), | |
| 187 | − grantSetJson, | |
| 188 | − createdAt: input.source.createdAt, | |
| 189 | − updatedAt: input.source.updatedAt, | |
| 190 | − }; | |
| 191 | − } | |
| 192 | − | |
| 193 | − if (input.auth.kind === "oauth2_authorized_user") { | |
| 194 | − return { | |
| 195 | − id, | |
| 196 | − scopeId: input.source.scopeId, | |
| 197 | − sourceId: input.source.id, | |
| 198 | − actorScopeId: input.actorScopeId ?? null, | |
| 199 | − slot: input.slot, | |
| 200 | − artifactKind: RefreshableOAuth2AuthorizedUserAuthArtifactKind, | |
| 201 | − configJson: encodeRefreshableOAuth2AuthorizedUserAuthArtifactConfig({ | |
| 202 | − headerName: input.auth.headerName, | |
| 203 | − prefix: input.auth.prefix, | |
| 204 | − tokenEndpoint: input.auth.tokenEndpoint, | |
| 205 | − clientId: input.auth.clientId, | |
| 206 | − clientAuthentication: input.auth.clientAuthentication, | |
| 207 | − clientSecret: input.auth.clientSecret, | |
| 208 | − refreshToken: input.auth.refreshToken, | |
| 209 | − }), | |
| 210 | − grantSetJson, | |
| 211 | − createdAt: input.source.createdAt, | |
| 212 | − updatedAt: input.source.updatedAt, | |
| 213 | − }; | |
| 214 | − } | |
| 215 | − | |
| 216 | − if (input.auth.kind === "provider_grant_ref") { | |
| 217 | − return { | |
| 218 | − id, | |
| 219 | − scopeId: input.source.scopeId, | |
| 220 | − sourceId: input.source.id, | |
| 221 | − actorScopeId: input.actorScopeId ?? null, | |
| 222 | − slot: input.slot, | |
| 223 | − artifactKind: ProviderGrantRefAuthArtifactKind, | |
| 224 | − configJson: encodeProviderGrantRefAuthArtifactConfig({ | |
| 225 | − grantId: input.auth.grantId, | |
| 226 | − providerKey: input.auth.providerKey, | |
| 227 | − requiredScopes: [...input.auth.requiredScopes], | |
| 228 | − headerName: input.auth.headerName, | |
| 229 | − prefix: input.auth.prefix, | |
| 230 | − }), | |
| 231 | − grantSetJson, | |
| 232 | − createdAt: input.source.createdAt, | |
| 233 | − updatedAt: input.source.updatedAt, | |
| 234 | − }; | |
| 235 | − } | |
| 236 | − | |
| 237 | − if (input.auth.kind === "mcp_oauth") { | |
| 238 | − return { | |
| 239 | − id, | |
| 240 | − scopeId: input.source.scopeId, | |
| 241 | − sourceId: input.source.id, | |
| 242 | − actorScopeId: input.actorScopeId ?? null, | |
| 243 | − slot: input.slot, | |
| 244 | − artifactKind: McpOAuthAuthArtifactKind, | |
| 245 | − configJson: encodeMcpOAuthAuthArtifactConfig({ | |
| 246 | − redirectUri: input.auth.redirectUri, | |
| 247 | − accessToken: input.auth.accessToken, | |
| 248 | − refreshToken: input.auth.refreshToken, | |
| 249 | − tokenType: input.auth.tokenType, | |
| 250 | − expiresIn: input.auth.expiresIn, | |
| 251 | − scope: input.auth.scope, | |
| 252 | − resourceMetadataUrl: input.auth.resourceMetadataUrl, | |
| 253 | − authorizationServerUrl: input.auth.authorizationServerUrl, | |
| 254 | − resourceMetadataJson: input.auth.resourceMetadataJson, | |
| 255 | − authorizationServerMetadataJson: input.auth.authorizationServerMetadataJson, | |
| 256 | − clientInformationJson: input.auth.clientInformationJson, | |
| 257 | − }), | |
| 258 | − grantSetJson, | |
| 259 | − createdAt: input.source.createdAt, | |
| 260 | − updatedAt: input.source.updatedAt, | |
| 261 | − }; | |
| 262 | − } | |
| 263 | − | |
| 264 | − return { | |
| 265 | − id, | |
| 266 | − scopeId: input.source.scopeId, | |
| 267 | − sourceId: input.source.id, | |
| 268 | − actorScopeId: input.actorScopeId ?? null, | |
| 269 | − slot: input.slot, | |
| 270 | − artifactKind: StaticOAuth2AuthArtifactKind, | |
| 271 | − configJson: encodeStaticOAuth2AuthArtifactConfig({ | |
| 272 | − headerName: input.auth.headerName, | |
| 273 | − prefix: input.auth.prefix, | |
| 274 | − accessToken: input.auth.accessToken, | |
| 275 | − refreshToken: input.auth.refreshToken, | |
| 276 | − }), | |
| 277 | − grantSetJson, | |
| 278 | − createdAt: input.source.createdAt, | |
| 279 | − updatedAt: input.source.updatedAt, | |
| 280 | − }; | |
| 281 | −}; | |
| 282 | − | |
| 283 | −export const sourceAuthFromAuthArtifact = (artifact: AuthArtifact | null): SourceAuth => { | |
| 284 | − if (artifact === null) { | |
| 285 | − return { kind: "none" }; | |
| 286 | − } | |
| 287 | − | |
| 288 | − const providerGrantRefConfig = decodeProviderGrantRefAuthArtifactConfig(artifact); | |
| 289 | − if (providerGrantRefConfig !== null) { | |
| 290 | − return { | |
| 291 | − kind: "provider_grant_ref", | |
| 292 | − grantId: providerGrantRefConfig.grantId, | |
| 293 | − providerKey: providerGrantRefConfig.providerKey, | |
| 294 | − requiredScopes: [...providerGrantRefConfig.requiredScopes], | |
| 295 | − headerName: providerGrantRefConfig.headerName, | |
| 296 | − prefix: providerGrantRefConfig.prefix, | |
| 297 | − }; | |
| 298 | − } | |
| 299 | − | |
| 300 | − const mcpOAuthConfig = decodeMcpOAuthAuthArtifactConfig(artifact); | |
| 301 | − if (mcpOAuthConfig !== null) { | |
| 302 | − return { | |
| 303 | − kind: "mcp_oauth", | |
| 304 | − redirectUri: mcpOAuthConfig.redirectUri, | |
| 305 | − accessToken: mcpOAuthConfig.accessToken, | |
| 306 | − refreshToken: mcpOAuthConfig.refreshToken, | |
| 307 | − tokenType: mcpOAuthConfig.tokenType, | |
| 308 | − expiresIn: mcpOAuthConfig.expiresIn, | |
| 309 | − scope: mcpOAuthConfig.scope, | |
| 310 | − resourceMetadataUrl: mcpOAuthConfig.resourceMetadataUrl, | |
| 311 | − authorizationServerUrl: mcpOAuthConfig.authorizationServerUrl, | |
| 312 | − resourceMetadataJson: mcpOAuthConfig.resourceMetadataJson, | |
| 313 | − authorizationServerMetadataJson: mcpOAuthConfig.authorizationServerMetadataJson, | |
| 314 | − clientInformationJson: mcpOAuthConfig.clientInformationJson, | |
| 315 | − }; | |
| 316 | − } | |
| 317 | − | |
| 318 | − const decoded = decodeBuiltInAuthArtifactConfig(artifact); | |
| 319 | − if (decoded === null) { | |
| 320 | − return { kind: "none" }; | |
| 321 | − } | |
| 322 | − | |
| 323 | − switch (decoded.artifactKind) { | |
| 324 | − case StaticBearerAuthArtifactKind: | |
| 325 | − return { | |
| 326 | − kind: "bearer", | |
| 327 | − headerName: decoded.config.headerName, | |
| 328 | − prefix: decoded.config.prefix, | |
| 329 | − token: decoded.config.token, | |
| 330 | − }; | |
| 331 | − case StaticOAuth2AuthArtifactKind: | |
| 332 | − return { | |
| 333 | − kind: "oauth2", | |
| 334 | − headerName: decoded.config.headerName, | |
| 335 | − prefix: decoded.config.prefix, | |
| 336 | − accessToken: decoded.config.accessToken, | |
| 337 | − refreshToken: decoded.config.refreshToken, | |
| 338 | − }; | |
| 339 | − case StaticPlacementsAuthArtifactKind: | |
| 340 | − return { kind: "none" }; | |
| 341 | − case RefreshableOAuth2AuthorizedUserAuthArtifactKind: | |
| 342 | − return { | |
| 343 | − kind: "oauth2_authorized_user", | |
| 344 | − headerName: decoded.config.headerName, | |
| 345 | − prefix: decoded.config.prefix, | |
| 346 | − tokenEndpoint: decoded.config.tokenEndpoint, | |
| 347 | − clientId: decoded.config.clientId, | |
| 348 | − clientAuthentication: decoded.config.clientAuthentication, | |
| 349 | − clientSecret: decoded.config.clientSecret, | |
| 350 | − refreshToken: decoded.config.refreshToken, | |
| 351 | − grantSet: decodeAuthGrantSet(artifact.grantSetJson), | |
| 352 | − }; | |
| 353 | − } | |
| 354 | −}; | |
| 355 | − | |
| 356 | −export const authArtifactGrantSet = (artifact: Pick<AuthArtifact, "grantSetJson">): ReadonlyArray<string> | null => | |
| 357 | − decodeAuthGrantSet(artifact.grantSetJson); | |
| 358 | − | |
| 359 | −export const authArtifactSecretMaterialRefs = ( | |
| 360 | − artifact: Pick<AuthArtifact, "artifactKind" | "configJson">, | |
| 361 | −): ReadonlyArray<SecretRef> => authArtifactSecretRefs(artifact); | |
| 362 | − | |
| 363 | −export const encodeStaticPlacementsArtifactConfig = (placements: ReadonlyArray<{ | |
| 364 | − location: "header" | "query" | "cookie" | "body"; | |
| 365 | − name?: string; | |
| 366 | − path?: string; | |
| 367 | − parts: ReadonlyArray<RequestPlacementPart>; | |
| 368 | −}>): string => | |
| 369 | − encodeStaticPlacementsAuthArtifactConfig({ | |
| 370 | − placements: placements.map((placement) => | |
| 371 | − placement.location === "body" | |
| 372 | − ? { | |
| 373 | − location: "body" as const, | |
| 374 | − path: placement.path ?? "", | |
| 375 | − parts: [...placement.parts], | |
| 376 | − } | |
| 377 | − : { | |
| 378 | − location: placement.location, | |
| 379 | − name: placement.name ?? "", | |
| 380 | − parts: [...placement.parts], | |
| 381 | − }), | |
| 382 | − }); | |
| 383 | − | |
| 384 | −export const encodeAuthGrantSetJson = (grantSet: ReadonlyArray<string> | null): string | null => | |
| 385 | − grantSet === null ? null : encodeAuthGrantSet([...grantSet]); | |
| 386 | − | |
| 387 | −export const resolveAuthArtifactMaterial = (input: { | |
| 388 | − artifact: AuthArtifact | null; | |
| 389 | − lease?: { | |
| 390 | − placementsTemplateJson: string; | |
| 391 | − expiresAt: number | null; | |
| 392 | − refreshAfter: number | null; | |
| 393 | − } | null; | |
| 394 | − resolveSecretMaterial: ResolveSecretMaterial; | |
| 395 | − context?: SecretMaterialResolveContext; | |
| 396 | −}): Effect.Effect<ResolvedSourceAuthMaterial, Error, never> => | |
| 397 | − Effect.gen(function* () { | |
| 398 | − if (input.artifact === null) { | |
| 399 | − return emptyResolvedAuthMaterial; | |
| 400 | − } | |
| 401 | − | |
| 402 | − const decoded = decodeBuiltInAuthArtifactConfig(input.artifact); | |
| 403 | − if (decoded !== null) { | |
| 404 | − switch (decoded.artifactKind) { | |
| 405 | − case StaticBearerAuthArtifactKind: { | |
| 406 | − const token = yield* input.resolveSecretMaterial({ | |
| 407 | − ref: decoded.config.token, | |
| 408 | − context: input.context, | |
| 409 | − }); | |
| 410 | − | |
| 411 | − return summarizeResolvedPlacements([ | |
| 412 | − { | |
| 413 | − location: "header", | |
| 414 | − name: decoded.config.headerName, | |
| 415 | − value: `${decoded.config.prefix}${token}`, | |
| 416 | − }, | |
| 417 | − ]); | |
| 418 | − } | |
| 419 | − case StaticOAuth2AuthArtifactKind: { | |
| 420 | − const accessToken = yield* input.resolveSecretMaterial({ | |
| 421 | − ref: decoded.config.accessToken, | |
| 422 | − context: input.context, | |
| 423 | − }); | |
| 424 | − | |
| 425 | − return summarizeResolvedPlacements([ | |
| 426 | − { | |
| 427 | − location: "header", | |
| 428 | − name: decoded.config.headerName, | |
| 429 | − value: `${decoded.config.prefix}${accessToken}`, | |
| 430 | − }, | |
| 431 | − ]); | |
| 432 | − } | |
| 433 | − case StaticPlacementsAuthArtifactKind: { | |
| 434 | − const placements = yield* Effect.forEach(decoded.config.placements, (placement) => | |
| 435 | − Effect.map( | |
| 436 | − resolvePlacementParts({ | |
| 437 | − parts: placement.parts, | |
| 438 | − resolveSecretMaterial: input.resolveSecretMaterial, | |
| 439 | − context: input.context, | |
| 440 | − }), | |
| 441 | − (value): RequestPlacement => | |
| 442 | − placement.location === "body" | |
| 443 | − ? { | |
| 444 | − location: "body", | |
| 445 | − path: placement.path, | |
| 446 | − value, | |
| 447 | − } | |
| 448 | − : { | |
| 449 | − location: placement.location, | |
| 450 | − name: placement.name, | |
| 451 | − value, | |
| 452 | − }, | |
| 453 | − ), { discard: false }); | |
| 454 | − | |
| 455 | − return summarizeResolvedPlacements(placements); | |
| 456 | − } | |
| 457 | − case RefreshableOAuth2AuthorizedUserAuthArtifactKind: | |
| 458 | − break; | |
| 459 | − } | |
| 460 | − } | |
| 461 | − | |
| 462 | − const providerGrantRefConfig = decodeProviderGrantRefAuthArtifactConfig(input.artifact); | |
| 463 | − if (providerGrantRefConfig !== null) { | |
| 464 | − if (input.lease === null || input.lease === undefined) { | |
| 465 | − return yield* runtimeEffectError("auth/auth-artifacts", `Provider grant auth artifact ${input.artifact.id} requires a lease`); | |
| 466 | − } | |
| 467 | − } | |
| 468 | − | |
| 469 | − const mcpOAuthConfig = decodeMcpOAuthAuthArtifactConfig(input.artifact); | |
| 470 | − if (mcpOAuthConfig !== null) { | |
| 471 | − return { | |
| 472 | − ...emptyResolvedAuthMaterial, | |
| 473 | − }; | |
| 474 | − } | |
| 475 | − | |
| 476 | − if (input.lease === null || input.lease === undefined) { | |
| 477 | − return yield* runtimeEffectError("auth/auth-artifacts", `Unsupported auth artifact kind: ${input.artifact.artifactKind}`); | |
| 478 | − } | |
| 479 | − | |
| 480 | − const templatesEither = decodeRequestPlacementTemplates( | |
| 481 | − input.lease.placementsTemplateJson, | |
| 482 | − ); | |
| 483 | − if (Either.isLeft(templatesEither)) { | |
| 484 | − return yield* runtimeEffectError("auth/auth-artifacts", | |
| 485 | − `Invalid auth lease placements for artifact ${input.artifact.id}`, | |
| 486 | − ); | |
| 487 | − } | |
| 488 | − | |
| 489 | − const placements = yield* Effect.forEach(templatesEither.right, (placement) => | |
| 490 | − Effect.map( | |
| 491 | − resolvePlacementParts({ | |
| 492 | − parts: placement.parts, | |
| 493 | − resolveSecretMaterial: input.resolveSecretMaterial, | |
| 494 | − context: input.context, | |
| 495 | − }), | |
| 496 | − (value): RequestPlacement => | |
| 497 | − placement.location === "body" | |
| 498 | − ? { | |
| 499 | − location: "body", | |
| 500 | − path: placement.path, | |
| 501 | − value, | |
| 502 | − } | |
| 503 | − : { | |
| 504 | − location: placement.location, | |
| 505 | − name: placement.name, | |
| 506 | − value, | |
| 507 | − }, | |
| 508 | − ), { discard: false }); | |
| 509 | − | |
| 510 | − return summarizeResolvedPlacements(placements, { | |
| 511 | − expiresAt: input.lease.expiresAt, | |
| 512 | − refreshAfter: input.lease.refreshAfter, | |
| 513 | − }); | |
| 514 | − }); | |
| @@ -1,507 +0,0 @@ | ||
| 1 | −import type { | |
| 2 | − AuthArtifact, | |
| 3 | − AuthLease, | |
| 4 | − ProviderAuthGrant, | |
| 5 | − RequestPlacementTemplate, | |
| 6 | − SecretRef, | |
| 7 | −} from "#schema"; | |
| 8 | −import { | |
| 9 | − AuthLeaseIdSchema, | |
| 10 | − decodeMcpOAuthAuthArtifactConfig, | |
| 11 | − decodeProviderGrantRefAuthArtifactConfig, | |
| 12 | − RefreshableOAuth2AuthorizedUserAuthArtifactKind, | |
| 13 | − authLeaseSecretRefs, | |
| 14 | − decodeBuiltInAuthArtifactConfig, | |
| 15 | −} from "#schema"; | |
| 16 | −import * as Effect from "effect/Effect"; | |
| 17 | −import * as Option from "effect/Option"; | |
| 18 | − | |
| 19 | −import type { | |
| 20 | − ExecutorStateStoreShape, | |
| 21 | −} from "../executor-state-store"; | |
| 22 | −import { | |
| 23 | − resolveAuthArtifactMaterial, | |
| 24 | − type ResolvedSourceAuthMaterial, | |
| 25 | −} from "./auth-artifacts"; | |
| 26 | −import { | |
| 27 | − type DeleteSecretMaterial, | |
| 28 | − type ResolveSecretMaterial, | |
| 29 | − type SecretMaterialResolveContext, | |
| 30 | − type StoreSecretMaterial, | |
| 31 | −} from "../scope/secret-material-providers"; | |
| 32 | −import { | |
| 33 | − refreshOAuth2AccessToken, | |
| 34 | −} from "./oauth2-pkce"; | |
| 35 | −import type { | |
| 36 | − OAuth2TokenResponse, | |
| 37 | −} from "./oauth2-pkce"; | |
| 38 | −import { | |
| 39 | − createPersistedMcpAuthProvider, | |
| 40 | −} from "./mcp-auth-provider"; | |
| 41 | −import { | |
| 42 | − runtimeEffectError, | |
| 43 | −} from "../effect-errors"; | |
| 44 | − | |
| 45 | −const LEASE_REFRESH_SKEW_MS = 60_000; | |
| 46 | − | |
| 47 | −const encodeLeasePlacementTemplatesJson = (templates: ReadonlyArray<RequestPlacementTemplate>): string => | |
| 48 | − JSON.stringify(templates); | |
| 49 | − | |
| 50 | −const secretRefKey = (ref: SecretRef): string => | |
| 51 | − `${ref.providerId}:${ref.handle}`; | |
| 52 | − | |
| 53 | −const cleanupAuthLeaseSecretRefs = ( | |
| 54 | − executorState: ExecutorStateStoreShape, | |
| 55 | − input: { | |
| 56 | − previous: Pick<AuthLease, "placementsTemplateJson"> | null; | |
| 57 | − next: Pick<AuthLease, "placementsTemplateJson"> | null; | |
| 58 | − }, | |
| 59 | − deleteSecretMaterial: DeleteSecretMaterial, | |
| 60 | −) => | |
| 61 | − Effect.gen(function* () { | |
| 62 | − if (input.previous === null) { | |
| 63 | − return; | |
| 64 | − } | |
| 65 | − const nextRefKeys = new Set( | |
| 66 | − (input.next === null ? [] : authLeaseSecretRefs(input.next)).map(secretRefKey), | |
| 67 | − ); | |
| 68 | − const refsToDelete = authLeaseSecretRefs(input.previous).filter( | |
| 69 | − (ref) => !nextRefKeys.has(secretRefKey(ref)), | |
| 70 | − ); | |
| 71 | − | |
| 72 | − yield* Effect.forEach( | |
| 73 | − refsToDelete, | |
| 74 | − (ref) => Effect.either(deleteSecretMaterial(ref)), | |
| 75 | − { discard: true }, | |
| 76 | − ); | |
| 77 | − }); | |
| 78 | − | |
| 79 | −const leaseIsFresh = (lease: AuthLease | null, now: number): boolean => { | |
| 80 | − if (lease === null) { | |
| 81 | − return false; | |
| 82 | − } | |
| 83 | − | |
| 84 | − if (lease.refreshAfter !== null && now >= lease.refreshAfter) { | |
| 85 | − return false; | |
| 86 | − } | |
| 87 | − | |
| 88 | − if (lease.expiresAt !== null && now >= lease.expiresAt - LEASE_REFRESH_SKEW_MS) { | |
| 89 | − return false; | |
| 90 | − } | |
| 91 | − | |
| 92 | − return true; | |
| 93 | −}; | |
| 94 | − | |
| 95 | −const refreshRefreshableOauth2AuthorizedUserArtifact = (input: { | |
| 96 | − executorState: ExecutorStateStoreShape; | |
| 97 | − artifact: AuthArtifact; | |
| 98 | − lease: AuthLease | null; | |
| 99 | − resolveSecretMaterial: ResolveSecretMaterial; | |
| 100 | − storeSecretMaterial: StoreSecretMaterial; | |
| 101 | − deleteSecretMaterial: DeleteSecretMaterial; | |
| 102 | − context?: SecretMaterialResolveContext; | |
| 103 | −}): Effect.Effect<AuthLease, Error, never> => | |
| 104 | − Effect.gen(function* () { | |
| 105 | − const decoded = decodeBuiltInAuthArtifactConfig(input.artifact); | |
| 106 | − if ( | |
| 107 | − decoded === null | |
| 108 | − || decoded.artifactKind !== RefreshableOAuth2AuthorizedUserAuthArtifactKind | |
| 109 | − ) { | |
| 110 | − return yield* runtimeEffectError("auth/auth-leases", `Unsupported auth artifact kind: ${input.artifact.artifactKind}`); | |
| 111 | − } | |
| 112 | − | |
| 113 | − const refreshToken = yield* input.resolveSecretMaterial({ | |
| 114 | − ref: decoded.config.refreshToken, | |
| 115 | − context: input.context, | |
| 116 | − }); | |
| 117 | − let clientSecret: string | null = null; | |
| 118 | − if (decoded.config.clientSecret) { | |
| 119 | − clientSecret = yield* input.resolveSecretMaterial({ | |
| 120 | − ref: decoded.config.clientSecret, | |
| 121 | − context: input.context, | |
| 122 | − }); | |
| 123 | − } | |
| 124 | − | |
| 125 | − const tokenResponse = yield* refreshOAuth2AccessToken({ | |
| 126 | − tokenEndpoint: decoded.config.tokenEndpoint, | |
| 127 | − clientId: decoded.config.clientId, | |
| 128 | − clientAuthentication: decoded.config.clientAuthentication, | |
| 129 | − clientSecret, | |
| 130 | − refreshToken, | |
| 131 | − }); | |
| 132 | − | |
| 133 | − const accessTokenRef = yield* input.storeSecretMaterial({ | |
| 134 | − purpose: "oauth_access_token", | |
| 135 | − value: tokenResponse.access_token, | |
| 136 | − name: `${decoded.config.clientId} Access Token`, | |
| 137 | − }); | |
| 138 | − const now = Date.now(); | |
| 139 | − const expiresInMs = | |
| 140 | − typeof tokenResponse.expires_in === "number" && Number.isFinite(tokenResponse.expires_in) | |
| 141 | − ? Math.max(0, tokenResponse.expires_in * 1000) | |
| 142 | − : null; | |
| 143 | − const expiresAt = expiresInMs === null ? null : now + expiresInMs; | |
| 144 | − const refreshAfter = | |
| 145 | − expiresAt === null ? null : Math.max(now, expiresAt - LEASE_REFRESH_SKEW_MS); | |
| 146 | − | |
| 147 | − const nextLease: AuthLease = { | |
| 148 | − id: input.lease?.id ?? AuthLeaseIdSchema.make(`auth_lease_${crypto.randomUUID()}`), | |
| 149 | − authArtifactId: input.artifact.id, | |
| 150 | − scopeId: input.artifact.scopeId, | |
| 151 | − sourceId: input.artifact.sourceId, | |
| 152 | − actorScopeId: input.artifact.actorScopeId, | |
| 153 | − slot: input.artifact.slot, | |
| 154 | − placementsTemplateJson: encodeLeasePlacementTemplatesJson([ | |
| 155 | − { | |
| 156 | − location: "header", | |
| 157 | − name: decoded.config.headerName, | |
| 158 | − parts: [ | |
| 159 | − { | |
| 160 | − kind: "literal", | |
| 161 | − value: decoded.config.prefix, | |
| 162 | − }, | |
| 163 | − { | |
| 164 | − kind: "secret_ref", | |
| 165 | − ref: accessTokenRef, | |
| 166 | − }, | |
| 167 | − ], | |
| 168 | − }, | |
| 169 | − ]), | |
| 170 | − expiresAt, | |
| 171 | − refreshAfter, | |
| 172 | − createdAt: input.lease?.createdAt ?? now, | |
| 173 | − updatedAt: now, | |
| 174 | − }; | |
| 175 | − | |
| 176 | − yield* input.executorState.authLeases.upsert(nextLease); | |
| 177 | − yield* cleanupAuthLeaseSecretRefs(input.executorState, { | |
| 178 | − previous: input.lease, | |
| 179 | − next: nextLease, | |
| 180 | − }, input.deleteSecretMaterial); | |
| 181 | − | |
| 182 | − return nextLease; | |
| 183 | − }); | |
| 184 | − | |
| 185 | −const scopeOauthClientSecretRef = (input: { | |
| 186 | − clientSecretProviderId: string | null; | |
| 187 | − clientSecretHandle: string | null; | |
| 188 | −}): SecretRef | null => | |
| 189 | − input.clientSecretProviderId && input.clientSecretHandle | |
| 190 | − ? { | |
| 191 | − providerId: input.clientSecretProviderId, | |
| 192 | − handle: input.clientSecretHandle, | |
| 193 | − } | |
| 194 | − : null; | |
| 195 | − | |
| 196 | −const cleanupProviderGrantRefreshToken = (executorState: ExecutorStateStoreShape, input: { | |
| 197 | − previous: SecretRef; | |
| 198 | − next: SecretRef; | |
| 199 | −}, deleteSecretMaterial: DeleteSecretMaterial) => | |
| 200 | − secretRefKey(input.previous) === secretRefKey(input.next) | |
| 201 | − ? Effect.void | |
| 202 | − : deleteSecretMaterial(input.previous).pipe( | |
| 203 | − Effect.either, | |
| 204 | − Effect.ignore, | |
| 205 | − ); | |
| 206 | − | |
| 207 | −const refreshProviderGrantRefArtifact = (input: { | |
| 208 | − executorState: ExecutorStateStoreShape; | |
| 209 | − artifact: AuthArtifact; | |
| 210 | − lease: AuthLease | null; | |
| 211 | − resolveSecretMaterial: ResolveSecretMaterial; | |
| 212 | − storeSecretMaterial: StoreSecretMaterial; | |
| 213 | − deleteSecretMaterial: DeleteSecretMaterial; | |
| 214 | − context?: SecretMaterialResolveContext; | |
| 215 | −}): Effect.Effect<AuthLease, Error, never> => | |
| 216 | − Effect.gen(function* () { | |
| 217 | − const config = decodeProviderGrantRefAuthArtifactConfig(input.artifact); | |
| 218 | − if (config === null) { | |
| 219 | − return yield* runtimeEffectError("auth/auth-leases", `Unsupported auth artifact kind: ${input.artifact.artifactKind}`); | |
| 220 | − } | |
| 221 | − | |
| 222 | − const grantOption = yield* input.executorState.providerAuthGrants.getById(config.grantId); | |
| 223 | − if (Option.isNone(grantOption)) { | |
| 224 | − return yield* runtimeEffectError("auth/auth-leases", `Provider auth grant not found: ${config.grantId}`); | |
| 225 | − } | |
| 226 | − const grant = grantOption.value; | |
| 227 | − | |
| 228 | − const oauthClientOption = yield* input.executorState.scopeOauthClients.getById(grant.oauthClientId); | |
| 229 | − if (Option.isNone(oauthClientOption)) { | |
| 230 | − return yield* runtimeEffectError("auth/auth-leases", `Scope OAuth client not found: ${grant.oauthClientId}`); | |
| 231 | − } | |
| 232 | − const oauthClient = oauthClientOption.value; | |
| 233 | − | |
| 234 | − const refreshToken = yield* input.resolveSecretMaterial({ | |
| 235 | − ref: grant.refreshToken, | |
| 236 | − context: input.context, | |
| 237 | − }); | |
| 238 | − const clientSecretRef = scopeOauthClientSecretRef(oauthClient); | |
| 239 | − const clientSecret = clientSecretRef | |
| 240 | − ? yield* input.resolveSecretMaterial({ | |
| 241 | − ref: clientSecretRef, | |
| 242 | − context: input.context, | |
| 243 | − }) | |
| 244 | − : null; | |
| 245 | − | |
| 246 | − const tokenResponse = yield* refreshOAuth2AccessToken({ | |
| 247 | − tokenEndpoint: grant.tokenEndpoint, | |
| 248 | − clientId: oauthClient.clientId, | |
| 249 | − clientAuthentication: grant.clientAuthentication, | |
| 250 | − clientSecret, | |
| 251 | − refreshToken, | |
| 252 | − scopes: config.requiredScopes.length > 0 ? config.requiredScopes : null, | |
| 253 | − }); | |
| 254 | − | |
| 255 | − const accessTokenRef = yield* input.storeSecretMaterial({ | |
| 256 | − purpose: "oauth_access_token", | |
| 257 | − value: tokenResponse.access_token, | |
| 258 | − name: `${grant.providerKey} Access Token`, | |
| 259 | − }); | |
| 260 | − | |
| 261 | − const rotatedRefreshTokenRef = tokenResponse.refresh_token | |
| 262 | − ? yield* input.storeSecretMaterial({ | |
| 263 | − purpose: "oauth_refresh_token", | |
| 264 | − value: tokenResponse.refresh_token, | |
| 265 | − name: `${grant.providerKey} Refresh Token`, | |
| 266 | − }) | |
| 267 | − : grant.refreshToken; | |
| 268 | − | |
| 269 | − const now = Date.now(); | |
| 270 | − const nextGrant: ProviderAuthGrant = { | |
| 271 | − ...grant, | |
| 272 | − refreshToken: rotatedRefreshTokenRef, | |
| 273 | − lastRefreshedAt: now, | |
| 274 | − updatedAt: now, | |
| 275 | − }; | |
| 276 | − yield* input.executorState.providerAuthGrants.upsert(nextGrant); | |
| 277 | − yield* cleanupProviderGrantRefreshToken(input.executorState, { | |
| 278 | − previous: grant.refreshToken, | |
| 279 | − next: rotatedRefreshTokenRef, | |
| 280 | − }, input.deleteSecretMaterial); | |
| 281 | − | |
| 282 | − const expiresInMs = | |
| 283 | − typeof tokenResponse.expires_in === "number" && Number.isFinite(tokenResponse.expires_in) | |
| 284 | − ? Math.max(0, tokenResponse.expires_in * 1000) | |
| 285 | − : null; | |
| 286 | − const expiresAt = expiresInMs === null ? null : now + expiresInMs; | |
| 287 | − const refreshAfter = | |
| 288 | − expiresAt === null ? null : Math.max(now, expiresAt - LEASE_REFRESH_SKEW_MS); | |
| 289 | − | |
| 290 | − const nextLease: AuthLease = { | |
| 291 | − id: input.lease?.id ?? AuthLeaseIdSchema.make(`auth_lease_${crypto.randomUUID()}`), | |
| 292 | − authArtifactId: input.artifact.id, | |
| 293 | − scopeId: input.artifact.scopeId, | |
| 294 | − sourceId: input.artifact.sourceId, | |
| 295 | − actorScopeId: input.artifact.actorScopeId, | |
| 296 | − slot: input.artifact.slot, | |
| 297 | − placementsTemplateJson: encodeLeasePlacementTemplatesJson([ | |
| 298 | − { | |
| 299 | − location: "header", | |
| 300 | − name: config.headerName, | |
| 301 | − parts: [ | |
| 302 | − { | |
| 303 | − kind: "literal", | |
| 304 | − value: config.prefix, | |
| 305 | − }, | |
| 306 | − { | |
| 307 | − kind: "secret_ref", | |
| 308 | − ref: accessTokenRef, | |
| 309 | − }, | |
| 310 | − ], | |
| 311 | − }, | |
| 312 | − ]), | |
| 313 | − expiresAt, | |
| 314 | − refreshAfter, | |
| 315 | − createdAt: input.lease?.createdAt ?? now, | |
| 316 | − updatedAt: now, | |
| 317 | − }; | |
| 318 | − | |
| 319 | − yield* input.executorState.authLeases.upsert(nextLease); | |
| 320 | − yield* cleanupAuthLeaseSecretRefs(input.executorState, { | |
| 321 | − previous: input.lease, | |
| 322 | − next: nextLease, | |
| 323 | − }, input.deleteSecretMaterial); | |
| 324 | − | |
| 325 | − return nextLease; | |
| 326 | − }); | |
| 327 | − | |
| 328 | −export const removeAuthLeaseAndSecrets = (executorState: ExecutorStateStoreShape, input: { | |
| 329 | − authArtifactId: AuthArtifact["id"]; | |
| 330 | −}, deleteSecretMaterial: DeleteSecretMaterial): Effect.Effect<void, Error, never> => | |
| 331 | − Effect.gen(function* () { | |
| 332 | − const existingLease = yield* executorState.authLeases.getByAuthArtifactId(input.authArtifactId); | |
| 333 | − if (Option.isNone(existingLease)) { | |
| 334 | − return; | |
| 335 | − } | |
| 336 | − | |
| 337 | − yield* executorState.authLeases.removeByAuthArtifactId(input.authArtifactId); | |
| 338 | − yield* cleanupAuthLeaseSecretRefs(executorState, { | |
| 339 | − previous: existingLease.value, | |
| 340 | − next: null, | |
| 341 | − }, deleteSecretMaterial); | |
| 342 | − }); | |
| 343 | − | |
| 344 | −export const upsertOauth2AuthorizedUserLeaseFromTokenResponse = (input: { | |
| 345 | − executorState: ExecutorStateStoreShape; | |
| 346 | − artifact: AuthArtifact; | |
| 347 | − tokenResponse: OAuth2TokenResponse; | |
| 348 | − storeSecretMaterial: StoreSecretMaterial; | |
| 349 | − deleteSecretMaterial: DeleteSecretMaterial; | |
| 350 | −}): Effect.Effect<void, Error, never> => | |
| 351 | − Effect.gen(function* () { | |
| 352 | − const decoded = decodeBuiltInAuthArtifactConfig(input.artifact); | |
| 353 | − if ( | |
| 354 | − decoded === null | |
| 355 | − || decoded.artifactKind !== RefreshableOAuth2AuthorizedUserAuthArtifactKind | |
| 356 | − ) { | |
| 357 | − return yield* runtimeEffectError("auth/auth-leases", `Unsupported auth artifact kind: ${input.artifact.artifactKind}`); | |
| 358 | − } | |
| 359 | − | |
| 360 | − const existingLeaseOption = yield* input.executorState.authLeases.getByAuthArtifactId(input.artifact.id); | |
| 361 | − const existingLease = Option.isSome(existingLeaseOption) ? existingLeaseOption.value : null; | |
| 362 | − const accessTokenRef = yield* input.storeSecretMaterial({ | |
| 363 | − purpose: "oauth_access_token", | |
| 364 | − value: input.tokenResponse.access_token, | |
| 365 | − name: `${decoded.config.clientId} Access Token`, | |
| 366 | − }); | |
| 367 | − const now = Date.now(); | |
| 368 | − const expiresInMs = | |
| 369 | − typeof input.tokenResponse.expires_in === "number" && Number.isFinite(input.tokenResponse.expires_in) | |
| 370 | − ? Math.max(0, input.tokenResponse.expires_in * 1000) | |
| 371 | − : null; | |
| 372 | − const expiresAt = expiresInMs === null ? null : now + expiresInMs; | |
| 373 | − const refreshAfter = | |
| 374 | − expiresAt === null ? null : Math.max(now, expiresAt - LEASE_REFRESH_SKEW_MS); | |
| 375 | − | |
| 376 | − const nextLease: AuthLease = { | |
| 377 | − id: existingLease?.id ?? AuthLeaseIdSchema.make(`auth_lease_${crypto.randomUUID()}`), | |
| 378 | − authArtifactId: input.artifact.id, | |
| 379 | − scopeId: input.artifact.scopeId, | |
| 380 | − sourceId: input.artifact.sourceId, | |
| 381 | − actorScopeId: input.artifact.actorScopeId, | |
| 382 | − slot: input.artifact.slot, | |
| 383 | − placementsTemplateJson: encodeLeasePlacementTemplatesJson([ | |
| 384 | − { | |
| 385 | − location: "header", | |
| 386 | − name: decoded.config.headerName, | |
| 387 | − parts: [ | |
| 388 | − { | |
| 389 | − kind: "literal", | |
| 390 | − value: decoded.config.prefix, | |
| 391 | − }, | |
| 392 | − { | |
| 393 | − kind: "secret_ref", | |
| 394 | − ref: accessTokenRef, | |
| 395 | − }, | |
| 396 | − ], | |
| 397 | − }, | |
| 398 | − ]), | |
| 399 | − expiresAt, | |
| 400 | − refreshAfter, | |
| 401 | − createdAt: existingLease?.createdAt ?? now, | |
| 402 | − updatedAt: now, | |
| 403 | − }; | |
| 404 | − | |
| 405 | − yield* input.executorState.authLeases.upsert(nextLease); | |
| 406 | − yield* cleanupAuthLeaseSecretRefs(input.executorState, { | |
| 407 | − previous: existingLease, | |
| 408 | − next: nextLease, | |
| 409 | − }, input.deleteSecretMaterial); | |
| 410 | − }); | |
| 411 | − | |
| 412 | −export const resolveAuthArtifactMaterialWithLeases = (input: { | |
| 413 | − executorState: ExecutorStateStoreShape; | |
| 414 | − artifact: AuthArtifact | null; | |
| 415 | − resolveSecretMaterial: ResolveSecretMaterial; | |
| 416 | − storeSecretMaterial: StoreSecretMaterial; | |
| 417 | − deleteSecretMaterial: DeleteSecretMaterial; | |
| 418 | − context?: SecretMaterialResolveContext; | |
| 419 | −}): Effect.Effect<ResolvedSourceAuthMaterial, Error, never> => | |
| 420 | − Effect.gen(function* () { | |
| 421 | − if (input.artifact === null) { | |
| 422 | − return yield* resolveAuthArtifactMaterial({ | |
| 423 | − artifact: null, | |
| 424 | − resolveSecretMaterial: input.resolveSecretMaterial, | |
| 425 | − context: input.context, | |
| 426 | − }); | |
| 427 | − } | |
| 428 | − | |
| 429 | − const existingLeaseOption = yield* input.executorState.authLeases.getByAuthArtifactId(input.artifact.id); | |
| 430 | − const existingLease = Option.isSome(existingLeaseOption) ? existingLeaseOption.value : null; | |
| 431 | − const decoded = decodeBuiltInAuthArtifactConfig(input.artifact); | |
| 432 | − const providerGrantConfig = decodeProviderGrantRefAuthArtifactConfig(input.artifact); | |
| 433 | − const mcpOAuthConfig = decodeMcpOAuthAuthArtifactConfig(input.artifact); | |
| 434 | − | |
| 435 | − if ( | |
| 436 | − decoded !== null | |
| 437 | − && decoded.artifactKind === RefreshableOAuth2AuthorizedUserAuthArtifactKind | |
| 438 | − ) { | |
| 439 | − const lease = leaseIsFresh(existingLease, Date.now()) | |
| 440 | − ? existingLease | |
| 441 | − : yield* refreshRefreshableOauth2AuthorizedUserArtifact({ | |
| 442 | − executorState: input.executorState, | |
| 443 | − artifact: input.artifact, | |
| 444 | − lease: existingLease, | |
| 445 | − resolveSecretMaterial: input.resolveSecretMaterial, | |
| 446 | − storeSecretMaterial: input.storeSecretMaterial, | |
| 447 | − deleteSecretMaterial: input.deleteSecretMaterial, | |
| 448 | − context: input.context, | |
| 449 | − }); | |
| 450 | − | |
| 451 | − return yield* resolveAuthArtifactMaterial({ | |
| 452 | − artifact: input.artifact, | |
| 453 | − lease, | |
| 454 | − resolveSecretMaterial: input.resolveSecretMaterial, | |
| 455 | − context: input.context, | |
| 456 | − }); | |
| 457 | − } | |
| 458 | − | |
| 459 | − if (providerGrantConfig !== null) { | |
| 460 | − const lease = leaseIsFresh(existingLease, Date.now()) | |
| 461 | − ? existingLease | |
| 462 | − : yield* refreshProviderGrantRefArtifact({ | |
| 463 | − executorState: input.executorState, | |
| 464 | − artifact: input.artifact, | |
| 465 | − lease: existingLease, | |
| 466 | − resolveSecretMaterial: input.resolveSecretMaterial, | |
| 467 | − storeSecretMaterial: input.storeSecretMaterial, | |
| 468 | − deleteSecretMaterial: input.deleteSecretMaterial, | |
| 469 | − context: input.context, | |
| 470 | − }); | |
| 471 | − | |
| 472 | − return yield* resolveAuthArtifactMaterial({ | |
| 473 | − artifact: input.artifact, | |
| 474 | − lease, | |
| 475 | − resolveSecretMaterial: input.resolveSecretMaterial, | |
| 476 | − context: input.context, | |
| 477 | − }); | |
| 478 | − } | |
| 479 | − | |
| 480 | − if (mcpOAuthConfig !== null) { | |
| 481 | − const material = yield* resolveAuthArtifactMaterial({ | |
| 482 | − artifact: input.artifact, | |
| 483 | − resolveSecretMaterial: input.resolveSecretMaterial, | |
| 484 | − context: input.context, | |
| 485 | − }); | |
| 486 | − | |
| 487 | − return { | |
| 488 | − ...material, | |
| 489 | − authProvider: createPersistedMcpAuthProvider({ | |
| 490 | − executorState: input.executorState, | |
| 491 | − artifact: input.artifact, | |
| 492 | − config: mcpOAuthConfig, | |
| 493 | − resolveSecretMaterial: input.resolveSecretMaterial, | |
| 494 | − storeSecretMaterial: input.storeSecretMaterial, | |
| 495 | − deleteSecretMaterial: input.deleteSecretMaterial, | |
| 496 | − context: input.context, | |
| 497 | − }), | |
| 498 | − }; | |
| 499 | − } | |
| 500 | − | |
| 501 | − return yield* resolveAuthArtifactMaterial({ | |
| 502 | − artifact: input.artifact, | |
| 503 | − lease: existingLease, | |
| 504 | − resolveSecretMaterial: input.resolveSecretMaterial, | |
| 505 | − context: input.context, | |
| 506 | − }); | |
| 507 | − }); | |
| @@ -1,262 +0,0 @@ | ||
| 1 | −import type { | |
| 2 | − OAuthClientInformationMixed, | |
| 3 | − OAuthTokens, | |
| 4 | −} from "@modelcontextprotocol/sdk/shared/auth.js"; | |
| 5 | −import type { | |
| 6 | − OAuthClientMetadata, | |
| 7 | −} from "@modelcontextprotocol/sdk/shared/auth.js"; | |
| 8 | −import type { | |
| 9 | − OAuthClientProvider, | |
| 10 | − OAuthDiscoveryState, | |
| 11 | −} from "@modelcontextprotocol/sdk/client/auth.js"; | |
| 12 | −import type { | |
| 13 | − AuthArtifact, | |
| 14 | − McpOAuthAuthArtifactConfig, | |
| 15 | − SecretRef, | |
| 16 | −} from "#schema"; | |
| 17 | −import { | |
| 18 | − McpOAuthAuthArtifactConfigJsonSchema, | |
| 19 | −} from "#schema"; | |
| 20 | −import * as Effect from "effect/Effect"; | |
| 21 | −import * as Schema from "effect/Schema"; | |
| 22 | − | |
| 23 | −import type { | |
| 24 | − ExecutorStateStoreShape, | |
| 25 | −} from "../executor-state-store"; | |
| 26 | −import { | |
| 27 | − type DeleteSecretMaterial, | |
| 28 | − type ResolveSecretMaterial, | |
| 29 | − type SecretMaterialResolveContext, | |
| 30 | − type StoreSecretMaterial, | |
| 31 | −} from "../scope/secret-material-providers"; | |
| 32 | − | |
| 33 | −const encodeMcpOAuthAuthArtifactConfig = Schema.encodeSync( | |
| 34 | − McpOAuthAuthArtifactConfigJsonSchema, | |
| 35 | −); | |
| 36 | − | |
| 37 | −const parseJsonObject = <T>(value: string | null): T | undefined => { | |
| 38 | − if (value === null) { | |
| 39 | − return undefined; | |
| 40 | − } | |
| 41 | − | |
| 42 | − try { | |
| 43 | − const parsed = JSON.parse(value) as unknown; | |
| 44 | − return parsed !== null && typeof parsed === "object" && !Array.isArray(parsed) | |
| 45 | − ? parsed as T | |
| 46 | − : undefined; | |
| 47 | − } catch { | |
| 48 | − return undefined; | |
| 49 | − } | |
| 50 | −}; | |
| 51 | − | |
| 52 | −const stringifyJsonObject = (value: unknown): string | null => | |
| 53 | − value === null || value === undefined ? null : JSON.stringify(value); | |
| 54 | − | |
| 55 | −const createClientMetadata = (redirectUrl: string): OAuthClientMetadata => ({ | |
| 56 | − redirect_uris: [redirectUrl], | |
| 57 | − grant_types: ["authorization_code", "refresh_token"], | |
| 58 | − response_types: ["code"], | |
| 59 | − token_endpoint_auth_method: "none", | |
| 60 | − client_name: "Executor Local", | |
| 61 | −}); | |
| 62 | − | |
| 63 | −const secretRefEquals = (left: SecretRef | null, right: SecretRef | null): boolean => | |
| 64 | − (left?.providerId ?? null) === (right?.providerId ?? null) | |
| 65 | − && (left?.handle ?? null) === (right?.handle ?? null); | |
| 66 | − | |
| 67 | −const cleanupReplacedSecretRefs = (input: { | |
| 68 | − deleteSecretMaterial: DeleteSecretMaterial; | |
| 69 | − previousAccessToken: SecretRef; | |
| 70 | − nextAccessToken: SecretRef; | |
| 71 | − previousRefreshToken: SecretRef | null; | |
| 72 | − nextRefreshToken: SecretRef | null; | |
| 73 | −}) => | |
| 74 | − Effect.gen(function* () { | |
| 75 | − if (!secretRefEquals(input.previousAccessToken, input.nextAccessToken)) { | |
| 76 | − yield* Effect.either(input.deleteSecretMaterial(input.previousAccessToken)); | |
| 77 | − } | |
| 78 | − | |
| 79 | − if ( | |
| 80 | − input.previousRefreshToken !== null | |
| 81 | − && !secretRefEquals(input.previousRefreshToken, input.nextRefreshToken) | |
| 82 | − ) { | |
| 83 | − yield* Effect.either(input.deleteSecretMaterial(input.previousRefreshToken)); | |
| 84 | − } | |
| 85 | − }); | |
| 86 | − | |
| 87 | −export const createPersistedMcpOAuthSourceAuth = (input: { | |
| 88 | − redirectUri: string; | |
| 89 | − accessToken: SecretRef; | |
| 90 | − refreshToken: SecretRef | null; | |
| 91 | − tokenType: string; | |
| 92 | − expiresIn: number | null; | |
| 93 | − scope: string | null; | |
| 94 | − resourceMetadataUrl: string | null; | |
| 95 | − authorizationServerUrl: string | null; | |
| 96 | − resourceMetadata: unknown; | |
| 97 | − authorizationServerMetadata: unknown; | |
| 98 | − clientInformation: unknown; | |
| 99 | −}) => ({ | |
| 100 | − kind: "mcp_oauth" as const, | |
| 101 | − redirectUri: input.redirectUri, | |
| 102 | − accessToken: input.accessToken, | |
| 103 | − refreshToken: input.refreshToken, | |
| 104 | − tokenType: input.tokenType, | |
| 105 | − expiresIn: input.expiresIn, | |
| 106 | − scope: input.scope, | |
| 107 | − resourceMetadataUrl: input.resourceMetadataUrl, | |
| 108 | − authorizationServerUrl: input.authorizationServerUrl, | |
| 109 | − resourceMetadataJson: stringifyJsonObject(input.resourceMetadata), | |
| 110 | − authorizationServerMetadataJson: stringifyJsonObject(input.authorizationServerMetadata), | |
| 111 | − clientInformationJson: stringifyJsonObject(input.clientInformation), | |
| 112 | −}); | |
| 113 | − | |
| 114 | −export const createPersistedMcpAuthProvider = (input: { | |
| 115 | − executorState: ExecutorStateStoreShape; | |
| 116 | − artifact: AuthArtifact; | |
| 117 | − config: McpOAuthAuthArtifactConfig; | |
| 118 | − resolveSecretMaterial: ResolveSecretMaterial; | |
| 119 | − storeSecretMaterial: StoreSecretMaterial; | |
| 120 | − deleteSecretMaterial: DeleteSecretMaterial; | |
| 121 | − context?: SecretMaterialResolveContext; | |
| 122 | −}): OAuthClientProvider => { | |
| 123 | − let currentArtifact = input.artifact; | |
| 124 | − let currentConfig = input.config; | |
| 125 | − | |
| 126 | − const persistConfig = (nextConfig: McpOAuthAuthArtifactConfig) => | |
| 127 | − Effect.gen(function* () { | |
| 128 | − const nextArtifact: AuthArtifact = { | |
| 129 | − ...currentArtifact, | |
| 130 | − configJson: encodeMcpOAuthAuthArtifactConfig(nextConfig), | |
| 131 | − updatedAt: Date.now(), | |
| 132 | − }; | |
| 133 | − yield* input.executorState.authArtifacts.upsert(nextArtifact); | |
| 134 | − currentArtifact = nextArtifact; | |
| 135 | − currentConfig = nextConfig; | |
| 136 | − }); | |
| 137 | − | |
| 138 | − return { | |
| 139 | − get redirectUrl() { | |
| 140 | − return currentConfig.redirectUri; | |
| 141 | − }, | |
| 142 | − | |
| 143 | − get clientMetadata() { | |
| 144 | − return createClientMetadata(currentConfig.redirectUri); | |
| 145 | − }, | |
| 146 | − | |
| 147 | − clientInformation: () => | |
| 148 | − parseJsonObject<OAuthClientInformationMixed>(currentConfig.clientInformationJson), | |
| 149 | − | |
| 150 | − saveClientInformation: (clientInformation) => | |
| 151 | − Effect.runPromise( | |
| 152 | − persistConfig({ | |
| 153 | − ...currentConfig, | |
| 154 | − clientInformationJson: stringifyJsonObject(clientInformation), | |
| 155 | − }), | |
| 156 | − ).then(() => undefined), | |
| 157 | − | |
| 158 | − tokens: async () => { | |
| 159 | − const accessToken = await Effect.runPromise( | |
| 160 | − input.resolveSecretMaterial({ | |
| 161 | − ref: currentConfig.accessToken, | |
| 162 | − context: input.context, | |
| 163 | − }), | |
| 164 | − ); | |
| 165 | − const refreshToken = currentConfig.refreshToken | |
| 166 | − ? await Effect.runPromise( | |
| 167 | − input.resolveSecretMaterial({ | |
| 168 | − ref: currentConfig.refreshToken, | |
| 169 | − context: input.context, | |
| 170 | − }), | |
| 171 | − ) | |
| 172 | − : undefined; | |
| 173 | − | |
| 174 | − return { | |
| 175 | − access_token: accessToken, | |
| 176 | − token_type: currentConfig.tokenType, | |
| 177 | − ...(typeof currentConfig.expiresIn === "number" | |
| 178 | − ? { expires_in: currentConfig.expiresIn } | |
| 179 | − : {}), | |
| 180 | − ...(currentConfig.scope ? { scope: currentConfig.scope } : {}), | |
| 181 | − ...(refreshToken ? { refresh_token: refreshToken } : {}), | |
| 182 | − } satisfies OAuthTokens; | |
| 183 | − }, | |
| 184 | − | |
| 185 | − saveTokens: (tokens) => | |
| 186 | − Effect.runPromise(Effect.gen(function* () { | |
| 187 | − const previousConfig = currentConfig; | |
| 188 | − const accessTokenRef = yield* input.storeSecretMaterial({ | |
| 189 | − purpose: "oauth_access_token", | |
| 190 | − value: tokens.access_token, | |
| 191 | − name: `${currentArtifact.sourceId} MCP Access Token`, | |
| 192 | − }); | |
| 193 | − const refreshTokenRef = tokens.refresh_token | |
| 194 | − ? yield* input.storeSecretMaterial({ | |
| 195 | − purpose: "oauth_refresh_token", | |
| 196 | − value: tokens.refresh_token, | |
| 197 | − name: `${currentArtifact.sourceId} MCP Refresh Token`, | |
| 198 | − }) | |
| 199 | − : currentConfig.refreshToken; | |
| 200 | − | |
| 201 | − const nextConfig: McpOAuthAuthArtifactConfig = { | |
| 202 | − ...currentConfig, | |
| 203 | − accessToken: accessTokenRef, | |
| 204 | − refreshToken: refreshTokenRef, | |
| 205 | − tokenType: tokens.token_type ?? currentConfig.tokenType, | |
| 206 | − expiresIn: | |
| 207 | − typeof tokens.expires_in === "number" && Number.isFinite(tokens.expires_in) | |
| 208 | − ? tokens.expires_in | |
| 209 | − : currentConfig.expiresIn, | |
| 210 | − scope: tokens.scope ?? currentConfig.scope, | |
| 211 | − }; | |
| 212 | − | |
| 213 | − yield* persistConfig(nextConfig); | |
| 214 | − yield* cleanupReplacedSecretRefs({ | |
| 215 | − deleteSecretMaterial: input.deleteSecretMaterial, | |
| 216 | − previousAccessToken: previousConfig.accessToken, | |
| 217 | − nextAccessToken: accessTokenRef, | |
| 218 | − previousRefreshToken: previousConfig.refreshToken, | |
| 219 | − nextRefreshToken: refreshTokenRef, | |
| 220 | − }); | |
| 221 | − })).then(() => undefined), | |
| 222 | − | |
| 223 | − redirectToAuthorization: async (authorizationUrl) => { | |
| 224 | − throw new Error( | |
| 225 | − `MCP OAuth re-authorization is required for ${currentArtifact.sourceId}: ${authorizationUrl.toString()}`, | |
| 226 | − ); | |
| 227 | − }, | |
| 228 | − | |
| 229 | − saveCodeVerifier: () => undefined, | |
| 230 | − | |
| 231 | − codeVerifier: () => { | |
| 232 | − throw new Error("Persisted MCP OAuth sessions do not retain an active PKCE verifier"); | |
| 233 | − }, | |
| 234 | − | |
| 235 | − saveDiscoveryState: (state) => | |
| 236 | − Effect.runPromise( | |
| 237 | − persistConfig({ | |
| 238 | − ...currentConfig, | |
| 239 | − resourceMetadataUrl: state.resourceMetadataUrl ?? null, | |
| 240 | − authorizationServerUrl: state.authorizationServerUrl ?? null, | |
| 241 | − resourceMetadataJson: stringifyJsonObject(state.resourceMetadata), | |
| 242 | − authorizationServerMetadataJson: stringifyJsonObject( | |
| 243 | − state.authorizationServerMetadata, | |
| 244 | − ), | |
| 245 | − }), | |
| 246 | − ).then(() => undefined), | |
| 247 | − | |
| 248 | − discoveryState: () => | |
| 249 | − currentConfig.authorizationServerUrl === null | |
| 250 | − ? undefined | |
| 251 | − : { | |
| 252 | − resourceMetadataUrl: currentConfig.resourceMetadataUrl ?? undefined, | |
| 253 | − authorizationServerUrl: currentConfig.authorizationServerUrl, | |
| 254 | − resourceMetadata: parseJsonObject<OAuthDiscoveryState["resourceMetadata"]>( | |
| 255 | − currentConfig.resourceMetadataJson, | |
| 256 | − ), | |
| 257 | − authorizationServerMetadata: parseJsonObject< | |
| 258 | − OAuthDiscoveryState["authorizationServerMetadata"] | |
| 259 | − >(currentConfig.authorizationServerMetadataJson), | |
| 260 | − }, | |
| 261 | − }; | |
| 262 | −}; | |
| @@ -1,94 +0,0 @@ | ||
| 1 | −import type { | |
| 2 | − AuthArtifact, | |
| 3 | − ProviderAuthGrant, | |
| 4 | − ScopeId, | |
| 5 | −} from "#schema"; | |
| 6 | −import { | |
| 7 | − decodeProviderGrantRefAuthArtifactConfig, | |
| 8 | −} from "#schema"; | |
| 9 | −import * as Effect from "effect/Effect"; | |
| 10 | −import * as Option from "effect/Option"; | |
| 11 | − | |
| 12 | −import { | |
| 13 | − type DeleteSecretMaterial, | |
| 14 | −} from "../scope/secret-material-providers"; | |
| 15 | −import type { | |
| 16 | − ExecutorStateStoreShape, | |
| 17 | −} from "../executor-state-store"; | |
| 18 | − | |
| 19 | −const providerGrantRefFromArtifact = ( | |
| 20 | − artifact: Pick<AuthArtifact, "artifactKind" | "configJson">, | |
| 21 | −) => decodeProviderGrantRefAuthArtifactConfig(artifact); | |
| 22 | − | |
| 23 | −export const providerGrantIdFromArtifact = ( | |
| 24 | − artifact: Pick<AuthArtifact, "artifactKind" | "configJson">, | |
| 25 | −): ProviderAuthGrant["id"] | null => | |
| 26 | − providerGrantRefFromArtifact(artifact)?.grantId ?? null; | |
| 27 | − | |
| 28 | −export const listProviderGrantRefArtifacts = (executorState: ExecutorStateStoreShape, input: { | |
| 29 | − scopeId: ScopeId; | |
| 30 | − grantId?: ProviderAuthGrant["id"] | null; | |
| 31 | −}): Effect.Effect<readonly AuthArtifact[], Error, never> => | |
| 32 | − Effect.map( | |
| 33 | − executorState.authArtifacts.listByScopeId(input.scopeId), | |
| 34 | − (artifacts) => | |
| 35 | − artifacts.filter((artifact) => { | |
| 36 | − const grantId = providerGrantIdFromArtifact(artifact); | |
| 37 | − return grantId !== null && (input.grantId == null || grantId === input.grantId); | |
| 38 | − }), | |
| 39 | − ); | |
| 40 | − | |
| 41 | −export const clearProviderGrantOrphanedAt = (executorState: ExecutorStateStoreShape, input: { | |
| 42 | − grantId: ProviderAuthGrant["id"]; | |
| 43 | −}): Effect.Effect<boolean, Error, never> => | |
| 44 | − Effect.gen(function* () { | |
| 45 | − const grantOption = yield* executorState.providerAuthGrants.getById(input.grantId); | |
| 46 | − if (Option.isNone(grantOption) || grantOption.value.orphanedAt === null) { | |
| 47 | − return false; | |
| 48 | − } | |
| 49 | − | |
| 50 | − yield* executorState.providerAuthGrants.upsert({ | |
| 51 | − ...grantOption.value, | |
| 52 | − orphanedAt: null, | |
| 53 | − updatedAt: Date.now(), | |
| 54 | − }); | |
| 55 | − return true; | |
| 56 | − }); | |
| 57 | − | |
| 58 | −export const markProviderGrantOrphanedIfUnused = (executorState: ExecutorStateStoreShape, input: { | |
| 59 | − scopeId: ScopeId; | |
| 60 | − grantId: ProviderAuthGrant["id"]; | |
| 61 | −}): Effect.Effect<boolean, Error, never> => | |
| 62 | − Effect.gen(function* () { | |
| 63 | − const references = yield* listProviderGrantRefArtifacts(executorState, input); | |
| 64 | − if (references.length > 0) { | |
| 65 | − return false; | |
| 66 | − } | |
| 67 | − | |
| 68 | − const grantOption = yield* executorState.providerAuthGrants.getById(input.grantId); | |
| 69 | − if (Option.isNone(grantOption) || grantOption.value.scopeId !== input.scopeId) { | |
| 70 | − return false; | |
| 71 | − } | |
| 72 | − | |
| 73 | − const grant = grantOption.value; | |
| 74 | − if (grant.orphanedAt !== null) { | |
| 75 | − return false; | |
| 76 | − } | |
| 77 | − | |
| 78 | − yield* executorState.providerAuthGrants.upsert({ | |
| 79 | − ...grant, | |
| 80 | − orphanedAt: Date.now(), | |
| 81 | − updatedAt: Date.now(), | |
| 82 | − }); | |
| 83 | − return true; | |
| 84 | − }); | |
| 85 | − | |
| 86 | −export const removeProviderAuthGrantSecret = (_executorState: ExecutorStateStoreShape, input: { | |
| 87 | − grant: ProviderAuthGrant; | |
| 88 | −}, deleteSecretMaterial: DeleteSecretMaterial): Effect.Effect<void, Error, never> => | |
| 89 | − Effect.gen(function* () { | |
| 90 | − yield* deleteSecretMaterial(input.grant.refreshToken).pipe( | |
| 91 | − Effect.either, | |
| 92 | − Effect.ignore, | |
| 93 | − ); | |
| 94 | − }); | |
| @@ -1,176 +0,0 @@ | ||
| 1 | −import type { | |
| 2 | − ScopeId, | |
| 3 | − CredentialSlot, | |
| 4 | − Source, | |
| 5 | − SourceAuth, | |
| 6 | −} from "#schema"; | |
| 7 | −import * as Context from "effect/Context"; | |
| 8 | −import * as Effect from "effect/Effect"; | |
| 9 | −import * as Layer from "effect/Layer"; | |
| 10 | −import * as Option from "effect/Option"; | |
| 11 | − | |
| 12 | −import { | |
| 13 | − ExecutorStateStore, | |
| 14 | − type ExecutorStateStoreShape, | |
| 15 | −} from "../executor-state-store"; | |
| 16 | −import { | |
| 17 | − authArtifactFromSourceAuth, | |
| 18 | − resolveAuthArtifactMaterial, | |
| 19 | − type ResolvedSourceAuthMaterial, | |
| 20 | −} from "./auth-artifacts"; | |
| 21 | −import { | |
| 22 | − resolveAuthArtifactMaterialWithLeases, | |
| 23 | −} from "./auth-leases"; | |
| 24 | −import type { | |
| 25 | − DeleteSecretMaterial, | |
| 26 | − ResolveSecretMaterial, | |
| 27 | − SecretMaterialResolveContext, | |
| 28 | − StoreSecretMaterial, | |
| 29 | −} from "../scope/secret-material-providers"; | |
| 30 | −import { | |
| 31 | − SecretMaterialDeleterService, | |
| 32 | − SecretMaterialResolverService, | |
| 33 | − SecretMaterialStorerService, | |
| 34 | −} from "../scope/secret-material-providers"; | |
| 35 | −import { | |
| 36 | − runtimeEffectError, | |
| 37 | −} from "../effect-errors"; | |
| 38 | − | |
| 39 | −const authForSlot = (input: { | |
| 40 | − source: Source; | |
| 41 | − slot: CredentialSlot; | |
| 42 | −}): SourceAuth => { | |
| 43 | − if (input.slot === "runtime") { | |
| 44 | − return input.source.auth; | |
| 45 | − } | |
| 46 | − | |
| 47 | − if (input.source.importAuthPolicy === "reuse_runtime") { | |
| 48 | − return input.source.auth; | |
| 49 | − } | |
| 50 | − | |
| 51 | − if (input.source.importAuthPolicy === "none") { | |
| 52 | − return { kind: "none" }; | |
| 53 | − } | |
| 54 | − | |
| 55 | − return input.source.importAuth; | |
| 56 | −}; | |
| 57 | − | |
| 58 | −export type RuntimeSourceAuthMaterialShape = { | |
| 59 | − resolve: (input: { | |
| 60 | − source: Source; | |
| 61 | − slot?: CredentialSlot; | |
| 62 | − actorScopeId?: ScopeId | null; | |
| 63 | − context?: SecretMaterialResolveContext; | |
| 64 | − }) => Effect.Effect<ResolvedSourceAuthMaterial, Error, never>; | |
| 65 | −}; | |
| 66 | − | |
| 67 | −export class RuntimeSourceAuthMaterialService extends Context.Tag( | |
| 68 | − "#runtime/RuntimeSourceAuthMaterialService", | |
| 69 | −)<RuntimeSourceAuthMaterialService, RuntimeSourceAuthMaterialShape>() {} | |
| 70 | − | |
| 71 | −export const resolveSourceAuthMaterialWithDeps = (input: { | |
| 72 | − source: Source; | |
| 73 | − slot?: CredentialSlot; | |
| 74 | − actorScopeId?: ScopeId | null; | |
| 75 | − executorState?: ExecutorStateStoreShape; | |
| 76 | − resolveSecretMaterial: ResolveSecretMaterial; | |
| 77 | − storeSecretMaterial?: StoreSecretMaterial; | |
| 78 | − deleteSecretMaterial?: DeleteSecretMaterial; | |
| 79 | − context?: SecretMaterialResolveContext; | |
| 80 | −}): Effect.Effect<ResolvedSourceAuthMaterial, Error, never> => | |
| 81 | − Effect.gen(function* () { | |
| 82 | − const slot = input.slot ?? "runtime"; | |
| 83 | − | |
| 84 | − if (input.executorState !== undefined) { | |
| 85 | − const candidateSlots = | |
| 86 | − slot === "import" && input.source.importAuthPolicy === "reuse_runtime" | |
| 87 | − ? ["import", "runtime"] satisfies ReadonlyArray<CredentialSlot> | |
| 88 | − : [slot] satisfies ReadonlyArray<CredentialSlot>; | |
| 89 | − | |
| 90 | − for (const candidateSlot of candidateSlots) { | |
| 91 | − const artifactOption = yield* input.executorState.authArtifacts.getByScopeSourceAndActor({ | |
| 92 | − scopeId: input.source.scopeId, | |
| 93 | − sourceId: input.source.id, | |
| 94 | − actorScopeId: input.actorScopeId ?? null, | |
| 95 | − slot: candidateSlot, | |
| 96 | − }); | |
| 97 | − | |
| 98 | − if (Option.isSome(artifactOption)) { | |
| 99 | − return yield* resolveAuthArtifactMaterialWithLeases({ | |
| 100 | − executorState: input.executorState, | |
| 101 | − artifact: artifactOption.value, | |
| 102 | − resolveSecretMaterial: input.resolveSecretMaterial, | |
| 103 | − storeSecretMaterial: input.storeSecretMaterial ?? (() => Effect.dieMessage("storeSecretMaterial unavailable")), | |
| 104 | − deleteSecretMaterial: input.deleteSecretMaterial ?? (() => Effect.dieMessage("deleteSecretMaterial unavailable")), | |
| 105 | − context: input.context, | |
| 106 | − }); | |
| 107 | − } | |
| 108 | − } | |
| 109 | − } | |
| 110 | − | |
| 111 | − const artifact = authArtifactFromSourceAuth({ | |
| 112 | − source: input.source, | |
| 113 | − auth: authForSlot({ | |
| 114 | − source: input.source, | |
| 115 | − slot, | |
| 116 | − }), | |
| 117 | − slot, | |
| 118 | − actorScopeId: input.actorScopeId ?? null, | |
| 119 | − }); | |
| 120 | − | |
| 121 | − if (input.executorState !== undefined) { | |
| 122 | − return yield* resolveAuthArtifactMaterialWithLeases({ | |
| 123 | − executorState: input.executorState, | |
| 124 | − artifact, | |
| 125 | − resolveSecretMaterial: input.resolveSecretMaterial, | |
| 126 | − storeSecretMaterial: input.storeSecretMaterial ?? (() => Effect.dieMessage("storeSecretMaterial unavailable")), | |
| 127 | − deleteSecretMaterial: input.deleteSecretMaterial ?? (() => Effect.dieMessage("deleteSecretMaterial unavailable")), | |
| 128 | − context: input.context, | |
| 129 | − }); | |
| 130 | − } | |
| 131 | − | |
| 132 | − if ( | |
| 133 | − artifact?.artifactKind === "oauth2_authorized_user" | |
| 134 | − || artifact?.artifactKind === "provider_grant_ref" | |
| 135 | − || artifact?.artifactKind === "mcp_oauth" | |
| 136 | − ) { | |
| 137 | − return yield* runtimeEffectError("auth/source-auth-material", "Dynamic auth artifacts require persistence-backed lease resolution"); | |
| 138 | − } | |
| 139 | − | |
| 140 | − return yield* resolveAuthArtifactMaterial({ | |
| 141 | − artifact, | |
| 142 | − resolveSecretMaterial: input.resolveSecretMaterial, | |
| 143 | − context: input.context, | |
| 144 | − }); | |
| 145 | − }); | |
| 146 | − | |
| 147 | −export const resolveSourceAuthMaterial = (input: { | |
| 148 | − source: Source; | |
| 149 | − slot?: CredentialSlot; | |
| 150 | − actorScopeId?: ScopeId | null; | |
| 151 | − context?: SecretMaterialResolveContext; | |
| 152 | −}): Effect.Effect<ResolvedSourceAuthMaterial, Error, RuntimeSourceAuthMaterialService> => | |
| 153 | − Effect.flatMap(RuntimeSourceAuthMaterialService, (service) => service.resolve(input)); | |
| 154 | − | |
| 155 | −export const RuntimeSourceAuthMaterialLive = Layer.effect( | |
| 156 | − RuntimeSourceAuthMaterialService, | |
| 157 | − Effect.gen(function* () { | |
| 158 | − const executorState = yield* ExecutorStateStore; | |
| 159 | − const resolveSecretMaterial = yield* SecretMaterialResolverService; | |
| 160 | − const storeSecretMaterial = yield* SecretMaterialStorerService; | |
| 161 | − const deleteSecretMaterial = yield* SecretMaterialDeleterService; | |
| 162 | − | |
| 163 | − return RuntimeSourceAuthMaterialService.of({ | |
| 164 | − resolve: (input) => | |
| 165 | − resolveSourceAuthMaterialWithDeps({ | |
| 166 | − ...input, | |
| 167 | − executorState, | |
| 168 | − resolveSecretMaterial, | |
| 169 | − storeSecretMaterial, | |
| 170 | − deleteSecretMaterial, | |
| 171 | − }), | |
| 172 | − }); | |
| 173 | − }), | |
| 174 | −); | |
| 175 | − | |
| 176 | −export type { ResolvedSourceAuthMaterial } from "./auth-artifacts"; | |
| @@ -11,8 +11,8 @@ import { · 10 unmodified lines | ||
| 11 | 11 | SourceArtifactStore, |
| 12 | 12 | } from "../../scope/storage"; |
| 13 | 13 | import { |
| 14 | − getSourceAdapterForSource, | |
| 15 | −} from "../../sources/source-adapters"; | |
| 14 | + getSourcePluginForSource, | |
| 15 | +} from "../../sources/source-plugins"; | |
| 16 | 16 | import { |
| 17 | 17 | RuntimeSourceStoreService, |
| 18 | 18 | } from "../../sources/source-store"; |
| @@ -23,7 +23,7 @@ import { · 4 unmodified lines | ||
| 23 | 23 | const shouldReconcileSource = (source: Source): boolean => |
| 24 | 24 | source.enabled |
| 25 | 25 | && source.status === "connected" |
| 26 | − && getSourceAdapterForSource(source).catalogKind !== "internal"; | |
| 26 | + && getSourcePluginForSource(source).catalogKind !== "internal"; | |
| 27 | 27 | |
| 28 | 28 | export const reconcileMissingSourceCatalogArtifacts = (input: { |
| 29 | 29 | scopeId: ScopeId; |
| @@ -597,11 +597,11 @@ const codemodeDescriptorFromCapability = (input: { · 596 unmodified lines | ||
| 597 | 597 | ...(inputSchema !== undefined ? { inputSchema } : {}), |
| 598 | 598 | ...(outputSchema !== undefined ? { outputSchema } : {}), |
| 599 | 599 | }, |
| 600 | − providerKind: input.executable.adapterKey, | |
| 601 | − providerData: { | |
| 600 | + pluginKind: input.executable.pluginKey, | |
| 601 | + pluginData: { | |
| 602 | 602 | capabilityId: input.capability.id, |
| 603 | 603 | executableId: input.executable.id, |
| 604 | − adapterKey: input.executable.adapterKey, | |
| 604 | + pluginKey: input.executable.pluginKey, | |
| 605 | 605 | display: input.executable.display, |
| 606 | 606 | }, |
| 607 | 607 | }; |
| @@ -679,8 +679,6 @@ const sourceRecordFromCatalogArtifact = (input: { · 71 unmodified lines | ||
| 679 | 679 | status: input.source.status, |
| 680 | 680 | enabled: input.source.enabled, |
| 681 | 681 | namespace: input.source.namespace, |
| 682 | − importAuthPolicy: input.source.importAuthPolicy, | |
| 683 | − bindingConfigJson: JSON.stringify(input.source.binding), | |
| 684 | 682 | sourceHash: input.source.sourceHash, |
| 685 | 683 | lastError: input.source.lastError, |
| 686 | 684 | createdAt: input.source.createdAt, |
| @@ -21,14 +21,8 @@ import { · 20 unmodified lines | ||
| 21 | 21 | type LocalScopeState, |
| 22 | 22 | } from "../../scope-state"; |
| 23 | 23 | import { |
| 24 | − RuntimeSourceAuthMaterialService, | |
| 25 | −} from "../../auth/source-auth-material"; | |
| 26 | −import { | |
| 27 | − getSourceAdapterForSource, | |
| 28 | −} from "../../sources/source-adapters"; | |
| 29 | −import { | |
| 30 | − SecretMaterialResolverService, | |
| 31 | −} from "../../scope/secret-material-providers"; | |
| 24 | + getSourcePluginForSource, | |
| 25 | +} from "../../sources/source-plugins"; | |
| 32 | 26 | import { |
| 33 | 27 | snapshotFromSourceCatalogSyncResult, |
| 34 | 28 | } from "@executor/source-core"; |
| @@ -43,24 +37,20 @@ import { · 8 unmodified lines | ||
| 43 | 37 | const shouldIndexSource = (source: Source): boolean => |
| 44 | 38 | source.enabled |
| 45 | 39 | && source.status === "connected" |
| 46 | − && getSourceAdapterForSource(source).catalogKind !== "internal"; | |
| 40 | + && getSourcePluginForSource(source).catalogKind !== "internal"; | |
| 47 | 41 | |
| 48 | 42 | type RuntimeSourceCatalogSyncDeps = { |
| 49 | 43 | runtimeLocalScope: RuntimeLocalScopeState; |
| 50 | 44 | scopeStateStore: ScopeStateStoreShape; |
| 51 | 45 | sourceArtifactStore: SourceArtifactStoreShape; |
| 52 | 46 | sourceTypeDeclarationsRefresher: SourceTypeDeclarationsRefresherShape; |
| 53 | − resolveSecretMaterial: Effect.Effect.Success<typeof SecretMaterialResolverService>; | |
| 54 | − sourceAuthMaterialService: Effect.Effect.Success<typeof RuntimeSourceAuthMaterialService>; | |
| 55 | 47 | }; |
| 56 | 48 | |
| 57 | 49 | type SourceCatalogSyncServices = |
| 58 | 50 | | RuntimeLocalScopeService |
| 59 | 51 | | ScopeStateStore |
| 60 | 52 | | SourceArtifactStore |
| 61 | − | SourceTypeDeclarationsRefresherService | |
| 62 | − | RuntimeSourceAuthMaterialService | |
| 63 | − | SecretMaterialResolverService; | |
| 53 | + | SourceTypeDeclarationsRefresherService; | |
| 64 | 54 | |
| 65 | 55 | export type RuntimeSourceCatalogSyncShape = { |
| 66 | 56 | sync: (input: { |
| @@ -123,23 +113,16 @@ const syncSourceCatalogWithDeps = ( · 56 unmodified lines | ||
| 123 | 113 | return; |
| 124 | 114 | } |
| 125 | 115 | |
| 126 | − const adapter = getSourceAdapterForSource(input.source); | |
| 127 | − const syncResult = yield* adapter.syncCatalog({ | |
| 116 | + const definition = getSourcePluginForSource(input.source); | |
| 117 | + const irModel = yield* definition.getIrModel({ | |
| 128 | 118 | source: input.source, |
| 129 | − resolveSecretMaterial: deps.resolveSecretMaterial, | |
| 130 | − resolveAuthMaterialForSlot: (slot) => | |
| 131 | − deps.sourceAuthMaterialService.resolve({ | |
| 132 | − source: input.source, | |
| 133 | − slot, | |
| 134 | − actorScopeId: input.actorScopeId, | |
| 135 | − }), | |
| 136 | 119 | }); |
| 137 | − const snapshot = snapshotFromSourceCatalogSyncResult(syncResult); | |
| 120 | + const snapshot = snapshotFromSourceCatalogSyncResult(irModel); | |
| 138 | 121 | yield* deps.sourceArtifactStore.write({ |
| 139 | 122 | sourceId: input.source.id, |
| 140 | 123 | artifact: deps.sourceArtifactStore.build({ |
| 141 | 124 | source: input.source, |
| 142 | − syncResult, | |
| 125 | + syncResult: irModel, | |
| 143 | 126 | }), |
| 144 | 127 | }); |
| 145 | 128 | |
| @@ -152,7 +135,7 @@ const syncSourceCatalogWithDeps = ( · 6 unmodified lines | ||
| 152 | 135 | [input.source.id]: { |
| 153 | 136 | status: "connected", |
| 154 | 137 | lastError: null, |
| 155 | − sourceHash: syncResult.sourceHash, | |
| 138 | + sourceHash: irModel.sourceHash, | |
| 156 | 139 | createdAt: existingSourceState?.createdAt ?? input.source.createdAt, |
| 157 | 140 | updatedAt: Date.now(), |
| 158 | 141 | }, |
| @@ -187,17 +170,12 @@ export const syncSourceCatalog = (input: { · 28 unmodified lines | ||
| 187 | 170 | const sourceArtifactStore = yield* SourceArtifactStore; |
| 188 | 171 | const sourceTypeDeclarationsRefresher = |
| 189 | 172 | yield* SourceTypeDeclarationsRefresherService; |
| 190 | − const resolveSecretMaterial = yield* SecretMaterialResolverService; | |
| 191 | − const sourceAuthMaterialService = yield* RuntimeSourceAuthMaterialService; | |
| 192 | − | |
| 193 | 173 | return yield* syncSourceCatalogWithDeps( |
| 194 | 174 | { |
| 195 | 175 | runtimeLocalScope, |
| 196 | 176 | scopeStateStore, |
| 197 | 177 | sourceArtifactStore, |
| 198 | 178 | sourceTypeDeclarationsRefresher, |
| 199 | − resolveSecretMaterial, | |
| 200 | − sourceAuthMaterialService, | |
| 201 | 179 | }, |
| 202 | 180 | { |
| 203 | 181 | source: input.source, |
| @@ -214,16 +192,11 @@ export const RuntimeSourceCatalogSyncLive = Layer.effect( · 10 unmodified lines | ||
| 214 | 192 | const sourceArtifactStore = yield* SourceArtifactStore; |
| 215 | 193 | const sourceTypeDeclarationsRefresher = |
| 216 | 194 | yield* SourceTypeDeclarationsRefresherService; |
| 217 | − const resolveSecretMaterial = yield* SecretMaterialResolverService; | |
| 218 | − const sourceAuthMaterialService = yield* RuntimeSourceAuthMaterialService; | |
| 219 | − | |
| 220 | 195 | const deps: RuntimeSourceCatalogSyncDeps = { |
| 221 | 196 | runtimeLocalScope, |
| 222 | 197 | scopeStateStore, |
| 223 | 198 | sourceArtifactStore, |
| 224 | 199 | sourceTypeDeclarationsRefresher, |
| 225 | − resolveSecretMaterial, | |
| 226 | − sourceAuthMaterialService, | |
| 227 | 200 | }; |
| 228 | 201 | |
| 229 | 202 | return RuntimeSourceCatalogSyncService.of({ |
| @@ -10,12 +10,9 @@ import * as Effect from "effect/Effect"; · 9 unmodified lines | ||
| 10 | 10 | import type { |
| 11 | 11 | LoadedSourceCatalogToolIndexEntry, |
| 12 | 12 | } from "../catalog/source/runtime"; |
| 13 | −import type { | |
| 14 | − ResolvedSourceAuthMaterial, | |
| 15 | −} from "../auth/source-auth-material"; | |
| 16 | 13 | import { |
| 17 | − getSourceAdapter, | |
| 18 | −} from "../sources/source-adapters"; | |
| 14 | + getSourcePlugin, | |
| 15 | +} from "../sources/source-plugins"; | |
| 19 | 16 | import { |
| 20 | 17 | runtimeEffectError, |
| 21 | 18 | } from "../effect-errors"; |
| @@ -55,28 +52,26 @@ export const invokeIrTool = (input: { · 33 unmodified lines | ||
| 55 | 52 | scopeId: Source["scopeId"]; |
| 56 | 53 | actorScopeId: ScopeId; |
| 57 | 54 | tool: LoadedSourceCatalogToolIndexEntry; |
| 58 | − auth: ResolvedSourceAuthMaterial; | |
| 59 | 55 | args: unknown; |
| 60 | 56 | onElicitation?: OnElicitation; |
| 61 | 57 | context?: Record<string, unknown>; |
| 62 | 58 | }) => { |
| 63 | − const adapter = getSourceAdapter(input.tool.executable.adapterKey); | |
| 64 | − if (adapter.key !== input.tool.source.kind) { | |
| 59 | + const definition = getSourcePlugin(input.tool.executable.pluginKey); | |
| 60 | + if (definition.kind !== input.tool.source.kind) { | |
| 65 | 61 | return Effect.fail( |
| 66 | 62 | runtimeEffectError("execution/ir-execution", |
| 67 | − `Executable ${input.tool.executable.id} expects adapter ${adapter.key}, but source ${input.tool.source.id} is ${input.tool.source.kind}`, | |
| 63 | + `Executable ${input.tool.executable.id} expects source type ${definition.kind}, but source ${input.tool.source.id} is ${input.tool.source.kind}`, | |
| 68 | 64 | ), |
| 69 | 65 | ); |
| 70 | 66 | } |
| 71 | 67 | |
| 72 | − return adapter.invoke({ | |
| 68 | + return definition.invoke({ | |
| 73 | 69 | source: input.tool.source, |
| 74 | 70 | capability: input.tool.capability, |
| 75 | 71 | executable: input.tool.executable, |
| 76 | 72 | descriptor: input.tool.descriptor, |
| 77 | 73 | catalog: input.tool.projectedCatalog, |
| 78 | 74 | args: input.args, |
| 79 | − auth: input.auth, | |
| 80 | 75 | onElicitation: input.onElicitation, |
| 81 | 76 | context: input.context, |
| 82 | 77 | }); |
| @@ -111,12 +111,6 @@ const interactionPurposeFromInput = (input: Parameters<OnElicitation>[0]): strin · 110 unmodified lines | ||
| 111 | 111 | return explicitPurpose; |
| 112 | 112 | } |
| 113 | 113 | |
| 114 | − if (input.path === "executor.sources.add") { | |
| 115 | − return input.elicitation.mode === "url" | |
| 116 | − ? "source_connect_oauth2" | |
| 117 | − : "source_connect_secret"; | |
| 118 | − } | |
| 119 | − | |
| 120 | 114 | return "elicitation"; |
| 121 | 115 | }; |
| 122 | 116 | |
| @@ -17,15 +17,9 @@ import { · 16 unmodified lines | ||
| 17 | 17 | import { |
| 18 | 18 | createScopeToolInvoker, |
| 19 | 19 | } from "./tool-invoker"; |
| 20 | −import { | |
| 21 | − RuntimeSourceAuthServiceTag, | |
| 22 | −} from "../../sources/source-auth-service"; | |
| 23 | 20 | import { |
| 24 | 21 | RuntimeSourceCatalogStoreService, |
| 25 | 22 | } from "../../catalog/source/runtime"; |
| 26 | −import { | |
| 27 | − RuntimeSourceAuthMaterialService, | |
| 28 | −} from "../../auth/source-auth-material"; | |
| 29 | 23 | import { |
| 30 | 24 | RuntimeSourceCatalogSyncService, |
| 31 | 25 | } from "../../catalog/source/sync"; |
| @@ -81,12 +75,6 @@ export const createScopeExecutionEnvironmentResolver = · 49 unmodified lines | ||
| 81 | 75 | sourceCatalogSyncService: Effect.Effect.Success< |
| 82 | 76 | typeof RuntimeSourceCatalogSyncService |
| 83 | 77 | >; |
| 84 | − sourceAuthMaterialService: Effect.Effect.Success< | |
| 85 | − typeof RuntimeSourceAuthMaterialService | |
| 86 | − >; | |
| 87 | − sourceAuthService: Effect.Effect.Success< | |
| 88 | − typeof RuntimeSourceAuthServiceTag | |
| 89 | − >; | |
| 90 | 78 | sourceCatalogStore: Effect.Effect.Success< |
| 91 | 79 | typeof RuntimeSourceCatalogStoreService |
| 92 | 80 | >; |
| @@ -127,8 +115,6 @@ export const createScopeExecutionEnvironmentResolver = · 34 unmodified lines | ||
| 127 | 115 | scopeConfigStore: input.scopeConfigStore, |
| 128 | 116 | scopeStateStore: input.scopeStateStore, |
| 129 | 117 | sourceArtifactStore: input.sourceArtifactStore, |
| 130 | − sourceAuthMaterialService: input.sourceAuthMaterialService, | |
| 131 | − sourceAuthService: input.sourceAuthService, | |
| 132 | 118 | runtimeLocalScope, |
| 133 | 119 | localToolRuntime, |
| 134 | 120 | createInternalToolMap: input.createInternalToolMap, |
| @@ -168,9 +154,6 @@ export const RuntimeExecutionResolverLive = ( · 33 unmodified lines | ||
| 168 | 154 | const sourceStore = yield* RuntimeSourceStoreService; |
| 169 | 155 | const sourceCatalogSyncService = |
| 170 | 156 | yield* RuntimeSourceCatalogSyncService; |
| 171 | − const sourceAuthMaterialService = | |
| 172 | − yield* RuntimeSourceAuthMaterialService; | |
| 173 | − const sourceAuthService = yield* RuntimeSourceAuthServiceTag; | |
| 174 | 157 | const sourceCatalogStore = yield* RuntimeSourceCatalogStoreService; |
| 175 | 158 | const localToolRuntimeLoader = yield* LocalToolRuntimeLoaderService; |
| 176 | 159 | const installationStore = yield* InstallationStore; |
| @@ -186,8 +169,6 @@ export const RuntimeExecutionResolverLive = ( · 9 unmodified lines | ||
| 186 | 169 | executorStateStore, |
| 187 | 170 | sourceStore, |
| 188 | 171 | sourceCatalogSyncService, |
| 189 | − sourceAuthService, | |
| 190 | − sourceAuthMaterialService, | |
| 191 | 172 | sourceCatalogStore, |
| 192 | 173 | localToolRuntimeLoader, |
| 193 | 174 | installationStore, |
| @@ -14,9 +14,6 @@ import type { · 13 unmodified lines | ||
| 14 | 14 | } from "#schema"; |
| 15 | 15 | import * as Effect from "effect/Effect"; |
| 16 | 16 | |
| 17 | −import { | |
| 18 | − RuntimeSourceAuthMaterialService, | |
| 19 | −} from "../../auth/source-auth-material"; | |
| 20 | 17 | import { |
| 21 | 18 | RuntimeSourceCatalogStoreService, |
| 22 | 19 | } from "../../catalog/source/runtime"; |
| @@ -42,9 +39,6 @@ import type { · 19 unmodified lines | ||
| 42 | 39 | import type { |
| 43 | 40 | ExecutorStateStoreShape, |
| 44 | 41 | } from "../../executor-state-store"; |
| 45 | −import { | |
| 46 | − RuntimeSourceAuthService, | |
| 47 | −} from "../../sources/source-auth-service"; | |
| 48 | 42 | import { |
| 49 | 43 | type RuntimeSourceStore, |
| 50 | 44 | } from "../../sources/source-store"; |
| @@ -80,7 +74,6 @@ export type ScopeInternalToolContext = { · 29 unmodified lines | ||
| 80 | 74 | sourceCatalogSyncService: Effect.Effect.Success< |
| 81 | 75 | typeof RuntimeSourceCatalogSyncService |
| 82 | 76 | >; |
| 83 | − sourceAuthService: RuntimeSourceAuthService; | |
| 84 | 77 | installationStore: InstallationStoreShape; |
| 85 | 78 | instanceConfigResolver: ResolveInstanceConfig; |
| 86 | 79 | storeSecretMaterial: StoreSecretMaterial; |
| @@ -115,10 +108,6 @@ export const createScopeToolInvoker = (input: { · 28 unmodified lines | ||
| 115 | 108 | scopeConfigStore: ScopeConfigStoreShape; |
| 116 | 109 | scopeStateStore: ScopeStateStoreShape; |
| 117 | 110 | sourceArtifactStore: SourceArtifactStoreShape; |
| 118 | − sourceAuthMaterialService: Effect.Effect.Success< | |
| 119 | − typeof RuntimeSourceAuthMaterialService | |
| 120 | − >; | |
| 121 | − sourceAuthService: RuntimeSourceAuthService; | |
| 122 | 111 | runtimeLocalScope: RuntimeLocalScopeState | null; |
| 123 | 112 | localToolRuntime: LocalToolRuntime; |
| 124 | 113 | createInternalToolMap?: CreateScopeInternalToolMap; |
| @@ -140,7 +129,6 @@ export const createScopeToolInvoker = (input: { · 15 unmodified lines | ||
| 140 | 129 | const executorTools = createExecutorToolMap({ |
| 141 | 130 | scopeId: input.scopeId, |
| 142 | 131 | actorScopeId: input.actorScopeId, |
| 143 | − sourceAuthService: input.sourceAuthService, | |
| 144 | 132 | installationStore: input.installationStore, |
| 145 | 133 | scopeConfigStore: input.scopeConfigStore, |
| 146 | 134 | scopeStateStore: input.scopeStateStore, |
| @@ -154,7 +142,6 @@ export const createScopeToolInvoker = (input: { · 7 unmodified lines | ||
| 154 | 142 | executorStateStore: input.executorStateStore, |
| 155 | 143 | sourceStore: input.sourceStore, |
| 156 | 144 | sourceCatalogSyncService: input.sourceCatalogSyncService, |
| 157 | − sourceAuthService: input.sourceAuthService, | |
| 158 | 145 | installationStore: input.installationStore, |
| 159 | 146 | instanceConfigResolver: input.instanceConfigResolver, |
| 160 | 147 | storeSecretMaterial: input.storeSecretMaterial, |
| @@ -232,16 +219,10 @@ export const createScopeToolInvoker = (input: { · 71 unmodified lines | ||
| 232 | 219 | onElicitation: input.onElicitation, |
| 233 | 220 | }); |
| 234 | 221 | |
| 235 | − const auth = yield* input.sourceAuthMaterialService.resolve({ | |
| 236 | − source: catalogTool.source, | |
| 237 | − actorScopeId: input.actorScopeId, | |
| 238 | − context: toSecretResolutionContext(invocation.context), | |
| 239 | − }); | |
| 240 | 222 | return yield* invokeIrTool({ |
| 241 | 223 | scopeId: input.scopeId, |
| 242 | 224 | actorScopeId: input.actorScopeId, |
| 243 | 225 | tool: catalogTool, |
| 244 | − auth, | |
| 245 | 226 | args: invocation.args, |
| 246 | 227 | onElicitation: input.onElicitation, |
| 247 | 228 | context: invocation.context, |
| @@ -254,13 +235,13 @@ export const createScopeToolInvoker = (input: { · 6 unmodified lines | ||
| 254 | 235 | return { |
| 255 | 236 | catalog, |
| 256 | 237 | toolInvoker: { |
| 257 | − invoke: ({ path, args, context }) => | |
| 258 | − provideRuntimeLocalScope( | |
| 259 | − authoredToolPaths.has(path) | |
| 260 | − ? authoredInvoker.invoke({ path, args, context }) | |
| 261 | − : invokePersistedTool({ path, args, context }), | |
| 262 | − input.runtimeLocalScope, | |
| 263 | − ), | |
| 238 | + invoke: ({ path, args, context }) => { | |
| 239 | + const effect: Effect.Effect<unknown, unknown, never> = authoredToolPaths.has(path) | |
| 240 | + ? authoredInvoker.invoke({ path, args, context }) as Effect.Effect<unknown, unknown, never> | |
| 241 | + : invokePersistedTool({ path, args, context }); | |
| 242 | + | |
| 243 | + return provideRuntimeLocalScope(effect, input.runtimeLocalScope); | |
| 244 | + }, | |
| 264 | 245 | }, |
| 265 | 246 | }; |
| 266 | 247 | }; |
| @@ -2,16 +2,10 @@ import * as Context from "effect/Context"; · 1 unmodified line | ||
| 2 | 2 | import type * as Effect from "effect/Effect"; |
| 3 | 3 | |
| 4 | 4 | import type { |
| 5 | − AuthArtifact, | |
| 6 | − AuthLease, | |
| 7 | 5 | Execution, |
| 8 | 6 | ExecutionInteraction, |
| 9 | 7 | ExecutionStep, |
| 10 | − ProviderAuthGrant, | |
| 11 | 8 | SecretMaterial, |
| 12 | − SourceAuthSession, | |
| 13 | − ScopeOauthClient, | |
| 14 | − ScopedSourceOauthClient, | |
| 15 | 9 | } from "#schema"; |
| 16 | 10 | |
| 17 | 11 | type SecretMaterialSummary = { |
| @@ -24,120 +18,6 @@ type SecretMaterialSummary = { · 6 unmodified lines | ||
| 24 | 18 | }; |
| 25 | 19 | |
| 26 | 20 | export type ExecutorStateStoreShape = { |
| 27 | − authArtifacts: { | |
| 28 | − listByScopeId: ( | |
| 29 | − scopeId: AuthArtifact["scopeId"], | |
| 30 | − ) => Effect.Effect<readonly AuthArtifact[], Error, never>; | |
| 31 | − listByScopeAndSourceId: (input: { | |
| 32 | − scopeId: AuthArtifact["scopeId"]; | |
| 33 | − sourceId: AuthArtifact["sourceId"]; | |
| 34 | − }) => Effect.Effect<readonly AuthArtifact[], Error, never>; | |
| 35 | − getByScopeSourceAndActor: (input: { | |
| 36 | − scopeId: AuthArtifact["scopeId"]; | |
| 37 | − sourceId: AuthArtifact["sourceId"]; | |
| 38 | − actorScopeId: AuthArtifact["actorScopeId"]; | |
| 39 | − slot: AuthArtifact["slot"]; | |
| 40 | − }) => Effect.Effect<import("effect/Option").Option<AuthArtifact>, Error, never>; | |
| 41 | − upsert: (artifact: AuthArtifact) => Effect.Effect<void, Error, never>; | |
| 42 | − removeByScopeSourceAndActor: (input: { | |
| 43 | − scopeId: AuthArtifact["scopeId"]; | |
| 44 | − sourceId: AuthArtifact["sourceId"]; | |
| 45 | − actorScopeId: AuthArtifact["actorScopeId"]; | |
| 46 | − slot?: AuthArtifact["slot"]; | |
| 47 | − }) => Effect.Effect<boolean, Error, never>; | |
| 48 | − removeByScopeAndSourceId: (input: { | |
| 49 | − scopeId: AuthArtifact["scopeId"]; | |
| 50 | − sourceId: AuthArtifact["sourceId"]; | |
| 51 | − }) => Effect.Effect<number, Error, never>; | |
| 52 | − }; | |
| 53 | − authLeases: { | |
| 54 | − listAll: () => Effect.Effect<readonly AuthLease[], Error, never>; | |
| 55 | − getByAuthArtifactId: ( | |
| 56 | − authArtifactId: AuthLease["authArtifactId"], | |
| 57 | − ) => Effect.Effect<import("effect/Option").Option<AuthLease>, Error, never>; | |
| 58 | − upsert: (lease: AuthLease) => Effect.Effect<void, Error, never>; | |
| 59 | − removeByAuthArtifactId: ( | |
| 60 | − authArtifactId: AuthLease["authArtifactId"], | |
| 61 | − ) => Effect.Effect<boolean, Error, never>; | |
| 62 | − }; | |
| 63 | − sourceOauthClients: { | |
| 64 | − getByScopeSourceAndProvider: (input: { | |
| 65 | − scopeId: ScopedSourceOauthClient["scopeId"]; | |
| 66 | − sourceId: ScopedSourceOauthClient["sourceId"]; | |
| 67 | − providerKey: string; | |
| 68 | − }) => Effect.Effect< | |
| 69 | − import("effect/Option").Option<ScopedSourceOauthClient>, | |
| 70 | − Error, | |
| 71 | − never | |
| 72 | − >; | |
| 73 | − upsert: ( | |
| 74 | − oauthClient: ScopedSourceOauthClient, | |
| 75 | − ) => Effect.Effect<void, Error, never>; | |
| 76 | − removeByScopeAndSourceId: (input: { | |
| 77 | − scopeId: ScopedSourceOauthClient["scopeId"]; | |
| 78 | − sourceId: ScopedSourceOauthClient["sourceId"]; | |
| 79 | − }) => Effect.Effect<number, Error, never>; | |
| 80 | − }; | |
| 81 | − scopeOauthClients: { | |
| 82 | − listByScopeAndProvider: (input: { | |
| 83 | − scopeId: ScopeOauthClient["scopeId"]; | |
| 84 | − providerKey: string; | |
| 85 | − }) => Effect.Effect<readonly ScopeOauthClient[], Error, never>; | |
| 86 | − getById: ( | |
| 87 | − id: ScopeOauthClient["id"], | |
| 88 | − ) => Effect.Effect<import("effect/Option").Option<ScopeOauthClient>, Error, never>; | |
| 89 | − upsert: (oauthClient: ScopeOauthClient) => Effect.Effect<void, Error, never>; | |
| 90 | − removeById: (id: ScopeOauthClient["id"]) => Effect.Effect<boolean, Error, never>; | |
| 91 | − }; | |
| 92 | − providerAuthGrants: { | |
| 93 | − listByScopeId: ( | |
| 94 | − scopeId: ProviderAuthGrant["scopeId"], | |
| 95 | − ) => Effect.Effect<readonly ProviderAuthGrant[], Error, never>; | |
| 96 | − listByScopeActorAndProvider: (input: { | |
| 97 | − scopeId: ProviderAuthGrant["scopeId"]; | |
| 98 | − actorScopeId: ProviderAuthGrant["actorScopeId"]; | |
| 99 | − providerKey: string; | |
| 100 | − }) => Effect.Effect<readonly ProviderAuthGrant[], Error, never>; | |
| 101 | − getById: ( | |
| 102 | − id: ProviderAuthGrant["id"], | |
| 103 | − ) => Effect.Effect<import("effect/Option").Option<ProviderAuthGrant>, Error, never>; | |
| 104 | − upsert: (grant: ProviderAuthGrant) => Effect.Effect<void, Error, never>; | |
| 105 | − removeById: (id: ProviderAuthGrant["id"]) => Effect.Effect<boolean, Error, never>; | |
| 106 | − }; | |
| 107 | − sourceAuthSessions: { | |
| 108 | − listAll: () => Effect.Effect<readonly SourceAuthSession[], Error, never>; | |
| 109 | − listByScopeId: ( | |
| 110 | − scopeId: SourceAuthSession["scopeId"], | |
| 111 | − ) => Effect.Effect<readonly SourceAuthSession[], Error, never>; | |
| 112 | − getById: ( | |
| 113 | − id: SourceAuthSession["id"], | |
| 114 | − ) => Effect.Effect<import("effect/Option").Option<SourceAuthSession>, Error, never>; | |
| 115 | − getByState: ( | |
| 116 | − state: SourceAuthSession["state"], | |
| 117 | − ) => Effect.Effect<import("effect/Option").Option<SourceAuthSession>, Error, never>; | |
| 118 | − getPendingByScopeSourceAndActor: (input: { | |
| 119 | − scopeId: SourceAuthSession["scopeId"]; | |
| 120 | − sourceId: SourceAuthSession["sourceId"]; | |
| 121 | − actorScopeId: SourceAuthSession["actorScopeId"]; | |
| 122 | − credentialSlot?: SourceAuthSession["credentialSlot"]; | |
| 123 | − }) => Effect.Effect< | |
| 124 | − import("effect/Option").Option<SourceAuthSession>, | |
| 125 | − Error, | |
| 126 | − never | |
| 127 | − >; | |
| 128 | − insert: (session: SourceAuthSession) => Effect.Effect<void, Error, never>; | |
| 129 | − update: ( | |
| 130 | − id: SourceAuthSession["id"], | |
| 131 | − patch: Partial< | |
| 132 | − Omit<SourceAuthSession, "id" | "scopeId" | "sourceId" | "createdAt"> | |
| 133 | − >, | |
| 134 | − ) => Effect.Effect<import("effect/Option").Option<SourceAuthSession>, Error, never>; | |
| 135 | − upsert: (session: SourceAuthSession) => Effect.Effect<void, Error, never>; | |
| 136 | − removeByScopeAndSourceId: ( | |
| 137 | − scopeId: SourceAuthSession["scopeId"], | |
| 138 | − sourceId: SourceAuthSession["sourceId"], | |
| 139 | − ) => Effect.Effect<boolean, Error, never>; | |
| 140 | − }; | |
| 141 | 21 | secretMaterials: { |
| 142 | 22 | getById: ( |
| 143 | 23 | id: SecretMaterial["id"], |
| @@ -10,9 +10,6 @@ import * as Effect from "effect/Effect"; · 9 unmodified lines | ||
| 10 | 10 | import * as Layer from "effect/Layer"; |
| 11 | 11 | import * as ManagedRuntime from "effect/ManagedRuntime"; |
| 12 | 12 | |
| 13 | −import { | |
| 14 | − RuntimeSourceAuthMaterialLive, | |
| 15 | −} from "./auth/source-auth-material"; | |
| 16 | 13 | import { |
| 17 | 14 | RuntimeSourceCatalogStoreService, |
| 18 | 15 | RuntimeSourceCatalogStoreLive, |
| @@ -92,9 +89,6 @@ import { · 73 unmodified lines | ||
| 92 | 89 | ExecutorStateStore, |
| 93 | 90 | type ExecutorStateStoreShape, |
| 94 | 91 | } from "./executor-state-store"; |
| 95 | −import { | |
| 96 | − RuntimeSourceAuthServiceLive, | |
| 97 | −} from "./sources/source-auth-service"; | |
| 98 | 92 | import { |
| 99 | 93 | RuntimeSourceStoreLive, |
| 100 | 94 | } from "./sources/source-store"; |
| @@ -105,7 +99,6 @@ export * from "./execution/live"; · 4 unmodified lines | ||
| 105 | 99 | export * from "./catalog/schema-type-signature"; |
| 106 | 100 | export * from "./catalog/source/runtime"; |
| 107 | 101 | export * from "./catalog/source/sync"; |
| 108 | −export * from "./sources/source-auth-service"; | |
| 109 | 102 | export * from "./sources/source-credential-interactions"; |
| 110 | 103 | export * from "./sources/source-store"; |
| 111 | 104 | export * from "./executor-state-store"; |
| @@ -131,22 +124,13 @@ export type { · 19 unmodified lines | ||
| 131 | 124 | UpdateSecretMaterial, |
| 132 | 125 | } from "./scope/secret-material-providers"; |
| 133 | 126 | export { |
| 134 | − builtInSourceAdapters, | |
| 135 | − connectableSourceAdapters, | |
| 136 | − executorAddableSourceAdapters, | |
| 137 | − localConfigurableSourceAdapters, | |
| 138 | − hasRegisteredConnectableSourceAdapters, | |
| 139 | − hasRegisteredExecutorAddableSourceAdapters, | |
| 140 | − hasRegisteredExternalSourceAdapters, | |
| 141 | − getSourceAdapter, | |
| 142 | − getSourceAdapterForSource, | |
| 143 | − findSourceAdapterByProviderKey, | |
| 144 | − sourceBindingStateFromSource, | |
| 145 | − sourceAdapterCatalogKind, | |
| 146 | − sourceAdapterRequiresInteractiveConnect, | |
| 147 | − sourceAdapterUsesCredentialManagedAuth, | |
| 148 | − isInternalSourceAdapter, | |
| 149 | −} from "./sources/source-adapters"; | |
| 127 | + registeredSourcePlugins, | |
| 128 | + hasRegisteredExternalSourcePlugins, | |
| 129 | + getSourcePlugin, | |
| 130 | + getSourcePluginForSource, | |
| 131 | + sourcePluginCatalogKind, | |
| 132 | + isInternalSourcePluginKind, | |
| 133 | +} from "./sources/source-plugins"; | |
| 150 | 134 | |
| 151 | 135 | export type ExecutorRuntimeOptions = { |
| 152 | 136 | executionResolver?: ResolveExecutionEnvironment; |
| @@ -213,15 +197,6 @@ export type RuntimeSecretMaterialServices = { · 60 unmodified lines | ||
| 213 | 197 | update: UpdateSecretMaterial; |
| 214 | 198 | }; |
| 215 | 199 | |
| 216 | −export type RuntimeAuthStorageServices = { | |
| 217 | − artifacts: ExecutorStateStoreShape["authArtifacts"]; | |
| 218 | − leases: ExecutorStateStoreShape["authLeases"]; | |
| 219 | − sourceOauthClients: ExecutorStateStoreShape["sourceOauthClients"]; | |
| 220 | − scopeOauthClients: ExecutorStateStoreShape["scopeOauthClients"]; | |
| 221 | − providerGrants: ExecutorStateStoreShape["providerAuthGrants"]; | |
| 222 | − sourceSessions: ExecutorStateStoreShape["sourceAuthSessions"]; | |
| 223 | −}; | |
| 224 | − | |
| 225 | 200 | export const prewarmWorkspaceSourceCatalogToolIndex = (input: { |
| 226 | 201 | scopeId: LocalInstallation["scopeId"]; |
| 227 | 202 | actorScopeId: LocalInstallation["actorScopeId"]; |
| @@ -253,7 +228,6 @@ export type RuntimeStorageServices = { · 25 unmodified lines | ||
| 253 | 228 | scopeConfig: BoundScopeConfigStore; |
| 254 | 229 | scopeState: BoundScopeStateStore; |
| 255 | 230 | sourceArtifacts: BoundSourceArtifactStore; |
| 256 | − auth: RuntimeAuthStorageServices; | |
| 257 | 231 | secrets: RuntimeSecretsStorageServices; |
| 258 | 232 | executions: RuntimeExecutionStorageServices; |
| 259 | 233 | close?: () => Promise<void>; |
| @@ -327,12 +301,6 @@ const makeInstanceConfigLayer = (input: RuntimeInstanceConfigService) => · 67 unmodified lines | ||
| 327 | 301 | const toExecutorStateStoreShape = ( |
| 328 | 302 | input: RuntimeStorageServices, |
| 329 | 303 | ): ExecutorStateStoreShape => ({ |
| 330 | − authArtifacts: input.auth.artifacts, | |
| 331 | − authLeases: input.auth.leases, | |
| 332 | − sourceOauthClients: input.auth.sourceOauthClients, | |
| 333 | − scopeOauthClients: input.auth.scopeOauthClients, | |
| 334 | − providerAuthGrants: input.auth.providerGrants, | |
| 335 | − sourceAuthSessions: input.auth.sourceSessions, | |
| 336 | 304 | secretMaterials: input.secrets, |
| 337 | 305 | executions: input.executions.runs, |
| 338 | 306 | executionInteractions: input.executions.interactions, |
| @@ -387,27 +355,9 @@ export const createExecutorRuntimeLayer = ( · 48 unmodified lines | ||
| 387 | 355 | Layer.provide(Layer.mergeAll(baseLayer, sourceStoreLayer)), |
| 388 | 356 | ); |
| 389 | 357 | |
| 390 | − const sourceAuthMaterialLayer = RuntimeSourceAuthMaterialLive.pipe( | |
| 391 | − Layer.provide(Layer.mergeAll(baseLayer, secretMaterialLayer)), | |
| 392 | − ); | |
| 393 | − | |
| 394 | 358 | const sourceCatalogSyncLayer = RuntimeSourceCatalogSyncLive.pipe( |
| 395 | 359 | Layer.provide( |
| 396 | − Layer.mergeAll(baseLayer, secretMaterialLayer, sourceAuthMaterialLayer), | |
| 397 | − ), | |
| 398 | − ); | |
| 399 | − | |
| 400 | − const sourceAuthLayer = RuntimeSourceAuthServiceLive({ | |
| 401 | − getLocalServerBaseUrl: input.getLocalServerBaseUrl, | |
| 402 | − }).pipe( | |
| 403 | − Layer.provide( | |
| 404 | − Layer.mergeAll( | |
| 405 | − baseLayer, | |
| 406 | − instanceConfigLayer, | |
| 407 | − secretMaterialLayer, | |
| 408 | − sourceStoreLayer, | |
| 409 | − sourceCatalogSyncLayer, | |
| 410 | − ), | |
| 360 | + Layer.mergeAll(baseLayer, secretMaterialLayer), | |
| 411 | 361 | ), |
| 412 | 362 | ); |
| 413 | 363 | |
| @@ -421,9 +371,7 @@ export const createExecutorRuntimeLayer = ( · 7 unmodified lines | ||
| 421 | 371 | instanceConfigLayer, |
| 422 | 372 | secretMaterialLayer, |
| 423 | 373 | sourceStoreLayer, |
| 424 | − sourceAuthMaterialLayer, | |
| 425 | 374 | sourceCatalogSyncLayer, |
| 426 | − sourceAuthLayer, | |
| 427 | 375 | sourceCatalogStoreLayer, |
| 428 | 376 | localToolRuntimeLayer, |
| 429 | 377 | ), |
| @@ -435,11 +383,9 @@ export const createExecutorRuntimeLayer = ( · 5 unmodified lines | ||
| 435 | 383 | instanceConfigLayer, |
| 436 | 384 | secretMaterialLayer, |
| 437 | 385 | sourceStoreLayer, |
| 438 | − sourceAuthMaterialLayer, | |
| 439 | 386 | sourceCatalogSyncLayer, |
| 440 | 387 | sourceCatalogStoreLayer, |
| 441 | 388 | localToolRuntimeLayer, |
| 442 | − sourceAuthLayer, | |
| 443 | 389 | executionResolverLayer, |
| 444 | 390 | ) as ExecutorRuntimeLayer; |
| 445 | 391 | }; |
| @@ -1,276 +1,47 @@ | ||
| 1 | −import { | |
| 2 | − type ElicitationResponse, | |
| 3 | − toTool, | |
| 4 | − type ToolMap, | |
| 5 | − type ToolPath, | |
| 6 | −} from "@executor/codemode-core"; | |
| 7 | −import { | |
| 8 | − type ScopeId, | |
| 9 | − ExecutionIdSchema, | |
| 10 | − ExecutionInteractionIdSchema, | |
| 11 | − SourceSchema, | |
| 12 | − type Source, | |
| 13 | −} from "#schema"; | |
| 14 | −import * as Effect from "effect/Effect"; | |
| 15 | −import * as Cause from "effect/Cause"; | |
| 16 | −import * as Exit from "effect/Exit"; | |
| 17 | −import * as Schema from "effect/Schema"; | |
| 18 | −import type { | |
| 19 | − RuntimeLocalScopeState, | |
| 20 | −} from "../scope/runtime-context"; | |
| 21 | −import { | |
| 22 | − type LocalStorageServices, | |
| 23 | − type InstallationStoreShape, | |
| 24 | − type SourceArtifactStoreShape, | |
| 25 | − type ScopeConfigStoreShape, | |
| 26 | − type ScopeStateStoreShape, | |
| 27 | − makeLocalStorageLayer, | |
| 28 | −} from "../scope/storage"; | |
| 29 | −import { | |
| 30 | − provideOptionalRuntimeLocalScope, | |
| 31 | −} from "../scope/runtime-context"; | |
| 32 | − | |
| 33 | −/** Run an Effect as a Promise, preserving the original error (not FiberFailure). */ | |
| 34 | −const runEffect = async <A>( | |
| 35 | − effect: Effect.Effect<A, unknown, LocalStorageServices>, | |
| 36 | − storage: { | |
| 37 | − installationStore: InstallationStoreShape; | |
| 38 | − scopeConfigStore: ScopeConfigStoreShape; | |
| 39 | − scopeStateStore: ScopeStateStoreShape; | |
| 40 | − sourceArtifactStore: SourceArtifactStoreShape; | |
| 41 | − }, | |
| 42 | − runtimeLocalScope: RuntimeLocalScopeState | null = null, | |
| 43 | −): Promise<A> => { | |
| 44 | − const baseLayer = makeLocalStorageLayer(storage); | |
| 45 | − const exit = await Effect.runPromiseExit( | |
| 46 | − provideOptionalRuntimeLocalScope( | |
| 47 | − effect.pipe(Effect.provide(baseLayer)), | |
| 48 | − runtimeLocalScope, | |
| 49 | − ), | |
| 50 | − ); | |
| 51 | − if (Exit.isSuccess(exit)) return exit.value; | |
| 52 | − throw Cause.squash(exit.cause); | |
| 53 | −}; | |
| 1 | +import type { ToolMap } from "@executor/codemode-core"; | |
| 2 | +import { SourceSchema } from "#schema"; | |
| 54 | 3 | |
| 55 | −import { | |
| 56 | − type ExecutorAddSourceInput, | |
| 57 | − type RuntimeSourceAuthService, | |
| 58 | −} from "./source-auth-service"; | |
| 59 | 4 | import { |
| 60 | 5 | deriveSchemaJson, |
| 61 | 6 | deriveSchemaTypeSignature, |
| 62 | 7 | } from "../catalog/schema-type-signature"; |
| 63 | −import { | |
| 64 | − ExecutorAddSourceInputSchema, | |
| 65 | − executorAddableSourceAdapters, | |
| 66 | − hasRegisteredExecutorAddableSourceAdapters, | |
| 67 | −} from "./source-adapters"; | |
| 68 | − | |
| 69 | −const ExecutorSourcesAddInputSchema = Schema.standardSchemaV1( | |
| 70 | − ExecutorAddSourceInputSchema, | |
| 71 | −); | |
| 72 | − | |
| 73 | −const ExecutorSourcesAddOutputSchema = Schema.standardSchemaV1(SourceSchema); | |
| 8 | +import type { | |
| 9 | + InstallationStoreShape, | |
| 10 | + SourceArtifactStoreShape, | |
| 11 | + ScopeConfigStoreShape, | |
| 12 | + ScopeStateStoreShape, | |
| 13 | +} from "../scope/storage"; | |
| 74 | 14 | |
| 75 | −export const EXECUTOR_SOURCES_ADD_INPUT_HINT = hasRegisteredExecutorAddableSourceAdapters | |
| 76 | − ? deriveSchemaTypeSignature( | |
| 77 | − ExecutorAddSourceInputSchema, | |
| 78 | − 320, | |
| 79 | − ) | |
| 80 | − : "Source plugins are not registered in this build."; | |
| 15 | +export const EXECUTOR_SOURCES_ADD_INPUT_HINT = | |
| 16 | + "Source plugins are not registered in this build."; | |
| 81 | 17 | |
| 82 | 18 | export const EXECUTOR_SOURCES_ADD_OUTPUT_SIGNATURE = deriveSchemaTypeSignature( |
| 83 | 19 | SourceSchema, |
| 84 | 20 | 260, |
| 85 | 21 | ); |
| 86 | 22 | |
| 87 | −export const EXECUTOR_SOURCES_ADD_INPUT_SCHEMA = hasRegisteredExecutorAddableSourceAdapters | |
| 88 | − ? deriveSchemaJson( | |
| 89 | − ExecutorAddSourceInputSchema, | |
| 90 | − ) ?? {} | |
| 91 | − : {}; | |
| 23 | +export const EXECUTOR_SOURCES_ADD_INPUT_SCHEMA = {}; | |
| 92 | 24 | |
| 93 | 25 | export const EXECUTOR_SOURCES_ADD_OUTPUT_SCHEMA = deriveSchemaJson( |
| 94 | 26 | SourceSchema, |
| 95 | 27 | ) ?? {}; |
| 96 | 28 | |
| 97 | −export const EXECUTOR_SOURCES_ADD_HELP_LINES = hasRegisteredExecutorAddableSourceAdapters | |
| 98 | − ? [ | |
| 99 | − "Source add input shapes:", | |
| 100 | − ...executorAddableSourceAdapters.flatMap((adapter) => | |
| 101 | − adapter.executorAddInputSchema | |
| 102 | − && adapter.executorAddInputSignatureWidth !== null | |
| 103 | − && adapter.executorAddHelpText | |
| 104 | − ? [ | |
| 105 | − `- ${adapter.displayName}: ${deriveSchemaTypeSignature(adapter.executorAddInputSchema, adapter.executorAddInputSignatureWidth)}`, | |
| 106 | − ...adapter.executorAddHelpText.map((line) => ` ${line}`), | |
| 107 | − ] | |
| 108 | − : [], | |
| 109 | − ), | |
| 110 | − " executor handles the credential setup for you.", | |
| 111 | − ] as const | |
| 112 | − : [ | |
| 113 | − "Source plugins are not registered in this build.", | |
| 114 | − ] as const; | |
| 29 | +export const EXECUTOR_SOURCES_ADD_HELP_LINES = [ | |
| 30 | + "Source plugins are not registered in this build.", | |
| 31 | +] as const; | |
| 115 | 32 | |
| 116 | 33 | export const buildExecutorSourcesAddDescription = (): string => |
| 117 | − hasRegisteredExecutorAddableSourceAdapters | |
| 118 | − ? [ | |
| 119 | − "Add a registered source plugin to the current scope.", | |
| 120 | − ...EXECUTOR_SOURCES_ADD_HELP_LINES, | |
| 121 | − ].join("\n") | |
| 122 | − : "Source plugins are not registered in this build."; | |
| 123 | − | |
| 124 | −const toExecutionId = (value: unknown) => { | |
| 125 | − if (typeof value !== "string" || value.trim().length === 0) { | |
| 126 | − throw new Error("Missing execution run id for executor.sources.add"); | |
| 127 | − } | |
| 128 | − | |
| 129 | − return ExecutionIdSchema.make(value); | |
| 130 | −}; | |
| 131 | − | |
| 132 | −const asToolPath = (value: string): ToolPath => value as ToolPath; | |
| 133 | − | |
| 134 | −const toSerializableValue = <A>(value: A): A => | |
| 135 | − JSON.parse(JSON.stringify(value)) as A; | |
| 136 | − | |
| 137 | −type ExecutorSourcesAddToolArgs = Omit< | |
| 138 | − ExecutorAddSourceInput, | |
| 139 | − "scopeId" | "actorScopeId" | "executionId" | "interactionId" | |
| 140 | −>; | |
| 141 | − | |
| 142 | −const prepareExecutorAddSourceInput = (input: { | |
| 143 | − args: ExecutorSourcesAddToolArgs; | |
| 144 | − scopeId: ScopeId; | |
| 145 | − actorScopeId: ScopeId; | |
| 146 | − executionId: ReturnType<typeof toExecutionId>; | |
| 147 | − interactionId: ReturnType<typeof ExecutionInteractionIdSchema.make>; | |
| 148 | −}): ExecutorAddSourceInput => ({ | |
| 149 | − ...input.args, | |
| 150 | − scopeId: input.scopeId, | |
| 151 | − actorScopeId: input.actorScopeId, | |
| 152 | − executionId: input.executionId, | |
| 153 | − interactionId: input.interactionId, | |
| 154 | − } as ExecutorAddSourceInput); | |
| 34 | + "Source plugins are not registered in this build."; | |
| 155 | 35 | |
| 156 | 36 | export const createExecutorToolMap = (input: { |
| 157 | − scopeId: ScopeId; | |
| 158 | − actorScopeId: ScopeId; | |
| 159 | − sourceAuthService: RuntimeSourceAuthService; | |
| 37 | + scopeId?: string; | |
| 38 | + actorScopeId?: string; | |
| 160 | 39 | installationStore: InstallationStoreShape; |
| 161 | 40 | scopeConfigStore: ScopeConfigStoreShape; |
| 162 | 41 | scopeStateStore: ScopeStateStoreShape; |
| 163 | 42 | sourceArtifactStore: SourceArtifactStoreShape; |
| 164 | − runtimeLocalScope: RuntimeLocalScopeState | null; | |
| 165 | −}): ToolMap => | |
| 166 | − !hasRegisteredExecutorAddableSourceAdapters | |
| 167 | − ? {} | |
| 168 | − : ({ | |
| 169 | − "executor.sources.add": toTool({ | |
| 170 | − tool: { | |
| 171 | − description: buildExecutorSourcesAddDescription(), | |
| 172 | − inputSchema: ExecutorSourcesAddInputSchema, | |
| 173 | − outputSchema: ExecutorSourcesAddOutputSchema, | |
| 174 | − execute: async (args: ExecutorSourcesAddToolArgs, context): Promise<Source> => { | |
| 175 | − const executionId = toExecutionId(context?.invocation?.runId); | |
| 176 | − const interactionId = ExecutionInteractionIdSchema.make( | |
| 177 | − `executor.sources.add:${crypto.randomUUID()}`, | |
| 178 | − ); | |
| 179 | − const preparedArgs = prepareExecutorAddSourceInput({ | |
| 180 | − args, | |
| 181 | − scopeId: input.scopeId, | |
| 182 | − actorScopeId: input.actorScopeId, | |
| 183 | − executionId, | |
| 184 | − interactionId, | |
| 185 | − }); | |
| 186 | − const result = await runEffect( | |
| 187 | − input.sourceAuthService.addExecutorSource( | |
| 188 | − preparedArgs, | |
| 189 | − context?.onElicitation | |
| 190 | − ? { | |
| 191 | − mcpDiscoveryElicitation: { | |
| 192 | − onElicitation: context.onElicitation, | |
| 193 | − path: context.path ?? asToolPath("executor.sources.add"), | |
| 194 | − sourceKey: context.sourceKey, | |
| 195 | − args, | |
| 196 | − metadata: context.metadata, | |
| 197 | − invocation: context.invocation, | |
| 198 | − }, | |
| 199 | − } | |
| 200 | − : undefined, | |
| 201 | − ), | |
| 202 | − { | |
| 203 | − installationStore: input.installationStore, | |
| 204 | − scopeConfigStore: input.scopeConfigStore, | |
| 205 | − scopeStateStore: input.scopeStateStore, | |
| 206 | − sourceArtifactStore: input.sourceArtifactStore, | |
| 207 | − }, | |
| 208 | − input.runtimeLocalScope, | |
| 209 | − ); | |
| 210 | − | |
| 211 | − if (result.kind === "connected") { | |
| 212 | − return toSerializableValue(result.source); | |
| 213 | − } | |
| 214 | − if (!context?.onElicitation || result.kind !== "oauth_required") { | |
| 215 | − throw new Error( | |
| 216 | − `executor.sources.add requires plugin-managed continuation support for ${result.source.id}`, | |
| 217 | − ); | |
| 218 | − } | |
| 219 | − | |
| 220 | − const response: ElicitationResponse = await runEffect( | |
| 221 | − context.onElicitation({ | |
| 222 | − interactionId, | |
| 223 | − path: context.path ?? asToolPath("executor.sources.add"), | |
| 224 | − sourceKey: context.sourceKey, | |
| 225 | − args: preparedArgs, | |
| 226 | − metadata: context.metadata, | |
| 227 | − context: context.invocation, | |
| 228 | − elicitation: { | |
| 229 | − mode: "url", | |
| 230 | − message: `Open the provider sign-in page to connect ${result.source.name}`, | |
| 231 | − url: result.authorizationUrl, | |
| 232 | − elicitationId: result.sessionId, | |
| 233 | − }, | |
| 234 | − }), | |
| 235 | − { | |
| 236 | − installationStore: input.installationStore, | |
| 237 | − scopeConfigStore: input.scopeConfigStore, | |
| 238 | − scopeStateStore: input.scopeStateStore, | |
| 239 | − sourceArtifactStore: input.sourceArtifactStore, | |
| 240 | − }, | |
| 241 | − input.runtimeLocalScope, | |
| 242 | − ); | |
| 243 | − | |
| 244 | − if (response.action !== "accept") { | |
| 245 | − throw new Error(`Source add was not completed for ${result.source.id}`); | |
| 246 | − } | |
| 247 | − | |
| 248 | − const connected = await runEffect( | |
| 249 | − input.sourceAuthService.getSourceById({ | |
| 250 | − scopeId: input.scopeId, | |
| 251 | − sourceId: result.source.id, | |
| 252 | − actorScopeId: input.actorScopeId, | |
| 253 | − }), | |
| 254 | − { | |
| 255 | − installationStore: input.installationStore, | |
| 256 | − scopeConfigStore: input.scopeConfigStore, | |
| 257 | − scopeStateStore: input.scopeStateStore, | |
| 258 | − sourceArtifactStore: input.sourceArtifactStore, | |
| 259 | − }, | |
| 260 | − input.runtimeLocalScope, | |
| 261 | − ); | |
| 262 | − return toSerializableValue(connected); | |
| 263 | − }, | |
| 264 | − }, | |
| 265 | − metadata: { | |
| 266 | − contract: { | |
| 267 | − inputTypePreview: EXECUTOR_SOURCES_ADD_INPUT_HINT, | |
| 268 | − outputTypePreview: EXECUTOR_SOURCES_ADD_OUTPUT_SIGNATURE, | |
| 269 | − inputSchema: EXECUTOR_SOURCES_ADD_INPUT_SCHEMA, | |
| 270 | − outputSchema: EXECUTOR_SOURCES_ADD_OUTPUT_SCHEMA, | |
| 271 | − }, | |
| 272 | − sourceKey: "executor", | |
| 273 | − interaction: "auto", | |
| 274 | − }, | |
| 275 | − }), | |
| 276 | − }); | |
| 43 | + runtimeLocalScope?: unknown; | |
| 44 | +}): ToolMap => { | |
| 45 | + void input; | |
| 46 | + return {}; | |
| 47 | +}; | |
| @@ -1,64 +0,0 @@ | ||
| 1 | −import * as Schema from "effect/Schema"; | |
| 2 | − | |
| 3 | −import { | |
| 4 | − createSourceAdapterComposition, | |
| 5 | − type SourceAdapter, | |
| 6 | −} from "@executor/source-core"; | |
| 7 | −import { | |
| 8 | − externalSourceAdapters, | |
| 9 | −} from "@executor/source-builtins"; | |
| 10 | − | |
| 11 | −import { | |
| 12 | − internalSourceAdapter, | |
| 13 | −} from "./internal"; | |
| 14 | − | |
| 15 | −type DisabledSourcePluginPayload = { | |
| 16 | − __sourcePluginRegistrationRequired?: true; | |
| 17 | − [key: string]: unknown; | |
| 18 | −}; | |
| 19 | − | |
| 20 | −export type * from "@executor/source-core"; | |
| 21 | − | |
| 22 | −export const builtInSourceAdapters = [ | |
| 23 | − ...externalSourceAdapters, | |
| 24 | − internalSourceAdapter, | |
| 25 | −] as const satisfies readonly SourceAdapter[]; | |
| 26 | −const composition = createSourceAdapterComposition(builtInSourceAdapters); | |
| 27 | − | |
| 28 | −export const connectableSourceAdapters = composition.connectableSourceAdapters; | |
| 29 | −export const ConnectSourcePayloadSchema = | |
| 30 | − composition.connectPayloadSchema as unknown as Schema.Schema< | |
| 31 | − typeof composition.connectPayloadSchema.Type | DisabledSourcePluginPayload, | |
| 32 | − any, | |
| 33 | − never | |
| 34 | − >; | |
| 35 | −export type ConnectSourcePayload = typeof ConnectSourcePayloadSchema.Type; | |
| 36 | − | |
| 37 | −export const executorAddableSourceAdapters = composition.executorAddableSourceAdapters; | |
| 38 | −export const ExecutorAddSourceInputSchema = | |
| 39 | − composition.executorAddInputSchema as unknown as Schema.Schema< | |
| 40 | − typeof composition.executorAddInputSchema.Type | DisabledSourcePluginPayload, | |
| 41 | − any, | |
| 42 | − never | |
| 43 | − >; | |
| 44 | −export type ExecutorAddSourceInput = typeof ExecutorAddSourceInputSchema.Type; | |
| 45 | − | |
| 46 | −export const localConfigurableSourceAdapters = composition.localConfigurableSourceAdapters; | |
| 47 | −export const hasRegisteredConnectableSourceAdapters = | |
| 48 | − connectableSourceAdapters.length > 0; | |
| 49 | −export const hasRegisteredExecutorAddableSourceAdapters = | |
| 50 | − executorAddableSourceAdapters.length > 0; | |
| 51 | −export const hasRegisteredExternalSourceAdapters = | |
| 52 | − hasRegisteredConnectableSourceAdapters | |
| 53 | − || hasRegisteredExecutorAddableSourceAdapters; | |
| 54 | − | |
| 55 | −export const getSourceAdapter = composition.getSourceAdapter; | |
| 56 | −export const getSourceAdapterForSource = composition.getSourceAdapterForSource; | |
| 57 | −export const findSourceAdapterByProviderKey = composition.findSourceAdapterByProviderKey; | |
| 58 | −export const sourceBindingStateFromSource = composition.sourceBindingStateFromSource; | |
| 59 | −export const sourceAdapterCatalogKind = composition.sourceAdapterCatalogKind; | |
| 60 | −export const sourceAdapterRequiresInteractiveConnect = | |
| 61 | − composition.sourceAdapterRequiresInteractiveConnect; | |
| 62 | −export const sourceAdapterUsesCredentialManagedAuth = | |
| 63 | − composition.sourceAdapterUsesCredentialManagedAuth; | |
| 64 | −export const isInternalSourceAdapter = composition.isInternalSourceAdapter; | |
| @@ -1,131 +0,0 @@ | ||
| 1 | −import * as Effect from "effect/Effect"; | |
| 2 | −import * as Schema from "effect/Schema"; | |
| 3 | −import { | |
| 4 | − createSourceCatalogSyncResult, | |
| 5 | − createCatalogImportMetadata, | |
| 6 | − decodeBindingConfig, | |
| 7 | − decodeSourceBindingPayload, | |
| 8 | − emptySourceBindingState, | |
| 9 | − encodeBindingConfig, | |
| 10 | − type Source, | |
| 11 | − type SourceAdapter, | |
| 12 | −} from "@executor/source-core"; | |
| 13 | −import { | |
| 14 | − runtimeEffectError, | |
| 15 | −} from "../../effect-errors"; | |
| 16 | − | |
| 17 | −const InternalBindingConfigSchema = Schema.Struct({}); | |
| 18 | − | |
| 19 | −const INTERNAL_BINDING_CONFIG_VERSION = 1; | |
| 20 | − | |
| 21 | −const bindingHasAnyField = ( | |
| 22 | − value: unknown, | |
| 23 | − fields: readonly string[], | |
| 24 | −): boolean => | |
| 25 | − value !== null && | |
| 26 | − typeof value === "object" && | |
| 27 | − !Array.isArray(value) && | |
| 28 | − fields.some((field) => Object.prototype.hasOwnProperty.call(value, field)); | |
| 29 | − | |
| 30 | −const internalBindingConfigFromSource = ( | |
| 31 | − source: Pick<Source, "id" | "bindingVersion" | "binding">, | |
| 32 | −) => | |
| 33 | − Effect.gen(function* () { | |
| 34 | − if ( | |
| 35 | − bindingHasAnyField(source.binding, [ | |
| 36 | − "specUrl", | |
| 37 | − "defaultHeaders", | |
| 38 | − "transport", | |
| 39 | − "queryParams", | |
| 40 | − "headers", | |
| 41 | − ]) | |
| 42 | − ) { | |
| 43 | − return yield* runtimeEffectError("sources/source-adapters/internal", "internal sources cannot define HTTP source settings"); | |
| 44 | − } | |
| 45 | − | |
| 46 | − return yield* decodeSourceBindingPayload({ | |
| 47 | − sourceId: source.id, | |
| 48 | − label: "internal", | |
| 49 | − version: source.bindingVersion, | |
| 50 | − expectedVersion: INTERNAL_BINDING_CONFIG_VERSION, | |
| 51 | − schema: InternalBindingConfigSchema, | |
| 52 | − value: source.binding, | |
| 53 | − allowedKeys: [], | |
| 54 | − }); | |
| 55 | − }); | |
| 56 | − | |
| 57 | −export const internalSourceAdapter = { | |
| 58 | − key: "internal", | |
| 59 | − displayName: "Internal", | |
| 60 | − catalogKind: "internal", | |
| 61 | − connectStrategy: "none", | |
| 62 | − credentialStrategy: "none", | |
| 63 | − bindingConfigVersion: INTERNAL_BINDING_CONFIG_VERSION, | |
| 64 | − providerKey: "generic_internal", | |
| 65 | − defaultImportAuthPolicy: "none", | |
| 66 | − connectPayloadSchema: null, | |
| 67 | − executorAddInputSchema: null, | |
| 68 | − executorAddHelpText: null, | |
| 69 | − executorAddInputSignatureWidth: null, | |
| 70 | − localConfigBindingSchema: null, | |
| 71 | − localConfigBindingFromSource: () => null, | |
| 72 | − serializeBindingConfig: (source) => | |
| 73 | − encodeBindingConfig({ | |
| 74 | − adapterKey: source.kind, | |
| 75 | − version: INTERNAL_BINDING_CONFIG_VERSION, | |
| 76 | − payloadSchema: InternalBindingConfigSchema, | |
| 77 | − payload: Effect.runSync(internalBindingConfigFromSource(source)), | |
| 78 | − }), | |
| 79 | − deserializeBindingConfig: ({ id, bindingConfigJson }) => | |
| 80 | − Effect.map( | |
| 81 | − decodeBindingConfig({ | |
| 82 | − sourceId: id, | |
| 83 | − label: "internal", | |
| 84 | − adapterKey: "internal", | |
| 85 | − version: INTERNAL_BINDING_CONFIG_VERSION, | |
| 86 | − payloadSchema: InternalBindingConfigSchema, | |
| 87 | − value: bindingConfigJson, | |
| 88 | − }), | |
| 89 | − ({ version, payload }) => ({ | |
| 90 | − version, | |
| 91 | − payload, | |
| 92 | − }), | |
| 93 | − ), | |
| 94 | − bindingStateFromSource: () => Effect.succeed(emptySourceBindingState), | |
| 95 | − sourceConfigFromSource: (source) => ({ | |
| 96 | − kind: "internal", | |
| 97 | − endpoint: source.endpoint, | |
| 98 | − }), | |
| 99 | − validateSource: (source) => | |
| 100 | − Effect.gen(function* () { | |
| 101 | − yield* internalBindingConfigFromSource(source); | |
| 102 | − | |
| 103 | − return { | |
| 104 | − ...source, | |
| 105 | − bindingVersion: INTERNAL_BINDING_CONFIG_VERSION, | |
| 106 | − binding: {}, | |
| 107 | − }; | |
| 108 | − }), | |
| 109 | − shouldAutoProbe: () => false, | |
| 110 | − syncCatalog: ({ source }) => | |
| 111 | − Effect.succeed( | |
| 112 | − createSourceCatalogSyncResult({ | |
| 113 | − fragment: { | |
| 114 | − version: "ir.v1.fragment", | |
| 115 | − }, | |
| 116 | − importMetadata: { | |
| 117 | − ...createCatalogImportMetadata({ | |
| 118 | − source, | |
| 119 | − adapterKey: "internal", | |
| 120 | − }), | |
| 121 | − importerVersion: "ir.v1.internal", | |
| 122 | − sourceConfigHash: "internal", | |
| 123 | − }, | |
| 124 | − sourceHash: null, | |
| 125 | − }), | |
| 126 | − ), | |
| 127 | − invoke: () => | |
| 128 | − Effect.fail( | |
| 129 | − runtimeEffectError("sources/source-adapters/internal", "Internal sources do not support persisted adapter invocation"), | |
| 130 | − ), | |
| 131 | −} satisfies SourceAdapter; | |
| @@ -1,219 +0,0 @@ | ||
| 1 | −import type { | |
| 2 | − CredentialSlot, | |
| 3 | − SecretRef, | |
| 4 | −} from "@executor/source-core"; | |
| 5 | −import { | |
| 6 | − type ScopeId, | |
| 7 | − type Source, | |
| 8 | − type SourceAuthSession, | |
| 9 | − SourceAuthSessionIdSchema, | |
| 10 | − SourceSchema, | |
| 11 | −} from "#schema"; | |
| 12 | −import * as Context from "effect/Context"; | |
| 13 | −import * as Effect from "effect/Effect"; | |
| 14 | −import * as Layer from "effect/Layer"; | |
| 15 | −import * as Schema from "effect/Schema"; | |
| 16 | − | |
| 17 | −import { | |
| 18 | − LiveExecutionManagerService, | |
| 19 | − type LiveExecutionManager, | |
| 20 | −} from "../execution/live"; | |
| 21 | −import { | |
| 22 | − getRuntimeLocalScopeOption, | |
| 23 | − provideOptionalRuntimeLocalScope, | |
| 24 | − type RuntimeLocalScopeState, | |
| 25 | −} from "../scope/runtime-context"; | |
| 26 | −import { | |
| 27 | − type DeleteSecretMaterial, | |
| 28 | − type ResolveSecretMaterial, | |
| 29 | − SecretMaterialDeleterService, | |
| 30 | − SecretMaterialResolverService, | |
| 31 | − SecretMaterialStorerService, | |
| 32 | − type StoreSecretMaterial, | |
| 33 | −} from "../scope/secret-material-providers"; | |
| 34 | −import { | |
| 35 | − RuntimeSourceCatalogSyncService, | |
| 36 | − type RuntimeSourceCatalogSyncShape, | |
| 37 | −} from "../catalog/source/sync"; | |
| 38 | −import { | |
| 39 | − type RuntimeSourceStore, | |
| 40 | − RuntimeSourceStoreService, | |
| 41 | −} from "./source-store"; | |
| 42 | −import type { | |
| 43 | − ScopeStorageServices, | |
| 44 | −} from "../scope/storage"; | |
| 45 | −import { | |
| 46 | − ExecutorStateStore, | |
| 47 | − type ExecutorStateStoreShape, | |
| 48 | −} from "../executor-state-store"; | |
| 49 | −import { | |
| 50 | − runtimeEffectError, | |
| 51 | −} from "../effect-errors"; | |
| 52 | −import type { | |
| 53 | − ExecutorAddSourceInput as RegisteredExecutorAddSourceInput, | |
| 54 | −} from "./source-adapters"; | |
| 55 | − | |
| 56 | −const SOURCE_PLUGINS_REMOVED_MESSAGE = | |
| 57 | − "Source plugins and legacy source adapters have been removed from this build."; | |
| 58 | − | |
| 59 | −const sourcePluginsRemovedError = ( | |
| 60 | − operation: string, | |
| 61 | −) => runtimeEffectError("sources/source-auth-service", `${operation}: ${SOURCE_PLUGINS_REMOVED_MESSAGE}`); | |
| 62 | − | |
| 63 | −const disabledSourcePlugins = <A>( | |
| 64 | − operation: string, | |
| 65 | −): Effect.Effect<A, Error, never> => | |
| 66 | − Effect.fail(sourcePluginsRemovedError(operation)); | |
| 67 | − | |
| 68 | −export type ExecutorSourceAddResult = | |
| 69 | − | { | |
| 70 | − kind: "connected"; | |
| 71 | − source: Source; | |
| 72 | − } | |
| 73 | − | { | |
| 74 | − kind: "credential_required"; | |
| 75 | − source: Source; | |
| 76 | − credentialSlot: CredentialSlot; | |
| 77 | − } | |
| 78 | − | { | |
| 79 | − kind: "oauth_required"; | |
| 80 | − source: Source; | |
| 81 | − sessionId: SourceAuthSession["id"]; | |
| 82 | − authorizationUrl: string; | |
| 83 | − }; | |
| 84 | − | |
| 85 | −export type ExecutorAddSourceInput = RegisteredExecutorAddSourceInput & { | |
| 86 | − scopeId: ScopeId; | |
| 87 | − actorScopeId?: ScopeId | null; | |
| 88 | − executionId: SourceAuthSession["executionId"]; | |
| 89 | − interactionId: SourceAuthSession["interactionId"]; | |
| 90 | −}; | |
| 91 | − | |
| 92 | −export type CompleteSourceCredentialSetupResult = { | |
| 93 | − sessionId: SourceAuthSession["id"]; | |
| 94 | − source: Source; | |
| 95 | −}; | |
| 96 | − | |
| 97 | −type RuntimeSourceAuthServiceShape = { | |
| 98 | − getSourceById: (input: { | |
| 99 | − scopeId: ScopeId; | |
| 100 | − sourceId: Source["id"]; | |
| 101 | − actorScopeId?: ScopeId | null; | |
| 102 | − }) => Effect.Effect<Source, Error, ScopeStorageServices>; | |
| 103 | − getLocalServerBaseUrl: () => string | null; | |
| 104 | − storeSecretMaterial: (input: { | |
| 105 | − purpose: Parameters<StoreSecretMaterial>[0]["purpose"]; | |
| 106 | − value: string; | |
| 107 | − }) => Effect.Effect<SecretRef, Error, never>; | |
| 108 | − addExecutorSource: ( | |
| 109 | − input: ExecutorAddSourceInput, | |
| 110 | − options?: { | |
| 111 | − mcpDiscoveryElicitation?: unknown; | |
| 112 | − baseUrl?: string | null; | |
| 113 | − }, | |
| 114 | − ) => Effect.Effect<ExecutorSourceAddResult, Error, ScopeStorageServices>; | |
| 115 | − completeSourceCredentialSetup: (input: { | |
| 116 | − scopeId: ScopeId; | |
| 117 | − sourceId: Source["id"]; | |
| 118 | − actorScopeId?: ScopeId | null; | |
| 119 | − state: string; | |
| 120 | − code?: string | null; | |
| 121 | − error?: string | null; | |
| 122 | − errorDescription?: string | null; | |
| 123 | − }) => Effect.Effect<CompleteSourceCredentialSetupResult, Error, ScopeStorageServices>; | |
| 124 | −}; | |
| 125 | − | |
| 126 | −type RuntimeSourceAuthDependencies = { | |
| 127 | − executorState: ExecutorStateStoreShape; | |
| 128 | − liveExecutionManager: LiveExecutionManager; | |
| 129 | − sourceStore: RuntimeSourceStore; | |
| 130 | − sourceCatalogSync: RuntimeSourceCatalogSyncShape; | |
| 131 | − resolveSecretMaterial: ResolveSecretMaterial; | |
| 132 | − storeSecretMaterial: StoreSecretMaterial; | |
| 133 | − deleteSecretMaterial: DeleteSecretMaterial; | |
| 134 | − getLocalServerBaseUrl?: () => string | undefined; | |
| 135 | − localScopeState?: RuntimeLocalScopeState; | |
| 136 | −}; | |
| 137 | − | |
| 138 | −export const createRuntimeSourceAuthService = ( | |
| 139 | − input: RuntimeSourceAuthDependencies, | |
| 140 | −): RuntimeSourceAuthService => { | |
| 141 | − const provideLocalWorkspace = <A, E, R>(effect: Effect.Effect<A, E, R>) => | |
| 142 | − provideOptionalRuntimeLocalScope(effect, input.localScopeState); | |
| 143 | − | |
| 144 | − return { | |
| 145 | − getSourceById: ({ scopeId, sourceId, actorScopeId }) => | |
| 146 | − provideLocalWorkspace( | |
| 147 | − input.sourceStore.loadSourceById({ | |
| 148 | − scopeId, | |
| 149 | − sourceId, | |
| 150 | − actorScopeId, | |
| 151 | − }), | |
| 152 | − ), | |
| 153 | − getLocalServerBaseUrl: () => input.getLocalServerBaseUrl?.() ?? null, | |
| 154 | − storeSecretMaterial: ({ purpose, value }) => | |
| 155 | − input.storeSecretMaterial({ | |
| 156 | − purpose, | |
| 157 | − value, | |
| 158 | − }), | |
| 159 | − addExecutorSource: () => | |
| 160 | − provideLocalWorkspace(disabledSourcePlugins("addExecutorSource")), | |
| 161 | − completeSourceCredentialSetup: () => | |
| 162 | − provideLocalWorkspace(disabledSourcePlugins("completeSourceCredentialSetup")), | |
| 163 | − }; | |
| 164 | −}; | |
| 165 | − | |
| 166 | −export type RuntimeSourceAuthService = RuntimeSourceAuthServiceShape; | |
| 167 | − | |
| 168 | −export class RuntimeSourceAuthServiceTag extends Context.Tag( | |
| 169 | − "#runtime/RuntimeSourceAuthServiceTag", | |
| 170 | −)<RuntimeSourceAuthServiceTag, RuntimeSourceAuthService>() {} | |
| 171 | − | |
| 172 | −export const RuntimeSourceAuthServiceLive = (input: { | |
| 173 | − getLocalServerBaseUrl?: () => string | undefined; | |
| 174 | −} = {}) => | |
| 175 | − Layer.effect( | |
| 176 | − RuntimeSourceAuthServiceTag, | |
| 177 | − Effect.gen(function* () { | |
| 178 | − const executorState = yield* ExecutorStateStore; | |
| 179 | − const liveExecutionManager = yield* LiveExecutionManagerService; | |
| 180 | − const sourceStore = yield* RuntimeSourceStoreService; | |
| 181 | − const sourceCatalogSync = yield* RuntimeSourceCatalogSyncService; | |
| 182 | − const resolveSecretMaterial = yield* SecretMaterialResolverService; | |
| 183 | − const storeSecretMaterial = yield* SecretMaterialStorerService; | |
| 184 | − const deleteSecretMaterial = yield* SecretMaterialDeleterService; | |
| 185 | − const runtimeLocalScope = yield* getRuntimeLocalScopeOption(); | |
| 186 | − | |
| 187 | − return createRuntimeSourceAuthService({ | |
| 188 | − executorState, | |
| 189 | − liveExecutionManager, | |
| 190 | − sourceStore, | |
| 191 | − sourceCatalogSync, | |
| 192 | − resolveSecretMaterial, | |
| 193 | − storeSecretMaterial, | |
| 194 | − deleteSecretMaterial, | |
| 195 | − getLocalServerBaseUrl: input.getLocalServerBaseUrl, | |
| 196 | − localScopeState: runtimeLocalScope ?? undefined, | |
| 197 | − }); | |
| 198 | − }), | |
| 199 | − ); | |
| 200 | − | |
| 201 | −export const ExecutorAddSourceResultSchema = Schema.Union( | |
| 202 | − Schema.Struct({ | |
| 203 | − kind: Schema.Literal("connected"), | |
| 204 | − source: SourceSchema, | |
| 205 | − }), | |
| 206 | − Schema.Struct({ | |
| 207 | − kind: Schema.Literal("credential_required"), | |
| 208 | − source: SourceSchema, | |
| 209 | − credentialSlot: Schema.Literal("runtime", "import"), | |
| 210 | − }), | |
| 211 | − Schema.Struct({ | |
| 212 | − kind: Schema.Literal("oauth_required"), | |
| 213 | − source: SourceSchema, | |
| 214 | − sessionId: SourceAuthSessionIdSchema, | |
| 215 | − authorizationUrl: Schema.String, | |
| 216 | − }), | |
| 217 | −); | |
| 218 | − | |
| 219 | −export type ExecutorAddSourceResult = typeof ExecutorAddSourceResultSchema.Type; | |
| @@ -1,44 +1,22 @@ | ||
| 1 | −import { | |
| 2 | − sha256Hex, | |
| 3 | −} from "@executor/codemode-core"; | |
| 1 | +import { sha256Hex } from "@executor/codemode-core"; | |
| 4 | 2 | |
| 5 | −import type { | |
| 6 | − CreateSourcePayload, | |
| 7 | − UpdateSourcePayload, | |
| 8 | −} from "../../sources/contracts"; | |
| 9 | 3 | import type { |
| 10 | 4 | ScopeId, |
| 11 | − AuthArtifact, | |
| 12 | 5 | Source, |
| 13 | − SourceAuth, | |
| 14 | − SourceImportAuthPolicy, | |
| 15 | − SourceCatalogAdapterKey, | |
| 16 | 6 | SourceCatalogId, |
| 17 | 7 | SourceCatalogKind, |
| 8 | + SourceCatalogPluginKey, | |
| 18 | 9 | SourceCatalogRevisionId, |
| 19 | − StoredSourceRecord, | |
| 20 | 10 | StoredSourceCatalogRecord, |
| 21 | 11 | StoredSourceCatalogRevisionRecord, |
| 22 | 12 | } from "#schema"; |
| 23 | 13 | import { |
| 24 | − AuthArtifactIdSchema, | |
| 25 | − ProviderAuthGrantIdSchema, | |
| 26 | 14 | SourceCatalogIdSchema, |
| 27 | 15 | SourceCatalogRevisionIdSchema, |
| 28 | 16 | } from "#schema"; |
| 29 | 17 | import * as Effect from "effect/Effect"; |
| 30 | 18 | |
| 31 | −import { | |
| 32 | − getSourceAdapter, | |
| 33 | − getSourceAdapterForSource, | |
| 34 | −} from "./source-adapters"; | |
| 35 | −import { | |
| 36 | − authArtifactFromSourceAuth, | |
| 37 | − sourceAuthFromAuthArtifact, | |
| 38 | −} from "../auth/auth-artifacts"; | |
| 39 | −import { | |
| 40 | − runtimeEffectError, | |
| 41 | −} from "../effect-errors"; | |
| 19 | +import { getSourcePluginForSource } from "./source-plugins"; | |
| 42 | 20 | |
| 43 | 21 | const trimOrNull = (value: string | null | undefined): string | null => { |
| 44 | 22 | if (value === null || value === undefined) { |
| @@ -52,20 +30,19 @@ const trimOrNull = (value: string | null | undefined): string | null => { · 7 unmodified lines | ||
| 52 | 30 | type SourceCatalogSourceConfig = Record<string, unknown>; |
| 53 | 31 | |
| 54 | 32 | const sourceConfigFromSource = (source: Source): SourceCatalogSourceConfig => |
| 55 | − getSourceAdapterForSource(source).sourceConfigFromSource(source); | |
| 33 | + getSourcePluginForSource(source).catalogIdentity?.({ | |
| 34 | + source, | |
| 35 | + }) ?? { | |
| 36 | + kind: source.kind, | |
| 37 | + endpoint: source.endpoint, | |
| 38 | + namespace: source.namespace, | |
| 39 | + }; | |
| 56 | 40 | |
| 57 | −const sourceCatalogKindFromSource = (source: Source): SourceCatalogKind => { | |
| 58 | − const adapter = getSourceAdapterForSource(source); | |
| 59 | − return adapter.catalogKind; | |
| 60 | −}; | |
| 41 | +const sourceCatalogKindFromSource = (source: Source): SourceCatalogKind => | |
| 42 | + getSourcePluginForSource(source).catalogKind; | |
| 61 | 43 | |
| 62 | −const sourceCatalogAdapterKeyFromSource = (source: Source): SourceCatalogAdapterKey => { | |
| 63 | − return getSourceAdapterForSource(source).key; | |
| 64 | −}; | |
| 65 | − | |
| 66 | −const sourceCatalogProviderKeyFromSource = (source: Source): string => { | |
| 67 | − return getSourceAdapterForSource(source).providerKey; | |
| 68 | −}; | |
| 44 | +const sourceCatalogPluginKeyFromSource = (source: Source): SourceCatalogPluginKey => | |
| 45 | + getSourcePluginForSource(source).kind; | |
| 69 | 46 | |
| 70 | 47 | const stableHash = (value: string): string => |
| 71 | 48 | sha256Hex(value).slice(0, 24); |
| @@ -73,13 +50,21 @@ const stableHash = (value: string): string => · 1 unmodified line | ||
| 73 | 50 | const sourceCatalogSignature = (source: Source): string => |
| 74 | 51 | JSON.stringify({ |
| 75 | 52 | catalogKind: sourceCatalogKindFromSource(source), |
| 76 | − adapterKey: sourceCatalogAdapterKeyFromSource(source), | |
| 77 | − providerKey: sourceCatalogProviderKeyFromSource(source), | |
| 53 | + pluginKey: sourceCatalogPluginKeyFromSource(source), | |
| 54 | + sourceId: source.id, | |
| 78 | 55 | sourceConfig: sourceConfigFromSource(source), |
| 79 | 56 | }); |
| 80 | 57 | |
| 81 | 58 | export const sourceConfigSignature = (source: Source): string => |
| 82 | − JSON.stringify(sourceConfigFromSource(source)); | |
| 59 | + JSON.stringify({ | |
| 60 | + sourceId: source.id, | |
| 61 | + kind: source.kind, | |
| 62 | + name: source.name, | |
| 63 | + endpoint: source.endpoint, | |
| 64 | + namespace: source.namespace, | |
| 65 | + enabled: source.enabled, | |
| 66 | + updatedAt: source.updatedAt, | |
| 67 | + }); | |
| 83 | 68 | |
| 84 | 69 | export const stableSourceCatalogId = (source: Source): SourceCatalogId => |
| 85 | 70 | SourceCatalogIdSchema.make(`src_catalog_${stableHash(sourceCatalogSignature(source))}`); |
| @@ -89,280 +74,45 @@ export const stableSourceCatalogRevisionId = ( · 3 unmodified lines | ||
| 89 | 74 | ): SourceCatalogRevisionId => |
| 90 | 75 | SourceCatalogRevisionIdSchema.make(`src_catalog_rev_${stableHash(sourceConfigSignature(source))}`); |
| 91 | 76 | |
| 92 | −const normalizeAuth = ( | |
| 93 | − auth: SourceAuth | undefined, | |
| 94 | −): Effect.Effect<SourceAuth, Error, never> => | |
| 95 | − Effect.gen(function* () { | |
| 96 | − if (auth === undefined || auth.kind === "none") { | |
| 97 | − return { kind: "none" } satisfies SourceAuth; | |
| 98 | − } | |
| 99 | − | |
| 100 | − if (auth.kind === "bearer") { | |
| 101 | − const headerName = trimOrNull(auth.headerName) ?? "Authorization"; | |
| 102 | − const prefix = auth.prefix ?? "Bearer "; | |
| 103 | − const providerId = trimOrNull(auth.token.providerId); | |
| 104 | − const handle = trimOrNull(auth.token.handle); | |
| 105 | − if (providerId === null || handle === null) { | |
| 106 | − return yield* runtimeEffectError("sources/source-definitions", "Bearer auth requires a token secret ref"); | |
| 107 | − } | |
| 108 | − | |
| 109 | − return { | |
| 110 | − kind: "bearer", | |
| 111 | − headerName, | |
| 112 | − prefix, | |
| 113 | − token: { | |
| 114 | − providerId, | |
| 115 | − handle, | |
| 116 | − }, | |
| 117 | − } satisfies SourceAuth; | |
| 118 | − } | |
| 119 | − | |
| 120 | − if (auth.kind === "oauth2_authorized_user") { | |
| 121 | − const headerName = trimOrNull(auth.headerName) ?? "Authorization"; | |
| 122 | − const prefix = auth.prefix ?? "Bearer "; | |
| 123 | − const refreshProviderId = trimOrNull(auth.refreshToken.providerId); | |
| 124 | − const refreshHandle = trimOrNull(auth.refreshToken.handle); | |
| 125 | − if (refreshProviderId === null || refreshHandle === null) { | |
| 126 | − return yield* runtimeEffectError("sources/source-definitions", "OAuth2 authorized-user auth requires a refresh token secret ref"); | |
| 127 | − } | |
| 128 | − | |
| 129 | − let clientSecret: { providerId: string; handle: string } | null = null; | |
| 130 | − if (auth.clientSecret !== null) { | |
| 131 | − const clientSecretProviderId = trimOrNull(auth.clientSecret.providerId); | |
| 132 | − const clientSecretHandle = trimOrNull(auth.clientSecret.handle); | |
| 133 | − if (clientSecretProviderId === null || clientSecretHandle === null) { | |
| 134 | − return yield* runtimeEffectError("sources/source-definitions", "OAuth2 authorized-user client secret ref must include providerId and handle"); | |
| 135 | − } | |
| 136 | − clientSecret = { | |
| 137 | − providerId: clientSecretProviderId, | |
| 138 | − handle: clientSecretHandle, | |
| 139 | − }; | |
| 140 | − } | |
| 141 | − | |
| 142 | − const tokenEndpoint = trimOrNull(auth.tokenEndpoint); | |
| 143 | − const clientId = trimOrNull(auth.clientId); | |
| 144 | − if (tokenEndpoint === null || clientId === null) { | |
| 145 | − return yield* runtimeEffectError("sources/source-definitions", "OAuth2 authorized-user auth requires tokenEndpoint and clientId"); | |
| 146 | − } | |
| 147 | − | |
| 148 | − return { | |
| 149 | − kind: "oauth2_authorized_user", | |
| 150 | − headerName, | |
| 151 | − prefix, | |
| 152 | − tokenEndpoint, | |
| 153 | − clientId, | |
| 154 | − clientAuthentication: auth.clientAuthentication, | |
| 155 | − clientSecret, | |
| 156 | − refreshToken: { | |
| 157 | − providerId: refreshProviderId, | |
| 158 | − handle: refreshHandle, | |
| 159 | − }, | |
| 160 | − grantSet: auth.grantSet ?? null, | |
| 161 | − } satisfies SourceAuth; | |
| 162 | − } | |
| 163 | − | |
| 164 | − if (auth.kind === "provider_grant_ref") { | |
| 165 | − const headerName = trimOrNull(auth.headerName) ?? "Authorization"; | |
| 166 | − const prefix = auth.prefix ?? "Bearer "; | |
| 167 | − const grantId = trimOrNull(auth.grantId); | |
| 168 | − if (grantId === null) { | |
| 169 | − return yield* runtimeEffectError("sources/source-definitions", "Provider grant auth requires a grantId"); | |
| 170 | − } | |
| 171 | − | |
| 172 | − return { | |
| 173 | − kind: "provider_grant_ref", | |
| 174 | − grantId: ProviderAuthGrantIdSchema.make(grantId), | |
| 175 | − providerKey: trimOrNull(auth.providerKey) ?? "", | |
| 176 | − requiredScopes: auth.requiredScopes | |
| 177 | − .map((scope) => scope.trim()) | |
| 178 | − .filter((scope) => scope.length > 0), | |
| 179 | − headerName, | |
| 180 | − prefix, | |
| 181 | − } satisfies SourceAuth; | |
| 182 | − } | |
| 183 | − | |
| 184 | − if (auth.kind === "mcp_oauth") { | |
| 185 | − const redirectUri = trimOrNull(auth.redirectUri); | |
| 186 | − const accessProviderId = trimOrNull(auth.accessToken.providerId); | |
| 187 | − const accessHandle = trimOrNull(auth.accessToken.handle); | |
| 188 | − if (redirectUri === null || accessProviderId === null || accessHandle === null) { | |
| 189 | − return yield* runtimeEffectError("sources/source-definitions", "MCP OAuth auth requires redirectUri and access token secret ref"); | |
| 190 | − } | |
| 191 | − | |
| 192 | − let refreshToken: { providerId: string; handle: string } | null = null; | |
| 193 | − if (auth.refreshToken !== null) { | |
| 194 | − const refreshProviderId = trimOrNull(auth.refreshToken.providerId); | |
| 195 | − const refreshHandle = trimOrNull(auth.refreshToken.handle); | |
| 196 | − if (refreshProviderId === null || refreshHandle === null) { | |
| 197 | − return yield* runtimeEffectError("sources/source-definitions", "MCP OAuth refresh token ref must include providerId and handle"); | |
| 198 | − } | |
| 199 | − | |
| 200 | − refreshToken = { | |
| 201 | − providerId: refreshProviderId, | |
| 202 | − handle: refreshHandle, | |
| 203 | − }; | |
| 204 | − } | |
| 205 | − | |
| 206 | − const tokenType = trimOrNull(auth.tokenType) ?? "Bearer"; | |
| 207 | − | |
| 208 | − return { | |
| 209 | − kind: "mcp_oauth", | |
| 210 | − redirectUri, | |
| 211 | − accessToken: { | |
| 212 | − providerId: accessProviderId, | |
| 213 | − handle: accessHandle, | |
| 214 | − }, | |
| 215 | − refreshToken, | |
| 216 | − tokenType, | |
| 217 | − expiresIn: auth.expiresIn ?? null, | |
| 218 | − scope: trimOrNull(auth.scope), | |
| 219 | − resourceMetadataUrl: trimOrNull(auth.resourceMetadataUrl), | |
| 220 | − authorizationServerUrl: trimOrNull(auth.authorizationServerUrl), | |
| 221 | − resourceMetadataJson: trimOrNull(auth.resourceMetadataJson), | |
| 222 | − authorizationServerMetadataJson: trimOrNull(auth.authorizationServerMetadataJson), | |
| 223 | − clientInformationJson: trimOrNull(auth.clientInformationJson), | |
| 224 | − } satisfies SourceAuth; | |
| 225 | − } | |
| 226 | − | |
| 227 | − const headerName = trimOrNull(auth.headerName) ?? "Authorization"; | |
| 228 | − const prefix = auth.prefix ?? "Bearer "; | |
| 229 | − const accessProviderId = trimOrNull(auth.accessToken.providerId); | |
| 230 | − const accessHandle = trimOrNull(auth.accessToken.handle); | |
| 231 | − if (accessProviderId === null || accessHandle === null) { | |
| 232 | − return yield* runtimeEffectError("sources/source-definitions", "OAuth2 auth requires an access token secret ref"); | |
| 233 | − } | |
| 234 | − | |
| 235 | − let refreshToken: { providerId: string; handle: string } | null = null; | |
| 236 | − if (auth.refreshToken !== null) { | |
| 237 | − const refreshProviderId = trimOrNull(auth.refreshToken.providerId); | |
| 238 | − const refreshHandle = trimOrNull(auth.refreshToken.handle); | |
| 239 | − if (refreshProviderId === null || refreshHandle === null) { | |
| 240 | − return yield* runtimeEffectError("sources/source-definitions", "OAuth2 refresh token ref must include providerId and handle"); | |
| 241 | − } | |
| 242 | − | |
| 243 | − refreshToken = { | |
| 244 | − providerId: refreshProviderId, | |
| 245 | − handle: refreshHandle, | |
| 246 | − }; | |
| 247 | − } | |
| 248 | − | |
| 249 | − return { | |
| 250 | − kind: "oauth2", | |
| 251 | − headerName, | |
| 252 | − prefix, | |
| 253 | − accessToken: { | |
| 254 | − providerId: accessProviderId, | |
| 255 | − handle: accessHandle, | |
| 256 | − }, | |
| 257 | − refreshToken, | |
| 258 | − } satisfies SourceAuth; | |
| 259 | − }); | |
| 260 | − | |
| 261 | −const normalizeImportAuthPolicy = ( | |
| 262 | − sourceKind: Source["kind"], | |
| 263 | − policy: SourceImportAuthPolicy | undefined, | |
| 264 | −): SourceImportAuthPolicy => policy ?? getSourceAdapter(sourceKind).defaultImportAuthPolicy; | |
| 265 | − | |
| 266 | −const validateSourceImportAuth = (source: Source): Effect.Effect<Source, Error, never> => | |
| 267 | − Effect.gen(function* () { | |
| 268 | − if (source.importAuthPolicy !== "separate" && source.importAuth.kind !== "none") { | |
| 269 | − return yield* runtimeEffectError("sources/source-definitions", "importAuth must be none unless importAuthPolicy is separate"); | |
| 270 | − } | |
| 271 | − | |
| 272 | − return source; | |
| 273 | − }); | |
| 274 | − | |
| 275 | 77 | const validateSourceByKind = (source: Source): Effect.Effect<Source, Error, never> => |
| 276 | − Effect.flatMap( | |
| 277 | − validateSourceImportAuth(source), | |
| 278 | − (validated) => | |
| 279 | − Effect.map( | |
| 280 | − getSourceAdapterForSource(validated).validateSource(validated), | |
| 281 | − (result) => result as Source, | |
| 282 | − ), | |
| 283 | − ); | |
| 78 | + Effect.succeed(source); | |
| 284 | 79 | |
| 285 | −export const createSourceFromPayload = (input: { | |
| 80 | +export const normalizeSourceForCreate = (input: { | |
| 286 | 81 | scopeId: ScopeId; |
| 287 | 82 | sourceId: Source["id"]; |
| 288 | − payload: CreateSourcePayload; | |
| 83 | + source: Omit< | |
| 84 | + Source, | |
| 85 | + "id" | "scopeId" | "createdAt" | "updatedAt" | |
| 86 | + >; | |
| 289 | 87 | now: number; |
| 290 | 88 | }): Effect.Effect<Source, Error, never> => |
| 291 | − Effect.gen(function* () { | |
| 292 | − const auth = yield* normalizeAuth(input.payload.auth); | |
| 293 | − const importAuth = yield* normalizeAuth(input.payload.importAuth); | |
| 294 | − const importAuthPolicy = normalizeImportAuthPolicy( | |
| 295 | − input.payload.kind, | |
| 296 | − input.payload.importAuthPolicy, | |
| 297 | − ); | |
| 298 | − | |
| 299 | − return yield* validateSourceByKind({ | |
| 300 | − id: input.sourceId, | |
| 301 | − scopeId: input.scopeId, | |
| 302 | − name: input.payload.name.trim(), | |
| 303 | − kind: input.payload.kind, | |
| 304 | − endpoint: input.payload.endpoint.trim(), | |
| 305 | − status: input.payload.status ?? "draft", | |
| 306 | − enabled: input.payload.enabled ?? true, | |
| 307 | − namespace: trimOrNull(input.payload.namespace), | |
| 308 | − bindingVersion: getSourceAdapter(input.payload.kind).bindingConfigVersion, | |
| 309 | − binding: input.payload.binding ?? {}, | |
| 310 | − importAuthPolicy, | |
| 311 | − importAuth, | |
| 312 | − auth, | |
| 313 | − sourceHash: trimOrNull(input.payload.sourceHash), | |
| 314 | − lastError: trimOrNull(input.payload.lastError), | |
| 315 | − createdAt: input.now, | |
| 316 | − updatedAt: input.now, | |
| 317 | − }); | |
| 89 | + validateSourceByKind({ | |
| 90 | + id: input.sourceId, | |
| 91 | + scopeId: input.scopeId, | |
| 92 | + name: input.source.name.trim(), | |
| 93 | + kind: input.source.kind, | |
| 94 | + endpoint: input.source.endpoint.trim(), | |
| 95 | + status: input.source.status, | |
| 96 | + enabled: input.source.enabled, | |
| 97 | + namespace: trimOrNull(input.source.namespace), | |
| 98 | + sourceHash: trimOrNull(input.source.sourceHash), | |
| 99 | + lastError: trimOrNull(input.source.lastError), | |
| 100 | + createdAt: input.now, | |
| 101 | + updatedAt: input.now, | |
| 318 | 102 | }); |
| 319 | 103 | |
| 320 | −export const updateSourceFromPayload = (input: { | |
| 104 | +export const normalizeSourceForSave = (input: { | |
| 321 | 105 | source: Source; |
| 322 | − payload: UpdateSourcePayload; | |
| 323 | 106 | now: number; |
| 324 | 107 | }): Effect.Effect<Source, Error, never> => |
| 325 | − Effect.gen(function* () { | |
| 326 | − const nextAuth = input.payload.auth === undefined | |
| 327 | − ? input.source.auth | |
| 328 | − : yield* normalizeAuth(input.payload.auth); | |
| 329 | − const nextImportAuth = input.payload.importAuth === undefined | |
| 330 | − ? input.source.importAuth | |
| 331 | − : yield* normalizeAuth(input.payload.importAuth); | |
| 332 | − const nextImportAuthPolicy = normalizeImportAuthPolicy( | |
| 333 | − input.source.kind, | |
| 334 | − input.payload.importAuthPolicy ?? input.source.importAuthPolicy, | |
| 335 | − ); | |
| 336 | − | |
| 337 | − return yield* validateSourceByKind({ | |
| 338 | − ...input.source, | |
| 339 | − name: input.payload.name !== undefined ? input.payload.name.trim() : input.source.name, | |
| 340 | − endpoint: | |
| 341 | − input.payload.endpoint !== undefined | |
| 342 | − ? input.payload.endpoint.trim() | |
| 343 | − : input.source.endpoint, | |
| 344 | − status: input.payload.status ?? input.source.status, | |
| 345 | − enabled: input.payload.enabled ?? input.source.enabled, | |
| 346 | − namespace: input.payload.namespace !== undefined | |
| 347 | − ? trimOrNull(input.payload.namespace) | |
| 348 | − : input.source.namespace, | |
| 349 | − bindingVersion: input.payload.binding !== undefined | |
| 350 | − ? getSourceAdapter(input.source.kind).bindingConfigVersion | |
| 351 | − : input.source.bindingVersion, | |
| 352 | − binding: input.payload.binding !== undefined | |
| 353 | − ? input.payload.binding | |
| 354 | − : input.source.binding, | |
| 355 | − importAuthPolicy: nextImportAuthPolicy, | |
| 356 | − importAuth: nextImportAuth, | |
| 357 | − auth: nextAuth, | |
| 358 | − sourceHash: input.payload.sourceHash !== undefined | |
| 359 | − ? trimOrNull(input.payload.sourceHash) | |
| 360 | − : input.source.sourceHash, | |
| 361 | − lastError: input.payload.lastError !== undefined | |
| 362 | − ? trimOrNull(input.payload.lastError) | |
| 363 | − : input.source.lastError, | |
| 364 | − updatedAt: input.now, | |
| 365 | − }); | |
| 108 | + validateSourceByKind({ | |
| 109 | + ...input.source, | |
| 110 | + name: input.source.name.trim(), | |
| 111 | + endpoint: input.source.endpoint.trim(), | |
| 112 | + namespace: trimOrNull(input.source.namespace), | |
| 113 | + sourceHash: trimOrNull(input.source.sourceHash), | |
| 114 | + lastError: trimOrNull(input.source.lastError), | |
| 115 | + updatedAt: input.now, | |
| 366 | 116 | }); |
| 367 | 117 | |
| 368 | 118 | export const createSourceCatalogRecord = (input: { |
| @@ -372,8 +122,7 @@ export const createSourceCatalogRecord = (input: { · 3 unmodified lines | ||
| 372 | 122 | }): StoredSourceCatalogRecord => ({ |
| 373 | 123 | id: input.catalogId ?? stableSourceCatalogId(input.source), |
| 374 | 124 | kind: sourceCatalogKindFromSource(input.source), |
| 375 | − adapterKey: sourceCatalogAdapterKeyFromSource(input.source), | |
| 376 | − providerKey: sourceCatalogProviderKeyFromSource(input.source), | |
| 125 | + pluginKey: sourceCatalogPluginKeyFromSource(input.source), | |
| 377 | 126 | name: input.source.name, |
| 378 | 127 | summary: null, |
| 379 | 128 | visibility: "scope", |
| @@ -403,128 +152,3 @@ export const createSourceCatalogRevisionRecord = (input: { · 23 unmodified lines | ||
| 403 | 152 | createdAt: input.source.createdAt, |
| 404 | 153 | updatedAt: input.source.updatedAt, |
| 405 | 154 | }); |
| 406 | − | |
| 407 | −export const splitSourceForStorage = (input: { | |
| 408 | − source: Source; | |
| 409 | − catalogId: SourceCatalogId; | |
| 410 | − catalogRevisionId: SourceCatalogRevisionId; | |
| 411 | − actorScopeId?: ScopeId | null; | |
| 412 | − existingRuntimeAuthArtifactId?: AuthArtifact["id"] | null; | |
| 413 | − existingImportAuthArtifactId?: AuthArtifact["id"] | null; | |
| 414 | −}): { | |
| 415 | − sourceRecord: StoredSourceRecord; | |
| 416 | − runtimeAuthArtifact: AuthArtifact | null; | |
| 417 | − importAuthArtifact: AuthArtifact | null; | |
| 418 | −} => { | |
| 419 | − const sourceRecord: StoredSourceRecord = { | |
| 420 | − id: input.source.id, | |
| 421 | − scopeId: input.source.scopeId, | |
| 422 | − catalogId: input.catalogId, | |
| 423 | − catalogRevisionId: input.catalogRevisionId, | |
| 424 | − name: input.source.name, | |
| 425 | − kind: input.source.kind, | |
| 426 | − endpoint: input.source.endpoint, | |
| 427 | − status: input.source.status, | |
| 428 | − enabled: input.source.enabled, | |
| 429 | − namespace: input.source.namespace, | |
| 430 | − importAuthPolicy: input.source.importAuthPolicy, | |
| 431 | − bindingConfigJson: getSourceAdapterForSource(input.source).serializeBindingConfig(input.source), | |
| 432 | − sourceHash: input.source.sourceHash, | |
| 433 | − lastError: input.source.lastError, | |
| 434 | − createdAt: input.source.createdAt, | |
| 435 | − updatedAt: input.source.updatedAt, | |
| 436 | − }; | |
| 437 | − | |
| 438 | − return { | |
| 439 | − sourceRecord, | |
| 440 | − runtimeAuthArtifact: authArtifactFromSourceAuth({ | |
| 441 | − source: input.source, | |
| 442 | − auth: input.source.auth, | |
| 443 | − slot: "runtime", | |
| 444 | − actorScopeId: input.actorScopeId, | |
| 445 | − existingAuthArtifactId: input.existingRuntimeAuthArtifactId | |
| 446 | − ?? AuthArtifactIdSchema.make(`auth_art_${crypto.randomUUID()}`), | |
| 447 | − }), | |
| 448 | − importAuthArtifact: input.source.importAuthPolicy === "separate" | |
| 449 | − ? authArtifactFromSourceAuth({ | |
| 450 | − source: input.source, | |
| 451 | − auth: input.source.importAuth, | |
| 452 | − slot: "import", | |
| 453 | − actorScopeId: input.actorScopeId, | |
| 454 | − existingAuthArtifactId: input.existingImportAuthArtifactId | |
| 455 | − ?? AuthArtifactIdSchema.make(`auth_art_${crypto.randomUUID()}`), | |
| 456 | − }) | |
| 457 | − : null, | |
| 458 | − }; | |
| 459 | −}; | |
| 460 | − | |
| 461 | −export const projectSourceFromStorage = (input: { | |
| 462 | − sourceRecord: StoredSourceRecord; | |
| 463 | − runtimeAuthArtifact: AuthArtifact | null; | |
| 464 | − importAuthArtifact: AuthArtifact | null; | |
| 465 | −}): Effect.Effect<Source, Error, never> => | |
| 466 | − Effect.gen(function* () { | |
| 467 | − const adapter = getSourceAdapter(input.sourceRecord.kind); | |
| 468 | − const bindingConfig = yield* adapter.deserializeBindingConfig({ | |
| 469 | − id: input.sourceRecord.id, | |
| 470 | − bindingConfigJson: input.sourceRecord.bindingConfigJson, | |
| 471 | − }); | |
| 472 | − | |
| 473 | − return { | |
| 474 | − id: input.sourceRecord.id, | |
| 475 | − scopeId: input.sourceRecord.scopeId, | |
| 476 | − name: input.sourceRecord.name, | |
| 477 | − kind: input.sourceRecord.kind, | |
| 478 | − endpoint: input.sourceRecord.endpoint, | |
| 479 | − status: input.sourceRecord.status, | |
| 480 | − enabled: input.sourceRecord.enabled, | |
| 481 | − namespace: input.sourceRecord.namespace, | |
| 482 | − bindingVersion: bindingConfig.version, | |
| 483 | − binding: bindingConfig.payload, | |
| 484 | − importAuthPolicy: input.sourceRecord.importAuthPolicy, | |
| 485 | − importAuth: | |
| 486 | − input.sourceRecord.importAuthPolicy === "separate" | |
| 487 | − ? sourceAuthFromAuthArtifact(input.importAuthArtifact) | |
| 488 | − : { kind: "none" }, | |
| 489 | − auth: sourceAuthFromAuthArtifact(input.runtimeAuthArtifact), | |
| 490 | − sourceHash: input.sourceRecord.sourceHash, | |
| 491 | − lastError: input.sourceRecord.lastError, | |
| 492 | − createdAt: input.sourceRecord.createdAt, | |
| 493 | − updatedAt: input.sourceRecord.updatedAt, | |
| 494 | − } satisfies Source; | |
| 495 | − }).pipe( | |
| 496 | − Effect.mapError((cause) => | |
| 497 | − cause instanceof Error ? cause : new Error(String(cause)), | |
| 498 | − ), | |
| 499 | − ); | |
| 500 | − | |
| 501 | −export const projectSourcesFromStorage = (input: { | |
| 502 | − sourceRecords: ReadonlyArray<StoredSourceRecord>; | |
| 503 | − authArtifacts: ReadonlyArray<AuthArtifact>; | |
| 504 | −}): Effect.Effect<ReadonlyArray<Source>, Error, never> => { | |
| 505 | − const authArtifactsBySourceId = new Map<string, { | |
| 506 | − runtime: AuthArtifact | null; | |
| 507 | − import: AuthArtifact | null; | |
| 508 | − }>(); | |
| 509 | − | |
| 510 | − for (const authArtifact of input.authArtifacts) { | |
| 511 | − const existing = authArtifactsBySourceId.get(authArtifact.sourceId) ?? { | |
| 512 | − runtime: null, | |
| 513 | − import: null, | |
| 514 | − }; | |
| 515 | − const current = authArtifact.slot === "runtime" ? existing.runtime : existing.import; | |
| 516 | − if (current === null || (current.actorScopeId === null && authArtifact.actorScopeId !== null)) { | |
| 517 | − authArtifactsBySourceId.set(authArtifact.sourceId, { | |
| 518 | − ...existing, | |
| 519 | − [authArtifact.slot]: authArtifact, | |
| 520 | − }); | |
| 521 | − } | |
| 522 | − } | |
| 523 | − | |
| 524 | − return Effect.forEach(input.sourceRecords, (sourceRecord) => | |
| 525 | − projectSourceFromStorage({ | |
| 526 | − sourceRecord, | |
| 527 | − runtimeAuthArtifact: authArtifactsBySourceId.get(sourceRecord.id)?.runtime ?? null, | |
| 528 | − importAuthArtifact: authArtifactsBySourceId.get(sourceRecord.id)?.import ?? null, | |
| 529 | − })); | |
| 530 | −}; | |
| @@ -31,7 +31,7 @@ describe("source inspection", () => { · 30 unmodified lines | ||
| 31 | 31 | }, |
| 32 | 32 | executable: { |
| 33 | 33 | id: "exec_graphql_administrableTeams", |
| 34 | − adapterKey: "graphql", | |
| 34 | + pluginKey: "graphql", | |
| 35 | 35 | bindingVersion: 1, |
| 36 | 36 | binding: { |
| 37 | 37 | operationKind: "query", |
| @@ -0,0 +1,41 @@ | ||
| 1 | +import { | |
| 2 | + registerExecutorSdkPlugins, | |
| 3 | + type ExecutorSdkPlugin, | |
| 4 | +} from "../../../plugins"; | |
| 5 | + | |
| 6 | +import { | |
| 7 | + InternalSourceSdkPlugin, | |
| 8 | +} from "./internal"; | |
| 9 | + | |
| 10 | +let configuredExternalSourcePlugins: readonly ExecutorSdkPlugin[] = []; | |
| 11 | +let registry = registerExecutorSdkPlugins([ | |
| 12 | + InternalSourceSdkPlugin, | |
| 13 | +]); | |
| 14 | + | |
| 15 | +const refreshRegistry = () => { | |
| 16 | + registry = registerExecutorSdkPlugins([ | |
| 17 | + ...configuredExternalSourcePlugins, | |
| 18 | + InternalSourceSdkPlugin, | |
| 19 | + ]); | |
| 20 | +}; | |
| 21 | + | |
| 22 | +export const configureExecutorSourcePlugins = ( | |
| 23 | + plugins: readonly ExecutorSdkPlugin[], | |
| 24 | +): void => { | |
| 25 | + configuredExternalSourcePlugins = plugins; | |
| 26 | + refreshRegistry(); | |
| 27 | +}; | |
| 28 | + | |
| 29 | +export const registeredSourcePlugins = () => registry.sourcePlugins; | |
| 30 | + | |
| 31 | +export const getSourcePlugin = (kind: string) => registry.getSourcePlugin(kind); | |
| 32 | +export const getSourcePluginForSource = ( | |
| 33 | + source: Parameters<typeof registry.getSourcePluginForSource>[0], | |
| 34 | +) => registry.getSourcePluginForSource(source); | |
| 35 | +export const sourcePluginCatalogKind = (kind: string) => | |
| 36 | + registry.sourcePluginCatalogKind(kind); | |
| 37 | +export const isInternalSourcePluginKind = (kind: string) => | |
| 38 | + registry.isInternalSourcePluginKind(kind); | |
| 39 | + | |
| 40 | +export const hasRegisteredExternalSourcePlugins = () => | |
| 41 | + configuredExternalSourcePlugins.length > 0; | |
| @@ -0,0 +1,48 @@ | ||
| 1 | +import * as Effect from "effect/Effect"; | |
| 2 | + | |
| 3 | +import { | |
| 4 | + createCatalogImportMetadata, | |
| 5 | + createSourceCatalogSyncResult, | |
| 6 | +} from "@executor/source-core"; | |
| 7 | +import type { ExecutorSdkPlugin } from "../../../plugins"; | |
| 8 | + | |
| 9 | +import { runtimeEffectError } from "../../effect-errors"; | |
| 10 | + | |
| 11 | +export const InternalSourceSdkPlugin = { | |
| 12 | + key: "internal", | |
| 13 | + sources: [ | |
| 14 | + { | |
| 15 | + kind: "internal", | |
| 16 | + displayName: "Internal", | |
| 17 | + catalogKind: "internal", | |
| 18 | + catalogIdentity: ({ source }) => ({ | |
| 19 | + kind: "internal", | |
| 20 | + endpoint: source.endpoint, | |
| 21 | + }), | |
| 22 | + getIrModel: ({ source }) => | |
| 23 | + Effect.succeed( | |
| 24 | + createSourceCatalogSyncResult({ | |
| 25 | + fragment: { | |
| 26 | + version: "ir.v1.fragment", | |
| 27 | + }, | |
| 28 | + importMetadata: { | |
| 29 | + ...createCatalogImportMetadata({ | |
| 30 | + source, | |
| 31 | + pluginKey: "internal", | |
| 32 | + }), | |
| 33 | + importerVersion: "ir.v1.internal", | |
| 34 | + sourceConfigHash: "internal", | |
| 35 | + }, | |
| 36 | + sourceHash: null, | |
| 37 | + }), | |
| 38 | + ), | |
| 39 | + invoke: () => | |
| 40 | + Effect.fail( | |
| 41 | + runtimeEffectError( | |
| 42 | + "sources/source-plugins/internal", | |
| 43 | + "Internal sources do not support persisted plugin invocation", | |
| 44 | + ), | |
| 45 | + ), | |
| 46 | + }, | |
| 47 | + ], | |
| 48 | +} satisfies ExecutorSdkPlugin<"internal">; | |
| @@ -15,9 +15,6 @@ import { · 14 unmodified lines | ||
| 15 | 15 | ScopeConfigStore, |
| 16 | 16 | ScopeStateStore, |
| 17 | 17 | } from "../scope/storage"; |
| 18 | −import { | |
| 19 | − SecretMaterialDeleterService, | |
| 20 | −} from "../scope/secret-material-providers"; | |
| 21 | 18 | import { |
| 22 | 19 | RuntimeLocalScopeService, |
| 23 | 20 | } from "../scope/runtime-context"; |
| @@ -128,13 +125,11 @@ export const removeSourceById = ( · 104 unmodified lines | ||
| 128 | 125 | Error, |
| 129 | 126 | | ScopeStorageServices |
| 130 | 127 | | SourceTypeDeclarationsRefresherService |
| 131 | − | SecretMaterialDeleterService | |
| 132 | 128 | > => |
| 133 | − Effect.gen(function* () { | |
| 134 | − const deps = yield* loadRuntimeSourceStoreDeps(executorState, input.scopeId); | |
| 135 | − const deleteSecretMaterial = yield* SecretMaterialDeleterService; | |
| 136 | − return yield* removeSourceByIdWithDeps(deps, input, deleteSecretMaterial); | |
| 137 | − }); | |
| 129 | + Effect.flatMap( | |
| 130 | + loadRuntimeSourceStoreDeps(executorState, input.scopeId), | |
| 131 | + (deps) => removeSourceByIdWithDeps(deps, input), | |
| 132 | + ); | |
| 138 | 133 | |
| 139 | 134 | export const persistSource = ( |
| 140 | 135 | executorState: ExecutorStateStoreShape, |
| @@ -147,13 +142,11 @@ export const persistSource = ( · 6 unmodified lines | ||
| 147 | 142 | Error, |
| 148 | 143 | | ScopeStorageServices |
| 149 | 144 | | SourceTypeDeclarationsRefresherService |
| 150 | − | SecretMaterialDeleterService | |
| 151 | 145 | > => |
| 152 | − Effect.gen(function* () { | |
| 153 | − const deps = yield* loadRuntimeSourceStoreDeps(executorState, source.scopeId); | |
| 154 | − const deleteSecretMaterial = yield* SecretMaterialDeleterService; | |
| 155 | − return yield* persistSourceWithDeps(deps, source, options, deleteSecretMaterial); | |
| 156 | − }); | |
| 146 | + Effect.flatMap( | |
| 147 | + loadRuntimeSourceStoreDeps(executorState, source.scopeId), | |
| 148 | + (deps) => persistSourceWithDeps(deps, source, options), | |
| 149 | + ); | |
| 157 | 150 | |
| 158 | 151 | export class RuntimeSourceStoreService extends Context.Tag( |
| 159 | 152 | "#runtime/RuntimeSourceStoreService", |
| @@ -169,7 +162,6 @@ export const RuntimeSourceStoreLive = Layer.effect( · 9 unmodified lines | ||
| 169 | 162 | const sourceArtifactStore = yield* SourceArtifactStore; |
| 170 | 163 | const sourceTypeDeclarationsRefresher = |
| 171 | 164 | yield* SourceTypeDeclarationsRefresherService; |
| 172 | − const deleteSecretMaterial = yield* SecretMaterialDeleterService; | |
| 173 | 165 | |
| 174 | 166 | const deps: RuntimeSourceStoreDeps = { |
| 175 | 167 | executorState, |
| @@ -188,9 +180,9 @@ export const RuntimeSourceStoreLive = Layer.effect( · 12 unmodified lines | ||
| 188 | 180 | loadSourceById: (input) => |
| 189 | 181 | loadSourceByIdWithDeps(deps, input), |
| 190 | 182 | removeSourceById: (input) => |
| 191 | − removeSourceByIdWithDeps(deps, input, deleteSecretMaterial), | |
| 183 | + removeSourceByIdWithDeps(deps, input), | |
| 192 | 184 | persistSource: (source, options = {}) => |
| 193 | − persistSourceWithDeps(deps, source, options, deleteSecretMaterial), | |
| 185 | + persistSourceWithDeps(deps, source, options), | |
| 194 | 186 | }); |
| 195 | 187 | }), |
| 196 | 188 | ); |
| @@ -1,141 +0,0 @@ | ||
| 1 | −import type { | |
| 2 | − ScopeId, | |
| 3 | − AuthArtifact, | |
| 4 | − CredentialSlot, | |
| 5 | − ProviderAuthGrant, | |
| 6 | − Source, | |
| 7 | −} from "#schema"; | |
| 8 | −import { | |
| 9 | − decodeProviderGrantRefAuthArtifactConfig, | |
| 10 | −} from "#schema"; | |
| 11 | −import * as Effect from "effect/Effect"; | |
| 12 | − | |
| 13 | −import { | |
| 14 | − authArtifactSecretMaterialRefs, | |
| 15 | −} from "../../auth/auth-artifacts"; | |
| 16 | −import { | |
| 17 | − removeAuthLeaseAndSecrets, | |
| 18 | −} from "../../auth/auth-leases"; | |
| 19 | −import type { | |
| 20 | − DeleteSecretMaterial, | |
| 21 | −} from "../../scope/secret-material-providers"; | |
| 22 | −import type { | |
| 23 | − ExecutorStateStoreShape, | |
| 24 | −} from "../../executor-state-store"; | |
| 25 | − | |
| 26 | −const secretRefKey = (ref: { providerId: string; handle: string }): string => | |
| 27 | − `${ref.providerId}:${ref.handle}`; | |
| 28 | − | |
| 29 | −export const cleanupAuthArtifactSecretRefs = ( | |
| 30 | − executorState: ExecutorStateStoreShape, | |
| 31 | − input: { | |
| 32 | − previous: AuthArtifact | null; | |
| 33 | − next: AuthArtifact | null; | |
| 34 | − }, | |
| 35 | − deleteSecretMaterial: DeleteSecretMaterial, | |
| 36 | −) => | |
| 37 | − Effect.gen(function* () { | |
| 38 | − if (input.previous === null) { | |
| 39 | − return; | |
| 40 | − } | |
| 41 | − const nextRefKeys = new Set( | |
| 42 | − (input.next === null ? [] : authArtifactSecretMaterialRefs(input.next)).map( | |
| 43 | − secretRefKey, | |
| 44 | − ), | |
| 45 | − ); | |
| 46 | − const refsToDelete = authArtifactSecretMaterialRefs(input.previous).filter( | |
| 47 | − (ref) => !nextRefKeys.has(secretRefKey(ref)), | |
| 48 | − ); | |
| 49 | − | |
| 50 | − yield* Effect.forEach( | |
| 51 | − refsToDelete, | |
| 52 | − (ref) => Effect.either(deleteSecretMaterial(ref)), | |
| 53 | − { discard: true }, | |
| 54 | − ); | |
| 55 | − }); | |
| 56 | − | |
| 57 | −export const providerGrantIdsFromArtifacts = ( | |
| 58 | − artifacts: ReadonlyArray< | |
| 59 | − Pick<AuthArtifact, "artifactKind" | "configJson"> | null | |
| 60 | − >, | |
| 61 | −): ReadonlySet<ProviderAuthGrant["id"]> => | |
| 62 | − new Set( | |
| 63 | − artifacts | |
| 64 | − .flatMap((artifact) => | |
| 65 | − artifact ? [decodeProviderGrantRefAuthArtifactConfig(artifact)] : [] | |
| 66 | − ) | |
| 67 | − .flatMap((config) => (config ? [config.grantId] : [])), | |
| 68 | − ); | |
| 69 | − | |
| 70 | −export const selectPreferredAuthArtifact = (input: { | |
| 71 | − authArtifacts: ReadonlyArray<AuthArtifact>; | |
| 72 | − actorScopeId?: ScopeId | null; | |
| 73 | − slot: CredentialSlot; | |
| 74 | −}): AuthArtifact | null => { | |
| 75 | − const matchingSlot = input.authArtifacts.filter( | |
| 76 | − (artifact) => artifact.slot === input.slot, | |
| 77 | − ); | |
| 78 | − | |
| 79 | − if (input.actorScopeId !== undefined) { | |
| 80 | − const exact = matchingSlot.find( | |
| 81 | − (artifact) => artifact.actorScopeId === input.actorScopeId, | |
| 82 | − ); | |
| 83 | − if (exact) { | |
| 84 | − return exact; | |
| 85 | − } | |
| 86 | − } | |
| 87 | − | |
| 88 | − return matchingSlot.find((artifact) => artifact.actorScopeId === null) ?? null; | |
| 89 | −}; | |
| 90 | − | |
| 91 | −export const selectExactAuthArtifact = (input: { | |
| 92 | − authArtifacts: ReadonlyArray<AuthArtifact>; | |
| 93 | − actorScopeId?: ScopeId | null; | |
| 94 | − slot: CredentialSlot; | |
| 95 | −}): AuthArtifact | null => | |
| 96 | − input.authArtifacts.find( | |
| 97 | − (artifact) => | |
| 98 | − artifact.slot === input.slot && | |
| 99 | − artifact.actorScopeId === (input.actorScopeId ?? null), | |
| 100 | − ) ?? null; | |
| 101 | − | |
| 102 | −export const removeAuthArtifactsForSource = ( | |
| 103 | − executorState: ExecutorStateStoreShape, | |
| 104 | − input: { | |
| 105 | − scopeId: ScopeId; | |
| 106 | − sourceId: Source["id"]; | |
| 107 | − }, | |
| 108 | − deleteSecretMaterial: DeleteSecretMaterial, | |
| 109 | −) => | |
| 110 | − Effect.gen(function* () { | |
| 111 | − const existingAuthArtifacts = yield* executorState.authArtifacts.listByScopeAndSourceId({ | |
| 112 | − scopeId: input.scopeId, | |
| 113 | − sourceId: input.sourceId, | |
| 114 | − }); | |
| 115 | − | |
| 116 | − yield* executorState.authArtifacts.removeByScopeAndSourceId({ | |
| 117 | − scopeId: input.scopeId, | |
| 118 | − sourceId: input.sourceId, | |
| 119 | − }); | |
| 120 | − | |
| 121 | − yield* Effect.forEach( | |
| 122 | − existingAuthArtifacts, | |
| 123 | − (artifact) => | |
| 124 | − removeAuthLeaseAndSecrets(executorState, { | |
| 125 | − authArtifactId: artifact.id, | |
| 126 | − }, deleteSecretMaterial), | |
| 127 | − { discard: true }, | |
| 128 | − ); | |
| 129 | − | |
| 130 | − yield* Effect.forEach( | |
| 131 | − existingAuthArtifacts, | |
| 132 | − (artifact) => | |
| 133 | − cleanupAuthArtifactSecretRefs(executorState, { | |
| 134 | − previous: artifact, | |
| 135 | − next: null, | |
| 136 | − }, deleteSecretMaterial), | |
| 137 | − { discard: true }, | |
| 138 | − ); | |
| 139 | − | |
| 140 | − return existingAuthArtifacts.length; | |
| 141 | − }); | |
| @@ -1,5 +1,4 @@ | ||
| 1 | 1 | import type { |
| 2 | − LocalConfigSecretInput, | |
| 3 | 2 | LocalConfigSource, |
| 4 | 3 | Source, |
| 5 | 4 | SourceId, |
| @@ -8,19 +7,6 @@ import { · 2 unmodified lines | ||
| 8 | 7 | SourceIdSchema, |
| 9 | 8 | } from "#schema"; |
| 10 | 9 | |
| 11 | −import type { | |
| 12 | − LoadedLocalExecutorConfig, | |
| 13 | −} from "../../scope-config"; | |
| 14 | −import { | |
| 15 | − LocalUnsupportedSourceKindError, | |
| 16 | −} from "../../scope-errors"; | |
| 17 | −import { | |
| 18 | − fromConfigSecretProviderId, | |
| 19 | − toConfigSecretProviderId, | |
| 20 | −} from "../../scope/config-secrets"; | |
| 21 | −import { | |
| 22 | − getSourceAdapterForSource, | |
| 23 | −} from "../source-adapters"; | |
| 24 | 10 | import { |
| 25 | 11 | slugify, |
| 26 | 12 | } from "../slug"; |
| @@ -52,120 +38,11 @@ export const deriveLocalSourceId = ( · 25 unmodified lines | ||
| 52 | 38 | return SourceIdSchema.make(candidate); |
| 53 | 39 | }; |
| 54 | 40 | |
| 55 | −const resolveLocalConfigSecretProviderAlias = ( | |
| 56 | − config: LoadedLocalExecutorConfig["config"], | |
| 57 | −): string | null => { | |
| 58 | − const defaultAlias = trimOrNull(config?.secrets?.defaults?.env); | |
| 59 | − if (defaultAlias !== null && config?.secrets?.providers?.[defaultAlias]) { | |
| 60 | − return defaultAlias; | |
| 61 | − } | |
| 62 | − | |
| 63 | − return config?.secrets?.providers?.default ? "default" : null; | |
| 64 | −}; | |
| 65 | − | |
| 66 | −export const sourceAuthFromConfigInput = (input: { | |
| 67 | − auth: unknown; | |
| 68 | − config: LoadedLocalExecutorConfig["config"]; | |
| 69 | − existing: Source["auth"] | null; | |
| 70 | −}): Source["auth"] => { | |
| 71 | − if (input.auth === undefined) { | |
| 72 | − return input.existing ?? { kind: "none" }; | |
| 73 | − } | |
| 74 | − | |
| 75 | − if (typeof input.auth === "string") { | |
| 76 | − const providerAlias = resolveLocalConfigSecretProviderAlias(input.config); | |
| 77 | − return { | |
| 78 | − kind: "bearer", | |
| 79 | − headerName: "Authorization", | |
| 80 | − prefix: "Bearer ", | |
| 81 | − token: { | |
| 82 | − providerId: providerAlias ? toConfigSecretProviderId(providerAlias) : "env", | |
| 83 | − handle: input.auth, | |
| 84 | − }, | |
| 85 | − }; | |
| 86 | − } | |
| 87 | − | |
| 88 | − if (typeof input.auth === "object" && input.auth !== null) { | |
| 89 | − const explicit = input.auth as { | |
| 90 | − source?: string; | |
| 91 | − provider?: string; | |
| 92 | − id?: string; | |
| 93 | − }; | |
| 94 | − const providerAlias = trimOrNull(explicit.provider); | |
| 95 | − const providerId = providerAlias | |
| 96 | − ? providerAlias === "params" | |
| 97 | − ? "params" | |
| 98 | − : toConfigSecretProviderId(providerAlias) | |
| 99 | − : explicit.source === "env" | |
| 100 | − ? "env" | |
| 101 | − : explicit.source === "params" | |
| 102 | − ? "params" | |
| 103 | − : null; | |
| 104 | − const handle = trimOrNull(explicit.id); | |
| 105 | − if (providerId && handle) { | |
| 106 | − return { | |
| 107 | − kind: "bearer", | |
| 108 | − headerName: "Authorization", | |
| 109 | − prefix: "Bearer ", | |
| 110 | − token: { | |
| 111 | − providerId, | |
| 112 | − handle, | |
| 113 | − }, | |
| 114 | − }; | |
| 115 | − } | |
| 116 | − } | |
| 117 | − | |
| 118 | − return input.existing ?? { kind: "none" }; | |
| 119 | −}; | |
| 120 | − | |
| 121 | −const configAuthFromSource = (input: { | |
| 122 | − source: Source; | |
| 123 | − existingConfigAuth: LocalConfigSecretInput | undefined; | |
| 124 | − config: LoadedLocalExecutorConfig["config"]; | |
| 125 | −}): LocalConfigSecretInput | undefined => { | |
| 126 | − if (input.source.auth.kind !== "bearer") { | |
| 127 | − return input.existingConfigAuth; | |
| 128 | − } | |
| 129 | − | |
| 130 | − if (input.source.auth.token.providerId === "env") { | |
| 131 | − return input.source.auth.token.handle; | |
| 132 | − } | |
| 133 | − | |
| 134 | − if (input.source.auth.token.providerId === "params") { | |
| 135 | − return { | |
| 136 | − source: "params", | |
| 137 | − provider: "params", | |
| 138 | − id: input.source.auth.token.handle, | |
| 139 | − }; | |
| 140 | − } | |
| 141 | − | |
| 142 | − const provider = fromConfigSecretProviderId(input.source.auth.token.providerId); | |
| 143 | − if (provider !== null) { | |
| 144 | − const configuredProvider = input.config?.secrets?.providers?.[provider]; | |
| 145 | − if (configuredProvider) { | |
| 146 | − return { | |
| 147 | − source: configuredProvider.source, | |
| 148 | − provider, | |
| 149 | − id: input.source.auth.token.handle, | |
| 150 | − }; | |
| 151 | − } | |
| 152 | − } | |
| 153 | − | |
| 154 | − return input.existingConfigAuth; | |
| 155 | −}; | |
| 156 | − | |
| 157 | 41 | export const configSourceFromLocalSource = (input: { |
| 158 | 42 | source: Source; |
| 159 | − existingConfigAuth: LocalConfigSecretInput | undefined; | |
| 160 | − config: LoadedLocalExecutorConfig["config"]; | |
| 161 | 43 | }): LocalConfigSource => { |
| 162 | − const auth = configAuthFromSource({ | |
| 163 | − source: input.source, | |
| 164 | − existingConfigAuth: input.existingConfigAuth, | |
| 165 | − config: input.config, | |
| 166 | − }); | |
| 167 | − | |
| 168 | − const common = { | |
| 44 | + return { | |
| 45 | + kind: input.source.kind as LocalConfigSource["kind"], | |
| 169 | 46 | ...(trimOrNull(input.source.name) !== trimOrNull(input.source.id) |
| 170 | 47 | ? { name: input.source.name } |
| 171 | 48 | : {}), |
| @@ -175,21 +52,6 @@ export const configSourceFromLocalSource = (input: { · 3 unmodified lines | ||
| 175 | 52 | ...(input.source.enabled === false ? { enabled: false } : {}), |
| 176 | 53 | connection: { |
| 177 | 54 | endpoint: input.source.endpoint, |
| 178 | − ...(auth !== undefined ? { auth } : {}), | |
| 179 | 55 | }, |
| 180 | − }; | |
| 181 | − | |
| 182 | − const adapter = getSourceAdapterForSource(input.source); | |
| 183 | − if (adapter.localConfigBindingSchema === null) { | |
| 184 | − throw new LocalUnsupportedSourceKindError({ | |
| 185 | − message: `Unsupported source kind for local config: ${input.source.kind}`, | |
| 186 | − kind: input.source.kind, | |
| 187 | − }); | |
| 188 | − } | |
| 189 | − | |
| 190 | − return { | |
| 191 | − kind: input.source.kind as LocalConfigSource["kind"], | |
| 192 | − ...common, | |
| 193 | − binding: cloneJson(adapter.localConfigBindingFromSource(input.source)), | |
| 194 | 56 | } as LocalConfigSource; |
| 195 | 57 | }; |
| @@ -4,30 +4,7 @@ import type { · 3 unmodified lines | ||
| 4 | 4 | } from "#schema"; |
| 5 | 5 | import * as Effect from "effect/Effect"; |
| 6 | 6 | |
| 7 | −import { | |
| 8 | − removeAuthLeaseAndSecrets, | |
| 9 | −} from "../../auth/auth-leases"; | |
| 10 | −import { | |
| 11 | − clearProviderGrantOrphanedAt, | |
| 12 | − markProviderGrantOrphanedIfUnused, | |
| 13 | −} from "../../auth/provider-grant-lifecycle"; | |
| 14 | −import type { | |
| 15 | − DeleteSecretMaterial, | |
| 16 | −} from "../../scope/secret-material-providers"; | |
| 17 | −import type { | |
| 18 | − LocalScopeState, | |
| 19 | −} from "../../scope-state"; | |
| 20 | −import { | |
| 21 | − stableSourceCatalogId, | |
| 22 | − stableSourceCatalogRevisionId, | |
| 23 | − splitSourceForStorage, | |
| 24 | −} from "../source-definitions"; | |
| 25 | −import { | |
| 26 | − cleanupAuthArtifactSecretRefs, | |
| 27 | − providerGrantIdsFromArtifacts, | |
| 28 | − removeAuthArtifactsForSource, | |
| 29 | − selectExactAuthArtifact, | |
| 30 | −} from "./auth"; | |
| 7 | +import type { LocalScopeState } from "../../scope-state"; | |
| 31 | 8 | import { |
| 32 | 9 | configSourceFromLocalSource, |
| 33 | 10 | cloneJson, |
| @@ -49,7 +26,6 @@ export const removeSourceByIdWithDeps = ( · 15 unmodified lines | ||
| 49 | 26 | scopeId: ScopeId; |
| 50 | 27 | sourceId: Source["id"]; |
| 51 | 28 | }, |
| 52 | − deleteSecretMaterial: DeleteSecretMaterial, | |
| 53 | 29 | ): Effect.Effect<boolean, Error, never> => |
| 54 | 30 | Effect.gen(function* () { |
| 55 | 31 | const localScope = yield* resolveRuntimeLocalScopeFromDeps( |
| @@ -84,31 +60,6 @@ export const removeSourceByIdWithDeps = ( · 28 unmodified lines | ||
| 84 | 60 | yield* localScope.sourceArtifactStore.remove({ |
| 85 | 61 | sourceId: input.sourceId, |
| 86 | 62 | }); |
| 87 | − const existingAuthArtifacts = | |
| 88 | − yield* deps.executorState.authArtifacts.listByScopeAndSourceId({ | |
| 89 | − scopeId: input.scopeId, | |
| 90 | − sourceId: input.sourceId, | |
| 91 | − }); | |
| 92 | − const removedGrantIds = providerGrantIdsFromArtifacts(existingAuthArtifacts); | |
| 93 | − | |
| 94 | − yield* deps.executorState.sourceAuthSessions.removeByScopeAndSourceId( | |
| 95 | − input.scopeId, | |
| 96 | − input.sourceId, | |
| 97 | − ); | |
| 98 | − yield* deps.executorState.sourceOauthClients.removeByScopeAndSourceId({ | |
| 99 | − scopeId: input.scopeId, | |
| 100 | − sourceId: input.sourceId, | |
| 101 | − }); | |
| 102 | − yield* removeAuthArtifactsForSource(deps.executorState, input, deleteSecretMaterial); | |
| 103 | − yield* Effect.forEach( | |
| 104 | − [...removedGrantIds], | |
| 105 | − (grantId) => | |
| 106 | − markProviderGrantOrphanedIfUnused(deps.executorState, { | |
| 107 | − scopeId: input.scopeId, | |
| 108 | − grantId, | |
| 109 | − }), | |
| 110 | − { discard: true }, | |
| 111 | − ); | |
| 112 | 63 | yield* syncScopeSourceTypeDeclarationsWithDeps(deps, input.scopeId); |
| 113 | 64 | |
| 114 | 65 | return true; |
| @@ -120,7 +71,6 @@ export const persistSourceWithDeps = ( · 5 unmodified lines | ||
| 120 | 71 | options: { |
| 121 | 72 | actorScopeId?: ScopeId | null; |
| 122 | 73 | } = {}, |
| 123 | − deleteSecretMaterial: DeleteSecretMaterial, | |
| 124 | 74 | ): Effect.Effect<Source, Error, never> => |
| 125 | 75 | Effect.gen(function* () { |
| 126 | 76 | const localScope = yield* resolveRuntimeLocalScopeFromDeps( |
| @@ -138,30 +88,13 @@ export const persistSourceWithDeps = ( · 11 unmodified lines | ||
| 138 | 88 | new Set(Object.keys(localScope.loadedConfig.config?.sources ?? {})), |
| 139 | 89 | ), |
| 140 | 90 | } satisfies Source; |
| 141 | − const existingAuthArtifacts = | |
| 142 | − yield* deps.executorState.authArtifacts.listByScopeAndSourceId({ | |
| 143 | − scopeId: nextSource.scopeId, | |
| 144 | − sourceId: nextSource.id, | |
| 145 | − }); | |
| 146 | − const existingRuntimeAuthArtifact = selectExactAuthArtifact({ | |
| 147 | − authArtifacts: existingAuthArtifacts, | |
| 148 | − actorScopeId: options.actorScopeId, | |
| 149 | − slot: "runtime", | |
| 150 | − }); | |
| 151 | − const existingImportAuthArtifact = selectExactAuthArtifact({ | |
| 152 | − authArtifacts: existingAuthArtifacts, | |
| 153 | − actorScopeId: options.actorScopeId, | |
| 154 | − slot: "import", | |
| 155 | − }); | |
| 91 | + | |
| 156 | 92 | const projectConfig = cloneJson(localScope.loadedConfig.projectConfig ?? {}); |
| 157 | 93 | const sources = { |
| 158 | 94 | ...projectConfig.sources, |
| 159 | 95 | }; |
| 160 | − const existingConfigSource = sources[nextSource.id]; | |
| 161 | 96 | sources[nextSource.id] = configSourceFromLocalSource({ |
| 162 | 97 | source: nextSource, |
| 163 | − existingConfigAuth: existingConfigSource?.connection.auth, | |
| 164 | − config: localScope.loadedConfig.config, | |
| 165 | 98 | }); |
| 166 | 99 | yield* localScope.scopeConfigStore.writeProject({ |
| 167 | 100 | config: { |
| @@ -170,100 +103,6 @@ export const persistSourceWithDeps = ( · 2 unmodified lines | ||
| 170 | 103 | }, |
| 171 | 104 | }); |
| 172 | 105 | |
| 173 | − const { runtimeAuthArtifact, importAuthArtifact } = splitSourceForStorage({ | |
| 174 | − source: nextSource, | |
| 175 | − catalogId: stableSourceCatalogId(nextSource), | |
| 176 | − catalogRevisionId: stableSourceCatalogRevisionId(nextSource), | |
| 177 | − actorScopeId: options.actorScopeId, | |
| 178 | − existingRuntimeAuthArtifactId: existingRuntimeAuthArtifact?.id ?? null, | |
| 179 | − existingImportAuthArtifactId: existingImportAuthArtifact?.id ?? null, | |
| 180 | − }); | |
| 181 | − | |
| 182 | − if (runtimeAuthArtifact === null) { | |
| 183 | − if (existingRuntimeAuthArtifact !== null) { | |
| 184 | − yield* removeAuthLeaseAndSecrets(deps.executorState, { | |
| 185 | − authArtifactId: existingRuntimeAuthArtifact.id, | |
| 186 | − }, deleteSecretMaterial); | |
| 187 | − } | |
| 188 | − yield* deps.executorState.authArtifacts.removeByScopeSourceAndActor({ | |
| 189 | − scopeId: nextSource.scopeId, | |
| 190 | − sourceId: nextSource.id, | |
| 191 | − actorScopeId: options.actorScopeId ?? null, | |
| 192 | − slot: "runtime", | |
| 193 | − }); | |
| 194 | − } else { | |
| 195 | − yield* deps.executorState.authArtifacts.upsert(runtimeAuthArtifact); | |
| 196 | − if ( | |
| 197 | − existingRuntimeAuthArtifact !== null && | |
| 198 | − existingRuntimeAuthArtifact.id !== runtimeAuthArtifact.id | |
| 199 | − ) { | |
| 200 | − yield* removeAuthLeaseAndSecrets(deps.executorState, { | |
| 201 | − authArtifactId: existingRuntimeAuthArtifact.id, | |
| 202 | − }, deleteSecretMaterial); | |
| 203 | − } | |
| 204 | − } | |
| 205 | − | |
| 206 | − yield* cleanupAuthArtifactSecretRefs(deps.executorState, { | |
| 207 | − previous: existingRuntimeAuthArtifact ?? null, | |
| 208 | − next: runtimeAuthArtifact, | |
| 209 | − }, deleteSecretMaterial); | |
| 210 | − | |
| 211 | − if (importAuthArtifact === null) { | |
| 212 | − if (existingImportAuthArtifact !== null) { | |
| 213 | − yield* removeAuthLeaseAndSecrets(deps.executorState, { | |
| 214 | − authArtifactId: existingImportAuthArtifact.id, | |
| 215 | − }, deleteSecretMaterial); | |
| 216 | − } | |
| 217 | − yield* deps.executorState.authArtifacts.removeByScopeSourceAndActor({ | |
| 218 | − scopeId: nextSource.scopeId, | |
| 219 | − sourceId: nextSource.id, | |
| 220 | − actorScopeId: options.actorScopeId ?? null, | |
| 221 | − slot: "import", | |
| 222 | − }); | |
| 223 | − } else { | |
| 224 | − yield* deps.executorState.authArtifacts.upsert(importAuthArtifact); | |
| 225 | − if ( | |
| 226 | − existingImportAuthArtifact !== null && | |
| 227 | − existingImportAuthArtifact.id !== importAuthArtifact.id | |
| 228 | − ) { | |
| 229 | − yield* removeAuthLeaseAndSecrets(deps.executorState, { | |
| 230 | − authArtifactId: existingImportAuthArtifact.id, | |
| 231 | − }, deleteSecretMaterial); | |
| 232 | − } | |
| 233 | − } | |
| 234 | − | |
| 235 | − yield* cleanupAuthArtifactSecretRefs(deps.executorState, { | |
| 236 | − previous: existingImportAuthArtifact ?? null, | |
| 237 | − next: importAuthArtifact, | |
| 238 | − }, deleteSecretMaterial); | |
| 239 | − | |
| 240 | − const previousGrantIds = providerGrantIdsFromArtifacts([ | |
| 241 | − existingRuntimeAuthArtifact, | |
| 242 | − existingImportAuthArtifact, | |
| 243 | − ]); | |
| 244 | − const nextGrantIds = providerGrantIdsFromArtifacts([ | |
| 245 | − runtimeAuthArtifact, | |
| 246 | − importAuthArtifact, | |
| 247 | − ]); | |
| 248 | − | |
| 249 | − yield* Effect.forEach( | |
| 250 | − [...nextGrantIds], | |
| 251 | − (grantId) => | |
| 252 | − clearProviderGrantOrphanedAt(deps.executorState, { | |
| 253 | − grantId, | |
| 254 | − }), | |
| 255 | − { discard: true }, | |
| 256 | − ); | |
| 257 | − yield* Effect.forEach( | |
| 258 | − [...previousGrantIds].filter((grantId) => !nextGrantIds.has(grantId)), | |
| 259 | − (grantId) => | |
| 260 | − markProviderGrantOrphanedIfUnused(deps.executorState, { | |
| 261 | − scopeId: nextSource.scopeId, | |
| 262 | − grantId, | |
| 263 | − }), | |
| 264 | − { discard: true }, | |
| 265 | − ); | |
| 266 | − | |
| 267 | 106 | const existingSourceState = localScope.scopeState.sources[nextSource.id]; |
| 268 | 107 | const scopeState: LocalScopeState = { |
| 269 | 108 | ...localScope.scopeState, |
| @@ -1,53 +1,29 @@ | ||
| 1 | 1 | import type { |
| 2 | 2 | ScopeId, |
| 3 | − AuthArtifact, | |
| 4 | 3 | Source, |
| 5 | 4 | SourceId, |
| 6 | 5 | } from "#schema"; |
| 7 | −import { | |
| 8 | − SourceIdSchema, | |
| 9 | −} from "#schema"; | |
| 6 | +import { SourceIdSchema } from "#schema"; | |
| 10 | 7 | import * as Effect from "effect/Effect"; |
| 11 | 8 | |
| 12 | −import { | |
| 13 | − sourceAuthFromAuthArtifact, | |
| 14 | −} from "../../auth/auth-artifacts"; | |
| 15 | −import { | |
| 16 | − authArtifactSecretMaterialRefs, | |
| 17 | −} from "../../auth/auth-artifacts"; | |
| 18 | −import type { | |
| 19 | − LoadedLocalExecutorConfig, | |
| 20 | −} from "../../scope-config"; | |
| 9 | +import type { LoadedLocalExecutorConfig } from "../../scope-config"; | |
| 21 | 10 | import { |
| 22 | 11 | LocalConfiguredSourceNotFoundError, |
| 23 | 12 | RuntimeLocalScopeMismatchError, |
| 24 | 13 | RuntimeLocalScopeUnavailableError, |
| 25 | 14 | } from "../../scope-errors"; |
| 26 | −import type { | |
| 27 | − LocalScopeState, | |
| 28 | −} from "../../scope-state"; | |
| 29 | −import { | |
| 30 | − getSourceAdapter, | |
| 31 | −} from "../source-adapters"; | |
| 15 | +import type { LocalScopeState } from "../../scope-state"; | |
| 32 | 16 | import { |
| 33 | 17 | resolveRuntimeLocalScopeFromDeps, |
| 34 | 18 | type RuntimeSourceStoreDeps, |
| 35 | 19 | } from "./deps"; |
| 36 | −import { | |
| 37 | − selectPreferredAuthArtifact, | |
| 38 | −} from "./auth"; | |
| 39 | −import { | |
| 40 | − sourceAuthFromConfigInput, | |
| 41 | − trimOrNull, | |
| 42 | −} from "./config"; | |
| 20 | +import { trimOrNull } from "./config"; | |
| 43 | 21 | |
| 44 | 22 | export const buildLocalSourceRecord = (input: { |
| 45 | 23 | scopeId: ScopeId; |
| 46 | 24 | loadedConfig: LoadedLocalExecutorConfig; |
| 47 | 25 | scopeState: LocalScopeState; |
| 48 | 26 | sourceId: SourceId; |
| 49 | − actorScopeId?: ScopeId | null; | |
| 50 | − authArtifacts: ReadonlyArray<AuthArtifact>; | |
| 51 | 27 | }): Effect.Effect< |
| 52 | 28 | { |
| 53 | 29 | source: Source; |
| @@ -60,14 +36,13 @@ export const buildLocalSourceRecord = (input: { · 6 unmodified lines | ||
| 60 | 36 | const sourceConfig = input.loadedConfig.config?.sources?.[input.sourceId]; |
| 61 | 37 | if (!sourceConfig) { |
| 62 | 38 | return yield* new LocalConfiguredSourceNotFoundError({ |
| 63 | − message: `Configured source not found for id ${input.sourceId}`, | |
| 64 | − sourceId: input.sourceId, | |
| 65 | − }); | |
| 39 | + message: `Configured source not found for id ${input.sourceId}`, | |
| 40 | + sourceId: input.sourceId, | |
| 41 | + }); | |
| 66 | 42 | } |
| 67 | 43 | |
| 68 | 44 | const existingState = input.scopeState.sources[input.sourceId]; |
| 69 | − const adapter = getSourceAdapter(sourceConfig.kind); | |
| 70 | − const baseSource = (yield* adapter.validateSource({ | |
| 45 | + const source: Source = { | |
| 71 | 46 | id: SourceIdSchema.make(input.sourceId), |
| 72 | 47 | scopeId: input.scopeId, |
| 73 | 48 | name: trimOrNull(sourceConfig.name) ?? input.sourceId, |
| @@ -78,48 +53,10 @@ export const buildLocalSourceRecord = (input: { · 4 unmodified lines | ||
| 78 | 53 | (sourceConfig.enabled ?? true ? "connected" : "draft"), |
| 79 | 54 | enabled: sourceConfig.enabled ?? true, |
| 80 | 55 | namespace: trimOrNull(sourceConfig.namespace) ?? input.sourceId, |
| 81 | − bindingVersion: adapter.bindingConfigVersion, | |
| 82 | − binding: sourceConfig.binding, | |
| 83 | − importAuthPolicy: adapter.defaultImportAuthPolicy, | |
| 84 | − importAuth: { kind: "none" }, | |
| 85 | − auth: sourceAuthFromConfigInput({ | |
| 86 | − auth: sourceConfig.connection.auth, | |
| 87 | − config: input.loadedConfig.config, | |
| 88 | − existing: null, | |
| 89 | − }), | |
| 90 | 56 | sourceHash: existingState?.sourceHash ?? null, |
| 91 | 57 | lastError: existingState?.lastError ?? null, |
| 92 | 58 | createdAt: existingState?.createdAt ?? Date.now(), |
| 93 | 59 | updatedAt: existingState?.updatedAt ?? Date.now(), |
| 94 | − })) as Source; | |
| 95 | − | |
| 96 | − const runtimeAuthArtifact = selectPreferredAuthArtifact({ | |
| 97 | − authArtifacts: input.authArtifacts.filter( | |
| 98 | − (artifactItem) => artifactItem.sourceId === baseSource.id, | |
| 99 | − ), | |
| 100 | − actorScopeId: input.actorScopeId, | |
| 101 | − slot: "runtime", | |
| 102 | − }); | |
| 103 | − const importAuthArtifact = selectPreferredAuthArtifact({ | |
| 104 | − authArtifacts: input.authArtifacts.filter( | |
| 105 | − (artifactItem) => artifactItem.sourceId === baseSource.id, | |
| 106 | − ), | |
| 107 | − actorScopeId: input.actorScopeId, | |
| 108 | − slot: "import", | |
| 109 | − }); | |
| 110 | − | |
| 111 | − const source: Source = { | |
| 112 | − ...baseSource, | |
| 113 | − auth: | |
| 114 | − runtimeAuthArtifact === null | |
| 115 | − ? baseSource.auth | |
| 116 | − : sourceAuthFromAuthArtifact(runtimeAuthArtifact), | |
| 117 | − importAuth: | |
| 118 | − baseSource.importAuthPolicy === "separate" | |
| 119 | − ? importAuthArtifact === null | |
| 120 | − ? baseSource.importAuth | |
| 121 | − : sourceAuthFromAuthArtifact(importAuthArtifact) | |
| 122 | − : { kind: "none" }, | |
| 123 | 60 | }; |
| 124 | 61 | |
| 125 | 62 | return { |
| @@ -131,7 +68,7 @@ export const buildLocalSourceRecord = (input: { · 5 unmodified lines | ||
| 131 | 68 | export const loadSourcesInWorkspaceWithDeps = ( |
| 132 | 69 | deps: RuntimeSourceStoreDeps, |
| 133 | 70 | scopeId: ScopeId, |
| 134 | − options: { | |
| 71 | + _options: { | |
| 135 | 72 | actorScopeId?: ScopeId | null; |
| 136 | 73 | } = {}, |
| 137 | 74 | ): Effect.Effect< |
| @@ -147,9 +84,6 @@ export const loadSourcesInWorkspaceWithDeps = ( · 9 unmodified lines | ||
| 147 | 84 | deps, |
| 148 | 85 | scopeId, |
| 149 | 86 | ); |
| 150 | − const authArtifacts = yield* deps.executorState.authArtifacts.listByScopeId( | |
| 151 | − scopeId, | |
| 152 | − ); | |
| 153 | 87 | const sources = yield* Effect.forEach( |
| 154 | 88 | Object.keys(localScope.loadedConfig.config?.sources ?? {}), |
| 155 | 89 | (sourceId) => |
| @@ -159,8 +93,6 @@ export const loadSourcesInWorkspaceWithDeps = ( · 3 unmodified lines | ||
| 159 | 93 | loadedConfig: localScope.loadedConfig, |
| 160 | 94 | scopeState: localScope.scopeState, |
| 161 | 95 | sourceId: SourceIdSchema.make(sourceId), |
| 162 | − actorScopeId: options.actorScopeId, | |
| 163 | − authArtifacts, | |
| 164 | 96 | }), |
| 165 | 97 | ({ source }) => source, |
| 166 | 98 | ), |
| @@ -241,44 +173,10 @@ export const listLinkedSecretSourcesInWorkspaceWithDeps = ( · 74 unmodified lines | ||
| 241 | 173 | never |
| 242 | 174 | > => |
| 243 | 175 | Effect.gen(function* () { |
| 244 | − const [sources, authArtifacts, materialIds] = yield* Effect.all([ | |
| 245 | − loadSourcesInWorkspaceWithDeps(deps, scopeId, { | |
| 246 | − actorScopeId: options.actorScopeId, | |
| 247 | − }), | |
| 248 | − deps.executorState.authArtifacts.listByScopeId(scopeId), | |
| 249 | − deps.executorState.secretMaterials.listAll().pipe( | |
| 250 | − Effect.map( | |
| 251 | − (materials) => new Set(materials.map((material) => String(material.id))), | |
| 252 | − ), | |
| 253 | − ), | |
| 254 | − ]); | |
| 255 | − | |
| 256 | − const sourceNames = new Map( | |
| 257 | − sources.map((source) => [source.id, source.name] as const), | |
| 258 | − ); | |
| 259 | − const linkedSources = new Map< | |
| 260 | − string, | |
| 261 | − Array<{ sourceId: string; sourceName: string }> | |
| 262 | − >(); | |
| 263 | − | |
| 264 | − for (const artifact of authArtifacts) { | |
| 265 | − for (const ref of authArtifactSecretMaterialRefs(artifact)) { | |
| 266 | − if (!materialIds.has(ref.handle)) { | |
| 267 | − continue; | |
| 268 | − } | |
| 269 | − | |
| 270 | − const existing = linkedSources.get(ref.handle) ?? []; | |
| 271 | − if (!existing.some((link) => link.sourceId === artifact.sourceId)) { | |
| 272 | − existing.push({ | |
| 273 | − sourceId: artifact.sourceId, | |
| 274 | − sourceName: sourceNames.get(artifact.sourceId) ?? artifact.sourceId, | |
| 275 | − }); | |
| 276 | − linkedSources.set(ref.handle, existing); | |
| 277 | − } | |
| 278 | − } | |
| 279 | − } | |
| 280 | − | |
| 281 | − return linkedSources; | |
| 176 | + yield* loadSourcesInWorkspaceWithDeps(deps, scopeId, { | |
| 177 | + actorScopeId: options.actorScopeId, | |
| 178 | + }); | |
| 179 | + return new Map<string, Array<{ sourceId: string; sourceName: string }>>(); | |
| 282 | 180 | }); |
| 283 | 181 | |
| 284 | 182 | export const loadSourceByIdWithDeps = ( |
| @@ -301,14 +199,11 @@ export const loadSourceByIdWithDeps = ( · 16 unmodified lines | ||
| 301 | 199 | deps, |
| 302 | 200 | input.scopeId, |
| 303 | 201 | ); |
| 304 | − const authArtifacts = yield* deps.executorState.authArtifacts.listByScopeId( | |
| 305 | − input.scopeId, | |
| 306 | − ); | |
| 307 | 202 | if (!localScope.loadedConfig.config?.sources?.[input.sourceId]) { |
| 308 | 203 | return yield* new LocalConfiguredSourceNotFoundError({ |
| 309 | − message: `Source not found: scopeId=${input.scopeId} sourceId=${input.sourceId}`, | |
| 310 | − sourceId: input.sourceId, | |
| 311 | − }); | |
| 204 | + message: `Source not found: scopeId=${input.scopeId} sourceId=${input.sourceId}`, | |
| 205 | + sourceId: input.sourceId, | |
| 206 | + }); | |
| 312 | 207 | } |
| 313 | 208 | |
| 314 | 209 | const localSource = yield* buildLocalSourceRecord({ |
| @@ -316,8 +211,6 @@ export const loadSourceByIdWithDeps = ( · 1 unmodified line | ||
| 316 | 211 | loadedConfig: localScope.loadedConfig, |
| 317 | 212 | scopeState: localScope.scopeState, |
| 318 | 213 | sourceId: input.sourceId, |
| 319 | − actorScopeId: input.actorScopeId, | |
| 320 | − authArtifacts, | |
| 321 | 214 | }); |
| 322 | 215 | |
| 323 | 216 | return localSource.source; |
| @@ -1,12 +1,7 @@ | ||
| 1 | 1 | export { |
| 2 | − SourceAuthSchema, | |
| 3 | − SourceBindingSchema, | |
| 4 | − SourceBindingVersionSchema, | |
| 5 | 2 | SourceKindSchema, |
| 6 | 3 | SourceStatusSchema, |
| 7 | 4 | SourceTransportSchema, |
| 8 | − type SourceAuth, | |
| 9 | − type SourceBinding, | |
| 10 | 5 | type SourceKind, |
| 11 | 6 | type SourceStatus, |
| 12 | 7 | type SourceTransport, |
| @@ -14,29 +9,15 @@ export { · 1 unmodified line | ||
| 14 | 9 | export { |
| 15 | 10 | SecretRefSchema, |
| 16 | 11 | type SecretRef, |
| 17 | −} from "./models/auth-artifact"; | |
| 12 | +} from "./models/secret-ref"; | |
| 18 | 13 | export { |
| 19 | − SourceCatalogAdapterKeySchema, | |
| 14 | + SourceCatalogPluginKeySchema, | |
| 20 | 15 | SourceCatalogKindSchema, |
| 21 | 16 | SourceCatalogVisibilitySchema, |
| 22 | − type SourceCatalogAdapterKey, | |
| 17 | + type SourceCatalogPluginKey, | |
| 23 | 18 | type SourceCatalogKind, |
| 24 | 19 | type SourceCatalogVisibility, |
| 25 | 20 | } from "./models/source-catalog"; |
| 26 | −export { | |
| 27 | − AuthArtifactKindSchema, | |
| 28 | − AuthArtifactSlotSchema, | |
| 29 | − BuiltInAuthArtifactKindSchema, | |
| 30 | − type AuthArtifactKind, | |
| 31 | − type AuthArtifactSlot, | |
| 32 | − type BuiltInAuthArtifactKind, | |
| 33 | −} from "./models/auth-artifact"; | |
| 34 | −export { | |
| 35 | − SourceAuthSessionProviderKindSchema, | |
| 36 | − SourceAuthSessionStatusSchema, | |
| 37 | − type SourceAuthSessionProviderKind, | |
| 38 | − type SourceAuthSessionStatus, | |
| 39 | −} from "./models/source-auth-session"; | |
| 40 | 21 | export { |
| 41 | 22 | LocalScopePolicyApprovalModeSchema, |
| 42 | 23 | LocalScopePolicyEffectSchema, |
| @@ -8,25 +8,6 @@ export const SourceCatalogIdSchema = Schema.String.pipe(Schema.brand("SourceCata · 7 unmodified lines | ||
| 8 | 8 | export const SourceCatalogRevisionIdSchema = Schema.String.pipe( |
| 9 | 9 | Schema.brand("SourceCatalogRevisionId"), |
| 10 | 10 | ); |
| 11 | −export const SourceAuthSessionIdSchema = Schema.String.pipe( | |
| 12 | − Schema.brand("SourceAuthSessionId"), | |
| 13 | −); | |
| 14 | −export const AuthArtifactIdSchema = Schema.String.pipe( | |
| 15 | − Schema.brand("AuthArtifactId"), | |
| 16 | −); | |
| 17 | −export const AuthLeaseIdSchema = Schema.String.pipe( | |
| 18 | − Schema.brand("AuthLeaseId"), | |
| 19 | −); | |
| 20 | −export const CredentialIdSchema = AuthArtifactIdSchema; | |
| 21 | −export const ScopedSourceOauthClientIdSchema = Schema.String.pipe( | |
| 22 | − Schema.brand("ScopedSourceOauthClientId"), | |
| 23 | −); | |
| 24 | −export const ScopeOauthClientIdSchema = Schema.String.pipe( | |
| 25 | − Schema.brand("ScopeOauthClientId"), | |
| 26 | −); | |
| 27 | −export const ProviderAuthGrantIdSchema = Schema.String.pipe( | |
| 28 | − Schema.brand("ProviderAuthGrantId"), | |
| 29 | −); | |
| 30 | 11 | export const SecretMaterialIdSchema = Schema.String.pipe( |
| 31 | 12 | Schema.brand("SecretMaterialId"), |
| 32 | 13 | ); |
| @@ -43,13 +24,6 @@ export type ScopeId = typeof ScopeIdSchema.Type; · 10 unmodified lines | ||
| 43 | 24 | export type SourceId = typeof SourceIdSchema.Type; |
| 44 | 25 | export type SourceCatalogId = typeof SourceCatalogIdSchema.Type; |
| 45 | 26 | export type SourceCatalogRevisionId = typeof SourceCatalogRevisionIdSchema.Type; |
| 46 | −export type SourceAuthSessionId = typeof SourceAuthSessionIdSchema.Type; | |
| 47 | −export type AuthArtifactId = typeof AuthArtifactIdSchema.Type; | |
| 48 | −export type AuthLeaseId = typeof AuthLeaseIdSchema.Type; | |
| 49 | −export type CredentialId = typeof CredentialIdSchema.Type; | |
| 50 | −export type ScopedSourceOauthClientId = typeof ScopedSourceOauthClientIdSchema.Type; | |
| 51 | −export type ScopeOauthClientId = typeof ScopeOauthClientIdSchema.Type; | |
| 52 | −export type ProviderAuthGrantId = typeof ProviderAuthGrantIdSchema.Type; | |
| 53 | 27 | export type SecretMaterialId = typeof SecretMaterialIdSchema.Type; |
| 54 | 28 | export type PolicyId = typeof PolicyIdSchema.Type; |
| 55 | 29 | export type ExecutionId = typeof ExecutionIdSchema.Type; |
| @@ -4,13 +4,8 @@ export * from "./ids"; · 3 unmodified lines | ||
| 4 | 4 | |
| 5 | 5 | export * from "./models/source"; |
| 6 | 6 | export * from "./models/source-catalog"; |
| 7 | −export * from "./models/auth-artifact"; | |
| 8 | −export * from "./models/auth-lease"; | |
| 9 | −export * from "./models/source-oauth-client"; | |
| 10 | −export * from "./models/scope-oauth-client"; | |
| 11 | −export * from "./models/provider-auth-grant"; | |
| 7 | +export * from "./models/secret-ref"; | |
| 12 | 8 | export * from "./models/secret-material"; |
| 13 | −export * from "./models/source-auth-session"; | |
| 14 | 9 | export * from "./models/policy"; |
| 15 | 10 | export * from "./models/local-installation"; |
| 16 | 11 | export * from "./models/local-config"; |
| @@ -1,375 +0,0 @@ | ||
| 1 | −import { | |
| 2 | − Schema, | |
| 3 | −} from "effect"; | |
| 4 | −import * as Option from "effect/Option"; | |
| 5 | − | |
| 6 | −import { | |
| 7 | − TimestampMsSchema, | |
| 8 | −} from "../common"; | |
| 9 | −import { | |
| 10 | − ScopeIdSchema, | |
| 11 | − AuthArtifactIdSchema, | |
| 12 | − ProviderAuthGrantIdSchema, | |
| 13 | − SourceIdSchema, | |
| 14 | −} from "../ids"; | |
| 15 | − | |
| 16 | −export const SecretRefSchema = Schema.Struct({ | |
| 17 | − providerId: Schema.String, | |
| 18 | − handle: Schema.String, | |
| 19 | −}); | |
| 20 | − | |
| 21 | −export const AuthArtifactSlotSchema = Schema.Literal("runtime", "import"); | |
| 22 | −export const CredentialSlotSchema = AuthArtifactSlotSchema; | |
| 23 | − | |
| 24 | −export const AuthArtifactKindSchema = Schema.String; | |
| 25 | −export const AuthGrantSetSchema = Schema.Array(Schema.String); | |
| 26 | − | |
| 27 | −export const RequestPlacementPartSchema = Schema.Union( | |
| 28 | − Schema.Struct({ | |
| 29 | − kind: Schema.Literal("literal"), | |
| 30 | − value: Schema.String, | |
| 31 | − }), | |
| 32 | − Schema.Struct({ | |
| 33 | − kind: Schema.Literal("secret_ref"), | |
| 34 | − ref: SecretRefSchema, | |
| 35 | − }), | |
| 36 | −); | |
| 37 | − | |
| 38 | −export const RequestPlacementTemplateSchema = Schema.Union( | |
| 39 | − Schema.Struct({ | |
| 40 | − location: Schema.Literal("header"), | |
| 41 | − name: Schema.String, | |
| 42 | − parts: Schema.Array(RequestPlacementPartSchema), | |
| 43 | − }), | |
| 44 | − Schema.Struct({ | |
| 45 | − location: Schema.Literal("query"), | |
| 46 | − name: Schema.String, | |
| 47 | − parts: Schema.Array(RequestPlacementPartSchema), | |
| 48 | − }), | |
| 49 | − Schema.Struct({ | |
| 50 | − location: Schema.Literal("cookie"), | |
| 51 | − name: Schema.String, | |
| 52 | − parts: Schema.Array(RequestPlacementPartSchema), | |
| 53 | − }), | |
| 54 | − Schema.Struct({ | |
| 55 | − location: Schema.Literal("body"), | |
| 56 | − path: Schema.String, | |
| 57 | − parts: Schema.Array(RequestPlacementPartSchema), | |
| 58 | − }), | |
| 59 | −); | |
| 60 | − | |
| 61 | −export const RequestPlacementSchema = Schema.Union( | |
| 62 | − Schema.Struct({ | |
| 63 | − location: Schema.Literal("header"), | |
| 64 | − name: Schema.String, | |
| 65 | − value: Schema.String, | |
| 66 | − }), | |
| 67 | − Schema.Struct({ | |
| 68 | − location: Schema.Literal("query"), | |
| 69 | − name: Schema.String, | |
| 70 | − value: Schema.String, | |
| 71 | − }), | |
| 72 | − Schema.Struct({ | |
| 73 | − location: Schema.Literal("cookie"), | |
| 74 | − name: Schema.String, | |
| 75 | − value: Schema.String, | |
| 76 | − }), | |
| 77 | − Schema.Struct({ | |
| 78 | − location: Schema.Literal("body"), | |
| 79 | − path: Schema.String, | |
| 80 | − value: Schema.String, | |
| 81 | − }), | |
| 82 | −); | |
| 83 | − | |
| 84 | −export const RequestPlacementTemplatesJsonSchema = Schema.parseJson( | |
| 85 | − Schema.Array(RequestPlacementTemplateSchema), | |
| 86 | −); | |
| 87 | − | |
| 88 | −export const StaticBearerAuthArtifactKind = "static_bearer" as const; | |
| 89 | −export const StaticOAuth2AuthArtifactKind = "static_oauth2" as const; | |
| 90 | −export const StaticPlacementsAuthArtifactKind = "static_placements" as const; | |
| 91 | −export const RefreshableOAuth2AuthorizedUserAuthArtifactKind = | |
| 92 | − "oauth2_authorized_user" as const; | |
| 93 | −export const ProviderGrantRefAuthArtifactKind = "provider_grant_ref" as const; | |
| 94 | −export const McpOAuthAuthArtifactKind = "mcp_oauth" as const; | |
| 95 | − | |
| 96 | −export const OAuth2ClientAuthenticationMethodSchema = Schema.Literal( | |
| 97 | − "none", | |
| 98 | − "client_secret_post", | |
| 99 | −); | |
| 100 | − | |
| 101 | −export const BuiltInAuthArtifactKindSchema = Schema.Literal( | |
| 102 | − StaticBearerAuthArtifactKind, | |
| 103 | − StaticOAuth2AuthArtifactKind, | |
| 104 | − StaticPlacementsAuthArtifactKind, | |
| 105 | − RefreshableOAuth2AuthorizedUserAuthArtifactKind, | |
| 106 | −); | |
| 107 | − | |
| 108 | −export const StaticBearerAuthArtifactConfigSchema = Schema.Struct({ | |
| 109 | − headerName: Schema.String, | |
| 110 | − prefix: Schema.String, | |
| 111 | − token: SecretRefSchema, | |
| 112 | −}); | |
| 113 | − | |
| 114 | −export const StaticOAuth2AuthArtifactConfigSchema = Schema.Struct({ | |
| 115 | − headerName: Schema.String, | |
| 116 | − prefix: Schema.String, | |
| 117 | − accessToken: SecretRefSchema, | |
| 118 | − refreshToken: Schema.NullOr(SecretRefSchema), | |
| 119 | −}); | |
| 120 | − | |
| 121 | −export const StaticPlacementsAuthArtifactConfigSchema = Schema.Struct({ | |
| 122 | − placements: Schema.Array(RequestPlacementTemplateSchema), | |
| 123 | −}); | |
| 124 | − | |
| 125 | −export const RefreshableOAuth2AuthorizedUserAuthArtifactConfigSchema = Schema.Struct({ | |
| 126 | − headerName: Schema.String, | |
| 127 | − prefix: Schema.String, | |
| 128 | − tokenEndpoint: Schema.String, | |
| 129 | − clientId: Schema.String, | |
| 130 | − clientAuthentication: OAuth2ClientAuthenticationMethodSchema, | |
| 131 | − clientSecret: Schema.NullOr(SecretRefSchema), | |
| 132 | − refreshToken: SecretRefSchema, | |
| 133 | −}); | |
| 134 | − | |
| 135 | −export const ProviderGrantRefAuthArtifactConfigSchema = Schema.Struct({ | |
| 136 | − grantId: ProviderAuthGrantIdSchema, | |
| 137 | − providerKey: Schema.String, | |
| 138 | − requiredScopes: Schema.Array(Schema.String), | |
| 139 | − headerName: Schema.String, | |
| 140 | − prefix: Schema.String, | |
| 141 | −}); | |
| 142 | − | |
| 143 | −export const McpOAuthAuthArtifactConfigSchema = Schema.Struct({ | |
| 144 | − redirectUri: Schema.String, | |
| 145 | − accessToken: SecretRefSchema, | |
| 146 | − refreshToken: Schema.NullOr(SecretRefSchema), | |
| 147 | − tokenType: Schema.String, | |
| 148 | − expiresIn: Schema.NullOr(Schema.Number), | |
| 149 | − scope: Schema.NullOr(Schema.String), | |
| 150 | − resourceMetadataUrl: Schema.NullOr(Schema.String), | |
| 151 | − authorizationServerUrl: Schema.NullOr(Schema.String), | |
| 152 | − resourceMetadataJson: Schema.NullOr(Schema.String), | |
| 153 | − authorizationServerMetadataJson: Schema.NullOr(Schema.String), | |
| 154 | − clientInformationJson: Schema.NullOr(Schema.String), | |
| 155 | −}); | |
| 156 | − | |
| 157 | −export const StaticBearerAuthArtifactConfigJsonSchema = Schema.parseJson( | |
| 158 | − StaticBearerAuthArtifactConfigSchema, | |
| 159 | −); | |
| 160 | − | |
| 161 | −export const StaticOAuth2AuthArtifactConfigJsonSchema = Schema.parseJson( | |
| 162 | − StaticOAuth2AuthArtifactConfigSchema, | |
| 163 | −); | |
| 164 | − | |
| 165 | −export const StaticPlacementsAuthArtifactConfigJsonSchema = Schema.parseJson( | |
| 166 | − StaticPlacementsAuthArtifactConfigSchema, | |
| 167 | −); | |
| 168 | − | |
| 169 | −export const RefreshableOAuth2AuthorizedUserAuthArtifactConfigJsonSchema = Schema.parseJson( | |
| 170 | − RefreshableOAuth2AuthorizedUserAuthArtifactConfigSchema, | |
| 171 | −); | |
| 172 | − | |
| 173 | −export const ProviderGrantRefAuthArtifactConfigJsonSchema = Schema.parseJson( | |
| 174 | − ProviderGrantRefAuthArtifactConfigSchema, | |
| 175 | −); | |
| 176 | − | |
| 177 | −export const McpOAuthAuthArtifactConfigJsonSchema = Schema.parseJson( | |
| 178 | − McpOAuthAuthArtifactConfigSchema, | |
| 179 | −); | |
| 180 | − | |
| 181 | −export const RequestPlacementsJsonSchema = Schema.parseJson( | |
| 182 | − Schema.Array(RequestPlacementSchema), | |
| 183 | −); | |
| 184 | − | |
| 185 | −export const AuthGrantSetJsonSchema = Schema.parseJson(AuthGrantSetSchema); | |
| 186 | − | |
| 187 | −const decodeStaticBearerAuthArtifactConfigOption = Schema.decodeUnknownOption( | |
| 188 | − StaticBearerAuthArtifactConfigJsonSchema, | |
| 189 | −); | |
| 190 | − | |
| 191 | −const decodeStaticOAuth2AuthArtifactConfigOption = Schema.decodeUnknownOption( | |
| 192 | − StaticOAuth2AuthArtifactConfigJsonSchema, | |
| 193 | −); | |
| 194 | − | |
| 195 | −const decodeStaticPlacementsAuthArtifactConfigOption = Schema.decodeUnknownOption( | |
| 196 | − StaticPlacementsAuthArtifactConfigJsonSchema, | |
| 197 | −); | |
| 198 | − | |
| 199 | −const decodeRefreshableOAuth2AuthorizedUserAuthArtifactConfigOption = Schema.decodeUnknownOption( | |
| 200 | − RefreshableOAuth2AuthorizedUserAuthArtifactConfigJsonSchema, | |
| 201 | −); | |
| 202 | −const decodeProviderGrantRefAuthArtifactConfigOption = Schema.decodeUnknownOption( | |
| 203 | − ProviderGrantRefAuthArtifactConfigJsonSchema, | |
| 204 | −); | |
| 205 | −const decodeMcpOAuthAuthArtifactConfigOption = Schema.decodeUnknownOption( | |
| 206 | − McpOAuthAuthArtifactConfigJsonSchema, | |
| 207 | −); | |
| 208 | − | |
| 209 | −const decodeAuthGrantSetOption = Schema.decodeUnknownOption(AuthGrantSetJsonSchema); | |
| 210 | − | |
| 211 | −export const AuthArtifactSchema = Schema.Struct({ | |
| 212 | − id: AuthArtifactIdSchema, | |
| 213 | − scopeId: ScopeIdSchema, | |
| 214 | − sourceId: SourceIdSchema, | |
| 215 | − actorScopeId: Schema.NullOr(ScopeIdSchema), | |
| 216 | − slot: AuthArtifactSlotSchema, | |
| 217 | − artifactKind: AuthArtifactKindSchema, | |
| 218 | − configJson: Schema.String, | |
| 219 | − grantSetJson: Schema.NullOr(Schema.String), | |
| 220 | − createdAt: TimestampMsSchema, | |
| 221 | − updatedAt: TimestampMsSchema, | |
| 222 | −}); | |
| 223 | − | |
| 224 | −export type SecretRef = typeof SecretRefSchema.Type; | |
| 225 | −export type AuthArtifactSlot = typeof AuthArtifactSlotSchema.Type; | |
| 226 | −export type CredentialSlot = typeof CredentialSlotSchema.Type; | |
| 227 | −export type AuthArtifactKind = typeof AuthArtifactKindSchema.Type; | |
| 228 | −export type AuthGrantSet = typeof AuthGrantSetSchema.Type; | |
| 229 | −export type RequestPlacementPart = typeof RequestPlacementPartSchema.Type; | |
| 230 | −export type RequestPlacementTemplate = typeof RequestPlacementTemplateSchema.Type; | |
| 231 | −export type RequestPlacement = typeof RequestPlacementSchema.Type; | |
| 232 | −export type OAuth2ClientAuthenticationMethod = | |
| 233 | − typeof OAuth2ClientAuthenticationMethodSchema.Type; | |
| 234 | −export type BuiltInAuthArtifactKind = typeof BuiltInAuthArtifactKindSchema.Type; | |
| 235 | −export type StaticBearerAuthArtifactConfig = typeof StaticBearerAuthArtifactConfigSchema.Type; | |
| 236 | −export type StaticOAuth2AuthArtifactConfig = typeof StaticOAuth2AuthArtifactConfigSchema.Type; | |
| 237 | −export type StaticPlacementsAuthArtifactConfig = typeof StaticPlacementsAuthArtifactConfigSchema.Type; | |
| 238 | −export type RefreshableOAuth2AuthorizedUserAuthArtifactConfig = | |
| 239 | − typeof RefreshableOAuth2AuthorizedUserAuthArtifactConfigSchema.Type; | |
| 240 | −export type ProviderGrantRefAuthArtifactConfig = | |
| 241 | − typeof ProviderGrantRefAuthArtifactConfigSchema.Type; | |
| 242 | −export type McpOAuthAuthArtifactConfig = typeof McpOAuthAuthArtifactConfigSchema.Type; | |
| 243 | −export type AuthArtifact = typeof AuthArtifactSchema.Type; | |
| 244 | − | |
| 245 | −export type DecodedBuiltInAuthArtifactConfig = | |
| 246 | − | { | |
| 247 | − artifactKind: typeof StaticBearerAuthArtifactKind; | |
| 248 | − config: StaticBearerAuthArtifactConfig; | |
| 249 | − } | |
| 250 | − | { | |
| 251 | − artifactKind: typeof StaticOAuth2AuthArtifactKind; | |
| 252 | − config: StaticOAuth2AuthArtifactConfig; | |
| 253 | − } | |
| 254 | − | { | |
| 255 | − artifactKind: typeof StaticPlacementsAuthArtifactKind; | |
| 256 | − config: StaticPlacementsAuthArtifactConfig; | |
| 257 | − } | |
| 258 | − | { | |
| 259 | − artifactKind: typeof RefreshableOAuth2AuthorizedUserAuthArtifactKind; | |
| 260 | − config: RefreshableOAuth2AuthorizedUserAuthArtifactConfig; | |
| 261 | − }; | |
| 262 | − | |
| 263 | −export const decodeProviderGrantRefAuthArtifactConfig = ( | |
| 264 | − artifact: Pick<AuthArtifact, "artifactKind" | "configJson">, | |
| 265 | −): ProviderGrantRefAuthArtifactConfig | null => { | |
| 266 | − if (artifact.artifactKind !== ProviderGrantRefAuthArtifactKind) { | |
| 267 | − return null; | |
| 268 | − } | |
| 269 | − | |
| 270 | − const decoded = decodeProviderGrantRefAuthArtifactConfigOption(artifact.configJson); | |
| 271 | − return Option.isSome(decoded) ? decoded.value : null; | |
| 272 | −}; | |
| 273 | − | |
| 274 | −export const decodeMcpOAuthAuthArtifactConfig = ( | |
| 275 | − artifact: Pick<AuthArtifact, "artifactKind" | "configJson">, | |
| 276 | −): McpOAuthAuthArtifactConfig | null => { | |
| 277 | − if (artifact.artifactKind !== McpOAuthAuthArtifactKind) { | |
| 278 | − return null; | |
| 279 | − } | |
| 280 | − | |
| 281 | − const decoded = decodeMcpOAuthAuthArtifactConfigOption(artifact.configJson); | |
| 282 | − return Option.isSome(decoded) ? decoded.value : null; | |
| 283 | −}; | |
| 284 | − | |
| 285 | −export const decodeBuiltInAuthArtifactConfig = ( | |
| 286 | − artifact: Pick<AuthArtifact, "artifactKind" | "configJson">, | |
| 287 | −): DecodedBuiltInAuthArtifactConfig | null => { | |
| 288 | − switch (artifact.artifactKind) { | |
| 289 | − case StaticBearerAuthArtifactKind: { | |
| 290 | − const decoded = decodeStaticBearerAuthArtifactConfigOption(artifact.configJson); | |
| 291 | − return Option.isSome(decoded) | |
| 292 | − ? { artifactKind: StaticBearerAuthArtifactKind, config: decoded.value } | |
| 293 | − : null; | |
| 294 | − } | |
| 295 | − case StaticOAuth2AuthArtifactKind: { | |
| 296 | − const decoded = decodeStaticOAuth2AuthArtifactConfigOption(artifact.configJson); | |
| 297 | − return Option.isSome(decoded) | |
| 298 | − ? { artifactKind: StaticOAuth2AuthArtifactKind, config: decoded.value } | |
| 299 | − : null; | |
| 300 | − } | |
| 301 | − case StaticPlacementsAuthArtifactKind: { | |
| 302 | − const decoded = decodeStaticPlacementsAuthArtifactConfigOption(artifact.configJson); | |
| 303 | − return Option.isSome(decoded) | |
| 304 | − ? { artifactKind: StaticPlacementsAuthArtifactKind, config: decoded.value } | |
| 305 | − : null; | |
| 306 | − } | |
| 307 | − case RefreshableOAuth2AuthorizedUserAuthArtifactKind: { | |
| 308 | − const decoded = decodeRefreshableOAuth2AuthorizedUserAuthArtifactConfigOption( | |
| 309 | − artifact.configJson, | |
| 310 | − ); | |
| 311 | − return Option.isSome(decoded) | |
| 312 | − ? { | |
| 313 | − artifactKind: RefreshableOAuth2AuthorizedUserAuthArtifactKind, | |
| 314 | − config: decoded.value, | |
| 315 | − } | |
| 316 | − : null; | |
| 317 | − } | |
| 318 | − default: | |
| 319 | − return null; | |
| 320 | − } | |
| 321 | −}; | |
| 322 | − | |
| 323 | −export const decodeAuthArtifactGrantSet = ( | |
| 324 | − artifact: Pick<AuthArtifact, "grantSetJson"> | string | null, | |
| 325 | −): AuthGrantSet | null => { | |
| 326 | − const grantSetJson = artifact !== null && typeof artifact === "object" | |
| 327 | − ? artifact.grantSetJson | |
| 328 | − : artifact; | |
| 329 | − | |
| 330 | − if (grantSetJson === null) { | |
| 331 | − return null; | |
| 332 | − } | |
| 333 | − | |
| 334 | − const decoded = decodeAuthGrantSetOption(grantSetJson); | |
| 335 | − return Option.isSome(decoded) ? decoded.value : null; | |
| 336 | −}; | |
| 337 | − | |
| 338 | −export const decodeAuthGrantSet = decodeAuthArtifactGrantSet; | |
| 339 | − | |
| 340 | −export const authArtifactSecretRefs = ( | |
| 341 | − artifact: Pick<AuthArtifact, "artifactKind" | "configJson">, | |
| 342 | −): ReadonlyArray<SecretRef> => { | |
| 343 | − const decoded = decodeBuiltInAuthArtifactConfig(artifact); | |
| 344 | − if (decoded !== null) { | |
| 345 | − switch (decoded.artifactKind) { | |
| 346 | − case StaticBearerAuthArtifactKind: | |
| 347 | − return [decoded.config.token]; | |
| 348 | − case StaticOAuth2AuthArtifactKind: | |
| 349 | − return decoded.config.refreshToken | |
| 350 | − ? [decoded.config.accessToken, decoded.config.refreshToken] | |
| 351 | − : [decoded.config.accessToken]; | |
| 352 | − case StaticPlacementsAuthArtifactKind: | |
| 353 | − return decoded.config.placements.flatMap((placement) => | |
| 354 | − placement.parts.flatMap((part) => | |
| 355 | − part.kind === "secret_ref" ? [part.ref] : [], | |
| 356 | − ) | |
| 357 | − ); | |
| 358 | − case RefreshableOAuth2AuthorizedUserAuthArtifactKind: | |
| 359 | − return decoded.config.clientSecret | |
| 360 | − ? [decoded.config.refreshToken, decoded.config.clientSecret] | |
| 361 | − : [decoded.config.refreshToken]; | |
| 362 | − } | |
| 363 | − } | |
| 364 | − | |
| 365 | − const mcpOAuthConfig = decodeMcpOAuthAuthArtifactConfig(artifact); | |
| 366 | − if (mcpOAuthConfig !== null) { | |
| 367 | − return mcpOAuthConfig.refreshToken | |
| 368 | − ? [mcpOAuthConfig.accessToken, mcpOAuthConfig.refreshToken] | |
| 369 | − : [mcpOAuthConfig.accessToken]; | |
| 370 | − } | |
| 371 | − | |
| 372 | − return []; | |
| 373 | −}; | |
| 374 | − | |
| 375 | −export const authArtifactSecretMaterialRefs = authArtifactSecretRefs; | |
| @@ -1,54 +0,0 @@ | ||
| 1 | −import { | |
| 2 | − Schema, | |
| 3 | −} from "effect"; | |
| 4 | −import * as Option from "effect/Option"; | |
| 5 | − | |
| 6 | −import { | |
| 7 | − TimestampMsSchema, | |
| 8 | −} from "../common"; | |
| 9 | −import { | |
| 10 | − ScopeIdSchema, | |
| 11 | − AuthArtifactIdSchema, | |
| 12 | − AuthLeaseIdSchema, | |
| 13 | − SourceIdSchema, | |
| 14 | −} from "../ids"; | |
| 15 | − | |
| 16 | −import { | |
| 17 | − AuthArtifactSlotSchema, | |
| 18 | − RequestPlacementTemplatesJsonSchema, | |
| 19 | − type RequestPlacementTemplate, | |
| 20 | −} from "./auth-artifact"; | |
| 21 | − | |
| 22 | −export const AuthLeaseSchema = Schema.Struct({ | |
| 23 | − id: AuthLeaseIdSchema, | |
| 24 | − authArtifactId: AuthArtifactIdSchema, | |
| 25 | − scopeId: ScopeIdSchema, | |
| 26 | − sourceId: SourceIdSchema, | |
| 27 | − actorScopeId: Schema.NullOr(ScopeIdSchema), | |
| 28 | − slot: AuthArtifactSlotSchema, | |
| 29 | − placementsTemplateJson: Schema.String, | |
| 30 | − expiresAt: Schema.NullOr(TimestampMsSchema), | |
| 31 | − refreshAfter: Schema.NullOr(TimestampMsSchema), | |
| 32 | − createdAt: TimestampMsSchema, | |
| 33 | − updatedAt: TimestampMsSchema, | |
| 34 | −}); | |
| 35 | − | |
| 36 | −export type AuthLease = typeof AuthLeaseSchema.Type; | |
| 37 | − | |
| 38 | −const decodeLeasePlacementTemplatesOption = Schema.decodeUnknownOption( | |
| 39 | − RequestPlacementTemplatesJsonSchema, | |
| 40 | −); | |
| 41 | − | |
| 42 | −export const decodeAuthLeasePlacementTemplates = ( | |
| 43 | − lease: Pick<AuthLease, "placementsTemplateJson">, | |
| 44 | −): ReadonlyArray<RequestPlacementTemplate> | null => { | |
| 45 | − const decoded = decodeLeasePlacementTemplatesOption(lease.placementsTemplateJson); | |
| 46 | − return Option.isSome(decoded) ? decoded.value : null; | |
| 47 | −}; | |
| 48 | − | |
| 49 | −export const authLeaseSecretRefs = ( | |
| 50 | − lease: Pick<AuthLease, "placementsTemplateJson">, | |
| 51 | −) => | |
| 52 | − (decodeAuthLeasePlacementTemplates(lease) ?? []).flatMap((placement) => | |
| 53 | − placement.parts.flatMap((part) => (part.kind === "secret_ref" ? [part.ref] : [])), | |
| 54 | − ); | |
| @@ -2,10 +2,6 @@ import { · 1 unmodified line | ||
| 2 | 2 | Schema, |
| 3 | 3 | } from "effect"; |
| 4 | 4 | |
| 5 | −import { | |
| 6 | − JsonObjectSchema, | |
| 7 | −} from "@executor/source-core"; | |
| 8 | − | |
| 9 | 5 | export const LocalExecutorRuntimeSchema = Schema.Literal( |
| 10 | 6 | "quickjs", |
| 11 | 7 | "ses", |
| @@ -62,7 +58,6 @@ export const LocalConfigSecretInputSchema = Schema.Union( · 50 unmodified lines | ||
| 62 | 58 | |
| 63 | 59 | export const LocalConfigSourceConnectionSchema = Schema.Struct({ |
| 64 | 60 | endpoint: Schema.String, |
| 65 | − auth: Schema.optional(LocalConfigSecretInputSchema), | |
| 66 | 61 | }); |
| 67 | 62 | |
| 68 | 63 | const LocalConfigSourceEntryBaseSchema = Schema.Struct({ |
| @@ -76,7 +71,6 @@ export const LocalConfigSourceSchema = Schema.extend( · 7 unmodified lines | ||
| 76 | 71 | LocalConfigSourceEntryBaseSchema, |
| 77 | 72 | Schema.Struct({ |
| 78 | 73 | kind: Schema.String, |
| 79 | − binding: JsonObjectSchema, | |
| 80 | 74 | }), |
| 81 | 75 | ); |
| 82 | 76 | |
| @@ -1,37 +0,0 @@ | ||
| 1 | −import { | |
| 2 | − Schema, | |
| 3 | −} from "effect"; | |
| 4 | − | |
| 5 | −import { | |
| 6 | − TimestampMsSchema, | |
| 7 | −} from "../common"; | |
| 8 | −import { | |
| 9 | − ScopeIdSchema, | |
| 10 | − ProviderAuthGrantIdSchema, | |
| 11 | − ScopeOauthClientIdSchema, | |
| 12 | −} from "../ids"; | |
| 13 | − | |
| 14 | −import { | |
| 15 | − OAuth2ClientAuthenticationMethodSchema, | |
| 16 | − SecretRefSchema, | |
| 17 | −} from "./auth-artifact"; | |
| 18 | − | |
| 19 | −export const ProviderAuthGrantSchema = Schema.Struct({ | |
| 20 | − id: ProviderAuthGrantIdSchema, | |
| 21 | − scopeId: ScopeIdSchema, | |
| 22 | − actorScopeId: Schema.NullOr(ScopeIdSchema), | |
| 23 | − providerKey: Schema.String, | |
| 24 | − oauthClientId: ScopeOauthClientIdSchema, | |
| 25 | − tokenEndpoint: Schema.String, | |
| 26 | − clientAuthentication: OAuth2ClientAuthenticationMethodSchema, | |
| 27 | − headerName: Schema.String, | |
| 28 | − prefix: Schema.String, | |
| 29 | − refreshToken: SecretRefSchema, | |
| 30 | − grantedScopes: Schema.Array(Schema.String), | |
| 31 | − lastRefreshedAt: Schema.NullOr(TimestampMsSchema), | |
| 32 | − orphanedAt: Schema.NullOr(TimestampMsSchema), | |
| 33 | − createdAt: TimestampMsSchema, | |
| 34 | − updatedAt: TimestampMsSchema, | |
| 35 | −}); | |
| 36 | − | |
| 37 | −export type ProviderAuthGrant = typeof ProviderAuthGrantSchema.Type; | |
| @@ -1,26 +0,0 @@ | ||
| 1 | −import { | |
| 2 | − Schema, | |
| 3 | −} from "effect"; | |
| 4 | − | |
| 5 | −import { | |
| 6 | − TimestampMsSchema, | |
| 7 | −} from "../common"; | |
| 8 | −import { | |
| 9 | − ScopeIdSchema, | |
| 10 | − ScopeOauthClientIdSchema, | |
| 11 | −} from "../ids"; | |
| 12 | − | |
| 13 | −export const ScopeOauthClientSchema = Schema.Struct({ | |
| 14 | − id: ScopeOauthClientIdSchema, | |
| 15 | − scopeId: ScopeIdSchema, | |
| 16 | − providerKey: Schema.String, | |
| 17 | − label: Schema.NullOr(Schema.String), | |
| 18 | − clientId: Schema.String, | |
| 19 | − clientSecretProviderId: Schema.NullOr(Schema.String), | |
| 20 | − clientSecretHandle: Schema.NullOr(Schema.String), | |
| 21 | − clientMetadataJson: Schema.NullOr(Schema.String), | |
| 22 | − createdAt: TimestampMsSchema, | |
| 23 | − updatedAt: TimestampMsSchema, | |
| 24 | −}); | |
| 25 | − | |
| 26 | −export type ScopeOauthClient = typeof ScopeOauthClientSchema.Type; | |
| @@ -0,0 +1,8 @@ | ||
| 1 | +import * as Schema from "effect/Schema"; | |
| 2 | + | |
| 3 | +export const SecretRefSchema = Schema.Struct({ | |
| 4 | + providerId: Schema.String, | |
| 5 | + handle: Schema.String, | |
| 6 | +}); | |
| 7 | + | |
| 8 | +export type SecretRef = typeof SecretRefSchema.Type; | |
| @@ -1,159 +0,0 @@ | ||
| 1 | −import { | |
| 2 | − Schema, | |
| 3 | −} from "effect"; | |
| 4 | − | |
| 5 | −import { | |
| 6 | − TimestampMsSchema, | |
| 7 | −} from "../common"; | |
| 8 | −import { | |
| 9 | − ScopeIdSchema, | |
| 10 | − ExecutionIdSchema, | |
| 11 | − ExecutionInteractionIdSchema, | |
| 12 | − SourceIdSchema, | |
| 13 | − SourceAuthSessionIdSchema, | |
| 14 | − ScopeOauthClientIdSchema, | |
| 15 | −} from "../ids"; | |
| 16 | −import { | |
| 17 | − CredentialSlotSchema, | |
| 18 | − OAuth2ClientAuthenticationMethodSchema, | |
| 19 | − SecretRefSchema, | |
| 20 | −} from "./auth-artifact"; | |
| 21 | − | |
| 22 | −export const SourceAuthSessionProviderKindSchema = Schema.String; | |
| 23 | − | |
| 24 | −export const SourceAuthSessionStatusSchema = Schema.Literal( | |
| 25 | − "pending", | |
| 26 | − "completed", | |
| 27 | − "failed", | |
| 28 | − "cancelled", | |
| 29 | −); | |
| 30 | − | |
| 31 | −export type JsonValue = | |
| 32 | − | string | |
| 33 | − | number | |
| 34 | − | boolean | |
| 35 | − | null | |
| 36 | − | JsonObject | |
| 37 | − | ReadonlyArray<JsonValue>; | |
| 38 | − | |
| 39 | −export type JsonObject = { | |
| 40 | − readonly [key: string]: JsonValue; | |
| 41 | −}; | |
| 42 | − | |
| 43 | −export const JsonValueSchema: Schema.Schema<JsonValue> = Schema.suspend(() => | |
| 44 | − Schema.Union( | |
| 45 | − Schema.String, | |
| 46 | − Schema.Number, | |
| 47 | − Schema.Boolean, | |
| 48 | − Schema.Null, | |
| 49 | − Schema.Array(JsonValueSchema), | |
| 50 | − Schema.Record({ | |
| 51 | − key: Schema.String, | |
| 52 | − value: JsonValueSchema, | |
| 53 | − }), | |
| 54 | − ) | |
| 55 | −).annotations({ identifier: "JsonValue" }); | |
| 56 | − | |
| 57 | −export const JsonObjectSchema = Schema.Record({ | |
| 58 | − key: Schema.String, | |
| 59 | − value: JsonValueSchema, | |
| 60 | −}).annotations({ identifier: "JsonObject" }); | |
| 61 | − | |
| 62 | −export const McpSourceAuthSessionDataSchema = Schema.Struct({ | |
| 63 | − kind: Schema.Literal("mcp_oauth"), | |
| 64 | − endpoint: Schema.String, | |
| 65 | − redirectUri: Schema.String, | |
| 66 | − scope: Schema.NullOr(Schema.String), | |
| 67 | − resourceMetadataUrl: Schema.NullOr(Schema.String), | |
| 68 | − authorizationServerUrl: Schema.NullOr(Schema.String), | |
| 69 | − resourceMetadata: Schema.NullOr(JsonObjectSchema), | |
| 70 | − authorizationServerMetadata: Schema.NullOr(JsonObjectSchema), | |
| 71 | − clientInformation: Schema.NullOr(JsonObjectSchema), | |
| 72 | − codeVerifier: Schema.NullOr(Schema.String), | |
| 73 | − authorizationUrl: Schema.NullOr(Schema.String), | |
| 74 | −}); | |
| 75 | − | |
| 76 | −export const McpSourceAuthSessionDataJsonSchema = Schema.parseJson( | |
| 77 | − McpSourceAuthSessionDataSchema, | |
| 78 | −); | |
| 79 | − | |
| 80 | −export const OAuth2PkceSourceAuthSessionDataSchema = Schema.Struct({ | |
| 81 | − kind: Schema.Literal("oauth2_pkce"), | |
| 82 | − providerKey: Schema.String, | |
| 83 | − authorizationEndpoint: Schema.String, | |
| 84 | − tokenEndpoint: Schema.String, | |
| 85 | − redirectUri: Schema.String, | |
| 86 | − clientId: Schema.String, | |
| 87 | − clientAuthentication: OAuth2ClientAuthenticationMethodSchema, | |
| 88 | − clientSecret: Schema.NullOr(SecretRefSchema), | |
| 89 | − scopes: Schema.Array(Schema.String), | |
| 90 | − headerName: Schema.String, | |
| 91 | − prefix: Schema.String, | |
| 92 | − authorizationParams: Schema.Record({ | |
| 93 | − key: Schema.String, | |
| 94 | − value: Schema.String, | |
| 95 | − }), | |
| 96 | − codeVerifier: Schema.NullOr(Schema.String), | |
| 97 | − authorizationUrl: Schema.NullOr(Schema.String), | |
| 98 | −}); | |
| 99 | − | |
| 100 | −export const OAuth2PkceSourceAuthSessionDataJsonSchema = Schema.parseJson( | |
| 101 | − OAuth2PkceSourceAuthSessionDataSchema, | |
| 102 | −); | |
| 103 | − | |
| 104 | −export const ProviderOauthTargetSourceSchema = Schema.Struct({ | |
| 105 | − sourceId: SourceIdSchema, | |
| 106 | − requiredScopes: Schema.Array(Schema.String), | |
| 107 | −}); | |
| 108 | − | |
| 109 | −export const ProviderOauthBatchSourceAuthSessionDataSchema = Schema.Struct({ | |
| 110 | − kind: Schema.Literal("provider_oauth_batch"), | |
| 111 | − providerKey: Schema.String, | |
| 112 | − authorizationEndpoint: Schema.String, | |
| 113 | − tokenEndpoint: Schema.String, | |
| 114 | − redirectUri: Schema.String, | |
| 115 | − oauthClientId: ScopeOauthClientIdSchema, | |
| 116 | − clientAuthentication: OAuth2ClientAuthenticationMethodSchema, | |
| 117 | − scopes: Schema.Array(Schema.String), | |
| 118 | − headerName: Schema.String, | |
| 119 | − prefix: Schema.String, | |
| 120 | − authorizationParams: Schema.Record({ | |
| 121 | − key: Schema.String, | |
| 122 | − value: Schema.String, | |
| 123 | − }), | |
| 124 | − targetSources: Schema.Array(ProviderOauthTargetSourceSchema), | |
| 125 | − codeVerifier: Schema.NullOr(Schema.String), | |
| 126 | − authorizationUrl: Schema.NullOr(Schema.String), | |
| 127 | −}); | |
| 128 | − | |
| 129 | −export const ProviderOauthBatchSourceAuthSessionDataJsonSchema = Schema.parseJson( | |
| 130 | − ProviderOauthBatchSourceAuthSessionDataSchema, | |
| 131 | −); | |
| 132 | − | |
| 133 | −export const SourceAuthSessionSchema = Schema.Struct({ | |
| 134 | − id: SourceAuthSessionIdSchema, | |
| 135 | − scopeId: ScopeIdSchema, | |
| 136 | − sourceId: SourceIdSchema, | |
| 137 | − actorScopeId: Schema.NullOr(ScopeIdSchema), | |
| 138 | − credentialSlot: CredentialSlotSchema, | |
| 139 | − executionId: Schema.NullOr(ExecutionIdSchema), | |
| 140 | − interactionId: Schema.NullOr(ExecutionInteractionIdSchema), | |
| 141 | − providerKind: SourceAuthSessionProviderKindSchema, | |
| 142 | − status: SourceAuthSessionStatusSchema, | |
| 143 | − state: Schema.String, | |
| 144 | − sessionDataJson: Schema.String, | |
| 145 | − errorText: Schema.NullOr(Schema.String), | |
| 146 | − completedAt: Schema.NullOr(TimestampMsSchema), | |
| 147 | − createdAt: TimestampMsSchema, | |
| 148 | − updatedAt: TimestampMsSchema, | |
| 149 | −}); | |
| 150 | − | |
| 151 | −export type SourceAuthSessionProviderKind = typeof SourceAuthSessionProviderKindSchema.Type; | |
| 152 | −export type SourceAuthSessionStatus = typeof SourceAuthSessionStatusSchema.Type; | |
| 153 | −export type McpSourceAuthSessionData = typeof McpSourceAuthSessionDataSchema.Type; | |
| 154 | −export type OAuth2PkceSourceAuthSessionData = | |
| 155 | − typeof OAuth2PkceSourceAuthSessionDataSchema.Type; | |
| 156 | −export type ProviderOauthTargetSource = typeof ProviderOauthTargetSourceSchema.Type; | |
| 157 | −export type ProviderOauthBatchSourceAuthSessionData = | |
| 158 | − typeof ProviderOauthBatchSourceAuthSessionDataSchema.Type; | |
| 159 | −export type SourceAuthSession = typeof SourceAuthSessionSchema.Type; | |
| @@ -15,7 +15,7 @@ export const SourceCatalogKindSchema = Schema.Literal( · 14 unmodified lines | ||
| 15 | 15 | "internal", |
| 16 | 16 | ); |
| 17 | 17 | |
| 18 | −export const SourceCatalogAdapterKeySchema = Schema.String; | |
| 18 | +export const SourceCatalogPluginKeySchema = Schema.String; | |
| 19 | 19 | |
| 20 | 20 | export const SourceCatalogVisibilitySchema = Schema.Literal( |
| 21 | 21 | "private", |
| @@ -27,8 +27,7 @@ export const SourceCatalogVisibilitySchema = Schema.Literal( · 5 unmodified lines | ||
| 27 | 27 | export const StoredSourceCatalogRecordSchema = Schema.Struct({ |
| 28 | 28 | id: SourceCatalogIdSchema, |
| 29 | 29 | kind: SourceCatalogKindSchema, |
| 30 | − adapterKey: SourceCatalogAdapterKeySchema, | |
| 31 | − providerKey: Schema.String, | |
| 30 | + pluginKey: SourceCatalogPluginKeySchema, | |
| 32 | 31 | name: Schema.String, |
| 33 | 32 | summary: Schema.NullOr(Schema.String), |
| 34 | 33 | visibility: SourceCatalogVisibilitySchema, |
| @@ -50,7 +49,7 @@ export const StoredSourceCatalogRevisionRecordSchema = Schema.Struct({ · 15 unmodified lines | ||
| 50 | 49 | }); |
| 51 | 50 | |
| 52 | 51 | export type SourceCatalogKind = typeof SourceCatalogKindSchema.Type; |
| 53 | −export type SourceCatalogAdapterKey = typeof SourceCatalogAdapterKeySchema.Type; | |
| 52 | +export type SourceCatalogPluginKey = typeof SourceCatalogPluginKeySchema.Type; | |
| 54 | 53 | export type SourceCatalogVisibility = typeof SourceCatalogVisibilitySchema.Type; |
| 55 | 54 | export type StoredSourceCatalogRecord = typeof StoredSourceCatalogRecordSchema.Type; |
| 56 | 55 | export type StoredSourceCatalogRevisionRecord = typeof StoredSourceCatalogRevisionRecordSchema.Type; |
| @@ -1,48 +0,0 @@ | ||
| 1 | −import { | |
| 2 | − Schema, | |
| 3 | −} from "effect"; | |
| 4 | −export { | |
| 5 | − SourceOauthClientInputSchema, | |
| 6 | − ScopedSourceOauthClientRedirectModeSchema, | |
| 7 | −} from "@executor/source-core"; | |
| 8 | −import { | |
| 9 | − SourceOauthClientInputSchema, | |
| 10 | − ScopedSourceOauthClientRedirectModeSchema, | |
| 11 | −} from "@executor/source-core"; | |
| 12 | − | |
| 13 | −import { | |
| 14 | − TimestampMsSchema, | |
| 15 | −} from "../common"; | |
| 16 | −import { | |
| 17 | − SourceIdSchema, | |
| 18 | − ScopeIdSchema, | |
| 19 | − ScopedSourceOauthClientIdSchema, | |
| 20 | −} from "../ids"; | |
| 21 | − | |
| 22 | −export const ScopedSourceOauthClientMetadataSchema = Schema.Struct({ | |
| 23 | − redirectMode: Schema.optional(ScopedSourceOauthClientRedirectModeSchema), | |
| 24 | −}); | |
| 25 | − | |
| 26 | −export const ScopedSourceOauthClientMetadataJsonSchema = Schema.parseJson( | |
| 27 | − ScopedSourceOauthClientMetadataSchema, | |
| 28 | −); | |
| 29 | − | |
| 30 | −export const ScopedSourceOauthClientSchema = Schema.Struct({ | |
| 31 | − id: ScopedSourceOauthClientIdSchema, | |
| 32 | − scopeId: ScopeIdSchema, | |
| 33 | − sourceId: SourceIdSchema, | |
| 34 | − providerKey: Schema.String, | |
| 35 | − clientId: Schema.String, | |
| 36 | − clientSecretProviderId: Schema.NullOr(Schema.String), | |
| 37 | − clientSecretHandle: Schema.NullOr(Schema.String), | |
| 38 | − clientMetadataJson: Schema.NullOr(Schema.String), | |
| 39 | − createdAt: TimestampMsSchema, | |
| 40 | − updatedAt: TimestampMsSchema, | |
| 41 | −}); | |
| 42 | − | |
| 43 | −export type ScopedSourceOauthClient = typeof ScopedSourceOauthClientSchema.Type; | |
| 44 | −export type ScopedSourceOauthClientRedirectMode = | |
| 45 | − typeof ScopedSourceOauthClientRedirectModeSchema.Type; | |
| 46 | −export type ScopedSourceOauthClientMetadata = | |
| 47 | − typeof ScopedSourceOauthClientMetadataSchema.Type; | |
| 48 | −export type SourceOauthClientInput = typeof SourceOauthClientInputSchema.Type; | |
| @@ -2,12 +2,10 @@ import { · 1 unmodified line | ||
| 2 | 2 | Schema, |
| 3 | 3 | } from "effect"; |
| 4 | 4 | export { |
| 5 | − SourceImportAuthPolicySchema, | |
| 6 | 5 | SourceTransportSchema, |
| 7 | 6 | StringMapSchema, |
| 8 | 7 | } from "@executor/source-core"; |
| 9 | 8 | import { |
| 10 | − SourceImportAuthPolicySchema, | |
| 11 | 9 | SourceTransportSchema, |
| 12 | 10 | StringMapSchema, |
| 13 | 11 | } from "@executor/source-core"; |
| @@ -16,19 +14,11 @@ import { · 2 unmodified lines | ||
| 16 | 14 | TimestampMsSchema, |
| 17 | 15 | } from "../common"; |
| 18 | 16 | import { |
| 19 | − ProviderAuthGrantIdSchema, | |
| 20 | 17 | SourceIdSchema, |
| 21 | 18 | SourceCatalogIdSchema, |
| 22 | 19 | SourceCatalogRevisionIdSchema, |
| 23 | 20 | ScopeIdSchema, |
| 24 | 21 | } from "../ids"; |
| 25 | −import { | |
| 26 | − SecretRefSchema, | |
| 27 | −} from "./auth-artifact"; | |
| 28 | −import { | |
| 29 | − JsonObjectSchema, | |
| 30 | −} from "./source-auth-session"; | |
| 31 | − | |
| 32 | 22 | export const SourceKindSchema = Schema.String; |
| 33 | 23 | |
| 34 | 24 | export const SourceStatusSchema = Schema.Literal( |
| @@ -39,65 +29,6 @@ export const SourceStatusSchema = Schema.Literal( · 4 unmodified lines | ||
| 39 | 29 | "error", |
| 40 | 30 | ); |
| 41 | 31 | |
| 42 | −export const SourceAuthSchema = Schema.Union( | |
| 43 | − Schema.Struct({ | |
| 44 | − kind: Schema.Literal("none"), | |
| 45 | − }), | |
| 46 | − Schema.Struct({ | |
| 47 | − kind: Schema.Literal("bearer"), | |
| 48 | − headerName: Schema.String, | |
| 49 | − prefix: Schema.String, | |
| 50 | − token: SecretRefSchema, | |
| 51 | − }), | |
| 52 | − Schema.Struct({ | |
| 53 | − kind: Schema.Literal("oauth2"), | |
| 54 | − headerName: Schema.String, | |
| 55 | − prefix: Schema.String, | |
| 56 | − accessToken: SecretRefSchema, | |
| 57 | − refreshToken: Schema.NullOr(SecretRefSchema), | |
| 58 | − }), | |
| 59 | − Schema.Struct({ | |
| 60 | − kind: Schema.Literal("oauth2_authorized_user"), | |
| 61 | − headerName: Schema.String, | |
| 62 | − prefix: Schema.String, | |
| 63 | − tokenEndpoint: Schema.String, | |
| 64 | − clientId: Schema.String, | |
| 65 | − clientAuthentication: Schema.Literal("none", "client_secret_post"), | |
| 66 | − clientSecret: Schema.NullOr(SecretRefSchema), | |
| 67 | − refreshToken: SecretRefSchema, | |
| 68 | − grantSet: Schema.NullOr(Schema.Array(Schema.String)), | |
| 69 | − }), | |
| 70 | − Schema.Struct({ | |
| 71 | − kind: Schema.Literal("provider_grant_ref"), | |
| 72 | − grantId: ProviderAuthGrantIdSchema, | |
| 73 | − providerKey: Schema.String, | |
| 74 | − requiredScopes: Schema.Array(Schema.String), | |
| 75 | − headerName: Schema.String, | |
| 76 | − prefix: Schema.String, | |
| 77 | − }), | |
| 78 | − Schema.Struct({ | |
| 79 | − kind: Schema.Literal("mcp_oauth"), | |
| 80 | − redirectUri: Schema.String, | |
| 81 | − accessToken: SecretRefSchema, | |
| 82 | − refreshToken: Schema.NullOr(SecretRefSchema), | |
| 83 | − tokenType: Schema.String, | |
| 84 | − expiresIn: Schema.NullOr(Schema.Number), | |
| 85 | − scope: Schema.NullOr(Schema.String), | |
| 86 | − resourceMetadataUrl: Schema.NullOr(Schema.String), | |
| 87 | − authorizationServerUrl: Schema.NullOr(Schema.String), | |
| 88 | − resourceMetadataJson: Schema.NullOr(Schema.String), | |
| 89 | − authorizationServerMetadataJson: Schema.NullOr(Schema.String), | |
| 90 | − clientInformationJson: Schema.NullOr(Schema.String), | |
| 91 | − }), | |
| 92 | −); | |
| 93 | − | |
| 94 | −export const SourceBindingVersionSchema = Schema.Number; | |
| 95 | − | |
| 96 | −export const SourceBindingSchema = Schema.Struct({ | |
| 97 | − version: SourceBindingVersionSchema, | |
| 98 | − payload: JsonObjectSchema, | |
| 99 | −}); | |
| 100 | − | |
| 101 | 32 | const SourceStorageRowSchema = Schema.Struct({ |
| 102 | 33 | scopeId: ScopeIdSchema, |
| 103 | 34 | sourceId: SourceIdSchema, |
| @@ -109,8 +40,6 @@ const SourceStorageRowSchema = Schema.Struct({ · 5 unmodified lines | ||
| 109 | 40 | status: SourceStatusSchema, |
| 110 | 41 | enabled: Schema.Boolean, |
| 111 | 42 | namespace: Schema.NullOr(Schema.String), |
| 112 | − importAuthPolicy: SourceImportAuthPolicySchema, | |
| 113 | − bindingConfigJson: Schema.String, | |
| 114 | 43 | sourceHash: Schema.NullOr(Schema.String), |
| 115 | 44 | lastError: Schema.NullOr(Schema.String), |
| 116 | 45 | createdAt: TimestampMsSchema, |
| @@ -130,8 +59,6 @@ export const StoredSourceRecordSchema = Schema.transform( · 13 unmodified lines | ||
| 130 | 59 | status: SourceStatusSchema, |
| 131 | 60 | enabled: Schema.Boolean, |
| 132 | 61 | namespace: Schema.NullOr(Schema.String), |
| 133 | − importAuthPolicy: SourceImportAuthPolicySchema, | |
| 134 | − bindingConfigJson: Schema.String, | |
| 135 | 62 | sourceHash: Schema.NullOr(Schema.String), |
| 136 | 63 | lastError: Schema.NullOr(Schema.String), |
| 137 | 64 | createdAt: TimestampMsSchema, |
| @@ -150,8 +77,6 @@ export const StoredSourceRecordSchema = Schema.transform( · 12 unmodified lines | ||
| 150 | 77 | status: row.status, |
| 151 | 78 | enabled: row.enabled, |
| 152 | 79 | namespace: row.namespace, |
| 153 | − importAuthPolicy: row.importAuthPolicy, | |
| 154 | − bindingConfigJson: row.bindingConfigJson, | |
| 155 | 80 | sourceHash: row.sourceHash, |
| 156 | 81 | lastError: row.lastError, |
| 157 | 82 | createdAt: row.createdAt, |
| @@ -168,8 +93,6 @@ export const StoredSourceRecordSchema = Schema.transform( · 10 unmodified lines | ||
| 168 | 93 | status: source.status, |
| 169 | 94 | enabled: source.enabled, |
| 170 | 95 | namespace: source.namespace, |
| 171 | − importAuthPolicy: source.importAuthPolicy, | |
| 172 | − bindingConfigJson: source.bindingConfigJson, | |
| 173 | 96 | sourceHash: source.sourceHash, |
| 174 | 97 | lastError: source.lastError, |
| 175 | 98 | createdAt: source.createdAt, |
| @@ -187,11 +110,6 @@ export const SourceSchema = Schema.Struct({ · 11 unmodified lines | ||
| 187 | 110 | status: SourceStatusSchema, |
| 188 | 111 | enabled: Schema.Boolean, |
| 189 | 112 | namespace: Schema.NullOr(Schema.String), |
| 190 | − bindingVersion: SourceBindingVersionSchema, | |
| 191 | − binding: JsonObjectSchema, | |
| 192 | − importAuthPolicy: SourceImportAuthPolicySchema, | |
| 193 | − importAuth: SourceAuthSchema, | |
| 194 | − auth: SourceAuthSchema, | |
| 195 | 113 | sourceHash: Schema.NullOr(Schema.String), |
| 196 | 114 | lastError: Schema.NullOr(Schema.String), |
| 197 | 115 | createdAt: TimestampMsSchema, |
| @@ -201,9 +119,6 @@ export const SourceSchema = Schema.Struct({ · 3 unmodified lines | ||
| 201 | 119 | export type SourceKind = typeof SourceKindSchema.Type; |
| 202 | 120 | export type SourceStatus = typeof SourceStatusSchema.Type; |
| 203 | 121 | export type SourceTransport = typeof SourceTransportSchema.Type; |
| 204 | −export type SourceImportAuthPolicy = typeof SourceImportAuthPolicySchema.Type; | |
| 205 | −export type SourceAuth = typeof SourceAuthSchema.Type; | |
| 206 | −export type SourceBinding = typeof SourceBindingSchema.Type; | |
| 207 | 122 | export type StoredSourceRecord = typeof StoredSourceRecordSchema.Type; |
| 208 | 123 | export type StringMap = typeof StringMapSchema.Type; |
| 209 | 124 | export type Source = typeof SourceSchema.Type; |
| @@ -1,97 +0,0 @@ | ||
| 1 | −import { | |
| 2 | − ExecutionInteractionIdSchema, | |
| 3 | − JsonObjectSchema, | |
| 4 | − ProviderAuthGrantIdSchema, | |
| 5 | − SourceAuthSchema, | |
| 6 | − SourceImportAuthPolicySchema, | |
| 7 | − SourceKindSchema, | |
| 8 | − SourceSchema, | |
| 9 | − SourceStatusSchema, | |
| 10 | − SourceOauthClientInputSchema, | |
| 11 | − ScopeIdSchema, | |
| 12 | − ScopeOauthClientIdSchema, | |
| 13 | − ScopeOauthClientSchema, | |
| 14 | −} from "../schema"; | |
| 15 | −import * as Schema from "effect/Schema"; | |
| 16 | −import { | |
| 17 | − OptionalTrimmedNonEmptyStringSchema, | |
| 18 | − TrimmedNonEmptyStringSchema, | |
| 19 | −} from "../string-schemas"; | |
| 20 | − | |
| 21 | −const createSourcePayloadRequiredSchema = Schema.Struct({ | |
| 22 | − name: TrimmedNonEmptyStringSchema, | |
| 23 | − kind: SourceKindSchema, | |
| 24 | − endpoint: TrimmedNonEmptyStringSchema, | |
| 25 | −}); | |
| 26 | − | |
| 27 | −const createSourcePayloadOptionalSchema = Schema.Struct({ | |
| 28 | − status: Schema.optional(SourceStatusSchema), | |
| 29 | − enabled: Schema.optional(Schema.Boolean), | |
| 30 | − namespace: Schema.optional(Schema.NullOr(Schema.String)), | |
| 31 | − binding: Schema.optional(JsonObjectSchema), | |
| 32 | − importAuthPolicy: Schema.optional(SourceImportAuthPolicySchema), | |
| 33 | − importAuth: Schema.optional(SourceAuthSchema), | |
| 34 | − auth: Schema.optional(SourceAuthSchema), | |
| 35 | − sourceHash: Schema.optional(Schema.NullOr(Schema.String)), | |
| 36 | − lastError: Schema.optional(Schema.NullOr(Schema.String)), | |
| 37 | −}); | |
| 38 | − | |
| 39 | −export const CreateSourcePayloadSchema = Schema.extend( | |
| 40 | − createSourcePayloadRequiredSchema, | |
| 41 | − createSourcePayloadOptionalSchema, | |
| 42 | −); | |
| 43 | − | |
| 44 | −export type CreateSourcePayload = typeof CreateSourcePayloadSchema.Type; | |
| 45 | − | |
| 46 | −export const UpdateSourcePayloadSchema = Schema.Struct({ | |
| 47 | − name: OptionalTrimmedNonEmptyStringSchema, | |
| 48 | − endpoint: OptionalTrimmedNonEmptyStringSchema, | |
| 49 | − status: Schema.optional(SourceStatusSchema), | |
| 50 | − enabled: Schema.optional(Schema.Boolean), | |
| 51 | − namespace: Schema.optional(Schema.NullOr(Schema.String)), | |
| 52 | − binding: Schema.optional(JsonObjectSchema), | |
| 53 | − importAuthPolicy: Schema.optional(SourceImportAuthPolicySchema), | |
| 54 | − importAuth: Schema.optional(SourceAuthSchema), | |
| 55 | − auth: Schema.optional(SourceAuthSchema), | |
| 56 | − sourceHash: Schema.optional(Schema.NullOr(Schema.String)), | |
| 57 | − lastError: Schema.optional(Schema.NullOr(Schema.String)), | |
| 58 | −}); | |
| 59 | − | |
| 60 | −export type UpdateSourcePayload = typeof UpdateSourcePayloadSchema.Type; | |
| 61 | − | |
| 62 | −export const CredentialPageUrlParamsSchema = Schema.Struct({ | |
| 63 | − interactionId: ExecutionInteractionIdSchema, | |
| 64 | −}); | |
| 65 | − | |
| 66 | −export const CredentialSubmitPayloadSchema = Schema.Struct({ | |
| 67 | − action: Schema.optional(Schema.Literal("submit", "continue", "cancel")), | |
| 68 | − token: Schema.optional(Schema.String), | |
| 69 | −}); | |
| 70 | − | |
| 71 | −export const CredentialOauthCompleteUrlParamsSchema = Schema.Struct({ | |
| 72 | − state: Schema.String, | |
| 73 | − code: Schema.optional(Schema.String), | |
| 74 | − error: Schema.optional(Schema.String), | |
| 75 | − error_description: Schema.optional(Schema.String), | |
| 76 | −}); | |
| 77 | − | |
| 78 | −export const ScopeOauthClientQuerySchema = Schema.Struct({ | |
| 79 | − providerKey: Schema.String, | |
| 80 | −}); | |
| 81 | − | |
| 82 | −export const CreateScopeOauthClientPayloadSchema = Schema.Struct({ | |
| 83 | − providerKey: Schema.String, | |
| 84 | − label: Schema.optional(Schema.NullOr(Schema.String)), | |
| 85 | − oauthClient: SourceOauthClientInputSchema, | |
| 86 | −}); | |
| 87 | − | |
| 88 | −export type CreateScopeOauthClientPayload = | |
| 89 | − typeof CreateScopeOauthClientPayloadSchema.Type; | |
| 90 | − | |
| 91 | −export const oauthClientIdParam = ScopeOauthClientIdSchema; | |
| 92 | −export const grantIdParam = ProviderAuthGrantIdSchema; | |
| 93 | − | |
| 94 | −export { | |
| 95 | − ScopeIdSchema, | |
| 96 | − ScopeOauthClientSchema, | |
| 97 | −}; | |
| @@ -101,7 +101,7 @@ const loadSourceCatalogOrEmpty = (input: { · 100 unmodified lines | ||
| 101 | 101 | const executableDetails = (tool: LoadedSourceCatalogTool) => { |
| 102 | 102 | const display = tool.executable.display ?? {}; |
| 103 | 103 | return { |
| 104 | − protocol: display.protocol ?? tool.executable.adapterKey, | |
| 104 | + protocol: display.protocol ?? tool.executable.pluginKey, | |
| 105 | 105 | method: display.method ?? null, |
| 106 | 106 | pathTemplate: display.pathTemplate ?? null, |
| 107 | 107 | rawToolId: display.rawToolId ?? tool.path.split(".").at(-1) ?? null, |
| @@ -255,7 +255,7 @@ export const inspectionToolDetailFromTool = ( · 147 unmodified lines | ||
| 255 | 255 | jsonSection("Capability", tool.capability), |
| 256 | 256 | jsonSection("Executable", { |
| 257 | 257 | id: tool.executable.id, |
| 258 | − adapterKey: tool.executable.adapterKey, | |
| 258 | + pluginKey: tool.executable.pluginKey, | |
| 259 | 259 | bindingVersion: tool.executable.bindingVersion, |
| 260 | 260 | binding: tool.executable.binding, |
| 261 | 261 | projection: tool.executable.projection, |
| @@ -1,7 +1,3 @@ | ||
| 1 | −import type { | |
| 2 | − CreateSourcePayload, | |
| 3 | − UpdateSourcePayload, | |
| 4 | −} from "./contracts"; | |
| 5 | 1 | import { |
| 6 | 2 | type ScopeId, |
| 7 | 3 | SourceIdSchema, |
| @@ -12,12 +8,9 @@ import * as Either from "effect/Either"; · 4 unmodified lines | ||
| 12 | 8 | import * as Effect from "effect/Effect"; |
| 13 | 9 | |
| 14 | 10 | import { |
| 15 | − createSourceFromPayload, | |
| 16 | − updateSourceFromPayload, | |
| 11 | + normalizeSourceForCreate, | |
| 12 | + normalizeSourceForSave, | |
| 17 | 13 | } from "../runtime/sources/source-definitions"; |
| 18 | −import { | |
| 19 | − getSourceAdapterForSource, | |
| 20 | −} from "../runtime/sources/source-adapters"; | |
| 21 | 14 | import { |
| 22 | 15 | mapPersistenceError, |
| 23 | 16 | } from "../runtime/policy/operations-shared"; |
| @@ -43,9 +36,6 @@ const sourceOps = { · 19 unmodified lines | ||
| 43 | 36 | remove: operationErrors("sources.remove"), |
| 44 | 37 | } as const; |
| 45 | 38 | |
| 46 | −const shouldAutoProbeSource = (source: Source): boolean => | |
| 47 | − getSourceAdapterForSource(source).shouldAutoProbe(source); | |
| 48 | − | |
| 49 | 39 | const syncArtifactsForSource = (input: { |
| 50 | 40 | store: ExecutorStateStoreShape; |
| 51 | 41 | sourceStore: Effect.Effect.Success<typeof RuntimeSourceStoreService>; |
| @@ -56,57 +46,21 @@ const syncArtifactsForSource = (input: { · 4 unmodified lines | ||
| 56 | 46 | Effect.gen(function* () { |
| 57 | 47 | const catalogSyncService = yield* RuntimeSourceCatalogSyncService; |
| 58 | 48 | |
| 59 | − // For HTTP-backed source kinds that can validate themselves from a remote | |
| 60 | − // document, automatically attempt to probe and connect. This mirrors the | |
| 61 | − // addExecutorSource flow by overriding status to "connected" so the sync | |
| 62 | − // guard passes. | |
| 63 | − const autoProbe = shouldAutoProbeSource(input.source); | |
| 64 | − const sourceForSync = autoProbe | |
| 65 | − ? { ...input.source, status: "connected" as const } | |
| 66 | − : input.source; | |
| 67 | − | |
| 68 | 49 | const synced = yield* Effect.either( |
| 69 | 50 | catalogSyncService.sync({ |
| 70 | − source: sourceForSync, | |
| 51 | + source: input.source, | |
| 71 | 52 | actorScopeId: input.actorScopeId, |
| 72 | 53 | }), |
| 73 | 54 | ); |
| 74 | 55 | |
| 75 | 56 | return yield* Either.match(synced, { |
| 76 | − onRight: () => | |
| 77 | − Effect.gen(function* () { | |
| 78 | − if (autoProbe) { | |
| 79 | − const connectedSource = yield* updateSourceFromPayload({ | |
| 80 | − source: input.source, | |
| 81 | − payload: { status: "connected", lastError: null }, | |
| 82 | − now: Date.now(), | |
| 83 | − }).pipe( | |
| 84 | − Effect.mapError((cause) => | |
| 85 | − input.operation.badRequest( | |
| 86 | − "Failed updating source status", | |
| 87 | − cause instanceof Error ? cause.message : String(cause), | |
| 88 | − ), | |
| 89 | − ), | |
| 90 | − ); | |
| 91 | − yield* mapPersistenceError( | |
| 92 | − input.operation.child("source_connected"), | |
| 93 | − input.sourceStore.persistSource(connectedSource, { | |
| 94 | − actorScopeId: input.actorScopeId, | |
| 95 | − }), | |
| 96 | − ); | |
| 97 | − return connectedSource; | |
| 98 | − } | |
| 99 | − return input.source; | |
| 100 | − }), | |
| 57 | + onRight: () => Effect.succeed(input.source), | |
| 101 | 58 | onLeft: (error) => |
| 102 | 59 | Effect.gen(function* () { |
| 103 | − if ( | |
| 104 | − autoProbe || | |
| 105 | − (input.source.enabled && input.source.status === "connected") | |
| 106 | − ) { | |
| 107 | − const erroredSource = yield* updateSourceFromPayload({ | |
| 108 | − source: input.source, | |
| 109 | − payload: { | |
| 60 | + if (input.source.enabled && input.source.status === "connected") { | |
| 61 | + const erroredSource = yield* normalizeSourceForSave({ | |
| 62 | + source: { | |
| 63 | + ...input.source, | |
| 110 | 64 | status: "error", |
| 111 | 65 | lastError: error.message, |
| 112 | 66 | }, |
| @@ -144,35 +98,36 @@ export const listSources = (input: { · 31 unmodified lines | ||
| 144 | 98 | Effect.gen(function* () { |
| 145 | 99 | const sourceStore = yield* RuntimeSourceStoreService; |
| 146 | 100 | |
| 147 | − return yield* sourceStore | |
| 148 | − .loadSourcesInScope(input.scopeId, { | |
| 149 | − actorScopeId: input.actorScopeId, | |
| 150 | − }) | |
| 151 | − .pipe( | |
| 152 | − Effect.mapError((error) => | |
| 153 | − sourceOps.list.unknownStorage( | |
| 154 | − error, | |
| 155 | − "Failed projecting stored sources", | |
| 156 | − ), | |
| 101 | + return yield* sourceStore.loadSourcesInScope(input.scopeId, { | |
| 102 | + actorScopeId: input.actorScopeId, | |
| 103 | + }).pipe( | |
| 104 | + Effect.mapError((error) => | |
| 105 | + sourceOps.list.unknownStorage( | |
| 106 | + error, | |
| 107 | + "Failed projecting stored sources", | |
| 157 | 108 | ), |
| 158 | − ); | |
| 109 | + ), | |
| 110 | + ); | |
| 159 | 111 | }), |
| 160 | 112 | ); |
| 161 | 113 | |
| 162 | −export const createSource = (input: { | |
| 114 | +export const createManagedSource = (input: { | |
| 163 | 115 | scopeId: ScopeId; |
| 164 | 116 | actorScopeId: ScopeId; |
| 165 | − payload: CreateSourcePayload; | |
| 117 | + source: Omit< | |
| 118 | + Source, | |
| 119 | + "id" | "scopeId" | "createdAt" | "updatedAt" | |
| 120 | + >; | |
| 166 | 121 | }) => |
| 167 | 122 | Effect.flatMap(ExecutorStateStore, (store) => |
| 168 | 123 | Effect.gen(function* () { |
| 169 | 124 | const sourceStore = yield* RuntimeSourceStoreService; |
| 170 | 125 | const now = Date.now(); |
| 171 | 126 | |
| 172 | − const source = yield* createSourceFromPayload({ | |
| 127 | + const source = yield* normalizeSourceForCreate({ | |
| 173 | 128 | scopeId: input.scopeId, |
| 174 | 129 | sourceId: SourceIdSchema.make(`src_${crypto.randomUUID()}`), |
| 175 | − payload: input.payload, | |
| 130 | + source: input.source, | |
| 176 | 131 | now, |
| 177 | 132 | }).pipe( |
| 178 | 133 | Effect.mapError((cause) => |
| @@ -211,62 +166,36 @@ export const getSource = (input: { · 32 unmodified lines | ||
| 211 | 166 | Effect.gen(function* () { |
| 212 | 167 | const sourceStore = yield* RuntimeSourceStoreService; |
| 213 | 168 | |
| 214 | − return yield* sourceStore | |
| 215 | − .loadSourceById({ | |
| 216 | − scopeId: input.scopeId, | |
| 217 | − sourceId: input.sourceId, | |
| 218 | − actorScopeId: input.actorScopeId, | |
| 219 | − }) | |
| 220 | − .pipe( | |
| 221 | − Effect.mapError((cause) => | |
| 222 | − cause instanceof Error && | |
| 223 | − cause.message.startsWith("Source not found:") | |
| 224 | − ? sourceOps.get.notFound( | |
| 225 | − "Source not found", | |
| 226 | − `scopeId=${input.scopeId} sourceId=${input.sourceId}`, | |
| 227 | − ) | |
| 228 | − : sourceOps.get.unknownStorage( | |
| 229 | − cause, | |
| 230 | − "Failed projecting stored source", | |
| 231 | − ), | |
| 232 | − ), | |
| 233 | − ); | |
| 169 | + return yield* sourceStore.loadSourceById({ | |
| 170 | + scopeId: input.scopeId, | |
| 171 | + sourceId: input.sourceId, | |
| 172 | + actorScopeId: input.actorScopeId, | |
| 173 | + }).pipe( | |
| 174 | + Effect.mapError((cause) => | |
| 175 | + cause instanceof Error && | |
| 176 | + cause.message.startsWith("Source not found:") | |
| 177 | + ? sourceOps.get.notFound( | |
| 178 | + "Source not found", | |
| 179 | + `scopeId=${input.scopeId} sourceId=${input.sourceId}`, | |
| 180 | + ) | |
| 181 | + : sourceOps.get.unknownStorage( | |
| 182 | + cause, | |
| 183 | + "Failed projecting stored source", | |
| 184 | + ), | |
| 185 | + ), | |
| 186 | + ); | |
| 234 | 187 | }), |
| 235 | 188 | ); |
| 236 | 189 | |
| 237 | −export const updateSource = (input: { | |
| 238 | − scopeId: ScopeId; | |
| 239 | − sourceId: SourceId; | |
| 190 | +export const saveManagedSource = (input: { | |
| 240 | 191 | actorScopeId: ScopeId; |
| 241 | − payload: UpdateSourcePayload; | |
| 192 | + source: Source; | |
| 242 | 193 | }) => |
| 243 | 194 | Effect.flatMap(ExecutorStateStore, (store) => |
| 244 | 195 | Effect.gen(function* () { |
| 245 | 196 | const sourceStore = yield* RuntimeSourceStoreService; |
| 246 | − const existingSource = yield* sourceStore | |
| 247 | − .loadSourceById({ | |
| 248 | − scopeId: input.scopeId, | |
| 249 | − sourceId: input.sourceId, | |
| 250 | − actorScopeId: input.actorScopeId, | |
| 251 | − }) | |
| 252 | − .pipe( | |
| 253 | − Effect.mapError((cause) => | |
| 254 | − cause instanceof Error && | |
| 255 | − cause.message.startsWith("Source not found:") | |
| 256 | − ? sourceOps.update.notFound( | |
| 257 | − "Source not found", | |
| 258 | − `scopeId=${input.scopeId} sourceId=${input.sourceId}`, | |
| 259 | − ) | |
| 260 | − : sourceOps.update.unknownStorage( | |
| 261 | − cause, | |
| 262 | − "Failed projecting stored source", | |
| 263 | − ), | |
| 264 | − ), | |
| 265 | − ); | |
| 266 | − | |
| 267 | − const updatedSource = yield* updateSourceFromPayload({ | |
| 268 | − source: existingSource, | |
| 269 | − payload: input.payload, | |
| 197 | + const updatedSource = yield* normalizeSourceForSave({ | |
| 198 | + source: input.source, | |
| 270 | 199 | now: Date.now(), |
| 271 | 200 | }).pipe( |
| 272 | 201 | Effect.mapError((cause) => |
| @@ -15,6 +15,9 @@ · 14 unmodified lines | ||
| 15 | 15 | "@effect/platform": "catalog:", |
| 16 | 16 | "@effect/platform-node": "catalog:", |
| 17 | 17 | "@executor/executor-mcp": "workspace:*", |
| 18 | + "@executor/plugin-openapi-http": "workspace:*", | |
| 19 | + "@executor/plugin-openapi-shared": "workspace:*", | |
| 20 | + "@executor/plugin-openapi-sdk": "workspace:*", | |
| 18 | 21 | "@executor/platform-api": "workspace:*", |
| 19 | 22 | "@executor/platform-internal": "workspace:*", |
| 20 | 23 | "@executor/platform-sdk": "workspace:*", |
| @@ -8,6 +8,10 @@ import { dirname, extname, resolve } from "node:path"; · 7 unmodified lines | ||
| 8 | 8 | import { Readable } from "node:stream"; |
| 9 | 9 | import { FileSystem, HttpApiBuilder, HttpServer } from "@effect/platform"; |
| 10 | 10 | import { NodeFileSystem } from "@effect/platform-node"; |
| 11 | +import { openApiHttpPlugin } from "@executor/plugin-openapi-http"; | |
| 12 | +import { | |
| 13 | + openApiSdkPlugin, | |
| 14 | +} from "@executor/plugin-openapi-sdk"; | |
| 11 | 15 | import { |
| 12 | 16 | createExecutorApiLayer, |
| 13 | 17 | } from "@executor/platform-api/http"; |
| @@ -44,6 +48,9 @@ import { · 30 unmodified lines | ||
| 44 | 48 | tracingSearchUrl, |
| 45 | 49 | } from "./tracing"; |
| 46 | 50 | import { platformServerEffectError } from "./effect-errors"; |
| 51 | +import { createFileOpenApiSourceStorage } from "./openapi-source-storage"; | |
| 52 | + | |
| 53 | +export { createFileOpenApiSourceStorage } from "./openapi-source-storage"; | |
| 47 | 54 | |
| 48 | 55 | export { |
| 49 | 56 | DEFAULT_EXECUTOR_DATA_DIR, |
| @@ -107,6 +114,7 @@ type ExecutorMcpHandler = ReturnType<typeof createExecutorMcpRequestHandler>; · 57 unmodified lines | ||
| 107 | 114 | const EXECUTOR_NPM_DIST_TAGS_PATHNAME = "/v1/app/npm/dist-tags"; |
| 108 | 115 | const EXECUTOR_NPM_DIST_TAGS_URL = |
| 109 | 116 | "https://registry.npmjs.org/-/package/executor/dist-tags"; |
| 117 | +const executorHttpPlugins = [openApiHttpPlugin()] as const; | |
| 110 | 118 | |
| 111 | 119 | const disposeExecutor = (executor: Executor) => |
| 112 | 120 | Effect.tryPromise({ |
| @@ -125,6 +133,13 @@ const createExecutorRuntime = ( · 12 unmodified lines | ||
| 125 | 133 | workspaceRoot: options.workspaceRoot, |
| 126 | 134 | localDataDir, |
| 127 | 135 | }), |
| 136 | + plugins: [ | |
| 137 | + openApiSdkPlugin({ | |
| 138 | + storage: createFileOpenApiSourceStorage({ | |
| 139 | + rootDir: resolve(localDataDir, "plugins", "openapi", "sources"), | |
| 140 | + }), | |
| 141 | + }), | |
| 142 | + ] as const, | |
| 128 | 143 | executionResolver: options.executionResolver, |
| 129 | 144 | createInternalToolMap: createWorkspaceExecutorAdminToolMap, |
| 130 | 145 | resolveSecretMaterial: options.resolveSecretMaterial, |
| @@ -140,20 +155,21 @@ const createExecutorApiWebHandler = ( · 9 unmodified lines | ||
| 140 | 155 | tracingRuntime: ReturnType<typeof createLocalTracingRuntimeFromEnv>, |
| 141 | 156 | ) => |
| 142 | 157 | Effect.acquireRelease( |
| 143 | − Effect.sync(() => | |
| 144 | − HttpApiBuilder.toWebHandler( | |
| 145 | − Layer.merge( | |
| 146 | − HttpApiBuilder.middlewareOpenApi({ path: "/v1/openapi.json" }).pipe( | |
| 147 | − Layer.provideMerge( | |
| 148 | − createExecutorApiLayer(executor).pipe( | |
| 149 | − Layer.provideMerge(tracingRuntime?.layer ?? Layer.empty), | |
| 150 | − ), | |
| 151 | − ) | |
| 158 | + Effect.sync(() => { | |
| 159 | + const apiLayer: any = HttpApiBuilder.middlewareOpenApi({ | |
| 160 | + path: "/v1/openapi.json", | |
| 161 | + }).pipe( | |
| 162 | + Layer.provideMerge( | |
| 163 | + createExecutorApiLayer(executor, { | |
| 164 | + plugins: executorHttpPlugins, | |
| 165 | + }).pipe( | |
| 166 | + Layer.provideMerge(tracingRuntime?.layer ?? Layer.empty), | |
| 152 | 167 | ), |
| 153 | − HttpServer.layerContext, | |
| 154 | 168 | ), |
| 155 | − ), | |
| 156 | − ), | |
| 169 | + ); | |
| 170 | + const webLayer: any = Layer.merge(apiLayer, HttpServer.layerContext); | |
| 171 | + return HttpApiBuilder.toWebHandler(webLayer); | |
| 172 | + }), | |
| 157 | 173 | (handler: ExecutorApiWebHandler) => Effect.tryPromise({ try: () => handler.dispose(), catch: (cause) => cause instanceof Error ? cause : new Error(String(cause ?? "web handler dispose failed")) }).pipe(Effect.orDie), |
| 158 | 174 | ); |
| 159 | 175 | |
| @@ -0,0 +1,92 @@ | ||
| 1 | +import { join } from "node:path"; | |
| 2 | +import { FileSystem } from "@effect/platform"; | |
| 3 | +import { NodeFileSystem } from "@effect/platform-node"; | |
| 4 | +import type { OpenApiSourceStorage } from "@executor/plugin-openapi-sdk"; | |
| 5 | +import { | |
| 6 | + OpenApiStoredSourceDataSchema, | |
| 7 | + type OpenApiStoredSourceData, | |
| 8 | +} from "@executor/plugin-openapi-shared"; | |
| 9 | +import * as Effect from "effect/Effect"; | |
| 10 | +import * as Schema from "effect/Schema"; | |
| 11 | + | |
| 12 | +const decodeStoredSourceData = Schema.decodeUnknownSync(OpenApiStoredSourceDataSchema); | |
| 13 | +const encodeStoredSourceData = Schema.encodeSync(OpenApiStoredSourceDataSchema); | |
| 14 | + | |
| 15 | +const storagePath = (input: { | |
| 16 | + rootDir: string; | |
| 17 | + scopeId: string; | |
| 18 | + sourceId: string; | |
| 19 | +}) => join(input.rootDir, input.scopeId, `${input.sourceId}.json`); | |
| 20 | + | |
| 21 | +const toError = (cause: unknown): Error => | |
| 22 | + cause instanceof Error ? cause : new Error(String(cause)); | |
| 23 | + | |
| 24 | +const bindNodeFileSystem = <A, E>( | |
| 25 | + effect: Effect.Effect<A, E, FileSystem.FileSystem>, | |
| 26 | +): Effect.Effect<A, E, never> => | |
| 27 | + effect.pipe(Effect.provide(NodeFileSystem.layer)); | |
| 28 | + | |
| 29 | +const readStoredSourceData = ( | |
| 30 | + path: string, | |
| 31 | +): Effect.Effect<OpenApiStoredSourceData | null, Error, never> => | |
| 32 | + bindNodeFileSystem( | |
| 33 | + Effect.gen(function* () { | |
| 34 | + const fileSystem = yield* FileSystem.FileSystem; | |
| 35 | + const exists = yield* fileSystem.exists(path).pipe(Effect.mapError(toError)); | |
| 36 | + if (!exists) { | |
| 37 | + return null; | |
| 38 | + } | |
| 39 | + | |
| 40 | + const contents = yield* fileSystem.readFileString(path, "utf8").pipe( | |
| 41 | + Effect.mapError(toError), | |
| 42 | + ); | |
| 43 | + | |
| 44 | + return decodeStoredSourceData(JSON.parse(contents)); | |
| 45 | + }), | |
| 46 | + ); | |
| 47 | + | |
| 48 | +export const createFileOpenApiSourceStorage = (input: { | |
| 49 | + rootDir: string; | |
| 50 | +}): OpenApiSourceStorage => ({ | |
| 51 | + get: ({ scopeId, sourceId }) => | |
| 52 | + readStoredSourceData( | |
| 53 | + storagePath({ | |
| 54 | + rootDir: input.rootDir, | |
| 55 | + scopeId, | |
| 56 | + sourceId, | |
| 57 | + }), | |
| 58 | + ), | |
| 59 | + put: ({ scopeId, sourceId, value }) => | |
| 60 | + bindNodeFileSystem( | |
| 61 | + Effect.gen(function* () { | |
| 62 | + const fileSystem = yield* FileSystem.FileSystem; | |
| 63 | + const path = storagePath({ | |
| 64 | + rootDir: input.rootDir, | |
| 65 | + scopeId, | |
| 66 | + sourceId, | |
| 67 | + }); | |
| 68 | + yield* fileSystem.makeDirectory(join(input.rootDir, scopeId), { | |
| 69 | + recursive: true, | |
| 70 | + }).pipe(Effect.mapError(toError)); | |
| 71 | + yield* fileSystem.writeFileString( | |
| 72 | + path, | |
| 73 | + `${JSON.stringify(encodeStoredSourceData(value), null, 2)}\n`, | |
| 74 | + ).pipe(Effect.mapError(toError)); | |
| 75 | + }), | |
| 76 | + ), | |
| 77 | + remove: ({ scopeId, sourceId }) => | |
| 78 | + bindNodeFileSystem( | |
| 79 | + Effect.gen(function* () { | |
| 80 | + const fileSystem = yield* FileSystem.FileSystem; | |
| 81 | + const path = storagePath({ | |
| 82 | + rootDir: input.rootDir, | |
| 83 | + scopeId, | |
| 84 | + sourceId, | |
| 85 | + }); | |
| 86 | + const exists = yield* fileSystem.exists(path).pipe(Effect.mapError(toError)); | |
| 87 | + if (exists) { | |
| 88 | + yield* fileSystem.remove(path).pipe(Effect.mapError(toError)); | |
| 89 | + } | |
| 90 | + }), | |
| 91 | + ), | |
| 92 | +}); | |
| @@ -1,3 +0,0 @@ | ||
| 1 | −import type { SourceAdapter } from "@executor/source-core"; | |
| 2 | − | |
| 3 | −export const externalSourceAdapters = [] as const satisfies readonly SourceAdapter[]; | |
| @@ -117,7 +117,7 @@ const createServiceScope = (input: { · 116 unmodified lines | ||
| 117 | 117 | export const buildCatalogFragment = (input: { |
| 118 | 118 | source: Pick< |
| 119 | 119 | Source, |
| 120 | − "id" | "kind" | "name" | "endpoint" | "namespace" | "binding" | "auth" | |
| 120 | + "id" | "kind" | "name" | "endpoint" | "namespace" | |
| 121 | 121 | >; |
| 122 | 122 | documents: readonly CatalogSourceDocumentInput[]; |
| 123 | 123 | serviceScopeDefaults?: Scope["defaults"]; |
| @@ -120,19 +120,17 @@ export const interactionForEffect = ( · 119 unmodified lines | ||
| 120 | 120 | }); |
| 121 | 121 | |
| 122 | 122 | export const createCatalogImportMetadata = (input: { |
| 123 | − source: Pick<Source, "kind" | "endpoint" | "sourceHash" | "binding" | "auth">; | |
| 124 | − adapterKey: string; | |
| 123 | + source: Pick<Source, "kind" | "endpoint" | "sourceHash">; | |
| 124 | + pluginKey: string; | |
| 125 | 125 | }): ImportMetadata => ({ |
| 126 | 126 | sourceKind: sourceKindFromSource(input.source), |
| 127 | − adapterKey: input.adapterKey, | |
| 127 | + pluginKey: input.pluginKey, | |
| 128 | 128 | importerVersion: "ir.v1.snapshot_builder", |
| 129 | 129 | importedAt: new Date().toISOString(), |
| 130 | 130 | sourceConfigHash: |
| 131 | 131 | input.source.sourceHash ?? |
| 132 | 132 | stableHash({ |
| 133 | 133 | endpoint: input.source.endpoint, |
| 134 | − binding: input.source.binding, | |
| 135 | − auth: input.source.auth?.kind ?? null, | |
| 136 | 134 | }), |
| 137 | 135 | }); |
| 138 | 136 | |
| @@ -1,90 +0,0 @@ | ||
| 1 | −import * as Schema from "effect/Schema"; | |
| 2 | − | |
| 3 | −import { createSourceAdapterRegistry } from "./registry"; | |
| 4 | −import type { SourceAdapter, SourceAdapterInputSchema } from "./types"; | |
| 5 | − | |
| 6 | −type SchemaTypeOf<TSchema> = TSchema extends { readonly Type: infer T } ? T : never; | |
| 7 | −type AdapterUnion<TAdapters extends readonly SourceAdapter[]> = TAdapters[number]; | |
| 8 | −type ConnectPayloadSchema<TAdapters extends readonly SourceAdapter[]> = | |
| 9 | − NonNullable<AdapterUnion<TAdapters>["connectPayloadSchema"]>; | |
| 10 | −type ExecutorAddInputSchema<TAdapters extends readonly SourceAdapter[]> = | |
| 11 | − NonNullable<AdapterUnion<TAdapters>["executorAddInputSchema"]>; | |
| 12 | − | |
| 13 | −export type ConnectableSourceAdapter<TAdapter extends SourceAdapter = SourceAdapter> = TAdapter & { | |
| 14 | − connectPayloadSchema: SourceAdapterInputSchema; | |
| 15 | −}; | |
| 16 | − | |
| 17 | −export type ExecutorAddableSourceAdapter<TAdapter extends SourceAdapter = SourceAdapter> = TAdapter & { | |
| 18 | − executorAddInputSchema: SourceAdapterInputSchema; | |
| 19 | −}; | |
| 20 | − | |
| 21 | −export type LocalConfigurableSourceAdapter<TAdapter extends SourceAdapter = SourceAdapter> = TAdapter & { | |
| 22 | − localConfigBindingSchema: SourceAdapterInputSchema; | |
| 23 | −}; | |
| 24 | − | |
| 25 | −const isConnectableSourceAdapter = <TAdapter extends SourceAdapter>( | |
| 26 | − adapter: TAdapter, | |
| 27 | −): adapter is ConnectableSourceAdapter<TAdapter> => | |
| 28 | − adapter.connectPayloadSchema !== null; | |
| 29 | − | |
| 30 | −const isExecutorAddableSourceAdapter = <TAdapter extends SourceAdapter>( | |
| 31 | − adapter: TAdapter, | |
| 32 | −): adapter is ExecutorAddableSourceAdapter<TAdapter> => | |
| 33 | − adapter.executorAddInputSchema !== null; | |
| 34 | − | |
| 35 | −const isLocalConfigurableSourceAdapter = <TAdapter extends SourceAdapter>( | |
| 36 | − adapter: TAdapter, | |
| 37 | −): adapter is LocalConfigurableSourceAdapter<TAdapter> => | |
| 38 | − adapter.localConfigBindingSchema !== null; | |
| 39 | − | |
| 40 | −const asSchemaTuple = ( | |
| 41 | − schemas: ReadonlyArray<Schema.Schema<any, any, never>>, | |
| 42 | −): [ | |
| 43 | − Schema.Schema<any, any, never>, | |
| 44 | − Schema.Schema<any, any, never>, | |
| 45 | − ...Array<Schema.Schema<any, any, never>>, | |
| 46 | −] => schemas as [ | |
| 47 | − Schema.Schema<any, any, never>, | |
| 48 | − Schema.Schema<any, any, never>, | |
| 49 | − ...Array<Schema.Schema<any, any, never>>, | |
| 50 | −]; | |
| 51 | − | |
| 52 | −const DisabledSourceAdapterSchema = Schema.Struct({ | |
| 53 | − __sourcePluginRegistrationRequired: Schema.Literal(true), | |
| 54 | −}) as unknown as SourceAdapterInputSchema; | |
| 55 | − | |
| 56 | −const createSchemaFromAdapters = <TSchema extends SourceAdapterInputSchema>( | |
| 57 | − schemas: ReadonlyArray<TSchema>, | |
| 58 | − _label: string, | |
| 59 | −): TSchema => | |
| 60 | − (schemas.length === 0 | |
| 61 | − ? DisabledSourceAdapterSchema | |
| 62 | − : schemas.length === 1 | |
| 63 | − ? schemas[0]! | |
| 64 | − : Schema.Union(...asSchemaTuple(schemas))) as TSchema; | |
| 65 | − | |
| 66 | −export const createSourceAdapterComposition = <const TAdapters extends readonly SourceAdapter[]>( | |
| 67 | − adapters: TAdapters, | |
| 68 | −) => { | |
| 69 | − const connectableSourceAdapters = adapters.filter(isConnectableSourceAdapter); | |
| 70 | − const executorAddableSourceAdapters = adapters.filter(isExecutorAddableSourceAdapter); | |
| 71 | − const localConfigurableSourceAdapters = adapters.filter(isLocalConfigurableSourceAdapter); | |
| 72 | − const registry = createSourceAdapterRegistry(adapters); | |
| 73 | − | |
| 74 | − return { | |
| 75 | − connectableSourceAdapters, | |
| 76 | − connectPayloadSchema: createSchemaFromAdapters( | |
| 77 | − connectableSourceAdapters.map((adapter) => adapter.connectPayloadSchema), | |
| 78 | − "connect payload schema", | |
| 79 | − ) as Schema.Schema<SchemaTypeOf<ConnectPayloadSchema<TAdapters>>, any, never>, | |
| 80 | − executorAddableSourceAdapters, | |
| 81 | − executorAddInputSchema: createSchemaFromAdapters( | |
| 82 | − executorAddableSourceAdapters.map((adapter) => adapter.executorAddInputSchema), | |
| 83 | − "executor add input schema", | |
| 84 | − ) as Schema.Schema<SchemaTypeOf<ExecutorAddInputSchema<TAdapters>>, any, never>, | |
| 85 | − localConfigurableSourceAdapters, | |
| 86 | − ...registry, | |
| 87 | − }; | |
| 88 | −}; | |
| 89 | − | |
| 90 | −export type SourceAdapterComposition = ReturnType<typeof createSourceAdapterComposition>; | |
| @@ -1,10 +1,8 @@ | ||
| 1 | 1 | export * from "./catalog"; |
| 2 | 2 | export * from "./catalog-sync-result"; |
| 3 | −export * from "./composition"; | |
| 4 | 3 | export * from "./discovery"; |
| 5 | 4 | export * from "./discovery-models"; |
| 6 | 5 | export * from "./effect-errors"; |
| 7 | −export * from "./registry"; | |
| 8 | 6 | export * from "./shared"; |
| 9 | 7 | export * from "./source-models"; |
| 10 | 8 | export * from "./types"; |
| @@ -1,44 +0,0 @@ | ||
| 1 | −import type { Source, SourceCatalogKind } from "./source-models"; | |
| 2 | −import type { SourceAdapter } from "./types"; | |
| 3 | − | |
| 4 | −export const createSourceAdapterRegistry = <const TAdapters extends readonly SourceAdapter[]>( | |
| 5 | − adapters: TAdapters, | |
| 6 | −) => { | |
| 7 | − const adaptersByKey = new Map<string, SourceAdapter>( | |
| 8 | − adapters.map((adapter) => [adapter.key, adapter]), | |
| 9 | − ); | |
| 10 | − | |
| 11 | − const getSourceAdapter = (key: string): SourceAdapter => { | |
| 12 | − const adapter = adaptersByKey.get(key); | |
| 13 | − if (!adapter) { | |
| 14 | − throw new Error(`Unsupported source adapter: ${key}`); | |
| 15 | − } | |
| 16 | − | |
| 17 | − return adapter; | |
| 18 | − }; | |
| 19 | − | |
| 20 | − const getSourceAdapterForSource = (source: Pick<Source, "kind">): SourceAdapter => | |
| 21 | − getSourceAdapter(source.kind); | |
| 22 | − | |
| 23 | − const findSourceAdapterByProviderKey = (providerKey: string): SourceAdapter | null => | |
| 24 | − adapters.find((adapter) => adapter.providerKey === providerKey) ?? null; | |
| 25 | − | |
| 26 | − return { | |
| 27 | − adapters, | |
| 28 | − getSourceAdapter, | |
| 29 | − getSourceAdapterForSource, | |
| 30 | − findSourceAdapterByProviderKey, | |
| 31 | − sourceBindingStateFromSource: (source: Source) => | |
| 32 | − getSourceAdapterForSource(source).bindingStateFromSource(source), | |
| 33 | − sourceAdapterCatalogKind: (key: string): SourceCatalogKind => | |
| 34 | − getSourceAdapter(key).catalogKind, | |
| 35 | − sourceAdapterRequiresInteractiveConnect: (key: string): boolean => | |
| 36 | − getSourceAdapter(key).connectStrategy === "interactive", | |
| 37 | − sourceAdapterUsesCredentialManagedAuth: (key: string): boolean => | |
| 38 | − getSourceAdapter(key).credentialStrategy === "credential_managed", | |
| 39 | − isInternalSourceAdapter: (key: string): boolean => | |
| 40 | − getSourceAdapter(key).catalogKind === "internal", | |
| 41 | − }; | |
| 42 | −}; | |
| 43 | − | |
| 44 | −export type SourceAdapterRegistry = ReturnType<typeof createSourceAdapterRegistry>; | |
| @@ -1,84 +1,5 @@ | ||
| 1 | 1 | import * as Data from "effect/Data"; |
| 2 | 2 | import * as Effect from "effect/Effect"; |
| 3 | −import * as Schema from "effect/Schema"; | |
| 4 | − | |
| 5 | −import { sourceCoreEffectError } from "./effect-errors"; | |
| 6 | −import { | |
| 7 | − SecretRefSchema, | |
| 8 | − SourceBindingVersionSchema, | |
| 9 | − SourceImportAuthPolicySchema, | |
| 10 | − SourceOauthClientInputSchema, | |
| 11 | − StringArraySchema, | |
| 12 | − SourceTransportSchema, | |
| 13 | − StringMapSchema, | |
| 14 | − type CredentialSlot, | |
| 15 | − type SecretRef, | |
| 16 | − type SourceBinding, | |
| 17 | − type StringArray, | |
| 18 | − type SourceTransport, | |
| 19 | − type StringMap, | |
| 20 | −} from "./source-models"; | |
| 21 | − | |
| 22 | −const TrimmedNonEmptyStringSchema = Schema.Trim.pipe(Schema.nonEmptyString()); | |
| 23 | − | |
| 24 | −export const OptionalNullableStringSchema = Schema.optional( | |
| 25 | − Schema.NullOr(Schema.String), | |
| 26 | −); | |
| 27 | − | |
| 28 | −export const ConnectBearerAuthSchema = Schema.Struct({ | |
| 29 | − kind: Schema.Literal("bearer"), | |
| 30 | − headerName: OptionalNullableStringSchema, | |
| 31 | − prefix: OptionalNullableStringSchema, | |
| 32 | − token: OptionalNullableStringSchema, | |
| 33 | − tokenRef: Schema.optional( | |
| 34 | − Schema.NullOr(SecretRefSchema as Schema.Schema<SecretRef, SecretRef, never>), | |
| 35 | − ), | |
| 36 | −}); | |
| 37 | − | |
| 38 | −export const ConnectOAuth2AuthSchema = Schema.Struct({ | |
| 39 | − kind: Schema.Literal("oauth2"), | |
| 40 | − headerName: OptionalNullableStringSchema, | |
| 41 | − prefix: OptionalNullableStringSchema, | |
| 42 | − accessToken: OptionalNullableStringSchema, | |
| 43 | − accessTokenRef: Schema.optional( | |
| 44 | − Schema.NullOr(SecretRefSchema as Schema.Schema<SecretRef, SecretRef, never>), | |
| 45 | − ), | |
| 46 | − refreshToken: OptionalNullableStringSchema, | |
| 47 | − refreshTokenRef: Schema.optional( | |
| 48 | − Schema.NullOr(SecretRefSchema as Schema.Schema<SecretRef, SecretRef, never>), | |
| 49 | − ), | |
| 50 | −}); | |
| 51 | − | |
| 52 | −export const ConnectHttpAuthSchema = Schema.Union( | |
| 53 | − Schema.Struct({ kind: Schema.Literal("none") }), | |
| 54 | − ConnectBearerAuthSchema, | |
| 55 | − ConnectOAuth2AuthSchema, | |
| 56 | −); | |
| 57 | − | |
| 58 | −export const ConnectHttpImportAuthSchema = Schema.Struct({ | |
| 59 | − importAuthPolicy: Schema.optional(SourceImportAuthPolicySchema), | |
| 60 | − importAuth: Schema.optional(ConnectHttpAuthSchema), | |
| 61 | −}); | |
| 62 | − | |
| 63 | −export const ConnectOauthClientSchema = Schema.optional( | |
| 64 | − Schema.NullOr(SourceOauthClientInputSchema), | |
| 65 | −); | |
| 66 | − | |
| 67 | −export const SourceConnectCommonFieldsSchema = Schema.Struct({ | |
| 68 | − endpoint: TrimmedNonEmptyStringSchema, | |
| 69 | − name: OptionalNullableStringSchema, | |
| 70 | − namespace: OptionalNullableStringSchema, | |
| 71 | −}); | |
| 72 | − | |
| 73 | −export const McpConnectFieldsSchema = Schema.Struct({ | |
| 74 | − transport: Schema.optional(Schema.NullOr(SourceTransportSchema)), | |
| 75 | − queryParams: Schema.optional(Schema.NullOr(StringMapSchema)), | |
| 76 | − headers: Schema.optional(Schema.NullOr(StringMapSchema)), | |
| 77 | − command: Schema.optional(Schema.NullOr(Schema.String)), | |
| 78 | − args: Schema.optional(Schema.NullOr(StringArraySchema)), | |
| 79 | − env: Schema.optional(Schema.NullOr(StringMapSchema)), | |
| 80 | − cwd: Schema.optional(Schema.NullOr(Schema.String)), | |
| 81 | −}); | |
| 82 | 3 | |
| 83 | 4 | export const parseJsonValue = <T>(input: { |
| 84 | 5 | label: string; |
| @@ -97,11 +18,11 @@ export const parseJsonValue = <T>(input: { · 12 unmodified lines | ||
| 97 | 18 | export class SourceCredentialRequiredError extends Data.TaggedError( |
| 98 | 19 | "SourceCredentialRequiredError", |
| 99 | 20 | )<{ |
| 100 | − readonly slot: CredentialSlot; | |
| 21 | + readonly slot: "runtime" | "import"; | |
| 101 | 22 | readonly message: string; |
| 102 | 23 | }> { |
| 103 | 24 | constructor( |
| 104 | − slot: CredentialSlot, | |
| 25 | + slot: "runtime" | "import", | |
| 105 | 26 | message: string, |
| 106 | 27 | ) { |
| 107 | 28 | super({ slot, message }); |
| @@ -112,157 +33,3 @@ export const isSourceCredentialRequiredError = ( · 4 unmodified lines | ||
| 112 | 33 | error: unknown, |
| 113 | 34 | ): error is SourceCredentialRequiredError => |
| 114 | 35 | error instanceof SourceCredentialRequiredError; |
| 115 | − | |
| 116 | −export const emptySourceBindingState = { | |
| 117 | − transport: null, | |
| 118 | − queryParams: null, | |
| 119 | − headers: null, | |
| 120 | − command: null, | |
| 121 | − args: null, | |
| 122 | − env: null, | |
| 123 | − cwd: null, | |
| 124 | − specUrl: null, | |
| 125 | − defaultHeaders: null, | |
| 126 | −} satisfies { | |
| 127 | − transport: SourceTransport | null; | |
| 128 | − queryParams: StringMap | null; | |
| 129 | − headers: StringMap | null; | |
| 130 | − command: string | null; | |
| 131 | − args: StringArray | null; | |
| 132 | − env: StringMap | null; | |
| 133 | − cwd: string | null; | |
| 134 | − specUrl: string | null; | |
| 135 | − defaultHeaders: StringMap | null; | |
| 136 | −}; | |
| 137 | − | |
| 138 | −const BindingConfigEnvelopeSchema = <A, I>( | |
| 139 | − adapterKey: string, | |
| 140 | − payloadSchema: Schema.Schema<A, I, never>, | |
| 141 | −) => | |
| 142 | − Schema.Struct({ | |
| 143 | − adapterKey: Schema.Literal(adapterKey), | |
| 144 | − version: SourceBindingVersionSchema, | |
| 145 | − payload: payloadSchema, | |
| 146 | − }); | |
| 147 | − | |
| 148 | −export const encodeBindingConfig = <A, I>(input: { | |
| 149 | − adapterKey: string; | |
| 150 | − version: number; | |
| 151 | − payloadSchema: Schema.Schema<A, I, never>; | |
| 152 | − payload: A; | |
| 153 | −}): string => | |
| 154 | − Schema.encodeSync( | |
| 155 | − Schema.parseJson(BindingConfigEnvelopeSchema(input.adapterKey, input.payloadSchema)), | |
| 156 | − )({ | |
| 157 | − adapterKey: input.adapterKey, | |
| 158 | − version: input.version, | |
| 159 | − payload: input.payload, | |
| 160 | − }); | |
| 161 | − | |
| 162 | −export const decodeBindingConfig = <A>(input: { | |
| 163 | − sourceId: string; | |
| 164 | − label: string; | |
| 165 | − adapterKey: string; | |
| 166 | − version: number; | |
| 167 | − payloadSchema: Schema.Schema<A, any, never>; | |
| 168 | − value: string | null; | |
| 169 | −}): Effect.Effect<SourceBinding & { payload: A }, Error, never> => { | |
| 170 | − if (input.value === null) { | |
| 171 | − return Effect.fail( | |
| 172 | − sourceCoreEffectError("core/shared", `Missing ${input.label} binding config for ${input.sourceId}`), | |
| 173 | − ); | |
| 174 | − } | |
| 175 | − | |
| 176 | − return Effect.try({ | |
| 177 | − try: () => | |
| 178 | − Schema.decodeUnknownSync( | |
| 179 | − Schema.parseJson(BindingConfigEnvelopeSchema(input.adapterKey, input.payloadSchema)), | |
| 180 | − )(input.value), | |
| 181 | − catch: (cause) => { | |
| 182 | − const message = cause instanceof Error ? cause.message : String(cause); | |
| 183 | − return new Error( | |
| 184 | − `Invalid ${input.label} binding config for ${input.sourceId}: ${message}`, | |
| 185 | − ); | |
| 186 | − }, | |
| 187 | − }).pipe( | |
| 188 | − Effect.flatMap((decoded) => | |
| 189 | − decoded.version === input.version | |
| 190 | − ? Effect.succeed({ | |
| 191 | − version: decoded.version, | |
| 192 | − payload: decoded.payload, | |
| 193 | − } as SourceBinding & { payload: A }) | |
| 194 | − : Effect.fail( | |
| 195 | − sourceCoreEffectError("core/shared", | |
| 196 | − `Unsupported ${input.label} binding config version ${decoded.version} for ${input.sourceId}; expected ${input.version}`, | |
| 197 | − ), | |
| 198 | − ), | |
| 199 | − ), | |
| 200 | − ); | |
| 201 | −}; | |
| 202 | − | |
| 203 | −export const decodeSourceBindingPayload = <A>(input: { | |
| 204 | − sourceId: string; | |
| 205 | − label: string; | |
| 206 | − version: number; | |
| 207 | − expectedVersion: number; | |
| 208 | − schema: Schema.Schema<A, any, never>; | |
| 209 | − value: unknown; | |
| 210 | − allowedKeys?: readonly string[] | undefined; | |
| 211 | −}): Effect.Effect<A, Error, never> => | |
| 212 | − input.version !== input.expectedVersion | |
| 213 | − ? Effect.fail( | |
| 214 | − sourceCoreEffectError("core/shared", | |
| 215 | − `Unsupported ${input.label} binding version ${input.version} for ${input.sourceId}; expected ${input.expectedVersion}`, | |
| 216 | − ), | |
| 217 | − ) | |
| 218 | − : Effect.try({ | |
| 219 | − try: () => { | |
| 220 | − if ( | |
| 221 | − input.allowedKeys | |
| 222 | − && input.value !== null | |
| 223 | − && typeof input.value === "object" | |
| 224 | − && !Array.isArray(input.value) | |
| 225 | − ) { | |
| 226 | − const extraKeys = Object.keys(input.value as Record<string, unknown>).filter( | |
| 227 | − (key) => !input.allowedKeys!.includes(key), | |
| 228 | − ); | |
| 229 | − if (extraKeys.length > 0) { | |
| 230 | − throw new Error( | |
| 231 | − `Unsupported fields: ${extraKeys.join(", ")}`, | |
| 232 | − ); | |
| 233 | − } | |
| 234 | − } | |
| 235 | − | |
| 236 | − return Schema.decodeUnknownSync(input.schema)(input.value); | |
| 237 | − }, | |
| 238 | − catch: (cause) => { | |
| 239 | − const message = cause instanceof Error ? cause.message : String(cause); | |
| 240 | − return new Error( | |
| 241 | − `Invalid ${input.label} binding payload for ${input.sourceId}: ${message}`, | |
| 242 | − ); | |
| 243 | − }, | |
| 244 | − }); | |
| 245 | − | |
| 246 | −export const decodeExecutableBindingPayload = <A>(input: { | |
| 247 | − executableId: string; | |
| 248 | − label: string; | |
| 249 | − version: number; | |
| 250 | − expectedVersion: number; | |
| 251 | − schema: Schema.Schema<A, any, never>; | |
| 252 | − value: unknown; | |
| 253 | −}): A => { | |
| 254 | − if (input.version !== input.expectedVersion) { | |
| 255 | − throw new Error( | |
| 256 | − `Unsupported ${input.label} executable binding version ${input.version} for ${input.executableId}; expected ${input.expectedVersion}`, | |
| 257 | − ); | |
| 258 | − } | |
| 259 | − | |
| 260 | − try { | |
| 261 | − return Schema.decodeUnknownSync(input.schema)(input.value); | |
| 262 | − } catch (cause) { | |
| 263 | − const message = cause instanceof Error ? cause.message : String(cause); | |
| 264 | − throw new Error( | |
| 265 | − `Invalid ${input.label} executable binding for ${input.executableId}: ${message}`, | |
| 266 | − ); | |
| 267 | − } | |
| 268 | −}; | |
| @@ -29,12 +29,6 @@ export const SourceTransportSchema = Schema.Literal( · 28 unmodified lines | ||
| 29 | 29 | "stdio", |
| 30 | 30 | ); |
| 31 | 31 | |
| 32 | −export const SourceImportAuthPolicySchema = Schema.Literal( | |
| 33 | − "none", | |
| 34 | − "reuse_runtime", | |
| 35 | − "separate", | |
| 36 | −); | |
| 37 | − | |
| 38 | 32 | export const StringMapSchema = Schema.Record({ |
| 39 | 33 | key: Schema.String, |
| 40 | 34 | value: Schema.String, |
| @@ -73,64 +67,6 @@ export const JsonObjectSchema = Schema.Record({ · 32 unmodified lines | ||
| 73 | 67 | value: JsonValueSchema, |
| 74 | 68 | }).annotations({ identifier: "JsonObject" }); |
| 75 | 69 | |
| 76 | −export const SourceAuthSchema = Schema.Union( | |
| 77 | − Schema.Struct({ | |
| 78 | − kind: Schema.Literal("none"), | |
| 79 | − }), | |
| 80 | − Schema.Struct({ | |
| 81 | − kind: Schema.Literal("bearer"), | |
| 82 | − headerName: Schema.String, | |
| 83 | − prefix: Schema.String, | |
| 84 | − token: SecretRefSchema, | |
| 85 | − }), | |
| 86 | − Schema.Struct({ | |
| 87 | − kind: Schema.Literal("oauth2"), | |
| 88 | − headerName: Schema.String, | |
| 89 | − prefix: Schema.String, | |
| 90 | − accessToken: SecretRefSchema, | |
| 91 | − refreshToken: Schema.NullOr(SecretRefSchema), | |
| 92 | − }), | |
| 93 | − Schema.Struct({ | |
| 94 | − kind: Schema.Literal("oauth2_authorized_user"), | |
| 95 | − headerName: Schema.String, | |
| 96 | − prefix: Schema.String, | |
| 97 | − tokenEndpoint: Schema.String, | |
| 98 | − clientId: Schema.String, | |
| 99 | − clientAuthentication: Schema.Literal("none", "client_secret_post"), | |
| 100 | − clientSecret: Schema.NullOr(SecretRefSchema), | |
| 101 | − refreshToken: SecretRefSchema, | |
| 102 | − grantSet: Schema.NullOr(Schema.Array(Schema.String)), | |
| 103 | − }), | |
| 104 | − Schema.Struct({ | |
| 105 | − kind: Schema.Literal("provider_grant_ref"), | |
| 106 | − grantId: Schema.String, | |
| 107 | − providerKey: Schema.String, | |
| 108 | − requiredScopes: Schema.Array(Schema.String), | |
| 109 | − headerName: Schema.String, | |
| 110 | − prefix: Schema.String, | |
| 111 | − }), | |
| 112 | − Schema.Struct({ | |
| 113 | − kind: Schema.Literal("mcp_oauth"), | |
| 114 | − redirectUri: Schema.String, | |
| 115 | − accessToken: SecretRefSchema, | |
| 116 | − refreshToken: Schema.NullOr(SecretRefSchema), | |
| 117 | − tokenType: Schema.String, | |
| 118 | − expiresIn: Schema.NullOr(Schema.Number), | |
| 119 | − scope: Schema.NullOr(Schema.String), | |
| 120 | − resourceMetadataUrl: Schema.NullOr(Schema.String), | |
| 121 | − authorizationServerUrl: Schema.NullOr(Schema.String), | |
| 122 | − resourceMetadataJson: Schema.NullOr(Schema.String), | |
| 123 | − authorizationServerMetadataJson: Schema.NullOr(Schema.String), | |
| 124 | − clientInformationJson: Schema.NullOr(Schema.String), | |
| 125 | − }), | |
| 126 | −); | |
| 127 | − | |
| 128 | −export const SourceBindingVersionSchema = Schema.Number; | |
| 129 | − | |
| 130 | −export const SourceBindingSchema = Schema.Struct({ | |
| 131 | − version: SourceBindingVersionSchema, | |
| 132 | − payload: JsonObjectSchema, | |
| 133 | −}); | |
| 134 | 70 | |
| 135 | 71 | export const SourceSchema = Schema.Struct({ |
| 136 | 72 | id: Schema.String, |
| @@ -141,11 +77,6 @@ export const SourceSchema = Schema.Struct({ · 4 unmodified lines | ||
| 141 | 77 | status: SourceStatusSchema, |
| 142 | 78 | enabled: Schema.Boolean, |
| 143 | 79 | namespace: Schema.NullOr(Schema.String), |
| 144 | − bindingVersion: SourceBindingVersionSchema, | |
| 145 | − binding: JsonObjectSchema, | |
| 146 | − importAuthPolicy: SourceImportAuthPolicySchema, | |
| 147 | − importAuth: SourceAuthSchema, | |
| 148 | − auth: SourceAuthSchema, | |
| 149 | 80 | sourceHash: Schema.NullOr(Schema.String), |
| 150 | 81 | lastError: Schema.NullOr(Schema.String), |
| 151 | 82 | createdAt: Schema.Number, |
| @@ -154,22 +85,6 @@ export const SourceSchema = Schema.Struct({ · 2 unmodified lines | ||
| 154 | 85 | |
| 155 | 86 | export const StoredSourceRecordSchema = Schema.Struct({ |
| 156 | 87 | id: Schema.String, |
| 157 | − bindingConfigJson: Schema.NullOr(Schema.String), | |
| 158 | −}); | |
| 159 | − | |
| 160 | −export const ScopedSourceOauthClientRedirectModeSchema = Schema.Literal( | |
| 161 | − "app_callback", | |
| 162 | − "loopback", | |
| 163 | −); | |
| 164 | − | |
| 165 | −export const ScopeOauthClientIdSchema = Schema.String; | |
| 166 | − | |
| 167 | −export const SourceOauthClientInputSchema = Schema.Struct({ | |
| 168 | − clientId: Schema.Trim.pipe(Schema.nonEmptyString()), | |
| 169 | − clientSecret: Schema.optional( | |
| 170 | − Schema.NullOr(Schema.Trim.pipe(Schema.nonEmptyString())), | |
| 171 | − ), | |
| 172 | − redirectMode: Schema.optional(ScopedSourceOauthClientRedirectModeSchema), | |
| 173 | 88 | }); |
| 174 | 89 | |
| 175 | 90 | export type SecretRef = typeof SecretRefSchema.Type; |
| @@ -178,13 +93,7 @@ export type SourceCatalogKind = typeof SourceCatalogKindSchema.Type; · 2 unmodified lines | ||
| 178 | 93 | export type SourceKind = typeof SourceKindSchema.Type; |
| 179 | 94 | export type SourceStatus = typeof SourceStatusSchema.Type; |
| 180 | 95 | export type SourceTransport = typeof SourceTransportSchema.Type; |
| 181 | −export type SourceImportAuthPolicy = typeof SourceImportAuthPolicySchema.Type; | |
| 182 | 96 | export type StringMap = typeof StringMapSchema.Type; |
| 183 | 97 | export type StringArray = typeof StringArraySchema.Type; |
| 184 | −export type SourceAuth = typeof SourceAuthSchema.Type; | |
| 185 | −export type SourceBinding = typeof SourceBindingSchema.Type; | |
| 186 | 98 | export type Source = typeof SourceSchema.Type; |
| 187 | 99 | export type StoredSourceRecord = typeof StoredSourceRecordSchema.Type; |
| 188 | −export type ScopedSourceOauthClientRedirectMode = | |
| 189 | − typeof ScopedSourceOauthClientRedirectModeSchema.Type; | |
| 190 | −export type SourceOauthClientInput = typeof SourceOauthClientInputSchema.Type; | |
| @@ -1,179 +1,31 @@ | ||
| 1 | −import type { OAuthClientProvider } from "@modelcontextprotocol/sdk/client/auth.js"; | |
| 2 | 1 | import type { |
| 3 | 2 | OnElicitation, |
| 4 | 3 | ToolDescriptor as CatalogToolDescriptor, |
| 5 | 4 | } from "@executor/codemode-core"; |
| 6 | 5 | import type { Capability, CatalogV1, Executable } from "@executor/ir/model"; |
| 7 | −import * as Effect from "effect/Effect"; | |
| 8 | −import type { Schema } from "effect"; | |
| 9 | − | |
| 10 | −import type { OAuth2ClientAuthenticationMethod } from "@executor/auth-oauth2"; | |
| 11 | 6 | import type { SourceCatalogSyncResult } from "./catalog-sync-result"; |
| 12 | −import type { SourceDiscoveryResult } from "./discovery-models"; | |
| 13 | 7 | import type { |
| 14 | − CredentialSlot, | |
| 15 | − SecretRef, | |
| 16 | 8 | Source, |
| 17 | − SourceBinding, | |
| 18 | − SourceCatalogKind, | |
| 19 | − SourceImportAuthPolicy, | |
| 20 | − SourceOauthClientInput, | |
| 21 | − StringArray, | |
| 22 | − SourceTransport, | |
| 23 | − StoredSourceRecord, | |
| 24 | − StringMap, | |
| 25 | 9 | } from "./source-models"; |
| 26 | 10 | |
| 27 | −export type RequestPlacement = | |
| 28 | − | { | |
| 29 | − location: "header"; | |
| 30 | − name: string; | |
| 31 | − value: string; | |
| 32 | − } | |
| 33 | − | { | |
| 34 | − location: "query"; | |
| 35 | − name: string; | |
| 36 | − value: string; | |
| 37 | − } | |
| 38 | − | { | |
| 39 | − location: "cookie"; | |
| 40 | − name: string; | |
| 41 | − value: string; | |
| 42 | − } | |
| 43 | − | { | |
| 44 | − location: "body"; | |
| 45 | − path: string; | |
| 46 | − value: string; | |
| 47 | − }; | |
| 48 | − | |
| 49 | −export type ResolvedSourceAuthMaterial = { | |
| 50 | − placements: ReadonlyArray<RequestPlacement>; | |
| 51 | − headers: Readonly<Record<string, string>>; | |
| 52 | − queryParams: Readonly<Record<string, string>>; | |
| 53 | − cookies: Readonly<Record<string, string>>; | |
| 54 | − bodyValues: Readonly<Record<string, string>>; | |
| 55 | − expiresAt: number | null; | |
| 56 | − refreshAfter: number | null; | |
| 57 | − authProvider?: OAuthClientProvider | undefined; | |
| 58 | −}; | |
| 59 | − | |
| 60 | −export type SecretMaterialResolveContext = { | |
| 61 | − params?: Readonly<Record<string, string | undefined>>; | |
| 62 | −}; | |
| 63 | − | |
| 64 | −export type ResolveSecretMaterial = (input: { | |
| 65 | − ref: SecretRef; | |
| 66 | − context?: SecretMaterialResolveContext; | |
| 67 | −}) => Effect.Effect<string, Error, never>; | |
| 68 | − | |
| 69 | −export type SourceAdapterConnectStrategy = "direct" | "interactive" | "none"; | |
| 70 | − | |
| 71 | −export type SourceAdapterCredentialStrategy = | |
| 72 | − | "credential_managed" | |
| 73 | − | "adapter_defined" | |
| 74 | − | "none"; | |
| 75 | − | |
| 76 | −export type SourceAdapterInputSchema = Schema.Schema<any, any, never>; | |
| 77 | − | |
| 78 | −export type SourceBindingState = { | |
| 79 | − transport: SourceTransport | null; | |
| 80 | − queryParams: StringMap | null; | |
| 81 | − headers: StringMap | null; | |
| 82 | − command: string | null; | |
| 83 | − args: StringArray | null; | |
| 84 | − env: StringMap | null; | |
| 85 | − cwd: string | null; | |
| 86 | − specUrl: string | null; | |
| 87 | − defaultHeaders: StringMap | null; | |
| 88 | −}; | |
| 89 | − | |
| 90 | −export type StoredSourceBindingConfig = Pick<SourceBinding, "version" | "payload">; | |
| 91 | − | |
| 92 | −export type SourceAdapterSyncInput = { | |
| 11 | +export type SourceSyncInput = { | |
| 93 | 12 | source: Source; |
| 94 | − resolveSecretMaterial: ResolveSecretMaterial; | |
| 95 | − resolveAuthMaterialForSlot: (slot: CredentialSlot) => Effect.Effect< | |
| 96 | − ResolvedSourceAuthMaterial, | |
| 97 | − Error, | |
| 98 | − never | |
| 99 | − >; | |
| 100 | −}; | |
| 101 | − | |
| 102 | −export type SourceAdapterOauth2SetupConfig = { | |
| 103 | − providerKey: string; | |
| 104 | − authorizationEndpoint: string; | |
| 105 | − tokenEndpoint: string; | |
| 106 | − scopes: readonly string[]; | |
| 107 | − headerName: string; | |
| 108 | − prefix: string; | |
| 109 | − clientAuthentication: OAuth2ClientAuthenticationMethod; | |
| 110 | − authorizationParams?: Readonly<Record<string, string>>; | |
| 111 | 13 | }; |
| 112 | 14 | |
| 113 | −export type SourceAdapterInvokeResult = { | |
| 15 | +export type SourceInvokeResult = { | |
| 114 | 16 | data: unknown; |
| 115 | 17 | error: unknown; |
| 116 | 18 | headers: Record<string, string>; |
| 117 | 19 | status: number | null; |
| 118 | 20 | }; |
| 119 | 21 | |
| 120 | −export type SourceAdapterInvokeInput = { | |
| 22 | +export type SourceInvokeInput = { | |
| 121 | 23 | source: Source; |
| 122 | 24 | capability: Capability; |
| 123 | 25 | executable: Executable; |
| 124 | 26 | descriptor: CatalogToolDescriptor; |
| 125 | 27 | catalog: CatalogV1; |
| 126 | 28 | args: unknown; |
| 127 | − auth: ResolvedSourceAuthMaterial; | |
| 128 | 29 | onElicitation?: OnElicitation; |
| 129 | 30 | context?: Record<string, unknown>; |
| 130 | 31 | }; |
| 131 | − | |
| 132 | −export type SourceAdapterDiscoveryInput = { | |
| 133 | − normalizedUrl: string; | |
| 134 | − headers: Readonly<Record<string, string>>; | |
| 135 | −}; | |
| 136 | − | |
| 137 | −export type SourceAdapter = { | |
| 138 | − key: string; | |
| 139 | − displayName: string; | |
| 140 | − catalogKind: SourceCatalogKind; | |
| 141 | − connectStrategy: SourceAdapterConnectStrategy; | |
| 142 | − credentialStrategy: SourceAdapterCredentialStrategy; | |
| 143 | − bindingConfigVersion: number; | |
| 144 | − providerKey: string; | |
| 145 | − defaultImportAuthPolicy: SourceImportAuthPolicy; | |
| 146 | − connectPayloadSchema: SourceAdapterInputSchema | null; | |
| 147 | − executorAddInputSchema: SourceAdapterInputSchema | null; | |
| 148 | − executorAddHelpText: readonly string[] | null; | |
| 149 | − executorAddInputSignatureWidth: number | null; | |
| 150 | − localConfigBindingSchema: SourceAdapterInputSchema | null; | |
| 151 | − localConfigBindingFromSource: (source: Source) => unknown; | |
| 152 | − serializeBindingConfig: (source: Source) => string; | |
| 153 | − deserializeBindingConfig: ( | |
| 154 | − input: Pick<StoredSourceRecord, "id" | "bindingConfigJson">, | |
| 155 | − ) => Effect.Effect<StoredSourceBindingConfig, Error, never>; | |
| 156 | − bindingStateFromSource: (source: Source) => Effect.Effect<SourceBindingState, Error, never>; | |
| 157 | − sourceConfigFromSource: (source: Source) => Record<string, unknown>; | |
| 158 | − validateSource: (source: Source) => Effect.Effect<Source, Error, never>; | |
| 159 | − shouldAutoProbe: (source: Source) => boolean; | |
| 160 | − discoveryPriority?: (input: { | |
| 161 | − normalizedUrl: string; | |
| 162 | − }) => number; | |
| 163 | − detectSource?: ( | |
| 164 | − input: SourceAdapterDiscoveryInput, | |
| 165 | − ) => Effect.Effect<SourceDiscoveryResult | null, Error, never>; | |
| 166 | − syncCatalog: ( | |
| 167 | − input: SourceAdapterSyncInput, | |
| 168 | − ) => Effect.Effect<SourceCatalogSyncResult, Error, never>; | |
| 169 | − invoke: ( | |
| 170 | − input: SourceAdapterInvokeInput, | |
| 171 | − ) => Effect.Effect<SourceAdapterInvokeResult, Error, never>; | |
| 172 | − getOauth2SetupConfig?: (input: { | |
| 173 | − source: Source; | |
| 174 | − slot: CredentialSlot; | |
| 175 | − }) => Effect.Effect<SourceAdapterOauth2SetupConfig | null, Error, never>; | |
| 176 | − normalizeOauthClientInput?: ( | |
| 177 | − input: SourceOauthClientInput, | |
| 178 | − ) => Effect.Effect<SourceOauthClientInput, Error, never>; | |
| 179 | −}; | |
| @@ -0,0 +1,113 @@ | ||
| 1 | +import { | |
| 2 | + HttpApi, | |
| 3 | + HttpApiBuilder, | |
| 4 | + HttpApiEndpoint, | |
| 5 | + HttpApiGroup, | |
| 6 | + HttpApiSchema, | |
| 7 | +} from "@effect/platform"; | |
| 8 | +import { | |
| 9 | + ControlPlaneBadRequestError, | |
| 10 | + ControlPlaneForbiddenError, | |
| 11 | + ControlPlaneStorageError, | |
| 12 | + type ExecutorHttpApiExtension, | |
| 13 | + type ExecutorHttpPlugin, | |
| 14 | +} from "@executor/platform-api"; | |
| 15 | +import { resolveRequestedLocalWorkspace } from "@executor/platform-api/local-context"; | |
| 16 | +import { | |
| 17 | + ScopeIdSchema, | |
| 18 | + SourceSchema, | |
| 19 | + type Source, | |
| 20 | +} from "@executor/platform-sdk/schema"; | |
| 21 | +import * as Effect from "effect/Effect"; | |
| 22 | + | |
| 23 | +import { | |
| 24 | + OpenApiConnectInputSchema, | |
| 25 | + OpenApiPreviewRequestSchema, | |
| 26 | + OpenApiPreviewResponseSchema, | |
| 27 | + type OpenApiConnectInput, | |
| 28 | + type OpenApiPreviewRequest, | |
| 29 | + type OpenApiPreviewResponse, | |
| 30 | +} from "@executor/plugin-openapi-shared"; | |
| 31 | + | |
| 32 | +type OpenApiExecutorExtension = { | |
| 33 | + openapi: { | |
| 34 | + previewDocument: ( | |
| 35 | + input: OpenApiPreviewRequest, | |
| 36 | + ) => Effect.Effect<OpenApiPreviewResponse, Error, never>; | |
| 37 | + createSource: ( | |
| 38 | + input: OpenApiConnectInput, | |
| 39 | + ) => Effect.Effect<Source, Error, never>; | |
| 40 | + }; | |
| 41 | +}; | |
| 42 | + | |
| 43 | +const workspaceIdParam = HttpApiSchema.param("workspaceId", ScopeIdSchema); | |
| 44 | + | |
| 45 | +export const OpenApiHttpGroup = HttpApiGroup.make("openapi") | |
| 46 | + .add( | |
| 47 | + HttpApiEndpoint.post("previewDocument")`/workspaces/${workspaceIdParam}/plugins/openapi/preview` | |
| 48 | + .setPayload(OpenApiPreviewRequestSchema) | |
| 49 | + .addSuccess(OpenApiPreviewResponseSchema) | |
| 50 | + .addError(ControlPlaneBadRequestError) | |
| 51 | + .addError(ControlPlaneForbiddenError) | |
| 52 | + .addError(ControlPlaneStorageError), | |
| 53 | + ) | |
| 54 | + .add( | |
| 55 | + HttpApiEndpoint.post("createSource")`/workspaces/${workspaceIdParam}/plugins/openapi/sources` | |
| 56 | + .setPayload(OpenApiConnectInputSchema) | |
| 57 | + .addSuccess(SourceSchema) | |
| 58 | + .addError(ControlPlaneBadRequestError) | |
| 59 | + .addError(ControlPlaneForbiddenError) | |
| 60 | + .addError(ControlPlaneStorageError), | |
| 61 | + ) | |
| 62 | + .prefix("/v1"); | |
| 63 | + | |
| 64 | +export const OpenApiHttpApi = HttpApi.make("executor").add(OpenApiHttpGroup); | |
| 65 | + | |
| 66 | +export const openApiHttpApiExtension = { | |
| 67 | + key: "openapi", | |
| 68 | + group: OpenApiHttpGroup, | |
| 69 | +} satisfies ExecutorHttpApiExtension<typeof OpenApiHttpGroup>; | |
| 70 | + | |
| 71 | +const toBadRequestError = (operation: string) => (cause: unknown) => | |
| 72 | + new ControlPlaneBadRequestError({ | |
| 73 | + operation, | |
| 74 | + message: cause instanceof Error ? cause.message : String(cause), | |
| 75 | + details: cause instanceof Error ? cause.stack ?? cause.message : String(cause), | |
| 76 | + }); | |
| 77 | + | |
| 78 | +const toStorageError = (operation: string) => (cause: unknown) => | |
| 79 | + new ControlPlaneStorageError({ | |
| 80 | + operation, | |
| 81 | + message: cause instanceof Error ? cause.message : String(cause), | |
| 82 | + details: cause instanceof Error ? cause.stack ?? cause.message : String(cause), | |
| 83 | + }); | |
| 84 | + | |
| 85 | +export const openApiHttpPlugin = (): ExecutorHttpPlugin< | |
| 86 | + typeof OpenApiHttpGroup, | |
| 87 | + OpenApiExecutorExtension | |
| 88 | +> => ({ | |
| 89 | + key: "openapi", | |
| 90 | + group: OpenApiHttpGroup, | |
| 91 | + build: ({ executor }) => | |
| 92 | + HttpApiBuilder.group(OpenApiHttpApi, "openapi", (handlers) => | |
| 93 | + handlers | |
| 94 | + .handle("previewDocument", ({ path, payload }) => | |
| 95 | + resolveRequestedLocalWorkspace( | |
| 96 | + "openapi.previewDocument", | |
| 97 | + path.workspaceId, | |
| 98 | + ).pipe( | |
| 99 | + Effect.flatMap(() => executor.openapi.previewDocument(payload)), | |
| 100 | + Effect.mapError(toBadRequestError("openapi.previewDocument")), | |
| 101 | + ) | |
| 102 | + ) | |
| 103 | + .handle("createSource", ({ path, payload }) => | |
| 104 | + resolveRequestedLocalWorkspace( | |
| 105 | + "openapi.createSource", | |
| 106 | + path.workspaceId, | |
| 107 | + ).pipe( | |
| 108 | + Effect.flatMap(() => executor.openapi.createSource(payload)), | |
| 109 | + Effect.mapError(toStorageError("openapi.createSource")), | |
| 110 | + ) | |
| 111 | + ) | |
| 112 | + ), | |
| 113 | +}); | |
| @@ -0,0 +1,26 @@ | ||
| 1 | +{ | |
| 2 | + "name": "@executor/plugin-openapi-http", | |
| 3 | + "private": true, | |
| 4 | + "type": "module", | |
| 5 | + "exports": { | |
| 6 | + ".": "./index.ts" | |
| 7 | + }, | |
| 8 | + "files": [ | |
| 9 | + "index.ts" | |
| 10 | + ], | |
| 11 | + "scripts": { | |
| 12 | + "typecheck": "bunx tsc --noEmit -p tsconfig.json" | |
| 13 | + }, | |
| 14 | + "dependencies": { | |
| 15 | + "@effect/platform": "catalog:", | |
| 16 | + "@executor/platform-api": "workspace:*", | |
| 17 | + "@executor/platform-sdk": "workspace:*", | |
| 18 | + "@executor/plugin-openapi-shared": "workspace:*", | |
| 19 | + "effect": "catalog:" | |
| 20 | + }, | |
| 21 | + "devDependencies": { | |
| 22 | + "@types/node": "catalog:", | |
| 23 | + "bun-types": "catalog:" | |
| 24 | + }, | |
| 25 | + "version": "0.0.0" | |
| 26 | +} | |
| @@ -6,10 +6,10 @@ · 5 unmodified lines | ||
| 6 | 6 | "strict": true, |
| 7 | 7 | "skipLibCheck": true, |
| 8 | 8 | "noEmit": true, |
| 9 | − "lib": ["ES2022"], | |
| 9 | + "lib": ["ES2022", "DOM"], | |
| 10 | 10 | "types": ["bun-types", "node"] |
| 11 | 11 | }, |
| 12 | 12 | "include": [ |
| 13 | − "src/**/*.ts" | |
| 13 | + "index.ts" | |
| 14 | 14 | ] |
| 15 | 15 | } |
| @@ -0,0 +1,460 @@ | ||
| 1 | +import type { Source } from "@executor/react"; | |
| 2 | +import { | |
| 3 | + Result, | |
| 4 | + defineExecutorPluginHttpApiClient, | |
| 5 | + useAtomValue, | |
| 6 | + useAtomSet, | |
| 7 | + useExecutorMutation, | |
| 8 | + useLocalInstallation, | |
| 9 | +} from "@executor/react"; | |
| 10 | +import { | |
| 11 | + openApiHttpApiExtension, | |
| 12 | +} from "@executor/plugin-openapi-http"; | |
| 13 | +import type { | |
| 14 | + OpenApiConnectInput, | |
| 15 | + OpenApiPreviewRequest, | |
| 16 | + OpenApiPreviewResponse, | |
| 17 | +} from "@executor/plugin-openapi-shared"; | |
| 18 | +import { useNavigate } from "@tanstack/react-router"; | |
| 19 | +import { startTransition, useState, type ReactNode } from "react"; | |
| 20 | + | |
| 21 | +type FrontendSourceTypeDefinition = { | |
| 22 | + kind: string; | |
| 23 | + displayName: string; | |
| 24 | + renderAddPage: () => ReactNode; | |
| 25 | + renderEditPage?: (input: { source: Source }) => ReactNode; | |
| 26 | + renderDetailPage?: (input: { | |
| 27 | + source: Source; | |
| 28 | + route: { | |
| 29 | + search?: unknown; | |
| 30 | + navigate?: unknown; | |
| 31 | + }; | |
| 32 | + }) => ReactNode; | |
| 33 | +}; | |
| 34 | + | |
| 35 | +type FrontendPluginRegisterApi = { | |
| 36 | + sources: { | |
| 37 | + registerType: (definition: FrontendSourceTypeDefinition) => void; | |
| 38 | + }; | |
| 39 | +}; | |
| 40 | + | |
| 41 | +const defaultOpenApiInput = (): OpenApiConnectInput => ({ | |
| 42 | + name: "My OpenAPI Source", | |
| 43 | + specUrl: "https://example.com/openapi.json", | |
| 44 | + baseUrl: null, | |
| 45 | + auth: { | |
| 46 | + kind: "none", | |
| 47 | + }, | |
| 48 | +}); | |
| 49 | + | |
| 50 | +const getOpenApiHttpClient = defineExecutorPluginHttpApiClient<"OpenApiReactHttpClient">()( | |
| 51 | + "OpenApiReactHttpClient", | |
| 52 | + [openApiHttpApiExtension] as const, | |
| 53 | +); | |
| 54 | + | |
| 55 | + | |
| 56 | +const Section = (props: { | |
| 57 | + title: string; | |
| 58 | + children: ReactNode; | |
| 59 | +}) => ( | |
| 60 | + <section className="rounded-xl border border-border/70 bg-card/40 p-4"> | |
| 61 | + <div className="mb-3 flex items-center gap-2"> | |
| 62 | + <h2 className="text-sm font-semibold">{props.title}</h2> | |
| 63 | + <span className="inline-flex items-center rounded-full border border-transparent bg-secondary px-2 py-0.5 text-[10px] font-medium uppercase tracking-wide text-secondary-foreground"> | |
| 64 | + Plugin | |
| 65 | + </span> | |
| 66 | + </div> | |
| 67 | + {props.children} | |
| 68 | + </section> | |
| 69 | +); | |
| 70 | + | |
| 71 | +function OpenApiAddSourcePage(props: { | |
| 72 | + initialValue: OpenApiConnectInput; | |
| 73 | +}) { | |
| 74 | + const navigate = useNavigate(); | |
| 75 | + const installation = useLocalInstallation(); | |
| 76 | + const [name, setName] = useState(props.initialValue.name); | |
| 77 | + const [specUrl, setSpecUrl] = useState(props.initialValue.specUrl); | |
| 78 | + const [baseUrl, setBaseUrl] = useState(props.initialValue.baseUrl ?? ""); | |
| 79 | + const [error, setError] = useState<string | null>(null); | |
| 80 | + const [preview, setPreview] = useState<OpenApiPreviewResponse | null>(null); | |
| 81 | + const [nameEdited, setNameEdited] = useState(false); | |
| 82 | + const [baseUrlEdited, setBaseUrlEdited] = useState(false); | |
| 83 | + const openApiHttpClient = getOpenApiHttpClient(); | |
| 84 | + const secretsResult = useAtomValue( | |
| 85 | + openApiHttpClient.query("local", "listSecrets", { | |
| 86 | + reactivityKeys: { | |
| 87 | + secrets: [], | |
| 88 | + }, | |
| 89 | + timeToLive: "1 minute", | |
| 90 | + }), | |
| 91 | + ); | |
| 92 | + const availableSecrets = Result.isSuccess(secretsResult) | |
| 93 | + ? secretsResult.value | |
| 94 | + : []; | |
| 95 | + const [authKind, setAuthKind] = useState<OpenApiConnectInput["auth"]["kind"]>( | |
| 96 | + props.initialValue.auth.kind, | |
| 97 | + ); | |
| 98 | + const [tokenSecretRef, setTokenSecretRef] = useState( | |
| 99 | + props.initialValue.auth.kind === "bearer" | |
| 100 | + ? props.initialValue.auth.tokenSecretRef | |
| 101 | + : "", | |
| 102 | + ); | |
| 103 | + const previewDocument = useAtomSet( | |
| 104 | + openApiHttpClient.mutation("openapi", "previewDocument"), | |
| 105 | + { mode: "promise" }, | |
| 106 | + ); | |
| 107 | + const createSource = useAtomSet( | |
| 108 | + openApiHttpClient.mutation("openapi", "createSource"), | |
| 109 | + { mode: "promise" }, | |
| 110 | + ); | |
| 111 | + | |
| 112 | + const requireWorkspaceId = (): string => { | |
| 113 | + if (installation.status === "ready") { | |
| 114 | + return installation.data.scopeId; | |
| 115 | + } | |
| 116 | + | |
| 117 | + if (installation.status === "error") { | |
| 118 | + throw installation.error; | |
| 119 | + } | |
| 120 | + | |
| 121 | + throw new Error("Workspace is still loading."); | |
| 122 | + }; | |
| 123 | + | |
| 124 | + const previewMutation = useExecutorMutation< | |
| 125 | + OpenApiPreviewRequest, | |
| 126 | + OpenApiPreviewResponse | |
| 127 | + >(async (payload) => | |
| 128 | + previewDocument({ | |
| 129 | + path: { | |
| 130 | + workspaceId: requireWorkspaceId() as Source["scopeId"], | |
| 131 | + }, | |
| 132 | + payload, | |
| 133 | + }) | |
| 134 | + ); | |
| 135 | + | |
| 136 | + const createMutation = useExecutorMutation< | |
| 137 | + OpenApiConnectInput, | |
| 138 | + Source | |
| 139 | + >(async (payload) => | |
| 140 | + createSource({ | |
| 141 | + path: { | |
| 142 | + workspaceId: requireWorkspaceId() as Source["scopeId"], | |
| 143 | + }, | |
| 144 | + payload, | |
| 145 | + reactivityKeys: { | |
| 146 | + sources: [requireWorkspaceId()], | |
| 147 | + }, | |
| 148 | + }) | |
| 149 | + ); | |
| 150 | + | |
| 151 | + const handlePreview = async () => { | |
| 152 | + setError(null); | |
| 153 | + const trimmedSpecUrl = specUrl.trim(); | |
| 154 | + if (!trimmedSpecUrl) { | |
| 155 | + setError("Spec URL is required."); | |
| 156 | + return; | |
| 157 | + } | |
| 158 | + | |
| 159 | + if (authKind === "bearer" && tokenSecretRef.trim().length === 0) { | |
| 160 | + setError("Select a secret for bearer auth."); | |
| 161 | + return; | |
| 162 | + } | |
| 163 | + | |
| 164 | + try { | |
| 165 | + const result = await previewMutation.mutateAsync({ | |
| 166 | + specUrl: trimmedSpecUrl, | |
| 167 | + }); | |
| 168 | + setPreview({ | |
| 169 | + ...result, | |
| 170 | + warnings: [...result.warnings], | |
| 171 | + }); | |
| 172 | + | |
| 173 | + if (!nameEdited && result.title) { | |
| 174 | + setName(result.title); | |
| 175 | + } | |
| 176 | + | |
| 177 | + if (!baseUrlEdited && result.baseUrl) { | |
| 178 | + setBaseUrl(result.baseUrl); | |
| 179 | + } | |
| 180 | + } catch (cause) { | |
| 181 | + setError(cause instanceof Error ? cause.message : "Failed previewing document."); | |
| 182 | + setPreview(null); | |
| 183 | + } | |
| 184 | + }; | |
| 185 | + | |
| 186 | + const handleSubmit = async () => { | |
| 187 | + setError(null); | |
| 188 | + | |
| 189 | + const trimmedName = name.trim(); | |
| 190 | + const trimmedSpecUrl = specUrl.trim(); | |
| 191 | + const trimmedBaseUrl = baseUrl.trim(); | |
| 192 | + | |
| 193 | + if (!trimmedName) { | |
| 194 | + setError("Name is required."); | |
| 195 | + return; | |
| 196 | + } | |
| 197 | + | |
| 198 | + if (!trimmedSpecUrl) { | |
| 199 | + setError("Spec URL is required."); | |
| 200 | + return; | |
| 201 | + } | |
| 202 | + | |
| 203 | + try { | |
| 204 | + const source = await createMutation.mutateAsync({ | |
| 205 | + name: trimmedName, | |
| 206 | + specUrl: trimmedSpecUrl, | |
| 207 | + baseUrl: trimmedBaseUrl || null, | |
| 208 | + auth: | |
| 209 | + authKind === "bearer" | |
| 210 | + ? { | |
| 211 | + kind: "bearer", | |
| 212 | + tokenSecretRef, | |
| 213 | + } | |
| 214 | + : { | |
| 215 | + kind: "none", | |
| 216 | + }, | |
| 217 | + }); | |
| 218 | + | |
| 219 | + startTransition(() => { | |
| 220 | + void navigate({ | |
| 221 | + to: "/sources/$sourceId", | |
| 222 | + params: { | |
| 223 | + sourceId: source.id, | |
| 224 | + }, | |
| 225 | + search: { | |
| 226 | + tab: "model", | |
| 227 | + }, | |
| 228 | + }); | |
| 229 | + }); | |
| 230 | + } catch (cause) { | |
| 231 | + setError(cause instanceof Error ? cause.message : "Failed creating source."); | |
| 232 | + } | |
| 233 | + }; | |
| 234 | + | |
| 235 | + return ( | |
| 236 | + <div className="space-y-4"> | |
| 237 | + <Section title="Connection"> | |
| 238 | + <p className="text-sm text-muted-foreground"> | |
| 239 | + This plugin owns its typed HTTP client and source payload shape. The app shell only | |
| 240 | + mounts the registered page. | |
| 241 | + </p> | |
| 242 | + <div className="mt-4 grid gap-4"> | |
| 243 | + <label className="grid gap-1.5"> | |
| 244 | + <span className="text-[12px] font-medium text-foreground">Name</span> | |
| 245 | + <input | |
| 246 | + value={name} | |
| 247 | + onChange={(event) => { | |
| 248 | + setNameEdited(true); | |
| 249 | + setName(event.target.value); | |
| 250 | + }} | |
| 251 | + placeholder="GitHub REST" | |
| 252 | + className="h-10 w-full rounded-lg border border-input bg-background px-3 text-[13px] text-foreground outline-none transition-colors placeholder:text-muted-foreground/35 focus:border-ring focus:ring-1 focus:ring-ring/25" | |
| 253 | + /> | |
| 254 | + </label> | |
| 255 | + | |
| 256 | + <label className="grid gap-1.5"> | |
| 257 | + <span className="text-[12px] font-medium text-foreground">Spec URL</span> | |
| 258 | + <input | |
| 259 | + value={specUrl} | |
| 260 | + onChange={(event) => setSpecUrl(event.target.value)} | |
| 261 | + placeholder="https://example.com/openapi.json" | |
| 262 | + className="h-10 w-full rounded-lg border border-input bg-background px-3 font-mono text-[12px] text-foreground outline-none transition-colors placeholder:text-muted-foreground/35 focus:border-ring focus:ring-1 focus:ring-ring/25" | |
| 263 | + /> | |
| 264 | + </label> | |
| 265 | + | |
| 266 | + <label className="grid gap-1.5"> | |
| 267 | + <span className="text-[12px] font-medium text-foreground">Base URL</span> | |
| 268 | + <input | |
| 269 | + value={baseUrl} | |
| 270 | + onChange={(event) => { | |
| 271 | + setBaseUrlEdited(true); | |
| 272 | + setBaseUrl(event.target.value); | |
| 273 | + }} | |
| 274 | + placeholder="https://api.example.com" | |
| 275 | + className="h-10 w-full rounded-lg border border-input bg-background px-3 font-mono text-[12px] text-foreground outline-none transition-colors placeholder:text-muted-foreground/35 focus:border-ring focus:ring-1 focus:ring-ring/25" | |
| 276 | + /> | |
| 277 | + </label> | |
| 278 | + | |
| 279 | + <label className="grid gap-1.5"> | |
| 280 | + <span className="text-[12px] font-medium text-foreground">Auth</span> | |
| 281 | + <select | |
| 282 | + value={authKind} | |
| 283 | + onChange={(event) => | |
| 284 | + setAuthKind(event.target.value as OpenApiConnectInput["auth"]["kind"])} | |
| 285 | + className="h-10 w-full rounded-lg border border-input bg-background px-3 text-[13px] text-foreground outline-none transition-colors focus:border-ring focus:ring-1 focus:ring-ring/25" | |
| 286 | + > | |
| 287 | + <option value="none">None</option> | |
| 288 | + <option value="bearer">Bearer Secret</option> | |
| 289 | + </select> | |
| 290 | + </label> | |
| 291 | + | |
| 292 | + {authKind === "bearer" && ( | |
| 293 | + <label className="grid gap-1.5"> | |
| 294 | + <span className="text-[12px] font-medium text-foreground">Secret</span> | |
| 295 | + <select | |
| 296 | + value={tokenSecretRef} | |
| 297 | + onChange={(event) => setTokenSecretRef(event.target.value)} | |
| 298 | + className="h-10 w-full rounded-lg border border-input bg-background px-3 text-[13px] text-foreground outline-none transition-colors focus:border-ring focus:ring-1 focus:ring-ring/25" | |
| 299 | + > | |
| 300 | + <option value="">Select a secret</option> | |
| 301 | + {availableSecrets.map((secret) => ( | |
| 302 | + <option key={secret.id} value={secret.id}> | |
| 303 | + {secret.name || secret.id} | |
| 304 | + </option> | |
| 305 | + ))} | |
| 306 | + </select> | |
| 307 | + </label> | |
| 308 | + )} | |
| 309 | + </div> | |
| 310 | + </Section> | |
| 311 | + | |
| 312 | + <Section title="Preview"> | |
| 313 | + <p className="text-sm text-muted-foreground"> | |
| 314 | + Preview introspects the document and can pull out defaults like title and base URL from | |
| 315 | + the OpenAPI spec. | |
| 316 | + </p> | |
| 317 | + <div className="mt-3 flex items-center gap-3"> | |
| 318 | + <button | |
| 319 | + type="button" | |
| 320 | + onClick={() => { | |
| 321 | + void handlePreview(); | |
| 322 | + }} | |
| 323 | + disabled={previewMutation.status === "pending" || createMutation.status === "pending"} | |
| 324 | + className="inline-flex h-7 items-center justify-center rounded-md border border-input bg-transparent px-2.5 text-xs font-medium text-foreground disabled:pointer-events-none disabled:opacity-50" | |
| 325 | + > | |
| 326 | + {previewMutation.status === "pending" ? "Previewing..." : "Preview OpenAPI Document"} | |
| 327 | + </button> | |
| 328 | + {preview && ( | |
| 329 | + <div className="text-xs text-muted-foreground"> | |
| 330 | + {preview.operationCount} operations | |
| 331 | + {preview.version ? ` · v${preview.version}` : ""} | |
| 332 | + </div> | |
| 333 | + )} | |
| 334 | + </div> | |
| 335 | + {preview && ( | |
| 336 | + <div className="mt-4 rounded-lg border border-border/70 bg-background/60 p-4 text-sm"> | |
| 337 | + <div className="grid gap-2"> | |
| 338 | + <div> | |
| 339 | + <span className="font-medium text-foreground">Title:</span>{" "} | |
| 340 | + <span className="text-muted-foreground">{preview.title ?? "Unknown"}</span> | |
| 341 | + </div> | |
| 342 | + <div> | |
| 343 | + <span className="font-medium text-foreground">Version:</span>{" "} | |
| 344 | + <span className="text-muted-foreground">{preview.version ?? "Unknown"}</span> | |
| 345 | + </div> | |
| 346 | + <div> | |
| 347 | + <span className="font-medium text-foreground">Base URL:</span>{" "} | |
| 348 | + <span className="text-muted-foreground">{preview.baseUrl ?? "Not declared"}</span> | |
| 349 | + </div> | |
| 350 | + </div> | |
| 351 | + {preview.warnings.length > 0 && ( | |
| 352 | + <div className="mt-3 rounded-md border border-amber-300/40 bg-amber-100/20 px-3 py-2 text-xs text-amber-800"> | |
| 353 | + {preview.warnings.join(" ")} | |
| 354 | + </div> | |
| 355 | + )} | |
| 356 | + </div> | |
| 357 | + )} | |
| 358 | + </Section> | |
| 359 | + | |
| 360 | + <Section title="Submit"> | |
| 361 | + <p className="text-sm text-muted-foreground"> | |
| 362 | + This plugin can use its own HTTP endpoints and the core API from one merged client. That | |
| 363 | + is how the bearer-secret selector is loaded without a separate app-owned client path. | |
| 364 | + </p> | |
| 365 | + {error && ( | |
| 366 | + <div className="mb-3 rounded-lg border border-destructive/30 bg-destructive/8 px-4 py-2.5 text-[13px] text-destructive"> | |
| 367 | + {error} | |
| 368 | + </div> | |
| 369 | + )} | |
| 370 | + <div className="flex items-center gap-3"> | |
| 371 | + <button | |
| 372 | + type="button" | |
| 373 | + onClick={() => { | |
| 374 | + void handleSubmit(); | |
| 375 | + }} | |
| 376 | + disabled={createMutation.status === "pending" || installation.status === "loading"} | |
| 377 | + className="inline-flex h-7 items-center justify-center rounded-md bg-primary px-2.5 text-xs font-medium text-primary-foreground disabled:pointer-events-none disabled:opacity-50" | |
| 378 | + > | |
| 379 | + {createMutation.status === "pending" ? "Creating..." : "Create Source"} | |
| 380 | + </button> | |
| 381 | + <div className="text-xs text-muted-foreground"> | |
| 382 | + Creates a real <code>kind: "openapi"</code> source. | |
| 383 | + </div> | |
| 384 | + </div> | |
| 385 | + </Section> | |
| 386 | + </div> | |
| 387 | + ); | |
| 388 | +} | |
| 389 | + | |
| 390 | +function OpenApiEditSourcePage(props: { | |
| 391 | + source: Source; | |
| 392 | +}) { | |
| 393 | + return ( | |
| 394 | + <Section title="OpenAPI Plugin Editor"> | |
| 395 | + <p className="text-sm text-muted-foreground"> | |
| 396 | + Plugin-specific configuration is stored behind the OpenAPI plugin boundary, not on the | |
| 397 | + shared source row. | |
| 398 | + </p> | |
| 399 | + <pre className="mt-3 overflow-x-auto rounded-md bg-muted/60 p-3 text-xs"> | |
| 400 | + {JSON.stringify({ | |
| 401 | + id: props.source.id, | |
| 402 | + kind: props.source.kind, | |
| 403 | + endpoint: props.source.endpoint, | |
| 404 | + sourceHash: props.source.sourceHash, | |
| 405 | + }, null, 2)} | |
| 406 | + </pre> | |
| 407 | + </Section> | |
| 408 | + ); | |
| 409 | +} | |
| 410 | + | |
| 411 | +function OpenApiSourceDetailPage(props: { | |
| 412 | + source: Source; | |
| 413 | +}) { | |
| 414 | + return ( | |
| 415 | + <div className="space-y-4"> | |
| 416 | + <Section title="Source Detail"> | |
| 417 | + <p className="text-sm text-muted-foreground"> | |
| 418 | + OpenAPI-specific configuration and auth live in plugin storage. The shared source record | |
| 419 | + only carries generic routing and status metadata. | |
| 420 | + </p> | |
| 421 | + <pre className="mt-3 overflow-x-auto rounded-md bg-muted/60 p-3 text-xs"> | |
| 422 | + {JSON.stringify({ | |
| 423 | + id: props.source.id, | |
| 424 | + name: props.source.name, | |
| 425 | + kind: props.source.kind, | |
| 426 | + endpoint: props.source.endpoint, | |
| 427 | + status: props.source.status, | |
| 428 | + sourceHash: props.source.sourceHash, | |
| 429 | + }, null, 2)} | |
| 430 | + </pre> | |
| 431 | + </Section> | |
| 432 | + | |
| 433 | + <Section title="Plugin Boundary"> | |
| 434 | + <p className="text-sm text-muted-foreground"> | |
| 435 | + The shell only knows there is a registered source plugin named <code>openapi</code>. | |
| 436 | + Everything specific stays inside this plugin. | |
| 437 | + </p> | |
| 438 | + </Section> | |
| 439 | + </div> | |
| 440 | + ); | |
| 441 | +} | |
| 442 | + | |
| 443 | +export const OpenApiReactPlugin = { | |
| 444 | + key: "openapi", | |
| 445 | + register(api: FrontendPluginRegisterApi) { | |
| 446 | + api.sources.registerType({ | |
| 447 | + kind: "openapi", | |
| 448 | + displayName: "OpenAPI", | |
| 449 | + renderAddPage: () => ( | |
| 450 | + <OpenApiAddSourcePage initialValue={defaultOpenApiInput()} /> | |
| 451 | + ), | |
| 452 | + renderEditPage: ({ source }) => ( | |
| 453 | + <OpenApiEditSourcePage source={source} /> | |
| 454 | + ), | |
| 455 | + renderDetailPage: ({ source }) => ( | |
| 456 | + <OpenApiSourceDetailPage source={source} /> | |
| 457 | + ), | |
| 458 | + }); | |
| 459 | + }, | |
| 460 | +}; | |
| @@ -0,0 +1,27 @@ | ||
| 1 | +{ | |
| 2 | + "name": "@executor/plugin-openapi-react", | |
| 3 | + "private": true, | |
| 4 | + "type": "module", | |
| 5 | + "exports": { | |
| 6 | + ".": "./index.tsx" | |
| 7 | + }, | |
| 8 | + "files": [ | |
| 9 | + "index.tsx" | |
| 10 | + ], | |
| 11 | + "scripts": { | |
| 12 | + "typecheck": "bunx tsc --noEmit -p tsconfig.json" | |
| 13 | + }, | |
| 14 | + "dependencies": { | |
| 15 | + "@executor/plugin-openapi-http": "workspace:*", | |
| 16 | + "@executor/plugin-openapi-shared": "workspace:*", | |
| 17 | + "@executor/react": "workspace:*", | |
| 18 | + "@tanstack/react-router": "^1.132.7", | |
| 19 | + "react": "^19.2.0" | |
| 20 | + }, | |
| 21 | + "devDependencies": { | |
| 22 | + "@types/node": "catalog:", | |
| 23 | + "@types/react": "^19.2.10", | |
| 24 | + "bun-types": "catalog:" | |
| 25 | + }, | |
| 26 | + "version": "0.0.0" | |
| 27 | +} | |
| @@ -0,0 +1,16 @@ | ||
| 1 | +{ | |
| 2 | + "compilerOptions": { | |
| 3 | + "target": "ES2022", | |
| 4 | + "module": "ESNext", | |
| 5 | + "moduleResolution": "Bundler", | |
| 6 | + "strict": true, | |
| 7 | + "skipLibCheck": true, | |
| 8 | + "noEmit": true, | |
| 9 | + "lib": ["ES2022", "DOM", "DOM.Iterable"], | |
| 10 | + "jsx": "react-jsx", | |
| 11 | + "types": ["bun-types", "node"] | |
| 12 | + }, | |
| 13 | + "include": [ | |
| 14 | + "index.tsx" | |
| 15 | + ] | |
| 16 | +} | |
| @@ -0,0 +1,146 @@ | ||
| 1 | +import { createHash } from "node:crypto"; | |
| 2 | +import * as Effect from "effect/Effect"; | |
| 3 | + | |
| 4 | +import { | |
| 5 | + createCatalogImportMetadata, | |
| 6 | + createSourceCatalogSyncResult, | |
| 7 | +} from "@executor/source-core"; | |
| 8 | +import type { Source } from "@executor/platform-sdk/schema"; | |
| 9 | +import type { | |
| 10 | + ExecutorSdkPlugin, | |
| 11 | + SourcePluginRuntime, | |
| 12 | +} from "@executor/platform-sdk/plugins"; | |
| 13 | +import { | |
| 14 | + previewOpenApiDocument, | |
| 15 | + type OpenApiConnectInput, | |
| 16 | + type OpenApiPreviewRequest, | |
| 17 | + type OpenApiPreviewResponse, | |
| 18 | + type OpenApiStoredSourceData, | |
| 19 | +} from "@executor/plugin-openapi-shared"; | |
| 20 | + | |
| 21 | +const stableSourceHash = (value: OpenApiStoredSourceData): string => | |
| 22 | + createHash("sha256").update(JSON.stringify(value)).digest("hex").slice(0, 24); | |
| 23 | + | |
| 24 | +export type OpenApiSourceStorage = { | |
| 25 | + get: (input: { | |
| 26 | + scopeId: string; | |
| 27 | + sourceId: string; | |
| 28 | + }) => Effect.Effect<OpenApiStoredSourceData | null, Error, never>; | |
| 29 | + put: (input: { | |
| 30 | + scopeId: string; | |
| 31 | + sourceId: string; | |
| 32 | + value: OpenApiStoredSourceData; | |
| 33 | + }) => Effect.Effect<void, Error, never>; | |
| 34 | + remove?: (input: { | |
| 35 | + scopeId: string; | |
| 36 | + sourceId: string; | |
| 37 | + }) => Effect.Effect<void, Error, never>; | |
| 38 | +}; | |
| 39 | + | |
| 40 | +export type OpenApiSecrets = { | |
| 41 | + resolve: (input: { | |
| 42 | + ref: string; | |
| 43 | + }) => Effect.Effect<string, Error, never>; | |
| 44 | +}; | |
| 45 | + | |
| 46 | +export type OpenApiSdk = { | |
| 47 | + previewDocument: ( | |
| 48 | + input: OpenApiPreviewRequest, | |
| 49 | + ) => Effect.Effect<OpenApiPreviewResponse, Error, never>; | |
| 50 | + createSource: ( | |
| 51 | + input: OpenApiConnectInput, | |
| 52 | + ) => Effect.Effect<Source, Error, never>; | |
| 53 | +}; | |
| 54 | + | |
| 55 | +export type OpenApiSdkPluginOptions = { | |
| 56 | + storage: OpenApiSourceStorage; | |
| 57 | + secrets?: OpenApiSecrets; | |
| 58 | +}; | |
| 59 | + | |
| 60 | +const createStoredSourceData = ( | |
| 61 | + input: OpenApiConnectInput, | |
| 62 | +): OpenApiStoredSourceData => ({ | |
| 63 | + specUrl: input.specUrl.trim(), | |
| 64 | + baseUrl: input.baseUrl?.trim() || null, | |
| 65 | + auth: input.auth, | |
| 66 | + defaultHeaders: null, | |
| 67 | + etag: null, | |
| 68 | + lastSyncAt: null, | |
| 69 | +}); | |
| 70 | + | |
| 71 | +const createOpenApiSourceRuntime = ( | |
| 72 | + options: OpenApiSdkPluginOptions, | |
| 73 | +): SourcePluginRuntime => ({ | |
| 74 | + kind: "openapi", | |
| 75 | + displayName: "OpenAPI", | |
| 76 | + catalogKind: "imported", | |
| 77 | + catalogIdentity: ({ source }) => ({ | |
| 78 | + kind: "openapi", | |
| 79 | + endpoint: source.endpoint, | |
| 80 | + }), | |
| 81 | + getIrModel: ({ source }) => | |
| 82 | + Effect.gen(function* () { | |
| 83 | + const stored = yield* options.storage.get({ | |
| 84 | + scopeId: source.scopeId, | |
| 85 | + sourceId: source.id, | |
| 86 | + }); | |
| 87 | + | |
| 88 | + return createSourceCatalogSyncResult({ | |
| 89 | + fragment: { | |
| 90 | + version: "ir.v1.fragment", | |
| 91 | + }, | |
| 92 | + importMetadata: { | |
| 93 | + ...createCatalogImportMetadata({ | |
| 94 | + source, | |
| 95 | + pluginKey: "openapi", | |
| 96 | + }), | |
| 97 | + importerVersion: "ir.v1.openapi", | |
| 98 | + sourceConfigHash: | |
| 99 | + stored === null ? source.sourceHash ?? "openapi" : stableSourceHash(stored), | |
| 100 | + }, | |
| 101 | + sourceHash: | |
| 102 | + stored === null ? source.sourceHash ?? null : stableSourceHash(stored), | |
| 103 | + }); | |
| 104 | + }), | |
| 105 | + invoke: () => | |
| 106 | + Effect.fail(new Error("OpenAPI plugin invocation is not implemented.")), | |
| 107 | +}); | |
| 108 | + | |
| 109 | +export const openApiSdkPlugin = ( | |
| 110 | + options: OpenApiSdkPluginOptions, | |
| 111 | +): ExecutorSdkPlugin<"openapi", OpenApiSdk> => ({ | |
| 112 | + key: "openapi", | |
| 113 | + sources: [createOpenApiSourceRuntime(options)], | |
| 114 | + extendExecutor: ({ host }) => ({ | |
| 115 | + previewDocument: (input) => | |
| 116 | + Effect.tryPromise({ | |
| 117 | + try: () => previewOpenApiDocument(input), | |
| 118 | + catch: (cause) => | |
| 119 | + cause instanceof Error ? cause : new Error(String(cause)), | |
| 120 | + }), | |
| 121 | + createSource: (input) => | |
| 122 | + Effect.gen(function* () { | |
| 123 | + const stored = createStoredSourceData(input); | |
| 124 | + const source = yield* host.sources.create({ | |
| 125 | + source: { | |
| 126 | + name: input.name.trim(), | |
| 127 | + kind: "openapi", | |
| 128 | + endpoint: stored.baseUrl ?? stored.specUrl, | |
| 129 | + status: "connected", | |
| 130 | + enabled: true, | |
| 131 | + namespace: null, | |
| 132 | + sourceHash: stableSourceHash(stored), | |
| 133 | + lastError: null, | |
| 134 | + }, | |
| 135 | + }); | |
| 136 | + | |
| 137 | + yield* options.storage.put({ | |
| 138 | + scopeId: source.scopeId, | |
| 139 | + sourceId: source.id, | |
| 140 | + value: stored, | |
| 141 | + }); | |
| 142 | + | |
| 143 | + return source; | |
| 144 | + }), | |
| 145 | + }), | |
| 146 | +}); | |
| @@ -0,0 +1,25 @@ | ||
| 1 | +{ | |
| 2 | + "name": "@executor/plugin-openapi-sdk", | |
| 3 | + "private": true, | |
| 4 | + "type": "module", | |
| 5 | + "exports": { | |
| 6 | + ".": "./index.ts" | |
| 7 | + }, | |
| 8 | + "files": [ | |
| 9 | + "index.ts" | |
| 10 | + ], | |
| 11 | + "scripts": { | |
| 12 | + "typecheck": "bunx tsc --noEmit -p tsconfig.json" | |
| 13 | + }, | |
| 14 | + "dependencies": { | |
| 15 | + "@executor/platform-sdk": "workspace:*", | |
| 16 | + "@executor/plugin-openapi-shared": "workspace:*", | |
| 17 | + "@executor/source-core": "workspace:*", | |
| 18 | + "effect": "catalog:" | |
| 19 | + }, | |
| 20 | + "devDependencies": { | |
| 21 | + "@types/node": "catalog:", | |
| 22 | + "bun-types": "catalog:" | |
| 23 | + }, | |
| 24 | + "version": "0.0.0" | |
| 25 | +} | |
| @@ -0,0 +1,15 @@ | ||
| 1 | +{ | |
| 2 | + "compilerOptions": { | |
| 3 | + "target": "ES2022", | |
| 4 | + "module": "ESNext", | |
| 5 | + "moduleResolution": "Bundler", | |
| 6 | + "strict": true, | |
| 7 | + "skipLibCheck": true, | |
| 8 | + "noEmit": true, | |
| 9 | + "lib": ["ES2022", "DOM"], | |
| 10 | + "types": ["bun-types", "node"] | |
| 11 | + }, | |
| 12 | + "include": [ | |
| 13 | + "index.ts" | |
| 14 | + ] | |
| 15 | +} | |
| @@ -0,0 +1,177 @@ | ||
| 1 | +import * as Effect from "effect/Effect"; | |
| 2 | +import * as Schema from "effect/Schema"; | |
| 3 | +import YAML from "yaml"; | |
| 4 | + | |
| 5 | +import { | |
| 6 | + StringMapSchema, | |
| 7 | +} from "@executor/source-core"; | |
| 8 | + | |
| 9 | +export const OpenApiConnectionAuthSchema = Schema.Union( | |
| 10 | + Schema.Struct({ | |
| 11 | + kind: Schema.Literal("none"), | |
| 12 | + }), | |
| 13 | + Schema.Struct({ | |
| 14 | + kind: Schema.Literal("bearer"), | |
| 15 | + tokenSecretRef: Schema.String, | |
| 16 | + }), | |
| 17 | +); | |
| 18 | + | |
| 19 | +export const OpenApiConnectInputSchema = Schema.Struct({ | |
| 20 | + name: Schema.String, | |
| 21 | + specUrl: Schema.String, | |
| 22 | + baseUrl: Schema.NullOr(Schema.String), | |
| 23 | + auth: OpenApiConnectionAuthSchema, | |
| 24 | +}); | |
| 25 | + | |
| 26 | +export const OpenApiSourceConfigSchema = Schema.Struct({ | |
| 27 | + specUrl: Schema.String, | |
| 28 | + baseUrl: Schema.NullOr(Schema.String), | |
| 29 | + authStrategy: Schema.Literal("none", "bearer"), | |
| 30 | + documentHash: Schema.String, | |
| 31 | +}); | |
| 32 | + | |
| 33 | +export const OpenApiStoredSourceDataSchema = Schema.Struct({ | |
| 34 | + specUrl: Schema.String, | |
| 35 | + baseUrl: Schema.NullOr(Schema.String), | |
| 36 | + auth: OpenApiConnectionAuthSchema, | |
| 37 | + defaultHeaders: Schema.NullOr(StringMapSchema), | |
| 38 | + etag: Schema.NullOr(Schema.String), | |
| 39 | + lastSyncAt: Schema.NullOr(Schema.Number), | |
| 40 | +}); | |
| 41 | + | |
| 42 | +export const OpenApiPreviewRequestSchema = Schema.Struct({ | |
| 43 | + specUrl: Schema.String, | |
| 44 | +}); | |
| 45 | + | |
| 46 | +export const OpenApiPreviewResponseSchema = Schema.Struct({ | |
| 47 | + title: Schema.NullOr(Schema.String), | |
| 48 | + version: Schema.NullOr(Schema.String), | |
| 49 | + baseUrl: Schema.NullOr(Schema.String), | |
| 50 | + operationCount: Schema.Number, | |
| 51 | + warnings: Schema.Array(Schema.String), | |
| 52 | +}); | |
| 53 | + | |
| 54 | +export type OpenApiConnectionAuth = typeof OpenApiConnectionAuthSchema.Type; | |
| 55 | +export type OpenApiConnectInput = typeof OpenApiConnectInputSchema.Type; | |
| 56 | +export type OpenApiSourceConfig = typeof OpenApiSourceConfigSchema.Type; | |
| 57 | +export type OpenApiStoredSourceData = typeof OpenApiStoredSourceDataSchema.Type; | |
| 58 | +export type OpenApiPreviewRequest = typeof OpenApiPreviewRequestSchema.Type; | |
| 59 | +export type OpenApiPreviewResponse = typeof OpenApiPreviewResponseSchema.Type; | |
| 60 | + | |
| 61 | +type JsonRecord = Record<string, unknown>; | |
| 62 | + | |
| 63 | +const asRecord = (value: unknown): JsonRecord | null => | |
| 64 | + value !== null && typeof value === "object" && !Array.isArray(value) | |
| 65 | + ? value as JsonRecord | |
| 66 | + : null; | |
| 67 | + | |
| 68 | +const asString = (value: unknown): string | null => | |
| 69 | + typeof value === "string" && value.trim().length > 0 ? value.trim() : null; | |
| 70 | + | |
| 71 | +const parseDocument = (text: string): unknown => { | |
| 72 | + const trimmed = text.trim(); | |
| 73 | + if (!trimmed) { | |
| 74 | + throw new Error("The OpenAPI document is empty."); | |
| 75 | + } | |
| 76 | + | |
| 77 | + if (trimmed.startsWith("{") || trimmed.startsWith("[")) { | |
| 78 | + return JSON.parse(trimmed); | |
| 79 | + } | |
| 80 | + | |
| 81 | + return YAML.parse(trimmed); | |
| 82 | +}; | |
| 83 | + | |
| 84 | +const deriveBaseUrl = (document: JsonRecord, specUrl: string): string | null => { | |
| 85 | + const servers = Array.isArray(document.servers) ? document.servers : []; | |
| 86 | + const firstServer = asRecord(servers[0]); | |
| 87 | + const rawUrl = asString(firstServer?.url); | |
| 88 | + if (rawUrl === null) { | |
| 89 | + return null; | |
| 90 | + } | |
| 91 | + | |
| 92 | + try { | |
| 93 | + return new URL(rawUrl, specUrl).toString(); | |
| 94 | + } catch { | |
| 95 | + return rawUrl; | |
| 96 | + } | |
| 97 | +}; | |
| 98 | + | |
| 99 | +const countOperations = (document: JsonRecord): number => { | |
| 100 | + const paths = asRecord(document.paths); | |
| 101 | + if (paths === null) { | |
| 102 | + return 0; | |
| 103 | + } | |
| 104 | + | |
| 105 | + const methodNames = new Set([ | |
| 106 | + "get", | |
| 107 | + "post", | |
| 108 | + "put", | |
| 109 | + "patch", | |
| 110 | + "delete", | |
| 111 | + "head", | |
| 112 | + "options", | |
| 113 | + "trace", | |
| 114 | + ]); | |
| 115 | + | |
| 116 | + let count = 0; | |
| 117 | + for (const pathItem of Object.values(paths)) { | |
| 118 | + const pathRecord = asRecord(pathItem); | |
| 119 | + if (pathRecord === null) { | |
| 120 | + continue; | |
| 121 | + } | |
| 122 | + | |
| 123 | + for (const key of Object.keys(pathRecord)) { | |
| 124 | + if (methodNames.has(key.toLowerCase())) { | |
| 125 | + count += 1; | |
| 126 | + } | |
| 127 | + } | |
| 128 | + } | |
| 129 | + | |
| 130 | + return count; | |
| 131 | +}; | |
| 132 | + | |
| 133 | +export const previewOpenApiDocument = async ( | |
| 134 | + input: OpenApiPreviewRequest, | |
| 135 | +): Promise<OpenApiPreviewResponse> => { | |
| 136 | + const response = await fetch(input.specUrl); | |
| 137 | + if (!response.ok) { | |
| 138 | + throw new Error(`Failed fetching spec: ${response.status} ${response.statusText}`); | |
| 139 | + } | |
| 140 | + | |
| 141 | + const text = await response.text(); | |
| 142 | + const parsed = parseDocument(text); | |
| 143 | + const document = asRecord(parsed); | |
| 144 | + if (document === null) { | |
| 145 | + throw new Error("The fetched document is not a valid OpenAPI object."); | |
| 146 | + } | |
| 147 | + | |
| 148 | + const info = asRecord(document.info); | |
| 149 | + const warnings: string[] = []; | |
| 150 | + | |
| 151 | + const openapiVersion = asString(document.openapi) ?? asString(document.swagger); | |
| 152 | + if (openapiVersion === null) { | |
| 153 | + warnings.push("The document does not declare an OpenAPI/Swagger version."); | |
| 154 | + } | |
| 155 | + | |
| 156 | + const baseUrl = deriveBaseUrl(document, input.specUrl); | |
| 157 | + if (baseUrl === null) { | |
| 158 | + warnings.push("No server URL was found in the document."); | |
| 159 | + } | |
| 160 | + | |
| 161 | + return { | |
| 162 | + title: asString(info?.title), | |
| 163 | + version: asString(info?.version), | |
| 164 | + baseUrl, | |
| 165 | + operationCount: countOperations(document), | |
| 166 | + warnings, | |
| 167 | + }; | |
| 168 | +}; | |
| 169 | + | |
| 170 | +export const decodeOpenApiStoredSourceData = ( | |
| 171 | + value: unknown, | |
| 172 | +): Effect.Effect<OpenApiStoredSourceData, Error, never> => | |
| 173 | + Effect.try({ | |
| 174 | + try: () => Schema.decodeUnknownSync(OpenApiStoredSourceDataSchema)(value), | |
| 175 | + catch: (cause) => | |
| 176 | + cause instanceof Error ? cause : new Error(String(cause)), | |
| 177 | + }); | |
| @@ -1,18 +1,20 @@ | ||
| 1 | 1 | { |
| 2 | − "name": "@executor/source-builtins", | |
| 2 | + "name": "@executor/plugin-openapi-shared", | |
| 3 | 3 | "private": true, |
| 4 | 4 | "type": "module", |
| 5 | 5 | "exports": { |
| 6 | − ".": "./src/index.ts" | |
| 6 | + ".": "./index.ts" | |
| 7 | 7 | }, |
| 8 | 8 | "files": [ |
| 9 | − "src" | |
| 9 | + "index.ts" | |
| 10 | 10 | ], |
| 11 | 11 | "scripts": { |
| 12 | 12 | "typecheck": "bunx tsc --noEmit -p tsconfig.json" |
| 13 | 13 | }, |
| 14 | 14 | "dependencies": { |
| 15 | − "@executor/source-core": "workspace:*" | |
| 15 | + "@executor/source-core": "workspace:*", | |
| 16 | + "effect": "catalog:", | |
| 17 | + "yaml": "^2.8.1" | |
| 16 | 18 | }, |
| 17 | 19 | "devDependencies": { |
| 18 | 20 | "@types/node": "catalog:", |
| @@ -0,0 +1,15 @@ | ||
| 1 | +{ | |
| 2 | + "compilerOptions": { | |
| 3 | + "target": "ES2022", | |
| 4 | + "module": "ESNext", | |
| 5 | + "moduleResolution": "Bundler", | |
| 6 | + "strict": true, | |
| 7 | + "skipLibCheck": true, | |
| 8 | + "noEmit": true, | |
| 9 | + "lib": ["ES2022", "DOM"], | |
| 10 | + "types": ["bun-types", "node"] | |
| 11 | + }, | |
| 12 | + "include": [ | |
| 13 | + "index.ts" | |
| 14 | + ] | |
| 15 | +} | |