@scarn/sdk 0.8.15 → 0.8.18
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/automations/index.js +4 -4
- package/dist/{chunk-4ggr8af6.js → chunk-098740f7.js} +1 -1
- package/dist/{chunk-1yb2h6t9.js → chunk-0c60x3v8.js} +53 -61
- package/dist/{chunk-y2pv8d6a.js → chunk-19brnwkp.js} +1 -1
- package/dist/{chunk-b8hxjwag.js → chunk-2tmrw253.js} +2 -2
- package/dist/{chunk-z25n32z0.js → chunk-3zp2qtf8.js} +88 -9
- package/dist/{chunk-k4y5qt4y.js → chunk-46wmsgv7.js} +1 -1
- package/dist/{chunk-ar6hcj1r.js → chunk-6tra3gw8.js} +7 -1
- package/dist/{chunk-zf4gwg0p.js → chunk-833ef6dg.js} +170 -269
- package/dist/{chunk-11hbmexe.js → chunk-9we3vqsv.js} +1 -1
- package/dist/{chunk-5zsavw98.js → chunk-aemxz9r7.js} +19 -3
- package/dist/{chunk-43y7tfn4.js → chunk-aknfw08j.js} +1 -1
- package/dist/chunk-e0pt5x0e.js +167 -0
- package/dist/{chunk-cnxaagfj.js → chunk-evb3hw48.js} +1 -1
- package/dist/chunk-mmy80pec.js +64 -0
- package/dist/chunk-mzj1j0p5.js +116 -0
- package/dist/{chunk-76d1bwwz.js → chunk-p1fs73bd.js} +2 -2
- package/dist/{chunk-e1h021kq.js → chunk-pqtd0hr7.js} +13 -3
- package/dist/chunk-qgkx89eg.js +210 -0
- package/dist/chunk-rphfy0fj.js +167 -0
- package/dist/chunk-t1dq2c2s.js +224 -0
- package/dist/{chunk-7bpy3w3z.js → chunk-tvjcfh6s.js} +5 -1
- package/dist/{chunk-63f90zky.js → chunk-y34zsgsw.js} +1 -1
- package/dist/{chunk-skzxcba3.js → chunk-yf15kdte.js} +7087 -1944
- package/dist/{chunk-efs789y2.js → chunk-ymywp5ht.js} +2 -2
- package/dist/client.js +8 -2
- package/dist/connectors/catalog.d.ts +49 -0
- package/dist/connectors/index.d.ts +45 -0
- package/dist/connectors/index.js +41 -0
- package/dist/contracts/artifacts.js +2 -2
- package/dist/contracts/automation-document/index.js +3 -3
- package/dist/contracts/pipeline-document/index.js +2 -2
- package/dist/contracts/step-artifact-submissions.js +2 -2
- package/dist/contracts/work-item-changes.js +1 -1
- package/dist/defaults/index.js +2 -2
- package/dist/definitions/automations/index.js +3 -3
- package/dist/definitions/environments/define-environment.d.ts +39 -0
- package/dist/definitions/environments/environments-client.d.ts +50 -0
- package/dist/definitions/environments/index.d.ts +6 -0
- package/dist/definitions/environments/index.js +97 -0
- package/dist/definitions/pipelines/index.js +3 -3
- package/dist/definitions/steps/compile-mcps.d.ts +8 -12
- package/dist/definitions/steps/define-code-step.d.ts +18 -11
- package/dist/definitions/steps/define-step.d.ts +14 -25
- package/dist/definitions/steps/env.d.ts +30 -8
- package/dist/definitions/steps/index.js +35 -18
- package/dist/definitions/steps/mcp-server-config.d.ts +19 -9
- package/dist/definitions/steps/repo.d.ts +56 -28
- package/dist/definitions/steps/runtime.d.ts +54 -39
- package/dist/definitions/steps/step-definitions-client.d.ts +222 -63
- package/dist/definitions/steps/step-handle.d.ts +8 -1
- package/dist/definitions/validation/index.js +10 -7
- package/dist/definitions/validation/validate-repo.d.ts +3 -7
- package/dist/definitions/validation/validate-runtime.d.ts +2 -7
- package/dist/devcontainer-config-path.js +2 -2
- package/dist/env-vars.d.ts +57 -1
- package/dist/env-vars.js +8 -2
- package/dist/environment.d.ts +564 -0
- package/dist/environment.js +46 -0
- package/dist/generated/index.d.ts +2 -2
- package/dist/generated/sdk.gen.d.ts +35 -10
- package/dist/generated/types.gen.d.ts +2151 -188
- package/dist/health-checks.d.ts +3 -3
- package/dist/health-checks.js +2 -2
- package/dist/index.d.ts +2 -0
- package/dist/index.js +100 -34
- package/dist/managed-runtimes.js +2 -2
- package/dist/opencode-mcp.d.ts +75 -4
- package/dist/opencode-mcp.js +3 -2
- package/dist/pipelines/index.js +3 -3
- package/dist/push/code-step-lookup.d.ts +6 -0
- package/dist/push/code-step-lookup.js +3 -1
- package/dist/push/collect-definitions.d.ts +13 -0
- package/dist/push/index.js +132 -20
- package/dist/push/push-from-directory.d.ts +11 -2
- package/dist/repo-config.d.ts +88 -30
- package/dist/repo-config.js +22 -6
- package/dist/resolve-environment.d.ts +19 -0
- package/dist/resolve-environment.js +19 -0
- package/dist/task-plane-client.d.ts +139 -22
- package/package.json +17 -1
- package/dist/chunk-xzx08r6y.js +0 -103
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// @bun
|
|
2
2
|
import {
|
|
3
3
|
exports_external
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-yf15kdte.js";
|
|
5
5
|
|
|
6
6
|
// src/env-vars.ts
|
|
7
7
|
var ENV_VAR_NAME_PATTERN = /^[A-Z_][A-Z0-9_]*$/;
|
|
@@ -63,10 +63,20 @@ var inheritEnvVarSchema = exports_external.object({
|
|
|
63
63
|
path: ["default"],
|
|
64
64
|
message: "a secret cannot carry a default; it would be stored in plaintext"
|
|
65
65
|
});
|
|
66
|
+
var secretEnvVarSchema = exports_external.object({
|
|
67
|
+
name: envVarNameSchema,
|
|
68
|
+
source: exports_external.literal("secret"),
|
|
69
|
+
secretName: envVarNameSchema,
|
|
70
|
+
applies: envVarAppliesSchema
|
|
71
|
+
}).strict();
|
|
66
72
|
var envVarSpecSchema = exports_external.discriminatedUnion("source", [
|
|
67
73
|
valueEnvVarSchema,
|
|
68
|
-
inheritEnvVarSchema
|
|
74
|
+
inheritEnvVarSchema,
|
|
75
|
+
secretEnvVarSchema
|
|
69
76
|
]);
|
|
77
|
+
function isMaskedEnvVar(entry) {
|
|
78
|
+
return entry.source === "secret" || entry.secret;
|
|
79
|
+
}
|
|
70
80
|
var envVarsSchema = exports_external.array(envVarSpecSchema).max(MAX_ENV_VARS).refine((entries) => new Set(entries.map((entry) => entry.name)).size === entries.length, { message: "environment variable names must be unique" });
|
|
71
81
|
var storedEnvVarsSchema = exports_external.array(exports_external.discriminatedUnion("source", [
|
|
72
82
|
exports_external.object({
|
|
@@ -85,7 +95,13 @@ var storedEnvVarsSchema = exports_external.array(exports_external.discriminatedU
|
|
|
85
95
|
default: exports_external.string().optional(),
|
|
86
96
|
mcp: exports_external.string().optional(),
|
|
87
97
|
applies: exports_external.enum(envVarAppliesValues).default("agent")
|
|
98
|
+
}),
|
|
99
|
+
exports_external.object({
|
|
100
|
+
name: exports_external.string(),
|
|
101
|
+
source: exports_external.literal("secret"),
|
|
102
|
+
secretName: exports_external.string(),
|
|
103
|
+
applies: exports_external.enum(envVarAppliesValues).default("agent")
|
|
88
104
|
})
|
|
89
105
|
]));
|
|
90
106
|
|
|
91
|
-
export { ENV_VAR_NAME_PATTERN, RESERVED_ENV_VAR_NAMES, RESERVED_ENV_VAR_PREFIX, MAX_ENV_VARS, MAX_ENV_VAR_NAME_LENGTH, MAX_ENV_VAR_VALUE_LENGTH, containsInputToken, isReservedEnvVarName, envVarAppliesValues, appliesToAgent, appliesToSetup, isUninheritableWorkerEnvVarName, envVarSpecSchema, envVarsSchema, storedEnvVarsSchema };
|
|
107
|
+
export { ENV_VAR_NAME_PATTERN, RESERVED_ENV_VAR_NAMES, RESERVED_ENV_VAR_PREFIX, MAX_ENV_VARS, MAX_ENV_VAR_NAME_LENGTH, MAX_ENV_VAR_VALUE_LENGTH, containsInputToken, isReservedEnvVarName, envVarAppliesValues, appliesToAgent, appliesToSetup, isUninheritableWorkerEnvVarName, inheritEnvVarSchema, secretEnvVarSchema, envVarSpecSchema, isMaskedEnvVar, envVarsSchema, storedEnvVarsSchema };
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import {
|
|
3
|
+
devcontainerConfigPathSchema
|
|
4
|
+
} from "./chunk-098740f7.js";
|
|
5
|
+
import {
|
|
6
|
+
managedRuntimeIdSchema
|
|
7
|
+
} from "./chunk-46wmsgv7.js";
|
|
8
|
+
import {
|
|
9
|
+
connectorIdsSchema,
|
|
10
|
+
findMissingConnectorVars
|
|
11
|
+
} from "./chunk-qgkx89eg.js";
|
|
12
|
+
import {
|
|
13
|
+
envVarsSchema,
|
|
14
|
+
storedEnvVarsSchema
|
|
15
|
+
} from "./chunk-aemxz9r7.js";
|
|
16
|
+
import {
|
|
17
|
+
exports_external
|
|
18
|
+
} from "./chunk-yf15kdte.js";
|
|
19
|
+
|
|
20
|
+
// src/environment.ts
|
|
21
|
+
var environmentNameSchema = exports_external.string().regex(/^[a-z0-9][a-z0-9-]*$/, "must match /^[a-z0-9][a-z0-9-]*$/");
|
|
22
|
+
var environmentRuntimeSchema = exports_external.discriminatedUnion("kind", [
|
|
23
|
+
exports_external.strictObject({
|
|
24
|
+
kind: exports_external.literal("devcontainer"),
|
|
25
|
+
config: devcontainerConfigPathSchema.optional()
|
|
26
|
+
}),
|
|
27
|
+
exports_external.strictObject({
|
|
28
|
+
kind: exports_external.literal("managed"),
|
|
29
|
+
id: managedRuntimeIdSchema
|
|
30
|
+
}),
|
|
31
|
+
exports_external.strictObject({ kind: exports_external.literal("host") })
|
|
32
|
+
]);
|
|
33
|
+
var rejectEnvironmentBranch = (issue) => issue.code === "unrecognized_keys" && issue.keys.includes("branch") ? "environments have no branch; use the step's repo baseBranch" : undefined;
|
|
34
|
+
var environmentFieldsSchema = exports_external.strictObject({
|
|
35
|
+
runtime: environmentRuntimeSchema.optional(),
|
|
36
|
+
vars: envVarsSchema.optional(),
|
|
37
|
+
connectors: connectorIdsSchema.optional()
|
|
38
|
+
}, { error: rejectEnvironmentBranch });
|
|
39
|
+
var findHostSetupVar = ({
|
|
40
|
+
runtime,
|
|
41
|
+
vars
|
|
42
|
+
}) => runtime?.kind === "host" ? (vars ?? []).find((entry) => entry.applies !== "agent") : undefined;
|
|
43
|
+
var hostSetupVarMessage = (entry) => `env var "${entry.name}" applies to '${entry.applies}', but runtime 'host' has no container to set up; use 'agent'`;
|
|
44
|
+
var environmentContentSchema = environmentFieldsSchema.extend({ description: exports_external.string().optional() }).superRefine((value, context) => {
|
|
45
|
+
const setupVar = findHostSetupVar(value);
|
|
46
|
+
if (setupVar !== undefined) {
|
|
47
|
+
context.addIssue({
|
|
48
|
+
code: "custom",
|
|
49
|
+
path: ["vars"],
|
|
50
|
+
message: hostSetupVarMessage(setupVar)
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
for (const { connector, vars } of findMissingConnectorVars(value.connectors ?? [], value.vars ?? [])) {
|
|
54
|
+
context.addIssue({
|
|
55
|
+
code: "custom",
|
|
56
|
+
path: ["connectors"],
|
|
57
|
+
message: `connector "${connector}" needs ${vars.join(", ")}; add them to the environment's vars`
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
function rejectHostSetupVars(vars, ctx, path) {
|
|
62
|
+
for (const entry of vars) {
|
|
63
|
+
if (entry.applies !== "agent") {
|
|
64
|
+
ctx.addIssue({
|
|
65
|
+
code: "custom",
|
|
66
|
+
path: [...path, entry.name, "applies"],
|
|
67
|
+
message: `env "${entry.name}": applies "${entry.applies}" needs a container to set up; host has none`
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
var namedEnvironmentRefSchema = exports_external.strictObject({
|
|
73
|
+
kind: exports_external.literal("named"),
|
|
74
|
+
name: environmentNameSchema
|
|
75
|
+
});
|
|
76
|
+
var inlineEnvironmentRefSchema = exports_external.strictObject({
|
|
77
|
+
kind: exports_external.literal("inline"),
|
|
78
|
+
runtime: environmentRuntimeSchema.optional(),
|
|
79
|
+
envJson: envVarsSchema.nullish(),
|
|
80
|
+
connectors: connectorIdsSchema.optional()
|
|
81
|
+
}, { error: rejectEnvironmentBranch });
|
|
82
|
+
function rejectHostSetupRef(ref, ctx) {
|
|
83
|
+
if (ref.kind === "inline" && ref.runtime?.kind === "host") {
|
|
84
|
+
rejectHostSetupVars(ref.envJson ?? [], ctx, ["envJson"]);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
var environmentRefSchema = exports_external.discriminatedUnion("kind", [
|
|
88
|
+
namedEnvironmentRefSchema,
|
|
89
|
+
inlineEnvironmentRefSchema
|
|
90
|
+
]).superRefine(rejectHostSetupRef).nullable();
|
|
91
|
+
var inlineEnvironmentRefReadSchema = inlineEnvironmentRefSchema.extend({
|
|
92
|
+
envJson: storedEnvVarsSchema.nullish()
|
|
93
|
+
});
|
|
94
|
+
var environmentRefReadSchema = exports_external.discriminatedUnion("kind", [
|
|
95
|
+
namedEnvironmentRefSchema,
|
|
96
|
+
inlineEnvironmentRefReadSchema
|
|
97
|
+
]).superRefine(rejectHostSetupRef).nullable();
|
|
98
|
+
var inlineEnvironmentReadSchema = inlineEnvironmentRefReadSchema.superRefine(rejectHostSetupRef).nullable();
|
|
99
|
+
var storedEnvironmentRuntimeSchema = exports_external.discriminatedUnion("kind", [
|
|
100
|
+
exports_external.object({
|
|
101
|
+
kind: exports_external.literal("devcontainer"),
|
|
102
|
+
config: exports_external.string().optional()
|
|
103
|
+
}),
|
|
104
|
+
exports_external.object({ kind: exports_external.literal("managed"), id: managedRuntimeIdSchema }),
|
|
105
|
+
exports_external.object({ kind: exports_external.literal("host") })
|
|
106
|
+
]);
|
|
107
|
+
var storedEnvironmentFieldsSchema = exports_external.object({
|
|
108
|
+
runtime: storedEnvironmentRuntimeSchema.optional(),
|
|
109
|
+
vars: storedEnvVarsSchema.optional(),
|
|
110
|
+
connectors: exports_external.array(exports_external.string()).optional()
|
|
111
|
+
});
|
|
112
|
+
var storedEnvironmentContentSchema = storedEnvironmentFieldsSchema.extend({
|
|
113
|
+
description: exports_external.string().optional()
|
|
114
|
+
});
|
|
115
|
+
var resolvedEnvironmentRefSchema = exports_external.union([
|
|
116
|
+
exports_external.strictObject({
|
|
117
|
+
kind: exports_external.literal("inline"),
|
|
118
|
+
runtime: environmentRuntimeSchema.optional(),
|
|
119
|
+
envJson: storedEnvVarsSchema.nullish(),
|
|
120
|
+
connectors: exports_external.array(exports_external.string()).optional()
|
|
121
|
+
}),
|
|
122
|
+
exports_external.strictObject({
|
|
123
|
+
kind: exports_external.literal("named"),
|
|
124
|
+
name: environmentNameSchema,
|
|
125
|
+
version: exports_external.number().int().positive(),
|
|
126
|
+
content: storedEnvironmentContentSchema
|
|
127
|
+
}),
|
|
128
|
+
exports_external.strictObject({
|
|
129
|
+
kind: exports_external.literal("named"),
|
|
130
|
+
name: environmentNameSchema,
|
|
131
|
+
notFound: exports_external.literal(true)
|
|
132
|
+
})
|
|
133
|
+
]).nullable();
|
|
134
|
+
|
|
135
|
+
class EnvironmentNotFound extends Error {
|
|
136
|
+
environmentName;
|
|
137
|
+
kind = "EnvironmentNotFound";
|
|
138
|
+
code = "SCARN_ENVIRONMENT_NOT_FOUND";
|
|
139
|
+
constructor(environmentName) {
|
|
140
|
+
super(`Environment not found: ${environmentName}`);
|
|
141
|
+
this.environmentName = environmentName;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
class EnvironmentInvalid extends Error {
|
|
146
|
+
environment;
|
|
147
|
+
issues;
|
|
148
|
+
kind = "EnvironmentInvalid";
|
|
149
|
+
code = "SCARN_ENVIRONMENT_INVALID";
|
|
150
|
+
constructor(environment, issues) {
|
|
151
|
+
super(`Invalid ${environment ?? "environment reference"}: ${issues.map((issue) => `${issue.path.join(".") || "<root>"}: ${issue.message}`).join("; ")}`);
|
|
152
|
+
this.environment = environment;
|
|
153
|
+
this.issues = issues;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
class BrokenDevcontainerReference extends Error {
|
|
158
|
+
configPath;
|
|
159
|
+
kind = "BrokenDevcontainerReference";
|
|
160
|
+
code = "SCARN_DEVCONTAINER_REFERENCE_BROKEN";
|
|
161
|
+
constructor(configPath, discoveryPaths) {
|
|
162
|
+
super(discoveryPaths ? `Devcontainer auto-discovery found no config; checked: ${discoveryPaths.join(", ")}` : `Devcontainer config not found: ${configPath}`);
|
|
163
|
+
this.configPath = configPath;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
export { environmentNameSchema, environmentRuntimeSchema, rejectEnvironmentBranch, environmentFieldsSchema, findHostSetupVar, hostSetupVarMessage, environmentContentSchema, environmentRefSchema, environmentRefReadSchema, inlineEnvironmentReadSchema, storedEnvironmentRuntimeSchema, storedEnvironmentFieldsSchema, storedEnvironmentContentSchema, resolvedEnvironmentRefSchema, EnvironmentNotFound, EnvironmentInvalid, BrokenDevcontainerReference };
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import {
|
|
3
|
+
Environments,
|
|
4
|
+
createClient
|
|
5
|
+
} from "./chunk-3zp2qtf8.js";
|
|
6
|
+
import {
|
|
7
|
+
exports_external
|
|
8
|
+
} from "./chunk-yf15kdte.js";
|
|
9
|
+
|
|
10
|
+
// src/definitions/environments/environments-client.ts
|
|
11
|
+
var environmentContentIssueSchema = exports_external.object({
|
|
12
|
+
path: exports_external.string(),
|
|
13
|
+
message: exports_external.string()
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
class EnvironmentsApiError extends Error {
|
|
17
|
+
code;
|
|
18
|
+
status;
|
|
19
|
+
issues;
|
|
20
|
+
constructor(error) {
|
|
21
|
+
super(error.detail ?? error.title ?? JSON.stringify(error));
|
|
22
|
+
this.name = "EnvironmentsApiError";
|
|
23
|
+
this.code = error.code;
|
|
24
|
+
this.status = error.status;
|
|
25
|
+
this.issues = Array.isArray(error.errors) ? error.errors.flatMap((issue) => {
|
|
26
|
+
const parsed = environmentContentIssueSchema.safeParse(issue);
|
|
27
|
+
return parsed.success ? [parsed.data] : [];
|
|
28
|
+
}) : [];
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
function unwrap(result) {
|
|
32
|
+
if (result.error !== undefined) {
|
|
33
|
+
throw new EnvironmentsApiError(result.error);
|
|
34
|
+
}
|
|
35
|
+
return result.data;
|
|
36
|
+
}
|
|
37
|
+
function createEnvironmentsClient(baseUrl) {
|
|
38
|
+
const client = createClient({ baseUrl });
|
|
39
|
+
return buildEnvironmentsClient(new Environments({ client }));
|
|
40
|
+
}
|
|
41
|
+
var buildEnvironmentsClient = (environments) => ({
|
|
42
|
+
listByProjectId: async (projectId, options) => unwrap(await environments.listEnvironments({
|
|
43
|
+
path: { projectId },
|
|
44
|
+
headers: options?.headers
|
|
45
|
+
})),
|
|
46
|
+
get: async (projectId, name, options) => unwrap(await environments.getEnvironment({
|
|
47
|
+
path: { projectId, name },
|
|
48
|
+
...options?.version === undefined ? {} : { query: { version: options.version } },
|
|
49
|
+
headers: options?.headers
|
|
50
|
+
})),
|
|
51
|
+
publish: async (projectId, name, content, options) => unwrap(await environments.publishEnvironmentVersion({
|
|
52
|
+
path: { projectId, name },
|
|
53
|
+
body: { content },
|
|
54
|
+
headers: options?.headers
|
|
55
|
+
})),
|
|
56
|
+
delete: async (projectId, name, options) => {
|
|
57
|
+
unwrap(await environments.deleteEnvironment({
|
|
58
|
+
path: { projectId, name },
|
|
59
|
+
headers: options?.headers
|
|
60
|
+
}));
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
export { EnvironmentsApiError, createEnvironmentsClient };
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import {
|
|
3
|
+
BrokenDevcontainerReference,
|
|
4
|
+
EnvironmentInvalid,
|
|
5
|
+
EnvironmentNotFound,
|
|
6
|
+
environmentNameSchema,
|
|
7
|
+
inlineEnvironmentReadSchema
|
|
8
|
+
} from "./chunk-e0pt5x0e.js";
|
|
9
|
+
import {
|
|
10
|
+
ConnectorVarsMissing,
|
|
11
|
+
findMissingConnectorVars
|
|
12
|
+
} from "./chunk-qgkx89eg.js";
|
|
13
|
+
import {
|
|
14
|
+
exports_external
|
|
15
|
+
} from "./chunk-yf15kdte.js";
|
|
16
|
+
|
|
17
|
+
// src/resolve-environment.ts
|
|
18
|
+
var DEVCONTAINER_DISCOVERY_PATHS = [
|
|
19
|
+
".devcontainer/devcontainer.json",
|
|
20
|
+
"devcontainer.json"
|
|
21
|
+
];
|
|
22
|
+
var namedContentAsInline = ({
|
|
23
|
+
runtime,
|
|
24
|
+
vars,
|
|
25
|
+
connectors
|
|
26
|
+
}) => ({
|
|
27
|
+
kind: "inline",
|
|
28
|
+
...runtime === undefined ? {} : { runtime },
|
|
29
|
+
...vars === undefined ? {} : { envJson: vars },
|
|
30
|
+
...connectors === undefined ? {} : { connectors }
|
|
31
|
+
});
|
|
32
|
+
var namedEnvironmentEnvelopeSchema = exports_external.union([
|
|
33
|
+
exports_external.object({
|
|
34
|
+
name: environmentNameSchema,
|
|
35
|
+
version: exports_external.number().int().positive(),
|
|
36
|
+
content: exports_external.object({})
|
|
37
|
+
}),
|
|
38
|
+
exports_external.object({ name: environmentNameSchema, notFound: exports_external.literal(true) })
|
|
39
|
+
]);
|
|
40
|
+
function readEnvironmentDefinition(ref) {
|
|
41
|
+
let named;
|
|
42
|
+
if (ref?.kind === "named") {
|
|
43
|
+
const envelope = namedEnvironmentEnvelopeSchema.safeParse(ref);
|
|
44
|
+
if (!envelope.success) {
|
|
45
|
+
return new EnvironmentInvalid(undefined, envelope.error.issues);
|
|
46
|
+
}
|
|
47
|
+
if ("notFound" in envelope.data) {
|
|
48
|
+
return new EnvironmentNotFound(envelope.data.name);
|
|
49
|
+
}
|
|
50
|
+
named = {
|
|
51
|
+
name: envelope.data.name,
|
|
52
|
+
label: `environment ${envelope.data.name} v${String(envelope.data.version)}`
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
const parsedRef = inlineEnvironmentReadSchema.safeParse(ref?.kind === "named" && "content" in ref ? namedContentAsInline(ref.content) : ref);
|
|
56
|
+
if (!parsedRef.success) {
|
|
57
|
+
return new EnvironmentInvalid(named?.label, named === undefined ? parsedRef.error.issues : parsedRef.error.issues.map((issue) => ({
|
|
58
|
+
...issue,
|
|
59
|
+
path: issue.path.map((key) => key === "envJson" ? "vars" : key)
|
|
60
|
+
})));
|
|
61
|
+
}
|
|
62
|
+
const reference = parsedRef.data;
|
|
63
|
+
const runtime = reference?.runtime;
|
|
64
|
+
const envVars = reference?.envJson ?? [];
|
|
65
|
+
const connectors = reference?.connectors ?? [];
|
|
66
|
+
const missing = findMissingConnectorVars(connectors, envVars);
|
|
67
|
+
if (missing.length > 0) {
|
|
68
|
+
return new ConnectorVarsMissing(named?.label, missing);
|
|
69
|
+
}
|
|
70
|
+
return {
|
|
71
|
+
source: named ? "named" : reference?.kind ?? "repo-default",
|
|
72
|
+
...named ? { name: named.name } : {},
|
|
73
|
+
...runtime === undefined ? {} : { runtime },
|
|
74
|
+
envVars,
|
|
75
|
+
connectors
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
async function resolveEnvironment(deps, ref) {
|
|
79
|
+
const definition = readEnvironmentDefinition(ref);
|
|
80
|
+
if (definition instanceof Error)
|
|
81
|
+
return definition;
|
|
82
|
+
return resolveEnvironmentDefinition(deps, definition);
|
|
83
|
+
}
|
|
84
|
+
async function resolveEnvironmentDefinition(deps, definition) {
|
|
85
|
+
const { runtime } = definition;
|
|
86
|
+
let resolvedRuntime;
|
|
87
|
+
if (runtime?.kind === "devcontainer" && runtime.config !== undefined) {
|
|
88
|
+
if (!await deps.devcontainerExists(runtime.config)) {
|
|
89
|
+
return new BrokenDevcontainerReference(runtime.config);
|
|
90
|
+
}
|
|
91
|
+
resolvedRuntime = { kind: "devcontainer", config: runtime.config };
|
|
92
|
+
} else if (runtime === undefined || runtime.kind === "devcontainer") {
|
|
93
|
+
let discoveredConfig;
|
|
94
|
+
for (const config of DEVCONTAINER_DISCOVERY_PATHS) {
|
|
95
|
+
if (await deps.devcontainerExists(config)) {
|
|
96
|
+
discoveredConfig = config;
|
|
97
|
+
break;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
if (discoveredConfig !== undefined) {
|
|
101
|
+
resolvedRuntime = { kind: "devcontainer", config: discoveredConfig };
|
|
102
|
+
} else if (runtime?.kind === "devcontainer") {
|
|
103
|
+
return new BrokenDevcontainerReference(DEVCONTAINER_DISCOVERY_PATHS[0], DEVCONTAINER_DISCOVERY_PATHS);
|
|
104
|
+
} else {
|
|
105
|
+
resolvedRuntime = { kind: "managed", id: "bun1" };
|
|
106
|
+
}
|
|
107
|
+
} else {
|
|
108
|
+
resolvedRuntime = runtime;
|
|
109
|
+
}
|
|
110
|
+
return {
|
|
111
|
+
...definition,
|
|
112
|
+
runtime: resolvedRuntime
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export { readEnvironmentDefinition, resolveEnvironment, resolveEnvironmentDefinition };
|
|
@@ -3,10 +3,10 @@ import {
|
|
|
3
3
|
MATCH_MODES,
|
|
4
4
|
argValueSchema,
|
|
5
5
|
conditionSchema
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-evb3hw48.js";
|
|
7
7
|
import {
|
|
8
8
|
exports_external
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-yf15kdte.js";
|
|
10
10
|
|
|
11
11
|
// src/contracts/automation-document/schema.ts
|
|
12
12
|
var AUTOMATION_SCOPES = ["workItem", "project"];
|
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
// @bun
|
|
2
|
+
import {
|
|
3
|
+
MAX_ENV_VARS,
|
|
4
|
+
inheritEnvVarSchema
|
|
5
|
+
} from "./chunk-aemxz9r7.js";
|
|
2
6
|
import {
|
|
3
7
|
exports_external
|
|
4
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-yf15kdte.js";
|
|
5
9
|
|
|
6
10
|
// src/opencode-mcp.ts
|
|
11
|
+
var workerVarsSchema = exports_external.array(inheritEnvVarSchema.safeExtend({ applies: exports_external.literal("agent") })).max(MAX_ENV_VARS).refine((entries) => new Set(entries.map((entry) => entry.name)).size === entries.length, { message: "MCP worker variable names must be unique" });
|
|
7
12
|
var nonEmptyStringSchema = exports_external.string().trim().min(1);
|
|
8
13
|
var mcpStringMapSchema = exports_external.record(exports_external.string(), exports_external.string());
|
|
9
14
|
var positiveIntSchema = exports_external.int().gt(0).max(Number.MAX_SAFE_INTEGER);
|
|
@@ -48,13 +53,18 @@ var openCodeMcpRemoteConfigSchema = exports_external.object({
|
|
|
48
53
|
var openCodeMcpRefConfigSchema = exports_external.object({
|
|
49
54
|
type: exports_external.literal("ref"),
|
|
50
55
|
name: nonEmptyStringSchema.optional(),
|
|
56
|
+
workerVars: workerVarsSchema.optional(),
|
|
51
57
|
...sharedServerFields
|
|
52
58
|
}).strict();
|
|
53
59
|
var openCodeResolvedMcpServerConfigSchema = exports_external.discriminatedUnion("type", [openCodeMcpLocalConfigSchema, openCodeMcpRemoteConfigSchema]);
|
|
54
60
|
var openCodeResolvedMcpServersSchema = exports_external.record(exports_external.string(), openCodeResolvedMcpServerConfigSchema);
|
|
55
61
|
var openCodeMcpServerConfigSchema = exports_external.discriminatedUnion("type", [
|
|
56
|
-
openCodeMcpLocalConfigSchema
|
|
57
|
-
|
|
62
|
+
openCodeMcpLocalConfigSchema.extend({
|
|
63
|
+
workerVars: workerVarsSchema.optional()
|
|
64
|
+
}),
|
|
65
|
+
openCodeMcpRemoteConfigSchema.extend({
|
|
66
|
+
workerVars: workerVarsSchema.optional()
|
|
67
|
+
}),
|
|
58
68
|
openCodeMcpRefConfigSchema
|
|
59
69
|
]);
|
|
60
70
|
var openCodeMcpServersSchema = exports_external.record(exports_external.string(), openCodeMcpServerConfigSchema);
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import {
|
|
3
|
+
collectEnvPlaceholderNames,
|
|
4
|
+
isEnvPlaceholderValue,
|
|
5
|
+
openCodeResolvedMcpServerConfigSchema
|
|
6
|
+
} from "./chunk-pqtd0hr7.js";
|
|
7
|
+
import {
|
|
8
|
+
ENV_VAR_NAME_PATTERN
|
|
9
|
+
} from "./chunk-aemxz9r7.js";
|
|
10
|
+
import {
|
|
11
|
+
exports_external
|
|
12
|
+
} from "./chunk-yf15kdte.js";
|
|
13
|
+
|
|
14
|
+
// src/connectors/catalog.ts
|
|
15
|
+
var connectorAuthValues = ["none", "apiKey"];
|
|
16
|
+
var CONNECTOR_ID_PATTERN = /^[a-z0-9]+(?:-[a-z0-9]+)*$/u;
|
|
17
|
+
var CONNECTOR_DEFINITIONS = [
|
|
18
|
+
{
|
|
19
|
+
id: "playwright",
|
|
20
|
+
name: "Playwright",
|
|
21
|
+
description: "Drive a headless browser: open pages, click, type, read the page and take screenshots.",
|
|
22
|
+
auth: "none",
|
|
23
|
+
requiredVars: [],
|
|
24
|
+
mcp: {
|
|
25
|
+
type: "local",
|
|
26
|
+
command: ["npx", "-y", "@playwright/mcp@0.0.68", "--headless"]
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
id: "datadog",
|
|
31
|
+
name: "Datadog",
|
|
32
|
+
description: "Query Datadog logs, metrics, traces, monitors, dashboards and incidents (US1 site).",
|
|
33
|
+
auth: "apiKey",
|
|
34
|
+
requiredVars: [
|
|
35
|
+
{ name: "DD_API_KEY", description: "A Datadog API key." },
|
|
36
|
+
{
|
|
37
|
+
name: "DD_APPLICATION_KEY",
|
|
38
|
+
description: "A Datadog application key; its scopes limit what the agent can read and change."
|
|
39
|
+
}
|
|
40
|
+
],
|
|
41
|
+
mcp: {
|
|
42
|
+
type: "remote",
|
|
43
|
+
url: "https://mcp.datadoghq.com/v1/mcp",
|
|
44
|
+
headers: {
|
|
45
|
+
DD_API_KEY: "{env:DD_API_KEY}",
|
|
46
|
+
DD_APPLICATION_KEY: "{env:DD_APPLICATION_KEY}"
|
|
47
|
+
},
|
|
48
|
+
oauth: false
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
];
|
|
52
|
+
var E2E_FAKE_CONNECTOR_FLAG = "SCARN_E2E_FAKE_CONNECTOR";
|
|
53
|
+
var E2E_FAKE_CONNECTOR = {
|
|
54
|
+
id: "e2e-fake",
|
|
55
|
+
name: "E2E fake",
|
|
56
|
+
description: "Test-only fake MCP server for the end-to-end tests.",
|
|
57
|
+
auth: "apiKey",
|
|
58
|
+
requiredVars: [
|
|
59
|
+
{
|
|
60
|
+
name: "FAKE_API_KEY",
|
|
61
|
+
description: "Any value; the fake server needs one."
|
|
62
|
+
}
|
|
63
|
+
],
|
|
64
|
+
mcp: {
|
|
65
|
+
type: "local",
|
|
66
|
+
command: ["bun", ".scarn/e2e-fake-mcp.mjs"],
|
|
67
|
+
environment: { FAKE_API_KEY: "{env:FAKE_API_KEY}" }
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
function connectorDefinitions(env) {
|
|
71
|
+
return env[E2E_FAKE_CONNECTOR_FLAG] === "true" ? [...CONNECTOR_DEFINITIONS, E2E_FAKE_CONNECTOR] : CONNECTOR_DEFINITIONS;
|
|
72
|
+
}
|
|
73
|
+
function validateConnectorCatalog(entries) {
|
|
74
|
+
const problems = [];
|
|
75
|
+
const seen = new Set;
|
|
76
|
+
for (const entry of entries) {
|
|
77
|
+
const label = `connector "${entry.id}"`;
|
|
78
|
+
if (!CONNECTOR_ID_PATTERN.test(entry.id)) {
|
|
79
|
+
problems.push(`${label}: id must be kebab-case`);
|
|
80
|
+
}
|
|
81
|
+
if (seen.has(entry.id))
|
|
82
|
+
problems.push(`${label}: duplicate id`);
|
|
83
|
+
seen.add(entry.id);
|
|
84
|
+
if (!openCodeResolvedMcpServerConfigSchema.safeParse(entry.mcp).success) {
|
|
85
|
+
problems.push(`${label}: mcp is not a valid OpenCode MCP config`);
|
|
86
|
+
}
|
|
87
|
+
const credentialValues = Object.values(entry.mcp.type === "local" ? entry.mcp.environment ?? {} : entry.mcp.headers ?? {});
|
|
88
|
+
if (!credentialValues.every(isEnvPlaceholderValue)) {
|
|
89
|
+
problems.push(`${label}: ${entry.mcp.type === "local" ? "environment" : "headers"} values must be {env:NAME} placeholders`);
|
|
90
|
+
}
|
|
91
|
+
const declared = entry.requiredVars.map((variable) => variable.name);
|
|
92
|
+
if (new Set(declared).size !== declared.length) {
|
|
93
|
+
problems.push(`${label}: requiredVars names must be unique`);
|
|
94
|
+
}
|
|
95
|
+
for (const name of declared) {
|
|
96
|
+
if (!ENV_VAR_NAME_PATTERN.test(name)) {
|
|
97
|
+
problems.push(`${label}: requiredVars "${name}" is not a valid name`);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
const read = collectEnvPlaceholderNames(entry.mcp);
|
|
101
|
+
for (const name of read.filter((name2) => !declared.includes(name2))) {
|
|
102
|
+
problems.push(`${label}: mcp reads {env:${name}} but requiredVars omits it`);
|
|
103
|
+
}
|
|
104
|
+
for (const name of declared.filter((name2) => !read.includes(name2))) {
|
|
105
|
+
problems.push(`${label}: requiredVars lists ${name} but mcp never reads it`);
|
|
106
|
+
}
|
|
107
|
+
if (entry.auth === "none" !== (declared.length === 0)) {
|
|
108
|
+
problems.push(`${label}: auth "none" means no requiredVars, and requiredVars need an auth`);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return problems;
|
|
112
|
+
}
|
|
113
|
+
function buildCatalog(entries) {
|
|
114
|
+
const problems = validateConnectorCatalog(entries);
|
|
115
|
+
if (problems.length > 0) {
|
|
116
|
+
throw new Error(`Invalid connector catalog: ${problems.join("; ")}`);
|
|
117
|
+
}
|
|
118
|
+
return Object.freeze(Object.fromEntries(entries.map((entry) => [entry.id, entry])));
|
|
119
|
+
}
|
|
120
|
+
var runtimeEnv = globalThis.process?.env ?? {};
|
|
121
|
+
var CONNECTOR_CATALOG = buildCatalog(connectorDefinitions(runtimeEnv));
|
|
122
|
+
function isConnectorId(id) {
|
|
123
|
+
return Object.hasOwn(CONNECTOR_CATALOG, id);
|
|
124
|
+
}
|
|
125
|
+
function getConnector(id) {
|
|
126
|
+
return isConnectorId(id) ? CONNECTOR_CATALOG[id] : undefined;
|
|
127
|
+
}
|
|
128
|
+
function listConnectorSummaries() {
|
|
129
|
+
return Object.values(CONNECTOR_CATALOG).map(({ id, name, description, auth, requiredVars }) => ({
|
|
130
|
+
id,
|
|
131
|
+
name,
|
|
132
|
+
description,
|
|
133
|
+
auth,
|
|
134
|
+
requiredVars: requiredVars.map((variable) => ({ ...variable }))
|
|
135
|
+
}));
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// src/connectors/index.ts
|
|
139
|
+
var connectorIdsSchema = exports_external.array(exports_external.string()).superRefine((ids, ctx) => {
|
|
140
|
+
const seen = new Set;
|
|
141
|
+
ids.forEach((id, index) => {
|
|
142
|
+
if (!isConnectorId(id)) {
|
|
143
|
+
ctx.addIssue({
|
|
144
|
+
code: "custom",
|
|
145
|
+
path: [index],
|
|
146
|
+
message: `unknown connector "${id}"; known connectors: ${Object.keys(CONNECTOR_CATALOG).join(", ")}`
|
|
147
|
+
});
|
|
148
|
+
} else if (seen.has(id)) {
|
|
149
|
+
ctx.addIssue({
|
|
150
|
+
code: "custom",
|
|
151
|
+
path: [index],
|
|
152
|
+
message: `connector "${id}" is listed more than once`
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
seen.add(id);
|
|
156
|
+
});
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
class ConnectorVarsMissing extends Error {
|
|
160
|
+
environment;
|
|
161
|
+
missing;
|
|
162
|
+
kind = "ConnectorVarsMissing";
|
|
163
|
+
code = "SCARN_CONNECTOR_VARS_MISSING";
|
|
164
|
+
constructor(environment, missing) {
|
|
165
|
+
super(`The ${environment ?? "environment reference"} is missing variables its connectors need: ${missing.map(({ connector, vars }) => `${connector} needs ${vars.join(", ")}`).join("; ")}. Add them to the environment's vars.`);
|
|
166
|
+
this.environment = environment;
|
|
167
|
+
this.missing = missing;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
function findMissingConnectorVars(connectors, envVars) {
|
|
171
|
+
const provided = new Set(envVars.filter((entry) => entry.applies !== "setup").map((entry) => entry.name));
|
|
172
|
+
return connectors.flatMap((connector) => {
|
|
173
|
+
const vars = (CONNECTOR_CATALOG[connector]?.requiredVars ?? []).map((variable) => variable.name).filter((name) => !provided.has(name));
|
|
174
|
+
return vars.length > 0 ? [{ connector, vars }] : [];
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
function findConnectorMcpCollisions(connectors, stepMcpKeys) {
|
|
178
|
+
const ids = new Set(connectors);
|
|
179
|
+
return [...stepMcpKeys].filter((key) => ids.has(key)).sort();
|
|
180
|
+
}
|
|
181
|
+
function connectorMcpCollisionMessage(collisions) {
|
|
182
|
+
return `step mcps ${collisions.map((key) => `"${key}"`).join(", ")} collide with the environment's connectors; rename the step's MCP server or drop the connector`;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
class ConnectorMcpCollision extends Error {
|
|
186
|
+
collisions;
|
|
187
|
+
kind = "ConnectorMcpCollision";
|
|
188
|
+
code = "SCARN_ENVIRONMENT_INVALID";
|
|
189
|
+
constructor(collisions) {
|
|
190
|
+
super(connectorMcpCollisionMessage(collisions));
|
|
191
|
+
this.collisions = collisions;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
function mergeConnectorMcpServers(connectors, servers, stepMcpKeys = Object.keys(servers ?? {})) {
|
|
195
|
+
if (connectors.length === 0)
|
|
196
|
+
return servers;
|
|
197
|
+
const collisions = findConnectorMcpCollisions(connectors, stepMcpKeys);
|
|
198
|
+
if (collisions.length > 0)
|
|
199
|
+
throw new ConnectorMcpCollision(collisions);
|
|
200
|
+
const merged = { ...servers };
|
|
201
|
+
for (const id of connectors) {
|
|
202
|
+
const connector = CONNECTOR_CATALOG[id];
|
|
203
|
+
if (connector === undefined)
|
|
204
|
+
throw new Error(`Unknown connector "${id}"`);
|
|
205
|
+
merged[id] = structuredClone(connector.mcp);
|
|
206
|
+
}
|
|
207
|
+
return merged;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
export { connectorAuthValues, E2E_FAKE_CONNECTOR_FLAG, E2E_FAKE_CONNECTOR, connectorDefinitions, validateConnectorCatalog, CONNECTOR_CATALOG, isConnectorId, getConnector, listConnectorSummaries, connectorIdsSchema, ConnectorVarsMissing, findMissingConnectorVars, findConnectorMcpCollisions, connectorMcpCollisionMessage, ConnectorMcpCollision, mergeConnectorMcpServers };
|