@mainsoft/agent-cms 0.0.0-stage → 0.6.1

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 +49 -0
  2. package/LICENSE +21 -0
  3. package/README.md +347 -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-BTO42652.js +249 -0
  20. package/dist/chunk-CRDW6Q72.js +188 -0
  21. package/dist/chunk-DD56PTZ4.js +78 -0
  22. package/dist/chunk-DOADAH4L.js +52 -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-QIUXAUQ6.js +6 -0
  28. package/dist/chunk-QQV6VLYJ.js +204 -0
  29. package/dist/chunk-T66ZKBHF.js +25 -0
  30. package/dist/chunk-VICZ76TR.js +118 -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 +1104 -0
  60. package/dist/http.d.cts +67 -0
  61. package/dist/http.d.ts +67 -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 +649 -0
  72. package/dist/mcp.d.cts +33 -0
  73. package/dist/mcp.d.ts +33 -0
  74. package/dist/mcp.js +24 -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,411 @@
1
+ import { ZodTypeAny, z } from 'zod';
2
+ import { FieldChange, Hunk } from './diff.cjs';
3
+ import { Messages, Diagnostic, CmsErrorCode } from './errors.cjs';
4
+ import { C as CmsRepo } from './repo-CeDxUxO6.cjs';
5
+ import { CollectionConfig, SearchMissEvent, Actor, CmsDoc, DocStatus, DocSummary, DocCounts, CmsVersion, VersionSummary, DocContent, ReviewMark, Via, KeyScope, CmsKey, AuditEntry } from './types.cjs';
6
+
7
+ /**
8
+ * Section patches: change one `## ` section of a body without resending the
9
+ * whole document. Anchors are the ones `splitSections()` and the public page
10
+ * use, so an agent can patch the section a search result pointed at.
11
+ */
12
+ type PatchOp =
13
+ /** Replace the text under the section's heading (the heading stays unless `heading` is given). */
14
+ {
15
+ op: "replace";
16
+ anchor: string;
17
+ markdown: string;
18
+ heading?: string;
19
+ }
20
+ /** Insert markdown (usually a new `## ` section) right after / before the section. */
21
+ | {
22
+ op: "insert_after";
23
+ anchor: string;
24
+ markdown: string;
25
+ } | {
26
+ op: "insert_before";
27
+ anchor: string;
28
+ markdown: string;
29
+ }
30
+ /** Remove the section with its heading. */
31
+ | {
32
+ op: "delete";
33
+ anchor: string;
34
+ }
35
+ /** Add markdown at the end of the body. */
36
+ | {
37
+ op: "append";
38
+ markdown: string;
39
+ };
40
+ interface SectionRange {
41
+ /** "" = the text before the first heading. */
42
+ anchor: string;
43
+ heading: string;
44
+ /** Line index of the heading (or 0 for the intro). */
45
+ start: number;
46
+ /** First line after the section (exclusive). */
47
+ end: number;
48
+ /** True when the section has a heading line. */
49
+ hasHeading: boolean;
50
+ }
51
+ /** Where each section is, by line. Same anchors as `splitSections()`. */
52
+ declare function sectionRanges(body: string): SectionRange[];
53
+ /** Apply ops in order. Throws `invalid_anchor` (with the valid anchors) for an unknown section. */
54
+ declare function applyPatch(body: string, ops: PatchOp[]): string;
55
+
56
+ /**
57
+ * In-memory keyword search over published documents, split into sections.
58
+ *
59
+ * Why not Postgres full-text or embeddings: the corpus is small (hundreds of
60
+ * sections), the agent is waiting on it mid-answer, and Korean questions
61
+ * ("슬랙 어떻게 연결해?") rarely share exact words with a title ("Slack
62
+ * 연결하기"). Hangul words are indexed as whole words AND 2-grams, so
63
+ * "연결해" still meets "연결하기"; authors add aliases ("슬랙", "slack") as
64
+ * keywords, which weigh the most. Building the index is a few ms; a query is
65
+ * well under one.
66
+ */
67
+ interface SearchUnit {
68
+ docId: string;
69
+ collection: string;
70
+ slug: string;
71
+ title: string;
72
+ summary: string;
73
+ category: string | null;
74
+ keywords: string[];
75
+ /** Section anchor ("" = intro). */
76
+ anchor: string;
77
+ heading: string;
78
+ markdown: string;
79
+ publishedAt: string | null;
80
+ fields: Record<string, unknown>;
81
+ }
82
+ interface SearchHit {
83
+ unit: SearchUnit;
84
+ score: number;
85
+ /** Share of the query's meaningful words that matched (0–1). */
86
+ coverage: number;
87
+ }
88
+ declare function normalizeQuery(q: string): string;
89
+
90
+ /**
91
+ * The CMS itself: every rule about documents, versions, publishing, access,
92
+ * search, keys, previews and the audit log. Transport-free: REST (`http.ts`),
93
+ * MCP (`mcp.ts`), AI SDK tools (`ai.ts`) and the CLI are thin shells over this
94
+ * object, so they can never disagree.
95
+ *
96
+ * User questions are app data: the CMS stores none of them. A search the
97
+ * caller flags with `reportMiss` that finds nothing calls `onSearchMiss`, and
98
+ * the app decides what to keep.
99
+ */
100
+
101
+ /** Any collection (the default when nothing is known about the set). */
102
+ type AnyCollection = CollectionConfig<ZodTypeAny | undefined, string>;
103
+ declare function defineCollection<const S extends string, F extends ZodTypeAny | undefined = undefined>(c: CollectionConfig<F, S>): CollectionConfig<F, S>;
104
+ /** Collection slugs of a set (a union of literals when the set was declared with `defineCollection`). */
105
+ type CollectionName<C extends readonly AnyCollection[]> = C[number]["slug"];
106
+ /** The parsed `fields` type of collection `N` (zod output), or a plain record. */
107
+ type FieldsOf<C extends readonly AnyCollection[], N extends string> = Extract<C[number], {
108
+ slug: N;
109
+ }> extends CollectionConfig<infer F, string> ? [F] extends [undefined] ? Record<string, unknown> : [ZodTypeAny] extends [F] ? Record<string, unknown> : z.output<NonNullable<F>> : Record<string, unknown>;
110
+ type TypedDoc<F> = Omit<CmsDoc, "fields"> & {
111
+ fields: F;
112
+ };
113
+ declare const SLUG_RE: RegExp;
114
+ declare const LIMITS: {
115
+ readonly slug: 120;
116
+ readonly title: 200;
117
+ readonly summary: 300;
118
+ readonly body: 60000;
119
+ readonly keyword: 40;
120
+ readonly keywords: 30;
121
+ };
122
+ interface DocInput<F = Record<string, unknown>> {
123
+ slug?: string;
124
+ title?: string;
125
+ summary?: string;
126
+ body?: string;
127
+ category?: string | null;
128
+ keywords?: string[];
129
+ /** On update: a JSON Merge Patch (a key set to null is removed). */
130
+ fields?: FieldsPatch<F>;
131
+ }
132
+ /** A merge patch of `F`: every key optional, objects patched recursively, null removes. */
133
+ type FieldsPatch<F> = F extends readonly unknown[] ? F : F extends Record<string, unknown> ? {
134
+ [K in keyof F]?: FieldsPatch<F[K]> | null;
135
+ } : F;
136
+ interface WriteOptions {
137
+ /** Version the caller last read; a mismatch is a 409 (someone else saved). */
138
+ expectedVersion?: number;
139
+ /** Why it changed (shown in the version list). */
140
+ note?: string | null;
141
+ /** Publish right away (needs publish permission). */
142
+ publish?: boolean;
143
+ }
144
+ interface SearchResult {
145
+ hits: SearchHit[];
146
+ /** True when nothing relevant was found. */
147
+ empty: boolean;
148
+ }
149
+ interface SearchOptions {
150
+ limit?: number;
151
+ perDoc?: number;
152
+ /** When nothing is found, tell the app through `onSearchMiss`. */
153
+ reportMiss?: boolean;
154
+ /** @deprecated since 0.6.0: renamed to `reportMiss`. */
155
+ logGap?: boolean;
156
+ filter?: (u: SearchHit["unit"]) => boolean;
157
+ }
158
+ interface CreateCmsOptions<C extends readonly AnyCollection[] = readonly AnyCollection[]> {
159
+ repo: CmsRepo;
160
+ collections: C;
161
+ /** How often to check whether another process changed documents (ms). Default 60s. */
162
+ searchRefreshMs?: number;
163
+ /** Search results below this coverage count as "nothing found". Default 0.5. */
164
+ minCoverage?: number;
165
+ now?: () => Date;
166
+ /** IANA time zone that decides which calendar day a usage hit counts for. Default "UTC". */
167
+ timeZone?: string;
168
+ /** Error messages (default English). `import { ko } from "@mainsoft/agent-cms/messages/ko"`. */
169
+ messages?: Partial<Messages>;
170
+ /**
171
+ * Called (not awaited) when a search flagged with `reportMiss` found
172
+ * nothing. Store it in your own table if you want a "questions nobody
173
+ * answered" screen; the CMS keeps nothing. Errors go to `onError`.
174
+ */
175
+ onSearchMiss?: (e: SearchMissEvent) => void | Promise<void>;
176
+ /** Secret for signed draft preview links (32+ characters). Preview links are off without it. */
177
+ previewSecret?: string;
178
+ /** Check `cms_meta.schema_version` before the first call. Default true. */
179
+ schemaCheck?: boolean;
180
+ onError?: (err: unknown, where: string) => void;
181
+ /** Deprecation and setup warnings (default console.warn), each once. */
182
+ warn?: (message: string) => void;
183
+ }
184
+ /** Second argument of `afterChange` hooks and `onChange` listeners. */
185
+ interface ChangeInfo {
186
+ /**
187
+ * True when what the public sees changed (published content, publish,
188
+ * unpublish, archive, unarchive, delete). False for draft-only saves.
189
+ */
190
+ contentChanged: boolean;
191
+ }
192
+ /** `YYYY-MM-DD` of `d` in `timeZone`. */
193
+ declare function dayIn(timeZone: string, d: Date): string;
194
+ interface ListOptions {
195
+ drafts?: boolean;
196
+ status?: DocStatus;
197
+ /** Display state (editors): draft, published (incl. modified), modified, archived. */
198
+ state?: "draft" | "published" | "modified" | "archived";
199
+ category?: string;
200
+ /** Title, slug or summary contains (case-insensitive). */
201
+ q?: string;
202
+ /** Last writer kind (editors). */
203
+ by?: "user" | "key" | "system";
204
+ }
205
+ /** RFC 7396 JSON Merge Patch: objects merge, null removes a key, anything else replaces. */
206
+ declare function mergePatch(target: unknown, patch: unknown): unknown;
207
+ declare const PREVIEW_TTLS: {
208
+ readonly "1h": 3600000;
209
+ readonly "24h": 86400000;
210
+ readonly "7d": number;
211
+ };
212
+ type PreviewTtl = keyof typeof PREVIEW_TTLS;
213
+ declare const BULK_ACTIONS: readonly ["publish", "unpublish", "archive", "unarchive", "delete"];
214
+ type BulkAction = (typeof BULK_ACTIONS)[number];
215
+ interface BulkResult {
216
+ slug: string;
217
+ ok: boolean;
218
+ error?: {
219
+ code: CmsErrorCode;
220
+ message: string;
221
+ };
222
+ }
223
+ /** An agent's change still waiting for a person (`cms.agentChanges`). */
224
+ interface AgentChange {
225
+ /** Hunk id; pass it to `reviewChanges`. */
226
+ id: string;
227
+ version: number;
228
+ author: string;
229
+ authorKind: "key" | "system";
230
+ at: string;
231
+ removed: string[];
232
+ added: string[];
233
+ /** Line just before the change in that version (to put removed lines back). */
234
+ before: string | null;
235
+ }
236
+ interface PreviewLink {
237
+ url: string;
238
+ token: string;
239
+ version: number;
240
+ expiresAt: string;
241
+ }
242
+ interface PreviewRead {
243
+ collection: string;
244
+ slug: string;
245
+ version: number;
246
+ expiresAt: string;
247
+ doc: DocContent;
248
+ }
249
+ interface DocDiff {
250
+ a: number;
251
+ b: number;
252
+ fields: FieldChange[];
253
+ hunks: Hunk[];
254
+ }
255
+ /** The untyped CMS (what the transports use). `createCms` returns it with typed overloads on top. */
256
+ declare function createCmsCore(opts: CreateCmsOptions): {
257
+ collections: () => AnyCollection[];
258
+ collection: (slug: string) => AnyCollection;
259
+ can: (actor: Actor, col: string, what: "read" | "write" | "publish", doc?: CmsDoc | null) => boolean;
260
+ isAdmin: (actor: Actor) => boolean;
261
+ get: (actor: Actor, col: string, slug: string, o?: {
262
+ draft?: boolean;
263
+ }) => Promise<CmsDoc>;
264
+ list: (actor: Actor, col: string, o?: ListOptions) => Promise<CmsDoc[]>;
265
+ page: (actor: Actor, col: string, o?: ListOptions & {
266
+ limit?: number;
267
+ cursor?: string | null;
268
+ hits?: boolean;
269
+ }) => Promise<{
270
+ docs: DocSummary[];
271
+ total: number;
272
+ nextCursor: string | null;
273
+ }>;
274
+ counts: (actor: Actor, col: string) => Promise<DocCounts>;
275
+ versions: (actor: Actor, col: string, slug: string) => Promise<CmsVersion[]>;
276
+ versionList: (actor: Actor, col: string, slug: string) => Promise<VersionSummary[]>;
277
+ version: (actor: Actor, col: string, slug: string, n: number) => Promise<CmsVersion>;
278
+ diff: (actor: Actor, col: string, slug: string, a: number, b: number, o?: {
279
+ context?: number;
280
+ }) => Promise<DocDiff>;
281
+ diagnose: (actor: Actor, col: string, input: DocInput, o?: {
282
+ slug?: string;
283
+ }) => Promise<Diagnostic[]>;
284
+ create: (actor: Actor, col: string, input: DocInput, o?: WriteOptions) => Promise<CmsDoc>;
285
+ update: (actor: Actor, col: string, slug: string, input: DocInput, o?: WriteOptions) => Promise<CmsDoc>;
286
+ patch: (actor: Actor, col: string, slug: string, ops: PatchOp[], o?: WriteOptions & {
287
+ dryRun?: boolean;
288
+ }) => Promise<{
289
+ doc: CmsDoc | null;
290
+ diff: string;
291
+ diagnostics: Diagnostic[];
292
+ saved: boolean;
293
+ }>;
294
+ sections: (actor: Actor, col: string, slug: string) => Promise<{
295
+ anchor: string;
296
+ heading: string;
297
+ }[]>;
298
+ autosave: (actor: Actor, col: string, slug: string, input: DocInput, baseVersion: number) => Promise<{
299
+ content: DocContent;
300
+ at: string;
301
+ by: string;
302
+ baseVersion: number;
303
+ }>;
304
+ discardAutosave: (actor: Actor, col: string, slug: string) => Promise<void>;
305
+ publish: (actor: Actor, col: string, slug: string, o?: {
306
+ version?: number;
307
+ expectedVersion?: number;
308
+ }) => Promise<CmsDoc>;
309
+ archive: (actor: Actor, col: string, slug: string, o?: {
310
+ expectedVersion?: number;
311
+ }) => Promise<CmsDoc>;
312
+ unarchive: (actor: Actor, col: string, slug: string, o?: {
313
+ expectedVersion?: number;
314
+ }) => Promise<CmsDoc>;
315
+ unpublish: (actor: Actor, col: string, slug: string, o?: {
316
+ expectedVersion?: number;
317
+ }) => Promise<CmsDoc>;
318
+ restore: (actor: Actor, col: string, slug: string, n: number, o?: WriteOptions) => Promise<CmsDoc>;
319
+ remove: (actor: Actor, col: string, slug: string, o?: {
320
+ expectedVersion?: number;
321
+ }) => Promise<void>;
322
+ bulk: (actor: Actor, col: string, action: BulkAction, items: {
323
+ slug: string;
324
+ expectedVersion?: number;
325
+ }[]) => Promise<BulkResult[]>;
326
+ agentChanges: (actor: Actor, col: string, slug: string) => Promise<AgentChange[]>;
327
+ reviewChanges: (actor: Actor, col: string, slug: string, o: {
328
+ hunks: string[] | "all";
329
+ action?: ReviewMark["action"];
330
+ }) => Promise<{
331
+ reviewed: number;
332
+ }>;
333
+ createPreviewLink: (actor: Actor, col: string, slug: string, o?: {
334
+ ttl?: PreviewTtl;
335
+ }) => Promise<PreviewLink>;
336
+ readPreview: (token: string) => Promise<PreviewRead>;
337
+ previewEnabled: () => boolean;
338
+ search: (actor: Actor, cols: string[], query: string, o?: SearchOptions) => Promise<SearchResult>;
339
+ recordHits: (docIds: string[], source?: Via) => Promise<void>;
340
+ hitCounts: (actor: Actor, col: string, days?: number) => Promise<Map<string, number>>;
341
+ createKey: (actor: Actor, input: {
342
+ name: string;
343
+ scopes: KeyScope[];
344
+ collections?: string[] | null;
345
+ expiresAt?: string | null;
346
+ }) => Promise<{
347
+ key: CmsKey;
348
+ secret: string;
349
+ }>;
350
+ listKeys: (actor: Actor) => Promise<CmsKey[]>;
351
+ revokeKey: (actor: Actor, id: string) => Promise<void>;
352
+ authenticateKey: (raw: string) => Promise<Extract<Actor, {
353
+ kind: "key";
354
+ }> | null>;
355
+ audit: (actor: Actor, o?: {
356
+ cursor?: string | null;
357
+ limit?: number;
358
+ action?: string;
359
+ outcome?: AuditEntry["outcome"];
360
+ actorKind?: AuditEntry["actorKind"];
361
+ }) => Promise<{
362
+ entries: AuditEntry[];
363
+ nextCursor: string | null;
364
+ }>;
365
+ message: (e: unknown) => string;
366
+ messages: Partial<Messages> | undefined;
367
+ /** Fails with `schema_outdated` when the database needs a migration. */
368
+ checkSchema: () => Promise<void>;
369
+ /** Warm the search index (e.g. at boot) so the first agent call is fast. */
370
+ warm: () => Promise<void>;
371
+ onChange(fn: (doc: CmsDoc, info: ChangeInfo) => void): () => boolean;
372
+ repo: CmsRepo;
373
+ };
374
+ type CmsCore = ReturnType<typeof createCmsCore>;
375
+ type Typed = "get" | "list" | "create" | "update" | "publish" | "archive" | "unarchive" | "unpublish" | "restore";
376
+ /**
377
+ * The CMS with types from its collections: collection names are checked at
378
+ * compile time and `fields` is the collection's zod output.
379
+ */
380
+ type Cms<C extends readonly AnyCollection[] = readonly AnyCollection[]> = Omit<CmsCore, Typed> & {
381
+ /** The untyped CMS (what REST, MCP and the tools use). */
382
+ readonly core: CmsCore;
383
+ get<N extends CollectionName<C>>(actor: Actor, col: N, slug: string, o?: {
384
+ draft?: boolean;
385
+ }): Promise<TypedDoc<FieldsOf<C, N>>>;
386
+ list<N extends CollectionName<C>>(actor: Actor, col: N, o?: Parameters<CmsCore["list"]>[2]): Promise<TypedDoc<FieldsOf<C, N>>[]>;
387
+ create<N extends CollectionName<C>>(actor: Actor, col: N, input: DocInput<FieldsOf<C, N>>, o?: WriteOptions): Promise<TypedDoc<FieldsOf<C, N>>>;
388
+ update<N extends CollectionName<C>>(actor: Actor, col: N, slug: string, input: DocInput<FieldsOf<C, N>>, o?: WriteOptions): Promise<TypedDoc<FieldsOf<C, N>>>;
389
+ publish<N extends CollectionName<C>>(actor: Actor, col: N, slug: string, o?: {
390
+ version?: number;
391
+ expectedVersion?: number;
392
+ }): Promise<TypedDoc<FieldsOf<C, N>>>;
393
+ archive<N extends CollectionName<C>>(actor: Actor, col: N, slug: string, o?: {
394
+ expectedVersion?: number;
395
+ }): Promise<TypedDoc<FieldsOf<C, N>>>;
396
+ unarchive<N extends CollectionName<C>>(actor: Actor, col: N, slug: string, o?: {
397
+ expectedVersion?: number;
398
+ }): Promise<TypedDoc<FieldsOf<C, N>>>;
399
+ unpublish<N extends CollectionName<C>>(actor: Actor, col: N, slug: string, o?: {
400
+ expectedVersion?: number;
401
+ }): Promise<TypedDoc<FieldsOf<C, N>>>;
402
+ restore<N extends CollectionName<C>>(actor: Actor, col: N, slug: string, n: number, o?: WriteOptions): Promise<TypedDoc<FieldsOf<C, N>>>;
403
+ };
404
+ /** Anything that carries a CMS (the typed `Cms` or the core itself). */
405
+ type CmsLike = {
406
+ readonly core: CmsCore;
407
+ } | CmsCore;
408
+ declare const coreOf: (c: CmsLike) => CmsCore;
409
+ declare function createCms<const C extends readonly AnyCollection[]>(opts: CreateCmsOptions<C>): Cms<C>;
410
+
411
+ export { type AgentChange as A, BULK_ACTIONS as B, type CmsLike as C, type DocDiff as D, sectionRanges as E, type FieldsOf as F, LIMITS as L, PREVIEW_TTLS as P, SLUG_RE as S, type TypedDoc as T, type WriteOptions as W, type AnyCollection as a, type BulkAction as b, type BulkResult as c, type ChangeInfo as d, type Cms as e, type CmsCore as f, type CollectionName as g, type CreateCmsOptions as h, type DocInput as i, type FieldsPatch as j, type ListOptions as k, type PatchOp as l, type PreviewLink as m, type PreviewRead as n, type PreviewTtl as o, type SearchOptions as p, type SearchResult as q, type SectionRange as r, applyPatch as s, coreOf as t, createCms as u, createCmsCore as v, dayIn as w, defineCollection as x, mergePatch as y, normalizeQuery as z };
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/config.ts
31
+ var config_exports = {};
32
+ __export(config_exports, {
33
+ CONFIG_FILES: () => CONFIG_FILES,
34
+ defineConfig: () => defineConfig,
35
+ loadConfig: () => loadConfig
36
+ });
37
+ module.exports = __toCommonJS(config_exports);
38
+ function defineConfig(c) {
39
+ return c;
40
+ }
41
+ var CONFIG_FILES = ["agent-cms.config.ts", "agent-cms.config.mts", "agent-cms.config.js", "agent-cms.config.mjs"];
42
+ async function loadConfig(cwd) {
43
+ const { existsSync } = await import("fs");
44
+ const { join } = await import("path");
45
+ for (const f of CONFIG_FILES) {
46
+ const path = join(cwd, f);
47
+ if (!existsSync(path)) continue;
48
+ const { createJiti } = await import("jiti");
49
+ const jiti = createJiti(join(cwd, "_"), { interopDefault: true });
50
+ const mod = await jiti.import(path);
51
+ const config = mod && "default" in mod ? mod.default : mod;
52
+ return { path, config: config ?? {} };
53
+ }
54
+ return null;
55
+ }
56
+ // Annotate the CommonJS export names for ESM import in node:
57
+ 0 && (module.exports = {
58
+ CONFIG_FILES,
59
+ defineConfig,
60
+ loadConfig
61
+ });
@@ -0,0 +1,36 @@
1
+ import { PgDatabase } from 'drizzle-orm/pg-core';
2
+ import { CmsTablesOptions } from './tables.cjs';
3
+ import './types.cjs';
4
+ import 'zod';
5
+ import './errors.cjs';
6
+
7
+ /**
8
+ * `agent-cms.config.ts`: what the local CLI commands (`init`, `doctor`,
9
+ * `migrate`, `add`) need to know about the app. Loaded with jiti, so it can
10
+ * be TypeScript and import the app's own modules.
11
+ *
12
+ * import { defineConfig } from "@mainsoft/agent-cms/config";
13
+ * export default defineConfig({
14
+ * db: async () => (await import("./lib/db")).db,
15
+ * });
16
+ */
17
+
18
+ interface AgentCmsConfig {
19
+ /** The app's Drizzle database (for `doctor` and `migrate`). */
20
+ db?: () => PgDatabase<any, any, any> | Promise<PgDatabase<any, any, any>>;
21
+ /** Same options as `cmsTables()` when the app uses a prefix or schema. */
22
+ tables?: CmsTablesOptions;
23
+ /** Where `agent-cms add` copies the admin screens. Default: `<components alias>/cms` from components.json. */
24
+ ui?: {
25
+ dir?: string;
26
+ };
27
+ }
28
+ declare function defineConfig(c: AgentCmsConfig): AgentCmsConfig;
29
+ declare const CONFIG_FILES: readonly ["agent-cms.config.ts", "agent-cms.config.mts", "agent-cms.config.js", "agent-cms.config.mjs"];
30
+ /** Find and load the config from `cwd` (null when there is none). */
31
+ declare function loadConfig(cwd: string): Promise<{
32
+ path: string;
33
+ config: AgentCmsConfig;
34
+ } | null>;
35
+
36
+ export { type AgentCmsConfig, CONFIG_FILES, defineConfig, loadConfig };
@@ -0,0 +1,36 @@
1
+ import { PgDatabase } from 'drizzle-orm/pg-core';
2
+ import { CmsTablesOptions } from './tables.js';
3
+ import './types.js';
4
+ import 'zod';
5
+ import './errors.js';
6
+
7
+ /**
8
+ * `agent-cms.config.ts`: what the local CLI commands (`init`, `doctor`,
9
+ * `migrate`, `add`) need to know about the app. Loaded with jiti, so it can
10
+ * be TypeScript and import the app's own modules.
11
+ *
12
+ * import { defineConfig } from "@mainsoft/agent-cms/config";
13
+ * export default defineConfig({
14
+ * db: async () => (await import("./lib/db")).db,
15
+ * });
16
+ */
17
+
18
+ interface AgentCmsConfig {
19
+ /** The app's Drizzle database (for `doctor` and `migrate`). */
20
+ db?: () => PgDatabase<any, any, any> | Promise<PgDatabase<any, any, any>>;
21
+ /** Same options as `cmsTables()` when the app uses a prefix or schema. */
22
+ tables?: CmsTablesOptions;
23
+ /** Where `agent-cms add` copies the admin screens. Default: `<components alias>/cms` from components.json. */
24
+ ui?: {
25
+ dir?: string;
26
+ };
27
+ }
28
+ declare function defineConfig(c: AgentCmsConfig): AgentCmsConfig;
29
+ declare const CONFIG_FILES: readonly ["agent-cms.config.ts", "agent-cms.config.mts", "agent-cms.config.js", "agent-cms.config.mjs"];
30
+ /** Find and load the config from `cwd` (null when there is none). */
31
+ declare function loadConfig(cwd: string): Promise<{
32
+ path: string;
33
+ config: AgentCmsConfig;
34
+ } | null>;
35
+
36
+ export { type AgentCmsConfig, CONFIG_FILES, defineConfig, loadConfig };
package/dist/config.js ADDED
@@ -0,0 +1,11 @@
1
+ import {
2
+ CONFIG_FILES,
3
+ defineConfig,
4
+ loadConfig
5
+ } from "./chunk-T66ZKBHF.js";
6
+ import "./chunk-2NTK7H4W.js";
7
+ export {
8
+ CONFIG_FILES,
9
+ defineConfig,
10
+ loadConfig
11
+ };