@empiricalrun/test-gen 0.15.1 → 0.16.3

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.
Files changed (46) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/dist/actions/assert.d.ts.map +1 -1
  3. package/dist/actions/assert.js +1 -9
  4. package/dist/actions/click.d.ts.map +1 -1
  5. package/dist/actions/click.js +1 -9
  6. package/dist/actions/fill.d.ts.map +1 -1
  7. package/dist/actions/fill.js +1 -9
  8. package/dist/actions/index.d.ts.map +1 -1
  9. package/dist/actions/index.js +7 -5
  10. package/dist/agent/browsing/index.d.ts +5 -2
  11. package/dist/agent/browsing/index.d.ts.map +1 -1
  12. package/dist/agent/browsing/index.js +18 -11
  13. package/dist/agent/browsing/run.d.ts.map +1 -1
  14. package/dist/agent/browsing/run.js +12 -9
  15. package/dist/agent/browsing/utils.d.ts +6 -0
  16. package/dist/agent/browsing/utils.d.ts.map +1 -1
  17. package/dist/agent/browsing/utils.js +13 -1
  18. package/dist/agent/codegen/run.d.ts +2 -2
  19. package/dist/agent/codegen/run.d.ts.map +1 -1
  20. package/dist/agent/codegen/run.js +29 -9
  21. package/dist/bin/index.js +5 -1
  22. package/dist/bin/utils/platform/web/index.d.ts.map +1 -1
  23. package/dist/bin/utils/platform/web/index.js +11 -1
  24. package/dist/constants/index.d.ts +6 -0
  25. package/dist/constants/index.d.ts.map +1 -0
  26. package/dist/constants/index.js +13 -0
  27. package/dist/index.d.ts.map +1 -1
  28. package/dist/index.js +6 -1
  29. package/dist/session/index.d.ts.map +1 -0
  30. package/dist/{bin/session → session}/index.js +1 -1
  31. package/dist/types/index.d.ts +6 -4
  32. package/dist/types/index.d.ts.map +1 -1
  33. package/dist/utils/exec.d.ts.map +1 -1
  34. package/dist/utils/exec.js +14 -3
  35. package/package.json +2 -3
  36. package/dist/bin/ai/index.d.ts +0 -9
  37. package/dist/bin/ai/index.d.ts.map +0 -1
  38. package/dist/bin/ai/index.js +0 -31
  39. package/dist/bin/ai/prompts/provider/index.d.ts +0 -9
  40. package/dist/bin/ai/prompts/provider/index.d.ts.map +0 -1
  41. package/dist/bin/ai/prompts/provider/index.js +0 -28
  42. package/dist/bin/ai/trace/index.d.ts +0 -37
  43. package/dist/bin/ai/trace/index.d.ts.map +0 -1
  44. package/dist/bin/ai/trace/index.js +0 -67
  45. package/dist/bin/session/index.d.ts.map +0 -1
  46. /package/dist/{bin/session → session}/index.d.ts +0 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,35 @@
1
1
  # @empiricalrun/test-gen
2
2
 
3
+ ## 0.16.3
4
+
5
+ ### Patch Changes
6
+
7
+ - 8243b11: fix: add logs for errors while running playwright
8
+
9
+ ## 0.16.2
10
+
11
+ ### Patch Changes
12
+
13
+ - Updated dependencies [ffaa43d]
14
+ - @empiricalrun/llm@0.2.0
15
+
16
+ ## 0.16.1
17
+
18
+ ### Patch Changes
19
+
20
+ - 8b19502: fix: browsing agent message format
21
+
22
+ ## 0.16.0
23
+
24
+ ### Minor Changes
25
+
26
+ - af9724a: feat: add support for ai gateway
27
+
28
+ ### Patch Changes
29
+
30
+ - Updated dependencies [af9724a]
31
+ - @empiricalrun/llm@0.1.0
32
+
3
33
  ## 0.15.1
4
34
 
5
35
  ### Patch Changes
@@ -1 +1 @@
1
- {"version":3,"file":"assert.d.ts","sourceRoot":"","sources":["../../src/actions/assert.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,UAAU,CAAC;AAGrD,eAAO,MAAM,6CAA6C,2BAChC,CAAC;AAE3B,eAAO,MAAM,mCAAmC,EAAE,yBAsDjD,CAAC"}
1
+ {"version":3,"file":"assert.d.ts","sourceRoot":"","sources":["../../src/actions/assert.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,UAAU,CAAC;AAGrD,eAAO,MAAM,6CAA6C,2BAChC,CAAC;AAE3B,eAAO,MAAM,mCAAmC,EAAE,yBA8CjD,CAAC"}
@@ -15,15 +15,7 @@ const assertTextVisibilityActionGenerator = (page) => {
15
15
  },
16
16
  // TODO: args transformer to be kept at a single place
17
17
  template: (args, options) => {
18
- const css = args.css_selector;
19
- const assertStr = `await expect(page.locator("${css}")).toBeVisible();`;
20
- if (options?.locator) {
21
- return `
22
- // ${assertStr}
23
- await expect(page.${options.locator}).toBeVisible();
24
- `;
25
- }
26
- return assertStr;
18
+ return `await expect(page.${options.locator}).toBeVisible();`;
27
19
  },
28
20
  name: exports.PLAYWRIGHT_ASSERT_TEXT_VISIBILITY_ACTION_NAME,
29
21
  schema: {
@@ -1 +1 @@
1
- {"version":3,"file":"click.d.ts","sourceRoot":"","sources":["../../src/actions/click.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,UAAU,CAAC;AAGrD,eAAO,MAAM,4BAA4B,kBAAkB,CAAC;AAE5D,eAAO,MAAM,oBAAoB,EAAE,yBAsDlC,CAAC"}
1
+ {"version":3,"file":"click.d.ts","sourceRoot":"","sources":["../../src/actions/click.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,UAAU,CAAC;AAGrD,eAAO,MAAM,4BAA4B,kBAAkB,CAAC;AAE5D,eAAO,MAAM,oBAAoB,EAAE,yBA8ClC,CAAC"}
@@ -17,15 +17,7 @@ const clickActionGenerator = (page) => {
17
17
  },
18
18
  // TODO: args transformer to be kept at a single place
19
19
  template: (args, options) => {
20
- const css = args.css_selector;
21
- const templ = `await page.locator("${css}").first().click();`;
22
- if (options?.locator) {
23
- return `
24
- // ${templ}
25
- await page.${options.locator}.click();
26
- `;
27
- }
28
- return templ;
20
+ return `await page.${options.locator}.click();`;
29
21
  },
30
22
  name: exports.PLAYWRIGHT_CLICK_ACTION_NAME,
31
23
  schema: {
@@ -1 +1 @@
1
- {"version":3,"file":"fill.d.ts","sourceRoot":"","sources":["../../src/actions/fill.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,UAAU,CAAC;AAGrD,eAAO,MAAM,2BAA2B,uBAAuB,CAAC;AAEhE,eAAO,MAAM,mBAAmB,EAAE,yBAsDjC,CAAC"}
1
+ {"version":3,"file":"fill.d.ts","sourceRoot":"","sources":["../../src/actions/fill.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,UAAU,CAAC;AAGrD,eAAO,MAAM,2BAA2B,uBAAuB,CAAC;AAEhE,eAAO,MAAM,mBAAmB,EAAE,yBA8CjC,CAAC"}
@@ -16,15 +16,7 @@ const fillActionGenerator = (page) => {
16
16
  },
17
17
  // TODO: args transformer to be kept at a single place
18
18
  template: (args, options) => {
19
- const css = args.css_selector;
20
- const templ = `await page.locator("${css}").fill("${args.text}");`;
21
- if (options?.locator) {
22
- return `
23
- // ${templ}
24
- await page.${options?.locator}.fill("${args.text}");
25
- `;
26
- }
27
- return templ;
19
+ return `await page.${options.locator}.fill("${args.text}");`;
28
20
  },
29
21
  name: exports.PLAYWRIGHT_FILL_ACTION_NAME,
30
22
  schema: {
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/actions/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAGlC,OAAO,EAAU,YAAY,EAAE,MAAM,UAAU,CAAC;AAQhD,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,OAAO,CAAW;IAC1B,OAAO,CAAC,eAAe,CAAmC;gBAC9C,IAAI,EAAE,IAAI;IAYhB,aAAa,CAAC,IAAI,oBAAa,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;IAmBhE,gBAAgB,IAAI,YAAY,EAAE;IAIlC,YAAY;IAIZ,UAAU;CAMX"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/actions/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAGlC,OAAO,EAAU,YAAY,EAAE,MAAM,UAAU,CAAC;AAQhD,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,OAAO,CAAW;IAC1B,OAAO,CAAC,eAAe,CAAmC;gBAC9C,IAAI,EAAE,IAAI;IAYhB,aAAa,CAAC,IAAI,oBAAa,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;IAqBhE,gBAAgB,IAAI,YAAY,EAAE;IAIlC,YAAY;IAIZ,UAAU;CAMX"}
@@ -27,17 +27,19 @@ class PlaywrightActions {
27
27
  if (!action) {
28
28
  throw Error(`No action registered for action: ${name}`);
29
29
  }
30
+ const logger = new logger_1.CustomLogger();
31
+ logger.logEmptyLine();
30
32
  try {
31
- const logger = new logger_1.CustomLogger();
32
- logger.log(`executing: ${name}`);
33
- logger.log(`reason: ${args.reason}`);
34
- const templateOptions = (await action.execute(args)) || undefined;
33
+ const templateOptions = (await action.execute(args)) || { locator: "" };
35
34
  // record successful actions
36
35
  const code = action.template(args, templateOptions);
37
36
  this.recordedActions.push({ name, code });
38
- logger.log(`code: ${code}`, "\n\n");
37
+ if (code) {
38
+ logger.log(`action: ${name} \ncode: ${code} \nreason: ${args.reason}`);
39
+ }
39
40
  }
40
41
  catch (e) {
42
+ logger.log(`action: ${name} \nreason: ${args.reason}`);
41
43
  throw Error(`Error executing ${name} action of playwright: ${e}`);
42
44
  }
43
45
  }
@@ -1,7 +1,10 @@
1
1
  import { Page } from "playwright";
2
- export declare function browsingAgent(task: string, page: Page, options?: {
2
+ import { TestGenConfigOptions } from "../../types";
3
+ type BrowsingAgentOptions = Partial<TestGenConfigOptions> & {
3
4
  htmlSanitize?: {
4
5
  disallowedStrings?: string[];
5
6
  };
6
- }): Promise<string>;
7
+ };
8
+ export declare function browsingAgent(task: string, page: Page, options: BrowsingAgentOptions): Promise<string>;
9
+ export {};
7
10
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/agent/browsing/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAUlC,wBAAsB,aAAa,CACjC,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,IAAI,EACV,OAAO,GAAE;IACP,YAAY,CAAC,EAAE;QACb,iBAAiB,CAAC,EAAE,MAAM,EAAE,CAAC;KAC9B,CAAC;CACE,mBAiFP"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/agent/browsing/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAWlC,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAInD,KAAK,oBAAoB,GAAG,OAAO,CAAC,oBAAoB,CAAC,GAAG;IAC1D,YAAY,CAAC,EAAE;QACb,iBAAiB,CAAC,EAAE,MAAM,EAAE,CAAC;KAC9B,CAAC;CACH,CAAC;AAEF,wBAAsB,aAAa,CACjC,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,IAAI,EACV,OAAO,EAAE,oBAAoB,mBA4F9B"}
@@ -1,19 +1,19 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.browsingAgent = void 0;
4
+ const llm_1 = require("@empiricalrun/llm");
7
5
  const actions_1 = require("../../actions");
8
- const ai_1 = require("../../bin/ai");
9
- const provider_1 = require("../../bin/ai/prompts/provider");
10
- const trace_1 = __importDefault(require("../../bin/ai/trace"));
11
6
  const logger_1 = require("../../bin/logger");
7
+ const constants_1 = require("../../constants");
8
+ const session_1 = require("../../session");
12
9
  const html_1 = require("../../utils/html");
13
10
  const utils_1 = require("./utils");
14
- async function browsingAgent(task, page, options = {}) {
11
+ async function browsingAgent(task, page, options) {
15
12
  const logger = new logger_1.CustomLogger();
16
- const trace = new trace_1.default({ name: "browsing-agent" });
13
+ const trace = new llm_1.LLMTracing({
14
+ name: "browsing-agent",
15
+ sessionDetails: (0, session_1.getSessionDetails)(),
16
+ });
17
17
  const actions = new actions_1.PlaywrightActions(page);
18
18
  const tools = actions.getActionSchemas();
19
19
  let isTaskDone = false;
@@ -33,18 +33,25 @@ async function browsingAgent(task, page, options = {}) {
33
33
  const successfulActions = executedActions
34
34
  .filter((a) => !a.isError)
35
35
  .map((a) => a.action);
36
- const messages = await (0, provider_1.getPromptForNextAction)({
36
+ const messages = await (0, utils_1.getPromptForNextAction)({
37
37
  pageSnapshot,
38
38
  previousActions: successfulActions,
39
39
  task,
40
40
  lastActionErrors: lastActionExecTrace ? [lastActionExecTrace] : [],
41
41
  });
42
42
  promptSpan.end({ output: { messages } });
43
- const completion = await (0, ai_1.getLLMResult)({
43
+ const completion = await (0, llm_1.getLLMResult)({
44
44
  messages,
45
45
  tools,
46
46
  trace,
47
- tool_choice: "required",
47
+ model: options.model || constants_1.DEFAULT_MODEL,
48
+ provider: options.modelProvider || constants_1.DEFAULT_MODEL_PROVIDER,
49
+ providerApiKey: constants_1.MODEL_API_KEYS[options.modelProvider || constants_1.DEFAULT_MODEL_PROVIDER],
50
+ modelParameters: {
51
+ ...constants_1.DEFAULT_MODEL_PARAMETERS,
52
+ ...options.modelParameters,
53
+ tool_choice: "required",
54
+ },
48
55
  });
49
56
  const toolCalls = completion?.tool_calls || [];
50
57
  for (const i in toolCalls) {
@@ -1 +1 @@
1
- {"version":3,"file":"run.d.ts","sourceRoot":"","sources":["../../../src/agent/browsing/run.ts"],"names":[],"mappings":"AAaA,wBAAsB,+BAA+B,CAAC,YAAY,EAAE,MAAM,iBA0BzE"}
1
+ {"version":3,"file":"run.d.ts","sourceRoot":"","sources":["../../../src/agent/browsing/run.ts"],"names":[],"mappings":"AAaA,wBAAsB,+BAA+B,CAAC,YAAY,EAAE,MAAM,iBA4BzE"}
@@ -26,15 +26,18 @@ async function generateTestsUsingBrowsingAgent(testFilePath) {
26
26
  if (!process.env.CI) {
27
27
  command = command.concat(` --headed`);
28
28
  }
29
- const exitCode = await (0, exec_1.cmd)(command.split(" "), {
30
- env: {
31
- APP_PORT: port.toString(),
32
- PW_TEST_HTML_REPORT_OPEN: "never",
33
- TEST_GEN_TOKEN: (0, utils_1.getTestConfigCliArg)(),
34
- },
35
- });
36
- if (exitCode != 0) {
37
- process.exit(exitCode);
29
+ try {
30
+ await (0, exec_1.cmd)(command.split(" "), {
31
+ env: {
32
+ APP_PORT: port.toString(),
33
+ PW_TEST_HTML_REPORT_OPEN: "never",
34
+ TEST_GEN_TOKEN: (0, utils_1.getTestConfigCliArg)(),
35
+ },
36
+ });
37
+ }
38
+ catch (e) {
39
+ logger.error(e);
40
+ process.exit(1);
38
41
  }
39
42
  await (0, web_1.removeTestOnly)(testFilePath);
40
43
  }
@@ -14,4 +14,10 @@ export declare function readPlaywrightConfig(): Promise<PlaywrightTestConfig>;
14
14
  * @returns
15
15
  */
16
16
  export declare function detectProjectName(testFilePath: string, playwrightConfig: PlaywrightTestConfig): Promise<string>;
17
+ export declare function getPromptForNextAction({ pageSnapshot, task, previousActions, lastActionErrors, }: {
18
+ pageSnapshot: string;
19
+ task: string;
20
+ previousActions: string[];
21
+ lastActionErrors: string[];
22
+ }): Promise<import("openai/resources/index.mjs").ChatCompletionMessageParam[]>;
17
23
  //# sourceMappingURL=utils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/agent/browsing/utils.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAClC,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AASvD,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,wBAAgB,QAAQ,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG,IAAI,MAAM,CAKhD;AAED,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,MAAM,CAAC,EAAE,MAAM,UAIxE;AAED,wBAAsB,2BAA2B,CAAC,SAAS,EAAE,aAAa,iBAqCzE;AAiBD,wBAAsB,wBAAwB,CAAC,IAAI,EAAE,IAAI,iBASxD;AAED,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,QA4BnD;AAED,wBAAsB,oBAAoB,IAAI,OAAO,CAAC,oBAAoB,CAAC,CAM1E;AAED;;;;;GAKG;AACH,wBAAsB,iBAAiB,CACrC,YAAY,EAAE,MAAM,EACpB,gBAAgB,EAAE,oBAAoB,GACrC,OAAO,CAAC,MAAM,CAAC,CAkDjB"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/agent/browsing/utils.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAClC,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AASvD,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,wBAAgB,QAAQ,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG,IAAI,MAAM,CAKhD;AAED,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,MAAM,CAAC,EAAE,MAAM,UAIxE;AAED,wBAAsB,2BAA2B,CAAC,SAAS,EAAE,aAAa,iBAqCzE;AAiBD,wBAAsB,wBAAwB,CAAC,IAAI,EAAE,IAAI,iBASxD;AAED,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,QA4BnD;AAED,wBAAsB,oBAAoB,IAAI,OAAO,CAAC,oBAAoB,CAAC,CAM1E;AAED;;;;;GAKG;AACH,wBAAsB,iBAAiB,CACrC,YAAY,EAAE,MAAM,EACpB,gBAAgB,EAAE,oBAAoB,GACrC,OAAO,CAAC,MAAM,CAAC,CAkDjB;AAED,wBAAsB,sBAAsB,CAAC,EAC3C,YAAiB,EACjB,IAAS,EACT,eAAoB,EACpB,gBAAqB,GACtB,EAAE;IACD,YAAY,EAAE,MAAM,CAAC;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,eAAe,EAAE,MAAM,EAAE,CAAC;IAC1B,gBAAgB,EAAE,MAAM,EAAE,CAAC;CAC5B,8EASA"}
@@ -3,7 +3,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.detectProjectName = exports.readPlaywrightConfig = exports.canRunBrowsingAgent = exports.injectPwLocatorGenerator = exports.prepareFileForBrowsingAgent = exports.prepareBrowsingAgentTask = exports.isRegExp = void 0;
6
+ exports.getPromptForNextAction = exports.detectProjectName = exports.readPlaywrightConfig = exports.canRunBrowsingAgent = exports.injectPwLocatorGenerator = exports.prepareFileForBrowsingAgent = exports.prepareBrowsingAgentTask = exports.isRegExp = void 0;
7
+ const llm_1 = require("@empiricalrun/llm");
7
8
  const child_process_1 = require("child_process");
8
9
  const fs_extra_1 = __importDefault(require("fs-extra"));
9
10
  const minimatch_1 = require("minimatch");
@@ -154,3 +155,14 @@ async function detectProjectName(testFilePath, playwrightConfig) {
154
155
  return project;
155
156
  }
156
157
  exports.detectProjectName = detectProjectName;
158
+ async function getPromptForNextAction({ pageSnapshot = "", task = "", previousActions = [], lastActionErrors = [], }) {
159
+ const previousActionsStr = previousActions.join("\n\n ---- \n\n");
160
+ const prompt = await (0, llm_1.getPrompt)("browsing-agent-next-action", {
161
+ pageSnapshot,
162
+ previousActionsStr,
163
+ task,
164
+ lastActionErrors,
165
+ });
166
+ return prompt;
167
+ }
168
+ exports.getPromptForNextAction = getPromptForNextAction;
@@ -1,3 +1,3 @@
1
- import { Scenario } from "../../types";
2
- export declare function generateTest(scenarios: Scenario[], file: string, isUpdate: boolean): Promise<Scenario[]>;
1
+ import { Scenario, TestGenConfigOptions } from "../../types";
2
+ export declare function generateTest(scenarios: Scenario[], file: string, isUpdate: boolean, options: TestGenConfigOptions): Promise<Scenario[]>;
3
3
  //# sourceMappingURL=run.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"run.d.ts","sourceRoot":"","sources":["../../../src/agent/codegen/run.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEvC,wBAAsB,YAAY,CAChC,SAAS,EAAE,QAAQ,EAAE,EACrB,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,OAAO,GAChB,OAAO,CAAC,QAAQ,EAAE,CAAC,CA+HrB"}
1
+ {"version":3,"file":"run.d.ts","sourceRoot":"","sources":["../../../src/agent/codegen/run.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAE,QAAQ,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAE7D,wBAAsB,YAAY,CAChC,SAAS,EAAE,QAAQ,EAAE,EACrB,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,OAAO,EACjB,OAAO,EAAE,oBAAoB,GAC5B,OAAO,CAAC,QAAQ,EAAE,CAAC,CAqJrB"}
@@ -4,14 +4,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.generateTest = void 0;
7
+ const llm_1 = require("@empiricalrun/llm");
7
8
  const fs_extra_1 = __importDefault(require("fs-extra"));
8
- const ai_1 = require("../../bin/ai");
9
- const provider_1 = require("../../bin/ai/prompts/provider");
10
- const trace_1 = __importDefault(require("../../bin/ai/trace"));
11
9
  const logger_1 = require("../../bin/logger");
12
10
  const context_1 = require("../../bin/utils/context");
13
11
  const web_1 = require("../../bin/utils/platform/web");
14
- async function generateTest(scenarios, file, isUpdate) {
12
+ const constants_1 = require("../../constants");
13
+ const session_1 = require("../../session");
14
+ async function generateTest(scenarios, file, isUpdate, options) {
15
15
  const logger = new logger_1.CustomLogger();
16
16
  if (!fs_extra_1.default.existsSync(file)) {
17
17
  logger.log(`Creating a new spec file: ${file}`);
@@ -22,7 +22,10 @@ async function generateTest(scenarios, file, isUpdate) {
22
22
  const generatedScenarios = [];
23
23
  for (const i in scenarios) {
24
24
  logger.logEmptyLine();
25
- const trace = new trace_1.default({ name: "generate-test" });
25
+ const trace = new llm_1.LLMTracing({
26
+ name: "generate-test",
27
+ sessionDetails: (0, session_1.getSessionDetails)(),
28
+ });
26
29
  trace.event({
27
30
  name: "collate-files-as-text",
28
31
  output: {
@@ -41,7 +44,7 @@ async function generateTest(scenarios, file, isUpdate) {
41
44
  }
42
45
  const promptSpan = trace.startSpan(isUpdate ? "update-scenario-prompt" : "add-scenario-prompt");
43
46
  const promptName = isUpdate ? "update-scenario" : "add-scenario";
44
- const instruction = await (0, provider_1.getPrompt)(promptName, {
47
+ const instruction = await (0, llm_1.getPrompt)(promptName, {
45
48
  testFiles: codePrompt,
46
49
  pageFiles: pomPrompt,
47
50
  scenarioName: scenario.name,
@@ -50,9 +53,16 @@ async function generateTest(scenarios, file, isUpdate) {
50
53
  scenarioFile: file,
51
54
  });
52
55
  promptSpan.end({ output: { instruction } });
53
- const firstShotMessage = await (0, ai_1.getLLMResult)({
56
+ const firstShotMessage = await (0, llm_1.getLLMResult)({
54
57
  messages: instruction,
55
58
  trace,
59
+ model: options.model || constants_1.DEFAULT_MODEL,
60
+ provider: options.modelProvider || constants_1.DEFAULT_MODEL_PROVIDER,
61
+ providerApiKey: constants_1.MODEL_API_KEYS[options.modelProvider || constants_1.DEFAULT_MODEL_PROVIDER],
62
+ modelParameters: {
63
+ ...constants_1.DEFAULT_MODEL_PARAMETERS,
64
+ ...options.modelParameters,
65
+ },
56
66
  });
57
67
  let response = firstShotMessage?.content || "";
58
68
  logger.success("Test generated successfully!");
@@ -96,7 +106,7 @@ async function generateTest(scenarios, file, isUpdate) {
96
106
  errors.forEach((e) => logger.warn(e));
97
107
  logger.log("Trying to fix above errors...");
98
108
  const promptSpan = trace.startSpan("fix-type-errors-prompt");
99
- const instruction = await (0, provider_1.getPrompt)("fix-file-errors-ts", {
109
+ const instruction = await (0, llm_1.getPrompt)("fix-file-errors-ts", {
100
110
  testFiles: codePrompt || "",
101
111
  pageFiles: pomPrompt || "",
102
112
  scenarioFile: file,
@@ -105,7 +115,17 @@ async function generateTest(scenarios, file, isUpdate) {
105
115
  scenaioName: scenario.name,
106
116
  });
107
117
  promptSpan.end({ output: { instruction } });
108
- const message = await (0, ai_1.getLLMResult)({ messages: instruction, trace });
118
+ const message = await (0, llm_1.getLLMResult)({
119
+ messages: instruction,
120
+ trace,
121
+ model: options.model || constants_1.DEFAULT_MODEL,
122
+ provider: options.modelProvider || constants_1.DEFAULT_MODEL_PROVIDER,
123
+ providerApiKey: constants_1.MODEL_API_KEYS[options.modelProvider || constants_1.DEFAULT_MODEL_PROVIDER],
124
+ modelParameters: {
125
+ ...constants_1.DEFAULT_MODEL_PARAMETERS,
126
+ ...options.modelParameters,
127
+ },
128
+ });
109
129
  response = message?.content || "";
110
130
  const readWriteFileSpan = trace.startSpan("write-to-file");
111
131
  await fs_extra_1.default.writeFile(file, response, "utf-8");
package/dist/bin/index.js CHANGED
@@ -4,6 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  return (mod && mod.__esModule) ? mod : { "default": mod };
5
5
  };
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
+ const llm_1 = require("@empiricalrun/llm");
7
8
  const dotenv_1 = __importDefault(require("dotenv"));
8
9
  const run_1 = require("../agent/browsing/run");
9
10
  const utils_1 = require("../agent/browsing/utils");
@@ -15,6 +16,9 @@ const utils_2 = require("./utils");
15
16
  dotenv_1.default.config({
16
17
  path: [".env.local", ".env"],
17
18
  });
19
+ process.on("exit", async () => await (0, llm_1.flushAllTraces)());
20
+ process.on("SIGINT", async () => await (0, llm_1.flushAllTraces)());
21
+ process.on("SIGTERM", async () => await (0, llm_1.flushAllTraces)());
18
22
  async function runAgent(sourceFile, isUpdate, testGenConfigs) {
19
23
  const logger = new logger_1.CustomLogger();
20
24
  const generatedTestScenarios = [];
@@ -30,7 +34,7 @@ async function runAgent(sourceFile, isUpdate, testGenConfigs) {
30
34
  }
31
35
  else {
32
36
  logger.success("Generating test using coding agent");
33
- const gen = await (0, run_2.generateTest)(scenarios, specPath, isUpdate);
37
+ const gen = await (0, run_2.generateTest)(scenarios, specPath, isUpdate, testGenConfig.options);
34
38
  generatedTestScenarios.push(...gen);
35
39
  }
36
40
  }
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/bin/utils/platform/web/index.ts"],"names":[],"mappings":"AAKA,wBAAgB,sBAAsB,CACpC,YAAY,EAAE,MAAM,EACpB,OAAO,EAAE,MAAM,GACd,MAAM,GAAG,SAAS,CAQpB;AAED,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAG5E;AAED,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,EAAE,CAwC7D;AAED,wBAAsB,sBAAsB,CAAC,OAAO,EAAE,MAAM,qBAM3D;AAED,wBAAsB,UAAU,CAAC,QAAQ,EAAE,MAAM,iBAOhD;AAED,wBAAsB,UAAU,CAAC,QAAQ,EAAE,MAAM,iBAQhD;AAED,wBAAgB,YAAY,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,UAE5E;AAED,wBAAsB,cAAc,CAAC,QAAQ,EAAE,MAAM,iBAIpD"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/bin/utils/platform/web/index.ts"],"names":[],"mappings":"AAKA,wBAAgB,sBAAsB,CACpC,YAAY,EAAE,MAAM,EACpB,OAAO,EAAE,MAAM,GACd,MAAM,GAAG,SAAS,CAQpB;AAED,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAG5E;AAED,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,EAAE,CAiD7D;AAED,wBAAsB,sBAAsB,CAAC,OAAO,EAAE,MAAM,qBAM3D;AAED,wBAAsB,UAAU,CAAC,QAAQ,EAAE,MAAM,iBAOhD;AAED,wBAAsB,UAAU,CAAC,QAAQ,EAAE,MAAM,iBAQhD;AAED,wBAAgB,YAAY,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,UAE5E;AAED,wBAAsB,cAAc,CAAC,QAAQ,EAAE,MAAM,iBAIpD"}
@@ -56,7 +56,17 @@ function validateTypescript(filePath) {
56
56
  const semanticDiagnostics = program.getSemanticDiagnostics(sourceFile);
57
57
  if (semanticDiagnostics.length > 0) {
58
58
  semanticDiagnostics.forEach((diagnostic) => {
59
- errors.push(diagnostic.messageText.toString());
59
+ if (typeof diagnostic.messageText === "string") {
60
+ errors.push(diagnostic.messageText);
61
+ }
62
+ else {
63
+ let messageChain = diagnostic.messageText;
64
+ errors.push(messageChain.messageText);
65
+ while (messageChain?.next) {
66
+ messageChain = messageChain.next[0];
67
+ errors.push(messageChain?.messageText);
68
+ }
69
+ }
60
70
  });
61
71
  }
62
72
  return errors;
@@ -0,0 +1,6 @@
1
+ import { LLMModel, LLMProvider, ModelParameters } from "@empiricalrun/llm";
2
+ export declare const MODEL_API_KEYS: Record<LLMProvider, string>;
3
+ export declare const DEFAULT_MODEL_PROVIDER: LLMProvider;
4
+ export declare const DEFAULT_MODEL: LLMModel;
5
+ export declare const DEFAULT_MODEL_PARAMETERS: ModelParameters;
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/constants/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAE3E,eAAO,MAAM,cAAc,EAAE,MAAM,CAAC,WAAW,EAAE,MAAM,CAItD,CAAC;AAEF,eAAO,MAAM,sBAAsB,EAAE,WAAsB,CAAC;AAE5D,eAAO,MAAM,aAAa,EAAE,QAAmB,CAAC;AAEhD,eAAO,MAAM,wBAAwB,EAAE,eAEtC,CAAC"}
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DEFAULT_MODEL_PARAMETERS = exports.DEFAULT_MODEL = exports.DEFAULT_MODEL_PROVIDER = exports.MODEL_API_KEYS = void 0;
4
+ exports.MODEL_API_KEYS = {
5
+ google: process.env.GOOGLE_API_KEY || "",
6
+ anthropic: process.env.ANTHROPIC_API_KEY || "",
7
+ openai: process.env.OPENAI_API_KEY || "",
8
+ };
9
+ exports.DEFAULT_MODEL_PROVIDER = "openai";
10
+ exports.DEFAULT_MODEL = "gpt-4o";
11
+ exports.DEFAULT_MODEL_PARAMETERS = {
12
+ temperature: 0.5,
13
+ };
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAOlC,wBAAsB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,iBAiBnE"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAWlC,wBAAsB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,iBAkBnE"}
package/dist/index.js CHANGED
@@ -4,22 +4,27 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.createTest = void 0;
7
+ const llm_1 = require("@empiricalrun/llm");
7
8
  const browsing_1 = require("./agent/browsing");
8
9
  const reporter_1 = require("./bin/reporter");
9
10
  const utils_1 = require("./bin/utils");
10
11
  const client_1 = __importDefault(require("./file/client"));
12
+ process.on("exit", async () => await (0, llm_1.flushAllTraces)());
13
+ process.on("SIGINT", async () => await (0, llm_1.flushAllTraces)());
14
+ process.on("SIGTERM", async () => await (0, llm_1.flushAllTraces)());
11
15
  async function createTest(task, page, test) {
12
16
  const port = process.env.APP_PORT || 3030;
13
17
  const testConfigArg = process.env.TEST_GEN_TOKEN;
14
18
  const { testGenConfigs } = await (0, utils_1.parseCliArgs)(testConfigArg);
15
19
  const [testGenConfig] = testGenConfigs;
16
- (0, reporter_1.setReporterConfig)(testGenConfig?.options?.metadata);
20
+ (0, reporter_1.setReporterConfig)(testGenConfig.options?.metadata);
17
21
  const fileService = new client_1.default(Number(port));
18
22
  test.setTimeout(900000);
19
23
  const code = await (0, browsing_1.browsingAgent)(task, page, {
20
24
  htmlSanitize: {
21
25
  disallowedStrings: ["v-data-table__td v-data-table-column--align-start"],
22
26
  },
27
+ ...testGenConfig.options,
23
28
  });
24
29
  await fileService.updateTest({
25
30
  task,
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/session/index.ts"],"names":[],"mappings":"AAKA,iBAAS,iBAAiB;;;EAKzB;AAED,OAAO,EAAE,iBAAiB,EAAE,CAAC"}
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.getSessionDetails = void 0;
7
7
  const crypto_1 = __importDefault(require("crypto"));
8
- const package_json_1 = __importDefault(require("./../../../package.json"));
8
+ const package_json_1 = __importDefault(require("./../../package.json"));
9
9
  const sessionId = crypto_1.default.randomUUID();
10
10
  function getSessionDetails() {
11
11
  return {
@@ -1,3 +1,4 @@
1
+ import { LLMModel, LLMProvider, ModelParameters } from "@empiricalrun/llm";
1
2
  import OpenAI from "openai";
2
3
  import { Page } from "playwright";
3
4
  export type FileContent = {
@@ -6,9 +7,10 @@ export type FileContent = {
6
7
  };
7
8
  export type TestGenConfigOptions = {
8
9
  agent: "code" | "browser";
9
- model: string;
10
+ model: LLMModel;
11
+ modelProvider: LLMProvider;
12
+ modelParameters?: ModelParameters;
10
13
  metadata: {
11
- apiToken: string;
12
14
  testSessionId: number;
13
15
  testCaseName: string;
14
16
  projectRepoName: string;
@@ -31,8 +33,8 @@ export type Action = {
31
33
  schema: ActionSchema;
32
34
  execute: (args: Record<string, any>) => Promise<{
33
35
  locator: string;
34
- } | void | undefined>;
35
- template: (args: Record<string, any>, options?: {
36
+ } | void>;
37
+ template: (args: Record<string, any>, options: {
36
38
  locator: string;
37
39
  }) => string;
38
40
  };
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAElC,MAAM,MAAM,WAAW,GAAG;IACxB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG;IACjC,KAAK,EAAE,MAAM,GAAG,SAAS,CAAC;IAC1B,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE;QACR,QAAQ,EAAE,MAAM,CAAC;QACjB,aAAa,EAAE,MAAM,CAAC;QACtB,YAAY,EAAE,MAAM,CAAC;QACrB,eAAe,EAAE,MAAM,CAAC;KACzB,CAAC;CACH,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IAC1B,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,QAAQ,EAAE,CAAC;IACtB,OAAO,CAAC,EAAE,oBAAoB,CAAC;CAChC,CAAC;AAEF,MAAM,MAAM,QAAQ,GAAG;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,yBAAyB,GAAG,CAAC,IAAI,EAAE,IAAI,KAAK,MAAM,CAAC;AAE/D,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,kBAAkB,CAAC;AAEtE,MAAM,MAAM,MAAM,GAAG;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,YAAY,CAAC;IACrB,OAAO,EAAE,CACP,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KACtB,OAAO,CAAC;QAAE,OAAO,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,GAAG,SAAS,CAAC,CAAC;IACrD,QAAQ,EAAE,CACR,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EACzB,OAAO,CAAC,EAAE;QAAE,OAAO,EAAE,MAAM,CAAA;KAAE,KAC1B,MAAM,CAAC;CACb,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAC3E,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAElC,MAAM,MAAM,WAAW,GAAG;IACxB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG;IACjC,KAAK,EAAE,MAAM,GAAG,SAAS,CAAC;IAC1B,KAAK,EAAE,QAAQ,CAAC;IAChB,aAAa,EAAE,WAAW,CAAC;IAC3B,eAAe,CAAC,EAAE,eAAe,CAAC;IAClC,QAAQ,EAAE;QACR,aAAa,EAAE,MAAM,CAAC;QACtB,YAAY,EAAE,MAAM,CAAC;QACrB,eAAe,EAAE,MAAM,CAAC;KACzB,CAAC;CACH,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IAC1B,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,QAAQ,EAAE,CAAC;IACtB,OAAO,CAAC,EAAE,oBAAoB,CAAC;CAChC,CAAC;AAEF,MAAM,MAAM,QAAQ,GAAG;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,yBAAyB,GAAG,CAAC,IAAI,EAAE,IAAI,KAAK,MAAM,CAAC;AAE/D,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,kBAAkB,CAAC;AAEtE,MAAM,MAAM,MAAM,GAAG;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,YAAY,CAAC;IACrB,OAAO,EAAE,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAAK,OAAO,CAAC;QAAE,OAAO,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAC,CAAC;IAC5E,QAAQ,EAAE,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,OAAO,EAAE;QAAE,OAAO,EAAE,MAAM,CAAA;KAAE,KAAK,MAAM,CAAC;CAC/E,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"exec.d.ts","sourceRoot":"","sources":["../../src/utils/exec.ts"],"names":[],"mappings":"AAGA,wBAAgB,GAAG,CACjB,OAAO,EAAE,MAAM,EAAE,EACjB,OAAO,EAAE;IAAE,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAAE,GACxC,OAAO,CAAC,MAAM,CAAC,CAejB"}
1
+ {"version":3,"file":"exec.d.ts","sourceRoot":"","sources":["../../src/utils/exec.ts"],"names":[],"mappings":"AAGA,wBAAgB,GAAG,CACjB,OAAO,EAAE,MAAM,EAAE,EACjB,OAAO,EAAE;IAAE,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAAE,GACxC,OAAO,CAAC,MAAM,CAAC,CAyBjB"}
@@ -7,18 +7,29 @@ exports.cmd = void 0;
7
7
  const child_process_1 = require("child_process");
8
8
  const process_1 = __importDefault(require("process"));
9
9
  function cmd(command, options) {
10
- return new Promise((resolveFunc) => {
10
+ let lastLog = "";
11
+ return new Promise((resolveFunc, rejectFunc) => {
11
12
  let p = (0, child_process_1.spawn)(command[0], command.slice(1), {
12
13
  env: { ...process_1.default.env, ...options.env },
13
14
  });
14
15
  p.stdout.on("data", (x) => {
15
- process_1.default.stdout.write(x.toString());
16
+ const log = x.toString();
17
+ process_1.default.stdout.write(log);
18
+ lastLog = log;
16
19
  });
17
20
  p.stderr.on("data", (x) => {
21
+ const log = x.toString();
18
22
  process_1.default.stderr.write(x.toString());
23
+ lastLog = log;
19
24
  });
20
25
  p.on("exit", (code) => {
21
- resolveFunc(code);
26
+ if (code != 0) {
27
+ // assuming last log is the error message before exiting
28
+ rejectFunc(lastLog);
29
+ }
30
+ else {
31
+ resolveFunc(code);
32
+ }
22
33
  });
23
34
  });
24
35
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@empiricalrun/test-gen",
3
- "version": "0.15.1",
3
+ "version": "0.16.3",
4
4
  "publishConfig": {
5
5
  "registry": "https://registry.npmjs.org/",
6
6
  "access": "public"
@@ -25,8 +25,6 @@
25
25
  "google-auth-library": "^9.10.0",
26
26
  "google-spreadsheet": "^4.1.2",
27
27
  "ignore": "^5.3.1",
28
- "langfuse": "^3.11.2",
29
- "langfuse-core": "^3.11.2",
30
28
  "minimatch": "^10.0.1",
31
29
  "openai": "^4.47.2",
32
30
  "picocolors": "^1.0.1",
@@ -36,6 +34,7 @@
36
34
  "slugify": "^1.6.6",
37
35
  "tsx": "^4.16.2",
38
36
  "typescript": "^5.3.3",
37
+ "@empiricalrun/llm": "^0.2.0",
39
38
  "@empiricalrun/reporter": "^0.11.0"
40
39
  },
41
40
  "devDependencies": {
@@ -1,9 +0,0 @@
1
- import OpenAI from "openai";
2
- import LLMTracing from "./trace";
3
- export declare function getLLMResult({ messages, trace, tools, tool_choice, }: {
4
- messages: OpenAI.Chat.Completions.ChatCompletionMessageParam[];
5
- trace?: LLMTracing;
6
- tools?: OpenAI.Chat.Completions.ChatCompletionTool[];
7
- tool_choice?: OpenAI.Chat.Completions.ChatCompletionToolChoiceOption;
8
- }): Promise<OpenAI.Chat.Completions.ChatCompletionMessage | undefined>;
9
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/bin/ai/index.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAE5B,OAAO,UAAU,MAAM,SAAS,CAAC;AAEjC,wBAAsB,YAAY,CAAC,EACjC,QAAQ,EACR,KAAK,EACL,KAAK,EACL,WAAW,GACZ,EAAE;IACD,QAAQ,EAAE,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,0BAA0B,EAAE,CAAC;IAC/D,KAAK,CAAC,EAAE,UAAU,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,kBAAkB,EAAE,CAAC;IACrD,WAAW,CAAC,EAAE,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,8BAA8B,CAAC;CACtE,GAAG,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,qBAAqB,GAAG,SAAS,CAAC,CAsBrE"}
@@ -1,31 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getLLMResult = void 0;
7
- const openai_1 = __importDefault(require("openai"));
8
- async function getLLMResult({ messages, trace, tools, tool_choice, }) {
9
- const openai = new openai_1.default();
10
- const model = "gpt-4o";
11
- const parameters = {
12
- temperature: 0.5,
13
- };
14
- const generation = trace?.startGeneration({
15
- name: "get-llm-result",
16
- model,
17
- parameters,
18
- input: messages,
19
- });
20
- const completion = await openai.chat.completions.create({
21
- messages,
22
- model,
23
- tools,
24
- ...parameters,
25
- tool_choice,
26
- });
27
- const output = completion.choices[0]?.message;
28
- generation?.end({ output });
29
- return output;
30
- }
31
- exports.getLLMResult = getLLMResult;
@@ -1,9 +0,0 @@
1
- import OpenAI from "openai";
2
- export declare function getPrompt(name: string, vars: any): Promise<OpenAI.Chat.Completions.ChatCompletionMessageParam[]>;
3
- export declare function getPromptForNextAction({ pageSnapshot, task, previousActions, lastActionErrors, }: {
4
- pageSnapshot: string;
5
- task: string;
6
- previousActions: string[];
7
- lastActionErrors: string[];
8
- }): Promise<OpenAI.Chat.Completions.ChatCompletionMessageParam[]>;
9
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/bin/ai/prompts/provider/index.ts"],"names":[],"mappings":"AACA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAS5B,wBAAsB,SAAS,CAC7B,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,GAAG,GACR,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,0BAA0B,EAAE,CAAC,CAI/D;AAGD,wBAAsB,sBAAsB,CAAC,EAC3C,YAAiB,EACjB,IAAS,EACT,eAAoB,EACpB,gBAAqB,GACtB,EAAE;IACD,YAAY,EAAE,MAAM,CAAC;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,eAAe,EAAE,MAAM,EAAE,CAAC;IAC1B,gBAAgB,EAAE,MAAM,EAAE,CAAC;CAC5B,iEASA"}
@@ -1,28 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getPromptForNextAction = exports.getPrompt = void 0;
4
- const langfuse_1 = require("langfuse");
5
- const langfuse = new langfuse_1.Langfuse({
6
- secretKey: "sk-lf-30eee545-9c2c-4646-bfd9-8f38acf2fa8f",
7
- publicKey: "pk-lf-c5c7cf23-de76-4098-ad81-594bce7cf330",
8
- baseUrl: "https://us.cloud.langfuse.com",
9
- flushAt: 1,
10
- });
11
- async function getPrompt(name, vars) {
12
- const prompt = await langfuse.getPrompt(name, undefined, { type: "chat" });
13
- const compiledPrompt = prompt.compile(vars);
14
- return compiledPrompt;
15
- }
16
- exports.getPrompt = getPrompt;
17
- // TODO: move this prompt to langfuse
18
- async function getPromptForNextAction({ pageSnapshot = "", task = "", previousActions = [], lastActionErrors = [], }) {
19
- const previousActionsStr = previousActions.join("\n\n ---- \n\n");
20
- const prompt = await getPrompt("browsing-agent-next-action", {
21
- pageSnapshot,
22
- previousActionsStr,
23
- task,
24
- lastActionErrors,
25
- });
26
- return prompt;
27
- }
28
- exports.getPromptForNextAction = getPromptForNextAction;
@@ -1,37 +0,0 @@
1
- import OpenAI from "openai";
2
- export default class LLMTracing {
3
- private trace;
4
- constructor({ name }: {
5
- name: string;
6
- });
7
- get id(): string;
8
- get url(): string;
9
- event({ name, input, metadata, output, }: {
10
- name: string;
11
- input?: any;
12
- metadata?: any;
13
- output?: any;
14
- }): void;
15
- update({ input, output, metadata, }: {
16
- input?: any;
17
- output?: any;
18
- metadata?: any;
19
- }): void;
20
- startSpan(name: string, input?: Record<string, any>, metadata?: Record<string, any>): {
21
- end: ({ output }: {
22
- output: Record<string, any>;
23
- }) => void;
24
- };
25
- startGeneration({ name, model, parameters, input, }: {
26
- name: string;
27
- model: string;
28
- parameters: Record<string, any>;
29
- input: any;
30
- }): {
31
- end: ({ output, usage, }: {
32
- output: any;
33
- usage?: OpenAI.Completions.CompletionUsage | undefined;
34
- }) => void;
35
- };
36
- }
37
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/bin/ai/trace/index.ts"],"names":[],"mappings":"AACA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAe5B,MAAM,CAAC,OAAO,OAAO,UAAU;IAC7B,OAAO,CAAC,KAAK,CAAsB;gBACvB,EAAE,IAAI,EAAE,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE;IAStC,IAAI,EAAE,WAEL;IAED,IAAI,GAAG,WAEN;IAED,KAAK,CAAC,EACJ,IAAI,EACJ,KAAK,EACL,QAAQ,EACR,MAAM,GACP,EAAE;QACD,IAAI,EAAE,MAAM,CAAC;QACb,KAAK,CAAC,EAAE,GAAG,CAAC;QACZ,QAAQ,CAAC,EAAE,GAAG,CAAC;QACf,MAAM,CAAC,EAAE,GAAG,CAAC;KACd;IAID,MAAM,CAAC,EACL,KAAU,EACV,MAAW,EACX,QAAa,GACd,EAAE;QACD,KAAK,CAAC,EAAE,GAAG,CAAC;QACZ,MAAM,CAAC,EAAE,GAAG,CAAC;QACb,QAAQ,CAAC,EAAE,GAAG,CAAC;KAChB;IAID,SAAS,CACP,IAAI,EAAE,MAAM,EACZ,KAAK,GAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAM,EAC/B,QAAQ,GAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAM;;oBAIJ,OAAO,MAAM,EAAE,GAAG,CAAC;;;IAMnD,eAAe,CAAC,EACd,IAAS,EACT,KAAU,EACV,UAAe,EACf,KAAU,GACX,EAAE;QACD,IAAI,EAAE,MAAM,CAAC;QACb,KAAK,EAAE,MAAM,CAAC;QACd,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;QAChC,KAAK,EAAE,GAAG,CAAC;KACZ;;oBAYa,GAAG;;cAET,IAAI;;CAcb"}
@@ -1,67 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const langfuse_1 = require("langfuse");
4
- const session_1 = require("../../session");
5
- const langfuse = new langfuse_1.Langfuse({
6
- secretKey: "sk-lf-30eee545-9c2c-4646-bfd9-8f38acf2fa8f",
7
- publicKey: "pk-lf-c5c7cf23-de76-4098-ad81-594bce7cf330",
8
- baseUrl: "https://us.cloud.langfuse.com",
9
- flushAt: 1,
10
- });
11
- process.on("exit", async () => await langfuse.flushAsync());
12
- process.on("SIGINT", async () => await langfuse.flushAsync());
13
- process.on("SIGTERM", async () => await langfuse.flushAsync());
14
- class LLMTracing {
15
- trace;
16
- constructor({ name }) {
17
- const sessionDetails = (0, session_1.getSessionDetails)();
18
- this.trace = langfuse.trace({
19
- name,
20
- sessionId: sessionDetails.id,
21
- release: sessionDetails.version,
22
- });
23
- }
24
- get id() {
25
- return this.trace.traceId;
26
- }
27
- get url() {
28
- return this.trace.getTraceUrl();
29
- }
30
- event({ name, input, metadata, output, }) {
31
- this.trace.event({ name, input, metadata, output });
32
- }
33
- update({ input = {}, output = {}, metadata = {}, }) {
34
- this.trace.update({ input, output, metadata });
35
- }
36
- startSpan(name, input = {}, metadata = {}) {
37
- const span = this.trace.span({ name, metadata, input });
38
- return {
39
- end: ({ output }) => {
40
- span.end({ output });
41
- },
42
- };
43
- }
44
- startGeneration({ name = "", model = "", parameters = {}, input = {}, }) {
45
- const generation = this.trace.generation({
46
- name,
47
- model,
48
- modelParameters: parameters,
49
- input,
50
- });
51
- return {
52
- end: ({ output, usage, }) => {
53
- generation.end({
54
- output,
55
- usage: usage
56
- ? {
57
- promptTokens: usage.prompt_tokens,
58
- completionTokens: usage.completion_tokens,
59
- totalTokens: usage.total_tokens,
60
- }
61
- : undefined,
62
- });
63
- },
64
- };
65
- }
66
- }
67
- exports.default = LLMTracing;
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/bin/session/index.ts"],"names":[],"mappings":"AAKA,iBAAS,iBAAiB;;;EAKzB;AAED,OAAO,EAAE,iBAAiB,EAAE,CAAC"}
File without changes