open-agents-ai 0.185.80 → 0.185.82

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.
Files changed (2) hide show
  1. package/dist/index.js +114 -92
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -66205,7 +66205,12 @@ var init_web_ui = __esm({
66205
66205
  });
66206
66206
 
66207
66207
  // packages/cli/dist/api/logger.js
66208
+ function setQuiet(quiet) {
66209
+ _quiet = quiet;
66210
+ }
66208
66211
  function log(level, fields) {
66212
+ if (_quiet)
66213
+ return;
66209
66214
  if (LEVEL_NUM[level] > LEVEL_NUM[configuredLevel])
66210
66215
  return;
66211
66216
  if (useJson) {
@@ -66221,7 +66226,7 @@ function log(level, fields) {
66221
66226
  function logRequest(fields) {
66222
66227
  log("info", fields);
66223
66228
  }
66224
- var LEVEL_NUM, configuredLevel, useJson;
66229
+ var LEVEL_NUM, configuredLevel, useJson, _quiet;
66225
66230
  var init_logger = __esm({
66226
66231
  "packages/cli/dist/api/logger.js"() {
66227
66232
  "use strict";
@@ -66233,6 +66238,7 @@ var init_logger = __esm({
66233
66238
  return "info";
66234
66239
  })();
66235
66240
  useJson = (process.env["OA_LOG_FORMAT"] || "json").toLowerCase() !== "text";
66241
+ _quiet = false;
66236
66242
  }
66237
66243
  });
66238
66244
 
@@ -66405,10 +66411,6 @@ function addAssistantMessage(session, content) {
66405
66411
  session.messages.push({ role: "assistant", content });
66406
66412
  session.lastActivity = Date.now();
66407
66413
  }
66408
- function trackSessionTokens(session, tokensIn, tokensOut) {
66409
- session.tokensIn += tokensIn;
66410
- session.tokensOut += tokensOut;
66411
- }
66412
66414
  function listSessions() {
66413
66415
  return Array.from(sessions.values()).map((s) => ({
66414
66416
  id: s.id,
@@ -67927,18 +67929,43 @@ async function handleRequest(req, res, ollamaUrl, verbose) {
67927
67929
  }
67928
67930
  const sessionId = chatBody.session_id;
67929
67931
  const model = chatBody.model || loadConfig().model;
67930
- const session = getSession(sessionId, model, resolve31(process.cwd()));
67931
- const messages = addUserMessage(session, chatBody.message);
67932
+ const cwdPath = resolve31(process.cwd());
67933
+ const session = getSession(sessionId, model, cwdPath);
67934
+ addUserMessage(session, chatBody.message);
67932
67935
  compactSession(session);
67936
+ const historyLines = session.messages.filter((m) => m.role !== "system").slice(-10).map((m) => m.role === "user" ? `User: ${m.content}` : `Assistant: ${m.content}`).join("\n");
67937
+ const taskPrompt = `You are in a conversational chat session. Respond naturally and helpfully.
67938
+ Use your tools (web_search, web_fetch, file_read, shell, memory_read, etc.) when the user's request requires real data.
67939
+ If the user asks about current events, news, or real-time data \u2014 use web_search to find it.
67940
+ If the user asks about files or code \u2014 use file_read.
67941
+ If the user asks you to run something \u2014 use shell.
67942
+ NEVER say "I don't have browsing capabilities" \u2014 you DO have web_search and web_fetch.
67943
+ NEVER say "I'm just an AI" \u2014 you are Open Agent with full tool access.
67944
+
67945
+ ` + (historyLines ? `Previous conversation:
67946
+ ${historyLines}
67947
+
67948
+ ` : "") + `User's latest message: ${chatBody.message}
67949
+
67950
+ Respond conversationally. Call task_complete with your response when done.`;
67951
+ const oaBin = process.argv[1] || "oa";
67952
+ const args = [taskPrompt, "--json", "--non-interactive"];
67953
+ if (model)
67954
+ args.push("--model", model.replace(/^local\//, ""));
67933
67955
  const streamMode = chatBody.stream !== false;
67934
- const chatRequest = {
67935
- model: session.model,
67936
- messages,
67937
- stream: streamMode,
67938
- max_tokens: chatBody.max_tokens || 4096
67956
+ const runEnv = {
67957
+ ...process.env,
67958
+ __OPEN_AGENTS_NO_AUTO_RUN: "",
67959
+ OA_RUN_USER: req._authUser || "anonymous",
67960
+ OA_RUN_SCOPE: req._authScope || "admin"
67939
67961
  };
67940
- const route = resolveModelEndpoint(session.model);
67941
- const targetUrl = route?.endpoint?.url || loadConfig().backendUrl;
67962
+ const child = spawn21("oa", args, {
67963
+ cwd: cwdPath,
67964
+ env: runEnv,
67965
+ stdio: ["ignore", "pipe", "pipe"],
67966
+ detached: true
67967
+ });
67968
+ child.unref();
67942
67969
  if (streamMode) {
67943
67970
  res.writeHead(200, {
67944
67971
  "Content-Type": "text/event-stream",
@@ -67947,86 +67974,79 @@ async function handleRequest(req, res, ollamaUrl, verbose) {
67947
67974
  "X-Session-ID": session.id
67948
67975
  });
67949
67976
  let fullContent = "";
67950
- try {
67951
- const url = new URL("/api/chat", targetUrl);
67952
- const isHttps = url.protocol === "https:";
67953
- const transport = isHttps ? https : http;
67954
- const reqBody = JSON.stringify({
67955
- model: session.model.replace(/^local\//, ""),
67956
- messages: messages.map((m) => ({ role: m.role, content: m.content })),
67957
- stream: true
67958
- });
67959
- await new Promise((resolve36, reject) => {
67960
- const proxyReq = transport.request({
67961
- hostname: url.hostname,
67962
- port: url.port || (isHttps ? 443 : 80),
67963
- path: url.pathname,
67964
- method: "POST",
67965
- headers: { "Content-Type": "application/json", "Content-Length": Buffer.byteLength(reqBody) }
67966
- }, (proxyRes) => {
67967
- let buffer = "";
67968
- proxyRes.on("data", (chunk) => {
67969
- buffer += chunk.toString();
67970
- const lines = buffer.split("\n");
67971
- buffer = lines.pop() || "";
67972
- for (const line of lines) {
67973
- if (!line.trim())
67974
- continue;
67975
- try {
67976
- const parsed = JSON.parse(line);
67977
- if (parsed.message?.content) {
67978
- fullContent += parsed.message.content;
67979
- const sseChunk = {
67980
- id: `chatcmpl-${session.id.slice(0, 8)}`,
67981
- object: "chat.completion.chunk",
67982
- choices: [{ index: 0, delta: { content: parsed.message.content }, finish_reason: null }]
67983
- };
67984
- res.write("data: " + JSON.stringify(sseChunk) + "\n\n");
67985
- }
67986
- if (parsed.done) {
67987
- trackSessionTokens(session, parsed.prompt_eval_count ?? 0, parsed.eval_count ?? 0);
67988
- trackTokens("local", parsed.prompt_eval_count ?? 0, parsed.eval_count ?? 0);
67989
- metrics.totalTokensIn += parsed.prompt_eval_count ?? 0;
67990
- metrics.totalTokensOut += parsed.eval_count ?? 0;
67991
- res.write("data: [DONE]\n\n");
67992
- }
67993
- } catch {
67994
- }
67995
- }
67996
- });
67997
- proxyRes.on("end", resolve36);
67998
- proxyRes.on("error", reject);
67999
- });
68000
- proxyReq.setTimeout(12e4, () => proxyReq.destroy(new Error("Chat stream timeout")));
68001
- proxyReq.on("error", reject);
68002
- proxyReq.write(reqBody);
68003
- proxyReq.end();
68004
- });
68005
- } catch (e) {
68006
- res.write("data: " + JSON.stringify({ error: e.message }) + "\n\n");
68007
- }
68008
- addAssistantMessage(session, fullContent);
68009
- res.end();
67977
+ let lastOutput = "";
67978
+ child.stdout?.on("data", (chunk) => {
67979
+ const text = chunk.toString();
67980
+ for (const line of text.split("\n")) {
67981
+ if (!line.trim())
67982
+ continue;
67983
+ try {
67984
+ const evt = JSON.parse(line);
67985
+ if (evt.type === "assistant_text" || evt.type === "text") {
67986
+ const delta = evt.content || evt.text || "";
67987
+ fullContent += delta;
67988
+ res.write("data: " + JSON.stringify({
67989
+ id: `chatcmpl-${session.id.slice(0, 8)}`,
67990
+ object: "chat.completion.chunk",
67991
+ choices: [{ index: 0, delta: { content: delta }, finish_reason: null }]
67992
+ }) + "\n\n");
67993
+ } else if (evt.type === "tool_call") {
67994
+ res.write("data: " + JSON.stringify({
67995
+ type: "tool_call",
67996
+ tool: evt.tool || evt.name,
67997
+ args: evt.args
67998
+ }) + "\n\n");
67999
+ } else if (evt.type === "task_complete") {
68000
+ const summary = evt.summary || evt.content || "";
68001
+ if (summary && !fullContent.includes(summary))
68002
+ fullContent += summary;
68003
+ }
68004
+ lastOutput = line;
68005
+ } catch {
68006
+ if (line.trim() && !line.startsWith("{")) {
68007
+ fullContent += line;
68008
+ res.write("data: " + JSON.stringify({
68009
+ id: `chatcmpl-${session.id.slice(0, 8)}`,
68010
+ object: "chat.completion.chunk",
68011
+ choices: [{ index: 0, delta: { content: line }, finish_reason: null }]
68012
+ }) + "\n\n");
68013
+ }
68014
+ }
68015
+ }
68016
+ });
68017
+ child.stderr?.on("data", () => {
68018
+ });
68019
+ child.on("close", () => {
68020
+ addAssistantMessage(session, fullContent);
68021
+ res.write("data: [DONE]\n\n");
68022
+ res.end();
68023
+ });
68010
68024
  } else {
68011
- try {
68012
- const result = await ollamaRequest(targetUrl, "/api/chat", "POST", JSON.stringify({
68013
- model: session.model.replace(/^local\//, ""),
68014
- messages: messages.map((m) => ({ role: m.role, content: m.content })),
68015
- stream: false
68016
- }));
68017
- const parsed = JSON.parse(result.body);
68018
- const content = parsed.message?.content ?? "";
68019
- addAssistantMessage(session, content);
68020
- trackSessionTokens(session, parsed.prompt_eval_count ?? 0, parsed.eval_count ?? 0);
68021
- trackTokens("local", parsed.prompt_eval_count ?? 0, parsed.eval_count ?? 0);
68022
- jsonResponse(res, 200, {
68023
- session_id: session.id,
68024
- message: { role: "assistant", content },
68025
- usage: { prompt_tokens: parsed.prompt_eval_count ?? 0, completion_tokens: parsed.eval_count ?? 0 }
68026
- });
68027
- } catch (e) {
68028
- jsonResponse(res, 500, { error: "Chat failed", message: e.message });
68025
+ let output = "";
68026
+ child.stdout?.on("data", (chunk) => {
68027
+ output += chunk.toString();
68028
+ });
68029
+ child.stderr?.on("data", () => {
68030
+ });
68031
+ await new Promise((resolve36) => child.on("close", resolve36));
68032
+ let content = "";
68033
+ for (const line of output.split("\n")) {
68034
+ try {
68035
+ const evt = JSON.parse(line);
68036
+ if (evt.type === "assistant_text" || evt.type === "text")
68037
+ content += evt.content || evt.text || "";
68038
+ else if (evt.type === "task_complete")
68039
+ content += evt.summary || evt.content || "";
68040
+ } catch {
68041
+ if (line.trim() && !line.startsWith("{"))
68042
+ content += line + "\n";
68043
+ }
68029
68044
  }
68045
+ addAssistantMessage(session, content.trim());
68046
+ jsonResponse(res, 200, {
68047
+ session_id: session.id,
68048
+ message: { role: "assistant", content: content.trim() }
68049
+ });
68030
68050
  }
68031
68051
  return;
68032
68052
  }
@@ -68234,6 +68254,8 @@ async function handleRequest(req, res, ollamaUrl, verbose) {
68234
68254
  }
68235
68255
  }
68236
68256
  function startApiServer(options = {}) {
68257
+ if (options.quiet)
68258
+ setQuiet(true);
68237
68259
  const log2 = options.quiet ? (_msg) => {
68238
68260
  } : (msg) => process.stderr.write(msg);
68239
68261
  let host = "127.0.0.1";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "open-agents-ai",
3
- "version": "0.185.80",
3
+ "version": "0.185.82",
4
4
  "description": "AI coding agent powered by open-source models (Ollama/vLLM) — interactive TUI with agentic tool-calling loop",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",