incremnt 0.7.1 → 0.8.0

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.
@@ -100,6 +100,23 @@ function failedChecks(result) {
100
100
  return (result.checks ?? []).filter((check) => !check.passed);
101
101
  }
102
102
 
103
+ function nonEmptyStrings(values, { max = 12 } = {}) {
104
+ const unique = [];
105
+ const seen = new Set();
106
+ for (const value of Array.isArray(values) ? values : []) {
107
+ const text = typeof value === 'string' ? value.trim() : '';
108
+ if (!text || seen.has(text)) continue;
109
+ seen.add(text);
110
+ unique.push(text);
111
+ if (unique.length >= max) break;
112
+ }
113
+ return unique.length > 0 ? unique : undefined;
114
+ }
115
+
116
+ function countArray(values) {
117
+ return Array.isArray(values) ? values.length : undefined;
118
+ }
119
+
103
120
  function langfuseScoreTarget({ testCase = {}, context = {}, sessionId }) {
104
121
  const providerMetadata = context.providerResponse?.metadata ?? {};
105
122
  const caseMetadata = testCase.metadata ?? {};
@@ -138,6 +155,21 @@ export function buildPromptfooLangfuseScorePayload({
138
155
  const runId = scoreRunId(context, env, now);
139
156
  const mode = promptfooEvalMode(env);
140
157
  const provider = providerLabel(context);
158
+ const providerMetadata = context.providerResponse?.metadata ?? {};
159
+ const routingMetadata = providerMetadata.routingMetadata && typeof providerMetadata.routingMetadata === 'object'
160
+ ? providerMetadata.routingMetadata
161
+ : {};
162
+ const evidencePlan = routingMetadata.evidencePlan && typeof routingMetadata.evidencePlan === 'object'
163
+ ? routingMetadata.evidencePlan
164
+ : providerMetadata.evidencePlan && typeof providerMetadata.evidencePlan === 'object'
165
+ ? providerMetadata.evidencePlan
166
+ : {};
167
+ const contextBundle = routingMetadata.contextBundle && typeof routingMetadata.contextBundle === 'object'
168
+ ? routingMetadata.contextBundle
169
+ : {};
170
+ const structured = providerMetadata.structured && typeof providerMetadata.structured === 'object'
171
+ ? providerMetadata.structured
172
+ : {};
141
173
  const failed = failedChecks(result);
142
174
  const promptVersion = vars.promptVersion
143
175
  ?? testCase.metadata?.promptVersion
@@ -179,6 +211,29 @@ export function buildPromptfooLangfuseScorePayload({
179
211
  assertionCount: result.checks?.length ?? 0,
180
212
  failedAssertionKeys: failed.map((check) => check.key),
181
213
  failedAssertionReasons: failed.map((check) => check.reason).slice(0, 10),
214
+ route: firstString(routingMetadata.route, evidencePlan.route),
215
+ effectiveRoute: firstString(routingMetadata.effectiveRoute, evidencePlan.effectiveRoute),
216
+ requestedAction: firstString(routingMetadata.intent?.requestedAction),
217
+ intentConfidence: typeof routingMetadata.intent?.confidence === 'number' ? routingMetadata.intent.confidence : undefined,
218
+ contextCharCount: typeof routingMetadata.contextCharCount === 'number' ? routingMetadata.contextCharCount : undefined,
219
+ historyTurnCount: typeof routingMetadata.historyTurnCount === 'number' ? routingMetadata.historyTurnCount : undefined,
220
+ requiredTools: nonEmptyStrings(evidencePlan.requiredTools),
221
+ executedTools: nonEmptyStrings(evidencePlan.executedTools ?? routingMetadata.toolsUsed ?? contextBundle.executedTools),
222
+ evidenceGaps: nonEmptyStrings(evidencePlan.evidenceGaps),
223
+ missingDataFlags: nonEmptyStrings([
224
+ ...(routingMetadata.missingDataFlags ?? []),
225
+ ...(contextBundle.missingDataFlags ?? []),
226
+ ...(evidencePlan.evidenceGaps ?? [])
227
+ ]),
228
+ structuredResponsePresent: Object.keys(structured).length > 0 ? true : undefined,
229
+ structuredConfidence: firstString(structured.confidence),
230
+ followUpSuggestionCount: countArray(structured.followUpSuggestions),
231
+ limitationCount: countArray(structured.limitations),
232
+ evidenceUsedLabels: nonEmptyStrings((structured.evidenceUsed ?? []).map((item) => item?.label)),
233
+ evidenceUsedTools: nonEmptyStrings((structured.evidenceUsed ?? []).map((item) => item?.toolName)),
234
+ recommendedActionIds: nonEmptyStrings((structured.recommendedActions ?? []).map((item) => item?.id)),
235
+ recommendedActionLabels: nonEmptyStrings((structured.recommendedActions ?? []).map((item) => item?.label)),
236
+ hasProgramDraft: structured.programDraft != null ? true : undefined,
182
237
  generatedAt: now.toISOString()
183
238
  }),
184
239
  environment: env.LANGFUSE_ENVIRONMENT ?? env.NODE_ENV ?? 'development'