@librechat/agents-types 3.0.36 → 3.0.40

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 (3) hide show
  1. package/graph.ts +7 -1
  2. package/package.json +1 -1
  3. package/tools.ts +166 -0
package/graph.ts CHANGED
@@ -18,7 +18,7 @@ import type {
18
18
  import type { RunnableConfig, Runnable } from '@langchain/core/runnables';
19
19
  import type { ChatGenerationChunk } from '@langchain/core/outputs';
20
20
  import type { GoogleAIToolType } from '@langchain/google-common';
21
- import type { ToolMap, ToolEndEvent, GenericTool } from '@/types/tools';
21
+ import type { ToolMap, ToolEndEvent, GenericTool, LCTool } from '@/types/tools';
22
22
  import type { Providers, Callback, GraphNodeKeys } from '@/common';
23
23
  import type { StandardGraph, MultiAgentGraph } from '@/graphs';
24
24
  import type { ClientOptions } from '@/types/llm';
@@ -369,4 +369,10 @@ export interface AgentInputs {
369
369
  reasoningKey?: 'reasoning_content' | 'reasoning';
370
370
  /** Format content blocks as strings (for legacy compatibility i.e. Ollama/Azure Serverless) */
371
371
  useLegacyContent?: boolean;
372
+ /**
373
+ * Tool definitions for all tools, including deferred and programmatic.
374
+ * Used for tool search and programmatic tool calling.
375
+ * Maps tool name to LCTool definition.
376
+ */
377
+ toolRegistry?: Map<string, LCTool>;
372
378
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@librechat/agents-types",
3
- "version": "3.0.36",
3
+ "version": "3.0.40",
4
4
  "description": "Type definitions for @librechat/agents",
5
5
  "types": "index.d.ts",
6
6
  "scripts": {
package/tools.ts CHANGED
@@ -35,6 +35,12 @@ export type ToolNodeOptions = {
35
35
  data: ToolErrorData,
36
36
  metadata?: Record<string, unknown>
37
37
  ) => Promise<void>;
38
+ /** Tools available for programmatic code execution (allowed_callers includes 'code_execution') */
39
+ programmaticToolMap?: ToolMap;
40
+ /** Tool definitions for programmatic code execution (sent to Code API for stub generation) */
41
+ programmaticToolDefs?: LCTool[];
42
+ /** Tool registry for tool search (deferred tool definitions) */
43
+ toolRegistry?: LCToolRegistry;
38
44
  };
39
45
 
40
46
  export type ToolNodeConstructorParams = ToolRefs & ToolNodeOptions;
@@ -78,3 +84,163 @@ export type ExecuteResult = {
78
84
  stderr: string;
79
85
  files?: FileRefs;
80
86
  };
87
+
88
+ /** JSON Schema type definition for tool parameters */
89
+ export type JsonSchemaType = {
90
+ type:
91
+ | 'string'
92
+ | 'number'
93
+ | 'integer'
94
+ | 'float'
95
+ | 'boolean'
96
+ | 'array'
97
+ | 'object';
98
+ enum?: string[];
99
+ items?: JsonSchemaType;
100
+ properties?: Record<string, JsonSchemaType>;
101
+ required?: string[];
102
+ description?: string;
103
+ additionalProperties?: boolean | JsonSchemaType;
104
+ };
105
+
106
+ /**
107
+ * Specifies which contexts can invoke a tool (inspired by Anthropic's allowed_callers)
108
+ * - 'direct': Only callable directly by the LLM (default if omitted)
109
+ * - 'code_execution': Only callable from within programmatic code execution
110
+ */
111
+ export type AllowedCaller = 'direct' | 'code_execution';
112
+
113
+ /** Tool definition with optional deferred loading and caller restrictions */
114
+ export type LCTool = {
115
+ name: string;
116
+ description?: string;
117
+ parameters?: JsonSchemaType;
118
+ /** When true, tool is not loaded into context initially (for tool search) */
119
+ defer_loading?: boolean;
120
+ /**
121
+ * Which contexts can invoke this tool.
122
+ * Default: ['direct'] (only callable directly by LLM)
123
+ * Options: 'direct', 'code_execution'
124
+ */
125
+ allowed_callers?: AllowedCaller[];
126
+ };
127
+
128
+ /** Map of tool names to tool definitions */
129
+ export type LCToolRegistry = Map<string, LCTool>;
130
+
131
+ /** Parameters for creating a Tool Search Regex tool */
132
+ export type ToolSearchRegexParams = {
133
+ apiKey?: string;
134
+ toolRegistry?: LCToolRegistry;
135
+ onlyDeferred?: boolean;
136
+ baseUrl?: string;
137
+ [key: string]: unknown;
138
+ };
139
+
140
+ /** Simplified tool metadata for search purposes */
141
+ export type ToolMetadata = {
142
+ name: string;
143
+ description: string;
144
+ parameters?: JsonSchemaType;
145
+ };
146
+
147
+ /** Individual search result for a matching tool */
148
+ export type ToolSearchResult = {
149
+ tool_name: string;
150
+ match_score: number;
151
+ matched_field: string;
152
+ snippet: string;
153
+ };
154
+
155
+ /** Response from the tool search operation */
156
+ export type ToolSearchResponse = {
157
+ tool_references: ToolSearchResult[];
158
+ total_tools_searched: number;
159
+ pattern_used: string;
160
+ };
161
+
162
+ /** Artifact returned alongside the formatted search results */
163
+ export type ToolSearchArtifact = {
164
+ tool_references: ToolSearchResult[];
165
+ metadata: {
166
+ total_searched: number;
167
+ pattern: string;
168
+ error?: string;
169
+ };
170
+ };
171
+
172
+ // ============================================================================
173
+ // Programmatic Tool Calling Types
174
+ // ============================================================================
175
+
176
+ /**
177
+ * Tool call requested by the Code API during programmatic execution
178
+ */
179
+ export type PTCToolCall = {
180
+ /** Unique ID like "call_001" */
181
+ id: string;
182
+ /** Tool name */
183
+ name: string;
184
+ /** Input parameters */
185
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
186
+ input: Record<string, any>;
187
+ };
188
+
189
+ /**
190
+ * Tool result sent back to the Code API
191
+ */
192
+ export type PTCToolResult = {
193
+ /** Matches PTCToolCall.id */
194
+ call_id: string;
195
+ /** Tool execution result (any JSON-serializable value) */
196
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
197
+ result: any;
198
+ /** Whether tool execution failed */
199
+ is_error: boolean;
200
+ /** Error details if is_error=true */
201
+ error_message?: string;
202
+ };
203
+
204
+ /**
205
+ * Response from the Code API for programmatic execution
206
+ */
207
+ export type ProgrammaticExecutionResponse = {
208
+ status: 'tool_call_required' | 'completed' | 'error' | unknown;
209
+ session_id?: string;
210
+
211
+ /** Present when status='tool_call_required' */
212
+ continuation_token?: string;
213
+ tool_calls?: PTCToolCall[];
214
+
215
+ /** Present when status='completed' */
216
+ stdout?: string;
217
+ stderr?: string;
218
+ files?: FileRefs;
219
+
220
+ /** Present when status='error' */
221
+ error?: string;
222
+ };
223
+
224
+ /**
225
+ * Artifact returned by the PTC tool
226
+ */
227
+ export type ProgrammaticExecutionArtifact = {
228
+ session_id?: string;
229
+ files?: FileRefs;
230
+ };
231
+
232
+ /**
233
+ * Initialization parameters for the PTC tool
234
+ */
235
+ export type ProgrammaticToolCallingParams = {
236
+ /** Code API key (or use CODE_API_KEY env var) */
237
+ apiKey?: string;
238
+ /** Code API base URL (or use CODE_BASEURL env var) */
239
+ baseUrl?: string;
240
+ /** Safety limit for round-trips (default: 20) */
241
+ maxRoundTrips?: number;
242
+ /** HTTP proxy URL */
243
+ proxy?: string;
244
+ /** Environment variable key for API key */
245
+ [key: string]: unknown;
246
+ };