@chanl/scenarios-core 0.4.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/dist/__tests__/e2e/test-helpers.d.ts +79 -0
- package/dist/__tests__/e2e/test-helpers.d.ts.map +1 -0
- package/dist/__tests__/e2e/test-helpers.js +162 -0
- package/dist/__tests__/e2e/test-helpers.js.map +1 -0
- package/dist/adapters/adapter-registry.d.ts +14 -0
- package/dist/adapters/adapter-registry.d.ts.map +1 -0
- package/dist/adapters/adapter-registry.js +53 -0
- package/dist/adapters/adapter-registry.js.map +1 -0
- package/dist/adapters/agent-adapter.interface.d.ts +70 -0
- package/dist/adapters/agent-adapter.interface.d.ts.map +1 -0
- package/dist/adapters/agent-adapter.interface.js +3 -0
- package/dist/adapters/agent-adapter.interface.js.map +1 -0
- package/dist/adapters/anthropic.adapter.d.ts +17 -0
- package/dist/adapters/anthropic.adapter.d.ts.map +1 -0
- package/dist/adapters/anthropic.adapter.js +145 -0
- package/dist/adapters/anthropic.adapter.js.map +1 -0
- package/dist/adapters/http.adapter.d.ts +17 -0
- package/dist/adapters/http.adapter.d.ts.map +1 -0
- package/dist/adapters/http.adapter.js +95 -0
- package/dist/adapters/http.adapter.js.map +1 -0
- package/dist/adapters/index.d.ts +6 -0
- package/dist/adapters/index.d.ts.map +1 -0
- package/dist/adapters/index.js +22 -0
- package/dist/adapters/index.js.map +1 -0
- package/dist/adapters/openai.adapter.d.ts +17 -0
- package/dist/adapters/openai.adapter.d.ts.map +1 -0
- package/dist/adapters/openai.adapter.js +133 -0
- package/dist/adapters/openai.adapter.js.map +1 -0
- package/dist/dataset/convert.d.ts +28 -0
- package/dist/dataset/convert.d.ts.map +1 -0
- package/dist/dataset/convert.js +94 -0
- package/dist/dataset/convert.js.map +1 -0
- package/dist/dataset/formats/dpo.d.ts +41 -0
- package/dist/dataset/formats/dpo.d.ts.map +1 -0
- package/dist/dataset/formats/dpo.js +79 -0
- package/dist/dataset/formats/dpo.js.map +1 -0
- package/dist/dataset/formats/index.d.ts +4 -0
- package/dist/dataset/formats/index.d.ts.map +1 -0
- package/dist/dataset/formats/index.js +13 -0
- package/dist/dataset/formats/index.js.map +1 -0
- package/dist/dataset/formats/openai.d.ts +29 -0
- package/dist/dataset/formats/openai.d.ts.map +1 -0
- package/dist/dataset/formats/openai.js +98 -0
- package/dist/dataset/formats/openai.js.map +1 -0
- package/dist/dataset/formats/sharegpt.d.ts +31 -0
- package/dist/dataset/formats/sharegpt.d.ts.map +1 -0
- package/dist/dataset/formats/sharegpt.js +76 -0
- package/dist/dataset/formats/sharegpt.js.map +1 -0
- package/dist/dataset/index.d.ts +4 -0
- package/dist/dataset/index.d.ts.map +1 -0
- package/dist/dataset/index.js +20 -0
- package/dist/dataset/index.js.map +1 -0
- package/dist/dataset/types.d.ts +108 -0
- package/dist/dataset/types.d.ts.map +1 -0
- package/dist/dataset/types.js +7 -0
- package/dist/dataset/types.js.map +1 -0
- package/dist/execution/agent-config-resolver.d.ts +44 -0
- package/dist/execution/agent-config-resolver.d.ts.map +1 -0
- package/dist/execution/agent-config-resolver.js +76 -0
- package/dist/execution/agent-config-resolver.js.map +1 -0
- package/dist/execution/execution-processor.d.ts +75 -0
- package/dist/execution/execution-processor.d.ts.map +1 -0
- package/dist/execution/execution-processor.js +569 -0
- package/dist/execution/execution-processor.js.map +1 -0
- package/dist/execution/execution.module.d.ts +3 -0
- package/dist/execution/execution.module.d.ts.map +1 -0
- package/dist/execution/execution.module.js +56 -0
- package/dist/execution/execution.module.js.map +1 -0
- package/dist/execution/execution.service.d.ts +52 -0
- package/dist/execution/execution.service.d.ts.map +1 -0
- package/dist/execution/execution.service.js +182 -0
- package/dist/execution/execution.service.js.map +1 -0
- package/dist/execution/index.d.ts +11 -0
- package/dist/execution/index.d.ts.map +1 -0
- package/dist/execution/index.js +30 -0
- package/dist/execution/index.js.map +1 -0
- package/dist/execution/interfaces/job-data.interface.d.ts +38 -0
- package/dist/execution/interfaces/job-data.interface.d.ts.map +1 -0
- package/dist/execution/interfaces/job-data.interface.js +3 -0
- package/dist/execution/interfaces/job-data.interface.js.map +1 -0
- package/dist/execution/judge-llm.d.ts +35 -0
- package/dist/execution/judge-llm.d.ts.map +1 -0
- package/dist/execution/judge-llm.js +129 -0
- package/dist/execution/judge-llm.js.map +1 -0
- package/dist/execution/llm-config-resolver.d.ts +26 -0
- package/dist/execution/llm-config-resolver.d.ts.map +1 -0
- package/dist/execution/llm-config-resolver.js +99 -0
- package/dist/execution/llm-config-resolver.js.map +1 -0
- package/dist/execution/persona-llm.d.ts +29 -0
- package/dist/execution/persona-llm.d.ts.map +1 -0
- package/dist/execution/persona-llm.js +98 -0
- package/dist/execution/persona-llm.js.map +1 -0
- package/dist/execution/persona-strategy-registry.d.ts +14 -0
- package/dist/execution/persona-strategy-registry.d.ts.map +1 -0
- package/dist/execution/persona-strategy-registry.js +51 -0
- package/dist/execution/persona-strategy-registry.js.map +1 -0
- package/dist/execution/persona-strategy.interface.d.ts +88 -0
- package/dist/execution/persona-strategy.interface.d.ts.map +1 -0
- package/dist/execution/persona-strategy.interface.js +3 -0
- package/dist/execution/persona-strategy.interface.js.map +1 -0
- package/dist/execution/queue-producer.service.d.ts +21 -0
- package/dist/execution/queue-producer.service.d.ts.map +1 -0
- package/dist/execution/queue-producer.service.js +60 -0
- package/dist/execution/queue-producer.service.js.map +1 -0
- package/dist/execution/queues.config.d.ts +39 -0
- package/dist/execution/queues.config.d.ts.map +1 -0
- package/dist/execution/queues.config.js +43 -0
- package/dist/execution/queues.config.js.map +1 -0
- package/dist/execution/strategies/default.strategy.d.ts +11 -0
- package/dist/execution/strategies/default.strategy.d.ts.map +1 -0
- package/dist/execution/strategies/default.strategy.js +31 -0
- package/dist/execution/strategies/default.strategy.js.map +1 -0
- package/dist/execution/strategies/reactive.strategy.d.ts +28 -0
- package/dist/execution/strategies/reactive.strategy.d.ts.map +1 -0
- package/dist/execution/strategies/reactive.strategy.js +220 -0
- package/dist/execution/strategies/reactive.strategy.js.map +1 -0
- package/dist/execution/template-renderer.d.ts +52 -0
- package/dist/execution/template-renderer.d.ts.map +1 -0
- package/dist/execution/template-renderer.js +90 -0
- package/dist/execution/template-renderer.js.map +1 -0
- package/dist/generation/index.d.ts +2 -0
- package/dist/generation/index.d.ts.map +1 -0
- package/dist/generation/index.js +6 -0
- package/dist/generation/index.js.map +1 -0
- package/dist/generation/scenario-generator.service.d.ts +77 -0
- package/dist/generation/scenario-generator.service.d.ts.map +1 -0
- package/dist/generation/scenario-generator.service.js +272 -0
- package/dist/generation/scenario-generator.service.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +27 -0
- package/dist/index.js.map +1 -0
- package/dist/personas/dto/create-persona.dto.d.ts +61 -0
- package/dist/personas/dto/create-persona.dto.d.ts.map +1 -0
- package/dist/personas/dto/create-persona.dto.js +146 -0
- package/dist/personas/dto/create-persona.dto.js.map +1 -0
- package/dist/personas/dto/index.d.ts +3 -0
- package/dist/personas/dto/index.d.ts.map +1 -0
- package/dist/personas/dto/index.js +19 -0
- package/dist/personas/dto/index.js.map +1 -0
- package/dist/personas/dto/update-persona.dto.d.ts +8 -0
- package/dist/personas/dto/update-persona.dto.d.ts.map +1 -0
- package/dist/personas/dto/update-persona.dto.js +29 -0
- package/dist/personas/dto/update-persona.dto.js.map +1 -0
- package/dist/personas/index.d.ts +6 -0
- package/dist/personas/index.d.ts.map +1 -0
- package/dist/personas/index.js +22 -0
- package/dist/personas/index.js.map +1 -0
- package/dist/personas/persona.controller.d.ts +69 -0
- package/dist/personas/persona.controller.d.ts.map +1 -0
- package/dist/personas/persona.controller.js +282 -0
- package/dist/personas/persona.controller.js.map +1 -0
- package/dist/personas/persona.module.d.ts +3 -0
- package/dist/personas/persona.module.d.ts.map +1 -0
- package/dist/personas/persona.module.js +28 -0
- package/dist/personas/persona.module.js.map +1 -0
- package/dist/personas/persona.service.d.ts +85 -0
- package/dist/personas/persona.service.d.ts.map +1 -0
- package/dist/personas/persona.service.js +382 -0
- package/dist/personas/persona.service.js.map +1 -0
- package/dist/personas/schemas/persona.schema.d.ts +90 -0
- package/dist/personas/schemas/persona.schema.d.ts.map +1 -0
- package/dist/personas/schemas/persona.schema.js +321 -0
- package/dist/personas/schemas/persona.schema.js.map +1 -0
- package/dist/scenarios/controllers/scenario-execution.controller.d.ts +48 -0
- package/dist/scenarios/controllers/scenario-execution.controller.d.ts.map +1 -0
- package/dist/scenarios/controllers/scenario-execution.controller.js +260 -0
- package/dist/scenarios/controllers/scenario-execution.controller.js.map +1 -0
- package/dist/scenarios/controllers/scenario.controller.d.ts +81 -0
- package/dist/scenarios/controllers/scenario.controller.d.ts.map +1 -0
- package/dist/scenarios/controllers/scenario.controller.js +345 -0
- package/dist/scenarios/controllers/scenario.controller.js.map +1 -0
- package/dist/scenarios/dto/create-scenario.dto.d.ts +31 -0
- package/dist/scenarios/dto/create-scenario.dto.d.ts.map +1 -0
- package/dist/scenarios/dto/create-scenario.dto.js +102 -0
- package/dist/scenarios/dto/create-scenario.dto.js.map +1 -0
- package/dist/scenarios/dto/execute-scenario.dto.d.ts +34 -0
- package/dist/scenarios/dto/execute-scenario.dto.d.ts.map +1 -0
- package/dist/scenarios/dto/execute-scenario.dto.js +150 -0
- package/dist/scenarios/dto/execute-scenario.dto.js.map +1 -0
- package/dist/scenarios/dto/index.d.ts +4 -0
- package/dist/scenarios/dto/index.d.ts.map +1 -0
- package/dist/scenarios/dto/index.js +20 -0
- package/dist/scenarios/dto/index.js.map +1 -0
- package/dist/scenarios/dto/update-scenario.dto.d.ts +6 -0
- package/dist/scenarios/dto/update-scenario.dto.d.ts.map +1 -0
- package/dist/scenarios/dto/update-scenario.dto.js +9 -0
- package/dist/scenarios/dto/update-scenario.dto.js.map +1 -0
- package/dist/scenarios/index.d.ts +9 -0
- package/dist/scenarios/index.d.ts.map +1 -0
- package/dist/scenarios/index.js +25 -0
- package/dist/scenarios/index.js.map +1 -0
- package/dist/scenarios/scenario.module.d.ts +3 -0
- package/dist/scenarios/scenario.module.d.ts.map +1 -0
- package/dist/scenarios/scenario.module.js +42 -0
- package/dist/scenarios/scenario.module.js.map +1 -0
- package/dist/scenarios/schemas/scenario-execution.schema.d.ts +133 -0
- package/dist/scenarios/schemas/scenario-execution.schema.d.ts.map +1 -0
- package/dist/scenarios/schemas/scenario-execution.schema.js +292 -0
- package/dist/scenarios/schemas/scenario-execution.schema.js.map +1 -0
- package/dist/scenarios/schemas/scenario.schema.d.ts +106 -0
- package/dist/scenarios/schemas/scenario.schema.d.ts.map +1 -0
- package/dist/scenarios/schemas/scenario.schema.js +205 -0
- package/dist/scenarios/schemas/scenario.schema.js.map +1 -0
- package/dist/scenarios/services/scenario-execution.service.d.ts +73 -0
- package/dist/scenarios/services/scenario-execution.service.d.ts.map +1 -0
- package/dist/scenarios/services/scenario-execution.service.js +505 -0
- package/dist/scenarios/services/scenario-execution.service.js.map +1 -0
- package/dist/scenarios/services/scenario.service.d.ts +110 -0
- package/dist/scenarios/services/scenario.service.d.ts.map +1 -0
- package/dist/scenarios/services/scenario.service.js +608 -0
- package/dist/scenarios/services/scenario.service.js.map +1 -0
- package/dist/simulator/index.d.ts +2 -0
- package/dist/simulator/index.d.ts.map +1 -0
- package/dist/simulator/index.js +18 -0
- package/dist/simulator/index.js.map +1 -0
- package/dist/simulator/persona-simulator.service.d.ts +81 -0
- package/dist/simulator/persona-simulator.service.d.ts.map +1 -0
- package/dist/simulator/persona-simulator.service.js +358 -0
- package/dist/simulator/persona-simulator.service.js.map +1 -0
- package/dist/templates/dto/create-template.dto.d.ts +16 -0
- package/dist/templates/dto/create-template.dto.d.ts.map +1 -0
- package/dist/templates/dto/create-template.dto.js +75 -0
- package/dist/templates/dto/create-template.dto.js.map +1 -0
- package/dist/templates/dto/index.d.ts +4 -0
- package/dist/templates/dto/index.d.ts.map +1 -0
- package/dist/templates/dto/index.js +10 -0
- package/dist/templates/dto/index.js.map +1 -0
- package/dist/templates/dto/instantiate-template.dto.d.ts +7 -0
- package/dist/templates/dto/instantiate-template.dto.d.ts.map +1 -0
- package/dist/templates/dto/instantiate-template.dto.js +38 -0
- package/dist/templates/dto/instantiate-template.dto.js.map +1 -0
- package/dist/templates/dto/update-template.dto.d.ts +6 -0
- package/dist/templates/dto/update-template.dto.d.ts.map +1 -0
- package/dist/templates/dto/update-template.dto.js +9 -0
- package/dist/templates/dto/update-template.dto.js.map +1 -0
- package/dist/templates/index.d.ts +6 -0
- package/dist/templates/index.d.ts.map +1 -0
- package/dist/templates/index.js +22 -0
- package/dist/templates/index.js.map +1 -0
- package/dist/templates/scenario-template.controller.d.ts +42 -0
- package/dist/templates/scenario-template.controller.d.ts.map +1 -0
- package/dist/templates/scenario-template.controller.js +148 -0
- package/dist/templates/scenario-template.controller.js.map +1 -0
- package/dist/templates/scenario-template.module.d.ts +3 -0
- package/dist/templates/scenario-template.module.d.ts.map +1 -0
- package/dist/templates/scenario-template.module.js +30 -0
- package/dist/templates/scenario-template.module.js.map +1 -0
- package/dist/templates/scenario-template.service.d.ts +50 -0
- package/dist/templates/scenario-template.service.d.ts.map +1 -0
- package/dist/templates/scenario-template.service.js +497 -0
- package/dist/templates/scenario-template.service.js.map +1 -0
- package/dist/templates/schemas/scenario-template.schema.d.ts +59 -0
- package/dist/templates/schemas/scenario-template.schema.d.ts.map +1 -0
- package/dist/templates/schemas/scenario-template.schema.js +132 -0
- package/dist/templates/schemas/scenario-template.schema.js.map +1 -0
- package/dist/tool-fixtures/dto/create-tool-fixture.dto.d.ts +18 -0
- package/dist/tool-fixtures/dto/create-tool-fixture.dto.d.ts.map +1 -0
- package/dist/tool-fixtures/dto/create-tool-fixture.dto.js +46 -0
- package/dist/tool-fixtures/dto/create-tool-fixture.dto.js.map +1 -0
- package/dist/tool-fixtures/dto/index.d.ts +4 -0
- package/dist/tool-fixtures/dto/index.d.ts.map +1 -0
- package/dist/tool-fixtures/dto/index.js +20 -0
- package/dist/tool-fixtures/dto/index.js.map +1 -0
- package/dist/tool-fixtures/dto/tool-fixture-filter.dto.d.ts +6 -0
- package/dist/tool-fixtures/dto/tool-fixture-filter.dto.d.ts.map +1 -0
- package/dist/tool-fixtures/dto/tool-fixture-filter.dto.js +33 -0
- package/dist/tool-fixtures/dto/tool-fixture-filter.dto.js.map +1 -0
- package/dist/tool-fixtures/dto/update-tool-fixture.dto.d.ts +6 -0
- package/dist/tool-fixtures/dto/update-tool-fixture.dto.d.ts.map +1 -0
- package/dist/tool-fixtures/dto/update-tool-fixture.dto.js +9 -0
- package/dist/tool-fixtures/dto/update-tool-fixture.dto.js.map +1 -0
- package/dist/tool-fixtures/index.d.ts +7 -0
- package/dist/tool-fixtures/index.d.ts.map +1 -0
- package/dist/tool-fixtures/index.js +23 -0
- package/dist/tool-fixtures/index.js.map +1 -0
- package/dist/tool-fixtures/mock-resolver.service.d.ts +48 -0
- package/dist/tool-fixtures/mock-resolver.service.d.ts.map +1 -0
- package/dist/tool-fixtures/mock-resolver.service.js +99 -0
- package/dist/tool-fixtures/mock-resolver.service.js.map +1 -0
- package/dist/tool-fixtures/schemas/tool-fixture.schema.d.ts +35 -0
- package/dist/tool-fixtures/schemas/tool-fixture.schema.d.ts.map +1 -0
- package/dist/tool-fixtures/schemas/tool-fixture.schema.js +87 -0
- package/dist/tool-fixtures/schemas/tool-fixture.schema.js.map +1 -0
- package/dist/tool-fixtures/tool-fixture.controller.d.ts +45 -0
- package/dist/tool-fixtures/tool-fixture.controller.d.ts.map +1 -0
- package/dist/tool-fixtures/tool-fixture.controller.js +223 -0
- package/dist/tool-fixtures/tool-fixture.controller.js.map +1 -0
- package/dist/tool-fixtures/tool-fixture.module.d.ts +3 -0
- package/dist/tool-fixtures/tool-fixture.module.d.ts.map +1 -0
- package/dist/tool-fixtures/tool-fixture.module.js +31 -0
- package/dist/tool-fixtures/tool-fixture.module.js.map +1 -0
- package/dist/tool-fixtures/tool-fixture.service.d.ts +59 -0
- package/dist/tool-fixtures/tool-fixture.service.d.ts.map +1 -0
- package/dist/tool-fixtures/tool-fixture.service.js +198 -0
- package/dist/tool-fixtures/tool-fixture.service.js.map +1 -0
- package/package.json +47 -0
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { Model } from 'mongoose';
|
|
2
|
+
import { ScenarioExecution, ScenarioExecutionDocument } from '../schemas/scenario-execution.schema';
|
|
3
|
+
import { ScenarioDocument } from '../schemas/scenario.schema';
|
|
4
|
+
import { ExecuteScenarioDto, RetryExecutionDto, EvaluateExecutionDto } from '../dto/execute-scenario.dto';
|
|
5
|
+
import { QueueProducerService } from '../../execution/queue-producer.service';
|
|
6
|
+
import { EvaluationService } from '@chanl/scorecards-core';
|
|
7
|
+
export declare class ScenarioExecutionService {
|
|
8
|
+
private executionModel;
|
|
9
|
+
private scenarioModel;
|
|
10
|
+
private readonly queueProducer;
|
|
11
|
+
private readonly evaluationService;
|
|
12
|
+
private readonly logger;
|
|
13
|
+
constructor(executionModel: Model<ScenarioExecutionDocument>, scenarioModel: Model<ScenarioDocument>, queueProducer: QueueProducerService, evaluationService: EvaluationService);
|
|
14
|
+
/**
|
|
15
|
+
* Create and queue a scenario execution.
|
|
16
|
+
* Note: actual queue processing will be wired up by the execution engine (Task 4).
|
|
17
|
+
*/
|
|
18
|
+
execute(scenarioId: string, executeDto: ExecuteScenarioDto): Promise<ScenarioExecution>;
|
|
19
|
+
/**
|
|
20
|
+
* Get execution by executionId
|
|
21
|
+
*/
|
|
22
|
+
findOne(executionId: string): Promise<ScenarioExecution>;
|
|
23
|
+
/**
|
|
24
|
+
* Get executions for a specific scenario
|
|
25
|
+
*/
|
|
26
|
+
findByScenario(scenarioId: string, pagination?: {
|
|
27
|
+
limit?: number;
|
|
28
|
+
offset?: number;
|
|
29
|
+
}): Promise<{
|
|
30
|
+
executions: ScenarioExecution[];
|
|
31
|
+
total: number;
|
|
32
|
+
}>;
|
|
33
|
+
/**
|
|
34
|
+
* Get all executions with filters
|
|
35
|
+
*/
|
|
36
|
+
findAll(filters?: {
|
|
37
|
+
scenarioId?: string;
|
|
38
|
+
agentId?: string;
|
|
39
|
+
personaId?: string;
|
|
40
|
+
status?: string;
|
|
41
|
+
triggerId?: string;
|
|
42
|
+
triggeredBy?: string;
|
|
43
|
+
fromDate?: string;
|
|
44
|
+
toDate?: string;
|
|
45
|
+
minScore?: number;
|
|
46
|
+
maxScore?: number;
|
|
47
|
+
}, pagination?: {
|
|
48
|
+
limit?: number;
|
|
49
|
+
offset?: number;
|
|
50
|
+
}): Promise<{
|
|
51
|
+
executions: ScenarioExecution[];
|
|
52
|
+
total: number;
|
|
53
|
+
}>;
|
|
54
|
+
/**
|
|
55
|
+
* Update execution status
|
|
56
|
+
*/
|
|
57
|
+
updateStatus(executionId: string, status: string, updates?: Partial<ScenarioExecution>): Promise<ScenarioExecution>;
|
|
58
|
+
/**
|
|
59
|
+
* Cancel a running or queued execution
|
|
60
|
+
*/
|
|
61
|
+
cancel(executionId: string): Promise<void>;
|
|
62
|
+
/**
|
|
63
|
+
* Retry a failed execution
|
|
64
|
+
*/
|
|
65
|
+
retry(executionId: string, retryDto: RetryExecutionDto): Promise<ScenarioExecution>;
|
|
66
|
+
/**
|
|
67
|
+
* Evaluate a completed execution against a scorecard.
|
|
68
|
+
* Builds a transcript from stepResults and runs the EvaluationService.
|
|
69
|
+
*/
|
|
70
|
+
evaluate(executionId: string, dto: EvaluateExecutionDto): Promise<ScenarioExecution>;
|
|
71
|
+
private generateEvalSummary;
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=scenario-execution.service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scenario-execution.service.d.ts","sourceRoot":"","sources":["../../../src/scenarios/services/scenario-execution.service.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,KAAK,EAAS,MAAM,UAAU,CAAC;AAExC,OAAO,EACL,iBAAiB,EACjB,yBAAyB,EAC1B,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EAAY,g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CAAC;QACnB,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;KACnB,EACD,UAAU,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,GAC/C,OAAO,CAAC;QAAE,UAAU,EAAE,iBAAiB,EAAE,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;IAuE9D;;OAEG;IACG,YAAY,CAChB,WAAW,EAAE,MAAM,EACnB,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE,OAAO,CAAC,iBAAiB,CAAC,GACnC,OAAO,CAAC,iBAAiB,CAAC;IAuC7B;;OAEG;IACG,MAAM,CACV,WAAW,EAAE,MAAM,GAClB,OAAO,CAAC,IAAI,CAAC;IA4ChB;;OAEG;IACG,KAAK,CACT,WAAW,EAAE,MAAM,EACnB,QAAQ,EAAE,iBAAiB,GAC1B,OAAO,CAAC,iBAAiB,CAAC;IA0E7B;;;OAGG;IACG,QAAQ,CACZ,WAAW,EAAE,MAAM,EACnB,GAAG,EAAE,oBAAoB,GACxB,OAAO,CAAC,iBAAiB,CAAC;YA0Kf,mBAAmB;CAsDlC"}
|
|
@@ -0,0 +1,505 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
var ScenarioExecutionService_1;
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.ScenarioExecutionService = void 0;
|
|
17
|
+
const common_1 = require("@nestjs/common");
|
|
18
|
+
const mongoose_1 = require("@nestjs/mongoose");
|
|
19
|
+
const mongoose_2 = require("mongoose");
|
|
20
|
+
const crypto_1 = require("crypto");
|
|
21
|
+
const scenario_execution_schema_1 = require("../schemas/scenario-execution.schema");
|
|
22
|
+
const scenario_schema_1 = require("../schemas/scenario.schema");
|
|
23
|
+
const queue_producer_service_1 = require("../../execution/queue-producer.service");
|
|
24
|
+
const scorecards_core_1 = require("@chanl/scorecards-core");
|
|
25
|
+
const judge_llm_1 = require("../../execution/judge-llm");
|
|
26
|
+
let ScenarioExecutionService = ScenarioExecutionService_1 = class ScenarioExecutionService {
|
|
27
|
+
constructor(executionModel, scenarioModel, queueProducer, evaluationService) {
|
|
28
|
+
this.executionModel = executionModel;
|
|
29
|
+
this.scenarioModel = scenarioModel;
|
|
30
|
+
this.queueProducer = queueProducer;
|
|
31
|
+
this.evaluationService = evaluationService;
|
|
32
|
+
this.logger = new common_1.Logger(ScenarioExecutionService_1.name);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Create and queue a scenario execution.
|
|
36
|
+
* Note: actual queue processing will be wired up by the execution engine (Task 4).
|
|
37
|
+
*/
|
|
38
|
+
async execute(scenarioId, executeDto) {
|
|
39
|
+
try {
|
|
40
|
+
// Verify scenario exists and is active
|
|
41
|
+
const scenario = await this.scenarioModel.findById(scenarioId);
|
|
42
|
+
if (!scenario) {
|
|
43
|
+
throw new common_1.NotFoundException(`Scenario with ID ${scenarioId} not found`);
|
|
44
|
+
}
|
|
45
|
+
if (scenario.status !== 'active') {
|
|
46
|
+
throw new common_1.BadRequestException(`Cannot execute scenario with status "${scenario.status}". Scenario must be active.`);
|
|
47
|
+
}
|
|
48
|
+
// Create execution record
|
|
49
|
+
const executionId = `exec_${(0, crypto_1.randomUUID)()}`;
|
|
50
|
+
const executionData = {
|
|
51
|
+
executionId,
|
|
52
|
+
scenarioId: new mongoose_2.Types.ObjectId(scenarioId),
|
|
53
|
+
promptId: new mongoose_2.Types.ObjectId(executeDto.promptId),
|
|
54
|
+
personaId: executeDto.personaId
|
|
55
|
+
? new mongoose_2.Types.ObjectId(executeDto.personaId)
|
|
56
|
+
: scenario.personaIds?.[0],
|
|
57
|
+
scorecardId: executeDto.scorecardId
|
|
58
|
+
? new mongoose_2.Types.ObjectId(executeDto.scorecardId)
|
|
59
|
+
: scenario.scorecardId,
|
|
60
|
+
triggerId: executeDto.triggerId
|
|
61
|
+
? new mongoose_2.Types.ObjectId(executeDto.triggerId)
|
|
62
|
+
: undefined,
|
|
63
|
+
status: 'queued',
|
|
64
|
+
startTime: new Date(),
|
|
65
|
+
triggeredBy: 'system',
|
|
66
|
+
parameters: executeDto.parameters || {},
|
|
67
|
+
environment: {
|
|
68
|
+
version: '1.0.0',
|
|
69
|
+
environment: executeDto.environment || 'development',
|
|
70
|
+
},
|
|
71
|
+
};
|
|
72
|
+
const execution = new this.executionModel(executionData);
|
|
73
|
+
const savedExecution = await execution.save();
|
|
74
|
+
// Enqueue the BullMQ job for the execution processor
|
|
75
|
+
await this.queueProducer.enqueueExecution(executionId, scenarioId, {
|
|
76
|
+
promptId: executeDto.promptId,
|
|
77
|
+
personaId: executeDto.personaId || scenario.personaIds?.[0]?.toString(),
|
|
78
|
+
parameters: executeDto.parameters,
|
|
79
|
+
toolFixtureIds: executeDto.toolFixtureIds,
|
|
80
|
+
});
|
|
81
|
+
this.logger.log(`Created and enqueued execution ${executionId} for scenario ${scenarioId}`);
|
|
82
|
+
return savedExecution.toJSON();
|
|
83
|
+
}
|
|
84
|
+
catch (error) {
|
|
85
|
+
this.logger.error(`Failed to queue execution: ${error.message}`, error.stack);
|
|
86
|
+
throw error;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Get execution by executionId
|
|
91
|
+
*/
|
|
92
|
+
async findOne(executionId) {
|
|
93
|
+
try {
|
|
94
|
+
// Accept both MongoDB _id (24-char hex) and executionId (exec_uuid)
|
|
95
|
+
const isObjectId = /^[a-f0-9]{24}$/.test(executionId);
|
|
96
|
+
const execution = isObjectId
|
|
97
|
+
? await this.executionModel.findById(executionId)
|
|
98
|
+
: await this.executionModel.findOne({ executionId });
|
|
99
|
+
if (!execution) {
|
|
100
|
+
throw new common_1.NotFoundException(`Execution with ID ${executionId} not found`);
|
|
101
|
+
}
|
|
102
|
+
return execution.toJSON();
|
|
103
|
+
}
|
|
104
|
+
catch (error) {
|
|
105
|
+
if (error instanceof common_1.NotFoundException) {
|
|
106
|
+
throw error;
|
|
107
|
+
}
|
|
108
|
+
this.logger.error(`Failed to find execution: ${error.message}`, error.stack);
|
|
109
|
+
throw error;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Get executions for a specific scenario
|
|
114
|
+
*/
|
|
115
|
+
async findByScenario(scenarioId, pagination) {
|
|
116
|
+
try {
|
|
117
|
+
const query = {
|
|
118
|
+
scenarioId: new mongoose_2.Types.ObjectId(scenarioId),
|
|
119
|
+
};
|
|
120
|
+
let queryBuilder = this.executionModel
|
|
121
|
+
.find(query)
|
|
122
|
+
.sort({ startTime: -1 });
|
|
123
|
+
if (pagination?.offset)
|
|
124
|
+
queryBuilder = queryBuilder.skip(pagination.offset);
|
|
125
|
+
if (pagination?.limit)
|
|
126
|
+
queryBuilder = queryBuilder.limit(pagination.limit);
|
|
127
|
+
const executions = await queryBuilder.exec();
|
|
128
|
+
const total = await this.executionModel.countDocuments(query);
|
|
129
|
+
return {
|
|
130
|
+
executions: executions.map((e) => e.toJSON()),
|
|
131
|
+
total,
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
catch (error) {
|
|
135
|
+
this.logger.error(`Failed to find scenario executions: ${error.message}`, error.stack);
|
|
136
|
+
throw error;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Get all executions with filters
|
|
141
|
+
*/
|
|
142
|
+
async findAll(filters, pagination) {
|
|
143
|
+
try {
|
|
144
|
+
const query = {};
|
|
145
|
+
if (filters) {
|
|
146
|
+
if (filters.scenarioId) {
|
|
147
|
+
query.scenarioId = new mongoose_2.Types.ObjectId(filters.scenarioId);
|
|
148
|
+
}
|
|
149
|
+
if (filters.agentId) {
|
|
150
|
+
query.agentId = new mongoose_2.Types.ObjectId(filters.agentId);
|
|
151
|
+
}
|
|
152
|
+
if (filters.personaId) {
|
|
153
|
+
query.personaId = new mongoose_2.Types.ObjectId(filters.personaId);
|
|
154
|
+
}
|
|
155
|
+
if (filters.status) {
|
|
156
|
+
query.status = filters.status;
|
|
157
|
+
}
|
|
158
|
+
if (filters.triggerId) {
|
|
159
|
+
query.triggerId = new mongoose_2.Types.ObjectId(filters.triggerId);
|
|
160
|
+
}
|
|
161
|
+
if (filters.triggeredBy) {
|
|
162
|
+
query.triggeredBy = filters.triggeredBy;
|
|
163
|
+
}
|
|
164
|
+
if (filters.fromDate || filters.toDate) {
|
|
165
|
+
query.startTime = {};
|
|
166
|
+
if (filters.fromDate) {
|
|
167
|
+
query.startTime.$gte = new Date(filters.fromDate);
|
|
168
|
+
}
|
|
169
|
+
if (filters.toDate) {
|
|
170
|
+
query.startTime.$lte = new Date(filters.toDate);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
if (filters.minScore !== undefined ||
|
|
174
|
+
filters.maxScore !== undefined) {
|
|
175
|
+
query.overallScore = {};
|
|
176
|
+
if (filters.minScore !== undefined) {
|
|
177
|
+
query.overallScore.$gte = filters.minScore;
|
|
178
|
+
}
|
|
179
|
+
if (filters.maxScore !== undefined) {
|
|
180
|
+
query.overallScore.$lte = filters.maxScore;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
let queryBuilder = this.executionModel
|
|
185
|
+
.find(query)
|
|
186
|
+
.sort({ startTime: -1 });
|
|
187
|
+
if (pagination?.offset)
|
|
188
|
+
queryBuilder = queryBuilder.skip(pagination.offset);
|
|
189
|
+
if (pagination?.limit)
|
|
190
|
+
queryBuilder = queryBuilder.limit(pagination.limit);
|
|
191
|
+
const executions = await queryBuilder.exec();
|
|
192
|
+
const total = await this.executionModel.countDocuments(query);
|
|
193
|
+
return {
|
|
194
|
+
executions: executions.map((e) => e.toJSON()),
|
|
195
|
+
total,
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
catch (error) {
|
|
199
|
+
this.logger.error(`Failed to find executions: ${error.message}`, error.stack);
|
|
200
|
+
throw error;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Update execution status
|
|
205
|
+
*/
|
|
206
|
+
async updateStatus(executionId, status, updates) {
|
|
207
|
+
try {
|
|
208
|
+
const updateData = {
|
|
209
|
+
status,
|
|
210
|
+
updatedAt: new Date(),
|
|
211
|
+
...updates,
|
|
212
|
+
};
|
|
213
|
+
if (['completed', 'failed', 'timeout', 'cancelled'].includes(status)) {
|
|
214
|
+
updateData.endTime = updateData.endTime || new Date();
|
|
215
|
+
}
|
|
216
|
+
const execution = await this.executionModel.findOneAndUpdate({ executionId }, updateData, { new: true });
|
|
217
|
+
if (!execution) {
|
|
218
|
+
throw new common_1.NotFoundException(`Execution with ID ${executionId} not found`);
|
|
219
|
+
}
|
|
220
|
+
return execution.toJSON();
|
|
221
|
+
}
|
|
222
|
+
catch (error) {
|
|
223
|
+
if (error instanceof common_1.NotFoundException) {
|
|
224
|
+
throw error;
|
|
225
|
+
}
|
|
226
|
+
this.logger.error(`Failed to update execution status: ${error.message}`, error.stack);
|
|
227
|
+
throw error;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Cancel a running or queued execution
|
|
232
|
+
*/
|
|
233
|
+
async cancel(executionId) {
|
|
234
|
+
try {
|
|
235
|
+
const isObjectId = /^[a-f0-9]{24}$/.test(executionId);
|
|
236
|
+
const execution = isObjectId
|
|
237
|
+
? await this.executionModel.findById(executionId)
|
|
238
|
+
: await this.executionModel.findOne({ executionId });
|
|
239
|
+
if (!execution) {
|
|
240
|
+
throw new common_1.NotFoundException(`Execution with ID ${executionId} not found`);
|
|
241
|
+
}
|
|
242
|
+
if (!['queued', 'running'].includes(execution.status)) {
|
|
243
|
+
throw new common_1.BadRequestException(`Cannot cancel execution with status "${execution.status}"`);
|
|
244
|
+
}
|
|
245
|
+
await this.executionModel.findOneAndUpdate({ executionId }, {
|
|
246
|
+
status: 'cancelled',
|
|
247
|
+
endTime: new Date(),
|
|
248
|
+
updatedAt: new Date(),
|
|
249
|
+
});
|
|
250
|
+
this.logger.log(`Cancelled execution ${executionId}`);
|
|
251
|
+
}
|
|
252
|
+
catch (error) {
|
|
253
|
+
if (error instanceof common_1.NotFoundException ||
|
|
254
|
+
error instanceof common_1.BadRequestException) {
|
|
255
|
+
throw error;
|
|
256
|
+
}
|
|
257
|
+
this.logger.error(`Failed to cancel execution: ${error.message}`, error.stack);
|
|
258
|
+
throw error;
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* Retry a failed execution
|
|
263
|
+
*/
|
|
264
|
+
async retry(executionId, retryDto) {
|
|
265
|
+
try {
|
|
266
|
+
const isObjectId = /^[a-f0-9]{24}$/.test(executionId);
|
|
267
|
+
const originalExecution = isObjectId
|
|
268
|
+
? await this.executionModel.findById(executionId)
|
|
269
|
+
: await this.executionModel.findOne({ executionId });
|
|
270
|
+
if (!originalExecution) {
|
|
271
|
+
throw new common_1.NotFoundException(`Execution with ID ${executionId} not found`);
|
|
272
|
+
}
|
|
273
|
+
if (!['failed', 'timeout', 'cancelled'].includes(originalExecution.status)) {
|
|
274
|
+
throw new common_1.BadRequestException(`Cannot retry execution with status "${originalExecution.status}"`);
|
|
275
|
+
}
|
|
276
|
+
// Create new execution based on original
|
|
277
|
+
const newExecutionId = `exec_${(0, crypto_1.randomUUID)()}`;
|
|
278
|
+
const retryCount = (originalExecution.retryInfo?.retryCount || 0) + 1;
|
|
279
|
+
const newExecution = new this.executionModel({
|
|
280
|
+
executionId: newExecutionId,
|
|
281
|
+
scenarioId: originalExecution.scenarioId,
|
|
282
|
+
agentId: originalExecution.agentId,
|
|
283
|
+
personaId: originalExecution.personaId,
|
|
284
|
+
scorecardId: originalExecution.scorecardId,
|
|
285
|
+
triggerId: originalExecution.triggerId,
|
|
286
|
+
status: 'queued',
|
|
287
|
+
startTime: new Date(),
|
|
288
|
+
triggeredBy: 'system',
|
|
289
|
+
parameters: {
|
|
290
|
+
...originalExecution.parameters,
|
|
291
|
+
...retryDto.parameters,
|
|
292
|
+
},
|
|
293
|
+
environment: originalExecution.environment,
|
|
294
|
+
retryInfo: {
|
|
295
|
+
isRetry: true,
|
|
296
|
+
retryCount,
|
|
297
|
+
originalExecutionId: executionId,
|
|
298
|
+
retryReason: retryDto.reason || 'Manual retry',
|
|
299
|
+
},
|
|
300
|
+
parentExecutionId: originalExecution._id,
|
|
301
|
+
});
|
|
302
|
+
const savedExecution = await newExecution.save();
|
|
303
|
+
this.logger.log(`Created retry execution ${newExecutionId} for original ${executionId}`);
|
|
304
|
+
return savedExecution.toJSON();
|
|
305
|
+
}
|
|
306
|
+
catch (error) {
|
|
307
|
+
if (error instanceof common_1.NotFoundException ||
|
|
308
|
+
error instanceof common_1.BadRequestException) {
|
|
309
|
+
throw error;
|
|
310
|
+
}
|
|
311
|
+
this.logger.error(`Failed to retry execution: ${error.message}`, error.stack);
|
|
312
|
+
throw error;
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
/**
|
|
316
|
+
* Evaluate a completed execution against a scorecard.
|
|
317
|
+
* Builds a transcript from stepResults and runs the EvaluationService.
|
|
318
|
+
*/
|
|
319
|
+
async evaluate(executionId, dto) {
|
|
320
|
+
// 1. Load execution
|
|
321
|
+
const isObjectId = /^[a-f0-9]{24}$/.test(executionId);
|
|
322
|
+
const execution = isObjectId
|
|
323
|
+
? await this.executionModel.findById(executionId)
|
|
324
|
+
: await this.executionModel.findOne({ executionId });
|
|
325
|
+
if (!execution) {
|
|
326
|
+
throw new common_1.NotFoundException(`Execution with ID ${executionId} not found`);
|
|
327
|
+
}
|
|
328
|
+
if (execution.status !== 'completed') {
|
|
329
|
+
throw new common_1.BadRequestException(`Cannot evaluate execution with status "${execution.status}". Execution must be completed.`);
|
|
330
|
+
}
|
|
331
|
+
if (!execution.stepResults || execution.stepResults.length === 0) {
|
|
332
|
+
throw new common_1.BadRequestException('Execution has no step results to evaluate.');
|
|
333
|
+
}
|
|
334
|
+
// 2. Build transcript from stepResults
|
|
335
|
+
const conversationSteps = execution.stepResults.filter((s) => s.role === 'persona' || s.role === 'agent');
|
|
336
|
+
if (conversationSteps.length === 0) {
|
|
337
|
+
throw new common_1.BadRequestException('Execution has no conversation steps (persona/agent) to evaluate.');
|
|
338
|
+
}
|
|
339
|
+
const transcriptText = conversationSteps
|
|
340
|
+
.map((s) => s.role === 'agent'
|
|
341
|
+
? `Agent: ${s.actualResponse || ''}`
|
|
342
|
+
: `Customer: ${s.actualResponse || ''}`)
|
|
343
|
+
.join('\n');
|
|
344
|
+
const segments = conversationSteps.map((s) => ({
|
|
345
|
+
speaker: s.role === 'agent' ? 'agent' : 'customer',
|
|
346
|
+
text: s.actualResponse || '',
|
|
347
|
+
}));
|
|
348
|
+
// 3. Resolve an API key for the LLM judge
|
|
349
|
+
// Priority: Settings DB (UI-configured) > env vars (headless/CI fallback)
|
|
350
|
+
let judgeApiKey;
|
|
351
|
+
let judgeKind = 'openai';
|
|
352
|
+
// Settings DB first — this is where the Settings UI saves keys
|
|
353
|
+
try {
|
|
354
|
+
const settingsDoc = await this.executionModel.db.collection('settings').findOne({});
|
|
355
|
+
const providerKeys = settingsDoc?.providerKeys ?? {};
|
|
356
|
+
if (providerKeys.openai) {
|
|
357
|
+
judgeApiKey = providerKeys.openai;
|
|
358
|
+
judgeKind = 'openai';
|
|
359
|
+
}
|
|
360
|
+
else if (providerKeys.anthropic) {
|
|
361
|
+
judgeApiKey = providerKeys.anthropic;
|
|
362
|
+
judgeKind = 'anthropic';
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
catch {
|
|
366
|
+
// Settings lookup failed — fall through to env vars
|
|
367
|
+
}
|
|
368
|
+
// Env var fallback (headless/CI)
|
|
369
|
+
if (!judgeApiKey && process.env.CHANL_OPENAI_API_KEY) {
|
|
370
|
+
judgeApiKey = process.env.CHANL_OPENAI_API_KEY;
|
|
371
|
+
judgeKind = 'openai';
|
|
372
|
+
}
|
|
373
|
+
else if (!judgeApiKey && process.env.CHANL_ANTHROPIC_API_KEY) {
|
|
374
|
+
judgeApiKey = process.env.CHANL_ANTHROPIC_API_KEY;
|
|
375
|
+
judgeKind = 'anthropic';
|
|
376
|
+
}
|
|
377
|
+
const llmEvaluate = judgeApiKey
|
|
378
|
+
? (0, judge_llm_1.buildLlmJudge)({ kind: judgeKind, apiKey: judgeApiKey })
|
|
379
|
+
: undefined;
|
|
380
|
+
// 4. Calculate first-response latency metric
|
|
381
|
+
const firstAgentStep = conversationSteps.find((s) => s.role === 'agent');
|
|
382
|
+
const firstResponseLatency = firstAgentStep?.duration
|
|
383
|
+
? firstAgentStep.duration / 1000
|
|
384
|
+
: 0;
|
|
385
|
+
// 5. Run evaluation
|
|
386
|
+
try {
|
|
387
|
+
const evalResult = await this.evaluationService.evaluate(dto.scorecardId, {
|
|
388
|
+
transcriptText,
|
|
389
|
+
segments,
|
|
390
|
+
metrics: { firstResponseLatency },
|
|
391
|
+
llmEvaluate,
|
|
392
|
+
}, { scenarioExecutionId: execution.executionId });
|
|
393
|
+
// 6. Save results to execution via findOneAndUpdate
|
|
394
|
+
const scorecardResults = {
|
|
395
|
+
scorecardId: dto.scorecardId,
|
|
396
|
+
resultId: evalResult.resultId,
|
|
397
|
+
overallScore: evalResult.overallScore,
|
|
398
|
+
passed: evalResult.passed,
|
|
399
|
+
categoryScores: evalResult.categoryScores,
|
|
400
|
+
criteriaResults: evalResult.criteriaResults.map((cr) => ({
|
|
401
|
+
criteriaId: cr.criteriaId,
|
|
402
|
+
criteriaKey: cr.criteriaKey,
|
|
403
|
+
criteriaName: cr.criteriaName,
|
|
404
|
+
categoryId: cr.categoryId,
|
|
405
|
+
categoryName: cr.categoryName,
|
|
406
|
+
passed: cr.passed,
|
|
407
|
+
result: cr.result,
|
|
408
|
+
reasoning: cr.reasoning,
|
|
409
|
+
evidence: cr.evidence,
|
|
410
|
+
})),
|
|
411
|
+
evaluatedAt: new Date(),
|
|
412
|
+
};
|
|
413
|
+
const filter = isObjectId
|
|
414
|
+
? { _id: executionId }
|
|
415
|
+
: { executionId };
|
|
416
|
+
// Generate critical summary — reuse the same judge key
|
|
417
|
+
let scorecardSummary;
|
|
418
|
+
if (judgeApiKey) {
|
|
419
|
+
try {
|
|
420
|
+
scorecardSummary = await this.generateEvalSummary(evalResult, { kind: judgeKind, apiKey: judgeApiKey });
|
|
421
|
+
}
|
|
422
|
+
catch {
|
|
423
|
+
// Non-fatal — summary is optional
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
const updated = await this.executionModel.findOneAndUpdate(filter, { $set: { scorecardResults, ...(scorecardSummary ? { scorecardSummary } : {}) } }, { new: true });
|
|
427
|
+
if (!updated) {
|
|
428
|
+
throw new common_1.NotFoundException(`Execution with ID ${executionId} not found after evaluation`);
|
|
429
|
+
}
|
|
430
|
+
this.logger.log(`Evaluated execution ${executionId} against scorecard ${dto.scorecardId} — score: ${evalResult.overallScore}, passed: ${evalResult.passed}`);
|
|
431
|
+
return updated.toJSON();
|
|
432
|
+
}
|
|
433
|
+
catch (error) {
|
|
434
|
+
if (error instanceof common_1.NotFoundException ||
|
|
435
|
+
error instanceof common_1.BadRequestException) {
|
|
436
|
+
throw error;
|
|
437
|
+
}
|
|
438
|
+
this.logger.error(`Failed to evaluate execution: ${error.message}`, error.stack);
|
|
439
|
+
throw new common_1.InternalServerErrorException(`Evaluation failed: ${error.message}`);
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
async generateEvalSummary(evalResult, llmConfig) {
|
|
443
|
+
const failed = evalResult.criteriaResults.filter((c) => !c.passed);
|
|
444
|
+
const passed = evalResult.criteriaResults.filter((c) => c.passed);
|
|
445
|
+
const scorePercent = Math.round(evalResult.overallScore * 10);
|
|
446
|
+
const prompt = `You are a QA analyst summarizing an AI agent evaluation.
|
|
447
|
+
|
|
448
|
+
Score: ${scorePercent}% (${passed.length}/${evalResult.criteriaResults.length} criteria passed)
|
|
449
|
+
|
|
450
|
+
Failed criteria:
|
|
451
|
+
${failed.length === 0 ? 'None — all criteria passed.' : failed.map((c) => `- ${c.criteriaName} (${c.categoryName}): ${c.reasoning || 'No reasoning'}`).join('\n')}
|
|
452
|
+
|
|
453
|
+
Passed criteria:
|
|
454
|
+
${passed.map((c) => `- ${c.criteriaName} (${c.categoryName})`).join('\n')}
|
|
455
|
+
|
|
456
|
+
Write a critical 2-3 sentence summary. Focus on what went wrong (if anything) and the most important strengths. Be specific — name the criteria. No filler.`;
|
|
457
|
+
if (llmConfig.kind === 'openai') {
|
|
458
|
+
const res = await fetch('https://api.openai.com/v1/chat/completions', {
|
|
459
|
+
method: 'POST',
|
|
460
|
+
headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${llmConfig.apiKey}` },
|
|
461
|
+
body: JSON.stringify({
|
|
462
|
+
model: llmConfig.model || 'gpt-4o-mini',
|
|
463
|
+
messages: [{ role: 'user', content: prompt }],
|
|
464
|
+
max_tokens: 150,
|
|
465
|
+
temperature: 0.3,
|
|
466
|
+
}),
|
|
467
|
+
});
|
|
468
|
+
if (!res.ok)
|
|
469
|
+
return undefined;
|
|
470
|
+
const data = await res.json();
|
|
471
|
+
return data.choices?.[0]?.message?.content?.trim() || undefined;
|
|
472
|
+
}
|
|
473
|
+
else if (llmConfig.kind === 'anthropic') {
|
|
474
|
+
const res = await fetch('https://api.anthropic.com/v1/messages', {
|
|
475
|
+
method: 'POST',
|
|
476
|
+
headers: {
|
|
477
|
+
'Content-Type': 'application/json',
|
|
478
|
+
'x-api-key': llmConfig.apiKey,
|
|
479
|
+
'anthropic-version': '2023-06-01',
|
|
480
|
+
},
|
|
481
|
+
body: JSON.stringify({
|
|
482
|
+
model: llmConfig.model || 'claude-3-5-haiku-20241022',
|
|
483
|
+
max_tokens: 150,
|
|
484
|
+
messages: [{ role: 'user', content: prompt }],
|
|
485
|
+
}),
|
|
486
|
+
});
|
|
487
|
+
if (!res.ok)
|
|
488
|
+
return undefined;
|
|
489
|
+
const data = await res.json();
|
|
490
|
+
return data.content?.[0]?.text?.trim() || undefined;
|
|
491
|
+
}
|
|
492
|
+
return undefined;
|
|
493
|
+
}
|
|
494
|
+
};
|
|
495
|
+
exports.ScenarioExecutionService = ScenarioExecutionService;
|
|
496
|
+
exports.ScenarioExecutionService = ScenarioExecutionService = ScenarioExecutionService_1 = __decorate([
|
|
497
|
+
(0, common_1.Injectable)(),
|
|
498
|
+
__param(0, (0, mongoose_1.InjectModel)(scenario_execution_schema_1.ScenarioExecution.name)),
|
|
499
|
+
__param(1, (0, mongoose_1.InjectModel)(scenario_schema_1.Scenario.name)),
|
|
500
|
+
__metadata("design:paramtypes", [mongoose_2.Model,
|
|
501
|
+
mongoose_2.Model,
|
|
502
|
+
queue_producer_service_1.QueueProducerService,
|
|
503
|
+
scorecards_core_1.EvaluationService])
|
|
504
|
+
], ScenarioExecutionService);
|
|
505
|
+
//# sourceMappingURL=scenario-execution.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scenario-execution.service.js","sourceRoot":"","sources":["../../../src/scenarios/services/scenario-execution.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAMwB;AACxB,+CAA+C;AAC/C,uCAAwC;AACxC,mCAAoC;AACpC,oFAG8C;AAC9C,gEAAwE;AAMxE,mFAA8E;AAC9E,4DAA2D;AAC3D,yDAA0D;AAInD,IAAM,wBAAwB,gCAA9B,MAAM,wBAAwB;IAGnC,YAEE,cAAwD,EAExD,aAA8C,EAC7B,aAAmC,EACnC,iBAAoC;QAJ7C,mBAAc,GAAd,cAAc,CAAkC;QAEhD,kBAAa,GAAb,aAAa,CAAyB;QAC7B,kBAAa,GAAb,aAAa,CAAsB;QACnC,sBAAiB,GAAjB,iBAAiB,CAAmB;QARtC,WAAM,GAAG,IAAI,eAAM,CAAC,0BAAwB,CAAC,IAAI,CAAC,CAAC;IASjE,CAAC;IAEJ;;;OAGG;IACH,KAAK,CAAC,OAAO,CACX,UAAkB,EAClB,UAA8B;QAE9B,IAAI,CAAC;YACH,uCAAuC;YACvC,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,aAAa,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;YAC/D,IAAI,CAAC,QAAQ,EAAE,CAAC;gBACd,MAAM,IAAI,0BAAiB,CACzB,oBAAoB,UAAU,YAAY,CAC3C,CAAC;YACJ,CAAC;YAED,IAAI,QAAQ,CAAC,MAAM,KAAK,QAAQ,EAAE,CAAC;gBACjC,MAAM,IAAI,4BAAmB,CAC3B,wCAAwC,QAAQ,CAAC,MAAM,6BAA6B,CACrF,CAAC;YACJ,CAAC;YAED,0BAA0B;YAC1B,MAAM,WAAW,GAAG,QAAQ,IAAA,mBAAU,GAAE,EAAE,CAAC;YAC3C,MAAM,aAAa,GAAQ;gBACzB,WAAW;gBACX,UAAU,EAAE,IAAI,gBAAK,CAAC,QAAQ,CAAC,UAAU,CAAC;gBAC1C,Q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