managed-deepagents 0.4.2 → 0.4.3-dev.95

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 (449) hide show
  1. package/README.md +78 -35
  2. package/dist/channels/assistant-text.js +1 -1
  3. package/dist/channels/assistant-text.js.map +1 -1
  4. package/dist/channels/binding.d.ts.map +1 -1
  5. package/dist/channels/binding.js +3 -1
  6. package/dist/channels/binding.js.map +1 -1
  7. package/dist/channels/index.d.ts +7 -8
  8. package/dist/channels/index.d.ts.map +1 -1
  9. package/dist/channels/index.js +6 -5
  10. package/dist/channels/index.js.map +1 -1
  11. package/dist/channels/manifest.d.ts +7 -4
  12. package/dist/channels/manifest.d.ts.map +1 -1
  13. package/dist/channels/messaging-registry.d.ts +21 -0
  14. package/dist/channels/messaging-registry.d.ts.map +1 -0
  15. package/dist/channels/messaging-registry.js +50 -0
  16. package/dist/channels/messaging-registry.js.map +1 -0
  17. package/dist/channels/registry-types.d.ts +1 -1
  18. package/dist/channels/registry.d.ts +4 -3
  19. package/dist/channels/registry.d.ts.map +1 -1
  20. package/dist/channels/registry.js +5 -6
  21. package/dist/channels/registry.js.map +1 -1
  22. package/dist/channels/schedule-delivery.d.ts +4 -1
  23. package/dist/channels/schedule-delivery.d.ts.map +1 -1
  24. package/dist/channels/schedule-delivery.js +3 -1
  25. package/dist/channels/schedule-delivery.js.map +1 -1
  26. package/dist/channels/slack/adapter.d.ts +1 -2
  27. package/dist/channels/slack/adapter.d.ts.map +1 -1
  28. package/dist/channels/slack/adapter.js +0 -2
  29. package/dist/channels/slack/adapter.js.map +1 -1
  30. package/dist/channels/slack/http.d.ts +7 -39
  31. package/dist/channels/slack/http.d.ts.map +1 -1
  32. package/dist/channels/slack/http.js +64 -122
  33. package/dist/channels/slack/http.js.map +1 -1
  34. package/dist/channels/slack/index.d.ts +94 -8
  35. package/dist/channels/slack/index.d.ts.map +1 -1
  36. package/dist/channels/slack/index.js +144 -6
  37. package/dist/channels/slack/index.js.map +1 -1
  38. package/dist/channels/slack/normalize.d.ts +6 -4
  39. package/dist/channels/slack/normalize.d.ts.map +1 -1
  40. package/dist/channels/slack/normalize.js +61 -28
  41. package/dist/channels/slack/normalize.js.map +1 -1
  42. package/dist/channels/slack/transport.d.ts.map +1 -1
  43. package/dist/channels/slack/transport.js +3 -2
  44. package/dist/channels/slack/transport.js.map +1 -1
  45. package/dist/channels/store.d.ts +14 -0
  46. package/dist/channels/store.d.ts.map +1 -1
  47. package/dist/channels/store.js +41 -27
  48. package/dist/channels/store.js.map +1 -1
  49. package/dist/connectors/marketplace/catalog.d.ts +96 -0
  50. package/dist/connectors/marketplace/catalog.d.ts.map +1 -0
  51. package/dist/connectors/marketplace/catalog.js +213 -0
  52. package/dist/connectors/marketplace/catalog.js.map +1 -0
  53. package/dist/connectors/marketplace/fleet-mcp.d.ts +62 -0
  54. package/dist/connectors/marketplace/fleet-mcp.d.ts.map +1 -0
  55. package/dist/connectors/marketplace/fleet-mcp.js +215 -0
  56. package/dist/connectors/marketplace/fleet-mcp.js.map +1 -0
  57. package/dist/connectors/marketplace/index.d.ts +31 -0
  58. package/dist/connectors/marketplace/index.d.ts.map +1 -0
  59. package/dist/connectors/marketplace/index.js +39 -0
  60. package/dist/connectors/marketplace/index.js.map +1 -0
  61. package/dist/connectors/marketplace/load.d.ts +14 -0
  62. package/dist/connectors/marketplace/load.d.ts.map +1 -0
  63. package/dist/connectors/marketplace/load.js +206 -0
  64. package/dist/connectors/marketplace/load.js.map +1 -0
  65. package/dist/connectors/mcp/index.d.ts +13 -20
  66. package/dist/connectors/mcp/index.d.ts.map +1 -1
  67. package/dist/connectors/mcp/index.js +92 -112
  68. package/dist/connectors/mcp/index.js.map +1 -1
  69. package/dist/connectors/mcp/load.d.ts.map +1 -1
  70. package/dist/connectors/mcp/load.js +16 -40
  71. package/dist/connectors/mcp/load.js.map +1 -1
  72. package/dist/connectors/slack/index.d.ts +24 -0
  73. package/dist/connectors/slack/index.d.ts.map +1 -0
  74. package/dist/connectors/slack/index.js +64 -0
  75. package/dist/connectors/slack/index.js.map +1 -0
  76. package/dist/connectors/tool-selection.d.ts +55 -0
  77. package/dist/connectors/tool-selection.d.ts.map +1 -0
  78. package/dist/connectors/tool-selection.js +112 -0
  79. package/dist/connectors/tool-selection.js.map +1 -0
  80. package/dist/connectors/toolserver/catalog.d.ts +326 -0
  81. package/dist/connectors/toolserver/catalog.d.ts.map +1 -0
  82. package/dist/connectors/toolserver/catalog.js +415 -0
  83. package/dist/connectors/toolserver/catalog.js.map +1 -0
  84. package/dist/connectors/toolserver/connectors.d.ts +698 -0
  85. package/dist/connectors/toolserver/connectors.d.ts.map +1 -0
  86. package/dist/connectors/toolserver/connectors.js +13 -0
  87. package/dist/connectors/toolserver/connectors.js.map +1 -0
  88. package/dist/connectors/toolserver/index.d.ts +142 -0
  89. package/dist/connectors/toolserver/index.d.ts.map +1 -0
  90. package/dist/connectors/toolserver/index.js +105 -0
  91. package/dist/connectors/toolserver/index.js.map +1 -0
  92. package/dist/connectors/toolserver/integrations.d.ts +103 -0
  93. package/dist/connectors/toolserver/integrations.d.ts.map +1 -0
  94. package/dist/connectors/toolserver/integrations.js +288 -0
  95. package/dist/connectors/toolserver/integrations.js.map +1 -0
  96. package/dist/connectors/toolserver/load.d.ts +55 -0
  97. package/dist/connectors/toolserver/load.d.ts.map +1 -0
  98. package/dist/connectors/toolserver/load.js +289 -0
  99. package/dist/connectors/toolserver/load.js.map +1 -0
  100. package/dist/define-deep-agent.d.ts.map +1 -1
  101. package/dist/define-deep-agent.js +9 -3
  102. package/dist/define-deep-agent.js.map +1 -1
  103. package/dist/extension.d.ts +69 -0
  104. package/dist/extension.d.ts.map +1 -0
  105. package/dist/extension.js +108 -0
  106. package/dist/extension.js.map +1 -0
  107. package/dist/identity/actor-subject.d.ts +60 -0
  108. package/dist/identity/actor-subject.d.ts.map +1 -0
  109. package/dist/identity/actor-subject.js +107 -0
  110. package/dist/identity/actor-subject.js.map +1 -0
  111. package/dist/identity/byo-oauth.d.ts +105 -0
  112. package/dist/identity/byo-oauth.d.ts.map +1 -0
  113. package/dist/identity/byo-oauth.js +190 -0
  114. package/dist/identity/byo-oauth.js.map +1 -0
  115. package/dist/identity/claims.d.ts +16 -0
  116. package/dist/identity/claims.d.ts.map +1 -0
  117. package/dist/identity/claims.js +33 -0
  118. package/dist/identity/claims.js.map +1 -0
  119. package/dist/identity/connect-inference.d.ts +37 -0
  120. package/dist/identity/connect-inference.d.ts.map +1 -0
  121. package/dist/identity/connect-inference.js +53 -0
  122. package/dist/identity/connect-inference.js.map +1 -0
  123. package/dist/identity/connect-provider-types.d.ts +35 -6
  124. package/dist/identity/connect-provider-types.d.ts.map +1 -1
  125. package/dist/identity/connect-provider-types.js +3 -1
  126. package/dist/identity/connect-provider-types.js.map +1 -1
  127. package/dist/identity/connect-provider.d.ts +9 -4
  128. package/dist/identity/connect-provider.d.ts.map +1 -1
  129. package/dist/identity/connect-provider.js +39 -13
  130. package/dist/identity/connect-provider.js.map +1 -1
  131. package/dist/identity/credential-resolvers.d.ts +33 -0
  132. package/dist/identity/credential-resolvers.d.ts.map +1 -0
  133. package/dist/identity/credential-resolvers.js +62 -0
  134. package/dist/identity/credential-resolvers.js.map +1 -0
  135. package/dist/identity/define-fleet-connect.d.ts +53 -0
  136. package/dist/identity/define-fleet-connect.d.ts.map +1 -0
  137. package/dist/identity/define-fleet-connect.js +76 -0
  138. package/dist/identity/define-fleet-connect.js.map +1 -0
  139. package/dist/identity/fleet-connect-hint.d.ts +41 -0
  140. package/dist/identity/fleet-connect-hint.d.ts.map +1 -0
  141. package/dist/identity/fleet-connect-hint.js +190 -0
  142. package/dist/identity/fleet-connect-hint.js.map +1 -0
  143. package/dist/identity/fleet-connect.d.ts +93 -0
  144. package/dist/identity/fleet-connect.d.ts.map +1 -0
  145. package/dist/identity/fleet-connect.js +256 -0
  146. package/dist/identity/fleet-connect.js.map +1 -0
  147. package/dist/identity/fleet-integration-connect.d.ts +32 -0
  148. package/dist/identity/fleet-integration-connect.d.ts.map +1 -0
  149. package/dist/identity/fleet-integration-connect.js +35 -0
  150. package/dist/identity/fleet-integration-connect.js.map +1 -0
  151. package/dist/identity/fleet.d.ts +56 -0
  152. package/dist/identity/fleet.d.ts.map +1 -0
  153. package/dist/identity/fleet.js +131 -0
  154. package/dist/identity/fleet.js.map +1 -0
  155. package/dist/identity/github/connect-http.d.ts +8 -4
  156. package/dist/identity/github/connect-http.d.ts.map +1 -1
  157. package/dist/identity/github/connect-http.js +32 -15
  158. package/dist/identity/github/connect-http.js.map +1 -1
  159. package/dist/identity/github/credentials-store.d.ts +10 -10
  160. package/dist/identity/github/credentials-store.d.ts.map +1 -1
  161. package/dist/identity/github/credentials-store.js +62 -49
  162. package/dist/identity/github/credentials-store.js.map +1 -1
  163. package/dist/identity/github/credentials.d.ts +16 -13
  164. package/dist/identity/github/credentials.d.ts.map +1 -1
  165. package/dist/identity/github/credentials.js +43 -23
  166. package/dist/identity/github/credentials.js.map +1 -1
  167. package/dist/identity/github/index.d.ts +1 -4
  168. package/dist/identity/github/index.d.ts.map +1 -1
  169. package/dist/identity/github/index.js +0 -3
  170. package/dist/identity/github/index.js.map +1 -1
  171. package/dist/identity/github/oauth.d.ts +18 -20
  172. package/dist/identity/github/oauth.d.ts.map +1 -1
  173. package/dist/identity/github/oauth.js +90 -109
  174. package/dist/identity/github/oauth.js.map +1 -1
  175. package/dist/identity/google/connect-http.d.ts +37 -0
  176. package/dist/identity/google/connect-http.d.ts.map +1 -0
  177. package/dist/identity/google/connect-http.js +42 -0
  178. package/dist/identity/google/connect-http.js.map +1 -0
  179. package/dist/identity/google/index.d.ts +7 -0
  180. package/dist/identity/google/index.d.ts.map +1 -0
  181. package/dist/identity/google/index.js +6 -0
  182. package/dist/identity/google/index.js.map +1 -0
  183. package/dist/identity/google/oauth.d.ts +22 -0
  184. package/dist/identity/google/oauth.d.ts.map +1 -0
  185. package/dist/identity/google/oauth.js +48 -0
  186. package/dist/identity/google/oauth.js.map +1 -0
  187. package/dist/identity/index.d.ts +40 -64
  188. package/dist/identity/index.d.ts.map +1 -1
  189. package/dist/identity/index.js +104 -243
  190. package/dist/identity/index.js.map +1 -1
  191. package/dist/identity/linkedin/connect-http.d.ts +37 -0
  192. package/dist/identity/linkedin/connect-http.d.ts.map +1 -0
  193. package/dist/identity/linkedin/connect-http.js +41 -0
  194. package/dist/identity/linkedin/connect-http.js.map +1 -0
  195. package/dist/identity/linkedin/index.d.ts +7 -0
  196. package/dist/identity/linkedin/index.d.ts.map +1 -0
  197. package/dist/identity/linkedin/index.js +6 -0
  198. package/dist/identity/linkedin/index.js.map +1 -0
  199. package/dist/identity/linkedin/oauth.d.ts +22 -0
  200. package/dist/identity/linkedin/oauth.d.ts.map +1 -0
  201. package/dist/identity/linkedin/oauth.js +47 -0
  202. package/dist/identity/linkedin/oauth.js.map +1 -0
  203. package/dist/identity/loopback.d.ts +27 -2
  204. package/dist/identity/loopback.d.ts.map +1 -1
  205. package/dist/identity/loopback.js +61 -8
  206. package/dist/identity/loopback.js.map +1 -1
  207. package/dist/identity/marketplace/connect-hint.d.ts +31 -0
  208. package/dist/identity/marketplace/connect-hint.d.ts.map +1 -0
  209. package/dist/identity/marketplace/connect-hint.js +59 -0
  210. package/dist/identity/marketplace/connect-hint.js.map +1 -0
  211. package/dist/identity/marketplace/connect.d.ts +51 -0
  212. package/dist/identity/marketplace/connect.d.ts.map +1 -0
  213. package/dist/identity/marketplace/connect.js +88 -0
  214. package/dist/identity/marketplace/connect.js.map +1 -0
  215. package/dist/identity/marketplace/index.d.ts +9 -0
  216. package/dist/identity/marketplace/index.d.ts.map +1 -0
  217. package/dist/identity/marketplace/index.js +9 -0
  218. package/dist/identity/marketplace/index.js.map +1 -0
  219. package/dist/identity/microsoft/connect-http.d.ts +38 -0
  220. package/dist/identity/microsoft/connect-http.d.ts.map +1 -0
  221. package/dist/identity/microsoft/connect-http.js +42 -0
  222. package/dist/identity/microsoft/connect-http.js.map +1 -0
  223. package/dist/identity/microsoft/index.d.ts +7 -0
  224. package/dist/identity/microsoft/index.d.ts.map +1 -0
  225. package/dist/identity/microsoft/index.js +6 -0
  226. package/dist/identity/microsoft/index.js.map +1 -0
  227. package/dist/identity/microsoft/oauth.d.ts +24 -0
  228. package/dist/identity/microsoft/oauth.d.ts.map +1 -0
  229. package/dist/identity/microsoft/oauth.js +65 -0
  230. package/dist/identity/microsoft/oauth.js.map +1 -0
  231. package/dist/identity/oauth-env.d.ts +43 -0
  232. package/dist/identity/oauth-env.d.ts.map +1 -0
  233. package/dist/identity/oauth-env.js +66 -0
  234. package/dist/identity/oauth-env.js.map +1 -0
  235. package/dist/identity/oauth-tickets.d.ts +37 -0
  236. package/dist/identity/oauth-tickets.d.ts.map +1 -0
  237. package/dist/identity/oauth-tickets.js +114 -0
  238. package/dist/identity/oauth-tickets.js.map +1 -0
  239. package/dist/identity/options.d.ts +35 -0
  240. package/dist/identity/options.d.ts.map +1 -0
  241. package/dist/identity/options.js +80 -0
  242. package/dist/identity/options.js.map +1 -0
  243. package/dist/identity/slack/connect-http.d.ts +6 -4
  244. package/dist/identity/slack/connect-http.d.ts.map +1 -1
  245. package/dist/identity/slack/connect-http.js +27 -17
  246. package/dist/identity/slack/connect-http.js.map +1 -1
  247. package/dist/identity/slack/index.d.ts +1 -2
  248. package/dist/identity/slack/index.d.ts.map +1 -1
  249. package/dist/identity/slack/index.js +1 -2
  250. package/dist/identity/slack/index.js.map +1 -1
  251. package/dist/identity/slack/links.d.ts +18 -17
  252. package/dist/identity/slack/links.d.ts.map +1 -1
  253. package/dist/identity/slack/links.js +75 -61
  254. package/dist/identity/slack/links.js.map +1 -1
  255. package/dist/identity/slack/oauth.d.ts +3 -35
  256. package/dist/identity/slack/oauth.d.ts.map +1 -1
  257. package/dist/identity/slack/oauth.js +9 -115
  258. package/dist/identity/slack/oauth.js.map +1 -1
  259. package/dist/identity/supabase.js +9 -9
  260. package/dist/identity/supabase.js.map +1 -1
  261. package/dist/identity/types.d.ts +91 -54
  262. package/dist/identity/types.d.ts.map +1 -1
  263. package/dist/identity/x/connect-http.d.ts +38 -0
  264. package/dist/identity/x/connect-http.d.ts.map +1 -0
  265. package/dist/identity/x/connect-http.js +41 -0
  266. package/dist/identity/x/connect-http.js.map +1 -0
  267. package/dist/identity/x/index.d.ts +6 -0
  268. package/dist/identity/x/index.d.ts.map +1 -0
  269. package/dist/identity/x/index.js +5 -0
  270. package/dist/identity/x/index.js.map +1 -0
  271. package/dist/index.d.ts +9 -20
  272. package/dist/index.d.ts.map +1 -1
  273. package/dist/index.js +3 -11
  274. package/dist/index.js.map +1 -1
  275. package/dist/ingress/index.d.ts +52 -0
  276. package/dist/ingress/index.d.ts.map +1 -0
  277. package/dist/ingress/index.js +139 -0
  278. package/dist/ingress/index.js.map +1 -0
  279. package/dist/memory/define-memory.d.ts +39 -0
  280. package/dist/memory/define-memory.d.ts.map +1 -0
  281. package/dist/memory/define-memory.js +78 -0
  282. package/dist/memory/define-memory.js.map +1 -0
  283. package/dist/memory/index.d.ts +9 -0
  284. package/dist/memory/index.d.ts.map +1 -0
  285. package/dist/memory/index.js +8 -0
  286. package/dist/memory/index.js.map +1 -0
  287. package/dist/memory/instructions-middleware.d.ts +74 -0
  288. package/dist/memory/instructions-middleware.d.ts.map +1 -0
  289. package/dist/memory/instructions-middleware.js +115 -0
  290. package/dist/memory/instructions-middleware.js.map +1 -0
  291. package/dist/memory/slices.d.ts +21 -0
  292. package/dist/memory/slices.d.ts.map +1 -0
  293. package/dist/memory/slices.js +61 -0
  294. package/dist/memory/slices.js.map +1 -0
  295. package/dist/memory/types.d.ts +71 -0
  296. package/dist/memory/types.d.ts.map +1 -0
  297. package/dist/memory/types.js +10 -0
  298. package/dist/memory/types.js.map +1 -0
  299. package/dist/namespaces.d.ts +262 -0
  300. package/dist/namespaces.d.ts.map +1 -0
  301. package/dist/namespaces.js +101 -0
  302. package/dist/namespaces.js.map +1 -0
  303. package/dist/runtime/auth.d.ts +46 -32
  304. package/dist/runtime/auth.d.ts.map +1 -1
  305. package/dist/runtime/auth.js +234 -125
  306. package/dist/runtime/auth.js.map +1 -1
  307. package/dist/runtime/backend.d.ts +1 -1
  308. package/dist/runtime/backend.d.ts.map +1 -1
  309. package/dist/runtime/backend.js +26 -5
  310. package/dist/runtime/backend.js.map +1 -1
  311. package/dist/runtime/channel.d.ts +91 -0
  312. package/dist/runtime/channel.d.ts.map +1 -0
  313. package/dist/runtime/channel.js +98 -0
  314. package/dist/runtime/channel.js.map +1 -0
  315. package/dist/runtime/connector.d.ts +66 -23
  316. package/dist/runtime/connector.d.ts.map +1 -1
  317. package/dist/runtime/connector.js +67 -27
  318. package/dist/runtime/connector.js.map +1 -1
  319. package/dist/runtime/cors.d.ts +12 -3
  320. package/dist/runtime/cors.d.ts.map +1 -1
  321. package/dist/runtime/cors.js +23 -5
  322. package/dist/runtime/cors.js.map +1 -1
  323. package/dist/runtime/credentials.d.ts +8 -8
  324. package/dist/runtime/credentials.d.ts.map +1 -1
  325. package/dist/runtime/credentials.js +46 -23
  326. package/dist/runtime/credentials.js.map +1 -1
  327. package/dist/runtime/http.d.ts +46 -0
  328. package/dist/runtime/http.d.ts.map +1 -0
  329. package/dist/runtime/http.js +53 -0
  330. package/dist/runtime/http.js.map +1 -0
  331. package/dist/runtime/identity-http.d.ts +13 -20
  332. package/dist/runtime/identity-http.d.ts.map +1 -1
  333. package/dist/runtime/identity-http.js +158 -75
  334. package/dist/runtime/identity-http.js.map +1 -1
  335. package/dist/runtime/identity-runtime.d.ts +12 -28
  336. package/dist/runtime/identity-runtime.d.ts.map +1 -1
  337. package/dist/runtime/identity-runtime.js +35 -72
  338. package/dist/runtime/identity-runtime.js.map +1 -1
  339. package/dist/runtime/index.d.ts +89 -225
  340. package/dist/runtime/index.d.ts.map +1 -1
  341. package/dist/runtime/index.js +92 -61
  342. package/dist/runtime/index.js.map +1 -1
  343. package/dist/runtime/memory/index.d.ts +0 -2
  344. package/dist/runtime/memory/index.d.ts.map +1 -1
  345. package/dist/runtime/memory/index.js +0 -2
  346. package/dist/runtime/memory/index.js.map +1 -1
  347. package/dist/runtime/memory/mounts.d.ts +4 -12
  348. package/dist/runtime/memory/mounts.d.ts.map +1 -1
  349. package/dist/runtime/memory/mounts.js +9 -20
  350. package/dist/runtime/memory/mounts.js.map +1 -1
  351. package/dist/runtime/recursion-limit.d.ts +22 -0
  352. package/dist/runtime/recursion-limit.d.ts.map +1 -0
  353. package/dist/runtime/recursion-limit.js +46 -0
  354. package/dist/runtime/recursion-limit.js.map +1 -0
  355. package/dist/runtime/sandbox-manager.d.ts +60 -3
  356. package/dist/runtime/sandbox-manager.d.ts.map +1 -1
  357. package/dist/runtime/sandbox-manager.js +326 -26
  358. package/dist/runtime/sandbox-manager.js.map +1 -1
  359. package/dist/runtime/sandbox-stream-retry.d.ts +18 -0
  360. package/dist/runtime/sandbox-stream-retry.d.ts.map +1 -0
  361. package/dist/runtime/sandbox-stream-retry.js +90 -0
  362. package/dist/runtime/sandbox-stream-retry.js.map +1 -0
  363. package/dist/runtime/setup-script.d.ts.map +1 -1
  364. package/dist/runtime/setup-script.js +16 -2
  365. package/dist/runtime/setup-script.js.map +1 -1
  366. package/dist/runtime/types.d.ts +16 -0
  367. package/dist/runtime/types.d.ts.map +1 -1
  368. package/dist/runtime/validated-token.d.ts +9 -14
  369. package/dist/runtime/validated-token.d.ts.map +1 -1
  370. package/dist/runtime/validated-token.js +79 -106
  371. package/dist/runtime/validated-token.js.map +1 -1
  372. package/dist/sandbox.d.ts +17 -42
  373. package/dist/sandbox.d.ts.map +1 -1
  374. package/dist/sandbox.js +11 -32
  375. package/dist/sandbox.js.map +1 -1
  376. package/dist/schedules.js +8 -9
  377. package/dist/schedules.js.map +1 -1
  378. package/dist/types.d.ts +4 -3
  379. package/dist/types.d.ts.map +1 -1
  380. package/dist/types.js.map +1 -1
  381. package/package.json +22 -29
  382. package/dist/channels/collect.d.ts +0 -26
  383. package/dist/channels/collect.d.ts.map +0 -1
  384. package/dist/channels/collect.js +0 -42
  385. package/dist/channels/collect.js.map +0 -1
  386. package/dist/channels/github/adapter-core.d.ts +0 -6
  387. package/dist/channels/github/adapter-core.d.ts.map +0 -1
  388. package/dist/channels/github/adapter-core.js +0 -27
  389. package/dist/channels/github/adapter-core.js.map +0 -1
  390. package/dist/channels/github/adapter.d.ts +0 -16
  391. package/dist/channels/github/adapter.d.ts.map +0 -1
  392. package/dist/channels/github/adapter.js +0 -52
  393. package/dist/channels/github/adapter.js.map +0 -1
  394. package/dist/channels/github/define.d.ts +0 -198
  395. package/dist/channels/github/define.d.ts.map +0 -1
  396. package/dist/channels/github/define.js +0 -166
  397. package/dist/channels/github/define.js.map +0 -1
  398. package/dist/channels/github/http.d.ts +0 -25
  399. package/dist/channels/github/http.d.ts.map +0 -1
  400. package/dist/channels/github/http.js +0 -147
  401. package/dist/channels/github/http.js.map +0 -1
  402. package/dist/channels/github/index.d.ts +0 -12
  403. package/dist/channels/github/index.d.ts.map +0 -1
  404. package/dist/channels/github/index.js +0 -10
  405. package/dist/channels/github/index.js.map +0 -1
  406. package/dist/channels/github/normalize.d.ts +0 -32
  407. package/dist/channels/github/normalize.d.ts.map +0 -1
  408. package/dist/channels/github/normalize.js +0 -152
  409. package/dist/channels/github/normalize.js.map +0 -1
  410. package/dist/channels/github/source-thread.d.ts +0 -24
  411. package/dist/channels/github/source-thread.d.ts.map +0 -1
  412. package/dist/channels/github/source-thread.js +0 -54
  413. package/dist/channels/github/source-thread.js.map +0 -1
  414. package/dist/channels/github/transport.d.ts +0 -19
  415. package/dist/channels/github/transport.d.ts.map +0 -1
  416. package/dist/channels/github/transport.js +0 -92
  417. package/dist/channels/github/transport.js.map +0 -1
  418. package/dist/channels/plugin.d.ts +0 -61
  419. package/dist/channels/plugin.d.ts.map +0 -1
  420. package/dist/channels/plugin.js +0 -80
  421. package/dist/channels/plugin.js.map +0 -1
  422. package/dist/channels/slack/define.d.ts +0 -74
  423. package/dist/channels/slack/define.d.ts.map +0 -1
  424. package/dist/channels/slack/define.js +0 -160
  425. package/dist/channels/slack/define.js.map +0 -1
  426. package/dist/connectors/github/index.d.ts +0 -78
  427. package/dist/connectors/github/index.d.ts.map +0 -1
  428. package/dist/connectors/github/index.js +0 -106
  429. package/dist/connectors/github/index.js.map +0 -1
  430. package/dist/connectors/github/sandbox.d.ts +0 -54
  431. package/dist/connectors/github/sandbox.d.ts.map +0 -1
  432. package/dist/connectors/github/sandbox.js +0 -515
  433. package/dist/connectors/github/sandbox.js.map +0 -1
  434. package/dist/connectors/langsmith/index.d.ts +0 -385
  435. package/dist/connectors/langsmith/index.d.ts.map +0 -1
  436. package/dist/connectors/langsmith/index.js +0 -431
  437. package/dist/connectors/langsmith/index.js.map +0 -1
  438. package/dist/connectors/langsmith/routes.d.ts +0 -247
  439. package/dist/connectors/langsmith/routes.d.ts.map +0 -1
  440. package/dist/connectors/langsmith/routes.js +0 -1182
  441. package/dist/connectors/langsmith/routes.js.map +0 -1
  442. package/dist/runtime/memory/seed.d.ts +0 -21
  443. package/dist/runtime/memory/seed.d.ts.map +0 -1
  444. package/dist/runtime/memory/seed.js +0 -160
  445. package/dist/runtime/memory/seed.js.map +0 -1
  446. package/dist/runtime/memory/user-repo.d.ts +0 -19
  447. package/dist/runtime/memory/user-repo.d.ts.map +0 -1
  448. package/dist/runtime/memory/user-repo.js +0 -57
  449. package/dist/runtime/memory/user-repo.js.map +0 -1
@@ -1,1182 +0,0 @@
1
- /**
2
- * LangSmith connector — runtime enforcement engine.
3
- *
4
- * Mounted by the connector's `http(ctx)` hook on its namespaced sub-router.
5
- * Exposes one uniform endpoint per capability:
6
- *
7
- * POST /connectors/langsmith/capabilities/{capability_id}
8
- *
9
- * with a JSON body naming the `action` and its parameters. Per request the
10
- * engine resolves identity (resolve-or-401), checks the caller surface, checks
11
- * the action, proves capability ownership from `runtime.identity`, validates typed
12
- * constraints, performs the LangSmith operation server-side with the workspace
13
- * key, and returns an allowlisted response.
14
- *
15
- * v0 has no rate limiting, audit, or multi-workspace fan-out.
16
- */
17
- import { Client } from "langsmith";
18
- import { resolveLoopbackApiUrl } from "../../identity/loopback.js";
19
- import { ACTOR_HEADER, INGRESS_SECRET_HEADER, TENANT_HEADER, } from "../../runtime/auth.js";
20
- /** An error carrying an HTTP status the engine surfaces to the caller. */
21
- export class EnforcementError extends Error {
22
- status;
23
- /**
24
- * @param status - HTTP status code returned to the caller.
25
- * @param message - Human-readable error detail.
26
- */
27
- constructor(status, message) {
28
- super(message);
29
- this.status = status;
30
- this.name = "EnforcementError";
31
- }
32
- }
33
- /**
34
- * Mount the capability route on the connector's namespaced sub-router. Runs the
35
- * identity-dependent authoring checks at mount time (fails startup on an illegal
36
- * scope/ingress combination), then registers the uniform POST endpoint.
37
- *
38
- * @param ctx - HTTP mount context with the namespaced router and identity config.
39
- * @param capabilities - Declared LangSmith capabilities to expose.
40
- * @param client - LangSmith client used for server-side operations; defaults to {@link defaultClient}.
41
- */
42
- export function mountLangSmithRoutes(ctx, capabilities, client = defaultClient()) {
43
- validateAgainstIdentity(capabilities, ctx.identity);
44
- const deps = {
45
- capabilitiesById: new Map(capabilities.map((c) => [c.id, c])),
46
- client,
47
- identityConfig: ctx.identity,
48
- };
49
- // Registered on the secure-by-default router, which resolves and enforces
50
- // identity before this runs and injects the frozen identity as the handler's
51
- // second argument.
52
- ctx.router.post("/capabilities/:id", (request, identity) => handleCapabilityRequest(request, identity, deps));
53
- }
54
- /**
55
- * Identity-aware authoring validation, run when the app is constructed.
56
- * Rejects illegal scope/ingress combinations before any request is served.
57
- *
58
- * @param capabilities - Declared LangSmith capabilities to validate.
59
- * @param identity - Deployment identity config, or `undefined` when identity is not configured.
60
- * @throws {Error} When a capability's scope, exposure, or tenancy is illegal for this deployment.
61
- */
62
- export function validateAgainstIdentity(capabilities, identity) {
63
- const httpMode = identity?.ingress.http;
64
- const hasValidatedToken = httpMode !== undefined && httpMode !== "trusted_backend";
65
- const tenancy = identity?.tenancy ?? "single";
66
- for (const capability of capabilities) {
67
- const externallyExposed = capability.exposeTo.length > 0;
68
- const identityScoped = capability.scope === "actor" ||
69
- capability.scope === "tenant" ||
70
- capability.scope === "thread" ||
71
- capability.scope === "run";
72
- if (!identity) {
73
- const readOnly = capability.actions.every((a) => a.startsWith("read"));
74
- if (externallyExposed && !(capability.scope === "agent" && readOnly)) {
75
- throw new Error(`LangSmith capability "${capability.id}" is exposed externally but the ` +
76
- `deployment has no identity configured. Only agent-scoped, read-only ` +
77
- `capabilities may be exposed without identity.`);
78
- }
79
- continue;
80
- }
81
- if (capability.scope === "tenant" && tenancy === "single") {
82
- throw new Error(`LangSmith capability "${capability.id}" is tenant-scoped but the ` +
83
- `deployment is tenancy: "single".`);
84
- }
85
- if (capability.exposeTo.includes("browser") &&
86
- identityScoped &&
87
- !hasValidatedToken) {
88
- throw new Error(`LangSmith capability "${capability.id}" is ${capability.scope}-scoped and ` +
89
- `exposed to browser, but the deployment has no validated_token ingress ` +
90
- `to resolve an end-user identity.`);
91
- }
92
- }
93
- }
94
- /**
95
- * Per-request enforcement pipeline for a capability POST.
96
- * Resolves the capability, checks surface/action, proves thread ownership when
97
- * needed, enforces scope, performs the LangSmith call, and shapes the response.
98
- *
99
- * @param request - Incoming HTTP request for `/capabilities/:id`.
100
- * @param identity - Frozen runtime identity resolved by the secure router.
101
- * @param deps - Closed-over capabilities map, LangSmith client, and optional access prover.
102
- * @returns JSON `Response` with `{ data }` on success or `{ error }` on failure.
103
- */
104
- export async function handleCapabilityRequest(request, identity, deps) {
105
- try {
106
- const capabilityId = capabilityIdFromUrl(request.url);
107
- const capability = deps.capabilitiesById.get(capabilityId);
108
- if (!capability) {
109
- throw new EnforcementError(404, `unknown capability "${capabilityId}"`);
110
- }
111
- const surface = callerSurface(identity, deps.identityConfig);
112
- if (!capability.exposeTo.includes(surface)) {
113
- throw new EnforcementError(403, `capability "${capability.id}" is not exposed to ${surface}`);
114
- }
115
- const body = await parseJsonBody(request);
116
- const action = String(body.action ?? "");
117
- if (!capability.actions.includes(action)) {
118
- throw new EnforcementError(403, `action "${action}" is not allowed for capability "${capability.id}"`);
119
- }
120
- // Connector HTTP has no LangGraph configurable.thread_id. Resolve a thread
121
- // id from identity / run / body, prove access when it is client-supplied,
122
- // then bind the proven id onto identity for the rest of the request.
123
- const assertThreadAccess = deps.assertThreadAccess ??
124
- defaultAssertThreadAccess(request, identity, deps.identityConfig);
125
- const provenThreadId = await resolveProvenThreadId(capability, identity, body, deps.client, assertThreadAccess);
126
- const scopedIdentity = provenThreadId
127
- ? withIdentityThread(identity, provenThreadId)
128
- : identity;
129
- await assertCapabilityScope(capability, scopedIdentity, body, deps.client);
130
- const raw = toRecord(await performLangSmithCall(capability, action, body, deps, scopedIdentity));
131
- const shaped = shapeResponse(raw, capability);
132
- return jsonResponse(200, { data: shaped });
133
- }
134
- catch (error) {
135
- if (error instanceof EnforcementError) {
136
- return jsonResponse(error.status, { error: error.message });
137
- }
138
- const status = statusFromUnknownError(error);
139
- return jsonResponse(status, { error: errorMessage(error) });
140
- }
141
- }
142
- /**
143
- * Map the resolved identity + ingress mode to a caller surface.
144
- *
145
- * @param identity - Frozen runtime identity for this request.
146
- * @param identityConfig - Deployment identity config (ingress mode).
147
- * @returns The surface used for `exposeTo` checks (`browser`, `trusted_backend`, `channel`, or `schedule`).
148
- */
149
- export function callerSurface(identity, identityConfig) {
150
- const provider = identity.source.provider;
151
- if (provider === "slack") {
152
- return "channel";
153
- }
154
- if (provider === "schedule") {
155
- return "schedule";
156
- }
157
- // http / cli: browser vs trusted_backend depends on the ingress mode.
158
- return identityConfig?.ingress.http === "trusted_backend"
159
- ? "trusted_backend"
160
- : "browser";
161
- }
162
- // --- Ownership + constraints -----------------------------------------------
163
- /**
164
- * Read the thread id from the frozen identity envelope (`source.threadId`).
165
- *
166
- * @param identity - Frozen runtime identity.
167
- * @returns Non-empty thread id, or `undefined` when absent.
168
- */
169
- function identityThreadId(identity) {
170
- const threadId = identity.source.threadId;
171
- return typeof threadId === "string" && threadId.length > 0
172
- ? threadId
173
- : undefined;
174
- }
175
- /**
176
- * Attach a proven thread id onto a copy of the identity envelope.
177
- * Returns the same object when the identity already carries that thread id.
178
- *
179
- * @param identity - Frozen runtime identity to copy.
180
- * @param threadId - Proven thread id to bind onto `source.threadId`.
181
- * @returns Identity with `source.threadId` set to `threadId`.
182
- */
183
- export function withIdentityThread(identity, threadId) {
184
- if (identityThreadId(identity) === threadId) {
185
- return identity;
186
- }
187
- return {
188
- ...identity,
189
- source: { ...identity.source, threadId },
190
- };
191
- }
192
- /**
193
- * Resolve the thread id for a thread/run-scoped capability and prove access
194
- * when it did not come from the trusted identity envelope.
195
- *
196
- * - identity `source.threadId` (server-derived from agent runs) is trusted
197
- * - LangSmith run session/thread (when `run_id` is present) is authoritative
198
- * - bare body `threadId`/`thread_id` (no identity thread, no run) requires
199
- * {@link AssertThreadAccess}
200
- *
201
- * @param capability - Capability whose `scope` drives whether a thread id is required.
202
- * @param identity - Frozen runtime identity for this request.
203
- * @param body - Parsed JSON request body.
204
- * @param client - LangSmith client used to load a run when `run_id` is present.
205
- * @param assertThreadAccess - Ownership prover for bare body thread ids.
206
- * @returns Proven thread id, or the identity thread id for non-thread/run scopes.
207
- * @throws {EnforcementError} On missing/mismatched thread ids or failed ownership proof.
208
- */
209
- export async function resolveProvenThreadId(capability, identity, body, client, assertThreadAccess) {
210
- if (capability.scope !== "thread" && capability.scope !== "run") {
211
- return identityThreadId(identity);
212
- }
213
- const fromIdentity = identityThreadId(identity);
214
- const fromBody = optionalBodyString(body, "threadId", "thread_id");
215
- const runId = optionalBodyString(body, "runId", "run_id");
216
- let fromRun;
217
- if (runId) {
218
- const run = toRecord(await client.readRun({ runId }));
219
- fromRun = runThreadId(run);
220
- if (!fromRun) {
221
- throw new EnforcementError(403, "run has no thread id");
222
- }
223
- }
224
- else if (capability.scope === "run") {
225
- // update/delete may omit runId; require identity or body thread below
226
- }
227
- for (const [left, right, label] of [
228
- [fromIdentity, fromBody, "body thread id does not match identity thread"],
229
- [fromIdentity, fromRun, "run does not belong to identity thread"],
230
- [fromBody, fromRun, "body thread id does not match run thread"],
231
- ]) {
232
- if (left && right && left !== right) {
233
- throw new EnforcementError(403, label);
234
- }
235
- }
236
- const threadId = fromIdentity ?? fromRun ?? fromBody;
237
- if (!threadId) {
238
- throw new EnforcementError(403, `${capability.scope} scope requires thread id (identity source, run, or request body)`);
239
- }
240
- // Identity- and run-derived thread ids are already proven. Only a bare body
241
- // thread id (no identity thread, no run) needs a live ownership check.
242
- if (!fromIdentity && !fromRun) {
243
- await assertThreadAccess(threadId);
244
- }
245
- return threadId;
246
- }
247
- /**
248
- * Build the default ownership proof: `GET /threads/{id}` with the caller's
249
- * credentials and require `metadata.owner` to match the identity's thread-owner key.
250
- *
251
- * @param request - Incoming request whose auth headers are forwarded to the thread GET.
252
- * @param identity - Frozen runtime identity used to derive the expected owner key.
253
- * @param identityConfig - Deployment identity config (`scoping.threads`).
254
- * @returns An `AssertThreadAccess` function closed over the request and expected owner.
255
- */
256
- export function defaultAssertThreadAccess(request, identity, identityConfig) {
257
- const expectedOwner = threadOwnerFromIdentity(identity, identityConfig);
258
- return async (threadId) => {
259
- if (!expectedOwner) {
260
- throw new EnforcementError(403, "thread access requires identity.actor.id");
261
- }
262
- // Server-local Agent Server origin only — never derive from request.url /
263
- // Host (attacker-controlled and would turn this credentialed GET into SSRF).
264
- const origin = resolveLoopbackApiUrl();
265
- const threadUrl = new URL(`/threads/${encodeURIComponent(threadId)}`, origin.endsWith("/") ? origin : `${origin}/`);
266
- const headers = forwardAuthHeaders(request);
267
- let response;
268
- try {
269
- response = await fetch(threadUrl, {
270
- method: "GET",
271
- headers,
272
- redirect: "manual",
273
- });
274
- }
275
- catch {
276
- throw new EnforcementError(502, "failed to verify thread access");
277
- }
278
- if (response.status === 401) {
279
- throw new EnforcementError(401, "unauthorized");
280
- }
281
- if (response.status === 403 || response.status === 404) {
282
- throw new EnforcementError(403, "thread is not accessible to this identity");
283
- }
284
- if (!response.ok) {
285
- throw new EnforcementError(502, `failed to verify thread access (${response.status})`);
286
- }
287
- let payload;
288
- try {
289
- payload = await response.json();
290
- }
291
- catch {
292
- return;
293
- }
294
- const owner = threadOwnerFromPayload(payload);
295
- if (owner && owner !== expectedOwner) {
296
- throw new EnforcementError(403, "thread is not accessible to this identity");
297
- }
298
- };
299
- }
300
- /**
301
- * Owner key used by `@auth.on.threads` for this identity.
302
- *
303
- * @param identity - Frozen runtime identity.
304
- * @param identityConfig - Deployment identity config (`scoping.threads`).
305
- * @returns Actor or tenant id used as the thread `metadata.owner`, or `undefined` when missing.
306
- */
307
- function threadOwnerFromIdentity(identity, identityConfig) {
308
- const scope = identityConfig?.scoping?.threads ?? "actor";
309
- if (scope === "tenant") {
310
- return identity.tenant?.id ?? identity.actor?.id;
311
- }
312
- return identity.actor?.id;
313
- }
314
- /**
315
- * Extract `metadata.owner` from a LangGraph thread payload.
316
- *
317
- * @param payload - Parsed JSON body from `GET /threads/{id}`.
318
- * @returns Non-empty owner string, or `undefined` when absent/malformed.
319
- */
320
- function threadOwnerFromPayload(payload) {
321
- if (!payload || typeof payload !== "object" || Array.isArray(payload)) {
322
- return undefined;
323
- }
324
- const metadata = payload.metadata;
325
- if (!metadata || typeof metadata !== "object" || Array.isArray(metadata)) {
326
- return undefined;
327
- }
328
- const owner = metadata.owner;
329
- return typeof owner === "string" && owner.length > 0 ? owner : undefined;
330
- }
331
- const FORWARDED_AUTH_HEADERS = [
332
- "authorization",
333
- "cookie",
334
- "x-api-key",
335
- "x-auth-key",
336
- "x-supabase-region",
337
- INGRESS_SECRET_HEADER,
338
- ACTOR_HEADER,
339
- TENANT_HEADER,
340
- ];
341
- /**
342
- * Copy auth-related headers from the inbound request for same-origin thread GETs.
343
- *
344
- * @param request - Incoming capability request.
345
- * @returns Headers containing only the allowlisted auth fields that were present.
346
- */
347
- function forwardAuthHeaders(request) {
348
- const headers = new Headers();
349
- for (const name of FORWARDED_AUTH_HEADERS) {
350
- const value = request.headers.get(name);
351
- if (value) {
352
- headers.set(name, value);
353
- }
354
- }
355
- return headers;
356
- }
357
- /**
358
- * Prove the capability's ownership scope from `runtime.identity` before the
359
- * LangSmith call. Thread id must already be present on identity when required
360
- * (see {@link resolveProvenThreadId}).
361
- *
362
- * @param capability - Capability whose `scope` is enforced.
363
- * @param identity - Identity with any proven thread id already bound.
364
- * @param body - Parsed JSON request body (used for run-scoped `run_id` checks).
365
- * @param client - LangSmith client used to load runs for run-scope verification.
366
- * @throws {EnforcementError} When the identity lacks the required scope fields or the run is foreign.
367
- */
368
- export async function assertCapabilityScope(capability, identity, body, client) {
369
- switch (capability.scope) {
370
- case "agent":
371
- return;
372
- case "actor": {
373
- const actorId = identity.actor?.id;
374
- if (typeof actorId !== "string" || actorId.length === 0) {
375
- throw new EnforcementError(403, "actor scope requires identity.actor.id");
376
- }
377
- return;
378
- }
379
- case "tenant": {
380
- const tenantId = identity.tenant?.id;
381
- if (typeof tenantId !== "string" || tenantId.length === 0) {
382
- throw new EnforcementError(403, "tenant scope requires identity.tenant.id");
383
- }
384
- return;
385
- }
386
- case "thread": {
387
- if (!identityThreadId(identity)) {
388
- throw new EnforcementError(403, "thread scope requires thread id (identity source, run, or request body)");
389
- }
390
- return;
391
- }
392
- case "run": {
393
- const threadId = identityThreadId(identity);
394
- if (!threadId) {
395
- throw new EnforcementError(403, "run scope requires thread id (identity source, run, or request body)");
396
- }
397
- const runId = await resolveRunIdForScope(body, client);
398
- if (!runId) {
399
- throw new EnforcementError(403, "run scope requires run id or feedback id");
400
- }
401
- const run = toRecord(await client.readRun({ runId }));
402
- const runThread = runThreadId(run);
403
- if (!runThread || runThread !== threadId) {
404
- throw new EnforcementError(403, "run does not belong to identity thread");
405
- }
406
- return;
407
- }
408
- default:
409
- throw new EnforcementError(400, `unknown capability scope "${String(capability.scope)}"`);
410
- }
411
- }
412
- /**
413
- * Resolve a LangGraph thread id from a LangSmith run.
414
- *
415
- * Prefer explicit `thread_id` fields. Metadata may also carry `session_id` as
416
- * the conversation/thread id. Do **not** use the run's top-level `session_id`:
417
- * on LangSmith that field is the tracing project/session UUID, not the
418
- * LangGraph thread.
419
- *
420
- * @param run - LangSmith run record (top-level and metadata bags).
421
- * @returns First non-empty LangGraph thread id found, or `undefined`.
422
- */
423
- function runThreadId(run) {
424
- const threadKeys = ["thread_id", "threadId"];
425
- const metadataKeys = [
426
- "thread_id",
427
- "threadId",
428
- "session_id",
429
- "sessionId",
430
- ];
431
- for (const key of threadKeys) {
432
- const value = run[key];
433
- if (typeof value === "string" && value.length > 0) {
434
- return value;
435
- }
436
- }
437
- const metadataBags = [run.metadata];
438
- const extra = run.extra;
439
- if (extra && typeof extra === "object" && !Array.isArray(extra)) {
440
- const extraRecord = extra;
441
- metadataBags.push(extraRecord.metadata ?? extraRecord);
442
- }
443
- for (const bag of metadataBags) {
444
- if (!bag || typeof bag !== "object" || Array.isArray(bag))
445
- continue;
446
- const record = bag;
447
- for (const key of metadataKeys) {
448
- const value = record[key];
449
- if (typeof value === "string" && value.length > 0) {
450
- return value;
451
- }
452
- }
453
- }
454
- return undefined;
455
- }
456
- /**
457
- * Normalize LangSmith id fields to a non-empty string.
458
- * Python SDK returns `uuid.UUID`; JS JSON is usually already a string.
459
- *
460
- * @param value - Raw id from a body field or LangSmith SDK object.
461
- * @returns Non-empty string id, or `undefined`.
462
- */
463
- function asIdString(value) {
464
- if (typeof value === "string" && value.length > 0) {
465
- return value;
466
- }
467
- return undefined;
468
- }
469
- /**
470
- * Resolve the run id for run-scoped ownership checks.
471
- * Prefer an explicit body `runId`/`run_id`; otherwise load the feedback and
472
- * use its `run_id` so update/delete cannot skip thread ownership.
473
- *
474
- * @param body - Parsed JSON request body.
475
- * @param client - LangSmith client used to load feedback when needed.
476
- * @returns Run id to verify against the identity thread, or `undefined`.
477
- */
478
- async function resolveRunIdForScope(body, client) {
479
- const fromBody = optionalBodyString(body, "runId", "run_id");
480
- if (fromBody) {
481
- return fromBody;
482
- }
483
- const feedbackId = optionalBodyString(body, "feedbackId", "feedback_id");
484
- if (!feedbackId) {
485
- return undefined;
486
- }
487
- const feedback = toRecord(await client.readFeedback({ feedbackId }));
488
- return asIdString(feedback.run_id ?? feedback.runId);
489
- }
490
- /**
491
- * Read the MDA actor id stamped onto feedback metadata (`mda_actor_id`).
492
- *
493
- * @param feedback - LangSmith feedback record.
494
- * @returns Actor id from top-level or `feedback_source` metadata, or `undefined`.
495
- */
496
- function feedbackActorId(feedback) {
497
- const direct = feedback.metadata;
498
- if (direct && typeof direct === "object" && !Array.isArray(direct)) {
499
- const actorId = direct.mda_actor_id;
500
- if (typeof actorId === "string" && actorId.length > 0) {
501
- return actorId;
502
- }
503
- }
504
- const source = feedback.feedback_source;
505
- if (source && typeof source === "object" && !Array.isArray(source)) {
506
- const metadata = source.metadata;
507
- if (metadata && typeof metadata === "object" && !Array.isArray(metadata)) {
508
- const actorId = metadata.mda_actor_id;
509
- if (typeof actorId === "string" && actorId.length > 0) {
510
- return actorId;
511
- }
512
- }
513
- }
514
- return undefined;
515
- }
516
- /**
517
- * Read the MDA thread id stamped onto example metadata (`mda_thread_id`).
518
- *
519
- * @param example - LangSmith example record.
520
- * @returns Thread id from `metadata.mda_thread_id`, or `undefined`.
521
- */
522
- function exampleThreadId(example) {
523
- const metadata = example.metadata;
524
- if (metadata && typeof metadata === "object" && !Array.isArray(metadata)) {
525
- const threadId = metadata.mda_thread_id;
526
- if (typeof threadId === "string" && threadId.length > 0) {
527
- return threadId;
528
- }
529
- }
530
- return undefined;
531
- }
532
- /**
533
- * Dispatch a capability action to the matching LangSmith resource handler.
534
- *
535
- * @param capability - Capability declaring the resource and constraints.
536
- * @param action - Requested action name from the body.
537
- * @param body - Parsed JSON request body.
538
- * @param deps - Handler dependencies including the LangSmith client.
539
- * @param identity - Scoped identity (with proven thread id when applicable).
540
- * @returns Raw LangSmith SDK result before response shaping.
541
- * @throws {EnforcementError} When the resource is unsupported or the action fails validation.
542
- */
543
- async function performLangSmithCall(capability, action, body, deps, identity) {
544
- switch (capability.resource) {
545
- case "feedback":
546
- return feedbackCall(capability, action, body, deps.client, identity);
547
- case "runs":
548
- return runsCall(action, body, deps.client);
549
- case "examples":
550
- return examplesCall(capability, body, deps.client, identity);
551
- case "annotation_queues":
552
- return annotationQueueCall(capability, body, deps.client);
553
- case "prompts":
554
- return deps.client.readPrompt({ name: requireString(body, "name") });
555
- case "threads":
556
- return threadsCall(capability, action, body, deps.client);
557
- default:
558
- throw new EnforcementError(400, `resource "${capability.resource}" is not supported in v0`);
559
- }
560
- }
561
- /**
562
- * Execute a feedback create/update/delete against LangSmith, applying
563
- * capability constraints (`keys`, `scores`, `maxCommentChars`, `onePerActor`).
564
- *
565
- * @param capability - Feedback capability with constraints.
566
- * @param action - One of `create`, `update`, or `delete`.
567
- * @param body - Parsed JSON request body.
568
- * @param client - LangSmith client.
569
- * @param identity - Runtime identity (actor id for `onePerActor` and metadata).
570
- * @returns Created feedback, or `void` for update/delete.
571
- * @throws {EnforcementError} On invalid action, constraint violation, or duplicate actor feedback.
572
- */
573
- async function feedbackCall(capability, action, body, client, identity) {
574
- const c = capability.constraints ?? {};
575
- if (action === "create") {
576
- const key = requireString(body, "key");
577
- assertAllowed(c.keys, key, "key");
578
- // Validated against the `scores` allowlist, then handed to the SDK as a
579
- // categorical score/value (see LangSmithClient docs).
580
- const score = body.score;
581
- if (score !== undefined) {
582
- assertAllowed(c.scores, String(score), "score");
583
- }
584
- const comment = optionalComment(body, c.maxCommentChars);
585
- const runId = bodyString(body, "runId", "run_id");
586
- const actorId = identity.actor?.id;
587
- if (c.onePerActor === true) {
588
- if (typeof actorId !== "string" || actorId.length === 0) {
589
- throw new EnforcementError(403, "onePerActor requires identity.actor.id");
590
- }
591
- const existing = await client.listFeedbackForRun({ runId });
592
- for (const feedback of existing) {
593
- if (feedbackActorId(toRecord(feedback)) === actorId) {
594
- throw new EnforcementError(409, "actor already submitted feedback for this run");
595
- }
596
- }
597
- }
598
- const metadata = typeof actorId === "string" && actorId.length > 0
599
- ? { mda_actor_id: actorId }
600
- : undefined;
601
- const feedbackId = optionalBodyString(body, "feedbackId", "feedback_id");
602
- return client.createFeedback({
603
- runId,
604
- key,
605
- ...(score !== undefined ? { score } : {}),
606
- ...(comment !== undefined ? { comment } : {}),
607
- ...(feedbackId !== undefined ? { feedbackId } : {}),
608
- ...(metadata ? { metadata } : {}),
609
- });
610
- }
611
- if (action === "update") {
612
- const comment = optionalComment(body, c.maxCommentChars);
613
- const score = body.score;
614
- return client.updateFeedback({
615
- feedbackId: bodyString(body, "feedbackId", "feedback_id"),
616
- ...(score !== undefined ? { score } : {}),
617
- ...(comment !== undefined ? { comment } : {}),
618
- });
619
- }
620
- if (action === "delete") {
621
- return client.deleteFeedback({
622
- feedbackId: bodyString(body, "feedbackId", "feedback_id"),
623
- });
624
- }
625
- throw new EnforcementError(400, `unknown feedback action "${action}"`);
626
- }
627
- /**
628
- * Execute a runs read or share against LangSmith.
629
- *
630
- * @param action - One of `read` or `share`.
631
- * @param body - Parsed JSON request body (`runId` / `run_id`).
632
- * @param client - LangSmith client.
633
- * @returns Run record or share URL payload.
634
- * @throws {EnforcementError} On unknown action or missing run id.
635
- */
636
- async function runsCall(action, body, client) {
637
- const runId = bodyString(body, "runId", "run_id");
638
- if (action === "read") {
639
- return client.readRun({ runId });
640
- }
641
- if (action === "share") {
642
- return client.shareRun({ runId });
643
- }
644
- throw new EnforcementError(400, `unknown runs action "${action}"`);
645
- }
646
- /**
647
- * Create a LangSmith example in the capability's dataset, applying field and
648
- * per-thread caps and stamping MDA metadata.
649
- *
650
- * @param capability - Examples capability with `dataset` and related constraints.
651
- * @param body - Parsed JSON request body (`inputs`, optional `outputs`).
652
- * @param client - LangSmith client.
653
- * @param identity - Runtime identity (thread/actor metadata and `maxExamplesPerThread`).
654
- * @returns Created example.
655
- * @throws {EnforcementError} On missing dataset, disallowed fields, or thread example cap.
656
- */
657
- async function examplesCall(capability, body, client, identity) {
658
- const c = capability.constraints ?? {};
659
- const dataset = c.dataset;
660
- if (!dataset) {
661
- throw new EnforcementError(400, "examples capability has no dataset");
662
- }
663
- const inputs = requireObject(body, "inputs");
664
- const allowedFields = c.allowedFields;
665
- if (allowedFields) {
666
- for (const field of Object.keys(inputs)) {
667
- if (!allowedFields.includes(field)) {
668
- throw new EnforcementError(400, `field "${field}" is not allowed`);
669
- }
670
- }
671
- }
672
- const outputs = body.outputs && typeof body.outputs === "object"
673
- ? body.outputs
674
- : undefined;
675
- const maxExamples = c.maxExamplesPerThread;
676
- const threadId = identityThreadId(identity);
677
- if (typeof maxExamples === "number") {
678
- if (!threadId) {
679
- throw new EnforcementError(403, "maxExamplesPerThread requires identity thread id");
680
- }
681
- const existing = await client.listExamples({
682
- dataset,
683
- metadata: { mda_thread_id: threadId },
684
- });
685
- const count = existing.filter((example) => exampleThreadId(toRecord(example)) === threadId).length;
686
- if (count >= maxExamples) {
687
- throw new EnforcementError(409, `thread already has ${maxExamples} examples in this dataset`);
688
- }
689
- }
690
- const metadata = {};
691
- if (threadId) {
692
- metadata.mda_thread_id = threadId;
693
- }
694
- const actorId = identity.actor?.id;
695
- if (typeof actorId === "string" && actorId.length > 0) {
696
- metadata.mda_actor_id = actorId;
697
- }
698
- return client.createExample({
699
- dataset,
700
- inputs,
701
- ...(outputs ? { outputs } : {}),
702
- ...(Object.keys(metadata).length > 0 ? { metadata } : {}),
703
- });
704
- }
705
- /**
706
- * Enqueue a run onto the capability's annotation queue.
707
- *
708
- * @param capability - Annotation-queue capability with `queue` and related constraints.
709
- * @param body - Parsed JSON request body (`runId`, optional `priority` / `note`).
710
- * @param client - LangSmith client.
711
- * @returns Resolves when the run is enqueued.
712
- * @throws {EnforcementError} On missing queue or disallowed priority/note.
713
- */
714
- async function annotationQueueCall(capability, body, client) {
715
- const c = capability.constraints ?? {};
716
- const queue = c.queue;
717
- if (!queue) {
718
- throw new EnforcementError(400, "annotation queue capability has no queue");
719
- }
720
- const priority = body.priority;
721
- if (priority !== undefined) {
722
- assertAllowed(c.allowedPriorities, String(priority), "priority");
723
- }
724
- const note = optionalComment(body, c.maxNoteChars, "note");
725
- return client.enqueueRun({
726
- queue,
727
- runId: bodyString(body, "runId", "run_id"),
728
- ...(typeof priority === "string" ? { priority } : {}),
729
- ...(note !== undefined ? { note } : {}),
730
- });
731
- }
732
- /**
733
- * Execute a threads read or metadata update against LangSmith.
734
- *
735
- * @param capability - Threads capability with metadata constraints.
736
- * @param action - One of `read` or `update_metadata`.
737
- * @param body - Parsed JSON request body (`threadId`, optional `metadata`).
738
- * @param client - LangSmith client.
739
- * @returns Thread/run record, or `void` for metadata updates.
740
- * @throws {EnforcementError} On unknown action or disallowed metadata keys/title length.
741
- */
742
- async function threadsCall(capability, action, body, client) {
743
- const threadId = bodyString(body, "threadId", "thread_id");
744
- if (action === "read") {
745
- return client.readThread({ threadId });
746
- }
747
- if (action === "update_metadata") {
748
- const c = capability.constraints ?? {};
749
- const metadata = requireObject(body, "metadata");
750
- const metadataKeys = c.metadataKeys;
751
- if (metadataKeys) {
752
- for (const key of Object.keys(metadata)) {
753
- if (!metadataKeys.includes(key)) {
754
- throw new EnforcementError(400, `metadata key "${key}" is not allowed`);
755
- }
756
- }
757
- }
758
- const maxTitle = c.maxTitleChars;
759
- if (maxTitle !== undefined && typeof metadata.title === "string") {
760
- if (metadata.title.length > maxTitle) {
761
- throw new EnforcementError(400, `title exceeds ${maxTitle} characters`);
762
- }
763
- }
764
- return client.updateThreadMetadata({ threadId, metadata });
765
- }
766
- throw new EnforcementError(400, `unknown threads action "${action}"`);
767
- }
768
- // --- Response shaping ------------------------------------------------------
769
- /**
770
- * Apply the capability's `include` allowlist, then drop any `redact` roots.
771
- *
772
- * @param raw - Full LangSmith result coerced to a plain record.
773
- * @param capability - Capability whose `response.include` / `response.redact` apply.
774
- * @returns Allowlisted (and redacted) response object returned to the caller.
775
- */
776
- export function shapeResponse(raw, capability) {
777
- const include = capability.response?.include ?? [];
778
- const redact = new Set(capability.response?.redact ?? []);
779
- const picked = {};
780
- for (const path of include) {
781
- const [root, ...rest] = path.split(".");
782
- if (root === undefined || redact.has(root)) {
783
- continue;
784
- }
785
- if (rest.length === 0) {
786
- if (root in raw) {
787
- picked[root] = raw[root];
788
- }
789
- continue;
790
- }
791
- const nested = pickNested(raw[root], rest);
792
- if (nested !== undefined) {
793
- const existing = picked[root] ?? {};
794
- picked[root] = { ...existing, [rest.join(".")]: nested };
795
- }
796
- }
797
- return picked;
798
- }
799
- /**
800
- * Walk a dotted path into a nested value.
801
- *
802
- * @param value - Root value to traverse.
803
- * @param path - Remaining path segments after the root key.
804
- * @returns Nested value at `path`, or `undefined` if any segment is missing.
805
- */
806
- function pickNested(value, path) {
807
- let current = value;
808
- for (const segment of path) {
809
- if (current && typeof current === "object" && segment in current) {
810
- current = current[segment];
811
- }
812
- else {
813
- return undefined;
814
- }
815
- }
816
- return current;
817
- }
818
- // --- Helpers ---------------------------------------------------------------
819
- /**
820
- * Extract the capability id from a `/capabilities/{id}` request URL.
821
- *
822
- * @param url - Absolute or relative request URL.
823
- * @returns Decoded capability id path segment.
824
- * @throws {EnforcementError} When the path has no `/capabilities/` marker.
825
- */
826
- function capabilityIdFromUrl(url) {
827
- const { pathname } = new URL(url);
828
- const marker = "/capabilities/";
829
- const index = pathname.lastIndexOf(marker);
830
- if (index === -1) {
831
- throw new EnforcementError(404, "capability id missing from path");
832
- }
833
- return decodeURIComponent(pathname.slice(index + marker.length));
834
- }
835
- /**
836
- * Parse the request body as a JSON object.
837
- *
838
- * @param request - Incoming HTTP request.
839
- * @returns Parsed object body.
840
- * @throws {EnforcementError} When the body is missing, non-JSON, or not an object.
841
- */
842
- async function parseJsonBody(request) {
843
- try {
844
- const parsed = await request.json();
845
- if (parsed && typeof parsed === "object") {
846
- return parsed;
847
- }
848
- }
849
- catch {
850
- // fall through to the uniform error below
851
- }
852
- throw new EnforcementError(400, "request body must be a JSON object");
853
- }
854
- /**
855
- * Read a required non-empty string field from the body.
856
- *
857
- * @param body - Parsed JSON request body.
858
- * @param key - Exact field name to read.
859
- * @returns Non-empty string value.
860
- * @throws {EnforcementError} When the field is missing, non-string, or empty.
861
- */
862
- function requireString(body, key) {
863
- const value = body[key];
864
- if (typeof value !== "string" || value.length === 0) {
865
- throw new EnforcementError(400, `missing or invalid "${key}"`);
866
- }
867
- return value;
868
- }
869
- /**
870
- * Read a required string from the body, accepting either camelCase or snake_case.
871
- *
872
- * @param body - Parsed JSON request body.
873
- * @param camel - Preferred camelCase field name (used in error messages).
874
- * @param snake - Alternate snake_case field name.
875
- * @returns Non-empty string from either key.
876
- * @throws {EnforcementError} When neither key yields a non-empty string.
877
- */
878
- export function bodyString(body, camel, snake) {
879
- const value = optionalBodyString(body, camel, snake);
880
- if (value === undefined) {
881
- throw new EnforcementError(400, `missing or invalid "${camel}"`);
882
- }
883
- return value;
884
- }
885
- /**
886
- * Read an optional string from the body, accepting either camelCase or snake_case.
887
- *
888
- * @param body - Parsed JSON request body.
889
- * @param camel - Preferred camelCase field name.
890
- * @param snake - Alternate snake_case field name.
891
- * @returns Non-empty string from either key, or `undefined` when both are absent.
892
- */
893
- function optionalBodyString(body, camel, snake) {
894
- const camelValue = body[camel];
895
- if (typeof camelValue === "string" && camelValue.length > 0) {
896
- return camelValue;
897
- }
898
- const snakeValue = body[snake];
899
- if (typeof snakeValue === "string" && snakeValue.length > 0) {
900
- return snakeValue;
901
- }
902
- return undefined;
903
- }
904
- /**
905
- * Read a required plain-object field from the body.
906
- *
907
- * @param body - Parsed JSON request body.
908
- * @param key - Field name to read.
909
- * @returns Object value (not an array).
910
- * @throws {EnforcementError} When the field is missing, not an object, or an array.
911
- */
912
- function requireObject(body, key) {
913
- const value = body[key];
914
- if (!value || typeof value !== "object" || Array.isArray(value)) {
915
- throw new EnforcementError(400, `missing or invalid "${key}"`);
916
- }
917
- return value;
918
- }
919
- /**
920
- * Enforce an optional allowlist for a string value.
921
- *
922
- * @param allowed - Allowed values, or `undefined` to skip the check.
923
- * @param value - Candidate value.
924
- * @param label - Field label used in the error message.
925
- * @throws {EnforcementError} When `allowed` is set and does not include `value`.
926
- */
927
- function assertAllowed(allowed, value, label) {
928
- if (allowed && !allowed.includes(value)) {
929
- throw new EnforcementError(400, `${label} "${value}" is not allowed`);
930
- }
931
- }
932
- /**
933
- * Read an optional string comment/note from the body and enforce a max length.
934
- *
935
- * @param body - Parsed JSON request body.
936
- * @param maxChars - Maximum allowed length, or `undefined` for no limit.
937
- * @param field - Body field name (defaults to `"comment"`).
938
- * @returns Trimmed-present string, or `undefined` when the field is nullish.
939
- * @throws {EnforcementError} When the field is non-string or exceeds `maxChars`.
940
- */
941
- function optionalComment(body, maxChars, field = "comment") {
942
- const value = body[field];
943
- if (value === undefined || value === null) {
944
- return undefined;
945
- }
946
- if (typeof value !== "string") {
947
- throw new EnforcementError(400, `"${field}" must be a string`);
948
- }
949
- if (maxChars !== undefined && value.length > maxChars) {
950
- throw new EnforcementError(400, `"${field}" exceeds ${maxChars} characters`);
951
- }
952
- return value;
953
- }
954
- /**
955
- * Build a JSON HTTP response with a fixed content type.
956
- *
957
- * @param status - HTTP status code.
958
- * @param body - Response payload (coerced via {@link jsonSafe}).
959
- * @returns `Response` with `application/json` body.
960
- */
961
- function jsonResponse(status, body) {
962
- return new Response(JSON.stringify(jsonSafe(body)), {
963
- status,
964
- headers: { "content-type": "application/json" },
965
- });
966
- }
967
- /**
968
- * Coerce values LangSmith may return (Date, etc.) into JSON-serializable form.
969
- *
970
- * @param value - Arbitrary value from the SDK or engine.
971
- * @returns JSON-safe clone (Dates → ISO strings; objects/arrays walked recursively).
972
- */
973
- function jsonSafe(value) {
974
- if (value === null || typeof value !== "object") {
975
- return value;
976
- }
977
- if (value instanceof Date) {
978
- return value.toISOString();
979
- }
980
- if (Array.isArray(value)) {
981
- return value.map(jsonSafe);
982
- }
983
- const out = {};
984
- for (const [key, nested] of Object.entries(value)) {
985
- out[key] = jsonSafe(nested);
986
- }
987
- return out;
988
- }
989
- /**
990
- * Map an unknown thrown value to an HTTP status for the error response.
991
- *
992
- * Prefers an explicit status on the error (or its `response`), then status
993
- * codes embedded in SDK messages, then `502` when nothing recoverable is
994
- * present. Mirrors the Python connector's `_status_from_unknown_error`.
995
- *
996
- * @param error - Caught value that is not an {@link EnforcementError}.
997
- * @returns Status in `400..599` when recoverable; otherwise `502`.
998
- */
999
- function statusFromUnknownError(error) {
1000
- const seen = new Set();
1001
- let current = error;
1002
- while (current != null && typeof current === "object" && !seen.has(current)) {
1003
- seen.add(current);
1004
- const record = current;
1005
- const direct = coerceHttpErrorStatus(record.status ?? record.statusCode);
1006
- if (direct !== undefined) {
1007
- return direct;
1008
- }
1009
- const response = record.response;
1010
- if (response != null && typeof response === "object") {
1011
- const nested = response;
1012
- const fromResponse = coerceHttpErrorStatus(nested.status ?? nested.statusCode);
1013
- if (fromResponse !== undefined) {
1014
- return fromResponse;
1015
- }
1016
- }
1017
- const name = typeof record.name === "string" ? record.name : undefined;
1018
- if (name === "LangSmithNotFoundError") {
1019
- return 404;
1020
- }
1021
- if (name === "LangSmithConflictError") {
1022
- return 409;
1023
- }
1024
- const message = current instanceof Error
1025
- ? current.message
1026
- : typeof record.message === "string"
1027
- ? record.message
1028
- : String(current);
1029
- const fromMessage = statusFromErrorMessage(message);
1030
- if (fromMessage !== undefined) {
1031
- return fromMessage;
1032
- }
1033
- current = record.cause;
1034
- }
1035
- return 502;
1036
- }
1037
- /** Return `value` when it is an HTTP error status in `400..599`. */
1038
- function coerceHttpErrorStatus(value) {
1039
- if (typeof value === "number" && value >= 400 && value <= 599) {
1040
- return value;
1041
- }
1042
- return undefined;
1043
- }
1044
- /**
1045
- * Recover an HTTP status embedded in LangSmith / requests-style error text.
1046
- *
1047
- * @param message - Error message that may mention an upstream status.
1048
- * @returns Status in `400..599` when found; otherwise `undefined`.
1049
- */
1050
- function statusFromErrorMessage(message) {
1051
- const patterns = [
1052
- /Received status \[([45]\d{2})\]/,
1053
- /\b([45]\d{2}) Client Error\b/,
1054
- /\b([45]\d{2}) Server Error\b/,
1055
- /\bHTTPError\(['"]([45]\d{2})\b/,
1056
- ];
1057
- for (const pattern of patterns) {
1058
- const match = pattern.exec(message);
1059
- if (match) {
1060
- return coerceHttpErrorStatus(Number(match[1]));
1061
- }
1062
- }
1063
- return undefined;
1064
- }
1065
- /**
1066
- * Extract a human-readable message from an unknown thrown value.
1067
- *
1068
- * @param error - Caught value.
1069
- * @returns `Error.message` when available; otherwise `"internal error"`.
1070
- */
1071
- function errorMessage(error) {
1072
- if (error instanceof Error) {
1073
- return error.message;
1074
- }
1075
- return "internal error";
1076
- }
1077
- /**
1078
- * Coerce an SDK result (object | void | null) into a plain record for shaping.
1079
- *
1080
- * @param value - Raw LangSmith call result.
1081
- * @returns Shallow-copied object, or `{}` when `value` is not an object.
1082
- */
1083
- function toRecord(value) {
1084
- if (value && typeof value === "object") {
1085
- return { ...value };
1086
- }
1087
- return {};
1088
- }
1089
- /**
1090
- * Resolve the LangSmith workspace id used for `X-Tenant-Id`.
1091
- *
1092
- * Org-scoped / multi-workspace API keys default to the key's home workspace
1093
- * unless scoped. Prefer `LANGSMITH_WORKSPACE_ID` (SDK standard); fall back to
1094
- * `LANGSMITH_TENANT_ID` (deploy CLI / platform legacy name for the same id).
1095
- *
1096
- * @param env - Environment map; defaults to `process.env`.
1097
- * @returns Trimmed workspace id, or `undefined` when unset.
1098
- */
1099
- export function resolveLangSmithWorkspaceId(env = process.env) {
1100
- for (const key of [
1101
- "LANGSMITH_WORKSPACE_ID",
1102
- "LANGCHAIN_WORKSPACE_ID",
1103
- "LANGSMITH_TENANT_ID",
1104
- "LANGCHAIN_TENANT_ID",
1105
- ]) {
1106
- const value = env[key]?.trim();
1107
- if (value)
1108
- return value;
1109
- }
1110
- return undefined;
1111
- }
1112
- /**
1113
- * Default client backed by the `langsmith` SDK {@link Client}. The underlying
1114
- * client is created on first use so building the engine (e.g. for an app with no
1115
- * requests yet) never requires `LANGSMITH_API_KEY`.
1116
- *
1117
- * Passes {@link resolveLangSmithWorkspaceId} so run/feedback calls target the
1118
- * deployment workspace rather than the API key's default tenant.
1119
- *
1120
- * A connector "score" is numeric/boolean → LangSmith `score`, or categorical
1121
- * (string/object) → LangSmith feedback `value`.
1122
- *
1123
- * @returns `LangSmithClient` adapter over the official SDK.
1124
- */
1125
- export function defaultClient() {
1126
- let client;
1127
- const sdk = () => {
1128
- client ??= new Client({
1129
- apiKey: process.env.LANGSMITH_API_KEY,
1130
- workspaceId: resolveLangSmithWorkspaceId(),
1131
- });
1132
- return client;
1133
- };
1134
- const isScore = (value) => typeof value === "number" || typeof value === "boolean" || value === null;
1135
- const scoreOrValue = (value) => {
1136
- if (isScore(value)) {
1137
- return { score: value };
1138
- }
1139
- return value === undefined ? {} : { value };
1140
- };
1141
- return {
1142
- createFeedback: ({ runId, key, score, comment, feedbackId, metadata }) => sdk().createFeedback(runId, key, {
1143
- ...scoreOrValue(score),
1144
- comment,
1145
- feedbackId,
1146
- ...(metadata ? { sourceInfo: metadata } : {}),
1147
- }),
1148
- updateFeedback: ({ feedbackId, score, comment }) => sdk().updateFeedback(feedbackId, { ...scoreOrValue(score), comment }),
1149
- deleteFeedback: ({ feedbackId }) => sdk().deleteFeedback(feedbackId),
1150
- listFeedbackForRun: async ({ runId }) => {
1151
- const out = [];
1152
- for await (const feedback of sdk().listFeedback({ runIds: [runId] })) {
1153
- out.push(feedback);
1154
- }
1155
- return out;
1156
- },
1157
- readFeedback: ({ feedbackId }) => sdk().readFeedback(feedbackId),
1158
- readRun: ({ runId }) => sdk().readRun(runId),
1159
- shareRun: async ({ runId }) => ({ url: await sdk().shareRun(runId) }),
1160
- createExample: ({ dataset, inputs, outputs, metadata }) => sdk().createExample({
1161
- inputs,
1162
- outputs,
1163
- dataset_name: dataset,
1164
- ...(metadata ? { metadata } : {}),
1165
- }),
1166
- listExamples: async ({ dataset, metadata }) => {
1167
- const out = [];
1168
- for await (const example of sdk().listExamples({
1169
- datasetName: dataset,
1170
- ...(metadata ? { metadata } : {}),
1171
- })) {
1172
- out.push(example);
1173
- }
1174
- return out;
1175
- },
1176
- enqueueRun: ({ queue, runId }) => sdk().addRunsToAnnotationQueue(queue, [runId]),
1177
- readPrompt: ({ name }) => sdk().getPrompt(name),
1178
- readThread: ({ threadId }) => sdk().readRun(threadId),
1179
- updateThreadMetadata: ({ threadId, metadata }) => sdk().updateRun(threadId, { extra: metadata }),
1180
- };
1181
- }
1182
- //# sourceMappingURL=routes.js.map