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.
- package/ARCHITECTURE.md +467 -0
- package/LICENSE +21 -0
- package/README.md +200 -2
- package/README.uk.md +201 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +722 -0
- package/dist/config-edit.d.ts +18 -0
- package/dist/config-edit.js +201 -0
- package/dist/config.d.ts +55 -0
- package/dist/config.js +32 -0
- package/dist/edge.d.ts +22 -0
- package/dist/edge.js +56 -0
- package/dist/gates/a2a.d.ts +45 -0
- package/dist/gates/a2a.js +126 -0
- package/dist/gates/discovery.d.ts +36 -0
- package/dist/gates/discovery.js +54 -0
- package/dist/gates/events.d.ts +14 -0
- package/dist/gates/events.js +86 -0
- package/dist/gates/graphql.d.ts +41 -0
- package/dist/gates/graphql.js +226 -0
- package/dist/gates/mcp.d.ts +8 -0
- package/dist/gates/mcp.js +60 -0
- package/dist/gates/openapi.d.ts +56 -0
- package/dist/gates/openapi.js +61 -0
- package/dist/gates/rest.d.ts +21 -0
- package/dist/gates/rest.js +263 -0
- package/dist/gates/studio.d.ts +21 -0
- package/dist/gates/studio.js +107 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.js +19 -0
- package/dist/kernel/action.d.ts +49 -0
- package/dist/kernel/action.js +22 -0
- package/dist/kernel/briefs.d.ts +161 -0
- package/dist/kernel/briefs.js +197 -0
- package/dist/kernel/changesets.d.ts +367 -0
- package/dist/kernel/changesets.js +765 -0
- package/dist/kernel/cms.d.ts +127 -0
- package/dist/kernel/cms.js +419 -0
- package/dist/kernel/core-actions.d.ts +5 -0
- package/dist/kernel/core-actions.js +487 -0
- package/dist/kernel/errors.d.ts +14 -0
- package/dist/kernel/errors.js +25 -0
- package/dist/kernel/install.d.ts +32 -0
- package/dist/kernel/install.js +34 -0
- package/dist/kernel/model-actions.d.ts +5 -0
- package/dist/kernel/model-actions.js +126 -0
- package/dist/kernel/modules.d.ts +221 -0
- package/dist/kernel/modules.js +207 -0
- package/dist/kernel/policy.d.ts +42 -0
- package/dist/kernel/policy.js +47 -0
- package/dist/load.d.ts +10 -0
- package/dist/load.js +63 -0
- package/dist/modules/catalog.d.ts +15 -0
- package/dist/modules/catalog.js +21 -0
- package/dist/modules/commerce.d.ts +67 -0
- package/dist/modules/commerce.js +260 -0
- package/dist/modules/git-sync.d.ts +20 -0
- package/dist/modules/git-sync.js +187 -0
- package/dist/modules/i18n.d.ts +6 -0
- package/dist/modules/i18n.js +168 -0
- package/dist/modules/index.d.ts +9 -0
- package/dist/modules/index.js +10 -0
- package/dist/modules/lint.d.ts +22 -0
- package/dist/modules/lint.js +126 -0
- package/dist/modules/media.d.ts +52 -0
- package/dist/modules/media.js +319 -0
- package/dist/modules/payments.d.ts +19 -0
- package/dist/modules/payments.js +110 -0
- package/dist/modules/search.d.ts +27 -0
- package/dist/modules/search.js +81 -0
- package/dist/modules/seo.d.ts +34 -0
- package/dist/modules/seo.js +189 -0
- package/dist/modules/text.d.ts +10 -0
- package/dist/modules/text.js +42 -0
- package/dist/node.d.ts +7 -0
- package/dist/node.js +11 -0
- package/dist/registry.d.ts +57 -0
- package/dist/registry.js +110 -0
- package/dist/schema/fields.d.ts +100 -0
- package/dist/schema/fields.js +134 -0
- package/dist/schema/markdown.d.ts +7 -0
- package/dist/schema/markdown.js +168 -0
- package/dist/schema/model.d.ts +44 -0
- package/dist/schema/model.js +104 -0
- package/dist/schema/slug.d.ts +2 -0
- package/dist/schema/slug.js +40 -0
- package/dist/store/d1.d.ts +30 -0
- package/dist/store/d1.js +27 -0
- package/dist/store/postgres.d.ts +164 -0
- package/dist/store/postgres.js +552 -0
- package/dist/store/sql.d.ts +135 -0
- package/dist/store/sql.js +530 -0
- package/dist/store/sqlite.d.ts +14 -0
- package/dist/store/sqlite.js +60 -0
- package/dist/store/types.d.ts +226 -0
- package/dist/store/types.js +21 -0
- package/dist/studio/assets/geologica-cyrillic-ext-wght-normal-C8B9Chlh.woff2 +0 -0
- package/dist/studio/assets/geologica-cyrillic-wght-normal-DbeVG3Ps.woff2 +0 -0
- package/dist/studio/assets/geologica-greek-wght-normal-DPM5d9ub.woff2 +0 -0
- package/dist/studio/assets/geologica-latin-ext-wght-normal-DZyYlgcm.woff2 +0 -0
- package/dist/studio/assets/geologica-latin-wght-normal-BBL8hQxZ.woff2 +0 -0
- package/dist/studio/assets/geologica-vietnamese-wght-normal-DcI17N1q.woff2 +0 -0
- package/dist/studio/assets/index-3dJ0YHxb.js +22 -0
- package/dist/studio/assets/index-DuyGLFw4.css +1 -0
- package/dist/studio/assets/jetbrains-mono-cyrillic-wght-normal-D73BlboJ.woff2 +0 -0
- package/dist/studio/assets/jetbrains-mono-greek-wght-normal-Bw9x6K1M.woff2 +0 -0
- package/dist/studio/assets/jetbrains-mono-latin-ext-wght-normal-DBQx-q_a.woff2 +0 -0
- package/dist/studio/assets/jetbrains-mono-latin-wght-normal-B9CIFXIH.woff2 +0 -0
- package/dist/studio/assets/jetbrains-mono-vietnamese-wght-normal-Bt-aOZkq.woff2 +0 -0
- package/dist/studio/assets/unbounded-cyrillic-wght-normal-C627f1f8.woff2 +0 -0
- package/dist/studio/assets/unbounded-latin-ext-wght-normal-D6H-S6MW.woff2 +0 -0
- package/dist/studio/assets/unbounded-latin-wght-normal-D5afBTBx.woff2 +0 -0
- package/dist/studio/assets/unbounded-vietnamese-wght-normal-rat7GD3o.woff2 +0 -0
- package/dist/studio/index.html +21 -0
- package/dist/typegen.d.ts +7 -0
- package/dist/typegen.js +55 -0
- package/package.json +88 -4
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
import { Hono } from "hono";
|
|
2
|
+
import { deleteCookie, getCookie } from "hono/cookie";
|
|
3
|
+
import { AicmsError, isAicmsError } from "../kernel/errors.js";
|
|
4
|
+
import { filterableFields } from "../schema/model.js";
|
|
5
|
+
import { llmsTxt, manifest, VERSION } from "./discovery.js";
|
|
6
|
+
import { eventStream } from "./events.js";
|
|
7
|
+
import { buildSchema, runGraphQL } from "./graphql.js";
|
|
8
|
+
import { agentCard, createA2A } from "./a2a.js";
|
|
9
|
+
import { moduleContext } from "../kernel/modules.js";
|
|
10
|
+
import { handleMcpRequest } from "./mcp.js";
|
|
11
|
+
import { openapi } from "./openapi.js";
|
|
12
|
+
import { dirSource, findStudio, mountStudio, SESSION_COOKIE } from "./studio.js";
|
|
13
|
+
const SAFE_METHODS = new Set(["GET", "HEAD", "OPTIONS"]);
|
|
14
|
+
/** Cookie-authenticated writes must come from the same site (CSRF). */
|
|
15
|
+
function sameOrigin(c) {
|
|
16
|
+
const site = c.req.header("sec-fetch-site");
|
|
17
|
+
if (site)
|
|
18
|
+
return site === "same-origin";
|
|
19
|
+
const origin = c.req.header("origin");
|
|
20
|
+
if (!origin)
|
|
21
|
+
return false;
|
|
22
|
+
const host = c.req.header("x-forwarded-host") ?? c.req.header("host") ?? new URL(c.req.url).host;
|
|
23
|
+
try {
|
|
24
|
+
return new URL(origin).host === host;
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
const origin = (c) => new URL(c.req.url).origin;
|
|
31
|
+
async function body(c) {
|
|
32
|
+
const text = await c.req.text();
|
|
33
|
+
if (!text.trim())
|
|
34
|
+
return {};
|
|
35
|
+
try {
|
|
36
|
+
const parsed = JSON.parse(text);
|
|
37
|
+
if (parsed && typeof parsed === "object" && !Array.isArray(parsed))
|
|
38
|
+
return parsed;
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
/* fall through */
|
|
42
|
+
}
|
|
43
|
+
throw new AicmsError("invalid", "Request body must be a JSON object");
|
|
44
|
+
}
|
|
45
|
+
/** Query strings are strings; turn "true", "42" and "null" into what the schema expects. */
|
|
46
|
+
function coerce(value) {
|
|
47
|
+
if (value === "true")
|
|
48
|
+
return true;
|
|
49
|
+
if (value === "false")
|
|
50
|
+
return false;
|
|
51
|
+
if (value === "null")
|
|
52
|
+
return null;
|
|
53
|
+
if (/^-?\d+(\.\d+)?$/.test(value))
|
|
54
|
+
return Number(value);
|
|
55
|
+
return value;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* The HTTP surface: REST routes, discovery, OpenAPI and MCP.
|
|
59
|
+
* Everything is a thin wrapper over kernel.call(), so rules are identical across gates.
|
|
60
|
+
*/
|
|
61
|
+
export function createApp(k, opts = {}) {
|
|
62
|
+
const app = new Hono();
|
|
63
|
+
app.onError((err, c) => {
|
|
64
|
+
if (isAicmsError(err))
|
|
65
|
+
return c.json({ error: err.toJSON() }, err.status);
|
|
66
|
+
console.error("[aicms]", err);
|
|
67
|
+
return c.json({ error: { code: "internal", message: "Internal error" } }, 500);
|
|
68
|
+
});
|
|
69
|
+
// A bearer token wins; otherwise a Studio session cookie; otherwise the public actor.
|
|
70
|
+
app.use("*", async (c, next) => {
|
|
71
|
+
const header = c.req.header("authorization") ?? "";
|
|
72
|
+
const bearer = header.toLowerCase().startsWith("bearer ") ? header.slice(7).trim() : null;
|
|
73
|
+
const session = bearer ? null : (getCookie(c, SESSION_COOKIE) ?? null);
|
|
74
|
+
if (session && !SAFE_METHODS.has(c.req.method) && !sameOrigin(c))
|
|
75
|
+
throw new AicmsError("forbidden", "Cross-site request refused");
|
|
76
|
+
let actor;
|
|
77
|
+
try {
|
|
78
|
+
actor = await k.resolveToken(bearer ?? session);
|
|
79
|
+
}
|
|
80
|
+
catch (e) {
|
|
81
|
+
if (!session)
|
|
82
|
+
throw e;
|
|
83
|
+
deleteCookie(c, SESSION_COOKIE, { path: "/" }); // expired or revoked session
|
|
84
|
+
actor = await k.resolveToken(null);
|
|
85
|
+
}
|
|
86
|
+
c.set("actor", actor);
|
|
87
|
+
c.set("gate", session && actor.kind !== "public" ? "studio" : "rest");
|
|
88
|
+
await next();
|
|
89
|
+
});
|
|
90
|
+
const call = (c, name, input) => k.call(name, input, { actor: c.get("actor"), gate: c.get("gate") });
|
|
91
|
+
const model = (name) => {
|
|
92
|
+
const m = k.models.get(name);
|
|
93
|
+
if (!m)
|
|
94
|
+
throw new AicmsError("not_found", `No model "${name}". Models: ${[...k.models.keys()].join(", ")}`);
|
|
95
|
+
return m;
|
|
96
|
+
};
|
|
97
|
+
// ---- discovery ----
|
|
98
|
+
app.get("/", (c) => c.json({
|
|
99
|
+
name: k.config.name,
|
|
100
|
+
software: `aicms ${VERSION}`,
|
|
101
|
+
mcp: `${origin(c)}/mcp`,
|
|
102
|
+
rest: `${origin(c)}/api/v1`,
|
|
103
|
+
openapi: `${origin(c)}/openapi.json`,
|
|
104
|
+
llms: `${origin(c)}/llms.txt`,
|
|
105
|
+
events: `${origin(c)}/api/v1/events`,
|
|
106
|
+
graphql: `${origin(c)}/graphql`,
|
|
107
|
+
a2a: `${origin(c)}/.well-known/agent-card.json`,
|
|
108
|
+
studio: `${origin(c)}/studio/`,
|
|
109
|
+
}));
|
|
110
|
+
app.get("/llms.txt", (c) => c.text(llmsTxt(k, c.get("actor"), origin(c))));
|
|
111
|
+
app.get("/.well-known/aicms.json", (c) => c.json(manifest(k, origin(c))));
|
|
112
|
+
app.get("/openapi.json", (c) => c.json(openapi(k, c.get("actor"), origin(c))));
|
|
113
|
+
// ---- GraphQL (schema rebuilt when a module adds models) ----
|
|
114
|
+
let schema = null;
|
|
115
|
+
k.on("module.installed", () => {
|
|
116
|
+
schema = null;
|
|
117
|
+
});
|
|
118
|
+
const gql = async (c, req, readOnly) => {
|
|
119
|
+
schema ??= buildSchema(k);
|
|
120
|
+
const r = await runGraphQL(k, schema, c.get("actor"), req, readOnly);
|
|
121
|
+
return c.json(r.body, r.status);
|
|
122
|
+
};
|
|
123
|
+
app.post("/graphql", async (c) => gql(c, await body(c), false));
|
|
124
|
+
app.get("/graphql", async (c) => {
|
|
125
|
+
const q = c.req.query();
|
|
126
|
+
if (!q.query)
|
|
127
|
+
return c.json({ graphql: `${origin(c)}/graphql`, hint: "POST { query, variables } or GET ?query=…; the schema is generated from your models (introspection works)." });
|
|
128
|
+
let variables;
|
|
129
|
+
try {
|
|
130
|
+
variables = q.variables ? JSON.parse(q.variables) : undefined;
|
|
131
|
+
}
|
|
132
|
+
catch {
|
|
133
|
+
throw new AicmsError("invalid", "variables must be JSON");
|
|
134
|
+
}
|
|
135
|
+
return gql(c, { query: q.query, variables, operationName: q.operationName }, true);
|
|
136
|
+
});
|
|
137
|
+
// ---- A2A: Agent Card + JSON-RPC ----
|
|
138
|
+
const a2a = createA2A(k);
|
|
139
|
+
app.get("/.well-known/agent-card.json", (c) => c.json(agentCard(k, origin(c), c.get("actor"))));
|
|
140
|
+
app.get("/.well-known/agent.json", (c) => c.json(agentCard(k, origin(c), c.get("actor"))));
|
|
141
|
+
app.post("/a2a", async (c) => {
|
|
142
|
+
let req;
|
|
143
|
+
try {
|
|
144
|
+
req = JSON.parse(await c.req.text());
|
|
145
|
+
}
|
|
146
|
+
catch {
|
|
147
|
+
return c.json({ jsonrpc: "2.0", id: null, error: { code: -32700, message: "Parse error" } });
|
|
148
|
+
}
|
|
149
|
+
return c.json(await a2a(c.get("actor"), req));
|
|
150
|
+
});
|
|
151
|
+
// ---- MCP ----
|
|
152
|
+
app.all("/mcp", (c) => handleMcpRequest(k, c.get("actor"), c.req.raw));
|
|
153
|
+
// ---- REST ----
|
|
154
|
+
app.get("/api/v1", async (c) => c.json(await call(c, "cms.describe", {})));
|
|
155
|
+
app.get("/api/v1/search", async (c) => c.json(await call(c, "cms.search", { query: c.req.query("q") ?? "", model: c.req.query("model") })));
|
|
156
|
+
app.post("/api/v1/actions/:name", async (c) => c.json(await call(c, c.req.param("name"), await body(c))));
|
|
157
|
+
// Read-only Actions also answer GET, so frontends and CDNs can cache them: ?input=<JSON>.
|
|
158
|
+
app.get("/api/v1/actions/:name", async (c) => {
|
|
159
|
+
const name = c.req.param("name");
|
|
160
|
+
const a = k.actions.get(name);
|
|
161
|
+
if (a && !a.readOnly)
|
|
162
|
+
throw new AicmsError("invalid", `"${name}" changes data; call it with POST`);
|
|
163
|
+
let input = {};
|
|
164
|
+
const raw = c.req.query("input");
|
|
165
|
+
if (raw) {
|
|
166
|
+
try {
|
|
167
|
+
input = JSON.parse(raw);
|
|
168
|
+
}
|
|
169
|
+
catch {
|
|
170
|
+
throw new AicmsError("invalid", "The input query parameter must be JSON");
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
return c.json(await call(c, name, input));
|
|
174
|
+
});
|
|
175
|
+
app.get("/api/v1/events", (c) => eventStream(k, c, c.get("actor")));
|
|
176
|
+
app.get("/api/v1/changesets", async (c) => c.json(c.req.query("review") ? await call(c, "cms.review", { status: c.req.query("status") }) : await call(c, "cms.changes", {})));
|
|
177
|
+
app.get("/api/v1/changesets/:id", async (c) => c.json(await call(c, "cms.review", { id: c.req.param("id") })));
|
|
178
|
+
app.post("/api/v1/changesets/submit", async (c) => c.json(await call(c, "cms.submit", await body(c))));
|
|
179
|
+
app.post("/api/v1/changesets/:id/merge", async (c) => c.json(await call(c, "cms.merge", { ...(await body(c)), id: c.req.param("id") })));
|
|
180
|
+
app.post("/api/v1/changesets/:id/unschedule", async (c) => c.json(await call(c, "cms.unschedule", { id: c.req.param("id") })));
|
|
181
|
+
app.post("/api/v1/changesets/:id/reject", async (c) => c.json(await call(c, "cms.reject", { ...(await body(c)), id: c.req.param("id") })));
|
|
182
|
+
app.post("/api/v1/changesets/:id/revert", async (c) => {
|
|
183
|
+
const draft = await call(c, "cms.revert", { changeset: c.req.param("id") });
|
|
184
|
+
if (c.req.query("submit") === "true")
|
|
185
|
+
return c.json({ draft, submit: await call(c, "cms.submit", { note: `Revert ${c.req.param("id")}` }) });
|
|
186
|
+
return c.json(draft);
|
|
187
|
+
});
|
|
188
|
+
app.get("/api/v1/:model", async (c) => {
|
|
189
|
+
const m = model(c.req.param("model"));
|
|
190
|
+
const q = c.req.query();
|
|
191
|
+
const where = {};
|
|
192
|
+
for (const f of filterableFields(m))
|
|
193
|
+
if (q[f] !== undefined)
|
|
194
|
+
where[f] = coerce(q[f]);
|
|
195
|
+
return c.json(await call(c, `${m.name}.list`, {
|
|
196
|
+
...(Object.keys(where).length ? { where } : {}),
|
|
197
|
+
...(q.fields ? { fields: q.fields.split(",") } : {}),
|
|
198
|
+
...(q.order ? { order: q.order } : {}),
|
|
199
|
+
...(q.limit ? { limit: Number(q.limit) } : {}),
|
|
200
|
+
...(q.offset ? { offset: Number(q.offset) } : {}),
|
|
201
|
+
...(q.locale ? { locale: q.locale } : {}),
|
|
202
|
+
...(q.format ? { format: q.format } : {}),
|
|
203
|
+
}));
|
|
204
|
+
});
|
|
205
|
+
app.get("/api/v1/:model/:id", async (c) => {
|
|
206
|
+
const m = model(c.req.param("model"));
|
|
207
|
+
const q = c.req.query();
|
|
208
|
+
return c.json(await call(c, `${m.name}.get`, { id: c.req.param("id"), ...(q.fields ? { fields: q.fields.split(",") } : {}), ...(q.format ? { format: q.format } : {}) }));
|
|
209
|
+
});
|
|
210
|
+
app.get("/api/v1/:model/:id/history", async (c) => {
|
|
211
|
+
model(c.req.param("model"));
|
|
212
|
+
const v = c.req.query("version");
|
|
213
|
+
return c.json(await call(c, "cms.history", { id: c.req.param("id"), ...(v ? { version: Number(v) } : {}), ...(c.req.query("format") ? { format: c.req.query("format") } : {}) }));
|
|
214
|
+
});
|
|
215
|
+
app.post("/api/v1/:model/:id/restore", async (c) => {
|
|
216
|
+
model(c.req.param("model"));
|
|
217
|
+
const { version } = await body(c);
|
|
218
|
+
const draft = await call(c, "cms.restore", { id: c.req.param("id"), version });
|
|
219
|
+
if (c.req.query("submit") === "true")
|
|
220
|
+
return c.json({ draft, submit: await call(c, "cms.submit", { note: `Restore ${c.req.param("id")} to v${version}` }) });
|
|
221
|
+
return c.json(draft);
|
|
222
|
+
});
|
|
223
|
+
app.post("/api/v1/:model", async (c) => {
|
|
224
|
+
const m = model(c.req.param("model"));
|
|
225
|
+
const { id: _ignored, ...data } = await body(c);
|
|
226
|
+
const draft = await call(c, `${m.name}.draft`, data);
|
|
227
|
+
if (c.req.query("submit") === "true")
|
|
228
|
+
return c.json({ draft, submit: await call(c, "cms.submit", {}) }, 201);
|
|
229
|
+
return c.json(draft, 201);
|
|
230
|
+
});
|
|
231
|
+
app.patch("/api/v1/:model/:id", async (c) => {
|
|
232
|
+
const m = model(c.req.param("model"));
|
|
233
|
+
const draft = await call(c, `${m.name}.draft`, { ...(await body(c)), id: c.req.param("id") });
|
|
234
|
+
if (c.req.query("submit") === "true")
|
|
235
|
+
return c.json({ draft, submit: await call(c, "cms.submit", {}) });
|
|
236
|
+
return c.json(draft);
|
|
237
|
+
});
|
|
238
|
+
app.delete("/api/v1/:model/:id", async (c) => {
|
|
239
|
+
const m = model(c.req.param("model"));
|
|
240
|
+
return c.json(await call(c, `${m.name}.delete`, { id: c.req.param("id") }));
|
|
241
|
+
});
|
|
242
|
+
if (opts.studio !== false) {
|
|
243
|
+
const dir = typeof opts.studio === "string" ? opts.studio : opts.studio ? null : findStudio();
|
|
244
|
+
mountStudio(app, k, typeof opts.studio === "object" ? opts.studio : dir ? dirSource(dir) : null);
|
|
245
|
+
}
|
|
246
|
+
// ---- module routes (sitemap.xml, /media/…), matched at request time so installs take effect at once ----
|
|
247
|
+
app.all("*", async (c, next) => {
|
|
248
|
+
const url = new URL(c.req.url);
|
|
249
|
+
const hit = k.matchRoute(c.req.method, url.pathname);
|
|
250
|
+
if (!hit)
|
|
251
|
+
return next();
|
|
252
|
+
const mod = k.modules.find((m) => m.name === hit.route.module);
|
|
253
|
+
const actor = c.get("actor");
|
|
254
|
+
const started = Date.now();
|
|
255
|
+
const res = await hit.route.handler({ request: c.req.raw, url, params: hit.params, ctx: moduleContext(k, mod, actor, c.get("gate")) });
|
|
256
|
+
if (c.req.method !== "GET" && c.req.method !== "HEAD") {
|
|
257
|
+
await k.store.logEvent({ at: new Date().toISOString(), actor: actor.id, gate: c.get("gate"), action: `${hit.route.method} ${hit.route.path}`, ok: res.ok, ms: Date.now() - started }).catch(() => { });
|
|
258
|
+
}
|
|
259
|
+
return res;
|
|
260
|
+
});
|
|
261
|
+
app.notFound((c) => c.json({ error: { code: "not_found", message: `No route ${c.req.method} ${new URL(c.req.url).pathname}` } }, 404));
|
|
262
|
+
return app;
|
|
263
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Hono } from "hono";
|
|
2
|
+
import type { Kernel } from "../kernel/cms.ts";
|
|
3
|
+
export declare const SESSION_COOKIE = "aicms_session";
|
|
4
|
+
/** Where Studio's files come from: a folder on a server, or Workers Assets on the edge. */
|
|
5
|
+
export interface StudioSource {
|
|
6
|
+
/** A file by its path under /studio/ (e.g. "assets/index.js"), or null if there is none. */
|
|
7
|
+
read(rel: string): Promise<{
|
|
8
|
+
body: Uint8Array | ReadableStream;
|
|
9
|
+
type?: string;
|
|
10
|
+
} | null>;
|
|
11
|
+
}
|
|
12
|
+
/** The built Studio: dist/studio next to the compiled kernel, or the repo's dist/ when running from source. */
|
|
13
|
+
export declare function findStudio(): string | null;
|
|
14
|
+
/** Studio files from a folder. */
|
|
15
|
+
export declare function dirSource(dir: string): StudioSource;
|
|
16
|
+
/** Studio files from a Cloudflare Workers Assets binding whose directory is dist/studio. */
|
|
17
|
+
export declare function assetsSource(assets: {
|
|
18
|
+
fetch(request: Request): Promise<Response>;
|
|
19
|
+
}): StudioSource;
|
|
20
|
+
/** Studio: sign-in, sign-out and the single-page app under /studio. */
|
|
21
|
+
export declare function mountStudio(app: Hono<any>, k: Kernel, source: StudioSource | null): void;
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { extname, join, normalize, sep } from "node:path";
|
|
2
|
+
import { builtin } from "../node.js";
|
|
3
|
+
import { deleteCookie, getCookie, setCookie } from "hono/cookie";
|
|
4
|
+
export const SESSION_COOKIE = "aicms_session";
|
|
5
|
+
const TYPES = {
|
|
6
|
+
".html": "text/html; charset=utf-8",
|
|
7
|
+
".js": "text/javascript; charset=utf-8",
|
|
8
|
+
".css": "text/css; charset=utf-8",
|
|
9
|
+
".svg": "image/svg+xml",
|
|
10
|
+
".png": "image/png",
|
|
11
|
+
".ico": "image/x-icon",
|
|
12
|
+
".woff2": "font/woff2",
|
|
13
|
+
".woff": "font/woff",
|
|
14
|
+
".json": "application/json",
|
|
15
|
+
".txt": "text/plain; charset=utf-8",
|
|
16
|
+
};
|
|
17
|
+
/** The built Studio: dist/studio next to the compiled kernel, or the repo's dist/ when running from source. */
|
|
18
|
+
export function findStudio() {
|
|
19
|
+
const fs = builtin("node:fs");
|
|
20
|
+
const url = builtin("node:url");
|
|
21
|
+
if (!fs || !url)
|
|
22
|
+
return null;
|
|
23
|
+
for (const rel of ["../studio/", "../../dist/studio/"]) {
|
|
24
|
+
const dir = url.fileURLToPath(new URL(rel, import.meta.url));
|
|
25
|
+
if (fs.existsSync(join(dir, "index.html")))
|
|
26
|
+
return dir;
|
|
27
|
+
}
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
/** Studio files from a folder. */
|
|
31
|
+
export function dirSource(dir) {
|
|
32
|
+
return {
|
|
33
|
+
async read(rel) {
|
|
34
|
+
const file = normalize(join(dir, rel));
|
|
35
|
+
if (!file.startsWith(dir.endsWith(sep) ? dir : dir + sep))
|
|
36
|
+
return null;
|
|
37
|
+
try {
|
|
38
|
+
const body = await (await import("node:fs/promises")).readFile(file);
|
|
39
|
+
return { body: new Uint8Array(body), type: TYPES[extname(file)] };
|
|
40
|
+
}
|
|
41
|
+
catch {
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
/** Studio files from a Cloudflare Workers Assets binding whose directory is dist/studio. */
|
|
48
|
+
export function assetsSource(assets) {
|
|
49
|
+
return {
|
|
50
|
+
async read(rel) {
|
|
51
|
+
const res = await assets.fetch(new Request(`https://assets.local/${rel}`));
|
|
52
|
+
if (!res.ok || !res.body)
|
|
53
|
+
return null;
|
|
54
|
+
return { body: res.body, type: res.headers.get("content-type") ?? TYPES[extname(rel)] };
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
const isHttps = (c) => c.req.header("x-forwarded-proto") === "https" || new URL(c.req.url).protocol === "https:";
|
|
59
|
+
function notice(title, body) {
|
|
60
|
+
return `<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>${title} · AICMS Studio</title>
|
|
61
|
+
<style>:root{color-scheme:light dark}body{margin:0;min-height:100vh;display:grid;place-items:center;font:16px/1.6 system-ui,sans-serif;background:#ECEFF3;color:#131A2A}
|
|
62
|
+
@media (prefers-color-scheme:dark){body{background:#0D1119;color:#E7EBF3}main{background:#151B27!important}}
|
|
63
|
+
main{max-width:440px;margin:16px;padding:32px;border-radius:20px;background:#fff}h1{font-size:20px;margin:0 0 8px}code{font:14px ui-monospace,Menlo,monospace}</style></head>
|
|
64
|
+
<body><main><h1>${title}</h1><p>${body}</p></main></body></html>`;
|
|
65
|
+
}
|
|
66
|
+
/** Studio: sign-in, sign-out and the single-page app under /studio. */
|
|
67
|
+
export function mountStudio(app, k, source) {
|
|
68
|
+
app.get("/studio", (c) => c.redirect("/studio/"));
|
|
69
|
+
app.get("/studio/login", async (c) => {
|
|
70
|
+
try {
|
|
71
|
+
const s = await k.startSession(c.req.query("code") ?? "");
|
|
72
|
+
setCookie(c, SESSION_COOKIE, s.token, { httpOnly: true, sameSite: "Lax", secure: isHttps(c), path: "/", expires: new Date(s.expiresAt) });
|
|
73
|
+
return c.redirect("/studio/");
|
|
74
|
+
}
|
|
75
|
+
catch (e) {
|
|
76
|
+
const message = e instanceof Error ? e.message : String(e);
|
|
77
|
+
return c.html(notice("Can't sign in", `${message.replace(/`([^`]+)`/g, "<code>$1</code>")}`), 401);
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
app.post("/studio/logout", async (c) => {
|
|
81
|
+
const token = getCookie(c, SESSION_COOKIE);
|
|
82
|
+
if (token)
|
|
83
|
+
await k.endSession(token);
|
|
84
|
+
deleteCookie(c, SESSION_COOKIE, { path: "/" });
|
|
85
|
+
return c.json({ ok: true });
|
|
86
|
+
});
|
|
87
|
+
app.get("/studio/*", async (c) => {
|
|
88
|
+
if (!source) {
|
|
89
|
+
return c.html(notice("Studio isn't built", "Run <code>npm run build</code> in the aicms repository, then restart the server."), 503);
|
|
90
|
+
}
|
|
91
|
+
const rel = decodeURIComponent(new URL(c.req.url).pathname.replace(/^\/studio\/?/, ""));
|
|
92
|
+
if (rel && extname(rel) && !rel.split("/").includes("..")) {
|
|
93
|
+
const file = await source.read(rel);
|
|
94
|
+
if (!file)
|
|
95
|
+
return c.text("Not found", 404);
|
|
96
|
+
return c.body(file.body, 200, {
|
|
97
|
+
"content-type": file.type ?? TYPES[extname(rel)] ?? "application/octet-stream",
|
|
98
|
+
"cache-control": rel.startsWith("assets/") ? "public, max-age=31536000, immutable" : "no-cache",
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
// Client-side routes all get the app shell.
|
|
102
|
+
const shell = await source.read("index.html");
|
|
103
|
+
if (!shell)
|
|
104
|
+
return c.text("Studio's index.html is missing", 500);
|
|
105
|
+
return c.body(shell.body, 200, { "content-type": TYPES[".html"], "cache-control": "no-cache" });
|
|
106
|
+
});
|
|
107
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export { defineConfig, type Config, type AgentConfig, type WebhookConfig } from "./config.ts";
|
|
2
|
+
export { defineModel, type Model, type InferModel, type ModelAgentOptions, type ModelOp } from "./schema/model.ts";
|
|
3
|
+
export { field, type Field, type InferFields, type MediaValue } from "./schema/fields.ts";
|
|
4
|
+
export { slugify } from "./schema/slug.ts";
|
|
5
|
+
export { markdownToBlocks, blocksToMarkdown, type Block } from "./schema/markdown.ts";
|
|
6
|
+
export { action, type ActionDef, type Gate } from "./kernel/action.ts";
|
|
7
|
+
export { defineModule, moduleManifest, type ModuleDef, type ModuleContext, type ModuleManifest, type ModuleStorage, type EventHandler, type RouteHandler, type CheckFn, type CheckFinding, type CheckInput } from "./kernel/modules.ts";
|
|
8
|
+
export { type Brief, type BriefStatus, type BriefNote } from "./kernel/briefs.ts";
|
|
9
|
+
export { createCMS, type Kernel, type ToolInfo, type CreateOptions, type FeedEvent, type Feed } from "./kernel/cms.ts";
|
|
10
|
+
export { AicmsError, type ErrorCode } from "./kernel/errors.ts";
|
|
11
|
+
export { allows, type Actor, type ReviewMode, type Budget } from "./kernel/policy.ts";
|
|
12
|
+
export { sqlite, SqliteStore } from "./store/sqlite.ts";
|
|
13
|
+
export { postgres, PostgresStore, pgDriver, pgliteDriver, type PostgresOptions, type SqlDriver } from "./store/postgres.ts";
|
|
14
|
+
export type { Store, EntryRow, ChangesetRow, ChangesetItem, CheckIssue } from "./store/types.ts";
|
|
15
|
+
export { createApp, type AppOptions } from "./gates/rest.ts";
|
|
16
|
+
export { generateTypes } from "./typegen.ts";
|
|
17
|
+
export { createMcpServer, handleMcpRequest, serveStdio } from "./gates/mcp.ts";
|
|
18
|
+
export { VERSION } from "./gates/discovery.ts";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// Public API. A site needs only defineConfig, defineModel and field;
|
|
2
|
+
// modules add defineModule and action.
|
|
3
|
+
export { defineConfig } from "./config.js";
|
|
4
|
+
export { defineModel } from "./schema/model.js";
|
|
5
|
+
export { field } from "./schema/fields.js";
|
|
6
|
+
export { slugify } from "./schema/slug.js";
|
|
7
|
+
export { markdownToBlocks, blocksToMarkdown } from "./schema/markdown.js";
|
|
8
|
+
export { action } from "./kernel/action.js";
|
|
9
|
+
export { defineModule, moduleManifest } from "./kernel/modules.js";
|
|
10
|
+
export {} from "./kernel/briefs.js";
|
|
11
|
+
export { createCMS } from "./kernel/cms.js";
|
|
12
|
+
export { AicmsError } from "./kernel/errors.js";
|
|
13
|
+
export { allows } from "./kernel/policy.js";
|
|
14
|
+
export { sqlite, SqliteStore } from "./store/sqlite.js";
|
|
15
|
+
export { postgres, PostgresStore, pgDriver, pgliteDriver } from "./store/postgres.js";
|
|
16
|
+
export { createApp } from "./gates/rest.js";
|
|
17
|
+
export { generateTypes } from "./typegen.js";
|
|
18
|
+
export { createMcpServer, handleMcpRequest, serveStdio } from "./gates/mcp.js";
|
|
19
|
+
export { VERSION } from "./gates/discovery.js";
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type { AnyField } from "../schema/fields.ts";
|
|
3
|
+
import type { Actor } from "./policy.ts";
|
|
4
|
+
import type { Kernel } from "./cms.ts";
|
|
5
|
+
import type { ModuleContext } from "./modules.ts";
|
|
6
|
+
export type Gate = "mcp" | "rest" | "graphql" | "a2a" | "cli" | "sdk" | "studio" | "internal";
|
|
7
|
+
export interface CallContext {
|
|
8
|
+
actor: Actor;
|
|
9
|
+
gate: Gate;
|
|
10
|
+
kernel: Kernel;
|
|
11
|
+
}
|
|
12
|
+
/** An Action as declared by a module. */
|
|
13
|
+
export interface ActionDef<I = any, O = any> {
|
|
14
|
+
readonly kind?: "action";
|
|
15
|
+
description: string;
|
|
16
|
+
/** Fields (like a model) or a Zod object. */
|
|
17
|
+
input?: Record<string, AnyField> | z.ZodObject;
|
|
18
|
+
/** Scope required to see and call the Action. Omit to allow any signed-in caller. */
|
|
19
|
+
scope?: string;
|
|
20
|
+
/** Also allow anonymous callers. */
|
|
21
|
+
public?: boolean;
|
|
22
|
+
readOnly?: boolean;
|
|
23
|
+
destructive?: boolean;
|
|
24
|
+
run(args: {
|
|
25
|
+
input: I;
|
|
26
|
+
ctx: ModuleContext;
|
|
27
|
+
}): O | Promise<O>;
|
|
28
|
+
}
|
|
29
|
+
export declare function action<I = any, O = any>(def: Omit<ActionDef<I, O>, "kind">): ActionDef<I, O>;
|
|
30
|
+
/** An Action in the kernel registry. Everything a gate exposes is one of these. */
|
|
31
|
+
export interface RegisteredAction {
|
|
32
|
+
name: string;
|
|
33
|
+
description: string;
|
|
34
|
+
module?: string;
|
|
35
|
+
readOnly?: boolean;
|
|
36
|
+
destructive?: boolean;
|
|
37
|
+
/** Is the Action listed for this actor at all? */
|
|
38
|
+
visible(actor: Actor): boolean;
|
|
39
|
+
/** Schema used to validate input. */
|
|
40
|
+
schema(actor: Actor): z.ZodType;
|
|
41
|
+
/** Schema advertised to this actor as a tool (may be narrower, e.g. only writable fields). */
|
|
42
|
+
advertised?(actor: Actor): z.ZodType;
|
|
43
|
+
run(input: any, ctx: CallContext): Promise<unknown>;
|
|
44
|
+
}
|
|
45
|
+
/** Turn a field map into a Zod object, honouring `required` and input schemas. */
|
|
46
|
+
export declare function fieldsToSchema(fields: Record<string, AnyField>): z.ZodObject;
|
|
47
|
+
export declare function normalizeFields(fields: Record<string, AnyField>, input: Record<string, unknown>): Record<string, unknown>;
|
|
48
|
+
/** MCP tool names may not contain dots in several LLM APIs. */
|
|
49
|
+
export declare const toolName: (action: string) => string;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export function action(def) {
|
|
3
|
+
return { kind: "action", ...def };
|
|
4
|
+
}
|
|
5
|
+
/** Turn a field map into a Zod object, honouring `required` and input schemas. */
|
|
6
|
+
export function fieldsToSchema(fields) {
|
|
7
|
+
return z.strictObject(Object.fromEntries(Object.entries(fields).map(([k, f]) => {
|
|
8
|
+
let s = f.input ?? f.schema;
|
|
9
|
+
if (f.options.description)
|
|
10
|
+
s = s.describe(f.options.description);
|
|
11
|
+
return [k, f.options.required ? s : s.optional()];
|
|
12
|
+
})));
|
|
13
|
+
}
|
|
14
|
+
export function normalizeFields(fields, input) {
|
|
15
|
+
const out = { ...input };
|
|
16
|
+
for (const [k, f] of Object.entries(fields))
|
|
17
|
+
if (out[k] != null && f.normalize)
|
|
18
|
+
out[k] = f.normalize(out[k]);
|
|
19
|
+
return out;
|
|
20
|
+
}
|
|
21
|
+
/** MCP tool names may not contain dots in several LLM APIs. */
|
|
22
|
+
export const toolName = (action) => action.replace(/\./g, "_");
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import { type Actor } from "./policy.ts";
|
|
2
|
+
import type { Kernel } from "./cms.ts";
|
|
3
|
+
export type BriefStatus = "open" | "in_progress" | "blocked" | "in_review" | "done" | "canceled";
|
|
4
|
+
export declare const BRIEF_STATUSES: BriefStatus[];
|
|
5
|
+
/** What an agent working on a brief may set. The rest follows from its changesets or a person's decision. */
|
|
6
|
+
export declare const AGENT_BRIEF_STATUSES: readonly ["in_progress", "blocked", "open", "done"];
|
|
7
|
+
export interface BriefNote {
|
|
8
|
+
at: string;
|
|
9
|
+
by: string;
|
|
10
|
+
text: string;
|
|
11
|
+
}
|
|
12
|
+
export interface Brief {
|
|
13
|
+
id: string;
|
|
14
|
+
title: string;
|
|
15
|
+
/** What to do, in Markdown: audience, sources, tone, must-haves. */
|
|
16
|
+
details?: string;
|
|
17
|
+
/** The agent it's for. Without one, any agent may pick it up. */
|
|
18
|
+
agent?: string;
|
|
19
|
+
/** What to produce, e.g. "post". */
|
|
20
|
+
model?: string;
|
|
21
|
+
/** An existing entry to work on. */
|
|
22
|
+
entry?: string;
|
|
23
|
+
/** When the work should be ready (ISO date or time). */
|
|
24
|
+
due?: string;
|
|
25
|
+
/** When the result should go live; passed on to cms_submit. */
|
|
26
|
+
publishAt?: string;
|
|
27
|
+
status: BriefStatus;
|
|
28
|
+
/** The agent that took it, for briefs without `agent`. */
|
|
29
|
+
claimedBy?: string;
|
|
30
|
+
changesets: string[];
|
|
31
|
+
notes: BriefNote[];
|
|
32
|
+
createdBy: string;
|
|
33
|
+
createdAt: string;
|
|
34
|
+
updatedAt: string;
|
|
35
|
+
}
|
|
36
|
+
/** May write and manage briefs: people (the owner) and planning agents with `briefs:write`. */
|
|
37
|
+
export declare const briefWriter: (a: Actor) => boolean;
|
|
38
|
+
/** Is this brief for this agent: assigned to it, taken by it, or open to anyone? */
|
|
39
|
+
export declare function briefIsFor(b: Brief, actor: Actor): boolean;
|
|
40
|
+
/** The list view: everything but the notes. */
|
|
41
|
+
export declare function briefSummary(b: Brief): {
|
|
42
|
+
lastNote?: BriefNote | undefined;
|
|
43
|
+
notes: number;
|
|
44
|
+
id: string;
|
|
45
|
+
title: string;
|
|
46
|
+
/** What to do, in Markdown: audience, sources, tone, must-haves. */
|
|
47
|
+
details?: string;
|
|
48
|
+
/** The agent it's for. Without one, any agent may pick it up. */
|
|
49
|
+
agent?: string;
|
|
50
|
+
/** What to produce, e.g. "post". */
|
|
51
|
+
model?: string;
|
|
52
|
+
/** An existing entry to work on. */
|
|
53
|
+
entry?: string;
|
|
54
|
+
/** When the work should be ready (ISO date or time). */
|
|
55
|
+
due?: string;
|
|
56
|
+
/** When the result should go live; passed on to cms_submit. */
|
|
57
|
+
publishAt?: string;
|
|
58
|
+
status: BriefStatus;
|
|
59
|
+
/** The agent that took it, for briefs without `agent`. */
|
|
60
|
+
claimedBy?: string;
|
|
61
|
+
changesets: string[];
|
|
62
|
+
createdBy: string;
|
|
63
|
+
createdAt: string;
|
|
64
|
+
updatedAt: string;
|
|
65
|
+
};
|
|
66
|
+
export declare function getBrief(k: Kernel, actor: Actor, id: string): Promise<Brief>;
|
|
67
|
+
export declare function listBriefs(k: Kernel, actor: Actor, q?: {
|
|
68
|
+
status?: BriefStatus[];
|
|
69
|
+
agent?: string;
|
|
70
|
+
limit?: number;
|
|
71
|
+
}): Promise<{
|
|
72
|
+
briefs: {
|
|
73
|
+
lastNote?: BriefNote | undefined;
|
|
74
|
+
notes: number;
|
|
75
|
+
id: string;
|
|
76
|
+
title: string;
|
|
77
|
+
/** What to do, in Markdown: audience, sources, tone, must-haves. */
|
|
78
|
+
details?: string;
|
|
79
|
+
/** The agent it's for. Without one, any agent may pick it up. */
|
|
80
|
+
agent?: string;
|
|
81
|
+
/** What to produce, e.g. "post". */
|
|
82
|
+
model?: string;
|
|
83
|
+
/** An existing entry to work on. */
|
|
84
|
+
entry?: string;
|
|
85
|
+
/** When the work should be ready (ISO date or time). */
|
|
86
|
+
due?: string;
|
|
87
|
+
/** When the result should go live; passed on to cms_submit. */
|
|
88
|
+
publishAt?: string;
|
|
89
|
+
status: BriefStatus;
|
|
90
|
+
/** The agent that took it, for briefs without `agent`. */
|
|
91
|
+
claimedBy?: string;
|
|
92
|
+
changesets: string[];
|
|
93
|
+
createdBy: string;
|
|
94
|
+
createdAt: string;
|
|
95
|
+
updatedAt: string;
|
|
96
|
+
}[];
|
|
97
|
+
total: number;
|
|
98
|
+
}>;
|
|
99
|
+
export interface BriefInput {
|
|
100
|
+
title?: string;
|
|
101
|
+
details?: string | null;
|
|
102
|
+
agent?: string | null;
|
|
103
|
+
model?: string | null;
|
|
104
|
+
entry?: string | null;
|
|
105
|
+
due?: string | null;
|
|
106
|
+
publishAt?: string | null;
|
|
107
|
+
status?: "open" | "canceled" | "done";
|
|
108
|
+
note?: string;
|
|
109
|
+
}
|
|
110
|
+
/** Create a brief (no id) or change one: people and planning agents. */
|
|
111
|
+
export declare function writeBrief(k: Kernel, actor: Actor, id: string | undefined, input: BriefInput): Promise<{
|
|
112
|
+
brief: Brief;
|
|
113
|
+
next: string;
|
|
114
|
+
} | {
|
|
115
|
+
brief: Brief;
|
|
116
|
+
next?: undefined;
|
|
117
|
+
}>;
|
|
118
|
+
/** An agent reports on a brief: takes it, asks a question (blocked), gives it back, or finishes it without content changes. */
|
|
119
|
+
export declare function updateBrief(k: Kernel, actor: Actor, id: string, input: {
|
|
120
|
+
status?: (typeof AGENT_BRIEF_STATUSES)[number];
|
|
121
|
+
note?: string;
|
|
122
|
+
}): Promise<{
|
|
123
|
+
brief: Brief;
|
|
124
|
+
next: string;
|
|
125
|
+
} | {
|
|
126
|
+
brief: Brief;
|
|
127
|
+
next?: undefined;
|
|
128
|
+
} | {
|
|
129
|
+
brief: {
|
|
130
|
+
lastNote?: BriefNote | undefined;
|
|
131
|
+
notes: number;
|
|
132
|
+
id: string;
|
|
133
|
+
title: string;
|
|
134
|
+
/** What to do, in Markdown: audience, sources, tone, must-haves. */
|
|
135
|
+
details?: string;
|
|
136
|
+
/** The agent it's for. Without one, any agent may pick it up. */
|
|
137
|
+
agent?: string;
|
|
138
|
+
/** What to produce, e.g. "post". */
|
|
139
|
+
model?: string;
|
|
140
|
+
/** An existing entry to work on. */
|
|
141
|
+
entry?: string;
|
|
142
|
+
/** When the work should be ready (ISO date or time). */
|
|
143
|
+
due?: string;
|
|
144
|
+
/** When the result should go live; passed on to cms_submit. */
|
|
145
|
+
publishAt?: string;
|
|
146
|
+
status: BriefStatus;
|
|
147
|
+
/** The agent that took it, for briefs without `agent`. */
|
|
148
|
+
claimedBy?: string;
|
|
149
|
+
changesets: string[];
|
|
150
|
+
createdBy: string;
|
|
151
|
+
createdAt: string;
|
|
152
|
+
updatedAt: string;
|
|
153
|
+
};
|
|
154
|
+
next: string | undefined;
|
|
155
|
+
}>;
|
|
156
|
+
/** Before cms_submit links a changeset: is the brief this agent's to answer? Returns its publishAt, if any. */
|
|
157
|
+
export declare function briefForSubmit(k: Kernel, actor: Actor, id: string): Promise<Brief>;
|
|
158
|
+
/** After cms_submit: link the changeset and move the brief along. */
|
|
159
|
+
export declare function linkSubmission(k: Kernel, actor: Actor, id: string, changeset: string, status: string): Promise<void>;
|
|
160
|
+
/** Merges close briefs; rejections bring the reviewer's comment back to the agent. */
|
|
161
|
+
export declare function watchBriefs(k: Kernel): void;
|