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.
Files changed (57) hide show
  1. package/README.md +6 -3
  2. package/component-catalog.json +24 -1
  3. package/component-catalog.md +6 -5
  4. package/dist/add-module.d.ts +7 -0
  5. package/dist/add-module.js +17 -2
  6. package/dist/apply-design.js +1 -12
  7. package/dist/lib/env-catalog.js +2 -2
  8. package/dist/lib/import-mdx.js +10 -2
  9. package/dist/lib/license-key-files.d.ts +2 -0
  10. package/dist/lib/license-key-files.js +11 -0
  11. package/dist/paid-sections.d.ts +19 -0
  12. package/dist/paid-sections.js +41 -0
  13. package/dist/programmatic.js +56 -6
  14. package/dist/seed-workspace.d.ts +1 -1
  15. package/dist/seed-workspace.js +10 -3
  16. package/dist/surfaces.js +1 -1
  17. package/dist/update.d.ts +21 -2
  18. package/dist/update.js +188 -10
  19. package/package.json +3 -3
  20. package/templates/apps/api/.env.example +23 -0
  21. package/templates/apps/api/CLAUDE.md +17 -7
  22. package/templates/apps/api/src/lib/__mocks__/prisma.ts +11 -0
  23. package/templates/apps/mcp/.env.example +14 -3
  24. package/templates/apps/mcp/CLAUDE.md +47 -24
  25. package/templates/apps/mcp/src/index.ts +1 -1
  26. package/templates/apps/web/.env.example +1 -1
  27. package/templates/apps/web/CLAUDE.md +47 -16
  28. package/templates/apps/web/app/.well-known/mcp.json/build-manifest.ts +44 -41
  29. package/templates/apps/web/app/.well-known/mcp.json/route.ts +24 -33
  30. package/templates/apps/web/app/[locale]/layout.tsx +10 -7
  31. package/templates/apps/web/app/api/site-status/__tests__/route.test.ts +120 -0
  32. package/templates/apps/web/app/api/site-status/route.ts +62 -0
  33. package/templates/apps/web/app/llms.txt/route.ts +3 -3
  34. package/templates/apps/web/app/openapi.json/__tests__/route.test.ts +21 -4
  35. package/templates/apps/web/app/openapi.json/route.ts +10 -9
  36. package/templates/apps/web/app/sitemap.xml/route.ts +3 -3
  37. package/templates/apps/web/auth.ts +25 -1
  38. package/templates/apps/web/lib/__tests__/fixtures/mcp-stub-server.ts +245 -0
  39. package/templates/apps/web/lib/__tests__/mcp-served-tools.test.ts +395 -0
  40. package/templates/apps/web/lib/__tests__/offerings-pricing.test.ts +112 -0
  41. package/templates/apps/web/lib/__tests__/pricing-page.test.ts +280 -0
  42. package/templates/apps/web/lib/__tests__/site-brand.test.ts +5 -6
  43. package/templates/apps/web/lib/__tests__/site-visibility.test.ts +64 -0
  44. package/templates/apps/web/lib/__tests__/structured-data.test.tsx +108 -11
  45. package/templates/apps/web/lib/license-key-store.ts +1 -1
  46. package/templates/apps/web/lib/mcp-oauth.ts +64 -0
  47. package/templates/apps/web/lib/mcp-served-tools.ts +231 -0
  48. package/templates/apps/web/lib/offerings-pricing.ts +30 -6
  49. package/templates/apps/web/lib/pricing-page.ts +142 -35
  50. package/templates/apps/web/lib/site-brand.tsx +1 -7
  51. package/templates/apps/web/lib/site-visibility.ts +45 -0
  52. package/templates/apps/web/messages/en.json +8 -0
  53. package/templates/apps/web/middleware.ts +16 -1
  54. package/templates/apps/web/src/lib/routes.ts +3 -3
  55. package/versions.json +51 -51
  56. package/templates/apps/web/app/.well-known/ai-plugin.json/route.ts +0 -93
  57. package/templates/apps/web/lib/release-scope.ts +0 -47
@@ -7,35 +7,30 @@
7
7
  * The endpoint is advertised only when MCP_PUBLIC_HTTP_URL configures one
8
8
  * (#7396) — apps/web serves no MCP endpoint itself.
9
9
  *
10
- * Assembly — no fetch(). The catalog is read in-process from
11
- * @working-theory/metadata; the AILK version is read from this app's
12
- * package.json; the `commerce` add-on claim is read locally through
13
- * `checkLicense()` (#5971) so an add-on-gated tool is advertised on exactly
14
- * the deployments whose MCP server registers it. Without that, a KEYED site
15
- * would register `start_purchase` while hiding it from its own manifest —
16
- * the surface disagreement `apps/mcp/__tests__/catalog-drift.test.ts` exists
17
- * to make impossible. The same single read also yields the licence features
18
- * the deployment holds (#7136), which gate the five `feature`-tagged tools
19
- * here exactly as they gate registration on the MCP server. `create_project`
20
- * is always left out: this manifest describes the HTTP surface, and the MCP
21
- * server serves that tool over stdio only (#9965 D13, #8584).
10
+ * The tools are the MCP server's own (#11951). The route asks the server at
11
+ * MCP_PUBLIC_HTTP_URL for its `tools/list` (`lib/mcp-served-tools.ts`, one
12
+ * answer per URL per instance for 60 s) and lists exactly that, in its order.
13
+ * Only the MCP deployment knows which module packages it installed, so the
14
+ * licence, commerce-claim and topology gates this route once copied from its
15
+ * registration rule (#5971, #7136, #8070) drifted by construction: the
16
+ * server applies them itself. `create_project` is absent because the HTTP
17
+ * transport never lists it (#9965 D13). When the server cannot be read the
18
+ * manifest lists no tools — never a guess — and answers `no-store`; with no
19
+ * MCP_PUBLIC_HTTP_URL there is no server to ask, and it lists none. The
20
+ * catalog in @working-theory/metadata only supplies each known tool's entry;
21
+ * the AILK version is read from this app's package.json.
22
22
  *
23
- * Mirrors /.well-known/ai-plugin.json conventions: Response.json with a
24
- * conservative cache-control header.
23
+ * Response.json with a conservative cache-control header (a day; `no-store`
24
+ * on a failed read).
25
25
  *
26
26
  * CORS: MCP discovery clients are cross-origin by design. The open GET is
27
27
  * public — no credentials, no session-scoped data — so Access-Control-Allow-Origin: *
28
28
  * is appropriate per the MCP discovery spec.
29
29
  */
30
30
 
31
- import { siteDiscoverable } from "@working-theory/api-client";
32
-
33
- import { UNSERVED_MCP_TOOLS } from "../../../lib/topology.generated";
31
+ import { readServedMcpTools } from "../../../lib/mcp-served-tools";
32
+ import { siteHidden } from "../../../lib/site-visibility";
34
33
  import packageJson from "../../../package.json";
35
- import {
36
- COMMERCE_FEATURE,
37
- resolveLicenceFeatures,
38
- } from "../../../src/lib/commerce-claim";
39
34
 
40
35
  import { buildMcpManifest } from "./build-manifest";
41
36
 
@@ -57,8 +52,9 @@ export function OPTIONS(): Response {
57
52
  }
58
53
 
59
54
  export async function GET(): Promise<Response> {
60
- // #10510 D4 — hidden by the owner: 404, never cached, before the licence read.
61
- if (!(await siteDiscoverable())) {
55
+ // #11978 D2 — Hidden (STEALTH or the owner's switch): 404, never cached,
56
+ // before the MCP server is asked (#11951).
57
+ if (await siteHidden()) {
62
58
  return new Response(null, {
63
59
  status: 404,
64
60
  headers: { "cache-control": "no-store", ...CORS_HEADERS },
@@ -71,18 +67,12 @@ export async function GET(): Promise<Response> {
71
67
  const mcpHttpUrlEnv = process.env["MCP_PUBLIC_HTTP_URL"];
72
68
  // With it, the site's pinned issuer turns on the OAuth metadata (#10392).
73
69
  const authIssuerEnv = process.env["BETTER_AUTH_URL"];
74
- const heldFeatures = await resolveLicenceFeatures();
70
+ // #11951 D4 — the server's own tools/list; `null` is a failed read.
71
+ const served = mcpHttpUrlEnv ? await readServedMcpTools(mcpHttpUrlEnv) : [];
75
72
 
76
73
  const manifest = buildMcpManifest({
77
74
  ailkVersion: packageJson.version,
78
- commerceClaimed: heldFeatures.includes(COMMERCE_FEATURE),
79
- heldFeatures,
80
- // The tools this topology's MCP server does not register (#8070 D7) —
81
- // and create_project, which the HTTP transport never serves (#9965 D13).
82
- unservedTools: [
83
- ...UNSERVED_MCP_TOOLS.filter((name) => name !== "create_project"),
84
- "create_project",
85
- ],
75
+ servedTools: served ?? [],
86
76
  // Spread conditional to satisfy exactOptionalPropertyTypes: omit the key
87
77
  // entirely when the env var is not set rather than passing undefined.
88
78
  ...(mcpHttpUrlEnv ? { mcpHttpUrl: mcpHttpUrlEnv } : {}),
@@ -92,7 +82,8 @@ export async function GET(): Promise<Response> {
92
82
  return Response.json(manifest, {
93
83
  status: 200,
94
84
  headers: {
95
- "cache-control": "public, max-age=86400",
85
+ // A failed read is a passing state no client should keep (#11951 D4).
86
+ "cache-control": served === null ? "no-store" : "public, max-age=86400",
96
87
  ...CORS_HEADERS,
97
88
  },
98
89
  });
@@ -131,6 +131,7 @@ import "../../lib/site-identity";
131
131
  // (#7521). Inert without AILK_LISTING_PUBLIC_KEY or the paid package.
132
132
  import "../../lib/listings";
133
133
  import { siteThemeHead } from "../../lib/site-theme-head";
134
+ import { siteHidden } from "../../lib/site-visibility";
134
135
  import {
135
136
  SIGN_IN_PATH,
136
137
  SIGN_UP_PATH,
@@ -298,9 +299,15 @@ export async function generateMetadata(): Promise<Metadata> {
298
299
  // none of its own: the request's own URL, never the home page's.
299
300
  const requestUrl = pathname === "/" ? baseUrl : `${baseUrl}${pathname}`;
300
301
 
301
- // #11456 D6 — `STEALTH` wins; otherwise the hub's Allow search indexing
302
- // off answers `noindex, follow` on every page that sets no robots of its own.
302
+ // #11978 D2 — `STEALTH` wins; otherwise Site visibility Hidden answers
303
+ // `noindex, nofollow` on every page that sets no robots of its own.
303
304
  const stealthRobots = getStealthRobots();
305
+ const robots =
306
+ "robots" in stealthRobots
307
+ ? stealthRobots
308
+ : (await siteHidden())
309
+ ? { robots: { index: false, follow: false } }
310
+ : {};
304
311
 
305
312
  return {
306
313
  title: brand.siteName,
@@ -318,11 +325,7 @@ export async function generateMetadata(): Promise<Metadata> {
318
325
  description: brand.description,
319
326
  images: [ogImageUrl],
320
327
  },
321
- ...("robots" in stealthRobots
322
- ? stealthRobots
323
- : brand.indexable
324
- ? {}
325
- : { robots: { index: false, follow: true } }),
328
+ ...robots,
326
329
  alternates: {
327
330
  canonical: requestUrl,
328
331
  languages,
@@ -0,0 +1,120 @@
1
+ /**
2
+ * @jest-environment node
3
+ */
4
+
5
+ /**
6
+ * GET /api/site-status (#11978 D3, AC-3 (a), AC-5 (b)). The owner's switch is
7
+ * mocked at its HTTP boundary (`siteDiscoverable`), STEALTH is the env var,
8
+ * and the MCP server is a `node:http` stub of its `/mcp` route.
9
+ */
10
+
11
+ import { siteStatusSchema } from "@working-theory/validation";
12
+
13
+ import { __resetServedMcpToolsForTests } from "../../../../lib/mcp-served-tools";
14
+ import { PUBLIC_PAGES } from "../../../../lib/modules.generated";
15
+ import {
16
+ startMcpStub,
17
+ type McpStub,
18
+ } from "../../../../lib/__tests__/fixtures/mcp-stub-server";
19
+ import { GET } from "../route";
20
+
21
+ const mockSiteDiscoverable = jest.fn<Promise<boolean>, []>();
22
+ jest.mock("@working-theory/api-client", () => ({
23
+ ...jest.requireActual<typeof import("@working-theory/api-client")>(
24
+ "@working-theory/api-client",
25
+ ),
26
+ siteDiscoverable: () => mockSiteDiscoverable(),
27
+ }));
28
+
29
+ const ENV = ["STEALTH", "MCP_PUBLIC_HTTP_URL"] as const;
30
+ const saved = new Map(ENV.map((key) => [key, process.env[key]]));
31
+ const stubs: McpStub[] = [];
32
+
33
+ beforeEach(() => {
34
+ __resetServedMcpToolsForTests();
35
+ mockSiteDiscoverable.mockReset().mockResolvedValue(true);
36
+ for (const key of ENV) delete process.env[key];
37
+ });
38
+
39
+ afterEach(async () => {
40
+ await Promise.all(stubs.splice(0).map((s) => s.close()));
41
+ });
42
+
43
+ afterAll(() => {
44
+ for (const [key, value] of saved) {
45
+ if (value === undefined) delete process.env[key];
46
+ else process.env[key] = value;
47
+ }
48
+ });
49
+
50
+ async function report(): Promise<{ response: Response; body: unknown }> {
51
+ const response = await GET();
52
+ return { response, body: await response.json() };
53
+ }
54
+
55
+ function expectMachineHeaders(response: Response): void {
56
+ expect(response.status).toBe(200);
57
+ expect(response.headers.get("cache-control")).toBe("no-store");
58
+ expect(response.headers.get("x-robots-tag")).toBe("noindex, nofollow, noarchive");
59
+ expect(response.headers.get("set-cookie")).toBeNull();
60
+ }
61
+
62
+ describe("GET /api/site-status — visibility and the hosting lock (AC-3 (a))", () => {
63
+ it("STEALTH: hidden, locked by hosting, and no hub read", async () => {
64
+ process.env["STEALTH"] = "true";
65
+ const { response, body } = await report();
66
+ expectMachineHeaders(response);
67
+ expect(body).toEqual({
68
+ visibility: "hidden",
69
+ lock: "hosting",
70
+ // The module list decides it: a site with no public page (a hub) reads false.
71
+ publicPages: PUBLIC_PAGES,
72
+ mcp: { state: "none" },
73
+ });
74
+ expect(mockSiteDiscoverable).not.toHaveBeenCalled();
75
+ expect(siteStatusSchema.parse(body)).toEqual(body);
76
+ });
77
+
78
+ it("STEALTH unset, the switch off: hidden, no lock", async () => {
79
+ mockSiteDiscoverable.mockResolvedValue(false);
80
+ const { response, body } = await report();
81
+ expectMachineHeaders(response);
82
+ expect(body).toMatchObject({ visibility: "hidden", lock: null });
83
+ expect(siteStatusSchema.safeParse(body).success).toBe(true);
84
+ });
85
+
86
+ it("STEALTH unset, the switch on: live, no lock", async () => {
87
+ const { response, body } = await report();
88
+ expectMachineHeaders(response);
89
+ expect(body).toMatchObject({ visibility: "live", lock: null });
90
+ expect(siteStatusSchema.safeParse(body).success).toBe(true);
91
+ });
92
+ });
93
+
94
+ describe("GET /api/site-status — the MCP server's answer (AC-5 (b))", () => {
95
+ it("MCP_PUBLIC_HTTP_URL unset → none", async () => {
96
+ expect((await report()).body).toMatchObject({ mcp: { state: "none" } });
97
+ });
98
+
99
+ it("an answering server → its tool names and installed names, nothing else", async () => {
100
+ const server = await startMcpStub({
101
+ mode: "stateless",
102
+ tools: [{ name: "search_content", description: "Search.", inputSchema: { type: "object" } }],
103
+ experimental: { "ailk/installed": { tools: ["create_booking"] } },
104
+ });
105
+ stubs.push(server);
106
+ process.env["MCP_PUBLIC_HTTP_URL"] = server.url;
107
+ const { body } = await report();
108
+ expect(body).toMatchObject({
109
+ mcp: { state: "answering", tools: ["search_content"], installed: ["create_booking"] },
110
+ });
111
+ expect(JSON.stringify(body)).not.toContain(server.url);
112
+ });
113
+
114
+ it("a server refusing initialize with 404 → refused", async () => {
115
+ const server = await startMcpStub({ mode: "stateless", tools: [], override: () => ({ status: 404 }) });
116
+ stubs.push(server);
117
+ process.env["MCP_PUBLIC_HTTP_URL"] = server.url;
118
+ expect((await report()).body).toMatchObject({ mcp: { state: "refused" } });
119
+ });
120
+ });
@@ -0,0 +1,62 @@
1
+ /**
2
+ * GET /api/site-status — the site's own report of its visibility (#11978 D3,
3
+ * spec docs/specs/11978-one-site-visibility-control-with-spec.md).
4
+ *
5
+ * The Admin reads it to show the hosting lock (STEALTH, which the hub never
6
+ * learns), to judge its status line against the owner's chosen state, and to
7
+ * fill the What agents can do card's Installed column on every topology —
8
+ * the site answers for its own deployment, a spoke included. The body is
9
+ * `siteStatusSchema` (`@working-theory/validation`), bare, no envelope:
10
+ *
11
+ * - `visibility` — `lib/site-visibility.ts`'s `siteHidden()`, the one rule
12
+ * every surface acts on;
13
+ * - `lock` — `"hosting"` under STEALTH;
14
+ * - `publicPages` — `PUBLIC_PAGES` (#10040);
15
+ * - `mcp` — what the site's MCP server (`MCP_PUBLIC_HTTP_URL`) answered its
16
+ * own `initialize` (`readMcpServer`, shared per URL for 60 s): its tool
17
+ * names and installed names, `refused`, `unreachable`, or `none` when the
18
+ * site has no MCP server.
19
+ *
20
+ * It takes no input (any query is ignored), reads and sets no cookie, and
21
+ * sends no URL, key or setting value. Every answer is `no-store` and
22
+ * noindex: a machine report is never indexed. Its two reads are the shared,
23
+ * cached ones, so a burst of callers costs at most one hub read per 15 s and
24
+ * one MCP exchange per minute per instance.
25
+ */
26
+
27
+ import type { SiteStatus } from "@working-theory/validation";
28
+
29
+ import { readMcpServer } from "../../../lib/mcp-served-tools";
30
+ import { PUBLIC_PAGES } from "../../../lib/modules.generated";
31
+ import { HIDDEN_ROBOTS_HEADER, siteHidden, siteLock } from "../../../lib/site-visibility";
32
+
33
+ export const dynamic = "force-dynamic";
34
+
35
+ async function mcpStatus(): Promise<SiteStatus["mcp"]> {
36
+ const url = process.env["MCP_PUBLIC_HTTP_URL"];
37
+ if (!url) return { state: "none" };
38
+ const answer = await readMcpServer(url);
39
+ if (answer.state !== "answering") return answer;
40
+ return {
41
+ state: "answering",
42
+ tools: answer.tools.map((tool) => tool.name),
43
+ installed: answer.installed,
44
+ };
45
+ }
46
+
47
+ export async function GET(): Promise<Response> {
48
+ const [hidden, mcp] = await Promise.all([siteHidden(), mcpStatus()]);
49
+ const status: SiteStatus = {
50
+ visibility: hidden ? "hidden" : "live",
51
+ lock: siteLock(),
52
+ publicPages: PUBLIC_PAGES,
53
+ mcp,
54
+ };
55
+ return Response.json(status, {
56
+ status: 200,
57
+ headers: {
58
+ "cache-control": "no-store",
59
+ "X-Robots-Tag": HIDDEN_ROBOTS_HEADER,
60
+ },
61
+ });
62
+ }
@@ -34,7 +34,6 @@
34
34
  * 2026-11-11 on #11423.
35
35
  */
36
36
 
37
- import { siteDiscoverable } from "@working-theory/api-client";
38
37
  import {
39
38
  SCHEMA_ORG_TYPES,
40
39
  resolvedAdapterKind,
@@ -55,6 +54,7 @@ import {
55
54
  import { MARKETING_PAGES, PUBLIC_PAGES } from "../../lib/modules.generated";
56
55
  import { resolveSiteBrand } from "../../lib/site-brand";
57
56
  import { SITE_LISTING } from "../../lib/site-listing";
57
+ import { siteLive } from "../../lib/site-visibility";
58
58
  import { agentContactLines, pagePathFor, resolveBaseUrl } from "../../src/lib/routes";
59
59
 
60
60
  // #10510 D4 — read per request: the owner's discovery switch is a runtime
@@ -77,7 +77,7 @@ export interface LlmsHandlerDeps {
77
77
  getBlogPages?: () => Array<{ url: string; data: { title: string; description?: string } }>;
78
78
  /** The docs pages (#10041). Defaults to `listDocsPages` over this app's docs directory. */
79
79
  getDocsPages?: () => DocsIndexPage[];
80
- /** The owner's discovery switch (#10510 D4). Defaults to `siteDiscoverable`. */
80
+ /** The owner's discovery switch (#10510 D4). Defaults to `siteLive` — Hidden under STEALTH too (#11978). */
81
81
  discoverable?: () => Promise<boolean>;
82
82
  /** The site's own listing (#10940 D3). Defaults to `SITE_LISTING`. */
83
83
  getSiteListing?: () => SiteListing;
@@ -93,7 +93,7 @@ export function createLlmsHandler(deps: LlmsHandlerDeps = {}) {
93
93
  const resolveAdapter = deps.getContentAdapter ?? defaultGetContentAdapter;
94
94
  const resolveBlogPages = deps.getBlogPages ?? (() => []);
95
95
  const resolveDocsPages = deps.getDocsPages ?? listDocsPages;
96
- const isDiscoverable = deps.discoverable ?? siteDiscoverable;
96
+ const isDiscoverable = deps.discoverable ?? siteLive;
97
97
  const resolveSiteListing = deps.getSiteListing ?? (() => SITE_LISTING);
98
98
  const resolveHasContactPage = deps.hasContactPage ?? (() => MARKETING_PAGES);
99
99
 
@@ -5,10 +5,9 @@
5
5
  /**
6
6
  * Route handler tests: GET /openapi.json (#7396)
7
7
  *
8
- * `/.well-known/ai-plugin.json` advertises `${baseUrl}/openapi.json` as its
9
- * `api.url`. This route serves that document on the web host by proxying the
10
- * API's own `/v1/openapi.json`; when the API cannot answer it, the route
11
- * answers 502 — never the 404 an agent following the manifest used to get.
8
+ * This route serves the site's OpenAPI document on the web host by proxying
9
+ * the API's own `/v1/openapi.json`; when the API cannot answer it, the route
10
+ * answers 502 — never a 404 an agent could read as "no API".
12
11
  * A relative `servers[]` URL is resolved against the API origin, so the
13
12
  * document never sends an agent to this (web) host for an API call.
14
13
  */
@@ -342,4 +341,22 @@ describe("GET /openapi.json and the owner's discovery switch (#10510)", () => {
342
341
  expect(response.headers.get("cache-control")).toBe("no-store");
343
342
  expect(fetchSpy).not.toHaveBeenCalled();
344
343
  });
344
+
345
+ // #11978 D2, AC-2 (e) — STEALTH hides it too, before the switch is read.
346
+ it("STEALTH with the switch on: 404, never cached, the API never fetched", async () => {
347
+ const saved = process.env["STEALTH"];
348
+ process.env["STEALTH"] = "true";
349
+ try {
350
+ apiAnswers(200, JSON.stringify(SPEC));
351
+ const response = await GET();
352
+ expect(response.status).toBe(404);
353
+ expect(await response.text()).toBe("");
354
+ expect(response.headers.get("cache-control")).toBe("no-store");
355
+ expect(fetchSpy).not.toHaveBeenCalled();
356
+ expect(mockSiteDiscoverable).not.toHaveBeenCalled();
357
+ } finally {
358
+ if (saved === undefined) delete process.env["STEALTH"];
359
+ else process.env["STEALTH"] = saved;
360
+ }
361
+ });
345
362
  });
@@ -1,11 +1,12 @@
1
1
  /**
2
2
  * GET /openapi.json
3
3
  *
4
- * The OpenAPI document `/.well-known/ai-plugin.json` advertises as its
5
- * `api.url` (#7396). apps/api renders it at `/v1/openapi.json`; this route
6
- * serves that same document on the web host, so the URL the manifest names
7
- * answers here instead of 404ing. It is read over HTTP — apps/web never
8
- * imports apps/api.
4
+ * The site's OpenAPI document at its conventional path (#7396), for a
5
+ * non-MCP agent that calls the HTTP API — an OpenAPI importer such as a
6
+ * custom-GPT Action takes this URL directly (#11978 D9; no manifest points at
7
+ * it since `/.well-known/ai-plugin.json` was dropped). apps/api renders it at
8
+ * `/v1/openapi.json`; this route serves that same document on the web host.
9
+ * It is read over HTTP — apps/web never imports apps/api.
9
10
  *
10
11
  * A `servers[]` URL that is relative (apps/api emits `/` when
11
12
  * AILK_PUBLIC_API_URL is unset) is resolved against the API origin before the
@@ -23,10 +24,9 @@
23
24
  * host, and never calls a path this site would answer 404.
24
25
  */
25
26
 
26
- import { siteDiscoverable } from "@working-theory/api-client";
27
-
28
27
  import { browserApiOrigin } from "../../lib/api-origin.generated";
29
28
  import { RELAY_ROUTES } from "../../lib/relay";
29
+ import { siteHidden } from "../../lib/site-visibility";
30
30
  import { TOPOLOGY } from "../../lib/topology.generated";
31
31
  import { resolveBaseUrl } from "../../src/lib/routes";
32
32
 
@@ -159,8 +159,9 @@ function badGateway(message: string): Response {
159
159
  }
160
160
 
161
161
  export async function GET(): Promise<Response> {
162
- // #10510 D4 — hidden by the owner: 404, never cached, the API never read.
163
- if (!(await siteDiscoverable())) return new Response(null, { status: 404, headers: { "cache-control": "no-store" } });
162
+ // #11978 D2 — Hidden (STEALTH or the owner's switch): 404, never cached,
163
+ // the API never read.
164
+ if (await siteHidden()) return new Response(null, { status: 404, headers: { "cache-control": "no-store" } });
164
165
  let upstream: Response;
165
166
  try {
166
167
  upstream = await fetch(`${apiBase()}${UPSTREAM_PATH}`, {
@@ -37,7 +37,6 @@
37
37
  * directory is listed instead (`getDocsPages`, default `listDocsPages`).
38
38
  */
39
39
 
40
- import { siteDiscoverable } from "@working-theory/api-client";
41
40
  import {
42
41
  SCHEMA_ORG_TYPES,
43
42
  resolvedAdapterKind,
@@ -57,6 +56,7 @@ import {
57
56
  } from "../../lib/docs-index";
58
57
  import { PUBLIC_PAGES } from "../../lib/modules.generated";
59
58
  import { SITE_LISTING } from "../../lib/site-listing";
59
+ import { siteLive } from "../../lib/site-visibility";
60
60
  import { pagePathFor, resolveBaseUrl } from "../../src/lib/routes";
61
61
 
62
62
  // #10510 D4 — read per request: the owner's discovery switch is a runtime
@@ -71,7 +71,7 @@ export interface SitemapHandlerDeps {
71
71
  getContentAdapter?: () => ContentAdapter;
72
72
  /** The docs pages (#10041). Defaults to `listDocsPages` over this app's docs directory. */
73
73
  getDocsPages?: () => DocsIndexPage[];
74
- /** The owner's discovery switch (#10510 D4). Defaults to `siteDiscoverable`. */
74
+ /** The owner's discovery switch (#10510 D4). Defaults to `siteLive` — Hidden under STEALTH too (#11978). */
75
75
  discoverable?: () => Promise<boolean>;
76
76
  /** The site's own listing (#10940 D3). Defaults to `SITE_LISTING`. */
77
77
  getSiteListing?: () => SiteListing;
@@ -110,7 +110,7 @@ function buildLocaleUrl(
110
110
  export function createSitemapHandler(deps: SitemapHandlerDeps = {}) {
111
111
  const resolveAdapter = deps.getContentAdapter ?? defaultGetContentAdapter;
112
112
  const resolveDocsPages = deps.getDocsPages ?? listDocsPages;
113
- const isDiscoverable = deps.discoverable ?? siteDiscoverable;
113
+ const isDiscoverable = deps.discoverable ?? siteLive;
114
114
  const resolveSiteListing = deps.getSiteListing ?? (() => SITE_LISTING);
115
115
  return async function sitemapGET(): Promise<Response> {
116
116
  // #10040 decision 7 — no public page, no sitemap: 404 before the adapter.
@@ -618,6 +618,17 @@ export function createAuth(deps: CreateAuthDeps = {}) {
618
618
  /** Plain assignment, no cast — see `VerificationStore`. */
619
619
  const verificationStore: VerificationStore = prisma;
620
620
 
621
+ /**
622
+ * #12063 FR7 — the MCP server's outside-send clear: one person's switches,
623
+ * for one client or (no `applicationId`) every OAuth client of theirs, in
624
+ * every workspace. Agent-key switches are never touched here.
625
+ */
626
+ const clearOutsideSendSwitches = async (target: { userId: string; applicationId?: string }): Promise<void> => {
627
+ await prisma.outsideSendGrant.deleteMany({
628
+ where: { userId: target.userId, applicationId: target.applicationId ?? { not: null } },
629
+ });
630
+ };
631
+
621
632
  // No cast: `AuthEmailPrisma` is declared with method shorthand, which the
622
633
  // generated `PrismaClient` satisfies structurally (see its docblock).
623
634
  const sendResetPassword = makeSendResetPassword({
@@ -750,6 +761,19 @@ export function createAuth(deps: CreateAuthDeps = {}) {
750
761
  })}`,
751
762
  );
752
763
  }
764
+ // #12063 FR7 — the outside-send switches of those connections go with
765
+ // them. Guarded like its siblings: the reset has already happened.
766
+ try {
767
+ await clearOutsideSendSwitches({ userId: user.id });
768
+ } catch {
769
+ console.warn(
770
+ `[auth-email] ${JSON.stringify({
771
+ userId: user.id,
772
+ kind: "password-reset",
773
+ reason: "outside_send_clear_failed",
774
+ })}`,
775
+ );
776
+ }
753
777
  /**
754
778
  * Guarded like its sibling above, though `lib/auth-email.ts` now also
755
779
  * guards its own signing step (#6068). BOTH, deliberately: this callback
@@ -807,7 +831,7 @@ export function createAuth(deps: CreateAuthDeps = {}) {
807
831
  })),
808
832
  );
809
833
  };
810
- const mcpServer = baseURL ? mcpAuthorizationServer({ readMemberships }) : [];
834
+ const mcpServer = baseURL ? mcpAuthorizationServer({ readMemberships, clearOutsideSendSwitches }) : [];
811
835
 
812
836
  /** The phone step (#11106 D9); its sign-in and reset paths close with it. */
813
837
  const phoneActive = phoneStepActive();