@posthog/ai 8.1.0 → 8.1.2

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.
@@ -215,7 +215,7 @@ function sanitizeValues(obj) {
215
215
  return jsonSafe;
216
216
  }
217
217
 
218
- var version = "8.1.0";
218
+ var version = "8.1.2";
219
219
 
220
220
  const DEFAULT_MAX_DEPTH = 3;
221
221
  const MAX_STACK_LINES = 20;
@@ -301,18 +301,16 @@ class LangChainCallbackHandler extends BaseCallbackHandler {
301
301
  this._setTraceOrSpanMetadata(chain, inputs, runId, parentRunId, metadata, tags, runName);
302
302
  }
303
303
  handleChainEnd(outputs, runId, parentRunId, tags, _kwargs) {
304
- this._logDebugEvent('on_chain_end', runId, parentRunId, {
304
+ this._logAndPopTraceOrSpan('on_chain_end', runId, parentRunId, {
305
305
  outputs,
306
306
  tags
307
- });
308
- this._popRunAndCaptureTraceOrSpan(runId, parentRunId, outputs);
307
+ }, outputs);
309
308
  }
310
309
  handleChainError(error, runId, parentRunId, tags, _kwargs) {
311
- this._logDebugEvent('on_chain_error', runId, parentRunId, {
310
+ this._logAndPopTraceOrSpan('on_chain_error', runId, parentRunId, {
312
311
  error,
313
312
  tags
314
- });
315
- this._popRunAndCaptureTraceOrSpan(runId, parentRunId, error);
313
+ }, error);
316
314
  }
317
315
  handleChatModelStart(serialized, messages, runId, parentRunId, extraParams, tags, metadata, runName) {
318
316
  this._logDebugEvent('on_chat_model_start', runId, parentRunId, {
@@ -333,62 +331,52 @@ class LangChainCallbackHandler extends BaseCallbackHandler {
333
331
  this._setLLMMetadata(serialized, runId, prompts, metadata, extraParams, runName);
334
332
  }
335
333
  handleLLMEnd(output, runId, parentRunId, tags, _extraParams) {
336
- this._logDebugEvent('on_llm_end', runId, parentRunId, {
334
+ this._logAndPopGeneration('on_llm_end', runId, parentRunId, {
337
335
  output,
338
336
  tags
339
- });
340
- this._popRunAndCaptureGeneration(runId, parentRunId, output);
337
+ }, output);
341
338
  }
342
339
  handleLLMError(err, runId, parentRunId, tags, _extraParams) {
343
- this._logDebugEvent('on_llm_error', runId, parentRunId, {
340
+ this._logAndPopGeneration('on_llm_error', runId, parentRunId, {
344
341
  err,
345
342
  tags
346
- });
347
- this._popRunAndCaptureGeneration(runId, parentRunId, err);
343
+ }, err);
348
344
  }
349
345
  handleToolStart(tool, input, runId, parentRunId, tags, metadata, runName) {
350
- this._logDebugEvent('on_tool_start', runId, parentRunId, {
346
+ this._logAndSetTraceOrSpan('on_tool_start', tool, input, runId, parentRunId, {
351
347
  input,
352
348
  tags
353
- });
354
- this._setParentOfRun(runId, parentRunId);
355
- this._setTraceOrSpanMetadata(tool, input, runId, parentRunId, metadata, tags, runName);
349
+ }, tags, metadata, runName);
356
350
  }
357
351
  handleToolEnd(output, runId, parentRunId, tags) {
358
- this._logDebugEvent('on_tool_end', runId, parentRunId, {
352
+ this._logAndPopTraceOrSpan('on_tool_end', runId, parentRunId, {
359
353
  output,
360
354
  tags
361
- });
362
- this._popRunAndCaptureTraceOrSpan(runId, parentRunId, output);
355
+ }, output);
363
356
  }
364
357
  handleToolError(err, runId, parentRunId, tags) {
365
- this._logDebugEvent('on_tool_error', runId, parentRunId, {
358
+ this._logAndPopTraceOrSpan('on_tool_error', runId, parentRunId, {
366
359
  err,
367
360
  tags
368
- });
369
- this._popRunAndCaptureTraceOrSpan(runId, parentRunId, err);
361
+ }, err);
370
362
  }
371
363
  handleRetrieverStart(retriever, query, runId, parentRunId, tags, metadata, name) {
372
- this._logDebugEvent('on_retriever_start', runId, parentRunId, {
364
+ this._logAndSetTraceOrSpan('on_retriever_start', retriever, query, runId, parentRunId, {
373
365
  query,
374
366
  tags
375
- });
376
- this._setParentOfRun(runId, parentRunId);
377
- this._setTraceOrSpanMetadata(retriever, query, runId, parentRunId, metadata, tags, name);
367
+ }, tags, metadata, name);
378
368
  }
379
369
  handleRetrieverEnd(documents, runId, parentRunId, tags) {
380
- this._logDebugEvent('on_retriever_end', runId, parentRunId, {
370
+ this._logAndPopTraceOrSpan('on_retriever_end', runId, parentRunId, {
381
371
  documents,
382
372
  tags
383
- });
384
- this._popRunAndCaptureTraceOrSpan(runId, parentRunId, documents);
373
+ }, documents);
385
374
  }
386
375
  handleRetrieverError(err, runId, parentRunId, tags) {
387
- this._logDebugEvent('on_retriever_error', runId, parentRunId, {
376
+ this._logAndPopTraceOrSpan('on_retriever_error', runId, parentRunId, {
388
377
  err,
389
378
  tags
390
- });
391
- this._popRunAndCaptureTraceOrSpan(runId, parentRunId, err);
379
+ }, err);
392
380
  }
393
381
  handleAgentAction(action, runId, parentRunId, tags) {
394
382
  this._logDebugEvent('on_agent_action', runId, parentRunId, {
@@ -408,6 +396,19 @@ class LangChainCallbackHandler extends BaseCallbackHandler {
408
396
 
409
397
  // ===== PRIVATE HELPERS =====
410
398
 
399
+ _logAndSetTraceOrSpan(eventName, serialized, input, runId, parentRunId, debugPayload, tags, metadata, runName) {
400
+ this._logDebugEvent(eventName, runId, parentRunId, debugPayload);
401
+ this._setParentOfRun(runId, parentRunId);
402
+ this._setTraceOrSpanMetadata(serialized, input, runId, parentRunId, metadata, tags, runName);
403
+ }
404
+ _logAndPopTraceOrSpan(eventName, runId, parentRunId, debugPayload, result) {
405
+ this._logDebugEvent(eventName, runId, parentRunId, debugPayload);
406
+ this._popRunAndCaptureTraceOrSpan(runId, parentRunId, result);
407
+ }
408
+ _logAndPopGeneration(eventName, runId, parentRunId, debugPayload, result) {
409
+ this._logDebugEvent(eventName, runId, parentRunId, debugPayload);
410
+ this._popRunAndCaptureGeneration(runId, parentRunId, result);
411
+ }
411
412
  _setParentOfRun(runId, parentRunId) {
412
413
  if (parentRunId) {
413
414
  this.parentTree[runId] = parentRunId;