@librechat/agents 3.1.79 → 3.1.80-dev.0
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.
- package/dist/cjs/tools/BashExecutor.cjs +10 -2
- package/dist/cjs/tools/BashExecutor.cjs.map +1 -1
- package/dist/cjs/tools/BashProgrammaticToolCalling.cjs +2 -1
- package/dist/cjs/tools/BashProgrammaticToolCalling.cjs.map +1 -1
- package/dist/cjs/tools/CodeExecutor.cjs +16 -5
- package/dist/cjs/tools/CodeExecutor.cjs.map +1 -1
- package/dist/cjs/tools/ProgrammaticToolCalling.cjs +9 -4
- package/dist/cjs/tools/ProgrammaticToolCalling.cjs.map +1 -1
- package/dist/cjs/tools/ToolNode.cjs +63 -40
- package/dist/cjs/tools/ToolNode.cjs.map +1 -1
- package/dist/cjs/tools/local/LocalExecutionTools.cjs.map +1 -1
- package/dist/cjs/tools/local/LocalProgrammaticToolCalling.cjs.map +1 -1
- package/dist/esm/tools/BashExecutor.mjs +10 -2
- package/dist/esm/tools/BashExecutor.mjs.map +1 -1
- package/dist/esm/tools/BashProgrammaticToolCalling.mjs +2 -1
- package/dist/esm/tools/BashProgrammaticToolCalling.mjs.map +1 -1
- package/dist/esm/tools/CodeExecutor.mjs +16 -5
- package/dist/esm/tools/CodeExecutor.mjs.map +1 -1
- package/dist/esm/tools/ProgrammaticToolCalling.mjs +9 -4
- package/dist/esm/tools/ProgrammaticToolCalling.mjs.map +1 -1
- package/dist/esm/tools/ToolNode.mjs +63 -40
- package/dist/esm/tools/ToolNode.mjs.map +1 -1
- package/dist/esm/tools/local/LocalExecutionTools.mjs.map +1 -1
- package/dist/esm/tools/local/LocalProgrammaticToolCalling.mjs.map +1 -1
- package/dist/types/types/tools.d.ts +82 -17
- package/package.json +1 -1
- package/src/scripts/code_exec_multi_session.ts +4 -4
- package/src/tools/BashExecutor.ts +11 -3
- package/src/tools/BashProgrammaticToolCalling.ts +6 -6
- package/src/tools/CodeExecutor.ts +17 -6
- package/src/tools/ProgrammaticToolCalling.ts +14 -10
- package/src/tools/ToolNode.ts +85 -48
- package/src/tools/__tests__/ProgrammaticToolCalling.test.ts +9 -2
- package/src/tools/__tests__/ToolNode.session.test.ts +131 -50
- package/src/tools/local/LocalExecutionTools.ts +2 -2
- package/src/tools/local/LocalProgrammaticToolCalling.ts +23 -6
- package/src/types/tools.ts +79 -17
|
@@ -115,7 +115,7 @@ export function createLocalCodeExecutionTool(
|
|
|
115
115
|
{
|
|
116
116
|
session_id: getLocalSessionId(config),
|
|
117
117
|
files: [],
|
|
118
|
-
},
|
|
118
|
+
} satisfies t.CodeExecutionArtifact,
|
|
119
119
|
];
|
|
120
120
|
},
|
|
121
121
|
{
|
|
@@ -151,7 +151,7 @@ export function createLocalBashExecutionTool(options?: {
|
|
|
151
151
|
{
|
|
152
152
|
session_id: getLocalSessionId(config),
|
|
153
153
|
files: [],
|
|
154
|
-
},
|
|
154
|
+
} satisfies t.CodeExecutionArtifact,
|
|
155
155
|
];
|
|
156
156
|
},
|
|
157
157
|
{
|
|
@@ -79,7 +79,9 @@ type LocalProgrammaticParams = {
|
|
|
79
79
|
|
|
80
80
|
type ToolFilter = (toolDefs: t.LCTool[], code: string) => t.LCTool[];
|
|
81
81
|
|
|
82
|
-
function resolveRuntime(
|
|
82
|
+
function resolveRuntime(
|
|
83
|
+
params: LocalProgrammaticParams
|
|
84
|
+
): LocalProgrammaticRuntime {
|
|
83
85
|
const rawRuntime = params.lang ?? params.runtime ?? params.language ?? 'bash';
|
|
84
86
|
return rawRuntime === 'py' || rawRuntime === 'python' ? 'python' : 'bash';
|
|
85
87
|
}
|
|
@@ -494,13 +496,17 @@ async function runLocalProgrammaticTool(args: {
|
|
|
494
496
|
localConfig: t.LocalExecutionConfig;
|
|
495
497
|
runtime: LocalProgrammaticRuntime;
|
|
496
498
|
}): Promise<[string, t.ProgrammaticExecutionArtifact]> {
|
|
497
|
-
const { toolMap, toolDefs, hookContext } = getProgrammaticContext(
|
|
499
|
+
const { toolMap, toolDefs, hookContext } = getProgrammaticContext(
|
|
500
|
+
args.config
|
|
501
|
+
);
|
|
498
502
|
|
|
499
503
|
if (toolMap == null || toolMap.size === 0) {
|
|
500
504
|
throw new Error('No toolMap provided for local programmatic execution.');
|
|
501
505
|
}
|
|
502
506
|
if (toolDefs == null || toolDefs.length === 0) {
|
|
503
|
-
throw new Error(
|
|
507
|
+
throw new Error(
|
|
508
|
+
'No tool definitions provided for local programmatic execution.'
|
|
509
|
+
);
|
|
504
510
|
}
|
|
505
511
|
|
|
506
512
|
const { effectiveTools, effectiveMap } = createEffectiveToolMap(
|
|
@@ -512,17 +518,28 @@ async function runLocalProgrammaticTool(args: {
|
|
|
512
518
|
const bridge = await createToolBridge(effectiveMap, hookContext);
|
|
513
519
|
|
|
514
520
|
try {
|
|
515
|
-
const timeoutMs =
|
|
521
|
+
const timeoutMs =
|
|
522
|
+
args.params.timeout ?? args.localConfig.timeoutMs ?? DEFAULT_TIMEOUT;
|
|
516
523
|
const result =
|
|
517
524
|
args.runtime === 'bash'
|
|
518
525
|
? await executeLocalBash(
|
|
519
|
-
createBashProgram(
|
|
526
|
+
createBashProgram(
|
|
527
|
+
args.params.code,
|
|
528
|
+
effectiveTools,
|
|
529
|
+
bridge.url,
|
|
530
|
+
bridge.token
|
|
531
|
+
),
|
|
520
532
|
{ ...args.localConfig, timeoutMs }
|
|
521
533
|
)
|
|
522
534
|
: await executeLocalCode(
|
|
523
535
|
{
|
|
524
536
|
lang: 'py',
|
|
525
|
-
code: createPythonProgram(
|
|
537
|
+
code: createPythonProgram(
|
|
538
|
+
args.params.code,
|
|
539
|
+
effectiveTools,
|
|
540
|
+
bridge.url,
|
|
541
|
+
bridge.token
|
|
542
|
+
),
|
|
526
543
|
},
|
|
527
544
|
{ ...args.localConfig, timeoutMs }
|
|
528
545
|
);
|
package/src/types/tools.ts
CHANGED
|
@@ -138,42 +138,90 @@ export type ToolEndEvent = {
|
|
|
138
138
|
type?: 'tool_call';
|
|
139
139
|
};
|
|
140
140
|
|
|
141
|
-
|
|
141
|
+
/**
|
|
142
|
+
* Closed set of resource kinds for sandbox file caching. Defined as a
|
|
143
|
+
* `as const` tuple so the runtime list and the TypeScript union can't
|
|
144
|
+
* drift on future additions — adding a new kind to the tuple updates
|
|
145
|
+
* both at once.
|
|
146
|
+
*
|
|
147
|
+
* - `skill`: shared per skill identity. Cross-user-within-tenant
|
|
148
|
+
* sharing. Codeapi sessionKey omits the user dimension. `version`
|
|
149
|
+
* is required (skill's monotonic counter scopes cache per revision).
|
|
150
|
+
* - `agent`: shared per agent identity. Same sharing semantic as
|
|
151
|
+
* skills.
|
|
152
|
+
* - `user`: user-private. Codeapi sessionKey is keyed by the
|
|
153
|
+
* requesting user from auth context. Used for chat attachments
|
|
154
|
+
* and code-output files.
|
|
155
|
+
*/
|
|
156
|
+
export const CODE_ENV_KINDS = ['skill', 'agent', 'user'] as const;
|
|
157
|
+
export type CodeEnvKind = (typeof CODE_ENV_KINDS)[number];
|
|
158
|
+
|
|
159
|
+
type CodeEnvFileBase = {
|
|
160
|
+
/**
|
|
161
|
+
* Resource identity. Semantics depend on `kind`:
|
|
162
|
+
* - `skill`: skill `_id` (sessionKey-meaningful, cross-user shared).
|
|
163
|
+
* - `agent`: agent id (sessionKey-meaningful, cross-user shared).
|
|
164
|
+
* - `user`: informational only — codeapi derives sessionKey from
|
|
165
|
+
* the auth-context user. Kept on the type for shape uniformity;
|
|
166
|
+
* do not rely on it for routing.
|
|
167
|
+
*/
|
|
142
168
|
id: string;
|
|
143
169
|
name: string;
|
|
144
|
-
session_id: string;
|
|
145
170
|
/**
|
|
146
|
-
*
|
|
147
|
-
*
|
|
148
|
-
*
|
|
149
|
-
*
|
|
150
|
-
*
|
|
151
|
-
* file plus a user attachment in the same call).
|
|
171
|
+
* Storage session — the long-lived bucket where this file's bytes
|
|
172
|
+
* live in object storage. Distinct from the (transient) execution
|
|
173
|
+
* session id that appears at the top level of an execute response;
|
|
174
|
+
* the two used to share the field name `session_id` and the
|
|
175
|
+
* conflation caused real bugs. See codeapi #1455 / agents #148.
|
|
152
176
|
*/
|
|
153
|
-
|
|
177
|
+
storage_session_id: string;
|
|
154
178
|
};
|
|
155
179
|
|
|
180
|
+
/**
|
|
181
|
+
* `CodeEnvFile` is a discriminated union on `kind`. `version` is
|
|
182
|
+
* statically required for `kind: 'skill'` and statically forbidden
|
|
183
|
+
* for `agent` / `user` — the constraint holds at compile time on
|
|
184
|
+
* every consumer, not just on codeapi's runtime validator.
|
|
185
|
+
*
|
|
186
|
+
* Codeapi switches on `kind` to derive the sessionKey for cache
|
|
187
|
+
* scoping (`<tenant>:<kind>:<id>[:v:<version>]`). Cross-user sharing
|
|
188
|
+
* for `kind: 'skill'` / `'agent'` is a designed property of the
|
|
189
|
+
* kind switch.
|
|
190
|
+
*/
|
|
191
|
+
export type CodeEnvFile =
|
|
192
|
+
| (CodeEnvFileBase & { kind: 'skill'; version: number })
|
|
193
|
+
| (CodeEnvFileBase & { kind: 'agent' })
|
|
194
|
+
| (CodeEnvFileBase & { kind: 'user' });
|
|
195
|
+
|
|
156
196
|
export type CodeExecutionToolParams =
|
|
157
197
|
| undefined
|
|
158
198
|
| {
|
|
199
|
+
/** Execution session — see `CodeSessionContext.session_id`. */
|
|
159
200
|
session_id?: string;
|
|
160
201
|
user_id?: string;
|
|
161
202
|
files?: CodeEnvFile[];
|
|
162
203
|
};
|
|
163
204
|
|
|
164
205
|
export type FileRef = {
|
|
206
|
+
/**
|
|
207
|
+
* Resource identity. Semantics depend on `kind` (when present):
|
|
208
|
+
* - `skill` / `agent`: shared resource id (sessionKey-meaningful).
|
|
209
|
+
* - `user`: informational only — codeapi derives sessionKey from
|
|
210
|
+
* the auth-context user. Do not rely on it for routing.
|
|
211
|
+
*/
|
|
165
212
|
id: string;
|
|
166
213
|
name: string;
|
|
167
214
|
path?: string;
|
|
168
|
-
/** Session ID this file belongs to (for multi-session file tracking) */
|
|
169
|
-
session_id?: string;
|
|
170
215
|
/**
|
|
171
|
-
*
|
|
172
|
-
*
|
|
173
|
-
* `_injected_files` when a subsequent execute references a mix of
|
|
174
|
-
* files uploaded under different entities.
|
|
216
|
+
* Storage session this file lives in. See `CodeEnvFile.storage_session_id`
|
|
217
|
+
* for the full motivation.
|
|
175
218
|
*/
|
|
176
|
-
|
|
219
|
+
storage_session_id?: string;
|
|
220
|
+
/** Resource kind — see `CodeEnvFile.kind`. */
|
|
221
|
+
kind?: CodeEnvKind;
|
|
222
|
+
/** Resource version — see `CodeEnvFile.version`. Only meaningful when
|
|
223
|
+
* `kind === 'skill'`. */
|
|
224
|
+
version?: number;
|
|
177
225
|
/**
|
|
178
226
|
* `true` when the codeapi sandbox echoed this entry as an unchanged
|
|
179
227
|
* passthrough of an input the caller already owns (skill files,
|
|
@@ -188,6 +236,11 @@ export type FileRef = {
|
|
|
188
236
|
export type FileRefs = FileRef[];
|
|
189
237
|
|
|
190
238
|
export type ExecuteResult = {
|
|
239
|
+
/**
|
|
240
|
+
* Execution session id — the (transient) sandbox run that produced
|
|
241
|
+
* this output. Distinct from per-file `storage_session_id` on the
|
|
242
|
+
* files array.
|
|
243
|
+
*/
|
|
191
244
|
session_id: string;
|
|
192
245
|
stdout: string;
|
|
193
246
|
stderr: string;
|
|
@@ -254,6 +307,7 @@ export type ToolCallRequest = {
|
|
|
254
307
|
turn?: number;
|
|
255
308
|
/** Code execution session context for session continuity in event-driven mode */
|
|
256
309
|
codeSessionContext?: {
|
|
310
|
+
/** Execution session — see `CodeSessionContext.session_id`. */
|
|
257
311
|
session_id: string;
|
|
258
312
|
files?: CodeEnvFile[];
|
|
259
313
|
};
|
|
@@ -775,6 +829,7 @@ export type PTCToolResult = {
|
|
|
775
829
|
*/
|
|
776
830
|
export type ProgrammaticExecutionResponse = {
|
|
777
831
|
status: 'tool_call_required' | 'completed' | 'error' | unknown;
|
|
832
|
+
/** Execution session — see `CodeSessionContext.session_id`. */
|
|
778
833
|
session_id?: string;
|
|
779
834
|
|
|
780
835
|
/** Present when status='tool_call_required' */
|
|
@@ -794,6 +849,7 @@ export type ProgrammaticExecutionResponse = {
|
|
|
794
849
|
* Artifact returned by the PTC tool
|
|
795
850
|
*/
|
|
796
851
|
export type ProgrammaticExecutionArtifact = {
|
|
852
|
+
/** Execution session — see `CodeSessionContext.session_id`. */
|
|
797
853
|
session_id?: string;
|
|
798
854
|
files?: FileRefs;
|
|
799
855
|
};
|
|
@@ -827,7 +883,12 @@ export type ProgrammaticToolCallingParams = {
|
|
|
827
883
|
* Stored in Graph.sessions and injected into subsequent tool invocations.
|
|
828
884
|
*/
|
|
829
885
|
export type CodeSessionContext = {
|
|
830
|
-
/**
|
|
886
|
+
/**
|
|
887
|
+
* Execution session id — the (transient) sandbox run id. Used by
|
|
888
|
+
* ToolNode to thread session continuity into the next code-execution
|
|
889
|
+
* tool call. Distinct from per-file `storage_session_id` carried on
|
|
890
|
+
* `files`.
|
|
891
|
+
*/
|
|
831
892
|
session_id: string;
|
|
832
893
|
/** Files generated in this session (for context/tracking) */
|
|
833
894
|
files?: FileRefs;
|
|
@@ -840,6 +901,7 @@ export type CodeSessionContext = {
|
|
|
840
901
|
* Used to extract session context after tool completion.
|
|
841
902
|
*/
|
|
842
903
|
export type CodeExecutionArtifact = {
|
|
904
|
+
/** Execution session — see `CodeSessionContext.session_id`. */
|
|
843
905
|
session_id?: string;
|
|
844
906
|
files?: FileRefs;
|
|
845
907
|
};
|