|
| 1 | +--- |
| 2 | +permalink: /helpers/Decision |
| 3 | +editLink: false |
| 4 | +sidebar: auto |
| 5 | +title: Decision |
| 6 | +--- |
| 7 | + |
| 8 | +<!-- Generated by documentation.js. Update this documentation by updating the source code. --> |
| 9 | + |
| 10 | +## Decision |
| 11 | + |
| 12 | +**Extends Helper** |
| 13 | + |
| 14 | +Asserts statements about the current page with a decision model. |
| 15 | + |
| 16 | +Decision models (like [Jev][1] or [Clef][2]) |
| 17 | +do not generate text. They read the page state and return the probability that a statement is true. |
| 18 | +A statement passes when its probability reaches the configured `confidence`. |
| 19 | + |
| 20 | +```js |
| 21 | +I.decide('top level navigation is available'); |
| 22 | +I.decide([ |
| 23 | + 'checkout form has all required fields', |
| 24 | + 'success message is shown', |
| 25 | + 'submit button enabled', |
| 26 | + 'cancel button present', |
| 27 | +]); |
| 28 | +I.decideVisually('sidebar is shown'); |
| 29 | +``` |
| 30 | + |
| 31 | +The model receives the page URL, title and ARIA snapshot. |
| 32 | +Helpers without ARIA snapshots (anything but Playwright) send minified HTML instead. |
| 33 | +`decideVisually` also sends a screenshot, so it requires a model with image input. |
| 34 | + |
| 35 | +This helper must be enabled together with a web helper (Playwright, Puppeteer, WebDriver). |
| 36 | + |
| 37 | +## Configuration |
| 38 | + |
| 39 | +Decision model is configured in the `ai.decisionModel` section of the config: |
| 40 | + |
| 41 | +```js |
| 42 | +ai: { |
| 43 | + decisionModel: { |
| 44 | + provider: 'openrouter', |
| 45 | + model: 'typesafe/jev-1.13', |
| 46 | + visualModel: 'cloudflare/clef', |
| 47 | + confidence: 0.7, |
| 48 | + }, |
| 49 | +}, |
| 50 | +helpers: { |
| 51 | + Playwright: { url: 'http://localhost', browser: 'chromium' }, |
| 52 | + Decision: {}, |
| 53 | +} |
| 54 | +``` |
| 55 | + |
| 56 | +* `provider` (default: `openrouter`) - decision API to call: `openrouter` (reads `OPENROUTER_API_KEY`) or `typesafe` (reads `TYPESAFE_API_KEY`). |
| 57 | +* `apiKey` (optional) - API key, overrides the environment variable. |
| 58 | +* `model` (default: `typesafe/jev-1.13`) - decision model used by `decide`. Use `jev-latest` with the `typesafe` provider. |
| 59 | +* `visualModel` (default: `cloudflare/clef`) - decision model with image input used by `decideVisually`. Available on OpenRouter only. |
| 60 | +* `confidence` (default: `0.7`) - minimal probability, between 0 and 1, for a statement to pass. |
| 61 | +* `timeout` (default: `15000`) - request timeout in ms. |
| 62 | +* `maxLength` (default: `12000`) - maximal length of ARIA snapshot or HTML sent to the model. |
| 63 | + |
| 64 | +The helper has one option: |
| 65 | + |
| 66 | +* `mode` (default: `assert`) - how decisions are executed: |
| 67 | + * `assert` - request the model and fail the step when a statement is not confirmed. |
| 68 | + * `report` - request the model but never fail, even on API errors. Results and errors are added to the step as a comment. |
| 69 | + * `skip` - do not request the model, every decision passes. |
| 70 | + |
| 71 | +```js |
| 72 | +Decision: { mode: process.env.CI ? 'assert' : 'skip' } |
| 73 | +``` |
| 74 | + |
| 75 | +Decisions work without the `--ai` flag. |
| 76 | +Browse all decision models at [OpenRouter][3]. |
| 77 | + |
| 78 | +## Methods |
| 79 | + |
| 80 | +### Parameters |
| 81 | + |
| 82 | +* `config` |
| 83 | + |
| 84 | +### decide |
| 85 | + |
| 86 | +Asserts that a statement (or each of statements) is true for the current page. |
| 87 | +The decision model receives page URL, title and ARIA snapshot. |
| 88 | +Multiple statements are checked in a single request and all of them must pass. |
| 89 | + |
| 90 | +```js |
| 91 | +I.decide('user is logged in'); |
| 92 | +I.decide(['submit button enabled', 'cancel button present']); |
| 93 | +const probability = await I.decide('cart is empty'); |
| 94 | +``` |
| 95 | + |
| 96 | +#### Parameters |
| 97 | + |
| 98 | +* `statements` **([string][4] | [Array][5]<[string][4]>)** statement or list of statements to verify. |
| 99 | + |
| 100 | +Returns **[Promise][6]<([number][7] | [Array][5]<[number][7]> | [undefined][8])>** probability of each statement, `undefined` in `skip` mode. |
| 101 | + |
| 102 | +### decideVisually |
| 103 | + |
| 104 | +Asserts that a statement (or each of statements) is true for the current page using a screenshot. |
| 105 | +The decision model receives page URL, title, ARIA snapshot and a screenshot. |
| 106 | +Requires `visualModel` with image input. Experimental. |
| 107 | + |
| 108 | +```js |
| 109 | +I.decideVisually('sidebar is shown'); |
| 110 | +I.decideVisually(['logo is in the header', 'page uses dark theme']); |
| 111 | +``` |
| 112 | + |
| 113 | +#### Parameters |
| 114 | + |
| 115 | +* `statements` **([string][4] | [Array][5]<[string][4]>)** statement or list of statements to verify. |
| 116 | + |
| 117 | +Returns **[Promise][6]<([number][7] | [Array][5]<[number][7]> | [undefined][8])>** probability of each statement, `undefined` in `skip` mode. |
| 118 | + |
| 119 | +[1]: https://openrouter.ai/typesafe/jev-1.13 |
| 120 | + |
| 121 | +[2]: https://openrouter.ai/cloudflare/clef |
| 122 | + |
| 123 | +[3]: https://openrouter.ai/models?output_modalities=decisions |
| 124 | + |
| 125 | +[4]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String |
| 126 | + |
| 127 | +[5]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array |
| 128 | + |
| 129 | +[6]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise |
| 130 | + |
| 131 | +[7]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number |
| 132 | + |
| 133 | +[8]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/undefined |
0 commit comments