elasticdash-sdk 0.2.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.
- package/LICENSE +21 -0
- package/README.md +775 -0
- package/dist/browser-ui.d.ts +43 -0
- package/dist/browser-ui.d.ts.map +1 -0
- package/dist/browser-ui.js +246 -0
- package/dist/browser-ui.js.map +1 -0
- package/dist/capture/event.d.ts +33 -0
- package/dist/capture/event.d.ts.map +1 -0
- package/dist/capture/event.js +2 -0
- package/dist/capture/event.js.map +1 -0
- package/dist/capture/index.d.ts +4 -0
- package/dist/capture/index.d.ts.map +1 -0
- package/dist/capture/index.js +4 -0
- package/dist/capture/index.js.map +1 -0
- package/dist/capture/recorder.d.ts +24 -0
- package/dist/capture/recorder.d.ts.map +1 -0
- package/dist/capture/recorder.js +46 -0
- package/dist/capture/recorder.js.map +1 -0
- package/dist/capture/replay.d.ts +20 -0
- package/dist/capture/replay.d.ts.map +1 -0
- package/dist/capture/replay.js +47 -0
- package/dist/capture/replay.js.map +1 -0
- package/dist/ci/api-client.d.ts +38 -0
- package/dist/ci/api-client.d.ts.map +1 -0
- package/dist/ci/api-client.js +96 -0
- package/dist/ci/api-client.js.map +1 -0
- package/dist/ci/benchmark.d.ts +33 -0
- package/dist/ci/benchmark.d.ts.map +1 -0
- package/dist/ci/benchmark.js +213 -0
- package/dist/ci/benchmark.js.map +1 -0
- package/dist/ci/ed-runner.d.ts +48 -0
- package/dist/ci/ed-runner.d.ts.map +1 -0
- package/dist/ci/ed-runner.js +260 -0
- package/dist/ci/ed-runner.js.map +1 -0
- package/dist/ci/executor.d.ts +13 -0
- package/dist/ci/executor.d.ts.map +1 -0
- package/dist/ci/executor.js +542 -0
- package/dist/ci/executor.js.map +1 -0
- package/dist/ci/git-info.d.ts +17 -0
- package/dist/ci/git-info.d.ts.map +1 -0
- package/dist/ci/git-info.js +102 -0
- package/dist/ci/git-info.js.map +1 -0
- package/dist/ci/index.d.ts +6 -0
- package/dist/ci/index.d.ts.map +1 -0
- package/dist/ci/index.js +4 -0
- package/dist/ci/index.js.map +1 -0
- package/dist/ci/measurement.d.ts +9 -0
- package/dist/ci/measurement.d.ts.map +1 -0
- package/dist/ci/measurement.js +15 -0
- package/dist/ci/measurement.js.map +1 -0
- package/dist/ci/replay.d.ts +31 -0
- package/dist/ci/replay.d.ts.map +1 -0
- package/dist/ci/replay.js +96 -0
- package/dist/ci/replay.js.map +1 -0
- package/dist/ci/reporters/default.d.ts +8 -0
- package/dist/ci/reporters/default.d.ts.map +1 -0
- package/dist/ci/reporters/default.js +46 -0
- package/dist/ci/reporters/default.js.map +1 -0
- package/dist/ci/reporters/index.d.ts +8 -0
- package/dist/ci/reporters/index.d.ts.map +1 -0
- package/dist/ci/reporters/index.js +14 -0
- package/dist/ci/reporters/index.js.map +1 -0
- package/dist/ci/reporters/json.d.ts +8 -0
- package/dist/ci/reporters/json.d.ts.map +1 -0
- package/dist/ci/reporters/json.js +14 -0
- package/dist/ci/reporters/json.js.map +1 -0
- package/dist/ci/reporters/junit.d.ts +8 -0
- package/dist/ci/reporters/junit.d.ts.map +1 -0
- package/dist/ci/reporters/junit.js +48 -0
- package/dist/ci/reporters/junit.js.map +1 -0
- package/dist/ci/runner.d.ts +3 -0
- package/dist/ci/runner.d.ts.map +1 -0
- package/dist/ci/runner.js +187 -0
- package/dist/ci/runner.js.map +1 -0
- package/dist/ci/test-discovery.d.ts +5 -0
- package/dist/ci/test-discovery.d.ts.map +1 -0
- package/dist/ci/test-discovery.js +11 -0
- package/dist/ci/test-discovery.js.map +1 -0
- package/dist/ci/test-loader.d.ts +19 -0
- package/dist/ci/test-loader.d.ts.map +1 -0
- package/dist/ci/test-loader.js +149 -0
- package/dist/ci/test-loader.js.map +1 -0
- package/dist/ci/test-registry.d.ts +42 -0
- package/dist/ci/test-registry.d.ts.map +1 -0
- package/dist/ci/test-registry.js +18 -0
- package/dist/ci/test-registry.js.map +1 -0
- package/dist/ci/trace-schema.d.ts +30 -0
- package/dist/ci/trace-schema.d.ts.map +1 -0
- package/dist/ci/trace-schema.js +66 -0
- package/dist/ci/trace-schema.js.map +1 -0
- package/dist/ci/trace-writer.d.ts +16 -0
- package/dist/ci/trace-writer.d.ts.map +1 -0
- package/dist/ci/trace-writer.js +108 -0
- package/dist/ci/trace-writer.js.map +1 -0
- package/dist/ci/types.d.ts +108 -0
- package/dist/ci/types.d.ts.map +1 -0
- package/dist/ci/types.js +3 -0
- package/dist/ci/types.js.map +1 -0
- package/dist/ci/upload-client.d.ts +74 -0
- package/dist/ci/upload-client.d.ts.map +1 -0
- package/dist/ci/upload-client.js +195 -0
- package/dist/ci/upload-client.js.map +1 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +716 -0
- package/dist/cli.js.map +1 -0
- package/dist/core/agent-state.d.ts +47 -0
- package/dist/core/agent-state.d.ts.map +1 -0
- package/dist/core/agent-state.js +137 -0
- package/dist/core/agent-state.js.map +1 -0
- package/dist/core/judge-utils.d.ts +22 -0
- package/dist/core/judge-utils.d.ts.map +1 -0
- package/dist/core/judge-utils.js +211 -0
- package/dist/core/judge-utils.js.map +1 -0
- package/dist/core/registry.d.ts +28 -0
- package/dist/core/registry.d.ts.map +1 -0
- package/dist/core/registry.js +52 -0
- package/dist/core/registry.js.map +1 -0
- package/dist/dashboard-server.d.ts +65 -0
- package/dist/dashboard-server.d.ts.map +1 -0
- package/dist/dashboard-server.js +3940 -0
- package/dist/dashboard-server.js.map +1 -0
- package/dist/execution/tool-runner.d.ts +26 -0
- package/dist/execution/tool-runner.d.ts.map +1 -0
- package/dist/execution/tool-runner.js +316 -0
- package/dist/execution/tool-runner.js.map +1 -0
- package/dist/html/dashboard.html +2218 -0
- package/dist/http.d.ts +14 -0
- package/dist/http.d.ts.map +1 -0
- package/dist/http.js +13 -0
- package/dist/http.js.map +1 -0
- package/dist/index.cjs +8102 -0
- package/dist/index.d.ts +61 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +67 -0
- package/dist/index.js.map +1 -0
- package/dist/interceptors/ai-interceptor.d.ts +26 -0
- package/dist/interceptors/ai-interceptor.d.ts.map +1 -0
- package/dist/interceptors/ai-interceptor.js +756 -0
- package/dist/interceptors/ai-interceptor.js.map +1 -0
- package/dist/interceptors/db-auto.d.ts +8 -0
- package/dist/interceptors/db-auto.d.ts.map +1 -0
- package/dist/interceptors/db-auto.js +217 -0
- package/dist/interceptors/db-auto.js.map +1 -0
- package/dist/interceptors/db.d.ts +23 -0
- package/dist/interceptors/db.d.ts.map +1 -0
- package/dist/interceptors/db.js +137 -0
- package/dist/interceptors/db.js.map +1 -0
- package/dist/interceptors/http.d.ts +28 -0
- package/dist/interceptors/http.d.ts.map +1 -0
- package/dist/interceptors/http.js +356 -0
- package/dist/interceptors/http.js.map +1 -0
- package/dist/interceptors/side-effects.d.ts +7 -0
- package/dist/interceptors/side-effects.d.ts.map +1 -0
- package/dist/interceptors/side-effects.js +72 -0
- package/dist/interceptors/side-effects.js.map +1 -0
- package/dist/interceptors/telemetry-push.d.ts +142 -0
- package/dist/interceptors/telemetry-push.d.ts.map +1 -0
- package/dist/interceptors/telemetry-push.js +463 -0
- package/dist/interceptors/telemetry-push.js.map +1 -0
- package/dist/interceptors/tool.d.ts +2 -0
- package/dist/interceptors/tool.d.ts.map +1 -0
- package/dist/interceptors/tool.js +274 -0
- package/dist/interceptors/tool.js.map +1 -0
- package/dist/interceptors/workflow-ai.d.ts +5 -0
- package/dist/interceptors/workflow-ai.d.ts.map +1 -0
- package/dist/interceptors/workflow-ai.js +382 -0
- package/dist/interceptors/workflow-ai.js.map +1 -0
- package/dist/internals/conditional-recorder.d.ts +21 -0
- package/dist/internals/conditional-recorder.d.ts.map +1 -0
- package/dist/internals/conditional-recorder.js +54 -0
- package/dist/internals/conditional-recorder.js.map +1 -0
- package/dist/internals/mock-resolver.d.ts +146 -0
- package/dist/internals/mock-resolver.d.ts.map +1 -0
- package/dist/internals/mock-resolver.js +427 -0
- package/dist/internals/mock-resolver.js.map +1 -0
- package/dist/matchers/index.d.ts +96 -0
- package/dist/matchers/index.d.ts.map +1 -0
- package/dist/matchers/index.js +668 -0
- package/dist/matchers/index.js.map +1 -0
- package/dist/observability.d.ts +82 -0
- package/dist/observability.d.ts.map +1 -0
- package/dist/observability.js +471 -0
- package/dist/observability.js.map +1 -0
- package/dist/portal-executor.d.ts +30 -0
- package/dist/portal-executor.d.ts.map +1 -0
- package/dist/portal-executor.js +324 -0
- package/dist/portal-executor.js.map +1 -0
- package/dist/portal-server.d.ts +3 -0
- package/dist/portal-server.d.ts.map +1 -0
- package/dist/portal-server.js +279 -0
- package/dist/portal-server.js.map +1 -0
- package/dist/proxy/llm-capture.d.ts +14 -0
- package/dist/proxy/llm-capture.d.ts.map +1 -0
- package/dist/proxy/llm-capture.js +264 -0
- package/dist/proxy/llm-capture.js.map +1 -0
- package/dist/reporter.d.ts +3 -0
- package/dist/reporter.d.ts.map +1 -0
- package/dist/reporter.js +72 -0
- package/dist/reporter.js.map +1 -0
- package/dist/runWorkflowSubprocess.d.ts +14 -0
- package/dist/runWorkflowSubprocess.d.ts.map +1 -0
- package/dist/runWorkflowSubprocess.js +66 -0
- package/dist/runWorkflowSubprocess.js.map +1 -0
- package/dist/runner.d.ts +16 -0
- package/dist/runner.d.ts.map +1 -0
- package/dist/runner.js +138 -0
- package/dist/runner.js.map +1 -0
- package/dist/socket-connector.d.ts +22 -0
- package/dist/socket-connector.d.ts.map +1 -0
- package/dist/socket-connector.js +104 -0
- package/dist/socket-connector.js.map +1 -0
- package/dist/telemetry-batcher.d.ts +56 -0
- package/dist/telemetry-batcher.d.ts.map +1 -0
- package/dist/telemetry-batcher.js +143 -0
- package/dist/telemetry-batcher.js.map +1 -0
- package/dist/test-setup.d.ts +12 -0
- package/dist/test-setup.d.ts.map +1 -0
- package/dist/test-setup.js +13 -0
- package/dist/test-setup.js.map +1 -0
- package/dist/tool-registry.d.ts +31 -0
- package/dist/tool-registry.d.ts.map +1 -0
- package/dist/tool-registry.js +73 -0
- package/dist/tool-registry.js.map +1 -0
- package/dist/tool-runner-worker.d.ts +2 -0
- package/dist/tool-runner-worker.d.ts.map +1 -0
- package/dist/tool-runner-worker.js +215 -0
- package/dist/tool-runner-worker.js.map +1 -0
- package/dist/trace-adapter/context.d.ts +72 -0
- package/dist/trace-adapter/context.d.ts.map +1 -0
- package/dist/trace-adapter/context.js +80 -0
- package/dist/trace-adapter/context.js.map +1 -0
- package/dist/tracing.d.ts +2 -0
- package/dist/tracing.d.ts.map +1 -0
- package/dist/tracing.js +59 -0
- package/dist/tracing.js.map +1 -0
- package/dist/trigger-executor.d.ts +12 -0
- package/dist/trigger-executor.d.ts.map +1 -0
- package/dist/trigger-executor.js +130 -0
- package/dist/trigger-executor.js.map +1 -0
- package/dist/types/portal.d.ts +76 -0
- package/dist/types/portal.d.ts.map +1 -0
- package/dist/types/portal.js +2 -0
- package/dist/types/portal.js.map +1 -0
- package/dist/utils/debug.d.ts +3 -0
- package/dist/utils/debug.d.ts.map +1 -0
- package/dist/utils/debug.js +8 -0
- package/dist/utils/debug.js.map +1 -0
- package/dist/utils/license-error.d.ts +23 -0
- package/dist/utils/license-error.d.ts.map +1 -0
- package/dist/utils/license-error.js +42 -0
- package/dist/utils/license-error.js.map +1 -0
- package/dist/utils/redact.d.ts +7 -0
- package/dist/utils/redact.d.ts.map +1 -0
- package/dist/utils/redact.js +26 -0
- package/dist/utils/redact.js.map +1 -0
- package/dist/workflow-runner-worker.d.ts +2 -0
- package/dist/workflow-runner-worker.d.ts.map +1 -0
- package/dist/workflow-runner-worker.js +329 -0
- package/dist/workflow-runner-worker.js.map +1 -0
- package/dist/workflow-runner.d.ts +14 -0
- package/dist/workflow-runner.d.ts.map +1 -0
- package/dist/workflow-runner.js +34 -0
- package/dist/workflow-runner.js.map +1 -0
- package/docs/agent-coding-instructions.md +138 -0
- package/docs/agent-integration-guide.md +564 -0
- package/docs/agents.md +140 -0
- package/docs/dashboard.md +394 -0
- package/docs/deno.md +69 -0
- package/docs/instrumentation.md +424 -0
- package/docs/langfuse-trace-structure.md +145 -0
- package/docs/matchers.md +173 -0
- package/docs/observability_contract.md +192 -0
- package/docs/observability_mode.md +195 -0
- package/docs/quickstart.md +621 -0
- package/docs/security-compliance.md +566 -0
- package/docs/test-writing-guidelines.md +444 -0
- package/docs/tools.md +165 -0
- package/docs/workflow-modes.md +253 -0
- package/package.json +76 -0
- package/src/browser-ui.ts +281 -0
- package/src/capture/event.ts +30 -0
- package/src/capture/index.ts +3 -0
- package/src/capture/recorder.ts +62 -0
- package/src/capture/replay.ts +55 -0
- package/src/ci/api-client.ts +136 -0
- package/src/ci/benchmark.ts +257 -0
- package/src/ci/ed-runner.ts +351 -0
- package/src/ci/executor.ts +671 -0
- package/src/ci/git-info.ts +127 -0
- package/src/ci/index.ts +5 -0
- package/src/ci/measurement.ts +25 -0
- package/src/ci/replay.ts +127 -0
- package/src/ci/reporters/default.ts +50 -0
- package/src/ci/reporters/index.ts +21 -0
- package/src/ci/reporters/json.ts +18 -0
- package/src/ci/reporters/junit.ts +61 -0
- package/src/ci/runner.ts +208 -0
- package/src/ci/test-discovery.ts +16 -0
- package/src/ci/test-loader.ts +187 -0
- package/src/ci/test-registry.ts +62 -0
- package/src/ci/trace-schema.ts +96 -0
- package/src/ci/trace-writer.ts +107 -0
- package/src/ci/types.ts +115 -0
- package/src/ci/upload-client.ts +300 -0
- package/src/cli.ts +811 -0
- package/src/core/agent-state.ts +162 -0
- package/src/core/judge-utils.ts +232 -0
- package/src/core/registry.ts +92 -0
- package/src/dashboard-server.ts +2047 -0
- package/src/execution/tool-runner.ts +352 -0
- package/src/html/dashboard.html +2218 -0
- package/src/http.ts +13 -0
- package/src/index.ts +138 -0
- package/src/interceptors/ai-interceptor.ts +798 -0
- package/src/interceptors/db-auto.ts +243 -0
- package/src/interceptors/db.ts +156 -0
- package/src/interceptors/http.ts +393 -0
- package/src/interceptors/side-effects.ts +83 -0
- package/src/interceptors/telemetry-push.ts +537 -0
- package/src/interceptors/tool.ts +287 -0
- package/src/interceptors/workflow-ai.ts +419 -0
- package/src/internals/conditional-recorder.ts +63 -0
- package/src/internals/mock-resolver.ts +492 -0
- package/src/matchers/index.ts +824 -0
- package/src/observability.ts +501 -0
- package/src/portal-executor.ts +355 -0
- package/src/portal-server.ts +304 -0
- package/src/proxy/llm-capture.ts +301 -0
- package/src/reporter.ts +81 -0
- package/src/runWorkflowSubprocess.ts +74 -0
- package/src/runner.ts +178 -0
- package/src/socket-connector.ts +117 -0
- package/src/telemetry-batcher.ts +191 -0
- package/src/test-setup.ts +16 -0
- package/src/tool-registry.ts +94 -0
- package/src/tool-runner-worker.ts +244 -0
- package/src/trace-adapter/context.ts +156 -0
- package/src/tracing.ts +62 -0
- package/src/trigger-executor.ts +171 -0
- package/src/types/agent.d.ts +63 -0
- package/src/types/expect.d.ts +81 -0
- package/src/types/modules.d.ts +2 -0
- package/src/types/portal.ts +69 -0
- package/src/utils/debug.ts +8 -0
- package/src/utils/license-error.ts +43 -0
- package/src/utils/redact.ts +25 -0
- package/src/workflow-runner-worker.ts +386 -0
- package/src/workflow-runner.ts +58 -0
|
@@ -0,0 +1,382 @@
|
|
|
1
|
+
import { getCaptureContext } from '../capture/recorder.js';
|
|
2
|
+
import { rawDateNow } from './side-effects.js';
|
|
3
|
+
import { getHttpRunContext, getHttpFrozenEvent, getHttpPromptMock, getHttpUserPromptMock, getHttpAIMock, pushTelemetryEvent, tryAutoInitHttpContext, getObservabilityContext } from './telemetry-push.js';
|
|
4
|
+
import { resolveAIMock, resolvePromptMock, resolveUserPromptMock } from '../internals/mock-resolver.js';
|
|
5
|
+
import { consumeCapturedLLMRequest } from './ai-interceptor.js';
|
|
6
|
+
import { getEdReplayContext, replayCall } from '../ci/replay.js';
|
|
7
|
+
/**
|
|
8
|
+
* Tracks whether we are currently inside a `wrapAI` execution.
|
|
9
|
+
* When active, `ai-interceptor` should skip recording to avoid duplicates.
|
|
10
|
+
* Uses a counter (not boolean) to handle nested wrapAI calls correctly.
|
|
11
|
+
*/
|
|
12
|
+
const AI_WRAPPER_KEY = '__elasticdash_ai_wrapper_depth__';
|
|
13
|
+
const g = globalThis;
|
|
14
|
+
if (g[AI_WRAPPER_KEY] == null)
|
|
15
|
+
g[AI_WRAPPER_KEY] = 0;
|
|
16
|
+
function enterAIWrapper() {
|
|
17
|
+
g[AI_WRAPPER_KEY] = (g[AI_WRAPPER_KEY] ?? 0) + 1;
|
|
18
|
+
}
|
|
19
|
+
function leaveAIWrapper() {
|
|
20
|
+
g[AI_WRAPPER_KEY] = Math.max(0, (g[AI_WRAPPER_KEY] ?? 0) - 1);
|
|
21
|
+
}
|
|
22
|
+
function extractUsage(output) {
|
|
23
|
+
if (!output || typeof output !== 'object')
|
|
24
|
+
return undefined;
|
|
25
|
+
const o = output;
|
|
26
|
+
if (o.usage && typeof o.usage === 'object') {
|
|
27
|
+
const u = o.usage;
|
|
28
|
+
// Anthropic SDK: input_tokens / output_tokens
|
|
29
|
+
if (u.input_tokens != null || u.output_tokens != null) {
|
|
30
|
+
return {
|
|
31
|
+
inputTokens: u.input_tokens,
|
|
32
|
+
outputTokens: u.output_tokens,
|
|
33
|
+
totalTokens: (u.input_tokens ?? 0) + (u.output_tokens ?? 0),
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
// OpenAI SDK: prompt_tokens / completion_tokens
|
|
37
|
+
if (u.prompt_tokens != null || u.completion_tokens != null) {
|
|
38
|
+
return {
|
|
39
|
+
inputTokens: u.prompt_tokens,
|
|
40
|
+
outputTokens: u.completion_tokens,
|
|
41
|
+
totalTokens: u.total_tokens,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
// Vercel AI SDK: { inputTokens, outputTokens }
|
|
45
|
+
if (u.inputTokens != null || u.outputTokens != null) {
|
|
46
|
+
return {
|
|
47
|
+
inputTokens: u.inputTokens,
|
|
48
|
+
outputTokens: u.outputTokens,
|
|
49
|
+
totalTokens: (u.inputTokens ?? 0) + (u.outputTokens ?? 0),
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
// Gemini SDK: usageMetadata
|
|
54
|
+
if (o.usageMetadata && typeof o.usageMetadata === 'object') {
|
|
55
|
+
const u = o.usageMetadata;
|
|
56
|
+
return {
|
|
57
|
+
inputTokens: u.promptTokenCount,
|
|
58
|
+
outputTokens: u.candidatesTokenCount,
|
|
59
|
+
totalTokens: u.totalTokenCount,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
// Flat token fields (e.g. { tokens: N } or { outputTokens: N, inputTokens: N })
|
|
63
|
+
if (typeof o.tokens === 'number' || typeof o.outputTokens === 'number') {
|
|
64
|
+
return {
|
|
65
|
+
inputTokens: typeof o.inputTokens === 'number' ? o.inputTokens : undefined,
|
|
66
|
+
outputTokens: typeof o.outputTokens === 'number' ? o.outputTokens : (typeof o.tokens === 'number' ? o.tokens : undefined),
|
|
67
|
+
totalTokens: (typeof o.inputTokens === 'number' ? o.inputTokens : 0) + (typeof o.outputTokens === 'number' ? o.outputTokens : (typeof o.tokens === 'number' ? o.tokens : 0)),
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
return undefined;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* After callFn returns, consume any captured LLM request from ai-interceptor
|
|
74
|
+
* and merge it into the event input so the recorded event contains the actual
|
|
75
|
+
* HTTP payload sent to the LLM (messages, model, parameters).
|
|
76
|
+
* Also returns captured usage when the app's output doesn't include it.
|
|
77
|
+
*/
|
|
78
|
+
function enrichFromLLMCapture(input, appUsage, fallbackModel, fallbackProvider) {
|
|
79
|
+
const captured = consumeCapturedLLMRequest();
|
|
80
|
+
if (captured) {
|
|
81
|
+
const enrichedInput = (input && typeof input === 'object')
|
|
82
|
+
? { ...input, llmRequest: captured.body, promptSnippet: captured.promptSnippet }
|
|
83
|
+
: { originalInput: input, llmRequest: captured.body, promptSnippet: captured.promptSnippet };
|
|
84
|
+
const usage = appUsage ?? captured.usage;
|
|
85
|
+
return { input: enrichedInput, usage };
|
|
86
|
+
}
|
|
87
|
+
// Interceptor capture failed (e.g. OpenAI SDK uses native fetch not globalThis.fetch).
|
|
88
|
+
// Fall back to model/provider from wrapAI options or function arguments.
|
|
89
|
+
const resolvedModel = fallbackModel
|
|
90
|
+
|| (input && typeof input === 'object' ? input.model : undefined);
|
|
91
|
+
const resolvedProvider = fallbackProvider
|
|
92
|
+
|| (input && typeof input === 'object' ? input.provider : undefined);
|
|
93
|
+
if (resolvedModel || resolvedProvider) {
|
|
94
|
+
const enrichedInput = (input && typeof input === 'object')
|
|
95
|
+
? { ...input, llmRequest: { model: resolvedModel, provider: resolvedProvider } }
|
|
96
|
+
: { originalInput: input, llmRequest: { model: resolvedModel, provider: resolvedProvider } };
|
|
97
|
+
return { input: enrichedInput, usage: appUsage };
|
|
98
|
+
}
|
|
99
|
+
return { input, usage: appUsage };
|
|
100
|
+
}
|
|
101
|
+
function isReadableStream(v) {
|
|
102
|
+
return (typeof v === 'object' &&
|
|
103
|
+
v !== null &&
|
|
104
|
+
typeof v.getReader === 'function' &&
|
|
105
|
+
typeof v.tee === 'function');
|
|
106
|
+
}
|
|
107
|
+
function isAsyncIterable(v) {
|
|
108
|
+
return typeof v === 'object' && v !== null && Symbol.asyncIterator in v;
|
|
109
|
+
}
|
|
110
|
+
async function bufferReadableStream(stream) {
|
|
111
|
+
const decoder = new TextDecoder();
|
|
112
|
+
const reader = stream.getReader();
|
|
113
|
+
let raw = '';
|
|
114
|
+
try {
|
|
115
|
+
for (;;) {
|
|
116
|
+
const { done, value } = await reader.read();
|
|
117
|
+
if (done)
|
|
118
|
+
break;
|
|
119
|
+
raw += decoder.decode(value, { stream: true });
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
finally {
|
|
123
|
+
reader.releaseLock();
|
|
124
|
+
}
|
|
125
|
+
return raw;
|
|
126
|
+
}
|
|
127
|
+
function reconstructStream(raw) {
|
|
128
|
+
const encoder = new TextEncoder();
|
|
129
|
+
return new ReadableStream({
|
|
130
|
+
start(ctrl) {
|
|
131
|
+
ctrl.enqueue(encoder.encode(raw));
|
|
132
|
+
ctrl.close();
|
|
133
|
+
},
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
/** Wraps an AsyncIterable so chunks are collected while the caller iterates */
|
|
137
|
+
function wrapAsyncIterable(source, onComplete) {
|
|
138
|
+
return {
|
|
139
|
+
[Symbol.asyncIterator]() {
|
|
140
|
+
const iter = source[Symbol.asyncIterator]();
|
|
141
|
+
const collected = [];
|
|
142
|
+
return {
|
|
143
|
+
async next() {
|
|
144
|
+
const result = await iter.next();
|
|
145
|
+
if (!result.done) {
|
|
146
|
+
collected.push(result.value);
|
|
147
|
+
}
|
|
148
|
+
else {
|
|
149
|
+
onComplete(collected);
|
|
150
|
+
}
|
|
151
|
+
return result;
|
|
152
|
+
},
|
|
153
|
+
async return(value) {
|
|
154
|
+
onComplete(collected);
|
|
155
|
+
return iter.return ? iter.return(value) : { done: true, value: undefined };
|
|
156
|
+
},
|
|
157
|
+
};
|
|
158
|
+
},
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
export function wrapAI(modelName, callFn, _options) {
|
|
162
|
+
return async (...args) => {
|
|
163
|
+
// Phase 3 fixture replay: short-circuit if ed-runner replay is active
|
|
164
|
+
const edReplay = getEdReplayContext();
|
|
165
|
+
if (edReplay) {
|
|
166
|
+
const input = args.length === 1 ? args[0] : args;
|
|
167
|
+
const { output } = replayCall(edReplay, 'ai_call', modelName, input);
|
|
168
|
+
return output;
|
|
169
|
+
}
|
|
170
|
+
await tryAutoInitHttpContext();
|
|
171
|
+
const ctx = getCaptureContext();
|
|
172
|
+
const httpCtx = getHttpRunContext();
|
|
173
|
+
const obsCtx = getObservabilityContext();
|
|
174
|
+
if (!ctx && !httpCtx && !obsCtx)
|
|
175
|
+
return callFn(...args);
|
|
176
|
+
enterAIWrapper();
|
|
177
|
+
try {
|
|
178
|
+
const start = rawDateNow();
|
|
179
|
+
// Observability-only mode: record and push, no mocks/replay
|
|
180
|
+
if (!ctx && !httpCtx && obsCtx) {
|
|
181
|
+
const id = obsCtx.nextId();
|
|
182
|
+
const input = args.length === 1 ? args[0] : args;
|
|
183
|
+
try {
|
|
184
|
+
const output = await callFn(...args);
|
|
185
|
+
const enriched = enrichFromLLMCapture(input, extractUsage(output), _options?.model, _options?.provider);
|
|
186
|
+
if (isReadableStream(output)) {
|
|
187
|
+
const [streamForCaller, streamForRecorder] = output.tee();
|
|
188
|
+
bufferReadableStream(streamForRecorder).then((rawText) => {
|
|
189
|
+
const durationMs = rawDateNow() - start;
|
|
190
|
+
pushTelemetryEvent({ id, type: 'ai', name: modelName, input: enriched.input, output: null, streamed: true, streamRaw: rawText, timestamp: start, durationMs, ...(enriched.usage ? { usage: enriched.usage } : {}) });
|
|
191
|
+
}).catch(() => {
|
|
192
|
+
const durationMs = rawDateNow() - start;
|
|
193
|
+
pushTelemetryEvent({ id, type: 'ai', name: modelName, input: enriched.input, output: null, streamed: true, streamRaw: '', timestamp: start, durationMs, ...(enriched.usage ? { usage: enriched.usage } : {}) });
|
|
194
|
+
});
|
|
195
|
+
return streamForCaller;
|
|
196
|
+
}
|
|
197
|
+
if (isAsyncIterable(output)) {
|
|
198
|
+
return wrapAsyncIterable(output, (chunks) => {
|
|
199
|
+
const durationMs = rawDateNow() - start;
|
|
200
|
+
const rawText = chunks.map((c) => (typeof c === 'string' ? c : JSON.stringify(c))).join('');
|
|
201
|
+
pushTelemetryEvent({ id, type: 'ai', name: modelName, input: enriched.input, output: null, streamed: true, streamRaw: rawText, timestamp: start, durationMs, ...(enriched.usage ? { usage: enriched.usage } : {}) });
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
const durationMs = rawDateNow() - start;
|
|
205
|
+
const event = {
|
|
206
|
+
id, type: 'ai', name: modelName, input: enriched.input, output,
|
|
207
|
+
timestamp: start, durationMs,
|
|
208
|
+
...(enriched.usage ? { usage: enriched.usage } : {}),
|
|
209
|
+
};
|
|
210
|
+
pushTelemetryEvent(event);
|
|
211
|
+
return output;
|
|
212
|
+
}
|
|
213
|
+
catch (e) {
|
|
214
|
+
const enriched = enrichFromLLMCapture(input, undefined, _options?.model, _options?.provider);
|
|
215
|
+
const durationMs = rawDateNow() - start;
|
|
216
|
+
pushTelemetryEvent({
|
|
217
|
+
id, type: 'ai', name: modelName, input: enriched.input,
|
|
218
|
+
output: { error: String(e) }, timestamp: start, durationMs,
|
|
219
|
+
});
|
|
220
|
+
throw e;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
if (ctx) {
|
|
224
|
+
const { recorder, replay } = ctx;
|
|
225
|
+
const id = recorder.nextId();
|
|
226
|
+
if (replay.shouldReplay(id)) {
|
|
227
|
+
const historical = replay.getRecordedEvent(id);
|
|
228
|
+
if (historical?.streamed === true) {
|
|
229
|
+
const raw = typeof historical.streamRaw === 'string' ? historical.streamRaw : '';
|
|
230
|
+
return reconstructStream(raw);
|
|
231
|
+
}
|
|
232
|
+
return replay.getRecordedResult(id);
|
|
233
|
+
}
|
|
234
|
+
// Check AI mock (output mock — skip real call, return recorded result)
|
|
235
|
+
const aiMock = resolveAIMock(modelName);
|
|
236
|
+
if (aiMock.mocked) {
|
|
237
|
+
const input = args.length === 1 ? args[0] : args;
|
|
238
|
+
const event = {
|
|
239
|
+
id, type: 'ai', name: modelName, input,
|
|
240
|
+
output: aiMock.result, timestamp: start, durationMs: 0,
|
|
241
|
+
};
|
|
242
|
+
recorder.record(event);
|
|
243
|
+
if (httpCtx)
|
|
244
|
+
pushTelemetryEvent(event);
|
|
245
|
+
return aiMock.result;
|
|
246
|
+
}
|
|
247
|
+
// Check prompt mocks (system + user prompt replacement — call real LLM with modified prompts)
|
|
248
|
+
const rawInput = args.length === 1 ? args[0] : args;
|
|
249
|
+
const promptModifiedInput = resolvePromptMock(rawInput);
|
|
250
|
+
const userPromptModifiedInput = resolveUserPromptMock(promptModifiedInput !== undefined ? promptModifiedInput : rawInput);
|
|
251
|
+
const modifiedInput = userPromptModifiedInput !== undefined ? userPromptModifiedInput : promptModifiedInput;
|
|
252
|
+
const effectiveArgs = modifiedInput !== undefined ? [modifiedInput] : args;
|
|
253
|
+
const input = modifiedInput !== undefined ? modifiedInput : rawInput;
|
|
254
|
+
try {
|
|
255
|
+
const output = await callFn(...effectiveArgs);
|
|
256
|
+
if (isReadableStream(output)) {
|
|
257
|
+
const [streamForCaller, streamForRecorder] = output.tee();
|
|
258
|
+
bufferReadableStream(streamForRecorder).then((rawText) => {
|
|
259
|
+
const durationMs = rawDateNow() - start;
|
|
260
|
+
const event = { id, type: 'ai', name: modelName, input, output: null, streamed: true, streamRaw: rawText, timestamp: start, durationMs };
|
|
261
|
+
recorder.record(event);
|
|
262
|
+
if (httpCtx)
|
|
263
|
+
pushTelemetryEvent(event);
|
|
264
|
+
}).catch(() => {
|
|
265
|
+
const durationMs = rawDateNow() - start;
|
|
266
|
+
const event = { id, type: 'ai', name: modelName, input, output: null, streamed: true, streamRaw: '', timestamp: start, durationMs };
|
|
267
|
+
recorder.record(event);
|
|
268
|
+
if (httpCtx)
|
|
269
|
+
pushTelemetryEvent(event);
|
|
270
|
+
});
|
|
271
|
+
return streamForCaller;
|
|
272
|
+
}
|
|
273
|
+
if (isAsyncIterable(output)) {
|
|
274
|
+
return wrapAsyncIterable(output, (chunks) => {
|
|
275
|
+
const durationMs = rawDateNow() - start;
|
|
276
|
+
const rawText = chunks.map((c) => (typeof c === 'string' ? c : JSON.stringify(c))).join('');
|
|
277
|
+
const event = { id, type: 'ai', name: modelName, input, output: null, streamed: true, streamRaw: rawText, timestamp: start, durationMs };
|
|
278
|
+
recorder.record(event);
|
|
279
|
+
if (httpCtx)
|
|
280
|
+
pushTelemetryEvent(event);
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
const durationMs = rawDateNow() - start;
|
|
284
|
+
const usage = extractUsage(output);
|
|
285
|
+
const event = {
|
|
286
|
+
id, type: 'ai', name: modelName, input, output,
|
|
287
|
+
timestamp: start, durationMs,
|
|
288
|
+
...(usage ? { usage } : {}),
|
|
289
|
+
};
|
|
290
|
+
recorder.record(event);
|
|
291
|
+
if (httpCtx)
|
|
292
|
+
pushTelemetryEvent(event);
|
|
293
|
+
return output;
|
|
294
|
+
}
|
|
295
|
+
catch (e) {
|
|
296
|
+
const durationMs = rawDateNow() - start;
|
|
297
|
+
const event = {
|
|
298
|
+
id, type: 'ai', name: modelName, input,
|
|
299
|
+
output: { error: String(e) }, timestamp: start, durationMs,
|
|
300
|
+
};
|
|
301
|
+
recorder.record(event);
|
|
302
|
+
if (httpCtx)
|
|
303
|
+
pushTelemetryEvent(event);
|
|
304
|
+
throw e;
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
// HTTP mode only (no capture context)
|
|
308
|
+
const id = httpCtx.nextId();
|
|
309
|
+
// Replay frozen step: push historical event so dashboard trace stays complete
|
|
310
|
+
const frozen = getHttpFrozenEvent(id);
|
|
311
|
+
if (frozen) {
|
|
312
|
+
pushTelemetryEvent(frozen);
|
|
313
|
+
if (frozen.streamed === true) {
|
|
314
|
+
const raw = typeof frozen.streamRaw === 'string' ? frozen.streamRaw : '';
|
|
315
|
+
return reconstructStream(raw);
|
|
316
|
+
}
|
|
317
|
+
return frozen.output;
|
|
318
|
+
}
|
|
319
|
+
// Check AI output mock (skip real call, return mocked result)
|
|
320
|
+
const aiMock = getHttpAIMock(modelName);
|
|
321
|
+
if (aiMock.mocked) {
|
|
322
|
+
const input = args.length === 1 ? args[0] : args;
|
|
323
|
+
const event = {
|
|
324
|
+
id, type: 'ai', name: modelName, input,
|
|
325
|
+
output: aiMock.result, timestamp: start, durationMs: 0,
|
|
326
|
+
};
|
|
327
|
+
pushTelemetryEvent(event);
|
|
328
|
+
return aiMock.result;
|
|
329
|
+
}
|
|
330
|
+
// Check prompt mocks (system + user prompt replacement in HTTP mode)
|
|
331
|
+
const rawHttpInput = args.length === 1 ? args[0] : args;
|
|
332
|
+
const httpSystemModified = getHttpPromptMock(rawHttpInput);
|
|
333
|
+
const httpUserModified = getHttpUserPromptMock(httpSystemModified !== undefined ? httpSystemModified : rawHttpInput);
|
|
334
|
+
const httpModifiedInput = httpUserModified !== undefined ? httpUserModified : httpSystemModified;
|
|
335
|
+
const httpEffectiveArgs = httpModifiedInput !== undefined ? [httpModifiedInput] : args;
|
|
336
|
+
const input = httpModifiedInput !== undefined ? httpModifiedInput : rawHttpInput;
|
|
337
|
+
try {
|
|
338
|
+
const output = await callFn(...httpEffectiveArgs);
|
|
339
|
+
const enriched = enrichFromLLMCapture(input, extractUsage(output), _options?.model, _options?.provider);
|
|
340
|
+
if (isReadableStream(output)) {
|
|
341
|
+
const [streamForCaller, streamForRecorder] = output.tee();
|
|
342
|
+
bufferReadableStream(streamForRecorder).then((rawText) => {
|
|
343
|
+
const durationMs = rawDateNow() - start;
|
|
344
|
+
pushTelemetryEvent({ id, type: 'ai', name: modelName, input: enriched.input, output: null, streamed: true, streamRaw: rawText, timestamp: start, durationMs, ...(enriched.usage ? { usage: enriched.usage } : {}) });
|
|
345
|
+
}).catch(() => {
|
|
346
|
+
const durationMs = rawDateNow() - start;
|
|
347
|
+
pushTelemetryEvent({ id, type: 'ai', name: modelName, input: enriched.input, output: null, streamed: true, streamRaw: '', timestamp: start, durationMs, ...(enriched.usage ? { usage: enriched.usage } : {}) });
|
|
348
|
+
});
|
|
349
|
+
return streamForCaller;
|
|
350
|
+
}
|
|
351
|
+
if (isAsyncIterable(output)) {
|
|
352
|
+
return wrapAsyncIterable(output, (chunks) => {
|
|
353
|
+
const durationMs = rawDateNow() - start;
|
|
354
|
+
const rawText = chunks.map((c) => (typeof c === 'string' ? c : JSON.stringify(c))).join('');
|
|
355
|
+
pushTelemetryEvent({ id, type: 'ai', name: modelName, input: enriched.input, output: null, streamed: true, streamRaw: rawText, timestamp: start, durationMs, ...(enriched.usage ? { usage: enriched.usage } : {}) });
|
|
356
|
+
});
|
|
357
|
+
}
|
|
358
|
+
const durationMs = rawDateNow() - start;
|
|
359
|
+
const event = {
|
|
360
|
+
id, type: 'ai', name: modelName, input: enriched.input, output,
|
|
361
|
+
timestamp: start, durationMs,
|
|
362
|
+
...(enriched.usage ? { usage: enriched.usage } : {}),
|
|
363
|
+
};
|
|
364
|
+
pushTelemetryEvent(event);
|
|
365
|
+
return output;
|
|
366
|
+
}
|
|
367
|
+
catch (e) {
|
|
368
|
+
const enriched = enrichFromLLMCapture(input, undefined, _options?.model, _options?.provider);
|
|
369
|
+
const durationMs = rawDateNow() - start;
|
|
370
|
+
pushTelemetryEvent({
|
|
371
|
+
id, type: 'ai', name: modelName, input: enriched.input,
|
|
372
|
+
output: { error: String(e) }, timestamp: start, durationMs,
|
|
373
|
+
});
|
|
374
|
+
throw e;
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
finally {
|
|
378
|
+
leaveAIWrapper();
|
|
379
|
+
}
|
|
380
|
+
};
|
|
381
|
+
}
|
|
382
|
+
//# sourceMappingURL=workflow-ai.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workflow-ai.js","sourceRoot":"","sources":["../../src/interceptors/workflow-ai.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAC1D,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAC9C,OAAO,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,qBAAqB,EAAE,aAAa,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,uBAAuB,EAAE,MAAM,qBAAqB,CAAA;AACzM,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAA;AACvG,OAAO,EAAE,yBAAyB,EAAE,MAAM,qBAAqB,CAAA;AAC/D,OAAO,EAAE,kBAAkB,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAGhE;;;;GAIG;AACH,MAAM,cAAc,G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CAAA;gBACD,kBAAkB,CAAC,KAAK,CAAC,CAAA;gBACzB,OAAO,MAAM,CAAA;YACf,CAAC;YAAC,OAAO,CAAC,EAAE,CAAC;gBACX,MAAM,QAAQ,GAAG,oBAAoB,CAAC,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,KAAK,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAA;gBAC5F,MAAM,UAAU,GAAG,UAAU,EAAE,GAAG,KAAK,CAAA;gBACvC,kBAAkB,CAAC;oBACjB,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,QAAQ,CAAC,KAAK;oBACtD,MAAM,EAAE,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,SAAS,EAAE,KAAK,EAAE,UAAU;iBAC3D,CAAC,CAAA;gBACF,MAAM,CAAC,CAAA;YACT,CAAC;QACD,CAAC;gBAAS,CAAC;YACT,cAAc,EAAE,CAAA;QAClB,CAAC;IACH,CAAC,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Conditional recorder utility for worker contexts
|
|
3
|
+
*
|
|
4
|
+
* This module provides a safe wrapper around recordToolCall that only executes
|
|
5
|
+
* in worker environments. In non-worker contexts, it's a no-op to avoid unnecessary
|
|
6
|
+
* imports and function calls.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Safely record a tool call only if in worker context
|
|
10
|
+
*
|
|
11
|
+
* @param name - Name of the tool/function
|
|
12
|
+
* @param input - Input parameters to the tool
|
|
13
|
+
* @param output - Output/result from the tool
|
|
14
|
+
*/
|
|
15
|
+
export declare const safeRecordToolCall: (name: string, input: any, output: any) => Promise<void>;
|
|
16
|
+
/**
|
|
17
|
+
* Synchronous version - checks if we're in worker context without importing
|
|
18
|
+
* Use this if you want to avoid async/await in your tool functions
|
|
19
|
+
*/
|
|
20
|
+
export declare const isWorker: () => boolean;
|
|
21
|
+
//# sourceMappingURL=conditional-recorder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"conditional-recorder.d.ts","sourceRoot":"","sources":["../../src/internals/conditional-recorder.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAgCH;;;;;;GAMG;AACH,eAAO,MAAM,kBAAkB,GAC7B,MAAM,MAAM,EACZ,OAAO,GAAG,EACV,QAAQ,GAAG,KACV,OAAO,CAAC,IAAI,CAKd,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,QAAQ,QAAO,OAE3B,CAAC"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Conditional recorder utility for worker contexts
|
|
3
|
+
*
|
|
4
|
+
* This module provides a safe wrapper around recordToolCall that only executes
|
|
5
|
+
* in worker environments. In non-worker contexts, it's a no-op to avoid unnecessary
|
|
6
|
+
* imports and function calls.
|
|
7
|
+
*/
|
|
8
|
+
// Check if running in an Elasticdash worker context
|
|
9
|
+
const isWorkerContext = () => {
|
|
10
|
+
if (typeof globalThis === 'undefined') {
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
return globalThis.__ELASTICDASH_WORKER__ === true;
|
|
14
|
+
};
|
|
15
|
+
let recordToolCallFn = null;
|
|
16
|
+
// Lazy load recordToolCall only if in worker context
|
|
17
|
+
const getRecordToolCall = async () => {
|
|
18
|
+
if (!isWorkerContext()) {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
if (recordToolCallFn !== null) {
|
|
22
|
+
return recordToolCallFn;
|
|
23
|
+
}
|
|
24
|
+
try {
|
|
25
|
+
const { recordToolCall } = await import('../tracing.js');
|
|
26
|
+
recordToolCallFn = recordToolCall;
|
|
27
|
+
return recordToolCallFn;
|
|
28
|
+
}
|
|
29
|
+
catch (err) {
|
|
30
|
+
console.warn('Failed to load recordToolCall from tracing module:', err);
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Safely record a tool call only if in worker context
|
|
36
|
+
*
|
|
37
|
+
* @param name - Name of the tool/function
|
|
38
|
+
* @param input - Input parameters to the tool
|
|
39
|
+
* @param output - Output/result from the tool
|
|
40
|
+
*/
|
|
41
|
+
export const safeRecordToolCall = async (name, input, output) => {
|
|
42
|
+
const recorder = await getRecordToolCall();
|
|
43
|
+
if (recorder) {
|
|
44
|
+
recorder(name, input, output);
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* Synchronous version - checks if we're in worker context without importing
|
|
49
|
+
* Use this if you want to avoid async/await in your tool functions
|
|
50
|
+
*/
|
|
51
|
+
export const isWorker = () => {
|
|
52
|
+
return isWorkerContext();
|
|
53
|
+
};
|
|
54
|
+
//# sourceMappingURL=conditional-recorder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"conditional-recorder.js","sourceRoot":"","sources":["../../src/internals/conditional-recorder.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,oDAAoD;AACpD,MAAM,eAAe,GAAG,GAAY,EAAE;IACpC,IAAI,OAAO,UAAU,KAAK,WAAW,EAAE,CAAC;QACtC,OAAO,KAAK,CAAC;IACf,CAAC;IACD,OAAQ,UAAkB,CAAC,sBAAsB,KAAK,IAAI,CAAC;AAC7D,CAAC,CAAC;AAEF,IAAI,gBAAgB,GAA6D,IAAI,CAAC;AAEtF,qDAAqD;AACrD,MAAM,iBAAiB,GAAG,KAAK,IAAuE,EAAE;IACtG,IAAI,CAAC,eAAe,EAAE,EAAE,CAAC;QACvB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,IAAI,gBAAgB,KAAK,IAAI,EAAE,CAAC;QAC9B,OAAO,gBAAgB,CAAC;IAC1B,CAAC;IAED,IAAI,CAAC;QACH,MAAM,EAAE,cAAc,EAAE,GAAG,MAAM,MAAM,CAAC,eAAe,CAAC,CAAC;QACzD,gBAAgB,GAAG,cAAc,CAAC;QAClC,OAAO,gBAAgB,CAAC;IAC1B,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,OAAO,CAAC,IAAI,CAAC,oDAAoD,EAAE,GAAG,CAAC,CAAC;QACxE,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,KAAK,EACrC,IAAY,EACZ,KAAU,EACV,MAAW,EACI,EAAE;IACjB,MAAM,QAAQ,GAAG,MAAM,iBAAiB,EAAE,CAAC;IAC3C,IAAI,QAAQ,EAAE,CAAC;QACb,QAAQ,CAAC,IAAI,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;IAChC,CAAC;AACH,CAAC,CAAC;AAEF;;;GAGG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,GAAY,EAAE;IACpC,OAAO,eAAe,EAAE,CAAC;AAC3B,CAAC,CAAC"}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runtime mock resolution for module-imported tools and AI calls.
|
|
3
|
+
*
|
|
4
|
+
* Tools/AI calls that are statically imported (not accessed via globalThis)
|
|
5
|
+
* cannot be intercepted by the worker's proxy-based mocking. Instead, each
|
|
6
|
+
* wrapped function calls `resolveMock` / `resolveAIMock` at its entry point.
|
|
7
|
+
* The worker writes the mock config to `__ELASTICDASH_TOOL_MOCKS__` /
|
|
8
|
+
* `__ELASTICDASH_AI_MOCKS__` before the workflow runs and clears it after.
|
|
9
|
+
*/
|
|
10
|
+
/** Per-model AI mock configuration (mirrors ToolMockConfig) */
|
|
11
|
+
export interface AIMockEntry {
|
|
12
|
+
mode: 'live' | 'mock-all' | 'mock-specific';
|
|
13
|
+
callIndices?: number[];
|
|
14
|
+
mockData?: Record<number, unknown>;
|
|
15
|
+
}
|
|
16
|
+
export interface AIMockConfig {
|
|
17
|
+
[modelName: string]: AIMockEntry;
|
|
18
|
+
}
|
|
19
|
+
type MockResult = {
|
|
20
|
+
mocked: true;
|
|
21
|
+
result: unknown;
|
|
22
|
+
} | {
|
|
23
|
+
mocked: false;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Recursively normalises a mock result fetched from the trace.
|
|
27
|
+
*
|
|
28
|
+
* The trace recorder stores tool outputs as-is. When a tool returns a JSON
|
|
29
|
+
* string (rather than a parsed object), the stored value is that string, and
|
|
30
|
+
* inner string values may themselves be JSON-quoted. This function unwraps
|
|
31
|
+
* every layer so the calling code receives the same shape as the real output.
|
|
32
|
+
*
|
|
33
|
+
* - string → try JSON.parse, then recurse on the result
|
|
34
|
+
* - array → recurse on every element
|
|
35
|
+
* - object → recurse on every value
|
|
36
|
+
* - other → return unchanged
|
|
37
|
+
*/
|
|
38
|
+
export declare function normaliseMockResult(value: unknown): unknown;
|
|
39
|
+
/**
|
|
40
|
+
* Resolves whether the current call to `toolName` should be mocked.
|
|
41
|
+
*
|
|
42
|
+
* - Returns `{ mocked: false }` when no mock config is active or mode is `'live'`.
|
|
43
|
+
* - Increments the per-tool call counter on every non-live invocation so that
|
|
44
|
+
* `mock-specific` indices remain accurate even when some calls run live.
|
|
45
|
+
* - Safe to call in production: no-op when the mock globals are absent.
|
|
46
|
+
*/
|
|
47
|
+
export declare function resolveMock(toolName: string): MockResult;
|
|
48
|
+
/**
|
|
49
|
+
* Extracts the system prompt string from an LLM call input.
|
|
50
|
+
* Handles:
|
|
51
|
+
* - Anthropic style: `{ system: "...", messages: [...] }`
|
|
52
|
+
* - OpenAI style: `{ messages: [{ role: "system", content: "..." }, ...] }`
|
|
53
|
+
* - Plain message array: `[{ role: "system", content: "..." }, ...]`
|
|
54
|
+
* - Separate field: `{ systemPrompt: "...", messages: [...] }` (custom wrapAI callers)
|
|
55
|
+
*/
|
|
56
|
+
export declare function extractSystemPrompt(input: unknown): string | undefined;
|
|
57
|
+
/**
|
|
58
|
+
* Returns a shallow copy of `input` with the system prompt replaced by `newSystemPrompt`.
|
|
59
|
+
*/
|
|
60
|
+
export declare function replaceSystemPrompt(input: unknown, newSystemPrompt: string): unknown;
|
|
61
|
+
/**
|
|
62
|
+
* System prompt mock entry — mirrors user prompt mock entry.
|
|
63
|
+
*/
|
|
64
|
+
export interface SystemPromptMockEntry {
|
|
65
|
+
mode: 'live' | 'replace-all' | 'replace-specific';
|
|
66
|
+
replacement: string;
|
|
67
|
+
callIndices?: number[];
|
|
68
|
+
}
|
|
69
|
+
export interface SystemPromptMockConfig {
|
|
70
|
+
[originalText: string]: SystemPromptMockEntry;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* If a prompt mock is configured for the system prompt found in `input`, returns
|
|
74
|
+
* a copy of `input` with the system prompt replaced. Otherwise returns `undefined`.
|
|
75
|
+
*
|
|
76
|
+
* `__ELASTICDASH_PROMPT_MOCKS__` is `Record<string, SystemPromptMockEntry>` keyed by
|
|
77
|
+
* the original system prompt text. Supports replace-all and replace-specific modes
|
|
78
|
+
* with per-text call counting.
|
|
79
|
+
*
|
|
80
|
+
* For backward compatibility, also accepts the legacy `Record<string, string>` format
|
|
81
|
+
* (treated as replace-all).
|
|
82
|
+
*/
|
|
83
|
+
export declare function resolvePromptMock(input: unknown): unknown | undefined;
|
|
84
|
+
/**
|
|
85
|
+
* Look up a mock entry by key, falling back to stripped-quotes variants
|
|
86
|
+
* to handle mismatches between trace-recorded text and runtime text.
|
|
87
|
+
*/
|
|
88
|
+
export declare function lookupMockEntry<T>(mocks: Record<string, T>, text: string): {
|
|
89
|
+
key: string;
|
|
90
|
+
entry: T;
|
|
91
|
+
} | undefined;
|
|
92
|
+
/**
|
|
93
|
+
* Extracts all user-role message content strings from an LLM call input.
|
|
94
|
+
* Handles OpenAI-style `{ messages: [...] }` and plain message arrays.
|
|
95
|
+
*/
|
|
96
|
+
export declare function extractUserPrompts(input: unknown): string[];
|
|
97
|
+
/**
|
|
98
|
+
* Returns a shallow copy of `input` with all user-role messages whose content
|
|
99
|
+
* matches `originalText` replaced with `newText`.
|
|
100
|
+
*/
|
|
101
|
+
export declare function replaceUserPrompt(input: unknown, originalText: string, newText: string): unknown;
|
|
102
|
+
/**
|
|
103
|
+
* User prompt mock entry — mirrors tool mock but for user-role messages.
|
|
104
|
+
*/
|
|
105
|
+
export interface UserPromptMockEntry {
|
|
106
|
+
mode: 'live' | 'replace-all' | 'replace-specific';
|
|
107
|
+
replacement: string;
|
|
108
|
+
callIndices?: number[];
|
|
109
|
+
}
|
|
110
|
+
export interface UserPromptMockConfig {
|
|
111
|
+
[originalText: string]: UserPromptMockEntry;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* If user prompt mocks are configured, applies all matching replacements to `input`.
|
|
115
|
+
* Returns modified input or `undefined` if no replacements applied.
|
|
116
|
+
*
|
|
117
|
+
* `__ELASTICDASH_USER_PROMPT_MOCKS__` is `Record<string, UserPromptMockEntry>` keyed
|
|
118
|
+
* by original user message text.
|
|
119
|
+
*
|
|
120
|
+
* Call counting is per unique text — "the x-th LLM call where this text appears".
|
|
121
|
+
*/
|
|
122
|
+
export declare function resolveUserPromptMock(input: unknown): unknown | undefined;
|
|
123
|
+
/**
|
|
124
|
+
* Resolves whether the current call to `modelName` should be mocked.
|
|
125
|
+
* Mirrors `resolveMock` but reads `__ELASTICDASH_AI_MOCKS__` and
|
|
126
|
+
* `__ELASTICDASH_AI_CALL_COUNTERS__`.
|
|
127
|
+
*/
|
|
128
|
+
/**
|
|
129
|
+
* Standalone utility: applies all matching user prompt mock replacements to
|
|
130
|
+
* a messages array (or LLM input object). Works without ALS — takes the mock
|
|
131
|
+
* config and call counters as explicit parameters.
|
|
132
|
+
*
|
|
133
|
+
* Returns the modified input, or the original input unchanged if no mocks matched.
|
|
134
|
+
*/
|
|
135
|
+
export declare function applyUserPromptMocks(input: unknown, userPromptMocks: Record<string, UserPromptMockEntry>, callCounters?: Record<string, number>): unknown;
|
|
136
|
+
/**
|
|
137
|
+
* Standalone utility: applies system prompt mock replacement to an LLM input
|
|
138
|
+
* object. Works without ALS — takes the mock config and call counters as
|
|
139
|
+
* explicit parameters.
|
|
140
|
+
*
|
|
141
|
+
* Returns the modified input, or the original input unchanged if no mock matched.
|
|
142
|
+
*/
|
|
143
|
+
export declare function applySystemPromptMocks(input: unknown, promptMocks: Record<string, string | SystemPromptMockEntry>, callCounters?: Record<string, number>): unknown;
|
|
144
|
+
export declare function resolveAIMock(modelName: string): MockResult;
|
|
145
|
+
export {};
|
|
146
|
+
//# sourceMappingURL=mock-resolver.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mock-resolver.d.ts","sourceRoot":"","sources":["../../src/internals/mock-resolver.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAQH,+DAA+D;AAC/D,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,GAAG,UAAU,GAAG,eAAe,CAAA;IAC3C,WAAW,CAAC,EAAE,MAAM,EAAE,CAAA;IACtB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CACnC;AAED,MAAM,WAAW,YAAY;IAC3B,CAAC,SAAS,EAAE,MAAM,GAAG,WAAW,CAAA;CACjC;AAED,KAAK,UAAU,GACX;IAAE,MAAM,EAAE,IAAI,CAAC;IAAC,MAAM,EAAE,OAAO,CAAA;CAAE,GACjC;IAAE,MAAM,EAAE,KAAK,CAAA;CAAE,CAAA;AAErB;;;;;;;;;;;;GAYG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAe3D;AAED;;;;;;;GAOG;AACH,wBAAgB,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,UAAU,CAkCxD;AAED;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAetE;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,OAAO,EAAE,eAAe,EAAE,MAAM,GAAG,OAAO,CA2BpF;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