@hivegpt/hiveai-angular 0.0.602 → 0.0.604

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.
@@ -4311,7 +4311,7 @@ class ChatDrawerComponent {
4311
4311
  return;
4312
4312
  }
4313
4313
  this.disconnectAskWebSocket();
4314
- const askNewUrl = `${this.environment.BASE_URL}/ask-new`;
4314
+ const askNewUrl = `${this.environment.BASE_URL}/ai/ask-new`;
4315
4315
  const connectBody = {
4316
4316
  bot_id: this.botId,
4317
4317
  conversation_id: conversationId,
@@ -4379,6 +4379,158 @@ class ChatDrawerComponent {
4379
4379
  }
4380
4380
  return currentChatMessage;
4381
4381
  }
4382
+ getToolContentString(toolResult) {
4383
+ const content = toolResult?.tool_result?.messages?.[0]?.content ??
4384
+ toolResult?.messages?.[0]?.content ??
4385
+ toolResult?.content ??
4386
+ '';
4387
+ if (typeof content === 'string')
4388
+ return content;
4389
+ if (content == null)
4390
+ return '';
4391
+ try {
4392
+ return JSON.stringify(content);
4393
+ }
4394
+ catch (error) {
4395
+ return '';
4396
+ }
4397
+ }
4398
+ getPrimaryToolResult(toolResults) {
4399
+ if (!toolResults)
4400
+ return null;
4401
+ const candidates = [];
4402
+ if (Array.isArray(toolResults)) {
4403
+ candidates.push(...toolResults);
4404
+ }
4405
+ else {
4406
+ candidates.push(toolResults);
4407
+ if (toolResults?.serializable_to_return) {
4408
+ candidates.push(toolResults.serializable_to_return);
4409
+ }
4410
+ if (typeof toolResults === 'object') {
4411
+ Object.entries(toolResults).forEach(([key, value]) => {
4412
+ if (value && typeof value === 'object') {
4413
+ const v = value;
4414
+ candidates.push({ ...v, tool_name: v?.tool_name || key });
4415
+ }
4416
+ });
4417
+ }
4418
+ }
4419
+ for (const candidate of candidates) {
4420
+ const toolName = candidate?.tool_name;
4421
+ const content = this.getToolContentString(candidate);
4422
+ if (toolName && content) {
4423
+ return { toolName, content };
4424
+ }
4425
+ }
4426
+ return null;
4427
+ }
4428
+ applyToolResultCardMessage(currentChatMessage, messageId, answerText, toolResults) {
4429
+ const primaryTool = this.getPrimaryToolResult(toolResults);
4430
+ if (!primaryTool)
4431
+ return false;
4432
+ const toolName = primaryTool.toolName;
4433
+ const contentStr = primaryTool.content;
4434
+ const setBase = (type) => {
4435
+ currentChatMessage._id = messageId;
4436
+ currentChatMessage.type = type;
4437
+ currentChatMessage.message = answerText
4438
+ ? this.processMessageForDisplay(answerText)
4439
+ : '';
4440
+ currentChatMessage.time = currentChatMessage.time || formatNow(this.timezone);
4441
+ };
4442
+ const isSessionTool = toolName === 'get_event_sessions' ||
4443
+ toolName === 'get_event_sessions_v2' ||
4444
+ toolName === 'get_sessions_by_interest' ||
4445
+ toolName === 'get_sessions_by_track' ||
4446
+ toolName === 'get_speaker_sessions' ||
4447
+ toolName === 'get_upcoming_sessions' ||
4448
+ toolName === 'get_my_agenda';
4449
+ if (isSessionTool) {
4450
+ let sessions = [];
4451
+ try {
4452
+ const parsed = JSON.parse(contentStr);
4453
+ sessions = parsed?.sessions ?? [];
4454
+ }
4455
+ catch (error) {
4456
+ sessions = this.parseSessionContentV2(contentStr);
4457
+ }
4458
+ const mapped = this.mapSessionsToCardData(sessions);
4459
+ this.ensureSpeakersForSessionCards(mapped);
4460
+ if (mapped.length > 0) {
4461
+ setBase('session_cards');
4462
+ currentChatMessage.sessionCards = mapped;
4463
+ return true;
4464
+ }
4465
+ return false;
4466
+ }
4467
+ if (toolName === 'get_event_attendees') {
4468
+ try {
4469
+ const parsed = JSON.parse(contentStr);
4470
+ const mapped = this.mapAttendeesToCardData(parsed?.attendees ?? []);
4471
+ if (mapped.length > 0) {
4472
+ setBase('attendee_cards');
4473
+ currentChatMessage.attendeeCards = mapped;
4474
+ return true;
4475
+ }
4476
+ }
4477
+ catch (error) { }
4478
+ return false;
4479
+ }
4480
+ if (toolName === 'get_event_speakers') {
4481
+ try {
4482
+ const parsed = JSON.parse(contentStr);
4483
+ const mapped = this.mapSpeakersToCardData(parsed?.speakers ?? parsed?.speaker ?? []);
4484
+ if (mapped.length > 0) {
4485
+ setBase('speaker_cards');
4486
+ currentChatMessage.speakerCards = mapped;
4487
+ return true;
4488
+ }
4489
+ }
4490
+ catch (error) { }
4491
+ return false;
4492
+ }
4493
+ if (toolName === 'get_event_sponsors') {
4494
+ try {
4495
+ const parsed = JSON.parse(contentStr);
4496
+ const mapped = this.mapSponsorsToCardData(parsed?.sponsors ?? []);
4497
+ if (mapped.length > 0) {
4498
+ setBase('sponsor_cards');
4499
+ currentChatMessage.sponsorCards = mapped;
4500
+ return true;
4501
+ }
4502
+ }
4503
+ catch (error) { }
4504
+ return false;
4505
+ }
4506
+ if (toolName === 'get_event_booths') {
4507
+ try {
4508
+ const parsed = JSON.parse(contentStr);
4509
+ const mapped = this.mapBoothsToCardData(parsed?.booths ?? []);
4510
+ if (mapped.length > 0) {
4511
+ setBase('sponsor_cards');
4512
+ currentChatMessage.sponsorCards = mapped;
4513
+ return true;
4514
+ }
4515
+ }
4516
+ catch (error) { }
4517
+ return false;
4518
+ }
4519
+ if (toolName === 'get_booth_representatives') {
4520
+ try {
4521
+ const parsed = JSON.parse(contentStr);
4522
+ const mapped = this.mapBoothRepsToCardData(parsed?.representatives ?? []);
4523
+ if (mapped.length > 0) {
4524
+ setBase('booth_rep_cards');
4525
+ currentChatMessage.boothRepCards = mapped;
4526
+ return true;
4527
+ }
4528
+ }
4529
+ catch (error) { }
4530
+ return false;
4531
+ }
4532
+ return false;
4533
+ }
4382
4534
  handleAskWebSocketMessage(rawMessage) {
4383
4535
  if (!rawMessage)
4384
4536
  return;
@@ -4413,7 +4565,11 @@ class ChatDrawerComponent {
4413
4565
  }
4414
4566
  const currentChatMessage = this.upsertAiChatMessage(messageId);
4415
4567
  const finalAnswer = payload?.text ?? currentChatMessage.message ?? '';
4416
- currentChatMessage.message = this.processMessageForDisplay(finalAnswer);
4568
+ const hasCardResponse = this.applyToolResultCardMessage(currentChatMessage, messageId, finalAnswer, payload?.tool_results);
4569
+ if (!hasCardResponse) {
4570
+ currentChatMessage.type = 'ai';
4571
+ currentChatMessage.message = this.processMessageForDisplay(finalAnswer);
4572
+ }
4417
4573
  if (Array.isArray(payload?.suggestions)) {
4418
4574
  currentChatMessage.relatedListItems = payload.suggestions;
4419
4575
  }