@cloudhal/mcp-server 0.10.1 → 0.12.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/README.md +5 -2
- package/dist/src/asset-tools.d.ts +54 -2
- package/dist/src/asset-tools.js +51 -22
- package/dist/src/body-tools.d.ts +6 -0
- package/dist/src/body-tools.js +22 -5
- package/dist/src/changes.d.ts +8 -0
- package/dist/src/changes.js +14 -1
- package/dist/src/collection-listings.d.ts +2 -0
- package/dist/src/collection-listings.js +8 -2
- package/dist/src/common.d.ts +25 -1
- package/dist/src/common.js +26 -1
- package/dist/src/elevation-tools.js +13 -8
- package/dist/src/entry-list.d.ts +3 -2
- package/dist/src/entry-list.js +4 -3
- package/dist/src/field-hints.js +4 -0
- package/dist/src/http.d.ts +10 -1
- package/dist/src/http.js +25 -3
- package/dist/src/pending-changes.d.ts +4 -0
- package/dist/src/pending-changes.js +159 -0
- package/dist/src/publish-gate.d.ts +31 -0
- package/dist/src/publish-gate.js +115 -0
- package/dist/src/publish-tools.d.ts +4 -8
- package/dist/src/publish-tools.js +12 -36
- package/dist/src/render/cdp.js +6 -0
- package/dist/src/render-tools.js +21 -1
- package/dist/src/section-queries.js +7 -1
- package/dist/src/server-call.js +1 -0
- package/dist/src/server-instructions.d.ts +3 -1
- package/dist/src/server-instructions.js +6 -2
- package/dist/src/server.d.ts +3 -1
- package/dist/src/server.js +7 -2
- package/dist/src/structured-data-tools.js +3 -1
- package/dist/src/tools.d.ts +1 -1
- package/dist/src/tools.js +12 -55
- package/dist/src/upload-hints.d.ts +13 -0
- package/dist/src/upload-hints.js +116 -0
- package/dist/src/upload-tools.d.ts +12 -0
- package/dist/src/upload-tools.js +328 -0
- package/package.json +13 -13
package/dist/src/http.js
CHANGED
|
@@ -11,10 +11,10 @@
|
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
|
|
15
15
|
import { createMcpHandler, } from "@modelcontextprotocol/server";
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
|
|
18
18
|
|
|
19
19
|
import { createCloudhalMcpServer } from "./server.js";
|
|
20
20
|
|
|
@@ -28,6 +28,17 @@ import { createCloudhalMcpServer } from "./server.js";
|
|
|
28
28
|
|
|
29
29
|
|
|
30
30
|
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
31
42
|
|
|
32
43
|
|
|
33
44
|
|
|
@@ -70,6 +81,7 @@ export function createCloudhalMcpHandler(options )
|
|
|
70
81
|
previewSecret: options.previewSecret,
|
|
71
82
|
build: options.build,
|
|
72
83
|
media: options.media,
|
|
84
|
+
uploads: uploadsFor(options, ctx.authInfo?.extra?.origin),
|
|
73
85
|
analytics: options.analytics,
|
|
74
86
|
comments: options.comments,
|
|
75
87
|
schedules: options.schedules,
|
|
@@ -93,9 +105,19 @@ export function createCloudhalMcpHandler(options )
|
|
|
93
105
|
token: "",
|
|
94
106
|
clientId: principal.actor.id,
|
|
95
107
|
scopes: principal.scopes,
|
|
96
|
-
extra: { principal },
|
|
108
|
+
extra: { principal, origin: new URL(request.url).origin },
|
|
97
109
|
},
|
|
98
110
|
}),
|
|
99
111
|
close: () => handler.close(),
|
|
100
112
|
};
|
|
101
113
|
}
|
|
114
|
+
|
|
115
|
+
/** The links of one request: the configured origin, else the request's own. */
|
|
116
|
+
function uploadsFor(options , requestOrigin ) {
|
|
117
|
+
const u = options.uploads;
|
|
118
|
+
const origin = u?.baseUrl ?? (typeof requestOrigin === "string" ? requestOrigin : undefined);
|
|
119
|
+
if (!u || !origin) return undefined;
|
|
120
|
+
return { link: (upload) => u.link(upload), verifiable: u.verifiable, origin: trimSlash(origin) };
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const trimSlash = (origin ) => (origin.endsWith("/") ? origin.slice(0, -1) : origin);
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `pending_changes` (#279): what a `publish` of the current state would change against the live
|
|
3
|
+
* snapshot, before anyone publishes. The diff is `pendingChanges` (publish bookkeeping left out,
|
|
4
|
+
* held nodes at their live version), the lines are the `publish` approval prompt's, every node
|
|
5
|
+
* names the fields that changed, and the approval part runs the same gate as `publish`: the
|
|
6
|
+
* policy's decision, the own-only rule and `auto` mode's low-risk check (`publish-gate.ts`).
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { describeAutoCheck } from "@cloudhal/agent-runtime";
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
import { changedFields } from "./body-tools.js";
|
|
13
|
+
import { publishCounts, publishLines } from "./changes.js";
|
|
14
|
+
import { id, obj, requireSite, } from "./common.js";
|
|
15
|
+
import { autoPublishGate, ownOnlyGate } from "./publish-gate.js";
|
|
16
|
+
|
|
17
|
+
/** At most this many nodes are listed; `more` counts the rest (as `diff_node`, one site at a time). */
|
|
18
|
+
export const PENDING_NODE_LIMIT = 200;
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
/** The working copy of a node by its kind. */
|
|
22
|
+
const CURRENT = {
|
|
23
|
+
site: (ctx, i) => ctx.store.getSite(i),
|
|
24
|
+
page: (ctx, i) => ctx.store.getPage(i),
|
|
25
|
+
contentEntry: (ctx, i) => ctx.store.getContentEntry(i),
|
|
26
|
+
taxonomy: (ctx, i) => ctx.store.getTaxonomy(i),
|
|
27
|
+
term: (ctx, i) => ctx.store.getTerm(i),
|
|
28
|
+
redirect: (ctx, i) => ctx.store.getRedirect(i),
|
|
29
|
+
menu: (ctx, i) => ctx.store.getMenu(i),
|
|
30
|
+
asset: (ctx, i) => ctx.store.getAsset(i),
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
/** The site node's live pointer moves with every publish: never a field to explain (#248). */
|
|
42
|
+
const SITE_BOOKKEEPING = ["publishedSnapshotId"];
|
|
43
|
+
|
|
44
|
+
async function fieldsOf(ctx , before , after ) {
|
|
45
|
+
const was = await ctx.store.readSnapshotNode(before).catch(() => undefined);
|
|
46
|
+
const now = await CURRENT[after.kind]?.(ctx, after.id);
|
|
47
|
+
return changedFields(was, now, after.kind === "site" ? SITE_BOOKKEEPING : []);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
async function pendingNodes(ctx , diff ) {
|
|
51
|
+
const all = [
|
|
52
|
+
...diff.added.map((ref) => ({ change: "added" , ref })),
|
|
53
|
+
...diff.changed.map((c) => ({ change: "changed" , ref: c.after, before: c.before })),
|
|
54
|
+
...diff.removed.map((ref) => ({ change: "removed" , ref })),
|
|
55
|
+
];
|
|
56
|
+
const nodes = [];
|
|
57
|
+
for (const { change, ref, before } of all.slice(0, PENDING_NODE_LIMIT))
|
|
58
|
+
nodes.push({
|
|
59
|
+
change,
|
|
60
|
+
kind: ref.kind,
|
|
61
|
+
id: ref.id,
|
|
62
|
+
...(before ? { fields: await fieldsOf(ctx, before, ref) } : {}),
|
|
63
|
+
});
|
|
64
|
+
return { nodes, more: Math.max(0, all.length - PENDING_NODE_LIMIT) };
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** Whether the caller's `publish` would go live at once, wait for a person, or be refused. */
|
|
68
|
+
async function publishApproval(ctx , siteId ) {
|
|
69
|
+
if (!ctx.policy) return { verdict: "unknown" , reason: "no policy engine in this call" };
|
|
70
|
+
let decision = ctx.policy.evaluate(ctx.principal, "publish", { args: { siteId } });
|
|
71
|
+
decision = await ownOnlyGate(ctx, siteId, decision);
|
|
72
|
+
const gate = await autoPublishGate(ctx, siteId, decision);
|
|
73
|
+
decision = gate.decision;
|
|
74
|
+
if (decision.kind === "deny") return { verdict: "refused" , reason: decision.reason };
|
|
75
|
+
if (decision.kind === "approval-required" && !gate.autoNote)
|
|
76
|
+
return {
|
|
77
|
+
verdict: "asks-a-person" ,
|
|
78
|
+
reason: decision.reason,
|
|
79
|
+
cause: decision.cause,
|
|
80
|
+
...(gate.autoCheck ? { autoCheck: describeAutoCheck(gate.autoCheck) } : {}),
|
|
81
|
+
};
|
|
82
|
+
return {
|
|
83
|
+
verdict: "publishes" ,
|
|
84
|
+
...(gate.autoNote ? { reason: gate.autoNote } : {}),
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const NODE = obj(
|
|
89
|
+
{
|
|
90
|
+
change: { type: "string", enum: ["added", "changed", "removed"] },
|
|
91
|
+
kind: { type: "string" },
|
|
92
|
+
id: { type: "string" },
|
|
93
|
+
fields: { type: "array", items: { type: "string" } },
|
|
94
|
+
},
|
|
95
|
+
["change", "kind", "id"],
|
|
96
|
+
);
|
|
97
|
+
|
|
98
|
+
export const pendingChangesTool = {
|
|
99
|
+
name: "pending_changes",
|
|
100
|
+
title: "What a publish would change",
|
|
101
|
+
description:
|
|
102
|
+
"Before `publish`: what publishing the current state would change against the live version. `lines` are the approval prompt's lines, `nodes` every node with the fields that changed (`diff_node` shows a page's or article's body block by block), and `approval` whether your `publish` would go live at once (`publishes`), wait for a person (`asks-a-person`, with the reason and, in `auto` mode, the rule that stopped it) or be refused. Needs no snapshot ids.",
|
|
103
|
+
inputSchema: obj({ siteId: id }, ["siteId"]),
|
|
104
|
+
outputSchema: obj(
|
|
105
|
+
{
|
|
106
|
+
live: {
|
|
107
|
+
type: "string",
|
|
108
|
+
description: "The live snapshot, or `none` before the first publish",
|
|
109
|
+
},
|
|
110
|
+
counts: obj(
|
|
111
|
+
{
|
|
112
|
+
added: { type: "integer" },
|
|
113
|
+
changed: { type: "integer" },
|
|
114
|
+
removed: { type: "integer" },
|
|
115
|
+
},
|
|
116
|
+
["added", "changed", "removed"],
|
|
117
|
+
),
|
|
118
|
+
summary: { type: "string" },
|
|
119
|
+
lines: { type: "array", items: { type: "string" } },
|
|
120
|
+
nodes: { type: "array", items: NODE },
|
|
121
|
+
more: { type: "integer", description: "Nodes past the first 200, not listed" },
|
|
122
|
+
approval: obj(
|
|
123
|
+
{
|
|
124
|
+
verdict: { type: "string", enum: ["publishes", "asks-a-person", "refused", "unknown"] },
|
|
125
|
+
reason: { type: "string" },
|
|
126
|
+
cause: { type: "string" },
|
|
127
|
+
autoCheck: { type: "string" },
|
|
128
|
+
},
|
|
129
|
+
["verdict"],
|
|
130
|
+
),
|
|
131
|
+
},
|
|
132
|
+
["live", "counts", "summary", "lines", "nodes", "approval"],
|
|
133
|
+
),
|
|
134
|
+
annotations: {
|
|
135
|
+
readOnlyHint: true,
|
|
136
|
+
destructiveHint: false,
|
|
137
|
+
idempotentHint: true,
|
|
138
|
+
openWorldHint: false,
|
|
139
|
+
},
|
|
140
|
+
scopes: ["site:read"],
|
|
141
|
+
handler: async (a, ctx) => {
|
|
142
|
+
const site = await requireSite(ctx, a.siteId );
|
|
143
|
+
const diff = await ctx.store.pendingChanges(site.id);
|
|
144
|
+
const { nodes, more } = await pendingNodes(ctx, diff);
|
|
145
|
+
return {
|
|
146
|
+
live: site.publishedSnapshotId ?? "none",
|
|
147
|
+
counts: {
|
|
148
|
+
added: diff.added.length,
|
|
149
|
+
changed: diff.changed.length,
|
|
150
|
+
removed: diff.removed.length,
|
|
151
|
+
},
|
|
152
|
+
summary: `${publishCounts(diff)} since the live version`,
|
|
153
|
+
lines: await publishLines(ctx, diff, site),
|
|
154
|
+
nodes,
|
|
155
|
+
...(more ? { more } : {}),
|
|
156
|
+
approval: await publishApproval(ctx, site.id),
|
|
157
|
+
};
|
|
158
|
+
},
|
|
159
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What stands between a publish and the live site, beyond the policy's own decision: the own-only
|
|
3
|
+
* rule (RFC-0005 I10) and `auto` mode's low-risk check (ADR-0015). `runTool` applies both to a
|
|
4
|
+
* `publish` call; `pending_changes` (#279) applies the same steps without publishing, so an agent
|
|
5
|
+
* learns in advance whether a person will be asked.
|
|
6
|
+
*/
|
|
7
|
+
import type { AutoCheck, Decision, OwnOnlyResult } from "@cloudhal/agent-runtime";
|
|
8
|
+
import { type ToolContext } from "./common.js";
|
|
9
|
+
/**
|
|
10
|
+
* Is publishing the current state own-only for the caller (RFC-0005 §4, I10)? Every publicly
|
|
11
|
+
* visible pending change must be an entry the caller's person owns.
|
|
12
|
+
*/
|
|
13
|
+
export declare function ownOnlyPublish(ctx: ToolContext, siteId: string): Promise<OwnOnlyResult>;
|
|
14
|
+
/**
|
|
15
|
+
* Own-only publish (I10): an Author's (or their agent's) publish that carries someone else's work,
|
|
16
|
+
* or structure, waits for someone whose role allows it (cause `role`). `approved`: an out-of-band
|
|
17
|
+
* approval was redeemed, so the own limit no longer applies.
|
|
18
|
+
*/
|
|
19
|
+
export declare function ownOnlyGate(ctx: ToolContext, siteId: string | undefined, decision: Decision, approved?: boolean): Promise<Decision>;
|
|
20
|
+
export interface AutoGate {
|
|
21
|
+
readonly decision: Decision;
|
|
22
|
+
/** The `auto`-mode check, when the decision offered it. */
|
|
23
|
+
readonly autoCheck?: AutoCheck;
|
|
24
|
+
/** Set when the check lets the publish through without a person (English, for the agent). */
|
|
25
|
+
readonly autoNote?: string;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* `auto` mode: a publish that only adds or edits a few articles goes live without a person. When
|
|
29
|
+
* the check fails, the decision keeps waiting and its reason names the rule that stopped it.
|
|
30
|
+
*/
|
|
31
|
+
export declare function autoPublishGate(ctx: ToolContext, siteId: string | undefined, decision: Decision): Promise<AutoGate>;
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What stands between a publish and the live site, beyond the policy's own decision: the own-only
|
|
3
|
+
* rule (RFC-0005 I10) and `auto` mode's low-risk check (ADR-0015). `runTool` applies both to a
|
|
4
|
+
* `publish` call; `pending_changes` (#279) applies the same steps without publishing, so an agent
|
|
5
|
+
* learns in advance whether a person will be asked.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import {
|
|
9
|
+
checkAutoPublish,
|
|
10
|
+
describeAutoCheck,
|
|
11
|
+
describeOwnOnly,
|
|
12
|
+
ownOnlyChangeSet,
|
|
13
|
+
} from "@cloudhal/agent-runtime";
|
|
14
|
+
import { expiringEntries, } from "@cloudhal/core-ts";
|
|
15
|
+
import { ACTOR_OWNERSHIP, callerPerson, } from "./common.js";
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Is publishing the current state own-only for the caller (RFC-0005 §4, I10)? Every publicly
|
|
19
|
+
* visible pending change must be an entry the caller's person owns.
|
|
20
|
+
*/
|
|
21
|
+
export async function ownOnlyPublish(ctx , siteId ) {
|
|
22
|
+
const store = ctx.store;
|
|
23
|
+
return ownOnlyChangeSet(
|
|
24
|
+
await store.pendingChanges(siteId),
|
|
25
|
+
callerPerson(ctx),
|
|
26
|
+
ctx.ownership ?? ACTOR_OWNERSHIP,
|
|
27
|
+
{
|
|
28
|
+
before: (ref) => store.readSnapshotNode(ref).catch(() => undefined),
|
|
29
|
+
after: async (ref) =>
|
|
30
|
+
ref.kind === "contentEntry"
|
|
31
|
+
? store.getContentEntry(ref.id)
|
|
32
|
+
: ref.kind === "site"
|
|
33
|
+
? store.getSite(ref.id)
|
|
34
|
+
: undefined,
|
|
35
|
+
},
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Own-only publish (I10): an Author's (or their agent's) publish that carries someone else's work,
|
|
41
|
+
* or structure, waits for someone whose role allows it (cause `role`). `approved`: an out-of-band
|
|
42
|
+
* approval was redeemed, so the own limit no longer applies.
|
|
43
|
+
*/
|
|
44
|
+
export async function ownOnlyGate(
|
|
45
|
+
ctx ,
|
|
46
|
+
siteId ,
|
|
47
|
+
decision ,
|
|
48
|
+
approved = false,
|
|
49
|
+
) {
|
|
50
|
+
if (decision.kind === "deny" || decision.limit?.target !== "changeset" || approved || !siteId)
|
|
51
|
+
return decision;
|
|
52
|
+
const check = await ownOnlyPublish(ctx, siteId).catch(() => undefined);
|
|
53
|
+
if (check?.ownOnly) return decision;
|
|
54
|
+
const why = check ? describeOwnOnly(check) : "the site could not be read";
|
|
55
|
+
return {
|
|
56
|
+
kind: "approval-required",
|
|
57
|
+
reason: `your role publishes only your own work, but ${why}`,
|
|
58
|
+
cause: "role",
|
|
59
|
+
limit: decision.limit,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* What the store knows about a pending publish for the `auto`-mode check: new images riding with
|
|
65
|
+
* articles (RFC-0004 §6.3), corrections (RFC-0019 §2.4) and derived gates added or moved earlier
|
|
66
|
+
* on live articles (RFC-0042 §3.5).
|
|
67
|
+
*/
|
|
68
|
+
async function autoPublishFacts(store , siteId , pending ) {
|
|
69
|
+
return {
|
|
70
|
+
ridingAssets: await store.ridingAssets(siteId, pending),
|
|
71
|
+
corrections: await store.correctingEntries(siteId, pending),
|
|
72
|
+
expiries: await expiringEntries(store, siteId, pending),
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* `auto` mode: a publish that only adds or edits a few articles goes live without a person. When
|
|
86
|
+
* the check fails, the decision keeps waiting and its reason names the rule that stopped it.
|
|
87
|
+
*/
|
|
88
|
+
export async function autoPublishGate(
|
|
89
|
+
ctx ,
|
|
90
|
+
siteId ,
|
|
91
|
+
decision ,
|
|
92
|
+
) {
|
|
93
|
+
if (
|
|
94
|
+
decision.kind !== "approval-required" ||
|
|
95
|
+
decision.autoApprove !== "low-risk-publish" ||
|
|
96
|
+
!siteId
|
|
97
|
+
)
|
|
98
|
+
return { decision };
|
|
99
|
+
const pending = await ctx.store.pendingChanges(siteId);
|
|
100
|
+
// New raster images used only by the articles in this publish ride along (RFC-0004 §6.3).
|
|
101
|
+
const autoCheck = checkAutoPublish(pending, await autoPublishFacts(ctx.store, siteId, pending));
|
|
102
|
+
if (autoCheck.lowRisk)
|
|
103
|
+
return {
|
|
104
|
+
decision,
|
|
105
|
+
autoCheck,
|
|
106
|
+
autoNote: `auto mode: published without approval (${describeAutoCheck(autoCheck)})`,
|
|
107
|
+
};
|
|
108
|
+
return {
|
|
109
|
+
decision: {
|
|
110
|
+
...decision,
|
|
111
|
+
reason: `auto mode waits for a person: ${describeAutoCheck(autoCheck)}`,
|
|
112
|
+
},
|
|
113
|
+
autoCheck,
|
|
114
|
+
};
|
|
115
|
+
}
|
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
/** Snapshot, diff, preview, publish and rollback tools (approval-gated publishing). */
|
|
2
|
-
import type
|
|
3
|
-
|
|
4
|
-
/** create_snapshot … rollback, in `tools/list` order. */
|
|
2
|
+
import { type ToolDefinition } from "./common.js";
|
|
3
|
+
/** create_snapshot … rollback, in `tools/list` order (`pending_changes` right before `publish`). */
|
|
5
4
|
export declare function publishTools(): ToolDefinition[];
|
|
6
|
-
/**
|
|
7
|
-
|
|
8
|
-
* visible pending change must be an entry the caller's person owns.
|
|
9
|
-
*/
|
|
10
|
-
export declare function ownOnlyPublish(ctx: ToolContext, siteId: string): Promise<OwnOnlyResult>;
|
|
5
|
+
/** Moved to `publish-gate.ts` with the rest of the publish gate; kept here for importers. */
|
|
6
|
+
export { ownOnlyPublish } from "./publish-gate.js";
|
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
/** Snapshot, diff, preview, publish and rollback tools (approval-gated publishing). */
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
import { ownOnlyChangeSet } from "@cloudhal/agent-runtime";
|
|
5
|
-
import { describeChanges } from "./changes.js";
|
|
3
|
+
import { publishCounts, publishLines } from "./changes.js";
|
|
6
4
|
import {
|
|
7
|
-
ACTOR_OWNERSHIP,
|
|
8
|
-
callerPerson,
|
|
9
5
|
id,
|
|
10
6
|
mapError,
|
|
11
7
|
obj,
|
|
@@ -17,7 +13,7 @@ import {
|
|
|
17
13
|
ToolError,
|
|
18
14
|
} from "./common.js";
|
|
19
15
|
import { SITE, SNAPSHOT } from "./content-shared.js";
|
|
20
|
-
import {
|
|
16
|
+
import { pendingChangesTool } from "./pending-changes.js";
|
|
21
17
|
import { previewDoc } from "./preview-doc.js";
|
|
22
18
|
import { PREVIEW_UI_URI } from "./preview-view.js";
|
|
23
19
|
|
|
@@ -82,7 +78,8 @@ const listSnapshotsTool = {
|
|
|
82
78
|
const diffSnapshotsTool = {
|
|
83
79
|
name: "diff_snapshots",
|
|
84
80
|
title: "Diff snapshots",
|
|
85
|
-
description:
|
|
81
|
+
description:
|
|
82
|
+
"Added, changed and removed nodes between two snapshots. The site node is listed only when its settings differ: the live pointer, rev and updatedAt that every publish rewrites are not a change (the same rule as publish's approval).",
|
|
86
83
|
inputSchema: obj({ siteId: id, fromSnapshotId: id, toSnapshotId: id }, [
|
|
87
84
|
"siteId",
|
|
88
85
|
"fromSnapshotId",
|
|
@@ -144,7 +141,8 @@ const previewPageTool = {
|
|
|
144
141
|
const publishTool = {
|
|
145
142
|
name: "publish",
|
|
146
143
|
title: "Publish site",
|
|
147
|
-
description:
|
|
144
|
+
description:
|
|
145
|
+
"Snapshot the current state and make it live. Waits for a person, except a low-risk article publish in `auto` mode (only articles added or edited, nothing removed, within the mode's limits; get_mode shows your mode).",
|
|
148
146
|
inputSchema: obj({ siteId: id, label: str("Label for the published snapshot") }, ["siteId"]),
|
|
149
147
|
outputSchema: obj({ site: SITE, snapshot: SNAPSHOT }, ["site", "snapshot"]),
|
|
150
148
|
annotations: {
|
|
@@ -160,12 +158,8 @@ const publishTool = {
|
|
|
160
158
|
const site = await requireSite(ctx, a.siteId );
|
|
161
159
|
// What the person approves is what goes live: the current state against the live snapshot.
|
|
162
160
|
const diff = await ctx.store.pendingChanges(site.id);
|
|
163
|
-
const lines =
|
|
164
|
-
|
|
165
|
-
...(await publishMenuLines(ctx, site)),
|
|
166
|
-
];
|
|
167
|
-
const counts = `+${diff.added.length} added, ~${diff.changed.length} changed, −${diff.removed.length} removed`;
|
|
168
|
-
return `Publish "${quote(site.name)}" to production (${counts} since the live version)?${lines.length ? `\n${lines.join("\n")}` : ""}`;
|
|
161
|
+
const lines = await publishLines(ctx, diff, site);
|
|
162
|
+
return `Publish "${quote(site.name)}" to production (${publishCounts(diff)} since the live version)?${lines.length ? `\n${lines.join("\n")}` : ""}`;
|
|
169
163
|
},
|
|
170
164
|
handler: async (a, ctx) => {
|
|
171
165
|
const site = await requireSite(ctx, a.siteId );
|
|
@@ -213,36 +207,18 @@ const rollbackTool = {
|
|
|
213
207
|
},
|
|
214
208
|
};
|
|
215
209
|
|
|
216
|
-
/** create_snapshot … rollback, in `tools/list` order. */
|
|
210
|
+
/** create_snapshot … rollback, in `tools/list` order (`pending_changes` right before `publish`). */
|
|
217
211
|
export function publishTools() {
|
|
218
212
|
return [
|
|
219
213
|
createSnapshotTool,
|
|
220
214
|
listSnapshotsTool,
|
|
221
215
|
diffSnapshotsTool,
|
|
222
216
|
previewPageTool,
|
|
217
|
+
pendingChangesTool,
|
|
223
218
|
publishTool,
|
|
224
219
|
rollbackTool,
|
|
225
220
|
];
|
|
226
221
|
}
|
|
227
222
|
|
|
228
|
-
/**
|
|
229
|
-
|
|
230
|
-
* visible pending change must be an entry the caller's person owns.
|
|
231
|
-
*/
|
|
232
|
-
export async function ownOnlyPublish(ctx , siteId ) {
|
|
233
|
-
const store = ctx.store;
|
|
234
|
-
return ownOnlyChangeSet(
|
|
235
|
-
await store.pendingChanges(siteId),
|
|
236
|
-
callerPerson(ctx),
|
|
237
|
-
ctx.ownership ?? ACTOR_OWNERSHIP,
|
|
238
|
-
{
|
|
239
|
-
before: (ref) => store.readSnapshotNode(ref).catch(() => undefined),
|
|
240
|
-
after: async (ref) =>
|
|
241
|
-
ref.kind === "contentEntry"
|
|
242
|
-
? store.getContentEntry(ref.id)
|
|
243
|
-
: ref.kind === "site"
|
|
244
|
-
? store.getSite(ref.id)
|
|
245
|
-
: undefined,
|
|
246
|
-
},
|
|
247
|
-
);
|
|
248
|
-
}
|
|
223
|
+
/** Moved to `publish-gate.ts` with the rest of the publish gate; kept here for importers. */
|
|
224
|
+
export { ownOnlyPublish } from "./publish-gate.js";
|
package/dist/src/render/cdp.js
CHANGED
|
@@ -107,6 +107,12 @@ export async function cdpSession(
|
|
|
107
107
|
const s = (method , params = {}) =>
|
|
108
108
|
cdp.send(method, params, sessionId);
|
|
109
109
|
await s("Page.enable");
|
|
110
|
+
// #249: a tab that is not in front (a browser's own first page, another render in the same
|
|
111
|
+
// browser) is hidden, and Chrome throttles a hidden page's frames: IntersectionObserver
|
|
112
|
+
// runs late or not at all (a scroll story keeps its first step) and screenshots wait for
|
|
113
|
+
// frames. Each render tab is focused and in front, whatever else the browser has open.
|
|
114
|
+
await s("Emulation.setFocusEmulationEnabled", { enabled: true });
|
|
115
|
+
await s("Page.bringToFront");
|
|
110
116
|
await s("Emulation.setDeviceMetricsOverride", {
|
|
111
117
|
width: viewport.width,
|
|
112
118
|
height: viewport.height,
|
package/dist/src/render-tools.js
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* component behind each problem. Read-only: nothing is stored, and the preview link expires.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
+
import { mintPreviewToken, previewUrlAt } from "@cloudhal/core-ts";
|
|
8
9
|
import {
|
|
9
10
|
id,
|
|
10
11
|
obj,
|
|
@@ -126,6 +127,25 @@ function mergeContrast(
|
|
|
126
127
|
);
|
|
127
128
|
}
|
|
128
129
|
|
|
130
|
+
/**
|
|
131
|
+
* The link the browser opens: the preview link, or the same signed link at `render.origin` for a
|
|
132
|
+
* browser that reaches the site only on a private network (RFC-0047, #292). Still the site's own
|
|
133
|
+
* preview of this page: no other URL is ever opened.
|
|
134
|
+
*/
|
|
135
|
+
async function renderTarget(
|
|
136
|
+
a ,
|
|
137
|
+
ctx ,
|
|
138
|
+
doc ,
|
|
139
|
+
) {
|
|
140
|
+
const origin = ctx.render?.origin;
|
|
141
|
+
if (!origin || !ctx.previewSecret) return doc;
|
|
142
|
+
const token = await mintPreviewToken(ctx.previewSecret, {
|
|
143
|
+
site: a.siteId ,
|
|
144
|
+
target: "live",
|
|
145
|
+
});
|
|
146
|
+
return { ...doc, url: previewUrlAt(origin, doc.path, token) };
|
|
147
|
+
}
|
|
148
|
+
|
|
129
149
|
export function renderTools(previewDoc ) {
|
|
130
150
|
return [
|
|
131
151
|
{
|
|
@@ -229,7 +249,7 @@ export function renderTools(previewDoc ) {
|
|
|
229
249
|
},
|
|
230
250
|
handler: async (a, ctx) => {
|
|
231
251
|
if (!a.pageId && !a.entryId) throw new ToolError("invalid", "pass pageId or entryId");
|
|
232
|
-
const doc = await previewDoc(a, ctx);
|
|
252
|
+
const doc = await renderTarget(a, ctx, await previewDoc(a, ctx));
|
|
233
253
|
if (!ctx.render)
|
|
234
254
|
throw new ToolError(
|
|
235
255
|
"render_unavailable",
|
|
@@ -6,7 +6,12 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
import { InvariantError } from "@cloudhal/core-ts";
|
|
9
|
-
import {
|
|
9
|
+
import {
|
|
10
|
+
checkFieldQuery,
|
|
11
|
+
|
|
12
|
+
fieldDefinitions,
|
|
13
|
+
siteCollections,
|
|
14
|
+
} from "@cloudhal/core-ts/fields";
|
|
10
15
|
import { requireSite, toToolError } from "./common.js";
|
|
11
16
|
|
|
12
17
|
|
|
@@ -40,6 +45,7 @@ export async function checkSectionQueries(
|
|
|
40
45
|
fieldDefinitions(site, section.collection),
|
|
41
46
|
listFields,
|
|
42
47
|
section,
|
|
48
|
+
siteCollections(site),
|
|
43
49
|
))
|
|
44
50
|
issues.push({ ...issue, path: `sections/${i}/${issue.path}` });
|
|
45
51
|
});
|
package/dist/src/server-call.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
/** The server's `instructions`: the workflow text, then the caller's mode and role (RFC-0005 §10.2). */
|
|
2
2
|
import { type Principal } from "@cloudhal/agent-runtime";
|
|
3
3
|
/** The full `instructions` text for one principal. */
|
|
4
|
-
export declare function serverInstructions(principal: Principal
|
|
4
|
+
export declare function serverInstructions(principal: Principal, o?: {
|
|
5
|
+
uploads?: boolean;
|
|
6
|
+
}): string;
|
|
@@ -78,7 +78,11 @@ function modeInstructions(principal ) {
|
|
|
78
78
|
return `${MODE_TEXT[mode]}\nThis mode is temporary: a person granted it until ${elevation.until} (UTC). After that you work in ${elevation.from.toUpperCase()} mode again, so finish or hand over anything that depends on it before then.`;
|
|
79
79
|
}
|
|
80
80
|
|
|
81
|
+
/** RFC-0048: said only where `get_mode.uploads.signedUrl` is true. */
|
|
82
|
+
const UPLOADS = `Media files on disk: when you have a shell, add them with create_upload (declare the size, type and SHA-256), run the PUT it returns (the curl line), then complete_upload; the bytes never pass through this conversation. upload_asset (base64, at most 4 MB) is for small files or when you have no shell. An upload link is a credential for that one file: do not share it.`;
|
|
83
|
+
|
|
81
84
|
/** The full `instructions` text for one principal. */
|
|
82
|
-
export function serverInstructions(principal ) {
|
|
83
|
-
|
|
85
|
+
export function serverInstructions(principal , o = {}) {
|
|
86
|
+
const uploads = o.uploads ? `\n\n${UPLOADS}` : "";
|
|
87
|
+
return `${INSTRUCTIONS}${uploads}\n\n${modeInstructions(principal)}${personInstructions(principal)}`;
|
|
84
88
|
}
|
package/dist/src/server.d.ts
CHANGED
|
@@ -18,7 +18,7 @@ import type { AnalyticsService } from "@cloudhal/analytics/service";
|
|
|
18
18
|
import type { SiteGraphStore } from "@cloudhal/core-ts";
|
|
19
19
|
import { McpServer } from "@modelcontextprotocol/server";
|
|
20
20
|
import type { CommentsDeps } from "./comments.js";
|
|
21
|
-
import type { BuildObserver, MediaToolOptions, RenderDeps } from "./common.js";
|
|
21
|
+
import type { BuildObserver, MediaToolOptions, RenderDeps, UploadLinkDeps } from "./common.js";
|
|
22
22
|
import type { SchedulesDeps } from "./schedules.js";
|
|
23
23
|
import { type ToolDefinition } from "./tools.js";
|
|
24
24
|
export { SKILL_META_KEY } from "./server-call.js";
|
|
@@ -36,6 +36,8 @@ export interface CloudhalMcpOptions {
|
|
|
36
36
|
previewSecret?: string | undefined;
|
|
37
37
|
/** Media settings for the asset tools (fetch transport, host lists, daily limits; RFC-0004). */
|
|
38
38
|
media?: MediaToolOptions | undefined;
|
|
39
|
+
/** RFC-0048: agents' upload links (HTTP only; without it `uploads.signedUrl` is false). */
|
|
40
|
+
uploads?: UploadLinkDeps | undefined;
|
|
39
41
|
/** Site analytics for the read-only analytics tools (RFC-0006 §9.3). */
|
|
40
42
|
analytics?: AnalyticsService | undefined;
|
|
41
43
|
/** Reader comments for the comment tools (RFC-0007 §11). */
|
package/dist/src/server.js
CHANGED
|
@@ -25,7 +25,7 @@ import {
|
|
|
25
25
|
|
|
26
26
|
import { createRequestStateCodec, McpServer } from "@modelcontextprotocol/server";
|
|
27
27
|
|
|
28
|
-
|
|
28
|
+
|
|
29
29
|
|
|
30
30
|
|
|
31
31
|
import { handleToolCall } from "./server-call.js";
|
|
@@ -33,6 +33,7 @@ import { serverInstructions } from "./server-instructions.js";
|
|
|
33
33
|
import { registerResources } from "./server-resources.js";
|
|
34
34
|
import { compiledSchema, defaultToolList, registeredInputSchema } from "./server-schema.js";
|
|
35
35
|
import { toolPolicies } from "./tools.js";
|
|
36
|
+
import { uploadCapability } from "./upload-tools.js";
|
|
36
37
|
|
|
37
38
|
export { SKILL_META_KEY } from "./server-call.js";
|
|
38
39
|
|
|
@@ -50,6 +51,8 @@ export { SKILL_META_KEY } from "./server-call.js";
|
|
|
50
51
|
|
|
51
52
|
|
|
52
53
|
|
|
54
|
+
|
|
55
|
+
|
|
53
56
|
|
|
54
57
|
|
|
55
58
|
|
|
@@ -110,7 +113,9 @@ export function createCloudhalMcpServer(options )
|
|
|
110
113
|
},
|
|
111
114
|
{
|
|
112
115
|
capabilities: { tools: {}, resources: {} },
|
|
113
|
-
instructions: serverInstructions(options.principal
|
|
116
|
+
instructions: serverInstructions(options.principal, {
|
|
117
|
+
uploads: uploadCapability(options).signedUrl,
|
|
118
|
+
}),
|
|
114
119
|
requestState: { verify: codec.verify },
|
|
115
120
|
},
|
|
116
121
|
);
|