opencode-auto-resume 1.0.3 → 1.0.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 +15 -4
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -203,6 +203,8 @@ var AutoResumePlugin = async (ctx, options) => {
|
|
|
203
203
|
}
|
|
204
204
|
}
|
|
205
205
|
async function checkForToolCallAsText(sid, w) {
|
|
206
|
+
if (typeof sid !== "string" || !sid)
|
|
207
|
+
return;
|
|
206
208
|
if (w.userCancelled || w.toolTextRecovered)
|
|
207
209
|
return;
|
|
208
210
|
if (w.toolTextAttempts > 0) {
|
|
@@ -250,7 +252,7 @@ var AutoResumePlugin = async (ctx, options) => {
|
|
|
250
252
|
try {
|
|
251
253
|
await ctx.client.session.prompt({
|
|
252
254
|
path: { id: sid },
|
|
253
|
-
body: { agent: w.agent, parts: [{ type: "text", text: TOOL_TEXT_RECOVERY_PROMPT }] }
|
|
255
|
+
body: { agent: typeof w.agent === "string" ? w.agent : undefined, parts: [{ type: "text", text: TOOL_TEXT_RECOVERY_PROMPT }] }
|
|
254
256
|
});
|
|
255
257
|
recordContinue(sid);
|
|
256
258
|
w.lastRetryAt = Date.now();
|
|
@@ -273,7 +275,7 @@ var AutoResumePlugin = async (ctx, options) => {
|
|
|
273
275
|
try {
|
|
274
276
|
await ctx.client.session.prompt({
|
|
275
277
|
path: { id: sid },
|
|
276
|
-
body: { agent: w.agent, parts: [{ type: "text", text: "continue" }] }
|
|
278
|
+
body: { agent: typeof w.agent === "string" ? w.agent : undefined, parts: [{ type: "text", text: "continue" }] }
|
|
277
279
|
});
|
|
278
280
|
recordContinue(sid);
|
|
279
281
|
w.lastRetryAt = Date.now();
|
|
@@ -293,6 +295,8 @@ var AutoResumePlugin = async (ctx, options) => {
|
|
|
293
295
|
}
|
|
294
296
|
}
|
|
295
297
|
async function tryAbortAndResume(sid, w) {
|
|
298
|
+
if (typeof sid !== "string" || !sid)
|
|
299
|
+
return false;
|
|
296
300
|
if (w.aborting)
|
|
297
301
|
return false;
|
|
298
302
|
w.aborting = true;
|
|
@@ -313,7 +317,7 @@ var AutoResumePlugin = async (ctx, options) => {
|
|
|
313
317
|
try {
|
|
314
318
|
await ctx.client.session.prompt({
|
|
315
319
|
path: { id: sid },
|
|
316
|
-
body: { agent: w.agent, parts: [{ type: "text", text: "continue" }] }
|
|
320
|
+
body: { agent: typeof w.agent === "string" ? w.agent : undefined, parts: [{ type: "text", text: "continue" }] }
|
|
317
321
|
});
|
|
318
322
|
recordContinue(sid);
|
|
319
323
|
await log("info", `${short(sid)} - abort+continue done`);
|
|
@@ -330,6 +334,10 @@ var AutoResumePlugin = async (ctx, options) => {
|
|
|
330
334
|
}
|
|
331
335
|
}
|
|
332
336
|
async function tryResume(sid, w, reason) {
|
|
337
|
+
if (typeof sid !== "string" || !sid) {
|
|
338
|
+
await log("warn", `tryResume called with invalid sid: ${sid}`);
|
|
339
|
+
return false;
|
|
340
|
+
}
|
|
333
341
|
const now = Date.now();
|
|
334
342
|
const elapsedSinceRetry = now - w.lastRetryAt;
|
|
335
343
|
const requiredBackoff = backoffMs(w.resumeAttempts);
|
|
@@ -342,10 +350,11 @@ var AutoResumePlugin = async (ctx, options) => {
|
|
|
342
350
|
w.resumeAttempts++;
|
|
343
351
|
const idleSec = Math.round((now - w.lastActivityAt) / 1000);
|
|
344
352
|
await log("info", `${reason} on ${short(sid)} (${idleSec}s, retry ${w.resumeAttempts}/${maxRetries})`);
|
|
353
|
+
const agent = typeof w.agent === "string" ? w.agent : undefined;
|
|
345
354
|
try {
|
|
346
355
|
await ctx.client.session.prompt({
|
|
347
356
|
path: { id: sid },
|
|
348
|
-
body: { agent
|
|
357
|
+
body: { agent, model: true, parts: [{ type: "text", text: "continue" }] }
|
|
349
358
|
});
|
|
350
359
|
recordContinue(sid);
|
|
351
360
|
await log("info", `${short(sid)} - retry sent`);
|
|
@@ -359,6 +368,8 @@ var AutoResumePlugin = async (ctx, options) => {
|
|
|
359
368
|
}
|
|
360
369
|
}
|
|
361
370
|
async function getSessionAgent(sid) {
|
|
371
|
+
if (typeof sid !== "string" || !sid)
|
|
372
|
+
return;
|
|
362
373
|
try {
|
|
363
374
|
const response = await ctx.client.session.messages({
|
|
364
375
|
path: { id: sid }
|
package/package.json
CHANGED