@dexto/core 1.2.6 → 1.3.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.
Files changed (82) hide show
  1. package/README.md +47 -13
  2. package/dist/agent/DextoAgent.cjs +92 -34
  3. package/dist/agent/DextoAgent.d.ts +3 -3
  4. package/dist/agent/DextoAgent.d.ts.map +1 -1
  5. package/dist/agent/DextoAgent.js +93 -36
  6. package/dist/agent/schemas.cjs +1 -1
  7. package/dist/agent/schemas.js +1 -1
  8. package/dist/agent/types.d.ts +0 -1
  9. package/dist/agent/types.d.ts.map +1 -1
  10. package/dist/approval/schemas.cjs +2 -1
  11. package/dist/approval/schemas.d.ts +21 -20
  12. package/dist/approval/schemas.d.ts.map +1 -1
  13. package/dist/approval/schemas.js +2 -1
  14. package/dist/context/manager.cjs +7 -0
  15. package/dist/context/manager.d.ts.map +1 -1
  16. package/dist/context/manager.js +7 -0
  17. package/dist/context/types.d.ts +6 -2
  18. package/dist/context/types.d.ts.map +1 -1
  19. package/dist/errors/types.cjs +1 -0
  20. package/dist/errors/types.d.ts +4 -2
  21. package/dist/errors/types.d.ts.map +1 -1
  22. package/dist/errors/types.js +1 -0
  23. package/dist/events/index.cjs +4 -1
  24. package/dist/events/index.d.ts +23 -52
  25. package/dist/events/index.d.ts.map +1 -1
  26. package/dist/events/index.js +4 -1
  27. package/dist/llm/formatters/openai.cjs +8 -1
  28. package/dist/llm/formatters/openai.d.ts.map +1 -1
  29. package/dist/llm/formatters/openai.js +8 -1
  30. package/dist/llm/tokenizer/openai.d.ts +8 -0
  31. package/dist/llm/tokenizer/openai.d.ts.map +1 -1
  32. package/dist/logger/v2/schemas.cjs +1 -1
  33. package/dist/logger/v2/schemas.js +1 -1
  34. package/dist/plugins/error-codes.cjs +1 -0
  35. package/dist/plugins/error-codes.d.ts +3 -1
  36. package/dist/plugins/error-codes.d.ts.map +1 -1
  37. package/dist/plugins/error-codes.js +1 -0
  38. package/dist/plugins/loader.cjs +25 -5
  39. package/dist/plugins/loader.d.ts.map +1 -1
  40. package/dist/plugins/loader.js +25 -5
  41. package/dist/prompts/providers/custom-prompt-provider.cjs +2 -2
  42. package/dist/prompts/providers/custom-prompt-provider.d.ts +1 -1
  43. package/dist/prompts/providers/custom-prompt-provider.d.ts.map +1 -1
  44. package/dist/prompts/providers/custom-prompt-provider.js +2 -2
  45. package/dist/storage/cache/factory.cjs +6 -2
  46. package/dist/storage/cache/factory.d.ts +2 -1
  47. package/dist/storage/cache/factory.d.ts.map +1 -1
  48. package/dist/storage/cache/factory.js +6 -2
  49. package/dist/storage/database/factory.cjs +11 -17
  50. package/dist/storage/database/factory.d.ts +2 -1
  51. package/dist/storage/database/factory.d.ts.map +1 -1
  52. package/dist/storage/database/factory.js +11 -17
  53. package/dist/storage/database/sqlite-store.cjs +8 -0
  54. package/dist/storage/database/sqlite-store.d.ts.map +1 -1
  55. package/dist/storage/database/sqlite-store.js +8 -0
  56. package/dist/storage/error-codes.cjs +1 -0
  57. package/dist/storage/error-codes.d.ts +1 -0
  58. package/dist/storage/error-codes.d.ts.map +1 -1
  59. package/dist/storage/error-codes.js +1 -0
  60. package/dist/storage/errors.cjs +17 -0
  61. package/dist/storage/errors.d.ts +9 -0
  62. package/dist/storage/errors.d.ts.map +1 -1
  63. package/dist/storage/errors.js +17 -0
  64. package/dist/telemetry/error-codes.cjs +36 -0
  65. package/dist/telemetry/error-codes.d.ts +13 -0
  66. package/dist/telemetry/error-codes.d.ts.map +1 -0
  67. package/dist/telemetry/error-codes.js +13 -0
  68. package/dist/telemetry/errors.cjs +105 -0
  69. package/dist/telemetry/errors.d.ts +28 -0
  70. package/dist/telemetry/errors.d.ts.map +1 -0
  71. package/dist/telemetry/errors.js +82 -0
  72. package/dist/telemetry/telemetry.cjs +92 -26
  73. package/dist/telemetry/telemetry.d.ts +1 -1
  74. package/dist/telemetry/telemetry.d.ts.map +1 -1
  75. package/dist/telemetry/telemetry.js +74 -18
  76. package/dist/tools/schemas.cjs +1 -1
  77. package/dist/tools/schemas.js +1 -1
  78. package/dist/tools/types.d.ts +0 -11
  79. package/dist/tools/types.d.ts.map +1 -1
  80. package/dist/utils/schema.d.ts +6 -0
  81. package/dist/utils/schema.d.ts.map +1 -1
  82. package/package.json +52 -14
@@ -0,0 +1,105 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var errors_exports = {};
20
+ __export(errors_exports, {
21
+ TelemetryError: () => TelemetryError
22
+ });
23
+ module.exports = __toCommonJS(errors_exports);
24
+ var import_DextoRuntimeError = require("../errors/DextoRuntimeError.js");
25
+ var import_types = require("../errors/types.js");
26
+ var import_error_codes = require("./error-codes.js");
27
+ class TelemetryError {
28
+ /**
29
+ * Required OpenTelemetry dependencies not installed
30
+ */
31
+ static dependencyNotInstalled(packages) {
32
+ return new import_DextoRuntimeError.DextoRuntimeError(
33
+ import_error_codes.TelemetryErrorCode.DEPENDENCY_NOT_INSTALLED,
34
+ import_types.ErrorScope.TELEMETRY,
35
+ import_types.ErrorType.USER,
36
+ "Telemetry is enabled but required OpenTelemetry packages are not installed.",
37
+ {
38
+ packages,
39
+ hint: `Install with: npm install ${packages.join(" ")}`,
40
+ recovery: "Or disable telemetry by setting enabled: false in your configuration."
41
+ }
42
+ );
43
+ }
44
+ /**
45
+ * Specific exporter dependency not installed (gRPC or HTTP)
46
+ */
47
+ static exporterDependencyNotInstalled(exporterType, packageName) {
48
+ return new import_DextoRuntimeError.DextoRuntimeError(
49
+ import_error_codes.TelemetryErrorCode.EXPORTER_DEPENDENCY_NOT_INSTALLED,
50
+ import_types.ErrorScope.TELEMETRY,
51
+ import_types.ErrorType.USER,
52
+ `OTLP ${exporterType.toUpperCase()} exporter configured but '${packageName}' is not installed.`,
53
+ {
54
+ exporterType,
55
+ packageName,
56
+ hint: `Install with: npm install ${packageName}`
57
+ }
58
+ );
59
+ }
60
+ /**
61
+ * Telemetry initialization failed
62
+ */
63
+ static initializationFailed(reason, originalError) {
64
+ return new import_DextoRuntimeError.DextoRuntimeError(
65
+ import_error_codes.TelemetryErrorCode.INITIALIZATION_FAILED,
66
+ import_types.ErrorScope.TELEMETRY,
67
+ import_types.ErrorType.SYSTEM,
68
+ `Failed to initialize telemetry: ${reason}`,
69
+ {
70
+ reason,
71
+ originalError: originalError instanceof Error ? originalError.message : String(originalError)
72
+ }
73
+ );
74
+ }
75
+ /**
76
+ * Telemetry not initialized when expected
77
+ */
78
+ static notInitialized() {
79
+ return new import_DextoRuntimeError.DextoRuntimeError(
80
+ import_error_codes.TelemetryErrorCode.NOT_INITIALIZED,
81
+ import_types.ErrorScope.TELEMETRY,
82
+ import_types.ErrorType.USER,
83
+ "Telemetry not initialized. Call Telemetry.init() first.",
84
+ {
85
+ hint: "Ensure telemetry is initialized before accessing the global instance."
86
+ }
87
+ );
88
+ }
89
+ /**
90
+ * Telemetry shutdown failed (non-blocking warning)
91
+ */
92
+ static shutdownFailed(reason) {
93
+ return new import_DextoRuntimeError.DextoRuntimeError(
94
+ import_error_codes.TelemetryErrorCode.SHUTDOWN_FAILED,
95
+ import_types.ErrorScope.TELEMETRY,
96
+ import_types.ErrorType.SYSTEM,
97
+ `Telemetry shutdown failed: ${reason}`,
98
+ { reason }
99
+ );
100
+ }
101
+ }
102
+ // Annotate the CommonJS export names for ESM import in node:
103
+ 0 && (module.exports = {
104
+ TelemetryError
105
+ });
@@ -0,0 +1,28 @@
1
+ import { DextoRuntimeError } from '../errors/DextoRuntimeError.js';
2
+ /**
3
+ * Telemetry error factory with typed methods for creating telemetry-specific errors
4
+ * Each method creates a properly typed error with TELEMETRY scope
5
+ */
6
+ export declare class TelemetryError {
7
+ /**
8
+ * Required OpenTelemetry dependencies not installed
9
+ */
10
+ static dependencyNotInstalled(packages: string[]): DextoRuntimeError;
11
+ /**
12
+ * Specific exporter dependency not installed (gRPC or HTTP)
13
+ */
14
+ static exporterDependencyNotInstalled(exporterType: 'grpc' | 'http', packageName: string): DextoRuntimeError;
15
+ /**
16
+ * Telemetry initialization failed
17
+ */
18
+ static initializationFailed(reason: string, originalError?: unknown): DextoRuntimeError;
19
+ /**
20
+ * Telemetry not initialized when expected
21
+ */
22
+ static notInitialized(): DextoRuntimeError;
23
+ /**
24
+ * Telemetry shutdown failed (non-blocking warning)
25
+ */
26
+ static shutdownFailed(reason: string): DextoRuntimeError;
27
+ }
28
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/telemetry/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AAInE;;;GAGG;AACH,qBAAa,cAAc;IACvB;;OAEG;IACH,MAAM,CAAC,sBAAsB,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,iBAAiB;IAcpE;;OAEG;IACH,MAAM,CAAC,8BAA8B,CACjC,YAAY,EAAE,MAAM,GAAG,MAAM,EAC7B,WAAW,EAAE,MAAM,GACpB,iBAAiB;IAcpB;;OAEG;IACH,MAAM,CAAC,oBAAoB,CAAC,MAAM,EAAE,MAAM,EAAE,aAAa,CAAC,EAAE,OAAO,GAAG,iBAAiB;IAcvF;;OAEG;IACH,MAAM,CAAC,cAAc,IAAI,iBAAiB;IAY1C;;OAEG;IACH,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,iBAAiB;CAS3D"}
@@ -0,0 +1,82 @@
1
+ import "../chunk-C6A6W6XS.js";
2
+ import { DextoRuntimeError } from "../errors/DextoRuntimeError.js";
3
+ import { ErrorScope, ErrorType } from "../errors/types.js";
4
+ import { TelemetryErrorCode } from "./error-codes.js";
5
+ class TelemetryError {
6
+ /**
7
+ * Required OpenTelemetry dependencies not installed
8
+ */
9
+ static dependencyNotInstalled(packages) {
10
+ return new DextoRuntimeError(
11
+ TelemetryErrorCode.DEPENDENCY_NOT_INSTALLED,
12
+ ErrorScope.TELEMETRY,
13
+ ErrorType.USER,
14
+ "Telemetry is enabled but required OpenTelemetry packages are not installed.",
15
+ {
16
+ packages,
17
+ hint: `Install with: npm install ${packages.join(" ")}`,
18
+ recovery: "Or disable telemetry by setting enabled: false in your configuration."
19
+ }
20
+ );
21
+ }
22
+ /**
23
+ * Specific exporter dependency not installed (gRPC or HTTP)
24
+ */
25
+ static exporterDependencyNotInstalled(exporterType, packageName) {
26
+ return new DextoRuntimeError(
27
+ TelemetryErrorCode.EXPORTER_DEPENDENCY_NOT_INSTALLED,
28
+ ErrorScope.TELEMETRY,
29
+ ErrorType.USER,
30
+ `OTLP ${exporterType.toUpperCase()} exporter configured but '${packageName}' is not installed.`,
31
+ {
32
+ exporterType,
33
+ packageName,
34
+ hint: `Install with: npm install ${packageName}`
35
+ }
36
+ );
37
+ }
38
+ /**
39
+ * Telemetry initialization failed
40
+ */
41
+ static initializationFailed(reason, originalError) {
42
+ return new DextoRuntimeError(
43
+ TelemetryErrorCode.INITIALIZATION_FAILED,
44
+ ErrorScope.TELEMETRY,
45
+ ErrorType.SYSTEM,
46
+ `Failed to initialize telemetry: ${reason}`,
47
+ {
48
+ reason,
49
+ originalError: originalError instanceof Error ? originalError.message : String(originalError)
50
+ }
51
+ );
52
+ }
53
+ /**
54
+ * Telemetry not initialized when expected
55
+ */
56
+ static notInitialized() {
57
+ return new DextoRuntimeError(
58
+ TelemetryErrorCode.NOT_INITIALIZED,
59
+ ErrorScope.TELEMETRY,
60
+ ErrorType.USER,
61
+ "Telemetry not initialized. Call Telemetry.init() first.",
62
+ {
63
+ hint: "Ensure telemetry is initialized before accessing the global instance."
64
+ }
65
+ );
66
+ }
67
+ /**
68
+ * Telemetry shutdown failed (non-blocking warning)
69
+ */
70
+ static shutdownFailed(reason) {
71
+ return new DextoRuntimeError(
72
+ TelemetryErrorCode.SHUTDOWN_FAILED,
73
+ ErrorScope.TELEMETRY,
74
+ ErrorType.SYSTEM,
75
+ `Telemetry shutdown failed: ${reason}`,
76
+ { reason }
77
+ );
78
+ }
79
+ }
80
+ export {
81
+ TelemetryError
82
+ };
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
+ var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
5
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
8
  var __export = (target, all) => {
7
9
  for (var name in all)
@@ -15,6 +17,14 @@ var __copyProps = (to, from, except, desc) => {
15
17
  }
16
18
  return to;
17
19
  };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
18
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
29
  var telemetry_exports = {};
20
30
  __export(telemetry_exports, {
@@ -22,15 +32,9 @@ __export(telemetry_exports, {
22
32
  });
23
33
  module.exports = __toCommonJS(telemetry_exports);
24
34
  var import_api = require("@opentelemetry/api");
25
- var import_sdk_node = require("@opentelemetry/sdk-node");
26
- var import_sdk_trace_base = require("@opentelemetry/sdk-trace-base");
27
- var import_exporter_trace_otlp_http = require("@opentelemetry/exporter-trace-otlp-http");
28
- var import_exporter_trace_otlp_grpc = require("@opentelemetry/exporter-trace-otlp-grpc");
29
- var import_auto_instrumentations_node = require("@opentelemetry/auto-instrumentations-node");
30
- var import_resources = require("@opentelemetry/resources");
31
- var import_semantic_conventions = require("@opentelemetry/semantic-conventions");
32
- var import_exporters = require("./exporters.js");
33
35
  var import_logger = require("../logger/logger.js");
36
+ var import_errors = require("./errors.js");
37
+ var import_DextoRuntimeError = require("../errors/DextoRuntimeError.js");
34
38
  class Telemetry {
35
39
  tracer = import_api.trace.getTracer("dexto");
36
40
  name = "dexto-service";
@@ -48,18 +52,47 @@ class Telemetry {
48
52
  }
49
53
  this._isInitialized = enabled && !!sdk;
50
54
  }
51
- static buildTraceExporter(config) {
55
+ static async buildTraceExporter(config) {
52
56
  const e = config?.export;
53
57
  if (!e || e.type === "console") {
54
- return new import_sdk_trace_base.ConsoleSpanExporter();
58
+ const { ConsoleSpanExporter: ConsoleSpanExporter2 } = await import("@opentelemetry/sdk-trace-base");
59
+ return new ConsoleSpanExporter2();
55
60
  }
56
61
  if (e.type === "otlp") {
57
62
  if (e.protocol === "grpc") {
63
+ let OTLPGrpcExporter;
64
+ try {
65
+ const mod = await import("@opentelemetry/exporter-trace-otlp-grpc");
66
+ OTLPGrpcExporter = mod.OTLPTraceExporter;
67
+ } catch (err) {
68
+ const error = err;
69
+ if (error.code === "ERR_MODULE_NOT_FOUND") {
70
+ throw import_errors.TelemetryError.exporterDependencyNotInstalled(
71
+ "grpc",
72
+ "@opentelemetry/exporter-trace-otlp-grpc"
73
+ );
74
+ }
75
+ throw err;
76
+ }
58
77
  const options2 = {};
59
78
  if (e.endpoint) {
60
79
  options2.url = e.endpoint;
61
80
  }
62
- return new import_exporter_trace_otlp_grpc.OTLPTraceExporter(options2);
81
+ return new OTLPGrpcExporter(options2);
82
+ }
83
+ let OTLPHttpExporter;
84
+ try {
85
+ const mod = await import("@opentelemetry/exporter-trace-otlp-http");
86
+ OTLPHttpExporter = mod.OTLPTraceExporter;
87
+ } catch (err) {
88
+ const error = err;
89
+ if (error.code === "ERR_MODULE_NOT_FOUND") {
90
+ throw import_errors.TelemetryError.exporterDependencyNotInstalled(
91
+ "http",
92
+ "@opentelemetry/exporter-trace-otlp-http"
93
+ );
94
+ }
95
+ throw err;
63
96
  }
64
97
  const options = {};
65
98
  if (e.endpoint) {
@@ -68,9 +101,10 @@ class Telemetry {
68
101
  if (e.headers) {
69
102
  options.headers = e.headers;
70
103
  }
71
- return new import_exporter_trace_otlp_http.OTLPTraceExporter(options);
104
+ return new OTLPHttpExporter(options);
72
105
  }
73
- return new import_sdk_trace_base.ConsoleSpanExporter();
106
+ const { ConsoleSpanExporter } = await import("@opentelemetry/sdk-trace-base");
107
+ return new ConsoleSpanExporter();
74
108
  }
75
109
  /**
76
110
  * Initialize telemetry with the given configuration
@@ -87,15 +121,44 @@ class Telemetry {
87
121
  const enabled = config.enabled !== false;
88
122
  let sdk;
89
123
  if (enabled) {
90
- const resource = new import_resources.Resource({
91
- [import_semantic_conventions.ATTR_SERVICE_NAME]: config.serviceName ?? "dexto-service"
124
+ let NodeSDK;
125
+ let Resource;
126
+ let getNodeAutoInstrumentations;
127
+ let ATTR_SERVICE_NAME;
128
+ try {
129
+ const sdkModule = await import("@opentelemetry/sdk-node");
130
+ NodeSDK = sdkModule.NodeSDK;
131
+ const resourcesModule = await import("@opentelemetry/resources");
132
+ Resource = resourcesModule.Resource;
133
+ const autoInstModule = await import("@opentelemetry/auto-instrumentations-node");
134
+ getNodeAutoInstrumentations = autoInstModule.getNodeAutoInstrumentations;
135
+ const semanticModule = await import("@opentelemetry/semantic-conventions");
136
+ ATTR_SERVICE_NAME = semanticModule.ATTR_SERVICE_NAME;
137
+ } catch (importError) {
138
+ const err = importError;
139
+ if (err.code === "ERR_MODULE_NOT_FOUND") {
140
+ throw import_errors.TelemetryError.dependencyNotInstalled([
141
+ "@opentelemetry/sdk-node",
142
+ "@opentelemetry/auto-instrumentations-node",
143
+ "@opentelemetry/resources",
144
+ "@opentelemetry/semantic-conventions",
145
+ "@opentelemetry/sdk-trace-base",
146
+ "@opentelemetry/exporter-trace-otlp-http",
147
+ "@opentelemetry/exporter-trace-otlp-grpc"
148
+ ]);
149
+ }
150
+ throw importError;
151
+ }
152
+ const resource = new Resource({
153
+ [ATTR_SERVICE_NAME]: config.serviceName ?? "dexto-service"
92
154
  });
93
- const spanExporter = exporter || Telemetry.buildTraceExporter(config);
94
- const traceExporter = spanExporter instanceof import_exporters.CompositeExporter ? spanExporter : new import_exporters.CompositeExporter([spanExporter]);
95
- sdk = new import_sdk_node.NodeSDK({
155
+ const spanExporter = exporter || await Telemetry.buildTraceExporter(config);
156
+ const { CompositeExporter } = await import("./exporters.js");
157
+ const traceExporter = spanExporter instanceof CompositeExporter ? spanExporter : new CompositeExporter([spanExporter]);
158
+ sdk = new NodeSDK({
96
159
  resource,
97
160
  traceExporter,
98
- instrumentations: [(0, import_auto_instrumentations_node.getNodeAutoInstrumentations)()]
161
+ instrumentations: [getNodeAutoInstrumentations()]
99
162
  });
100
163
  await sdk.start();
101
164
  const sigterm = () => {
@@ -112,13 +175,16 @@ class Telemetry {
112
175
  }
113
176
  return globalThis.__TELEMETRY__;
114
177
  })();
115
- return Telemetry._initPromise;
178
+ return await Telemetry._initPromise;
116
179
  } catch (error) {
117
- const wrappedError = new Error(
118
- `Failed to initialize telemetry: ${error instanceof Error ? error.message : String(error)}`
119
- );
120
180
  Telemetry._initPromise = void 0;
121
- throw wrappedError;
181
+ if (error instanceof import_DextoRuntimeError.DextoRuntimeError) {
182
+ throw error;
183
+ }
184
+ throw import_errors.TelemetryError.initializationFailed(
185
+ error instanceof Error ? error.message : String(error),
186
+ error
187
+ );
122
188
  }
123
189
  }
124
190
  static getActiveSpan() {
@@ -127,12 +193,12 @@ class Telemetry {
127
193
  }
128
194
  /**
129
195
  * Get the global telemetry instance
130
- * @throws {Error} If telemetry has not been initialized
196
+ * @throws {DextoRuntimeError} If telemetry has not been initialized
131
197
  * @returns {Telemetry} The global telemetry instance
132
198
  */
133
199
  static get() {
134
200
  if (!globalThis.__TELEMETRY__) {
135
- throw new Error("Telemetry not initialized");
201
+ throw import_errors.TelemetryError.notInitialized();
136
202
  }
137
203
  return globalThis.__TELEMETRY__;
138
204
  }
@@ -31,7 +31,7 @@ export declare class Telemetry {
31
31
  static getActiveSpan(): import("@opentelemetry/api").Span | undefined;
32
32
  /**
33
33
  * Get the global telemetry instance
34
- * @throws {Error} If telemetry has not been initialized
34
+ * @throws {DextoRuntimeError} If telemetry has not been initialized
35
35
  * @returns {Telemetry} The global telemetry instance
36
36
  */
37
37
  static get(): Telemetry;
@@ -1 +1 @@
1
- {"version":3,"file":"telemetry.d.ts","sourceRoot":"","sources":["../../src/telemetry/telemetry.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACxE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAYtD,OAAO,CAAC,MAAM,CAAC;IACX,IAAI,aAAa,EAAE,SAAS,GAAG,SAAS,CAAC;CAC5C;AAED;;;;;;;;GAQG;AACH,qBAAa,SAAS;IACX,MAAM,EAAE,MAAM,CAA4B;IACjD,IAAI,EAAE,MAAM,CAAmB;IAC/B,OAAO,CAAC,cAAc,CAAkB;IACxC,OAAO,CAAC,IAAI,CAAC,CAAsB;IACnC,OAAO,CAAC,MAAM,CAAC,YAAY,CAAC,CAAiC;IAC7D,OAAO,CAAC,MAAM,CAAC,eAAe,CAAC,CAA0D;IAEzF,OAAO;IAYP,OAAO,CAAC,MAAM,CAAC,kBAAkB;IA0BjC;;;;;OAKG;WACU,I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OAAO;mBAYc,kBAAkB;IA0DvC;;;;;OAKG;WACU,IAAI,CACb,MAAM,GAAE,iBAAsB,EAC9B,QAAQ,CAAC,EAAE,OAAO,+BAA+B,EAAE,YAAY,GAChE,OAAO,CAAC,SAAS,CAAC;IAgHrB,MAAM,CAAC,aAAa;IAKpB;;;;OAIG;IACH,MAAM,CAAC,GAAG,IAAI,SAAS;IAOvB;;;OAGG;IACH,MAAM,CAAC,iBAAiB,IAAI,OAAO;IAInC;;;;;OAKG;WACU,cAAc,IAAI,OAAO,CAAC,IAAI,CAAC;IAS5C;;;OAGG;IACI,aAAa,IAAI,OAAO;IAI/B,MAAM,CAAC,UAAU,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,EAAE,GAAG,GAAE,OAA8B;IAc5F,MAAM,CAAC,WAAW,CAAC,GAAG,EAAE,OAAO,EAAE,EAAE,EAAE,MAAM,IAAI;IAI/C;;;OAGG;IACU,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAUxC;;;;;;;;;OASG;IACU,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;CA8BzC"}
@@ -1,14 +1,8 @@
1
1
  import "../chunk-C6A6W6XS.js";
2
2
  import { context as otlpContext, trace, propagation } from "@opentelemetry/api";
3
- import { NodeSDK } from "@opentelemetry/sdk-node";
4
- import { ConsoleSpanExporter } from "@opentelemetry/sdk-trace-base";
5
- import { OTLPTraceExporter as OTLPHttpExporter } from "@opentelemetry/exporter-trace-otlp-http";
6
- import { OTLPTraceExporter as OTLPGrpcExporter } from "@opentelemetry/exporter-trace-otlp-grpc";
7
- import { getNodeAutoInstrumentations } from "@opentelemetry/auto-instrumentations-node";
8
- import { Resource } from "@opentelemetry/resources";
9
- import { ATTR_SERVICE_NAME } from "@opentelemetry/semantic-conventions";
10
- import { CompositeExporter } from "./exporters.js";
11
3
  import { logger } from "../logger/logger.js";
4
+ import { TelemetryError } from "./errors.js";
5
+ import { DextoRuntimeError } from "../errors/DextoRuntimeError.js";
12
6
  class Telemetry {
13
7
  tracer = trace.getTracer("dexto");
14
8
  name = "dexto-service";
@@ -26,19 +20,48 @@ class Telemetry {
26
20
  }
27
21
  this._isInitialized = enabled && !!sdk;
28
22
  }
29
- static buildTraceExporter(config) {
23
+ static async buildTraceExporter(config) {
30
24
  const e = config?.export;
31
25
  if (!e || e.type === "console") {
32
- return new ConsoleSpanExporter();
26
+ const { ConsoleSpanExporter: ConsoleSpanExporter2 } = await import("@opentelemetry/sdk-trace-base");
27
+ return new ConsoleSpanExporter2();
33
28
  }
34
29
  if (e.type === "otlp") {
35
30
  if (e.protocol === "grpc") {
31
+ let OTLPGrpcExporter;
32
+ try {
33
+ const mod = await import("@opentelemetry/exporter-trace-otlp-grpc");
34
+ OTLPGrpcExporter = mod.OTLPTraceExporter;
35
+ } catch (err) {
36
+ const error = err;
37
+ if (error.code === "ERR_MODULE_NOT_FOUND") {
38
+ throw TelemetryError.exporterDependencyNotInstalled(
39
+ "grpc",
40
+ "@opentelemetry/exporter-trace-otlp-grpc"
41
+ );
42
+ }
43
+ throw err;
44
+ }
36
45
  const options2 = {};
37
46
  if (e.endpoint) {
38
47
  options2.url = e.endpoint;
39
48
  }
40
49
  return new OTLPGrpcExporter(options2);
41
50
  }
51
+ let OTLPHttpExporter;
52
+ try {
53
+ const mod = await import("@opentelemetry/exporter-trace-otlp-http");
54
+ OTLPHttpExporter = mod.OTLPTraceExporter;
55
+ } catch (err) {
56
+ const error = err;
57
+ if (error.code === "ERR_MODULE_NOT_FOUND") {
58
+ throw TelemetryError.exporterDependencyNotInstalled(
59
+ "http",
60
+ "@opentelemetry/exporter-trace-otlp-http"
61
+ );
62
+ }
63
+ throw err;
64
+ }
42
65
  const options = {};
43
66
  if (e.endpoint) {
44
67
  options.url = e.endpoint;
@@ -48,6 +71,7 @@ class Telemetry {
48
71
  }
49
72
  return new OTLPHttpExporter(options);
50
73
  }
74
+ const { ConsoleSpanExporter } = await import("@opentelemetry/sdk-trace-base");
51
75
  return new ConsoleSpanExporter();
52
76
  }
53
77
  /**
@@ -65,10 +89,39 @@ class Telemetry {
65
89
  const enabled = config.enabled !== false;
66
90
  let sdk;
67
91
  if (enabled) {
92
+ let NodeSDK;
93
+ let Resource;
94
+ let getNodeAutoInstrumentations;
95
+ let ATTR_SERVICE_NAME;
96
+ try {
97
+ const sdkModule = await import("@opentelemetry/sdk-node");
98
+ NodeSDK = sdkModule.NodeSDK;
99
+ const resourcesModule = await import("@opentelemetry/resources");
100
+ Resource = resourcesModule.Resource;
101
+ const autoInstModule = await import("@opentelemetry/auto-instrumentations-node");
102
+ getNodeAutoInstrumentations = autoInstModule.getNodeAutoInstrumentations;
103
+ const semanticModule = await import("@opentelemetry/semantic-conventions");
104
+ ATTR_SERVICE_NAME = semanticModule.ATTR_SERVICE_NAME;
105
+ } catch (importError) {
106
+ const err = importError;
107
+ if (err.code === "ERR_MODULE_NOT_FOUND") {
108
+ throw TelemetryError.dependencyNotInstalled([
109
+ "@opentelemetry/sdk-node",
110
+ "@opentelemetry/auto-instrumentations-node",
111
+ "@opentelemetry/resources",
112
+ "@opentelemetry/semantic-conventions",
113
+ "@opentelemetry/sdk-trace-base",
114
+ "@opentelemetry/exporter-trace-otlp-http",
115
+ "@opentelemetry/exporter-trace-otlp-grpc"
116
+ ]);
117
+ }
118
+ throw importError;
119
+ }
68
120
  const resource = new Resource({
69
121
  [ATTR_SERVICE_NAME]: config.serviceName ?? "dexto-service"
70
122
  });
71
- const spanExporter = exporter || Telemetry.buildTraceExporter(config);
123
+ const spanExporter = exporter || await Telemetry.buildTraceExporter(config);
124
+ const { CompositeExporter } = await import("./exporters.js");
72
125
  const traceExporter = spanExporter instanceof CompositeExporter ? spanExporter : new CompositeExporter([spanExporter]);
73
126
  sdk = new NodeSDK({
74
127
  resource,
@@ -90,13 +143,16 @@ class Telemetry {
90
143
  }
91
144
  return globalThis.__TELEMETRY__;
92
145
  })();
93
- return Telemetry._initPromise;
146
+ return await Telemetry._initPromise;
94
147
  } catch (error) {
95
- const wrappedError = new Error(
96
- `Failed to initialize telemetry: ${error instanceof Error ? error.message : String(error)}`
97
- );
98
148
  Telemetry._initPromise = void 0;
99
- throw wrappedError;
149
+ if (error instanceof DextoRuntimeError) {
150
+ throw error;
151
+ }
152
+ throw TelemetryError.initializationFailed(
153
+ error instanceof Error ? error.message : String(error),
154
+ error
155
+ );
100
156
  }
101
157
  }
102
158
  static getActiveSpan() {
@@ -105,12 +161,12 @@ class Telemetry {
105
161
  }
106
162
  /**
107
163
  * Get the global telemetry instance
108
- * @throws {Error} If telemetry has not been initialized
164
+ * @throws {DextoRuntimeError} If telemetry has not been initialized
109
165
  * @returns {Telemetry} The global telemetry instance
110
166
  */
111
167
  static get() {
112
168
  if (!globalThis.__TELEMETRY__) {
113
- throw new Error("Telemetry not initialized");
169
+ throw TelemetryError.notInitialized();
114
170
  }
115
171
  return globalThis.__TELEMETRY__;
116
172
  }
@@ -60,7 +60,7 @@ const ToolConfirmationConfigSchema = import_zod.z.object({
60
60
  )
61
61
  }).strict().describe("Tool confirmation and approval configuration");
62
62
  const ElicitationConfigSchema = import_zod.z.object({
63
- enabled: import_zod.z.boolean().default(true).describe(
63
+ enabled: import_zod.z.boolean().default(false).describe(
64
64
  "Enable elicitation support (ask_user tool and MCP server elicitations). When disabled, elicitation requests will be rejected."
65
65
  ),
66
66
  timeout: import_zod.z.number().int().positive().default(12e4).describe(
@@ -31,7 +31,7 @@ const ToolConfirmationConfigSchema = z.object({
31
31
  )
32
32
  }).strict().describe("Tool confirmation and approval configuration");
33
33
  const ElicitationConfigSchema = z.object({
34
- enabled: z.boolean().default(true).describe(
34
+ enabled: z.boolean().default(false).describe(
35
35
  "Enable elicitation support (ask_user tool and MCP server elicitations). When disabled, elicitation requests will be rejected."
36
36
  ),
37
37
  timeout: z.number().int().positive().default(12e4).describe(
@@ -39,17 +39,6 @@ export interface ToolResult {
39
39
  data?: any;
40
40
  error?: string;
41
41
  }
42
- /**
43
- * Tool call representation
44
- */
45
- export interface ToolCall {
46
- id: string;
47
- toolName: string;
48
- input: any;
49
- output?: any;
50
- error?: string;
51
- duration?: number;
52
- }
53
42
  /**
54
43
  * Interface for any provider of tools
55
44
  */
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/tools/types.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,KAAK,CAAC;AAErC;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACjC,8BAA8B;IAC9B,SAAS,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAClC;AAMD;;GAEG;AACH,MAAM,WAAW,YAAY;IACzB,qCAAqC;IACrC,EAAE,EAAE,MAAM,CAAC;IAEX,uDAAuD;IACvD,WAAW,EAAE,MAAM,CAAC;IAEpB,+CAA+C;IAC/C,WAAW,EAAE,SAAS,CAAC;IAEvB,8FAA8F;IAC9F,OAAO,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,oBAAoB,KAAK,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC;CAC3F;AAED;;;GAGG;AACH,MAAM,WAAW,OAAO;IACpB,CAAC,GAAG,EAAE,MAAM,GAAG;QACX,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,UAAU,EAAE,WAAW,CAAC;KAC3B,CAAC;CACL;AAMD;;GAEG;AACH,MAAM,WAAW,UAAU;IACvB,OAAO,EAAE,OAAO,CAAC;IACjB,IAAI,CAAC,EAAE,GAAG,CAAC;IACX,KAAK,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,QAAQ;IACrB,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,GAAG,CAAC;IACX,MAAM,CAAC,EAAE,G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,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IACzB,QAAQ,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;IAC7B,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CAC/E"}
@@ -1,6 +1,12 @@
1
1
  import type { IDextoLogger } from '../logger/v2/types.js';
2
2
  /**
3
3
  * Convert Zod schema to JSON Schema format for tool parameters
4
+ *
5
+ * TODO: Replace zod-to-json-schema with Zod v4 native JSON schema support
6
+ * The zod-to-json-schema package is deprecated and adds ~19MB due to a packaging bug
7
+ * (includes test files with full Zod copies in dist-test-v3 and dist-test-v4 folders).
8
+ * Zod v4 has native toJsonSchema() support - migrate when upgrading to Zod v4.
9
+ * See: https://github.com/StefanTerdell/zod-to-json-schema
4
10
  */
5
11
  export declare function convertZodSchemaToJsonSchema(zodSchema: any, logger: IDextoLogger): any;
6
12
  //# sourceMappingURL=schema.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/utils/schema.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAE1D;;GAEG;AACH,wBAAgB,4BAA4B,CAAC,SAAS,EAAE,GAAG,EAAE,MAAM,EAAE,YAAY,GAAG,GAAG,CActF"}
1
+ {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/utils/schema.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAE1D;;;;;;;;GAQG;AACH,wBAAgB,4BAA4B,CAAC,SAAS,EAAE,GAAG,EAAE,MAAM,EAAE,YAAY,GAAG,GAAG,CActF"}