@velocity-astro/cms-astro 0.1.0-beta.11 → 0.1.0-beta.13

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 (38) hide show
  1. package/agents/cms.md +145 -0
  2. package/agents/skills/cms-add-content-type/SKILL.md +81 -0
  3. package/agents/skills/cms-add-form/SKILL.md +85 -0
  4. package/agents/skills/cms-add-section/SKILL.md +97 -0
  5. package/agents/skills/cms-add-to-site/SKILL.md +57 -0
  6. package/agents/skills/cms-connect-page/SKILL.md +64 -0
  7. package/agents/skills/cms-deploy/SKILL.md +64 -0
  8. package/agents/skills/cms-import-content/SKILL.md +63 -0
  9. package/agents/skills/cms-set-up-crm/SKILL.md +53 -0
  10. package/agents/skills/cms-write-plugin/SKILL.md +81 -0
  11. package/dist/agent-files.d.ts +23 -0
  12. package/dist/agent-files.d.ts.map +1 -0
  13. package/dist/agent-files.js +84 -0
  14. package/dist/agent-files.js.map +1 -0
  15. package/dist/check.d.ts +38 -0
  16. package/dist/check.d.ts.map +1 -0
  17. package/dist/check.js +194 -0
  18. package/dist/check.js.map +1 -0
  19. package/dist/cli-content.d.ts +22 -0
  20. package/dist/cli-content.d.ts.map +1 -0
  21. package/dist/cli-content.js +309 -0
  22. package/dist/cli-content.js.map +1 -0
  23. package/dist/cli.d.ts +3 -0
  24. package/dist/cli.d.ts.map +1 -1
  25. package/dist/cli.js +128 -5
  26. package/dist/cli.js.map +1 -1
  27. package/dist/editor.d.ts.map +1 -1
  28. package/dist/editor.js +1 -0
  29. package/dist/editor.js.map +1 -1
  30. package/dist/import-files.d.ts +30 -0
  31. package/dist/import-files.d.ts.map +1 -0
  32. package/dist/import-files.js +100 -0
  33. package/dist/import-files.js.map +1 -0
  34. package/dist/site-client.d.ts +37 -0
  35. package/dist/site-client.d.ts.map +1 -0
  36. package/dist/site-client.js +73 -0
  37. package/dist/site-client.js.map +1 -0
  38. package/package.json +8 -7
@@ -0,0 +1,30 @@
1
+ /** One entry read from a file, before it is sent: its slug, its language if it says one, and its values by key. */
2
+ export interface ImportItem {
3
+ /** Where it came from, for the report. */
4
+ readonly source: string;
5
+ /** The folder of the file it came from, where pictures it names by a relative path are looked for. */
6
+ readonly dir: string;
7
+ readonly slug: string;
8
+ readonly locale?: string;
9
+ readonly values: Record<string, unknown>;
10
+ /** The Markdown under the front matter, if the file was Markdown. */
11
+ readonly body?: string;
12
+ }
13
+ /** A slug made from a file's name or a title: lowercase words joined by hyphens. */
14
+ export declare function slugFrom(text: string): string;
15
+ /**
16
+ * The front matter of a Markdown file and what follows it. Only the plain part of YAML that
17
+ * blogs use is read: `key: value`, lists of `- item` under a key, and `key: |` blocks of text.
18
+ */
19
+ export declare function readFrontMatter(text: string): {
20
+ readonly data: Record<string, unknown>;
21
+ readonly body: string;
22
+ };
23
+ /**
24
+ * What a file or a folder holds, as entries to import: a JSON file of a list of entries (each
25
+ * `{ slug, locale?, data }`, or its values beside the slug), a Markdown file, or a folder of
26
+ * Markdown files. A Markdown file's slug is its front matter's `slug`, else its file's name
27
+ * (or its folder's, for `index.md`), so old addresses are kept.
28
+ */
29
+ export declare function readImport(target: string): ImportItem[];
30
+ //# sourceMappingURL=import-files.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"import-files.d.ts","sourceRoot":"","sources":["../src/import-files.ts"],"names":[],"mappings":"AAGA,mHAAmH;AACnH,MAAM,WAAW,UAAU;IACzB,0CAA0C;IAC1C,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,sGAAsG;IACtG,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACzC,qEAAqE;IACrE,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;CACxB;AAID,oFAAoF;AACpF,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAQ7C;AAaD;;;GAGG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAwB/G;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,UAAU,EAAE,CAoBvD"}
@@ -0,0 +1,100 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ const MARKDOWN = new Set(['.md', '.mdx', '.markdown']);
4
+ /** A slug made from a file's name or a title: lowercase words joined by hyphens. */
5
+ export function slugFrom(text) {
6
+ return text
7
+ .normalize('NFKD')
8
+ .replace(/[̀-ͯ]/g, '')
9
+ .toLowerCase()
10
+ .replace(/[^a-z0-9]+/g, '-')
11
+ .replace(/^-+|-+$/g, '')
12
+ .slice(0, 100);
13
+ }
14
+ /** One value of front matter: a quoted or plain string, a number, true or false, or `[a, b]`. */
15
+ function scalar(raw) {
16
+ const text = raw.trim();
17
+ if (text === '' || text === '~' || text === 'null')
18
+ return null;
19
+ if (/^(['"])(.*)\1$/.test(text))
20
+ return text.slice(1, -1).replace(/\\"/g, '"').replace(/''/g, "'");
21
+ if (text === 'true' || text === 'false')
22
+ return text === 'true';
23
+ if (/^-?\d+(\.\d+)?$/.test(text))
24
+ return Number(text);
25
+ if (text.startsWith('[') && text.endsWith(']'))
26
+ return text.slice(1, -1).split(',').map((part) => scalar(part)).filter((part) => part !== null);
27
+ return text;
28
+ }
29
+ /**
30
+ * The front matter of a Markdown file and what follows it. Only the plain part of YAML that
31
+ * blogs use is read: `key: value`, lists of `- item` under a key, and `key: |` blocks of text.
32
+ */
33
+ export function readFrontMatter(text) {
34
+ const match = /^---\r?\n([\s\S]*?)\r?\n---\r?\n?([\s\S]*)$/.exec(text);
35
+ if (!match)
36
+ return { data: {}, body: text };
37
+ const data = {};
38
+ const lines = (match[1] ?? '').split(/\r?\n/);
39
+ for (let at = 0; at < lines.length; at++) {
40
+ const line = lines[at] ?? '';
41
+ const pair = /^([A-Za-z_][\w-]*)\s*:\s*(.*)$/.exec(line);
42
+ if (!pair)
43
+ continue;
44
+ const key = pair[1] ?? '';
45
+ const rest = pair[2] ?? '';
46
+ if (rest === '|' || rest === '>') {
47
+ const block = [];
48
+ while (at + 1 < lines.length && /^\s+\S|^\s*$/.test(lines[at + 1] ?? ''))
49
+ block.push((lines[++at] ?? '').replace(/^\s{2}/, ''));
50
+ data[key] = block.join(rest === '|' ? '\n' : ' ').trim();
51
+ }
52
+ else if (rest.trim() === '') {
53
+ const items = [];
54
+ while (at + 1 < lines.length && /^\s*-\s+/.test(lines[at + 1] ?? ''))
55
+ items.push(scalar((lines[++at] ?? '').replace(/^\s*-\s+/, '')));
56
+ data[key] = items.length > 0 ? items : null;
57
+ }
58
+ else {
59
+ data[key] = scalar(rest);
60
+ }
61
+ }
62
+ return { data, body: match[2] ?? '' };
63
+ }
64
+ /**
65
+ * What a file or a folder holds, as entries to import: a JSON file of a list of entries (each
66
+ * `{ slug, locale?, data }`, or its values beside the slug), a Markdown file, or a folder of
67
+ * Markdown files. A Markdown file's slug is its front matter's `slug`, else its file's name
68
+ * (or its folder's, for `index.md`), so old addresses are kept.
69
+ */
70
+ export function readImport(target) {
71
+ const stat = fs.statSync(target);
72
+ if (stat.isDirectory()) {
73
+ return fs
74
+ .readdirSync(target, { recursive: true, encoding: 'utf8' })
75
+ .filter((name) => MARKDOWN.has(path.extname(name).toLowerCase()))
76
+ .sort()
77
+ .map((name) => readMarkdown(path.join(target, name), path.relative(target, path.join(target, name))));
78
+ }
79
+ if (path.extname(target).toLowerCase() === '.json') {
80
+ const parsed = JSON.parse(fs.readFileSync(target, 'utf8'));
81
+ const list = Array.isArray(parsed) ? parsed : [parsed];
82
+ return list.map((item, index) => {
83
+ const record = (typeof item === 'object' && item !== null ? item : {});
84
+ const { slug, locale, data, ...rest } = record;
85
+ const values = typeof data === 'object' && data !== null ? data : rest;
86
+ return { source: `${path.basename(target)} #${index + 1}`, dir: path.dirname(target), slug: typeof slug === 'string' ? slug : '', ...(typeof locale === 'string' && { locale }), values };
87
+ });
88
+ }
89
+ return [readMarkdown(target, path.basename(target))];
90
+ }
91
+ function readMarkdown(file, source) {
92
+ const { data, body } = readFrontMatter(fs.readFileSync(file, 'utf8'));
93
+ const { slug, locale, ...values } = data;
94
+ const base = path.basename(file, path.extname(file));
95
+ const named = base === 'index' ? path.basename(path.dirname(file)) : base;
96
+ // A dated file name, `2024-05-01-hello.md`, keeps only its words.
97
+ const fromName = slugFrom(named.replace(/^\d{4}-\d{2}-\d{2}-/, ''));
98
+ return { source, dir: path.dirname(file), slug: typeof slug === 'string' && slug !== '' ? slug : fromName, ...(typeof locale === 'string' && { locale }), values, body };
99
+ }
100
+ //# sourceMappingURL=import-files.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"import-files.js","sourceRoot":"","sources":["../src/import-files.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAe7B,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC,CAAC,KAAK,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC;AAEvD,oFAAoF;AACpF,MAAM,UAAU,QAAQ,CAAC,IAAY;IACnC,OAAO,IAAI;SACR,SAAS,CAAC,MAAM,CAAC;SACjB,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC;SACrB,WAAW,EAAE;SACb,OAAO,CAAC,aAAa,EAAE,GAAG,CAAC;SAC3B,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC;SACvB,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;AACnB,CAAC;AAED,iGAAiG;AACjG,SAAS,MAAM,CAAC,GAAW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EAAE,MAAc;IAChD,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,eAAe,CAAC,EAAE,CAAC,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC;IACtE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,GAAG,IAAI,CAAC;IACzC,MAAM,IAAI,GAAG,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;IACrD,MAAM,KAAK,GAAG,IAAI,KAAK,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IAC1E,kEAAkE;IAClE,MAAM,QAAQ,GAAG,QAAQ,CAAC,KAAK,CAAC,OAAO,CAAC,qBAAqB,EAAE,EAAE,CAAC,CAAC,CAAC;IACpE,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,KAAK,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,QAAQ,EAAE,GAAG,CAAC,OAAO,MAAM,KAAK,QAAQ,IAAI,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;AAC3K,CAAC"}
@@ -0,0 +1,37 @@
1
+ /**
2
+ * How the `velocity-cms` command reaches a site's content: over the site's own API, with an
3
+ * access token, so it works the same on this computer and on the live site, and goes through
4
+ * every rule, plugin and cache the site has. Content commands call the same tools an AI agent
5
+ * calls over MCP (`/api/cms/mcp`), so the two can never disagree.
6
+ */
7
+ /** A refusal from the site, in its own words: what happened and what to do. */
8
+ export declare class SiteRefusal extends Error {
9
+ readonly name = "SiteRefusal";
10
+ }
11
+ export interface SiteClientOptions {
12
+ /** The site's address, such as `https://example.com` or `http://localhost:4321`. */
13
+ readonly origin: string;
14
+ /** An access token, `vcms_…`, made in the editor (Settings, Access tokens) or with `velocity-cms token`. */
15
+ readonly token: string;
16
+ /** Where the API is served. Defaults to `/api/cms`. */
17
+ readonly apiPath?: string;
18
+ readonly fetch?: typeof fetch;
19
+ }
20
+ /** The content type an image upload is sent as, from its file's name, or `null` for one the CMS does not take. */
21
+ export declare function imageTypeOf(fileName: string): string | null;
22
+ export declare class SiteClient {
23
+ #private;
24
+ constructor(options: SiteClientOptions);
25
+ /** Where the site's MCP server is. */
26
+ get mcpAddress(): string;
27
+ /** Hands one JSON-RPC message to the site's MCP server as it is, and its answer back (`null` for a notification). */
28
+ relay(message: string): Promise<string | null>;
29
+ /** Calls one of the site's MCP tools and returns what it answered, or throws its refusal. */
30
+ tool<T = unknown>(name: string, args?: Record<string, unknown>): Promise<T>;
31
+ /** Uploads one image. Answers with what an image field stores: its name. */
32
+ upload(fileName: string, bytes: Uint8Array): Promise<{
33
+ readonly name: string;
34
+ readonly url: string;
35
+ }>;
36
+ }
37
+ //# sourceMappingURL=site-client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"site-client.d.ts","sourceRoot":"","sources":["../src/site-client.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,+EAA+E;AAC/E,qBAAa,WAAY,SAAQ,KAAK;IACpC,SAAkB,IAAI,iBAAiB;CACxC;AAED,MAAM,WAAW,iBAAiB;IAChC,oFAAoF;IACpF,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,4GAA4G;IAC5G,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,uDAAuD;IACvD,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,KAAK,CAAC;CAC/B;AAID,kHAAkH;AAClH,wBAAgB,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAE3D;AAED,qBAAa,UAAU;;gBAMT,OAAO,EAAE,iBAAiB;IAMtC,sCAAsC;IACtC,IAAI,UAAU,IAAI,MAAM,CAEvB;IAED,qHAAqH;IAC/G,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAKpD,6FAA6F;IACvF,IAAI,CAAC,CAAC,GAAG,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM,GAAG,OAAO,CAAC,CAAC,CAAC;IASrF,4EAA4E;IACtE,MAAM,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,GAAG,OAAO,CAAC;QAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;KAAE,CAAC;CAsB5G"}
@@ -0,0 +1,73 @@
1
+ /**
2
+ * How the `velocity-cms` command reaches a site's content: over the site's own API, with an
3
+ * access token, so it works the same on this computer and on the live site, and goes through
4
+ * every rule, plugin and cache the site has. Content commands call the same tools an AI agent
5
+ * calls over MCP (`/api/cms/mcp`), so the two can never disagree.
6
+ */
7
+ /** A refusal from the site, in its own words: what happened and what to do. */
8
+ export class SiteRefusal extends Error {
9
+ name = 'SiteRefusal';
10
+ }
11
+ const IMAGE_TYPES = { jpg: 'image/jpeg', jpeg: 'image/jpeg', png: 'image/png', webp: 'image/webp' };
12
+ /** The content type an image upload is sent as, from its file's name, or `null` for one the CMS does not take. */
13
+ export function imageTypeOf(fileName) {
14
+ return IMAGE_TYPES[fileName.split('.').pop()?.toLowerCase() ?? ''] ?? null;
15
+ }
16
+ export class SiteClient {
17
+ #base;
18
+ #token;
19
+ #fetch;
20
+ #next = 1;
21
+ constructor(options) {
22
+ this.#base = `${options.origin.replace(/\/+$/, '')}/${(options.apiPath ?? '/api/cms').split('/').filter(Boolean).join('/')}`;
23
+ this.#token = options.token;
24
+ this.#fetch = options.fetch ?? fetch;
25
+ }
26
+ /** Where the site's MCP server is. */
27
+ get mcpAddress() {
28
+ return `${this.#base}/mcp`;
29
+ }
30
+ /** Hands one JSON-RPC message to the site's MCP server as it is, and its answer back (`null` for a notification). */
31
+ async relay(message) {
32
+ const response = await this.#post('/mcp', 'application/json', message);
33
+ return response.status === 202 ? null : response.text();
34
+ }
35
+ /** Calls one of the site's MCP tools and returns what it answered, or throws its refusal. */
36
+ async tool(name, args = {}) {
37
+ const response = await this.#post('/mcp', 'application/json', JSON.stringify({ jsonrpc: '2.0', id: this.#next++, method: 'tools/call', params: { name, arguments: args } }));
38
+ const answer = (await response.json());
39
+ if (answer.error)
40
+ throw new SiteRefusal(answer.error.message ?? 'The site refused the request.');
41
+ const text = answer.result?.content?.[0]?.text ?? '';
42
+ if (answer.result?.isError)
43
+ throw new SiteRefusal(text);
44
+ return JSON.parse(text === '' ? '{}' : text);
45
+ }
46
+ /** Uploads one image. Answers with what an image field stores: its name. */
47
+ async upload(fileName, bytes) {
48
+ const type = imageTypeOf(fileName);
49
+ if (type === null)
50
+ throw new SiteRefusal(`${fileName} is not an image the CMS takes. Use a JPEG, PNG or WebP file.`);
51
+ const response = await this.#post(`/images?name=${encodeURIComponent(fileName)}`, type, bytes);
52
+ return (await response.json());
53
+ }
54
+ async #post(path, contentType, body) {
55
+ let response;
56
+ try {
57
+ response = await this.#fetch(`${this.#base}${path}`, { method: 'POST', headers: { authorization: `Bearer ${this.#token}`, 'content-type': contentType, accept: 'application/json' }, body });
58
+ }
59
+ catch {
60
+ throw new SiteRefusal(`The site at ${new URL(this.#base).origin} did not answer. Is it running? Start it, or set VELOCITY_CMS_ORIGIN to its address.`);
61
+ }
62
+ if (response.status === 401)
63
+ throw new SiteRefusal('The site did not accept the token. Make a new one in the editor (Settings, Access tokens) or with `velocity-cms token`, and set VELOCITY_CMS_TOKEN.');
64
+ if (response.status === 404)
65
+ throw new SiteRefusal(`There is no Velocity CMS at ${new URL(this.#base).origin}, or it is older than this command. Check VELOCITY_CMS_ORIGIN, and update @velocity-astro/cms-astro.`);
66
+ if (!response.ok) {
67
+ const body = (await response.json().catch(() => null));
68
+ throw new SiteRefusal(body?.error?.message ?? `The site answered ${response.status}.`);
69
+ }
70
+ return response;
71
+ }
72
+ }
73
+ //# sourceMappingURL=site-client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"site-client.js","sourceRoot":"","sources":["../src/site-client.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,+EAA+E;AAC/E,MAAM,OAAO,WAAY,SAAQ,KAAK;IAClB,IAAI,GAAG,aAAa,CAAC;CACxC;AAYD,MAAM,WAAW,GAAqC,EAAE,GAAG,EAAE,YAAY,EAAE,IAAI,EAAE,YAAY,EAAE,GAAG,EAAE,WAAW,EAAE,IAAI,EAAE,YAAY,EAAE,CAAC;AAEtI,kHAAkH;AAClH,MAAM,UAAU,WAAW,CAAC,QAAgB;IAC1C,OAAO,WAAW,CAAC,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC,IAAI,IAAI,CAAC;AAC7E,CAAC;AAED,MAAM,OAAO,UAAU;IACZ,KAAK,CAAS;IACd,MAAM,CAAS;IACf,MAAM,CAAe;IAC9B,KAAK,GAAG,CAAC,CAAC;IAEV,YAAY,OAA0B;QACpC,IAAI,CAAC,KAAK,GAAG,GAAG,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,IAAI,UAAU,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;QAC7H,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC;QAC5B,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,KAAK,IAAI,KAAK,CAAC;IACvC,CA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CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;YACjB,MAAM,IAAI,GAAG,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,CAA4C,CAAC;YAClG,MAAM,IAAI,WAAW,CAAC,IAAI,EAAE,KAAK,EAAE,OAAO,IAAI,qBAAqB,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC;QACzF,CAAC;QACD,OAAO,QAAQ,CAAC;IAClB,CAAC;CACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@velocity-astro/cms-astro",
3
- "version": "0.1.0-beta.11",
3
+ "version": "0.1.0-beta.13",
4
4
  "description": "The Astro side of Velocity CMS: a live loader for pages rendered on demand, a Content Layer loader for static builds, and the integration.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -31,15 +31,16 @@
31
31
  "dist",
32
32
  "routes",
33
33
  "bin",
34
+ "agents",
34
35
  "!dist/**/*.test.*"
35
36
  ],
36
37
  "dependencies": {
37
- "@velocity-astro/cms-admin": "0.1.0-beta.11",
38
- "@velocity-astro/cms-api": "0.1.0-beta.11",
39
- "@velocity-astro/cms-core": "0.1.0-beta.11",
40
- "@velocity-astro/cms-db": "0.1.0-beta.11",
41
- "@velocity-astro/cms-plugins": "0.1.0-beta.11",
42
- "@velocity-astro/cms-auth": "0.1.0-beta.11"
38
+ "@velocity-astro/cms-auth": "0.1.0-beta.13",
39
+ "@velocity-astro/cms-api": "0.1.0-beta.13",
40
+ "@velocity-astro/cms-db": "0.1.0-beta.13",
41
+ "@velocity-astro/cms-admin": "0.1.0-beta.13",
42
+ "@velocity-astro/cms-plugins": "0.1.0-beta.13",
43
+ "@velocity-astro/cms-core": "0.1.0-beta.13"
43
44
  },
44
45
  "optionalDependencies": {
45
46
  "sharp": "^0.35.4"