@rapidaai/react 1.1.49 → 1.1.51
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-JA65S2AA.mjs → chunk-A2PCWS4P.mjs} +104 -166
- package/dist/chunk-A2PCWS4P.mjs.map +1 -0
- package/dist/components/device-selector.d.mts +1 -1
- package/dist/components/device-selector.d.ts +1 -1
- package/dist/components/device-selector.js +103 -145
- package/dist/components/device-selector.js.map +1 -1
- package/dist/components/device-selector.mjs +1 -1
- package/dist/{device-selector-o07ACCD6.d.mts → device-selector-D2B4ipII.d.mts} +6 -31
- package/dist/{device-selector-o07ACCD6.d.ts → device-selector-D2B4ipII.d.ts} +6 -31
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +133 -162
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +102 -75
- package/dist/index.mjs.map +1 -1
- package/package.json +11 -2
- package/dist/chunk-JA65S2AA.mjs.map +0 -1
package/dist/index.js
CHANGED
|
@@ -3675,8 +3675,8 @@ var require_common_pb = __commonJS({
|
|
|
3675
3675
|
id: jspb.Message.getFieldWithDefault(msg, 1, "0"),
|
|
3676
3676
|
messageid: jspb.Message.getFieldWithDefault(msg, 3, ""),
|
|
3677
3677
|
assistantconversationid: jspb.Message.getFieldWithDefault(msg, 2, "0"),
|
|
3678
|
-
|
|
3679
|
-
|
|
3678
|
+
role: jspb.Message.getFieldWithDefault(msg, 4, ""),
|
|
3679
|
+
body: jspb.Message.getFieldWithDefault(msg, 5, ""),
|
|
3680
3680
|
source: jspb.Message.getFieldWithDefault(msg, 9, ""),
|
|
3681
3681
|
metricsList: jspb.Message.toObjectList(
|
|
3682
3682
|
msg.getMetricsList(),
|
|
@@ -3735,15 +3735,19 @@ var require_common_pb = __commonJS({
|
|
|
3735
3735
|
);
|
|
3736
3736
|
msg.setAssistantconversationid(value);
|
|
3737
3737
|
break;
|
|
3738
|
-
case
|
|
3739
|
-
var value =
|
|
3740
|
-
|
|
3741
|
-
|
|
3738
|
+
case 4:
|
|
3739
|
+
var value = (
|
|
3740
|
+
/** @type {string} */
|
|
3741
|
+
reader.readString()
|
|
3742
|
+
);
|
|
3743
|
+
msg.setRole(value);
|
|
3742
3744
|
break;
|
|
3743
|
-
case
|
|
3744
|
-
var value =
|
|
3745
|
-
|
|
3746
|
-
|
|
3745
|
+
case 5:
|
|
3746
|
+
var value = (
|
|
3747
|
+
/** @type {string} */
|
|
3748
|
+
reader.readString()
|
|
3749
|
+
);
|
|
3750
|
+
msg.setBody(value);
|
|
3747
3751
|
break;
|
|
3748
3752
|
case 9:
|
|
3749
3753
|
var value = (
|
|
@@ -3842,20 +3846,18 @@ var require_common_pb = __commonJS({
|
|
|
3842
3846
|
f
|
|
3843
3847
|
);
|
|
3844
3848
|
}
|
|
3845
|
-
f = message.
|
|
3846
|
-
if (f
|
|
3847
|
-
writer.
|
|
3848
|
-
|
|
3849
|
-
f
|
|
3850
|
-
proto.Message.serializeBinaryToWriter
|
|
3849
|
+
f = message.getRole();
|
|
3850
|
+
if (f.length > 0) {
|
|
3851
|
+
writer.writeString(
|
|
3852
|
+
4,
|
|
3853
|
+
f
|
|
3851
3854
|
);
|
|
3852
3855
|
}
|
|
3853
|
-
f = message.
|
|
3854
|
-
if (f
|
|
3855
|
-
writer.
|
|
3856
|
-
|
|
3857
|
-
f
|
|
3858
|
-
proto.Message.serializeBinaryToWriter
|
|
3856
|
+
f = message.getBody();
|
|
3857
|
+
if (f.length > 0) {
|
|
3858
|
+
writer.writeString(
|
|
3859
|
+
5,
|
|
3860
|
+
f
|
|
3859
3861
|
);
|
|
3860
3862
|
}
|
|
3861
3863
|
f = message.getSource();
|
|
@@ -3960,35 +3962,23 @@ var require_common_pb = __commonJS({
|
|
|
3960
3962
|
proto.AssistantConversationMessage.prototype.setAssistantconversationid = function(value) {
|
|
3961
3963
|
return jspb.Message.setProto3StringIntField(this, 2, value);
|
|
3962
3964
|
};
|
|
3963
|
-
proto.AssistantConversationMessage.prototype.
|
|
3965
|
+
proto.AssistantConversationMessage.prototype.getRole = function() {
|
|
3964
3966
|
return (
|
|
3965
|
-
/** @type{
|
|
3966
|
-
jspb.Message.
|
|
3967
|
+
/** @type {string} */
|
|
3968
|
+
jspb.Message.getFieldWithDefault(this, 4, "")
|
|
3967
3969
|
);
|
|
3968
3970
|
};
|
|
3969
|
-
proto.AssistantConversationMessage.prototype.
|
|
3970
|
-
return jspb.Message.
|
|
3971
|
-
};
|
|
3972
|
-
proto.AssistantConversationMessage.prototype.clearRequest = function() {
|
|
3973
|
-
return this.setRequest(void 0);
|
|
3974
|
-
};
|
|
3975
|
-
proto.AssistantConversationMessage.prototype.hasRequest = function() {
|
|
3976
|
-
return jspb.Message.getField(this, 5) != null;
|
|
3971
|
+
proto.AssistantConversationMessage.prototype.setRole = function(value) {
|
|
3972
|
+
return jspb.Message.setProto3StringField(this, 4, value);
|
|
3977
3973
|
};
|
|
3978
|
-
proto.AssistantConversationMessage.prototype.
|
|
3974
|
+
proto.AssistantConversationMessage.prototype.getBody = function() {
|
|
3979
3975
|
return (
|
|
3980
|
-
/** @type{
|
|
3981
|
-
jspb.Message.
|
|
3976
|
+
/** @type {string} */
|
|
3977
|
+
jspb.Message.getFieldWithDefault(this, 5, "")
|
|
3982
3978
|
);
|
|
3983
3979
|
};
|
|
3984
|
-
proto.AssistantConversationMessage.prototype.
|
|
3985
|
-
return jspb.Message.
|
|
3986
|
-
};
|
|
3987
|
-
proto.AssistantConversationMessage.prototype.clearResponse = function() {
|
|
3988
|
-
return this.setResponse(void 0);
|
|
3989
|
-
};
|
|
3990
|
-
proto.AssistantConversationMessage.prototype.hasResponse = function() {
|
|
3991
|
-
return jspb.Message.getField(this, 7) != null;
|
|
3980
|
+
proto.AssistantConversationMessage.prototype.setBody = function(value) {
|
|
3981
|
+
return jspb.Message.setProto3StringField(this, 5, value);
|
|
3992
3982
|
};
|
|
3993
3983
|
proto.AssistantConversationMessage.prototype.getSource = function() {
|
|
3994
3984
|
return (
|
|
@@ -7544,14 +7534,13 @@ var require_talk_api_pb = __commonJS({
|
|
|
7544
7534
|
proto.talk_api.AssistantMessagingRequest.prototype.hasMessage = function() {
|
|
7545
7535
|
return jspb.Message.getField(this, 3) != null;
|
|
7546
7536
|
};
|
|
7547
|
-
proto.talk_api.AssistantMessagingResponse.oneofGroups_ = [[9, 10, 11, 12,
|
|
7537
|
+
proto.talk_api.AssistantMessagingResponse.oneofGroups_ = [[9, 10, 11, 12, 14, 15]];
|
|
7548
7538
|
proto.talk_api.AssistantMessagingResponse.DataCase = {
|
|
7549
7539
|
DATA_NOT_SET: 0,
|
|
7550
7540
|
CONFIGURATION: 9,
|
|
7551
7541
|
INTERRUPTION: 10,
|
|
7552
7542
|
USER: 11,
|
|
7553
7543
|
ASSISTANT: 12,
|
|
7554
|
-
MESSAGE: 13,
|
|
7555
7544
|
ACTION: 14,
|
|
7556
7545
|
ERROR: 15
|
|
7557
7546
|
};
|
|
@@ -7573,7 +7562,6 @@ var require_talk_api_pb = __commonJS({
|
|
|
7573
7562
|
interruption: (f = msg.getInterruption()) && common_pb.AssistantConversationInterruption.toObject(includeInstance, f),
|
|
7574
7563
|
user: (f = msg.getUser()) && common_pb.AssistantConversationUserMessage.toObject(includeInstance, f),
|
|
7575
7564
|
assistant: (f = msg.getAssistant()) && common_pb.AssistantConversationAssistantMessage.toObject(includeInstance, f),
|
|
7576
|
-
message: (f = msg.getMessage()) && common_pb.AssistantConversationMessage.toObject(includeInstance, f),
|
|
7577
7565
|
action: (f = msg.getAction()) && common_pb.AssistantConversationAction.toObject(includeInstance, f),
|
|
7578
7566
|
error: (f = msg.getError()) && common_pb.Error.toObject(includeInstance, f)
|
|
7579
7567
|
};
|
|
@@ -7629,11 +7617,6 @@ var require_talk_api_pb = __commonJS({
|
|
|
7629
7617
|
reader.readMessage(value, common_pb.AssistantConversationAssistantMessage.deserializeBinaryFromReader);
|
|
7630
7618
|
msg.setAssistant(value);
|
|
7631
7619
|
break;
|
|
7632
|
-
case 13:
|
|
7633
|
-
var value = new common_pb.AssistantConversationMessage();
|
|
7634
|
-
reader.readMessage(value, common_pb.AssistantConversationMessage.deserializeBinaryFromReader);
|
|
7635
|
-
msg.setMessage(value);
|
|
7636
|
-
break;
|
|
7637
7620
|
case 14:
|
|
7638
7621
|
var value = new common_pb.AssistantConversationAction();
|
|
7639
7622
|
reader.readMessage(value, common_pb.AssistantConversationAction.deserializeBinaryFromReader);
|
|
@@ -7704,14 +7687,6 @@ var require_talk_api_pb = __commonJS({
|
|
|
7704
7687
|
common_pb.AssistantConversationAssistantMessage.serializeBinaryToWriter
|
|
7705
7688
|
);
|
|
7706
7689
|
}
|
|
7707
|
-
f = message.getMessage();
|
|
7708
|
-
if (f != null) {
|
|
7709
|
-
writer.writeMessage(
|
|
7710
|
-
13,
|
|
7711
|
-
f,
|
|
7712
|
-
common_pb.AssistantConversationMessage.serializeBinaryToWriter
|
|
7713
|
-
);
|
|
7714
|
-
}
|
|
7715
7690
|
f = message.getAction();
|
|
7716
7691
|
if (f != null) {
|
|
7717
7692
|
writer.writeMessage(
|
|
@@ -7807,21 +7782,6 @@ var require_talk_api_pb = __commonJS({
|
|
|
7807
7782
|
proto.talk_api.AssistantMessagingResponse.prototype.hasAssistant = function() {
|
|
7808
7783
|
return jspb.Message.getField(this, 12) != null;
|
|
7809
7784
|
};
|
|
7810
|
-
proto.talk_api.AssistantMessagingResponse.prototype.getMessage = function() {
|
|
7811
|
-
return (
|
|
7812
|
-
/** @type{?proto.AssistantConversationMessage} */
|
|
7813
|
-
jspb.Message.getWrapperField(this, common_pb.AssistantConversationMessage, 13)
|
|
7814
|
-
);
|
|
7815
|
-
};
|
|
7816
|
-
proto.talk_api.AssistantMessagingResponse.prototype.setMessage = function(value) {
|
|
7817
|
-
return jspb.Message.setOneofWrapperField(this, 13, proto.talk_api.AssistantMessagingResponse.oneofGroups_[0], value);
|
|
7818
|
-
};
|
|
7819
|
-
proto.talk_api.AssistantMessagingResponse.prototype.clearMessage = function() {
|
|
7820
|
-
return this.setMessage(void 0);
|
|
7821
|
-
};
|
|
7822
|
-
proto.talk_api.AssistantMessagingResponse.prototype.hasMessage = function() {
|
|
7823
|
-
return jspb.Message.getField(this, 13) != null;
|
|
7824
|
-
};
|
|
7825
7785
|
proto.talk_api.AssistantMessagingResponse.prototype.getAction = function() {
|
|
7826
7786
|
return (
|
|
7827
7787
|
/** @type{?proto.AssistantConversationAction} */
|
|
@@ -60225,6 +60185,9 @@ var import_moment = __toESM(require("moment"));
|
|
|
60225
60185
|
function isSafari() {
|
|
60226
60186
|
return getBrowser()?.name === "Safari";
|
|
60227
60187
|
}
|
|
60188
|
+
function isChrome() {
|
|
60189
|
+
return getBrowser()?.name === "Chrome";
|
|
60190
|
+
}
|
|
60228
60191
|
function toDate(timestamp) {
|
|
60229
60192
|
const seconds = timestamp.getSeconds();
|
|
60230
60193
|
const nanos = timestamp.getNanos();
|
|
@@ -60466,7 +60429,7 @@ var AgentEvent = /* @__PURE__ */ ((AgentEvent2) => {
|
|
|
60466
60429
|
})(AgentEvent || {});
|
|
60467
60430
|
|
|
60468
60431
|
// src/agents/voice-agent.ts
|
|
60469
|
-
var
|
|
60432
|
+
var import_common_pb8 = __toESM(require_common_pb());
|
|
60470
60433
|
|
|
60471
60434
|
// src/types/message.ts
|
|
60472
60435
|
var MessageRole = /* @__PURE__ */ ((MessageRole2) => {
|
|
@@ -61934,6 +61897,24 @@ registerProcessor("raw-audio-processor", RawAudioProcessor);
|
|
|
61934
61897
|
|
|
61935
61898
|
// src/audio/input.ts
|
|
61936
61899
|
var LIBSAMPLERATE_JS = "https://cdn.jsdelivr.net/npm/@alexanderolsen/libsamplerate-js@2.1.2/dist/libsamplerate.worklet.js";
|
|
61900
|
+
function getAudioConstraints(sampleRate) {
|
|
61901
|
+
if (isChrome()) {
|
|
61902
|
+
return {
|
|
61903
|
+
sampleRate: { ideal: sampleRate },
|
|
61904
|
+
echoCancellation: true,
|
|
61905
|
+
noiseSuppression: true,
|
|
61906
|
+
autoGainControl: true,
|
|
61907
|
+
// Chrome-specific: helps with consistent audio quality
|
|
61908
|
+
channelCount: { ideal: 1 }
|
|
61909
|
+
};
|
|
61910
|
+
}
|
|
61911
|
+
return {
|
|
61912
|
+
sampleRate: { ideal: sampleRate },
|
|
61913
|
+
echoCancellation: { ideal: true },
|
|
61914
|
+
noiseSuppression: { ideal: true },
|
|
61915
|
+
autoGainControl: { ideal: true }
|
|
61916
|
+
};
|
|
61917
|
+
}
|
|
61937
61918
|
var Input = class _Input {
|
|
61938
61919
|
constructor(context, analyser, worklet, inputStream) {
|
|
61939
61920
|
this.context = context;
|
|
@@ -61941,18 +61922,10 @@ var Input = class _Input {
|
|
|
61941
61922
|
this.worklet = worklet;
|
|
61942
61923
|
this.inputStream = inputStream;
|
|
61943
61924
|
}
|
|
61944
|
-
static async create({
|
|
61945
|
-
sampleRate,
|
|
61946
|
-
format
|
|
61947
|
-
}) {
|
|
61925
|
+
static async create({ sampleRate, format }, existingStream) {
|
|
61948
61926
|
let context = null;
|
|
61949
61927
|
let inputStream = null;
|
|
61950
61928
|
try {
|
|
61951
|
-
const options = {
|
|
61952
|
-
sampleRate: { ideal: sampleRate },
|
|
61953
|
-
echoCancellation: { ideal: true },
|
|
61954
|
-
noiseSuppression: { ideal: true }
|
|
61955
|
-
};
|
|
61956
61929
|
const supportsSampleRateConstraint = navigator.mediaDevices.getSupportedConstraints().sampleRate;
|
|
61957
61930
|
context = new window.AudioContext(
|
|
61958
61931
|
supportsSampleRateConstraint ? { sampleRate } : {}
|
|
@@ -61962,9 +61935,14 @@ var Input = class _Input {
|
|
|
61962
61935
|
await context.audioWorklet.addModule(LIBSAMPLERATE_JS);
|
|
61963
61936
|
}
|
|
61964
61937
|
await loadRawAudioProcessor(context.audioWorklet);
|
|
61965
|
-
|
|
61966
|
-
|
|
61967
|
-
}
|
|
61938
|
+
if (existingStream) {
|
|
61939
|
+
inputStream = existingStream;
|
|
61940
|
+
} else {
|
|
61941
|
+
const options = getAudioConstraints(sampleRate);
|
|
61942
|
+
inputStream = await navigator.mediaDevices.getUserMedia({
|
|
61943
|
+
audio: options
|
|
61944
|
+
});
|
|
61945
|
+
}
|
|
61968
61946
|
const source = context.createMediaStreamSource(inputStream);
|
|
61969
61947
|
const worklet = new AudioWorkletNode(context, "raw-audio-processor");
|
|
61970
61948
|
worklet.port.postMessage({ type: "setFormat", format, sampleRate });
|
|
@@ -62153,47 +62131,15 @@ function arrayBufferToUint8(arrayBuffer) {
|
|
|
62153
62131
|
}
|
|
62154
62132
|
|
|
62155
62133
|
// src/types/agent-callback.ts
|
|
62156
|
-
var import_common_pb8 = __toESM(require_common_pb());
|
|
62157
|
-
|
|
62158
|
-
// src/utils/rapida_content.ts
|
|
62159
62134
|
var import_common_pb7 = __toESM(require_common_pb());
|
|
62160
|
-
var TEXT_CONTENT_FORMAT_RAW = "raw";
|
|
62161
|
-
var AUDIO_CONTENT_FORMAT_CHUNK = "chunk";
|
|
62162
|
-
var toTextContent = (str, format) => {
|
|
62163
|
-
const cnt = new import_common_pb7.Content();
|
|
62164
|
-
if (format) cnt.setContentformat(format);
|
|
62165
|
-
else cnt.setContentformat(TEXT_CONTENT_FORMAT_RAW);
|
|
62166
|
-
cnt.setContenttype("text" /* TEXT_CONTENT */);
|
|
62167
|
-
cnt.setContent(new TextEncoder().encode(str));
|
|
62168
|
-
return cnt;
|
|
62169
|
-
};
|
|
62170
|
-
var toStreamAudioContent = (raw) => {
|
|
62171
|
-
const cnt = new import_common_pb7.Content();
|
|
62172
|
-
cnt.setContentformat(AUDIO_CONTENT_FORMAT_CHUNK);
|
|
62173
|
-
cnt.setContenttype("audio" /* AUDIO_CONTENT */);
|
|
62174
|
-
cnt.setContent(raw);
|
|
62175
|
-
return cnt;
|
|
62176
|
-
};
|
|
62177
|
-
var toContentText = (cnt) => {
|
|
62178
|
-
if (!cnt) return "";
|
|
62179
|
-
return cnt.filter((x) => x.getContenttype() === "text").map((x) => {
|
|
62180
|
-
try {
|
|
62181
|
-
return new TextDecoder().decode(x.getContent());
|
|
62182
|
-
} catch (error) {
|
|
62183
|
-
return "";
|
|
62184
|
-
}
|
|
62185
|
-
}).join(" ");
|
|
62186
|
-
};
|
|
62187
|
-
|
|
62188
|
-
// src/types/agent-callback.ts
|
|
62189
62135
|
var ConversationUserMessage = class {
|
|
62190
62136
|
constructor(config) {
|
|
62191
62137
|
if (config) {
|
|
62192
62138
|
Object.assign(this, config.toObject());
|
|
62193
62139
|
switch (config.getMessageCase()) {
|
|
62194
|
-
case
|
|
62195
|
-
case
|
|
62196
|
-
case
|
|
62140
|
+
case import_common_pb7.AssistantConversationUserMessage.MessageCase.MESSAGE_NOT_SET:
|
|
62141
|
+
case import_common_pb7.AssistantConversationUserMessage.MessageCase.AUDIO:
|
|
62142
|
+
case import_common_pb7.AssistantConversationUserMessage.MessageCase.TEXT:
|
|
62197
62143
|
this.messageText = config.getText()?.getContent();
|
|
62198
62144
|
}
|
|
62199
62145
|
}
|
|
@@ -62204,25 +62150,14 @@ var ConversationAssistantMessage = class {
|
|
|
62204
62150
|
if (config) {
|
|
62205
62151
|
Object.assign(this, config.toObject());
|
|
62206
62152
|
switch (config.getMessageCase()) {
|
|
62207
|
-
case
|
|
62208
|
-
case
|
|
62209
|
-
case
|
|
62153
|
+
case import_common_pb7.AssistantConversationUserMessage.MessageCase.MESSAGE_NOT_SET:
|
|
62154
|
+
case import_common_pb7.AssistantConversationUserMessage.MessageCase.AUDIO:
|
|
62155
|
+
case import_common_pb7.AssistantConversationUserMessage.MessageCase.TEXT:
|
|
62210
62156
|
this.messageText = config.getText()?.getContent();
|
|
62211
62157
|
}
|
|
62212
62158
|
}
|
|
62213
62159
|
}
|
|
62214
62160
|
};
|
|
62215
|
-
var ConversationMessage = class {
|
|
62216
|
-
constructor(config) {
|
|
62217
|
-
if (config) {
|
|
62218
|
-
Object.assign(this, config.toObject());
|
|
62219
|
-
this.userMessage = toContentText(config.getRequest()?.getContentsList());
|
|
62220
|
-
this.systemMessage = toContentText(
|
|
62221
|
-
config.getResponse()?.getContentsList()
|
|
62222
|
-
);
|
|
62223
|
-
}
|
|
62224
|
-
}
|
|
62225
|
-
};
|
|
62226
62161
|
|
|
62227
62162
|
// src/agents/voice-agent.ts
|
|
62228
62163
|
var VoiceAgent = class extends Agent {
|
|
@@ -62260,13 +62195,14 @@ var VoiceAgent = class extends Agent {
|
|
|
62260
62195
|
connectDevice = async () => {
|
|
62261
62196
|
try {
|
|
62262
62197
|
this.preliminaryInputStream = await this.waitForUserMediaPermission();
|
|
62263
|
-
|
|
62264
|
-
|
|
62265
|
-
|
|
62266
|
-
|
|
62198
|
+
this.output = await Output.create(this.agentConfig.outputOptions.playerOption);
|
|
62199
|
+
this.input = await Input.create(
|
|
62200
|
+
this.agentConfig.inputOptions.recorderOption,
|
|
62201
|
+
this.preliminaryInputStream
|
|
62202
|
+
// Reuse the same MediaStream
|
|
62203
|
+
);
|
|
62267
62204
|
this.input.worklet.port.onmessage = this.onInputWorkletMessage;
|
|
62268
62205
|
this.output.worklet.port.onmessage = this.onOutputWorkletMessage;
|
|
62269
|
-
this.preliminaryInputStream?.getTracks().forEach((track) => track.stop());
|
|
62270
62206
|
this.preliminaryInputStream = null;
|
|
62271
62207
|
} catch (error) {
|
|
62272
62208
|
await this.disconnectAudio();
|
|
@@ -62276,7 +62212,20 @@ var VoiceAgent = class extends Agent {
|
|
|
62276
62212
|
// Helper method to handle media permissions:
|
|
62277
62213
|
waitForUserMediaPermission = async () => {
|
|
62278
62214
|
try {
|
|
62279
|
-
|
|
62215
|
+
const sampleRate = this.agentConfig.inputOptions.recorderOption.sampleRate;
|
|
62216
|
+
const options = isChrome() ? {
|
|
62217
|
+
sampleRate: { ideal: sampleRate },
|
|
62218
|
+
echoCancellation: true,
|
|
62219
|
+
noiseSuppression: true,
|
|
62220
|
+
autoGainControl: true,
|
|
62221
|
+
channelCount: { ideal: 1 }
|
|
62222
|
+
} : {
|
|
62223
|
+
sampleRate: { ideal: sampleRate },
|
|
62224
|
+
echoCancellation: { ideal: true },
|
|
62225
|
+
noiseSuppression: { ideal: true },
|
|
62226
|
+
autoGainControl: { ideal: true }
|
|
62227
|
+
};
|
|
62228
|
+
return await navigator.mediaDevices.getUserMedia({ audio: options });
|
|
62280
62229
|
} catch (error) {
|
|
62281
62230
|
console.error(
|
|
62282
62231
|
"Permission denied or error while requesting microphone access:",
|
|
@@ -62474,13 +62423,13 @@ var VoiceAgent = class extends Agent {
|
|
|
62474
62423
|
onHandleInterruption = (interruptionData) => {
|
|
62475
62424
|
if (interruptionData) {
|
|
62476
62425
|
switch (interruptionData.getType()) {
|
|
62477
|
-
case
|
|
62426
|
+
case import_common_pb8.AssistantConversationInterruption.InterruptionType.INTERRUPTION_TYPE_UNSPECIFIED:
|
|
62478
62427
|
console.log("Unspecified interruption type");
|
|
62479
62428
|
break;
|
|
62480
|
-
case
|
|
62429
|
+
case import_common_pb8.AssistantConversationInterruption.InterruptionType.INTERRUPTION_TYPE_VAD:
|
|
62481
62430
|
this.fadeOutAudio();
|
|
62482
62431
|
break;
|
|
62483
|
-
case
|
|
62432
|
+
case import_common_pb8.AssistantConversationInterruption.InterruptionType.INTERRUPTION_TYPE_WORD:
|
|
62484
62433
|
if (this.agentMessages.length > 0) {
|
|
62485
62434
|
const lastIndex = this.agentMessages.length - 1;
|
|
62486
62435
|
this.agentMessages[lastIndex] = {
|
|
@@ -62507,9 +62456,9 @@ var VoiceAgent = class extends Agent {
|
|
|
62507
62456
|
onHandleUser = (userContent) => {
|
|
62508
62457
|
if (userContent) {
|
|
62509
62458
|
switch (userContent.getMessageCase()) {
|
|
62510
|
-
case
|
|
62511
|
-
case
|
|
62512
|
-
case
|
|
62459
|
+
case import_common_pb8.AssistantConversationUserMessage.MessageCase.MESSAGE_NOT_SET:
|
|
62460
|
+
case import_common_pb8.AssistantConversationUserMessage.MessageCase.AUDIO:
|
|
62461
|
+
case import_common_pb8.AssistantConversationUserMessage.MessageCase.TEXT:
|
|
62513
62462
|
const agentTranscript = userContent.getText()?.getContent();
|
|
62514
62463
|
if (agentTranscript) {
|
|
62515
62464
|
if (this.agentMessages.length > 0) {
|
|
@@ -62541,14 +62490,15 @@ var VoiceAgent = class extends Agent {
|
|
|
62541
62490
|
onHandleAssistant = (systemContent) => {
|
|
62542
62491
|
if (systemContent) {
|
|
62543
62492
|
switch (systemContent.getMessageCase()) {
|
|
62544
|
-
case
|
|
62545
|
-
case
|
|
62493
|
+
case import_common_pb8.AssistantConversationAssistantMessage.MessageCase.MESSAGE_NOT_SET:
|
|
62494
|
+
case import_common_pb8.AssistantConversationAssistantMessage.MessageCase.AUDIO:
|
|
62546
62495
|
const content = systemContent.getAudio();
|
|
62547
62496
|
if (content) {
|
|
62548
62497
|
const audioData = content.getContent_asU8();
|
|
62549
62498
|
this.addAudioChunk(new Uint8Array(audioData).buffer);
|
|
62550
62499
|
}
|
|
62551
|
-
|
|
62500
|
+
break;
|
|
62501
|
+
case import_common_pb8.AssistantConversationAssistantMessage.MessageCase.TEXT:
|
|
62552
62502
|
const systemTranscript = systemContent.getText()?.getContent();
|
|
62553
62503
|
if (systemTranscript) {
|
|
62554
62504
|
if (systemContent.getCompleted()) {
|
|
@@ -62632,8 +62582,6 @@ var VoiceAgent = class extends Agent {
|
|
|
62632
62582
|
const conversation = response.getConfiguration();
|
|
62633
62583
|
if (!conversation?.getAssistantconversationid()) return;
|
|
62634
62584
|
break;
|
|
62635
|
-
case import_talk_api_pb2.AssistantMessagingResponse.DataCase.MESSAGE:
|
|
62636
|
-
break;
|
|
62637
62585
|
default:
|
|
62638
62586
|
break;
|
|
62639
62587
|
}
|
|
@@ -62648,7 +62596,7 @@ var VoiceAgent = class extends Agent {
|
|
|
62648
62596
|
case import_talk_api_pb2.AssistantMessagingResponse.DataCase.DATA_NOT_SET:
|
|
62649
62597
|
break;
|
|
62650
62598
|
case import_talk_api_pb2.AssistantMessagingResponse.DataCase.ACTION:
|
|
62651
|
-
if (response.getAction()?.getAction() ===
|
|
62599
|
+
if (response.getAction()?.getAction() === import_common_pb8.AssistantConversationAction.ActionType.END_CONVERSATION) {
|
|
62652
62600
|
await this.disconnect();
|
|
62653
62601
|
}
|
|
62654
62602
|
if (agentCallback && agentCallback?.onAction) {
|
|
@@ -62683,13 +62631,6 @@ var VoiceAgent = class extends Agent {
|
|
|
62683
62631
|
const cnvId = response.getConfiguration()?.getAssistantconversationid();
|
|
62684
62632
|
if (cnvId) this.changeConversation(cnvId);
|
|
62685
62633
|
break;
|
|
62686
|
-
case import_talk_api_pb2.AssistantMessagingResponse.DataCase.MESSAGE:
|
|
62687
|
-
if (agentCallback && agentCallback?.onMessage) {
|
|
62688
|
-
agentCallback.onMessage(
|
|
62689
|
-
new ConversationMessage(response.getMessage())
|
|
62690
|
-
);
|
|
62691
|
-
}
|
|
62692
|
-
break;
|
|
62693
62634
|
default:
|
|
62694
62635
|
break;
|
|
62695
62636
|
}
|
|
@@ -62725,6 +62666,36 @@ var VoiceAgent = class extends Agent {
|
|
|
62725
62666
|
};
|
|
62726
62667
|
};
|
|
62727
62668
|
|
|
62669
|
+
// src/utils/rapida_content.ts
|
|
62670
|
+
var import_common_pb9 = __toESM(require_common_pb());
|
|
62671
|
+
var TEXT_CONTENT_FORMAT_RAW = "raw";
|
|
62672
|
+
var AUDIO_CONTENT_FORMAT_CHUNK = "chunk";
|
|
62673
|
+
var toTextContent = (str, format) => {
|
|
62674
|
+
const cnt = new import_common_pb9.Content();
|
|
62675
|
+
if (format) cnt.setContentformat(format);
|
|
62676
|
+
else cnt.setContentformat(TEXT_CONTENT_FORMAT_RAW);
|
|
62677
|
+
cnt.setContenttype("text" /* TEXT_CONTENT */);
|
|
62678
|
+
cnt.setContent(new TextEncoder().encode(str));
|
|
62679
|
+
return cnt;
|
|
62680
|
+
};
|
|
62681
|
+
var toStreamAudioContent = (raw) => {
|
|
62682
|
+
const cnt = new import_common_pb9.Content();
|
|
62683
|
+
cnt.setContentformat(AUDIO_CONTENT_FORMAT_CHUNK);
|
|
62684
|
+
cnt.setContenttype("audio" /* AUDIO_CONTENT */);
|
|
62685
|
+
cnt.setContent(raw);
|
|
62686
|
+
return cnt;
|
|
62687
|
+
};
|
|
62688
|
+
var toContentText = (cnt) => {
|
|
62689
|
+
if (!cnt) return "";
|
|
62690
|
+
return cnt.filter((x) => x.getContenttype() === "text").map((x) => {
|
|
62691
|
+
try {
|
|
62692
|
+
return new TextDecoder().decode(x.getContent());
|
|
62693
|
+
} catch (error) {
|
|
62694
|
+
return "";
|
|
62695
|
+
}
|
|
62696
|
+
}).join(" ");
|
|
62697
|
+
};
|
|
62698
|
+
|
|
62728
62699
|
// src/hooks/use-message-feedback.ts
|
|
62729
62700
|
var React = __toESM(require("react"));
|
|
62730
62701
|
function useMessageFeedback(agent) {
|