/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
*--------------------------------------------------------------------------------------------*/
/**
* Generates SDK protocol version constants for all SDK languages.
*
* Reads from sdk-protocol-version.json and generates:
* - nodejs/src/sdkProtocolVersion.ts
* - go/sdk_protocol_version.go
* - python/copilot/_sdk_protocol_version.py
* - dotnet/src/SdkProtocolVersion.cs
* - rust/src/sdk_protocol_version.rs
* - java/sdk/src/main/java/com/github/copilot/SdkProtocolVersion.java
*
* Run this script whenever the protocol version changes.
*/
import fs from "node:fs";
import path from "node:path";
import { fileURLToPath } from "node:url";
import versionFile from "../../sdk-protocol-version.json" with { type: "json" };
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const rootDir = path.join(__dirname, "..", "..");
const version = versionFile.version;
console.log(`Generating SDK protocol version constants for version ${version}...`);
// Generate TypeScript
const tsCode = `/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
*--------------------------------------------------------------------------------------------*/
// Code generated by update-protocol-version.ts. DO NOT EDIT.
/**
* The SDK protocol version.
* This must match the version expected by the copilot-agent-runtime server.
*/
export const SDK_PROTOCOL_VERSION = ${version};
/**
* Gets the SDK protocol version.
* @returns The protocol version number
*/
export function getSdkProtocolVersion(): number {
return SDK_PROTOCOL_VERSION;
}
`;
fs.writeFileSync(path.join(rootDir, "nodejs", "src", "sdkProtocolVersion.ts"), tsCode);
console.log(" ✓ nodejs/src/sdkProtocolVersion.ts");
// Generate Go
const goCode = `// Code generated by update-protocol-version.ts. DO NOT EDIT.
package copilot
// SDKProtocolVersion is the SDK protocol version.
// This must match the version expected by the copilot-agent-runtime server.
const SDKProtocolVersion = ${version}
// GetSDKProtocolVersion returns the SDK protocol version.
func GetSDKProtocolVersion() int {
return SDKProtocolVersion
}
`;
fs.writeFileSync(path.join(rootDir, "go", "sdk_protocol_version.go"), goCode);
console.log(" ✓ go/sdk_protocol_version.go");
// Generate Python
const pythonCode = `# Code generated by update-protocol-version.ts. DO NOT EDIT.
"""
SDK Protocol Version for the Copilot SDK.
This must match the version expected by the copilot-agent-runtime server.
"""
SDK_PROTOCOL_VERSION = ${version}
def get_sdk_protocol_version() -> int:
"""
Gets the SDK protocol version.
Returns:
The protocol version number
"""
return SDK_PROTOCOL_VERSION
`;
fs.writeFileSync(path.join(rootDir, "python", "copilot", "_sdk_protocol_version.py"), pythonCode);
console.log(" ✓ python/copilot/_sdk_protocol_version.py");
// Generate C#
const csharpCode = `// Code generated by update-protocol-version.ts. DO NOT EDIT.
namespace GitHub.Copilot;
///
/// Provides the SDK protocol version.
/// This must match the version expected by the copilot-agent-runtime server.
///
internal static class SdkProtocolVersion
{
///
/// The SDK protocol version.
///
private const int Version = ${version};
///
/// Gets the SDK protocol version.
///
public static int GetVersion() => Version;
}
`;
fs.writeFileSync(path.join(rootDir, "dotnet", "src", "SdkProtocolVersion.cs"), csharpCode);
console.log(" ✓ dotnet/src/SdkProtocolVersion.cs");
// Generate Rust
const rustCode = `// Code generated by update-protocol-version.ts. DO NOT EDIT.
//! The SDK protocol version. Must match the version expected by the
//! copilot-agent-runtime server.
/// The SDK protocol version.
pub const SDK_PROTOCOL_VERSION: u32 = ${version};
/// Returns the SDK protocol version.
#[must_use]
pub const fn get_sdk_protocol_version() -> u32 {
SDK_PROTOCOL_VERSION
}
`;
fs.writeFileSync(path.join(rootDir, "rust", "src", "sdk_protocol_version.rs"), rustCode);
console.log(" ✓ rust/src/sdk_protocol_version.rs");
const javaCode = `/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
*--------------------------------------------------------------------------------------------*/
// Code generated by update-protocol-version.ts. DO NOT EDIT.
package com.github.copilot;
/**
* Provides the SDK protocol version. This must match the version expected by
* the copilot-agent-runtime server.
*
* @since 1.0.0
*/
public enum SdkProtocolVersion {
LATEST(${version});
private int versionNumber;
private SdkProtocolVersion(int versionNumber) {
this.versionNumber = versionNumber;
}
public int getVersionNumber() {
return this.versionNumber;
}
/**
* Gets the SDK protocol version.
*
* @return the protocol version
*/
public static int get() {
return LATEST.getVersionNumber();
}
}
`;
fs.writeFileSync(
path.join(rootDir, "java/sdk/src/main/java/com/github/copilot/SdkProtocolVersion.java"),
javaCode
);
console.log(" ✓ java/sdk/src/main/java/com/github/copilot/SdkProtocolVersion.java");
console.log("Done!");