open-agents-ai 0.187.585 → 0.187.586
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 +77 -62
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -591008,31 +591008,27 @@ function formatTelegramProgressEvent(event) {
|
|
|
591008
591008
|
if (event.type === "tool_call" && event.toolName === "task_complete") return null;
|
|
591009
591009
|
if (event.type === "tool_result" && event.toolName === "task_complete") return null;
|
|
591010
591010
|
if (event.type === "tool_call") {
|
|
591011
|
-
return
|
|
591011
|
+
return `Using ${escapeTelegramHTML(event.toolName || "tool")}`;
|
|
591012
591012
|
}
|
|
591013
591013
|
if (event.type === "tool_result") {
|
|
591014
|
-
const icon = event.success ? "✔" : "✘";
|
|
591015
591014
|
const preview = sanitizeTelegramProgressText(event.content || "", 80);
|
|
591016
|
-
const
|
|
591017
|
-
return `${
|
|
591015
|
+
const toolName = escapeTelegramHTML(event.toolName || "tool");
|
|
591016
|
+
if (preview) return `${toolName}: ${escapeTelegramHTML(preview)}`;
|
|
591017
|
+
return event.success ? `${toolName} completed` : `${toolName} failed`;
|
|
591018
591018
|
}
|
|
591019
591019
|
if (event.type === "status") {
|
|
591020
591020
|
const content = sanitizeTelegramProgressText(event.content || "", 120);
|
|
591021
|
-
return content ?
|
|
591021
|
+
return content ? escapeTelegramHTML(content) : null;
|
|
591022
591022
|
}
|
|
591023
591023
|
return null;
|
|
591024
591024
|
}
|
|
591025
591025
|
function renderTelegramLiveProgressHTML(progressLines, accumulated) {
|
|
591026
|
-
const
|
|
591027
|
-
|
|
591028
|
-
|
|
591029
|
-
|
|
591030
|
-
|
|
591031
|
-
|
|
591032
|
-
${convertMarkdownToTelegramHTML(draft)}
|
|
591033
|
-
<i>▌</i>` : "\n\n<i>Working...</i>";
|
|
591034
|
-
return `<b>✈ Working on this...</b>
|
|
591035
|
-
${progressBlock}${draftBlock}`;
|
|
591026
|
+
const draft = stripTelegramHiddenThinking(accumulated).trim();
|
|
591027
|
+
if (draft) {
|
|
591028
|
+
const clipped = draft.length > 2e3 ? `${draft.slice(0, 1997).trimEnd()}...` : draft;
|
|
591029
|
+
return convertMarkdownToTelegramHTML(clipped);
|
|
591030
|
+
}
|
|
591031
|
+
return progressLines.slice(-6).map((line) => line.trim()).filter(Boolean).join("\n");
|
|
591036
591032
|
}
|
|
591037
591033
|
function normalizeTelegramChatId(value2) {
|
|
591038
591034
|
if (typeof value2 === "number" || typeof value2 === "string") return value2;
|
|
@@ -592058,6 +592054,7 @@ Join: ${newUrl}`);
|
|
|
592058
592054
|
runner: null,
|
|
592059
592055
|
typingInterval: null,
|
|
592060
592056
|
liveMessageId: null,
|
|
592057
|
+
liveMessagePromise: null,
|
|
592061
592058
|
accumulated: "",
|
|
592062
592059
|
assistantText: "",
|
|
592063
592060
|
streamText: "",
|
|
@@ -592080,14 +592077,6 @@ Join: ${newUrl}`);
|
|
|
592080
592077
|
}
|
|
592081
592078
|
this.tuiWrite(() => renderTelegramSubAgentStart(msg.username, msg.text, isAdminDM));
|
|
592082
592079
|
try {
|
|
592083
|
-
if (!msg.guestQueryId) {
|
|
592084
|
-
const msgId = await this.sendLiveMessage(
|
|
592085
|
-
msg.chatId,
|
|
592086
|
-
renderTelegramLiveProgressHTML([], ""),
|
|
592087
|
-
msg.chatType !== "private" ? msg.messageId : void 0
|
|
592088
|
-
);
|
|
592089
|
-
subAgent.liveMessageId = msgId;
|
|
592090
|
-
}
|
|
592091
592080
|
let mediaContext = "";
|
|
592092
592081
|
if (msg.media) {
|
|
592093
592082
|
mediaContext = await this.processMedia(msg);
|
|
@@ -592108,6 +592097,10 @@ Join: ${newUrl}`);
|
|
|
592108
592097
|
return;
|
|
592109
592098
|
}
|
|
592110
592099
|
const finalText = stripTelegramHiddenThinking(result || "").trim() || "I couldn't generate a response. Please try again.";
|
|
592100
|
+
if (subAgent.liveMessagePromise) {
|
|
592101
|
+
await subAgent.liveMessagePromise.catch(() => {
|
|
592102
|
+
});
|
|
592103
|
+
}
|
|
592111
592104
|
this.recordChatHistory(sessionKey, { role: "user", text: msg.text, mode: "action" });
|
|
592112
592105
|
this.recordChatHistory(sessionKey, { role: "assistant", text: finalText, mode: "action" });
|
|
592113
592106
|
const finalHtml = convertMarkdownToTelegramHTML(finalText);
|
|
@@ -592132,7 +592125,7 @@ Join: ${newUrl}`);
|
|
|
592132
592125
|
this.subAgentViewCallbacks?.onWrite(subAgent.viewId, `error: ${errMsg}`);
|
|
592133
592126
|
this.subAgentViewCallbacks?.onStatus(subAgent.viewId, "failed");
|
|
592134
592127
|
if (subAgent.liveMessageId && !msg.guestQueryId) {
|
|
592135
|
-
await this.editLiveMessage(msg.chatId, subAgent.liveMessageId,
|
|
592128
|
+
await this.editLiveMessage(msg.chatId, subAgent.liveMessageId, `Error: ${errMsg}`).catch(() => {
|
|
592136
592129
|
});
|
|
592137
592130
|
} else {
|
|
592138
592131
|
await this.replyToTelegramMessage(msg, "Sorry, I encountered an error processing your message. Please try again.").catch(() => {
|
|
@@ -592154,10 +592147,11 @@ Join: ${newUrl}`);
|
|
|
592154
592147
|
runner: null,
|
|
592155
592148
|
typingInterval: null,
|
|
592156
592149
|
liveMessageId: null,
|
|
592150
|
+
liveMessagePromise: null,
|
|
592157
592151
|
accumulated: "",
|
|
592158
592152
|
assistantText: "",
|
|
592159
592153
|
streamText: "",
|
|
592160
|
-
intermediateLines: [
|
|
592154
|
+
intermediateLines: [],
|
|
592161
592155
|
lastEditMs: 0,
|
|
592162
592156
|
aborted: false,
|
|
592163
592157
|
toolContext,
|
|
@@ -592178,13 +592172,6 @@ Join: ${newUrl}`);
|
|
|
592178
592172
|
}
|
|
592179
592173
|
this.tuiWrite(() => renderTelegramSubAgentEvent(msg.username, `admin chat with full context/tools (${this.interactionMode})`));
|
|
592180
592174
|
try {
|
|
592181
|
-
if (!msg.guestQueryId) {
|
|
592182
|
-
subAgent.liveMessageId = await this.sendLiveMessage(
|
|
592183
|
-
msg.chatId,
|
|
592184
|
-
renderTelegramLiveProgressHTML(subAgent.intermediateLines, ""),
|
|
592185
|
-
msg.chatType !== "private" ? msg.messageId : void 0
|
|
592186
|
-
);
|
|
592187
|
-
}
|
|
592188
592175
|
let mediaContext = "";
|
|
592189
592176
|
if (msg.media) {
|
|
592190
592177
|
mediaContext = await this.processMedia(msg);
|
|
@@ -592195,6 +592182,10 @@ Join: ${newUrl}`);
|
|
|
592195
592182
|
subAgent.typingInterval = null;
|
|
592196
592183
|
}
|
|
592197
592184
|
const finalText = stripTelegramHiddenThinking(result || "").trim() || "I heard you.";
|
|
592185
|
+
if (subAgent.liveMessagePromise) {
|
|
592186
|
+
await subAgent.liveMessagePromise.catch(() => {
|
|
592187
|
+
});
|
|
592188
|
+
}
|
|
592198
592189
|
this.recordChatHistory(sessionKey, { role: "user", text: msg.text, mode: "chat" });
|
|
592199
592190
|
this.recordChatHistory(sessionKey, { role: "assistant", text: finalText, mode: "chat" });
|
|
592200
592191
|
const finalHtml = convertMarkdownToTelegramHTML(finalText);
|
|
@@ -592218,7 +592209,7 @@ Join: ${newUrl}`);
|
|
|
592218
592209
|
this.subAgentViewCallbacks?.onWrite(subAgent.viewId, `error: ${errMsg}`);
|
|
592219
592210
|
this.subAgentViewCallbacks?.onStatus(subAgent.viewId, "failed");
|
|
592220
592211
|
if (subAgent.liveMessageId && !msg.guestQueryId) {
|
|
592221
|
-
await this.editLiveMessage(msg.chatId, subAgent.liveMessageId,
|
|
592212
|
+
await this.editLiveMessage(msg.chatId, subAgent.liveMessageId, `Error: ${escapeTelegramHTML(errMsg)}`).catch(() => {
|
|
592222
592213
|
});
|
|
592223
592214
|
} else {
|
|
592224
592215
|
await this.replyToTelegramMessage(msg, "Sorry, I couldn't process that Telegram chat message.").catch(() => {
|
|
@@ -592247,7 +592238,8 @@ Join: ${newUrl}`);
|
|
|
592247
592238
|
let accumulated = "";
|
|
592248
592239
|
let lastEditMs = 0;
|
|
592249
592240
|
let lastViewWriteMs = 0;
|
|
592250
|
-
|
|
592241
|
+
let liveMessagePromise = null;
|
|
592242
|
+
const progressLines = [];
|
|
592251
592243
|
this.activeChatViews.add(viewId);
|
|
592252
592244
|
this.refreshActiveTelegramInteractionCount();
|
|
592253
592245
|
this.subAgentViewCallbacks?.onRegister(
|
|
@@ -592263,19 +592255,12 @@ Join: ${newUrl}`);
|
|
|
592263
592255
|
}
|
|
592264
592256
|
this.tuiWrite(() => renderTelegramSubAgentEvent(msg.username, `chat-mode fast reply (${this.interactionMode})`));
|
|
592265
592257
|
try {
|
|
592266
|
-
if (!msg.guestQueryId) {
|
|
592267
|
-
liveMessageId = await this.sendLiveMessage(
|
|
592268
|
-
msg.chatId,
|
|
592269
|
-
renderTelegramLiveProgressHTML(progressLines, ""),
|
|
592270
|
-
msg.chatType !== "private" ? msg.messageId : void 0
|
|
592271
|
-
);
|
|
592272
|
-
}
|
|
592273
592258
|
const mediaContext = msg.media || msg.livePhoto ? "Attachment received. Quick-chat mode does not inspect media; use action mode for media analysis." : "";
|
|
592274
592259
|
const finalText = await this.runTelegramChatCompletion(
|
|
592275
592260
|
msg,
|
|
592276
592261
|
toolContext,
|
|
592277
592262
|
mediaContext,
|
|
592278
|
-
(nextText) => {
|
|
592263
|
+
async (nextText) => {
|
|
592279
592264
|
accumulated = nextText;
|
|
592280
592265
|
const now = Date.now();
|
|
592281
592266
|
if (now - lastViewWriteMs > 900) {
|
|
@@ -592284,12 +592269,28 @@ Join: ${newUrl}`);
|
|
|
592284
592269
|
}
|
|
592285
592270
|
if (liveMessageId && !msg.guestQueryId && now - lastEditMs > 900) {
|
|
592286
592271
|
lastEditMs = now;
|
|
592287
|
-
this.editLiveMessage(
|
|
592272
|
+
await this.editLiveMessage(
|
|
592288
592273
|
msg.chatId,
|
|
592289
592274
|
liveMessageId,
|
|
592290
592275
|
renderTelegramLiveProgressHTML(progressLines, accumulated)
|
|
592291
592276
|
).catch(() => {
|
|
592292
592277
|
});
|
|
592278
|
+
} else if (!liveMessageId && !liveMessagePromise && !msg.guestQueryId) {
|
|
592279
|
+
const html = renderTelegramLiveProgressHTML(progressLines, accumulated);
|
|
592280
|
+
if (html.trim()) {
|
|
592281
|
+
liveMessagePromise = this.sendLiveMessage(
|
|
592282
|
+
msg.chatId,
|
|
592283
|
+
html,
|
|
592284
|
+
msg.chatType !== "private" ? msg.messageId : void 0
|
|
592285
|
+
).then((id) => {
|
|
592286
|
+
liveMessageId = id;
|
|
592287
|
+
lastEditMs = Date.now();
|
|
592288
|
+
}).catch(() => {
|
|
592289
|
+
}).finally(() => {
|
|
592290
|
+
liveMessagePromise = null;
|
|
592291
|
+
});
|
|
592292
|
+
await liveMessagePromise;
|
|
592293
|
+
}
|
|
592293
592294
|
}
|
|
592294
592295
|
}
|
|
592295
592296
|
);
|
|
@@ -592298,6 +592299,11 @@ Join: ${newUrl}`);
|
|
|
592298
592299
|
typingInterval = null;
|
|
592299
592300
|
}
|
|
592300
592301
|
const cleaned = stripTelegramHiddenThinking(finalText || accumulated).trim() || "I heard you.";
|
|
592302
|
+
const pendingLiveMessage = liveMessagePromise;
|
|
592303
|
+
if (pendingLiveMessage) {
|
|
592304
|
+
await pendingLiveMessage.catch(() => {
|
|
592305
|
+
});
|
|
592306
|
+
}
|
|
592301
592307
|
this.recordChatHistory(sessionKey, { role: "user", text: msg.text, mode: "chat" });
|
|
592302
592308
|
this.recordChatHistory(sessionKey, { role: "assistant", text: cleaned, mode: "chat" });
|
|
592303
592309
|
const finalHtml = convertMarkdownToTelegramHTML(cleaned);
|
|
@@ -592321,7 +592327,7 @@ Join: ${newUrl}`);
|
|
|
592321
592327
|
this.subAgentViewCallbacks?.onWrite(viewId, `error: ${errMsg}`);
|
|
592322
592328
|
this.subAgentViewCallbacks?.onStatus(viewId, "failed");
|
|
592323
592329
|
if (liveMessageId && !msg.guestQueryId) {
|
|
592324
|
-
await this.editLiveMessage(msg.chatId, liveMessageId,
|
|
592330
|
+
await this.editLiveMessage(msg.chatId, liveMessageId, `Error: ${escapeTelegramHTML(errMsg)}`).catch(() => {
|
|
592325
592331
|
});
|
|
592326
592332
|
} else {
|
|
592327
592333
|
await this.replyToTelegramMessage(msg, "Sorry, I couldn't process that quick chat message.").catch(() => {
|
|
@@ -592391,14 +592397,14 @@ ${mediaContext}` : ""}`
|
|
|
592391
592397
|
for await (const chunk of streamable.chatCompletionStream(request)) {
|
|
592392
592398
|
if (chunk.type === "content" && !chunk.thinking && chunk.content) {
|
|
592393
592399
|
accumulated += chunk.content;
|
|
592394
|
-
onToken(accumulated);
|
|
592400
|
+
await onToken(accumulated);
|
|
592395
592401
|
}
|
|
592396
592402
|
}
|
|
592397
592403
|
}
|
|
592398
592404
|
if (!accumulated.trim()) {
|
|
592399
592405
|
const result = await backend.chatCompletion(request);
|
|
592400
592406
|
accumulated = result.choices[0]?.message?.content ?? "";
|
|
592401
|
-
if (accumulated) onToken(accumulated);
|
|
592407
|
+
if (accumulated) await onToken(accumulated);
|
|
592402
592408
|
}
|
|
592403
592409
|
return stripTelegramHiddenThinking(accumulated).trim();
|
|
592404
592410
|
}
|
|
@@ -592456,26 +592462,35 @@ ${mediaContext}` : ""}`
|
|
|
592456
592462
|
} else if (event.type === "stream_end" && event.content) {
|
|
592457
592463
|
subAgent.streamText = event.content;
|
|
592458
592464
|
}
|
|
592459
|
-
if (
|
|
592460
|
-
|
|
592461
|
-
|
|
592462
|
-
|
|
592463
|
-
|
|
592464
|
-
|
|
592465
|
-
|
|
592466
|
-
|
|
592465
|
+
if (event.type === "stream_token" && event.streamKind === "content" && event.content) {
|
|
592466
|
+
subAgent.accumulated += event.content;
|
|
592467
|
+
}
|
|
592468
|
+
const intermediateLine = formatTelegramProgressEvent(event);
|
|
592469
|
+
if (intermediateLine) {
|
|
592470
|
+
subAgent.intermediateLines.push(intermediateLine);
|
|
592471
|
+
}
|
|
592472
|
+
if (!msg.guestQueryId) {
|
|
592473
|
+
const html = renderTelegramLiveProgressHTML(subAgent.intermediateLines, subAgent.accumulated);
|
|
592474
|
+
if (!html.trim()) return;
|
|
592467
592475
|
const now = Date.now();
|
|
592468
|
-
if (
|
|
592469
|
-
|
|
592470
|
-
if (hasContent) {
|
|
592476
|
+
if (subAgent.liveMessageId) {
|
|
592477
|
+
if (now - subAgent.lastEditMs > 1e3) {
|
|
592471
592478
|
subAgent.lastEditMs = now;
|
|
592472
|
-
this.editLiveMessage(
|
|
592473
|
-
msg.chatId,
|
|
592474
|
-
subAgent.liveMessageId,
|
|
592475
|
-
renderTelegramLiveProgressHTML(subAgent.intermediateLines, subAgent.accumulated)
|
|
592476
|
-
).catch(() => {
|
|
592479
|
+
this.editLiveMessage(msg.chatId, subAgent.liveMessageId, html).catch(() => {
|
|
592477
592480
|
});
|
|
592478
592481
|
}
|
|
592482
|
+
} else if (!subAgent.liveMessagePromise) {
|
|
592483
|
+
subAgent.liveMessagePromise = this.sendLiveMessage(
|
|
592484
|
+
msg.chatId,
|
|
592485
|
+
html,
|
|
592486
|
+
msg.chatType !== "private" ? msg.messageId : void 0
|
|
592487
|
+
).then((id) => {
|
|
592488
|
+
subAgent.liveMessageId = id;
|
|
592489
|
+
subAgent.lastEditMs = Date.now();
|
|
592490
|
+
}).catch(() => {
|
|
592491
|
+
}).finally(() => {
|
|
592492
|
+
subAgent.liveMessagePromise = null;
|
|
592493
|
+
});
|
|
592479
592494
|
}
|
|
592480
592495
|
}
|
|
592481
592496
|
});
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "open-agents-ai",
|
|
3
|
-
"version": "0.187.
|
|
3
|
+
"version": "0.187.586",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "open-agents-ai",
|
|
9
|
-
"version": "0.187.
|
|
9
|
+
"version": "0.187.586",
|
|
10
10
|
"hasInstallScript": true,
|
|
11
11
|
"license": "CC-BY-NC-4.0",
|
|
12
12
|
"dependencies": {
|
package/package.json
CHANGED