-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Expand file tree
/
Copy pathupdate-protocol-version.ts
More file actions
184 lines (146 loc) · 5.46 KB
/
Copy pathupdate-protocol-version.ts
File metadata and controls
184 lines (146 loc) · 5.46 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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
/*---------------------------------------------------------------------------------------------
* 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;
/// <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");
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!");