@catamorphic/fastify-plugin 0.0.0-stage → 0.1.0-alpha.31
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.
- package/LICENSE.txt +202 -0
- package/NOTICE.txt +32 -0
- package/README.md +143 -2
- package/dist/app-presentation-tools.d.ts +4 -0
- package/dist/app-presentation-tools.d.ts.map +1 -0
- package/dist/app.d.ts +27 -0
- package/dist/app.d.ts.map +1 -0
- package/dist/chunk-baagvvm3.js +164 -0
- package/dist/chunk-baagvvm3.js.map +10 -0
- package/dist/http-identity.d.ts +52 -0
- package/dist/http-identity.d.ts.map +1 -0
- package/dist/hung-up.d.ts +7 -0
- package/dist/hung-up.d.ts.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +10884 -0
- package/dist/index.js.map +56 -0
- package/dist/mcp-shared.d.ts +117 -0
- package/dist/mcp-shared.d.ts.map +1 -0
- package/dist/mcp.d.ts +6 -0
- package/dist/mcp.d.ts.map +1 -0
- package/dist/mcp.js +13 -0
- package/dist/mcp.js.map +9 -0
- package/dist/plugin.d.ts +113 -0
- package/dist/plugin.d.ts.map +1 -0
- package/dist/project-capabilities.d.ts +25 -0
- package/dist/project-capabilities.d.ts.map +1 -0
- package/dist/project-mcp-program.d.ts +15 -0
- package/dist/project-mcp-program.d.ts.map +1 -0
- package/dist/project-mcp-surface.d.ts +16 -0
- package/dist/project-mcp-surface.d.ts.map +1 -0
- package/dist/request-logging.d.ts +18 -0
- package/dist/request-logging.d.ts.map +1 -0
- package/dist/routes/agent-capabilities.d.ts +4 -0
- package/dist/routes/agent-capabilities.d.ts.map +1 -0
- package/dist/routes/agent.d.ts +4 -0
- package/dist/routes/agent.d.ts.map +1 -0
- package/dist/routes/apps-mcp.d.ts +4 -0
- package/dist/routes/apps-mcp.d.ts.map +1 -0
- package/dist/routes/apps.d.ts +12 -0
- package/dist/routes/apps.d.ts.map +1 -0
- package/dist/routes/client-runners.d.ts +11 -0
- package/dist/routes/client-runners.d.ts.map +1 -0
- package/dist/routes/code-hosts.d.ts +11 -0
- package/dist/routes/code-hosts.d.ts.map +1 -0
- package/dist/routes/connection-mcp.d.ts +10 -0
- package/dist/routes/connection-mcp.d.ts.map +1 -0
- package/dist/routes/connections.d.ts +4 -0
- package/dist/routes/connections.d.ts.map +1 -0
- package/dist/routes/documents.d.ts +11 -0
- package/dist/routes/documents.d.ts.map +1 -0
- package/dist/routes/environments.d.ts +4 -0
- package/dist/routes/environments.d.ts.map +1 -0
- package/dist/routes/git-gateway.d.ts +21 -0
- package/dist/routes/git-gateway.d.ts.map +1 -0
- package/dist/routes/http-gateway.d.ts +13 -0
- package/dist/routes/http-gateway.d.ts.map +1 -0
- package/dist/routes/me.d.ts +12 -0
- package/dist/routes/me.d.ts.map +1 -0
- package/dist/routes/memberships.d.ts +12 -0
- package/dist/routes/memberships.d.ts.map +1 -0
- package/dist/routes/model-gateway.d.ts +12 -0
- package/dist/routes/model-gateway.d.ts.map +1 -0
- package/dist/routes/notifications.d.ts +4 -0
- package/dist/routes/notifications.d.ts.map +1 -0
- package/dist/routes/parse.d.ts +5 -0
- package/dist/routes/parse.d.ts.map +1 -0
- package/dist/routes/personal-environment.d.ts +13 -0
- package/dist/routes/personal-environment.d.ts.map +1 -0
- package/dist/routes/plugins.d.ts +4 -0
- package/dist/routes/plugins.d.ts.map +1 -0
- package/dist/routes/project-mcp.d.ts +25 -0
- package/dist/routes/project-mcp.d.ts.map +1 -0
- package/dist/routes/projects.d.ts +4 -0
- package/dist/routes/projects.d.ts.map +1 -0
- package/dist/routes/publications.d.ts +15 -0
- package/dist/routes/publications.d.ts.map +1 -0
- package/dist/routes/run-errors.d.ts +8 -0
- package/dist/routes/run-errors.d.ts.map +1 -0
- package/dist/routes/runs.d.ts +4 -0
- package/dist/routes/runs.d.ts.map +1 -0
- package/dist/routes/session-artifacts.d.ts +27 -0
- package/dist/routes/session-artifacts.d.ts.map +1 -0
- package/dist/routes/session-mailboxes.d.ts +4 -0
- package/dist/routes/session-mailboxes.d.ts.map +1 -0
- package/dist/routes/session-previews.d.ts +40 -0
- package/dist/routes/session-previews.d.ts.map +1 -0
- package/dist/routes/session-terminals.d.ts +15 -0
- package/dist/routes/session-terminals.d.ts.map +1 -0
- package/dist/routes/triggers.d.ts +20 -0
- package/dist/routes/triggers.d.ts.map +1 -0
- package/dist/routes/watchers.d.ts +4 -0
- package/dist/routes/watchers.d.ts.map +1 -0
- package/dist/routes/webhooks.d.ts +11 -0
- package/dist/routes/webhooks.d.ts.map +1 -0
- package/dist/routes/workflow-enablements.d.ts +4 -0
- package/dist/routes/workflow-enablements.d.ts.map +1 -0
- package/dist/routes/workflows.d.ts +4 -0
- package/dist/routes/workflows.d.ts.map +1 -0
- package/dist/schemas.d.ts +17776 -0
- package/dist/schemas.d.ts.map +1 -0
- package/dist/session-artifact-tools.d.ts +5 -0
- package/dist/session-artifact-tools.d.ts.map +1 -0
- package/dist/session-event-stream.d.ts +45 -0
- package/dist/session-event-stream.d.ts.map +1 -0
- package/dist/spa.d.ts +24 -0
- package/dist/spa.d.ts.map +1 -0
- package/dist/telemetry.d.ts +4 -0
- package/dist/telemetry.d.ts.map +1 -0
- package/package.json +73 -4
- package/src/app-presentation-tools.ts +46 -0
- package/src/app.ts +115 -0
- package/src/http-identity.ts +145 -0
- package/src/hung-up.ts +13 -0
- package/src/index.ts +25 -0
- package/src/mcp-shared.ts +331 -0
- package/src/mcp.ts +10 -0
- package/src/plugin.ts +332 -0
- package/src/project-capabilities.ts +153 -0
- package/src/project-mcp-program.ts +607 -0
- package/src/project-mcp-surface.ts +881 -0
- package/src/request-logging.ts +47 -0
- package/src/routes/agent-capabilities.ts +109 -0
- package/src/routes/agent.ts +1566 -0
- package/src/routes/apps-mcp.ts +303 -0
- package/src/routes/apps.ts +692 -0
- package/src/routes/client-runners.ts +251 -0
- package/src/routes/code-hosts.ts +247 -0
- package/src/routes/connection-mcp.ts +135 -0
- package/src/routes/connections.ts +494 -0
- package/src/routes/documents.ts +538 -0
- package/src/routes/environments.ts +72 -0
- package/src/routes/git-gateway.ts +106 -0
- package/src/routes/http-gateway.ts +141 -0
- package/src/routes/me.ts +122 -0
- package/src/routes/memberships.ts +173 -0
- package/src/routes/model-gateway.ts +134 -0
- package/src/routes/notifications.ts +101 -0
- package/src/routes/parse.ts +32 -0
- package/src/routes/personal-environment.ts +146 -0
- package/src/routes/plugins.ts +341 -0
- package/src/routes/project-mcp.ts +394 -0
- package/src/routes/projects.ts +708 -0
- package/src/routes/publications.ts +222 -0
- package/src/routes/run-errors.ts +86 -0
- package/src/routes/runs.ts +253 -0
- package/src/routes/session-artifacts.ts +293 -0
- package/src/routes/session-mailboxes.ts +80 -0
- package/src/routes/session-previews.ts +224 -0
- package/src/routes/session-terminals.ts +209 -0
- package/src/routes/triggers.ts +241 -0
- package/src/routes/watchers.ts +94 -0
- package/src/routes/webhooks.ts +171 -0
- package/src/routes/workflow-enablements.ts +331 -0
- package/src/routes/workflows.ts +323 -0
- package/src/schemas.ts +2735 -0
- package/src/session-artifact-tools.ts +170 -0
- package/src/session-event-stream.ts +122 -0
- package/src/spa.ts +135 -0
- package/src/telemetry.ts +93 -0
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { FastifyReply, FastifyRequest } from "fastify";
|
|
2
|
+
|
|
3
|
+
/** URLs can carry OAuth codes, bearer state and webhook tokens. */
|
|
4
|
+
export function requestLogFields(request: FastifyRequest) {
|
|
5
|
+
return {
|
|
6
|
+
method: request.method,
|
|
7
|
+
route: request.routeOptions?.url ?? "[unmatched]",
|
|
8
|
+
remoteAddress: request.ip,
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/** Provider and database exception messages can repeat credential material. */
|
|
13
|
+
export function errorLogFields(_error: unknown) {
|
|
14
|
+
return { type: "Error", message: "Request failed", stack: "" };
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** Sending an Error invokes Fastify's raw-message logger; send safe data. */
|
|
18
|
+
export function apiErrorResponse(
|
|
19
|
+
error: unknown,
|
|
20
|
+
request: FastifyRequest,
|
|
21
|
+
reply: FastifyReply,
|
|
22
|
+
) {
|
|
23
|
+
const status =
|
|
24
|
+
error instanceof Error &&
|
|
25
|
+
"statusCode" in error &&
|
|
26
|
+
typeof error.statusCode === "number" &&
|
|
27
|
+
Number.isInteger(error.statusCode) &&
|
|
28
|
+
error.statusCode >= 400 &&
|
|
29
|
+
error.statusCode <= 599
|
|
30
|
+
? error.statusCode
|
|
31
|
+
: 500;
|
|
32
|
+
request.log.error(
|
|
33
|
+
{ errorType: errorLogFields(error).type },
|
|
34
|
+
"API request failed",
|
|
35
|
+
);
|
|
36
|
+
return reply.status(status).send({
|
|
37
|
+
error: status >= 500 ? "Internal server error" : "Invalid request",
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** Fastify's default 404 logs the credential-bearing raw URL as its message. */
|
|
42
|
+
export function apiNotFoundResponse(
|
|
43
|
+
_request: FastifyRequest,
|
|
44
|
+
reply: FastifyReply,
|
|
45
|
+
) {
|
|
46
|
+
return reply.status(404).send({ error: "Not found" });
|
|
47
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { AccessDeniedError } from "@catamorphic/core";
|
|
2
|
+
import {
|
|
3
|
+
CapabilityPageSchema,
|
|
4
|
+
DiscoverCapabilitiesSchema,
|
|
5
|
+
InvokeCapabilitySchema,
|
|
6
|
+
} from "@catamorphic/sandbox";
|
|
7
|
+
import type { FastifyInstance } from "fastify";
|
|
8
|
+
import type { ZodTypeProvider } from "fastify-type-provider-zod";
|
|
9
|
+
import { z } from "zod";
|
|
10
|
+
import type { RouteContext } from "../app.js";
|
|
11
|
+
import { resolveIdentity } from "../http-identity.js";
|
|
12
|
+
import { ErrorSchema } from "../schemas.js";
|
|
13
|
+
|
|
14
|
+
export function registerAgentCapabilityRoutes(
|
|
15
|
+
app: FastifyInstance,
|
|
16
|
+
ctx: RouteContext,
|
|
17
|
+
): void {
|
|
18
|
+
const typed = app.withTypeProvider<ZodTypeProvider>();
|
|
19
|
+
const base = "/projects/:projectId/agent/sessions/:sessionId/capabilities";
|
|
20
|
+
const params = z.object({
|
|
21
|
+
projectId: z.string().uuid(),
|
|
22
|
+
sessionId: z.string().uuid(),
|
|
23
|
+
});
|
|
24
|
+
const headers = z.object({
|
|
25
|
+
"x-catamorphic-allocation-id": z.string().uuid().optional(),
|
|
26
|
+
});
|
|
27
|
+
const failures = { 403: ErrorSchema, 409: ErrorSchema, 503: ErrorSchema };
|
|
28
|
+
const gateway = (
|
|
29
|
+
identity: ReturnType<typeof resolveIdentity>,
|
|
30
|
+
input: z.output<typeof params>,
|
|
31
|
+
allocation: unknown,
|
|
32
|
+
) => {
|
|
33
|
+
if (!ctx.core)
|
|
34
|
+
throw Object.assign(new Error("Capabilities are not configured"), {
|
|
35
|
+
statusCode: 503,
|
|
36
|
+
});
|
|
37
|
+
return ctx.core.agentCapabilities.forSession({
|
|
38
|
+
identity,
|
|
39
|
+
...input,
|
|
40
|
+
allocationId: z.string().uuid().optional().parse(allocation),
|
|
41
|
+
});
|
|
42
|
+
};
|
|
43
|
+
typed.post(
|
|
44
|
+
`${base}/discover`,
|
|
45
|
+
{
|
|
46
|
+
schema: {
|
|
47
|
+
params,
|
|
48
|
+
headers,
|
|
49
|
+
body: DiscoverCapabilitiesSchema,
|
|
50
|
+
response: { 200: CapabilityPageSchema, ...failures },
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
(request) =>
|
|
54
|
+
run(() =>
|
|
55
|
+
gateway(
|
|
56
|
+
resolveIdentity(request),
|
|
57
|
+
request.params,
|
|
58
|
+
request.headers["x-catamorphic-allocation-id"],
|
|
59
|
+
).discover(request.body),
|
|
60
|
+
),
|
|
61
|
+
);
|
|
62
|
+
typed.post(
|
|
63
|
+
`${base}/invoke`,
|
|
64
|
+
{
|
|
65
|
+
bodyLimit: 6 * 1024 * 1024,
|
|
66
|
+
schema: {
|
|
67
|
+
params,
|
|
68
|
+
headers,
|
|
69
|
+
body: InvokeCapabilitySchema,
|
|
70
|
+
response: { 200: z.object({ value: z.unknown() }), ...failures },
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
(request, reply) =>
|
|
74
|
+
run(async () => {
|
|
75
|
+
const abort = new AbortController();
|
|
76
|
+
const cancel = () => abort.abort();
|
|
77
|
+
reply.raw.once("close", cancel);
|
|
78
|
+
try {
|
|
79
|
+
return {
|
|
80
|
+
value: z.json().parse(
|
|
81
|
+
await gateway(
|
|
82
|
+
resolveIdentity(request),
|
|
83
|
+
request.params,
|
|
84
|
+
request.headers["x-catamorphic-allocation-id"],
|
|
85
|
+
).invoke({
|
|
86
|
+
...request.body,
|
|
87
|
+
signal: abort.signal,
|
|
88
|
+
}),
|
|
89
|
+
),
|
|
90
|
+
};
|
|
91
|
+
} finally {
|
|
92
|
+
reply.raw.removeListener("close", cancel);
|
|
93
|
+
}
|
|
94
|
+
}),
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
async function run<T>(operation: () => Promise<T>): Promise<T> {
|
|
98
|
+
try {
|
|
99
|
+
return await operation();
|
|
100
|
+
} catch (error) {
|
|
101
|
+
if (error instanceof AccessDeniedError)
|
|
102
|
+
throw Object.assign(error, { statusCode: 403 });
|
|
103
|
+
if (error instanceof Error && "statusCode" in error) throw error;
|
|
104
|
+
throw Object.assign(
|
|
105
|
+
error instanceof Error ? error : new Error("Capability failed"),
|
|
106
|
+
{ statusCode: 409 },
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
}
|