@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.
Files changed (82) hide show
  1. package/dist/automations/index.js +4 -4
  2. package/dist/{chunk-4ggr8af6.js → chunk-098740f7.js} +1 -1
  3. package/dist/{chunk-1yb2h6t9.js → chunk-0c60x3v8.js} +53 -61
  4. package/dist/{chunk-y2pv8d6a.js → chunk-19brnwkp.js} +1 -1
  5. package/dist/{chunk-b8hxjwag.js → chunk-2tmrw253.js} +2 -2
  6. package/dist/{chunk-z25n32z0.js → chunk-3zp2qtf8.js} +88 -9
  7. package/dist/{chunk-k4y5qt4y.js → chunk-46wmsgv7.js} +1 -1
  8. package/dist/{chunk-ar6hcj1r.js → chunk-6tra3gw8.js} +7 -1
  9. package/dist/{chunk-zf4gwg0p.js → chunk-833ef6dg.js} +170 -269
  10. package/dist/{chunk-11hbmexe.js → chunk-9we3vqsv.js} +1 -1
  11. package/dist/{chunk-5zsavw98.js → chunk-aemxz9r7.js} +19 -3
  12. package/dist/{chunk-43y7tfn4.js → chunk-aknfw08j.js} +1 -1
  13. package/dist/chunk-e0pt5x0e.js +167 -0
  14. package/dist/{chunk-cnxaagfj.js → chunk-evb3hw48.js} +1 -1
  15. package/dist/chunk-mmy80pec.js +64 -0
  16. package/dist/chunk-mzj1j0p5.js +116 -0
  17. package/dist/{chunk-76d1bwwz.js → chunk-p1fs73bd.js} +2 -2
  18. package/dist/{chunk-e1h021kq.js → chunk-pqtd0hr7.js} +13 -3
  19. package/dist/chunk-qgkx89eg.js +210 -0
  20. package/dist/chunk-rphfy0fj.js +167 -0
  21. package/dist/chunk-t1dq2c2s.js +224 -0
  22. package/dist/{chunk-7bpy3w3z.js → chunk-tvjcfh6s.js} +5 -1
  23. package/dist/{chunk-63f90zky.js → chunk-y34zsgsw.js} +1 -1
  24. package/dist/{chunk-skzxcba3.js → chunk-yf15kdte.js} +7087 -1944
  25. package/dist/{chunk-efs789y2.js → chunk-ymywp5ht.js} +2 -2
  26. package/dist/client.js +8 -2
  27. package/dist/connectors/catalog.d.ts +49 -0
  28. package/dist/connectors/index.d.ts +45 -0
  29. package/dist/connectors/index.js +41 -0
  30. package/dist/contracts/artifacts.js +2 -2
  31. package/dist/contracts/automation-document/index.js +3 -3
  32. package/dist/contracts/pipeline-document/index.js +2 -2
  33. package/dist/contracts/step-artifact-submissions.js +2 -2
  34. package/dist/contracts/work-item-changes.js +1 -1
  35. package/dist/defaults/index.js +2 -2
  36. package/dist/definitions/automations/index.js +3 -3
  37. package/dist/definitions/environments/define-environment.d.ts +39 -0
  38. package/dist/definitions/environments/environments-client.d.ts +50 -0
  39. package/dist/definitions/environments/index.d.ts +6 -0
  40. package/dist/definitions/environments/index.js +97 -0
  41. package/dist/definitions/pipelines/index.js +3 -3
  42. package/dist/definitions/steps/compile-mcps.d.ts +8 -12
  43. package/dist/definitions/steps/define-code-step.d.ts +18 -11
  44. package/dist/definitions/steps/define-step.d.ts +14 -25
  45. package/dist/definitions/steps/env.d.ts +30 -8
  46. package/dist/definitions/steps/index.js +35 -18
  47. package/dist/definitions/steps/mcp-server-config.d.ts +19 -9
  48. package/dist/definitions/steps/repo.d.ts +56 -28
  49. package/dist/definitions/steps/runtime.d.ts +54 -39
  50. package/dist/definitions/steps/step-definitions-client.d.ts +222 -63
  51. package/dist/definitions/steps/step-handle.d.ts +8 -1
  52. package/dist/definitions/validation/index.js +10 -7
  53. package/dist/definitions/validation/validate-repo.d.ts +3 -7
  54. package/dist/definitions/validation/validate-runtime.d.ts +2 -7
  55. package/dist/devcontainer-config-path.js +2 -2
  56. package/dist/env-vars.d.ts +57 -1
  57. package/dist/env-vars.js +8 -2
  58. package/dist/environment.d.ts +564 -0
  59. package/dist/environment.js +46 -0
  60. package/dist/generated/index.d.ts +2 -2
  61. package/dist/generated/sdk.gen.d.ts +35 -10
  62. package/dist/generated/types.gen.d.ts +2151 -188
  63. package/dist/health-checks.d.ts +3 -3
  64. package/dist/health-checks.js +2 -2
  65. package/dist/index.d.ts +2 -0
  66. package/dist/index.js +100 -34
  67. package/dist/managed-runtimes.js +2 -2
  68. package/dist/opencode-mcp.d.ts +75 -4
  69. package/dist/opencode-mcp.js +3 -2
  70. package/dist/pipelines/index.js +3 -3
  71. package/dist/push/code-step-lookup.d.ts +6 -0
  72. package/dist/push/code-step-lookup.js +3 -1
  73. package/dist/push/collect-definitions.d.ts +13 -0
  74. package/dist/push/index.js +132 -20
  75. package/dist/push/push-from-directory.d.ts +11 -2
  76. package/dist/repo-config.d.ts +88 -30
  77. package/dist/repo-config.js +22 -6
  78. package/dist/resolve-environment.d.ts +19 -0
  79. package/dist/resolve-environment.js +19 -0
  80. package/dist/task-plane-client.d.ts +139 -22
  81. package/package.json +17 -1
  82. package/dist/chunk-xzx08r6y.js +0 -103
@@ -2,10 +2,10 @@
2
2
  import {
3
3
  PipelineDefinitions,
4
4
  createClient
5
- } from "./chunk-z25n32z0.js";
5
+ } from "./chunk-3zp2qtf8.js";
6
6
  import {
7
7
  exports_external
8
- } from "./chunk-skzxcba3.js";
8
+ } from "./chunk-yf15kdte.js";
9
9
 
10
10
  // src/definitions/pipelines/pipeline-definitions-client.ts
11
11
  var pipelineDocumentIssueSchema = exports_external.object({
package/dist/client.js CHANGED
@@ -2,12 +2,14 @@
2
2
  import {
3
3
  createScarnClient,
4
4
  createTaskPlaneClient
5
- } from "./chunk-7bpy3w3z.js";
5
+ } from "./chunk-tvjcfh6s.js";
6
6
  import {
7
7
  Api,
8
8
  Automations,
9
9
  Billing,
10
+ Connectors,
10
11
  Conversations,
12
+ Environments,
11
13
  GitHubIntegrations,
12
14
  Inbox,
13
15
  NotificationRules,
@@ -16,6 +18,7 @@ import {
16
18
  ProjectArtifacts,
17
19
  ProjectIntegrations,
18
20
  ProjectInvites,
21
+ ProjectSecrets,
19
22
  Projects,
20
23
  ScarnClient,
21
24
  Secrets,
@@ -28,13 +31,15 @@ import {
28
31
  WorkItemCommentDrafts,
29
32
  WorkItemComments,
30
33
  WorkItems
31
- } from "./chunk-z25n32z0.js";
34
+ } from "./chunk-3zp2qtf8.js";
32
35
  import"./chunk-y64skrwp.js";
33
36
  export {
34
37
  Api,
35
38
  Automations,
36
39
  Billing,
40
+ Connectors,
37
41
  Conversations,
42
+ Environments,
38
43
  GitHubIntegrations,
39
44
  Inbox,
40
45
  NotificationRules,
@@ -43,6 +48,7 @@ export {
43
48
  ProjectArtifacts,
44
49
  ProjectIntegrations,
45
50
  ProjectInvites,
51
+ ProjectSecrets,
46
52
  Projects,
47
53
  ScarnClient,
48
54
  Secrets,
@@ -0,0 +1,49 @@
1
+ /**
2
+ * The Scarn connector catalog: pre-built MCP servers an environment turns on
3
+ * with `connectors: [id, …]`. Each entry's `mcp` reads credentials only
4
+ * through `{env:NAME}` placeholders, and every placeholder is one of its
5
+ * `requiredVars`; the environment's `vars` provide them by any source.
6
+ * `validateConnectorCatalog` enforces this when the module loads.
7
+ */
8
+ import { type ResolvedOpenCodeMcpServerConfig } from "../opencode-mcp";
9
+ /**
10
+ * How a connector authenticates. `none` is for local servers that need no
11
+ * credentials; `apiKey` reads static keys from `requiredVars`. OAuth joins
12
+ * this union in a later slice.
13
+ */
14
+ export declare const connectorAuthValues: readonly ["none", "apiKey"];
15
+ export type ConnectorAuth = (typeof connectorAuthValues)[number];
16
+ export type ConnectorRequiredVar = {
17
+ name: string;
18
+ description: string;
19
+ };
20
+ export type ConnectorDefinition = {
21
+ id: string;
22
+ name: string;
23
+ description: string;
24
+ auth: ConnectorAuth;
25
+ requiredVars: readonly ConnectorRequiredVar[];
26
+ mcp: ResolvedOpenCodeMcpServerConfig;
27
+ };
28
+ /** What the API exposes: everything but the MCP config. */
29
+ export type ConnectorSummary = Omit<ConnectorDefinition, "mcp" | "requiredVars"> & {
30
+ requiredVars: ConnectorRequiredVar[];
31
+ };
32
+ /** The env flag that adds {@link E2E_FAKE_CONNECTOR} to the catalog. */
33
+ export declare const E2E_FAKE_CONNECTOR_FLAG = "SCARN_E2E_FAKE_CONNECTOR";
34
+ /**
35
+ * A test-only connector for `packages/e2e-tests`. It runs the fake MCP server
36
+ * the e2e repository commits at `.scarn/e2e-fake-mcp.mjs`, and joins the
37
+ * catalog only in a process started with `SCARN_E2E_FAKE_CONNECTOR=true`. The
38
+ * e2e uses it through a named environment, which `scarn pipelines push`, the
39
+ * server and the worker all validate, so each of them needs the flag.
40
+ */
41
+ export declare const E2E_FAKE_CONNECTOR: ConnectorDefinition;
42
+ /** The catalog's entries, plus the e2e fake when `env` sets its flag. */
43
+ export declare function connectorDefinitions(env: Readonly<Record<string, string | undefined>>): readonly ConnectorDefinition[];
44
+ /** Returns every problem with a catalog; empty when it is valid. */
45
+ export declare function validateConnectorCatalog(entries: readonly ConnectorDefinition[]): string[];
46
+ export declare const CONNECTOR_CATALOG: Readonly<Record<string, ConnectorDefinition>>;
47
+ export declare function isConnectorId(id: string): boolean;
48
+ export declare function getConnector(id: string): ConnectorDefinition | undefined;
49
+ export declare function listConnectorSummaries(): ConnectorSummary[];
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Connectors: the catalog, the environment's `connectors` field, and the
3
+ * rules shared by the SDK, core and the worker (required vars, merging into a
4
+ * step's MCP servers, and the step `mcps` collision rule).
5
+ */
6
+ import { z } from "zod";
7
+ import type { EnvVarSpecInput } from "../env-vars";
8
+ import type { ResolvedOpenCodeMcpServers } from "../opencode-mcp";
9
+ export * from "./catalog";
10
+ export declare const connectorIdsSchema: z.ZodArray<z.ZodString>;
11
+ export type ConnectorVarsMissingEntry = {
12
+ connector: string;
13
+ vars: string[];
14
+ };
15
+ export declare class ConnectorVarsMissing extends Error {
16
+ readonly environment: string | undefined;
17
+ readonly missing: readonly ConnectorVarsMissingEntry[];
18
+ readonly kind = "ConnectorVarsMissing";
19
+ readonly code = "SCARN_CONNECTOR_VARS_MISSING";
20
+ /** `environment` is `environment <name> v<N>` for a named environment. */
21
+ constructor(environment: string | undefined, missing: readonly ConnectorVarsMissingEntry[]);
22
+ }
23
+ /**
24
+ * For each connector, the required variables the environment does not give
25
+ * the agent. A setup-only var does not count: the MCP server runs in the
26
+ * agent.
27
+ */
28
+ export declare function findMissingConnectorVars(connectors: readonly string[], envVars: readonly Pick<EnvVarSpecInput, "name" | "applies">[]): ConnectorVarsMissingEntry[];
29
+ /** Step `mcps` keys that reuse a connector id (decision 9). */
30
+ export declare function findConnectorMcpCollisions(connectors: readonly string[], stepMcpKeys: Iterable<string>): string[];
31
+ export declare function connectorMcpCollisionMessage(collisions: readonly string[]): string;
32
+ export declare class ConnectorMcpCollision extends Error {
33
+ readonly collisions: readonly string[];
34
+ readonly kind = "ConnectorMcpCollision";
35
+ readonly code = "SCARN_ENVIRONMENT_INVALID";
36
+ constructor(collisions: readonly string[]);
37
+ }
38
+ /**
39
+ * The step's MCP servers plus each connector's catalog config under its id.
40
+ * Throws `ConnectorMcpCollision` when one of `stepMcpKeys` (the step's own
41
+ * `mcps` keys; default: every key of `servers`) reuses a connector id. Other
42
+ * entries under a connector id, such as a disabled repository server, are
43
+ * replaced.
44
+ */
45
+ export declare function mergeConnectorMcpServers(connectors: readonly string[], servers: ResolvedOpenCodeMcpServers | null, stepMcpKeys?: Iterable<string>): ResolvedOpenCodeMcpServers | null;
@@ -0,0 +1,41 @@
1
+ // @bun
2
+ import {
3
+ CONNECTOR_CATALOG,
4
+ ConnectorMcpCollision,
5
+ ConnectorVarsMissing,
6
+ E2E_FAKE_CONNECTOR,
7
+ E2E_FAKE_CONNECTOR_FLAG,
8
+ connectorAuthValues,
9
+ connectorDefinitions,
10
+ connectorIdsSchema,
11
+ connectorMcpCollisionMessage,
12
+ findConnectorMcpCollisions,
13
+ findMissingConnectorVars,
14
+ getConnector,
15
+ isConnectorId,
16
+ listConnectorSummaries,
17
+ mergeConnectorMcpServers,
18
+ validateConnectorCatalog
19
+ } from "../chunk-qgkx89eg.js";
20
+ import"../chunk-pqtd0hr7.js";
21
+ import"../chunk-aemxz9r7.js";
22
+ import"../chunk-yf15kdte.js";
23
+ import"../chunk-y64skrwp.js";
24
+ export {
25
+ CONNECTOR_CATALOG,
26
+ ConnectorMcpCollision,
27
+ ConnectorVarsMissing,
28
+ E2E_FAKE_CONNECTOR,
29
+ E2E_FAKE_CONNECTOR_FLAG,
30
+ connectorAuthValues,
31
+ connectorDefinitions,
32
+ connectorIdsSchema,
33
+ connectorMcpCollisionMessage,
34
+ findConnectorMcpCollisions,
35
+ findMissingConnectorVars,
36
+ getConnector,
37
+ isConnectorId,
38
+ listConnectorSummaries,
39
+ mergeConnectorMcpServers,
40
+ validateConnectorCatalog
41
+ };
@@ -10,8 +10,8 @@ import {
10
10
  isEmbeddableArtifactExtension,
11
11
  matchArtifactNode,
12
12
  readArtifactKeyword
13
- } from "../chunk-y2pv8d6a.js";
14
- import"../chunk-skzxcba3.js";
13
+ } from "../chunk-19brnwkp.js";
14
+ import"../chunk-yf15kdte.js";
15
15
  import"../chunk-y64skrwp.js";
16
16
  export {
17
17
  ARTIFACT_SCHEMA_KEYWORD,
@@ -13,9 +13,9 @@ import {
13
13
  automationTargetSchema,
14
14
  eventHasChild,
15
15
  scopeOfEvent
16
- } from "../../chunk-76d1bwwz.js";
17
- import"../../chunk-cnxaagfj.js";
18
- import"../../chunk-skzxcba3.js";
16
+ } from "../../chunk-p1fs73bd.js";
17
+ import"../../chunk-evb3hw48.js";
18
+ import"../../chunk-yf15kdte.js";
19
19
  import"../../chunk-y64skrwp.js";
20
20
  export {
21
21
  AUTOMATION_EVENTS,
@@ -40,7 +40,7 @@ import {
40
40
  succeedNodeSchema,
41
41
  toleratedFailuresSchema,
42
42
  waitNodeSchema
43
- } from "../../chunk-cnxaagfj.js";
43
+ } from "../../chunk-evb3hw48.js";
44
44
  import {
45
45
  BUILT_IN_ERRORS,
46
46
  CONVERSATION_RESULT_SCHEMA,
@@ -50,7 +50,7 @@ import {
50
50
  WAIT_ERRORS,
51
51
  decisionResultSchema
52
52
  } from "../../chunk-01nfqm18.js";
53
- import"../../chunk-skzxcba3.js";
53
+ import"../../chunk-yf15kdte.js";
54
54
  import"../../chunk-y64skrwp.js";
55
55
  export {
56
56
  ALIAS_PATTERN,
@@ -3,10 +3,10 @@ import {
3
3
  artifactAcceptsFile,
4
4
  artifactFileExtension,
5
5
  findArtifactFields
6
- } from "../chunk-y2pv8d6a.js";
6
+ } from "../chunk-19brnwkp.js";
7
7
  import {
8
8
  exports_external
9
- } from "../chunk-skzxcba3.js";
9
+ } from "../chunk-yf15kdte.js";
10
10
  import"../chunk-y64skrwp.js";
11
11
 
12
12
  // src/contracts/step-artifact-submissions.ts
@@ -1,7 +1,7 @@
1
1
  // @bun
2
2
  import {
3
3
  exports_external
4
- } from "../chunk-skzxcba3.js";
4
+ } from "../chunk-yf15kdte.js";
5
5
  import"../chunk-y64skrwp.js";
6
6
 
7
7
  // src/contracts/work-item-changes.ts
@@ -4,8 +4,8 @@ import {
4
4
  } from "../chunk-rt9tq4j6.js";
5
5
  import {
6
6
  createScarnClient
7
- } from "../chunk-7bpy3w3z.js";
8
- import"../chunk-z25n32z0.js";
7
+ } from "../chunk-tvjcfh6s.js";
8
+ import"../chunk-3zp2qtf8.js";
9
9
  import"../chunk-y64skrwp.js";
10
10
 
11
11
  // src/defaults/auth-file.ts
@@ -2,9 +2,9 @@
2
2
  import {
3
3
  AutomationsApiError,
4
4
  createAutomationsClient
5
- } from "../../chunk-b8hxjwag.js";
6
- import"../../chunk-z25n32z0.js";
7
- import"../../chunk-skzxcba3.js";
5
+ } from "../../chunk-2tmrw253.js";
6
+ import"../../chunk-3zp2qtf8.js";
7
+ import"../../chunk-yf15kdte.js";
8
8
  import"../../chunk-y64skrwp.js";
9
9
  export {
10
10
  AutomationsApiError,
@@ -0,0 +1,39 @@
1
+ import { type EnvironmentContentOutput } from "../../environment";
2
+ import { type EnvRecord } from "../steps/env";
3
+ import { type RuntimeSpec } from "../steps/runtime";
4
+ export type DefineEnvironmentInput<TEnv extends EnvRecord = EnvRecord> = {
5
+ /** The name steps use to refer to it: `[a-z0-9][a-z0-9-]*`. */
6
+ name: string;
7
+ description?: string;
8
+ /** Defaults to the repository's runtime. */
9
+ runtime?: RuntimeSpec;
10
+ /**
11
+ * A record only: an environment is shared by steps with different inputs,
12
+ * so it has no function form and no `{{input.…}}` tokens.
13
+ */
14
+ vars?: TEnv;
15
+ /**
16
+ * Scarn catalog connectors to turn on, e.g. `["datadog"]`. `vars` must
17
+ * provide each connector's required variables.
18
+ */
19
+ connectors?: readonly string[];
20
+ };
21
+ /** A named environment's compiled content: what push uploads. */
22
+ export type EnvironmentContent = EnvironmentContentOutput;
23
+ /**
24
+ * What `defineEnvironment` returns. A step can use it in place of the
25
+ * environment's name. `__env` is a phantom field: it exists only in the type,
26
+ * so a step's prompt `env` can be typed from the environment's `vars`.
27
+ */
28
+ export type EnvironmentHandle<TEnv extends EnvRecord = EnvRecord> = {
29
+ readonly kind: "environment";
30
+ readonly name: string;
31
+ readonly content: EnvironmentContent;
32
+ readonly __env: TEnv;
33
+ };
34
+ /**
35
+ * Defines a named environment. Runs the checks inline environments run (no
36
+ * static secrets, no setup vars on host, known connectors) plus every
37
+ * connector's required vars, and throws on the first problem.
38
+ */
39
+ export declare function defineEnvironment<const TEnv extends EnvRecord = Record<never, never>>(config: DefineEnvironmentInput<TEnv>): EnvironmentHandle<TEnv>;
@@ -0,0 +1,50 @@
1
+ import { z } from "zod";
2
+ import { Environments } from "../../generated/sdk.gen";
3
+ import type { GetApiProjectsByProjectIdEnvironmentsByNameResponses, GetApiProjectsByProjectIdEnvironmentsResponses, PutApiProjectsByProjectIdEnvironmentsByNameData, PutApiProjectsByProjectIdEnvironmentsByNameResponses } from "../../generated/types.gen";
4
+ type RequestOptions = {
5
+ headers?: Record<string, unknown> | undefined;
6
+ };
7
+ export type EnvironmentSummary = GetApiProjectsByProjectIdEnvironmentsResponses[200][number];
8
+ export type EnvironmentDetail = GetApiProjectsByProjectIdEnvironmentsByNameResponses[200];
9
+ export type PublishEnvironmentContent = PutApiProjectsByProjectIdEnvironmentsByNameData["body"]["content"];
10
+ export type PublishEnvironmentResult = PutApiProjectsByProjectIdEnvironmentsByNameResponses[200];
11
+ declare const environmentContentIssueSchema: z.ZodObject<{
12
+ path: z.ZodString;
13
+ message: z.ZodString;
14
+ }, z.core.$strip>;
15
+ /** One validation error the server reports for rejected environment content. */
16
+ export type EnvironmentContentIssue = z.infer<typeof environmentContentIssueSchema>;
17
+ type ApiError = {
18
+ title?: string;
19
+ detail?: string;
20
+ code?: string;
21
+ status?: number;
22
+ errors?: unknown;
23
+ };
24
+ /**
25
+ * Thrown when the API rejects a request. `issues` carries the per-path
26
+ * validation errors of a `VALIDATION` rejection.
27
+ */
28
+ export declare class EnvironmentsApiError extends Error {
29
+ readonly code: string | undefined;
30
+ readonly status: number | undefined;
31
+ readonly issues: readonly EnvironmentContentIssue[];
32
+ constructor(error: ApiError);
33
+ }
34
+ export type EnvironmentsClient = ReturnType<typeof buildEnvironmentsClient>;
35
+ export declare function createEnvironmentsClient(baseUrl: string): EnvironmentsClient;
36
+ declare const buildEnvironmentsClient: (environments: Environments) => {
37
+ listByProjectId: (projectId: string, options?: RequestOptions) => Promise<EnvironmentSummary[]>;
38
+ /** The latest version's content, or version `options.version` when given. */
39
+ get: (projectId: string, name: string, options?: RequestOptions & {
40
+ version?: number;
41
+ }) => Promise<EnvironmentDetail>;
42
+ /**
43
+ * Publishes `content` as the environment's next version, creating the
44
+ * environment when the name is new or deleted. `published` is false when it
45
+ * matched the latest version.
46
+ */
47
+ publish: (projectId: string, name: string, content: PublishEnvironmentContent, options?: RequestOptions) => Promise<PublishEnvironmentResult>;
48
+ delete: (projectId: string, name: string, options?: RequestOptions) => Promise<void>;
49
+ };
50
+ export {};
@@ -0,0 +1,6 @@
1
+ export * from "./define-environment";
2
+ export * from "./environments-client";
3
+ export { Env, type EnvEntry, type EnvInherit, type EnvRecord, type EnvSecret, type EnvValue, } from "../steps/env";
4
+ export { Runtime, type DevcontainerRuntimeSpec, type HostRuntimeSpec, type ManagedRuntimeSpec, type RuntimeSpec, } from "../steps/runtime";
5
+ export { environmentContentSchema, type EnvironmentContentInput, } from "../../environment";
6
+ export { isEnvironmentHandle } from "../../push/code-step-lookup";
@@ -0,0 +1,97 @@
1
+ // @bun
2
+ import {
3
+ EnvironmentsApiError,
4
+ createEnvironmentsClient
5
+ } from "../../chunk-mmy80pec.js";
6
+ import {
7
+ Env,
8
+ Runtime,
9
+ assertNoSetupVarsOnHost,
10
+ compileConnectors,
11
+ normalizeEnv
12
+ } from "../../chunk-t1dq2c2s.js";
13
+ import {
14
+ isEnvironmentHandle
15
+ } from "../../chunk-6tra3gw8.js";
16
+ import {
17
+ environmentContentSchema,
18
+ environmentNameSchema
19
+ } from "../../chunk-e0pt5x0e.js";
20
+ import"../../chunk-098740f7.js";
21
+ import"../../chunk-46wmsgv7.js";
22
+ import {
23
+ findMissingConnectorVars
24
+ } from "../../chunk-qgkx89eg.js";
25
+ import"../../chunk-pqtd0hr7.js";
26
+ import {
27
+ containsInputToken
28
+ } from "../../chunk-aemxz9r7.js";
29
+ import"../../chunk-3zp2qtf8.js";
30
+ import"../../chunk-yf15kdte.js";
31
+ import"../../chunk-y64skrwp.js";
32
+
33
+ // src/definitions/environments/define-environment.ts
34
+ function compileContent(owner, config) {
35
+ if (typeof config.vars === "function") {
36
+ throw new Error(`${owner}: vars must be a record; an environment is shared across steps with different inputs, so it has no function form.`);
37
+ }
38
+ const vars = normalizeEnv(config.vars);
39
+ const tokenVar = (vars ?? []).find((entry) => [
40
+ entry.source === "value" ? entry.value : undefined,
41
+ entry.source === "inherit" ? entry.default : undefined
42
+ ].some((value) => value !== undefined && containsInputToken(value)));
43
+ if (tokenVar !== undefined) {
44
+ throw new Error(`${owner} env "${tokenVar.name}": an environment is shared across steps with different inputs, so it cannot use {{input.\u2026}} tokens. Put input-dependent vars on the step's inline environment.`);
45
+ }
46
+ assertNoSetupVarsOnHost(vars, config.runtime, owner);
47
+ const connectors = compileConnectors(config.connectors, owner);
48
+ assertConnectorVars(owner, connectors ?? [], vars ?? []);
49
+ const parsed = environmentContentSchema.safeParse({
50
+ ...config.description === undefined ? {} : { description: config.description },
51
+ ...config.runtime === undefined ? {} : { runtime: config.runtime },
52
+ ...vars === null ? {} : { vars },
53
+ ...connectors === undefined ? {} : { connectors }
54
+ });
55
+ if (parsed.success)
56
+ return parsed.data;
57
+ throw new Error(`${owner}: ${parsed.error.issues.map((issue) => issue.path.length > 0 ? `${issue.path.map(String).join(".")}: ${issue.message}` : issue.message).join("; ")}`);
58
+ }
59
+ function assertConnectorVars(owner, connectors, vars) {
60
+ const missing = findMissingConnectorVars(connectors, vars);
61
+ if (missing.length === 0)
62
+ return;
63
+ throw new Error(`${owner} is missing variables its connectors need: ${missing.map(({ connector, vars: vars2 }) => `${connector} needs ${vars2.join(", ")}`).join("; ")}. Add them to the environment's vars.`);
64
+ }
65
+ function defineEnvironment(config) {
66
+ const owner = `Environment "${config.name}"`;
67
+ const name = environmentNameSchema.safeParse(config.name);
68
+ if (!name.success) {
69
+ throw new Error(`${owner}: name ${name.error.issues.map((issue) => issue.message).join("; ")}`);
70
+ }
71
+ if ("branch" in config) {
72
+ throw new Error(`${owner}: environments have no branch; use the step's repo baseBranch.`);
73
+ }
74
+ let content;
75
+ try {
76
+ content = compileContent(owner, config);
77
+ } catch (error) {
78
+ if (error instanceof Error && !error.message.startsWith(owner)) {
79
+ throw new Error(`${owner}: ${error.message}`, { cause: error });
80
+ }
81
+ throw error;
82
+ }
83
+ return Object.freeze({
84
+ kind: "environment",
85
+ name: name.data,
86
+ content
87
+ });
88
+ }
89
+ export {
90
+ Env,
91
+ EnvironmentsApiError,
92
+ Runtime,
93
+ createEnvironmentsClient,
94
+ defineEnvironment,
95
+ environmentContentSchema,
96
+ isEnvironmentHandle
97
+ };
@@ -5,9 +5,9 @@ import {
5
5
  WORK_ITEM_TOP_LEVEL_FIELDS,
6
6
  createPipelineDefinitionsClient,
7
7
  resolveWorkItemFieldPath
8
- } from "../../chunk-efs789y2.js";
9
- import"../../chunk-z25n32z0.js";
10
- import"../../chunk-skzxcba3.js";
8
+ } from "../../chunk-ymywp5ht.js";
9
+ import"../../chunk-3zp2qtf8.js";
10
+ import"../../chunk-yf15kdte.js";
11
11
  import"../../chunk-y64skrwp.js";
12
12
  export {
13
13
  PipelineDefinitionsApiError,
@@ -1,19 +1,10 @@
1
- import type { EnvVarSpec, EnvVarsInput } from "../../env-vars";
1
+ import type { EnvVarsInput } from "../../env-vars";
2
2
  import type { HealthChecksInput } from "../../health-checks";
3
3
  import type { OpenCodeMcpServers } from "../../opencode-mcp";
4
4
  import { type McpHandle } from "./define-mcp";
5
- /**
6
- * Compiles a step's `mcps` (`defineMcp` handles keyed by the step's server
7
- * key) into the wire fields, and merges them with the step's own
8
- * `healthChecks` and `environment.vars`.
9
- */
10
- type InheritEnvVarSpec = Extract<EnvVarSpec, {
11
- source: "inherit";
12
- }>;
13
5
  export type CompiledMcps = {
14
6
  opencodeMcpJson: OpenCodeMcpServers;
15
7
  healthChecks: HealthChecksInput;
16
- envEntries: InheritEnvVarSpec[];
17
8
  };
18
9
  export type StepMcpFields = {
19
10
  opencodeMcpJson: OpenCodeMcpServers | null;
@@ -22,13 +13,18 @@ export type StepMcpFields = {
22
13
  };
23
14
  /** Throws when a value under `mcps` is not a `defineMcp` handle. */
24
15
  export declare function compileMcps(mcps: Readonly<Record<string, McpHandle>>, stepKey: string): CompiledMcps;
16
+ /**
17
+ * Throws when a step `mcps` key reuses a connector id of the step's
18
+ * environment handle. A name-only environment is checked at publish and
19
+ * startup instead.
20
+ */
21
+ export declare function assertNoConnectorMcpCollisions(stepKey: string, environment: unknown, mcps: Readonly<Record<string, McpHandle>> | undefined): void;
25
22
  /**
26
23
  * Merges compiled `mcps` into the step's own fields: MCP checks run before the
27
- * step's own, and a step var replaces an MCP var of the same name.
24
+ * step's own. Variable declarations stay on each server until worker resolution.
28
25
  */
29
26
  export declare function mergeStepMcps(stepKey: string, input: {
30
27
  mcps: Readonly<Record<string, McpHandle>> | undefined;
31
28
  healthChecks: HealthChecksInput | null | undefined;
32
29
  envJson: EnvVarsInput | null;
33
30
  }): StepMcpFields;
34
- export {};
@@ -2,8 +2,10 @@ import type { ZodType } from "zod";
2
2
  import type { EffectiveResult, StepConcurrency, StepRetryEntry } from "./define-step";
3
3
  import type { BuiltInError } from "../../pipelines/types";
4
4
  import { type StepHandle } from "./step-handle";
5
- import { type CodeStepEnvironment } from "./runtime";
5
+ import { type InlineCodeStepEnvironment, type NamedStepEnvironment } from "./runtime";
6
+ import type { EnvRecord, PromptEnvContext } from "./env";
6
7
  import type { CodeStepFeature } from "./step-features";
8
+ import { type RepoField, type RepoSpec } from "./repo";
7
9
  /** What the worker passes a code step besides its input. */
8
10
  export type CodeStepContext = {
9
11
  /**
@@ -14,7 +16,7 @@ export type CodeStepContext = {
14
16
  artifactsDir: string;
15
17
  };
16
18
  export type CodeStepFn<TInput, TResult> = (input: TInput, context: CodeStepContext) => TResult | Promise<TResult>;
17
- export type DefineCodeStepInput<TInput extends ZodType = ZodType, TResult extends ZodType = ZodType, TFeatures extends ReadonlyArray<CodeStepFeature> = never[]> = {
19
+ export type DefineCodeStepInput<TInput extends ZodType = ZodType, TResult extends ZodType = ZodType, TFeatures extends ReadonlyArray<CodeStepFeature> = never[], TEnv extends EnvRecord = EnvRecord, TNamed extends NamedStepEnvironment | undefined = NamedStepEnvironment | undefined> = {
18
20
  key: string;
19
21
  name: string;
20
22
  description?: string | null;
@@ -43,23 +45,28 @@ export type DefineCodeStepInput<TInput extends ZodType = ZodType, TResult extend
43
45
  */
44
46
  features?: TFeatures;
45
47
  /**
46
- * Where the step's runner executes (`runtime`) and the environment variables
47
- * it receives (`vars`). The function reads the variables back through
48
- * `process.env`; unlike `defineStep()`, there is no typed `env` argument to
49
- * `fn`.
48
+ * A named environment (its name or `defineEnvironment` handle), or inline
49
+ * runtime and environment variables (`vars`).
50
+ * The function reads the variables back through `process.env`; unlike
51
+ * `defineStep()`, there is no typed `env` argument to `fn`.
50
52
  *
51
- * Omitting `runtime` compiles to `Runtime.managed.bun1()`, a worker-supplied
52
- * container. `Runtime.devcontainer()` opts into the project's own container,
53
- * which must then provide a JS runtime for the runner script.
53
+ * For an inline environment, omitting `runtime` compiles to
54
+ * `Runtime.managed.bun1()`, a worker-supplied container.
55
+ * `Runtime.devcontainer()` opts into the project's own container, which must
56
+ * then provide a JS runtime for the runner script.
54
57
  *
55
58
  * `Runtime.host()` is not supported: a code step runs repo code, so it needs
56
59
  * a workspace, and the host runtime has none. It is a type error here and
57
60
  * `validateDefinitionSpecs` rejects it for hand-built specs.
61
+ * A handle whose runtime is host throws here; a name's runtime is checked by
62
+ * the worker after resolution.
58
63
  *
59
64
  * `repo` follows the same rules as for `defineStep()`; `result` is typed from
60
65
  * `resultSchema`.
61
66
  */
62
- environment?: CodeStepEnvironment<TInput["_output"], TResult["_output"]>;
67
+ environment?: InlineCodeStepEnvironment<TInput["_output"], TEnv> | TNamed;
68
+ /** `env` is typed from the environment as `defineStep()`'s prompt `env` is. */
69
+ repo?: RepoField<TInput["_output"], TResult["_output"], RepoSpec, PromptEnvContext<TEnv, TNamed>>;
63
70
  status?: "draft" | "active";
64
71
  /**
65
72
  * Error names this step can fail with, beyond the built-in ones. A
@@ -78,7 +85,7 @@ export type DefineCodeStepInput<TInput extends ZodType = ZodType, TResult extend
78
85
  * `entrypoint.fn` reference attached instead — see `StepDefinitionSpec`'s
79
86
  * own doc comment for what happens to it during collection.
80
87
  */
81
- export declare function codeStep<TInput extends ZodType = ZodType, TResult extends ZodType = ZodType, const TFeatures extends ReadonlyArray<CodeStepFeature> = never[], const TErrors extends string = never>(config: Omit<DefineCodeStepInput<TInput, TResult, TFeatures>, "errors" | "retry"> & {
88
+ export declare function codeStep<TInput extends ZodType = ZodType, TResult extends ZodType = ZodType, const TFeatures extends ReadonlyArray<CodeStepFeature> = never[], const TErrors extends string = never, TEnv extends EnvRecord = EnvRecord, TNamed extends NamedStepEnvironment | undefined = undefined>(config: Omit<DefineCodeStepInput<TInput, TResult, TFeatures, TEnv, TNamed>, "errors" | "retry"> & {
82
89
  errors?: readonly TErrors[];
83
90
  retry?: readonly {
84
91
  on: readonly (BuiltInError | TErrors)[];