An open-source, faster Devin alternative
TypeScript
cli: connection add waits for the authorization, and list re-checks pending accounts — the listing route never asks the provider whether a consent completed, so an account authorized minutes ago still reads pending and nothing a user could run would clear it; add now polls the status route, which does reconcile, and list reconciles the pending rows it finds. No browser is opened: the account is often somebody else's and this runs on servers too. --no-wait and --json skip the wait
Brian Reardon0776dc5de51a
diff --git a/cli/src/api.ts b/cli/src/api.tsindex 1c42b452..f4ac8b20 100644--- a/cli/src/api.ts+++ b/cli/src/api.ts@@ -667,6 +667,29 @@ export class OpenComputerClient {});}+ /**+ * Live status for one connected account.+ *+ * Unlike the listing, this reconciles: it asks the provider whether the+ * consent completed and records the answer. A connection that was left+ * `pending` in the listing becomes `connected` here once someone has+ * actually authorized it.+ */+ serviceConnectionStatus(input: { service: string; label: string }) {+ const provider = input.service === "github" ? "github" : "google";+ const query = new URLSearchParams({+ service: input.service,+ label: input.label,+ });+ return this.request<{+ service: string;+ label: string;+ status: string;+ connectionId?: string;+ scopes?: string[];+ }>(`/api/managed-agents/connections/${provider}/status?${query.toString()}`);+ }+disconnectServiceConnection(input: { service: string; connectionId: string }) {const provider = input.service === "github" ? "github" : "google";const query = new URLSearchParams({diff --git a/cli/src/commands.ts b/cli/src/commands.tsindex 40a795f1..4a7216d7 100644--- a/cli/src/commands.ts+++ b/cli/src/commands.ts@@ -1343,8 +1343,11 @@ function serviceOfConnection(connection: {throw new Error(`Use \`opencomputer connection add <${SERVICES.join("|")}>\``);}const label = option(args, "--alias") ?? option(args, "--label");+ const noWait = flag(args, "--no-wait");if (args.length) throw new Error(`Unexpected argument: ${args[0]}`);const result = await client.linkServiceConnection({ service, label });+ // --json is for scripting, where blocking for a consent that may never+ // come is the wrong default.if (globals.json) {printJSON(result);return;@@ -1355,17 +1358,72 @@ function serviceOfConnection(connection: {);return;}- // The person who opens this consents with their own account, and it is- // connected under this label — they never sign in to OpenComputer.+ // Deliberately not opened for you: the account often belongs to someone+ // else, and this runs on servers and in CI as readily as on a laptop.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`,+ `Connect ${service} as "${result.label}" by opening:\n\n ${result.authorizationUrl}\n\n`,+ );+ if (noWait) {+ process.stdout.write(+ `Run \`opencomputer connection list\` once it has been authorized.\n`,+ );+ return;+ }++ // Poll the status route rather than the listing: only the status route+ // reconciles, so a listing can report `pending` long after the consent+ // completed. Without this, "did it work?" has no reliable answer.+ const deadline = result.expiresAt+ ? Date.parse(result.expiresAt)+ : Date.now() + 5 * 60_000;+ process.stdout.write("Waiting for authorization… (Ctrl-C to stop)\n");+ while (Date.now() < deadline) {+ await new Promise((resolve) => setTimeout(resolve, 2_000));+ let status: string | undefined;+ try {+ status = (+ await client.serviceConnectionStatus({+ service,+ label: result.label,+ })+ ).status;+ } catch {+ // A transient failure mid-consent should not end the wait; the+ // deadline is what ends it.+ continue;+ }+ if (status === "connected") {+ process.stdout.write(`Connected ${service} as "${result.label}".\n`);+ return;+ }+ }+ process.stdout.write(+ `Still not authorized. The link may have expired — run ` ++ `\`opencomputer connection list\` to check, or add it again.\n`,);return;}if (action === "list" || action === "ls" || action === undefined) {- const connections = await client.serviceConnections();+ const listed = await client.serviceConnections();+ // The listing route does not re-check with the provider, so an account+ // authorized minutes ago can still read `pending`. The status route does+ // reconcile, so ask it about the pending ones — and only those, so a+ // settled list costs nothing extra.+ const connections = await Promise.all(+ listed.map(async (connection) => {+ if (connection.status === "connected") return connection;+ try {+ const live = await client.serviceConnectionStatus({+ service: serviceOfConnection(connection),+ label: connection.label,+ });+ return { ...connection, status: live.status };+ } catch {+ return connection;+ }+ }),+ );if (globals.json) {printJSON(connections);return;diff --git a/cli/src/index.ts b/cli/src/index.tsindex 1664f9be..fad54cbd 100644--- a/cli/src/index.ts+++ b/cli/src/index.ts@@ -75,7 +75,7 @@ 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 add <gmail|calendar|drive|sheets|github> [--alias <name>] [--no-wait]opencomputer connection listopencomputer connection remove <alias|connection-id> [--service <name>]opencomputer model-access connect codex [--project <id|slug>]diff --git a/docs/agents/services.mdx b/docs/agents/services.mdxindex a9dd3a8b..4aa0c13f 100644--- a/docs/agents/services.mdx+++ b/docs/agents/services.mdx@@ -41,8 +41,15 @@ curl -X POST "$OC_API_URL/api/managed-agents/connections/google/link" \Both return a link. Whoever opens it consents with their own account and it isconnected under that label — they never sign in to OpenComputer, and no-credential passes through your side. Send the link to the person whose account-it is.+credential passes through your side.++The CLI then waits and prints `Connected` once the account is authorized, so+you know it worked. It does not open a browser: the account often belongs to+somebody else, and this runs on servers as readily as on a laptop. Send them+the link and leave it waiting, or press Ctrl-C — the connection is unaffected.++For minting several links at once, `--no-wait` prints the link and exits.+`--json` does the same and is the one to script against.Omitting the label connects it as `default`, which is what the examples belowassume. **`default` is a literal name, not a fallback**: if you connect an@@ -247,6 +254,7 @@ collections rather than asking for them in one call.| `409 connection_alias_required` | Several accounts connected, no `label` given | Pass `label`; the message lists them || `403` from the service | The consent is narrower than the call needs | Reconnect the account with wider access || `listServices()` returns `[]` | The service is not declared | Add `useService("gmail")` |+| A connection stays `pending` | Nobody has opened the link yet, or it expired | `opencomputer connection list` re-checks pending accounts with the provider, so its answer is current || A header you set is ignored | It is not in the allowlist above | Nothing — it cannot be sent || Throws *managed connections are unavailable* | No connection layer | You are running outside the platform |