@morsehq-dev/sdk 0.5.1-rc.1 → 0.6.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 (139) hide show
  1. package/dist/anthropic/index.cjs +11 -11
  2. package/dist/anthropic/index.d.cts +1 -1
  3. package/dist/anthropic/index.d.ts +1 -1
  4. package/dist/anthropic/index.js +4 -4
  5. package/dist/anthropic-agent-sdk/index.cjs +44 -40
  6. package/dist/anthropic-agent-sdk/index.cjs.map +1 -1
  7. package/dist/anthropic-agent-sdk/index.d.cts +1 -1
  8. package/dist/anthropic-agent-sdk/index.d.ts +1 -1
  9. package/dist/anthropic-agent-sdk/index.js +10 -6
  10. package/dist/anthropic-agent-sdk/index.js.map +1 -1
  11. package/dist/browser/anthropic/index.cjs +11 -11
  12. package/dist/browser/anthropic/index.js +4 -4
  13. package/dist/browser/anthropic-agent-sdk/index.cjs +44 -40
  14. package/dist/browser/anthropic-agent-sdk/index.cjs.map +1 -1
  15. package/dist/browser/anthropic-agent-sdk/index.js +10 -6
  16. package/dist/browser/anthropic-agent-sdk/index.js.map +1 -1
  17. package/dist/browser/{chunk-ZOOYJTDT.cjs → chunk-33WDUUKZ.cjs} +18 -18
  18. package/dist/browser/{chunk-ZOOYJTDT.cjs.map → chunk-33WDUUKZ.cjs.map} +1 -1
  19. package/dist/browser/{chunk-E6WORBIU.cjs → chunk-3I7IGP3P.cjs} +5 -5
  20. package/dist/browser/chunk-3I7IGP3P.cjs.map +1 -0
  21. package/dist/{chunk-FHQGPQFR.js → browser/chunk-3OYHDDOJ.js} +27 -5
  22. package/dist/browser/chunk-3OYHDDOJ.js.map +1 -0
  23. package/dist/browser/{chunk-HJTUPXNE.cjs → chunk-4IUHXUCJ.cjs} +21 -4
  24. package/dist/browser/chunk-4IUHXUCJ.cjs.map +1 -0
  25. package/dist/browser/{chunk-AX6NEG6X.js → chunk-5TYTCLKA.js} +4 -4
  26. package/dist/browser/{chunk-AX6NEG6X.js.map → chunk-5TYTCLKA.js.map} +1 -1
  27. package/dist/browser/{chunk-5IMBYZUB.js → chunk-6JHMFFPE.js} +3 -3
  28. package/dist/browser/chunk-6JHMFFPE.js.map +1 -0
  29. package/dist/{chunk-2UFTRWUS.cjs → browser/chunk-FKYI3N5N.cjs} +7 -7
  30. package/dist/browser/{chunk-FYIQARMI.cjs.map → chunk-FKYI3N5N.cjs.map} +1 -1
  31. package/dist/browser/{chunk-TIMAH323.js → chunk-FPTUHYDJ.js} +3 -3
  32. package/dist/browser/{chunk-TIMAH323.js.map → chunk-FPTUHYDJ.js.map} +1 -1
  33. package/dist/browser/{chunk-YXCWAU36.cjs → chunk-IDKQZ4X5.cjs} +38 -15
  34. package/dist/browser/chunk-IDKQZ4X5.cjs.map +1 -0
  35. package/dist/browser/{chunk-HNOHWDK3.cjs → chunk-LIP3XCTK.cjs} +12 -12
  36. package/dist/browser/{chunk-HNOHWDK3.cjs.map → chunk-LIP3XCTK.cjs.map} +1 -1
  37. package/dist/browser/{chunk-RDNSY73W.js → chunk-OUQAH27A.js} +3 -3
  38. package/dist/browser/{chunk-RDNSY73W.js.map → chunk-OUQAH27A.js.map} +1 -1
  39. package/dist/browser/{chunk-Z26QGUMP.cjs → chunk-PSNZZBQJ.cjs} +6 -6
  40. package/dist/browser/{chunk-Z26QGUMP.cjs.map → chunk-PSNZZBQJ.cjs.map} +1 -1
  41. package/dist/browser/{chunk-7G266PKE.js → chunk-PXHTLCEU.js} +21 -5
  42. package/dist/browser/chunk-PXHTLCEU.js.map +1 -0
  43. package/dist/browser/{chunk-VSHCKROM.js → chunk-TRVACYUN.js} +5 -5
  44. package/dist/browser/{chunk-VSHCKROM.js.map → chunk-TRVACYUN.js.map} +1 -1
  45. package/dist/browser/index.cjs +99 -99
  46. package/dist/browser/index.js +8 -8
  47. package/dist/browser/integrations/pino.cjs +4 -4
  48. package/dist/browser/integrations/pino.js +3 -3
  49. package/dist/browser/langchain/index.cjs +28 -26
  50. package/dist/browser/langchain/index.cjs.map +1 -1
  51. package/dist/browser/langchain/index.js +13 -11
  52. package/dist/browser/langchain/index.js.map +1 -1
  53. package/dist/browser/langgraph/index.cjs +32 -30
  54. package/dist/browser/langgraph/index.cjs.map +1 -1
  55. package/dist/browser/langgraph/index.js +10 -8
  56. package/dist/browser/langgraph/index.js.map +1 -1
  57. package/dist/browser/openai/index.cjs +11 -11
  58. package/dist/browser/openai/index.js +2 -2
  59. package/dist/browser/openai-agents/index.cjs +63 -35
  60. package/dist/browser/openai-agents/index.cjs.map +1 -1
  61. package/dist/browser/openai-agents/index.js +33 -5
  62. package/dist/browser/openai-agents/index.js.map +1 -1
  63. package/dist/browser/vercel-ai/index.cjs +14 -14
  64. package/dist/browser/vercel-ai/index.js +3 -3
  65. package/dist/{chunk-ZTBAMSCC.cjs → chunk-7DALGJL2.cjs} +72 -20
  66. package/dist/chunk-7DALGJL2.cjs.map +1 -0
  67. package/dist/{chunk-KALB7HJ5.cjs → chunk-B7TGG62X.cjs} +12 -12
  68. package/dist/{chunk-KALB7HJ5.cjs.map → chunk-B7TGG62X.cjs.map} +1 -1
  69. package/dist/{chunk-GATTHW3X.cjs → chunk-COZFARLL.cjs} +5 -5
  70. package/dist/chunk-COZFARLL.cjs.map +1 -0
  71. package/dist/{chunk-XBI4AMCW.cjs → chunk-DXTNU2KT.cjs} +38 -15
  72. package/dist/chunk-DXTNU2KT.cjs.map +1 -0
  73. package/dist/{chunk-5MJS5ECA.js → chunk-ERH3TNXZ.js} +3 -3
  74. package/dist/{chunk-5MJS5ECA.js.map → chunk-ERH3TNXZ.js.map} +1 -1
  75. package/dist/{chunk-QLJAATBR.cjs → chunk-ESJJXXB6.cjs} +6 -6
  76. package/dist/{chunk-QLJAATBR.cjs.map → chunk-ESJJXXB6.cjs.map} +1 -1
  77. package/dist/{chunk-HCN6Z56N.cjs → chunk-ETRNCI5Z.cjs} +18 -18
  78. package/dist/{chunk-HCN6Z56N.cjs.map → chunk-ETRNCI5Z.cjs.map} +1 -1
  79. package/dist/{browser/chunk-PIZVCAW7.js → chunk-GULJAURY.js} +27 -5
  80. package/dist/chunk-GULJAURY.js.map +1 -0
  81. package/dist/{chunk-YGKEP2GY.js → chunk-HJV35HWL.js} +72 -21
  82. package/dist/chunk-HJV35HWL.js.map +1 -0
  83. package/dist/{chunk-ZMRXUZ5L.js → chunk-L7AD4KUD.js} +3 -3
  84. package/dist/chunk-L7AD4KUD.js.map +1 -0
  85. package/dist/{chunk-GQVNZPRF.js → chunk-QBDTQTMN.js} +3 -3
  86. package/dist/{chunk-GQVNZPRF.js.map → chunk-QBDTQTMN.js.map} +1 -1
  87. package/dist/{browser/chunk-FYIQARMI.cjs → chunk-WG4H5JC6.cjs} +7 -7
  88. package/dist/{chunk-2UFTRWUS.cjs.map → chunk-WG4H5JC6.cjs.map} +1 -1
  89. package/dist/{chunk-62FWHZXN.js → chunk-XS4P7XPV.js} +5 -5
  90. package/dist/{chunk-62FWHZXN.js.map → chunk-XS4P7XPV.js.map} +1 -1
  91. package/dist/{chunk-4WUG3RMJ.js → chunk-YVLEDBN7.js} +4 -4
  92. package/dist/{chunk-4WUG3RMJ.js.map → chunk-YVLEDBN7.js.map} +1 -1
  93. package/dist/index.cjs +106 -106
  94. package/dist/index.cjs.map +1 -1
  95. package/dist/index.d.cts +2 -2
  96. package/dist/index.d.ts +2 -2
  97. package/dist/index.js +9 -9
  98. package/dist/index.js.map +1 -1
  99. package/dist/integrations/pino.cjs +4 -4
  100. package/dist/integrations/pino.js +3 -3
  101. package/dist/langchain/index.cjs +28 -26
  102. package/dist/langchain/index.cjs.map +1 -1
  103. package/dist/langchain/index.d.cts +3 -3
  104. package/dist/langchain/index.d.ts +3 -3
  105. package/dist/langchain/index.js +13 -11
  106. package/dist/langchain/index.js.map +1 -1
  107. package/dist/langgraph/index.cjs +32 -30
  108. package/dist/langgraph/index.cjs.map +1 -1
  109. package/dist/langgraph/index.d.cts +3 -3
  110. package/dist/langgraph/index.d.ts +3 -3
  111. package/dist/langgraph/index.js +10 -8
  112. package/dist/langgraph/index.js.map +1 -1
  113. package/dist/openai/index.cjs +11 -11
  114. package/dist/openai/index.js +2 -2
  115. package/dist/openai-agents/index.cjs +63 -35
  116. package/dist/openai-agents/index.cjs.map +1 -1
  117. package/dist/openai-agents/index.d.cts +13 -4
  118. package/dist/openai-agents/index.d.ts +13 -4
  119. package/dist/openai-agents/index.js +33 -5
  120. package/dist/openai-agents/index.js.map +1 -1
  121. package/dist/{spans-DZtMuBvc.d.cts → spans-CBMWNg2C.d.cts} +1 -0
  122. package/dist/{spans-DZtMuBvc.d.ts → spans-CBMWNg2C.d.ts} +1 -0
  123. package/dist/{tracing-J8ZgxVzU.d.ts → tracing-BMWTyexr.d.ts} +1 -1
  124. package/dist/{tracing-CNlre8TK.d.cts → tracing-Bh-cbvr6.d.cts} +1 -1
  125. package/dist/vercel-ai/index.cjs +14 -14
  126. package/dist/vercel-ai/index.js +3 -3
  127. package/package.json +1 -1
  128. package/dist/browser/chunk-5IMBYZUB.js.map +0 -1
  129. package/dist/browser/chunk-7G266PKE.js.map +0 -1
  130. package/dist/browser/chunk-E6WORBIU.cjs.map +0 -1
  131. package/dist/browser/chunk-HJTUPXNE.cjs.map +0 -1
  132. package/dist/browser/chunk-PIZVCAW7.js.map +0 -1
  133. package/dist/browser/chunk-YXCWAU36.cjs.map +0 -1
  134. package/dist/chunk-FHQGPQFR.js.map +0 -1
  135. package/dist/chunk-GATTHW3X.cjs.map +0 -1
  136. package/dist/chunk-XBI4AMCW.cjs.map +0 -1
  137. package/dist/chunk-YGKEP2GY.js.map +0 -1
  138. package/dist/chunk-ZMRXUZ5L.js.map +0 -1
  139. package/dist/chunk-ZTBAMSCC.cjs.map +0 -1
@@ -455,6 +455,7 @@ function recordDrop(reason, category, quantity = 1) {
455
455
  if (checkBucket(localLogBuckets, `drop:${key}`, LOCAL_LOG_LIMIT_PER_WINDOW, LOCAL_LOG_WINDOW_MS)) {
456
456
  console.warn(`morse: dropped ${quantity} ${category} (${reason}) \u2014 telemetry is being lost`);
457
457
  }
458
+ if (transmissionAllowed()) ensureTimer();
458
459
  } catch {
459
460
  }
460
461
  }
@@ -628,7 +629,7 @@ var init_diagnostics = __esm({
628
629
  "src/_internal/diagnostics.ts"() {
629
630
  init_env();
630
631
  init_redaction();
631
- SDK_VERSION = "0.5.1-rc.1" ;
632
+ SDK_VERSION = "0.6.0-rc.1" ;
632
633
  LEVEL_OFF = "off";
633
634
  LEVEL_ERROR = "error";
634
635
  LEVEL_DEBUG = "debug";
@@ -731,7 +732,10 @@ var init_spans = __esm({
731
732
  // MHQ-482: matches Python's `SpanType.RETRIEVER` (apps/sdk/python/src/morse_ai/spans.py).
732
733
  // @beta — retriever span type is subject to change before SDK v1.0 (see
733
734
  // the plain-LangChain adapter's on_retriever_* callbacks in src/langchain/).
734
- RETRIEVER: "retriever"
735
+ RETRIEVER: "retriever",
736
+ // MHQ-1025: matches Python's `SpanType.HANDOFF`. One span per routing
737
+ // decision between two agents, with `from_agent` / `to_agent` metadata.
738
+ HANDOFF: "handoff"
735
739
  };
736
740
  }
737
741
  });
@@ -806,6 +810,14 @@ function redactAttrValue(value, config) {
806
810
  }
807
811
  return value;
808
812
  }
813
+ function dropReasonForExportError(error) {
814
+ const code = error?.code;
815
+ if (typeof code !== "number") return exports.REASON_RETRY_EXHAUSTED;
816
+ if (code === 429) return exports.REASON_QUOTA_REJECTED;
817
+ if (code === 401 || code === 403) return exports.REASON_AUTH_REJECTED;
818
+ if (code >= 400 && code < 500) return exports.REASON_ENDPOINT_REJECTED;
819
+ return exports.REASON_SEND_FAILED;
820
+ }
809
821
  function getEngine() {
810
822
  if (engine === null) engine = new OtelEngine();
811
823
  return engine;
@@ -813,7 +825,7 @@ function getEngine() {
813
825
  function spanDictToOtelAttributes(spanDict, traceDict, resourceDict, opts) {
814
826
  const attrs = {};
815
827
  const spanType = spanDict.type;
816
- if (typeof spanType === "string" && spanType) attrs["av.span_type"] = spanType;
828
+ if (typeof spanType === "string" && spanType) attrs["morse.span_type"] = spanType;
817
829
  const model = spanDict.model;
818
830
  if (model !== void 0 && model !== null) attrs["gen_ai.request.model"] = String(model);
819
831
  const tokenFields = [
@@ -832,12 +844,12 @@ function spanDictToOtelAttributes(spanDict, traceDict, resourceDict, opts) {
832
844
  }
833
845
  const costUsd = spanDict.cost_usd;
834
846
  if (costUsd !== void 0 && costUsd !== null) {
835
- attrs["av.cost_usd"] = String(costUsd);
847
+ attrs["morse.cost_usd"] = String(costUsd);
836
848
  }
837
849
  for (const [src, otelKey] of [
838
- ["input_data", "av.input_data"],
839
- ["output_data", "av.output_data"],
840
- ["context_segments", "av.context_segments"]
850
+ ["input_data", "morse.input_data"],
851
+ ["output_data", "morse.output_data"],
852
+ ["context_segments", "morse.context_segments"]
841
853
  ]) {
842
854
  const v = spanDict[src];
843
855
  if (v !== void 0 && v !== null) {
@@ -849,35 +861,36 @@ function spanDictToOtelAttributes(spanDict, traceDict, resourceDict, opts) {
849
861
  if (metadata && typeof metadata === "object") {
850
862
  for (const [key, value] of Object.entries(metadata)) {
851
863
  const encoded = jsonCapped(value, opts.maxFieldBytes);
852
- if (encoded !== null) attrs[`av.metadata.${key}`] = encoded;
864
+ if (encoded !== null) attrs[`morse.metadata.${key}`] = encoded;
853
865
  }
854
866
  }
855
867
  const errorMessage = spanDict.error_message;
856
868
  if (opts.isRoot) {
857
869
  const threadId = traceDict.thread_id;
858
- if (threadId !== void 0 && threadId !== null) attrs["av.thread_id"] = String(threadId);
870
+ if (threadId !== void 0 && threadId !== null) attrs["morse.thread_id"] = String(threadId);
859
871
  const userId = traceDict.user_id;
860
- if (userId !== void 0 && userId !== null) attrs["av.user_id"] = String(userId);
872
+ if (userId !== void 0 && userId !== null) attrs["morse.user_id"] = String(userId);
861
873
  const userMetadata = traceDict.user_metadata;
862
874
  if (userMetadata && typeof userMetadata === "object") {
863
875
  const entries = Object.entries(userMetadata);
864
876
  if (entries.length > 0) {
865
- attrs["av.user_metadata"] = JSON.stringify(
877
+ attrs["morse.user_metadata"] = JSON.stringify(
866
878
  Object.fromEntries(entries.map(([k, v]) => [k, String(v)]))
867
879
  );
868
880
  }
869
881
  }
870
882
  const success = traceDict.success;
871
- if (success !== void 0 && success !== null) attrs["av.outcome.success"] = Boolean(success);
883
+ if (success !== void 0 && success !== null)
884
+ attrs["morse.outcome.success"] = Boolean(success);
872
885
  const outcome = traceDict.outcome;
873
- if (outcome !== void 0 && outcome !== null) attrs["av.outcome.label"] = String(outcome);
886
+ if (outcome !== void 0 && outcome !== null) attrs["morse.outcome.label"] = String(outcome);
874
887
  const framework = resourceDict["morse_ai.framework"];
875
- if (typeof framework === "string" && framework) attrs["av.framework"] = framework;
888
+ if (typeof framework === "string" && framework) attrs["morse.framework"] = framework;
876
889
  const source = resourceDict["morse_ai.source"];
877
- if (typeof source === "string" && source) attrs["av.source"] = source;
890
+ if (typeof source === "string" && source) attrs["morse.source"] = source;
878
891
  }
879
892
  if (errorMessage && spanDict.status === "failed") {
880
- attrs["av.error_message"] = String(errorMessage);
893
+ attrs["morse.error_message"] = String(errorMessage);
881
894
  }
882
895
  return attrs;
883
896
  }
@@ -969,7 +982,7 @@ function reportSwallowed(err, fingerprint) {
969
982
  } catch {
970
983
  }
971
984
  }
972
- var INSTRUMENTATION_NAME, DEFAULT_MAX_FIELD_BYTES, TRUNCATION_MARKER, contextManagerRegistered, MAX_U64, RedactingSpanExporter, RecordingSpanExporter, ResultCapturingExporter, OtelEngine, engine;
985
+ var INSTRUMENTATION_NAME, DEFAULT_MAX_FIELD_BYTES, TRUNCATION_MARKER, contextManagerRegistered, MAX_U64, RedactingSpanExporter, DropReportingExporter, RecordingSpanExporter, ResultCapturingExporter, OtelEngine, engine;
973
986
  var init_otel_provider = __esm({
974
987
  "src/_internal/otel-provider.ts"() {
975
988
  init_diagnostics();
@@ -1006,6 +1019,29 @@ var init_otel_provider = __esm({
1006
1019
  return this.inner.forceFlush ? this.inner.forceFlush() : Promise.resolve();
1007
1020
  }
1008
1021
  };
1022
+ DropReportingExporter = class {
1023
+ constructor(inner) {
1024
+ this.inner = inner;
1025
+ }
1026
+ inner;
1027
+ export(spans, resultCallback) {
1028
+ this.inner.export(spans, (result) => {
1029
+ if (result.code === core.ExportResultCode.FAILED) {
1030
+ try {
1031
+ recordDrop(dropReasonForExportError(result.error), "span", spans.length);
1032
+ } catch {
1033
+ }
1034
+ }
1035
+ resultCallback(result);
1036
+ });
1037
+ }
1038
+ shutdown() {
1039
+ return this.inner.shutdown();
1040
+ }
1041
+ forceFlush() {
1042
+ return this.inner.forceFlush ? this.inner.forceFlush() : Promise.resolve();
1043
+ }
1044
+ };
1009
1045
  RecordingSpanExporter = class {
1010
1046
  spans = [];
1011
1047
  export(spans, resultCallback) {
@@ -1072,7 +1108,10 @@ var init_otel_provider = __esm({
1072
1108
  compression: otlpExporterBase.CompressionAlgorithm.GZIP,
1073
1109
  timeoutMillis: opts.timeoutMillis
1074
1110
  });
1075
- let exporter = new RedactingSpanExporter(otlpExporter, opts.redactionConfig);
1111
+ let exporter = new RedactingSpanExporter(
1112
+ new DropReportingExporter(otlpExporter),
1113
+ opts.redactionConfig
1114
+ );
1076
1115
  if (opts.resultSink) {
1077
1116
  exporter = new ResultCapturingExporter(exporter, opts.resultSink);
1078
1117
  }
@@ -1490,6 +1529,18 @@ function setContext(dims) {
1490
1529
  if (state.userMetadata === void 0) state.userMetadata = {};
1491
1530
  Object.assign(state.userMetadata, coerceDims(dims, "morse.tracing.set_context"));
1492
1531
  }
1532
+ function adoptThreadId(value) {
1533
+ const state = getActiveTraceState();
1534
+ if (state === null || state.threadId !== void 0 || value === null || value === void 0) {
1535
+ return;
1536
+ }
1537
+ try {
1538
+ const s = String(value);
1539
+ if (s !== "") state.threadId = s;
1540
+ } catch (err) {
1541
+ report(err, { fingerprint: "morse.tracing.adopt_thread_id" });
1542
+ }
1543
+ }
1493
1544
  function coerceDims(dims, fingerprint) {
1494
1545
  const out = {};
1495
1546
  for (const k of Object.keys(dims)) {
@@ -1692,6 +1743,7 @@ var init_propagation = __esm({
1692
1743
 
1693
1744
  exports._resetForTesting = _resetForTesting;
1694
1745
  exports._resetForTesting2 = _resetForTesting2;
1746
+ exports.adoptThreadId = adoptThreadId;
1695
1747
  exports.buildRedactionConfig = buildRedactionConfig;
1696
1748
  exports.buildTraceEntry = buildTraceEntry;
1697
1749
  exports.extractTraceparent = extractTraceparent;
@@ -1741,5 +1793,5 @@ exports.setTransport = setTransport;
1741
1793
  exports.spanAsync = spanAsync;
1742
1794
  exports.spanSync = spanSync;
1743
1795
  exports.startSpan = startSpan;
1744
- //# sourceMappingURL=chunk-ZTBAMSCC.cjs.map
1745
- //# sourceMappingURL=chunk-ZTBAMSCC.cjs.map
1796
+ //# sourceMappingURL=chunk-7DALGJL2.cjs.map
1797
+ //# sourceMappingURL=chunk-7DALGJL2.cjs.map