@datagrout/conduit 0.4.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/chunk-CIESM3BP.mjs +33 -0
- package/dist/{chunk-RED5DKGI.mjs → chunk-LW7VX5SZ.mjs} +7 -31
- package/dist/chunk-W56N7X6V.mjs +71 -0
- package/dist/index.d.mts +138 -12
- package/dist/index.d.ts +138 -12
- package/dist/index.js +281 -43
- package/dist/index.mjs +210 -48
- package/dist/{oauth-OMPWCI2X.mjs → oauth-T2D3EDCN.mjs} +2 -1
- package/dist/onramp-RDGV3FOI.mjs +13 -0
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1,13 +1,19 @@
|
|
|
1
1
|
import {
|
|
2
2
|
OAuthTokenProvider,
|
|
3
|
-
__esm,
|
|
4
|
-
__export,
|
|
5
|
-
__require,
|
|
6
|
-
__toCommonJS,
|
|
7
3
|
deriveTokenEndpoint,
|
|
8
4
|
init_oauth,
|
|
9
5
|
oauth_exports
|
|
10
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-LW7VX5SZ.mjs";
|
|
7
|
+
import {
|
|
8
|
+
registerAndExchange,
|
|
9
|
+
registerOnly
|
|
10
|
+
} from "./chunk-W56N7X6V.mjs";
|
|
11
|
+
import {
|
|
12
|
+
__esm,
|
|
13
|
+
__export,
|
|
14
|
+
__require,
|
|
15
|
+
__toCommonJS
|
|
16
|
+
} from "./chunk-CIESM3BP.mjs";
|
|
11
17
|
|
|
12
18
|
// src/identity.ts
|
|
13
19
|
var identity_exports = {};
|
|
@@ -29,7 +35,9 @@ async function fetchWithIdentity(url, init, identity) {
|
|
|
29
35
|
port: parsedUrl.port || 443,
|
|
30
36
|
path: parsedUrl.pathname + parsedUrl.search,
|
|
31
37
|
method: (init.method ?? "GET").toUpperCase(),
|
|
32
|
-
headers: flattenHeaders(
|
|
38
|
+
headers: flattenHeaders(
|
|
39
|
+
init.headers
|
|
40
|
+
),
|
|
33
41
|
cert: identity.certPem,
|
|
34
42
|
key: identity.keyPem,
|
|
35
43
|
...identity.caPem ? { ca: identity.caPem } : {}
|
|
@@ -113,7 +121,9 @@ var init_identity = __esm({
|
|
|
113
121
|
*/
|
|
114
122
|
static fromPaths(certPath, keyPath, caPath) {
|
|
115
123
|
if (typeof process === "undefined" || !process.versions?.node) {
|
|
116
|
-
throw new Error(
|
|
124
|
+
throw new Error(
|
|
125
|
+
"ConduitIdentity.fromPaths() is only available in Node.js environments"
|
|
126
|
+
);
|
|
117
127
|
}
|
|
118
128
|
const fs2 = __require("fs");
|
|
119
129
|
const certPem = fs2.readFileSync(certPath, "utf8");
|
|
@@ -137,7 +147,9 @@ var init_identity = __esm({
|
|
|
137
147
|
if (!certPem) return null;
|
|
138
148
|
const keyPem = process.env.CONDUIT_MTLS_KEY;
|
|
139
149
|
if (!keyPem) {
|
|
140
|
-
throw new Error(
|
|
150
|
+
throw new Error(
|
|
151
|
+
"CONDUIT_MTLS_CERT is set but CONDUIT_MTLS_KEY is missing"
|
|
152
|
+
);
|
|
141
153
|
}
|
|
142
154
|
const caPem = process.env.CONDUIT_MTLS_CA || void 0;
|
|
143
155
|
return _ConduitIdentity.fromPem(certPem, keyPem, caPem);
|
|
@@ -227,7 +239,11 @@ var init_identity = __esm({
|
|
|
227
239
|
const keyPath = `${dir}/identity_key.pem`;
|
|
228
240
|
if (!fs2.existsSync(certPath) || !fs2.existsSync(keyPath)) return null;
|
|
229
241
|
const caPath = `${dir}/ca.pem`;
|
|
230
|
-
return _ConduitIdentity.fromPaths(
|
|
242
|
+
return _ConduitIdentity.fromPaths(
|
|
243
|
+
certPath,
|
|
244
|
+
keyPath,
|
|
245
|
+
fs2.existsSync(caPath) ? caPath : void 0
|
|
246
|
+
);
|
|
231
247
|
} catch {
|
|
232
248
|
return null;
|
|
233
249
|
}
|
|
@@ -348,6 +364,9 @@ var MCPTransport = class extends Transport {
|
|
|
348
364
|
throw new Error("Not connected. Call connect() first.");
|
|
349
365
|
}
|
|
350
366
|
const result = await this.client.callTool({ name, arguments: args });
|
|
367
|
+
if (result?.structuredContent !== void 0) {
|
|
368
|
+
return result.structuredContent;
|
|
369
|
+
}
|
|
351
370
|
const content = result?.content;
|
|
352
371
|
if (Array.isArray(content) && content.length > 0) {
|
|
353
372
|
const first = content[0];
|
|
@@ -358,6 +377,7 @@ var MCPTransport = class extends Transport {
|
|
|
358
377
|
return { text: first.text };
|
|
359
378
|
}
|
|
360
379
|
}
|
|
380
|
+
return first;
|
|
361
381
|
}
|
|
362
382
|
return result;
|
|
363
383
|
}
|
|
@@ -454,7 +474,11 @@ var InvalidConfigError = class extends ConduitError {
|
|
|
454
474
|
|
|
455
475
|
// src/transports/jsonrpc.ts
|
|
456
476
|
function unwrapContent(result) {
|
|
457
|
-
if (result
|
|
477
|
+
if (!result) return result;
|
|
478
|
+
if (result.structuredContent !== void 0) {
|
|
479
|
+
return result.structuredContent;
|
|
480
|
+
}
|
|
481
|
+
if (Array.isArray(result.content) && result.content.length > 0) {
|
|
458
482
|
const first = result.content[0];
|
|
459
483
|
if (first && typeof first.text === "string") {
|
|
460
484
|
try {
|
|
@@ -463,6 +487,7 @@ function unwrapContent(result) {
|
|
|
463
487
|
return { text: first.text };
|
|
464
488
|
}
|
|
465
489
|
}
|
|
490
|
+
return first;
|
|
466
491
|
}
|
|
467
492
|
return result;
|
|
468
493
|
}
|
|
@@ -489,7 +514,9 @@ var JSONRPCTransport = class extends Transport {
|
|
|
489
514
|
this.identity = identity;
|
|
490
515
|
this.timeout = timeout;
|
|
491
516
|
if (identity?.needsRotation(30)) {
|
|
492
|
-
console.warn(
|
|
517
|
+
console.warn(
|
|
518
|
+
"[conduit] mTLS certificate expires within 30 days \u2014 consider rotating"
|
|
519
|
+
);
|
|
493
520
|
}
|
|
494
521
|
if (auth?.clientCredentials) {
|
|
495
522
|
const cc = auth.clientCredentials;
|
|
@@ -522,7 +549,9 @@ var JSONRPCTransport = class extends Transport {
|
|
|
522
549
|
} else if (this.auth?.bearer) {
|
|
523
550
|
headers["Authorization"] = `Bearer ${this.auth.bearer}`;
|
|
524
551
|
} else if (this.auth?.basic) {
|
|
525
|
-
const credentials = btoa(
|
|
552
|
+
const credentials = btoa(
|
|
553
|
+
`${this.auth.basic.username}:${this.auth.basic.password}`
|
|
554
|
+
);
|
|
526
555
|
headers["Authorization"] = `Basic ${credentials}`;
|
|
527
556
|
} else if (this.auth?.custom) {
|
|
528
557
|
Object.assign(headers, this.auth.custom);
|
|
@@ -661,7 +690,9 @@ var WsTransport = class extends Transport {
|
|
|
661
690
|
super();
|
|
662
691
|
const scheme = new URL(url).protocol.replace(":", "");
|
|
663
692
|
if (scheme !== "ws" && scheme !== "wss") {
|
|
664
|
-
throw new Error(
|
|
693
|
+
throw new Error(
|
|
694
|
+
`WS transport requires a ws:// or wss:// URL, got ${scheme}://`
|
|
695
|
+
);
|
|
665
696
|
}
|
|
666
697
|
this._url = url;
|
|
667
698
|
this._auth = auth;
|
|
@@ -676,7 +707,9 @@ var WsTransport = class extends Transport {
|
|
|
676
707
|
});
|
|
677
708
|
await new Promise((resolve, reject) => {
|
|
678
709
|
ws.onopen = () => resolve();
|
|
679
|
-
ws.onerror = (ev) => reject(
|
|
710
|
+
ws.onerror = (ev) => reject(
|
|
711
|
+
new Error(`WS connect failed: ${ev.message ?? "unknown"}`)
|
|
712
|
+
);
|
|
680
713
|
});
|
|
681
714
|
ws.onmessage = (ev) => this._handleMessage(ev.data);
|
|
682
715
|
ws.onerror = (_ev) => this._failAll("WS connection error");
|
|
@@ -710,7 +743,12 @@ var WsTransport = class extends Transport {
|
|
|
710
743
|
const id = this._mintId();
|
|
711
744
|
return new Promise((resolve, reject) => {
|
|
712
745
|
this._pendingSubscribe.set(id, { topic, resolve, reject });
|
|
713
|
-
this._send({
|
|
746
|
+
this._send({
|
|
747
|
+
jsonrpc: "2.0",
|
|
748
|
+
id,
|
|
749
|
+
method: "subscribe",
|
|
750
|
+
params: { topic }
|
|
751
|
+
});
|
|
714
752
|
});
|
|
715
753
|
}
|
|
716
754
|
/**
|
|
@@ -780,7 +818,12 @@ var WsTransport = class extends Transport {
|
|
|
780
818
|
const id = this._mintId();
|
|
781
819
|
return new Promise((resolve, reject) => {
|
|
782
820
|
this._pending.set(id, { resolve, reject });
|
|
783
|
-
this._send({
|
|
821
|
+
this._send({
|
|
822
|
+
jsonrpc: "2.0",
|
|
823
|
+
id,
|
|
824
|
+
method,
|
|
825
|
+
...params !== void 0 ? { params } : {}
|
|
826
|
+
});
|
|
784
827
|
});
|
|
785
828
|
}
|
|
786
829
|
_handleMessage(data) {
|
|
@@ -792,7 +835,9 @@ var WsTransport = class extends Transport {
|
|
|
792
835
|
}
|
|
793
836
|
if (!("id" in msg)) {
|
|
794
837
|
if (msg["method"] === "notification") {
|
|
795
|
-
this._routeNotification(
|
|
838
|
+
this._routeNotification(
|
|
839
|
+
msg["params"]
|
|
840
|
+
);
|
|
796
841
|
}
|
|
797
842
|
return;
|
|
798
843
|
}
|
|
@@ -802,7 +847,9 @@ var WsTransport = class extends Transport {
|
|
|
802
847
|
this._pendingSubscribe.delete(msgId);
|
|
803
848
|
const err = msg["error"];
|
|
804
849
|
if (err !== void 0) {
|
|
805
|
-
pendingSub.reject(
|
|
850
|
+
pendingSub.reject(
|
|
851
|
+
new Error(String(err["message"] ?? "Subscribe failed"))
|
|
852
|
+
);
|
|
806
853
|
return;
|
|
807
854
|
}
|
|
808
855
|
const result = msg["result"] ?? {};
|
|
@@ -859,7 +906,9 @@ function buildUpgradeHeaders(auth) {
|
|
|
859
906
|
} else if ("apiKey" in auth && auth.apiKey !== void 0) {
|
|
860
907
|
headers["X-API-Key"] = auth.apiKey;
|
|
861
908
|
} else if ("basic" in auth && auth.basic !== void 0) {
|
|
862
|
-
const encoded = Buffer.from(
|
|
909
|
+
const encoded = Buffer.from(
|
|
910
|
+
`${auth.basic.username}:${auth.basic.password}`
|
|
911
|
+
).toString("base64");
|
|
863
912
|
headers["Authorization"] = `Basic ${encoded}`;
|
|
864
913
|
}
|
|
865
914
|
return headers;
|
|
@@ -898,7 +947,9 @@ async function fetchDgCaCert(url = DG_CA_URL) {
|
|
|
898
947
|
}
|
|
899
948
|
const pem = await resp.text();
|
|
900
949
|
if (!pem.includes("-----BEGIN CERTIFICATE-----")) {
|
|
901
|
-
throw new Error(
|
|
950
|
+
throw new Error(
|
|
951
|
+
`Response from ${url} does not look like a PEM certificate`
|
|
952
|
+
);
|
|
902
953
|
}
|
|
903
954
|
return pem;
|
|
904
955
|
}
|
|
@@ -914,7 +965,10 @@ function generateKeypair() {
|
|
|
914
965
|
namedCurve: "P-256"
|
|
915
966
|
});
|
|
916
967
|
return {
|
|
917
|
-
privateKeyPem: privateKey.export({
|
|
968
|
+
privateKeyPem: privateKey.export({
|
|
969
|
+
type: "pkcs8",
|
|
970
|
+
format: "pem"
|
|
971
|
+
}),
|
|
918
972
|
publicKeyPem: publicKey.export({ type: "spki", format: "pem" })
|
|
919
973
|
};
|
|
920
974
|
}
|
|
@@ -954,9 +1008,17 @@ async function registerIdentity(keypair, opts) {
|
|
|
954
1008
|
};
|
|
955
1009
|
}
|
|
956
1010
|
async function rotateIdentity(opts) {
|
|
957
|
-
const { privateKey, publicKey } = crypto.generateKeyPairSync("ec", {
|
|
958
|
-
|
|
959
|
-
|
|
1011
|
+
const { privateKey, publicKey } = crypto.generateKeyPairSync("ec", {
|
|
1012
|
+
namedCurve: "P-256"
|
|
1013
|
+
});
|
|
1014
|
+
const publicKeyPem = publicKey.export({
|
|
1015
|
+
type: "spki",
|
|
1016
|
+
format: "pem"
|
|
1017
|
+
});
|
|
1018
|
+
const privateKeyPem = privateKey.export({
|
|
1019
|
+
type: "pkcs8",
|
|
1020
|
+
format: "pem"
|
|
1021
|
+
});
|
|
960
1022
|
const url = opts.endpoint.replace(/\/$/, "") + "/rotate";
|
|
961
1023
|
const https = await import("https");
|
|
962
1024
|
const urlModule = await import("url");
|
|
@@ -971,7 +1033,10 @@ async function rotateIdentity(opts) {
|
|
|
971
1033
|
cert: opts.currentCertPem,
|
|
972
1034
|
key: opts.currentKeyPem
|
|
973
1035
|
};
|
|
974
|
-
const body = JSON.stringify({
|
|
1036
|
+
const body = JSON.stringify({
|
|
1037
|
+
public_key_pem: publicKeyPem,
|
|
1038
|
+
name: opts.name
|
|
1039
|
+
});
|
|
975
1040
|
const req = https.request(reqOptions, (res) => {
|
|
976
1041
|
let data = "";
|
|
977
1042
|
res.on("data", (chunk) => {
|
|
@@ -981,7 +1046,9 @@ async function rotateIdentity(opts) {
|
|
|
981
1046
|
if (res.statusCode && res.statusCode >= 200 && res.statusCode < 300) {
|
|
982
1047
|
resolve(data);
|
|
983
1048
|
} else {
|
|
984
|
-
reject(
|
|
1049
|
+
reject(
|
|
1050
|
+
new Error(`Rotation failed (HTTP ${res.statusCode}): ${data}`)
|
|
1051
|
+
);
|
|
985
1052
|
}
|
|
986
1053
|
});
|
|
987
1054
|
});
|
|
@@ -1081,8 +1148,12 @@ var PrismNamespace = class {
|
|
|
1081
1148
|
data: options.data,
|
|
1082
1149
|
source_type: options.sourceType,
|
|
1083
1150
|
target_type: options.targetType,
|
|
1084
|
-
...options.sourceAnnotations && {
|
|
1085
|
-
|
|
1151
|
+
...options.sourceAnnotations && {
|
|
1152
|
+
source_annotations: options.sourceAnnotations
|
|
1153
|
+
},
|
|
1154
|
+
...options.targetAnnotations && {
|
|
1155
|
+
target_annotations: options.targetAnnotations
|
|
1156
|
+
},
|
|
1086
1157
|
...options.context && { context: options.context }
|
|
1087
1158
|
};
|
|
1088
1159
|
return this.callDg("prism.focus", params);
|
|
@@ -1107,7 +1178,9 @@ var LogicNamespace = class {
|
|
|
1107
1178
|
statement = opts.statement;
|
|
1108
1179
|
}
|
|
1109
1180
|
if (!statement && !opts?.facts?.length) {
|
|
1110
|
-
throw new InvalidConfigError(
|
|
1181
|
+
throw new InvalidConfigError(
|
|
1182
|
+
"remember() requires either a statement or facts"
|
|
1183
|
+
);
|
|
1111
1184
|
}
|
|
1112
1185
|
const params = { tag: opts?.tag ?? "default" };
|
|
1113
1186
|
if (opts?.facts) {
|
|
@@ -1128,7 +1201,9 @@ var LogicNamespace = class {
|
|
|
1128
1201
|
question = opts.question;
|
|
1129
1202
|
}
|
|
1130
1203
|
if (!question && !opts?.patterns?.length) {
|
|
1131
|
-
throw new InvalidConfigError(
|
|
1204
|
+
throw new InvalidConfigError(
|
|
1205
|
+
"query() requires either a question or patterns"
|
|
1206
|
+
);
|
|
1132
1207
|
}
|
|
1133
1208
|
const params = { limit: opts?.limit ?? 50 };
|
|
1134
1209
|
if (opts?.patterns) {
|
|
@@ -1141,7 +1216,9 @@ var LogicNamespace = class {
|
|
|
1141
1216
|
/** Retract facts from the logic cell (`data-grout/logic.forget`). */
|
|
1142
1217
|
async forget(options) {
|
|
1143
1218
|
if (!options.handles?.length && !options.pattern) {
|
|
1144
|
-
throw new InvalidConfigError(
|
|
1219
|
+
throw new InvalidConfigError(
|
|
1220
|
+
"forget() requires either handles or pattern"
|
|
1221
|
+
);
|
|
1145
1222
|
}
|
|
1146
1223
|
const params = {};
|
|
1147
1224
|
if (options.handles) params.handles = options.handles;
|
|
@@ -1150,13 +1227,18 @@ var LogicNamespace = class {
|
|
|
1150
1227
|
}
|
|
1151
1228
|
/** Reflect on the logic cell (`data-grout/logic.reflect`). */
|
|
1152
1229
|
async reflect(options) {
|
|
1153
|
-
const params = {
|
|
1230
|
+
const params = {
|
|
1231
|
+
summary_only: options?.summaryOnly ?? false
|
|
1232
|
+
};
|
|
1154
1233
|
if (options?.entity) params.entity = options.entity;
|
|
1155
1234
|
return this.callDg("logic.reflect", params);
|
|
1156
1235
|
}
|
|
1157
1236
|
/** Add a constraint rule (`data-grout/logic.constrain`). */
|
|
1158
1237
|
async constrain(rule, options) {
|
|
1159
|
-
const params = {
|
|
1238
|
+
const params = {
|
|
1239
|
+
rule,
|
|
1240
|
+
tag: options?.tag ?? "constraint"
|
|
1241
|
+
};
|
|
1160
1242
|
return this.callDg("logic.constrain", params);
|
|
1161
1243
|
}
|
|
1162
1244
|
/** Hydrate the logic cell from external data (`data-grout/logic.hydrate`). */
|
|
@@ -1318,7 +1400,9 @@ var FlowNamespace = class {
|
|
|
1318
1400
|
/** Get details for a specific execution (`data-grout/inspect.execution-details`). */
|
|
1319
1401
|
async details(executionId) {
|
|
1320
1402
|
this.warn("inspect.execution-details");
|
|
1321
|
-
return this.callDg("inspect.execution-details", {
|
|
1403
|
+
return this.callDg("inspect.execution-details", {
|
|
1404
|
+
execution_id: executionId
|
|
1405
|
+
});
|
|
1322
1406
|
}
|
|
1323
1407
|
};
|
|
1324
1408
|
|
|
@@ -1398,10 +1482,7 @@ var Client2 = class _Client {
|
|
|
1398
1482
|
this.isDg = isDgUrl(this.url);
|
|
1399
1483
|
this.useIntelligentInterface = options.useIntelligentInterface ?? this.isDg;
|
|
1400
1484
|
this.maxRetries = options.maxRetries ?? 3;
|
|
1401
|
-
|
|
1402
|
-
if (identity === void 0 && this.isDg && !options.disableMtls) {
|
|
1403
|
-
identity = ConduitIdentity.tryDiscover(options.identityDir) ?? void 0;
|
|
1404
|
-
}
|
|
1485
|
+
const identity = options.identity ?? (options.identityAuto ? ConduitIdentity.tryDiscover(options.identityDir) ?? void 0 : void 0);
|
|
1405
1486
|
const transportType = options.transport || "mcp";
|
|
1406
1487
|
if (transportType === "mcp") {
|
|
1407
1488
|
this.transport = new MCPTransport(this.url, this.auth, identity);
|
|
@@ -1409,10 +1490,20 @@ var Client2 = class _Client {
|
|
|
1409
1490
|
let wsUrl = this.url;
|
|
1410
1491
|
if (wsUrl.startsWith("https://")) wsUrl = "wss://" + wsUrl.slice(8);
|
|
1411
1492
|
else if (wsUrl.startsWith("http://")) wsUrl = "ws://" + wsUrl.slice(7);
|
|
1412
|
-
this.transport = new WsTransport(
|
|
1493
|
+
this.transport = new WsTransport(
|
|
1494
|
+
wsUrl,
|
|
1495
|
+
this.auth,
|
|
1496
|
+
options.timeout,
|
|
1497
|
+
identity
|
|
1498
|
+
);
|
|
1413
1499
|
} else {
|
|
1414
1500
|
const rpcUrl = this.url.endsWith("/mcp") ? this.url.slice(0, -4) + "/rpc" : this.url;
|
|
1415
|
-
this.transport = new JSONRPCTransport(
|
|
1501
|
+
this.transport = new JSONRPCTransport(
|
|
1502
|
+
rpcUrl,
|
|
1503
|
+
this.auth,
|
|
1504
|
+
options.timeout,
|
|
1505
|
+
identity
|
|
1506
|
+
);
|
|
1416
1507
|
}
|
|
1417
1508
|
}
|
|
1418
1509
|
// ===== Bootstrap / seamless mTLS =====
|
|
@@ -1470,7 +1561,7 @@ var Client2 = class _Client {
|
|
|
1470
1561
|
* @param options.substrateEndpoint - Override the DG Substrate endpoint.
|
|
1471
1562
|
*/
|
|
1472
1563
|
static async bootstrapIdentityOAuth(options) {
|
|
1473
|
-
const { OAuthTokenProvider: OAuthTokenProvider2, deriveTokenEndpoint: deriveTokenEndpoint2 } = await import("./oauth-
|
|
1564
|
+
const { OAuthTokenProvider: OAuthTokenProvider2, deriveTokenEndpoint: deriveTokenEndpoint2 } = await import("./oauth-T2D3EDCN.mjs");
|
|
1474
1565
|
const tokenEndpoint = deriveTokenEndpoint2(options.url);
|
|
1475
1566
|
const provider = new OAuthTokenProvider2({
|
|
1476
1567
|
clientId: options.clientId,
|
|
@@ -1486,6 +1577,66 @@ var Client2 = class _Client {
|
|
|
1486
1577
|
substrateEndpoint: options.substrateEndpoint
|
|
1487
1578
|
});
|
|
1488
1579
|
}
|
|
1580
|
+
/**
|
|
1581
|
+
* Register autonomously with DG and bootstrap an mTLS identity.
|
|
1582
|
+
*
|
|
1583
|
+
* The all-in-one flow: onramp (no prior credentials required) →
|
|
1584
|
+
* OAuth token exchange → mTLS identity registration and persistence.
|
|
1585
|
+
*
|
|
1586
|
+
* On subsequent runs the saved mTLS identity is auto-discovered and
|
|
1587
|
+
* no credentials are needed.
|
|
1588
|
+
*
|
|
1589
|
+
* @param options.opts - Onramp registration options.
|
|
1590
|
+
* @param options.url - MCP server URL. Required if the onramp
|
|
1591
|
+
* response does not include `mcpUrl`.
|
|
1592
|
+
* @param options.identityDir - Custom identity storage directory.
|
|
1593
|
+
*
|
|
1594
|
+
* @example
|
|
1595
|
+
* ```ts
|
|
1596
|
+
* import { Client } from './client';
|
|
1597
|
+
* import type { OnrampOptions } from './onramp';
|
|
1598
|
+
*
|
|
1599
|
+
* const client = await Client.bootstrapOnramp({
|
|
1600
|
+
* opts: {
|
|
1601
|
+
* gateway: 'https://app.datagrout.ai',
|
|
1602
|
+
* agentName: 'my-research-agent',
|
|
1603
|
+
* agentType: 'claude-sonnet-4-6',
|
|
1604
|
+
* },
|
|
1605
|
+
* });
|
|
1606
|
+
* await client.connect();
|
|
1607
|
+
* ```
|
|
1608
|
+
*/
|
|
1609
|
+
static async bootstrapOnramp(options) {
|
|
1610
|
+
const { _doRegister, _exchangeToken } = await import("./onramp-RDGV3FOI.mjs");
|
|
1611
|
+
const dir = options.identityDir || DEFAULT_IDENTITY_DIR;
|
|
1612
|
+
const existing = ConduitIdentity.tryDiscover(dir);
|
|
1613
|
+
if (existing && !existing.needsRotation(7)) {
|
|
1614
|
+
if (!options.url) {
|
|
1615
|
+
throw new Error(
|
|
1616
|
+
"'url' must be provided when an existing identity is reused"
|
|
1617
|
+
);
|
|
1618
|
+
}
|
|
1619
|
+
return new _Client({
|
|
1620
|
+
url: options.url,
|
|
1621
|
+
identity: existing,
|
|
1622
|
+
identityDir: dir
|
|
1623
|
+
});
|
|
1624
|
+
}
|
|
1625
|
+
const creds = await _doRegister(options.opts);
|
|
1626
|
+
const token = await _exchangeToken(creds);
|
|
1627
|
+
const url = creds.mcpUrl ?? options.url;
|
|
1628
|
+
if (!url) {
|
|
1629
|
+
throw new Error(
|
|
1630
|
+
"'url' must be provided when mcpUrl is absent from the onramp response"
|
|
1631
|
+
);
|
|
1632
|
+
}
|
|
1633
|
+
return _Client.bootstrapIdentity({
|
|
1634
|
+
url,
|
|
1635
|
+
authToken: token,
|
|
1636
|
+
name: options.opts.agentName,
|
|
1637
|
+
identityDir: options.identityDir
|
|
1638
|
+
});
|
|
1639
|
+
}
|
|
1489
1640
|
// ===== Lifecycle =====
|
|
1490
1641
|
/**
|
|
1491
1642
|
* Establish the underlying transport connection.
|
|
@@ -1537,7 +1688,9 @@ var Client2 = class _Client {
|
|
|
1537
1688
|
// ===== Namespace Accessors =====
|
|
1538
1689
|
callDgTool = async (tool, params) => {
|
|
1539
1690
|
this.ensureInitialized();
|
|
1540
|
-
return this.sendWithRetry(
|
|
1691
|
+
return this.sendWithRetry(
|
|
1692
|
+
() => this.transport.callTool(`data-grout/${tool}`, params)
|
|
1693
|
+
);
|
|
1541
1694
|
};
|
|
1542
1695
|
/** Data transformation, charting, rendering, and type bridging. */
|
|
1543
1696
|
get prism() {
|
|
@@ -1553,7 +1706,10 @@ var Client2 = class _Client {
|
|
|
1553
1706
|
}
|
|
1554
1707
|
/** Work product registration, listing, and retrieval. */
|
|
1555
1708
|
get deliverables() {
|
|
1556
|
-
return new DeliverablesNamespace(
|
|
1709
|
+
return new DeliverablesNamespace(
|
|
1710
|
+
this.callDgTool,
|
|
1711
|
+
(m) => this.warnIfNotDg(m)
|
|
1712
|
+
);
|
|
1557
1713
|
}
|
|
1558
1714
|
/** Cache listing and inspection. */
|
|
1559
1715
|
get ephemerals() {
|
|
@@ -1642,7 +1798,9 @@ var Client2 = class _Client {
|
|
|
1642
1798
|
*/
|
|
1643
1799
|
async getPrompt(name, args, options) {
|
|
1644
1800
|
this.ensureInitialized();
|
|
1645
|
-
return this.sendWithRetry(
|
|
1801
|
+
return this.sendWithRetry(
|
|
1802
|
+
() => this.transport.getPrompt(name, args, options)
|
|
1803
|
+
);
|
|
1646
1804
|
}
|
|
1647
1805
|
// ===== WebSocket push subscriptions =====
|
|
1648
1806
|
/**
|
|
@@ -1743,7 +1901,7 @@ var Client2 = class _Client {
|
|
|
1743
1901
|
outputSchema: r.output_contract || r.output_schema || r.outputSchema
|
|
1744
1902
|
})),
|
|
1745
1903
|
total: result.total ?? tools.length,
|
|
1746
|
-
limit: result.limit ??
|
|
1904
|
+
limit: result.limit ?? options.limit ?? 10
|
|
1747
1905
|
};
|
|
1748
1906
|
}
|
|
1749
1907
|
/**
|
|
@@ -1859,8 +2017,10 @@ var Client2 = class _Client {
|
|
|
1859
2017
|
if (options.k !== void 0) params.k = options.k;
|
|
1860
2018
|
if (options.policy) params.policy = options.policy;
|
|
1861
2019
|
if (options.have) params.have = options.have;
|
|
1862
|
-
if (options.returnCallHandles !== void 0)
|
|
1863
|
-
|
|
2020
|
+
if (options.returnCallHandles !== void 0)
|
|
2021
|
+
params.return_call_handles = options.returnCallHandles;
|
|
2022
|
+
if (options.exposeVirtualSkills !== void 0)
|
|
2023
|
+
params.expose_virtual_skills = options.exposeVirtualSkills;
|
|
1864
2024
|
if (options.modelOverrides) params.model_overrides = options.modelOverrides;
|
|
1865
2025
|
return this.sendWithRetry(
|
|
1866
2026
|
() => this.transport.callTool("data-grout/discovery.plan", params)
|
|
@@ -1978,7 +2138,7 @@ function buildToolMeta(raw) {
|
|
|
1978
2138
|
}
|
|
1979
2139
|
|
|
1980
2140
|
// src/index.ts
|
|
1981
|
-
var version = "0.
|
|
2141
|
+
var version = "0.5.0";
|
|
1982
2142
|
export {
|
|
1983
2143
|
AuthError,
|
|
1984
2144
|
Client2 as Client,
|
|
@@ -2003,7 +2163,9 @@ export {
|
|
|
2003
2163
|
generateKeypair,
|
|
2004
2164
|
isDgUrl,
|
|
2005
2165
|
refreshCaCert,
|
|
2166
|
+
registerAndExchange,
|
|
2006
2167
|
registerIdentity,
|
|
2168
|
+
registerOnly,
|
|
2007
2169
|
rotateIdentity,
|
|
2008
2170
|
saveIdentity,
|
|
2009
2171
|
version
|