@mainsoft/agent-cms 0.0.0-stage → 0.7.0
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/CHANGELOG.md +54 -0
- package/LICENSE +21 -0
- package/README.md +359 -2
- package/TODO.md +178 -0
- package/UPGRADE-0.6.md +236 -0
- package/dist/agent.cjs +250 -0
- package/dist/agent.d.cts +88 -0
- package/dist/agent.d.ts +88 -0
- package/dist/agent.js +24 -0
- package/dist/ai.cjs +555 -0
- package/dist/ai.d.cts +48 -0
- package/dist/ai.d.ts +48 -0
- package/dist/ai.js +73 -0
- package/dist/bin.js +1556 -0
- package/dist/chunk-2NTK7H4W.js +10 -0
- package/dist/chunk-52NUUZC7.js +1446 -0
- package/dist/chunk-6K5ZTGHQ.js +30 -0
- package/dist/chunk-AKN7SUXU.js +281 -0
- package/dist/chunk-CRDW6Q72.js +188 -0
- package/dist/chunk-DD56PTZ4.js +78 -0
- package/dist/chunk-DOADAH4L.js +52 -0
- package/dist/chunk-EXV6JNLY.js +251 -0
- package/dist/chunk-IGL2V6US.js +324 -0
- package/dist/chunk-IW3D4I7Q.js +317 -0
- package/dist/chunk-OQ55GEF3.js +6 -0
- package/dist/chunk-QC2M4NZY.js +158 -0
- package/dist/chunk-QQV6VLYJ.js +204 -0
- package/dist/chunk-T66ZKBHF.js +25 -0
- package/dist/chunk-VICZ76TR.js +118 -0
- package/dist/chunk-Y63XQS2J.js +6 -0
- package/dist/cli.cjs +1596 -0
- package/dist/cli.d.cts +89 -0
- package/dist/cli.d.ts +89 -0
- package/dist/cli.js +534 -0
- package/dist/client.cjs +185 -0
- package/dist/client.d.cts +228 -0
- package/dist/client.d.ts +228 -0
- package/dist/client.js +13 -0
- package/dist/cms-BPp01z-8.d.ts +411 -0
- package/dist/cms-D6D89-qZ.d.cts +411 -0
- package/dist/config.cjs +61 -0
- package/dist/config.d.cts +36 -0
- package/dist/config.d.ts +36 -0
- package/dist/config.js +11 -0
- package/dist/diff.cjs +316 -0
- package/dist/diff.d.cts +122 -0
- package/dist/diff.d.ts +122 -0
- package/dist/diff.js +29 -0
- package/dist/drizzle-repo-B1rt7r4j.d.ts +90 -0
- package/dist/drizzle-repo-Cn-kL2FK.d.cts +90 -0
- package/dist/errors.cjs +193 -0
- package/dist/errors.d.cts +109 -0
- package/dist/errors.d.ts +109 -0
- package/dist/errors.js +16 -0
- package/dist/frontmatter.cjs +103 -0
- package/dist/frontmatter.d.cts +32 -0
- package/dist/frontmatter.d.ts +32 -0
- package/dist/frontmatter.js +9 -0
- package/dist/http.cjs +1105 -0
- package/dist/http.d.cts +75 -0
- package/dist/http.d.ts +75 -0
- package/dist/http.js +321 -0
- package/dist/index.cjs +3066 -0
- package/dist/index.d.cts +19 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.js +263 -0
- package/dist/markdown.cjs +220 -0
- package/dist/markdown.d.cts +88 -0
- package/dist/markdown.d.ts +88 -0
- package/dist/markdown.js +23 -0
- package/dist/mcp.cjs +652 -0
- package/dist/mcp.d.cts +43 -0
- package/dist/mcp.d.ts +43 -0
- package/dist/mcp.js +26 -0
- package/dist/messages/en.cjs +76 -0
- package/dist/messages/en.d.cts +7 -0
- package/dist/messages/en.d.ts +7 -0
- package/dist/messages/en.js +7 -0
- package/dist/messages/ko.cjs +76 -0
- package/dist/messages/ko.d.cts +7 -0
- package/dist/messages/ko.d.ts +7 -0
- package/dist/messages/ko.js +53 -0
- package/dist/registry/cms-audit.json +25 -0
- package/dist/registry/cms-command.json +23 -0
- package/dist/registry/cms-doc-editor.json +36 -0
- package/dist/registry/cms-doc-list.json +29 -0
- package/dist/registry/cms-empty.json +22 -0
- package/dist/registry/cms-keys.json +29 -0
- package/dist/registry/cms-lib.json +33 -0
- package/dist/registry/cms-merge.json +26 -0
- package/dist/registry/cms-shell.json +22 -0
- package/dist/registry/cms-versions.json +26 -0
- package/dist/registry/registry.json +255 -0
- package/dist/repo-BWI2Pkrv.d.ts +162 -0
- package/dist/repo-CeDxUxO6.d.cts +162 -0
- package/dist/tables.cjs +356 -0
- package/dist/tables.d.cts +3515 -0
- package/dist/tables.d.ts +3515 -0
- package/dist/tables.js +35 -0
- package/dist/tools.cjs +420 -0
- package/dist/tools.d.cts +27 -0
- package/dist/tools.d.ts +27 -0
- package/dist/tools.js +18 -0
- package/dist/types.cjs +226 -0
- package/dist/types.d.cts +286 -0
- package/dist/types.d.ts +286 -0
- package/dist/types.js +28 -0
- package/package.json +277 -4
package/dist/mcp.d.cts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { C as CmsLike } from './cms-D6D89-qZ.cjs';
|
|
4
|
+
import { Actor } from './types.cjs';
|
|
5
|
+
import './diff.cjs';
|
|
6
|
+
import './errors.cjs';
|
|
7
|
+
import './repo-CeDxUxO6.cjs';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* MCP over Streamable HTTP with the official SDK (`@modelcontextprotocol/sdk`),
|
|
11
|
+
* stateless: every POST is answered with plain JSON, no sessions. A coding
|
|
12
|
+
* agent registers `https://app/api/cms/mcp` with `Authorization: Bearer sgk_…`
|
|
13
|
+
* and gets the same rules as REST, because both call `cms`.
|
|
14
|
+
*
|
|
15
|
+
* Tools are the shared list in `tools.ts`. Published documents are also
|
|
16
|
+
* resources (`cms://<collection>/<slug>`), and two prompts show how to answer
|
|
17
|
+
* from the CMS and how to edit it safely.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
interface McpOptions {
|
|
21
|
+
/**
|
|
22
|
+
* `"read"`: requests without a key get the read tools below and see only
|
|
23
|
+
* published documents of collections anyone may read. Default `false`
|
|
24
|
+
* (401 without a key).
|
|
25
|
+
*/
|
|
26
|
+
anonymous?: "read" | false;
|
|
27
|
+
}
|
|
28
|
+
/** Tools a keyless caller gets with `mcp: { anonymous: "read" }`. */
|
|
29
|
+
declare const ANONYMOUS_READ_TOOLS: readonly ["list_collections", "search_documents", "read_for_answer", "list_documents", "get_document"];
|
|
30
|
+
/**
|
|
31
|
+
* JSON Schema for a zod schema (the subset tool inputs and collection fields
|
|
32
|
+
* use). Reads `_def.typeName` rather than `instanceof`, so schemas made by
|
|
33
|
+
* another copy of zod (an app bundle, ESM next to CJS) work too. zod 4
|
|
34
|
+
* schemas go through zod's own `toJSONSchema`.
|
|
35
|
+
*/
|
|
36
|
+
declare function toJsonSchema(schema: z.ZodTypeAny): Record<string, unknown>;
|
|
37
|
+
declare const MCP_INSTRUCTIONS: string;
|
|
38
|
+
/** The MCP server for one actor (stateless: built per request). */
|
|
39
|
+
declare function createMcpServer(cms: CmsLike, actor: Actor): Server;
|
|
40
|
+
declare function handleMcp(cms: CmsLike, actor: Actor, req: Request, opts?: McpOptions): Promise<Response>;
|
|
41
|
+
declare const MCP_TOOL_NAMES: string[];
|
|
42
|
+
|
|
43
|
+
export { ANONYMOUS_READ_TOOLS, MCP_INSTRUCTIONS, MCP_TOOL_NAMES, type McpOptions, createMcpServer, handleMcp, toJsonSchema };
|
package/dist/mcp.d.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { C as CmsLike } from './cms-BPp01z-8.js';
|
|
4
|
+
import { Actor } from './types.js';
|
|
5
|
+
import './diff.js';
|
|
6
|
+
import './errors.js';
|
|
7
|
+
import './repo-BWI2Pkrv.js';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* MCP over Streamable HTTP with the official SDK (`@modelcontextprotocol/sdk`),
|
|
11
|
+
* stateless: every POST is answered with plain JSON, no sessions. A coding
|
|
12
|
+
* agent registers `https://app/api/cms/mcp` with `Authorization: Bearer sgk_…`
|
|
13
|
+
* and gets the same rules as REST, because both call `cms`.
|
|
14
|
+
*
|
|
15
|
+
* Tools are the shared list in `tools.ts`. Published documents are also
|
|
16
|
+
* resources (`cms://<collection>/<slug>`), and two prompts show how to answer
|
|
17
|
+
* from the CMS and how to edit it safely.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
interface McpOptions {
|
|
21
|
+
/**
|
|
22
|
+
* `"read"`: requests without a key get the read tools below and see only
|
|
23
|
+
* published documents of collections anyone may read. Default `false`
|
|
24
|
+
* (401 without a key).
|
|
25
|
+
*/
|
|
26
|
+
anonymous?: "read" | false;
|
|
27
|
+
}
|
|
28
|
+
/** Tools a keyless caller gets with `mcp: { anonymous: "read" }`. */
|
|
29
|
+
declare const ANONYMOUS_READ_TOOLS: readonly ["list_collections", "search_documents", "read_for_answer", "list_documents", "get_document"];
|
|
30
|
+
/**
|
|
31
|
+
* JSON Schema for a zod schema (the subset tool inputs and collection fields
|
|
32
|
+
* use). Reads `_def.typeName` rather than `instanceof`, so schemas made by
|
|
33
|
+
* another copy of zod (an app bundle, ESM next to CJS) work too. zod 4
|
|
34
|
+
* schemas go through zod's own `toJSONSchema`.
|
|
35
|
+
*/
|
|
36
|
+
declare function toJsonSchema(schema: z.ZodTypeAny): Record<string, unknown>;
|
|
37
|
+
declare const MCP_INSTRUCTIONS: string;
|
|
38
|
+
/** The MCP server for one actor (stateless: built per request). */
|
|
39
|
+
declare function createMcpServer(cms: CmsLike, actor: Actor): Server;
|
|
40
|
+
declare function handleMcp(cms: CmsLike, actor: Actor, req: Request, opts?: McpOptions): Promise<Response>;
|
|
41
|
+
declare const MCP_TOOL_NAMES: string[];
|
|
42
|
+
|
|
43
|
+
export { ANONYMOUS_READ_TOOLS, MCP_INSTRUCTIONS, MCP_TOOL_NAMES, type McpOptions, createMcpServer, handleMcp, toJsonSchema };
|
package/dist/mcp.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ANONYMOUS_READ_TOOLS,
|
|
3
|
+
MCP_INSTRUCTIONS,
|
|
4
|
+
MCP_TOOL_NAMES,
|
|
5
|
+
createMcpServer,
|
|
6
|
+
handleMcp,
|
|
7
|
+
toJsonSchema
|
|
8
|
+
} from "./chunk-EXV6JNLY.js";
|
|
9
|
+
import "./chunk-Y63XQS2J.js";
|
|
10
|
+
import "./chunk-QQV6VLYJ.js";
|
|
11
|
+
import "./chunk-52NUUZC7.js";
|
|
12
|
+
import "./chunk-6K5ZTGHQ.js";
|
|
13
|
+
import "./chunk-OQ55GEF3.js";
|
|
14
|
+
import "./chunk-AKN7SUXU.js";
|
|
15
|
+
import "./chunk-VICZ76TR.js";
|
|
16
|
+
import "./chunk-DOADAH4L.js";
|
|
17
|
+
import "./chunk-CRDW6Q72.js";
|
|
18
|
+
import "./chunk-2NTK7H4W.js";
|
|
19
|
+
export {
|
|
20
|
+
ANONYMOUS_READ_TOOLS,
|
|
21
|
+
MCP_INSTRUCTIONS,
|
|
22
|
+
MCP_TOOL_NAMES,
|
|
23
|
+
createMcpServer,
|
|
24
|
+
handleMcp,
|
|
25
|
+
toJsonSchema
|
|
26
|
+
};
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/messages/en.ts
|
|
21
|
+
var en_exports = {};
|
|
22
|
+
__export(en_exports, {
|
|
23
|
+
en: () => en
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(en_exports);
|
|
26
|
+
var en = {
|
|
27
|
+
not_found: "Document not found",
|
|
28
|
+
version_not_found: "Version v{version} not found",
|
|
29
|
+
key_not_found: "API key not found",
|
|
30
|
+
route_not_found: "No such route",
|
|
31
|
+
unknown_collection: "Unknown collection: {collection}",
|
|
32
|
+
unauthorized: "Sign in or use an API key",
|
|
33
|
+
invalid_key: "The API key is wrong or revoked",
|
|
34
|
+
key_expired: "The API key expired on {expiresAt}",
|
|
35
|
+
preview_invalid: "This preview link is not valid",
|
|
36
|
+
preview_expired: "This preview link expired",
|
|
37
|
+
forbidden: "Not allowed",
|
|
38
|
+
forbidden_read: "No read access to {collection}",
|
|
39
|
+
forbidden_write: "No edit access to {collection}",
|
|
40
|
+
forbidden_publish: "No publish access to {collection}",
|
|
41
|
+
forbidden_keys: "No access to API keys",
|
|
42
|
+
forbidden_audit: "No access to the audit log",
|
|
43
|
+
key_too_wide: "A key can only create keys narrower than itself",
|
|
44
|
+
cross_site: "Cross-site request refused",
|
|
45
|
+
invalid: "Invalid input",
|
|
46
|
+
invalid_slug: "The slug may use lowercase letters, digits and hyphens (max {max})",
|
|
47
|
+
invalid_title: "The title must be 1 to {max} characters",
|
|
48
|
+
summary_too_long: "The summary must be at most {max} characters",
|
|
49
|
+
body_too_long: "The body is too long (max {max} characters)",
|
|
50
|
+
invalid_keywords: "At most {max} keywords of {maxLength} characters each",
|
|
51
|
+
forbidden_char: "The character \u201C{char}\u201D is not allowed",
|
|
52
|
+
invalid_category: "The category must be one of: {allowed}",
|
|
53
|
+
invalid_field: "{path}: {issue}",
|
|
54
|
+
unknown_link: "Unknown screen link: {keys}",
|
|
55
|
+
slug_locked: "A published document's slug cannot change",
|
|
56
|
+
not_published: "Only a published document can be hidden",
|
|
57
|
+
invalid_key_name: "The key name must be 1 to 60 characters",
|
|
58
|
+
scopes_required: "Choose at least one scope",
|
|
59
|
+
invalid_expiry: "The expiry date must be in the future",
|
|
60
|
+
invalid_anchor: "No section \u201C{anchor}\u201D. Sections: {valid}",
|
|
61
|
+
invalid_version: "Invalid version number",
|
|
62
|
+
invalid_request: "Invalid request: {issues}",
|
|
63
|
+
invalid_json: "The request body is not valid JSON",
|
|
64
|
+
body_too_large: "The request is too large",
|
|
65
|
+
preview_disabled: "Preview links are off (set previewSecret)",
|
|
66
|
+
no_public_url: "This collection has no public URL (set url)",
|
|
67
|
+
schema_outdated: "The database schema is v{found}, this version needs v{expected}. Run: {command}",
|
|
68
|
+
conflict_version: "Someone else saved v{current} since you read v{expected}. Reload or merge, then save",
|
|
69
|
+
slug_taken: "The slug {slug} is already used",
|
|
70
|
+
precondition_required: "Send If-Match (or expectedVersion) to change this document",
|
|
71
|
+
internal: "Something went wrong"
|
|
72
|
+
};
|
|
73
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
74
|
+
0 && (module.exports = {
|
|
75
|
+
en
|
|
76
|
+
});
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/messages/ko.ts
|
|
21
|
+
var ko_exports = {};
|
|
22
|
+
__export(ko_exports, {
|
|
23
|
+
ko: () => ko
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(ko_exports);
|
|
26
|
+
var ko = {
|
|
27
|
+
not_found: "\uBB38\uC11C\uB97C \uCC3E\uC744 \uC218 \uC5C6\uC5B4\uC694",
|
|
28
|
+
version_not_found: "v{version} \uBC84\uC804\uC774 \uC5C6\uC5B4\uC694",
|
|
29
|
+
key_not_found: "API \uD0A4\uB97C \uCC3E\uC744 \uC218 \uC5C6\uC5B4\uC694",
|
|
30
|
+
route_not_found: "\uC5C6\uB294 \uACBD\uB85C\uC608\uC694",
|
|
31
|
+
unknown_collection: "\uC5C6\uB294 \uCEEC\uB809\uC158\uC774\uC5D0\uC694: {collection}",
|
|
32
|
+
unauthorized: "\uB85C\uADF8\uC778\uD558\uAC70\uB098 API \uD0A4\uB97C \uC368 \uC8FC\uC138\uC694",
|
|
33
|
+
invalid_key: "API \uD0A4\uAC00 \uC62C\uBC14\uB974\uC9C0 \uC54A\uAC70\uB098 \uD3D0\uAE30\uB410\uC5B4\uC694",
|
|
34
|
+
key_expired: "API \uD0A4\uAC00 {expiresAt}\uC5D0 \uB9CC\uB8CC\uB410\uC5B4\uC694",
|
|
35
|
+
preview_invalid: "\uC62C\uBC14\uB974\uC9C0 \uC54A\uC740 \uBBF8\uB9AC\uBCF4\uAE30 \uB9C1\uD06C\uC608\uC694",
|
|
36
|
+
preview_expired: "\uBBF8\uB9AC\uBCF4\uAE30 \uB9C1\uD06C\uAC00 \uB9CC\uB8CC\uB410\uC5B4\uC694",
|
|
37
|
+
forbidden: "\uAD8C\uD55C\uC774 \uC5C6\uC5B4\uC694",
|
|
38
|
+
forbidden_read: "{collection} \uC77D\uAE30 \uAD8C\uD55C\uC774 \uC5C6\uC5B4\uC694",
|
|
39
|
+
forbidden_write: "{collection} \uD3B8\uC9D1 \uAD8C\uD55C\uC774 \uC5C6\uC5B4\uC694",
|
|
40
|
+
forbidden_publish: "{collection} \uAC8C\uC2DC \uAD8C\uD55C\uC774 \uC5C6\uC5B4\uC694",
|
|
41
|
+
forbidden_keys: "API \uD0A4 \uAD00\uB9AC \uAD8C\uD55C\uC774 \uC5C6\uC5B4\uC694",
|
|
42
|
+
forbidden_audit: "\uAC10\uC0AC \uB85C\uADF8\uB97C \uBCFC \uAD8C\uD55C\uC774 \uC5C6\uC5B4\uC694",
|
|
43
|
+
key_too_wide: "\uC774 \uD0A4\uBCF4\uB2E4 \uB113\uC740 \uAD8C\uD55C\uC758 \uD0A4\uB294 \uB9CC\uB4E4 \uC218 \uC5C6\uC5B4\uC694",
|
|
44
|
+
cross_site: "\uB2E4\uB978 \uC0AC\uC774\uD2B8\uC5D0\uC11C \uC628 \uC694\uCCAD\uC774\uB77C \uAC70\uC808\uD588\uC5B4\uC694",
|
|
45
|
+
invalid: "\uC785\uB825\uC774 \uC62C\uBC14\uB974\uC9C0 \uC54A\uC544\uC694",
|
|
46
|
+
invalid_slug: "\uC8FC\uC18C(slug)\uB294 \uC601\uBB38 \uC18C\uBB38\uC790, \uC22B\uC790, \uD558\uC774\uD508\uB9CC \uC4F8 \uC218 \uC788\uC5B4\uC694(\uCD5C\uB300 {max}\uC790)",
|
|
47
|
+
invalid_title: "\uC81C\uBAA9\uC740 1~{max}\uC790\uB85C \uC368 \uC8FC\uC138\uC694",
|
|
48
|
+
summary_too_long: "\uC694\uC57D\uC740 {max}\uC790 \uC774\uD558\uB85C \uC368 \uC8FC\uC138\uC694",
|
|
49
|
+
body_too_long: "\uBCF8\uBB38\uC774 \uB108\uBB34 \uAE38\uC5B4\uC694(\uCD5C\uB300 {max}\uC790)",
|
|
50
|
+
invalid_keywords: "\uAC80\uC0C9\uC5B4\uB294 {max}\uAC1C, \uAC01 {maxLength}\uC790\uAE4C\uC9C0\uC608\uC694",
|
|
51
|
+
forbidden_char: "\u2018{char}\u2019 \uBB38\uC790\uB294 \uC4F8 \uC218 \uC5C6\uC5B4\uC694",
|
|
52
|
+
invalid_category: "\uBD84\uB958\uB294 {allowed} \uC911 \uD558\uB098\uB85C \uACE8\uB77C \uC8FC\uC138\uC694",
|
|
53
|
+
invalid_field: "{path}: {issue}",
|
|
54
|
+
unknown_link: "\uBAA8\uB974\uB294 \uD654\uBA74 \uB9C1\uD06C\uC608\uC694: {keys}",
|
|
55
|
+
slug_locked: "\uAC8C\uC2DC\uB41C \uBB38\uC11C\uC758 \uC8FC\uC18C\uB294 \uBC14\uAFC0 \uC218 \uC5C6\uC5B4\uC694",
|
|
56
|
+
not_published: "\uAC8C\uC2DC\uB41C \uBB38\uC11C\uB9CC \uC228\uAE38 \uC218 \uC788\uC5B4\uC694",
|
|
57
|
+
invalid_key_name: "\uD0A4 \uC774\uB984\uC740 1~60\uC790\uB85C \uC368 \uC8FC\uC138\uC694",
|
|
58
|
+
scopes_required: "\uAD8C\uD55C\uC744 \uD558\uB098 \uC774\uC0C1 \uACE8\uB77C \uC8FC\uC138\uC694",
|
|
59
|
+
invalid_expiry: "\uB9CC\uB8CC\uC77C\uC740 \uC624\uB298 \uC774\uD6C4\uB85C \uACE8\uB77C \uC8FC\uC138\uC694",
|
|
60
|
+
invalid_anchor: "\u201C{anchor}\u201D \uC139\uC158\uC774 \uC5C6\uC5B4\uC694. \uC788\uB294 \uC139\uC158: {valid}",
|
|
61
|
+
invalid_version: "\uBC84\uC804 \uBC88\uD638\uAC00 \uC62C\uBC14\uB974\uC9C0 \uC54A\uC544\uC694",
|
|
62
|
+
invalid_request: "\uC694\uCCAD\uC774 \uC62C\uBC14\uB974\uC9C0 \uC54A\uC544\uC694: {issues}",
|
|
63
|
+
invalid_json: "JSON \uD615\uC2DD\uC774 \uC62C\uBC14\uB974\uC9C0 \uC54A\uC544\uC694",
|
|
64
|
+
body_too_large: "\uC694\uCCAD\uC774 \uB108\uBB34 \uCEE4\uC694",
|
|
65
|
+
preview_disabled: "\uBBF8\uB9AC\uBCF4\uAE30 \uB9C1\uD06C\uAC00 \uAEBC\uC838 \uC788\uC5B4\uC694(previewSecret \uC124\uC815 \uD544\uC694)",
|
|
66
|
+
no_public_url: "\uC774 \uCEEC\uB809\uC158\uC5D0\uB294 \uACF5\uAC1C \uC8FC\uC18C\uAC00 \uC5C6\uC5B4\uC694(url \uC124\uC815 \uD544\uC694)",
|
|
67
|
+
schema_outdated: "DB \uC2A4\uD0A4\uB9C8\uAC00 v{found}\uC774\uACE0 \uC774 \uBC84\uC804\uC740 v{expected}\uAC00 \uD544\uC694\uD574\uC694. \uC2E4\uD589: {command}",
|
|
68
|
+
conflict_version: "v{expected}\uB97C \uC77D\uC740 \uB4A4 \uB2E4\uB978 \uACF3\uC5D0\uC11C v{current}\uB85C \uC800\uC7A5\uD588\uC5B4\uC694. \uB2E4\uC2DC \uBD88\uB7EC\uC624\uAC70\uB098 \uD569\uCE5C \uB4A4 \uC800\uC7A5\uD574 \uC8FC\uC138\uC694",
|
|
69
|
+
slug_taken: "\uC774\uBBF8 \uC4F0\uB294 \uC8FC\uC18C\uC608\uC694: {slug}",
|
|
70
|
+
precondition_required: "\uC774 \uBB38\uC11C\uB97C \uBC14\uAFB8\uB824\uBA74 If-Match(\uB610\uB294 expectedVersion)\uB97C \uBCF4\uB0B4 \uC8FC\uC138\uC694",
|
|
71
|
+
internal: "\uCC98\uB9AC \uC911 \uC624\uB958\uAC00 \uB0AC\uC5B4\uC694"
|
|
72
|
+
};
|
|
73
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
74
|
+
0 && (module.exports = {
|
|
75
|
+
ko
|
|
76
|
+
});
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import "../chunk-2NTK7H4W.js";
|
|
2
|
+
|
|
3
|
+
// src/messages/ko.ts
|
|
4
|
+
var ko = {
|
|
5
|
+
not_found: "\uBB38\uC11C\uB97C \uCC3E\uC744 \uC218 \uC5C6\uC5B4\uC694",
|
|
6
|
+
version_not_found: "v{version} \uBC84\uC804\uC774 \uC5C6\uC5B4\uC694",
|
|
7
|
+
key_not_found: "API \uD0A4\uB97C \uCC3E\uC744 \uC218 \uC5C6\uC5B4\uC694",
|
|
8
|
+
route_not_found: "\uC5C6\uB294 \uACBD\uB85C\uC608\uC694",
|
|
9
|
+
unknown_collection: "\uC5C6\uB294 \uCEEC\uB809\uC158\uC774\uC5D0\uC694: {collection}",
|
|
10
|
+
unauthorized: "\uB85C\uADF8\uC778\uD558\uAC70\uB098 API \uD0A4\uB97C \uC368 \uC8FC\uC138\uC694",
|
|
11
|
+
invalid_key: "API \uD0A4\uAC00 \uC62C\uBC14\uB974\uC9C0 \uC54A\uAC70\uB098 \uD3D0\uAE30\uB410\uC5B4\uC694",
|
|
12
|
+
key_expired: "API \uD0A4\uAC00 {expiresAt}\uC5D0 \uB9CC\uB8CC\uB410\uC5B4\uC694",
|
|
13
|
+
preview_invalid: "\uC62C\uBC14\uB974\uC9C0 \uC54A\uC740 \uBBF8\uB9AC\uBCF4\uAE30 \uB9C1\uD06C\uC608\uC694",
|
|
14
|
+
preview_expired: "\uBBF8\uB9AC\uBCF4\uAE30 \uB9C1\uD06C\uAC00 \uB9CC\uB8CC\uB410\uC5B4\uC694",
|
|
15
|
+
forbidden: "\uAD8C\uD55C\uC774 \uC5C6\uC5B4\uC694",
|
|
16
|
+
forbidden_read: "{collection} \uC77D\uAE30 \uAD8C\uD55C\uC774 \uC5C6\uC5B4\uC694",
|
|
17
|
+
forbidden_write: "{collection} \uD3B8\uC9D1 \uAD8C\uD55C\uC774 \uC5C6\uC5B4\uC694",
|
|
18
|
+
forbidden_publish: "{collection} \uAC8C\uC2DC \uAD8C\uD55C\uC774 \uC5C6\uC5B4\uC694",
|
|
19
|
+
forbidden_keys: "API \uD0A4 \uAD00\uB9AC \uAD8C\uD55C\uC774 \uC5C6\uC5B4\uC694",
|
|
20
|
+
forbidden_audit: "\uAC10\uC0AC \uB85C\uADF8\uB97C \uBCFC \uAD8C\uD55C\uC774 \uC5C6\uC5B4\uC694",
|
|
21
|
+
key_too_wide: "\uC774 \uD0A4\uBCF4\uB2E4 \uB113\uC740 \uAD8C\uD55C\uC758 \uD0A4\uB294 \uB9CC\uB4E4 \uC218 \uC5C6\uC5B4\uC694",
|
|
22
|
+
cross_site: "\uB2E4\uB978 \uC0AC\uC774\uD2B8\uC5D0\uC11C \uC628 \uC694\uCCAD\uC774\uB77C \uAC70\uC808\uD588\uC5B4\uC694",
|
|
23
|
+
invalid: "\uC785\uB825\uC774 \uC62C\uBC14\uB974\uC9C0 \uC54A\uC544\uC694",
|
|
24
|
+
invalid_slug: "\uC8FC\uC18C(slug)\uB294 \uC601\uBB38 \uC18C\uBB38\uC790, \uC22B\uC790, \uD558\uC774\uD508\uB9CC \uC4F8 \uC218 \uC788\uC5B4\uC694(\uCD5C\uB300 {max}\uC790)",
|
|
25
|
+
invalid_title: "\uC81C\uBAA9\uC740 1~{max}\uC790\uB85C \uC368 \uC8FC\uC138\uC694",
|
|
26
|
+
summary_too_long: "\uC694\uC57D\uC740 {max}\uC790 \uC774\uD558\uB85C \uC368 \uC8FC\uC138\uC694",
|
|
27
|
+
body_too_long: "\uBCF8\uBB38\uC774 \uB108\uBB34 \uAE38\uC5B4\uC694(\uCD5C\uB300 {max}\uC790)",
|
|
28
|
+
invalid_keywords: "\uAC80\uC0C9\uC5B4\uB294 {max}\uAC1C, \uAC01 {maxLength}\uC790\uAE4C\uC9C0\uC608\uC694",
|
|
29
|
+
forbidden_char: "\u2018{char}\u2019 \uBB38\uC790\uB294 \uC4F8 \uC218 \uC5C6\uC5B4\uC694",
|
|
30
|
+
invalid_category: "\uBD84\uB958\uB294 {allowed} \uC911 \uD558\uB098\uB85C \uACE8\uB77C \uC8FC\uC138\uC694",
|
|
31
|
+
invalid_field: "{path}: {issue}",
|
|
32
|
+
unknown_link: "\uBAA8\uB974\uB294 \uD654\uBA74 \uB9C1\uD06C\uC608\uC694: {keys}",
|
|
33
|
+
slug_locked: "\uAC8C\uC2DC\uB41C \uBB38\uC11C\uC758 \uC8FC\uC18C\uB294 \uBC14\uAFC0 \uC218 \uC5C6\uC5B4\uC694",
|
|
34
|
+
not_published: "\uAC8C\uC2DC\uB41C \uBB38\uC11C\uB9CC \uC228\uAE38 \uC218 \uC788\uC5B4\uC694",
|
|
35
|
+
invalid_key_name: "\uD0A4 \uC774\uB984\uC740 1~60\uC790\uB85C \uC368 \uC8FC\uC138\uC694",
|
|
36
|
+
scopes_required: "\uAD8C\uD55C\uC744 \uD558\uB098 \uC774\uC0C1 \uACE8\uB77C \uC8FC\uC138\uC694",
|
|
37
|
+
invalid_expiry: "\uB9CC\uB8CC\uC77C\uC740 \uC624\uB298 \uC774\uD6C4\uB85C \uACE8\uB77C \uC8FC\uC138\uC694",
|
|
38
|
+
invalid_anchor: "\u201C{anchor}\u201D \uC139\uC158\uC774 \uC5C6\uC5B4\uC694. \uC788\uB294 \uC139\uC158: {valid}",
|
|
39
|
+
invalid_version: "\uBC84\uC804 \uBC88\uD638\uAC00 \uC62C\uBC14\uB974\uC9C0 \uC54A\uC544\uC694",
|
|
40
|
+
invalid_request: "\uC694\uCCAD\uC774 \uC62C\uBC14\uB974\uC9C0 \uC54A\uC544\uC694: {issues}",
|
|
41
|
+
invalid_json: "JSON \uD615\uC2DD\uC774 \uC62C\uBC14\uB974\uC9C0 \uC54A\uC544\uC694",
|
|
42
|
+
body_too_large: "\uC694\uCCAD\uC774 \uB108\uBB34 \uCEE4\uC694",
|
|
43
|
+
preview_disabled: "\uBBF8\uB9AC\uBCF4\uAE30 \uB9C1\uD06C\uAC00 \uAEBC\uC838 \uC788\uC5B4\uC694(previewSecret \uC124\uC815 \uD544\uC694)",
|
|
44
|
+
no_public_url: "\uC774 \uCEEC\uB809\uC158\uC5D0\uB294 \uACF5\uAC1C \uC8FC\uC18C\uAC00 \uC5C6\uC5B4\uC694(url \uC124\uC815 \uD544\uC694)",
|
|
45
|
+
schema_outdated: "DB \uC2A4\uD0A4\uB9C8\uAC00 v{found}\uC774\uACE0 \uC774 \uBC84\uC804\uC740 v{expected}\uAC00 \uD544\uC694\uD574\uC694. \uC2E4\uD589: {command}",
|
|
46
|
+
conflict_version: "v{expected}\uB97C \uC77D\uC740 \uB4A4 \uB2E4\uB978 \uACF3\uC5D0\uC11C v{current}\uB85C \uC800\uC7A5\uD588\uC5B4\uC694. \uB2E4\uC2DC \uBD88\uB7EC\uC624\uAC70\uB098 \uD569\uCE5C \uB4A4 \uC800\uC7A5\uD574 \uC8FC\uC138\uC694",
|
|
47
|
+
slug_taken: "\uC774\uBBF8 \uC4F0\uB294 \uC8FC\uC18C\uC608\uC694: {slug}",
|
|
48
|
+
precondition_required: "\uC774 \uBB38\uC11C\uB97C \uBC14\uAFB8\uB824\uBA74 If-Match(\uB610\uB294 expectedVersion)\uB97C \uBCF4\uB0B4 \uC8FC\uC138\uC694",
|
|
49
|
+
internal: "\uCC98\uB9AC \uC911 \uC624\uB958\uAC00 \uB0AC\uC5B4\uC694"
|
|
50
|
+
};
|
|
51
|
+
export {
|
|
52
|
+
ko
|
|
53
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://ui.shadcn.com/schema/registry-item.json",
|
|
3
|
+
"name": "cms-audit",
|
|
4
|
+
"type": "registry:component",
|
|
5
|
+
"title": "Audit log",
|
|
6
|
+
"description": "Who did what through which channel, filtered by action, who and result.",
|
|
7
|
+
"dependencies": [
|
|
8
|
+
"@mainsoft/agent-cms",
|
|
9
|
+
"lucide-react"
|
|
10
|
+
],
|
|
11
|
+
"registryDependencies": [
|
|
12
|
+
"badge",
|
|
13
|
+
"button",
|
|
14
|
+
"select",
|
|
15
|
+
"table",
|
|
16
|
+
"cms-lib"
|
|
17
|
+
],
|
|
18
|
+
"files": [
|
|
19
|
+
{
|
|
20
|
+
"path": "registry/cms/cms-audit.tsx",
|
|
21
|
+
"type": "registry:component",
|
|
22
|
+
"content": "// agent-cms registry: cms-audit (0.6.0). Copied into your app by `npx agent-cms add`; edit freely.\n//\n// The audit log: key changes, publishes, deletes, denied access and failed\n// sign-ins, filtered by action, who and result, with \"Load more\".\n\"use client\";\n\nimport * as React from \"react\";\nimport { UserX } from \"lucide-react\";\nimport type { AuditEntry } from \"@mainsoft/agent-cms/types\";\nimport { Badge } from \"@/components/ui/badge\";\nimport { Button } from \"@/components/ui/button\";\nimport { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from \"@/components/ui/select\";\nimport { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from \"@/components/ui/table\";\nimport { cn } from \"@/lib/utils\";\nimport { errorMessage, type MessageKey } from \"./cms-messages\";\nimport { PageHeader, StatusText, Who } from \"./cms-parts\";\nimport { formatDateTime, useCms } from \"./use-cms\";\n\nconst ACTIONS = [\"doc.publish\", \"doc.unpublish\", \"doc.archive\", \"doc.unarchive\", \"doc.delete\", \"doc.restore\", \"preview.create\", \"key.create\", \"key.revoke\", \"access.denied\", \"auth.failed\"] as const;\ntype ActorFilter = \"__all\" | \"user\" | \"key\" | \"system\" | \"anonymous\";\n\nexport interface CmsAuditProps {\n /** Entries per page. Default 50. */\n pageSize?: number;\n className?: string;\n}\n\nexport function CmsAudit({ pageSize = 50, className }: CmsAuditProps) {\n const { client, t, locale } = useCms();\n const [action, setAction] = React.useState<string>(\"__all\");\n const [actor, setActor] = React.useState<ActorFilter>(\"__all\");\n const [outcome, setOutcome] = React.useState<string>(\"__all\");\n const [entries, setEntries] = React.useState<AuditEntry[]>([]);\n const [cursor, setCursor] = React.useState<string | null>(null);\n const [loading, setLoading] = React.useState(true);\n const [error, setError] = React.useState<unknown>(null);\n\n const q = React.useMemo(() => ({ action: action === \"__all\" ? undefined : action, outcome: outcome === \"__all\" ? undefined : outcome, limit: pageSize }), [action, outcome, pageSize]);\n\n React.useEffect(() => {\n let live = true;\n setLoading(true);\n client.audit(q).then(\n (r) => {\n if (!live) return;\n setEntries(r.entries);\n setCursor(r.nextCursor);\n setError(null);\n setLoading(false);\n },\n (e) => {\n if (!live) return;\n setError(e);\n setLoading(false);\n }\n );\n return () => {\n live = false;\n };\n }, [client, q]);\n\n const more = async () => {\n if (!cursor) return;\n setLoading(true);\n try {\n const r = await client.audit({ ...q, cursor });\n setEntries((x) => [...x, ...r.entries]);\n setCursor(r.nextCursor);\n } catch (e) {\n setError(e);\n } finally {\n setLoading(false);\n }\n };\n\n // The REST route filters by action and outcome; \"who\" filters what is loaded.\n const shown = actor === \"__all\" ? entries : entries.filter((e) => e.actorKind === actor);\n\n const actionLabel = (a: string) => t(`audit.${a}` as MessageKey);\n const actorLabel = (k: string) => t(`actor_${k}` as MessageKey);\n const outcomeLabel = (o: string) => t(`outcome_${o}` as MessageKey);\n\n const filter = (id: string, labelKey: MessageKey, fmtKey: MessageKey, value: string, set: (v: string) => void, options: { value: string; label: string }[]) => (\n <Select value={value} onValueChange={(v: string | null) => set(v ?? \"__all\")}>\n <SelectTrigger id={id} className=\"h-8 w-auto gap-1.5 text-[13px]\" aria-label={t(labelKey)}>\n <SelectValue>{t(fmtKey, { value: value === \"__all\" ? t(\"all\") : (options.find((o) => o.value === value)?.label ?? value) })}</SelectValue>\n </SelectTrigger>\n <SelectContent>\n <SelectItem value=\"__all\">{t(\"all\")}</SelectItem>\n {options.map((o) => (\n <SelectItem key={o.value} value={o.value}>\n {o.label}\n </SelectItem>\n ))}\n </SelectContent>\n </Select>\n );\n\n const target = (e: AuditEntry) => {\n if (e.collection || e.slug)\n return (\n <>\n <span className=\"font-mono text-xs\">{[e.collection, e.slug].filter(Boolean).join(\"/\")}</span>\n {e.version ? <span className=\"ml-1.5 text-xs text-muted-foreground\">v{e.version}</span> : null}\n </>\n );\n const d = e.detail as { name?: string; scopes?: string[]; key?: string };\n if (d.name)\n return (\n <>\n {d.name}\n {d.scopes?.length ? <span className=\"ml-1.5 text-xs text-muted-foreground\">{d.scopes.join(\", \")}</span> : null}\n </>\n );\n if (d.key) return <span className=\"font-mono text-xs\">{d.key}</span>;\n return null;\n };\n\n return (\n <div className={cn(\"flex min-h-0 flex-1 flex-col\", className)}>\n <PageHeader title={t(\"audit_title\")} />\n <div className=\"flex-1 overflow-x-auto px-4 py-4 md:px-6\">\n <div className=\"mb-3.5 flex flex-wrap items-center gap-2\">\n {filter(\"cms-audit-action\", \"audit_action_label\", \"audit_action\", action, setAction, ACTIONS.map((a) => ({ value: a, label: actionLabel(a) })))}\n {filter(\"cms-audit-actor\", \"audit_actor_label\", \"audit_actor\", actor, (v) => setActor(v as ActorFilter), ([\"user\", \"key\", \"system\", \"anonymous\"] as const).map((k) => ({ value: k, label: actorLabel(k) })))}\n {filter(\"cms-audit-outcome\", \"audit_outcome_label\", \"audit_outcome\", outcome, setOutcome, ([\"ok\", \"denied\", \"failed\"] as const).map((o) => ({ value: o, label: outcomeLabel(o) })))}\n </div>\n <Table>\n <TableHeader>\n <TableRow>\n <TableHead>{t(\"audit_time\")}</TableHead>\n <TableHead>{t(\"audit_who\")}</TableHead>\n <TableHead>{t(\"audit_what\")}</TableHead>\n <TableHead>{t(\"audit_target\")}</TableHead>\n <TableHead>{t(\"audit_result\")}</TableHead>\n <TableHead>{t(\"audit_via\")}</TableHead>\n </TableRow>\n </TableHeader>\n <TableBody>\n {shown.map((e) => (\n <TableRow key={e.id}>\n <TableCell className=\"whitespace-nowrap text-xs tabular-nums\">{formatDateTime(e.at, locale)}</TableCell>\n <TableCell className=\"text-[13.5px]\">\n {e.actorKind === \"anonymous\" ? (\n <span className=\"inline-flex items-center gap-1.5 text-muted-foreground\">\n <span aria-hidden className=\"inline-grid h-5 w-5 place-items-center rounded-full bg-muted\">\n <UserX className=\"h-3 w-3\" />\n </span>\n {e.action === \"auth.failed\" ? t(\"unknown_key\") : actorLabel(\"anonymous\")}\n </span>\n ) : (\n <Who kind={e.actorKind} label={e.actorLabel} />\n )}\n </TableCell>\n <TableCell className=\"text-[13.5px]\">{actionLabel(e.action)}</TableCell>\n <TableCell className=\"text-[13.5px]\">{target(e)}</TableCell>\n <TableCell>\n {e.outcome === \"ok\" ? (\n <Badge variant=\"outline\" className=\"gap-1.5 rounded-full px-2 py-0 text-[11.5px] font-medium\">\n <span aria-hidden className=\"h-1.5 w-1.5 rounded-full bg-green-600\" />\n {outcomeLabel(\"ok\")}\n </Badge>\n ) : (\n <Badge variant=\"outline\" className=\"rounded-full border-red-200 bg-red-50 px-2 py-0 text-[11.5px] text-red-700\">\n {outcomeLabel(e.outcome)}\n </Badge>\n )}\n </TableCell>\n <TableCell className=\"text-xs text-muted-foreground\">{e.via ? t(`via_${e.via}` as MessageKey) : \"\"}</TableCell>\n </TableRow>\n ))}\n </TableBody>\n </Table>\n <div className=\"mt-3 flex flex-col items-center gap-2\">\n <StatusText tone={error ? \"error\" : \"muted\"} className=\"text-xs\">\n {error ? errorMessage(error, t) : loading ? t(\"loading\") : !shown.length ? t(\"audit_empty\") : \"\"}\n </StatusText>\n {cursor ? (\n <Button type=\"button\" variant=\"outline\" size=\"sm\" disabled={loading} onClick={() => void more()}>\n {t(\"load_more\")}\n </Button>\n ) : null}\n </div>\n </div>\n </div>\n );\n}\n"
|
|
23
|
+
}
|
|
24
|
+
]
|
|
25
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://ui.shadcn.com/schema/registry-item.json",
|
|
3
|
+
"name": "cms-command",
|
|
4
|
+
"type": "registry:component",
|
|
5
|
+
"title": "Command menu",
|
|
6
|
+
"description": "Cmd+K or Ctrl+K: find documents (drafts included) across collections and open, publish or start a new one.",
|
|
7
|
+
"dependencies": [
|
|
8
|
+
"@mainsoft/agent-cms",
|
|
9
|
+
"lucide-react"
|
|
10
|
+
],
|
|
11
|
+
"registryDependencies": [
|
|
12
|
+
"command",
|
|
13
|
+
"dialog",
|
|
14
|
+
"cms-lib"
|
|
15
|
+
],
|
|
16
|
+
"files": [
|
|
17
|
+
{
|
|
18
|
+
"path": "registry/cms/cms-command.tsx",
|
|
19
|
+
"type": "registry:component",
|
|
20
|
+
"content": "// agent-cms registry: cms-command (0.6.0). Copied into your app by `npx agent-cms add`; edit freely.\n//\n// ⌘K / Ctrl+K: find any document (drafts too) across the collections you can\n// edit, open it, publish it, see its history, or start a new document.\n\"use client\";\n\nimport * as React from \"react\";\nimport { FileText, History, Plus, Upload } from \"lucide-react\";\nimport type { DocSummary } from \"@mainsoft/agent-cms/types\";\nimport { Command, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList } from \"@/components/ui/command\";\nimport { Dialog, DialogContent, DialogDescription, DialogTitle } from \"@/components/ui/dialog\";\nimport { cn } from \"@/lib/utils\";\nimport { StateBadge } from \"./cms-parts\";\nimport { useCms, useDebounced } from \"./use-cms\";\n\nexport interface CmsCommandProps {\n /** Controlled open state (leave out to let ⌘K / Ctrl+K handle it). */\n open?: boolean;\n onOpenChange?: (open: boolean) => void;\n /** Listen for ⌘K / Ctrl+K. Default true. */\n hotkey?: boolean;\n /** The collection the user is in: its \"New document\" comes first. */\n collection?: string;\n onOpenDocument: (collection: string, slug: string) => void;\n onNewDocument?: (collection: string) => void;\n onOpenVersions?: (collection: string, slug: string) => void;\n /** Called after \"Publish\" from the menu. */\n onPublished?: (collection: string, slug: string) => void;\n /** Documents per collection. Default 8. */\n limit?: number;\n}\n\ntype Hit = DocSummary & { collectionLabel: string };\n\nfunction Mark({ text, q }: { text: string; q: string }) {\n const i = q ? text.toLowerCase().indexOf(q.toLowerCase()) : -1;\n if (i < 0) return <>{text}</>;\n return (\n <>\n {text.slice(0, i)}\n <mark className=\"rounded-sm bg-yellow-100 px-0 text-inherit\">{text.slice(i, i + q.length)}</mark>\n {text.slice(i + q.length)}\n </>\n );\n}\n\nexport function CmsCommand({ open: openProp, onOpenChange, hotkey = true, collection, onOpenDocument, onNewDocument, onOpenVersions, onPublished, limit = 8 }: CmsCommandProps) {\n const { client, t, me } = useCms();\n const [openState, setOpenState] = React.useState(false);\n const open = openProp ?? openState;\n const setOpen = React.useCallback(\n (o: boolean) => {\n setOpenState(o);\n onOpenChange?.(o);\n },\n [onOpenChange]\n );\n const [q, setQ] = React.useState(\"\");\n const [hits, setHits] = React.useState<Hit[]>([]);\n const [loading, setLoading] = React.useState(false);\n const seq = React.useRef(0);\n\n React.useEffect(() => {\n if (!hotkey) return;\n const on = (e: KeyboardEvent) => {\n if ((e.metaKey || e.ctrlKey) && e.key.toLowerCase() === \"k\") {\n e.preventDefault();\n setOpen(!open);\n }\n };\n document.addEventListener(\"keydown\", on);\n return () => document.removeEventListener(\"keydown\", on);\n }, [hotkey, open, setOpen]);\n\n const cols = React.useMemo(() => (me?.collections ?? []).filter((c) => c.canWrite), [me]);\n\n const search = useDebounced(async (text: string) => {\n const n = ++seq.current;\n setLoading(true);\n const results = await Promise.all(\n cols.map((c) =>\n client.list(c.slug, { q: text || undefined, limit }).then(\n (r) => r.docs.map((d) => ({ ...d, collectionLabel: c.label })),\n () => [] as Hit[]\n )\n )\n );\n if (n !== seq.current) return;\n setHits(results.flat());\n setLoading(false);\n }, 200);\n\n React.useEffect(() => {\n if (open) search(q);\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [open, q, cols]);\n\n React.useEffect(() => {\n if (!open) setQ(\"\");\n }, [open]);\n\n const first = hits[0];\n const newIn = [...cols].sort((a, b) => (a.slug === collection ? -1 : b.slug === collection ? 1 : 0));\n\n const run = (fn: () => void) => {\n setOpen(false);\n fn();\n };\n\n return (\n <Dialog open={open} onOpenChange={setOpen}>\n <DialogContent className=\"top-[12vh] max-w-[620px] translate-y-0 overflow-hidden p-0\">\n <DialogTitle className=\"sr-only\">{t(\"cmd_title\")}</DialogTitle>\n <DialogDescription className=\"sr-only\">{t(\"cmd_placeholder\")}</DialogDescription>\n <Command shouldFilter={false} label={t(\"cmd_title\")} className=\"[&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:text-xs [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-muted-foreground\">\n <CommandInput value={q} onValueChange={setQ} placeholder={t(\"cmd_placeholder\")} aria-label={t(\"cmd_placeholder\")} className=\"h-12\" />\n <CommandList className=\"max-h-[420px]\">\n {!loading ? <CommandEmpty>{t(\"cmd_empty\")}</CommandEmpty> : null}\n {hits.length ? (\n <CommandGroup heading={t(\"cmd_docs\")}>\n {hits.map((d) => (\n <CommandItem key={`${d.collection}/${d.slug}`} value={`doc:${d.collection}/${d.slug}`} onSelect={() => run(() => onOpenDocument(d.collection, d.slug))} className=\"gap-2\">\n <FileText aria-hidden className=\"h-4 w-4 shrink-0 text-muted-foreground\" />\n <span className=\"min-w-0 flex-1 truncate\">\n <Mark text={d.title || d.slug} q={q} />\n </span>\n <StateBadge state={d.state} label={d.state === \"draft\" ? t(\"draft_version\", { version: d.version }) : undefined} />\n <span className=\"text-xs text-muted-foreground\">{d.collectionLabel}</span>\n </CommandItem>\n ))}\n </CommandGroup>\n ) : null}\n <CommandGroup heading={t(\"cmd_actions\")}>\n {first && q && (first.state === \"draft\" || first.modifiedSincePublish) && cols.find((c) => c.slug === first.collection)?.canPublish ? (\n <CommandItem\n value={`publish:${first.collection}/${first.slug}`}\n className=\"gap-2\"\n onSelect={() =>\n run(() => {\n void client.publish(first.collection, first.slug, { expectedVersion: first.version }).then(() => onPublished?.(first.collection, first.slug));\n })\n }\n >\n <Upload aria-hidden className=\"h-4 w-4 text-muted-foreground\" />\n {t(\"cmd_publish\", { title: first.title || first.slug })}\n </CommandItem>\n ) : null}\n {first && q && onOpenVersions ? (\n <CommandItem value={`versions:${first.collection}/${first.slug}`} className=\"gap-2\" onSelect={() => run(() => onOpenVersions(first.collection, first.slug))}>\n <History aria-hidden className=\"h-4 w-4 text-muted-foreground\" />\n {t(\"cmd_versions\", { title: first.title || first.slug })}\n </CommandItem>\n ) : null}\n {onNewDocument\n ? newIn.map((c) => (\n <CommandItem key={c.slug} value={`new:${c.slug}`} className=\"gap-2\" onSelect={() => run(() => onNewDocument(c.slug))}>\n <Plus aria-hidden className=\"h-4 w-4 text-muted-foreground\" />\n {t(\"cmd_new_in\", { collection: c.label })}\n </CommandItem>\n ))\n : null}\n </CommandGroup>\n </CommandList>\n <div className={cn(\"flex items-center gap-4 border-t px-3 py-2 text-xs text-muted-foreground\")} aria-hidden>\n <span>\n <kbd className=\"rounded border border-b-2 px-1 font-mono\">↑</kbd> <kbd className=\"rounded border border-b-2 px-1 font-mono\">↓</kbd> {t(\"cmd_move\")}\n </span>\n <span>\n <kbd className=\"rounded border border-b-2 px-1 font-mono\">↵</kbd> {t(\"cmd_open\")}\n </span>\n </div>\n </Command>\n </DialogContent>\n </Dialog>\n );\n}\n"
|
|
21
|
+
}
|
|
22
|
+
]
|
|
23
|
+
}
|