donobu 2.52.0 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/README.md +100 -100
  2. package/dist/assets/generated/version +1 -1
  3. package/dist/esm/assets/generated/version +1 -1
  4. package/dist/esm/exceptions/PageAiException.d.ts +2 -1
  5. package/dist/esm/exceptions/PageAiException.d.ts.map +1 -1
  6. package/dist/esm/exceptions/PageAiException.js +10 -2
  7. package/dist/esm/exceptions/PageAiException.js.map +1 -1
  8. package/dist/esm/lib/DonobuExtendedPage.d.ts +75 -100
  9. package/dist/esm/lib/DonobuExtendedPage.d.ts.map +1 -1
  10. package/dist/esm/lib/PageAi.d.ts +10 -6
  11. package/dist/esm/lib/PageAi.d.ts.map +1 -1
  12. package/dist/esm/lib/PageAi.js +3 -10
  13. package/dist/esm/lib/PageAi.js.map +1 -1
  14. package/dist/esm/lib/SmartSelector.d.ts +16 -15
  15. package/dist/esm/lib/SmartSelector.d.ts.map +1 -1
  16. package/dist/esm/lib/SmartSelector.js +20 -7
  17. package/dist/esm/lib/SmartSelector.js.map +1 -1
  18. package/dist/esm/lib/createDonobuExtendedPage.d.ts.map +1 -1
  19. package/dist/esm/lib/createDonobuExtendedPage.js +103 -136
  20. package/dist/esm/lib/createDonobuExtendedPage.js.map +1 -1
  21. package/dist/esm/lib/pageAi/cache.d.ts +1 -1
  22. package/dist/esm/managers/CodeGenerator.d.ts.map +1 -1
  23. package/dist/esm/managers/CodeGenerator.js +58 -28
  24. package/dist/esm/managers/CodeGenerator.js.map +1 -1
  25. package/dist/esm/tools/CreateBrowserCookieReportTool.d.ts +17 -0
  26. package/dist/esm/tools/CreateBrowserCookieReportTool.d.ts.map +1 -1
  27. package/dist/esm/tools/CreateBrowserCookieReportTool.js +26 -32
  28. package/dist/esm/tools/CreateBrowserCookieReportTool.js.map +1 -1
  29. package/dist/esm/tools/RunAccessibilityTestTool.d.ts +6 -0
  30. package/dist/esm/tools/RunAccessibilityTestTool.d.ts.map +1 -1
  31. package/dist/esm/tools/RunAccessibilityTestTool.js.map +1 -1
  32. package/dist/exceptions/PageAiException.d.ts +2 -1
  33. package/dist/exceptions/PageAiException.d.ts.map +1 -1
  34. package/dist/exceptions/PageAiException.js +10 -2
  35. package/dist/exceptions/PageAiException.js.map +1 -1
  36. package/dist/lib/DonobuExtendedPage.d.ts +75 -100
  37. package/dist/lib/DonobuExtendedPage.d.ts.map +1 -1
  38. package/dist/lib/PageAi.d.ts +10 -6
  39. package/dist/lib/PageAi.d.ts.map +1 -1
  40. package/dist/lib/PageAi.js +3 -10
  41. package/dist/lib/PageAi.js.map +1 -1
  42. package/dist/lib/SmartSelector.d.ts +16 -15
  43. package/dist/lib/SmartSelector.d.ts.map +1 -1
  44. package/dist/lib/SmartSelector.js +20 -7
  45. package/dist/lib/SmartSelector.js.map +1 -1
  46. package/dist/lib/createDonobuExtendedPage.d.ts.map +1 -1
  47. package/dist/lib/createDonobuExtendedPage.js +103 -136
  48. package/dist/lib/createDonobuExtendedPage.js.map +1 -1
  49. package/dist/lib/pageAi/cache.d.ts +1 -1
  50. package/dist/managers/CodeGenerator.d.ts.map +1 -1
  51. package/dist/managers/CodeGenerator.js +58 -28
  52. package/dist/managers/CodeGenerator.js.map +1 -1
  53. package/dist/tools/CreateBrowserCookieReportTool.d.ts +17 -0
  54. package/dist/tools/CreateBrowserCookieReportTool.d.ts.map +1 -1
  55. package/dist/tools/CreateBrowserCookieReportTool.js +26 -32
  56. package/dist/tools/CreateBrowserCookieReportTool.js.map +1 -1
  57. package/dist/tools/RunAccessibilityTestTool.d.ts +6 -0
  58. package/dist/tools/RunAccessibilityTestTool.d.ts.map +1 -1
  59. package/dist/tools/RunAccessibilityTestTool.js.map +1 -1
  60. package/package.json +1 -1
package/README.md CHANGED
@@ -1,121 +1,121 @@
1
- # Donobu
1
+ # Donobu SDK
2
2
 
3
- This package allows people to create, edit, and run Playwright scripts using [Donobu](https://donobu.com).
3
+ Create, run, and heal AI-assisted Playwright flows with a single dependency. The `donobu` package ships the Playwright fixture, Page.AI orchestration layer, CLI wrapper, failure triage, and plugin system to comprehensively test websites.
4
4
 
5
- Donobu extends the standard Playwright test fixture to include capabilities like:
5
+ ## Highlights
6
6
 
7
- - Adding prioritized failover for when standard one-shot selectors fail when clicking, inputting text, etc.
8
- - Performing selector-less visual/semantic assertions on a page.
9
- - Creating a browser cookie report for a page (`page.createCookieReport()`).
10
- - Running an accessibility test for a page (`page.runAccessibilityTest()`).
7
+ - **Typed Playwright fixture** - `import { test } from 'donobu'` to extend Playwright with `page.ai` helpers, smart selectors, and persistence.
8
+ - **Autonomous Page.AI** - run `page.ai.act()` with optional Zod schemas, cached tool-call replays, custom tool allow-lists, and env-var controls.
9
+ - **Prebuilt tools** - call keyboard, mouse, accessibility, cookie, and analysis tools via friendly wrappers (`page.runAccessibilityTest`, etc).
10
+ - **Failure triage & auto-heal** - `npx donobu test --auto-heal` captures screenshots, GPT reasoning, structured treatment plans, and can re-run fixes automatically.
11
11
 
12
- ## Setup
12
+ ## Prerequisites
13
13
 
14
- 1. `npm install donobu`
15
- 2. `npx playwright install`
14
+ - Node.js 18+ and npm 8+.
15
+ - Playwright browsers (`npx playwright install`).
16
+ - At least one LLM credential (OpenAI, Anthropic, Google Gemini, AWS Bedrock, or Donobu API).
16
17
 
17
- ## Example
18
+ ## Installation
18
19
 
19
- ```typescript
20
- /**
21
- * Be sure that Donobu is installed before running this script...
22
- * 'npm install donobu' or 'yarn add donobu'
23
- *
24
- * Also, be sure that Playwright's browsers are installed...
25
- * 'npx playwright install'
26
- *
27
- * Also, since this test is using tools that require the usage of an LLM, be
28
- * sure to have an appropriate LLM API key available as an environment variable
29
- * (e.g. OPENAI_API_KEY, ANTHROPIC_API_KEY, etc).
30
- */
31
- import { test } from 'donobu';
32
- import { gptClientFixture } from 'donobu';
33
-
34
- const testTitle = 'Test for https://news.ycombinator.com';
35
- const testDetails = {
36
- annotation: {
37
- type: 'objective',
38
- description: `Scroll down to find the search box and then do a search for "mac app for web testing".
39
- Assert that one of the top search results is for "Donobu".`,
40
- },
41
- };
42
- test.extend({ gptClient: gptClientFixture() })(
43
- testTitle,
44
- testDetails,
45
- async ({ page }) => {
46
- // Initializing web navigation.
47
- await page.goto('https://news.ycombinator.com');
48
- // Scrolling down to find the search box which appears to be at the bottom of the page based on the preview image.
49
- await page.scroll({
50
- direction: 'DOWN',
51
- });
52
- // Inputting the search query "mac app for web testing" into the search box at the bottom of the page to fulfill the objective.
53
- await page.inputText({
54
- finalizeWithSubmit: true,
55
- text: 'mac app for web testing',
56
- selector: {
57
- element: [
58
- 'form > :nth-child(1)',
59
- 'form > input:nth-of-type(1)',
60
- 'input',
61
- ],
62
- frame: null,
63
- },
64
- });
65
- // Verifying that Donobu appears in the search results for "mac app for web testing" to fulfill the objective.
66
- await page.assertPageText({
67
- text: 'Show HN: Donobu – Mac App for Web Automation and Testing',
68
- });
69
- },
70
- );
20
+ ```bash
21
+ npm install --save-dev donobu @playwright/test
22
+ npx playwright install # downloads browsers if needed
71
23
  ```
72
24
 
73
- [See additional examples in this repository](https://github.com/donobu-inc/playwright-flows).
25
+ ## Quick Start
74
26
 
75
- ## Compound Self Healing
27
+ 1. **Author a test using the Donobu fixture**
76
28
 
77
- Donobu supports two layers of self healing.
29
+ ```ts
30
+ import { test } from 'donobu';
78
31
 
79
- ### Automatic Selector Failover
32
+ test('Test for https://www.starbucks.com', async ({ page }) => {
33
+ await page.goto('https://www.starbucks.com');
34
+ await page.ai.act('Go to the featured menu page');
35
+ await page.ai.assertPage(
36
+ `Assert that the featured menu page has a seasonally appropriate vibe for ${new Date()}`,
37
+ );
38
+ await page.ai.act('Find a Starbucks store in Stowe, Vermont');
39
+ await page.ai.assertPage(
40
+ 'Assert that a store in Stowe, Vermont is found and the map shows Mt. Mansfield close by.',
41
+ );
42
+ });
43
+ ```
80
44
 
81
- When generating code using the [Donobu Application](https://www.donobu.com/download), the generated
82
- code will include a prioritized list of query selectors to attempt to use when interacting with a particular
83
- element in a website. Here is an example of a code snippet that uses prioritized selectors...
45
+ 2. **Run the test with Page.AI enabled**
84
46
 
85
- ```
86
- await page.inputText({
87
- finalizeWithSubmit: true,
88
- text: 'mac app for web testing',
89
- selector: {
90
- element: [
91
- 'form > :nth-child(1)',
92
- 'form > input:nth-of-type(1)',
93
- 'input',
94
- ],
95
- frame: null,
96
- },
97
- });
47
+ ```bash
48
+ OPENAI_API_KEY=sk-*** npx donobu test
98
49
  ```
99
50
 
100
- In the above example, `['form > :nth-child(1)', 'form > input:nth-of-type(1)', 'input']`, is the prioritized
101
- selector queries. The first selector query will be attempted to be resolved and will have the text `mac app for web testing`
102
- inputted to it, if that fails, it tries the next query selector, and so on.
51
+ `npx donobu test` proxies Playwright while wiring Donobu-specific env vars (triage directories, Page.AI cache clearing, auto-heal retries, etc.).
103
52
 
104
- ### Automatic Testfile Updates
53
+ ### Page.AI API Surface
105
54
 
106
- When running code that was generated the [Donobu Application](https://www.donobu.com/download), the generated
107
- code can attempt to update itself if the test case itself flatly fails (e.g. automatic selector failover
108
- entirely fails due to the underlying website materially changing). In this case, Donobu will attempt to
109
- re-run the test using an AI agent to help it through, then update the test file as necessary. This method of
110
- self healing is optional, and opt-in.
55
+ | Method | Description | Key options |
56
+ | -------------------------------------------- | ----------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------ |
57
+ | `await page.ai.act(instruction, opts?)` | Launches an autonomous Donobu flow that can call browser tools and GPT. | `schema` (Zod) for structured output, `allowedTools`, `maxToolCalls` (default 25), `cache` (default `true`), `envVars`, `gptClient`. |
58
+ | `await page.ai.assertPage(assertion, opts?)` | AI assertion against DOM text, screenshot, title, and URL. | `retries`, `retryDelaySeconds`, `gptClient`. |
59
+ | `await page.ai.extract(schema, opts?)` | Produce JSON data shaped by a Zod schema using screenshot + history. | `instruction`, `gptClient`. |
111
60
 
112
- To use this feature, run the the test with the `SELF_HEAL_TESTS_ENABLED` environment variable set to `true`,
113
- and have an LLM API key set up (of which can also be done via an environment variable).
61
+ - Every invocation is cached by URL+instruction+schema in `<spec directory>/donobu.json`. Call `await page._dnb.pageAi?.invalidate(...)` or run `npx donobu test --clear-ai-cache` to regenerate tool calls.
62
+ - Provide a custom LLM by passing `gptClient` (a Donobu `GptClient` or any `LanguageModel` supported by `ai`’s Vercel SDK).
63
+ - Use `envVars` to explicitly pass secret names the flow may read. Donobu also parses `$.env.SECRET_NAME` placeholders in the `objective` annotation to whitelist secrets.
114
64
 
115
- Here is an example terminal command:
65
+ ## Page.AI Caching, Env Vars, and Secrets
116
66
 
117
- ```
118
- SELF_HEAL_TESTS_ENABLED=true \
119
- ANTHROPIC_API_KEY=your-api-key \
120
- npx playwright test your-test.ts
121
- ```
67
+ - Per-spec cache: Page.AI cache entries are saved next to the spec (`donobu.json`). Commit them to stabilise selectors or delete to regenerate.
68
+ - CLI toggles: `--clear-ai-cache` (or `DONOBU_PAGE_AI_CLEAR_CACHE=1`) clears cache before each `page.ai.act`.
69
+ - Whitelisting env vars: add `$.env.MY_SECRET` inside the objective or annotate tests manually:
70
+ ```ts
71
+ test('uses secret', async ({ page }, testInfo) => {
72
+ testInfo.annotations.push({ type: 'ENV', description: 'MY_SECRET' });
73
+ await page.ai.act('Log in using $.env.MY_SECRET credentials');
74
+ });
75
+ ```
76
+ Only listed env vars are exposed to the agent.
77
+
78
+ ## CLI Usage
79
+
80
+ `npx donobu` mirrors Playwright subcommands and adds Donobu-specific tooling.
81
+
82
+ | Command | What it does |
83
+ | ------------------------------------------------- | ----------------------------------------------------------------------------------------------------- |
84
+ | `npx donobu test [playwright args]` | Runs Playwright tests with Donobu fixtures, triage, optional auto-heal, and Page.AI caching controls. |
85
+ | `npx donobu test --auto-heal` | After failures, generate treatment plans and automatically retry tests whose plans recommend it. |
86
+ | `npx donobu test --no-triage` | Skip evidence gathering (faster but no treatment plans). |
87
+ | `npx donobu test --triage-output-dir ./artifacts` | Persist evidence outside `test-results/donobu-triage`. |
88
+ | `npx donobu test --clear-ai-cache` | Clear Page.AI cache before every `act()` invocation for the run. |
89
+ | `npx donobu heal --plan path/to/plan.json` | Re-run a previously generated treatment plan with matching Playwright args. |
90
+ | `npx playwright-json-to-markdown report.json` | Convert Playwright JSON reports into human-friendly Markdown. |
91
+ | `npx playwright-json-to-slack-json report.json` | Produce Slack-ready payloads from Playwright reports. |
92
+
93
+ ### Failure Evidence & Auto-Heal
94
+
95
+ - During `donobu test`, failure evidence (flow metadata, screenshots, DOM dumps, GPT summaries) is stored under `test-results/donobu-triage/<timestamp>-<runId>/`.
96
+ - `triageTestFailure` builds a structured treatment plan containing failure reason, remediation steps, and automation directives. Plans are written next to the evidence (prefixed with `treatment-plan-`).
97
+ - Passing `--auto-heal` lets Donobu run an autonomous flow that attempts to fix selectors/code. Successful fixes attach regenerated tests (`fixed-test.ts`) and annotate runs with `@self-healed`.
98
+
99
+ ## GPT Configuration
100
+
101
+ Donobu selects a GPT backend in the following priority order:
102
+
103
+ 1. `BASE64_GPT_CONFIG` - Base64 JSON matching `GptConfigSchema`.
104
+ 2. `DONOBU_API_KEY` - use Donobu hosted models.
105
+ 3. Anthropic via AWS Bedrock (`AWS_BEDROCK_MODEL_NAME`, `AWS_REGION`, `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY`).
106
+ 4. Anthropic direct (`ANTHROPIC_API_KEY`, optional `ANTHROPIC_MODEL_NAME`).
107
+ 5. Google Gemini (`GOOGLE_GENERATIVE_AI_API_KEY`, optional `GOOGLE_GENERATIVE_AI_MODEL_NAME`).
108
+ 6. OpenAI (`OPENAI_API_KEY`, optional `OPENAI_API_MODEL_NAME`).
109
+
110
+ Additional runtime env vars:
111
+
112
+ | Env var | Purpose |
113
+ | ------------------------------------------------ | ---------------------------------------------------------------- |
114
+ | `DONOBU_PAGE_AI_CLEAR_CACHE` | Force cache invalidation for every `page.ai.act`. |
115
+ | `BASE_WORKING_DIR` | Override the platform-specific Donobu data directory. |
116
+ | `BROWSERBASE_API_KEY` / `BROWSERBASE_PROJECT_ID` | Run flows inside BrowserBase sessions instead of local Chromium. |
117
+
118
+ ## Additional Resources
119
+
120
+ - Example flows and generated tests: <https://github.com/donobu-inc/playwright-flows>
121
+ - Support: <https://donobu.com>
@@ -1 +1 @@
1
- 1427
1
+ 1428
@@ -1 +1 @@
1
- 1427
1
+ 1428
@@ -4,7 +4,8 @@ import type { FlowMetadata } from '../main';
4
4
  * finishes to a state that is not {@link State.SUCCESS}.
5
5
  */
6
6
  export declare class PageAiException extends Error {
7
+ readonly originalInstruction: string;
7
8
  readonly metadata: FlowMetadata;
8
- constructor(metadata: FlowMetadata);
9
+ constructor(originalInstruction: string, metadata: FlowMetadata);
9
10
  }
10
11
  //# sourceMappingURL=PageAiException.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"PageAiException.d.ts","sourceRoot":"","sources":["../../../src/exceptions/PageAiException.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAE5C;;;GAGG;AACH,qBAAa,eAAgB,SAAQ,KAAK;aACL,QAAQ,EAAE,YAAY;gBAAtB,QAAQ,EAAE,YAAY;CAG1D"}
1
+ {"version":3,"file":"PageAiException.d.ts","sourceRoot":"","sources":["../../../src/exceptions/PageAiException.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAE5C;;;GAGG;AACH,qBAAa,eAAgB,SAAQ,KAAK;aAEtB,mBAAmB,EAAE,MAAM;aAC3B,QAAQ,EAAE,YAAY;gBADtB,mBAAmB,EAAE,MAAM,EAC3B,QAAQ,EAAE,YAAY;CAczC"}
@@ -6,8 +6,16 @@ exports.PageAiException = void 0;
6
6
  * finishes to a state that is not {@link State.SUCCESS}.
7
7
  */
8
8
  class PageAiException extends Error {
9
- constructor(metadata) {
10
- super(JSON.stringify(metadata.result, null, 2));
9
+ constructor(originalInstruction, metadata) {
10
+ const resultDetails = metadata.result
11
+ ? `Result payload:\n${JSON.stringify(metadata.result, null, 2)}`
12
+ : 'No result payload was returned.';
13
+ super([
14
+ `page.ai flow stopped in state ${metadata.state} (expected SUCCESS).`,
15
+ `Original instruction: ${originalInstruction}`,
16
+ resultDetails,
17
+ ].join('\n'));
18
+ this.originalInstruction = originalInstruction;
11
19
  this.metadata = metadata;
12
20
  }
13
21
  }
@@ -1 +1 @@
1
- {"version":3,"file":"PageAiException.js","sourceRoot":"","sources":["../../../src/exceptions/PageAiException.ts"],"names":[],"mappings":";;;AAEA;;;GAGG;AACH,MAAa,eAAgB,SAAQ,KAAK;IACxC,YAAmC,QAAsB;QACvD,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;QADf,aAAQ,GAAR,QAAQ,CAAc;IAEzD,CAAC;CACF;AAJD,0CAIC"}
1
+ {"version":3,"file":"PageAiException.js","sourceRoot":"","sources":["../../../src/exceptions/PageAiException.ts"],"names":[],"mappings":";;;AAEA;;;GAGG;AACH,MAAa,eAAgB,SAAQ,KAAK;IACxC,YACkB,mBAA2B,EAC3B,QAAsB;QAEtC,MAAM,aAAa,GAAG,QAAQ,CAAC,MAAM;YACnC,CAAC,CAAC,oBAAoB,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE;YAChE,CAAC,CAAC,iCAAiC,CAAC;QAEtC,KAAK,CACH;YACE,iCAAiC,QAAQ,CAAC,KAAK,sBAAsB;YACrE,yBAAyB,mBAAmB,EAAE;YAC9C,aAAa;SACd,CAAC,IAAI,CAAC,IAAI,CAAC,CACb,CAAC;QAbc,wBAAmB,GAAnB,mBAAmB,CAAQ;QAC3B,aAAQ,GAAR,QAAQ,CAAc;IAaxC,CAAC;CACF;AAjBD,0CAiBC"}
@@ -8,82 +8,78 @@ import type { BrowserStorageState } from '../models/BrowserStorageState';
8
8
  import type { FlowMetadata } from '../models/FlowMetadata';
9
9
  import type { ToolCallResult } from '../models/ToolCallResult';
10
10
  import type { FlowsPersistence } from '../persistence/flows/FlowsPersistence';
11
- import type { AnalyzePageTextCoreParameters } from '../tools/AnalyzePageTextTool';
12
- import type { AssertPageTextCoreParameters } from '../tools/AssertPageTextTool';
13
- import type { AssertCoreSchema } from '../tools/AssertTool';
14
- import type { ChooseSelectOptionNonGptSchema } from '../tools/ChooseSelectOptionTool';
15
- import type { InputRandomizedEmailAddressNonGptSchema } from '../tools/InputRandomizedEmailAddressTool';
16
- import type { InputTextNonGptSchema } from '../tools/InputTextTool';
17
- import type { PressKeyNonGptSchema } from '../tools/PressKeyTool';
18
- import type { SelectorBasedSchema } from '../tools/ReplayableInteraction';
19
- import type { ScrollPageNonGptSchema } from '../tools/ScrollPageTool';
20
- import type { PageAi, PageAiOptions } from './PageAi';
11
+ import type { CookieAnalyses } from '../tools/CreateBrowserCookieReportTool';
12
+ import type { AccessibilityResults } from '../tools/RunAccessibilityTestTool';
13
+ import type { PageAi, PageAiNoSchemaOptions, PageAiOptions, PageAiSchemaOptions } from './PageAi';
21
14
  import type { SmartSelector } from './SmartSelector';
22
- export type { PageAiOptions };
15
+ export type { PageAiNoSchemaOptions, PageAiOptions, PageAiSchemaOptions };
23
16
  /**
24
17
  * Extends the Page object with additional test-related methods.
25
18
  */
26
19
  export interface DonobuExtendedPage extends Page {
27
- /**
28
- * Launches an autonomous Donobu flow that uses AI to satisfy a natural-language instruction.
29
- * The flow may call Donobu tools and mirrors the metadata recorded for the surrounding test run.
30
- *
31
- * Provide a Zod schema when you want the flow to produce structured output; the AI's response is
32
- * validated against the schema and is returned as the result.
33
- *
34
- * @template T The Zod object schema describing the expected shape of the AI result.
35
- * @param instruction High-level description of what the autonomous flow should accomplish.
36
- * @returns The parsed schema result when a schema is provided; otherwise, void.
37
- * @throws PageAiException if the autonomous flow fails or reaches a terminal non-success state.
38
- */
39
- ai<Schema extends z.ZodObject | undefined = undefined>(instruction: string, options?: PageAiOptions<Schema>): Promise<Schema extends z.ZodObject ? z.infer<Schema> : void>;
40
- /**
41
- * Run an arbitrary Donobu tool by name.
42
- */
43
- run(toolName: string, toolParams?: any, gptClientOverride?: GptClient | LanguageModel): Promise<ToolCallResult>;
44
- /**
45
- * Run an analysis on the current webpage's full raw text. Note that since this runs an analysis on the raw text,
46
- * rather than, the HTML of the page, the raw text may be a bit jumbled, have its styling lost, careful
47
- * positioning lost, etc. This tool is useful if there happens to be a lot of text on a page, and it would be
48
- * tedious to scroll through the entirety of the page in order to get enough context to run an analysis.
49
- *
50
- * If there is context relevant to running the analysis that would not be found in the webpage text itself,
51
- * perhaps context given in another message, prompt, overall object, etc, then provide it in the
52
- * "additionalRelevantContext" parameter.
53
- */
54
- analyzePageText(params: z.infer<typeof AnalyzePageTextCoreParameters>, gptClientOverride?: GptClient | LanguageModel): Promise<ToolCallResult>;
55
- /**
56
- * Assert that given text is visible in the current page.
57
- */
58
- assertPageText(params: z.infer<typeof AssertPageTextCoreParameters>, gptClientOverride?: GptClient | LanguageModel): Promise<ToolCallResult>;
59
- /**
60
- * Checks all of the pages in the current browser context and returns the one
61
- * matching the given URL.
62
- */
63
- changeTab(url: string): Promise<DonobuExtendedPage>;
64
- /**
65
- * Choose <option> values for a particular <select> HTML element.
66
- */
67
- chooseSelectOption(params: z.infer<typeof ChooseSelectOptionNonGptSchema>): Promise<ToolCallResult>;
68
- /**
69
- * Click an element on a webpage.
70
- */
71
- clickElement(params: z.infer<typeof SelectorBasedSchema>): Promise<ToolCallResult>;
72
- /**
73
- * Perform an analysis of the cookies for the current web browsing session.
74
- */
75
- createCookieReport(gptClientOverride?: GptClient | LanguageModel): Promise<ToolCallResult>;
76
- /**
77
- * Return an object conforming to the given Zod schema. The object will be
78
- * generated considering the following:
79
- * - The given instruction (if any).
80
- * - A screenshot of the current state of the page.
81
- * - The history of actions taken on the page.
82
- */
83
- extract<T>(params: {
84
- instruction?: string;
85
- schema: z.ZodSchema<T>;
86
- }, gptClientOverride?: GptClient | LanguageModel): Promise<T>;
20
+ ai: {
21
+ /**
22
+ * Launches an autonomous Donobu flow that uses AI to satisfy a natural-language instruction.
23
+ * The flow may call Donobu tools and mirrors the metadata recorded for the surrounding test run.
24
+ *
25
+ * Provide a Zod schema when you want the flow to produce structured output; the AI's response is
26
+ * validated against the schema and is returned as the result.
27
+ *
28
+ * @template Schema The Zod object schema describing the expected shape of the AI result.
29
+ * @param instruction High-level description of what the autonomous flow should accomplish.
30
+ * @returns The parsed schema result when a schema is provided; otherwise, void.
31
+ * @throws PageAiException if the autonomous flow fails or reaches a terminal non-success state.
32
+ */
33
+ act<Schema extends z.ZodObject>(instruction: string, options?: Omit<PageAiSchemaOptions<Schema>, 'gptClient'> & {
34
+ gptClient?: GptClient | Exclude<LanguageModel, string>;
35
+ }): Promise<z.infer<Schema>>;
36
+ act(instruction: string, options?: Omit<PageAiNoSchemaOptions, 'gptClient'> & {
37
+ gptClient?: GptClient | Exclude<LanguageModel, string>;
38
+ }): Promise<void>;
39
+ /**
40
+ * Assert that a given condition about the current page holds true (or throws).
41
+ * The assertion is evaluated by AI using the context of the current page's...
42
+ * - Textual context
43
+ * - Viewport screenshot
44
+ * - URL
45
+ * - Title
46
+ */
47
+ assertPage(assertion: string, options?: {
48
+ retries?: number;
49
+ retryDelaySeconds?: number;
50
+ gptClient?: GptClient | Exclude<LanguageModel, string>;
51
+ }): Promise<void>;
52
+ /**
53
+ * Return an object conforming to the given Zod schema. The object will be
54
+ * generated considering the following:
55
+ * - The given instruction (if any).
56
+ * - A screenshot of the current state of the page.
57
+ * - The history of key actions taken on the page.
58
+ */
59
+ extract<Schema extends z.ZodObject>(schema: Schema, options?: {
60
+ instruction?: string;
61
+ gptClient?: GptClient | Exclude<LanguageModel, string>;
62
+ }): Promise<z.infer<Schema>>;
63
+ /**
64
+ * Run an analysis on the current webpage's full raw text. Note that since this runs an analysis
65
+ * on the raw text, rather than, the HTML of the page, the raw text may be a bit jumbled,
66
+ * have its styling lost, careful positioning lost, etc.
67
+ *
68
+ * If there is context relevant to running the analysis that would not be found in the webpage
69
+ * text itself, perhaps context given in another message, prompt, overall object, etc, then
70
+ * provide it in the "additionalContext" parameter.
71
+ */
72
+ analyzePageText(analysisToRun: string, options?: {
73
+ additionalContext?: string;
74
+ gptClient?: GptClient | Exclude<LanguageModel, string>;
75
+ }): Promise<string>;
76
+ /**
77
+ * Perform an analysis of the cookies for the current web browsing session.
78
+ */
79
+ createCookieReport(options?: {
80
+ gptClient?: GptClient | Exclude<LanguageModel, string>;
81
+ }): Promise<CookieAnalyses>;
82
+ };
87
83
  /**
88
84
  * Builds a smart selector object that will automatically failover when performing
89
85
  * actions.
@@ -93,41 +89,20 @@ export interface DonobuExtendedPage extends Page {
93
89
  frame?: string;
94
90
  }): SmartSelector;
95
91
  /**
96
- * Hover the mouse over a specified element on a webpage.
97
- */
98
- hoverOverElement(params: z.infer<typeof SelectorBasedSchema>): Promise<ToolCallResult>;
99
- /**
100
- * Create a new randomized email address based on a given email and inputs it to a specific input text field.
101
- * For example if passed "foo@gmail.com", this tool will create "foo+SOMETHING_RANDOM@gmail.com", where
102
- * SOMETHING_RANDOM is a random string of characters safe for use in an email address, and input it in the
103
- * specified text field.
104
- */
105
- inputRandomizedEmailAddress(params: z.infer<typeof InputRandomizedEmailAddressNonGptSchema>): Promise<ToolCallResult>;
106
- /**
107
- * Input text to a webpage's text input box.
92
+ * Run an arbitrary Donobu tool by name.
108
93
  */
109
- inputText(params: z.infer<typeof InputTextNonGptSchema>): Promise<ToolCallResult>;
94
+ run(toolName: string, toolParams?: any, options?: {
95
+ gptClient?: GptClient | Exclude<LanguageModel, string>;
96
+ }): Promise<ToolCallResult>;
110
97
  /**
111
- * Press a single key. Note that if there is existing text in the element, it is appended rather than cleared.
112
- *
113
- * Generally, prefer using the 'inputText' tool instead as it automatically clears existing text
114
- * and it allows the input of multiple characters at a time. The only advantage this tool has is
115
- * that it allows the passing of control keys like "Tab", "Backspace", etc.
98
+ * Checks all of the pages in the current browser context and returns the one
99
+ * matching the given URL.
116
100
  */
117
- pressKey(params: z.infer<typeof PressKeyNonGptSchema>): Promise<ToolCallResult>;
101
+ changeTab(url: string): Promise<DonobuExtendedPage>;
118
102
  /**
119
103
  * Run an web accessibility (i.e. axe-core) test on the current webpage.
120
104
  */
121
- runAccessibilityTest(): Promise<ToolCallResult>;
122
- /**
123
- * Scroll the given element.
124
- */
125
- scroll(params: z.infer<typeof ScrollPageNonGptSchema>): Promise<ToolCallResult>;
126
- /**
127
- * Visually assert that a given condition (i.e. the 'assertionToTestFor' field) holds true, using a screenshot of
128
- * the current webpage.
129
- */
130
- visuallyAssert(params: z.infer<typeof AssertCoreSchema>, gptClientOverride?: GptClient | LanguageModel): Promise<ToolCallResult>;
105
+ runAccessibilityTest(): Promise<AccessibilityResults>;
131
106
  _dnb: {
132
107
  donobuFlowMetadata: FlowMetadata;
133
108
  donobuStack: DonobuStack;
@@ -1 +1 @@
1
- {"version":3,"file":"DonobuExtendedPage.d.ts","sourceRoot":"","sources":["../../../src/lib/DonobuExtendedPage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,IAAI,CAAC;AACxC,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAC;AAC/E,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAC;AACzE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,KAAK,EAAE,gBAAgB,EAA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EAAE,SAAS,GAAG,OAAO,CAAC,aAAa,EAAE,MAAM,CAAC,CAAC;SACxD,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC;KAC7B,CAAC;IACF;;;OAGG;IACH,IAAI,CACF,QAAQ,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE;QAAE,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,GAChD,aAAa,CAAC;IACjB;;OAEG;IACH,GAAG,CACD,QAAQ,EAAE,MAAM,EAChB,UAAU,CAAC,EAAE,GAAG,EAChB,OAAO,CAAC,EAAE;QACR,SAAS,CAAC,EAAE,SAAS,GAAG,OAAO,CAAC,aAAa,EAAE,MAAM,CAAC,CAAC;KACxD,GACA,OAAO,CAAC,cAAc,CAAC,CAAC;IAC3B;;;OAGG;IACH,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAC;IACpD;;OAEG;IACH,oBAAoB,IAAI,OAAO,CAAC,oBAAoB,CAAC,CAAC;IAEtD,IAAI,EAAE;QACJ,kBAAkB,EAAE,YAAY,CAAC;QACjC,WAAW,EAAE,WAAW,CAAC;QACzB,qBAAqB,EAAE,qBAAqB,CAAC;QAC7C,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;QAC3B,WAAW,EAAE,gBAAgB,CAAC;QAC9B,mBAAmB,EAAE,mBAAmB,CAAC;QACzC,SAAS,EAAE,SAAS,GAAG,SAAS,CAAC;QACjC,iBAAiB,CAAC,EAAE;YAClB,gBAAgB,CAAC,EAAE,OAAO,CAAC;SAC5B,CAAC;KACH,CAAC;CACH"}
@@ -17,11 +17,11 @@ import type { PageAiCache } from './pageAi/cache';
17
17
  * - {@link PageAiRunner} sets up the `DonobuFlow` and keeps the persistence
18
18
  * layer in sync. It knows nothing about caches.
19
19
  * - {@link PageAi} glues together the runner with a pluggable cache so that
20
- * consumers (e.g., Playwright fixtures) keep their simple `page.ai(...)`
20
+ * consumers (e.g., Playwright fixtures) keep their simple `page.ai.act(...)`
21
21
  * API while gaining better separation of concerns.
22
22
  *
23
23
  * The documentation in this file attempts to guide new contributors through
24
- * the lifecycle of a single `page.ai` call: resolve cache → run flow →
24
+ * the lifecycle of a single `page.ai.act(...)` call: resolve cache → run flow →
25
25
  * persist metadata → update cache.
26
26
  */
27
27
  type PageAiBaseOptions = {
@@ -29,11 +29,12 @@ type PageAiBaseOptions = {
29
29
  allowedTools?: string[];
30
30
  maxToolCalls?: number;
31
31
  envVars?: string[];
32
+ gptClient?: GptClient;
32
33
  };
33
- type PageAiSchemaOptions<Schema extends z.ZodObject> = PageAiBaseOptions & {
34
+ export type PageAiSchemaOptions<Schema extends z.ZodObject> = PageAiBaseOptions & {
34
35
  schema: Schema;
35
36
  };
36
- type PageAiNoSchemaOptions = PageAiBaseOptions & {
37
+ export type PageAiNoSchemaOptions = PageAiBaseOptions & {
37
38
  schema?: undefined;
38
39
  };
39
40
  export type PageAiOptions<Schema extends z.ZodObject | undefined = undefined> = Schema extends z.ZodObject ? PageAiSchemaOptions<Schema> : PageAiNoSchemaOptions;
@@ -48,6 +49,7 @@ type PageAiRunConfiguration<Schema extends z.ZodObject | undefined> = {
48
49
  envVarNames: string[];
49
50
  cachedToolCalls: ProposedToolCall[] | null;
50
51
  runMode: FlowMetadata['runMode'];
52
+ gptClient: GptClient | undefined;
51
53
  };
52
54
  type PageAiRunResult<Schema extends z.ZodObject | undefined> = {
53
55
  donobuFlow: DonobuFlow;
@@ -107,9 +109,11 @@ export declare class PageAi {
107
109
  static withFileCache(donobu: DonobuStack, gptClient: GptClient, cacheFilepath: string): PageAi;
108
110
  static withInMemoryCache(donobu: DonobuStack, gptClient: GptClient): PageAi;
109
111
  /**
110
- * Public entry point invoked by `page.ai`. Handles cache lookup, delegates to
112
+ * Public entry point invoked by `page.ai.act`. Handles cache lookup, delegates to
111
113
  * the runner, and stores the result back into the cache when appropriate.
112
114
  */
115
+ ai<Schema extends z.ZodObject>(page: DonobuExtendedPage, instruction: string, options: PageAiSchemaOptions<Schema>): Promise<z.infer<Schema>>;
116
+ ai(page: DonobuExtendedPage, instruction: string, options?: PageAiNoSchemaOptions): Promise<void>;
113
117
  ai<Schema extends z.ZodObject | undefined = undefined>(page: DonobuExtendedPage, instruction: string, options?: PageAiOptions<Schema>): Promise<AiResult<Schema>>;
114
118
  /**
115
119
  * Invalidates cache entries matching the provided invocation parameters.
@@ -127,7 +131,7 @@ export declare class PageAi {
127
131
  */
128
132
  private buildDescriptor;
129
133
  /**
130
- * Computes the cache key that uniquely identifies a `page.ai` invocation.
134
+ * Computes the cache key that uniquely identifies a `page.ai.act(...)` invocation.
131
135
  * Keep this logic in sync with any external cache generators (e.g. the code
132
136
  * generator) so that hits and invalidations behave the same everywhere.
133
137
  */
@@ -1 +1 @@
1
- {"version":3,"file":"PageAi.d.ts","sourceRoot":"","sources":["../../../src/lib/PageAi.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,QAAQ,CAAC;AAE3B,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAGtD,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAEpD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAG3D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAEnE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE/D,OAAO,KAAK,EAAE,WAAW,EAAkB,MAAM,gBAAgB,CAAC;AAIlE;;;;;;;;;;;;;;;;;GAiBG;AACH,KAAK,iBAAiB,GAAG;IACvB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,OAAO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