Skip to content

An open-source, faster Devin alternative

TypeScript

cli: bring back opencomputer connection — #624 removed it as unsupported, then callService and useService shipped and made managed connections real, leaving the API as the only way to attach an account and leaving the platform's own 404 telling people to run a command that no longer existed; add|list|remove wrap the routes the docs currently spell out as curl, and nothing secret passes through the CLI because add returns a link for the account's owner to open

Brian Reardonec1bf3e248de
diff --git a/cli/src/api.ts b/cli/src/api.ts
index bd09d6a3..2572b5a8 100644
--- a/cli/src/api.ts
+++ b/cli/src/api.ts
@@ -65,6 +65,19 @@ export interface ManagedSecretMetadata {
// Model access (work 011). The provider token is write-only; these shapes
// carry only normalized metadata.
+/** An account the platform holds an OAuth credential for. */
+export interface ServiceConnection {
+ id: string;
+ /** `google` or `github` — the grant, not the API being called. */
+ provider: string;
+ /** The alias it was connected under; what an agent passes as `label`. */
+ label: string;
+ /** Who the account belongs to, e.g. the mailbox address. */
+ displayName?: string;
+ scopes?: string[];
+ status: string;
+}
+
export interface ModelAccessConnection {
id: string;
organizationId: string;
@@ -570,6 +583,53 @@ export class OpenComputerClient {
);
}
+ // ── Connected services ───────────────────────────────────────────────────
+ // Accounts the platform holds an OAuth credential for, reached from an agent
+ // with callService(). The provider segment is the grant — google covers
+ // gmail, calendar, drive and sheets; github is its own.
+
+ async serviceConnections(): Promise<ServiceConnection[]> {
+ const result = await this.request<{ connections: ServiceConnection[] }>(
+ "/api/managed-agents/connections",
+ );
+ return result.connections ?? [];
+ }
+
+ /**
+ * Begin connecting an account. Returns a link for whoever owns it to open;
+ * no credential passes through the CLI, and the person consenting never
+ * signs in to OpenComputer.
+ */
+ linkServiceConnection(input: { service: string; label?: string }) {
+ const provider = input.service === "github" ? "github" : "google";
+ return this.request<{
+ service: string;
+ label: string;
+ status: string;
+ authorizationUrl?: string;
+ connectionId?: string;
+ expiresAt?: string;
+ }>(`/api/managed-agents/connections/${provider}/link`, {
+ method: "POST",
+ body: JSON.stringify({
+ service: input.service,
+ ...(input.label ? { label: input.label } : {}),
+ }),
+ });
+ }
+
+ disconnectServiceConnection(input: { service: string; connectionId: string }) {
+ const provider = input.service === "github" ? "github" : "google";
+ const query = new URLSearchParams({
+ service: input.service,
+ connectionId: input.connectionId,
+ });
+ return this.request<void>(
+ `/api/managed-agents/connections/${provider}?${query.toString()}`,
+ { method: "DELETE" },
+ );
+ }
+
// ── Model access (work 011) ──────────────────────────────────────────────
async modelAccessConnections(): Promise<ModelAccessConnection[]> {
const result = await this.request<{ data: ModelAccessConnection[] }>(
diff --git a/cli/src/commands.ts b/cli/src/commands.ts
index cb8d7f73..7cfa1be9 100644
--- a/cli/src/commands.ts
+++ b/cli/src/commands.ts
@@ -1311,6 +1311,109 @@ export async function runCommand(
throw new Error("Use `opencomputer secrets set`, `list`, or `remove`.");
}
+ if (command === "connection" || command === "connections") {
+ // Accounts the platform holds an OAuth credential for. Nothing secret
+ // passes through here: `add` returns a link for the account's owner to
+ // open, and the token is minted and refreshed server-side.
+ const SERVICES = ["gmail", "calendar", "drive", "sheets", "github"];
+ const action = args.shift();
+
+ if (action === "add" || action === "connect") {
+ const service = args.shift();
+ if (!service || !SERVICES.includes(service)) {
+ throw new Error(`Use \`opencomputer connection add <${SERVICES.join("|")}>\``);
+ }
+ const label = option(args, "--alias") ?? option(args, "--label");
+ if (args.length) throw new Error(`Unexpected argument: ${args[0]}`);
+ const result = await client.linkServiceConnection({ service, label });
+ if (globals.json) {
+ printJSON(result);
+ return;
+ }
+ if (!result.authorizationUrl) {
+ process.stdout.write(
+ `${service} is already connected as ${result.label}.\n`,
+ );
+ return;
+ }
+ // The person who opens this consents with their own account, and it is
+ // connected under this label — they never sign in to OpenComputer.
+ process.stdout.write(
+ `Connect ${service} as "${result.label}" by opening:\n\n ${result.authorizationUrl}\n\n` +
+ `Send it to whoever owns the account. Run \`opencomputer connection list\` to confirm.\n`,
+ );
+ return;
+ }
+
+ if (action === "list" || action === "ls" || action === undefined) {
+ const connections = await client.serviceConnections();
+ if (globals.json) {
+ printJSON(connections);
+ return;
+ }
+ if (!connections.length) {
+ process.stdout.write(
+ "No connected accounts. Add one with `opencomputer connection add gmail`.\n",
+ );
+ return;
+ }
+ for (const connection of connections) {
+ process.stdout.write(
+ `${connection.label.padEnd(20)} ${connection.provider.padEnd(8)} ` +
+ `${connection.status.padEnd(12)} ${connection.displayName ?? ""}\n`,
+ );
+ }
+ return;
+ }
+
+ if (action === "remove" || action === "disconnect") {
+ const target = args.shift();
+ if (!target) {
+ throw new Error("Use `opencomputer connection remove <alias|connection-id>`");
+ }
+ const service = option(args, "--service");
+ if (args.length) throw new Error(`Unexpected argument: ${args[0]}`);
+ const connections = await client.serviceConnections();
+ // Accept either the alias a person remembers or the id the API returns.
+ const matches = connections.filter(
+ (connection) => connection.label === target || connection.id === target,
+ );
+ if (!matches.length) {
+ throw new Error(
+ `No connection named ${JSON.stringify(target)}. ` +
+ `Run \`opencomputer connection list\` to see them.`,
+ );
+ }
+ if (matches.length > 1 && !service) {
+ throw new Error(
+ `${matches.length} connections use the alias ${JSON.stringify(target)}. ` +
+ `Add --service <${SERVICES.join("|")}> to choose one.`,
+ );
+ }
+ const connection = matches[0]!;
+ // The delete route wants the service, not the provider; a google
+ // connection's scopes decide which one it is.
+ const resolved =
+ service ??
+ (connection.provider === "github"
+ ? "github"
+ : (SERVICES.find((candidate) =>
+ (connection.scopes ?? []).some((scope) =>
+ scope.includes(candidate === "calendar" ? "calendar" : candidate),
+ ),
+ ) ?? "gmail"));
+ await client.disconnectServiceConnection({
+ service: resolved,
+ connectionId: connection.id,
+ });
+ if (globals.json) printJSON({ removed: connection.id, label: connection.label });
+ else process.stdout.write(`Removed ${connection.label} (${resolved}).\n`);
+ return;
+ }
+
+ throw new Error("Use `opencomputer connection add|list|remove`.");
+ }
+
if (command === "model-access") {
const action = args.shift();
if (action === "connect") {
diff --git a/cli/src/index.ts b/cli/src/index.ts
index 83682a7c..1664f9be 100644
--- a/cli/src/index.ts
+++ b/cli/src/index.ts
@@ -75,6 +75,9 @@ Usage:
opencomputer env set <name> --value-stdin [--environment development|production] [--agent <agent>|current]
opencomputer env list [--environment development|production] [--agent <agent>|current]
opencomputer env remove <name> [--environment development|production] [--agent <agent>|current]
+ opencomputer connection add <gmail|calendar|drive|sheets|github> [--alias <name>]
+ opencomputer connection list
+ opencomputer connection remove <alias|connection-id> [--service <name>]
opencomputer model-access connect codex [--project <id|slug>]
opencomputer model-access list
opencomputer model-access disconnect codex