@geekity/cms 0.42.2 → 0.44.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/admin/pages/federation/followers.njk +1 -1
- package/admin/pages/users/activity.njk +3 -1
- package/admin/pages/users/apps.njk +55 -19
- package/admin/static/admin.css +9 -1
- package/admin/static/editor.js +22 -21
- package/dist/admin/app-activity.d.ts +8 -3
- package/dist/admin/app-activity.d.ts.map +1 -1
- package/dist/admin/app-activity.js +10 -3
- package/dist/admin/app-activity.js.map +1 -1
- package/dist/admin/connected-apps.d.ts +1 -1
- package/dist/admin/connected-apps.d.ts.map +1 -1
- package/dist/admin/connected-apps.js +99 -28
- package/dist/admin/connected-apps.js.map +1 -1
- package/dist/admin/indieauth-consent.d.ts.map +1 -1
- package/dist/admin/indieauth-consent.js +20 -2
- package/dist/admin/indieauth-consent.js.map +1 -1
- package/dist/admin/list-indent.d.ts +19 -0
- package/dist/admin/list-indent.d.ts.map +1 -0
- package/dist/admin/list-indent.js +73 -0
- package/dist/admin/list-indent.js.map +1 -0
- package/dist/admin/widget-health.d.ts.map +1 -1
- package/dist/admin/widget-health.js +2 -0
- package/dist/admin/widget-health.js.map +1 -1
- package/dist/cms/app.d.ts.map +1 -1
- package/dist/cms/app.js +3 -0
- package/dist/cms/app.js.map +1 -1
- package/dist/cms/services.d.ts.map +1 -1
- package/dist/cms/services.js +21 -2
- package/dist/cms/services.js.map +1 -1
- package/dist/{micropub/create.d.ts → content/micropub-create.d.ts} +5 -5
- package/dist/content/micropub-create.d.ts.map +1 -0
- package/dist/{micropub/create.js → content/micropub-create.js} +8 -8
- package/dist/content/micropub-create.js.map +1 -0
- package/dist/{micropub/update.d.ts → content/micropub-update.d.ts} +9 -9
- package/dist/content/micropub-update.d.ts.map +1 -0
- package/dist/{micropub/update.js → content/micropub-update.js} +8 -8
- package/dist/content/micropub-update.js.map +1 -0
- package/dist/federation/delivery.d.ts +20 -2
- package/dist/federation/delivery.d.ts.map +1 -1
- package/dist/federation/delivery.js +37 -23
- package/dist/federation/delivery.js.map +1 -1
- package/dist/federation/federation.d.ts.map +1 -1
- package/dist/federation/federation.js +2 -8
- package/dist/federation/federation.js.map +1 -1
- package/dist/federation/inbox.d.ts +5 -2
- package/dist/federation/inbox.d.ts.map +1 -1
- package/dist/federation/inbox.js +3 -3
- package/dist/federation/inbox.js.map +1 -1
- package/dist/federation/keys.d.ts +10 -0
- package/dist/federation/keys.d.ts.map +1 -1
- package/dist/federation/keys.js +13 -8
- package/dist/federation/keys.js.map +1 -1
- package/dist/federation/outbox-observer.d.ts +17 -0
- package/dist/federation/outbox-observer.d.ts.map +1 -0
- package/dist/federation/outbox-observer.js +98 -0
- package/dist/federation/outbox-observer.js.map +1 -0
- package/dist/federation/relays.d.ts.map +1 -1
- package/dist/federation/relays.js +32 -7
- package/dist/federation/relays.js.map +1 -1
- package/dist/federation/resend-job.d.ts +2 -1
- package/dist/federation/resend-job.d.ts.map +1 -1
- package/dist/federation/resend-job.js +11 -10
- package/dist/federation/resend-job.js.map +1 -1
- package/dist/federation/retry-job.d.ts +44 -0
- package/dist/federation/retry-job.d.ts.map +1 -0
- package/dist/federation/retry-job.js +102 -0
- package/dist/federation/retry-job.js.map +1 -0
- package/dist/files/data-files.d.ts +1 -0
- package/dist/files/data-files.d.ts.map +1 -1
- package/dist/files/data-files.js +6 -0
- package/dist/files/data-files.js.map +1 -1
- package/dist/indieauth/request.d.ts +4 -3
- package/dist/indieauth/request.d.ts.map +1 -1
- package/dist/indieauth/request.js +21 -3
- package/dist/indieauth/request.js.map +1 -1
- package/dist/mcp/audit.d.ts +3 -0
- package/dist/mcp/audit.d.ts.map +1 -0
- package/dist/mcp/audit.js +35 -0
- package/dist/mcp/audit.js.map +1 -0
- package/dist/mcp/authoring/create.d.ts +2 -0
- package/dist/mcp/authoring/create.d.ts.map +1 -0
- package/dist/mcp/authoring/create.js +79 -0
- package/dist/mcp/authoring/create.js.map +1 -0
- package/dist/mcp/authoring/publish.d.ts +2 -0
- package/dist/mcp/authoring/publish.d.ts.map +1 -0
- package/dist/mcp/authoring/publish.js +75 -0
- package/dist/mcp/authoring/publish.js.map +1 -0
- package/dist/mcp/authoring/shared.d.ts +23 -0
- package/dist/mcp/authoring/shared.d.ts.map +1 -0
- package/dist/mcp/authoring/shared.js +35 -0
- package/dist/mcp/authoring/shared.js.map +1 -0
- package/dist/mcp/authoring/source.d.ts +2 -0
- package/dist/mcp/authoring/source.d.ts.map +1 -0
- package/dist/mcp/authoring/source.js +48 -0
- package/dist/mcp/authoring/source.js.map +1 -0
- package/dist/mcp/authoring/update.d.ts +2 -0
- package/dist/mcp/authoring/update.d.ts.map +1 -0
- package/dist/mcp/authoring/update.js +97 -0
- package/dist/mcp/authoring/update.js.map +1 -0
- package/dist/mcp/authoring/upload.d.ts +3 -0
- package/dist/mcp/authoring/upload.d.ts.map +1 -0
- package/dist/mcp/authoring/upload.js +71 -0
- package/dist/mcp/authoring/upload.js.map +1 -0
- package/dist/mcp/call-limit.d.ts +18 -0
- package/dist/mcp/call-limit.d.ts.map +1 -0
- package/dist/mcp/call-limit.js +24 -0
- package/dist/mcp/call-limit.js.map +1 -0
- package/dist/mcp/endpoint.d.ts +7 -0
- package/dist/mcp/endpoint.d.ts.map +1 -0
- package/dist/mcp/endpoint.js +161 -0
- package/dist/mcp/endpoint.js.map +1 -0
- package/dist/mcp/inspect/inbox.d.ts +2 -0
- package/dist/mcp/inspect/inbox.d.ts.map +1 -0
- package/dist/mcp/inspect/inbox.js +123 -0
- package/dist/mcp/inspect/inbox.js.map +1 -0
- package/dist/mcp/inspect/paging.d.ts +71 -0
- package/dist/mcp/inspect/paging.d.ts.map +1 -0
- package/dist/mcp/inspect/paging.js +59 -0
- package/dist/mcp/inspect/paging.js.map +1 -0
- package/dist/mcp/inspect/post.d.ts +9 -0
- package/dist/mcp/inspect/post.d.ts.map +1 -0
- package/dist/mcp/inspect/post.js +161 -0
- package/dist/mcp/inspect/post.js.map +1 -0
- package/dist/mcp/inspect/records.d.ts +4 -0
- package/dist/mcp/inspect/records.d.ts.map +1 -0
- package/dist/mcp/inspect/records.js +213 -0
- package/dist/mcp/inspect/records.js.map +1 -0
- package/dist/mcp/inspect/remote.d.ts +85 -0
- package/dist/mcp/inspect/remote.d.ts.map +1 -0
- package/dist/mcp/inspect/remote.js +274 -0
- package/dist/mcp/inspect/remote.js.map +1 -0
- package/dist/mcp/inspect/schemas.d.ts +70 -0
- package/dist/mcp/inspect/schemas.d.ts.map +1 -0
- package/dist/mcp/inspect/schemas.js +46 -0
- package/dist/mcp/inspect/schemas.js.map +1 -0
- package/dist/mcp/inspect/status.d.ts +2 -0
- package/dist/mcp/inspect/status.d.ts.map +1 -0
- package/dist/mcp/inspect/status.js +194 -0
- package/dist/mcp/inspect/status.js.map +1 -0
- package/dist/mcp/inspect/webmentions.d.ts +2 -0
- package/dist/mcp/inspect/webmentions.d.ts.map +1 -0
- package/dist/mcp/inspect/webmentions.js +130 -0
- package/dist/mcp/inspect/webmentions.js.map +1 -0
- package/dist/mcp/plugin-tools.d.ts +4 -0
- package/dist/mcp/plugin-tools.d.ts.map +1 -0
- package/dist/mcp/plugin-tools.js +29 -0
- package/dist/mcp/plugin-tools.js.map +1 -0
- package/dist/mcp/protocol.d.ts +67 -0
- package/dist/mcp/protocol.d.ts.map +1 -0
- package/dist/mcp/protocol.js +130 -0
- package/dist/mcp/protocol.js.map +1 -0
- package/dist/mcp/repair/refresh.d.ts +2 -0
- package/dist/mcp/repair/refresh.d.ts.map +1 -0
- package/dist/mcp/repair/refresh.js +111 -0
- package/dist/mcp/repair/refresh.js.map +1 -0
- package/dist/mcp/repair/resend.d.ts +2 -0
- package/dist/mcp/repair/resend.d.ts.map +1 -0
- package/dist/mcp/repair/resend.js +46 -0
- package/dist/mcp/repair/resend.js.map +1 -0
- package/dist/mcp/repair/retry.d.ts +2 -0
- package/dist/mcp/repair/retry.d.ts.map +1 -0
- package/dist/mcp/repair/retry.js +91 -0
- package/dist/mcp/repair/retry.js.map +1 -0
- package/dist/mcp/repair/schemas.d.ts +30 -0
- package/dist/mcp/repair/schemas.d.ts.map +1 -0
- package/dist/mcp/repair/schemas.js +26 -0
- package/dist/mcp/repair/schemas.js.map +1 -0
- package/dist/mcp/tools.d.ts +84 -0
- package/dist/mcp/tools.d.ts.map +1 -0
- package/dist/mcp/tools.js +102 -0
- package/dist/mcp/tools.js.map +1 -0
- package/dist/mcp/whoami.d.ts +2 -0
- package/dist/mcp/whoami.d.ts.map +1 -0
- package/dist/mcp/whoami.js +40 -0
- package/dist/mcp/whoami.js.map +1 -0
- package/dist/micropub/endpoint.d.ts.map +1 -1
- package/dist/micropub/endpoint.js +2 -2
- package/dist/micropub/endpoint.js.map +1 -1
- package/dist/plugin.d.ts +77 -1
- package/dist/plugin.d.ts.map +1 -1
- package/dist/plugin.js +16 -1
- package/dist/plugin.js.map +1 -1
- package/dist/plugins/registry.d.ts +7 -1
- package/dist/plugins/registry.d.ts.map +1 -1
- package/dist/plugins/registry.js +23 -5
- package/dist/plugins/registry.js.map +1 -1
- package/dist/store/admin-store.d.ts +3 -3
- package/dist/store/admin-store.d.ts.map +1 -1
- package/dist/store/admin-store.js.map +1 -1
- package/dist/store/deliveries.d.ts +35 -4
- package/dist/store/deliveries.d.ts.map +1 -1
- package/dist/store/deliveries.js +64 -2
- package/dist/store/deliveries.js.map +1 -1
- package/dist/store/inbox.d.ts +17 -1
- package/dist/store/inbox.d.ts.map +1 -1
- package/dist/store/inbox.js +35 -0
- package/dist/store/inbox.js.map +1 -1
- package/dist/store/rows.d.ts +5 -0
- package/dist/store/rows.d.ts.map +1 -1
- package/dist/store/rows.js.map +1 -1
- package/dist/util/json-schema.d.ts +68 -0
- package/dist/util/json-schema.d.ts.map +1 -0
- package/dist/util/json-schema.js +60 -0
- package/dist/util/json-schema.js.map +1 -0
- package/dist/util/package-version.d.ts +2 -0
- package/dist/util/package-version.d.ts.map +1 -0
- package/dist/util/package-version.js +3 -0
- package/dist/util/package-version.js.map +1 -0
- package/dist/web/env.d.ts +2 -0
- package/dist/web/env.d.ts.map +1 -1
- package/dist/web/federation-routes.d.ts +1 -0
- package/dist/web/federation-routes.d.ts.map +1 -1
- package/dist/web/federation-routes.js +10 -7
- package/dist/web/federation-routes.js.map +1 -1
- package/dist/web/indieauth-activity-log.d.ts +23 -5
- package/dist/web/indieauth-activity-log.d.ts.map +1 -1
- package/dist/web/indieauth-activity-log.js +62 -23
- package/dist/web/indieauth-activity-log.js.map +1 -1
- package/dist/web/indieauth-bearer.d.ts +8 -1
- package/dist/web/indieauth-bearer.d.ts.map +1 -1
- package/dist/web/indieauth-bearer.js +24 -18
- package/dist/web/indieauth-bearer.js.map +1 -1
- package/dist/web/indieauth-discovery.d.ts +11 -2
- package/dist/web/indieauth-discovery.d.ts.map +1 -1
- package/dist/web/indieauth-discovery.js +22 -4
- package/dist/web/indieauth-discovery.js.map +1 -1
- package/dist/web/llms.d.ts.map +1 -1
- package/dist/web/llms.js +2 -0
- package/dist/web/llms.js.map +1 -1
- package/dist/web/routes.d.ts.map +1 -1
- package/dist/web/routes.js +4 -3
- package/dist/web/routes.js.map +1 -1
- package/dist/webmention/fetch-public.d.ts +9 -0
- package/dist/webmention/fetch-public.d.ts.map +1 -1
- package/dist/webmention/fetch-public.js +6 -4
- package/dist/webmention/fetch-public.js.map +1 -1
- package/package.json +3 -1
- package/dist/micropub/create.d.ts.map +0 -1
- package/dist/micropub/create.js.map +0 -1
- package/dist/micropub/update.d.ts.map +0 -1
- package/dist/micropub/update.js.map +0 -1
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { formFor } from '../../content/document-form.js';
|
|
2
|
+
import { POST_KIND } from '../../content/document-kind.js';
|
|
3
|
+
import { postLocations } from '../../content/locations.js';
|
|
4
|
+
import { isTrashedPath } from '../../content/store.js';
|
|
5
|
+
import { writeDocument } from '../../content/write.js';
|
|
6
|
+
import { absoluteUrl } from '../../util/url.js';
|
|
7
|
+
import { documentSiteFrom } from '../../web/document-site.js';
|
|
8
|
+
import { POST_INPUT } from '../inspect/post.js';
|
|
9
|
+
import { defineTool, isRefused, refused } from '../tools.js';
|
|
10
|
+
import { ownPost, unsaved } from './shared.js';
|
|
11
|
+
export const publishPost = defineTool({
|
|
12
|
+
name: 'publish_post',
|
|
13
|
+
title: 'Publish a draft',
|
|
14
|
+
description: 'Publish one of your drafts as it reads now, as the editor’s Publish button does: the post goes public, federates a Create to followers and sends its webmentions. A post that is already published is left as it is.',
|
|
15
|
+
scope: 'publish',
|
|
16
|
+
annotations: {
|
|
17
|
+
readOnlyHint: false,
|
|
18
|
+
destructiveHint: true,
|
|
19
|
+
idempotentHint: true,
|
|
20
|
+
openWorldHint: true,
|
|
21
|
+
},
|
|
22
|
+
inputSchema: {
|
|
23
|
+
type: 'object',
|
|
24
|
+
properties: { post: POST_INPUT },
|
|
25
|
+
required: ['post'],
|
|
26
|
+
additionalProperties: false,
|
|
27
|
+
},
|
|
28
|
+
outputSchema: {
|
|
29
|
+
type: 'object',
|
|
30
|
+
properties: {
|
|
31
|
+
url: { type: 'string' },
|
|
32
|
+
slug: { type: 'string' },
|
|
33
|
+
alreadyPublished: {
|
|
34
|
+
type: 'boolean',
|
|
35
|
+
description: 'true when the post was published before this call, which changed nothing.',
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
required: ['url', 'slug', 'alreadyPublished'],
|
|
39
|
+
},
|
|
40
|
+
run: async (args, { user, site }) => {
|
|
41
|
+
const document = ownPost(site, user, args.post);
|
|
42
|
+
if (isRefused(document))
|
|
43
|
+
return document;
|
|
44
|
+
const { baseUrl, dataDir } = site.config;
|
|
45
|
+
if (isTrashedPath(document.path)) {
|
|
46
|
+
return refused(`${document.slug} is in the trash. Restore it in the admin first.`);
|
|
47
|
+
}
|
|
48
|
+
if (!document.draft) {
|
|
49
|
+
const url = absoluteUrl(document.permalink, baseUrl);
|
|
50
|
+
return {
|
|
51
|
+
ok: true,
|
|
52
|
+
summary: `${document.slug} was already published at ${url}; nothing changed.`,
|
|
53
|
+
structured: { url, slug: document.slug, alreadyPublished: true },
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
const timezone = site.siteAtRequestStart.timezone;
|
|
57
|
+
const form = formFor(POST_KIND, document, timezone, postLocations(dataDir).read(document.permalink));
|
|
58
|
+
const written = await writeDocument(documentSiteFrom(site, user.username), {
|
|
59
|
+
kind: POST_KIND,
|
|
60
|
+
document,
|
|
61
|
+
form,
|
|
62
|
+
draft: false,
|
|
63
|
+
});
|
|
64
|
+
if (written.outcome !== 'saved')
|
|
65
|
+
return unsaved(written, document.slug);
|
|
66
|
+
const { saved } = written;
|
|
67
|
+
const url = absoluteUrl(saved.permalink, baseUrl);
|
|
68
|
+
return {
|
|
69
|
+
ok: true,
|
|
70
|
+
summary: `Published ${saved.slug} at ${url}.`,
|
|
71
|
+
structured: { url, slug: saved.slug, alreadyPublished: false },
|
|
72
|
+
};
|
|
73
|
+
},
|
|
74
|
+
});
|
|
75
|
+
//# sourceMappingURL=publish.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"publish.js","sourceRoot":"","sources":["../../../src/mcp/authoring/publish.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,gCAAgC,CAAC;AACzD,OAAO,EAAE,SAAS,EAAE,MAAM,gCAAgC,CAAC;AAC3D,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAC9D,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAC7D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C,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Document } from '../../content/document.ts';
|
|
2
|
+
import type { WriteOutcome } from '../../content/write.ts';
|
|
3
|
+
import type { SourceSite } from '../../content/micropub-update.ts';
|
|
4
|
+
import type { User } from '../../site/users.ts';
|
|
5
|
+
import type { Refused, ToolSite } from '../tools.ts';
|
|
6
|
+
export declare function ownPost(site: ToolSite, user: User, reference: string): Document | Refused;
|
|
7
|
+
export declare function sourceSite(site: ToolSite): SourceSite;
|
|
8
|
+
export declare function unsaved(written: Exclude<WriteOutcome, {
|
|
9
|
+
outcome: 'saved';
|
|
10
|
+
}>, slug: string): Refused;
|
|
11
|
+
export declare const POST_WRITTEN: {
|
|
12
|
+
readonly url: {
|
|
13
|
+
readonly type: 'string';
|
|
14
|
+
readonly description: 'The post’s address.';
|
|
15
|
+
};
|
|
16
|
+
readonly slug: {
|
|
17
|
+
readonly type: 'string';
|
|
18
|
+
};
|
|
19
|
+
readonly draft: {
|
|
20
|
+
readonly type: 'boolean';
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
//# sourceMappingURL=shared.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../../../src/mcp/authoring/shared.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AAG1D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kCAAkC,CAAC;AAEnE,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAGhD,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAErD,wBAAgB,OAAO,CAAC,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,GAAG,QAAQ,GAAG,OAAO,CAQzF;AAED,wBAAgB,UAAU,CAAC,IAAI,EAAE,QAAQ,GAAG,UAAU,CAOrD;AAED,wBAAgB,OAAO,CACrB,OAAO,EAAE,OAAO,CAAC,YAAY,EAAE;IAAE,OAAO,EAAE,OAAO,CAAA;CAAE,CAAC,EACpD,IAAI,EAAE,MAAM,GACX,OAAO,CAMT;AAED,eAAO,MAAM,YAAY;aACvB,GAAG;iBAAI,IAAI,EAAE,QAAQ;iBAAE,WAAW,EAAE,qBAAqB;;aACzD,IAAI;iBAAI,IAAI,EAAE,QAAQ;;aACtB,KAAK;iBAAI,IAAI,EAAE,SAAS;;CAChB,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { userForAuthor } from '../../content/authors.js';
|
|
2
|
+
import { keptProperties } from '../../content/kept-properties.js';
|
|
3
|
+
import { postLocations } from '../../content/locations.js';
|
|
4
|
+
import { listUsers } from '../../site/users.js';
|
|
5
|
+
import { findPost } from '../inspect/post.js';
|
|
6
|
+
import { isRefused, refused } from '../tools.js';
|
|
7
|
+
export function ownPost(site, user, reference) {
|
|
8
|
+
const document = findPost(site, reference);
|
|
9
|
+
if (isRefused(document))
|
|
10
|
+
return document;
|
|
11
|
+
const author = userForAuthor(listUsers(site.config.dataDir), document.author);
|
|
12
|
+
if (author !== undefined && author.id !== user.id) {
|
|
13
|
+
return refused(`${reference} is not your post.`);
|
|
14
|
+
}
|
|
15
|
+
return document;
|
|
16
|
+
}
|
|
17
|
+
export function sourceSite(site) {
|
|
18
|
+
return {
|
|
19
|
+
baseUrl: site.config.baseUrl,
|
|
20
|
+
targets: site.siteRecords.syndicationTargets(),
|
|
21
|
+
locations: postLocations(site.config.dataDir),
|
|
22
|
+
kept: keptProperties(site.config.dataDir),
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
export function unsaved(written, slug) {
|
|
26
|
+
return written.outcome === 'refused'
|
|
27
|
+
? refused(written.message)
|
|
28
|
+
: refused(`${slug} changed since it was read. Read it again with get_post_source and update from what it holds now.`);
|
|
29
|
+
}
|
|
30
|
+
export const POST_WRITTEN = {
|
|
31
|
+
url: { type: 'string', description: 'The post’s address.' },
|
|
32
|
+
slug: { type: 'string' },
|
|
33
|
+
draft: { type: 'boolean' },
|
|
34
|
+
};
|
|
35
|
+
//# sourceMappingURL=shared.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shared.js","sourceRoot":"","sources":["../../../src/mcp/authoring/shared.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAEzD,OAAO,EAAE,cAAc,EAAE,MAAM,kCAAkC,CAAC;AAClE,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAG3D,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAEhD,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAGjD,MAAM,UAAU,OAAO,CAAC,IAAc,EAAE,IAAU,EAAE,SAAiB;IACnE,MAAM,QAAQ,GAAG,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;IAC3C,IAAI,SAAS,CAAC,QAAQ,CAAC;QAAE,OAAO,QAAQ,CAAC;IACzC,MAAM,MAAM,GAAG,aAAa,CAAC,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;IAC9E,IAAI,MAAM,KAAK,SAAS,IAAI,MAAM,CAAC,EAAE,KAAK,IAAI,CAAC,EAAE,EAAE,CAAC;QAClD,OAAO,OAAO,CAAC,GAAG,SAAS,oBAAoB,CAAC,CAAC;IACnD,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,IAAc;IACvC,OAAO;QACL,OAAO,EAAE,IAAI,CAAC,MAAM,CAAC,OAAO;QAC5B,OAAO,EAAE,IAAI,CAAC,WAAW,CAAC,kBAAkB,EAAE;QAC9C,SAAS,EAAE,aAAa,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC;QAC7C,IAAI,EAAE,cAAc,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC;KAC1C,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,OAAO,CACrB,OAAoD,EACpD,IAAY;IAEZ,OAAO,OAAO,CAAC,OAAO,KAAK,SAAS;QAClC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC;QAC1B,CAAC,CAAC,OAAO,CACL,GAAG,IAAI,mGAAmG,CAC3G,CAAC;AACR,CAAC;AAED,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,GAAG,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,qBAAqB,EAAE;IAC3D,IAAI,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;IACxB,KAAK,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE;CAClB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"source.d.ts","sourceRoot":"","sources":["../../../src/mcp/authoring/source.ts"],"names":[],"mappings":"AAOA,eAAO,MAAM,aAAa,+BAwCxB,CAAC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { micropubType, sourceProperties } from '../../content/micropub-update.js';
|
|
2
|
+
import { absoluteUrl } from '../../util/url.js';
|
|
3
|
+
import { POST_INPUT } from '../inspect/post.js';
|
|
4
|
+
import { ANY_OBJECT, READ_ONLY } from '../inspect/schemas.js';
|
|
5
|
+
import { defineTool, isRefused } from '../tools.js';
|
|
6
|
+
import { ownPost, sourceSite } from './shared.js';
|
|
7
|
+
export const getPostSource = defineTool({
|
|
8
|
+
name: 'get_post_source',
|
|
9
|
+
title: 'Read a post’s source',
|
|
10
|
+
description: 'One of your posts as Micropub q=source answers it: its type and its properties, each a list of values, draft or published. Returns the hash update_post needs, so an edit fails rather than overwrites when the post changed in between.',
|
|
11
|
+
scope: 'update',
|
|
12
|
+
annotations: READ_ONLY,
|
|
13
|
+
inputSchema: {
|
|
14
|
+
type: 'object',
|
|
15
|
+
properties: { post: POST_INPUT },
|
|
16
|
+
required: ['post'],
|
|
17
|
+
additionalProperties: false,
|
|
18
|
+
},
|
|
19
|
+
outputSchema: {
|
|
20
|
+
type: 'object',
|
|
21
|
+
properties: {
|
|
22
|
+
url: { type: 'string' },
|
|
23
|
+
slug: { type: 'string' },
|
|
24
|
+
type: { type: 'string', description: 'h-entry, h-event or h-review.' },
|
|
25
|
+
properties: { ...ANY_OBJECT, description: 'Each property as a list of values.' },
|
|
26
|
+
hash: { type: 'string', description: 'The version read. Pass it to update_post.' },
|
|
27
|
+
},
|
|
28
|
+
required: ['url', 'slug', 'type', 'properties', 'hash'],
|
|
29
|
+
},
|
|
30
|
+
run: (args, { user, site }) => {
|
|
31
|
+
const document = ownPost(site, user, args.post);
|
|
32
|
+
if (isRefused(document))
|
|
33
|
+
return Promise.resolve(document);
|
|
34
|
+
const url = absoluteUrl(document.permalink, site.config.baseUrl);
|
|
35
|
+
return Promise.resolve({
|
|
36
|
+
ok: true,
|
|
37
|
+
summary: `${document.slug} is ${document.draft ? 'a draft' : 'published'} at ${url}.`,
|
|
38
|
+
structured: {
|
|
39
|
+
url,
|
|
40
|
+
slug: document.slug,
|
|
41
|
+
type: micropubType(document),
|
|
42
|
+
properties: sourceProperties(document, sourceSite(site)),
|
|
43
|
+
hash: document.hash,
|
|
44
|
+
},
|
|
45
|
+
});
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
//# sourceMappingURL=source.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"source.js","sourceRoot":"","sources":["../../../src/mcp/authoring/source.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AAClF,OAA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AAC,IAAI,CAAC,CAAC;QAChD,IAAI,SAAS,CAAC,QAAQ,CAAC;YAAE,OAAO,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;QAC1D,MAAM,GAAG,GAAG,WAAW,CAAC,QAAQ,CAAC,SAAS,EAAE,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QACjE,OAAO,OAAO,CAAC,OAAO,CAAC;YACrB,EAAE,EAAE,IAAI;YACR,OAAO,EAAE,GAAG,QAAQ,CAAC,IAAI,OAAO,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,WAAW,OAAO,GAAG,GAAG;YACrF,UAAU,EAAE;gBACV,GAAG;gBACH,IAAI,EAAE,QAAQ,CAAC,IAAI;gBACnB,IAAI,EAAE,YAAY,CAAC,QAAQ,CAAC;gBAC5B,UAAU,EAAE,gBAAgB,CAAC,QAAQ,EAAE,UAAU,CAAC,IAAI,CAAC,CAAC;gBACxD,IAAI,EAAE,QAAQ,CAAC,IAAI;aACpB;SACF,CAAC,CAAC;IACL,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"update.d.ts","sourceRoot":"","sources":["../../../src/mcp/authoring/update.ts"],"names":[],"mappings":"AAWA,eAAO,MAAM,UAAU,+BAoFrB,CAAC"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { POST_KIND } from '../../content/document-kind.js';
|
|
2
|
+
import { writeDocument } from '../../content/write.js';
|
|
3
|
+
import { parseChanges, updateForm } from '../../content/micropub-update.js';
|
|
4
|
+
import { absoluteUrl } from '../../util/url.js';
|
|
5
|
+
import { documentSiteFrom } from '../../web/document-site.js';
|
|
6
|
+
import { POST_INPUT } from '../inspect/post.js';
|
|
7
|
+
import { ANY_OBJECT } from '../inspect/schemas.js';
|
|
8
|
+
import { defineTool, isRefused, refused } from '../tools.js';
|
|
9
|
+
import { ownPost, POST_WRITTEN, sourceSite, unsaved } from './shared.js';
|
|
10
|
+
export const updatePost = defineTool({
|
|
11
|
+
name: 'update_post',
|
|
12
|
+
title: 'Edit a post',
|
|
13
|
+
description: 'Change named properties of one of your posts, as a Micropub update does, leaving every other property as it is. Read the post with get_post_source first and pass its hash: when the post changed since, nothing is written. Changing a published post, or setting post-status to published, publishes: the post is stamped updated, federates an Update and sends webmentions, so it needs the publish scope as well.',
|
|
14
|
+
scope: 'update',
|
|
15
|
+
annotations: {
|
|
16
|
+
readOnlyHint: false,
|
|
17
|
+
destructiveHint: true,
|
|
18
|
+
idempotentHint: false,
|
|
19
|
+
openWorldHint: true,
|
|
20
|
+
},
|
|
21
|
+
inputSchema: {
|
|
22
|
+
type: 'object',
|
|
23
|
+
properties: {
|
|
24
|
+
post: POST_INPUT,
|
|
25
|
+
hash: { type: 'string', description: 'The hash get_post_source returned.' },
|
|
26
|
+
replace: {
|
|
27
|
+
...ANY_OBJECT,
|
|
28
|
+
description: 'Properties whose values are replaced: {"content": ["New text"]}.',
|
|
29
|
+
},
|
|
30
|
+
add: { ...ANY_OBJECT, description: 'Values added to properties: {"category": ["new"]}.' },
|
|
31
|
+
delete: {
|
|
32
|
+
type: 'array',
|
|
33
|
+
items: { type: 'string' },
|
|
34
|
+
description: 'Properties taken away entirely: ["summary"].',
|
|
35
|
+
},
|
|
36
|
+
deleteValues: {
|
|
37
|
+
...ANY_OBJECT,
|
|
38
|
+
description: 'Values taken out of properties: {"category": ["old"]}.',
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
required: ['post', 'hash'],
|
|
42
|
+
additionalProperties: false,
|
|
43
|
+
},
|
|
44
|
+
outputSchema: {
|
|
45
|
+
type: 'object',
|
|
46
|
+
properties: POST_WRITTEN,
|
|
47
|
+
required: ['url', 'slug', 'draft'],
|
|
48
|
+
},
|
|
49
|
+
run: async (args, { user, token, site }) => {
|
|
50
|
+
const document = ownPost(site, user, args.post);
|
|
51
|
+
if (isRefused(document))
|
|
52
|
+
return document;
|
|
53
|
+
const parsed = parseChanges({
|
|
54
|
+
replace: args.replace,
|
|
55
|
+
add: args.add,
|
|
56
|
+
delete: args.deleteValues,
|
|
57
|
+
});
|
|
58
|
+
if ('error' in parsed)
|
|
59
|
+
return refused(parsed.error);
|
|
60
|
+
const removed = (args.delete ?? []).map((property) => ({
|
|
61
|
+
op: 'delete',
|
|
62
|
+
property,
|
|
63
|
+
values: undefined,
|
|
64
|
+
}));
|
|
65
|
+
const changes = [...parsed, ...removed];
|
|
66
|
+
if (changes.length === 0)
|
|
67
|
+
return refused('Name a property to replace, add or delete.');
|
|
68
|
+
const { store, config } = site;
|
|
69
|
+
const updated = updateForm(document, changes, {
|
|
70
|
+
...sourceSite(site),
|
|
71
|
+
timezone: site.siteAtRequestStart.timezone,
|
|
72
|
+
now: store.now(),
|
|
73
|
+
});
|
|
74
|
+
if ('errors' in updated)
|
|
75
|
+
return refused(updated.errors.join(' '));
|
|
76
|
+
const publishes = !document.draft || !updated.draft;
|
|
77
|
+
if (publishes && !token.scopes.includes('publish'))
|
|
78
|
+
return { needsScope: 'publish' };
|
|
79
|
+
const written = await writeDocument(documentSiteFrom(site, user.username), {
|
|
80
|
+
kind: POST_KIND,
|
|
81
|
+
document,
|
|
82
|
+
form: { ...updated.form, hash: args.hash },
|
|
83
|
+
draft: updated.draft,
|
|
84
|
+
keptProperties: updated.keptProperties,
|
|
85
|
+
});
|
|
86
|
+
if (written.outcome !== 'saved')
|
|
87
|
+
return unsaved(written, document.slug);
|
|
88
|
+
const { saved } = written;
|
|
89
|
+
const url = absoluteUrl(saved.permalink, config.baseUrl);
|
|
90
|
+
return {
|
|
91
|
+
ok: true,
|
|
92
|
+
summary: `Updated ${saved.slug} at ${url}${saved.draft ? ', still a draft' : ''}.`,
|
|
93
|
+
structured: { url, slug: saved.slug, draft: saved.draft },
|
|
94
|
+
};
|
|
95
|
+
},
|
|
96
|
+
});
|
|
97
|
+
//# sourceMappingURL=update.js.map
|
|
@@ -0,0 +1 @@
|
|
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O,GAAG,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,iBAAiB,CAAC,CAAC,CAAC,EAAE,GAAG;YAClF,UAAU,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE;SAC1D,CAAC;IACJ,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"upload.d.ts","sourceRoot":"","sources":["../../../src/mcp/authoring/upload.ts"],"names":[],"mappings":"AAcA,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAElD;AAED,eAAO,MAAM,WAAW,+BA+DtB,CAAC"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { writeAltText } from '../../content/alt-text.js';
|
|
2
|
+
import { uploadPath } from '../../content/image-tags.js';
|
|
3
|
+
import { largestUploadLimit, refusedUpload, storeUpload, tooLargeMessage, } from '../../media/uploads.js';
|
|
4
|
+
import { nullable } from '../../util/json-schema.js';
|
|
5
|
+
import { absoluteUrl } from '../../util/url.js';
|
|
6
|
+
import { defineTool, refused } from '../tools.js';
|
|
7
|
+
const BASE64 = /^[A-Za-z0-9+/]*={0,2}$/;
|
|
8
|
+
export function base64Length(bytes) {
|
|
9
|
+
return Math.ceil(bytes / 3) * 4;
|
|
10
|
+
}
|
|
11
|
+
export const uploadMedia = defineTool({
|
|
12
|
+
name: 'upload_media',
|
|
13
|
+
title: 'Upload media',
|
|
14
|
+
description: 'Store a file in the media library, under the same rules as the admin’s uploads and the Micropub media endpoint, with its alt text. Returns the file’s address, to use as a photo property or in a post’s content.',
|
|
15
|
+
scope: 'media',
|
|
16
|
+
annotations: {
|
|
17
|
+
readOnlyHint: false,
|
|
18
|
+
destructiveHint: false,
|
|
19
|
+
idempotentHint: false,
|
|
20
|
+
openWorldHint: false,
|
|
21
|
+
},
|
|
22
|
+
inputSchema: {
|
|
23
|
+
type: 'object',
|
|
24
|
+
properties: {
|
|
25
|
+
filename: {
|
|
26
|
+
type: 'string',
|
|
27
|
+
description: 'The file’s name with its extension, such as sunset.jpg. The extension decides what the file is.',
|
|
28
|
+
},
|
|
29
|
+
data: { type: 'string', description: 'The file’s bytes, base64-encoded.' },
|
|
30
|
+
alt: {
|
|
31
|
+
type: 'string',
|
|
32
|
+
description: 'What the image shows, for somebody who cannot see it.',
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
required: ['filename', 'data'],
|
|
36
|
+
additionalProperties: false,
|
|
37
|
+
},
|
|
38
|
+
outputSchema: {
|
|
39
|
+
type: 'object',
|
|
40
|
+
properties: {
|
|
41
|
+
url: { type: 'string', description: 'The file’s address.' },
|
|
42
|
+
kind: { type: 'string', description: 'image, audio, video or document.' },
|
|
43
|
+
alt: nullable({ type: 'string' }),
|
|
44
|
+
},
|
|
45
|
+
required: ['url', 'kind', 'alt'],
|
|
46
|
+
},
|
|
47
|
+
run: async (args, { site }) => {
|
|
48
|
+
const { config } = site;
|
|
49
|
+
const limit = largestUploadLimit(config);
|
|
50
|
+
const data = args.data.replace(/\s+/g, '');
|
|
51
|
+
if (data.length > base64Length(limit))
|
|
52
|
+
return refused(tooLargeMessage(limit));
|
|
53
|
+
if (!BASE64.test(data) || data.length % 4 === 1)
|
|
54
|
+
return refused('data is not base64.');
|
|
55
|
+
const stored = await storeUpload(new File([Buffer.from(data, 'base64')], args.filename), config);
|
|
56
|
+
if (refusedUpload(stored))
|
|
57
|
+
return refused(stored.error);
|
|
58
|
+
const alt = args.alt?.trim().replace(/\s+/g, ' ') ?? '';
|
|
59
|
+
const source = uploadPath(stored.url);
|
|
60
|
+
if (alt !== '' && source !== undefined) {
|
|
61
|
+
await writeAltText(config.contentDir, source, { kind: 'described', text: alt });
|
|
62
|
+
}
|
|
63
|
+
const url = absoluteUrl(stored.url, config.baseUrl);
|
|
64
|
+
return {
|
|
65
|
+
ok: true,
|
|
66
|
+
summary: `Stored ${url}${alt === '' ? ' with no alt text' : ''}.`,
|
|
67
|
+
structured: { url, kind: stored.media.kind, alt: alt === '' ? null : alt },
|
|
68
|
+
};
|
|
69
|
+
},
|
|
70
|
+
});
|
|
71
|
+
//# sourceMappingURL=upload.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"upload.js","sourceRoot":"","sources":["../../../src/mcp/authoring/upload.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzD,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AACzD,OAAO,EACL,kBAAkB,EAClB,aAAa,EACb,WAAW,EACX,eAAe,GAChB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AACrD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAElD,MAAM,MAAM,GAAG,wBAAwB,CAAC;AAExC,MAAM,UAAU,YAAY,CAAC,KAAa;IACxC,OAAO,IAAI,CAAC,IAAI,CAAC,KAAK,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC;AAClC,CAAC;AAED,MAAM,CAAC,MAAM,WAAW,GAAG,UAAU,CAAC;IACpC,IAAI,EAAE,cAAc;IACpB,KAAK,EAAE,cAAc;IACrB,WAAW,EACT,mNAAmN;IACrN,KAAK,EAAE,OAAO;IACd,WAAW,EAAE;QACX,YAAY,EAAE,KAAK;QACnB,eAAe,EAAE,KAAK;QACtB,cAAc,EAAE,KAAK;QACrB,aAAa,EAAE,KAAK;KACrB;IACD,WAAW,EAAE;QACX,IAAI,EAAE,QAAQ;QACd,UAAU,EAAE;YACV,QAAQ,EAAE;gBACR,IAAI,EAAE,QAAQ;gBACd,WAAW,EACT,iGAAiG;aACpG;YACD,IAAI,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,mCAA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P,CAAC;QACF,IAAI,aAAa,CAAC,MAAM,CAAC;YAAE,OAAO,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAExD,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,IAAI,EAAE,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,IAAI,EAAE,CAAC;QACxD,MAAM,MAAM,GAAG,UAAU,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QACtC,IAAI,GAAG,KAAK,EAAE,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;YACvC,MAAM,YAAY,CAAC,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,CAAC;QAClF,CAAC;QACD,MAAM,GAAG,GAAG,WAAW,CAAC,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC;QACpD,OAAO;YACL,EAAE,EAAE,IAAI;YACR,OAAO,EAAE,UAAU,GAAG,GAAG,GAAG,KAAK,EAAE,CAAC,CAAC,CAAC,mBAAmB,CAAC,CAAC,CAAC,EAAE,GAAG;YACjE,UAAU,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE,GAAG,EAAE,GAAG,KAAK,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,EAAE;SAC3E,CAAC;IACJ,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Clock } from '../util/clock.ts';
|
|
2
|
+
export type LimitDecision = {
|
|
3
|
+
readonly kind: 'allowed';
|
|
4
|
+
} | {
|
|
5
|
+
readonly kind: 'refused';
|
|
6
|
+
readonly retryAfter: number;
|
|
7
|
+
readonly first: boolean;
|
|
8
|
+
};
|
|
9
|
+
export interface CallLimit {
|
|
10
|
+
take(key: string): LimitDecision;
|
|
11
|
+
}
|
|
12
|
+
export interface CallLimitOptions {
|
|
13
|
+
readonly calls: number;
|
|
14
|
+
readonly windowSeconds: number;
|
|
15
|
+
readonly now: Clock;
|
|
16
|
+
}
|
|
17
|
+
export declare function createCallLimit(options: CallLimitOptions): CallLimit;
|
|
18
|
+
//# sourceMappingURL=call-limit.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"call-limit.d.ts","sourceRoot":"","sources":["../../src/mcp/call-limit.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAE9C,MAAM,MAAM,aAAa,GACrB;IAAE,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAA;CAAE,GAC5B;IAAE,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IAAC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAA;CAAE,CAAC;AAEvF,MAAM,WAAW,SAAS;IACxB,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,aAAa,CAAC;CAClC;AAED,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,GAAG,EAAE,KAAK,CAAC;CACrB;AAED,wBAAgB,eAAe,CAAC,OAAO,EAAE,gBAAgB,GAAG,SAAS,CAqBpE"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export function createCallLimit(options) {
|
|
2
|
+
const window = options.windowSeconds * 1000;
|
|
3
|
+
const windows = new Map();
|
|
4
|
+
return {
|
|
5
|
+
take(key) {
|
|
6
|
+
const at = options.now().getTime();
|
|
7
|
+
for (const [each, entry] of windows) {
|
|
8
|
+
if (at >= entry.endsAt)
|
|
9
|
+
windows.delete(each);
|
|
10
|
+
}
|
|
11
|
+
const entry = windows.get(key) ?? { count: 0, endsAt: at + window };
|
|
12
|
+
entry.count += 1;
|
|
13
|
+
windows.set(key, entry);
|
|
14
|
+
if (entry.count <= options.calls)
|
|
15
|
+
return { kind: 'allowed' };
|
|
16
|
+
return {
|
|
17
|
+
kind: 'refused',
|
|
18
|
+
retryAfter: Math.max(1, Math.ceil((entry.endsAt - at) / 1000)),
|
|
19
|
+
first: entry.count === options.calls + 1,
|
|
20
|
+
};
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=call-limit.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"call-limit.js","sourceRoot":"","sources":["../../src/mcp/call-limit.ts"],"names":[],"mappings":"AAgBA,MAAM,UAAU,eAAe,CAAC,OAAyB;IACvD,MAAM,MAAM,GAAG,OAAO,CAAC,aAAa,GAAG,IAAI,CAAC;IAC5C,MAAM,OAAO,GAAG,IAAI,GAAG,EAA6C,CAAC;IAErE,OAAO;QACL,IAAI,CAAC,GAAG;YACN,MAAM,EAAE,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC,OAAO,EAAE,CAAC;YACnC,KAAK,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,OAAO,EAAE,CAAC;gBACpC,IAAI,EAAE,IAAI,KAAK,CAAC,MAAM;oBAAE,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;YAC/C,CAAC;YACD,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC,EAAE,MAAM,EAAE,EAAE,GAAG,MAAM,EAAE,CAAC;YACpE,KAAK,CAAC,KAAK,IAAI,CAAC,CAAC;YACjB,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;YACxB,IAAI,KAAK,CAAC,KAAK,IAAI,OAAO,CAAC,KAAK;gBAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;YAC7D,OAAO;gBACL,IAAI,EAAE,SAAS;gBACf,UAAU,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,MAAM,GAAG,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC;gBAC9D,KAAK,EAAE,KAAK,CAAC,KAAK,KAAK,OAAO,CAAC,KAAK,GAAG,CAAC;aACzC,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Hono } from 'hono';
|
|
2
|
+
import type { ResolvedConfig } from '../config.ts';
|
|
3
|
+
import type { GeekityEnv } from '../web/env.ts';
|
|
4
|
+
export declare const MCP_CALLS_PER_WINDOW = 60;
|
|
5
|
+
export declare const MCP_CALL_WINDOW_SECONDS = 60;
|
|
6
|
+
export declare function mountMcp(app: Hono<GeekityEnv>, config: ResolvedConfig): void;
|
|
7
|
+
//# sourceMappingURL=endpoint.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"endpoint.d.ts","sourceRoot":"","sources":["../../src/mcp/endpoint.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAW,IAAI,EAAqB,MAAM,MAAM,CAAC;AAE7D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AACnD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AA6DhD,eAAO,MAAM,oBAAoB,KAAK,CAAC;AAEvC,eAAO,MAAM,uBAAuB,KAAK,CAAC;AAE1C,wBAAgB,QAAQ,CAAC,GAAG,EAAE,IAAI,CAAC,UAAU,CAAC,EAAE,MAAM,EAAE,cAAc,GAAG,IAAI,CA0F5E"}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import { bearerChallenge, requireBearer } from '../web/indieauth-bearer.js';
|
|
2
|
+
import { MCP_PATH, MCP_RESOURCE_METADATA_PATH, MCP_SERVER_CARD_PATH, } from '../web/indieauth-discovery.js';
|
|
3
|
+
import { largestUploadLimit, UPLOAD_ENVELOPE_BYTES } from '../media/uploads.js';
|
|
4
|
+
import { PACKAGE_VERSION } from '../util/package-version.js';
|
|
5
|
+
import { readWithin } from '../webmention/fetch-public.js';
|
|
6
|
+
import { failure, isSupportedVersion, JSON_RPC_ERRORS, LATEST_PROTOCOL_VERSION, reply, SERVER_CAPABILITIES, } from './protocol.js';
|
|
7
|
+
import { auditToolCall } from './audit.js';
|
|
8
|
+
import { createCallLimit } from './call-limit.js';
|
|
9
|
+
import { createToolRegistry } from './tools.js';
|
|
10
|
+
import { activePluginTools } from './plugin-tools.js';
|
|
11
|
+
import { whoami } from './whoami.js';
|
|
12
|
+
import { createDraft } from './authoring/create.js';
|
|
13
|
+
import { publishPost } from './authoring/publish.js';
|
|
14
|
+
import { getPostSource } from './authoring/source.js';
|
|
15
|
+
import { updatePost } from './authoring/update.js';
|
|
16
|
+
import { base64Length, uploadMedia } from './authoring/upload.js';
|
|
17
|
+
import { inboxSearch } from './inspect/inbox.js';
|
|
18
|
+
import { postFederation } from './inspect/post.js';
|
|
19
|
+
import { followers, quoteApprovals, relays } from './inspect/records.js';
|
|
20
|
+
import { remoteLookup } from './inspect/remote.js';
|
|
21
|
+
import { federationStatus } from './inspect/status.js';
|
|
22
|
+
import { webmentions } from './inspect/webmentions.js';
|
|
23
|
+
import { refreshActor } from './repair/refresh.js';
|
|
24
|
+
import { resendPost } from './repair/resend.js';
|
|
25
|
+
import { retryDeliveries } from './repair/retry.js';
|
|
26
|
+
const CORE_TOOLS = [
|
|
27
|
+
whoami,
|
|
28
|
+
federationStatus,
|
|
29
|
+
inboxSearch,
|
|
30
|
+
postFederation,
|
|
31
|
+
followers,
|
|
32
|
+
relays,
|
|
33
|
+
quoteApprovals,
|
|
34
|
+
webmentions,
|
|
35
|
+
remoteLookup,
|
|
36
|
+
resendPost,
|
|
37
|
+
retryDeliveries,
|
|
38
|
+
refreshActor,
|
|
39
|
+
createDraft,
|
|
40
|
+
getPostSource,
|
|
41
|
+
updatePost,
|
|
42
|
+
publishPost,
|
|
43
|
+
uploadMedia,
|
|
44
|
+
];
|
|
45
|
+
export const MCP_CALLS_PER_WINDOW = 60;
|
|
46
|
+
export const MCP_CALL_WINDOW_SECONDS = 60;
|
|
47
|
+
export function mountMcp(app, config) {
|
|
48
|
+
const guards = {
|
|
49
|
+
limit: createCallLimit({
|
|
50
|
+
calls: MCP_CALLS_PER_WINDOW,
|
|
51
|
+
windowSeconds: MCP_CALL_WINDOW_SECONDS,
|
|
52
|
+
now: config.now,
|
|
53
|
+
}),
|
|
54
|
+
record: (record) => {
|
|
55
|
+
auditToolCall(config.dataDir, record, config.now());
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
app.post(MCP_PATH, sameOriginOnly, requireMcpToken, async (c) => {
|
|
59
|
+
c.header('cache-control', 'no-store');
|
|
60
|
+
const version = c.req.header('mcp-protocol-version');
|
|
61
|
+
if (version !== undefined && !isSupportedVersion(version)) {
|
|
62
|
+
return c.json(failure(null, {
|
|
63
|
+
code: JSON_RPC_ERRORS.invalidRequest,
|
|
64
|
+
message: `This server does not speak MCP ${version}.`,
|
|
65
|
+
}), 400);
|
|
66
|
+
}
|
|
67
|
+
const limit = bodyLimit(c.var.config);
|
|
68
|
+
const read = await readWithin(c.req.raw, limit, 'refuse');
|
|
69
|
+
if (read === undefined) {
|
|
70
|
+
return c.json(failure(null, {
|
|
71
|
+
code: JSON_RPC_ERRORS.invalidRequest,
|
|
72
|
+
message: `The request is larger than the ${String(limit)} bytes this server takes.`,
|
|
73
|
+
}), 413);
|
|
74
|
+
}
|
|
75
|
+
let message;
|
|
76
|
+
try {
|
|
77
|
+
message = JSON.parse(new TextDecoder().decode(read.body));
|
|
78
|
+
}
|
|
79
|
+
catch {
|
|
80
|
+
return c.json(failure(null, { code: JSON_RPC_ERRORS.parseError, message: 'The body is not JSON.' }), 400);
|
|
81
|
+
}
|
|
82
|
+
const { user, token } = c.var.bearer;
|
|
83
|
+
const answered = await reply(message, {
|
|
84
|
+
registry: createToolRegistry(toolsFor(c.var), guards),
|
|
85
|
+
info: serverInfo(c.var.siteAtRequestStart.title),
|
|
86
|
+
call: { user, token, signal: c.req.raw.signal, site: c.var },
|
|
87
|
+
});
|
|
88
|
+
switch (answered.kind) {
|
|
89
|
+
case 'accepted':
|
|
90
|
+
return c.body(null, 202);
|
|
91
|
+
case 'answer':
|
|
92
|
+
return c.json(answered.message);
|
|
93
|
+
case 'malformed':
|
|
94
|
+
return c.json(answered.message, 400);
|
|
95
|
+
case 'insufficient-scope':
|
|
96
|
+
return refuseForScope(c, [...token.scopes, answered.scope], answered.message);
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
// Streamable HTTP lets a server that opens no stream and keeps no session
|
|
100
|
+
// answer GET and DELETE with 405.
|
|
101
|
+
app.on(['GET', 'DELETE'], MCP_PATH, sameOriginOnly, requireMcpToken, (c) => {
|
|
102
|
+
c.header('allow', 'POST');
|
|
103
|
+
return c.body(null, 405);
|
|
104
|
+
});
|
|
105
|
+
app.get(MCP_SERVER_CARD_PATH, (c) => {
|
|
106
|
+
const { baseUrl } = c.var.config;
|
|
107
|
+
return c.json({
|
|
108
|
+
serverInfo: serverInfo(c.var.siteAtRequestStart.title),
|
|
109
|
+
description: 'Tools for inspecting and running this Geekity CMS site.',
|
|
110
|
+
protocolVersion: LATEST_PROTOCOL_VERSION,
|
|
111
|
+
transport: { type: 'streamable-http', endpoint: `${baseUrl}${MCP_PATH}` },
|
|
112
|
+
capabilities: SERVER_CAPABILITIES,
|
|
113
|
+
authentication: {
|
|
114
|
+
required: true,
|
|
115
|
+
schemes: ['oauth2'],
|
|
116
|
+
resourceMetadata: `${baseUrl}${MCP_RESOURCE_METADATA_PATH}`,
|
|
117
|
+
},
|
|
118
|
+
tools: createToolRegistry(toolsFor(c.var), guards)
|
|
119
|
+
.list()
|
|
120
|
+
.map(({ name, title, description }) => ({ name, title, description })),
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
function bodyLimit(config) {
|
|
125
|
+
return base64Length(largestUploadLimit(config)) + UPLOAD_ENVELOPE_BYTES;
|
|
126
|
+
}
|
|
127
|
+
function toolsFor(vars) {
|
|
128
|
+
return { core: CORE_TOOLS, plugin: activePluginTools(vars) };
|
|
129
|
+
}
|
|
130
|
+
function serverInfo(title) {
|
|
131
|
+
return { name: 'geekity', title, version: PACKAGE_VERSION };
|
|
132
|
+
}
|
|
133
|
+
const requireMcpToken = async (c, next) => await requireBearer({
|
|
134
|
+
audience: { resource: `${c.var.config.baseUrl}${MCP_PATH}`, acceptsUnbound: false },
|
|
135
|
+
resourceMetadataPath: MCP_RESOURCE_METADATA_PATH,
|
|
136
|
+
})(c, next);
|
|
137
|
+
/**
|
|
138
|
+
* A browser sends an Origin header, and a page on another origin must not
|
|
139
|
+
* reach the endpoint through it: the transport spec's guard against DNS
|
|
140
|
+
* rebinding. A client that is not a browser sends none and is let through.
|
|
141
|
+
*/
|
|
142
|
+
const sameOriginOnly = async (c, next) => {
|
|
143
|
+
const origin = c.req.header('origin');
|
|
144
|
+
if (origin !== undefined && origin !== new URL(c.var.config.baseUrl).origin) {
|
|
145
|
+
return c.json(failure(null, {
|
|
146
|
+
code: JSON_RPC_ERRORS.invalidRequest,
|
|
147
|
+
message: 'Requests from another origin are refused.',
|
|
148
|
+
}), 403);
|
|
149
|
+
}
|
|
150
|
+
await next();
|
|
151
|
+
};
|
|
152
|
+
/**
|
|
153
|
+
* The MCP authorization spec's answer to a token short of a scope: 403 with a
|
|
154
|
+
* challenge naming the scopes the token holds and the one it lacks, so a
|
|
155
|
+
* client can ask the person for them all in one sign-in.
|
|
156
|
+
*/
|
|
157
|
+
function refuseForScope(c, scopes, message) {
|
|
158
|
+
c.header('www-authenticate', bearerChallenge(c.var.config.baseUrl, { error: 'insufficient_scope', scope: [...new Set(scopes)].join(' ') }, MCP_RESOURCE_METADATA_PATH));
|
|
159
|
+
return c.json(message, 403);
|
|
160
|
+
}
|
|
161
|
+
//# sourceMappingURL=endpoint.js.map
|