@hivegpt/hiveai-angular 0.0.603 → 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.
@@ -4370,6 +4370,157 @@ class ChatDrawerComponent {
4370
4370
  }
4371
4371
  return currentChatMessage;
4372
4372
  }
4373
+ getToolContentString(toolResult) {
4374
+ var _a, _b, _c, _d, _e, _f, _g, _h;
4375
+ const content = (_h = (_g = (_d = (_c = (_b = (_a = toolResult === null || toolResult === void 0 ? void 0 : toolResult.tool_result) === null || _a === void 0 ? void 0 : _a.messages) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.content) !== null && _d !== void 0 ? _d : (_f = (_e = toolResult === null || toolResult === void 0 ? void 0 : toolResult.messages) === null || _e === void 0 ? void 0 : _e[0]) === null || _f === void 0 ? void 0 : _f.content) !== null && _g !== void 0 ? _g : toolResult === null || toolResult === void 0 ? void 0 : toolResult.content) !== null && _h !== void 0 ? _h : '';
4376
+ if (typeof content === 'string')
4377
+ return content;
4378
+ if (content == null)
4379
+ return '';
4380
+ try {
4381
+ return JSON.stringify(content);
4382
+ }
4383
+ catch (error) {
4384
+ return '';
4385
+ }
4386
+ }
4387
+ getPrimaryToolResult(toolResults) {
4388
+ if (!toolResults)
4389
+ return null;
4390
+ const candidates = [];
4391
+ if (Array.isArray(toolResults)) {
4392
+ candidates.push(...toolResults);
4393
+ }
4394
+ else {
4395
+ candidates.push(toolResults);
4396
+ if (toolResults === null || toolResults === void 0 ? void 0 : toolResults.serializable_to_return) {
4397
+ candidates.push(toolResults.serializable_to_return);
4398
+ }
4399
+ if (typeof toolResults === 'object') {
4400
+ Object.entries(toolResults).forEach(([key, value]) => {
4401
+ if (value && typeof value === 'object') {
4402
+ const v = value;
4403
+ candidates.push(Object.assign(Object.assign({}, v), { tool_name: (v === null || v === void 0 ? void 0 : v.tool_name) || key }));
4404
+ }
4405
+ });
4406
+ }
4407
+ }
4408
+ for (const candidate of candidates) {
4409
+ const toolName = candidate === null || candidate === void 0 ? void 0 : candidate.tool_name;
4410
+ const content = this.getToolContentString(candidate);
4411
+ if (toolName && content) {
4412
+ return { toolName, content };
4413
+ }
4414
+ }
4415
+ return null;
4416
+ }
4417
+ applyToolResultCardMessage(currentChatMessage, messageId, answerText, toolResults) {
4418
+ var _a, _b, _c, _d, _e, _f, _g;
4419
+ const primaryTool = this.getPrimaryToolResult(toolResults);
4420
+ if (!primaryTool)
4421
+ return false;
4422
+ const toolName = primaryTool.toolName;
4423
+ const contentStr = primaryTool.content;
4424
+ const setBase = (type) => {
4425
+ currentChatMessage._id = messageId;
4426
+ currentChatMessage.type = type;
4427
+ currentChatMessage.message = answerText
4428
+ ? this.processMessageForDisplay(answerText)
4429
+ : '';
4430
+ currentChatMessage.time = currentChatMessage.time || formatNow(this.timezone);
4431
+ };
4432
+ const isSessionTool = toolName === 'get_event_sessions' ||
4433
+ toolName === 'get_event_sessions_v2' ||
4434
+ toolName === 'get_sessions_by_interest' ||
4435
+ toolName === 'get_sessions_by_track' ||
4436
+ toolName === 'get_speaker_sessions' ||
4437
+ toolName === 'get_upcoming_sessions' ||
4438
+ toolName === 'get_my_agenda';
4439
+ if (isSessionTool) {
4440
+ let sessions = [];
4441
+ try {
4442
+ const parsed = JSON.parse(contentStr);
4443
+ sessions = (_a = parsed === null || parsed === void 0 ? void 0 : parsed.sessions) !== null && _a !== void 0 ? _a : [];
4444
+ }
4445
+ catch (error) {
4446
+ sessions = this.parseSessionContentV2(contentStr);
4447
+ }
4448
+ const mapped = this.mapSessionsToCardData(sessions);
4449
+ this.ensureSpeakersForSessionCards(mapped);
4450
+ if (mapped.length > 0) {
4451
+ setBase('session_cards');
4452
+ currentChatMessage.sessionCards = mapped;
4453
+ return true;
4454
+ }
4455
+ return false;
4456
+ }
4457
+ if (toolName === 'get_event_attendees') {
4458
+ try {
4459
+ const parsed = JSON.parse(contentStr);
4460
+ const mapped = this.mapAttendeesToCardData((_b = parsed === null || parsed === void 0 ? void 0 : parsed.attendees) !== null && _b !== void 0 ? _b : []);
4461
+ if (mapped.length > 0) {
4462
+ setBase('attendee_cards');
4463
+ currentChatMessage.attendeeCards = mapped;
4464
+ return true;
4465
+ }
4466
+ }
4467
+ catch (error) { }
4468
+ return false;
4469
+ }
4470
+ if (toolName === 'get_event_speakers') {
4471
+ try {
4472
+ const parsed = JSON.parse(contentStr);
4473
+ const mapped = this.mapSpeakersToCardData((_d = (_c = parsed === null || parsed === void 0 ? void 0 : parsed.speakers) !== null && _c !== void 0 ? _c : parsed === null || parsed === void 0 ? void 0 : parsed.speaker) !== null && _d !== void 0 ? _d : []);
4474
+ if (mapped.length > 0) {
4475
+ setBase('speaker_cards');
4476
+ currentChatMessage.speakerCards = mapped;
4477
+ return true;
4478
+ }
4479
+ }
4480
+ catch (error) { }
4481
+ return false;
4482
+ }
4483
+ if (toolName === 'get_event_sponsors') {
4484
+ try {
4485
+ const parsed = JSON.parse(contentStr);
4486
+ const mapped = this.mapSponsorsToCardData((_e = parsed === null || parsed === void 0 ? void 0 : parsed.sponsors) !== null && _e !== void 0 ? _e : []);
4487
+ if (mapped.length > 0) {
4488
+ setBase('sponsor_cards');
4489
+ currentChatMessage.sponsorCards = mapped;
4490
+ return true;
4491
+ }
4492
+ }
4493
+ catch (error) { }
4494
+ return false;
4495
+ }
4496
+ if (toolName === 'get_event_booths') {
4497
+ try {
4498
+ const parsed = JSON.parse(contentStr);
4499
+ const mapped = this.mapBoothsToCardData((_f = parsed === null || parsed === void 0 ? void 0 : parsed.booths) !== null && _f !== void 0 ? _f : []);
4500
+ if (mapped.length > 0) {
4501
+ setBase('sponsor_cards');
4502
+ currentChatMessage.sponsorCards = mapped;
4503
+ return true;
4504
+ }
4505
+ }
4506
+ catch (error) { }
4507
+ return false;
4508
+ }
4509
+ if (toolName === 'get_booth_representatives') {
4510
+ try {
4511
+ const parsed = JSON.parse(contentStr);
4512
+ const mapped = this.mapBoothRepsToCardData((_g = parsed === null || parsed === void 0 ? void 0 : parsed.representatives) !== null && _g !== void 0 ? _g : []);
4513
+ if (mapped.length > 0) {
4514
+ setBase('booth_rep_cards');
4515
+ currentChatMessage.boothRepCards = mapped;
4516
+ return true;
4517
+ }
4518
+ }
4519
+ catch (error) { }
4520
+ return false;
4521
+ }
4522
+ return false;
4523
+ }
4373
4524
  handleAskWebSocketMessage(rawMessage) {
4374
4525
  var _a, _b, _c, _d, _e;
4375
4526
  if (!rawMessage)
@@ -4405,7 +4556,11 @@ class ChatDrawerComponent {
4405
4556
  }
4406
4557
  const currentChatMessage = this.upsertAiChatMessage(messageId);
4407
4558
  const finalAnswer = (_c = (_b = payload === null || payload === void 0 ? void 0 : payload.text) !== null && _b !== void 0 ? _b : currentChatMessage.message) !== null && _c !== void 0 ? _c : '';
4408
- currentChatMessage.message = this.processMessageForDisplay(finalAnswer);
4559
+ const hasCardResponse = this.applyToolResultCardMessage(currentChatMessage, messageId, finalAnswer, payload === null || payload === void 0 ? void 0 : payload.tool_results);
4560
+ if (!hasCardResponse) {
4561
+ currentChatMessage.type = 'ai';
4562
+ currentChatMessage.message = this.processMessageForDisplay(finalAnswer);
4563
+ }
4409
4564
  if (Array.isArray(payload === null || payload === void 0 ? void 0 : payload.suggestions)) {
4410
4565
  currentChatMessage.relatedListItems = payload.suggestions;
4411
4566
  }