History

fix markdown rendering, scope to current folder

Rhys Sullivan committed 7 months ago

Commit 996904a1 parent df846c129 files · +323 −118Browse files

Unified · Split

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

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t