@tiens.nguyen/gonext-local-worker 1.0.77 → 1.0.79

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.
@@ -239,16 +239,28 @@ def run_agent_chat(cfg):
239
239
 
240
240
  _log(f"start model={agent_model_id!r} base={agent_base_url!r} maxSteps={max_steps}")
241
241
 
242
- # Use only the latest user message as the agent task.
242
+ # Build task from the conversation history.
243
+ # Include prior USER messages as context so the agent has conversational memory,
244
+ # but exclude prior ASSISTANT messages (they contain raw HTTP/thinking content
245
+ # that confuses small models).
243
246
  task_text = ""
247
+ prior_user_msgs = []
244
248
  for m in messages:
245
- if m.get("role") == "user":
246
- task_text = m.get("content", "")
249
+ role = m.get("role", "")
250
+ content = m.get("content", "")
251
+ if role == "user":
252
+ if task_text:
253
+ prior_user_msgs.append(task_text)
254
+ task_text = content
247
255
 
248
256
  if not task_text:
249
257
  _emit({"type": "final", "text": "[No user message found in history]"})
250
258
  return
251
259
 
260
+ if prior_user_msgs:
261
+ context = "\n".join(f"- {t[:300]}" for t in prior_user_msgs[-4:])
262
+ task_text = f"Conversation context (previous user messages):\n{context}\n\nCurrent task: {task_text}"
263
+
252
264
  _log(f"task={task_text[:120]!r}")
253
265
 
254
266
  # Route: ask the model if this task needs HTTP tool use.
@@ -268,17 +280,22 @@ def run_agent_chat(cfg):
268
280
  # Prepend explicit tool instructions so small models use http_request correctly
269
281
  # and always terminate with final_answer() rather than looping forever.
270
282
  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"
283
+ "You have ONE built-in function:\n"
284
+ " `http_request(method, url, headers='', body='', username='', password='')`\n"
285
+ "RETURN FORMAT: the function returns a string like:\n"
286
+ " 'HTTP 200\\n{\"key\": \"value\"}'\n"
287
+ " First line is 'HTTP <code>' (e.g. 'HTTP 200'). Body follows after the first newline.\n"
288
+ "CORRECT USAGE — always just pass response directly to final_answer:\n"
289
+ " response = http_request('GET', url)\n"
290
+ " final_answer(response)\n"
291
+ "Do NOT try to parse or split the response string.\n"
274
292
  "IMPORTANT RULES:\n"
275
- "- `headers` must be a JSON string, e.g. headers='{\"Content-Type\": \"application/json\"}'\n"
276
- "- For Basic Auth: import base64; "
277
- "creds = base64.b64encode(b'user:password').decode(); "
278
- "headers = '{\"Authorization\": \"Basic ' + creds + '\"}'\n"
279
- "- For Bearer token: headers='{\"Authorization\": \"Bearer YOUR_TOKEN\"}'\n"
280
- "- Python's `datetime` and `base64` modules are available.\n"
281
- "- If http_request returns an error starting with 'Error:', do NOT retry the same URL. Try a different one.\n"
293
+ "- If you get HTTP 2xx (200, 201, etc.) in the first line, the request SUCCEEDED. "
294
+ "Call final_answer immediately do NOT retry.\n"
295
+ "- For Basic Auth: username= and password= params handle encoding automatically.\n"
296
+ "- For Bearer token: headers='{\"Authorization\": \"Bearer TOKEN\"}'\n"
297
+ "- If http_request returns an error (starts with 'Error:'), try a different URL.\n"
298
+ "- Python's `datetime` module is available for date/time tasks.\n"
282
299
  "- Do NOT put final_answer outside the code block.\n\n"
283
300
  )
284
301
  task_with_hint = tool_hint + "Task: " + task_text
@@ -287,7 +304,8 @@ def run_agent_chat(cfg):
287
304
  _failed_urls: set = set()
288
305
 
289
306
  @tool
290
- def http_request(method: str, url: str, headers: str = "", body: str = "") -> str:
307
+ def http_request(method: str, url: str, headers: str = "", body: str = "",
308
+ username: str = "", password: str = "") -> str:
291
309
  """Perform an HTTP request and return the status code and body preview.
292
310
 
293
311
  Args:
@@ -295,11 +313,18 @@ def run_agent_chat(cfg):
295
313
  url: Full URL to request
296
314
  headers: Optional JSON object string of request headers
297
315
  body: Optional request body string
316
+ username: Username for Basic Authentication (avoids manual base64 encoding)
317
+ password: Password for Basic Authentication
298
318
  """
319
+ import base64 as _b64
299
320
  parsed_headers = {}
321
+ # Basic Auth: encode credentials automatically if provided.
322
+ if username or password:
323
+ creds = _b64.b64encode(f"{username}:{password}".encode()).decode()
324
+ parsed_headers["Authorization"] = f"Basic {creds}"
300
325
  if headers:
301
326
  try:
302
- parsed_headers = json.loads(headers)
327
+ parsed_headers.update(json.loads(headers))
303
328
  except Exception: # noqa: BLE001
304
329
  pass
305
330
  url_key = f"{method.upper()}:{url}"
@@ -322,6 +347,9 @@ def run_agent_chat(cfg):
322
347
  "Try a DIFFERENT URL or use Python's datetime/math/etc. module instead."
323
348
  )
324
349
  status_line = result.split("\n")[0][:150] if result else "no response"
350
+ # Append a success tag to 2xx responses so the model knows to stop and call final_answer.
351
+ if result and result.startswith("HTTP 2"):
352
+ result = result + "\n[SUCCESS — call final_answer(response) now, do not parse or retry]"
325
353
  _emit({"type": "step", "text": f"HTTP {method.upper()} {url} → {status_line}"})
326
354
  _log(f"http_request {method.upper()} {url} → {result[:80]}")
327
355
  return result
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tiens.nguyen/gonext-local-worker",
3
- "version": "1.0.77",
3
+ "version": "1.0.79",
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",