mirror of
https://github.com/stablyai/orca.git
synced 2026-11-16 02:47:34 +00:00
* feat(native-chat): run GitHub Copilot in Chat over its ACP server Copilot chats launch `copilot --acp` with Copilot's own sign-in (or gh's), so enterprise hosts and managed policy carry over. A Copilot dialect turns its tool results into plain output and exit codes, and withholds the commands that would switch Copilot to approving everything behind the chat's permission mode. The CLI version reader now accepts a version that ends a sentence, as Copilot prints it. Co-authored-by: Morten Trydal <trydis@hotmail.com> * fix(native-chat): show Auto when a session lists no models instead of hiding the model pill * fix(native-chat): don't name Copilot chats with a Copilot run that stays in its history --------- Co-authored-by: Morten Trydal <trydis@hotmail.com>
116 lines
3.3 KiB
TypeScript
116 lines
3.3 KiB
TypeScript
type ParsedVersion = {
|
|
core: [number, number, number]
|
|
prerelease: string[]
|
|
}
|
|
|
|
function parseVersion(value: string): ParsedVersion | null {
|
|
const normalized = value.trim().replace(/^v/i, '')
|
|
const match = normalized.match(
|
|
/^(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z-.]+))?(?:\+([0-9A-Za-z-.]+))?$/
|
|
)
|
|
if (!match) {
|
|
return null
|
|
}
|
|
|
|
return {
|
|
core: [Number(match[1]), Number(match[2]), Number(match[3])],
|
|
prerelease: match[4]?.split('.') ?? []
|
|
}
|
|
}
|
|
|
|
export function isValidAppVersion(value: string): boolean {
|
|
return parseVersion(value) !== null
|
|
}
|
|
|
|
/** Extracts the first valid semver (with prerelease/build) from CLI `--version` output. */
|
|
export function parseCliVersion(output: string | null | undefined): string | null {
|
|
// A sentence may end on the version ("GitHub Copilot CLI 1.0.109."); a fourth part may not.
|
|
const version = output?.match(
|
|
/(?<![\w.-])v?(\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?)(?![\w+-]|\.\w)/
|
|
)?.[1]
|
|
return version && isValidAppVersion(version) ? version : null
|
|
}
|
|
|
|
export function isPrereleaseAppVersion(value: string): boolean {
|
|
const parsed = parseVersion(value)
|
|
return parsed !== null && parsed.prerelease.length > 0
|
|
}
|
|
|
|
export function isPerfPrereleaseAppVersion(value: string): boolean {
|
|
const parsed = parseVersion(value)
|
|
return parsed?.prerelease.some((identifier) => identifier.toLowerCase() === 'perf') ?? false
|
|
}
|
|
|
|
function compareIdentifiers(left: string, right: string): number {
|
|
const leftNumeric = /^\d+$/.test(left)
|
|
const rightNumeric = /^\d+$/.test(right)
|
|
|
|
if (leftNumeric && rightNumeric) {
|
|
return Number(left) - Number(right)
|
|
}
|
|
if (leftNumeric) {
|
|
return -1
|
|
}
|
|
if (rightNumeric) {
|
|
return 1
|
|
}
|
|
return left.localeCompare(right, 'en')
|
|
}
|
|
|
|
/** Returns negative if left < right, 0 if equal, positive if left > right. */
|
|
export function compareAppVersions(left: string, right: string): number {
|
|
const leftVersion = parseVersion(left)
|
|
const rightVersion = parseVersion(right)
|
|
if (!leftVersion || !rightVersion) {
|
|
return 0
|
|
}
|
|
|
|
for (let index = 0; index < leftVersion.core.length; index += 1) {
|
|
const leftPart = leftVersion.core[index]
|
|
const rightPart = rightVersion.core[index]
|
|
if (leftPart !== rightPart) {
|
|
return leftPart - rightPart
|
|
}
|
|
}
|
|
|
|
const leftPrerelease = leftVersion.prerelease
|
|
const rightPrerelease = rightVersion.prerelease
|
|
if (leftPrerelease.length === 0 && rightPrerelease.length === 0) {
|
|
return 0
|
|
}
|
|
if (leftPrerelease.length === 0) {
|
|
return 1
|
|
}
|
|
if (rightPrerelease.length === 0) {
|
|
return -1
|
|
}
|
|
|
|
for (let index = 0; index < Math.max(leftPrerelease.length, rightPrerelease.length); index += 1) {
|
|
const leftPart = leftPrerelease[index]
|
|
const rightPart = rightPrerelease[index]
|
|
if (leftPart === undefined) {
|
|
return -1
|
|
}
|
|
if (rightPart === undefined) {
|
|
return 1
|
|
}
|
|
|
|
const comparison = compareIdentifiers(leftPart, rightPart)
|
|
if (comparison !== 0) {
|
|
return comparison
|
|
}
|
|
}
|
|
|
|
return 0
|
|
}
|
|
|
|
/** True when `current` is at or past `target`. Unparseable or absent versions never qualify. */
|
|
export function hasReachedAppVersion(current: string, target: string | null): boolean {
|
|
return (
|
|
target !== null &&
|
|
isValidAppVersion(current) &&
|
|
isValidAppVersion(target) &&
|
|
compareAppVersions(current, target) >= 0
|
|
)
|
|
}
|