@scarn/sdk 0.8.20 → 0.8.22
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/auth/api-token-cache.d.ts +24 -0
- package/dist/auth/api-token-source.d.ts +39 -0
- package/dist/auth/authenticated-fetch.d.ts +10 -0
- package/dist/auth/index.d.ts +3 -0
- package/dist/auth/index.js +19 -0
- package/dist/automations/index.js +14 -17
- package/dist/{chunk-habmdf89.js → chunk-0bwsjn0b.js} +29 -29
- package/dist/{chunk-mzj1j0p5.js → chunk-0w13kxkr.js} +34 -31
- package/dist/{chunk-qgkx89eg.js → chunk-3j5wf2t5.js} +44 -43
- package/dist/{chunk-0y2fy5en.js → chunk-4361gxk0.js} +7 -7
- package/dist/{chunk-n3ywwx7n.js → chunk-52520csz.js} +15 -14
- package/dist/chunk-5dnfgyx8.js +159 -0
- package/dist/{chunk-tr3v83cn.js → chunk-5fa4arn1.js} +18 -11
- package/dist/{chunk-ngy1fdcx.js → chunk-631ffb6r.js} +10 -10
- package/dist/{chunk-01nfqm18.js → chunk-7anj08zc.js} +11 -9
- package/dist/{chunk-yq0sf8sb.js → chunk-7dr4kybf.js} +483 -451
- package/dist/chunk-7mhr5aex.js +171 -0
- package/dist/chunk-7rywbqzz.js +27 -0
- package/dist/{chunk-yf15kdte.js → chunk-9ct3xypr.js} +2636 -3864
- package/dist/chunk-9geh4c3v.js +1034 -0
- package/dist/{chunk-19brnwkp.js → chunk-9qf0eg7m.js} +19 -19
- package/dist/{chunk-y11p1q7r.js → chunk-aqqywy8g.js} +4 -4
- package/dist/chunk-bcvx11fn.js +174 -0
- package/dist/{chunk-z4smq8qd.js → chunk-cyfeaz43.js} +86 -86
- package/dist/chunk-czq37rrt.js +286 -0
- package/dist/chunk-ec5z8bbq.js +126 -0
- package/dist/{chunk-rt9tq4j6.js → chunk-h9yxx0hd.js} +7 -7
- package/dist/{chunk-t1dq2c2s.js → chunk-hma87efq.js} +40 -40
- package/dist/{chunk-5dny5jg1.js → chunk-hpv234hf.js} +11 -11
- package/dist/{chunk-rq5k7m33.js → chunk-k7xnsmp5.js} +182 -97
- package/dist/{chunk-91f5gm5z.js → chunk-kbpkpxcn.js} +22 -21
- package/dist/{chunk-6tra3gw8.js → chunk-kjn1knb9.js} +7 -7
- package/dist/{chunk-g4j5cfpc.js → chunk-p3s7cjfc.js} +17 -16
- package/dist/chunk-pq6hrtnb.js +49 -0
- package/dist/{chunk-mp2rqtcj.js → chunk-ptpy7nnm.js} +8 -8
- package/dist/{chunk-xqfj56m9.js → chunk-vn1rfxma.js} +8 -8
- package/dist/chunk-vyv8kvkv.js +113 -0
- package/dist/{chunk-0c60x3v8.js → chunk-xe2zgyz7.js} +35 -35
- package/dist/chunk-y4dwmhn2.js +14 -0
- package/dist/{chunk-098740f7.js → chunk-yypj3zn0.js} +8 -8
- package/dist/chunk-yzj1mfpr.js +1515 -0
- package/dist/client.d.ts +5 -1
- package/dist/client.js +62 -61
- package/dist/connectors/index.js +36 -37
- package/dist/contracts/artifact-markers.js +11 -12
- package/dist/contracts/artifacts.js +21 -23
- package/dist/contracts/automation-document/index.js +28 -30
- package/dist/contracts/pipeline-document/built-ins.d.ts +1 -1
- package/dist/contracts/pipeline-document/index.js +95 -97
- package/dist/contracts/step-artifact-submissions.js +20 -17
- package/dist/contracts/work-item-changes.js +8 -6
- package/dist/create-api-client.d.ts +11 -0
- package/dist/defaults/index.js +44 -884
- package/dist/defaults/load-push-defaults.d.ts +11 -4
- package/dist/defaults/project-ref.d.ts +2 -4
- package/dist/definitions/automations/automations-client.d.ts +2 -1
- package/dist/definitions/automations/index.js +6 -8
- package/dist/definitions/environments/environments-client.d.ts +2 -1
- package/dist/definitions/environments/index.js +37 -38
- package/dist/definitions/pipelines/index.js +12 -14
- package/dist/definitions/pipelines/pipeline-definitions-client.d.ts +2 -1
- package/dist/definitions/steps/define-mcp.d.ts +2 -2
- package/dist/definitions/steps/index.js +93 -95
- package/dist/definitions/steps/mcp-server-config.d.ts +13 -3
- package/dist/definitions/steps/step-definitions-client.d.ts +20 -1
- package/dist/definitions/validation/index.js +17 -18
- package/dist/devcontainer-config-path.js +9 -11
- package/dist/env-vars.js +37 -39
- package/dist/environment.js +41 -42
- package/dist/eslint.js +0 -2
- package/dist/generated/index.d.ts +2 -2
- package/dist/generated/sdk.gen.d.ts +41 -1
- package/dist/generated/types.gen.d.ts +1801 -0
- package/dist/git-url/git-repo-identity.js +0 -2
- package/dist/health-checks.js +15 -17
- package/dist/index.js +364 -358
- package/dist/jsonc.js +7 -8
- package/dist/managed-connections.d.ts +16 -0
- package/dist/managed-connections.js +9 -0
- package/dist/managed-runtimes.js +9 -11
- package/dist/opencode-mcp.d.ts +55 -1
- package/dist/opencode-mcp.js +33 -28
- package/dist/pipelines/index.js +78 -81
- package/dist/push/code-step-lookup.js +9 -10
- package/dist/push/index.d.ts +1 -0
- package/dist/push/index.js +109 -79
- package/dist/push/push-from-directory.d.ts +9 -1
- package/dist/push/pushed-mcp-servers.d.ts +28 -0
- package/dist/repo-config.js +41 -43
- package/dist/resolve-environment.js +14 -15
- package/dist/scarn-config-parser.js +5 -6
- package/dist/task-plane-client.d.ts +143 -1
- package/package.json +11 -3
- package/dist/chunk-46wmsgv7.js +0 -14
- package/dist/chunk-a56zc4s5.js +0 -119
- package/dist/chunk-aemxz9r7.js +0 -107
- package/dist/chunk-b9ja6ss5.js +0 -275
- package/dist/chunk-e0pt5x0e.js +0 -167
- package/dist/chunk-pqtd0hr7.js +0 -96
- package/dist/chunk-rphfy0fj.js +0 -167
- package/dist/chunk-y34zsgsw.js +0 -39
- package/dist/chunk-y64skrwp.js +0 -17
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* On-disk cache of short-lived API tokens (`~/.scarn/api-tokens.jsonc`),
|
|
3
|
+
* keyed by base URL exactly as `auth.jsonc` keys its profiles. Each entry
|
|
4
|
+
* remembers a hash of the session token it was minted from, so a re-login
|
|
5
|
+
* makes it stale. Kept apart from `auth.jsonc` because the worker watches that
|
|
6
|
+
* file for re-logins and token refreshes must not trigger it.
|
|
7
|
+
*/
|
|
8
|
+
export interface ApiTokenCacheEntry {
|
|
9
|
+
sessionHash: string;
|
|
10
|
+
token: string;
|
|
11
|
+
/** Epoch milliseconds. */
|
|
12
|
+
expiresAt: number;
|
|
13
|
+
}
|
|
14
|
+
export declare const getApiTokenCacheFilePath: () => string;
|
|
15
|
+
export declare const loadApiTokenCacheEntry: (baseUrl: string) => ApiTokenCacheEntry | null;
|
|
16
|
+
export declare const saveApiTokenCacheEntry: (baseUrl: string, entry: ApiTokenCacheEntry) => void;
|
|
17
|
+
/**
|
|
18
|
+
* Removes the cached token for `baseUrl`. With `onlyToken`, the entry is
|
|
19
|
+
* removed only if it still holds that token, so a token another process has
|
|
20
|
+
* just refreshed is left alone.
|
|
21
|
+
*/
|
|
22
|
+
export declare const deleteApiTokenCacheEntry: (baseUrl: string, options?: {
|
|
23
|
+
onlyToken?: string;
|
|
24
|
+
}) => void;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export type FetchLike = (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
|
|
2
|
+
/**
|
|
3
|
+
* The session token is missing or the server rejected it while minting an API
|
|
4
|
+
* token: the user has to log in again.
|
|
5
|
+
*/
|
|
6
|
+
export declare class ApiTokenAuthError extends Error {
|
|
7
|
+
readonly baseUrl: string;
|
|
8
|
+
readonly status: number | undefined;
|
|
9
|
+
constructor(message: string, baseUrl: string, status?: number);
|
|
10
|
+
}
|
|
11
|
+
export type ApiCredential = {
|
|
12
|
+
/** Full `Authorization` header value. */
|
|
13
|
+
authorization: string;
|
|
14
|
+
/** `session` once the server has no token endpoint (404) and the session bearer is sent instead. */
|
|
15
|
+
kind: "jwt" | "session";
|
|
16
|
+
};
|
|
17
|
+
export type ApiTokenSourceOptions = {
|
|
18
|
+
baseUrl: string;
|
|
19
|
+
getSessionToken: () => string | null | undefined | Promise<string | null | undefined>;
|
|
20
|
+
fetch?: FetchLike | undefined;
|
|
21
|
+
};
|
|
22
|
+
export type ApiTokenSource = {
|
|
23
|
+
getAuthorization(): Promise<string>;
|
|
24
|
+
getCredential(): Promise<ApiCredential>;
|
|
25
|
+
/**
|
|
26
|
+
* Drops the cached token (memory and disk). With `failedAuthorization`,
|
|
27
|
+
* drops it only if it is still the token that failed, so a token refreshed
|
|
28
|
+
* meanwhile survives.
|
|
29
|
+
*/
|
|
30
|
+
invalidate(failedAuthorization?: string): void;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Supplies the `Authorization` header for API calls: a short-lived JWT minted
|
|
34
|
+
* from the session token at `GET /api/auth/token`, cached in memory and in
|
|
35
|
+
* `~/.scarn/api-tokens.jsonc` and reused while it has more than a minute left.
|
|
36
|
+
* Servers without the token endpoint (404) get the session bearer for the
|
|
37
|
+
* rest of the process.
|
|
38
|
+
*/
|
|
39
|
+
export declare function createApiTokenSource(options: ApiTokenSourceOptions): ApiTokenSource;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ApiTokenSource, FetchLike } from "./api-token-source";
|
|
2
|
+
/**
|
|
3
|
+
* Wraps `fetch` so every request carries the token source's `Authorization`.
|
|
4
|
+
* A 401 on a request sent with a JWT invalidates that token and retries once
|
|
5
|
+
* with a fresh one; the retry's response is returned as is. The retry uses a
|
|
6
|
+
* clone taken before the first send, so request bodies can be resent.
|
|
7
|
+
*/
|
|
8
|
+
export declare function createAuthenticatedFetch(source: ApiTokenSource, options?: {
|
|
9
|
+
fetch?: FetchLike | undefined;
|
|
10
|
+
}): FetchLike;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { deleteApiTokenCacheEntry, getApiTokenCacheFilePath, loadApiTokenCacheEntry, saveApiTokenCacheEntry, type ApiTokenCacheEntry, } from "./api-token-cache";
|
|
2
|
+
export { ApiTokenAuthError, createApiTokenSource, type ApiCredential, type ApiTokenSource, type ApiTokenSourceOptions, type FetchLike, } from "./api-token-source";
|
|
3
|
+
export { createAuthenticatedFetch } from "./authenticated-fetch";
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import {
|
|
3
|
+
getApiTokenCacheFilePath2,
|
|
4
|
+
loadApiTokenCacheEntry2,
|
|
5
|
+
saveApiTokenCacheEntry2,
|
|
6
|
+
deleteApiTokenCacheEntry2,
|
|
7
|
+
ApiTokenAuthError2,
|
|
8
|
+
createApiTokenSource2,
|
|
9
|
+
createAuthenticatedFetch2
|
|
10
|
+
} from "../chunk-9geh4c3v.js";
|
|
11
|
+
export {
|
|
12
|
+
ApiTokenAuthError2 as ApiTokenAuthError,
|
|
13
|
+
createApiTokenSource2 as createApiTokenSource,
|
|
14
|
+
createAuthenticatedFetch2 as createAuthenticatedFetch,
|
|
15
|
+
deleteApiTokenCacheEntry2 as deleteApiTokenCacheEntry,
|
|
16
|
+
getApiTokenCacheFilePath2 as getApiTokenCacheFilePath,
|
|
17
|
+
loadApiTokenCacheEntry2 as loadApiTokenCacheEntry,
|
|
18
|
+
saveApiTokenCacheEntry2 as saveApiTokenCacheEntry
|
|
19
|
+
};
|
|
@@ -1,21 +1,18 @@
|
|
|
1
1
|
// @bun
|
|
2
2
|
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
} from "../chunk-
|
|
8
|
-
import"../chunk-
|
|
9
|
-
import"../chunk-
|
|
10
|
-
import"../chunk-
|
|
11
|
-
import"../chunk-
|
|
12
|
-
import"../chunk-
|
|
13
|
-
import"../chunk-01nfqm18.js";
|
|
14
|
-
import"../chunk-yf15kdte.js";
|
|
15
|
-
import"../chunk-y64skrwp.js";
|
|
3
|
+
skip2,
|
|
4
|
+
attach2,
|
|
5
|
+
onEvent2,
|
|
6
|
+
defineAutomation2
|
|
7
|
+
} from "../chunk-0bwsjn0b.js";
|
|
8
|
+
import"../chunk-ptpy7nnm.js";
|
|
9
|
+
import"../chunk-ec5z8bbq.js";
|
|
10
|
+
import"../chunk-hpv234hf.js";
|
|
11
|
+
import"../chunk-czq37rrt.js";
|
|
12
|
+
import"../chunk-aqqywy8g.js";
|
|
16
13
|
export {
|
|
17
|
-
attach,
|
|
18
|
-
defineAutomation,
|
|
19
|
-
onEvent,
|
|
20
|
-
skip
|
|
14
|
+
attach2 as attach,
|
|
15
|
+
defineAutomation2 as defineAutomation,
|
|
16
|
+
onEvent2 as onEvent,
|
|
17
|
+
skip2 as skip
|
|
21
18
|
};
|
|
@@ -1,31 +1,31 @@
|
|
|
1
1
|
// @bun
|
|
2
2
|
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
compileCondition,
|
|
7
|
-
conditionData,
|
|
8
|
-
issue,
|
|
9
|
-
mapSource,
|
|
10
|
-
newState,
|
|
11
|
-
rootPlaceholder,
|
|
12
|
-
withOwners,
|
|
13
|
-
withTracker
|
|
14
|
-
} from "./chunk-mp2rqtcj.js";
|
|
15
|
-
import {
|
|
16
|
-
eventHasChild,
|
|
17
|
-
scopeOfEvent
|
|
18
|
-
} from "./chunk-a56zc4s5.js";
|
|
3
|
+
scopeOfEvent2,
|
|
4
|
+
eventHasChild2
|
|
5
|
+
} from "./chunk-ec5z8bbq.js";
|
|
19
6
|
import {
|
|
7
|
+
captureSite,
|
|
8
|
+
PipelineBuildError2,
|
|
20
9
|
AuthoringError,
|
|
21
|
-
|
|
10
|
+
registerAutomationTarget,
|
|
22
11
|
automationTargetOf,
|
|
23
|
-
captureSite,
|
|
24
12
|
markSubject,
|
|
25
13
|
nodeOf,
|
|
26
|
-
registerAutomationTarget,
|
|
27
14
|
targetOf
|
|
28
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-aqqywy8g.js";
|
|
16
|
+
import {
|
|
17
|
+
withOwners,
|
|
18
|
+
withTracker,
|
|
19
|
+
rootPlaceholder,
|
|
20
|
+
conditionData,
|
|
21
|
+
compileCondition,
|
|
22
|
+
compileArg,
|
|
23
|
+
argEntries,
|
|
24
|
+
newState,
|
|
25
|
+
issue,
|
|
26
|
+
mapSource,
|
|
27
|
+
attempt
|
|
28
|
+
} from "./chunk-ptpy7nnm.js";
|
|
29
29
|
|
|
30
30
|
// src/automations/define-automation.ts
|
|
31
31
|
var rules = new WeakMap;
|
|
@@ -49,7 +49,7 @@ function eventWorkItem(subject, owner) {
|
|
|
49
49
|
function eventContext(event) {
|
|
50
50
|
const context = {};
|
|
51
51
|
context["workItem"] = eventWorkItem("workItem", context);
|
|
52
|
-
if (
|
|
52
|
+
if (eventHasChild2(event)) {
|
|
53
53
|
context["child"] = eventWorkItem("child", context);
|
|
54
54
|
}
|
|
55
55
|
if (event === "workItem.label.added") {
|
|
@@ -60,8 +60,8 @@ function eventContext(event) {
|
|
|
60
60
|
}
|
|
61
61
|
return context;
|
|
62
62
|
}
|
|
63
|
-
var
|
|
64
|
-
function
|
|
63
|
+
var skip2 = registerAutomationTarget({ kind: "skip", site: null });
|
|
64
|
+
function attach2(automation) {
|
|
65
65
|
if (automation?._tag !== "automation_document") {
|
|
66
66
|
throw new AuthoringError("attach(...) takes an automation: the value defineAutomation returns");
|
|
67
67
|
}
|
|
@@ -71,7 +71,7 @@ function attach(automation) {
|
|
|
71
71
|
site: captureSite()
|
|
72
72
|
});
|
|
73
73
|
}
|
|
74
|
-
function
|
|
74
|
+
function onEvent2(options) {
|
|
75
75
|
const site = captureSite();
|
|
76
76
|
const rule = options.routes === undefined ? {
|
|
77
77
|
event: options.event,
|
|
@@ -147,7 +147,7 @@ function compileTarget(state, scope, rule, spec, context, pointer) {
|
|
|
147
147
|
const report = (message) => {
|
|
148
148
|
issue(state, target.site ?? rule.site, pointer, message);
|
|
149
149
|
};
|
|
150
|
-
if ((target.kind === "step" || target.kind === "pipeline") && target.on === "child" && !
|
|
150
|
+
if ((target.kind === "step" || target.kind === "pipeline") && target.on === "child" && !eventHasChild2(rule.event)) {
|
|
151
151
|
report(`"${rule.event}" has no child work item; .on(r.child) only works on child.* events`);
|
|
152
152
|
return;
|
|
153
153
|
}
|
|
@@ -177,7 +177,7 @@ function compileTarget(state, scope, rule, spec, context, pointer) {
|
|
|
177
177
|
function compileRule(state, scope, rule, index) {
|
|
178
178
|
const base = ["rules", index];
|
|
179
179
|
mapSource(state, base, rule.site);
|
|
180
|
-
if (
|
|
180
|
+
if (scopeOfEvent2(rule.event) !== scope) {
|
|
181
181
|
issue(state, rule.site, [...base, "event"], `"${rule.event}" isn't an event of a ${scope === "workItem" ? "work-item" : "project"} automation`);
|
|
182
182
|
}
|
|
183
183
|
const context = eventContext(rule.event);
|
|
@@ -214,7 +214,7 @@ function compileRule(state, scope, rule, index) {
|
|
|
214
214
|
}
|
|
215
215
|
return { event: rule.event, next };
|
|
216
216
|
}
|
|
217
|
-
function
|
|
217
|
+
function defineAutomation2(config) {
|
|
218
218
|
const site = captureSite();
|
|
219
219
|
const state = newState();
|
|
220
220
|
const compiled = withTracker(state.tracker, () => config.rules.map((value, index) => {
|
|
@@ -226,7 +226,7 @@ function defineAutomation(config) {
|
|
|
226
226
|
return compileRule(state, config.scope, rule, index);
|
|
227
227
|
}));
|
|
228
228
|
if (state.issues.length > 0) {
|
|
229
|
-
throw new
|
|
229
|
+
throw new PipelineBuildError2(config.key, state.issues);
|
|
230
230
|
}
|
|
231
231
|
const document = {
|
|
232
232
|
kind: "automation",
|
|
@@ -247,4 +247,4 @@ function defineAutomation(config) {
|
|
|
247
247
|
}
|
|
248
248
|
};
|
|
249
249
|
}
|
|
250
|
-
export {
|
|
250
|
+
export { skip2, attach2, onEvent2, defineAutomation2 };
|
|
@@ -1,18 +1,21 @@
|
|
|
1
1
|
// @bun
|
|
2
2
|
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
environmentNameSchema,
|
|
7
|
-
inlineEnvironmentReadSchema
|
|
8
|
-
} from "./chunk-e0pt5x0e.js";
|
|
3
|
+
ConnectorVarsMissing2,
|
|
4
|
+
findMissingConnectorVars2
|
|
5
|
+
} from "./chunk-3j5wf2t5.js";
|
|
9
6
|
import {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
7
|
+
environmentNameSchema2,
|
|
8
|
+
inlineEnvironmentReadSchema2,
|
|
9
|
+
EnvironmentNotFound2,
|
|
10
|
+
EnvironmentInvalid2,
|
|
11
|
+
BrokenDevcontainerReference2
|
|
12
|
+
} from "./chunk-bcvx11fn.js";
|
|
13
13
|
import {
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
number,
|
|
15
|
+
object,
|
|
16
|
+
union,
|
|
17
|
+
literal
|
|
18
|
+
} from "./chunk-9ct3xypr.js";
|
|
16
19
|
|
|
17
20
|
// src/resolve-environment.ts
|
|
18
21
|
var DEVCONTAINER_DISCOVERY_PATHS = [
|
|
@@ -29,32 +32,32 @@ var namedContentAsInline = ({
|
|
|
29
32
|
...vars === undefined ? {} : { envJson: vars },
|
|
30
33
|
...connectors === undefined ? {} : { connectors }
|
|
31
34
|
});
|
|
32
|
-
var namedEnvironmentEnvelopeSchema =
|
|
33
|
-
|
|
34
|
-
name:
|
|
35
|
-
version:
|
|
36
|
-
content:
|
|
35
|
+
var namedEnvironmentEnvelopeSchema = union([
|
|
36
|
+
object({
|
|
37
|
+
name: environmentNameSchema2,
|
|
38
|
+
version: number().int().positive(),
|
|
39
|
+
content: object({})
|
|
37
40
|
}),
|
|
38
|
-
|
|
41
|
+
object({ name: environmentNameSchema2, notFound: literal(true) })
|
|
39
42
|
]);
|
|
40
|
-
function
|
|
43
|
+
function readEnvironmentDefinition2(ref) {
|
|
41
44
|
let named;
|
|
42
45
|
if (ref?.kind === "named") {
|
|
43
46
|
const envelope = namedEnvironmentEnvelopeSchema.safeParse(ref);
|
|
44
47
|
if (!envelope.success) {
|
|
45
|
-
return new
|
|
48
|
+
return new EnvironmentInvalid2(undefined, envelope.error.issues);
|
|
46
49
|
}
|
|
47
50
|
if ("notFound" in envelope.data) {
|
|
48
|
-
return new
|
|
51
|
+
return new EnvironmentNotFound2(envelope.data.name);
|
|
49
52
|
}
|
|
50
53
|
named = {
|
|
51
54
|
name: envelope.data.name,
|
|
52
55
|
label: `environment ${envelope.data.name} v${String(envelope.data.version)}`
|
|
53
56
|
};
|
|
54
57
|
}
|
|
55
|
-
const parsedRef =
|
|
58
|
+
const parsedRef = inlineEnvironmentReadSchema2.safeParse(ref?.kind === "named" && "content" in ref ? namedContentAsInline(ref.content) : ref);
|
|
56
59
|
if (!parsedRef.success) {
|
|
57
|
-
return new
|
|
60
|
+
return new EnvironmentInvalid2(named?.label, named === undefined ? parsedRef.error.issues : parsedRef.error.issues.map((issue) => ({
|
|
58
61
|
...issue,
|
|
59
62
|
path: issue.path.map((key) => key === "envJson" ? "vars" : key)
|
|
60
63
|
})));
|
|
@@ -63,9 +66,9 @@ function readEnvironmentDefinition(ref) {
|
|
|
63
66
|
const runtime = reference?.runtime;
|
|
64
67
|
const envVars = reference?.envJson ?? [];
|
|
65
68
|
const connectors = reference?.connectors ?? [];
|
|
66
|
-
const missing =
|
|
69
|
+
const missing = findMissingConnectorVars2(connectors, envVars);
|
|
67
70
|
if (missing.length > 0) {
|
|
68
|
-
return new
|
|
71
|
+
return new ConnectorVarsMissing2(named?.label, missing);
|
|
69
72
|
}
|
|
70
73
|
return {
|
|
71
74
|
source: named ? "named" : reference?.kind ?? "repo-default",
|
|
@@ -75,18 +78,18 @@ function readEnvironmentDefinition(ref) {
|
|
|
75
78
|
connectors
|
|
76
79
|
};
|
|
77
80
|
}
|
|
78
|
-
async function
|
|
79
|
-
const definition =
|
|
81
|
+
async function resolveEnvironment2(deps, ref) {
|
|
82
|
+
const definition = readEnvironmentDefinition2(ref);
|
|
80
83
|
if (definition instanceof Error)
|
|
81
84
|
return definition;
|
|
82
|
-
return
|
|
85
|
+
return resolveEnvironmentDefinition2(deps, definition);
|
|
83
86
|
}
|
|
84
|
-
async function
|
|
87
|
+
async function resolveEnvironmentDefinition2(deps, definition) {
|
|
85
88
|
const { runtime } = definition;
|
|
86
89
|
let resolvedRuntime;
|
|
87
90
|
if (runtime?.kind === "devcontainer" && runtime.config !== undefined) {
|
|
88
91
|
if (!await deps.devcontainerExists(runtime.config)) {
|
|
89
|
-
return new
|
|
92
|
+
return new BrokenDevcontainerReference2(runtime.config);
|
|
90
93
|
}
|
|
91
94
|
resolvedRuntime = { kind: "devcontainer", config: runtime.config };
|
|
92
95
|
} else if (runtime === undefined || runtime.kind === "devcontainer") {
|
|
@@ -100,7 +103,7 @@ async function resolveEnvironmentDefinition(deps, definition) {
|
|
|
100
103
|
if (discoveredConfig !== undefined) {
|
|
101
104
|
resolvedRuntime = { kind: "devcontainer", config: discoveredConfig };
|
|
102
105
|
} else if (runtime?.kind === "devcontainer") {
|
|
103
|
-
return new
|
|
106
|
+
return new BrokenDevcontainerReference2(DEVCONTAINER_DISCOVERY_PATHS[0], DEVCONTAINER_DISCOVERY_PATHS);
|
|
104
107
|
} else {
|
|
105
108
|
resolvedRuntime = { kind: "managed", id: "bun1" };
|
|
106
109
|
}
|
|
@@ -113,4 +116,4 @@ async function resolveEnvironmentDefinition(deps, definition) {
|
|
|
113
116
|
};
|
|
114
117
|
}
|
|
115
118
|
|
|
116
|
-
export {
|
|
119
|
+
export { readEnvironmentDefinition2, resolveEnvironment2, resolveEnvironmentDefinition2 };
|
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
// @bun
|
|
2
2
|
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
openCodeResolvedMcpServerConfigSchema
|
|
6
|
-
} from "./chunk-pqtd0hr7.js";
|
|
3
|
+
ENV_VAR_NAME_PATTERN2
|
|
4
|
+
} from "./chunk-vyv8kvkv.js";
|
|
7
5
|
import {
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
openCodeResolvedMcpServerConfigSchema2,
|
|
7
|
+
isEnvPlaceholderValue2,
|
|
8
|
+
collectEnvPlaceholderNames2
|
|
9
|
+
} from "./chunk-5dnfgyx8.js";
|
|
10
10
|
import {
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
string,
|
|
12
|
+
array
|
|
13
|
+
} from "./chunk-9ct3xypr.js";
|
|
13
14
|
|
|
14
15
|
// src/connectors/catalog.ts
|
|
15
|
-
var
|
|
16
|
+
var connectorAuthValues2 = ["none", "apiKey"];
|
|
16
17
|
var CONNECTOR_ID_PATTERN = /^[a-z0-9]+(?:-[a-z0-9]+)*$/u;
|
|
17
18
|
var CONNECTOR_DEFINITIONS = [
|
|
18
19
|
{
|
|
@@ -49,8 +50,8 @@ var CONNECTOR_DEFINITIONS = [
|
|
|
49
50
|
}
|
|
50
51
|
}
|
|
51
52
|
];
|
|
52
|
-
var
|
|
53
|
-
var
|
|
53
|
+
var E2E_FAKE_CONNECTOR_FLAG2 = "SCARN_E2E_FAKE_CONNECTOR";
|
|
54
|
+
var E2E_FAKE_CONNECTOR2 = {
|
|
54
55
|
id: "e2e-fake",
|
|
55
56
|
name: "E2E fake",
|
|
56
57
|
description: "Test-only fake MCP server for the end-to-end tests.",
|
|
@@ -67,10 +68,10 @@ var E2E_FAKE_CONNECTOR = {
|
|
|
67
68
|
environment: { FAKE_API_KEY: "{env:FAKE_API_KEY}" }
|
|
68
69
|
}
|
|
69
70
|
};
|
|
70
|
-
function
|
|
71
|
-
return env[
|
|
71
|
+
function connectorDefinitions2(env) {
|
|
72
|
+
return env[E2E_FAKE_CONNECTOR_FLAG2] === "true" ? [...CONNECTOR_DEFINITIONS, E2E_FAKE_CONNECTOR2] : CONNECTOR_DEFINITIONS;
|
|
72
73
|
}
|
|
73
|
-
function
|
|
74
|
+
function validateConnectorCatalog2(entries) {
|
|
74
75
|
const problems = [];
|
|
75
76
|
const seen = new Set;
|
|
76
77
|
for (const entry of entries) {
|
|
@@ -81,11 +82,11 @@ function validateConnectorCatalog(entries) {
|
|
|
81
82
|
if (seen.has(entry.id))
|
|
82
83
|
problems.push(`${label}: duplicate id`);
|
|
83
84
|
seen.add(entry.id);
|
|
84
|
-
if (!
|
|
85
|
+
if (!openCodeResolvedMcpServerConfigSchema2.safeParse(entry.mcp).success) {
|
|
85
86
|
problems.push(`${label}: mcp is not a valid OpenCode MCP config`);
|
|
86
87
|
}
|
|
87
88
|
const credentialValues = Object.values(entry.mcp.type === "local" ? entry.mcp.environment ?? {} : entry.mcp.headers ?? {});
|
|
88
|
-
if (!credentialValues.every(
|
|
89
|
+
if (!credentialValues.every(isEnvPlaceholderValue2)) {
|
|
89
90
|
problems.push(`${label}: ${entry.mcp.type === "local" ? "environment" : "headers"} values must be {env:NAME} placeholders`);
|
|
90
91
|
}
|
|
91
92
|
const declared = entry.requiredVars.map((variable) => variable.name);
|
|
@@ -93,15 +94,15 @@ function validateConnectorCatalog(entries) {
|
|
|
93
94
|
problems.push(`${label}: requiredVars names must be unique`);
|
|
94
95
|
}
|
|
95
96
|
for (const name of declared) {
|
|
96
|
-
if (!
|
|
97
|
+
if (!ENV_VAR_NAME_PATTERN2.test(name)) {
|
|
97
98
|
problems.push(`${label}: requiredVars "${name}" is not a valid name`);
|
|
98
99
|
}
|
|
99
100
|
}
|
|
100
|
-
const read =
|
|
101
|
-
for (const name of read.filter((
|
|
101
|
+
const read = collectEnvPlaceholderNames2(entry.mcp);
|
|
102
|
+
for (const name of read.filter((name) => !declared.includes(name))) {
|
|
102
103
|
problems.push(`${label}: mcp reads {env:${name}} but requiredVars omits it`);
|
|
103
104
|
}
|
|
104
|
-
for (const name of declared.filter((
|
|
105
|
+
for (const name of declared.filter((name) => !read.includes(name))) {
|
|
105
106
|
problems.push(`${label}: requiredVars lists ${name} but mcp never reads it`);
|
|
106
107
|
}
|
|
107
108
|
if (entry.auth === "none" !== (declared.length === 0)) {
|
|
@@ -111,22 +112,22 @@ function validateConnectorCatalog(entries) {
|
|
|
111
112
|
return problems;
|
|
112
113
|
}
|
|
113
114
|
function buildCatalog(entries) {
|
|
114
|
-
const problems =
|
|
115
|
+
const problems = validateConnectorCatalog2(entries);
|
|
115
116
|
if (problems.length > 0) {
|
|
116
117
|
throw new Error(`Invalid connector catalog: ${problems.join("; ")}`);
|
|
117
118
|
}
|
|
118
119
|
return Object.freeze(Object.fromEntries(entries.map((entry) => [entry.id, entry])));
|
|
119
120
|
}
|
|
120
121
|
var runtimeEnv = globalThis.process?.env ?? {};
|
|
121
|
-
var
|
|
122
|
-
function
|
|
123
|
-
return Object.hasOwn(
|
|
122
|
+
var CONNECTOR_CATALOG2 = buildCatalog(connectorDefinitions2(runtimeEnv));
|
|
123
|
+
function isConnectorId2(id) {
|
|
124
|
+
return Object.hasOwn(CONNECTOR_CATALOG2, id);
|
|
124
125
|
}
|
|
125
|
-
function
|
|
126
|
-
return
|
|
126
|
+
function getConnector2(id) {
|
|
127
|
+
return isConnectorId2(id) ? CONNECTOR_CATALOG2[id] : undefined;
|
|
127
128
|
}
|
|
128
|
-
function
|
|
129
|
-
return Object.values(
|
|
129
|
+
function listConnectorSummaries2() {
|
|
130
|
+
return Object.values(CONNECTOR_CATALOG2).map(({ id, name, description, auth, requiredVars }) => ({
|
|
130
131
|
id,
|
|
131
132
|
name,
|
|
132
133
|
description,
|
|
@@ -136,14 +137,14 @@ function listConnectorSummaries() {
|
|
|
136
137
|
}
|
|
137
138
|
|
|
138
139
|
// src/connectors/index.ts
|
|
139
|
-
var
|
|
140
|
+
var connectorIdsSchema2 = array(string()).superRefine((ids, ctx) => {
|
|
140
141
|
const seen = new Set;
|
|
141
142
|
ids.forEach((id, index) => {
|
|
142
|
-
if (!
|
|
143
|
+
if (!isConnectorId2(id)) {
|
|
143
144
|
ctx.addIssue({
|
|
144
145
|
code: "custom",
|
|
145
146
|
path: [index],
|
|
146
|
-
message: `unknown connector "${id}"; known connectors: ${Object.keys(
|
|
147
|
+
message: `unknown connector "${id}"; known connectors: ${Object.keys(CONNECTOR_CATALOG2).join(", ")}`
|
|
147
148
|
});
|
|
148
149
|
} else if (seen.has(id)) {
|
|
149
150
|
ctx.addIssue({
|
|
@@ -156,7 +157,7 @@ var connectorIdsSchema = exports_external.array(exports_external.string()).super
|
|
|
156
157
|
});
|
|
157
158
|
});
|
|
158
159
|
|
|
159
|
-
class
|
|
160
|
+
class ConnectorVarsMissing2 extends Error {
|
|
160
161
|
environment;
|
|
161
162
|
missing;
|
|
162
163
|
kind = "ConnectorVarsMissing";
|
|
@@ -167,39 +168,39 @@ class ConnectorVarsMissing extends Error {
|
|
|
167
168
|
this.missing = missing;
|
|
168
169
|
}
|
|
169
170
|
}
|
|
170
|
-
function
|
|
171
|
+
function findMissingConnectorVars2(connectors, envVars) {
|
|
171
172
|
const provided = new Set(envVars.filter((entry) => entry.applies !== "setup").map((entry) => entry.name));
|
|
172
173
|
return connectors.flatMap((connector) => {
|
|
173
|
-
const vars = (
|
|
174
|
+
const vars = (CONNECTOR_CATALOG2[connector]?.requiredVars ?? []).map((variable) => variable.name).filter((name) => !provided.has(name));
|
|
174
175
|
return vars.length > 0 ? [{ connector, vars }] : [];
|
|
175
176
|
});
|
|
176
177
|
}
|
|
177
|
-
function
|
|
178
|
+
function findConnectorMcpCollisions2(connectors, stepMcpKeys) {
|
|
178
179
|
const ids = new Set(connectors);
|
|
179
180
|
return [...stepMcpKeys].filter((key) => ids.has(key)).sort();
|
|
180
181
|
}
|
|
181
|
-
function
|
|
182
|
+
function connectorMcpCollisionMessage2(collisions) {
|
|
182
183
|
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
|
}
|
|
184
185
|
|
|
185
|
-
class
|
|
186
|
+
class ConnectorMcpCollision2 extends Error {
|
|
186
187
|
collisions;
|
|
187
188
|
kind = "ConnectorMcpCollision";
|
|
188
189
|
code = "SCARN_ENVIRONMENT_INVALID";
|
|
189
190
|
constructor(collisions) {
|
|
190
|
-
super(
|
|
191
|
+
super(connectorMcpCollisionMessage2(collisions));
|
|
191
192
|
this.collisions = collisions;
|
|
192
193
|
}
|
|
193
194
|
}
|
|
194
|
-
function
|
|
195
|
+
function mergeConnectorMcpServers2(connectors, servers, stepMcpKeys = Object.keys(servers ?? {})) {
|
|
195
196
|
if (connectors.length === 0)
|
|
196
197
|
return servers;
|
|
197
|
-
const collisions =
|
|
198
|
+
const collisions = findConnectorMcpCollisions2(connectors, stepMcpKeys);
|
|
198
199
|
if (collisions.length > 0)
|
|
199
|
-
throw new
|
|
200
|
+
throw new ConnectorMcpCollision2(collisions);
|
|
200
201
|
const merged = { ...servers };
|
|
201
202
|
for (const id of connectors) {
|
|
202
|
-
const connector =
|
|
203
|
+
const connector = CONNECTOR_CATALOG2[id];
|
|
203
204
|
if (connector === undefined)
|
|
204
205
|
throw new Error(`Unknown connector "${id}"`);
|
|
205
206
|
merged[id] = structuredClone(connector.mcp);
|
|
@@ -207,4 +208,4 @@ function mergeConnectorMcpServers(connectors, servers, stepMcpKeys = Object.keys
|
|
|
207
208
|
return merged;
|
|
208
209
|
}
|
|
209
210
|
|
|
210
|
-
export {
|
|
211
|
+
export { connectorAuthValues2, E2E_FAKE_CONNECTOR_FLAG2, E2E_FAKE_CONNECTOR2, connectorDefinitions2, validateConnectorCatalog2, CONNECTOR_CATALOG2, isConnectorId2, getConnector2, listConnectorSummaries2, connectorIdsSchema2, ConnectorVarsMissing2, findMissingConnectorVars2, findConnectorMcpCollisions2, connectorMcpCollisionMessage2, ConnectorMcpCollision2, mergeConnectorMcpServers2 };
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// src/scarn-config-parser.ts
|
|
3
3
|
import { access, readFile } from "fs/promises";
|
|
4
4
|
import path from "path";
|
|
5
|
-
var
|
|
5
|
+
var SCARN_CONFIG_RELATIVE_PATH2 = ".scarn/scarn.jsonc";
|
|
6
6
|
var stripJsoncComments = (content) => {
|
|
7
7
|
let result = "";
|
|
8
8
|
let inString = false;
|
|
@@ -90,12 +90,12 @@ var stripTrailingCommas = (content) => {
|
|
|
90
90
|
if (character === ",") {
|
|
91
91
|
let lookaheadIndex = index + 1;
|
|
92
92
|
while (lookaheadIndex < content.length) {
|
|
93
|
-
const
|
|
94
|
-
if (/\s/u.test(
|
|
93
|
+
const lookaheadCharacter = content.charAt(lookaheadIndex);
|
|
94
|
+
if (/\s/u.test(lookaheadCharacter)) {
|
|
95
95
|
lookaheadIndex += 1;
|
|
96
96
|
continue;
|
|
97
97
|
}
|
|
98
|
-
if (
|
|
98
|
+
if (lookaheadCharacter === "}" || lookaheadCharacter === "]") {
|
|
99
99
|
break;
|
|
100
100
|
}
|
|
101
101
|
result += character;
|
|
@@ -146,8 +146,8 @@ var parseServices = (raw) => {
|
|
|
146
146
|
};
|
|
147
147
|
});
|
|
148
148
|
};
|
|
149
|
-
async function
|
|
150
|
-
const filePath = path.join(workspacePath,
|
|
149
|
+
async function parseScarnConfig2(workspacePath) {
|
|
150
|
+
const filePath = path.join(workspacePath, SCARN_CONFIG_RELATIVE_PATH2);
|
|
151
151
|
const exists = await access(filePath).then(() => true).catch(() => false);
|
|
152
152
|
if (!exists) {
|
|
153
153
|
return { found: false };
|
|
@@ -163,4 +163,4 @@ async function parseScarnConfig(workspacePath) {
|
|
|
163
163
|
};
|
|
164
164
|
}
|
|
165
165
|
|
|
166
|
-
export {
|
|
166
|
+
export { SCARN_CONFIG_RELATIVE_PATH2, parseScarnConfig2 };
|