@playpilot/tpi 8.40.0-beta.4 → 8.40.0-beta.5

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@playpilot/tpi",
3
- "version": "8.40.0-beta.4",
3
+ "version": "8.40.0-beta.5",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "dev": "vite dev",
@@ -30,39 +30,15 @@ export function injectLinksInDocument(elements: HTMLElement[], injections: LinkI
30
30
 
31
31
  const validInjections = filterInvalidInTextInjections(mergedInjections)
32
32
  const foundInjections = validInjections.filter(i => fullText.includes(cleanPhrase(i.sentence)))
33
-
34
- const failedMessages: Record<string, string> = {}
35
- const aiInjectionSidsCount: Record<string, number> = {}
36
- let aiParticipantInjectionsCount = 0
33
+ const { injections: limitedInjections, failedMessages } = limitInjectionsByCount(foundInjections)
37
34
 
38
35
  let injectionIndex = -1 // This index is used in Option 3 below.
39
- for (const injection of sortInjections(foundInjections)) {
36
+ for (const injection of sortInjections(limitedInjections)) {
40
37
  injectionIndex++
41
38
 
42
- if (!injection.manual) {
43
- const previousCount = aiInjectionSidsCount[injection.sid] || 0
44
-
45
- const exceedsUniqueCount =
46
- window.PlayPilotLinkInjections?.config?.unique_injection_count_limit &&
47
- previousCount >= window.PlayPilotLinkInjections?.config?.unique_injection_count_limit
48
-
49
- const exceedsTotalParticipantsCount =
50
- injection.type === 'participant' &&
51
- window.PlayPilotLinkInjections?.config?.total_participant_injection_count_limit &&
52
- aiParticipantInjectionsCount >= window.PlayPilotLinkInjections?.config?.total_participant_injection_count_limit
53
-
54
- if (exceedsUniqueCount || exceedsTotalParticipantsCount) {
55
- failedMessages[injection.key] = 'Injection was withheld because it exceeded the maximum unique count.'
56
- continue
57
- } else {
58
- aiInjectionSidsCount[injection.sid] = previousCount + 1
59
- if (injection.type === 'participant') aiParticipantInjectionsCount++
60
- }
61
-
62
- if (injection.type === 'participant' && !doesParticipantMeetThreshold(mergedInjections, injection.participant_details!)) {
63
- failedMessages[injection.key] = 'Participant does not meet popularity threshold.'
64
- continue
65
- }
39
+ if (!injection.manual && injection.type === 'participant' && !doesParticipantMeetThreshold(mergedInjections, injection.participant_details!)) {
40
+ failedMessages[injection.key] = 'Participant does not meet popularity threshold.'
41
+ continue
66
42
  }
67
43
 
68
44
  const elementIndex = elements.findIndex(element => cleanPhrase(element.innerText).includes(cleanPhrase(injection.sentence)))
@@ -468,6 +444,41 @@ export function filterRemovedAndInactiveInjections(injections: LinkInjection[]):
468
444
  })
469
445
  }
470
446
 
447
+ export function limitInjectionsByCount(injections: LinkInjection[]): { injections: LinkInjection[], failedMessages: Record<string, string> } {
448
+ const limitedInjections: LinkInjection[] = []
449
+ const failedMessages: Record<string, string> = {}
450
+
451
+ const aiInjectionSidsCount: Record<string, number> = {}
452
+ let aiParticipantInjectionsCount = 0
453
+
454
+ for (const injection of injections) {
455
+ if (!injection.manual) {
456
+ const previousCount = aiInjectionSidsCount[injection.sid] || 0
457
+
458
+ const exceedsUniqueCount =
459
+ window.PlayPilotLinkInjections?.config?.unique_injection_count_limit &&
460
+ previousCount >= window.PlayPilotLinkInjections?.config?.unique_injection_count_limit
461
+
462
+ const exceedsTotalParticipantsCount =
463
+ injection.type === 'participant' &&
464
+ window.PlayPilotLinkInjections?.config?.total_participant_injection_count_limit &&
465
+ aiParticipantInjectionsCount >= window.PlayPilotLinkInjections?.config?.total_participant_injection_count_limit
466
+
467
+ if (exceedsUniqueCount || exceedsTotalParticipantsCount) {
468
+ failedMessages[injection.key] = `Injection was withheld because it exceeded the maximum ${exceedsUniqueCount ? 'unique' : 'total'} count.`
469
+ continue
470
+ } else {
471
+ aiInjectionSidsCount[injection.sid] = previousCount + 1
472
+ if (injection.type === 'participant') aiParticipantInjectionsCount++
473
+ }
474
+ }
475
+
476
+ limitedInjections.push(injection)
477
+ }
478
+
479
+ return { injections: limitedInjections, failedMessages }
480
+ }
481
+
471
482
  /**
472
483
  * Injections are sorted first by their sentence and second by their title length. The first sorting, sentence, is so that injections remain
473
484
  * roughly grouped. The second sorting is to prevent shorter titles from merging into longer ones. For instance;