waygate-core 0.2.1 → 0.2.2

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.
Files changed (2) hide show
  1. package/dist/server.js +6 -2
  2. package/package.json +1 -1
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.2",
4
4
  "description": "Waygate 家族共享骨架:本地反代 HTTP 服务、入站密钥、CLI、自检",
5
5
  "type": "module",
6
6
  "license": "MIT",