@jamiexiongr/panda-hub 0.1.20 → 0.1.21
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 '${
|
|
8533
|
-
`if ($null -eq $service) {
|
|
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
|
-
|
|
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
|
|
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 '" +
|
|
8912
|
-
"if ($null -eq $service) { '
|
|
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
|
-
|
|
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-
|
|
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-
|
|
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-
|
|
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.
|
|
18
|
+
version: "0.1.21",
|
|
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 = (
|
|
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(
|
|
104
|
-
`if ($null -eq $service) {
|
|
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
|
-
|
|
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,59 @@ ${result.stderr ?? ""}`.trim();
|
|
|
117
141
|
var wait = (ms) => new Promise((resolve) => {
|
|
118
142
|
setTimeout(resolve, ms);
|
|
119
143
|
});
|
|
120
|
-
var waitForWindowsServiceState = async (
|
|
144
|
+
var waitForWindowsServiceState = async (input, desiredState, timeoutMs = WINDOWS_SERVICE_TIMEOUT_MS) => {
|
|
121
145
|
const startedAt = Date.now();
|
|
122
|
-
let latest = queryWindowsServiceStatus(
|
|
146
|
+
let latest = queryWindowsServiceStatus(input);
|
|
123
147
|
while (latest.state !== desiredState && Date.now() - startedAt < timeoutMs) {
|
|
124
148
|
await wait(750);
|
|
125
|
-
latest = queryWindowsServiceStatus(
|
|
149
|
+
latest = queryWindowsServiceStatus(input);
|
|
126
150
|
}
|
|
127
151
|
return latest;
|
|
128
152
|
};
|
|
129
|
-
var startWindowsService = async (
|
|
153
|
+
var startWindowsService = async (input) => {
|
|
130
154
|
ensureWindows();
|
|
131
|
-
const current = queryWindowsServiceStatus(
|
|
155
|
+
const current = queryWindowsServiceStatus(input);
|
|
132
156
|
if (!current.exists) {
|
|
133
|
-
throw new Error(`Windows \u670D\u52A1 ${
|
|
157
|
+
throw new Error(`Windows \u670D\u52A1 ${current.displayName} \u4E0D\u5B58\u5728\u3002`);
|
|
134
158
|
}
|
|
135
159
|
if (current.state === "running") {
|
|
136
160
|
return current;
|
|
137
161
|
}
|
|
138
|
-
const result = runPowerShell(
|
|
162
|
+
const result = runPowerShell(
|
|
163
|
+
`Start-Service -Name '${escapePowerShellString(current.controllerName)}' -ErrorAction Stop`
|
|
164
|
+
);
|
|
139
165
|
const output = `${result.stdout ?? ""}
|
|
140
166
|
${result.stderr ?? ""}`.trim();
|
|
141
|
-
const latest = await waitForWindowsServiceState(
|
|
167
|
+
const latest = await waitForWindowsServiceState(input, "running");
|
|
142
168
|
if (latest.state !== "running") {
|
|
143
|
-
throw new Error(
|
|
169
|
+
throw new Error(
|
|
170
|
+
describeCommandFailure(output || latest.rawOutput, `\u542F\u52A8\u670D\u52A1 ${current.displayName} \u5931\u8D25\u3002`)
|
|
171
|
+
);
|
|
144
172
|
}
|
|
145
173
|
return latest;
|
|
146
174
|
};
|
|
147
|
-
var stopWindowsService = async (
|
|
175
|
+
var stopWindowsService = async (input) => {
|
|
148
176
|
ensureWindows();
|
|
149
|
-
const current = queryWindowsServiceStatus(
|
|
177
|
+
const current = queryWindowsServiceStatus(input);
|
|
150
178
|
if (!current.exists || current.state === "stopped") {
|
|
151
179
|
return current;
|
|
152
180
|
}
|
|
153
|
-
const result = runPowerShell(
|
|
181
|
+
const result = runPowerShell(
|
|
182
|
+
`Stop-Service -Name '${escapePowerShellString(current.controllerName)}' -Force -ErrorAction Stop`
|
|
183
|
+
);
|
|
154
184
|
const output = `${result.stdout ?? ""}
|
|
155
185
|
${result.stderr ?? ""}`.trim();
|
|
156
|
-
const latest = await waitForWindowsServiceState(
|
|
186
|
+
const latest = await waitForWindowsServiceState(input, "stopped");
|
|
157
187
|
if (latest.state !== "stopped") {
|
|
158
|
-
throw new Error(
|
|
188
|
+
throw new Error(
|
|
189
|
+
describeCommandFailure(output || latest.rawOutput, `\u505C\u6B62\u670D\u52A1 ${current.displayName} \u5931\u8D25\u3002`)
|
|
190
|
+
);
|
|
159
191
|
}
|
|
160
192
|
return latest;
|
|
161
193
|
};
|
|
162
|
-
var restartWindowsService = async (
|
|
163
|
-
await stopWindowsService(
|
|
164
|
-
return await startWindowsService(
|
|
194
|
+
var restartWindowsService = async (input) => {
|
|
195
|
+
await stopWindowsService(input);
|
|
196
|
+
return await startWindowsService(input);
|
|
165
197
|
};
|
|
166
198
|
var collectServiceEnvironment = (env) => Object.entries(env ?? process.env).filter(([key, value]) => key.startsWith("PANDA_") && typeof value === "string" && value.trim()).map(([name, value]) => ({
|
|
167
199
|
name,
|
|
@@ -182,6 +214,7 @@ var createNodeWindowsService = (definition) => {
|
|
|
182
214
|
ensureWindows();
|
|
183
215
|
const Service = getNodeWindowsServiceConstructor();
|
|
184
216
|
return new Service({
|
|
217
|
+
id: resolveWindowsServiceReference(definition).controllerName,
|
|
185
218
|
name: definition.name,
|
|
186
219
|
description: definition.description,
|
|
187
220
|
script: definition.scriptPath,
|
|
@@ -222,38 +255,39 @@ var waitForNodeWindowsAction = async (service, action) => await new Promise((res
|
|
|
222
255
|
});
|
|
223
256
|
var uninstallWindowsService = async (definition) => {
|
|
224
257
|
ensureWindows();
|
|
225
|
-
const current = queryWindowsServiceStatus(definition
|
|
258
|
+
const current = queryWindowsServiceStatus(definition);
|
|
226
259
|
if (!current.exists) {
|
|
227
260
|
return current;
|
|
228
261
|
}
|
|
229
262
|
if (current.state === "running") {
|
|
230
|
-
await stopWindowsService(definition
|
|
263
|
+
await stopWindowsService(definition);
|
|
231
264
|
}
|
|
232
265
|
const service = createNodeWindowsService(definition);
|
|
233
266
|
await waitForNodeWindowsAction(service, "uninstall");
|
|
234
|
-
return queryWindowsServiceStatus(definition
|
|
267
|
+
return queryWindowsServiceStatus(definition);
|
|
235
268
|
};
|
|
236
269
|
var installOrUpdateWindowsService = async (definition, options) => {
|
|
237
270
|
ensureWindows();
|
|
238
|
-
const
|
|
271
|
+
const reference = resolveWindowsServiceReference(definition);
|
|
272
|
+
const existing = queryWindowsServiceStatus(definition);
|
|
239
273
|
if (existing.exists) {
|
|
240
274
|
await uninstallWindowsService(definition);
|
|
241
275
|
}
|
|
242
276
|
const service = createNodeWindowsService(definition);
|
|
243
277
|
await waitForNodeWindowsAction(service, "install");
|
|
244
|
-
runSc(["config", quoteForSc(
|
|
278
|
+
runSc(["config", quoteForSc(reference.controllerName), "start=", "auto"]);
|
|
245
279
|
let started = false;
|
|
246
280
|
let startError = null;
|
|
247
281
|
if (options?.start !== false) {
|
|
248
282
|
try {
|
|
249
|
-
const startedStatus = await startWindowsService(definition
|
|
283
|
+
const startedStatus = await startWindowsService(definition);
|
|
250
284
|
started = startedStatus.state === "running";
|
|
251
285
|
} catch (error) {
|
|
252
286
|
startError = error instanceof Error ? error.message : String(error);
|
|
253
287
|
}
|
|
254
288
|
}
|
|
255
289
|
return {
|
|
256
|
-
status: queryWindowsServiceStatus(definition
|
|
290
|
+
status: queryWindowsServiceStatus(definition),
|
|
257
291
|
started,
|
|
258
292
|
startError
|
|
259
293
|
};
|
package/dist/cli.mjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
manageJamiexiongrHubService,
|
|
3
3
|
startJamiexiongrHub
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-YKNCRHVV.mjs";
|
|
5
5
|
import {
|
|
6
6
|
resolveTailscalePublicationMode
|
|
7
|
-
} from "./chunk-
|
|
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-
|
|
5
|
-
import "./chunk-
|
|
4
|
+
} from "./chunk-YKNCRHVV.mjs";
|
|
5
|
+
import "./chunk-SPTBBMUL.mjs";
|
|
6
6
|
import "./chunk-AEQMWH7D.mjs";
|
|
7
7
|
export {
|
|
8
8
|
manageJamiexiongrHubService,
|