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

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.
@@ -204,18 +204,27 @@ def _summarize_result(task_text: str, agent_output: str,
204
204
  return agent_output
205
205
 
206
206
 
207
- def _plain_reply(task_text: str, base_url: str, api_key: str, model_id: str) -> str:
208
- """Plain chat completion without any tools."""
207
+ def _plain_reply(messages: list, base_url: str, api_key: str, model_id: str) -> str:
208
+ """Plain chat completion using the full conversation history."""
209
+ _THINK_RE_LOCAL = re.compile(r"<think>.*?</think>", re.DOTALL | re.IGNORECASE)
210
+ chat_messages = [{"role": "system", "content": "You are a helpful assistant."}]
211
+ for m in messages:
212
+ role = m.get("role", "")
213
+ content = m.get("content", "")
214
+ if role not in ("user", "assistant"):
215
+ continue
216
+ if role == "assistant":
217
+ content = _THINK_RE_LOCAL.sub("", content).strip()
218
+ if not content:
219
+ continue
220
+ chat_messages.append({"role": role, "content": content})
209
221
  try:
210
222
  from openai import OpenAI
211
223
  client = OpenAI(base_url=base_url, api_key=api_key or "local",
212
224
  max_retries=0, timeout=60)
213
225
  resp = client.chat.completions.create(
214
226
  model=model_id,
215
- messages=[
216
- {"role": "system", "content": "You are a helpful assistant."},
217
- {"role": "user", "content": task_text},
218
- ],
227
+ messages=chat_messages,
219
228
  temperature=0.7,
220
229
  max_tokens=512,
221
230
  )
@@ -239,16 +248,28 @@ def run_agent_chat(cfg):
239
248
 
240
249
  _log(f"start model={agent_model_id!r} base={agent_base_url!r} maxSteps={max_steps}")
241
250
 
242
- # Use only the latest user message as the agent task.
251
+ # Build task from the conversation history.
252
+ # Include prior USER messages as context so the agent has conversational memory,
253
+ # but exclude prior ASSISTANT messages (they contain raw HTTP/thinking content
254
+ # that confuses small models).
243
255
  task_text = ""
256
+ prior_user_msgs = []
244
257
  for m in messages:
245
- if m.get("role") == "user":
246
- task_text = m.get("content", "")
258
+ role = m.get("role", "")
259
+ content = m.get("content", "")
260
+ if role == "user":
261
+ if task_text:
262
+ prior_user_msgs.append(task_text)
263
+ task_text = content
247
264
 
248
265
  if not task_text:
249
266
  _emit({"type": "final", "text": "[No user message found in history]"})
250
267
  return
251
268
 
269
+ if prior_user_msgs:
270
+ context = "\n".join(f"- {t[:300]}" for t in prior_user_msgs[-4:])
271
+ task_text = f"Conversation context (previous user messages):\n{context}\n\nCurrent task: {task_text}"
272
+
252
273
  _log(f"task={task_text[:120]!r}")
253
274
 
254
275
  # Route: ask the model if this task needs HTTP tool use.
@@ -256,7 +277,7 @@ def run_agent_chat(cfg):
256
277
 
257
278
  if not needs_agent:
258
279
  _log("router: plain chat (no HTTP needed)")
259
- answer = _plain_reply(task_text, agent_base_url, agent_api_key, agent_model_id)
280
+ answer = _plain_reply(messages, agent_base_url, agent_api_key, agent_model_id)
260
281
  _log(f"plain reply: {len(answer)} chars")
261
282
  _emit({"type": "final", "text": answer})
262
283
  return
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tiens.nguyen/gonext-local-worker",
3
- "version": "1.0.78",
3
+ "version": "1.0.80",
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",