opencode-auto-resume 1.0.2 → 1.0.3
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 +42 -6
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -250,7 +250,7 @@ var AutoResumePlugin = async (ctx, options) => {
|
|
|
250
250
|
try {
|
|
251
251
|
await ctx.client.session.prompt({
|
|
252
252
|
path: { id: sid },
|
|
253
|
-
body: { parts: [{ type: "text", text: TOOL_TEXT_RECOVERY_PROMPT }] }
|
|
253
|
+
body: { agent: w.agent, parts: [{ type: "text", text: TOOL_TEXT_RECOVERY_PROMPT }] }
|
|
254
254
|
});
|
|
255
255
|
recordContinue(sid);
|
|
256
256
|
w.lastRetryAt = Date.now();
|
|
@@ -273,7 +273,7 @@ var AutoResumePlugin = async (ctx, options) => {
|
|
|
273
273
|
try {
|
|
274
274
|
await ctx.client.session.prompt({
|
|
275
275
|
path: { id: sid },
|
|
276
|
-
body: { parts: [{ type: "text", text: "continue" }] }
|
|
276
|
+
body: { agent: w.agent, parts: [{ type: "text", text: "continue" }] }
|
|
277
277
|
});
|
|
278
278
|
recordContinue(sid);
|
|
279
279
|
w.lastRetryAt = Date.now();
|
|
@@ -313,7 +313,7 @@ var AutoResumePlugin = async (ctx, options) => {
|
|
|
313
313
|
try {
|
|
314
314
|
await ctx.client.session.prompt({
|
|
315
315
|
path: { id: sid },
|
|
316
|
-
body: { parts: [{ type: "text", text: "continue" }] }
|
|
316
|
+
body: { agent: w.agent, parts: [{ type: "text", text: "continue" }] }
|
|
317
317
|
});
|
|
318
318
|
recordContinue(sid);
|
|
319
319
|
await log("info", `${short(sid)} - abort+continue done`);
|
|
@@ -345,7 +345,7 @@ var AutoResumePlugin = async (ctx, options) => {
|
|
|
345
345
|
try {
|
|
346
346
|
await ctx.client.session.prompt({
|
|
347
347
|
path: { id: sid },
|
|
348
|
-
body: { parts: [{ type: "text", text: "continue" }] }
|
|
348
|
+
body: { agent: w.agent, model: true, parts: [{ type: "text", text: "continue" }] }
|
|
349
349
|
});
|
|
350
350
|
recordContinue(sid);
|
|
351
351
|
await log("info", `${short(sid)} - retry sent`);
|
|
@@ -358,6 +358,32 @@ var AutoResumePlugin = async (ctx, options) => {
|
|
|
358
358
|
return false;
|
|
359
359
|
}
|
|
360
360
|
}
|
|
361
|
+
async function getSessionAgent(sid) {
|
|
362
|
+
try {
|
|
363
|
+
const response = await ctx.client.session.messages({
|
|
364
|
+
path: { id: sid }
|
|
365
|
+
});
|
|
366
|
+
const data = response;
|
|
367
|
+
let messages = [];
|
|
368
|
+
if (Array.isArray(data)) {
|
|
369
|
+
messages = data;
|
|
370
|
+
} else if (Array.isArray(data.data)) {
|
|
371
|
+
messages = data.data;
|
|
372
|
+
} else if (Array.isArray(data.messages)) {
|
|
373
|
+
messages = data.messages;
|
|
374
|
+
}
|
|
375
|
+
for (let i = messages.length - 1;i >= 0; i--) {
|
|
376
|
+
const msg = messages[i];
|
|
377
|
+
const role = msg.role;
|
|
378
|
+
if (role === "assistant") {
|
|
379
|
+
const agent = msg.agent;
|
|
380
|
+
if (agent)
|
|
381
|
+
return agent;
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
} catch {}
|
|
385
|
+
return;
|
|
386
|
+
}
|
|
361
387
|
async function discoverSessions() {
|
|
362
388
|
try {
|
|
363
389
|
const response = await ctx.client.session.list();
|
|
@@ -370,7 +396,8 @@ var AutoResumePlugin = async (ctx, options) => {
|
|
|
370
396
|
}
|
|
371
397
|
for (const s of list) {
|
|
372
398
|
const sid = s.id;
|
|
373
|
-
if (sid
|
|
399
|
+
if (sid) {
|
|
400
|
+
const isNew = !sessions.has(sid);
|
|
374
401
|
ensureWatch(sid);
|
|
375
402
|
const status = s.status;
|
|
376
403
|
if (status) {
|
|
@@ -379,7 +406,16 @@ var AutoResumePlugin = async (ctx, options) => {
|
|
|
379
406
|
if (status === "idle")
|
|
380
407
|
w.idleSince = Date.now();
|
|
381
408
|
}
|
|
382
|
-
|
|
409
|
+
if (isNew) {
|
|
410
|
+
const agent = await getSessionAgent(sid);
|
|
411
|
+
if (agent) {
|
|
412
|
+
const w = sessions.get(sid);
|
|
413
|
+
w.agent = agent;
|
|
414
|
+
log("debug", `Discovered session ${short(sid)} with agent: ${agent}`);
|
|
415
|
+
} else {
|
|
416
|
+
log("debug", `Discovered session ${short(sid)} via list()`);
|
|
417
|
+
}
|
|
418
|
+
}
|
|
383
419
|
}
|
|
384
420
|
}
|
|
385
421
|
} catch (err) {
|
package/package.json
CHANGED