getownit 0.1.3 → 0.1.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.
Files changed (2) hide show
  1. package/dist/debrief.js +30 -4
  2. package/package.json +1 -1
package/dist/debrief.js CHANGED
@@ -19,6 +19,32 @@ async function withSpinner(out, text, work) {
19
19
  spin.stop();
20
20
  }
21
21
  }
22
+ /** A provider error worth retrying: the model did not answer in time or failed on its side. */
23
+ const isUnavailable = (error) => error instanceof ApiError && error.isProviderError && error.body.reason === 'unavailable';
24
+ /**
25
+ * Runs a model request. When the model doesn't answer, it tries once more by
26
+ * itself, then asks before each further try, so a slow moment never throws
27
+ * away a debrief in progress.
28
+ */
29
+ async function withRetry(prompter, request) {
30
+ const c = paint(prompter.out);
31
+ for (let attempt = 1;; attempt++) {
32
+ try {
33
+ return await request();
34
+ }
35
+ catch (error) {
36
+ if (!isUnavailable(error))
37
+ throw error;
38
+ if (attempt === 1) {
39
+ prompter.out.write(c.dim('The model did not answer in time. Trying again…\n'));
40
+ continue;
41
+ }
42
+ const again = await prompter.ask(`${c.yellow(error.message)} Try again? [Y/n] `);
43
+ if (again === null || /^n/i.test(again.trim()))
44
+ throw error;
45
+ }
46
+ }
47
+ }
22
48
  function printQuestion(out, question, total, followUp) {
23
49
  const c = paint(out);
24
50
  const label = `Question ${question.idx + 1}/${total}`;
@@ -55,12 +81,12 @@ async function askUntilPassed(debrief, first) {
55
81
  return later(out);
56
82
  let result;
57
83
  try {
58
- result = await withSpinner(out, 'Checking your answer…', () => api.request('POST', '/api/interview/answer', {
84
+ result = await withRetry(prompter, () => withSpinner(out, 'Checking your answer…', () => api.request('POST', '/api/interview/answer', {
59
85
  session: debrief.session,
60
86
  idx: question.idx,
61
87
  answer: answer.slice(0, MAX_ANSWER_CHARS),
62
88
  ...debrief.payload,
63
- }));
89
+ })));
64
90
  }
65
91
  catch (error) {
66
92
  return failure(out, error);
@@ -92,14 +118,14 @@ export async function runDebrief(api, prompter, target) {
92
118
  };
93
119
  let start;
94
120
  try {
95
- start = await withSpinner(out, 'Nemotron is reading your push…', () => api.request('POST', '/api/interview/start', {
121
+ start = await withRetry(prompter, () => withSpinner(out, 'Nemotron is reading your push…', () => api.request('POST', '/api/interview/start', {
96
122
  repo: target.repo,
97
123
  base_sha: target.baseSha,
98
124
  head_sha: target.headSha,
99
125
  changed_lines: target.diff.changedLines,
100
126
  push_id: target.pushId,
101
127
  ...payload,
102
- }));
128
+ })));
103
129
  }
104
130
  catch (error) {
105
131
  return failure(out, error);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "getownit",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "description": "Debrief the code you just pushed, in your terminal, with NVIDIA Nemotron.",
5
5
  "license": "MIT",
6
6
  "repository": {