/*--------------------------------------------------------------------------------------------- * 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 * * 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.SDK; /// /// 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. /// public 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"); console.log("Done!");