@catamorphic/fastify-plugin 0.1.0-alpha.39 → 0.1.0-alpha.42

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (81) hide show
  1. package/NOTICE.txt +7 -0
  2. package/dist/app.d.ts +2 -0
  3. package/dist/app.d.ts.map +1 -1
  4. package/dist/chunk-jytcc42y.js +592 -0
  5. package/dist/chunk-jytcc42y.js.map +11 -0
  6. package/dist/index.d.ts +1 -1
  7. package/dist/index.d.ts.map +1 -1
  8. package/dist/index.js +1673 -411
  9. package/dist/index.js.map +29 -25
  10. package/dist/mcp-scopes.d.ts +12 -0
  11. package/dist/mcp-scopes.d.ts.map +1 -0
  12. package/dist/mcp-server.d.ts +158 -0
  13. package/dist/mcp-server.d.ts.map +1 -0
  14. package/dist/mcp-shared.d.ts +3 -50
  15. package/dist/mcp-shared.d.ts.map +1 -1
  16. package/dist/mcp.d.ts +4 -2
  17. package/dist/mcp.d.ts.map +1 -1
  18. package/dist/mcp.js +6 -4
  19. package/dist/mcp.js.map +1 -1
  20. package/dist/plugin.d.ts +26 -2
  21. package/dist/plugin.d.ts.map +1 -1
  22. package/dist/project-capabilities.d.ts.map +1 -1
  23. package/dist/project-mcp-surface.d.ts +3 -4
  24. package/dist/project-mcp-surface.d.ts.map +1 -1
  25. package/dist/routes/agent.d.ts.map +1 -1
  26. package/dist/routes/apps-mcp.d.ts.map +1 -1
  27. package/dist/routes/client-runners.d.ts.map +1 -1
  28. package/dist/routes/connection-mcp.d.ts.map +1 -1
  29. package/dist/routes/documents.d.ts.map +1 -1
  30. package/dist/routes/environments.d.ts.map +1 -1
  31. package/dist/routes/project-mcp.d.ts.map +1 -1
  32. package/dist/routes/projects.d.ts.map +1 -1
  33. package/dist/routes/publications.d.ts.map +1 -1
  34. package/dist/routes/run-errors.d.ts.map +1 -1
  35. package/dist/routes/runs.d.ts.map +1 -1
  36. package/dist/routes/server-mcp.d.ts +17 -0
  37. package/dist/routes/server-mcp.d.ts.map +1 -0
  38. package/dist/routes/session-mailboxes.d.ts.map +1 -1
  39. package/dist/routes/triggers.d.ts.map +1 -1
  40. package/dist/routes/watchers.d.ts.map +1 -1
  41. package/dist/routes/workflow-enablements.d.ts.map +1 -1
  42. package/dist/routes/workflows.d.ts.map +1 -1
  43. package/dist/schemas.d.ts +3684 -28
  44. package/dist/schemas.d.ts.map +1 -1
  45. package/dist/session-mcp.d.ts +54 -0
  46. package/dist/session-mcp.d.ts.map +1 -0
  47. package/dist/session-tools.d.ts +49 -0
  48. package/dist/session-tools.d.ts.map +1 -0
  49. package/package.json +12 -12
  50. package/src/app.ts +3 -0
  51. package/src/index.ts +1 -0
  52. package/src/mcp-scopes.ts +69 -0
  53. package/src/mcp-server.ts +827 -0
  54. package/src/mcp-shared.ts +3 -151
  55. package/src/mcp.ts +6 -5
  56. package/src/plugin.ts +73 -2
  57. package/src/project-capabilities.ts +5 -3
  58. package/src/project-mcp-program.ts +2 -2
  59. package/src/project-mcp-surface.ts +18 -239
  60. package/src/routes/agent.ts +384 -41
  61. package/src/routes/apps-mcp.ts +84 -82
  62. package/src/routes/client-runners.ts +3 -1
  63. package/src/routes/connection-mcp.ts +6 -13
  64. package/src/routes/documents.ts +4 -0
  65. package/src/routes/environments.ts +49 -1
  66. package/src/routes/project-mcp.ts +176 -154
  67. package/src/routes/projects.ts +6 -0
  68. package/src/routes/publications.ts +2 -0
  69. package/src/routes/run-errors.ts +5 -1
  70. package/src/routes/runs.ts +4 -0
  71. package/src/routes/server-mcp.ts +151 -0
  72. package/src/routes/session-mailboxes.ts +1 -0
  73. package/src/routes/triggers.ts +6 -1
  74. package/src/routes/watchers.ts +1 -0
  75. package/src/routes/workflow-enablements.ts +132 -1
  76. package/src/routes/workflows.ts +4 -0
  77. package/src/schemas.ts +347 -5
  78. package/src/session-mcp.ts +696 -0
  79. package/src/session-tools.ts +169 -0
  80. package/dist/chunk-baagvvm3.js +0 -164
  81. package/dist/chunk-baagvvm3.js.map +0 -10
@@ -12,6 +12,7 @@ import {
12
12
  RunInputInvalidError,
13
13
  TenantActiveRunLimitError,
14
14
  TriggerBindingsInvalidError,
15
+ TriggerKindHostOnlyError,
15
16
  TriggerKindNotRegisteredError,
16
17
  TriggerModeNotAllowedError,
17
18
  TriggerPayloadInvalidError,
@@ -118,6 +119,7 @@ export function registerTriggerRoutes(app: FastifyInstance, ctx: RouteContext) {
118
119
  body: FireTriggerSchema,
119
120
  response: {
120
121
  200: TriggerFireResultSchema,
122
+ 403: ErrorSchema,
121
123
  404: ErrorSchema,
122
124
  409: ErrorSchema,
123
125
  422: ErrorSchema,
@@ -210,7 +212,10 @@ function handleTriggerError(
210
212
  requirements: [...err.requirements],
211
213
  });
212
214
  }
213
- if (err instanceof EnvironmentAccessDeniedError) {
215
+ if (
216
+ err instanceof EnvironmentAccessDeniedError ||
217
+ err instanceof TriggerKindHostOnlyError
218
+ ) {
214
219
  return reply.status(403).send({ error: err.message });
215
220
  }
216
221
  if (err instanceof EnvironmentNotFoundError) {
@@ -56,6 +56,7 @@ export function registerWatcherRoutes(app: FastifyInstance, ctx: RouteContext) {
56
56
  typed.route({
57
57
  method: "DELETE",
58
58
  url: "/projects/:projectId/agent/sessions/:sessionId/watchers/:watcherId",
59
+ config: { tokenScope: "sessions:run" },
59
60
  schema: {
60
61
  params: WatcherIdParamsSchema,
61
62
  response: {
@@ -9,8 +9,10 @@ import {
9
9
  EnvironmentNotFoundError,
10
10
  EnvironmentPolicyInvalidError,
11
11
  ProductionDeploymentNotFoundError,
12
+ PublishedRevisionNotRetryableError,
12
13
  WorkflowEnablementConflictError,
13
14
  WorkflowEnablementConsentRequiredError,
15
+ WorkflowEnablementFollowUnavailableError,
14
16
  WorkflowEnablementNotFoundError,
15
17
  WorkflowEnablementSuspendedError,
16
18
  WorkflowNotFoundError,
@@ -24,6 +26,7 @@ import {
24
26
  AuthenticationRequiredSchema,
25
27
  ErrorSchema,
26
28
  ProjectIdParamsSchema,
29
+ PublishedRevisionSchema,
27
30
  WorkflowEnablementOwnerSchema,
28
31
  WorkflowEnablementPreviewSchema,
29
32
  WorkflowEnablementSchema,
@@ -136,7 +139,14 @@ export function registerWorkflowEnablementRoutes(
136
139
  url: "/projects/:projectId/workflow-enablements",
137
140
  schema: {
138
141
  params: ProjectIdParamsSchema,
139
- body: PreviewBodySchema.extend({ consentDigest: z.string().length(64) }),
142
+ body: PreviewBodySchema.extend({
143
+ consentDigest: z.string().length(64),
144
+ /**
145
+ * Move to each newly published revision (ADR 0330). Defaults to
146
+ * true for an enablement of main.
147
+ */
148
+ follow: z.boolean().optional(),
149
+ }),
140
150
  response: {
141
151
  201: WorkflowEnablementSchema,
142
152
  403: ErrorSchema,
@@ -284,6 +294,126 @@ export function registerWorkflowEnablementRoutes(
284
294
  }
285
295
  },
286
296
  });
297
+
298
+ typed.route({
299
+ method: "POST",
300
+ url: "/projects/:projectId/workflow-enablements/:enablementId/follow",
301
+ schema: {
302
+ params: EnablementParamsSchema,
303
+ body: z.object({ follow: z.boolean() }),
304
+ response: {
305
+ 200: WorkflowEnablementSchema,
306
+ 403: ErrorSchema,
307
+ 404: ErrorSchema,
308
+ 409: PreviewConflictSchema,
309
+ },
310
+ },
311
+ handler: async (request, reply) => {
312
+ const workflowEnablements = service();
313
+ if (!workflowEnablements) {
314
+ return reply
315
+ .status(404)
316
+ .send({ error: "Workflow enablement not found" });
317
+ }
318
+ try {
319
+ const identity = resolveIdentity(request);
320
+ const current = await workflowEnablements.get({
321
+ identity,
322
+ enablementId: request.params.enablementId,
323
+ });
324
+ if (current.projectId !== request.params.projectId) {
325
+ return reply
326
+ .status(404)
327
+ .send({ error: "Workflow enablement not found" });
328
+ }
329
+ return reply.send(
330
+ await workflowEnablements.setFollow({
331
+ identity,
332
+ enablementId: request.params.enablementId,
333
+ follow: request.body.follow,
334
+ }),
335
+ );
336
+ } catch (error) {
337
+ return handleEnablementError(error, reply);
338
+ }
339
+ },
340
+ });
341
+
342
+ typed.route({
343
+ method: "GET",
344
+ url: "/projects/:projectId/published-revisions",
345
+ schema: {
346
+ params: ProjectIdParamsSchema,
347
+ querystring: z.object({
348
+ limit: z.coerce.number().int().min(1).max(100).optional(),
349
+ }),
350
+ response: {
351
+ 200: z.object({ items: z.array(PublishedRevisionSchema) }),
352
+ 403: ErrorSchema,
353
+ 503: ErrorSchema,
354
+ },
355
+ },
356
+ handler: async (request, reply) => {
357
+ const revisions = ctx.core?.publishedRevisions;
358
+ if (!revisions) {
359
+ return reply
360
+ .status(503)
361
+ .send({ error: "Published revisions unavailable" });
362
+ }
363
+ try {
364
+ return reply.send({
365
+ items: await revisions.list({
366
+ identity: resolveIdentity(request),
367
+ projectId: request.params.projectId,
368
+ ...(request.query.limit ? { limit: request.query.limit } : {}),
369
+ }),
370
+ });
371
+ } catch (error) {
372
+ return handleEnablementError(error, reply);
373
+ }
374
+ },
375
+ });
376
+
377
+ registerPublishedRevisionRetryRoute(app, ctx);
378
+ }
379
+
380
+ function registerPublishedRevisionRetryRoute(
381
+ app: FastifyInstance,
382
+ ctx: RouteContext,
383
+ ): void {
384
+ app.withTypeProvider<ZodTypeProvider>().route({
385
+ method: "POST",
386
+ url: "/projects/:projectId/published-revisions/retry",
387
+ schema: {
388
+ params: ProjectIdParamsSchema,
389
+ response: {
390
+ 200: PublishedRevisionSchema,
391
+ 403: ErrorSchema,
392
+ 409: ErrorSchema,
393
+ 503: ErrorSchema,
394
+ },
395
+ },
396
+ handler: async (request, reply) => {
397
+ const revisions = ctx.core?.publishedRevisions;
398
+ if (!revisions) {
399
+ return reply
400
+ .status(503)
401
+ .send({ error: "Published revisions unavailable" });
402
+ }
403
+ try {
404
+ return reply.send(
405
+ await revisions.retry({
406
+ identity: resolveIdentity(request),
407
+ projectId: request.params.projectId,
408
+ }),
409
+ );
410
+ } catch (error) {
411
+ if (error instanceof PublishedRevisionNotRetryableError)
412
+ return reply.status(409).send({ error: error.message });
413
+ return handleEnablementError(error, reply);
414
+ }
415
+ },
416
+ });
287
417
  }
288
418
 
289
419
  export function handleEnablementError(error: unknown, reply: FastifyReply) {
@@ -318,6 +448,7 @@ export function handleEnablementError(error: unknown, reply: FastifyReply) {
318
448
  if (
319
449
  error instanceof WorkflowEnablementConsentRequiredError ||
320
450
  error instanceof WorkflowEnablementConflictError ||
451
+ error instanceof WorkflowEnablementFollowUnavailableError ||
321
452
  error instanceof ConnectionUnavailableError ||
322
453
  error instanceof EnvironmentNotFoundError ||
323
454
  error instanceof EnvironmentPolicyInvalidError ||
@@ -111,6 +111,7 @@ export function registerWorkflowRoutes(
111
111
  typed.route({
112
112
  method: "POST",
113
113
  url: "/projects/:projectId/workflows/:name/runs",
114
+ config: { tokenScope: "sessions:run" },
114
115
  schema: {
115
116
  params: WorkflowNameParamsSchema,
116
117
  body: TriggerRunSchema,
@@ -154,6 +155,7 @@ export function registerWorkflowRoutes(
154
155
  typed.route({
155
156
  method: "POST",
156
157
  url: "/projects/:projectId/workflows/:name/calls",
158
+ config: { tokenScope: "sessions:run" },
157
159
  schema: {
158
160
  params: WorkflowNameParamsSchema,
159
161
  body: CallRunSchema,
@@ -241,6 +243,7 @@ export function registerWorkflowRoutes(
241
243
  typed.route({
242
244
  method: "POST",
243
245
  url: "/projects/:projectId/workflows/:name/signals",
246
+ config: { tokenScope: "sessions:run" },
244
247
  schema: {
245
248
  params: WorkflowNameParamsSchema,
246
249
  body: SignalRunSchema,
@@ -294,6 +297,7 @@ export function registerWorkflowRoutes(
294
297
  typed.route({
295
298
  method: "POST",
296
299
  url: "/projects/:projectId/workflows/:name/cancellations",
300
+ config: { tokenScope: "sessions:run" },
297
301
  schema: {
298
302
  params: WorkflowNameParamsSchema,
299
303
  body: CancelRunByKeySchema,