@mastra/core 0.0.0-commonjs-20250227130920
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 +180 -0
- package/dist/agent/index.cjs +1865 -0
- package/dist/agent/index.d.cts +15 -0
- package/dist/agent/index.d.ts +15 -0
- package/dist/agent/index.js +1 -0
- package/dist/base-D90KQ4XI.d.ts +139 -0
- package/dist/base-hs9NDAZ2.d.cts +139 -0
- package/dist/base-nKCMCNrM.d.ts +920 -0
- package/dist/base-nhesrHv3.d.cts +920 -0
- package/dist/base.cjs +138 -0
- package/dist/base.d.cts +6 -0
- package/dist/base.d.ts +6 -0
- package/dist/base.js +1 -0
- package/dist/bundler/index.cjs +158 -0
- package/dist/bundler/index.d.cts +28 -0
- package/dist/bundler/index.d.ts +28 -0
- package/dist/bundler/index.js +1 -0
- package/dist/chunk-33GSTUNK.js +620 -0
- package/dist/chunk-4YRYBCOZ.js +10 -0
- package/dist/chunk-55NFNRKO.js +10 -0
- package/dist/chunk-5XPCMNGW.js +215 -0
- package/dist/chunk-B3M27AMP.js +1479 -0
- package/dist/chunk-BB4KXGBU.js +83 -0
- package/dist/chunk-C6A6W6XS.js +77 -0
- package/dist/chunk-HQ55LN2U.js +318 -0
- package/dist/chunk-KNVTCZW7.js +416 -0
- package/dist/chunk-LH47WVJL.js +61 -0
- package/dist/chunk-NGD2HQYW.js +346 -0
- package/dist/chunk-NUDAZEOG.js +35 -0
- package/dist/chunk-OZ4XVJ6F.js +49 -0
- package/dist/chunk-PHMSPCTC.js +145 -0
- package/dist/chunk-PNZK456O.js +88 -0
- package/dist/chunk-QAAJAHDB.js +37 -0
- package/dist/chunk-RG66XEJT.js +8 -0
- package/dist/chunk-SIFBBGY6.js +190 -0
- package/dist/chunk-SVEAENO7.js +22 -0
- package/dist/chunk-SY5244IR.js +1499 -0
- package/dist/chunk-W5HVJX45.js +402 -0
- package/dist/chunk-WIBGG4X6.js +173 -0
- package/dist/chunk-ZDWFBE5L.js +1 -0
- package/dist/chunk-ZINPRHAN.js +22 -0
- package/dist/deployer/index.cjs +165 -0
- package/dist/deployer/index.d.cts +19 -0
- package/dist/deployer/index.d.ts +19 -0
- package/dist/deployer/index.js +1 -0
- package/dist/eval/index.cjs +110 -0
- package/dist/eval/index.d.cts +28 -0
- package/dist/eval/index.d.ts +28 -0
- package/dist/eval/index.js +1 -0
- package/dist/filter/index.cjs +192 -0
- package/dist/filter/index.d.cts +90 -0
- package/dist/filter/index.d.ts +90 -0
- package/dist/filter/index.js +1 -0
- package/dist/hooks/index.cjs +87 -0
- package/dist/hooks/index.d.cts +33 -0
- package/dist/hooks/index.d.ts +33 -0
- package/dist/hooks/index.js +1 -0
- package/dist/index-mKY1XrpK.d.cts +90 -0
- package/dist/index-mKY1XrpK.d.ts +90 -0
- package/dist/index.cjs +6844 -0
- package/dist/index.d.cts +97 -0
- package/dist/index.d.ts +97 -0
- package/dist/index.js +119 -0
- package/dist/integration/index.cjs +113 -0
- package/dist/integration/index.d.cts +52 -0
- package/dist/integration/index.d.ts +52 -0
- package/dist/integration/index.js +1 -0
- package/dist/llm/index.cjs +2 -0
- package/dist/llm/index.d.cts +15 -0
- package/dist/llm/index.d.ts +15 -0
- package/dist/llm/index.js +1 -0
- package/dist/logger/index.cjs +159 -0
- package/dist/logger/index.d.cts +3 -0
- package/dist/logger/index.d.ts +3 -0
- package/dist/logger/index.js +1 -0
- package/dist/mastra/index.cjs +1741 -0
- package/dist/mastra/index.d.cts +67 -0
- package/dist/mastra/index.d.ts +67 -0
- package/dist/mastra/index.js +1 -0
- package/dist/memory/index.cjs +1907 -0
- package/dist/memory/index.d.cts +15 -0
- package/dist/memory/index.d.ts +15 -0
- package/dist/memory/index.js +1 -0
- package/dist/relevance/index.cjs +1927 -0
- package/dist/relevance/index.d.cts +21 -0
- package/dist/relevance/index.d.ts +21 -0
- package/dist/relevance/index.js +1 -0
- package/dist/storage/index.cjs +361 -0
- package/dist/storage/index.d.cts +15 -0
- package/dist/storage/index.d.ts +15 -0
- package/dist/storage/index.js +2 -0
- package/dist/storage/libsql/index.cjs +770 -0
- package/dist/storage/libsql/index.d.cts +81 -0
- package/dist/storage/libsql/index.d.ts +81 -0
- package/dist/storage/libsql/index.js +1 -0
- package/dist/telemetry/index.cjs +413 -0
- package/dist/telemetry/index.d.cts +51 -0
- package/dist/telemetry/index.d.ts +51 -0
- package/dist/telemetry/index.js +1 -0
- package/dist/telemetry/otel-vendor.cjs +52 -0
- package/dist/telemetry/otel-vendor.d.cts +7 -0
- package/dist/telemetry/otel-vendor.d.ts +7 -0
- package/dist/telemetry/otel-vendor.js +7 -0
- package/dist/tools/index.cjs +25 -0
- package/dist/tools/index.d.cts +29 -0
- package/dist/tools/index.d.ts +29 -0
- package/dist/tools/index.js +1 -0
- package/dist/tts/index.cjs +328 -0
- package/dist/tts/index.d.cts +28 -0
- package/dist/tts/index.d.ts +28 -0
- package/dist/tts/index.js +1 -0
- package/dist/types-m9RryK9a.d.cts +14 -0
- package/dist/types-m9RryK9a.d.ts +14 -0
- package/dist/utils.cjs +179 -0
- package/dist/utils.d.cts +26 -0
- package/dist/utils.d.ts +26 -0
- package/dist/utils.js +1 -0
- package/dist/vector/index.cjs +145 -0
- package/dist/vector/index.d.cts +30 -0
- package/dist/vector/index.d.ts +30 -0
- package/dist/vector/index.js +1 -0
- package/dist/vector/libsql/index.cjs +951 -0
- package/dist/vector/libsql/index.d.cts +29 -0
- package/dist/vector/libsql/index.d.ts +29 -0
- package/dist/vector/libsql/index.js +1 -0
- package/dist/voice/index.cjs +369 -0
- package/dist/voice/index.d.cts +67 -0
- package/dist/voice/index.d.ts +67 -0
- package/dist/voice/index.js +76 -0
- package/dist/workflow-DqQ4pON_.d.cts +84 -0
- package/dist/workflow-Ng_F_Zaf.d.ts +84 -0
- package/dist/workflows/index.cjs +1628 -0
- package/dist/workflows/index.d.cts +48 -0
- package/dist/workflows/index.d.ts +48 -0
- package/dist/workflows/index.js +1 -0
- package/package.json +162 -0
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var promises = require('fs/promises');
|
|
4
|
+
var dotenv = require('dotenv');
|
|
5
|
+
var stream = require('stream');
|
|
6
|
+
var pino = require('pino');
|
|
7
|
+
var pretty = require('pino-pretty');
|
|
8
|
+
|
|
9
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
10
|
+
|
|
11
|
+
var pino__default = /*#__PURE__*/_interopDefault(pino);
|
|
12
|
+
var pretty__default = /*#__PURE__*/_interopDefault(pretty);
|
|
13
|
+
|
|
14
|
+
// src/bundler/index.ts
|
|
15
|
+
var RegisteredLogger = {
|
|
16
|
+
LLM: "LLM"};
|
|
17
|
+
var LogLevel = {
|
|
18
|
+
INFO: "info"};
|
|
19
|
+
var Logger = class {
|
|
20
|
+
logger;
|
|
21
|
+
transports;
|
|
22
|
+
constructor(options = {}) {
|
|
23
|
+
this.transports = options.transports || {};
|
|
24
|
+
const transportsAry = Object.entries(this.transports);
|
|
25
|
+
this.logger = pino__default.default(
|
|
26
|
+
{
|
|
27
|
+
name: options.name || "app",
|
|
28
|
+
level: options.level || LogLevel.INFO
|
|
29
|
+
},
|
|
30
|
+
options.overrideDefaultTransports ? options?.transports?.default : transportsAry.length === 0 ? pretty__default.default({
|
|
31
|
+
colorize: true,
|
|
32
|
+
levelFirst: true,
|
|
33
|
+
ignore: "pid,hostname",
|
|
34
|
+
colorizeObjects: true,
|
|
35
|
+
translateTime: "SYS:standard",
|
|
36
|
+
singleLine: false
|
|
37
|
+
}) : pino__default.default.multistream([
|
|
38
|
+
...transportsAry.map(([_, transport]) => ({
|
|
39
|
+
stream: transport,
|
|
40
|
+
level: options.level || LogLevel.INFO
|
|
41
|
+
})),
|
|
42
|
+
{
|
|
43
|
+
stream: pretty__default.default({
|
|
44
|
+
colorize: true,
|
|
45
|
+
levelFirst: true,
|
|
46
|
+
ignore: "pid,hostname",
|
|
47
|
+
colorizeObjects: true,
|
|
48
|
+
translateTime: "SYS:standard",
|
|
49
|
+
singleLine: false
|
|
50
|
+
}),
|
|
51
|
+
level: options.level || LogLevel.INFO
|
|
52
|
+
}
|
|
53
|
+
])
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
debug(message, args = {}) {
|
|
57
|
+
this.logger.debug(args, message);
|
|
58
|
+
}
|
|
59
|
+
info(message, args = {}) {
|
|
60
|
+
this.logger.info(args, message);
|
|
61
|
+
}
|
|
62
|
+
warn(message, args = {}) {
|
|
63
|
+
this.logger.warn(args, message);
|
|
64
|
+
}
|
|
65
|
+
error(message, args = {}) {
|
|
66
|
+
this.logger.error(args, message);
|
|
67
|
+
}
|
|
68
|
+
// Stream creation for process output handling
|
|
69
|
+
createStream() {
|
|
70
|
+
return new stream.Transform({
|
|
71
|
+
transform: (chunk, _encoding, callback) => {
|
|
72
|
+
const line = chunk.toString().trim();
|
|
73
|
+
if (line) {
|
|
74
|
+
this.info(line);
|
|
75
|
+
}
|
|
76
|
+
callback(null, chunk);
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
async getLogs(transportId) {
|
|
81
|
+
if (!transportId || !this.transports[transportId]) {
|
|
82
|
+
return [];
|
|
83
|
+
}
|
|
84
|
+
return this.transports[transportId].getLogs();
|
|
85
|
+
}
|
|
86
|
+
async getLogsByRunId({ runId, transportId }) {
|
|
87
|
+
return this.transports[transportId]?.getLogsByRunId({ runId });
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
function createLogger(options) {
|
|
91
|
+
return new Logger(options);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// src/base.ts
|
|
95
|
+
var MastraBase = class {
|
|
96
|
+
component = RegisteredLogger.LLM;
|
|
97
|
+
logger;
|
|
98
|
+
name;
|
|
99
|
+
telemetry;
|
|
100
|
+
constructor({ component, name }) {
|
|
101
|
+
this.component = component || RegisteredLogger.LLM;
|
|
102
|
+
this.name = name;
|
|
103
|
+
this.logger = createLogger({ name: `${this.component} - ${this.name}` });
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Set the logger for the agent
|
|
107
|
+
* @param logger
|
|
108
|
+
*/
|
|
109
|
+
__setLogger(logger) {
|
|
110
|
+
this.logger = logger;
|
|
111
|
+
this.logger.debug(`Logger updated [component=${this.component}] [name=${this.name}]`);
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Set the telemetry for the
|
|
115
|
+
* @param telemetry
|
|
116
|
+
*/
|
|
117
|
+
__setTelemetry(telemetry) {
|
|
118
|
+
this.telemetry = telemetry;
|
|
119
|
+
this.logger.debug(`Telemetry updated [component=${this.component}] [tracer=${this.telemetry.tracer}]`);
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Get the telemetry on the vector
|
|
123
|
+
* @returns telemetry
|
|
124
|
+
*/
|
|
125
|
+
__getTelemetry() {
|
|
126
|
+
return this.telemetry;
|
|
127
|
+
}
|
|
128
|
+
/*
|
|
129
|
+
get experimental_telemetry config
|
|
130
|
+
*/
|
|
131
|
+
get experimental_telemetry() {
|
|
132
|
+
return this.telemetry ? {
|
|
133
|
+
// tracer: this.telemetry.tracer,
|
|
134
|
+
tracer: this.telemetry.getBaggageTracer(),
|
|
135
|
+
isEnabled: !!this.telemetry.tracer
|
|
136
|
+
} : void 0;
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
// src/bundler/index.ts
|
|
141
|
+
var MastraBundler = class extends MastraBase {
|
|
142
|
+
constructor({ name, component = "BUNDLER" }) {
|
|
143
|
+
super({ component, name });
|
|
144
|
+
}
|
|
145
|
+
async loadEnvVars() {
|
|
146
|
+
const envVars = /* @__PURE__ */ new Map();
|
|
147
|
+
for (const file of await this.getEnvFiles()) {
|
|
148
|
+
const content = await promises.readFile(file, "utf-8");
|
|
149
|
+
const config = dotenv.parse(content);
|
|
150
|
+
Object.entries(config).forEach(([key, value]) => {
|
|
151
|
+
envVars.set(key, value);
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
return envVars;
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
// src/deployer/index.ts
|
|
159
|
+
var MastraDeployer = class extends MastraBundler {
|
|
160
|
+
constructor({ name }) {
|
|
161
|
+
super({ component: "DEPLOYER", name });
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
exports.MastraDeployer = MastraDeployer;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { MastraBundler, IBundler } from '../bundler/index.cjs';
|
|
2
|
+
import '../base-hs9NDAZ2.cjs';
|
|
3
|
+
import '@opentelemetry/api';
|
|
4
|
+
import '../index-mKY1XrpK.cjs';
|
|
5
|
+
import 'stream';
|
|
6
|
+
import 'pino';
|
|
7
|
+
import '@opentelemetry/sdk-trace-base';
|
|
8
|
+
|
|
9
|
+
interface IDeployer extends IBundler {
|
|
10
|
+
deploy(outputDirectory: string): Promise<void>;
|
|
11
|
+
}
|
|
12
|
+
declare abstract class MastraDeployer extends MastraBundler implements IDeployer {
|
|
13
|
+
constructor({ name }: {
|
|
14
|
+
name: string;
|
|
15
|
+
});
|
|
16
|
+
abstract deploy(outputDirectory: string): Promise<void>;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export { type IDeployer, MastraDeployer };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { MastraBundler, IBundler } from '../bundler/index.js';
|
|
2
|
+
import '../base-D90KQ4XI.js';
|
|
3
|
+
import '@opentelemetry/api';
|
|
4
|
+
import '../index-mKY1XrpK.js';
|
|
5
|
+
import 'stream';
|
|
6
|
+
import 'pino';
|
|
7
|
+
import '@opentelemetry/sdk-trace-base';
|
|
8
|
+
|
|
9
|
+
interface IDeployer extends IBundler {
|
|
10
|
+
deploy(outputDirectory: string): Promise<void>;
|
|
11
|
+
}
|
|
12
|
+
declare abstract class MastraDeployer extends MastraBundler implements IDeployer {
|
|
13
|
+
constructor({ name }: {
|
|
14
|
+
name: string;
|
|
15
|
+
});
|
|
16
|
+
abstract deploy(outputDirectory: string): Promise<void>;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export { type IDeployer, MastraDeployer };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { MastraDeployer } from '../chunk-4YRYBCOZ.js';
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/eval/metric.ts
|
|
4
|
+
var Metric = class {
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
// src/hooks/mitt.ts
|
|
8
|
+
function mitt(all) {
|
|
9
|
+
all = all || /* @__PURE__ */ new Map();
|
|
10
|
+
return {
|
|
11
|
+
/**
|
|
12
|
+
* A Map of event names to registered handler functions.
|
|
13
|
+
*/
|
|
14
|
+
all,
|
|
15
|
+
/**
|
|
16
|
+
* Register an event handler for the given type.
|
|
17
|
+
* @param {string|symbol} type Type of event to listen for, or `'*'` for all events
|
|
18
|
+
* @param {Function} handler Function to call in response to given event
|
|
19
|
+
* @memberOf mitt
|
|
20
|
+
*/
|
|
21
|
+
on(type, handler) {
|
|
22
|
+
const handlers = all.get(type);
|
|
23
|
+
if (handlers) {
|
|
24
|
+
handlers.push(handler);
|
|
25
|
+
} else {
|
|
26
|
+
all.set(type, [handler]);
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
/**
|
|
30
|
+
* Remove an event handler for the given type.
|
|
31
|
+
* If `handler` is omitted, all handlers of the given type are removed.
|
|
32
|
+
* @param {string|symbol} type Type of event to unregister `handler` from (`'*'` to remove a wildcard handler)
|
|
33
|
+
* @param {Function} [handler] Handler function to remove
|
|
34
|
+
* @memberOf mitt
|
|
35
|
+
*/
|
|
36
|
+
off(type, handler) {
|
|
37
|
+
const handlers = all.get(type);
|
|
38
|
+
if (handlers) {
|
|
39
|
+
if (handler) {
|
|
40
|
+
handlers.splice(handlers.indexOf(handler) >>> 0, 1);
|
|
41
|
+
} else {
|
|
42
|
+
all.set(type, []);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
/**
|
|
47
|
+
* Invoke all handlers for the given type.
|
|
48
|
+
* If present, `'*'` handlers are invoked after type-matched handlers.
|
|
49
|
+
*
|
|
50
|
+
* Note: Manually firing '*' handlers is not supported.
|
|
51
|
+
*
|
|
52
|
+
* @param {string|symbol} type The event type to invoke
|
|
53
|
+
* @param {Any} [evt] Any value (object is recommended and powerful), passed to each handler
|
|
54
|
+
* @memberOf mitt
|
|
55
|
+
*/
|
|
56
|
+
emit(type, evt) {
|
|
57
|
+
let handlers = all.get(type);
|
|
58
|
+
if (handlers) {
|
|
59
|
+
handlers.slice().map((handler) => {
|
|
60
|
+
handler(evt);
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
handlers = all.get("*");
|
|
64
|
+
if (handlers) {
|
|
65
|
+
handlers.slice().map((handler) => {
|
|
66
|
+
handler(type, evt);
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// src/hooks/index.ts
|
|
74
|
+
var hooks = mitt();
|
|
75
|
+
function executeHook(hook, data) {
|
|
76
|
+
setImmediate(() => {
|
|
77
|
+
hooks.emit(hook, data);
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// src/eval/evaluation.ts
|
|
82
|
+
async function evaluate({
|
|
83
|
+
agentName,
|
|
84
|
+
input,
|
|
85
|
+
metric,
|
|
86
|
+
output,
|
|
87
|
+
runId,
|
|
88
|
+
globalRunId,
|
|
89
|
+
testInfo,
|
|
90
|
+
instructions
|
|
91
|
+
}) {
|
|
92
|
+
const runIdToUse = runId || crypto.randomUUID();
|
|
93
|
+
const metricResult = await metric.measure(input.toString(), output);
|
|
94
|
+
const traceObject = {
|
|
95
|
+
input: input.toString(),
|
|
96
|
+
output,
|
|
97
|
+
result: metricResult,
|
|
98
|
+
agentName,
|
|
99
|
+
metricName: metric.constructor.name,
|
|
100
|
+
instructions,
|
|
101
|
+
globalRunId,
|
|
102
|
+
runId: runIdToUse,
|
|
103
|
+
testInfo
|
|
104
|
+
};
|
|
105
|
+
executeHook("onEvaluation" /* ON_EVALUATION */, traceObject);
|
|
106
|
+
return metricResult;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
exports.Metric = Metric;
|
|
110
|
+
exports.evaluate = evaluate;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { a as Metric, T as TestInfo, M as MetricResult } from '../types-m9RryK9a.cjs';
|
|
2
|
+
import { A as Agent } from '../base-nhesrHv3.cjs';
|
|
3
|
+
import 'ai';
|
|
4
|
+
import '../base-hs9NDAZ2.cjs';
|
|
5
|
+
import '@opentelemetry/api';
|
|
6
|
+
import '../index-mKY1XrpK.cjs';
|
|
7
|
+
import 'stream';
|
|
8
|
+
import 'pino';
|
|
9
|
+
import '@opentelemetry/sdk-trace-base';
|
|
10
|
+
import 'sift';
|
|
11
|
+
import 'zod';
|
|
12
|
+
import 'json-schema';
|
|
13
|
+
import '../vector/index.cjs';
|
|
14
|
+
import '../voice/index.cjs';
|
|
15
|
+
import '../tts/index.cjs';
|
|
16
|
+
|
|
17
|
+
declare function evaluate<T extends Agent>({ agentName, input, metric, output, runId, globalRunId, testInfo, instructions, }: {
|
|
18
|
+
agentName: string;
|
|
19
|
+
input: Parameters<T['generate']>[0];
|
|
20
|
+
metric: Metric;
|
|
21
|
+
output: string;
|
|
22
|
+
globalRunId: string;
|
|
23
|
+
runId?: string;
|
|
24
|
+
testInfo?: TestInfo;
|
|
25
|
+
instructions: string;
|
|
26
|
+
}): Promise<MetricResult>;
|
|
27
|
+
|
|
28
|
+
export { Metric, MetricResult, TestInfo, evaluate };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { a as Metric, T as TestInfo, M as MetricResult } from '../types-m9RryK9a.js';
|
|
2
|
+
import { A as Agent } from '../base-nKCMCNrM.js';
|
|
3
|
+
import 'ai';
|
|
4
|
+
import '../base-D90KQ4XI.js';
|
|
5
|
+
import '@opentelemetry/api';
|
|
6
|
+
import '../index-mKY1XrpK.js';
|
|
7
|
+
import 'stream';
|
|
8
|
+
import 'pino';
|
|
9
|
+
import '@opentelemetry/sdk-trace-base';
|
|
10
|
+
import 'sift';
|
|
11
|
+
import 'zod';
|
|
12
|
+
import 'json-schema';
|
|
13
|
+
import '../vector/index.js';
|
|
14
|
+
import '../voice/index.js';
|
|
15
|
+
import '../tts/index.js';
|
|
16
|
+
|
|
17
|
+
declare function evaluate<T extends Agent>({ agentName, input, metric, output, runId, globalRunId, testInfo, instructions, }: {
|
|
18
|
+
agentName: string;
|
|
19
|
+
input: Parameters<T['generate']>[0];
|
|
20
|
+
metric: Metric;
|
|
21
|
+
output: string;
|
|
22
|
+
globalRunId: string;
|
|
23
|
+
runId?: string;
|
|
24
|
+
testInfo?: TestInfo;
|
|
25
|
+
instructions: string;
|
|
26
|
+
}): Promise<MetricResult>;
|
|
27
|
+
|
|
28
|
+
export { Metric, MetricResult, TestInfo, evaluate };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Metric, evaluate } from '../chunk-NUDAZEOG.js';
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/filter/base.ts
|
|
4
|
+
var BaseFilterTranslator = class _BaseFilterTranslator {
|
|
5
|
+
/**
|
|
6
|
+
* Operator type checks
|
|
7
|
+
*/
|
|
8
|
+
isOperator(key) {
|
|
9
|
+
return key.startsWith("$");
|
|
10
|
+
}
|
|
11
|
+
static BASIC_OPERATORS = ["$eq", "$ne"];
|
|
12
|
+
static NUMERIC_OPERATORS = ["$gt", "$gte", "$lt", "$lte"];
|
|
13
|
+
static ARRAY_OPERATORS = ["$in", "$nin", "$all", "$elemMatch"];
|
|
14
|
+
static LOGICAL_OPERATORS = ["$and", "$or", "$not", "$nor"];
|
|
15
|
+
static ELEMENT_OPERATORS = ["$exists"];
|
|
16
|
+
static REGEX_OPERATORS = ["$regex", "$options"];
|
|
17
|
+
static DEFAULT_OPERATORS = {
|
|
18
|
+
logical: _BaseFilterTranslator.LOGICAL_OPERATORS,
|
|
19
|
+
basic: _BaseFilterTranslator.BASIC_OPERATORS,
|
|
20
|
+
numeric: _BaseFilterTranslator.NUMERIC_OPERATORS,
|
|
21
|
+
array: _BaseFilterTranslator.ARRAY_OPERATORS,
|
|
22
|
+
element: _BaseFilterTranslator.ELEMENT_OPERATORS,
|
|
23
|
+
regex: _BaseFilterTranslator.REGEX_OPERATORS
|
|
24
|
+
};
|
|
25
|
+
isLogicalOperator(key) {
|
|
26
|
+
return _BaseFilterTranslator.DEFAULT_OPERATORS.logical.includes(key);
|
|
27
|
+
}
|
|
28
|
+
isBasicOperator(key) {
|
|
29
|
+
return _BaseFilterTranslator.DEFAULT_OPERATORS.basic.includes(key);
|
|
30
|
+
}
|
|
31
|
+
isNumericOperator(key) {
|
|
32
|
+
return _BaseFilterTranslator.DEFAULT_OPERATORS.numeric.includes(key);
|
|
33
|
+
}
|
|
34
|
+
isArrayOperator(key) {
|
|
35
|
+
return _BaseFilterTranslator.DEFAULT_OPERATORS.array.includes(key);
|
|
36
|
+
}
|
|
37
|
+
isElementOperator(key) {
|
|
38
|
+
return _BaseFilterTranslator.DEFAULT_OPERATORS.element.includes(key);
|
|
39
|
+
}
|
|
40
|
+
isRegexOperator(key) {
|
|
41
|
+
return _BaseFilterTranslator.DEFAULT_OPERATORS.regex.includes(key);
|
|
42
|
+
}
|
|
43
|
+
isFieldOperator(key) {
|
|
44
|
+
return this.isOperator(key) && !this.isLogicalOperator(key);
|
|
45
|
+
}
|
|
46
|
+
isCustomOperator(key) {
|
|
47
|
+
const support = this.getSupportedOperators();
|
|
48
|
+
return support.custom?.includes(key) ?? false;
|
|
49
|
+
}
|
|
50
|
+
getSupportedOperators() {
|
|
51
|
+
return _BaseFilterTranslator.DEFAULT_OPERATORS;
|
|
52
|
+
}
|
|
53
|
+
isValidOperator(key) {
|
|
54
|
+
const support = this.getSupportedOperators();
|
|
55
|
+
const allSupported = Object.values(support).flat();
|
|
56
|
+
return allSupported.includes(key);
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Value normalization for comparison operators
|
|
60
|
+
*/
|
|
61
|
+
normalizeComparisonValue(value) {
|
|
62
|
+
if (value instanceof Date) {
|
|
63
|
+
return value.toISOString();
|
|
64
|
+
}
|
|
65
|
+
if (typeof value === "number" && Object.is(value, -0)) {
|
|
66
|
+
return 0;
|
|
67
|
+
}
|
|
68
|
+
return value;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Helper method to simulate $all operator using $and + $eq when needed.
|
|
72
|
+
* Some vector stores don't support $all natively.
|
|
73
|
+
*/
|
|
74
|
+
simulateAllOperator(field, values) {
|
|
75
|
+
return {
|
|
76
|
+
$and: values.map((value) => ({
|
|
77
|
+
[field]: { $in: [this.normalizeComparisonValue(value)] }
|
|
78
|
+
}))
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Utility functions for type checking
|
|
83
|
+
*/
|
|
84
|
+
isPrimitive(value) {
|
|
85
|
+
return value === null || value === void 0 || typeof value === "string" || typeof value === "number" || typeof value === "boolean";
|
|
86
|
+
}
|
|
87
|
+
isRegex(value) {
|
|
88
|
+
return value instanceof RegExp;
|
|
89
|
+
}
|
|
90
|
+
isEmpty(obj) {
|
|
91
|
+
return obj === null || obj === void 0 || typeof obj === "object" && Object.keys(obj).length === 0;
|
|
92
|
+
}
|
|
93
|
+
static ErrorMessages = {
|
|
94
|
+
UNSUPPORTED_OPERATOR: (op) => `Unsupported operator: ${op}`,
|
|
95
|
+
INVALID_LOGICAL_OPERATOR_LOCATION: (op, path) => `Logical operator ${op} cannot be used at field level: ${path}`,
|
|
96
|
+
NOT_REQUIRES_OBJECT: `$not operator requires an object`,
|
|
97
|
+
NOT_CANNOT_BE_EMPTY: `$not operator cannot be empty`,
|
|
98
|
+
INVALID_LOGICAL_OPERATOR_CONTENT: (path) => `Logical operators must contain field conditions, not direct operators: ${path}`,
|
|
99
|
+
INVALID_TOP_LEVEL_OPERATOR: (op) => `Invalid top-level operator: ${op}`,
|
|
100
|
+
ELEM_MATCH_REQUIRES_OBJECT: `$elemMatch requires an object with conditions`
|
|
101
|
+
};
|
|
102
|
+
/**
|
|
103
|
+
* Helper to handle array value normalization consistently
|
|
104
|
+
*/
|
|
105
|
+
normalizeArrayValues(values) {
|
|
106
|
+
return values.map((value) => this.normalizeComparisonValue(value));
|
|
107
|
+
}
|
|
108
|
+
validateFilter(filter) {
|
|
109
|
+
const validation = this.validateFilterSupport(filter);
|
|
110
|
+
if (!validation.supported) {
|
|
111
|
+
throw new Error(validation.messages.join(", "));
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Validates if a filter structure is supported by the specific vector DB
|
|
116
|
+
* and returns detailed validation information.
|
|
117
|
+
*/
|
|
118
|
+
validateFilterSupport(node, path = "") {
|
|
119
|
+
const messages = [];
|
|
120
|
+
if (this.isPrimitive(node) || this.isEmpty(node)) {
|
|
121
|
+
return { supported: true, messages: [] };
|
|
122
|
+
}
|
|
123
|
+
if (Array.isArray(node)) {
|
|
124
|
+
const arrayResults = node.map((item) => this.validateFilterSupport(item, path));
|
|
125
|
+
const arrayMessages = arrayResults.flatMap((r) => r.messages);
|
|
126
|
+
return {
|
|
127
|
+
supported: arrayResults.every((r) => r.supported),
|
|
128
|
+
messages: arrayMessages
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
const nodeObj = node;
|
|
132
|
+
let isSupported = true;
|
|
133
|
+
for (const [key, value] of Object.entries(nodeObj)) {
|
|
134
|
+
const newPath = path ? `${path}.${key}` : key;
|
|
135
|
+
if (this.isOperator(key)) {
|
|
136
|
+
if (!this.isValidOperator(key)) {
|
|
137
|
+
isSupported = false;
|
|
138
|
+
messages.push(_BaseFilterTranslator.ErrorMessages.UNSUPPORTED_OPERATOR(key));
|
|
139
|
+
continue;
|
|
140
|
+
}
|
|
141
|
+
if (!path && !this.isLogicalOperator(key)) {
|
|
142
|
+
isSupported = false;
|
|
143
|
+
messages.push(_BaseFilterTranslator.ErrorMessages.INVALID_TOP_LEVEL_OPERATOR(key));
|
|
144
|
+
continue;
|
|
145
|
+
}
|
|
146
|
+
if (key === "$elemMatch" && (typeof value !== "object" || Array.isArray(value))) {
|
|
147
|
+
isSupported = false;
|
|
148
|
+
messages.push(_BaseFilterTranslator.ErrorMessages.ELEM_MATCH_REQUIRES_OBJECT);
|
|
149
|
+
continue;
|
|
150
|
+
}
|
|
151
|
+
if (this.isLogicalOperator(key)) {
|
|
152
|
+
if (key === "$not") {
|
|
153
|
+
if (Array.isArray(value) || typeof value !== "object") {
|
|
154
|
+
isSupported = false;
|
|
155
|
+
messages.push(_BaseFilterTranslator.ErrorMessages.NOT_REQUIRES_OBJECT);
|
|
156
|
+
continue;
|
|
157
|
+
}
|
|
158
|
+
if (this.isEmpty(value)) {
|
|
159
|
+
isSupported = false;
|
|
160
|
+
messages.push(_BaseFilterTranslator.ErrorMessages.NOT_CANNOT_BE_EMPTY);
|
|
161
|
+
continue;
|
|
162
|
+
}
|
|
163
|
+
continue;
|
|
164
|
+
}
|
|
165
|
+
if (path && !this.isLogicalOperator(path.split(".").pop())) {
|
|
166
|
+
isSupported = false;
|
|
167
|
+
messages.push(_BaseFilterTranslator.ErrorMessages.INVALID_LOGICAL_OPERATOR_LOCATION(key, newPath));
|
|
168
|
+
continue;
|
|
169
|
+
}
|
|
170
|
+
if (Array.isArray(value)) {
|
|
171
|
+
const hasDirectOperators = value.some(
|
|
172
|
+
(item) => typeof item === "object" && Object.keys(item).length === 1 && this.isFieldOperator(Object.keys(item)[0])
|
|
173
|
+
);
|
|
174
|
+
if (hasDirectOperators) {
|
|
175
|
+
isSupported = false;
|
|
176
|
+
messages.push(_BaseFilterTranslator.ErrorMessages.INVALID_LOGICAL_OPERATOR_CONTENT(newPath));
|
|
177
|
+
continue;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
const nestedValidation = this.validateFilterSupport(value, newPath);
|
|
183
|
+
if (!nestedValidation.supported) {
|
|
184
|
+
isSupported = false;
|
|
185
|
+
messages.push(...nestedValidation.messages);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
return { supported: isSupported, messages };
|
|
189
|
+
}
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
exports.BaseFilterTranslator = BaseFilterTranslator;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
type BasicOperator = '$eq' | '$ne';
|
|
2
|
+
type NumericOperator = '$gt' | '$gte' | '$lt' | '$lte';
|
|
3
|
+
type LogicalOperator = '$and' | '$not' | '$nor' | '$or';
|
|
4
|
+
type ArrayOperator = '$all' | '$in' | '$nin' | '$elemMatch';
|
|
5
|
+
type ElementOperator = '$exists';
|
|
6
|
+
type RegexOperator = '$regex' | '$options';
|
|
7
|
+
type QueryOperator = BasicOperator | NumericOperator | LogicalOperator | ArrayOperator | ElementOperator | RegexOperator;
|
|
8
|
+
type OperatorCondition = {
|
|
9
|
+
[K in QueryOperator]?: any;
|
|
10
|
+
};
|
|
11
|
+
type FieldCondition = OperatorCondition | any;
|
|
12
|
+
type Filter = {
|
|
13
|
+
[field: string]: FieldCondition | Filter;
|
|
14
|
+
};
|
|
15
|
+
type OperatorSupport = {
|
|
16
|
+
logical?: LogicalOperator[];
|
|
17
|
+
array?: ArrayOperator[];
|
|
18
|
+
basic?: BasicOperator[];
|
|
19
|
+
numeric?: NumericOperator[];
|
|
20
|
+
element?: ElementOperator[];
|
|
21
|
+
regex?: RegexOperator[];
|
|
22
|
+
custom?: string[];
|
|
23
|
+
};
|
|
24
|
+
declare abstract class BaseFilterTranslator {
|
|
25
|
+
abstract translate(filter: Filter): unknown;
|
|
26
|
+
/**
|
|
27
|
+
* Operator type checks
|
|
28
|
+
*/
|
|
29
|
+
protected isOperator(key: string): key is QueryOperator;
|
|
30
|
+
protected static readonly BASIC_OPERATORS: BasicOperator[];
|
|
31
|
+
protected static readonly NUMERIC_OPERATORS: NumericOperator[];
|
|
32
|
+
protected static readonly ARRAY_OPERATORS: ArrayOperator[];
|
|
33
|
+
protected static readonly LOGICAL_OPERATORS: LogicalOperator[];
|
|
34
|
+
protected static readonly ELEMENT_OPERATORS: ElementOperator[];
|
|
35
|
+
protected static readonly REGEX_OPERATORS: RegexOperator[];
|
|
36
|
+
static readonly DEFAULT_OPERATORS: {
|
|
37
|
+
logical: LogicalOperator[];
|
|
38
|
+
basic: BasicOperator[];
|
|
39
|
+
numeric: NumericOperator[];
|
|
40
|
+
array: ArrayOperator[];
|
|
41
|
+
element: "$exists"[];
|
|
42
|
+
regex: RegexOperator[];
|
|
43
|
+
};
|
|
44
|
+
protected isLogicalOperator(key: string): key is LogicalOperator;
|
|
45
|
+
protected isBasicOperator(key: string): key is BasicOperator;
|
|
46
|
+
protected isNumericOperator(key: string): key is NumericOperator;
|
|
47
|
+
protected isArrayOperator(key: string): key is ArrayOperator;
|
|
48
|
+
protected isElementOperator(key: string): key is ElementOperator;
|
|
49
|
+
protected isRegexOperator(key: string): key is RegexOperator;
|
|
50
|
+
protected isFieldOperator(key: string): key is QueryOperator;
|
|
51
|
+
protected isCustomOperator(key: string): boolean;
|
|
52
|
+
protected getSupportedOperators(): OperatorSupport;
|
|
53
|
+
protected isValidOperator(key: string): boolean;
|
|
54
|
+
/**
|
|
55
|
+
* Value normalization for comparison operators
|
|
56
|
+
*/
|
|
57
|
+
protected normalizeComparisonValue(value: any): any;
|
|
58
|
+
/**
|
|
59
|
+
* Helper method to simulate $all operator using $and + $eq when needed.
|
|
60
|
+
* Some vector stores don't support $all natively.
|
|
61
|
+
*/
|
|
62
|
+
protected simulateAllOperator(field: string, values: any[]): Filter;
|
|
63
|
+
/**
|
|
64
|
+
* Utility functions for type checking
|
|
65
|
+
*/
|
|
66
|
+
protected isPrimitive(value: any): boolean;
|
|
67
|
+
protected isRegex(value: any): boolean;
|
|
68
|
+
protected isEmpty(obj: any): boolean;
|
|
69
|
+
protected static readonly ErrorMessages: {
|
|
70
|
+
readonly UNSUPPORTED_OPERATOR: (op: string) => string;
|
|
71
|
+
readonly INVALID_LOGICAL_OPERATOR_LOCATION: (op: string, path: string) => string;
|
|
72
|
+
readonly NOT_REQUIRES_OBJECT: "$not operator requires an object";
|
|
73
|
+
readonly NOT_CANNOT_BE_EMPTY: "$not operator cannot be empty";
|
|
74
|
+
readonly INVALID_LOGICAL_OPERATOR_CONTENT: (path: string) => string;
|
|
75
|
+
readonly INVALID_TOP_LEVEL_OPERATOR: (op: string) => string;
|
|
76
|
+
readonly ELEM_MATCH_REQUIRES_OBJECT: "$elemMatch requires an object with conditions";
|
|
77
|
+
};
|
|
78
|
+
/**
|
|
79
|
+
* Helper to handle array value normalization consistently
|
|
80
|
+
*/
|
|
81
|
+
protected normalizeArrayValues(values: any[]): any[];
|
|
82
|
+
protected validateFilter(filter: Filter): void;
|
|
83
|
+
/**
|
|
84
|
+
* Validates if a filter structure is supported by the specific vector DB
|
|
85
|
+
* and returns detailed validation information.
|
|
86
|
+
*/
|
|
87
|
+
private validateFilterSupport;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export { type ArrayOperator, BaseFilterTranslator, type BasicOperator, type ElementOperator, type FieldCondition, type Filter, type LogicalOperator, type NumericOperator, type OperatorCondition, type OperatorSupport, type QueryOperator, type RegexOperator };
|