@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.
Files changed (108) hide show
  1. package/CHANGELOG.md +54 -0
  2. package/LICENSE +21 -0
  3. package/README.md +359 -2
  4. package/TODO.md +178 -0
  5. package/UPGRADE-0.6.md +236 -0
  6. package/dist/agent.cjs +250 -0
  7. package/dist/agent.d.cts +88 -0
  8. package/dist/agent.d.ts +88 -0
  9. package/dist/agent.js +24 -0
  10. package/dist/ai.cjs +555 -0
  11. package/dist/ai.d.cts +48 -0
  12. package/dist/ai.d.ts +48 -0
  13. package/dist/ai.js +73 -0
  14. package/dist/bin.js +1556 -0
  15. package/dist/chunk-2NTK7H4W.js +10 -0
  16. package/dist/chunk-52NUUZC7.js +1446 -0
  17. package/dist/chunk-6K5ZTGHQ.js +30 -0
  18. package/dist/chunk-AKN7SUXU.js +281 -0
  19. package/dist/chunk-CRDW6Q72.js +188 -0
  20. package/dist/chunk-DD56PTZ4.js +78 -0
  21. package/dist/chunk-DOADAH4L.js +52 -0
  22. package/dist/chunk-EXV6JNLY.js +251 -0
  23. package/dist/chunk-IGL2V6US.js +324 -0
  24. package/dist/chunk-IW3D4I7Q.js +317 -0
  25. package/dist/chunk-OQ55GEF3.js +6 -0
  26. package/dist/chunk-QC2M4NZY.js +158 -0
  27. package/dist/chunk-QQV6VLYJ.js +204 -0
  28. package/dist/chunk-T66ZKBHF.js +25 -0
  29. package/dist/chunk-VICZ76TR.js +118 -0
  30. package/dist/chunk-Y63XQS2J.js +6 -0
  31. package/dist/cli.cjs +1596 -0
  32. package/dist/cli.d.cts +89 -0
  33. package/dist/cli.d.ts +89 -0
  34. package/dist/cli.js +534 -0
  35. package/dist/client.cjs +185 -0
  36. package/dist/client.d.cts +228 -0
  37. package/dist/client.d.ts +228 -0
  38. package/dist/client.js +13 -0
  39. package/dist/cms-BPp01z-8.d.ts +411 -0
  40. package/dist/cms-D6D89-qZ.d.cts +411 -0
  41. package/dist/config.cjs +61 -0
  42. package/dist/config.d.cts +36 -0
  43. package/dist/config.d.ts +36 -0
  44. package/dist/config.js +11 -0
  45. package/dist/diff.cjs +316 -0
  46. package/dist/diff.d.cts +122 -0
  47. package/dist/diff.d.ts +122 -0
  48. package/dist/diff.js +29 -0
  49. package/dist/drizzle-repo-B1rt7r4j.d.ts +90 -0
  50. package/dist/drizzle-repo-Cn-kL2FK.d.cts +90 -0
  51. package/dist/errors.cjs +193 -0
  52. package/dist/errors.d.cts +109 -0
  53. package/dist/errors.d.ts +109 -0
  54. package/dist/errors.js +16 -0
  55. package/dist/frontmatter.cjs +103 -0
  56. package/dist/frontmatter.d.cts +32 -0
  57. package/dist/frontmatter.d.ts +32 -0
  58. package/dist/frontmatter.js +9 -0
  59. package/dist/http.cjs +1105 -0
  60. package/dist/http.d.cts +75 -0
  61. package/dist/http.d.ts +75 -0
  62. package/dist/http.js +321 -0
  63. package/dist/index.cjs +3066 -0
  64. package/dist/index.d.cts +19 -0
  65. package/dist/index.d.ts +19 -0
  66. package/dist/index.js +263 -0
  67. package/dist/markdown.cjs +220 -0
  68. package/dist/markdown.d.cts +88 -0
  69. package/dist/markdown.d.ts +88 -0
  70. package/dist/markdown.js +23 -0
  71. package/dist/mcp.cjs +652 -0
  72. package/dist/mcp.d.cts +43 -0
  73. package/dist/mcp.d.ts +43 -0
  74. package/dist/mcp.js +26 -0
  75. package/dist/messages/en.cjs +76 -0
  76. package/dist/messages/en.d.cts +7 -0
  77. package/dist/messages/en.d.ts +7 -0
  78. package/dist/messages/en.js +7 -0
  79. package/dist/messages/ko.cjs +76 -0
  80. package/dist/messages/ko.d.cts +7 -0
  81. package/dist/messages/ko.d.ts +7 -0
  82. package/dist/messages/ko.js +53 -0
  83. package/dist/registry/cms-audit.json +25 -0
  84. package/dist/registry/cms-command.json +23 -0
  85. package/dist/registry/cms-doc-editor.json +36 -0
  86. package/dist/registry/cms-doc-list.json +29 -0
  87. package/dist/registry/cms-empty.json +22 -0
  88. package/dist/registry/cms-keys.json +29 -0
  89. package/dist/registry/cms-lib.json +33 -0
  90. package/dist/registry/cms-merge.json +26 -0
  91. package/dist/registry/cms-shell.json +22 -0
  92. package/dist/registry/cms-versions.json +26 -0
  93. package/dist/registry/registry.json +255 -0
  94. package/dist/repo-BWI2Pkrv.d.ts +162 -0
  95. package/dist/repo-CeDxUxO6.d.cts +162 -0
  96. package/dist/tables.cjs +356 -0
  97. package/dist/tables.d.cts +3515 -0
  98. package/dist/tables.d.ts +3515 -0
  99. package/dist/tables.js +35 -0
  100. package/dist/tools.cjs +420 -0
  101. package/dist/tools.d.cts +27 -0
  102. package/dist/tools.d.ts +27 -0
  103. package/dist/tools.js +18 -0
  104. package/dist/types.cjs +226 -0
  105. package/dist/types.d.cts +286 -0
  106. package/dist/types.d.ts +286 -0
  107. package/dist/types.js +28 -0
  108. package/package.json +277 -4
@@ -0,0 +1,185 @@
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/client.ts
21
+ var client_exports = {};
22
+ __export(client_exports, {
23
+ CmsRemoteError: () => CmsRemoteError,
24
+ createCmsClient: () => createCmsClient,
25
+ createRestClient: () => createRestClient,
26
+ isCmsRemoteError: () => isCmsRemoteError
27
+ });
28
+ module.exports = __toCommonJS(client_exports);
29
+ var CmsRemoteError = class extends Error {
30
+ constructor(message, code, extra = {}) {
31
+ super(message);
32
+ this.code = code;
33
+ this.extra = extra;
34
+ this.name = "CmsRemoteError";
35
+ }
36
+ code;
37
+ extra;
38
+ isCmsRemoteError = true;
39
+ get kind() {
40
+ return this.extra.kind;
41
+ }
42
+ get status() {
43
+ return this.extra.status;
44
+ }
45
+ get params() {
46
+ return this.extra.params;
47
+ }
48
+ get diagnostics() {
49
+ return this.extra.diagnostics;
50
+ }
51
+ /** On `conflict_version`: the working copy someone else saved (for a merge). */
52
+ get current() {
53
+ return this.extra.current;
54
+ }
55
+ };
56
+ function isCmsRemoteError(e) {
57
+ return !!e && typeof e === "object" && e.isCmsRemoteError === true;
58
+ }
59
+ function createCmsClient(opts) {
60
+ const base = opts.url.replace(/\/+$/, "");
61
+ const doFetch = opts.fetch ?? fetch;
62
+ let seq = 0;
63
+ async function rpc(method, params) {
64
+ const res = await doFetch(`${base}/mcp`, {
65
+ method: "POST",
66
+ headers: {
67
+ "content-type": "application/json",
68
+ accept: "application/json, text/event-stream",
69
+ authorization: `Bearer ${opts.key}`,
70
+ ...opts.clientName ? { "x-agent-cms-client": opts.clientName } : {}
71
+ },
72
+ body: JSON.stringify({ jsonrpc: "2.0", id: ++seq, method, params })
73
+ });
74
+ const text = await res.text();
75
+ let msg = null;
76
+ try {
77
+ msg = JSON.parse(text);
78
+ } catch {
79
+ }
80
+ if (!res.ok || !msg) {
81
+ const rest = msg;
82
+ if (rest && typeof rest.error === "string") throw new CmsRemoteError(rest.message ?? rest.error, rest.error, { status: res.status });
83
+ throw new CmsRemoteError(msg?.error?.message ?? `HTTP ${res.status}: ${text.slice(0, 200)}`, "http", { status: res.status });
84
+ }
85
+ if (msg.error) throw new CmsRemoteError(msg.error.message ?? "RPC error", "rpc");
86
+ return msg.result;
87
+ }
88
+ return {
89
+ /** Tools this key can use. */
90
+ async listTools() {
91
+ const r = await rpc("tools/list", {});
92
+ return r.tools;
93
+ },
94
+ /** Call one tool (see `CMS_TOOL_NAMES`). Throws CmsRemoteError on failure. */
95
+ async call(name, args = {}) {
96
+ const r = await rpc("tools/call", { name, arguments: args });
97
+ const text = r.content?.find((c) => c.type === "text")?.text ?? "";
98
+ if (r.isError) {
99
+ const s = r.structuredContent;
100
+ if (s?.error) throw new CmsRemoteError(s.message ?? text, s.error, { kind: s.kind, params: s.params, diagnostics: s.diagnostics, current: s.current });
101
+ const m = /^([a-z_]+): ([\s\S]*)$/.exec(text);
102
+ throw new CmsRemoteError(m ? m[2] : text, m ? m[1] : "tool");
103
+ }
104
+ try {
105
+ return JSON.parse(text);
106
+ } catch {
107
+ return r.structuredContent;
108
+ }
109
+ }
110
+ };
111
+ }
112
+ function createRestClient(opts) {
113
+ const base = opts.url.replace(/\/+$/, "");
114
+ const doFetch = opts.fetch ?? ((...a) => fetch(...a));
115
+ const enc = encodeURIComponent;
116
+ async function req(method, path, o = {}) {
117
+ const qs = o.query ? Object.entries(o.query).filter(([, v]) => v !== void 0 && v !== null && v !== false && v !== "").map(([k, v]) => `${enc(k)}=${enc(v === true ? "1" : String(v))}`).join("&") : "";
118
+ let res;
119
+ try {
120
+ res = await doFetch(`${base}${path}${qs ? `?${qs}` : ""}`, {
121
+ method,
122
+ credentials: "same-origin",
123
+ headers: {
124
+ accept: "application/json",
125
+ ...o.body !== void 0 ? { "content-type": "application/json" } : {},
126
+ ...o.ifMatch !== void 0 ? { "if-match": `"v${o.ifMatch}"` } : {},
127
+ ...opts.headers
128
+ },
129
+ body: o.body !== void 0 ? JSON.stringify(o.body) : void 0
130
+ });
131
+ } catch (e) {
132
+ throw new CmsRemoteError(e instanceof Error ? e.message : String(e), "network");
133
+ }
134
+ const text = await res.text();
135
+ let data = null;
136
+ try {
137
+ data = text ? JSON.parse(text) : null;
138
+ } catch {
139
+ }
140
+ if (!res.ok) {
141
+ const e = data ?? {};
142
+ throw new CmsRemoteError(e.message ?? `HTTP ${res.status}`, e.error ?? "http", { kind: e.kind, status: res.status, params: e.params, diagnostics: e.diagnostics, current: e.current });
143
+ }
144
+ return data;
145
+ }
146
+ const doc = (c, s) => `/collections/${enc(c)}/${enc(s)}`;
147
+ return {
148
+ me: () => req("GET", "/_me"),
149
+ schema: (c) => req("GET", `/collections/${enc(c)}/_schema`),
150
+ list: (c, q = {}) => req("GET", `/collections/${enc(c)}`, { query: { fields: "summary", ...q } }),
151
+ counts: (c) => req("GET", `/collections/${enc(c)}/_counts`).then((r) => r.counts),
152
+ get: (c, s, o = { draft: true }) => req("GET", doc(c, s), { query: { draft: o.draft } }).then((r) => r.doc),
153
+ create: (c, d, o = {}) => req("POST", `/collections/${enc(c)}`, { body: { doc: d, ...o } }).then((r) => r.doc),
154
+ update: (c, s, d, o) => req("PATCH", doc(c, s), { body: { doc: d, publish: o.publish, note: o.note }, ifMatch: o.expectedVersion }).then((r) => r.doc),
155
+ remove: (c, s, expectedVersion) => req("DELETE", doc(c, s), { ifMatch: expectedVersion }),
156
+ diagnose: (c, d, slug) => req("POST", `/collections/${enc(c)}/_diagnose`, { body: { doc: d, slug } }).then((r) => r.diagnostics),
157
+ patch: (c, s, ops, o = {}) => req("POST", `${doc(c, s)}/patch`, { body: { ops, ...o } }),
158
+ autosave: (c, s, d, baseVersion) => req("PUT", `${doc(c, s)}/autosave`, { body: { doc: d, baseVersion } }).then((r) => r.autosave),
159
+ discardAutosave: (c, s) => req("DELETE", `${doc(c, s)}/autosave`),
160
+ publish: (c, s, o = {}) => req("POST", `${doc(c, s)}/publish`, { body: { version: o.version }, ifMatch: o.expectedVersion }).then((r) => r.doc),
161
+ unpublish: (c, s, expectedVersion) => req("POST", `${doc(c, s)}/unpublish`, { body: {}, ifMatch: expectedVersion }).then((r) => r.doc),
162
+ archive: (c, s, expectedVersion) => req("POST", `${doc(c, s)}/archive`, { body: {}, ifMatch: expectedVersion }).then((r) => r.doc),
163
+ unarchive: (c, s, expectedVersion) => req("POST", `${doc(c, s)}/unarchive`, { body: {}, ifMatch: expectedVersion }).then((r) => r.doc),
164
+ bulk: (c, action, items) => req("POST", `/collections/${enc(c)}/_bulk`, { body: { action, items } }).then((r) => r.results),
165
+ versions: (c, s) => req("GET", `${doc(c, s)}/versions`, { query: { fields: "summary" } }).then((r) => r.versions),
166
+ version: (c, s, n) => req("GET", `${doc(c, s)}/versions/${n}`).then((r) => r.version),
167
+ diff: (c, s, a, b) => req("GET", `${doc(c, s)}/diff`, { query: { a, b } }),
168
+ restore: (c, s, n, o = {}) => req("POST", `${doc(c, s)}/versions/${n}/restore`, { body: { publish: o.publish }, ifMatch: o.expectedVersion }).then((r) => r.doc),
169
+ changes: (c, s) => req("GET", `${doc(c, s)}/changes`).then((r) => r.changes),
170
+ review: (c, s, hunks, action = "accepted") => req("POST", `${doc(c, s)}/review`, { body: { hunks, action } }),
171
+ previewLink: (c, s, ttl = "24h") => req("POST", `${doc(c, s)}/preview`, { body: { ttl } }),
172
+ search: (q, collections) => req("GET", "/search", { query: { q, collections: collections?.join(",") } }),
173
+ keys: () => req("GET", "/keys").then((r) => r.keys),
174
+ createKey: (k) => req("POST", "/keys", { body: k }),
175
+ revokeKey: (id) => req("DELETE", `/keys/${enc(id)}`),
176
+ audit: (q = {}) => req("GET", "/audit", { query: q })
177
+ };
178
+ }
179
+ // Annotate the CommonJS export names for ESM import in node:
180
+ 0 && (module.exports = {
181
+ CmsRemoteError,
182
+ createCmsClient,
183
+ createRestClient,
184
+ isCmsRemoteError
185
+ });
@@ -0,0 +1,228 @@
1
+ import { l as PatchOp, b as BulkAction, c as BulkResult, D as DocDiff, A as AgentChange, o as PreviewTtl, m as PreviewLink } from './cms-D6D89-qZ.cjs';
2
+ import { ErrorParams, Diagnostic } from './errors.cjs';
3
+ import { DocSummary, DocCounts, CmsDoc, AutosaveState, VersionSummary, CmsVersion, CmsKey, KeyScope, AuditEntry } from './types.cjs';
4
+ import 'zod';
5
+ import './diff.cjs';
6
+ import './repo-CeDxUxO6.cjs';
7
+
8
+ /** Types the REST client sends and receives (re-exported for the admin screens). Type-only, browser-safe. */
9
+
10
+ /** A document body for create / update over REST. */
11
+ interface DocInputWire {
12
+ slug?: string;
13
+ title?: string;
14
+ summary?: string;
15
+ body?: string;
16
+ category?: string | null;
17
+ keywords?: string[];
18
+ fields?: Record<string, unknown>;
19
+ }
20
+
21
+ /**
22
+ * Clients for an app that runs agent-cms. Browser- and edge-safe (only
23
+ * `fetch`).
24
+ *
25
+ * - `createCmsClient({ url, key })`: the agent tools over MCP with an API key
26
+ * (scripts, CI, another service, the CLI). Never ship a write key to a browser.
27
+ * - `createRestClient({ url })`: the REST API with the browser's session
28
+ * cookie. This is what the copied admin screens use.
29
+ */
30
+
31
+ interface CmsClientOptions {
32
+ /** The CMS base URL, e.g. https://app.example.com/api/cms */
33
+ url: string;
34
+ /** An API key (`sgk_…`). */
35
+ key: string;
36
+ fetch?: typeof fetch;
37
+ /** Sent as `x-agent-cms-client` (the CLI sends "cli"). */
38
+ clientName?: string;
39
+ }
40
+ declare class CmsRemoteError extends Error {
41
+ /** e.g. "conflict_version", "forbidden_write", "not_found" (from the server), or "http" / "rpc" / "network". */
42
+ code: string;
43
+ extra: {
44
+ kind?: string;
45
+ status?: number;
46
+ params?: ErrorParams;
47
+ diagnostics?: Diagnostic[];
48
+ current?: unknown;
49
+ };
50
+ constructor(message: string,
51
+ /** e.g. "conflict_version", "forbidden_write", "not_found" (from the server), or "http" / "rpc" / "network". */
52
+ code: string, extra?: {
53
+ kind?: string;
54
+ status?: number;
55
+ params?: ErrorParams;
56
+ diagnostics?: Diagnostic[];
57
+ current?: unknown;
58
+ });
59
+ readonly isCmsRemoteError = true;
60
+ get kind(): string | undefined;
61
+ get status(): number | undefined;
62
+ get params(): ErrorParams | undefined;
63
+ get diagnostics(): Diagnostic[] | undefined;
64
+ /** On `conflict_version`: the working copy someone else saved (for a merge). */
65
+ get current(): unknown;
66
+ }
67
+ /** Like `isCmsError`: survives duplicated copies of this class in a bundle. */
68
+ declare function isCmsRemoteError(e: unknown): e is CmsRemoteError;
69
+ interface RemoteTool {
70
+ name: string;
71
+ description: string;
72
+ inputSchema: Record<string, unknown>;
73
+ }
74
+ declare function createCmsClient(opts: CmsClientOptions): {
75
+ /** Tools this key can use. */
76
+ listTools(): Promise<RemoteTool[]>;
77
+ /** Call one tool (see `CMS_TOOL_NAMES`). Throws CmsRemoteError on failure. */
78
+ call<T = unknown>(name: string, args?: Record<string, unknown>): Promise<T>;
79
+ };
80
+ type CmsClient = ReturnType<typeof createCmsClient>;
81
+ interface RestClientOptions {
82
+ /** The CMS base URL, e.g. "/api/cms" in the browser. */
83
+ url: string;
84
+ fetch?: typeof fetch;
85
+ /** Extra headers (e.g. a key for server-side use). */
86
+ headers?: Record<string, string>;
87
+ }
88
+ interface Me {
89
+ actor: {
90
+ kind: string;
91
+ label?: string;
92
+ id?: string | null;
93
+ };
94
+ isAdmin: boolean;
95
+ previewLinks: boolean;
96
+ collections: {
97
+ slug: string;
98
+ label: string;
99
+ visibility: "public" | "internal";
100
+ canWrite: boolean;
101
+ canPublish: boolean;
102
+ }[];
103
+ }
104
+ interface CollectionSchema {
105
+ slug: string;
106
+ label: string;
107
+ visibility: "public" | "internal";
108
+ categories: string[] | null;
109
+ draftsMode: boolean;
110
+ hasUrl: boolean;
111
+ fields: Record<string, unknown> | null;
112
+ admin: Record<string, {
113
+ label?: string;
114
+ help?: string;
115
+ widget?: string;
116
+ }>;
117
+ forbiddenChars: string[];
118
+ canWrite: boolean;
119
+ canPublish: boolean;
120
+ }
121
+ interface ListQuery {
122
+ state?: "draft" | "published" | "modified" | "archived";
123
+ q?: string;
124
+ category?: string;
125
+ by?: "user" | "key" | "system";
126
+ limit?: number;
127
+ cursor?: string | null;
128
+ hits?: boolean;
129
+ }
130
+ declare function createRestClient(opts: RestClientOptions): {
131
+ me: () => Promise<Me>;
132
+ schema: (c: string) => Promise<CollectionSchema>;
133
+ list: (c: string, q?: ListQuery) => Promise<{
134
+ docs: DocSummary[];
135
+ total: number;
136
+ nextCursor: string | null;
137
+ }>;
138
+ counts: (c: string) => Promise<DocCounts>;
139
+ get: (c: string, s: string, o?: {
140
+ draft?: boolean;
141
+ }) => Promise<CmsDoc>;
142
+ create: (c: string, d: DocInputWire, o?: {
143
+ publish?: boolean;
144
+ note?: string;
145
+ }) => Promise<CmsDoc>;
146
+ update: (c: string, s: string, d: DocInputWire, o: {
147
+ expectedVersion: number;
148
+ publish?: boolean;
149
+ note?: string;
150
+ }) => Promise<CmsDoc>;
151
+ remove: (c: string, s: string, expectedVersion?: number) => Promise<{
152
+ ok: true;
153
+ }>;
154
+ diagnose: (c: string, d: DocInputWire, slug?: string) => Promise<Diagnostic[]>;
155
+ patch: (c: string, s: string, ops: PatchOp[], o?: {
156
+ expectedVersion?: number;
157
+ dryRun?: boolean;
158
+ }) => Promise<{
159
+ doc: CmsDoc | null;
160
+ diff: string;
161
+ diagnostics: Diagnostic[];
162
+ saved: boolean;
163
+ }>;
164
+ autosave: (c: string, s: string, d: DocInputWire, baseVersion: number) => Promise<AutosaveState>;
165
+ discardAutosave: (c: string, s: string) => Promise<{
166
+ ok: true;
167
+ }>;
168
+ publish: (c: string, s: string, o?: {
169
+ expectedVersion?: number;
170
+ version?: number;
171
+ }) => Promise<CmsDoc>;
172
+ unpublish: (c: string, s: string, expectedVersion?: number) => Promise<CmsDoc>;
173
+ archive: (c: string, s: string, expectedVersion?: number) => Promise<CmsDoc>;
174
+ unarchive: (c: string, s: string, expectedVersion?: number) => Promise<CmsDoc>;
175
+ bulk: (c: string, action: BulkAction, items: {
176
+ slug: string;
177
+ expectedVersion?: number;
178
+ }[]) => Promise<BulkResult[]>;
179
+ versions: (c: string, s: string) => Promise<VersionSummary[]>;
180
+ version: (c: string, s: string, n: number) => Promise<CmsVersion>;
181
+ diff: (c: string, s: string, a: number, b: number) => Promise<DocDiff>;
182
+ restore: (c: string, s: string, n: number, o?: {
183
+ expectedVersion?: number;
184
+ publish?: boolean;
185
+ }) => Promise<CmsDoc>;
186
+ changes: (c: string, s: string) => Promise<AgentChange[]>;
187
+ review: (c: string, s: string, hunks: string[] | "all", action?: "accepted" | "reverted") => Promise<{
188
+ reviewed: number;
189
+ }>;
190
+ previewLink: (c: string, s: string, ttl?: PreviewTtl) => Promise<PreviewLink>;
191
+ search: (q: string, collections?: string[]) => Promise<{
192
+ empty: boolean;
193
+ hits: {
194
+ collection: string;
195
+ slug: string;
196
+ title: string;
197
+ heading: string;
198
+ anchor: string;
199
+ score: number;
200
+ }[];
201
+ }>;
202
+ keys: () => Promise<CmsKey[]>;
203
+ createKey: (k: {
204
+ name: string;
205
+ scopes: KeyScope[];
206
+ collections?: string[] | null;
207
+ expiresAt?: string | null;
208
+ }) => Promise<{
209
+ key: CmsKey;
210
+ secret: string;
211
+ }>;
212
+ revokeKey: (id: string) => Promise<{
213
+ ok: true;
214
+ }>;
215
+ audit: (q?: {
216
+ cursor?: string | null;
217
+ action?: string;
218
+ outcome?: string;
219
+ actorKind?: "user" | "key" | "system" | "anonymous";
220
+ limit?: number;
221
+ }) => Promise<{
222
+ entries: AuditEntry[];
223
+ nextCursor: string | null;
224
+ }>;
225
+ };
226
+ type RestClient = ReturnType<typeof createRestClient>;
227
+
228
+ export { type CmsClient, type CmsClientOptions, CmsRemoteError, type CollectionSchema, type ListQuery, type Me, type RemoteTool, type RestClient, type RestClientOptions, createCmsClient, createRestClient, isCmsRemoteError };
@@ -0,0 +1,228 @@
1
+ import { l as PatchOp, b as BulkAction, c as BulkResult, D as DocDiff, A as AgentChange, o as PreviewTtl, m as PreviewLink } from './cms-BPp01z-8.js';
2
+ import { ErrorParams, Diagnostic } from './errors.js';
3
+ import { DocSummary, DocCounts, CmsDoc, AutosaveState, VersionSummary, CmsVersion, CmsKey, KeyScope, AuditEntry } from './types.js';
4
+ import 'zod';
5
+ import './diff.js';
6
+ import './repo-BWI2Pkrv.js';
7
+
8
+ /** Types the REST client sends and receives (re-exported for the admin screens). Type-only, browser-safe. */
9
+
10
+ /** A document body for create / update over REST. */
11
+ interface DocInputWire {
12
+ slug?: string;
13
+ title?: string;
14
+ summary?: string;
15
+ body?: string;
16
+ category?: string | null;
17
+ keywords?: string[];
18
+ fields?: Record<string, unknown>;
19
+ }
20
+
21
+ /**
22
+ * Clients for an app that runs agent-cms. Browser- and edge-safe (only
23
+ * `fetch`).
24
+ *
25
+ * - `createCmsClient({ url, key })`: the agent tools over MCP with an API key
26
+ * (scripts, CI, another service, the CLI). Never ship a write key to a browser.
27
+ * - `createRestClient({ url })`: the REST API with the browser's session
28
+ * cookie. This is what the copied admin screens use.
29
+ */
30
+
31
+ interface CmsClientOptions {
32
+ /** The CMS base URL, e.g. https://app.example.com/api/cms */
33
+ url: string;
34
+ /** An API key (`sgk_…`). */
35
+ key: string;
36
+ fetch?: typeof fetch;
37
+ /** Sent as `x-agent-cms-client` (the CLI sends "cli"). */
38
+ clientName?: string;
39
+ }
40
+ declare class CmsRemoteError extends Error {
41
+ /** e.g. "conflict_version", "forbidden_write", "not_found" (from the server), or "http" / "rpc" / "network". */
42
+ code: string;
43
+ extra: {
44
+ kind?: string;
45
+ status?: number;
46
+ params?: ErrorParams;
47
+ diagnostics?: Diagnostic[];
48
+ current?: unknown;
49
+ };
50
+ constructor(message: string,
51
+ /** e.g. "conflict_version", "forbidden_write", "not_found" (from the server), or "http" / "rpc" / "network". */
52
+ code: string, extra?: {
53
+ kind?: string;
54
+ status?: number;
55
+ params?: ErrorParams;
56
+ diagnostics?: Diagnostic[];
57
+ current?: unknown;
58
+ });
59
+ readonly isCmsRemoteError = true;
60
+ get kind(): string | undefined;
61
+ get status(): number | undefined;
62
+ get params(): ErrorParams | undefined;
63
+ get diagnostics(): Diagnostic[] | undefined;
64
+ /** On `conflict_version`: the working copy someone else saved (for a merge). */
65
+ get current(): unknown;
66
+ }
67
+ /** Like `isCmsError`: survives duplicated copies of this class in a bundle. */
68
+ declare function isCmsRemoteError(e: unknown): e is CmsRemoteError;
69
+ interface RemoteTool {
70
+ name: string;
71
+ description: string;
72
+ inputSchema: Record<string, unknown>;
73
+ }
74
+ declare function createCmsClient(opts: CmsClientOptions): {
75
+ /** Tools this key can use. */
76
+ listTools(): Promise<RemoteTool[]>;
77
+ /** Call one tool (see `CMS_TOOL_NAMES`). Throws CmsRemoteError on failure. */
78
+ call<T = unknown>(name: string, args?: Record<string, unknown>): Promise<T>;
79
+ };
80
+ type CmsClient = ReturnType<typeof createCmsClient>;
81
+ interface RestClientOptions {
82
+ /** The CMS base URL, e.g. "/api/cms" in the browser. */
83
+ url: string;
84
+ fetch?: typeof fetch;
85
+ /** Extra headers (e.g. a key for server-side use). */
86
+ headers?: Record<string, string>;
87
+ }
88
+ interface Me {
89
+ actor: {
90
+ kind: string;
91
+ label?: string;
92
+ id?: string | null;
93
+ };
94
+ isAdmin: boolean;
95
+ previewLinks: boolean;
96
+ collections: {
97
+ slug: string;
98
+ label: string;
99
+ visibility: "public" | "internal";
100
+ canWrite: boolean;
101
+ canPublish: boolean;
102
+ }[];
103
+ }
104
+ interface CollectionSchema {
105
+ slug: string;
106
+ label: string;
107
+ visibility: "public" | "internal";
108
+ categories: string[] | null;
109
+ draftsMode: boolean;
110
+ hasUrl: boolean;
111
+ fields: Record<string, unknown> | null;
112
+ admin: Record<string, {
113
+ label?: string;
114
+ help?: string;
115
+ widget?: string;
116
+ }>;
117
+ forbiddenChars: string[];
118
+ canWrite: boolean;
119
+ canPublish: boolean;
120
+ }
121
+ interface ListQuery {
122
+ state?: "draft" | "published" | "modified" | "archived";
123
+ q?: string;
124
+ category?: string;
125
+ by?: "user" | "key" | "system";
126
+ limit?: number;
127
+ cursor?: string | null;
128
+ hits?: boolean;
129
+ }
130
+ declare function createRestClient(opts: RestClientOptions): {
131
+ me: () => Promise<Me>;
132
+ schema: (c: string) => Promise<CollectionSchema>;
133
+ list: (c: string, q?: ListQuery) => Promise<{
134
+ docs: DocSummary[];
135
+ total: number;
136
+ nextCursor: string | null;
137
+ }>;
138
+ counts: (c: string) => Promise<DocCounts>;
139
+ get: (c: string, s: string, o?: {
140
+ draft?: boolean;
141
+ }) => Promise<CmsDoc>;
142
+ create: (c: string, d: DocInputWire, o?: {
143
+ publish?: boolean;
144
+ note?: string;
145
+ }) => Promise<CmsDoc>;
146
+ update: (c: string, s: string, d: DocInputWire, o: {
147
+ expectedVersion: number;
148
+ publish?: boolean;
149
+ note?: string;
150
+ }) => Promise<CmsDoc>;
151
+ remove: (c: string, s: string, expectedVersion?: number) => Promise<{
152
+ ok: true;
153
+ }>;
154
+ diagnose: (c: string, d: DocInputWire, slug?: string) => Promise<Diagnostic[]>;
155
+ patch: (c: string, s: string, ops: PatchOp[], o?: {
156
+ expectedVersion?: number;
157
+ dryRun?: boolean;
158
+ }) => Promise<{
159
+ doc: CmsDoc | null;
160
+ diff: string;
161
+ diagnostics: Diagnostic[];
162
+ saved: boolean;
163
+ }>;
164
+ autosave: (c: string, s: string, d: DocInputWire, baseVersion: number) => Promise<AutosaveState>;
165
+ discardAutosave: (c: string, s: string) => Promise<{
166
+ ok: true;
167
+ }>;
168
+ publish: (c: string, s: string, o?: {
169
+ expectedVersion?: number;
170
+ version?: number;
171
+ }) => Promise<CmsDoc>;
172
+ unpublish: (c: string, s: string, expectedVersion?: number) => Promise<CmsDoc>;
173
+ archive: (c: string, s: string, expectedVersion?: number) => Promise<CmsDoc>;
174
+ unarchive: (c: string, s: string, expectedVersion?: number) => Promise<CmsDoc>;
175
+ bulk: (c: string, action: BulkAction, items: {
176
+ slug: string;
177
+ expectedVersion?: number;
178
+ }[]) => Promise<BulkResult[]>;
179
+ versions: (c: string, s: string) => Promise<VersionSummary[]>;
180
+ version: (c: string, s: string, n: number) => Promise<CmsVersion>;
181
+ diff: (c: string, s: string, a: number, b: number) => Promise<DocDiff>;
182
+ restore: (c: string, s: string, n: number, o?: {
183
+ expectedVersion?: number;
184
+ publish?: boolean;
185
+ }) => Promise<CmsDoc>;
186
+ changes: (c: string, s: string) => Promise<AgentChange[]>;
187
+ review: (c: string, s: string, hunks: string[] | "all", action?: "accepted" | "reverted") => Promise<{
188
+ reviewed: number;
189
+ }>;
190
+ previewLink: (c: string, s: string, ttl?: PreviewTtl) => Promise<PreviewLink>;
191
+ search: (q: string, collections?: string[]) => Promise<{
192
+ empty: boolean;
193
+ hits: {
194
+ collection: string;
195
+ slug: string;
196
+ title: string;
197
+ heading: string;
198
+ anchor: string;
199
+ score: number;
200
+ }[];
201
+ }>;
202
+ keys: () => Promise<CmsKey[]>;
203
+ createKey: (k: {
204
+ name: string;
205
+ scopes: KeyScope[];
206
+ collections?: string[] | null;
207
+ expiresAt?: string | null;
208
+ }) => Promise<{
209
+ key: CmsKey;
210
+ secret: string;
211
+ }>;
212
+ revokeKey: (id: string) => Promise<{
213
+ ok: true;
214
+ }>;
215
+ audit: (q?: {
216
+ cursor?: string | null;
217
+ action?: string;
218
+ outcome?: string;
219
+ actorKind?: "user" | "key" | "system" | "anonymous";
220
+ limit?: number;
221
+ }) => Promise<{
222
+ entries: AuditEntry[];
223
+ nextCursor: string | null;
224
+ }>;
225
+ };
226
+ type RestClient = ReturnType<typeof createRestClient>;
227
+
228
+ export { type CmsClient, type CmsClientOptions, CmsRemoteError, type CollectionSchema, type ListQuery, type Me, type RemoteTool, type RestClient, type RestClientOptions, createCmsClient, createRestClient, isCmsRemoteError };
package/dist/client.js ADDED
@@ -0,0 +1,13 @@
1
+ import {
2
+ CmsRemoteError,
3
+ createCmsClient,
4
+ createRestClient,
5
+ isCmsRemoteError
6
+ } from "./chunk-QC2M4NZY.js";
7
+ import "./chunk-2NTK7H4W.js";
8
+ export {
9
+ CmsRemoteError,
10
+ createCmsClient,
11
+ createRestClient,
12
+ isCmsRemoteError
13
+ };