@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.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,KAAK,EAAE,UAAU,EAAE,cAAc,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAG/F,OAAO,KAAK,EACV,oBAAoB,IAAI,UAAU,EAClC,qBAAqB,EACrB,iBAAiB,EAIlB,MAAM,SAAS,CAAC;AAMjB,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAC7C,YAAY,EAAE,oBAAoB,EAAE,sBAAsB,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAoBxH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,qBAAa,cAAe,SAAQ,WAAW,CAC7C,UAAU,EACV,qBAAqB,EACrB,qBAAqB,EACrB,UAAU,EACV,iBAAiB,CAClB;IACC,OAAO,CAAC,MAAM,CAAC,CAAuB;IACtC,OAAO,CAAC,MAAM,CAAC,CAAqB;IACpC,OAAO,CAAC,WAAW,CAAC,CAAc;IAClC,OAAO,CAAC,WAAW,CAAC,CAAwB;IAC5C,OAAO,CAAC,YAAY,CAAC,CAAa;IAClC,OAAO,CAAC,YAAY,CAAC,CAAa;IAClC,OAAO,CAAC,WAAW,CAAC,CAAS;IAC7B,OAAO,CAAC,KAAK,CAA+D;IAC5E,OAAO,CAAC,MAAM,CAAW;IACzB,OAAO,CAAC,YAAY,CAAC,CAAS;IAC9B,OAAO,CAAC,KAAK,CAAC,CAAa;IAC3B,OAAO,CAAC,cAAc,CAAC,CAAi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AAC,SAAS,EAAE,MAAM,CAAC,cAAc,GAAG,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,CAuIvE;IAED;;;OAGG;IACG,aAAa,IAAI,OAAO,CAAC,IAAI,CAAC,CAqCnC;IAED;;OAEG;IACH,EAAE,CAAC,CAAC,SAAS,cAAc,EACzB,KAAK,EAAE,CAAC,EACR,QAAQ,EAAE,CAAC,IAAI,EAAE,CAAC,SAAS,MAAM,iBAAiB,GAAG,iBAAiB,CAAC,CAAC,CAAC,GAAG,OAAO,KAAK,IAAI,GAC3F,IAAI,CAKN;IAED;;OAEG;IACH,GAAG,CAAC,CAAC,SAAS,cAAc,EAC1B,KAAK,EAAE,CAAC,EACR,QAAQ,EAAE,CAAC,IAAI,EAAE,CAAC,SAAS,MAAM,iBAAiB,GAAG,iBAAiB,CAAC,CAAC,CAAC,GAAG,OAAO,KAAK,IAAI,GAC3F,IAAI,CAQN;IAED;;OAEG;IACH,OAAO,CAAC,IAAI;IAkBZ;;OAEG;IACG,WAAW,IAAI,OAAO,CAAC;QAAE,OAAO,EAAE,OAAO,CAAA;KAAE,CAAC,CAEjD;IAED;;OAEG;IACH,OAAO,CAAC,GAAG;CAKZ"}
package/dist/index.js CHANGED
@@ -4,6 +4,46 @@ import { BedrockRuntimeClient, InvokeModelWithBidirectionalStreamCommand } from
4
4
  import { NodeHttp2Handler } from "@smithy/node-http-handler";
5
5
  import { defaultProvider } from "@aws-sdk/credential-provider-node";
6
6
  //#region ../../packages/_internal-core/dist/logger/index.js
7
+ /**
8
+ * Export a tracked exception through the adapter sink, mirroring the
9
+ * DualLogger dual-write shape (`errorId`/`domain`/`category`/`details`/`cause`
10
+ * when present on a MastraError-like value). Never throws into the caller.
11
+ */
12
+ function exportTrackedException(ctx, error, metadata) {
13
+ if (!ctx?.options.export) return;
14
+ try {
15
+ const mastraError = error;
16
+ ctx.getLogSink()?.error(error.message, {
17
+ ...mastraError.id !== void 0 ? { errorId: mastraError.id } : {},
18
+ ...mastraError.domain !== void 0 ? { domain: mastraError.domain } : {},
19
+ ...mastraError.category !== void 0 ? { category: mastraError.category } : {},
20
+ ...mastraError.details !== void 0 ? { details: mastraError.details } : {},
21
+ ...error.cause instanceof Error ? { cause: error.cause.message } : {},
22
+ ...metadata
23
+ });
24
+ } catch {}
25
+ }
26
+ /**
27
+ * Adapt IMastraLogger's variadic args into the structured `data` payload of
28
+ * an exported log record. Extracts the first plain object as data,
29
+ * serializes an Error arg, and collects remaining primitives under `args`
30
+ * so the derived record preserves all context from the native call.
31
+ */
32
+ function buildLogRecordData(args) {
33
+ const objectData = args.find((arg) => arg !== null && typeof arg === "object" && !Array.isArray(arg) && !(arg instanceof Error));
34
+ const errorArg = args.find((arg) => arg instanceof Error);
35
+ const extraArgs = args.filter((arg) => arg !== objectData && arg !== errorArg);
36
+ if (!objectData && !errorArg && extraArgs.length === 0) return void 0;
37
+ return {
38
+ ...objectData ?? {},
39
+ ...errorArg ? { error: {
40
+ name: errorArg.name,
41
+ message: errorArg.message,
42
+ stack: errorArg.stack
43
+ } } : {},
44
+ ...extraArgs.length > 0 ? { args: extraArgs } : {}
45
+ };
46
+ }
7
47
  const RegisteredLogger = {
8
48
  AGENT: "AGENT",
9
49
  OBSERVABILITY: "OBSERVABILITY",
@@ -90,19 +130,56 @@ var MastraLogger = class {
90
130
  var ConsoleLogger = class ConsoleLogger extends MastraLogger {
91
131
  component;
92
132
  filter;
133
+ #adapterContext;
93
134
  constructor(options = {}) {
94
135
  super(options);
95
136
  this.component = options.component;
96
137
  this.filter = options.filter;
97
138
  }
139
+ /**
140
+ * Adapter hook (see `AdaptableLogger`): enables native trace correlation
141
+ * (trace_id/span_id appended to console output) and observability export
142
+ * derived from the same record. Called by Mastra during setup.
143
+ */
144
+ __attachObservability(ctx) {
145
+ this.#adapterContext = ctx;
146
+ }
98
147
  child(componentOrBindings) {
99
148
  const component = typeof componentOrBindings === "string" ? componentOrBindings : componentOrBindings?.component ?? this.component;
100
- return new ConsoleLogger({
149
+ const child = new ConsoleLogger({
101
150
  name: this.name,
102
151
  level: this.level,
103
152
  component,
104
153
  filter: this.filter
105
154
  });
155
+ if (this.#adapterContext) child.__attachObservability(this.#adapterContext);
156
+ return child;
157
+ }
158
+ /**
159
+ * Native-record correlation: when a span is active, append the trace
160
+ * fields object to the console args so every destination sees them.
161
+ */
162
+ #correlate(args) {
163
+ const ctx = this.#adapterContext;
164
+ if (!ctx?.options.correlation) return args;
165
+ try {
166
+ const fields = ctx.resolveTraceFields();
167
+ return fields ? [...args, fields] : args;
168
+ } catch {
169
+ return args;
170
+ }
171
+ }
172
+ /**
173
+ * Export the record derived from the same native call to observability.
174
+ * Mirrors DualLogger semantics: export is independent of the console
175
+ * level filter, and never throws into the caller.
176
+ */
177
+ #export(level, message, args) {
178
+ const ctx = this.#adapterContext;
179
+ if (!ctx?.options.export) return;
180
+ try {
181
+ ctx.getLogSink()?.[level](message, buildLogRecordData(args));
182
+ } catch {}
106
183
  }
107
184
  shouldLog(level, message, args) {
108
185
  if (!this.filter) return true;
@@ -122,16 +199,23 @@ var ConsoleLogger = class ConsoleLogger extends MastraLogger {
122
199
  return this.component ? `[${this.component}] ` : "";
123
200
  }
124
201
  debug(message, ...args) {
125
- if (this.level === LogLevel.DEBUG && this.shouldLog(LogLevel.DEBUG, message, args)) console.info(`${this.prefix()}${message}`, ...args);
202
+ if (this.level === LogLevel.DEBUG && this.shouldLog(LogLevel.DEBUG, message, args)) console.info(`${this.prefix()}${message}`, ...this.#correlate(args));
203
+ this.#export("debug", message, args);
126
204
  }
127
205
  info(message, ...args) {
128
- if ((this.level === LogLevel.INFO || this.level === LogLevel.DEBUG) && this.shouldLog(LogLevel.INFO, message, args)) console.info(`${this.prefix()}${message}`, ...args);
206
+ if ((this.level === LogLevel.INFO || this.level === LogLevel.DEBUG) && this.shouldLog(LogLevel.INFO, message, args)) console.info(`${this.prefix()}${message}`, ...this.#correlate(args));
207
+ this.#export("info", message, args);
129
208
  }
130
209
  warn(message, ...args) {
131
- 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);
210
+ 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));
211
+ this.#export("warn", message, args);
132
212
  }
133
213
  error(message, ...args) {
134
- 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);
214
+ 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));
215
+ this.#export("error", message, args);
216
+ }
217
+ trackException(error, metadata) {
218
+ exportTrackedException(this.#adapterContext, error, metadata);
135
219
  }
136
220
  async listLogs(_transportId, _params) {
137
221
  return {