@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.
- package/dist/connection/connection.enum.js +1 -29
- package/dist/connection/connection.operation.js +1 -124
- package/dist/connection/connection.presentation.js +1 -125
- package/dist/connection/connection.schema.js +1 -71
- package/dist/connection/index.js +1 -127
- package/dist/docs/index.js +5 -49
- package/dist/docs/integration-hub.docblock.js +5 -49
- package/dist/events.js +1 -211
- package/dist/example.js +1 -42
- package/dist/handlers/index.js +5 -292
- package/dist/handlers/integration.handlers.js +5 -292
- package/dist/index.js +8 -2355
- package/dist/integration/index.js +1 -92
- package/dist/integration/integration.enum.js +1 -12
- package/dist/integration/integration.operations.js +1 -89
- package/dist/integration/integration.presentation.js +1 -120
- package/dist/integration/integration.schema.js +1 -42
- package/dist/integration-hub.capability.js +1 -43
- package/dist/integration-hub.feature.js +1 -330
- package/dist/mcp-example.js +1 -154
- package/dist/node/connection/connection.enum.js +1 -29
- package/dist/node/connection/connection.operation.js +1 -124
- package/dist/node/connection/connection.presentation.js +1 -125
- package/dist/node/connection/connection.schema.js +1 -71
- package/dist/node/connection/index.js +1 -127
- package/dist/node/docs/index.js +5 -49
- package/dist/node/docs/integration-hub.docblock.js +5 -49
- package/dist/node/events.js +1 -211
- package/dist/node/example.js +1 -42
- package/dist/node/handlers/index.js +5 -292
- package/dist/node/handlers/integration.handlers.js +5 -292
- package/dist/node/index.js +8 -2355
- package/dist/node/integration/index.js +1 -92
- package/dist/node/integration/integration.enum.js +1 -12
- package/dist/node/integration/integration.operations.js +1 -89
- package/dist/node/integration/integration.presentation.js +1 -120
- package/dist/node/integration/integration.schema.js +1 -42
- package/dist/node/integration-hub.capability.js +1 -43
- package/dist/node/integration-hub.feature.js +1 -330
- package/dist/node/mcp-example.js +1 -154
- package/dist/node/run-mcp.js +1 -159
- package/dist/node/seeders/index.js +6 -60
- package/dist/node/sync/index.js +1 -332
- package/dist/node/sync/sync.enum.js +1 -26
- package/dist/node/sync/sync.operations.js +1 -321
- package/dist/node/sync/sync.presentation.js +1 -301
- package/dist/node/sync/sync.schema.js +1 -154
- package/dist/node/sync-engine/index.js +1 -186
- package/dist/node/tests/operations.test-spec.js +1 -85
- package/dist/node/ui/IntegrationDashboard.js +1 -886
- package/dist/node/ui/IntegrationDashboard.visualizations.js +1 -250
- package/dist/node/ui/IntegrationHubChat.js +1 -34
- package/dist/node/ui/hooks/index.js +1 -57
- package/dist/node/ui/hooks/useIntegrationData.js +1 -54
- package/dist/node/ui/index.js +4 -1173
- package/dist/node/ui/renderers/index.js +4 -484
- package/dist/node/ui/renderers/integration.markdown.js +4 -484
- package/dist/node/ui/tables/ConnectionsTable.js +1 -211
- package/dist/node/ui/tables/IntegrationTables.js +1 -361
- package/dist/node/ui/tables/SyncConfigsTable.js +1 -230
- package/dist/node/ui/tables/integration-table.shared.js +1 -84
- package/dist/node/visualizations/catalog.js +1 -137
- package/dist/node/visualizations/index.js +1 -211
- package/dist/node/visualizations/selectors.js +1 -204
- package/dist/run-mcp.js +1 -159
- package/dist/seeders/index.js +6 -60
- package/dist/sync/index.js +1 -332
- package/dist/sync/sync.enum.js +1 -26
- package/dist/sync/sync.operations.js +1 -321
- package/dist/sync/sync.presentation.js +1 -301
- package/dist/sync/sync.schema.js +1 -154
- package/dist/sync-engine/index.js +1 -186
- package/dist/tests/operations.test-spec.js +1 -85
- package/dist/ui/IntegrationDashboard.js +1 -886
- package/dist/ui/IntegrationDashboard.visualizations.js +1 -250
- package/dist/ui/IntegrationHubChat.js +1 -34
- package/dist/ui/hooks/index.js +1 -57
- package/dist/ui/hooks/useIntegrationData.js +1 -54
- package/dist/ui/index.js +4 -1173
- package/dist/ui/renderers/index.js +4 -484
- package/dist/ui/renderers/integration.markdown.js +4 -484
- package/dist/ui/tables/ConnectionsTable.js +1 -211
- package/dist/ui/tables/IntegrationTables.js +1 -361
- package/dist/ui/tables/SyncConfigsTable.js +1 -230
- package/dist/ui/tables/integration-table.shared.js +1 -84
- package/dist/visualizations/catalog.js +1 -137
- package/dist/visualizations/index.js +1 -211
- package/dist/visualizations/selectors.js +1 -204
- package/package.json +11 -11
|
@@ -1,330 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
defineVisualization,
|
|
4
|
-
VisualizationRegistry
|
|
5
|
-
} from "@contractspec/lib.contracts-spec/visualizations";
|
|
6
|
-
var INTEGRATION_LIST_REF = {
|
|
7
|
-
key: "integration.list",
|
|
8
|
-
version: "1.0.0"
|
|
9
|
-
};
|
|
10
|
-
var CONNECTION_LIST_REF = {
|
|
11
|
-
key: "integration.connection.list",
|
|
12
|
-
version: "1.0.0"
|
|
13
|
-
};
|
|
14
|
-
var SYNC_CONFIG_REF = {
|
|
15
|
-
key: "integration.syncConfig.list",
|
|
16
|
-
version: "1.0.0"
|
|
17
|
-
};
|
|
18
|
-
var META = {
|
|
19
|
-
version: "1.0.0",
|
|
20
|
-
domain: "integration",
|
|
21
|
-
stability: "experimental",
|
|
22
|
-
owners: ["@example.integration-hub"],
|
|
23
|
-
tags: ["integration", "visualization", "sync"]
|
|
24
|
-
};
|
|
25
|
-
var IntegrationTypeVisualization = defineVisualization({
|
|
26
|
-
meta: {
|
|
27
|
-
...META,
|
|
28
|
-
key: "integration-hub.visualization.integration-types",
|
|
29
|
-
title: "Integration Types",
|
|
30
|
-
description: "Distribution of configured integration categories.",
|
|
31
|
-
goal: "Show where integration coverage is concentrated.",
|
|
32
|
-
context: "Integration overview."
|
|
33
|
-
},
|
|
34
|
-
source: { primary: INTEGRATION_LIST_REF, resultPath: "data" },
|
|
35
|
-
visualization: {
|
|
36
|
-
kind: "pie",
|
|
37
|
-
nameDimension: "type",
|
|
38
|
-
valueMeasure: "count",
|
|
39
|
-
dimensions: [
|
|
40
|
-
{ key: "type", label: "Type", dataPath: "type", type: "category" }
|
|
41
|
-
],
|
|
42
|
-
measures: [
|
|
43
|
-
{ key: "count", label: "Count", dataPath: "count", format: "number" }
|
|
44
|
-
],
|
|
45
|
-
table: { caption: "Integration counts by type." }
|
|
46
|
-
}
|
|
47
|
-
});
|
|
48
|
-
var ConnectionStatusVisualization = defineVisualization({
|
|
49
|
-
meta: {
|
|
50
|
-
...META,
|
|
51
|
-
key: "integration-hub.visualization.connection-status",
|
|
52
|
-
title: "Connection Status",
|
|
53
|
-
description: "Status distribution across configured connections.",
|
|
54
|
-
goal: "Highlight connection health and instability.",
|
|
55
|
-
context: "Connection monitoring."
|
|
56
|
-
},
|
|
57
|
-
source: { primary: CONNECTION_LIST_REF, resultPath: "data" },
|
|
58
|
-
visualization: {
|
|
59
|
-
kind: "cartesian",
|
|
60
|
-
variant: "bar",
|
|
61
|
-
xDimension: "status",
|
|
62
|
-
yMeasures: ["count"],
|
|
63
|
-
dimensions: [
|
|
64
|
-
{ key: "status", label: "Status", dataPath: "status", type: "category" }
|
|
65
|
-
],
|
|
66
|
-
measures: [
|
|
67
|
-
{
|
|
68
|
-
key: "count",
|
|
69
|
-
label: "Connections",
|
|
70
|
-
dataPath: "count",
|
|
71
|
-
format: "number",
|
|
72
|
-
color: "#1d4ed8"
|
|
73
|
-
}
|
|
74
|
-
],
|
|
75
|
-
table: { caption: "Connection counts by status." }
|
|
76
|
-
}
|
|
77
|
-
});
|
|
78
|
-
var HealthySyncMetricVisualization = defineVisualization({
|
|
79
|
-
meta: {
|
|
80
|
-
...META,
|
|
81
|
-
key: "integration-hub.visualization.sync-healthy",
|
|
82
|
-
title: "Healthy Syncs",
|
|
83
|
-
description: "Sync configurations currently healthy or recently successful.",
|
|
84
|
-
goal: "Summarize healthy synchronization capacity.",
|
|
85
|
-
context: "Sync-state comparison."
|
|
86
|
-
},
|
|
87
|
-
source: { primary: SYNC_CONFIG_REF, resultPath: "data" },
|
|
88
|
-
visualization: {
|
|
89
|
-
kind: "metric",
|
|
90
|
-
measure: "value",
|
|
91
|
-
measures: [
|
|
92
|
-
{ key: "value", label: "Syncs", dataPath: "value", format: "number" }
|
|
93
|
-
],
|
|
94
|
-
table: { caption: "Healthy sync count." }
|
|
95
|
-
}
|
|
96
|
-
});
|
|
97
|
-
var AttentionSyncMetricVisualization = defineVisualization({
|
|
98
|
-
meta: {
|
|
99
|
-
...META,
|
|
100
|
-
key: "integration-hub.visualization.sync-attention",
|
|
101
|
-
title: "Attention Needed",
|
|
102
|
-
description: "Sync configurations paused, failing, or otherwise needing review.",
|
|
103
|
-
goal: "Summarize syncs needing action.",
|
|
104
|
-
context: "Sync-state comparison."
|
|
105
|
-
},
|
|
106
|
-
source: { primary: SYNC_CONFIG_REF, resultPath: "data" },
|
|
107
|
-
visualization: {
|
|
108
|
-
kind: "metric",
|
|
109
|
-
measure: "value",
|
|
110
|
-
measures: [
|
|
111
|
-
{ key: "value", label: "Syncs", dataPath: "value", format: "number" }
|
|
112
|
-
],
|
|
113
|
-
table: { caption: "Syncs requiring attention." }
|
|
114
|
-
}
|
|
115
|
-
});
|
|
116
|
-
var IntegrationVisualizationSpecs = [
|
|
117
|
-
IntegrationTypeVisualization,
|
|
118
|
-
ConnectionStatusVisualization,
|
|
119
|
-
HealthySyncMetricVisualization,
|
|
120
|
-
AttentionSyncMetricVisualization
|
|
121
|
-
];
|
|
122
|
-
var IntegrationVisualizationRegistry = new VisualizationRegistry([
|
|
123
|
-
...IntegrationVisualizationSpecs
|
|
124
|
-
]);
|
|
125
|
-
var IntegrationVisualizationRefs = IntegrationVisualizationSpecs.map((spec) => ({
|
|
126
|
-
key: spec.meta.key,
|
|
127
|
-
version: spec.meta.version
|
|
128
|
-
}));
|
|
129
|
-
|
|
130
|
-
// src/visualizations/selectors.ts
|
|
131
|
-
function isHealthySync(status) {
|
|
132
|
-
return status === "ACTIVE" || status === "SUCCESS";
|
|
133
|
-
}
|
|
134
|
-
function createIntegrationVisualizationSections(integrations, connections, syncConfigs) {
|
|
135
|
-
const integrationTypes = new Map;
|
|
136
|
-
const connectionStatuses = new Map;
|
|
137
|
-
let healthySyncs = 0;
|
|
138
|
-
let attentionSyncs = 0;
|
|
139
|
-
for (const integration of integrations) {
|
|
140
|
-
integrationTypes.set(integration.type, (integrationTypes.get(integration.type) ?? 0) + 1);
|
|
141
|
-
}
|
|
142
|
-
for (const connection of connections) {
|
|
143
|
-
connectionStatuses.set(connection.status, (connectionStatuses.get(connection.status) ?? 0) + 1);
|
|
144
|
-
}
|
|
145
|
-
for (const syncConfig of syncConfigs) {
|
|
146
|
-
if (isHealthySync(syncConfig.status)) {
|
|
147
|
-
healthySyncs += 1;
|
|
148
|
-
} else {
|
|
149
|
-
attentionSyncs += 1;
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
const primaryItems = [
|
|
153
|
-
{
|
|
154
|
-
key: "integration-types",
|
|
155
|
-
spec: IntegrationTypeVisualization,
|
|
156
|
-
data: {
|
|
157
|
-
data: Array.from(integrationTypes.entries()).map(([type, count]) => ({
|
|
158
|
-
type,
|
|
159
|
-
count
|
|
160
|
-
}))
|
|
161
|
-
},
|
|
162
|
-
title: "Integration Types",
|
|
163
|
-
description: "Configured integrations grouped by category.",
|
|
164
|
-
height: 260
|
|
165
|
-
},
|
|
166
|
-
{
|
|
167
|
-
key: "connection-status",
|
|
168
|
-
spec: ConnectionStatusVisualization,
|
|
169
|
-
data: {
|
|
170
|
-
data: Array.from(connectionStatuses.entries()).map(([status, count]) => ({
|
|
171
|
-
status,
|
|
172
|
-
count
|
|
173
|
-
}))
|
|
174
|
-
},
|
|
175
|
-
title: "Connection Status",
|
|
176
|
-
description: "Operational health across current connections."
|
|
177
|
-
}
|
|
178
|
-
];
|
|
179
|
-
const comparisonItems = [
|
|
180
|
-
{
|
|
181
|
-
key: "healthy-syncs",
|
|
182
|
-
spec: HealthySyncMetricVisualization,
|
|
183
|
-
data: { data: [{ value: healthySyncs }] },
|
|
184
|
-
title: "Healthy Syncs",
|
|
185
|
-
description: "Active or recently successful sync configurations.",
|
|
186
|
-
height: 200
|
|
187
|
-
},
|
|
188
|
-
{
|
|
189
|
-
key: "attention-syncs",
|
|
190
|
-
spec: AttentionSyncMetricVisualization,
|
|
191
|
-
data: { data: [{ value: attentionSyncs }] },
|
|
192
|
-
title: "Attention Needed",
|
|
193
|
-
description: "Paused, failed, or degraded sync configurations.",
|
|
194
|
-
height: 200
|
|
195
|
-
}
|
|
196
|
-
];
|
|
197
|
-
return {
|
|
198
|
-
primaryItems,
|
|
199
|
-
comparisonItems
|
|
200
|
-
};
|
|
201
|
-
}
|
|
202
|
-
// src/integration-hub.feature.ts
|
|
203
|
-
import { defineFeature } from "@contractspec/lib.contracts-spec";
|
|
204
|
-
var IntegrationHubFeature = defineFeature({
|
|
205
|
-
meta: {
|
|
206
|
-
key: "integration-hub",
|
|
207
|
-
version: "1.0.0",
|
|
208
|
-
title: "Integration Hub",
|
|
209
|
-
description: "Connect and sync data with external systems through configurable integrations",
|
|
210
|
-
domain: "integration",
|
|
211
|
-
owners: ["@integration-team"],
|
|
212
|
-
tags: ["integration", "sync", "etl", "connectors"],
|
|
213
|
-
stability: "experimental"
|
|
214
|
-
},
|
|
215
|
-
operations: [
|
|
216
|
-
{ key: "integration.create", version: "1.0.0" },
|
|
217
|
-
{ key: "integration.connection.create", version: "1.0.0" },
|
|
218
|
-
{ key: "integration.syncConfig.create", version: "1.0.0" },
|
|
219
|
-
{ key: "integration.fieldMapping.add", version: "1.0.0" },
|
|
220
|
-
{ key: "integration.sync.trigger", version: "1.0.0" },
|
|
221
|
-
{ key: "integration.syncRun.list", version: "1.0.0" }
|
|
222
|
-
],
|
|
223
|
-
events: [
|
|
224
|
-
{ key: "integration.created", version: "1.0.0" },
|
|
225
|
-
{ key: "integration.connection.created", version: "1.0.0" },
|
|
226
|
-
{ key: "integration.connection.statusChanged", version: "1.0.0" },
|
|
227
|
-
{ key: "integration.syncConfig.created", version: "1.0.0" },
|
|
228
|
-
{ key: "integration.sync.started", version: "1.0.0" },
|
|
229
|
-
{ key: "integration.sync.completed", version: "1.0.0" },
|
|
230
|
-
{ key: "integration.sync.failed", version: "1.0.0" },
|
|
231
|
-
{ key: "integration.record.synced", version: "1.0.0" },
|
|
232
|
-
{ key: "integration.fieldMapping.added", version: "1.0.0" }
|
|
233
|
-
],
|
|
234
|
-
presentations: [
|
|
235
|
-
{ key: "integration.list", version: "1.0.0" },
|
|
236
|
-
{ key: "integration.detail", version: "1.0.0" },
|
|
237
|
-
{ key: "integration.connection.list", version: "1.0.0" },
|
|
238
|
-
{ key: "integration.connection.setup", version: "1.0.0" },
|
|
239
|
-
{ key: "integration.syncConfig.list", version: "1.0.0" },
|
|
240
|
-
{ key: "integration.syncConfig.editor", version: "1.0.0" },
|
|
241
|
-
{ key: "integration.fieldMapping.editor", version: "1.0.0" },
|
|
242
|
-
{ key: "integration.syncRun.viewList", version: "1.0.0" },
|
|
243
|
-
{ key: "integration.syncRun.detail", version: "1.0.0" },
|
|
244
|
-
{ key: "integration.health", version: "1.0.0" },
|
|
245
|
-
{ key: "integration.sync.activity", version: "1.0.0" }
|
|
246
|
-
],
|
|
247
|
-
opToPresentation: [
|
|
248
|
-
{
|
|
249
|
-
op: { key: "integration.syncConfig.create", version: "1.0.0" },
|
|
250
|
-
pres: { key: "integration.syncConfig.editor", version: "1.0.0" }
|
|
251
|
-
},
|
|
252
|
-
{
|
|
253
|
-
op: { key: "integration.fieldMapping.add", version: "1.0.0" },
|
|
254
|
-
pres: { key: "integration.fieldMapping.editor", version: "1.0.0" }
|
|
255
|
-
},
|
|
256
|
-
{
|
|
257
|
-
op: { key: "integration.syncRun.list", version: "1.0.0" },
|
|
258
|
-
pres: { key: "integration.syncRun.viewList", version: "1.0.0" }
|
|
259
|
-
}
|
|
260
|
-
],
|
|
261
|
-
presentationsTargets: [
|
|
262
|
-
{
|
|
263
|
-
key: "integration.list",
|
|
264
|
-
version: "1.0.0",
|
|
265
|
-
targets: ["react", "markdown"]
|
|
266
|
-
},
|
|
267
|
-
{
|
|
268
|
-
key: "integration.detail",
|
|
269
|
-
version: "1.0.0",
|
|
270
|
-
targets: ["react", "markdown"]
|
|
271
|
-
},
|
|
272
|
-
{
|
|
273
|
-
key: "integration.syncConfig.list",
|
|
274
|
-
version: "1.0.0",
|
|
275
|
-
targets: ["react", "markdown"]
|
|
276
|
-
},
|
|
277
|
-
{
|
|
278
|
-
key: "integration.syncConfig.editor",
|
|
279
|
-
version: "1.0.0",
|
|
280
|
-
targets: ["react"]
|
|
281
|
-
},
|
|
282
|
-
{
|
|
283
|
-
key: "integration.fieldMapping.editor",
|
|
284
|
-
version: "1.0.0",
|
|
285
|
-
targets: ["react"]
|
|
286
|
-
},
|
|
287
|
-
{
|
|
288
|
-
key: "integration.syncRun.viewList",
|
|
289
|
-
version: "1.0.0",
|
|
290
|
-
targets: ["react", "markdown"]
|
|
291
|
-
},
|
|
292
|
-
{
|
|
293
|
-
key: "integration.syncRun.detail",
|
|
294
|
-
version: "1.0.0",
|
|
295
|
-
targets: ["react", "markdown"]
|
|
296
|
-
}
|
|
297
|
-
],
|
|
298
|
-
visualizations: IntegrationVisualizationRefs,
|
|
299
|
-
capabilities: {
|
|
300
|
-
requires: [
|
|
301
|
-
{ key: "identity", version: "1.0.0" },
|
|
302
|
-
{ key: "audit-trail", version: "1.0.0" },
|
|
303
|
-
{ key: "feature-flags", version: "1.0.0" },
|
|
304
|
-
{ key: "jobs", version: "1.0.0" },
|
|
305
|
-
{ key: "files", version: "1.0.0" }
|
|
306
|
-
],
|
|
307
|
-
provides: [
|
|
308
|
-
{ key: "integration", version: "1.0.0" },
|
|
309
|
-
{ key: "sync", version: "1.0.0" },
|
|
310
|
-
{ key: "etl", version: "1.0.0" }
|
|
311
|
-
]
|
|
312
|
-
},
|
|
313
|
-
integrations: [
|
|
314
|
-
{ key: "integration-hub.integration.default-connector", version: "1.0.0" }
|
|
315
|
-
],
|
|
316
|
-
telemetry: [{ key: "integration-hub.telemetry", version: "1.0.0" }],
|
|
317
|
-
jobs: [
|
|
318
|
-
{ key: "integration-hub.job.sync-run", version: "1.0.0" },
|
|
319
|
-
{ key: "integration-hub.job.health-check", version: "1.0.0" }
|
|
320
|
-
],
|
|
321
|
-
docs: [
|
|
322
|
-
"docs.examples.integration-hub",
|
|
323
|
-
"docs.examples.integration-hub.goal",
|
|
324
|
-
"docs.examples.integration-hub.usage",
|
|
325
|
-
"docs.examples.integration-hub.constraints"
|
|
326
|
-
]
|
|
327
|
-
});
|
|
328
|
-
export {
|
|
329
|
-
IntegrationHubFeature
|
|
330
|
-
};
|
|
1
|
+
import{defineVisualization as j,VisualizationRegistry as v}from"@contractspec/lib.contracts-spec/visualizations";var L={key:"integration.list",version:"1.0.0"},Y={key:"integration.connection.list",version:"1.0.0"},W={key:"integration.syncConfig.list",version:"1.0.0"},k={version:"1.0.0",domain:"integration",stability:"experimental",owners:["@example.integration-hub"],tags:["integration","visualization","sync"]},D=j({meta:{...k,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:L,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."}}}),J=j({meta:{...k,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:Y,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."}}}),K=j({meta:{...k,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:W,resultPath:"data"},visualization:{kind:"metric",measure:"value",measures:[{key:"value",label:"Syncs",dataPath:"value",format:"number"}],table:{caption:"Healthy sync count."}}}),P=j({meta:{...k,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:W,resultPath:"data"},visualization:{kind:"metric",measure:"value",measures:[{key:"value",label:"Syncs",dataPath:"value",format:"number"}],table:{caption:"Syncs requiring attention."}}}),X=[D,J,K,P],f=new v([...X]),Z=X.map((x)=>({key:x.meta.key,version:x.meta.version}));function G(x){return x==="ACTIVE"||x==="SUCCESS"}function F(x,$,b){let q=new Map,w=new Map,Q=0,U=0;for(let m of x)q.set(m.type,(q.get(m.type)??0)+1);for(let m of $)w.set(m.status,(w.get(m.status)??0)+1);for(let m of b)if(G(m.status))Q+=1;else U+=1;return{primaryItems:[{key:"integration-types",spec:D,data:{data:Array.from(q.entries()).map(([m,B])=>({type:m,count:B}))},title:"Integration Types",description:"Configured integrations grouped by category.",height:260},{key:"connection-status",spec:J,data:{data:Array.from(w.entries()).map(([m,B])=>({status:m,count:B}))},title:"Connection Status",description:"Operational health across current connections."}],comparisonItems:[{key:"healthy-syncs",spec:K,data:{data:[{value:Q}]},title:"Healthy Syncs",description:"Active or recently successful sync configurations.",height:200},{key:"attention-syncs",spec:P,data:{data:[{value:U}]},title:"Attention Needed",description:"Paused, failed, or degraded sync configurations.",height:200}]}}import{defineFeature as H}from"@contractspec/lib.contracts-spec";var p=H({meta:{key:"integration-hub",version:"1.0.0",title:"Integration Hub",description:"Connect and sync data with external systems through configurable integrations",domain:"integration",owners:["@integration-team"],tags:["integration","sync","etl","connectors"],stability:"experimental"},operations:[{key:"integration.create",version:"1.0.0"},{key:"integration.connection.create",version:"1.0.0"},{key:"integration.syncConfig.create",version:"1.0.0"},{key:"integration.fieldMapping.add",version:"1.0.0"},{key:"integration.sync.trigger",version:"1.0.0"},{key:"integration.syncRun.list",version:"1.0.0"}],events:[{key:"integration.created",version:"1.0.0"},{key:"integration.connection.created",version:"1.0.0"},{key:"integration.connection.statusChanged",version:"1.0.0"},{key:"integration.syncConfig.created",version:"1.0.0"},{key:"integration.sync.started",version:"1.0.0"},{key:"integration.sync.completed",version:"1.0.0"},{key:"integration.sync.failed",version:"1.0.0"},{key:"integration.record.synced",version:"1.0.0"},{key:"integration.fieldMapping.added",version:"1.0.0"}],presentations:[{key:"integration.list",version:"1.0.0"},{key:"integration.detail",version:"1.0.0"},{key:"integration.connection.list",version:"1.0.0"},{key:"integration.connection.setup",version:"1.0.0"},{key:"integration.syncConfig.list",version:"1.0.0"},{key:"integration.syncConfig.editor",version:"1.0.0"},{key:"integration.fieldMapping.editor",version:"1.0.0"},{key:"integration.syncRun.viewList",version:"1.0.0"},{key:"integration.syncRun.detail",version:"1.0.0"},{key:"integration.health",version:"1.0.0"},{key:"integration.sync.activity",version:"1.0.0"}],opToPresentation:[{op:{key:"integration.syncConfig.create",version:"1.0.0"},pres:{key:"integration.syncConfig.editor",version:"1.0.0"}},{op:{key:"integration.fieldMapping.add",version:"1.0.0"},pres:{key:"integration.fieldMapping.editor",version:"1.0.0"}},{op:{key:"integration.syncRun.list",version:"1.0.0"},pres:{key:"integration.syncRun.viewList",version:"1.0.0"}}],presentationsTargets:[{key:"integration.list",version:"1.0.0",targets:["react","markdown"]},{key:"integration.detail",version:"1.0.0",targets:["react","markdown"]},{key:"integration.syncConfig.list",version:"1.0.0",targets:["react","markdown"]},{key:"integration.syncConfig.editor",version:"1.0.0",targets:["react"]},{key:"integration.fieldMapping.editor",version:"1.0.0",targets:["react"]},{key:"integration.syncRun.viewList",version:"1.0.0",targets:["react","markdown"]},{key:"integration.syncRun.detail",version:"1.0.0",targets:["react","markdown"]}],visualizations:Z,capabilities:{requires:[{key:"identity",version:"1.0.0"},{key:"audit-trail",version:"1.0.0"},{key:"feature-flags",version:"1.0.0"},{key:"jobs",version:"1.0.0"},{key:"files",version:"1.0.0"}],provides:[{key:"integration",version:"1.0.0"},{key:"sync",version:"1.0.0"},{key:"etl",version:"1.0.0"}]},integrations:[{key:"integration-hub.integration.default-connector",version:"1.0.0"}],telemetry:[{key:"integration-hub.telemetry",version:"1.0.0"}],jobs:[{key:"integration-hub.job.sync-run",version:"1.0.0"},{key:"integration-hub.job.health-check",version:"1.0.0"}],docs:["docs.examples.integration-hub","docs.examples.integration-hub.goal","docs.examples.integration-hub.usage","docs.examples.integration-hub.constraints"]});export{p as IntegrationHubFeature};
|
package/dist/node/mcp-example.js
CHANGED
|
@@ -1,154 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
createMcpToolsets
|
|
4
|
-
} from "@contractspec/lib.ai-agent/tools/mcp-client";
|
|
5
|
-
import { randomUUID } from "crypto";
|
|
6
|
-
var DEFAULT_STDIO_ARGS = [
|
|
7
|
-
"-y",
|
|
8
|
-
"@modelcontextprotocol/server-filesystem",
|
|
9
|
-
"."
|
|
10
|
-
];
|
|
11
|
-
async function runIntegrationHubMcpExampleFromEnv() {
|
|
12
|
-
const mode = resolveMode();
|
|
13
|
-
const transport = resolveTransport();
|
|
14
|
-
const config = buildMcpConfigFromEnv();
|
|
15
|
-
const toolset = await createMcpToolsets([config], {
|
|
16
|
-
onNameCollision: "error"
|
|
17
|
-
});
|
|
18
|
-
try {
|
|
19
|
-
const toolNames = Object.keys(toolset.tools).sort();
|
|
20
|
-
const output = {
|
|
21
|
-
mode,
|
|
22
|
-
server: {
|
|
23
|
-
name: config.name,
|
|
24
|
-
transport
|
|
25
|
-
},
|
|
26
|
-
authMethod: process.env.CONTRACTSPEC_INTEGRATION_HUB_MCP_AUTH_METHOD,
|
|
27
|
-
apiVersion: process.env.CONTRACTSPEC_INTEGRATION_HUB_MCP_API_VERSION,
|
|
28
|
-
tools: toolNames
|
|
29
|
-
};
|
|
30
|
-
if (mode === "call") {
|
|
31
|
-
const toolName = requireEnv("CONTRACTSPEC_INTEGRATION_HUB_MCP_TOOL_NAME");
|
|
32
|
-
const toolArgs = parseRecordEnvOrDefault("CONTRACTSPEC_INTEGRATION_HUB_MCP_TOOL_ARGS_JSON", {});
|
|
33
|
-
const tool = toolset.tools[toolName];
|
|
34
|
-
if (!tool?.execute) {
|
|
35
|
-
throw new Error(`Tool "${toolName}" was not found. Available tools: ${toolNames.join(", ")}`);
|
|
36
|
-
}
|
|
37
|
-
const toolOutput = await tool.execute(toolArgs, {
|
|
38
|
-
toolCallId: `integration-hub-${randomUUID()}`,
|
|
39
|
-
messages: []
|
|
40
|
-
});
|
|
41
|
-
output.toolCall = {
|
|
42
|
-
name: toolName,
|
|
43
|
-
args: toolArgs,
|
|
44
|
-
output: toolOutput
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
return output;
|
|
48
|
-
} finally {
|
|
49
|
-
await toolset.cleanup().catch(() => {
|
|
50
|
-
return;
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
function buildMcpConfigFromEnv() {
|
|
55
|
-
const name = process.env.CONTRACTSPEC_INTEGRATION_HUB_MCP_NAME ?? "filesystem";
|
|
56
|
-
const transport = resolveTransport();
|
|
57
|
-
const toolPrefix = process.env.CONTRACTSPEC_INTEGRATION_HUB_MCP_TOOL_PREFIX;
|
|
58
|
-
if (transport === "stdio") {
|
|
59
|
-
return {
|
|
60
|
-
name,
|
|
61
|
-
transport,
|
|
62
|
-
command: process.env.CONTRACTSPEC_INTEGRATION_HUB_MCP_COMMAND ?? "npx",
|
|
63
|
-
args: parseStringArrayEnv("CONTRACTSPEC_INTEGRATION_HUB_MCP_ARGS_JSON", DEFAULT_STDIO_ARGS),
|
|
64
|
-
toolPrefix
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
const accessToken = process.env.CONTRACTSPEC_INTEGRATION_HUB_MCP_ACCESS_TOKEN;
|
|
68
|
-
const accessTokenEnvVar = process.env.CONTRACTSPEC_INTEGRATION_HUB_MCP_ACCESS_TOKEN_ENV;
|
|
69
|
-
const mcpTransport = transport === "webhook" || transport === "http" ? "http" : "sse";
|
|
70
|
-
return {
|
|
71
|
-
name,
|
|
72
|
-
transport: mcpTransport,
|
|
73
|
-
url: requireEnv("CONTRACTSPEC_INTEGRATION_HUB_MCP_URL"),
|
|
74
|
-
headers: parseStringRecordEnv("CONTRACTSPEC_INTEGRATION_HUB_MCP_HEADERS_JSON"),
|
|
75
|
-
accessToken,
|
|
76
|
-
accessTokenEnvVar,
|
|
77
|
-
toolPrefix
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
function resolveMode() {
|
|
81
|
-
const rawMode = process.env.CONTRACTSPEC_INTEGRATION_HUB_MCP_MODE?.toLowerCase() ?? "list";
|
|
82
|
-
if (rawMode === "list" || rawMode === "call") {
|
|
83
|
-
return rawMode;
|
|
84
|
-
}
|
|
85
|
-
throw new Error(`Unsupported CONTRACTSPEC_INTEGRATION_HUB_MCP_MODE: ${rawMode}. Use "list" or "call".`);
|
|
86
|
-
}
|
|
87
|
-
function resolveTransport() {
|
|
88
|
-
const rawTransport = process.env.CONTRACTSPEC_INTEGRATION_HUB_MCP_TRANSPORT?.toLowerCase() ?? "stdio";
|
|
89
|
-
if (rawTransport === "stdio" || rawTransport === "http" || rawTransport === "sse" || rawTransport === "webhook") {
|
|
90
|
-
return rawTransport;
|
|
91
|
-
}
|
|
92
|
-
throw new Error(`Unsupported CONTRACTSPEC_INTEGRATION_HUB_MCP_TRANSPORT: ${rawTransport}. Use "stdio", "http", "sse", or "webhook".`);
|
|
93
|
-
}
|
|
94
|
-
function parseStringArrayEnv(key, fallback) {
|
|
95
|
-
const raw = process.env[key];
|
|
96
|
-
if (!raw) {
|
|
97
|
-
return fallback;
|
|
98
|
-
}
|
|
99
|
-
const parsed = parseJsonEnv(key);
|
|
100
|
-
if (!Array.isArray(parsed) || parsed.some((value) => typeof value !== "string")) {
|
|
101
|
-
throw new Error(`${key} must be a JSON string array.`);
|
|
102
|
-
}
|
|
103
|
-
return parsed;
|
|
104
|
-
}
|
|
105
|
-
function parseRecordEnv(key) {
|
|
106
|
-
const raw = process.env[key];
|
|
107
|
-
if (!raw) {
|
|
108
|
-
return;
|
|
109
|
-
}
|
|
110
|
-
const parsed = parseJsonEnv(key);
|
|
111
|
-
if (!isRecord(parsed)) {
|
|
112
|
-
throw new Error(`${key} must be a JSON object.`);
|
|
113
|
-
}
|
|
114
|
-
return parsed;
|
|
115
|
-
}
|
|
116
|
-
function parseRecordEnvOrDefault(key, fallback) {
|
|
117
|
-
return parseRecordEnv(key) ?? fallback;
|
|
118
|
-
}
|
|
119
|
-
function parseStringRecordEnv(key) {
|
|
120
|
-
const parsed = parseRecordEnv(key);
|
|
121
|
-
if (!parsed) {
|
|
122
|
-
return;
|
|
123
|
-
}
|
|
124
|
-
const entries = Object.entries(parsed);
|
|
125
|
-
const invalidEntry = entries.find(([, value]) => typeof value !== "string");
|
|
126
|
-
if (invalidEntry) {
|
|
127
|
-
throw new Error(`${key} must contain only string values.`);
|
|
128
|
-
}
|
|
129
|
-
return Object.fromEntries(entries);
|
|
130
|
-
}
|
|
131
|
-
function parseJsonEnv(key) {
|
|
132
|
-
const raw = process.env[key];
|
|
133
|
-
if (!raw) {
|
|
134
|
-
return;
|
|
135
|
-
}
|
|
136
|
-
try {
|
|
137
|
-
return JSON.parse(raw);
|
|
138
|
-
} catch {
|
|
139
|
-
throw new Error(`${key} contains invalid JSON.`);
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
function requireEnv(key) {
|
|
143
|
-
const value = process.env[key];
|
|
144
|
-
if (!value) {
|
|
145
|
-
throw new Error(`Missing required env var: ${key}`);
|
|
146
|
-
}
|
|
147
|
-
return value;
|
|
148
|
-
}
|
|
149
|
-
function isRecord(value) {
|
|
150
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
151
|
-
}
|
|
152
|
-
export {
|
|
153
|
-
runIntegrationHubMcpExampleFromEnv
|
|
154
|
-
};
|
|
1
|
+
import{createMcpToolsets as L}from"@contractspec/lib.ai-agent/tools/mcp-client";import{randomUUID as V}from"crypto";var q=["-y","@modelcontextprotocol/server-filesystem","."];async function D(){let h=F(),j=Y(),z=x(),B=await L([z],{onNameCollision:"error"});try{let H=Object.keys(B.tools).sort(),K={mode:h,server:{name:z.name,transport:j},authMethod:process.env.CONTRACTSPEC_INTEGRATION_HUB_MCP_AUTH_METHOD,apiVersion:process.env.CONTRACTSPEC_INTEGRATION_HUB_MCP_API_VERSION,tools:H};if(h==="call"){let Q=C("CONTRACTSPEC_INTEGRATION_HUB_MCP_TOOL_NAME"),W=J("CONTRACTSPEC_INTEGRATION_HUB_MCP_TOOL_ARGS_JSON",{}),X=B.tools[Q];if(!X?.execute)throw Error(`Tool "${Q}" was not found. Available tools: ${H.join(", ")}`);let G=await X.execute(W,{toolCallId:`integration-hub-${V()}`,messages:[]});K.toolCall={name:Q,args:W,output:G}}return K}finally{await B.cleanup().catch(()=>{return})}}function x(){let h=process.env.CONTRACTSPEC_INTEGRATION_HUB_MCP_NAME??"filesystem",j=Y(),z=process.env.CONTRACTSPEC_INTEGRATION_HUB_MCP_TOOL_PREFIX;if(j==="stdio")return{name:h,transport:j,command:process.env.CONTRACTSPEC_INTEGRATION_HUB_MCP_COMMAND??"npx",args:I("CONTRACTSPEC_INTEGRATION_HUB_MCP_ARGS_JSON",q),toolPrefix:z};let B=process.env.CONTRACTSPEC_INTEGRATION_HUB_MCP_ACCESS_TOKEN,H=process.env.CONTRACTSPEC_INTEGRATION_HUB_MCP_ACCESS_TOKEN_ENV;return{name:h,transport:j==="webhook"||j==="http"?"http":"sse",url:C("CONTRACTSPEC_INTEGRATION_HUB_MCP_URL"),headers:P("CONTRACTSPEC_INTEGRATION_HUB_MCP_HEADERS_JSON"),accessToken:B,accessTokenEnvVar:H,toolPrefix:z}}function F(){let h=process.env.CONTRACTSPEC_INTEGRATION_HUB_MCP_MODE?.toLowerCase()??"list";if(h==="list"||h==="call")return h;throw Error(`Unsupported CONTRACTSPEC_INTEGRATION_HUB_MCP_MODE: ${h}. Use "list" or "call".`)}function Y(){let h=process.env.CONTRACTSPEC_INTEGRATION_HUB_MCP_TRANSPORT?.toLowerCase()??"stdio";if(h==="stdio"||h==="http"||h==="sse"||h==="webhook")return h;throw Error(`Unsupported CONTRACTSPEC_INTEGRATION_HUB_MCP_TRANSPORT: ${h}. Use "stdio", "http", "sse", or "webhook".`)}function I(h,j){if(!process.env[h])return j;let B=$(h);if(!Array.isArray(B)||B.some((H)=>typeof H!=="string"))throw Error(`${h} must be a JSON string array.`);return B}function Z(h){if(!process.env[h])return;let z=$(h);if(!_(z))throw Error(`${h} must be a JSON object.`);return z}function J(h,j){return Z(h)??j}function P(h){let j=Z(h);if(!j)return;let z=Object.entries(j);if(z.find(([,H])=>typeof H!=="string"))throw Error(`${h} must contain only string values.`);return Object.fromEntries(z)}function $(h){let j=process.env[h];if(!j)return;try{return JSON.parse(j)}catch{throw Error(`${h} contains invalid JSON.`)}}function C(h){let j=process.env[h];if(!j)throw Error(`Missing required env var: ${h}`);return j}function _(h){return typeof h==="object"&&h!==null&&!Array.isArray(h)}export{D as runIntegrationHubMcpExampleFromEnv};
|
package/dist/node/run-mcp.js
CHANGED
|
@@ -1,159 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
createMcpToolsets
|
|
4
|
-
} from "@contractspec/lib.ai-agent/tools/mcp-client";
|
|
5
|
-
import { randomUUID } from "crypto";
|
|
6
|
-
var DEFAULT_STDIO_ARGS = [
|
|
7
|
-
"-y",
|
|
8
|
-
"@modelcontextprotocol/server-filesystem",
|
|
9
|
-
"."
|
|
10
|
-
];
|
|
11
|
-
async function runIntegrationHubMcpExampleFromEnv() {
|
|
12
|
-
const mode = resolveMode();
|
|
13
|
-
const transport = resolveTransport();
|
|
14
|
-
const config = buildMcpConfigFromEnv();
|
|
15
|
-
const toolset = await createMcpToolsets([config], {
|
|
16
|
-
onNameCollision: "error"
|
|
17
|
-
});
|
|
18
|
-
try {
|
|
19
|
-
const toolNames = Object.keys(toolset.tools).sort();
|
|
20
|
-
const output = {
|
|
21
|
-
mode,
|
|
22
|
-
server: {
|
|
23
|
-
name: config.name,
|
|
24
|
-
transport
|
|
25
|
-
},
|
|
26
|
-
authMethod: process.env.CONTRACTSPEC_INTEGRATION_HUB_MCP_AUTH_METHOD,
|
|
27
|
-
apiVersion: process.env.CONTRACTSPEC_INTEGRATION_HUB_MCP_API_VERSION,
|
|
28
|
-
tools: toolNames
|
|
29
|
-
};
|
|
30
|
-
if (mode === "call") {
|
|
31
|
-
const toolName = requireEnv("CONTRACTSPEC_INTEGRATION_HUB_MCP_TOOL_NAME");
|
|
32
|
-
const toolArgs = parseRecordEnvOrDefault("CONTRACTSPEC_INTEGRATION_HUB_MCP_TOOL_ARGS_JSON", {});
|
|
33
|
-
const tool = toolset.tools[toolName];
|
|
34
|
-
if (!tool?.execute) {
|
|
35
|
-
throw new Error(`Tool "${toolName}" was not found. Available tools: ${toolNames.join(", ")}`);
|
|
36
|
-
}
|
|
37
|
-
const toolOutput = await tool.execute(toolArgs, {
|
|
38
|
-
toolCallId: `integration-hub-${randomUUID()}`,
|
|
39
|
-
messages: []
|
|
40
|
-
});
|
|
41
|
-
output.toolCall = {
|
|
42
|
-
name: toolName,
|
|
43
|
-
args: toolArgs,
|
|
44
|
-
output: toolOutput
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
return output;
|
|
48
|
-
} finally {
|
|
49
|
-
await toolset.cleanup().catch(() => {
|
|
50
|
-
return;
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
function buildMcpConfigFromEnv() {
|
|
55
|
-
const name = process.env.CONTRACTSPEC_INTEGRATION_HUB_MCP_NAME ?? "filesystem";
|
|
56
|
-
const transport = resolveTransport();
|
|
57
|
-
const toolPrefix = process.env.CONTRACTSPEC_INTEGRATION_HUB_MCP_TOOL_PREFIX;
|
|
58
|
-
if (transport === "stdio") {
|
|
59
|
-
return {
|
|
60
|
-
name,
|
|
61
|
-
transport,
|
|
62
|
-
command: process.env.CONTRACTSPEC_INTEGRATION_HUB_MCP_COMMAND ?? "npx",
|
|
63
|
-
args: parseStringArrayEnv("CONTRACTSPEC_INTEGRATION_HUB_MCP_ARGS_JSON", DEFAULT_STDIO_ARGS),
|
|
64
|
-
toolPrefix
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
const accessToken = process.env.CONTRACTSPEC_INTEGRATION_HUB_MCP_ACCESS_TOKEN;
|
|
68
|
-
const accessTokenEnvVar = process.env.CONTRACTSPEC_INTEGRATION_HUB_MCP_ACCESS_TOKEN_ENV;
|
|
69
|
-
const mcpTransport = transport === "webhook" || transport === "http" ? "http" : "sse";
|
|
70
|
-
return {
|
|
71
|
-
name,
|
|
72
|
-
transport: mcpTransport,
|
|
73
|
-
url: requireEnv("CONTRACTSPEC_INTEGRATION_HUB_MCP_URL"),
|
|
74
|
-
headers: parseStringRecordEnv("CONTRACTSPEC_INTEGRATION_HUB_MCP_HEADERS_JSON"),
|
|
75
|
-
accessToken,
|
|
76
|
-
accessTokenEnvVar,
|
|
77
|
-
toolPrefix
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
function resolveMode() {
|
|
81
|
-
const rawMode = process.env.CONTRACTSPEC_INTEGRATION_HUB_MCP_MODE?.toLowerCase() ?? "list";
|
|
82
|
-
if (rawMode === "list" || rawMode === "call") {
|
|
83
|
-
return rawMode;
|
|
84
|
-
}
|
|
85
|
-
throw new Error(`Unsupported CONTRACTSPEC_INTEGRATION_HUB_MCP_MODE: ${rawMode}. Use "list" or "call".`);
|
|
86
|
-
}
|
|
87
|
-
function resolveTransport() {
|
|
88
|
-
const rawTransport = process.env.CONTRACTSPEC_INTEGRATION_HUB_MCP_TRANSPORT?.toLowerCase() ?? "stdio";
|
|
89
|
-
if (rawTransport === "stdio" || rawTransport === "http" || rawTransport === "sse" || rawTransport === "webhook") {
|
|
90
|
-
return rawTransport;
|
|
91
|
-
}
|
|
92
|
-
throw new Error(`Unsupported CONTRACTSPEC_INTEGRATION_HUB_MCP_TRANSPORT: ${rawTransport}. Use "stdio", "http", "sse", or "webhook".`);
|
|
93
|
-
}
|
|
94
|
-
function parseStringArrayEnv(key, fallback) {
|
|
95
|
-
const raw = process.env[key];
|
|
96
|
-
if (!raw) {
|
|
97
|
-
return fallback;
|
|
98
|
-
}
|
|
99
|
-
const parsed = parseJsonEnv(key);
|
|
100
|
-
if (!Array.isArray(parsed) || parsed.some((value) => typeof value !== "string")) {
|
|
101
|
-
throw new Error(`${key} must be a JSON string array.`);
|
|
102
|
-
}
|
|
103
|
-
return parsed;
|
|
104
|
-
}
|
|
105
|
-
function parseRecordEnv(key) {
|
|
106
|
-
const raw = process.env[key];
|
|
107
|
-
if (!raw) {
|
|
108
|
-
return;
|
|
109
|
-
}
|
|
110
|
-
const parsed = parseJsonEnv(key);
|
|
111
|
-
if (!isRecord(parsed)) {
|
|
112
|
-
throw new Error(`${key} must be a JSON object.`);
|
|
113
|
-
}
|
|
114
|
-
return parsed;
|
|
115
|
-
}
|
|
116
|
-
function parseRecordEnvOrDefault(key, fallback) {
|
|
117
|
-
return parseRecordEnv(key) ?? fallback;
|
|
118
|
-
}
|
|
119
|
-
function parseStringRecordEnv(key) {
|
|
120
|
-
const parsed = parseRecordEnv(key);
|
|
121
|
-
if (!parsed) {
|
|
122
|
-
return;
|
|
123
|
-
}
|
|
124
|
-
const entries = Object.entries(parsed);
|
|
125
|
-
const invalidEntry = entries.find(([, value]) => typeof value !== "string");
|
|
126
|
-
if (invalidEntry) {
|
|
127
|
-
throw new Error(`${key} must contain only string values.`);
|
|
128
|
-
}
|
|
129
|
-
return Object.fromEntries(entries);
|
|
130
|
-
}
|
|
131
|
-
function parseJsonEnv(key) {
|
|
132
|
-
const raw = process.env[key];
|
|
133
|
-
if (!raw) {
|
|
134
|
-
return;
|
|
135
|
-
}
|
|
136
|
-
try {
|
|
137
|
-
return JSON.parse(raw);
|
|
138
|
-
} catch {
|
|
139
|
-
throw new Error(`${key} contains invalid JSON.`);
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
function requireEnv(key) {
|
|
143
|
-
const value = process.env[key];
|
|
144
|
-
if (!value) {
|
|
145
|
-
throw new Error(`Missing required env var: ${key}`);
|
|
146
|
-
}
|
|
147
|
-
return value;
|
|
148
|
-
}
|
|
149
|
-
function isRecord(value) {
|
|
150
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
// src/run-mcp.ts
|
|
154
|
-
runIntegrationHubMcpExampleFromEnv().then((result) => {
|
|
155
|
-
console.log(JSON.stringify(result, null, 2));
|
|
156
|
-
}).catch((error) => {
|
|
157
|
-
console.error(error);
|
|
158
|
-
process.exitCode = 1;
|
|
159
|
-
});
|
|
1
|
+
import{createMcpToolsets as V}from"@contractspec/lib.ai-agent/tools/mcp-client";import{randomUUID as q}from"crypto";var J=["-y","@modelcontextprotocol/server-filesystem","."];async function Z(){let h=_(),j=$(),z=P(),B=await V([z],{onNameCollision:"error"});try{let K=Object.keys(B.tools).sort(),Q={mode:h,server:{name:z.name,transport:j},authMethod:process.env.CONTRACTSPEC_INTEGRATION_HUB_MCP_AUTH_METHOD,apiVersion:process.env.CONTRACTSPEC_INTEGRATION_HUB_MCP_API_VERSION,tools:K};if(h==="call"){let W=H("CONTRACTSPEC_INTEGRATION_HUB_MCP_TOOL_NAME"),X=F("CONTRACTSPEC_INTEGRATION_HUB_MCP_TOOL_ARGS_JSON",{}),Y=B.tools[W];if(!Y?.execute)throw Error(`Tool "${W}" was not found. Available tools: ${K.join(", ")}`);let L=await Y.execute(X,{toolCallId:`integration-hub-${q()}`,messages:[]});Q.toolCall={name:W,args:X,output:L}}return Q}finally{await B.cleanup().catch(()=>{return})}}function P(){let h=process.env.CONTRACTSPEC_INTEGRATION_HUB_MCP_NAME??"filesystem",j=$(),z=process.env.CONTRACTSPEC_INTEGRATION_HUB_MCP_TOOL_PREFIX;if(j==="stdio")return{name:h,transport:j,command:process.env.CONTRACTSPEC_INTEGRATION_HUB_MCP_COMMAND??"npx",args:x("CONTRACTSPEC_INTEGRATION_HUB_MCP_ARGS_JSON",J),toolPrefix:z};let B=process.env.CONTRACTSPEC_INTEGRATION_HUB_MCP_ACCESS_TOKEN,K=process.env.CONTRACTSPEC_INTEGRATION_HUB_MCP_ACCESS_TOKEN_ENV;return{name:h,transport:j==="webhook"||j==="http"?"http":"sse",url:H("CONTRACTSPEC_INTEGRATION_HUB_MCP_URL"),headers:I("CONTRACTSPEC_INTEGRATION_HUB_MCP_HEADERS_JSON"),accessToken:B,accessTokenEnvVar:K,toolPrefix:z}}function _(){let h=process.env.CONTRACTSPEC_INTEGRATION_HUB_MCP_MODE?.toLowerCase()??"list";if(h==="list"||h==="call")return h;throw Error(`Unsupported CONTRACTSPEC_INTEGRATION_HUB_MCP_MODE: ${h}. Use "list" or "call".`)}function $(){let h=process.env.CONTRACTSPEC_INTEGRATION_HUB_MCP_TRANSPORT?.toLowerCase()??"stdio";if(h==="stdio"||h==="http"||h==="sse"||h==="webhook")return h;throw Error(`Unsupported CONTRACTSPEC_INTEGRATION_HUB_MCP_TRANSPORT: ${h}. Use "stdio", "http", "sse", or "webhook".`)}function x(h,j){if(!process.env[h])return j;let B=G(h);if(!Array.isArray(B)||B.some((K)=>typeof K!=="string"))throw Error(`${h} must be a JSON string array.`);return B}function C(h){if(!process.env[h])return;let z=G(h);if(!O(z))throw Error(`${h} must be a JSON object.`);return z}function F(h,j){return C(h)??j}function I(h){let j=C(h);if(!j)return;let z=Object.entries(j);if(z.find(([,K])=>typeof K!=="string"))throw Error(`${h} must contain only string values.`);return Object.fromEntries(z)}function G(h){let j=process.env[h];if(!j)return;try{return JSON.parse(j)}catch{throw Error(`${h} contains invalid JSON.`)}}function H(h){let j=process.env[h];if(!j)throw Error(`Missing required env var: ${h}`);return j}function O(h){return typeof h==="object"&&h!==null&&!Array.isArray(h)}Z().then((h)=>{console.log(JSON.stringify(h,null,2))}).catch((h)=>{console.error(h),process.exitCode=1});
|