Unified · Split
| @@ -0,0 +1,20 @@ | ||
| 1 | +import { HttpApiBuilder } from "@effect/platform"; | |
| 2 | +import { Effect } from "effect"; | |
| 3 | + | |
| 4 | +import { ExecutorApi } from "@executor/api"; | |
| 5 | +import { ExecutorService } from "../services/executor"; | |
| 6 | + | |
| 7 | +export const ScopeHandlers = HttpApiBuilder.group( | |
| 8 | + ExecutorApi, | |
| 9 | + "scope", | |
| 10 | + (handlers) => | |
| 11 | + handlers.handle("info", () => | |
| 12 | + Effect.gen(function* () { | |
| 13 | + const executor = yield* ExecutorService; | |
| 14 | + return { | |
| 15 | + id: executor.scope.id, | |
| 16 | + name: executor.scope.name, | |
| 17 | + }; | |
| 18 | + }), | |
| 19 | + ), | |
| 20 | +); | |
| @@ -17,6 +17,7 @@ import { ToolsHandlers } from "./handlers/tools"; · 16 unmodified lines | ||
| 17 | 17 | import { SourcesHandlers } from "./handlers/sources"; |
| 18 | 18 | import { SecretsHandlers } from "./handlers/secrets"; |
| 19 | 19 | import { ExecutionsHandlers } from "./handlers/executions"; |
| 20 | +import { ScopeHandlers } from "./handlers/scope"; | |
| 20 | 21 | import { OpenApiHandlersLive } from "./handlers/openapi"; |
| 21 | 22 | import { McpSourceHandlersLive } from "./handlers/mcp-source"; |
| 22 | 23 | import { GoogleDiscoveryHandlersLive } from "./handlers/google-discovery"; |
| @@ -46,6 +47,7 @@ const ApiBase = HttpApiBuilder.api(ExecutorApiWithPlugins).pipe( · 23 unmodified lines | ||
| 46 | 47 | SourcesHandlers, |
| 47 | 48 | SecretsHandlers, |
| 48 | 49 | ExecutionsHandlers, |
| 50 | + ScopeHandlers, | |
| 49 | 51 | OpenApiHandlersLive, |
| 50 | 52 | McpSourceHandlersLive, |
| 51 | 53 | GoogleDiscoveryHandlersLive, |
| @@ -5,7 +5,7 @@ import { NodeFileSystem } from "@effect/platform-node"; · 4 unmodified lines | ||
| 5 | 5 | import * as fs from "node:fs"; |
| 6 | 6 | |
| 7 | 7 | import { createExecutor, scopeKv } from "@executor/sdk"; |
| 8 | −import { makeSqliteKv, makeKvConfig, migrate } from "@executor/storage-file"; | |
| 8 | +import { makeSqliteKv, makeKvConfig, makeScopedKv, migrate } from "@executor/storage-file"; | |
| 9 | 9 | import { withConfigFile } from "@executor/config"; |
| 10 | 10 | import { openApiPlugin, makeKvOperationStore, type OpenApiPluginExtension } from "@executor/plugin-openapi"; |
| 11 | 11 | import { mcpPlugin, makeKvBindingStore, type McpPluginExtension } from "@executor/plugin-mcp"; |
| @@ -82,8 +82,10 @@ const ExecutorLayer = Layer.effect( · 70 unmodified lines | ||
| 82 | 82 | |
| 83 | 83 | yield* migrate.pipe(Effect.catchAll((e) => Effect.die(e))); |
| 84 | 84 | |
| 85 | + const cwd = process.cwd(); | |
| 85 | 86 | const kv = makeSqliteKv(sql); |
| 86 | − const config = makeKvConfig(kv); | |
| 87 | + const config = makeKvConfig(kv, { cwd }); | |
| 88 | + const scopedKv = makeScopedKv(kv, cwd); | |
| 87 | 89 | |
| 88 | 90 | const configPath = join(process.cwd(), "executor.jsonc"); |
| 89 | 91 | const fsLayer = NodeFileSystem.layer; |
| @@ -93,24 +95,24 @@ const ExecutorLayer = Layer.effect( · 3 unmodified lines | ||
| 93 | 95 | plugins: [ |
| 94 | 96 | openApiPlugin({ |
| 95 | 97 | operationStore: withConfigFile.openapi( |
| 96 | − makeKvOperationStore(kv, "openapi"), | |
| 98 | + makeKvOperationStore(scopedKv, "openapi"), | |
| 97 | 99 | configPath, |
| 98 | 100 | fsLayer, |
| 99 | 101 | ), |
| 100 | 102 | }), |
| 101 | 103 | mcpPlugin({ |
| 102 | 104 | bindingStore: withConfigFile.mcp( |
| 103 | − makeKvBindingStore(kv, "mcp"), | |
| 105 | + makeKvBindingStore(scopedKv, "mcp"), | |
| 104 | 106 | configPath, |
| 105 | 107 | fsLayer, |
| 106 | 108 | ), |
| 107 | 109 | }), |
| 108 | 110 | googleDiscoveryPlugin({ |
| 109 | − bindingStore: makeKvGoogleDiscoveryBindingStore(kv, "google-discovery"), | |
| 111 | + bindingStore: makeKvGoogleDiscoveryBindingStore(scopedKv, "google-discovery"), | |
| 110 | 112 | }), |
| 111 | 113 | graphqlPlugin({ |
| 112 | 114 | operationStore: withConfigFile.graphql( |
| 113 | − makeKvGraphqlOperationStore(kv, "graphql"), | |
| 115 | + makeKvGraphqlOperationStore(scopedKv, "graphql"), | |
| 114 | 116 | configPath, |
| 115 | 117 | fsLayer, |
| 116 | 118 | ), |
| @@ -118,7 +120,7 @@ const ExecutorLayer = Layer.effect( · 1 unmodified line | ||
| 118 | 120 | keychainPlugin(), |
| 119 | 121 | fileSecretsPlugin(), |
| 120 | 122 | onepasswordPlugin({ |
| 121 | − kv: scopeKv(kv, "onepassword"), | |
| 123 | + kv: scopeKv(scopedKv, "onepassword"), | |
| 122 | 124 | }), |
| 123 | 125 | ] as const, |
| 124 | 126 | }); |
| @@ -0,0 +1 @@ | ||
| 1 | +export { useScope } from "@executor/react"; | |
| @@ -9,7 +9,8 @@ import { · 8 unmodified lines | ||
| 9 | 9 | removeSecret, |
| 10 | 10 | } from "@executor/react"; |
| 11 | 11 | import type { SecretProviderPlugin } from "@executor/react"; |
| 12 | −import { SecretId, ScopeId } from "@executor/sdk"; | |
| 12 | +import { SecretId } from "@executor/sdk"; | |
| 13 | +import { useScope } from "../lib/use-scope"; | |
| 13 | 14 | import { onePasswordSecretProviderPlugin } from "@executor/plugin-onepassword/react"; |
| 14 | 15 | import { |
| 15 | 16 | Dialog, |
| @@ -51,8 +52,9 @@ function AddSecretDialog(props: { open: boolean; onOpenChange: (v: boolean) => v · 35 unmodified lines | ||
| 51 | 52 | const [saving, setSaving] = useState(false); |
| 52 | 53 | const [error, setError] = useState<string | null>(null); |
| 53 | 54 | |
| 55 | + const scopeId = useScope(); | |
| 54 | 56 | const doSet = useAtomSet(setSecret, { mode: "promise" }); |
| 55 | − const refresh = useAtomRefresh(secretsAtom()); | |
| 57 | + const refresh = useAtomRefresh(secretsAtom(scopeId)); | |
| 56 | 58 | |
| 57 | 59 | const reset = () => { |
| 58 | 60 | setId(""); |
| @@ -70,7 +72,7 @@ function AddSecretDialog(props: { open: boolean; onOpenChange: (v: boolean) => v · 11 unmodified lines | ||
| 70 | 72 | setError(null); |
| 71 | 73 | try { |
| 72 | 74 | await doSet({ |
| 73 | − path: { scopeId: ScopeId.make("default") }, | |
| 75 | + path: { scopeId }, | |
| 74 | 76 | payload: { |
| 75 | 77 | id: SecretId.make(id.trim()), |
| 76 | 78 | name: name.trim(), |
| @@ -275,15 +277,16 @@ const secretProviderPlugins: SecretProviderPlugin[] = [ · 198 unmodified lines | ||
| 275 | 277 | |
| 276 | 278 | export function SecretsPage() { |
| 277 | 279 | const [addOpen, setAddOpen] = useState(false); |
| 278 | − const secrets = useAtomValue(secretsAtom()); | |
| 280 | + const scopeId = useScope(); | |
| 281 | + const secrets = useAtomValue(secretsAtom(scopeId)); | |
| 279 | 282 | const doRemove = useAtomSet(removeSecret, { mode: "promise" }); |
| 280 | − const refresh = useAtomRefresh(secretsAtom()); | |
| 283 | + const refresh = useAtomRefresh(secretsAtom(scopeId)); | |
| 281 | 284 | |
| 282 | 285 | const handleRemove = async (secretId: string) => { |
| 283 | 286 | try { |
| 284 | 287 | await doRemove({ |
| 285 | 288 | path: { |
| 286 | − scopeId: ScopeId.make("default"), | |
| 289 | + scopeId, | |
| 287 | 290 | secretId: SecretId.make(secretId), |
| 288 | 291 | }, |
| 289 | 292 | }); |
| @@ -1,4 +1,4 @@ | ||
| 1 | −import { useMemo, useState } from "react"; | |
| 1 | +import { useEffect, useMemo, useState } from "react"; | |
| 2 | 2 | import { useNavigate } from "@tanstack/react-router"; |
| 3 | 3 | import { |
| 4 | 4 | useAtomValue, |
| @@ -10,24 +10,31 @@ import { · 5 unmodified lines | ||
| 10 | 10 | removeSource, |
| 11 | 11 | refreshSource, |
| 12 | 12 | Result, |
| 13 | − ScopeId, | |
| 14 | 13 | } from "@executor/react"; |
| 15 | 14 | import { ToolTree } from "../components/tool-tree"; |
| 16 | 15 | import { ToolDetail, ToolDetailEmpty } from "../components/tool-detail"; |
| 17 | 16 | import type { ToolSummary } from "../components/tool-tree"; |
| 18 | − | |
| 19 | −const DEFAULT_SCOPE = ScopeId.make("default"); | |
| 17 | +import { useScope } from "../lib/use-scope"; | |
| 20 | 18 | |
| 21 | 19 | export function SourceDetailPage(props: { namespace: string }) { |
| 22 | 20 | const { namespace } = props; |
| 23 | − const source = useAtomValue(sourceAtom(namespace)); | |
| 24 | − const tools = useAtomValue(sourceToolsAtom(namespace)); | |
| 25 | − const refreshSources = useAtomRefresh(sourcesAtom()); | |
| 26 | − const refreshTools = useAtomRefresh(sourceToolsAtom(namespace)); | |
| 21 | + const scopeId = useScope(); | |
| 22 | + const source = useAtomValue(sourceAtom(namespace, scopeId)); | |
| 23 | + const tools = useAtomValue(sourceToolsAtom(namespace, scopeId)); | |
| 24 | + const refreshSources = useAtomRefresh(sourcesAtom(scopeId)); | |
| 25 | + const refreshTools = useAtomRefresh(sourceToolsAtom(namespace, scopeId)); | |
| 27 | 26 | const doRemove = useAtomSet(removeSource, { mode: "promise" }); |
| 28 | 27 | const doRefresh = useAtomSet(refreshSource, { mode: "promise" }); |
| 29 | 28 | const navigate = useNavigate(); |
| 30 | 29 | |
| 30 | + // HMR: refresh source tools when the backend is hot-reloaded | |
| 31 | + useEffect(() => { | |
| 32 | + if (!import.meta.hot) return; | |
| 33 | + const refresh = () => { refreshTools(); refreshSources(); }; | |
| 34 | + import.meta.hot.on("executor:backend-updated", refresh); | |
| 35 | + return () => { import.meta.hot?.off("executor:backend-updated", refresh); }; | |
| 36 | + }, [refreshTools, refreshSources]); | |
| 37 | + | |
| 31 | 38 | const [selectedToolId, setSelectedToolId] = useState<string | null>(null); |
| 32 | 39 | const [confirmDelete, setConfirmDelete] = useState(false); |
| 33 | 40 | const [deleting, setDeleting] = useState(false); |
| @@ -56,7 +63,7 @@ export function SourceDetailPage(props: { namespace: string }) { · 22 unmodified lines | ||
| 56 | 63 | setDeleting(true); |
| 57 | 64 | try { |
| 58 | 65 | await doRemove({ |
| 59 | − path: { scopeId: DEFAULT_SCOPE, sourceId: namespace }, | |
| 66 | + path: { scopeId, sourceId: namespace }, | |
| 60 | 67 | }); |
| 61 | 68 | refreshSources(); |
| 62 | 69 | void navigate({ to: "/" }); |
| @@ -70,7 +77,7 @@ export function SourceDetailPage(props: { namespace: string }) { · 7 unmodified lines | ||
| 70 | 77 | setRefreshing(true); |
| 71 | 78 | try { |
| 72 | 79 | await doRefresh({ |
| 73 | − path: { scopeId: DEFAULT_SCOPE, sourceId: namespace }, | |
| 80 | + path: { scopeId, sourceId: namespace }, | |
| 74 | 81 | }); |
| 75 | 82 | refreshTools(); |
| 76 | 83 | refreshSources(); |
| @@ -174,7 +181,7 @@ export function SourceDetailPage(props: { namespace: string }) { · 97 unmodified lines | ||
| 174 | 181 | toolId={selectedTool.id} |
| 175 | 182 | toolName={selectedTool.name} |
| 176 | 183 | toolDescription={selectedTool.description} |
| 177 | − scopeId={DEFAULT_SCOPE} | |
| 184 | + scopeId={scopeId} | |
| 178 | 185 | /> |
| 179 | 186 | ) : ( |
| 180 | 187 | <ToolDetailEmpty hasTools={sourceTools.length > 0} /> |
| @@ -1,6 +1,7 @@ | ||
| 1 | 1 | import { useReducer, useCallback, useMemo, Suspense } from "react"; |
| 2 | 2 | import { Link } from "@tanstack/react-router"; |
| 3 | 3 | import { Result, useAtomValue, useAtomRefresh, useAtomSet, sourcesAtom, detectSource } from "@executor/react"; |
| 4 | +import { useScope } from "../lib/use-scope"; | |
| 4 | 5 | import type { SourcePlugin, SourcePreset } from "@executor/react"; |
| 5 | 6 | import { openApiSourcePlugin } from "@executor/plugin-openapi/react"; |
| 6 | 7 | import { mcpSourcePlugin } from "@executor/plugin-mcp/react"; |
| @@ -82,8 +83,9 @@ function reducer(state: State, action: Action): State { · 75 unmodified lines | ||
| 82 | 83 | |
| 83 | 84 | export function SourcesPage() { |
| 84 | 85 | const [state, dispatch] = useReducer(reducer, init); |
| 85 | − const sources = useAtomValue(sourcesAtom()); | |
| 86 | − const refreshSources = useAtomRefresh(sourcesAtom()); | |
| 86 | + const scopeId = useScope(); | |
| 87 | + const sources = useAtomValue(sourcesAtom(scopeId)); | |
| 88 | + const refreshSources = useAtomRefresh(sourcesAtom(scopeId)); | |
| 87 | 89 | const doDetect = useAtomSet(detectSource, { mode: "promise" }); |
| 88 | 90 | |
| 89 | 91 | const handleDetect = useCallback(async () => { |
| @@ -92,7 +94,7 @@ export function SourcesPage() { · 2 unmodified lines | ||
| 92 | 94 | dispatch({ type: "detect-start" }); |
| 93 | 95 | try { |
| 94 | 96 | const results = await doDetect({ |
| 95 | − path: { scopeId: "default" as any }, | |
| 97 | + path: { scopeId }, | |
| 96 | 98 | payload: { url: trimmed }, |
| 97 | 99 | }); |
| 98 | 100 | if (results.length === 0) { |
| @@ -1,7 +1,9 @@ | ||
| 1 | 1 | import { useAtomValue, Result, toolsAtom } from "@executor/react"; |
| 2 | +import { useScope } from "../lib/use-scope"; | |
| 2 | 3 | |
| 3 | 4 | export function ToolsPage() { |
| 4 | − const tools = useAtomValue(toolsAtom()); | |
| 5 | + const scopeId = useScope(); | |
| 6 | + const tools = useAtomValue(toolsAtom(scopeId)); | |
| 5 | 7 | |
| 6 | 8 | return ( |
| 7 | 9 | <div className="min-h-0 flex-1 overflow-y-auto"> |
| @@ -4,9 +4,10 @@ import { · 3 unmodified lines | ||
| 4 | 4 | useAtomRefresh, |
| 5 | 5 | useAtomValue, |
| 6 | 6 | Result, |
| 7 | − sourceToolsAtom, | |
| 8 | 7 | sourcesAtom, |
| 9 | 8 | toolsAtom, |
| 9 | + useScope, | |
| 10 | + useScopeInfo, | |
| 10 | 11 | } from "@executor/react"; |
| 11 | 12 | import { Button } from "@executor/ui/components/button"; |
| 12 | 13 | |
| @@ -190,7 +191,8 @@ function NavItem(props: { to: string; label: string; active: boolean; onNavigate · 177 unmodified lines | ||
| 190 | 191 | // ── SourceList ─────────────────────────────────────────────────────────── |
| 191 | 192 | |
| 192 | 193 | function SourceList(props: { pathname: string; onNavigate?: () => void }) { |
| 193 | − const sources = useAtomValue(sourcesAtom()); | |
| 194 | + const scopeId = useScope(); | |
| 195 | + const sources = useAtomValue(sourcesAtom(scopeId)); | |
| 194 | 196 | |
| 195 | 197 | return Result.match(sources, { |
| 196 | 198 | onInitial: () => ( |
| @@ -236,6 +238,30 @@ function SourceList(props: { pathname: string; onNavigate?: () => void }) { · 39 unmodified lines | ||
| 236 | 238 | }); |
| 237 | 239 | } |
| 238 | 240 | |
| 241 | +// ── ScopeLabel ─────────────────────────────────────────────────────────── | |
| 242 | + | |
| 243 | +function ScopeLabel() { | |
| 244 | + const { name } = useScopeInfo(); | |
| 245 | + // Show just the last folder name, with full path as tooltip | |
| 246 | + const parts = name.replace(/\/+$/, "").split("/"); | |
| 247 | + const folder = parts[parts.length - 1] || name; | |
| 248 | + | |
| 249 | + return ( | |
| 250 | + <div className="mb-1.5 flex items-center gap-1.5 rounded-md px-2.5 py-1.5" title={name}> | |
| 251 | + <svg viewBox="0 0 16 16" fill="none" className="size-3.5 shrink-0 text-muted-foreground/50"> | |
| 252 | + <path | |
| 253 | + d="M2 4.5C2 3.67 2.67 3 3.5 3h3.09a1 1 0 0 1 .7.29l1.42 1.42a1 1 0 0 0 .7.29H12.5c.83 0 1.5.67 1.5 1.5v5.5c0 .83-.67 1.5-1.5 1.5h-9A1.5 1.5 0 0 1 2 12V4.5z" | |
| 254 | + stroke="currentColor" | |
| 255 | + strokeWidth="1.2" | |
| 256 | + /> | |
| 257 | + </svg> | |
| 258 | + <span className="truncate text-[12px] font-medium text-foreground/80"> | |
| 259 | + {folder} | |
| 260 | + </span> | |
| 261 | + </div> | |
| 262 | + ); | |
| 263 | +} | |
| 264 | + | |
| 239 | 265 | // ── SidebarContent ─────────────────────────────────────────────────────── |
| 240 | 266 | |
| 241 | 267 | function SidebarContent(props: { |
| @@ -265,6 +291,7 @@ function SidebarContent(props: { · 23 unmodified lines | ||
| 265 | 291 | )} |
| 266 | 292 | |
| 267 | 293 | <nav className="flex flex-1 flex-col overflow-y-auto p-2"> |
| 294 | + <ScopeLabel /> | |
| 268 | 295 | <NavItem |
| 269 | 296 | to="/" |
| 270 | 297 | label="Dashboard" |
| @@ -338,14 +365,9 @@ function SidebarContent(props: { · 67 unmodified lines | ||
| 338 | 365 | export function Shell() { |
| 339 | 366 | const location = useLocation(); |
| 340 | 367 | const pathname = location.pathname; |
| 341 | − const currentSourceId = pathname.startsWith("/sources/") | |
| 342 | − ? decodeURIComponent(pathname.slice("/sources/".length).split("/")[0] ?? "") | |
| 343 | − : null; | |
| 344 | − const refreshSources = useAtomRefresh(sourcesAtom()); | |
| 345 | − const refreshTools = useAtomRefresh(toolsAtom()); | |
| 346 | − const refreshSourceTools = useAtomRefresh( | |
| 347 | − sourceToolsAtom(currentSourceId ?? "__runtime__"), | |
| 348 | − ); | |
| 368 | + const scopeId = useScope(); | |
| 369 | + const refreshSources = useAtomRefresh(sourcesAtom(scopeId)); | |
| 370 | + const refreshTools = useAtomRefresh(toolsAtom(scopeId)); | |
| 349 | 371 | const { latestVersion, updateAvailable, channel } = useLatestVersion(VITE_APP_VERSION); |
| 350 | 372 | const lastPathname = useRef(pathname); |
| 351 | 373 | const [mobileSidebarOpen, setMobileSidebarOpen] = useState(false); |
| @@ -372,9 +394,6 @@ export function Shell() { · 20 unmodified lines | ||
| 372 | 394 | const refreshBackendData = () => { |
| 373 | 395 | refreshSources(); |
| 374 | 396 | refreshTools(); |
| 375 | − if (currentSourceId) { | |
| 376 | − refreshSourceTools(); | |
| 377 | − } | |
| 378 | 397 | }; |
| 379 | 398 | |
| 380 | 399 | import.meta.hot.on("executor:backend-updated", refreshBackendData); |
| @@ -382,7 +401,7 @@ export function Shell() { · 1 unmodified line | ||
| 382 | 401 | return () => { |
| 383 | 402 | import.meta.hot?.off("executor:backend-updated", refreshBackendData); |
| 384 | 403 | }; |
| 385 | − }, [currentSourceId, refreshSourceTools, refreshSources, refreshTools]); | |
| 404 | + }, [refreshSources, refreshTools]); | |
| 386 | 405 | |
| 387 | 406 | return ( |
| 388 | 407 | <div className="flex h-screen overflow-hidden"> |
| @@ -1,23 +1,28 @@ | ||
| 1 | 1 | import type { ScopeId, ToolId, SecretId } from "@executor/sdk"; |
| 2 | 2 | import { Atom } from "@effect-atom/atom-react"; |
| 3 | −import { ScopeId as ScopeIdSchema } from "@executor/sdk"; | |
| 4 | 3 | |
| 5 | 4 | import { ExecutorApiClient } from "./client"; |
| 6 | 5 | |
| 7 | 6 | // --------------------------------------------------------------------------- |
| 8 | −// Query atoms — typed, cached, reactive | |
| 7 | +// Scope — fetched from the server | |
| 9 | 8 | // --------------------------------------------------------------------------- |
| 10 | 9 | |
| 11 | −const DEFAULT_SCOPE = ScopeIdSchema.make("default"); | |
| 10 | +export const scopeAtom = ExecutorApiClient.query("scope", "info", { | |
| 11 | + timeToLive: "5 minutes", | |
| 12 | +}); | |
| 13 | + | |
| 14 | +// --------------------------------------------------------------------------- | |
| 15 | +// Query atoms — typed, cached, reactive | |
| 16 | +// --------------------------------------------------------------------------- | |
| 12 | 17 | |
| 13 | −export const toolsAtom = (scopeId: ScopeId = DEFAULT_SCOPE) => | |
| 18 | +export const toolsAtom = (scopeId: ScopeId) => | |
| 14 | 19 | ExecutorApiClient.query("tools", "list", { |
| 15 | 20 | path: { scopeId }, |
| 16 | 21 | timeToLive: "30 seconds", |
| 17 | 22 | }); |
| 18 | 23 | |
| 19 | 24 | /** Tools for a specific source */ |
| 20 | −export const sourceToolsAtom = (sourceId: string, scopeId: ScopeId = DEFAULT_SCOPE) => | |
| 25 | +export const sourceToolsAtom = (sourceId: string, scopeId: ScopeId) => | |
| 21 | 26 | ExecutorApiClient.query("sources", "tools", { |
| 22 | 27 | path: { scopeId, sourceId }, |
| 23 | 28 | timeToLive: "30 seconds", |
| @@ -29,20 +34,20 @@ export const toolSchemaAtom = (scopeId: ScopeId, toolId: ToolId) => · 5 unmodified lines | ||
| 29 | 34 | timeToLive: "1 minute", |
| 30 | 35 | }); |
| 31 | 36 | |
| 32 | −export const sourcesAtom = (scopeId: ScopeId = DEFAULT_SCOPE) => | |
| 37 | +export const sourcesAtom = (scopeId: ScopeId) => | |
| 33 | 38 | ExecutorApiClient.query("sources", "list", { |
| 34 | 39 | path: { scopeId }, |
| 35 | 40 | timeToLive: "30 seconds", |
| 36 | 41 | }); |
| 37 | 42 | |
| 38 | 43 | /** Single source by id — derived from the sources list */ |
| 39 | −export const sourceAtom = (sourceId: string, scopeId: ScopeId = DEFAULT_SCOPE) => | |
| 44 | +export const sourceAtom = (sourceId: string, scopeId: ScopeId) => | |
| 40 | 45 | Atom.mapResult( |
| 41 | 46 | sourcesAtom(scopeId), |
| 42 | 47 | (sources) => sources.find((s) => s.id === sourceId) ?? null, |
| 43 | 48 | ); |
| 44 | 49 | |
| 45 | −export const secretsAtom = (scopeId: ScopeId = DEFAULT_SCOPE) => | |
| 50 | +export const secretsAtom = (scopeId: ScopeId) => | |
| 46 | 51 | ExecutorApiClient.query("secrets", "list", { |
| 47 | 52 | path: { scopeId }, |
| 48 | 53 | timeToLive: "30 seconds", |
| @@ -36,6 +36,10 @@ export { · 35 unmodified lines | ||
| 36 | 36 | detectSource, |
| 37 | 37 | } from "./atoms"; |
| 38 | 38 | |
| 39 | +// Scope hook | |
| 40 | +export { useScope, useScopeInfo } from "./use-scope"; | |
| 41 | +export type { ScopeInfo } from "./use-scope"; | |
| 42 | + | |
| 39 | 43 | // Provider |
| 40 | 44 | export { ExecutorProvider } from "./provider"; |
| 41 | 45 | export { SecretPicker } from "./secret-picker"; |
| @@ -1,6 +1,9 @@ | ||
| 1 | 1 | import { RegistryProvider } from "@effect-atom/atom-react"; |
| 2 | 2 | import * as React from "react"; |
| 3 | +import { ScopeProvider } from "./scope-context"; | |
| 3 | 4 | |
| 4 | 5 | export const ExecutorProvider = (props: React.PropsWithChildren) => ( |
| 5 | − <RegistryProvider>{props.children}</RegistryProvider> | |
| 6 | + <RegistryProvider> | |
| 7 | + <ScopeProvider>{props.children}</ScopeProvider> | |
| 8 | + </RegistryProvider> | |
| 6 | 9 | ); |
| @@ -0,0 +1,55 @@ | ||
| 1 | +import * as React from "react"; | |
| 2 | +import { useAtomValue, Result } from "@effect-atom/atom-react"; | |
| 3 | + | |
| 4 | +import type { ScopeId } from "@executor/sdk"; | |
| 5 | +import { scopeAtom } from "./atoms"; | |
| 6 | + | |
| 7 | +export interface ScopeInfo { | |
| 8 | + readonly id: ScopeId; | |
| 9 | + readonly name: string; | |
| 10 | +} | |
| 11 | + | |
| 12 | +const ScopeContext = React.createContext<ScopeInfo | null>(null); | |
| 13 | + | |
| 14 | +/** | |
| 15 | + * Provides the server scope to all children. | |
| 16 | + * Renders nothing until the scope is fetched. | |
| 17 | + */ | |
| 18 | +export function ScopeProvider(props: React.PropsWithChildren) { | |
| 19 | + const result = useAtomValue(scopeAtom); | |
| 20 | + | |
| 21 | + if (Result.isSuccess(result)) { | |
| 22 | + return ( | |
| 23 | + <ScopeContext.Provider value={result.value}> | |
| 24 | + {props.children} | |
| 25 | + </ScopeContext.Provider> | |
| 26 | + ); | |
| 27 | + } | |
| 28 | + | |
| 29 | + // Loading or error — don't render children | |
| 30 | + return null; | |
| 31 | +} | |
| 32 | + | |
| 33 | +/** | |
| 34 | + * Returns the current scope ID. | |
| 35 | + * Must be used inside a ScopeProvider (which gates rendering until scope is loaded). | |
| 36 | + */ | |
| 37 | +export function useScope(): ScopeId { | |
| 38 | + const scope = React.useContext(ScopeContext); | |
| 39 | + if (scope === null) { | |
| 40 | + throw new Error("useScope must be used inside a ScopeProvider"); | |
| 41 | + } | |
| 42 | + return scope.id; | |
| 43 | +} | |
| 44 | + | |
| 45 | +/** | |
| 46 | + * Returns the full scope info (id + display name). | |
| 47 | + * Must be used inside a ScopeProvider. | |
| 48 | + */ | |
| 49 | +export function useScopeInfo(): ScopeInfo { | |
| 50 | + const scope = React.useContext(ScopeContext); | |
| 51 | + if (scope === null) { | |
| 52 | + throw new Error("useScopeInfo must be used inside a ScopeProvider"); | |
| 53 | + } | |
| 54 | + return scope; | |
| 55 | +} | |
| @@ -0,0 +1,2 @@ | ||
| 1 | +export { useScope, useScopeInfo } from "./scope-context"; | |
| 2 | +export type { ScopeInfo } from "./scope-context"; | |
| @@ -5,12 +5,14 @@ import { ToolsApi } from "./tools/api"; · 4 unmodified lines | ||
| 5 | 5 | import { SourcesApi } from "./sources/api"; |
| 6 | 6 | import { SecretsApi } from "./secrets/api"; |
| 7 | 7 | import { ExecutionsApi } from "./executions/api"; |
| 8 | +import { ScopeApi } from "./scope/api"; | |
| 8 | 9 | |
| 9 | 10 | export const CoreExecutorApi = HttpApi.make("executor") |
| 10 | 11 | .add(ToolsApi) |
| 11 | 12 | .add(SourcesApi) |
| 12 | 13 | .add(SecretsApi) |
| 13 | 14 | .add(ExecutionsApi) |
| 15 | + .add(ScopeApi) | |
| 14 | 16 | .annotateContext( |
| 15 | 17 | OpenApi.annotations({ |
| 16 | 18 | title: "Executor API", |
| @@ -3,3 +3,4 @@ export { ToolsApi } from "./tools/api"; · 2 unmodified lines | ||
| 3 | 3 | export { SourcesApi } from "./sources/api"; |
| 4 | 4 | export { SecretsApi } from "./secrets/api"; |
| 5 | 5 | export { ExecutionsApi } from "./executions/api"; |
| 6 | +export { ScopeApi } from "./scope/api"; | |
| @@ -0,0 +1,23 @@ | ||
| 1 | +import { HttpApiEndpoint, HttpApiGroup } from "@effect/platform"; | |
| 2 | +import { Schema } from "effect"; | |
| 3 | +import { ScopeId } from "@executor/sdk"; | |
| 4 | + | |
| 5 | +// --------------------------------------------------------------------------- | |
| 6 | +// Response schemas | |
| 7 | +// --------------------------------------------------------------------------- | |
| 8 | + | |
| 9 | +const ScopeInfoResponse = Schema.Struct({ | |
| 10 | + id: ScopeId, | |
| 11 | + name: Schema.String, | |
| 12 | +}); | |
| 13 | + | |
| 14 | +// --------------------------------------------------------------------------- | |
| 15 | +// Group | |
| 16 | +// --------------------------------------------------------------------------- | |
| 17 | + | |
| 18 | +export class ScopeApi extends HttpApiGroup.make("scope") | |
| 19 | + .add( | |
| 20 | + HttpApiEndpoint.get("info")`/scope` | |
| 21 | + .addSuccess(ScopeInfoResponse), | |
| 22 | + ) | |
| 23 | + .prefix("/v1") {} | |
| @@ -4,7 +4,6 @@ import { ScopeId } from "./ids"; · 3 unmodified lines | ||
| 4 | 4 | |
| 5 | 5 | export class Scope extends Schema.Class<Scope>("Scope")({ |
| 6 | 6 | id: ScopeId, |
| 7 | − parentId: Schema.NullOr(ScopeId), | |
| 8 | 7 | name: Schema.String, |
| 9 | 8 | createdAt: Schema.DateFromNumber, |
| 10 | 9 | }) {} |
| @@ -16,14 +16,14 @@ export const makeTestConfig = < · 15 unmodified lines | ||
| 16 | 16 | const TPlugins extends readonly ExecutorPlugin<string, object>[] = [], |
| 17 | 17 | >( |
| 18 | 18 | options?: { |
| 19 | − readonly name?: string; | |
| 19 | + readonly cwd?: string; | |
| 20 | 20 | readonly plugins?: TPlugins; |
| 21 | 21 | }, |
| 22 | 22 | ): ExecutorConfig<TPlugins> => { |
| 23 | + const cwd = options?.cwd ?? "/test"; | |
| 23 | 24 | const scope: Scope = { |
| 24 | 25 | id: ScopeId.make("test-scope"), |
| 25 | − parentId: null, | |
| 26 | − name: options?.name ?? "test", | |
| 26 | + name: cwd, | |
| 27 | 27 | createdAt: new Date(), |
| 28 | 28 | }; |
| 29 | 29 | |
| @@ -21,6 +21,9 @@ · 20 unmodified lines | ||
| 21 | 21 | // |
| 22 | 22 | // --------------------------------------------------------------------------- |
| 23 | 23 | |
| 24 | +import { createHash } from "node:crypto"; | |
| 25 | +import { basename } from "node:path"; | |
| 26 | + | |
| 24 | 27 | import { scopeKv, ScopeId, makeInMemorySourceRegistry } from "@executor/sdk"; |
| 25 | 28 | import type { Kv, Scope, ExecutorConfig, ExecutorPlugin } from "@executor/sdk"; |
| 26 | 29 | |
| @@ -28,6 +31,16 @@ import { makeKvToolRegistry } from "./tool-registry"; · 1 unmodified line | ||
| 28 | 31 | import { makeKvSecretStore } from "./secret-store"; |
| 29 | 32 | import { makeKvPolicyEngine } from "./policy-engine"; |
| 30 | 33 | |
| 34 | +/** | |
| 35 | + * Derive a URL-safe scope ID from a folder path. | |
| 36 | + * Format: `foldername-shortHash` e.g. `my-project-a1b2c3d4` | |
| 37 | + */ | |
| 38 | +const makeScopeId = (cwd: string): string => { | |
| 39 | + const folder = basename(cwd) || cwd; | |
| 40 | + const hash = createHash("sha256").update(cwd).digest("hex").slice(0, 8); | |
| 41 | + return `${folder}-${hash}`; | |
| 42 | +}; | |
| 43 | + | |
| 31 | 44 | export { makeSqliteKv, makeInMemoryKv } from "./plugin-kv"; |
| 32 | 45 | export { makeKvToolRegistry } from "./tool-registry"; |
| 33 | 46 | export { makeKvSecretStore } from "./secret-store"; |
| @@ -42,32 +55,48 @@ export const makeKvConfig = < · 8 unmodified lines | ||
| 42 | 55 | const TPlugins extends readonly ExecutorPlugin<string, object>[] = [], |
| 43 | 56 | >( |
| 44 | 57 | kv: Kv, |
| 45 | − options?: { | |
| 46 | − readonly name?: string; | |
| 58 | + options: { | |
| 59 | + readonly cwd: string; | |
| 47 | 60 | readonly plugins?: TPlugins; |
| 48 | 61 | }, |
| 49 | 62 | ): ExecutorConfig<TPlugins> => { |
| 63 | + const cwd = options.cwd; | |
| 64 | + const scopeId = makeScopeId(cwd); | |
| 50 | 65 | const scope: Scope = { |
| 51 | − id: ScopeId.make("default"), | |
| 52 | − parentId: null, | |
| 53 | − name: options?.name ?? "default", | |
| 66 | + id: ScopeId.make(scopeId), | |
| 67 | + name: cwd, | |
| 54 | 68 | createdAt: new Date(), |
| 55 | 69 | }; |
| 56 | 70 | |
| 71 | + // Prefix all KV namespaces with the full cwd so each folder is fully isolated. | |
| 72 | + const ns = (name: string) => `${cwd}::${name}`; | |
| 73 | + | |
| 57 | 74 | return { |
| 58 | 75 | scope, |
| 59 | 76 | tools: makeKvToolRegistry( |
| 60 | − scopeKv(kv, "tools"), | |
| 61 | − scopeKv(kv, "defs"), | |
| 77 | + scopeKv(kv, ns("tools")), | |
| 78 | + scopeKv(kv, ns("defs")), | |
| 62 | 79 | ), |
| 63 | 80 | sources: makeInMemorySourceRegistry(), |
| 64 | 81 | secrets: makeKvSecretStore( |
| 65 | − scopeKv(kv, "secrets"), | |
| 82 | + scopeKv(kv, ns("secrets")), | |
| 66 | 83 | ), |
| 67 | 84 | policies: makeKvPolicyEngine( |
| 68 | − scopeKv(kv, "policies"), | |
| 69 | − scopeKv(kv, "meta"), | |
| 85 | + scopeKv(kv, ns("policies")), | |
| 86 | + scopeKv(kv, ns("meta")), | |
| 70 | 87 | ), |
| 71 | 88 | plugins: options?.plugins, |
| 72 | 89 | }; |
| 73 | 90 | }; |
| 91 | + | |
| 92 | +/** | |
| 93 | + * Create a scoped Kv that prefixes all namespaces with the given folder path. | |
| 94 | + * Used by plugins that need their own KV namespace scoped to a folder. | |
| 95 | + */ | |
| 96 | +export const makeScopedKv = (kv: Kv, folder: string): Kv => ({ | |
| 97 | + get: (namespace, key) => kv.get(`${folder}::${namespace}`, key), | |
| 98 | + set: (namespace, key, value) => kv.set(`${folder}::${namespace}`, key, value), | |
| 99 | + delete: (namespace, key) => kv.delete(`${folder}::${namespace}`, key), | |
| 100 | + list: (namespace) => kv.list(`${folder}::${namespace}`), | |
| 101 | + deleteAll: (namespace) => kv.deleteAll(`${folder}::${namespace}`), | |
| 102 | +}); | |
| @@ -2,7 +2,7 @@ import { useCallback, useEffect, useMemo, useRef, useState } from "react"; · 1 unmodified line | ||
| 2 | 2 | import { useAtomSet, useAtomValue, Result } from "@effect-atom/atom-react"; |
| 3 | 3 | |
| 4 | 4 | import { |
| 5 | − ScopeId, | |
| 5 | + useScope, | |
| 6 | 6 | SecretPicker, |
| 7 | 7 | secretsAtom, |
| 8 | 8 | type SecretPickerSecret, |
| @@ -212,8 +212,6 @@ type OAuthPopupResult = · 203 unmodified lines | ||
| 212 | 212 | error: string; |
| 213 | 213 | }; |
| 214 | 214 | |
| 215 | −const DEFAULT_SCOPE = ScopeId.make("default"); | |
| 216 | − | |
| 217 | 215 | function openOAuthPopup( |
| 218 | 216 | url: string, |
| 219 | 217 | onResult: (data: OAuthPopupResult) => void, |
| @@ -287,10 +285,11 @@ export default function AddGoogleDiscoverySource(props: { · 67 unmodified lines | ||
| 287 | 285 | const [error, setError] = useState<string | null>(null); |
| 288 | 286 | const [showScopes, setShowScopes] = useState(false); |
| 289 | 287 | |
| 288 | + const scopeId = useScope(); | |
| 290 | 289 | const doProbe = useAtomSet(probeGoogleDiscovery, { mode: "promise" }); |
| 291 | 290 | const doAdd = useAtomSet(addGoogleDiscoverySource, { mode: "promise" }); |
| 292 | 291 | const doStartOAuth = useAtomSet(startGoogleDiscoveryOAuth, { mode: "promise" }); |
| 293 | − const secrets = useAtomValue(secretsAtom()); | |
| 292 | + const secrets = useAtomValue(secretsAtom(scopeId)); | |
| 294 | 293 | |
| 295 | 294 | const canUseOAuth = useMemo( |
| 296 | 295 | () => (probe?.scopes.length ?? 0) > 0, |
| @@ -326,7 +325,7 @@ export default function AddGoogleDiscoverySource(props: { · 29 unmodified lines | ||
| 326 | 325 | setShowScopes(false); |
| 327 | 326 | try { |
| 328 | 327 | const result = await doProbe({ |
| 329 | − path: { scopeId: DEFAULT_SCOPE }, | |
| 328 | + path: { scopeId }, | |
| 330 | 329 | payload: { discoveryUrl: discoveryUrl.trim() }, |
| 331 | 330 | }); |
| 332 | 331 | setProbe({ ...result, scopes: [...result.scopes] }); |
| @@ -358,7 +357,7 @@ export default function AddGoogleDiscoverySource(props: { · 25 unmodified lines | ||
| 358 | 357 | setError(null); |
| 359 | 358 | try { |
| 360 | 359 | const response = await doStartOAuth({ |
| 361 | − path: { scopeId: DEFAULT_SCOPE }, | |
| 360 | + path: { scopeId }, | |
| 362 | 361 | payload: { |
| 363 | 362 | name: name.trim() || probe.name, |
| 364 | 363 | discoveryUrl: discoveryUrl.trim(), |
| @@ -406,7 +405,7 @@ export default function AddGoogleDiscoverySource(props: { · 41 unmodified lines | ||
| 406 | 405 | setError(null); |
| 407 | 406 | try { |
| 408 | 407 | await doAdd({ |
| 409 | − path: { scopeId: DEFAULT_SCOPE }, | |
| 408 | + path: { scopeId }, | |
| 410 | 409 | payload: { |
| 411 | 410 | name: name.trim() || probe.name, |
| 412 | 411 | discoveryUrl: discoveryUrl.trim(), |
| @@ -4,7 +4,7 @@ import { useAtomSet, useAtomValue, useAtomRefresh, Result } from "@effect-atom/a · 3 unmodified lines | ||
| 4 | 4 | import { |
| 5 | 5 | secretsAtom, |
| 6 | 6 | setSecret, |
| 7 | − ScopeId, | |
| 7 | + useScope, | |
| 8 | 8 | SecretPicker, |
| 9 | 9 | type SecretPickerSecret, |
| 10 | 10 | } from "@executor/react"; |
| @@ -31,8 +31,9 @@ function InlineCreateSecret(props: { · 20 unmodified lines | ||
| 31 | 31 | const [secretValue, setSecretValue] = useState(""); |
| 32 | 32 | const [saving, setSaving] = useState(false); |
| 33 | 33 | const [error, setError] = useState<string | null>(null); |
| 34 | + const scopeId = useScope(); | |
| 34 | 35 | const doSet = useAtomSet(setSecret, { mode: "promise" }); |
| 35 | − const refreshSecrets = useAtomRefresh(secretsAtom()); | |
| 36 | + const refreshSecrets = useAtomRefresh(secretsAtom(scopeId)); | |
| 36 | 37 | |
| 37 | 38 | const handleSave = async () => { |
| 38 | 39 | if (!secretId.trim() || !secretValue.trim()) return; |
| @@ -40,7 +41,7 @@ function InlineCreateSecret(props: { · 1 unmodified line | ||
| 40 | 41 | setError(null); |
| 41 | 42 | try { |
| 42 | 43 | await doSet({ |
| 43 | − path: { scopeId: ScopeId.make("default") }, | |
| 44 | + path: { scopeId }, | |
| 44 | 45 | payload: { |
| 45 | 46 | id: SecretId.make(secretId.trim()), |
| 46 | 47 | name: secretName.trim() || secretId.trim(), |
| @@ -165,8 +166,9 @@ export default function AddGraphqlSource(props: { · 118 unmodified lines | ||
| 165 | 166 | const [adding, setAdding] = useState(false); |
| 166 | 167 | const [addError, setAddError] = useState<string | null>(null); |
| 167 | 168 | |
| 169 | + const scopeId = useScope(); | |
| 168 | 170 | const doAdd = useAtomSet(addGraphqlSource, { mode: "promise" }); |
| 169 | − const secrets = useAtomValue(secretsAtom()); | |
| 171 | + const secrets = useAtomValue(secretsAtom(scopeId)); | |
| 170 | 172 | |
| 171 | 173 | const secretList: readonly SecretPickerSecret[] = Result.match(secrets, { |
| 172 | 174 | onInitial: () => [] as SecretPickerSecret[], |
| @@ -191,7 +193,7 @@ export default function AddGraphqlSource(props: { · 18 unmodified lines | ||
| 191 | 193 | } |
| 192 | 194 | |
| 193 | 195 | await doAdd({ |
| 194 | − path: { scopeId: "default" as never }, | |
| 196 | + path: { scopeId }, | |
| 195 | 197 | payload: { |
| 196 | 198 | endpoint: endpoint.trim(), |
| 197 | 199 | namespace: namespace.trim() || undefined, |
| @@ -1,7 +1,7 @@ | ||
| 1 | 1 | import { useReducer, useCallback, useEffect, useRef } from "react"; |
| 2 | 2 | import { useAtomSet } from "@effect-atom/atom-react"; |
| 3 | 3 | |
| 4 | −import { ScopeId } from "@executor/react"; | |
| 4 | +import { useScope } from "@executor/react"; | |
| 5 | 5 | import { Button } from "@executor/ui/components/button"; |
| 6 | 6 | import { Input } from "@executor/ui/components/input"; |
| 7 | 7 | import { Label } from "@executor/ui/components/label"; |
| @@ -171,6 +171,7 @@ export default function AddMcpSource(props: { · 163 unmodified lines | ||
| 171 | 171 | props.initialUrl ? { step: "url" as const, url: props.initialUrl } : init, |
| 172 | 172 | ); |
| 173 | 173 | |
| 174 | + const scopeId = useScope(); | |
| 174 | 175 | const doProbe = useAtomSet(probeMcpEndpoint, { mode: "promise" }); |
| 175 | 176 | const doAdd = useAtomSet(addMcpSource, { mode: "promise" }); |
| 176 | 177 | const doStartOAuth = useAtomSet(startMcpOAuth, { mode: "promise" }); |
| @@ -191,14 +192,14 @@ export default function AddMcpSource(props: { · 14 unmodified lines | ||
| 191 | 192 | dispatch({ type: "probe-start" }); |
| 192 | 193 | try { |
| 193 | 194 | const result = await doProbe({ |
| 194 | − path: { scopeId: ScopeId.make("default") }, | |
| 195 | + path: { scopeId }, | |
| 195 | 196 | payload: { endpoint: state.url.trim() }, |
| 196 | 197 | }); |
| 197 | 198 | dispatch({ type: "probe-ok", probe: result }); |
| 198 | 199 | } catch (e) { |
| 199 | 200 | dispatch({ type: "probe-fail", error: e instanceof Error ? e.message : "Failed to connect" }); |
| 200 | 201 | } |
| 201 | − }, [state.url, doProbe]); | |
| 202 | + }, [state.url, scopeId, doProbe]); | |
| 202 | 203 | |
| 203 | 204 | const autoProbed = useRef(false); |
| 204 | 205 | useEffect(() => { |
| @@ -213,7 +214,7 @@ export default function AddMcpSource(props: { · 8 unmodified lines | ||
| 213 | 214 | try { |
| 214 | 215 | const redirectUrl = `${window.location.origin}/v1/mcp/oauth/callback`; |
| 215 | 216 | const result = await doStartOAuth({ |
| 216 | − path: { scopeId: ScopeId.make("default") }, | |
| 217 | + path: { scopeId }, | |
| 217 | 218 | payload: { endpoint: state.url.trim(), redirectUrl }, |
| 218 | 219 | }); |
| 219 | 220 | dispatch({ type: "oauth-waiting", sessionId: result.sessionId }); |
| @@ -247,7 +248,7 @@ export default function AddMcpSource(props: { · 27 unmodified lines | ||
| 247 | 248 | dispatch({ type: "add-start" }); |
| 248 | 249 | try { |
| 249 | 250 | await doAdd({ |
| 250 | − path: { scopeId: ScopeId.make("default") }, | |
| 251 | + path: { scopeId }, | |
| 251 | 252 | payload: { |
| 252 | 253 | transport: "remote" as const, |
| 253 | 254 | name: probe.serverName ?? probe.name, |
| @@ -1,7 +1,7 @@ | ||
| 1 | 1 | import { useState } from "react"; |
| 2 | 2 | import { useAtomSet, useAtomValue, useAtomRefresh } from "@effect-atom/atom-react"; |
| 3 | 3 | import { Result } from "@effect-atom/atom-react"; |
| 4 | −import { ScopeId } from "@executor/sdk"; | |
| 4 | +import { useScope } from "@executor/react"; | |
| 5 | 5 | import { Button } from "@executor/ui/components/button"; |
| 6 | 6 | import { Input } from "@executor/ui/components/input"; |
| 7 | 7 | import { Label } from "@executor/ui/components/label"; |
| @@ -41,8 +41,9 @@ function VaultPicker(props: { · 33 unmodified lines | ||
| 41 | 41 | onVaultSelect: (id: string, name: string) => void; |
| 42 | 42 | }) { |
| 43 | 43 | const account = props.accountName.trim(); |
| 44 | + const scopeId = useScope(); | |
| 44 | 45 | const vaultsResult = useAtomValue( |
| 45 | − onepasswordVaultsAtom(props.authKind, account), | |
| 46 | + onepasswordVaultsAtom(props.authKind, account, scopeId), | |
| 46 | 47 | ); |
| 47 | 48 | |
| 48 | 49 | const { vaults, isLoading, error } = Result.match( |
| @@ -117,8 +118,9 @@ function ConfigDialog(props: { · 68 unmodified lines | ||
| 117 | 118 | const [saving, setSaving] = useState(false); |
| 118 | 119 | const [error, setError] = useState<string | null>(null); |
| 119 | 120 | |
| 121 | + const scopeId = useScope(); | |
| 120 | 122 | const doConfigure = useAtomSet(configureOnePassword, { mode: "promise" }); |
| 121 | − const refreshConfig = useAtomRefresh(onepasswordConfigAtom()); | |
| 123 | + const refreshConfig = useAtomRefresh(onepasswordConfigAtom(scopeId)); | |
| 122 | 124 | |
| 123 | 125 | const reset = () => { |
| 124 | 126 | if (!isEdit) { |
| @@ -142,7 +144,7 @@ function ConfigDialog(props: { · 17 unmodified lines | ||
| 142 | 144 | : { kind: "service-account" as const, tokenSecretId: accountName.trim() }; |
| 143 | 145 | |
| 144 | 146 | await doConfigure({ |
| 145 | − path: { scopeId: "default" as ScopeId }, | |
| 147 | + path: { scopeId }, | |
| 146 | 148 | payload: { auth, vaultId: vaultId.trim(), name: vaultName.trim() || "1Password" }, |
| 147 | 149 | }); |
| 148 | 150 | props.onOpenChange(false); |
| @@ -256,13 +258,14 @@ function ConfigDialog(props: { · 107 unmodified lines | ||
| 256 | 258 | |
| 257 | 259 | export default function OnePasswordSettings() { |
| 258 | 260 | const [configOpen, setConfigOpen] = useState(false); |
| 259 | − const configResult = useAtomValue(onepasswordConfigAtom()); | |
| 261 | + const scopeId = useScope(); | |
| 262 | + const configResult = useAtomValue(onepasswordConfigAtom(scopeId)); | |
| 260 | 263 | const doRemove = useAtomSet(removeOnePasswordConfig, { mode: "promise" }); |
| 261 | − const refreshConfig = useAtomRefresh(onepasswordConfigAtom()); | |
| 264 | + const refreshConfig = useAtomRefresh(onepasswordConfigAtom(scopeId)); | |
| 262 | 265 | |
| 263 | 266 | const handleRemove = async () => { |
| 264 | 267 | try { |
| 265 | − await doRemove({ path: { scopeId: "default" as ScopeId } }); | |
| 268 | + await doRemove({ path: { scopeId } }); | |
| 266 | 269 | refreshConfig(); |
| 267 | 270 | } catch { /* TODO: toast */ } |
| 268 | 271 | }; |
| @@ -1,23 +1,17 @@ | ||
| 1 | −import { ScopeId } from "@executor/sdk"; | |
| 1 | +import type { ScopeId } from "@executor/sdk"; | |
| 2 | 2 | import { OnePasswordClient } from "./client"; |
| 3 | 3 | |
| 4 | 4 | // --------------------------------------------------------------------------- |
| 5 | −// Stable default scope | |
| 5 | +// Query atoms | |
| 6 | 6 | // --------------------------------------------------------------------------- |
| 7 | 7 | |
| 8 | −const DEFAULT_SCOPE = ScopeId.make("default"); | |
| 9 | − | |
| 10 | −// --------------------------------------------------------------------------- | |
| 11 | −// Query atoms — stable references for default scope | |
| 12 | −// --------------------------------------------------------------------------- | |
| 13 | − | |
| 14 | −export const onepasswordConfigAtom = (scopeId: ScopeId = DEFAULT_SCOPE) => | |
| 8 | +export const onepasswordConfigAtom = (scopeId: ScopeId) => | |
| 15 | 9 | OnePasswordClient.query("onepassword", "getConfig", { |
| 16 | 10 | path: { scopeId }, |
| 17 | 11 | timeToLive: "30 seconds", |
| 18 | 12 | }); |
| 19 | 13 | |
| 20 | −export const onepasswordStatusAtom = (scopeId: ScopeId = DEFAULT_SCOPE) => | |
| 14 | +export const onepasswordStatusAtom = (scopeId: ScopeId) => | |
| 21 | 15 | OnePasswordClient.query("onepassword", "status", { |
| 22 | 16 | path: { scopeId }, |
| 23 | 17 | timeToLive: "15 seconds", |
| @@ -30,7 +24,7 @@ export const onepasswordStatusAtom = (scopeId: ScopeId = DEFAULT_SCOPE) => · 6 unmodified lines | ||
| 30 | 24 | export const onepasswordVaultsAtom = ( |
| 31 | 25 | authKind: "desktop-app" | "service-account", |
| 32 | 26 | account: string, |
| 33 | − scopeId: ScopeId = DEFAULT_SCOPE, | |
| 27 | + scopeId: ScopeId, | |
| 34 | 28 | ) => |
| 35 | 29 | OnePasswordClient.query("onepassword", "listVaults", { |
| 36 | 30 | path: { scopeId }, |
| @@ -6,7 +6,7 @@ import { · 5 unmodified lines | ||
| 6 | 6 | secretsAtom, |
| 7 | 7 | setSecret, |
| 8 | 8 | resolveSecret, |
| 9 | − ScopeId, | |
| 9 | + useScope, | |
| 10 | 10 | SecretPicker, |
| 11 | 11 | type SecretPickerSecret, |
| 12 | 12 | } from "@executor/react"; |
| @@ -38,8 +38,9 @@ function InlineCreateSecret(props: { · 25 unmodified lines | ||
| 38 | 38 | const [secretValue, setSecretValue] = useState(""); |
| 39 | 39 | const [saving, setSaving] = useState(false); |
| 40 | 40 | const [error, setError] = useState<string | null>(null); |
| 41 | + const scopeId = useScope(); | |
| 41 | 42 | const doSet = useAtomSet(setSecret, { mode: "promise" }); |
| 42 | − const refreshSecrets = useAtomRefresh(secretsAtom()); | |
| 43 | + const refreshSecrets = useAtomRefresh(secretsAtom(scopeId)); | |
| 43 | 44 | |
| 44 | 45 | const handleSave = async () => { |
| 45 | 46 | if (!secretId.trim() || !secretValue.trim()) return; |
| @@ -47,7 +48,7 @@ function InlineCreateSecret(props: { · 1 unmodified line | ||
| 47 | 48 | setError(null); |
| 48 | 49 | try { |
| 49 | 50 | await doSet({ |
| 50 | − path: { scopeId: ScopeId.make("default") }, | |
| 51 | + path: { scopeId }, | |
| 51 | 52 | payload: { |
| 52 | 53 | id: SecretId.make(secretId.trim()), |
| 53 | 54 | name: secretName.trim() || secretId.trim(), |
| @@ -129,6 +130,7 @@ function HeaderValuePreview(props: { · 75 unmodified lines | ||
| 129 | 130 | prefix?: string; |
| 130 | 131 | }) { |
| 131 | 132 | const { headerName, secretId, prefix } = props; |
| 133 | + const scopeId = useScope(); | |
| 132 | 134 | const [state, setState] = useState<ResolveState>({ status: "hidden" }); |
| 133 | 135 | const doResolve = useAtomSet(resolveSecret, { mode: "promise" }); |
| 134 | 136 | |
| @@ -141,7 +143,7 @@ function HeaderValuePreview(props: { · 6 unmodified lines | ||
| 141 | 143 | try { |
| 142 | 144 | const result = await doResolve({ |
| 143 | 145 | path: { |
| 144 | − scopeId: ScopeId.make("default"), | |
| 146 | + scopeId, | |
| 145 | 147 | secretId: SecretId.make(secretId), |
| 146 | 148 | }, |
| 147 | 149 | }); |
| @@ -433,9 +435,10 @@ export default function AddOpenApiSource(props: { · 285 unmodified lines | ||
| 433 | 435 | const [adding, setAdding] = useState(false); |
| 434 | 436 | const [addError, setAddError] = useState<string | null>(null); |
| 435 | 437 | |
| 438 | + const scopeId = useScope(); | |
| 436 | 439 | const doPreview = useAtomSet(previewOpenApiSpec, { mode: "promise" }); |
| 437 | 440 | const doAdd = useAtomSet(addOpenApiSpec, { mode: "promise" }); |
| 438 | − const secrets = useAtomValue(secretsAtom()); | |
| 441 | + const secrets = useAtomValue(secretsAtom(scopeId)); | |
| 439 | 442 | const autoAnalyzed = useRef(false); |
| 440 | 443 | |
| 441 | 444 | useEffect(() => { |
| @@ -497,7 +500,7 @@ export default function AddOpenApiSource(props: { · 55 unmodified lines | ||
| 497 | 500 | setAddError(null); |
| 498 | 501 | try { |
| 499 | 502 | const result = await doPreview({ |
| 500 | − path: { scopeId: "default" as never }, | |
| 503 | + path: { scopeId }, | |
| 501 | 504 | payload: { spec: specUrl }, |
| 502 | 505 | }); |
| 503 | 506 | setPreview(result); |
| @@ -546,7 +549,7 @@ export default function AddOpenApiSource(props: { · 42 unmodified lines | ||
| 546 | 549 | setAddError(null); |
| 547 | 550 | try { |
| 548 | 551 | await doAdd({ |
| 549 | − path: { scopeId: "default" as never }, | |
| 552 | + path: { scopeId }, | |
| 550 | 553 | payload: { |
| 551 | 554 | spec: specUrl, |
| 552 | 555 | baseUrl: baseUrl.trim() || undefined, |
| @@ -181,8 +181,7 @@ layer(TestLayer)("OpenAPI Plugin", (it) => { · 180 unmodified lines | ||
| 181 | 181 | |
| 182 | 182 | const scope = { |
| 183 | 183 | id: ScopeId.make("test-scope"), |
| 184 | − parentId: null, | |
| 185 | − name: "test", | |
| 184 | + name: "/test", | |
| 186 | 185 | createdAt: new Date(), |
| 187 | 186 | } as const; |
| 188 | 187 | |
| @@ -206,7 +206,11 @@ export const openApiPlugin = (options?: { · 205 unmodified lines | ||
| 206 | 206 | Effect.gen(function* () { |
| 207 | 207 | const trimmed = url.trim(); |
| 208 | 208 | if (!trimmed) return null; |
| 209 | − try { new URL(trimmed); } catch { return null; } | |
| 209 | + try { | |
| 210 | + new URL(trimmed); | |
| 211 | + } catch { | |
| 212 | + return null; | |
| 213 | + } | |
| 210 | 214 | |
| 211 | 215 | // Try fetching the URL and parsing as OpenAPI spec |
| 212 | 216 | // parse() handles both URLs directly and spec text |
| @@ -310,7 +314,7 @@ export const openApiPlugin = (options?: { · 97 unmodified lines | ||
| 310 | 314 | id: "openapi.previewSpec", |
| 311 | 315 | name: "openapi.previewSpec", |
| 312 | 316 | description: |
| 313 | − "Preview an OpenAPI document before adding it as a source", | |
| 317 | + "Preview an OpenAPI document before adding it as a source \n\n ```ts \ntesting this```", | |
| 314 | 318 | inputSchema: PreviewSpecInputSchema, |
| 315 | 319 | outputSchema: SpecPreview, |
| 316 | 320 | handler: ({ spec }: PreviewSpecInput) => previewSpec(spec), |
| @@ -1,7 +1,27 @@ | ||
| 1 | +import { isValidElement, Children, type ReactNode } from "react"; | |
| 1 | 2 | import { Streamdown } from "streamdown"; |
| 2 | −import { createCodeHighlighterPlugin } from "../lib/shiki"; | |
| 3 | +import { CodeBlock } from "./code-block"; | |
| 3 | 4 | |
| 4 | −const codePlugin = createCodeHighlighterPlugin(); | |
| 5 | +function extractText(node: ReactNode): string { | |
| 6 | + if (typeof node === "string") return node; | |
| 7 | + if (typeof node === "number") return String(node); | |
| 8 | + if (Array.isArray(node)) return node.map(extractText).join(""); | |
| 9 | + if (isValidElement(node) && node.props) { | |
| 10 | + return extractText((node.props as { children?: ReactNode }).children); | |
| 11 | + } | |
| 12 | + return ""; | |
| 13 | +} | |
| 14 | + | |
| 15 | +function PreBlock(props: { children?: ReactNode; node?: unknown }) { | |
| 16 | + const child = Children.toArray(props.children)[0]; | |
| 17 | + if (isValidElement(child) && (child.type === "code" || (child.props as Record<string, unknown>)?.className)) { | |
| 18 | + const childProps = child.props as { className?: string; children?: ReactNode }; | |
| 19 | + const lang = childProps.className?.replace("language-", "") ?? undefined; | |
| 20 | + const code = extractText(childProps.children).replace(/\n$/, ""); | |
| 21 | + return <CodeBlock code={code} lang={lang} className="my-2" />; | |
| 22 | + } | |
| 23 | + return <pre>{props.children}</pre>; | |
| 24 | +} | |
| 5 | 25 | |
| 6 | 26 | const PROSE_CLASSES = [ |
| 7 | 27 | "text-[13px] leading-relaxed text-muted-foreground", |
| @@ -13,10 +33,6 @@ const PROSE_CLASSES = [ · 5 unmodified lines | ||
| 13 | 33 | // inline code |
| 14 | 34 | "[&_code]:font-mono [&_code]:text-xs [&_code]:bg-muted [&_code]:border [&_code]:border-border", |
| 15 | 35 | "[&_code]:rounded-sm [&_code]:px-1.5 [&_code]:py-px [&_code]:text-primary", |
| 16 | − // pre blocks | |
| 17 | − "[&_pre]:bg-muted [&_pre]:border [&_pre]:border-border [&_pre]:rounded-md", | |
| 18 | − "[&_pre]:px-3 [&_pre]:py-2 [&_pre]:overflow-x-auto [&_pre]:my-2 [&_pre]:text-xs [&_pre]:leading-relaxed", | |
| 19 | − "[&_pre_code]:bg-transparent [&_pre_code]:border-0 [&_pre_code]:p-0 [&_pre_code]:text-inherit", | |
| 20 | 36 | // links |
| 21 | 37 | "[&_a]:text-primary [&_a]:underline [&_a]:underline-offset-2", |
| 22 | 38 | "[&_a]:decoration-primary/30 hover:[&_a]:decoration-primary/80", |
| @@ -43,7 +59,10 @@ const PROSE_CLASSES = [ · 20 unmodified lines | ||
| 43 | 59 | export function Markdown(props: { children: string; className?: string }) { |
| 44 | 60 | return ( |
| 45 | 61 | <div className={props.className ? `${PROSE_CLASSES} ${props.className}` : PROSE_CLASSES}> |
| 46 | − <Streamdown plugins={{ code: codePlugin }} controls={{ code: true }} linkSafety={{ enabled: false }}> | |
| 62 | + <Streamdown | |
| 63 | + linkSafety={{ enabled: false }} | |
| 64 | + components={{ pre: PreBlock as never }} | |
| 65 | + > | |
| 47 | 66 | {props.children} |
| 48 | 67 | </Streamdown> |
| 49 | 68 | </div> |