open-agents-ai 0.186.3 → 0.186.4
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.
- package/dist/index.js +28 -69
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -68116,89 +68116,46 @@ Respond conversationally. Call task_complete with your final response.`;
|
|
|
68116
68116
|
"X-Session-ID": session.id
|
|
68117
68117
|
});
|
|
68118
68118
|
let fullContent = "";
|
|
68119
|
-
let
|
|
68120
|
-
let toolCalls = [];
|
|
68121
|
-
let rawBuffer = "";
|
|
68119
|
+
let rawOutput = "";
|
|
68122
68120
|
child.stdout?.on("data", (chunk) => {
|
|
68123
|
-
|
|
68124
|
-
const lines = rawBuffer.split("\n");
|
|
68125
|
-
rawBuffer = lines.pop() || "";
|
|
68126
|
-
for (const line of lines) {
|
|
68127
|
-
if (!line.trim())
|
|
68128
|
-
continue;
|
|
68129
|
-
try {
|
|
68130
|
-
const evt = JSON.parse(line);
|
|
68131
|
-
if (evt.type === "tool_call" || evt.tool) {
|
|
68132
|
-
const toolInfo = { tool: evt.tool || evt.name || "unknown", args: evt.args };
|
|
68133
|
-
toolCalls.push(toolInfo);
|
|
68134
|
-
res.write("data: " + JSON.stringify({ type: "tool_call", ...toolInfo }) + "\n\n");
|
|
68135
|
-
} else if (evt.type === "tool_result") {
|
|
68136
|
-
const lastTool = toolCalls[toolCalls.length - 1];
|
|
68137
|
-
if (lastTool)
|
|
68138
|
-
lastTool.result = (evt.output || evt.result || "").slice(0, 500);
|
|
68139
|
-
res.write("data: " + JSON.stringify({ type: "tool_result", output: (evt.output || evt.result || "").slice(0, 200) }) + "\n\n");
|
|
68140
|
-
} else if (evt.type === "assistant_text" || evt.type === "text") {
|
|
68141
|
-
const delta = evt.content || evt.text || "";
|
|
68142
|
-
fullContent += delta;
|
|
68143
|
-
res.write("data: " + JSON.stringify({
|
|
68144
|
-
id: `chatcmpl-${session.id.slice(0, 8)}`,
|
|
68145
|
-
object: "chat.completion.chunk",
|
|
68146
|
-
choices: [{ index: 0, delta: { content: delta }, finish_reason: null }]
|
|
68147
|
-
}) + "\n\n");
|
|
68148
|
-
} else if (evt.status === "completed" || evt.type === "task_complete") {
|
|
68149
|
-
const summary = evt.summary || evt.content || "";
|
|
68150
|
-
const contentMatch = summary.match(/Tokens:\s*[\d,]+\s+(.*)/s);
|
|
68151
|
-
const cleanContent = contentMatch ? contentMatch[1].trim() : summary;
|
|
68152
|
-
if (cleanContent && cleanContent.length > 5) {
|
|
68153
|
-
fullContent = cleanContent;
|
|
68154
|
-
res.write("data: " + JSON.stringify({
|
|
68155
|
-
id: `chatcmpl-${session.id.slice(0, 8)}`,
|
|
68156
|
-
object: "chat.completion.chunk",
|
|
68157
|
-
choices: [{ index: 0, delta: { content: cleanContent }, finish_reason: null }]
|
|
68158
|
-
}) + "\n\n");
|
|
68159
|
-
}
|
|
68160
|
-
res.write("data: " + JSON.stringify({
|
|
68161
|
-
type: "complete",
|
|
68162
|
-
turns: evt.turns || summary.match(/(\d+) turns/)?.[1],
|
|
68163
|
-
toolCalls: toolCalls.length,
|
|
68164
|
-
tokens: evt.tokens || summary.match(/Tokens:\s*([\d,]+)/)?.[1],
|
|
68165
|
-
duration: evt.durationMs || evt.duration
|
|
68166
|
-
}) + "\n\n");
|
|
68167
|
-
}
|
|
68168
|
-
} catch {
|
|
68169
|
-
}
|
|
68170
|
-
}
|
|
68121
|
+
rawOutput += chunk.toString();
|
|
68171
68122
|
});
|
|
68172
68123
|
child.stderr?.on("data", () => {
|
|
68173
68124
|
});
|
|
68174
|
-
|
|
68175
|
-
|
|
68176
|
-
const allOutput = rawBuffer.trim();
|
|
68125
|
+
await new Promise((resolve36) => {
|
|
68126
|
+
child.on("close", () => {
|
|
68177
68127
|
try {
|
|
68178
|
-
const result = JSON.parse(
|
|
68128
|
+
const result = JSON.parse(rawOutput.trim());
|
|
68179
68129
|
let content = result.assistant_text || "";
|
|
68180
68130
|
if (!content) {
|
|
68181
68131
|
const summary = result.summary || "";
|
|
68182
|
-
const
|
|
68183
|
-
content =
|
|
68132
|
+
const match = summary.match(/Tokens:\s*[\d,]+\s+([\s\S]*)/);
|
|
68133
|
+
content = match ? match[1].trim() : summary;
|
|
68184
68134
|
}
|
|
68185
68135
|
fullContent = content;
|
|
68186
|
-
|
|
68187
|
-
|
|
68188
|
-
|
|
68189
|
-
|
|
68190
|
-
|
|
68136
|
+
if (content) {
|
|
68137
|
+
res.write("data: " + JSON.stringify({
|
|
68138
|
+
id: `chatcmpl-${session.id.slice(0, 8)}`,
|
|
68139
|
+
object: "chat.completion.chunk",
|
|
68140
|
+
choices: [{ index: 0, delta: { content }, finish_reason: null }]
|
|
68141
|
+
}) + "\n\n");
|
|
68142
|
+
}
|
|
68143
|
+
if (result.tool_calls?.length) {
|
|
68144
|
+
for (const tc of result.tool_calls) {
|
|
68145
|
+
res.write("data: " + JSON.stringify({ type: "tool_call", tool: tc.tool, args: tc.args }) + "\n\n");
|
|
68146
|
+
}
|
|
68147
|
+
}
|
|
68191
68148
|
const meta = result.summary || "";
|
|
68192
68149
|
res.write("data: " + JSON.stringify({
|
|
68193
68150
|
type: "complete",
|
|
68194
68151
|
turns: meta.match(/(\d+) turns/)?.[1],
|
|
68195
68152
|
tokens: meta.match(/Tokens:\s*([\d,]+)/)?.[1],
|
|
68196
|
-
toolCalls:
|
|
68153
|
+
toolCalls: result.tool_calls?.length || 0,
|
|
68197
68154
|
duration: result.durationMs
|
|
68198
68155
|
}) + "\n\n");
|
|
68199
68156
|
} catch {
|
|
68200
|
-
if (
|
|
68201
|
-
fullContent =
|
|
68157
|
+
if (rawOutput.trim()) {
|
|
68158
|
+
fullContent = rawOutput.trim().slice(0, 500);
|
|
68202
68159
|
res.write("data: " + JSON.stringify({
|
|
68203
68160
|
id: `chatcmpl-${session.id.slice(0, 8)}`,
|
|
68204
68161
|
object: "chat.completion.chunk",
|
|
@@ -68206,11 +68163,13 @@ Respond conversationally. Call task_complete with your final response.`;
|
|
|
68206
68163
|
}) + "\n\n");
|
|
68207
68164
|
}
|
|
68208
68165
|
}
|
|
68209
|
-
|
|
68210
|
-
|
|
68211
|
-
|
|
68212
|
-
|
|
68166
|
+
addAssistantMessage(session, fullContent);
|
|
68167
|
+
res.write("data: [DONE]\n\n");
|
|
68168
|
+
res.end();
|
|
68169
|
+
resolve36();
|
|
68170
|
+
});
|
|
68213
68171
|
});
|
|
68172
|
+
return;
|
|
68214
68173
|
} else {
|
|
68215
68174
|
let output = "";
|
|
68216
68175
|
child.stdout?.on("data", (chunk) => {
|
package/package.json
CHANGED