@openai/agents-core
Version:
The OpenAI Agents SDK is a lightweight yet powerful framework for building multi-agent workflows.
66 lines • 2.34 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.SUPPORTED_SANDBOX_SESSION_STATE_VERSIONS = exports.SANDBOX_SESSION_STATE_VERSION = void 0;
exports.normalizeExposedPort = normalizeExposedPort;
exports.exposedPortStateKey = exposedPortStateKey;
exports.recordExposedPortEndpoint = recordExposedPortEndpoint;
exports.getRecordedExposedPortEndpoint = getRecordedExposedPortEndpoint;
exports.urlForExposedPort = urlForExposedPort;
const errors_1 = require("../errors.js");
exports.SANDBOX_SESSION_STATE_VERSION = 6;
exports.SUPPORTED_SANDBOX_SESSION_STATE_VERSIONS = [
1,
2,
3,
4,
5,
exports.SANDBOX_SESSION_STATE_VERSION,
];
function normalizeExposedPort(port) {
if (!Number.isInteger(port) || port < 1 || port > 65_535) {
throw new errors_1.UserError('Exposed ports must be integers between 1 and 65535.');
}
return port;
}
function exposedPortStateKey(port) {
return String(normalizeExposedPort(port));
}
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;
}
function getRecordedExposedPortEndpoint(state, port) {
return state.exposedPorts?.[exposedPortStateKey(port)];
}
function urlForExposedPort(endpoint, scheme) {
if (scheme !== 'http' && scheme !== 'ws') {
throw new errors_1.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.js.map