Skip to content

Commit 7c0496d

Browse files
authored
fix(firebaseai): fix the json parse for toolCallCancellation (#17690)
1 parent 41890d6 commit 7c0496d

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

packages/firebase_ai/firebase_ai/lib/src/live_api.dart

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,8 +322,13 @@ LiveServerMessage _parseServerMessage(Object jsonObject) {
322322

323323
return LiveServerToolCall(functionCalls: functionCalls);
324324
} else if (json.containsKey('toolCallCancellation')) {
325-
final toolCancelJson =
326-
json['toolCallCancellation'] as Map<String, List<String>>;
325+
final toolCancelData = json['toolCallCancellation'] as Map;
326+
final Map<String, List<String>> toolCancelJson = toolCancelData.map(
327+
(key, value) => MapEntry(
328+
key as String,
329+
(value as List).cast<String>(),
330+
),
331+
);
327332
return LiveServerToolCallCancellation(functionIds: toolCancelJson['ids']);
328333
} else if (json.containsKey('setupComplete')) {
329334
return LiveServerSetupComplete();

packages/firebase_ai/firebase_ai/test/live_test.dart

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
14+
import 'dart:convert';
1415
import 'dart:typed_data';
1516

1617
import 'package:firebase_ai/src/api.dart';
@@ -206,11 +207,13 @@ void main() {
206207

207208
test('parseServerMessage parses toolCallCancellation message correctly',
208209
() {
209-
final jsonObject = {
210-
'toolCallCancellation': {
211-
'ids': ['1', '2']
210+
final jsonObject = jsonDecode('''
211+
{
212+
"toolCallCancellation": {
213+
"ids": ["1", "2"]
214+
}
212215
}
213-
};
216+
''') as Map<String, dynamic>;
214217
final response = parseServerResponse(jsonObject);
215218
expect(response.message, isA<LiveServerToolCallCancellation>());
216219
final cancellationMessage =

0 commit comments

Comments
 (0)