godot-daedalus_backend 1.0.2 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -40,7 +40,7 @@ npm install godot-daedalus_backend
40
40
  After installing the package, start it through the published bin command:
41
41
 
42
42
  ```powershell
43
- $env:PORT = "8080"
43
+ $env:PORT = "38180"
44
44
  godot-daedalus-backend
45
45
  ```
46
46
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "godot-daedalus_backend",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "TypeScript backend for the Godot Daedalus editor assistant plugin.",
5
5
  "main": "./src/main.ts",
6
6
  "bin": {
package/src/main.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { createServer } from "./server/websocket-server.js";
2
2
  import { McpHost } from "./mcp/mcp-host.js";
3
3
 
4
- const DEFAULT_PORT: number = 8080;
4
+ const DEFAULT_PORT: number = 38180;
5
5
  const portText: string = process.env.PORT ?? String(DEFAULT_PORT);
6
6
  const port: number = Number.parseInt(portText, 10);
7
7
 
@@ -1,6 +1,6 @@
1
1
  import WebSocket from "ws";
2
2
 
3
- const url: string = process.env.WS_URL ?? "ws://localhost:8080";
3
+ const url: string = process.env.WS_URL ?? "ws://localhost:38180";
4
4
  const socket: WebSocket = new WebSocket(url);
5
5
 
6
6
  socket.on("open", (): void => {
@@ -0,0 +1,64 @@
1
+ import { readFileSync } from "node:fs";
2
+ import { dirname, resolve } from "node:path";
3
+ import { fileURLToPath } from "node:url";
4
+
5
+ const BACKEND_HEALTH_NAME: string = "godot-daedalus-backend";
6
+ const PACKAGE_ROOT: string = resolve(dirname(fileURLToPath(import.meta.url)), "../..");
7
+ const PACKAGE_JSON_PATH: string = resolve(PACKAGE_ROOT, "package.json");
8
+
9
+ type PackageManifest = {
10
+ name?: unknown;
11
+ version?: unknown;
12
+ };
13
+
14
+ export type BackendHealthResult = {
15
+ name: string;
16
+ version: string;
17
+ pid: number;
18
+ mode: "development" | "runtime";
19
+ };
20
+
21
+ let cachedPackageVersion: string | null = null;
22
+
23
+ export function getBackendPackageVersion(): string {
24
+ if (cachedPackageVersion !== null) {
25
+ return cachedPackageVersion;
26
+ }
27
+
28
+ const envVersion: string | undefined = process.env.npm_package_version;
29
+ if (envVersion !== undefined && envVersion.trim() !== "") {
30
+ cachedPackageVersion = envVersion.trim();
31
+ return cachedPackageVersion;
32
+ }
33
+
34
+ try {
35
+ const manifestText: string = readFileSync(PACKAGE_JSON_PATH, "utf8");
36
+ const manifest: PackageManifest = JSON.parse(manifestText) as PackageManifest;
37
+ if (typeof manifest.version === "string" && manifest.version.trim() !== "") {
38
+ cachedPackageVersion = manifest.version.trim();
39
+ return cachedPackageVersion;
40
+ }
41
+ } catch {
42
+ // health 不能因为版本元数据不可读而阻断 WebSocket 启动。
43
+ }
44
+
45
+ cachedPackageVersion = "0.0.0";
46
+ return cachedPackageVersion;
47
+ }
48
+
49
+ export function getBackendRuntimeMode(): "development" | "runtime" {
50
+ if (process.env.NODE_ENV === "development" || process.env.npm_lifecycle_event === "dev") {
51
+ return "development";
52
+ }
53
+
54
+ return "runtime";
55
+ }
56
+
57
+ export function createBackendHealthResult(): BackendHealthResult {
58
+ return {
59
+ name: BACKEND_HEALTH_NAME,
60
+ version: getBackendPackageVersion(),
61
+ pid: process.pid,
62
+ mode: getBackendRuntimeMode()
63
+ };
64
+ }
@@ -91,6 +91,7 @@ import {
91
91
  serializePendingApprovalState,
92
92
  type PendingApprovalState
93
93
  } from "../session/approval-persistence.js";
94
+ import { createBackendHealthResult } from "./backend-health.js";
94
95
 
95
96
  const tokenCounterPromise: Promise<TokenCounter> = createTokenCounter();
96
97
  let sessionCompressorPromptCache: string | undefined;
@@ -2292,12 +2293,7 @@ async function handleRequest(socket: WebSocket, request: ClientRequest, session:
2292
2293
  type: "response",
2293
2294
  id: request.id,
2294
2295
  ok: true,
2295
- result: {
2296
- name: "godot-daedalus-backend",
2297
- version: "1.0.1",
2298
- pid: process.pid,
2299
- mode: process.env.NODE_ENV === "development" || process.env.npm_lifecycle_event === "dev" ? "development" : "runtime"
2300
- }
2296
+ result: createBackendHealthResult()
2301
2297
  });
2302
2298
  break;
2303
2299