@ampless/mcp-server 1.0.0-alpha.16 → 1.0.0-alpha.18
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/README.ja.md +45 -123
- package/README.md +45 -123
- package/dist/index.d.ts +127 -1
- package/dist/index.js +1283 -32299
- package/package.json +17 -29
- package/LICENSE +0 -21
- package/dist/bowser-WRHMEFK3.js +0 -2822
- package/dist/chunk-6HZB2ZCT.js +0 -4715
- package/dist/chunk-7JQMGUAU.js +0 -134
- package/dist/chunk-ERHOBKHD.js +0 -891
- package/dist/chunk-ETWWJEHN.js +0 -574
- package/dist/chunk-FLMNALC3.js +0 -47
- package/dist/chunk-FM7TW5TD.js +0 -3558
- package/dist/chunk-HVSLKTKC.js +0 -968
- package/dist/chunk-IKXKDSVH.js +0 -1414
- package/dist/chunk-LD7M476A.js +0 -502
- package/dist/chunk-LMMQX4CK.js +0 -49
- package/dist/chunk-OBZN5IWW.js +0 -1375
- package/dist/chunk-Q4OVSLY4.js +0 -14
- package/dist/chunk-SPCUAJQT.js +0 -435
- package/dist/chunk-USNYVOYF.js +0 -1422
- package/dist/chunk-YR5GD2D7.js +0 -165
- package/dist/dist-es-2B6UPU6D.js +0 -485
- package/dist/dist-es-4QBVIVDD.js +0 -23
- package/dist/dist-es-DAQMEDLM.js +0 -165
- package/dist/dist-es-DWVRWSTC.js +0 -70
- package/dist/dist-es-H7Y5BZEG.js +0 -315
- package/dist/dist-es-QZOTLLWC.js +0 -377
- package/dist/dist-es-S3US4EVE.js +0 -88
- package/dist/event-streams-IEZDQ3X3.js +0 -44
- package/dist/event-streams-R54SMYED.js +0 -891
- package/dist/loadSso-B4NUZPX5.js +0 -552
- package/dist/signin-BEDHRSJ2.js +0 -647
- package/dist/sso-oidc-UXLRODTA.js +0 -787
- package/dist/sts-3BBU2O3O.js +0 -1366
- package/dist/tools/index.d.ts +0 -127
- package/dist/tools/index.js +0 -16
package/dist/chunk-HVSLKTKC.js
DELETED
|
@@ -1,968 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
// src/tools/post-mapping.ts
|
|
4
|
-
import {
|
|
5
|
-
decodeAwsJson
|
|
6
|
-
} from "ampless";
|
|
7
|
-
var POST_FIELDS = (
|
|
8
|
-
/* GraphQL */
|
|
9
|
-
`
|
|
10
|
-
fragment PostFields on Post {
|
|
11
|
-
postId
|
|
12
|
-
slug
|
|
13
|
-
title
|
|
14
|
-
excerpt
|
|
15
|
-
format
|
|
16
|
-
body
|
|
17
|
-
status
|
|
18
|
-
publishedAt
|
|
19
|
-
tags
|
|
20
|
-
metadata
|
|
21
|
-
}
|
|
22
|
-
`
|
|
23
|
-
);
|
|
24
|
-
function toCorePost(p) {
|
|
25
|
-
const metadata = decodeAwsJson(p.metadata);
|
|
26
|
-
return {
|
|
27
|
-
postId: p.postId,
|
|
28
|
-
slug: p.slug,
|
|
29
|
-
title: p.title,
|
|
30
|
-
excerpt: p.excerpt ?? void 0,
|
|
31
|
-
format: p.format ?? "markdown",
|
|
32
|
-
body: decodeAwsJson(p.body),
|
|
33
|
-
status: p.status ?? "draft",
|
|
34
|
-
publishedAt: p.publishedAt ?? void 0,
|
|
35
|
-
tags: (p.tags ?? []).filter((t) => typeof t === "string"),
|
|
36
|
-
metadata: metadata && typeof metadata === "object" && !Array.isArray(metadata) ? metadata : void 0
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
// src/tools/list-posts.ts
|
|
41
|
-
var QUERY = (
|
|
42
|
-
/* GraphQL */
|
|
43
|
-
`
|
|
44
|
-
${POST_FIELDS}
|
|
45
|
-
query ListPosts($filter: ModelPostFilterInput, $limit: Int, $nextToken: String) {
|
|
46
|
-
listPosts(filter: $filter, limit: $limit, nextToken: $nextToken) {
|
|
47
|
-
items {
|
|
48
|
-
...PostFields
|
|
49
|
-
}
|
|
50
|
-
nextToken
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
`
|
|
54
|
-
);
|
|
55
|
-
var listPostsSchema = {
|
|
56
|
-
type: "object",
|
|
57
|
-
properties: {
|
|
58
|
-
status: {
|
|
59
|
-
type: "string",
|
|
60
|
-
enum: ["draft", "published", "all"],
|
|
61
|
-
description: 'Filter by status (default "all")'
|
|
62
|
-
},
|
|
63
|
-
limit: { type: "integer", minimum: 1, maximum: 100, description: "Max results (default 20)" },
|
|
64
|
-
nextToken: { type: "string", description: "Pagination cursor from a previous call" }
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
|
-
async function listPosts(client, args = {}) {
|
|
68
|
-
const status = args.status ?? "all";
|
|
69
|
-
const filter = {};
|
|
70
|
-
if (status !== "all") filter.status = { eq: status };
|
|
71
|
-
const hasFilter = Object.keys(filter).length > 0;
|
|
72
|
-
const data = await client.query(QUERY, {
|
|
73
|
-
filter: hasFilter ? filter : void 0,
|
|
74
|
-
limit: args.limit ?? 20,
|
|
75
|
-
nextToken: args.nextToken
|
|
76
|
-
});
|
|
77
|
-
return {
|
|
78
|
-
posts: data.listPosts.items.map(toCorePost),
|
|
79
|
-
nextToken: data.listPosts.nextToken
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
// src/tools/get-post.ts
|
|
84
|
-
var GET_BY_ID = (
|
|
85
|
-
/* GraphQL */
|
|
86
|
-
`
|
|
87
|
-
${POST_FIELDS}
|
|
88
|
-
query GetPost($postId: ID!) {
|
|
89
|
-
getPost(postId: $postId) {
|
|
90
|
-
...PostFields
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
`
|
|
94
|
-
);
|
|
95
|
-
var LIST_BY_SLUG = (
|
|
96
|
-
/* GraphQL */
|
|
97
|
-
`
|
|
98
|
-
${POST_FIELDS}
|
|
99
|
-
query GetPostBySlug($filter: ModelPostFilterInput!) {
|
|
100
|
-
listPosts(filter: $filter, limit: 1) {
|
|
101
|
-
items {
|
|
102
|
-
...PostFields
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
`
|
|
107
|
-
);
|
|
108
|
-
var getPostSchema = {
|
|
109
|
-
type: "object",
|
|
110
|
-
properties: {
|
|
111
|
-
slug: { type: "string", description: "Post slug" },
|
|
112
|
-
postId: { type: "string", description: "Post id (used when slug is omitted)" }
|
|
113
|
-
}
|
|
114
|
-
};
|
|
115
|
-
async function getPost(client, args) {
|
|
116
|
-
if (!args.slug && !args.postId) {
|
|
117
|
-
throw new Error("get_post requires either `slug` or `postId`");
|
|
118
|
-
}
|
|
119
|
-
if (args.postId) {
|
|
120
|
-
const data2 = await client.query(GET_BY_ID, { postId: args.postId });
|
|
121
|
-
return data2.getPost ? toCorePost(data2.getPost) : null;
|
|
122
|
-
}
|
|
123
|
-
const data = await client.query(LIST_BY_SLUG, {
|
|
124
|
-
filter: { slug: { eq: args.slug } }
|
|
125
|
-
});
|
|
126
|
-
const item = data.listPosts.items[0];
|
|
127
|
-
return item ? toCorePost(item) : null;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
// src/tools/create-post.ts
|
|
131
|
-
import {
|
|
132
|
-
encodeAwsJson
|
|
133
|
-
} from "ampless";
|
|
134
|
-
|
|
135
|
-
// src/posttag.ts
|
|
136
|
-
function entries(post) {
|
|
137
|
-
if (post.status !== "published" || !post.publishedAt || !post.tags?.length) return [];
|
|
138
|
-
return post.tags.map((tag) => ({
|
|
139
|
-
tag,
|
|
140
|
-
publishedAtPostId: `${post.publishedAt}#${post.postId}`
|
|
141
|
-
}));
|
|
142
|
-
}
|
|
143
|
-
function entryKey(e) {
|
|
144
|
-
return `${e.tag}|${e.publishedAtPostId}`;
|
|
145
|
-
}
|
|
146
|
-
var CREATE_POST_TAG = (
|
|
147
|
-
/* GraphQL */
|
|
148
|
-
`
|
|
149
|
-
mutation CreatePostTag($input: CreatePostTagInput!) {
|
|
150
|
-
createPostTag(input: $input) {
|
|
151
|
-
tag
|
|
152
|
-
publishedAtPostId
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
`
|
|
156
|
-
);
|
|
157
|
-
var UPDATE_POST_TAG = (
|
|
158
|
-
/* GraphQL */
|
|
159
|
-
`
|
|
160
|
-
mutation UpdatePostTag($input: UpdatePostTagInput!) {
|
|
161
|
-
updatePostTag(input: $input) {
|
|
162
|
-
tag
|
|
163
|
-
publishedAtPostId
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
`
|
|
167
|
-
);
|
|
168
|
-
var DELETE_POST_TAG = (
|
|
169
|
-
/* GraphQL */
|
|
170
|
-
`
|
|
171
|
-
mutation DeletePostTag($input: DeletePostTagInput!) {
|
|
172
|
-
deletePostTag(input: $input) {
|
|
173
|
-
tag
|
|
174
|
-
publishedAtPostId
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
`
|
|
178
|
-
);
|
|
179
|
-
async function syncPostTags(client, post, oldPost) {
|
|
180
|
-
const oldEntries = oldPost ? entries(oldPost) : [];
|
|
181
|
-
const newEntries = entries(post);
|
|
182
|
-
const oldKeys = new Set(oldEntries.map(entryKey));
|
|
183
|
-
const newKeys = new Set(newEntries.map(entryKey));
|
|
184
|
-
await Promise.all(
|
|
185
|
-
oldEntries.filter((e) => !newKeys.has(entryKey(e))).map(
|
|
186
|
-
(e) => client.query(DELETE_POST_TAG, {
|
|
187
|
-
input: { tag: e.tag, publishedAtPostId: e.publishedAtPostId }
|
|
188
|
-
})
|
|
189
|
-
)
|
|
190
|
-
);
|
|
191
|
-
await Promise.all(
|
|
192
|
-
newEntries.filter((e) => !oldKeys.has(entryKey(e))).map(
|
|
193
|
-
(e) => client.query(CREATE_POST_TAG, {
|
|
194
|
-
input: {
|
|
195
|
-
tag: e.tag,
|
|
196
|
-
publishedAtPostId: e.publishedAtPostId,
|
|
197
|
-
postId: post.postId,
|
|
198
|
-
publishedAt: post.publishedAt,
|
|
199
|
-
slug: post.slug,
|
|
200
|
-
title: post.title,
|
|
201
|
-
excerpt: post.excerpt,
|
|
202
|
-
tags: post.tags ?? []
|
|
203
|
-
}
|
|
204
|
-
})
|
|
205
|
-
)
|
|
206
|
-
);
|
|
207
|
-
await Promise.all(
|
|
208
|
-
newEntries.filter((e) => oldKeys.has(entryKey(e))).map(
|
|
209
|
-
(e) => client.query(UPDATE_POST_TAG, {
|
|
210
|
-
input: {
|
|
211
|
-
tag: e.tag,
|
|
212
|
-
publishedAtPostId: e.publishedAtPostId,
|
|
213
|
-
slug: post.slug,
|
|
214
|
-
title: post.title,
|
|
215
|
-
excerpt: post.excerpt,
|
|
216
|
-
tags: post.tags ?? []
|
|
217
|
-
}
|
|
218
|
-
})
|
|
219
|
-
)
|
|
220
|
-
);
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
// src/tools/create-post.ts
|
|
224
|
-
var MUTATION = (
|
|
225
|
-
/* GraphQL */
|
|
226
|
-
`
|
|
227
|
-
${POST_FIELDS}
|
|
228
|
-
mutation CreatePost($input: CreatePostInput!) {
|
|
229
|
-
createPost(input: $input) {
|
|
230
|
-
...PostFields
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
`
|
|
234
|
-
);
|
|
235
|
-
var createPostSchema = {
|
|
236
|
-
type: "object",
|
|
237
|
-
required: ["slug", "title", "format", "body"],
|
|
238
|
-
properties: {
|
|
239
|
-
postId: { type: "string", description: "Optional explicit id; auto-generated if omitted" },
|
|
240
|
-
slug: { type: "string" },
|
|
241
|
-
title: { type: "string" },
|
|
242
|
-
format: {
|
|
243
|
-
type: "string",
|
|
244
|
-
enum: ["tiptap", "markdown", "html"],
|
|
245
|
-
description: "tiptap = rich text JSON tree; markdown = source string (GFM extensions enabled); html = raw HTML string (rendered verbatim, no sanitization)."
|
|
246
|
-
},
|
|
247
|
-
body: {
|
|
248
|
-
description: "tiptap JSON (when format=tiptap), markdown source string (format=markdown), or raw HTML string (format=html)."
|
|
249
|
-
},
|
|
250
|
-
status: { type: "string", enum: ["draft", "published"], default: "draft" },
|
|
251
|
-
excerpt: { type: "string" },
|
|
252
|
-
publishedAt: { type: "string", description: "ISO 8601 timestamp; required when status=published" },
|
|
253
|
-
tags: { type: "array", items: { type: "string" } },
|
|
254
|
-
metadata: {
|
|
255
|
-
type: "object",
|
|
256
|
-
description: "Free-form per-post metadata. Reserved well-known keys: `no_layout` (boolean) \u2014 when true, the public page is served as bare HTML with no theme chrome (middleware rewrites /<slug> to the internal bare-HTML route); meaningful only with format=html. `cache` (auto|deep|hot) \u2014 override the per-post cache strategy. See `cacheStrategy` in get_schema.notes for details. Other keys pass through unchanged for themes/plugins.",
|
|
257
|
-
properties: {
|
|
258
|
-
no_layout: {
|
|
259
|
-
type: "boolean",
|
|
260
|
-
description: "Serve the post as bare HTML with no theme chrome. Only meaningful when format=html; ignored otherwise."
|
|
261
|
-
},
|
|
262
|
-
cache: {
|
|
263
|
-
type: "string",
|
|
264
|
-
enum: ["auto", "deep", "hot"],
|
|
265
|
-
default: "auto",
|
|
266
|
-
description: "Override the response Cache-Control strategy. 'auto' (default): no-store within `cms.config.cache.cooldownMs` of updatedAt, then `max-age=freshTtlSeconds`. 'deep': always `max-age=deepTtlSeconds`. 'hot': always no-store. Independent of no_layout; applies uniformly to themed, no_layout, and static posts."
|
|
267
|
-
}
|
|
268
|
-
},
|
|
269
|
-
additionalProperties: true
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
};
|
|
273
|
-
async function createPost(client, args) {
|
|
274
|
-
const postId = args.postId ?? `post-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
|
|
275
|
-
const status = args.status ?? "draft";
|
|
276
|
-
const publishedAt = args.publishedAt ?? (status === "published" ? (/* @__PURE__ */ new Date()).toISOString() : void 0);
|
|
277
|
-
const data = await client.query(MUTATION, {
|
|
278
|
-
input: {
|
|
279
|
-
postId,
|
|
280
|
-
slug: args.slug,
|
|
281
|
-
title: args.title,
|
|
282
|
-
excerpt: args.excerpt,
|
|
283
|
-
format: args.format,
|
|
284
|
-
body: encodeAwsJson(args.body),
|
|
285
|
-
status,
|
|
286
|
-
publishedAt,
|
|
287
|
-
tags: args.tags,
|
|
288
|
-
metadata: args.metadata !== void 0 ? encodeAwsJson(args.metadata) : void 0
|
|
289
|
-
}
|
|
290
|
-
});
|
|
291
|
-
const created = toCorePost(data.createPost);
|
|
292
|
-
await syncPostTags(client, created, null);
|
|
293
|
-
return created;
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
// src/tools/update-post.ts
|
|
297
|
-
import {
|
|
298
|
-
encodeAwsJson as encodeAwsJson2
|
|
299
|
-
} from "ampless";
|
|
300
|
-
var MUTATION2 = (
|
|
301
|
-
/* GraphQL */
|
|
302
|
-
`
|
|
303
|
-
${POST_FIELDS}
|
|
304
|
-
mutation UpdatePost($input: UpdatePostInput!) {
|
|
305
|
-
updatePost(input: $input) {
|
|
306
|
-
...PostFields
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
`
|
|
310
|
-
);
|
|
311
|
-
var updatePostSchema = {
|
|
312
|
-
type: "object",
|
|
313
|
-
required: ["postId"],
|
|
314
|
-
properties: {
|
|
315
|
-
postId: { type: "string" },
|
|
316
|
-
slug: { type: "string" },
|
|
317
|
-
title: { type: "string" },
|
|
318
|
-
excerpt: { type: "string" },
|
|
319
|
-
format: {
|
|
320
|
-
type: "string",
|
|
321
|
-
enum: ["tiptap", "markdown", "html"],
|
|
322
|
-
description: "tiptap = rich text JSON tree; markdown = source string; html = raw HTML string (no sanitization)."
|
|
323
|
-
},
|
|
324
|
-
body: { description: "tiptap JSON, markdown source, or raw HTML string" },
|
|
325
|
-
status: { type: "string", enum: ["draft", "published"] },
|
|
326
|
-
publishedAt: { type: "string", description: "ISO 8601 timestamp" },
|
|
327
|
-
tags: { type: "array", items: { type: "string" } },
|
|
328
|
-
metadata: {
|
|
329
|
-
type: "object",
|
|
330
|
-
description: "Free-form per-post metadata. Reserved well-known keys: `no_layout` (boolean) \u2014 when true, the public page is served as bare HTML with no theme chrome (middleware rewrites /<slug> to the internal bare-HTML route); meaningful only with format=html. `cache` (auto|deep|hot) \u2014 override the per-post cache strategy. See `cacheStrategy` in get_schema.notes for details. Passing metadata replaces the existing metadata object \u2014 read the current post first if you only want to add a key.",
|
|
331
|
-
properties: {
|
|
332
|
-
no_layout: {
|
|
333
|
-
type: "boolean",
|
|
334
|
-
description: "Serve the post as bare HTML with no theme chrome. Only meaningful when format=html; ignored otherwise."
|
|
335
|
-
},
|
|
336
|
-
cache: {
|
|
337
|
-
type: "string",
|
|
338
|
-
enum: ["auto", "deep", "hot"],
|
|
339
|
-
default: "auto",
|
|
340
|
-
description: "Override the response Cache-Control strategy. 'auto' (default): no-store within `cms.config.cache.cooldownMs` of updatedAt, then `max-age=freshTtlSeconds`. 'deep': always `max-age=deepTtlSeconds`. 'hot': always no-store. Independent of no_layout; applies uniformly to themed, no_layout, and static posts."
|
|
341
|
-
}
|
|
342
|
-
},
|
|
343
|
-
additionalProperties: true
|
|
344
|
-
}
|
|
345
|
-
}
|
|
346
|
-
};
|
|
347
|
-
async function updatePost(client, args) {
|
|
348
|
-
const oldPost = await getPost(client, { postId: args.postId });
|
|
349
|
-
const input = { postId: args.postId };
|
|
350
|
-
if (args.slug !== void 0) input.slug = args.slug;
|
|
351
|
-
if (args.title !== void 0) input.title = args.title;
|
|
352
|
-
if (args.excerpt !== void 0) input.excerpt = args.excerpt;
|
|
353
|
-
if (args.format !== void 0) input.format = args.format;
|
|
354
|
-
if (args.body !== void 0) input.body = encodeAwsJson2(args.body);
|
|
355
|
-
if (args.status !== void 0) input.status = args.status;
|
|
356
|
-
if (args.publishedAt !== void 0) input.publishedAt = args.publishedAt;
|
|
357
|
-
if (args.tags !== void 0) input.tags = args.tags;
|
|
358
|
-
if (args.metadata !== void 0) input.metadata = encodeAwsJson2(args.metadata);
|
|
359
|
-
const data = await client.query(MUTATION2, { input });
|
|
360
|
-
const updated = toCorePost(data.updatePost);
|
|
361
|
-
await syncPostTags(client, updated, oldPost);
|
|
362
|
-
return updated;
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
// src/tools/delete-post.ts
|
|
366
|
-
var MUTATION3 = (
|
|
367
|
-
/* GraphQL */
|
|
368
|
-
`
|
|
369
|
-
mutation DeletePost($input: DeletePostInput!) {
|
|
370
|
-
deletePost(input: $input) {
|
|
371
|
-
postId
|
|
372
|
-
}
|
|
373
|
-
}
|
|
374
|
-
`
|
|
375
|
-
);
|
|
376
|
-
var deletePostSchema = {
|
|
377
|
-
type: "object",
|
|
378
|
-
required: ["postId"],
|
|
379
|
-
properties: {
|
|
380
|
-
postId: { type: "string" }
|
|
381
|
-
}
|
|
382
|
-
};
|
|
383
|
-
async function deletePost(client, args) {
|
|
384
|
-
const oldPost = await getPost(client, { postId: args.postId });
|
|
385
|
-
if (oldPost) {
|
|
386
|
-
await syncPostTags(client, { ...oldPost, status: "draft" }, oldPost);
|
|
387
|
-
}
|
|
388
|
-
const data = await client.query(MUTATION3, { input: { postId: args.postId } });
|
|
389
|
-
return { deleted: data.deletePost };
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
// src/tools/media-key.ts
|
|
393
|
-
function sanitizeName(name) {
|
|
394
|
-
return name.replace(/[\x00-\x1f\x7f]/g, "").replace(/[\\/:*?"<>|]/g, "_").replace(/\s+/g, "_").replace(/^\.+/, "_").slice(0, 200) || "upload";
|
|
395
|
-
}
|
|
396
|
-
function buildMediaKey(filename, now = /* @__PURE__ */ new Date()) {
|
|
397
|
-
const safe = sanitizeName(filename);
|
|
398
|
-
const yyyy = now.getFullYear();
|
|
399
|
-
const mm = String(now.getMonth() + 1).padStart(2, "0");
|
|
400
|
-
return `public/media/${yyyy}/${mm}/${now.getTime()}-${safe}`;
|
|
401
|
-
}
|
|
402
|
-
|
|
403
|
-
// src/tools/upload-media.ts
|
|
404
|
-
var MUTATION4 = (
|
|
405
|
-
/* GraphQL */
|
|
406
|
-
`
|
|
407
|
-
mutation CreateMedia($input: CreateMediaInput!) {
|
|
408
|
-
createMedia(input: $input) {
|
|
409
|
-
mediaId
|
|
410
|
-
src
|
|
411
|
-
mimeType
|
|
412
|
-
size
|
|
413
|
-
delivery
|
|
414
|
-
}
|
|
415
|
-
}
|
|
416
|
-
`
|
|
417
|
-
);
|
|
418
|
-
var uploadMediaSchema = {
|
|
419
|
-
type: "object",
|
|
420
|
-
required: ["filename", "mimeType", "base64Data"],
|
|
421
|
-
properties: {
|
|
422
|
-
filename: { type: "string", description: "Original filename; sanitized server-side" },
|
|
423
|
-
mimeType: {
|
|
424
|
-
type: "string",
|
|
425
|
-
description: "IANA media type (e.g. image/webp, image/jpeg). The MCP server does not transcode \u2014 pass the MIME of the bytes you actually send."
|
|
426
|
-
},
|
|
427
|
-
base64Data: {
|
|
428
|
-
type: "string",
|
|
429
|
-
description: "Base64-encoded file contents. NO data:URL prefix. The MCP server uploads bytes verbatim \u2014 resize/encode client-side first if needed."
|
|
430
|
-
}
|
|
431
|
-
}
|
|
432
|
-
};
|
|
433
|
-
async function uploadMedia(graphql, storage, args) {
|
|
434
|
-
const body = Buffer.from(args.base64Data, "base64");
|
|
435
|
-
const key = buildMediaKey(args.filename);
|
|
436
|
-
const url = await storage.putObject(key, body, args.mimeType);
|
|
437
|
-
const mediaId = `media-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
|
|
438
|
-
const data = await graphql.query(MUTATION4, {
|
|
439
|
-
input: {
|
|
440
|
-
mediaId,
|
|
441
|
-
src: key,
|
|
442
|
-
mimeType: args.mimeType,
|
|
443
|
-
size: body.length,
|
|
444
|
-
delivery: "nextjs"
|
|
445
|
-
}
|
|
446
|
-
});
|
|
447
|
-
return { media: data.createMedia, url };
|
|
448
|
-
}
|
|
449
|
-
|
|
450
|
-
// src/tools/get-schema.ts
|
|
451
|
-
var getSchemaSchema = {
|
|
452
|
-
type: "object",
|
|
453
|
-
properties: {}
|
|
454
|
-
};
|
|
455
|
-
function getSchema() {
|
|
456
|
-
return {
|
|
457
|
-
contentTypes: [
|
|
458
|
-
{
|
|
459
|
-
name: "post",
|
|
460
|
-
identifier: ["postId"],
|
|
461
|
-
fields: {
|
|
462
|
-
postId: { type: "string", required: true, description: "auto-generated if omitted on create" },
|
|
463
|
-
slug: { type: "string", required: true, description: "URL slug, unique" },
|
|
464
|
-
title: { type: "string", required: true },
|
|
465
|
-
excerpt: { type: "string" },
|
|
466
|
-
format: { type: "enum", values: ["tiptap", "markdown", "html"], required: true },
|
|
467
|
-
body: {
|
|
468
|
-
type: "json",
|
|
469
|
-
description: "tiptap node JSON when format=tiptap; markdown source string when format=markdown; raw HTML string when format=html"
|
|
470
|
-
},
|
|
471
|
-
status: { type: "enum", values: ["draft", "published"], default: "draft" },
|
|
472
|
-
publishedAt: { type: "datetime", description: "ISO 8601" },
|
|
473
|
-
tags: { type: "string[]" },
|
|
474
|
-
metadata: {
|
|
475
|
-
type: "json",
|
|
476
|
-
description: "Free-form per-post key/value bag. Reserved well-known keys (owned by ampless): `no_layout` (boolean), `cache` (auto|deep|hot). Other keys pass through unchanged for themes/plugins."
|
|
477
|
-
}
|
|
478
|
-
}
|
|
479
|
-
},
|
|
480
|
-
{
|
|
481
|
-
name: "page",
|
|
482
|
-
identifier: ["pageId"],
|
|
483
|
-
fields: {
|
|
484
|
-
pageId: { type: "string", required: true },
|
|
485
|
-
slug: { type: "string", required: true },
|
|
486
|
-
title: { type: "string", required: true },
|
|
487
|
-
format: { type: "enum", values: ["tiptap", "markdown", "html"], required: true },
|
|
488
|
-
body: { type: "json" },
|
|
489
|
-
status: { type: "enum", values: ["draft", "published"] },
|
|
490
|
-
publishedAt: { type: "datetime" }
|
|
491
|
-
}
|
|
492
|
-
},
|
|
493
|
-
{
|
|
494
|
-
name: "media",
|
|
495
|
-
identifier: ["mediaId"],
|
|
496
|
-
fields: {
|
|
497
|
-
mediaId: { type: "string", required: true },
|
|
498
|
-
src: { type: "string", required: true, description: "S3 key" },
|
|
499
|
-
mimeType: { type: "string", required: true },
|
|
500
|
-
size: { type: "integer" },
|
|
501
|
-
delivery: { type: "string" }
|
|
502
|
-
}
|
|
503
|
-
}
|
|
504
|
-
],
|
|
505
|
-
formats: ["tiptap", "markdown", "html"],
|
|
506
|
-
notes: {
|
|
507
|
-
editorTrust: 'editor stores arbitrary HTML/JS verbatim \u2014 same trust shape as WordPress unfiltered_html capability. See docs/architecture/04-access-layer-mcp.md \xA7"editor \u306E\u4FE1\u983C\u30E2\u30C7\u30EB".',
|
|
508
|
-
tiptapBody: 'When format=tiptap, body is the tiptap document JSON: { type: "doc", content: [...] }. The renderer expects this shape.',
|
|
509
|
-
noLayout: "metadata.no_layout=true serves the post as bare HTML with no theme chrome \u2014 middleware rewrites the public /<slug> request to the internal bare-HTML handler, which renders the body verbatim with no wrapping <html>/<head>/layout. Use this for landing pages, embeds, or any post whose body is a full HTML document. Only meaningful with format=html (the other formats need the theme renderer).",
|
|
510
|
-
staticFormat: "A fourth format value `static` exists on the underlying data model for posts whose body is a JSON manifest pointing to a pre-uploaded HTML/CSS/JS bundle in S3 at public/static/<slug>/. Public URL pattern: /<slug>/ for the entrypoint and /<slug>/<file> for every bundle file (middleware rewrites both to an internal static-bundle handler). Static posts are created/edited through the dedicated tools `upload_static_bundle` (zip in one shot), `upload_static_file` / `delete_static_file` (incremental per-file ops), and `commit_static_post` (rebuild the manifest from the current S3 prefix). `create_post` / `update_post` intentionally do NOT accept format=static \u2014 the bundle tools are the only supported entry point so the Post manifest stays in sync with the S3 prefix.",
|
|
511
|
-
cacheStrategy: "metadata.cache controls the response Cache-Control header (set by middleware). Values:\n - 'auto' (default): cooldown by edit time. Posts updated within cms.config.cache.cooldownMs (default 1h) emit `public, max-age=0, must-revalidate, s-maxage=0` so editors see fresh content immediately; older posts emit `public, max-age=<freshTtlSeconds>, s-maxage=<freshTtlSeconds>` (default 300 sec / 5 min).\n - 'deep': always `public, max-age=<deepTtlSeconds>, s-maxage=<deepTtlSeconds>` (default 3600 sec / 1 hour). Use for posts whose content is fixed for the foreseeable future.\n - 'hot': always `public, max-age=0, must-revalidate, s-maxage=0`. Use for rapidly-evolving posts or posts whose body is computed per request.\nIndependent of metadata.no_layout and post.format \u2014 applies uniformly to themed, no_layout, and static posts. Override the defaults per project via `cms.config.cache` ({ cooldownMs, freshTtlSeconds, deepTtlSeconds })."
|
|
512
|
-
}
|
|
513
|
-
};
|
|
514
|
-
}
|
|
515
|
-
|
|
516
|
-
// src/tools/upload-static-bundle.ts
|
|
517
|
-
import {
|
|
518
|
-
bundlePrefix,
|
|
519
|
-
mimeTypeFor,
|
|
520
|
-
pickDefaultEntrypoint,
|
|
521
|
-
validateBundle
|
|
522
|
-
} from "ampless";
|
|
523
|
-
|
|
524
|
-
// src/tools/static-bundle-extract.ts
|
|
525
|
-
import { unzipSync, strFromU8 } from "fflate";
|
|
526
|
-
import {
|
|
527
|
-
validateBundlePath,
|
|
528
|
-
stripCommonPrefix
|
|
529
|
-
} from "ampless";
|
|
530
|
-
var DEFAULT_MAX_BYTES = 50 * 1024 * 1024;
|
|
531
|
-
function extractZipFromBuffer(buffer, opts = {}) {
|
|
532
|
-
const maxBytes = opts.maxBytes ?? DEFAULT_MAX_BYTES;
|
|
533
|
-
const entries2 = unzipSync(buffer);
|
|
534
|
-
const files = [];
|
|
535
|
-
const issues = [];
|
|
536
|
-
let totalBytes = 0;
|
|
537
|
-
for (const [name, data] of Object.entries(entries2)) {
|
|
538
|
-
if (name.endsWith("/")) continue;
|
|
539
|
-
const reason = validateBundlePath(name);
|
|
540
|
-
if (reason) {
|
|
541
|
-
const silent = reason === "macOS resource fork" || reason === ".DS_Store junk" || reason === "Thumbs.db junk" || reason === "directory entry";
|
|
542
|
-
if (!silent) issues.push({ path: name, reason });
|
|
543
|
-
continue;
|
|
544
|
-
}
|
|
545
|
-
totalBytes += data.byteLength;
|
|
546
|
-
if (totalBytes > maxBytes) {
|
|
547
|
-
throw new Error(
|
|
548
|
-
`Bundle too large: uncompressed size exceeds the ${Math.round(maxBytes / 1024 / 1024)} MB ceiling.`
|
|
549
|
-
);
|
|
550
|
-
}
|
|
551
|
-
files.push({ path: name, data });
|
|
552
|
-
}
|
|
553
|
-
return { files: stripCommonPrefix(files), issues, totalBytes };
|
|
554
|
-
}
|
|
555
|
-
function decodeUtf8(data) {
|
|
556
|
-
return strFromU8(data);
|
|
557
|
-
}
|
|
558
|
-
|
|
559
|
-
// src/tools/upsert-static-post.ts
|
|
560
|
-
import {
|
|
561
|
-
encodeAwsJson as encodeAwsJson3
|
|
562
|
-
} from "ampless";
|
|
563
|
-
var CREATE_MUTATION = (
|
|
564
|
-
/* GraphQL */
|
|
565
|
-
`
|
|
566
|
-
${POST_FIELDS}
|
|
567
|
-
mutation CreatePost($input: CreatePostInput!) {
|
|
568
|
-
createPost(input: $input) {
|
|
569
|
-
...PostFields
|
|
570
|
-
}
|
|
571
|
-
}
|
|
572
|
-
`
|
|
573
|
-
);
|
|
574
|
-
var UPDATE_MUTATION = (
|
|
575
|
-
/* GraphQL */
|
|
576
|
-
`
|
|
577
|
-
${POST_FIELDS}
|
|
578
|
-
mutation UpdatePost($input: UpdatePostInput!) {
|
|
579
|
-
updatePost(input: $input) {
|
|
580
|
-
...PostFields
|
|
581
|
-
}
|
|
582
|
-
}
|
|
583
|
-
`
|
|
584
|
-
);
|
|
585
|
-
async function upsertStaticPost(graphql, slug, body, fields) {
|
|
586
|
-
const existing = await getPost(graphql, { slug });
|
|
587
|
-
if (existing) {
|
|
588
|
-
const input2 = {
|
|
589
|
-
postId: existing.postId,
|
|
590
|
-
format: "static",
|
|
591
|
-
body: encodeAwsJson3(body)
|
|
592
|
-
};
|
|
593
|
-
if (fields.title !== void 0) input2.title = fields.title;
|
|
594
|
-
if (fields.excerpt !== void 0) input2.excerpt = fields.excerpt;
|
|
595
|
-
if (fields.status !== void 0) input2.status = fields.status;
|
|
596
|
-
if (fields.publishedAt !== void 0) input2.publishedAt = fields.publishedAt;
|
|
597
|
-
if (fields.tags !== void 0) input2.tags = fields.tags;
|
|
598
|
-
if (fields.metadata !== void 0) {
|
|
599
|
-
input2.metadata = encodeAwsJson3(fields.metadata);
|
|
600
|
-
}
|
|
601
|
-
const data2 = await graphql.query(UPDATE_MUTATION, { input: input2 });
|
|
602
|
-
const updated = toCorePost(data2.updatePost);
|
|
603
|
-
await syncPostTags(graphql, updated, existing);
|
|
604
|
-
return { post: updated, created: false };
|
|
605
|
-
}
|
|
606
|
-
if (!fields.title) {
|
|
607
|
-
throw new Error(
|
|
608
|
-
`commit_static_post: cannot create a new post at slug "${slug}" without a title. Pass \`title\` or commit against an existing post.`
|
|
609
|
-
);
|
|
610
|
-
}
|
|
611
|
-
const status = fields.status ?? "draft";
|
|
612
|
-
const publishedAt = fields.publishedAt ?? (status === "published" ? (/* @__PURE__ */ new Date()).toISOString() : void 0);
|
|
613
|
-
const postId = fields.postId ?? `post-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
|
|
614
|
-
const input = {
|
|
615
|
-
postId,
|
|
616
|
-
slug,
|
|
617
|
-
title: fields.title,
|
|
618
|
-
format: "static",
|
|
619
|
-
body: encodeAwsJson3(body),
|
|
620
|
-
status
|
|
621
|
-
};
|
|
622
|
-
if (fields.excerpt !== void 0) input.excerpt = fields.excerpt;
|
|
623
|
-
if (publishedAt !== void 0) input.publishedAt = publishedAt;
|
|
624
|
-
if (fields.tags !== void 0) input.tags = fields.tags;
|
|
625
|
-
if (fields.metadata !== void 0) input.metadata = encodeAwsJson3(fields.metadata);
|
|
626
|
-
const data = await graphql.query(CREATE_MUTATION, { input });
|
|
627
|
-
const created = toCorePost(data.createPost);
|
|
628
|
-
await syncPostTags(graphql, created, null);
|
|
629
|
-
return { post: created, created: true };
|
|
630
|
-
}
|
|
631
|
-
|
|
632
|
-
// src/tools/upload-static-bundle.ts
|
|
633
|
-
var uploadStaticBundleSchema = {
|
|
634
|
-
type: "object",
|
|
635
|
-
required: ["slug", "title", "zipBase64"],
|
|
636
|
-
properties: {
|
|
637
|
-
postId: {
|
|
638
|
-
type: "string",
|
|
639
|
-
description: "Optional explicit Post id when creating a new post. Ignored if a post at this slug already exists."
|
|
640
|
-
},
|
|
641
|
-
slug: { type: "string", description: "URL slug. Doubles as the S3 bundle path key." },
|
|
642
|
-
title: { type: "string" },
|
|
643
|
-
zipBase64: {
|
|
644
|
-
type: "string",
|
|
645
|
-
description: "Base64-encoded zip archive. NO `data:` URL prefix. Every entry must reference others by RELATIVE path; absolute paths (`/foo`) and protocol-relative URLs (`//cdn/foo`) inside HTML / CSS / SVG are rejected as the bundle would not be portable across URL prefixes."
|
|
646
|
-
},
|
|
647
|
-
entrypoint: {
|
|
648
|
-
type: "string",
|
|
649
|
-
description: "Relative path to the file served at the post URL (default `index.html`, or the first `.html` at root if `index.html` is absent)."
|
|
650
|
-
},
|
|
651
|
-
status: { type: "string", enum: ["draft", "published"], default: "draft" },
|
|
652
|
-
excerpt: { type: "string" },
|
|
653
|
-
publishedAt: { type: "string", description: 'ISO 8601 timestamp; defaults to "now" when status=published.' },
|
|
654
|
-
tags: { type: "array", items: { type: "string" } },
|
|
655
|
-
metadata: {
|
|
656
|
-
type: "object",
|
|
657
|
-
description: "Free-form per-post metadata. NOTE: `no_layout` is irrelevant for static posts (the bundle is already served raw).",
|
|
658
|
-
additionalProperties: true
|
|
659
|
-
}
|
|
660
|
-
}
|
|
661
|
-
};
|
|
662
|
-
async function uploadStaticBundle(graphql, storage, args) {
|
|
663
|
-
const slug = args.slug;
|
|
664
|
-
const zipBytes = Buffer.from(args.zipBase64, "base64");
|
|
665
|
-
if (zipBytes.length === 0) {
|
|
666
|
-
throw new Error("upload_static_bundle: zipBase64 decoded to zero bytes.");
|
|
667
|
-
}
|
|
668
|
-
const { files, issues } = extractZipFromBuffer(zipBytes);
|
|
669
|
-
if (issues.length > 0) {
|
|
670
|
-
throw new Error(
|
|
671
|
-
`upload_static_bundle: rejected bundle path(s): ${issues.map((i) => `${i.path} (${i.reason})`).join("; ")}`
|
|
672
|
-
);
|
|
673
|
-
}
|
|
674
|
-
if (files.length === 0) {
|
|
675
|
-
throw new Error("upload_static_bundle: zip contained no files.");
|
|
676
|
-
}
|
|
677
|
-
const contentIssues = validateBundle(files);
|
|
678
|
-
if (contentIssues.length > 0) {
|
|
679
|
-
throw new Error(
|
|
680
|
-
`upload_static_bundle: bundle contains absolute / protocol-relative refs: ${contentIssues.map((i) => `${i.path}: ${i.reason}`).join("; ")}`
|
|
681
|
-
);
|
|
682
|
-
}
|
|
683
|
-
const entrypoint = args.entrypoint ?? pickDefaultEntrypoint(files);
|
|
684
|
-
if (!files.some((f) => f.path === entrypoint)) {
|
|
685
|
-
throw new Error(
|
|
686
|
-
`upload_static_bundle: entrypoint "${entrypoint}" is not present in the bundle.`
|
|
687
|
-
);
|
|
688
|
-
}
|
|
689
|
-
const prefix = bundlePrefix(slug);
|
|
690
|
-
const existing = await storage.listObjects(prefix).catch((err) => {
|
|
691
|
-
console.error("[upload_static_bundle] listObjects failed (proceeding)", err);
|
|
692
|
-
return [];
|
|
693
|
-
});
|
|
694
|
-
for (const obj of existing) {
|
|
695
|
-
await storage.deleteObject(obj.key);
|
|
696
|
-
}
|
|
697
|
-
let uploadedFiles = 0;
|
|
698
|
-
for (const f of files) {
|
|
699
|
-
await storage.putObject(`${prefix}${f.path}`, f.data, mimeTypeFor(f.path));
|
|
700
|
-
uploadedFiles += 1;
|
|
701
|
-
}
|
|
702
|
-
const body = {
|
|
703
|
-
entrypoint,
|
|
704
|
-
files: files.map((f) => f.path).sort(),
|
|
705
|
-
uploadedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
706
|
-
};
|
|
707
|
-
const { post } = await upsertStaticPost(graphql, slug, body, {
|
|
708
|
-
title: args.title,
|
|
709
|
-
postId: args.postId,
|
|
710
|
-
status: args.status,
|
|
711
|
-
publishedAt: args.publishedAt,
|
|
712
|
-
excerpt: args.excerpt,
|
|
713
|
-
tags: args.tags,
|
|
714
|
-
metadata: args.metadata
|
|
715
|
-
});
|
|
716
|
-
return { post, bundle: body, uploadedFiles };
|
|
717
|
-
}
|
|
718
|
-
|
|
719
|
-
// src/tools/upload-static-file.ts
|
|
720
|
-
import {
|
|
721
|
-
bundlePrefix as bundlePrefix2,
|
|
722
|
-
findAbsolutePathRefs,
|
|
723
|
-
mimeTypeFor as mimeTypeFor2,
|
|
724
|
-
validateBundlePath as validateBundlePath2,
|
|
725
|
-
TEXT_EXTENSIONS
|
|
726
|
-
} from "ampless";
|
|
727
|
-
var uploadStaticFileSchema = {
|
|
728
|
-
type: "object",
|
|
729
|
-
required: ["slug", "filename", "base64Data"],
|
|
730
|
-
properties: {
|
|
731
|
-
slug: { type: "string", description: "Bundle slug. Files land at public/static/<slug>/<filename>." },
|
|
732
|
-
filename: {
|
|
733
|
-
type: "string",
|
|
734
|
-
description: "Relative path inside the bundle. Must NOT start with `/`, contain `..`, or include null bytes. macOS / Windows zip junk (`.DS_Store`, `__MACOSX/*`, `Thumbs.db`) is also rejected."
|
|
735
|
-
},
|
|
736
|
-
contentType: {
|
|
737
|
-
type: "string",
|
|
738
|
-
description: "IANA media type. Omit to derive from the filename extension (text/html, text/css, application/javascript, image/* \u2026; falls back to application/octet-stream)."
|
|
739
|
-
},
|
|
740
|
-
base64Data: {
|
|
741
|
-
type: "string",
|
|
742
|
-
description: "Base64-encoded file bytes. NO `data:` URL prefix. Text files (HTML/CSS/SVG) are linted for absolute / protocol-relative URL refs \u2014 failures throw."
|
|
743
|
-
}
|
|
744
|
-
}
|
|
745
|
-
};
|
|
746
|
-
async function uploadStaticFile(storage, args) {
|
|
747
|
-
const filename = args.filename;
|
|
748
|
-
const reason = validateBundlePath2(filename);
|
|
749
|
-
if (reason) {
|
|
750
|
-
throw new Error(`upload_static_file: invalid filename "${filename}" (${reason})`);
|
|
751
|
-
}
|
|
752
|
-
const body = Buffer.from(args.base64Data, "base64");
|
|
753
|
-
if (body.length === 0) {
|
|
754
|
-
throw new Error("upload_static_file: base64Data decoded to zero bytes.");
|
|
755
|
-
}
|
|
756
|
-
const ext = filename.toLowerCase().slice(filename.lastIndexOf("."));
|
|
757
|
-
if (TEXT_EXTENSIONS.has(ext)) {
|
|
758
|
-
const text = body.toString("utf8");
|
|
759
|
-
const issues = findAbsolutePathRefs(filename, text);
|
|
760
|
-
if (issues.length > 0) {
|
|
761
|
-
throw new Error(
|
|
762
|
-
`upload_static_file: ${filename} contains absolute / protocol-relative refs: ${issues.map((i) => i.reason).join("; ")}`
|
|
763
|
-
);
|
|
764
|
-
}
|
|
765
|
-
}
|
|
766
|
-
const contentType = args.contentType ?? mimeTypeFor2(filename);
|
|
767
|
-
const key = `${bundlePrefix2(args.slug)}${filename}`;
|
|
768
|
-
const url = await storage.putObject(key, body, contentType);
|
|
769
|
-
return { key, url, size: body.length };
|
|
770
|
-
}
|
|
771
|
-
|
|
772
|
-
// src/tools/delete-static-file.ts
|
|
773
|
-
import { bundlePrefix as bundlePrefix3, validateBundlePath as validateBundlePath3 } from "ampless";
|
|
774
|
-
var deleteStaticFileSchema = {
|
|
775
|
-
type: "object",
|
|
776
|
-
required: ["slug", "filename"],
|
|
777
|
-
properties: {
|
|
778
|
-
slug: { type: "string" },
|
|
779
|
-
filename: {
|
|
780
|
-
type: "string",
|
|
781
|
-
description: "Relative path inside the bundle to delete. Same path rules as `upload_static_file` apply (no `..`, no absolute paths, no null bytes)."
|
|
782
|
-
}
|
|
783
|
-
}
|
|
784
|
-
};
|
|
785
|
-
async function deleteStaticFile(storage, args) {
|
|
786
|
-
const reason = validateBundlePath3(args.filename);
|
|
787
|
-
if (reason) {
|
|
788
|
-
throw new Error(`delete_static_file: invalid filename "${args.filename}" (${reason})`);
|
|
789
|
-
}
|
|
790
|
-
const prefix = bundlePrefix3(args.slug);
|
|
791
|
-
const key = `${prefix}${args.filename}`;
|
|
792
|
-
const existing = await storage.listObjects(key);
|
|
793
|
-
const found = existing.some((o) => o.key === key);
|
|
794
|
-
if (!found) {
|
|
795
|
-
return { key, deleted: false };
|
|
796
|
-
}
|
|
797
|
-
await storage.deleteObject(key);
|
|
798
|
-
return { key, deleted: true };
|
|
799
|
-
}
|
|
800
|
-
|
|
801
|
-
// src/tools/commit-static-post.ts
|
|
802
|
-
import {
|
|
803
|
-
bundlePrefix as bundlePrefix4,
|
|
804
|
-
pickDefaultEntrypoint as pickDefaultEntrypoint2
|
|
805
|
-
} from "ampless";
|
|
806
|
-
var commitStaticPostSchema = {
|
|
807
|
-
type: "object",
|
|
808
|
-
required: ["slug"],
|
|
809
|
-
properties: {
|
|
810
|
-
slug: { type: "string" },
|
|
811
|
-
title: {
|
|
812
|
-
type: "string",
|
|
813
|
-
description: "Required when this is a brand-new post (no existing row at the slug). On update, falls back to the current title."
|
|
814
|
-
},
|
|
815
|
-
entrypoint: {
|
|
816
|
-
type: "string",
|
|
817
|
-
description: "Relative path of the entry file (defaults to `index.html`, or the first `.html` at root if absent). Must exist under the current S3 prefix."
|
|
818
|
-
},
|
|
819
|
-
postId: {
|
|
820
|
-
type: "string",
|
|
821
|
-
description: "Optional explicit Post id when creating a new post. Ignored if a row at this slug already exists."
|
|
822
|
-
},
|
|
823
|
-
status: { type: "string", enum: ["draft", "published"] },
|
|
824
|
-
publishedAt: { type: "string", description: "ISO 8601 timestamp." },
|
|
825
|
-
excerpt: { type: "string" },
|
|
826
|
-
tags: { type: "array", items: { type: "string" } },
|
|
827
|
-
metadata: {
|
|
828
|
-
type: "object",
|
|
829
|
-
description: "Free-form per-post metadata. Passing this REPLACES the existing object on update.",
|
|
830
|
-
additionalProperties: true
|
|
831
|
-
}
|
|
832
|
-
}
|
|
833
|
-
};
|
|
834
|
-
async function commitStaticPost(graphql, storage, args) {
|
|
835
|
-
const slug = args.slug;
|
|
836
|
-
const prefix = bundlePrefix4(slug);
|
|
837
|
-
const objects = await storage.listObjects(prefix);
|
|
838
|
-
if (objects.length === 0) {
|
|
839
|
-
throw new Error(
|
|
840
|
-
`commit_static_post: no files found under "${prefix}". Upload at least one file via upload_static_file or upload_static_bundle before committing.`
|
|
841
|
-
);
|
|
842
|
-
}
|
|
843
|
-
const relPaths = objects.map((o) => o.key.slice(prefix.length)).filter((p) => p !== "").sort();
|
|
844
|
-
const entrypoint = args.entrypoint ?? pickDefaultEntrypoint2(relPaths.map((p) => ({ path: p })));
|
|
845
|
-
if (!relPaths.includes(entrypoint)) {
|
|
846
|
-
throw new Error(
|
|
847
|
-
`commit_static_post: entrypoint "${entrypoint}" is not present under "${prefix}".`
|
|
848
|
-
);
|
|
849
|
-
}
|
|
850
|
-
const body = {
|
|
851
|
-
entrypoint,
|
|
852
|
-
files: relPaths,
|
|
853
|
-
uploadedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
854
|
-
};
|
|
855
|
-
const { post, created } = await upsertStaticPost(graphql, slug, body, {
|
|
856
|
-
title: args.title,
|
|
857
|
-
postId: args.postId,
|
|
858
|
-
excerpt: args.excerpt,
|
|
859
|
-
status: args.status,
|
|
860
|
-
publishedAt: args.publishedAt,
|
|
861
|
-
tags: args.tags,
|
|
862
|
-
metadata: args.metadata
|
|
863
|
-
});
|
|
864
|
-
return { post, bundle: body, created };
|
|
865
|
-
}
|
|
866
|
-
|
|
867
|
-
// src/tools/index.ts
|
|
868
|
-
var tools = [
|
|
869
|
-
{
|
|
870
|
-
name: "list_posts",
|
|
871
|
-
description: "List posts in the CMS with optional filters by status. Returns up to `limit` posts (default 20) plus a `nextToken` cursor for pagination.",
|
|
872
|
-
inputSchema: listPostsSchema,
|
|
873
|
-
handler: (args, ctx) => listPosts(ctx.graphql, args)
|
|
874
|
-
},
|
|
875
|
-
{
|
|
876
|
-
name: "get_post",
|
|
877
|
-
description: "Fetch a single post by slug or postId. Returns null if not found.",
|
|
878
|
-
inputSchema: getPostSchema,
|
|
879
|
-
handler: (args, ctx) => getPost(ctx.graphql, args)
|
|
880
|
-
},
|
|
881
|
-
{
|
|
882
|
-
name: "create_post",
|
|
883
|
-
description: 'Create a new post. Title and slug are required. Body shape depends on format: tiptap=JSON node tree, markdown=source string, html=raw HTML string. Defaults to status=draft. Pass `metadata: { no_layout: true }` alongside format=html to publish the body as a bare HTML page with no theme chrome (middleware rewrites the /<slug> request to the internal bare-HTML handler). Pass `metadata: { cache: "deep" | "hot" }` to override the default cooldown-based cache strategy \u2014 see get_schema.notes.cacheStrategy for details.',
|
|
884
|
-
inputSchema: createPostSchema,
|
|
885
|
-
handler: (args, ctx) => createPost(ctx.graphql, args)
|
|
886
|
-
},
|
|
887
|
-
{
|
|
888
|
-
name: "update_post",
|
|
889
|
-
description: "Update an existing post by postId. Only the fields you pass are changed. Tag list / publishedAt changes also update the PostTag denormalized index. Passing `metadata` REPLACES the existing object \u2014 call get_post first if you only want to add or change one key.",
|
|
890
|
-
inputSchema: updatePostSchema,
|
|
891
|
-
handler: (args, ctx) => updatePost(ctx.graphql, args)
|
|
892
|
-
},
|
|
893
|
-
{
|
|
894
|
-
name: "delete_post",
|
|
895
|
-
description: "Delete a post by postId. Also drops associated PostTag index entries.",
|
|
896
|
-
inputSchema: deletePostSchema,
|
|
897
|
-
handler: (args, ctx) => deletePost(ctx.graphql, args),
|
|
898
|
-
destructive: true
|
|
899
|
-
},
|
|
900
|
-
{
|
|
901
|
-
name: "upload_media",
|
|
902
|
-
description: "Upload a file to the site's media S3 bucket. Pass base64-encoded bytes; the server stores them verbatim under public/media/YYYY/MM/. Returns the public URL and Media record. The server does not transcode \u2014 pre-process (e.g. resize/webp) on the client.",
|
|
903
|
-
inputSchema: uploadMediaSchema,
|
|
904
|
-
handler: (args, ctx) => uploadMedia(ctx.graphql, ctx.storage(), args)
|
|
905
|
-
},
|
|
906
|
-
{
|
|
907
|
-
name: "get_schema",
|
|
908
|
-
description: "Returns the CMS content schema (Post/Page/Media field shapes, format enum, notes). Useful as the first call to understand what fields are available.",
|
|
909
|
-
inputSchema: getSchemaSchema,
|
|
910
|
-
handler: async () => getSchema()
|
|
911
|
-
},
|
|
912
|
-
{
|
|
913
|
-
name: "upload_static_bundle",
|
|
914
|
-
description: "Create or replace a `format: 'static'` post in one shot. Pass a base64-encoded zip; the server unpacks it, validates every path + lints HTML/CSS/SVG for absolute path refs (bundles must be self-contained via relative paths), wipes the existing S3 prefix at public/static/<slug>/, uploads every file, and upserts the Post row with a manifest pointing at the entrypoint. Use this when you have the whole bundle to submit at once. For incremental edits use upload_static_file / delete_static_file followed by commit_static_post.",
|
|
915
|
-
inputSchema: uploadStaticBundleSchema,
|
|
916
|
-
handler: (args, ctx) => uploadStaticBundle(
|
|
917
|
-
ctx.graphql,
|
|
918
|
-
ctx.storage(),
|
|
919
|
-
args
|
|
920
|
-
),
|
|
921
|
-
destructive: true
|
|
922
|
-
},
|
|
923
|
-
{
|
|
924
|
-
name: "upload_static_file",
|
|
925
|
-
description: "Upload a single file into an existing static bundle's S3 prefix. The Post row is NOT modified \u2014 its `body` manifest will be out of sync with the prefix until you call `commit_static_post`. Use this for incremental edits (one CSS swap, single image change) where rebuilding the entire zip would be overkill. Text files (HTML/CSS/SVG) are linted for absolute / protocol-relative URL refs the same as the zip flow.",
|
|
926
|
-
inputSchema: uploadStaticFileSchema,
|
|
927
|
-
handler: (args, ctx) => uploadStaticFile(
|
|
928
|
-
ctx.storage(),
|
|
929
|
-
args
|
|
930
|
-
)
|
|
931
|
-
},
|
|
932
|
-
{
|
|
933
|
-
name: "delete_static_file",
|
|
934
|
-
description: "Delete a single file from a static bundle's S3 prefix. The Post row is NOT modified \u2014 its `body` manifest will list the deleted file until you call `commit_static_post`. Idempotent: returns `{ deleted: false }` instead of throwing if the file isn't there.",
|
|
935
|
-
inputSchema: deleteStaticFileSchema,
|
|
936
|
-
handler: (args, ctx) => deleteStaticFile(
|
|
937
|
-
ctx.storage(),
|
|
938
|
-
args
|
|
939
|
-
),
|
|
940
|
-
destructive: true
|
|
941
|
-
},
|
|
942
|
-
{
|
|
943
|
-
name: "commit_static_post",
|
|
944
|
-
description: 'Rebuild a static post\'s Post row from whatever is currently in its S3 prefix. Scans `public/static/<slug>/`, picks the entrypoint (default `index.html` or override), and upserts the Post with a fresh manifest (sorted file list + uploadedAt timestamp). Use this as the "save" step after a series of `upload_static_file` / `delete_static_file` calls. `title` is required when creating a brand-new post; on update, existing fields are preserved unless explicitly overridden.',
|
|
945
|
-
inputSchema: commitStaticPostSchema,
|
|
946
|
-
handler: (args, ctx) => commitStaticPost(
|
|
947
|
-
ctx.graphql,
|
|
948
|
-
ctx.storage(),
|
|
949
|
-
args
|
|
950
|
-
)
|
|
951
|
-
}
|
|
952
|
-
];
|
|
953
|
-
async function dispatchToolCall(name, args, ctx) {
|
|
954
|
-
const tool = tools.find((t) => t.name === name);
|
|
955
|
-
if (!tool) return null;
|
|
956
|
-
return tool.handler(args, ctx);
|
|
957
|
-
}
|
|
958
|
-
function getTools() {
|
|
959
|
-
return tools;
|
|
960
|
-
}
|
|
961
|
-
|
|
962
|
-
export {
|
|
963
|
-
extractZipFromBuffer,
|
|
964
|
-
decodeUtf8,
|
|
965
|
-
tools,
|
|
966
|
-
dispatchToolCall,
|
|
967
|
-
getTools
|
|
968
|
-
};
|