@sayer/agent-step 0.1.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 (43) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +2 -0
  3. package/dist/agent/action-executor.d.ts +20 -0
  4. package/dist/agent/action-executor.d.ts.map +1 -0
  5. package/dist/agent/action-executor.js +112 -0
  6. package/dist/agent/action-executor.js.map +1 -0
  7. package/dist/agent/agent-runtime.d.ts +11 -0
  8. package/dist/agent/agent-runtime.d.ts.map +1 -0
  9. package/dist/agent/agent-runtime.js +103 -0
  10. package/dist/agent/agent-runtime.js.map +1 -0
  11. package/dist/agent/browser-tools.d.ts +28 -0
  12. package/dist/agent/browser-tools.d.ts.map +1 -0
  13. package/dist/agent/browser-tools.js +259 -0
  14. package/dist/agent/browser-tools.js.map +1 -0
  15. package/dist/agent/model.d.ts +6 -0
  16. package/dist/agent/model.d.ts.map +1 -0
  17. package/dist/agent/model.js +161 -0
  18. package/dist/agent/model.js.map +1 -0
  19. package/dist/agent/redaction.d.ts +4 -0
  20. package/dist/agent/redaction.d.ts.map +1 -0
  21. package/dist/agent/redaction.js +37 -0
  22. package/dist/agent/redaction.js.map +1 -0
  23. package/dist/agent/types.d.ts +89 -0
  24. package/dist/agent/types.d.ts.map +1 -0
  25. package/dist/agent/types.js +2 -0
  26. package/dist/agent/types.js.map +1 -0
  27. package/dist/agent/verifier.d.ts +22 -0
  28. package/dist/agent/verifier.d.ts.map +1 -0
  29. package/dist/agent/verifier.js +209 -0
  30. package/dist/agent/verifier.js.map +1 -0
  31. package/dist/agent-step.d.ts +10 -0
  32. package/dist/agent-step.d.ts.map +1 -0
  33. package/dist/agent-step.js +68 -0
  34. package/dist/agent-step.js.map +1 -0
  35. package/dist/agent-test.d.ts +10 -0
  36. package/dist/agent-test.d.ts.map +1 -0
  37. package/dist/agent-test.js +7 -0
  38. package/dist/agent-test.js.map +1 -0
  39. package/dist/index.d.ts +4 -0
  40. package/dist/index.d.ts.map +1 -0
  41. package/dist/index.js +3 -0
  42. package/dist/index.js.map +1 -0
  43. package/package.json +68 -0
@@ -0,0 +1,68 @@
1
+ import { test } from '@playwright/test';
2
+ import { AgentRuntime, AgentStepError } from './agent/agent-runtime.js';
3
+ import { redactObject } from './agent/redaction.js';
4
+ export function createAgentStep({ page, testInfo, }) {
5
+ const runtime = new AgentRuntime({ page, testInfo });
6
+ return async (input) => {
7
+ testInfo.annotations.push({
8
+ type: 'agent-expect',
9
+ description: input.expect.join(' | '),
10
+ });
11
+ return test.step(`agent: ${input.action}`, async (step) => {
12
+ try {
13
+ const result = await runtime.runStep(input);
14
+ await step.attach('agent-transcript.json', {
15
+ body: JSON.stringify(redactObject(result.actionTranscript, input.secrets ?? {}), null, 2),
16
+ contentType: 'application/json',
17
+ });
18
+ await step.attach('agent-verification.json', {
19
+ body: JSON.stringify(result.verification, null, 2),
20
+ contentType: 'application/json',
21
+ });
22
+ if (result.rawVerifierContent) {
23
+ await step.attach('agent-verifier-raw.json', {
24
+ body: result.rawVerifierContent,
25
+ contentType: 'application/json',
26
+ });
27
+ }
28
+ await step.attach('agent-token-usage.json', {
29
+ body: JSON.stringify(result.tokenUsage, null, 2),
30
+ contentType: 'application/json',
31
+ });
32
+ return result;
33
+ }
34
+ catch (error) {
35
+ const screenshot = await page
36
+ .screenshot({ fullPage: true })
37
+ .catch(() => null);
38
+ if (screenshot) {
39
+ await step.attach('agent-failure.png', {
40
+ body: screenshot,
41
+ contentType: 'image/png',
42
+ });
43
+ }
44
+ if (error instanceof AgentStepError && error.result) {
45
+ await step.attach('agent-transcript.json', {
46
+ body: JSON.stringify(redactObject(error.result.actionTranscript, input.secrets ?? {}), null, 2),
47
+ contentType: 'application/json',
48
+ });
49
+ await step.attach('agent-verification.json', {
50
+ body: JSON.stringify(error.result.verification, null, 2),
51
+ contentType: 'application/json',
52
+ });
53
+ if (error.result.rawVerifierContent) {
54
+ await step.attach('agent-verifier-raw.json', {
55
+ body: error.result.rawVerifierContent,
56
+ contentType: 'application/json',
57
+ });
58
+ }
59
+ }
60
+ throw error;
61
+ }
62
+ });
63
+ };
64
+ }
65
+ export async function agentStep(page, input) {
66
+ return createAgentStep({ page, testInfo: test.info() })(input);
67
+ }
68
+ //# sourceMappingURL=agent-step.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent-step.js","sourceRoot":"","sources":["../src/agent-step.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAA4B,MAAM,kBAAkB,CAAC;AAClE,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AACxE,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAUpD,MAAM,UAAU,eAAe,CAAC,EAC9B,IAAI,EACJ,QAAQ,GACe;IACvB,MAAM,OAAO,GAAG,IAAI,YAAY,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,CAAC;IAErD,OAAO,KAAK,EAAE,KAAK,EAAE,EAAE;QACrB,QAAQ,CAAC,WAAW,CAAC,IAAI,CAAC;YACxB,IAAI,EAAE,cAAc;YACpB,WAAW,EAAE,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC;SACtC,CAAC,CAAC;QAEH,OAAO,IAAI,CAAC,IAAI,CAAC,UAAU,KAAK,CAAC,MAAM,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE;YACxD,IAAI,CAAC;gBACH,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;gBAE5C,MAAM,IAAI,CAAC,MAAM,CAAC,uBAAuB,EAAE;oBACzC,IAAI,EAAE,IAAI,CAAC,SAAS,CAClB,YAAY,CAAC,MAAM,CAAC,gBAAgB,EAAE,KAAK,CAAC,OAAO,IAAI,EAAE,CAAC,EAC1D,IAAI,EACJ,CAAC,CACF;oBACD,WAAW,EAAE,kBAAkB;iBAChC,CAAC,CAAC;gBAEH,MAAM,IA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AW,EAAE,kBAAkB;qBAChC,CAAC,CAAC;oBACD,MAAM,IAAI,CAAC,MAAM,CAAC,yBAAyB,EAAE;wBAC3C,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,MAAM,CAAC,YAAY,EAAE,IAAI,EAAE,CAAC,CAAC;wBACxD,WAAW,EAAE,kBAAkB;qBAChC,CAAC,CAAC;oBACH,IAAI,KAAK,CAAC,MAAM,CAAC,kBAAkB,EAAE,CAAC;wBACpC,MAAM,IAAI,CAAC,MAAM,CAAC,yBAAyB,EAAE;4BAC3C,IAAI,EAAE,KAAK,CAAC,MAAM,CAAC,kBAAkB;4BACrC,WAAW,EAAE,kBAAkB;yBAChC,CAAC,CAAC;oBACL,CAAC;gBACL,CAAC;gBAED,MAAM,KAAK,CAAC;YACd,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,SAAS,CAC7B,IAAU,EACV,KAAqB;IAErB,OAAO,eAAe,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC;AACjE,CAAC","sourcesContent":["import { test, type Page, type TestInfo } from '@playwright/test';\nimport { AgentRuntime, AgentStepError } from './agent/agent-runtime.js';\nimport { redactObject } from './agent/redaction.js';\nimport type { AgentStepInput, AgentStepResult } from './agent/types.js';\n\nexport type AgentStep = (input: AgentStepInput) => Promise<AgentStepResult>;\n\nexport interface CreateAgentStepOptions {\n page: Page;\n testInfo: TestInfo;\n}\n\nexport function createAgentStep({\n page,\n testInfo,\n}: CreateAgentStepOptions): AgentStep {\n const runtime = new AgentRuntime({ page, testInfo });\n\n return async (input) => {\n testInfo.annotations.push({\n type: 'agent-expect',\n description: input.expect.join(' | '),\n });\n\n return test.step(`agent: ${input.action}`, async (step) => {\n try {\n const result = await runtime.runStep(input);\n\n await step.attach('agent-transcript.json', {\n body: JSON.stringify(\n redactObject(result.actionTranscript, input.secrets ?? {}),\n null,\n 2,\n ),\n contentType: 'application/json',\n });\n\n await step.attach('agent-verification.json', {\n body: JSON.stringify(result.verification, null, 2),\n contentType: 'application/json',\n });\n\n if (result.rawVerifierContent) {\n await step.attach('agent-verifier-raw.json', {\n body: result.rawVerifierContent,\n contentType: 'application/json',\n });\n }\n\n await step.attach('agent-token-usage.json', {\n body: JSON.stringify(result.tokenUsage, null, 2),\n contentType: 'application/json',\n });\n\n return result;\n } catch (error) {\n const screenshot = await page\n .screenshot({ fullPage: true })\n .catch(() => null);\n if (screenshot) {\n await step.attach('agent-failure.png', {\n body: screenshot,\n contentType: 'image/png',\n });\n }\n\n if (error instanceof AgentStepError && error.result) {\n await step.attach('agent-transcript.json', {\n body: JSON.stringify(\n redactObject(error.result.actionTranscript, input.secrets ?? {}),\n null,\n 2,\n ),\n contentType: 'application/json',\n });\n await step.attach('agent-verification.json', {\n body: JSON.stringify(error.result.verification, null, 2),\n contentType: 'application/json',\n });\n if (error.result.rawVerifierContent) {\n await step.attach('agent-verifier-raw.json', {\n body: error.result.rawVerifierContent,\n contentType: 'application/json',\n });\n }\n }\n\n throw error;\n }\n });\n };\n}\n\nexport async function agentStep(\n page: Page,\n input: AgentStepInput,\n): Promise<AgentStepResult> {\n return createAgentStep({ page, testInfo: test.info() })(input);\n}\n"]}
@@ -0,0 +1,10 @@
1
+ import type { Fixtures, Page } from '@playwright/test';
2
+ import { type AgentStep } from './agent-step.js';
3
+ export type AgentStepFixtures = {
4
+ agentStep: AgentStep;
5
+ };
6
+ export type AgentFixtures = AgentStepFixtures;
7
+ export declare const agentStepFixture: Fixtures<AgentStepFixtures, {}, {
8
+ page: Page;
9
+ }>;
10
+ //# sourceMappingURL=agent-test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent-test.d.ts","sourceRoot":"","sources":["../src/agent-test.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAAmB,KAAK,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAElE,MAAM,MAAM,iBAAiB,GAAG;IAC9B,SAAS,EAAE,SAAS,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG,iBAAiB,CAAC;AAE9C,eAAO,MAAM,gBAAgB,EAAE,QAAQ,CACrC,iBAAiB,EACjB,EAAE,EACF;IAAE,IAAI,EAAE,IAAI,CAAA;CAAE,CAKf,CAAC"}
@@ -0,0 +1,7 @@
1
+ import { createAgentStep } from './agent-step.js';
2
+ export const agentStepFixture = {
3
+ agentStep: async ({ page }, use, testInfo) => {
4
+ await use(createAgentStep({ page, testInfo }));
5
+ },
6
+ };
7
+ //# sourceMappingURL=agent-test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent-test.js","sourceRoot":"","sources":["../src/agent-test.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAkB,MAAM,iBAAiB,CAAC;AAQlE,MAAM,CAAC,MAAM,gBAAgB,GAIzB;IACF,SAAS,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,EAAE,GAAG,EAAE,QAAQ,EAAE,EAAE;QAC3C,MAAM,GAAG,CAAC,eAAe,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,CAAC,CAAC;IACjD,CAAC;CACF,CAAC","sourcesContent":["import type { Fixtures, Page } from '@playwright/test';\nimport { createAgentStep, type AgentStep } from './agent-step.js';\n\nexport type AgentStepFixtures = {\n agentStep: AgentStep;\n};\n\nexport type AgentFixtures = AgentStepFixtures;\n\nexport const agentStepFixture: Fixtures<\n AgentStepFixtures,\n {},\n { page: Page }\n> = {\n agentStep: async ({ page }, use, testInfo) => {\n await use(createAgentStep({ page, testInfo }));\n },\n};\n"]}
@@ -0,0 +1,4 @@
1
+ export { agentStep, createAgentStep, type AgentStep, type CreateAgentStepOptions, } from './agent-step.js';
2
+ export { agentStepFixture, type AgentFixtures, type AgentStepFixtures, } from './agent-test.js';
3
+ export type { AgentStepInput, AgentStepResult, CriterionVerdict, TokenUsage, TranscriptEntry, VerificationResult, } from './agent/types.js';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EACT,eAAe,EACf,KAAK,SAAS,EACd,KAAK,sBAAsB,GAC5B,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EACL,gBAAgB,EAChB,KAAK,aAAa,EAClB,KAAK,iBAAiB,GACvB,MAAM,iBAAiB,CAAC;AAEzB,YAAY,EACV,cAAc,EACd,eAAe,EACf,gBAAgB,EAChB,UAAU,EACV,eAAe,EACf,kBAAkB,GACnB,MAAM,kBAAkB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export { agentStep, createAgentStep, } from './agent-step.js';
2
+ export { agentStepFixture, } from './agent-test.js';
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EACT,eAAe,GAGhB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EACL,gBAAgB,GAGjB,MAAM,iBAAiB,CAAC","sourcesContent":["export {\n agentStep,\n createAgentStep,\n type AgentStep,\n type CreateAgentStepOptions,\n} from './agent-step.js';\n\nexport {\n agentStepFixture,\n type AgentFixtures,\n type AgentStepFixtures,\n} from './agent-test.js';\n\nexport type {\n AgentStepInput,\n AgentStepResult,\n CriterionVerdict,\n TokenUsage,\n TranscriptEntry,\n VerificationResult,\n} from './agent/types.js';\n"]}
package/package.json ADDED
@@ -0,0 +1,68 @@
1
+ {
2
+ "name": "@sayer/agent-step",
3
+ "version": "0.1.0",
4
+ "description": "Runtime agentic test steps for Playwright using plain-language actions and expectations",
5
+ "author": "Jack Sayer",
6
+ "license": "MIT",
7
+ "type": "module",
8
+ "main": "./dist/index.js",
9
+ "types": "./dist/index.d.ts",
10
+ "exports": {
11
+ ".": {
12
+ "types": "./dist/index.d.ts",
13
+ "import": "./dist/index.js",
14
+ "default": "./dist/index.js"
15
+ }
16
+ },
17
+ "files": [
18
+ "dist",
19
+ "README.md",
20
+ "LICENSE"
21
+ ],
22
+ "repository": {
23
+ "type": "git",
24
+ "url": "git+https://github.com/Sayer122/agent-step.git"
25
+ },
26
+ "bugs": {
27
+ "url": "https://github.com/Sayer122/agent-step/issues"
28
+ },
29
+ "homepage": "https://github.com/Sayer122/agent-step#readme",
30
+ "publishConfig": {
31
+ "access": "public"
32
+ },
33
+ "keywords": [
34
+ "playwright",
35
+ "testing",
36
+ "agentic",
37
+ "llm",
38
+ "e2e",
39
+ "automation"
40
+ ],
41
+ "engines": {
42
+ "node": ">=20"
43
+ },
44
+ "scripts": {
45
+ "clean": "node -e \"require('node:fs').rmSync('dist', { recursive: true, force: true })\"",
46
+ "build": "npm run clean && tsc -p tsconfig.build.json",
47
+ "test": "playwright test",
48
+ "test:framework": "playwright test --project=framework",
49
+ "test:agentic": "playwright test --project=agentic",
50
+ "test:live": "playwright test --project=live",
51
+ "test:package": "npm run build && tsc -p examples/consumer/tsconfig.json && node --input-type=module -e \"const pkg = await import('@sayer/agent-step'); if (!pkg.agentStep || !pkg.createAgentStep || !pkg.agentStepFixture) throw new Error('Missing public exports')\"",
52
+ "typecheck": "tsc --noEmit",
53
+ "prepack": "npm run build",
54
+ "prepublishOnly": "npm run typecheck && npm run test:framework && npm run test:package"
55
+ },
56
+ "devDependencies": {
57
+ "@playwright/test": "^1.63.0",
58
+ "@types/node": "^22.10.0",
59
+ "typescript": "^5.7.0"
60
+ },
61
+ "peerDependencies": {
62
+ "@playwright/test": ">=1.63.0 <2"
63
+ },
64
+ "dependencies": {
65
+ "openai": "^4.77.0",
66
+ "zod": "^3.24.0"
67
+ }
68
+ }