@langwatch/scenario 0.2.13 → 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/README.md +36 -9
- package/dist/index.d.mts +433 -256
- package/dist/index.d.ts +433 -256
- package/dist/index.js +2221 -516
- package/dist/index.mjs +2611 -303
- package/dist/integrations/vitest/config.mjs +0 -2
- package/dist/integrations/vitest/reporter.js +36 -11
- package/dist/integrations/vitest/reporter.mjs +159 -8
- package/dist/integrations/vitest/setup-global.mjs +0 -2
- package/dist/integrations/vitest/setup.js +85 -53
- package/dist/integrations/vitest/setup.mjs +619 -18
- package/package.json +46 -30
- package/dist/chunk-6SKQWXT7.mjs +0 -528
- package/dist/chunk-7P6ASYW6.mjs +0 -9
- package/dist/chunk-OL4RFXV4.mjs +0 -133
package/dist/chunk-OL4RFXV4.mjs
DELETED
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
// src/config/env.ts
|
|
2
|
-
import { z } from "zod";
|
|
3
|
-
|
|
4
|
-
// src/config/log-levels.ts
|
|
5
|
-
var LogLevel = /* @__PURE__ */ ((LogLevel2) => {
|
|
6
|
-
LogLevel2["ERROR"] = "ERROR";
|
|
7
|
-
LogLevel2["WARN"] = "WARN";
|
|
8
|
-
LogLevel2["INFO"] = "INFO";
|
|
9
|
-
LogLevel2["DEBUG"] = "DEBUG";
|
|
10
|
-
return LogLevel2;
|
|
11
|
-
})(LogLevel || {});
|
|
12
|
-
var LOG_LEVELS = Object.values(LogLevel);
|
|
13
|
-
|
|
14
|
-
// src/config/env.ts
|
|
15
|
-
var envSchema = z.object({
|
|
16
|
-
/**
|
|
17
|
-
* LangWatch API key for event reporting.
|
|
18
|
-
* If not provided, events will not be sent to LangWatch.
|
|
19
|
-
*/
|
|
20
|
-
LANGWATCH_API_KEY: z.string().optional(),
|
|
21
|
-
/**
|
|
22
|
-
* LangWatch endpoint URL for event reporting.
|
|
23
|
-
* Defaults to the production LangWatch endpoint.
|
|
24
|
-
*/
|
|
25
|
-
LANGWATCH_ENDPOINT: z.string().url().optional().default("https://app.langwatch.ai"),
|
|
26
|
-
/**
|
|
27
|
-
* Disables simulation report info messages when set to any truthy value.
|
|
28
|
-
* Useful for CI/CD environments or when you want cleaner output.
|
|
29
|
-
*/
|
|
30
|
-
SCENARIO_DISABLE_SIMULATION_REPORT_INFO: z.string().optional().transform((val) => Boolean(val)),
|
|
31
|
-
/**
|
|
32
|
-
* Node environment - affects logging and behavior.
|
|
33
|
-
* Defaults to 'development' if not specified.
|
|
34
|
-
*/
|
|
35
|
-
NODE_ENV: z.enum(["development", "production", "test"]).default("development"),
|
|
36
|
-
/**
|
|
37
|
-
* Case-insensitive log level for the scenario package.
|
|
38
|
-
* Defaults to 'info' if not specified.
|
|
39
|
-
*/
|
|
40
|
-
LOG_LEVEL: z.string().toUpperCase().pipe(z.nativeEnum(LogLevel)).optional().default("INFO" /* INFO */),
|
|
41
|
-
/**
|
|
42
|
-
* Scenario batch run ID.
|
|
43
|
-
* If not provided, a random ID will be generated.
|
|
44
|
-
*/
|
|
45
|
-
SCENARIO_BATCH_RUN_ID: z.string().optional()
|
|
46
|
-
});
|
|
47
|
-
function getEnv() {
|
|
48
|
-
return envSchema.parse(process.env);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
// src/utils/logger.ts
|
|
52
|
-
var Logger = class _Logger {
|
|
53
|
-
constructor(context) {
|
|
54
|
-
this.context = context;
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* Creates a logger with context (e.g., class name)
|
|
58
|
-
*/
|
|
59
|
-
static create(context) {
|
|
60
|
-
return new _Logger(context);
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* Returns the current log level from environment.
|
|
64
|
-
* Uses a getter for clarity and idiomatic usage.
|
|
65
|
-
*/
|
|
66
|
-
get LOG_LEVEL() {
|
|
67
|
-
return getEnv().LOG_LEVEL;
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* Returns the index of the given log level in the LOG_LEVELS array.
|
|
71
|
-
* @param level - The log level to get the index for.
|
|
72
|
-
* @returns The index of the log level in the LOG_LEVELS array.
|
|
73
|
-
*/
|
|
74
|
-
getLogLevelIndexFor(level) {
|
|
75
|
-
return LOG_LEVELS.indexOf(level);
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Checks if logging should occur based on LOG_LEVEL env var
|
|
79
|
-
*/
|
|
80
|
-
shouldLog(level) {
|
|
81
|
-
const currentLevelIndex = this.getLogLevelIndexFor(this.LOG_LEVEL);
|
|
82
|
-
const requestedLevelIndex = this.getLogLevelIndexFor(level);
|
|
83
|
-
return currentLevelIndex >= 0 && requestedLevelIndex <= currentLevelIndex;
|
|
84
|
-
}
|
|
85
|
-
formatMessage(message) {
|
|
86
|
-
return this.context ? `[${this.context}] ${message}` : message;
|
|
87
|
-
}
|
|
88
|
-
error(message, data) {
|
|
89
|
-
if (this.shouldLog("ERROR" /* ERROR */)) {
|
|
90
|
-
const formattedMessage = this.formatMessage(message);
|
|
91
|
-
if (data) {
|
|
92
|
-
console.error(formattedMessage, data);
|
|
93
|
-
} else {
|
|
94
|
-
console.error(formattedMessage);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
warn(message, data) {
|
|
99
|
-
if (this.shouldLog("WARN" /* WARN */)) {
|
|
100
|
-
const formattedMessage = this.formatMessage(message);
|
|
101
|
-
if (data) {
|
|
102
|
-
console.warn(formattedMessage, data);
|
|
103
|
-
} else {
|
|
104
|
-
console.warn(formattedMessage);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
info(message, data) {
|
|
109
|
-
if (this.shouldLog("INFO" /* INFO */)) {
|
|
110
|
-
const formattedMessage = this.formatMessage(message);
|
|
111
|
-
if (data) {
|
|
112
|
-
console.info(formattedMessage, data);
|
|
113
|
-
} else {
|
|
114
|
-
console.info(formattedMessage);
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
debug(message, data) {
|
|
119
|
-
if (this.shouldLog("DEBUG" /* DEBUG */)) {
|
|
120
|
-
const formattedMessage = this.formatMessage(message);
|
|
121
|
-
if (data) {
|
|
122
|
-
console.log(formattedMessage, data);
|
|
123
|
-
} else {
|
|
124
|
-
console.log(formattedMessage);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
};
|
|
129
|
-
|
|
130
|
-
export {
|
|
131
|
-
getEnv,
|
|
132
|
-
Logger
|
|
133
|
-
};
|