Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@librechat/agents",
"version": "3.1.79",
"version": "3.1.80-dev.0",
"main": "./dist/cjs/main.cjs",
"module": "./dist/esm/main.mjs",
"types": "./dist/types/index.d.ts",
Expand Down
8 changes: 4 additions & 4 deletions src/scripts/code_exec_multi_session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function printSessionContext(run: Run<t.IState>, label: string): void {
console.log(` Latest session_id: ${session.session_id}`);
console.log(` Files tracked: ${session.files?.length ?? 0}`);
for (const file of session.files ?? []) {
console.log(` - ${file.name} (session: ${file.session_id})`);
console.log(` - ${file.name} (storage: ${file.storage_session_id})`);
}
}

Expand Down Expand Up @@ -200,13 +200,13 @@ Tell me what version it shows.

if (finalSession) {
const files = finalSession.files ?? [];
const uniqueSessionIds = new Set(files.map((f) => f.session_id));
const uniqueSessionIds = new Set(files.map((f) => f.storage_session_id));
console.log(`\nTotal files tracked: ${files.length}`);
console.log(`Unique session_ids: ${uniqueSessionIds.size}`);
console.log(`Unique storage_session_ids: ${uniqueSessionIds.size}`);
console.log('\nFiles:');
for (const file of files) {
console.log(
` - ${file.name} (session: ${file.session_id?.slice(0, 20)}...)`
` - ${file.name} (storage: ${file.storage_session_id?.slice(0, 20)}...)`
);
}

Expand Down
14 changes: 11 additions & 3 deletions src/tools/BashExecutor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,10 @@ function createBashExecutionTool(
const id = nameParts.length > 1 ? nameParts[1].split('.')[0] : '';

return {
session_id,
storage_session_id: session_id,
/* `/files` fallback returns code-output files belonging
* to the user; tag them user-private. */
kind: 'user' as const,
id,
name: file.metadata['original-filename'],
};
Expand Down Expand Up @@ -241,11 +244,16 @@ function createBashExecutionTool(
{
session_id: result.session_id,
files: result.files,
},
} satisfies t.CodeExecutionArtifact,
];
}

return [formattedOutput.trim(), { session_id: result.session_id }];
return [
formattedOutput.trim(),
{
session_id: result.session_id,
} satisfies t.CodeExecutionArtifact,
];
} catch (error) {
throw new Error(
`Execution error:\n\n${(error as Error | undefined)?.message}`
Expand Down
12 changes: 6 additions & 6 deletions src/tools/BashProgrammaticToolCalling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,12 +252,12 @@ export function createBashProgrammaticToolCallingTool(
const params = rawParams as { code: string; timeout?: number };
const { code, timeout = DEFAULT_TIMEOUT } = params;

const { toolMap, toolDefs, session_id, _injected_files } =
(config.toolCall ?? {}) as ToolCall &
Partial<t.ProgrammaticCache> & {
session_id?: string;
_injected_files?: t.CodeEnvFile[];
};
const toolCall = (config.toolCall ?? {}) as ToolCall &
Partial<t.ProgrammaticCache> & {
session_id?: string;
_injected_files?: t.CodeEnvFile[];
};
const { toolMap, toolDefs, session_id, _injected_files } = toolCall;

if (toolMap == null || toolMap.size === 0) {
throw new Error(
Expand Down
23 changes: 17 additions & 6 deletions src/tools/CodeExecutor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ function createCodeExecutionTool(
};
/**
* Extract session context from config.toolCall (injected by ToolNode).
* - session_id: For API to associate with previous session
* - _injected_files: File refs to pass directly (avoids /files endpoint race condition)
* - session_id: associates with the previous run.
* - _injected_files: File refs to pass directly (avoids /files endpoint race condition).
*/
const { session_id, _injected_files } = (config.toolCall ?? {}) as {
session_id?: string;
Expand All @@ -153,7 +153,10 @@ function createCodeExecutionTool(
/**
* File injection priority:
* 1. Use _injected_files from ToolNode (avoids /files endpoint race condition)
* 2. Fall back to fetching from /files endpoint if session_id provided but no injected files
* 2. Fall back to fetching from /files endpoint if session_id
* provided but no injected files. The /files lookup still uses the
* same id value β€” codeapi stores output files under the exec id as
* their storage prefix, so the two values coincide here.
*/
if (_injected_files && _injected_files.length > 0) {
postData.files = _injected_files;
Expand Down Expand Up @@ -186,7 +189,10 @@ function createCodeExecutionTool(
const id = nameParts.length > 1 ? nameParts[1].split('.')[0] : '';

return {
session_id,
storage_session_id: session_id,
/* `/files` fallback returns code-output files belonging
* to the user; tag them user-private. */
kind: 'user' as const,
id,
name: file.metadata['original-filename'],
};
Expand Down Expand Up @@ -259,11 +265,16 @@ function createCodeExecutionTool(
{
session_id: result.session_id,
files: result.files,
},
} satisfies t.CodeExecutionArtifact,
];
}

return [formattedOutput.trim(), { session_id: result.session_id }];
return [
formattedOutput.trim(),
{
session_id: result.session_id,
} satisfies t.CodeExecutionArtifact,
];
} catch (error) {
throw new Error(
`Execution error:\n\n${(error as Error | undefined)?.message}`
Expand Down
24 changes: 14 additions & 10 deletions src/tools/ProgrammaticToolCalling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,10 @@ export async function fetchSessionFiles(
const id = nameParts.length > 1 ? nameParts[1].split('.')[0] : '';

return {
session_id: sessionId,
storage_session_id: sessionId,
/* `/files` fallback returns code-output files belonging to
* the user; tag them user-private. */
kind: 'user' as const,
id,
name: (file.metadata as Record<string, unknown>)[
'original-filename'
Expand Down Expand Up @@ -588,7 +591,7 @@ export function formatCompletedResponse(
{
session_id: response.session_id,
files: response.files,
},
} satisfies t.ProgrammaticExecutionArtifact,
];
}

Expand Down Expand Up @@ -629,13 +632,13 @@ export function createProgrammaticToolCallingTool(
const params = rawParams as { code: string; timeout?: number };
const { code, timeout = DEFAULT_TIMEOUT } = params;

// Extra params injected by ToolNode (follows web_search pattern)
const { toolMap, toolDefs, session_id, _injected_files } =
(config.toolCall ?? {}) as ToolCall &
Partial<t.ProgrammaticCache> & {
session_id?: string;
_injected_files?: t.CodeEnvFile[];
};
// Extra params injected by ToolNode (follows web_search pattern).
const toolCall = (config.toolCall ?? {}) as ToolCall &
Partial<t.ProgrammaticCache> & {
session_id?: string;
_injected_files?: t.CodeEnvFile[];
};
const { toolMap, toolDefs, session_id, _injected_files } = toolCall;

if (toolMap == null || toolMap.size === 0) {
throw new Error(
Expand Down Expand Up @@ -671,7 +674,8 @@ export function createProgrammaticToolCallingTool(
/**
* File injection priority:
* 1. Use _injected_files from ToolNode (avoids /files endpoint race condition)
* 2. Fall back to fetching from /files endpoint if session_id provided but no injected files
* 2. Fall back to fetching from /files endpoint if session_id
* provided but no injected files.
*/
let files: t.CodeEnvFile[] | undefined;
if (_injected_files && _injected_files.length > 0) {
Expand Down
Loading
Loading