@scarn/sdk 0.8.17 → 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.
Files changed (62) hide show
  1. package/dist/{chunk-g2mzg278.js → chunk-0c60x3v8.js} +51 -59
  2. package/dist/{chunk-dhqeg0wf.js → chunk-2tmrw253.js} +1 -1
  3. package/dist/{chunk-r03knh9j.js → chunk-3zp2qtf8.js} +80 -1
  4. package/dist/{chunk-ar6hcj1r.js → chunk-6tra3gw8.js} +7 -1
  5. package/dist/{chunk-a04phj60.js → chunk-833ef6dg.js} +121 -260
  6. package/dist/{chunk-2ekz6tr5.js → chunk-aemxz9r7.js} +18 -2
  7. package/dist/chunk-e0pt5x0e.js +167 -0
  8. package/dist/chunk-mmy80pec.js +64 -0
  9. package/dist/chunk-mzj1j0p5.js +116 -0
  10. package/dist/{chunk-cdj0yqgs.js → chunk-pqtd0hr7.js} +12 -2
  11. package/dist/chunk-qgkx89eg.js +210 -0
  12. package/dist/chunk-rphfy0fj.js +167 -0
  13. package/dist/chunk-t1dq2c2s.js +224 -0
  14. package/dist/{chunk-qs7p11rp.js → chunk-tvjcfh6s.js} +5 -1
  15. package/dist/{chunk-1wnv6rb2.js → chunk-ymywp5ht.js} +1 -1
  16. package/dist/client.js +8 -2
  17. package/dist/connectors/catalog.d.ts +49 -0
  18. package/dist/connectors/index.d.ts +45 -0
  19. package/dist/connectors/index.js +41 -0
  20. package/dist/defaults/index.js +2 -2
  21. package/dist/definitions/automations/index.js +2 -2
  22. package/dist/definitions/environments/define-environment.d.ts +39 -0
  23. package/dist/definitions/environments/environments-client.d.ts +50 -0
  24. package/dist/definitions/environments/index.d.ts +6 -0
  25. package/dist/definitions/environments/index.js +97 -0
  26. package/dist/definitions/pipelines/index.js +2 -2
  27. package/dist/definitions/steps/compile-mcps.d.ts +8 -12
  28. package/dist/definitions/steps/define-code-step.d.ts +18 -11
  29. package/dist/definitions/steps/define-step.d.ts +14 -25
  30. package/dist/definitions/steps/env.d.ts +30 -8
  31. package/dist/definitions/steps/index.js +30 -13
  32. package/dist/definitions/steps/mcp-server-config.d.ts +19 -9
  33. package/dist/definitions/steps/repo.d.ts +56 -28
  34. package/dist/definitions/steps/runtime.d.ts +54 -39
  35. package/dist/definitions/steps/step-definitions-client.d.ts +222 -63
  36. package/dist/definitions/steps/step-handle.d.ts +8 -1
  37. package/dist/definitions/validation/index.js +6 -3
  38. package/dist/definitions/validation/validate-repo.d.ts +3 -7
  39. package/dist/definitions/validation/validate-runtime.d.ts +2 -7
  40. package/dist/env-vars.d.ts +57 -1
  41. package/dist/env-vars.js +7 -1
  42. package/dist/environment.d.ts +564 -0
  43. package/dist/environment.js +46 -0
  44. package/dist/generated/index.d.ts +2 -2
  45. package/dist/generated/sdk.gen.d.ts +26 -1
  46. package/dist/generated/types.gen.d.ts +2090 -187
  47. package/dist/index.d.ts +2 -0
  48. package/dist/index.js +94 -28
  49. package/dist/opencode-mcp.d.ts +75 -4
  50. package/dist/opencode-mcp.js +2 -1
  51. package/dist/push/code-step-lookup.d.ts +6 -0
  52. package/dist/push/code-step-lookup.js +3 -1
  53. package/dist/push/collect-definitions.d.ts +13 -0
  54. package/dist/push/index.js +127 -15
  55. package/dist/push/push-from-directory.d.ts +11 -2
  56. package/dist/repo-config.d.ts +88 -30
  57. package/dist/repo-config.js +21 -5
  58. package/dist/resolve-environment.d.ts +19 -0
  59. package/dist/resolve-environment.js +19 -0
  60. package/dist/task-plane-client.d.ts +124 -22
  61. package/package.json +17 -1
  62. package/dist/chunk-2sk92cnd.js +0 -103
@@ -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 };
@@ -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
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
- openCodeMcpRemoteConfigSchema,
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 };