@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
@@ -1,11 +1,11 @@
1
1
  'use strict';
2
2
 
3
- var chunk3BGG7GH3_cjs = require('./chunk-3BGG7GH3.cjs');
4
- var chunkDXWHT3HK_cjs = require('./chunk-DXWHT3HK.cjs');
3
+ var chunkFNZWJU64_cjs = require('./chunk-FNZWJU64.cjs');
4
+ var chunkZGYZZCUK_cjs = require('./chunk-ZGYZZCUK.cjs');
5
5
 
6
6
  // src/log.ts
7
- chunkDXWHT3HK_cjs.init_redaction();
8
- chunkDXWHT3HK_cjs.init_tracing();
7
+ chunkZGYZZCUK_cjs.init_redaction();
8
+ chunkZGYZZCUK_cjs.init_tracing();
9
9
  var DEFAULT_SERVICE_NAME = "morse-sdk-ts";
10
10
  var ensureInitialized = () => {
11
11
  };
@@ -14,14 +14,14 @@ function _setEnsureInitialized(fn) {
14
14
  }
15
15
  function logImpl(message, options = {}) {
16
16
  ensureInitialized();
17
- const transport = chunkDXWHT3HK_cjs.getTransport();
17
+ const transport = chunkZGYZZCUK_cjs.getTransport();
18
18
  if (transport === null) {
19
19
  return;
20
20
  }
21
21
  let traceId = options.traceId ?? null;
22
22
  let spanId = options.spanId ?? null;
23
23
  if (traceId === null || spanId === null) {
24
- const state = chunkDXWHT3HK_cjs.getActiveTraceState();
24
+ const state = chunkZGYZZCUK_cjs.getActiveTraceState();
25
25
  if (state !== null) {
26
26
  if (traceId === null) traceId = state.traceId;
27
27
  if (spanId === null && state.spanStack.length > 0) {
@@ -31,10 +31,10 @@ function logImpl(message, options = {}) {
31
31
  }
32
32
  const severity = (options.severity ?? "info").toUpperCase();
33
33
  const serviceName = options.serviceName ?? DEFAULT_SERVICE_NAME;
34
- const config = chunkDXWHT3HK_cjs.getRedactionConfig();
34
+ const config = chunkZGYZZCUK_cjs.getRedactionConfig();
35
35
  const rawAttributes = options.attributes ?? {};
36
- const redactedAttributes = config.enabled ? chunkDXWHT3HK_cjs.redactValue(rawAttributes, config) : rawAttributes;
37
- const redactedBody = config.enabled ? chunkDXWHT3HK_cjs.redactValue(String(message), config) : String(message);
36
+ const redactedAttributes = config.enabled ? chunkZGYZZCUK_cjs.redactValue(rawAttributes, config) : rawAttributes;
37
+ const redactedBody = config.enabled ? chunkZGYZZCUK_cjs.redactValue(String(message), config) : String(message);
38
38
  const record = {
39
39
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
40
40
  severity,
@@ -46,11 +46,11 @@ function logImpl(message, options = {}) {
46
46
  };
47
47
  transport.track({ logs: [record] });
48
48
  }
49
- var log = chunk3BGG7GH3_cjs.absorbErrorsSync(logImpl, {
49
+ var log = chunkFNZWJU64_cjs.absorbErrorsSync(logImpl, {
50
50
  fingerprint: "morse.log"
51
51
  });
52
52
 
53
53
  exports._setEnsureInitialized = _setEnsureInitialized;
54
54
  exports.log = log;
55
- //# sourceMappingURL=chunk-HGN7J3EU.cjs.map
56
- //# sourceMappingURL=chunk-HGN7J3EU.cjs.map
55
+ //# sourceMappingURL=chunk-WY2VLKRR.cjs.map
56
+ //# sourceMappingURL=chunk-WY2VLKRR.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/log.ts"],"names":["init_redaction","init_tracing","getTransport","getActiveTraceState","getRedactionConfig","redactValue","absorbErrorsSync"],"mappings":";;;;;;AA8BAA,gCAAA,EAAA;AACAC,8BAAA,EAAA;AA2BA,IAAM,oBAAA,GAAuB,cAAA;AAS7B,IAAI,oBAAgC,MAAM;AAE1C,CAAA;AAGO,SAAS,sBAAsB,EAAA,EAAsB;AAC1D,EAAA,iBAAA,GAAoB,EAAA;AACtB;AAEA,SAAS,OAAA,CAAQ,OAAA,EAAiB,OAAA,GAAsB,EAAC,EAAS;AAGhE,EAAA,iBAAA,EAAkB;AAClB,EAAA,MAAM,YAAkCC,8BAAA,EAAa;AACrD,EAAA,IAAI,cAAc,IAAA,EAAM;AAGtB,IAAA;AAAA,EACF;AAMA,EAAA,IAAI,OAAA,GAAyB,QAAQ,OAAA,IAAW,IAAA;AAChD,EAAA,IAAI,MAAA,GAAwB,QAAQ,MAAA,IAAU,IAAA;AAC9C,EAAA,IAAI,OAAA,KAAY,IAAA,IAAQ,MAAA,KAAW,IAAA,EAAM;AACvC,IAAA,MAAM,QAAQC,qCAAA,EAAoB;AAClC,IAAA,IAAI,UAAU,IAAA,EAAM;AAClB,MAAA,IAAI,OAAA,KAAY,IAAA,EAAM,OAAA,GAAU,KAAA,CAAM,OAAA;AACtC,MAAA,IAAI,MAAA,KAAW,IAAA,IAAQ,KAAA,CAAM,SAAA,CAAU,SAAS,CAAA,EAAG;AACjD,QAAA,MAAA,GAAS,MAAM,SAAA,CAAU,KAAA,CAAM,SAAA,CAAU,MAAA,GAAS,CAAC,CAAA,CAAG,OAAA;AAAA,MACxD;AAAA,IACF;AAAA,EACF;AAEA,EAAA,MAAM,QAAA,GAAA,CAAY,OAAA,CAAQ,QAAA,IAAY,MAAA,EAAQ,WAAA,EAAY;AAC1D,EAAA,MAAM,WAAA,GAAc,QAAQ,WAAA,IAAe,oBAAA;AAK3C,EAAA,MAAM,SAASC,oCAAA,EAAmB;AAClC,EAAA,MAAM,aAAA,GAAgB,OAAA,CAAQ,UAAA,IAAc,EAAC;AAC7C,EAAA,MAAM,qBAAqB,MAAA,CAAO,OAAA,GAC7BC,6BAAA,CAAY,aAAA,EAAe,MAAM,CAAA,GAClC,aAAA;AACJ,EAAA,MAAM,YAAA,GAAe,MAAA,CAAO,OAAA,GACvBA,6BAAA,CAAY,MAAA,CAAO,OAAO,CAAA,EAAG,MAAM,CAAA,GACpC,MAAA,CAAO,OAAO,CAAA;AAElB,EAAA,MAAM,MAAA,GAAS;AAAA,IACb,SAAA,EAAA,iBAAW,IAAI,IAAA,EAAK,EAAE,WAAA,EAAY;AAAA,IAClC,QAAA;AAAA,IACA,YAAA,EAAc,WAAA;AAAA,IACd,IAAA,EAAM,YAAA;AAAA,IACN,UAAA,EAAY,kBAAA;AAAA,IACZ,QAAA,EAAU,OAAA;AAAA,IACV,OAAA,EAAS;AAAA,GACX;AAEA,EAAA,SAAA,CAAU,MAAM,EAAE,IAAA,EAAM,CAAC,MAAM,GAAG,CAAA;AACpC;AAmCO,IAAM,GAAA,GAAMC,mCAAiB,OAAA,EAAS;AAAA,EAC3C,WAAA,EAAa;AACf,CAAC","file":"chunk-HGN7J3EU.cjs","sourcesContent":["/**\n * Phase 12.5 Tier 1.2 — TypeScript SDK `log()` export.\n *\n * Closes the TS side of Feature #4 \"Gap A\": before this module, customers\n * using the TS SDK had no way to populate the Logs tab of a trace's\n * Correlation panel without standing up their own OTel collector. The\n * Python SDK already had `morse.log(...)` (AGE-240); this is the\n * cross-language peer.\n *\n * Semantics mirror Python's `morse.log()`\n * (`apps/sdk/python/src/morse/__init__.py:360-411`):\n *\n * - Default severity: \"info\" (case-normalised to upper on the wire).\n * - Default service_name: \"morse-sdk-ts\" (overridable).\n * - Auto-reads the active trace_id + span_id from the SDK's existing\n * `node:async_hooks.AsyncLocalStorage` context (re-uses\n * `getActiveTraceState()` — the same primitive `run()`/`span()` use).\n * - Batched: the record is enqueued on the existing `BatchTransport`,\n * which flushes it to `/api/v1/logs/ingest` (derived from the traces\n * batch endpoint) on the next tick. NO synchronous fetch per call.\n * - Internal errors are absorbed via `absorbErrorsSync` so they never\n * propagate into the customer's logging call. Mirrors the Python\n * `@absorb_errors` decorator pattern.\n *\n * Wire shape: `{ logs: [{ timestamp, severity, service_name, body,\n * attributes, trace_id, span_id }] }`. See `apps/api/apps/logs/\n * controllers.py:66-134` for the API contract.\n */\n\nimport { absorbErrorsSync } from \"./_internal/errors\";\nimport { redactValue } from \"./_internal/redaction\";\nimport {\n getActiveTraceState,\n getRedactionConfig,\n getTransport,\n type TransportLike,\n} from \"./_internal/tracing\";\n\n/** Log severity — case-insensitive on input, upper-cased on the wire. */\nexport type LogSeverity = \"trace\" | \"debug\" | \"info\" | \"warn\" | \"error\" | \"fatal\";\n\n/** Options accepted by `log()`. */\nexport interface LogOptions {\n /** Default: `\"info\"`. Upper-cased server-side. */\n severity?: LogSeverity;\n /** Free-form structured fields persisted on the record. */\n attributes?: Record<string, unknown>;\n /**\n * Override the auto-detected trace_id. Use only when emitting on\n * behalf of a known external trace (rare).\n */\n traceId?: string;\n /** Override the auto-detected span_id. Same caveat as `traceId`. */\n spanId?: string;\n /** Logical service tag. Default: `\"morse-sdk-ts\"`. */\n serviceName?: string;\n}\n\nconst DEFAULT_SERVICE_NAME = \"morse-sdk-ts\";\n\n/**\n * Lazy-init hook injected by `index.ts`. Allows `log()` to participate\n * in env-driven auto-init (matching the behaviour of `track()` /\n * `record()`) without `log.ts` reaching into the singleton state.\n *\n * @internal\n */\nlet ensureInitialized: () => void = () => {\n /* default no-op; replaced from index.ts */\n};\n\n/** @internal */\nexport function _setEnsureInitialized(fn: () => void): void {\n ensureInitialized = fn;\n}\n\nfunction logImpl(message: string, options: LogOptions = {}): void {\n // Match Python semantics: env-driven auto-init kicks in if the SDK\n // hasn't been explicitly init()'d yet but MORSE_API_KEY is set.\n ensureInitialized();\n const transport: TransportLike | null = getTransport();\n if (transport === null) {\n // SDK not initialised — silent no-op. Matches Python behaviour\n // (`_ensure_initialized()` short-circuit).\n return;\n }\n\n // Auto-pull trace + span IDs from the active context. Re-uses the\n // exact same context primitive that `track()` / `run()` / `span()`\n // use, so a `log()` call inside an `await run(...)` callback will\n // see the active trace's IDs.\n let traceId: string | null = options.traceId ?? null;\n let spanId: string | null = options.spanId ?? null;\n if (traceId === null || spanId === null) {\n const state = getActiveTraceState();\n if (state !== null) {\n if (traceId === null) traceId = state.traceId;\n if (spanId === null && state.spanStack.length > 0) {\n spanId = state.spanStack[state.spanStack.length - 1]!.span_id;\n }\n }\n }\n\n const severity = (options.severity ?? \"info\").toUpperCase();\n const serviceName = options.serviceName ?? DEFAULT_SERVICE_NAME;\n\n // PII redaction reuses the trace path's allow-list config. Mirrors\n // the Python client's `self._redaction_config.redact_value(payload)`\n // call.\n const config = getRedactionConfig();\n const rawAttributes = options.attributes ?? {};\n const redactedAttributes = config.enabled\n ? (redactValue(rawAttributes, config) as Record<string, unknown>)\n : rawAttributes;\n const redactedBody = config.enabled\n ? (redactValue(String(message), config) as string)\n : String(message);\n\n const record = {\n timestamp: new Date().toISOString(),\n severity,\n service_name: serviceName,\n body: redactedBody,\n attributes: redactedAttributes,\n trace_id: traceId,\n span_id: spanId,\n };\n\n transport.track({ logs: [record] });\n}\n\n/**\n * Emit a log record correlated to the current trace context.\n *\n * Auto-correlates to the surrounding `morse.run()` /\n * `morse.span()` if one is active. Inside a trace, the record's\n * `trace_id` + `span_id` are filled in from `AsyncLocalStorage`;\n * outside a trace, both fields are `null` and the record is still\n * accepted by the backend (it surfaces in the service-wide Logs view\n * but not on any individual trace's Correlation panel).\n *\n * Non-blocking. Batched alongside trace events on the existing\n * transport — flushes at the SDK's configured interval (default 2s).\n * Internal errors are absorbed; this call never throws.\n *\n * Silent no-op when the SDK isn't initialised (no `MORSE_API_KEY`\n * and no explicit `init()` call).\n *\n * @example\n * ```ts\n * import { init, runTraced, log } from \"@morsehq-dev/sdk\";\n *\n * init({ apiKey: process.env.MORSE_API_KEY });\n *\n * await runTraced({ agentName: \"lead-qualifier\" }, async () => {\n * log(\"starting search\", { attributes: { query: \"morse\" } });\n * const results = await search();\n * log(\"search complete\", {\n * severity: \"info\",\n * attributes: { result_count: results.length },\n * });\n * });\n * ```\n */\nexport const log = absorbErrorsSync(logImpl, {\n fingerprint: \"morse.log\",\n});\n"]}
1
+ {"version":3,"sources":["../../src/log.ts"],"names":["init_redaction","init_tracing","getTransport","getActiveTraceState","getRedactionConfig","redactValue","absorbErrorsSync"],"mappings":";;;;;;AA8BAA,gCAAA,EAAA;AACAC,8BAAA,EAAA;AA2BA,IAAM,oBAAA,GAAuB,cAAA;AAS7B,IAAI,oBAAgC,MAAM;AAE1C,CAAA;AAGO,SAAS,sBAAsB,EAAA,EAAsB;AAC1D,EAAA,iBAAA,GAAoB,EAAA;AACtB;AAEA,SAAS,OAAA,CAAQ,OAAA,EAAiB,OAAA,GAAsB,EAAC,EAAS;AAGhE,EAAA,iBAAA,EAAkB;AAClB,EAAA,MAAM,YAAkCC,8BAAA,EAAa;AACrD,EAAA,IAAI,cAAc,IAAA,EAAM;AAGtB,IAAA;AAAA,EACF;AAMA,EAAA,IAAI,OAAA,GAAyB,QAAQ,OAAA,IAAW,IAAA;AAChD,EAAA,IAAI,MAAA,GAAwB,QAAQ,MAAA,IAAU,IAAA;AAC9C,EAAA,IAAI,OAAA,KAAY,IAAA,IAAQ,MAAA,KAAW,IAAA,EAAM;AACvC,IAAA,MAAM,QAAQC,qCAAA,EAAoB;AAClC,IAAA,IAAI,UAAU,IAAA,EAAM;AAClB,MAAA,IAAI,OAAA,KAAY,IAAA,EAAM,OAAA,GAAU,KAAA,CAAM,OAAA;AACtC,MAAA,IAAI,MAAA,KAAW,IAAA,IAAQ,KAAA,CAAM,SAAA,CAAU,SAAS,CAAA,EAAG;AACjD,QAAA,MAAA,GAAS,MAAM,SAAA,CAAU,KAAA,CAAM,SAAA,CAAU,MAAA,GAAS,CAAC,CAAA,CAAG,OAAA;AAAA,MACxD;AAAA,IACF;AAAA,EACF;AAEA,EAAA,MAAM,QAAA,GAAA,CAAY,OAAA,CAAQ,QAAA,IAAY,MAAA,EAAQ,WAAA,EAAY;AAC1D,EAAA,MAAM,WAAA,GAAc,QAAQ,WAAA,IAAe,oBAAA;AAK3C,EAAA,MAAM,SAASC,oCAAA,EAAmB;AAClC,EAAA,MAAM,aAAA,GAAgB,OAAA,CAAQ,UAAA,IAAc,EAAC;AAC7C,EAAA,MAAM,qBAAqB,MAAA,CAAO,OAAA,GAC7BC,6BAAA,CAAY,aAAA,EAAe,MAAM,CAAA,GAClC,aAAA;AACJ,EAAA,MAAM,YAAA,GAAe,MAAA,CAAO,OAAA,GACvBA,6BAAA,CAAY,MAAA,CAAO,OAAO,CAAA,EAAG,MAAM,CAAA,GACpC,MAAA,CAAO,OAAO,CAAA;AAElB,EAAA,MAAM,MAAA,GAAS;AAAA,IACb,SAAA,EAAA,iBAAW,IAAI,IAAA,EAAK,EAAE,WAAA,EAAY;AAAA,IAClC,QAAA;AAAA,IACA,YAAA,EAAc,WAAA;AAAA,IACd,IAAA,EAAM,YAAA;AAAA,IACN,UAAA,EAAY,kBAAA;AAAA,IACZ,QAAA,EAAU,OAAA;AAAA,IACV,OAAA,EAAS;AAAA,GACX;AAEA,EAAA,SAAA,CAAU,MAAM,EAAE,IAAA,EAAM,CAAC,MAAM,GAAG,CAAA;AACpC;AAmCO,IAAM,GAAA,GAAMC,mCAAiB,OAAA,EAAS;AAAA,EAC3C,WAAA,EAAa;AACf,CAAC","file":"chunk-WY2VLKRR.cjs","sourcesContent":["/**\n * Phase 12.5 Tier 1.2 — TypeScript SDK `log()` export.\n *\n * Closes the TS side of Feature #4 \"Gap A\": before this module, customers\n * using the TS SDK had no way to populate the Logs tab of a trace's\n * Correlation panel without standing up their own OTel collector. The\n * Python SDK already had `morse.log(...)` (AGE-240); this is the\n * cross-language peer.\n *\n * Semantics mirror Python's `morse.log()`\n * (`apps/sdk/python/src/morse/__init__.py:360-411`):\n *\n * - Default severity: \"info\" (case-normalised to upper on the wire).\n * - Default service_name: \"morse-sdk-ts\" (overridable).\n * - Auto-reads the active trace_id + span_id from the SDK's existing\n * `node:async_hooks.AsyncLocalStorage` context (re-uses\n * `getActiveTraceState()` — the same primitive `run()`/`span()` use).\n * - Batched: the record is enqueued on the existing `BatchTransport`,\n * which flushes it to `/api/v1/logs/ingest` (derived from the traces\n * batch endpoint) on the next tick. NO synchronous fetch per call.\n * - Internal errors are absorbed via `absorbErrorsSync` so they never\n * propagate into the customer's logging call. Mirrors the Python\n * `@absorb_errors` decorator pattern.\n *\n * Wire shape: `{ logs: [{ timestamp, severity, service_name, body,\n * attributes, trace_id, span_id }] }`. See `apps/api/apps/logs/\n * controllers.py:66-134` for the API contract.\n */\n\nimport { absorbErrorsSync } from \"./_internal/errors\";\nimport { redactValue } from \"./_internal/redaction\";\nimport {\n getActiveTraceState,\n getRedactionConfig,\n getTransport,\n type TransportLike,\n} from \"./_internal/tracing\";\n\n/** Log severity — case-insensitive on input, upper-cased on the wire. */\nexport type LogSeverity = \"trace\" | \"debug\" | \"info\" | \"warn\" | \"error\" | \"fatal\";\n\n/** Options accepted by `log()`. */\nexport interface LogOptions {\n /** Default: `\"info\"`. Upper-cased server-side. */\n severity?: LogSeverity;\n /** Free-form structured fields persisted on the record. */\n attributes?: Record<string, unknown>;\n /**\n * Override the auto-detected trace_id. Use only when emitting on\n * behalf of a known external trace (rare).\n */\n traceId?: string;\n /** Override the auto-detected span_id. Same caveat as `traceId`. */\n spanId?: string;\n /** Logical service tag. Default: `\"morse-sdk-ts\"`. */\n serviceName?: string;\n}\n\nconst DEFAULT_SERVICE_NAME = \"morse-sdk-ts\";\n\n/**\n * Lazy-init hook injected by `index.ts`. Allows `log()` to participate\n * in env-driven auto-init (matching the behaviour of `track()` /\n * `record()`) without `log.ts` reaching into the singleton state.\n *\n * @internal\n */\nlet ensureInitialized: () => void = () => {\n /* default no-op; replaced from index.ts */\n};\n\n/** @internal */\nexport function _setEnsureInitialized(fn: () => void): void {\n ensureInitialized = fn;\n}\n\nfunction logImpl(message: string, options: LogOptions = {}): void {\n // Match Python semantics: env-driven auto-init kicks in if the SDK\n // hasn't been explicitly init()'d yet but MORSE_API_KEY is set.\n ensureInitialized();\n const transport: TransportLike | null = getTransport();\n if (transport === null) {\n // SDK not initialised — silent no-op. Matches Python behaviour\n // (`_ensure_initialized()` short-circuit).\n return;\n }\n\n // Auto-pull trace + span IDs from the active context. Re-uses the\n // exact same context primitive that `track()` / `run()` / `span()`\n // use, so a `log()` call inside an `await run(...)` callback will\n // see the active trace's IDs.\n let traceId: string | null = options.traceId ?? null;\n let spanId: string | null = options.spanId ?? null;\n if (traceId === null || spanId === null) {\n const state = getActiveTraceState();\n if (state !== null) {\n if (traceId === null) traceId = state.traceId;\n if (spanId === null && state.spanStack.length > 0) {\n spanId = state.spanStack[state.spanStack.length - 1]!.span_id;\n }\n }\n }\n\n const severity = (options.severity ?? \"info\").toUpperCase();\n const serviceName = options.serviceName ?? DEFAULT_SERVICE_NAME;\n\n // PII redaction reuses the trace path's allow-list config. Mirrors\n // the Python client's `self._redaction_config.redact_value(payload)`\n // call.\n const config = getRedactionConfig();\n const rawAttributes = options.attributes ?? {};\n const redactedAttributes = config.enabled\n ? (redactValue(rawAttributes, config) as Record<string, unknown>)\n : rawAttributes;\n const redactedBody = config.enabled\n ? (redactValue(String(message), config) as string)\n : String(message);\n\n const record = {\n timestamp: new Date().toISOString(),\n severity,\n service_name: serviceName,\n body: redactedBody,\n attributes: redactedAttributes,\n trace_id: traceId,\n span_id: spanId,\n };\n\n transport.track({ logs: [record] });\n}\n\n/**\n * Emit a log record correlated to the current trace context.\n *\n * Auto-correlates to the surrounding `morse.run()` /\n * `morse.span()` if one is active. Inside a trace, the record's\n * `trace_id` + `span_id` are filled in from `AsyncLocalStorage`;\n * outside a trace, both fields are `null` and the record is still\n * accepted by the backend (it surfaces in the service-wide Logs view\n * but not on any individual trace's Correlation panel).\n *\n * Non-blocking. Batched alongside trace events on the existing\n * transport — flushes at the SDK's configured interval (default 2s).\n * Internal errors are absorbed; this call never throws.\n *\n * Silent no-op when the SDK isn't initialised (no `MORSE_API_KEY`\n * and no explicit `init()` call).\n *\n * @example\n * ```ts\n * import { init, runTraced, log } from \"@morsehq-dev/sdk\";\n *\n * init({ apiKey: process.env.MORSE_API_KEY });\n *\n * await runTraced({ agentName: \"lead-qualifier\" }, async () => {\n * log(\"starting search\", { attributes: { query: \"morse\" } });\n * const results = await search();\n * log(\"search complete\", {\n * severity: \"info\",\n * attributes: { result_count: results.length },\n * });\n * });\n * ```\n */\nexport const log = absorbErrorsSync(logImpl, {\n fingerprint: \"morse.log\",\n});\n"]}
@@ -120,53 +120,6 @@ var init_env = __esm({
120
120
  }
121
121
  });
122
122
 
123
- // src/_internal/otel-provider.browser.ts
124
- function noteBrowserRuntime() {
125
- if (warned) return;
126
- warned = true;
127
- try {
128
- console.info(
129
- "[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."
130
- );
131
- } catch {
132
- }
133
- }
134
- function getEngine() {
135
- return engine;
136
- }
137
- function withOtelSpanContext(traceIdHex, spanIdHex, fn) {
138
- return fn();
139
- }
140
- var warned, OtelEngine, engine;
141
- var init_otel_provider_browser = __esm({
142
- "src/_internal/otel-provider.browser.ts"() {
143
- warned = false;
144
- OtelEngine = class {
145
- // Params are declared (not dropped) so this class stays signature-compatible
146
- // with the real `OtelEngine` — the build swaps the modules, but anything
147
- // type-checking against this one must see the same shape. `void x` marks the
148
- // deliberate non-use for @typescript-eslint/no-unused-vars.
149
- configure(opts) {
150
- noteBrowserRuntime();
151
- }
152
- shutdown() {
153
- }
154
- resetForTesting() {
155
- warned = false;
156
- }
157
- async flush() {
158
- }
159
- resolveSampled(traceIdHex) {
160
- return true;
161
- }
162
- registerInstrumentations(instrumentations) {
163
- return null;
164
- }
165
- };
166
- engine = new OtelEngine();
167
- }
168
- });
169
-
170
123
  // src/_internal/redaction.ts
171
124
  function buildRedactionConfig(options) {
172
125
  const opts = options ?? {};
@@ -355,6 +308,377 @@ var init_redaction = __esm({
355
308
  }
356
309
  });
357
310
 
311
+ // src/_internal/diagnostics.ts
312
+ function setRedactionConfig(config) {
313
+ activeRedactionConfig = config;
314
+ }
315
+ function setLevel(raw) {
316
+ if (!raw) return;
317
+ const value = String(raw).trim().toLowerCase();
318
+ if (!VALID_LEVELS.has(value)) return;
319
+ level = value;
320
+ }
321
+ function transmissionAllowed() {
322
+ if (isTelemetryDisabled() || isDisabled()) return false;
323
+ return level !== LEVEL_OFF;
324
+ }
325
+ function checkBucket(buckets, key, limit, windowMs) {
326
+ const now = Date.now();
327
+ const bucket = buckets.get(key) ?? [];
328
+ const cutoff = now - windowMs;
329
+ while (bucket.length > 0 && bucket[0] < cutoff) bucket.shift();
330
+ if (bucket.length >= limit) {
331
+ buckets.set(key, bucket);
332
+ return false;
333
+ }
334
+ bucket.push(now);
335
+ buckets.set(key, bucket);
336
+ return true;
337
+ }
338
+ function checkRateLimit(fingerprint) {
339
+ const limit = level === LEVEL_DEBUG ? RATE_LIMIT_PER_WINDOW_DEBUG : RATE_LIMIT_PER_WINDOW;
340
+ return checkBucket(rateBuckets, fingerprint, limit, RATE_WINDOW_MS);
341
+ }
342
+ function isMorseFrame(line) {
343
+ return MORSE_PATH_MARKERS.some((marker) => line.includes(marker));
344
+ }
345
+ function parseFrame(line) {
346
+ const withParens = /^\s*at\s+(.+?)\s+\((.+?):(\d+):(\d+)\)\s*$/.exec(line);
347
+ if (withParens) {
348
+ return {
349
+ fn: withParens[1],
350
+ file: withParens[2],
351
+ lineNo: Number(withParens[3])
352
+ };
353
+ }
354
+ const bare = /^\s*at\s+(.+?):(\d+):(\d+)\s*$/.exec(line);
355
+ if (bare) return { file: bare[1], lineNo: Number(bare[2]) };
356
+ return {};
357
+ }
358
+ function buildScopedStack(error) {
359
+ const frames = [];
360
+ try {
361
+ const stack = error instanceof Error ? error.stack ?? "" : "";
362
+ if (!stack) return frames;
363
+ let elided = 0;
364
+ for (const raw of stack.split("\n")) {
365
+ if (!raw.trim().startsWith("at ")) continue;
366
+ if (isMorseFrame(raw)) {
367
+ if (elided > 0) {
368
+ frames.push({ elided });
369
+ elided = 0;
370
+ }
371
+ const { file, lineNo, fn } = parseFrame(raw);
372
+ const frame = {};
373
+ if (file) frame.file = file.split(/[\\/]/).slice(-3).join("/");
374
+ if (typeof lineNo === "number" && !Number.isNaN(lineNo)) frame.line = lineNo;
375
+ if (fn) frame.function = fn.slice(0, 255);
376
+ frames.push(frame);
377
+ } else {
378
+ elided += 1;
379
+ }
380
+ }
381
+ if (elided > 0) frames.push({ elided });
382
+ } catch {
383
+ }
384
+ return frames.length > MAX_STACK_ENTRIES ? frames.slice(-MAX_STACK_ENTRIES) : frames;
385
+ }
386
+ function redactedMessage(error) {
387
+ let raw;
388
+ try {
389
+ raw = error instanceof Error ? error.message : String(error);
390
+ } catch {
391
+ return "";
392
+ }
393
+ try {
394
+ if (activeRedactionConfig) {
395
+ const out = redactValue(raw, activeRedactionConfig);
396
+ raw = typeof out === "string" ? out : String(out);
397
+ }
398
+ } catch {
399
+ return "<redaction unavailable>";
400
+ }
401
+ return raw.slice(0, MAX_MESSAGE_CHARS);
402
+ }
403
+ function scrubExtra(extra) {
404
+ const out = {};
405
+ if (!extra) return out;
406
+ for (const [key, value] of Object.entries(extra)) {
407
+ if (ALLOWED_EXTRA_KEYS.has(key) && value != null) {
408
+ out[key] = String(value).slice(0, 255);
409
+ }
410
+ }
411
+ return out;
412
+ }
413
+ function recordDrop(reason, category, quantity = 1) {
414
+ try {
415
+ if (quantity <= 0) return;
416
+ const key = `${reason}:${category}`;
417
+ const existing = counters.get(key);
418
+ if (existing) existing.quantity += quantity;
419
+ else counters.set(key, { reason, category, quantity });
420
+ if (checkBucket(localLogBuckets, `drop:${key}`, LOCAL_LOG_LIMIT_PER_WINDOW, LOCAL_LOG_WINDOW_MS)) {
421
+ console.warn(`morse: dropped ${quantity} ${category} (${reason}) \u2014 telemetry is being lost`);
422
+ }
423
+ } catch {
424
+ }
425
+ }
426
+ function drainCounters() {
427
+ if (counters.size === 0) return [];
428
+ const drained = [...counters.values()];
429
+ counters.clear();
430
+ return drained;
431
+ }
432
+ function report(error, options) {
433
+ if (reporting) return;
434
+ reporting = true;
435
+ try {
436
+ const errClass = error instanceof Error ? error.name : "Error";
437
+ const errMessage = error instanceof Error ? error.message : String(error);
438
+ if (checkBucket(
439
+ localLogBuckets,
440
+ options.fingerprint,
441
+ LOCAL_LOG_LIMIT_PER_WINDOW,
442
+ LOCAL_LOG_WINDOW_MS
443
+ )) {
444
+ const line = `morse internal error [${options.fingerprint}]: ${errClass}: ${errMessage}`;
445
+ if (isDebug()) console.error(line, error);
446
+ else console.warn(line);
447
+ }
448
+ if (!transmissionAllowed()) return;
449
+ if (!checkRateLimit(options.fingerprint)) return;
450
+ enqueue({
451
+ kind: "error",
452
+ fingerprint: options.fingerprint.slice(0, 255),
453
+ error_type: errClass.slice(0, 255),
454
+ message: redactedMessage(error),
455
+ stack: buildScopedStack(error),
456
+ sdk_language: "typescript",
457
+ sdk_version: sdkVersion(),
458
+ runtime_version: runtimeVersion(),
459
+ platform: platformLabel(),
460
+ extra: scrubExtra(options.extra)
461
+ });
462
+ } catch {
463
+ } finally {
464
+ reporting = false;
465
+ }
466
+ }
467
+ function sdkVersion() {
468
+ return SDK_VERSION;
469
+ }
470
+ function runtimeVersion() {
471
+ try {
472
+ const proc = globalThis.process;
473
+ return proc?.version ? String(proc.version) : "";
474
+ } catch {
475
+ return "";
476
+ }
477
+ }
478
+ function platformLabel() {
479
+ try {
480
+ const proc = globalThis.process;
481
+ if (proc?.platform) return `${proc.platform}-${proc.arch ?? ""}`.slice(0, 128);
482
+ return "browser";
483
+ } catch {
484
+ return "";
485
+ }
486
+ }
487
+ function enqueue(event) {
488
+ pending.push(event);
489
+ while (pending.length > MAX_PENDING) pending.shift();
490
+ ensureTimer();
491
+ }
492
+ function ensureTimer() {
493
+ if (timer !== null) return;
494
+ try {
495
+ timer = setInterval(() => {
496
+ void flushOnce();
497
+ }, FLUSH_INTERVAL_MS);
498
+ timer?.unref?.();
499
+ } catch {
500
+ timer = null;
501
+ }
502
+ }
503
+ function breakerBlocks() {
504
+ return breakerOpenUntil > 0 && Date.now() < breakerOpenUntil;
505
+ }
506
+ function recordResult(ok) {
507
+ if (ok) {
508
+ consecutiveFailures = 0;
509
+ breakerOpenUntil = 0;
510
+ return;
511
+ }
512
+ consecutiveFailures += 1;
513
+ if (consecutiveFailures >= BREAKER_THRESHOLD) {
514
+ breakerOpenUntil = Date.now() + BREAKER_COOLDOWN_MS;
515
+ }
516
+ }
517
+ async function flushOnce() {
518
+ try {
519
+ const batch = pending.splice(0, MAX_BATCH_EVENTS);
520
+ const drained = drainCounters();
521
+ if (drained.length > 0) {
522
+ batch.push({
523
+ kind: "counters",
524
+ fingerprint: "morse.transport.delivery",
525
+ counters: drained,
526
+ sdk_language: "typescript",
527
+ sdk_version: sdkVersion()
528
+ });
529
+ }
530
+ if (batch.length === 0) return;
531
+ if (breakerBlocks() || !transmissionAllowed()) return;
532
+ const target = resolveTarget();
533
+ if (target === null) return;
534
+ let response;
535
+ try {
536
+ response = await fetch(target.url, {
537
+ method: "POST",
538
+ headers: {
539
+ Authorization: `Bearer ${target.apiKey}`,
540
+ "Content-Type": "application/json"
541
+ },
542
+ body: JSON.stringify({ events: batch })
543
+ });
544
+ } catch {
545
+ recordResult(false);
546
+ return;
547
+ }
548
+ setLevel(response.headers.get("X-Morse-Diagnostics"));
549
+ recordResult(response.ok);
550
+ } catch {
551
+ }
552
+ }
553
+ function resolveTarget() {
554
+ try {
555
+ const apiKey = getApiKey();
556
+ if (!apiKey) return null;
557
+ const url = deriveDiagnosticsUrl(String(getEndpoint() ?? ""));
558
+ if (!url) return null;
559
+ return { apiKey: String(apiKey), url };
560
+ } catch {
561
+ return null;
562
+ }
563
+ }
564
+ function deriveDiagnosticsUrl(tracesEndpoint) {
565
+ try {
566
+ const parsed = new URL(tracesEndpoint);
567
+ return `${parsed.protocol}//${parsed.host}${DIAGNOSTICS_PATH}`;
568
+ } catch {
569
+ return null;
570
+ }
571
+ }
572
+ function _resetForTesting() {
573
+ rateBuckets.clear();
574
+ localLogBuckets.clear();
575
+ counters.clear();
576
+ pending = [];
577
+ if (timer !== null) {
578
+ clearInterval(timer);
579
+ timer = null;
580
+ }
581
+ consecutiveFailures = 0;
582
+ breakerOpenUntil = 0;
583
+ reporting = false;
584
+ level = LEVEL_ERROR;
585
+ activeRedactionConfig = null;
586
+ }
587
+ 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; exports.REASON_QUEUE_FULL = void 0; exports.REASON_RETRY_EXHAUSTED = void 0; exports.REASON_QUOTA_REJECTED = void 0; exports.REASON_SHUTDOWN_DROP = void 0; var counters, activeRedactionConfig, pending, timer, consecutiveFailures, breakerOpenUntil, reporting, MORSE_PATH_MARKERS;
588
+ var init_diagnostics = __esm({
589
+ "src/_internal/diagnostics.ts"() {
590
+ init_env();
591
+ init_redaction();
592
+ SDK_VERSION = "0.5.0-rc.1" ;
593
+ LEVEL_OFF = "off";
594
+ LEVEL_ERROR = "error";
595
+ LEVEL_DEBUG = "debug";
596
+ VALID_LEVELS = /* @__PURE__ */ new Set([LEVEL_OFF, LEVEL_ERROR, LEVEL_DEBUG]);
597
+ level = LEVEL_ERROR;
598
+ RATE_WINDOW_MS = 6e4;
599
+ RATE_LIMIT_PER_WINDOW = 100;
600
+ RATE_LIMIT_PER_WINDOW_DEBUG = 1e3;
601
+ rateBuckets = /* @__PURE__ */ new Map();
602
+ LOCAL_LOG_WINDOW_MS = 6e4;
603
+ LOCAL_LOG_LIMIT_PER_WINDOW = 10;
604
+ localLogBuckets = /* @__PURE__ */ new Map();
605
+ MAX_STACK_ENTRIES = 64;
606
+ MAX_MESSAGE_CHARS = 4096;
607
+ MAX_BATCH_EVENTS = 32;
608
+ ALLOWED_EXTRA_KEYS = /* @__PURE__ */ new Set([
609
+ "adapter",
610
+ "module",
611
+ "function",
612
+ "operation",
613
+ "endpoint_host"
614
+ ]);
615
+ DIAGNOSTICS_PATH = "/api/v1/diagnostics/sdk";
616
+ MAX_PENDING = 100;
617
+ FLUSH_INTERVAL_MS = 5e3;
618
+ BREAKER_THRESHOLD = 3;
619
+ BREAKER_COOLDOWN_MS = 3e5;
620
+ exports.REASON_QUEUE_FULL = "queue_full";
621
+ exports.REASON_RETRY_EXHAUSTED = "retry_exhausted";
622
+ exports.REASON_QUOTA_REJECTED = "quota_rejected";
623
+ exports.REASON_SHUTDOWN_DROP = "shutdown_drop";
624
+ counters = /* @__PURE__ */ new Map();
625
+ activeRedactionConfig = null;
626
+ pending = [];
627
+ timer = null;
628
+ consecutiveFailures = 0;
629
+ breakerOpenUntil = 0;
630
+ reporting = false;
631
+ MORSE_PATH_MARKERS = ["@morsehq/sdk", "morse-sdk", "/morse/", "morse_ai"];
632
+ }
633
+ });
634
+
635
+ // src/_internal/otel-provider.browser.ts
636
+ function noteBrowserRuntime() {
637
+ if (warned) return;
638
+ warned = true;
639
+ try {
640
+ console.info(
641
+ "[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."
642
+ );
643
+ } catch {
644
+ }
645
+ }
646
+ function getEngine() {
647
+ return engine;
648
+ }
649
+ function withOtelSpanContext(traceIdHex, spanIdHex, fn) {
650
+ return fn();
651
+ }
652
+ var warned, OtelEngine, engine;
653
+ var init_otel_provider_browser = __esm({
654
+ "src/_internal/otel-provider.browser.ts"() {
655
+ warned = false;
656
+ OtelEngine = class {
657
+ // Params are declared (not dropped) so this class stays signature-compatible
658
+ // with the real `OtelEngine` — the build swaps the modules, but anything
659
+ // type-checking against this one must see the same shape. `void x` marks the
660
+ // deliberate non-use for @typescript-eslint/no-unused-vars.
661
+ configure(opts) {
662
+ noteBrowserRuntime();
663
+ }
664
+ shutdown() {
665
+ }
666
+ resetForTesting() {
667
+ warned = false;
668
+ }
669
+ async flush() {
670
+ }
671
+ resolveSampled(traceIdHex) {
672
+ return true;
673
+ }
674
+ registerInstrumentations(instrumentations) {
675
+ return null;
676
+ }
677
+ };
678
+ engine = new OtelEngine();
679
+ }
680
+ });
681
+
358
682
  // src/_internal/spans.ts
359
683
  function generateTraceId() {
360
684
  return randomHex(32);
@@ -455,8 +779,9 @@ function setTransport(t) {
455
779
  function getTransport() {
456
780
  return transport;
457
781
  }
458
- function setRedactionConfig(config) {
782
+ function setRedactionConfig2(config) {
459
783
  redactionConfig = config;
784
+ setRedactionConfig(config);
460
785
  }
461
786
  function getRedactionConfig() {
462
787
  return redactionConfig;
@@ -545,8 +870,15 @@ function buildTraceDict(state, rootSpan) {
545
870
  spans: spans.map((s) => redactSpanDict(s, config))
546
871
  };
547
872
  const effectiveSource = state.sourceOverride || _source;
873
+ const resource = {};
548
874
  if (effectiveSource) {
549
- out.resource = { "morse_ai.source": effectiveSource };
875
+ resource["morse_ai.source"] = effectiveSource;
876
+ }
877
+ if (state.framework) {
878
+ resource["morse_ai.framework"] = state.framework;
879
+ }
880
+ if (Object.keys(resource).length > 0) {
881
+ out.resource = resource;
550
882
  }
551
883
  return out;
552
884
  }
@@ -763,7 +1095,7 @@ async function spanAsync(opts, fn) {
763
1095
  throw err;
764
1096
  }
765
1097
  }
766
- function _resetForTesting() {
1098
+ function _resetForTesting2() {
767
1099
  browserState = null;
768
1100
  lastTrace = null;
769
1101
  redactionConfig = buildRedactionConfig();
@@ -773,6 +1105,7 @@ var init_tracing = __esm({
773
1105
  "src/_internal/tracing.ts"() {
774
1106
  init_env();
775
1107
  init_otel_provider_browser();
1108
+ init_diagnostics();
776
1109
  init_redaction();
777
1110
  init_spans();
778
1111
  als = null;
@@ -891,6 +1224,7 @@ var init_propagation = __esm({
891
1224
  });
892
1225
 
893
1226
  exports._resetForTesting = _resetForTesting;
1227
+ exports._resetForTesting2 = _resetForTesting2;
894
1228
  exports.buildRedactionConfig = buildRedactionConfig;
895
1229
  exports.buildTraceEntry = buildTraceEntry;
896
1230
  exports.extractTraceparent = extractTraceparent;
@@ -910,6 +1244,7 @@ exports.getMaxQueueSize = getMaxQueueSize;
910
1244
  exports.getRedactionConfig = getRedactionConfig;
911
1245
  exports.getSampleRate = getSampleRate;
912
1246
  exports.getTransport = getTransport;
1247
+ exports.init_diagnostics = init_diagnostics;
913
1248
  exports.init_env = init_env;
914
1249
  exports.init_otel_provider_browser = init_otel_provider_browser;
915
1250
  exports.init_propagation = init_propagation;
@@ -918,21 +1253,22 @@ exports.init_spans = init_spans;
918
1253
  exports.init_tracing = init_tracing;
919
1254
  exports.injectIntoRequestInit = injectIntoRequestInit;
920
1255
  exports.injectTraceparent = injectTraceparent;
921
- exports.isDebug = isDebug;
922
1256
  exports.isDisabled = isDisabled;
923
- exports.isTelemetryDisabled = isTelemetryDisabled;
924
1257
  exports.isValidInternalSource = isValidInternalSource;
925
1258
  exports.nowIso = nowIso;
1259
+ exports.recordDrop = recordDrop;
926
1260
  exports.redactValue = redactValue;
1261
+ exports.report = report;
927
1262
  exports.runAsync = runAsync;
928
1263
  exports.runSync = runSync;
929
1264
  exports.sendTrace = sendTrace;
930
1265
  exports.setContext = setContext;
931
- exports.setRedactionConfig = setRedactionConfig;
1266
+ exports.setLevel = setLevel;
1267
+ exports.setRedactionConfig = setRedactionConfig2;
932
1268
  exports.setSource = setSource;
933
1269
  exports.setTransport = setTransport;
934
1270
  exports.spanAsync = spanAsync;
935
1271
  exports.spanSync = spanSync;
936
1272
  exports.startSpan = startSpan;
937
- //# sourceMappingURL=chunk-DXWHT3HK.cjs.map
938
- //# sourceMappingURL=chunk-DXWHT3HK.cjs.map
1273
+ //# sourceMappingURL=chunk-ZGYZZCUK.cjs.map
1274
+ //# sourceMappingURL=chunk-ZGYZZCUK.cjs.map