@tiens.nguyen/gonext-local-worker 1.0.76 → 1.0.78

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.
@@ -268,13 +268,22 @@ def run_agent_chat(cfg):
268
268
  # Prepend explicit tool instructions so small models use http_request correctly
269
269
  # and always terminate with final_answer() rather than looping forever.
270
270
  tool_hint = (
271
- "You have ONE built-in function: `http_request(method, url, headers='', body='')`. "
272
- "It returns a STRING with the HTTP status and body. "
273
- "Call it, then immediately call `final_answer(response)` inside the same code block.\n"
271
+ "You have ONE built-in function:\n"
272
+ " `http_request(method, url, headers='', body='', username='', password='')`\n"
273
+ "RETURN FORMAT: the function returns a string like:\n"
274
+ " 'HTTP 200\\n{\"key\": \"value\"}'\n"
275
+ " First line is 'HTTP <code>' (e.g. 'HTTP 200'). Body follows after the first newline.\n"
276
+ "CORRECT USAGE — always just pass response directly to final_answer:\n"
277
+ " response = http_request('GET', url)\n"
278
+ " final_answer(response)\n"
279
+ "Do NOT try to parse or split the response string.\n"
274
280
  "IMPORTANT RULES:\n"
275
- "- Python's `datetime` module is available use it for date/time tasks, no HTTP needed.\n"
276
- "- If http_request returns an error starting with 'Error:', the URL failed. "
277
- "Do NOT retry the same URL. Try a DIFFERENT URL or API, or use Python stdlib.\n"
281
+ "- If you get HTTP 2xx (200, 201, etc.) in the first line, the request SUCCEEDED. "
282
+ "Call final_answer immediately do NOT retry.\n"
283
+ "- For Basic Auth: username= and password= params handle encoding automatically.\n"
284
+ "- For Bearer token: headers='{\"Authorization\": \"Bearer TOKEN\"}'\n"
285
+ "- If http_request returns an error (starts with 'Error:'), try a different URL.\n"
286
+ "- Python's `datetime` module is available for date/time tasks.\n"
278
287
  "- Do NOT put final_answer outside the code block.\n\n"
279
288
  )
280
289
  task_with_hint = tool_hint + "Task: " + task_text
@@ -283,7 +292,8 @@ def run_agent_chat(cfg):
283
292
  _failed_urls: set = set()
284
293
 
285
294
  @tool
286
- def http_request(method: str, url: str, headers: str = "", body: str = "") -> str:
295
+ def http_request(method: str, url: str, headers: str = "", body: str = "",
296
+ username: str = "", password: str = "") -> str:
287
297
  """Perform an HTTP request and return the status code and body preview.
288
298
 
289
299
  Args:
@@ -291,11 +301,18 @@ def run_agent_chat(cfg):
291
301
  url: Full URL to request
292
302
  headers: Optional JSON object string of request headers
293
303
  body: Optional request body string
304
+ username: Username for Basic Authentication (avoids manual base64 encoding)
305
+ password: Password for Basic Authentication
294
306
  """
307
+ import base64 as _b64
295
308
  parsed_headers = {}
309
+ # Basic Auth: encode credentials automatically if provided.
310
+ if username or password:
311
+ creds = _b64.b64encode(f"{username}:{password}".encode()).decode()
312
+ parsed_headers["Authorization"] = f"Basic {creds}"
296
313
  if headers:
297
314
  try:
298
- parsed_headers = json.loads(headers)
315
+ parsed_headers.update(json.loads(headers))
299
316
  except Exception: # noqa: BLE001
300
317
  pass
301
318
  url_key = f"{method.upper()}:{url}"
@@ -318,6 +335,9 @@ def run_agent_chat(cfg):
318
335
  "Try a DIFFERENT URL or use Python's datetime/math/etc. module instead."
319
336
  )
320
337
  status_line = result.split("\n")[0][:150] if result else "no response"
338
+ # Append a success tag to 2xx responses so the model knows to stop and call final_answer.
339
+ if result and result.startswith("HTTP 2"):
340
+ result = result + "\n[SUCCESS — call final_answer(response) now, do not parse or retry]"
321
341
  _emit({"type": "step", "text": f"HTTP {method.upper()} {url} → {status_line}"})
322
342
  _log(f"http_request {method.upper()} {url} → {result[:80]}")
323
343
  return result
@@ -363,7 +383,7 @@ def run_agent_chat(cfg):
363
383
  max_steps=max_steps,
364
384
  step_callbacks=[step_callback],
365
385
  executor_kwargs={"timeout_seconds": 60},
366
- additional_authorized_imports=["json", "urllib", "urllib.request", "urllib.error"],
386
+ additional_authorized_imports=["json", "base64", "urllib", "urllib.request", "urllib.error"],
367
387
  )
368
388
  with contextlib.redirect_stdout(sys.stderr):
369
389
  result = agent.run(task_with_hint)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tiens.nguyen/gonext-local-worker",
3
- "version": "1.0.76",
3
+ "version": "1.0.78",
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",