create-ailk 0.44.0 → 0.46.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 +6 -3
- package/component-catalog.json +24 -1
- package/component-catalog.md +6 -5
- package/dist/add-module.d.ts +7 -0
- package/dist/add-module.js +17 -2
- package/dist/apply-design.js +1 -12
- package/dist/lib/env-catalog.js +2 -2
- package/dist/lib/import-mdx.js +10 -2
- package/dist/lib/license-key-files.d.ts +2 -0
- package/dist/lib/license-key-files.js +11 -0
- package/dist/paid-sections.d.ts +19 -0
- package/dist/paid-sections.js +41 -0
- package/dist/programmatic.js +56 -6
- package/dist/seed-workspace.d.ts +1 -1
- package/dist/seed-workspace.js +10 -3
- package/dist/surfaces.js +1 -1
- package/dist/update.d.ts +21 -2
- package/dist/update.js +188 -10
- package/package.json +3 -3
- package/templates/apps/api/.env.example +23 -0
- package/templates/apps/api/CLAUDE.md +17 -7
- package/templates/apps/api/src/lib/__mocks__/prisma.ts +11 -0
- package/templates/apps/mcp/.env.example +14 -3
- package/templates/apps/mcp/CLAUDE.md +47 -24
- package/templates/apps/mcp/src/index.ts +1 -1
- package/templates/apps/web/.env.example +1 -1
- package/templates/apps/web/CLAUDE.md +47 -16
- package/templates/apps/web/app/.well-known/mcp.json/build-manifest.ts +44 -41
- package/templates/apps/web/app/.well-known/mcp.json/route.ts +24 -33
- package/templates/apps/web/app/[locale]/layout.tsx +10 -7
- package/templates/apps/web/app/api/site-status/__tests__/route.test.ts +120 -0
- package/templates/apps/web/app/api/site-status/route.ts +62 -0
- package/templates/apps/web/app/llms.txt/route.ts +3 -3
- package/templates/apps/web/app/openapi.json/__tests__/route.test.ts +21 -4
- package/templates/apps/web/app/openapi.json/route.ts +10 -9
- package/templates/apps/web/app/sitemap.xml/route.ts +3 -3
- package/templates/apps/web/auth.ts +25 -1
- package/templates/apps/web/lib/__tests__/fixtures/mcp-stub-server.ts +245 -0
- package/templates/apps/web/lib/__tests__/mcp-served-tools.test.ts +395 -0
- package/templates/apps/web/lib/__tests__/offerings-pricing.test.ts +112 -0
- package/templates/apps/web/lib/__tests__/pricing-page.test.ts +280 -0
- package/templates/apps/web/lib/__tests__/site-brand.test.ts +5 -6
- package/templates/apps/web/lib/__tests__/site-visibility.test.ts +64 -0
- package/templates/apps/web/lib/__tests__/structured-data.test.tsx +108 -11
- package/templates/apps/web/lib/license-key-store.ts +1 -1
- package/templates/apps/web/lib/mcp-oauth.ts +64 -0
- package/templates/apps/web/lib/mcp-served-tools.ts +231 -0
- package/templates/apps/web/lib/offerings-pricing.ts +30 -6
- package/templates/apps/web/lib/pricing-page.ts +142 -35
- package/templates/apps/web/lib/site-brand.tsx +1 -7
- package/templates/apps/web/lib/site-visibility.ts +45 -0
- package/templates/apps/web/messages/en.json +8 -0
- package/templates/apps/web/middleware.ts +16 -1
- package/templates/apps/web/src/lib/routes.ts +3 -3
- package/versions.json +51 -51
- package/templates/apps/web/app/.well-known/ai-plugin.json/route.ts +0 -93
- package/templates/apps/web/lib/release-scope.ts +0 -47
|
@@ -200,16 +200,17 @@ if (SOURCE === "database") process.env.AILK_API_URL = "http://127.0.0.1:9";
|
|
|
200
200
|
/**
|
|
201
201
|
* Every page the snapshot holds, keyed by its cache tag
|
|
202
202
|
* (`content:<workspace>:<type>:<slug>:<locale>`, `cache-tags.ts`), or why it
|
|
203
|
-
* holds none. Read only under
|
|
203
|
+
* holds none, and whether the file is `absent` (#11941 D1). Read only under
|
|
204
|
+
* `database`.
|
|
204
205
|
*/
|
|
205
|
-
function readHubPages(): {
|
|
206
|
+
function readHubPages(path = join(process.cwd(), SNAPSHOT_REL)): {
|
|
206
207
|
pages: Array<{ locale: string; type: string; slug: string }>;
|
|
207
208
|
problem: string | null;
|
|
209
|
+
absent: boolean;
|
|
208
210
|
} {
|
|
209
|
-
const path = join(process.cwd(), SNAPSHOT_REL);
|
|
210
211
|
const build = "run `pnpm --filter web build` under CONTENT_ADAPTER=database to write it";
|
|
211
212
|
if (!existsSync(path)) {
|
|
212
|
-
return { pages: [], problem: `${path} does not exist — ${build}
|
|
213
|
+
return { pages: [], problem: `${path} does not exist — ${build}`, absent: true };
|
|
213
214
|
}
|
|
214
215
|
let parsed: { version?: unknown; pages?: unknown; lists?: unknown } | null;
|
|
215
216
|
try {
|
|
@@ -226,7 +227,11 @@ function readHubPages(): {
|
|
|
226
227
|
typeof parsed.lists !== "object" ||
|
|
227
228
|
parsed.lists === null
|
|
228
229
|
) {
|
|
229
|
-
return {
|
|
230
|
+
return {
|
|
231
|
+
pages: [],
|
|
232
|
+
problem: `${path} is not a version-1 content snapshot — ${build}`,
|
|
233
|
+
absent: false,
|
|
234
|
+
};
|
|
230
235
|
}
|
|
231
236
|
const pages = Object.keys(parsed.pages).map((tag) => {
|
|
232
237
|
const parts = tag.split(":");
|
|
@@ -237,12 +242,27 @@ function readHubPages(): {
|
|
|
237
242
|
};
|
|
238
243
|
});
|
|
239
244
|
if (pages.length === 0) {
|
|
240
|
-
return { pages, problem: `${path} holds no page — ${build}
|
|
245
|
+
return { pages, problem: `${path} holds no page — ${build}`, absent: false };
|
|
241
246
|
}
|
|
242
|
-
return { pages, problem: null };
|
|
247
|
+
return { pages, problem: null, absent: false };
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
const HUB = SOURCE === "database" ? readHubPages() : { pages: [], problem: null, absent: false };
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* #11941 D1 — why this run does not check the hub's pages, or null when it
|
|
254
|
+
* does. Only a database-served run with no snapshot file skips: that is
|
|
255
|
+
* `pnpm test` before any database build. A snapshot that is present but
|
|
256
|
+
* unreadable or empty still fails, and a files-served run never skips.
|
|
257
|
+
*/
|
|
258
|
+
function snapshotSkipReason(
|
|
259
|
+
source: string,
|
|
260
|
+
hub: { problem: string | null; absent: boolean },
|
|
261
|
+
): string | null {
|
|
262
|
+
return source === "database" && hub.absent ? hub.problem : null;
|
|
243
263
|
}
|
|
244
264
|
|
|
245
|
-
const
|
|
265
|
+
const HUB_SKIP = snapshotSkipReason(SOURCE, HUB);
|
|
246
266
|
|
|
247
267
|
/** The snapshot's (locale, type) pairs, in the shape the content walk takes. */
|
|
248
268
|
function hubTypeDirs(): Array<{ locale: string; typeDir: string }> {
|
|
@@ -369,7 +389,12 @@ describe("structured data — every content page builds valid JSON-LD", () => {
|
|
|
369
389
|
|
|
370
390
|
it("finds content to check", () => {
|
|
371
391
|
if (SOURCE === "database") {
|
|
372
|
-
//
|
|
392
|
+
// #11941 D2 — no snapshot yet: the run is before any database build.
|
|
393
|
+
if (HUB_SKIP !== null) {
|
|
394
|
+
console.info(`structured-data: content walk not checked — ${HUB_SKIP}`);
|
|
395
|
+
return;
|
|
396
|
+
}
|
|
397
|
+
// A present snapshot that is unreadable or holds no page: misconfigured.
|
|
373
398
|
expect(HUB.problem).toBeNull();
|
|
374
399
|
return;
|
|
375
400
|
}
|
|
@@ -378,7 +403,8 @@ describe("structured data — every content page builds valid JSON-LD", () => {
|
|
|
378
403
|
expect(typeDirs.length).toBeGreaterThan(0);
|
|
379
404
|
});
|
|
380
405
|
|
|
381
|
-
it.
|
|
406
|
+
// #11941 D2 — a run with no snapshot has no table to walk; it says so above.
|
|
407
|
+
if (HUB_SKIP === null) it.each(typeDirs)(
|
|
382
408
|
"content/$locale/$typeDir — every page validates as its type",
|
|
383
409
|
async ({ locale, typeDir }) => {
|
|
384
410
|
if (!(SCHEMA_ORG_TYPES as readonly string[]).includes(typeDir)) {
|
|
@@ -831,6 +857,11 @@ describe("structured data — every route emits a valid JSON-LD script", () => {
|
|
|
831
857
|
DEFAULT_LOCALE,
|
|
832
858
|
);
|
|
833
859
|
if (page === null) {
|
|
860
|
+
// #11941 D3 — no snapshot yet: name the route, do not fail it.
|
|
861
|
+
if (HUB_SKIP !== null) {
|
|
862
|
+
console.info(`structured-data: ${label} not checked — ${HUB_SKIP}`);
|
|
863
|
+
return;
|
|
864
|
+
}
|
|
834
865
|
throw new Error(
|
|
835
866
|
SOURCE === "database"
|
|
836
867
|
? `${label}: renders ${type}/${identity.slug}, but the hub serves no such page (${SNAPSHOT_REL}) — the route serves 404 in production.`
|
|
@@ -857,7 +888,9 @@ describe("structured data — every route emits a valid JSON-LD script", () => {
|
|
|
857
888
|
slugs = served.map((p: ContentPage) => p.slug);
|
|
858
889
|
if (slugs.length === 0) {
|
|
859
890
|
console.info(
|
|
860
|
-
|
|
891
|
+
HUB_SKIP !== null
|
|
892
|
+
? `structured-data: ${label} not checked — ${HUB_SKIP}`
|
|
893
|
+
: `structured-data: ${label} has no ${type} content in ${DEFAULT_LOCALE}; every slug serves 404 in production — nothing to check`,
|
|
861
894
|
);
|
|
862
895
|
return;
|
|
863
896
|
}
|
|
@@ -1054,6 +1087,70 @@ describe("structured data — exemption(route, src) keys a standard magnet page
|
|
|
1054
1087
|
});
|
|
1055
1088
|
});
|
|
1056
1089
|
|
|
1090
|
+
// ── 2c. #11941 D4 — the skip rule, pinned in the default run ───────────────
|
|
1091
|
+
|
|
1092
|
+
describe("structured data — only a database run with no snapshot skips the hub's pages (#11941)", () => {
|
|
1093
|
+
// Reads a snapshot holding `body` (none when null) from a fresh temp dir.
|
|
1094
|
+
function readSnapshot(body: string | null) {
|
|
1095
|
+
const root = mkdtempSync(join(tmpdir(), "ailk-11941-sd-"));
|
|
1096
|
+
try {
|
|
1097
|
+
const path = join(root, "content-snapshot.json");
|
|
1098
|
+
if (body !== null) writeFileSync(path, body);
|
|
1099
|
+
return readHubPages(path);
|
|
1100
|
+
} finally {
|
|
1101
|
+
rmSync(root, { recursive: true, force: true });
|
|
1102
|
+
}
|
|
1103
|
+
}
|
|
1104
|
+
const UNREADABLE = "not json";
|
|
1105
|
+
const EMPTY = JSON.stringify({ version: 1, pages: {}, lists: {} });
|
|
1106
|
+
const ONE_PAGE = JSON.stringify({
|
|
1107
|
+
version: 1,
|
|
1108
|
+
pages: { "content:w:HomePage:home:en": {} },
|
|
1109
|
+
lists: {},
|
|
1110
|
+
});
|
|
1111
|
+
|
|
1112
|
+
it("reads an absent snapshot as absent, with the does-not-exist problem", () => {
|
|
1113
|
+
const hub = readSnapshot(null);
|
|
1114
|
+
expect(hub.absent).toBe(true);
|
|
1115
|
+
expect(hub.pages).toEqual([]);
|
|
1116
|
+
expect(hub.problem).toContain("does not exist");
|
|
1117
|
+
});
|
|
1118
|
+
|
|
1119
|
+
it("reads an unreadable snapshot as present, with the version-1 problem", () => {
|
|
1120
|
+
const hub = readSnapshot(UNREADABLE);
|
|
1121
|
+
expect(hub.absent).toBe(false);
|
|
1122
|
+
expect(hub.problem).toContain("is not a version-1 content snapshot");
|
|
1123
|
+
});
|
|
1124
|
+
|
|
1125
|
+
it("reads a snapshot with no page as present, with the holds-no-page problem", () => {
|
|
1126
|
+
const hub = readSnapshot(EMPTY);
|
|
1127
|
+
expect(hub.absent).toBe(false);
|
|
1128
|
+
expect(hub.problem).toContain("holds no page");
|
|
1129
|
+
});
|
|
1130
|
+
|
|
1131
|
+
it("reads a snapshot's pages from their cache tags", () => {
|
|
1132
|
+
const hub = readSnapshot(ONE_PAGE);
|
|
1133
|
+
expect(hub.absent).toBe(false);
|
|
1134
|
+
expect(hub.problem).toBeNull();
|
|
1135
|
+
expect(hub.pages).toEqual([{ type: "HomePage", slug: "home", locale: "en" }]);
|
|
1136
|
+
});
|
|
1137
|
+
|
|
1138
|
+
it("skips under database only when the snapshot is absent", () => {
|
|
1139
|
+
const absent = readSnapshot(null);
|
|
1140
|
+
expect(
|
|
1141
|
+
[absent, readSnapshot(UNREADABLE), readSnapshot(EMPTY), readSnapshot(ONE_PAGE)].map(
|
|
1142
|
+
(hub) => snapshotSkipReason("database", hub),
|
|
1143
|
+
),
|
|
1144
|
+
).toEqual([absent.problem, null, null, null]);
|
|
1145
|
+
});
|
|
1146
|
+
|
|
1147
|
+
it("never skips under a files-served source", () => {
|
|
1148
|
+
const absent = readSnapshot(null);
|
|
1149
|
+
expect(snapshotSkipReason("mdx", absent)).toBeNull();
|
|
1150
|
+
expect(snapshotSkipReason("projection", absent)).toBeNull();
|
|
1151
|
+
});
|
|
1152
|
+
});
|
|
1153
|
+
|
|
1057
1154
|
// ── 3. The two defect shapes that shipped, pinned ───────────────────────────
|
|
1058
1155
|
//
|
|
1059
1156
|
// These prove the checks above reach the validator rule that rejects each
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* `@working-theory/license` renews the deployment's key before it lapses and
|
|
5
5
|
* keeps the renewed key in a `LicenseKeyStore`. Its default store is a file,
|
|
6
6
|
* which a redeploy wipes — and this app's one real `checkLicense()` caller
|
|
7
|
-
* (`src/lib/commerce-claim.ts`, gating /purchase/*
|
|
7
|
+
* (`src/lib/commerce-claim.ts`, gating /purchase/*)
|
|
8
8
|
* would then run on the older `AILK_LICENSE_KEY` alone. With a database
|
|
9
9
|
* configured, this registers the store backed by ONE deployment-wide
|
|
10
10
|
* `SiteSetting` row, `(DEFAULT_WORKSPACE_ID, "license.renewed_key")`, shared
|
|
@@ -89,6 +89,16 @@ export interface McpOAuthDeps {
|
|
|
89
89
|
* carrying the entry is not this server's. Requires `issuerTag`.
|
|
90
90
|
*/
|
|
91
91
|
allWorkspaces?: boolean;
|
|
92
|
+
/**
|
|
93
|
+
* #12063 FR7 — clear outside-send switches, in every workspace: one
|
|
94
|
+
* person's for one client, or (no `applicationId`) every client of theirs.
|
|
95
|
+
* A switch never outlives the connection it was given to, so this runs when
|
|
96
|
+
* the person's line for a client ends (`/mcp/revoke`, `/mcp/revoke-client`,
|
|
97
|
+
* a changed password) and when a client and person with no live token
|
|
98
|
+
* consent again, which also covers a lapsed refresh and a disabled client.
|
|
99
|
+
* Absent: nothing is cleared.
|
|
100
|
+
*/
|
|
101
|
+
clearOutsideSendSwitches?(target: { userId: string; applicationId?: string }): Promise<void>;
|
|
92
102
|
}
|
|
93
103
|
|
|
94
104
|
/** The scopes `/mcp/authorize` accepts a request for. */
|
|
@@ -234,6 +244,7 @@ interface AuthorizationValue {
|
|
|
234
244
|
}
|
|
235
245
|
|
|
236
246
|
interface OAuthApplicationRow {
|
|
247
|
+
id: string;
|
|
237
248
|
clientId: string;
|
|
238
249
|
clientSecret?: string | null;
|
|
239
250
|
type?: string | null;
|
|
@@ -572,6 +583,14 @@ export function mcpOAuthPlugin(deps: McpOAuthDeps) {
|
|
|
572
583
|
`[auth-email] ${JSON.stringify({ userId, kind: "password-change", reason: "mcp_token_revocation_failed" })}`,
|
|
573
584
|
);
|
|
574
585
|
}
|
|
586
|
+
// #12063 FR7 — and their outside-send switches with them.
|
|
587
|
+
try {
|
|
588
|
+
await deps.clearOutsideSendSwitches?.({ userId });
|
|
589
|
+
} catch {
|
|
590
|
+
console.warn(
|
|
591
|
+
`[auth-email] ${JSON.stringify({ userId, kind: "password-change", reason: "outside_send_clear_failed" })}`,
|
|
592
|
+
);
|
|
593
|
+
}
|
|
575
594
|
}),
|
|
576
595
|
},
|
|
577
596
|
],
|
|
@@ -691,6 +710,22 @@ export function mcpOAuthPlugin(deps: McpOAuthDeps) {
|
|
|
691
710
|
});
|
|
692
711
|
}
|
|
693
712
|
|
|
713
|
+
// #12063 FR7 — a client and person with no live token are a new
|
|
714
|
+
// connection, so it starts off: whatever ended the last one (a
|
|
715
|
+
// lapsed refresh, a disabled client, a revoke elsewhere), an owner
|
|
716
|
+
// who let that one send did not let this one.
|
|
717
|
+
if (deps.clearOutsideSendSwitches) {
|
|
718
|
+
const live = await ctx.context.adapter.findOne({
|
|
719
|
+
model: "oauthAccessToken",
|
|
720
|
+
where: [
|
|
721
|
+
{ field: "clientId", value: value.clientId },
|
|
722
|
+
{ field: "userId", value: userId },
|
|
723
|
+
{ field: "refreshTokenExpiresAt", value: new Date(), operator: "gt" },
|
|
724
|
+
],
|
|
725
|
+
});
|
|
726
|
+
if (!live) await deps.clearOutsideSendSwitches({ applicationId: client.id, userId });
|
|
727
|
+
}
|
|
728
|
+
|
|
694
729
|
// `openid`, `profile` and `email` are never bound: no id_token.
|
|
695
730
|
const scope = [
|
|
696
731
|
// Always bound: the plugin issues and refreshes only for it, and
|
|
@@ -773,6 +808,22 @@ export function mcpOAuthPlugin(deps: McpOAuthDeps) {
|
|
|
773
808
|
throw refuse("UNAUTHORIZED", "invalid_client");
|
|
774
809
|
}
|
|
775
810
|
if (!token) throw refuse("BAD_REQUEST", "invalid_request");
|
|
811
|
+
// #12063 FR7 — whose line this token is, read before it goes.
|
|
812
|
+
const held =
|
|
813
|
+
(await ctx.context.adapter.findOne<{ userId?: string | null }>({
|
|
814
|
+
model: "oauthAccessToken",
|
|
815
|
+
where: [
|
|
816
|
+
{ field: "clientId", value: clientId },
|
|
817
|
+
{ field: "accessToken", value: token },
|
|
818
|
+
],
|
|
819
|
+
})) ??
|
|
820
|
+
(await ctx.context.adapter.findOne<{ userId?: string | null }>({
|
|
821
|
+
model: "oauthAccessToken",
|
|
822
|
+
where: [
|
|
823
|
+
{ field: "clientId", value: clientId },
|
|
824
|
+
{ field: "refreshToken", value: token },
|
|
825
|
+
],
|
|
826
|
+
}));
|
|
776
827
|
await deleteTokensOf(ctx, [
|
|
777
828
|
{ field: "clientId", value: clientId },
|
|
778
829
|
{ field: "accessToken", value: token },
|
|
@@ -781,6 +832,9 @@ export function mcpOAuthPlugin(deps: McpOAuthDeps) {
|
|
|
781
832
|
{ field: "clientId", value: clientId },
|
|
782
833
|
{ field: "refreshToken", value: token },
|
|
783
834
|
]);
|
|
835
|
+
if (held?.userId && deps.clearOutsideSendSwitches) {
|
|
836
|
+
await deps.clearOutsideSendSwitches({ applicationId: client.id, userId: held.userId });
|
|
837
|
+
}
|
|
784
838
|
return ctx.json({});
|
|
785
839
|
},
|
|
786
840
|
),
|
|
@@ -794,6 +848,16 @@ export function mcpOAuthPlugin(deps: McpOAuthDeps) {
|
|
|
794
848
|
{ field: "clientId", value: ctx.body.client_id },
|
|
795
849
|
{ field: "userId", value: ctx.context.session.user.id },
|
|
796
850
|
]);
|
|
851
|
+
// #12063 FR7 — the person's switches for this client go with it.
|
|
852
|
+
if (deps.clearOutsideSendSwitches) {
|
|
853
|
+
const app = await ctx.context.adapter.findOne<OAuthApplicationRow>({
|
|
854
|
+
model: "oauthApplication",
|
|
855
|
+
where: [{ field: "clientId", value: ctx.body.client_id }],
|
|
856
|
+
});
|
|
857
|
+
if (app) {
|
|
858
|
+
await deps.clearOutsideSendSwitches({ applicationId: app.id, userId: ctx.context.session.user.id });
|
|
859
|
+
}
|
|
860
|
+
}
|
|
797
861
|
return ctx.json({ revoked });
|
|
798
862
|
},
|
|
799
863
|
),
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The tools the site's own MCP server serves (#11951, spec
|
|
3
|
+
* docs/specs/11951-the-mcp-discovery-file-lists-spec.md D1–D3).
|
|
4
|
+
*
|
|
5
|
+
* `/.well-known/mcp.json` lists exactly what the MCP server's `tools/list`
|
|
6
|
+
* answers at `MCP_PUBLIC_HTTP_URL`, because only the MCP deployment knows
|
|
7
|
+
* which module packages it installed — a second copy of its registration rule
|
|
8
|
+
* here drifted by construction. `readServedMcpTools(url)` asks it over plain
|
|
9
|
+
* `fetch`, no MCP SDK: `initialize`, `notifications/initialized`, `tools/list`
|
|
10
|
+
* (following `nextCursor`, at most `MAX_PAGES` pages), then a `DELETE` when
|
|
11
|
+
* the server opened a session. One exchange serves both transport modes: a
|
|
12
|
+
* stateless server answers JSON with no session, a stateful one
|
|
13
|
+
* `text/event-stream` with an `Mcp-Session-Id` every later request carries.
|
|
14
|
+
*
|
|
15
|
+
* Every request carries `MCP_DISCOVERY_USER_AGENT`, because the server's abuse
|
|
16
|
+
* guard refuses a missing UA and the built-in client ones (`curl/`,
|
|
17
|
+
* `node-fetch`, …) with 403 — and one deadline, `MCP_TOOLS_TIMEOUT_MS`, bounds
|
|
18
|
+
* the whole exchange. One answer per URL per server instance for
|
|
19
|
+
* `MCP_TOOLS_TTL_MS` — `siteDiscoverable()`'s shape
|
|
20
|
+
* (`packages/api-client/src/discovery.ts`): concurrent and later requests
|
|
21
|
+
* inside the window share it, a failure included, so an outage never adds the
|
|
22
|
+
* deadline to every manifest request.
|
|
23
|
+
*
|
|
24
|
+
* #11978 D3 — `readMcpServer(url)` is the same one exchange and the same
|
|
25
|
+
* shared answer, told apart for the site's status report: `answering` (with
|
|
26
|
+
* the tools, and the loaded packs' tool names the server reports in its
|
|
27
|
+
* `initialize` answer under `capabilities.experimental["ailk/installed"]`, or
|
|
28
|
+
* `null` from a server that reports none), `refused` when `initialize`
|
|
29
|
+
* answered HTTP 404 (the server is hidden, #10510), and `unreachable` for
|
|
30
|
+
* every other failure below. `readServedMcpTools(url)` is its tools when
|
|
31
|
+
* answering, else `null`, so mcp.json's answers are unchanged.
|
|
32
|
+
*
|
|
33
|
+
* A failed read is `null` — a throw, the deadline, a non-2xx `initialize` or
|
|
34
|
+
* `tools/list`, no JSON-RPC answer with the request's `id`, an `error`
|
|
35
|
+
* answer, a `result.tools` that is not an array, an entry with no string
|
|
36
|
+
* `name` or no object `inputSchema`, or a tenth page still carrying
|
|
37
|
+
* `nextCursor`. The closing `DELETE` is courtesy, sent whenever `initialize`
|
|
38
|
+
* opened a session: its answer is not read, and its failure fails nothing.
|
|
39
|
+
* It never rejects.
|
|
40
|
+
*/
|
|
41
|
+
|
|
42
|
+
import { MCP_INSTALLED_CAPABILITY } from "@working-theory/validation";
|
|
43
|
+
|
|
44
|
+
/** Names this caller and its purpose to the server's user-agent guard. */
|
|
45
|
+
export const MCP_DISCOVERY_USER_AGENT = "ailk-web/mcp-discovery";
|
|
46
|
+
/** The MCP protocol version this site speaks and its manifest advertises. */
|
|
47
|
+
export const MCP_PROTOCOL_VERSION = "2025-03-26";
|
|
48
|
+
/** Shared per URL per instance for this long. */
|
|
49
|
+
export const MCP_TOOLS_TTL_MS = 60_000;
|
|
50
|
+
/** The whole exchange, every request together, is bounded by this. */
|
|
51
|
+
export const MCP_TOOLS_TIMEOUT_MS = 3_000;
|
|
52
|
+
|
|
53
|
+
const MAX_PAGES = 10;
|
|
54
|
+
|
|
55
|
+
/** One `tools/list` entry, as the manifest needs it. */
|
|
56
|
+
export interface ServedMcpTool {
|
|
57
|
+
name: string;
|
|
58
|
+
description?: string;
|
|
59
|
+
inputSchema: Record<string, unknown>;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** #11978 D3 — what the MCP server at a URL answered. */
|
|
63
|
+
export type McpServerAnswer =
|
|
64
|
+
| { state: "answering"; tools: ServedMcpTool[]; installed: string[] | null }
|
|
65
|
+
| { state: "refused" }
|
|
66
|
+
| { state: "unreachable" };
|
|
67
|
+
|
|
68
|
+
const REFUSED: McpServerAnswer = { state: "refused" };
|
|
69
|
+
const UNREACHABLE: McpServerAnswer = { state: "unreachable" };
|
|
70
|
+
|
|
71
|
+
type JsonRpcMessage = { id?: unknown; result?: unknown; error?: unknown };
|
|
72
|
+
|
|
73
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
74
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function parseJson(text: string): unknown {
|
|
78
|
+
try {
|
|
79
|
+
return JSON.parse(text) as unknown;
|
|
80
|
+
} catch {
|
|
81
|
+
return undefined;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** The JSON-RPC answer to request `id` in a reply body, read by its content type. */
|
|
86
|
+
async function answerTo(res: Response, id: number): Promise<JsonRpcMessage | null> {
|
|
87
|
+
const type = res.headers.get("content-type") ?? "";
|
|
88
|
+
const text = await res.text();
|
|
89
|
+
const messages: unknown[] = [];
|
|
90
|
+
if (type.includes("text/event-stream")) {
|
|
91
|
+
for (const event of text.split(/\r?\n\r?\n/)) {
|
|
92
|
+
const data = event
|
|
93
|
+
.split(/\r?\n/)
|
|
94
|
+
.filter((line) => line.startsWith("data:"))
|
|
95
|
+
.map((line) => line.slice(5).replace(/^ /, ""))
|
|
96
|
+
.join("\n");
|
|
97
|
+
if (data) messages.push(parseJson(data));
|
|
98
|
+
}
|
|
99
|
+
} else if (type.includes("application/json")) {
|
|
100
|
+
messages.push(parseJson(text));
|
|
101
|
+
}
|
|
102
|
+
const answer = messages.find((m) => isRecord(m) && m["id"] === id);
|
|
103
|
+
return isRecord(answer) ? answer : null;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function toServedTool(entry: unknown): ServedMcpTool | null {
|
|
107
|
+
if (!isRecord(entry)) return null;
|
|
108
|
+
const { name, description, inputSchema } = entry;
|
|
109
|
+
if (typeof name !== "string" || !isRecord(inputSchema)) return null;
|
|
110
|
+
return {
|
|
111
|
+
name,
|
|
112
|
+
...(typeof description === "string" ? { description } : {}),
|
|
113
|
+
inputSchema,
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/** #11978 D4 — the loaded packs' tool names from an `initialize` result, or `null`. */
|
|
118
|
+
function installedOf(result: Record<string, unknown>): string[] | null {
|
|
119
|
+
const capabilities = result["capabilities"];
|
|
120
|
+
const experimental = isRecord(capabilities) ? capabilities["experimental"] : undefined;
|
|
121
|
+
const entry = isRecord(experimental) ? experimental[MCP_INSTALLED_CAPABILITY] : undefined;
|
|
122
|
+
const tools = isRecord(entry) ? entry["tools"] : undefined;
|
|
123
|
+
return Array.isArray(tools) && tools.every((name) => typeof name === "string")
|
|
124
|
+
? (tools as string[])
|
|
125
|
+
: null;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
async function exchange(url: string): Promise<McpServerAnswer> {
|
|
129
|
+
const signal = AbortSignal.timeout(MCP_TOOLS_TIMEOUT_MS);
|
|
130
|
+
const headers: Record<string, string> = {
|
|
131
|
+
"user-agent": MCP_DISCOVERY_USER_AGENT,
|
|
132
|
+
accept: "application/json, text/event-stream",
|
|
133
|
+
};
|
|
134
|
+
let nextId = 1;
|
|
135
|
+
let lastStatus = 0;
|
|
136
|
+
|
|
137
|
+
const post = (body: Record<string, unknown>): Promise<Response> =>
|
|
138
|
+
fetch(url, {
|
|
139
|
+
method: "POST",
|
|
140
|
+
// The transport answers a POST that is not application/json with 415.
|
|
141
|
+
headers: { ...headers, "content-type": "application/json" },
|
|
142
|
+
body: JSON.stringify({ jsonrpc: "2.0", ...body }),
|
|
143
|
+
cache: "no-store",
|
|
144
|
+
signal,
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
/** One request: its answer's `result` and the reply, or `null` on any failure shape. */
|
|
148
|
+
const call = async (
|
|
149
|
+
method: string,
|
|
150
|
+
params: Record<string, unknown>,
|
|
151
|
+
): Promise<{ result: Record<string, unknown>; res: Response } | null> => {
|
|
152
|
+
const id = nextId++;
|
|
153
|
+
const res = await post({ id, method, params });
|
|
154
|
+
lastStatus = res.status;
|
|
155
|
+
if (!res.ok) {
|
|
156
|
+
await res.body?.cancel();
|
|
157
|
+
return null;
|
|
158
|
+
}
|
|
159
|
+
const answer = await answerTo(res, id);
|
|
160
|
+
if (answer === null || answer.error !== undefined || !isRecord(answer.result)) return null;
|
|
161
|
+
return { result: answer.result, res };
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
const init = await call("initialize", {
|
|
165
|
+
protocolVersion: MCP_PROTOCOL_VERSION,
|
|
166
|
+
capabilities: {},
|
|
167
|
+
clientInfo: { name: "ailk-web", version: "1" },
|
|
168
|
+
});
|
|
169
|
+
// #11978 D3 — a hidden server answers `initialize` with Fastify's 404.
|
|
170
|
+
if (init === null) return lastStatus === 404 ? REFUSED : UNREACHABLE;
|
|
171
|
+
const sessionId = init.res.headers.get("mcp-session-id");
|
|
172
|
+
const version = init.result["protocolVersion"];
|
|
173
|
+
headers["mcp-protocol-version"] =
|
|
174
|
+
typeof version === "string" ? version : MCP_PROTOCOL_VERSION;
|
|
175
|
+
if (sessionId) headers["mcp-session-id"] = sessionId;
|
|
176
|
+
|
|
177
|
+
try {
|
|
178
|
+
// The lifecycle's required notice; its answer is not read.
|
|
179
|
+
await (await post({ method: "notifications/initialized" })).body?.cancel();
|
|
180
|
+
|
|
181
|
+
const tools: ServedMcpTool[] = [];
|
|
182
|
+
let cursor: string | undefined;
|
|
183
|
+
for (let page = 0; page < MAX_PAGES; page++) {
|
|
184
|
+
const listed = await call("tools/list", cursor === undefined ? {} : { cursor });
|
|
185
|
+
if (listed === null || !Array.isArray(listed.result["tools"])) return UNREACHABLE;
|
|
186
|
+
for (const entry of listed.result["tools"] as unknown[]) {
|
|
187
|
+
const tool = toServedTool(entry);
|
|
188
|
+
if (tool === null) return UNREACHABLE;
|
|
189
|
+
tools.push(tool);
|
|
190
|
+
}
|
|
191
|
+
const next = listed.result["nextCursor"];
|
|
192
|
+
cursor = typeof next === "string" ? next : undefined;
|
|
193
|
+
if (cursor === undefined) break;
|
|
194
|
+
}
|
|
195
|
+
return cursor === undefined
|
|
196
|
+
? { state: "answering", tools, installed: installedOf(init.result) }
|
|
197
|
+
: UNREACHABLE;
|
|
198
|
+
} finally {
|
|
199
|
+
if (sessionId) {
|
|
200
|
+
// End the stateful session, whatever the list's outcome. No
|
|
201
|
+
// content-type: the server refuses an empty JSON body. Courtesy only —
|
|
202
|
+
// its answer is not read, and its failure fails nothing.
|
|
203
|
+
await fetch(url, { method: "DELETE", headers, cache: "no-store", signal })
|
|
204
|
+
.then((res) => res.body?.cancel())
|
|
205
|
+
.catch(() => undefined);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
const held = new Map<string, { at: number; answer: Promise<McpServerAnswer> }>();
|
|
211
|
+
|
|
212
|
+
/** #11978 D3 — what the MCP server at `url` answered. Never rejects. */
|
|
213
|
+
export function readMcpServer(url: string): Promise<McpServerAnswer> {
|
|
214
|
+
const now = Date.now();
|
|
215
|
+
const hit = held.get(url);
|
|
216
|
+
if (hit !== undefined && now - hit.at < MCP_TOOLS_TTL_MS) return hit.answer;
|
|
217
|
+
const answer = exchange(url).catch(() => UNREACHABLE);
|
|
218
|
+
held.set(url, { at: now, answer });
|
|
219
|
+
return answer;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/** #11951 D2 — the tools the MCP server at `url` serves, or `null`. Never rejects. */
|
|
223
|
+
export async function readServedMcpTools(url: string): Promise<ServedMcpTool[] | null> {
|
|
224
|
+
const answer = await readMcpServer(url);
|
|
225
|
+
return answer.state === "answering" ? answer.tools : null;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/** Test seam: forget every held answer. */
|
|
229
|
+
export function __resetServedMcpToolsForTests(): void {
|
|
230
|
+
held.clear();
|
|
231
|
+
}
|
|
@@ -22,7 +22,10 @@
|
|
|
22
22
|
* in the key (D2).
|
|
23
23
|
*
|
|
24
24
|
* The module holds no user-visible copy: the CTA label, the recommended label
|
|
25
|
-
* and the period phrasings arrive in `labels` (D9, customer-facing-i18n).
|
|
25
|
+
* and the period phrasings arrive in `labels` (D9, customer-facing-i18n). A
|
|
26
|
+
* seller's own button label (`ctaLabel`, Stripe `ailk_cta`) and an add-on's
|
|
27
|
+
* eyebrow (`ailk_eyebrow`) are seller-authored text shown as written, as the
|
|
28
|
+
* product name is (#12103 D1, D5).
|
|
26
29
|
*/
|
|
27
30
|
import {
|
|
28
31
|
parseLookupKey,
|
|
@@ -45,7 +48,7 @@ type PricingAddonTile = NonNullable<PricingSectionData["addons"]>[number] & {
|
|
|
45
48
|
};
|
|
46
49
|
|
|
47
50
|
export interface OfferingsPricingLabels {
|
|
48
|
-
/** The CTA label on every card and tile. */
|
|
51
|
+
/** The CTA label on every card and tile whose product sets none of its own. */
|
|
49
52
|
cta: string;
|
|
50
53
|
/** The recommended plan's pill and the recommended add-on's eyebrow. */
|
|
51
54
|
recommended: string;
|
|
@@ -175,6 +178,12 @@ function stripFormatCharacters(text: string, keepNewlines = false): string {
|
|
|
175
178
|
);
|
|
176
179
|
}
|
|
177
180
|
|
|
181
|
+
/** The product's own button label (#12103 D1), else the translated default. */
|
|
182
|
+
function ctaLabel(product: OfferingsProduct, labels: OfferingsPricingLabels): string {
|
|
183
|
+
const own = product.ctaLabel && stripFormatCharacters(product.ctaLabel);
|
|
184
|
+
return own || labels.cta;
|
|
185
|
+
}
|
|
186
|
+
|
|
178
187
|
function features(product: OfferingsProduct): string[] {
|
|
179
188
|
return product.marketingFeatures
|
|
180
189
|
.map((feature) => stripFormatCharacters(feature))
|
|
@@ -255,7 +264,7 @@ function bundleCard(
|
|
|
255
264
|
name: stripFormatCharacters(product.name),
|
|
256
265
|
price,
|
|
257
266
|
features: features(product),
|
|
258
|
-
cta: { label: labels
|
|
267
|
+
cta: { label: ctaLabel(product, labels), href },
|
|
259
268
|
};
|
|
260
269
|
// The deposit note wins the footnote; the terms note shows only without one.
|
|
261
270
|
// NO_HAND_IMPLEMENT_OK: builder-assessors run for #10030 — the builder is the implementer.
|
|
@@ -297,7 +306,7 @@ function planCard(
|
|
|
297
306
|
name: stripFormatCharacters(product.name),
|
|
298
307
|
price,
|
|
299
308
|
features: features(product),
|
|
300
|
-
cta: { label: labels
|
|
309
|
+
cta: { label: ctaLabel(product, labels), href },
|
|
301
310
|
};
|
|
302
311
|
const description =
|
|
303
312
|
product.description && stripFormatCharacters(product.description, true);
|
|
@@ -339,10 +348,16 @@ function addonTile(
|
|
|
339
348
|
name: stripFormatCharacters(product.name),
|
|
340
349
|
price: phrase(shown, locale, labels),
|
|
341
350
|
features: features(product),
|
|
342
|
-
cta: { label: labels
|
|
351
|
+
cta: { label: ctaLabel(product, labels), href },
|
|
343
352
|
};
|
|
344
353
|
if (product.unitLabel)
|
|
345
354
|
tile.qualifier = stripFormatCharacters(product.unitLabel);
|
|
355
|
+
// #12103 D5 — the seller's eyebrow and note; the recommended add-on's
|
|
356
|
+
// eyebrow stays the Recommended label, the one place a tile shows it.
|
|
357
|
+
const eyebrow = product.eyebrow && stripFormatCharacters(product.eyebrow);
|
|
358
|
+
if (eyebrow) tile.eyebrow = eyebrow;
|
|
359
|
+
const note = product.note && stripFormatCharacters(product.note);
|
|
360
|
+
if (note) tile.note = note;
|
|
346
361
|
if (highlighted) {
|
|
347
362
|
tile.eyebrow = labels.recommended;
|
|
348
363
|
tile.checkTone = "primary";
|
|
@@ -393,6 +408,10 @@ function narrowToPlans(
|
|
|
393
408
|
* `plans` (#10044 D4) narrows the set to an offering page's own products:
|
|
394
409
|
* those whose `{plan}` it lists, plus every product a kept one `requires`, in
|
|
395
410
|
* the snapshot's order. Absent, every shown product is mapped, as before.
|
|
411
|
+
*
|
|
412
|
+
* `exclude` (#12103 D2) drops the plan cards of the plans it lists — the ones
|
|
413
|
+
* a section's own `offeringPlans` already shows — so the page's unlisted
|
|
414
|
+
* plans section does not show them twice. Add-on tiles are unaffected.
|
|
396
415
|
*/
|
|
397
416
|
export function offeringsPricing(
|
|
398
417
|
shownSet: unknown,
|
|
@@ -400,6 +419,7 @@ export function offeringsPricing(
|
|
|
400
419
|
locale: string;
|
|
401
420
|
labels: OfferingsPricingLabels;
|
|
402
421
|
plans?: readonly string[] | undefined;
|
|
422
|
+
exclude?: readonly string[] | undefined;
|
|
403
423
|
},
|
|
404
424
|
): OfferingsPricing | null {
|
|
405
425
|
const parsed = shownSetSchema.safeParse(shownSet);
|
|
@@ -415,9 +435,13 @@ export function offeringsPricing(
|
|
|
415
435
|
shown.map((o) => o.requires).filter((plan) => plan !== undefined),
|
|
416
436
|
);
|
|
417
437
|
const offerings = narrowToPlans(shown, options.plans);
|
|
438
|
+
const excluded = new Set(options.exclude);
|
|
418
439
|
// #11166 — the two group reads are exact, so an `offer` falls into neither.
|
|
419
440
|
const planProducts = offerings.filter(
|
|
420
|
-
(o) =>
|
|
441
|
+
(o) =>
|
|
442
|
+
o.ailkGroup === "plan" &&
|
|
443
|
+
!requiredPlans.has(o.plan) &&
|
|
444
|
+
!excluded.has(o.plan),
|
|
421
445
|
);
|
|
422
446
|
const addonProducts = offerings.filter((o) => o.ailkGroup === "addon");
|
|
423
447
|
const recommendedPlan = firstRecommended(planProducts);
|