@tiens.nguyen/gonext-local-worker 1.0.22 → 1.0.25

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.
@@ -162,6 +162,10 @@ async function runChatJob(job) {
162
162
  /** Chains debounced chunk POSTs so we never PATCH `completed` while a chunk POST is still in flight. */
163
163
  let flushTail = Promise.resolve();
164
164
 
165
+ /** Batch streamed text: fewer HTTPS round-trips to the API than a 12ms debounce per flush. */
166
+ const CHUNK_DEBOUNCE_MS = 80;
167
+ const CHUNK_MAX_BUF = 6144;
168
+
165
169
  const flushChunks = async () => {
166
170
  const t = buf;
167
171
  buf = "";
@@ -199,13 +203,23 @@ async function runChatJob(job) {
199
203
  if (!s) return;
200
204
  fullText += s;
201
205
  buf += s;
206
+ if (buf.length >= CHUNK_MAX_BUF) {
207
+ if (flushTimer) {
208
+ clearTimeout(flushTimer);
209
+ flushTimer = null;
210
+ }
211
+ flushTail = flushTail.then(() => flushChunks()).catch((err) => {
212
+ console.error("[gonext-worker] chunk flush error:", err);
213
+ });
214
+ return;
215
+ }
202
216
  if (!flushTimer) {
203
217
  flushTimer = setTimeout(() => {
204
218
  flushTimer = null;
205
219
  flushTail = flushTail.then(() => flushChunks()).catch((err) => {
206
220
  console.error("[gonext-worker] chunk flush error:", err);
207
221
  });
208
- }, 12);
222
+ }, CHUNK_DEBOUNCE_MS);
209
223
  }
210
224
  };
211
225
 
@@ -251,6 +265,8 @@ async function runChatJob(job) {
251
265
  await flushTail;
252
266
  await flushChunks();
253
267
 
268
+ logModelResponseToWorker(jobId, payload.modelId, fullText);
269
+
254
270
  const totalTimeSeconds = (Date.now() - start) / 1000;
255
271
  await workerFetch(`/api/worker/jobs/${jobId}`, {
256
272
  method: "PATCH",
@@ -300,6 +316,16 @@ function sourceLabelFromBase(base) {
300
316
  }
301
317
  }
302
318
 
319
+ /** Log assistant text to stdout; cap size so huge replies do not flood the terminal. */
320
+ function logModelResponseToWorker(jobId, modelId, text) {
321
+ const max = 12000;
322
+ const n = text.length;
323
+ const body = n <= max ? text : `${text.slice(0, max)}\n… [log truncated: ${n - max} more chars]`;
324
+ console.log(
325
+ `[gonext-worker] model reply job=${jobId} model=${modelId} chars=${n}:\n${body}`
326
+ );
327
+ }
328
+
303
329
  async function checkOllamaTags(base) {
304
330
  const endpoint = `${base}/api/tags`;
305
331
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tiens.nguyen/gonext-local-worker",
3
- "version": "1.0.22",
3
+ "version": "1.0.25",
4
4
  "description": "Polls GoNext cloud API for async local LLM jobs and runs them against Ollama/OpenAI-compatible servers on this Mac",
5
5
  "type": "module",
6
6
  "license": "MIT",