@stablyai/playwright-base 0.1.6 → 0.1.7-next.2

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.
@@ -1,7 +1,18 @@
1
1
  import type { Locator, Page } from "@stablyai/internal-playwright-test";
2
2
  import * as z4 from "zod/v4/core";
3
+ import { z } from "zod";
3
4
  export type ExtractSchema = z4.$ZodType;
4
5
  export type SchemaOutput<T extends ExtractSchema> = z4.output<T>;
6
+ export declare const zExtractionResponse: z.ZodDiscriminatedUnion<[z.ZodObject<{
7
+ success: z.ZodLiteral<true>;
8
+ value: z.ZodUnknown;
9
+ }, z4.$strict>, z.ZodObject<{
10
+ success: z.ZodLiteral<false>;
11
+ error: z.ZodString;
12
+ }, z4.$strict>], "success">;
13
+ export declare const zError: z.ZodObject<{
14
+ error: z.ZodString;
15
+ }, z4.$strict>;
5
16
  type ExtractSubject = Page | Locator;
6
17
  type BaseExtractArgs = {
7
18
  prompt: string;
@@ -33,13 +33,17 @@ var __importStar = (this && this.__importStar) || (function () {
33
33
  };
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.zError = exports.zExtractionResponse = void 0;
36
37
  exports.extract = extract;
37
38
  const z4 = __importStar(require("zod/v4/core"));
38
39
  const zod_1 = require("zod");
39
40
  const runtime_1 = require("../runtime");
40
- const EXTRACT_ENDPOINT = "https://api.stably.ai/internal/v1/extract";
41
- const zSuccess = zod_1.z.object({ value: zod_1.z.unknown() });
42
- const zError = zod_1.z.object({ error: zod_1.z.string() });
41
+ const EXTRACT_ENDPOINT = "https://api.stably.ai/internal/v2/extract";
42
+ exports.zExtractionResponse = zod_1.z.discriminatedUnion("success", [
43
+ zod_1.z.object({ success: zod_1.z.literal(true), value: zod_1.z.unknown() }).strict(),
44
+ zod_1.z.object({ success: zod_1.z.literal(false), error: zod_1.z.string() }).strict(),
45
+ ]);
46
+ exports.zError = zod_1.z.object({ error: zod_1.z.string() }).strict();
43
47
  class ExtractValidationError extends Error {
44
48
  issues;
45
49
  constructor(message, issues) {
@@ -74,15 +78,23 @@ async function extract({ prompt, pageOrLocator, schema, }) {
74
78
  },
75
79
  body: form,
76
80
  });
77
- const parsed = await response.json().catch(() => undefined);
81
+ const raw = await response.json().catch(() => undefined);
78
82
  if (response.ok) {
79
- const { value } = zSuccess.parse(parsed);
83
+ const parsed = exports.zExtractionResponse.safeParse(raw);
84
+ if (!parsed.success) {
85
+ throw new Error("Extract returned unexpected response shape");
86
+ }
87
+ // AI could not find requested content; return message for display
88
+ if (parsed.data.success === false) {
89
+ return parsed.data.error;
90
+ }
91
+ const { value } = parsed.data;
80
92
  return schema
81
93
  ? await validateWithSchema(schema, value)
82
94
  : typeof value === "string"
83
95
  ? value
84
96
  : JSON.stringify(value);
85
97
  }
86
- const err = zError.safeParse(parsed);
87
- throw new Error(`Extract failed (${response.status})${err.success ? `: ${err.data.error}` : ""}`);
98
+ const err = exports.zError.safeParse(raw);
99
+ throw new Error(err.success ? err.data.error : "Extract failed");
88
100
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stablyai/playwright-base",
3
- "version": "0.1.6",
3
+ "version": "0.1.7-next.2",
4
4
  "description": "Shared augmentation runtime for Stably Playwright wrappers",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -11,7 +11,7 @@
11
11
  "node": ">=18"
12
12
  },
13
13
  "dependencies": {
14
- "@stablyai/internal-playwright-test": "0.1.2",
14
+ "@stablyai/internal-playwright-test": "0.1.8",
15
15
  "jpeg-js": "^0.4.4",
16
16
  "pixelmatch": "^5.3.0",
17
17
  "pngjs": "^7.0.0"
@@ -19,6 +19,11 @@
19
19
  "peerDependencies": {
20
20
  "zod": "^3.25.0 || ^4.0.0"
21
21
  },
22
+ "peerDependenciesMeta": {
23
+ "zod": {
24
+ "optional": true
25
+ }
26
+ },
22
27
  "devDependencies": {
23
28
  "@types/jpeg-js": "^0.3.7",
24
29
  "@types/pngjs": "^6.0.5",