elasticdash-test 0.1.18-alpha-23 → 0.1.18-alpha-24
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 +1 -1
- package/src/interceptors/workflow-ai.ts +33 -12
package/package.json
CHANGED
|
@@ -64,15 +64,36 @@ function extractUsage(output: unknown): UsageInfo | undefined {
|
|
|
64
64
|
* HTTP payload sent to the LLM (messages, model, parameters).
|
|
65
65
|
* Also returns captured usage when the app's output doesn't include it.
|
|
66
66
|
*/
|
|
67
|
-
function enrichFromLLMCapture(
|
|
67
|
+
function enrichFromLLMCapture(
|
|
68
|
+
input: unknown,
|
|
69
|
+
appUsage: UsageInfo | undefined,
|
|
70
|
+
fallbackModel?: string,
|
|
71
|
+
fallbackProvider?: string,
|
|
72
|
+
): { input: unknown; usage: UsageInfo | undefined } {
|
|
68
73
|
const captured = consumeCapturedLLMRequest()
|
|
69
|
-
if (
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
74
|
+
if (captured) {
|
|
75
|
+
const enrichedInput = (input && typeof input === 'object')
|
|
76
|
+
? { ...(input as Record<string, unknown>), llmRequest: captured.body, promptSnippet: captured.promptSnippet }
|
|
77
|
+
: { originalInput: input, llmRequest: captured.body, promptSnippet: captured.promptSnippet }
|
|
78
|
+
const usage = appUsage ?? captured.usage
|
|
79
|
+
return { input: enrichedInput, usage }
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// Interceptor capture failed (e.g. OpenAI SDK uses native fetch not globalThis.fetch).
|
|
83
|
+
// Fall back to model/provider from wrapAI options or function arguments.
|
|
84
|
+
const resolvedModel = fallbackModel
|
|
85
|
+
|| (input && typeof input === 'object' ? (input as Record<string, unknown>).model as string | undefined : undefined)
|
|
86
|
+
const resolvedProvider = fallbackProvider
|
|
87
|
+
|| (input && typeof input === 'object' ? (input as Record<string, unknown>).provider as string | undefined : undefined)
|
|
88
|
+
|
|
89
|
+
if (resolvedModel || resolvedProvider) {
|
|
90
|
+
const enrichedInput = (input && typeof input === 'object')
|
|
91
|
+
? { ...(input as Record<string, unknown>), llmRequest: { model: resolvedModel, provider: resolvedProvider } }
|
|
92
|
+
: { originalInput: input, llmRequest: { model: resolvedModel, provider: resolvedProvider } }
|
|
93
|
+
return { input: enrichedInput, usage: appUsage }
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return { input, usage: appUsage }
|
|
76
97
|
}
|
|
77
98
|
|
|
78
99
|
function isReadableStream(v: unknown): v is ReadableStream<Uint8Array> {
|
|
@@ -165,7 +186,7 @@ export function wrapAI<Args extends unknown[], R>(
|
|
|
165
186
|
const input = args.length === 1 ? args[0] : args
|
|
166
187
|
try {
|
|
167
188
|
const output = await callFn(...args)
|
|
168
|
-
const enriched = enrichFromLLMCapture(input, extractUsage(output))
|
|
189
|
+
const enriched = enrichFromLLMCapture(input, extractUsage(output), _options?.model, _options?.provider)
|
|
169
190
|
|
|
170
191
|
if (isReadableStream(output)) {
|
|
171
192
|
const [streamForCaller, streamForRecorder] = output.tee()
|
|
@@ -196,7 +217,7 @@ export function wrapAI<Args extends unknown[], R>(
|
|
|
196
217
|
pushTelemetryEvent(event)
|
|
197
218
|
return output
|
|
198
219
|
} catch (e) {
|
|
199
|
-
const enriched = enrichFromLLMCapture(input, undefined)
|
|
220
|
+
const enriched = enrichFromLLMCapture(input, undefined, _options?.model, _options?.provider)
|
|
200
221
|
const durationMs = rawDateNow() - start
|
|
201
222
|
pushTelemetryEvent({
|
|
202
223
|
id, type: 'ai', name: modelName, input: enriched.input,
|
|
@@ -327,7 +348,7 @@ export function wrapAI<Args extends unknown[], R>(
|
|
|
327
348
|
|
|
328
349
|
try {
|
|
329
350
|
const output = await callFn(...httpEffectiveArgs)
|
|
330
|
-
const enriched = enrichFromLLMCapture(input, extractUsage(output))
|
|
351
|
+
const enriched = enrichFromLLMCapture(input, extractUsage(output), _options?.model, _options?.provider)
|
|
331
352
|
|
|
332
353
|
if (isReadableStream(output)) {
|
|
333
354
|
const [streamForCaller, streamForRecorder] = output.tee()
|
|
@@ -358,7 +379,7 @@ export function wrapAI<Args extends unknown[], R>(
|
|
|
358
379
|
pushTelemetryEvent(event)
|
|
359
380
|
return output
|
|
360
381
|
} catch (e) {
|
|
361
|
-
const enriched = enrichFromLLMCapture(input, undefined)
|
|
382
|
+
const enriched = enrichFromLLMCapture(input, undefined, _options?.model, _options?.provider)
|
|
362
383
|
const durationMs = rawDateNow() - start
|
|
363
384
|
pushTelemetryEvent({
|
|
364
385
|
id, type: 'ai', name: modelName, input: enriched.input,
|