@botpress/vai 0.0.1 → 0.0.2-beta.1

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/tsup.config.ts CHANGED
@@ -2,15 +2,9 @@ import { defineConfig } from 'tsup'
2
2
 
3
3
  export default defineConfig({
4
4
  entry: ['src/index.ts'],
5
- splitting: false,
6
- format: ['esm', 'cjs'],
7
- sourcemap: true,
8
- keepNames: true,
9
5
  dts: true,
10
- platform: 'browser',
6
+ outDir: 'dist',
7
+ platform: 'neutral',
11
8
  clean: true,
12
- shims: true,
13
- external: ['react', 'react-dom'],
14
- bundle: true,
15
- plugins: [],
9
+ bundle: false
16
10
  })
package/dist/index.cjs DELETED
@@ -1,503 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __defProps = Object.defineProperties;
5
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
7
- var __getOwnPropNames = Object.getOwnPropertyNames;
8
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
9
- var __getProtoOf = Object.getPrototypeOf;
10
- var __hasOwnProp = Object.prototype.hasOwnProperty;
11
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
12
- var __typeError = (msg) => {
13
- throw TypeError(msg);
14
- };
15
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
16
- var __spreadValues = (a, b) => {
17
- for (var prop in b || (b = {}))
18
- if (__hasOwnProp.call(b, prop))
19
- __defNormalProp(a, prop, b[prop]);
20
- if (__getOwnPropSymbols)
21
- for (var prop of __getOwnPropSymbols(b)) {
22
- if (__propIsEnum.call(b, prop))
23
- __defNormalProp(a, prop, b[prop]);
24
- }
25
- return a;
26
- };
27
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
28
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
29
- var __export = (target, all) => {
30
- for (var name in all)
31
- __defProp(target, name, { get: all[name], enumerable: true });
32
- };
33
- var __copyProps = (to, from, except, desc) => {
34
- if (from && typeof from === "object" || typeof from === "function") {
35
- for (let key of __getOwnPropNames(from))
36
- if (!__hasOwnProp.call(to, key) && key !== except)
37
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
38
- }
39
- return to;
40
- };
41
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
42
- // If the importer is in node compatibility mode or this is not an ESM
43
- // file that has been converted to a CommonJS file using a Babel-
44
- // compatible transform (i.e. "__esModule" has not been set), then set
45
- // "default" to the CommonJS "module.exports" for node compatibility.
46
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
47
- mod
48
- ));
49
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
50
- var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
51
- var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
52
- var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
53
- var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
54
-
55
- // src/index.ts
56
- var index_exports = {};
57
- __export(index_exports, {
58
- check: () => check,
59
- compare: () => compare,
60
- extract: () => extract,
61
- filter: () => filter,
62
- rate: () => rate,
63
- setEvaluator: () => setEvaluator,
64
- setupClient: () => setupClient
65
- });
66
- module.exports = __toCommonJS(index_exports);
67
-
68
- // src/utils/zui.ts
69
- var import_sdk = __toESM(require("@botpress/sdk"), 1);
70
- var z = import_sdk.default.z;
71
-
72
- // src/task/compare.ts
73
- var import_suite = require("vitest/suite");
74
-
75
- // src/utils/deferred.ts
76
- var _Deferred = class _Deferred {
77
- constructor() {
78
- this.promise = new Promise((resolve, reject) => {
79
- this._resolve = resolve;
80
- this._reject = reject;
81
- });
82
- }
83
- resolve(value) {
84
- this._resolve(value);
85
- }
86
- reject(reason) {
87
- this._reject(reason);
88
- }
89
- };
90
- __name(_Deferred, "Deferred");
91
- var Deferred = _Deferred;
92
-
93
- // src/task/compare.ts
94
- var scenarioId = z.string().trim().min(1, "Scenario ID/name must not be empty").max(50, "Scenario ID/name is too long");
95
- var ScenarioLike = z.union([
96
- scenarioId,
97
- z.object({ name: scenarioId }).passthrough(),
98
- z.object({ id: scenarioId }).passthrough()
99
- ]);
100
- var getScenarioName = /* @__PURE__ */ __name((scenario) => typeof scenario === "string" ? scenario : "name" in scenario ? scenario == null ? void 0 : scenario.name : scenario == null ? void 0 : scenario.id, "getScenarioName");
101
- var scenarioArgs = z.array(ScenarioLike).min(2, "You need at least two scenarios to compare").max(10, "You can only compare up to 10 scenarios").refine((scenarios) => {
102
- const set = /* @__PURE__ */ new Set();
103
- scenarios.forEach((scenario) => set.add(getScenarioName(scenario)));
104
- return set.size === scenarios.length;
105
- }, "Scenarios names must be unique");
106
- function compare(name, scenarios, fn) {
107
- scenarios = scenarioArgs.parse(scenarios);
108
- return (0, import_suite.createTaskCollector)((_name, fn2, timeout) => {
109
- const currentSuite = (0, import_suite.getCurrentSuite)();
110
- let completedCount = 0;
111
- const finished = new Deferred();
112
- for (const scenario of scenarios) {
113
- const key = getScenarioName(scenario);
114
- currentSuite.task(key, {
115
- meta: {
116
- scenario: key,
117
- isVaiTest: true
118
- },
119
- handler: /* @__PURE__ */ __name(async (context) => {
120
- const extendedContext = Object.freeze({
121
- scenario
122
- });
123
- context.onTestFinished(() => {
124
- if (++completedCount === scenarios.length) {
125
- finished.resolve();
126
- }
127
- });
128
- await fn2(__spreadValues(__spreadValues({}, context), extendedContext));
129
- }, "handler"),
130
- timeout: timeout != null ? timeout : 1e4
131
- });
132
- }
133
- })(name, fn);
134
- }
135
- __name(compare, "compare");
136
-
137
- // src/context.ts
138
- var import_vitest = require("vitest");
139
- var import_suite2 = require("vitest/suite");
140
- var getTestMetadata = /* @__PURE__ */ __name(() => {
141
- var _a;
142
- const test = (0, import_suite2.getCurrentTest)();
143
- return (_a = test == null ? void 0 : test.meta) != null ? _a : {
144
- isVaiTest: false
145
- };
146
- }, "getTestMetadata");
147
- var _client, _wrapError;
148
- var _VaiContext = class _VaiContext {
149
- constructor() {
150
- __privateAdd(this, _client, null);
151
- __privateAdd(this, _wrapError, false);
152
- }
153
- get wrapError() {
154
- return __privateGet(this, _wrapError);
155
- }
156
- get client() {
157
- if (!__privateGet(this, _client)) {
158
- throw new Error("Botpress client is not set");
159
- }
160
- return __privateGet(this, _client);
161
- }
162
- get evaluatorModel() {
163
- var _a;
164
- return (_a = getTestMetadata().evaluatorModel) != null ? _a : "openai__gpt-4o-mini-2024-07-18";
165
- }
166
- get scenario() {
167
- return getTestMetadata().scenario;
168
- }
169
- get isVaiTest() {
170
- return getTestMetadata().isVaiTest;
171
- }
172
- setClient(cognitive) {
173
- __privateSet(this, _client, cognitive);
174
- }
175
- swallowErrors() {
176
- if (!(0, import_suite2.getCurrentTest)()) {
177
- throw new Error("cancelBail is a Vitest hook and must be called within a test");
178
- }
179
- __privateSet(this, _wrapError, true);
180
- (0, import_vitest.onTestFinished)(() => {
181
- __privateSet(this, _wrapError, false);
182
- });
183
- }
184
- };
185
- _client = new WeakMap();
186
- _wrapError = new WeakMap();
187
- __name(_VaiContext, "VaiContext");
188
- var VaiContext = _VaiContext;
189
- var Context = new VaiContext();
190
-
191
- // src/utils/asyncAssertion.ts
192
- var import_vitest2 = require("vitest");
193
- var import_suite3 = require("vitest/suite");
194
- var _AsyncExpectError = class _AsyncExpectError extends Error {
195
- constructor(message, output) {
196
- super(message);
197
- this.output = output;
198
- this.name = "AsyncExpectError";
199
- }
200
- };
201
- __name(_AsyncExpectError, "AsyncExpectError");
202
- var AsyncExpectError = _AsyncExpectError;
203
- var getErrorMessages = /* @__PURE__ */ __name((e) => {
204
- if (e instanceof Error) {
205
- return e.message;
206
- } else if (typeof e === "string") {
207
- return e;
208
- } else if (typeof e === "object" && e !== null) {
209
- return JSON.stringify(e);
210
- }
211
- return `Unknown error: ${e}`;
212
- }, "getErrorMessages");
213
- var asyncExpect = /* @__PURE__ */ __name((output, assertion) => {
214
- var _a, _b;
215
- const promise = output.then((x) => {
216
- try {
217
- assertion((0, import_vitest2.expect)(x.result, x.reason));
218
- } catch (e) {
219
- if (Context.wrapError) {
220
- return new AsyncExpectError(getErrorMessages(e), x);
221
- }
222
- throw e;
223
- }
224
- return x;
225
- });
226
- (_b = (_a = (0, import_suite3.getCurrentTest)()).promises) != null ? _b : _a.promises = [];
227
- (0, import_suite3.getCurrentTest)().promises.push(promise);
228
- return promise;
229
- }, "asyncExpect");
230
-
231
- // src/utils/predictJson.ts
232
- var import_json5 = __toESM(require("json5"), 1);
233
- var nonEmptyString = z.string().trim().min(1);
234
- var nonEmptyObject = z.object({}).passthrough().refine((value) => Object.keys(value).length > 0, {
235
- message: "Expected a non-empty object"
236
- });
237
- var Input = nonEmptyString.or(nonEmptyObject).or(z.array(z.any()));
238
- var Output = z.object({
239
- reason: nonEmptyString.describe("A human-readable explanation of the result"),
240
- result: z.any().describe(
241
- "Your best guess at the output according to the instructions provided, rooted in the context of the input and the reason above"
242
- )
243
- });
244
- var Example = z.object({
245
- input: Input,
246
- output: Output
247
- });
248
- var Options = z.object({
249
- systemMessage: z.string(),
250
- examples: z.array(Example).default([]),
251
- input: Input,
252
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
253
- outputSchema: z.custom((value) => typeof value === "object" && value !== null && "_def" in value),
254
- model: z.string()
255
- });
256
- var isValidExample = /* @__PURE__ */ __name((outputSchema) => (example) => Input.safeParse(example.input).success && Output.safeParse(example.output).success && outputSchema.safeParse(example.output.result).success, "isValidExample");
257
- async function predictJson(_options) {
258
- var _a, _b;
259
- const options = Options.parse(_options);
260
- const [integration, model] = options.model.split("__");
261
- if (!(model == null ? void 0 : model.length)) {
262
- throw new Error("Invalid model");
263
- }
264
- const exampleMessages = options.examples.filter(isValidExample(options.outputSchema)).flatMap(({ input, output: output2 }) => [
265
- { role: "user", content: JSON.stringify(input, null, 2) },
266
- { role: "assistant", content: JSON.stringify(output2, null, 2) }
267
- ]);
268
- const outputSchema = Output.extend({
269
- result: options.outputSchema.describe(Output.shape.result.description)
270
- });
271
- const result = await Context.client.callAction({
272
- type: `${integration}:generateContent`,
273
- input: {
274
- systemPrompt: `
275
- ${options.systemMessage}
276
-
277
- ---
278
- Please generate a JSON response with the following format:
279
- \`\`\`typescript
280
- ${await outputSchema.toTypescriptAsync()}
281
- \`\`\`
282
- `.trim(),
283
- messages: [
284
- ...exampleMessages,
285
- {
286
- role: "user",
287
- content: JSON.stringify(options.input, null, 2)
288
- }
289
- ],
290
- temperature: 0,
291
- responseFormat: "json_object",
292
- model: { id: model }
293
- }
294
- });
295
- const output = result.output;
296
- if (!output.choices.length || typeof ((_b = (_a = output.choices) == null ? void 0 : _a[0]) == null ? void 0 : _b.content) !== "string") {
297
- throw new Error("Invalid response from the model");
298
- }
299
- const json = output.choices[0].content.trim();
300
- if (!json.length) {
301
- throw new Error("No response from the model");
302
- }
303
- return outputSchema.parse(import_json5.default.parse(json));
304
- }
305
- __name(predictJson, "predictJson");
306
-
307
- // src/assertions/extension.ts
308
- var import_json52 = __toESM(require("json5"), 1);
309
- var import_vitest3 = require("vitest");
310
- var import_suite4 = require("vitest/suite");
311
- var toAssertion = /* @__PURE__ */ __name((promise) => {
312
- return {
313
- then: promise.then.bind(promise),
314
- value: promise.then((value) => value.result)
315
- };
316
- }, "toAssertion");
317
- var makeToMatchInlineSnapshot = /* @__PURE__ */ __name((promise) => async (expected) => {
318
- const stack = new Error().stack.split("\n")[2];
319
- const newStack = `
320
- at __INLINE_SNAPSHOT__ (node:internal/process/task_queues:1:1)
321
- at randomLine (node:internal/process/task_queues:1:1)
322
- ${stack}
323
- `.trim();
324
- const obj = import_json52.default.parse(expected != null ? expected : '""');
325
- const expectation = asyncExpect(promise, (expect3) => expect3.toMatchObject(obj)).catch(() => {
326
- });
327
- try {
328
- (0, import_vitest3.expect)((await promise).result).toMatchObject(obj);
329
- } catch (err) {
330
- const newError = new Error();
331
- newError.stack = newStack;
332
- import_vitest3.expect.getState().snapshotState.match({
333
- isInline: true,
334
- received: (await promise).result,
335
- testName: (0, import_suite4.getCurrentTest)().name,
336
- error: newError,
337
- inlineSnapshot: expected
338
- });
339
- }
340
- return expectation;
341
- }, "makeToMatchInlineSnapshot");
342
-
343
- // src/assertions/check.ts
344
- function check(value, condition, options) {
345
- var _a;
346
- const promise = predictJson({
347
- systemMessage: `Check that the value meets the condition: ${condition}`,
348
- examples: (_a = options == null ? void 0 : options.examples) == null ? void 0 : _a.map(({ value: value2, reason, expected }) => ({
349
- input: value2,
350
- output: { reason, result: expected }
351
- })),
352
- outputSchema: z.boolean(),
353
- model: Context.evaluatorModel,
354
- input: value
355
- });
356
- return __spreadProps(__spreadValues({}, toAssertion(promise)), {
357
- toBe: /* @__PURE__ */ __name((expected) => asyncExpect(promise, (expect3) => expect3.toEqual(expected)), "toBe"),
358
- toMatchInlineSnapshot: makeToMatchInlineSnapshot(promise)
359
- });
360
- }
361
- __name(check, "check");
362
-
363
- // src/assertions/extract.ts
364
- function extract(value, shape, options) {
365
- var _a;
366
- const additionalMessage = (options == null ? void 0 : options.description) ? `
367
- In order to extract the right information, follow these instructions:
368
- ${options.description}
369
- ` : "";
370
- const promise = predictJson({
371
- systemMessage: "From the given input, extract the required information into the requested format." + additionalMessage.trim(),
372
- examples: (_a = options == null ? void 0 : options.examples) == null ? void 0 : _a.map(({ value: value2, reason, extracted }) => ({
373
- input: value2,
374
- output: { reason, result: extracted }
375
- })),
376
- outputSchema: shape,
377
- model: Context.evaluatorModel,
378
- input: value
379
- });
380
- return __spreadProps(__spreadValues({}, toAssertion(promise)), {
381
- toBe: /* @__PURE__ */ __name((expected) => asyncExpect(promise, (expect3) => expect3.toEqual(expected)), "toBe"),
382
- toMatchObject: /* @__PURE__ */ __name((expected) => asyncExpect(promise, (expect3) => expect3.toMatchObject(expected)), "toMatchObject"),
383
- toMatchInlineSnapshot: makeToMatchInlineSnapshot(promise)
384
- });
385
- }
386
- __name(extract, "extract");
387
-
388
- // src/assertions/filter.ts
389
- function filter(values, condition, options) {
390
- var _a, _b;
391
- const mappedValues = values.map(
392
- (_, idx) => z.object({
393
- index: z.literal(idx),
394
- reason: z.string(),
395
- keep: z.boolean()
396
- })
397
- );
398
- const input = values.map((value, idx) => ({
399
- index: idx,
400
- value
401
- }));
402
- const schema = z.tuple(mappedValues).describe(
403
- "An array of the objects with the index and a boolean value indicating if the object should be kept or not"
404
- );
405
- const promise = predictJson({
406
- systemMessage: `
407
- Based on the following qualification criteria, you need to filter the given list of objects.
408
- Citeria: ${condition}
409
-
410
- ---
411
- You need to return an array of objects with the index and a boolean value indicating if the object should be kept or not.
412
- `.trim(),
413
- examples: (options == null ? void 0 : options.examples) ? [
414
- {
415
- input: (_a = options == null ? void 0 : options.examples) == null ? void 0 : _a.map((v, index) => ({
416
- index,
417
- value: v.value
418
- })),
419
- output: {
420
- reason: "Here are some examples",
421
- result: (_b = options == null ? void 0 : options.examples) == null ? void 0 : _b.map((v, idx) => ({
422
- index: idx,
423
- reason: v.reason,
424
- keep: v.keep
425
- }))
426
- }
427
- }
428
- ] : void 0,
429
- outputSchema: schema,
430
- model: Context.evaluatorModel,
431
- input
432
- }).then((x) => {
433
- const results = schema.parse(x.result);
434
- return {
435
- result: values.filter((_, idx) => {
436
- var _a2;
437
- return (_a2 = results.find((r) => r.index === idx)) == null ? void 0 : _a2.keep;
438
- }),
439
- reason: x.reason
440
- };
441
- });
442
- return __spreadProps(__spreadValues({}, toAssertion(promise)), {
443
- toBe: /* @__PURE__ */ __name((expected) => asyncExpect(promise, (expect3) => expect3.toEqual(expected)), "toBe"),
444
- toMatchInlineSnapshot: makeToMatchInlineSnapshot(promise),
445
- toHaveNoneFiltered: /* @__PURE__ */ __name(() => asyncExpect(promise, (expect3) => expect3.toEqual(values)), "toHaveNoneFiltered"),
446
- toHaveSomeFiltered: /* @__PURE__ */ __name(() => asyncExpect(promise, (expect3) => expect3.not.toEqual(values)), "toHaveSomeFiltered"),
447
- toBeEmpty: /* @__PURE__ */ __name(() => asyncExpect(promise, (expect3) => expect3.toHaveLength(0)), "toBeEmpty"),
448
- length: {
449
- toBe: /* @__PURE__ */ __name((expected) => asyncExpect(promise, (expect3) => expect3.toHaveLength(expected)), "toBe"),
450
- toBeGreaterThanOrEqual: /* @__PURE__ */ __name((expected) => asyncExpect(promise, (expect3) => expect3.length.greaterThanOrEqual(expected)), "toBeGreaterThanOrEqual"),
451
- toBeLessThanOrEqual: /* @__PURE__ */ __name((expected) => asyncExpect(promise, (expect3) => expect3.length.lessThanOrEqual(expected)), "toBeLessThanOrEqual"),
452
- toBeBetween: /* @__PURE__ */ __name((min, max) => asyncExpect(promise, (expect3) => expect3.length.within(min, max)), "toBeBetween")
453
- }
454
- });
455
- }
456
- __name(filter, "filter");
457
-
458
- // src/assertions/rate.ts
459
- function rate(value, condition, options) {
460
- var _a;
461
- const schema = z.number().min(1).max(5).describe("Rating score, higher is better (1 is the worst, 5 is the best)");
462
- const promise = predictJson({
463
- systemMessage: `Based on the following qualification criteria, you need to rate the given situation from a score of 1 to 5.
464
- Scoring: 1 is the worst score, 5 is the best score possible.
465
- Criteria: ${condition}`,
466
- examples: (_a = options == null ? void 0 : options.examples) == null ? void 0 : _a.map(({ value: value2, reason, rating }) => ({
467
- input: value2,
468
- output: { reason, result: rating }
469
- })),
470
- outputSchema: schema,
471
- model: Context.evaluatorModel,
472
- input: value
473
- }).then((x) => {
474
- return {
475
- result: typeof x.result === "number" ? x.result : parseInt(x.result, 10),
476
- reason: x.reason
477
- };
478
- });
479
- return __spreadProps(__spreadValues({}, toAssertion(promise)), {
480
- toBe: /* @__PURE__ */ __name((expected) => asyncExpect(promise, (expect3) => expect3.toEqual(expected)), "toBe"),
481
- toMatchInlineSnapshot: makeToMatchInlineSnapshot(promise),
482
- toBeGreaterThanOrEqual: /* @__PURE__ */ __name((expected) => asyncExpect(promise, (expect3) => expect3.toBeGreaterThanOrEqual(expected)), "toBeGreaterThanOrEqual"),
483
- toBeLessThanOrEqual: /* @__PURE__ */ __name((expected) => asyncExpect(promise, (expect3) => expect3.toBeLessThanOrEqual(expected)), "toBeLessThanOrEqual")
484
- });
485
- }
486
- __name(rate, "rate");
487
-
488
- // src/hooks/setEvaluator.ts
489
- var import_suite5 = require("vitest/suite");
490
- var setEvaluator = /* @__PURE__ */ __name((model) => {
491
- const test = (0, import_suite5.getCurrentTest)();
492
- if (!test) {
493
- throw new Error("setEvaluator is a Vitest hook and must be called within a test");
494
- }
495
- const meta = test.meta;
496
- meta.evaluatorModel = model;
497
- }, "setEvaluator");
498
-
499
- // src/hooks/setupClient.ts
500
- var setupClient = /* @__PURE__ */ __name((client) => {
501
- Context.setClient(client);
502
- }, "setupClient");
503
- //# sourceMappingURL=index.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/index.ts","../src/utils/zui.ts","../src/task/compare.ts","../src/utils/deferred.ts","../src/context.ts","../src/utils/asyncAssertion.ts","../src/utils/predictJson.ts","../src/assertions/extension.ts","../src/assertions/check.ts","../src/assertions/extract.ts","../src/assertions/filter.ts","../src/assertions/rate.ts","../src/hooks/setEvaluator.ts","../src/hooks/setupClient.ts"],"sourcesContent":["export { compare } from './task/compare'\n\nexport { check } from './assertions/check'\nexport { extract } from './assertions/extract'\nexport { filter } from './assertions/filter'\nexport { rate } from './assertions/rate'\n\nexport { setEvaluator } from './hooks/setEvaluator'\nexport { setupClient } from './hooks/setupClient'\n","import sdk from '@botpress/sdk'\n\nexport const z = sdk.z\n","import { z as Z } from '@botpress/sdk'\nimport { z } from '../utils/zui'\n\nimport { TestFunction } from 'vitest'\nimport { createTaskCollector, getCurrentSuite } from 'vitest/suite'\nimport { TestMetadata } from '../context'\nimport { Deferred } from '../utils/deferred'\n\nconst scenarioId = z\n .string()\n .trim()\n .min(1, 'Scenario ID/name must not be empty')\n .max(50, 'Scenario ID/name is too long')\n\nexport type ScenarioLike = Z.infer<typeof ScenarioLike>\nconst ScenarioLike = z.union([\n scenarioId,\n z.object({ name: scenarioId }).passthrough(),\n z.object({ id: scenarioId }).passthrough()\n])\n\nconst getScenarioName = (scenario: ScenarioLike) =>\n (typeof scenario === 'string' ? scenario : 'name' in scenario ? scenario?.name : scenario?.id) as string\n\nconst scenarioArgs = z\n .array(ScenarioLike)\n .min(2, 'You need at least two scenarios to compare')\n .max(10, 'You can only compare up to 10 scenarios')\n .refine((scenarios) => {\n const set = new Set<string>()\n scenarios.forEach((scenario) => set.add(getScenarioName(scenario)))\n return set.size === scenarios.length\n }, 'Scenarios names must be unique')\n\nexport function compare<T extends ReadonlyArray<ScenarioLike>>(\n name: string | Function,\n scenarios: T,\n fn?: TestFunction<{\n scenario: T[number]\n }>\n) {\n scenarios = scenarioArgs.parse(scenarios) as unknown as T\n\n return createTaskCollector((_name, fn, timeout) => {\n const currentSuite = getCurrentSuite()\n\n let completedCount = 0\n const finished = new Deferred<void>()\n\n for (const scenario of scenarios) {\n const key = getScenarioName(scenario)\n\n currentSuite.task(key, {\n meta: {\n scenario: key,\n isVaiTest: true\n } satisfies TestMetadata,\n handler: async (context) => {\n const extendedContext = Object.freeze({\n scenario\n })\n context.onTestFinished(() => {\n if (++completedCount === scenarios.length) {\n finished.resolve()\n }\n })\n\n await fn({ ...context, ...extendedContext })\n },\n timeout: timeout ?? 10_000\n })\n }\n })(name, fn)\n}\n","export class Deferred<T> {\n promise: Promise<T>\n private _resolve!: (value: T | PromiseLike<T>) => void\n private _reject!: (reason?: unknown) => void\n\n constructor() {\n this.promise = new Promise<T>((resolve, reject) => {\n this._resolve = resolve\n this._reject = reject\n })\n }\n\n resolve(value: T | PromiseLike<T>): void {\n this._resolve(value)\n }\n\n reject(reason?: unknown): void {\n this._reject(reason)\n }\n}\n","import type { Client } from '@botpress/client'\nimport { onTestFinished } from 'vitest'\nimport { getCurrentTest } from 'vitest/suite'\nimport { Models } from './models'\n\nexport type EvaluatorModel = (typeof Models)[number]['id']\n\nexport type TestMetadata = {\n isVaiTest: boolean\n scenario?: string\n evaluatorModel?: EvaluatorModel\n}\n\nconst getTestMetadata = (): TestMetadata => {\n const test = getCurrentTest()\n return (test?.meta ?? {\n isVaiTest: false\n }) as TestMetadata\n}\n\nclass VaiContext {\n #client: Client | null = null\n #wrapError = false\n\n get wrapError() {\n return this.#wrapError\n }\n\n get client() {\n if (!this.#client) {\n throw new Error('Botpress client is not set')\n }\n\n return this.#client\n }\n\n get evaluatorModel(): EvaluatorModel {\n return getTestMetadata().evaluatorModel ?? 'openai__gpt-4o-mini-2024-07-18'\n }\n\n get scenario() {\n return getTestMetadata().scenario\n }\n\n get isVaiTest() {\n return getTestMetadata().isVaiTest\n }\n\n setClient(cognitive: Client) {\n this.#client = cognitive\n }\n\n swallowErrors() {\n if (!getCurrentTest()) {\n throw new Error('cancelBail is a Vitest hook and must be called within a test')\n }\n\n this.#wrapError = true\n onTestFinished(() => {\n this.#wrapError = false\n })\n }\n}\n\nexport const Context = new VaiContext()\n","import { Assertion, expect } from 'vitest'\nimport { getCurrentTest } from 'vitest/suite'\nimport { Context } from '../context'\nimport { Output } from './predictJson'\n\nexport class AsyncExpectError<T> extends Error {\n constructor(message: string, public readonly output: Output<T>) {\n super(message)\n this.name = 'AsyncExpectError'\n }\n}\n\nconst getErrorMessages = (e: unknown): string => {\n if (e instanceof Error) {\n return e.message\n } else if (typeof e === 'string') {\n return e\n } else if (typeof e === 'object' && e !== null) {\n return JSON.stringify(e)\n }\n\n return `Unknown error: ${e}`\n}\n\nexport const asyncExpect = <T>(output: Promise<Output<T>>, assertion: (assert: Assertion<T>) => void) => {\n const promise = output.then((x) => {\n try {\n assertion(expect(x.result, x.reason))\n } catch (e: unknown) {\n if (Context.wrapError) {\n return new AsyncExpectError<T>(getErrorMessages(e), x)\n }\n throw e\n }\n return x\n })\n getCurrentTest()!.promises ??= []\n getCurrentTest()!.promises!.push(promise)\n return promise\n}\n","import { z } from '../utils/zui'\nimport { type ZodSchema, z as Z } from '@botpress/sdk'\nimport JSON5 from 'json5'\nimport { Context } from '../context'\nimport { llm } from '../sdk-interfaces/llm/generateContent'\n\nconst nonEmptyString = z.string().trim().min(1)\nconst nonEmptyObject = z\n .object({})\n .passthrough()\n .refine((value) => Object.keys(value).length > 0, {\n message: 'Expected a non-empty object'\n })\n\nexport type Input = Z.infer<typeof Input>\nconst Input = nonEmptyString.or(nonEmptyObject).or(z.array(z.any()))\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type Output<T = any> = Z.infer<typeof Output> & { result: T }\nconst Output = z.object({\n reason: nonEmptyString.describe('A human-readable explanation of the result'),\n result: z\n .any()\n .describe(\n 'Your best guess at the output according to the instructions provided, rooted in the context of the input and the reason above'\n )\n})\n\ntype Example = Z.infer<typeof Example>\nconst Example = z.object({\n input: Input,\n output: Output\n})\n\ntype InputOptions<T extends ZodSchema = ZodSchema> = Z.input<typeof Options> & { outputSchema: T }\ntype Options = Z.infer<typeof Options>\nconst Options = z.object({\n systemMessage: z.string(),\n examples: z.array(Example).default([]),\n input: Input,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n outputSchema: z.custom<ZodSchema<any>>((value) => typeof value === 'object' && value !== null && '_def' in value),\n model: z.string()\n})\n\ntype Message = {\n role: 'user' | 'assistant' | 'system'\n content: string\n}\n\nconst isValidExample =\n (outputSchema: ZodSchema) =>\n (example: Example): example is Example =>\n Input.safeParse(example.input).success &&\n Output.safeParse(example.output).success &&\n outputSchema.safeParse(example.output.result).success\n\nexport async function predictJson<T extends ZodSchema>(_options: InputOptions<T>): Promise<Output<Z.infer<T>>> {\n const options = Options.parse(_options)\n const [integration, model] = options.model.split('__')\n\n if (!model?.length) {\n throw new Error('Invalid model')\n }\n\n const exampleMessages = options.examples\n .filter(isValidExample(options.outputSchema))\n .flatMap(({ input, output }) => [\n { role: 'user', content: JSON.stringify(input, null, 2) } satisfies Message,\n { role: 'assistant', content: JSON.stringify(output, null, 2) } satisfies Message\n ])\n\n const outputSchema = Output.extend({\n result: options.outputSchema.describe(Output.shape.result.description!)\n })\n\n const result = await Context.client.callAction({\n type: `${integration}:generateContent`,\n input: {\n systemPrompt: `\n${options.systemMessage}\n\n---\nPlease generate a JSON response with the following format:\n\\`\\`\\`typescript\n${await outputSchema.toTypescriptAsync()}\n\\`\\`\\`\n`.trim(),\n messages: [\n ...exampleMessages,\n {\n role: 'user',\n content: JSON.stringify(options.input, null, 2)\n }\n ],\n temperature: 0,\n responseFormat: 'json_object',\n model: { id: model! }\n } satisfies llm.generateContent.Input\n })\n\n const output = result.output as llm.generateContent.Output\n\n if (!output.choices.length || typeof output.choices?.[0]?.content !== 'string') {\n throw new Error('Invalid response from the model')\n }\n\n const json = output.choices[0].content.trim()\n\n if (!json.length) {\n throw new Error('No response from the model')\n }\n\n return outputSchema.parse(JSON5.parse(json)) as Output<Z.infer<T>>\n}\n","import json5 from 'json5'\nimport { expect } from 'vitest'\nimport { getCurrentTest } from 'vitest/suite'\n\nimport { asyncExpect } from '../utils/asyncAssertion'\nimport { Output } from '../utils/predictJson'\n\nexport type ExtendedPromise<T> = PromiseLike<Output<T>> & {\n value: PromiseLike<T>\n}\n\nexport const toAssertion = <T>(promise: Promise<Output<T>>): ExtendedPromise<T> => {\n return {\n then: promise.then.bind(promise),\n value: promise.then((value) => value.result)\n }\n}\n\nexport const makeToMatchInlineSnapshot =\n <T>(promise: Promise<Output<T>>) =>\n async (expected?: string) => {\n const stack = new Error().stack!.split('\\n')[2]\n const newStack = `\nat __INLINE_SNAPSHOT__ (node:internal/process/task_queues:1:1)\nat randomLine (node:internal/process/task_queues:1:1)\n${stack}\n`.trim()\n\n const obj = json5.parse(expected ?? '\"\"')\n const expectation = asyncExpect(promise, (expect) => expect.toMatchObject(obj)).catch(() => {\n // we swallow the error here, as we're going to throw a new one with the correct stack\n // this is just to make vitest happy and show a nice error message\n })\n\n try {\n expect((await promise).result).toMatchObject(obj)\n } catch (err) {\n const newError = new Error()\n newError.stack = newStack\n\n expect.getState().snapshotState.match({\n isInline: true,\n received: (await promise).result,\n testName: getCurrentTest()!.name,\n error: newError,\n inlineSnapshot: expected\n })\n }\n\n return expectation\n }\n","import { z } from '../utils/zui'\nimport { Context } from '../context'\nimport { asyncExpect } from '../utils/asyncAssertion'\nimport { Input, predictJson } from '../utils/predictJson'\nimport { makeToMatchInlineSnapshot, toAssertion } from './extension'\n\nexport type CheckOptions<T> = {\n examples?: { value: T; expected: boolean; reason: string }[]\n}\n\nexport function check<T extends Input>(value: T, condition: string, options?: CheckOptions<T>) {\n const promise = predictJson({\n systemMessage: `Check that the value meets the condition: ${condition}`,\n examples: options?.examples?.map(({ value, reason, expected }) => ({\n input: value,\n output: { reason, result: expected }\n })),\n outputSchema: z.boolean(),\n model: Context.evaluatorModel,\n input: value\n })\n\n return {\n ...toAssertion(promise),\n toBe: (expected: boolean) => asyncExpect(promise, (expect) => expect.toEqual(expected)),\n toMatchInlineSnapshot: makeToMatchInlineSnapshot(promise)\n }\n}\n","import { z as Z } from '@botpress/sdk'\n\nimport { Context } from '../context'\nimport { asyncExpect } from '../utils/asyncAssertion'\nimport { Input, predictJson } from '../utils/predictJson'\nimport { makeToMatchInlineSnapshot, toAssertion } from './extension'\n\nexport type ExtractOptions<T, S> = {\n description?: string\n examples?: { value: T; extracted: S; reason: string }[]\n}\n\nexport function extract<T extends Input, S extends Z.AnyZodObject>(\n value: T,\n shape: S,\n options?: ExtractOptions<T, Z.infer<S>>\n) {\n const additionalMessage = options?.description\n ? `\\nIn order to extract the right information, follow these instructions:\\n${options.description}\\n`\n : ''\n const promise = predictJson({\n systemMessage:\n 'From the given input, extract the required information into the requested format.' + additionalMessage.trim(),\n examples: options?.examples?.map(({ value, reason, extracted }) => ({\n input: value,\n output: { reason, result: extracted }\n })),\n outputSchema: shape,\n model: Context.evaluatorModel,\n input: value\n })\n\n return {\n ...toAssertion(promise),\n toBe: (expected: Z.infer<S>) => asyncExpect(promise, (expect) => expect.toEqual(expected)),\n toMatchObject: (expected: Partial<Z.infer<S>>) => asyncExpect(promise, (expect) => expect.toMatchObject(expected)),\n toMatchInlineSnapshot: makeToMatchInlineSnapshot(promise)\n }\n}\n","import { z } from '../utils/zui'\n\nimport { Context } from '../context'\nimport { asyncExpect } from '../utils/asyncAssertion'\nimport { predictJson } from '../utils/predictJson'\nimport { makeToMatchInlineSnapshot, toAssertion } from './extension'\n\nexport type FilterOptions<T> = {\n examples?: { value: T; reason: string; keep: boolean }[]\n}\n\nexport function filter<U>(values: U[], condition: string, options?: FilterOptions<U>) {\n const mappedValues = values.map((_, idx) =>\n z.object({\n index: z.literal(idx),\n reason: z.string(),\n keep: z.boolean()\n })\n )\n\n const input = values.map((value, idx) => ({\n index: idx,\n value\n }))\n\n const schema = z\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n .tuple(mappedValues as any)\n .describe(\n 'An array of the objects with the index and a boolean value indicating if the object should be kept or not'\n )\n\n const promise = predictJson({\n systemMessage: `\nBased on the following qualification criteria, you need to filter the given list of objects.\nCiteria: ${condition}\n\n---\nYou need to return an array of objects with the index and a boolean value indicating if the object should be kept or not.\n`.trim(),\n examples: options?.examples\n ? [\n {\n input: options?.examples?.map((v, index) => ({\n index,\n value: v.value\n })),\n output: {\n reason: 'Here are some examples',\n result: options?.examples?.map((v, idx) => ({\n index: idx,\n reason: v.reason,\n keep: v.keep\n }))\n }\n }\n ]\n : undefined,\n outputSchema: schema,\n model: Context.evaluatorModel,\n input\n }).then((x) => {\n const results = schema.parse(x.result) as { index: number; keep: boolean }[]\n return {\n result: values.filter((_, idx) => results.find((r) => r.index === idx)?.keep),\n reason: x.reason\n }\n })\n\n return {\n ...toAssertion(promise),\n toBe: (expected: U[]) => asyncExpect(promise, (expect) => expect.toEqual(expected)),\n toMatchInlineSnapshot: makeToMatchInlineSnapshot(promise),\n toHaveNoneFiltered: () => asyncExpect(promise, (expect) => expect.toEqual(values)),\n toHaveSomeFiltered: () => asyncExpect(promise, (expect) => expect.not.toEqual(values)),\n toBeEmpty: () => asyncExpect(promise, (expect) => expect.toHaveLength(0)),\n length: {\n toBe: (expected: number) => asyncExpect(promise, (expect) => expect.toHaveLength(expected)),\n toBeGreaterThanOrEqual: (expected: number) =>\n asyncExpect(promise, (expect) => expect.length.greaterThanOrEqual(expected)),\n toBeLessThanOrEqual: (expected: number) =>\n asyncExpect(promise, (expect) => expect.length.lessThanOrEqual(expected)),\n toBeBetween: (min: number, max: number) => asyncExpect(promise, (expect) => expect.length.within(min, max))\n }\n }\n}\n","import { z } from '../utils/zui'\n\nimport { Context } from '../context'\nimport { asyncExpect } from '../utils/asyncAssertion'\nimport { Input, predictJson } from '../utils/predictJson'\nimport { makeToMatchInlineSnapshot, toAssertion } from './extension'\n\nexport type RatingScore = 1 | 2 | 3 | 4 | 5\nexport type RateOptions<T> = {\n examples?: { value: T; rating: number; reason: string }[]\n}\n\nexport function rate<T extends Input>(value: T, condition: string, options?: RateOptions<T>) {\n const schema = z.number().min(1).max(5).describe('Rating score, higher is better (1 is the worst, 5 is the best)')\n const promise = predictJson({\n systemMessage: `Based on the following qualification criteria, you need to rate the given situation from a score of 1 to 5.\\nScoring: 1 is the worst score, 5 is the best score possible.\\nCriteria: ${condition}`,\n examples: options?.examples?.map(({ value, reason, rating }) => ({\n input: value,\n output: { reason, result: rating }\n })),\n outputSchema: schema,\n model: Context.evaluatorModel,\n input: value\n }).then((x) => {\n return {\n result: typeof x.result === 'number' ? x.result : parseInt(x.result, 10),\n reason: x.reason\n }\n })\n\n return {\n ...toAssertion(promise),\n toBe: (expected: number) => asyncExpect(promise, (expect) => expect.toEqual(expected)),\n toMatchInlineSnapshot: makeToMatchInlineSnapshot(promise),\n toBeGreaterThanOrEqual: (expected: RatingScore) =>\n asyncExpect(promise, (expect) => expect.toBeGreaterThanOrEqual(expected)),\n toBeLessThanOrEqual: (expected: RatingScore) =>\n asyncExpect(promise, (expect) => expect.toBeLessThanOrEqual(expected))\n }\n}\n","import { getCurrentTest } from 'vitest/suite'\nimport { EvaluatorModel, TestMetadata } from '../context'\n\nexport const setEvaluator = (model: EvaluatorModel) => {\n const test = getCurrentTest()\n\n if (!test) {\n throw new Error('setEvaluator is a Vitest hook and must be called within a test')\n }\n\n const meta = test.meta as TestMetadata\n meta.evaluatorModel = model\n}\n","import { Client } from '@botpress/client'\nimport { Context } from '../context'\n\nexport const setupClient = (client: Client) => {\n Context.setClient(client)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,iBAAgB;AAET,IAAM,IAAI,WAAAA,QAAI;;;ACErB,mBAAqD;;;ACJ9C,IAAM,YAAN,MAAM,UAAY;AAAA,EAKvB,cAAc;AACZ,SAAK,UAAU,IAAI,QAAW,CAAC,SAAS,WAAW;AACjD,WAAK,WAAW;AAChB,WAAK,UAAU;AAAA,IACjB,CAAC;AAAA,EACH;AAAA,EAEA,QAAQ,OAAiC;AACvC,SAAK,SAAS,KAAK;AAAA,EACrB;AAAA,EAEA,OAAO,QAAwB;AAC7B,SAAK,QAAQ,MAAM;AAAA,EACrB;AACF;AAnByB;AAAlB,IAAM,WAAN;;;ADQP,IAAM,aAAa,EAChB,OAAO,EACP,KAAK,EACL,IAAI,GAAG,oCAAoC,EAC3C,IAAI,IAAI,8BAA8B;AAGzC,IAAM,eAAe,EAAE,MAAM;AAAA,EAC3B;AAAA,EACA,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC,EAAE,YAAY;AAAA,EAC3C,EAAE,OAAO,EAAE,IAAI,WAAW,CAAC,EAAE,YAAY;AAC3C,CAAC;AAED,IAAM,kBAAkB,wBAAC,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QAAO,QAAQ,OAAO,OAAO;AAAA,MAC/D,OAAOA;AAAA,MACP,QAAQ,EAAE,QAAQ,QAAQ,OAAO;AAAA,IACnC;AAAA,IACA,cAAc;AAAA,IACd,OAAO,QAAQ;AAAA,IACf,OAAO;AAAA,EACT,CAAC,EAAE,KAAK,CAAC,MAAM;AACb,WAAO;AAAA,MACL,QAAQ,OAAO,EAAE,WAAW,WAAW,EAAE,SAAS,SAAS,EAAE,QAAQ,EAAE;AAAA,MACvE,QAAQ,EAAE;AAAA,IACZ;AAAA,EACF,CAAC;AAED,SAAO,iCACF,YAAY,OAAO,IADjB;AAAA,IAEL,MAAM,wBAAC,aAAqB,YAAY,SAAS,CAACC,YAAWA,QAAO,QAAQ,QAAQ,CAAC,GAA/E;AAAA,IACN,uBAAuB,0BAA0B,OAAO;AAAA,IACxD,wBAAwB,wBAAC,aACvB,YAAY,SAAS,CAACA,YAAWA,QAAO,uBAAuB,QAAQ,CAAC,GADlD;AAAA,IAExB,qBAAqB,wBAAC,aACpB,YAAY,SAAS,CAACA,YAAWA,QAAO,oBAAoB,QAAQ,CAAC,GADlD;AAAA,EAEvB;AACF;AA3BgB;;;ACZhB,IAAAC,gBAA+B;AAGxB,IAAM,eAAe,wBAAC,UAA0B;AACrD,QAAM,WAAO,8BAAe;AAE5B,MAAI,CAAC,MAAM;AACT,UAAM,IAAI,MAAM,gEAAgE;AAAA,EAClF;AAEA,QAAM,OAAO,KAAK;AAClB,OAAK,iBAAiB;AACxB,GAT4B;;;ACArB,IAAM,cAAc,wBAAC,WAAmB;AAC7C,UAAQ,UAAU,MAAM;AAC1B,GAF2B;","names":["sdk","fn","import_suite","import_vitest","import_suite","output","JSON5","import_json5","import_vitest","import_suite","json5","expect","value","expect","value","expect","_a","expect","value","expect","import_suite"]}