mdedit-cli 0.4.0 → 0.4.2

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
@@ -151,7 +151,7 @@ The CLI is designed to be used by AI agents without modification.
151
151
 
152
152
  ### Agent skills
153
153
 
154
- The canonical Save, Find, Revise, and Publish skills are bundled in focused CLI-backed and MCP-backed variants.
154
+ The canonical Save, Find, Revise, Review, and Publish skills are bundled in focused CLI-backed and MCP-backed variants.
155
155
 
156
156
  ```bash
157
157
  # List and inspect skills
@@ -159,7 +159,7 @@ mdedit skill list
159
159
  mdedit skill show save-mdedit-document --via cli
160
160
  mdedit skill show revise-mdedit-document --via mcp
161
161
 
162
- # Install all four CLI-backed skills for the current project
162
+ # Install all five CLI-backed skills for the current project
163
163
  mdedit skill install
164
164
 
165
165
  # Select a host-native directory or MCP-backed variant
package/dist/index.js CHANGED
@@ -50,6 +50,30 @@ function getDefaultFetchers() {
50
50
  "MDEdit API client is not initialized. Call initApiClient(config) at app bootstrap (e.g. pages/_app.jsx) before using API functions."
51
51
  );
52
52
  }
53
+ async function buildApiError(resp) {
54
+ let data = void 0;
55
+ try {
56
+ data = await resp.clone().json();
57
+ } catch {
58
+ }
59
+ let text = "";
60
+ if (!data) {
61
+ try {
62
+ text = await resp.text();
63
+ } catch {
64
+ text = "";
65
+ }
66
+ }
67
+ const messageFromJson = data?.error?.message || data?.message || (typeof data?.error === "string" ? data.error : "");
68
+ const message = messageFromJson || text || `Request failed (${resp.status})`;
69
+ return new ApiError(resp.status, message, data);
70
+ }
71
+ async function getToolJobStatus(jobId, fetchers) {
72
+ const fetchV2 = fetchers?.customFetchV2 ?? customFetchV2;
73
+ const resp = await fetchV2(`/tools/jobs/${encodeURIComponent(jobId)}`);
74
+ if (!resp.ok) throw await buildApiError(resp);
75
+ return resp.json();
76
+ }
53
77
  async function fetchErrorFromResponse(prefix, response) {
54
78
  const text = await response.text();
55
79
  let data;
@@ -109,7 +133,29 @@ function createSdkClient(config) {
109
133
  await withFetchError(() => deleteArticle(workspaceId, articleId, fetchers));
110
134
  },
111
135
  saveContent: (workspaceId, articleId, content, options) => withFetchError(() => saveArticleContent(workspaceId, articleId, content, options, fetchers)),
112
- exportZip: (workspaceId, articleId) => withFetchError(() => exportArticleZip(workspaceId, articleId, fetchers))
136
+ exportZip: (workspaceId, articleId) => withFetchError(() => exportArticleZip(workspaceId, articleId, fetchers)),
137
+ presentation: (workspaceId, articleId) => withFetchError(() => getArticlePresentation(workspaceId, articleId, fetchers)),
138
+ startExport: (workspaceId, articleId, format) => withFetchError(() => createArticleExportJob(workspaceId, articleId, format, fetchers)),
139
+ exportStatus: (jobId) => withFetchError(() => getToolJobStatus(jobId, fetchers)),
140
+ assetUrls: async (workspaceId, articleId, fileNames) => {
141
+ const result = await withFetchError(() => getArticleAssetDownloadUrls(
142
+ workspaceId,
143
+ articleId,
144
+ fileNames,
145
+ fetchers
146
+ ));
147
+ return Object.fromEntries(result.assets.map((asset) => [asset.fileName, asset.downloadUrl]));
148
+ },
149
+ mediaProxyUrls: async (workspaceId, articleId, urls) => {
150
+ const result = await withFetchError(() => getArticleMediaProxyUrls(
151
+ workspaceId,
152
+ articleId,
153
+ urls,
154
+ fetchers
155
+ ));
156
+ return Object.fromEntries(result.urls.map((item) => [item.source, item.proxyUrl]));
157
+ },
158
+ safeGists: async (workspaceId, articleId, urls) => (await withFetchError(() => getArticleSafeGists(workspaceId, articleId, urls, fetchers))).gists
113
159
  },
114
160
  collaboration: {
115
161
  checkpoint: (workspaceId, articleId) => withFetchError(() => checkpointCollaboration(workspaceId, articleId, fetchers))
@@ -122,7 +168,7 @@ function createSdkClient(config) {
122
168
  }
123
169
  };
124
170
  }
125
- var _defaultFetchers, customFetchV2, FetchError, errors_default, createArticle, updateArticle, getArticles, getArticlesByFolder, getArticle, deleteArticle, exportArticleZip, saveArticleContent, getWorkspaces, createWorkspace, updateWorkspace, deleteWorkspace, getWorkspace, normalizeTimestampMs, readFolderErrorMessage, normalizeFolder, createFolder, updateFolder, getFolders, getFolder, deleteFolder, sleep, isRetriableStatus, withRetries, listApiKeys, createApiKey, revokeApiKey, checkpointCollaboration, publishArticle, unpublishArticle, getPublishStatus, updatePublishedArticle, FetchError2;
171
+ var _defaultFetchers, customFetchV2, FetchError, errors_default, createArticle, updateArticle, getArticles, getArticlesByFolder, getArticle, getArticlePresentation, getArticleAssetDownloadUrls, getArticleMediaProxyUrls, getArticleSafeGists, deleteArticle, exportArticleZip, createArticleExportJob, ApiError, saveArticleContent, getWorkspaces, createWorkspace, updateWorkspace, deleteWorkspace, getWorkspace, normalizeTimestampMs, readFolderErrorMessage, normalizeFolder, createFolder, updateFolder, getFolders, getFolder, deleteFolder, sleep, isRetriableStatus, withRetries, listApiKeys, createApiKey, revokeApiKey, checkpointCollaboration, publishArticle, unpublishArticle, getPublishStatus, updatePublishedArticle, FetchError2;
126
172
  var init_dist = __esm({
127
173
  "../sdk/dist/index.js"() {
128
174
  "use strict";
@@ -257,6 +303,50 @@ var init_dist = __esm({
257
303
  }
258
304
  return response.json();
259
305
  };
306
+ getArticlePresentation = async (workspaceId, articleId, fetchers) => {
307
+ const fetchV2 = fetchers?.customFetchV2 ?? customFetchV2;
308
+ const response = await fetchV2(
309
+ `/workspaces/${workspaceId}/articles/${articleId}/presentation`
310
+ );
311
+ if (!response.ok) {
312
+ throw new errors_default(
313
+ `Error fetching article presentation. ${await response.text()}`,
314
+ response.status
315
+ );
316
+ }
317
+ return response.json();
318
+ };
319
+ getArticleAssetDownloadUrls = async (workspaceId, articleId, fileNames, fetchers) => {
320
+ const fetchV2 = fetchers?.customFetchV2 ?? customFetchV2;
321
+ const response = await fetchV2(
322
+ `/workspaces/${workspaceId}/articles/${articleId}/assets/download-urls`,
323
+ { method: "POST", body: JSON.stringify({ fileNames }) }
324
+ );
325
+ if (!response.ok) {
326
+ throw new errors_default(`Error resolving article assets. ${await response.text()}`, response.status);
327
+ }
328
+ return response.json();
329
+ };
330
+ getArticleMediaProxyUrls = async (workspaceId, articleId, urls, fetchers) => {
331
+ const fetchV2 = fetchers?.customFetchV2 ?? customFetchV2;
332
+ const response = await fetchV2(
333
+ `/workspaces/${workspaceId}/articles/${articleId}/presentation/media-urls`,
334
+ { method: "POST", body: JSON.stringify({ urls }) }
335
+ );
336
+ if (!response.ok) {
337
+ throw new errors_default(`Error resolving article media. ${await response.text()}`, response.status);
338
+ }
339
+ return response.json();
340
+ };
341
+ getArticleSafeGists = async (workspaceId, articleId, urls, fetchers) => {
342
+ const fetchV2 = fetchers?.customFetchV2 ?? customFetchV2;
343
+ const response = await fetchV2(
344
+ `/workspaces/${workspaceId}/articles/${articleId}/presentation/gists`,
345
+ { method: "POST", body: JSON.stringify({ urls }) }
346
+ );
347
+ if (!response.ok) throw new errors_default(`Error loading Gists. ${await response.text()}`, response.status);
348
+ return response.json();
349
+ };
260
350
  deleteArticle = async (workspaceId, articleId, fetchers) => {
261
351
  const fetchV2 = fetchers?.customFetchV2 ?? customFetchV2;
262
352
  const response = await fetchV2(
@@ -285,6 +375,33 @@ var init_dist = __esm({
285
375
  }
286
376
  return response.blob();
287
377
  };
378
+ createArticleExportJob = async (workspaceId, articleId, format, fetchers) => {
379
+ const fetchV2 = fetchers?.customFetchV2 ?? customFetchV2;
380
+ const response = await fetchV2(
381
+ `/workspaces/${workspaceId}/articles/${articleId}/export`,
382
+ {
383
+ method: "POST",
384
+ body: JSON.stringify({ format })
385
+ }
386
+ );
387
+ if (!response.ok) {
388
+ throw new errors_default(
389
+ `Error exporting article. ${await response.text()}`,
390
+ response.status
391
+ );
392
+ }
393
+ return response.json();
394
+ };
395
+ ApiError = class extends Error {
396
+ status;
397
+ data;
398
+ constructor(status, message, data) {
399
+ super(message);
400
+ this.name = "ApiError";
401
+ this.status = status;
402
+ this.data = data;
403
+ }
404
+ };
288
405
  saveArticleContent = async (workspaceId, articleId, content, optionsOrFetchers, fetchers) => {
289
406
  const maybeFetchers = optionsOrFetchers && "customFetchV2" in optionsOrFetchers ? optionsOrFetchers : fetchers;
290
407
  const options = optionsOrFetchers && !("customFetchV2" in optionsOrFetchers) ? optionsOrFetchers : void 0;
@@ -1803,23 +1920,21 @@ function requestedPublicationMode(options) {
1803
1920
  if (options.live) return "live";
1804
1921
  return void 0;
1805
1922
  }
1806
- function publishRequest(options, defaultMode) {
1923
+ function publishRequest(options, defaultModeIfUnpublished) {
1807
1924
  const seoMetadata = {
1808
1925
  ...options.seoTitle ? { title: options.seoTitle } : {},
1809
1926
  ...options.seoDescription ? { description: options.seoDescription } : {}
1810
1927
  };
1811
- const mode = requestedPublicationMode(options) ?? defaultMode;
1928
+ const mode = requestedPublicationMode(options);
1812
1929
  return {
1813
1930
  ...options.slug ? { customSlug: options.slug } : {},
1814
1931
  ...Object.keys(seoMetadata).length > 0 ? { seoMetadata } : {},
1815
- ...mode ? { mode } : {}
1932
+ ...mode ? { mode } : {},
1933
+ ...!mode && defaultModeIfUnpublished ? { defaultModeIfUnpublished } : {}
1816
1934
  };
1817
1935
  }
1818
- async function agentPublishRequest(client, workspaceId, articleId, options) {
1819
- const requestedMode = requestedPublicationMode(options);
1820
- if (requestedMode) return publishRequest(options);
1821
- const status = await client.publish.status(workspaceId, articleId);
1822
- return publishRequest(options, status.isPublished ? void 0 : "live");
1936
+ function agentPublishRequest(options) {
1937
+ return publishRequest(options, "live");
1823
1938
  }
1824
1939
  async function readEditOperations(filePath) {
1825
1940
  const raw = await readFile(filePath, "utf-8");
@@ -2056,7 +2171,7 @@ function createArticleCommands() {
2056
2171
  const result = await client.publish.publish(
2057
2172
  workspaceId,
2058
2173
  articleId,
2059
- await agentPublishRequest(client, workspaceId, articleId, options)
2174
+ agentPublishRequest(options)
2060
2175
  );
2061
2176
  output.success("Article published publicly");
2062
2177
  output.output(result);