aicms 0.0.0-stage → 0.5.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 (117) hide show
  1. package/ARCHITECTURE.md +467 -0
  2. package/LICENSE +21 -0
  3. package/README.md +200 -2
  4. package/README.uk.md +201 -0
  5. package/dist/cli.d.ts +2 -0
  6. package/dist/cli.js +722 -0
  7. package/dist/config-edit.d.ts +18 -0
  8. package/dist/config-edit.js +201 -0
  9. package/dist/config.d.ts +55 -0
  10. package/dist/config.js +32 -0
  11. package/dist/edge.d.ts +22 -0
  12. package/dist/edge.js +56 -0
  13. package/dist/gates/a2a.d.ts +45 -0
  14. package/dist/gates/a2a.js +126 -0
  15. package/dist/gates/discovery.d.ts +36 -0
  16. package/dist/gates/discovery.js +54 -0
  17. package/dist/gates/events.d.ts +14 -0
  18. package/dist/gates/events.js +86 -0
  19. package/dist/gates/graphql.d.ts +41 -0
  20. package/dist/gates/graphql.js +226 -0
  21. package/dist/gates/mcp.d.ts +8 -0
  22. package/dist/gates/mcp.js +60 -0
  23. package/dist/gates/openapi.d.ts +56 -0
  24. package/dist/gates/openapi.js +61 -0
  25. package/dist/gates/rest.d.ts +21 -0
  26. package/dist/gates/rest.js +263 -0
  27. package/dist/gates/studio.d.ts +21 -0
  28. package/dist/gates/studio.js +107 -0
  29. package/dist/index.d.ts +18 -0
  30. package/dist/index.js +19 -0
  31. package/dist/kernel/action.d.ts +49 -0
  32. package/dist/kernel/action.js +22 -0
  33. package/dist/kernel/briefs.d.ts +161 -0
  34. package/dist/kernel/briefs.js +197 -0
  35. package/dist/kernel/changesets.d.ts +367 -0
  36. package/dist/kernel/changesets.js +765 -0
  37. package/dist/kernel/cms.d.ts +127 -0
  38. package/dist/kernel/cms.js +419 -0
  39. package/dist/kernel/core-actions.d.ts +5 -0
  40. package/dist/kernel/core-actions.js +487 -0
  41. package/dist/kernel/errors.d.ts +14 -0
  42. package/dist/kernel/errors.js +25 -0
  43. package/dist/kernel/install.d.ts +32 -0
  44. package/dist/kernel/install.js +34 -0
  45. package/dist/kernel/model-actions.d.ts +5 -0
  46. package/dist/kernel/model-actions.js +126 -0
  47. package/dist/kernel/modules.d.ts +221 -0
  48. package/dist/kernel/modules.js +207 -0
  49. package/dist/kernel/policy.d.ts +42 -0
  50. package/dist/kernel/policy.js +47 -0
  51. package/dist/load.d.ts +10 -0
  52. package/dist/load.js +63 -0
  53. package/dist/modules/catalog.d.ts +15 -0
  54. package/dist/modules/catalog.js +21 -0
  55. package/dist/modules/commerce.d.ts +67 -0
  56. package/dist/modules/commerce.js +260 -0
  57. package/dist/modules/git-sync.d.ts +20 -0
  58. package/dist/modules/git-sync.js +187 -0
  59. package/dist/modules/i18n.d.ts +6 -0
  60. package/dist/modules/i18n.js +168 -0
  61. package/dist/modules/index.d.ts +9 -0
  62. package/dist/modules/index.js +10 -0
  63. package/dist/modules/lint.d.ts +22 -0
  64. package/dist/modules/lint.js +126 -0
  65. package/dist/modules/media.d.ts +52 -0
  66. package/dist/modules/media.js +319 -0
  67. package/dist/modules/payments.d.ts +19 -0
  68. package/dist/modules/payments.js +110 -0
  69. package/dist/modules/search.d.ts +27 -0
  70. package/dist/modules/search.js +81 -0
  71. package/dist/modules/seo.d.ts +34 -0
  72. package/dist/modules/seo.js +189 -0
  73. package/dist/modules/text.d.ts +10 -0
  74. package/dist/modules/text.js +42 -0
  75. package/dist/node.d.ts +7 -0
  76. package/dist/node.js +11 -0
  77. package/dist/registry.d.ts +57 -0
  78. package/dist/registry.js +110 -0
  79. package/dist/schema/fields.d.ts +100 -0
  80. package/dist/schema/fields.js +134 -0
  81. package/dist/schema/markdown.d.ts +7 -0
  82. package/dist/schema/markdown.js +168 -0
  83. package/dist/schema/model.d.ts +44 -0
  84. package/dist/schema/model.js +104 -0
  85. package/dist/schema/slug.d.ts +2 -0
  86. package/dist/schema/slug.js +40 -0
  87. package/dist/store/d1.d.ts +30 -0
  88. package/dist/store/d1.js +27 -0
  89. package/dist/store/postgres.d.ts +164 -0
  90. package/dist/store/postgres.js +552 -0
  91. package/dist/store/sql.d.ts +135 -0
  92. package/dist/store/sql.js +530 -0
  93. package/dist/store/sqlite.d.ts +14 -0
  94. package/dist/store/sqlite.js +60 -0
  95. package/dist/store/types.d.ts +226 -0
  96. package/dist/store/types.js +21 -0
  97. package/dist/studio/assets/geologica-cyrillic-ext-wght-normal-C8B9Chlh.woff2 +0 -0
  98. package/dist/studio/assets/geologica-cyrillic-wght-normal-DbeVG3Ps.woff2 +0 -0
  99. package/dist/studio/assets/geologica-greek-wght-normal-DPM5d9ub.woff2 +0 -0
  100. package/dist/studio/assets/geologica-latin-ext-wght-normal-DZyYlgcm.woff2 +0 -0
  101. package/dist/studio/assets/geologica-latin-wght-normal-BBL8hQxZ.woff2 +0 -0
  102. package/dist/studio/assets/geologica-vietnamese-wght-normal-DcI17N1q.woff2 +0 -0
  103. package/dist/studio/assets/index-3dJ0YHxb.js +22 -0
  104. package/dist/studio/assets/index-DuyGLFw4.css +1 -0
  105. package/dist/studio/assets/jetbrains-mono-cyrillic-wght-normal-D73BlboJ.woff2 +0 -0
  106. package/dist/studio/assets/jetbrains-mono-greek-wght-normal-Bw9x6K1M.woff2 +0 -0
  107. package/dist/studio/assets/jetbrains-mono-latin-ext-wght-normal-DBQx-q_a.woff2 +0 -0
  108. package/dist/studio/assets/jetbrains-mono-latin-wght-normal-B9CIFXIH.woff2 +0 -0
  109. package/dist/studio/assets/jetbrains-mono-vietnamese-wght-normal-Bt-aOZkq.woff2 +0 -0
  110. package/dist/studio/assets/unbounded-cyrillic-wght-normal-C627f1f8.woff2 +0 -0
  111. package/dist/studio/assets/unbounded-latin-ext-wght-normal-D6H-S6MW.woff2 +0 -0
  112. package/dist/studio/assets/unbounded-latin-wght-normal-D5afBTBx.woff2 +0 -0
  113. package/dist/studio/assets/unbounded-vietnamese-wght-normal-rat7GD3o.woff2 +0 -0
  114. package/dist/studio/index.html +21 -0
  115. package/dist/typegen.d.ts +7 -0
  116. package/dist/typegen.js +55 -0
  117. package/package.json +88 -4
@@ -0,0 +1,226 @@
1
+ export interface EntryRow {
2
+ id: string;
3
+ model: string;
4
+ locale: string;
5
+ data: Record<string, unknown>;
6
+ version: number;
7
+ createdAt: string;
8
+ updatedAt: string;
9
+ createdBy: string;
10
+ updatedBy: string;
11
+ }
12
+ export interface VersionRow {
13
+ entryId: string;
14
+ version: number;
15
+ data: Record<string, unknown> | null;
16
+ changesetId: string | null;
17
+ actor: string;
18
+ createdAt: string;
19
+ }
20
+ /** `scheduled`: approved by a person, merged automatically at `publishAt`. */
21
+ export type ChangesetStatus = "open" | "submitted" | "scheduled" | "merged" | "rejected";
22
+ export interface ChangesetItem {
23
+ /** `install` items carry a module proposal (`id` is the module name, `data.options` its options). */
24
+ op: "create" | "update" | "delete" | "install";
25
+ model: string;
26
+ id: string;
27
+ locale: string;
28
+ /** Full data for create, a patch for update (null clears a field), absent for delete. */
29
+ data?: Record<string, unknown>;
30
+ /** Version the change was based on, for conflict detection. */
31
+ baseVersion?: number;
32
+ }
33
+ export interface CheckIssue {
34
+ entry: string;
35
+ model: string;
36
+ field?: string;
37
+ message: string;
38
+ /** The module check that found it, e.g. "lint/avoid"; absent for schema and conflict checks. */
39
+ check?: string;
40
+ }
41
+ export interface ChangesetRow {
42
+ id: string;
43
+ actor: string;
44
+ status: ChangesetStatus;
45
+ note?: string;
46
+ /** The reviewer's comment, shown to the agent. */
47
+ comment?: string;
48
+ /** Why the changeset waits for a person, if it does. */
49
+ reviewReason?: string;
50
+ items: ChangesetItem[];
51
+ /** Errors: the changeset can't be merged until they are fixed. */
52
+ issues: CheckIssue[];
53
+ /** Module check warnings: shown to the reviewer; they send an "auto" agent's changes to a person. */
54
+ warnings?: CheckIssue[];
55
+ /** When to publish: asked for by the author, or set by the reviewer when scheduling. */
56
+ publishAt?: string;
57
+ /** Who scheduled it. */
58
+ scheduledBy?: string;
59
+ /** The brief this changeset answers. */
60
+ brief?: string;
61
+ createdAt: string;
62
+ updatedAt: string;
63
+ mergedAt?: string;
64
+ mergedBy?: string;
65
+ }
66
+ /** Changeset fields kept together in one JSON column, so new ones need no migration. */
67
+ export declare const CHANGESET_META: readonly ["warnings", "publishAt", "scheduledBy", "brief"];
68
+ export declare function changesetMeta(c: ChangesetRow): Record<string, unknown> | null;
69
+ export interface EventRow {
70
+ id?: number;
71
+ at: string;
72
+ actor: string;
73
+ gate: string;
74
+ action: string;
75
+ input?: string;
76
+ ok: boolean;
77
+ error?: string;
78
+ ms: number;
79
+ }
80
+ export interface ListQuery {
81
+ model: string;
82
+ locale?: string;
83
+ /** field → value; array fields match when they contain the value. */
84
+ where?: Record<string, unknown>;
85
+ arrayFields?: string[];
86
+ order?: {
87
+ field: string;
88
+ desc: boolean;
89
+ } | null;
90
+ limit: number;
91
+ offset: number;
92
+ }
93
+ export interface IndexSpec {
94
+ model: string;
95
+ fields: string[];
96
+ }
97
+ export interface Store {
98
+ init(indexes: IndexSpec[]): Promise<void>;
99
+ close(): Promise<void>;
100
+ getEntry(id: string): Promise<EntryRow | null>;
101
+ findOne(model: string, field: string, value: unknown, locale?: string): Promise<EntryRow | null>;
102
+ list(q: ListQuery): Promise<{
103
+ items: EntryRow[];
104
+ total: number;
105
+ }>;
106
+ /** Up to `limit` entries of the given models, newest first, for scanning. */
107
+ scan(models: string[], limit: number): Promise<EntryRow[]>;
108
+ versions(entryId: string): Promise<VersionRow[]>;
109
+ getChangeset(id: string): Promise<ChangesetRow | null>;
110
+ findOpenChangeset(actor: string): Promise<ChangesetRow | null>;
111
+ createChangeset(row: ChangesetRow): Promise<void>;
112
+ saveChangeset(row: ChangesetRow): Promise<void>;
113
+ listChangesets(q: {
114
+ actor?: string;
115
+ status?: ChangesetStatus[];
116
+ limit: number;
117
+ }): Promise<ChangesetRow[]>;
118
+ /**
119
+ * Apply every item and mark the changeset merged, all in one transaction.
120
+ * Throws `ConflictError` if an entry changed since it was drafted.
121
+ */
122
+ mergeChangeset(id: string, by: string, at: string): Promise<EntryRow[]>;
123
+ logEvent(e: EventRow): Promise<void>;
124
+ countEvents(actor: string, sinceIso: string): Promise<number>;
125
+ /** Newest first. `before` is an event id, for paging back. */
126
+ listEvents(q: {
127
+ actor?: string;
128
+ limit: number;
129
+ before?: number;
130
+ }): Promise<EventRow[]>;
131
+ /** Last call and number of calls since `sinceIso`, per actor. */
132
+ actorStats(sinceIso: string): Promise<{
133
+ actor: string;
134
+ lastAt: string;
135
+ recent: number;
136
+ }[]>;
137
+ kvGet(scope: string, key: string): Promise<unknown>;
138
+ kvSet(scope: string, key: string, value: unknown): Promise<void>;
139
+ kvDelete(scope: string, key: string): Promise<void>;
140
+ kvList(scope: string, prefix?: string): Promise<{
141
+ key: string;
142
+ value: unknown;
143
+ }[]>;
144
+ textUpsert(doc: TextDoc): Promise<void>;
145
+ textRemove(id: string): Promise<void>;
146
+ textSearch(q: {
147
+ terms: string[];
148
+ prefixLast: boolean;
149
+ models: string[];
150
+ locale?: string;
151
+ limit: number;
152
+ }): Promise<TextHit[]>;
153
+ textCount(): Promise<number>;
154
+ textClear(): Promise<void>;
155
+ createMedia(row: MediaRow): Promise<void>;
156
+ getMedia(id: string): Promise<MediaRow | null>;
157
+ listMedia(q: {
158
+ query?: string;
159
+ missingAlt?: boolean;
160
+ limit: number;
161
+ offset: number;
162
+ }): Promise<{
163
+ items: MediaRow[];
164
+ total: number;
165
+ }>;
166
+ updateMedia(id: string, patch: Partial<Pick<MediaRow, "alt" | "meta">>): Promise<MediaRow | null>;
167
+ deleteMedia(id: string): Promise<boolean>;
168
+ createToken(row: TokenRow): Promise<void>;
169
+ /** An active token: not revoked and not expired at `nowIso`. */
170
+ findToken(hash: string, nowIso: string): Promise<{
171
+ id: string;
172
+ agent: string;
173
+ kind: TokenKind;
174
+ } | null>;
175
+ revokeToken(id: string, at: string): Promise<boolean>;
176
+ revokeTokens(agent: string, at: string): Promise<number>;
177
+ /** Agent tokens and Studio sessions, newest first (login codes are left out). */
178
+ listTokens(): Promise<(Omit<TokenRow, "hash"> & {
179
+ revokedAt: string | null;
180
+ })[]>;
181
+ }
182
+ export interface TextDoc {
183
+ id: string;
184
+ model: string;
185
+ locale: string;
186
+ title: string;
187
+ body: string;
188
+ /** term → weighted frequency; title terms count more. */
189
+ terms: Record<string, number>;
190
+ }
191
+ export interface TextHit {
192
+ id: string;
193
+ model: string;
194
+ locale: string;
195
+ title: string;
196
+ body: string;
197
+ score: number;
198
+ matched: number;
199
+ }
200
+ export interface MediaRow {
201
+ id: string;
202
+ url: string;
203
+ filename: string;
204
+ mime: string;
205
+ size: number;
206
+ width?: number;
207
+ height?: number;
208
+ alt?: string;
209
+ meta?: Record<string, unknown>;
210
+ createdAt: string;
211
+ createdBy: string;
212
+ }
213
+ /** `agent`: an API token. `session`: a Studio sign-in. `login`: a one-time code that starts a session. */
214
+ export type TokenKind = "agent" | "session" | "login";
215
+ export interface TokenRow {
216
+ id: string;
217
+ agent: string;
218
+ hash: string;
219
+ createdAt: string;
220
+ kind?: TokenKind;
221
+ expiresAt?: string;
222
+ }
223
+ export declare class ConflictError extends Error {
224
+ readonly entry: string;
225
+ constructor(entry: string, message: string);
226
+ }
@@ -0,0 +1,21 @@
1
+ // The storage contract. SQLite implements it today; Postgres and D1 will
2
+ // implement the same interface. Every method is atomic on its own, so the
3
+ // kernel never holds a transaction open across an `await`.
4
+ /** Changeset fields kept together in one JSON column, so new ones need no migration. */
5
+ export const CHANGESET_META = ["warnings", "publishAt", "scheduledBy", "brief"];
6
+ export function changesetMeta(c) {
7
+ const meta = {};
8
+ for (const key of CHANGESET_META) {
9
+ const v = c[key];
10
+ if (v !== undefined && !(Array.isArray(v) && !v.length))
11
+ meta[key] = v;
12
+ }
13
+ return Object.keys(meta).length ? meta : null;
14
+ }
15
+ export class ConflictError extends Error {
16
+ entry;
17
+ constructor(entry, message) {
18
+ super(message);
19
+ this.entry = entry;
20
+ }
21
+ }