MCPcopy
hub / github.com/CodebuffAI/codebuff / determineNextVersion

Function determineNextVersion

packages/internal/src/utils/version-utils.ts:95–131  ·  view source on GitHub ↗
(params: {
  agentId: string
  publisherId: string
  providedVersion?: string
  db: CodebuffPgDatabase
})

Source from the content-addressed store, hash-verified

93 * - If version is provided, validate and use it
94 */
95export async function determineNextVersion(params: {
96 agentId: string
97 publisherId: string
98 providedVersion?: string
99 db: CodebuffPgDatabase
100}): Promise<Version> {
101 const { agentId, publisherId, providedVersion, db } = params
102
103 const latestVersion = await getLatestAgentVersion({
104 agentId,
105 publisherId,
106 db,
107 })
108
109 if (!providedVersion) {
110 return incrementPatchVersion(latestVersion)
111 }
112
113 let version: Version
114 try {
115 version = parseVersion(providedVersion)
116 } catch (error) {
117 throw new Error(
118 `Invalid version format: ${providedVersion}. Must be in semver format (e.g., 1.0.0)`,
119 )
120 }
121
122 if (!isGreater(version, latestVersion)) {
123 throw new Error(
124 `Provided version ${providedVersion} must be greater than the latest version (${stringifyVersion(
125 latestVersion,
126 )})`,
127 )
128 }
129
130 return version
131}
132
133/**
134 * Check if a specific version already exists for an agent

Callers 2

POSTFunction · 0.90

Calls 5

getLatestAgentVersionFunction · 0.85
incrementPatchVersionFunction · 0.85
isGreaterFunction · 0.85
stringifyVersionFunction · 0.85
parseVersionFunction · 0.70

Tested by

no test coverage detected