@mintlify/cli 4.0.1122 → 4.0.1124

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/bin/cli.js CHANGED
@@ -33,7 +33,6 @@ import { scoreHandler } from './score/index.js';
33
33
  import { status, getCliSubdomains } from './status.js';
34
34
  import { trackTelemetryPreferenceChange } from './telemetry/track.js';
35
35
  import { update } from './update.js';
36
- import { addWorkflow } from './workflow.js';
37
36
  export const cli = ({ packageName = 'mint' }) => {
38
37
  const telemetryMiddleware = createTelemetryMiddleware();
39
38
  render(_jsx(Logs, {}));
@@ -400,16 +399,6 @@ export const cli = ({ packageName = 'mint' }) => {
400
399
  addLog(_jsx(ErrorLog, { message: error instanceof Error ? error.message : 'error occurred' }));
401
400
  yield terminate(1);
402
401
  }
403
- }))
404
- .command('workflow', 'Add a workflow to your documentation repository', () => undefined, () => __awaiter(void 0, void 0, void 0, function* () {
405
- try {
406
- yield addWorkflow();
407
- yield terminate(0);
408
- }
409
- catch (error) {
410
- addLog(_jsx(ErrorLog, { message: error instanceof Error ? error.message : 'error occurred' }));
411
- yield terminate(1);
412
- }
413
402
  }))
414
403
  .command('analytics', 'View analytics for your documentation', analyticsBuilder)
415
404
  .command('score <url>', 'Run agent readiness checks on a docs site', (yargs) => yargs
@@ -9,13 +9,28 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  };
10
10
  import { authenticatedFetch } from '../authenticatedFetch.js';
11
11
  import { API_URL } from '../constants.js';
12
- export function getScore(url) {
12
+ export function resolveScoreForUrl(url) {
13
13
  return __awaiter(this, void 0, void 0, function* () {
14
14
  const endpoint = new URL(`${API_URL}/api/cli/score`);
15
15
  endpoint.searchParams.set('url', url);
16
16
  const res = yield authenticatedFetch(endpoint.toString(), {
17
17
  headers: { Accept: 'application/json' },
18
18
  });
19
+ if (res.status !== 200 && res.status !== 202) {
20
+ const body = yield res.text().catch(() => '');
21
+ throw new Error(`API error (${res.status}): ${body || res.statusText}`);
22
+ }
23
+ return res.json();
24
+ });
25
+ }
26
+ export function fetchScoreBySlug(slug) {
27
+ return __awaiter(this, void 0, void 0, function* () {
28
+ const endpoint = new URL(`${API_URL}/api/cli/score/${encodeURIComponent(slug)}`);
29
+ const res = yield authenticatedFetch(endpoint.toString(), {
30
+ headers: { Accept: 'application/json' },
31
+ });
32
+ if (res.status === 202)
33
+ return null;
19
34
  if (!res.ok) {
20
35
  const body = yield res.text().catch(() => '');
21
36
  throw new Error(`API error (${res.status}): ${body || res.statusText}`);
@@ -13,7 +13,9 @@ import chalk from 'chalk';
13
13
  import { Text } from 'ink';
14
14
  import { terminate } from '../helpers.js';
15
15
  import { trackEvent } from '../telemetry/track.js';
16
- import { getScore } from './client.js';
16
+ import { fetchScoreBySlug, resolveScoreForUrl } from './client.js';
17
+ const POLL_INTERVAL_MS = 3000;
18
+ const POLL_TIMEOUT_MS = 120000;
17
19
  function resolveFormat(argv) {
18
20
  if (argv.format === 'table' || argv.format === 'plain' || argv.format === 'json')
19
21
  return argv.format;
@@ -49,6 +51,18 @@ function renderPlain(checks, prefix = '') {
49
51
  }
50
52
  return lines;
51
53
  }
54
+ function renderTable(score, opts) {
55
+ const scoreColor = score.overallScore >= 70 ? 'green' : score.overallScore >= 40 ? 'yellow' : 'red';
56
+ const header = (opts === null || opts === void 0 ? void 0 : opts.stale)
57
+ ? chalk.bold(`\nAgent Readiness Score — ${score.canonicalUrl}`) +
58
+ chalk.dim(` (last run ${new Date(score.computedAt).toLocaleString()})\n`)
59
+ : chalk.bold(`\nAgent Readiness Score — ${score.canonicalUrl}\n`);
60
+ const lines = [header];
61
+ lines.push(` Score: ${chalk[scoreColor].bold(`${score.overallScore}%`)}\n`);
62
+ lines.push(chalk.bold(' Checks'));
63
+ lines.push(...renderChecks(score.checks));
64
+ return lines.join('\n');
65
+ }
52
66
  function output(format, text) {
53
67
  if (format === 'table') {
54
68
  addLog(_jsx(Text, { children: text }));
@@ -57,37 +71,88 @@ function output(format, text) {
57
71
  process.stdout.write(text + '\n');
58
72
  }
59
73
  }
74
+ function sleep(ms) {
75
+ return __awaiter(this, void 0, void 0, function* () {
76
+ return new Promise((resolve) => setTimeout(resolve, ms));
77
+ });
78
+ }
79
+ function pollForScore(slug, afterIso, onAttempt) {
80
+ return __awaiter(this, void 0, void 0, function* () {
81
+ const deadline = Date.now() + POLL_TIMEOUT_MS;
82
+ while (Date.now() < deadline) {
83
+ yield sleep(POLL_INTERVAL_MS);
84
+ onAttempt === null || onAttempt === void 0 ? void 0 : onAttempt();
85
+ const score = yield fetchScoreBySlug(slug);
86
+ if (!score)
87
+ continue;
88
+ if (afterIso === null)
89
+ return score;
90
+ if (new Date(score.computedAt).getTime() > new Date(afterIso).getTime())
91
+ return score;
92
+ }
93
+ throw new Error(`Score did not complete within ${POLL_TIMEOUT_MS / 1000}s`);
94
+ });
95
+ }
60
96
  export const scoreHandler = (argv) => __awaiter(void 0, void 0, void 0, function* () {
61
97
  const format = resolveFormat(argv);
62
98
  try {
63
99
  if (format === 'table')
64
- addLog(_jsx(SpinnerLog, { message: "Running agent readiness checks..." }));
65
- const data = yield getScore(argv.url);
100
+ addLog(_jsx(SpinnerLog, { message: "Checking agent readiness..." }));
101
+ const resolved = yield resolveScoreForUrl(argv.url);
102
+ let final;
103
+ if (resolved.status === 'ready') {
104
+ const score = yield fetchScoreBySlug(resolved.slug);
105
+ if (format === 'table')
106
+ removeLastLog();
107
+ if (!score)
108
+ throw new Error('Score was unexpectedly unavailable');
109
+ final = score;
110
+ }
111
+ else if (resolved.status === 'stale_refresh_queued') {
112
+ const stale = yield fetchScoreBySlug(resolved.slug);
113
+ if (format === 'table')
114
+ removeLastLog();
115
+ if (!stale)
116
+ throw new Error('Stale score was unexpectedly unavailable');
117
+ if (format === 'table') {
118
+ output('table', renderTable(stale, { stale: true }));
119
+ addLog(_jsx(SpinnerLog, { message: "Refreshing score in the background..." }));
120
+ }
121
+ else {
122
+ process.stderr.write('Refreshing score in the background...\n');
123
+ }
124
+ final = yield pollForScore(resolved.slug, stale.computedAt);
125
+ if (format === 'table')
126
+ removeLastLog();
127
+ }
128
+ else {
129
+ if (format === 'table') {
130
+ removeLastLog();
131
+ addLog(_jsx(SpinnerLog, { message: "Queued a new scoring run. Waiting for first result..." }));
132
+ }
133
+ else {
134
+ process.stderr.write('Queued a new scoring run. Waiting for first result...\n');
135
+ }
136
+ final = yield pollForScore(resolved.slug, null);
137
+ if (format === 'table')
138
+ removeLastLog();
139
+ }
66
140
  void trackEvent('cli.score.executed', {
67
141
  url: argv.url,
68
- score: data.overallScore,
142
+ score: final.overallScore,
69
143
  format,
144
+ status: resolved.status,
70
145
  });
71
- if (format === 'table')
72
- removeLastLog();
73
146
  if (format === 'json') {
74
- output(format, JSON.stringify(data, null, 2));
75
- yield terminate(0);
76
- return;
147
+ output(format, JSON.stringify(final, null, 2));
77
148
  }
78
- if (format === 'plain') {
79
- const lines = [`SCORE\t${data.overallScore}`, ...renderPlain(data.checks)];
149
+ else if (format === 'plain') {
150
+ const lines = [`SCORE\t${final.overallScore}`, ...renderPlain(final.checks)];
80
151
  output(format, lines.join('\n'));
81
- yield terminate(0);
82
- return;
83
152
  }
84
- const scoreColor = data.overallScore >= 70 ? 'green' : data.overallScore >= 40 ? 'yellow' : 'red';
85
- const lines = [];
86
- lines.push(chalk.bold(`\nAgent Readiness Score — ${data.url}\n`));
87
- lines.push(` Score: ${chalk[scoreColor].bold(`${data.overallScore}%`)}\n`);
88
- lines.push(chalk.bold(' Checks'));
89
- lines.push(...renderChecks(data.checks));
90
- output(format, lines.join('\n'));
153
+ else {
154
+ output(format, renderTable(final));
155
+ }
91
156
  yield terminate(0);
92
157
  }
93
158
  catch (err) {