@mastra/observability 1.17.2-alpha.0 → 1.17.2-alpha.1

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.js CHANGED
@@ -221,10 +221,18 @@ function mergeSerializationOptions(userOptions) {
221
221
  }
222
222
  /**
223
223
  * Hard-cap any string to prevent unbounded growth.
224
+ *
225
+ * The cut never splits a UTF-16 surrogate pair: if it would land immediately
226
+ * after a lone high surrogate (U+D800..U+DBFF), it backs off one code unit so
227
+ * the pair is dropped as a whole. `JSON.stringify` emits a lone `\ud83d` for a
228
+ * split pair, which PostgreSQL rejects on a jsonb cast with 22P02
229
+ * ("Unicode low surrogate must follow a high surrogate").
224
230
  */
225
231
  function truncateString(s, maxChars) {
226
232
  if (s.length <= maxChars) return s;
227
- return s.slice(0, maxChars) + "…[truncated]";
233
+ const code = s.charCodeAt(maxChars - 1);
234
+ const safeEnd = code >= 55296 && code <= 56319 ? maxChars - 1 : maxChars;
235
+ return s.slice(0, safeEnd) + "…[truncated]";
228
236
  }
229
237
  function formatSerializationError(error) {
230
238
  return `[${error instanceof Error ? truncateString(error.message, 256) : "unknown error"}]`;