AIToolAuthorizer

class AIToolAuthorizer(connect: suspend (call: AIToolCallPart, url: String) -> Boolean, decline: suspend (call: AIToolCallPart) -> Unit)

How the person signs in on this device when a tool call waits for their account at a provider, and how their "not now" reaches your backend, which holds the call until one or the other.

The SDK doesn't open the sign-in page itself: Connect hands it to connect, and your app opens it in a browser, such as a Custom Tab. The page goes back to the return URL your backend gives its sign-ins, with status=connected in its query once the account is connected; your backend then updates the call's step, and the call goes on. Give it to AIToolApprover to offer sign-ins:

val authorizer = AIToolAuthorizer(
connect = { call, url -> signIns.open(url) }, // true once the page came back connected
decline = { call -> backend.declineSignIn(call.id) },
)
val approver = AIToolApprover(userId, installId, viewModelScope, authorizer) { call, allowed -> /* … */}

Both run in the approver's scope.

Parameters

connect

Opens the sign-in page, the call's AIToolAuthorization.launchUrl, and returns once the person is back: true when the page came back saying the account is connected, which keeps the card connecting while your backend changes the call's step (and offers Connect again if, after a while, it hasn't), or false when they came back without connecting, which lets them connect again. Return false as soon as the person is back when your app can't tell. A thrown exception says the page couldn't be opened, and the person can try again.

decline

Tells your backend the person won't sign in now. Your backend ends the call, which never runs. A thrown exception lets the person answer again.

Constructors

Link copied to clipboard
constructor(connect: suspend (call: AIToolCallPart, url: String) -> Boolean, decline: suspend (call: AIToolCallPart) -> Unit)