@morsehq-dev/sdk 0.4.1 → 0.5.0-rc.2

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-GWJYOQNC.js → chunk-3MTJGZGX.js} +10 -4
  14. package/dist/browser/chunk-3MTJGZGX.js.map +1 -0
  15. package/dist/browser/{chunk-EFUQVASI.cjs → chunk-63ZI6PGP.cjs} +17 -15
  16. package/dist/browser/chunk-63ZI6PGP.cjs.map +1 -0
  17. package/dist/browser/{chunk-DXWHT3HK.cjs → chunk-A5EYWAOT.cjs} +428 -63
  18. package/dist/browser/chunk-A5EYWAOT.cjs.map +1 -0
  19. package/dist/browser/{chunk-AYNX24P5.js → chunk-AM6LMQCT.js} +3 -3
  20. package/dist/browser/{chunk-AYNX24P5.js.map → chunk-AM6LMQCT.js.map} +1 -1
  21. package/dist/{chunk-SBGY5NS4.js → browser/chunk-FDE32B3R.js} +6 -4
  22. package/dist/browser/chunk-FDE32B3R.js.map +1 -0
  23. package/dist/browser/{chunk-DOLWR7LD.js → chunk-L6FWDEGJ.js} +4 -4
  24. package/dist/browser/{chunk-DOLWR7LD.js.map → chunk-L6FWDEGJ.js.map} +1 -1
  25. package/dist/browser/{chunk-QWRQJO57.js → chunk-MLDVXMQD.js} +3 -3
  26. package/dist/browser/{chunk-QWRQJO57.js.map → chunk-MLDVXMQD.js.map} +1 -1
  27. package/dist/{chunk-Y7SVGUKY.cjs → browser/chunk-N3PXJCOE.cjs} +7 -7
  28. package/dist/browser/{chunk-YNUZGKUA.cjs.map → chunk-N3PXJCOE.cjs.map} +1 -1
  29. package/dist/browser/chunk-NH54DAJP.js +118 -0
  30. package/dist/browser/chunk-NH54DAJP.js.map +1 -0
  31. package/dist/browser/chunk-NRYB5GJT.js +28 -0
  32. package/dist/browser/chunk-NRYB5GJT.js.map +1 -0
  33. package/dist/browser/{chunk-F3B4UR64.js → chunk-OOGAYEJF.js} +423 -61
  34. package/dist/browser/chunk-OOGAYEJF.js.map +1 -0
  35. package/dist/browser/{chunk-3643DC7K.cjs → chunk-RBNCTHK3.cjs} +5 -2
  36. package/dist/browser/{chunk-3643DC7K.cjs.map → chunk-RBNCTHK3.cjs.map} +1 -1
  37. package/dist/browser/chunk-SOJYLXCR.cjs +126 -0
  38. package/dist/browser/chunk-SOJYLXCR.cjs.map +1 -0
  39. package/dist/browser/{chunk-HGN7J3EU.cjs → chunk-T4NHSVXH.cjs} +12 -12
  40. package/dist/browser/{chunk-HGN7J3EU.cjs.map → chunk-T4NHSVXH.cjs.map} +1 -1
  41. package/dist/browser/chunk-YMEU6XQQ.cjs +31 -0
  42. package/dist/browser/chunk-YMEU6XQQ.cjs.map +1 -0
  43. package/dist/browser/{chunk-M2GZJ3RS.cjs → chunk-YR2FCEWM.cjs} +20 -14
  44. package/dist/browser/chunk-YR2FCEWM.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-LTKGLXAE.js → chunk-3IGQWLWE.js} +447 -76
  68. package/dist/chunk-3IGQWLWE.js.map +1 -0
  69. package/dist/{chunk-4R4SHGOK.js → chunk-4JPZV2VZ.js} +3 -3
  70. package/dist/{chunk-4R4SHGOK.js.map → chunk-4JPZV2VZ.js.map} +1 -1
  71. package/dist/chunk-6DZNK4VX.cjs +31 -0
  72. package/dist/chunk-6DZNK4VX.cjs.map +1 -0
  73. package/dist/{browser/chunk-F7BGQ26H.js → chunk-FCAPLB7A.js} +6 -4
  74. package/dist/chunk-FCAPLB7A.js.map +1 -0
  75. package/dist/{chunk-KJEO52QS.cjs → chunk-HICEJ4LV.cjs} +5 -2
  76. package/dist/{chunk-KJEO52QS.cjs.map → chunk-HICEJ4LV.cjs.map} +1 -1
  77. package/dist/chunk-S4WUABAU.js +28 -0
  78. package/dist/chunk-S4WUABAU.js.map +1 -0
  79. package/dist/{chunk-V5J6J4ZR.js → chunk-SHK2XEPB.js} +4 -4
  80. package/dist/{chunk-V5J6J4ZR.js.map → chunk-SHK2XEPB.js.map} +1 -1
  81. package/dist/{chunk-LQI63FHF.cjs → chunk-SNGYSP7Z.cjs} +20 -14
  82. package/dist/chunk-SNGYSP7Z.cjs.map +1 -0
  83. package/dist/chunk-VHF4GWJ4.cjs +126 -0
  84. package/dist/chunk-VHF4GWJ4.cjs.map +1 -0
  85. package/dist/{chunk-HNCWTENX.cjs → chunk-XCOZIFHC.cjs} +452 -78
  86. package/dist/chunk-XCOZIFHC.cjs.map +1 -0
  87. package/dist/chunk-XJUH6PR5.js +118 -0
  88. package/dist/chunk-XJUH6PR5.js.map +1 -0
  89. package/dist/{browser/chunk-YNUZGKUA.cjs → chunk-Y2QHMV6H.cjs} +7 -7
  90. package/dist/{chunk-Y7SVGUKY.cjs.map → chunk-Y2QHMV6H.cjs.map} +1 -1
  91. package/dist/{chunk-STK4KJQ6.js → chunk-YJYF4NSA.js} +10 -4
  92. package/dist/chunk-YJYF4NSA.js.map +1 -0
  93. package/dist/{chunk-5D6SBSEI.cjs → chunk-Z2IYSTRT.cjs} +17 -15
  94. package/dist/chunk-Z2IYSTRT.cjs.map +1 -0
  95. package/dist/{chunk-QXRJUPDP.cjs → chunk-ZIER4DGK.cjs} +12 -12
  96. package/dist/{chunk-QXRJUPDP.cjs.map → chunk-ZIER4DGK.cjs.map} +1 -1
  97. package/dist/{chunk-AEFUXEKV.js → chunk-ZWOSPXS4.js} +3 -3
  98. package/dist/{chunk-AEFUXEKV.js.map → chunk-ZWOSPXS4.js.map} +1 -1
  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
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AM,MAAA,KAAW,CAAA,EAAG,OAAO,MAAA;AAC/B,EAAA,OAAO,YAAA,CAAa,KAAA,CAAM,IAAA,CAAK,IAAI,GAAG,QAAQ,CAAA;AAChD;AAEA,SAAS,SAAS,KAAA,EAAwB;AACxC,EAAA,IAAI;AACF,IAAA,OAAO,IAAA,CAAK,SAAA,CAAU,KAAK,CAAA,IAAK,OAAO,KAAK,CAAA;AAAA,EAC9C,CAAA,CAAA,MAAQ;AACN,IAAA,OAAO,OAAO,KAAK,CAAA;AAAA,EACrB;AACF","file":"chunk-NH54DAJP.js","sourcesContent":["/**\n * MHQ-859 — active framework discovery, the TS half of AGE-240.\n *\n * Python has had this since AGE-240: each adapter marks itself active when\n * it intercepts a call, the trace stamps `morse_ai.framework` on its\n * resource, and the server uses it to disambiguate agents that share a\n * logical name but not an implementation. TypeScript had the *consumer*\n * side wired all along — `otel-provider.ts` already maps\n * `resource[\"morse_ai.framework\"]` to the `av.framework` root-span\n * attribute — but nothing ever set it, so every TS trace landed with\n * `framework` NULL and framework filtering silently excluded all TS traffic.\n *\n * Python uses a `threading.local`. The Node equivalent is per-trace state,\n * not per-thread: `AsyncLocalStorage` already scopes the active trace, and\n * concurrent traces in one process must not see each other's marker. So the\n * marker is written straight onto the active trace state and there is no\n * module-global to leak across interleaved async calls — which also removes\n * the need for Python's `clear_active_framework()` try/finally discipline.\n *\n * First framework wins per trace: when a customer mixes two adapters in one\n * trace, the first to fire defines the label. Absence is the signal — never\n * invent a default.\n */\n\nimport { getActiveTraceState } from \"./tracing\";\n\n/**\n * Mark `name` as the framework for the currently-active trace.\n *\n * No-op when no trace is active (an adapter can fire outside `run()`), and\n * no-op when a framework is already set. Never throws — telemetry must not\n * break customer code.\n */\nexport function setActiveFramework(name: string): void {\n if (typeof name !== \"string\" || name.length === 0) return;\n try {\n const state = getActiveTraceState();\n if (state !== null && !state.framework) {\n state.framework = name;\n }\n } catch {\n // swallow — never break the caller\n }\n}\n\n/** Framework recorded on the active trace, or `undefined`. */\nexport function getActiveFramework(): string | undefined {\n try {\n return getActiveTraceState()?.framework ?? undefined;\n } catch {\n return undefined;\n }\n}\n","/**\n * MHQ-858 — shared `input_data` / `output_data` capture for LLM spans.\n *\n * Python's adapters have captured prompt/response content on `llm` spans\n * since MHQ-772; no TypeScript adapter ever did, so the trace-detail\n * INPUT/OUTPUT panes were empty for every TS customer while being populated\n * for the Python customer running the identical workload.\n *\n * Mirrors `morse_ai/adapters/anthropic.py`'s `_safe_input_messages` /\n * `_extract_output_text`, including the 4096-byte cap, so the two SDKs\n * produce the same shape for the same call.\n */\n\nimport { contentToText, getContent, getRole } from \"../_agent-sdk-common/context-decomposer\";\n\n/** Bytes of text kept per field. Matches Python's `_CONTENT_BYTE_CAP`. */\nexport const CONTENT_BYTE_CAP = 4096;\n\n/**\n * Truncate on a UTF-8 *byte* budget, not a UTF-16 code-unit count — a\n * 4096-char string of emoji is 16KB on the wire. Never splits a code point.\n */\nexport function truncateText(text: string, maxBytes: number = CONTENT_BYTE_CAP): string {\n if (typeof text !== \"string\" || text.length === 0) return text;\n const encoder = new TextEncoder();\n const bytes = encoder.encode(text);\n if (bytes.length <= maxBytes) return text;\n // `fatal: false` replaces a trailing partial code point with U+FFFD\n // rather than throwing; drop it so the value stays clean.\n const sliced = new TextDecoder(\"utf-8\", { fatal: false }).decode(bytes.subarray(0, maxBytes));\n return sliced.replace(/�$/, \"\") + \"…\";\n}\n\nexport interface CapturedInput {\n messages: Array<{ role?: unknown; content?: unknown }>;\n system?: string;\n}\n\n/**\n * Build a truncated, JSON-safe `input_data` from a chat-completions-shaped\n * request. String content is truncated; block-form content (tool_use,\n * tool_result, image parts) passes through as-is — per-block truncation\n * would mean reconstructing each provider's content-block schema exactly,\n * which is not worth it for a display field.\n *\n * Returns `undefined` when there is nothing worth showing, so callers can\n * assign unconditionally without writing empty objects onto the wire.\n */\nexport function captureInputMessages(\n messages: unknown,\n system?: unknown,\n maxBytes: number = CONTENT_BYTE_CAP,\n): CapturedInput | undefined {\n if (!Array.isArray(messages) || messages.length === 0) return undefined;\n\n const safeMessages = messages\n .filter((m): m is Record<string, unknown> => typeof m === \"object\" && m !== null)\n .map((m) => ({\n role: m.role,\n content: typeof m.content === \"string\" ? truncateText(m.content, maxBytes) : m.content,\n }));\n if (safeMessages.length === 0) return undefined;\n\n const out: CapturedInput = { messages: safeMessages };\n const systemText = flattenSystem(system);\n if (systemText) out.system = truncateText(systemText, maxBytes);\n return out;\n}\n\n/**\n * Anthropic's `system` is either a string or an array of text blocks.\n * Returns `undefined` when neither yields text.\n */\nexport function flattenSystem(system: unknown): string | undefined {\n if (typeof system === \"string\") return system || undefined;\n if (!Array.isArray(system)) return undefined;\n const parts = system\n .map((block) =>\n typeof block === \"string\"\n ? block\n : typeof (block as { text?: unknown })?.text === \"string\"\n ? (block as { text: string }).text\n : \"\",\n )\n .filter(Boolean);\n return parts.length > 0 ? parts.join(\"\\n\") : undefined;\n}\n\n/**\n * Extract the assistant's text from an Anthropic `Message.content` array.\n * A response that only calls a tool still yields something meaningful\n * rather than nothing — same rule as Python's `_extract_output_text`.\n */\nexport function extractAnthropicOutputText(\n content: unknown,\n maxBytes: number = CONTENT_BYTE_CAP,\n): string | undefined {\n if (!Array.isArray(content) || content.length === 0) return undefined;\n const parts: string[] = [];\n for (const block of content) {\n const b = block as { type?: unknown; text?: unknown; name?: unknown; input?: unknown };\n if (b?.type === \"text\" && typeof b.text === \"string\" && b.text) {\n parts.push(b.text);\n } else if (b?.type === \"tool_use\") {\n const name = typeof b.name === \"string\" ? b.name : \"tool\";\n parts.push(b.input ? `[tool_use:${name}] ${safeJson(b.input)}` : `[tool_use:${name}]`);\n }\n }\n if (parts.length === 0) return undefined;\n return truncateText(parts.join(\"\\n\"), maxBytes);\n}\n\n/**\n * Extract the assistant's text from an OpenAI chat-completions response,\n * including a tool-call-only response.\n */\nexport function extractOpenAiOutputText(\n choices: unknown,\n maxBytes: number = CONTENT_BYTE_CAP,\n): string | undefined {\n if (!Array.isArray(choices) || choices.length === 0) return undefined;\n const parts: string[] = [];\n for (const choice of choices) {\n const message = (choice as { message?: Record<string, unknown> })?.message;\n if (!message) continue;\n if (typeof message.content === \"string\" && message.content) {\n parts.push(message.content);\n }\n const toolCalls = message.tool_calls;\n if (Array.isArray(toolCalls)) {\n for (const call of toolCalls) {\n const fn = (call as { function?: { name?: unknown; arguments?: unknown } })?.function;\n const name = typeof fn?.name === \"string\" ? fn.name : \"tool\";\n parts.push(\n fn?.arguments ? `[tool_call:${name}] ${String(fn.arguments)}` : `[tool_call:${name}]`,\n );\n }\n }\n }\n if (parts.length === 0) return undefined;\n return truncateText(parts.join(\"\\n\"), maxBytes);\n}\n\n/**\n * `input_data` for LangChain/LangGraph callbacks, whose messages are class\n * instances with `_getType()` rather than plain `{role, content}` dicts.\n * Reuses the decomposer's duck-typing so the two never drift.\n */\nexport function captureLangChainMessages(\n messages: unknown,\n maxBytes: number = CONTENT_BYTE_CAP,\n): CapturedInput | undefined {\n if (!Array.isArray(messages) || messages.length === 0) return undefined;\n const safeMessages = messages\n .map((m) => ({ role: getRole(m) || undefined, content: contentToText(getContent(m)) }))\n .filter((m) => m.content.length > 0)\n .map((m) => ({ role: m.role, content: truncateText(m.content, maxBytes) }));\n return safeMessages.length > 0 ? { messages: safeMessages } : undefined;\n}\n\n/** `input_data` for the raw-prompt (non-chat) LangChain LLM callback. */\nexport function capturePrompts(\n prompts: unknown,\n maxBytes: number = CONTENT_BYTE_CAP,\n): CapturedInput | undefined {\n if (!Array.isArray(prompts) || prompts.length === 0) return undefined;\n const messages = prompts\n .filter((p): p is string => typeof p === \"string\" && p.length > 0)\n .map((p) => ({ role: \"user\" as const, content: truncateText(p, maxBytes) }));\n return messages.length > 0 ? { messages } : undefined;\n}\n\n/**\n * `output_data` text from a LangChain `LLMResult` — `generations` is an\n * array-of-arrays (one inner array per prompt).\n */\nexport function extractLangChainOutputText(\n generations: unknown,\n maxBytes: number = CONTENT_BYTE_CAP,\n): string | undefined {\n if (!Array.isArray(generations)) return undefined;\n const parts: string[] = [];\n for (const group of generations) {\n if (!Array.isArray(group)) continue;\n for (const gen of group) {\n const text = (gen as { text?: unknown })?.text;\n if (typeof text === \"string\" && text) parts.push(text);\n }\n }\n if (parts.length === 0) return undefined;\n return truncateText(parts.join(\"\\n\"), maxBytes);\n}\n\nfunction safeJson(value: unknown): string {\n try {\n return JSON.stringify(value) ?? String(value);\n } catch {\n return String(value);\n }\n}\n"]}
@@ -0,0 +1,28 @@
1
+ import { init_diagnostics, report } from './chunk-OOGAYEJF.js';
2
+
3
+ // src/_internal/errors.ts
4
+ init_diagnostics();
5
+ function absorbErrorsSync(fn, options) {
6
+ return (...args) => {
7
+ try {
8
+ return fn(...args);
9
+ } catch (err) {
10
+ report(err, options);
11
+ return void 0;
12
+ }
13
+ };
14
+ }
15
+ function absorbErrorsAsync(fn, options) {
16
+ return async (...args) => {
17
+ try {
18
+ return await fn(...args);
19
+ } catch (err) {
20
+ report(err, options);
21
+ return void 0;
22
+ }
23
+ };
24
+ }
25
+
26
+ export { absorbErrorsAsync, absorbErrorsSync };
27
+ //# sourceMappingURL=chunk-NRYB5GJT.js.map
28
+ //# sourceMappingURL=chunk-NRYB5GJT.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/_internal/errors.ts"],"names":[],"mappings":";;;AAsBA,gBAAA,EAAA;AAiBO,SAAS,gBAAA,CACd,IACA,OAAA,EACyC;AACzC,EAAA,OAAO,IAAI,IAAA,KAAqC;AAC9C,IAAA,IAAI;AACF,MAAA,OAAO,EAAA,CAAG,GAAG,IAAI,CAAA;AAAA,IACnB,SAAS,GAAA,EAAK;AACZ,MAAA,MAAA,CAAO,KAAK,OAAO,CAAA;AACnB,MAAA,OAAO,MAAA;AAAA,IACT;AAAA,EACF,CAAA;AACF;AAOO,SAAS,iBAAA,CACd,IACA,OAAA,EACkD;AAClD,EAAA,OAAO,UAAU,IAAA,KAA8C;AAC7D,IAAA,IAAI;AACF,MAAA,OAAO,MAAM,EAAA,CAAG,GAAG,IAAI,CAAA;AAAA,IACzB,SAAS,GAAA,EAAK;AACZ,MAAA,MAAA,CAAO,KAAK,OAAO,CAAA;AACnB,MAAA,OAAO,MAAA;AAAA,IACT;AAAA,EACF,CAAA;AACF","file":"chunk-NRYB5GJT.js","sourcesContent":["/**\n * Non-invasive error isolation — the foundational SDK guarantee.\n *\n * Mirrors Python's `_internal/errors.py` `@absorb_errors` decorator. Every\n * public SDK function and every adapter-installed wrapper is wrapped with\n * `absorbErrors()`. The wrapper catches all exceptions and reports them\n * out-of-band to Morse's own diagnostics endpoint, then returns a benign value\n * (typically `undefined`) instead of propagating.\n *\n * Foundational principle:\n *\n * Telemetry must never break the host application.\n *\n * The customer's call returns its original result (or `undefined`)\n * regardless of whether the SDK's recording path succeeded.\n *\n * Note on async: TypeScript-land has no `KeyboardInterrupt` equivalent —\n * the analogue is \"no exceptions are special\". We absorb everything,\n * and rely on Node's `process.exit` / browser navigation to tear down\n * the runtime cleanly.\n */\n\nimport { report } from \"./diagnostics\";\n\nexport interface AbsorbErrorsOptions {\n /**\n * Stable identifier for grouping. Used for server-side grouping and\n * the rate limiter (max 100 events per fingerprint per minute).\n */\n fingerprint: string;\n /** Optional metadata attached to the report; scrubbed against an allow-list. */\n extra?: Record<string, unknown>;\n}\n\n/**\n * Wrap a synchronous function so that any thrown exception is absorbed\n * (reported out-of-band) instead of propagating. Returns `undefined` on\n * absorbed error.\n */\nexport function absorbErrorsSync<TArgs extends unknown[], TReturn>(\n fn: (...args: TArgs) => TReturn,\n options: AbsorbErrorsOptions,\n): (...args: TArgs) => TReturn | undefined {\n return (...args: TArgs): TReturn | undefined => {\n try {\n return fn(...args);\n } catch (err) {\n report(err, options);\n return undefined;\n }\n };\n}\n\n/**\n * Wrap an async function so that any rejection or thrown exception is\n * absorbed (reported out-of-band) instead of propagating. Returns\n * `undefined` on absorbed error.\n */\nexport function absorbErrorsAsync<TArgs extends unknown[], TReturn>(\n fn: (...args: TArgs) => Promise<TReturn>,\n options: AbsorbErrorsOptions,\n): (...args: TArgs) => Promise<TReturn | undefined> {\n return async (...args: TArgs): Promise<TReturn | undefined> => {\n try {\n return await fn(...args);\n } catch (err) {\n report(err, options);\n return undefined;\n }\n };\n}\n\n/**\n * Higher-order alias chosen to read like the Python decorator: pass a\n * function in, get a wrapped version back. Resolves to the sync or async\n * variant based on the runtime return value (a Promise). Defaults to\n * sync at the type level; use `absorbErrorsAsync` directly for proper\n * async typing.\n */\nexport const absorbErrors = absorbErrorsSync;\n"]}
@@ -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.2" ;
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);
@@ -421,6 +745,17 @@ function tryLoadAls() {
421
745
  als = null;
422
746
  return als;
423
747
  }
748
+ try {
749
+ const getBuiltin = process?.getBuiltinModule;
750
+ if (typeof getBuiltin === "function") {
751
+ const mod = getBuiltin("node:async_hooks");
752
+ if (mod?.AsyncLocalStorage) {
753
+ als = new mod.AsyncLocalStorage();
754
+ return als;
755
+ }
756
+ }
757
+ } catch {
758
+ }
424
759
  try {
425
760
  const dynamicRequire = Function("m", "return require(m)");
426
761
  const mod = dynamicRequire("node:async_hooks");
@@ -453,8 +788,9 @@ function setTransport(t) {
453
788
  function getTransport() {
454
789
  return transport;
455
790
  }
456
- function setRedactionConfig(config) {
791
+ function setRedactionConfig2(config) {
457
792
  redactionConfig = config;
793
+ setRedactionConfig(config);
458
794
  }
459
795
  function getRedactionConfig() {
460
796
  return redactionConfig;
@@ -543,8 +879,15 @@ function buildTraceDict(state, rootSpan) {
543
879
  spans: spans.map((s) => redactSpanDict(s, config))
544
880
  };
545
881
  const effectiveSource = state.sourceOverride || _source;
882
+ const resource = {};
546
883
  if (effectiveSource) {
547
- out.resource = { "morse_ai.source": effectiveSource };
884
+ resource["morse_ai.source"] = effectiveSource;
885
+ }
886
+ if (state.framework) {
887
+ resource["morse_ai.framework"] = state.framework;
888
+ }
889
+ if (Object.keys(resource).length > 0) {
890
+ out.resource = resource;
548
891
  }
549
892
  return out;
550
893
  }
@@ -636,16 +979,37 @@ function errToString(e) {
636
979
  if (e instanceof Error) return e.message;
637
980
  return String(e);
638
981
  }
982
+ function isThenable(v) {
983
+ return v !== null && (typeof v === "object" || typeof v === "function") && typeof v.then === "function";
984
+ }
639
985
  function runSync(opts, fn) {
640
986
  const { state, rootSpan, startMono } = startTrace(opts);
641
987
  const handle = buildRunHandle(state);
642
988
  const store = tryLoadAls();
643
989
  const runFn = () => withDbCaptureContext(state.traceId, rootSpan.span_id, () => fn(handle));
644
- if (store) {
645
- try {
646
- const result = store.run(state, runFn);
990
+ const settle = (result, onDone) => {
991
+ if (!isThenable(result)) {
647
992
  endTrace(state, rootSpan, startMono, void 0);
993
+ onDone();
648
994
  return result;
995
+ }
996
+ return result.then(
997
+ (value) => {
998
+ endTrace(state, rootSpan, startMono, void 0);
999
+ onDone();
1000
+ return value;
1001
+ },
1002
+ (err) => {
1003
+ endTrace(state, rootSpan, startMono, err);
1004
+ onDone();
1005
+ throw err;
1006
+ }
1007
+ );
1008
+ };
1009
+ if (store) {
1010
+ try {
1011
+ return settle(store.run(state, runFn), () => {
1012
+ });
649
1013
  } catch (err) {
650
1014
  endTrace(state, rootSpan, startMono, err);
651
1015
  throw err;
@@ -653,14 +1017,11 @@ function runSync(opts, fn) {
653
1017
  } else {
654
1018
  const reset = setActiveTraceState(state);
655
1019
  try {
656
- const result = runFn();
657
- endTrace(state, rootSpan, startMono, void 0);
658
- return result;
1020
+ return settle(runFn(), reset);
659
1021
  } catch (err) {
660
1022
  endTrace(state, rootSpan, startMono, err);
661
- throw err;
662
- } finally {
663
1023
  reset();
1024
+ throw err;
664
1025
  }
665
1026
  }
666
1027
  }
@@ -761,7 +1122,7 @@ async function spanAsync(opts, fn) {
761
1122
  throw err;
762
1123
  }
763
1124
  }
764
- function _resetForTesting() {
1125
+ function _resetForTesting2() {
765
1126
  browserState = null;
766
1127
  lastTrace = null;
767
1128
  redactionConfig = buildRedactionConfig();
@@ -771,6 +1132,7 @@ var init_tracing = __esm({
771
1132
  "src/_internal/tracing.ts"() {
772
1133
  init_env();
773
1134
  init_otel_provider_browser();
1135
+ init_diagnostics();
774
1136
  init_redaction();
775
1137
  init_spans();
776
1138
  als = null;
@@ -888,6 +1250,6 @@ var init_propagation = __esm({
888
1250
  }
889
1251
  });
890
1252
 
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
1253
+ 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 };
1254
+ //# sourceMappingURL=chunk-OOGAYEJF.js.map
1255
+ //# sourceMappingURL=chunk-OOGAYEJF.js.map