-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathupdate-protocol-version.ts
More file actions
138 lines (109 loc) · 4.21 KB
/
update-protocol-version.ts
File metadata and controls
138 lines (109 loc) · 4.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/*---------------------------------------------------------------------------------------------
* 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;
/// <summary>
/// Provides the SDK protocol version.
/// This must match the version expected by the copilot-agent-runtime server.
/// </summary>
internal static class SdkProtocolVersion
{
/// <summary>
/// The SDK protocol version.
/// </summary>
private const int Version = ${version};
/// <summary>
/// Gets the SDK protocol version.
/// </summary>
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");
console.log("Done!");