prompts.cjs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.isVersionGreaterOrEqual = isVersionGreaterOrEqual;
  4. exports.parsePromptIdentifier = parsePromptIdentifier;
  5. const semver_1 = require("semver");
  6. function isVersionGreaterOrEqual(current_version, target_version) {
  7. const current = (0, semver_1.parse)(current_version);
  8. const target = (0, semver_1.parse)(target_version);
  9. if (!current || !target) {
  10. throw new Error("Invalid version format.");
  11. }
  12. return current.compare(target) >= 0;
  13. }
  14. function parsePromptIdentifier(identifier) {
  15. if (!identifier ||
  16. identifier.split("/").length > 2 ||
  17. identifier.startsWith("/") ||
  18. identifier.endsWith("/") ||
  19. identifier.split(":").length > 2) {
  20. throw new Error(`Invalid identifier format: ${identifier}`);
  21. }
  22. const [ownerNamePart, commitPart] = identifier.split(":");
  23. const commit = commitPart || "latest";
  24. if (ownerNamePart.includes("/")) {
  25. const [owner, name] = ownerNamePart.split("/", 2);
  26. if (!owner || !name) {
  27. throw new Error(`Invalid identifier format: ${identifier}`);
  28. }
  29. return [owner, name, commit];
  30. }
  31. else {
  32. if (!ownerNamePart) {
  33. throw new Error(`Invalid identifier format: ${identifier}`);
  34. }
  35. return ["-", ownerNamePart, commit];
  36. }
  37. }