@contractspec/example.integration-hub 3.8.9 → 3.8.10

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 (89) hide show
  1. package/dist/connection/connection.enum.js +1 -29
  2. package/dist/connection/connection.operation.js +1 -124
  3. package/dist/connection/connection.presentation.js +1 -125
  4. package/dist/connection/connection.schema.js +1 -71
  5. package/dist/connection/index.js +1 -127
  6. package/dist/docs/index.js +5 -49
  7. package/dist/docs/integration-hub.docblock.js +5 -49
  8. package/dist/events.js +1 -211
  9. package/dist/example.js +1 -42
  10. package/dist/handlers/index.js +5 -292
  11. package/dist/handlers/integration.handlers.js +5 -292
  12. package/dist/index.js +8 -2355
  13. package/dist/integration/index.js +1 -92
  14. package/dist/integration/integration.enum.js +1 -12
  15. package/dist/integration/integration.operations.js +1 -89
  16. package/dist/integration/integration.presentation.js +1 -120
  17. package/dist/integration/integration.schema.js +1 -42
  18. package/dist/integration-hub.capability.js +1 -43
  19. package/dist/integration-hub.feature.js +1 -330
  20. package/dist/mcp-example.js +1 -154
  21. package/dist/node/connection/connection.enum.js +1 -29
  22. package/dist/node/connection/connection.operation.js +1 -124
  23. package/dist/node/connection/connection.presentation.js +1 -125
  24. package/dist/node/connection/connection.schema.js +1 -71
  25. package/dist/node/connection/index.js +1 -127
  26. package/dist/node/docs/index.js +5 -49
  27. package/dist/node/docs/integration-hub.docblock.js +5 -49
  28. package/dist/node/events.js +1 -211
  29. package/dist/node/example.js +1 -42
  30. package/dist/node/handlers/index.js +5 -292
  31. package/dist/node/handlers/integration.handlers.js +5 -292
  32. package/dist/node/index.js +8 -2355
  33. package/dist/node/integration/index.js +1 -92
  34. package/dist/node/integration/integration.enum.js +1 -12
  35. package/dist/node/integration/integration.operations.js +1 -89
  36. package/dist/node/integration/integration.presentation.js +1 -120
  37. package/dist/node/integration/integration.schema.js +1 -42
  38. package/dist/node/integration-hub.capability.js +1 -43
  39. package/dist/node/integration-hub.feature.js +1 -330
  40. package/dist/node/mcp-example.js +1 -154
  41. package/dist/node/run-mcp.js +1 -159
  42. package/dist/node/seeders/index.js +6 -60
  43. package/dist/node/sync/index.js +1 -332
  44. package/dist/node/sync/sync.enum.js +1 -26
  45. package/dist/node/sync/sync.operations.js +1 -321
  46. package/dist/node/sync/sync.presentation.js +1 -301
  47. package/dist/node/sync/sync.schema.js +1 -154
  48. package/dist/node/sync-engine/index.js +1 -186
  49. package/dist/node/tests/operations.test-spec.js +1 -85
  50. package/dist/node/ui/IntegrationDashboard.js +1 -886
  51. package/dist/node/ui/IntegrationDashboard.visualizations.js +1 -250
  52. package/dist/node/ui/IntegrationHubChat.js +1 -34
  53. package/dist/node/ui/hooks/index.js +1 -57
  54. package/dist/node/ui/hooks/useIntegrationData.js +1 -54
  55. package/dist/node/ui/index.js +4 -1173
  56. package/dist/node/ui/renderers/index.js +4 -484
  57. package/dist/node/ui/renderers/integration.markdown.js +4 -484
  58. package/dist/node/ui/tables/ConnectionsTable.js +1 -211
  59. package/dist/node/ui/tables/IntegrationTables.js +1 -361
  60. package/dist/node/ui/tables/SyncConfigsTable.js +1 -230
  61. package/dist/node/ui/tables/integration-table.shared.js +1 -84
  62. package/dist/node/visualizations/catalog.js +1 -137
  63. package/dist/node/visualizations/index.js +1 -211
  64. package/dist/node/visualizations/selectors.js +1 -204
  65. package/dist/run-mcp.js +1 -159
  66. package/dist/seeders/index.js +6 -60
  67. package/dist/sync/index.js +1 -332
  68. package/dist/sync/sync.enum.js +1 -26
  69. package/dist/sync/sync.operations.js +1 -321
  70. package/dist/sync/sync.presentation.js +1 -301
  71. package/dist/sync/sync.schema.js +1 -154
  72. package/dist/sync-engine/index.js +1 -186
  73. package/dist/tests/operations.test-spec.js +1 -85
  74. package/dist/ui/IntegrationDashboard.js +1 -886
  75. package/dist/ui/IntegrationDashboard.visualizations.js +1 -250
  76. package/dist/ui/IntegrationHubChat.js +1 -34
  77. package/dist/ui/hooks/index.js +1 -57
  78. package/dist/ui/hooks/useIntegrationData.js +1 -54
  79. package/dist/ui/index.js +4 -1173
  80. package/dist/ui/renderers/index.js +4 -484
  81. package/dist/ui/renderers/integration.markdown.js +4 -484
  82. package/dist/ui/tables/ConnectionsTable.js +1 -211
  83. package/dist/ui/tables/IntegrationTables.js +1 -361
  84. package/dist/ui/tables/SyncConfigsTable.js +1 -230
  85. package/dist/ui/tables/integration-table.shared.js +1 -84
  86. package/dist/visualizations/catalog.js +1 -137
  87. package/dist/visualizations/index.js +1 -211
  88. package/dist/visualizations/selectors.js +1 -204
  89. package/package.json +11 -11
@@ -1,887 +1,2 @@
1
1
  // @bun
2
- // src/ui/hooks/useIntegrationData.ts
3
- import { useTemplateRuntime } from "@contractspec/lib.example-shared-ui";
4
- import { useCallback, useEffect, useState } from "react";
5
- "use client";
6
- function useIntegrationData(projectId = "local-project") {
7
- const { handlers } = useTemplateRuntime();
8
- const integration = handlers.integration;
9
- const [integrations, setIntegrations] = useState([]);
10
- const [connections, setConnections] = useState([]);
11
- const [syncConfigs, setSyncConfigs] = useState([]);
12
- const [loading, setLoading] = useState(true);
13
- const [error, setError] = useState(null);
14
- const fetchData = useCallback(async () => {
15
- try {
16
- setLoading(true);
17
- setError(null);
18
- const [integResult, connResult, syncResult] = await Promise.all([
19
- integration.listIntegrations({ projectId, limit: 100 }),
20
- integration.listConnections({ limit: 100 }),
21
- integration.listSyncConfigs({ limit: 100 })
22
- ]);
23
- setIntegrations(integResult.integrations);
24
- setConnections(connResult.connections);
25
- setSyncConfigs(syncResult.configs);
26
- } catch (err) {
27
- setError(err instanceof Error ? err : new Error("Failed to load integrations"));
28
- } finally {
29
- setLoading(false);
30
- }
31
- }, [integration, projectId]);
32
- useEffect(() => {
33
- fetchData();
34
- }, [fetchData]);
35
- const stats = {
36
- totalIntegrations: integrations.length,
37
- activeIntegrations: integrations.filter((i) => i.status === "ACTIVE").length,
38
- totalConnections: connections.length,
39
- connectedCount: connections.filter((c) => c.status === "CONNECTED").length,
40
- totalSyncs: syncConfigs.length,
41
- activeSyncs: syncConfigs.filter((s) => s.status === "ACTIVE").length
42
- };
43
- return {
44
- integrations,
45
- connections,
46
- syncConfigs,
47
- loading,
48
- error,
49
- stats,
50
- refetch: fetchData
51
- };
52
- }
53
-
54
- // src/visualizations/catalog.ts
55
- import {
56
- defineVisualization,
57
- VisualizationRegistry
58
- } from "@contractspec/lib.contracts-spec/visualizations";
59
- var INTEGRATION_LIST_REF = {
60
- key: "integration.list",
61
- version: "1.0.0"
62
- };
63
- var CONNECTION_LIST_REF = {
64
- key: "integration.connection.list",
65
- version: "1.0.0"
66
- };
67
- var SYNC_CONFIG_REF = {
68
- key: "integration.syncConfig.list",
69
- version: "1.0.0"
70
- };
71
- var META = {
72
- version: "1.0.0",
73
- domain: "integration",
74
- stability: "experimental",
75
- owners: ["@example.integration-hub"],
76
- tags: ["integration", "visualization", "sync"]
77
- };
78
- var IntegrationTypeVisualization = defineVisualization({
79
- meta: {
80
- ...META,
81
- key: "integration-hub.visualization.integration-types",
82
- title: "Integration Types",
83
- description: "Distribution of configured integration categories.",
84
- goal: "Show where integration coverage is concentrated.",
85
- context: "Integration overview."
86
- },
87
- source: { primary: INTEGRATION_LIST_REF, resultPath: "data" },
88
- visualization: {
89
- kind: "pie",
90
- nameDimension: "type",
91
- valueMeasure: "count",
92
- dimensions: [
93
- { key: "type", label: "Type", dataPath: "type", type: "category" }
94
- ],
95
- measures: [
96
- { key: "count", label: "Count", dataPath: "count", format: "number" }
97
- ],
98
- table: { caption: "Integration counts by type." }
99
- }
100
- });
101
- var ConnectionStatusVisualization = defineVisualization({
102
- meta: {
103
- ...META,
104
- key: "integration-hub.visualization.connection-status",
105
- title: "Connection Status",
106
- description: "Status distribution across configured connections.",
107
- goal: "Highlight connection health and instability.",
108
- context: "Connection monitoring."
109
- },
110
- source: { primary: CONNECTION_LIST_REF, resultPath: "data" },
111
- visualization: {
112
- kind: "cartesian",
113
- variant: "bar",
114
- xDimension: "status",
115
- yMeasures: ["count"],
116
- dimensions: [
117
- { key: "status", label: "Status", dataPath: "status", type: "category" }
118
- ],
119
- measures: [
120
- {
121
- key: "count",
122
- label: "Connections",
123
- dataPath: "count",
124
- format: "number",
125
- color: "#1d4ed8"
126
- }
127
- ],
128
- table: { caption: "Connection counts by status." }
129
- }
130
- });
131
- var HealthySyncMetricVisualization = defineVisualization({
132
- meta: {
133
- ...META,
134
- key: "integration-hub.visualization.sync-healthy",
135
- title: "Healthy Syncs",
136
- description: "Sync configurations currently healthy or recently successful.",
137
- goal: "Summarize healthy synchronization capacity.",
138
- context: "Sync-state comparison."
139
- },
140
- source: { primary: SYNC_CONFIG_REF, resultPath: "data" },
141
- visualization: {
142
- kind: "metric",
143
- measure: "value",
144
- measures: [
145
- { key: "value", label: "Syncs", dataPath: "value", format: "number" }
146
- ],
147
- table: { caption: "Healthy sync count." }
148
- }
149
- });
150
- var AttentionSyncMetricVisualization = defineVisualization({
151
- meta: {
152
- ...META,
153
- key: "integration-hub.visualization.sync-attention",
154
- title: "Attention Needed",
155
- description: "Sync configurations paused, failing, or otherwise needing review.",
156
- goal: "Summarize syncs needing action.",
157
- context: "Sync-state comparison."
158
- },
159
- source: { primary: SYNC_CONFIG_REF, resultPath: "data" },
160
- visualization: {
161
- kind: "metric",
162
- measure: "value",
163
- measures: [
164
- { key: "value", label: "Syncs", dataPath: "value", format: "number" }
165
- ],
166
- table: { caption: "Syncs requiring attention." }
167
- }
168
- });
169
- var IntegrationVisualizationSpecs = [
170
- IntegrationTypeVisualization,
171
- ConnectionStatusVisualization,
172
- HealthySyncMetricVisualization,
173
- AttentionSyncMetricVisualization
174
- ];
175
- var IntegrationVisualizationRegistry = new VisualizationRegistry([
176
- ...IntegrationVisualizationSpecs
177
- ]);
178
- var IntegrationVisualizationRefs = IntegrationVisualizationSpecs.map((spec) => ({
179
- key: spec.meta.key,
180
- version: spec.meta.version
181
- }));
182
-
183
- // src/visualizations/selectors.ts
184
- function isHealthySync(status) {
185
- return status === "ACTIVE" || status === "SUCCESS";
186
- }
187
- function createIntegrationVisualizationSections(integrations, connections, syncConfigs) {
188
- const integrationTypes = new Map;
189
- const connectionStatuses = new Map;
190
- let healthySyncs = 0;
191
- let attentionSyncs = 0;
192
- for (const integration of integrations) {
193
- integrationTypes.set(integration.type, (integrationTypes.get(integration.type) ?? 0) + 1);
194
- }
195
- for (const connection of connections) {
196
- connectionStatuses.set(connection.status, (connectionStatuses.get(connection.status) ?? 0) + 1);
197
- }
198
- for (const syncConfig of syncConfigs) {
199
- if (isHealthySync(syncConfig.status)) {
200
- healthySyncs += 1;
201
- } else {
202
- attentionSyncs += 1;
203
- }
204
- }
205
- const primaryItems = [
206
- {
207
- key: "integration-types",
208
- spec: IntegrationTypeVisualization,
209
- data: {
210
- data: Array.from(integrationTypes.entries()).map(([type, count]) => ({
211
- type,
212
- count
213
- }))
214
- },
215
- title: "Integration Types",
216
- description: "Configured integrations grouped by category.",
217
- height: 260
218
- },
219
- {
220
- key: "connection-status",
221
- spec: ConnectionStatusVisualization,
222
- data: {
223
- data: Array.from(connectionStatuses.entries()).map(([status, count]) => ({
224
- status,
225
- count
226
- }))
227
- },
228
- title: "Connection Status",
229
- description: "Operational health across current connections."
230
- }
231
- ];
232
- const comparisonItems = [
233
- {
234
- key: "healthy-syncs",
235
- spec: HealthySyncMetricVisualization,
236
- data: { data: [{ value: healthySyncs }] },
237
- title: "Healthy Syncs",
238
- description: "Active or recently successful sync configurations.",
239
- height: 200
240
- },
241
- {
242
- key: "attention-syncs",
243
- spec: AttentionSyncMetricVisualization,
244
- data: { data: [{ value: attentionSyncs }] },
245
- title: "Attention Needed",
246
- description: "Paused, failed, or degraded sync configurations.",
247
- height: 200
248
- }
249
- ];
250
- return {
251
- primaryItems,
252
- comparisonItems
253
- };
254
- }
255
- // src/ui/IntegrationDashboard.visualizations.tsx
256
- import {
257
- ComparisonView,
258
- VisualizationCard,
259
- VisualizationGrid
260
- } from "@contractspec/lib.design-system";
261
- import { jsxDEV } from "react/jsx-dev-runtime";
262
- "use client";
263
- function IntegrationVisualizationOverview({
264
- integrations,
265
- connections,
266
- syncConfigs
267
- }) {
268
- const { primaryItems, comparisonItems } = createIntegrationVisualizationSections(integrations, connections, syncConfigs);
269
- return /* @__PURE__ */ jsxDEV("section", {
270
- className: "space-y-4",
271
- children: [
272
- /* @__PURE__ */ jsxDEV("div", {
273
- children: [
274
- /* @__PURE__ */ jsxDEV("h3", {
275
- className: "font-semibold text-lg",
276
- children: "Integration Visualizations"
277
- }, undefined, false, undefined, this),
278
- /* @__PURE__ */ jsxDEV("p", {
279
- className: "text-muted-foreground text-sm",
280
- children: "Contract-backed charts for integration coverage and sync health."
281
- }, undefined, false, undefined, this)
282
- ]
283
- }, undefined, true, undefined, this),
284
- /* @__PURE__ */ jsxDEV(VisualizationGrid, {
285
- children: primaryItems.map((item) => /* @__PURE__ */ jsxDEV(VisualizationCard, {
286
- data: item.data,
287
- description: item.description,
288
- height: item.height,
289
- spec: item.spec,
290
- title: item.title
291
- }, item.key, false, undefined, this))
292
- }, undefined, false, undefined, this),
293
- /* @__PURE__ */ jsxDEV(ComparisonView, {
294
- description: "Comparison surface for healthy versus attention-needed syncs.",
295
- items: comparisonItems,
296
- title: "Sync-State Comparison"
297
- }, undefined, false, undefined, this)
298
- ]
299
- }, undefined, true, undefined, this);
300
- }
301
-
302
- // src/ui/IntegrationHubChat.tsx
303
- import { ChatWithSidebar } from "@contractspec/module.ai-chat";
304
- import { jsxDEV as jsxDEV2 } from "react/jsx-dev-runtime";
305
- "use client";
306
- var DEFAULT_SUGGESTIONS = [
307
- "List my integrations",
308
- "Show sync status",
309
- "Add a connection"
310
- ];
311
- var DEFAULT_SYSTEM_PROMPT = `You are an Integration Hub assistant. Help users manage integrations, connections, and sync configurations. When asked about integrations, connections, or syncs, provide clear, actionable guidance.`;
312
- function IntegrationHubChat({
313
- proxyUrl = "/api/chat",
314
- mcpServers,
315
- thinkingLevel = "thinking",
316
- suggestions = DEFAULT_SUGGESTIONS,
317
- systemPrompt = DEFAULT_SYSTEM_PROMPT,
318
- className
319
- }) {
320
- return /* @__PURE__ */ jsxDEV2("div", {
321
- className: className ?? "flex h-[500px] flex-col",
322
- children: /* @__PURE__ */ jsxDEV2(ChatWithSidebar, {
323
- className: "flex-1",
324
- systemPrompt,
325
- proxyUrl,
326
- mcpServers,
327
- thinkingLevel,
328
- suggestions,
329
- showSuggestionsWhenEmpty: true
330
- }, undefined, false, undefined, this)
331
- }, undefined, false, undefined, this);
332
- }
333
-
334
- // src/ui/tables/integration-table.shared.tsx
335
- import { Button } from "@contractspec/lib.design-system";
336
- import { Badge } from "@contractspec/lib.ui-kit-web/ui/badge";
337
- import { HStack } from "@contractspec/lib.ui-kit-web/ui/stack";
338
- import { jsxDEV as jsxDEV3 } from "react/jsx-dev-runtime";
339
- "use client";
340
- var STATUS_VARIANTS = {
341
- ACTIVE: "default",
342
- CONNECTED: "default",
343
- SUCCESS: "default",
344
- PENDING: "secondary",
345
- PAUSED: "secondary",
346
- ERROR: "destructive",
347
- DISCONNECTED: "outline"
348
- };
349
- function formatDateTime(value) {
350
- return value ? value.toLocaleString() : "Never";
351
- }
352
- function formatJson(value) {
353
- return value ? JSON.stringify(value, null, 2) : "No configuration";
354
- }
355
- function StatusBadge({ status }) {
356
- return /* @__PURE__ */ jsxDEV3(Badge, {
357
- variant: STATUS_VARIANTS[status] ?? "outline",
358
- children: status
359
- }, undefined, false, undefined, this);
360
- }
361
- function IntegrationTableToolbar({
362
- controller,
363
- label,
364
- toggleColumnId,
365
- toggleVisibleLabel,
366
- toggleHiddenLabel,
367
- pinColumnId,
368
- pinLabel,
369
- resizeColumnId,
370
- resizeLabel
371
- }) {
372
- const firstRow = controller.rows[0];
373
- const toggleColumn = controller.columns.find((column) => column.id === toggleColumnId);
374
- const pinColumn = controller.columns.find((column) => column.id === pinColumnId);
375
- const resizeColumn = controller.columns.find((column) => column.id === resizeColumnId);
376
- const pinTarget = pinColumn?.pinState === "left" ? false : "left";
377
- return /* @__PURE__ */ jsxDEV3(HStack, {
378
- gap: "sm",
379
- className: "flex-wrap",
380
- children: [
381
- /* @__PURE__ */ jsxDEV3(Badge, {
382
- variant: "outline",
383
- children: label
384
- }, undefined, false, undefined, this),
385
- /* @__PURE__ */ jsxDEV3(Button, {
386
- variant: "outline",
387
- size: "sm",
388
- onPress: () => firstRow?.toggleExpanded?.(!firstRow?.isExpanded),
389
- children: "Expand First Row"
390
- }, undefined, false, undefined, this),
391
- /* @__PURE__ */ jsxDEV3(Button, {
392
- variant: "outline",
393
- size: "sm",
394
- onPress: () => toggleColumn?.toggleVisibility?.(!toggleColumn?.visible),
395
- children: toggleColumn?.visible ? toggleVisibleLabel : toggleHiddenLabel
396
- }, undefined, false, undefined, this),
397
- /* @__PURE__ */ jsxDEV3(Button, {
398
- variant: "outline",
399
- size: "sm",
400
- onPress: () => pinColumn?.pin?.(pinTarget),
401
- children: pinColumn?.pinState === "left" ? `Unpin ${pinLabel}` : `Pin ${pinLabel}`
402
- }, undefined, false, undefined, this),
403
- /* @__PURE__ */ jsxDEV3(Button, {
404
- variant: "outline",
405
- size: "sm",
406
- onPress: () => resizeColumn?.resizeBy?.(40),
407
- children: resizeLabel
408
- }, undefined, false, undefined, this)
409
- ]
410
- }, undefined, true, undefined, this);
411
- }
412
-
413
- // src/ui/tables/ConnectionsTable.tsx
414
- import { DataTable } from "@contractspec/lib.design-system";
415
- import { useContractTable } from "@contractspec/lib.presentation-runtime-react";
416
- import { VStack } from "@contractspec/lib.ui-kit-web/ui/stack";
417
- import { Text } from "@contractspec/lib.ui-kit-web/ui/text";
418
- import { jsxDEV as jsxDEV4 } from "react/jsx-dev-runtime";
419
- "use client";
420
- function ConnectionsTable({
421
- connections
422
- }) {
423
- const controller = useContractTable({
424
- data: connections,
425
- columns: [
426
- {
427
- id: "connection",
428
- header: "Connection",
429
- label: "Connection",
430
- accessor: (connection) => connection.name,
431
- cell: ({ item }) => /* @__PURE__ */ jsxDEV4(VStack, {
432
- gap: "xs",
433
- children: [
434
- /* @__PURE__ */ jsxDEV4(Text, {
435
- className: "font-medium text-sm",
436
- children: item.name
437
- }, undefined, false, undefined, this),
438
- /* @__PURE__ */ jsxDEV4(Text, {
439
- className: "text-muted-foreground text-xs",
440
- children: [
441
- "Created ",
442
- item.createdAt.toLocaleDateString()
443
- ]
444
- }, undefined, true, undefined, this)
445
- ]
446
- }, undefined, true, undefined, this),
447
- size: 240,
448
- minSize: 180,
449
- canSort: true,
450
- canPin: true,
451
- canResize: true
452
- },
453
- {
454
- id: "status",
455
- header: "Status",
456
- label: "Status",
457
- accessorKey: "status",
458
- cell: ({ value }) => /* @__PURE__ */ jsxDEV4(StatusBadge, {
459
- status: String(value)
460
- }, undefined, false, undefined, this),
461
- size: 150,
462
- canSort: true,
463
- canPin: true,
464
- canResize: true
465
- },
466
- {
467
- id: "lastSyncAt",
468
- header: "Last Sync",
469
- label: "Last Sync",
470
- accessor: (connection) => connection.lastSyncAt?.getTime() ?? 0,
471
- cell: ({ item }) => formatDateTime(item.lastSyncAt),
472
- size: 200,
473
- canSort: true,
474
- canHide: true,
475
- canResize: true
476
- },
477
- {
478
- id: "errorMessage",
479
- header: "Errors",
480
- label: "Errors",
481
- accessor: (connection) => connection.errorMessage ?? "",
482
- cell: ({ value }) => String(value || "No errors"),
483
- size: 240,
484
- canHide: true,
485
- canResize: true
486
- }
487
- ],
488
- initialState: {
489
- pagination: { pageIndex: 0, pageSize: 3 },
490
- columnVisibility: { errorMessage: false },
491
- columnPinning: { left: ["connection"], right: [] }
492
- },
493
- renderExpandedContent: (connection) => /* @__PURE__ */ jsxDEV4(VStack, {
494
- gap: "sm",
495
- className: "py-2",
496
- children: [
497
- /* @__PURE__ */ jsxDEV4(Text, {
498
- className: "font-medium text-sm",
499
- children: "Credentials"
500
- }, undefined, false, undefined, this),
501
- /* @__PURE__ */ jsxDEV4("pre", {
502
- className: "overflow-auto rounded-md bg-muted/40 p-3 text-xs",
503
- children: formatJson(connection.credentials)
504
- }, undefined, false, undefined, this),
505
- /* @__PURE__ */ jsxDEV4(Text, {
506
- className: "font-medium text-sm",
507
- children: "Config"
508
- }, undefined, false, undefined, this),
509
- /* @__PURE__ */ jsxDEV4("pre", {
510
- className: "overflow-auto rounded-md bg-muted/40 p-3 text-xs",
511
- children: formatJson(connection.config)
512
- }, undefined, false, undefined, this),
513
- /* @__PURE__ */ jsxDEV4(Text, {
514
- className: "text-muted-foreground text-sm",
515
- children: connection.errorMessage ?? "No sync errors recorded."
516
- }, undefined, false, undefined, this)
517
- ]
518
- }, undefined, true, undefined, this),
519
- getCanExpand: () => true
520
- });
521
- return /* @__PURE__ */ jsxDEV4(DataTable, {
522
- controller,
523
- title: "Connections",
524
- description: "Client-mode ContractSpec table with visibility, pinning, resizing, and expanded diagnostics.",
525
- toolbar: /* @__PURE__ */ jsxDEV4(IntegrationTableToolbar, {
526
- controller,
527
- label: `${connections.length} total connections`,
528
- toggleColumnId: "errorMessage",
529
- toggleVisibleLabel: "Hide Error Column",
530
- toggleHiddenLabel: "Show Error Column",
531
- pinColumnId: "status",
532
- pinLabel: "Status",
533
- resizeColumnId: "connection",
534
- resizeLabel: "Widen Connection"
535
- }, undefined, false, undefined, this),
536
- emptyState: /* @__PURE__ */ jsxDEV4("div", {
537
- className: "rounded-md border border-dashed p-8 text-center text-muted-foreground text-sm",
538
- children: "No connections found"
539
- }, undefined, false, undefined, this)
540
- }, undefined, false, undefined, this);
541
- }
542
-
543
- // src/ui/tables/SyncConfigsTable.tsx
544
- import { DataTable as DataTable2 } from "@contractspec/lib.design-system";
545
- import { useContractTable as useContractTable2 } from "@contractspec/lib.presentation-runtime-react";
546
- import { VStack as VStack2 } from "@contractspec/lib.ui-kit-web/ui/stack";
547
- import { Text as Text2 } from "@contractspec/lib.ui-kit-web/ui/text";
548
- import { jsxDEV as jsxDEV5 } from "react/jsx-dev-runtime";
549
- "use client";
550
- function SyncConfigsTable({
551
- syncConfigs
552
- }) {
553
- const controller = useContractTable2({
554
- data: syncConfigs,
555
- columns: [
556
- {
557
- id: "sync",
558
- header: "Sync Config",
559
- label: "Sync Config",
560
- accessor: (sync) => sync.name,
561
- cell: ({ item }) => /* @__PURE__ */ jsxDEV5(VStack2, {
562
- gap: "xs",
563
- children: [
564
- /* @__PURE__ */ jsxDEV5(Text2, {
565
- className: "font-medium text-sm",
566
- children: item.name
567
- }, undefined, false, undefined, this),
568
- /* @__PURE__ */ jsxDEV5(Text2, {
569
- className: "text-muted-foreground text-xs",
570
- children: [
571
- item.sourceEntity,
572
- " \u2192 ",
573
- item.targetEntity
574
- ]
575
- }, undefined, true, undefined, this)
576
- ]
577
- }, undefined, true, undefined, this),
578
- size: 260,
579
- minSize: 200,
580
- canSort: true,
581
- canPin: true,
582
- canResize: true
583
- },
584
- {
585
- id: "frequency",
586
- header: "Frequency",
587
- label: "Frequency",
588
- accessorKey: "frequency",
589
- size: 160,
590
- canSort: true,
591
- canHide: true,
592
- canResize: true
593
- },
594
- {
595
- id: "status",
596
- header: "Status",
597
- label: "Status",
598
- accessorKey: "status",
599
- cell: ({ value }) => /* @__PURE__ */ jsxDEV5(StatusBadge, {
600
- status: String(value)
601
- }, undefined, false, undefined, this),
602
- size: 150,
603
- canSort: true,
604
- canPin: true,
605
- canResize: true
606
- },
607
- {
608
- id: "recordsSynced",
609
- header: "Records",
610
- label: "Records",
611
- accessorKey: "recordsSynced",
612
- align: "right",
613
- size: 140,
614
- canSort: true,
615
- canResize: true
616
- },
617
- {
618
- id: "lastRunAt",
619
- header: "Last Run",
620
- label: "Last Run",
621
- accessor: (sync) => sync.lastRunAt?.getTime() ?? 0,
622
- cell: ({ item }) => formatDateTime(item.lastRunAt),
623
- size: 200,
624
- canSort: true,
625
- canHide: true,
626
- canResize: true
627
- }
628
- ],
629
- initialState: {
630
- pagination: { pageIndex: 0, pageSize: 3 },
631
- columnVisibility: { lastRunAt: false },
632
- columnPinning: { left: ["sync"], right: [] }
633
- },
634
- renderExpandedContent: (sync) => /* @__PURE__ */ jsxDEV5(VStack2, {
635
- gap: "sm",
636
- className: "py-2",
637
- children: [
638
- /* @__PURE__ */ jsxDEV5(Text2, {
639
- className: "text-muted-foreground text-sm",
640
- children: [
641
- "Connection ",
642
- sync.connectionId
643
- ]
644
- }, undefined, true, undefined, this),
645
- /* @__PURE__ */ jsxDEV5(Text2, {
646
- className: "text-muted-foreground text-sm",
647
- children: [
648
- "Last run: ",
649
- formatDateTime(sync.lastRunAt)
650
- ]
651
- }, undefined, true, undefined, this),
652
- /* @__PURE__ */ jsxDEV5(Text2, {
653
- className: "text-muted-foreground text-sm",
654
- children: [
655
- "Last status: ",
656
- sync.lastRunStatus ?? "No runs recorded"
657
- ]
658
- }, undefined, true, undefined, this),
659
- /* @__PURE__ */ jsxDEV5(Text2, {
660
- className: "text-muted-foreground text-sm",
661
- children: [
662
- "Updated ",
663
- sync.updatedAt.toLocaleString()
664
- ]
665
- }, undefined, true, undefined, this)
666
- ]
667
- }, undefined, true, undefined, this),
668
- getCanExpand: () => true
669
- });
670
- return /* @__PURE__ */ jsxDEV5(DataTable2, {
671
- controller,
672
- title: "Sync Configs",
673
- description: "Shared table primitives applied to sync monitoring without changing the surrounding dashboard layout.",
674
- toolbar: /* @__PURE__ */ jsxDEV5(IntegrationTableToolbar, {
675
- controller,
676
- label: `${syncConfigs.length} syncs`,
677
- toggleColumnId: "lastRunAt",
678
- toggleVisibleLabel: "Hide Last Run",
679
- toggleHiddenLabel: "Show Last Run",
680
- pinColumnId: "status",
681
- pinLabel: "Status",
682
- resizeColumnId: "sync",
683
- resizeLabel: "Widen Sync"
684
- }, undefined, false, undefined, this),
685
- emptyState: /* @__PURE__ */ jsxDEV5("div", {
686
- className: "rounded-md border border-dashed p-8 text-center text-muted-foreground text-sm",
687
- children: "No sync configurations found"
688
- }, undefined, false, undefined, this)
689
- }, undefined, false, undefined, this);
690
- }
691
- // src/ui/IntegrationDashboard.tsx
692
- import {
693
- Button as Button2,
694
- ErrorState,
695
- LoaderBlock,
696
- StatCard,
697
- StatCardGroup
698
- } from "@contractspec/lib.design-system";
699
- import { useState as useState2 } from "react";
700
- import { jsxDEV as jsxDEV6 } from "react/jsx-dev-runtime";
701
- "use client";
702
- var STATUS_COLORS = {
703
- ACTIVE: "bg-green-100 text-green-700 dark:bg-green-900/30 dark:text-green-400",
704
- INACTIVE: "bg-gray-100 text-gray-700 dark:bg-gray-900/30 dark:text-gray-400",
705
- CONNECTED: "bg-green-100 text-green-700 dark:bg-green-900/30 dark:text-green-400",
706
- DISCONNECTED: "bg-gray-100 text-gray-700 dark:bg-gray-900/30 dark:text-gray-400",
707
- PENDING: "bg-yellow-100 text-yellow-700 dark:bg-yellow-900/30 dark:text-yellow-400",
708
- ERROR: "bg-red-100 text-red-700 dark:bg-red-900/30 dark:text-red-400",
709
- PAUSED: "bg-yellow-100 text-yellow-700 dark:bg-yellow-900/30 dark:text-yellow-400"
710
- };
711
- var TYPE_ICONS = {
712
- CRM: "\uD83D\uDCCA",
713
- MARKETING: "\uD83D\uDCE3",
714
- PAYMENT: "\uD83D\uDCB3",
715
- COMMUNICATION: "\uD83D\uDCAC",
716
- DATA: "\uD83D\uDDC4\uFE0F",
717
- CUSTOM: "\u2699\uFE0F"
718
- };
719
- function IntegrationDashboard() {
720
- const [activeTab, setActiveTab] = useState2("integrations");
721
- const {
722
- integrations,
723
- connections,
724
- syncConfigs,
725
- loading,
726
- error,
727
- stats,
728
- refetch
729
- } = useIntegrationData();
730
- const tabs = [
731
- { id: "integrations", label: "Integrations", icon: "\uD83D\uDD0C" },
732
- { id: "connections", label: "Connections", icon: "\uD83D\uDD17" },
733
- { id: "syncs", label: "Sync Configs", icon: "\uD83D\uDD04" },
734
- { id: "chat", label: "Chat", icon: "\uD83D\uDCAC" }
735
- ];
736
- if (loading) {
737
- return /* @__PURE__ */ jsxDEV6(LoaderBlock, {
738
- label: "Loading Integrations..."
739
- }, undefined, false, undefined, this);
740
- }
741
- if (error) {
742
- return /* @__PURE__ */ jsxDEV6(ErrorState, {
743
- title: "Failed to load Integrations",
744
- description: error.message,
745
- onRetry: refetch,
746
- retryLabel: "Retry"
747
- }, undefined, false, undefined, this);
748
- }
749
- return /* @__PURE__ */ jsxDEV6("div", {
750
- className: "space-y-6",
751
- children: [
752
- /* @__PURE__ */ jsxDEV6("div", {
753
- className: "flex items-center justify-between",
754
- children: [
755
- /* @__PURE__ */ jsxDEV6("h2", {
756
- className: "font-bold text-2xl",
757
- children: "Integration Hub"
758
- }, undefined, false, undefined, this),
759
- /* @__PURE__ */ jsxDEV6(Button2, {
760
- onClick: () => alert("Add integration modal"),
761
- children: [
762
- /* @__PURE__ */ jsxDEV6("span", {
763
- className: "mr-2",
764
- children: "+"
765
- }, undefined, false, undefined, this),
766
- " Add Integration"
767
- ]
768
- }, undefined, true, undefined, this)
769
- ]
770
- }, undefined, true, undefined, this),
771
- /* @__PURE__ */ jsxDEV6(StatCardGroup, {
772
- children: [
773
- /* @__PURE__ */ jsxDEV6(StatCard, {
774
- label: "Integrations",
775
- value: stats.totalIntegrations,
776
- hint: `${stats.activeIntegrations} active`
777
- }, undefined, false, undefined, this),
778
- /* @__PURE__ */ jsxDEV6(StatCard, {
779
- label: "Connections",
780
- value: stats.totalConnections,
781
- hint: `${stats.connectedCount} connected`
782
- }, undefined, false, undefined, this),
783
- /* @__PURE__ */ jsxDEV6(StatCard, {
784
- label: "Syncs",
785
- value: stats.totalSyncs,
786
- hint: `${stats.activeSyncs} active`
787
- }, undefined, false, undefined, this)
788
- ]
789
- }, undefined, true, undefined, this),
790
- /* @__PURE__ */ jsxDEV6(IntegrationVisualizationOverview, {
791
- connections,
792
- integrations,
793
- syncConfigs
794
- }, undefined, false, undefined, this),
795
- /* @__PURE__ */ jsxDEV6("nav", {
796
- className: "flex gap-1 rounded-lg bg-muted p-1",
797
- role: "tablist",
798
- children: tabs.map((tab) => /* @__PURE__ */ jsxDEV6(Button2, {
799
- type: "button",
800
- role: "tab",
801
- "aria-selected": activeTab === tab.id,
802
- onClick: () => setActiveTab(tab.id),
803
- className: `flex flex-1 items-center justify-center gap-2 rounded-md px-4 py-2 font-medium text-sm transition-colors ${activeTab === tab.id ? "bg-background text-foreground shadow-sm" : "text-muted-foreground hover:text-foreground"}`,
804
- children: [
805
- /* @__PURE__ */ jsxDEV6("span", {
806
- children: tab.icon
807
- }, undefined, false, undefined, this),
808
- tab.label
809
- ]
810
- }, tab.id, true, undefined, this))
811
- }, undefined, false, undefined, this),
812
- /* @__PURE__ */ jsxDEV6("div", {
813
- className: "min-h-[400px]",
814
- role: "tabpanel",
815
- children: [
816
- activeTab === "integrations" && /* @__PURE__ */ jsxDEV6("div", {
817
- className: "grid gap-4 sm:grid-cols-2 lg:grid-cols-3",
818
- children: [
819
- integrations.map((integration) => /* @__PURE__ */ jsxDEV6("div", {
820
- className: "cursor-pointer rounded-lg border border-border bg-card p-4 transition-colors hover:bg-muted/50",
821
- children: [
822
- /* @__PURE__ */ jsxDEV6("div", {
823
- className: "mb-3 flex items-center gap-3",
824
- children: [
825
- /* @__PURE__ */ jsxDEV6("span", {
826
- className: "text-2xl",
827
- children: TYPE_ICONS[integration.type] ?? "\u2699\uFE0F"
828
- }, undefined, false, undefined, this),
829
- /* @__PURE__ */ jsxDEV6("div", {
830
- children: [
831
- /* @__PURE__ */ jsxDEV6("h3", {
832
- className: "font-medium",
833
- children: integration.name
834
- }, undefined, false, undefined, this),
835
- /* @__PURE__ */ jsxDEV6("p", {
836
- className: "text-muted-foreground text-sm",
837
- children: integration.type
838
- }, undefined, false, undefined, this)
839
- ]
840
- }, undefined, true, undefined, this)
841
- ]
842
- }, undefined, true, undefined, this),
843
- /* @__PURE__ */ jsxDEV6("div", {
844
- className: "flex items-center justify-between",
845
- children: [
846
- /* @__PURE__ */ jsxDEV6("span", {
847
- className: `inline-flex rounded-full px-2 py-0.5 font-medium text-xs ${STATUS_COLORS[integration.status] ?? ""}`,
848
- children: integration.status
849
- }, undefined, false, undefined, this),
850
- /* @__PURE__ */ jsxDEV6("span", {
851
- className: "text-muted-foreground text-xs",
852
- children: integration.createdAt.toLocaleDateString()
853
- }, undefined, false, undefined, this)
854
- ]
855
- }, undefined, true, undefined, this)
856
- ]
857
- }, integration.id, true, undefined, this)),
858
- integrations.length === 0 && /* @__PURE__ */ jsxDEV6("div", {
859
- className: "col-span-full flex h-64 items-center justify-center text-muted-foreground",
860
- children: "No integrations configured"
861
- }, undefined, false, undefined, this)
862
- ]
863
- }, undefined, true, undefined, this),
864
- activeTab === "connections" && /* @__PURE__ */ jsxDEV6(ConnectionsTable, {
865
- connections
866
- }, undefined, false, undefined, this),
867
- activeTab === "chat" && /* @__PURE__ */ jsxDEV6(IntegrationHubChat, {
868
- proxyUrl: "/api/chat",
869
- thinkingLevel: "thinking",
870
- suggestions: [
871
- "List my integrations",
872
- "Show sync status",
873
- "Add a connection"
874
- ],
875
- className: "min-h-[400px]"
876
- }, undefined, false, undefined, this),
877
- activeTab === "syncs" && /* @__PURE__ */ jsxDEV6(SyncConfigsTable, {
878
- syncConfigs
879
- }, undefined, false, undefined, this)
880
- ]
881
- }, undefined, true, undefined, this)
882
- ]
883
- }, undefined, true, undefined, this);
884
- }
885
- export {
886
- IntegrationDashboard
887
- };
2
+ import{useTemplateRuntime as Kq}from"@contractspec/lib.example-shared-ui";import{useCallback as Qq,useEffect as Xq,useState as R}from"react";function x(K="local-project"){let{handlers:W}=Kq(),q=W.integration,[J,Y]=R([]),[X,U]=R([]),[P,O]=R([]),[$,Q]=R(!0),[k,z]=R(null),A=Qq(async()=>{try{Q(!0),z(null);let[w,t,qq]=await Promise.all([q.listIntegrations({projectId:K,limit:100}),q.listConnections({limit:100}),q.listSyncConfigs({limit:100})]);Y(w.integrations),U(t.connections),O(qq.configs)}catch(w){z(w instanceof Error?w:Error("Failed to load integrations"))}finally{Q(!1)}},[q,K]);Xq(()=>{A()},[A]);let B={totalIntegrations:J.length,activeIntegrations:J.filter((w)=>w.status==="ACTIVE").length,totalConnections:X.length,connectedCount:X.filter((w)=>w.status==="CONNECTED").length,totalSyncs:P.length,activeSyncs:P.filter((w)=>w.status==="ACTIVE").length};return{integrations:J,connections:X,syncConfigs:P,loading:$,error:k,stats:B,refetch:A}}import{defineVisualization as h,VisualizationRegistry as Zq}from"@contractspec/lib.contracts-spec/visualizations";var $q={key:"integration.list",version:"1.0.0"},Wq={key:"integration.connection.list",version:"1.0.0"},g={key:"integration.syncConfig.list",version:"1.0.0"},V={version:"1.0.0",domain:"integration",stability:"experimental",owners:["@example.integration-hub"],tags:["integration","visualization","sync"]},d=h({meta:{...V,key:"integration-hub.visualization.integration-types",title:"Integration Types",description:"Distribution of configured integration categories.",goal:"Show where integration coverage is concentrated.",context:"Integration overview."},source:{primary:$q,resultPath:"data"},visualization:{kind:"pie",nameDimension:"type",valueMeasure:"count",dimensions:[{key:"type",label:"Type",dataPath:"type",type:"category"}],measures:[{key:"count",label:"Count",dataPath:"count",format:"number"}],table:{caption:"Integration counts by type."}}}),p=h({meta:{...V,key:"integration-hub.visualization.connection-status",title:"Connection Status",description:"Status distribution across configured connections.",goal:"Highlight connection health and instability.",context:"Connection monitoring."},source:{primary:Wq,resultPath:"data"},visualization:{kind:"cartesian",variant:"bar",xDimension:"status",yMeasures:["count"],dimensions:[{key:"status",label:"Status",dataPath:"status",type:"category"}],measures:[{key:"count",label:"Connections",dataPath:"count",format:"number",color:"#1d4ed8"}],table:{caption:"Connection counts by status."}}}),C=h({meta:{...V,key:"integration-hub.visualization.sync-healthy",title:"Healthy Syncs",description:"Sync configurations currently healthy or recently successful.",goal:"Summarize healthy synchronization capacity.",context:"Sync-state comparison."},source:{primary:g,resultPath:"data"},visualization:{kind:"metric",measure:"value",measures:[{key:"value",label:"Syncs",dataPath:"value",format:"number"}],table:{caption:"Healthy sync count."}}}),S=h({meta:{...V,key:"integration-hub.visualization.sync-attention",title:"Attention Needed",description:"Sync configurations paused, failing, or otherwise needing review.",goal:"Summarize syncs needing action.",context:"Sync-state comparison."},source:{primary:g,resultPath:"data"},visualization:{kind:"metric",measure:"value",measures:[{key:"value",label:"Syncs",dataPath:"value",format:"number"}],table:{caption:"Syncs requiring attention."}}}),u=[d,p,C,S],Iq=new Zq([...u]),dq=u.map((K)=>({key:K.meta.key,version:K.meta.version}));function Jq(K){return K==="ACTIVE"||K==="SUCCESS"}function l(K,W,q){let J=new Map,Y=new Map,X=0,U=0;for(let $ of K)J.set($.type,(J.get($.type)??0)+1);for(let $ of W)Y.set($.status,(Y.get($.status)??0)+1);for(let $ of q)if(Jq($.status))X+=1;else U+=1;return{primaryItems:[{key:"integration-types",spec:d,data:{data:Array.from(J.entries()).map(([$,Q])=>({type:$,count:Q}))},title:"Integration Types",description:"Configured integrations grouped by category.",height:260},{key:"connection-status",spec:p,data:{data:Array.from(Y.entries()).map(([$,Q])=>({status:$,count:Q}))},title:"Connection Status",description:"Operational health across current connections."}],comparisonItems:[{key:"healthy-syncs",spec:C,data:{data:[{value:X}]},title:"Healthy Syncs",description:"Active or recently successful sync configurations.",height:200},{key:"attention-syncs",spec:S,data:{data:[{value:U}]},title:"Attention Needed",description:"Paused, failed, or degraded sync configurations.",height:200}]}}import{ComparisonView as Yq,VisualizationCard as Pq,VisualizationGrid as Hq}from"@contractspec/lib.design-system";import{jsx as _,jsxs as r}from"react/jsx-runtime";function c({integrations:K,connections:W,syncConfigs:q}){let{primaryItems:J,comparisonItems:Y}=l(K,W,q);return r("section",{className:"space-y-4",children:[r("div",{children:[_("h3",{className:"font-semibold text-lg",children:"Integration Visualizations"}),_("p",{className:"text-muted-foreground text-sm",children:"Contract-backed charts for integration coverage and sync health."})]}),_(Hq,{children:J.map((X)=>_(Pq,{data:X.data,description:X.description,height:X.height,spec:X.spec,title:X.title},X.key))}),_(Yq,{description:"Comparison surface for healthy versus attention-needed syncs.",items:Y,title:"Sync-State Comparison"})]})}import{ChatWithSidebar as Uq}from"@contractspec/module.ai-chat";import{jsx as o}from"react/jsx-runtime";var wq=["List my integrations","Show sync status","Add a connection"],Gq="You are an Integration Hub assistant. Help users manage integrations, connections, and sync configurations. When asked about integrations, connections, or syncs, provide clear, actionable guidance.";function a({proxyUrl:K="/api/chat",mcpServers:W,thinkingLevel:q="thinking",suggestions:J=wq,systemPrompt:Y=Gq,className:X}){return o("div",{className:X??"flex h-[500px] flex-col",children:o(Uq,{className:"flex-1",systemPrompt:Y,proxyUrl:K,mcpServers:W,thinkingLevel:q,suggestions:J,showSuggestionsWhenEmpty:!0})})}import{Button as v}from"@contractspec/lib.design-system";import{Badge as i}from"@contractspec/lib.ui-kit-web/ui/badge";import{HStack as Bq}from"@contractspec/lib.ui-kit-web/ui/stack";import{jsx as M,jsxs as Oq}from"react/jsx-runtime";var Fq={ACTIVE:"default",CONNECTED:"default",SUCCESS:"default",PENDING:"secondary",PAUSED:"secondary",ERROR:"destructive",DISCONNECTED:"outline"};function N(K){return K?K.toLocaleString():"Never"}function b(K){return K?JSON.stringify(K,null,2):"No configuration"}function f({status:K}){return M(i,{variant:Fq[K]??"outline",children:K})}function I({controller:K,label:W,toggleColumnId:q,toggleVisibleLabel:J,toggleHiddenLabel:Y,pinColumnId:X,pinLabel:U,resizeColumnId:P,resizeLabel:O}){let $=K.rows[0],Q=K.columns.find((B)=>B.id===q),k=K.columns.find((B)=>B.id===X),z=K.columns.find((B)=>B.id===P),A=k?.pinState==="left"?!1:"left";return Oq(Bq,{gap:"sm",className:"flex-wrap",children:[M(i,{variant:"outline",children:W}),M(v,{variant:"outline",size:"sm",onPress:()=>$?.toggleExpanded?.(!$?.isExpanded),children:"Expand First Row"}),M(v,{variant:"outline",size:"sm",onPress:()=>Q?.toggleVisibility?.(!Q?.visible),children:Q?.visible?J:Y}),M(v,{variant:"outline",size:"sm",onPress:()=>k?.pin?.(A),children:k?.pinState==="left"?`Unpin ${U}`:`Pin ${U}`}),M(v,{variant:"outline",size:"sm",onPress:()=>z?.resizeBy?.(40),children:O})]})}import{DataTable as Mq}from"@contractspec/lib.design-system";import{useContractTable as Dq}from"@contractspec/lib.presentation-runtime-react";import{VStack as s}from"@contractspec/lib.ui-kit-web/ui/stack";import{Text as E}from"@contractspec/lib.ui-kit-web/ui/text";import{jsx as G,jsxs as T}from"react/jsx-runtime";function y({connections:K}){let W=Dq({data:K,columns:[{id:"connection",header:"Connection",label:"Connection",accessor:(q)=>q.name,cell:({item:q})=>T(s,{gap:"xs",children:[G(E,{className:"font-medium text-sm",children:q.name}),T(E,{className:"text-muted-foreground text-xs",children:["Created ",q.createdAt.toLocaleDateString()]})]}),size:240,minSize:180,canSort:!0,canPin:!0,canResize:!0},{id:"status",header:"Status",label:"Status",accessorKey:"status",cell:({value:q})=>G(f,{status:String(q)}),size:150,canSort:!0,canPin:!0,canResize:!0},{id:"lastSyncAt",header:"Last Sync",label:"Last Sync",accessor:(q)=>q.lastSyncAt?.getTime()??0,cell:({item:q})=>N(q.lastSyncAt),size:200,canSort:!0,canHide:!0,canResize:!0},{id:"errorMessage",header:"Errors",label:"Errors",accessor:(q)=>q.errorMessage??"",cell:({value:q})=>String(q||"No errors"),size:240,canHide:!0,canResize:!0}],initialState:{pagination:{pageIndex:0,pageSize:3},columnVisibility:{errorMessage:!1},columnPinning:{left:["connection"],right:[]}},renderExpandedContent:(q)=>T(s,{gap:"sm",className:"py-2",children:[G(E,{className:"font-medium text-sm",children:"Credentials"}),G("pre",{className:"overflow-auto rounded-md bg-muted/40 p-3 text-xs",children:b(q.credentials)}),G(E,{className:"font-medium text-sm",children:"Config"}),G("pre",{className:"overflow-auto rounded-md bg-muted/40 p-3 text-xs",children:b(q.config)}),G(E,{className:"text-muted-foreground text-sm",children:q.errorMessage??"No sync errors recorded."})]}),getCanExpand:()=>!0});return G(Mq,{controller:W,title:"Connections",description:"Client-mode ContractSpec table with visibility, pinning, resizing, and expanded diagnostics.",toolbar:G(I,{controller:W,label:`${K.length} total connections`,toggleColumnId:"errorMessage",toggleVisibleLabel:"Hide Error Column",toggleHiddenLabel:"Show Error Column",pinColumnId:"status",pinLabel:"Status",resizeColumnId:"connection",resizeLabel:"Widen Connection"}),emptyState:G("div",{className:"rounded-md border border-dashed p-8 text-center text-muted-foreground text-sm",children:"No connections found"})})}import{DataTable as kq}from"@contractspec/lib.design-system";import{useContractTable as Aq}from"@contractspec/lib.presentation-runtime-react";import{VStack as e}from"@contractspec/lib.ui-kit-web/ui/stack";import{Text as D}from"@contractspec/lib.ui-kit-web/ui/text";import{jsx as L,jsxs as F}from"react/jsx-runtime";function m({syncConfigs:K}){let W=Aq({data:K,columns:[{id:"sync",header:"Sync Config",label:"Sync Config",accessor:(q)=>q.name,cell:({item:q})=>F(e,{gap:"xs",children:[L(D,{className:"font-medium text-sm",children:q.name}),F(D,{className:"text-muted-foreground text-xs",children:[q.sourceEntity," \u2192 ",q.targetEntity]})]}),size:260,minSize:200,canSort:!0,canPin:!0,canResize:!0},{id:"frequency",header:"Frequency",label:"Frequency",accessorKey:"frequency",size:160,canSort:!0,canHide:!0,canResize:!0},{id:"status",header:"Status",label:"Status",accessorKey:"status",cell:({value:q})=>L(f,{status:String(q)}),size:150,canSort:!0,canPin:!0,canResize:!0},{id:"recordsSynced",header:"Records",label:"Records",accessorKey:"recordsSynced",align:"right",size:140,canSort:!0,canResize:!0},{id:"lastRunAt",header:"Last Run",label:"Last Run",accessor:(q)=>q.lastRunAt?.getTime()??0,cell:({item:q})=>N(q.lastRunAt),size:200,canSort:!0,canHide:!0,canResize:!0}],initialState:{pagination:{pageIndex:0,pageSize:3},columnVisibility:{lastRunAt:!1},columnPinning:{left:["sync"],right:[]}},renderExpandedContent:(q)=>F(e,{gap:"sm",className:"py-2",children:[F(D,{className:"text-muted-foreground text-sm",children:["Connection ",q.connectionId]}),F(D,{className:"text-muted-foreground text-sm",children:["Last run: ",N(q.lastRunAt)]}),F(D,{className:"text-muted-foreground text-sm",children:["Last status: ",q.lastRunStatus??"No runs recorded"]}),F(D,{className:"text-muted-foreground text-sm",children:["Updated ",q.updatedAt.toLocaleString()]})]}),getCanExpand:()=>!0});return L(kq,{controller:W,title:"Sync Configs",description:"Shared table primitives applied to sync monitoring without changing the surrounding dashboard layout.",toolbar:L(I,{controller:W,label:`${K.length} syncs`,toggleColumnId:"lastRunAt",toggleVisibleLabel:"Hide Last Run",toggleHiddenLabel:"Show Last Run",pinColumnId:"status",pinLabel:"Status",resizeColumnId:"sync",resizeLabel:"Widen Sync"}),emptyState:L("div",{className:"rounded-md border border-dashed p-8 text-center text-muted-foreground text-sm",children:"No sync configurations found"})})}import{Button as n,ErrorState as Rq,LoaderBlock as _q,StatCard as j,StatCardGroup as Nq}from"@contractspec/lib.design-system";import{useState as Eq}from"react";import{jsx as Z,jsxs as H}from"react/jsx-runtime";var Lq={ACTIVE:"bg-green-100 text-green-700 dark:bg-green-900/30 dark:text-green-400",INACTIVE:"bg-gray-100 text-gray-700 dark:bg-gray-900/30 dark:text-gray-400",CONNECTED:"bg-green-100 text-green-700 dark:bg-green-900/30 dark:text-green-400",DISCONNECTED:"bg-gray-100 text-gray-700 dark:bg-gray-900/30 dark:text-gray-400",PENDING:"bg-yellow-100 text-yellow-700 dark:bg-yellow-900/30 dark:text-yellow-400",ERROR:"bg-red-100 text-red-700 dark:bg-red-900/30 dark:text-red-400",PAUSED:"bg-yellow-100 text-yellow-700 dark:bg-yellow-900/30 dark:text-yellow-400"},zq={CRM:"\uD83D\uDCCA",MARKETING:"\uD83D\uDCE3",PAYMENT:"\uD83D\uDCB3",COMMUNICATION:"\uD83D\uDCAC",DATA:"\uD83D\uDDC4\uFE0F",CUSTOM:"\u2699\uFE0F"};function AK(){let[K,W]=Eq("integrations"),{integrations:q,connections:J,syncConfigs:Y,loading:X,error:U,stats:P,refetch:O}=x(),$=[{id:"integrations",label:"Integrations",icon:"\uD83D\uDD0C"},{id:"connections",label:"Connections",icon:"\uD83D\uDD17"},{id:"syncs",label:"Sync Configs",icon:"\uD83D\uDD04"},{id:"chat",label:"Chat",icon:"\uD83D\uDCAC"}];if(X)return Z(_q,{label:"Loading Integrations..."});if(U)return Z(Rq,{title:"Failed to load Integrations",description:U.message,onRetry:O,retryLabel:"Retry"});return H("div",{className:"space-y-6",children:[H("div",{className:"flex items-center justify-between",children:[Z("h2",{className:"font-bold text-2xl",children:"Integration Hub"}),H(n,{onClick:()=>alert("Add integration modal"),children:[Z("span",{className:"mr-2",children:"+"})," Add Integration"]})]}),H(Nq,{children:[Z(j,{label:"Integrations",value:P.totalIntegrations,hint:`${P.activeIntegrations} active`}),Z(j,{label:"Connections",value:P.totalConnections,hint:`${P.connectedCount} connected`}),Z(j,{label:"Syncs",value:P.totalSyncs,hint:`${P.activeSyncs} active`})]}),Z(c,{connections:J,integrations:q,syncConfigs:Y}),Z("nav",{className:"flex gap-1 rounded-lg bg-muted p-1",role:"tablist",children:$.map((Q)=>H(n,{type:"button",role:"tab","aria-selected":K===Q.id,onClick:()=>W(Q.id),className:`flex flex-1 items-center justify-center gap-2 rounded-md px-4 py-2 font-medium text-sm transition-colors ${K===Q.id?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,children:[Z("span",{children:Q.icon}),Q.label]},Q.id))}),H("div",{className:"min-h-[400px]",role:"tabpanel",children:[K==="integrations"&&H("div",{className:"grid gap-4 sm:grid-cols-2 lg:grid-cols-3",children:[q.map((Q)=>H("div",{className:"cursor-pointer rounded-lg border border-border bg-card p-4 transition-colors hover:bg-muted/50",children:[H("div",{className:"mb-3 flex items-center gap-3",children:[Z("span",{className:"text-2xl",children:zq[Q.type]??"\u2699\uFE0F"}),H("div",{children:[Z("h3",{className:"font-medium",children:Q.name}),Z("p",{className:"text-muted-foreground text-sm",children:Q.type})]})]}),H("div",{className:"flex items-center justify-between",children:[Z("span",{className:`inline-flex rounded-full px-2 py-0.5 font-medium text-xs ${Lq[Q.status]??""}`,children:Q.status}),Z("span",{className:"text-muted-foreground text-xs",children:Q.createdAt.toLocaleDateString()})]})]},Q.id)),q.length===0&&Z("div",{className:"col-span-full flex h-64 items-center justify-center text-muted-foreground",children:"No integrations configured"})]}),K==="connections"&&Z(y,{connections:J}),K==="chat"&&Z(a,{proxyUrl:"/api/chat",thinkingLevel:"thinking",suggestions:["List my integrations","Show sync status","Add a connection"],className:"min-h-[400px]"}),K==="syncs"&&Z(m,{syncConfigs:Y})]})]})}export{AK as IntegrationDashboard};