Skip to content

Commit 61e17ab

Browse files
carderneTrigger.dev RepoOps
authored andcommitted
docs: add gated Sandbox Tasks and Named machines docs
Mono-RevId: 5a40f75bbcb4b8c08dc8e2bd8be54176e35b6fad
1 parent 608c15c commit 61e17ab

9 files changed

Lines changed: 93 additions & 10 deletions

File tree

‎apps/docs/lib/gated-flags.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
// The feature flags a docs page or section may be gated on. The dashboard's copy is `DOCS_FLAGS` in
22
// apps/webapp/app/services/docsReader.server.ts, the only flags it ever reports to the docs;
33
// lib/gated.test.ts keeps the two lists equal. Node built-ins only: build scripts load this file.
4-
export const DOCS_FLAGS = ["hasDocsPanel", "bufferedTasks", "agentVault"] as const;
4+
export const DOCS_FLAGS = [
5+
"hasDocsPanel",
6+
"bufferedTasks",
7+
"agentVault",
8+
"sandboxTasks",
9+
"namedMachines",
10+
] as const;
511

612
export type DocsFlag = (typeof DOCS_FLAGS)[number];
713

‎apps/docs/lib/gated-view.test.ts‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,43 @@ describe("withGatedPages", () => {
9696
]);
9797
});
9898

99+
it("groups gated pages under a sidebar separator after ungrouped pages", () => {
100+
const merged = withGatedPages(tree(), [
101+
item("/beta/inline", "/pn/troubleshooting"),
102+
{
103+
url: "/beta/overview",
104+
title: "Overview",
105+
after: "/pn/troubleshooting",
106+
group: "Beta section",
107+
},
108+
{
109+
url: "/beta/network",
110+
title: "Network",
111+
after: "/pn/troubleshooting",
112+
group: "Beta section",
113+
},
114+
]);
115+
const docFolder = merged.children[0];
116+
expect(docFolder?.type).toBe("folder");
117+
if (docFolder?.type !== "folder") return;
118+
const afterIdx = docFolder.children.findIndex(
119+
(n) => n.type === "page" && n.url === "/pn/troubleshooting"
120+
);
121+
expect(
122+
docFolder.children.slice(afterIdx, afterIdx + 5).map((n) => ({
123+
type: n.type,
124+
name: n.name,
125+
url: n.type === "page" ? n.url : undefined,
126+
}))
127+
).toEqual([
128+
{ type: "page", name: "Troubleshooting", url: "/pn/troubleshooting" },
129+
{ type: "page", name: "/beta/inline", url: "/beta/inline" },
130+
{ type: "separator", name: "Beta section", url: undefined },
131+
{ type: "page", name: "Overview", url: "/beta/overview" },
132+
{ type: "page", name: "Network", url: "/beta/network" },
133+
]);
134+
});
135+
99136
// Catches: the sidebar never showing the pages (fumadocs re-reads the tree only on a new $id),
100137
// or the shared public tree being changed for the next reader.
101138
it("returns a new tree with a new $id and leaves the public tree alone", () => {

‎apps/docs/lib/gated-view.ts‎

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,41 @@ import type { Reader } from "./reader";
44
// What the browser shows for gated docs (components/gated.tsx), kept apart so it can be tested.
55

66
/** A gated page the reader's flags open, from /api/gated/nav: listed in the sidebar after `after`. */
7-
export type GatedNavItem = { url: string; title: string; after: string };
7+
export type GatedNavItem = { url: string; title: string; after: string; group?: string };
88

99
/**
1010
* The sidebar tree with each gated page right after the page its `after` names, in that page's
1111
* folder (first in a folder whose index page it names). Pages after the same page keep their order.
12+
* Items with a `group` are placed after ungrouped items under a sidebar separator heading.
1213
*/
1314
export function withGatedPages(tree: Root, items: GatedNavItem[]): Root {
1415
if (!items.length) return tree;
15-
const after = (url: string): Node[] =>
16-
items
17-
.filter((i) => i.after === url)
18-
.map((i) => ({ type: "page", name: i.title, url: i.url, $id: `gated:${i.url}` }));
16+
const after = (url: string): Node[] => {
17+
const matched = items.filter((i) => i.after === url);
18+
if (!matched.length) return [];
19+
const plain: Node[] = [];
20+
const grouped = new Map<string, Node[]>();
21+
for (const item of matched) {
22+
const node: Node = {
23+
type: "page",
24+
name: item.title,
25+
url: item.url,
26+
$id: `gated:${item.url}`,
27+
};
28+
if (!item.group) {
29+
plain.push(node);
30+
} else {
31+
const list = grouped.get(item.group) ?? [];
32+
list.push(node);
33+
grouped.set(item.group, list);
34+
}
35+
}
36+
const groups: Node[] = [];
37+
for (const [name, pages] of grouped) {
38+
groups.push({ type: "separator", name, $id: `gated-group:${url}:${name}` }, ...pages);
39+
}
40+
return [...plain, ...groups];
41+
};
1942
const place = (nodes: Node[]): Node[] =>
2043
nodes.flatMap((n): Node[] => {
2144
if (n.type === "page") return [n, ...after(n.url)];

‎apps/docs/lib/gated.ts‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,21 @@ for (const entry of gated) {
1919
else pages.set(path, entry);
2020
}
2121

22-
/** The gated pages these flags open, for the sidebar, in file order. */
22+
/** The gated pages these flags open, for the sidebar, in order then file order. */
2323
export function gatedNav(flags: DocsFlag[]): GatedNavItem[] {
2424
return [...pages]
2525
.filter(([, e]) => flags.includes(e.flag))
26-
.sort(([a], [b]) => (a < b ? -1 : 1))
26+
.sort(([aSlug, a], [bSlug, b]) => {
27+
if (a.order !== b.order) {
28+
return (a.order ?? Number.POSITIVE_INFINITY) - (b.order ?? Number.POSITIVE_INFINITY);
29+
}
30+
return aSlug < bSlug ? -1 : aSlug > bSlug ? 1 : 0;
31+
})
2732
.map(([slug, e]) => ({
2833
url: `/${encodeURI(slug)}`,
29-
title: e.title ?? slug,
34+
title: e.sidebarTitle ?? e.title ?? slug,
3035
after: `/${e.after}`,
36+
...(e.group ? { group: e.group } : {}),
3137
}));
3238
}
3339

‎apps/docs/source.config.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,15 @@ export const gated = defineCollections({
6969
async: lazyBodies,
7070
schema: z.object({
7171
title: z.string().optional(),
72+
sidebarTitle: z.string().optional(),
7273
description: z.string().optional(),
7374
flag: z.enum(DOCS_FLAGS),
7475
// The sidebar page (a docs.json path) a gated page is listed right after.
7576
after: z.string().optional(),
77+
// Optional sidebar section heading grouping gated pages placed after the same `after` page.
78+
group: z.string().optional(),
79+
// Optional sort order among gated pages sharing the same `after` page.
80+
order: z.number().optional(),
7681
}),
7782
});
7883

‎apps/webapp/app/services/docsReader.server.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,8 @@ export const DOCS_FLAGS = [
160160
"hasDocsPanel",
161161
"bufferedTasks",
162162
"agentVault",
163+
"sandboxTasks",
164+
"namedMachines",
163165
] as const satisfies readonly FeatureFlagKey[];
164166

165167
export type DocsFlag = (typeof DOCS_FLAGS)[number];

‎docs/AGENTS.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ after: private-networking/aws-console-setup
8484
---
8585
```
8686

87-
`after` is the `docs.json` path of a page in the sidebar (not a hidden page or one whose `url` links out). Flagged readers see the gated page right after it, in the same group, and at `/docs/<path>`; everyone else gets the normal 404. Several gated pages after the same page are listed in file name order. Don't add a gated page to `docs.json`.
87+
`after` is the `docs.json` path of a page in the sidebar (not a hidden page or one whose `url` links out). Flagged readers see the gated page right after it, in the same group, and at `/docs/<path>`; everyone else gets the normal 404. Optional `sidebarTitle`, `order`, and `group` frontmatter customize the sidebar label, sort order, and sidebar section heading when placing multiple pages after the same `after` page. Don't add a gated page to `docs.json`.
8888

8989
- `flag` must be in `DOCS_FLAGS` (`apps/docs/lib/gated-flags.ts`, and the dashboard's copy in `apps/webapp/app/services/docsReader.server.ts`). Add a new flag to both.
9090
- Write it like a public page: the same components (`<Steps>`, `<Tabs>`, `<CodeGroup>`, callouts, `<Accordion>`, ...), snippets and code blocks work. Two things don't: images, videos and iframes (the build fails on them, since their files would be public), and type hovers (gated code blocks render without them). A gated section can't hold another `<Gated>`.

‎docs/machines.mdx‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ await tasks.trigger<typeof heavyTask>(
5858

5959
This is useful when you know that a certain payload will require more memory than the default machine. For example, you know it's a larger file or a customer that has a lot of data.
6060

61+
<Gated id="k7m2p4" />
62+
6163
## Out Of Memory (OOM) errors
6264

6365
Sometimes you might see one of your runs fail with an "Out Of Memory" error.

‎docs/tasks/overview.mdx‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ description: "Tasks are functions that can run for a long time and provide stron
66

77
There are different types of tasks including regular tasks and [scheduled tasks](/tasks/scheduled).
88

9+
<Gated id="r4n8v2" />
10+
911
## Hello world task and how to trigger it
1012

1113
Here's an incredibly simple task:

0 commit comments

Comments
 (0)