Skip to content

Commit

Permalink
added interrupt to update config
Browse files Browse the repository at this point in the history
  • Loading branch information
jptaylor committed Aug 29, 2024
1 parent b6fdb4e commit 29a0404
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
6 changes: 4 additions & 2 deletions rtvi-client-js/src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -510,16 +510,18 @@ export abstract class Client extends (EventEmitter as new () => TypedEmitter<Voi
/**
* Update pipeline and services
* @param config - VoiceClientConfigOption[] partial object with the new configuration
* @param interrupt - boolean flag to interrupt the current pipeline, or wait until the next turn
* @returns Promise<unknown> - Promise that resolves with the updated configuration
*/
public async updateConfig(
config: VoiceClientConfigOption[]
config: VoiceClientConfigOption[],
interrupt: boolean = false
): Promise<unknown> {
// Only send the partial config if the bot is ready to prevent
// potential racing conditions whilst pipeline is instantiating
if (this._transport.state === "ready") {
return this._messageDispatcher.dispatch(
VoiceMessage.updateConfig(config),
VoiceMessage.updateConfig(config, interrupt),
true
);
} else {
Expand Down
10 changes: 8 additions & 2 deletions rtvi-client-js/src/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,14 @@ export class VoiceMessage {
return new VoiceMessage(VoiceMessageType.CLIENT_READY, {});
}

static updateConfig(config: VoiceClientConfigOption[]): VoiceMessage {
return new VoiceMessage(VoiceMessageType.UPDATE_CONFIG, { config });
static updateConfig(
config: VoiceClientConfigOption[],
interrupt: boolean = false
): VoiceMessage {
return new VoiceMessage(VoiceMessageType.UPDATE_CONFIG, {
config,
interrupt,
});
}

static describeConfig(): VoiceMessage {
Expand Down
6 changes: 3 additions & 3 deletions rtvi-client-js/tests/config.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,8 @@ describe("Voice Client Config Setter Helper Methods", () => {
test("setServiceOptionInConfig should set or update multiple items", () => {
const newConfig = voiceClient.setServiceOptionInConfig("llm", [
{
name: "test",
value: "testabc",
name: "model",
value: "newModel",
} as ConfigOption,
{
name: "test2",
Expand All @@ -168,7 +168,7 @@ describe("Voice Client Config Setter Helper Methods", () => {
expect.objectContaining({
service: "llm",
options: expect.arrayContaining([
{ name: "test", value: "testabc" },
{ name: "model", value: "newModel" },
{ name: "test2", value: "test2" },
]),
}),
Expand Down

0 comments on commit 29a0404

Please sign in to comment.