LibreChat/packages/data-provider/src/agentToolOptions.ts
lia-by-librechat[bot] 385c6f8a1a
Some checks are pending
Backend Unit Tests / Build packages (push) Waiting to run
Backend Unit Tests / Codegraph select (push) Waiting to run
Backend Unit Tests / TypeScript type checks (push) Blocked by required conditions
Backend Unit Tests / Circular dependency checks (push) Waiting to run
Backend Unit Tests / Tests: api (shard 1/3) (push) Blocked by required conditions
Backend Unit Tests / Tests: api (shard 2/3) (push) Blocked by required conditions
Backend Unit Tests / Tests: api (shard 3/3) (push) Blocked by required conditions
Backend Unit Tests / Tests: data-provider (push) Blocked by required conditions
Backend Unit Tests / Tests: data-schemas (push) Blocked by required conditions
Backend Unit Tests / Tests: @librechat/api (shard 1/4) (push) Blocked by required conditions
Backend Unit Tests / Tests: @librechat/api (shard 2/4) (push) Blocked by required conditions
Backend Unit Tests / Tests: @librechat/api (shard 3/4) (push) Blocked by required conditions
Backend Unit Tests / Tests: @librechat/api (shard 4/4) (push) Blocked by required conditions
Codegraph E2E Votes / vote (full suite) (push) Waiting to run
Docker Dev Branch Images Build / publish (push) Waiting to run
Frontend Unit Tests / Client build recovery regression (push) Waiting to run
Frontend Unit Tests / Codegraph select (push) Waiting to run
Frontend Unit Tests / Build packages (push) Waiting to run
Frontend Unit Tests / TypeScript type checks (client) (push) Blocked by required conditions
Frontend Unit Tests / Tests: @librechat/client (push) Blocked by required conditions
Frontend Unit Tests / Tests: Ubuntu (shard 1/2) (push) Blocked by required conditions
Frontend Unit Tests / Tests: Ubuntu (shard 2/2) (push) Blocked by required conditions
Frontend Unit Tests / Vite build verification (push) Blocked by required conditions
Docker Dev Images Build / publish (push) Waiting to run
Sync Helm Chart Tags / Ignore non-main push (push) Waiting to run
Sync Helm Chart Tags / Sync chart tags (push) Waiting to run
⚗️ refactor: Separate Content, Tool, and Agent Types From the Assistants Module (#15910)
types/assistants.ts held ~60 exports of which only ~11 were Assistants
API types. The rest were core message-content types and the Agent entity
types, so schemas.ts and agents.ts both imported foundational types from
a file named after the Assistants API.

Split into types/tools.ts (tool primitives, action naming) and
types/content.ts (message content parts, annotations, tool calls), moved
the Agent entity types into the existing types/agents.ts, and left a slim
Assistants-only types/assistants.ts.

No behavior change: every symbol keeps its public export from the package
barrel, so no consumer outside data-provider changes.

Co-authored-by: Lia <lia@librechat.ai>
2026-09-15 14:15:24 -04:00

58 lines
1.8 KiB
TypeScript

import {
actionDelimiter,
actionDomainSeparator,
isActionTool,
type AgentToolOptions,
type AllowedCaller,
} from './types/tools';
const actionDomainSeparatorRegex = new RegExp(actionDomainSeparator, 'g');
/**
* Collapses the encoded-domain suffix of an action tool name to the shape used
* by runtime tool definitions. The operation id is deliberately preserved.
*/
export function normalizeActionToolName(toolName: string): string {
if (!isActionTool(toolName)) {
return toolName;
}
const delimiterIndex = toolName.lastIndexOf(actionDelimiter);
const prefixEnd = delimiterIndex + actionDelimiter.length;
const encodedDomain = toolName.slice(prefixEnd);
return toolName.slice(0, prefixEnd) + encodedDomain.replace(actionDomainSeparatorRegex, '_');
}
/**
* Removes Code Interpreter as an allowed caller without mutating the input.
* Tool entries and unrelated options are preserved; an empty entry is removed.
*/
export function removeCodeExecutionCaller(
toolOptions: AgentToolOptions | undefined,
): AgentToolOptions | undefined {
if (toolOptions == null) {
return toolOptions;
}
const normalized: AgentToolOptions = {};
for (const [toolName, options] of Object.entries(toolOptions)) {
const callers = options.allowed_callers;
if (callers?.includes('code_execution') !== true) {
normalized[toolName] = options;
continue;
}
const allowedCallers = callers.filter(
(caller): caller is AllowedCaller => caller !== 'code_execution',
);
const { allowed_callers: _removed, ...remainingOptions } = options;
const nextOptions =
allowedCallers.length > 0
? { ...remainingOptions, allowed_callers: allowedCallers }
: remainingOptions;
if (Object.keys(nextOptions).length > 0) {
normalized[toolName] = nextOptions;
}
}
return normalized;
}