@luxorai/sandbox
Version:
TypeScript SDK for Luxor Sandbox: cloud sandboxes (microVMs) for AI agents on Luxor Agent Cloud
46 lines • 2.08 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.egressPolicySpecToProto = egressPolicySpecToProto;
exports.egressPolicyFromMessage = egressPolicyFromMessage;
exports.workspaceScope = workspaceScope;
exports.publicEgressAcknowledged = publicEgressAcknowledged;
const protobuf_1 = require("@bufbuild/protobuf");
const wkt_1 = require("@bufbuild/protobuf/wkt");
const sandbox_pb_js_1 = require("./internal/proto/tenki/sandbox/v1/sandbox_pb.js");
const session_js_1 = require("./session.js");
function egressPolicySpecToProto(spec) {
return (0, protobuf_1.create)(sandbox_pb_js_1.SessionEgressPolicySchema, {
allowDomains: [...(spec.allowDomains ?? [])],
allowCidrs: [...(spec.allowCidrs ?? [])],
interceptHttps: spec.interceptHttps ?? false,
allowedPorts: [...(spec.allowedPorts ?? [])],
publicEgress: spec.publicEgress,
httpRules: (spec.httpRules ?? []).map(session_js_1.egressHttpRuleToProto),
});
}
function egressPolicyFromMessage(policy) {
if (!policy)
throw new Error("Missing egress policy");
return {
id: policy.id,
workspaceId: policy.workspaceId,
name: policy.name,
revision: policy.revision,
egress: (0, session_js_1.egressPolicyFromProto)(policy.egress),
activeSessionCount: policy.activeSessionCount,
createdAt: policy.createdAt && (0, wkt_1.timestampDate)(policy.createdAt),
updatedAt: policy.updatedAt && (0, wkt_1.timestampDate)(policy.updatedAt),
deletedAt: policy.deletedAt && (0, wkt_1.timestampDate)(policy.deletedAt),
};
}
function workspaceScope(options) {
return options?.workspaceId?.trim() || undefined;
}
function publicEgressAcknowledged(requested, actual) {
if (requested === undefined)
return true;
return (actual !== undefined &&
actual.tcpPorts.every((port) => (requested.tcpPorts ?? []).includes(port)) &&
actual.udpPorts.every((port) => (requested.udpPorts ?? []).includes(port)));
}
//# sourceMappingURL=egress-policies.js.map