@agent-native/core 0.232.0 → 0.233.0-nightly-20261124004026
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/dist/a2a/handlers.js +60 -1
- package/dist/a2a/server.js +9 -0
- package/dist/action-call-classification.d.ts +9 -0
- package/dist/action-call-classification.js +18 -0
- package/dist/action-conformance.d.ts +81 -0
- package/dist/action-conformance.js +392 -0
- package/dist/action.d.ts +18 -0
- package/dist/action.js +68 -5
- package/dist/agent/execution-fence.d.ts +3 -1
- package/dist/agent/execution-fence.js +13 -2
- package/dist/agent/production-agent.d.ts +3 -0
- package/dist/agent/production-agent.js +301 -145
- package/dist/agent/run-store.js +11 -0
- package/dist/agent/thread-data-builder.d.ts +2 -0
- package/dist/agent/thread-data-builder.js +5 -1
- package/dist/app-config/schema.d.ts +24 -1
- package/dist/application-state/handlers.d.ts +1 -1
- package/dist/application-state/navigate-write-guard.d.ts +4 -1
- package/dist/application-state/navigate-write-guard.js +15 -1
- package/dist/cli/design-connect.js +5 -1
- package/dist/cli/matched-check.d.ts +1 -0
- package/dist/cli/matched-check.js +76 -0
- package/dist/client/agent-chat/index.d.ts +1 -1
- package/dist/client/agent-chat/index.js +1 -1
- package/dist/client/analytics/index.d.ts +1 -1
- package/dist/client/analytics.d.ts +13 -1
- package/dist/client/analytics.js +5 -2
- package/dist/client/application-state.d.ts +11 -0
- package/dist/client/application-state.js +219 -23
- package/dist/client/chat/agentkit-agent-native.js +52 -11
- package/dist/client/chat/agentkit-protocol.js +23 -2
- package/dist/client/chat-first-state.d.ts +6 -0
- package/dist/client/chat-first-state.js +36 -1
- package/dist/client/feature-flags/use-feature-flag.js +14 -6
- package/dist/client/navigation/index.d.ts +2 -0
- package/dist/client/navigation/index.js +2 -0
- package/dist/client/route-state.js +60 -18
- package/dist/client/screen-settled.d.ts +71 -1
- package/dist/client/screen-settled.js +221 -3
- package/dist/client/sse-event-processor.d.ts +1 -0
- package/dist/client/sse-event-processor.js +89 -10
- package/dist/client/theme.d.ts +6 -0
- package/dist/client/theme.js +7 -1
- package/dist/client/use-action.js +32 -10
- package/dist/client/use-session.js +36 -18
- package/dist/collab/struct-routes.d.ts +1 -1
- package/dist/db/client.js +2 -2
- package/dist/db/errors.d.ts +2 -0
- package/dist/db/errors.js +38 -6
- package/dist/feature-flags/actions/get-feature-flags.js +9 -2
- package/dist/file-upload/actions/upload-image.d.ts +2 -2
- package/dist/framework-package-versions.json +8 -8
- package/dist/ingestion/index.d.ts +1 -0
- package/dist/ingestion/index.js +1 -0
- package/dist/ingestion/matched-capture.d.ts +173 -0
- package/dist/ingestion/matched-capture.js +574 -0
- package/dist/ingestion/pptx.d.ts +1 -0
- package/dist/ingestion/pptx.js +4 -2
- package/dist/labs/store.d.ts +3 -1
- package/dist/labs/store.js +8 -4
- package/dist/manifest/index.d.ts +142 -3
- package/dist/manifest/index.js +249 -19
- package/dist/mcp/build-server.d.ts +2 -0
- package/dist/mcp/build-server.js +8 -1
- package/dist/mcp/server.js +3 -1
- package/dist/notifications/routes.d.ts +3 -3
- package/dist/observability/metrics.d.ts +2 -0
- package/dist/observability/metrics.js +7 -0
- package/dist/org/index.d.ts +1 -1
- package/dist/provider-api/actions/custom-provider-registration.d.ts +10 -10
- package/dist/provider-api/actions/provider-api.d.ts +14 -14
- package/dist/server/action-routes.js +9 -0
- package/dist/server/agent-chat/prompt-resources.js +107 -83
- package/dist/server/agent-run-context.d.ts +3 -0
- package/dist/server/agent-run-context.js +7 -0
- package/dist/server/builder-oauth.d.ts +1 -0
- package/dist/server/builder-oauth.js +40 -2
- package/dist/server/filesystem-action-entry.js +5 -0
- package/dist/server/first-touch-route.d.ts +2 -2
- package/dist/server/index.d.ts +2 -2
- package/dist/server/index.js +2 -2
- package/dist/server/open-route.js +10 -4
- package/dist/server/poll.d.ts +3 -0
- package/dist/server/poll.js +74 -14
- package/dist/server/request-context.d.ts +16 -6
- package/dist/server/request-context.js +4 -0
- package/dist/server/transcribe-voice.d.ts +1 -1
- package/dist/shared/analytics-events.d.ts +7 -0
- package/dist/shared/viewport-mode.d.ts +2 -0
- package/dist/shared/viewport-mode.js +9 -0
- package/dist/templates/chat/.agents/skills/actions/SKILL.md +1 -0
- package/dist/templates/chat/.agents/skills/build-an-app/SKILL.md +38 -17
- package/dist/templates/chat/.agents/skills/shadcn-ui/SKILL.md +3 -2
- package/dist/templates/default/.agents/skills/actions/SKILL.md +1 -0
- package/dist/templates/default/.agents/skills/build-an-app/SKILL.md +38 -17
- package/dist/templates/default/.agents/skills/shadcn-ui/SKILL.md +3 -2
- package/dist/templates/factory/.agents/skills/review-latest-feedback/SKILL.md +3 -2
- package/dist/templates/headless/.agents/skills/actions/SKILL.md +1 -0
- package/dist/templates/workspace-core/.agents/skills/actions/SKILL.md +1 -0
- package/dist/templates/workspace-core/.agents/skills/build-an-app/SKILL.md +38 -17
- package/dist/templates/workspace-core/.agents/skills/shadcn-ui/SKILL.md +3 -2
- package/dist/testing.d.ts +1 -0
- package/dist/testing.js +1 -0
- package/dist/tracking/action-lifecycle.d.ts +2 -0
- package/dist/tracking/action-lifecycle.js +16 -5
- package/docs/content/actions-defining.mdx +7 -0
- package/docs/content/custom-design-system.mdx +4 -2
- package/package.json +3 -3
- package/src/templates/chat/.agents/skills/actions/SKILL.md +1 -0
- package/src/templates/chat/.agents/skills/build-an-app/SKILL.md +38 -17
- package/src/templates/chat/.agents/skills/shadcn-ui/SKILL.md +3 -2
- package/src/templates/default/.agents/skills/actions/SKILL.md +1 -0
- package/src/templates/default/.agents/skills/build-an-app/SKILL.md +38 -17
- package/src/templates/default/.agents/skills/shadcn-ui/SKILL.md +3 -2
- package/src/templates/factory/.agents/skills/review-latest-feedback/SKILL.md +3 -2
- package/src/templates/headless/.agents/skills/actions/SKILL.md +1 -0
- package/src/templates/workspace-core/.agents/skills/actions/SKILL.md +1 -0
- package/src/templates/workspace-core/.agents/skills/build-an-app/SKILL.md +38 -17
- package/src/templates/workspace-core/.agents/skills/shadcn-ui/SKILL.md +3 -2
|
@@ -0,0 +1,574 @@
|
|
|
1
|
+
import { sha256 } from "@noble/hashes/sha2.js";
|
|
2
|
+
import { bytesToHex } from "@noble/hashes/utils.js";
|
|
3
|
+
import { loadOptionalPeer } from "../shared/optional-peer.js";
|
|
4
|
+
export const BREAKPOINT_PRESETS = {
|
|
5
|
+
desktop: { width: 1440, height: 900, deviceScaleFactor: 1 },
|
|
6
|
+
tablet: { width: 900, height: 1200, deviceScaleFactor: 2 },
|
|
7
|
+
mobile: { width: 390, height: 844, deviceScaleFactor: 2 },
|
|
8
|
+
};
|
|
9
|
+
export function resolveBreakpoint(input) {
|
|
10
|
+
if ("preset" in input) {
|
|
11
|
+
const preset = BREAKPOINT_PRESETS[input.preset];
|
|
12
|
+
if (!preset)
|
|
13
|
+
throw new Error(`Unknown breakpoint preset "${input.preset}".`);
|
|
14
|
+
const { preset: name, ...overrides } = input;
|
|
15
|
+
return { ...preset, ...overrides, name: overrides.name ?? name };
|
|
16
|
+
}
|
|
17
|
+
return input;
|
|
18
|
+
}
|
|
19
|
+
async function loadSharp() {
|
|
20
|
+
const specifier = "sharp";
|
|
21
|
+
const module = (await loadOptionalPeer("sharp", () => import(/* @vite-ignore */ specifier)));
|
|
22
|
+
return module.default ?? module;
|
|
23
|
+
}
|
|
24
|
+
const MAX_CONCURRENCY = 4;
|
|
25
|
+
const MAX_MOTION_FRAMES = 6;
|
|
26
|
+
const MAX_MOTION_INTERVAL_MS = 1000;
|
|
27
|
+
function parseBackground(value) {
|
|
28
|
+
const match = /^#([0-9a-f]{6})$/i.exec(value ?? "");
|
|
29
|
+
const hex = match?.[1];
|
|
30
|
+
if (!hex)
|
|
31
|
+
return null;
|
|
32
|
+
const n = parseInt(hex, 16);
|
|
33
|
+
return { r: (n >> 16) & 255, g: (n >> 8) & 255, b: n & 255 };
|
|
34
|
+
}
|
|
35
|
+
function check(breakpoint, id, status, detail) {
|
|
36
|
+
return { id, breakpoint, status, detail };
|
|
37
|
+
}
|
|
38
|
+
const SAFE_BREAKPOINT_NAME = /^[A-Za-z0-9][A-Za-z0-9_-]{0,63}$/;
|
|
39
|
+
function validateBreakpointRecord(bp) {
|
|
40
|
+
if (typeof bp.name !== "string" || !SAFE_BREAKPOINT_NAME.test(bp.name)) {
|
|
41
|
+
return "name must be 1-64 letters, digits, dashes or underscores, starting with a letter or digit";
|
|
42
|
+
}
|
|
43
|
+
const ints = [bp.width, bp.height];
|
|
44
|
+
if (!ints.every((n) => Number.isInteger(n) && n > 0)) {
|
|
45
|
+
return "width and height must be positive integers";
|
|
46
|
+
}
|
|
47
|
+
if (!(bp.deviceScaleFactor > 0))
|
|
48
|
+
return "deviceScaleFactor must be positive";
|
|
49
|
+
const reducedMotion = bp.reducedMotion;
|
|
50
|
+
if (reducedMotion !== undefined &&
|
|
51
|
+
reducedMotion !== "reduce" &&
|
|
52
|
+
reducedMotion !== "no-preference")
|
|
53
|
+
return "unsupported reducedMotion";
|
|
54
|
+
if (bp.colorSpace && bp.colorSpace !== "srgb") {
|
|
55
|
+
return `unsupported colorSpace "${bp.colorSpace}"`;
|
|
56
|
+
}
|
|
57
|
+
if (bp.orientation && bp.orientation !== "normal") {
|
|
58
|
+
return `unsupported orientation "${bp.orientation}"`;
|
|
59
|
+
}
|
|
60
|
+
if (bp.crop) {
|
|
61
|
+
const { left, top, width, height } = bp.crop;
|
|
62
|
+
if (left < 0 ||
|
|
63
|
+
top < 0 ||
|
|
64
|
+
!(width > 0) ||
|
|
65
|
+
!(height > 0) ||
|
|
66
|
+
left + width > bp.width ||
|
|
67
|
+
top + height > bp.height) {
|
|
68
|
+
return "crop must lie inside the viewport";
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
function expectedPixels(bp) {
|
|
74
|
+
const w = bp.crop?.width ?? bp.width;
|
|
75
|
+
const h = bp.crop?.height ?? bp.height;
|
|
76
|
+
return {
|
|
77
|
+
width: Math.round(w * bp.deviceScaleFactor),
|
|
78
|
+
height: Math.round(h * bp.deviceScaleFactor),
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
function clockCheck(bp, side, capture, tolerance, requested) {
|
|
82
|
+
const id = `clock-${side}`;
|
|
83
|
+
if (!capture.clock.pinned || capture.clock.requestedTimeMs === null) {
|
|
84
|
+
return check(bp, id, "could-not-run", capture.clock.reason ??
|
|
85
|
+
`${side} clock could not be pinned (${capture.clock.kind}); comparison is unverified`);
|
|
86
|
+
}
|
|
87
|
+
if (requested.kind === "unpinned" ||
|
|
88
|
+
capture.clock.kind !== requested.kind ||
|
|
89
|
+
capture.clock.requestedTimeMs !== requested.timeMs) {
|
|
90
|
+
return check(bp, id, "fail", `${side} capturer did not honor the requested clock`);
|
|
91
|
+
}
|
|
92
|
+
const observed = capture.observed.timeMs;
|
|
93
|
+
if (observed === null || !Number.isFinite(observed)) {
|
|
94
|
+
return check(bp, id, "could-not-run", `${side} pinned time could not be read back`);
|
|
95
|
+
}
|
|
96
|
+
const skew = Math.abs(observed - capture.clock.requestedTimeMs);
|
|
97
|
+
return skew <= tolerance
|
|
98
|
+
? check(bp, id, "pass", `observed ${observed}ms matches requested`)
|
|
99
|
+
: check(bp, id, "fail", `${side} observed time ${observed}ms differs from requested ${capture.clock.requestedTimeMs}ms by ${skew}ms`);
|
|
100
|
+
}
|
|
101
|
+
function validateSide(bp, side, capture) {
|
|
102
|
+
const out = [];
|
|
103
|
+
const v = capture.observed.viewport;
|
|
104
|
+
out.push(v.width === bp.width && v.height === bp.height
|
|
105
|
+
? check(bp.name, `viewport-${side}`, "pass", `${v.width}x${v.height}`)
|
|
106
|
+
: check(bp.name, `viewport-${side}`, "fail", `requested ${bp.width}x${bp.height} but ${side} rendered ${v.width}x${v.height}`));
|
|
107
|
+
out.push(capture.observed.devicePixelRatio === bp.deviceScaleFactor
|
|
108
|
+
? check(bp.name, `dpr-${side}`, "pass", `${bp.deviceScaleFactor}`)
|
|
109
|
+
: check(bp.name, `dpr-${side}`, "fail", `requested DPR ${bp.deviceScaleFactor} but ${side} observed ${capture.observed.devicePixelRatio}`));
|
|
110
|
+
if (bp.reducedMotion) {
|
|
111
|
+
const wantReduce = bp.reducedMotion === "reduce";
|
|
112
|
+
out.push(capture.observed.reducedMotion === wantReduce
|
|
113
|
+
? check(bp.name, `reduced-motion-${side}`, "pass", bp.reducedMotion)
|
|
114
|
+
: check(bp.name, `reduced-motion-${side}`, "fail", `requested ${bp.reducedMotion} but ${side} observed prefers-reduced-motion=${capture.observed.reducedMotion}`));
|
|
115
|
+
}
|
|
116
|
+
return out;
|
|
117
|
+
}
|
|
118
|
+
async function decode(sharp, bytes) {
|
|
119
|
+
const m = await sharp(Buffer.from(bytes), { failOn: "none" }).metadata();
|
|
120
|
+
if (!m.width || !m.height)
|
|
121
|
+
throw new Error("image has no dimensions");
|
|
122
|
+
let hasTransparency = false;
|
|
123
|
+
if (m.hasAlpha === true) {
|
|
124
|
+
const { data, info } = await sharp(Buffer.from(bytes), { failOn: "none" })
|
|
125
|
+
.raw()
|
|
126
|
+
.toBuffer({ resolveWithObject: true });
|
|
127
|
+
const channels = info.channels;
|
|
128
|
+
if (channels >= 2) {
|
|
129
|
+
for (let i = channels - 1; i < data.length; i += channels) {
|
|
130
|
+
if ((data[i] ?? 255) < 255) {
|
|
131
|
+
hasTransparency = true;
|
|
132
|
+
break;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
return {
|
|
138
|
+
width: m.width,
|
|
139
|
+
height: m.height,
|
|
140
|
+
hasAlpha: hasTransparency,
|
|
141
|
+
space: m.space,
|
|
142
|
+
orientation: m.orientation,
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
async function normalizedPixels(sharp, bytes, background) {
|
|
146
|
+
const { data, info } = await sharp(Buffer.from(bytes), { failOn: "none" })
|
|
147
|
+
.flatten({ background })
|
|
148
|
+
.removeAlpha()
|
|
149
|
+
.toColourspace("srgb")
|
|
150
|
+
.raw()
|
|
151
|
+
.toBuffer({ resolveWithObject: true });
|
|
152
|
+
if (info.channels !== 3) {
|
|
153
|
+
throw new Error(`normalized image has ${info.channels} channels, expected 3`);
|
|
154
|
+
}
|
|
155
|
+
return data;
|
|
156
|
+
}
|
|
157
|
+
function measure(a, b) {
|
|
158
|
+
const left = Buffer.from(a);
|
|
159
|
+
const right = Buffer.from(b);
|
|
160
|
+
let squared = 0;
|
|
161
|
+
let abs = 0;
|
|
162
|
+
for (let i = 0; i < a.length; i++) {
|
|
163
|
+
const d = (left.readUInt8(i) - right.readUInt8(i)) / 255;
|
|
164
|
+
squared += d * d;
|
|
165
|
+
abs += Math.abs(d);
|
|
166
|
+
}
|
|
167
|
+
return {
|
|
168
|
+
rmse: Math.sqrt(squared / a.length) * 100,
|
|
169
|
+
mae: (abs / a.length) * 100,
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
function sha(bytes) {
|
|
173
|
+
return bytesToHex(sha256(bytes));
|
|
174
|
+
}
|
|
175
|
+
async function compareBreakpoint(input, bp, sharp, clockTolerance) {
|
|
176
|
+
const result = {
|
|
177
|
+
breakpoint: bp.name,
|
|
178
|
+
validity: "valid",
|
|
179
|
+
checks: [],
|
|
180
|
+
artifacts: [],
|
|
181
|
+
diagnostics: [],
|
|
182
|
+
};
|
|
183
|
+
const invalid = validateBreakpointRecord(bp);
|
|
184
|
+
if (invalid) {
|
|
185
|
+
result.checks.push(check(bp.name, "breakpoint", "fail", invalid));
|
|
186
|
+
return finalize(result);
|
|
187
|
+
}
|
|
188
|
+
const run = (side) => input.capture({
|
|
189
|
+
side,
|
|
190
|
+
target: input[side].target,
|
|
191
|
+
breakpoint: bp,
|
|
192
|
+
clock: input[side].clock,
|
|
193
|
+
motion: input.motion,
|
|
194
|
+
});
|
|
195
|
+
const [sourceSettled, destinationSettled] = await Promise.allSettled([
|
|
196
|
+
run("source"),
|
|
197
|
+
run("destination"),
|
|
198
|
+
]);
|
|
199
|
+
const captures = {};
|
|
200
|
+
const record = (side, s) => {
|
|
201
|
+
if (s.status === "fulfilled") {
|
|
202
|
+
captures[side] = s.value;
|
|
203
|
+
result.checks.push(check(bp.name, `capture-${side}`, "pass", "captured"));
|
|
204
|
+
}
|
|
205
|
+
else {
|
|
206
|
+
const msg = s.reason instanceof Error ? s.reason.message : String(s.reason);
|
|
207
|
+
result.checks.push(check(bp.name, `capture-${side}`, "could-not-run", msg));
|
|
208
|
+
}
|
|
209
|
+
};
|
|
210
|
+
record("source", sourceSettled);
|
|
211
|
+
record("destination", destinationSettled);
|
|
212
|
+
const source = captures.source;
|
|
213
|
+
const destination = captures.destination;
|
|
214
|
+
if (!source || !destination)
|
|
215
|
+
return finalize(result);
|
|
216
|
+
result.checks.push(...validateSide(bp, "source", source), ...validateSide(bp, "destination", destination), clockCheck(bp.name, "source", source, clockTolerance, input.source.clock), clockCheck(bp.name, "destination", destination, clockTolerance, input.destination.clock));
|
|
217
|
+
if (source.observed.timeMs !== null &&
|
|
218
|
+
destination.observed.timeMs !== null &&
|
|
219
|
+
source.clock.pinned &&
|
|
220
|
+
destination.clock.pinned) {
|
|
221
|
+
const skew = Math.abs(source.observed.timeMs - destination.observed.timeMs);
|
|
222
|
+
result.checks.push(skew <= clockTolerance
|
|
223
|
+
? check(bp.name, "clock-match", "pass", "source and destination times match")
|
|
224
|
+
: check(bp.name, "clock-match", "fail", `source time ${source.observed.timeMs}ms and destination time ${destination.observed.timeMs}ms differ by ${skew}ms`));
|
|
225
|
+
}
|
|
226
|
+
else {
|
|
227
|
+
result.checks.push(check(bp.name, "clock-match", "could-not-run", "source and destination times are not both pinned and observed"));
|
|
228
|
+
}
|
|
229
|
+
if (source.motion || destination.motion) {
|
|
230
|
+
result.motion = {
|
|
231
|
+
source: source.motion,
|
|
232
|
+
destination: destination.motion,
|
|
233
|
+
note: "Short motion observation only; matching stills do not prove animation fidelity.",
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
let decoded;
|
|
237
|
+
try {
|
|
238
|
+
decoded = {
|
|
239
|
+
source: await decode(sharp, source.image),
|
|
240
|
+
destination: await decode(sharp, destination.image),
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
catch (error) {
|
|
244
|
+
result.checks.push(check(bp.name, "image-decode", "fail", error instanceof Error ? error.message : String(error)));
|
|
245
|
+
return finalize(result);
|
|
246
|
+
}
|
|
247
|
+
const expected = expectedPixels(bp);
|
|
248
|
+
for (const side of ["source", "destination"]) {
|
|
249
|
+
const d = decoded[side];
|
|
250
|
+
result.checks.push(d.width === expected.width && d.height === expected.height
|
|
251
|
+
? check(bp.name, `bounds-${side}`, "pass", `${d.width}x${d.height}`)
|
|
252
|
+
: check(bp.name, `bounds-${side}`, "fail", `${side} image is ${d.width}x${d.height}, expected ${expected.width}x${expected.height} for ${bp.crop ? "the crop" : "the viewport"} at DPR ${bp.deviceScaleFactor}`));
|
|
253
|
+
const badSpace = d.space !== undefined && d.space !== "srgb";
|
|
254
|
+
const badOrientation = d.orientation !== undefined && d.orientation !== 1;
|
|
255
|
+
result.checks.push(badSpace || badOrientation
|
|
256
|
+
? check(bp.name, `color-orientation-${side}`, "fail", `${side} image has colorSpace=${d.space ?? "unknown"} orientation=${d.orientation ?? "none"}; requested ${bp.colorSpace ?? "srgb"} / ${bp.orientation ?? "normal"}`)
|
|
257
|
+
: check(bp.name, `color-orientation-${side}`, "pass", "srgb, normal"));
|
|
258
|
+
}
|
|
259
|
+
const backgroundHex = input.background;
|
|
260
|
+
const background = parseBackground(backgroundHex);
|
|
261
|
+
const anyAlpha = decoded.source.hasAlpha || decoded.destination.hasAlpha;
|
|
262
|
+
if (backgroundHex !== undefined && !background) {
|
|
263
|
+
result.checks.push(check(bp.name, "alpha-normalization", "fail", `background "${backgroundHex}" is not an opaque #rrggbb color`));
|
|
264
|
+
}
|
|
265
|
+
else if (anyAlpha && !background) {
|
|
266
|
+
result.checks.push(check(bp.name, "alpha-normalization", "fail", "an image has transparency but no opaque #rrggbb background was provided to normalize both sides"));
|
|
267
|
+
}
|
|
268
|
+
else {
|
|
269
|
+
result.checks.push(check(bp.name, "alpha-normalization", "pass", anyAlpha ? `flattened onto ${input.background}` : "no transparency"));
|
|
270
|
+
}
|
|
271
|
+
if (input.storeArtifact) {
|
|
272
|
+
for (const side of ["source", "destination"]) {
|
|
273
|
+
const bytes = (side === "source" ? source : destination).image;
|
|
274
|
+
result.artifacts.push({
|
|
275
|
+
side,
|
|
276
|
+
handle: await input.storeArtifact(`${bp.name}-${side}.png`, bytes),
|
|
277
|
+
sha256: sha(bytes),
|
|
278
|
+
width: decoded[side].width,
|
|
279
|
+
height: decoded[side].height,
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
if (result.checks.some((c) => c.status !== "pass")) {
|
|
284
|
+
return finalize(result);
|
|
285
|
+
}
|
|
286
|
+
const flatten = background ?? { r: 255, g: 255, b: 255 };
|
|
287
|
+
const [a, b] = await Promise.all([
|
|
288
|
+
normalizedPixels(sharp, source.image, flatten),
|
|
289
|
+
normalizedPixels(sharp, destination.image, flatten),
|
|
290
|
+
]);
|
|
291
|
+
if (a.length !== b.length) {
|
|
292
|
+
result.checks.push(check(bp.name, "canvas-match", "fail", "normalized canvases differ in size"));
|
|
293
|
+
return finalize(result);
|
|
294
|
+
}
|
|
295
|
+
const { rmse, mae } = measure(a, b);
|
|
296
|
+
const threshold = input.maxRmsePercent ?? null;
|
|
297
|
+
result.alphaNormalization = {
|
|
298
|
+
background: backgroundHex ?? "none",
|
|
299
|
+
sourceHadAlpha: decoded.source.hasAlpha,
|
|
300
|
+
destinationHadAlpha: decoded.destination.hasAlpha,
|
|
301
|
+
};
|
|
302
|
+
result.fidelity = {
|
|
303
|
+
rmsePercent: round(rmse),
|
|
304
|
+
meanAbsolutePercent: round(mae),
|
|
305
|
+
width: decoded.source.width,
|
|
306
|
+
height: decoded.source.height,
|
|
307
|
+
threshold,
|
|
308
|
+
pass: threshold === null ? null : rmse <= threshold,
|
|
309
|
+
};
|
|
310
|
+
if (threshold !== null)
|
|
311
|
+
result.checks.push(check(bp.name, "fidelity-threshold", rmse <= threshold ? "pass" : "fail", `rmse ${round(rmse)}% ${rmse <= threshold ? "meets" : "exceeds"} threshold ${threshold}%`));
|
|
312
|
+
return finalize(result);
|
|
313
|
+
}
|
|
314
|
+
function round(n) {
|
|
315
|
+
return Math.round(n * 1000) / 1000;
|
|
316
|
+
}
|
|
317
|
+
function finalize(result) {
|
|
318
|
+
const failed = result.checks.filter((c) => c.status === "fail" && c.id !== "fidelity-threshold");
|
|
319
|
+
const notRun = result.checks.filter((c) => c.status === "could-not-run");
|
|
320
|
+
const captureFailed = notRun.some((c) => c.id.startsWith("capture-"));
|
|
321
|
+
const onlyClock = notRun.every((c) => c.id.startsWith("clock-"));
|
|
322
|
+
if (failed.length)
|
|
323
|
+
result.validity = "invalid";
|
|
324
|
+
else if (captureFailed)
|
|
325
|
+
result.validity = "could-not-run";
|
|
326
|
+
else if (notRun.length && onlyClock)
|
|
327
|
+
result.validity = "unverified";
|
|
328
|
+
else if (notRun.length)
|
|
329
|
+
result.validity = "could-not-run";
|
|
330
|
+
else
|
|
331
|
+
result.validity = "valid";
|
|
332
|
+
result.diagnostics = [...failed, ...notRun].map((c) => `${c.id}: ${c.detail}`);
|
|
333
|
+
if (result.validity !== "valid")
|
|
334
|
+
delete result.fidelity;
|
|
335
|
+
else if (result.fidelity?.pass === false) {
|
|
336
|
+
result.diagnostics.push(`fidelity: rmse ${result.fidelity.rmsePercent}% exceeds threshold ${result.fidelity.threshold}%`);
|
|
337
|
+
}
|
|
338
|
+
else if (!result.fidelity) {
|
|
339
|
+
result.validity = "could-not-run";
|
|
340
|
+
result.diagnostics.push("fidelity: no metric was produced");
|
|
341
|
+
}
|
|
342
|
+
return result;
|
|
343
|
+
}
|
|
344
|
+
async function mapWithConcurrency(items, limit, fn) {
|
|
345
|
+
const out = new Array(items.length);
|
|
346
|
+
const queue = items.entries();
|
|
347
|
+
const failures = [];
|
|
348
|
+
const worker = async () => {
|
|
349
|
+
for (const [index, item] of queue) {
|
|
350
|
+
if (failures.length > 0)
|
|
351
|
+
return;
|
|
352
|
+
try {
|
|
353
|
+
out[index] = await fn(item);
|
|
354
|
+
}
|
|
355
|
+
catch (error) {
|
|
356
|
+
failures.push(error);
|
|
357
|
+
return;
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
};
|
|
361
|
+
await Promise.all(Array.from({ length: Math.min(limit, items.length) }, worker));
|
|
362
|
+
if (failures.length > 0)
|
|
363
|
+
throw failures[0];
|
|
364
|
+
return out;
|
|
365
|
+
}
|
|
366
|
+
export function summarizeResults(results) {
|
|
367
|
+
let pass = 0;
|
|
368
|
+
let fail = 0;
|
|
369
|
+
let couldNotRun = 0;
|
|
370
|
+
for (const r of results) {
|
|
371
|
+
for (const c of r.checks) {
|
|
372
|
+
if (c.status === "pass")
|
|
373
|
+
pass++;
|
|
374
|
+
else if (c.status === "fail")
|
|
375
|
+
fail++;
|
|
376
|
+
else
|
|
377
|
+
couldNotRun++;
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
return {
|
|
381
|
+
results,
|
|
382
|
+
totals: {
|
|
383
|
+
breakpoints: results.length,
|
|
384
|
+
checks: pass + fail + couldNotRun,
|
|
385
|
+
pass,
|
|
386
|
+
fail,
|
|
387
|
+
couldNotRun,
|
|
388
|
+
},
|
|
389
|
+
};
|
|
390
|
+
}
|
|
391
|
+
export async function runMatchedCheck(input) {
|
|
392
|
+
const sharp = await loadSharp();
|
|
393
|
+
const rawConcurrency = input.concurrency ?? 2;
|
|
394
|
+
if (!Number.isInteger(rawConcurrency) || rawConcurrency < 1) {
|
|
395
|
+
throw new Error("concurrency must be a positive integer.");
|
|
396
|
+
}
|
|
397
|
+
const concurrency = Math.min(rawConcurrency, MAX_CONCURRENCY);
|
|
398
|
+
const tolerance = input.clockToleranceMs ?? 1;
|
|
399
|
+
if (!Number.isFinite(tolerance) || tolerance < 0) {
|
|
400
|
+
throw new Error("clockToleranceMs must be a finite non-negative number.");
|
|
401
|
+
}
|
|
402
|
+
if (input.motion &&
|
|
403
|
+
(!Number.isInteger(input.motion.frames) ||
|
|
404
|
+
input.motion.frames < 2 ||
|
|
405
|
+
!Number.isFinite(input.motion.intervalMs) ||
|
|
406
|
+
input.motion.intervalMs <= 0))
|
|
407
|
+
throw new Error("motion requires at least two frames and a positive finite intervalMs");
|
|
408
|
+
const motion = input.motion
|
|
409
|
+
? {
|
|
410
|
+
frames: Math.max(2, Math.min(input.motion.frames, MAX_MOTION_FRAMES)),
|
|
411
|
+
intervalMs: Math.max(1, Math.min(input.motion.intervalMs, MAX_MOTION_INTERVAL_MS)),
|
|
412
|
+
}
|
|
413
|
+
: undefined;
|
|
414
|
+
const bounded = { ...input, motion };
|
|
415
|
+
if (!Array.isArray(input.breakpoints) || input.breakpoints.length === 0) {
|
|
416
|
+
throw new Error("runMatchedCheck needs at least one breakpoint.");
|
|
417
|
+
}
|
|
418
|
+
const breakpoints = input.breakpoints.map(resolveBreakpoint);
|
|
419
|
+
const seen = new Set();
|
|
420
|
+
for (const bp of breakpoints) {
|
|
421
|
+
const key = bp.name.toLowerCase();
|
|
422
|
+
if (seen.has(key)) {
|
|
423
|
+
throw new Error(`Duplicate breakpoint name "${bp.name}".`);
|
|
424
|
+
}
|
|
425
|
+
seen.add(key);
|
|
426
|
+
}
|
|
427
|
+
const results = await mapWithConcurrency(breakpoints, concurrency, (bp) => compareBreakpoint(bounded, bp, sharp, tolerance));
|
|
428
|
+
return summarizeResults(results);
|
|
429
|
+
}
|
|
430
|
+
function toClip(crop) {
|
|
431
|
+
return { x: crop.left, y: crop.top, width: crop.width, height: crop.height };
|
|
432
|
+
}
|
|
433
|
+
export function createPlaywrightCapturer(options = {}) {
|
|
434
|
+
let browserPromise = null;
|
|
435
|
+
const getBrowser = () => {
|
|
436
|
+
browserPromise ??= (async () => {
|
|
437
|
+
const specifier = "playwright";
|
|
438
|
+
const pw = (await loadOptionalPeer("playwright", () => import(/* @vite-ignore */ specifier)));
|
|
439
|
+
return pw.chromium.launch({
|
|
440
|
+
headless: options.headless !== false,
|
|
441
|
+
args: options.launchArgs ?? [],
|
|
442
|
+
...(options.executablePath
|
|
443
|
+
? { executablePath: options.executablePath }
|
|
444
|
+
: {}),
|
|
445
|
+
});
|
|
446
|
+
})();
|
|
447
|
+
return browserPromise;
|
|
448
|
+
};
|
|
449
|
+
const capture = async (request) => {
|
|
450
|
+
const { breakpoint: bp, clock } = request;
|
|
451
|
+
const browser = await getBrowser();
|
|
452
|
+
const context = await browser.newContext({
|
|
453
|
+
viewport: { width: bp.width, height: bp.height },
|
|
454
|
+
deviceScaleFactor: bp.deviceScaleFactor,
|
|
455
|
+
reducedMotion: bp.reducedMotion ?? "no-preference",
|
|
456
|
+
});
|
|
457
|
+
try {
|
|
458
|
+
const page = await context.newPage();
|
|
459
|
+
const requestedTimeMs = clock.kind === "unpinned" ? null : clock.timeMs;
|
|
460
|
+
if (clock.kind === "playwright-clock") {
|
|
461
|
+
await context.clock.install({ time: clock.timeMs - 1000 });
|
|
462
|
+
await page.clock.pauseAt(clock.timeMs);
|
|
463
|
+
}
|
|
464
|
+
await page.goto(request.target, { waitUntil: "load" });
|
|
465
|
+
let pinned = false;
|
|
466
|
+
let reason;
|
|
467
|
+
if (clock.kind === "playwright-clock") {
|
|
468
|
+
pinned = true;
|
|
469
|
+
}
|
|
470
|
+
else if (clock.kind === "hook") {
|
|
471
|
+
const applied = await page.evaluate((a) => {
|
|
472
|
+
let target = globalThis;
|
|
473
|
+
let owner = globalThis;
|
|
474
|
+
for (const part of a.setter.split(".")) {
|
|
475
|
+
owner = target;
|
|
476
|
+
target = target?.[part];
|
|
477
|
+
}
|
|
478
|
+
if (typeof target !== "function")
|
|
479
|
+
return false;
|
|
480
|
+
target.call(owner, a.timeMs);
|
|
481
|
+
return true;
|
|
482
|
+
}, { setter: clock.setter, timeMs: clock.timeMs });
|
|
483
|
+
pinned = applied;
|
|
484
|
+
if (!applied) {
|
|
485
|
+
reason = `unsupported clock hook: "${clock.setter}" is not a function on the page`;
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
else {
|
|
489
|
+
reason = "no clock strategy: time is not pinned";
|
|
490
|
+
}
|
|
491
|
+
const observed = await page.evaluate((a) => {
|
|
492
|
+
let time = null;
|
|
493
|
+
if (a.readback) {
|
|
494
|
+
let v = globalThis;
|
|
495
|
+
for (const part of a.readback.split(".")) {
|
|
496
|
+
v = v?.[part];
|
|
497
|
+
}
|
|
498
|
+
if (typeof v === "function")
|
|
499
|
+
v = v();
|
|
500
|
+
if (typeof v === "number")
|
|
501
|
+
time = v;
|
|
502
|
+
}
|
|
503
|
+
else if (a.useDate) {
|
|
504
|
+
time = Date.now();
|
|
505
|
+
}
|
|
506
|
+
return {
|
|
507
|
+
viewport: { width: innerWidth, height: innerHeight },
|
|
508
|
+
devicePixelRatio,
|
|
509
|
+
reducedMotion: matchMedia("(prefers-reduced-motion: reduce)")
|
|
510
|
+
.matches,
|
|
511
|
+
timeMs: time,
|
|
512
|
+
};
|
|
513
|
+
}, {
|
|
514
|
+
readback: clock.kind === "hook" ? clock.readback : null,
|
|
515
|
+
useDate: clock.kind === "playwright-clock",
|
|
516
|
+
});
|
|
517
|
+
const image = await page.screenshot({
|
|
518
|
+
type: "png",
|
|
519
|
+
...(bp.crop ? { clip: toClip(bp.crop) } : {}),
|
|
520
|
+
animations: "allow",
|
|
521
|
+
});
|
|
522
|
+
let motion;
|
|
523
|
+
if (request.motion) {
|
|
524
|
+
const hashes = [];
|
|
525
|
+
for (let i = 0; i < request.motion.frames; i++) {
|
|
526
|
+
if (i > 0) {
|
|
527
|
+
if (clock.kind === "playwright-clock") {
|
|
528
|
+
await page.clock.runFor(request.motion.intervalMs);
|
|
529
|
+
}
|
|
530
|
+
else {
|
|
531
|
+
await page.waitForTimeout(request.motion.intervalMs);
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
hashes.push(sha(await page.screenshot({
|
|
535
|
+
type: "png",
|
|
536
|
+
...(bp.crop ? { clip: toClip(bp.crop) } : {}),
|
|
537
|
+
animations: "allow",
|
|
538
|
+
})));
|
|
539
|
+
}
|
|
540
|
+
const distinct = new Set(hashes).size;
|
|
541
|
+
motion = {
|
|
542
|
+
frames: hashes.length,
|
|
543
|
+
distinctFrames: distinct,
|
|
544
|
+
changed: distinct > 1,
|
|
545
|
+
frameSha256: hashes,
|
|
546
|
+
};
|
|
547
|
+
}
|
|
548
|
+
return {
|
|
549
|
+
image,
|
|
550
|
+
observed,
|
|
551
|
+
clock: {
|
|
552
|
+
kind: clock.kind,
|
|
553
|
+
requestedTimeMs,
|
|
554
|
+
pinned,
|
|
555
|
+
...(reason ? { reason } : {}),
|
|
556
|
+
},
|
|
557
|
+
...(motion ? { motion } : {}),
|
|
558
|
+
};
|
|
559
|
+
}
|
|
560
|
+
finally {
|
|
561
|
+
await context.close();
|
|
562
|
+
}
|
|
563
|
+
};
|
|
564
|
+
return {
|
|
565
|
+
capture,
|
|
566
|
+
async close() {
|
|
567
|
+
if (!browserPromise)
|
|
568
|
+
return;
|
|
569
|
+
// coercion-ok: a failed launch was already reported by the capture that triggered it
|
|
570
|
+
const browser = await browserPromise.catch(() => null);
|
|
571
|
+
await browser?.close();
|
|
572
|
+
},
|
|
573
|
+
};
|
|
574
|
+
}
|
package/dist/ingestion/pptx.d.ts
CHANGED
package/dist/ingestion/pptx.js
CHANGED
|
@@ -746,7 +746,9 @@ async function parseShapeFragment(fragment, args) {
|
|
|
746
746
|
});
|
|
747
747
|
if (!image)
|
|
748
748
|
return [];
|
|
749
|
-
|
|
749
|
+
const altText = stringValue(readNonVisualProperties(node)?.["@_descr"]);
|
|
750
|
+
const picture = altText ? { ...image.image, altText } : image.image;
|
|
751
|
+
args.images.push(picture);
|
|
750
752
|
return [
|
|
751
753
|
{
|
|
752
754
|
id,
|
|
@@ -756,7 +758,7 @@ async function parseShapeFragment(fragment, args) {
|
|
|
756
758
|
shapeType,
|
|
757
759
|
...(shapeAdjustments ? { shapeAdjustments } : {}),
|
|
758
760
|
...(geometry ? { geometry } : {}),
|
|
759
|
-
image:
|
|
761
|
+
image: picture,
|
|
760
762
|
},
|
|
761
763
|
];
|
|
762
764
|
}
|
package/dist/labs/store.d.ts
CHANGED
|
@@ -12,7 +12,9 @@ export interface UserLabStateError {
|
|
|
12
12
|
error: "invalid-choice" | "legacy-unavailable";
|
|
13
13
|
}
|
|
14
14
|
export type UserLabStateResult = UserLabState | UserLabStateError;
|
|
15
|
-
export declare function getUserLabStates(email: string, scope?: FeatureFlagScope
|
|
15
|
+
export declare function getUserLabStates(email: string, scope?: FeatureFlagScope, options?: {
|
|
16
|
+
propagateTransientErrors?: boolean;
|
|
17
|
+
}): Promise<Record<string, UserLabStateResult>>;
|
|
16
18
|
/**
|
|
17
19
|
* Host hook: when an app runs inside another product (e.g. Builder), the host
|
|
18
20
|
* owns rollout decisions. A host override wins over the user's saved choice
|
package/dist/labs/store.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isTransientDatabaseError } from "../db/errors.js";
|
|
1
2
|
import { defaultFeatureFlagRules, evaluateFeatureFlagRules, normalizeFeatureFlagRules, } from "../feature-flags/store.js";
|
|
2
3
|
import { getOrgSetting } from "../settings/org-settings.js";
|
|
3
4
|
import { getSetting } from "../settings/store.js";
|
|
@@ -56,15 +57,15 @@ async function getLegacyRules(key, scope) {
|
|
|
56
57
|
]);
|
|
57
58
|
return parseLegacyRules(key, org ?? global);
|
|
58
59
|
}
|
|
59
|
-
export async function getUserLabStates(email, scope = {}) {
|
|
60
|
+
export async function getUserLabStates(email, scope = {}, options) {
|
|
60
61
|
const stored = await getStoredLabs(email);
|
|
61
|
-
return resolveStoredLabStates(email, stored, scope);
|
|
62
|
+
return resolveStoredLabStates(email, stored, scope, listLabs(), options);
|
|
62
63
|
}
|
|
63
64
|
let hostLabOverride = null;
|
|
64
65
|
export function registerHostLabOverrides(override) {
|
|
65
66
|
hostLabOverride = override;
|
|
66
67
|
}
|
|
67
|
-
async function resolveStoredLabStates(email, stored, scope, definitions = listLabs()) {
|
|
68
|
+
async function resolveStoredLabStates(email, stored, scope, definitions = listLabs(), options) {
|
|
68
69
|
const invalidChoices = new Set(definitions
|
|
69
70
|
.filter(({ key }) => stored &&
|
|
70
71
|
Object.hasOwn(stored, key) &&
|
|
@@ -81,7 +82,10 @@ async function resolveStoredLabStates(email, stored, scope, definitions = listLa
|
|
|
81
82
|
try {
|
|
82
83
|
return [key, await getLegacyRules(key, evaluationScope)];
|
|
83
84
|
}
|
|
84
|
-
catch {
|
|
85
|
+
catch (error) {
|
|
86
|
+
if (options?.propagateTransientErrors &&
|
|
87
|
+
isTransientDatabaseError(error, { source: "database" }))
|
|
88
|
+
throw error;
|
|
85
89
|
return [key, null];
|
|
86
90
|
}
|
|
87
91
|
})));
|