@langwatch/scenario 0.2.13 → 0.3.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/README.md +35 -8
- package/dist/{chunk-6SKQWXT7.mjs → chunk-3Z7E24UI.mjs} +26 -6
- package/dist/{chunk-OL4RFXV4.mjs → chunk-RHTLQKEJ.mjs} +1 -1
- package/dist/index.d.mts +109 -130
- package/dist/index.d.ts +109 -130
- package/dist/index.js +95 -75
- package/dist/index.mjs +23 -23
- package/dist/integrations/vitest/reporter.js +14 -10
- package/dist/integrations/vitest/reporter.mjs +7 -3
- package/dist/integrations/vitest/setup.js +70 -50
- package/dist/integrations/vitest/setup.mjs +2 -2
- package/package.json +6 -5
package/README.md
CHANGED
|
@@ -78,7 +78,7 @@ import { describe, it, expect } from "vitest";
|
|
|
78
78
|
import { openai } from "@ai-sdk/openai";
|
|
79
79
|
import scenario, { type AgentAdapter, AgentRole } from "@langwatch/scenario";
|
|
80
80
|
import { generateText, tool } from "ai";
|
|
81
|
-
import { z } from "zod";
|
|
81
|
+
import { z } from "zod/v4";
|
|
82
82
|
|
|
83
83
|
describe("Weather Agent", () => {
|
|
84
84
|
it("should get the weather for a city", async () => {
|
|
@@ -103,13 +103,40 @@ describe("Weather Agent", () => {
|
|
|
103
103
|
tools: { get_current_weather: getCurrentWeather },
|
|
104
104
|
});
|
|
105
105
|
|
|
106
|
-
if (response.toolCalls
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
106
|
+
if (response.toolCalls && response.toolCalls.length > 0) {
|
|
107
|
+
const toolCall = response.toolCalls[0];
|
|
108
|
+
// Agent executes the tool directly and returns both messages
|
|
109
|
+
const toolResult = await getCurrentWeather.execute(
|
|
110
|
+
toolCall.input as { city: string },
|
|
111
|
+
{
|
|
112
|
+
toolCallId: toolCall.toolCallId,
|
|
113
|
+
messages: input.messages,
|
|
114
|
+
}
|
|
115
|
+
);
|
|
116
|
+
return [
|
|
117
|
+
{
|
|
118
|
+
role: "assistant",
|
|
119
|
+
content: [
|
|
120
|
+
{
|
|
121
|
+
type: "tool-call",
|
|
122
|
+
toolName: toolCall.toolName,
|
|
123
|
+
toolCallId: toolCall.toolCallId,
|
|
124
|
+
input: toolCall.input,
|
|
125
|
+
},
|
|
126
|
+
],
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
role: "tool",
|
|
130
|
+
content: [
|
|
131
|
+
{
|
|
132
|
+
type: "tool-result",
|
|
133
|
+
toolName: toolCall.toolName,
|
|
134
|
+
toolCallId: toolCall.toolCallId,
|
|
135
|
+
output: { type: "text", value: toolResult as string },
|
|
136
|
+
},
|
|
137
|
+
],
|
|
138
|
+
},
|
|
139
|
+
];
|
|
113
140
|
}
|
|
114
141
|
|
|
115
142
|
return response.text;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Logger,
|
|
3
3
|
getEnv
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-RHTLQKEJ.mjs";
|
|
5
5
|
import {
|
|
6
6
|
__export
|
|
7
7
|
} from "./chunk-7P6ASYW6.mjs";
|
|
8
8
|
|
|
9
9
|
// src/domain/core/config.ts
|
|
10
|
-
import { z } from "zod";
|
|
10
|
+
import { z } from "zod/v4";
|
|
11
11
|
var DEFAULT_TEMPERATURE = 0;
|
|
12
12
|
var scenarioProjectConfigSchema = z.object({
|
|
13
13
|
defaultModel: z.object({
|
|
@@ -75,6 +75,9 @@ import {
|
|
|
75
75
|
} from "rxjs";
|
|
76
76
|
|
|
77
77
|
// src/events/event-alert-message-logger.ts
|
|
78
|
+
import * as fs2 from "fs";
|
|
79
|
+
import * as os from "os";
|
|
80
|
+
import * as path2 from "path";
|
|
78
81
|
import open from "open";
|
|
79
82
|
|
|
80
83
|
// src/config/load.ts
|
|
@@ -184,8 +187,23 @@ function generateMessageId() {
|
|
|
184
187
|
}
|
|
185
188
|
|
|
186
189
|
// src/events/event-alert-message-logger.ts
|
|
187
|
-
var EventAlertMessageLogger = class
|
|
188
|
-
|
|
190
|
+
var EventAlertMessageLogger = class {
|
|
191
|
+
/**
|
|
192
|
+
* Creates a coordination file to prevent duplicate messages across processes.
|
|
193
|
+
* Returns true if this process should show the message (first one to create the file).
|
|
194
|
+
*/
|
|
195
|
+
createCoordinationFile(type) {
|
|
196
|
+
try {
|
|
197
|
+
const batchId = getBatchRunId();
|
|
198
|
+
const tmpDir = os.tmpdir();
|
|
199
|
+
const fileName = `scenario-${type}-${batchId}`;
|
|
200
|
+
const filePath = path2.join(tmpDir, fileName);
|
|
201
|
+
fs2.writeFileSync(filePath, process.pid.toString(), { flag: "wx" });
|
|
202
|
+
return true;
|
|
203
|
+
} catch {
|
|
204
|
+
return false;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
189
207
|
/**
|
|
190
208
|
* Shows a fancy greeting message about simulation reporting status.
|
|
191
209
|
* Only shows once per batch run to avoid spam.
|
|
@@ -194,10 +212,9 @@ var EventAlertMessageLogger = class _EventAlertMessageLogger {
|
|
|
194
212
|
if (this.isGreetingDisabled()) {
|
|
195
213
|
return;
|
|
196
214
|
}
|
|
197
|
-
if (
|
|
215
|
+
if (!this.createCoordinationFile("greeting")) {
|
|
198
216
|
return;
|
|
199
217
|
}
|
|
200
|
-
_EventAlertMessageLogger.shownBatchIds.add(getBatchRunId());
|
|
201
218
|
this.displayGreeting();
|
|
202
219
|
}
|
|
203
220
|
/**
|
|
@@ -208,6 +225,9 @@ var EventAlertMessageLogger = class _EventAlertMessageLogger {
|
|
|
208
225
|
if (this.isGreetingDisabled()) {
|
|
209
226
|
return;
|
|
210
227
|
}
|
|
228
|
+
if (!this.createCoordinationFile(`watch-${params.scenarioSetId}`)) {
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
211
231
|
await this.displayWatchMessage(params);
|
|
212
232
|
}
|
|
213
233
|
isGreetingDisabled() {
|
package/dist/index.d.mts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import * as ai from 'ai';
|
|
2
|
-
import { CoreMessage, CoreUserMessage, CoreAssistantMessage, CoreToolMessage, LanguageModel } from 'ai';
|
|
3
|
-
import { z } from 'zod';
|
|
2
|
+
import { CoreMessage, CoreUserMessage, CoreAssistantMessage, CoreToolMessage, LanguageModel, ModelMessage } from 'ai';
|
|
3
|
+
import { z } from 'zod/v4';
|
|
4
4
|
import { Observable } from 'rxjs';
|
|
5
|
+
import { z as z$1 } from 'zod';
|
|
5
6
|
|
|
6
7
|
declare enum AgentRole {
|
|
7
8
|
USER = "User",
|
|
@@ -352,34 +353,12 @@ interface ScenarioExecutionStateLike {
|
|
|
352
353
|
declare const DEFAULT_TEMPERATURE = 0;
|
|
353
354
|
declare const scenarioProjectConfigSchema: z.ZodObject<{
|
|
354
355
|
defaultModel: z.ZodOptional<z.ZodObject<{
|
|
355
|
-
model: z.
|
|
356
|
+
model: z.ZodCustom<LanguageModel, LanguageModel>;
|
|
356
357
|
temperature: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
357
358
|
maxTokens: z.ZodOptional<z.ZodNumber>;
|
|
358
|
-
},
|
|
359
|
-
model: ai.LanguageModelV1;
|
|
360
|
-
temperature: number;
|
|
361
|
-
maxTokens?: number | undefined;
|
|
362
|
-
}, {
|
|
363
|
-
model: ai.LanguageModelV1;
|
|
364
|
-
temperature?: number | undefined;
|
|
365
|
-
maxTokens?: number | undefined;
|
|
366
|
-
}>>;
|
|
359
|
+
}, z.core.$strip>>;
|
|
367
360
|
headless: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
368
|
-
},
|
|
369
|
-
headless: boolean;
|
|
370
|
-
defaultModel?: {
|
|
371
|
-
model: ai.LanguageModelV1;
|
|
372
|
-
temperature: number;
|
|
373
|
-
maxTokens?: number | undefined;
|
|
374
|
-
} | undefined;
|
|
375
|
-
}, {
|
|
376
|
-
defaultModel?: {
|
|
377
|
-
model: ai.LanguageModelV1;
|
|
378
|
-
temperature?: number | undefined;
|
|
379
|
-
maxTokens?: number | undefined;
|
|
380
|
-
} | undefined;
|
|
381
|
-
headless?: boolean | undefined;
|
|
382
|
-
}>;
|
|
361
|
+
}, z.core.$strict>;
|
|
383
362
|
type ScenarioProjectConfig = z.infer<typeof scenarioProjectConfigSchema>;
|
|
384
363
|
declare function defineConfig(config: ScenarioProjectConfig): ScenarioProjectConfig;
|
|
385
364
|
|
|
@@ -494,7 +473,7 @@ declare class JudgeAgent extends JudgeAgentAdapter {
|
|
|
494
473
|
constructor(cfg: JudgeAgentConfig);
|
|
495
474
|
call(input: AgentInput): Promise<never[] | {
|
|
496
475
|
success: boolean;
|
|
497
|
-
messages:
|
|
476
|
+
messages: ai.ModelMessage[];
|
|
498
477
|
reasoning: string;
|
|
499
478
|
metCriteria: string[];
|
|
500
479
|
unmetCriteria: string[];
|
|
@@ -690,26 +669,26 @@ declare enum ScenarioRunStatus {
|
|
|
690
669
|
* Discriminated union of all possible scenario event types.
|
|
691
670
|
* Enables type-safe handling of different event types based on the 'type' field.
|
|
692
671
|
*/
|
|
693
|
-
declare const scenarioEventSchema: z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
|
|
694
|
-
timestamp: z.ZodNumber;
|
|
695
|
-
rawEvent: z.ZodOptional<z.ZodAny>;
|
|
696
|
-
batchRunId: z.ZodString;
|
|
697
|
-
scenarioId: z.ZodString;
|
|
698
|
-
scenarioRunId: z.ZodString;
|
|
699
|
-
scenarioSetId: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
672
|
+
declare const scenarioEventSchema: z$1.ZodDiscriminatedUnion<"type", [z$1.ZodObject<{
|
|
673
|
+
timestamp: z$1.ZodNumber;
|
|
674
|
+
rawEvent: z$1.ZodOptional<z$1.ZodAny>;
|
|
675
|
+
batchRunId: z$1.ZodString;
|
|
676
|
+
scenarioId: z$1.ZodString;
|
|
677
|
+
scenarioRunId: z$1.ZodString;
|
|
678
|
+
scenarioSetId: z$1.ZodDefault<z$1.ZodOptional<z$1.ZodString>>;
|
|
700
679
|
} & {
|
|
701
|
-
type: z.ZodLiteral<ScenarioEventType.RUN_STARTED>;
|
|
702
|
-
metadata: z.ZodObject<{
|
|
703
|
-
name: z.ZodOptional<z.ZodString>;
|
|
704
|
-
description: z.ZodOptional<z.ZodString>;
|
|
705
|
-
}, "strip", z.ZodTypeAny, {
|
|
680
|
+
type: z$1.ZodLiteral<ScenarioEventType.RUN_STARTED>;
|
|
681
|
+
metadata: z$1.ZodObject<{
|
|
682
|
+
name: z$1.ZodOptional<z$1.ZodString>;
|
|
683
|
+
description: z$1.ZodOptional<z$1.ZodString>;
|
|
684
|
+
}, "strip", z$1.ZodTypeAny, {
|
|
706
685
|
name?: string | undefined;
|
|
707
686
|
description?: string | undefined;
|
|
708
687
|
}, {
|
|
709
688
|
name?: string | undefined;
|
|
710
689
|
description?: string | undefined;
|
|
711
690
|
}>;
|
|
712
|
-
}, "strip", z.ZodTypeAny, {
|
|
691
|
+
}, "strip", z$1.ZodTypeAny, {
|
|
713
692
|
type: ScenarioEventType.RUN_STARTED;
|
|
714
693
|
timestamp: number;
|
|
715
694
|
batchRunId: string;
|
|
@@ -733,36 +712,36 @@ declare const scenarioEventSchema: z.ZodDiscriminatedUnion<"type", [z.ZodObject<
|
|
|
733
712
|
};
|
|
734
713
|
rawEvent?: any;
|
|
735
714
|
scenarioSetId?: string | undefined;
|
|
736
|
-
}>, z.ZodObject<{
|
|
737
|
-
timestamp: z.ZodNumber;
|
|
738
|
-
rawEvent: z.ZodOptional<z.ZodAny>;
|
|
739
|
-
batchRunId: z.ZodString;
|
|
740
|
-
scenarioId: z.ZodString;
|
|
741
|
-
scenarioRunId: z.ZodString;
|
|
742
|
-
scenarioSetId: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
715
|
+
}>, z$1.ZodObject<{
|
|
716
|
+
timestamp: z$1.ZodNumber;
|
|
717
|
+
rawEvent: z$1.ZodOptional<z$1.ZodAny>;
|
|
718
|
+
batchRunId: z$1.ZodString;
|
|
719
|
+
scenarioId: z$1.ZodString;
|
|
720
|
+
scenarioRunId: z$1.ZodString;
|
|
721
|
+
scenarioSetId: z$1.ZodDefault<z$1.ZodOptional<z$1.ZodString>>;
|
|
743
722
|
} & {
|
|
744
|
-
type: z.ZodLiteral<ScenarioEventType.RUN_FINISHED>;
|
|
745
|
-
status: z.ZodNativeEnum<typeof ScenarioRunStatus>;
|
|
746
|
-
results: z.ZodNullable<z.ZodOptional<z.ZodObject<{
|
|
747
|
-
verdict: z.ZodNativeEnum<typeof Verdict>;
|
|
748
|
-
reasoning: z.ZodOptional<z.ZodString>;
|
|
749
|
-
metCriteria: z.ZodArray<z.ZodString, "many">;
|
|
750
|
-
unmetCriteria: z.ZodArray<z.ZodString, "many">;
|
|
751
|
-
error: z.ZodOptional<z.ZodString>;
|
|
752
|
-
}, "strip", z.ZodTypeAny, {
|
|
723
|
+
type: z$1.ZodLiteral<ScenarioEventType.RUN_FINISHED>;
|
|
724
|
+
status: z$1.ZodNativeEnum<typeof ScenarioRunStatus>;
|
|
725
|
+
results: z$1.ZodNullable<z$1.ZodOptional<z$1.ZodObject<{
|
|
726
|
+
verdict: z$1.ZodNativeEnum<typeof Verdict>;
|
|
727
|
+
reasoning: z$1.ZodOptional<z$1.ZodString>;
|
|
728
|
+
metCriteria: z$1.ZodArray<z$1.ZodString, "many">;
|
|
729
|
+
unmetCriteria: z$1.ZodArray<z$1.ZodString, "many">;
|
|
730
|
+
error: z$1.ZodOptional<z$1.ZodString>;
|
|
731
|
+
}, "strip", z$1.ZodTypeAny, {
|
|
753
732
|
verdict: Verdict;
|
|
754
733
|
metCriteria: string[];
|
|
755
734
|
unmetCriteria: string[];
|
|
756
|
-
reasoning?: string | undefined;
|
|
757
735
|
error?: string | undefined;
|
|
736
|
+
reasoning?: string | undefined;
|
|
758
737
|
}, {
|
|
759
738
|
verdict: Verdict;
|
|
760
739
|
metCriteria: string[];
|
|
761
740
|
unmetCriteria: string[];
|
|
762
|
-
reasoning?: string | undefined;
|
|
763
741
|
error?: string | undefined;
|
|
742
|
+
reasoning?: string | undefined;
|
|
764
743
|
}>>>;
|
|
765
|
-
}, "strip", z.ZodTypeAny, {
|
|
744
|
+
}, "strip", z$1.ZodTypeAny, {
|
|
766
745
|
type: ScenarioEventType.RUN_FINISHED;
|
|
767
746
|
status: ScenarioRunStatus;
|
|
768
747
|
timestamp: number;
|
|
@@ -775,8 +754,8 @@ declare const scenarioEventSchema: z.ZodDiscriminatedUnion<"type", [z.ZodObject<
|
|
|
775
754
|
verdict: Verdict;
|
|
776
755
|
metCriteria: string[];
|
|
777
756
|
unmetCriteria: string[];
|
|
778
|
-
reasoning?: string | undefined;
|
|
779
757
|
error?: string | undefined;
|
|
758
|
+
reasoning?: string | undefined;
|
|
780
759
|
} | null | undefined;
|
|
781
760
|
}, {
|
|
782
761
|
type: ScenarioEventType.RUN_FINISHED;
|
|
@@ -791,19 +770,19 @@ declare const scenarioEventSchema: z.ZodDiscriminatedUnion<"type", [z.ZodObject<
|
|
|
791
770
|
verdict: Verdict;
|
|
792
771
|
metCriteria: string[];
|
|
793
772
|
unmetCriteria: string[];
|
|
794
|
-
reasoning?: string | undefined;
|
|
795
773
|
error?: string | undefined;
|
|
774
|
+
reasoning?: string | undefined;
|
|
796
775
|
} | null | undefined;
|
|
797
|
-
}>, z.ZodObject<{
|
|
798
|
-
messages: z.ZodArray<z.ZodDiscriminatedUnion<"role", [z.ZodObject<z.objectUtil.extendShape<{
|
|
799
|
-
id: z.ZodString;
|
|
800
|
-
role: z.ZodString;
|
|
801
|
-
content: z.ZodOptional<z.ZodString>;
|
|
802
|
-
name: z.ZodOptional<z.ZodString>;
|
|
776
|
+
}>, z$1.ZodObject<{
|
|
777
|
+
messages: z$1.ZodArray<z$1.ZodDiscriminatedUnion<"role", [z$1.ZodObject<z$1.objectUtil.extendShape<{
|
|
778
|
+
id: z$1.ZodString;
|
|
779
|
+
role: z$1.ZodString;
|
|
780
|
+
content: z$1.ZodOptional<z$1.ZodString>;
|
|
781
|
+
name: z$1.ZodOptional<z$1.ZodString>;
|
|
803
782
|
}, {
|
|
804
|
-
role: z.ZodLiteral<"developer">;
|
|
805
|
-
content: z.ZodString;
|
|
806
|
-
}>, "strip", z.ZodTypeAny, {
|
|
783
|
+
role: z$1.ZodLiteral<"developer">;
|
|
784
|
+
content: z$1.ZodString;
|
|
785
|
+
}>, "strip", z$1.ZodTypeAny, {
|
|
807
786
|
id: string;
|
|
808
787
|
role: "developer";
|
|
809
788
|
content: string;
|
|
@@ -813,15 +792,15 @@ declare const scenarioEventSchema: z.ZodDiscriminatedUnion<"type", [z.ZodObject<
|
|
|
813
792
|
role: "developer";
|
|
814
793
|
content: string;
|
|
815
794
|
name?: string | undefined;
|
|
816
|
-
}>, z.ZodObject<z.objectUtil.extendShape<{
|
|
817
|
-
id: z.ZodString;
|
|
818
|
-
role: z.ZodString;
|
|
819
|
-
content: z.ZodOptional<z.ZodString>;
|
|
820
|
-
name: z.ZodOptional<z.ZodString>;
|
|
795
|
+
}>, z$1.ZodObject<z$1.objectUtil.extendShape<{
|
|
796
|
+
id: z$1.ZodString;
|
|
797
|
+
role: z$1.ZodString;
|
|
798
|
+
content: z$1.ZodOptional<z$1.ZodString>;
|
|
799
|
+
name: z$1.ZodOptional<z$1.ZodString>;
|
|
821
800
|
}, {
|
|
822
|
-
role: z.ZodLiteral<"system">;
|
|
823
|
-
content: z.ZodString;
|
|
824
|
-
}>, "strip", z.ZodTypeAny, {
|
|
801
|
+
role: z$1.ZodLiteral<"system">;
|
|
802
|
+
content: z$1.ZodString;
|
|
803
|
+
}>, "strip", z$1.ZodTypeAny, {
|
|
825
804
|
id: string;
|
|
826
805
|
role: "system";
|
|
827
806
|
content: string;
|
|
@@ -831,28 +810,28 @@ declare const scenarioEventSchema: z.ZodDiscriminatedUnion<"type", [z.ZodObject<
|
|
|
831
810
|
role: "system";
|
|
832
811
|
content: string;
|
|
833
812
|
name?: string | undefined;
|
|
834
|
-
}>, z.ZodObject<z.objectUtil.extendShape<{
|
|
835
|
-
id: z.ZodString;
|
|
836
|
-
role: z.ZodString;
|
|
837
|
-
content: z.ZodOptional<z.ZodString>;
|
|
838
|
-
name: z.ZodOptional<z.ZodString>;
|
|
813
|
+
}>, z$1.ZodObject<z$1.objectUtil.extendShape<{
|
|
814
|
+
id: z$1.ZodString;
|
|
815
|
+
role: z$1.ZodString;
|
|
816
|
+
content: z$1.ZodOptional<z$1.ZodString>;
|
|
817
|
+
name: z$1.ZodOptional<z$1.ZodString>;
|
|
839
818
|
}, {
|
|
840
|
-
role: z.ZodLiteral<"assistant">;
|
|
841
|
-
content: z.ZodOptional<z.ZodString>;
|
|
842
|
-
toolCalls: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
843
|
-
id: z.ZodString;
|
|
844
|
-
type: z.ZodLiteral<"function">;
|
|
845
|
-
function: z.ZodObject<{
|
|
846
|
-
name: z.ZodString;
|
|
847
|
-
arguments: z.ZodString;
|
|
848
|
-
}, "strip", z.ZodTypeAny, {
|
|
819
|
+
role: z$1.ZodLiteral<"assistant">;
|
|
820
|
+
content: z$1.ZodOptional<z$1.ZodString>;
|
|
821
|
+
toolCalls: z$1.ZodOptional<z$1.ZodArray<z$1.ZodObject<{
|
|
822
|
+
id: z$1.ZodString;
|
|
823
|
+
type: z$1.ZodLiteral<"function">;
|
|
824
|
+
function: z$1.ZodObject<{
|
|
825
|
+
name: z$1.ZodString;
|
|
826
|
+
arguments: z$1.ZodString;
|
|
827
|
+
}, "strip", z$1.ZodTypeAny, {
|
|
849
828
|
name: string;
|
|
850
829
|
arguments: string;
|
|
851
830
|
}, {
|
|
852
831
|
name: string;
|
|
853
832
|
arguments: string;
|
|
854
833
|
}>;
|
|
855
|
-
}, "strip", z.ZodTypeAny, {
|
|
834
|
+
}, "strip", z$1.ZodTypeAny, {
|
|
856
835
|
function: {
|
|
857
836
|
name: string;
|
|
858
837
|
arguments: string;
|
|
@@ -867,7 +846,7 @@ declare const scenarioEventSchema: z.ZodDiscriminatedUnion<"type", [z.ZodObject<
|
|
|
867
846
|
type: "function";
|
|
868
847
|
id: string;
|
|
869
848
|
}>, "many">>;
|
|
870
|
-
}>, "strip", z.ZodTypeAny, {
|
|
849
|
+
}>, "strip", z$1.ZodTypeAny, {
|
|
871
850
|
id: string;
|
|
872
851
|
role: "assistant";
|
|
873
852
|
name?: string | undefined;
|
|
@@ -893,15 +872,15 @@ declare const scenarioEventSchema: z.ZodDiscriminatedUnion<"type", [z.ZodObject<
|
|
|
893
872
|
type: "function";
|
|
894
873
|
id: string;
|
|
895
874
|
}[] | undefined;
|
|
896
|
-
}>, z.ZodObject<z.objectUtil.extendShape<{
|
|
897
|
-
id: z.ZodString;
|
|
898
|
-
role: z.ZodString;
|
|
899
|
-
content: z.ZodOptional<z.ZodString>;
|
|
900
|
-
name: z.ZodOptional<z.ZodString>;
|
|
875
|
+
}>, z$1.ZodObject<z$1.objectUtil.extendShape<{
|
|
876
|
+
id: z$1.ZodString;
|
|
877
|
+
role: z$1.ZodString;
|
|
878
|
+
content: z$1.ZodOptional<z$1.ZodString>;
|
|
879
|
+
name: z$1.ZodOptional<z$1.ZodString>;
|
|
901
880
|
}, {
|
|
902
|
-
role: z.ZodLiteral<"user">;
|
|
903
|
-
content: z.ZodString;
|
|
904
|
-
}>, "strip", z.ZodTypeAny, {
|
|
881
|
+
role: z$1.ZodLiteral<"user">;
|
|
882
|
+
content: z$1.ZodString;
|
|
883
|
+
}>, "strip", z$1.ZodTypeAny, {
|
|
905
884
|
id: string;
|
|
906
885
|
role: "user";
|
|
907
886
|
content: string;
|
|
@@ -911,12 +890,12 @@ declare const scenarioEventSchema: z.ZodDiscriminatedUnion<"type", [z.ZodObject<
|
|
|
911
890
|
role: "user";
|
|
912
891
|
content: string;
|
|
913
892
|
name?: string | undefined;
|
|
914
|
-
}>, z.ZodObject<{
|
|
915
|
-
id: z.ZodString;
|
|
916
|
-
content: z.ZodString;
|
|
917
|
-
role: z.ZodLiteral<"tool">;
|
|
918
|
-
toolCallId: z.ZodString;
|
|
919
|
-
}, "strip", z.ZodTypeAny, {
|
|
893
|
+
}>, z$1.ZodObject<{
|
|
894
|
+
id: z$1.ZodString;
|
|
895
|
+
content: z$1.ZodString;
|
|
896
|
+
role: z$1.ZodLiteral<"tool">;
|
|
897
|
+
toolCallId: z$1.ZodString;
|
|
898
|
+
}, "strip", z$1.ZodTypeAny, {
|
|
920
899
|
id: string;
|
|
921
900
|
role: "tool";
|
|
922
901
|
content: string;
|
|
@@ -928,14 +907,14 @@ declare const scenarioEventSchema: z.ZodDiscriminatedUnion<"type", [z.ZodObject<
|
|
|
928
907
|
toolCallId: string;
|
|
929
908
|
}>]>, "many">;
|
|
930
909
|
} & {
|
|
931
|
-
timestamp: z.ZodNumber;
|
|
932
|
-
rawEvent: z.ZodOptional<z.ZodAny>;
|
|
933
|
-
batchRunId: z.ZodString;
|
|
934
|
-
scenarioId: z.ZodString;
|
|
935
|
-
scenarioRunId: z.ZodString;
|
|
936
|
-
scenarioSetId: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
937
|
-
type: z.ZodLiteral<ScenarioEventType.MESSAGE_SNAPSHOT>;
|
|
938
|
-
}, "strip", z.ZodTypeAny, {
|
|
910
|
+
timestamp: z$1.ZodNumber;
|
|
911
|
+
rawEvent: z$1.ZodOptional<z$1.ZodAny>;
|
|
912
|
+
batchRunId: z$1.ZodString;
|
|
913
|
+
scenarioId: z$1.ZodString;
|
|
914
|
+
scenarioRunId: z$1.ZodString;
|
|
915
|
+
scenarioSetId: z$1.ZodDefault<z$1.ZodOptional<z$1.ZodString>>;
|
|
916
|
+
type: z$1.ZodLiteral<ScenarioEventType.MESSAGE_SNAPSHOT>;
|
|
917
|
+
}, "strip", z$1.ZodTypeAny, {
|
|
939
918
|
type: ScenarioEventType.MESSAGE_SNAPSHOT;
|
|
940
919
|
messages: ({
|
|
941
920
|
id: string;
|
|
@@ -1020,7 +999,7 @@ declare const scenarioEventSchema: z.ZodDiscriminatedUnion<"type", [z.ZodObject<
|
|
|
1020
999
|
rawEvent?: any;
|
|
1021
1000
|
scenarioSetId?: string | undefined;
|
|
1022
1001
|
}>]>;
|
|
1023
|
-
type ScenarioEvent = z.infer<typeof scenarioEventSchema>;
|
|
1002
|
+
type ScenarioEvent = z$1.infer<typeof scenarioEventSchema>;
|
|
1024
1003
|
|
|
1025
1004
|
/**
|
|
1026
1005
|
* Manages the execution of a single scenario test.
|
|
@@ -1155,9 +1134,9 @@ declare class ScenarioExecution implements ScenarioExecutionLike {
|
|
|
1155
1134
|
/**
|
|
1156
1135
|
* Gets the complete conversation history as an array of messages.
|
|
1157
1136
|
*
|
|
1158
|
-
* @returns Array of
|
|
1137
|
+
* @returns Array of ModelMessage objects representing the full conversation
|
|
1159
1138
|
*/
|
|
1160
|
-
get messages():
|
|
1139
|
+
get messages(): ModelMessage[];
|
|
1161
1140
|
/**
|
|
1162
1141
|
* Gets the unique identifier for the conversation thread.
|
|
1163
1142
|
* This ID is used to maintain conversation context across multiple runs.
|
|
@@ -1230,7 +1209,7 @@ declare class ScenarioExecution implements ScenarioExecutionLike {
|
|
|
1230
1209
|
* }
|
|
1231
1210
|
* ```
|
|
1232
1211
|
*/
|
|
1233
|
-
step(): Promise<
|
|
1212
|
+
step(): Promise<ModelMessage[] | ScenarioResult>;
|
|
1234
1213
|
private _step;
|
|
1235
1214
|
/**
|
|
1236
1215
|
* Calls a specific agent to generate a response or make a decision.
|
|
@@ -1270,7 +1249,7 @@ declare class ScenarioExecution implements ScenarioExecutionLike {
|
|
|
1270
1249
|
* - "assistant" messages are routed to AGENT role agents
|
|
1271
1250
|
* - Other message types are added directly to the conversation
|
|
1272
1251
|
*
|
|
1273
|
-
* @param message - The
|
|
1252
|
+
* @param message - The ModelMessage to add to the conversation
|
|
1274
1253
|
*
|
|
1275
1254
|
* @example
|
|
1276
1255
|
* ```typescript
|
|
@@ -1280,7 +1259,7 @@ declare class ScenarioExecution implements ScenarioExecutionLike {
|
|
|
1280
1259
|
* });
|
|
1281
1260
|
* ```
|
|
1282
1261
|
*/
|
|
1283
|
-
message(message:
|
|
1262
|
+
message(message: ModelMessage): Promise<void>;
|
|
1284
1263
|
/**
|
|
1285
1264
|
* Executes a user turn in the conversation.
|
|
1286
1265
|
*
|
|
@@ -1290,7 +1269,7 @@ declare class ScenarioExecution implements ScenarioExecutionLike {
|
|
|
1290
1269
|
*
|
|
1291
1270
|
* This method is part of the ScenarioExecutionLike interface used by script steps.
|
|
1292
1271
|
*
|
|
1293
|
-
* @param content - Optional content for the user's message. Can be a string or
|
|
1272
|
+
* @param content - Optional content for the user's message. Can be a string or ModelMessage.
|
|
1294
1273
|
* If not provided, the user simulator agent will generate the content.
|
|
1295
1274
|
*
|
|
1296
1275
|
* @example
|
|
@@ -1301,14 +1280,14 @@ declare class ScenarioExecution implements ScenarioExecutionLike {
|
|
|
1301
1280
|
* // Let user simulator generate content
|
|
1302
1281
|
* await execution.user();
|
|
1303
1282
|
*
|
|
1304
|
-
* // Use a
|
|
1283
|
+
* // Use a ModelMessage object
|
|
1305
1284
|
* await execution.user({
|
|
1306
1285
|
* role: "user",
|
|
1307
1286
|
* content: "Tell me a joke"
|
|
1308
1287
|
* });
|
|
1309
1288
|
* ```
|
|
1310
1289
|
*/
|
|
1311
|
-
user(content?: string |
|
|
1290
|
+
user(content?: string | ModelMessage): Promise<void>;
|
|
1312
1291
|
/**
|
|
1313
1292
|
* Executes an agent turn in the conversation.
|
|
1314
1293
|
*
|
|
@@ -1318,7 +1297,7 @@ declare class ScenarioExecution implements ScenarioExecutionLike {
|
|
|
1318
1297
|
*
|
|
1319
1298
|
* This method is part of the ScenarioExecutionLike interface used by script steps.
|
|
1320
1299
|
*
|
|
1321
|
-
* @param content - Optional content for the agent's response. Can be a string or
|
|
1300
|
+
* @param content - Optional content for the agent's response. Can be a string or ModelMessage.
|
|
1322
1301
|
* If not provided, the agent under test will generate the response.
|
|
1323
1302
|
*
|
|
1324
1303
|
* @example
|
|
@@ -1329,14 +1308,14 @@ declare class ScenarioExecution implements ScenarioExecutionLike {
|
|
|
1329
1308
|
* // Use provided content
|
|
1330
1309
|
* await execution.agent("The weather is sunny today!");
|
|
1331
1310
|
*
|
|
1332
|
-
* // Use a
|
|
1311
|
+
* // Use a ModelMessage object
|
|
1333
1312
|
* await execution.agent({
|
|
1334
1313
|
* role: "assistant",
|
|
1335
1314
|
* content: "I'm here to help you with weather information."
|
|
1336
1315
|
* });
|
|
1337
1316
|
* ```
|
|
1338
1317
|
*/
|
|
1339
|
-
agent(content?: string |
|
|
1318
|
+
agent(content?: string | ModelMessage): Promise<void>;
|
|
1340
1319
|
/**
|
|
1341
1320
|
* Invokes the judge agent to evaluate the current state of the conversation.
|
|
1342
1321
|
*
|
|
@@ -1364,7 +1343,7 @@ declare class ScenarioExecution implements ScenarioExecutionLike {
|
|
|
1364
1343
|
* const result = await execution.judge("Please consider the user's satisfaction level");
|
|
1365
1344
|
* ```
|
|
1366
1345
|
*/
|
|
1367
|
-
judge(content?: string |
|
|
1346
|
+
judge(content?: string | ModelMessage): Promise<ScenarioResult | null>;
|
|
1368
1347
|
/**
|
|
1369
1348
|
* Lets the scenario proceed automatically for a specified number of turns.
|
|
1370
1349
|
*
|