Skip to content

Commit 3dc2893

Browse files
Copilotfriggeri
andcommitted
Fix module import error by generating sdkProtocolVersion.ts from JSON
Co-authored-by: friggeri <106686+friggeri@users.noreply.github.com>
1 parent a68d1e7 commit 3dc2893

File tree

3 files changed

+34
-3
lines changed

3 files changed

+34
-3
lines changed

nodejs/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"lint:fix": "eslint --fix \"src/**/*.ts\" \"test/**/*.ts\"",
2727
"typecheck": "tsc --noEmit",
2828
"generate:session-types": "tsx scripts/generate-session-types.ts",
29-
"update:protocol-version": "tsx scripts/generate-protocol-version.ts",
29+
"update:protocol-version": "tsx scripts/update-protocol-version.ts",
3030
"prepublishOnly": "npm run build",
3131
"package": "npm run clean && npm run build && node scripts/set-version.js && npm pack && npm version 0.1.0 --no-git-tag-version --allow-same-version"
3232
},

nodejs/scripts/update-protocol-version.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* Generates SDK protocol version constants for all SDK languages.
77
*
88
* Reads from sdk-protocol-version.json and generates:
9+
* - nodejs/src/sdkProtocolVersion.ts
910
* - go/sdk_protocol_version.go
1011
* - python/copilot/sdk_protocol_version.py
1112
* - dotnet/src/SdkProtocolVersion.cs
@@ -26,6 +27,30 @@ const version = versionFile.version;
2627

2728
console.log(`Generating SDK protocol version constants for version ${version}...`);
2829

30+
// Generate TypeScript
31+
const tsCode = `/*---------------------------------------------------------------------------------------------
32+
* Copyright (c) Microsoft Corporation. All rights reserved.
33+
*--------------------------------------------------------------------------------------------*/
34+
35+
// Code generated by update-protocol-version.ts. DO NOT EDIT.
36+
37+
/**
38+
* The SDK protocol version.
39+
* This must match the version expected by the copilot-agent-runtime server.
40+
*/
41+
export const SDK_PROTOCOL_VERSION = ${version};
42+
43+
/**
44+
* Gets the SDK protocol version from sdk-protocol-version.json.
45+
* @returns The protocol version number
46+
*/
47+
export function getSdkProtocolVersion(): number {
48+
return SDK_PROTOCOL_VERSION;
49+
}
50+
`;
51+
fs.writeFileSync(path.join(rootDir, "nodejs", "src", "sdkProtocolVersion.ts"), tsCode);
52+
console.log(" ✓ nodejs/src/sdkProtocolVersion.ts");
53+
2954
// Generate Go
3055
const goCode = `// Code generated by generate-protocol-version.ts. DO NOT EDIT.
3156

nodejs/src/sdkProtocolVersion.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,18 @@
22
* Copyright (c) Microsoft Corporation. All rights reserved.
33
*--------------------------------------------------------------------------------------------*/
44

5-
import sdkProtocolVersion from "../../sdk-protocol-version.json";
5+
// Code generated by update-protocol-version.ts. DO NOT EDIT.
6+
7+
/**
8+
* The SDK protocol version.
9+
* This must match the version expected by the copilot-agent-runtime server.
10+
*/
11+
export const SDK_PROTOCOL_VERSION = 1;
612

713
/**
814
* Gets the SDK protocol version from sdk-protocol-version.json.
915
* @returns The protocol version number
1016
*/
1117
export function getSdkProtocolVersion(): number {
12-
return sdkProtocolVersion.version;
18+
return SDK_PROTOCOL_VERSION;
1319
}

0 commit comments

Comments
 (0)