An open-source, faster Devin alternative
TypeScript
feat: let agent sessions request connections
Mohamed Habib06fab41b3acc
diff --git a/cli/src/project.test.ts b/cli/src/project.test.tsindex a2d2f3ee..1f363b49 100644--- a/cli/src/project.test.ts+++ b/cli/src/project.test.ts@@ -96,6 +96,18 @@ test("the compiler maps flat source into an OpenCode runtime", async () => {(await stat(resolve(runtime, ".opencode", "tools", "gmail.ts"))).isFile(),true,);+ assert.match(+ await readFile(+ resolve(+ runtime,+ ".opencode",+ "tools",+ "opencomputer-connections.ts",+ ),+ "utf8",+ ),+ /export const request = tool/,+ );assert.equal((await stat(resolve(runtime, "opencode.json"))).isFile(),true,diff --git a/cli/src/project.ts b/cli/src/project.tsindex ab7a852f..2cc34e74 100644--- a/cli/src/project.ts+++ b/cli/src/project.ts@@ -386,6 +386,59 @@ export const send = tool({`;}+function connectionControlToolSource(): string {+ return `import { tool } from "@opencode-ai/plugin";++async function connectionControl(+ method: "GET" | "POST",+ body?: unknown,+): Promise<unknown> {+ const base = process.env.OPENCOMPUTER_CONNECTIONS_URL;+ const token = process.env.OPENCOMPUTER_CONNECTION_TOKEN;+ if (!base || !token) {+ throw new Error("OpenComputer connections are unavailable");+ }+ const response = await fetch(base, {+ method,+ headers: {+ authorization: \`Bearer \${token}\`,+ ...(body ? { "content-type": "application/json" } : {}),+ },+ body: body ? JSON.stringify(body) : undefined,+ });+ const result = await response.json() as {+ error?: { message?: string };+ [key: string]: unknown;+ };+ if (!response.ok) {+ throw new Error(result.error?.message ?? "Connection request failed");+ }+ return result;+}++export const list = tool({+ description:+ "List the connected accounts available to the current session identity. Use this to discover connection providers and aliases without exposing credentials.",+ args: {},+ async execute() {+ return JSON.stringify(await connectionControl("GET"));+ },+});++export const request = tool({+ description:+ "Ask the current user to connect an additional account. In a messaging channel OpenComputer privately sends the authorization link to that user; otherwise the result includes the link.",+ args: {+ service: tool.schema.string(),+ label: tool.schema.string().optional(),+ },+ async execute(args) {+ return JSON.stringify(await connectionControl("POST", args));+ },+});+`;+}+export async function writeManifest(root: string,manifest: AgentManifest,@@ -737,6 +790,11 @@ export async function prepareAgent(root: string): Promise<string> {});}}+ await mkdir(resolve(runtime, ".opencode", "tools"), { recursive: true });+ await writeFile(+ resolve(runtime, ".opencode", "tools", "opencomputer-connections.ts"),+ connectionControlToolSource(),+ );const workspace = resolve(root, "workspace");if (await exists(workspace)) {await cp(workspace, runtime, { recursive: true });diff --git a/docs/agents/channels.mdx b/docs/agents/channels.mdxindex 82154fac..b441488f 100644--- a/docs/agents/channels.mdx+++ b/docs/agents/channels.mdx@@ -63,8 +63,9 @@ user links their own OpenComputer identity.OpenComputer user.</Step><Step title="Connect required services">- If the agent requires Gmail or another service, OpenComputer shows the- connection instructions for that user.+ If the agent needs Gmail or another declared service, it can send that+ Slack user a private connection link. Authorization never appears in the+ shared channel.</Step><Step title="Message the agent again">The channel session can now use only the connections owned by the linked@@ -75,6 +76,12 @@ user links their own OpenComputer identity.This prevents a shared Slack channel from inheriting the installer's Gmail oranother teammate's connected accounts.+OpenComputer identifies a Slack user within their Slack workspace and remembers+the linked OpenComputer identity. The same person can therefore use their own+connections across that workspace's OpenComputer agent apps without relinking+each app. This identity boundary also keeps two Slack workspaces with matching+user IDs separate.+## Connections and channels are different| Concept | Purpose | Ownership |diff --git a/docs/agents/connections.mdx b/docs/agents/connections.mdxindex 10a248d4..1ea9373d 100644--- a/docs/agents/connections.mdx+++ b/docs/agents/connections.mdx@@ -72,10 +72,19 @@ The same managed connection works in both execution modes:Provider credentials remain outside the agent's source, workspace, prompts,and model output.-When an agent needs a connection that the current user has not authorized,-the session returns an authorization command and, when available, a dashboard-link. This makes the same flow usable from the CLI, the playground, or a-connected channel.+Every agent runtime includes connection discovery and request tools. The agent+can list the providers and aliases available to the current session identity,+then ask that user to authorize a declared service when one is missing. These+tools return connection metadata only; they never return provider credentials.++In the CLI and playground, a connection request returns a secure dashboard+link. In Slack, OpenComputer privately messages that link to the person who+invoked the agent instead of posting it in the shared channel. After the user+authorizes the account, later sessions can find the connection by its alias.++An agent can request only connection providers declared by its deployed source.+The user still chooses whether to authorize the account and which provider+permissions to grant.## List and remove connectionsdiff --git a/web/src/managed-agents/Connections.tsx b/web/src/managed-agents/Connections.tsxindex 5b9bb452..71698542 100644--- a/web/src/managed-agents/Connections.tsx+++ b/web/src/managed-agents/Connections.tsx@@ -11,6 +11,7 @@ import {claimManagedAgentChannelIdentity,getManagedAgentConnections,getManagedAgents,+ linkManagedAgentConnection,} from './api'function displayResourceName(value: string) {@@ -22,9 +23,13 @@ function displayResourceName(value: string) {export default function ManagedAgentConnections() {const [searchParams, setSearchParams] = useSearchParams()const channelLinkStarted = useRef(false)+ const connectionStarted = useRef(false)const [channelLinkState, setChannelLinkState] = useState<'idle' | 'linking' | 'linked' | 'failed'>('idle')+ const [connectionRequestState, setConnectionRequestState] = useState<+ 'idle' | 'connecting' | 'connected' | 'failed'+ >('idle')const requestedService = searchParams.get('service')const requestedAlias = searchParams.get('alias') || 'default'const connections = useQuery({@@ -57,6 +62,35 @@ export default function ManagedAgentConnections() {.catch(() => setChannelLinkState('failed'))}, [searchParams, setSearchParams])+ useEffect(() => {+ if (+ searchParams.get('connect') !== '1' ||+ !requestedService ||+ connectionStarted.current ||+ channelLinkState === 'linking'+ ) {+ return+ }+ connectionStarted.current = true+ setConnectionRequestState('connecting')+ void linkManagedAgentConnection(requestedService, requestedAlias)+ .then((result) => {+ if (result.authorizationUrl) {+ window.location.assign(result.authorizationUrl)+ return+ }+ setConnectionRequestState('connected')+ void connections.refetch()+ })+ .catch(() => setConnectionRequestState('failed'))+ }, [+ channelLinkState,+ connections,+ requestedAlias,+ requestedService,+ searchParams,+ ])+return (<div><PageHeader@@ -84,11 +118,13 @@ export default function ManagedAgentConnections() {{requestedAlias}”</p><p className="text-muted-foreground mt-1 text-sm">- Run{' '}- <code className="bg-muted rounded px-1.5 py-0.5 font-mono text-xs">- opencomputer connection add {requestedService} --alias{' '}- {requestedAlias}- </code>+ {connectionRequestState === 'connecting'+ ? 'Opening secure authorization…'+ : connectionRequestState === 'connected'+ ? 'This connection is ready for your sessions.'+ : connectionRequestState === 'failed'+ ? 'The connection could not be started. Reload this link to try again.'+ : 'Continue to securely authorize this account.'}</p></PanelContent></Panel>diff --git a/web/src/managed-agents/api.ts b/web/src/managed-agents/api.tsindex 93af03b7..7681aacf 100644--- a/web/src/managed-agents/api.ts+++ b/web/src/managed-agents/api.ts@@ -75,6 +75,14 @@ const connectionsResponseSchema = z.object({const channelIdentityLinkSchema = z.object({ linked: z.literal(true) })+const connectionLinkSchema = z.object({+ connectionId: z.string(),+ service: z.string(),+ label: z.string(),+ status: z.enum(['connected', 'pending']),+ authorizationUrl: z.string().url().optional(),+})+const channelsResponseSchema = z.object({channels: z.array(channelSchema),})@@ -190,6 +198,20 @@ export async function claimManagedAgentChannelIdentity(token: string) {)}+export async function linkManagedAgentConnection(+ service: string,+ label: string,+) {+ return apiFetch(+ '/managed-agents/connections/link',+ {+ method: 'POST',+ body: JSON.stringify({ service, label }),+ },+ connectionLinkSchema,+ )+}+export async function getManagedAgentChannels() {return (await apiFetch(