@datagrout/conduit 0.1.0 → 0.2.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/dist/index.mjs CHANGED
@@ -735,6 +735,304 @@ function saveIdentity(identity, directory = DEFAULT_IDENTITY_DIR) {
735
735
  return result;
736
736
  }
737
737
 
738
+ // src/namespaces/prism.ts
739
+ var PrismNamespace = class {
740
+ /** @internal */
741
+ constructor(callDg, warn) {
742
+ this.callDg = callDg;
743
+ this.warn = warn;
744
+ }
745
+ /** AI-driven data transformation (`data-grout/prism.refract`). */
746
+ async refract(options) {
747
+ this.warn("prism.refract");
748
+ const params = {
749
+ goal: options.goal,
750
+ payload: options.payload
751
+ };
752
+ if (options.verbose !== void 0) params.verbose = options.verbose;
753
+ if (options.chart !== void 0) params.chart = options.chart;
754
+ return this.callDg("prism.refract", params);
755
+ }
756
+ /** AI-driven charting (`data-grout/prism.chart`). */
757
+ async chart(options) {
758
+ this.warn("prism.chart");
759
+ const params = {
760
+ goal: options.goal,
761
+ payload: options.payload
762
+ };
763
+ if (options.format) params.format = options.format;
764
+ if (options.chartType) params.chart_type = options.chartType;
765
+ if (options.title) params.title = options.title;
766
+ if (options.xLabel) params.x_label = options.xLabel;
767
+ if (options.yLabel) params.y_label = options.yLabel;
768
+ if (options.width !== void 0) params.width = options.width;
769
+ if (options.height !== void 0) params.height = options.height;
770
+ return this.callDg("prism.chart", params);
771
+ }
772
+ /** Generate a document toward a natural-language goal (`data-grout/prism.render`). */
773
+ async render(options) {
774
+ this.warn("prism.render");
775
+ const { goal, format = "markdown", payload, sections, ...rest } = options;
776
+ const params = { goal, format, ...rest };
777
+ if (payload !== void 0) params.payload = payload;
778
+ if (sections !== void 0) params.sections = sections;
779
+ return this.callDg("prism.render", params);
780
+ }
781
+ /** Convert content to another format without LLM (`data-grout/prism.export`). */
782
+ async export(options) {
783
+ this.warn("prism.export");
784
+ const { content, format, ...rest } = options;
785
+ const params = { content, format, ...rest };
786
+ return this.callDg("prism.export", params);
787
+ }
788
+ /** Semantic type transformation (`data-grout/prism.focus`). */
789
+ async focus(options) {
790
+ this.warn("prism.focus");
791
+ const params = {
792
+ data: options.data,
793
+ source_type: options.sourceType,
794
+ target_type: options.targetType,
795
+ ...options.sourceAnnotations && { source_annotations: options.sourceAnnotations },
796
+ ...options.targetAnnotations && { target_annotations: options.targetAnnotations },
797
+ ...options.context && { context: options.context }
798
+ };
799
+ return this.callDg("prism.focus", params);
800
+ }
801
+ };
802
+
803
+ // src/namespaces/logic.ts
804
+ var LogicNamespace = class {
805
+ /** @internal */
806
+ constructor(callDg, warn) {
807
+ this.callDg = callDg;
808
+ this.warn = warn;
809
+ }
810
+ async remember(statementOrOptions, optionsArg) {
811
+ let statement;
812
+ let opts;
813
+ if (typeof statementOrOptions === "string") {
814
+ statement = statementOrOptions;
815
+ opts = optionsArg;
816
+ } else {
817
+ opts = statementOrOptions;
818
+ statement = opts.statement;
819
+ }
820
+ if (!statement && !opts?.facts?.length) {
821
+ throw new InvalidConfigError("remember() requires either a statement or facts");
822
+ }
823
+ const params = { tag: opts?.tag ?? "default" };
824
+ if (opts?.facts) {
825
+ params.facts = opts.facts;
826
+ } else {
827
+ params.statement = statement;
828
+ }
829
+ return this.callDg("logic.remember", params);
830
+ }
831
+ async query(questionOrOptions, optionsArg) {
832
+ let question;
833
+ let opts;
834
+ if (typeof questionOrOptions === "string") {
835
+ question = questionOrOptions;
836
+ opts = optionsArg;
837
+ } else {
838
+ opts = questionOrOptions;
839
+ question = opts.question;
840
+ }
841
+ if (!question && !opts?.patterns?.length) {
842
+ throw new InvalidConfigError("query() requires either a question or patterns");
843
+ }
844
+ const params = { limit: opts?.limit ?? 50 };
845
+ if (opts?.patterns) {
846
+ params.patterns = opts.patterns;
847
+ } else {
848
+ params.question = question;
849
+ }
850
+ return this.callDg("logic.query", params);
851
+ }
852
+ /** Retract facts from the logic cell (`data-grout/logic.forget`). */
853
+ async forget(options) {
854
+ if (!options.handles?.length && !options.pattern) {
855
+ throw new InvalidConfigError("forget() requires either handles or pattern");
856
+ }
857
+ const params = {};
858
+ if (options.handles) params.handles = options.handles;
859
+ if (options.pattern) params.pattern = options.pattern;
860
+ return this.callDg("logic.forget", params);
861
+ }
862
+ /** Reflect on the logic cell (`data-grout/logic.reflect`). */
863
+ async reflect(options) {
864
+ const params = { summary_only: options?.summaryOnly ?? false };
865
+ if (options?.entity) params.entity = options.entity;
866
+ return this.callDg("logic.reflect", params);
867
+ }
868
+ /** Add a constraint rule (`data-grout/logic.constrain`). */
869
+ async constrain(rule, options) {
870
+ const params = { rule, tag: options?.tag ?? "constraint" };
871
+ return this.callDg("logic.constrain", params);
872
+ }
873
+ /** Hydrate the logic cell from external data (`data-grout/logic.hydrate`). */
874
+ async hydrate(params) {
875
+ this.warn("logic.hydrate");
876
+ return this.callDg("logic.hydrate", params);
877
+ }
878
+ /** Export the logic cell contents (`data-grout/logic.export`). */
879
+ async exportCell(params = {}) {
880
+ this.warn("logic.export");
881
+ return this.callDg("logic.export", params);
882
+ }
883
+ /** Import facts into the logic cell (`data-grout/logic.import`). */
884
+ async importCell(params) {
885
+ this.warn("logic.import");
886
+ return this.callDg("logic.import", params);
887
+ }
888
+ /** Tabulate logic cell contents (`data-grout/logic.tabulate`). */
889
+ async tabulate(params = {}) {
890
+ this.warn("logic.tabulate");
891
+ return this.callDg("logic.tabulate", params);
892
+ }
893
+ /** Manage hypothetical worlds (`data-grout/logic.worlds`). */
894
+ async worlds(params) {
895
+ this.warn("logic.worlds");
896
+ return this.callDg("logic.worlds", params);
897
+ }
898
+ };
899
+
900
+ // src/namespaces/warden.ts
901
+ var WardenNamespace = class {
902
+ /** @internal */
903
+ constructor(callDg, warn) {
904
+ this.callDg = callDg;
905
+ this.warn = warn;
906
+ }
907
+ /** Run a canary safety check (`data-grout/warden.canary`). */
908
+ async canary(params) {
909
+ this.warn("warden.canary");
910
+ return this.callDg("warden.canary", params);
911
+ }
912
+ /** Verify intent before executing an action (`data-grout/warden.intent`). */
913
+ async verifyIntent(params) {
914
+ this.warn("warden.intent");
915
+ return this.callDg("warden.intent", params);
916
+ }
917
+ /** Adjudicate a dispute or ambiguity (`data-grout/warden.adjudicate`). */
918
+ async adjudicate(params) {
919
+ this.warn("warden.adjudicate");
920
+ return this.callDg("warden.adjudicate", params);
921
+ }
922
+ /** Multi-model ensemble consensus check (`data-grout/warden.ensemble`). */
923
+ async ensemble(params) {
924
+ this.warn("warden.ensemble");
925
+ return this.callDg("warden.ensemble", params);
926
+ }
927
+ };
928
+
929
+ // src/namespaces/deliverables.ts
930
+ var DeliverablesNamespace = class {
931
+ /** @internal */
932
+ constructor(callDg, warn) {
933
+ this.callDg = callDg;
934
+ this.warn = warn;
935
+ }
936
+ /** Register a work product (`data-grout/deliverables.register`). */
937
+ async register(params) {
938
+ this.warn("deliverables.register");
939
+ return this.callDg("deliverables.register", params);
940
+ }
941
+ /** List deliverables with optional semantic search (`data-grout/deliverables.list`). */
942
+ async list(params = {}) {
943
+ this.warn("deliverables.list");
944
+ return this.callDg("deliverables.list", params);
945
+ }
946
+ /** Get a specific deliverable by reference (`data-grout/deliverables.get`). */
947
+ async get(refId) {
948
+ this.warn("deliverables.get");
949
+ return this.callDg("deliverables.get", { ref: refId });
950
+ }
951
+ };
952
+
953
+ // src/namespaces/ephemerals.ts
954
+ var EphemeralsNamespace = class {
955
+ /** @internal */
956
+ constructor(callDg, warn) {
957
+ this.callDg = callDg;
958
+ this.warn = warn;
959
+ }
960
+ /** List cached results (`data-grout/ephemerals.list`). */
961
+ async list(params = {}) {
962
+ this.warn("ephemerals.list");
963
+ return this.callDg("ephemerals.list", params);
964
+ }
965
+ /** Inspect a specific cache entry (`data-grout/ephemerals.inspect`). */
966
+ async inspect(cacheRef) {
967
+ this.warn("ephemerals.inspect");
968
+ return this.callDg("ephemerals.inspect", { cache_ref: cacheRef });
969
+ }
970
+ };
971
+
972
+ // src/namespaces/flow.ts
973
+ var FlowNamespace = class {
974
+ /** @internal */
975
+ constructor(callDg, warn) {
976
+ this.callDg = callDg;
977
+ this.warn = warn;
978
+ }
979
+ /** Execute a multi-step workflow plan (`data-grout/flow.into`). */
980
+ async run(options) {
981
+ this.warn("flow.into");
982
+ const params = {
983
+ plan: options.plan,
984
+ validate_ctc: options.validateCtc ?? true,
985
+ save_as_skill: options.saveAsSkill ?? false
986
+ };
987
+ if (options.inputData) params.input_data = options.inputData;
988
+ return this.callDg("flow.into", params);
989
+ }
990
+ /** Conditional dispatch with predicate-based branching (`data-grout/flow.route`). */
991
+ async route(options) {
992
+ this.warn("flow.route");
993
+ const { branches, payload, cacheRef, else: elseTarget, ...rest } = options;
994
+ const params = { branches, ...rest };
995
+ if (payload !== void 0) params.payload = payload;
996
+ if (cacheRef !== void 0) params.cache_ref = cacheRef;
997
+ if (elseTarget !== void 0) params.else = elseTarget;
998
+ return this.callDg("flow.route", params);
999
+ }
1000
+ /** Pause workflow for human approval (`data-grout/flow.request-approval`). */
1001
+ async requestApproval(options) {
1002
+ this.warn("flow.request-approval");
1003
+ const { action, details, reason, context, ...rest } = options;
1004
+ const params = { action, ...rest };
1005
+ if (details !== void 0) params.details = details;
1006
+ if (reason !== void 0) params.reason = reason;
1007
+ if (context !== void 0) params.context = context;
1008
+ return this.callDg("flow.request-approval", params);
1009
+ }
1010
+ /** Request user clarification for missing fields (`data-grout/flow.request-feedback`). */
1011
+ async requestFeedback(options) {
1012
+ this.warn("flow.request-feedback");
1013
+ const { missing_fields, reason, ...rest } = options;
1014
+ const params = { missing_fields, reason, ...rest };
1015
+ return this.callDg("flow.request-feedback", params);
1016
+ }
1017
+ /** List recent tool executions (`data-grout/inspect.execution-history`). */
1018
+ async history(options = {}) {
1019
+ this.warn("inspect.execution-history");
1020
+ const params = {
1021
+ limit: options.limit ?? 50,
1022
+ offset: options.offset ?? 0,
1023
+ refractions_only: options.refractions_only ?? false,
1024
+ ...options
1025
+ };
1026
+ if (options.status !== void 0) params.status = options.status;
1027
+ return this.callDg("inspect.execution-history", params);
1028
+ }
1029
+ /** Get details for a specific execution (`data-grout/inspect.execution-details`). */
1030
+ async details(executionId) {
1031
+ this.warn("inspect.execution-details");
1032
+ return this.callDg("inspect.execution-details", { execution_id: executionId });
1033
+ }
1034
+ };
1035
+
738
1036
  // src/client.ts
739
1037
  var GuidedSession = class {
740
1038
  client;
@@ -942,6 +1240,35 @@ var Client2 = class _Client {
942
1240
  }
943
1241
  }
944
1242
  }
1243
+ // ===== Namespace Accessors =====
1244
+ callDgTool = async (tool, params) => {
1245
+ this.ensureInitialized();
1246
+ return this.sendWithRetry(() => this.transport.callTool(`data-grout/${tool}`, params));
1247
+ };
1248
+ /** Data transformation, charting, rendering, and type bridging. */
1249
+ get prism() {
1250
+ return new PrismNamespace(this.callDgTool, (m) => this.warnIfNotDg(m));
1251
+ }
1252
+ /** Persistent agent memory backed by a Prolog logic cell. */
1253
+ get logic() {
1254
+ return new LogicNamespace(this.callDgTool, (m) => this.warnIfNotDg(m));
1255
+ }
1256
+ /** Safety gates, intent verification, and multi-model consensus. */
1257
+ get warden() {
1258
+ return new WardenNamespace(this.callDgTool, (m) => this.warnIfNotDg(m));
1259
+ }
1260
+ /** Work product registration, listing, and retrieval. */
1261
+ get deliverables() {
1262
+ return new DeliverablesNamespace(this.callDgTool, (m) => this.warnIfNotDg(m));
1263
+ }
1264
+ /** Cache listing and inspection. */
1265
+ get ephemerals() {
1266
+ return new EphemeralsNamespace(this.callDgTool, (m) => this.warnIfNotDg(m));
1267
+ }
1268
+ /** Multi-step orchestration, routing, approvals, and execution history. */
1269
+ get flow() {
1270
+ return new FlowNamespace(this.callDgTool, (m) => this.warnIfNotDg(m));
1271
+ }
945
1272
  // ===== Standard MCP API (Drop-in Compatible) =====
946
1273
  /**
947
1274
  * List all tools exposed by the connected MCP server.
@@ -1162,60 +1489,6 @@ var Client2 = class _Client {
1162
1489
  };
1163
1490
  return new GuidedSession(this, state);
1164
1491
  }
1165
- /**
1166
- * Execute a pre-planned sequence of tool calls (a "flow") through the
1167
- * DataGrout gateway.
1168
- *
1169
- * JSON-RPC method: `tools/call` → `data-grout/flow.into`
1170
- *
1171
- * @param options.plan - Ordered list of tool call descriptors.
1172
- * @param options.validateCtc - Validate each call against its CTC schema (default: `true`).
1173
- * @param options.saveAsSkill - Persist the flow as a reusable skill (default: `false`).
1174
- * @param options.inputData - Runtime input data for the flow.
1175
- */
1176
- async flowInto(options) {
1177
- this.ensureInitialized();
1178
- this.warnIfNotDg("flowInto");
1179
- const params = {
1180
- plan: options.plan,
1181
- validate_ctc: options.validateCtc ?? true,
1182
- save_as_skill: options.saveAsSkill ?? false
1183
- };
1184
- if (options.inputData) {
1185
- params.input_data = options.inputData;
1186
- }
1187
- return this.sendWithRetry(
1188
- () => this.transport.callTool("data-grout/flow.into", params)
1189
- );
1190
- }
1191
- /**
1192
- * Transform data from one annotated type to another using the DataGrout
1193
- * Prism semantic mapping engine.
1194
- *
1195
- * JSON-RPC method: `tools/call` → `data-grout/prism.focus`
1196
- *
1197
- * @param options.data - Source payload to transform.
1198
- * @param options.sourceType - Semantic type of the source data.
1199
- * @param options.targetType - Desired semantic type for the output.
1200
- * @param options.sourceAnnotations - Additional schema hints for the source.
1201
- * @param options.targetAnnotations - Additional schema hints for the target.
1202
- * @param options.context - Free-text context to guide the mapping.
1203
- */
1204
- async prismFocus(options) {
1205
- this.ensureInitialized();
1206
- this.warnIfNotDg("prismFocus");
1207
- const params = {
1208
- data: options.data,
1209
- source_type: options.sourceType,
1210
- target_type: options.targetType,
1211
- ...options.sourceAnnotations && { source_annotations: options.sourceAnnotations },
1212
- ...options.targetAnnotations && { target_annotations: options.targetAnnotations },
1213
- ...options.context && { context: options.context }
1214
- };
1215
- return this.sendWithRetry(
1216
- () => this.transport.callTool("data-grout/prism.focus", params)
1217
- );
1218
- }
1219
1492
  /**
1220
1493
  * Generate an execution plan for a goal using DataGrout's planning engine.
1221
1494
  *
@@ -1255,126 +1528,6 @@ var Client2 = class _Client {
1255
1528
  () => this.transport.callTool("data-grout/discovery.plan", params)
1256
1529
  );
1257
1530
  }
1258
- /**
1259
- * Analyse and summarise a payload using the DataGrout Prism refraction engine.
1260
- *
1261
- * JSON-RPC method: `tools/call` → `data-grout/prism.refract`
1262
- *
1263
- * @param options.goal - Description of what to extract or summarise.
1264
- * @param options.payload - Input data to analyse (any JSON-serializable value).
1265
- * @param options.verbose - Include detailed processing trace in the response.
1266
- * @param options.chart - Also generate a chart representation.
1267
- */
1268
- async refract(options) {
1269
- this.ensureInitialized();
1270
- this.warnIfNotDg("refract");
1271
- const params = {
1272
- goal: options.goal,
1273
- payload: options.payload
1274
- };
1275
- if (options.verbose !== void 0) params.verbose = options.verbose;
1276
- if (options.chart !== void 0) params.chart = options.chart;
1277
- return this.sendWithRetry(
1278
- () => this.transport.callTool("data-grout/prism.refract", params)
1279
- );
1280
- }
1281
- /**
1282
- * Generate a chart from a data payload using the DataGrout Prism engine.
1283
- *
1284
- * JSON-RPC method: `tools/call` → `data-grout/prism.chart`
1285
- *
1286
- * @param options.goal - What the chart should visualise.
1287
- * @param options.payload - Input data (any JSON-serializable value).
1288
- * @param options.format - Output format (e.g. `"png"`, `"svg"`).
1289
- * @param options.chartType - Chart type (e.g. `"bar"`, `"line"`, `"pie"`).
1290
- * @param options.title - Chart title.
1291
- * @param options.xLabel - X-axis label.
1292
- * @param options.yLabel - Y-axis label.
1293
- * @param options.width - Chart width in pixels.
1294
- * @param options.height - Chart height in pixels.
1295
- */
1296
- async chart(options) {
1297
- this.ensureInitialized();
1298
- this.warnIfNotDg("chart");
1299
- const params = {
1300
- goal: options.goal,
1301
- payload: options.payload
1302
- };
1303
- if (options.format) params.format = options.format;
1304
- if (options.chartType) params.chart_type = options.chartType;
1305
- if (options.title) params.title = options.title;
1306
- if (options.xLabel) params.x_label = options.xLabel;
1307
- if (options.yLabel) params.y_label = options.yLabel;
1308
- if (options.width !== void 0) params.width = options.width;
1309
- if (options.height !== void 0) params.height = options.height;
1310
- return this.sendWithRetry(
1311
- () => this.transport.callTool("data-grout/prism.chart", params)
1312
- );
1313
- }
1314
- /**
1315
- * Generate a document toward a natural-language goal.
1316
- * Supported formats: markdown, html, pdf, json.
1317
- */
1318
- async render(options) {
1319
- this.ensureInitialized();
1320
- this.warnIfNotDg("render");
1321
- const { goal, format = "markdown", payload, sections, ...rest } = options;
1322
- const params = { goal, format, ...rest };
1323
- if (payload !== void 0) params.payload = payload;
1324
- if (sections !== void 0) params.sections = sections;
1325
- return this.sendWithRetry(() => this.transport.callTool("data-grout/prism.render", params));
1326
- }
1327
- /**
1328
- * Convert content to another format (no LLM). Supports csv, xlsx, pdf, json, html, markdown, etc.
1329
- */
1330
- async export(options) {
1331
- this.ensureInitialized();
1332
- this.warnIfNotDg("export");
1333
- const { content, format, ...rest } = options;
1334
- const params = { content, format, ...rest };
1335
- return this.sendWithRetry(() => this.transport.callTool("data-grout/prism.export", params));
1336
- }
1337
- /**
1338
- * Pause workflow for human approval. Use for destructive or policy-gated actions.
1339
- */
1340
- async requestApproval(options) {
1341
- this.ensureInitialized();
1342
- this.warnIfNotDg("requestApproval");
1343
- const { action, details, reason, context, ...rest } = options;
1344
- const params = { action, ...rest };
1345
- if (details !== void 0) params.details = details;
1346
- if (reason !== void 0) params.reason = reason;
1347
- if (context !== void 0) params.context = context;
1348
- return this.sendWithRetry(() => this.transport.callTool("data-grout/flow.request-approval", params));
1349
- }
1350
- /**
1351
- * Request user clarification for missing fields. Pauses until user provides values.
1352
- */
1353
- async requestFeedback(options) {
1354
- this.ensureInitialized();
1355
- this.warnIfNotDg("requestFeedback");
1356
- const { missing_fields, reason, ...rest } = options;
1357
- const params = { missing_fields, reason, ...rest };
1358
- return this.sendWithRetry(() => this.transport.callTool("data-grout/flow.request-feedback", params));
1359
- }
1360
- /**
1361
- * List recent tool executions for the current server.
1362
- */
1363
- async executionHistory(options = {}) {
1364
- this.ensureInitialized();
1365
- this.warnIfNotDg("executionHistory");
1366
- const params = { limit: options.limit ?? 50, offset: options.offset ?? 0, refractions_only: options.refractions_only ?? false, ...options };
1367
- if (options.status !== void 0) params.status = options.status;
1368
- return this.sendWithRetry(() => this.transport.callTool("data-grout/inspect.execution-history", params));
1369
- }
1370
- /**
1371
- * Get details and transcript for a specific execution.
1372
- */
1373
- async executionDetails(executionId) {
1374
- this.ensureInitialized();
1375
- this.warnIfNotDg("executionDetails");
1376
- return this.sendWithRetry(() => this.transport.callTool("data-grout/inspect.execution-details", { execution_id: executionId }));
1377
- }
1378
1531
  /**
1379
1532
  * Call any DataGrout first-party tool by its short name.
1380
1533
  *
@@ -1391,119 +1544,6 @@ var Client2 = class _Client {
1391
1544
  const method = `data-grout/${toolShortName}`;
1392
1545
  return this.sendWithRetry(() => this.transport.callTool(method, params));
1393
1546
  }
1394
- async remember(statementOrOptions, optionsArg) {
1395
- this.ensureInitialized();
1396
- let statement;
1397
- let opts;
1398
- if (typeof statementOrOptions === "string") {
1399
- statement = statementOrOptions;
1400
- opts = optionsArg;
1401
- } else {
1402
- opts = statementOrOptions;
1403
- statement = opts.statement;
1404
- }
1405
- if (!statement && !opts?.facts?.length) {
1406
- throw new InvalidConfigError("remember() requires either a statement or facts");
1407
- }
1408
- const params = {
1409
- tag: opts?.tag ?? "default"
1410
- };
1411
- if (opts?.facts) {
1412
- params.facts = opts.facts;
1413
- } else {
1414
- params.statement = statement;
1415
- }
1416
- return this.sendWithRetry(
1417
- () => this.transport.callTool("data-grout/logic.remember", params)
1418
- );
1419
- }
1420
- async queryCell(questionOrOptions, optionsArg) {
1421
- this.ensureInitialized();
1422
- let question;
1423
- let opts;
1424
- if (typeof questionOrOptions === "string") {
1425
- question = questionOrOptions;
1426
- opts = optionsArg;
1427
- } else {
1428
- opts = questionOrOptions;
1429
- question = opts.question;
1430
- }
1431
- if (!question && !opts?.patterns?.length) {
1432
- throw new InvalidConfigError("queryCell() requires either a question or patterns");
1433
- }
1434
- const params = {
1435
- limit: opts?.limit ?? 50
1436
- };
1437
- if (opts?.patterns) {
1438
- params.patterns = opts.patterns;
1439
- } else {
1440
- params.question = question;
1441
- }
1442
- return this.sendWithRetry(
1443
- () => this.transport.callTool("data-grout/logic.query", params)
1444
- );
1445
- }
1446
- /**
1447
- * Retract facts from the agent's logic cell.
1448
- *
1449
- * Throws `InvalidConfigError` if neither `handles` nor `pattern` is provided.
1450
- *
1451
- * JSON-RPC method: `tools/call` → `data-grout/logic.forget`
1452
- *
1453
- * @param options.handles - Specific fact handles to retract.
1454
- * @param options.pattern - Natural language pattern — retract all matching facts.
1455
- */
1456
- async forget(options) {
1457
- this.ensureInitialized();
1458
- if (!options.handles?.length && !options.pattern) {
1459
- throw new InvalidConfigError("forget() requires either handles or pattern");
1460
- }
1461
- const params = {};
1462
- if (options.handles) params.handles = options.handles;
1463
- if (options.pattern) params.pattern = options.pattern;
1464
- return this.sendWithRetry(
1465
- () => this.transport.callTool("data-grout/logic.forget", params)
1466
- );
1467
- }
1468
- /**
1469
- * Reflect on the agent's logic cell — returns a full snapshot or a
1470
- * per-entity view of all stored facts.
1471
- *
1472
- * JSON-RPC method: `tools/call` → `data-grout/logic.reflect`
1473
- *
1474
- * @param options.entity - Optional entity name to scope reflection.
1475
- * @param options.summaryOnly - When `true`, return only counts (default: `false`).
1476
- */
1477
- async reflect(options) {
1478
- this.ensureInitialized();
1479
- const params = {
1480
- summary_only: options?.summaryOnly ?? false
1481
- };
1482
- if (options?.entity) params.entity = options.entity;
1483
- return this.sendWithRetry(
1484
- () => this.transport.callTool("data-grout/logic.reflect", params)
1485
- );
1486
- }
1487
- /**
1488
- * Store a logical rule or policy in the agent's logic cell.
1489
- *
1490
- * Rules are permanent constraints evaluated during `queryCell()` calls.
1491
- *
1492
- * JSON-RPC method: `tools/call` → `data-grout/logic.constrain`
1493
- *
1494
- * @param rule - Natural language rule (e.g. `"VIP customers have ARR > $500K"`).
1495
- * @param options.tag - Tag/namespace for this constraint (default: `"constraint"`).
1496
- */
1497
- async constrain(rule, options) {
1498
- this.ensureInitialized();
1499
- const params = {
1500
- rule,
1501
- tag: options?.tag ?? "constraint"
1502
- };
1503
- return this.sendWithRetry(
1504
- () => this.transport.callTool("data-grout/logic.constrain", params)
1505
- );
1506
- }
1507
1547
  /**
1508
1548
  * Estimate the credit cost of a tool call without executing it.
1509
1549
  *
@@ -1535,8 +1575,41 @@ init_oauth();
1535
1575
 
1536
1576
  // src/types.ts
1537
1577
  function extractMeta(result) {
1538
- const raw = result?._meta?.datagrout ?? result?._datagrout ?? result?._meta;
1539
- if (!raw?.receipt) return null;
1578
+ const rich = result?._meta?.datagrout;
1579
+ if (rich?.receipt) {
1580
+ return buildToolMeta(rich);
1581
+ }
1582
+ const legacy = result?._datagrout ?? result?._meta;
1583
+ if (legacy?.receipt) {
1584
+ return buildToolMeta(legacy);
1585
+ }
1586
+ const dg = result?._dg;
1587
+ if (dg) {
1588
+ const credits = dg.credits ?? {};
1589
+ const breakdown = {};
1590
+ if (credits.premium !== void 0) breakdown.premium = credits.premium;
1591
+ if (credits.llm !== void 0) breakdown.llm = credits.llm;
1592
+ return {
1593
+ receipt: {
1594
+ receiptId: "",
1595
+ timestamp: "",
1596
+ estimatedCredits: credits.estimated ?? 0,
1597
+ actualCredits: credits.charged ?? 0,
1598
+ netCredits: credits.charged ?? 0,
1599
+ savings: 0,
1600
+ savingsBonus: 0,
1601
+ balanceAfter: credits.remaining,
1602
+ breakdown,
1603
+ byok: { enabled: false, discountApplied: 0, discountRate: 0 }
1604
+ }
1605
+ };
1606
+ }
1607
+ console.warn(
1608
+ '[conduit] No DataGrout metadata found in tool result. Cost tracking data is unavailable. Enable "Include DG Inline" or "Include DataGrout Metadata" in your server settings.'
1609
+ );
1610
+ return null;
1611
+ }
1612
+ function buildToolMeta(raw) {
1540
1613
  const r = raw.receipt;
1541
1614
  const receipt = {
1542
1615
  receiptId: r.receipt_id ?? "",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@datagrout/conduit",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Production-ready MCP client with mTLS, OAuth 2.1, and semantic discovery",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",