@ekanos/harness 0.18.0 → 0.20.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 (187) hide show
  1. package/dist/api-types.d.ts +490 -0
  2. package/dist/api-types.js +6 -0
  3. package/dist/api.d.ts +33 -0
  4. package/dist/api.js +36 -1
  5. package/dist/app.js +6 -1
  6. package/dist/internal/components/approvals-tray.d.ts +17 -0
  7. package/dist/internal/components/approvals-tray.js +116 -0
  8. package/dist/internal/components/ask-assistant-bridge.js +1 -1
  9. package/dist/internal/components/connect-controls.d.ts +12 -0
  10. package/dist/internal/components/connect-controls.js +69 -0
  11. package/dist/internal/components/connect-dialog.d.ts +19 -0
  12. package/dist/internal/components/connect-dialog.js +61 -0
  13. package/dist/internal/components/connect-panel.d.ts +25 -0
  14. package/dist/internal/components/connect-panel.js +292 -0
  15. package/dist/internal/components/connection-chip.d.ts +14 -0
  16. package/dist/internal/components/connection-chip.js +75 -0
  17. package/dist/internal/components/dashboard-grid.js +38 -24
  18. package/dist/internal/components/dev-toolbar.js +176 -103
  19. package/dist/internal/components/events-panel.d.ts +10 -0
  20. package/dist/internal/components/events-panel.js +111 -0
  21. package/dist/internal/components/health-panel.d.ts +4 -0
  22. package/dist/internal/components/health-panel.js +56 -0
  23. package/dist/internal/components/integration-badge.d.ts +29 -0
  24. package/dist/internal/components/integration-badge.js +105 -0
  25. package/dist/internal/components/local-oauth-panel.js +21 -1
  26. package/dist/internal/components/operation-runner-panel.d.ts +12 -0
  27. package/dist/internal/components/operation-runner-panel.js +331 -0
  28. package/dist/internal/components/provenance-banner.d.ts +12 -0
  29. package/dist/internal/components/provenance-banner.js +107 -0
  30. package/dist/internal/components/repo-connection.d.ts +10 -0
  31. package/dist/internal/components/repo-connection.js +32 -0
  32. package/dist/internal/components/run-log.d.ts +9 -0
  33. package/dist/internal/components/run-log.js +228 -0
  34. package/dist/internal/components/runtime-strip.d.ts +12 -0
  35. package/dist/internal/components/runtime-strip.js +158 -0
  36. package/dist/internal/components/schema-form.d.ts +13 -0
  37. package/dist/internal/components/schema-form.js +382 -0
  38. package/dist/internal/components/scrollable-nav.d.ts +12 -0
  39. package/dist/internal/components/scrollable-nav.js +68 -0
  40. package/dist/internal/components/surface-nav.d.ts +31 -1
  41. package/dist/internal/components/surface-nav.js +244 -31
  42. package/dist/internal/components/workflow-runner.d.ts +14 -0
  43. package/dist/internal/components/workflow-runner.js +104 -0
  44. package/dist/internal/lib/bundled-secrets.d.ts +9 -0
  45. package/dist/internal/lib/bundled-secrets.js +24 -0
  46. package/dist/internal/lib/chrome-slot.d.ts +2 -0
  47. package/dist/internal/lib/chrome-slot.js +25 -0
  48. package/dist/internal/lib/connection-facts.d.ts +44 -0
  49. package/dist/internal/lib/connection-facts.js +116 -0
  50. package/dist/internal/lib/console-client.d.ts +55 -0
  51. package/dist/internal/lib/console-client.js +295 -0
  52. package/dist/internal/lib/console-context.d.ts +56 -0
  53. package/dist/internal/lib/console-context.js +67 -0
  54. package/dist/internal/lib/console-hooks.d.ts +33 -0
  55. package/dist/internal/lib/console-hooks.js +118 -0
  56. package/dist/internal/lib/console-types.d.ts +279 -0
  57. package/dist/internal/lib/console-types.js +0 -0
  58. package/dist/internal/lib/experience-runtime.d.ts +8 -0
  59. package/dist/internal/lib/experience-runtime.js +22 -0
  60. package/dist/internal/lib/preview-sections.d.ts +13 -0
  61. package/dist/internal/lib/preview-sections.js +32 -0
  62. package/dist/internal/lib/repo-context.d.ts +20 -0
  63. package/dist/internal/lib/repo-context.js +64 -0
  64. package/dist/internal/lib/run-log-view.d.ts +24 -0
  65. package/dist/internal/lib/run-log-view.js +57 -0
  66. package/dist/internal/lib/schema-form-model.d.ts +34 -0
  67. package/dist/internal/lib/schema-form-model.js +272 -0
  68. package/dist/internal/lib/toolbar-context.d.ts +9 -1
  69. package/dist/internal/lib/toolbar-context.js +13 -3
  70. package/dist/internal/lib/toolbar-visibility.d.ts +16 -0
  71. package/dist/internal/lib/toolbar-visibility.js +31 -0
  72. package/dist/internal/registry-context.d.ts +2 -0
  73. package/dist/internal/registry-context.js +11 -9
  74. package/dist/internal/routes/activation-page.js +44 -20
  75. package/dist/internal/routes/console-home-page.d.ts +5 -0
  76. package/dist/internal/routes/console-home-page.js +18 -0
  77. package/dist/internal/routes/experience-connect-page.d.ts +6 -0
  78. package/dist/internal/routes/experience-connect-page.js +127 -0
  79. package/dist/internal/routes/experience-layout-page.d.ts +8 -0
  80. package/dist/internal/routes/experience-layout-page.js +126 -0
  81. package/dist/internal/routes/experience-page-host.d.ts +7 -0
  82. package/dist/internal/routes/experience-page-host.js +79 -0
  83. package/dist/internal/routes/experience-review-queue-page.d.ts +2 -0
  84. package/dist/internal/routes/experience-review-queue-page.js +60 -0
  85. package/dist/internal/routes/experience-runs-page.d.ts +1 -0
  86. package/dist/internal/routes/experience-runs-page.js +13 -0
  87. package/dist/internal/routes/experience-summary-page.d.ts +1 -0
  88. package/dist/internal/routes/experience-summary-page.js +101 -0
  89. package/dist/internal/routes/experience-widget-page.d.ts +1 -0
  90. package/dist/internal/routes/experience-widget-page.js +26 -0
  91. package/dist/internal/routes/experience-widgets-page.d.ts +6 -0
  92. package/dist/internal/routes/experience-widgets-page.js +22 -0
  93. package/dist/internal/routes/experience-workflow-page.d.ts +1 -0
  94. package/dist/internal/routes/experience-workflow-page.js +24 -0
  95. package/dist/internal/routes/experience-workflows-page.d.ts +1 -0
  96. package/dist/internal/routes/experience-workflows-page.js +44 -0
  97. package/dist/internal/routes/index-page.d.ts +10 -9
  98. package/dist/internal/routes/index-page.js +3 -68
  99. package/dist/internal/routes/integration-layout.d.ts +12 -1
  100. package/dist/internal/routes/integration-layout.js +20 -6
  101. package/dist/internal/routes/integrations-connect-page.d.ts +1 -0
  102. package/dist/internal/routes/integrations-connect-page.js +19 -0
  103. package/dist/internal/routes/integrations-events-page.d.ts +1 -0
  104. package/dist/internal/routes/integrations-events-page.js +10 -0
  105. package/dist/internal/routes/integrations-health-page.d.ts +1 -0
  106. package/dist/internal/routes/integrations-health-page.js +10 -0
  107. package/dist/internal/routes/integrations-layout.d.ts +17 -0
  108. package/dist/internal/routes/integrations-layout.js +106 -0
  109. package/dist/internal/routes/integrations-list-page.d.ts +2 -0
  110. package/dist/internal/routes/integrations-list-page.js +94 -0
  111. package/dist/internal/routes/integrations-operation-page.d.ts +1 -0
  112. package/dist/internal/routes/integrations-operation-page.js +29 -0
  113. package/dist/internal/routes/integrations-operations-page.d.ts +1 -0
  114. package/dist/internal/routes/integrations-operations-page.js +61 -0
  115. package/dist/internal/routes/integrations-overview-page.d.ts +1 -0
  116. package/dist/internal/routes/integrations-overview-page.js +90 -0
  117. package/dist/internal/routes/integrations-runs-page.d.ts +1 -0
  118. package/dist/internal/routes/integrations-runs-page.js +14 -0
  119. package/dist/internal/routes/integrations-scope.d.ts +12 -0
  120. package/dist/internal/routes/integrations-scope.js +39 -0
  121. package/dist/internal/routes/legacy-preview-redirect.d.ts +6 -0
  122. package/dist/internal/routes/legacy-preview-redirect.js +12 -0
  123. package/dist/internal/routes/preview-index-page.d.ts +2 -0
  124. package/dist/internal/routes/preview-index-page.js +14 -0
  125. package/dist/internal/routes/repo-connections-page.d.ts +6 -0
  126. package/dist/internal/routes/repo-connections-page.js +8 -0
  127. package/dist/internal/routes/repo-home-page.d.ts +2 -0
  128. package/dist/internal/routes/repo-home-page.js +320 -0
  129. package/dist/internal/routes/repo-layout.d.ts +7 -0
  130. package/dist/internal/routes/repo-layout.js +76 -0
  131. package/dist/internal/routes/repo-package-layouts.d.ts +20 -0
  132. package/dist/internal/routes/repo-package-layouts.js +104 -0
  133. package/dist/internal/routes/root-layout.d.ts +3 -1
  134. package/dist/internal/routes/root-layout.js +13 -3
  135. package/dist/internal/routes/single-widget-page.js +5 -12
  136. package/dist/internal/routes/tile-page.js +20 -41
  137. package/dist/internal/routes/triggers-page.js +55 -62
  138. package/dist/internal/routes/widgets-page.js +1 -1
  139. package/dist/internal/server/api-router.js +46 -4
  140. package/dist/internal/server/approvals.d.ts +44 -0
  141. package/dist/internal/server/approvals.js +76 -0
  142. package/dist/internal/server/contract-sources.d.ts +28 -0
  143. package/dist/internal/server/contract-sources.js +83 -0
  144. package/dist/internal/server/definition-loader.d.ts +22 -0
  145. package/dist/internal/server/definition-loader.js +125 -0
  146. package/dist/internal/server/ekanos-api-router.d.ts +34 -0
  147. package/dist/internal/server/ekanos-api-router.js +835 -0
  148. package/dist/internal/server/experience-loader.d.ts +57 -0
  149. package/dist/internal/server/experience-loader.js +146 -0
  150. package/dist/internal/server/integration-lookup.d.ts +29 -0
  151. package/dist/internal/server/integration-lookup.js +33 -0
  152. package/dist/internal/server/integration-resolver.d.ts +121 -0
  153. package/dist/internal/server/integration-resolver.js +605 -0
  154. package/dist/internal/server/live-invoker.d.ts +11 -0
  155. package/dist/internal/server/live-invoker.js +106 -0
  156. package/dist/internal/server/local-secrets.d.ts +82 -1
  157. package/dist/internal/server/local-secrets.js +112 -1
  158. package/dist/internal/server/local-state.d.ts +12 -0
  159. package/dist/internal/server/local-state.js +45 -0
  160. package/dist/internal/server/oauth-persistence.d.ts +19 -0
  161. package/dist/internal/server/oauth-persistence.js +76 -0
  162. package/dist/internal/server/operation-runner.d.ts +95 -0
  163. package/dist/internal/server/operation-runner.js +231 -0
  164. package/dist/internal/server/project-manifest.d.ts +71 -0
  165. package/dist/internal/server/project-manifest.js +215 -0
  166. package/dist/internal/server/registry-cache.d.ts +68 -0
  167. package/dist/internal/server/registry-cache.js +328 -0
  168. package/dist/internal/server/repo-api-router.d.ts +33 -0
  169. package/dist/internal/server/repo-api-router.js +391 -0
  170. package/dist/internal/server/run-log.d.ts +22 -0
  171. package/dist/internal/server/run-log.js +32 -0
  172. package/dist/internal/server/semantics.d.ts +28 -0
  173. package/dist/internal/server/semantics.js +67 -0
  174. package/dist/internal/server/session-catalog.d.ts +67 -0
  175. package/dist/internal/server/session-catalog.js +18 -0
  176. package/dist/internal/server/workflow-runner.d.ts +36 -0
  177. package/dist/internal/server/workflow-runner.js +183 -0
  178. package/dist/registry.d.ts +7 -0
  179. package/dist/resolver.d.ts +145 -0
  180. package/dist/resolver.js +211 -0
  181. package/dist/routes.d.ts +66 -2
  182. package/dist/routes.js +61 -3
  183. package/dist/runtime.d.ts +46 -0
  184. package/dist/runtime.js +60 -0
  185. package/package.json +23 -9
  186. package/dist/internal/routes/integration-index-page.d.ts +0 -13
  187. package/dist/internal/routes/integration-index-page.js +0 -17
@@ -0,0 +1,55 @@
1
+ import type { IntegrationRuntime, RepoDisconnectResponse, RepoResponse } from '../../api-types.js';
2
+ import type { ApprovalDecision, ConnectionState, ConsoleContract, ConsoleProject, EmitEventRequest, EmitEventResponse, ExperienceInfo, HealthResult, PendingApproval, RunRecord, RunRequest, RunResponse, WorkflowRunState } from './console-types.js';
3
+ export declare const CONSOLE_API_BASE = "/__ekanos/api";
4
+ /**
5
+ * The console's whole view of the harness server. Components depend on this
6
+ * interface, never on `fetch`, so tests inject a fake and the wire shape lives
7
+ * in exactly one place: the adapter at the bottom of this file.
8
+ */
9
+ export interface ConsoleClient {
10
+ getProject(): Promise<ConsoleProject>;
11
+ getContract(integration: string): Promise<ConsoleContract>;
12
+ /** A write on the http channel resolves only after the tray decides it. */
13
+ runOperation(request: RunRequest): Promise<RunResponse>;
14
+ listRuns(): Promise<RunRecord[]>;
15
+ listApprovals(): Promise<PendingApproval[]>;
16
+ decideApproval(id: string, decision: ApprovalDecision): Promise<void>;
17
+ getConnection(integration: string): Promise<ConnectionState>;
18
+ saveSecrets(integration: string, values: Record<string, string>): Promise<void>;
19
+ /**
20
+ * Store what the integration's activation form submitted, as this
21
+ * integration's local credentials. Replaces what was stored before.
22
+ */
23
+ saveActivation(integration: string, activationData: Record<string, unknown>): Promise<void>;
24
+ /**
25
+ * Remove this integration's stored local credentials, from its own package
26
+ * store only. `clearKeys` also blanks the declared keys (an API-key
27
+ * integration); an OAuth integration keeps its app keys.
28
+ */
29
+ disconnect(integration: string, clearKeys: boolean): Promise<void>;
30
+ /** `fixtures` forces this integration to fixtures; `auto` follows its connection. */
31
+ setRuntimeMode(integration: string, mode: 'auto' | 'fixtures'): Promise<IntegrationRuntime>;
32
+ emitEvent(request: EmitEventRequest): Promise<EmitEventResponse>;
33
+ runHealth(integration: string): Promise<HealthResult>;
34
+ /** Null when the server does not describe the experience (integration repo). */
35
+ getExperience(): Promise<ExperienceInfo | null>;
36
+ /** Resolves when the run finishes; its approvals are decided in the tray. */
37
+ startWorkflow(id: string): Promise<WorkflowRunState>;
38
+ }
39
+ export declare class ConsoleApiError extends Error {
40
+ readonly status: number;
41
+ constructor(message: string, status: number);
42
+ }
43
+ /** `sanity@0.2/tool/create_draft` and `tool/create_draft` both become the latter. */
44
+ export declare function relativeOpKey(id: string): string;
45
+ export declare function createHttpConsoleClient(fetcher?: typeof fetch, base?: string): ConsoleClient;
46
+ /** Where a package's own harness API is served in a repo shell. */
47
+ export declare function packageApiBase(kind: 'integration' | 'experience', name: string): string;
48
+ /** What the repo home and Connections page need from the repo-root server. */
49
+ export interface RepoClient {
50
+ getRepo(): Promise<RepoResponse>;
51
+ /** Removes the stored keys, or the held OAuth token; never the app keys. */
52
+ disconnect(integration: string): Promise<RepoDisconnectResponse>;
53
+ runHealth(integration: string): Promise<HealthResult>;
54
+ }
55
+ export declare function createHttpRepoClient(fetcher?: typeof fetch): RepoClient;
@@ -0,0 +1,295 @@
1
+ const CONSOLE_API_BASE = "/__ekanos/api";
2
+ class ConsoleApiError extends Error {
3
+ constructor(message, status) {
4
+ super(message);
5
+ this.status = status;
6
+ this.name = "ConsoleApiError";
7
+ }
8
+ }
9
+ function provenance(wire) {
10
+ return wire.kind === "local" ? wire : { ...wire, ...wire.stale ? { stale: true } : { stale: false } };
11
+ }
12
+ function relativeOpKey(id) {
13
+ const at = id.indexOf("/");
14
+ return id.includes("@") && at !== -1 ? id.slice(at + 1) : id;
15
+ }
16
+ function integrationView(wire) {
17
+ const canLive = wire.runModes.includes("live");
18
+ return {
19
+ integration: wire.integration,
20
+ version: wire.version,
21
+ operations: wire.operations.map(relativeOpKey),
22
+ runModes: wire.runModes,
23
+ defaultMode: wire.defaultMode,
24
+ ...canLive ? {} : {
25
+ fixturesOnlyReason: wire.canDevelop === false ? "You hold use only on this integration, so it answers from fixtures." : "This integration answers from fixtures."
26
+ },
27
+ provenance: provenance(wire.provenance),
28
+ ...wire.self ? { own: true } : {},
29
+ bindingMode: wire.bindingMode,
30
+ ...wire.runtime ? { runtime: wire.runtime } : {}
31
+ };
32
+ }
33
+ function contractView(wire) {
34
+ const { contract } = wire;
35
+ return {
36
+ integration: contract.integration,
37
+ version: contract.compatLine,
38
+ contractVersion: contract.contractVersion,
39
+ digest: contract.digest,
40
+ connection: contract.connection,
41
+ operations: contract.operations,
42
+ events: contract.events.map((event) => ({
43
+ name: event.name,
44
+ payloadSchema: event.payload,
45
+ ...event.payloadExample === void 0 ? {} : { payloadExample: event.payloadExample }
46
+ })),
47
+ usedBy: Object.fromEntries(
48
+ Object.entries(wire.usedBy).map(([id, uses]) => [
49
+ relativeOpKey(id),
50
+ uses.map((use) => ({
51
+ kind: use.kind,
52
+ id: use.id,
53
+ title: use.id
54
+ }))
55
+ ])
56
+ )
57
+ };
58
+ }
59
+ function pendingApproval(approval) {
60
+ if (approval.kind === "operation") {
61
+ return {
62
+ id: approval.id,
63
+ createdAt: approval.createdAt,
64
+ integration: approval.integration,
65
+ opKey: approval.opKey,
66
+ channel: approval.channel,
67
+ mode: approval.mode,
68
+ argsHash: approval.argsHash,
69
+ args: approval.args
70
+ };
71
+ }
72
+ return {
73
+ id: approval.id,
74
+ createdAt: approval.createdAt,
75
+ integration: approval.workflowId,
76
+ opKey: `approval_gate/${approval.stepId}`,
77
+ channel: "workflow",
78
+ mode: "fixtures",
79
+ argsHash: "-",
80
+ args: { summary: approval.summary }
81
+ };
82
+ }
83
+ function runView(wire) {
84
+ const { provenance: prov, ...rest } = wire;
85
+ return { ...rest, provenance: prov ? prov.kind : null };
86
+ }
87
+ const STEP_STATUS = {
88
+ ok: "done",
89
+ refused: "failed",
90
+ rejected: "rejected",
91
+ "not-simulated": "not_simulated",
92
+ error: "failed"
93
+ };
94
+ function workflowView(wire) {
95
+ return {
96
+ workflowId: wire.workflowId,
97
+ completed: wire.completed,
98
+ steps: wire.steps.map((step) => ({
99
+ id: step.id,
100
+ status: STEP_STATUS[step.status],
101
+ ...step.detail === void 0 ? {} : { detail: step.detail },
102
+ ...step.output === void 0 ? {} : { output: step.output }
103
+ }))
104
+ };
105
+ }
106
+ const HEALTH = {
107
+ healthy: "healthy",
108
+ degraded: "degraded",
109
+ unhealthy: "unhealthy",
110
+ unknown: "unknown"
111
+ };
112
+ async function request(fetcher, path, init, base = CONSOLE_API_BASE) {
113
+ const response = await fetcher(`${base}${path}`, {
114
+ method: init?.method ?? "GET",
115
+ headers: init?.body === void 0 ? {} : { "content-type": "application/json" },
116
+ body: init?.body === void 0 ? null : JSON.stringify(init.body)
117
+ });
118
+ if (!response.ok) {
119
+ const text = await response.text();
120
+ throw new ConsoleApiError(
121
+ text || `${path} failed with ${response.status}`,
122
+ response.status
123
+ );
124
+ }
125
+ const parsed = await response.json();
126
+ return parsed;
127
+ }
128
+ const enc = encodeURIComponent;
129
+ function createHttpConsoleClient(fetcher = (input, init) => globalThis.fetch(input, init), base = CONSOLE_API_BASE) {
130
+ const get = (path) => request(fetcher, path, void 0, base);
131
+ const post = (path, body) => request(fetcher, path, { method: "POST", body: body ?? {} }, base);
132
+ return {
133
+ getProject: async () => {
134
+ const wire = await get("/integrations");
135
+ const experience = wire.kind === "experience" ? await getExperience() : null;
136
+ return {
137
+ kind: wire.kind,
138
+ name: experience?.name ?? (wire.kind === "integration" ? wire.integrations[0]?.integration ?? "integration" : "experience"),
139
+ integrations: wire.integrations.map(integrationView),
140
+ notices: wire.notices,
141
+ errors: wire.errors,
142
+ ...experience?.checks ? { checks: experience.checks } : {}
143
+ };
144
+ },
145
+ getContract: async (integration) => contractView(
146
+ await get(`/contract/${enc(integration)}`)
147
+ ),
148
+ runOperation: async (req) => {
149
+ const wire = await post("/ops/run", {
150
+ integration: req.integration,
151
+ op: req.opKey,
152
+ input: req.args,
153
+ channel: req.channel ?? "http",
154
+ mode: req.mode,
155
+ ...req.variant ? { scenario: req.variant } : {},
156
+ origin: req.origin ?? "console"
157
+ });
158
+ const approval = wire.approvalId ? { approvalId: wire.approvalId } : {};
159
+ return wire.result.ok ? {
160
+ status: "ok",
161
+ output: wire.result.data,
162
+ runId: wire.runId,
163
+ ...approval
164
+ } : {
165
+ status: "refused",
166
+ reason: wire.result.reason,
167
+ message: wire.result.message,
168
+ runId: wire.runId,
169
+ ...approval
170
+ };
171
+ },
172
+ listRuns: async () => (await get("/runs")).runs.map(runView),
173
+ listApprovals: async () => (await get("/approvals")).approvals.filter((approval) => approval.status === "pending").map(pendingApproval),
174
+ decideApproval: async (id, decision) => {
175
+ await post(`/approvals/${enc(id)}`, { decision });
176
+ },
177
+ getConnection: async (integration) => {
178
+ const wire = await get(
179
+ `/credentials/${enc(integration)}`
180
+ );
181
+ return {
182
+ managed: !wire.manageable,
183
+ root: wire.root,
184
+ fields: wire.declared.map((key) => ({
185
+ key,
186
+ label: key,
187
+ secret: true,
188
+ set: wire.set.includes(key)
189
+ })),
190
+ target: wire.target,
191
+ hasStored: wire.set.length > 0 || wire.activationFieldsSet.length > 0,
192
+ ...wire.displayRoot ? { displayRoot: wire.displayRoot } : {},
193
+ facts: wire.facts
194
+ };
195
+ },
196
+ disconnect: async (integration, clearKeys) => {
197
+ await request(
198
+ fetcher,
199
+ `/credentials/${enc(integration)}/disconnect`,
200
+ { method: "POST", body: { clearKeys } },
201
+ base
202
+ );
203
+ },
204
+ // Rooted at the INTEGRATION's project (a local override's own repo), so a
205
+ // key saved here also serves that repo's console. Names are validated
206
+ // against the definition server-side; values never come back.
207
+ saveSecrets: async (integration, values) => {
208
+ await request(
209
+ fetcher,
210
+ `/credentials/${enc(integration)}`,
211
+ { method: "PUT", body: { values } },
212
+ base
213
+ );
214
+ },
215
+ saveActivation: async (integration, activationData) => {
216
+ await request(
217
+ fetcher,
218
+ `/credentials/${enc(integration)}/activation`,
219
+ { method: "PUT", body: { activationData } },
220
+ base
221
+ );
222
+ },
223
+ setRuntimeMode: (integration, mode) => request(
224
+ fetcher,
225
+ `/integrations/${enc(integration)}/mode`,
226
+ { method: "PUT", body: { mode } },
227
+ base
228
+ ),
229
+ emitEvent: async (req) => {
230
+ const wire = await post("/events/emit", req);
231
+ return {
232
+ valid: wire.valid,
233
+ issues: wire.errors.map((message) => ({ path: "", message })),
234
+ outcome: wire.outcome,
235
+ ...wire.detail === void 0 ? {} : { detail: JSON.stringify(wire.detail, null, 2) },
236
+ matchedTriggers: wire.matchingWorkflows
237
+ };
238
+ },
239
+ runHealth: async (integration) => {
240
+ const wire = await post(`/health/${enc(integration)}`);
241
+ return {
242
+ status: wire.status ? HEALTH[wire.status] : "unknown",
243
+ ...wire.detail ? { message: wire.detail } : {}
244
+ };
245
+ },
246
+ getExperience,
247
+ startWorkflow: async (id) => workflowView(await post(`/workflows/${enc(id)}/run`))
248
+ };
249
+ async function getExperience() {
250
+ try {
251
+ return await get("/experience");
252
+ } catch (error) {
253
+ if (error instanceof ConsoleApiError && error.status === 404) {
254
+ console.warn(
255
+ "[harness] GET /__ekanos/api/experience is not served: workflow templates and the review queue will be empty."
256
+ );
257
+ return null;
258
+ }
259
+ throw error;
260
+ }
261
+ }
262
+ }
263
+ function packageApiBase(kind, name) {
264
+ return `${CONSOLE_API_BASE}/packages/${kind === "integration" ? "integrations" : "experiences"}/${enc(name)}`;
265
+ }
266
+ function createHttpRepoClient(fetcher = (input, init) => globalThis.fetch(input, init)) {
267
+ return {
268
+ getRepo: () => request(fetcher, "/repo"),
269
+ disconnect: (integration) => request(
270
+ fetcher,
271
+ `/repo/connections/${enc(integration)}/disconnect`,
272
+ { method: "POST", body: {} }
273
+ ),
274
+ runHealth: async (integration) => {
275
+ const wire = await request(
276
+ fetcher,
277
+ `/health/${enc(integration)}`,
278
+ { method: "POST", body: {} },
279
+ packageApiBase("integration", integration)
280
+ );
281
+ return {
282
+ status: wire.status ? HEALTH[wire.status] : "unknown",
283
+ ...wire.detail ? { message: wire.detail } : {}
284
+ };
285
+ }
286
+ };
287
+ }
288
+ export {
289
+ CONSOLE_API_BASE,
290
+ ConsoleApiError,
291
+ createHttpConsoleClient,
292
+ createHttpRepoClient,
293
+ packageApiBase,
294
+ relativeOpKey
295
+ };
@@ -0,0 +1,56 @@
1
+ import { type ComponentType, type ReactNode } from 'react';
2
+ import type { SuggestedLayout } from '@ekanos/sdk/experience';
3
+ import { QueryClient } from '@tanstack/react-query';
4
+ import type { HarnessWidget } from '../../registry.js';
5
+ import { type ConsoleClient } from './console-client.js';
6
+ /** What the experience repo's entry contributes beyond the server's JSON. */
7
+ export interface ExperienceSurfacePage {
8
+ id: string;
9
+ title: string;
10
+ /** Absent on a definition from before page kinds: a custom page. */
11
+ kind?: 'overview' | 'canvas' | 'custom';
12
+ path?: string;
13
+ /** Canvas pages: ids of the experience's own widgets. */
14
+ widgets?: readonly string[];
15
+ /** Custom pages: the sub-routes the component handles. */
16
+ routes?: ReadonlyArray<{
17
+ path: string;
18
+ title: string;
19
+ }>;
20
+ /** Absent on a canvas, and on an overview that uses the host's default. */
21
+ component?: ComponentType<{
22
+ path: string[];
23
+ }>;
24
+ }
25
+ export interface ExperienceSurfaces {
26
+ widgets: HarnessWidget[];
27
+ pages: ExperienceSurfacePage[];
28
+ suggestedLayout?: SuggestedLayout;
29
+ }
30
+ /**
31
+ * Where the console's links point. A single project mounts the Experience
32
+ * view at `/experience`; a repo mounts one per experience package at
33
+ * `/experiences/<name>` and offers a way back to the repo home.
34
+ */
35
+ export interface ConsoleLinks {
36
+ experience: string;
37
+ /** Set in a repo shell: the way back to "This repo". */
38
+ repoHome: string | null;
39
+ }
40
+ export declare function useConsoleLinks(): ConsoleLinks;
41
+ export declare function ConsoleProviders({ client, queryClient, experience, links, pollMs, apiBase, children, }: {
42
+ /** Where this console's API is served (a repo shell: one package's router). */
43
+ apiBase?: string;
44
+ links?: ConsoleLinks;
45
+ client?: ConsoleClient;
46
+ queryClient?: QueryClient;
47
+ experience?: ExperienceSurfaces;
48
+ /** How often the run log and approvals tray refetch. */
49
+ pollMs?: number;
50
+ children: ReactNode;
51
+ }): import("react").JSX.Element;
52
+ export declare function useConsoleClient(): ConsoleClient;
53
+ /** The console client, or null outside `ConsoleProviders` (a legacy surface). */
54
+ export declare function useOptionalConsoleClient(): ConsoleClient | null;
55
+ export declare function useExperienceSurfaces(): ExperienceSurfaces;
56
+ export declare function usePollMs(): number;
@@ -0,0 +1,67 @@
1
+ "use client";
2
+ import { jsx } from "react/jsx-runtime";
3
+ import {
4
+ createContext,
5
+ use,
6
+ useState
7
+ } from "react";
8
+ import { ExperienceRuntimeProvider } from "@ekanos/sdk/experience/client";
9
+ import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
10
+ import { createHttpConsoleClient } from "./console-client.js";
11
+ import { createExperienceRuntime } from "./experience-runtime.js";
12
+ const EMPTY_SURFACES = { widgets: [], pages: [] };
13
+ const DEFAULT_LINKS = {
14
+ experience: "/experience",
15
+ repoHome: null
16
+ };
17
+ const LinksContext = createContext(DEFAULT_LINKS);
18
+ function useConsoleLinks() {
19
+ return use(LinksContext);
20
+ }
21
+ const ClientContext = createContext(null);
22
+ const SurfacesContext = createContext(EMPTY_SURFACES);
23
+ const PollContext = createContext(1e3);
24
+ function ConsoleProviders({
25
+ client,
26
+ queryClient,
27
+ experience = EMPTY_SURFACES,
28
+ links = DEFAULT_LINKS,
29
+ pollMs = 1e3,
30
+ apiBase,
31
+ children
32
+ }) {
33
+ const [defaults] = useState(() => ({
34
+ client: createHttpConsoleClient(),
35
+ runtime: createExperienceRuntime(apiBase),
36
+ queryClient: new QueryClient({
37
+ defaultOptions: { queries: { retry: false, staleTime: 2e3 } }
38
+ })
39
+ }));
40
+ return /* @__PURE__ */ jsx(QueryClientProvider, { client: queryClient ?? defaults.queryClient, children: /* @__PURE__ */ jsx(ClientContext, { value: client ?? defaults.client, children: /* @__PURE__ */ jsx(LinksContext, { value: links, children: /* @__PURE__ */ jsx(PollContext, { value: pollMs, children: /* @__PURE__ */ jsx(SurfacesContext, { value: experience, children: /* @__PURE__ */ jsx(ExperienceRuntimeProvider, { runtime: defaults.runtime, children }) }) }) }) }) });
41
+ }
42
+ function useConsoleClient() {
43
+ const client = use(ClientContext);
44
+ if (!client) {
45
+ throw new Error(
46
+ "useConsoleClient() was called outside ConsoleProviders. Mount the console routes under ConsoleLayout."
47
+ );
48
+ }
49
+ return client;
50
+ }
51
+ function useOptionalConsoleClient() {
52
+ return use(ClientContext);
53
+ }
54
+ function useExperienceSurfaces() {
55
+ return use(SurfacesContext);
56
+ }
57
+ function usePollMs() {
58
+ return use(PollContext);
59
+ }
60
+ export {
61
+ ConsoleProviders,
62
+ useConsoleClient,
63
+ useConsoleLinks,
64
+ useExperienceSurfaces,
65
+ useOptionalConsoleClient,
66
+ usePollMs
67
+ };
@@ -0,0 +1,33 @@
1
+ import { type QueryClient } from '@tanstack/react-query';
2
+ import type { ConsoleClient } from './console-client.js';
3
+ import type { ApprovalDecision, RunRequest } from './console-types.js';
4
+ export declare const consoleKeys: {
5
+ project: readonly ['console', 'project'];
6
+ contract: (integration: string) => readonly ['console', 'contract', string];
7
+ runs: readonly ['console', 'runs'];
8
+ approvals: readonly ['console', 'approvals'];
9
+ connection: (integration: string) => readonly ['console', 'connection', string];
10
+ experience: readonly ['console', 'experience'];
11
+ /** Every `useOperation` read an experience widget made (the SDK's own key root). */
12
+ operations: readonly ['ekanos-operation'];
13
+ };
14
+ /**
15
+ * Something about how an integration answers changed (connected, edited,
16
+ * disconnected, forced): refetch the project (so the strip's chip follows) and
17
+ * every operation read, so widgets made under the old mode run again.
18
+ */
19
+ export declare function refreshRuntime(queryClient: QueryClient): Promise<[void, void]>;
20
+ export declare function useRefreshRuntime(): () => Promise<[void, void]>;
21
+ export declare function useProject(): import("@tanstack/react-query").UseQueryResult<import("./console-types.js").ConsoleProject, Error>;
22
+ export declare function useContract(integration: string): import("@tanstack/react-query").UseQueryResult<import("./console-types.js").ConsoleContract, Error>;
23
+ /** The run log polls: every surface appends to it, not just this tab. */
24
+ export declare function useRuns(): import("@tanstack/react-query").UseQueryResult<import("./console-types.js").RunRecord[], Error>;
25
+ export declare function useApprovals(): import("@tanstack/react-query").UseQueryResult<import("./console-types.js").PendingApproval[], Error>;
26
+ export declare function useRunOperation(): import("@tanstack/react-query").UseMutationResult<import("./console-types.js").RunResponse, Error, RunRequest, unknown>;
27
+ export declare function useDecideApproval(): import("@tanstack/react-query").UseMutationResult<void, Error, {
28
+ id: string;
29
+ decision: ApprovalDecision;
30
+ }, unknown>;
31
+ export declare function useConnection(integration: string): import("@tanstack/react-query").UseQueryResult<import("./console-types.js").ConnectionState, Error>;
32
+ export declare function useExperience(): import("@tanstack/react-query").UseQueryResult<import("./console-types.js").ExperienceInfo | null, Error>;
33
+ export declare function useConsoleMutation<TInput, TOutput>(run: (client: ConsoleClient, input: TInput) => Promise<TOutput>): import("@tanstack/react-query").UseMutationResult<TOutput, Error, TInput, unknown>;
@@ -0,0 +1,118 @@
1
+ "use client";
2
+ import {
3
+ useMutation,
4
+ useQuery,
5
+ useQueryClient
6
+ } from "@tanstack/react-query";
7
+ import { useConsoleClient, usePollMs } from "./console-context.js";
8
+ const consoleKeys = {
9
+ project: ["console", "project"],
10
+ contract: (integration) => ["console", "contract", integration],
11
+ runs: ["console", "runs"],
12
+ approvals: ["console", "approvals"],
13
+ connection: (integration) => ["console", "connection", integration],
14
+ experience: ["console", "experience"],
15
+ /** Every `useOperation` read an experience widget made (the SDK's own key root). */
16
+ operations: ["ekanos-operation"]
17
+ };
18
+ function refreshRuntime(queryClient) {
19
+ return Promise.all([
20
+ queryClient.invalidateQueries({ queryKey: consoleKeys.project }),
21
+ queryClient.invalidateQueries({ queryKey: consoleKeys.operations })
22
+ ]);
23
+ }
24
+ function useRefreshRuntime() {
25
+ const queryClient = useQueryClient();
26
+ return () => refreshRuntime(queryClient);
27
+ }
28
+ function useProject() {
29
+ const client = useConsoleClient();
30
+ return useQuery({
31
+ queryKey: consoleKeys.project,
32
+ queryFn: () => client.getProject()
33
+ });
34
+ }
35
+ function useContract(integration) {
36
+ const client = useConsoleClient();
37
+ return useQuery({
38
+ queryKey: consoleKeys.contract(integration),
39
+ queryFn: () => client.getContract(integration)
40
+ });
41
+ }
42
+ function useRuns() {
43
+ const client = useConsoleClient();
44
+ const pollMs = usePollMs();
45
+ return useQuery({
46
+ queryKey: consoleKeys.runs,
47
+ queryFn: () => client.listRuns(),
48
+ refetchInterval: pollMs
49
+ });
50
+ }
51
+ function useApprovals() {
52
+ const client = useConsoleClient();
53
+ const pollMs = usePollMs();
54
+ return useQuery({
55
+ queryKey: consoleKeys.approvals,
56
+ queryFn: () => client.listApprovals(),
57
+ refetchInterval: pollMs
58
+ });
59
+ }
60
+ function useInvalidateActivity() {
61
+ const queryClient = useQueryClient();
62
+ return () => Promise.all([
63
+ queryClient.invalidateQueries({ queryKey: consoleKeys.runs }),
64
+ queryClient.invalidateQueries({ queryKey: consoleKeys.approvals })
65
+ ]);
66
+ }
67
+ function useRunOperation() {
68
+ const client = useConsoleClient();
69
+ const invalidate = useInvalidateActivity();
70
+ return useMutation({
71
+ mutationFn: (request) => client.runOperation(request),
72
+ onSettled: invalidate
73
+ });
74
+ }
75
+ function useDecideApproval() {
76
+ const client = useConsoleClient();
77
+ const invalidate = useInvalidateActivity();
78
+ return useMutation({
79
+ mutationFn: (input) => client.decideApproval(input.id, input.decision),
80
+ onSettled: invalidate
81
+ });
82
+ }
83
+ function useConnection(integration) {
84
+ const client = useConsoleClient();
85
+ return useQuery({
86
+ queryKey: consoleKeys.connection(integration),
87
+ queryFn: () => client.getConnection(integration)
88
+ });
89
+ }
90
+ function useExperience() {
91
+ const client = useConsoleClient();
92
+ return useQuery({
93
+ queryKey: consoleKeys.experience,
94
+ queryFn: () => client.getExperience()
95
+ });
96
+ }
97
+ function useConsoleMutation(run) {
98
+ const client = useConsoleClient();
99
+ const invalidate = useInvalidateActivity();
100
+ return useMutation({
101
+ mutationFn: (input) => run(client, input),
102
+ onSettled: invalidate
103
+ });
104
+ }
105
+ export {
106
+ consoleKeys,
107
+ refreshRuntime,
108
+ useApprovals,
109
+ useConnection,
110
+ useConsoleMutation,
111
+ useContract,
112
+ useDecideApproval,
113
+ useExperience,
114
+ useProject,
115
+ useRefreshRuntime,
116
+ useRunOperation,
117
+ useRuns
118
+ };