UNPKG

@openai/agents-core

Version:

The OpenAI Agents SDK is a lightweight yet powerful framework for building multi-agent workflows.

110 lines • 4.17 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.toolQualifiedName = toolQualifiedName; exports.toolDisplayName = toolDisplayName; exports.getToolCallDisplayName = getToolCallDisplayName; exports.getToolSearchProviderCallId = getToolSearchProviderCallId; exports.getToolSearchMatchKey = getToolSearchMatchKey; exports.getToolSearchOutputReplacementKey = getToolSearchOutputReplacementKey; exports.getToolSearchExecution = getToolSearchExecution; exports.isClientToolSearchCall = isClientToolSearchCall; exports.shouldQueuePendingToolSearchCall = shouldQueuePendingToolSearchCall; exports.resolveToolSearchCallId = resolveToolSearchCallId; exports.takePendingToolSearchCallId = takePendingToolSearchCallId; function isNonEmptyString(value) { return typeof value === 'string' && value.length > 0; } function getToolSearchProviderData(value) { return typeof value.providerData === 'object' && value.providerData ? value.providerData : undefined; } function toolQualifiedName(name, namespace) { if (!isNonEmptyString(name)) { return undefined; } if (isNonEmptyString(namespace)) { return `${namespace}.${name}`; } return name; } function toolDisplayName(name, namespace) { if (!isNonEmptyString(name)) { return undefined; } if (!isNonEmptyString(namespace) || namespace === name) { return name; } return `${namespace}.${name}`; } function getToolCallDisplayName(toolCall) { return toolDisplayName(isNonEmptyString(toolCall.name) ? toolCall.name : undefined, isNonEmptyString(toolCall.namespace) ? toolCall.namespace : undefined); } function getToolSearchProviderCallId(value) { const providerData = getToolSearchProviderData(value); const providerCallId = providerData?.call_id ?? providerData?.callId; if (isNonEmptyString(providerCallId)) { return providerCallId; } if (isNonEmptyString(value.call_id)) { return value.call_id; } if (isNonEmptyString(value.callId)) { return value.callId; } return undefined; } function getToolSearchMatchKey(value) { if (isNonEmptyString(value.id)) { return getToolSearchProviderCallId(value) ?? value.id; } return getToolSearchProviderCallId(value); } function getToolSearchOutputReplacementKey(value) { const providerCallId = getToolSearchProviderCallId(value); if (providerCallId) { return `call:${providerCallId}`; } return isNonEmptyString(value.id) ? `item:${value.id}` : undefined; } function getToolSearchExecution(value) { if (value.execution === 'client' || value.execution === 'server') { return value.execution; } const providerData = getToolSearchProviderData(value); const execution = providerData?.execution; return execution === 'client' || execution === 'server' ? execution : undefined; } function isClientToolSearchCall(value) { return getToolSearchExecution(value) === 'client'; } function shouldQueuePendingToolSearchCall(value) { return getToolSearchExecution(value) !== 'server'; } function resolveToolSearchCallId(value, generateFallbackId) { const explicitMatchKey = getToolSearchMatchKey(value); if (explicitMatchKey) { return explicitMatchKey; } if (generateFallbackId) { return generateFallbackId(); } throw new Error('Tool search item is missing both call_id and id. Provide a fallback generator when resolving client-side tool_search history.'); } function takePendingToolSearchCallId(value, pendingCallIds, generateFallbackId) { const explicitCallId = getToolSearchProviderCallId(value); if (explicitCallId) { const pendingIndex = pendingCallIds.indexOf(explicitCallId); if (pendingIndex >= 0) { pendingCallIds.splice(pendingIndex, 1); } return explicitCallId; } if (getToolSearchExecution(value) === 'server') { return resolveToolSearchCallId(value, generateFallbackId); } return (pendingCallIds.shift() ?? resolveToolSearchCallId(value, generateFallbackId)); } //# sourceMappingURL=tooling.js.map