@catamorphic/fastify-plugin 0.0.0-stage → 0.1.0-alpha.30
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,146 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AccessDeniedError,
|
|
3
|
+
PersonalEnvironmentInvalidError,
|
|
4
|
+
PersonalEnvironmentUnavailableError,
|
|
5
|
+
ProjectNotFoundError,
|
|
6
|
+
} from "@catamorphic/core";
|
|
7
|
+
import type { FastifyInstance, FastifyReply } 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 {
|
|
13
|
+
ErrorSchema,
|
|
14
|
+
PersonalEnvironmentInvalidSchema,
|
|
15
|
+
PersonalEnvironmentSchema,
|
|
16
|
+
ProjectIdParamsSchema,
|
|
17
|
+
PutPersonalEnvironmentSchema,
|
|
18
|
+
} from "../schemas.js";
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* The caller's own personal environment for a project (ADR 0184): their
|
|
22
|
+
* listed files, which reach only their own chats' sandboxes in
|
|
23
|
+
* Environments that allow personal credentials, and their own setup
|
|
24
|
+
* command, which runs there after the Environment's (ADR 0208). Sign-ins
|
|
25
|
+
* are not part of it: they stay on the machine they were made on (ADR
|
|
26
|
+
* 0199). Every route acts on the caller's own set; none returns a file's
|
|
27
|
+
* value.
|
|
28
|
+
*/
|
|
29
|
+
export function registerPersonalEnvironmentRoutes(
|
|
30
|
+
app: FastifyInstance,
|
|
31
|
+
ctx: RouteContext,
|
|
32
|
+
): void {
|
|
33
|
+
const typed = app.withTypeProvider<ZodTypeProvider>();
|
|
34
|
+
const refuse = (reply: FastifyReply, error: unknown) => {
|
|
35
|
+
if (error instanceof ProjectNotFoundError)
|
|
36
|
+
return reply.status(404).send({ error: "Project not found" });
|
|
37
|
+
if (error instanceof AccessDeniedError)
|
|
38
|
+
return reply.status(403).send({ error: error.message });
|
|
39
|
+
if (error instanceof PersonalEnvironmentUnavailableError)
|
|
40
|
+
return reply.status(503).send({ error: error.message });
|
|
41
|
+
throw error;
|
|
42
|
+
};
|
|
43
|
+
// 50 files of up to 256 KiB each, as base64.
|
|
44
|
+
const bodyLimit = 24 * 1024 * 1024;
|
|
45
|
+
|
|
46
|
+
typed.route({
|
|
47
|
+
method: "PUT",
|
|
48
|
+
url: "/projects/:projectId/personal-environment",
|
|
49
|
+
bodyLimit,
|
|
50
|
+
schema: {
|
|
51
|
+
params: ProjectIdParamsSchema,
|
|
52
|
+
body: PutPersonalEnvironmentSchema,
|
|
53
|
+
response: {
|
|
54
|
+
200: PersonalEnvironmentSchema,
|
|
55
|
+
403: ErrorSchema,
|
|
56
|
+
404: ErrorSchema,
|
|
57
|
+
422: PersonalEnvironmentInvalidSchema,
|
|
58
|
+
503: ErrorSchema,
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
handler: async (request, reply) => {
|
|
62
|
+
const service = ctx.core?.personalEnvironments;
|
|
63
|
+
if (!service)
|
|
64
|
+
return reply
|
|
65
|
+
.status(503)
|
|
66
|
+
.send({ error: "Personal environments are not configured" });
|
|
67
|
+
try {
|
|
68
|
+
const status = await service.replace({
|
|
69
|
+
identity: resolveIdentity(request),
|
|
70
|
+
projectId: request.params.projectId,
|
|
71
|
+
input: request.body,
|
|
72
|
+
});
|
|
73
|
+
return reply.send(status);
|
|
74
|
+
} catch (error) {
|
|
75
|
+
if (error instanceof PersonalEnvironmentInvalidError)
|
|
76
|
+
return reply.status(422).send({
|
|
77
|
+
error: error.message,
|
|
78
|
+
code: "personal_environment_invalid",
|
|
79
|
+
issues: [...error.issues],
|
|
80
|
+
});
|
|
81
|
+
return refuse(reply, error);
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
typed.route({
|
|
87
|
+
method: "GET",
|
|
88
|
+
url: "/projects/:projectId/personal-environment",
|
|
89
|
+
schema: {
|
|
90
|
+
params: ProjectIdParamsSchema,
|
|
91
|
+
response: {
|
|
92
|
+
200: PersonalEnvironmentSchema,
|
|
93
|
+
403: ErrorSchema,
|
|
94
|
+
404: ErrorSchema,
|
|
95
|
+
503: ErrorSchema,
|
|
96
|
+
},
|
|
97
|
+
},
|
|
98
|
+
handler: async (request, reply) => {
|
|
99
|
+
const service = ctx.core?.personalEnvironments;
|
|
100
|
+
if (!service)
|
|
101
|
+
return reply
|
|
102
|
+
.status(503)
|
|
103
|
+
.send({ error: "Personal environments are not configured" });
|
|
104
|
+
try {
|
|
105
|
+
return reply.send(
|
|
106
|
+
await service.status({
|
|
107
|
+
identity: resolveIdentity(request),
|
|
108
|
+
projectId: request.params.projectId,
|
|
109
|
+
}),
|
|
110
|
+
);
|
|
111
|
+
} catch (error) {
|
|
112
|
+
return refuse(reply, error);
|
|
113
|
+
}
|
|
114
|
+
},
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
typed.route({
|
|
118
|
+
method: "DELETE",
|
|
119
|
+
url: "/projects/:projectId/personal-environment",
|
|
120
|
+
schema: {
|
|
121
|
+
params: ProjectIdParamsSchema,
|
|
122
|
+
response: {
|
|
123
|
+
204: z.null(),
|
|
124
|
+
403: ErrorSchema,
|
|
125
|
+
404: ErrorSchema,
|
|
126
|
+
503: ErrorSchema,
|
|
127
|
+
},
|
|
128
|
+
},
|
|
129
|
+
handler: async (request, reply) => {
|
|
130
|
+
const service = ctx.core?.personalEnvironments;
|
|
131
|
+
if (!service)
|
|
132
|
+
return reply
|
|
133
|
+
.status(503)
|
|
134
|
+
.send({ error: "Personal environments are not configured" });
|
|
135
|
+
try {
|
|
136
|
+
await service.remove({
|
|
137
|
+
identity: resolveIdentity(request),
|
|
138
|
+
projectId: request.params.projectId,
|
|
139
|
+
});
|
|
140
|
+
return reply.status(204).send(null);
|
|
141
|
+
} catch (error) {
|
|
142
|
+
return refuse(reply, error);
|
|
143
|
+
}
|
|
144
|
+
},
|
|
145
|
+
});
|
|
146
|
+
}
|
|
@@ -0,0 +1,341 @@
|
|
|
1
|
+
import {
|
|
2
|
+
assertProjectPermission,
|
|
3
|
+
PluginNotAttachedError,
|
|
4
|
+
SecretDeclarationConflictError,
|
|
5
|
+
SecretMemberNotFoundError,
|
|
6
|
+
SecretsUnavailableError,
|
|
7
|
+
SecretValueInvalidError,
|
|
8
|
+
UndeclaredSecretError,
|
|
9
|
+
UnfulfilledCapabilityError,
|
|
10
|
+
} from "@catamorphic/core";
|
|
11
|
+
import { PluginResolutionError } from "@catamorphic/plugins";
|
|
12
|
+
import type { FastifyInstance, FastifyRequest } from "fastify";
|
|
13
|
+
import type { ZodTypeProvider } from "fastify-type-provider-zod";
|
|
14
|
+
import { z } from "zod";
|
|
15
|
+
import type { RouteContext } from "../app.js";
|
|
16
|
+
import { resolveIdentity } from "../http-identity.js";
|
|
17
|
+
import {
|
|
18
|
+
AttachedPluginSchema,
|
|
19
|
+
AttachPluginSchema,
|
|
20
|
+
CatalogPluginSchema,
|
|
21
|
+
ErrorSchema,
|
|
22
|
+
PluginPackageParamsSchema,
|
|
23
|
+
ProjectIdParamsSchema,
|
|
24
|
+
SecretMemberParamsSchema,
|
|
25
|
+
SecretNameParamsSchema,
|
|
26
|
+
SecretStatusSchema,
|
|
27
|
+
SecretValueChangeSchema,
|
|
28
|
+
UpsertSecretSchema,
|
|
29
|
+
} from "../schemas.js";
|
|
30
|
+
|
|
31
|
+
/** A refused secret write or an unavailable vault, never an internal fault. */
|
|
32
|
+
function secretWriteError(
|
|
33
|
+
error: unknown,
|
|
34
|
+
): { status: 400 | 404 | 503; message: string } | undefined {
|
|
35
|
+
if (error instanceof SecretsUnavailableError)
|
|
36
|
+
return { status: 503, message: error.message };
|
|
37
|
+
if (error instanceof SecretMemberNotFoundError)
|
|
38
|
+
return { status: 404, message: error.message };
|
|
39
|
+
if (
|
|
40
|
+
error instanceof UndeclaredSecretError ||
|
|
41
|
+
error instanceof SecretDeclarationConflictError ||
|
|
42
|
+
error instanceof SecretValueInvalidError ||
|
|
43
|
+
error instanceof PluginNotAttachedError
|
|
44
|
+
)
|
|
45
|
+
return { status: 400, message: error.message };
|
|
46
|
+
return undefined;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function registerPluginRoutes(app: FastifyInstance, ctx: RouteContext) {
|
|
50
|
+
const typed = app.withTypeProvider<ZodTypeProvider>();
|
|
51
|
+
|
|
52
|
+
async function requirePublish(request: FastifyRequest, projectId: string) {
|
|
53
|
+
const identity = resolveIdentity(request);
|
|
54
|
+
await ctx.core?.projects.get(identity, projectId);
|
|
55
|
+
assertProjectPermission(identity, projectId, "program:publish");
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
typed.route({
|
|
59
|
+
method: "GET",
|
|
60
|
+
url: "/plugins/catalog",
|
|
61
|
+
schema: {
|
|
62
|
+
response: {
|
|
63
|
+
200: z.array(CatalogPluginSchema),
|
|
64
|
+
503: ErrorSchema,
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
handler: async (_request, reply) => {
|
|
68
|
+
if (!ctx.core?.plugins)
|
|
69
|
+
return reply.status(503).send({ error: "Plugins not configured" });
|
|
70
|
+
const catalog = await ctx.core.plugins.listCatalog();
|
|
71
|
+
return reply.send(catalog);
|
|
72
|
+
},
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
typed.route({
|
|
76
|
+
method: "GET",
|
|
77
|
+
url: "/projects/:projectId/plugins",
|
|
78
|
+
schema: {
|
|
79
|
+
params: ProjectIdParamsSchema,
|
|
80
|
+
response: {
|
|
81
|
+
200: z.array(AttachedPluginSchema),
|
|
82
|
+
503: ErrorSchema,
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
handler: async (request, reply) => {
|
|
86
|
+
if (!ctx.core?.plugins)
|
|
87
|
+
return reply.status(503).send({ error: "Plugins not configured" });
|
|
88
|
+
// Reading the project's plugins is reading its program.
|
|
89
|
+
await ctx.core.projects.get(
|
|
90
|
+
resolveIdentity(request),
|
|
91
|
+
request.params.projectId,
|
|
92
|
+
);
|
|
93
|
+
const attached = await ctx.core.plugins.listAttached(
|
|
94
|
+
request.params.projectId,
|
|
95
|
+
);
|
|
96
|
+
return reply.send(attached);
|
|
97
|
+
},
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
typed.route({
|
|
101
|
+
method: "POST",
|
|
102
|
+
url: "/projects/:projectId/plugins",
|
|
103
|
+
schema: {
|
|
104
|
+
params: ProjectIdParamsSchema,
|
|
105
|
+
body: AttachPluginSchema,
|
|
106
|
+
response: {
|
|
107
|
+
201: AttachedPluginSchema,
|
|
108
|
+
400: ErrorSchema,
|
|
109
|
+
404: ErrorSchema,
|
|
110
|
+
503: ErrorSchema,
|
|
111
|
+
},
|
|
112
|
+
},
|
|
113
|
+
handler: async (request, reply) => {
|
|
114
|
+
if (!ctx.core?.plugins)
|
|
115
|
+
return reply.status(503).send({ error: "Plugins not configured" });
|
|
116
|
+
// Attached plugins reach live runs at once: publishing the program.
|
|
117
|
+
await requirePublish(request, request.params.projectId);
|
|
118
|
+
try {
|
|
119
|
+
const attached = await ctx.core.plugins.attach(
|
|
120
|
+
request.params.projectId,
|
|
121
|
+
request.body.packageName,
|
|
122
|
+
);
|
|
123
|
+
return reply.status(201).send(attached);
|
|
124
|
+
} catch (err) {
|
|
125
|
+
if (err instanceof PluginResolutionError) {
|
|
126
|
+
return reply.status(404).send({ error: err.message });
|
|
127
|
+
}
|
|
128
|
+
// Fail-closed attach (ADR 0046): a required capability with no
|
|
129
|
+
// registered provider is a host configuration problem, not a 500.
|
|
130
|
+
if (err instanceof UnfulfilledCapabilityError) {
|
|
131
|
+
return reply.status(400).send({ error: err.message });
|
|
132
|
+
}
|
|
133
|
+
throw err;
|
|
134
|
+
}
|
|
135
|
+
},
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
typed.route({
|
|
139
|
+
method: "DELETE",
|
|
140
|
+
url: "/projects/:projectId/plugins/:packageName",
|
|
141
|
+
schema: {
|
|
142
|
+
params: PluginPackageParamsSchema,
|
|
143
|
+
response: {
|
|
144
|
+
200: z.object({ detached: z.boolean() }),
|
|
145
|
+
404: ErrorSchema,
|
|
146
|
+
503: ErrorSchema,
|
|
147
|
+
},
|
|
148
|
+
},
|
|
149
|
+
handler: async (request, reply) => {
|
|
150
|
+
if (!ctx.core?.plugins)
|
|
151
|
+
return reply.status(503).send({ error: "Plugins not configured" });
|
|
152
|
+
await requirePublish(request, request.params.projectId);
|
|
153
|
+
const ok = await ctx.core.plugins.detach(
|
|
154
|
+
request.params.projectId,
|
|
155
|
+
decodeURIComponent(request.params.packageName),
|
|
156
|
+
);
|
|
157
|
+
if (!ok) {
|
|
158
|
+
return reply
|
|
159
|
+
.status(404)
|
|
160
|
+
.send({ error: "Plugin not attached to project" });
|
|
161
|
+
}
|
|
162
|
+
return reply.send({ detached: true });
|
|
163
|
+
},
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
typed.route({
|
|
167
|
+
method: "GET",
|
|
168
|
+
url: "/projects/:projectId/secrets",
|
|
169
|
+
schema: {
|
|
170
|
+
params: ProjectIdParamsSchema,
|
|
171
|
+
response: {
|
|
172
|
+
200: z.array(SecretStatusSchema),
|
|
173
|
+
503: ErrorSchema,
|
|
174
|
+
},
|
|
175
|
+
},
|
|
176
|
+
handler: async (request, reply) => {
|
|
177
|
+
if (!ctx.core?.secrets)
|
|
178
|
+
return reply.status(503).send({ error: "Secrets not configured" });
|
|
179
|
+
const list = await ctx.core.secrets.list({
|
|
180
|
+
identity: resolveIdentity(request),
|
|
181
|
+
projectId: request.params.projectId,
|
|
182
|
+
});
|
|
183
|
+
return reply.send(list);
|
|
184
|
+
},
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
typed.route({
|
|
188
|
+
method: "PUT",
|
|
189
|
+
url: "/projects/:projectId/secrets/:name",
|
|
190
|
+
schema: {
|
|
191
|
+
params: SecretNameParamsSchema,
|
|
192
|
+
body: UpsertSecretSchema,
|
|
193
|
+
response: {
|
|
194
|
+
200: SecretStatusSchema,
|
|
195
|
+
400: ErrorSchema,
|
|
196
|
+
503: ErrorSchema,
|
|
197
|
+
},
|
|
198
|
+
},
|
|
199
|
+
handler: async (request, reply) => {
|
|
200
|
+
if (!ctx.core?.secrets)
|
|
201
|
+
return reply.status(503).send({ error: "Secrets not configured" });
|
|
202
|
+
try {
|
|
203
|
+
const status = await ctx.core.secrets.upsert({
|
|
204
|
+
identity: resolveIdentity(request),
|
|
205
|
+
projectId: request.params.projectId,
|
|
206
|
+
name: request.params.name,
|
|
207
|
+
value: request.body.value,
|
|
208
|
+
});
|
|
209
|
+
return reply.send(status);
|
|
210
|
+
} catch (err) {
|
|
211
|
+
const refused = secretWriteError(err);
|
|
212
|
+
if (refused?.status === 503)
|
|
213
|
+
return reply.status(503).send({ error: refused.message });
|
|
214
|
+
if (refused?.status === 400)
|
|
215
|
+
return reply.status(400).send({ error: refused.message });
|
|
216
|
+
throw err;
|
|
217
|
+
}
|
|
218
|
+
},
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
// A member's own value (ADR 0206): set by the member (`me`) or by anyone
|
|
222
|
+
// holding `secrets:write`.
|
|
223
|
+
typed.route({
|
|
224
|
+
method: "PUT",
|
|
225
|
+
url: "/projects/:projectId/secrets/:name/members/:member",
|
|
226
|
+
schema: {
|
|
227
|
+
params: SecretMemberParamsSchema,
|
|
228
|
+
body: UpsertSecretSchema,
|
|
229
|
+
response: {
|
|
230
|
+
200: SecretValueChangeSchema,
|
|
231
|
+
400: ErrorSchema,
|
|
232
|
+
404: ErrorSchema,
|
|
233
|
+
503: ErrorSchema,
|
|
234
|
+
},
|
|
235
|
+
},
|
|
236
|
+
handler: async (request, reply) => {
|
|
237
|
+
if (!ctx.core?.secrets)
|
|
238
|
+
return reply.status(503).send({ error: "Secrets not configured" });
|
|
239
|
+
const identity = resolveIdentity(request);
|
|
240
|
+
try {
|
|
241
|
+
const change = await ctx.core.secrets.setMember({
|
|
242
|
+
identity,
|
|
243
|
+
projectId: request.params.projectId,
|
|
244
|
+
name: request.params.name,
|
|
245
|
+
member:
|
|
246
|
+
request.params.member === "me"
|
|
247
|
+
? identity.externalUserId
|
|
248
|
+
: request.params.member,
|
|
249
|
+
value: request.body.value,
|
|
250
|
+
});
|
|
251
|
+
return reply.send(change);
|
|
252
|
+
} catch (err) {
|
|
253
|
+
const refused = secretWriteError(err);
|
|
254
|
+
if (refused?.status === 503)
|
|
255
|
+
return reply.status(503).send({ error: refused.message });
|
|
256
|
+
if (refused?.status === 400)
|
|
257
|
+
return reply.status(400).send({ error: refused.message });
|
|
258
|
+
if (refused?.status === 404)
|
|
259
|
+
return reply.status(404).send({ error: refused.message });
|
|
260
|
+
throw err;
|
|
261
|
+
}
|
|
262
|
+
},
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
typed.route({
|
|
266
|
+
method: "DELETE",
|
|
267
|
+
url: "/projects/:projectId/secrets/:name/members/:member",
|
|
268
|
+
schema: {
|
|
269
|
+
params: SecretMemberParamsSchema,
|
|
270
|
+
response: {
|
|
271
|
+
200: z.object({ deleted: z.boolean() }),
|
|
272
|
+
400: ErrorSchema,
|
|
273
|
+
503: ErrorSchema,
|
|
274
|
+
},
|
|
275
|
+
},
|
|
276
|
+
handler: async (request, reply) => {
|
|
277
|
+
if (!ctx.core?.secrets)
|
|
278
|
+
return reply.status(503).send({ error: "Secrets not configured" });
|
|
279
|
+
const identity = resolveIdentity(request);
|
|
280
|
+
try {
|
|
281
|
+
const deleted = await ctx.core.secrets.deleteMember({
|
|
282
|
+
identity,
|
|
283
|
+
projectId: request.params.projectId,
|
|
284
|
+
name: request.params.name,
|
|
285
|
+
member:
|
|
286
|
+
request.params.member === "me"
|
|
287
|
+
? identity.externalUserId
|
|
288
|
+
: request.params.member,
|
|
289
|
+
});
|
|
290
|
+
return reply.send({ deleted });
|
|
291
|
+
} catch (err) {
|
|
292
|
+
const refused = secretWriteError(err);
|
|
293
|
+
if (refused?.status === 400)
|
|
294
|
+
return reply.status(400).send({ error: refused.message });
|
|
295
|
+
throw err;
|
|
296
|
+
}
|
|
297
|
+
},
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
typed.route({
|
|
301
|
+
method: "GET",
|
|
302
|
+
url: "/projects/:projectId/agent-context",
|
|
303
|
+
schema: {
|
|
304
|
+
params: ProjectIdParamsSchema,
|
|
305
|
+
response: {
|
|
306
|
+
200: z.object({ systemPromptSuffix: z.string() }),
|
|
307
|
+
503: ErrorSchema,
|
|
308
|
+
},
|
|
309
|
+
},
|
|
310
|
+
handler: async (request, reply) => {
|
|
311
|
+
if (!ctx.core?.agentContext)
|
|
312
|
+
return reply.status(503).send({ error: "Plugins not configured" });
|
|
313
|
+
const systemPromptSuffix = await ctx.core.agentContext.buildPrompt(
|
|
314
|
+
request.params.projectId,
|
|
315
|
+
);
|
|
316
|
+
return reply.send({ systemPromptSuffix });
|
|
317
|
+
},
|
|
318
|
+
});
|
|
319
|
+
|
|
320
|
+
typed.route({
|
|
321
|
+
method: "DELETE",
|
|
322
|
+
url: "/projects/:projectId/secrets/:name",
|
|
323
|
+
schema: {
|
|
324
|
+
params: SecretNameParamsSchema,
|
|
325
|
+
response: {
|
|
326
|
+
200: z.object({ deleted: z.boolean() }),
|
|
327
|
+
503: ErrorSchema,
|
|
328
|
+
},
|
|
329
|
+
},
|
|
330
|
+
handler: async (request, reply) => {
|
|
331
|
+
if (!ctx.core?.secrets)
|
|
332
|
+
return reply.status(503).send({ error: "Secrets not configured" });
|
|
333
|
+
const ok = await ctx.core.secrets.delete({
|
|
334
|
+
identity: resolveIdentity(request),
|
|
335
|
+
projectId: request.params.projectId,
|
|
336
|
+
name: request.params.name,
|
|
337
|
+
});
|
|
338
|
+
return reply.send({ deleted: ok });
|
|
339
|
+
},
|
|
340
|
+
});
|
|
341
|
+
}
|