@morsehq-dev/sdk 0.5.0-rc.3 → 0.5.0-rc.5

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 (108) hide show
  1. package/README.md +51 -12
  2. package/dist/anthropic/index.cjs +11 -11
  3. package/dist/anthropic/index.js +4 -4
  4. package/dist/anthropic-agent-sdk/index.cjs +157 -102
  5. package/dist/anthropic-agent-sdk/index.cjs.map +1 -1
  6. package/dist/anthropic-agent-sdk/index.d.cts +57 -34
  7. package/dist/anthropic-agent-sdk/index.d.ts +57 -34
  8. package/dist/anthropic-agent-sdk/index.js +126 -72
  9. package/dist/anthropic-agent-sdk/index.js.map +1 -1
  10. package/dist/browser/anthropic/index.cjs +11 -11
  11. package/dist/browser/anthropic/index.js +4 -4
  12. package/dist/browser/anthropic-agent-sdk/index.cjs +157 -102
  13. package/dist/browser/anthropic-agent-sdk/index.cjs.map +1 -1
  14. package/dist/browser/anthropic-agent-sdk/index.js +126 -72
  15. package/dist/browser/anthropic-agent-sdk/index.js.map +1 -1
  16. package/dist/browser/{chunk-KFWCOUL3.cjs → chunk-26Q2QD5J.cjs} +5 -5
  17. package/dist/browser/{chunk-KFWCOUL3.cjs.map → chunk-26Q2QD5J.cjs.map} +1 -1
  18. package/dist/browser/{chunk-QCI2ZDQS.cjs → chunk-47GVOQB4.cjs} +12 -12
  19. package/dist/browser/{chunk-QCI2ZDQS.cjs.map → chunk-47GVOQB4.cjs.map} +1 -1
  20. package/dist/browser/{chunk-LGG5PL5U.js → chunk-64YI3IZS.js} +3 -3
  21. package/dist/browser/{chunk-LGG5PL5U.js.map → chunk-64YI3IZS.js.map} +1 -1
  22. package/dist/{chunk-HCEKAVDR.js → browser/chunk-CI7M2GHD.js} +4 -4
  23. package/dist/browser/{chunk-KGSLJLWW.js.map → chunk-CI7M2GHD.js.map} +1 -1
  24. package/dist/browser/{chunk-MI4OUWUZ.js → chunk-EH326H6U.js} +3 -3
  25. package/dist/browser/{chunk-MI4OUWUZ.js.map → chunk-EH326H6U.js.map} +1 -1
  26. package/dist/browser/{chunk-WUQXNRD3.js → chunk-GLL57K7P.js} +3 -3
  27. package/dist/browser/{chunk-WUQXNRD3.js.map → chunk-GLL57K7P.js.map} +1 -1
  28. package/dist/browser/{chunk-PM5D6VXF.cjs → chunk-IHIS62VS.cjs} +5 -4
  29. package/dist/browser/chunk-IHIS62VS.cjs.map +1 -0
  30. package/dist/browser/{chunk-N4Q2WMOE.js → chunk-MIB3EOC4.js} +5 -5
  31. package/dist/browser/{chunk-N4Q2WMOE.js.map → chunk-MIB3EOC4.js.map} +1 -1
  32. package/dist/browser/{chunk-P7XWSMFX.cjs → chunk-QAFFDJFK.cjs} +6 -6
  33. package/dist/browser/{chunk-P7XWSMFX.cjs.map → chunk-QAFFDJFK.cjs.map} +1 -1
  34. package/dist/{chunk-7PGR4NJG.js → browser/chunk-UL5TNXQL.js} +4 -4
  35. package/dist/browser/{chunk-MOBYR3AP.js.map → chunk-UL5TNXQL.js.map} +1 -1
  36. package/dist/browser/{chunk-Y3BOPSM3.js → chunk-V7AUPQIJ.js} +5 -5
  37. package/dist/browser/chunk-V7AUPQIJ.js.map +1 -0
  38. package/dist/browser/{chunk-VSG4EWNL.cjs → chunk-WGWPCVYB.cjs} +18 -18
  39. package/dist/browser/{chunk-VSG4EWNL.cjs.map → chunk-WGWPCVYB.cjs.map} +1 -1
  40. package/dist/browser/{chunk-YSJVJ3Z3.cjs → chunk-WR2SQLKP.cjs} +7 -7
  41. package/dist/browser/{chunk-YSJVJ3Z3.cjs.map → chunk-WR2SQLKP.cjs.map} +1 -1
  42. package/dist/browser/{chunk-XLQSSJUZ.cjs → chunk-ZVVUZRG7.cjs} +15 -15
  43. package/dist/browser/{chunk-XLQSSJUZ.cjs.map → chunk-ZVVUZRG7.cjs.map} +1 -1
  44. package/dist/browser/index.cjs +91 -90
  45. package/dist/browser/index.cjs.map +1 -1
  46. package/dist/browser/index.js +9 -8
  47. package/dist/browser/index.js.map +1 -1
  48. package/dist/browser/integrations/pino.cjs +4 -4
  49. package/dist/browser/integrations/pino.js +3 -3
  50. package/dist/browser/langchain/index.cjs +17 -17
  51. package/dist/browser/langchain/index.js +2 -2
  52. package/dist/browser/langgraph/index.cjs +27 -27
  53. package/dist/browser/langgraph/index.js +5 -5
  54. package/dist/browser/openai/index.cjs +11 -11
  55. package/dist/browser/openai/index.js +2 -2
  56. package/dist/browser/openai-agents/index.cjs +34 -34
  57. package/dist/browser/openai-agents/index.js +4 -4
  58. package/dist/browser/vercel-ai/index.cjs +14 -14
  59. package/dist/browser/vercel-ai/index.js +3 -3
  60. package/dist/{browser/chunk-KGSLJLWW.js → chunk-7I4ILCLY.js} +4 -4
  61. package/dist/{chunk-HCEKAVDR.js.map → chunk-7I4ILCLY.js.map} +1 -1
  62. package/dist/{chunk-3XQOZXJM.cjs → chunk-DGBQ3UI6.cjs} +7 -7
  63. package/dist/{chunk-3XQOZXJM.cjs.map → chunk-DGBQ3UI6.cjs.map} +1 -1
  64. package/dist/{chunk-YQ6ZA7OE.cjs → chunk-DPW4W7H7.cjs} +18 -18
  65. package/dist/{chunk-YQ6ZA7OE.cjs.map → chunk-DPW4W7H7.cjs.map} +1 -1
  66. package/dist/{chunk-E3G3IE6Y.cjs → chunk-DQ4T2MJE.cjs} +5 -4
  67. package/dist/chunk-DQ4T2MJE.cjs.map +1 -0
  68. package/dist/{chunk-XZRJXJFA.js → chunk-ELVBOJWY.js} +5 -5
  69. package/dist/chunk-ELVBOJWY.js.map +1 -0
  70. package/dist/{chunk-ZFE75G7S.js → chunk-HONYN2OI.js} +3 -3
  71. package/dist/{chunk-ZFE75G7S.js.map → chunk-HONYN2OI.js.map} +1 -1
  72. package/dist/{chunk-RK3JPX27.cjs → chunk-I3P5CHBV.cjs} +12 -12
  73. package/dist/{chunk-RK3JPX27.cjs.map → chunk-I3P5CHBV.cjs.map} +1 -1
  74. package/dist/{browser/chunk-MOBYR3AP.js → chunk-MNV4HASC.js} +4 -4
  75. package/dist/{chunk-7PGR4NJG.js.map → chunk-MNV4HASC.js.map} +1 -1
  76. package/dist/{chunk-XHOLQGN6.js → chunk-NR36TJMT.js} +5 -5
  77. package/dist/{chunk-XHOLQGN6.js.map → chunk-NR36TJMT.js.map} +1 -1
  78. package/dist/{chunk-T2NESDMT.js → chunk-QZDUGEIR.js} +3 -3
  79. package/dist/{chunk-T2NESDMT.js.map → chunk-QZDUGEIR.js.map} +1 -1
  80. package/dist/{chunk-TGHDV5MC.cjs → chunk-RRE2LX2A.cjs} +6 -6
  81. package/dist/{chunk-TGHDV5MC.cjs.map → chunk-RRE2LX2A.cjs.map} +1 -1
  82. package/dist/{chunk-DPGUBZVO.cjs → chunk-SJ625SQS.cjs} +15 -15
  83. package/dist/{chunk-DPGUBZVO.cjs.map → chunk-SJ625SQS.cjs.map} +1 -1
  84. package/dist/{chunk-UAJO6JM7.js → chunk-YKPZQPEW.js} +3 -3
  85. package/dist/{chunk-UAJO6JM7.js.map → chunk-YKPZQPEW.js.map} +1 -1
  86. package/dist/{chunk-NGBJJGOC.cjs → chunk-Z5MFR7UE.cjs} +5 -5
  87. package/dist/{chunk-NGBJJGOC.cjs.map → chunk-Z5MFR7UE.cjs.map} +1 -1
  88. package/dist/index.cjs +104 -98
  89. package/dist/index.cjs.map +1 -1
  90. package/dist/index.js +16 -10
  91. package/dist/index.js.map +1 -1
  92. package/dist/integrations/pino.cjs +4 -4
  93. package/dist/integrations/pino.js +3 -3
  94. package/dist/langchain/index.cjs +17 -17
  95. package/dist/langchain/index.js +2 -2
  96. package/dist/langgraph/index.cjs +27 -27
  97. package/dist/langgraph/index.js +5 -5
  98. package/dist/openai/index.cjs +11 -11
  99. package/dist/openai/index.js +2 -2
  100. package/dist/openai-agents/index.cjs +34 -34
  101. package/dist/openai-agents/index.js +4 -4
  102. package/dist/vercel-ai/index.cjs +14 -14
  103. package/dist/vercel-ai/index.js +3 -3
  104. package/package.json +14 -13
  105. package/dist/browser/chunk-PM5D6VXF.cjs.map +0 -1
  106. package/dist/browser/chunk-Y3BOPSM3.js.map +0 -1
  107. package/dist/chunk-E3G3IE6Y.cjs.map +0 -1
  108. package/dist/chunk-XZRJXJFA.js.map +0 -1
package/README.md CHANGED
@@ -83,6 +83,40 @@ installed without being wrapped.
83
83
  Each adapter is a separate subpath export so you only pull in what you
84
84
  use.
85
85
 
86
+ ### Supported versions
87
+
88
+ We verify two versions of each agent SDK — the declared floor and the
89
+ current latest. Versions between them are expected to work but are not
90
+ verified; below the floor is unsupported. Policy:
91
+ `engineering/SDK_VERSION_SUPPORT.md`.
92
+
93
+ Both ends are real checks, not lockfile trivia. `pnpm contract`
94
+ (`tests/contract/`) loads the actual installed package on every PR and
95
+ asserts the structural thing each adapter depends on — the export we patch,
96
+ the class we subclass, the function we replace. The nightly `latest-contract`
97
+ lanes in `.github/workflows/canary.yml` run the same assertions against
98
+ whatever upstream published most recently, so a breaking release surfaces the
99
+ night it ships rather than in a customer's process.
100
+
101
+ | Peer | Declared | Floor (verified per PR) | Latest (verified nightly) |
102
+ | -------------------------------- | ---------- | ----------------------- | ------------------------- |
103
+ | `ai` (Vercel AI SDK) | `>=7.0.0` | 7.0.55 | 7.0.55 |
104
+ | `openai` | `>=6.0.0` | 6.49.0 | — |
105
+ | `@anthropic-ai/sdk` | `>=0.90.0` | 0.96.0 | — |
106
+ | `@anthropic-ai/claude-agent-sdk` | `>=0.3.0` | 0.3.223 | 0.3.223 |
107
+ | `@openai/agents` | `>=0.2.0` | 0.2.1 | blocked — see below |
108
+ | `@langchain/core` | `>=1.0.0` | 1.2.5 | 1.2.5 |
109
+ | `@langchain/langgraph` | `>=1.0.0` | 1.4.9 | 1.4.9 |
110
+
111
+ Floor and latest coincide today because the pins were just raised to the
112
+ newest verified versions; they diverge again as soon as upstream ships.
113
+
114
+ `@openai/agents` is held at the `0.2.x` line deliberately: 0.5.0 and later
115
+ require peer `zod ^4`, and this monorepo is on zod 3 (MHQ-935).
116
+
117
+ `openai` and `@anthropic-ai/sdk` have no nightly `latest` lane yet — their
118
+ floors are verified per PR, but nothing watches upstream for them (MHQ-930).
119
+
86
120
  ### `@morsehq-dev/sdk/anthropic` — Anthropic Messages API
87
121
 
88
122
  ```ts
@@ -100,26 +134,31 @@ sibling `memory` span per call.
100
134
 
101
135
  ### `@morsehq-dev/sdk/anthropic-agent-sdk` — Claude Agent SDK
102
136
 
103
- Wraps `ClaudeSDKClient` from `@anthropic-ai/claude-agent-sdk`. Emits an
104
- outer **agent** span, per-call **llm** spans (with `context_segments`),
105
- **tool** spans, **subagent.spawn** spans for Task-tool fan-out, and
106
- **hook** spans for `pre_tool` / `post_tool` / `on_error` hooks.
137
+ Wrap the package's top-level `query` and call the returned function in its
138
+ place. Emits an outer **agent** span, per-call **llm** spans (with
139
+ `context_segments`), **tool** spans, **subagent.spawn** spans for Task-tool
140
+ fan-out, and **hook** spans.
107
141
 
108
142
  ```ts
109
- import { ClaudeSDKClient } from "@anthropic-ai/claude-agent-sdk";
110
- import { wrapClaudeAgentSDKWithFullInstrumentation } from "@morsehq-dev/sdk/anthropic-agent-sdk";
143
+ import { query } from "@anthropic-ai/claude-agent-sdk";
144
+ import { wrapClaudeAgentQuery } from "@morsehq-dev/sdk/anthropic-agent-sdk";
111
145
 
112
- const raw = new ClaudeSDKClient({
113
- /* ... */
114
- });
115
- const { client, dispose } = wrapClaudeAgentSDKWithFullInstrumentation(raw);
146
+ const tracedQuery = wrapClaudeAgentQuery(query);
116
147
 
117
- for await (const event of client.query("research the 2026 RLHF landscape")) {
148
+ for await (const message of tracedQuery({ prompt: "research the 2026 RLHF landscape" })) {
118
149
  // your code unchanged — spans flow to Morse as a side-effect
119
150
  }
120
- dispose();
121
151
  ```
122
152
 
153
+ The returned value is still a `Query`: `interrupt()`, `setPermissionMode()`
154
+ and every other control method are forwarded to the real one, so wrapping
155
+ costs you nothing at the call site.
156
+
157
+ Why a wrapper rather than zero-config auto-detect: the package's `query`
158
+ export is read-only and non-configurable, so there is nothing to patch in
159
+ place — the same constraint the Vercel AI adapter hit. Auto-detect notices
160
+ the package and logs a one-time hint pointing here.
161
+
123
162
  ### `@morsehq-dev/sdk/openai-agents` — OpenAI Agents SDK
124
163
 
125
164
  Wraps `Runner` from `@openai/agents`. Emits an outer **agent** span,
@@ -1,41 +1,41 @@
1
1
  'use strict';
2
2
 
3
- var chunkYQ6ZA7OE_cjs = require('../chunk-YQ6ZA7OE.cjs');
4
- require('../chunk-NGBJJGOC.cjs');
5
- require('../chunk-TGHDV5MC.cjs');
3
+ var chunkDPW4W7H7_cjs = require('../chunk-DPW4W7H7.cjs');
4
+ require('../chunk-Z5MFR7UE.cjs');
5
+ require('../chunk-RRE2LX2A.cjs');
6
6
  require('../chunk-KBWPNIH4.cjs');
7
7
  require('../chunk-HICEJ4LV.cjs');
8
- require('../chunk-E3G3IE6Y.cjs');
8
+ require('../chunk-DQ4T2MJE.cjs');
9
9
 
10
10
 
11
11
 
12
12
  Object.defineProperty(exports, "MAX_SEGMENT_CONTENT_BYTES", {
13
13
  enumerable: true,
14
- get: function () { return chunkYQ6ZA7OE_cjs.MAX_SEGMENT_CONTENT_BYTES; }
14
+ get: function () { return chunkDPW4W7H7_cjs.MAX_SEGMENT_CONTENT_BYTES; }
15
15
  });
16
16
  Object.defineProperty(exports, "_resetAnthropicInstallStateForTesting", {
17
17
  enumerable: true,
18
- get: function () { return chunkYQ6ZA7OE_cjs._resetAnthropicInstallStateForTesting; }
18
+ get: function () { return chunkDPW4W7H7_cjs._resetAnthropicInstallStateForTesting; }
19
19
  });
20
20
  Object.defineProperty(exports, "extractAnthropicSegments", {
21
21
  enumerable: true,
22
- get: function () { return chunkYQ6ZA7OE_cjs.extractAnthropicSegments; }
22
+ get: function () { return chunkDPW4W7H7_cjs.extractAnthropicSegments; }
23
23
  });
24
24
  Object.defineProperty(exports, "instrumentAnthropic", {
25
25
  enumerable: true,
26
- get: function () { return chunkYQ6ZA7OE_cjs.instrumentAnthropic; }
26
+ get: function () { return chunkDPW4W7H7_cjs.instrumentAnthropic; }
27
27
  });
28
28
  Object.defineProperty(exports, "isAnthropicWrapped", {
29
29
  enumerable: true,
30
- get: function () { return chunkYQ6ZA7OE_cjs.isAnthropicWrapped; }
30
+ get: function () { return chunkDPW4W7H7_cjs.isAnthropicWrapped; }
31
31
  });
32
32
  Object.defineProperty(exports, "uninstallAnthropic", {
33
33
  enumerable: true,
34
- get: function () { return chunkYQ6ZA7OE_cjs.uninstallAnthropic; }
34
+ get: function () { return chunkDPW4W7H7_cjs.uninstallAnthropic; }
35
35
  });
36
36
  Object.defineProperty(exports, "wrapAnthropic", {
37
37
  enumerable: true,
38
- get: function () { return chunkYQ6ZA7OE_cjs.wrapAnthropic; }
38
+ get: function () { return chunkDPW4W7H7_cjs.wrapAnthropic; }
39
39
  });
40
40
  //# sourceMappingURL=index.cjs.map
41
41
  //# sourceMappingURL=index.cjs.map
@@ -1,8 +1,8 @@
1
- export { MAX_SEGMENT_CONTENT_BYTES, _resetAnthropicInstallStateForTesting, extractAnthropicSegments, instrumentAnthropic, isAnthropicWrapped, uninstallAnthropic, wrapAnthropic } from '../chunk-XHOLQGN6.js';
2
- import '../chunk-T2NESDMT.js';
3
- import '../chunk-UAJO6JM7.js';
1
+ export { MAX_SEGMENT_CONTENT_BYTES, _resetAnthropicInstallStateForTesting, extractAnthropicSegments, instrumentAnthropic, isAnthropicWrapped, uninstallAnthropic, wrapAnthropic } from '../chunk-NR36TJMT.js';
2
+ import '../chunk-QZDUGEIR.js';
3
+ import '../chunk-YKPZQPEW.js';
4
4
  import '../chunk-XTKMUJWI.js';
5
5
  import '../chunk-4JPZV2VZ.js';
6
- import '../chunk-XZRJXJFA.js';
6
+ import '../chunk-ELVBOJWY.js';
7
7
  //# sourceMappingURL=index.js.map
8
8
  //# sourceMappingURL=index.js.map
@@ -1,19 +1,17 @@
1
1
  'use strict';
2
2
 
3
- var chunkYQ6ZA7OE_cjs = require('../chunk-YQ6ZA7OE.cjs');
4
- require('../chunk-NGBJJGOC.cjs');
5
- var chunk3XQOZXJM_cjs = require('../chunk-3XQOZXJM.cjs');
6
- var chunkDPGUBZVO_cjs = require('../chunk-DPGUBZVO.cjs');
7
- var chunkTGHDV5MC_cjs = require('../chunk-TGHDV5MC.cjs');
3
+ var chunkDPW4W7H7_cjs = require('../chunk-DPW4W7H7.cjs');
4
+ require('../chunk-Z5MFR7UE.cjs');
5
+ var chunkDGBQ3UI6_cjs = require('../chunk-DGBQ3UI6.cjs');
6
+ var chunkSJ625SQS_cjs = require('../chunk-SJ625SQS.cjs');
7
+ var chunkRRE2LX2A_cjs = require('../chunk-RRE2LX2A.cjs');
8
8
  var chunkKBWPNIH4_cjs = require('../chunk-KBWPNIH4.cjs');
9
9
  require('../chunk-HICEJ4LV.cjs');
10
- var chunkE3G3IE6Y_cjs = require('../chunk-E3G3IE6Y.cjs');
10
+ var chunkDQ4T2MJE_cjs = require('../chunk-DQ4T2MJE.cjs');
11
11
 
12
12
  // src/anthropic-agent-sdk/client-wrapper.ts
13
- chunkE3G3IE6Y_cjs.init_tracing();
13
+ chunkDQ4T2MJE_cjs.init_tracing();
14
14
  var WRAPPED_CLIENT = /* @__PURE__ */ Symbol.for("morse.anthropic-agent-sdk.wrapped");
15
- var INSTALL_SENTINEL = /* @__PURE__ */ Symbol.for("morse.anthropic-agent-sdk.installed");
16
- var ORIGINALS_SENTINEL = /* @__PURE__ */ Symbol.for("morse.anthropic-agent-sdk.originals");
17
15
  function wrapClaudeAgentSDK(client, options = {}) {
18
16
  if (!client || typeof client !== "object") return client;
19
17
  if (client[WRAPPED_CLIENT]) return client;
@@ -36,48 +34,13 @@ function wrapClaudeAgentSDK(client, options = {}) {
36
34
  });
37
35
  return wrapper;
38
36
  }
39
- var instrumentClaudeAgentSDK = chunkTGHDV5MC_cjs.absorbErrorsAsync(
40
- async (clientOrOptions = void 0, maybeOptions = {}) => {
41
- if (clientOrOptions && isClient(clientOrOptions)) {
42
- const opts2 = maybeOptions ?? {};
43
- return wrapClaudeAgentSDK(clientOrOptions, opts2);
44
- }
45
- const opts = clientOrOptions ?? {};
46
- const mod = await loadClaudeAgentSDKModule(opts.claudeAgentSdkModule);
47
- if (!mod) return false;
48
- const installed = mod[INSTALL_SENTINEL] === true;
49
- if (installed) return true;
50
- const carrier = findClientPrototypeCarrier(mod);
51
- if (!carrier) return false;
52
- const originalQuery = carrier.prototype.query;
53
- if (typeof originalQuery !== "function") return false;
54
- const patchedQuery = buildPatchedQuery(function(prompt, callOptions) {
55
- return originalQuery.call(this, prompt, callOptions);
56
- }, opts);
57
- carrier.prototype.query = patchedQuery;
58
- mod[ORIGINALS_SENTINEL] = {
59
- protoQuery: originalQuery,
60
- protoCarrier: carrier
61
- };
62
- mod[INSTALL_SENTINEL] = true;
63
- return true;
37
+ var instrumentClaudeAgentSDK = chunkRRE2LX2A_cjs.absorbErrorsAsync(
38
+ async (client = void 0, maybeOptions = {}) => {
39
+ if (client && isClient(client)) return wrapClaudeAgentSDK(client, maybeOptions);
40
+ return false;
64
41
  },
65
42
  { fingerprint: "morse.adapters.anthropic-agent-sdk.install" }
66
43
  );
67
- var uninstallClaudeAgentSDK = chunkTGHDV5MC_cjs.absorbErrorsSync(
68
- (claudeAgentSdkModule) => {
69
- if (!claudeAgentSdkModule || typeof claudeAgentSdkModule !== "object") return;
70
- const mod = claudeAgentSdkModule;
71
- if (!mod[INSTALL_SENTINEL]) return;
72
- const originals = mod[ORIGINALS_SENTINEL];
73
- if (originals?.protoCarrier && originals.protoQuery !== void 0) {
74
- originals.protoCarrier.prototype.query = originals.protoQuery;
75
- }
76
- mod[ORIGINALS_SENTINEL] = void 0;
77
- mod[INSTALL_SENTINEL] = false;
78
- },
79
- { fingerprint: "morse.adapters.anthropic-agent-sdk.uninstall" }
80
- );
81
44
  function isClaudeAgentSDKWrapped(client) {
82
45
  if (!client || typeof client !== "object") return false;
83
46
  return client[WRAPPED_CLIENT] === true;
@@ -87,36 +50,14 @@ function isClient(x) {
87
50
  const q = x.query;
88
51
  return typeof q === "function";
89
52
  }
90
- async function loadClaudeAgentSDKModule(explicit) {
91
- if (explicit && typeof explicit === "object") return explicit;
92
- try {
93
- return await Function("m", "return import(m)")("@anthropic-ai/claude-agent-sdk");
94
- } catch {
95
- return null;
96
- }
97
- }
98
- function findClientPrototypeCarrier(mod) {
99
- if (!mod || typeof mod !== "object") return null;
100
- const m = mod;
101
- const candidates = [
102
- m.ClaudeSDKClient,
103
- m.default?.ClaudeSDKClient
104
- ];
105
- for (const c of candidates) {
106
- if (c && typeof c === "function" && c.prototype && typeof c.prototype.query === "function") {
107
- return c;
108
- }
109
- }
110
- return null;
111
- }
112
53
  function buildPatchedQuery(original, options) {
113
54
  const defaultAgentName = options.defaultAgentName ?? "claude-agent-sdk";
114
55
  const defaultModel = options.defaultModel;
115
56
  return function patchedQuery(prompt, callOptions) {
116
57
  const boundOriginal = (p, o) => original.call(this, p, o);
117
58
  const model = (callOptions && typeof callOptions.model === "string" ? callOptions.model : void 0) ?? defaultModel;
118
- async function* iterateInTrace() {
119
- const handle = chunkDPGUBZVO_cjs.emitAgentSpan({
59
+ async function* iterateInTrace2() {
60
+ const handle = chunkSJ625SQS_cjs.emitAgentSpan({
120
61
  adapter: "anthropic-agent-sdk",
121
62
  agentName: defaultAgentName,
122
63
  model
@@ -139,8 +80,8 @@ function buildPatchedQuery(original, options) {
139
80
  }
140
81
  handle?.end();
141
82
  }
142
- if (chunkE3G3IE6Y_cjs.getActiveTraceState() !== null) {
143
- return iterateInTrace();
83
+ if (chunkDQ4T2MJE_cjs.getActiveTraceState() !== null) {
84
+ return iterateInTrace2();
144
85
  }
145
86
  return (async function* outerTrace() {
146
87
  const queue = [];
@@ -155,9 +96,9 @@ function buildPatchedQuery(original, options) {
155
96
  };
156
97
  }
157
98
  });
158
- const runPromise = chunkE3G3IE6Y_cjs.runAsync({ agentName: defaultAgentName }, async (runHandle) => {
99
+ const runPromise = chunkDQ4T2MJE_cjs.runAsync({ agentName: defaultAgentName }, async (runHandle) => {
159
100
  try {
160
- for await (const event of iterateInTrace()) {
101
+ for await (const event of iterateInTrace2()) {
161
102
  queue.push({ kind: "value", value: event });
162
103
  notify?.();
163
104
  }
@@ -191,10 +132,10 @@ function buildPatchedQuery(original, options) {
191
132
  }
192
133
 
193
134
  // src/_agent-sdk-common/context-propagation.ts
194
- chunkE3G3IE6Y_cjs.init_tracing();
195
- var captureParentForFanOut = chunkTGHDV5MC_cjs.absorbErrorsSync(
135
+ chunkDQ4T2MJE_cjs.init_tracing();
136
+ var captureParentForFanOut = chunkRRE2LX2A_cjs.absorbErrorsSync(
196
137
  () => {
197
- const state = chunkE3G3IE6Y_cjs.getActiveTraceState();
138
+ const state = chunkDQ4T2MJE_cjs.getActiveTraceState();
198
139
  if (state === null) return null;
199
140
  const top = state.spanStack[state.spanStack.length - 1];
200
141
  if (!top) return null;
@@ -205,13 +146,13 @@ var captureParentForFanOut = chunkTGHDV5MC_cjs.absorbErrorsSync(
205
146
  },
206
147
  { fingerprint: "agent-sdk-common.captureParentForFanOut" }
207
148
  );
208
- var emitWithPinnedParent = chunkTGHDV5MC_cjs.absorbErrorsSync(
149
+ var emitWithPinnedParent = chunkRRE2LX2A_cjs.absorbErrorsSync(
209
150
  (opts) => {
210
- const state = chunkE3G3IE6Y_cjs.getActiveTraceState();
151
+ const state = chunkDQ4T2MJE_cjs.getActiveTraceState();
211
152
  if (state === null) return null;
212
153
  const snap = opts.snapshot;
213
154
  if (!snap || snap.traceId !== state.traceId) return null;
214
- const handle = chunkE3G3IE6Y_cjs.startSpan({
155
+ const handle = chunkDQ4T2MJE_cjs.startSpan({
215
156
  name: opts.name,
216
157
  type: opts.type,
217
158
  metadata: opts.metadata
@@ -233,13 +174,13 @@ function findSpanById(state, spanId) {
233
174
  }
234
175
  return void 0;
235
176
  }
236
- var emitAsToolSibling = chunkTGHDV5MC_cjs.absorbErrorsSync(
177
+ var emitAsToolSibling = chunkRRE2LX2A_cjs.absorbErrorsSync(
237
178
  (opts) => {
238
- const state = chunkE3G3IE6Y_cjs.getActiveTraceState();
179
+ const state = chunkDQ4T2MJE_cjs.getActiveTraceState();
239
180
  if (state === null) return null;
240
181
  const tool = findSpanById(state, opts.toolSpanId);
241
182
  if (!tool) return null;
242
- const handle = chunkE3G3IE6Y_cjs.startSpan({
183
+ const handle = chunkDQ4T2MJE_cjs.startSpan({
243
184
  name: opts.name,
244
185
  type: opts.type,
245
186
  metadata: opts.metadata
@@ -250,9 +191,9 @@ var emitAsToolSibling = chunkTGHDV5MC_cjs.absorbErrorsSync(
250
191
  },
251
192
  { fingerprint: "agent-sdk-common.emitAsToolSibling" }
252
193
  );
253
- chunkTGHDV5MC_cjs.absorbErrorsSync(
194
+ chunkRRE2LX2A_cjs.absorbErrorsSync(
254
195
  () => {
255
- const state = chunkE3G3IE6Y_cjs.getActiveTraceState();
196
+ const state = chunkDQ4T2MJE_cjs.getActiveTraceState();
256
197
  if (state === null) return null;
257
198
  return {
258
199
  traceId: state.traceId,
@@ -297,7 +238,7 @@ var _handleHookEvent = (payload, options) => {
297
238
  return;
298
239
  }
299
240
  }
300
- const fallback = chunkDPGUBZVO_cjs.emitHookSpan({
241
+ const fallback = chunkSJ625SQS_cjs.emitHookSpan({
301
242
  adapter: "anthropic-agent-sdk",
302
243
  hookName: name,
303
244
  hookKind: kind,
@@ -307,7 +248,7 @@ var _handleHookEvent = (payload, options) => {
307
248
  fallback.end();
308
249
  }
309
250
  };
310
- var handleHookEvent = chunkTGHDV5MC_cjs.absorbErrorsSync(_handleHookEvent, {
251
+ var handleHookEvent = chunkRRE2LX2A_cjs.absorbErrorsSync(_handleHookEvent, {
311
252
  fingerprint: "morse.anthropic-agent-sdk.hook-instrumentation.handle"
312
253
  });
313
254
  function installHookInstrumentation(client, options) {
@@ -335,7 +276,7 @@ function installHookInstrumentation(client, options) {
335
276
  }
336
277
 
337
278
  // src/anthropic-agent-sdk/llm-instrumentation.ts
338
- chunkE3G3IE6Y_cjs.init_diagnostics();
279
+ chunkDQ4T2MJE_cjs.init_diagnostics();
339
280
  function readInputTokens(usage) {
340
281
  if (usage === void 0 || usage === null || typeof usage !== "object") return void 0;
341
282
  const base = typeof usage.input_tokens === "number" && Number.isFinite(usage.input_tokens) ? usage.input_tokens : 0;
@@ -402,7 +343,7 @@ async function* instrumentLlmCalls(events, options) {
402
343
  const reportedModel = typeof event.message?.model === "string" && event.message.model.length > 0 ? event.message.model : void 0;
403
344
  const model = reportedModel ?? fallbackModel;
404
345
  if (!model) return;
405
- const handle = chunkDPGUBZVO_cjs.emitLlmSpan({ adapter: "anthropic-agent-sdk", model });
346
+ const handle = chunkSJ625SQS_cjs.emitLlmSpan({ adapter: "anthropic-agent-sdk", model });
406
347
  if (!handle) return;
407
348
  const usage = event.message?.usage;
408
349
  const inputTokens = readInputTokens(usage);
@@ -419,7 +360,7 @@ async function* instrumentLlmCalls(events, options) {
419
360
  applyCost(handle, model, inputTokens, outputTokens, cacheWriteTokens, cachedInputTokens);
420
361
  if (requestParams !== void 0) {
421
362
  try {
422
- const segments = chunkYQ6ZA7OE_cjs.extractAnthropicSegments(
363
+ const segments = chunkDPW4W7H7_cjs.extractAnthropicSegments(
423
364
  requestParams,
424
365
  event.message
425
366
  );
@@ -442,7 +383,7 @@ async function* instrumentLlmCalls(events, options) {
442
383
  if (model === void 0 || model.length === 0) {
443
384
  return;
444
385
  }
445
- openSpan = chunkDPGUBZVO_cjs.emitLlmSpan({
386
+ openSpan = chunkSJ625SQS_cjs.emitLlmSpan({
446
387
  adapter: "anthropic-agent-sdk",
447
388
  model
448
389
  });
@@ -484,7 +425,7 @@ async function* instrumentLlmCalls(events, options) {
484
425
  }
485
426
  if (requestParams !== void 0) {
486
427
  try {
487
- const segments = chunkYQ6ZA7OE_cjs.extractAnthropicSegments(
428
+ const segments = chunkDPW4W7H7_cjs.extractAnthropicSegments(
488
429
  requestParams,
489
430
  event.message
490
431
  );
@@ -512,13 +453,13 @@ async function* instrumentLlmCalls(events, options) {
512
453
  }
513
454
  function reportSwallowed(err, fingerprint) {
514
455
  try {
515
- chunkE3G3IE6Y_cjs.report(err, { fingerprint });
456
+ chunkDQ4T2MJE_cjs.report(err, { fingerprint });
516
457
  } catch {
517
458
  }
518
459
  }
519
460
 
520
461
  // src/anthropic-agent-sdk/tool-and-subagent.ts
521
- chunkE3G3IE6Y_cjs.init_diagnostics();
462
+ chunkDQ4T2MJE_cjs.init_diagnostics();
522
463
  var ADAPTER = "anthropic-agent-sdk";
523
464
  var TASK_TOOL_NAME = "Task";
524
465
  function safeCloseFailed(handle, message) {
@@ -564,7 +505,7 @@ async function* instrumentTools(events, options) {
564
505
  tool_use_id: toolUseId
565
506
  };
566
507
  if (taskPrompt !== void 0) {
567
- metadata.task_description = chunk3XQOZXJM_cjs.summarizeToolInput(taskPrompt, inputOpts);
508
+ metadata.task_description = chunkDGBQ3UI6_cjs.summarizeToolInput(taskPrompt, inputOpts);
568
509
  }
569
510
  let handle2 = null;
570
511
  try {
@@ -586,10 +527,10 @@ async function* instrumentTools(events, options) {
586
527
  }
587
528
  let handle = null;
588
529
  try {
589
- handle = chunkDPGUBZVO_cjs.emitToolSpan({
530
+ handle = chunkSJ625SQS_cjs.emitToolSpan({
590
531
  adapter: ADAPTER,
591
532
  toolName: name,
592
- inputSummary: chunk3XQOZXJM_cjs.summarizeToolInput(event.input, inputOpts),
533
+ inputSummary: chunkDGBQ3UI6_cjs.summarizeToolInput(event.input, inputOpts),
593
534
  attributes: { tool_use_id: toolUseId }
594
535
  });
595
536
  } catch {
@@ -606,7 +547,7 @@ async function* instrumentTools(events, options) {
606
547
  open.delete(toolUseId);
607
548
  const isError = event.is_error === true;
608
549
  try {
609
- const outputSummary = chunk3XQOZXJM_cjs.summarizeToolOutput(event.content, outputOpts);
550
+ const outputSummary = chunkDGBQ3UI6_cjs.summarizeToolOutput(event.content, outputOpts);
610
551
  entry.handle.span.metadata = {
611
552
  ...entry.handle.span.metadata ?? {},
612
553
  tool_output_summary: outputSummary
@@ -678,11 +619,124 @@ async function* instrumentTools(events, options) {
678
619
  }
679
620
  function reportSwallowed2(err, fingerprint) {
680
621
  try {
681
- chunkE3G3IE6Y_cjs.report(err, { fingerprint });
622
+ chunkDQ4T2MJE_cjs.report(err, { fingerprint });
682
623
  } catch {
683
624
  }
684
625
  }
685
626
 
627
+ // src/anthropic-agent-sdk/trace-bridge.ts
628
+ chunkDQ4T2MJE_cjs.init_tracing();
629
+ function iterateInTrace(agentName, makeGenerator) {
630
+ if (chunkDQ4T2MJE_cjs.getActiveTraceState() !== null) {
631
+ return makeGenerator();
632
+ }
633
+ return (async function* outerTrace() {
634
+ const queue = [];
635
+ let notify = null;
636
+ const waitForItem = () => new Promise((resolve) => {
637
+ if (queue.length > 0) {
638
+ resolve();
639
+ } else {
640
+ notify = () => {
641
+ notify = null;
642
+ resolve();
643
+ };
644
+ }
645
+ });
646
+ const runPromise = chunkDQ4T2MJE_cjs.runAsync({ agentName }, async (runHandle) => {
647
+ try {
648
+ for await (const event of makeGenerator()) {
649
+ queue.push({ kind: "value", value: event });
650
+ notify?.();
651
+ }
652
+ runHandle.setOutcome(true);
653
+ } catch (err) {
654
+ queue.push({ kind: "error", error: err });
655
+ notify?.();
656
+ throw err;
657
+ } finally {
658
+ queue.push({ kind: "end" });
659
+ notify?.();
660
+ }
661
+ return null;
662
+ });
663
+ runPromise.catch(() => {
664
+ });
665
+ while (true) {
666
+ if (queue.length === 0) await waitForItem();
667
+ const item = queue.shift();
668
+ if (!item) continue;
669
+ if (item.kind === "value") {
670
+ yield item.value;
671
+ } else if (item.kind === "error") {
672
+ throw item.error;
673
+ } else {
674
+ return;
675
+ }
676
+ }
677
+ })();
678
+ }
679
+
680
+ // src/anthropic-agent-sdk/query-wrapper.ts
681
+ var WRAPPED = /* @__PURE__ */ Symbol.for("morse.claudeAgentQuery.wrapped");
682
+ function isClaudeAgentQueryWrapped(fn) {
683
+ return typeof fn === "function" && fn[WRAPPED] === true;
684
+ }
685
+ function wrapClaudeAgentQuery(query, options = {}) {
686
+ if (typeof query !== "function" || isClaudeAgentQueryWrapped(query)) return query;
687
+ const traced = function tracedQuery(params) {
688
+ const real = query(params);
689
+ const model = typeof params?.options?.model === "string" ? params.options.model : options.defaultModel;
690
+ let handle = null;
691
+ let opened = false;
692
+ async function* withAgentSpan() {
693
+ if (!opened) {
694
+ opened = true;
695
+ handle = chunkSJ625SQS_cjs.emitAgentSpan({
696
+ adapter: "anthropic-agent-sdk",
697
+ agentName: options.defaultAgentName ?? "claude-agent-sdk",
698
+ model
699
+ });
700
+ }
701
+ try {
702
+ for await (const message of real) {
703
+ yield message;
704
+ }
705
+ } catch (err) {
706
+ handle?.end(err);
707
+ handle = null;
708
+ throw err;
709
+ }
710
+ handle?.end();
711
+ handle = null;
712
+ }
713
+ const tapOpts = {
714
+ toolInputMaxBytes: options.toolInputMaxBytes,
715
+ toolOutputMaxBytes: options.toolOutputMaxBytes
716
+ };
717
+ const instrumented = iterateInTrace(
718
+ options.defaultAgentName ?? "claude-agent-sdk",
719
+ () => instrumentTools(
720
+ instrumentLlmCalls(withAgentSpan(), { fallbackModel: model }),
721
+ tapOpts
722
+ )
723
+ );
724
+ return new Proxy(real, {
725
+ get(target, prop, receiver) {
726
+ if (prop === Symbol.asyncIterator) return () => instrumented;
727
+ if (prop === "next" || prop === "return" || prop === "throw") {
728
+ const fn = instrumented[prop];
729
+ return typeof fn === "function" ? fn.bind(instrumented) : fn;
730
+ }
731
+ const value = Reflect.get(target, prop, receiver);
732
+ return typeof value === "function" ? value.bind(target) : value;
733
+ }
734
+ });
735
+ };
736
+ Object.defineProperty(traced, WRAPPED, { value: true, enumerable: false });
737
+ return traced;
738
+ }
739
+
686
740
  // src/anthropic-agent-sdk/index.ts
687
741
  var FULL_WRAP_SENTINEL = /* @__PURE__ */ Symbol.for("morse.anthropic-agent-sdk.full-wrapped");
688
742
  function wrapClaudeAgentSDKWithFullInstrumentation(client, options = {}) {
@@ -754,8 +808,9 @@ exports.installHookInstrumentation = installHookInstrumentation;
754
808
  exports.instrumentClaudeAgentSDK = instrumentClaudeAgentSDK;
755
809
  exports.instrumentLlmCalls = instrumentLlmCalls;
756
810
  exports.instrumentTools = instrumentTools;
811
+ exports.isClaudeAgentQueryWrapped = isClaudeAgentQueryWrapped;
757
812
  exports.isClaudeAgentSDKWrapped = isClaudeAgentSDKWrapped;
758
- exports.uninstallClaudeAgentSDK = uninstallClaudeAgentSDK;
813
+ exports.wrapClaudeAgentQuery = wrapClaudeAgentQuery;
759
814
  exports.wrapClaudeAgentSDK = wrapClaudeAgentSDK;
760
815
  exports.wrapClaudeAgentSDKWithFullInstrumentation = wrapClaudeAgentSDKWithFullInstrumentation;
761
816
  //# sourceMappingURL=index.cjs.map