@weatherboard/annotation 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/ADOPTING.md +360 -0
- package/LICENSE +21 -0
- package/README.md +109 -0
- package/dist/host.cjs +2 -0
- package/dist/host.cjs.map +7 -0
- package/dist/host.d.cts +60 -0
- package/dist/host.d.mts +60 -0
- package/dist/host.d.ts +60 -0
- package/dist/host.mjs +2 -0
- package/dist/host.mjs.map +7 -0
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +7 -0
- package/dist/index.d.cts +34 -0
- package/dist/index.d.mts +34 -0
- package/dist/index.d.ts +34 -0
- package/dist/index.mjs +2 -0
- package/dist/index.mjs.map +7 -0
- package/dist/overlay.d.cts +31 -0
- package/dist/overlay.d.mts +31 -0
- package/dist/overlay.d.ts +31 -0
- package/dist/protocol.cjs +2 -0
- package/dist/protocol.cjs.map +7 -0
- package/dist/protocol.d.cts +309 -0
- package/dist/protocol.d.mts +309 -0
- package/dist/protocol.d.ts +309 -0
- package/dist/protocol.mjs +2 -0
- package/dist/protocol.mjs.map +7 -0
- package/dist/screenshot.d.cts +182 -0
- package/dist/screenshot.d.mts +182 -0
- package/dist/screenshot.d.ts +182 -0
- package/dist/sdk.d.cts +52 -0
- package/dist/sdk.d.mts +52 -0
- package/dist/sdk.d.ts +52 -0
- package/dist/state.d.cts +62 -0
- package/dist/state.d.mts +62 -0
- package/dist/state.d.ts +62 -0
- package/dist/target.d.cts +74 -0
- package/dist/target.d.mts +74 -0
- package/dist/target.d.ts +74 -0
- package/package.json +94 -0
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The annotation postMessage protocol (A-36).
|
|
3
|
+
*
|
|
4
|
+
* Mirrors `docs/contracts/types.ts`. That file is the
|
|
5
|
+
* cross-component contract; this is the runtime copy the product bundle ships,
|
|
6
|
+
* because the product cannot import from a docs directory. Changing a shape
|
|
7
|
+
* here is a change to both — say so in the PR.
|
|
8
|
+
*/
|
|
9
|
+
export declare const SDK_VERSION = "1";
|
|
10
|
+
/**
|
|
11
|
+
* ===========================================================================
|
|
12
|
+
* THE ATTRIBUTES — THE OTHER WIRE (A-186)
|
|
13
|
+
* ===========================================================================
|
|
14
|
+
*
|
|
15
|
+
* These live in `protocol.ts`, not in `target.ts` where they are read, because
|
|
16
|
+
* they are a contract between TWO PACKAGES that a consumer installs separately:
|
|
17
|
+
* `@weatherboard/annotation-next` WRITES them at build time and this package
|
|
18
|
+
* READS them at runtime. Two spellings of `data-src` is not a bug anybody
|
|
19
|
+
* catches — the transform runs, the attributes appear, and every capture comes
|
|
20
|
+
* back with no source ref at all, which is indistinguishable from the transform
|
|
21
|
+
* not running.
|
|
22
|
+
*
|
|
23
|
+
* `annotation-next` imports these from `@weatherboard/annotation/protocol`
|
|
24
|
+
* rather than declaring its own, which is why the subpath has no DOM in it: a
|
|
25
|
+
* build tool importing the page SDK to learn two strings would be absurd.
|
|
26
|
+
*/
|
|
27
|
+
export declare const SRC_ATTR = "data-src";
|
|
28
|
+
export declare const NAME_ATTR = "data-src-name";
|
|
29
|
+
export interface SourceRef {
|
|
30
|
+
file: string;
|
|
31
|
+
line: number;
|
|
32
|
+
column?: number;
|
|
33
|
+
}
|
|
34
|
+
export interface BuildInfo {
|
|
35
|
+
/** Mandatory. Feedback not pinned to a revision is ambiguous the moment someone merges. */
|
|
36
|
+
gitSha: string;
|
|
37
|
+
/**
|
|
38
|
+
* Where this build came from.
|
|
39
|
+
*
|
|
40
|
+
* `"development"` was added in A-37, when the SDK was first mounted in a
|
|
41
|
+
* real app and the two halves turned out not to agree: `resolveBuildInfo` in
|
|
42
|
+
* `resolveBuildInfo` in the product's own Next config package — the module
|
|
43
|
+
* that stamps the build-env variable, and the only producer of this field —
|
|
44
|
+
* emits
|
|
45
|
+
* `production | preview | development`, mirroring `VERCEL_ENV`. This union
|
|
46
|
+
* instead offered `"staging"`, which nothing produces: a staging deploy IS a
|
|
47
|
+
* Vercel preview and reports itself as one. Widening rather than forcing the
|
|
48
|
+
* mount to lie: a locally-annotated build calling itself a preview would put
|
|
49
|
+
* someone's laptop in the corpus as though it were a deployment.
|
|
50
|
+
*/
|
|
51
|
+
env: "production" | "preview" | "staging" | "development";
|
|
52
|
+
branch?: string;
|
|
53
|
+
/** Set when reviewing an agent's preview deploy, so feedback routes to that run's session. */
|
|
54
|
+
previewRunId?: string;
|
|
55
|
+
}
|
|
56
|
+
export interface ConsoleEntry {
|
|
57
|
+
level: "error" | "warn";
|
|
58
|
+
message: string;
|
|
59
|
+
stack?: string;
|
|
60
|
+
at: string;
|
|
61
|
+
}
|
|
62
|
+
export interface NetworkEntry {
|
|
63
|
+
url: string;
|
|
64
|
+
method: string;
|
|
65
|
+
status: number;
|
|
66
|
+
at: string;
|
|
67
|
+
}
|
|
68
|
+
export interface TargetInfo {
|
|
69
|
+
/**
|
|
70
|
+
* What the reviewer selected — one element, or an area (A-179).
|
|
71
|
+
*
|
|
72
|
+
* -------------------------------------------------------------------------
|
|
73
|
+
* WHY THIS EXISTS RATHER THAN BEING INFERRED
|
|
74
|
+
* -------------------------------------------------------------------------
|
|
75
|
+
*
|
|
76
|
+
* A region capture and an element capture are the same SHAPE: a bounding box,
|
|
77
|
+
* a chain of source refs, a DOM path. Nothing in the values distinguishes
|
|
78
|
+
* them, and the two mean opposite things about the chain — for an element it
|
|
79
|
+
* is ANCESTORS, innermost first, so entry two contains entry one; for a
|
|
80
|
+
* region it is SIBLINGS the rectangle happened to cross, which contain
|
|
81
|
+
* nothing of each other.
|
|
82
|
+
*
|
|
83
|
+
* A reader that guesses will describe a region's siblings as a call-site
|
|
84
|
+
* chain, which is a confident false statement about the page. `describeCapture`
|
|
85
|
+
* hands that description to a model that writes acceptance criteria from it.
|
|
86
|
+
*
|
|
87
|
+
* -------------------------------------------------------------------------
|
|
88
|
+
* WHY IT IS OPTIONAL, AND WHY ABSENT MEANS `element`
|
|
89
|
+
* -------------------------------------------------------------------------
|
|
90
|
+
*
|
|
91
|
+
* The two halves of this protocol live in different repositories and deploy
|
|
92
|
+
* independently (see the note on the legacy parameter names below). Every
|
|
93
|
+
* capture in the store today, and every capture from a product bundle that
|
|
94
|
+
* predates region selection, has no such field — and all of them are element
|
|
95
|
+
* captures. Absent therefore has to mean `element`, or this field would
|
|
96
|
+
* retroactively make the entire history ambiguous.
|
|
97
|
+
*
|
|
98
|
+
* Required-with-a-default would have the same effect and a worse failure: an
|
|
99
|
+
* older bundle omits it, the type says it is there, and every reader believes
|
|
100
|
+
* a value nobody sent.
|
|
101
|
+
*/
|
|
102
|
+
selection?: "element" | "region";
|
|
103
|
+
source?: SourceRef;
|
|
104
|
+
/**
|
|
105
|
+
* Every `data-src` from the clicked element up to the document root, innermost
|
|
106
|
+
* first — an addition to the contract, and the reason is structural.
|
|
107
|
+
*
|
|
108
|
+
* Only host elements carry a ref (A-33), so `source` names the file that
|
|
109
|
+
* *writes the markup*. For a composed design-system component that is
|
|
110
|
+
* `MediaCard.tsx`, not the `GuideDetailCard.tsx` a human would say they
|
|
111
|
+
* clicked. The chain is what lets the PM agent and the coding agent see both,
|
|
112
|
+
* and pick the call site over the leaf when the feedback is about content
|
|
113
|
+
* rather than the component itself.
|
|
114
|
+
*/
|
|
115
|
+
sourceChain?: SourceRef[];
|
|
116
|
+
componentName?: string;
|
|
117
|
+
/** CSS selector fallback, for when no ancestor carries a ref at all. */
|
|
118
|
+
domPath: string;
|
|
119
|
+
boundingBox: {
|
|
120
|
+
x: number;
|
|
121
|
+
y: number;
|
|
122
|
+
w: number;
|
|
123
|
+
h: number;
|
|
124
|
+
};
|
|
125
|
+
/** Truncated to 200 characters. */
|
|
126
|
+
textContent?: string;
|
|
127
|
+
}
|
|
128
|
+
export interface AnnotationPayload {
|
|
129
|
+
schemaVersion: 1;
|
|
130
|
+
capturedAt: string;
|
|
131
|
+
build: BuildInfo;
|
|
132
|
+
page: {
|
|
133
|
+
url: string;
|
|
134
|
+
/** The matched route pattern, not the resolved URL. */
|
|
135
|
+
route: string;
|
|
136
|
+
viewport: {
|
|
137
|
+
w: number;
|
|
138
|
+
h: number;
|
|
139
|
+
dpr: number;
|
|
140
|
+
};
|
|
141
|
+
userAgent: string;
|
|
142
|
+
};
|
|
143
|
+
target: TargetInfo;
|
|
144
|
+
state: {
|
|
145
|
+
consoleErrors: ConsoleEntry[];
|
|
146
|
+
failedRequests: NetworkEntry[];
|
|
147
|
+
featureFlags: Record<string, unknown>;
|
|
148
|
+
};
|
|
149
|
+
screenshot?: {
|
|
150
|
+
dataUrl: string;
|
|
151
|
+
region: "element" | "viewport";
|
|
152
|
+
};
|
|
153
|
+
/** The human's words, verbatim. The parent frame fills this in; we never rewrite it. */
|
|
154
|
+
comment: string;
|
|
155
|
+
}
|
|
156
|
+
export type ParentToFrame = {
|
|
157
|
+
type: "annotate:enable";
|
|
158
|
+
} | {
|
|
159
|
+
type: "annotate:disable";
|
|
160
|
+
} | {
|
|
161
|
+
type: "annotate:ping";
|
|
162
|
+
};
|
|
163
|
+
export type FrameToParent = {
|
|
164
|
+
type: "annotate:ready";
|
|
165
|
+
sdkVersion: string;
|
|
166
|
+
build: BuildInfo;
|
|
167
|
+
} | {
|
|
168
|
+
type: "annotate:hover";
|
|
169
|
+
target: TargetInfo;
|
|
170
|
+
} | {
|
|
171
|
+
type: "annotate:capture";
|
|
172
|
+
payload: AnnotationPayload;
|
|
173
|
+
} | {
|
|
174
|
+
type: "annotate:cancel";
|
|
175
|
+
};
|
|
176
|
+
/**
|
|
177
|
+
* Is this a message we recognise?
|
|
178
|
+
*
|
|
179
|
+
* Origin is checked separately and first — a well-formed message from the wrong
|
|
180
|
+
* origin is the case this guard must not be trusted to catch.
|
|
181
|
+
*/
|
|
182
|
+
export declare function isParentMessage(data: unknown): data is ParentToFrame;
|
|
183
|
+
/**
|
|
184
|
+
* Reject wildcards outright rather than treating them as "any origin".
|
|
185
|
+
*
|
|
186
|
+
* `postMessage(msg, "*")` broadcasts the payload to whatever happens to be
|
|
187
|
+
* framing us, and an annotation payload carries page content, console errors and
|
|
188
|
+
* failed request URLs. The spec's rule is no wildcards in either direction; this
|
|
189
|
+
* makes it impossible to configure one by accident.
|
|
190
|
+
*/
|
|
191
|
+
export declare function assertConcreteOrigin(origin: string): string;
|
|
192
|
+
/**
|
|
193
|
+
* The query parameter that arms the SDK in a managed product, and the cookie
|
|
194
|
+
* that records it.
|
|
195
|
+
*
|
|
196
|
+
* THESE LIVE IN THE PROTOCOL BECAUSE THE TWO HALVES ARE NOW IN DIFFERENT
|
|
197
|
+
* REPOSITORIES. The managed product's middleware looks for the parameter and
|
|
198
|
+
* sets the cookie; the management app appends the parameter and the SDK reads
|
|
199
|
+
* the cookie. While both halves were one monorepo, a test could read the other
|
|
200
|
+
* side's source and assert the strings matched — that gate does not survive a
|
|
201
|
+
* repository split, and a mismatch produces no error at all: the frame loads,
|
|
202
|
+
* the cookie is never set, the SDK never boots, and the reviewer sees "waiting
|
|
203
|
+
* for the page to announce itself" with nothing to go on.
|
|
204
|
+
*
|
|
205
|
+
* So they stop being two spellings that agree and become one exported
|
|
206
|
+
* constant. A managed product that imports this package cannot drift from it.
|
|
207
|
+
*/
|
|
208
|
+
export declare const ANNOTATION_TOKEN_PARAM = "ai_annotate";
|
|
209
|
+
export declare const ANNOTATION_ARMED_COOKIE = "ai_annotate_armed";
|
|
210
|
+
/**
|
|
211
|
+
* The names these used to have (A-98).
|
|
212
|
+
*
|
|
213
|
+
* -------------------------------------------------------------------------
|
|
214
|
+
* WHY THE RENAME, AND WHY IT COULD NOT JUST BE DONE
|
|
215
|
+
* -------------------------------------------------------------------------
|
|
216
|
+
*
|
|
217
|
+
* They were `pits_annotate` and `pits_annotate_armed` — one managed product's
|
|
218
|
+
* initialism, in a contract every managed product's bundle has to implement.
|
|
219
|
+
* Onboarding a second product meant asking an unrelated codebase to adopt the
|
|
220
|
+
* first product's name in its cookies and its query strings. That is the bug
|
|
221
|
+
* A-98 is about, and it is a bug in a wire protocol rather than in a variable
|
|
222
|
+
* name, which is what makes it expensive.
|
|
223
|
+
*
|
|
224
|
+
* The two halves live in DIFFERENT REPOSITORIES and deploy independently. A
|
|
225
|
+
* clean rename is therefore a breaking change to every product bundle
|
|
226
|
+
* simultaneously, and its failure mode is silence: the frame loads, the cookie
|
|
227
|
+
* is never set, the SDK never boots, and the reviewer sees "waiting for the
|
|
228
|
+
* page to announce itself" with nothing to go on. Nothing throws, nothing logs,
|
|
229
|
+
* and the natural reading is that the agent broke the site.
|
|
230
|
+
*
|
|
231
|
+
* -------------------------------------------------------------------------
|
|
232
|
+
* THE MIGRATION: READ BOTH, WRITE BOTH, THEN STOP WRITING THE OLD ONE
|
|
233
|
+
* -------------------------------------------------------------------------
|
|
234
|
+
*
|
|
235
|
+
* 1. **Now.** Every reader accepts either name. Every writer emits BOTH, so a
|
|
236
|
+
* product still running the old bundle arms on the legacy name and one
|
|
237
|
+
* running the new bundle arms on the new one. Deploy order stops mattering,
|
|
238
|
+
* which is the whole point — there is no window in which a reviewer sees the
|
|
239
|
+
* silent failure above.
|
|
240
|
+
* 2. **After every managed product's bundle is on this version** (A-102). Drop
|
|
241
|
+
* the legacy names from the writers, then from the readers. Two steps, not
|
|
242
|
+
* one: a reader that stops accepting the old name before the writers stop
|
|
243
|
+
* emitting it re-creates the outage in the other direction.
|
|
244
|
+
*
|
|
245
|
+
* The legacy names are exported rather than inlined so the deletion in step 2
|
|
246
|
+
* is `git grep LEGACY_` rather than an archaeology exercise.
|
|
247
|
+
*/
|
|
248
|
+
export declare const LEGACY_ANNOTATION_TOKEN_PARAM = "pits_annotate";
|
|
249
|
+
export declare const LEGACY_ANNOTATION_ARMED_COOKIE = "pits_annotate_armed";
|
|
250
|
+
/**
|
|
251
|
+
* ===========================================================================
|
|
252
|
+
* AND THE NAMES ARE NOT CHANGING AGAIN FOR THE PUBLISHED PACKAGE (A-184)
|
|
253
|
+
* ===========================================================================
|
|
254
|
+
*
|
|
255
|
+
* When this becomes `@weatherboard/annotation` the obvious next thought is that
|
|
256
|
+
* the wire names should match the package — `weatherboard_annotate`. They
|
|
257
|
+
* should not, and the reason is the migration described above rather than
|
|
258
|
+
* taste.
|
|
259
|
+
*
|
|
260
|
+
* That migration is STILL IN FLIGHT. Readers accept both spellings; writers
|
|
261
|
+
* emit both; step 2 waits on every managed product's bundle being current.
|
|
262
|
+
* A third spelling introduced now does not replace the second, it joins it:
|
|
263
|
+
* every reader accepts three names, every writer emits three, and the window in
|
|
264
|
+
* which a product can be on any of them widens instead of closing.
|
|
265
|
+
*
|
|
266
|
+
* The cost is not the code. It is that each rename buys another instance of the
|
|
267
|
+
* failure this file exists to prevent — the frame loads, the cookie is never
|
|
268
|
+
* set, the SDK never boots, and the reviewer sees "waiting for the page to
|
|
269
|
+
* announce itself" with nothing to go on. Twice is a migration. Three times is
|
|
270
|
+
* a habit, and the third one would be paid by consumers who never asked for
|
|
271
|
+
* either.
|
|
272
|
+
*
|
|
273
|
+
* `ai_annotate` is already product-neutral, which was the entire point of A-98.
|
|
274
|
+
* A published package needs names that name no product; it does not need names
|
|
275
|
+
* that name the package. Nobody reading a query string cares which npm scope
|
|
276
|
+
* the library came from.
|
|
277
|
+
*
|
|
278
|
+
* The one real objection is collision: `ai_` is a common prefix and some other
|
|
279
|
+
* tool could plausibly use it. That is survivable by construction — arming
|
|
280
|
+
* requires the parameter to carry a token the product compares exactly, so a
|
|
281
|
+
* coincidental `?ai_annotate=` from an unrelated tool arms nothing. A colliding
|
|
282
|
+
* COOKIE cannot false-positive either; `isAnnotationArmed` matches on the
|
|
283
|
+
* delimiter rather than by substring, for exactly this reason.
|
|
284
|
+
*
|
|
285
|
+
* If a rename is ever genuinely warranted, it happens ONCE, after step 2 has
|
|
286
|
+
* landed and the reader accepts one name again — not layered on top of an
|
|
287
|
+
* unfinished one.
|
|
288
|
+
*/
|
|
289
|
+
/** Both spellings of the query parameter, current first. */
|
|
290
|
+
export declare const ANNOTATION_TOKEN_PARAMS: readonly ["ai_annotate", "pits_annotate"];
|
|
291
|
+
/** Both spellings of the cookie, current first. */
|
|
292
|
+
export declare const ANNOTATION_ARMED_COOKIES: readonly ["ai_annotate_armed", "pits_annotate_armed"];
|
|
293
|
+
/**
|
|
294
|
+
* Whether a cookie jar carries the armed cookie, under either name.
|
|
295
|
+
*
|
|
296
|
+
* Delimiter-aware rather than a substring test: a cookie named
|
|
297
|
+
* `not_ai_annotate_armed`, or another cookie whose VALUE contains the name,
|
|
298
|
+
* satisfies `includes` — and arming an annotation channel on a coincidence is
|
|
299
|
+
* not a failure anyone would think to look for.
|
|
300
|
+
*/
|
|
301
|
+
export declare function isAnnotationArmed(cookie: string): boolean;
|
|
302
|
+
/**
|
|
303
|
+
* The arming token from a URL's query string, under either name.
|
|
304
|
+
*
|
|
305
|
+
* Current name wins when both are present. They should never disagree — the
|
|
306
|
+
* management app writes both from one value — but if they ever do, the one this
|
|
307
|
+
* version of the protocol owns is the one to believe.
|
|
308
|
+
*/
|
|
309
|
+
export declare function readAnnotationToken(params: URLSearchParams): string | null;
|
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The annotation postMessage protocol (A-36).
|
|
3
|
+
*
|
|
4
|
+
* Mirrors `docs/contracts/types.ts`. That file is the
|
|
5
|
+
* cross-component contract; this is the runtime copy the product bundle ships,
|
|
6
|
+
* because the product cannot import from a docs directory. Changing a shape
|
|
7
|
+
* here is a change to both — say so in the PR.
|
|
8
|
+
*/
|
|
9
|
+
export declare const SDK_VERSION = "1";
|
|
10
|
+
/**
|
|
11
|
+
* ===========================================================================
|
|
12
|
+
* THE ATTRIBUTES — THE OTHER WIRE (A-186)
|
|
13
|
+
* ===========================================================================
|
|
14
|
+
*
|
|
15
|
+
* These live in `protocol.ts`, not in `target.ts` where they are read, because
|
|
16
|
+
* they are a contract between TWO PACKAGES that a consumer installs separately:
|
|
17
|
+
* `@weatherboard/annotation-next` WRITES them at build time and this package
|
|
18
|
+
* READS them at runtime. Two spellings of `data-src` is not a bug anybody
|
|
19
|
+
* catches — the transform runs, the attributes appear, and every capture comes
|
|
20
|
+
* back with no source ref at all, which is indistinguishable from the transform
|
|
21
|
+
* not running.
|
|
22
|
+
*
|
|
23
|
+
* `annotation-next` imports these from `@weatherboard/annotation/protocol`
|
|
24
|
+
* rather than declaring its own, which is why the subpath has no DOM in it: a
|
|
25
|
+
* build tool importing the page SDK to learn two strings would be absurd.
|
|
26
|
+
*/
|
|
27
|
+
export declare const SRC_ATTR = "data-src";
|
|
28
|
+
export declare const NAME_ATTR = "data-src-name";
|
|
29
|
+
export interface SourceRef {
|
|
30
|
+
file: string;
|
|
31
|
+
line: number;
|
|
32
|
+
column?: number;
|
|
33
|
+
}
|
|
34
|
+
export interface BuildInfo {
|
|
35
|
+
/** Mandatory. Feedback not pinned to a revision is ambiguous the moment someone merges. */
|
|
36
|
+
gitSha: string;
|
|
37
|
+
/**
|
|
38
|
+
* Where this build came from.
|
|
39
|
+
*
|
|
40
|
+
* `"development"` was added in A-37, when the SDK was first mounted in a
|
|
41
|
+
* real app and the two halves turned out not to agree: `resolveBuildInfo` in
|
|
42
|
+
* `resolveBuildInfo` in the product's own Next config package — the module
|
|
43
|
+
* that stamps the build-env variable, and the only producer of this field —
|
|
44
|
+
* emits
|
|
45
|
+
* `production | preview | development`, mirroring `VERCEL_ENV`. This union
|
|
46
|
+
* instead offered `"staging"`, which nothing produces: a staging deploy IS a
|
|
47
|
+
* Vercel preview and reports itself as one. Widening rather than forcing the
|
|
48
|
+
* mount to lie: a locally-annotated build calling itself a preview would put
|
|
49
|
+
* someone's laptop in the corpus as though it were a deployment.
|
|
50
|
+
*/
|
|
51
|
+
env: "production" | "preview" | "staging" | "development";
|
|
52
|
+
branch?: string;
|
|
53
|
+
/** Set when reviewing an agent's preview deploy, so feedback routes to that run's session. */
|
|
54
|
+
previewRunId?: string;
|
|
55
|
+
}
|
|
56
|
+
export interface ConsoleEntry {
|
|
57
|
+
level: "error" | "warn";
|
|
58
|
+
message: string;
|
|
59
|
+
stack?: string;
|
|
60
|
+
at: string;
|
|
61
|
+
}
|
|
62
|
+
export interface NetworkEntry {
|
|
63
|
+
url: string;
|
|
64
|
+
method: string;
|
|
65
|
+
status: number;
|
|
66
|
+
at: string;
|
|
67
|
+
}
|
|
68
|
+
export interface TargetInfo {
|
|
69
|
+
/**
|
|
70
|
+
* What the reviewer selected — one element, or an area (A-179).
|
|
71
|
+
*
|
|
72
|
+
* -------------------------------------------------------------------------
|
|
73
|
+
* WHY THIS EXISTS RATHER THAN BEING INFERRED
|
|
74
|
+
* -------------------------------------------------------------------------
|
|
75
|
+
*
|
|
76
|
+
* A region capture and an element capture are the same SHAPE: a bounding box,
|
|
77
|
+
* a chain of source refs, a DOM path. Nothing in the values distinguishes
|
|
78
|
+
* them, and the two mean opposite things about the chain — for an element it
|
|
79
|
+
* is ANCESTORS, innermost first, so entry two contains entry one; for a
|
|
80
|
+
* region it is SIBLINGS the rectangle happened to cross, which contain
|
|
81
|
+
* nothing of each other.
|
|
82
|
+
*
|
|
83
|
+
* A reader that guesses will describe a region's siblings as a call-site
|
|
84
|
+
* chain, which is a confident false statement about the page. `describeCapture`
|
|
85
|
+
* hands that description to a model that writes acceptance criteria from it.
|
|
86
|
+
*
|
|
87
|
+
* -------------------------------------------------------------------------
|
|
88
|
+
* WHY IT IS OPTIONAL, AND WHY ABSENT MEANS `element`
|
|
89
|
+
* -------------------------------------------------------------------------
|
|
90
|
+
*
|
|
91
|
+
* The two halves of this protocol live in different repositories and deploy
|
|
92
|
+
* independently (see the note on the legacy parameter names below). Every
|
|
93
|
+
* capture in the store today, and every capture from a product bundle that
|
|
94
|
+
* predates region selection, has no such field — and all of them are element
|
|
95
|
+
* captures. Absent therefore has to mean `element`, or this field would
|
|
96
|
+
* retroactively make the entire history ambiguous.
|
|
97
|
+
*
|
|
98
|
+
* Required-with-a-default would have the same effect and a worse failure: an
|
|
99
|
+
* older bundle omits it, the type says it is there, and every reader believes
|
|
100
|
+
* a value nobody sent.
|
|
101
|
+
*/
|
|
102
|
+
selection?: "element" | "region";
|
|
103
|
+
source?: SourceRef;
|
|
104
|
+
/**
|
|
105
|
+
* Every `data-src` from the clicked element up to the document root, innermost
|
|
106
|
+
* first — an addition to the contract, and the reason is structural.
|
|
107
|
+
*
|
|
108
|
+
* Only host elements carry a ref (A-33), so `source` names the file that
|
|
109
|
+
* *writes the markup*. For a composed design-system component that is
|
|
110
|
+
* `MediaCard.tsx`, not the `GuideDetailCard.tsx` a human would say they
|
|
111
|
+
* clicked. The chain is what lets the PM agent and the coding agent see both,
|
|
112
|
+
* and pick the call site over the leaf when the feedback is about content
|
|
113
|
+
* rather than the component itself.
|
|
114
|
+
*/
|
|
115
|
+
sourceChain?: SourceRef[];
|
|
116
|
+
componentName?: string;
|
|
117
|
+
/** CSS selector fallback, for when no ancestor carries a ref at all. */
|
|
118
|
+
domPath: string;
|
|
119
|
+
boundingBox: {
|
|
120
|
+
x: number;
|
|
121
|
+
y: number;
|
|
122
|
+
w: number;
|
|
123
|
+
h: number;
|
|
124
|
+
};
|
|
125
|
+
/** Truncated to 200 characters. */
|
|
126
|
+
textContent?: string;
|
|
127
|
+
}
|
|
128
|
+
export interface AnnotationPayload {
|
|
129
|
+
schemaVersion: 1;
|
|
130
|
+
capturedAt: string;
|
|
131
|
+
build: BuildInfo;
|
|
132
|
+
page: {
|
|
133
|
+
url: string;
|
|
134
|
+
/** The matched route pattern, not the resolved URL. */
|
|
135
|
+
route: string;
|
|
136
|
+
viewport: {
|
|
137
|
+
w: number;
|
|
138
|
+
h: number;
|
|
139
|
+
dpr: number;
|
|
140
|
+
};
|
|
141
|
+
userAgent: string;
|
|
142
|
+
};
|
|
143
|
+
target: TargetInfo;
|
|
144
|
+
state: {
|
|
145
|
+
consoleErrors: ConsoleEntry[];
|
|
146
|
+
failedRequests: NetworkEntry[];
|
|
147
|
+
featureFlags: Record<string, unknown>;
|
|
148
|
+
};
|
|
149
|
+
screenshot?: {
|
|
150
|
+
dataUrl: string;
|
|
151
|
+
region: "element" | "viewport";
|
|
152
|
+
};
|
|
153
|
+
/** The human's words, verbatim. The parent frame fills this in; we never rewrite it. */
|
|
154
|
+
comment: string;
|
|
155
|
+
}
|
|
156
|
+
export type ParentToFrame = {
|
|
157
|
+
type: "annotate:enable";
|
|
158
|
+
} | {
|
|
159
|
+
type: "annotate:disable";
|
|
160
|
+
} | {
|
|
161
|
+
type: "annotate:ping";
|
|
162
|
+
};
|
|
163
|
+
export type FrameToParent = {
|
|
164
|
+
type: "annotate:ready";
|
|
165
|
+
sdkVersion: string;
|
|
166
|
+
build: BuildInfo;
|
|
167
|
+
} | {
|
|
168
|
+
type: "annotate:hover";
|
|
169
|
+
target: TargetInfo;
|
|
170
|
+
} | {
|
|
171
|
+
type: "annotate:capture";
|
|
172
|
+
payload: AnnotationPayload;
|
|
173
|
+
} | {
|
|
174
|
+
type: "annotate:cancel";
|
|
175
|
+
};
|
|
176
|
+
/**
|
|
177
|
+
* Is this a message we recognise?
|
|
178
|
+
*
|
|
179
|
+
* Origin is checked separately and first — a well-formed message from the wrong
|
|
180
|
+
* origin is the case this guard must not be trusted to catch.
|
|
181
|
+
*/
|
|
182
|
+
export declare function isParentMessage(data: unknown): data is ParentToFrame;
|
|
183
|
+
/**
|
|
184
|
+
* Reject wildcards outright rather than treating them as "any origin".
|
|
185
|
+
*
|
|
186
|
+
* `postMessage(msg, "*")` broadcasts the payload to whatever happens to be
|
|
187
|
+
* framing us, and an annotation payload carries page content, console errors and
|
|
188
|
+
* failed request URLs. The spec's rule is no wildcards in either direction; this
|
|
189
|
+
* makes it impossible to configure one by accident.
|
|
190
|
+
*/
|
|
191
|
+
export declare function assertConcreteOrigin(origin: string): string;
|
|
192
|
+
/**
|
|
193
|
+
* The query parameter that arms the SDK in a managed product, and the cookie
|
|
194
|
+
* that records it.
|
|
195
|
+
*
|
|
196
|
+
* THESE LIVE IN THE PROTOCOL BECAUSE THE TWO HALVES ARE NOW IN DIFFERENT
|
|
197
|
+
* REPOSITORIES. The managed product's middleware looks for the parameter and
|
|
198
|
+
* sets the cookie; the management app appends the parameter and the SDK reads
|
|
199
|
+
* the cookie. While both halves were one monorepo, a test could read the other
|
|
200
|
+
* side's source and assert the strings matched — that gate does not survive a
|
|
201
|
+
* repository split, and a mismatch produces no error at all: the frame loads,
|
|
202
|
+
* the cookie is never set, the SDK never boots, and the reviewer sees "waiting
|
|
203
|
+
* for the page to announce itself" with nothing to go on.
|
|
204
|
+
*
|
|
205
|
+
* So they stop being two spellings that agree and become one exported
|
|
206
|
+
* constant. A managed product that imports this package cannot drift from it.
|
|
207
|
+
*/
|
|
208
|
+
export declare const ANNOTATION_TOKEN_PARAM = "ai_annotate";
|
|
209
|
+
export declare const ANNOTATION_ARMED_COOKIE = "ai_annotate_armed";
|
|
210
|
+
/**
|
|
211
|
+
* The names these used to have (A-98).
|
|
212
|
+
*
|
|
213
|
+
* -------------------------------------------------------------------------
|
|
214
|
+
* WHY THE RENAME, AND WHY IT COULD NOT JUST BE DONE
|
|
215
|
+
* -------------------------------------------------------------------------
|
|
216
|
+
*
|
|
217
|
+
* They were `pits_annotate` and `pits_annotate_armed` — one managed product's
|
|
218
|
+
* initialism, in a contract every managed product's bundle has to implement.
|
|
219
|
+
* Onboarding a second product meant asking an unrelated codebase to adopt the
|
|
220
|
+
* first product's name in its cookies and its query strings. That is the bug
|
|
221
|
+
* A-98 is about, and it is a bug in a wire protocol rather than in a variable
|
|
222
|
+
* name, which is what makes it expensive.
|
|
223
|
+
*
|
|
224
|
+
* The two halves live in DIFFERENT REPOSITORIES and deploy independently. A
|
|
225
|
+
* clean rename is therefore a breaking change to every product bundle
|
|
226
|
+
* simultaneously, and its failure mode is silence: the frame loads, the cookie
|
|
227
|
+
* is never set, the SDK never boots, and the reviewer sees "waiting for the
|
|
228
|
+
* page to announce itself" with nothing to go on. Nothing throws, nothing logs,
|
|
229
|
+
* and the natural reading is that the agent broke the site.
|
|
230
|
+
*
|
|
231
|
+
* -------------------------------------------------------------------------
|
|
232
|
+
* THE MIGRATION: READ BOTH, WRITE BOTH, THEN STOP WRITING THE OLD ONE
|
|
233
|
+
* -------------------------------------------------------------------------
|
|
234
|
+
*
|
|
235
|
+
* 1. **Now.** Every reader accepts either name. Every writer emits BOTH, so a
|
|
236
|
+
* product still running the old bundle arms on the legacy name and one
|
|
237
|
+
* running the new bundle arms on the new one. Deploy order stops mattering,
|
|
238
|
+
* which is the whole point — there is no window in which a reviewer sees the
|
|
239
|
+
* silent failure above.
|
|
240
|
+
* 2. **After every managed product's bundle is on this version** (A-102). Drop
|
|
241
|
+
* the legacy names from the writers, then from the readers. Two steps, not
|
|
242
|
+
* one: a reader that stops accepting the old name before the writers stop
|
|
243
|
+
* emitting it re-creates the outage in the other direction.
|
|
244
|
+
*
|
|
245
|
+
* The legacy names are exported rather than inlined so the deletion in step 2
|
|
246
|
+
* is `git grep LEGACY_` rather than an archaeology exercise.
|
|
247
|
+
*/
|
|
248
|
+
export declare const LEGACY_ANNOTATION_TOKEN_PARAM = "pits_annotate";
|
|
249
|
+
export declare const LEGACY_ANNOTATION_ARMED_COOKIE = "pits_annotate_armed";
|
|
250
|
+
/**
|
|
251
|
+
* ===========================================================================
|
|
252
|
+
* AND THE NAMES ARE NOT CHANGING AGAIN FOR THE PUBLISHED PACKAGE (A-184)
|
|
253
|
+
* ===========================================================================
|
|
254
|
+
*
|
|
255
|
+
* When this becomes `@weatherboard/annotation` the obvious next thought is that
|
|
256
|
+
* the wire names should match the package — `weatherboard_annotate`. They
|
|
257
|
+
* should not, and the reason is the migration described above rather than
|
|
258
|
+
* taste.
|
|
259
|
+
*
|
|
260
|
+
* That migration is STILL IN FLIGHT. Readers accept both spellings; writers
|
|
261
|
+
* emit both; step 2 waits on every managed product's bundle being current.
|
|
262
|
+
* A third spelling introduced now does not replace the second, it joins it:
|
|
263
|
+
* every reader accepts three names, every writer emits three, and the window in
|
|
264
|
+
* which a product can be on any of them widens instead of closing.
|
|
265
|
+
*
|
|
266
|
+
* The cost is not the code. It is that each rename buys another instance of the
|
|
267
|
+
* failure this file exists to prevent — the frame loads, the cookie is never
|
|
268
|
+
* set, the SDK never boots, and the reviewer sees "waiting for the page to
|
|
269
|
+
* announce itself" with nothing to go on. Twice is a migration. Three times is
|
|
270
|
+
* a habit, and the third one would be paid by consumers who never asked for
|
|
271
|
+
* either.
|
|
272
|
+
*
|
|
273
|
+
* `ai_annotate` is already product-neutral, which was the entire point of A-98.
|
|
274
|
+
* A published package needs names that name no product; it does not need names
|
|
275
|
+
* that name the package. Nobody reading a query string cares which npm scope
|
|
276
|
+
* the library came from.
|
|
277
|
+
*
|
|
278
|
+
* The one real objection is collision: `ai_` is a common prefix and some other
|
|
279
|
+
* tool could plausibly use it. That is survivable by construction — arming
|
|
280
|
+
* requires the parameter to carry a token the product compares exactly, so a
|
|
281
|
+
* coincidental `?ai_annotate=` from an unrelated tool arms nothing. A colliding
|
|
282
|
+
* COOKIE cannot false-positive either; `isAnnotationArmed` matches on the
|
|
283
|
+
* delimiter rather than by substring, for exactly this reason.
|
|
284
|
+
*
|
|
285
|
+
* If a rename is ever genuinely warranted, it happens ONCE, after step 2 has
|
|
286
|
+
* landed and the reader accepts one name again — not layered on top of an
|
|
287
|
+
* unfinished one.
|
|
288
|
+
*/
|
|
289
|
+
/** Both spellings of the query parameter, current first. */
|
|
290
|
+
export declare const ANNOTATION_TOKEN_PARAMS: readonly ["ai_annotate", "pits_annotate"];
|
|
291
|
+
/** Both spellings of the cookie, current first. */
|
|
292
|
+
export declare const ANNOTATION_ARMED_COOKIES: readonly ["ai_annotate_armed", "pits_annotate_armed"];
|
|
293
|
+
/**
|
|
294
|
+
* Whether a cookie jar carries the armed cookie, under either name.
|
|
295
|
+
*
|
|
296
|
+
* Delimiter-aware rather than a substring test: a cookie named
|
|
297
|
+
* `not_ai_annotate_armed`, or another cookie whose VALUE contains the name,
|
|
298
|
+
* satisfies `includes` — and arming an annotation channel on a coincidence is
|
|
299
|
+
* not a failure anyone would think to look for.
|
|
300
|
+
*/
|
|
301
|
+
export declare function isAnnotationArmed(cookie: string): boolean;
|
|
302
|
+
/**
|
|
303
|
+
* The arming token from a URL's query string, under either name.
|
|
304
|
+
*
|
|
305
|
+
* Current name wins when both are present. They should never disagree — the
|
|
306
|
+
* management app writes both from one value — but if they ever do, the one this
|
|
307
|
+
* version of the protocol owns is the one to believe.
|
|
308
|
+
*/
|
|
309
|
+
export declare function readAnnotationToken(params: URLSearchParams): string | null;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var g="1",l="data-src",m="data-src-name",o=new Set(["annotate:enable","annotate:disable","annotate:ping"]);function d(t){if(typeof t!="object"||t===null)return!1;let e=t.type;return typeof e=="string"&&o.has(e)}function A(t){if(!t||t==="*")throw new Error("[annotation] a concrete parent origin is required; '*' would broadcast annotation payloads to any embedder.");return t}var a="ai_annotate",s="ai_annotate_armed",i="pits_annotate",c="pits_annotate_armed",p=[a,i],u=[s,c];function f(t){return t.split(";").some(e=>{let n=e.trimStart();return u.some(r=>n.startsWith(`${r}=`))})}function T(t){for(let e of p){let n=t.get(e);if(n!==null&&n.length>0)return n}return null}export{s as ANNOTATION_ARMED_COOKIE,u as ANNOTATION_ARMED_COOKIES,a as ANNOTATION_TOKEN_PARAM,p as ANNOTATION_TOKEN_PARAMS,c as LEGACY_ANNOTATION_ARMED_COOKIE,i as LEGACY_ANNOTATION_TOKEN_PARAM,m as NAME_ATTR,g as SDK_VERSION,l as SRC_ATTR,A as assertConcreteOrigin,f as isAnnotationArmed,d as isParentMessage,T as readAnnotationToken};
|
|
2
|
+
//# sourceMappingURL=protocol.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/protocol.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * The annotation postMessage protocol (A-36).\n *\n * Mirrors `docs/contracts/types.ts`. That file is the\n * cross-component contract; this is the runtime copy the product bundle ships,\n * because the product cannot import from a docs directory. Changing a shape\n * here is a change to both \u2014 say so in the PR.\n */\n\nexport const SDK_VERSION = \"1\";\n\n/**\n * ===========================================================================\n * THE ATTRIBUTES \u2014 THE OTHER WIRE (A-186)\n * ===========================================================================\n *\n * These live in `protocol.ts`, not in `target.ts` where they are read, because\n * they are a contract between TWO PACKAGES that a consumer installs separately:\n * `@weatherboard/annotation-next` WRITES them at build time and this package\n * READS them at runtime. Two spellings of `data-src` is not a bug anybody\n * catches \u2014 the transform runs, the attributes appear, and every capture comes\n * back with no source ref at all, which is indistinguishable from the transform\n * not running.\n *\n * `annotation-next` imports these from `@weatherboard/annotation/protocol`\n * rather than declaring its own, which is why the subpath has no DOM in it: a\n * build tool importing the page SDK to learn two strings would be absurd.\n */\nexport const SRC_ATTR = \"data-src\";\nexport const NAME_ATTR = \"data-src-name\";\n\nexport interface SourceRef {\n file: string;\n line: number;\n column?: number;\n}\n\nexport interface BuildInfo {\n /** Mandatory. Feedback not pinned to a revision is ambiguous the moment someone merges. */\n gitSha: string;\n /**\n * Where this build came from.\n *\n * `\"development\"` was added in A-37, when the SDK was first mounted in a\n * real app and the two halves turned out not to agree: `resolveBuildInfo` in\n * `resolveBuildInfo` in the product's own Next config package \u2014 the module\n * that stamps the build-env variable, and the only producer of this field \u2014\n * emits\n * `production | preview | development`, mirroring `VERCEL_ENV`. This union\n * instead offered `\"staging\"`, which nothing produces: a staging deploy IS a\n * Vercel preview and reports itself as one. Widening rather than forcing the\n * mount to lie: a locally-annotated build calling itself a preview would put\n * someone's laptop in the corpus as though it were a deployment.\n */\n env: \"production\" | \"preview\" | \"staging\" | \"development\";\n branch?: string;\n /** Set when reviewing an agent's preview deploy, so feedback routes to that run's session. */\n previewRunId?: string;\n}\n\nexport interface ConsoleEntry {\n level: \"error\" | \"warn\";\n message: string;\n stack?: string;\n at: string;\n}\n\nexport interface NetworkEntry {\n url: string;\n method: string;\n status: number;\n at: string;\n}\n\nexport interface TargetInfo {\n /**\n * What the reviewer selected \u2014 one element, or an area (A-179).\n *\n * -------------------------------------------------------------------------\n * WHY THIS EXISTS RATHER THAN BEING INFERRED\n * -------------------------------------------------------------------------\n *\n * A region capture and an element capture are the same SHAPE: a bounding box,\n * a chain of source refs, a DOM path. Nothing in the values distinguishes\n * them, and the two mean opposite things about the chain \u2014 for an element it\n * is ANCESTORS, innermost first, so entry two contains entry one; for a\n * region it is SIBLINGS the rectangle happened to cross, which contain\n * nothing of each other.\n *\n * A reader that guesses will describe a region's siblings as a call-site\n * chain, which is a confident false statement about the page. `describeCapture`\n * hands that description to a model that writes acceptance criteria from it.\n *\n * -------------------------------------------------------------------------\n * WHY IT IS OPTIONAL, AND WHY ABSENT MEANS `element`\n * -------------------------------------------------------------------------\n *\n * The two halves of this protocol live in different repositories and deploy\n * independently (see the note on the legacy parameter names below). Every\n * capture in the store today, and every capture from a product bundle that\n * predates region selection, has no such field \u2014 and all of them are element\n * captures. Absent therefore has to mean `element`, or this field would\n * retroactively make the entire history ambiguous.\n *\n * Required-with-a-default would have the same effect and a worse failure: an\n * older bundle omits it, the type says it is there, and every reader believes\n * a value nobody sent.\n */\n selection?: \"element\" | \"region\";\n source?: SourceRef;\n /**\n * Every `data-src` from the clicked element up to the document root, innermost\n * first \u2014 an addition to the contract, and the reason is structural.\n *\n * Only host elements carry a ref (A-33), so `source` names the file that\n * *writes the markup*. For a composed design-system component that is\n * `MediaCard.tsx`, not the `GuideDetailCard.tsx` a human would say they\n * clicked. The chain is what lets the PM agent and the coding agent see both,\n * and pick the call site over the leaf when the feedback is about content\n * rather than the component itself.\n */\n sourceChain?: SourceRef[];\n componentName?: string;\n /** CSS selector fallback, for when no ancestor carries a ref at all. */\n domPath: string;\n boundingBox: { x: number; y: number; w: number; h: number };\n /** Truncated to 200 characters. */\n textContent?: string;\n}\n\nexport interface AnnotationPayload {\n schemaVersion: 1;\n capturedAt: string;\n build: BuildInfo;\n page: {\n url: string;\n /** The matched route pattern, not the resolved URL. */\n route: string;\n viewport: { w: number; h: number; dpr: number };\n userAgent: string;\n };\n target: TargetInfo;\n state: {\n consoleErrors: ConsoleEntry[];\n failedRequests: NetworkEntry[];\n featureFlags: Record<string, unknown>;\n };\n screenshot?: { dataUrl: string; region: \"element\" | \"viewport\" };\n /** The human's words, verbatim. The parent frame fills this in; we never rewrite it. */\n comment: string;\n}\n\nexport type ParentToFrame =\n | { type: \"annotate:enable\" }\n | { type: \"annotate:disable\" }\n | { type: \"annotate:ping\" };\n\nexport type FrameToParent =\n | { type: \"annotate:ready\"; sdkVersion: string; build: BuildInfo }\n | { type: \"annotate:hover\"; target: TargetInfo }\n | { type: \"annotate:capture\"; payload: AnnotationPayload }\n | { type: \"annotate:cancel\" };\n\nconst PARENT_TYPES = new Set([\"annotate:enable\", \"annotate:disable\", \"annotate:ping\"]);\n\n/**\n * Is this a message we recognise?\n *\n * Origin is checked separately and first \u2014 a well-formed message from the wrong\n * origin is the case this guard must not be trusted to catch.\n */\nexport function isParentMessage(data: unknown): data is ParentToFrame {\n if (typeof data !== \"object\" || data === null) return false;\n const type = (data as { type?: unknown }).type;\n return typeof type === \"string\" && PARENT_TYPES.has(type);\n}\n\n/**\n * Reject wildcards outright rather than treating them as \"any origin\".\n *\n * `postMessage(msg, \"*\")` broadcasts the payload to whatever happens to be\n * framing us, and an annotation payload carries page content, console errors and\n * failed request URLs. The spec's rule is no wildcards in either direction; this\n * makes it impossible to configure one by accident.\n */\nexport function assertConcreteOrigin(origin: string): string {\n if (!origin || origin === \"*\") {\n throw new Error(\n \"[annotation] a concrete parent origin is required; '*' would broadcast \" +\n \"annotation payloads to any embedder.\",\n );\n }\n return origin;\n}\n\n/**\n * The query parameter that arms the SDK in a managed product, and the cookie\n * that records it.\n *\n * THESE LIVE IN THE PROTOCOL BECAUSE THE TWO HALVES ARE NOW IN DIFFERENT\n * REPOSITORIES. The managed product's middleware looks for the parameter and\n * sets the cookie; the management app appends the parameter and the SDK reads\n * the cookie. While both halves were one monorepo, a test could read the other\n * side's source and assert the strings matched \u2014 that gate does not survive a\n * repository split, and a mismatch produces no error at all: the frame loads,\n * the cookie is never set, the SDK never boots, and the reviewer sees \"waiting\n * for the page to announce itself\" with nothing to go on.\n *\n * So they stop being two spellings that agree and become one exported\n * constant. A managed product that imports this package cannot drift from it.\n */\nexport const ANNOTATION_TOKEN_PARAM = \"ai_annotate\";\nexport const ANNOTATION_ARMED_COOKIE = \"ai_annotate_armed\";\n\n/**\n * The names these used to have (A-98).\n *\n * -------------------------------------------------------------------------\n * WHY THE RENAME, AND WHY IT COULD NOT JUST BE DONE\n * -------------------------------------------------------------------------\n *\n * They were `pits_annotate` and `pits_annotate_armed` \u2014 one managed product's\n * initialism, in a contract every managed product's bundle has to implement.\n * Onboarding a second product meant asking an unrelated codebase to adopt the\n * first product's name in its cookies and its query strings. That is the bug\n * A-98 is about, and it is a bug in a wire protocol rather than in a variable\n * name, which is what makes it expensive.\n *\n * The two halves live in DIFFERENT REPOSITORIES and deploy independently. A\n * clean rename is therefore a breaking change to every product bundle\n * simultaneously, and its failure mode is silence: the frame loads, the cookie\n * is never set, the SDK never boots, and the reviewer sees \"waiting for the\n * page to announce itself\" with nothing to go on. Nothing throws, nothing logs,\n * and the natural reading is that the agent broke the site.\n *\n * -------------------------------------------------------------------------\n * THE MIGRATION: READ BOTH, WRITE BOTH, THEN STOP WRITING THE OLD ONE\n * -------------------------------------------------------------------------\n *\n * 1. **Now.** Every reader accepts either name. Every writer emits BOTH, so a\n * product still running the old bundle arms on the legacy name and one\n * running the new bundle arms on the new one. Deploy order stops mattering,\n * which is the whole point \u2014 there is no window in which a reviewer sees the\n * silent failure above.\n * 2. **After every managed product's bundle is on this version** (A-102). Drop\n * the legacy names from the writers, then from the readers. Two steps, not\n * one: a reader that stops accepting the old name before the writers stop\n * emitting it re-creates the outage in the other direction.\n *\n * The legacy names are exported rather than inlined so the deletion in step 2\n * is `git grep LEGACY_` rather than an archaeology exercise.\n */\nexport const LEGACY_ANNOTATION_TOKEN_PARAM = \"pits_annotate\";\nexport const LEGACY_ANNOTATION_ARMED_COOKIE = \"pits_annotate_armed\";\n\n/**\n * ===========================================================================\n * AND THE NAMES ARE NOT CHANGING AGAIN FOR THE PUBLISHED PACKAGE (A-184)\n * ===========================================================================\n *\n * When this becomes `@weatherboard/annotation` the obvious next thought is that\n * the wire names should match the package \u2014 `weatherboard_annotate`. They\n * should not, and the reason is the migration described above rather than\n * taste.\n *\n * That migration is STILL IN FLIGHT. Readers accept both spellings; writers\n * emit both; step 2 waits on every managed product's bundle being current.\n * A third spelling introduced now does not replace the second, it joins it:\n * every reader accepts three names, every writer emits three, and the window in\n * which a product can be on any of them widens instead of closing.\n *\n * The cost is not the code. It is that each rename buys another instance of the\n * failure this file exists to prevent \u2014 the frame loads, the cookie is never\n * set, the SDK never boots, and the reviewer sees \"waiting for the page to\n * announce itself\" with nothing to go on. Twice is a migration. Three times is\n * a habit, and the third one would be paid by consumers who never asked for\n * either.\n *\n * `ai_annotate` is already product-neutral, which was the entire point of A-98.\n * A published package needs names that name no product; it does not need names\n * that name the package. Nobody reading a query string cares which npm scope\n * the library came from.\n *\n * The one real objection is collision: `ai_` is a common prefix and some other\n * tool could plausibly use it. That is survivable by construction \u2014 arming\n * requires the parameter to carry a token the product compares exactly, so a\n * coincidental `?ai_annotate=` from an unrelated tool arms nothing. A colliding\n * COOKIE cannot false-positive either; `isAnnotationArmed` matches on the\n * delimiter rather than by substring, for exactly this reason.\n *\n * If a rename is ever genuinely warranted, it happens ONCE, after step 2 has\n * landed and the reader accepts one name again \u2014 not layered on top of an\n * unfinished one.\n */\n\n/** Both spellings of the query parameter, current first. */\nexport const ANNOTATION_TOKEN_PARAMS = [\n ANNOTATION_TOKEN_PARAM,\n LEGACY_ANNOTATION_TOKEN_PARAM,\n] as const;\n\n/** Both spellings of the cookie, current first. */\nexport const ANNOTATION_ARMED_COOKIES = [\n ANNOTATION_ARMED_COOKIE,\n LEGACY_ANNOTATION_ARMED_COOKIE,\n] as const;\n\n/**\n * Whether a cookie jar carries the armed cookie, under either name.\n *\n * Delimiter-aware rather than a substring test: a cookie named\n * `not_ai_annotate_armed`, or another cookie whose VALUE contains the name,\n * satisfies `includes` \u2014 and arming an annotation channel on a coincidence is\n * not a failure anyone would think to look for.\n */\nexport function isAnnotationArmed(cookie: string): boolean {\n return cookie\n .split(\";\")\n .some((entry) => {\n const trimmed = entry.trimStart();\n return ANNOTATION_ARMED_COOKIES.some((name) => trimmed.startsWith(`${name}=`));\n });\n}\n\n/**\n * The arming token from a URL's query string, under either name.\n *\n * Current name wins when both are present. They should never disagree \u2014 the\n * management app writes both from one value \u2014 but if they ever do, the one this\n * version of the protocol owns is the one to believe.\n */\nexport function readAnnotationToken(params: URLSearchParams): string | null {\n for (const name of ANNOTATION_TOKEN_PARAMS) {\n const value = params.get(name);\n if (value !== null && value.length > 0) return value;\n }\n return null;\n}\n"],
|
|
5
|
+
"mappings": "AASO,IAAMA,EAAc,IAmBdC,EAAW,WACXC,EAAY,gBAsInBC,EAAe,IAAI,IAAI,CAAC,kBAAmB,mBAAoB,eAAe,CAAC,EAQ9E,SAASC,EAAgBC,EAAsC,CACpE,GAAI,OAAOA,GAAS,UAAYA,IAAS,KAAM,MAAO,GACtD,IAAMC,EAAQD,EAA4B,KAC1C,OAAO,OAAOC,GAAS,UAAYH,EAAa,IAAIG,CAAI,CAC1D,CAUO,SAASC,EAAqBC,EAAwB,CAC3D,GAAI,CAACA,GAAUA,IAAW,IACxB,MAAM,IAAI,MACR,6GAEF,EAEF,OAAOA,CACT,CAkBO,IAAMC,EAAyB,cACzBC,EAA0B,oBAwC1BC,EAAgC,gBAChCC,EAAiC,sBA2CjCC,EAA0B,CACrCJ,EACAE,CACF,EAGaG,EAA2B,CACtCJ,EACAE,CACF,EAUO,SAASG,EAAkBC,EAAyB,CACzD,OAAOA,EACJ,MAAM,GAAG,EACT,KAAMC,GAAU,CACf,IAAMC,EAAUD,EAAM,UAAU,EAChC,OAAOH,EAAyB,KAAMK,GAASD,EAAQ,WAAW,GAAGC,CAAI,GAAG,CAAC,CAC/E,CAAC,CACL,CASO,SAASC,EAAoBC,EAAwC,CAC1E,QAAWF,KAAQN,EAAyB,CAC1C,IAAMS,EAAQD,EAAO,IAAIF,CAAI,EAC7B,GAAIG,IAAU,MAAQA,EAAM,OAAS,EAAG,OAAOA,CACjD,CACA,OAAO,IACT",
|
|
6
|
+
"names": ["SDK_VERSION", "SRC_ATTR", "NAME_ATTR", "PARENT_TYPES", "isParentMessage", "data", "type", "assertConcreteOrigin", "origin", "ANNOTATION_TOKEN_PARAM", "ANNOTATION_ARMED_COOKIE", "LEGACY_ANNOTATION_TOKEN_PARAM", "LEGACY_ANNOTATION_ARMED_COOKIE", "ANNOTATION_TOKEN_PARAMS", "ANNOTATION_ARMED_COOKIES", "isAnnotationArmed", "cookie", "entry", "trimmed", "name", "readAnnotationToken", "params", "value"]
|
|
7
|
+
}
|