@mastra/voice-aws-nova-sonic 0.2.1 → 0.2.2-alpha.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.cjs CHANGED
@@ -5,6 +5,46 @@ let _aws_sdk_client_bedrock_runtime = require("@aws-sdk/client-bedrock-runtime")
5
5
  let _smithy_node_http_handler = require("@smithy/node-http-handler");
6
6
  let _aws_sdk_credential_provider_node = require("@aws-sdk/credential-provider-node");
7
7
  //#region ../../packages/_internal-core/dist/logger/index.js
8
+ /**
9
+ * Export a tracked exception through the adapter sink, mirroring the
10
+ * DualLogger dual-write shape (`errorId`/`domain`/`category`/`details`/`cause`
11
+ * when present on a MastraError-like value). Never throws into the caller.
12
+ */
13
+ function exportTrackedException(ctx, error, metadata) {
14
+ if (!ctx?.options.export) return;
15
+ try {
16
+ const mastraError = error;
17
+ ctx.getLogSink()?.error(error.message, {
18
+ ...mastraError.id !== void 0 ? { errorId: mastraError.id } : {},
19
+ ...mastraError.domain !== void 0 ? { domain: mastraError.domain } : {},
20
+ ...mastraError.category !== void 0 ? { category: mastraError.category } : {},
21
+ ...mastraError.details !== void 0 ? { details: mastraError.details } : {},
22
+ ...error.cause instanceof Error ? { cause: error.cause.message } : {},
23
+ ...metadata
24
+ });
25
+ } catch {}
26
+ }
27
+ /**
28
+ * Adapt IMastraLogger's variadic args into the structured `data` payload of
29
+ * an exported log record. Extracts the first plain object as data,
30
+ * serializes an Error arg, and collects remaining primitives under `args`
31
+ * so the derived record preserves all context from the native call.
32
+ */
33
+ function buildLogRecordData(args) {
34
+ const objectData = args.find((arg) => arg !== null && typeof arg === "object" && !Array.isArray(arg) && !(arg instanceof Error));
35
+ const errorArg = args.find((arg) => arg instanceof Error);
36
+ const extraArgs = args.filter((arg) => arg !== objectData && arg !== errorArg);
37
+ if (!objectData && !errorArg && extraArgs.length === 0) return void 0;
38
+ return {
39
+ ...objectData ?? {},
40
+ ...errorArg ? { error: {
41
+ name: errorArg.name,
42
+ message: errorArg.message,
43
+ stack: errorArg.stack
44
+ } } : {},
45
+ ...extraArgs.length > 0 ? { args: extraArgs } : {}
46
+ };
47
+ }
8
48
  const RegisteredLogger = {
9
49
  AGENT: "AGENT",
10
50
  OBSERVABILITY: "OBSERVABILITY",
@@ -91,19 +131,56 @@ var MastraLogger = class {
91
131
  var ConsoleLogger = class ConsoleLogger extends MastraLogger {
92
132
  component;
93
133
  filter;
134
+ #adapterContext;
94
135
  constructor(options = {}) {
95
136
  super(options);
96
137
  this.component = options.component;
97
138
  this.filter = options.filter;
98
139
  }
140
+ /**
141
+ * Adapter hook (see `AdaptableLogger`): enables native trace correlation
142
+ * (trace_id/span_id appended to console output) and observability export
143
+ * derived from the same record. Called by Mastra during setup.
144
+ */
145
+ __attachObservability(ctx) {
146
+ this.#adapterContext = ctx;
147
+ }
99
148
  child(componentOrBindings) {
100
149
  const component = typeof componentOrBindings === "string" ? componentOrBindings : componentOrBindings?.component ?? this.component;
101
- return new ConsoleLogger({
150
+ const child = new ConsoleLogger({
102
151
  name: this.name,
103
152
  level: this.level,
104
153
  component,
105
154
  filter: this.filter
106
155
  });
156
+ if (this.#adapterContext) child.__attachObservability(this.#adapterContext);
157
+ return child;
158
+ }
159
+ /**
160
+ * Native-record correlation: when a span is active, append the trace
161
+ * fields object to the console args so every destination sees them.
162
+ */
163
+ #correlate(args) {
164
+ const ctx = this.#adapterContext;
165
+ if (!ctx?.options.correlation) return args;
166
+ try {
167
+ const fields = ctx.resolveTraceFields();
168
+ return fields ? [...args, fields] : args;
169
+ } catch {
170
+ return args;
171
+ }
172
+ }
173
+ /**
174
+ * Export the record derived from the same native call to observability.
175
+ * Mirrors DualLogger semantics: export is independent of the console
176
+ * level filter, and never throws into the caller.
177
+ */
178
+ #export(level, message, args) {
179
+ const ctx = this.#adapterContext;
180
+ if (!ctx?.options.export) return;
181
+ try {
182
+ ctx.getLogSink()?.[level](message, buildLogRecordData(args));
183
+ } catch {}
107
184
  }
108
185
  shouldLog(level, message, args) {
109
186
  if (!this.filter) return true;
@@ -123,16 +200,23 @@ var ConsoleLogger = class ConsoleLogger extends MastraLogger {
123
200
  return this.component ? `[${this.component}] ` : "";
124
201
  }
125
202
  debug(message, ...args) {
126
- if (this.level === LogLevel.DEBUG && this.shouldLog(LogLevel.DEBUG, message, args)) console.info(`${this.prefix()}${message}`, ...args);
203
+ if (this.level === LogLevel.DEBUG && this.shouldLog(LogLevel.DEBUG, message, args)) console.info(`${this.prefix()}${message}`, ...this.#correlate(args));
204
+ this.#export("debug", message, args);
127
205
  }
128
206
  info(message, ...args) {
129
- if ((this.level === LogLevel.INFO || this.level === LogLevel.DEBUG) && this.shouldLog(LogLevel.INFO, message, args)) console.info(`${this.prefix()}${message}`, ...args);
207
+ if ((this.level === LogLevel.INFO || this.level === LogLevel.DEBUG) && this.shouldLog(LogLevel.INFO, message, args)) console.info(`${this.prefix()}${message}`, ...this.#correlate(args));
208
+ this.#export("info", message, args);
130
209
  }
131
210
  warn(message, ...args) {
132
- if ((this.level === LogLevel.WARN || this.level === LogLevel.INFO || this.level === LogLevel.DEBUG) && this.shouldLog(LogLevel.WARN, message, args)) console.warn(`${this.prefix()}${message}`, ...args);
211
+ if ((this.level === LogLevel.WARN || this.level === LogLevel.INFO || this.level === LogLevel.DEBUG) && this.shouldLog(LogLevel.WARN, message, args)) console.warn(`${this.prefix()}${message}`, ...this.#correlate(args));
212
+ this.#export("warn", message, args);
133
213
  }
134
214
  error(message, ...args) {
135
- if ((this.level === LogLevel.ERROR || this.level === LogLevel.WARN || this.level === LogLevel.INFO || this.level === LogLevel.DEBUG) && this.shouldLog(LogLevel.ERROR, message, args)) console.error(`${this.prefix()}${message}`, ...args);
215
+ if ((this.level === LogLevel.ERROR || this.level === LogLevel.WARN || this.level === LogLevel.INFO || this.level === LogLevel.DEBUG) && this.shouldLog(LogLevel.ERROR, message, args)) console.error(`${this.prefix()}${message}`, ...this.#correlate(args));
216
+ this.#export("error", message, args);
217
+ }
218
+ trackException(error, metadata) {
219
+ exportTrackedException(this.#adapterContext, error, metadata);
136
220
  }
137
221
  async listLogs(_transportId, _params) {
138
222
  return {