@openape/ape-agent 2.7.2 → 2.8.1
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/bridge.mjs +32 -4
- package/package.json +2 -2
package/dist/bridge.mjs
CHANGED
|
@@ -4117,7 +4117,7 @@ var CronRunner = class {
|
|
|
4117
4117
|
const contacts = await this.deps.chat.listContacts().catch(() => []);
|
|
4118
4118
|
const ownerLower = this.deps.ownerEmail.toLowerCase();
|
|
4119
4119
|
const room = contacts.find((c3) => c3.peerEmail.toLowerCase() === ownerLower && c3.connected && c3.roomId);
|
|
4120
|
-
if (!room?.roomId) {
|
|
4120
|
+
if (!spec.command && !room?.roomId) {
|
|
4121
4121
|
this.deps.log(`task ${spec.taskId} fired but no active owner room \u2014 skipping DM (accept the contact in chat)`);
|
|
4122
4122
|
return;
|
|
4123
4123
|
}
|
|
@@ -4141,11 +4141,34 @@ var CronRunner = class {
|
|
|
4141
4141
|
} catch (err) {
|
|
4142
4142
|
this.deps.log(`troop startRun ${spec.taskId} error: ${err instanceof Error ? err.message : String(err)}`);
|
|
4143
4143
|
}
|
|
4144
|
-
this.pending.set(sessionId, { taskId: spec.taskId, taskName: spec.name, accumulated: "", roomId: room
|
|
4144
|
+
this.pending.set(sessionId, { taskId: spec.taskId, taskName: spec.name, accumulated: "", roomId: room?.roomId ?? void 0, status: "pending", runId });
|
|
4145
4145
|
this.deps.log(`task ${spec.taskId} fired (session=${sessionId}, run=${runId ?? "no-troop"})`);
|
|
4146
4146
|
void this.runTask(sessionId, systemPrompt, spec);
|
|
4147
4147
|
}
|
|
4148
4148
|
async runTask(sessionId, systemPrompt, spec) {
|
|
4149
|
+
if (spec.command) {
|
|
4150
|
+
try {
|
|
4151
|
+
const res = await runApeShell(spec.command, 30 * 60 * 1e3);
|
|
4152
|
+
const turn = this.pending.get(sessionId);
|
|
4153
|
+
if (!turn) return;
|
|
4154
|
+
turn.status = res.exit_code === 0 ? "ok" : "error";
|
|
4155
|
+
turn.accumulated = `\`${spec.command}\` exited ${res.exit_code}
|
|
4156
|
+
|
|
4157
|
+
${(res.stdout || res.stderr).slice(0, 4e3)}`;
|
|
4158
|
+
await this.finaliseRun(turn, 1);
|
|
4159
|
+
await this.postResult(sessionId, turn);
|
|
4160
|
+
this.pending.delete(sessionId);
|
|
4161
|
+
} catch (err) {
|
|
4162
|
+
const turn = this.pending.get(sessionId);
|
|
4163
|
+
if (!turn) return;
|
|
4164
|
+
turn.status = "error";
|
|
4165
|
+
turn.accumulated = `(command error: ${err instanceof Error ? err.message : String(err)})`;
|
|
4166
|
+
await this.finaliseRun(turn, 0);
|
|
4167
|
+
await this.postResult(sessionId, turn);
|
|
4168
|
+
this.pending.delete(sessionId);
|
|
4169
|
+
}
|
|
4170
|
+
return;
|
|
4171
|
+
}
|
|
4149
4172
|
try {
|
|
4150
4173
|
const result = await runLoop({
|
|
4151
4174
|
config: this.deps.runtimeConfig,
|
|
@@ -4197,6 +4220,11 @@ var CronRunner = class {
|
|
|
4197
4220
|
}
|
|
4198
4221
|
}
|
|
4199
4222
|
async postResult(sid, turn) {
|
|
4223
|
+
if (!turn.roomId) {
|
|
4224
|
+
this.deps.log(`task ${turn.taskId} ran headless (no owner room) \u2014 DM skipped`);
|
|
4225
|
+
return;
|
|
4226
|
+
}
|
|
4227
|
+
const roomId = turn.roomId;
|
|
4200
4228
|
const prefix = turn.status === "error" ? "\u274C" : "\u2705";
|
|
4201
4229
|
const text = turn.accumulated.trim() || (turn.status === "error" ? "(crashed)" : "(no output)");
|
|
4202
4230
|
const body = `${prefix} *${turn.taskName}*
|
|
@@ -4205,7 +4233,7 @@ ${text}`.slice(0, 9e3);
|
|
|
4205
4233
|
let threadId = this.taskThreads.get(turn.taskId);
|
|
4206
4234
|
if (!threadId) {
|
|
4207
4235
|
try {
|
|
4208
|
-
const created = await this.deps.chat.createThread(
|
|
4236
|
+
const created = await this.deps.chat.createThread(roomId, turn.taskName || turn.taskId);
|
|
4209
4237
|
threadId = created.id;
|
|
4210
4238
|
this.taskThreads.set(turn.taskId, threadId);
|
|
4211
4239
|
this.persistTaskThreads();
|
|
@@ -4215,7 +4243,7 @@ ${text}`.slice(0, 9e3);
|
|
|
4215
4243
|
}
|
|
4216
4244
|
}
|
|
4217
4245
|
try {
|
|
4218
|
-
const posted = await this.deps.chat.postMessage(
|
|
4246
|
+
const posted = await this.deps.chat.postMessage(roomId, body, threadId ? { threadId } : {});
|
|
4219
4247
|
this.deps.log(`task DM posted (session=${sid}, ${turn.accumulated.length} chars, thread=${posted.threadId})`);
|
|
4220
4248
|
} catch (err) {
|
|
4221
4249
|
this.deps.log(`task DM post failed (session=${sid}): ${err instanceof Error ? err.message : String(err)}`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openape/ape-agent",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.8.1",
|
|
4
4
|
"description": "OpenApe agent runtime: per-agent process that connects to chat.openape.ai, runs the LLM loop with tools + cron tasks, and streams replies back to owners.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"ofetch": "^1.4.1",
|
|
24
24
|
"ws": "^8.18.0",
|
|
25
25
|
"yaml": "^2.8.0",
|
|
26
|
-
"@openape/apes": "1.
|
|
26
|
+
"@openape/apes": "1.28.1",
|
|
27
27
|
"@openape/cli-auth": "0.4.1",
|
|
28
28
|
"@openape/prompt-injection-detector": "0.1.0"
|
|
29
29
|
},
|