@posthog/ai 4.2.0 → 4.2.1

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/lib/index.esm.js CHANGED
@@ -166,7 +166,15 @@ const sendEventToPosthog = ({
166
166
  };
167
167
  if (fullDebug) {
168
168
  // @ts-ignore
169
- console.log('Sending event to PostHog', properties);
169
+ console.log('Sending event to PostHog', JSON.stringify(properties));
170
+ try {
171
+ // @ts-ignore
172
+ console.log('Size of properties (kb)', Math.round(Buffer.byteLength(JSON.stringify(properties), STRING_FORMAT) / 1024 * 10000) / 10000);
173
+ // @ts-ignore
174
+ console.log('Size of properties (mb)', Math.round(Buffer.byteLength(JSON.stringify(properties), STRING_FORMAT) / 1024 / 1024 * 10000) / 10000);
175
+ } catch (error) {
176
+ console.error('Error printing size of properties', error);
177
+ }
170
178
  }
171
179
  client.capture({
172
180
  distinctId: distinctId ?? traceId,
@@ -587,18 +595,21 @@ const mapVercelPrompt = prompt => {
587
595
  try {
588
596
  // Trim the inputs array until its JSON size fits within MAX_OUTPUT_SIZE
589
597
  let serialized = JSON.stringify(inputs);
598
+ let removedCount = 0;
590
599
  while (Buffer.byteLength(serialized, 'utf8') > MAX_OUTPUT_SIZE && inputs.length > 0) {
591
- // Remove oldest message
592
600
  inputs.shift();
593
- // add blank message to beginning of array
601
+ removedCount++;
602
+ serialized = JSON.stringify(inputs);
603
+ }
604
+ if (removedCount > 0) {
605
+ // Add one placeholder to indicate how many were removed
594
606
  inputs.unshift({
595
607
  role: 'assistant',
596
- content: '[removed message due to size limit]'
608
+ content: `[${removedCount} message${removedCount === 1 ? '' : 's'} removed due to size limit]`
597
609
  });
598
- serialized = JSON.stringify(inputs);
599
610
  }
600
611
  } catch (error) {
601
- console.error('Error stringifying inputs');
612
+ console.error('Error stringifying inputs', error);
602
613
  return [{
603
614
  role: 'posthog',
604
615
  content: 'An error occurred while processing your request. Please try again.'