| @@ -13,8 +13,6 @@ import { · 12 unmodified lines |
| 13 | RuntimeSourceCatalogStoreService, | 13 | RuntimeSourceCatalogStoreService, |
| 14 | type LoadedSourceCatalogToolIndexEntry, | 14 | type LoadedSourceCatalogToolIndexEntry, |
| 15 | catalogToolCatalogEntry, | 15 | catalogToolCatalogEntry, |
| 16 | expandCatalogTools, | | |
| 17 | loadedSourceCatalogToolIndexEntryFromLoadedTool, | | |
| 18 | } from "../../catalog/source/runtime"; | 16 | } from "../../catalog/source/runtime"; |
| 19 | import type { | 17 | import type { |
| 20 | RuntimeLocalScopeState, | 18 | RuntimeLocalScopeState, |
| @@ -130,40 +128,21 @@ export const loadWorkspaceCatalogTools = (input: { · 109 unmodified lines |
| 130 | scopeId: Source["scopeId"]; | 128 | scopeId: Source["scopeId"]; |
| 131 | actorScopeId: ScopeId; | 129 | actorScopeId: ScopeId; |
| 132 | sourceCatalogStore: Effect.Effect.Success<typeof RuntimeSourceCatalogStoreService>; | 130 | sourceCatalogStore: Effect.Effect.Success<typeof RuntimeSourceCatalogStoreService>; |
| 133 | includeSchemas: boolean; | | |
| 134 | }): Effect.Effect< | 131 | }): Effect.Effect< |
| 135 | readonly LoadedSourceCatalogToolIndexEntry[], | 132 | readonly LoadedSourceCatalogToolIndexEntry[], |
| 136 | Error, | 133 | Error, |
| 137 | ScopeStorageServices | 134 | ScopeStorageServices |
| 138 | > => | 135 | > => |
| 139 | input.includeSchemas | 136 | Effect.map( |
| 140 | ? Effect.gen(function* () { | 137 | input.sourceCatalogStore.loadWorkspaceSourceCatalogToolIndex({ |
| 141 | const catalogs = yield* input.sourceCatalogStore.loadWorkspaceSourceCatalogs({ | 138 | scopeId: input.scopeId, |
| 142 | scopeId: input.scopeId, | 139 | actorScopeId: input.actorScopeId, |
| 143 | actorScopeId: input.actorScopeId, | 140 | }), |
| 144 | }); | 141 | (tools) => |
| 145 | const tools = yield* expandCatalogTools({ | 142 | tools.filter( |
| 146 | catalogs, | 143 | (tool) => tool.source.enabled && tool.source.status === "connected", |
| 147 | includeSchemas: true, | 144 | ), |
| 148 | includeTypePreviews: true, | 145 | ); |
| 149 | }); | | |
| 150 | | | |
| 151 | return tools | | |
| 152 | .map(loadedSourceCatalogToolIndexEntryFromLoadedTool) | | |
| 153 | .filter( | | |
| 154 | (tool) => tool.source.enabled && tool.source.status === "connected", | | |
| 155 | ); | | |
| 156 | }) | | |
| 157 | : Effect.map( | | |
| 158 | input.sourceCatalogStore.loadWorkspaceSourceCatalogToolIndex({ | | |
| 159 | scopeId: input.scopeId, | | |
| 160 | actorScopeId: input.actorScopeId, | | |
| 161 | }), | | |
| 162 | (tools) => | | |
| 163 | tools.filter( | | |
| 164 | (tool) => tool.source.enabled && tool.source.status === "connected", | | |
| 165 | ), | | |
| 166 | ); | | |
| 167 | | 146 | |
| 168 | export const loadWorkspaceCatalogToolByPath = (input: { | 147 | export const loadWorkspaceCatalogToolByPath = (input: { |
| 169 | scopeId: Source["scopeId"]; | 148 | scopeId: Source["scopeId"]; |
| @@ -332,13 +311,12 @@ export const createScopeSourceCatalog = (input: { · 162 unmodified lines |
| 332 | const provideWorkspaceStorage = <A, E, R>(effect: Effect.Effect<A, E, R>) => | 311 | const provideWorkspaceStorage = <A, E, R>(effect: Effect.Effect<A, E, R>) => |
| 333 | effect.pipe(Effect.provide(scopeStorageLayer)); | 312 | effect.pipe(Effect.provide(scopeStorageLayer)); |
| 334 | | 313 | |
| 335 | const buildSharedCatalog = (includeSchemas: boolean) => | 314 | const buildSharedCatalog = () => |
| 336 | provideWorkspaceStorage(Effect.gen(function* () { | 315 | provideWorkspaceStorage(Effect.gen(function* () { |
| 337 | const catalogTools = yield* loadWorkspaceCatalogTools({ | 316 | const catalogTools = yield* loadWorkspaceCatalogTools({ |
| 338 | scopeId: input.scopeId, | 317 | scopeId: input.scopeId, |
| 339 | actorScopeId: input.actorScopeId, | 318 | actorScopeId: input.actorScopeId, |
| 340 | sourceCatalogStore: input.sourceCatalogStore, | 319 | sourceCatalogStore: input.sourceCatalogStore, |
| 341 | includeSchemas, | | |
| 342 | }); | 320 | }); |
| 343 | | 321 | |
| 344 | return createToolCatalogFromEntries({ | 322 | return createToolCatalogFromEntries({ |
| @@ -352,15 +330,9 @@ export const createScopeSourceCatalog = (input: { · 7 unmodified lines |
| 352 | })); | 330 | })); |
| 353 | | 331 | |
| 354 | const leanSharedCatalog = Effect.runSync( | 332 | const leanSharedCatalog = Effect.runSync( |
| 355 | Effect.cached(buildSharedCatalog(false)), | 333 | Effect.cached(buildSharedCatalog()), |
| 356 | ); | | |
| 357 | const schemaSharedCatalog = Effect.runSync( | | |
| 358 | Effect.cached(buildSharedCatalog(true)), | | |
| 359 | ); | 334 | ); |
| 360 | | 335 | |
| 361 | const createSharedCatalog = (includeSchemas: boolean): Effect.Effect<ToolCatalog, Error, never> => | | |
| 362 | includeSchemas ? schemaSharedCatalog : leanSharedCatalog; | | |
| 363 | | | |
| 364 | return { | 336 | return { |
| 365 | listNamespaces: ({ limit }) => | 337 | listNamespaces: ({ limit }) => |
| 366 | provideRuntimeLocalScope( | 338 | provideRuntimeLocalScope( |
| @@ -375,14 +347,14 @@ export const createScopeSourceCatalog = (input: { · 8 unmodified lines |
| 375 | input.runtimeLocalScope, | 347 | input.runtimeLocalScope, |
| 376 | ), | 348 | ), |
| 377 | | 349 | |
| 378 | listTools: ({ namespace, query, limit, includeSchemas = false }) => | 350 | listTools: ({ namespace, query, limit }) => |
| 379 | provideRuntimeLocalScope( | 351 | provideRuntimeLocalScope( |
| 380 | Effect.flatMap(createSharedCatalog(includeSchemas), (catalog) => | 352 | Effect.flatMap(leanSharedCatalog, (catalog) => |
| 381 | catalog.listTools({ | 353 | catalog.listTools({ |
| 382 | ...(namespace !== undefined ? { namespace } : {}), | 354 | ...(namespace !== undefined ? { namespace } : {}), |
| 383 | ...(query !== undefined ? { query } : {}), | 355 | ...(query !== undefined ? { query } : {}), |
| 384 | limit, | 356 | limit, |
| 385 | includeSchemas, | 357 | includeSchemas: false, |
| 386 | }), | 358 | }), |
| 387 | ), | 359 | ), |
| 388 | input.runtimeLocalScope, | 360 | input.runtimeLocalScope, |
| @@ -390,15 +362,26 @@ export const createScopeSourceCatalog = (input: { · 1 unmodified line |
| 390 | | 362 | |
| 391 | getToolByPath: ({ path, includeSchemas }) => | 363 | getToolByPath: ({ path, includeSchemas }) => |
| 392 | provideRuntimeLocalScope( | 364 | provideRuntimeLocalScope( |
| 393 | Effect.flatMap(createSharedCatalog(includeSchemas), (catalog) => | 365 | includeSchemas |
| 394 | catalog.getToolByPath({ path, includeSchemas }), | 366 | ? Effect.map( |
| 395 | ), | 367 | provideWorkspaceStorage(loadWorkspaceCatalogToolByPath({ |
| | 368 | scopeId: input.scopeId, |
| | 369 | actorScopeId: input.actorScopeId, |
| | 370 | sourceCatalogStore: input.sourceCatalogStore, |
| | 371 | path, |
| | 372 | includeSchemas: true, |
| | 373 | })), |
| | 374 | (tool) => tool?.descriptor ?? null, |
| | 375 | ) |
| | 376 | : Effect.flatMap(leanSharedCatalog, (catalog) => |
| | 377 | catalog.getToolByPath({ path, includeSchemas: false }) |
| | 378 | ), |
| 396 | input.runtimeLocalScope, | 379 | input.runtimeLocalScope, |
| 397 | ), | 380 | ), |
| 398 | | 381 | |
| 399 | searchTools: ({ query, namespace, limit }) => | 382 | searchTools: ({ query, namespace, limit }) => |
| 400 | provideRuntimeLocalScope( | 383 | provideRuntimeLocalScope( |
| 401 | Effect.flatMap(createSharedCatalog(false), (catalog) => | 384 | Effect.flatMap(leanSharedCatalog, (catalog) => |
| 402 | catalog.searchTools({ | 385 | catalog.searchTools({ |
| 403 | query, | 386 | query, |
| 404 | ...(namespace !== undefined ? { namespace } : {}), | 387 | ...(namespace !== undefined ? { namespace } : {}), |