@librechat/agents 3.1.75 → 3.1.77-dev.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (272) hide show
  1. package/dist/cjs/graphs/Graph.cjs +22 -3
  2. package/dist/cjs/graphs/Graph.cjs.map +1 -1
  3. package/dist/cjs/hitl/askUserQuestion.cjs +67 -0
  4. package/dist/cjs/hitl/askUserQuestion.cjs.map +1 -0
  5. package/dist/cjs/hooks/HookRegistry.cjs +54 -0
  6. package/dist/cjs/hooks/HookRegistry.cjs.map +1 -1
  7. package/dist/cjs/hooks/createToolPolicyHook.cjs +115 -0
  8. package/dist/cjs/hooks/createToolPolicyHook.cjs.map +1 -0
  9. package/dist/cjs/hooks/executeHooks.cjs +40 -1
  10. package/dist/cjs/hooks/executeHooks.cjs.map +1 -1
  11. package/dist/cjs/hooks/types.cjs +1 -0
  12. package/dist/cjs/hooks/types.cjs.map +1 -1
  13. package/dist/cjs/langchain/google-common.cjs +3 -0
  14. package/dist/cjs/langchain/google-common.cjs.map +1 -0
  15. package/dist/cjs/langchain/index.cjs +86 -0
  16. package/dist/cjs/langchain/index.cjs.map +1 -0
  17. package/dist/cjs/langchain/language_models/chat_models.cjs +3 -0
  18. package/dist/cjs/langchain/language_models/chat_models.cjs.map +1 -0
  19. package/dist/cjs/langchain/messages/tool.cjs +3 -0
  20. package/dist/cjs/langchain/messages/tool.cjs.map +1 -0
  21. package/dist/cjs/langchain/messages.cjs +51 -0
  22. package/dist/cjs/langchain/messages.cjs.map +1 -0
  23. package/dist/cjs/langchain/openai.cjs +3 -0
  24. package/dist/cjs/langchain/openai.cjs.map +1 -0
  25. package/dist/cjs/langchain/prompts.cjs +11 -0
  26. package/dist/cjs/langchain/prompts.cjs.map +1 -0
  27. package/dist/cjs/langchain/runnables.cjs +19 -0
  28. package/dist/cjs/langchain/runnables.cjs.map +1 -0
  29. package/dist/cjs/langchain/tools.cjs +23 -0
  30. package/dist/cjs/langchain/tools.cjs.map +1 -0
  31. package/dist/cjs/langchain/utils/env.cjs +11 -0
  32. package/dist/cjs/langchain/utils/env.cjs.map +1 -0
  33. package/dist/cjs/llm/anthropic/index.cjs +145 -52
  34. package/dist/cjs/llm/anthropic/index.cjs.map +1 -1
  35. package/dist/cjs/llm/anthropic/types.cjs.map +1 -1
  36. package/dist/cjs/llm/anthropic/utils/message_inputs.cjs +21 -14
  37. package/dist/cjs/llm/anthropic/utils/message_inputs.cjs.map +1 -1
  38. package/dist/cjs/llm/anthropic/utils/message_outputs.cjs +84 -70
  39. package/dist/cjs/llm/anthropic/utils/message_outputs.cjs.map +1 -1
  40. package/dist/cjs/llm/bedrock/index.cjs +1 -1
  41. package/dist/cjs/llm/bedrock/index.cjs.map +1 -1
  42. package/dist/cjs/llm/bedrock/utils/message_inputs.cjs +213 -3
  43. package/dist/cjs/llm/bedrock/utils/message_inputs.cjs.map +1 -1
  44. package/dist/cjs/llm/bedrock/utils/message_outputs.cjs +2 -1
  45. package/dist/cjs/llm/bedrock/utils/message_outputs.cjs.map +1 -1
  46. package/dist/cjs/llm/google/utils/common.cjs +5 -4
  47. package/dist/cjs/llm/google/utils/common.cjs.map +1 -1
  48. package/dist/cjs/llm/openai/index.cjs +519 -655
  49. package/dist/cjs/llm/openai/index.cjs.map +1 -1
  50. package/dist/cjs/llm/openai/utils/index.cjs +20 -458
  51. package/dist/cjs/llm/openai/utils/index.cjs.map +1 -1
  52. package/dist/cjs/llm/openrouter/index.cjs +57 -175
  53. package/dist/cjs/llm/openrouter/index.cjs.map +1 -1
  54. package/dist/cjs/llm/vertexai/index.cjs +5 -3
  55. package/dist/cjs/llm/vertexai/index.cjs.map +1 -1
  56. package/dist/cjs/main.cjs +112 -3
  57. package/dist/cjs/main.cjs.map +1 -1
  58. package/dist/cjs/messages/cache.cjs +2 -1
  59. package/dist/cjs/messages/cache.cjs.map +1 -1
  60. package/dist/cjs/messages/core.cjs +7 -6
  61. package/dist/cjs/messages/core.cjs.map +1 -1
  62. package/dist/cjs/messages/format.cjs +73 -15
  63. package/dist/cjs/messages/format.cjs.map +1 -1
  64. package/dist/cjs/messages/langchain.cjs +26 -0
  65. package/dist/cjs/messages/langchain.cjs.map +1 -0
  66. package/dist/cjs/messages/prune.cjs +7 -6
  67. package/dist/cjs/messages/prune.cjs.map +1 -1
  68. package/dist/cjs/run.cjs +400 -42
  69. package/dist/cjs/run.cjs.map +1 -1
  70. package/dist/cjs/tools/ToolNode.cjs +556 -56
  71. package/dist/cjs/tools/ToolNode.cjs.map +1 -1
  72. package/dist/cjs/tools/search/search.cjs +55 -66
  73. package/dist/cjs/tools/search/search.cjs.map +1 -1
  74. package/dist/cjs/tools/search/tavily-scraper.cjs +189 -0
  75. package/dist/cjs/tools/search/tavily-scraper.cjs.map +1 -0
  76. package/dist/cjs/tools/search/tavily-search.cjs +372 -0
  77. package/dist/cjs/tools/search/tavily-search.cjs.map +1 -0
  78. package/dist/cjs/tools/search/tool.cjs +26 -4
  79. package/dist/cjs/tools/search/tool.cjs.map +1 -1
  80. package/dist/cjs/tools/search/utils.cjs +10 -3
  81. package/dist/cjs/tools/search/utils.cjs.map +1 -1
  82. package/dist/esm/graphs/Graph.mjs +22 -3
  83. package/dist/esm/graphs/Graph.mjs.map +1 -1
  84. package/dist/esm/hitl/askUserQuestion.mjs +65 -0
  85. package/dist/esm/hitl/askUserQuestion.mjs.map +1 -0
  86. package/dist/esm/hooks/HookRegistry.mjs +54 -0
  87. package/dist/esm/hooks/HookRegistry.mjs.map +1 -1
  88. package/dist/esm/hooks/createToolPolicyHook.mjs +113 -0
  89. package/dist/esm/hooks/createToolPolicyHook.mjs.map +1 -0
  90. package/dist/esm/hooks/executeHooks.mjs +40 -1
  91. package/dist/esm/hooks/executeHooks.mjs.map +1 -1
  92. package/dist/esm/hooks/types.mjs +1 -0
  93. package/dist/esm/hooks/types.mjs.map +1 -1
  94. package/dist/esm/langchain/google-common.mjs +2 -0
  95. package/dist/esm/langchain/google-common.mjs.map +1 -0
  96. package/dist/esm/langchain/index.mjs +5 -0
  97. package/dist/esm/langchain/index.mjs.map +1 -0
  98. package/dist/esm/langchain/language_models/chat_models.mjs +2 -0
  99. package/dist/esm/langchain/language_models/chat_models.mjs.map +1 -0
  100. package/dist/esm/langchain/messages/tool.mjs +2 -0
  101. package/dist/esm/langchain/messages/tool.mjs.map +1 -0
  102. package/dist/esm/langchain/messages.mjs +2 -0
  103. package/dist/esm/langchain/messages.mjs.map +1 -0
  104. package/dist/esm/langchain/openai.mjs +2 -0
  105. package/dist/esm/langchain/openai.mjs.map +1 -0
  106. package/dist/esm/langchain/prompts.mjs +2 -0
  107. package/dist/esm/langchain/prompts.mjs.map +1 -0
  108. package/dist/esm/langchain/runnables.mjs +2 -0
  109. package/dist/esm/langchain/runnables.mjs.map +1 -0
  110. package/dist/esm/langchain/tools.mjs +2 -0
  111. package/dist/esm/langchain/tools.mjs.map +1 -0
  112. package/dist/esm/langchain/utils/env.mjs +2 -0
  113. package/dist/esm/langchain/utils/env.mjs.map +1 -0
  114. package/dist/esm/llm/anthropic/index.mjs +146 -54
  115. package/dist/esm/llm/anthropic/index.mjs.map +1 -1
  116. package/dist/esm/llm/anthropic/types.mjs.map +1 -1
  117. package/dist/esm/llm/anthropic/utils/message_inputs.mjs +21 -14
  118. package/dist/esm/llm/anthropic/utils/message_inputs.mjs.map +1 -1
  119. package/dist/esm/llm/anthropic/utils/message_outputs.mjs +84 -71
  120. package/dist/esm/llm/anthropic/utils/message_outputs.mjs.map +1 -1
  121. package/dist/esm/llm/bedrock/index.mjs +1 -1
  122. package/dist/esm/llm/bedrock/index.mjs.map +1 -1
  123. package/dist/esm/llm/bedrock/utils/message_inputs.mjs +214 -4
  124. package/dist/esm/llm/bedrock/utils/message_inputs.mjs.map +1 -1
  125. package/dist/esm/llm/bedrock/utils/message_outputs.mjs +2 -1
  126. package/dist/esm/llm/bedrock/utils/message_outputs.mjs.map +1 -1
  127. package/dist/esm/llm/google/utils/common.mjs +5 -4
  128. package/dist/esm/llm/google/utils/common.mjs.map +1 -1
  129. package/dist/esm/llm/openai/index.mjs +520 -656
  130. package/dist/esm/llm/openai/index.mjs.map +1 -1
  131. package/dist/esm/llm/openai/utils/index.mjs +23 -459
  132. package/dist/esm/llm/openai/utils/index.mjs.map +1 -1
  133. package/dist/esm/llm/openrouter/index.mjs +57 -175
  134. package/dist/esm/llm/openrouter/index.mjs.map +1 -1
  135. package/dist/esm/llm/vertexai/index.mjs +5 -3
  136. package/dist/esm/llm/vertexai/index.mjs.map +1 -1
  137. package/dist/esm/main.mjs +7 -0
  138. package/dist/esm/main.mjs.map +1 -1
  139. package/dist/esm/messages/cache.mjs +2 -1
  140. package/dist/esm/messages/cache.mjs.map +1 -1
  141. package/dist/esm/messages/core.mjs +7 -6
  142. package/dist/esm/messages/core.mjs.map +1 -1
  143. package/dist/esm/messages/format.mjs +73 -15
  144. package/dist/esm/messages/format.mjs.map +1 -1
  145. package/dist/esm/messages/langchain.mjs +23 -0
  146. package/dist/esm/messages/langchain.mjs.map +1 -0
  147. package/dist/esm/messages/prune.mjs +7 -6
  148. package/dist/esm/messages/prune.mjs.map +1 -1
  149. package/dist/esm/run.mjs +400 -42
  150. package/dist/esm/run.mjs.map +1 -1
  151. package/dist/esm/tools/ToolNode.mjs +557 -57
  152. package/dist/esm/tools/ToolNode.mjs.map +1 -1
  153. package/dist/esm/tools/search/search.mjs +55 -66
  154. package/dist/esm/tools/search/search.mjs.map +1 -1
  155. package/dist/esm/tools/search/tavily-scraper.mjs +186 -0
  156. package/dist/esm/tools/search/tavily-scraper.mjs.map +1 -0
  157. package/dist/esm/tools/search/tavily-search.mjs +370 -0
  158. package/dist/esm/tools/search/tavily-search.mjs.map +1 -0
  159. package/dist/esm/tools/search/tool.mjs +26 -4
  160. package/dist/esm/tools/search/tool.mjs.map +1 -1
  161. package/dist/esm/tools/search/utils.mjs +10 -3
  162. package/dist/esm/tools/search/utils.mjs.map +1 -1
  163. package/dist/types/graphs/Graph.d.ts +7 -0
  164. package/dist/types/hitl/askUserQuestion.d.ts +55 -0
  165. package/dist/types/hitl/index.d.ts +6 -0
  166. package/dist/types/hooks/HookRegistry.d.ts +58 -0
  167. package/dist/types/hooks/createToolPolicyHook.d.ts +87 -0
  168. package/dist/types/hooks/index.d.ts +4 -1
  169. package/dist/types/hooks/types.d.ts +109 -3
  170. package/dist/types/index.d.ts +10 -0
  171. package/dist/types/langchain/google-common.d.ts +1 -0
  172. package/dist/types/langchain/index.d.ts +8 -0
  173. package/dist/types/langchain/language_models/chat_models.d.ts +1 -0
  174. package/dist/types/langchain/messages/tool.d.ts +1 -0
  175. package/dist/types/langchain/messages.d.ts +2 -0
  176. package/dist/types/langchain/openai.d.ts +1 -0
  177. package/dist/types/langchain/prompts.d.ts +1 -0
  178. package/dist/types/langchain/runnables.d.ts +2 -0
  179. package/dist/types/langchain/tools.d.ts +2 -0
  180. package/dist/types/langchain/utils/env.d.ts +1 -0
  181. package/dist/types/llm/anthropic/index.d.ts +22 -9
  182. package/dist/types/llm/anthropic/types.d.ts +5 -1
  183. package/dist/types/llm/anthropic/utils/message_outputs.d.ts +13 -6
  184. package/dist/types/llm/anthropic/utils/output_parsers.d.ts +1 -1
  185. package/dist/types/llm/openai/index.d.ts +21 -24
  186. package/dist/types/llm/openrouter/index.d.ts +11 -9
  187. package/dist/types/llm/vertexai/index.d.ts +1 -0
  188. package/dist/types/messages/cache.d.ts +4 -1
  189. package/dist/types/messages/format.d.ts +4 -1
  190. package/dist/types/messages/langchain.d.ts +27 -0
  191. package/dist/types/run.d.ts +117 -1
  192. package/dist/types/tools/ToolNode.d.ts +26 -1
  193. package/dist/types/tools/search/tavily-scraper.d.ts +19 -0
  194. package/dist/types/tools/search/tavily-search.d.ts +4 -0
  195. package/dist/types/tools/search/types.d.ts +99 -5
  196. package/dist/types/tools/search/utils.d.ts +2 -2
  197. package/dist/types/types/graph.d.ts +23 -37
  198. package/dist/types/types/hitl.d.ts +272 -0
  199. package/dist/types/types/index.d.ts +1 -0
  200. package/dist/types/types/llm.d.ts +3 -3
  201. package/dist/types/types/run.d.ts +33 -0
  202. package/dist/types/types/stream.d.ts +1 -1
  203. package/dist/types/types/tools.d.ts +19 -0
  204. package/package.json +80 -17
  205. package/src/graphs/Graph.ts +33 -4
  206. package/src/graphs/__tests__/composition.smoke.test.ts +188 -0
  207. package/src/hitl/askUserQuestion.ts +72 -0
  208. package/src/hitl/index.ts +7 -0
  209. package/src/hooks/HookRegistry.ts +71 -0
  210. package/src/hooks/__tests__/createToolPolicyHook.test.ts +259 -0
  211. package/src/hooks/createToolPolicyHook.ts +184 -0
  212. package/src/hooks/executeHooks.ts +50 -1
  213. package/src/hooks/index.ts +6 -0
  214. package/src/hooks/types.ts +112 -0
  215. package/src/index.ts +22 -0
  216. package/src/langchain/google-common.ts +1 -0
  217. package/src/langchain/index.ts +8 -0
  218. package/src/langchain/language_models/chat_models.ts +1 -0
  219. package/src/langchain/messages/tool.ts +5 -0
  220. package/src/langchain/messages.ts +21 -0
  221. package/src/langchain/openai.ts +1 -0
  222. package/src/langchain/prompts.ts +1 -0
  223. package/src/langchain/runnables.ts +7 -0
  224. package/src/langchain/tools.ts +8 -0
  225. package/src/langchain/utils/env.ts +1 -0
  226. package/src/llm/anthropic/index.ts +252 -84
  227. package/src/llm/anthropic/llm.spec.ts +751 -102
  228. package/src/llm/anthropic/types.ts +9 -1
  229. package/src/llm/anthropic/utils/message_inputs.ts +37 -19
  230. package/src/llm/anthropic/utils/message_outputs.ts +119 -101
  231. package/src/llm/bedrock/index.ts +2 -2
  232. package/src/llm/bedrock/llm.spec.ts +341 -0
  233. package/src/llm/bedrock/utils/message_inputs.ts +303 -4
  234. package/src/llm/bedrock/utils/message_outputs.ts +2 -1
  235. package/src/llm/custom-chat-models.smoke.test.ts +836 -0
  236. package/src/llm/google/llm.spec.ts +339 -57
  237. package/src/llm/google/utils/common.ts +53 -48
  238. package/src/llm/openai/contentBlocks.test.ts +346 -0
  239. package/src/llm/openai/index.ts +856 -833
  240. package/src/llm/openai/utils/index.ts +107 -78
  241. package/src/llm/openai/utils/messages.test.ts +159 -0
  242. package/src/llm/openrouter/index.ts +124 -247
  243. package/src/llm/openrouter/reasoning.test.ts +8 -1
  244. package/src/llm/vertexai/index.ts +11 -5
  245. package/src/llm/vertexai/llm.spec.ts +28 -1
  246. package/src/messages/cache.test.ts +4 -3
  247. package/src/messages/cache.ts +3 -2
  248. package/src/messages/core.ts +16 -9
  249. package/src/messages/format.ts +96 -16
  250. package/src/messages/formatAgentMessages.test.ts +166 -1
  251. package/src/messages/langchain.ts +39 -0
  252. package/src/messages/prune.ts +12 -8
  253. package/src/run.ts +456 -47
  254. package/src/scripts/caching.ts +2 -3
  255. package/src/specs/summarization.test.ts +51 -58
  256. package/src/tools/ToolNode.ts +706 -63
  257. package/src/tools/__tests__/hitl.test.ts +3593 -0
  258. package/src/tools/search/search.ts +83 -73
  259. package/src/tools/search/tavily-scraper.ts +235 -0
  260. package/src/tools/search/tavily-search.ts +424 -0
  261. package/src/tools/search/tavily.test.ts +965 -0
  262. package/src/tools/search/tool.ts +36 -26
  263. package/src/tools/search/types.ts +133 -8
  264. package/src/tools/search/utils.ts +13 -5
  265. package/src/types/graph.ts +32 -87
  266. package/src/types/hitl.ts +303 -0
  267. package/src/types/index.ts +1 -0
  268. package/src/types/llm.ts +3 -3
  269. package/src/types/run.ts +33 -0
  270. package/src/types/stream.ts +1 -1
  271. package/src/types/tools.ts +19 -0
  272. package/src/utils/llmConfig.ts +1 -6
@@ -46,6 +46,13 @@ export declare abstract class Graph<T extends t.BaseGraphState = t.BaseGraphStat
46
46
  invokedToolIds?: Set<string>;
47
47
  handlerRegistry: HandlerRegistry | undefined;
48
48
  hookRegistry: HookRegistry | undefined;
49
+ /**
50
+ * Run-scoped HITL configuration. When `humanInTheLoop?.enabled` is
51
+ * `true`, `ToolNode` raises a real `interrupt()` for `PreToolUse`
52
+ * `ask` decisions instead of treating them as a synchronous deny.
53
+ * Threaded from `RunConfig.humanInTheLoop`.
54
+ */
55
+ humanInTheLoop: t.HumanInTheLoopConfig | undefined;
49
56
  /**
50
57
  * Run-scoped config for the tool output reference registry. Threaded
51
58
  * from `RunConfig.toolOutputReferences` down into every ToolNode this
@@ -0,0 +1,55 @@
1
+ /**
2
+ * Typed convenience wrapper around LangGraph's `interrupt()` for the
3
+ * `ask_user_question` interrupt category. Lets a custom graph node
4
+ * (or a tool implementation) suspend execution to collect a free-form
5
+ * answer from the human, without the host having to assemble the
6
+ * interrupt payload by hand. The companion to `Run.resume(answer)` on
7
+ * the host side.
8
+ *
9
+ * AsyncLocalStorage anchoring: this helper does NOT call
10
+ * `runWithConfig` itself — it expects to be invoked from inside a
11
+ * LangGraph node where the framework has already established the
12
+ * runnable config. ToolNode is the one place in this codebase that
13
+ * needs the manual `runWithConfig` shim, because its
14
+ * `RunnableCallable.trace = false` skips the upstream tracing path
15
+ * that normally sets up the AsyncLocalStorage frame; ordinary user
16
+ * nodes (RunnableLambda, addNode callbacks) do not have that
17
+ * constraint.
18
+ */
19
+ import type { AskUserQuestionRequest, AskUserQuestionResolution } from '@/types/hitl';
20
+ /**
21
+ * Suspend the current graph node to ask the human a question. Returns
22
+ * the host-supplied resolution after `Run.resume(resolution)` is
23
+ * called against a Run rebuilt with the same `thread_id` and
24
+ * checkpointer.
25
+ *
26
+ * On the FIRST call (no resume value available), `interrupt()` throws
27
+ * a `GraphInterrupt` that LangGraph catches; this function does not
28
+ * return — execution unwinds, the SDK persists the checkpoint, and
29
+ * the run completes with `run.getInterrupt()` returning a
30
+ * `RunInterruptResult` whose `payload` is an
31
+ * `AskUserQuestionInterruptPayload`.
32
+ *
33
+ * On RESUME, LangGraph re-runs the node from the start and this call
34
+ * returns the host's `AskUserQuestionResolution` directly.
35
+ *
36
+ * Hosts that prefer the raw `interrupt()` (e.g., to attach extra
37
+ * metadata) can construct an `AskUserQuestionInterruptPayload` and
38
+ * call `interrupt()` themselves — this helper is purely convenience.
39
+ *
40
+ * @example
41
+ * ```ts
42
+ * const builder = new StateGraph(MessagesAnnotation)
43
+ * .addNode('clarifier', () => {
44
+ * const { answer } = askUserQuestion({
45
+ * question: 'Which environment should I deploy to?',
46
+ * options: [
47
+ * { label: 'Staging', value: 'staging' },
48
+ * { label: 'Production', value: 'production' },
49
+ * ],
50
+ * });
51
+ * return { messages: [new HumanMessage(`Use ${answer}`)] };
52
+ * });
53
+ * ```
54
+ */
55
+ export declare function askUserQuestion(question: AskUserQuestionRequest): AskUserQuestionResolution;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Human-in-the-loop helpers. Type definitions live in `@/types/hitl`
3
+ * and re-export from the top-level types barrel; runtime helpers (like
4
+ * `askUserQuestion()`) live here.
5
+ */
6
+ export { askUserQuestion } from './askUserQuestion';
@@ -1,4 +1,17 @@
1
1
  import type { HookEvent, HookMatcher } from './types';
2
+ /**
3
+ * Snapshot of a halt request raised by a hook returning
4
+ * `preventContinuation: true`. The SDK's run loop polls for this between
5
+ * stream events and exits cleanly when set, skipping the `Stop` hook
6
+ * (the run is being halted, not naturally completing). One per registry
7
+ * instance — the first hook to halt wins; subsequent halts are ignored
8
+ * so the original reason isn't clobbered.
9
+ */
10
+ export interface HookHaltSignal {
11
+ reason: string;
12
+ /** Event of the hook that triggered the halt (for diagnostics). */
13
+ source: HookEvent;
14
+ }
2
15
  /**
3
16
  * Run-scoped storage for hook matchers with an additional layer for
4
17
  * session-scoped matchers that should be cleaned up between sessions.
@@ -20,6 +33,18 @@ import type { HookEvent, HookMatcher } from './types';
20
33
  export declare class HookRegistry {
21
34
  private readonly global;
22
35
  private readonly sessions;
36
+ /**
37
+ * Per-session halt signals. Scoped by `sessionId` (= the run id the
38
+ * hook fired under) so a host that shares one registry across
39
+ * concurrent runs cannot leak `preventContinuation` from one run
40
+ * into another. Without scoping, a halt raised by run A's hook
41
+ * would trip run B's stream-loop poll on the next iteration —
42
+ * silently terminating an unrelated run.
43
+ *
44
+ * Map storage mirrors the reasoning above for session matchers:
45
+ * O(1) insertion in hot paths, no spread-on-write.
46
+ */
47
+ private readonly haltSignals;
23
48
  /**
24
49
  * Register a matcher for the lifetime of this registry (= one Run).
25
50
  * Returns an unregister function that removes the matcher by reference.
@@ -50,6 +75,39 @@ export declare class HookRegistry {
50
75
  * cannot leak into the next session on the same registry.
51
76
  */
52
77
  clearSession(sessionId: string): void;
78
+ /**
79
+ * Raise a halt signal scoped to `sessionId` (= the run id the hook
80
+ * fired under). The SDK's run loop polls for this between stream
81
+ * events with the run's own id. First-write-wins per session: a
82
+ * halt already raised by an earlier hook in the same run is
83
+ * preserved so the original `reason` / `source` aren't overwritten.
84
+ *
85
+ * Per-session scoping is critical when hosts share one registry
86
+ * across concurrent runs (e.g. a global policy registered once and
87
+ * reused). Without it, a `preventContinuation` from run A would
88
+ * trip run B's stream-loop poll on the next iteration and silently
89
+ * terminate an unrelated run.
90
+ *
91
+ * Called by the SDK after `executeHooks` returns an aggregate with
92
+ * `preventContinuation: true`. Hosts can also call it directly from
93
+ * inside a hook callback if they want to halt without going through
94
+ * the aggregated return value, but `preventContinuation` is the
95
+ * canonical path.
96
+ */
97
+ haltRun(sessionId: string, reason: string, source: HookEvent): void;
98
+ /**
99
+ * Returns the halt signal raised by hooks running under `sessionId`,
100
+ * or `undefined` if no hook in that run has halted. Polled by
101
+ * `Run.processStream` between stream events using the run's own id.
102
+ */
103
+ getHaltSignal(sessionId: string): HookHaltSignal | undefined;
104
+ /**
105
+ * Clears the halt signal for `sessionId`. Called by
106
+ * `Run.processStream` in its `finally` block so a subsequent
107
+ * invocation of the same Run (e.g. resume) starts with a fresh
108
+ * halt state. No-op when no signal exists for that session.
109
+ */
110
+ clearHaltSignal(sessionId: string): void;
53
111
  /** True if at least one matcher exists for `event` (global + session). */
54
112
  hasHookFor(event: HookEvent, sessionId?: string): boolean;
55
113
  private ensureSessionBucket;
@@ -0,0 +1,87 @@
1
+ /**
2
+ * Declarative `PreToolUse` hook factory. Lets hosts express common
3
+ * permission policies (allow / deny / ask lists + a global mode) without
4
+ * hand-rolling matching, precedence, and decision logic per-host.
5
+ *
6
+ * Maps directly to the Claude Code Agent SDK permission vocabulary
7
+ * (`allowed_tools` / `disallowed_tools` / `permissionMode`) so users of
8
+ * either SDK can think in the same terms. See the README's HITL section
9
+ * for the cross-walk and `docs/hooks-design-report.md` for the broader
10
+ * hook system context.
11
+ */
12
+ import type { HookCallback } from './types';
13
+ /**
14
+ * Permission mode controlling how tool calls that match no rule are
15
+ * resolved. Mirrors Claude Code's `permissionMode`.
16
+ *
17
+ * - `default` — unmatched tools fall through to `'ask'` (interrupt).
18
+ * - `dontAsk` — unmatched tools are denied; the human is never
19
+ * prompted. Useful for headless / API agents where a
20
+ * silent denial is preferable to a hung interrupt.
21
+ * - `bypass` — every tool is approved, except those matching `deny`
22
+ * patterns. The kill switch you flip when you trust
23
+ * the agent and want to stop being asked. Equivalent to
24
+ * Claude Code's `bypassPermissions`.
25
+ */
26
+ export type ToolPolicyMode = 'default' | 'dontAsk' | 'bypass';
27
+ export interface ToolPolicyConfig {
28
+ /**
29
+ * Global mode applied to tools that don't match any rule.
30
+ * Defaults to `'default'` (ask the human).
31
+ */
32
+ mode?: ToolPolicyMode;
33
+ /**
34
+ * Tool name patterns that are auto-approved without a prompt.
35
+ * Patterns support glob `*` wildcards: `read_file`, `mcp:github:*`,
36
+ * `*search*`. Match is anchored (`^pattern$`).
37
+ */
38
+ allow?: readonly string[];
39
+ /**
40
+ * Tool name patterns that are blocked outright. Wins over `allow`
41
+ * and `ask`, and overrides `mode: 'bypass'` — a deny rule always
42
+ * holds, matching Claude Code's "deny rules are checked first" guarantee.
43
+ */
44
+ deny?: readonly string[];
45
+ /**
46
+ * Tool name patterns that always trigger human approval, regardless
47
+ * of `mode: 'default'` vs `'dontAsk'`. In `mode: 'bypass'` these are
48
+ * still bypassed (because that's what bypass means).
49
+ */
50
+ ask?: readonly string[];
51
+ /**
52
+ * Optional reason attached to the resulting `ask` / `deny` hook
53
+ * decision so the host UI can render why approval is required.
54
+ * The literal token `{tool}` is replaced with the tool name.
55
+ */
56
+ reason?: string;
57
+ }
58
+ /**
59
+ * Build a `PreToolUse` hook callback that applies a declarative tool
60
+ * permission policy. Register it with a `HookRegistry` and the SDK's
61
+ * `humanInTheLoop` machinery handles the rest:
62
+ *
63
+ * ```ts
64
+ * const policyHook = createToolPolicyHook({
65
+ * mode: 'default',
66
+ * allow: ['read_*', 'grep', 'glob'],
67
+ * deny: ['delete_*'],
68
+ * ask: ['execute_*', 'mcp:*'],
69
+ * });
70
+ * registry.register('PreToolUse', { hooks: [policyHook] });
71
+ * ```
72
+ *
73
+ * Evaluation order matches Claude Code's permission flow:
74
+ *
75
+ * 1. `deny` rule match → `'deny'` (always wins, even in `bypass`).
76
+ * 2. `mode === 'bypass'` → `'allow'`.
77
+ * 3. `allow` rule match → `'allow'`.
78
+ * 4. `ask` rule match → `'ask'`.
79
+ * 5. `mode === 'dontAsk'` → `'deny'`.
80
+ * 6. fallthrough → `'ask'`.
81
+ *
82
+ * The returned callback is a single `HookCallback`, not a `HookMatcher` —
83
+ * register it under the matcher with the pattern you want (omit the
84
+ * pattern to fire on every tool call, which is the typical case since
85
+ * the policy itself does the filtering).
86
+ */
87
+ export declare function createToolPolicyHook(config: ToolPolicyConfig): HookCallback<'PreToolUse'>;
@@ -1,6 +1,9 @@
1
1
  export { HookRegistry } from './HookRegistry';
2
+ export type { HookHaltSignal } from './HookRegistry';
2
3
  export { executeHooks, DEFAULT_HOOK_TIMEOUT_MS } from './executeHooks';
3
4
  export { matchesQuery, hasNestedQuantifier, MAX_PATTERN_LENGTH, MAX_CACHE_SIZE, } from './matchers';
5
+ export { createToolPolicyHook } from './createToolPolicyHook';
6
+ export type { ToolPolicyMode, ToolPolicyConfig } from './createToolPolicyHook';
4
7
  export { HOOK_EVENTS } from './types';
5
- export type { HookEvent, HookInput, HookOutput, HookCallback, HookMatcher, HooksByEvent, HookInputByEvent, HookOutputByEvent, BaseHookInput, BaseHookOutput, ToolDecision, StopDecision, AggregatedHookResult, RunStartHookInput, UserPromptSubmitHookInput, PreToolUseHookInput, PostToolUseHookInput, PostToolUseFailureHookInput, PermissionDeniedHookInput, SubagentStartHookInput, SubagentStopHookInput, StopHookInput, StopFailureHookInput, PreCompactHookInput, PostCompactHookInput, RunStartHookOutput, UserPromptSubmitHookOutput, PreToolUseHookOutput, PostToolUseHookOutput, PostToolUseFailureHookOutput, PermissionDeniedHookOutput, SubagentStartHookOutput, SubagentStopHookOutput, StopHookOutput, StopFailureHookOutput, PreCompactHookOutput, PostCompactHookOutput, } from './types';
8
+ export type { HookEvent, HookInput, HookOutput, HookCallback, HookMatcher, HooksByEvent, HookInputByEvent, HookOutputByEvent, BaseHookInput, BaseHookOutput, ToolDecision, StopDecision, AggregatedHookResult, RunStartHookInput, UserPromptSubmitHookInput, PreToolUseHookInput, PostToolUseHookInput, PostToolUseFailureHookInput, PostToolBatchHookInput, PostToolBatchEntry, PermissionDeniedHookInput, SubagentStartHookInput, SubagentStopHookInput, StopHookInput, StopFailureHookInput, PreCompactHookInput, PostCompactHookInput, RunStartHookOutput, UserPromptSubmitHookOutput, PreToolUseHookOutput, PostToolUseHookOutput, PostToolUseFailureHookOutput, PostToolBatchHookOutput, PermissionDeniedHookOutput, SubagentStartHookOutput, SubagentStopHookOutput, StopHookOutput, StopFailureHookOutput, PreCompactHookOutput, PostCompactHookOutput, } from './types';
6
9
  export type { ExecuteHooksOptions } from './executeHooks';
@@ -7,7 +7,7 @@ import type { BaseMessage } from '@langchain/core/messages';
7
7
  * `docs/hooks-design-report.md` §3.2 for the mapping to existing
8
8
  * `@librechat/agents` emission points.
9
9
  */
10
- export declare const HOOK_EVENTS: readonly ["RunStart", "UserPromptSubmit", "PreToolUse", "PostToolUse", "PostToolUseFailure", "PermissionDenied", "SubagentStart", "SubagentStop", "Stop", "StopFailure", "PreCompact", "PostCompact"];
10
+ export declare const HOOK_EVENTS: readonly ["RunStart", "UserPromptSubmit", "PreToolUse", "PostToolUse", "PostToolUseFailure", "PostToolBatch", "PermissionDenied", "SubagentStart", "SubagentStop", "Stop", "StopFailure", "PreCompact", "PostCompact"];
11
11
  export type HookEvent = (typeof HOOK_EVENTS)[number];
12
12
  /** Tool-gating decision; executeHooks folds with `deny > ask > allow` precedence. */
13
13
  export type ToolDecision = 'allow' | 'deny' | 'ask';
@@ -75,6 +75,40 @@ export interface PostToolUseFailureHookInput extends BaseHookInput {
75
75
  stepId?: string;
76
76
  turn?: number;
77
77
  }
78
+ /**
79
+ * Per-tool result snapshot included in a `PostToolBatch` event. Mirrors
80
+ * the data PostToolUse / PostToolUseFailure get individually, but the
81
+ * batch view lets a single hook see the whole set so it can inject one
82
+ * consolidated convention/audit message rather than N per-tool ones.
83
+ */
84
+ export interface PostToolBatchEntry {
85
+ toolName: string;
86
+ toolInput: Record<string, unknown>;
87
+ toolUseId: string;
88
+ stepId?: string;
89
+ turn?: number;
90
+ /** Successful tool output, present only when `status === 'success'`. */
91
+ toolOutput?: unknown;
92
+ /** Error message, present only when `status === 'error'`. */
93
+ error?: string;
94
+ status: 'success' | 'error';
95
+ }
96
+ /**
97
+ * Fires once after every tool call in a single batch finishes (including
98
+ * any that were rejected via HITL). Lets a hook react to the batch as a
99
+ * whole — useful for "inject conventions once for the whole batch", batch
100
+ * audit logging, or coordinating cleanup that depends on knowing the full
101
+ * result set rather than streaming each tool's result independently.
102
+ *
103
+ * Order: fires AFTER all per-tool PostToolUse / PostToolUseFailure hooks
104
+ * for the same batch have completed, BEFORE the next model call. Pass an
105
+ * `additionalContext` to inject context for that next model turn.
106
+ */
107
+ export interface PostToolBatchHookInput extends BaseHookInput {
108
+ hook_event_name: 'PostToolBatch';
109
+ /** All tool calls (and their outcomes) from this batch, in batch order. */
110
+ entries: PostToolBatchEntry[];
111
+ }
78
112
  export interface PermissionDeniedHookInput extends BaseHookInput {
79
113
  hook_event_name: 'PermissionDenied';
80
114
  toolName: string;
@@ -128,7 +162,7 @@ export interface PostCompactHookInput extends BaseHookInput {
128
162
  messagesAfterCount: number;
129
163
  }
130
164
  /** Discriminated union of every hook input shape. */
131
- export type HookInput = RunStartHookInput | UserPromptSubmitHookInput | PreToolUseHookInput | PostToolUseHookInput | PostToolUseFailureHookInput | PermissionDeniedHookInput | SubagentStartHookInput | SubagentStopHookInput | StopHookInput | StopFailureHookInput | PreCompactHookInput | PostCompactHookInput;
165
+ export type HookInput = RunStartHookInput | UserPromptSubmitHookInput | PreToolUseHookInput | PostToolUseHookInput | PostToolUseFailureHookInput | PostToolBatchHookInput | PermissionDeniedHookInput | SubagentStartHookInput | SubagentStopHookInput | StopHookInput | StopFailureHookInput | PreCompactHookInput | PostCompactHookInput;
132
166
  /** Compile-time map from event name to its input shape. */
133
167
  export type HookInputByEvent = {
134
168
  RunStart: RunStartHookInput;
@@ -136,6 +170,7 @@ export type HookInputByEvent = {
136
170
  PreToolUse: PreToolUseHookInput;
137
171
  PostToolUse: PostToolUseHookInput;
138
172
  PostToolUseFailure: PostToolUseFailureHookInput;
173
+ PostToolBatch: PostToolBatchHookInput;
139
174
  PermissionDenied: PermissionDeniedHookInput;
140
175
  SubagentStart: SubagentStartHookInput;
141
176
  SubagentStop: SubagentStopHookInput;
@@ -155,6 +190,56 @@ export interface BaseHookOutput {
155
190
  preventContinuation?: boolean;
156
191
  /** Reason reported alongside `preventContinuation`. */
157
192
  stopReason?: string;
193
+ /**
194
+ * Marks this hook output as fire-and-forget for INFLUENCE only.
195
+ * When `true`, the SDK skips every other field on this output —
196
+ * `decision`, `additionalContext`, `updatedInput`,
197
+ * `preventContinuation`, `allowedDecisions`, `updatedOutput` are
198
+ * all ignored. The hook's return value cannot block, modify, or
199
+ * inject context, so it's safe to use for pure side effects
200
+ * (logging, metrics, webhooks).
201
+ *
202
+ * Important caveat: the hook's CALLBACK promise is still awaited
203
+ * by `executeHooks` (subject to the matcher's timeout and the
204
+ * default `DEFAULT_HOOK_TIMEOUT_MS`). The SDK does not
205
+ * speculatively detach hooks based on output shape, because the
206
+ * shape is only known after the promise resolves. For TRUE
207
+ * fire-and-forget where the agent doesn't wait at all, the hook
208
+ * body should detach its side effect itself and return
209
+ * immediately:
210
+ *
211
+ * @example
212
+ * ```ts
213
+ * async (input) => {
214
+ * // Detach the slow work — the SDK awaits this hook's
215
+ * // returned promise, which resolves immediately because we
216
+ * // don't `await` the side effect.
217
+ * void sendToLoggingService(input).catch(console.error);
218
+ * return { async: true };
219
+ * };
220
+ * ```
221
+ *
222
+ * @example WRONG — the agent will block on the webhook
223
+ * ```ts
224
+ * async (input) => {
225
+ * await sendToLoggingService(input); // ← awaited, blocks
226
+ * return { async: true }; // returning async:true doesn't undo the await
227
+ * };
228
+ * ```
229
+ *
230
+ * Mirrors Claude Code Agent SDK's `async` output, with the same
231
+ * "detach inside the hook body" pattern.
232
+ */
233
+ async?: boolean;
234
+ /**
235
+ * Optional advisory timeout in milliseconds for the background work
236
+ * a host has detached inside an `async: true` hook body. The SDK
237
+ * does not enforce this (the hook's own AbortSignal handling does)
238
+ * but the field is preserved on the wire so downstream
239
+ * observability can surface long-running side effects. Ignored
240
+ * unless `async` is true.
241
+ */
242
+ asyncTimeout?: number;
158
243
  }
159
244
  export type RunStartHookOutput = BaseHookOutput;
160
245
  export interface UserPromptSubmitHookOutput extends BaseHookOutput {
@@ -175,6 +260,19 @@ export interface PreToolUseHookOutput extends BaseHookOutput {
175
260
  * `updatedInput` to one hook per matcher to avoid confusing precedence.
176
261
  */
177
262
  updatedInput?: Record<string, unknown>;
263
+ /**
264
+ * Restricts which decisions the host UI is allowed to surface for this
265
+ * tool call when the hook returns `decision: 'ask'`. Pass to lock a
266
+ * tool down to a subset of `'approve' | 'reject' | 'edit' | 'respond'`
267
+ * — for example, `['approve', 'reject']` to forbid the user from
268
+ * editing the tool's args or substituting a custom response.
269
+ *
270
+ * The values flow into the resulting interrupt's
271
+ * `review_configs[i].allowed_decisions`. Omitting the field keeps the
272
+ * SDK default (all four decisions advertised). Last-writer-wins in
273
+ * registration order, same precedence rules as `updatedInput`.
274
+ */
275
+ allowedDecisions?: ReadonlyArray<'approve' | 'reject' | 'edit' | 'respond'>;
178
276
  }
179
277
  export interface PostToolUseHookOutput extends BaseHookOutput {
180
278
  /**
@@ -186,6 +284,7 @@ export interface PostToolUseHookOutput extends BaseHookOutput {
186
284
  updatedOutput?: unknown;
187
285
  }
188
286
  export type PostToolUseFailureHookOutput = BaseHookOutput;
287
+ export type PostToolBatchHookOutput = BaseHookOutput;
189
288
  export type PermissionDeniedHookOutput = BaseHookOutput;
190
289
  export interface SubagentStartHookOutput extends BaseHookOutput {
191
290
  decision?: ToolDecision;
@@ -206,6 +305,7 @@ export type HookOutputByEvent = {
206
305
  PreToolUse: PreToolUseHookOutput;
207
306
  PostToolUse: PostToolUseHookOutput;
208
307
  PostToolUseFailure: PostToolUseFailureHookOutput;
308
+ PostToolBatch: PostToolBatchHookOutput;
209
309
  PermissionDenied: PermissionDeniedHookOutput;
210
310
  SubagentStart: SubagentStartHookOutput;
211
311
  SubagentStop: SubagentStopHookOutput;
@@ -215,7 +315,7 @@ export type HookOutputByEvent = {
215
315
  PostCompact: PostCompactHookOutput;
216
316
  };
217
317
  /** Superset output shape used by the executor's fold loop. */
218
- export type HookOutput = RunStartHookOutput | UserPromptSubmitHookOutput | PreToolUseHookOutput | PostToolUseHookOutput | PostToolUseFailureHookOutput | PermissionDeniedHookOutput | SubagentStartHookOutput | SubagentStopHookOutput | StopHookOutput | StopFailureHookOutput | PreCompactHookOutput | PostCompactHookOutput;
318
+ export type HookOutput = RunStartHookOutput | UserPromptSubmitHookOutput | PreToolUseHookOutput | PostToolUseHookOutput | PostToolUseFailureHookOutput | PostToolBatchHookOutput | PermissionDeniedHookOutput | SubagentStartHookOutput | SubagentStopHookOutput | StopHookOutput | StopFailureHookOutput | PreCompactHookOutput | PostCompactHookOutput;
219
319
  /**
220
320
  * A hook callback is a plain async function registered against a specific
221
321
  * event. The `signal` is always supplied by `executeHooks` and combines the
@@ -297,6 +397,12 @@ export interface AggregatedHookResult {
297
397
  * hook per matcher to avoid subtle precedence bugs.
298
398
  */
299
399
  updatedInput?: Record<string, unknown>;
400
+ /**
401
+ * Restricted decision set from a `PreToolUse` hook. Same last-writer-wins
402
+ * semantics as `updatedInput`. Surfaces to the interrupt payload's
403
+ * `review_configs[i].allowed_decisions`.
404
+ */
405
+ allowedDecisions?: ReadonlyArray<'approve' | 'reject' | 'edit' | 'respond'>;
300
406
  /**
301
407
  * Replacement tool output from a `PostToolUse` hook.
302
408
  *
@@ -23,7 +23,17 @@ export * from './tools/search';
23
23
  export * from './common';
24
24
  export * from './utils';
25
25
  export * from './hooks';
26
+ export * from './hitl';
26
27
  export type * from './types';
28
+ export * from './langchain';
29
+ /**
30
+ * HITL primitives re-exported from `@langchain/langgraph` so hosts that
31
+ * build durable checkpoint savers, dispatch `Command({ resume })`, or
32
+ * detect interrupts can do so against the same langgraph instance the
33
+ * SDK was compiled against — avoiding accidental dual-version drift.
34
+ */
35
+ export { Command, INTERRUPT, interrupt, MemorySaver, BaseCheckpointSaver, isInterrupted, } from '@langchain/langgraph';
36
+ export type { Interrupt } from '@langchain/langgraph';
27
37
  export { CustomOpenAIClient } from './llm/openai';
28
38
  export { ChatOpenRouter } from './llm/openrouter';
29
39
  export type { OpenRouterReasoning, OpenRouterReasoningEffort, ChatOpenRouterCallOptions, } from './llm/openrouter';
@@ -0,0 +1 @@
1
+ export type { GoogleAIToolType } from '@langchain/google-common';
@@ -0,0 +1,8 @@
1
+ export * from './messages';
2
+ export * from './prompts';
3
+ export * from './runnables';
4
+ export * from './tools';
5
+ export * from './google-common';
6
+ export * from './language_models/chat_models';
7
+ export * from './messages/tool';
8
+ export * from './openai';
@@ -0,0 +1 @@
1
+ export type { BindToolsInput } from '@langchain/core/language_models/chat_models';
@@ -0,0 +1 @@
1
+ export type { InvalidToolCall, ToolCall, ToolCallChunk, } from '@langchain/core/messages/tool';
@@ -0,0 +1,2 @@
1
+ export { AIMessage, AIMessageChunk, BaseMessage, BaseMessageChunk, HumanMessage, SystemMessage, ToolMessage, getBufferString, isAIMessage, isBaseMessage, isToolMessage, } from '@langchain/core/messages';
2
+ export type { BaseMessageFields, MessageContent, MessageContentText, MessageContentImageUrl, UsageMetadata, } from '@langchain/core/messages';
@@ -0,0 +1 @@
1
+ export type { AzureOpenAIInput } from '@langchain/openai';
@@ -0,0 +1 @@
1
+ export { PromptTemplate } from '@langchain/core/prompts';
@@ -0,0 +1,2 @@
1
+ export { Runnable, RunnableLambda, RunnableSequence, } from '@langchain/core/runnables';
2
+ export type { RunnableConfig } from '@langchain/core/runnables';
@@ -0,0 +1,2 @@
1
+ export { DynamicStructuredTool, StructuredTool, Tool, tool, } from '@langchain/core/tools';
2
+ export type { StructuredToolInterface } from '@langchain/core/tools';
@@ -0,0 +1 @@
1
+ export { getEnvironmentVariable } from '@langchain/core/utils/env';
@@ -4,18 +4,31 @@ import type { BaseChatModelParams } from '@langchain/core/language_models/chat_m
4
4
  import type { BaseMessage, UsageMetadata } from '@langchain/core/messages';
5
5
  import type { CallbackManagerForLLMRun } from '@langchain/core/callbacks/manager';
6
6
  import type { AnthropicInput } from '@langchain/anthropic';
7
- import type { AnthropicMessageCreateParams, AnthropicStreamingMessageCreateParams, AnthropicOutputConfig } from '@/llm/anthropic/types';
7
+ import type { Anthropic } from '@anthropic-ai/sdk';
8
+ import type { AnthropicMessageCreateParams, AnthropicStreamingMessageCreateParams, AnthropicOutputConfig, AnthropicBeta, AnthropicMCPServerURLDefinition, AnthropicContextManagementConfigParam } from '@/llm/anthropic/types';
9
+ export declare function _documentsInParams(params: AnthropicMessageCreateParams | AnthropicStreamingMessageCreateParams): boolean;
8
10
  export type CustomAnthropicInput = AnthropicInput & {
9
11
  _lc_stream_delay?: number;
10
12
  outputConfig?: AnthropicOutputConfig;
11
13
  inferenceGeo?: string;
12
- contextManagement?: any;
14
+ contextManagement?: AnthropicContextManagementConfigParam;
13
15
  } & BaseChatModelParams;
14
- /**
15
- * A type representing additional parameters that can be passed to the
16
- * Anthropic API.
17
- */
18
- type Kwargs = Record<string, any>;
16
+ export type CustomAnthropicCallOptions = {
17
+ outputConfig?: AnthropicOutputConfig;
18
+ outputFormat?: Anthropic.Messages.JSONOutputFormat;
19
+ inferenceGeo?: string;
20
+ betas?: AnthropicBeta[];
21
+ container?: string;
22
+ mcp_servers?: AnthropicMCPServerURLDefinition[];
23
+ };
24
+ type CustomAnthropicInvocationParams = {
25
+ betas?: AnthropicBeta[];
26
+ container?: string;
27
+ context_management?: AnthropicContextManagementConfigParam;
28
+ inference_geo?: string;
29
+ mcp_servers?: AnthropicMCPServerURLDefinition[];
30
+ output_config?: AnthropicOutputConfig;
31
+ };
19
32
  export declare class CustomAnthropic extends ChatAnthropicMessages {
20
33
  _lc_stream_delay: number;
21
34
  private message_start;
@@ -25,13 +38,13 @@ export declare class CustomAnthropic extends ChatAnthropicMessages {
25
38
  top_k: number | undefined;
26
39
  outputConfig?: AnthropicOutputConfig;
27
40
  inferenceGeo?: string;
28
- contextManagement?: any;
41
+ contextManagement?: AnthropicContextManagementConfigParam;
29
42
  constructor(fields?: CustomAnthropicInput);
30
43
  static lc_name(): 'LibreChatAnthropic';
31
44
  /**
32
45
  * Get the parameters used to invoke the model
33
46
  */
34
- invocationParams(options?: this['ParsedCallOptions']): Omit<AnthropicMessageCreateParams | AnthropicStreamingMessageCreateParams, 'messages'> & Kwargs;
47
+ invocationParams(options?: this['ParsedCallOptions'] & CustomAnthropicCallOptions): Omit<AnthropicMessageCreateParams | AnthropicStreamingMessageCreateParams, 'messages'> & CustomAnthropicInvocationParams;
35
48
  /**
36
49
  * Get stream usage as returned by this client's API response.
37
50
  * @returns The stream usage object.
@@ -1,5 +1,7 @@
1
1
  import Anthropic from '@anthropic-ai/sdk';
2
- import { BindToolsInput } from '@langchain/core/language_models/chat_models';
2
+ import type { BindToolsInput } from '@langchain/core/language_models/chat_models';
3
+ import type { AnthropicBeta } from '@anthropic-ai/sdk/resources';
4
+ export type { AnthropicBeta };
3
5
  export type AnthropicStreamUsage = Anthropic.Usage;
4
6
  export type AnthropicMessageDeltaEvent = Anthropic.MessageDeltaEvent;
5
7
  export type AnthropicMessageStartEvent = Anthropic.MessageStartEvent;
@@ -14,8 +16,10 @@ export type AnthropicMessageResponse = Anthropic.ContentBlock | AnthropicToolRes
14
16
  export type AnthropicMessageCreateParams = Anthropic.MessageCreateParamsNonStreaming;
15
17
  export type AnthropicStreamingMessageCreateParams = Anthropic.MessageCreateParamsStreaming;
16
18
  export type AnthropicThinkingConfigParam = Anthropic.ThinkingConfigParam;
19
+ export type AnthropicContextManagementConfigParam = Anthropic.Beta.BetaContextManagementConfig;
17
20
  export type AnthropicMessageStreamEvent = Anthropic.MessageStreamEvent;
18
21
  export type AnthropicRequestOptions = Anthropic.RequestOptions;
22
+ export type AnthropicMCPServerURLDefinition = Anthropic.Beta.Messages.BetaRequestMCPServerURLDefinition;
19
23
  export type AnthropicToolChoice = {
20
24
  type: 'tool';
21
25
  name: string;
@@ -1,10 +1,16 @@
1
- /**
2
- * This util file contains functions for converting Anthropic messages to LangChain messages.
3
- */
4
- import Anthropic from '@anthropic-ai/sdk';
1
+ /** This util file contains functions for converting Anthropic messages to LangChain messages. */
5
2
  import { AIMessageChunk } from '@langchain/core/messages';
6
- import { ChatGeneration } from '@langchain/core/outputs';
7
- import { AnthropicMessageResponse } from '../types';
3
+ import type Anthropic from '@anthropic-ai/sdk';
4
+ import type { UsageMetadata } from '@langchain/core/messages';
5
+ import type { ChatGeneration } from '@langchain/core/outputs';
6
+ import type { AnthropicMessageResponse } from '../types';
7
+ interface AnthropicUsageData {
8
+ input_tokens?: number | null;
9
+ output_tokens?: number | null;
10
+ cache_creation_input_tokens?: number | null;
11
+ cache_read_input_tokens?: number | null;
12
+ }
13
+ export declare function getAnthropicUsageMetadata(usage: AnthropicUsageData | null | undefined): UsageMetadata | undefined;
8
14
  export declare function _makeMessageChunkFromAnthropicEvent(data: Anthropic.Beta.Messages.BetaRawMessageStreamEvent, fields: {
9
15
  streamUsage: boolean;
10
16
  coerceContentToString: boolean;
@@ -12,3 +18,4 @@ export declare function _makeMessageChunkFromAnthropicEvent(data: Anthropic.Beta
12
18
  chunk: AIMessageChunk;
13
19
  } | null;
14
20
  export declare function anthropicResponseToChatMessages(messages: AnthropicMessageResponse[], additionalKwargs: Record<string, unknown>): ChatGeneration[];
21
+ export {};
@@ -18,5 +18,5 @@ export declare class AnthropicToolsOutputParser<T extends Record<string, any> =
18
18
  protected _validateResult(result: unknown): Promise<T>;
19
19
  parseResult(generations: ChatGeneration[]): Promise<T>;
20
20
  }
21
- export declare function extractToolCalls(content: Record<string, any>[]): ToolCall[];
21
+ export declare function extractToolCalls(content: Record<string, any>[]): ToolCall<string, Record<string, any>>[];
22
22
  export {};