gpteam 0.1.12 → 0.1.14

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/lib/bench.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import dns from 'node:dns';
2
2
  import https from 'node:https';
3
3
  import { performance } from 'node:perf_hooks';
4
+ import { formatNetworkError } from './errors.js';
4
5
  import { inspectSSEBody } from './sse.js';
5
6
 
6
7
  const MISSING_LATENCY_MS = 999999;
@@ -106,7 +107,7 @@ async function measureHealth(url) {
106
107
  error: response.ok ? '' : `health HTTP ${response.status}`
107
108
  };
108
109
  } catch (error) {
109
- return { ok: false, status: 0, totalMs: performance.now() - started, error: error.message };
110
+ return { ok: false, status: 0, totalMs: performance.now() - started, error: formatNetworkError(error) };
110
111
  }
111
112
  }
112
113
 
@@ -186,7 +187,7 @@ function measureStream(baseUrl, options) {
186
187
  status: 0,
187
188
  ...timings,
188
189
  totalMs: performance.now() - started,
189
- error: error.message
190
+ error: formatNetworkError(error)
190
191
  });
191
192
  });
192
193
  request.end(payload);
@@ -78,28 +78,54 @@ async function shouldInstallMissingClient(spec, options) {
78
78
 
79
79
  async function runInstallCommand(spec, runCommand, platform) {
80
80
  const [command, args] = spec.installCommand;
81
- const result = await runCommand(resolveSpawnCommand(command, platform), args, { stdio: 'inherit' });
81
+ const invocation = resolveSpawnInvocation(command, args, platform);
82
+ const result = await runCommand(invocation.command, invocation.args, { stdio: 'inherit' });
82
83
  if (result.status !== 0) {
83
- throw new Error(`${spec.label} 安装失败,命令:${formatInstallCommand(spec)}`);
84
+ throw new Error(`${spec.label} 安装失败,命令:${formatInstallCommand(spec)}${formatRunError(result)}`);
84
85
  }
85
86
  }
86
87
 
87
- export function resolveSpawnCommand(command, platform = process.platform) {
88
- if (platform === 'win32' && command === 'npm') return 'npm.cmd';
89
- return command;
88
+ export function resolveSpawnInvocation(command, args, platform = process.platform) {
89
+ if (platform === 'win32' && command === 'npm') {
90
+ return {
91
+ command: 'cmd.exe',
92
+ args: ['/d', '/s', '/c', windowsCommandLine('npm.cmd', args)]
93
+ };
94
+ }
95
+ return { command, args };
90
96
  }
91
97
 
92
98
  export function defaultRunCommand(command, args, options = {}) {
93
99
  return new Promise((resolve) => {
94
- const child = spawn(command, args, {
95
- stdio: options.stdio || 'ignore',
96
- shell: options.shell || false
97
- });
98
- child.on('error', () => resolve({ status: 127 }));
100
+ let child;
101
+ try {
102
+ child = spawn(command, args, {
103
+ stdio: options.stdio || 'ignore',
104
+ shell: options.shell || false
105
+ });
106
+ } catch (error) {
107
+ resolve({ status: 127, error });
108
+ return;
109
+ }
110
+ child.on('error', (error) => resolve({ status: 127, error }));
99
111
  child.on('close', (status) => resolve({ status: status ?? 1 }));
100
112
  });
101
113
  }
102
114
 
115
+ function formatRunError(result) {
116
+ if (!result || !result.error) return '';
117
+ const code = result.error.code || result.error.message;
118
+ return `,底层错误:${code}`;
119
+ }
120
+
121
+ function windowsCommandLine(command, args) {
122
+ return [command, ...args].map(windowsQuoteArg).join(' ');
123
+ }
124
+
125
+ function windowsQuoteArg(value) {
126
+ return `"${String(value).replace(/"/g, '\\"')}"`;
127
+ }
128
+
103
129
  function shellQuote(value) {
104
130
  return `'${String(value).replace(/'/g, "'\\''")}'`;
105
131
  }
package/lib/errors.js ADDED
@@ -0,0 +1,24 @@
1
+ export function formatNetworkError(error) {
2
+ const details = [];
3
+ const message = error && error.message ? String(error.message) : String(error || 'network error');
4
+ if (message) details.push(message);
5
+
6
+ let cause = error && error.cause;
7
+ const seen = new Set();
8
+ while (cause && !seen.has(cause)) {
9
+ seen.add(cause);
10
+ const causeDetails = [
11
+ cause.code,
12
+ cause.errno && cause.errno !== cause.code ? cause.errno : '',
13
+ cause.syscall,
14
+ cause.hostname,
15
+ cause.address,
16
+ cause.port ? `port ${cause.port}` : ''
17
+ ].filter(Boolean);
18
+ if (cause.message && cause.message !== message) causeDetails.push(cause.message);
19
+ if (causeDetails.length) details.push(causeDetails.join(' '));
20
+ cause = cause.cause;
21
+ }
22
+
23
+ return [...new Set(details)].join(',') || 'network error';
24
+ }
package/lib/help.js CHANGED
@@ -1,5 +1,5 @@
1
1
  export const PACKAGE_NAME = 'gpteam';
2
- export const PACKAGE_VERSION = '0.1.12';
2
+ export const PACKAGE_VERSION = '0.1.14';
3
3
 
4
4
  export function getHelpText() {
5
5
  return [
package/lib/models.js CHANGED
@@ -1,3 +1,5 @@
1
+ import { formatNetworkError } from './errors.js';
2
+
1
3
  export const FALLBACK_MODELS = {
2
4
  'gpt-5.2': {
3
5
  id: 'gpt-5.2',
@@ -73,13 +75,18 @@ export function normalizeModels(payload) {
73
75
  }
74
76
 
75
77
  export async function fetchModels(baseUrl, apiKey, options = {}) {
76
- const response = await fetch(`${baseUrl.replace(/\/$/, '')}/models`, {
77
- signal: makeTimeoutSignal(options.timeoutMs || 15000),
78
- headers: {
79
- Authorization: `Bearer ${apiKey}`,
80
- 'User-Agent': 'gpteam-api-config/0.1'
81
- }
82
- });
78
+ let response;
79
+ try {
80
+ response = await fetch(`${baseUrl.replace(/\/$/, '')}/models`, {
81
+ signal: makeTimeoutSignal(options.timeoutMs || 15000),
82
+ headers: {
83
+ Authorization: `Bearer ${apiKey}`,
84
+ 'User-Agent': 'gpteam-api-config/0.1'
85
+ }
86
+ });
87
+ } catch (error) {
88
+ throw new Error(`/v1/models 请求失败:${formatNetworkError(error)}`);
89
+ }
83
90
  if (!response.ok) {
84
91
  const detail = await readResponseError(response);
85
92
  throw new Error(`/v1/models 返回 HTTP ${response.status}${detail ? `:${detail}` : ''}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gpteam",
3
- "version": "0.1.12",
3
+ "version": "0.1.14",
4
4
  "description": "GPTeam API interactive client configurator and ingress benchmark CLI.",
5
5
  "type": "module",
6
6
  "bin": {