Commands

AI command execution and prompt gating

Overview

The Commands resource provides two capabilities:

  1. Execute — Run AI-powered commands with context (current screen, organization, locale, attachments).
  2. Gate Prompt — Evaluate a conversation to determine if it should be allowed or blocked.

All command methods are available on r.commands.

Methods

MethodDescription
execute(input)Execute an AI command with context and optional attachments.
gatePrompt(input)Evaluate a conversation for access gating.

Execute a command

Send a natural language prompt to the AI with optional context about the current screen, organization, locale, and file attachments.

1const { data: result } = await r.commands.execute({
2 prompt: 'Create a new project called "analytics-dashboard" and set up a database.',
3 current_screen: '/dashboard/projects',
4 org_slug: 'my-org',
5 model: 'anthropic/claude-sonnet-4',
6 locale: 'en',
7});
8
9console.log(result.text); // Natural language response
10console.log(result.actions); // Structured actions the AI wants to perform

Input fields:

FieldTypeRequiredDescription
promptstringYesThe command or instruction to execute.
current_screenstring?NoThe current screen/route in the application (provides UI context).
org_slugstring | null?NoOrganization slug for scoping the command.
modelstring?NoAI model to use.
localestring?NoLocale for the response (e.g., 'en', 'es', 'ja').
attachmentsAttachment[]?NoFiles to include with the command.

Attachment format:

1interface Attachment {
2 url: string; // URL to the file
3 mime?: string; // MIME type (e.g., 'image/png')
4 filename?: string; // Original filename
5}

Returns: SingleResponse<ExecutePromptResult>

1interface ExecutePromptResult {
2 text: string; // AI's natural language response
3 actions: Record<string, unknown>[]; // Structured actions to perform
4}

Example with attachments

1const { data: result } = await r.commands.execute({
2 prompt: 'Analyze this screenshot and suggest UI improvements.',
3 attachments: [
4 {
5 url: 'https://storage.example.com/screenshot.png',
6 mime: 'image/png',
7 filename: 'dashboard-screenshot.png',
8 },
9 ],
10});
11
12console.log(result.text);

Example with context

1const { data: result } = await r.commands.execute({
2 prompt: 'What can I do from this screen?',
3 current_screen: '/projects/proj_123/deployments',
4 org_slug: 'acme-corp',
5 locale: 'en',
6});
7
8console.log(result.text);
9// "From the deployments screen, you can: 1. Trigger a new deployment..."

Gate a prompt

The prompt gating endpoint evaluates a conversation to determine whether it should proceed. This is useful for implementing content moderation, access control, or guardrails for AI-powered features.

1const { data: result } = await r.commands.gatePrompt({
2 messages: [
3 { role: 'user', content: 'Help me write a Python script to analyze CSV data.' },
4 ],
5 model: 'anthropic/claude-sonnet-4',
6});
7
8console.log(result.approved); // true or false
9console.log(result.reply); // AI's explanation of the decision

Input fields:

FieldTypeRequiredDescription
messagesGatePromptMessage[]YesThe conversation to evaluate.
modelstring?NoAI model to use for evaluation.

Message format:

1interface GatePromptMessage {
2 role: 'user' | 'assistant';
3 content: string;
4}

Returns: SingleResponse<GatePromptResult>

1interface GatePromptResult {
2 reply: string; // The AI's response/explanation
3 approved: boolean; // Whether the prompt is approved
4}

Example: content moderation

1async function moderateMessage(userMessage: string): Promise<boolean> {
2 const { data: gate } = await r.commands.gatePrompt({
3 messages: [
4 { role: 'user', content: userMessage },
5 ],
6 });
7
8 if (!gate.approved) {
9 console.log('Message blocked:', gate.reply);
10 return false;
11 }
12
13 return true;
14}
15
16// Usage
17const allowed = await moderateMessage('Help me build a REST API');
18if (allowed) {
19 // Proceed with the command
20 const { data: result } = await r.commands.execute({
21 prompt: 'Help me build a REST API',
22 });
23 console.log(result.text);
24}

Example: multi-turn gating

1const conversation = [
2 { role: 'user' as const, content: 'I want to deploy my app.' },
3 { role: 'assistant' as const, content: 'Sure! Which project would you like to deploy?' },
4 { role: 'user' as const, content: 'The analytics dashboard, to production.' },
5];
6
7const { data: gate } = await r.commands.gatePrompt({
8 messages: conversation,
9});
10
11if (gate.approved) {
12 const { data: result } = await r.commands.execute({
13 prompt: conversation[conversation.length - 1].content,
14 current_screen: '/projects/analytics-dashboard',
15 });
16 console.log(result.text);
17 console.log(result.actions);
18}