mslxdff 0.1.223 → 0.1.224
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/package.json +1 -1
- package/src/providers/railway.js +19 -4
package/package.json
CHANGED
package/src/providers/railway.js
CHANGED
|
@@ -7,12 +7,13 @@
|
|
|
7
7
|
// ③ 带 opencode 身份头(UA + client/session/request/project),否则同样 403。
|
|
8
8
|
//
|
|
9
9
|
// 端点:<base>/zen/v1/models、<base>/zen/v1/chat/completions(base 缺省为 Railway 反代根)。
|
|
10
|
+
import crypto from "node:crypto";
|
|
10
11
|
import { createKeyRing } from "./keyring.js";
|
|
11
12
|
import { collectApiKeysGeneric, envInt, createAgent, getUndici, joinUrl } from "./base.js";
|
|
12
13
|
import { compatFetch } from "../compat.js";
|
|
13
14
|
import { loadProviderBaseUrl, loadProviderKeys, saveProviderConfig } from "../state.js";
|
|
14
15
|
import { ensureFreeLaneShape, aggregateChatSse } from "../free-lane.js";
|
|
15
|
-
import { genId, opencodeUa } from "../opencode-identity.js";
|
|
16
|
+
import { genId, opencodeUa, digestIdTail } from "../opencode-identity.js";
|
|
16
17
|
import { joinModelId } from "./model-id.js";
|
|
17
18
|
|
|
18
19
|
const { UndiciFetch } = getUndici();
|
|
@@ -72,17 +73,31 @@ export function createRailwayProvider({
|
|
|
72
73
|
} catch {}
|
|
73
74
|
|
|
74
75
|
// 身份头 + free-lane:railway 反代的是 zen,两样缺一不可(缺任一都是 403 FreeTierError)。
|
|
76
|
+
// 会话取值同 generic.js 的 resolveGoSession:已合规(ses_ 前缀)直接用;客户端透传的任意串
|
|
77
|
+
// 做 sha1 摘要派生(稳定 + 合规);无则每请求 fresh。绝不可裸拼 `ses_` + 客户端串——上游会反解
|
|
78
|
+
// 低 12 位校验 counter,形状不符 403 FreeTierError(见 opencode-identity.js 头注)。
|
|
79
|
+
function resolveSession(id) {
|
|
80
|
+
const raw = String(id || "").trim();
|
|
81
|
+
if (/^ses_/.test(raw)) return raw;
|
|
82
|
+
if (raw) {
|
|
83
|
+
try {
|
|
84
|
+
return `ses_${digestIdTail(crypto.createHash("sha1").update(raw).digest())}`;
|
|
85
|
+
} catch {
|
|
86
|
+
return genId("ses_");
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return genId("ses_");
|
|
90
|
+
}
|
|
91
|
+
|
|
75
92
|
function buildHeaders(opts = {}) {
|
|
76
93
|
return {
|
|
77
94
|
"Content-Type": "application/json",
|
|
78
95
|
"Accept": "text/event-stream",
|
|
79
96
|
"User-Agent": opencodeUa(),
|
|
80
97
|
"x-opencode-client": "desktop",
|
|
81
|
-
|
|
82
|
-
"x-opencode-session": opts.sessionId ? `ses_${String(opts.sessionId).slice(0, 24)}` : genId("ses_"),
|
|
98
|
+
"x-opencode-session": resolveSession(opts.sessionId),
|
|
83
99
|
"x-opencode-request": genId("msg_"),
|
|
84
100
|
"x-opencode-project": "global",
|
|
85
|
-
...(ring.size ? {} : {}),
|
|
86
101
|
};
|
|
87
102
|
}
|
|
88
103
|
|