@superblocksteam/gateway 2.0.0-SNAPSHOT.1d4c72c0ab174c21
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/LICENSE.txt +87 -0
- package/README.md +291 -0
- package/dist/agents/resolve-orchestrator-url.d.ts +22 -0
- package/dist/agents/resolve-orchestrator-url.js +38 -0
- package/dist/agents/resolve-orchestrator-url.js.map +1 -0
- package/dist/capabilities/integration-metadata.d.ts +28 -0
- package/dist/capabilities/integration-metadata.js +174 -0
- package/dist/capabilities/integration-metadata.js.map +1 -0
- package/dist/capabilities/lifecycle.d.ts +93 -0
- package/dist/capabilities/lifecycle.js +3450 -0
- package/dist/capabilities/lifecycle.js.map +1 -0
- package/dist/capabilities/query-integration.d.ts +14 -0
- package/dist/capabilities/query-integration.js +172 -0
- package/dist/capabilities/query-integration.js.map +1 -0
- package/dist/capabilities/source-files-archive.d.ts +11 -0
- package/dist/capabilities/source-files-archive.js +54 -0
- package/dist/capabilities/source-files-archive.js.map +1 -0
- package/dist/capabilities/types.d.ts +542 -0
- package/dist/capabilities/types.js +86 -0
- package/dist/capabilities/types.js.map +1 -0
- package/dist/capture/browser-contract.d.ts +46 -0
- package/dist/capture/browser-contract.js +34 -0
- package/dist/capture/browser-contract.js.map +1 -0
- package/dist/capture/browser-instructions.d.ts +10 -0
- package/dist/capture/browser-instructions.js +18 -0
- package/dist/capture/browser-instructions.js.map +1 -0
- package/dist/capture/capture-library-probe.d.ts +55 -0
- package/dist/capture/capture-library-probe.js +177 -0
- package/dist/capture/capture-library-probe.js.map +1 -0
- package/dist/capture/capture-library.d.ts +52 -0
- package/dist/capture/capture-library.js +249 -0
- package/dist/capture/capture-library.js.map +1 -0
- package/dist/capture/classify-library-paint.d.ts +21 -0
- package/dist/capture/classify-library-paint.js +13 -0
- package/dist/capture/classify-library-paint.js.map +1 -0
- package/dist/capture/host-mcp-scan.d.ts +16 -0
- package/dist/capture/host-mcp-scan.js +64 -0
- package/dist/capture/host-mcp-scan.js.map +1 -0
- package/dist/capture/library-parent-script.d.ts +35 -0
- package/dist/capture/library-parent-script.js +82 -0
- package/dist/capture/library-parent-script.js.map +1 -0
- package/dist/capture/mode.d.ts +29 -0
- package/dist/capture/mode.js +65 -0
- package/dist/capture/mode.js.map +1 -0
- package/dist/config.d.ts +148 -0
- package/dist/config.js +111 -0
- package/dist/config.js.map +1 -0
- package/dist/debug.d.ts +2 -0
- package/dist/debug.js +9 -0
- package/dist/debug.js.map +1 -0
- package/dist/deps.d.ts +38 -0
- package/dist/deps.js +2 -0
- package/dist/deps.js.map +1 -0
- package/dist/health/readiness.d.ts +99 -0
- package/dist/health/readiness.js +202 -0
- package/dist/health/readiness.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/dist/integrations/filters.d.ts +8 -0
- package/dist/integrations/filters.js +40 -0
- package/dist/integrations/filters.js.map +1 -0
- package/dist/integrations/map.d.ts +27 -0
- package/dist/integrations/map.js +43 -0
- package/dist/integrations/map.js.map +1 -0
- package/dist/integrations/profile-key.d.ts +19 -0
- package/dist/integrations/profile-key.js +35 -0
- package/dist/integrations/profile-key.js.map +1 -0
- package/dist/integrations/read-only-postgres-query.d.ts +2 -0
- package/dist/integrations/read-only-postgres-query.js +164 -0
- package/dist/integrations/read-only-postgres-query.js.map +1 -0
- package/dist/main.d.ts +2 -0
- package/dist/main.js +5 -0
- package/dist/main.js.map +1 -0
- package/dist/orchestrator/client.d.ts +62 -0
- package/dist/orchestrator/client.js +160 -0
- package/dist/orchestrator/client.js.map +1 -0
- package/dist/playwright/ensure-chromium.d.ts +24 -0
- package/dist/playwright/ensure-chromium.js +60 -0
- package/dist/playwright/ensure-chromium.js.map +1 -0
- package/dist/preview/capture-screenshot.d.ts +67 -0
- package/dist/preview/capture-screenshot.js +179 -0
- package/dist/preview/capture-screenshot.js.map +1 -0
- package/dist/preview/viewer-url.d.ts +82 -0
- package/dist/preview/viewer-url.js +130 -0
- package/dist/preview/viewer-url.js.map +1 -0
- package/dist/process/fault-barrier.d.ts +55 -0
- package/dist/process/fault-barrier.js +113 -0
- package/dist/process/fault-barrier.js.map +1 -0
- package/dist/sabs/agent-facing-text.d.ts +35 -0
- package/dist/sabs/agent-facing-text.js +165 -0
- package/dist/sabs/agent-facing-text.js.map +1 -0
- package/dist/sabs/app-state.d.ts +126 -0
- package/dist/sabs/app-state.js +332 -0
- package/dist/sabs/app-state.js.map +1 -0
- package/dist/sabs/awaited-decision.d.ts +47 -0
- package/dist/sabs/awaited-decision.js +124 -0
- package/dist/sabs/awaited-decision.js.map +1 -0
- package/dist/sabs/browser-context.d.ts +53 -0
- package/dist/sabs/browser-context.js +92 -0
- package/dist/sabs/browser-context.js.map +1 -0
- package/dist/sabs/editor-client-methods.d.ts +164 -0
- package/dist/sabs/editor-client-methods.js +750 -0
- package/dist/sabs/editor-client-methods.js.map +1 -0
- package/dist/sabs/editor-socket.d.ts +84 -0
- package/dist/sabs/editor-socket.js +64 -0
- package/dist/sabs/editor-socket.js.map +1 -0
- package/dist/sabs/recent-tool-runs.d.ts +14 -0
- package/dist/sabs/recent-tool-runs.js +61 -0
- package/dist/sabs/recent-tool-runs.js.map +1 -0
- package/dist/sabs/session-peer.d.ts +392 -0
- package/dist/sabs/session-peer.js +11 -0
- package/dist/sabs/session-peer.js.map +1 -0
- package/dist/sabs/streamed-reply.d.ts +42 -0
- package/dist/sabs/streamed-reply.js +110 -0
- package/dist/sabs/streamed-reply.js.map +1 -0
- package/dist/sabs/turn-collector.d.ts +169 -0
- package/dist/sabs/turn-collector.js +506 -0
- package/dist/sabs/turn-collector.js.map +1 -0
- package/dist/sabs/websocket-session-peer.d.ts +540 -0
- package/dist/sabs/websocket-session-peer.js +3289 -0
- package/dist/sabs/websocket-session-peer.js.map +1 -0
- package/dist/security/constant-time.d.ts +9 -0
- package/dist/security/constant-time.js +13 -0
- package/dist/security/constant-time.js.map +1 -0
- package/dist/server/client.d.ts +405 -0
- package/dist/server/client.js +684 -0
- package/dist/server/client.js.map +1 -0
- package/dist/server/identity-reads.d.ts +76 -0
- package/dist/server/identity-reads.js +209 -0
- package/dist/server/identity-reads.js.map +1 -0
- package/dist/start.d.ts +24 -0
- package/dist/start.js +81 -0
- package/dist/start.js.map +1 -0
- package/dist/stores/memory.d.ts +42 -0
- package/dist/stores/memory.js +121 -0
- package/dist/stores/memory.js.map +1 -0
- package/dist/stores/types.d.ts +74 -0
- package/dist/stores/types.js +11 -0
- package/dist/stores/types.js.map +1 -0
- package/dist/telemetry/mcp-client.d.ts +22 -0
- package/dist/telemetry/mcp-client.js +140 -0
- package/dist/telemetry/mcp-client.js.map +1 -0
- package/dist/telemetry/metrics.d.ts +41 -0
- package/dist/telemetry/metrics.js +103 -0
- package/dist/telemetry/metrics.js.map +1 -0
- package/dist/telemetry/runtime.d.ts +9 -0
- package/dist/telemetry/runtime.js +118 -0
- package/dist/telemetry/runtime.js.map +1 -0
- package/dist/transports/mcp/admin-tools.d.ts +56 -0
- package/dist/transports/mcp/admin-tools.js +252 -0
- package/dist/transports/mcp/admin-tools.js.map +1 -0
- package/dist/transports/mcp/app-status-html.d.ts +11 -0
- package/dist/transports/mcp/app-status-html.js +899 -0
- package/dist/transports/mcp/app-status-html.js.map +1 -0
- package/dist/transports/mcp/client-presentation.d.ts +16 -0
- package/dist/transports/mcp/client-presentation.js +13 -0
- package/dist/transports/mcp/client-presentation.js.map +1 -0
- package/dist/transports/mcp/cowork-editor-url.d.ts +6 -0
- package/dist/transports/mcp/cowork-editor-url.js +10 -0
- package/dist/transports/mcp/cowork-editor-url.js.map +1 -0
- package/dist/transports/mcp/decision-card-html.d.ts +26 -0
- package/dist/transports/mcp/decision-card-html.js +876 -0
- package/dist/transports/mcp/decision-card-html.js.map +1 -0
- package/dist/transports/mcp/decision-elicitation.d.ts +116 -0
- package/dist/transports/mcp/decision-elicitation.js +292 -0
- package/dist/transports/mcp/decision-elicitation.js.map +1 -0
- package/dist/transports/mcp/dispatch-probe.d.ts +24 -0
- package/dist/transports/mcp/dispatch-probe.js +48 -0
- package/dist/transports/mcp/dispatch-probe.js.map +1 -0
- package/dist/transports/mcp/editor-document-probe.d.ts +4 -0
- package/dist/transports/mcp/editor-document-probe.js +35 -0
- package/dist/transports/mcp/editor-document-probe.js.map +1 -0
- package/dist/transports/mcp/editor-integration-setup-url.d.ts +8 -0
- package/dist/transports/mcp/editor-integration-setup-url.js +23 -0
- package/dist/transports/mcp/editor-integration-setup-url.js.map +1 -0
- package/dist/transports/mcp/format-tool-content.d.ts +20 -0
- package/dist/transports/mcp/format-tool-content.js +89 -0
- package/dist/transports/mcp/format-tool-content.js.map +1 -0
- package/dist/transports/mcp/instructions/index.d.ts +23 -0
- package/dist/transports/mcp/instructions/index.js +81 -0
- package/dist/transports/mcp/instructions/index.js.map +1 -0
- package/dist/transports/mcp/instructions/result.d.ts +18 -0
- package/dist/transports/mcp/instructions/result.js +58 -0
- package/dist/transports/mcp/instructions/result.js.map +1 -0
- package/dist/transports/mcp/instructions/tools/ask-user.d.ts +2 -0
- package/dist/transports/mcp/instructions/tools/ask-user.js +17 -0
- package/dist/transports/mcp/instructions/tools/ask-user.js.map +1 -0
- package/dist/transports/mcp/instructions/tools/check-app-progress.d.ts +3 -0
- package/dist/transports/mcp/instructions/tools/check-app-progress.js +75 -0
- package/dist/transports/mcp/instructions/tools/check-app-progress.js.map +1 -0
- package/dist/transports/mcp/instructions/tools/check-publish-progress.d.ts +3 -0
- package/dist/transports/mcp/instructions/tools/check-publish-progress.js +23 -0
- package/dist/transports/mcp/instructions/tools/check-publish-progress.js.map +1 -0
- package/dist/transports/mcp/instructions/tools/copy.d.ts +14 -0
- package/dist/transports/mcp/instructions/tools/copy.js +35 -0
- package/dist/transports/mcp/instructions/tools/copy.js.map +1 -0
- package/dist/transports/mcp/instructions/tools/create-integration.d.ts +4 -0
- package/dist/transports/mcp/instructions/tools/create-integration.js +41 -0
- package/dist/transports/mcp/instructions/tools/create-integration.js.map +1 -0
- package/dist/transports/mcp/instructions/tools/edit-app.d.ts +2 -0
- package/dist/transports/mcp/instructions/tools/edit-app.js +18 -0
- package/dist/transports/mcp/instructions/tools/edit-app.js.map +1 -0
- package/dist/transports/mcp/instructions/tools/get-app.d.ts +3 -0
- package/dist/transports/mcp/instructions/tools/get-app.js +47 -0
- package/dist/transports/mcp/instructions/tools/get-app.js.map +1 -0
- package/dist/transports/mcp/instructions/tools/get-integration-metadata.d.ts +2 -0
- package/dist/transports/mcp/instructions/tools/get-integration-metadata.js +13 -0
- package/dist/transports/mcp/instructions/tools/get-integration-metadata.js.map +1 -0
- package/dist/transports/mcp/instructions/tools/index.d.ts +7 -0
- package/dist/transports/mcp/instructions/tools/index.js +26 -0
- package/dist/transports/mcp/instructions/tools/index.js.map +1 -0
- package/dist/transports/mcp/instructions/tools/preview-app.d.ts +3 -0
- package/dist/transports/mcp/instructions/tools/preview-app.js +14 -0
- package/dist/transports/mcp/instructions/tools/preview-app.js.map +1 -0
- package/dist/transports/mcp/instructions/tools/publish-app.d.ts +3 -0
- package/dist/transports/mcp/instructions/tools/publish-app.js +23 -0
- package/dist/transports/mcp/instructions/tools/publish-app.js.map +1 -0
- package/dist/transports/mcp/instructions/tools/start-app.d.ts +2 -0
- package/dist/transports/mcp/instructions/tools/start-app.js +22 -0
- package/dist/transports/mcp/instructions/tools/start-app.js.map +1 -0
- package/dist/transports/mcp/instructions/tools/upload-artifact.d.ts +2 -0
- package/dist/transports/mcp/instructions/tools/upload-artifact.js +13 -0
- package/dist/transports/mcp/instructions/tools/upload-artifact.js.map +1 -0
- package/dist/transports/mcp/mcp-app-brand-css.d.ts +1 -0
- package/dist/transports/mcp/mcp-app-brand-css.js +180 -0
- package/dist/transports/mcp/mcp-app-brand-css.js.map +1 -0
- package/dist/transports/mcp/mount.d.ts +22 -0
- package/dist/transports/mcp/mount.js +1040 -0
- package/dist/transports/mcp/mount.js.map +1 -0
- package/dist/transports/mcp/native-browser-presence.d.ts +45 -0
- package/dist/transports/mcp/native-browser-presence.js +158 -0
- package/dist/transports/mcp/native-browser-presence.js.map +1 -0
- package/dist/transports/mcp/plan-approval.d.ts +38 -0
- package/dist/transports/mcp/plan-approval.js +175 -0
- package/dist/transports/mcp/plan-approval.js.map +1 -0
- package/dist/transports/mcp/progress-notifier.d.ts +39 -0
- package/dist/transports/mcp/progress-notifier.js +52 -0
- package/dist/transports/mcp/progress-notifier.js.map +1 -0
- package/dist/transports/mcp/session-directory.d.ts +7 -0
- package/dist/transports/mcp/session-directory.js +18 -0
- package/dist/transports/mcp/session-directory.js.map +1 -0
- package/dist/transports/mcp/tool-names.d.ts +2 -0
- package/dist/transports/mcp/tool-names.js +2 -0
- package/dist/transports/mcp/tool-names.js.map +1 -0
- package/package.json +78 -0
- package/skills/superblocks-build/SKILL.md +59 -0
- package/skills/superblocks-import/SKILL.md +88 -0
package/dist/deps.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deps.js","sourceRoot":"","sources":["../src/deps.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import type { GatewayFault } from "../process/fault-barrier.js";
|
|
2
|
+
/**
|
|
3
|
+
* What the gateway's own request path is doing.
|
|
4
|
+
*
|
|
5
|
+
* `unmounted` is not a degenerate case: `createApp` builds the HTTP surface
|
|
6
|
+
* before the MCP transport is mounted onto it, and a gateway in that window has
|
|
7
|
+
* no way to serve a tool call. Reporting it as healthy is the ENG-5809 bug in
|
|
8
|
+
* miniature.
|
|
9
|
+
*/
|
|
10
|
+
export type DispatchState = "faulted" | "ok" | "unmounted" | "wedged";
|
|
11
|
+
export type UpstreamState = "reachable" | "unknown" | "unreachable";
|
|
12
|
+
export type ReadinessVerdict = {
|
|
13
|
+
dispatch: DispatchState;
|
|
14
|
+
/** Human-readable cause, present only when something is wrong. */
|
|
15
|
+
detail?: string;
|
|
16
|
+
/** Whether callers should be routed here. */
|
|
17
|
+
ready: boolean;
|
|
18
|
+
upstream: UpstreamState;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Proves the gateway can still take a request all the way through its own
|
|
22
|
+
* dispatch path. Resolving means it can; throwing or hanging means it cannot.
|
|
23
|
+
*/
|
|
24
|
+
export type DispatchProbe = () => Promise<void>;
|
|
25
|
+
export type UpstreamProbe = () => Promise<UpstreamState>;
|
|
26
|
+
export type GatewayReadinessOptions = {
|
|
27
|
+
cacheMs?: number;
|
|
28
|
+
dispatchDeadlineMs?: number;
|
|
29
|
+
/** Where the cause behind a bounded `detail` goes. */
|
|
30
|
+
log?: (message: string, cause: unknown) => void;
|
|
31
|
+
now?: () => number;
|
|
32
|
+
/** The Superblocks origin this gateway fronts, named in the verdict. */
|
|
33
|
+
serverUrl: string;
|
|
34
|
+
upstreamProbe?: UpstreamProbe;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Probes an origin for reachability rather than for authorization.
|
|
38
|
+
*
|
|
39
|
+
* Any HTTP status is a pass, including 401: a server that refuses an
|
|
40
|
+
* unauthenticated probe has still proved it is answering, which is the only
|
|
41
|
+
* question a health check can ask without a caller's credential. Only a
|
|
42
|
+
* transport failure or a timeout means unreachable.
|
|
43
|
+
*/
|
|
44
|
+
export declare function createUpstreamProbe(input: {
|
|
45
|
+
fetchImpl?: typeof fetch;
|
|
46
|
+
serverUrl: string;
|
|
47
|
+
timeoutMs?: number;
|
|
48
|
+
}): UpstreamProbe;
|
|
49
|
+
/**
|
|
50
|
+
* The gateway's honest answer to "are you working".
|
|
51
|
+
*
|
|
52
|
+
* Two questions, deliberately kept apart, because during the ENG-5809 outage
|
|
53
|
+
* nothing on the wire told the difference:
|
|
54
|
+
*
|
|
55
|
+
* - {@link liveness} asks whether *this process* can still serve. It fails on a
|
|
56
|
+
* broken or wedged dispatch path and on a fault it decided not to survive.
|
|
57
|
+
* An unreachable platform never fails it, because restarting this gateway
|
|
58
|
+
* cannot fix the platform, and a supervisor acting on liveness would restart
|
|
59
|
+
* a working process every few seconds until the platform came back.
|
|
60
|
+
* - {@link readiness} asks whether tool calls should be routed here, so an
|
|
61
|
+
* unreachable platform does fail it: nothing can be served through it.
|
|
62
|
+
*
|
|
63
|
+
* Both report `dispatch` and `upstream` as separate fields either way, so a
|
|
64
|
+
* caller reads which side to act on instead of inferring it from a bare "ok".
|
|
65
|
+
*/
|
|
66
|
+
export declare class GatewayReadiness {
|
|
67
|
+
private cached;
|
|
68
|
+
private dispatchProbe;
|
|
69
|
+
private fatal;
|
|
70
|
+
private inFlight;
|
|
71
|
+
private readonly options;
|
|
72
|
+
constructor(options: GatewayReadinessOptions);
|
|
73
|
+
/**
|
|
74
|
+
* Hands over the real dispatch path, once there is one. Called by the MCP
|
|
75
|
+
* transport as it mounts; until then the gateway reports `unmounted`.
|
|
76
|
+
*/
|
|
77
|
+
useDispatchProbe(probe: DispatchProbe): void;
|
|
78
|
+
/**
|
|
79
|
+
* Records what the process-level barrier caught.
|
|
80
|
+
*
|
|
81
|
+
* Only a fatal fault changes the verdict. A rejection the barrier absorbed
|
|
82
|
+
* cost one caller their call; failing liveness for it would hand a working
|
|
83
|
+
* process to a restart loop, which is the outage the barrier prevents.
|
|
84
|
+
*/
|
|
85
|
+
recordFault(fault: GatewayFault): void;
|
|
86
|
+
liveness(): Promise<ReadinessVerdict>;
|
|
87
|
+
readiness(): Promise<ReadinessVerdict>;
|
|
88
|
+
private verdict;
|
|
89
|
+
/**
|
|
90
|
+
* One probe run per cache window, shared by however many pollers arrive
|
|
91
|
+
* while it is running. Eight concurrent agents polling health must not stack
|
|
92
|
+
* eight MCP servers onto a gateway that is already struggling.
|
|
93
|
+
*/
|
|
94
|
+
private probe;
|
|
95
|
+
private runProbe;
|
|
96
|
+
private probeDispatch;
|
|
97
|
+
private log;
|
|
98
|
+
private probeUpstream;
|
|
99
|
+
}
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
import { recordReadinessVerdict } from "../telemetry/metrics.js";
|
|
2
|
+
/** How long the dispatch path gets to answer before it counts as wedged. */
|
|
3
|
+
const DEFAULT_DISPATCH_DEADLINE_MS = 5_000;
|
|
4
|
+
/** How long the upstream origin gets to answer before it counts as down. */
|
|
5
|
+
const DEFAULT_UPSTREAM_DEADLINE_MS = 3_000;
|
|
6
|
+
/** How long one probe run answers for. Health endpoints get polled hard. */
|
|
7
|
+
const DEFAULT_CACHE_MS = 2_000;
|
|
8
|
+
async function withDeadline(work, deadlineMs, onDeadline) {
|
|
9
|
+
let timer;
|
|
10
|
+
try {
|
|
11
|
+
return await Promise.race([
|
|
12
|
+
work,
|
|
13
|
+
new Promise((resolve) => {
|
|
14
|
+
timer = setTimeout(() => resolve(onDeadline()), deadlineMs);
|
|
15
|
+
timer.unref?.();
|
|
16
|
+
}),
|
|
17
|
+
]);
|
|
18
|
+
}
|
|
19
|
+
finally {
|
|
20
|
+
if (timer) {
|
|
21
|
+
clearTimeout(timer);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Probes an origin for reachability rather than for authorization.
|
|
27
|
+
*
|
|
28
|
+
* Any HTTP status is a pass, including 401: a server that refuses an
|
|
29
|
+
* unauthenticated probe has still proved it is answering, which is the only
|
|
30
|
+
* question a health check can ask without a caller's credential. Only a
|
|
31
|
+
* transport failure or a timeout means unreachable.
|
|
32
|
+
*/
|
|
33
|
+
export function createUpstreamProbe(input) {
|
|
34
|
+
const fetchImpl = input.fetchImpl ?? fetch;
|
|
35
|
+
return async () => {
|
|
36
|
+
try {
|
|
37
|
+
await fetchImpl(input.serverUrl, {
|
|
38
|
+
method: "GET",
|
|
39
|
+
signal: AbortSignal.timeout(input.timeoutMs ?? DEFAULT_UPSTREAM_DEADLINE_MS),
|
|
40
|
+
});
|
|
41
|
+
return "reachable";
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
return "unreachable";
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* The gateway's honest answer to "are you working".
|
|
50
|
+
*
|
|
51
|
+
* Two questions, deliberately kept apart, because during the ENG-5809 outage
|
|
52
|
+
* nothing on the wire told the difference:
|
|
53
|
+
*
|
|
54
|
+
* - {@link liveness} asks whether *this process* can still serve. It fails on a
|
|
55
|
+
* broken or wedged dispatch path and on a fault it decided not to survive.
|
|
56
|
+
* An unreachable platform never fails it, because restarting this gateway
|
|
57
|
+
* cannot fix the platform, and a supervisor acting on liveness would restart
|
|
58
|
+
* a working process every few seconds until the platform came back.
|
|
59
|
+
* - {@link readiness} asks whether tool calls should be routed here, so an
|
|
60
|
+
* unreachable platform does fail it: nothing can be served through it.
|
|
61
|
+
*
|
|
62
|
+
* Both report `dispatch` and `upstream` as separate fields either way, so a
|
|
63
|
+
* caller reads which side to act on instead of inferring it from a bare "ok".
|
|
64
|
+
*/
|
|
65
|
+
export class GatewayReadiness {
|
|
66
|
+
cached;
|
|
67
|
+
dispatchProbe;
|
|
68
|
+
fatal;
|
|
69
|
+
inFlight;
|
|
70
|
+
options;
|
|
71
|
+
constructor(options) {
|
|
72
|
+
this.options = options;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Hands over the real dispatch path, once there is one. Called by the MCP
|
|
76
|
+
* transport as it mounts; until then the gateway reports `unmounted`.
|
|
77
|
+
*/
|
|
78
|
+
useDispatchProbe(probe) {
|
|
79
|
+
this.dispatchProbe = probe;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Records what the process-level barrier caught.
|
|
83
|
+
*
|
|
84
|
+
* Only a fatal fault changes the verdict. A rejection the barrier absorbed
|
|
85
|
+
* cost one caller their call; failing liveness for it would hand a working
|
|
86
|
+
* process to a restart loop, which is the outage the barrier prevents.
|
|
87
|
+
*/
|
|
88
|
+
recordFault(fault) {
|
|
89
|
+
if (fault.fatal) {
|
|
90
|
+
this.fatal = fault;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
async liveness() {
|
|
94
|
+
return this.verdict("liveness");
|
|
95
|
+
}
|
|
96
|
+
async readiness() {
|
|
97
|
+
return this.verdict("readiness");
|
|
98
|
+
}
|
|
99
|
+
async verdict(probe) {
|
|
100
|
+
const probed = await this.probe();
|
|
101
|
+
const upstreamCounts = probe === "readiness";
|
|
102
|
+
const upstreamDown = upstreamCounts && probed.upstream === "unreachable";
|
|
103
|
+
const verdict = {
|
|
104
|
+
dispatch: probed.dispatch,
|
|
105
|
+
ready: probed.dispatch === "ok" && !upstreamDown,
|
|
106
|
+
upstream: probed.upstream,
|
|
107
|
+
...detailOf(probed, upstreamDown, this.options.serverUrl),
|
|
108
|
+
};
|
|
109
|
+
recordReadinessVerdict({
|
|
110
|
+
dispatch: verdict.dispatch,
|
|
111
|
+
probe,
|
|
112
|
+
ready: verdict.ready,
|
|
113
|
+
upstream: verdict.upstream,
|
|
114
|
+
});
|
|
115
|
+
return verdict;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* One probe run per cache window, shared by however many pollers arrive
|
|
119
|
+
* while it is running. Eight concurrent agents polling health must not stack
|
|
120
|
+
* eight MCP servers onto a gateway that is already struggling.
|
|
121
|
+
*/
|
|
122
|
+
async probe() {
|
|
123
|
+
const now = (this.options.now ?? Date.now)();
|
|
124
|
+
const cacheMs = this.options.cacheMs ?? DEFAULT_CACHE_MS;
|
|
125
|
+
if (this.cached && now - this.cached.at < cacheMs) {
|
|
126
|
+
return this.cached;
|
|
127
|
+
}
|
|
128
|
+
this.inFlight ??= this.runProbe(now).finally(() => {
|
|
129
|
+
this.inFlight = undefined;
|
|
130
|
+
});
|
|
131
|
+
return this.inFlight;
|
|
132
|
+
}
|
|
133
|
+
async runProbe(at) {
|
|
134
|
+
const [dispatch, upstream] = await Promise.all([
|
|
135
|
+
this.probeDispatch(),
|
|
136
|
+
this.probeUpstream(),
|
|
137
|
+
]);
|
|
138
|
+
const probed = { at, upstream, ...dispatch };
|
|
139
|
+
this.cached = probed;
|
|
140
|
+
return probed;
|
|
141
|
+
}
|
|
142
|
+
async probeDispatch() {
|
|
143
|
+
// A fault the process did not survive outranks anything a probe could say:
|
|
144
|
+
// the heap it left behind is what the probe would be running on.
|
|
145
|
+
if (this.fatal) {
|
|
146
|
+
// The kind and not the message. Both probes are unauthenticated, and an
|
|
147
|
+
// exception message can carry an internal route, a query, or an id that
|
|
148
|
+
// a caller cannot act on anyway. The message went to the log when the
|
|
149
|
+
// barrier caught it.
|
|
150
|
+
return {
|
|
151
|
+
dispatch: "faulted",
|
|
152
|
+
dispatchDetail: `The gateway recorded a fatal ${this.fatal.kind} and is waiting to be restarted.`,
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
const probe = this.dispatchProbe;
|
|
156
|
+
if (!probe) {
|
|
157
|
+
return {
|
|
158
|
+
dispatch: "unmounted",
|
|
159
|
+
dispatchDetail: "No MCP transport is mounted on this gateway yet.",
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
const deadlineMs = this.options.dispatchDeadlineMs ?? DEFAULT_DISPATCH_DEADLINE_MS;
|
|
163
|
+
try {
|
|
164
|
+
return await withDeadline(probe().then(() => ({ dispatch: "ok" })), deadlineMs, () => ({
|
|
165
|
+
dispatch: "wedged",
|
|
166
|
+
dispatchDetail: `The gateway's own dispatch path did not answer within ${deadlineMs}ms.`,
|
|
167
|
+
}));
|
|
168
|
+
}
|
|
169
|
+
catch (error) {
|
|
170
|
+
// Same reason as the fatal branch: the cause is for the operator reading
|
|
171
|
+
// logs, not for an unauthenticated caller reading a health endpoint.
|
|
172
|
+
this.log("gateway dispatch probe failed", error);
|
|
173
|
+
return {
|
|
174
|
+
dispatch: "wedged",
|
|
175
|
+
dispatchDetail: "The gateway's own dispatch path failed.",
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
log(message, cause) {
|
|
180
|
+
(this.options.log ?? ((text, err) => console.error(text, err)))(message, cause);
|
|
181
|
+
}
|
|
182
|
+
async probeUpstream() {
|
|
183
|
+
const probe = this.options.upstreamProbe;
|
|
184
|
+
if (!probe) {
|
|
185
|
+
return "unknown";
|
|
186
|
+
}
|
|
187
|
+
try {
|
|
188
|
+
return await probe();
|
|
189
|
+
}
|
|
190
|
+
catch {
|
|
191
|
+
return "unreachable";
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
function detailOf(probed, upstreamDown, serverUrl) {
|
|
196
|
+
const reasons = [
|
|
197
|
+
probed.dispatchDetail,
|
|
198
|
+
upstreamDown ? `${serverUrl} did not answer.` : undefined,
|
|
199
|
+
].filter((reason) => reason !== undefined);
|
|
200
|
+
return reasons.length > 0 ? { detail: reasons.join(" ") } : {};
|
|
201
|
+
}
|
|
202
|
+
//# sourceMappingURL=readiness.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"readiness.js","sourceRoot":"","sources":["../../src/health/readiness.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AAEjE,4EAA4E;AAC5E,MAAM,4BAA4B,GAAG,KAAK,CAAC;AAC3C,4EAA4E;AAC5E,MAAM,4BAA4B,GAAG,KAAK,CAAC;AAC3C,4EAA4E;AAC5E,MAAM,gBAAgB,GAAG,KAAK,CAAC;AAiD/B,KAAK,UAAU,YAAY,CACzB,IAAgB,EAChB,UAAkB,EAClB,UAAmB;IAEnB,IAAI,KAAgD,CAAC;IACrD,IAAI,CAAC;QACH,OAAO,MAAM,OAAO,CAAC,IAAI,CAAC;YACxB,IAAI;YACJ,IAAI,OAAO,CAAI,CAAC,OAAO,EAAE,EAAE;gBACzB,KAAK,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,UAAU,EAAE,CAAC,EAAE,UAAU,CAAC,CAAC;gBAC5D,KAAK,CAAC,KAAK,EAAE,EAAE,CAAC;YAClB,CAAC,CAAC;SACH,CAAC,CAAC;IACL,CAAC;YAAS,CAAC;QACT,IAAI,KAAK,EAAE,CAAC;Y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
export { formatCaptureModeSummary, formatCaptureModeUserSummary, resolveCaptureMode, } from "./capture/mode.js";
|
|
4
|
+
export { editApp, IMPORT_ZIP_MAX_BYTES, previewApp, publishApp, startApp, uploadArtifact, } from "./capabilities/lifecycle.js";
|
|
5
|
+
export { GATEWAY_FAULT_EXIT_CODE } from "./process/fault-barrier.js";
|
|
6
|
+
export { startStdioGateway } from "./start.js";
|
|
7
|
+
export type { StartGatewayOptions, StartedGateway } from "./start.js";
|
|
8
|
+
export { ensurePlaywrightChromium, playwrightChromiumPresent, } from "./playwright/ensure-chromium.js";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { loadConfig } from "./config.js";
|
|
2
|
+
export { scanHostBrowserMcp } from "./capture/host-mcp-scan.js";
|
|
3
|
+
export { formatCaptureModeSummary, formatCaptureModeUserSummary, resolveCaptureMode, } from "./capture/mode.js";
|
|
4
|
+
export { editApp, IMPORT_ZIP_MAX_BYTES, previewApp, publishApp, startApp, uploadArtifact, } from "./capabilities/lifecycle.js";
|
|
5
|
+
export { GATEWAY_FAULT_EXIT_CODE } from "./process/fault-barrier.js";
|
|
6
|
+
export { startStdioGateway } from "./start.js";
|
|
7
|
+
export { ensurePlaywrightChromium, playwrightChromiumPresent, } from "./playwright/ensure-chromium.js";
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAChE,OAAO,EACL,wBAAwB,EACxB,4BAA4B,EAC5B,kBAAkB,GACnB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,OAAO,EACP,oBAAoB,EACpB,UAAU,EACV,UAAU,EACV,QAAQ,EACR,cAAc,GACf,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,uBAAuB,EAAE,MAAM,4BAA4B,CAAC;AACrE,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAE/C,OAAO,EACL,wBAAwB,EACxB,yBAAyB,GAC1B,MAAM,iCAAiC,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether Clark's tool surface can use this plugin id.
|
|
3
|
+
*
|
|
4
|
+
* Fullstack apps (what Gateway creates) are SDK-enabled, so ad-hoc REST/GraphQL
|
|
5
|
+
* variants are excluded; preconfigured `restapiintegration` /
|
|
6
|
+
* `graphqlintegration` stay.
|
|
7
|
+
*/
|
|
8
|
+
export declare function integrationIsToolSupported(pluginId: string, sdkApiEnabled?: boolean): boolean;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Plugin ids Clark cannot use as tools. Mirrored from the UI's
|
|
3
|
+
* `integration-filters` so this package does not depend on `packages/ui`.
|
|
4
|
+
*/
|
|
5
|
+
const UNSUPPORTED_INTEGRATION_TYPES = new Set([
|
|
6
|
+
"confluentkafka",
|
|
7
|
+
"email",
|
|
8
|
+
"googlesheets",
|
|
9
|
+
"kafka",
|
|
10
|
+
"kinesis",
|
|
11
|
+
"openai",
|
|
12
|
+
"redis",
|
|
13
|
+
"redpanda",
|
|
14
|
+
"superblocks-ocr",
|
|
15
|
+
"workflow",
|
|
16
|
+
]);
|
|
17
|
+
/** Ad-hoc types filtered out for SDK-enabled (fullstack) apps. */
|
|
18
|
+
const AD_HOC_INTEGRATION_TYPES = new Set([
|
|
19
|
+
"graphql",
|
|
20
|
+
"javascript",
|
|
21
|
+
"python",
|
|
22
|
+
"restapi",
|
|
23
|
+
]);
|
|
24
|
+
/**
|
|
25
|
+
* Whether Clark's tool surface can use this plugin id.
|
|
26
|
+
*
|
|
27
|
+
* Fullstack apps (what Gateway creates) are SDK-enabled, so ad-hoc REST/GraphQL
|
|
28
|
+
* variants are excluded; preconfigured `restapiintegration` /
|
|
29
|
+
* `graphqlintegration` stay.
|
|
30
|
+
*/
|
|
31
|
+
export function integrationIsToolSupported(pluginId, sdkApiEnabled = true) {
|
|
32
|
+
if (UNSUPPORTED_INTEGRATION_TYPES.has(pluginId)) {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
if (sdkApiEnabled && AD_HOC_INTEGRATION_TYPES.has(pluginId)) {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
return true;
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=filters.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"filters.js","sourceRoot":"","sources":["../../src/integrations/filters.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,6BAA6B,GAAG,IAAI,GAAG,CAAC;IAC5C,gBAAgB;IAChB,OAAO;IACP,cAAc;IACd,OAAO;IACP,SAAS;IACT,QAAQ;IACR,OAAO;IACP,UAAU;IACV,iBAAiB;IACjB,UAAU;CACX,CAAC,CAAC;AAEH,kEAAkE;AAClE,MAAM,wBAAwB,GAAG,IAAI,GAAG,CAAC;IACvC,SAAS;IACT,YAAY;IACZ,QAAQ;IACR,SAAS;CACV,CAAC,CAAC;AAEH;;;;;;GAMG;AACH,MAAM,UAAU,0BAA0B,CACxC,QAAgB,EAChB,aAAa,GAAG,IAAI;IAEpB,IAAI,6BAA6B,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC;QAChD,OAAO,KAAK,CAAC;IACf,CAAC;IACD,IAAI,aAAa,IAAI,wBAAwB,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC5D,OAAO,KAAK,CAAC;IACf,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { PromptContextIntegration } from "@superblocksteam/library-shared/types";
|
|
2
|
+
/** Minimal fields needed from `GET /api/v1/integrations/superset`. */
|
|
3
|
+
export type SupersetIntegrationRow = {
|
|
4
|
+
configurations?: Array<{
|
|
5
|
+
configuration?: {
|
|
6
|
+
openApiSpecRef?: string;
|
|
7
|
+
};
|
|
8
|
+
isDefault?: boolean;
|
|
9
|
+
}>;
|
|
10
|
+
id: string;
|
|
11
|
+
managedBy?: string | null;
|
|
12
|
+
name: string;
|
|
13
|
+
permissions?: string[];
|
|
14
|
+
pluginId: string;
|
|
15
|
+
readOnly?: boolean;
|
|
16
|
+
};
|
|
17
|
+
export declare function hasBuildPermission(row: SupersetIntegrationRow): boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Maps a superset row to the shape Clark expects on `aiGetIntegrations`
|
|
20
|
+
* (no metadata).
|
|
21
|
+
*/
|
|
22
|
+
export declare function toPromptContextIntegrationSummary(row: SupersetIntegrationRow): Omit<PromptContextIntegration, "metadata">;
|
|
23
|
+
/**
|
|
24
|
+
* BUILD-filtered, tool-supported integrations for Clark's discovery list.
|
|
25
|
+
*/
|
|
26
|
+
export declare function listIntegrationsForClark(rows: SupersetIntegrationRow[], sdkApiEnabled?: boolean): Omit<PromptContextIntegration, "metadata">[];
|
|
27
|
+
export declare function toPromptContextIntegration(row: SupersetIntegrationRow, metadata?: Record<string, unknown>): PromptContextIntegration;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { integrationIsToolSupported } from "./filters.js";
|
|
2
|
+
export function hasBuildPermission(row) {
|
|
3
|
+
if (row.permissions && row.permissions.length > 0) {
|
|
4
|
+
return row.permissions.includes("build");
|
|
5
|
+
}
|
|
6
|
+
// Legacy rows without RBAC annotations: BUILD means not read-only.
|
|
7
|
+
return !row.readOnly;
|
|
8
|
+
}
|
|
9
|
+
function openApiSpecRef(row) {
|
|
10
|
+
const fromConfig = row.configurations?.find((c) => c.isDefault)?.configuration
|
|
11
|
+
?.openApiSpecRef;
|
|
12
|
+
return fromConfig || undefined;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Maps a superset row to the shape Clark expects on `aiGetIntegrations`
|
|
16
|
+
* (no metadata).
|
|
17
|
+
*/
|
|
18
|
+
export function toPromptContextIntegrationSummary(row) {
|
|
19
|
+
return {
|
|
20
|
+
displayName: row.name,
|
|
21
|
+
id: row.id,
|
|
22
|
+
...(row.managedBy != null ? { managedBy: row.managedBy } : {}),
|
|
23
|
+
name: row.name,
|
|
24
|
+
...(openApiSpecRef(row) ? { openApiSpecRef: openApiSpecRef(row) } : {}),
|
|
25
|
+
type: row.pluginId,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* BUILD-filtered, tool-supported integrations for Clark's discovery list.
|
|
30
|
+
*/
|
|
31
|
+
export function listIntegrationsForClark(rows, sdkApiEnabled = true) {
|
|
32
|
+
return rows
|
|
33
|
+
.filter(hasBuildPermission)
|
|
34
|
+
.filter((row) => integrationIsToolSupported(row.pluginId, sdkApiEnabled))
|
|
35
|
+
.map(toPromptContextIntegrationSummary);
|
|
36
|
+
}
|
|
37
|
+
export function toPromptContextIntegration(row, metadata = {}) {
|
|
38
|
+
return {
|
|
39
|
+
...toPromptContextIntegrationSummary(row),
|
|
40
|
+
metadata,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=map.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"map.js","sourceRoot":"","sources":["../../src/integrations/map.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,0BAA0B,EAAE,MAAM,cAAc,CAAC;AAgB1D,MAAM,UAAU,kBAAkB,CAAC,GAA2B;IAC5D,IAAI,GAAG,CAAC,WAAW,IAAI,GAAG,CAAC,WAAW,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAClD,OAAO,GAAG,CAAC,WAAW,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;IAC3C,CAAC;IACD,mEAAmE;IACnE,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC;AACvB,CAAC;AAED,SAAS,cAAc,CAAC,GAA2B;IACjD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
* orchestrator. Local orgs almost never have a profile literally named
|
|
4
|
+
* `default` — they use `dev` / `staging` / `production` — and a wrong key
|
|
5
|
+
* surfaces as orchestrator "Invalid profile specified" / HTTP 500.
|
|
6
|
+
*/
|
|
7
|
+
export type OrgProfileRow = {
|
|
8
|
+
allowedInEditor?: boolean;
|
|
9
|
+
key: string;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Resolves an editor profile key from the org's profile list.
|
|
13
|
+
*
|
|
14
|
+
* - Honors `preferred` when it exists on the org (and is not the legacy
|
|
15
|
+
* placeholder `default`).
|
|
16
|
+
* - Otherwise prefers staging → dev → production, then the first listed key.
|
|
17
|
+
* - When the org list is unavailable, falls back to `preferred` or `staging`.
|
|
18
|
+
*/
|
|
19
|
+
export declare function pickEditorProfileKey(preferred: string | undefined, profiles: OrgProfileRow[]): string;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Picks which Superblocks integration profile key Gateway should send to the
|
|
3
|
+
* orchestrator. Local orgs almost never have a profile literally named
|
|
4
|
+
* `default` — they use `dev` / `staging` / `production` — and a wrong key
|
|
5
|
+
* surfaces as orchestrator "Invalid profile specified" / HTTP 500.
|
|
6
|
+
*/
|
|
7
|
+
const AUTO_PREFERRED_KEYS = ["staging", "dev", "production"];
|
|
8
|
+
/**
|
|
9
|
+
* Resolves an editor profile key from the org's profile list.
|
|
10
|
+
*
|
|
11
|
+
* - Honors `preferred` when it exists on the org (and is not the legacy
|
|
12
|
+
* placeholder `default`).
|
|
13
|
+
* - Otherwise prefers staging → dev → production, then the first listed key.
|
|
14
|
+
* - When the org list is unavailable, falls back to `preferred` or `staging`.
|
|
15
|
+
*/
|
|
16
|
+
export function pickEditorProfileKey(preferred, profiles) {
|
|
17
|
+
const configured = preferred?.trim() ?? "";
|
|
18
|
+
const isAuto = !configured || configured.toLowerCase() === "default";
|
|
19
|
+
const keys = profiles
|
|
20
|
+
.map((profile) => profile.key?.trim())
|
|
21
|
+
.filter((key) => Boolean(key));
|
|
22
|
+
if (!isAuto && keys.includes(configured)) {
|
|
23
|
+
return configured;
|
|
24
|
+
}
|
|
25
|
+
if (keys.length === 0) {
|
|
26
|
+
return isAuto ? "staging" : configured;
|
|
27
|
+
}
|
|
28
|
+
for (const candidate of AUTO_PREFERRED_KEYS) {
|
|
29
|
+
if (keys.includes(candidate)) {
|
|
30
|
+
return candidate;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return keys[0] ?? "staging";
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=profile-key.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"profile-key.js","sourceRoot":"","sources":["../../src/integrations/profile-key.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,mBAAmB,GAAG,CAAC,SAAS,EAAE,KAAK,EAAE,YAAY,CAAU,CAAC;AAOtE;;;;;;;GAOG;AACH,MAAM,UAAU,oBAAoB,CAClC,SAA6B,EAC7B,QAAyB;IAEzB,MAAM,UAAU,GAAG,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;IAC3C,MAAM,MAAM,GAAG,CAAC,UAAU,IAAI,UAAU,CAAC,WAAW,EAAE,KAAK,SAAS,CAAC;IACrE,MAAM,IAAI,GAAG,QAAQ;SAClB,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE,IAAI,EAAE,CAAC;SACrC,MAAM,CAAC,CAAC,GAAG,EAAiB,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC;IAEhD,IAAI,CAAC,MAAM,IAAI,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE,CAAC;QACzC,OAAO,UAAU,CAAC;IACpB,CAAC;IAED,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACtB,OAAO,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,UAAU,CAAC;IACzC,CAAC;IAED,KAAK,MAAM,SAAS,IAAI,mBAAmB,EAAE,CAAC;QAC5C,IAAI,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC;YAC7B,OAAO,SAAS,CAAC;QACnB,CAAC;IACH,CAAC;IAED,OAAO,IAAI,CAAC,CAAC,CAAC,IAAI,SAAS,CAAC;AAC9B,CAAC"}
|