@datagrout/conduit 0.1.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 +213 -0
- package/dist/chunk-RED5DKGI.mjs +122 -0
- package/dist/index.d.mts +1242 -0
- package/dist/index.d.ts +1242 -0
- package/dist/index.js +1736 -0
- package/dist/index.mjs +1597 -0
- package/dist/oauth-OMPWCI2X.mjs +10 -0
- package/package.json +63 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,1242 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Identity and mTLS support for Conduit connections.
|
|
3
|
+
*
|
|
4
|
+
* A {@link ConduitIdentity} holds the client certificate and private key used
|
|
5
|
+
* for mutual TLS. When present, every connection presents the certificate
|
|
6
|
+
* during the TLS handshake — the server can verify the caller's identity
|
|
7
|
+
* without a separate application-layer token exchange.
|
|
8
|
+
*
|
|
9
|
+
* ## Auto-discovery
|
|
10
|
+
*
|
|
11
|
+
* {@link ConduitIdentity.tryDefault} walks this chain and returns the first
|
|
12
|
+
* identity it finds:
|
|
13
|
+
*
|
|
14
|
+
* 1. `CONDUIT_MTLS_CERT` + `CONDUIT_MTLS_KEY` (+ optional `CONDUIT_MTLS_CA`)
|
|
15
|
+
* environment variables (inline PEM strings).
|
|
16
|
+
* 2. `CONDUIT_IDENTITY_DIR` environment variable — a directory containing
|
|
17
|
+
* `identity.pem` and `identity_key.pem`. Useful for running multiple
|
|
18
|
+
* agents on the same machine with distinct identities.
|
|
19
|
+
* 3. `~/.conduit/identity.pem` + `~/.conduit/identity_key.pem`
|
|
20
|
+
* 4. `.conduit/identity.pem` relative to the current working directory.
|
|
21
|
+
*
|
|
22
|
+
* If nothing is found, `tryDefault` returns `null` — the client falls back to
|
|
23
|
+
* bearer token / API key auth silently.
|
|
24
|
+
*
|
|
25
|
+
* ## Rotation awareness
|
|
26
|
+
*
|
|
27
|
+
* Attach a known expiry with `withExpiry(date)` and call
|
|
28
|
+
* `needsRotation(thresholdDays)` to check whether the cert is within
|
|
29
|
+
* `thresholdDays` of expiry. Actual re-registration with the DataGrout CA is
|
|
30
|
+
* handled separately.
|
|
31
|
+
*
|
|
32
|
+
* ## Runtime note
|
|
33
|
+
*
|
|
34
|
+
* mTLS in HTTP is a Node.js capability — browser `fetch` implementations do
|
|
35
|
+
* not support client certificates. In browser environments the identity is
|
|
36
|
+
* stored but not applied; a warning is emitted instead.
|
|
37
|
+
*/
|
|
38
|
+
/** Raw mTLS material. */
|
|
39
|
+
interface MtlsConfig {
|
|
40
|
+
/** PEM-encoded X.509 client certificate. */
|
|
41
|
+
certPem: string;
|
|
42
|
+
/** PEM-encoded private key (PKCS#8 or PKCS#1). */
|
|
43
|
+
keyPem: string;
|
|
44
|
+
/**
|
|
45
|
+
* PEM-encoded CA certificate(s) for verifying the *server* cert.
|
|
46
|
+
* When absent the system trust store is used.
|
|
47
|
+
*/
|
|
48
|
+
caPem?: string;
|
|
49
|
+
/** Certificate expiry, if known. Set via {@link ConduitIdentity.withExpiry}. */
|
|
50
|
+
expiresAt?: Date;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* A Conduit client identity — the cert + key pair used for mTLS.
|
|
54
|
+
*
|
|
55
|
+
* Construct via {@link fromPem}, {@link fromPaths}, {@link fromEnv}, or
|
|
56
|
+
* {@link tryDefault}.
|
|
57
|
+
*/
|
|
58
|
+
declare class ConduitIdentity {
|
|
59
|
+
private readonly _config;
|
|
60
|
+
private constructor();
|
|
61
|
+
/**
|
|
62
|
+
* Build an identity from PEM strings already in memory.
|
|
63
|
+
*
|
|
64
|
+
* @throws {Error} if the PEM strings do not look like a certificate or key.
|
|
65
|
+
*/
|
|
66
|
+
static fromPem(certPem: string, keyPem: string, caPem?: string): ConduitIdentity;
|
|
67
|
+
/**
|
|
68
|
+
* Build an identity by reading PEM files from disk (Node.js only).
|
|
69
|
+
*
|
|
70
|
+
* @throws {Error} in browser environments or if the files cannot be read.
|
|
71
|
+
*/
|
|
72
|
+
static fromPaths(certPath: string, keyPath: string, caPath?: string): ConduitIdentity;
|
|
73
|
+
/**
|
|
74
|
+
* Build an identity from environment variables.
|
|
75
|
+
*
|
|
76
|
+
* Reads:
|
|
77
|
+
* - `CONDUIT_MTLS_CERT` — PEM string for the client certificate
|
|
78
|
+
* - `CONDUIT_MTLS_KEY` — PEM string for the private key
|
|
79
|
+
* - `CONDUIT_MTLS_CA` — PEM string for the CA (optional)
|
|
80
|
+
*
|
|
81
|
+
* @returns `null` if `CONDUIT_MTLS_CERT` is not set.
|
|
82
|
+
* @throws {Error} if `CONDUIT_MTLS_CERT` is set but `CONDUIT_MTLS_KEY` is missing.
|
|
83
|
+
*/
|
|
84
|
+
static fromEnv(): ConduitIdentity | null;
|
|
85
|
+
/**
|
|
86
|
+
* Try to locate an identity using the auto-discovery chain described in the
|
|
87
|
+
* module docs. Returns `null` if nothing is found.
|
|
88
|
+
*/
|
|
89
|
+
static tryDefault(): ConduitIdentity | null;
|
|
90
|
+
/**
|
|
91
|
+
* Like {@link tryDefault} but checks `overrideDir` first.
|
|
92
|
+
*
|
|
93
|
+
* Discovery order:
|
|
94
|
+
* 1. `overrideDir` (if provided)
|
|
95
|
+
* 2. `CONDUIT_MTLS_CERT` + `CONDUIT_MTLS_KEY` env vars
|
|
96
|
+
* 3. `CONDUIT_IDENTITY_DIR` env var
|
|
97
|
+
* 4. `~/.conduit/`
|
|
98
|
+
* 5. `.conduit/` relative to cwd
|
|
99
|
+
*/
|
|
100
|
+
static tryDiscover(overrideDir?: string): ConduitIdentity | null;
|
|
101
|
+
/** Attach a known certificate expiry for rotation checks. */
|
|
102
|
+
withExpiry(expiresAt: Date): ConduitIdentity;
|
|
103
|
+
/**
|
|
104
|
+
* Returns `true` if the certificate expires within `thresholdDays`.
|
|
105
|
+
*
|
|
106
|
+
* Always returns `false` when no expiry is set.
|
|
107
|
+
*/
|
|
108
|
+
needsRotation(thresholdDays: number): boolean;
|
|
109
|
+
get certPem(): string;
|
|
110
|
+
get keyPem(): string;
|
|
111
|
+
get caPem(): string | undefined;
|
|
112
|
+
get expiresAt(): Date | undefined;
|
|
113
|
+
private static _hasPemPrivateKey;
|
|
114
|
+
private static _tryLoadFromDir;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Perform an HTTP/HTTPS request using Node.js built-in `https` with a client
|
|
118
|
+
* certificate for mTLS. Returns a `Response`-compatible object usable
|
|
119
|
+
* everywhere the standard `fetch` response is expected.
|
|
120
|
+
*
|
|
121
|
+
* This bypasses the global `fetch` (which doesn't support client certs) and
|
|
122
|
+
* uses Node.js's `https.request` directly.
|
|
123
|
+
*/
|
|
124
|
+
declare function fetchWithIdentity(url: string, init: RequestInit, identity: ConduitIdentity): Promise<Response>;
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Type definitions for DataGrout Conduit
|
|
128
|
+
*/
|
|
129
|
+
/**
|
|
130
|
+
* Rate limit cap returned in `X-RateLimit-Limit` response headers.
|
|
131
|
+
*
|
|
132
|
+
* - `"unlimited"` — authenticated DataGrout users; the gateway never blocks them.
|
|
133
|
+
* - `{ perHour: number }` — unauthenticated callers hitting a per-hour cap.
|
|
134
|
+
*/
|
|
135
|
+
type RateLimit = 'unlimited' | {
|
|
136
|
+
perHour: number;
|
|
137
|
+
};
|
|
138
|
+
/**
|
|
139
|
+
* Parsed rate limit state from a gateway response.
|
|
140
|
+
*
|
|
141
|
+
* Surfaced via `RateLimitError.status` when the client receives HTTP 429.
|
|
142
|
+
*/
|
|
143
|
+
interface RateLimitStatus {
|
|
144
|
+
/** Calls made in the current 1-hour window. */
|
|
145
|
+
used: number;
|
|
146
|
+
/** Total allowed calls (or `"unlimited"`). */
|
|
147
|
+
limit: RateLimit;
|
|
148
|
+
/** `true` when the caller has been throttled. */
|
|
149
|
+
isLimited: boolean;
|
|
150
|
+
/** Remaining calls this window, or `null` when unlimited. */
|
|
151
|
+
remaining: number | null;
|
|
152
|
+
}
|
|
153
|
+
/** BYOK discount details embedded in a receipt. */
|
|
154
|
+
interface Byok {
|
|
155
|
+
enabled: boolean;
|
|
156
|
+
discountApplied: number;
|
|
157
|
+
discountRate: number;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Cost receipt attached to every DG tool-call result under `result._meta.datagrout.receipt`.
|
|
161
|
+
*
|
|
162
|
+
* Use `extractMeta(result)` to pull this out cleanly.
|
|
163
|
+
*/
|
|
164
|
+
interface Receipt {
|
|
165
|
+
/** DG-internal receipt identifier (`rcp_…`). */
|
|
166
|
+
receiptId: string;
|
|
167
|
+
/** DB transaction ID (set only when a user account was charged). */
|
|
168
|
+
transactionId?: string;
|
|
169
|
+
timestamp: string;
|
|
170
|
+
estimatedCredits: number;
|
|
171
|
+
actualCredits: number;
|
|
172
|
+
netCredits: number;
|
|
173
|
+
savings: number;
|
|
174
|
+
savingsBonus: number;
|
|
175
|
+
/** Account balance before the charge. */
|
|
176
|
+
balanceBefore?: number;
|
|
177
|
+
/** Account balance after the charge. */
|
|
178
|
+
balanceAfter?: number;
|
|
179
|
+
/** Per-component credit breakdown. */
|
|
180
|
+
breakdown: Record<string, any>;
|
|
181
|
+
byok: Byok;
|
|
182
|
+
}
|
|
183
|
+
/** Pre-execution credit estimate under `result._meta.datagrout.credit_estimate`. */
|
|
184
|
+
interface CreditEstimate {
|
|
185
|
+
estimatedTotal: number;
|
|
186
|
+
actualTotal: number;
|
|
187
|
+
netTotal: number;
|
|
188
|
+
breakdown: Record<string, any>;
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* The DataGrout billing block attached to every tool-call result in `_meta.datagrout`.
|
|
192
|
+
*
|
|
193
|
+
* @example
|
|
194
|
+
* ```ts
|
|
195
|
+
* const result = await client.callTool('salesforce@v1/get_lead@v1', { id: '123' });
|
|
196
|
+
* const meta = extractMeta(result);
|
|
197
|
+
* if (meta) console.log(`Charged ${meta.receipt.netCredits} credits`);
|
|
198
|
+
* ```
|
|
199
|
+
*/
|
|
200
|
+
interface ToolMeta {
|
|
201
|
+
receipt: Receipt;
|
|
202
|
+
creditEstimate?: CreditEstimate;
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Extract the DataGrout metadata block from a tool-call result.
|
|
206
|
+
*
|
|
207
|
+
* Checks `_meta.datagrout` first (current format — MCP spec extension point),
|
|
208
|
+
* then falls back to top-level `_datagrout`, then bare `_meta`, for
|
|
209
|
+
* backward compatibility with older gateway responses.
|
|
210
|
+
*
|
|
211
|
+
* Returns `null` when no recognized key is found (e.g. upstream servers not
|
|
212
|
+
* routed through the DG gateway).
|
|
213
|
+
*/
|
|
214
|
+
declare function extractMeta(result: Record<string, any>): ToolMeta | null;
|
|
215
|
+
interface ToolInfo {
|
|
216
|
+
toolName: string;
|
|
217
|
+
integration: string;
|
|
218
|
+
serverId?: string;
|
|
219
|
+
score?: number;
|
|
220
|
+
distance?: number;
|
|
221
|
+
description?: string;
|
|
222
|
+
sideEffects?: string;
|
|
223
|
+
inputSchema?: Record<string, any>;
|
|
224
|
+
outputSchema?: Record<string, any>;
|
|
225
|
+
}
|
|
226
|
+
interface DiscoverResult {
|
|
227
|
+
queryUsed: string;
|
|
228
|
+
results: ToolInfo[];
|
|
229
|
+
total: number;
|
|
230
|
+
limit: number;
|
|
231
|
+
}
|
|
232
|
+
interface PerformResult {
|
|
233
|
+
success: boolean;
|
|
234
|
+
result: any;
|
|
235
|
+
tool: string;
|
|
236
|
+
metadata?: Record<string, any>;
|
|
237
|
+
receipt?: Receipt;
|
|
238
|
+
}
|
|
239
|
+
interface GuideOptions {
|
|
240
|
+
id: string;
|
|
241
|
+
label: string;
|
|
242
|
+
cost: number;
|
|
243
|
+
viable: boolean;
|
|
244
|
+
metadata?: Record<string, any>;
|
|
245
|
+
}
|
|
246
|
+
interface GuideState {
|
|
247
|
+
sessionId: string;
|
|
248
|
+
step: string;
|
|
249
|
+
message: string;
|
|
250
|
+
status: string;
|
|
251
|
+
options?: GuideOptions[];
|
|
252
|
+
pathTaken?: string[];
|
|
253
|
+
totalCost?: number;
|
|
254
|
+
result?: any;
|
|
255
|
+
progress?: string;
|
|
256
|
+
}
|
|
257
|
+
interface AuthConfig {
|
|
258
|
+
bearer?: string;
|
|
259
|
+
basic?: {
|
|
260
|
+
username: string;
|
|
261
|
+
password: string;
|
|
262
|
+
};
|
|
263
|
+
/**
|
|
264
|
+
* OAuth 2.1 `client_credentials` grant.
|
|
265
|
+
*
|
|
266
|
+
* When set, the SDK automatically fetches and caches a short-lived JWT from
|
|
267
|
+
* the DataGrout token endpoint. No token management needed in application code.
|
|
268
|
+
*
|
|
269
|
+
* The `tokenEndpoint` is derived from the client URL automatically if omitted.
|
|
270
|
+
*/
|
|
271
|
+
clientCredentials?: {
|
|
272
|
+
clientId: string;
|
|
273
|
+
clientSecret: string;
|
|
274
|
+
/** Optional explicit token endpoint URL. Derived from the client URL if omitted. */
|
|
275
|
+
tokenEndpoint?: string;
|
|
276
|
+
/** Optional space-separated scope string (e.g. `"mcp tools"`). */
|
|
277
|
+
scope?: string;
|
|
278
|
+
};
|
|
279
|
+
custom?: Record<string, string>;
|
|
280
|
+
}
|
|
281
|
+
interface ClientOptions {
|
|
282
|
+
url: string;
|
|
283
|
+
auth?: AuthConfig;
|
|
284
|
+
/**
|
|
285
|
+
* mTLS client identity. When set, every connection presents this
|
|
286
|
+
* certificate during the TLS handshake (Node.js only).
|
|
287
|
+
*
|
|
288
|
+
* Can be set explicitly or discovered automatically via
|
|
289
|
+
* `ConduitIdentity.tryDefault()`.
|
|
290
|
+
*/
|
|
291
|
+
identity?: ConduitIdentity;
|
|
292
|
+
/**
|
|
293
|
+
* When `true`, auto-discover an mTLS identity from env vars or
|
|
294
|
+
* `~/.conduit/` before falling back to token auth. Equivalent to
|
|
295
|
+
* calling `ConduitIdentity.tryDefault()` and passing the result as
|
|
296
|
+
* `identity`.
|
|
297
|
+
*/
|
|
298
|
+
identityAuto?: boolean;
|
|
299
|
+
/**
|
|
300
|
+
* Custom directory for identity storage and discovery. Overrides the
|
|
301
|
+
* default `~/.conduit/` directory. Useful for running multiple agents
|
|
302
|
+
* on the same machine — each gets its own identity directory.
|
|
303
|
+
*/
|
|
304
|
+
identityDir?: string;
|
|
305
|
+
/**
|
|
306
|
+
* Enable the intelligent interface (DataGrout `discover` / `perform` only).
|
|
307
|
+
*
|
|
308
|
+
* When `true`, `listTools()` returns only the DataGrout semantic discovery
|
|
309
|
+
* and execution tools instead of the raw tool list from the MCP server.
|
|
310
|
+
* Defaults to `true` for DataGrout URLs, `false` otherwise.
|
|
311
|
+
* Pass explicitly to override.
|
|
312
|
+
*/
|
|
313
|
+
useIntelligentInterface?: boolean;
|
|
314
|
+
/**
|
|
315
|
+
* Disable automatic mTLS even for DataGrout URLs.
|
|
316
|
+
*
|
|
317
|
+
* By default, DG URLs (`*.datagrout.ai`) silently attempt to discover an
|
|
318
|
+
* mTLS identity from env vars or `~/.conduit/`. Set to `true` to opt out
|
|
319
|
+
* and use token-only auth.
|
|
320
|
+
*
|
|
321
|
+
* @default false
|
|
322
|
+
*/
|
|
323
|
+
disableMtls?: boolean;
|
|
324
|
+
transport?: 'mcp' | 'jsonrpc';
|
|
325
|
+
timeout?: number;
|
|
326
|
+
/**
|
|
327
|
+
* Maximum number of automatic retries on "server not initialized" errors.
|
|
328
|
+
* The client re-initializes the connection between attempts with a 500ms
|
|
329
|
+
* backoff.
|
|
330
|
+
*
|
|
331
|
+
* @default 3
|
|
332
|
+
*/
|
|
333
|
+
maxRetries?: number;
|
|
334
|
+
}
|
|
335
|
+
interface DiscoverOptions {
|
|
336
|
+
query?: string;
|
|
337
|
+
goal?: string;
|
|
338
|
+
limit?: number;
|
|
339
|
+
minScore?: number;
|
|
340
|
+
integrations?: string[];
|
|
341
|
+
servers?: string[];
|
|
342
|
+
}
|
|
343
|
+
interface PerformOptions {
|
|
344
|
+
tool: string;
|
|
345
|
+
args: Record<string, any>;
|
|
346
|
+
demux?: boolean;
|
|
347
|
+
demuxMode?: 'strict' | 'fuzzy';
|
|
348
|
+
}
|
|
349
|
+
interface GuideRequestOptions {
|
|
350
|
+
goal?: string;
|
|
351
|
+
policy?: Record<string, any>;
|
|
352
|
+
sessionId?: string;
|
|
353
|
+
choice?: string;
|
|
354
|
+
}
|
|
355
|
+
interface FlowOptions {
|
|
356
|
+
plan: Array<Record<string, any>>;
|
|
357
|
+
validateCtc?: boolean;
|
|
358
|
+
saveAsSkill?: boolean;
|
|
359
|
+
inputData?: Record<string, any>;
|
|
360
|
+
}
|
|
361
|
+
interface PrismFocusOptions {
|
|
362
|
+
data: any;
|
|
363
|
+
sourceType: string;
|
|
364
|
+
targetType: string;
|
|
365
|
+
sourceAnnotations?: Record<string, any>;
|
|
366
|
+
targetAnnotations?: Record<string, any>;
|
|
367
|
+
context?: string;
|
|
368
|
+
}
|
|
369
|
+
interface PlanOptions {
|
|
370
|
+
goal?: string;
|
|
371
|
+
query?: string;
|
|
372
|
+
server?: string;
|
|
373
|
+
k?: number;
|
|
374
|
+
policy?: any;
|
|
375
|
+
have?: any;
|
|
376
|
+
returnCallHandles?: boolean;
|
|
377
|
+
exposeVirtualSkills?: boolean;
|
|
378
|
+
modelOverrides?: any;
|
|
379
|
+
}
|
|
380
|
+
interface RefractOptions {
|
|
381
|
+
goal: string;
|
|
382
|
+
payload: any;
|
|
383
|
+
verbose?: boolean;
|
|
384
|
+
chart?: boolean;
|
|
385
|
+
}
|
|
386
|
+
interface ChartOptions {
|
|
387
|
+
goal: string;
|
|
388
|
+
payload: any;
|
|
389
|
+
format?: string;
|
|
390
|
+
chartType?: string;
|
|
391
|
+
title?: string;
|
|
392
|
+
xLabel?: string;
|
|
393
|
+
yLabel?: string;
|
|
394
|
+
width?: number;
|
|
395
|
+
height?: number;
|
|
396
|
+
}
|
|
397
|
+
/**
|
|
398
|
+
* Options for `Client.remember()`.
|
|
399
|
+
* Supply either `statement` (natural language) or `facts` (pre-structured),
|
|
400
|
+
* but not neither.
|
|
401
|
+
*/
|
|
402
|
+
interface RememberOptions {
|
|
403
|
+
/** Natural language statement to convert to symbolic facts. */
|
|
404
|
+
statement?: string;
|
|
405
|
+
/** Pre-structured fact list (skips NL conversion). */
|
|
406
|
+
facts?: Record<string, any>[];
|
|
407
|
+
/** Tag/namespace for grouping facts (default: `"default"`). */
|
|
408
|
+
tag?: string;
|
|
409
|
+
}
|
|
410
|
+
/**
|
|
411
|
+
* Options for `Client.queryCell()`.
|
|
412
|
+
* Supply either `question` (natural language) or `patterns` (pre-built),
|
|
413
|
+
* but not neither.
|
|
414
|
+
*/
|
|
415
|
+
interface QueryCellOptions {
|
|
416
|
+
/** Natural language question to translate into query patterns. */
|
|
417
|
+
question?: string;
|
|
418
|
+
/** Pre-built pattern list (skips NL translation). */
|
|
419
|
+
patterns?: Record<string, any>[];
|
|
420
|
+
/** Maximum number of results to return (default: 50). */
|
|
421
|
+
limit?: number;
|
|
422
|
+
}
|
|
423
|
+
/** Options for `Client.forget()`. Supply `handles`, `pattern`, or both. */
|
|
424
|
+
interface ForgetOptions {
|
|
425
|
+
/** Specific fact handles to retract. */
|
|
426
|
+
handles?: string[];
|
|
427
|
+
/** Natural language pattern — retract all matching facts. */
|
|
428
|
+
pattern?: string;
|
|
429
|
+
}
|
|
430
|
+
/** Options for `Client.constrain()`. */
|
|
431
|
+
interface ConstrainOptions {
|
|
432
|
+
/** Tag/namespace for this constraint (default: `"constraint"`). */
|
|
433
|
+
tag?: string;
|
|
434
|
+
}
|
|
435
|
+
/** Options for `Client.reflect()`. */
|
|
436
|
+
interface ReflectOptions {
|
|
437
|
+
/** Optional entity name to scope the reflection. */
|
|
438
|
+
entity?: string;
|
|
439
|
+
/** When `true`, return only summary counts instead of full facts. */
|
|
440
|
+
summaryOnly?: boolean;
|
|
441
|
+
}
|
|
442
|
+
interface MCPTool {
|
|
443
|
+
name: string;
|
|
444
|
+
description?: string;
|
|
445
|
+
inputSchema?: Record<string, any>;
|
|
446
|
+
annotations?: Record<string, any>;
|
|
447
|
+
}
|
|
448
|
+
interface MCPResource {
|
|
449
|
+
uri: string;
|
|
450
|
+
name?: string;
|
|
451
|
+
description?: string;
|
|
452
|
+
mimeType?: string;
|
|
453
|
+
}
|
|
454
|
+
interface MCPPrompt {
|
|
455
|
+
name: string;
|
|
456
|
+
description?: string;
|
|
457
|
+
arguments?: Array<{
|
|
458
|
+
name: string;
|
|
459
|
+
description?: string;
|
|
460
|
+
required?: boolean;
|
|
461
|
+
}>;
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
/**
|
|
465
|
+
* Stateful guided workflow session returned by `Client.guide()`.
|
|
466
|
+
*
|
|
467
|
+
* Call `session.choose(optionId)` to advance through workflow steps,
|
|
468
|
+
* and `session.complete()` to retrieve the final result once `status === "completed"`.
|
|
469
|
+
*/
|
|
470
|
+
declare class GuidedSession {
|
|
471
|
+
private client;
|
|
472
|
+
private state;
|
|
473
|
+
constructor(client: Client, state: GuideState);
|
|
474
|
+
/** Unique session identifier used to resume the workflow. */
|
|
475
|
+
get sessionId(): string;
|
|
476
|
+
/** Current workflow status (e.g. `"ready"`, `"completed"`). */
|
|
477
|
+
get status(): string;
|
|
478
|
+
/** Available options for the current step. */
|
|
479
|
+
get options(): GuideOptions[];
|
|
480
|
+
/** Final result, populated once `status === "completed"`. */
|
|
481
|
+
get result(): any;
|
|
482
|
+
/** Returns the raw `GuideState` snapshot for this step. */
|
|
483
|
+
getState(): GuideState;
|
|
484
|
+
/**
|
|
485
|
+
* Advance the guided session by selecting an option.
|
|
486
|
+
*
|
|
487
|
+
* @param optionId - The `id` of the option to choose (from `session.options`).
|
|
488
|
+
* @returns A new `GuidedSession` reflecting the next workflow step.
|
|
489
|
+
*/
|
|
490
|
+
choose(optionId: string): Promise<GuidedSession>;
|
|
491
|
+
/**
|
|
492
|
+
* Retrieve the completed workflow result.
|
|
493
|
+
*
|
|
494
|
+
* Throws if the session has not yet reached `status === "completed"`.
|
|
495
|
+
* Use `choose()` to advance through remaining steps first.
|
|
496
|
+
*/
|
|
497
|
+
complete(): Promise<any>;
|
|
498
|
+
}
|
|
499
|
+
/** Returns `true` when `url` points at a DataGrout-managed endpoint. */
|
|
500
|
+
declare function isDgUrl(url: string): boolean;
|
|
501
|
+
/**
|
|
502
|
+
* DataGrout Conduit client — a drop-in replacement for MCP clients with
|
|
503
|
+
* first-class support for DataGrout semantic extensions.
|
|
504
|
+
*
|
|
505
|
+
* @example
|
|
506
|
+
* ```ts
|
|
507
|
+
* const client = new Client('https://gateway.datagrout.ai/servers/<uuid>/mcp');
|
|
508
|
+
* await client.connect();
|
|
509
|
+
* const tools = await client.listTools();
|
|
510
|
+
* await client.disconnect();
|
|
511
|
+
* ```
|
|
512
|
+
*/
|
|
513
|
+
declare class Client {
|
|
514
|
+
private url;
|
|
515
|
+
private auth?;
|
|
516
|
+
private useIntelligentInterface;
|
|
517
|
+
private transport;
|
|
518
|
+
private readonly isDg;
|
|
519
|
+
private dgWarned;
|
|
520
|
+
private initialized;
|
|
521
|
+
private maxRetries;
|
|
522
|
+
constructor(options: ClientOptions | string);
|
|
523
|
+
/**
|
|
524
|
+
* Create a `Client` with an mTLS identity bootstrapped automatically.
|
|
525
|
+
*
|
|
526
|
+
* Checks the auto-discovery chain first. If an existing identity is found
|
|
527
|
+
* and not within 7 days of expiry, it is reused. Otherwise a new keypair
|
|
528
|
+
* is generated, registered with DataGrout, and saved locally.
|
|
529
|
+
*
|
|
530
|
+
* After the first successful bootstrap the token is no longer needed —
|
|
531
|
+
* mTLS handles authentication on every subsequent run.
|
|
532
|
+
*
|
|
533
|
+
* @param options.url - DataGrout server URL.
|
|
534
|
+
* @param options.authToken - Bearer token for the initial registration call.
|
|
535
|
+
* @param options.name - Human-readable identity name (default: `"conduit-client"`).
|
|
536
|
+
* @param options.identityDir - Custom identity storage directory.
|
|
537
|
+
* @param options.substrateEndpoint - Override the DG Substrate endpoint.
|
|
538
|
+
*/
|
|
539
|
+
static bootstrapIdentity(options: {
|
|
540
|
+
url: string;
|
|
541
|
+
authToken: string;
|
|
542
|
+
name?: string;
|
|
543
|
+
identityDir?: string;
|
|
544
|
+
substrateEndpoint?: string;
|
|
545
|
+
}): Promise<Client>;
|
|
546
|
+
/**
|
|
547
|
+
* Like `bootstrapIdentity` but uses OAuth 2.1 `client_credentials` to obtain
|
|
548
|
+
* the bearer token automatically — no pre-obtained token needed.
|
|
549
|
+
*
|
|
550
|
+
* @param options.url - DataGrout server URL.
|
|
551
|
+
* @param options.clientId - OAuth client ID.
|
|
552
|
+
* @param options.clientSecret - OAuth client secret.
|
|
553
|
+
* @param options.name - Human-readable identity name (default: `"conduit-client"`).
|
|
554
|
+
* @param options.identityDir - Custom identity storage directory.
|
|
555
|
+
* @param options.substrateEndpoint - Override the DG Substrate endpoint.
|
|
556
|
+
*/
|
|
557
|
+
static bootstrapIdentityOAuth(options: {
|
|
558
|
+
url: string;
|
|
559
|
+
clientId: string;
|
|
560
|
+
clientSecret: string;
|
|
561
|
+
name?: string;
|
|
562
|
+
identityDir?: string;
|
|
563
|
+
substrateEndpoint?: string;
|
|
564
|
+
}): Promise<Client>;
|
|
565
|
+
/**
|
|
566
|
+
* Establish the underlying transport connection.
|
|
567
|
+
*
|
|
568
|
+
* Must be called before any other method. For the MCP transport this
|
|
569
|
+
* performs the JSON-RPC `initialize` handshake; for JSONRPC it is a no-op
|
|
570
|
+
* (connections are per-request).
|
|
571
|
+
*/
|
|
572
|
+
connect(): Promise<void>;
|
|
573
|
+
/**
|
|
574
|
+
* Close the underlying transport connection and mark the client as
|
|
575
|
+
* uninitialized. After calling this, `connect()` must be called again
|
|
576
|
+
* before issuing further requests.
|
|
577
|
+
*/
|
|
578
|
+
disconnect(): Promise<void>;
|
|
579
|
+
private ensureInitialized;
|
|
580
|
+
/**
|
|
581
|
+
* Wrap a transport call with automatic retry on "not initialized" errors
|
|
582
|
+
* (JSON-RPC code -32002). Re-initializes the connection and retries up to
|
|
583
|
+
* `maxRetries` times with 500ms backoff between attempts.
|
|
584
|
+
*/
|
|
585
|
+
private sendWithRetry;
|
|
586
|
+
/**
|
|
587
|
+
* List all tools exposed by the connected MCP server.
|
|
588
|
+
*
|
|
589
|
+
* Calls the MCP `tools/list` method with automatic cursor-based pagination.
|
|
590
|
+
* When `useIntelligentInterface` is enabled (default for DataGrout URLs),
|
|
591
|
+
* integration tools (names containing `@`) are filtered out, leaving only
|
|
592
|
+
* the DataGrout semantic discovery interface.
|
|
593
|
+
*
|
|
594
|
+
* JSON-RPC method: `tools/list`
|
|
595
|
+
*/
|
|
596
|
+
listTools(options?: any): Promise<MCPTool[]>;
|
|
597
|
+
/**
|
|
598
|
+
* Invoke a named tool on the connected MCP server.
|
|
599
|
+
*
|
|
600
|
+
* JSON-RPC method: `tools/call`
|
|
601
|
+
*
|
|
602
|
+
* @param name - Fully-qualified tool name (e.g. `salesforce@v1/get_lead@v1`).
|
|
603
|
+
* @param args - Tool input arguments.
|
|
604
|
+
*/
|
|
605
|
+
callTool(name: string, args: Record<string, any>, _options?: any): Promise<any>;
|
|
606
|
+
/**
|
|
607
|
+
* List resources exposed by the connected MCP server.
|
|
608
|
+
*
|
|
609
|
+
* JSON-RPC method: `resources/list`
|
|
610
|
+
*/
|
|
611
|
+
listResources(options?: any): Promise<MCPResource[]>;
|
|
612
|
+
/**
|
|
613
|
+
* Read the content of a named resource.
|
|
614
|
+
*
|
|
615
|
+
* JSON-RPC method: `resources/read`
|
|
616
|
+
*
|
|
617
|
+
* @param uri - Resource URI as returned by `listResources()`.
|
|
618
|
+
*/
|
|
619
|
+
readResource(uri: string, options?: any): Promise<any>;
|
|
620
|
+
/**
|
|
621
|
+
* List prompt templates exposed by the connected MCP server.
|
|
622
|
+
*
|
|
623
|
+
* JSON-RPC method: `prompts/list`
|
|
624
|
+
*/
|
|
625
|
+
listPrompts(options?: any): Promise<MCPPrompt[]>;
|
|
626
|
+
/**
|
|
627
|
+
* Retrieve a prompt template, optionally instantiated with arguments.
|
|
628
|
+
*
|
|
629
|
+
* JSON-RPC method: `prompts/get`
|
|
630
|
+
*
|
|
631
|
+
* @param name - Prompt name as returned by `listPrompts()`.
|
|
632
|
+
* @param args - Template argument values.
|
|
633
|
+
*/
|
|
634
|
+
getPrompt(name: string, args?: Record<string, any>, options?: any): Promise<any>;
|
|
635
|
+
private warnIfNotDg;
|
|
636
|
+
/**
|
|
637
|
+
* Semantically discover tools relevant to a goal or query.
|
|
638
|
+
*
|
|
639
|
+
* Uses DataGrout's vector-search index to find the best-matching tools
|
|
640
|
+
* across all registered integrations. Returns ranked results with scores,
|
|
641
|
+
* descriptions, and schemas.
|
|
642
|
+
*
|
|
643
|
+
* JSON-RPC method: `tools/call` → `data-grout/discovery.discover`
|
|
644
|
+
*
|
|
645
|
+
* @param options.query - Natural language search query.
|
|
646
|
+
* @param options.goal - High-level goal description (alternative to `query`).
|
|
647
|
+
* @param options.limit - Maximum results to return (default: 10).
|
|
648
|
+
* @param options.minScore - Minimum relevance score (default: 0.0).
|
|
649
|
+
* @param options.integrations - Filter by specific integration names.
|
|
650
|
+
* @param options.servers - Filter by specific server IDs.
|
|
651
|
+
*/
|
|
652
|
+
discover(options: DiscoverOptions): Promise<DiscoverResult>;
|
|
653
|
+
/**
|
|
654
|
+
* Execute a single tool call routed through DataGrout's gateway.
|
|
655
|
+
*
|
|
656
|
+
* The gateway handles credential injection, usage tracking, and receipts.
|
|
657
|
+
* Use `performBatch()` to execute multiple calls in one request.
|
|
658
|
+
*
|
|
659
|
+
* JSON-RPC method: `tools/call` → `data-grout/discovery.perform`
|
|
660
|
+
*
|
|
661
|
+
* @param options.tool - Fully-qualified tool name.
|
|
662
|
+
* @param options.args - Tool input arguments.
|
|
663
|
+
* @param options.demux - When `true`, use semantic demultiplexing.
|
|
664
|
+
* @param options.demuxMode - Demux strictness (`"strict"` | `"fuzzy"`).
|
|
665
|
+
*/
|
|
666
|
+
perform(options: PerformOptions): Promise<any>;
|
|
667
|
+
/**
|
|
668
|
+
* Execute multiple tool calls in a single gateway request.
|
|
669
|
+
*
|
|
670
|
+
* JSON-RPC method: `tools/call` → `data-grout/discovery.perform`
|
|
671
|
+
*
|
|
672
|
+
* @param calls - Array of `{ tool, args }` call descriptors.
|
|
673
|
+
*/
|
|
674
|
+
performBatch(calls: Array<{
|
|
675
|
+
tool: string;
|
|
676
|
+
args: Record<string, any>;
|
|
677
|
+
}>): Promise<any[]>;
|
|
678
|
+
/**
|
|
679
|
+
* Start or advance a guided workflow session.
|
|
680
|
+
*
|
|
681
|
+
* The first call (with only `goal`) starts a new session and returns the
|
|
682
|
+
* initial options. Subsequent calls provide `sessionId` and `choice` to
|
|
683
|
+
* advance through steps. Returns a `GuidedSession` that exposes helpers
|
|
684
|
+
* for navigating the workflow.
|
|
685
|
+
*
|
|
686
|
+
* JSON-RPC method: `tools/call` → `data-grout/discovery.guide`
|
|
687
|
+
*
|
|
688
|
+
* @param options.goal - High-level goal to accomplish (first call only).
|
|
689
|
+
* @param options.policy - Optional policy constraints for tool selection.
|
|
690
|
+
* @param options.sessionId - Resume an existing session (subsequent calls).
|
|
691
|
+
* @param options.choice - Option ID selected at the current step.
|
|
692
|
+
*/
|
|
693
|
+
guide(options: GuideRequestOptions): Promise<GuidedSession>;
|
|
694
|
+
/**
|
|
695
|
+
* Execute a pre-planned sequence of tool calls (a "flow") through the
|
|
696
|
+
* DataGrout gateway.
|
|
697
|
+
*
|
|
698
|
+
* JSON-RPC method: `tools/call` → `data-grout/flow.into`
|
|
699
|
+
*
|
|
700
|
+
* @param options.plan - Ordered list of tool call descriptors.
|
|
701
|
+
* @param options.validateCtc - Validate each call against its CTC schema (default: `true`).
|
|
702
|
+
* @param options.saveAsSkill - Persist the flow as a reusable skill (default: `false`).
|
|
703
|
+
* @param options.inputData - Runtime input data for the flow.
|
|
704
|
+
*/
|
|
705
|
+
flowInto(options: FlowOptions): Promise<any>;
|
|
706
|
+
/**
|
|
707
|
+
* Transform data from one annotated type to another using the DataGrout
|
|
708
|
+
* Prism semantic mapping engine.
|
|
709
|
+
*
|
|
710
|
+
* JSON-RPC method: `tools/call` → `data-grout/prism.focus`
|
|
711
|
+
*
|
|
712
|
+
* @param options.data - Source payload to transform.
|
|
713
|
+
* @param options.sourceType - Semantic type of the source data.
|
|
714
|
+
* @param options.targetType - Desired semantic type for the output.
|
|
715
|
+
* @param options.sourceAnnotations - Additional schema hints for the source.
|
|
716
|
+
* @param options.targetAnnotations - Additional schema hints for the target.
|
|
717
|
+
* @param options.context - Free-text context to guide the mapping.
|
|
718
|
+
*/
|
|
719
|
+
prismFocus(options: PrismFocusOptions): Promise<any>;
|
|
720
|
+
/**
|
|
721
|
+
* Generate an execution plan for a goal using DataGrout's planning engine.
|
|
722
|
+
*
|
|
723
|
+
* Returns an ordered list of tool calls that, when executed, accomplish the
|
|
724
|
+
* stated goal. Throws `InvalidConfigError` if neither `goal` nor `query` is
|
|
725
|
+
* provided.
|
|
726
|
+
*
|
|
727
|
+
* JSON-RPC method: `tools/call` → `data-grout/discovery.plan`
|
|
728
|
+
*
|
|
729
|
+
* @param options.goal - High-level goal description.
|
|
730
|
+
* @param options.query - Search query to anchor the plan (alternative to `goal`).
|
|
731
|
+
* @param options.server - Restrict planning to a specific server.
|
|
732
|
+
* @param options.k - Maximum number of plan steps.
|
|
733
|
+
* @param options.policy - Policy constraints for tool selection.
|
|
734
|
+
* @param options.have - Pre-existing data/context available to the planner.
|
|
735
|
+
* @param options.returnCallHandles - Include call handles in the response.
|
|
736
|
+
* @param options.exposeVirtualSkills - Include virtual skills in the plan.
|
|
737
|
+
* @param options.modelOverrides - Override LLM model settings.
|
|
738
|
+
*/
|
|
739
|
+
plan(options: PlanOptions): Promise<any>;
|
|
740
|
+
/**
|
|
741
|
+
* Analyse and summarise a payload using the DataGrout Prism refraction engine.
|
|
742
|
+
*
|
|
743
|
+
* JSON-RPC method: `tools/call` → `data-grout/prism.refract`
|
|
744
|
+
*
|
|
745
|
+
* @param options.goal - Description of what to extract or summarise.
|
|
746
|
+
* @param options.payload - Input data to analyse (any JSON-serializable value).
|
|
747
|
+
* @param options.verbose - Include detailed processing trace in the response.
|
|
748
|
+
* @param options.chart - Also generate a chart representation.
|
|
749
|
+
*/
|
|
750
|
+
refract(options: RefractOptions): Promise<any>;
|
|
751
|
+
/**
|
|
752
|
+
* Generate a chart from a data payload using the DataGrout Prism engine.
|
|
753
|
+
*
|
|
754
|
+
* JSON-RPC method: `tools/call` → `data-grout/prism.chart`
|
|
755
|
+
*
|
|
756
|
+
* @param options.goal - What the chart should visualise.
|
|
757
|
+
* @param options.payload - Input data (any JSON-serializable value).
|
|
758
|
+
* @param options.format - Output format (e.g. `"png"`, `"svg"`).
|
|
759
|
+
* @param options.chartType - Chart type (e.g. `"bar"`, `"line"`, `"pie"`).
|
|
760
|
+
* @param options.title - Chart title.
|
|
761
|
+
* @param options.xLabel - X-axis label.
|
|
762
|
+
* @param options.yLabel - Y-axis label.
|
|
763
|
+
* @param options.width - Chart width in pixels.
|
|
764
|
+
* @param options.height - Chart height in pixels.
|
|
765
|
+
*/
|
|
766
|
+
chart(options: ChartOptions): Promise<any>;
|
|
767
|
+
/**
|
|
768
|
+
* Generate a document toward a natural-language goal.
|
|
769
|
+
* Supported formats: markdown, html, pdf, json.
|
|
770
|
+
*/
|
|
771
|
+
render(options: {
|
|
772
|
+
goal: string;
|
|
773
|
+
payload?: any;
|
|
774
|
+
format?: string;
|
|
775
|
+
sections?: any[];
|
|
776
|
+
[k: string]: any;
|
|
777
|
+
}): Promise<any>;
|
|
778
|
+
/**
|
|
779
|
+
* Convert content to another format (no LLM). Supports csv, xlsx, pdf, json, html, markdown, etc.
|
|
780
|
+
*/
|
|
781
|
+
export(options: {
|
|
782
|
+
content: any;
|
|
783
|
+
format: string;
|
|
784
|
+
style?: Record<string, any>;
|
|
785
|
+
metadata?: Record<string, any>;
|
|
786
|
+
[k: string]: any;
|
|
787
|
+
}): Promise<any>;
|
|
788
|
+
/**
|
|
789
|
+
* Pause workflow for human approval. Use for destructive or policy-gated actions.
|
|
790
|
+
*/
|
|
791
|
+
requestApproval(options: {
|
|
792
|
+
action: string;
|
|
793
|
+
details?: Record<string, any>;
|
|
794
|
+
reason?: string;
|
|
795
|
+
context?: Record<string, any>;
|
|
796
|
+
[k: string]: any;
|
|
797
|
+
}): Promise<any>;
|
|
798
|
+
/**
|
|
799
|
+
* Request user clarification for missing fields. Pauses until user provides values.
|
|
800
|
+
*/
|
|
801
|
+
requestFeedback(options: {
|
|
802
|
+
missing_fields: string[];
|
|
803
|
+
reason: string;
|
|
804
|
+
current_data?: Record<string, any>;
|
|
805
|
+
suggestions?: Record<string, any>;
|
|
806
|
+
context?: Record<string, any>;
|
|
807
|
+
[k: string]: any;
|
|
808
|
+
}): Promise<any>;
|
|
809
|
+
/**
|
|
810
|
+
* List recent tool executions for the current server.
|
|
811
|
+
*/
|
|
812
|
+
executionHistory(options?: {
|
|
813
|
+
limit?: number;
|
|
814
|
+
offset?: number;
|
|
815
|
+
status?: string;
|
|
816
|
+
refractions_only?: boolean;
|
|
817
|
+
[k: string]: any;
|
|
818
|
+
}): Promise<any>;
|
|
819
|
+
/**
|
|
820
|
+
* Get details and transcript for a specific execution.
|
|
821
|
+
*/
|
|
822
|
+
executionDetails(executionId: string): Promise<any>;
|
|
823
|
+
/**
|
|
824
|
+
* Call any DataGrout first-party tool by its short name.
|
|
825
|
+
*
|
|
826
|
+
* Prepends `data-grout/` to the tool name automatically, so
|
|
827
|
+
* `client.dg('prism.render', { ... })` calls `data-grout/prism.render`.
|
|
828
|
+
*
|
|
829
|
+
* JSON-RPC method: `tools/call` → `data-grout/<toolShortName>`
|
|
830
|
+
*
|
|
831
|
+
* @param toolShortName - Tool name without the `data-grout/` prefix.
|
|
832
|
+
* @param params - Tool input arguments.
|
|
833
|
+
*/
|
|
834
|
+
dg(toolShortName: string, params?: Record<string, any>): Promise<any>;
|
|
835
|
+
/**
|
|
836
|
+
* Store facts in the agent's persistent logic cell.
|
|
837
|
+
*
|
|
838
|
+
* Converts natural language to symbolic facts and stores them
|
|
839
|
+
* durably across sessions. Accepts either a natural language `statement`
|
|
840
|
+
* (positional or via options) or a pre-structured `facts` array.
|
|
841
|
+
*
|
|
842
|
+
* Throws `InvalidConfigError` if neither `statement` nor `facts` is provided.
|
|
843
|
+
*
|
|
844
|
+
* JSON-RPC method: `tools/call` → `data-grout/logic.remember`
|
|
845
|
+
*
|
|
846
|
+
* @param statement - Natural language statement to remember.
|
|
847
|
+
* @param options.tag - Tag/namespace for grouping facts (default: `"default"`).
|
|
848
|
+
* @param options.facts - Optional pre-structured fact list (skips NL conversion).
|
|
849
|
+
*/
|
|
850
|
+
remember(statement: string, options?: RememberOptions): Promise<{
|
|
851
|
+
handles: string[];
|
|
852
|
+
facts: any[];
|
|
853
|
+
count: number;
|
|
854
|
+
message: string;
|
|
855
|
+
}>;
|
|
856
|
+
/**
|
|
857
|
+
* Store facts in the agent's persistent logic cell using an options object.
|
|
858
|
+
*
|
|
859
|
+
* Throws `InvalidConfigError` if neither `statement` nor `facts` is provided.
|
|
860
|
+
*
|
|
861
|
+
* JSON-RPC method: `tools/call` → `data-grout/logic.remember`
|
|
862
|
+
*/
|
|
863
|
+
remember(options: RememberOptions): Promise<{
|
|
864
|
+
handles: string[];
|
|
865
|
+
facts: any[];
|
|
866
|
+
count: number;
|
|
867
|
+
message: string;
|
|
868
|
+
}>;
|
|
869
|
+
/**
|
|
870
|
+
* Query the agent's logic cell with a natural language question.
|
|
871
|
+
*
|
|
872
|
+
* Translates the question to query patterns and retrieves matching facts.
|
|
873
|
+
* Accepts either a natural language `question` (positional or via options)
|
|
874
|
+
* or a pre-built `patterns` array.
|
|
875
|
+
*
|
|
876
|
+
* Throws `InvalidConfigError` if neither `question` nor `patterns` is provided.
|
|
877
|
+
*
|
|
878
|
+
* JSON-RPC method: `tools/call` → `data-grout/logic.query`
|
|
879
|
+
*
|
|
880
|
+
* @param question - Natural language question.
|
|
881
|
+
* @param options.limit - Maximum results to return (default: 50).
|
|
882
|
+
* @param options.patterns - Optional pre-built pattern list (skips NL translation).
|
|
883
|
+
*/
|
|
884
|
+
queryCell(question: string, options?: QueryCellOptions): Promise<{
|
|
885
|
+
results: any[];
|
|
886
|
+
total: number;
|
|
887
|
+
description: string;
|
|
888
|
+
message: string;
|
|
889
|
+
}>;
|
|
890
|
+
/**
|
|
891
|
+
* Query the agent's logic cell using an options object.
|
|
892
|
+
*
|
|
893
|
+
* Throws `InvalidConfigError` if neither `question` nor `patterns` is provided.
|
|
894
|
+
*
|
|
895
|
+
* JSON-RPC method: `tools/call` → `data-grout/logic.query`
|
|
896
|
+
*/
|
|
897
|
+
queryCell(options: QueryCellOptions): Promise<{
|
|
898
|
+
results: any[];
|
|
899
|
+
total: number;
|
|
900
|
+
description: string;
|
|
901
|
+
message: string;
|
|
902
|
+
}>;
|
|
903
|
+
/**
|
|
904
|
+
* Retract facts from the agent's logic cell.
|
|
905
|
+
*
|
|
906
|
+
* Throws `InvalidConfigError` if neither `handles` nor `pattern` is provided.
|
|
907
|
+
*
|
|
908
|
+
* JSON-RPC method: `tools/call` → `data-grout/logic.forget`
|
|
909
|
+
*
|
|
910
|
+
* @param options.handles - Specific fact handles to retract.
|
|
911
|
+
* @param options.pattern - Natural language pattern — retract all matching facts.
|
|
912
|
+
*/
|
|
913
|
+
forget(options: ForgetOptions): Promise<{
|
|
914
|
+
retracted: number;
|
|
915
|
+
handles: string[];
|
|
916
|
+
message: string;
|
|
917
|
+
}>;
|
|
918
|
+
/**
|
|
919
|
+
* Reflect on the agent's logic cell — returns a full snapshot or a
|
|
920
|
+
* per-entity view of all stored facts.
|
|
921
|
+
*
|
|
922
|
+
* JSON-RPC method: `tools/call` → `data-grout/logic.reflect`
|
|
923
|
+
*
|
|
924
|
+
* @param options.entity - Optional entity name to scope reflection.
|
|
925
|
+
* @param options.summaryOnly - When `true`, return only counts (default: `false`).
|
|
926
|
+
*/
|
|
927
|
+
reflect(options?: ReflectOptions): Promise<{
|
|
928
|
+
total: number;
|
|
929
|
+
summary?: any;
|
|
930
|
+
entity?: string;
|
|
931
|
+
facts?: any[];
|
|
932
|
+
message: string;
|
|
933
|
+
}>;
|
|
934
|
+
/**
|
|
935
|
+
* Store a logical rule or policy in the agent's logic cell.
|
|
936
|
+
*
|
|
937
|
+
* Rules are permanent constraints evaluated during `queryCell()` calls.
|
|
938
|
+
*
|
|
939
|
+
* JSON-RPC method: `tools/call` → `data-grout/logic.constrain`
|
|
940
|
+
*
|
|
941
|
+
* @param rule - Natural language rule (e.g. `"VIP customers have ARR > $500K"`).
|
|
942
|
+
* @param options.tag - Tag/namespace for this constraint (default: `"constraint"`).
|
|
943
|
+
*/
|
|
944
|
+
constrain(rule: string, options?: ConstrainOptions): Promise<{
|
|
945
|
+
handle: string;
|
|
946
|
+
name: string;
|
|
947
|
+
rule: string;
|
|
948
|
+
message: string;
|
|
949
|
+
}>;
|
|
950
|
+
/**
|
|
951
|
+
* Estimate the credit cost of a tool call without executing it.
|
|
952
|
+
*
|
|
953
|
+
* Passes `estimate_only: true` to the tool, which returns a cost breakdown
|
|
954
|
+
* without performing any side effects or charging credits.
|
|
955
|
+
*
|
|
956
|
+
* @param tool - Fully-qualified tool name.
|
|
957
|
+
* @param args - Tool input arguments.
|
|
958
|
+
*/
|
|
959
|
+
estimateCost(tool: string, args: Record<string, any>): Promise<any>;
|
|
960
|
+
private performWithTracking;
|
|
961
|
+
}
|
|
962
|
+
|
|
963
|
+
/**
|
|
964
|
+
* OAuth 2.1 `client_credentials` token provider for Conduit.
|
|
965
|
+
*
|
|
966
|
+
* Fetches short-lived JWTs from the DataGrout machine-client token endpoint
|
|
967
|
+
* and caches them, refreshing proactively before they expire.
|
|
968
|
+
*
|
|
969
|
+
* @example
|
|
970
|
+
* ```ts
|
|
971
|
+
* // Most users should use the high-level `auth.clientCredentials` option on
|
|
972
|
+
* // ClientOptions instead of instantiating this class directly.
|
|
973
|
+
* import { Client } from 'datagrout-conduit';
|
|
974
|
+
*
|
|
975
|
+
* const client = new Client({
|
|
976
|
+
* url: 'https://app.datagrout.ai/servers/{uuid}/mcp',
|
|
977
|
+
* auth: {
|
|
978
|
+
* clientCredentials: { clientId: 'abc', clientSecret: 'xyz' },
|
|
979
|
+
* },
|
|
980
|
+
* });
|
|
981
|
+
* ```
|
|
982
|
+
*/
|
|
983
|
+
/**
|
|
984
|
+
* Derive the token endpoint URL from a DataGrout MCP URL.
|
|
985
|
+
*
|
|
986
|
+
* @example
|
|
987
|
+
* ```ts
|
|
988
|
+
* deriveTokenEndpoint('https://app.datagrout.ai/servers/abc/mcp');
|
|
989
|
+
* // → 'https://app.datagrout.ai/servers/abc/oauth/token'
|
|
990
|
+
* ```
|
|
991
|
+
*/
|
|
992
|
+
declare function deriveTokenEndpoint(mcpUrl: string): string;
|
|
993
|
+
/** @internal */
|
|
994
|
+
declare class OAuthTokenProvider {
|
|
995
|
+
private readonly clientId;
|
|
996
|
+
private readonly clientSecret;
|
|
997
|
+
private readonly tokenEndpoint;
|
|
998
|
+
private readonly scope?;
|
|
999
|
+
private cached;
|
|
1000
|
+
private fetchPromise;
|
|
1001
|
+
constructor(opts: {
|
|
1002
|
+
clientId: string;
|
|
1003
|
+
clientSecret: string;
|
|
1004
|
+
tokenEndpoint: string;
|
|
1005
|
+
scope?: string;
|
|
1006
|
+
});
|
|
1007
|
+
/**
|
|
1008
|
+
* Return the current bearer token, fetching a fresh one if necessary.
|
|
1009
|
+
* Concurrent callers share a single in-flight fetch.
|
|
1010
|
+
*/
|
|
1011
|
+
getToken(): Promise<string>;
|
|
1012
|
+
/** Invalidate the cached token (e.g. after receiving a 401). */
|
|
1013
|
+
invalidate(): void;
|
|
1014
|
+
private fetchToken;
|
|
1015
|
+
}
|
|
1016
|
+
|
|
1017
|
+
/**
|
|
1018
|
+
* Substrate identity registration with the DataGrout CA.
|
|
1019
|
+
*
|
|
1020
|
+
* Flow:
|
|
1021
|
+
* 1. Generate an ECDSA P-256 keypair locally — private key never leaves the client.
|
|
1022
|
+
* 2. Send only the public key to DataGrout via {@link registerIdentity}.
|
|
1023
|
+
* DG signs and returns the certificate + CA cert.
|
|
1024
|
+
* 3. Persist to `~/.conduit/` via {@link saveIdentity}.
|
|
1025
|
+
* 4. On renewal, call {@link rotateIdentity} — authenticated by mTLS, no API key needed.
|
|
1026
|
+
*
|
|
1027
|
+
* CA cert refresh
|
|
1028
|
+
* ---------------
|
|
1029
|
+
* {@link fetchDgCaCert} fetches the current DataGrout CA certificate from
|
|
1030
|
+
* `https://ca.datagrout.ai/ca.pem`. When the DG CA rotates, clients that call
|
|
1031
|
+
* {@link refreshCaCert} at startup automatically pick up the change without a
|
|
1032
|
+
* rebuild or re-registration.
|
|
1033
|
+
*/
|
|
1034
|
+
/** Canonical URL for the DataGrout CA certificate. */
|
|
1035
|
+
declare const DG_CA_URL = "https://ca.datagrout.ai/ca.pem";
|
|
1036
|
+
/** Substrate identity registration endpoint. */
|
|
1037
|
+
declare const DG_SUBSTRATE_ENDPOINT = "https://app.datagrout.ai/api/v1/substrate/identity";
|
|
1038
|
+
/** Default local identity directory. */
|
|
1039
|
+
declare const DEFAULT_IDENTITY_DIR: string;
|
|
1040
|
+
/**
|
|
1041
|
+
* Fetch the current DataGrout CA certificate from `ca.datagrout.ai`.
|
|
1042
|
+
*
|
|
1043
|
+
* Uses the system trust store for HTTPS (Cloudflare TLS) — no circularity
|
|
1044
|
+
* with the DG CA, which only signs client certificates.
|
|
1045
|
+
*
|
|
1046
|
+
* @param url Override the CA cert URL (default: {@link DG_CA_URL}).
|
|
1047
|
+
* @returns PEM-encoded CA certificate string.
|
|
1048
|
+
*/
|
|
1049
|
+
declare function fetchDgCaCert(url?: string): Promise<string>;
|
|
1050
|
+
/**
|
|
1051
|
+
* Refresh the locally-cached DG CA certificate.
|
|
1052
|
+
*
|
|
1053
|
+
* Fetches the current CA cert from `ca.datagrout.ai` and writes it to
|
|
1054
|
+
* `{identityDir}/ca.pem`. Call at application startup to pick up CA rotations
|
|
1055
|
+
* without requiring a new registration or SDK rebuild.
|
|
1056
|
+
*
|
|
1057
|
+
* @param identityDir Directory to write `ca.pem` into (default: `~/.conduit/`).
|
|
1058
|
+
* @param url Override the CA cert URL.
|
|
1059
|
+
* @returns Path to the written `ca.pem` file.
|
|
1060
|
+
*/
|
|
1061
|
+
declare function refreshCaCert(identityDir?: string, url?: string): Promise<string>;
|
|
1062
|
+
/**
|
|
1063
|
+
* An ECDSA P-256 keypair generated locally.
|
|
1064
|
+
*
|
|
1065
|
+
* Pass to {@link registerIdentity} to exchange for a DG-signed certificate.
|
|
1066
|
+
* The private key never leaves the client process.
|
|
1067
|
+
*/
|
|
1068
|
+
interface Keypair {
|
|
1069
|
+
/** PEM-encoded PKCS#8 private key (never transmitted). */
|
|
1070
|
+
privateKeyPem: string;
|
|
1071
|
+
/** PEM-encoded SPKI public key (sent to DG during registration). */
|
|
1072
|
+
publicKeyPem: string;
|
|
1073
|
+
}
|
|
1074
|
+
interface RegistrationOptions {
|
|
1075
|
+
/** DataGrout substrate identity API base URL. */
|
|
1076
|
+
endpoint: string;
|
|
1077
|
+
/** Any valid DG access token for bootstrap Bearer auth. */
|
|
1078
|
+
authToken: string;
|
|
1079
|
+
/** Human-readable label for this Substrate instance. */
|
|
1080
|
+
name: string;
|
|
1081
|
+
/** CA cert URL override (default: {@link DG_CA_URL}). */
|
|
1082
|
+
caUrl?: string;
|
|
1083
|
+
}
|
|
1084
|
+
interface RenewalOptions {
|
|
1085
|
+
/** DataGrout substrate identity API base URL. */
|
|
1086
|
+
endpoint: string;
|
|
1087
|
+
/** Human-readable label for the renewed identity. */
|
|
1088
|
+
name: string;
|
|
1089
|
+
/** CA cert URL override. */
|
|
1090
|
+
caUrl?: string;
|
|
1091
|
+
}
|
|
1092
|
+
interface RegisteredIdentity {
|
|
1093
|
+
/** PEM-encoded DG-signed certificate. */
|
|
1094
|
+
certPem: string;
|
|
1095
|
+
/** PEM-encoded private key (never sent to DG). */
|
|
1096
|
+
keyPem: string;
|
|
1097
|
+
/** PEM-encoded DG CA certificate. */
|
|
1098
|
+
caPem?: string;
|
|
1099
|
+
/** Server-assigned identity ID. */
|
|
1100
|
+
id: string;
|
|
1101
|
+
/** Human-readable label assigned during registration. */
|
|
1102
|
+
name: string;
|
|
1103
|
+
/** SHA-256 fingerprint of the certificate. */
|
|
1104
|
+
fingerprint: string;
|
|
1105
|
+
/** ISO-8601 timestamp when the identity was registered. */
|
|
1106
|
+
registeredAt: string;
|
|
1107
|
+
/** ISO-8601 expiry date. */
|
|
1108
|
+
validUntil?: string;
|
|
1109
|
+
}
|
|
1110
|
+
/**
|
|
1111
|
+
* Generate an ECDSA P-256 keypair for Substrate identity registration.
|
|
1112
|
+
*
|
|
1113
|
+
* Returns a {@link Keypair} holding the private key (local only) and the
|
|
1114
|
+
* public key to send to DataGrout. Pass the result to {@link registerIdentity}
|
|
1115
|
+
* to receive a DG-CA-signed certificate.
|
|
1116
|
+
*
|
|
1117
|
+
* Node.js only (`crypto.generateKeyPairSync`).
|
|
1118
|
+
*/
|
|
1119
|
+
declare function generateKeypair(): Keypair;
|
|
1120
|
+
/**
|
|
1121
|
+
* Register a Substrate keypair with the DataGrout CA.
|
|
1122
|
+
*
|
|
1123
|
+
* Sends only the public key to DG and receives a DG-CA-signed certificate.
|
|
1124
|
+
* The private key in *keypair* is reused — it never leaves the client.
|
|
1125
|
+
*
|
|
1126
|
+
* @param keypair Generated by {@link generateKeypair}.
|
|
1127
|
+
* @param opts Registration options (endpoint, API key, name).
|
|
1128
|
+
*/
|
|
1129
|
+
declare function registerIdentity(keypair: Keypair, opts: RegistrationOptions): Promise<RegisteredIdentity>;
|
|
1130
|
+
interface RotationOptions {
|
|
1131
|
+
/** DataGrout substrate identity API base URL. */
|
|
1132
|
+
endpoint: string;
|
|
1133
|
+
/** Human-readable label for the renewed identity. */
|
|
1134
|
+
name: string;
|
|
1135
|
+
/** CA cert URL override. */
|
|
1136
|
+
caUrl?: string;
|
|
1137
|
+
/** Current identity PEM strings, used to build the mTLS client cert. */
|
|
1138
|
+
currentCertPem: string;
|
|
1139
|
+
currentKeyPem: string;
|
|
1140
|
+
}
|
|
1141
|
+
/**
|
|
1142
|
+
* Rotate the Substrate identity by presenting the current cert over mTLS.
|
|
1143
|
+
*
|
|
1144
|
+
* Generates a new ECDSA P-256 keypair and sends the public key to the `/rotate`
|
|
1145
|
+
* endpoint, authenticated with the *existing* client certificate over mTLS.
|
|
1146
|
+
* The server returns a new DG-CA-signed certificate.
|
|
1147
|
+
*
|
|
1148
|
+
* Note: This uses Node.js `https` for mTLS — not compatible with browser environments.
|
|
1149
|
+
*/
|
|
1150
|
+
declare function rotateIdentity(opts: RotationOptions): Promise<RegisteredIdentity>;
|
|
1151
|
+
interface SavedPaths {
|
|
1152
|
+
certPath: string;
|
|
1153
|
+
keyPath: string;
|
|
1154
|
+
caPath?: string;
|
|
1155
|
+
}
|
|
1156
|
+
/**
|
|
1157
|
+
* Save a registered identity to a directory for auto-discovery by future sessions.
|
|
1158
|
+
*
|
|
1159
|
+
* Writes:
|
|
1160
|
+
* - `{dir}/identity.pem` — DG-signed certificate
|
|
1161
|
+
* - `{dir}/identity_key.pem` — private key (mode 0600)
|
|
1162
|
+
* - `{dir}/ca.pem` — DG CA certificate (if present)
|
|
1163
|
+
*/
|
|
1164
|
+
declare function saveIdentity(identity: RegisteredIdentity, directory?: string): SavedPaths;
|
|
1165
|
+
|
|
1166
|
+
/**
|
|
1167
|
+
* Typed error classes for the DataGrout Conduit SDK.
|
|
1168
|
+
*
|
|
1169
|
+
* All errors extend `ConduitError` so callers can catch the whole family with
|
|
1170
|
+
* a single `instanceof ConduitError` check, or target specific subclasses.
|
|
1171
|
+
*/
|
|
1172
|
+
|
|
1173
|
+
/**
|
|
1174
|
+
* Base class for all errors thrown by the Conduit SDK.
|
|
1175
|
+
*
|
|
1176
|
+
* Fixes the prototype chain so `instanceof` works correctly when compiling
|
|
1177
|
+
* to CommonJS / ES5 targets.
|
|
1178
|
+
*/
|
|
1179
|
+
declare class ConduitError extends Error {
|
|
1180
|
+
constructor(message: string);
|
|
1181
|
+
}
|
|
1182
|
+
/**
|
|
1183
|
+
* Thrown when a `Client` method is called before `connect()` has been invoked,
|
|
1184
|
+
* or after `disconnect()` has been called.
|
|
1185
|
+
*/
|
|
1186
|
+
declare class NotInitializedError extends ConduitError {
|
|
1187
|
+
constructor();
|
|
1188
|
+
}
|
|
1189
|
+
/**
|
|
1190
|
+
* Thrown when the DataGrout gateway returns HTTP 429 (Too Many Requests).
|
|
1191
|
+
*
|
|
1192
|
+
* Authenticated DataGrout users are never rate-limited. Unauthenticated
|
|
1193
|
+
* callers hitting the hourly cap will receive this error.
|
|
1194
|
+
*
|
|
1195
|
+
* @property status - Parsed rate-limit header state.
|
|
1196
|
+
* @property retryAfter - Seconds to wait before retrying (from `Retry-After` header), if present.
|
|
1197
|
+
*/
|
|
1198
|
+
declare class RateLimitError extends ConduitError {
|
|
1199
|
+
readonly status: RateLimitStatus;
|
|
1200
|
+
readonly retryAfter?: number;
|
|
1201
|
+
constructor(status: RateLimitStatus, retryAfter?: number);
|
|
1202
|
+
}
|
|
1203
|
+
/**
|
|
1204
|
+
* Thrown when the server returns HTTP 401 Unauthorized or HTTP 403 Forbidden.
|
|
1205
|
+
*/
|
|
1206
|
+
declare class AuthError extends ConduitError {
|
|
1207
|
+
constructor(message?: string);
|
|
1208
|
+
}
|
|
1209
|
+
/**
|
|
1210
|
+
* Thrown on network-level failures such as fetch errors, connection refused,
|
|
1211
|
+
* or request timeouts.
|
|
1212
|
+
*/
|
|
1213
|
+
declare class NetworkError extends ConduitError {
|
|
1214
|
+
constructor(message: string);
|
|
1215
|
+
}
|
|
1216
|
+
/**
|
|
1217
|
+
* Thrown when the server returns an unexpected non-success HTTP status or
|
|
1218
|
+
* a JSON-RPC error payload.
|
|
1219
|
+
*
|
|
1220
|
+
* @property code - HTTP status code or JSON-RPC error code.
|
|
1221
|
+
* @property serverMessage - Raw error message from the server.
|
|
1222
|
+
*/
|
|
1223
|
+
declare class ServerError extends ConduitError {
|
|
1224
|
+
readonly code: number;
|
|
1225
|
+
readonly serverMessage: string;
|
|
1226
|
+
constructor(code: number, serverMessage: string);
|
|
1227
|
+
}
|
|
1228
|
+
/**
|
|
1229
|
+
* Thrown when required parameters are missing, mutually-exclusive option
|
|
1230
|
+
* combinations are invalid, or a method receives an unusable configuration.
|
|
1231
|
+
*/
|
|
1232
|
+
declare class InvalidConfigError extends ConduitError {
|
|
1233
|
+
constructor(message: string);
|
|
1234
|
+
}
|
|
1235
|
+
|
|
1236
|
+
/**
|
|
1237
|
+
* DataGrout Conduit SDK for TypeScript/JavaScript
|
|
1238
|
+
*/
|
|
1239
|
+
|
|
1240
|
+
declare const version = "0.1.0";
|
|
1241
|
+
|
|
1242
|
+
export { type AuthConfig, AuthError, type Byok, type ChartOptions, Client, type ClientOptions, ConduitError, ConduitIdentity, type ConstrainOptions, type CreditEstimate, DEFAULT_IDENTITY_DIR, DG_CA_URL, DG_SUBSTRATE_ENDPOINT, type DiscoverOptions, type DiscoverResult, type FlowOptions, type ForgetOptions, type GuideOptions, type GuideRequestOptions, type GuideState, GuidedSession, InvalidConfigError, type Keypair, type MCPPrompt, type MCPResource, type MCPTool, type MtlsConfig, NetworkError, NotInitializedError, OAuthTokenProvider, type PerformOptions, type PerformResult, type PlanOptions, type PrismFocusOptions, type QueryCellOptions, type RateLimit, RateLimitError, type RateLimitStatus, type Receipt, type ReflectOptions, type RefractOptions, type RegisteredIdentity, type RegistrationOptions, type RememberOptions, type RenewalOptions, type RotationOptions, type SavedPaths, ServerError, type ToolInfo, type ToolMeta, deriveTokenEndpoint, extractMeta, fetchDgCaCert, fetchWithIdentity, generateKeypair, isDgUrl, refreshCaCert, registerIdentity, rotateIdentity, saveIdentity, version };
|