@rohzzn/uidna-schema 0.0.0-stage → 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.
- package/CHANGELOG.md +21 -0
- package/README.md +25 -2
- package/dist/scripts/json-schema.d.ts +1 -0
- package/dist/scripts/json-schema.js +27 -0
- package/dist/scripts/json-schema.js.map +1 -0
- package/dist/src/index.d.ts +22 -0
- package/dist/src/index.js +28 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/provenance.d.ts +377 -0
- package/dist/src/provenance.js +163 -0
- package/dist/src/provenance.js.map +1 -0
- package/dist/src/schema.d.ts +30009 -0
- package/dist/src/schema.js +573 -0
- package/dist/src/schema.js.map +1 -0
- package/dist/ui-dna.schema.json +23830 -0
- package/package.json +50 -4
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to `@rohzzn/uidna-schema` are documented here. The format follows
|
|
4
|
+
[Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and the package
|
|
5
|
+
follows semantic versioning. `dnaVersion` inside a document tracks this
|
|
6
|
+
package's version.
|
|
7
|
+
|
|
8
|
+
## [0.1.0] - 2026-10-13
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- First published UI DNA document schema (`dnaVersion` 0.1.0).
|
|
13
|
+
- Provenance envelope (`measured | observed | inferred | unknown`) with the
|
|
14
|
+
rule that `inferred` values come only from the `agent` source and `unknown`
|
|
15
|
+
values carry a reason instead of a value.
|
|
16
|
+
- Top-level sections: `target`, `app`, `states`, `components`, `visual`,
|
|
17
|
+
`behavior`, `assets`, `limitations`, `evidence`, `annotations` (the log of
|
|
18
|
+
agent patches applied through `annotate_dna`).
|
|
19
|
+
- `validateUiDna`, `parseUiDna`, `isUiDna` helpers and a generated JSON Schema
|
|
20
|
+
at `@rohzzn/uidna-schema/ui-dna.schema.json`.
|
|
21
|
+
- Complete example document built from Fixture A (`fixtures/a-marketing`).
|
package/README.md
CHANGED
|
@@ -1,3 +1,26 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @rohzzn/uidna-schema
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The UI DNA document schema. A UI DNA document describes a user interface the
|
|
4
|
+
way an engineer would need it described to rebuild it: pages and navigation,
|
|
5
|
+
observed states and the transitions between them, component candidates with
|
|
6
|
+
their instances, visual tokens with the measurements that support them, layout
|
|
7
|
+
constraints per node, observed behavior, assets and, just as importantly, what
|
|
8
|
+
could not be observed.
|
|
9
|
+
|
|
10
|
+
Every measured or inferred value is wrapped in a provenance envelope that says
|
|
11
|
+
how it was obtained, from which state and viewport, with which evidence and
|
|
12
|
+
with what confidence. Values that are not known are marked `unknown` with a
|
|
13
|
+
reason. They are never empty strings, zeros or `false`.
|
|
14
|
+
|
|
15
|
+
The schema is framework neutral. It contains no React, Tailwind or other
|
|
16
|
+
output-framework terms, so any generator or tool can consume it.
|
|
17
|
+
|
|
18
|
+
```ts
|
|
19
|
+
import { parseUiDna, validateUiDna, UI_DNA_VERSION } from '@rohzzn/uidna-schema';
|
|
20
|
+
|
|
21
|
+
const result = validateUiDna(JSON.parse(text));
|
|
22
|
+
if (!result.success) console.error(result.error.issues);
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
The JSON Schema is published at `@rohzzn/uidna-schema/ui-dna.schema.json`. The full
|
|
26
|
+
reference lives in `docs/ui-dna.md` in the UI DNA repository.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generates `dist/ui-dna.schema.json` from the Zod schema. Run after `tsc`.
|
|
3
|
+
*/
|
|
4
|
+
import { mkdir, writeFile } from 'node:fs/promises';
|
|
5
|
+
import { dirname, join } from 'node:path';
|
|
6
|
+
import { fileURLToPath } from 'node:url';
|
|
7
|
+
import { z } from 'zod';
|
|
8
|
+
import { UiDnaDocumentStructureSchema, UI_DNA_VERSION } from '../src/schema.js';
|
|
9
|
+
const here = dirname(fileURLToPath(import.meta.url));
|
|
10
|
+
// When run from dist/scripts/, the package root is two levels up; from scripts/ it is one.
|
|
11
|
+
const packageRoot = here.endsWith(join('dist', 'scripts')) ? join(here, '..', '..') : join(here, '..');
|
|
12
|
+
const outDir = join(packageRoot, 'dist');
|
|
13
|
+
const jsonSchema = z.toJSONSchema(UiDnaDocumentStructureSchema, {
|
|
14
|
+
target: 'draft-2020-12',
|
|
15
|
+
unrepresentable: 'any',
|
|
16
|
+
io: 'input',
|
|
17
|
+
});
|
|
18
|
+
const withMeta = {
|
|
19
|
+
$id: `https://uidna.dev/schema/ui-dna/${UI_DNA_VERSION}/ui-dna.schema.json`,
|
|
20
|
+
title: 'UI DNA document',
|
|
21
|
+
description: 'Describes a user interface down to the token, the component and the state transition, with provenance on every value. Cross-reference rules (state, page and component ids must resolve) are enforced by the Zod schema and are not expressible here.',
|
|
22
|
+
...jsonSchema,
|
|
23
|
+
};
|
|
24
|
+
await mkdir(outDir, { recursive: true });
|
|
25
|
+
await writeFile(join(outDir, 'ui-dna.schema.json'), JSON.stringify(withMeta, null, 2) + '\n', 'utf8');
|
|
26
|
+
console.log(`wrote ${join(outDir, 'ui-dna.schema.json')}`);
|
|
27
|
+
//# sourceMappingURL=json-schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json-schema.js","sourceRoot":"","sources":["../../scripts/json-schema.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,4BAA4B,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAEhF,MAAM,IAAI,GAAG,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;AACrD,2FAA2F;AAC3F,MAAM,WAAW,GAAG,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;AACvG,MAAM,MAAM,GAAG,IAAI,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC;AAEzC,MAAM,UAAU,GAAG,CAAC,CAAC,YAAY,CAAC,4BAA4B,EAAE;IAC9D,MAAM,EAAE,eAAe;IACvB,eAAe,EAAE,KAAK;IACtB,EAAE,EAAE,OAAO;CACZ,CAAC,CAAC;AAEH,MAAM,QAAQ,GAAG;IACf,GAAG,EAAE,mCAAmC,cAAc,qBAAqB;IAC3E,KAAK,EAAE,iBAAiB;IACxB,WAAW,EACT,uPAAuP;IACzP,GAAG,UAAU;CACd,CAAC;AAEF,MAAM,KAAK,CAAC,MAAM,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;AACzC,MAAM,SAAS,CAAC,IAAI,CAAC,MAAM,EAAE,oBAAoB,CAAC,EAAE,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC,GAAG,IAAI,EAAE,MAAM,CAAC,CAAC;AACtG,OAAO,CAAC,GAAG,CAAC,SAAS,IAAI,CAAC,MAAM,EAAE,oBAAoB,CAAC,EAAE,CAAC,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @rohzzn/uidna-schema — the UI DNA document schema.
|
|
3
|
+
*
|
|
4
|
+
* A UI DNA document describes a user interface down to the token, the
|
|
5
|
+
* component and the state transition, with provenance on every value.
|
|
6
|
+
*/
|
|
7
|
+
import type { z } from 'zod';
|
|
8
|
+
import type { UiDnaDocument } from './schema.js';
|
|
9
|
+
export * from './provenance.js';
|
|
10
|
+
export * from './schema.js';
|
|
11
|
+
/** Result of `validateUiDna`: either a validated document or the Zod error. */
|
|
12
|
+
export type UiDnaValidation = z.ZodSafeParseResult<UiDnaDocument>;
|
|
13
|
+
/** Validate an unknown value as a UI DNA document. Never throws. */
|
|
14
|
+
export declare function validateUiDna(input: unknown): UiDnaValidation;
|
|
15
|
+
/** Parse an unknown value as a UI DNA document, throwing a `ZodError` on failure. */
|
|
16
|
+
export declare function parseUiDna(input: unknown): UiDnaDocument;
|
|
17
|
+
/** Type guard: true when `input` is a valid UI DNA document. */
|
|
18
|
+
export declare function isUiDna(input: unknown): input is UiDnaDocument;
|
|
19
|
+
/** Human-readable list of validation issues, one per line. */
|
|
20
|
+
export declare function formatIssues(validation: UiDnaValidation): string[];
|
|
21
|
+
/** True when a document's `dnaVersion` is one this package can read (same major version). */
|
|
22
|
+
export declare function isCompatibleVersion(dnaVersion: string): boolean;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { UiDnaDocumentSchema, UI_DNA_VERSION } from './schema.js';
|
|
2
|
+
export * from './provenance.js';
|
|
3
|
+
export * from './schema.js';
|
|
4
|
+
/** Validate an unknown value as a UI DNA document. Never throws. */
|
|
5
|
+
export function validateUiDna(input) {
|
|
6
|
+
return UiDnaDocumentSchema.safeParse(input);
|
|
7
|
+
}
|
|
8
|
+
/** Parse an unknown value as a UI DNA document, throwing a `ZodError` on failure. */
|
|
9
|
+
export function parseUiDna(input) {
|
|
10
|
+
return UiDnaDocumentSchema.parse(input);
|
|
11
|
+
}
|
|
12
|
+
/** Type guard: true when `input` is a valid UI DNA document. */
|
|
13
|
+
export function isUiDna(input) {
|
|
14
|
+
return UiDnaDocumentSchema.safeParse(input).success;
|
|
15
|
+
}
|
|
16
|
+
/** Human-readable list of validation issues, one per line. */
|
|
17
|
+
export function formatIssues(validation) {
|
|
18
|
+
if (validation.success)
|
|
19
|
+
return [];
|
|
20
|
+
return validation.error.issues.map((issue) => `${issue.path.map(String).join('.') || '<root>'}: ${issue.message}`);
|
|
21
|
+
}
|
|
22
|
+
/** True when a document's `dnaVersion` is one this package can read (same major version). */
|
|
23
|
+
export function isCompatibleVersion(dnaVersion) {
|
|
24
|
+
const [docMajor] = dnaVersion.split('.');
|
|
25
|
+
const [ourMajor] = UI_DNA_VERSION.split('.');
|
|
26
|
+
return docMajor !== undefined && docMajor === ourMajor;
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,mBAAmB,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAGlE,cAAc,iBAAiB,CAAC;AAChC,cAAc,aAAa,CAAC;AAK5B,oEAAoE;AACpE,MAAM,UAAU,aAAa,CAAC,KAAc;IAC1C,OAAO,mBAAmB,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;AAC9C,CAAC;AAED,qFAAqF;AACrF,MAAM,UAAU,UAAU,CAAC,KAAc;IACvC,OAAO,mBAAmB,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;AAC1C,CAAC;AAED,gEAAgE;AAChE,MAAM,UAAU,OAAO,CAAC,KAAc;IACpC,OAAO,mBAAmB,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC;AACtD,CAAC;AAED,8DAA8D;AAC9D,MAAM,UAAU,YAAY,CAAC,UAA2B;IACtD,IAAI,UAAU,CAAC,OAAO;QAAE,OAAO,EAAE,CAAC;IAClC,OAAO,UAAU,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,GAAG,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,QAAQ,KAAK,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;AACrH,CAAC;AAED,6FAA6F;AAC7F,MAAM,UAAU,mBAAmB,CAAC,UAAkB;IACpD,MAAM,CAAC,QAAQ,CAAC,GAAG,UAAU,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACzC,MAAM,CAAC,QAAQ,CAAC,GAAG,cAAc,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC7C,OAAO,QAAQ,KAAK,SAAS,IAAI,QAAQ,KAAK,QAAQ,CAAC;AACzD,CAAC"}
|
|
@@ -0,0 +1,377 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Provenance envelope. Every measured or inferred value in a UI DNA document
|
|
3
|
+
* is wrapped with how it was obtained. Missing evidence is `unknown` with a
|
|
4
|
+
* reason; it is never an empty string, zero or `false`.
|
|
5
|
+
*/
|
|
6
|
+
import { z } from 'zod';
|
|
7
|
+
/** The four provenance kinds. Measured beats observed, observed beats inferred. */
|
|
8
|
+
export declare const PROVENANCE_KINDS: readonly ["measured", "observed", "inferred", "unknown"];
|
|
9
|
+
/** Where a value came from. `agent` is the only source allowed for `inferred`. */
|
|
10
|
+
export declare const PROVENANCE_SOURCES: readonly ["computed-style", "bounding-box", "a11y-tree", "screenshot", "interaction", "network", "agent"];
|
|
11
|
+
/** Instrument sources: everything except `agent`. */
|
|
12
|
+
export declare const INSTRUMENT_SOURCES: readonly ["computed-style", "bounding-box", "a11y-tree", "screenshot", "interaction", "network"];
|
|
13
|
+
/** Viewport size in CSS pixels. */
|
|
14
|
+
export declare const ViewportSchema: z.ZodObject<{
|
|
15
|
+
width: z.ZodNumber;
|
|
16
|
+
height: z.ZodNumber;
|
|
17
|
+
}, z.core.$strict>;
|
|
18
|
+
export type Viewport = z.infer<typeof ViewportSchema>;
|
|
19
|
+
/** Provenance of a value measured directly by the instrument. */
|
|
20
|
+
export declare const MeasuredProvenanceSchema: z.ZodObject<{
|
|
21
|
+
kind: z.ZodLiteral<"measured">;
|
|
22
|
+
source: z.ZodEnum<{
|
|
23
|
+
"computed-style": "computed-style";
|
|
24
|
+
"bounding-box": "bounding-box";
|
|
25
|
+
"a11y-tree": "a11y-tree";
|
|
26
|
+
screenshot: "screenshot";
|
|
27
|
+
interaction: "interaction";
|
|
28
|
+
network: "network";
|
|
29
|
+
}>;
|
|
30
|
+
stateId: z.ZodOptional<z.ZodString>;
|
|
31
|
+
viewport: z.ZodOptional<z.ZodObject<{
|
|
32
|
+
width: z.ZodNumber;
|
|
33
|
+
height: z.ZodNumber;
|
|
34
|
+
}, z.core.$strict>>;
|
|
35
|
+
evidenceId: z.ZodOptional<z.ZodString>;
|
|
36
|
+
capturedAt: z.ZodISODateTime;
|
|
37
|
+
confidence: z.ZodNumber;
|
|
38
|
+
}, z.core.$strict>;
|
|
39
|
+
export type MeasuredProvenance = z.infer<typeof MeasuredProvenanceSchema>;
|
|
40
|
+
/** Provenance of a value observed by the instrument (an interaction outcome, a visual change) rather than measured as a number. */
|
|
41
|
+
export declare const ObservedProvenanceSchema: z.ZodObject<{
|
|
42
|
+
kind: z.ZodLiteral<"observed">;
|
|
43
|
+
source: z.ZodEnum<{
|
|
44
|
+
"computed-style": "computed-style";
|
|
45
|
+
"bounding-box": "bounding-box";
|
|
46
|
+
"a11y-tree": "a11y-tree";
|
|
47
|
+
screenshot: "screenshot";
|
|
48
|
+
interaction: "interaction";
|
|
49
|
+
network: "network";
|
|
50
|
+
}>;
|
|
51
|
+
stateId: z.ZodOptional<z.ZodString>;
|
|
52
|
+
viewport: z.ZodOptional<z.ZodObject<{
|
|
53
|
+
width: z.ZodNumber;
|
|
54
|
+
height: z.ZodNumber;
|
|
55
|
+
}, z.core.$strict>>;
|
|
56
|
+
evidenceId: z.ZodOptional<z.ZodString>;
|
|
57
|
+
capturedAt: z.ZodISODateTime;
|
|
58
|
+
confidence: z.ZodNumber;
|
|
59
|
+
}, z.core.$strict>;
|
|
60
|
+
export type ObservedProvenance = z.infer<typeof ObservedProvenanceSchema>;
|
|
61
|
+
/** Provenance of a value written by the host agent through `annotate_dna`. Only `agent` may infer. */
|
|
62
|
+
export declare const InferredProvenanceSchema: z.ZodObject<{
|
|
63
|
+
kind: z.ZodLiteral<"inferred">;
|
|
64
|
+
source: z.ZodLiteral<"agent">;
|
|
65
|
+
stateId: z.ZodOptional<z.ZodString>;
|
|
66
|
+
viewport: z.ZodOptional<z.ZodObject<{
|
|
67
|
+
width: z.ZodNumber;
|
|
68
|
+
height: z.ZodNumber;
|
|
69
|
+
}, z.core.$strict>>;
|
|
70
|
+
evidenceId: z.ZodOptional<z.ZodString>;
|
|
71
|
+
capturedAt: z.ZodISODateTime;
|
|
72
|
+
confidence: z.ZodNumber;
|
|
73
|
+
rationale: z.ZodOptional<z.ZodString>;
|
|
74
|
+
basedOn: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
75
|
+
}, z.core.$strict>;
|
|
76
|
+
export type InferredProvenance = z.infer<typeof InferredProvenanceSchema>;
|
|
77
|
+
/** Provenance of a value that could not be obtained. Carries the reason instead of a value. */
|
|
78
|
+
export declare const UnknownProvenanceSchema: z.ZodObject<{
|
|
79
|
+
kind: z.ZodLiteral<"unknown">;
|
|
80
|
+
reason: z.ZodString;
|
|
81
|
+
source: z.ZodOptional<z.ZodEnum<{
|
|
82
|
+
"computed-style": "computed-style";
|
|
83
|
+
"bounding-box": "bounding-box";
|
|
84
|
+
"a11y-tree": "a11y-tree";
|
|
85
|
+
screenshot: "screenshot";
|
|
86
|
+
interaction: "interaction";
|
|
87
|
+
network: "network";
|
|
88
|
+
}>>;
|
|
89
|
+
stateId: z.ZodOptional<z.ZodString>;
|
|
90
|
+
viewport: z.ZodOptional<z.ZodObject<{
|
|
91
|
+
width: z.ZodNumber;
|
|
92
|
+
height: z.ZodNumber;
|
|
93
|
+
}, z.core.$strict>>;
|
|
94
|
+
evidenceId: z.ZodOptional<z.ZodString>;
|
|
95
|
+
capturedAt: z.ZodOptional<z.ZodISODateTime>;
|
|
96
|
+
}, z.core.$strict>;
|
|
97
|
+
export type UnknownProvenance = z.infer<typeof UnknownProvenanceSchema>;
|
|
98
|
+
/** Provenance for values that exist (measured, observed or inferred). */
|
|
99
|
+
export declare const KnownProvenanceSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
100
|
+
kind: z.ZodLiteral<"measured">;
|
|
101
|
+
source: z.ZodEnum<{
|
|
102
|
+
"computed-style": "computed-style";
|
|
103
|
+
"bounding-box": "bounding-box";
|
|
104
|
+
"a11y-tree": "a11y-tree";
|
|
105
|
+
screenshot: "screenshot";
|
|
106
|
+
interaction: "interaction";
|
|
107
|
+
network: "network";
|
|
108
|
+
}>;
|
|
109
|
+
stateId: z.ZodOptional<z.ZodString>;
|
|
110
|
+
viewport: z.ZodOptional<z.ZodObject<{
|
|
111
|
+
width: z.ZodNumber;
|
|
112
|
+
height: z.ZodNumber;
|
|
113
|
+
}, z.core.$strict>>;
|
|
114
|
+
evidenceId: z.ZodOptional<z.ZodString>;
|
|
115
|
+
capturedAt: z.ZodISODateTime;
|
|
116
|
+
confidence: z.ZodNumber;
|
|
117
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
118
|
+
kind: z.ZodLiteral<"observed">;
|
|
119
|
+
source: z.ZodEnum<{
|
|
120
|
+
"computed-style": "computed-style";
|
|
121
|
+
"bounding-box": "bounding-box";
|
|
122
|
+
"a11y-tree": "a11y-tree";
|
|
123
|
+
screenshot: "screenshot";
|
|
124
|
+
interaction: "interaction";
|
|
125
|
+
network: "network";
|
|
126
|
+
}>;
|
|
127
|
+
stateId: z.ZodOptional<z.ZodString>;
|
|
128
|
+
viewport: z.ZodOptional<z.ZodObject<{
|
|
129
|
+
width: z.ZodNumber;
|
|
130
|
+
height: z.ZodNumber;
|
|
131
|
+
}, z.core.$strict>>;
|
|
132
|
+
evidenceId: z.ZodOptional<z.ZodString>;
|
|
133
|
+
capturedAt: z.ZodISODateTime;
|
|
134
|
+
confidence: z.ZodNumber;
|
|
135
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
136
|
+
kind: z.ZodLiteral<"inferred">;
|
|
137
|
+
source: z.ZodLiteral<"agent">;
|
|
138
|
+
stateId: z.ZodOptional<z.ZodString>;
|
|
139
|
+
viewport: z.ZodOptional<z.ZodObject<{
|
|
140
|
+
width: z.ZodNumber;
|
|
141
|
+
height: z.ZodNumber;
|
|
142
|
+
}, z.core.$strict>>;
|
|
143
|
+
evidenceId: z.ZodOptional<z.ZodString>;
|
|
144
|
+
capturedAt: z.ZodISODateTime;
|
|
145
|
+
confidence: z.ZodNumber;
|
|
146
|
+
rationale: z.ZodOptional<z.ZodString>;
|
|
147
|
+
basedOn: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
148
|
+
}, z.core.$strict>], "kind">;
|
|
149
|
+
export type KnownProvenance = z.infer<typeof KnownProvenanceSchema>;
|
|
150
|
+
/** Any provenance. */
|
|
151
|
+
export declare const ProvenanceSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
152
|
+
kind: z.ZodLiteral<"measured">;
|
|
153
|
+
source: z.ZodEnum<{
|
|
154
|
+
"computed-style": "computed-style";
|
|
155
|
+
"bounding-box": "bounding-box";
|
|
156
|
+
"a11y-tree": "a11y-tree";
|
|
157
|
+
screenshot: "screenshot";
|
|
158
|
+
interaction: "interaction";
|
|
159
|
+
network: "network";
|
|
160
|
+
}>;
|
|
161
|
+
stateId: z.ZodOptional<z.ZodString>;
|
|
162
|
+
viewport: z.ZodOptional<z.ZodObject<{
|
|
163
|
+
width: z.ZodNumber;
|
|
164
|
+
height: z.ZodNumber;
|
|
165
|
+
}, z.core.$strict>>;
|
|
166
|
+
evidenceId: z.ZodOptional<z.ZodString>;
|
|
167
|
+
capturedAt: z.ZodISODateTime;
|
|
168
|
+
confidence: z.ZodNumber;
|
|
169
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
170
|
+
kind: z.ZodLiteral<"observed">;
|
|
171
|
+
source: z.ZodEnum<{
|
|
172
|
+
"computed-style": "computed-style";
|
|
173
|
+
"bounding-box": "bounding-box";
|
|
174
|
+
"a11y-tree": "a11y-tree";
|
|
175
|
+
screenshot: "screenshot";
|
|
176
|
+
interaction: "interaction";
|
|
177
|
+
network: "network";
|
|
178
|
+
}>;
|
|
179
|
+
stateId: z.ZodOptional<z.ZodString>;
|
|
180
|
+
viewport: z.ZodOptional<z.ZodObject<{
|
|
181
|
+
width: z.ZodNumber;
|
|
182
|
+
height: z.ZodNumber;
|
|
183
|
+
}, z.core.$strict>>;
|
|
184
|
+
evidenceId: z.ZodOptional<z.ZodString>;
|
|
185
|
+
capturedAt: z.ZodISODateTime;
|
|
186
|
+
confidence: z.ZodNumber;
|
|
187
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
188
|
+
kind: z.ZodLiteral<"inferred">;
|
|
189
|
+
source: z.ZodLiteral<"agent">;
|
|
190
|
+
stateId: z.ZodOptional<z.ZodString>;
|
|
191
|
+
viewport: z.ZodOptional<z.ZodObject<{
|
|
192
|
+
width: z.ZodNumber;
|
|
193
|
+
height: z.ZodNumber;
|
|
194
|
+
}, z.core.$strict>>;
|
|
195
|
+
evidenceId: z.ZodOptional<z.ZodString>;
|
|
196
|
+
capturedAt: z.ZodISODateTime;
|
|
197
|
+
confidence: z.ZodNumber;
|
|
198
|
+
rationale: z.ZodOptional<z.ZodString>;
|
|
199
|
+
basedOn: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
200
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
201
|
+
kind: z.ZodLiteral<"unknown">;
|
|
202
|
+
reason: z.ZodString;
|
|
203
|
+
source: z.ZodOptional<z.ZodEnum<{
|
|
204
|
+
"computed-style": "computed-style";
|
|
205
|
+
"bounding-box": "bounding-box";
|
|
206
|
+
"a11y-tree": "a11y-tree";
|
|
207
|
+
screenshot: "screenshot";
|
|
208
|
+
interaction: "interaction";
|
|
209
|
+
network: "network";
|
|
210
|
+
}>>;
|
|
211
|
+
stateId: z.ZodOptional<z.ZodString>;
|
|
212
|
+
viewport: z.ZodOptional<z.ZodObject<{
|
|
213
|
+
width: z.ZodNumber;
|
|
214
|
+
height: z.ZodNumber;
|
|
215
|
+
}, z.core.$strict>>;
|
|
216
|
+
evidenceId: z.ZodOptional<z.ZodString>;
|
|
217
|
+
capturedAt: z.ZodOptional<z.ZodISODateTime>;
|
|
218
|
+
}, z.core.$strict>], "kind">;
|
|
219
|
+
export type Provenance = z.infer<typeof ProvenanceSchema>;
|
|
220
|
+
export type ProvenanceKind = Provenance['kind'];
|
|
221
|
+
export type ProvenanceSource = (typeof PROVENANCE_SOURCES)[number];
|
|
222
|
+
/**
|
|
223
|
+
* Wrap a value schema in the provenance envelope. A known value carries a
|
|
224
|
+
* known provenance; an unknown value is `null` with an `unknown` provenance
|
|
225
|
+
* that explains why. An `annotation` lets the agent attach its own reading
|
|
226
|
+
* next to the measured one without overwriting it.
|
|
227
|
+
*/
|
|
228
|
+
export declare function attributed<T extends z.ZodType>(value: T): z.ZodUnion<readonly [z.ZodObject<{
|
|
229
|
+
value: T;
|
|
230
|
+
provenance: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
231
|
+
kind: z.ZodLiteral<"measured">;
|
|
232
|
+
source: z.ZodEnum<{
|
|
233
|
+
"computed-style": "computed-style";
|
|
234
|
+
"bounding-box": "bounding-box";
|
|
235
|
+
"a11y-tree": "a11y-tree";
|
|
236
|
+
screenshot: "screenshot";
|
|
237
|
+
interaction: "interaction";
|
|
238
|
+
network: "network";
|
|
239
|
+
}>;
|
|
240
|
+
stateId: z.ZodOptional<z.ZodString>;
|
|
241
|
+
viewport: z.ZodOptional<z.ZodObject<{
|
|
242
|
+
width: z.ZodNumber;
|
|
243
|
+
height: z.ZodNumber;
|
|
244
|
+
}, z.core.$strict>>;
|
|
245
|
+
evidenceId: z.ZodOptional<z.ZodString>;
|
|
246
|
+
capturedAt: z.ZodISODateTime;
|
|
247
|
+
confidence: z.ZodNumber;
|
|
248
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
249
|
+
kind: z.ZodLiteral<"observed">;
|
|
250
|
+
source: z.ZodEnum<{
|
|
251
|
+
"computed-style": "computed-style";
|
|
252
|
+
"bounding-box": "bounding-box";
|
|
253
|
+
"a11y-tree": "a11y-tree";
|
|
254
|
+
screenshot: "screenshot";
|
|
255
|
+
interaction: "interaction";
|
|
256
|
+
network: "network";
|
|
257
|
+
}>;
|
|
258
|
+
stateId: z.ZodOptional<z.ZodString>;
|
|
259
|
+
viewport: z.ZodOptional<z.ZodObject<{
|
|
260
|
+
width: z.ZodNumber;
|
|
261
|
+
height: z.ZodNumber;
|
|
262
|
+
}, z.core.$strict>>;
|
|
263
|
+
evidenceId: z.ZodOptional<z.ZodString>;
|
|
264
|
+
capturedAt: z.ZodISODateTime;
|
|
265
|
+
confidence: z.ZodNumber;
|
|
266
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
267
|
+
kind: z.ZodLiteral<"inferred">;
|
|
268
|
+
source: z.ZodLiteral<"agent">;
|
|
269
|
+
stateId: z.ZodOptional<z.ZodString>;
|
|
270
|
+
viewport: z.ZodOptional<z.ZodObject<{
|
|
271
|
+
width: z.ZodNumber;
|
|
272
|
+
height: z.ZodNumber;
|
|
273
|
+
}, z.core.$strict>>;
|
|
274
|
+
evidenceId: z.ZodOptional<z.ZodString>;
|
|
275
|
+
capturedAt: z.ZodISODateTime;
|
|
276
|
+
confidence: z.ZodNumber;
|
|
277
|
+
rationale: z.ZodOptional<z.ZodString>;
|
|
278
|
+
basedOn: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
279
|
+
}, z.core.$strict>], "kind">;
|
|
280
|
+
annotation: z.ZodOptional<z.ZodObject<{
|
|
281
|
+
value: T;
|
|
282
|
+
provenance: z.ZodObject<{
|
|
283
|
+
kind: z.ZodLiteral<"inferred">;
|
|
284
|
+
source: z.ZodLiteral<"agent">;
|
|
285
|
+
stateId: z.ZodOptional<z.ZodString>;
|
|
286
|
+
viewport: z.ZodOptional<z.ZodObject<{
|
|
287
|
+
width: z.ZodNumber;
|
|
288
|
+
height: z.ZodNumber;
|
|
289
|
+
}, z.core.$strict>>;
|
|
290
|
+
evidenceId: z.ZodOptional<z.ZodString>;
|
|
291
|
+
capturedAt: z.ZodISODateTime;
|
|
292
|
+
confidence: z.ZodNumber;
|
|
293
|
+
rationale: z.ZodOptional<z.ZodString>;
|
|
294
|
+
basedOn: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
295
|
+
}, z.core.$strict>;
|
|
296
|
+
}, z.core.$strict>>;
|
|
297
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
298
|
+
value: z.ZodNull;
|
|
299
|
+
provenance: z.ZodObject<{
|
|
300
|
+
kind: z.ZodLiteral<"unknown">;
|
|
301
|
+
reason: z.ZodString;
|
|
302
|
+
source: z.ZodOptional<z.ZodEnum<{
|
|
303
|
+
"computed-style": "computed-style";
|
|
304
|
+
"bounding-box": "bounding-box";
|
|
305
|
+
"a11y-tree": "a11y-tree";
|
|
306
|
+
screenshot: "screenshot";
|
|
307
|
+
interaction: "interaction";
|
|
308
|
+
network: "network";
|
|
309
|
+
}>>;
|
|
310
|
+
stateId: z.ZodOptional<z.ZodString>;
|
|
311
|
+
viewport: z.ZodOptional<z.ZodObject<{
|
|
312
|
+
width: z.ZodNumber;
|
|
313
|
+
height: z.ZodNumber;
|
|
314
|
+
}, z.core.$strict>>;
|
|
315
|
+
evidenceId: z.ZodOptional<z.ZodString>;
|
|
316
|
+
capturedAt: z.ZodOptional<z.ZodISODateTime>;
|
|
317
|
+
}, z.core.$strict>;
|
|
318
|
+
annotation: z.ZodOptional<z.ZodObject<{
|
|
319
|
+
value: T;
|
|
320
|
+
provenance: z.ZodObject<{
|
|
321
|
+
kind: z.ZodLiteral<"inferred">;
|
|
322
|
+
source: z.ZodLiteral<"agent">;
|
|
323
|
+
stateId: z.ZodOptional<z.ZodString>;
|
|
324
|
+
viewport: z.ZodOptional<z.ZodObject<{
|
|
325
|
+
width: z.ZodNumber;
|
|
326
|
+
height: z.ZodNumber;
|
|
327
|
+
}, z.core.$strict>>;
|
|
328
|
+
evidenceId: z.ZodOptional<z.ZodString>;
|
|
329
|
+
capturedAt: z.ZodISODateTime;
|
|
330
|
+
confidence: z.ZodNumber;
|
|
331
|
+
rationale: z.ZodOptional<z.ZodString>;
|
|
332
|
+
basedOn: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
333
|
+
}, z.core.$strict>;
|
|
334
|
+
}, z.core.$strict>>;
|
|
335
|
+
}, z.core.$strict>]>;
|
|
336
|
+
/** TypeScript shape of an attributed value. */
|
|
337
|
+
export type Attributed<T> = {
|
|
338
|
+
value: T;
|
|
339
|
+
provenance: KnownProvenance;
|
|
340
|
+
annotation?: {
|
|
341
|
+
value: T;
|
|
342
|
+
provenance: InferredProvenance;
|
|
343
|
+
};
|
|
344
|
+
} | {
|
|
345
|
+
value: null;
|
|
346
|
+
provenance: UnknownProvenance;
|
|
347
|
+
annotation?: {
|
|
348
|
+
value: T;
|
|
349
|
+
provenance: InferredProvenance;
|
|
350
|
+
};
|
|
351
|
+
};
|
|
352
|
+
/** Context shared by many measured values of one capture. */
|
|
353
|
+
export interface ProvenanceContext {
|
|
354
|
+
stateId?: string;
|
|
355
|
+
viewport?: Viewport;
|
|
356
|
+
evidenceId?: string;
|
|
357
|
+
capturedAt: string;
|
|
358
|
+
}
|
|
359
|
+
/** Build a measured value. */
|
|
360
|
+
export declare function measured<T>(value: T, source: (typeof INSTRUMENT_SOURCES)[number], context: ProvenanceContext, confidence?: number): Attributed<T>;
|
|
361
|
+
/** Build an observed value. */
|
|
362
|
+
export declare function observed<T>(value: T, source: (typeof INSTRUMENT_SOURCES)[number], context: ProvenanceContext, confidence?: number): Attributed<T>;
|
|
363
|
+
/** Build an inferred (agent-written) value. */
|
|
364
|
+
export declare function inferred<T>(value: T, context: ProvenanceContext & {
|
|
365
|
+
rationale?: string;
|
|
366
|
+
basedOn?: string[];
|
|
367
|
+
}, confidence: number): Attributed<T>;
|
|
368
|
+
/** Build an unknown value with a reason. */
|
|
369
|
+
export declare function unknown<T = never>(reason: string, context?: Partial<ProvenanceContext> & {
|
|
370
|
+
source?: (typeof INSTRUMENT_SOURCES)[number];
|
|
371
|
+
}): Attributed<T>;
|
|
372
|
+
/** True when the attributed value is known (not `unknown`). */
|
|
373
|
+
export declare function isKnown<T>(attr: Attributed<T>): attr is Extract<Attributed<T>, {
|
|
374
|
+
value: T;
|
|
375
|
+
}>;
|
|
376
|
+
/** The agent's annotation when present, otherwise the instrument's value. */
|
|
377
|
+
export declare function effectiveValue<T>(attr: Attributed<T>): T | null;
|