@jamiexiongr/panda-hub 0.1.20 → 0.1.22

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.
@@ -8517,20 +8517,30 @@ var killByPort = async (port) => {
8517
8517
  }
8518
8518
  return pids;
8519
8519
  };
8520
+ var resolveWindowsServiceControllerName = (serviceName) => {
8521
+ const normalizedName = normalizeNullableText(serviceName);
8522
+ if (!normalizedName) {
8523
+ return null;
8524
+ }
8525
+ return `${normalizedName.replace(/[^\w]/g, "").toLowerCase()}.exe`;
8526
+ };
8520
8527
  var queryWindowsServiceStatus = (serviceName) => {
8521
8528
  const normalizedName = normalizeNullableText(serviceName);
8522
8529
  if (process.platform !== "win32" || !normalizedName) {
8523
8530
  return null;
8524
8531
  }
8532
+ const controllerName = resolveWindowsServiceControllerName(normalizedName);
8525
8533
  const escapedName = normalizedName.replace(/'/g, "''");
8534
+ const escapedControllerName = (controllerName ?? normalizedName).replace(/'/g, "''");
8526
8535
  const result = spawnSync2(
8527
8536
  "powershell.exe",
8528
8537
  [
8529
8538
  "-NoProfile",
8530
8539
  "-Command",
8531
8540
  [
8532
- `$service = Get-Service -Name '${escapedName}' -ErrorAction SilentlyContinue`,
8533
- `if ($null -eq $service) { '__MISSING__' } else { $service.Status.ToString() }`
8541
+ `$service = Get-Service -Name '${escapedControllerName}' -ErrorAction SilentlyContinue`,
8542
+ `if ($null -eq $service) { $service = Get-Service -DisplayName '${escapedName}' -ErrorAction SilentlyContinue }`,
8543
+ `if ($null -eq $service) { '__MISSING__' } else { @{ Name = $service.Name; DisplayName = $service.DisplayName; Status = $service.Status.ToString() } | ConvertTo-Json -Compress }`
8534
8544
  ].join("; ")
8535
8545
  ],
8536
8546
  {
@@ -8541,10 +8551,21 @@ var queryWindowsServiceStatus = (serviceName) => {
8541
8551
  );
8542
8552
  const rawOutput = `${result.stdout ?? ""}
8543
8553
  ${result.stderr ?? ""}`.trim();
8544
- const normalizedOutput = rawOutput.trim().toLowerCase();
8554
+ let resolvedDisplayName = normalizedName;
8555
+ let resolvedControllerName = controllerName ?? normalizedName;
8556
+ let normalizedOutput = rawOutput.trim().toLowerCase();
8557
+ try {
8558
+ const parsed = JSON.parse(rawOutput);
8559
+ resolvedDisplayName = normalizeNullableText(parsed.DisplayName) ?? resolvedDisplayName;
8560
+ resolvedControllerName = normalizeNullableText(parsed.Name) ?? resolvedControllerName;
8561
+ normalizedOutput = (normalizeNullableText(parsed.Status) ?? rawOutput).trim().toLowerCase();
8562
+ } catch {
8563
+ }
8545
8564
  const status = normalizedOutput === "__missing__" ? "missing" : normalizedOutput === "running" ? "running" : normalizedOutput === "stopped" ? "stopped" : "unknown";
8546
8565
  return {
8547
8566
  name: normalizedName,
8567
+ displayName: resolvedDisplayName,
8568
+ controllerName: resolvedControllerName,
8548
8569
  installed: status !== "missing",
8549
8570
  status,
8550
8571
  rawOutput
@@ -8902,21 +8923,41 @@ const killByPort = async (port) => {
8902
8923
  return pids
8903
8924
  }
8904
8925
 
8926
+ const resolveWindowsServiceControllerName = (serviceName) => {
8927
+ const normalizedName = String(serviceName || '').trim()
8928
+ if (!normalizedName) {
8929
+ return null
8930
+ }
8931
+ return normalizedName.replace(/[^\w]/g, '').toLowerCase() + '.exe'
8932
+ }
8933
+
8905
8934
  const queryWindowsServiceStatus = (serviceName) => {
8906
8935
  if (process.platform !== 'win32' || !serviceName) {
8907
8936
  return null
8908
8937
  }
8909
- const escapedName = String(serviceName).replace(/'/g, "''")
8938
+ const normalizedName = String(serviceName).trim()
8939
+ const controllerName = resolveWindowsServiceControllerName(normalizedName) || normalizedName
8940
+ const escapedName = normalizedName.replace(/'/g, "''")
8941
+ const escapedControllerName = controllerName.replace(/'/g, "''")
8910
8942
  const result = spawnSync('powershell.exe', ['-NoProfile', '-Command', [
8911
- "$service = Get-Service -Name '" + escapedName + "' -ErrorAction SilentlyContinue",
8912
- "if ($null -eq $service) { '__MISSING__' } else { $service.Status.ToString() }",
8943
+ "$service = Get-Service -Name '" + escapedControllerName + "' -ErrorAction SilentlyContinue",
8944
+ "if ($null -eq $service) { $service = Get-Service -DisplayName '" + escapedName + "' -ErrorAction SilentlyContinue }",
8945
+ "if ($null -eq $service) { '__MISSING__' } else { @{ Name = $service.Name; DisplayName = $service.DisplayName; Status = $service.Status.ToString() } | ConvertTo-Json -Compress }",
8913
8946
  ].join('; ')], {
8914
8947
  encoding: 'utf8',
8915
8948
  timeout: 5000,
8916
8949
  windowsHide: true,
8917
8950
  })
8918
8951
  const rawOutput = (String(result.stdout || '') + '\n' + String(result.stderr || '')).trim()
8919
- const normalizedOutput = rawOutput.trim().toLowerCase()
8952
+ let resolvedDisplayName = normalizedName
8953
+ let resolvedControllerName = controllerName
8954
+ let normalizedOutput = rawOutput.trim().toLowerCase()
8955
+ try {
8956
+ const parsed = JSON.parse(rawOutput)
8957
+ resolvedDisplayName = String(parsed.DisplayName || '').trim() || resolvedDisplayName
8958
+ resolvedControllerName = String(parsed.Name || '').trim() || resolvedControllerName
8959
+ normalizedOutput = (String(parsed.Status || '').trim() || rawOutput).trim().toLowerCase()
8960
+ } catch {}
8920
8961
  const status =
8921
8962
  normalizedOutput === '__missing__'
8922
8963
  ? 'missing'
@@ -8926,6 +8967,8 @@ const queryWindowsServiceStatus = (serviceName) => {
8926
8967
  ? 'stopped'
8927
8968
  : 'unknown'
8928
8969
  return {
8970
+ displayName: resolvedDisplayName,
8971
+ controllerName: resolvedControllerName,
8929
8972
  installed: status !== 'missing',
8930
8973
  status,
8931
8974
  rawOutput,
@@ -8947,7 +8990,7 @@ const stopWindowsService = async (serviceName) => {
8947
8990
  if (!current || !current.installed || current.status === 'stopped') {
8948
8991
  return current
8949
8992
  }
8950
- const escapedName = String(serviceName).replace(/'/g, "''")
8993
+ const escapedName = String(current.controllerName || serviceName).replace(/'/g, "''")
8951
8994
  const result = spawnSync('powershell.exe', ['-NoProfile', '-Command', "Stop-Service -Name '" + escapedName + "' -Force -ErrorAction Stop"], {
8952
8995
  encoding: 'utf8',
8953
8996
  timeout: 5000,
@@ -8969,7 +9012,7 @@ const startWindowsService = async (serviceName) => {
8969
9012
  if (current.status === 'running') {
8970
9013
  return current
8971
9014
  }
8972
- const escapedName = String(serviceName).replace(/'/g, "''")
9015
+ const escapedName = String(current.controllerName || serviceName).replace(/'/g, "''")
8973
9016
  const result = spawnSync('powershell.exe', ['-NoProfile', '-Command', "Start-Service -Name '" + escapedName + "' -ErrorAction Stop"], {
8974
9017
  encoding: 'utf8',
8975
9018
  timeout: 5000,
@@ -11521,7 +11564,7 @@ var startPandaSessionService = async ({
11521
11564
  return nextOverlayEntries;
11522
11565
  };
11523
11566
  const readTimelineFromRollout = async (sessionId) => {
11524
- const { readCodexTimeline } = await import("./src-YGFHF7S3.mjs");
11567
+ const { readCodexTimeline } = await import("./src-M7W7LPHG.mjs");
11525
11568
  return readCodexTimeline(sessionId, {
11526
11569
  codexHome,
11527
11570
  sessionFiles: discoveredSessionFiles
@@ -12989,7 +13032,7 @@ var startPandaSessionService = async ({
12989
13032
  lastSnapshotRefreshAt = Date.now();
12990
13033
  return snapshot;
12991
13034
  }
12992
- const { discoverLocalCodexData } = await import("./src-YGFHF7S3.mjs");
13035
+ const { discoverLocalCodexData } = await import("./src-M7W7LPHG.mjs");
12993
13036
  const discovery = await discoverLocalCodexData({
12994
13037
  agentId: localAgentId,
12995
13038
  agentName: localAgentName,
@@ -5,7 +5,7 @@ import {
5
5
  resolveTailscalePublicationMode,
6
6
  resolveTailscaleServePort,
7
7
  startPandaSessionService
8
- } from "./chunk-I2346PMO.mjs";
8
+ } from "./chunk-SPTBBMUL.mjs";
9
9
 
10
10
  // release/panda-hub/src/index.ts
11
11
  import fs from "fs";
@@ -15,7 +15,7 @@ import { fileURLToPath as fileURLToPath2 } from "url";
15
15
  // release/panda-hub/package.json
16
16
  var package_default = {
17
17
  name: "@jamiexiongr/panda-hub",
18
- version: "0.1.20",
18
+ version: "0.1.22",
19
19
  type: "module",
20
20
  private: false,
21
21
  description: "Panda hub runtime",
@@ -67,6 +67,15 @@ var trimToNull = (value) => {
67
67
  };
68
68
  var escapePowerShellString = (value) => value.replace(/'/g, "''");
69
69
  var quoteForSc = (value) => value.trim();
70
+ var sanitizeNodeWindowsServiceId = (value) => `${value.replace(/[^\w]/g, "").toLowerCase()}.exe`;
71
+ var resolveWindowsServiceReference = (input) => {
72
+ const displayName = typeof input === "string" ? input : input.name;
73
+ const controllerName = typeof input === "string" ? sanitizeNodeWindowsServiceId(displayName) : trimToNull(input.id) ?? sanitizeNodeWindowsServiceId(displayName);
74
+ return {
75
+ displayName,
76
+ controllerName
77
+ };
78
+ };
70
79
  var describeCommandFailure = (output, fallback) => {
71
80
  const normalized = trimToNull(output);
72
81
  return normalized ?? fallback;
@@ -96,19 +105,34 @@ var parseWindowsServiceState = (output) => {
96
105
  }
97
106
  return "unknown";
98
107
  };
99
- var queryWindowsServiceStatus = (name) => {
108
+ var queryWindowsServiceStatus = (input) => {
100
109
  ensureWindows();
110
+ const reference = resolveWindowsServiceReference(input);
101
111
  const result = runPowerShell(
102
112
  [
103
- `$service = Get-Service -Name '${escapePowerShellString(name)}' -ErrorAction SilentlyContinue`,
104
- `if ($null -eq $service) { '__MISSING__' } else { $service.Status.ToString() }`
113
+ `$service = Get-Service -Name '${escapePowerShellString(reference.controllerName)}' -ErrorAction SilentlyContinue`,
114
+ `if ($null -eq $service) { $service = Get-Service -DisplayName '${escapePowerShellString(reference.displayName)}' -ErrorAction SilentlyContinue }`,
115
+ `if ($null -eq $service) { '__MISSING__' } else { @{ Name = $service.Name; DisplayName = $service.DisplayName; Status = $service.Status.ToString() } | ConvertTo-Json -Compress }`
105
116
  ].join("; ")
106
117
  );
107
118
  const rawOutput = `${result.stdout ?? ""}
108
119
  ${result.stderr ?? ""}`.trim();
109
- const state = parseWindowsServiceState(rawOutput);
120
+ let controllerName = reference.controllerName;
121
+ let displayName = reference.displayName;
122
+ let state = parseWindowsServiceState(rawOutput);
123
+ if (state !== "missing") {
124
+ try {
125
+ const parsed = JSON.parse(rawOutput);
126
+ controllerName = trimToNull(parsed.Name) ?? controllerName;
127
+ displayName = trimToNull(parsed.DisplayName) ?? displayName;
128
+ state = parseWindowsServiceState(trimToNull(parsed.Status) ?? rawOutput);
129
+ } catch {
130
+ }
131
+ }
110
132
  return {
111
- name,
133
+ name: displayName,
134
+ displayName,
135
+ controllerName,
112
136
  exists: state !== "missing",
113
137
  state,
114
138
  rawOutput
@@ -117,51 +141,68 @@ ${result.stderr ?? ""}`.trim();
117
141
  var wait = (ms) => new Promise((resolve) => {
118
142
  setTimeout(resolve, ms);
119
143
  });
120
- var waitForWindowsServiceState = async (name, desiredState, timeoutMs = WINDOWS_SERVICE_TIMEOUT_MS) => {
144
+ var waitForWindowsServiceState = async (input, desiredState, timeoutMs = WINDOWS_SERVICE_TIMEOUT_MS) => {
121
145
  const startedAt = Date.now();
122
- let latest = queryWindowsServiceStatus(name);
146
+ let latest = queryWindowsServiceStatus(input);
123
147
  while (latest.state !== desiredState && Date.now() - startedAt < timeoutMs) {
124
148
  await wait(750);
125
- latest = queryWindowsServiceStatus(name);
149
+ latest = queryWindowsServiceStatus(input);
126
150
  }
127
151
  return latest;
128
152
  };
129
- var startWindowsService = async (name) => {
153
+ var waitForWindowsServicePresence = async (input, timeoutMs = WINDOWS_SERVICE_TIMEOUT_MS) => {
154
+ const startedAt = Date.now();
155
+ let latest = queryWindowsServiceStatus(input);
156
+ while (!latest.exists && Date.now() - startedAt < timeoutMs) {
157
+ await wait(750);
158
+ latest = queryWindowsServiceStatus(input);
159
+ }
160
+ return latest;
161
+ };
162
+ var startWindowsService = async (input) => {
130
163
  ensureWindows();
131
- const current = queryWindowsServiceStatus(name);
164
+ const current = queryWindowsServiceStatus(input);
132
165
  if (!current.exists) {
133
- throw new Error(`Windows \u670D\u52A1 ${name} \u4E0D\u5B58\u5728\u3002`);
166
+ throw new Error(`Windows \u670D\u52A1 ${current.displayName} \u4E0D\u5B58\u5728\u3002`);
134
167
  }
135
168
  if (current.state === "running") {
136
169
  return current;
137
170
  }
138
- const result = runPowerShell(`Start-Service -Name '${escapePowerShellString(name)}' -ErrorAction Stop`);
171
+ const result = runPowerShell(
172
+ `Start-Service -Name '${escapePowerShellString(current.controllerName)}' -ErrorAction Stop`
173
+ );
139
174
  const output = `${result.stdout ?? ""}
140
175
  ${result.stderr ?? ""}`.trim();
141
- const latest = await waitForWindowsServiceState(name, "running");
176
+ const latest = await waitForWindowsServiceState(input, "running");
142
177
  if (latest.state !== "running") {
143
- throw new Error(describeCommandFailure(output || latest.rawOutput, `\u542F\u52A8\u670D\u52A1 ${name} \u5931\u8D25\u3002`));
178
+ throw new Error(
179
+ describeCommandFailure(output || latest.rawOutput, `\u542F\u52A8\u670D\u52A1 ${current.displayName} \u5931\u8D25\u3002`)
180
+ );
144
181
  }
145
182
  return latest;
146
183
  };
147
- var stopWindowsService = async (name) => {
184
+ var stopWindowsService = async (input) => {
148
185
  ensureWindows();
149
- const current = queryWindowsServiceStatus(name);
186
+ const current = queryWindowsServiceStatus(input);
150
187
  if (!current.exists || current.state === "stopped") {
151
188
  return current;
152
189
  }
153
- const result = runPowerShell(`Stop-Service -Name '${escapePowerShellString(name)}' -Force -ErrorAction Stop`);
190
+ const result = runPowerShell(
191
+ `Stop-Service -Name '${escapePowerShellString(current.controllerName)}' -Force -ErrorAction Stop`
192
+ );
154
193
  const output = `${result.stdout ?? ""}
155
194
  ${result.stderr ?? ""}`.trim();
156
- const latest = await waitForWindowsServiceState(name, "stopped");
195
+ const latest = await waitForWindowsServiceState(input, "stopped");
157
196
  if (latest.state !== "stopped") {
158
- throw new Error(describeCommandFailure(output || latest.rawOutput, `\u505C\u6B62\u670D\u52A1 ${name} \u5931\u8D25\u3002`));
197
+ throw new Error(
198
+ describeCommandFailure(output || latest.rawOutput, `\u505C\u6B62\u670D\u52A1 ${current.displayName} \u5931\u8D25\u3002`)
199
+ );
159
200
  }
160
201
  return latest;
161
202
  };
162
- var restartWindowsService = async (name) => {
163
- await stopWindowsService(name);
164
- return await startWindowsService(name);
203
+ var restartWindowsService = async (input) => {
204
+ await stopWindowsService(input);
205
+ return await startWindowsService(input);
165
206
  };
166
207
  var collectServiceEnvironment = (env) => Object.entries(env ?? process.env).filter(([key, value]) => key.startsWith("PANDA_") && typeof value === "string" && value.trim()).map(([name, value]) => ({
167
208
  name,
@@ -182,6 +223,7 @@ var createNodeWindowsService = (definition) => {
182
223
  ensureWindows();
183
224
  const Service = getNodeWindowsServiceConstructor();
184
225
  return new Service({
226
+ id: resolveWindowsServiceReference(definition).controllerName,
185
227
  name: definition.name,
186
228
  description: definition.description,
187
229
  script: definition.scriptPath,
@@ -222,38 +264,43 @@ var waitForNodeWindowsAction = async (service, action) => await new Promise((res
222
264
  });
223
265
  var uninstallWindowsService = async (definition) => {
224
266
  ensureWindows();
225
- const current = queryWindowsServiceStatus(definition.name);
267
+ const current = queryWindowsServiceStatus(definition);
226
268
  if (!current.exists) {
227
269
  return current;
228
270
  }
229
271
  if (current.state === "running") {
230
- await stopWindowsService(definition.name);
272
+ await stopWindowsService(definition);
231
273
  }
232
274
  const service = createNodeWindowsService(definition);
233
275
  await waitForNodeWindowsAction(service, "uninstall");
234
- return queryWindowsServiceStatus(definition.name);
276
+ return queryWindowsServiceStatus(definition);
235
277
  };
236
278
  var installOrUpdateWindowsService = async (definition, options) => {
237
279
  ensureWindows();
238
- const existing = queryWindowsServiceStatus(definition.name);
280
+ const reference = resolveWindowsServiceReference(definition);
281
+ const existing = queryWindowsServiceStatus(definition);
239
282
  if (existing.exists) {
240
283
  await uninstallWindowsService(definition);
241
284
  }
242
285
  const service = createNodeWindowsService(definition);
243
286
  await waitForNodeWindowsAction(service, "install");
244
- runSc(["config", quoteForSc(definition.name), "start=", "auto"]);
287
+ const installed = await waitForWindowsServicePresence(definition);
288
+ if (!installed.exists) {
289
+ throw new Error(`Windows \u670D\u52A1 ${reference.displayName} \u6CE8\u518C\u540E\u4ECD\u4E0D\u53EF\u89C1\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5\u3002`);
290
+ }
291
+ runSc(["config", quoteForSc(installed.controllerName), "start=", "auto"]);
245
292
  let started = false;
246
293
  let startError = null;
247
294
  if (options?.start !== false) {
248
295
  try {
249
- const startedStatus = await startWindowsService(definition.name);
296
+ const startedStatus = await startWindowsService(definition);
250
297
  started = startedStatus.state === "running";
251
298
  } catch (error) {
252
299
  startError = error instanceof Error ? error.message : String(error);
253
300
  }
254
301
  }
255
302
  return {
256
- status: queryWindowsServiceStatus(definition.name),
303
+ status: queryWindowsServiceStatus(definition),
257
304
  started,
258
305
  startError
259
306
  };
package/dist/cli.mjs CHANGED
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  manageJamiexiongrHubService,
3
3
  startJamiexiongrHub
4
- } from "./chunk-72Z5Y3ZR.mjs";
4
+ } from "./chunk-VKOJD7PG.mjs";
5
5
  import {
6
6
  resolveTailscalePublicationMode
7
- } from "./chunk-I2346PMO.mjs";
7
+ } from "./chunk-SPTBBMUL.mjs";
8
8
  import "./chunk-AEQMWH7D.mjs";
9
9
 
10
10
  // release/panda-hub/src/cli.ts
package/dist/index.mjs CHANGED
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  manageJamiexiongrHubService,
3
3
  startJamiexiongrHub
4
- } from "./chunk-72Z5Y3ZR.mjs";
5
- import "./chunk-I2346PMO.mjs";
4
+ } from "./chunk-VKOJD7PG.mjs";
5
+ import "./chunk-SPTBBMUL.mjs";
6
6
  import "./chunk-AEQMWH7D.mjs";
7
7
  export {
8
8
  manageJamiexiongrHubService,
@@ -42,7 +42,7 @@ import {
42
42
  writeCodexGlobalState,
43
43
  writePandaSessionPrefs,
44
44
  writePandaThreadPrefs
45
- } from "./chunk-I2346PMO.mjs";
45
+ } from "./chunk-SPTBBMUL.mjs";
46
46
  import "./chunk-AEQMWH7D.mjs";
47
47
 
48
48
  // packages/provider-codex/src/index.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jamiexiongr/panda-hub",
3
- "version": "0.1.20",
3
+ "version": "0.1.22",
4
4
  "type": "module",
5
5
  "private": false,
6
6
  "description": "Panda hub runtime",