Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
162 changes: 94 additions & 68 deletions api/openapi.json

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions api/scripts/check-premerge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,23 @@ const warn = (check: string, message: string, file?: string) => console.log(`::w
if (failed === before) console.log(`Job handlers: all ${types.size} enqueued and registered job types resolve through dispatch.ts.`);
}

// 12. An operation's summary is a name. It is the docs page's title in the browser tab and in search results
// (docsTitle, app/src/features/docs/meta.ts), the docs sidebar's entry and the SDK's comment, and the MCP tool leads
// with it: a sentence there runs past the 60 characters a search result shows. Sentences go in the description.
{
// The app's own title rule, by URL: the API's type check doesn't take in the app's sources.
const { docsTitle, operationTitle } = await import(new URL('../../app/src/features/docs/meta.ts', import.meta.url).href) as { docsTitle: (page: string) => string; operationTitle: (id: string) => string };
const before = failed;
const spec = JSON.parse(readFileSync(new URL('openapi.json', api), 'utf8')) as { paths: Record<string, Record<string, { operationId?: string; summary?: string }>> };
const operations = Object.values(spec.paths).flatMap(item => Object.values(item)).filter(op => op.operationId);
const most = 60 - docsTitle('').length;
for (const op of operations) {
const name = op.summary ?? operationTitle(op.operationId!), title = docsTitle(name);
if (title.length > 60 || /[.;:!?](\s|$)/.test(name)) fail('Operation summaries', `${op.operationId}'s summary “${name}” is ${title.length > 60 ? `${name.length} characters` : 'a sentence'}. A summary is a name of at most ${most} characters with no full stop, because it is the docs page's title (“${title}”, ${title.length} of 60 characters) and the SDK's comment. Keep a short name (“Create an inbox app password”), move the sentence word for word into the operation's description, warnings first, and run bun run sdk in api/.`);
}
if (failed === before) console.log(`Operation summaries: all ${operations.length} operations are named in at most ${most} characters, so every docs title fits in 60.`);
}

if (failed) {
console.log(`\n${failed} pre-merge check${failed === 1 ? '' : 's'} failed. docs/ci.md explains each one and how to fix it.`);
process.exitCode = 1;
Expand Down
4 changes: 2 additions & 2 deletions api/src/address-flow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,8 @@ export async function releaseAddress(tx: DbExecutor, c: Ctx, w: string, box: { i
export function registerAddressFlow(app: App) {
app.openapi(createRoute({
method: 'patch', path: '/v1/inbound/addresses/{addressId}/flow', operationId: 'setInboundAddressFlow', tags: ['Inbound addresses'], security,
summary: 'Change where one address’s mail goes, in one version',
description: 'Changes the route for the address’s own address and its two-way rule together: one transaction and one routing version, so all of it is saved or none of it. Omitted fields stay as they are, a field equal to what is saved writes nothing, and when nothing changes the version stays. deliver replaces only the route’s destinations (a paused route stays paused). Send the version from getInboundOverview or getRouting as If-Match; a stale one is refused with 409 and nothing changes.',
summary: 'Set where an address’s mail goes',
description: 'Change where one address’s mail goes, in one version. Changes the route for the address’s own address and its two-way rule together: one transaction and one routing version, so all of it is saved or none of it. Omitted fields stay as they are, a field equal to what is saved writes nothing, and when nothing changes the version stays. deliver replaces only the route’s destinations (a paused route stays paused). Send the version from getInboundOverview or getRouting as If-Match; a stale one is refused with 409 and nothing changes.',
request: {
params: z.object({ addressId: InboundAddressId }),
headers: z.object({ 'if-match': z.string().max(32).optional().describe('Apply only if routes and rules are still at this version, from getInboundOverview, GET /v1/routing or a previous ETag.') }),
Expand Down
8 changes: 4 additions & 4 deletions api/src/agent-setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ export function registerAgentSetup(app: App) {
return c.json({ id: setupId, status, expiresAt: isoTime(row.expires_at)!, connectedAt: isoTime(row.used_at), keyId: row.key_id, keyName: row.key_name }, 200);
});
app.openapi(createRoute({ method: 'post', path: '/v1/agent/setup', operationId: 'exchangeAgentSetupToken', tags, security: [],
summary: 'Exchange a setup token for the agent\'s API key',
summary: 'Exchange a setup token for an API key',
description: `For a coding agent: the setup token in the prompt a person copied from the dashboard (${secretPrefixes.agentSetup}…) becomes a lasting API key for the agent, in that person's workspace, named after client_name. It works once, within ${SETUP_MINUTES} minutes of copying. A wrong token gets 400 SETUP_TOKEN_INVALID, a used one 409 SETUP_TOKEN_USED (naming the key it gave, in error.details, never the key again), and an expired or replaced one 410 SETUP_TOKEN_EXPIRED or SETUP_TOKEN_REPLACED with a device code in error.details[0] (startAgentDeviceAuthorization's answer) for the person who copied it to approve: show them its link and poll it. The key is shown once.`,
request: { body: json(z.object({ token: Token.openapi({ example: `${secretPrefixes.agentSetup}${'0'.repeat(32)}.${'0'.repeat(64)}` }).describe('The setup token from the prompt.'),
client_name: ClientName }).strict()) },
Expand Down Expand Up @@ -254,7 +254,7 @@ export function registerAgentSetup(app: App) {

// ---------- device: RFC 8628 for an agent started without the prompt ----------
app.openapi(createRoute({ method: 'post', path: '/v1/agent/device', operationId: 'startAgentDeviceAuthorization', tags, security: [],
summary: 'Start the device flow for a coding agent',
summary: 'Start the device flow for an agent',
description: `For a coding agent without a setup token (RFC 8628): returns a device code to keep and a user code to show. Show the person verification_uri_complete as a link on its own line and ask them to open it, sign in, check the code and approve; nextStep says so in words. Then poll pollAgentDeviceToken every interval seconds until it returns the key. Codes work once, for ${DEVICE_MINUTES} minutes. With setup_token (one from the person's prompt that expired or was replaced before it was used), their dashboard shows you waiting.`,
request: { body: { ...json(z.object({ client_name: ClientName,
setup_token: Token.optional().describe('The setup token from the person\'s prompt, even if it expired or was replaced: their dashboard then shows you waiting for their approval. One that was used already addresses nobody.') }).strict()), required: false } },
Expand Down Expand Up @@ -357,7 +357,7 @@ export function registerAgentSetup(app: App) {
throw new ApiError(409, 'DEVICE_CODE_DECIDED', `This code was already ${row.status === 'denied' ? 'denied' : 'approved'}.`);
}
app.openapi(createRoute({ method: 'post', path: '/v1/agent/device/lookup', operationId: 'lookUpAgentDevice', tags, security: dashboardSecurity,
summary: 'Look up an agent waiting with a user code',
summary: 'Look up an agent by user code',
description: `The /connect page: the agent behind a user code, before you approve or deny it. Each attempt counts against ${LIMITS.userCode} a minute per person. Dashboard session only.`,
request: { body: json(z.object({ userCode: UserCode }).strict()) }, responses: { 200: response(DeviceRequest), ...errors } }), async c => {
const { userId } = person(c, false), code = await codeOf(c, userId, c.req.valid('json').userCode);
Expand All @@ -383,7 +383,7 @@ export function registerAgentSetup(app: App) {
return c.json({ data: rows.map(row => ({ userCode: shownCode(row.user_code), clientName: row.client_name, createdAt: isoTime(row.created_at)!, expiresAt: isoTime(row.expires_at)!, promptCopiedAt: isoTime(row.copied)! })) }, 200);
});
app.openapi(createRoute({ method: 'post', path: '/v1/agent/device/approve', operationId: 'approveAgentDevice', tags, security: dashboardSecurity,
summary: 'Approve an agent waiting with a user code',
summary: 'Approve an agent by user code',
description: 'Gives the agent behind the user code its own API key in the workspace this request acts in (X-Nightmail-Workspace), which you must own or administer. It receives the key on its next poll. Dashboard session only.',
request: { body: json(z.object({ userCode: UserCode }).strict()) }, responses: { 200: response(z.object({ userCode: z.string(), status: z.literal('approved'), workspaceId: z.string() }).openapi('AgentDeviceApproval')), ...errors, ...gone } }), async c => {
const { workspaceId, userId } = person(c, true), code = await codeOf(c, userId, c.req.valid('json').userCode);
Expand Down
2 changes: 1 addition & 1 deletion api/src/billing/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ async function ledgerPage(db: DbExecutor, workspaceId: string, cursor: string |
}

export function registerBilling(app: App) {
app.openapi(createRoute({ method: 'get', path: '/v1/billing', operationId: 'getBilling', tags: ['Billing'], security, summary: 'Balance, free allowance and billing state',
app.openapi(createRoute({ method: 'get', path: '/v1/billing', operationId: 'getBilling', tags: ['Billing'], security, summary: 'Read the balance and billing state',
description: 'Hosted only. The prepaid balance, this month’s free allowances (sent and received, counted separately) and cost, whether sending or receiving is paused for an empty balance, auto-recharge and the saved card, and the prices. Amounts are null unless the caller is an owner or admin session, or a manage key or grant. Keys restricted to domains get 403.',
responses: { 200: response(BillingSummarySchema), ...errors } }), async c => {
const a = billingActor(c, 'read');
Expand Down
Loading
Loading