mulesoft-anypoint-cli-agent-fabric-plugin 1.3.0 → 1.3.1-beta
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/README.md +77 -42
- package/bin/run +6 -0
- package/dist/commands/agent-network/project/agent-console.d.ts +16 -0
- package/dist/commands/agent-network/project/agent-console.js +175 -0
- package/dist/commands/agent-network/project/agent-console.js.map +1 -0
- package/dist/commands/agent-network/project/broker/create.d.ts +10 -0
- package/dist/commands/agent-network/project/broker/create.js +192 -0
- package/dist/commands/agent-network/project/broker/create.js.map +1 -0
- package/dist/commands/agent-network/project/create.d.ts +12 -0
- package/dist/commands/agent-network/project/create.js +48 -11
- package/dist/commands/agent-network/project/create.js.map +1 -1
- package/dist/commands/agent-network/project/deploy.d.ts +24 -14
- package/dist/commands/agent-network/project/deploy.js +230 -178
- package/dist/commands/agent-network/project/deploy.js.map +1 -1
- package/dist/commands/agent-network/project/export-logs.d.ts +11 -0
- package/dist/commands/agent-network/project/export-logs.js +38 -0
- package/dist/commands/agent-network/project/export-logs.js.map +1 -0
- package/dist/commands/agent-network/project/mcp/introspect.js +4 -1
- package/dist/commands/agent-network/project/mcp/introspect.js.map +1 -1
- package/dist/commands/agent-network/project/publish.js +1 -1
- package/dist/commands/agent-network/project/publish.js.map +1 -1
- package/dist/commands/agent-network/project/run-local.d.ts +85 -0
- package/dist/commands/agent-network/project/run-local.js +825 -0
- package/dist/commands/agent-network/project/run-local.js.map +1 -0
- package/dist/commands/agent-network/project/secrets.d.ts +21 -0
- package/dist/commands/agent-network/project/secrets.js +163 -0
- package/dist/commands/agent-network/project/secrets.js.map +1 -0
- package/dist/commands/agent-network/project/stop-local.d.ts +11 -0
- package/dist/commands/agent-network/project/stop-local.js +38 -0
- package/dist/commands/agent-network/project/stop-local.js.map +1 -0
- package/dist/commands/agent-network/project/undeploy.js +15 -10
- package/dist/commands/agent-network/project/undeploy.js.map +1 -1
- package/dist/commands/agent-network/project/unpublish.js +14 -6
- package/dist/commands/agent-network/project/unpublish.js.map +1 -1
- package/dist/commands/agent-network/setup/gateways.d.ts +3 -0
- package/dist/commands/agent-network/setup/gateways.js +66 -3
- package/dist/commands/agent-network/setup/gateways.js.map +1 -1
- package/dist/errors/error-factory.d.ts +51 -6
- package/dist/errors/error-factory.js +246 -15
- package/dist/errors/error-factory.js.map +1 -1
- package/dist/helpers/proxy-agent.d.ts +2 -0
- package/dist/helpers/proxy-agent.js +26 -0
- package/dist/helpers/proxy-agent.js.map +1 -0
- package/dist/helpers/request-utils.d.ts +2 -1
- package/dist/helpers/request-utils.js +2 -2
- package/dist/helpers/request-utils.js.map +1 -1
- package/dist/helpers/utils.d.ts +1 -0
- package/dist/helpers/utils.js +5 -0
- package/dist/helpers/utils.js.map +1 -1
- package/dist/resources/agent-console.html +478 -0
- package/dist/resources/schemas/broker-deployment-settings.schema.json +46 -0
- package/dist/types/agent-network-v2.d.ts +4 -0
- package/dist/types/agent-network-v2.js.map +1 -1
- package/dist/types/types.d.ts +1 -0
- package/dist/utils/builders/network-lock.d.ts +1 -0
- package/dist/utils/builders/network-lock.js +41 -6
- package/dist/utils/builders/network-lock.js.map +1 -1
- package/dist/utils/builders/policies-factory.d.ts +5 -1
- package/dist/utils/builders/policies-factory.js +10 -2
- package/dist/utils/builders/policies-factory.js.map +1 -1
- package/dist/utils/builders/project-builder-impl.d.ts +16 -2
- package/dist/utils/builders/project-builder-impl.js +29 -1
- package/dist/utils/builders/project-builder-impl.js.map +1 -1
- package/dist/utils/builders/project-builder.d.ts +29 -2
- package/dist/utils/builders/project-builder.js +10 -2
- package/dist/utils/builders/project-builder.js.map +1 -1
- package/dist/utils/builders/remote-space-resolver.d.ts +2 -2
- package/dist/utils/builders/remote-space-resolver.js +27 -11
- package/dist/utils/builders/remote-space-resolver.js.map +1 -1
- package/dist/utils/builders/space-serializer.js +3 -1
- package/dist/utils/builders/space-serializer.js.map +1 -1
- package/dist/utils/builders/stage-diagnostics.d.ts +2 -0
- package/dist/utils/builders/stage-diagnostics.js +27 -0
- package/dist/utils/builders/stage-diagnostics.js.map +1 -0
- package/dist/utils/builders/tooling-metadata.d.ts +4 -4
- package/dist/utils/builders/tooling-metadata.js +27 -15
- package/dist/utils/builders/tooling-metadata.js.map +1 -1
- package/dist/utils/builders/v1/network-builder.js +2 -1
- package/dist/utils/builders/v1/network-builder.js.map +1 -1
- package/dist/utils/builders/v2/broker-builder.d.ts +1 -0
- package/dist/utils/builders/v2/broker-builder.js +69 -4
- package/dist/utils/builders/v2/broker-builder.js.map +1 -1
- package/dist/utils/builders/v2/network-builder.js +1 -1
- package/dist/utils/builders/v2/network-builder.js.map +1 -1
- package/dist/utils/constants.d.ts +3 -0
- package/dist/utils/constants.js +8 -3
- package/dist/utils/constants.js.map +1 -1
- package/dist/utils/deployment-settings.d.ts +13 -0
- package/dist/utils/deployment-settings.js +97 -0
- package/dist/utils/deployment-settings.js.map +1 -0
- package/dist/utils/facets/abstract-facet.d.ts +1 -0
- package/dist/utils/facets/abstract-facet.js +3 -0
- package/dist/utils/facets/abstract-facet.js.map +1 -1
- package/dist/utils/facets/agent-graph-facet.d.ts +14 -1
- package/dist/utils/facets/agent-graph-facet.js +126 -49
- package/dist/utils/facets/agent-graph-facet.js.map +1 -1
- package/dist/utils/facets/api-instance-facet.d.ts +36 -1
- package/dist/utils/facets/api-instance-facet.js +196 -5
- package/dist/utils/facets/api-instance-facet.js.map +1 -1
- package/dist/utils/facets/connection-facet.d.ts +8 -0
- package/dist/utils/facets/connection-facet.js +65 -1
- package/dist/utils/facets/connection-facet.js.map +1 -1
- package/dist/utils/facets/deployment-helpers.d.ts +18 -1
- package/dist/utils/facets/deployment-helpers.js +53 -0
- package/dist/utils/facets/deployment-helpers.js.map +1 -1
- package/dist/utils/facets/deployment-logs.js +1 -0
- package/dist/utils/facets/deployment-logs.js.map +1 -1
- package/dist/utils/facets/deployment-runner.js +5 -0
- package/dist/utils/facets/deployment-runner.js.map +1 -1
- package/dist/utils/facets/facets.d.ts +2 -0
- package/dist/utils/facets/facets.js +20 -3
- package/dist/utils/facets/facets.js.map +1 -1
- package/dist/utils/facets/mule-application-facet.d.ts +1 -1
- package/dist/utils/facets/mule-application-facet.js +25 -21
- package/dist/utils/facets/mule-application-facet.js.map +1 -1
- package/dist/utils/files.d.ts +25 -0
- package/dist/utils/files.js +62 -0
- package/dist/utils/files.js.map +1 -1
- package/dist/utils/gateway.d.ts +6 -2
- package/dist/utils/gateway.js +37 -33
- package/dist/utils/gateway.js.map +1 -1
- package/dist/utils/keychain.d.ts +56 -0
- package/dist/utils/keychain.js +488 -0
- package/dist/utils/keychain.js.map +1 -0
- package/dist/utils/logger.d.ts +1 -0
- package/dist/utils/logger.js +3 -0
- package/dist/utils/logger.js.map +1 -1
- package/dist/utils/mcp/mcp-metadata-mapper.d.ts +8 -0
- package/dist/utils/mcp/mcp-metadata-mapper.js +7 -1
- package/dist/utils/mcp/mcp-metadata-mapper.js.map +1 -1
- package/dist/utils/mcp/project-registrar.js +2 -26
- package/dist/utils/mcp/project-registrar.js.map +1 -1
- package/dist/utils/naming.d.ts +13 -0
- package/dist/utils/naming.js +36 -4
- package/dist/utils/naming.js.map +1 -1
- package/dist/utils/request-executor.d.ts +5 -5
- package/dist/utils/run-local/agent-console-proxy.d.ts +56 -0
- package/dist/utils/run-local/agent-console-proxy.js +182 -0
- package/dist/utils/run-local/agent-console-proxy.js.map +1 -0
- package/dist/utils/run-local/broker-recreate-selector.d.ts +31 -0
- package/dist/utils/run-local/broker-recreate-selector.js +82 -0
- package/dist/utils/run-local/broker-recreate-selector.js.map +1 -0
- package/dist/utils/run-local/build-status.d.ts +73 -0
- package/dist/utils/run-local/build-status.js +210 -0
- package/dist/utils/run-local/build-status.js.map +1 -0
- package/dist/utils/run-local/constants.d.ts +28 -0
- package/dist/utils/run-local/constants.js +36 -0
- package/dist/utils/run-local/constants.js.map +1 -0
- package/dist/utils/run-local/crd-files.d.ts +2 -0
- package/dist/utils/run-local/crd-files.js +24 -0
- package/dist/utils/run-local/crd-files.js.map +1 -0
- package/dist/utils/run-local/index.d.ts +9 -0
- package/dist/utils/run-local/index.js +42 -0
- package/dist/utils/run-local/index.js.map +1 -0
- package/dist/utils/run-local/local-a2a-upstream.d.ts +9 -0
- package/dist/utils/run-local/local-a2a-upstream.js +55 -0
- package/dist/utils/run-local/local-a2a-upstream.js.map +1 -0
- package/dist/utils/run-local/local-deploy-descriptor.d.ts +36 -0
- package/dist/utils/run-local/local-deploy-descriptor.js +70 -0
- package/dist/utils/run-local/local-deploy-descriptor.js.map +1 -0
- package/dist/utils/run-local/local-run-manager.d.ts +51 -0
- package/dist/utils/run-local/local-run-manager.js +220 -0
- package/dist/utils/run-local/local-run-manager.js.map +1 -0
- package/dist/utils/run-local/policy-resolver.d.ts +69 -0
- package/dist/utils/run-local/policy-resolver.js +461 -0
- package/dist/utils/run-local/policy-resolver.js.map +1 -0
- package/dist/utils/run-local/runtime-environment-manager.d.ts +89 -0
- package/dist/utils/run-local/runtime-environment-manager.js +313 -0
- package/dist/utils/run-local/runtime-environment-manager.js.map +1 -0
- package/dist/utils/run-local/secrets-manager.d.ts +66 -0
- package/dist/utils/run-local/secrets-manager.js +181 -0
- package/dist/utils/run-local/secrets-manager.js.map +1 -0
- package/dist/utils/uris.js +4 -0
- package/dist/utils/uris.js.map +1 -1
- package/dist/utils/variables.d.ts +17 -4
- package/dist/utils/variables.js +52 -7
- package/dist/utils/variables.js.map +1 -1
- package/package.json +3 -1
- package/scripts/check-gus-ticket-format.sh +29 -0
- package/scripts/resolve-version.sh +161 -52
- package/scripts/resolve-version.test.sh +207 -20
- package/templates/agent-network/exchange.json.template +1 -0
- package/templates/agentic-network/brokers/broker1.agent.template +2 -2
- package/templates/agentic-network/exchange.json.template +1 -0
package/dist/utils/naming.d.ts
CHANGED
|
@@ -1,3 +1,16 @@
|
|
|
1
1
|
export declare function toSlug(input: string): string;
|
|
2
2
|
export declare function normalizeDeploymentName(input: string): string;
|
|
3
3
|
export declare function resolveDeploymentName(name: string | undefined, assetId: string): string;
|
|
4
|
+
/**
|
|
5
|
+
* Sanitizes an identifier into a valid Flex Gateway CRD resource name.
|
|
6
|
+
* Flex Gateway resource names and labels don't support underscores, so unlike
|
|
7
|
+
* {@link toSlug} this strips them (replacing with '-'). Use this for anything that
|
|
8
|
+
* feeds a CRD `metadata.name` / resource-name field in the run-local render path.
|
|
9
|
+
*/
|
|
10
|
+
export declare function toFlexResourceName(input: string): string;
|
|
11
|
+
export declare function toAgentGraphEnvVarName(name: string): string;
|
|
12
|
+
/**
|
|
13
|
+
* Builds `assetId + suffix`, trimming assetId (never the suffix) so the result fits the
|
|
14
|
+
* DNS label limit — this id doubles as a Docker Compose service name / network alias.
|
|
15
|
+
*/
|
|
16
|
+
export declare function trimToDnsLabel(assetId: string, suffix: string): string;
|
package/dist/utils/naming.js
CHANGED
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.toSlug = toSlug;
|
|
4
|
+
exports.normalizeDeploymentName = normalizeDeploymentName;
|
|
5
|
+
exports.resolveDeploymentName = resolveDeploymentName;
|
|
6
|
+
exports.toFlexResourceName = toFlexResourceName;
|
|
7
|
+
exports.toAgentGraphEnvVarName = toAgentGraphEnvVarName;
|
|
8
|
+
exports.trimToDnsLabel = trimToDnsLabel;
|
|
2
9
|
/*
|
|
3
10
|
* Copyright (c) 2026, Salesforce, Inc.
|
|
4
11
|
* All rights reserved.
|
|
5
12
|
* For full license text, see the LICENSE.txt file
|
|
6
13
|
*/
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
exports.normalizeDeploymentName = normalizeDeploymentName;
|
|
10
|
-
exports.resolveDeploymentName = resolveDeploymentName;
|
|
14
|
+
const logger_1 = require("./logger");
|
|
15
|
+
const constants_1 = require("./constants");
|
|
11
16
|
const WILDCARD = '-';
|
|
12
17
|
const WHITESPACE_PATTERN = /\s+/g;
|
|
13
18
|
const NON_LATIN_PATTERN = /[^\w-]+/g;
|
|
@@ -32,4 +37,31 @@ function normalizeDeploymentName(input) {
|
|
|
32
37
|
function resolveDeploymentName(name, assetId) {
|
|
33
38
|
return normalizeDeploymentName(name || assetId);
|
|
34
39
|
}
|
|
40
|
+
/**
|
|
41
|
+
* Sanitizes an identifier into a valid Flex Gateway CRD resource name.
|
|
42
|
+
* Flex Gateway resource names and labels don't support underscores, so unlike
|
|
43
|
+
* {@link toSlug} this strips them (replacing with '-'). Use this for anything that
|
|
44
|
+
* feeds a CRD `metadata.name` / resource-name field in the run-local render path.
|
|
45
|
+
*/
|
|
46
|
+
function toFlexResourceName(input) {
|
|
47
|
+
return slugify(input, [[UNDERSCORE_PATTERN, WILDCARD]]);
|
|
48
|
+
}
|
|
49
|
+
// Must exactly mirror agent-graph-module's common.py property_name_to_env_var — a divergence
|
|
50
|
+
// silently no-ops the env var lookup on the agent-graph side.
|
|
51
|
+
function toAgentGraphEnvVarName(name) {
|
|
52
|
+
return name.trim().replace(/[^\dA-Za-z]+/g, '_').replace(/^_+|_+$/g, '').toUpperCase();
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Builds `assetId + suffix`, trimming assetId (never the suffix) so the result fits the
|
|
56
|
+
* DNS label limit — this id doubles as a Docker Compose service name / network alias.
|
|
57
|
+
*/
|
|
58
|
+
function trimToDnsLabel(assetId, suffix) {
|
|
59
|
+
const full = assetId + suffix;
|
|
60
|
+
if (full.length <= constants_1.DNS_LABEL_MAX_LENGTH) {
|
|
61
|
+
return full;
|
|
62
|
+
}
|
|
63
|
+
const trimmedAssetId = assetId.slice(0, constants_1.DNS_LABEL_MAX_LENGTH - suffix.length);
|
|
64
|
+
logger_1.Log.warn(`Asset id '${assetId}' combined with suffix '${suffix}' exceeds the ${constants_1.DNS_LABEL_MAX_LENGTH}-character DNS label limit; trimmed to '${trimmedAssetId}${suffix}'.`);
|
|
65
|
+
return trimmedAssetId + suffix;
|
|
66
|
+
}
|
|
35
67
|
//# sourceMappingURL=naming.js.map
|
package/dist/utils/naming.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"naming.js","sourceRoot":"","sources":["../../src/utils/naming.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"naming.js","sourceRoot":"","sources":["../../src/utils/naming.ts"],"names":[],"mappings":";;AA2BA,wBAEC;AAED,0DAEC;AAED,sDAEC;AAQD,gDAEC;AAID,wDAEC;AAMD,wCASC;AApED;;;;GAIG;AACH,qCAA4B;AAC5B,2CAAgD;AAEhD,MAAM,QAAQ,GAAG,GAAG,CAAA;AACpB,MAAM,kBAAkB,GAAG,MAAM,CAAA;AACjC,MAAM,iBAAiB,GAAG,UAAU,CAAA;AACpC,MAAM,kBAAkB,GAAG,IAAI,CAAA;AAE/B,SAAS,OAAO,CAAC,KAAa,EAAE,YAAgC;IAC9D,MAAM,OAAO,GAAG,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,IAAI,EAAE,CAAA;IAC7B,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,OAAO,EAAE,CAAA;IACX,CAAC;IAED,IAAI,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,kBAAkB,EAAE,QAAQ,CAAC,CAAA;IAC1D,KAAK,MAAM,CAAC,OAAO,EAAE,WAAW,CAAC,IAAI,YAAY,EAAE,CAAC;QAClD,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,OAAO,EAAE,WAAW,CAAC,CAAA;IAC/C,CAAC;IAED,OAAO,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,iBAAiB,EAAE,EAAE,CAAC,CAAC,WAAW,EAAE,CAAA;AAC7E,CAAC;AAED,SAAgB,MAAM,CAAC,KAAa;IAClC,OAAO,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAA;AAC3B,CAAC;AAED,SAAgB,uBAAuB,CAAC,KAAa;IACnD,OAAO,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC,kBAAkB,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAA;AACzD,CAAC;AAED,SAAgB,qBAAqB,CAAC,IAAwB,EAAE,OAAe;IAC7E,OAAO,uBAAuB,CAAC,IAAI,IAAI,OAAO,CAAC,CAAA;AACjD,CAAC;AAED;;;;;GAKG;AACH,SAAgB,kBAAkB,CAAC,KAAa;IAC9C,OAAO,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC,kBAAkB,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAA;AACzD,CAAC;AAED,6FAA6F;AAC7F,8DAA8D;AAC9D,SAAgB,sBAAsB,CAAC,IAAY;IACjD,OAAO,IAAI,CAAC,IAAI,EAAE,CAAC,OAAO,CAAC,eAAe,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC,WAAW,EAAE,CAAA;AACxF,CAAC;AAED;;;GAGG;AACH,SAAgB,cAAc,CAAC,OAAe,EAAE,MAAc;IAC5D,MAAM,IAAI,GAAG,OAAO,GAAG,MAAM,CAAA;IAC7B,IAAI,IAAI,CAAC,MAAM,IAAI,gCAAoB,EAAE,CAAC;QACxC,OAAO,IAAI,CAAA;IACb,CAAC;IAED,MAAM,cAAc,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,gCAAoB,GAAG,MAAM,CAAC,MAAM,CAAC,CAAA;IAC7E,YAAG,CAAC,IAAI,CAAC,aAAa,OAAO,2BAA2B,MAAM,iBAAiB,gCAAoB,2CAA2C,cAAc,GAAG,MAAM,IAAI,CAAC,CAAA;IAC1K,OAAO,cAAc,GAAG,MAAM,CAAA;AAChC,CAAC"}
|
|
@@ -8,10 +8,10 @@ export declare const Retry: {
|
|
|
8
8
|
execute: typeof execute;
|
|
9
9
|
};
|
|
10
10
|
export declare const RequestExecutor: {
|
|
11
|
-
get<T = any>(req: AxiosInstance, url: string, config?: AxiosRequestConfig, maxAttempts?: number): Promise<import("axios").AxiosResponse<T, any
|
|
12
|
-
post<T = any>(req: AxiosInstance, url: string, body?: any, config?: AxiosRequestConfig, maxAttempts?: number): Promise<import("axios").AxiosResponse<T, any
|
|
13
|
-
put<T = any>(req: AxiosInstance, url: string, body?: any, config?: AxiosRequestConfig, maxAttempts?: number): Promise<import("axios").AxiosResponse<T, any
|
|
14
|
-
patch<T = any>(req: AxiosInstance, url: string, body?: any, config?: AxiosRequestConfig, maxAttempts?: number): Promise<import("axios").AxiosResponse<T, any
|
|
15
|
-
delete<T = any>(req: AxiosInstance, url: string, config?: AxiosRequestConfig, maxAttempts?: number): Promise<import("axios").AxiosResponse<T, any
|
|
11
|
+
get<T = any>(req: AxiosInstance, url: string, config?: AxiosRequestConfig, maxAttempts?: number): Promise<import("axios").AxiosResponse<T, any>>;
|
|
12
|
+
post<T = any>(req: AxiosInstance, url: string, body?: any, config?: AxiosRequestConfig, maxAttempts?: number): Promise<import("axios").AxiosResponse<T, any>>;
|
|
13
|
+
put<T = any>(req: AxiosInstance, url: string, body?: any, config?: AxiosRequestConfig, maxAttempts?: number): Promise<import("axios").AxiosResponse<T, any>>;
|
|
14
|
+
patch<T = any>(req: AxiosInstance, url: string, body?: any, config?: AxiosRequestConfig, maxAttempts?: number): Promise<import("axios").AxiosResponse<T, any>>;
|
|
15
|
+
delete<T = any>(req: AxiosInstance, url: string, config?: AxiosRequestConfig, maxAttempts?: number): Promise<import("axios").AxiosResponse<T, any>>;
|
|
16
16
|
};
|
|
17
17
|
export {};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
export declare const AGENT_CARD_SUFFIX = "/.well-known/agent-card.json";
|
|
2
|
+
export declare const CONSOLE_BIND_HOST = "127.0.0.1";
|
|
3
|
+
export declare const DEFAULT_GATEWAY_PORT = 8081;
|
|
4
|
+
export declare class AgentConsoleProxyError extends Error {
|
|
5
|
+
constructor(message: string);
|
|
6
|
+
}
|
|
7
|
+
export declare function normalizeAgentPath(path: string): string;
|
|
8
|
+
export declare function isAllowlistedAgentPath(path: string, allowed: Iterable<string>): boolean;
|
|
9
|
+
/**
|
|
10
|
+
* Join an allowlisted agent path onto the gateway origin. Uses `URL.origin` so
|
|
11
|
+
* userinfo (`path=@host`) cannot rewrite the host. Throws if the gateway URL is
|
|
12
|
+
* not http(s) or carries userinfo, or if the path is not allowlisted.
|
|
13
|
+
*/
|
|
14
|
+
export declare function joinGatewayUrl(gatewayUrl: string, agentPath: string, suffix: string, allowedPaths: Iterable<string>): string;
|
|
15
|
+
export declare function readDeployPortCfg(projectPath: string): string | undefined;
|
|
16
|
+
export declare function resolveGatewayUrl(explicitGatewayUrl: string | undefined, projectPath: string): string;
|
|
17
|
+
/** Do not follow 3xx — a gateway or upstream Location would bypass the path allowlist (second-hop SSRF). */
|
|
18
|
+
export declare const GATEWAY_FETCH_REDIRECT: RequestInit;
|
|
19
|
+
export declare class GatewayRedirectError extends AgentConsoleProxyError {
|
|
20
|
+
constructor();
|
|
21
|
+
}
|
|
22
|
+
export declare function rejectGatewayRedirect(response: {
|
|
23
|
+
status: number;
|
|
24
|
+
}): void;
|
|
25
|
+
/**
|
|
26
|
+
* True when `origin` is this console (http loopback + listen port). Rejects
|
|
27
|
+
* userinfo so a forged Origin cannot pass as loopback.
|
|
28
|
+
* @param origin Origin header value
|
|
29
|
+
* @param port Console listen port
|
|
30
|
+
* @returns whether the origin is this console
|
|
31
|
+
*/
|
|
32
|
+
export declare function isConsoleOrigin(origin: string, port: number): boolean;
|
|
33
|
+
export declare function isConsoleHostHeader(hostHeader: string, port: number): boolean;
|
|
34
|
+
type ConsoleRequestHeaders = {
|
|
35
|
+
host?: string | string[];
|
|
36
|
+
origin?: string | string[];
|
|
37
|
+
'content-type'?: string | string[];
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Loopback Host (and Origin, when sent) so DNS-rebinding / foreign pages cannot
|
|
41
|
+
* drive GET /api/agent-card as a blind gateway probe.
|
|
42
|
+
* @param headers Incoming Host and Origin
|
|
43
|
+
* @param port Console listen port
|
|
44
|
+
* @returns {void}
|
|
45
|
+
*/
|
|
46
|
+
export declare function assertConsoleLoopbackRequest(headers: ConsoleRequestHeaders, port: number): void;
|
|
47
|
+
/**
|
|
48
|
+
* CSRF / simple-request guard for POST /api/send and /api/cancel.
|
|
49
|
+
* Browsers' text/plain POSTs (no preflight) are rejected; an Origin, when sent,
|
|
50
|
+
* must be this console. Curl with application/json and no Origin still works.
|
|
51
|
+
* @param headers Incoming Host, Origin, and Content-Type
|
|
52
|
+
* @param port Console listen port
|
|
53
|
+
* @returns {void}
|
|
54
|
+
*/
|
|
55
|
+
export declare function assertConsoleMutatingRequest(headers: ConsoleRequestHeaders, port: number): void;
|
|
56
|
+
export {};
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GatewayRedirectError = exports.GATEWAY_FETCH_REDIRECT = exports.AgentConsoleProxyError = exports.DEFAULT_GATEWAY_PORT = exports.CONSOLE_BIND_HOST = exports.AGENT_CARD_SUFFIX = void 0;
|
|
4
|
+
exports.normalizeAgentPath = normalizeAgentPath;
|
|
5
|
+
exports.isAllowlistedAgentPath = isAllowlistedAgentPath;
|
|
6
|
+
exports.joinGatewayUrl = joinGatewayUrl;
|
|
7
|
+
exports.readDeployPortCfg = readDeployPortCfg;
|
|
8
|
+
exports.resolveGatewayUrl = resolveGatewayUrl;
|
|
9
|
+
exports.rejectGatewayRedirect = rejectGatewayRedirect;
|
|
10
|
+
exports.isConsoleOrigin = isConsoleOrigin;
|
|
11
|
+
exports.isConsoleHostHeader = isConsoleHostHeader;
|
|
12
|
+
exports.assertConsoleLoopbackRequest = assertConsoleLoopbackRequest;
|
|
13
|
+
exports.assertConsoleMutatingRequest = assertConsoleMutatingRequest;
|
|
14
|
+
/*
|
|
15
|
+
* Copyright (c) 2026, Salesforce, Inc.
|
|
16
|
+
* All rights reserved.
|
|
17
|
+
* For full license text, see the LICENSE.txt file
|
|
18
|
+
*/
|
|
19
|
+
const node_fs_1 = require("node:fs");
|
|
20
|
+
const node_path_1 = require("node:path");
|
|
21
|
+
const constants_1 = require("./constants");
|
|
22
|
+
exports.AGENT_CARD_SUFFIX = '/.well-known/agent-card.json';
|
|
23
|
+
exports.CONSOLE_BIND_HOST = '127.0.0.1';
|
|
24
|
+
exports.DEFAULT_GATEWAY_PORT = 8081;
|
|
25
|
+
const DISALLOWED_PATH = /[@:?#\\]|\/\/|\.\./;
|
|
26
|
+
class AgentConsoleProxyError extends Error {
|
|
27
|
+
constructor(message) {
|
|
28
|
+
super(message);
|
|
29
|
+
this.name = 'AgentConsoleProxyError';
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
exports.AgentConsoleProxyError = AgentConsoleProxyError;
|
|
33
|
+
function normalizeAgentPath(path) {
|
|
34
|
+
const trimmed = path.trim();
|
|
35
|
+
const withSlash = trimmed.startsWith('/') ? trimmed : `/${trimmed}`;
|
|
36
|
+
if (withSlash.length > 1 && withSlash.endsWith('/')) {
|
|
37
|
+
return withSlash.slice(0, -1);
|
|
38
|
+
}
|
|
39
|
+
return withSlash;
|
|
40
|
+
}
|
|
41
|
+
function isAllowlistedAgentPath(path, allowed) {
|
|
42
|
+
if (!path || DISALLOWED_PATH.test(path) || path.includes('://')) {
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
const normalized = normalizeAgentPath(path);
|
|
46
|
+
const allowedSet = allowed instanceof Set ? allowed : new Set([...allowed].map(normalizeAgentPath));
|
|
47
|
+
return allowedSet.has(normalized);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Join an allowlisted agent path onto the gateway origin. Uses `URL.origin` so
|
|
51
|
+
* userinfo (`path=@host`) cannot rewrite the host. Throws if the gateway URL is
|
|
52
|
+
* not http(s) or carries userinfo, or if the path is not allowlisted.
|
|
53
|
+
*/
|
|
54
|
+
function joinGatewayUrl(gatewayUrl, agentPath, suffix, allowedPaths) {
|
|
55
|
+
let gateway;
|
|
56
|
+
try {
|
|
57
|
+
gateway = new URL(gatewayUrl);
|
|
58
|
+
}
|
|
59
|
+
catch {
|
|
60
|
+
throw new AgentConsoleProxyError('Invalid gateway URL.');
|
|
61
|
+
}
|
|
62
|
+
if (gateway.protocol !== 'http:' && gateway.protocol !== 'https:') {
|
|
63
|
+
throw new AgentConsoleProxyError('Gateway URL must be http or https.');
|
|
64
|
+
}
|
|
65
|
+
if (gateway.username || gateway.password) {
|
|
66
|
+
throw new AgentConsoleProxyError('Gateway URL must not include credentials.');
|
|
67
|
+
}
|
|
68
|
+
if (!isAllowlistedAgentPath(agentPath, allowedPaths)) {
|
|
69
|
+
throw new AgentConsoleProxyError('Agent path is not allowlisted.');
|
|
70
|
+
}
|
|
71
|
+
const normalizedPath = normalizeAgentPath(agentPath);
|
|
72
|
+
const normalizedSuffix = suffix.startsWith('/') ? suffix : `/${suffix}`;
|
|
73
|
+
return new URL(`${normalizedPath}${normalizedSuffix}`, `${gateway.origin}/`).href;
|
|
74
|
+
}
|
|
75
|
+
function readDeployPortCfg(projectPath) {
|
|
76
|
+
const portFile = (0, node_path_1.join)(projectPath, constants_1.LOCAL_RUN_DIR, 'deploy-port.cfg');
|
|
77
|
+
if (!(0, node_fs_1.existsSync)(portFile)) {
|
|
78
|
+
return undefined;
|
|
79
|
+
}
|
|
80
|
+
const raw = (0, node_fs_1.readFileSync)(portFile, 'utf-8').trim();
|
|
81
|
+
return raw || undefined;
|
|
82
|
+
}
|
|
83
|
+
function resolveGatewayUrl(explicitGatewayUrl, projectPath) {
|
|
84
|
+
if (explicitGatewayUrl) {
|
|
85
|
+
return explicitGatewayUrl.replace(/\/$/, '');
|
|
86
|
+
}
|
|
87
|
+
const cfgPort = readDeployPortCfg(projectPath);
|
|
88
|
+
return `http://localhost:${cfgPort || exports.DEFAULT_GATEWAY_PORT}`;
|
|
89
|
+
}
|
|
90
|
+
/** Do not follow 3xx — a gateway or upstream Location would bypass the path allowlist (second-hop SSRF). */
|
|
91
|
+
exports.GATEWAY_FETCH_REDIRECT = { redirect: 'manual' };
|
|
92
|
+
class GatewayRedirectError extends AgentConsoleProxyError {
|
|
93
|
+
constructor() {
|
|
94
|
+
super('Refusing to follow an upstream redirect.');
|
|
95
|
+
this.name = 'GatewayRedirectError';
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
exports.GatewayRedirectError = GatewayRedirectError;
|
|
99
|
+
function rejectGatewayRedirect(response) {
|
|
100
|
+
if (response.status >= 300 && response.status < 400) {
|
|
101
|
+
throw new GatewayRedirectError();
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
function headerFirst(value) {
|
|
105
|
+
var _a;
|
|
106
|
+
if (Array.isArray(value)) {
|
|
107
|
+
return (_a = value[0]) !== null && _a !== void 0 ? _a : '';
|
|
108
|
+
}
|
|
109
|
+
return value !== null && value !== void 0 ? value : '';
|
|
110
|
+
}
|
|
111
|
+
function isLoopbackHostname(hostname) {
|
|
112
|
+
return hostname === exports.CONSOLE_BIND_HOST || hostname === 'localhost' || hostname === '::1' || hostname === '[::1]';
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* True when `origin` is this console (http loopback + listen port). Rejects
|
|
116
|
+
* userinfo so a forged Origin cannot pass as loopback.
|
|
117
|
+
* @param origin Origin header value
|
|
118
|
+
* @param port Console listen port
|
|
119
|
+
* @returns whether the origin is this console
|
|
120
|
+
*/
|
|
121
|
+
function isConsoleOrigin(origin, port) {
|
|
122
|
+
let url;
|
|
123
|
+
try {
|
|
124
|
+
url = new URL(origin);
|
|
125
|
+
}
|
|
126
|
+
catch {
|
|
127
|
+
return false;
|
|
128
|
+
}
|
|
129
|
+
if (url.protocol !== 'http:' || url.username || url.password) {
|
|
130
|
+
return false;
|
|
131
|
+
}
|
|
132
|
+
if (url.pathname !== '/' || url.search || url.hash) {
|
|
133
|
+
return false;
|
|
134
|
+
}
|
|
135
|
+
if (!isLoopbackHostname(url.hostname)) {
|
|
136
|
+
return false;
|
|
137
|
+
}
|
|
138
|
+
const actualPort = url.port || '80';
|
|
139
|
+
return actualPort === String(port);
|
|
140
|
+
}
|
|
141
|
+
function isConsoleHostHeader(hostHeader, port) {
|
|
142
|
+
const host = hostHeader.trim();
|
|
143
|
+
if (!host) {
|
|
144
|
+
return false;
|
|
145
|
+
}
|
|
146
|
+
return isConsoleOrigin(`http://${host}`, port);
|
|
147
|
+
}
|
|
148
|
+
function isJsonContentType(contentType) {
|
|
149
|
+
const mediaType = contentType.split(';')[0].trim().toLowerCase();
|
|
150
|
+
return mediaType === 'application/json';
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Loopback Host (and Origin, when sent) so DNS-rebinding / foreign pages cannot
|
|
154
|
+
* drive GET /api/agent-card as a blind gateway probe.
|
|
155
|
+
* @param headers Incoming Host and Origin
|
|
156
|
+
* @param port Console listen port
|
|
157
|
+
* @returns {void}
|
|
158
|
+
*/
|
|
159
|
+
function assertConsoleLoopbackRequest(headers, port) {
|
|
160
|
+
if (!isConsoleHostHeader(headerFirst(headers.host), port)) {
|
|
161
|
+
throw new AgentConsoleProxyError('Invalid Host.');
|
|
162
|
+
}
|
|
163
|
+
const origin = headerFirst(headers.origin);
|
|
164
|
+
if (origin && !isConsoleOrigin(origin, port)) {
|
|
165
|
+
throw new AgentConsoleProxyError('Invalid Origin.');
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* CSRF / simple-request guard for POST /api/send and /api/cancel.
|
|
170
|
+
* Browsers' text/plain POSTs (no preflight) are rejected; an Origin, when sent,
|
|
171
|
+
* must be this console. Curl with application/json and no Origin still works.
|
|
172
|
+
* @param headers Incoming Host, Origin, and Content-Type
|
|
173
|
+
* @param port Console listen port
|
|
174
|
+
* @returns {void}
|
|
175
|
+
*/
|
|
176
|
+
function assertConsoleMutatingRequest(headers, port) {
|
|
177
|
+
if (!isJsonContentType(headerFirst(headers['content-type']))) {
|
|
178
|
+
throw new AgentConsoleProxyError('Content-Type must be application/json.');
|
|
179
|
+
}
|
|
180
|
+
assertConsoleLoopbackRequest(headers, port);
|
|
181
|
+
}
|
|
182
|
+
//# sourceMappingURL=agent-console-proxy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-console-proxy.js","sourceRoot":"","sources":["../../../src/utils/run-local/agent-console-proxy.ts"],"names":[],"mappings":";;;AAsBA,gDAQC;AAED,wDAQC;AAOD,wCA4BC;AAED,8CAQC;AAED,8CAOC;AAYD,sDAIC;AAqBD,0CAsBC;AAED,kDAOC;AAgBD,oEASC;AAUD,oEAMC;AA3MD;;;;GAIG;AACH,qCAAgD;AAChD,yCAA8B;AAC9B,2CAAyC;AAE5B,QAAA,iBAAiB,GAAG,8BAA8B,CAAA;AAClD,QAAA,iBAAiB,GAAG,WAAW,CAAA;AAC/B,QAAA,oBAAoB,GAAG,IAAI,CAAA;AAExC,MAAM,eAAe,GAAG,oBAAoB,CAAA;AAE5C,MAAa,sBAAuB,SAAQ,KAAK;IAC/C,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,wBAAwB,CAAA;IACtC,CAAC;CACF;AALD,wDAKC;AAED,SAAgB,kBAAkB,CAAC,IAAY;IAC7C,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,EAAE,CAAA;IAC3B,MAAM,SAAS,GAAG,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,OAAO,EAAE,CAAA;IACnE,IAAI,SAAS,CAAC,MAAM,GAAG,CAAC,IAAI,SAAS,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;QACpD,OAAO,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;IAC/B,CAAC;IAED,OAAO,SAAS,CAAA;AAClB,CAAC;AAED,SAAgB,sBAAsB,CAAC,IAAY,EAAE,OAAyB;IAC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
|
3
|
+
* A rebuild's fingerprint of everything a broker container binds at creation time: its own env file
|
|
4
|
+
* (read once, at container creation) and the shared source tree (a single mount + mainFile that
|
|
5
|
+
* every broker reads). Carried forward across rebuilds so the next one recreates only what changed.
|
|
6
|
+
*/
|
|
7
|
+
export type RecreateFingerprints = {
|
|
8
|
+
/** brokerId → sha256 of that broker's env file (or ENV_FILE_MISSING when the file is absent). */
|
|
9
|
+
env: Record<string, string>;
|
|
10
|
+
/** Order-independent digest of the shared agent-graph/src tree. */
|
|
11
|
+
sharedSource: string;
|
|
12
|
+
};
|
|
13
|
+
export type BrokerRecreateSelection = {
|
|
14
|
+
services: string[];
|
|
15
|
+
fingerprints: RecreateFingerprints;
|
|
16
|
+
};
|
|
17
|
+
/** Every agent-graph compose service name (broker id) across the space's components. */
|
|
18
|
+
export declare function agentGraphServiceIds(space: Space): string[];
|
|
19
|
+
/** Fingerprints the current on-disk render: per-broker env files plus the shared source tree. */
|
|
20
|
+
export declare function computeRecreateFingerprints(space: Space, localRenderDir: string): RecreateFingerprints;
|
|
21
|
+
/**
|
|
22
|
+
* Selects which broker containers a rebuild must recreate, comparing the current render's
|
|
23
|
+
* fingerprints against the previous rebuild's. Returns the new fingerprints so the caller can thread
|
|
24
|
+
* them forward — the next rebuild then diffs against the just-applied state.
|
|
25
|
+
*
|
|
26
|
+
* Absent a prior snapshot (the first rebuild without a baseline) every broker is recreated, matching
|
|
27
|
+
* the initial force-recreate. A changed shared source tree recreates ALL brokers: a source/spec edit
|
|
28
|
+
* mutates the single read-only mount and mainFile every broker shares, so it is not attributable to
|
|
29
|
+
* one broker. Otherwise only brokers whose env file changed (or is newly appearing/missing) recreate.
|
|
30
|
+
*/
|
|
31
|
+
export declare function selectBrokersToRecreate(space: Space, localRenderDir: string, prior: RecreateFingerprints | undefined): BrokerRecreateSelection;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.agentGraphServiceIds = agentGraphServiceIds;
|
|
4
|
+
exports.computeRecreateFingerprints = computeRecreateFingerprints;
|
|
5
|
+
exports.selectBrokersToRecreate = selectBrokersToRecreate;
|
|
6
|
+
const tslib_1 = require("tslib");
|
|
7
|
+
const node_crypto_1 = require("node:crypto");
|
|
8
|
+
const fs = tslib_1.__importStar(require("fs-extra"));
|
|
9
|
+
const node_path_1 = require("node:path");
|
|
10
|
+
const AGENT_GRAPH_DIR = 'agent-graph';
|
|
11
|
+
const SHARED_SRC_DIR = 'src';
|
|
12
|
+
const ENV_FILE = 'env';
|
|
13
|
+
// Sentinel hash for a broker whose env file is absent on disk. sha256 hex is 64 chars, so this can
|
|
14
|
+
// never collide with a real digest — it forces the broker to recreate rather than crashing.
|
|
15
|
+
const ENV_FILE_MISSING = 'missing';
|
|
16
|
+
/** Every agent-graph compose service name (broker id) across the space's components. */
|
|
17
|
+
function agentGraphServiceIds(space) {
|
|
18
|
+
return Object.values(space.components).flatMap(component => Object.values(component.agentGraphs).map(agentGraph => agentGraph.id));
|
|
19
|
+
}
|
|
20
|
+
function sha256(data) {
|
|
21
|
+
return (0, node_crypto_1.createHash)('sha256').update(data).digest('hex');
|
|
22
|
+
}
|
|
23
|
+
function hashEnvFile(envPath) {
|
|
24
|
+
if (!fs.existsSync(envPath)) {
|
|
25
|
+
return ENV_FILE_MISSING;
|
|
26
|
+
}
|
|
27
|
+
return sha256(fs.readFileSync(envPath));
|
|
28
|
+
}
|
|
29
|
+
function hashSharedSource(srcDir) {
|
|
30
|
+
if (!fs.existsSync(srcDir)) {
|
|
31
|
+
return '';
|
|
32
|
+
}
|
|
33
|
+
const entries = [];
|
|
34
|
+
const walk = (dir, rel) => {
|
|
35
|
+
for (const name of fs.readdirSync(dir).sort()) {
|
|
36
|
+
const abs = (0, node_path_1.join)(dir, name);
|
|
37
|
+
const relPath = rel ? `${rel}/${name}` : name;
|
|
38
|
+
// lstat, not stat: following a symlink throws on a broken link and recurses forever on a
|
|
39
|
+
// directory-symlink cycle. A symlink is fingerprinted by its link value, not its target.
|
|
40
|
+
const stat = fs.lstatSync(abs);
|
|
41
|
+
if (stat.isSymbolicLink()) {
|
|
42
|
+
entries.push(`${relPath}:symlink:${sha256(fs.readlinkSync(abs))}`);
|
|
43
|
+
}
|
|
44
|
+
else if (stat.isDirectory()) {
|
|
45
|
+
walk(abs, relPath);
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
entries.push(`${relPath}:${sha256(fs.readFileSync(abs))}`);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
walk(srcDir, '');
|
|
53
|
+
return sha256(entries.join('\n'));
|
|
54
|
+
}
|
|
55
|
+
/** Fingerprints the current on-disk render: per-broker env files plus the shared source tree. */
|
|
56
|
+
function computeRecreateFingerprints(space, localRenderDir) {
|
|
57
|
+
const env = {};
|
|
58
|
+
for (const id of agentGraphServiceIds(space)) {
|
|
59
|
+
env[id] = hashEnvFile((0, node_path_1.join)(localRenderDir, AGENT_GRAPH_DIR, id, ENV_FILE));
|
|
60
|
+
}
|
|
61
|
+
return { env, sharedSource: hashSharedSource((0, node_path_1.join)(localRenderDir, AGENT_GRAPH_DIR, SHARED_SRC_DIR)) };
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Selects which broker containers a rebuild must recreate, comparing the current render's
|
|
65
|
+
* fingerprints against the previous rebuild's. Returns the new fingerprints so the caller can thread
|
|
66
|
+
* them forward — the next rebuild then diffs against the just-applied state.
|
|
67
|
+
*
|
|
68
|
+
* Absent a prior snapshot (the first rebuild without a baseline) every broker is recreated, matching
|
|
69
|
+
* the initial force-recreate. A changed shared source tree recreates ALL brokers: a source/spec edit
|
|
70
|
+
* mutates the single read-only mount and mainFile every broker shares, so it is not attributable to
|
|
71
|
+
* one broker. Otherwise only brokers whose env file changed (or is newly appearing/missing) recreate.
|
|
72
|
+
*/
|
|
73
|
+
function selectBrokersToRecreate(space, localRenderDir, prior) {
|
|
74
|
+
const fingerprints = computeRecreateFingerprints(space, localRenderDir);
|
|
75
|
+
const allIds = agentGraphServiceIds(space);
|
|
76
|
+
if (!prior || fingerprints.sharedSource !== prior.sharedSource) {
|
|
77
|
+
return { services: allIds, fingerprints };
|
|
78
|
+
}
|
|
79
|
+
const services = allIds.filter(id => fingerprints.env[id] === ENV_FILE_MISSING || prior.env[id] !== fingerprints.env[id]);
|
|
80
|
+
return { services, fingerprints };
|
|
81
|
+
}
|
|
82
|
+
//# sourceMappingURL=broker-recreate-selector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"broker-recreate-selector.js","sourceRoot":"","sources":["../../../src/utils/run-local/broker-recreate-selector.ts"],"names":[],"mappings":";;AA8BA,oDAGC;AA0CD,kEAOC;AAYD,0DAeC;;AA7GD,6CAAsC;AACtC,qDAA8B;AAC9B,yCAA8B;AAG9B,MAAM,eAAe,GAAG,aAAa,CAAA;AACrC,MAAM,cAAc,GAAG,KAAK,CAAA;AAC5B,MAAM,QAAQ,GAAG,KAAK,CAAA;AACtB,mGAAmG;AACnG,4FAA4F;AAC5F,MAAM,gBAAgB,GAAG,SAAS,CAAA;AAmBlC,wFAAwF;AACxF,SAAgB,oBAAoB,CAAC,KAAY;IAC/C,OAAO,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,CACzD,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC,CAAA;AAC1E,CAAC;AAED,SAAS,MAAM,CAAC,IAAqB;IACnC,OAAO,IAAA,wBAAU,EAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;AACxD,CAAC;AAED,SAAS,WAAW,CAAC,OAAe;IAClC,IAAI,CAAC,EAAE,CAAC,UA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
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/** Bumped only on a breaking change to the shape; consumers must ignore versions they don't know. */
|
|
2
|
+
export declare const BUILD_STATUS_SCHEMA_VERSION: 1;
|
|
3
|
+
export declare const LOCAL_DEPLOYMENT_SESSION_ID_ENV = "MULE_LOCAL_DEPLOYMENT_SESSION_ID";
|
|
4
|
+
export type LocalDeploymentTask = 'initializing' | 'building' | 'rendering' | 'waiting_for_input' | 'deploying';
|
|
5
|
+
export type LocalDeploymentFailurePhase = LocalDeploymentTask | 'runtime';
|
|
6
|
+
export type LocalDeploymentFailureKind = 'port' | 'build' | 'docker_prerequisite' | 'project_input' | 'schema_validation' | 'variable_validation' | 'secret_validation' | 'policy' | 'runtime_config' | 'compose_command' | 'runtime_exit' | 'unexpected';
|
|
7
|
+
export type LocalDeploymentTrigger = 'initial' | 'watch';
|
|
8
|
+
export type LocalDeploymentFailure = {
|
|
9
|
+
phase: LocalDeploymentFailurePhase;
|
|
10
|
+
kind: LocalDeploymentFailureKind;
|
|
11
|
+
code?: number;
|
|
12
|
+
};
|
|
13
|
+
export type LocalDeploymentOperationStatus = {
|
|
14
|
+
schemaVersion: typeof BUILD_STATUS_SCHEMA_VERSION;
|
|
15
|
+
sessionId: string;
|
|
16
|
+
sequence: number;
|
|
17
|
+
generation: number;
|
|
18
|
+
trigger: LocalDeploymentTrigger;
|
|
19
|
+
state: 'running';
|
|
20
|
+
task?: LocalDeploymentTask;
|
|
21
|
+
} | {
|
|
22
|
+
schemaVersion: typeof BUILD_STATUS_SCHEMA_VERSION;
|
|
23
|
+
sessionId: string;
|
|
24
|
+
sequence: number;
|
|
25
|
+
generation: number;
|
|
26
|
+
trigger: LocalDeploymentTrigger;
|
|
27
|
+
state: 'completed' | 'failed' | 'cancelled';
|
|
28
|
+
failure?: LocalDeploymentFailure;
|
|
29
|
+
};
|
|
30
|
+
/** True when `docker compose` was killed by a process signal (Ctrl+C / SIGTERM). */
|
|
31
|
+
export declare function isComposeSignalExit(error: unknown): boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Resolves a session id from an explicit value or `MULE_LOCAL_DEPLOYMENT_SESSION_ID`.
|
|
34
|
+
* Rejects path traversal and other unsafe temp-name characters.
|
|
35
|
+
*/
|
|
36
|
+
export declare function resolveLocalDeploymentSessionId(explicit?: string): string;
|
|
37
|
+
/**
|
|
38
|
+
* Maps a thrown value to the machine-readable failure shape. Never copies messages, paths, or
|
|
39
|
+
* secrets — only phase/kind and an optional numeric BaseError.errorCode.
|
|
40
|
+
*/
|
|
41
|
+
export declare function classifyLocalDeploymentFailure(error: unknown, currentPhase: LocalDeploymentFailurePhase): LocalDeploymentFailure;
|
|
42
|
+
export type LocalDeploymentStatusWriterOptions = {
|
|
43
|
+
sessionId?: string;
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* Owns `.deployment/local/build-status.json`. Writes are advisory: I/O failures warn and never throw.
|
|
47
|
+
* Call sites live in RunLocal / WatchSession only — not in RuntimeEnvironmentManager.
|
|
48
|
+
*
|
|
49
|
+
* After `seal()` or a terminal write (`completed` / `failed` / `cancelled`), further non-cancel
|
|
50
|
+
* writes are dropped so an in-flight rebuild cannot overwrite Ctrl+C. `beginWatchGeneration`
|
|
51
|
+
* clears the latch so the next watch generation can publish again after a non-fatal failure.
|
|
52
|
+
*/
|
|
53
|
+
export declare class LocalDeploymentStatusWriter {
|
|
54
|
+
private readonly localRunDir;
|
|
55
|
+
readonly sessionId: string;
|
|
56
|
+
private sequence;
|
|
57
|
+
private generation;
|
|
58
|
+
private trigger;
|
|
59
|
+
private currentPhase;
|
|
60
|
+
private sealed;
|
|
61
|
+
private cancelledEmitted;
|
|
62
|
+
constructor(localRunDir: string, options?: LocalDeploymentStatusWriterOptions);
|
|
63
|
+
/** Drop subsequent non-cancel writes; call at shutdown start before teardown I/O. */
|
|
64
|
+
seal(): void;
|
|
65
|
+
/** Call once at the start of each watch rebuild — not on debounce or queue coalescing. */
|
|
66
|
+
beginWatchGeneration(): void;
|
|
67
|
+
writeRunning(task?: LocalDeploymentTask): void;
|
|
68
|
+
writeCompleted(): void;
|
|
69
|
+
writeFailed(error: unknown, phase?: LocalDeploymentFailurePhase): void;
|
|
70
|
+
writeCancelled(): void;
|
|
71
|
+
private nextSequence;
|
|
72
|
+
private writeAtomic;
|
|
73
|
+
}
|