@superblocksteam/gateway 2.0.155-next.0
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 +170 -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/import-prompt.d.ts +11 -0
- package/dist/capabilities/import-prompt.js +96 -0
- package/dist/capabilities/import-prompt.js.map +1 -0
- package/dist/capabilities/lifecycle.d.ts +73 -0
- package/dist/capabilities/lifecycle.js +2531 -0
- package/dist/capabilities/lifecycle.js.map +1 -0
- package/dist/capabilities/persisted-progress.d.ts +46 -0
- package/dist/capabilities/persisted-progress.js +246 -0
- package/dist/capabilities/persisted-progress.js.map +1 -0
- package/dist/capabilities/types.d.ts +446 -0
- package/dist/capabilities/types.js +47 -0
- package/dist/capabilities/types.js.map +1 -0
- package/dist/capture/browser-contract.d.ts +36 -0
- package/dist/capture/browser-contract.js +24 -0
- package/dist/capture/browser-contract.js.map +1 -0
- package/dist/capture/browser-instructions.d.ts +9 -0
- package/dist/capture/browser-instructions.js +17 -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 +34 -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 +22 -0
- package/dist/capture/mode.js +45 -0
- package/dist/capture/mode.js.map +1 -0
- package/dist/config.d.ts +141 -0
- package/dist/config.js +109 -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 +36 -0
- package/dist/deps.js +2 -0
- package/dist/deps.js.map +1 -0
- package/dist/events/cursor.d.ts +43 -0
- package/dist/events/cursor.js +78 -0
- package/dist/events/cursor.js.map +1 -0
- package/dist/events/memory-event-store.d.ts +34 -0
- package/dist/events/memory-event-store.js +110 -0
- package/dist/events/memory-event-store.js.map +1 -0
- package/dist/events/merge.d.ts +23 -0
- package/dist/events/merge.js +97 -0
- package/dist/events/merge.js.map +1 -0
- package/dist/events/normalized-collector.d.ts +62 -0
- package/dist/events/normalized-collector.js +156 -0
- package/dist/events/normalized-collector.js.map +1 -0
- package/dist/events/schema.d.ts +9 -0
- package/dist/events/schema.js +93 -0
- package/dist/events/schema.js.map +1 -0
- package/dist/events/snapshot.d.ts +32 -0
- package/dist/events/snapshot.js +57 -0
- package/dist/events/snapshot.js.map +1 -0
- package/dist/events/stream-key.d.ts +2 -0
- package/dist/events/stream-key.js +31 -0
- package/dist/events/stream-key.js.map +1 -0
- package/dist/events/types.d.ts +179 -0
- package/dist/events/types.js +66 -0
- package/dist/events/types.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 +10 -0
- package/dist/index.js +10 -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 +26 -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/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 +26 -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 +52 -0
- package/dist/preview/capture-screenshot.js +158 -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 +128 -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/resume/memory-progress-store.d.ts +39 -0
- package/dist/resume/memory-progress-store.js +82 -0
- package/dist/resume/memory-progress-store.js.map +1 -0
- package/dist/resume/memory-recent-app-store.d.ts +14 -0
- package/dist/resume/memory-recent-app-store.js +27 -0
- package/dist/resume/memory-recent-app-store.js.map +1 -0
- package/dist/resume/memory-turn-store.d.ts +18 -0
- package/dist/resume/memory-turn-store.js +73 -0
- package/dist/resume/memory-turn-store.js.map +1 -0
- package/dist/resume/progress-key.d.ts +21 -0
- package/dist/resume/progress-key.js +58 -0
- package/dist/resume/progress-key.js.map +1 -0
- package/dist/resume/stores.d.ts +14 -0
- package/dist/resume/stores.js +18 -0
- package/dist/resume/stores.js.map +1 -0
- package/dist/resume/types.d.ts +124 -0
- package/dist/resume/types.js +13 -0
- package/dist/resume/types.js.map +1 -0
- package/dist/sabs/agent-facing-text.d.ts +33 -0
- package/dist/sabs/agent-facing-text.js +125 -0
- package/dist/sabs/agent-facing-text.js.map +1 -0
- package/dist/sabs/browser-context.d.ts +53 -0
- package/dist/sabs/browser-context.js +91 -0
- package/dist/sabs/browser-context.js.map +1 -0
- package/dist/sabs/editor-client-methods.d.ts +147 -0
- package/dist/sabs/editor-client-methods.js +715 -0
- package/dist/sabs/editor-client-methods.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 +351 -0
- package/dist/sabs/session-peer.js +2 -0
- package/dist/sabs/session-peer.js.map +1 -0
- package/dist/sabs/turn-collector.d.ts +152 -0
- package/dist/sabs/turn-collector.js +573 -0
- package/dist/sabs/turn-collector.js.map +1 -0
- package/dist/sabs/websocket-session-peer.d.ts +514 -0
- package/dist/sabs/websocket-session-peer.js +2487 -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 +371 -0
- package/dist/server/client.js +572 -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 +14 -0
- package/dist/start.js +75 -0
- package/dist/start.js.map +1 -0
- package/dist/telemetry/metrics.d.ts +32 -0
- package/dist/telemetry/metrics.js +57 -0
- package/dist/telemetry/metrics.js.map +1 -0
- package/dist/transports/mcp/admin-tools.d.ts +47 -0
- package/dist/transports/mcp/admin-tools.js +164 -0
- package/dist/transports/mcp/admin-tools.js.map +1 -0
- package/dist/transports/mcp/app-status-html.d.ts +15 -0
- package/dist/transports/mcp/app-status-html.js +563 -0
- package/dist/transports/mcp/app-status-html.js.map +1 -0
- package/dist/transports/mcp/decision-elicitation.d.ts +74 -0
- package/dist/transports/mcp/decision-elicitation.js +233 -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/format-tool-content.d.ts +25 -0
- package/dist/transports/mcp/format-tool-content.js +48 -0
- package/dist/transports/mcp/format-tool-content.js.map +1 -0
- package/dist/transports/mcp/mount.d.ts +9 -0
- package/dist/transports/mcp/mount.js +469 -0
- package/dist/transports/mcp/mount.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/package.json +72 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { loadConfig } from "./config.js";
|
|
2
|
+
export { scanHostBrowserMcp } from "./capture/host-mcp-scan.js";
|
|
3
|
+
export { formatCaptureModeSummary, resolveCaptureMode, } from "./capture/mode.js";
|
|
4
|
+
export { editApp, importApp, IMPORT_ZIP_MAX_BYTES, previewApp, publishApp, startApp, } 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";
|
|
9
|
+
export { MemoryRecentAppStore } from "./resume/memory-recent-app-store.js";
|
|
10
|
+
export { MemoryTurnStore } from "./resume/memory-turn-store.js";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { loadConfig } from "./config.js";
|
|
2
|
+
export { scanHostBrowserMcp } from "./capture/host-mcp-scan.js";
|
|
3
|
+
export { formatCaptureModeSummary, resolveCaptureMode, } from "./capture/mode.js";
|
|
4
|
+
export { editApp, importApp, IMPORT_ZIP_MAX_BYTES, previewApp, publishApp, startApp, } 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
|
+
export { MemoryRecentAppStore } from "./resume/memory-recent-app-store.js";
|
|
9
|
+
export { MemoryTurnStore } from "./resume/memory-turn-store.js";
|
|
10
|
+
//# 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,kBAAkB,GACnB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,OAAO,EACP,SAAS,EACT,oBAAoB,EACpB,UAAU,EACV,UAAU,EACV,QAAQ,GACT,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;AACzC,OAAO,EAAE,oBAAoB,EAAE,MAAM,qCAAqC,CAAC;AAC3E,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,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,26 @@
|
|
|
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
|
+
/**
|
|
18
|
+
* Maps a superset row to the shape Clark expects on `aiGetIntegrations`
|
|
19
|
+
* (no metadata).
|
|
20
|
+
*/
|
|
21
|
+
export declare function toPromptContextIntegrationSummary(row: SupersetIntegrationRow): Omit<PromptContextIntegration, "metadata">;
|
|
22
|
+
/**
|
|
23
|
+
* BUILD-filtered, tool-supported integrations for Clark's discovery list.
|
|
24
|
+
*/
|
|
25
|
+
export declare function listIntegrationsForClark(rows: SupersetIntegrationRow[], sdkApiEnabled?: boolean): Omit<PromptContextIntegration, "metadata">[];
|
|
26
|
+
export declare function toPromptContextIntegration(row: SupersetIntegrationRow, metadata?: Record<string, unknown>): PromptContextIntegration;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { integrationIsToolSupported } from "./filters.js";
|
|
2
|
+
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,SAAS,kBAAkB,CAAC,GAA2B;IACrD,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,MAAM,UAAU,GAAG,GAAG,CAAC,cAAc,EAAE,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,EAAE,aAAa;QAC5E,EAAE,cAAc,CAAC;IACnB,OAAO,UAAU,IAAI,SAAS,CAAC;AACjC,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,iCAAiC,CAC/C,GAA2B;IAE3B,OAAO;QACL,WAAW,EAAE,GAAG,CAAC,IAAI;QACrB,EAAE,EAAE,GAAG,CAAC,EAAE;QACV,GAAG,CAAC,GAAG,CAAC,SAAS,IAAI,IAAI,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,GAAG,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC9D,IAAI,EAAE,GAAG,CAAC,IAAI;QACd,GAAG,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,cAAc,EAAE,cAAc,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACvE,IAAI,EAAE,GAAG,CAAC,QAAQ;KACnB,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,wBAAwB,CACtC,IAA8B,EAC9B,aAAa,GAAG,IAAI;IAEpB,OAAO,IAAI;SACR,MAAM,CAAC,kBAAkB,CAAC;SAC1B,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,0BAA0B,CAAC,GAAG,CAAC,QAAQ,EAAE,aAAa,CAAC,CAAC;SACxE,GAAG,CAAC,iCAAiC,CAAC,CAAC;AAC5C,CAAC;AAED,MAAM,UAAU,0BAA0B,CACxC,GAA2B,EAC3B,WAAoC,EAAE;IAEtC,OAAO;QACL,GAAG,iCAAiC,CAAC,GAAG,CAAC;QACzC,QAAQ;KACT,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
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
|
+
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"}
|
package/dist/main.d.ts
ADDED
package/dist/main.js
ADDED
package/dist/main.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"main.js","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":";AAEA,OAAO,CAAC,KAAK,CACX,gGAAgG,CACjG,CAAC;AACF,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Thin HTTP client for the Superblocks orchestrator / agent used by Gateway
|
|
3
|
+
* when Clark asks the editor peer to run APIs or load integration metadata.
|
|
4
|
+
*
|
|
5
|
+
* The base URL is discovered per session from Server `/users/me` agents
|
|
6
|
+
* (same filters as the browser), not operator-picked env. Scoped JWTs travel
|
|
7
|
+
* in `x-superblocks-authorization`, matching the editor's execute path.
|
|
8
|
+
*/
|
|
9
|
+
export declare class OrchestratorHttpError extends Error {
|
|
10
|
+
readonly status: number;
|
|
11
|
+
constructor(message: string, status: number);
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Credential identifying who is asking, sent as `Authorization`.
|
|
15
|
+
*
|
|
16
|
+
* The orchestrator forwards this header verbatim when it fetches the app's
|
|
17
|
+
* code bundle from the Superblocks server, and that route authenticates it in
|
|
18
|
+
* its own right: a Superblocks JWT presented there is checked against
|
|
19
|
+
* `apps:view`, which a live-edit session's `apps:update` token does not carry.
|
|
20
|
+
* Sending the API key instead mirrors the browser editor, which puts its user
|
|
21
|
+
* session token here and keeps the scoped JWT to
|
|
22
|
+
* `x-superblocks-authorization`.
|
|
23
|
+
*/
|
|
24
|
+
type RequesterCredential = {
|
|
25
|
+
apiKey?: string;
|
|
26
|
+
};
|
|
27
|
+
export type SdkApiV3ExecuteInput = RequesterCredential & {
|
|
28
|
+
applicationId: string;
|
|
29
|
+
branchName?: string;
|
|
30
|
+
entryPoint: string;
|
|
31
|
+
exportName?: string;
|
|
32
|
+
inputs: Record<string, unknown>;
|
|
33
|
+
profileKey?: string;
|
|
34
|
+
scopedToken: string;
|
|
35
|
+
};
|
|
36
|
+
export type V2ExecuteInput = RequesterCredential & {
|
|
37
|
+
body: Record<string, unknown>;
|
|
38
|
+
profileKey?: string;
|
|
39
|
+
scopedToken: string;
|
|
40
|
+
};
|
|
41
|
+
export type MetadataInput = RequesterCredential & {
|
|
42
|
+
integrationId: string;
|
|
43
|
+
profileKey: string;
|
|
44
|
+
scopedToken: string;
|
|
45
|
+
stepConfiguration?: Record<string, unknown>;
|
|
46
|
+
};
|
|
47
|
+
export type OrchestratorClient = {
|
|
48
|
+
executeSdkApiV3(input: SdkApiV3ExecuteInput): Promise<unknown>;
|
|
49
|
+
executeV2Api(input: V2ExecuteInput): Promise<unknown>;
|
|
50
|
+
getMetadata(input: MetadataInput): Promise<Record<string, unknown>>;
|
|
51
|
+
};
|
|
52
|
+
export declare class HttpOrchestratorClient implements OrchestratorClient {
|
|
53
|
+
private readonly orchestratorUrl;
|
|
54
|
+
private readonly timeoutMs;
|
|
55
|
+
constructor(orchestratorUrl: string, timeoutMs?: number);
|
|
56
|
+
private baseUrl;
|
|
57
|
+
private post;
|
|
58
|
+
executeSdkApiV3(input: SdkApiV3ExecuteInput): Promise<unknown>;
|
|
59
|
+
executeV2Api(input: V2ExecuteInput): Promise<unknown>;
|
|
60
|
+
getMetadata(input: MetadataInput): Promise<Record<string, unknown>>;
|
|
61
|
+
}
|
|
62
|
+
export {};
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Thin HTTP client for the Superblocks orchestrator / agent used by Gateway
|
|
3
|
+
* when Clark asks the editor peer to run APIs or load integration metadata.
|
|
4
|
+
*
|
|
5
|
+
* The base URL is discovered per session from Server `/users/me` agents
|
|
6
|
+
* (same filters as the browser), not operator-picked env. Scoped JWTs travel
|
|
7
|
+
* in `x-superblocks-authorization`, matching the editor's execute path.
|
|
8
|
+
*/
|
|
9
|
+
const SUPERBLOCKS_AUTHORIZATION_HEADER = "x-superblocks-authorization";
|
|
10
|
+
/** Protobuf `api.v1.ViewMode.EDIT` — same numeric the UI sends on v3/execute. */
|
|
11
|
+
const ORCHESTRATOR_VIEW_MODE_EDIT = 1;
|
|
12
|
+
const DEFAULT_TIMEOUT_MS = 120_000;
|
|
13
|
+
const MAX_DETAIL_LENGTH = 300;
|
|
14
|
+
function detailSuffix(body) {
|
|
15
|
+
if (!body.trim()) {
|
|
16
|
+
return "";
|
|
17
|
+
}
|
|
18
|
+
let detail = body;
|
|
19
|
+
try {
|
|
20
|
+
const parsed = JSON.parse(body);
|
|
21
|
+
if (parsed && typeof parsed === "object") {
|
|
22
|
+
const record = parsed;
|
|
23
|
+
const message = record.responseMeta?.message ?? record.message ?? record.error;
|
|
24
|
+
if (typeof message === "string" && message.trim()) {
|
|
25
|
+
detail = message;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
// Not JSON — fall back to the raw body.
|
|
31
|
+
}
|
|
32
|
+
return ` — ${detail.trim().slice(0, MAX_DETAIL_LENGTH)}`;
|
|
33
|
+
}
|
|
34
|
+
export class OrchestratorHttpError extends Error {
|
|
35
|
+
status;
|
|
36
|
+
constructor(message, status) {
|
|
37
|
+
super(message);
|
|
38
|
+
this.status = status;
|
|
39
|
+
this.name = "OrchestratorHttpError";
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
export class HttpOrchestratorClient {
|
|
43
|
+
orchestratorUrl;
|
|
44
|
+
timeoutMs;
|
|
45
|
+
constructor(orchestratorUrl, timeoutMs = DEFAULT_TIMEOUT_MS) {
|
|
46
|
+
this.orchestratorUrl = orchestratorUrl;
|
|
47
|
+
this.timeoutMs = timeoutMs;
|
|
48
|
+
}
|
|
49
|
+
baseUrl() {
|
|
50
|
+
return this.orchestratorUrl.replace(/\/$/, "");
|
|
51
|
+
}
|
|
52
|
+
async post(path, input) {
|
|
53
|
+
const url = new URL(`${this.baseUrl()}/${path.replace(/^\//, "")}`);
|
|
54
|
+
for (const [key, value] of Object.entries(input.query ?? {})) {
|
|
55
|
+
url.searchParams.set(key, value);
|
|
56
|
+
}
|
|
57
|
+
const headers = new Headers({
|
|
58
|
+
Authorization: `Bearer ${input.apiKey ?? input.scopedToken}`,
|
|
59
|
+
"Content-Type": "application/json",
|
|
60
|
+
[SUPERBLOCKS_AUTHORIZATION_HEADER]: `Bearer ${input.scopedToken}`,
|
|
61
|
+
});
|
|
62
|
+
if (input.profileKey) {
|
|
63
|
+
headers.set("x-superblocks-profile", input.profileKey);
|
|
64
|
+
}
|
|
65
|
+
let response;
|
|
66
|
+
try {
|
|
67
|
+
response = await fetch(url, {
|
|
68
|
+
body: JSON.stringify(input.body),
|
|
69
|
+
headers,
|
|
70
|
+
method: "POST",
|
|
71
|
+
signal: AbortSignal.timeout(this.timeoutMs),
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
catch (error) {
|
|
75
|
+
if (error instanceof Error && error.name === "TimeoutError") {
|
|
76
|
+
throw new Error(`Orchestrator ${path} timed out after ${this.timeoutMs}ms`);
|
|
77
|
+
}
|
|
78
|
+
throw error;
|
|
79
|
+
}
|
|
80
|
+
if (!response.ok) {
|
|
81
|
+
if (response.status === 401) {
|
|
82
|
+
console.warn("gateway orchestrator auth rejected", {
|
|
83
|
+
path,
|
|
84
|
+
profileKey: input.profileKey,
|
|
85
|
+
status: response.status,
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
throw new OrchestratorHttpError(`Orchestrator ${path} failed: ${response.status}${detailSuffix(await response.text().catch(() => ""))}`, response.status);
|
|
89
|
+
}
|
|
90
|
+
if (response.status === 204) {
|
|
91
|
+
return undefined;
|
|
92
|
+
}
|
|
93
|
+
const text = await response.text();
|
|
94
|
+
if (!text.trim()) {
|
|
95
|
+
return undefined;
|
|
96
|
+
}
|
|
97
|
+
try {
|
|
98
|
+
return JSON.parse(text);
|
|
99
|
+
}
|
|
100
|
+
catch {
|
|
101
|
+
return text;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
async executeSdkApiV3(input) {
|
|
105
|
+
return this.post("v3/execute", {
|
|
106
|
+
apiKey: input.apiKey,
|
|
107
|
+
body: {
|
|
108
|
+
applicationId: input.applicationId,
|
|
109
|
+
entryPoint: input.entryPoint,
|
|
110
|
+
inputs: input.inputs,
|
|
111
|
+
viewMode: ORCHESTRATOR_VIEW_MODE_EDIT,
|
|
112
|
+
...(input.exportName ? { exportName: input.exportName } : {}),
|
|
113
|
+
...(input.branchName ? { branchName: input.branchName } : {}),
|
|
114
|
+
...(input.profileKey
|
|
115
|
+
? {
|
|
116
|
+
profile: {
|
|
117
|
+
key: input.profileKey,
|
|
118
|
+
name: input.profileKey,
|
|
119
|
+
},
|
|
120
|
+
}
|
|
121
|
+
: {}),
|
|
122
|
+
},
|
|
123
|
+
profileKey: input.profileKey,
|
|
124
|
+
scopedToken: input.scopedToken,
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
async executeV2Api(input) {
|
|
128
|
+
return this.post("v2/execute", {
|
|
129
|
+
apiKey: input.apiKey,
|
|
130
|
+
body: input.body,
|
|
131
|
+
profileKey: input.profileKey,
|
|
132
|
+
query: {
|
|
133
|
+
eventType: "ON_CLARK_REQUEST",
|
|
134
|
+
viewMode: "editor",
|
|
135
|
+
},
|
|
136
|
+
scopedToken: input.scopedToken,
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
async getMetadata(input) {
|
|
140
|
+
const raw = await this.post("v2/metadata", {
|
|
141
|
+
apiKey: input.apiKey,
|
|
142
|
+
body: {
|
|
143
|
+
integration: input.integrationId,
|
|
144
|
+
profile: { name: input.profileKey },
|
|
145
|
+
stepConfiguration: input.stepConfiguration ?? {},
|
|
146
|
+
},
|
|
147
|
+
profileKey: input.profileKey,
|
|
148
|
+
scopedToken: input.scopedToken,
|
|
149
|
+
});
|
|
150
|
+
if (raw && typeof raw === "object" && !Array.isArray(raw)) {
|
|
151
|
+
const record = raw;
|
|
152
|
+
if (record.data && typeof record.data === "object") {
|
|
153
|
+
return record.data;
|
|
154
|
+
}
|
|
155
|
+
return raw;
|
|
156
|
+
}
|
|
157
|
+
return {};
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/orchestrator/client.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,MAAM,gCAAgC,GAAG,6BAA6B,CAAC;AAEvE,iFAAiF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AE;gBACnC,iBAAiB,EAAE,KAAK,CAAC,iBAAiB,IAAI,EAAE;aACjD;YACD,UAAU,EAAE,KAAK,CAAC,UAAU;YAC5B,WAAW,EAAE,KAAK,CAAC,WAAW;SAC/B,CAAC,CAAC;QACH,IAAI,GAAG,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;YAC1D,MAAM,MAAM,GAAG,GAAyB,CAAC;YACzC,IAAI,MAAM,CAAC,IAAI,IAAI,OAAO,MAAM,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;gBACnD,OAAO,MAAM,CAAC,IAA+B,CAAC;YAChD,CAAC;YACD,OAAO,GAA8B,CAAC;QACxC,CAAC;QACD,OAAO,EAAE,CAAC;IACZ,CAAC;CACF"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export type EnsurePlaywrightChromiumOptions = {
|
|
2
|
+
/** Override for tests. Defaults to Playwright's Chromium executable path. */
|
|
3
|
+
chromiumExecutablePath?: string;
|
|
4
|
+
/** CLI invoked when Chromium is missing. Defaults to `pnpm`. */
|
|
5
|
+
playwrightCli?: string;
|
|
6
|
+
playwrightArgs?: string[];
|
|
7
|
+
};
|
|
8
|
+
export type EnsurePlaywrightChromiumResult = {
|
|
9
|
+
/** True when this call ran an install. */
|
|
10
|
+
installed: boolean;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Probe only: true when Playwright Chromium is already on disk. Does not
|
|
14
|
+
* download anything. Used by `gateway setup` capture.mode and by capabilities
|
|
15
|
+
* that must fail closed instead of waiting on `chromium.launch()`.
|
|
16
|
+
*/
|
|
17
|
+
export declare function playwrightChromiumPresent(options?: Pick<EnsurePlaywrightChromiumOptions, "chromiumExecutablePath">): Promise<boolean>;
|
|
18
|
+
/**
|
|
19
|
+
* Ensures Playwright Chromium is on disk. Intended for `gateway setup`, not
|
|
20
|
+
* every `gateway serve` - corp laptops need a one-time download with network.
|
|
21
|
+
*/
|
|
22
|
+
export declare function ensurePlaywrightChromium(options?: EnsurePlaywrightChromiumOptions): Promise<EnsurePlaywrightChromiumResult>;
|
|
23
|
+
/**
|
|
24
|
+
* Clear error for `gateway serve` when setup was skipped.
|
|
25
|
+
*/
|
|
26
|
+
export declare function assertPlaywrightChromiumInstalled(options?: Pick<EnsurePlaywrightChromiumOptions, "chromiumExecutablePath">): Promise<void>;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { execFile as execFileCallback } from "node:child_process";
|
|
2
|
+
import { access } from "node:fs/promises";
|
|
3
|
+
import { promisify } from "node:util";
|
|
4
|
+
import { chromium } from "playwright";
|
|
5
|
+
const execFile = promisify(execFileCallback);
|
|
6
|
+
async function pathExists(path) {
|
|
7
|
+
try {
|
|
8
|
+
await access(path);
|
|
9
|
+
return true;
|
|
10
|
+
}
|
|
11
|
+
catch {
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Probe only: true when Playwright Chromium is already on disk. Does not
|
|
17
|
+
* download anything. Used by `gateway setup` capture.mode and by capabilities
|
|
18
|
+
* that must fail closed instead of waiting on `chromium.launch()`.
|
|
19
|
+
*/
|
|
20
|
+
export async function playwrightChromiumPresent(options = {}) {
|
|
21
|
+
const executablePath = options.chromiumExecutablePath ?? chromium.executablePath();
|
|
22
|
+
return pathExists(executablePath);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Ensures Playwright Chromium is on disk. Intended for `gateway setup`, not
|
|
26
|
+
* every `gateway serve` - corp laptops need a one-time download with network.
|
|
27
|
+
*/
|
|
28
|
+
export async function ensurePlaywrightChromium(options = {}) {
|
|
29
|
+
const executablePath = options.chromiumExecutablePath ?? chromium.executablePath();
|
|
30
|
+
if (await pathExists(executablePath)) {
|
|
31
|
+
return { installed: false };
|
|
32
|
+
}
|
|
33
|
+
const cli = options.playwrightCli ?? "pnpm";
|
|
34
|
+
const args = options.playwrightArgs ??
|
|
35
|
+
(options.playwrightCli
|
|
36
|
+
? ["install", "chromium"]
|
|
37
|
+
: ["exec", "playwright", "install", "chromium"]);
|
|
38
|
+
try {
|
|
39
|
+
await execFile(cli, args);
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
const detail = error instanceof Error ? error.message : String(error);
|
|
43
|
+
throw new Error(`Failed to install Playwright Chromium (needed for preview screenshots). Run: pnpm exec playwright install chromium. (${detail})`);
|
|
44
|
+
}
|
|
45
|
+
if (!(await pathExists(executablePath))) {
|
|
46
|
+
throw new Error(`Playwright Chromium is still missing after install at ${executablePath}. Run: pnpm exec playwright install chromium`);
|
|
47
|
+
}
|
|
48
|
+
return { installed: true };
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Clear error for `gateway serve` when setup was skipped.
|
|
52
|
+
*/
|
|
53
|
+
export async function assertPlaywrightChromiumInstalled(options = {}) {
|
|
54
|
+
const executablePath = options.chromiumExecutablePath ?? chromium.executablePath();
|
|
55
|
+
if (await pathExists(executablePath)) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
throw new Error(`Playwright Chromium is not installed (looked for ${executablePath}). Run: superblocks gateway setup`);
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=ensure-chromium.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ensure-chromium.js","sourceRoot":"","sources":["../../src/playwright/ensure-chromium.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,IAAI,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAClE,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEtC,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEtC,MAAM,QAAQ,GAAG,SAAS,CAAC,gBAAgB,CAAC,CAAC;AAe7C,KAAK,UAAU,UAAU,CAAC,IAAY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,CAAC,MAAM,UAAU,CAAC,cAAc,CAAC,CAAC,EAAE,CAAC;QACxC,MAAM,IAAI,KAAK,CACb,yDAAyD,cAAc,8CAA8C,CACtH,CAAC;IACJ,CAAC;IAED,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;AAC7B,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,iCAAiC,CACrD,UAA2E,EAAE;IAE7E,MAAM,cAAc,GAClB,OAAO,CAAC,sBAAsB,IAAI,QAAQ,CAAC,cAAc,EAAE,CAAC;IAC9D,IAAI,MAAM,UAAU,CAAC,cAAc,CAAC,EAAE,CAAC;QACrC,OAAO;IACT,CAAC;IACD,MAAM,IAAI,KAAK,CACb,oDAAoD,cAAc,mCAAmC,CACtG,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Headless capture of a preview viewer URL for MCP image content.
|
|
3
|
+
*
|
|
4
|
+
* Best-effort: callers must succeed with URLs alone when this returns
|
|
5
|
+
* undefined. Output is capped for Claude Desktop tool-result size limits.
|
|
6
|
+
*/
|
|
7
|
+
export type PreviewScreenshot = {
|
|
8
|
+
dataBase64: string;
|
|
9
|
+
mimeType: "image/jpeg";
|
|
10
|
+
};
|
|
11
|
+
/** Soft cap on decoded bytes before base64 (~256 KiB). */
|
|
12
|
+
export declare const PREVIEW_SCREENSHOT_MAX_BYTES: number;
|
|
13
|
+
export type CapturePreviewScreenshot = (input: {
|
|
14
|
+
/**
|
|
15
|
+
* Bearer the embed shell should authenticate with. Without it the shell
|
|
16
|
+
* falls back to Auth0 silent login, which cannot succeed headless.
|
|
17
|
+
*/
|
|
18
|
+
embedToken?: string;
|
|
19
|
+
url: string;
|
|
20
|
+
timeoutMs?: number;
|
|
21
|
+
}) => Promise<PreviewScreenshot | undefined>;
|
|
22
|
+
/**
|
|
23
|
+
* Page source that hands the deployed shell its bearer, and the whole reason a
|
|
24
|
+
* headless capture can paint a real app.
|
|
25
|
+
*
|
|
26
|
+
* `ui-deployed-shell` only accepts a bearer through an `INITIALIZE_EMBED`
|
|
27
|
+
* message from its embedder, and ~300ms after mount it gives up and tries
|
|
28
|
+
* Auth0 silent login instead — which has no session to find here. At top level
|
|
29
|
+
* the shell's embedder port has no parent window to check messages against, so
|
|
30
|
+
* it accepts one posted by the page itself.
|
|
31
|
+
*
|
|
32
|
+
* Delivery happens exactly once: each `INITIALIZE_EMBED` replaces the shell's
|
|
33
|
+
* auth state and restarts its bootstrap, so a repeating handshake would keep
|
|
34
|
+
* the app from ever settling.
|
|
35
|
+
*
|
|
36
|
+
* This is source text rather than a function handed to `addInitScript` because
|
|
37
|
+
* Playwright ships a function by serializing it, which drags in whatever
|
|
38
|
+
* helpers the bundler injected into its body (`__name` under tsx) and throws a
|
|
39
|
+
* ReferenceError in the page.
|
|
40
|
+
*
|
|
41
|
+
* The result is only ever evaluated as script source (Playwright forwards it
|
|
42
|
+
* to CDP `addScriptToEvaluateOnNewDocument`), never interpolated into HTML, so
|
|
43
|
+
* `JSON.stringify` is sufficient to contain the token. Putting it in a
|
|
44
|
+
* `<script>` element would not be — the token would need `</script>` escaped.
|
|
45
|
+
*/
|
|
46
|
+
export declare function buildEmbedHandshakeScript(token: string): string;
|
|
47
|
+
/**
|
|
48
|
+
* Captures a JPEG screenshot via Playwright when available. Soft-fails when
|
|
49
|
+
* Chromium is missing or the page never becomes ready — callers must still
|
|
50
|
+
* return preview URLs when this returns undefined.
|
|
51
|
+
*/
|
|
52
|
+
export declare const capturePreviewScreenshotWithPlaywright: CapturePreviewScreenshot;
|