@agent-assembly/sdk 0.0.1-alpha.3

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 (256) hide show
  1. package/LICENSE +176 -0
  2. package/README.md +182 -0
  3. package/dist/cjs/adapters/adapter-registry.js +2 -0
  4. package/dist/cjs/adapters/adapter.js +2 -0
  5. package/dist/cjs/adapters/index.js +2 -0
  6. package/dist/cjs/adapters/langchain/assembly-callback-handler.js +93 -0
  7. package/dist/cjs/adapters/langchain/index.js +8 -0
  8. package/dist/cjs/adapters/langchain/wrap-tool-with-assembly.js +55 -0
  9. package/dist/cjs/audit/encode.js +176 -0
  10. package/dist/cjs/audit/index.js +8 -0
  11. package/dist/cjs/core/gateway-resolver.js +254 -0
  12. package/dist/cjs/core/index.js +9 -0
  13. package/dist/cjs/core/init-assembly.js +224 -0
  14. package/dist/cjs/errors/configuration-error.js +17 -0
  15. package/dist/cjs/errors/gateway-error.js +17 -0
  16. package/dist/cjs/errors/index.js +11 -0
  17. package/dist/cjs/errors/op-terminated-error.js +20 -0
  18. package/dist/cjs/errors/policy-violation-error.js +10 -0
  19. package/dist/cjs/gateway/client.js +15 -0
  20. package/dist/cjs/gateway/index.js +5 -0
  21. package/dist/cjs/hooks/adapter-registry.js +7 -0
  22. package/dist/cjs/hooks/ai-sdk-detection.js +14 -0
  23. package/dist/cjs/hooks/ai-sdk.js +164 -0
  24. package/dist/cjs/hooks/langchain.js +9 -0
  25. package/dist/cjs/hooks/langgraph-detection.js +14 -0
  26. package/dist/cjs/hooks/langgraph.js +107 -0
  27. package/dist/cjs/hooks/mastra-detection.js +14 -0
  28. package/dist/cjs/hooks/mastra.js +120 -0
  29. package/dist/cjs/hooks/openai-agents-detection.js +14 -0
  30. package/dist/cjs/hooks/openai-agents.js +189 -0
  31. package/dist/cjs/index.js +25 -0
  32. package/dist/cjs/lineage/agent-context-store.js +20 -0
  33. package/dist/cjs/lineage/index.js +7 -0
  34. package/dist/cjs/native/client.js +160 -0
  35. package/dist/cjs/op-control.js +150 -0
  36. package/dist/cjs/package.json +3 -0
  37. package/dist/cjs/proto/generated/common.js +365 -0
  38. package/dist/cjs/proto/generated/policy.js +1418 -0
  39. package/dist/cjs/runtime.js +144 -0
  40. package/dist/cjs/types/assembly-config.js +2 -0
  41. package/dist/cjs/types/assembly-context.js +2 -0
  42. package/dist/cjs/types/assembly-mode.js +2 -0
  43. package/dist/cjs/types/audit.js +5 -0
  44. package/dist/cjs/types/enforcement-mode.js +9 -0
  45. package/dist/cjs/types/gateway-governance.js +2 -0
  46. package/dist/cjs/types/index.js +5 -0
  47. package/dist/cjs/types/langchain-adapter.js +2 -0
  48. package/dist/cjs/types/openai-agents-adapter.js +2 -0
  49. package/dist/cjs/types/policy.js +2 -0
  50. package/dist/cjs/types/tool-map.js +2 -0
  51. package/dist/cjs/types/vercel-ai-adapter.js +2 -0
  52. package/dist/cjs/wrappers/index.js +5 -0
  53. package/dist/cjs/wrappers/with-assembly.js +82 -0
  54. package/dist/esm/adapters/adapter-registry.js +2 -0
  55. package/dist/esm/adapters/adapter-registry.js.map +1 -0
  56. package/dist/esm/adapters/adapter.js +2 -0
  57. package/dist/esm/adapters/adapter.js.map +1 -0
  58. package/dist/esm/adapters/index.js +2 -0
  59. package/dist/esm/adapters/index.js.map +1 -0
  60. package/dist/esm/adapters/langchain/assembly-callback-handler.js +90 -0
  61. package/dist/esm/adapters/langchain/assembly-callback-handler.js.map +1 -0
  62. package/dist/esm/adapters/langchain/index.js +3 -0
  63. package/dist/esm/adapters/langchain/index.js.map +1 -0
  64. package/dist/esm/adapters/langchain/wrap-tool-with-assembly.js +52 -0
  65. package/dist/esm/adapters/langchain/wrap-tool-with-assembly.js.map +1 -0
  66. package/dist/esm/audit/encode.js +171 -0
  67. package/dist/esm/audit/encode.js.map +1 -0
  68. package/dist/esm/audit/index.js +2 -0
  69. package/dist/esm/audit/index.js.map +1 -0
  70. package/dist/esm/core/gateway-resolver.js +213 -0
  71. package/dist/esm/core/gateway-resolver.js.map +1 -0
  72. package/dist/esm/core/index.js +2 -0
  73. package/dist/esm/core/index.js.map +1 -0
  74. package/dist/esm/core/init-assembly.js +218 -0
  75. package/dist/esm/core/init-assembly.js.map +1 -0
  76. package/dist/esm/errors/configuration-error.js +14 -0
  77. package/dist/esm/errors/configuration-error.js.map +1 -0
  78. package/dist/esm/errors/gateway-error.js +14 -0
  79. package/dist/esm/errors/gateway-error.js.map +1 -0
  80. package/dist/esm/errors/index.js +5 -0
  81. package/dist/esm/errors/index.js.map +1 -0
  82. package/dist/esm/errors/op-terminated-error.js +17 -0
  83. package/dist/esm/errors/op-terminated-error.js.map +1 -0
  84. package/dist/esm/errors/policy-violation-error.js +7 -0
  85. package/dist/esm/errors/policy-violation-error.js.map +1 -0
  86. package/dist/esm/gateway/client.js +13 -0
  87. package/dist/esm/gateway/client.js.map +1 -0
  88. package/dist/esm/gateway/index.js +2 -0
  89. package/dist/esm/gateway/index.js.map +1 -0
  90. package/dist/esm/hooks/adapter-registry.js +5 -0
  91. package/dist/esm/hooks/adapter-registry.js.map +1 -0
  92. package/dist/esm/hooks/ai-sdk-detection.js +12 -0
  93. package/dist/esm/hooks/ai-sdk-detection.js.map +1 -0
  94. package/dist/esm/hooks/ai-sdk.js +123 -0
  95. package/dist/esm/hooks/ai-sdk.js.map +1 -0
  96. package/dist/esm/hooks/langchain.js +7 -0
  97. package/dist/esm/hooks/langchain.js.map +1 -0
  98. package/dist/esm/hooks/langgraph-detection.js +12 -0
  99. package/dist/esm/hooks/langgraph-detection.js.map +1 -0
  100. package/dist/esm/hooks/langgraph.js +69 -0
  101. package/dist/esm/hooks/langgraph.js.map +1 -0
  102. package/dist/esm/hooks/mastra-detection.js +12 -0
  103. package/dist/esm/hooks/mastra-detection.js.map +1 -0
  104. package/dist/esm/hooks/mastra.js +83 -0
  105. package/dist/esm/hooks/mastra.js.map +1 -0
  106. package/dist/esm/hooks/openai-agents-detection.js +12 -0
  107. package/dist/esm/hooks/openai-agents-detection.js.map +1 -0
  108. package/dist/esm/hooks/openai-agents.js +145 -0
  109. package/dist/esm/hooks/openai-agents.js.map +1 -0
  110. package/dist/esm/index.js +12 -0
  111. package/dist/esm/index.js.map +1 -0
  112. package/dist/esm/lineage/agent-context-store.js +16 -0
  113. package/dist/esm/lineage/agent-context-store.js.map +1 -0
  114. package/dist/esm/lineage/index.js +2 -0
  115. package/dist/esm/lineage/index.js.map +1 -0
  116. package/dist/esm/native/client.js +150 -0
  117. package/dist/esm/native/client.js.map +1 -0
  118. package/dist/esm/op-control.js +147 -0
  119. package/dist/esm/op-control.js.map +1 -0
  120. package/dist/esm/proto/generated/common.js +357 -0
  121. package/dist/esm/proto/generated/common.js.map +1 -0
  122. package/dist/esm/proto/generated/policy.js +1414 -0
  123. package/dist/esm/proto/generated/policy.js.map +1 -0
  124. package/dist/esm/runtime.js +138 -0
  125. package/dist/esm/runtime.js.map +1 -0
  126. package/dist/esm/types/assembly-config.js +2 -0
  127. package/dist/esm/types/assembly-config.js.map +1 -0
  128. package/dist/esm/types/assembly-context.js +2 -0
  129. package/dist/esm/types/assembly-context.js.map +1 -0
  130. package/dist/esm/types/assembly-mode.js +2 -0
  131. package/dist/esm/types/assembly-mode.js.map +1 -0
  132. package/dist/esm/types/audit.js +5 -0
  133. package/dist/esm/types/audit.js.map +1 -0
  134. package/dist/esm/types/enforcement-mode.js +7 -0
  135. package/dist/esm/types/enforcement-mode.js.map +1 -0
  136. package/dist/esm/types/gateway-governance.js +2 -0
  137. package/dist/esm/types/gateway-governance.js.map +1 -0
  138. package/dist/esm/types/index.js +2 -0
  139. package/dist/esm/types/index.js.map +1 -0
  140. package/dist/esm/types/langchain-adapter.js +2 -0
  141. package/dist/esm/types/langchain-adapter.js.map +1 -0
  142. package/dist/esm/types/openai-agents-adapter.js +2 -0
  143. package/dist/esm/types/openai-agents-adapter.js.map +1 -0
  144. package/dist/esm/types/policy.js +2 -0
  145. package/dist/esm/types/policy.js.map +1 -0
  146. package/dist/esm/types/tool-map.js +2 -0
  147. package/dist/esm/types/tool-map.js.map +1 -0
  148. package/dist/esm/types/vercel-ai-adapter.js +2 -0
  149. package/dist/esm/types/vercel-ai-adapter.js.map +1 -0
  150. package/dist/esm/wrappers/index.js +2 -0
  151. package/dist/esm/wrappers/index.js.map +1 -0
  152. package/dist/esm/wrappers/with-assembly.js +80 -0
  153. package/dist/esm/wrappers/with-assembly.js.map +1 -0
  154. package/dist/types/adapters/adapter-registry.d.ts +7 -0
  155. package/dist/types/adapters/adapter-registry.d.ts.map +1 -0
  156. package/dist/types/adapters/adapter.d.ts +6 -0
  157. package/dist/types/adapters/adapter.d.ts.map +1 -0
  158. package/dist/types/adapters/index.d.ts +3 -0
  159. package/dist/types/adapters/index.d.ts.map +1 -0
  160. package/dist/types/adapters/langchain/assembly-callback-handler.d.ts +21 -0
  161. package/dist/types/adapters/langchain/assembly-callback-handler.d.ts.map +1 -0
  162. package/dist/types/adapters/langchain/index.d.ts +4 -0
  163. package/dist/types/adapters/langchain/index.d.ts.map +1 -0
  164. package/dist/types/adapters/langchain/wrap-tool-with-assembly.d.ts +9 -0
  165. package/dist/types/adapters/langchain/wrap-tool-with-assembly.d.ts.map +1 -0
  166. package/dist/types/audit/encode.d.ts +77 -0
  167. package/dist/types/audit/encode.d.ts.map +1 -0
  168. package/dist/types/audit/index.d.ts +3 -0
  169. package/dist/types/audit/index.d.ts.map +1 -0
  170. package/dist/types/core/gateway-resolver.d.ts +92 -0
  171. package/dist/types/core/gateway-resolver.d.ts.map +1 -0
  172. package/dist/types/core/index.d.ts +2 -0
  173. package/dist/types/core/index.d.ts.map +1 -0
  174. package/dist/types/core/init-assembly.d.ts +10 -0
  175. package/dist/types/core/init-assembly.d.ts.map +1 -0
  176. package/dist/types/errors/configuration-error.d.ts +11 -0
  177. package/dist/types/errors/configuration-error.d.ts.map +1 -0
  178. package/dist/types/errors/gateway-error.d.ts +11 -0
  179. package/dist/types/errors/gateway-error.d.ts.map +1 -0
  180. package/dist/types/errors/index.d.ts +5 -0
  181. package/dist/types/errors/index.d.ts.map +1 -0
  182. package/dist/types/errors/op-terminated-error.d.ts +13 -0
  183. package/dist/types/errors/op-terminated-error.d.ts.map +1 -0
  184. package/dist/types/errors/policy-violation-error.d.ts +4 -0
  185. package/dist/types/errors/policy-violation-error.d.ts.map +1 -0
  186. package/dist/types/gateway/client.d.ts +14 -0
  187. package/dist/types/gateway/client.d.ts.map +1 -0
  188. package/dist/types/gateway/index.d.ts +3 -0
  189. package/dist/types/gateway/index.d.ts.map +1 -0
  190. package/dist/types/hooks/adapter-registry.d.ts +3 -0
  191. package/dist/types/hooks/adapter-registry.d.ts.map +1 -0
  192. package/dist/types/hooks/ai-sdk-detection.d.ts +2 -0
  193. package/dist/types/hooks/ai-sdk-detection.d.ts.map +1 -0
  194. package/dist/types/hooks/ai-sdk.d.ts +36 -0
  195. package/dist/types/hooks/ai-sdk.d.ts.map +1 -0
  196. package/dist/types/hooks/langchain.d.ts +3 -0
  197. package/dist/types/hooks/langchain.d.ts.map +1 -0
  198. package/dist/types/hooks/langgraph-detection.d.ts +2 -0
  199. package/dist/types/hooks/langgraph-detection.d.ts.map +1 -0
  200. package/dist/types/hooks/langgraph.d.ts +26 -0
  201. package/dist/types/hooks/langgraph.d.ts.map +1 -0
  202. package/dist/types/hooks/mastra-detection.d.ts +2 -0
  203. package/dist/types/hooks/mastra-detection.d.ts.map +1 -0
  204. package/dist/types/hooks/mastra.d.ts +29 -0
  205. package/dist/types/hooks/mastra.d.ts.map +1 -0
  206. package/dist/types/hooks/openai-agents-detection.d.ts +2 -0
  207. package/dist/types/hooks/openai-agents-detection.d.ts.map +1 -0
  208. package/dist/types/hooks/openai-agents.d.ts +42 -0
  209. package/dist/types/hooks/openai-agents.d.ts.map +1 -0
  210. package/dist/types/index.d.ts +10 -0
  211. package/dist/types/index.d.ts.map +1 -0
  212. package/dist/types/lineage/agent-context-store.d.ts +12 -0
  213. package/dist/types/lineage/agent-context-store.d.ts.map +1 -0
  214. package/dist/types/lineage/index.d.ts +2 -0
  215. package/dist/types/lineage/index.d.ts.map +1 -0
  216. package/dist/types/native/client.d.ts +26 -0
  217. package/dist/types/native/client.d.ts.map +1 -0
  218. package/dist/types/op-control.d.ts +85 -0
  219. package/dist/types/op-control.d.ts.map +1 -0
  220. package/dist/types/proto/generated/common.d.ts +90 -0
  221. package/dist/types/proto/generated/common.d.ts.map +1 -0
  222. package/dist/types/proto/generated/policy.d.ts +298 -0
  223. package/dist/types/proto/generated/policy.d.ts.map +1 -0
  224. package/dist/types/runtime.d.ts +59 -0
  225. package/dist/types/runtime.d.ts.map +1 -0
  226. package/dist/types/types/assembly-config.d.ts +47 -0
  227. package/dist/types/types/assembly-config.d.ts.map +1 -0
  228. package/dist/types/types/assembly-context.d.ts +12 -0
  229. package/dist/types/types/assembly-context.d.ts.map +1 -0
  230. package/dist/types/types/assembly-mode.d.ts +2 -0
  231. package/dist/types/types/assembly-mode.d.ts.map +1 -0
  232. package/dist/types/types/audit.d.ts +76 -0
  233. package/dist/types/types/audit.d.ts.map +1 -0
  234. package/dist/types/types/enforcement-mode.d.ts +20 -0
  235. package/dist/types/types/enforcement-mode.d.ts.map +1 -0
  236. package/dist/types/types/gateway-governance.d.ts +31 -0
  237. package/dist/types/types/gateway-governance.d.ts.map +1 -0
  238. package/dist/types/types/index.d.ts +12 -0
  239. package/dist/types/types/index.d.ts.map +1 -0
  240. package/dist/types/types/langchain-adapter.d.ts +25 -0
  241. package/dist/types/types/langchain-adapter.d.ts.map +1 -0
  242. package/dist/types/types/openai-agents-adapter.d.ts +17 -0
  243. package/dist/types/types/openai-agents-adapter.d.ts.map +1 -0
  244. package/dist/types/types/policy.d.ts +10 -0
  245. package/dist/types/types/policy.d.ts.map +1 -0
  246. package/dist/types/types/tool-map.d.ts +2 -0
  247. package/dist/types/types/tool-map.d.ts.map +1 -0
  248. package/dist/types/types/vercel-ai-adapter.d.ts +12 -0
  249. package/dist/types/types/vercel-ai-adapter.d.ts.map +1 -0
  250. package/dist/types/wrappers/index.d.ts +3 -0
  251. package/dist/types/wrappers/index.d.ts.map +1 -0
  252. package/dist/types/wrappers/with-assembly.d.ts +9 -0
  253. package/dist/types/wrappers/with-assembly.d.ts.map +1 -0
  254. package/native/aa-ffi-node/index.cjs +20 -0
  255. package/native/aa-ffi-node/index.d.ts +23 -0
  256. package/package.json +95 -0
@@ -0,0 +1,176 @@
1
+ "use strict";
2
+ // JSON wire-format bridge for the `AuditEvent` / `CallStackNode` interfaces
3
+ // declared in `../types/audit.ts`. Mirrors the gateway's snake_case JSON
4
+ // convention (consistent with the existing `sendEvent(handle, eventJSON)`
5
+ // path used by `native/aa-ffi-node`) — see AAASM-1450 for context.
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.encodeCallStackNode = encodeCallStackNode;
8
+ exports.encodeAuditEvent = encodeAuditEvent;
9
+ exports.decodeCallStackNode = decodeCallStackNode;
10
+ exports.decodeAuditEvent = decodeAuditEvent;
11
+ /**
12
+ * Translate a {@link CallStackNode} into its wire JSON object form.
13
+ *
14
+ * Recurses through `children`. Optional fields (`latencyMs`,
15
+ * `children`) are dropped when undefined or — for `children` — empty,
16
+ * so the resulting object is the minimal payload the gateway accepts.
17
+ */
18
+ function encodeCallStackNode(node) {
19
+ const wire = {
20
+ id: node.id,
21
+ kind: node.kind,
22
+ label: node.label,
23
+ };
24
+ if (node.latencyMs !== undefined) {
25
+ wire.latency_ms = node.latencyMs;
26
+ }
27
+ if (node.children !== undefined && node.children.length > 0) {
28
+ wire.children = node.children.map(encodeCallStackNode);
29
+ }
30
+ return wire;
31
+ }
32
+ /**
33
+ * Serialize an {@link AuditEvent} to its JSON wire string.
34
+ *
35
+ * Translates the camelCase interface field names into the gateway's
36
+ * snake_case keys (`eventId` → `event_id`, `callStack` → `call_stack`,
37
+ * etc.), recursively encoding the call-stack tree via
38
+ * {@link encodeCallStackNode}. Optional fields whose value is
39
+ * `undefined`, an empty string, or an empty array are omitted so a
40
+ * legacy decoder that has never seen those fields reads the payload
41
+ * unchanged.
42
+ */
43
+ function encodeAuditEvent(event) {
44
+ const wire = {
45
+ event_id: event.eventId,
46
+ agent_id: event.agentId,
47
+ action_type: event.actionType,
48
+ decision: event.decision,
49
+ };
50
+ if (event.traceId !== undefined && event.traceId !== "") {
51
+ wire.trace_id = event.traceId;
52
+ }
53
+ if (event.spanId !== undefined && event.spanId !== "") {
54
+ wire.span_id = event.spanId;
55
+ }
56
+ if (event.parentSpanId !== undefined && event.parentSpanId !== "") {
57
+ wire.parent_span_id = event.parentSpanId;
58
+ }
59
+ if (event.labels !== undefined && Object.keys(event.labels).length > 0) {
60
+ wire.labels = event.labels;
61
+ }
62
+ if (event.callStack !== undefined && event.callStack.length > 0) {
63
+ wire.call_stack = event.callStack.map(encodeCallStackNode);
64
+ }
65
+ return JSON.stringify(wire);
66
+ }
67
+ function asRecord(value) {
68
+ if (typeof value !== "object" || value === null || Array.isArray(value)) {
69
+ throw new TypeError("expected JSON object on the wire");
70
+ }
71
+ return value;
72
+ }
73
+ /**
74
+ * Translate a wire JSON object back into a {@link CallStackNode}.
75
+ *
76
+ * Symmetric inverse of {@link encodeCallStackNode}: walks `children`
77
+ * recursively, restores `latencyMs` from `latency_ms`, and treats a
78
+ * missing or empty `children` field as `undefined` on the interface
79
+ * side (matches AAASM-1436's default).
80
+ */
81
+ function decodeCallStackNode(payload) {
82
+ const wire = asRecord(payload);
83
+ const id = wire.id;
84
+ const kindRaw = wire.kind;
85
+ const label = wire.label;
86
+ if (typeof id !== "string") {
87
+ throw new TypeError("CallStackNode.id missing or not a string");
88
+ }
89
+ if (typeof kindRaw !== "string") {
90
+ throw new TypeError("CallStackNode.kind missing or not a string");
91
+ }
92
+ if (typeof label !== "string") {
93
+ throw new TypeError("CallStackNode.label missing or not a string");
94
+ }
95
+ const node = {
96
+ id,
97
+ kind: kindRaw,
98
+ label,
99
+ };
100
+ if (typeof wire.latency_ms === "number") {
101
+ node.latencyMs = wire.latency_ms;
102
+ }
103
+ if (Array.isArray(wire.children) && wire.children.length > 0) {
104
+ node.children = wire.children.map(decodeCallStackNode);
105
+ }
106
+ return node;
107
+ }
108
+ function asNonEmptyString(value) {
109
+ return typeof value === "string" && value.length > 0 ? value : undefined;
110
+ }
111
+ function asStringMap(value) {
112
+ if (typeof value !== "object" || value === null || Array.isArray(value)) {
113
+ return undefined;
114
+ }
115
+ const entries = Object.entries(value).filter((entry) => typeof entry[1] === "string");
116
+ return entries.length > 0 ? Object.fromEntries(entries) : undefined;
117
+ }
118
+ /**
119
+ * Deserialize a JSON wire payload into a typed {@link AuditEvent}.
120
+ *
121
+ * Accepts either the raw JSON string (the gateway's standard
122
+ * transport) or an already-parsed object (handy for tests and for
123
+ * callers that received a JSON object via another path). Symmetric
124
+ * inverse of {@link encodeAuditEvent}: snake_case keys map back to
125
+ * camelCase fields, and missing / empty optionals decode to
126
+ * `undefined` so an `AuditEvent` produced from a legacy payload (no
127
+ * `call_stack`, empty `trace_id`, …) matches what AAASM-1436's
128
+ * existing consumer-side tests expect.
129
+ */
130
+ function decodeAuditEvent(payload) {
131
+ const wire = typeof payload === "string"
132
+ ? asRecord(JSON.parse(payload))
133
+ : asRecord(payload);
134
+ const eventId = wire.event_id;
135
+ const agentId = wire.agent_id;
136
+ const actionType = wire.action_type;
137
+ const decision = wire.decision;
138
+ if (typeof eventId !== "string") {
139
+ throw new TypeError("AuditEvent.event_id missing or not a string");
140
+ }
141
+ if (typeof agentId !== "string") {
142
+ throw new TypeError("AuditEvent.agent_id missing or not a string");
143
+ }
144
+ if (typeof actionType !== "string") {
145
+ throw new TypeError("AuditEvent.action_type missing or not a string");
146
+ }
147
+ if (typeof decision !== "string") {
148
+ throw new TypeError("AuditEvent.decision missing or not a string");
149
+ }
150
+ const event = {
151
+ eventId,
152
+ agentId,
153
+ actionType,
154
+ decision,
155
+ };
156
+ const traceId = asNonEmptyString(wire.trace_id);
157
+ if (traceId !== undefined) {
158
+ event.traceId = traceId;
159
+ }
160
+ const spanId = asNonEmptyString(wire.span_id);
161
+ if (spanId !== undefined) {
162
+ event.spanId = spanId;
163
+ }
164
+ const parentSpanId = asNonEmptyString(wire.parent_span_id);
165
+ if (parentSpanId !== undefined) {
166
+ event.parentSpanId = parentSpanId;
167
+ }
168
+ const labels = asStringMap(wire.labels);
169
+ if (labels !== undefined) {
170
+ event.labels = labels;
171
+ }
172
+ if (Array.isArray(wire.call_stack) && wire.call_stack.length > 0) {
173
+ event.callStack = wire.call_stack.map(decodeCallStackNode);
174
+ }
175
+ return event;
176
+ }
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.encodeCallStackNode = exports.encodeAuditEvent = exports.decodeCallStackNode = exports.decodeAuditEvent = void 0;
4
+ var encode_js_1 = require("./encode.js");
5
+ Object.defineProperty(exports, "decodeAuditEvent", { enumerable: true, get: function () { return encode_js_1.decodeAuditEvent; } });
6
+ Object.defineProperty(exports, "decodeCallStackNode", { enumerable: true, get: function () { return encode_js_1.decodeCallStackNode; } });
7
+ Object.defineProperty(exports, "encodeAuditEvent", { enumerable: true, get: function () { return encode_js_1.encodeAuditEvent; } });
8
+ Object.defineProperty(exports, "encodeCallStackNode", { enumerable: true, get: function () { return encode_js_1.encodeCallStackNode; } });
@@ -0,0 +1,254 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.__testing = exports.AASM_AUTO_START_ARGV = exports.ENV_API_KEY = exports.ENV_GATEWAY_URL = exports.DEFAULT_CONFIG_FILE_PATH = exports.DEFAULT_AUTO_START_TIMEOUT_MS = exports.DEFAULT_PROBE_TIMEOUT_MS = exports.DEFAULT_HEALTHZ_PATH = exports.DEFAULT_GATEWAY_URL = void 0;
37
+ exports.probeHealthz = probeHealthz;
38
+ exports.waitForHealthz = waitForHealthz;
39
+ exports.loadConfigFile = loadConfigFile;
40
+ exports.autoStartGateway = autoStartGateway;
41
+ exports.resolveGatewayUrl = resolveGatewayUrl;
42
+ exports.resolveApiKey = resolveApiKey;
43
+ const node_child_process_1 = require("node:child_process");
44
+ const node_fs_1 = require("node:fs");
45
+ const node_os_1 = require("node:os");
46
+ const node_path_1 = require("node:path");
47
+ const index_js_1 = require("../errors/index.js");
48
+ /**
49
+ * Resolve the gateway URL and API key for ``initAssembly``.
50
+ *
51
+ * Implements the zero-config developer-experience contract from Epic 17 (S-G):
52
+ * ``initAssembly({})`` with no fields and no environment variables should
53
+ * discover a local gateway at ``http://localhost:7391`` — probing it, and
54
+ * auto-starting ``aasm start --mode local --foreground`` when not running.
55
+ *
56
+ * Resolution precedence (highest first):
57
+ *
58
+ * 1. Explicit field on the AssemblyConfig
59
+ * 2. Environment variable (AAASM_GATEWAY_URL / AAASM_API_KEY)
60
+ * 3. Config file (~/.aasm/config.yaml, optional js-yaml soft dep)
61
+ * 4. Local default: probe http://localhost:7391, auto-start if absent
62
+ */
63
+ exports.DEFAULT_GATEWAY_URL = "http://localhost:7391";
64
+ exports.DEFAULT_HEALTHZ_PATH = "/healthz";
65
+ exports.DEFAULT_PROBE_TIMEOUT_MS = 500;
66
+ exports.DEFAULT_AUTO_START_TIMEOUT_MS = 5000;
67
+ exports.DEFAULT_CONFIG_FILE_PATH = "~/.aasm/config.yaml";
68
+ exports.ENV_GATEWAY_URL = "AAASM_GATEWAY_URL";
69
+ exports.ENV_API_KEY = "AAASM_API_KEY";
70
+ exports.AASM_AUTO_START_ARGV = ["start", "--mode", "local", "--foreground"];
71
+ /**
72
+ * Return true if a gateway responds with a 2xx status at ``{baseUrl}/healthz``.
73
+ *
74
+ * Uses the global ``fetch`` (Node 18+) with an AbortController-driven
75
+ * timeout. Any network / timeout / parse error is swallowed and reported
76
+ * as ``false`` — the resolver treats unreachable as "absent" rather than
77
+ * fatal.
78
+ */
79
+ async function probeHealthz(baseUrl, timeoutMs = exports.DEFAULT_PROBE_TIMEOUT_MS) {
80
+ const url = baseUrl.replace(/\/+$/, "") + exports.DEFAULT_HEALTHZ_PATH;
81
+ const controller = new AbortController();
82
+ const timer = setTimeout(() => controller.abort(), timeoutMs);
83
+ try {
84
+ const response = await fetch(url, { signal: controller.signal });
85
+ return response.status >= 200 && response.status < 300;
86
+ }
87
+ catch {
88
+ return false;
89
+ }
90
+ finally {
91
+ clearTimeout(timer);
92
+ }
93
+ }
94
+ /**
95
+ * Poll the gateway healthz endpoint until success or timeout.
96
+ *
97
+ * Resolves ``true`` as soon as ``probeHealthz`` succeeds, ``false`` if
98
+ * the gateway has not become ready within ``timeoutMs``. The poll
99
+ * interval is short (default 100ms) so the auto-start path feels
100
+ * instant when the local CP comes up quickly.
101
+ */
102
+ async function waitForHealthz(baseUrl, timeoutMs = exports.DEFAULT_AUTO_START_TIMEOUT_MS, pollIntervalMs = 100) {
103
+ const deadline = Date.now() + timeoutMs;
104
+ while (Date.now() < deadline) {
105
+ if (await probeHealthz(baseUrl)) {
106
+ return true;
107
+ }
108
+ await new Promise((resolve) => setTimeout(resolve, pollIntervalMs));
109
+ }
110
+ return probeHealthz(baseUrl);
111
+ }
112
+ function expandHome(p) {
113
+ return p.startsWith("~") ? (0, node_path_1.resolve)((0, node_os_1.homedir)(), p.slice(p.startsWith("~/") ? 2 : 1)) : p;
114
+ }
115
+ /**
116
+ * Load ``~/.aasm/config.yaml`` if present.
117
+ *
118
+ * Returns an empty record when the file is missing, when ``js-yaml`` is
119
+ * not installed (it is a soft dependency for SDK consumers), or when
120
+ * the file's contents are not an object. This keeps the resolver chain
121
+ * purely advisory at step 3 — never throws.
122
+ */
123
+ async function loadConfigFile(configPath = exports.DEFAULT_CONFIG_FILE_PATH) {
124
+ // Indirect specifier defeats static module resolution so missing js-yaml
125
+ // surfaces at runtime (caught below) rather than as a TS compile error.
126
+ const yamlSpec = "js-yaml";
127
+ let yamlMod;
128
+ try {
129
+ yamlMod = (await Promise.resolve(`${yamlSpec}`).then(s => __importStar(require(s))));
130
+ }
131
+ catch {
132
+ return {};
133
+ }
134
+ const expanded = expandHome(configPath);
135
+ if (!(0, node_fs_1.existsSync)(expanded)) {
136
+ return {};
137
+ }
138
+ try {
139
+ const parsed = yamlMod.load((0, node_fs_1.readFileSync)(expanded, "utf8"));
140
+ return parsed !== null && typeof parsed === "object" && !Array.isArray(parsed)
141
+ ? parsed
142
+ : {};
143
+ }
144
+ catch {
145
+ return {};
146
+ }
147
+ }
148
+ function defaultFindAasmOnPath() {
149
+ const PATH = process.env.PATH ?? "";
150
+ const sep = process.platform === "win32" ? ";" : ":";
151
+ const exts = process.platform === "win32" ? [".exe", ".cmd", ""] : [""];
152
+ for (const dir of PATH.split(sep)) {
153
+ if (!dir)
154
+ continue;
155
+ for (const ext of exts) {
156
+ const candidate = (0, node_path_1.join)(dir, `aasm${ext}`);
157
+ if ((0, node_fs_1.existsSync)(candidate))
158
+ return candidate;
159
+ }
160
+ }
161
+ return null;
162
+ }
163
+ function defaultSpawnAasm(aasmPath) {
164
+ const child = (0, node_child_process_1.spawn)(aasmPath, [...exports.AASM_AUTO_START_ARGV], {
165
+ detached: true,
166
+ stdio: "ignore",
167
+ });
168
+ child.unref();
169
+ }
170
+ /**
171
+ * Mutable seams used by ``autoStartGateway`` — exposed via ``__testing``
172
+ * so tests can stub the PATH lookup and subprocess spawn without using
173
+ * ESM module mocking. Production callers should treat this as private.
174
+ */
175
+ const _seams = {
176
+ findAasmOnPath: defaultFindAasmOnPath,
177
+ spawnAasm: defaultSpawnAasm,
178
+ probeHealthz: probeHealthz,
179
+ loadConfigFile: loadConfigFile,
180
+ autoStartGateway: autoStartGateway,
181
+ };
182
+ exports.__testing = { _seams };
183
+ /**
184
+ * Spawn ``aasm start --mode local --foreground`` and wait until ``/healthz``
185
+ * responds.
186
+ *
187
+ * Throws ``ConfigurationError`` when the ``aasm`` binary is missing from
188
+ * PATH — the SDK cannot meaningfully auto-start without it. Throws
189
+ * ``GatewayError`` when the spawned gateway does not become ready within
190
+ * ``timeoutMs``. The subprocess is launched detached + stdio:"ignore" so
191
+ * it survives the parent Node process — the docker-style daemon hand-off
192
+ * described in Epic 17 S-G.
193
+ */
194
+ async function autoStartGateway(baseUrl = exports.DEFAULT_GATEWAY_URL, timeoutMs = exports.DEFAULT_AUTO_START_TIMEOUT_MS) {
195
+ const aasmPath = _seams.findAasmOnPath();
196
+ if (aasmPath === null) {
197
+ throw new index_js_1.ConfigurationError(`No gateway found at ${baseUrl} and 'aasm' is not on PATH. ` +
198
+ "Install it with: npm install -g @agent-assembly/cli (or pnpm add -g)");
199
+ }
200
+ _seams.spawnAasm(aasmPath);
201
+ if (!(await waitForHealthz(baseUrl, timeoutMs))) {
202
+ throw new index_js_1.GatewayError(`Auto-started gateway at ${baseUrl} did not become ready ` +
203
+ `within ${(timeoutMs / 1000).toFixed(0)} seconds`);
204
+ }
205
+ }
206
+ /**
207
+ * Resolve the gateway URL using the 4-step precedence chain.
208
+ *
209
+ * Returns the resolved URL. May spawn a local ``aasm`` subprocess
210
+ * (step 4 only). Propagates ``ConfigurationError`` / ``GatewayError``
211
+ * from ``autoStartGateway`` when the local default is needed but
212
+ * cannot be brought up.
213
+ */
214
+ async function resolveGatewayUrl(explicit) {
215
+ if (explicit)
216
+ return explicit;
217
+ const fromEnv = process.env[exports.ENV_GATEWAY_URL];
218
+ if (fromEnv)
219
+ return fromEnv;
220
+ const config = await _seams.loadConfigFile();
221
+ const agent = config["agent"];
222
+ if (agent !== null && typeof agent === "object") {
223
+ const url = agent["gateway_url"];
224
+ if (typeof url === "string" && url.length > 0)
225
+ return url;
226
+ }
227
+ if (await _seams.probeHealthz(exports.DEFAULT_GATEWAY_URL)) {
228
+ return exports.DEFAULT_GATEWAY_URL;
229
+ }
230
+ await _seams.autoStartGateway(exports.DEFAULT_GATEWAY_URL);
231
+ return exports.DEFAULT_GATEWAY_URL;
232
+ }
233
+ /**
234
+ * Resolve the API key using the same 4-step precedence as the URL.
235
+ *
236
+ * Returns the resolved key (possibly empty for local mode, which
237
+ * accepts unauthenticated agents). Never rejects — an empty API key
238
+ * is the documented "local dev" default per Epic 17.
239
+ */
240
+ async function resolveApiKey(explicit) {
241
+ if (explicit)
242
+ return explicit;
243
+ const fromEnv = process.env[exports.ENV_API_KEY];
244
+ if (fromEnv)
245
+ return fromEnv;
246
+ const config = await _seams.loadConfigFile();
247
+ const agent = config["agent"];
248
+ if (agent !== null && typeof agent === "object") {
249
+ const apiKey = agent["api_key"];
250
+ if (typeof apiKey === "string" && apiKey.length > 0)
251
+ return apiKey;
252
+ }
253
+ return "";
254
+ }
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.startNetworkLayerIfNeeded = exports.registerAdapters = exports.initAssembly = exports.detectFrameworks = exports.createClient = void 0;
4
+ var init_assembly_js_1 = require("./init-assembly.js");
5
+ Object.defineProperty(exports, "createClient", { enumerable: true, get: function () { return init_assembly_js_1.createClient; } });
6
+ Object.defineProperty(exports, "detectFrameworks", { enumerable: true, get: function () { return init_assembly_js_1.detectFrameworks; } });
7
+ Object.defineProperty(exports, "initAssembly", { enumerable: true, get: function () { return init_assembly_js_1.initAssembly; } });
8
+ Object.defineProperty(exports, "registerAdapters", { enumerable: true, get: function () { return init_assembly_js_1.registerAdapters; } });
9
+ Object.defineProperty(exports, "startNetworkLayerIfNeeded", { enumerable: true, get: function () { return init_assembly_js_1.startNetworkLayerIfNeeded; } });
@@ -0,0 +1,224 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createClient = createClient;
4
+ exports.detectFrameworks = detectFrameworks;
5
+ exports.registerAdapters = registerAdapters;
6
+ exports.startNetworkLayerIfNeeded = startNetworkLayerIfNeeded;
7
+ exports.initAssembly = initAssembly;
8
+ const node_module_1 = require("node:module");
9
+ const index_js_1 = require("../adapters/langchain/index.js");
10
+ const client_js_1 = require("../gateway/client.js");
11
+ const client_js_2 = require("../native/client.js");
12
+ const enforcement_mode_js_1 = require("../types/enforcement-mode.js");
13
+ const ai_sdk_detection_js_1 = require("../hooks/ai-sdk-detection.js");
14
+ const ai_sdk_js_1 = require("../hooks/ai-sdk.js");
15
+ const langgraph_detection_js_1 = require("../hooks/langgraph-detection.js");
16
+ const langgraph_js_1 = require("../hooks/langgraph.js");
17
+ const mastra_detection_js_1 = require("../hooks/mastra-detection.js");
18
+ const mastra_js_1 = require("../hooks/mastra.js");
19
+ const openai_agents_detection_js_1 = require("../hooks/openai-agents-detection.js");
20
+ const openai_agents_js_1 = require("../hooks/openai-agents.js");
21
+ const index_js_2 = require("../lineage/index.js");
22
+ const gateway_resolver_js_1 = require("./gateway-resolver.js");
23
+ const requireFromCwd = (0, node_module_1.createRequire)(`${process.cwd()}/`);
24
+ function buildRegistrationEvent(config) {
25
+ const event = { event_type: "register" };
26
+ if (config.parentAgentId !== undefined)
27
+ event.parent_agent_id = config.parentAgentId;
28
+ if (config.teamId !== undefined)
29
+ event.team_id = config.teamId;
30
+ if (config.delegationReason !== undefined)
31
+ event.delegation_reason = config.delegationReason;
32
+ if (config.spawnedByTool !== undefined)
33
+ event.spawned_by_tool = config.spawnedByTool;
34
+ // AAASM-1561: per-agent enforcement_mode override. Sent only when the
35
+ // caller set it explicitly so a pre-feature SDK call produces a pre-feature
36
+ // wire shape. The gateway's REST → gRPC bridge maps the snake_case token
37
+ // onto RegisterRequest.enforcement_mode (proto enum) per AAASM-1555.
38
+ if (config.enforcementMode !== undefined)
39
+ event.enforcement_mode = config.enforcementMode;
40
+ return event;
41
+ }
42
+ function createClient(config) {
43
+ const mode = config.mode ?? "auto";
44
+ if (config.gatewayClient) {
45
+ return config.gatewayClient;
46
+ }
47
+ return (0, client_js_1.createNoopGatewayClient)(mode);
48
+ }
49
+ function isPackageInstalled(packageName) {
50
+ try {
51
+ requireFromCwd.resolve(packageName);
52
+ return true;
53
+ }
54
+ catch {
55
+ return false;
56
+ }
57
+ }
58
+ function detectFrameworks() {
59
+ const detected = [];
60
+ if (isPackageInstalled("@langchain/core")) {
61
+ detected.push("langchain-js");
62
+ }
63
+ if ((0, ai_sdk_detection_js_1.hasVercelAiSdk)()) {
64
+ detected.push("vercel-ai-sdk");
65
+ }
66
+ if ((0, openai_agents_detection_js_1.hasOpenAIAgentsSDK)()) {
67
+ detected.push("openai-agents");
68
+ }
69
+ if ((0, langgraph_detection_js_1.hasLangGraph)()) {
70
+ detected.push("langgraph-js");
71
+ }
72
+ if ((0, mastra_detection_js_1.hasMastra)()) {
73
+ detected.push("mastra");
74
+ }
75
+ return detected;
76
+ }
77
+ function createAdapter(id) {
78
+ return {
79
+ id,
80
+ apply: async () => undefined
81
+ };
82
+ }
83
+ async function registerAdapters(frameworks) {
84
+ const adapters = frameworks.map((framework) => createAdapter(framework));
85
+ for (const adapter of adapters) {
86
+ await adapter.apply();
87
+ }
88
+ return adapters;
89
+ }
90
+ async function startNetworkLayerIfNeeded(client, config) {
91
+ if (config.mode === "sdk-only") {
92
+ return;
93
+ }
94
+ await client.start();
95
+ }
96
+ function ensureLangChainCallbacks(config) {
97
+ config.langchain ??= {};
98
+ config.langchain.callbacks ??= [];
99
+ return config.langchain.callbacks;
100
+ }
101
+ function ensureLangChainTools(config) {
102
+ config.langchain ??= {};
103
+ config.langchain.tools ??= {};
104
+ return config.langchain.tools;
105
+ }
106
+ function registerLangChainHandler(config, client, frameworks) {
107
+ if (!frameworks.includes("langchain-js") && !config.langchain) {
108
+ return undefined;
109
+ }
110
+ const callbacks = ensureLangChainCallbacks(config);
111
+ const handler = new index_js_1.AssemblyCallbackHandler(client);
112
+ callbacks.push(handler);
113
+ return handler;
114
+ }
115
+ function wrapLangChainTools(config, client, frameworks) {
116
+ if (!frameworks.includes("langchain-js") && !config.langchain) {
117
+ return [];
118
+ }
119
+ const tools = ensureLangChainTools(config);
120
+ const wrapperOptions = {
121
+ ...(config.langchain?.approvalTimeoutMs
122
+ ? { approvalTimeoutMs: config.langchain.approvalTimeoutMs }
123
+ : {})
124
+ };
125
+ for (const tool of Object.values(tools)) {
126
+ (0, index_js_1.wrapToolWithAssembly)(tool, client, wrapperOptions);
127
+ }
128
+ return Object.keys(tools);
129
+ }
130
+ async function patchDetectedVercelAiSdk(client, frameworks, agentId) {
131
+ if (!frameworks.includes("vercel-ai-sdk")) {
132
+ return false;
133
+ }
134
+ return (0, ai_sdk_js_1.patchVercelAiSdk)({
135
+ gatewayClient: client,
136
+ ...(agentId !== undefined ? { agentId } : {})
137
+ });
138
+ }
139
+ async function patchDetectedLangGraph(frameworks, agentId) {
140
+ if (!frameworks.includes("langgraph-js") || !agentId) {
141
+ return false;
142
+ }
143
+ return (0, langgraph_js_1.patchLangGraph)({ agentId });
144
+ }
145
+ async function patchDetectedMastra(frameworks, agentId) {
146
+ if (!frameworks.includes("mastra") || !agentId) {
147
+ return false;
148
+ }
149
+ return (0, mastra_js_1.patchMastra)({ agentId });
150
+ }
151
+ async function patchDetectedOpenAIAgents(client, frameworks) {
152
+ if (!frameworks.includes("openai-agents")) {
153
+ return false;
154
+ }
155
+ return (0, openai_agents_js_1.patchOpenAIAgents)({ gatewayClient: client });
156
+ }
157
+ async function initAssembly(config = {}) {
158
+ if (config.delegationReason !== undefined && config.delegationReason.length > 256) {
159
+ throw new RangeError("delegationReason must be <= 256 characters");
160
+ }
161
+ // AAASM-1561: catch invalid enforcementMode strings from non-TS callers
162
+ // (plain JS, JSON config, dynamic input) so the agent doesn't silently
163
+ // register under live enforcement when the operator meant observe.
164
+ if (config.enforcementMode !== undefined && !enforcement_mode_js_1.ENFORCEMENT_MODES.includes(config.enforcementMode)) {
165
+ throw new RangeError(`enforcementMode must be one of: ${enforcement_mode_js_1.ENFORCEMENT_MODES.join(", ")} (got: ${String(config.enforcementMode)})`);
166
+ }
167
+ // Auto-populate parentAgentId from the async context store when not explicitly provided.
168
+ // This allows child agents spawned inside framework hooks to inherit lineage automatically.
169
+ const resolvedParentAgentId = config.parentAgentId ?? (0, index_js_2.currentAgentId)();
170
+ const resolvedGatewayUrl = await (0, gateway_resolver_js_1.resolveGatewayUrl)(config.gatewayUrl);
171
+ const resolvedApiKey = await (0, gateway_resolver_js_1.resolveApiKey)(config.apiKey);
172
+ const resolvedConfig = {
173
+ ...config,
174
+ gatewayUrl: resolvedGatewayUrl,
175
+ apiKey: resolvedApiKey,
176
+ ...(resolvedParentAgentId ? { parentAgentId: resolvedParentAgentId } : {})
177
+ };
178
+ const client = createClient(resolvedConfig);
179
+ const frameworks = detectFrameworks();
180
+ const adapters = await registerAdapters(frameworks);
181
+ await startNetworkLayerIfNeeded(client, resolvedConfig);
182
+ // Send topology registration event through the native transport on every boot
183
+ // except sdk-only mode (which has no sidecar to register with).
184
+ let nativeClient;
185
+ if (resolvedConfig.mode !== "sdk-only") {
186
+ nativeClient = (0, client_js_2.createNativeClient)({
187
+ gateway: resolvedGatewayUrl,
188
+ apiKey: resolvedApiKey,
189
+ mode: resolvedConfig.mode === "napi-inprocess" ? "napi-inprocess" : "grpc-sidecar",
190
+ });
191
+ nativeClient.sendEvent(buildRegistrationEvent(resolvedConfig));
192
+ }
193
+ const langChainHandler = registerLangChainHandler(resolvedConfig, client, frameworks);
194
+ const wrappedLangChainTools = wrapLangChainTools(resolvedConfig, client, frameworks);
195
+ const vercelAiSdkPatched = await patchDetectedVercelAiSdk(client, frameworks, resolvedConfig.agentId);
196
+ const openAIAgentsPatched = await patchDetectedOpenAIAgents(client, frameworks);
197
+ const langGraphPatched = await patchDetectedLangGraph(frameworks, resolvedConfig.agentId);
198
+ const mastraPatched = await patchDetectedMastra(frameworks, resolvedConfig.agentId);
199
+ return {
200
+ activeAdapters: [
201
+ ...new Set([
202
+ ...adapters.map((adapter) => adapter.id),
203
+ ...(langChainHandler ? ["langchain-js"] : []),
204
+ ...(wrappedLangChainTools.length > 0 ? ["langchain-js"] : []),
205
+ ...(vercelAiSdkPatched ? ["vercel-ai-sdk"] : []),
206
+ ...(openAIAgentsPatched ? ["openai-agents"] : []),
207
+ ...(langGraphPatched ? ["langgraph-js"] : []),
208
+ ...(mastraPatched ? ["mastra"] : [])
209
+ ])
210
+ ],
211
+ ...(resolvedConfig.parentAgentId !== undefined && { parentAgentId: resolvedConfig.parentAgentId }),
212
+ ...(resolvedConfig.teamId !== undefined && { teamId: resolvedConfig.teamId }),
213
+ ...(resolvedConfig.delegationReason !== undefined && { delegationReason: resolvedConfig.delegationReason }),
214
+ ...(resolvedConfig.spawnedByTool !== undefined && { spawnedByTool: resolvedConfig.spawnedByTool }),
215
+ ...(resolvedConfig.enforcementMode !== undefined && { enforcementMode: resolvedConfig.enforcementMode }),
216
+ shutdown: async () => {
217
+ for (const adapter of adapters) {
218
+ await adapter.shutdown?.();
219
+ }
220
+ await nativeClient?.close();
221
+ await client.close();
222
+ }
223
+ };
224
+ }