prompts.js 1.2 KB

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