MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / makeToolkitsExtension

Function makeToolkitsExtension

packages/plugins/toolkits/src/server.ts:276–608  ·  view source on GitHub ↗
(ctx: PluginCtx<ToolkitStorage>)

Source from the content-addressed store, hash-verified

274});
275
276const makeToolkitsExtension = (ctx: PluginCtx<ToolkitStorage>) => {
277 const storage = ctx.storage;
278
279 const list = () =>
280 storage.toolkits
281 .query({ orderBy: [{ field: "name" }] })
282 .pipe(
283 Effect.map((entries) =>
284 entries
285 .map(toolkitToResponse)
286 .sort(
287 (a, b) =>
288 (a.owner === b.owner ? 0 : a.owner === "org" ? -1 : 1) ||
289 a.name.localeCompare(b.name) ||
290 a.slug.localeCompare(b.slug),
291 ),
292 ),
293 );
294
295 const getEntry = (toolkitId: string) => storage.toolkits.get({ key: toolkitId });
296
297 const getBySlugEntry = (slug: string) =>
298 storage.toolkits
299 .query({ where: { slug } })
300 .pipe(
301 Effect.map(
302 (entries) => entries.find((entry) => entry.owner === "org") ?? entries[0] ?? null,
303 ),
304 );
305
306 const requireToolkit = (toolkitId: string) =>
307 getEntry(toolkitId).pipe(
308 Effect.flatMap((entry) => (entry ? Effect.succeed(entry) : fail("Toolkit not found."))),
309 );
310
311 const assertSlugAvailable = (slug: string, ignoreToolkitId?: string) =>
312 storage.toolkits.query({ where: { slug } }).pipe(
313 Effect.flatMap((entries) => {
314 const collision = entries.find((entry) => entry.data.id !== ignoreToolkitId);
315 return collision ? fail(`Toolkit slug "${slug}" is already in use.`) : Effect.void;
316 }),
317 );
318
319 const listPoliciesForRecord = (toolkitId: string) =>
320 storage.policies
321 .query({ where: { toolkitId } })
322 .pipe(Effect.map((entries) => entries.map((entry) => entry.data).sort(comparePositioned)));
323
324 const listConnectionsForRecord = (toolkitId: string) =>
325 storage.connections
326 .query({ where: { toolkitId } })
327 .pipe(Effect.map((entries) => entries.map((entry) => entry.data).sort(comparePositioned)));
328
329 const requirePolicy = (toolkitId: string, policyId: string, owner: Owner) =>
330 storage.policies
331 .getForOwner({ owner, key: policyId })
332 .pipe(
333 Effect.flatMap((entry) =>

Callers 1

server.tsFile · 0.85

Calls 2

listPoliciesFunction · 0.85
listConnectionsFunction · 0.85

Tested by

no test coverage detected