@morsehq-dev/sdk 0.4.1-rc.1 → 0.5.0-rc.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.
Files changed (149) hide show
  1. package/dist/anthropic/index.cjs +12 -10
  2. package/dist/anthropic/index.js +5 -3
  3. package/dist/anthropic-agent-sdk/index.cjs +52 -34
  4. package/dist/anthropic-agent-sdk/index.cjs.map +1 -1
  5. package/dist/anthropic-agent-sdk/index.js +25 -7
  6. package/dist/anthropic-agent-sdk/index.js.map +1 -1
  7. package/dist/browser/anthropic/index.cjs +12 -10
  8. package/dist/browser/anthropic/index.js +5 -3
  9. package/dist/browser/anthropic-agent-sdk/index.cjs +52 -34
  10. package/dist/browser/anthropic-agent-sdk/index.cjs.map +1 -1
  11. package/dist/browser/anthropic-agent-sdk/index.js +25 -7
  12. package/dist/browser/anthropic-agent-sdk/index.js.map +1 -1
  13. package/dist/browser/chunk-32U547L3.js +118 -0
  14. package/dist/browser/chunk-32U547L3.js.map +1 -0
  15. package/dist/{chunk-SBGY5NS4.js → browser/chunk-454FDWBM.js} +6 -4
  16. package/dist/browser/chunk-454FDWBM.js.map +1 -0
  17. package/dist/browser/{chunk-EFUQVASI.cjs → chunk-5EFKNOO7.cjs} +17 -15
  18. package/dist/browser/chunk-5EFKNOO7.cjs.map +1 -0
  19. package/dist/browser/{chunk-DOLWR7LD.js → chunk-5IWGFPKQ.js} +4 -4
  20. package/dist/browser/{chunk-DOLWR7LD.js.map → chunk-5IWGFPKQ.js.map} +1 -1
  21. package/dist/browser/{chunk-F3B4UR64.js → chunk-6DOP3MTY.js} +386 -53
  22. package/dist/browser/chunk-6DOP3MTY.js.map +1 -0
  23. package/dist/browser/{chunk-GWJYOQNC.js → chunk-A7P3ZBZX.js} +10 -4
  24. package/dist/browser/chunk-A7P3ZBZX.js.map +1 -0
  25. package/dist/browser/{chunk-M2GZJ3RS.cjs → chunk-AV35EOER.cjs} +20 -14
  26. package/dist/browser/chunk-AV35EOER.cjs.map +1 -0
  27. package/dist/browser/{chunk-AYNX24P5.js → chunk-AZ3SVK3K.js} +3 -3
  28. package/dist/browser/{chunk-AYNX24P5.js.map → chunk-AZ3SVK3K.js.map} +1 -1
  29. package/dist/browser/chunk-FNZWJU64.cjs +31 -0
  30. package/dist/browser/chunk-FNZWJU64.cjs.map +1 -0
  31. package/dist/browser/chunk-HZZK2EMO.cjs +126 -0
  32. package/dist/browser/chunk-HZZK2EMO.cjs.map +1 -0
  33. package/dist/browser/{chunk-QWRQJO57.js → chunk-MLDVXMQD.js} +3 -3
  34. package/dist/browser/{chunk-QWRQJO57.js.map → chunk-MLDVXMQD.js.map} +1 -1
  35. package/dist/{chunk-Y7SVGUKY.cjs → browser/chunk-NT37C2TK.cjs} +7 -7
  36. package/dist/browser/{chunk-YNUZGKUA.cjs.map → chunk-NT37C2TK.cjs.map} +1 -1
  37. package/dist/browser/{chunk-3643DC7K.cjs → chunk-RBNCTHK3.cjs} +5 -2
  38. package/dist/browser/{chunk-3643DC7K.cjs.map → chunk-RBNCTHK3.cjs.map} +1 -1
  39. package/dist/browser/chunk-VFNNU3AX.js +28 -0
  40. package/dist/browser/chunk-VFNNU3AX.js.map +1 -0
  41. package/dist/browser/{chunk-HGN7J3EU.cjs → chunk-WY2VLKRR.cjs} +12 -12
  42. package/dist/browser/{chunk-HGN7J3EU.cjs.map → chunk-WY2VLKRR.cjs.map} +1 -1
  43. package/dist/browser/{chunk-DXWHT3HK.cjs → chunk-ZGYZZCUK.cjs} +391 -55
  44. package/dist/browser/chunk-ZGYZZCUK.cjs.map +1 -0
  45. package/dist/browser/index.cjs +112 -82
  46. package/dist/browser/index.cjs.map +1 -1
  47. package/dist/browser/index.js +40 -10
  48. package/dist/browser/index.js.map +1 -1
  49. package/dist/browser/integrations/pino.cjs +4 -4
  50. package/dist/browser/integrations/pino.js +3 -3
  51. package/dist/browser/langchain/index.cjs +19 -19
  52. package/dist/browser/langchain/index.js +3 -3
  53. package/dist/browser/langgraph/index.cjs +34 -26
  54. package/dist/browser/langgraph/index.cjs.map +1 -1
  55. package/dist/browser/langgraph/index.js +16 -8
  56. package/dist/browser/langgraph/index.js.map +1 -1
  57. package/dist/browser/openai/index.cjs +22 -8
  58. package/dist/browser/openai/index.cjs.map +1 -1
  59. package/dist/browser/openai/index.js +17 -3
  60. package/dist/browser/openai/index.js.map +1 -1
  61. package/dist/browser/openai-agents/index.cjs +42 -34
  62. package/dist/browser/openai-agents/index.cjs.map +1 -1
  63. package/dist/browser/openai-agents/index.js +13 -5
  64. package/dist/browser/openai-agents/index.js.map +1 -1
  65. package/dist/browser/vercel-ai/index.cjs +16 -16
  66. package/dist/browser/vercel-ai/index.js +4 -4
  67. package/dist/{chunk-4R4SHGOK.js → chunk-4JPZV2VZ.js} +3 -3
  68. package/dist/{chunk-4R4SHGOK.js.map → chunk-4JPZV2VZ.js.map} +1 -1
  69. package/dist/{chunk-HNCWTENX.cjs → chunk-5B3IUESN.cjs} +415 -70
  70. package/dist/chunk-5B3IUESN.cjs.map +1 -0
  71. package/dist/chunk-5RXSICEJ.js +118 -0
  72. package/dist/chunk-5RXSICEJ.js.map +1 -0
  73. package/dist/chunk-7A2EWXZK.cjs +31 -0
  74. package/dist/chunk-7A2EWXZK.cjs.map +1 -0
  75. package/dist/{chunk-STK4KJQ6.js → chunk-AAR4FYFO.js} +10 -4
  76. package/dist/chunk-AAR4FYFO.js.map +1 -0
  77. package/dist/{chunk-LQI63FHF.cjs → chunk-ADRVMGAW.cjs} +20 -14
  78. package/dist/chunk-ADRVMGAW.cjs.map +1 -0
  79. package/dist/{chunk-V5J6J4ZR.js → chunk-CECVNM7R.js} +4 -4
  80. package/dist/{chunk-V5J6J4ZR.js.map → chunk-CECVNM7R.js.map} +1 -1
  81. package/dist/{chunk-KJEO52QS.cjs → chunk-HICEJ4LV.cjs} +5 -2
  82. package/dist/{chunk-KJEO52QS.cjs.map → chunk-HICEJ4LV.cjs.map} +1 -1
  83. package/dist/{chunk-QXRJUPDP.cjs → chunk-HSY7V4RG.cjs} +12 -12
  84. package/dist/{chunk-QXRJUPDP.cjs.map → chunk-HSY7V4RG.cjs.map} +1 -1
  85. package/dist/chunk-LB6ZLJUR.js +28 -0
  86. package/dist/chunk-LB6ZLJUR.js.map +1 -0
  87. package/dist/{browser/chunk-F7BGQ26H.js → chunk-O3Q5L2HY.js} +6 -4
  88. package/dist/chunk-O3Q5L2HY.js.map +1 -0
  89. package/dist/{chunk-5D6SBSEI.cjs → chunk-RF7NI5VN.cjs} +17 -15
  90. package/dist/chunk-RF7NI5VN.cjs.map +1 -0
  91. package/dist/{chunk-AEFUXEKV.js → chunk-TP3N3S2D.js} +3 -3
  92. package/dist/{chunk-AEFUXEKV.js.map → chunk-TP3N3S2D.js.map} +1 -1
  93. package/dist/{chunk-LTKGLXAE.js → chunk-UEKQIRRA.js} +410 -68
  94. package/dist/chunk-UEKQIRRA.js.map +1 -0
  95. package/dist/{browser/chunk-YNUZGKUA.cjs → chunk-UWQPOWJQ.cjs} +7 -7
  96. package/dist/{chunk-Y7SVGUKY.cjs.map → chunk-UWQPOWJQ.cjs.map} +1 -1
  97. package/dist/chunk-VD3KRXSP.cjs +126 -0
  98. package/dist/chunk-VD3KRXSP.cjs.map +1 -0
  99. package/dist/index.cjs +119 -89
  100. package/dist/index.cjs.map +1 -1
  101. package/dist/index.d.cts +2 -2
  102. package/dist/index.d.ts +2 -2
  103. package/dist/index.js +41 -11
  104. package/dist/index.js.map +1 -1
  105. package/dist/integrations/pino.cjs +4 -4
  106. package/dist/integrations/pino.js +3 -3
  107. package/dist/langchain/index.cjs +19 -19
  108. package/dist/langchain/index.d.cts +1 -1
  109. package/dist/langchain/index.d.ts +1 -1
  110. package/dist/langchain/index.js +3 -3
  111. package/dist/langgraph/index.cjs +34 -26
  112. package/dist/langgraph/index.cjs.map +1 -1
  113. package/dist/langgraph/index.d.cts +1 -1
  114. package/dist/langgraph/index.d.ts +1 -1
  115. package/dist/langgraph/index.js +16 -8
  116. package/dist/langgraph/index.js.map +1 -1
  117. package/dist/openai/index.cjs +22 -8
  118. package/dist/openai/index.cjs.map +1 -1
  119. package/dist/openai/index.js +17 -3
  120. package/dist/openai/index.js.map +1 -1
  121. package/dist/openai-agents/index.cjs +42 -34
  122. package/dist/openai-agents/index.cjs.map +1 -1
  123. package/dist/openai-agents/index.js +13 -5
  124. package/dist/openai-agents/index.js.map +1 -1
  125. package/dist/{tracing-BYAqjT5Q.d.cts → tracing-CNlre8TK.d.cts} +1 -0
  126. package/dist/{tracing-rz9cWQ8d.d.ts → tracing-J8ZgxVzU.d.ts} +1 -0
  127. package/dist/vercel-ai/index.cjs +16 -16
  128. package/dist/vercel-ai/index.js +4 -4
  129. package/package.json +1 -9
  130. package/dist/browser/chunk-3BGG7GH3.cjs +0 -183
  131. package/dist/browser/chunk-3BGG7GH3.cjs.map +0 -1
  132. package/dist/browser/chunk-DXWHT3HK.cjs.map +0 -1
  133. package/dist/browser/chunk-EFUQVASI.cjs.map +0 -1
  134. package/dist/browser/chunk-F3B4UR64.js.map +0 -1
  135. package/dist/browser/chunk-F7BGQ26H.js.map +0 -1
  136. package/dist/browser/chunk-GWJYOQNC.js.map +0 -1
  137. package/dist/browser/chunk-M2GZJ3RS.cjs.map +0 -1
  138. package/dist/browser/chunk-YHV5GL32.js +0 -178
  139. package/dist/browser/chunk-YHV5GL32.js.map +0 -1
  140. package/dist/chunk-5D6SBSEI.cjs.map +0 -1
  141. package/dist/chunk-HNCWTENX.cjs.map +0 -1
  142. package/dist/chunk-LQI63FHF.cjs.map +0 -1
  143. package/dist/chunk-LTKGLXAE.js.map +0 -1
  144. package/dist/chunk-POCQNSVD.js +0 -178
  145. package/dist/chunk-POCQNSVD.js.map +0 -1
  146. package/dist/chunk-SBGY5NS4.js.map +0 -1
  147. package/dist/chunk-STK4KJQ6.js.map +0 -1
  148. package/dist/chunk-T2KW3P23.cjs +0 -183
  149. package/dist/chunk-T2KW3P23.cjs.map +0 -1
@@ -118,53 +118,6 @@ var init_env = __esm({
118
118
  }
119
119
  });
120
120
 
121
- // src/_internal/otel-provider.browser.ts
122
- function noteBrowserRuntime() {
123
- if (warned) return;
124
- warned = true;
125
- try {
126
- console.info(
127
- "[morse] Browser build active: OpenTelemetry span export and database capture are Node-only, so traces are sent via Morse's JSON transport instead. Everything else \u2014 run()/span()/track() and W3C traceparent propagation \u2014 behaves identically. Server-side code (Next.js route handlers, RSC, Node services) automatically gets the full OTel pipeline."
128
- );
129
- } catch {
130
- }
131
- }
132
- function getEngine() {
133
- return engine;
134
- }
135
- function withOtelSpanContext(traceIdHex, spanIdHex, fn) {
136
- return fn();
137
- }
138
- var warned, OtelEngine, engine;
139
- var init_otel_provider_browser = __esm({
140
- "src/_internal/otel-provider.browser.ts"() {
141
- warned = false;
142
- OtelEngine = class {
143
- // Params are declared (not dropped) so this class stays signature-compatible
144
- // with the real `OtelEngine` — the build swaps the modules, but anything
145
- // type-checking against this one must see the same shape. `void x` marks the
146
- // deliberate non-use for @typescript-eslint/no-unused-vars.
147
- configure(opts) {
148
- noteBrowserRuntime();
149
- }
150
- shutdown() {
151
- }
152
- resetForTesting() {
153
- warned = false;
154
- }
155
- async flush() {
156
- }
157
- resolveSampled(traceIdHex) {
158
- return true;
159
- }
160
- registerInstrumentations(instrumentations) {
161
- return null;
162
- }
163
- };
164
- engine = new OtelEngine();
165
- }
166
- });
167
-
168
121
  // src/_internal/redaction.ts
169
122
  function buildRedactionConfig(options) {
170
123
  const opts = options ?? {};
@@ -353,6 +306,377 @@ var init_redaction = __esm({
353
306
  }
354
307
  });
355
308
 
309
+ // src/_internal/diagnostics.ts
310
+ function setRedactionConfig(config) {
311
+ activeRedactionConfig = config;
312
+ }
313
+ function setLevel(raw) {
314
+ if (!raw) return;
315
+ const value = String(raw).trim().toLowerCase();
316
+ if (!VALID_LEVELS.has(value)) return;
317
+ level = value;
318
+ }
319
+ function transmissionAllowed() {
320
+ if (isTelemetryDisabled() || isDisabled()) return false;
321
+ return level !== LEVEL_OFF;
322
+ }
323
+ function checkBucket(buckets, key, limit, windowMs) {
324
+ const now = Date.now();
325
+ const bucket = buckets.get(key) ?? [];
326
+ const cutoff = now - windowMs;
327
+ while (bucket.length > 0 && bucket[0] < cutoff) bucket.shift();
328
+ if (bucket.length >= limit) {
329
+ buckets.set(key, bucket);
330
+ return false;
331
+ }
332
+ bucket.push(now);
333
+ buckets.set(key, bucket);
334
+ return true;
335
+ }
336
+ function checkRateLimit(fingerprint) {
337
+ const limit = level === LEVEL_DEBUG ? RATE_LIMIT_PER_WINDOW_DEBUG : RATE_LIMIT_PER_WINDOW;
338
+ return checkBucket(rateBuckets, fingerprint, limit, RATE_WINDOW_MS);
339
+ }
340
+ function isMorseFrame(line) {
341
+ return MORSE_PATH_MARKERS.some((marker) => line.includes(marker));
342
+ }
343
+ function parseFrame(line) {
344
+ const withParens = /^\s*at\s+(.+?)\s+\((.+?):(\d+):(\d+)\)\s*$/.exec(line);
345
+ if (withParens) {
346
+ return {
347
+ fn: withParens[1],
348
+ file: withParens[2],
349
+ lineNo: Number(withParens[3])
350
+ };
351
+ }
352
+ const bare = /^\s*at\s+(.+?):(\d+):(\d+)\s*$/.exec(line);
353
+ if (bare) return { file: bare[1], lineNo: Number(bare[2]) };
354
+ return {};
355
+ }
356
+ function buildScopedStack(error) {
357
+ const frames = [];
358
+ try {
359
+ const stack = error instanceof Error ? error.stack ?? "" : "";
360
+ if (!stack) return frames;
361
+ let elided = 0;
362
+ for (const raw of stack.split("\n")) {
363
+ if (!raw.trim().startsWith("at ")) continue;
364
+ if (isMorseFrame(raw)) {
365
+ if (elided > 0) {
366
+ frames.push({ elided });
367
+ elided = 0;
368
+ }
369
+ const { file, lineNo, fn } = parseFrame(raw);
370
+ const frame = {};
371
+ if (file) frame.file = file.split(/[\\/]/).slice(-3).join("/");
372
+ if (typeof lineNo === "number" && !Number.isNaN(lineNo)) frame.line = lineNo;
373
+ if (fn) frame.function = fn.slice(0, 255);
374
+ frames.push(frame);
375
+ } else {
376
+ elided += 1;
377
+ }
378
+ }
379
+ if (elided > 0) frames.push({ elided });
380
+ } catch {
381
+ }
382
+ return frames.length > MAX_STACK_ENTRIES ? frames.slice(-MAX_STACK_ENTRIES) : frames;
383
+ }
384
+ function redactedMessage(error) {
385
+ let raw;
386
+ try {
387
+ raw = error instanceof Error ? error.message : String(error);
388
+ } catch {
389
+ return "";
390
+ }
391
+ try {
392
+ if (activeRedactionConfig) {
393
+ const out = redactValue(raw, activeRedactionConfig);
394
+ raw = typeof out === "string" ? out : String(out);
395
+ }
396
+ } catch {
397
+ return "<redaction unavailable>";
398
+ }
399
+ return raw.slice(0, MAX_MESSAGE_CHARS);
400
+ }
401
+ function scrubExtra(extra) {
402
+ const out = {};
403
+ if (!extra) return out;
404
+ for (const [key, value] of Object.entries(extra)) {
405
+ if (ALLOWED_EXTRA_KEYS.has(key) && value != null) {
406
+ out[key] = String(value).slice(0, 255);
407
+ }
408
+ }
409
+ return out;
410
+ }
411
+ function recordDrop(reason, category, quantity = 1) {
412
+ try {
413
+ if (quantity <= 0) return;
414
+ const key = `${reason}:${category}`;
415
+ const existing = counters.get(key);
416
+ if (existing) existing.quantity += quantity;
417
+ else counters.set(key, { reason, category, quantity });
418
+ if (checkBucket(localLogBuckets, `drop:${key}`, LOCAL_LOG_LIMIT_PER_WINDOW, LOCAL_LOG_WINDOW_MS)) {
419
+ console.warn(`morse: dropped ${quantity} ${category} (${reason}) \u2014 telemetry is being lost`);
420
+ }
421
+ } catch {
422
+ }
423
+ }
424
+ function drainCounters() {
425
+ if (counters.size === 0) return [];
426
+ const drained = [...counters.values()];
427
+ counters.clear();
428
+ return drained;
429
+ }
430
+ function report(error, options) {
431
+ if (reporting) return;
432
+ reporting = true;
433
+ try {
434
+ const errClass = error instanceof Error ? error.name : "Error";
435
+ const errMessage = error instanceof Error ? error.message : String(error);
436
+ if (checkBucket(
437
+ localLogBuckets,
438
+ options.fingerprint,
439
+ LOCAL_LOG_LIMIT_PER_WINDOW,
440
+ LOCAL_LOG_WINDOW_MS
441
+ )) {
442
+ const line = `morse internal error [${options.fingerprint}]: ${errClass}: ${errMessage}`;
443
+ if (isDebug()) console.error(line, error);
444
+ else console.warn(line);
445
+ }
446
+ if (!transmissionAllowed()) return;
447
+ if (!checkRateLimit(options.fingerprint)) return;
448
+ enqueue({
449
+ kind: "error",
450
+ fingerprint: options.fingerprint.slice(0, 255),
451
+ error_type: errClass.slice(0, 255),
452
+ message: redactedMessage(error),
453
+ stack: buildScopedStack(error),
454
+ sdk_language: "typescript",
455
+ sdk_version: sdkVersion(),
456
+ runtime_version: runtimeVersion(),
457
+ platform: platformLabel(),
458
+ extra: scrubExtra(options.extra)
459
+ });
460
+ } catch {
461
+ } finally {
462
+ reporting = false;
463
+ }
464
+ }
465
+ function sdkVersion() {
466
+ return SDK_VERSION;
467
+ }
468
+ function runtimeVersion() {
469
+ try {
470
+ const proc = globalThis.process;
471
+ return proc?.version ? String(proc.version) : "";
472
+ } catch {
473
+ return "";
474
+ }
475
+ }
476
+ function platformLabel() {
477
+ try {
478
+ const proc = globalThis.process;
479
+ if (proc?.platform) return `${proc.platform}-${proc.arch ?? ""}`.slice(0, 128);
480
+ return "browser";
481
+ } catch {
482
+ return "";
483
+ }
484
+ }
485
+ function enqueue(event) {
486
+ pending.push(event);
487
+ while (pending.length > MAX_PENDING) pending.shift();
488
+ ensureTimer();
489
+ }
490
+ function ensureTimer() {
491
+ if (timer !== null) return;
492
+ try {
493
+ timer = setInterval(() => {
494
+ void flushOnce();
495
+ }, FLUSH_INTERVAL_MS);
496
+ timer?.unref?.();
497
+ } catch {
498
+ timer = null;
499
+ }
500
+ }
501
+ function breakerBlocks() {
502
+ return breakerOpenUntil > 0 && Date.now() < breakerOpenUntil;
503
+ }
504
+ function recordResult(ok) {
505
+ if (ok) {
506
+ consecutiveFailures = 0;
507
+ breakerOpenUntil = 0;
508
+ return;
509
+ }
510
+ consecutiveFailures += 1;
511
+ if (consecutiveFailures >= BREAKER_THRESHOLD) {
512
+ breakerOpenUntil = Date.now() + BREAKER_COOLDOWN_MS;
513
+ }
514
+ }
515
+ async function flushOnce() {
516
+ try {
517
+ const batch = pending.splice(0, MAX_BATCH_EVENTS);
518
+ const drained = drainCounters();
519
+ if (drained.length > 0) {
520
+ batch.push({
521
+ kind: "counters",
522
+ fingerprint: "morse.transport.delivery",
523
+ counters: drained,
524
+ sdk_language: "typescript",
525
+ sdk_version: sdkVersion()
526
+ });
527
+ }
528
+ if (batch.length === 0) return;
529
+ if (breakerBlocks() || !transmissionAllowed()) return;
530
+ const target = resolveTarget();
531
+ if (target === null) return;
532
+ let response;
533
+ try {
534
+ response = await fetch(target.url, {
535
+ method: "POST",
536
+ headers: {
537
+ Authorization: `Bearer ${target.apiKey}`,
538
+ "Content-Type": "application/json"
539
+ },
540
+ body: JSON.stringify({ events: batch })
541
+ });
542
+ } catch {
543
+ recordResult(false);
544
+ return;
545
+ }
546
+ setLevel(response.headers.get("X-Morse-Diagnostics"));
547
+ recordResult(response.ok);
548
+ } catch {
549
+ }
550
+ }
551
+ function resolveTarget() {
552
+ try {
553
+ const apiKey = getApiKey();
554
+ if (!apiKey) return null;
555
+ const url = deriveDiagnosticsUrl(String(getEndpoint() ?? ""));
556
+ if (!url) return null;
557
+ return { apiKey: String(apiKey), url };
558
+ } catch {
559
+ return null;
560
+ }
561
+ }
562
+ function deriveDiagnosticsUrl(tracesEndpoint) {
563
+ try {
564
+ const parsed = new URL(tracesEndpoint);
565
+ return `${parsed.protocol}//${parsed.host}${DIAGNOSTICS_PATH}`;
566
+ } catch {
567
+ return null;
568
+ }
569
+ }
570
+ function _resetForTesting() {
571
+ rateBuckets.clear();
572
+ localLogBuckets.clear();
573
+ counters.clear();
574
+ pending = [];
575
+ if (timer !== null) {
576
+ clearInterval(timer);
577
+ timer = null;
578
+ }
579
+ consecutiveFailures = 0;
580
+ breakerOpenUntil = 0;
581
+ reporting = false;
582
+ level = LEVEL_ERROR;
583
+ activeRedactionConfig = null;
584
+ }
585
+ var SDK_VERSION, LEVEL_OFF, LEVEL_ERROR, LEVEL_DEBUG, VALID_LEVELS, level, RATE_WINDOW_MS, RATE_LIMIT_PER_WINDOW, RATE_LIMIT_PER_WINDOW_DEBUG, rateBuckets, LOCAL_LOG_WINDOW_MS, LOCAL_LOG_LIMIT_PER_WINDOW, localLogBuckets, MAX_STACK_ENTRIES, MAX_MESSAGE_CHARS, MAX_BATCH_EVENTS, ALLOWED_EXTRA_KEYS, DIAGNOSTICS_PATH, MAX_PENDING, FLUSH_INTERVAL_MS, BREAKER_THRESHOLD, BREAKER_COOLDOWN_MS, REASON_QUEUE_FULL, REASON_RETRY_EXHAUSTED, REASON_QUOTA_REJECTED, REASON_SHUTDOWN_DROP, counters, activeRedactionConfig, pending, timer, consecutiveFailures, breakerOpenUntil, reporting, MORSE_PATH_MARKERS;
586
+ var init_diagnostics = __esm({
587
+ "src/_internal/diagnostics.ts"() {
588
+ init_env();
589
+ init_redaction();
590
+ SDK_VERSION = "0.5.0-rc.1" ;
591
+ LEVEL_OFF = "off";
592
+ LEVEL_ERROR = "error";
593
+ LEVEL_DEBUG = "debug";
594
+ VALID_LEVELS = /* @__PURE__ */ new Set([LEVEL_OFF, LEVEL_ERROR, LEVEL_DEBUG]);
595
+ level = LEVEL_ERROR;
596
+ RATE_WINDOW_MS = 6e4;
597
+ RATE_LIMIT_PER_WINDOW = 100;
598
+ RATE_LIMIT_PER_WINDOW_DEBUG = 1e3;
599
+ rateBuckets = /* @__PURE__ */ new Map();
600
+ LOCAL_LOG_WINDOW_MS = 6e4;
601
+ LOCAL_LOG_LIMIT_PER_WINDOW = 10;
602
+ localLogBuckets = /* @__PURE__ */ new Map();
603
+ MAX_STACK_ENTRIES = 64;
604
+ MAX_MESSAGE_CHARS = 4096;
605
+ MAX_BATCH_EVENTS = 32;
606
+ ALLOWED_EXTRA_KEYS = /* @__PURE__ */ new Set([
607
+ "adapter",
608
+ "module",
609
+ "function",
610
+ "operation",
611
+ "endpoint_host"
612
+ ]);
613
+ DIAGNOSTICS_PATH = "/api/v1/diagnostics/sdk";
614
+ MAX_PENDING = 100;
615
+ FLUSH_INTERVAL_MS = 5e3;
616
+ BREAKER_THRESHOLD = 3;
617
+ BREAKER_COOLDOWN_MS = 3e5;
618
+ REASON_QUEUE_FULL = "queue_full";
619
+ REASON_RETRY_EXHAUSTED = "retry_exhausted";
620
+ REASON_QUOTA_REJECTED = "quota_rejected";
621
+ REASON_SHUTDOWN_DROP = "shutdown_drop";
622
+ counters = /* @__PURE__ */ new Map();
623
+ activeRedactionConfig = null;
624
+ pending = [];
625
+ timer = null;
626
+ consecutiveFailures = 0;
627
+ breakerOpenUntil = 0;
628
+ reporting = false;
629
+ MORSE_PATH_MARKERS = ["@morsehq/sdk", "morse-sdk", "/morse/", "morse_ai"];
630
+ }
631
+ });
632
+
633
+ // src/_internal/otel-provider.browser.ts
634
+ function noteBrowserRuntime() {
635
+ if (warned) return;
636
+ warned = true;
637
+ try {
638
+ console.info(
639
+ "[morse] Browser build active: OpenTelemetry span export and database capture are Node-only, so traces are sent via Morse's JSON transport instead. Everything else \u2014 run()/span()/track() and W3C traceparent propagation \u2014 behaves identically. Server-side code (Next.js route handlers, RSC, Node services) automatically gets the full OTel pipeline."
640
+ );
641
+ } catch {
642
+ }
643
+ }
644
+ function getEngine() {
645
+ return engine;
646
+ }
647
+ function withOtelSpanContext(traceIdHex, spanIdHex, fn) {
648
+ return fn();
649
+ }
650
+ var warned, OtelEngine, engine;
651
+ var init_otel_provider_browser = __esm({
652
+ "src/_internal/otel-provider.browser.ts"() {
653
+ warned = false;
654
+ OtelEngine = class {
655
+ // Params are declared (not dropped) so this class stays signature-compatible
656
+ // with the real `OtelEngine` — the build swaps the modules, but anything
657
+ // type-checking against this one must see the same shape. `void x` marks the
658
+ // deliberate non-use for @typescript-eslint/no-unused-vars.
659
+ configure(opts) {
660
+ noteBrowserRuntime();
661
+ }
662
+ shutdown() {
663
+ }
664
+ resetForTesting() {
665
+ warned = false;
666
+ }
667
+ async flush() {
668
+ }
669
+ resolveSampled(traceIdHex) {
670
+ return true;
671
+ }
672
+ registerInstrumentations(instrumentations) {
673
+ return null;
674
+ }
675
+ };
676
+ engine = new OtelEngine();
677
+ }
678
+ });
679
+
356
680
  // src/_internal/spans.ts
357
681
  function generateTraceId() {
358
682
  return randomHex(32);
@@ -453,8 +777,9 @@ function setTransport(t) {
453
777
  function getTransport() {
454
778
  return transport;
455
779
  }
456
- function setRedactionConfig(config) {
780
+ function setRedactionConfig2(config) {
457
781
  redactionConfig = config;
782
+ setRedactionConfig(config);
458
783
  }
459
784
  function getRedactionConfig() {
460
785
  return redactionConfig;
@@ -543,8 +868,15 @@ function buildTraceDict(state, rootSpan) {
543
868
  spans: spans.map((s) => redactSpanDict(s, config))
544
869
  };
545
870
  const effectiveSource = state.sourceOverride || _source;
871
+ const resource = {};
546
872
  if (effectiveSource) {
547
- out.resource = { "morse_ai.source": effectiveSource };
873
+ resource["morse_ai.source"] = effectiveSource;
874
+ }
875
+ if (state.framework) {
876
+ resource["morse_ai.framework"] = state.framework;
877
+ }
878
+ if (Object.keys(resource).length > 0) {
879
+ out.resource = resource;
548
880
  }
549
881
  return out;
550
882
  }
@@ -761,7 +1093,7 @@ async function spanAsync(opts, fn) {
761
1093
  throw err;
762
1094
  }
763
1095
  }
764
- function _resetForTesting() {
1096
+ function _resetForTesting2() {
765
1097
  browserState = null;
766
1098
  lastTrace = null;
767
1099
  redactionConfig = buildRedactionConfig();
@@ -771,6 +1103,7 @@ var init_tracing = __esm({
771
1103
  "src/_internal/tracing.ts"() {
772
1104
  init_env();
773
1105
  init_otel_provider_browser();
1106
+ init_diagnostics();
774
1107
  init_redaction();
775
1108
  init_spans();
776
1109
  als = null;
@@ -888,6 +1221,6 @@ var init_propagation = __esm({
888
1221
  }
889
1222
  });
890
1223
 
891
- export { DEFAULT_ENDPOINT, SpanType, W3C_TRACEPARENT_HEADER, _resetForTesting, buildRedactionConfig, buildTraceEntry, extractTraceparent, formatTraceparent, generateSpanId, generateTraceId, getActiveTraceState, getApiKey, getEndpoint, getEngine, getFlushIntervalSeconds, getInternalSource, getLastTrace, getMaxBatchSize, getMaxFieldBytes, getMaxQueueSize, getRedactionConfig, getSampleRate, getTransport, init_env, init_otel_provider_browser, init_propagation, init_redaction, init_spans, init_tracing, injectIntoRequestInit, injectTraceparent, isDebug, isDisabled, isTelemetryDisabled, isValidInternalSource, nowIso, redactValue, runAsync, runSync, sendTrace, setContext, setRedactionConfig, setSource, setTransport, spanAsync, spanSync, startSpan };
892
- //# sourceMappingURL=chunk-F3B4UR64.js.map
893
- //# sourceMappingURL=chunk-F3B4UR64.js.map
1224
+ export { DEFAULT_ENDPOINT, REASON_QUEUE_FULL, REASON_QUOTA_REJECTED, REASON_RETRY_EXHAUSTED, REASON_SHUTDOWN_DROP, SpanType, W3C_TRACEPARENT_HEADER, _resetForTesting, _resetForTesting2, buildRedactionConfig, buildTraceEntry, extractTraceparent, formatTraceparent, generateSpanId, generateTraceId, getActiveTraceState, getApiKey, getEndpoint, getEngine, getFlushIntervalSeconds, getInternalSource, getLastTrace, getMaxBatchSize, getMaxFieldBytes, getMaxQueueSize, getRedactionConfig, getSampleRate, getTransport, init_diagnostics, init_env, init_otel_provider_browser, init_propagation, init_redaction, init_spans, init_tracing, injectIntoRequestInit, injectTraceparent, isDisabled, isValidInternalSource, nowIso, recordDrop, redactValue, report, runAsync, runSync, sendTrace, setContext, setLevel, setRedactionConfig2 as setRedactionConfig, setSource, setTransport, spanAsync, spanSync, startSpan };
1225
+ //# sourceMappingURL=chunk-6DOP3MTY.js.map
1226
+ //# sourceMappingURL=chunk-6DOP3MTY.js.map