mdedit-cli 0.4.4 → 0.4.6

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/README.md CHANGED
@@ -18,9 +18,11 @@ All APIs require authentication. Create an API key here:
18
18
 
19
19
  - [API key docs](https://mdedit.ai/docs/api-keys)
20
20
 
21
- Interactive browser OAuth is also available in explicitly enabled cohorts. It
22
- uses authorization code + PKCE, a fixed loopback callback, and the operating
23
- system credential manager:
21
+ Signing in through your browser is being rolled out gradually. If it is available
22
+ for your account, you can sign in this way instead of creating a key. If it is
23
+ not available yet, use an API key. Sign-in uses authorization code with PKCE and
24
+ a fixed loopback callback, and your credentials are kept in your operating system
25
+ credential manager:
24
26
 
25
27
  ```bash
26
28
  mdedit auth login
@@ -28,8 +30,8 @@ mdedit auth status
28
30
  mdedit auth logout
29
31
  ```
30
32
 
31
- Headless and CI environments should continue to use scoped API keys. Browser
32
- OAuth remains release-gated and `--no-browser` is not a device flow.
33
+ Headless and CI environments should keep using scoped API keys. There is no
34
+ device-code flow, so `--no-browser` does not replace browser sign-in.
33
35
 
34
36
  ## Configure
35
37
 
@@ -66,7 +68,8 @@ mdedit document edit <documentId> --ops-file ops.json --format json
66
68
  An ops file is a non-empty JSON array of `replace`, `insert`, or `delete` operations with
67
69
  quote, heading, section, or range anchors. The command exits `2` when an anchor is missing,
68
70
  `3` when an anchor is ambiguous, and `4` when an edit conflict is reported. In JSON mode,
69
- the result or typed error is the only value written to stdout.
71
+ the result or typed error is the only value written to stdout. Successful JSON results
72
+ include `authority`, `contentHash`, and `contentRevision` from the durable backend commit.
70
73
 
71
74
  ## Public links
72
75
 
package/dist/index.js CHANGED
@@ -10,6 +10,17 @@ var __export = (target, all) => {
10
10
  };
11
11
 
12
12
  // ../sdk/dist/index.js
13
+ async function parseMutationJson(response, options) {
14
+ const body = await response.json();
15
+ options?.onResponseMetadata?.({
16
+ idempotencyReplay: response.headers?.get?.("Idempotency-Replayed") === "true",
17
+ idempotencyReplayTruncated: response.headers?.get?.("Idempotency-Replay-Truncated") === "true"
18
+ });
19
+ return body;
20
+ }
21
+ function mutationHeaders(options) {
22
+ return options?.idempotencyKey ? { "Idempotency-Key": options.idempotencyKey } : void 0;
23
+ }
13
24
  function createFetchers(config) {
14
25
  const baseUrlV1 = (config.baseUrlV1 ?? "").replace(/\/$/, "");
15
26
  const baseUrlV2 = (config.baseUrlV2 ?? "").replace(/\/$/, "");
@@ -236,6 +247,28 @@ async function fetchErrorFromResponse(prefix, response) {
236
247
  }
237
248
  return new errors_default(`${prefix}. ${text}`, response.status, data);
238
249
  }
250
+ async function checkpointCollaboration(workspaceId, articleId, requestOrFetchers = {}, suppliedFetchers) {
251
+ const legacyFetchers = "customFetchV2" in requestOrFetchers ? requestOrFetchers : void 0;
252
+ const request = legacyFetchers ? {} : requestOrFetchers;
253
+ const fetchers = legacyFetchers ?? suppliedFetchers;
254
+ const fetchV2 = fetchers?.customFetchV2 ?? customFetchV2;
255
+ const hasExpectedContentHash = typeof request.expectedContentHash === "string";
256
+ const response = await fetchV2(
257
+ `/workspaces/${workspaceId}/articles/${articleId}/collaboration/checkpoint`,
258
+ hasExpectedContentHash ? {
259
+ method: "POST",
260
+ headers: { "Content-Type": "application/json" },
261
+ body: JSON.stringify(request)
262
+ } : { method: "POST" }
263
+ );
264
+ if (!response.ok) {
265
+ throw new errors_default(
266
+ `Error checkpointing collaboration. ${await response.text()}`,
267
+ response.status
268
+ );
269
+ }
270
+ return response.json();
271
+ }
239
272
  function coerceToFetchError(err) {
240
273
  const anyErr = err;
241
274
  const status = typeof anyErr?.status === "number" ? anyErr.status : 500;
@@ -279,12 +312,24 @@ function createSdkClient(config) {
279
312
  list: async (workspaceId) => await withFetchError(() => getArticles(workspaceId, fetchers)) ?? [],
280
313
  listByFolder: async (workspaceId, folderId) => await withFetchError(() => getArticlesByFolder(workspaceId, folderId, fetchers)) ?? [],
281
314
  get: async (workspaceId, articleId) => await withFetchError(() => getArticle(workspaceId, articleId, fetchers)),
282
- create: (workspaceId, req) => withFetchError(() => createArticle(workspaceId, req, fetchers)),
283
- update: (workspaceId, req) => withFetchError(() => updateArticle(workspaceId, req, fetchers)),
284
- delete: async (workspaceId, articleId) => {
285
- await withFetchError(() => deleteArticle(workspaceId, articleId, fetchers));
315
+ create: (workspaceId, req, options) => withFetchError(() => createArticle(workspaceId, req, fetchers, options)),
316
+ editCommands: (workspaceId, articleId, request, options) => withFetchError(() => applyArticleEditCommands(workspaceId, articleId, request, fetchers, options)),
317
+ update: (workspaceId, req, options) => withFetchError(() => updateArticle(
318
+ workspaceId,
319
+ req,
320
+ fetchers,
321
+ options
322
+ )),
323
+ delete: async (workspaceId, articleId, options) => {
324
+ await withFetchError(() => deleteArticle(workspaceId, articleId, fetchers, options));
286
325
  },
287
- saveContent: (workspaceId, articleId, content, options) => withFetchError(() => saveArticleContent(workspaceId, articleId, content, options, fetchers)),
326
+ saveContent: (workspaceId, articleId, content, options) => withFetchError(() => saveArticleContent(
327
+ workspaceId,
328
+ articleId,
329
+ content,
330
+ options ? { ...options, request: { idempotencyKey: options.idempotencyKey } } : options,
331
+ fetchers
332
+ )),
288
333
  exportZip: (workspaceId, articleId) => withFetchError(() => exportArticleZip(workspaceId, articleId, fetchers)),
289
334
  presentation: (workspaceId, articleId) => withFetchError(() => getArticlePresentation(workspaceId, articleId, fetchers)),
290
335
  startExport: (workspaceId, articleId, format) => withFetchError(() => createArticleExportJob(workspaceId, articleId, format, fetchers)),
@@ -310,7 +355,7 @@ function createSdkClient(config) {
310
355
  safeGists: async (workspaceId, articleId, urls) => (await withFetchError(() => getArticleSafeGists(workspaceId, articleId, urls, fetchers))).gists
311
356
  },
312
357
  collaboration: {
313
- checkpoint: (workspaceId, articleId) => withFetchError(() => checkpointCollaboration(workspaceId, articleId, fetchers))
358
+ checkpoint: (workspaceId, articleId, request = {}) => withFetchError(() => checkpointCollaboration(workspaceId, articleId, request, fetchers))
314
359
  },
315
360
  tools: {
316
361
  createUpload: (request) => withFetchError(() => createConversionUploadUrl(request, fetchers)),
@@ -321,14 +366,14 @@ function createSdkClient(config) {
321
366
  startConversion: (input) => withFetchError(() => startConversionFromBytes(input, fetchers))
322
367
  },
323
368
  publish: {
324
- publish: (workspaceId, articleId, request = {}) => withFetchError(() => publishArticle(workspaceId, articleId, request, fetchers)),
369
+ publish: (workspaceId, articleId, request = {}, options) => withFetchError(() => publishArticle(workspaceId, articleId, request, fetchers, options)),
325
370
  status: (workspaceId, articleId) => withFetchError(() => getPublishStatus(workspaceId, articleId, fetchers)),
326
- update: (workspaceId, articleId, request = {}) => withFetchError(() => updatePublishedArticle(workspaceId, articleId, request, fetchers)),
327
- unpublish: (workspaceId, articleId) => withFetchError(() => unpublishArticle(workspaceId, articleId, fetchers))
371
+ update: (workspaceId, articleId, request = {}, options) => withFetchError(() => updatePublishedArticle(workspaceId, articleId, request, fetchers, options)),
372
+ unpublish: (workspaceId, articleId, options) => withFetchError(() => unpublishArticle(workspaceId, articleId, fetchers, options))
328
373
  }
329
374
  };
330
375
  }
331
- var _defaultFetchers, customFetchV2, FetchError, errors_default, createArticle, updateArticle, getArticles, getArticlesByFolder, getArticle, getArticlePresentation, getArticleAssetDownloadUrls, getArticleMediaProxyUrls, getArticleSafeGists, deleteArticle, exportArticleZip, createArticleExportJob, ApiError, DEFAULT_POLL_INTERVAL_MS, DEFAULT_TIMEOUT_MS, sleep, saveArticleContent, getWorkspaces, createWorkspace, updateWorkspace, deleteWorkspace, getWorkspace, normalizeTimestampMs, readFolderErrorMessage, normalizeFolder, createFolder, updateFolder, getFolders, getFolder, deleteFolder, sleep2, isRetriableStatus, withRetries, listApiKeys, createApiKey, revokeApiKey, checkpointCollaboration, publishArticle, unpublishArticle, getPublishStatus, updatePublishedArticle, FetchError2;
376
+ var _defaultFetchers, customFetchV2, FetchError, errors_default, createArticle, applyArticleEditCommands, updateArticle, getArticles, getArticlesByFolder, getArticle, getArticlePresentation, getArticleAssetDownloadUrls, getArticleMediaProxyUrls, getArticleSafeGists, deleteArticle, exportArticleZip, createArticleExportJob, ApiError, DEFAULT_POLL_INTERVAL_MS, DEFAULT_TIMEOUT_MS, sleep, saveArticleContent, getWorkspaces, createWorkspace, updateWorkspace, deleteWorkspace, getWorkspace, normalizeTimestampMs, readFolderErrorMessage, normalizeFolder, createFolder, updateFolder, getFolders, getFolder, deleteFolder, sleep2, isRetriableStatus, withRetries, listApiKeys, createApiKey, revokeApiKey, publishArticle, unpublishArticle, getPublishStatus, updatePublishedArticle, FetchError2;
332
377
  var init_dist = __esm({
333
378
  "../sdk/dist/index.js"() {
334
379
  "use strict";
@@ -348,16 +393,18 @@ var init_dist = __esm({
348
393
  }
349
394
  };
350
395
  errors_default = FetchError;
351
- createArticle = async (workspaceId, articleRequest, fetchers) => {
396
+ createArticle = async (workspaceId, articleRequest, fetchers, requestOptions) => {
352
397
  const fetchV2 = fetchers?.customFetchV2 ?? customFetchV2;
353
398
  const response = await fetchV2(`/workspaces/${workspaceId}/articles`, {
354
399
  method: "POST",
400
+ headers: mutationHeaders(requestOptions),
355
401
  body: JSON.stringify({
356
402
  articleId: articleRequest.articleId,
357
403
  title: articleRequest.title,
358
404
  folderId: articleRequest.folderId,
359
405
  collaborative: articleRequest.collaborative ?? false,
360
- articleSettings: articleRequest.articleSettings
406
+ articleSettings: articleRequest.articleSettings,
407
+ tags: articleRequest.tags
361
408
  })
362
409
  });
363
410
  if (!response.ok) {
@@ -375,9 +422,21 @@ var init_dist = __esm({
375
422
  }
376
423
  throw new errors_default(`Error creating article. ${errorText}`, response.status);
377
424
  }
378
- return response.json();
425
+ return parseMutationJson(response, requestOptions);
379
426
  };
380
- updateArticle = async (workspaceId, articleRequest, fetchers) => {
427
+ applyArticleEditCommands = async (workspaceId, articleId, body, fetchers, requestOptions) => {
428
+ const fetchV2 = fetchers?.customFetchV2 ?? customFetchV2;
429
+ const response = await fetchV2(`/workspaces/${workspaceId}/articles/${articleId}/edit-commands`, {
430
+ method: "POST",
431
+ headers: mutationHeaders(requestOptions),
432
+ body: JSON.stringify(body)
433
+ });
434
+ if (!response.ok) {
435
+ throw new errors_default(`Error editing article. ${await response.text()}`, response.status);
436
+ }
437
+ return parseMutationJson(response, requestOptions);
438
+ };
439
+ updateArticle = async (workspaceId, articleRequest, fetchers, requestOptions) => {
381
440
  const fetchV2 = fetchers?.customFetchV2 ?? customFetchV2;
382
441
  const body = {
383
442
  title: articleRequest.title,
@@ -388,6 +447,9 @@ var init_dist = __esm({
388
447
  if (articleRequest.folderId !== void 0) {
389
448
  body.folderId = articleRequest.folderId;
390
449
  }
450
+ if (articleRequest.tags !== void 0) {
451
+ body.tags = articleRequest.tags;
452
+ }
391
453
  if (articleRequest.preview) {
392
454
  body.preview = articleRequest.preview;
393
455
  }
@@ -404,6 +466,7 @@ var init_dist = __esm({
404
466
  `/workspaces/${workspaceId}/articles/${articleRequest.articleId}`,
405
467
  {
406
468
  method: "PUT",
469
+ headers: mutationHeaders(requestOptions),
407
470
  body: JSON.stringify(body)
408
471
  }
409
472
  );
@@ -507,11 +570,11 @@ var init_dist = __esm({
507
570
  if (!response.ok) throw new errors_default(`Error loading Gists. ${await response.text()}`, response.status);
508
571
  return response.json();
509
572
  };
510
- deleteArticle = async (workspaceId, articleId, fetchers) => {
573
+ deleteArticle = async (workspaceId, articleId, fetchers, requestOptions) => {
511
574
  const fetchV2 = fetchers?.customFetchV2 ?? customFetchV2;
512
575
  const response = await fetchV2(
513
576
  `/workspaces/${workspaceId}/articles/${articleId}`,
514
- { method: "DELETE" }
577
+ { method: "DELETE", headers: mutationHeaders(requestOptions) }
515
578
  );
516
579
  if (!response.ok) {
517
580
  throw new errors_default(
@@ -586,6 +649,7 @@ var init_dist = __esm({
586
649
  method: "POST",
587
650
  ...options ? {
588
651
  body: JSON.stringify({
652
+ uploadId: `${options.baseContentRevision}-${options.contentHash}`,
589
653
  baseContentRevision: options.baseContentRevision,
590
654
  baseContentHash: options.baseContentHash,
591
655
  contentHash: options.contentHash,
@@ -620,6 +684,7 @@ var init_dist = __esm({
620
684
  `/workspaces/${workspaceId}/articles/${articleId}/content-commit`,
621
685
  {
622
686
  method: "POST",
687
+ headers: mutationHeaders(options.request),
623
688
  body: JSON.stringify({
624
689
  uploadId,
625
690
  baseContentRevision: options.baseContentRevision,
@@ -631,7 +696,8 @@ var init_dist = __esm({
631
696
  folderId: options.folderId,
632
697
  isPinned: options.isPinned,
633
698
  isArchived: options.isArchived,
634
- articleSettings: options.articleSettings
699
+ articleSettings: options.articleSettings,
700
+ tags: options.tags
635
701
  })
636
702
  }
637
703
  );
@@ -892,26 +958,13 @@ var init_dist = __esm({
892
958
  }
893
959
  return response.json();
894
960
  };
895
- checkpointCollaboration = async (workspaceId, articleId, fetchers) => {
896
- const fetchV2 = fetchers?.customFetchV2 ?? customFetchV2;
897
- const response = await fetchV2(
898
- `/workspaces/${workspaceId}/articles/${articleId}/collaboration/checkpoint`,
899
- { method: "POST" }
900
- );
901
- if (!response.ok) {
902
- throw new errors_default(
903
- `Error checkpointing collaboration. ${await response.text()}`,
904
- response.status
905
- );
906
- }
907
- return response.json();
908
- };
909
- publishArticle = async (workspaceId, articleId, body, fetchers) => {
961
+ publishArticle = async (workspaceId, articleId, body, fetchers, requestOptions) => {
910
962
  const fetchV2 = fetchers?.customFetchV2 ?? customFetchV2;
911
963
  const response = await fetchV2(
912
964
  `/workspaces/${workspaceId}/articles/${articleId}/publish`,
913
965
  {
914
966
  method: "POST",
967
+ headers: mutationHeaders(requestOptions),
915
968
  body: JSON.stringify(body)
916
969
  }
917
970
  );
@@ -921,13 +974,13 @@ var init_dist = __esm({
921
974
  response.status
922
975
  );
923
976
  }
924
- return response.json();
977
+ return parseMutationJson(response, requestOptions);
925
978
  };
926
- unpublishArticle = async (workspaceId, articleId, fetchers) => {
979
+ unpublishArticle = async (workspaceId, articleId, fetchers, requestOptions) => {
927
980
  const fetchV2 = fetchers?.customFetchV2 ?? customFetchV2;
928
981
  const response = await fetchV2(
929
982
  `/workspaces/${workspaceId}/articles/${articleId}/publish`,
930
- { method: "DELETE" }
983
+ { method: "DELETE", headers: mutationHeaders(requestOptions) }
931
984
  );
932
985
  if (!response.ok) {
933
986
  throw new errors_default(
@@ -935,7 +988,7 @@ var init_dist = __esm({
935
988
  response.status
936
989
  );
937
990
  }
938
- return response.json();
991
+ return parseMutationJson(response, requestOptions);
939
992
  };
940
993
  getPublishStatus = async (workspaceId, articleId, fetchers) => {
941
994
  const fetchV2 = fetchers?.customFetchV2 ?? customFetchV2;
@@ -951,12 +1004,13 @@ var init_dist = __esm({
951
1004
  }
952
1005
  return response.json();
953
1006
  };
954
- updatePublishedArticle = async (workspaceId, articleId, body, fetchers) => {
1007
+ updatePublishedArticle = async (workspaceId, articleId, body, fetchers, requestOptions) => {
955
1008
  const fetchV2 = fetchers?.customFetchV2 ?? customFetchV2;
956
1009
  const response = await fetchV2(
957
1010
  `/workspaces/${workspaceId}/articles/${articleId}/publish`,
958
1011
  {
959
1012
  method: "PUT",
1013
+ headers: mutationHeaders(requestOptions),
960
1014
  body: JSON.stringify(body)
961
1015
  }
962
1016
  );
@@ -966,7 +1020,7 @@ var init_dist = __esm({
966
1020
  response.status
967
1021
  );
968
1022
  }
969
- return response.json();
1023
+ return parseMutationJson(response, requestOptions);
970
1024
  };
971
1025
  FetchError2 = class extends Error {
972
1026
  status;
@@ -1876,7 +1930,6 @@ import { fileURLToPath as fileURLToPath2 } from "url";
1876
1930
  import { AgentClientHttpError } from "@mdedit/agent-client";
1877
1931
 
1878
1932
  // src/commands/article.ts
1879
- init_dist();
1880
1933
  init_output();
1881
1934
  import { Command, Option } from "commander";
1882
1935
  import inquirer from "inquirer";
@@ -2238,26 +2291,14 @@ function createDocumentCommand(commandName, deprecated) {
2238
2291
  anchor: { range: { from: 0, to: currentContent.length } },
2239
2292
  text: contentText
2240
2293
  }]);
2294
+ const receipt = await session.ensureDurable();
2295
+ const expectedContentHash = sha256Hex(contentText);
2296
+ if (receipt.contentHash !== expectedContentHash) {
2297
+ throw new Error("Collaborative content durability receipt did not match the created content.");
2298
+ }
2241
2299
  } finally {
2242
2300
  await session.close();
2243
2301
  }
2244
- const expectedContentHash = sha256Hex(contentText);
2245
- let checkpointedContentHash;
2246
- for (let attempt = 0; attempt < 20; attempt += 1) {
2247
- try {
2248
- const checkpoint = await client.collaboration.checkpoint(workspaceId, articleId);
2249
- checkpointedContentHash = checkpoint.targetHashes["content.md"];
2250
- if (checkpointedContentHash === expectedContentHash) break;
2251
- } catch (error) {
2252
- if (!(error instanceof FetchError2) || error.status !== 409 && error.status !== 503) {
2253
- throw error;
2254
- }
2255
- }
2256
- await new Promise((resolve) => setTimeout(resolve, 500));
2257
- }
2258
- if (checkpointedContentHash !== expectedContentHash) {
2259
- throw new Error("Collaborative content did not reach a durable checkpoint within 10 seconds.");
2260
- }
2261
2302
  } else {
2262
2303
  await client.article.saveContent(workspaceId, articleId, contentText, {
2263
2304
  baseContentRevision: 0,
@@ -2433,6 +2474,7 @@ function createDocumentCommand(commandName, deprecated) {
2433
2474
  let session;
2434
2475
  let editError;
2435
2476
  let result;
2477
+ let receipt;
2436
2478
  try {
2437
2479
  session = await openArticleSession({
2438
2480
  credentialProvider,
@@ -2442,6 +2484,7 @@ function createDocumentCommand(commandName, deprecated) {
2442
2484
  apiUrl: getApiUrlRaw()
2443
2485
  });
2444
2486
  result = await session.edit(operations);
2487
+ receipt = await session.ensureDurable();
2445
2488
  } catch (error) {
2446
2489
  editError = error;
2447
2490
  throw error;
@@ -2454,8 +2497,15 @@ function createDocumentCommand(commandName, deprecated) {
2454
2497
  }
2455
2498
  }
2456
2499
  }
2457
- if (!session || !result) throw new Error("Document edit did not return a result.");
2458
- output.output({ articleId, mode: session.mode, ...result });
2500
+ if (!session || !result || !receipt) throw new Error("Document edit did not return a durable result.");
2501
+ output.output({
2502
+ articleId,
2503
+ mode: session.mode,
2504
+ authority: receipt.authority,
2505
+ contentHash: receipt.contentHash,
2506
+ contentRevision: receipt.contentRevision,
2507
+ ...result
2508
+ });
2459
2509
  if (result.conflicts.length > 0) {
2460
2510
  output.warning("The edit was applied with overlapping remote changes; re-read the document before continuing.");
2461
2511
  process.exitCode = CLI_EXIT_CODES.EDIT_CONFLICT;
@@ -3401,6 +3451,43 @@ function defaultOutputPath(inputFile, outputFormat) {
3401
3451
  const ext = outputFormat === "markdown" ? "md" : outputFormat;
3402
3452
  return `${stem}.${ext}`;
3403
3453
  }
3454
+ var CONVERSION_SCOPE = "conversions:execute";
3455
+ function isInteractive() {
3456
+ return Boolean(process.stdin.isTTY && process.stdout.isTTY) && !output.isJson();
3457
+ }
3458
+ async function ensureConvertAuthentication() {
3459
+ const usingApiKey = Boolean(process.env.MDEDIT_API_KEY?.trim());
3460
+ let needsLogin = false;
3461
+ try {
3462
+ requireAuthentication();
3463
+ } catch (error) {
3464
+ if (!isInteractive()) throw error;
3465
+ needsLogin = true;
3466
+ }
3467
+ if (!needsLogin && !usingApiKey) {
3468
+ const { oauthStatus: oauthStatus2 } = await Promise.resolve().then(() => (init_oauth(), oauth_exports));
3469
+ const status = await oauthStatus2().catch(() => null);
3470
+ if (status?.authenticated) {
3471
+ const hasConversionScope = (status.scope || []).some(
3472
+ (scope) => scope === CONVERSION_SCOPE || scope.endsWith(`/${CONVERSION_SCOPE}`)
3473
+ );
3474
+ if (!hasConversionScope) {
3475
+ if (!isInteractive()) {
3476
+ throw new Error(
3477
+ "Your sign-in predates conversion access. Run `mdedit auth login` to re-authorize, or pass an API key with the conversions:execute scope."
3478
+ );
3479
+ }
3480
+ output.info("Your sign-in predates conversion access. Re-authorizing in your browser...");
3481
+ needsLogin = true;
3482
+ }
3483
+ }
3484
+ }
3485
+ if (!needsLogin) return;
3486
+ output.info("Converting needs a one-time sign-in. Opening your browser...");
3487
+ const { loginWithOAuth: loginWithOAuth2 } = await Promise.resolve().then(() => (init_oauth(), oauth_exports));
3488
+ await loginWithOAuth2({});
3489
+ output.info("Signed in. Continuing with the conversion.");
3490
+ }
3404
3491
  function createConvertCommands() {
3405
3492
  return new Command9("convert").description("Convert a document between formats").argument("<input>", "Path to the file to convert").requiredOption("-t, --to <format>", "Target format, for example docx, pdf, md").option("-f, --from <format>", "Override the input format (inferred from the extension)").option("-o, --out <path>", "Where to write the result (defaults to the input name with the new extension)").addHelpText("after", `
3406
3493
  Examples:
@@ -3408,7 +3495,7 @@ Examples:
3408
3495
  $ mdedit convert notes.md --to pdf --out notes.pdf
3409
3496
  $ mdedit convert report.docx --to md
3410
3497
  `).action(async (inputFile, options) => {
3411
- requireApiKey();
3498
+ await ensureConvertAuthentication();
3412
3499
  const client = getApiClient();
3413
3500
  const conversion = resolveConversion(inputFile, options.to, options.from);
3414
3501
  const outPath = options.out || defaultOutputPath(inputFile, conversion.outputFormat);