ework-web 0.10.126 → 0.10.128
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/index.ts +14 -0
- package/src/translate.ts +4 -0
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -420,6 +420,9 @@ const SESSION_BATCH_RE = /^\/api\/sessions\/([A-Za-z0-9_-]+)\/batch$/;
|
|
|
420
420
|
const server = Bun.serve({
|
|
421
421
|
port: cfg.port,
|
|
422
422
|
hostname: cfg.host,
|
|
423
|
+
// Streaming routes (translate, live tails) legitimately sit silent past the
|
|
424
|
+
// 10s default while upstream queues; 60s matches their in-route heartbeats.
|
|
425
|
+
idleTimeout: 60,
|
|
423
426
|
async fetch(req, server) {
|
|
424
427
|
const url = new URL(req.url);
|
|
425
428
|
const ip = remoteAddr(req, server);
|
|
@@ -1009,6 +1012,16 @@ async function handle(req: Request, url: URL, ip: string, ctx: { authed: boolean
|
|
|
1009
1012
|
async start(controller) {
|
|
1010
1013
|
const enc = new TextEncoder();
|
|
1011
1014
|
const send = (obj: unknown) => controller.enqueue(enc.encode(JSON.stringify(obj) + "\n"));
|
|
1015
|
+
// Bun closes connections idle >10s by default; under model-server load
|
|
1016
|
+
// the first translation chunk can queue longer than that. Heartbeat
|
|
1017
|
+
// lines ({"s":1}) keep the connection alive and are ignored by clients.
|
|
1018
|
+
const heartbeat = setInterval(() => {
|
|
1019
|
+
try {
|
|
1020
|
+
send({ s: 1 });
|
|
1021
|
+
} catch {
|
|
1022
|
+
/* client disconnected */
|
|
1023
|
+
}
|
|
1024
|
+
}, 5000);
|
|
1012
1025
|
try {
|
|
1013
1026
|
let full = "";
|
|
1014
1027
|
for await (const chunk of translateTextStream(cfg, text)) {
|
|
@@ -1019,6 +1032,7 @@ async function handle(req: Request, url: URL, ip: string, ctx: { authed: boolean
|
|
|
1019
1032
|
} catch (e) {
|
|
1020
1033
|
send({ e: e instanceof Error ? e.message : String(e) });
|
|
1021
1034
|
} finally {
|
|
1035
|
+
clearInterval(heartbeat);
|
|
1022
1036
|
controller.close();
|
|
1023
1037
|
}
|
|
1024
1038
|
},
|
package/src/translate.ts
CHANGED
|
@@ -45,6 +45,9 @@ export async function translateText(cfg: Config, text: string): Promise<string>
|
|
|
45
45
|
body: JSON.stringify({
|
|
46
46
|
model: cfg.translateModel,
|
|
47
47
|
stream: false,
|
|
48
|
+
// Reasoning-off: translation needs none, and reasoning tokens delay
|
|
49
|
+
// time-to-first-token past interactive patience on the shared server.
|
|
50
|
+
chat_template_kwargs: { enable_thinking: false },
|
|
48
51
|
messages: [
|
|
49
52
|
{ role: "system", content: SYSTEM_PROMPT },
|
|
50
53
|
{ role: "user", content: body },
|
|
@@ -121,6 +124,7 @@ async function* streamOneChunk(cfg: Config, chunk: string): AsyncGenerator<strin
|
|
|
121
124
|
body: JSON.stringify({
|
|
122
125
|
model: cfg.translateModel,
|
|
123
126
|
stream: true,
|
|
127
|
+
chat_template_kwargs: { enable_thinking: false },
|
|
124
128
|
messages: [
|
|
125
129
|
{ role: "system", content: SYSTEM_PROMPT },
|
|
126
130
|
{ role: "user", content: chunk },
|