Skip to content

Conversation

@filipi87
Copy link
Contributor

@filipi87 filipi87 commented Oct 20, 2025

Allowing the transports to transform StartBotResult into TransportConnectionParams when using startBotAndConnect.

Copy link

@mattieruth mattieruth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@filipi87 filipi87 changed the title Saving the parameters used to start the bot. Transforming StartBotResult to TransportConnectionParams. Oct 21, 2025
let transportParams: T = await try self.startBot(startBotParams: startBotParams)
public func startBotAndConnect<T: StartBotResult>(startBotParams: APIRequest) async throws -> T {
let startBotResult: T = await try self.startBot(startBotParams: startBotParams)
let transportParams = try self.transport.transformStartBotResultToConnectionParams(startBotParams: startBotParams, startBotResult: startBotResult)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mattieruth , this is basically the _validateConnectionParams we had on the web.

There, we didn’t pass startBotParams to avoid a breaking change, but since this is a completely new method here, I thought this approach would make more sense.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think ?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm. actually, i think there's a bigger reason we don't do it this way on web. The issue is that we want the validation to occur as part of connect() and not part of startBot(). The above prevents someone from doing their own (i'm going to write this in js because... swift is alien): const result = await startBot(); waitForSomethingOrDoSomethingBeforeConnect(); connect(result); and still benefit from the transformation and validation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought the reason we ended up adding _validateConnectionParams inside connect on the web was due to all the backward compatibility we wanted to maintain there.

Here, it kind of feels like we have strong typing for both the startBot result and the connect parameters, which could actually be completely independent of each other.

That’s why I was only invoking this method to perform the transformation inside startBotAndConnect.

But let me know if you think having it inside connect is really the right approach here as well. If that’s the case, I believe I wouldn’t need a StartBotResult protocol, since startBot should also return TransportConnectionParams in this case.

Then, I will move to invoke the transformStartBotResultToConnectionParams method inside connect, and we should probably rename it to something else, maybe normalizeConnectionParams ? (Totally open to name suggestions; this one isn’t great. 😅)

What do you think?

Also tagging @marcus-daily, who might be interested in this for Android.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought the reason we ended up adding _validateConnectionParams inside connect on the web was due to all the backward compatibility we wanted to maintain there.

Somewhat? But not completely. Especially now with these SmallWebRTC startBot returns. Now this is supporting existing and recommended approaches. Let's say I want to build my own start endpoint because I need to return some other parameters for my client to handle in addition to the ones our built-in endpoint in the runner provides. Then I would copy exactly what the runner does, add the parameters i need and have my client do that startBot() and connect() separately. But we also don't want to force people's startBot() to return a certain type. They should be able to do their own transformation from whatever they send back in order to generate transport params.

Maybe I'm being too flexible? Yell at me if I am or if I'm missing the point.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But we also don't want to force people's startBot() to return a certain type. They should be able to do their own transformation from whatever they send back in order to generate transport params.

But we are allowing that. They can receive whatever they want from the startBot. That is why we are returning the StartBotResult protocol (which can be anything).

They can then transform it into SmallWebRTCTransportConnectionParams (in the SmallWebRTC case) and then invoke connect.

I just don't think that we need make the connect method, receive anything other than ConnectionParams, so SmallWebRTCTransportConnectionParams for the SmallWebRTC.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but my transform function will have to re-create all the logic in transformStartBot... if I've copied our pipecat endpoint and just added a field, right?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i guess it could just call transformStartBot... itself. It just might not be obvious to do that. 🤔

alright. i'm on board. i'm not sure i'll follow suit on web, though, since the types are so much looser there.

@filipi87 filipi87 changed the title Transforming StartBotResult to TransportConnectionParams. Allowing the transports to transform StartBotResult into TransportConnectionParams when using startBotAndConnect. Oct 21, 2025
…nectionParams when using startBotAndConnect.
@filipi87 filipi87 requested a review from mattieruth October 21, 2025 15:00
@filipi87 filipi87 merged commit 98133fc into main Oct 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants