@morsehq-dev/sdk 0.5.0-rc.4 → 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 (106) hide show
  1. package/README.md +17 -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-VOZBYSWK.cjs → chunk-26Q2QD5J.cjs} +5 -5
  17. package/dist/browser/{chunk-VOZBYSWK.cjs.map → chunk-26Q2QD5J.cjs.map} +1 -1
  18. package/dist/browser/{chunk-36QTJJT7.cjs → chunk-47GVOQB4.cjs} +12 -12
  19. package/dist/browser/{chunk-36QTJJT7.cjs.map → chunk-47GVOQB4.cjs.map} +1 -1
  20. package/dist/browser/{chunk-E2OVLWAF.js → chunk-64YI3IZS.js} +3 -3
  21. package/dist/browser/{chunk-E2OVLWAF.js.map → chunk-64YI3IZS.js.map} +1 -1
  22. package/dist/browser/{chunk-JR6JN7IZ.js → chunk-CI7M2GHD.js} +4 -4
  23. package/dist/browser/{chunk-JR6JN7IZ.js.map → chunk-CI7M2GHD.js.map} +1 -1
  24. package/dist/browser/{chunk-WIWUEI5Z.js → chunk-EH326H6U.js} +3 -3
  25. package/dist/browser/{chunk-WIWUEI5Z.js.map → chunk-EH326H6U.js.map} +1 -1
  26. package/dist/browser/{chunk-KXVSMY6L.js → chunk-GLL57K7P.js} +3 -3
  27. package/dist/browser/{chunk-KXVSMY6L.js.map → chunk-GLL57K7P.js.map} +1 -1
  28. package/dist/browser/{chunk-3H2OJLC2.cjs → chunk-IHIS62VS.cjs} +4 -4
  29. package/dist/browser/chunk-IHIS62VS.cjs.map +1 -0
  30. package/dist/browser/{chunk-PIWO5L5N.js → chunk-MIB3EOC4.js} +5 -5
  31. package/dist/browser/{chunk-PIWO5L5N.js.map → chunk-MIB3EOC4.js.map} +1 -1
  32. package/dist/browser/{chunk-3STFITZF.cjs → chunk-QAFFDJFK.cjs} +6 -6
  33. package/dist/browser/{chunk-3STFITZF.cjs.map → chunk-QAFFDJFK.cjs.map} +1 -1
  34. package/dist/{chunk-BNMTY7PE.js → browser/chunk-UL5TNXQL.js} +4 -4
  35. package/dist/browser/{chunk-VZA2EPY3.js.map → chunk-UL5TNXQL.js.map} +1 -1
  36. package/dist/browser/{chunk-XD4VWCAC.js → chunk-V7AUPQIJ.js} +4 -4
  37. package/dist/browser/chunk-V7AUPQIJ.js.map +1 -0
  38. package/dist/browser/{chunk-YD7TO4PD.cjs → chunk-WGWPCVYB.cjs} +18 -18
  39. package/dist/browser/{chunk-YD7TO4PD.cjs.map → chunk-WGWPCVYB.cjs.map} +1 -1
  40. package/dist/browser/{chunk-6J6F5LJI.cjs → chunk-WR2SQLKP.cjs} +7 -7
  41. package/dist/browser/{chunk-6J6F5LJI.cjs.map → chunk-WR2SQLKP.cjs.map} +1 -1
  42. package/dist/browser/{chunk-255AHH2W.cjs → chunk-ZVVUZRG7.cjs} +15 -15
  43. package/dist/browser/{chunk-255AHH2W.cjs.map → chunk-ZVVUZRG7.cjs.map} +1 -1
  44. package/dist/browser/index.cjs +91 -91
  45. package/dist/browser/index.js +8 -8
  46. package/dist/browser/integrations/pino.cjs +4 -4
  47. package/dist/browser/integrations/pino.js +3 -3
  48. package/dist/browser/langchain/index.cjs +17 -17
  49. package/dist/browser/langchain/index.js +2 -2
  50. package/dist/browser/langgraph/index.cjs +27 -27
  51. package/dist/browser/langgraph/index.js +5 -5
  52. package/dist/browser/openai/index.cjs +11 -11
  53. package/dist/browser/openai/index.js +2 -2
  54. package/dist/browser/openai-agents/index.cjs +34 -34
  55. package/dist/browser/openai-agents/index.js +4 -4
  56. package/dist/browser/vercel-ai/index.cjs +14 -14
  57. package/dist/browser/vercel-ai/index.js +3 -3
  58. package/dist/{chunk-MBOISGKD.js → chunk-7I4ILCLY.js} +4 -4
  59. package/dist/{chunk-MBOISGKD.js.map → chunk-7I4ILCLY.js.map} +1 -1
  60. package/dist/{chunk-7ZNGY236.cjs → chunk-DGBQ3UI6.cjs} +7 -7
  61. package/dist/{chunk-7ZNGY236.cjs.map → chunk-DGBQ3UI6.cjs.map} +1 -1
  62. package/dist/{chunk-VM3QM22Z.cjs → chunk-DPW4W7H7.cjs} +18 -18
  63. package/dist/{chunk-VM3QM22Z.cjs.map → chunk-DPW4W7H7.cjs.map} +1 -1
  64. package/dist/{chunk-HA5RY4N5.cjs → chunk-DQ4T2MJE.cjs} +4 -4
  65. package/dist/chunk-DQ4T2MJE.cjs.map +1 -0
  66. package/dist/{chunk-ELBY4SJ7.js → chunk-ELVBOJWY.js} +4 -4
  67. package/dist/chunk-ELVBOJWY.js.map +1 -0
  68. package/dist/{chunk-JFFZBCTP.js → chunk-HONYN2OI.js} +3 -3
  69. package/dist/{chunk-JFFZBCTP.js.map → chunk-HONYN2OI.js.map} +1 -1
  70. package/dist/{chunk-ULWGK6F5.cjs → chunk-I3P5CHBV.cjs} +12 -12
  71. package/dist/{chunk-ULWGK6F5.cjs.map → chunk-I3P5CHBV.cjs.map} +1 -1
  72. package/dist/{browser/chunk-VZA2EPY3.js → chunk-MNV4HASC.js} +4 -4
  73. package/dist/{chunk-BNMTY7PE.js.map → chunk-MNV4HASC.js.map} +1 -1
  74. package/dist/{chunk-2O2FFJLK.js → chunk-NR36TJMT.js} +5 -5
  75. package/dist/{chunk-2O2FFJLK.js.map → chunk-NR36TJMT.js.map} +1 -1
  76. package/dist/{chunk-YPP5DDPO.js → chunk-QZDUGEIR.js} +3 -3
  77. package/dist/{chunk-YPP5DDPO.js.map → chunk-QZDUGEIR.js.map} +1 -1
  78. package/dist/{chunk-RDFDPK2X.cjs → chunk-RRE2LX2A.cjs} +6 -6
  79. package/dist/{chunk-RDFDPK2X.cjs.map → chunk-RRE2LX2A.cjs.map} +1 -1
  80. package/dist/{chunk-WLNADB4J.cjs → chunk-SJ625SQS.cjs} +15 -15
  81. package/dist/{chunk-WLNADB4J.cjs.map → chunk-SJ625SQS.cjs.map} +1 -1
  82. package/dist/{chunk-Q6NQQ2LO.js → chunk-YKPZQPEW.js} +3 -3
  83. package/dist/{chunk-Q6NQQ2LO.js.map → chunk-YKPZQPEW.js.map} +1 -1
  84. package/dist/{chunk-HZKXILBF.cjs → chunk-Z5MFR7UE.cjs} +5 -5
  85. package/dist/{chunk-HZKXILBF.cjs.map → chunk-Z5MFR7UE.cjs.map} +1 -1
  86. package/dist/index.cjs +104 -99
  87. package/dist/index.cjs.map +1 -1
  88. package/dist/index.js +15 -10
  89. package/dist/index.js.map +1 -1
  90. package/dist/integrations/pino.cjs +4 -4
  91. package/dist/integrations/pino.js +3 -3
  92. package/dist/langchain/index.cjs +17 -17
  93. package/dist/langchain/index.js +2 -2
  94. package/dist/langgraph/index.cjs +27 -27
  95. package/dist/langgraph/index.js +5 -5
  96. package/dist/openai/index.cjs +11 -11
  97. package/dist/openai/index.js +2 -2
  98. package/dist/openai-agents/index.cjs +34 -34
  99. package/dist/openai-agents/index.js +4 -4
  100. package/dist/vercel-ai/index.cjs +14 -14
  101. package/dist/vercel-ai/index.js +3 -3
  102. package/package.json +1 -1
  103. package/dist/browser/chunk-3H2OJLC2.cjs.map +0 -1
  104. package/dist/browser/chunk-XD4VWCAC.js.map +0 -1
  105. package/dist/chunk-ELBY4SJ7.js.map +0 -1
  106. package/dist/chunk-HA5RY4N5.cjs.map +0 -1
package/README.md CHANGED
@@ -134,26 +134,31 @@ sibling `memory` span per call.
134
134
 
135
135
  ### `@morsehq-dev/sdk/anthropic-agent-sdk` — Claude Agent SDK
136
136
 
137
- Wraps `ClaudeSDKClient` from `@anthropic-ai/claude-agent-sdk`. Emits an
138
- outer **agent** span, per-call **llm** spans (with `context_segments`),
139
- **tool** spans, **subagent.spawn** spans for Task-tool fan-out, and
140
- **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.
141
141
 
142
142
  ```ts
143
- import { ClaudeSDKClient } from "@anthropic-ai/claude-agent-sdk";
144
- 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";
145
145
 
146
- const raw = new ClaudeSDKClient({
147
- /* ... */
148
- });
149
- const { client, dispose } = wrapClaudeAgentSDKWithFullInstrumentation(raw);
146
+ const tracedQuery = wrapClaudeAgentQuery(query);
150
147
 
151
- 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" })) {
152
149
  // your code unchanged — spans flow to Morse as a side-effect
153
150
  }
154
- dispose();
155
151
  ```
156
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
+
157
162
  ### `@morsehq-dev/sdk/openai-agents` — OpenAI Agents SDK
158
163
 
159
164
  Wraps `Runner` from `@openai/agents`. Emits an outer **agent** span,
@@ -1,41 +1,41 @@
1
1
  'use strict';
2
2
 
3
- var chunkVM3QM22Z_cjs = require('../chunk-VM3QM22Z.cjs');
4
- require('../chunk-HZKXILBF.cjs');
5
- require('../chunk-RDFDPK2X.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-HA5RY4N5.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 chunkVM3QM22Z_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 chunkVM3QM22Z_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 chunkVM3QM22Z_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 chunkVM3QM22Z_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 chunkVM3QM22Z_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 chunkVM3QM22Z_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 chunkVM3QM22Z_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-2O2FFJLK.js';
2
- import '../chunk-YPP5DDPO.js';
3
- import '../chunk-Q6NQQ2LO.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-ELBY4SJ7.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 chunkVM3QM22Z_cjs = require('../chunk-VM3QM22Z.cjs');
4
- require('../chunk-HZKXILBF.cjs');
5
- var chunk7ZNGY236_cjs = require('../chunk-7ZNGY236.cjs');
6
- var chunkWLNADB4J_cjs = require('../chunk-WLNADB4J.cjs');
7
- var chunkRDFDPK2X_cjs = require('../chunk-RDFDPK2X.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 chunkHA5RY4N5_cjs = require('../chunk-HA5RY4N5.cjs');
10
+ var chunkDQ4T2MJE_cjs = require('../chunk-DQ4T2MJE.cjs');
11
11
 
12
12
  // src/anthropic-agent-sdk/client-wrapper.ts
13
- chunkHA5RY4N5_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 = chunkRDFDPK2X_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 = chunkRDFDPK2X_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 = chunkWLNADB4J_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 (chunkHA5RY4N5_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 = chunkHA5RY4N5_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
- chunkHA5RY4N5_cjs.init_tracing();
195
- var captureParentForFanOut = chunkRDFDPK2X_cjs.absorbErrorsSync(
135
+ chunkDQ4T2MJE_cjs.init_tracing();
136
+ var captureParentForFanOut = chunkRRE2LX2A_cjs.absorbErrorsSync(
196
137
  () => {
197
- const state = chunkHA5RY4N5_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 = chunkRDFDPK2X_cjs.absorbErrorsSync(
205
146
  },
206
147
  { fingerprint: "agent-sdk-common.captureParentForFanOut" }
207
148
  );
208
- var emitWithPinnedParent = chunkRDFDPK2X_cjs.absorbErrorsSync(
149
+ var emitWithPinnedParent = chunkRRE2LX2A_cjs.absorbErrorsSync(
209
150
  (opts) => {
210
- const state = chunkHA5RY4N5_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 = chunkHA5RY4N5_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 = chunkRDFDPK2X_cjs.absorbErrorsSync(
177
+ var emitAsToolSibling = chunkRRE2LX2A_cjs.absorbErrorsSync(
237
178
  (opts) => {
238
- const state = chunkHA5RY4N5_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 = chunkHA5RY4N5_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 = chunkRDFDPK2X_cjs.absorbErrorsSync(
250
191
  },
251
192
  { fingerprint: "agent-sdk-common.emitAsToolSibling" }
252
193
  );
253
- chunkRDFDPK2X_cjs.absorbErrorsSync(
194
+ chunkRRE2LX2A_cjs.absorbErrorsSync(
254
195
  () => {
255
- const state = chunkHA5RY4N5_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 = chunkWLNADB4J_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 = chunkRDFDPK2X_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
- chunkHA5RY4N5_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 = chunkWLNADB4J_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 = chunkVM3QM22Z_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 = chunkWLNADB4J_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 = chunkVM3QM22Z_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
- chunkHA5RY4N5_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
- chunkHA5RY4N5_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 = chunk7ZNGY236_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 = chunkWLNADB4J_cjs.emitToolSpan({
530
+ handle = chunkSJ625SQS_cjs.emitToolSpan({
590
531
  adapter: ADAPTER,
591
532
  toolName: name,
592
- inputSummary: chunk7ZNGY236_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 = chunk7ZNGY236_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
- chunkHA5RY4N5_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