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