elasticdash-sdk 0.2.8 → 0.2.9
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/README.md +15 -8
- package/dist/index.cjs +445 -50
- package/dist/interceptors/ai-interceptor.d.ts +28 -0
- package/dist/interceptors/ai-interceptor.d.ts.map +1 -1
- package/dist/interceptors/ai-interceptor.js +535 -48
- package/dist/interceptors/ai-interceptor.js.map +1 -1
- package/dist/interceptors/http.d.ts.map +1 -1
- package/dist/interceptors/http.js +14 -9
- package/dist/interceptors/http.js.map +1 -1
- package/dist/interceptors/workflow-ai.d.ts.map +1 -1
- package/dist/interceptors/workflow-ai.js +5 -1
- package/dist/interceptors/workflow-ai.js.map +1 -1
- package/docs/agent-integration-guide.md +9 -5
- package/docs/matchers.md +1 -1
- package/docs/quickstart.md +8 -0
- package/docs/security-compliance.md +1 -1
- package/docs/test-writing-guidelines.md +23 -0
- package/package.json +1 -1
- package/src/interceptors/ai-interceptor.ts +528 -46
- package/src/interceptors/http.ts +17 -11
- package/src/interceptors/workflow-ai.ts +5 -1
package/src/interceptors/http.ts
CHANGED
|
@@ -12,6 +12,7 @@ const AI_URL_PATTERNS = [
|
|
|
12
12
|
/https?:\/\/generativelanguage\.googleapis\.com\/.*\/models\/[^/:]+:(generateContent|streamGenerateContent)/,
|
|
13
13
|
/https?:\/\/api\.x\.ai\/v1\/(chat\/)?completions/,
|
|
14
14
|
/https?:\/\/api\.moonshot\.ai\/v1\/(chat\/)?completions/,
|
|
15
|
+
/https?:\/\/bedrock-runtime\.[^./]+\.amazonaws\.com\/model\/[^/]+\/(invoke|invoke-with-response-stream|converse|converse-stream)/,
|
|
15
16
|
]
|
|
16
17
|
|
|
17
18
|
function isAIProviderUrl(url: string): boolean {
|
|
@@ -336,6 +337,22 @@ export function interceptFetch(): void {
|
|
|
336
337
|
const httpCtx = getHttpRunContext()
|
|
337
338
|
const obsCtx = getObservabilityContext()
|
|
338
339
|
|
|
340
|
+
const url =
|
|
341
|
+
typeof input === 'string'
|
|
342
|
+
? input
|
|
343
|
+
: input instanceof URL
|
|
344
|
+
? input.href
|
|
345
|
+
: (input as Request).url
|
|
346
|
+
|
|
347
|
+
// Let ai-interceptor handle AI provider URLs — it assigns its own event IDs.
|
|
348
|
+
// Short-circuit BEFORE attaching the mock-config header: AI provider servers
|
|
349
|
+
// don't run the SDK so they can't honor the header, and on Bedrock the
|
|
350
|
+
// gzipped header can exceed the edge proxy's header-size cap (yields a
|
|
351
|
+
// generic 400 "Request Header Or Cookie Too Large" page).
|
|
352
|
+
if (isAIProviderUrl(url)) {
|
|
353
|
+
return originalFetch!(input, init)
|
|
354
|
+
}
|
|
355
|
+
|
|
339
356
|
// Option-A passthrough: even when there is no SDK context active, if the
|
|
340
357
|
// CLI seeded mock globals we still attach the header so downstream Node
|
|
341
358
|
// processes (e.g. a Next.js dev server hit by an HTTP-mode workflow) can
|
|
@@ -348,21 +365,10 @@ export function interceptFetch(): void {
|
|
|
348
365
|
}
|
|
349
366
|
if (mockHeader) init = attachMockConfigHeader(init, mockHeader)
|
|
350
367
|
|
|
351
|
-
const url =
|
|
352
|
-
typeof input === 'string'
|
|
353
|
-
? input
|
|
354
|
-
: input instanceof URL
|
|
355
|
-
? input.href
|
|
356
|
-
: (input as Request).url
|
|
357
368
|
const method = (init?.method ?? (input instanceof Request ? input.method : 'GET')).toUpperCase()
|
|
358
369
|
const rawHeaders = init?.headers ?? (input instanceof Request ? input.headers : undefined)
|
|
359
370
|
const rawBody = init?.body ?? (input instanceof Request ? input.body : undefined)
|
|
360
371
|
|
|
361
|
-
// Let ai-interceptor handle AI provider URLs — it assigns its own event IDs
|
|
362
|
-
if (isAIProviderUrl(url)) {
|
|
363
|
-
return originalFetch!(input, init)
|
|
364
|
-
}
|
|
365
|
-
|
|
366
372
|
|
|
367
373
|
// --- Observability-only mode: record and push, no mocks/replay ---
|
|
368
374
|
if (!ctx && !httpCtx && obsCtx) {
|
|
@@ -96,7 +96,11 @@ function enrichFromLLMCapture(
|
|
|
96
96
|
return { input: enrichedInput, usage }
|
|
97
97
|
}
|
|
98
98
|
|
|
99
|
-
// Interceptor capture failed (e.g. OpenAI SDK uses native fetch not globalThis.fetch
|
|
99
|
+
// Interceptor capture failed (e.g. OpenAI SDK uses native fetch not globalThis.fetch;
|
|
100
|
+
// @aws-sdk/client-bedrock-runtime uses its own HTTP signer/handler on Node and likewise
|
|
101
|
+
// bypasses globalThis.fetch — when wrapping a Bedrock call, pass
|
|
102
|
+
// wrapAI(..., { provider: 'bedrock', model: '<modelId>' }) so this fallback enrichment
|
|
103
|
+
// still tags the event so mocked rerun can match it).
|
|
100
104
|
// Fall back to model/provider from wrapAI options or function arguments.
|
|
101
105
|
const resolvedModel = fallbackModel
|
|
102
106
|
|| (input && typeof input === 'object' ? (input as Record<string, unknown>).model as string | undefined : undefined)
|