I need a supported way to start Agent from a JavaScript Replit Extension, pass a prompt string, and execute it in Build mode, with an explicit success or failure result.
Requirement: agent.invoke(prompt, opts)
Problem
Extensions can orchestrate workflows in the workspace, they can run commands, edit files, and notify users, however there is no supported way to invoke Replit Agent programmatically with a prompt and respect Build semantics.
Behavior
-
mode: "build"returns an edit request; extension may callapplyEdit, or setautoApply: true. -
Promise shape mirrors existing SDK patterns that return structured
{ ok | error }. -
Respect user tier and credit limits; return an error if Build is unavailable.
Security and permissions
-
New manifest scope, for example
"agent:invoke". -
All actions occur in the current workspace context; no implicit elevation.
Why this matters
Enables safe automation and integrations that already exist at the workflow level, for example, synthesize a targeted prompt, invoke Agent to execute and optionally auto-apply. Keeps AI usage inside Replit, preserves workspace context, aligns with Plan and Build semantics.
Proposed API
import { agent } from "@replit/extensions";
type Mode = "plan" | "build";
interface InvokeOptions {
mode: Mode; // plan = no edits, build = produce edit request
autoApply?: boolean; // build only, apply the generated edit request
timeoutMs?: number;
onUpdate?: (e: AgentEvent) => void; // optional progress events
context?: { paths?: string[] }; // optional file scope hints
}
type InvokeResult =
| { ok: true; mode: "plan"; replyText: string }
| { ok: true; mode: "build"; runId: string; editId?: string; applied?: boolean }
| { ok: false; error: string; code?: string };
declare function invoke(prompt: string, opts: InvokeOptions): Promise<InvokeResult>;
declare function applyEdit(editId: string): Promise<{ ok: boolean; error?: string }>;
Minimal usage
const r = await agent.invoke(
"Fix SQL injection in routes/login, parameterize query, update tests",
{ mode: "build", autoApply: true, timeoutMs: 180000 }
);
if (!r.ok) console.error(r.error);
VS Code extensions support a similar flow: select a chat model with vscode.lm.selectChatModels, then invoke it using model.sendRequest(messages, options, token).