@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.
Files changed (183) hide show
  1. package/LICENSE.txt +87 -0
  2. package/README.md +170 -0
  3. package/dist/agents/resolve-orchestrator-url.d.ts +22 -0
  4. package/dist/agents/resolve-orchestrator-url.js +38 -0
  5. package/dist/agents/resolve-orchestrator-url.js.map +1 -0
  6. package/dist/capabilities/import-prompt.d.ts +11 -0
  7. package/dist/capabilities/import-prompt.js +96 -0
  8. package/dist/capabilities/import-prompt.js.map +1 -0
  9. package/dist/capabilities/lifecycle.d.ts +73 -0
  10. package/dist/capabilities/lifecycle.js +2531 -0
  11. package/dist/capabilities/lifecycle.js.map +1 -0
  12. package/dist/capabilities/persisted-progress.d.ts +46 -0
  13. package/dist/capabilities/persisted-progress.js +246 -0
  14. package/dist/capabilities/persisted-progress.js.map +1 -0
  15. package/dist/capabilities/types.d.ts +446 -0
  16. package/dist/capabilities/types.js +47 -0
  17. package/dist/capabilities/types.js.map +1 -0
  18. package/dist/capture/browser-contract.d.ts +36 -0
  19. package/dist/capture/browser-contract.js +24 -0
  20. package/dist/capture/browser-contract.js.map +1 -0
  21. package/dist/capture/browser-instructions.d.ts +9 -0
  22. package/dist/capture/browser-instructions.js +17 -0
  23. package/dist/capture/browser-instructions.js.map +1 -0
  24. package/dist/capture/capture-library-probe.d.ts +55 -0
  25. package/dist/capture/capture-library-probe.js +177 -0
  26. package/dist/capture/capture-library-probe.js.map +1 -0
  27. package/dist/capture/capture-library.d.ts +52 -0
  28. package/dist/capture/capture-library.js +249 -0
  29. package/dist/capture/capture-library.js.map +1 -0
  30. package/dist/capture/classify-library-paint.d.ts +21 -0
  31. package/dist/capture/classify-library-paint.js +13 -0
  32. package/dist/capture/classify-library-paint.js.map +1 -0
  33. package/dist/capture/host-mcp-scan.d.ts +16 -0
  34. package/dist/capture/host-mcp-scan.js +64 -0
  35. package/dist/capture/host-mcp-scan.js.map +1 -0
  36. package/dist/capture/library-parent-script.d.ts +34 -0
  37. package/dist/capture/library-parent-script.js +82 -0
  38. package/dist/capture/library-parent-script.js.map +1 -0
  39. package/dist/capture/mode.d.ts +22 -0
  40. package/dist/capture/mode.js +45 -0
  41. package/dist/capture/mode.js.map +1 -0
  42. package/dist/config.d.ts +141 -0
  43. package/dist/config.js +109 -0
  44. package/dist/config.js.map +1 -0
  45. package/dist/debug.d.ts +2 -0
  46. package/dist/debug.js +9 -0
  47. package/dist/debug.js.map +1 -0
  48. package/dist/deps.d.ts +36 -0
  49. package/dist/deps.js +2 -0
  50. package/dist/deps.js.map +1 -0
  51. package/dist/events/cursor.d.ts +43 -0
  52. package/dist/events/cursor.js +78 -0
  53. package/dist/events/cursor.js.map +1 -0
  54. package/dist/events/memory-event-store.d.ts +34 -0
  55. package/dist/events/memory-event-store.js +110 -0
  56. package/dist/events/memory-event-store.js.map +1 -0
  57. package/dist/events/merge.d.ts +23 -0
  58. package/dist/events/merge.js +97 -0
  59. package/dist/events/merge.js.map +1 -0
  60. package/dist/events/normalized-collector.d.ts +62 -0
  61. package/dist/events/normalized-collector.js +156 -0
  62. package/dist/events/normalized-collector.js.map +1 -0
  63. package/dist/events/schema.d.ts +9 -0
  64. package/dist/events/schema.js +93 -0
  65. package/dist/events/schema.js.map +1 -0
  66. package/dist/events/snapshot.d.ts +32 -0
  67. package/dist/events/snapshot.js +57 -0
  68. package/dist/events/snapshot.js.map +1 -0
  69. package/dist/events/stream-key.d.ts +2 -0
  70. package/dist/events/stream-key.js +31 -0
  71. package/dist/events/stream-key.js.map +1 -0
  72. package/dist/events/types.d.ts +179 -0
  73. package/dist/events/types.js +66 -0
  74. package/dist/events/types.js.map +1 -0
  75. package/dist/health/readiness.d.ts +99 -0
  76. package/dist/health/readiness.js +202 -0
  77. package/dist/health/readiness.js.map +1 -0
  78. package/dist/index.d.ts +10 -0
  79. package/dist/index.js +10 -0
  80. package/dist/index.js.map +1 -0
  81. package/dist/integrations/filters.d.ts +8 -0
  82. package/dist/integrations/filters.js +40 -0
  83. package/dist/integrations/filters.js.map +1 -0
  84. package/dist/integrations/map.d.ts +26 -0
  85. package/dist/integrations/map.js +43 -0
  86. package/dist/integrations/map.js.map +1 -0
  87. package/dist/integrations/profile-key.d.ts +19 -0
  88. package/dist/integrations/profile-key.js +35 -0
  89. package/dist/integrations/profile-key.js.map +1 -0
  90. package/dist/main.d.ts +2 -0
  91. package/dist/main.js +5 -0
  92. package/dist/main.js.map +1 -0
  93. package/dist/orchestrator/client.d.ts +62 -0
  94. package/dist/orchestrator/client.js +160 -0
  95. package/dist/orchestrator/client.js.map +1 -0
  96. package/dist/playwright/ensure-chromium.d.ts +26 -0
  97. package/dist/playwright/ensure-chromium.js +60 -0
  98. package/dist/playwright/ensure-chromium.js.map +1 -0
  99. package/dist/preview/capture-screenshot.d.ts +52 -0
  100. package/dist/preview/capture-screenshot.js +158 -0
  101. package/dist/preview/capture-screenshot.js.map +1 -0
  102. package/dist/preview/viewer-url.d.ts +82 -0
  103. package/dist/preview/viewer-url.js +128 -0
  104. package/dist/preview/viewer-url.js.map +1 -0
  105. package/dist/process/fault-barrier.d.ts +55 -0
  106. package/dist/process/fault-barrier.js +113 -0
  107. package/dist/process/fault-barrier.js.map +1 -0
  108. package/dist/resume/memory-progress-store.d.ts +39 -0
  109. package/dist/resume/memory-progress-store.js +82 -0
  110. package/dist/resume/memory-progress-store.js.map +1 -0
  111. package/dist/resume/memory-recent-app-store.d.ts +14 -0
  112. package/dist/resume/memory-recent-app-store.js +27 -0
  113. package/dist/resume/memory-recent-app-store.js.map +1 -0
  114. package/dist/resume/memory-turn-store.d.ts +18 -0
  115. package/dist/resume/memory-turn-store.js +73 -0
  116. package/dist/resume/memory-turn-store.js.map +1 -0
  117. package/dist/resume/progress-key.d.ts +21 -0
  118. package/dist/resume/progress-key.js +58 -0
  119. package/dist/resume/progress-key.js.map +1 -0
  120. package/dist/resume/stores.d.ts +14 -0
  121. package/dist/resume/stores.js +18 -0
  122. package/dist/resume/stores.js.map +1 -0
  123. package/dist/resume/types.d.ts +124 -0
  124. package/dist/resume/types.js +13 -0
  125. package/dist/resume/types.js.map +1 -0
  126. package/dist/sabs/agent-facing-text.d.ts +33 -0
  127. package/dist/sabs/agent-facing-text.js +125 -0
  128. package/dist/sabs/agent-facing-text.js.map +1 -0
  129. package/dist/sabs/browser-context.d.ts +53 -0
  130. package/dist/sabs/browser-context.js +91 -0
  131. package/dist/sabs/browser-context.js.map +1 -0
  132. package/dist/sabs/editor-client-methods.d.ts +147 -0
  133. package/dist/sabs/editor-client-methods.js +715 -0
  134. package/dist/sabs/editor-client-methods.js.map +1 -0
  135. package/dist/sabs/recent-tool-runs.d.ts +14 -0
  136. package/dist/sabs/recent-tool-runs.js +61 -0
  137. package/dist/sabs/recent-tool-runs.js.map +1 -0
  138. package/dist/sabs/session-peer.d.ts +351 -0
  139. package/dist/sabs/session-peer.js +2 -0
  140. package/dist/sabs/session-peer.js.map +1 -0
  141. package/dist/sabs/turn-collector.d.ts +152 -0
  142. package/dist/sabs/turn-collector.js +573 -0
  143. package/dist/sabs/turn-collector.js.map +1 -0
  144. package/dist/sabs/websocket-session-peer.d.ts +514 -0
  145. package/dist/sabs/websocket-session-peer.js +2487 -0
  146. package/dist/sabs/websocket-session-peer.js.map +1 -0
  147. package/dist/security/constant-time.d.ts +9 -0
  148. package/dist/security/constant-time.js +13 -0
  149. package/dist/security/constant-time.js.map +1 -0
  150. package/dist/server/client.d.ts +371 -0
  151. package/dist/server/client.js +572 -0
  152. package/dist/server/client.js.map +1 -0
  153. package/dist/server/identity-reads.d.ts +76 -0
  154. package/dist/server/identity-reads.js +209 -0
  155. package/dist/server/identity-reads.js.map +1 -0
  156. package/dist/start.d.ts +14 -0
  157. package/dist/start.js +75 -0
  158. package/dist/start.js.map +1 -0
  159. package/dist/telemetry/metrics.d.ts +32 -0
  160. package/dist/telemetry/metrics.js +57 -0
  161. package/dist/telemetry/metrics.js.map +1 -0
  162. package/dist/transports/mcp/admin-tools.d.ts +47 -0
  163. package/dist/transports/mcp/admin-tools.js +164 -0
  164. package/dist/transports/mcp/admin-tools.js.map +1 -0
  165. package/dist/transports/mcp/app-status-html.d.ts +15 -0
  166. package/dist/transports/mcp/app-status-html.js +563 -0
  167. package/dist/transports/mcp/app-status-html.js.map +1 -0
  168. package/dist/transports/mcp/decision-elicitation.d.ts +74 -0
  169. package/dist/transports/mcp/decision-elicitation.js +233 -0
  170. package/dist/transports/mcp/decision-elicitation.js.map +1 -0
  171. package/dist/transports/mcp/dispatch-probe.d.ts +24 -0
  172. package/dist/transports/mcp/dispatch-probe.js +48 -0
  173. package/dist/transports/mcp/dispatch-probe.js.map +1 -0
  174. package/dist/transports/mcp/format-tool-content.d.ts +25 -0
  175. package/dist/transports/mcp/format-tool-content.js +48 -0
  176. package/dist/transports/mcp/format-tool-content.js.map +1 -0
  177. package/dist/transports/mcp/mount.d.ts +9 -0
  178. package/dist/transports/mcp/mount.js +469 -0
  179. package/dist/transports/mcp/mount.js.map +1 -0
  180. package/dist/transports/mcp/progress-notifier.d.ts +39 -0
  181. package/dist/transports/mcp/progress-notifier.js +52 -0
  182. package/dist/transports/mcp/progress-notifier.js.map +1 -0
  183. package/package.json +72 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent-facing-text.js","sourceRoot":"","sources":["../../src/sabs/agent-facing-text.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,uEAAuE;AACvE,MAAM,eAAe,GAAa;IAChC,oEAAoE;IACpE,+EAA+E;IAC/E,0CAA0C;IAC1C,2BAA2B;IAC3B,uBAAuB;IACvB,wCAAwC;IACxC,iDAAiD;IACjD,sFAAsF;IACtF,0CAA0C;IAC1C,qFAAqF;CACtF,CAAC;AAEF,MAAM,iBAAiB,GAAG,IAAI,GAAG,CAAC;IAChC,SAAS;IACT,QAAQ;IACR,eAAe;IACf,UAAU;IACV,QAAQ;IACR,QAAQ;IACR,OAAO;CACR,CAAC,CAA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C;gBAC9C,GAAG,CAAC,GAAG,CAAC,GAAG,QAAQ,CAAC;gBACpB,SAAS;YACX,CAAC;YACD,GAAG,CAAC,GAAG,CAAC,GAAG,wBAAwB,CAAC,KAAK,CAAC,CAAC;QAC7C,CAAC;QACD,OAAO,GAAG,CAAC;IACb,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
@@ -0,0 +1,53 @@
1
+ /**
2
+ * Builds the `browserContext` the ai-service needs before it will register
3
+ * Clark's Playwright tools.
4
+ *
5
+ * Opt-in: the sandbox launches Chromium, mocks `window.parent`, and
6
+ * replays `initData` / `bootstrapData` to the app shell as `sb-init` and
7
+ * `sb-bootstrap-response`. The gateway only supplies the same context the
8
+ * browser editor assembles from Redux. Gateway preview screenshots use
9
+ * laptop Chromium instead and do not call this.
10
+ */
11
+ import type { BrowserContext } from "@superblocksteam/library-shared/types";
12
+ /**
13
+ * An org profile as the Superblocks API returns it. `key` is what selects the
14
+ * profile; `id` and `displayName` round out the `Profile` shape the app shell
15
+ * types against.
16
+ */
17
+ export type BrowserContextProfile = {
18
+ allowedInEditor?: boolean;
19
+ displayName?: string;
20
+ id?: string;
21
+ key: string;
22
+ };
23
+ export type BrowserContextInput = {
24
+ applicationId: string;
25
+ /**
26
+ * Personal API key sent as library `token` / `Authorization`. The
27
+ * orchestrator forwards that header to the code-bundle route, which
28
+ * checks `apps:view` and rejects the live-edit `apps:update` JWT.
29
+ */
30
+ apiKey?: string;
31
+ /** Sandbox origin from `connectLiveEdit`; the editor iframe's own base URL. */
32
+ liveEditUrl: string;
33
+ orchestratorUrl: string;
34
+ organizationId?: string;
35
+ /** Held-session peer id, so the app shell reuses this editor's socket. */
36
+ peerId: string;
37
+ /** Profile key already resolved for this session's orchestrator calls. */
38
+ profileKey?: string;
39
+ profiles?: BrowserContextProfile[];
40
+ /** Scoped `apps:update` JWT the live-edit session was opened with. */
41
+ sessionToken: string;
42
+ uiBaseUrl: string;
43
+ userEmail?: string;
44
+ userId: string;
45
+ };
46
+ /**
47
+ * Returns the context, or `undefined` when the sandbox URL is unusable.
48
+ *
49
+ * Undefined rather than a throw: browser testing is an enhancement to a turn,
50
+ * so a sandbox we cannot address should cost Clark its Playwright tools, not
51
+ * the whole prompt.
52
+ */
53
+ export declare function buildBrowserContext(input: BrowserContextInput): BrowserContext | undefined;
@@ -0,0 +1,91 @@
1
+ /**
2
+ * Builds the `browserContext` the ai-service needs before it will register
3
+ * Clark's Playwright tools.
4
+ *
5
+ * Opt-in: the sandbox launches Chromium, mocks `window.parent`, and
6
+ * replays `initData` / `bootstrapData` to the app shell as `sb-init` and
7
+ * `sb-bootstrap-response`. The gateway only supplies the same context the
8
+ * browser editor assembles from Redux. Gateway preview screenshots use
9
+ * laptop Chromium instead and do not call this.
10
+ */
11
+ import { Profile, ProfileType } from "@superblocksteam/shared";
12
+ function toProfile(row) {
13
+ return new Profile({
14
+ allowedInEditor: row.allowedInEditor,
15
+ description: "",
16
+ displayName: row.displayName ?? row.key,
17
+ id: row.id ?? row.key,
18
+ key: row.key,
19
+ type: ProfileType.RESERVED,
20
+ });
21
+ }
22
+ function selectProfiles(input) {
23
+ const rows = input.profiles ?? [];
24
+ if (rows.length === 0) {
25
+ return undefined;
26
+ }
27
+ const chosen = rows.find((row) => row.key === input.profileKey) ?? rows[0];
28
+ if (!chosen) {
29
+ return undefined;
30
+ }
31
+ const selected = toProfile(chosen);
32
+ return {
33
+ available: rows.map(toProfile),
34
+ default: selected,
35
+ selected,
36
+ };
37
+ }
38
+ /**
39
+ * Returns the context, or `undefined` when the sandbox URL is unusable.
40
+ *
41
+ * Undefined rather than a throw: browser testing is an enhancement to a turn,
42
+ * so a sandbox we cannot address should cost Clark its Playwright tools, not
43
+ * the whole prompt.
44
+ */
45
+ export function buildBrowserContext(input) {
46
+ let iframeBaseUrl;
47
+ try {
48
+ iframeBaseUrl = new URL(input.liveEditUrl);
49
+ }
50
+ catch {
51
+ return undefined;
52
+ }
53
+ if (iframeBaseUrl.protocol !== "http:" &&
54
+ iframeBaseUrl.protocol !== "https:") {
55
+ return undefined;
56
+ }
57
+ // The editor's iframe carries this too. Without it the app shell boots in
58
+ // its viewer mode, where the editing affordances Clark's tests drive are
59
+ // absent.
60
+ iframeBaseUrl.searchParams.set("app_mode", "EDIT");
61
+ const profiles = selectProfiles(input);
62
+ return {
63
+ bootstrapData: {
64
+ accessToken: input.sessionToken,
65
+ agents: [],
66
+ agentUrls: [input.orchestratorUrl],
67
+ appId: input.applicationId,
68
+ featureFlags: {
69
+ "clark.sdk-api.enabled": true,
70
+ },
71
+ orgId: input.organizationId,
72
+ ...(profiles ? { profiles } : {}),
73
+ // Library fetch: Authorization = this token, x-superblocks-authorization
74
+ // = accessToken. The API key belongs on Authorization; the scoped JWT
75
+ // does not carry apps:view for the orchestrator's code-bundle fetch.
76
+ token: input.apiKey ?? input.sessionToken,
77
+ userEmail: input.userEmail,
78
+ userId: input.userId,
79
+ windowOriginUrl: input.uiBaseUrl,
80
+ },
81
+ iframeBaseUrl: iframeBaseUrl.toString(),
82
+ initData: {
83
+ appId: input.applicationId,
84
+ devServerAuthorization: `Bearer ${input.sessionToken}`,
85
+ peerId: input.peerId,
86
+ userId: input.userId,
87
+ windowOriginUrl: input.uiBaseUrl,
88
+ },
89
+ };
90
+ }
91
+ //# sourceMappingURL=browser-context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"browser-context.js","sourceRoot":"","sources":["../../src/sabs/browser-context.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAGH,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AA4C/D,SAAS,SAAS,CAAC,GAA0B;IAC3C,OAAO,IAAI,OAAO,CAAC;QACjB,eAAe,EAAE,GAAG,CAAC,eAAe;QACpC,WAAW,EAAE,EAAE;QACf,WAAW,EAAE,GAAG,CAAC,WAAW,IAAI,GAAG,CAAC,GAAG;QACvC,EAAE,EAAE,GAAG,CAAC,EAAE,IAAI,GAAG,CAAC,G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;IACvC,OAAO;QACL,aAAa,EAAE;YACb,WAAW,EAAE,KAAK,CAAC,YAAY;YAC/B,MAAM,EAAE,EAAE;YACV,SAAS,EAAE,CAAC,KAAK,CAAC,eAAe,CAAC;YAClC,KAAK,EAAE,KAAK,CAAC,aAAa;YAC1B,YAAY,EAAE;gBACZ,uBAAuB,EAAE,IAAI;aAC9B;YACD,KAAK,EAAE,KAAK,CAAC,cAAc;YAC3B,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YACjC,yEAAyE;YACzE,sEAAsE;YACtE,qEAAqE;YACrE,KAAK,EAAE,KAAK,CAAC,MAAM,IAAI,KAAK,CAAC,YAAY;YACzC,SAAS,EAAE,KAAK,CAAC,SAAS;YAC1B,MAAM,EAAE,KAAK,CAAC,MAAM;YACpB,eAAe,EAAE,KAAK,CAAC,SAAS;SACjC;QACD,aAAa,EAAE,aAAa,CAAC,QAAQ,EAAE;QACvC,QAAQ,EAAE;YACR,KAAK,EAAE,KAAK,CAAC,aAAa;YAC1B,sBAAsB,EAAE,UAAU,KAAK,CAAC,YAAY,EAAE;YACtD,MAAM,EAAE,KAAK,CAAC,MAAM;YACpB,MAAM,EAAE,KAAK,CAAC,MAAM;YACpB,eAAe,EAAE,KAAK,CAAC,SAAS;SACjC;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,147 @@
1
+ import type { PromptContextIntegration, SdkApiExecutionResult } from "@superblocksteam/library-shared/types";
2
+ import { type MethodHandlers, type RequestContextBase } from "@superblocksteam/shared";
3
+ import type { OrchestratorClient } from "../orchestrator/client.js";
4
+ import type { SuperblocksServerClient } from "../server/client.js";
5
+ export type IntegrationExecuteResult = {
6
+ error?: string;
7
+ response?: string;
8
+ };
9
+ type IntegrationExecutePayload = {
10
+ integrationHint?: {
11
+ displayName?: string;
12
+ name: string;
13
+ type: string;
14
+ };
15
+ integrationId: string;
16
+ request: Record<string, unknown>;
17
+ };
18
+ /**
19
+ * The subset of library-shared's AiChatMessage the gateway reads. Test-run
20
+ * fields are flattened in here because Clark reports a whole test run through
21
+ * ordinary `aiPushMessage` pushes, distinguished only by `type`.
22
+ */
23
+ export type ClarkMessage = {
24
+ choices?: Array<string | {
25
+ text: string;
26
+ subText?: string;
27
+ }>;
28
+ content?: string;
29
+ header?: string;
30
+ id?: string;
31
+ name?: string;
32
+ options?: Array<string | {
33
+ label?: string;
34
+ value?: string;
35
+ }>;
36
+ role?: string;
37
+ summary?: string;
38
+ testCaseId?: string;
39
+ testCaseStatus?: string;
40
+ testCases?: Array<{
41
+ id?: string;
42
+ name?: string;
43
+ status?: string;
44
+ }>;
45
+ testRunId?: string;
46
+ testStatus?: string;
47
+ title?: string;
48
+ type?: string;
49
+ };
50
+ export type ClarkPeerEvent = {
51
+ kind: "message";
52
+ message: ClarkMessage;
53
+ } | {
54
+ kind: "change_info";
55
+ label: string;
56
+ } | {
57
+ kind: "draft_state";
58
+ hasDraft: boolean;
59
+ } | {
60
+ kind: "generation_state";
61
+ hasError?: boolean;
62
+ hasSuggestions?: boolean;
63
+ state: string;
64
+ } | {
65
+ kind: "reload_iframe";
66
+ } | {
67
+ kind: "sync_status";
68
+ status?: string;
69
+ } | {
70
+ kind: "task_status";
71
+ label: string;
72
+ };
73
+ export type ClarkPeerListener = (event: ClarkPeerEvent) => void;
74
+ /**
75
+ * Credentials and clients the held gateway peer needs to answer Clark's
76
+ * discovery and testApi RPCs without a browser tab.
77
+ */
78
+ export type EditorSessionContext = {
79
+ apiKey: string;
80
+ applicationId: string;
81
+ branchName?: string;
82
+ organizationId: string;
83
+ orchestrator: OrchestratorClient;
84
+ profileKey: string;
85
+ server: SuperblocksServerClient;
86
+ sessionToken: string;
87
+ waitUntilFilesSynced: () => Promise<boolean>;
88
+ };
89
+ export type EditorClientMethodDeps = {
90
+ getContext: () => EditorSessionContext | undefined;
91
+ /**
92
+ * Records a mid-turn testApi / testIntegration outcome for MCP progress and
93
+ * needs_decision payloads.
94
+ */
95
+ onToolRun?: (run: {
96
+ detail?: unknown;
97
+ kind: "test_api" | "test_integration";
98
+ name: string;
99
+ success: boolean;
100
+ }) => void;
101
+ /**
102
+ * Forwards a tool-permission decision to the ai-service via
103
+ * `editor.aiRespondToToolPermission` on the held socket. Headless sessions
104
+ * auto-approve only the allowlisted Clark agent tools; other tools deny.
105
+ */
106
+ respondToToolPermission: (payload: {
107
+ approved: boolean;
108
+ messageId: string;
109
+ requestId?: string;
110
+ }) => Promise<void>;
111
+ };
112
+ /**
113
+ * Runs Clark's executeRequestToIntegration the same way the browser editor
114
+ * does: one inline V2 API step against the orchestrator. Username/password and
115
+ * other stored-credential integrations execute here; interactive IdP auth
116
+ * surfaces as an error asking the user to authenticate in the editor.
117
+ */
118
+ export declare function executeRequestToIntegrationViaOrchestrator(context: EditorSessionContext, payload: IntegrationExecutePayload): Promise<IntegrationExecuteResult>;
119
+ /**
120
+ * Prefills Clark's promptContext.integrations the same way the editor does.
121
+ */
122
+ export declare function loadIntegrationsForPrompt(context: Pick<EditorSessionContext, "apiKey" | "applicationId" | "organizationId" | "server">): Promise<Omit<PromptContextIntegration, "metadata">[]>;
123
+ export declare function mapSdkExecutionResponse(response: unknown): SdkApiExecutionResult;
124
+ /**
125
+ * Server -> editor calls the dev server makes into the peer driving a turn,
126
+ * whether that peer negotiated protocol "editor" or "gateway".
127
+ *
128
+ * Leaving these unimplemented is not inert. ISocket answers an unknown method
129
+ * with `{ code: 2, message: "unknown method <name>" }`, and the dev server does
130
+ * not catch every one of those rejections — `resetScope` in particular escalates
131
+ * to `unhandledRejection`, which exits the sandbox with "Dev server fatal exit"
132
+ * and takes the in-flight Clark build down with it. A browser editor answers
133
+ * all of them, so a held gateway socket has to as well.
134
+ *
135
+ * Keyed on `EditorClientMethods` rather than a hand-kept list so that a method
136
+ * added to the protocol upstream fails this package's typecheck instead of
137
+ * reaching a sandbox and crashing it. Same handler surface as
138
+ * `createEditorHandlers` in vite-plugin-file-sync's dev-server-ws-smoke-client,
139
+ * the other non-browser peer that speaks this protocol; it is not imported from
140
+ * there because the gateway does not depend on the vite plugin.
141
+ *
142
+ * When a listener is provided, chat, generation-state, task/change, and
143
+ * preview-ready pushes are forwarded so the gateway can wait for Clark's turn
144
+ * and surface progress over MCP.
145
+ */
146
+ export declare function createEditorClientMethods(getListener?: () => ClarkPeerListener | undefined, onInbound?: (method: string) => void, deps?: EditorClientMethodDeps): MethodHandlers<Record<string, never>, Record<string, never>, RequestContextBase>;
147
+ export {};