@tiens.nguyen/gonext-local-worker 1.0.73 → 1.0.75

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.
@@ -1061,8 +1061,10 @@ async function correctOcrText(extractedText, modelOverride = "") {
1061
1061
  if (override.startsWith("http://") || override.startsWith("https://")) {
1062
1062
  const baseUrl = /\/v1\/?$/i.test(override) ? override : `${override}/v1`;
1063
1063
  console.log(`[gonext-worker] OCR correction via server ${baseUrl}`);
1064
+ console.log(`[gonext-worker] OCR correction input: ${extractedText.slice(0, 300)}`);
1064
1065
  try {
1065
1066
  const corrected = await correctOcrTextViaServer(extractedText, baseUrl);
1067
+ console.log(`[gonext-worker] OCR correction output: ${corrected.slice(0, 300)}`);
1066
1068
  console.log(`[gonext-worker] OCR correction done: ${extractedText.length} → ${corrected.length} chars`);
1067
1069
  return corrected;
1068
1070
  } catch (e) {
@@ -1081,6 +1083,7 @@ async function correctOcrText(extractedText, modelOverride = "") {
1081
1083
  "Return only the corrected text without any explanation.\n\n" +
1082
1084
  `Text:\n${extractedText}`;
1083
1085
  console.log(`[gonext-worker] OCR correction via CLI model=${modelPath}`);
1086
+ console.log(`[gonext-worker] OCR correction input: ${extractedText.slice(0, 300)}`);
1084
1087
  // Write prompt to a temp Python script that calls mlx_lm programmatically,
1085
1088
  // avoiding CLI arg length/escaping limits and the missing --prompt-file flag.
1086
1089
  const scriptFile = join(tmpdir(), `gonext-ocr-correct-${Date.now()}.py`);
@@ -1104,6 +1107,7 @@ print(result)
1104
1107
  console.log(`[gonext-worker] OCR correction CLI stderr: ${stderr.trim().slice(0, 300)}`);
1105
1108
  }
1106
1109
  const corrected = normalizeCorrection(stdout, extractedText);
1110
+ console.log(`[gonext-worker] OCR correction output: ${corrected.slice(0, 300)}`);
1107
1111
  console.log(`[gonext-worker] OCR correction done: ${extractedText.length} → ${corrected.length} chars`);
1108
1112
  return corrected;
1109
1113
  } catch (e) {
@@ -128,10 +128,12 @@ def _route(task_text: str, base_url: str, api_key: str, model_id: str) -> bool:
128
128
  model=model_id,
129
129
  messages=[
130
130
  {"role": "system", "content": (
131
- "You are a task classifier. Reply with YES or NO only, no punctuation."
131
+ "You are a task classifier. Reply YES or NO only, no punctuation. "
132
+ "Answer NO if the task can be solved with Python stdlib (datetime, math, etc.) "
133
+ "or is just conversation. Answer YES only if it requires calling an EXTERNAL URL or web API."
132
134
  )},
133
135
  {"role": "user", "content": (
134
- f"Does this task require making an HTTP request to a URL or API?\n\n"
136
+ f"Does this task specifically require making an HTTP request to an external URL or web API?\n\n"
135
137
  f"Task: {task_text}\n\nYES or NO:"
136
138
  )},
137
139
  ],
@@ -246,10 +248,17 @@ def run_agent_chat(cfg):
246
248
  "You have ONE built-in function: `http_request(method, url, headers='', body='')`. "
247
249
  "It returns a STRING with the HTTP status and body. "
248
250
  "Call it, then immediately call `final_answer(response)` inside the same code block.\n"
249
- "Do NOT put final_answer outside the code block.\n\n"
251
+ "IMPORTANT RULES:\n"
252
+ "- Python's `datetime` module is available — use it for date/time tasks, no HTTP needed.\n"
253
+ "- If http_request returns an error starting with 'Error:', the URL failed. "
254
+ "Do NOT retry the same URL. Try a DIFFERENT URL or API, or use Python stdlib.\n"
255
+ "- Do NOT put final_answer outside the code block.\n\n"
250
256
  )
251
257
  task_with_hint = tool_hint + "Task: " + task_text
252
258
 
259
+ # Track URLs that have already failed so we don't retry dead endpoints across steps.
260
+ _failed_urls: set = set()
261
+
253
262
  @tool
254
263
  def http_request(method: str, url: str, headers: str = "", body: str = "") -> str:
255
264
  """Perform an HTTP request and return the status code and body preview.
@@ -266,11 +275,25 @@ def run_agent_chat(cfg):
266
275
  parsed_headers = json.loads(headers)
267
276
  except Exception: # noqa: BLE001
268
277
  pass
269
- # Retry once on timeout — gorok tunnels can be flaky on the first attempt.
278
+ url_key = f"{method.upper()}:{url}"
279
+ if url_key in _failed_urls:
280
+ msg = f"Error: {url} already failed — try a different URL or use Python stdlib."
281
+ _emit({"type": "step", "text": f"HTTP {method.upper()} {url} → (skipped, already failed)"})
282
+ _log(f"http_request skipped (already failed): {url_key}")
283
+ return msg
270
284
  result = _http_request_impl(method, url, parsed_headers, body or None)
271
285
  if result.startswith("Error:"):
286
+ # Retry once for flaky connections (e.g. gorok tunnels).
272
287
  _log(f"http_request retry {method.upper()} {url}")
273
288
  result = _http_request_impl(method, url, parsed_headers, body or None)
289
+ if result.startswith("Error:"):
290
+ # Both attempts failed — mark URL as dead so model tries something else.
291
+ _failed_urls.add(url_key)
292
+ result = (
293
+ f"{result}\n"
294
+ "Note: This URL failed twice. Do NOT retry it. "
295
+ "Try a DIFFERENT URL or use Python's datetime/math/etc. module instead."
296
+ )
274
297
  status_line = result.split("\n")[0][:150] if result else "no response"
275
298
  _emit({"type": "step", "text": f"HTTP {method.upper()} {url} → {status_line}"})
276
299
  _log(f"http_request {method.upper()} {url} → {result[:80]}")
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tiens.nguyen/gonext-local-worker",
3
- "version": "1.0.73",
3
+ "version": "1.0.75",
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",