waygate-core 0.2.1 → 0.2.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/dist/report.js CHANGED
@@ -11,12 +11,16 @@ function baseUrl(host, port) {
11
11
  return `http://${h}:${port}`;
12
12
  }
13
13
  export function renderReady(r) {
14
+ const origin = baseUrl(r.host, r.port);
14
15
  const lines = [];
15
16
  lines.push(`途关 · ${r.displayName} 反代 v${r.version}`);
16
17
  lines.push('');
17
18
  lines.push(`凭证 ${r.credential.ok ? '✓' : '✗'} ${r.credential.detail}`);
18
19
  lines.push(`上游 ${r.upstream}`);
19
- lines.push(`代理 ${baseUrl(r.host, r.port)}`);
20
+ /* 两种填法都列 —— 客户端对 base_url 的约定不统一(OpenAI 系要带 /v1,
21
+ Claude Code 只填 origin),只给一个必然误导一半人。 */
22
+ lines.push(`代理 ${origin}/v1 (OpenAI 系客户端:Cursor / Cherry Studio / OpenAI SDK)`);
23
+ lines.push(` ${origin} (Anthropic 系客户端:Claude Code,它自己会补 /v1)`);
20
24
  /* 密钥**完整**打印(不打码):它就是给用户复制进客户端的,打码等于不可用。
21
25
  ⚠️ 只在本机终端输出;`--json` 同样给完整值(供脚本消费)。 */
22
26
  lines.push(`密钥 ${r.key}`);
@@ -34,18 +38,24 @@ export function renderReady(r) {
34
38
  lines.push(` ${m.id}${hint}`);
35
39
  }
36
40
  lines.push('');
37
- lines.push(`把上面的「代理地址 + 密钥」填进 Cursor / Claude Code / Cherry Studio 等客户端即可。`);
41
+ lines.push(`把上面的「代理地址 + 密钥」填进对应的客户端即可(两行按你的客户端类型二选一)。`);
38
42
  lines.push('端点:POST /v1/chat/completions(OpenAI 兼容)· POST /v1/messages(Anthropic 兼容)· GET /v1/models');
39
43
  lines.push('按 Ctrl+C 停止。');
40
44
  return lines.join('\n');
41
45
  }
42
46
  export function renderReadyJson(r) {
47
+ const origin = baseUrl(r.host, r.port);
43
48
  return JSON.stringify({
44
49
  command: r.command,
45
50
  displayName: r.displayName,
46
51
  version: r.version,
47
52
  upstream: r.upstream,
48
- proxyUrl: baseUrl(r.host, r.port),
53
+ /* 两种 base_url 都给:openaiBaseUrl 带 /v1(Cursor / Cherry Studio 等);
54
+ anthropicBaseUrl 不带(Claude Code 自己补 /v1)。origin 是裸地址。 */
55
+ origin,
56
+ proxyUrl: origin,
57
+ openaiBaseUrl: `${origin}/v1`,
58
+ anthropicBaseUrl: origin,
49
59
  key: r.key,
50
60
  credential: { ok: r.credential.ok, detail: r.credential.detail, source: r.credential.source ?? null },
51
61
  models: r.models.map((m) => ({ id: m.id, displayName: m.displayName ?? null })),
package/dist/server.js CHANGED
@@ -77,7 +77,11 @@ export function startServer(adapter, opts) {
77
77
  sendError(res, 401, '入站密钥缺失或不正确(Authorization: Bearer <key> 或 x-api-key)', 'invalid_api_key');
78
78
  return;
79
79
  }
80
- if (path === '/v1/models' && req.method === 'GET') {
80
+ /* [v0.2.2] 路径兼容:客户端对 base_url 的填法不一 —— 有的填 `http://host:port/v1`
81
+ (拼出 /v1/chat/completions),有的填 `http://host:port`(拼出 /chat/completions)。
82
+ 两种都接受,避免"多一个 /v1 就 404"这类让人摸不着头脑的失败。 */
83
+ const normalize = (p) => (p.startsWith('/v1/') ? p.slice(3) : p);
84
+ if (normalize(path) === '/models' && req.method === 'GET') {
81
85
  const models = await adapter.listModels();
82
86
  sendJson(res, 200, {
83
87
  object: 'list',
@@ -85,7 +89,7 @@ export function startServer(adapter, opts) {
85
89
  });
86
90
  return;
87
91
  }
88
- if ((path === '/v1/chat/completions' || path === '/v1/messages') && req.method === 'POST') {
92
+ if ((normalize(path) === '/chat/completions' || normalize(path) === '/messages') && req.method === 'POST') {
89
93
  const raw = (await readJsonBody(req));
90
94
  if (!raw || typeof raw.model !== 'string' || !raw.model.trim()) {
91
95
  sendError(res, 400, 'model 为必填项', 'invalid_request_error');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "waygate-core",
3
- "version": "0.2.1",
3
+ "version": "0.2.3",
4
4
  "description": "Waygate 家族共享骨架:本地反代 HTTP 服务、入站密钥、CLI、自检",
5
5
  "type": "module",
6
6
  "license": "MIT",