@commonlyai/cli 0.1.292 → 0.1.293
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/package.json +1 -1
- package/src/lib/adapters/pi.js +17 -3
package/package.json
CHANGED
package/src/lib/adapters/pi.js
CHANGED
|
@@ -56,6 +56,7 @@ import {
|
|
|
56
56
|
import { fileURLToPath } from 'url';
|
|
57
57
|
import {
|
|
58
58
|
adapterFailure,
|
|
59
|
+
describeUpstreamRefusal,
|
|
59
60
|
readUpstreamRefusal,
|
|
60
61
|
spawnCredentials,
|
|
61
62
|
} from '../upstream-refusal.js';
|
|
@@ -552,22 +553,27 @@ export const extractReply = (stdout) => {
|
|
|
552
553
|
if (event?.type === 'agent_end') finished = event.willRetry !== true && lastStop === 'stop';
|
|
553
554
|
if (event?.type === 'error') errors.push(String(event.message || event.error || 'error'));
|
|
554
555
|
}
|
|
555
|
-
return { text, sawAssistant, finished, errors };
|
|
556
|
+
return { text, sawAssistant, finished, lastStop, errors };
|
|
556
557
|
};
|
|
557
558
|
|
|
558
559
|
// A turn that printed an interim message and then ended without finishing. A
|
|
559
560
|
// crash keeps its cause, so a quota line in stderr or a refusal on the stream
|
|
560
561
|
// still classifies. A signal (143, 129, or a null code) has neither: stderr then
|
|
561
562
|
// holds pi's startup warnings, and a refusal on the stream may be one pi was
|
|
562
|
-
// recovering from, like an overflow's 400.
|
|
563
|
+
// recovering from, like an overflow's 400. A clean exit that ended on an error
|
|
564
|
+
// has only the stream: its stderr is those warnings too, and the refusal stands.
|
|
563
565
|
const stoppedTurnFailure = (reply, {
|
|
564
566
|
code, signal, stderr, credentials,
|
|
565
567
|
}) => {
|
|
566
568
|
const killed = Boolean(signal) || code === 143 || code === 129;
|
|
569
|
+
const cleanExit = code === 0;
|
|
567
570
|
const upstream = killed ? null : reply.upstream;
|
|
568
571
|
const failure = adapterFailure(
|
|
569
572
|
'pi',
|
|
570
|
-
reply.errors.join(' | ')
|
|
573
|
+
reply.errors.join(' | ')
|
|
574
|
+
|| (cleanExit ? describeUpstreamRefusal(upstream) : '')
|
|
575
|
+
|| (killed || cleanExit ? '' : stderr.trim().slice(-600))
|
|
576
|
+
|| upstream?.detail
|
|
571
577
|
|| 'the turn stopped before it finished',
|
|
572
578
|
{ credentials, exitCode: code, limit: 600 },
|
|
573
579
|
);
|
|
@@ -668,6 +674,14 @@ const runPi = ({
|
|
|
668
674
|
const tail = (reply.errors.join(' | ') || stderr).trim().slice(-600);
|
|
669
675
|
return reject(new Error(`pi exited ${code}: ${tail}`));
|
|
670
676
|
}
|
|
677
|
+
// A refused turn exits 0 too, so here the stream is what says the text was
|
|
678
|
+
// interim. Posting it would answer with half a turn (F258). The last stop
|
|
679
|
+
// decides, not `reply.upstream`, which outlives a refusal pi recovered from.
|
|
680
|
+
if (code === 0 && reply.sawAssistant && !reply.finished && reply.lastStop === 'error') {
|
|
681
|
+
return reject(stoppedTurnFailure(reply, {
|
|
682
|
+
code, signal, stderr, credentials,
|
|
683
|
+
}));
|
|
684
|
+
}
|
|
671
685
|
return resolve(reply);
|
|
672
686
|
});
|
|
673
687
|
});
|