UNPKG

@openai/agents-core

Version:

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

58 lines • 1.9 kB
import { UserError } from "../errors.mjs"; export const SANDBOX_SESSION_STATE_VERSION = 6; export const SUPPORTED_SANDBOX_SESSION_STATE_VERSIONS = [ 1, 2, 3, 4, 5, SANDBOX_SESSION_STATE_VERSION, ]; export function normalizeExposedPort(port) { if (!Number.isInteger(port) || port < 1 || port > 65_535) { throw new UserError('Exposed ports must be integers between 1 and 65535.'); } return port; } export function exposedPortStateKey(port) { return String(normalizeExposedPort(port)); } export function recordExposedPortEndpoint(state, endpoint, keyPort = endpoint.port) { const normalizedEndpoint = { ...endpoint, port: normalizeExposedPort(endpoint.port), tls: endpoint.tls ?? false, query: endpoint.query ?? '', }; state.exposedPorts = { ...(state.exposedPorts ?? {}), [exposedPortStateKey(keyPort)]: normalizedEndpoint, }; return normalizedEndpoint; } export function getRecordedExposedPortEndpoint(state, port) { return state.exposedPorts?.[exposedPortStateKey(port)]; } export function urlForExposedPort(endpoint, scheme) { if (scheme !== 'http' && scheme !== 'ws') { throw new UserError('Exposed port URL schemes must be "http" or "ws".'); } const tls = endpoint.tls ?? false; let prefix; if (scheme === 'http') { prefix = tls ? 'https' : 'http'; } else { prefix = tls ? 'wss' : 'ws'; } const defaultPort = tls ? 443 : 80; const host = endpoint.host.includes(':') && !endpoint.host.startsWith('[') ? `[${endpoint.host}]` : endpoint.host; const base = endpoint.port === defaultPort ? `${prefix}://${host}/` : `${prefix}://${host}:${endpoint.port}/`; const query = endpoint.query ?? ''; return query ? `${base}?${query}` : base; } //# sourceMappingURL=session.mjs.map