@catamorphic/fastify-plugin 0.1.0-alpha.37 → 0.1.0-alpha.39
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/dist/index.js +1047 -828
- package/dist/index.js.map +8 -7
- package/dist/plugin.d.ts.map +1 -1
- package/dist/routes/private-customizations.d.ts +4 -0
- package/dist/routes/private-customizations.d.ts.map +1 -0
- package/dist/routes/session-artifacts.d.ts +5 -0
- package/dist/routes/session-artifacts.d.ts.map +1 -1
- package/dist/routes/workflow-enablements.d.ts +2 -1
- package/dist/routes/workflow-enablements.d.ts.map +1 -1
- package/dist/schemas.d.ts +39 -0
- package/dist/schemas.d.ts.map +1 -1
- package/package.json +22 -20
- package/src/plugin.ts +2 -0
- package/src/routes/private-customizations.ts +287 -0
- package/src/routes/session-artifacts.ts +2 -0
- package/src/routes/workflow-enablements.ts +1 -1
- package/src/schemas.ts +12 -2
package/dist/index.js
CHANGED
|
@@ -1032,7 +1032,7 @@ var SandboxSchema = z.object({
|
|
|
1032
1032
|
provider: z.string(),
|
|
1033
1033
|
providerId: z.string(),
|
|
1034
1034
|
sandboxType: z.enum(["execution", "dev"]),
|
|
1035
|
-
commitSha: z.string().
|
|
1035
|
+
commitSha: z.string().nullable(),
|
|
1036
1036
|
userId: z.string().uuid().nullable(),
|
|
1037
1037
|
status: z.string(),
|
|
1038
1038
|
snapshotName: z.string().nullable(),
|
|
@@ -1069,7 +1069,8 @@ var AgentSessionSourceSchema = z.enum([
|
|
|
1069
1069
|
var AgentSessionsQuerySchema = PaginationQuerySchema.extend({
|
|
1070
1070
|
visibility: z.enum(["promoted", "latent", "archived"]).optional(),
|
|
1071
1071
|
parentSessionId: z.string().uuid().optional(),
|
|
1072
|
-
rootsOnly: z.enum(["true", "false"]).transform((value) => value === "true").optional()
|
|
1072
|
+
rootsOnly: z.enum(["true", "false"]).transform((value) => value === "true").optional(),
|
|
1073
|
+
query: z.string().max(500).optional()
|
|
1073
1074
|
}).refine((value) => !(value.rootsOnly && value.parentSessionId), {
|
|
1074
1075
|
message: "Choose rootsOnly or parentSessionId, not both."
|
|
1075
1076
|
});
|
|
@@ -1151,6 +1152,7 @@ var AgentSessionSchema = z.object({
|
|
|
1151
1152
|
attentionSeenRevision: z.number().int().nonnegative(),
|
|
1152
1153
|
attentionRequired: z.boolean(),
|
|
1153
1154
|
attentionMessage: z.object({ id: z.string().uuid(), content: z.string() }).optional(),
|
|
1155
|
+
match: z.string().optional(),
|
|
1154
1156
|
key: z.string().nullable(),
|
|
1155
1157
|
keyWorkflows: z.array(z.string()),
|
|
1156
1158
|
placement: AgentSessionPlacementSchema.nullable(),
|
|
@@ -1273,7 +1275,13 @@ var NativeRefSchema = describes()(z.object({
|
|
|
1273
1275
|
}));
|
|
1274
1276
|
var TurnErrorSchema = describes()(z.object({
|
|
1275
1277
|
message: z.string(),
|
|
1276
|
-
kind: z.enum([
|
|
1278
|
+
kind: z.enum([
|
|
1279
|
+
"auth",
|
|
1280
|
+
"rate_limit",
|
|
1281
|
+
"unavailable",
|
|
1282
|
+
"model_incompat",
|
|
1283
|
+
"agent_missing"
|
|
1284
|
+
]).optional(),
|
|
1277
1285
|
retrySafe: z.boolean().optional()
|
|
1278
1286
|
}));
|
|
1279
1287
|
var ProviderRetrySchema = z.object({
|
|
@@ -6739,213 +6747,958 @@ function registerPluginRoutes(app, ctx) {
|
|
|
6739
6747
|
});
|
|
6740
6748
|
}
|
|
6741
6749
|
|
|
6742
|
-
// src/routes/
|
|
6743
|
-
import { agentCapabilityTools } from "@catamorphic/sandbox";
|
|
6744
|
-
import { z as z17 } from "zod";
|
|
6745
|
-
|
|
6746
|
-
// src/project-mcp-program.ts
|
|
6750
|
+
// src/routes/private-customizations.ts
|
|
6747
6751
|
import {
|
|
6748
|
-
|
|
6749
|
-
|
|
6750
|
-
|
|
6751
|
-
|
|
6752
|
-
|
|
6753
|
-
|
|
6754
|
-
|
|
6752
|
+
DocumentConflictError as DocumentConflictError2,
|
|
6753
|
+
DocumentNotFoundError as DocumentNotFoundError2,
|
|
6754
|
+
DocumentPathError as DocumentPathError2,
|
|
6755
|
+
PrivateStateDeleteSchema,
|
|
6756
|
+
PrivateStateReadSchema,
|
|
6757
|
+
PrivateStateSchema,
|
|
6758
|
+
PrivateStateWriteSchema,
|
|
6759
|
+
PublishNotificationSchema
|
|
6755
6760
|
} from "@catamorphic/core";
|
|
6756
|
-
import {
|
|
6757
|
-
|
|
6758
|
-
|
|
6759
|
-
|
|
6760
|
-
|
|
6761
|
-
|
|
6762
|
-
|
|
6763
|
-
|
|
6764
|
-
|
|
6765
|
-
|
|
6766
|
-
|
|
6767
|
-
|
|
6768
|
-
|
|
6769
|
-
|
|
6770
|
-
|
|
6771
|
-
|
|
6772
|
-
|
|
6773
|
-
|
|
6774
|
-
|
|
6775
|
-
|
|
6776
|
-
|
|
6777
|
-
|
|
6778
|
-
|
|
6779
|
-
|
|
6780
|
-
|
|
6781
|
-
|
|
6782
|
-
|
|
6783
|
-
|
|
6784
|
-
|
|
6785
|
-
|
|
6786
|
-
|
|
6787
|
-
|
|
6788
|
-
|
|
6789
|
-
|
|
6790
|
-
|
|
6791
|
-
|
|
6792
|
-
|
|
6793
|
-
|
|
6794
|
-
|
|
6795
|
-
|
|
6796
|
-
|
|
6797
|
-
|
|
6798
|
-
|
|
6799
|
-
|
|
6800
|
-
|
|
6801
|
-
|
|
6802
|
-
|
|
6803
|
-
|
|
6804
|
-
|
|
6805
|
-
|
|
6806
|
-
|
|
6807
|
-
properties: {
|
|
6808
|
-
path: { type: "string" },
|
|
6809
|
-
content: { type: "string" },
|
|
6810
|
-
delete: { type: "boolean" }
|
|
6811
|
-
},
|
|
6812
|
-
required: ["path"]
|
|
6813
|
-
}
|
|
6814
|
-
}
|
|
6815
|
-
},
|
|
6816
|
-
required: ["changes"]
|
|
6817
|
-
}
|
|
6818
|
-
},
|
|
6819
|
-
call: guarded(async (args) => {
|
|
6820
|
-
const changes = Array.isArray(args.changes) ? args.changes : [];
|
|
6821
|
-
if (changes.length === 0)
|
|
6822
|
-
throw new Error("changes is required");
|
|
6823
|
-
await refreshDraft(core, identity, projectId);
|
|
6824
|
-
const draftChanges = changes.map((raw) => {
|
|
6825
|
-
const change = asRecord(raw);
|
|
6826
|
-
const path = str(change.path);
|
|
6827
|
-
if (!path)
|
|
6828
|
-
throw new Error("Each change needs a path");
|
|
6829
|
-
if (change.delete === true)
|
|
6830
|
-
return { path, delete: true };
|
|
6831
|
-
const content = str(change.content);
|
|
6832
|
-
if (content === undefined)
|
|
6833
|
-
throw new Error(`${path}: pass content or delete: true`);
|
|
6834
|
-
return { path, content };
|
|
6835
|
-
});
|
|
6836
|
-
await core.projects.writeFiles({
|
|
6837
|
-
identity,
|
|
6838
|
-
projectId,
|
|
6839
|
-
changes: draftChanges
|
|
6840
|
-
});
|
|
6841
|
-
return { written: draftChanges.map((change) => change.path) };
|
|
6842
|
-
})
|
|
6843
|
-
}, {
|
|
6844
|
-
definition: {
|
|
6845
|
-
name: "program_check",
|
|
6846
|
-
description: "Refresh your draft's generated types (the trigger kinds this server offers, in .work/workflows/src/work-triggers.d.ts, and each app's workflow API types), then validate it the way publishing does: workflow and app parse errors and trigger configurations. Run it after writing and before program_deploy.",
|
|
6847
|
-
inputSchema: { type: "object", properties: {} }
|
|
6848
|
-
},
|
|
6849
|
-
call: guarded(async () => checkDraft(core, identity, projectId))
|
|
6850
|
-
});
|
|
6851
|
-
}
|
|
6852
|
-
if (may("program:write") && may("program:publish")) {
|
|
6853
|
-
tools.push({
|
|
6854
|
-
definition: {
|
|
6855
|
-
name: "program_deploy",
|
|
6856
|
-
description: "Publish your draft as the project's production program: workflows move to it, and every app it changes (or that was never published) is built and published, with each app's result reported. Refused while program_check reports errors, and for projects whose program lives in a linked repository (use propose_change there).",
|
|
6857
|
-
inputSchema: {
|
|
6858
|
-
type: "object",
|
|
6859
|
-
properties: {
|
|
6860
|
-
message: {
|
|
6861
|
-
type: "string",
|
|
6862
|
-
description: "What changed and why, as a commit message"
|
|
6863
|
-
}
|
|
6864
|
-
},
|
|
6865
|
-
required: ["message"]
|
|
6866
|
-
}
|
|
6867
|
-
},
|
|
6868
|
-
call: guarded(async (args) => {
|
|
6869
|
-
const message = str(args.message);
|
|
6870
|
-
if (!message)
|
|
6871
|
-
throw new Error("message is required");
|
|
6872
|
-
const project = await core.projects.get(identity, projectId);
|
|
6873
|
-
if (project.remoteUrl)
|
|
6874
|
-
throw new Error(`This project's program is published from ${project.remoteUrl}. Open a pull request there, or use propose_change.`);
|
|
6875
|
-
const check = await checkDraft(core, identity, projectId);
|
|
6876
|
-
if (!check.ok)
|
|
6877
|
-
return { status: "blocked", ...check };
|
|
6878
|
-
const before = await core.deployment.getStatus(identity.tenantId, projectId, identity.externalUserId);
|
|
6879
|
-
const result = await core.deployment.deploy(identity.tenantId, projectId, identity.externalUserId, {
|
|
6880
|
-
message,
|
|
6881
|
-
guardPublishedPaths: (paths) => assertMayManageRolePolicy(identity, projectId, paths)
|
|
6882
|
-
});
|
|
6883
|
-
const published = result.status === "deployed" ? result.commitSha : result.status === "nothing-to-deploy" ? before.remoteHead : null;
|
|
6884
|
-
const apps = published ? await publishApps({
|
|
6885
|
-
core,
|
|
6886
|
-
identity,
|
|
6887
|
-
projectId,
|
|
6888
|
-
base: result.status === "deployed" ? before.remoteHead : published,
|
|
6889
|
-
head: published
|
|
6890
|
-
}) : [];
|
|
6891
|
-
return { ...result, apps, warnings: check.findings };
|
|
6892
|
-
})
|
|
6893
|
-
});
|
|
6894
|
-
}
|
|
6895
|
-
tools.push({
|
|
6896
|
-
definition: {
|
|
6897
|
-
name: "workflow_run",
|
|
6898
|
-
description: "Run a deployed workflow with an input. Waits up to 30 seconds: a finished run returns its output, a longer one returns its runId for run_details. Pass environment to choose where it runs (names in project_overview).",
|
|
6899
|
-
inputSchema: {
|
|
6900
|
-
type: "object",
|
|
6901
|
-
properties: {
|
|
6902
|
-
workflow: { type: "string" },
|
|
6903
|
-
input: {
|
|
6904
|
-
description: "The workflow's input, as JSON of the workflow's input type",
|
|
6905
|
-
type: ["object", "array", "string", "number", "boolean", "null"]
|
|
6906
|
-
},
|
|
6907
|
-
environment: { type: "string" }
|
|
6908
|
-
},
|
|
6909
|
-
required: ["workflow"]
|
|
6761
|
+
import { z as z16 } from "zod";
|
|
6762
|
+
|
|
6763
|
+
// src/routes/session-artifacts.ts
|
|
6764
|
+
import { APP_ICON_NAMES as APP_ICON_NAMES3 } from "@catamorphic/app";
|
|
6765
|
+
import { SessionArtifactNotFoundError } from "@catamorphic/core";
|
|
6766
|
+
import { z as z14 } from "zod";
|
|
6767
|
+
var SessionArtifactSchema = z14.object({
|
|
6768
|
+
id: z14.string().uuid(),
|
|
6769
|
+
projectId: z14.string().uuid(),
|
|
6770
|
+
sessionId: z14.string().uuid().nullable(),
|
|
6771
|
+
lifetime: z14.enum(["session", "member"]),
|
|
6772
|
+
workflowEnablementId: z14.string().uuid().nullable(),
|
|
6773
|
+
kind: z14.enum(["app", "workflow"]),
|
|
6774
|
+
name: z14.string(),
|
|
6775
|
+
title: z14.string(),
|
|
6776
|
+
sourcePath: z14.string(),
|
|
6777
|
+
remoteBranch: z14.string(),
|
|
6778
|
+
commitSha: z14.string(),
|
|
6779
|
+
revision: z14.number().int(),
|
|
6780
|
+
status: z14.enum(["active", "discarded"]),
|
|
6781
|
+
appName: z14.string().nullable(),
|
|
6782
|
+
createdAt: z14.string(),
|
|
6783
|
+
updatedAt: z14.string()
|
|
6784
|
+
});
|
|
6785
|
+
var SessionParams = z14.object({
|
|
6786
|
+
projectId: z14.string().uuid(),
|
|
6787
|
+
sessionId: z14.string().uuid()
|
|
6788
|
+
});
|
|
6789
|
+
var ArtifactParams = z14.object({
|
|
6790
|
+
projectId: z14.string().uuid(),
|
|
6791
|
+
artifactId: z14.string().uuid()
|
|
6792
|
+
});
|
|
6793
|
+
var Files = z14.record(z14.string().min(1).max(512), z14.string()).refine((files) => Object.keys(files).length <= 256);
|
|
6794
|
+
var Outcome = z14.object({
|
|
6795
|
+
artifact: SessionArtifactSchema,
|
|
6796
|
+
build: AppVersionSchema.nullable()
|
|
6797
|
+
});
|
|
6798
|
+
function registerSessionArtifactRoutes(app, ctx) {
|
|
6799
|
+
const typed = app.withTypeProvider();
|
|
6800
|
+
typed.route({
|
|
6801
|
+
method: "GET",
|
|
6802
|
+
url: "/projects/:projectId/agent/sessions/:sessionId/artifacts",
|
|
6803
|
+
schema: {
|
|
6804
|
+
params: SessionParams,
|
|
6805
|
+
response: {
|
|
6806
|
+
200: z14.array(SessionArtifactSchema),
|
|
6807
|
+
400: ErrorSchema,
|
|
6808
|
+
403: ErrorSchema,
|
|
6809
|
+
404: ErrorSchema,
|
|
6810
|
+
409: ErrorSchema,
|
|
6811
|
+
503: ErrorSchema
|
|
6910
6812
|
}
|
|
6911
6813
|
},
|
|
6912
|
-
|
|
6913
|
-
|
|
6914
|
-
|
|
6915
|
-
|
|
6916
|
-
|
|
6917
|
-
|
|
6918
|
-
identity,
|
|
6919
|
-
projectId,
|
|
6920
|
-
workflowName,
|
|
6921
|
-
...environment ? { environment } : {},
|
|
6922
|
-
...args.input === undefined ? {} : { input: args.input },
|
|
6923
|
-
budgetMs: TOOL_SYNC_BUDGET_MS
|
|
6814
|
+
handler: async (request, reply) => {
|
|
6815
|
+
if (!ctx.core)
|
|
6816
|
+
return reply.status(503).send({ error: "Artifacts are unavailable" });
|
|
6817
|
+
return ctx.core.sessionArtifacts.list({
|
|
6818
|
+
...request.params,
|
|
6819
|
+
identity: resolveIdentity(request)
|
|
6924
6820
|
});
|
|
6925
|
-
}
|
|
6926
|
-
}
|
|
6927
|
-
|
|
6928
|
-
|
|
6929
|
-
|
|
6930
|
-
|
|
6931
|
-
|
|
6932
|
-
|
|
6933
|
-
|
|
6934
|
-
|
|
6935
|
-
|
|
6936
|
-
|
|
6937
|
-
|
|
6821
|
+
}
|
|
6822
|
+
});
|
|
6823
|
+
typed.route({
|
|
6824
|
+
method: "POST",
|
|
6825
|
+
url: "/projects/:projectId/agent/sessions/:sessionId/artifacts",
|
|
6826
|
+
bodyLimit: 6 * 1024 * 1024,
|
|
6827
|
+
schema: {
|
|
6828
|
+
params: SessionParams,
|
|
6829
|
+
body: z14.object({
|
|
6830
|
+
kind: z14.enum(["app", "workflow"]),
|
|
6831
|
+
name: z14.string().min(1).max(100),
|
|
6832
|
+
title: z14.string().max(200).optional(),
|
|
6833
|
+
icon: z14.enum(APP_ICON_NAMES3).optional(),
|
|
6834
|
+
source: z14.string().max(5 * 1024 * 1024),
|
|
6835
|
+
files: Files.optional()
|
|
6836
|
+
}),
|
|
6837
|
+
response: {
|
|
6838
|
+
201: Outcome,
|
|
6839
|
+
400: ErrorSchema,
|
|
6840
|
+
403: ErrorSchema,
|
|
6841
|
+
404: ErrorSchema,
|
|
6842
|
+
409: ErrorSchema,
|
|
6843
|
+
503: ErrorSchema
|
|
6844
|
+
}
|
|
6938
6845
|
},
|
|
6939
|
-
|
|
6940
|
-
|
|
6941
|
-
|
|
6942
|
-
|
|
6943
|
-
|
|
6944
|
-
...
|
|
6945
|
-
|
|
6846
|
+
handler: async (request, reply) => {
|
|
6847
|
+
if (!ctx.core || request.body.kind === "app" && !ctx.core.apps)
|
|
6848
|
+
return reply.status(503).send({ error: "Artifacts are unavailable" });
|
|
6849
|
+
const identity = resolveIdentity(request);
|
|
6850
|
+
const artifact = await ctx.core.sessionArtifacts.create({
|
|
6851
|
+
...request.params,
|
|
6852
|
+
...request.body,
|
|
6853
|
+
identity
|
|
6946
6854
|
});
|
|
6947
|
-
|
|
6948
|
-
|
|
6855
|
+
const build = artifact.appName && ctx.core.apps ? await ctx.core.apps.build({
|
|
6856
|
+
identity,
|
|
6857
|
+
projectId: artifact.projectId,
|
|
6858
|
+
appName: artifact.appName,
|
|
6859
|
+
artifactId: artifact.id,
|
|
6860
|
+
kind: "preview"
|
|
6861
|
+
}) : null;
|
|
6862
|
+
if (artifact.appName && request.body.icon && ctx.core.apps)
|
|
6863
|
+
await ctx.core.apps.updatePresentation({
|
|
6864
|
+
identity,
|
|
6865
|
+
projectId: artifact.projectId,
|
|
6866
|
+
appName: artifact.appName,
|
|
6867
|
+
icon: request.body.icon
|
|
6868
|
+
});
|
|
6869
|
+
return reply.status(201).send({ artifact, build });
|
|
6870
|
+
}
|
|
6871
|
+
});
|
|
6872
|
+
typed.route({
|
|
6873
|
+
method: "GET",
|
|
6874
|
+
url: "/projects/:projectId/session-artifacts/:artifactId",
|
|
6875
|
+
schema: {
|
|
6876
|
+
params: ArtifactParams,
|
|
6877
|
+
response: {
|
|
6878
|
+
200: SessionArtifactSchema,
|
|
6879
|
+
400: ErrorSchema,
|
|
6880
|
+
403: ErrorSchema,
|
|
6881
|
+
404: ErrorSchema,
|
|
6882
|
+
409: ErrorSchema,
|
|
6883
|
+
503: ErrorSchema
|
|
6884
|
+
}
|
|
6885
|
+
},
|
|
6886
|
+
handler: async (request, reply) => {
|
|
6887
|
+
if (!ctx.core)
|
|
6888
|
+
return reply.status(503).send({ error: "Artifacts are unavailable" });
|
|
6889
|
+
try {
|
|
6890
|
+
return await ctx.core.sessionArtifacts.get({
|
|
6891
|
+
...request.params,
|
|
6892
|
+
identity: resolveIdentity(request)
|
|
6893
|
+
});
|
|
6894
|
+
} catch (error) {
|
|
6895
|
+
if (error instanceof SessionArtifactNotFoundError)
|
|
6896
|
+
return reply.status(404).send({ error: error.message });
|
|
6897
|
+
throw error;
|
|
6898
|
+
}
|
|
6899
|
+
}
|
|
6900
|
+
});
|
|
6901
|
+
typed.route({
|
|
6902
|
+
method: "GET",
|
|
6903
|
+
url: "/projects/:projectId/session-artifacts/:artifactId/files",
|
|
6904
|
+
schema: {
|
|
6905
|
+
params: ArtifactParams,
|
|
6906
|
+
response: {
|
|
6907
|
+
200: z14.record(z14.string(), z14.string()),
|
|
6908
|
+
400: ErrorSchema,
|
|
6909
|
+
403: ErrorSchema,
|
|
6910
|
+
404: ErrorSchema,
|
|
6911
|
+
409: ErrorSchema,
|
|
6912
|
+
503: ErrorSchema
|
|
6913
|
+
}
|
|
6914
|
+
},
|
|
6915
|
+
handler: async (request, reply) => {
|
|
6916
|
+
if (!ctx.core)
|
|
6917
|
+
return reply.status(503).send({ error: "Artifacts are unavailable" });
|
|
6918
|
+
return ctx.core.sessionArtifacts.files({
|
|
6919
|
+
...request.params,
|
|
6920
|
+
identity: resolveIdentity(request)
|
|
6921
|
+
});
|
|
6922
|
+
}
|
|
6923
|
+
});
|
|
6924
|
+
typed.route({
|
|
6925
|
+
method: "PATCH",
|
|
6926
|
+
url: "/projects/:projectId/session-artifacts/:artifactId",
|
|
6927
|
+
bodyLimit: 6 * 1024 * 1024,
|
|
6928
|
+
schema: {
|
|
6929
|
+
params: ArtifactParams,
|
|
6930
|
+
body: z14.object({
|
|
6931
|
+
revision: z14.number().int().positive(),
|
|
6932
|
+
title: z14.string().max(200).optional(),
|
|
6933
|
+
files: z14.record(z14.string().min(1).max(512), z14.string().nullable())
|
|
6934
|
+
}),
|
|
6935
|
+
response: {
|
|
6936
|
+
200: Outcome,
|
|
6937
|
+
400: ErrorSchema,
|
|
6938
|
+
403: ErrorSchema,
|
|
6939
|
+
404: ErrorSchema,
|
|
6940
|
+
409: ErrorSchema,
|
|
6941
|
+
503: ErrorSchema
|
|
6942
|
+
}
|
|
6943
|
+
},
|
|
6944
|
+
handler: async (request, reply) => {
|
|
6945
|
+
if (!ctx.core)
|
|
6946
|
+
return reply.status(503).send({ error: "Artifacts are unavailable" });
|
|
6947
|
+
const identity = resolveIdentity(request);
|
|
6948
|
+
const artifact = await ctx.core.sessionArtifacts.update({
|
|
6949
|
+
...request.params,
|
|
6950
|
+
...request.body,
|
|
6951
|
+
identity
|
|
6952
|
+
});
|
|
6953
|
+
const build = artifact.appName && ctx.core.apps ? await ctx.core.apps.build({
|
|
6954
|
+
identity,
|
|
6955
|
+
projectId: artifact.projectId,
|
|
6956
|
+
appName: artifact.appName,
|
|
6957
|
+
artifactId: artifact.id,
|
|
6958
|
+
kind: "preview"
|
|
6959
|
+
}) : null;
|
|
6960
|
+
return { artifact, build };
|
|
6961
|
+
}
|
|
6962
|
+
});
|
|
6963
|
+
typed.route({
|
|
6964
|
+
method: "DELETE",
|
|
6965
|
+
url: "/projects/:projectId/session-artifacts/:artifactId",
|
|
6966
|
+
schema: {
|
|
6967
|
+
params: ArtifactParams,
|
|
6968
|
+
response: {
|
|
6969
|
+
204: z14.null(),
|
|
6970
|
+
400: ErrorSchema,
|
|
6971
|
+
403: ErrorSchema,
|
|
6972
|
+
404: ErrorSchema,
|
|
6973
|
+
409: ErrorSchema,
|
|
6974
|
+
503: ErrorSchema
|
|
6975
|
+
}
|
|
6976
|
+
},
|
|
6977
|
+
handler: async (request, reply) => {
|
|
6978
|
+
if (!ctx.core)
|
|
6979
|
+
return reply.status(503).send({ error: "Artifacts are unavailable" });
|
|
6980
|
+
const identity = resolveIdentity(request);
|
|
6981
|
+
const artifact = await ctx.core.sessionArtifacts.discard({
|
|
6982
|
+
...request.params,
|
|
6983
|
+
identity
|
|
6984
|
+
});
|
|
6985
|
+
if (artifact.sessionId && ctx.core.watchers)
|
|
6986
|
+
await ctx.core.watchers.stop({
|
|
6987
|
+
identity,
|
|
6988
|
+
projectId: artifact.projectId,
|
|
6989
|
+
sessionId: artifact.sessionId,
|
|
6990
|
+
watcherId: artifact.id
|
|
6991
|
+
});
|
|
6992
|
+
return reply.status(204).send(null);
|
|
6993
|
+
}
|
|
6994
|
+
});
|
|
6995
|
+
typed.route({
|
|
6996
|
+
method: "POST",
|
|
6997
|
+
url: "/projects/:projectId/session-artifacts/:artifactId/runs",
|
|
6998
|
+
schema: {
|
|
6999
|
+
params: ArtifactParams,
|
|
7000
|
+
body: TriggerRunSchema.extend({ environment: z14.string().optional() }),
|
|
7001
|
+
response: {
|
|
7002
|
+
201: RunSchema,
|
|
7003
|
+
400: ErrorSchema,
|
|
7004
|
+
403: ErrorSchema,
|
|
7005
|
+
404: ErrorSchema,
|
|
7006
|
+
409: ErrorSchema,
|
|
7007
|
+
503: ErrorSchema
|
|
7008
|
+
}
|
|
7009
|
+
},
|
|
7010
|
+
handler: async (request, reply) => {
|
|
7011
|
+
if (!ctx.core)
|
|
7012
|
+
return reply.status(503).send({ error: "Artifacts are unavailable" });
|
|
7013
|
+
const identity = resolveIdentity(request);
|
|
7014
|
+
const artifact = await ctx.core.sessionArtifacts.get({
|
|
7015
|
+
...request.params,
|
|
7016
|
+
identity
|
|
7017
|
+
});
|
|
7018
|
+
if (artifact.kind !== "workflow")
|
|
7019
|
+
return reply.status(400).send({ error: "This artifact is an app" });
|
|
7020
|
+
await ctx.core.sessionArtifacts.assertActive({
|
|
7021
|
+
...request.params,
|
|
7022
|
+
identity
|
|
7023
|
+
});
|
|
7024
|
+
const run = await ctx.core.runs.triggerAtCommit({
|
|
7025
|
+
...request.body,
|
|
7026
|
+
identity,
|
|
7027
|
+
projectId: artifact.projectId,
|
|
7028
|
+
workflowName: artifact.name,
|
|
7029
|
+
commitSha: artifact.commitSha,
|
|
7030
|
+
remoteBranch: artifact.remoteBranch
|
|
7031
|
+
});
|
|
7032
|
+
return reply.status(201).send(run);
|
|
7033
|
+
}
|
|
7034
|
+
});
|
|
7035
|
+
}
|
|
7036
|
+
|
|
7037
|
+
// src/routes/workflow-enablements.ts
|
|
7038
|
+
import {
|
|
7039
|
+
AccessDeniedError as AccessDeniedError7,
|
|
7040
|
+
AuthenticationRequiredError as AuthenticationRequiredError4,
|
|
7041
|
+
ConnectionPermissionDeniedError as ConnectionPermissionDeniedError3,
|
|
7042
|
+
ConnectionUnavailableError as ConnectionUnavailableError3,
|
|
7043
|
+
EnvironmentAccessDeniedError as EnvironmentAccessDeniedError4,
|
|
7044
|
+
EnvironmentBindingUnavailableError as EnvironmentBindingUnavailableError4,
|
|
7045
|
+
EnvironmentIncompatibleError as EnvironmentIncompatibleError4,
|
|
7046
|
+
EnvironmentNotFoundError as EnvironmentNotFoundError4,
|
|
7047
|
+
EnvironmentPolicyInvalidError,
|
|
7048
|
+
ProductionDeploymentNotFoundError as ProductionDeploymentNotFoundError3,
|
|
7049
|
+
WorkflowEnablementConflictError,
|
|
7050
|
+
WorkflowEnablementConsentRequiredError,
|
|
7051
|
+
WorkflowEnablementNotFoundError,
|
|
7052
|
+
WorkflowEnablementSuspendedError,
|
|
7053
|
+
WorkflowNotFoundError as WorkflowNotFoundError2
|
|
7054
|
+
} from "@catamorphic/core";
|
|
7055
|
+
import { z as z15 } from "zod";
|
|
7056
|
+
var EnablementParamsSchema = ProjectIdParamsSchema.extend({
|
|
7057
|
+
enablementId: z15.string().uuid()
|
|
7058
|
+
});
|
|
7059
|
+
var NotPublishedErrorSchema = z15.object({
|
|
7060
|
+
error: z15.string(),
|
|
7061
|
+
reason: z15.literal("not_published")
|
|
7062
|
+
});
|
|
7063
|
+
var PreviewConflictSchema = z15.union([NotPublishedErrorSchema, ErrorSchema]);
|
|
7064
|
+
var SelectionSchema = z15.record(z15.string(), z15.string().uuid()).optional();
|
|
7065
|
+
var PreviewBodySchema = z15.object({
|
|
7066
|
+
workflowName: z15.string().min(1),
|
|
7067
|
+
environment: z15.string().min(1).optional(),
|
|
7068
|
+
owner: WorkflowEnablementOwnerSchema.optional(),
|
|
7069
|
+
connectionSelections: SelectionSchema
|
|
7070
|
+
});
|
|
7071
|
+
function registerWorkflowEnablementRoutes(app, ctx) {
|
|
7072
|
+
const typed = app.withTypeProvider();
|
|
7073
|
+
const service = () => ctx.core?.workflowEnablements;
|
|
7074
|
+
typed.route({
|
|
7075
|
+
method: "GET",
|
|
7076
|
+
url: "/projects/:projectId/workflow-enablements",
|
|
7077
|
+
schema: {
|
|
7078
|
+
params: ProjectIdParamsSchema,
|
|
7079
|
+
querystring: z15.object({ workflowName: z15.string().optional() }),
|
|
7080
|
+
response: {
|
|
7081
|
+
200: z15.object({
|
|
7082
|
+
items: z15.array(WorkflowEnablementSchema),
|
|
7083
|
+
canManageProjectAutomations: z15.boolean()
|
|
7084
|
+
}),
|
|
7085
|
+
503: ErrorSchema
|
|
7086
|
+
}
|
|
7087
|
+
},
|
|
7088
|
+
handler: async (request, reply) => {
|
|
7089
|
+
const workflowEnablements = service();
|
|
7090
|
+
if (!workflowEnablements) {
|
|
7091
|
+
return reply.status(503).send({ error: "Workflow enablements unavailable" });
|
|
7092
|
+
}
|
|
7093
|
+
const identity = resolveIdentity(request);
|
|
7094
|
+
const { projectId } = request.params;
|
|
7095
|
+
return reply.send({
|
|
7096
|
+
items: await workflowEnablements.list({
|
|
7097
|
+
identity,
|
|
7098
|
+
projectId,
|
|
7099
|
+
workflowName: request.query.workflowName
|
|
7100
|
+
}),
|
|
7101
|
+
canManageProjectAutomations: workflowEnablements.mayManageProjectAutomations({
|
|
7102
|
+
identity,
|
|
7103
|
+
projectId
|
|
7104
|
+
})
|
|
7105
|
+
});
|
|
7106
|
+
}
|
|
7107
|
+
});
|
|
7108
|
+
typed.route({
|
|
7109
|
+
method: "POST",
|
|
7110
|
+
url: "/projects/:projectId/workflow-enablement-preview",
|
|
7111
|
+
schema: {
|
|
7112
|
+
params: ProjectIdParamsSchema,
|
|
7113
|
+
body: PreviewBodySchema,
|
|
7114
|
+
response: {
|
|
7115
|
+
200: WorkflowEnablementPreviewSchema,
|
|
7116
|
+
403: ErrorSchema,
|
|
7117
|
+
409: PreviewConflictSchema,
|
|
7118
|
+
428: AuthenticationRequiredSchema,
|
|
7119
|
+
503: ErrorSchema
|
|
7120
|
+
}
|
|
7121
|
+
},
|
|
7122
|
+
handler: async (request, reply) => {
|
|
7123
|
+
const workflowEnablements = service();
|
|
7124
|
+
if (!workflowEnablements) {
|
|
7125
|
+
return reply.status(503).send({ error: "Workflow enablements unavailable" });
|
|
7126
|
+
}
|
|
7127
|
+
try {
|
|
7128
|
+
return reply.send(await workflowEnablements.preview({
|
|
7129
|
+
identity: resolveIdentity(request),
|
|
7130
|
+
projectId: request.params.projectId,
|
|
7131
|
+
...request.body
|
|
7132
|
+
}));
|
|
7133
|
+
} catch (error) {
|
|
7134
|
+
return handleEnablementError(error, reply);
|
|
7135
|
+
}
|
|
7136
|
+
}
|
|
7137
|
+
});
|
|
7138
|
+
typed.route({
|
|
7139
|
+
method: "POST",
|
|
7140
|
+
url: "/projects/:projectId/workflow-enablements",
|
|
7141
|
+
schema: {
|
|
7142
|
+
params: ProjectIdParamsSchema,
|
|
7143
|
+
body: PreviewBodySchema.extend({ consentDigest: z15.string().length(64) }),
|
|
7144
|
+
response: {
|
|
7145
|
+
201: WorkflowEnablementSchema,
|
|
7146
|
+
403: ErrorSchema,
|
|
7147
|
+
409: PreviewConflictSchema,
|
|
7148
|
+
428: AuthenticationRequiredSchema,
|
|
7149
|
+
503: ErrorSchema
|
|
7150
|
+
}
|
|
7151
|
+
},
|
|
7152
|
+
handler: async (request, reply) => {
|
|
7153
|
+
const workflowEnablements = service();
|
|
7154
|
+
if (!workflowEnablements) {
|
|
7155
|
+
return reply.status(503).send({ error: "Workflow enablements unavailable" });
|
|
7156
|
+
}
|
|
7157
|
+
try {
|
|
7158
|
+
return reply.status(201).send(await workflowEnablements.create({
|
|
7159
|
+
identity: resolveIdentity(request),
|
|
7160
|
+
projectId: request.params.projectId,
|
|
7161
|
+
...request.body
|
|
7162
|
+
}));
|
|
7163
|
+
} catch (error) {
|
|
7164
|
+
return handleEnablementError(error, reply);
|
|
7165
|
+
}
|
|
7166
|
+
}
|
|
7167
|
+
});
|
|
7168
|
+
typed.route({
|
|
7169
|
+
method: "GET",
|
|
7170
|
+
url: "/projects/:projectId/workflow-enablements/:enablementId",
|
|
7171
|
+
schema: {
|
|
7172
|
+
params: EnablementParamsSchema,
|
|
7173
|
+
response: {
|
|
7174
|
+
200: WorkflowEnablementSchema,
|
|
7175
|
+
403: ErrorSchema,
|
|
7176
|
+
404: ErrorSchema
|
|
7177
|
+
}
|
|
7178
|
+
},
|
|
7179
|
+
handler: async (request, reply) => {
|
|
7180
|
+
const workflowEnablements = service();
|
|
7181
|
+
if (!workflowEnablements) {
|
|
7182
|
+
return reply.status(404).send({ error: "Workflow enablement not found" });
|
|
7183
|
+
}
|
|
7184
|
+
try {
|
|
7185
|
+
const result = await workflowEnablements.get({
|
|
7186
|
+
identity: resolveIdentity(request),
|
|
7187
|
+
enablementId: request.params.enablementId
|
|
7188
|
+
});
|
|
7189
|
+
return result.projectId === request.params.projectId ? reply.send(result) : reply.status(404).send({ error: "Workflow enablement not found" });
|
|
7190
|
+
} catch (error) {
|
|
7191
|
+
return handleEnablementError(error, reply);
|
|
7192
|
+
}
|
|
7193
|
+
}
|
|
7194
|
+
});
|
|
7195
|
+
for (const action of ["disable", "reenable"]) {
|
|
7196
|
+
typed.route({
|
|
7197
|
+
method: "POST",
|
|
7198
|
+
url: `/projects/:projectId/workflow-enablements/:enablementId/${action}`,
|
|
7199
|
+
schema: {
|
|
7200
|
+
params: EnablementParamsSchema,
|
|
7201
|
+
response: {
|
|
7202
|
+
200: WorkflowEnablementSchema,
|
|
7203
|
+
403: ErrorSchema,
|
|
7204
|
+
404: ErrorSchema,
|
|
7205
|
+
409: PreviewConflictSchema
|
|
7206
|
+
}
|
|
7207
|
+
},
|
|
7208
|
+
handler: async (request, reply) => {
|
|
7209
|
+
const workflowEnablements = service();
|
|
7210
|
+
if (!workflowEnablements) {
|
|
7211
|
+
return reply.status(404).send({ error: "Workflow enablement not found" });
|
|
7212
|
+
}
|
|
7213
|
+
try {
|
|
7214
|
+
const identity = resolveIdentity(request);
|
|
7215
|
+
const current = await workflowEnablements.get({
|
|
7216
|
+
identity,
|
|
7217
|
+
enablementId: request.params.enablementId
|
|
7218
|
+
});
|
|
7219
|
+
if (current.projectId !== request.params.projectId) {
|
|
7220
|
+
return reply.status(404).send({ error: "Workflow enablement not found" });
|
|
7221
|
+
}
|
|
7222
|
+
const result = await workflowEnablements[action]({
|
|
7223
|
+
identity,
|
|
7224
|
+
enablementId: request.params.enablementId
|
|
7225
|
+
});
|
|
7226
|
+
return reply.send(result);
|
|
7227
|
+
} catch (error) {
|
|
7228
|
+
return handleEnablementError(error, reply);
|
|
7229
|
+
}
|
|
7230
|
+
}
|
|
7231
|
+
});
|
|
7232
|
+
}
|
|
7233
|
+
typed.route({
|
|
7234
|
+
method: "POST",
|
|
7235
|
+
url: "/projects/:projectId/workflow-enablements/:enablementId/update-deployment",
|
|
7236
|
+
schema: {
|
|
7237
|
+
params: EnablementParamsSchema,
|
|
7238
|
+
body: z15.object({ consentDigest: z15.string().length(64) }),
|
|
7239
|
+
response: {
|
|
7240
|
+
200: WorkflowEnablementSchema,
|
|
7241
|
+
403: ErrorSchema,
|
|
7242
|
+
404: ErrorSchema,
|
|
7243
|
+
409: PreviewConflictSchema,
|
|
7244
|
+
428: AuthenticationRequiredSchema
|
|
7245
|
+
}
|
|
7246
|
+
},
|
|
7247
|
+
handler: async (request, reply) => {
|
|
7248
|
+
const workflowEnablements = service();
|
|
7249
|
+
if (!workflowEnablements) {
|
|
7250
|
+
return reply.status(404).send({ error: "Workflow enablement not found" });
|
|
7251
|
+
}
|
|
7252
|
+
try {
|
|
7253
|
+
const identity = resolveIdentity(request);
|
|
7254
|
+
const current = await workflowEnablements.get({
|
|
7255
|
+
identity,
|
|
7256
|
+
enablementId: request.params.enablementId
|
|
7257
|
+
});
|
|
7258
|
+
if (current.projectId !== request.params.projectId) {
|
|
7259
|
+
return reply.status(404).send({ error: "Workflow enablement not found" });
|
|
7260
|
+
}
|
|
7261
|
+
const result = await workflowEnablements.updateDeployment({
|
|
7262
|
+
identity,
|
|
7263
|
+
enablementId: request.params.enablementId,
|
|
7264
|
+
consentDigest: request.body.consentDigest
|
|
7265
|
+
});
|
|
7266
|
+
return reply.send(result);
|
|
7267
|
+
} catch (error) {
|
|
7268
|
+
return handleEnablementError(error, reply);
|
|
7269
|
+
}
|
|
7270
|
+
}
|
|
7271
|
+
});
|
|
7272
|
+
}
|
|
7273
|
+
function handleEnablementError(error, reply) {
|
|
7274
|
+
if (error instanceof AuthenticationRequiredError4) {
|
|
7275
|
+
return reply.status(428).send({
|
|
7276
|
+
error: error.message,
|
|
7277
|
+
code: "authentication_required",
|
|
7278
|
+
environment: error.environment,
|
|
7279
|
+
requirements: error.requirements
|
|
7280
|
+
});
|
|
7281
|
+
}
|
|
7282
|
+
if (error instanceof WorkflowEnablementNotFoundError) {
|
|
7283
|
+
return reply.status(404).send({ error: error.message });
|
|
7284
|
+
}
|
|
7285
|
+
if (error instanceof WorkflowNotFoundError2 || error instanceof ProductionDeploymentNotFoundError3) {
|
|
7286
|
+
return reply.status(409).send({
|
|
7287
|
+
error: "This workflow isn't in the project's published version yet. Publish the project's changes, then turn it on.",
|
|
7288
|
+
reason: "not_published"
|
|
7289
|
+
});
|
|
7290
|
+
}
|
|
7291
|
+
if (error instanceof AccessDeniedError7 || error instanceof ConnectionPermissionDeniedError3 || error instanceof EnvironmentAccessDeniedError4) {
|
|
7292
|
+
return reply.status(403).send({ error: error.message });
|
|
7293
|
+
}
|
|
7294
|
+
if (error instanceof WorkflowEnablementConsentRequiredError || error instanceof WorkflowEnablementConflictError || error instanceof ConnectionUnavailableError3 || error instanceof EnvironmentNotFoundError4 || error instanceof EnvironmentPolicyInvalidError || error instanceof EnvironmentIncompatibleError4 || error instanceof EnvironmentBindingUnavailableError4 || error instanceof WorkflowEnablementSuspendedError) {
|
|
7295
|
+
return reply.status(409).send({ error: error.message });
|
|
7296
|
+
}
|
|
7297
|
+
throw error;
|
|
7298
|
+
}
|
|
7299
|
+
|
|
7300
|
+
// src/routes/private-customizations.ts
|
|
7301
|
+
var State = PrivateStateSchema.extend({ value: JsonValueSchema });
|
|
7302
|
+
var StateWrite = PrivateStateWriteSchema.extend({ value: JsonValueSchema });
|
|
7303
|
+
var Project = z16.object({ projectId: z16.string().uuid() });
|
|
7304
|
+
var Artifact = Project.extend({ artifactId: z16.string().uuid() });
|
|
7305
|
+
var Revision = z16.object({
|
|
7306
|
+
revision: z16.number().int().positive(),
|
|
7307
|
+
environment: z16.string().optional()
|
|
7308
|
+
});
|
|
7309
|
+
var errors = {
|
|
7310
|
+
400: ErrorSchema,
|
|
7311
|
+
403: ErrorSchema,
|
|
7312
|
+
404: ErrorSchema,
|
|
7313
|
+
409: ErrorSchema.extend({ currentVersion: z16.number().optional() }),
|
|
7314
|
+
422: ErrorSchema,
|
|
7315
|
+
428: AuthenticationRequiredSchema,
|
|
7316
|
+
429: ErrorSchema,
|
|
7317
|
+
503: ErrorSchema
|
|
7318
|
+
};
|
|
7319
|
+
function registerPrivateCustomizationRoutes(app, ctx) {
|
|
7320
|
+
app.register(async (privateApp) => {
|
|
7321
|
+
privateApp.setErrorHandler((error, _request, reply) => {
|
|
7322
|
+
if (error instanceof DocumentConflictError2)
|
|
7323
|
+
return reply.status(409).send({ error: error.message, currentVersion: error.currentVersion });
|
|
7324
|
+
if (error instanceof DocumentNotFoundError2)
|
|
7325
|
+
return reply.status(404).send({ error: error.message });
|
|
7326
|
+
if (error instanceof DocumentPathError2)
|
|
7327
|
+
return reply.status(400).send({ error: error.message });
|
|
7328
|
+
const triggerError = replyForTriggerError(error, reply);
|
|
7329
|
+
if (triggerError)
|
|
7330
|
+
return triggerError;
|
|
7331
|
+
return handleEnablementError(error, reply);
|
|
7332
|
+
});
|
|
7333
|
+
const typed = privateApp.withTypeProvider();
|
|
7334
|
+
typed.post("/projects/:projectId/private-state/read", {
|
|
7335
|
+
schema: {
|
|
7336
|
+
params: Project,
|
|
7337
|
+
body: PrivateStateReadSchema,
|
|
7338
|
+
response: { 200: State, ...errors }
|
|
7339
|
+
}
|
|
7340
|
+
}, async (request, reply) => {
|
|
7341
|
+
if (!ctx.core)
|
|
7342
|
+
return reply.status(503).send({ error: "Private state is unavailable" });
|
|
7343
|
+
return ctx.core.privateState.read({
|
|
7344
|
+
...request.params,
|
|
7345
|
+
...request.body,
|
|
7346
|
+
identity: resolveIdentity(request)
|
|
7347
|
+
});
|
|
7348
|
+
});
|
|
7349
|
+
typed.put("/projects/:projectId/private-state", {
|
|
7350
|
+
schema: {
|
|
7351
|
+
params: Project,
|
|
7352
|
+
body: StateWrite,
|
|
7353
|
+
response: { 200: State, ...errors }
|
|
7354
|
+
}
|
|
7355
|
+
}, async (request, reply) => {
|
|
7356
|
+
if (!ctx.core)
|
|
7357
|
+
return reply.status(503).send({ error: "Private state is unavailable" });
|
|
7358
|
+
return ctx.core.privateState.write({
|
|
7359
|
+
...request.params,
|
|
7360
|
+
...request.body,
|
|
7361
|
+
identity: resolveIdentity(request)
|
|
7362
|
+
});
|
|
7363
|
+
});
|
|
7364
|
+
typed.delete("/projects/:projectId/private-state", {
|
|
7365
|
+
schema: {
|
|
7366
|
+
params: Project,
|
|
7367
|
+
body: PrivateStateDeleteSchema,
|
|
7368
|
+
response: { 200: z16.object({ version: z16.number().int() }), ...errors }
|
|
7369
|
+
}
|
|
7370
|
+
}, async (request, reply) => {
|
|
7371
|
+
if (!ctx.core)
|
|
7372
|
+
return reply.status(503).send({ error: "Private state is unavailable" });
|
|
7373
|
+
return ctx.core.privateState.delete({
|
|
7374
|
+
...request.params,
|
|
7375
|
+
...request.body,
|
|
7376
|
+
identity: resolveIdentity(request)
|
|
7377
|
+
});
|
|
7378
|
+
});
|
|
7379
|
+
typed.post("/projects/:projectId/notifications", {
|
|
7380
|
+
schema: {
|
|
7381
|
+
params: Project,
|
|
7382
|
+
body: PublishNotificationSchema,
|
|
7383
|
+
response: {
|
|
7384
|
+
200: z16.object({ published: z16.literal(true) }),
|
|
7385
|
+
...errors
|
|
7386
|
+
}
|
|
7387
|
+
}
|
|
7388
|
+
}, async (request, reply) => {
|
|
7389
|
+
if (!ctx.core)
|
|
7390
|
+
return reply.status(503).send({ error: "Notifications are unavailable" });
|
|
7391
|
+
return ctx.core.notifications.notify({
|
|
7392
|
+
...request.params,
|
|
7393
|
+
...request.body,
|
|
7394
|
+
identity: resolveIdentity(request)
|
|
7395
|
+
});
|
|
7396
|
+
});
|
|
7397
|
+
typed.get("/projects/:projectId/private-workflows", {
|
|
7398
|
+
schema: {
|
|
7399
|
+
params: Project,
|
|
7400
|
+
response: { 200: z16.array(SessionArtifactSchema), ...errors }
|
|
7401
|
+
}
|
|
7402
|
+
}, async (request, reply) => {
|
|
7403
|
+
if (!ctx.core)
|
|
7404
|
+
return reply.status(503).send({ error: "Private workflows are unavailable" });
|
|
7405
|
+
return ctx.core.sessionArtifacts.list({
|
|
7406
|
+
...request.params,
|
|
7407
|
+
identity: resolveIdentity(request),
|
|
7408
|
+
lifetime: "member"
|
|
7409
|
+
});
|
|
7410
|
+
});
|
|
7411
|
+
typed.post("/projects/:projectId/private-workflows", {
|
|
7412
|
+
bodyLimit: 6 * 1024 * 1024,
|
|
7413
|
+
schema: {
|
|
7414
|
+
params: Project,
|
|
7415
|
+
body: z16.object({
|
|
7416
|
+
name: z16.string().min(1).max(100),
|
|
7417
|
+
title: z16.string().max(200).optional(),
|
|
7418
|
+
source: z16.string().max(5 * 1024 * 1024),
|
|
7419
|
+
files: z16.record(z16.string(), z16.string()).optional()
|
|
7420
|
+
}),
|
|
7421
|
+
response: { 201: SessionArtifactSchema, ...errors }
|
|
7422
|
+
}
|
|
7423
|
+
}, async (request, reply) => {
|
|
7424
|
+
if (!ctx.core)
|
|
7425
|
+
return reply.status(503).send({ error: "Private workflows are unavailable" });
|
|
7426
|
+
return reply.status(201).send(await ctx.core.sessionArtifacts.create({
|
|
7427
|
+
...request.params,
|
|
7428
|
+
...request.body,
|
|
7429
|
+
identity: resolveIdentity(request),
|
|
7430
|
+
lifetime: "member",
|
|
7431
|
+
kind: "workflow"
|
|
7432
|
+
}));
|
|
7433
|
+
});
|
|
7434
|
+
typed.post("/projects/:projectId/private-workflows/:artifactId/preview", {
|
|
7435
|
+
schema: {
|
|
7436
|
+
params: Artifact,
|
|
7437
|
+
body: Revision,
|
|
7438
|
+
response: { 200: WorkflowEnablementPreviewSchema, ...errors }
|
|
7439
|
+
}
|
|
7440
|
+
}, async (request, reply) => {
|
|
7441
|
+
if (!ctx.core)
|
|
7442
|
+
return reply.status(503).send({ error: "Private workflows are unavailable" });
|
|
7443
|
+
return ctx.core.privateWorkflows.preview({
|
|
7444
|
+
...request.params,
|
|
7445
|
+
...request.body,
|
|
7446
|
+
identity: resolveIdentity(request)
|
|
7447
|
+
});
|
|
7448
|
+
});
|
|
7449
|
+
typed.post("/projects/:projectId/private-workflows/:artifactId/activate", {
|
|
7450
|
+
schema: {
|
|
7451
|
+
params: Artifact,
|
|
7452
|
+
body: Revision.extend({ consentDigest: z16.string() }),
|
|
7453
|
+
response: { 200: WorkflowEnablementSchema, ...errors }
|
|
7454
|
+
}
|
|
7455
|
+
}, async (request, reply) => {
|
|
7456
|
+
if (!ctx.core)
|
|
7457
|
+
return reply.status(503).send({ error: "Private workflows are unavailable" });
|
|
7458
|
+
return ctx.core.privateWorkflows.activate({
|
|
7459
|
+
...request.params,
|
|
7460
|
+
...request.body,
|
|
7461
|
+
identity: resolveIdentity(request)
|
|
7462
|
+
});
|
|
7463
|
+
});
|
|
7464
|
+
typed.post("/projects/:projectId/private-workflows/:artifactId/stop", {
|
|
7465
|
+
schema: {
|
|
7466
|
+
params: Artifact,
|
|
7467
|
+
response: { 200: z16.object({ stopped: z16.boolean() }), ...errors }
|
|
7468
|
+
}
|
|
7469
|
+
}, async (request, reply) => {
|
|
7470
|
+
if (!ctx.core)
|
|
7471
|
+
return reply.status(503).send({ error: "Private workflows are unavailable" });
|
|
7472
|
+
return ctx.core.privateWorkflows.stop({
|
|
7473
|
+
...request.params,
|
|
7474
|
+
identity: resolveIdentity(request)
|
|
7475
|
+
});
|
|
7476
|
+
});
|
|
7477
|
+
typed.post("/projects/:projectId/private-workflows/:artifactId/run", {
|
|
7478
|
+
schema: {
|
|
7479
|
+
params: Artifact,
|
|
7480
|
+
body: Revision.extend({ input: JsonValueSchema.optional() }),
|
|
7481
|
+
response: { 200: RunSchema, ...errors }
|
|
7482
|
+
}
|
|
7483
|
+
}, async (request, reply) => {
|
|
7484
|
+
if (!ctx.core)
|
|
7485
|
+
return reply.status(503).send({ error: "Private workflows are unavailable" });
|
|
7486
|
+
return ctx.core.privateWorkflows.run({
|
|
7487
|
+
...request.params,
|
|
7488
|
+
...request.body,
|
|
7489
|
+
identity: resolveIdentity(request)
|
|
7490
|
+
});
|
|
7491
|
+
});
|
|
7492
|
+
});
|
|
7493
|
+
}
|
|
7494
|
+
|
|
7495
|
+
// src/routes/project-mcp.ts
|
|
7496
|
+
import { agentCapabilityTools } from "@catamorphic/sandbox";
|
|
7497
|
+
import { z as z20 } from "zod";
|
|
7498
|
+
|
|
7499
|
+
// src/project-mcp-program.ts
|
|
7500
|
+
import {
|
|
7501
|
+
AccessDeniedError as AccessDeniedError8,
|
|
7502
|
+
assertMayManageRolePolicy,
|
|
7503
|
+
assertProjectPermission as assertProjectPermission2,
|
|
7504
|
+
DeploymentBlockedError,
|
|
7505
|
+
effectiveProjectPermissions as effectiveProjectPermissions2,
|
|
7506
|
+
hasProjectPermission,
|
|
7507
|
+
mayUseProject
|
|
7508
|
+
} from "@catamorphic/core";
|
|
7509
|
+
import { checkProject } from "@catamorphic/parser";
|
|
7510
|
+
import {
|
|
7511
|
+
isProjectPathWithin,
|
|
7512
|
+
PROJECT_APPS_DIR,
|
|
7513
|
+
PROJECT_CONTRACTS_DIR,
|
|
7514
|
+
PROJECT_WORKFLOWS_DIR
|
|
7515
|
+
} from "@catamorphic/workflow/project-layout";
|
|
7516
|
+
var READ_ONLY = { readOnlyHint: true };
|
|
7517
|
+
var TOOL_SYNC_BUDGET_MS = 30000;
|
|
7518
|
+
function programTools(core, identity, projectId) {
|
|
7519
|
+
if (!mayUseProject(identity, projectId))
|
|
7520
|
+
return [];
|
|
7521
|
+
const tools = [overviewTool(core, identity, projectId)];
|
|
7522
|
+
const may = (permission) => hasProjectPermission(identity, projectId, permission);
|
|
7523
|
+
if (may("program:write")) {
|
|
7524
|
+
tools.push({
|
|
7525
|
+
definition: {
|
|
7526
|
+
name: "program_files",
|
|
7527
|
+
description: "Your draft of the project's program (workflows, apps, agents, roles and skills under .work/, plus any other files). Without a path, lists files and your unpublished changes; with a path, returns that file from your draft.",
|
|
7528
|
+
inputSchema: {
|
|
7529
|
+
type: "object",
|
|
7530
|
+
properties: {
|
|
7531
|
+
path: { type: "string", description: "File to read" }
|
|
7532
|
+
}
|
|
7533
|
+
}
|
|
7534
|
+
},
|
|
7535
|
+
call: guarded(async (args) => {
|
|
7536
|
+
const status = await refreshDraft(core, identity, projectId);
|
|
7537
|
+
const path = str(args.path);
|
|
7538
|
+
if (path)
|
|
7539
|
+
return {
|
|
7540
|
+
path,
|
|
7541
|
+
content: await core.projects.readFile(identity, projectId, path)
|
|
7542
|
+
};
|
|
7543
|
+
const files = await core.projects.listFiles(identity, projectId);
|
|
7544
|
+
return {
|
|
7545
|
+
files: files.map((file) => file.path).sort(),
|
|
7546
|
+
...draftSummary(status)
|
|
7547
|
+
};
|
|
7548
|
+
})
|
|
7549
|
+
}, {
|
|
7550
|
+
definition: {
|
|
7551
|
+
name: "program_write",
|
|
7552
|
+
description: "Change files in your draft of the program. Nothing reaches members until program_deploy (or propose_change). Role files under .work/roles need roles:write.",
|
|
7553
|
+
inputSchema: {
|
|
7554
|
+
type: "object",
|
|
7555
|
+
properties: {
|
|
7556
|
+
changes: {
|
|
7557
|
+
type: "array",
|
|
7558
|
+
items: {
|
|
7559
|
+
type: "object",
|
|
7560
|
+
properties: {
|
|
7561
|
+
path: { type: "string" },
|
|
7562
|
+
content: { type: "string" },
|
|
7563
|
+
delete: { type: "boolean" }
|
|
7564
|
+
},
|
|
7565
|
+
required: ["path"]
|
|
7566
|
+
}
|
|
7567
|
+
}
|
|
7568
|
+
},
|
|
7569
|
+
required: ["changes"]
|
|
7570
|
+
}
|
|
7571
|
+
},
|
|
7572
|
+
call: guarded(async (args) => {
|
|
7573
|
+
const changes = Array.isArray(args.changes) ? args.changes : [];
|
|
7574
|
+
if (changes.length === 0)
|
|
7575
|
+
throw new Error("changes is required");
|
|
7576
|
+
await refreshDraft(core, identity, projectId);
|
|
7577
|
+
const draftChanges = changes.map((raw) => {
|
|
7578
|
+
const change = asRecord(raw);
|
|
7579
|
+
const path = str(change.path);
|
|
7580
|
+
if (!path)
|
|
7581
|
+
throw new Error("Each change needs a path");
|
|
7582
|
+
if (change.delete === true)
|
|
7583
|
+
return { path, delete: true };
|
|
7584
|
+
const content = str(change.content);
|
|
7585
|
+
if (content === undefined)
|
|
7586
|
+
throw new Error(`${path}: pass content or delete: true`);
|
|
7587
|
+
return { path, content };
|
|
7588
|
+
});
|
|
7589
|
+
await core.projects.writeFiles({
|
|
7590
|
+
identity,
|
|
7591
|
+
projectId,
|
|
7592
|
+
changes: draftChanges
|
|
7593
|
+
});
|
|
7594
|
+
return { written: draftChanges.map((change) => change.path) };
|
|
7595
|
+
})
|
|
7596
|
+
}, {
|
|
7597
|
+
definition: {
|
|
7598
|
+
name: "program_check",
|
|
7599
|
+
description: "Refresh your draft's generated types (the trigger kinds this server offers, in .work/workflows/src/work-triggers.d.ts, and each app's workflow API types), then validate it the way publishing does: workflow and app parse errors and trigger configurations. Run it after writing and before program_deploy.",
|
|
7600
|
+
inputSchema: { type: "object", properties: {} }
|
|
7601
|
+
},
|
|
7602
|
+
call: guarded(async () => checkDraft(core, identity, projectId))
|
|
7603
|
+
});
|
|
7604
|
+
}
|
|
7605
|
+
if (may("program:write") && may("program:publish")) {
|
|
7606
|
+
tools.push({
|
|
7607
|
+
definition: {
|
|
7608
|
+
name: "program_deploy",
|
|
7609
|
+
description: "Publish your draft as the project's production program: workflows move to it, and every app it changes (or that was never published) is built and published, with each app's result reported. Refused while program_check reports errors, and for projects whose program lives in a linked repository (use propose_change there).",
|
|
7610
|
+
inputSchema: {
|
|
7611
|
+
type: "object",
|
|
7612
|
+
properties: {
|
|
7613
|
+
message: {
|
|
7614
|
+
type: "string",
|
|
7615
|
+
description: "What changed and why, as a commit message"
|
|
7616
|
+
}
|
|
7617
|
+
},
|
|
7618
|
+
required: ["message"]
|
|
7619
|
+
}
|
|
7620
|
+
},
|
|
7621
|
+
call: guarded(async (args) => {
|
|
7622
|
+
const message = str(args.message);
|
|
7623
|
+
if (!message)
|
|
7624
|
+
throw new Error("message is required");
|
|
7625
|
+
const project = await core.projects.get(identity, projectId);
|
|
7626
|
+
if (project.remoteUrl)
|
|
7627
|
+
throw new Error(`This project's program is published from ${project.remoteUrl}. Open a pull request there, or use propose_change.`);
|
|
7628
|
+
const check = await checkDraft(core, identity, projectId);
|
|
7629
|
+
if (!check.ok)
|
|
7630
|
+
return { status: "blocked", ...check };
|
|
7631
|
+
const before = await core.deployment.getStatus(identity.tenantId, projectId, identity.externalUserId);
|
|
7632
|
+
const result = await core.deployment.deploy(identity.tenantId, projectId, identity.externalUserId, {
|
|
7633
|
+
message,
|
|
7634
|
+
guardPublishedPaths: (paths) => assertMayManageRolePolicy(identity, projectId, paths)
|
|
7635
|
+
});
|
|
7636
|
+
const published = result.status === "deployed" ? result.commitSha : result.status === "nothing-to-deploy" ? before.remoteHead : null;
|
|
7637
|
+
const apps = published ? await publishApps({
|
|
7638
|
+
core,
|
|
7639
|
+
identity,
|
|
7640
|
+
projectId,
|
|
7641
|
+
base: result.status === "deployed" ? before.remoteHead : published,
|
|
7642
|
+
head: published
|
|
7643
|
+
}) : [];
|
|
7644
|
+
return { ...result, apps, warnings: check.findings };
|
|
7645
|
+
})
|
|
7646
|
+
});
|
|
7647
|
+
}
|
|
7648
|
+
tools.push({
|
|
7649
|
+
definition: {
|
|
7650
|
+
name: "workflow_run",
|
|
7651
|
+
description: "Run a deployed workflow with an input. Waits up to 30 seconds: a finished run returns its output, a longer one returns its runId for run_details. Pass environment to choose where it runs (names in project_overview).",
|
|
7652
|
+
inputSchema: {
|
|
7653
|
+
type: "object",
|
|
7654
|
+
properties: {
|
|
7655
|
+
workflow: { type: "string" },
|
|
7656
|
+
input: {
|
|
7657
|
+
description: "The workflow's input, as JSON of the workflow's input type",
|
|
7658
|
+
type: ["object", "array", "string", "number", "boolean", "null"]
|
|
7659
|
+
},
|
|
7660
|
+
environment: { type: "string" }
|
|
7661
|
+
},
|
|
7662
|
+
required: ["workflow"]
|
|
7663
|
+
}
|
|
7664
|
+
},
|
|
7665
|
+
call: guarded(async (args) => {
|
|
7666
|
+
const workflowName = str(args.workflow);
|
|
7667
|
+
if (!workflowName)
|
|
7668
|
+
throw new Error("workflow is required");
|
|
7669
|
+
const environment = str(args.environment);
|
|
7670
|
+
return core.runs.call({
|
|
7671
|
+
identity,
|
|
7672
|
+
projectId,
|
|
7673
|
+
workflowName,
|
|
7674
|
+
...environment ? { environment } : {},
|
|
7675
|
+
...args.input === undefined ? {} : { input: args.input },
|
|
7676
|
+
budgetMs: TOOL_SYNC_BUDGET_MS
|
|
7677
|
+
});
|
|
7678
|
+
})
|
|
7679
|
+
}, {
|
|
7680
|
+
definition: {
|
|
7681
|
+
name: "workflow_runs",
|
|
7682
|
+
description: "Recent runs of the project's workflows, newest first, with status and errors. Filter by workflow.",
|
|
7683
|
+
inputSchema: {
|
|
7684
|
+
type: "object",
|
|
7685
|
+
properties: {
|
|
7686
|
+
workflow: { type: "string" },
|
|
7687
|
+
limit: { type: "integer", minimum: 1, maximum: 100 }
|
|
7688
|
+
}
|
|
7689
|
+
},
|
|
7690
|
+
annotations: READ_ONLY
|
|
7691
|
+
},
|
|
7692
|
+
call: guarded(async (args) => {
|
|
7693
|
+
const workflowName = str(args.workflow);
|
|
7694
|
+
return core.runs.list({
|
|
7695
|
+
identity,
|
|
7696
|
+
projectId,
|
|
7697
|
+
...workflowName ? { workflowName } : {},
|
|
7698
|
+
limit: typeof args.limit === "number" ? args.limit : 20
|
|
7699
|
+
});
|
|
7700
|
+
})
|
|
7701
|
+
}, {
|
|
6949
7702
|
definition: {
|
|
6950
7703
|
name: "run_details",
|
|
6951
7704
|
description: "One run in full: status, input, output, error, and each step with its result, for debugging a workflow.",
|
|
@@ -6977,7 +7730,7 @@ function overviewTool(core, identity, projectId) {
|
|
|
6977
7730
|
},
|
|
6978
7731
|
call: guarded(async () => {
|
|
6979
7732
|
const optional = (load) => load().catch((error) => {
|
|
6980
|
-
if (error instanceof
|
|
7733
|
+
if (error instanceof AccessDeniedError8)
|
|
6981
7734
|
return;
|
|
6982
7735
|
throw error;
|
|
6983
7736
|
});
|
|
@@ -7118,7 +7871,7 @@ function guarded(fn) {
|
|
|
7118
7871
|
try {
|
|
7119
7872
|
return toolValue(await fn(args));
|
|
7120
7873
|
} catch (error) {
|
|
7121
|
-
if (error instanceof
|
|
7874
|
+
if (error instanceof AccessDeniedError8)
|
|
7122
7875
|
return toolError2("Your roles do not allow that.");
|
|
7123
7876
|
const code = typeof error === "object" && error !== null && "code" in error ? error.code : undefined;
|
|
7124
7877
|
if (code === "ENOENT")
|
|
@@ -7170,7 +7923,7 @@ import {
|
|
|
7170
7923
|
setSessionMetadataInputSchema
|
|
7171
7924
|
} from "@catamorphic/agent-protocol";
|
|
7172
7925
|
import {
|
|
7173
|
-
AccessDeniedError as
|
|
7926
|
+
AccessDeniedError as AccessDeniedError9,
|
|
7174
7927
|
AgentTurnUnsettledError,
|
|
7175
7928
|
EVERY_ARTIFACT,
|
|
7176
7929
|
mayUseProject as mayUseProject2,
|
|
@@ -7179,22 +7932,22 @@ import {
|
|
|
7179
7932
|
resolveScope,
|
|
7180
7933
|
SESSION_ACTION_SCHEMAS
|
|
7181
7934
|
} from "@catamorphic/core";
|
|
7182
|
-
import { z as
|
|
7935
|
+
import { z as z19 } from "zod";
|
|
7183
7936
|
|
|
7184
7937
|
// src/app-presentation-tools.ts
|
|
7185
|
-
import { APP_ICON_DESCRIPTIONS, APP_ICON_NAMES as
|
|
7186
|
-
import { z as
|
|
7187
|
-
var Input =
|
|
7188
|
-
appName:
|
|
7189
|
-
icon:
|
|
7190
|
-
title:
|
|
7938
|
+
import { APP_ICON_DESCRIPTIONS, APP_ICON_NAMES as APP_ICON_NAMES4 } from "@catamorphic/app";
|
|
7939
|
+
import { z as z17 } from "zod";
|
|
7940
|
+
var Input = z17.object({
|
|
7941
|
+
appName: z17.string().min(1),
|
|
7942
|
+
icon: z17.enum(APP_ICON_NAMES4).optional(),
|
|
7943
|
+
title: z17.string().trim().min(1).max(200).optional()
|
|
7191
7944
|
}).refine((value) => value.icon !== undefined || value.title !== undefined, "Supply a title or icon");
|
|
7192
7945
|
function appPresentationTool(core, identity, projectId) {
|
|
7193
7946
|
return {
|
|
7194
7947
|
definition: {
|
|
7195
7948
|
name: "set_app_presentation",
|
|
7196
|
-
description: `Set an app's title and/or canonical icon without rebuilding or publishing. Use a short, descriptive title that names what the app does or contains. Match the language of the task, avoid generic labels like Session app, and keep the title stable through revisions. There is no required title template. Use the returned appName for temporary apps, not their display title. All reviews use review. Choose default when in doubt; never infer a specialized type just from a filename. Choices: ${
|
|
7197
|
-
inputSchema:
|
|
7949
|
+
description: `Set an app's title and/or canonical icon without rebuilding or publishing. Use a short, descriptive title that names what the app does or contains. Match the language of the task, avoid generic labels like Session app, and keep the title stable through revisions. There is no required title template. Use the returned appName for temporary apps, not their display title. All reviews use review. Choose default when in doubt; never infer a specialized type just from a filename. Choices: ${APP_ICON_NAMES4.map((name) => `${name}: ${APP_ICON_DESCRIPTIONS[name]}`).join("; ")}.`,
|
|
7950
|
+
inputSchema: z17.toJSONSchema(Input)
|
|
7198
7951
|
},
|
|
7199
7952
|
call: async (raw) => {
|
|
7200
7953
|
try {
|
|
@@ -7213,28 +7966,28 @@ function appPresentationTool(core, identity, projectId) {
|
|
|
7213
7966
|
}
|
|
7214
7967
|
|
|
7215
7968
|
// src/session-artifact-tools.ts
|
|
7216
|
-
import { APP_ICON_NAMES as
|
|
7217
|
-
import { z as
|
|
7218
|
-
var Input2 =
|
|
7219
|
-
action:
|
|
7220
|
-
sessionId:
|
|
7221
|
-
artifactId:
|
|
7222
|
-
kind:
|
|
7223
|
-
name:
|
|
7224
|
-
title:
|
|
7225
|
-
icon:
|
|
7226
|
-
source:
|
|
7227
|
-
files:
|
|
7228
|
-
revision:
|
|
7229
|
-
environment:
|
|
7230
|
-
input:
|
|
7969
|
+
import { APP_ICON_NAMES as APP_ICON_NAMES5 } from "@catamorphic/app";
|
|
7970
|
+
import { z as z18 } from "zod";
|
|
7971
|
+
var Input2 = z18.object({
|
|
7972
|
+
action: z18.enum(["create", "list", "read", "update", "discard", "run"]),
|
|
7973
|
+
sessionId: z18.string().uuid().optional(),
|
|
7974
|
+
artifactId: z18.string().uuid().optional(),
|
|
7975
|
+
kind: z18.enum(["app", "workflow"]).optional(),
|
|
7976
|
+
name: z18.string().max(100).optional(),
|
|
7977
|
+
title: z18.string().max(200).optional(),
|
|
7978
|
+
icon: z18.enum(APP_ICON_NAMES5).optional(),
|
|
7979
|
+
source: z18.string().optional(),
|
|
7980
|
+
files: z18.record(z18.string(), z18.string().nullable()).optional(),
|
|
7981
|
+
revision: z18.number().int().positive().optional(),
|
|
7982
|
+
environment: z18.string().optional(),
|
|
7983
|
+
input: z18.json().optional()
|
|
7231
7984
|
});
|
|
7232
7985
|
function sessionArtifactTool(core, identity, projectId, currentSessionId) {
|
|
7233
7986
|
return {
|
|
7234
7987
|
definition: {
|
|
7235
7988
|
name: "session_artifact",
|
|
7236
7989
|
description: "Create, read, update, run or discard a temporary app or workflow owned by this session. Load the session-artifacts skill first. App source is a React component exporting default; the host supplies the standard app scaffold and builds it immediately. Additional files use ordinary workspace paths and may include shared components, dependencies and helper workflows. Workflow source is an ordinary exported defineWorkflow. No files are added to the user's checkout. Results survive closing tabs and remain available with the chat. Update requires the revision returned by read; files are explicit changed paths. Apps return their ordinary app:<appName> target. Creating a workflow does not run or enable it; use run for a one-off invocation, and the watcher tool for temporary scheduled activation. Discard prevents new use. Saving reusable work into the project is a separate selected-file change.",
|
|
7237
|
-
inputSchema:
|
|
7990
|
+
inputSchema: z18.toJSONSchema(Input2)
|
|
7238
7991
|
},
|
|
7239
7992
|
call: async (raw) => {
|
|
7240
7993
|
try {
|
|
@@ -7374,7 +8127,7 @@ function surfaceTools(core, identity, projectId, features = { publications: "pub
|
|
|
7374
8127
|
try {
|
|
7375
8128
|
return toolValue(await fn(args));
|
|
7376
8129
|
} catch (error) {
|
|
7377
|
-
if (error instanceof
|
|
8130
|
+
if (error instanceof AccessDeniedError9) {
|
|
7378
8131
|
return toolError2("Not authorized for that path or agent.");
|
|
7379
8132
|
}
|
|
7380
8133
|
return toolError2(error instanceof Error ? error.message : String(error));
|
|
@@ -7759,7 +8512,7 @@ function surfaceTools(core, identity, projectId, features = { publications: "pub
|
|
|
7759
8512
|
definition: {
|
|
7760
8513
|
name: "set_session_metadata",
|
|
7761
8514
|
description: SET_SESSION_METADATA_DESCRIPTION,
|
|
7762
|
-
inputSchema:
|
|
8515
|
+
inputSchema: z19.toJSONSchema(setSessionMetadataInputSchema)
|
|
7763
8516
|
},
|
|
7764
8517
|
call: guarded(async (args) => {
|
|
7765
8518
|
const values = sessionMetadataToolWrite(args);
|
|
@@ -7837,7 +8590,7 @@ function surfaceTools(core, identity, projectId, features = { publications: "pub
|
|
|
7837
8590
|
definition: {
|
|
7838
8591
|
name: `session_${operation}`,
|
|
7839
8592
|
description: `Session ${operation}. Uses the same authorized operation as workflows. Name the chat by sessionId, or by the project's key for it (key, with audience "project" for the project chat). Mutations require a stable idempotencyKey; retries return the existing result. Load the session-workflows skill for examples.`,
|
|
7840
|
-
inputSchema:
|
|
8593
|
+
inputSchema: z19.toJSONSchema(SESSION_ACTION_SCHEMAS[operation])
|
|
7841
8594
|
},
|
|
7842
8595
|
call: guarded(async (args) => {
|
|
7843
8596
|
const source = currentSessionId ? await sessions.get(identity, projectId, currentSessionId) : undefined;
|
|
@@ -8047,7 +8800,7 @@ function registerProjectMcpRoutes(app, ctx) {
|
|
|
8047
8800
|
...gatewayTools.map((tool) => ({
|
|
8048
8801
|
name: tool.name,
|
|
8049
8802
|
description: tool.description,
|
|
8050
|
-
inputSchema:
|
|
8803
|
+
inputSchema: z20.toJSONSchema(z20.object(tool.parameters))
|
|
8051
8804
|
})),
|
|
8052
8805
|
...tools.filter((tool) => !gatewayTools.some((gateway) => gateway.name === tool.name)).map(toolDefinition),
|
|
8053
8806
|
...tools.length > 0 || core.mcpToolKinds.length > 0 ? [POLL_RUN_TOOL_DEFINITION] : [],
|
|
@@ -8213,7 +8966,7 @@ import {
|
|
|
8213
8966
|
ProjectFileNotTextError,
|
|
8214
8967
|
ProjectNotFoundError as ProjectNotFoundError8
|
|
8215
8968
|
} from "@catamorphic/core";
|
|
8216
|
-
import { z as
|
|
8969
|
+
import { z as z21 } from "zod";
|
|
8217
8970
|
function toDto(project) {
|
|
8218
8971
|
return {
|
|
8219
8972
|
id: project.id,
|
|
@@ -8326,7 +9079,7 @@ function registerProjectRoutes(app, ctx) {
|
|
|
8326
9079
|
schema: {
|
|
8327
9080
|
params: ProjectIdParamsSchema,
|
|
8328
9081
|
response: {
|
|
8329
|
-
200:
|
|
9082
|
+
200: z21.object({ deleted: z21.boolean() }),
|
|
8330
9083
|
404: ErrorSchema,
|
|
8331
9084
|
503: ErrorSchema
|
|
8332
9085
|
}
|
|
@@ -8534,9 +9287,9 @@ function registerProjectRoutes(app, ctx) {
|
|
|
8534
9287
|
url: "/projects/:projectId/diff",
|
|
8535
9288
|
schema: {
|
|
8536
9289
|
params: ProjectIdParamsSchema,
|
|
8537
|
-
querystring:
|
|
8538
|
-
base:
|
|
8539
|
-
head:
|
|
9290
|
+
querystring: z21.object({
|
|
9291
|
+
base: z21.string().min(1),
|
|
9292
|
+
head: z21.string().min(1)
|
|
8540
9293
|
}),
|
|
8541
9294
|
response: {
|
|
8542
9295
|
200: DiffEntrySchema.array(),
|
|
@@ -8667,7 +9420,7 @@ function registerProjectRoutes(app, ctx) {
|
|
|
8667
9420
|
params: ProjectIdParamsSchema,
|
|
8668
9421
|
body: ResolveConflictsSchema,
|
|
8669
9422
|
response: {
|
|
8670
|
-
200:
|
|
9423
|
+
200: z21.object({ commitSha: z21.string() }),
|
|
8671
9424
|
404: ErrorSchema,
|
|
8672
9425
|
503: ErrorSchema
|
|
8673
9426
|
}
|
|
@@ -8698,18 +9451,18 @@ function registerProjectRoutes(app, ctx) {
|
|
|
8698
9451
|
url: "/projects/:projectId/ai-resolve-conflicts",
|
|
8699
9452
|
schema: {
|
|
8700
9453
|
params: ProjectIdParamsSchema,
|
|
8701
|
-
body:
|
|
8702
|
-
conflicts:
|
|
8703
|
-
path:
|
|
8704
|
-
base:
|
|
8705
|
-
ours:
|
|
8706
|
-
theirs:
|
|
9454
|
+
body: z21.object({
|
|
9455
|
+
conflicts: z21.array(z21.object({
|
|
9456
|
+
path: z21.string(),
|
|
9457
|
+
base: z21.string().nullable(),
|
|
9458
|
+
ours: z21.string().nullable(),
|
|
9459
|
+
theirs: z21.string().nullable()
|
|
8707
9460
|
}))
|
|
8708
9461
|
}),
|
|
8709
9462
|
response: {
|
|
8710
|
-
200:
|
|
8711
|
-
resolutions:
|
|
8712
|
-
notes:
|
|
9463
|
+
200: z21.object({
|
|
9464
|
+
resolutions: z21.record(z21.string(), z21.string()),
|
|
9465
|
+
notes: z21.string().optional()
|
|
8713
9466
|
}),
|
|
8714
9467
|
503: ErrorSchema
|
|
8715
9468
|
}
|
|
@@ -8732,9 +9485,9 @@ function registerProjectRoutes(app, ctx) {
|
|
|
8732
9485
|
url: "/projects/:projectId/files-at-ref",
|
|
8733
9486
|
schema: {
|
|
8734
9487
|
params: ProjectIdParamsSchema,
|
|
8735
|
-
querystring: RefQuerySchema.extend({ ref:
|
|
9488
|
+
querystring: RefQuerySchema.extend({ ref: z21.string().min(1) }),
|
|
8736
9489
|
response: {
|
|
8737
|
-
200:
|
|
9490
|
+
200: z21.record(z21.string(), z21.string()),
|
|
8738
9491
|
404: ErrorSchema,
|
|
8739
9492
|
503: ErrorSchema
|
|
8740
9493
|
}
|
|
@@ -8771,14 +9524,14 @@ async function safeListWorkflows(core, identity, projectId) {
|
|
|
8771
9524
|
|
|
8772
9525
|
// src/routes/publications.ts
|
|
8773
9526
|
import {
|
|
8774
|
-
DocumentNotFoundError as
|
|
8775
|
-
DocumentPathError as
|
|
9527
|
+
DocumentNotFoundError as DocumentNotFoundError3,
|
|
9528
|
+
DocumentPathError as DocumentPathError3,
|
|
8776
9529
|
ProjectNotFoundError as ProjectNotFoundError9,
|
|
8777
9530
|
PublicationNotFoundError,
|
|
8778
9531
|
PublicationSlugError,
|
|
8779
9532
|
PublicationSlugTakenError
|
|
8780
9533
|
} from "@catamorphic/core";
|
|
8781
|
-
import { z as
|
|
9534
|
+
import { z as z22 } from "zod";
|
|
8782
9535
|
function registerPublicationRoutes(app, ctx) {
|
|
8783
9536
|
const typed = app.withTypeProvider();
|
|
8784
9537
|
const core = () => {
|
|
@@ -8800,7 +9553,7 @@ function registerPublicationRoutes(app, ctx) {
|
|
|
8800
9553
|
if (err instanceof PublicationNotFoundError) {
|
|
8801
9554
|
return reply.status(404).send({ error: err.message });
|
|
8802
9555
|
}
|
|
8803
|
-
if (err instanceof
|
|
9556
|
+
if (err instanceof DocumentPathError3 || err instanceof PublicationSlugError) {
|
|
8804
9557
|
return reply.status(400).send({ error: err.message });
|
|
8805
9558
|
}
|
|
8806
9559
|
if (err instanceof PublicationSlugTakenError) {
|
|
@@ -8867,7 +9620,7 @@ function registerPublicationRoutes(app, ctx) {
|
|
|
8867
9620
|
url: "/projects/:projectId/publications/:slug",
|
|
8868
9621
|
schema: {
|
|
8869
9622
|
params: PublicationParamsSchema,
|
|
8870
|
-
response: { 204:
|
|
9623
|
+
response: { 204: z22.null(), 404: ErrorSchema }
|
|
8871
9624
|
},
|
|
8872
9625
|
handler: async (request, reply) => {
|
|
8873
9626
|
try {
|
|
@@ -8903,7 +9656,7 @@ function registerPublicationRoutes(app, ctx) {
|
|
|
8903
9656
|
}
|
|
8904
9657
|
return reply.send(Buffer.from(doc.bytes));
|
|
8905
9658
|
} catch (err) {
|
|
8906
|
-
if (err instanceof
|
|
9659
|
+
if (err instanceof DocumentNotFoundError3 || err instanceof DocumentPathError3) {
|
|
8907
9660
|
return reply.status(404).send({ error: "Not found" });
|
|
8908
9661
|
}
|
|
8909
9662
|
throw err;
|
|
@@ -8939,7 +9692,7 @@ import {
|
|
|
8939
9692
|
RunPauseNotFoundError,
|
|
8940
9693
|
RunResumeConflictError
|
|
8941
9694
|
} from "@catamorphic/core";
|
|
8942
|
-
import { z as
|
|
9695
|
+
import { z as z23 } from "zod";
|
|
8943
9696
|
function registerRunRoutes(app, ctx) {
|
|
8944
9697
|
const typed = app.withTypeProvider();
|
|
8945
9698
|
typed.route({
|
|
@@ -9107,7 +9860,7 @@ function registerRunRoutes(app, ctx) {
|
|
|
9107
9860
|
schema: {
|
|
9108
9861
|
params: RunItemParamsSchema,
|
|
9109
9862
|
response: {
|
|
9110
|
-
200:
|
|
9863
|
+
200: z23.array(BatchItemStepSchema),
|
|
9111
9864
|
404: ErrorSchema,
|
|
9112
9865
|
409: ErrorSchema,
|
|
9113
9866
|
503: ErrorSchema
|
|
@@ -9136,279 +9889,7 @@ function handleRunError(args) {
|
|
|
9136
9889
|
if (args.error instanceof RunCapabilityError2 || args.error instanceof RunResumeConflictError) {
|
|
9137
9890
|
return args.reply.status(409).send({ error: args.error.message });
|
|
9138
9891
|
}
|
|
9139
|
-
throw args.error;
|
|
9140
|
-
}
|
|
9141
|
-
|
|
9142
|
-
// src/routes/session-artifacts.ts
|
|
9143
|
-
import { APP_ICON_NAMES as APP_ICON_NAMES5 } from "@catamorphic/app";
|
|
9144
|
-
import { SessionArtifactNotFoundError } from "@catamorphic/core";
|
|
9145
|
-
import { z as z21 } from "zod";
|
|
9146
|
-
var SessionArtifactSchema = z21.object({
|
|
9147
|
-
id: z21.string().uuid(),
|
|
9148
|
-
projectId: z21.string().uuid(),
|
|
9149
|
-
sessionId: z21.string().uuid().nullable(),
|
|
9150
|
-
kind: z21.enum(["app", "workflow"]),
|
|
9151
|
-
name: z21.string(),
|
|
9152
|
-
title: z21.string(),
|
|
9153
|
-
sourcePath: z21.string(),
|
|
9154
|
-
remoteBranch: z21.string(),
|
|
9155
|
-
commitSha: z21.string(),
|
|
9156
|
-
revision: z21.number().int(),
|
|
9157
|
-
status: z21.enum(["active", "discarded"]),
|
|
9158
|
-
appName: z21.string().nullable(),
|
|
9159
|
-
createdAt: z21.string(),
|
|
9160
|
-
updatedAt: z21.string()
|
|
9161
|
-
});
|
|
9162
|
-
var SessionParams = z21.object({
|
|
9163
|
-
projectId: z21.string().uuid(),
|
|
9164
|
-
sessionId: z21.string().uuid()
|
|
9165
|
-
});
|
|
9166
|
-
var ArtifactParams = z21.object({
|
|
9167
|
-
projectId: z21.string().uuid(),
|
|
9168
|
-
artifactId: z21.string().uuid()
|
|
9169
|
-
});
|
|
9170
|
-
var Files = z21.record(z21.string().min(1).max(512), z21.string()).refine((files) => Object.keys(files).length <= 256);
|
|
9171
|
-
var Outcome = z21.object({
|
|
9172
|
-
artifact: SessionArtifactSchema,
|
|
9173
|
-
build: AppVersionSchema.nullable()
|
|
9174
|
-
});
|
|
9175
|
-
function registerSessionArtifactRoutes(app, ctx) {
|
|
9176
|
-
const typed = app.withTypeProvider();
|
|
9177
|
-
typed.route({
|
|
9178
|
-
method: "GET",
|
|
9179
|
-
url: "/projects/:projectId/agent/sessions/:sessionId/artifacts",
|
|
9180
|
-
schema: {
|
|
9181
|
-
params: SessionParams,
|
|
9182
|
-
response: {
|
|
9183
|
-
200: z21.array(SessionArtifactSchema),
|
|
9184
|
-
400: ErrorSchema,
|
|
9185
|
-
403: ErrorSchema,
|
|
9186
|
-
404: ErrorSchema,
|
|
9187
|
-
409: ErrorSchema,
|
|
9188
|
-
503: ErrorSchema
|
|
9189
|
-
}
|
|
9190
|
-
},
|
|
9191
|
-
handler: async (request, reply) => {
|
|
9192
|
-
if (!ctx.core)
|
|
9193
|
-
return reply.status(503).send({ error: "Artifacts are unavailable" });
|
|
9194
|
-
return ctx.core.sessionArtifacts.list({
|
|
9195
|
-
...request.params,
|
|
9196
|
-
identity: resolveIdentity(request)
|
|
9197
|
-
});
|
|
9198
|
-
}
|
|
9199
|
-
});
|
|
9200
|
-
typed.route({
|
|
9201
|
-
method: "POST",
|
|
9202
|
-
url: "/projects/:projectId/agent/sessions/:sessionId/artifacts",
|
|
9203
|
-
bodyLimit: 6 * 1024 * 1024,
|
|
9204
|
-
schema: {
|
|
9205
|
-
params: SessionParams,
|
|
9206
|
-
body: z21.object({
|
|
9207
|
-
kind: z21.enum(["app", "workflow"]),
|
|
9208
|
-
name: z21.string().min(1).max(100),
|
|
9209
|
-
title: z21.string().max(200).optional(),
|
|
9210
|
-
icon: z21.enum(APP_ICON_NAMES5).optional(),
|
|
9211
|
-
source: z21.string().max(5 * 1024 * 1024),
|
|
9212
|
-
files: Files.optional()
|
|
9213
|
-
}),
|
|
9214
|
-
response: {
|
|
9215
|
-
201: Outcome,
|
|
9216
|
-
400: ErrorSchema,
|
|
9217
|
-
403: ErrorSchema,
|
|
9218
|
-
404: ErrorSchema,
|
|
9219
|
-
409: ErrorSchema,
|
|
9220
|
-
503: ErrorSchema
|
|
9221
|
-
}
|
|
9222
|
-
},
|
|
9223
|
-
handler: async (request, reply) => {
|
|
9224
|
-
if (!ctx.core || request.body.kind === "app" && !ctx.core.apps)
|
|
9225
|
-
return reply.status(503).send({ error: "Artifacts are unavailable" });
|
|
9226
|
-
const identity = resolveIdentity(request);
|
|
9227
|
-
const artifact = await ctx.core.sessionArtifacts.create({
|
|
9228
|
-
...request.params,
|
|
9229
|
-
...request.body,
|
|
9230
|
-
identity
|
|
9231
|
-
});
|
|
9232
|
-
const build = artifact.appName && ctx.core.apps ? await ctx.core.apps.build({
|
|
9233
|
-
identity,
|
|
9234
|
-
projectId: artifact.projectId,
|
|
9235
|
-
appName: artifact.appName,
|
|
9236
|
-
artifactId: artifact.id,
|
|
9237
|
-
kind: "preview"
|
|
9238
|
-
}) : null;
|
|
9239
|
-
if (artifact.appName && request.body.icon && ctx.core.apps)
|
|
9240
|
-
await ctx.core.apps.updatePresentation({
|
|
9241
|
-
identity,
|
|
9242
|
-
projectId: artifact.projectId,
|
|
9243
|
-
appName: artifact.appName,
|
|
9244
|
-
icon: request.body.icon
|
|
9245
|
-
});
|
|
9246
|
-
return reply.status(201).send({ artifact, build });
|
|
9247
|
-
}
|
|
9248
|
-
});
|
|
9249
|
-
typed.route({
|
|
9250
|
-
method: "GET",
|
|
9251
|
-
url: "/projects/:projectId/session-artifacts/:artifactId",
|
|
9252
|
-
schema: {
|
|
9253
|
-
params: ArtifactParams,
|
|
9254
|
-
response: {
|
|
9255
|
-
200: SessionArtifactSchema,
|
|
9256
|
-
400: ErrorSchema,
|
|
9257
|
-
403: ErrorSchema,
|
|
9258
|
-
404: ErrorSchema,
|
|
9259
|
-
409: ErrorSchema,
|
|
9260
|
-
503: ErrorSchema
|
|
9261
|
-
}
|
|
9262
|
-
},
|
|
9263
|
-
handler: async (request, reply) => {
|
|
9264
|
-
if (!ctx.core)
|
|
9265
|
-
return reply.status(503).send({ error: "Artifacts are unavailable" });
|
|
9266
|
-
try {
|
|
9267
|
-
return await ctx.core.sessionArtifacts.get({
|
|
9268
|
-
...request.params,
|
|
9269
|
-
identity: resolveIdentity(request)
|
|
9270
|
-
});
|
|
9271
|
-
} catch (error) {
|
|
9272
|
-
if (error instanceof SessionArtifactNotFoundError)
|
|
9273
|
-
return reply.status(404).send({ error: error.message });
|
|
9274
|
-
throw error;
|
|
9275
|
-
}
|
|
9276
|
-
}
|
|
9277
|
-
});
|
|
9278
|
-
typed.route({
|
|
9279
|
-
method: "GET",
|
|
9280
|
-
url: "/projects/:projectId/session-artifacts/:artifactId/files",
|
|
9281
|
-
schema: {
|
|
9282
|
-
params: ArtifactParams,
|
|
9283
|
-
response: {
|
|
9284
|
-
200: z21.record(z21.string(), z21.string()),
|
|
9285
|
-
400: ErrorSchema,
|
|
9286
|
-
403: ErrorSchema,
|
|
9287
|
-
404: ErrorSchema,
|
|
9288
|
-
409: ErrorSchema,
|
|
9289
|
-
503: ErrorSchema
|
|
9290
|
-
}
|
|
9291
|
-
},
|
|
9292
|
-
handler: async (request, reply) => {
|
|
9293
|
-
if (!ctx.core)
|
|
9294
|
-
return reply.status(503).send({ error: "Artifacts are unavailable" });
|
|
9295
|
-
return ctx.core.sessionArtifacts.files({
|
|
9296
|
-
...request.params,
|
|
9297
|
-
identity: resolveIdentity(request)
|
|
9298
|
-
});
|
|
9299
|
-
}
|
|
9300
|
-
});
|
|
9301
|
-
typed.route({
|
|
9302
|
-
method: "PATCH",
|
|
9303
|
-
url: "/projects/:projectId/session-artifacts/:artifactId",
|
|
9304
|
-
bodyLimit: 6 * 1024 * 1024,
|
|
9305
|
-
schema: {
|
|
9306
|
-
params: ArtifactParams,
|
|
9307
|
-
body: z21.object({
|
|
9308
|
-
revision: z21.number().int().positive(),
|
|
9309
|
-
title: z21.string().max(200).optional(),
|
|
9310
|
-
files: z21.record(z21.string().min(1).max(512), z21.string().nullable())
|
|
9311
|
-
}),
|
|
9312
|
-
response: {
|
|
9313
|
-
200: Outcome,
|
|
9314
|
-
400: ErrorSchema,
|
|
9315
|
-
403: ErrorSchema,
|
|
9316
|
-
404: ErrorSchema,
|
|
9317
|
-
409: ErrorSchema,
|
|
9318
|
-
503: ErrorSchema
|
|
9319
|
-
}
|
|
9320
|
-
},
|
|
9321
|
-
handler: async (request, reply) => {
|
|
9322
|
-
if (!ctx.core)
|
|
9323
|
-
return reply.status(503).send({ error: "Artifacts are unavailable" });
|
|
9324
|
-
const identity = resolveIdentity(request);
|
|
9325
|
-
const artifact = await ctx.core.sessionArtifacts.update({
|
|
9326
|
-
...request.params,
|
|
9327
|
-
...request.body,
|
|
9328
|
-
identity
|
|
9329
|
-
});
|
|
9330
|
-
const build = artifact.appName && ctx.core.apps ? await ctx.core.apps.build({
|
|
9331
|
-
identity,
|
|
9332
|
-
projectId: artifact.projectId,
|
|
9333
|
-
appName: artifact.appName,
|
|
9334
|
-
artifactId: artifact.id,
|
|
9335
|
-
kind: "preview"
|
|
9336
|
-
}) : null;
|
|
9337
|
-
return { artifact, build };
|
|
9338
|
-
}
|
|
9339
|
-
});
|
|
9340
|
-
typed.route({
|
|
9341
|
-
method: "DELETE",
|
|
9342
|
-
url: "/projects/:projectId/session-artifacts/:artifactId",
|
|
9343
|
-
schema: {
|
|
9344
|
-
params: ArtifactParams,
|
|
9345
|
-
response: {
|
|
9346
|
-
204: z21.null(),
|
|
9347
|
-
400: ErrorSchema,
|
|
9348
|
-
403: ErrorSchema,
|
|
9349
|
-
404: ErrorSchema,
|
|
9350
|
-
409: ErrorSchema,
|
|
9351
|
-
503: ErrorSchema
|
|
9352
|
-
}
|
|
9353
|
-
},
|
|
9354
|
-
handler: async (request, reply) => {
|
|
9355
|
-
if (!ctx.core)
|
|
9356
|
-
return reply.status(503).send({ error: "Artifacts are unavailable" });
|
|
9357
|
-
const identity = resolveIdentity(request);
|
|
9358
|
-
const artifact = await ctx.core.sessionArtifacts.discard({
|
|
9359
|
-
...request.params,
|
|
9360
|
-
identity
|
|
9361
|
-
});
|
|
9362
|
-
if (artifact.sessionId && ctx.core.watchers)
|
|
9363
|
-
await ctx.core.watchers.stop({
|
|
9364
|
-
identity,
|
|
9365
|
-
projectId: artifact.projectId,
|
|
9366
|
-
sessionId: artifact.sessionId,
|
|
9367
|
-
watcherId: artifact.id
|
|
9368
|
-
});
|
|
9369
|
-
return reply.status(204).send(null);
|
|
9370
|
-
}
|
|
9371
|
-
});
|
|
9372
|
-
typed.route({
|
|
9373
|
-
method: "POST",
|
|
9374
|
-
url: "/projects/:projectId/session-artifacts/:artifactId/runs",
|
|
9375
|
-
schema: {
|
|
9376
|
-
params: ArtifactParams,
|
|
9377
|
-
body: TriggerRunSchema.extend({ environment: z21.string().optional() }),
|
|
9378
|
-
response: {
|
|
9379
|
-
201: RunSchema,
|
|
9380
|
-
400: ErrorSchema,
|
|
9381
|
-
403: ErrorSchema,
|
|
9382
|
-
404: ErrorSchema,
|
|
9383
|
-
409: ErrorSchema,
|
|
9384
|
-
503: ErrorSchema
|
|
9385
|
-
}
|
|
9386
|
-
},
|
|
9387
|
-
handler: async (request, reply) => {
|
|
9388
|
-
if (!ctx.core)
|
|
9389
|
-
return reply.status(503).send({ error: "Artifacts are unavailable" });
|
|
9390
|
-
const identity = resolveIdentity(request);
|
|
9391
|
-
const artifact = await ctx.core.sessionArtifacts.get({
|
|
9392
|
-
...request.params,
|
|
9393
|
-
identity
|
|
9394
|
-
});
|
|
9395
|
-
if (artifact.kind !== "workflow")
|
|
9396
|
-
return reply.status(400).send({ error: "This artifact is an app" });
|
|
9397
|
-
await ctx.core.sessionArtifacts.assertActive({
|
|
9398
|
-
...request.params,
|
|
9399
|
-
identity
|
|
9400
|
-
});
|
|
9401
|
-
const run = await ctx.core.runs.triggerAtCommit({
|
|
9402
|
-
...request.body,
|
|
9403
|
-
identity,
|
|
9404
|
-
projectId: artifact.projectId,
|
|
9405
|
-
workflowName: artifact.name,
|
|
9406
|
-
commitSha: artifact.commitSha,
|
|
9407
|
-
remoteBranch: artifact.remoteBranch
|
|
9408
|
-
});
|
|
9409
|
-
return reply.status(201).send(run);
|
|
9410
|
-
}
|
|
9411
|
-
});
|
|
9892
|
+
throw args.error;
|
|
9412
9893
|
}
|
|
9413
9894
|
|
|
9414
9895
|
// src/routes/session-mailboxes.ts
|
|
@@ -9470,9 +9951,9 @@ import {
|
|
|
9470
9951
|
// src/routes/session-terminals.ts
|
|
9471
9952
|
import {
|
|
9472
9953
|
AgentSessionNotFoundError as AgentSessionNotFoundError2,
|
|
9473
|
-
EnvironmentBindingUnavailableError as
|
|
9954
|
+
EnvironmentBindingUnavailableError as EnvironmentBindingUnavailableError5,
|
|
9474
9955
|
EnvironmentCapacityError as EnvironmentCapacityError4,
|
|
9475
|
-
EnvironmentNotFoundError as
|
|
9956
|
+
EnvironmentNotFoundError as EnvironmentNotFoundError5,
|
|
9476
9957
|
SessionTerminalNotFoundError,
|
|
9477
9958
|
SessionTerminalSecretsError,
|
|
9478
9959
|
SessionWorkspaceUnavailableError
|
|
@@ -9487,7 +9968,7 @@ function workspaceRefusal(reply, error) {
|
|
|
9487
9968
|
return reply.status(409).send({ error: error.message, code: error.reason });
|
|
9488
9969
|
if (error instanceof EnvironmentCapacityError4)
|
|
9489
9970
|
return reply.status(409).send({ error: error.message, code: "environment_full" });
|
|
9490
|
-
if (error instanceof
|
|
9971
|
+
if (error instanceof EnvironmentBindingUnavailableError5 || error instanceof EnvironmentNotFoundError5)
|
|
9491
9972
|
return reply.status(409).send({ error: error.message, code: "environment_unavailable" });
|
|
9492
9973
|
return;
|
|
9493
9974
|
}
|
|
@@ -9837,13 +10318,13 @@ import {
|
|
|
9837
10318
|
WebhookRejectedError,
|
|
9838
10319
|
WebhookTooLargeError
|
|
9839
10320
|
} from "@catamorphic/core";
|
|
9840
|
-
import { z as
|
|
9841
|
-
var WebhookSchema =
|
|
9842
|
-
name:
|
|
9843
|
-
url:
|
|
9844
|
-
workflows:
|
|
9845
|
-
listening:
|
|
9846
|
-
verified:
|
|
10321
|
+
import { z as z24 } from "zod";
|
|
10322
|
+
var WebhookSchema = z24.object({
|
|
10323
|
+
name: z24.string(),
|
|
10324
|
+
url: z24.string(),
|
|
10325
|
+
workflows: z24.array(z24.string()),
|
|
10326
|
+
listening: z24.boolean(),
|
|
10327
|
+
verified: z24.boolean()
|
|
9847
10328
|
});
|
|
9848
10329
|
function registerWebhookRoutes(app, ctx) {
|
|
9849
10330
|
const typed = app.withTypeProvider();
|
|
@@ -9858,14 +10339,14 @@ function registerWebhookRoutes(app, ctx) {
|
|
|
9858
10339
|
config: { public: true },
|
|
9859
10340
|
bodyLimit: hostMaxBytes,
|
|
9860
10341
|
schema: {
|
|
9861
|
-
params:
|
|
9862
|
-
projectId:
|
|
9863
|
-
name:
|
|
9864
|
-
token:
|
|
10342
|
+
params: z24.object({
|
|
10343
|
+
projectId: z24.string().uuid(),
|
|
10344
|
+
name: z24.string().min(1).max(63),
|
|
10345
|
+
token: z24.string().min(1).max(200)
|
|
9865
10346
|
}),
|
|
9866
10347
|
response: {
|
|
9867
|
-
200:
|
|
9868
|
-
202:
|
|
10348
|
+
200: z24.string(),
|
|
10349
|
+
202: z24.object({ id: z24.string(), duplicate: z24.boolean() }),
|
|
9869
10350
|
401: ErrorSchema,
|
|
9870
10351
|
404: ErrorSchema,
|
|
9871
10352
|
405: ErrorSchema,
|
|
@@ -9907,7 +10388,7 @@ function registerWebhookRoutes(app, ctx) {
|
|
|
9907
10388
|
url: "/projects/:projectId/webhooks",
|
|
9908
10389
|
schema: {
|
|
9909
10390
|
params: ProjectIdParamsSchema,
|
|
9910
|
-
response: { 200:
|
|
10391
|
+
response: { 200: z24.array(WebhookSchema), 503: ErrorSchema }
|
|
9911
10392
|
},
|
|
9912
10393
|
handler: async (request, reply) => {
|
|
9913
10394
|
const webhooks = ctx.core?.webhooks;
|
|
@@ -9928,7 +10409,7 @@ function registerWebhookRoutes(app, ctx) {
|
|
|
9928
10409
|
method: "POST",
|
|
9929
10410
|
url: "/projects/:projectId/webhooks/:name/rotate",
|
|
9930
10411
|
schema: {
|
|
9931
|
-
params: ProjectIdParamsSchema.extend({ name:
|
|
10412
|
+
params: ProjectIdParamsSchema.extend({ name: z24.string().min(1) }),
|
|
9932
10413
|
response: { 200: WebhookSchema, 404: ErrorSchema, 503: ErrorSchema }
|
|
9933
10414
|
},
|
|
9934
10415
|
handler: async (request, reply) => {
|
|
@@ -9959,269 +10440,6 @@ function queryValues(query) {
|
|
|
9959
10440
|
}));
|
|
9960
10441
|
}
|
|
9961
10442
|
|
|
9962
|
-
// src/routes/workflow-enablements.ts
|
|
9963
|
-
import {
|
|
9964
|
-
AccessDeniedError as AccessDeniedError9,
|
|
9965
|
-
AuthenticationRequiredError as AuthenticationRequiredError4,
|
|
9966
|
-
ConnectionPermissionDeniedError as ConnectionPermissionDeniedError3,
|
|
9967
|
-
ConnectionUnavailableError as ConnectionUnavailableError3,
|
|
9968
|
-
EnvironmentAccessDeniedError as EnvironmentAccessDeniedError4,
|
|
9969
|
-
EnvironmentBindingUnavailableError as EnvironmentBindingUnavailableError5,
|
|
9970
|
-
EnvironmentIncompatibleError as EnvironmentIncompatibleError4,
|
|
9971
|
-
EnvironmentNotFoundError as EnvironmentNotFoundError5,
|
|
9972
|
-
EnvironmentPolicyInvalidError,
|
|
9973
|
-
ProductionDeploymentNotFoundError as ProductionDeploymentNotFoundError3,
|
|
9974
|
-
WorkflowEnablementConflictError,
|
|
9975
|
-
WorkflowEnablementConsentRequiredError,
|
|
9976
|
-
WorkflowEnablementNotFoundError,
|
|
9977
|
-
WorkflowEnablementSuspendedError,
|
|
9978
|
-
WorkflowNotFoundError as WorkflowNotFoundError2
|
|
9979
|
-
} from "@catamorphic/core";
|
|
9980
|
-
import { z as z23 } from "zod";
|
|
9981
|
-
var EnablementParamsSchema = ProjectIdParamsSchema.extend({
|
|
9982
|
-
enablementId: z23.string().uuid()
|
|
9983
|
-
});
|
|
9984
|
-
var NotPublishedErrorSchema = z23.object({
|
|
9985
|
-
error: z23.string(),
|
|
9986
|
-
reason: z23.literal("not_published")
|
|
9987
|
-
});
|
|
9988
|
-
var PreviewConflictSchema = z23.union([NotPublishedErrorSchema, ErrorSchema]);
|
|
9989
|
-
var SelectionSchema = z23.record(z23.string(), z23.string().uuid()).optional();
|
|
9990
|
-
var PreviewBodySchema = z23.object({
|
|
9991
|
-
workflowName: z23.string().min(1),
|
|
9992
|
-
environment: z23.string().min(1).optional(),
|
|
9993
|
-
owner: WorkflowEnablementOwnerSchema.optional(),
|
|
9994
|
-
connectionSelections: SelectionSchema
|
|
9995
|
-
});
|
|
9996
|
-
function registerWorkflowEnablementRoutes(app, ctx) {
|
|
9997
|
-
const typed = app.withTypeProvider();
|
|
9998
|
-
const service = () => ctx.core?.workflowEnablements;
|
|
9999
|
-
typed.route({
|
|
10000
|
-
method: "GET",
|
|
10001
|
-
url: "/projects/:projectId/workflow-enablements",
|
|
10002
|
-
schema: {
|
|
10003
|
-
params: ProjectIdParamsSchema,
|
|
10004
|
-
querystring: z23.object({ workflowName: z23.string().optional() }),
|
|
10005
|
-
response: {
|
|
10006
|
-
200: z23.object({
|
|
10007
|
-
items: z23.array(WorkflowEnablementSchema),
|
|
10008
|
-
canManageProjectAutomations: z23.boolean()
|
|
10009
|
-
}),
|
|
10010
|
-
503: ErrorSchema
|
|
10011
|
-
}
|
|
10012
|
-
},
|
|
10013
|
-
handler: async (request, reply) => {
|
|
10014
|
-
const workflowEnablements = service();
|
|
10015
|
-
if (!workflowEnablements) {
|
|
10016
|
-
return reply.status(503).send({ error: "Workflow enablements unavailable" });
|
|
10017
|
-
}
|
|
10018
|
-
const identity = resolveIdentity(request);
|
|
10019
|
-
const { projectId } = request.params;
|
|
10020
|
-
return reply.send({
|
|
10021
|
-
items: await workflowEnablements.list({
|
|
10022
|
-
identity,
|
|
10023
|
-
projectId,
|
|
10024
|
-
workflowName: request.query.workflowName
|
|
10025
|
-
}),
|
|
10026
|
-
canManageProjectAutomations: workflowEnablements.mayManageProjectAutomations({
|
|
10027
|
-
identity,
|
|
10028
|
-
projectId
|
|
10029
|
-
})
|
|
10030
|
-
});
|
|
10031
|
-
}
|
|
10032
|
-
});
|
|
10033
|
-
typed.route({
|
|
10034
|
-
method: "POST",
|
|
10035
|
-
url: "/projects/:projectId/workflow-enablement-preview",
|
|
10036
|
-
schema: {
|
|
10037
|
-
params: ProjectIdParamsSchema,
|
|
10038
|
-
body: PreviewBodySchema,
|
|
10039
|
-
response: {
|
|
10040
|
-
200: WorkflowEnablementPreviewSchema,
|
|
10041
|
-
403: ErrorSchema,
|
|
10042
|
-
409: PreviewConflictSchema,
|
|
10043
|
-
428: AuthenticationRequiredSchema,
|
|
10044
|
-
503: ErrorSchema
|
|
10045
|
-
}
|
|
10046
|
-
},
|
|
10047
|
-
handler: async (request, reply) => {
|
|
10048
|
-
const workflowEnablements = service();
|
|
10049
|
-
if (!workflowEnablements) {
|
|
10050
|
-
return reply.status(503).send({ error: "Workflow enablements unavailable" });
|
|
10051
|
-
}
|
|
10052
|
-
try {
|
|
10053
|
-
return reply.send(await workflowEnablements.preview({
|
|
10054
|
-
identity: resolveIdentity(request),
|
|
10055
|
-
projectId: request.params.projectId,
|
|
10056
|
-
...request.body
|
|
10057
|
-
}));
|
|
10058
|
-
} catch (error) {
|
|
10059
|
-
return handleEnablementError(error, reply);
|
|
10060
|
-
}
|
|
10061
|
-
}
|
|
10062
|
-
});
|
|
10063
|
-
typed.route({
|
|
10064
|
-
method: "POST",
|
|
10065
|
-
url: "/projects/:projectId/workflow-enablements",
|
|
10066
|
-
schema: {
|
|
10067
|
-
params: ProjectIdParamsSchema,
|
|
10068
|
-
body: PreviewBodySchema.extend({ consentDigest: z23.string().length(64) }),
|
|
10069
|
-
response: {
|
|
10070
|
-
201: WorkflowEnablementSchema,
|
|
10071
|
-
403: ErrorSchema,
|
|
10072
|
-
409: PreviewConflictSchema,
|
|
10073
|
-
428: AuthenticationRequiredSchema,
|
|
10074
|
-
503: ErrorSchema
|
|
10075
|
-
}
|
|
10076
|
-
},
|
|
10077
|
-
handler: async (request, reply) => {
|
|
10078
|
-
const workflowEnablements = service();
|
|
10079
|
-
if (!workflowEnablements) {
|
|
10080
|
-
return reply.status(503).send({ error: "Workflow enablements unavailable" });
|
|
10081
|
-
}
|
|
10082
|
-
try {
|
|
10083
|
-
return reply.status(201).send(await workflowEnablements.create({
|
|
10084
|
-
identity: resolveIdentity(request),
|
|
10085
|
-
projectId: request.params.projectId,
|
|
10086
|
-
...request.body
|
|
10087
|
-
}));
|
|
10088
|
-
} catch (error) {
|
|
10089
|
-
return handleEnablementError(error, reply);
|
|
10090
|
-
}
|
|
10091
|
-
}
|
|
10092
|
-
});
|
|
10093
|
-
typed.route({
|
|
10094
|
-
method: "GET",
|
|
10095
|
-
url: "/projects/:projectId/workflow-enablements/:enablementId",
|
|
10096
|
-
schema: {
|
|
10097
|
-
params: EnablementParamsSchema,
|
|
10098
|
-
response: {
|
|
10099
|
-
200: WorkflowEnablementSchema,
|
|
10100
|
-
403: ErrorSchema,
|
|
10101
|
-
404: ErrorSchema
|
|
10102
|
-
}
|
|
10103
|
-
},
|
|
10104
|
-
handler: async (request, reply) => {
|
|
10105
|
-
const workflowEnablements = service();
|
|
10106
|
-
if (!workflowEnablements) {
|
|
10107
|
-
return reply.status(404).send({ error: "Workflow enablement not found" });
|
|
10108
|
-
}
|
|
10109
|
-
try {
|
|
10110
|
-
const result = await workflowEnablements.get({
|
|
10111
|
-
identity: resolveIdentity(request),
|
|
10112
|
-
enablementId: request.params.enablementId
|
|
10113
|
-
});
|
|
10114
|
-
return result.projectId === request.params.projectId ? reply.send(result) : reply.status(404).send({ error: "Workflow enablement not found" });
|
|
10115
|
-
} catch (error) {
|
|
10116
|
-
return handleEnablementError(error, reply);
|
|
10117
|
-
}
|
|
10118
|
-
}
|
|
10119
|
-
});
|
|
10120
|
-
for (const action of ["disable", "reenable"]) {
|
|
10121
|
-
typed.route({
|
|
10122
|
-
method: "POST",
|
|
10123
|
-
url: `/projects/:projectId/workflow-enablements/:enablementId/${action}`,
|
|
10124
|
-
schema: {
|
|
10125
|
-
params: EnablementParamsSchema,
|
|
10126
|
-
response: {
|
|
10127
|
-
200: WorkflowEnablementSchema,
|
|
10128
|
-
403: ErrorSchema,
|
|
10129
|
-
404: ErrorSchema,
|
|
10130
|
-
409: PreviewConflictSchema
|
|
10131
|
-
}
|
|
10132
|
-
},
|
|
10133
|
-
handler: async (request, reply) => {
|
|
10134
|
-
const workflowEnablements = service();
|
|
10135
|
-
if (!workflowEnablements) {
|
|
10136
|
-
return reply.status(404).send({ error: "Workflow enablement not found" });
|
|
10137
|
-
}
|
|
10138
|
-
try {
|
|
10139
|
-
const identity = resolveIdentity(request);
|
|
10140
|
-
const current = await workflowEnablements.get({
|
|
10141
|
-
identity,
|
|
10142
|
-
enablementId: request.params.enablementId
|
|
10143
|
-
});
|
|
10144
|
-
if (current.projectId !== request.params.projectId) {
|
|
10145
|
-
return reply.status(404).send({ error: "Workflow enablement not found" });
|
|
10146
|
-
}
|
|
10147
|
-
const result = await workflowEnablements[action]({
|
|
10148
|
-
identity,
|
|
10149
|
-
enablementId: request.params.enablementId
|
|
10150
|
-
});
|
|
10151
|
-
return reply.send(result);
|
|
10152
|
-
} catch (error) {
|
|
10153
|
-
return handleEnablementError(error, reply);
|
|
10154
|
-
}
|
|
10155
|
-
}
|
|
10156
|
-
});
|
|
10157
|
-
}
|
|
10158
|
-
typed.route({
|
|
10159
|
-
method: "POST",
|
|
10160
|
-
url: "/projects/:projectId/workflow-enablements/:enablementId/update-deployment",
|
|
10161
|
-
schema: {
|
|
10162
|
-
params: EnablementParamsSchema,
|
|
10163
|
-
body: z23.object({ consentDigest: z23.string().length(64) }),
|
|
10164
|
-
response: {
|
|
10165
|
-
200: WorkflowEnablementSchema,
|
|
10166
|
-
403: ErrorSchema,
|
|
10167
|
-
404: ErrorSchema,
|
|
10168
|
-
409: PreviewConflictSchema,
|
|
10169
|
-
428: AuthenticationRequiredSchema
|
|
10170
|
-
}
|
|
10171
|
-
},
|
|
10172
|
-
handler: async (request, reply) => {
|
|
10173
|
-
const workflowEnablements = service();
|
|
10174
|
-
if (!workflowEnablements) {
|
|
10175
|
-
return reply.status(404).send({ error: "Workflow enablement not found" });
|
|
10176
|
-
}
|
|
10177
|
-
try {
|
|
10178
|
-
const identity = resolveIdentity(request);
|
|
10179
|
-
const current = await workflowEnablements.get({
|
|
10180
|
-
identity,
|
|
10181
|
-
enablementId: request.params.enablementId
|
|
10182
|
-
});
|
|
10183
|
-
if (current.projectId !== request.params.projectId) {
|
|
10184
|
-
return reply.status(404).send({ error: "Workflow enablement not found" });
|
|
10185
|
-
}
|
|
10186
|
-
const result = await workflowEnablements.updateDeployment({
|
|
10187
|
-
identity,
|
|
10188
|
-
enablementId: request.params.enablementId,
|
|
10189
|
-
consentDigest: request.body.consentDigest
|
|
10190
|
-
});
|
|
10191
|
-
return reply.send(result);
|
|
10192
|
-
} catch (error) {
|
|
10193
|
-
return handleEnablementError(error, reply);
|
|
10194
|
-
}
|
|
10195
|
-
}
|
|
10196
|
-
});
|
|
10197
|
-
}
|
|
10198
|
-
function handleEnablementError(error, reply) {
|
|
10199
|
-
if (error instanceof AuthenticationRequiredError4) {
|
|
10200
|
-
return reply.status(428).send({
|
|
10201
|
-
error: error.message,
|
|
10202
|
-
code: "authentication_required",
|
|
10203
|
-
environment: error.environment,
|
|
10204
|
-
requirements: error.requirements
|
|
10205
|
-
});
|
|
10206
|
-
}
|
|
10207
|
-
if (error instanceof WorkflowEnablementNotFoundError) {
|
|
10208
|
-
return reply.status(404).send({ error: error.message });
|
|
10209
|
-
}
|
|
10210
|
-
if (error instanceof WorkflowNotFoundError2 || error instanceof ProductionDeploymentNotFoundError3) {
|
|
10211
|
-
return reply.status(409).send({
|
|
10212
|
-
error: "This workflow isn't in the project's published version yet. Publish the project's changes, then turn it on.",
|
|
10213
|
-
reason: "not_published"
|
|
10214
|
-
});
|
|
10215
|
-
}
|
|
10216
|
-
if (error instanceof AccessDeniedError9 || error instanceof ConnectionPermissionDeniedError3 || error instanceof EnvironmentAccessDeniedError4) {
|
|
10217
|
-
return reply.status(403).send({ error: error.message });
|
|
10218
|
-
}
|
|
10219
|
-
if (error instanceof WorkflowEnablementConsentRequiredError || error instanceof WorkflowEnablementConflictError || error instanceof ConnectionUnavailableError3 || error instanceof EnvironmentNotFoundError5 || error instanceof EnvironmentPolicyInvalidError || error instanceof EnvironmentIncompatibleError4 || error instanceof EnvironmentBindingUnavailableError5 || error instanceof WorkflowEnablementSuspendedError) {
|
|
10220
|
-
return reply.status(409).send({ error: error.message });
|
|
10221
|
-
}
|
|
10222
|
-
throw error;
|
|
10223
|
-
}
|
|
10224
|
-
|
|
10225
10443
|
// src/routes/workflows.ts
|
|
10226
10444
|
import {
|
|
10227
10445
|
ProjectNotFoundError as ProjectNotFoundError11,
|
|
@@ -10232,7 +10450,7 @@ import {
|
|
|
10232
10450
|
RunSignalNotFoundError,
|
|
10233
10451
|
WorkflowNotFoundError as WorkflowNotFoundError3
|
|
10234
10452
|
} from "@catamorphic/core";
|
|
10235
|
-
import { z as
|
|
10453
|
+
import { z as z25 } from "zod";
|
|
10236
10454
|
function registerWorkflowRoutes(app, ctx) {
|
|
10237
10455
|
const typed = app.withTypeProvider();
|
|
10238
10456
|
typed.route({
|
|
@@ -10469,7 +10687,7 @@ function registerWorkflowRoutes(app, ctx) {
|
|
|
10469
10687
|
body: CancelRunByKeySchema,
|
|
10470
10688
|
response: {
|
|
10471
10689
|
200: RunSchema,
|
|
10472
|
-
204:
|
|
10690
|
+
204: z25.null(),
|
|
10473
10691
|
404: ErrorSchema,
|
|
10474
10692
|
503: ErrorSchema
|
|
10475
10693
|
}
|
|
@@ -10593,6 +10811,7 @@ var catamorphicPlugin = async (app, opts) => {
|
|
|
10593
10811
|
registerWebhookRoutes(app, ctx);
|
|
10594
10812
|
registerAppRoutes(app, ctx);
|
|
10595
10813
|
registerSessionArtifactRoutes(app, ctx);
|
|
10814
|
+
registerPrivateCustomizationRoutes(app, ctx);
|
|
10596
10815
|
registerAppsMcpRoutes(app, ctx);
|
|
10597
10816
|
registerProjectMcpRoutes(app, ctx);
|
|
10598
10817
|
registerAgentCapabilityRoutes(app, ctx);
|
|
@@ -10664,7 +10883,7 @@ function createApp(config) {
|
|
|
10664
10883
|
import {
|
|
10665
10884
|
defineAgentCapability
|
|
10666
10885
|
} from "@catamorphic/core";
|
|
10667
|
-
import { z as
|
|
10886
|
+
import { z as z26 } from "zod";
|
|
10668
10887
|
var PUBLISHING_TOOLS = new Set([
|
|
10669
10888
|
"program_deploy",
|
|
10670
10889
|
"publish_document",
|
|
@@ -10675,11 +10894,11 @@ var OWN_CHAT_TOOLS = new Set([
|
|
|
10675
10894
|
"set_app_presentation",
|
|
10676
10895
|
"set_session_metadata"
|
|
10677
10896
|
]);
|
|
10678
|
-
var Definition =
|
|
10679
|
-
name:
|
|
10680
|
-
description:
|
|
10681
|
-
inputSchema:
|
|
10682
|
-
annotations:
|
|
10897
|
+
var Definition = z26.object({
|
|
10898
|
+
name: z26.string(),
|
|
10899
|
+
description: z26.string().default(""),
|
|
10900
|
+
inputSchema: z26.record(z26.string(), z26.unknown()),
|
|
10901
|
+
annotations: z26.object({ readOnlyHint: z26.boolean().optional() }).optional()
|
|
10683
10902
|
});
|
|
10684
10903
|
async function projectToolCapabilities(args) {
|
|
10685
10904
|
const { core, context } = args;
|
|
@@ -10714,8 +10933,8 @@ async function projectToolCapabilities(args) {
|
|
|
10714
10933
|
description: definition.description,
|
|
10715
10934
|
effect,
|
|
10716
10935
|
...PUBLISHING_TOOLS.has(definition.name) ? { sandboxing: "publish" } : OWN_CHAT_TOOLS.has(definition.name) ? { sandboxing: "contained" } : {},
|
|
10717
|
-
inputSchema:
|
|
10718
|
-
outputSchema:
|
|
10936
|
+
inputSchema: z26.fromJSONSchema(definition.inputSchema),
|
|
10937
|
+
outputSchema: z26.unknown(),
|
|
10719
10938
|
authorize: () => true,
|
|
10720
10939
|
beforeInvoke: (invocation, input) => args.beforeCall?.({
|
|
10721
10940
|
name: definition.name,
|
|
@@ -10725,7 +10944,7 @@ async function projectToolCapabilities(args) {
|
|
|
10725
10944
|
}) ?? Promise.resolve(),
|
|
10726
10945
|
execute: async (invocation, input) => {
|
|
10727
10946
|
invocation.signal?.throwIfAborted();
|
|
10728
|
-
const values =
|
|
10947
|
+
const values = z26.record(z26.string(), z26.unknown()).parse(input);
|
|
10729
10948
|
const owned = !taken.has(definition.name) && [
|
|
10730
10949
|
"session_artifact",
|
|
10731
10950
|
"create_watcher",
|
|
@@ -10734,13 +10953,13 @@ async function projectToolCapabilities(args) {
|
|
|
10734
10953
|
].includes(definition.name);
|
|
10735
10954
|
const result = await tool.call(owned ? { ...values, sessionId: context.sessionId } : values);
|
|
10736
10955
|
if (result.isError) {
|
|
10737
|
-
const content =
|
|
10956
|
+
const content = z26.array(z26.object({ text: z26.string() })).parse(result.content);
|
|
10738
10957
|
throw new Error(content.map((part) => part.text).join(`
|
|
10739
10958
|
`));
|
|
10740
10959
|
}
|
|
10741
10960
|
if (result.structuredContent !== undefined)
|
|
10742
10961
|
return JSON.parse(JSON.stringify(result.structuredContent));
|
|
10743
|
-
const content =
|
|
10962
|
+
const content = z26.array(z26.object({ text: z26.string() })).parse(result.content);
|
|
10744
10963
|
const text = content.map((part) => part.text).join(`
|
|
10745
10964
|
`);
|
|
10746
10965
|
try {
|
|
@@ -10917,5 +11136,5 @@ export {
|
|
|
10917
11136
|
serveSpaDist
|
|
10918
11137
|
};
|
|
10919
11138
|
|
|
10920
|
-
//# debugId=
|
|
11139
|
+
//# debugId=5B798E4881E33EC964756E2164756E21
|
|
10921
11140
|
//# sourceMappingURL=index.js.map
|