@xemahq/kernel-contracts 0.28.0 → 0.30.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/dist/document-patch/index.d.ts +4 -0
- package/dist/document-patch/index.d.ts.map +1 -0
- package/dist/document-patch/index.js +20 -0
- package/dist/document-patch/index.js.map +1 -0
- package/dist/document-patch/lib/patch-anchor.d.ts +7 -0
- package/dist/document-patch/lib/patch-anchor.d.ts.map +1 -0
- package/dist/document-patch/lib/patch-anchor.js +14 -0
- package/dist/document-patch/lib/patch-anchor.js.map +1 -0
- package/dist/document-patch/lib/patch-enums.d.ts +11 -0
- package/dist/document-patch/lib/patch-enums.d.ts.map +1 -0
- package/dist/document-patch/lib/patch-enums.js +16 -0
- package/dist/document-patch/lib/patch-enums.js.map +1 -0
- package/dist/document-patch/lib/pending-patch.d.ts +22 -0
- package/dist/document-patch/lib/pending-patch.d.ts.map +1 -0
- package/dist/document-patch/lib/pending-patch.js +3 -0
- package/dist/document-patch/lib/pending-patch.js.map +1 -0
- package/dist/output/index.d.ts +7 -0
- package/dist/output/index.d.ts.map +1 -0
- package/dist/output/index.js +23 -0
- package/dist/output/index.js.map +1 -0
- package/dist/output/lib/output-deliverable-expectation.d.ts +9 -0
- package/dist/output/lib/output-deliverable-expectation.d.ts.map +1 -0
- package/dist/output/lib/output-deliverable-expectation.js +3 -0
- package/dist/output/lib/output-deliverable-expectation.js.map +1 -0
- package/dist/output/lib/output-item-dto.d.ts +25 -0
- package/dist/output/lib/output-item-dto.d.ts.map +1 -0
- package/dist/output/lib/output-item-dto.js +3 -0
- package/dist/output/lib/output-item-dto.js.map +1 -0
- package/dist/output/lib/output-kind.d.ts +14 -0
- package/dist/output/lib/output-kind.d.ts.map +1 -0
- package/dist/output/lib/output-kind.js +18 -0
- package/dist/output/lib/output-kind.js.map +1 -0
- package/dist/output/lib/output-render-hint.d.ts +11 -0
- package/dist/output/lib/output-render-hint.d.ts.map +1 -0
- package/dist/output/lib/output-render-hint.js +10 -0
- package/dist/output/lib/output-render-hint.js.map +1 -0
- package/dist/output/lib/output-version-dto.d.ts +10 -0
- package/dist/output/lib/output-version-dto.d.ts.map +1 -0
- package/dist/output/lib/output-version-dto.js +3 -0
- package/dist/output/lib/output-version-dto.js.map +1 -0
- package/dist/output/lib/payload-schemas/code-diff.d.ts +7 -0
- package/dist/output/lib/payload-schemas/code-diff.d.ts.map +1 -0
- package/dist/output/lib/payload-schemas/code-diff.js +11 -0
- package/dist/output/lib/payload-schemas/code-diff.js.map +1 -0
- package/dist/output/lib/payload-schemas/decision-record.d.ts +19 -0
- package/dist/output/lib/payload-schemas/decision-record.d.ts.map +1 -0
- package/dist/output/lib/payload-schemas/decision-record.js +39 -0
- package/dist/output/lib/payload-schemas/decision-record.js.map +1 -0
- package/dist/output/lib/payload-schemas/diagram.d.ts +12 -0
- package/dist/output/lib/payload-schemas/diagram.d.ts.map +1 -0
- package/dist/output/lib/payload-schemas/diagram.js +34 -0
- package/dist/output/lib/payload-schemas/diagram.js.map +1 -0
- package/dist/output/lib/payload-schemas/external-blob.d.ts +9 -0
- package/dist/output/lib/payload-schemas/external-blob.d.ts.map +1 -0
- package/dist/output/lib/payload-schemas/external-blob.js +15 -0
- package/dist/output/lib/payload-schemas/external-blob.js.map +1 -0
- package/dist/output/lib/payload-schemas/index.d.ts +17 -0
- package/dist/output/lib/payload-schemas/index.d.ts.map +1 -0
- package/dist/output/lib/payload-schemas/index.js +94 -0
- package/dist/output/lib/payload-schemas/index.js.map +1 -0
- package/dist/output/lib/payload-schemas/json-payload.d.ts +4 -0
- package/dist/output/lib/payload-schemas/json-payload.d.ts.map +1 -0
- package/dist/output/lib/payload-schemas/json-payload.js +9 -0
- package/dist/output/lib/payload-schemas/json-payload.js.map +1 -0
- package/dist/output/lib/payload-schemas/manifest.d.ts +37 -0
- package/dist/output/lib/payload-schemas/manifest.d.ts.map +1 -0
- package/dist/output/lib/payload-schemas/manifest.js +43 -0
- package/dist/output/lib/payload-schemas/manifest.js.map +1 -0
- package/dist/output/lib/payload-schemas/markdown-doc.d.ts +8 -0
- package/dist/output/lib/payload-schemas/markdown-doc.d.ts.map +1 -0
- package/dist/output/lib/payload-schemas/markdown-doc.js +12 -0
- package/dist/output/lib/payload-schemas/markdown-doc.js.map +1 -0
- package/dist/output/lib/payload-schemas/review-findings.d.ts +30 -0
- package/dist/output/lib/payload-schemas/review-findings.d.ts.map +1 -0
- package/dist/output/lib/payload-schemas/review-findings.js +39 -0
- package/dist/output/lib/payload-schemas/review-findings.js.map +1 -0
- package/dist/output/lib/payload-schemas/schema.d.ts +4 -0
- package/dist/output/lib/payload-schemas/schema.d.ts.map +1 -0
- package/dist/output/lib/payload-schemas/schema.js +10 -0
- package/dist/output/lib/payload-schemas/schema.js.map +1 -0
- package/dist/output/lib/payload-schemas/test-report.d.ts +33 -0
- package/dist/output/lib/payload-schemas/test-report.d.ts.map +1 -0
- package/dist/output/lib/payload-schemas/test-report.js +46 -0
- package/dist/output/lib/payload-schemas/test-report.js.map +1 -0
- package/dist/output-surface-inspect/index.d.ts +3 -0
- package/dist/output-surface-inspect/index.d.ts.map +1 -0
- package/dist/output-surface-inspect/index.js +19 -0
- package/dist/output-surface-inspect/index.js.map +1 -0
- package/dist/output-surface-inspect/lib/output-surface-inspect.d.ts +226 -0
- package/dist/output-surface-inspect/lib/output-surface-inspect.d.ts.map +1 -0
- package/dist/output-surface-inspect/lib/output-surface-inspect.js +85 -0
- package/dist/output-surface-inspect/lib/output-surface-inspect.js.map +1 -0
- package/dist/output-surface-inspect/lib/step-schema.d.ts +64 -0
- package/dist/output-surface-inspect/lib/step-schema.d.ts.map +1 -0
- package/dist/output-surface-inspect/lib/step-schema.js +73 -0
- package/dist/output-surface-inspect/lib/step-schema.js.map +1 -0
- package/dist/output-surface-inspect/runtime/index.d.ts +2 -0
- package/dist/output-surface-inspect/runtime/index.d.ts.map +1 -0
- package/dist/output-surface-inspect/runtime/index.js +18 -0
- package/dist/output-surface-inspect/runtime/index.js.map +1 -0
- package/dist/workspace-image/index.d.ts +5 -0
- package/dist/workspace-image/index.d.ts.map +1 -0
- package/dist/workspace-image/index.js +21 -0
- package/dist/workspace-image/index.js.map +1 -0
- package/dist/workspace-image/lib/enums.d.ts +17 -0
- package/dist/workspace-image/lib/enums.d.ts.map +1 -0
- package/dist/workspace-image/lib/enums.js +22 -0
- package/dist/workspace-image/lib/enums.js.map +1 -0
- package/dist/workspace-image/lib/hash.d.ts +3 -0
- package/dist/workspace-image/lib/hash.d.ts.map +1 -0
- package/dist/workspace-image/lib/hash.js +50 -0
- package/dist/workspace-image/lib/hash.js.map +1 -0
- package/dist/workspace-image/lib/schemas.d.ts +103 -0
- package/dist/workspace-image/lib/schemas.d.ts.map +1 -0
- package/dist/workspace-image/lib/schemas.js +53 -0
- package/dist/workspace-image/lib/schemas.js.map +1 -0
- package/dist/workspace-image/lib/types.d.ts +50 -0
- package/dist/workspace-image/lib/types.d.ts.map +1 -0
- package/dist/workspace-image/lib/types.js +3 -0
- package/dist/workspace-image/lib/types.js.map +1 -0
- package/package.json +1 -1
- package/src/document-patch/index.ts +25 -0
- package/src/document-patch/lib/patch-anchor.ts +22 -0
- package/src/document-patch/lib/patch-enums.ts +36 -0
- package/src/document-patch/lib/pending-patch.ts +31 -0
- package/src/output/index.ts +20 -0
- package/src/output/lib/output-deliverable-expectation.ts +25 -0
- package/src/output/lib/output-item-dto.ts +54 -0
- package/src/output/lib/output-kind.ts +44 -0
- package/src/output/lib/output-render-hint.ts +28 -0
- package/src/output/lib/output-version-dto.ts +21 -0
- package/src/output/lib/payload-schemas/code-diff.ts +20 -0
- package/src/output/lib/payload-schemas/decision-record.ts +71 -0
- package/src/output/lib/payload-schemas/diagram.ts +54 -0
- package/src/output/lib/payload-schemas/external-blob.ts +36 -0
- package/src/output/lib/payload-schemas/index.ts +133 -0
- package/src/output/lib/payload-schemas/json-payload.ts +19 -0
- package/src/output/lib/payload-schemas/manifest.ts +81 -0
- package/src/output/lib/payload-schemas/markdown-doc.ts +33 -0
- package/src/output/lib/payload-schemas/review-findings.ts +75 -0
- package/src/output/lib/payload-schemas/schema.ts +22 -0
- package/src/output/lib/payload-schemas/test-report.ts +69 -0
- package/src/output-surface-inspect/index.ts +4 -0
- package/src/output-surface-inspect/lib/output-surface-inspect.ts +427 -0
- package/src/output-surface-inspect/lib/step-schema.ts +107 -0
- package/src/output-surface-inspect/runtime/index.ts +7 -0
- package/src/workspace-image/index.ts +13 -0
- package/src/workspace-image/lib/enums.ts +38 -0
- package/src/workspace-image/lib/hash.ts +95 -0
- package/src/workspace-image/lib/schemas.ts +63 -0
- package/src/workspace-image/lib/types.ts +79 -0
|
@@ -0,0 +1,427 @@
|
|
|
1
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
2
|
+
// output-surface-inspect-contracts — the pure (zero-dependency) wire contract for the
|
|
3
|
+
// Output Surface Inspector.
|
|
4
|
+
//
|
|
5
|
+
// One shared source of truth for three independently-deployed parties:
|
|
6
|
+
// • the `output-surface-inspector` agent's `browser` opencode tool (mirrors the
|
|
7
|
+
// step schema with opencode's bundled zod — it cannot import this package)
|
|
8
|
+
// • agent-session-api's OutputSurfaceInspectBroker (imports this package directly)
|
|
9
|
+
// • the Unified Output Surface Bridge injected into the output surface iframe
|
|
10
|
+
//
|
|
11
|
+
// This file is deliberately ZOD-FREE so the browser-side bridge can bundle it
|
|
12
|
+
// without pulling a validation library into every output surface page. The runtime
|
|
13
|
+
// zod schema (`InspectStepSchema`) lives in the sibling `step-schema.ts`, which
|
|
14
|
+
// is type-checked back against the `InspectStep` union declared here.
|
|
15
|
+
//
|
|
16
|
+
// The "step language" deliberately mirrors a headless browser's verb set so a
|
|
17
|
+
// future headless InspectProvider is a drop-in: `InspectTargetKind.HEADLESS`
|
|
18
|
+
// would simply be a superset of `USER_TAB` — every step here stays valid.
|
|
19
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
20
|
+
|
|
21
|
+
// ─── Target backends ────────────────────────────────────────────────────────
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Which browser the inspect batch runs against. Closed set. `USER_TAB` is the
|
|
25
|
+
* only implemented provider; `HEADLESS` is reserved for a future background
|
|
26
|
+
* navigator that drives its own Playwright browser — adding it must not change
|
|
27
|
+
* any other type in this file.
|
|
28
|
+
*/
|
|
29
|
+
export enum InspectTargetKind {
|
|
30
|
+
UserTab = 'user-tab',
|
|
31
|
+
Headless = 'headless',
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// ─── Step language ──────────────────────────────────────────────────────────
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Closed set of inspect step verbs. Navigation steps (`navigate`/`reload`/
|
|
38
|
+
* `back`) are *barriers*: the broker waits for the next page to re-arm the
|
|
39
|
+
* bridge before dispatching later steps.
|
|
40
|
+
*/
|
|
41
|
+
export enum InspectStepKind {
|
|
42
|
+
// navigation (barrier)
|
|
43
|
+
Navigate = 'navigate',
|
|
44
|
+
Reload = 'reload',
|
|
45
|
+
Back = 'back',
|
|
46
|
+
// interaction
|
|
47
|
+
Click = 'click',
|
|
48
|
+
Fill = 'fill',
|
|
49
|
+
Type = 'type',
|
|
50
|
+
Select = 'select',
|
|
51
|
+
Press = 'press',
|
|
52
|
+
Hover = 'hover',
|
|
53
|
+
// inspection
|
|
54
|
+
Snapshot = 'snapshot',
|
|
55
|
+
Evaluate = 'evaluate',
|
|
56
|
+
Console = 'console',
|
|
57
|
+
Network = 'network',
|
|
58
|
+
Page = 'page',
|
|
59
|
+
// control
|
|
60
|
+
Wait = 'wait',
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** Console levels the bridge captures. Closed set. */
|
|
64
|
+
export enum InspectConsoleLevel {
|
|
65
|
+
Log = 'log',
|
|
66
|
+
Info = 'info',
|
|
67
|
+
Warn = 'warn',
|
|
68
|
+
Error = 'error',
|
|
69
|
+
Debug = 'debug',
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** Every console level — the default when a read declares no level filter. */
|
|
73
|
+
export const INSPECT_CONSOLE_LEVEL_VALUES: readonly InspectConsoleLevel[] =
|
|
74
|
+
Object.values(InspectConsoleLevel);
|
|
75
|
+
|
|
76
|
+
/** Per-step outcome. Closed set — every non-`ok` value is a deterministic exit. */
|
|
77
|
+
export enum InspectStepStatus {
|
|
78
|
+
Ok = 'ok',
|
|
79
|
+
Error = 'error',
|
|
80
|
+
/** No bridge replied within the per-step deadline. */
|
|
81
|
+
Timeout = 'timeout',
|
|
82
|
+
/** The page unloaded mid-step (covers an unexpected navigation/refresh). */
|
|
83
|
+
PageNavigated = 'page-navigated',
|
|
84
|
+
/**
|
|
85
|
+
* The output surface navigated to an origin we do not control (external link,
|
|
86
|
+
* OAuth provider, off-site form POST) — the bridge can no longer be
|
|
87
|
+
* injected there, so inspection cannot continue until the user returns to
|
|
88
|
+
* the project output surface.
|
|
89
|
+
*/
|
|
90
|
+
OffDomain = 'off-domain',
|
|
91
|
+
/** An earlier step stopped the batch, so this step never ran. */
|
|
92
|
+
Skipped = 'skipped',
|
|
93
|
+
/** No live output surface tab was attached when the batch ran. */
|
|
94
|
+
OutputSurfaceNotOpen = 'output-surface-not-open',
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** Why the bridge announced an imminent unload. Closed set. */
|
|
98
|
+
export enum InspectUnloadReason {
|
|
99
|
+
/** A normal in-origin navigation/refresh — a new bridge will re-arm. */
|
|
100
|
+
Navigation = 'navigation',
|
|
101
|
+
/**
|
|
102
|
+
* The page is leaving our origin — no bridge can follow. The FE must
|
|
103
|
+
* surface a "return to the project output surface" affordance to the user.
|
|
104
|
+
*/
|
|
105
|
+
OffDomain = 'off-domain',
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/** Overall batch lifecycle. Closed set. */
|
|
109
|
+
export enum InspectBatchStatus {
|
|
110
|
+
Pending = 'pending',
|
|
111
|
+
Running = 'running',
|
|
112
|
+
Completed = 'completed',
|
|
113
|
+
Failed = 'failed',
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// ─── Step shapes ────────────────────────────────────────────────────────────
|
|
117
|
+
//
|
|
118
|
+
// Hand-authored discriminated union. `step-schema.ts` builds the matching zod
|
|
119
|
+
// validator and asserts — at compile time — that the two never drift.
|
|
120
|
+
|
|
121
|
+
// Optional fields on step shapes carry an explicit `| undefined` so this union
|
|
122
|
+
// matches the zod schema's `z.infer` output exactly (see `step-schema.ts`'s
|
|
123
|
+
// compile-time equivalence assertion under `exactOptionalPropertyTypes`).
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* An element target: either a `ref` returned by a prior `snapshot` step, or a
|
|
127
|
+
* raw CSS selector. At least one must be present (enforced by the zod schema).
|
|
128
|
+
*/
|
|
129
|
+
export interface InspectElementTarget {
|
|
130
|
+
ref?: string | undefined;
|
|
131
|
+
selector?: string | undefined;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** Filters shared by the windowed `console` / `network` reads. */
|
|
135
|
+
export interface InspectWindowedRead {
|
|
136
|
+
/** Only entries from the last N ms (rolling observation window). */
|
|
137
|
+
sinceMs?: number | undefined;
|
|
138
|
+
/** Only entries newer than this cursor (from a prior read's result). */
|
|
139
|
+
sinceCursor?: number | undefined;
|
|
140
|
+
/** Case-insensitive substring filter on the entry text/url. */
|
|
141
|
+
grep?: string | undefined;
|
|
142
|
+
/** Max entries returned. Server clamps to INSPECT_READ_MAX_LIMIT. */
|
|
143
|
+
limit?: number | undefined;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export interface InspectNavigateStep {
|
|
147
|
+
kind: InspectStepKind.Navigate;
|
|
148
|
+
/** Path within the output surface app, e.g. `/checkout`. Not an absolute URL. */
|
|
149
|
+
path: string;
|
|
150
|
+
}
|
|
151
|
+
export interface InspectReloadStep {
|
|
152
|
+
kind: InspectStepKind.Reload;
|
|
153
|
+
}
|
|
154
|
+
export interface InspectBackStep {
|
|
155
|
+
kind: InspectStepKind.Back;
|
|
156
|
+
}
|
|
157
|
+
export interface InspectClickStep extends InspectElementTarget {
|
|
158
|
+
kind: InspectStepKind.Click;
|
|
159
|
+
}
|
|
160
|
+
export interface InspectFillStep extends InspectElementTarget {
|
|
161
|
+
kind: InspectStepKind.Fill;
|
|
162
|
+
/** Value written into the input/textarea (replaces existing content). */
|
|
163
|
+
value: string;
|
|
164
|
+
}
|
|
165
|
+
export interface InspectTypeStep extends InspectElementTarget {
|
|
166
|
+
kind: InspectStepKind.Type;
|
|
167
|
+
/** Text typed keystroke-by-keystroke into the focused/target element. */
|
|
168
|
+
text: string;
|
|
169
|
+
}
|
|
170
|
+
export interface InspectSelectStep extends InspectElementTarget {
|
|
171
|
+
kind: InspectStepKind.Select;
|
|
172
|
+
/** `<option>` value (or visible label) to select. */
|
|
173
|
+
value: string;
|
|
174
|
+
}
|
|
175
|
+
export interface InspectPressStep extends InspectElementTarget {
|
|
176
|
+
kind: InspectStepKind.Press;
|
|
177
|
+
/** Key name, e.g. `Enter`, `Tab`, `Escape`. */
|
|
178
|
+
key: string;
|
|
179
|
+
}
|
|
180
|
+
export interface InspectHoverStep extends InspectElementTarget {
|
|
181
|
+
kind: InspectStepKind.Hover;
|
|
182
|
+
}
|
|
183
|
+
export interface InspectSnapshotStep {
|
|
184
|
+
kind: InspectStepKind.Snapshot;
|
|
185
|
+
/** Optional CSS selector to scope the snapshot to a subtree. */
|
|
186
|
+
selector?: string | undefined;
|
|
187
|
+
}
|
|
188
|
+
export interface InspectEvaluateStep {
|
|
189
|
+
kind: InspectStepKind.Evaluate;
|
|
190
|
+
/** JavaScript expression evaluated in the page; result is JSON-serialized. */
|
|
191
|
+
expression: string;
|
|
192
|
+
}
|
|
193
|
+
export interface InspectConsoleStep extends InspectWindowedRead {
|
|
194
|
+
kind: InspectStepKind.Console;
|
|
195
|
+
levels?: InspectConsoleLevel[] | undefined;
|
|
196
|
+
}
|
|
197
|
+
export interface InspectNetworkStep extends InspectWindowedRead {
|
|
198
|
+
kind: InspectStepKind.Network;
|
|
199
|
+
/** Only requests that failed or returned a >=400 status. */
|
|
200
|
+
failedOnly?: boolean | undefined;
|
|
201
|
+
}
|
|
202
|
+
export interface InspectPageStep {
|
|
203
|
+
kind: InspectStepKind.Page;
|
|
204
|
+
}
|
|
205
|
+
export interface InspectWaitStep {
|
|
206
|
+
kind: InspectStepKind.Wait;
|
|
207
|
+
/** Milliseconds to wait before the next step (observation window control). */
|
|
208
|
+
ms: number;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* One inspect step. Discriminated on `kind`. Kept as a hand-authored union so
|
|
213
|
+
* the browser bridge can consume it without bundling zod; `step-schema.ts`
|
|
214
|
+
* holds the runtime validator and is asserted equivalent to this type.
|
|
215
|
+
*/
|
|
216
|
+
export type InspectStep =
|
|
217
|
+
| InspectNavigateStep
|
|
218
|
+
| InspectReloadStep
|
|
219
|
+
| InspectBackStep
|
|
220
|
+
| InspectClickStep
|
|
221
|
+
| InspectFillStep
|
|
222
|
+
| InspectTypeStep
|
|
223
|
+
| InspectSelectStep
|
|
224
|
+
| InspectPressStep
|
|
225
|
+
| InspectHoverStep
|
|
226
|
+
| InspectSnapshotStep
|
|
227
|
+
| InspectEvaluateStep
|
|
228
|
+
| InspectConsoleStep
|
|
229
|
+
| InspectNetworkStep
|
|
230
|
+
| InspectPageStep
|
|
231
|
+
| InspectWaitStep;
|
|
232
|
+
|
|
233
|
+
// ─── Results ────────────────────────────────────────────────────────────────
|
|
234
|
+
|
|
235
|
+
export interface InspectConsoleEntry {
|
|
236
|
+
readonly level: InspectConsoleLevel;
|
|
237
|
+
readonly text: string;
|
|
238
|
+
/** Consecutive identical entries are collapsed; >1 means repeated. */
|
|
239
|
+
readonly count: number;
|
|
240
|
+
readonly firstAt: number;
|
|
241
|
+
readonly lastAt: number;
|
|
242
|
+
readonly source: 'console' | 'window.error' | 'unhandledrejection';
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
export interface InspectNetworkEntry {
|
|
246
|
+
readonly url: string;
|
|
247
|
+
readonly method?: string;
|
|
248
|
+
/** HTTP status — only known for `fetch`/XHR; absent for other resources. */
|
|
249
|
+
readonly status?: number;
|
|
250
|
+
readonly resourceType: string;
|
|
251
|
+
readonly startedAt: number;
|
|
252
|
+
readonly durationMs?: number;
|
|
253
|
+
readonly transferSize?: number;
|
|
254
|
+
readonly failed?: boolean;
|
|
255
|
+
readonly errorText?: string;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
/** Bounded-read envelope shared by `console` and `network` results. */
|
|
259
|
+
export interface InspectReadResult<TEntry> {
|
|
260
|
+
readonly entries: readonly TEntry[];
|
|
261
|
+
/** Total entries currently held in the buffer for this page. */
|
|
262
|
+
readonly collected: number;
|
|
263
|
+
readonly returned: number;
|
|
264
|
+
/** Entries dropped from the buffer (ring eviction) or filtered out. */
|
|
265
|
+
readonly dropped: number;
|
|
266
|
+
readonly truncated: boolean;
|
|
267
|
+
/** Pass back as `sinceCursor` on the next read for incremental polling. */
|
|
268
|
+
readonly cursor: number;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
export interface InspectStepResult {
|
|
272
|
+
readonly kind: InspectStepKind;
|
|
273
|
+
readonly status: InspectStepStatus;
|
|
274
|
+
/** Step-specific payload (page info, snapshot tree, read envelope, …). */
|
|
275
|
+
readonly data?: unknown;
|
|
276
|
+
readonly error?: string;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
/** Request body for `POST /sessions/:id/output-surface-inspect/batch`. */
|
|
280
|
+
export interface InspectBatchRequest {
|
|
281
|
+
readonly steps: readonly InspectStep[];
|
|
282
|
+
readonly target?: InspectTargetKind;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* One output surface app known for the session. Its source lives in the agent's own
|
|
287
|
+
* `/workspace` under `repos/<repoSlug>/` — the agent and the running output surface
|
|
288
|
+
* share that tree, so edits the main agent makes appear live (dev-server HMR).
|
|
289
|
+
*/
|
|
290
|
+
export interface InspectOutputSurfaceApp {
|
|
291
|
+
readonly name: string;
|
|
292
|
+
readonly repoSlug: string;
|
|
293
|
+
readonly kind: string;
|
|
294
|
+
readonly status: string;
|
|
295
|
+
readonly externalUrl?: string;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* The runtime context a `browser` call carries back so the agent always knows
|
|
300
|
+
* *what it is operating on* — derived generically from the session's output surface
|
|
301
|
+
* apps, so it fits any interactive session (webapp-studio, design-system-builder, …).
|
|
302
|
+
*/
|
|
303
|
+
export interface InspectOutputSurfaceContext {
|
|
304
|
+
/** Which browser the steps ran in (`user-tab` = the user's real tab). */
|
|
305
|
+
readonly target: InspectTargetKind;
|
|
306
|
+
/** Output surface apps known for this session and where their source lives. */
|
|
307
|
+
readonly apps: readonly InspectOutputSurfaceApp[];
|
|
308
|
+
/** Absolute workspace root shared by the agent and the running output surface. */
|
|
309
|
+
readonly workspaceRoot: string;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
/** Result of a batch — what the `browser` tool returns to the agent. */
|
|
313
|
+
export interface InspectBatchResult {
|
|
314
|
+
readonly batchId: string;
|
|
315
|
+
readonly status: InspectBatchStatus;
|
|
316
|
+
readonly results: readonly InspectStepResult[];
|
|
317
|
+
/** Human-readable note when the batch ended early (e.g. output-surface-not-open). */
|
|
318
|
+
readonly note?: string;
|
|
319
|
+
/** Runtime context — present on every result so the agent stays oriented. */
|
|
320
|
+
readonly outputSurfaceContext?: InspectOutputSurfaceContext;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
// ─── Bridge ↔ FE-relay postMessage protocol ─────────────────────────────────
|
|
324
|
+
|
|
325
|
+
/** Bridge announces itself on every page load. */
|
|
326
|
+
export const XEMA_INSPECT_HELLO = 'xema:inspect:hello' as const;
|
|
327
|
+
/** Bridge signals an imminent page unload (covers any navigation/refresh). */
|
|
328
|
+
export const XEMA_INSPECT_UNLOADING = 'xema:inspect:unloading' as const;
|
|
329
|
+
/** FE relay → bridge: execute one step. */
|
|
330
|
+
export const XEMA_INSPECT_COMMAND = 'xema:inspect:command' as const;
|
|
331
|
+
/** Bridge → FE relay: the result of one command. */
|
|
332
|
+
export const XEMA_INSPECT_RESULT = 'xema:inspect:result' as const;
|
|
333
|
+
|
|
334
|
+
export interface InspectHelloMessage {
|
|
335
|
+
readonly type: typeof XEMA_INSPECT_HELLO;
|
|
336
|
+
readonly bridgeInstanceId: string;
|
|
337
|
+
readonly url: string;
|
|
338
|
+
readonly title: string;
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
export interface InspectUnloadingMessage {
|
|
342
|
+
readonly type: typeof XEMA_INSPECT_UNLOADING;
|
|
343
|
+
readonly bridgeInstanceId: string;
|
|
344
|
+
readonly reason: InspectUnloadReason;
|
|
345
|
+
/** Best-effort target URL when the bridge could observe it (off-domain). */
|
|
346
|
+
readonly targetUrl?: string;
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
export interface InspectCommandMessage {
|
|
350
|
+
readonly type: typeof XEMA_INSPECT_COMMAND;
|
|
351
|
+
readonly commandId: string;
|
|
352
|
+
readonly step: InspectStep;
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
export interface InspectResultMessage {
|
|
356
|
+
readonly type: typeof XEMA_INSPECT_RESULT;
|
|
357
|
+
readonly commandId: string;
|
|
358
|
+
readonly result: InspectStepResult;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
// ─── Bridge → FE passive signals (not part of the command channel) ──────────
|
|
362
|
+
|
|
363
|
+
/** Bridge announces the output surface app finished its first paint. */
|
|
364
|
+
export const XEMA_OUTPUT_SURFACE_READY = 'xema:output-surface-ready' as const;
|
|
365
|
+
/** Bridge pushes a bounded error summary — drives the FE "Try to fix" gate. */
|
|
366
|
+
export const XEMA_RUNTIME_ERRORS = 'xema:runtime-errors' as const;
|
|
367
|
+
/** FE → bridge: toggle click-to-comment mode. */
|
|
368
|
+
export const XEMA_SET_COMMENT_MODE = 'xema:set-comment-mode' as const;
|
|
369
|
+
/** Bridge → FE: the user clicked an element while comment mode was on. */
|
|
370
|
+
export const XEMA_COMMENT = 'xema:comment' as const;
|
|
371
|
+
|
|
372
|
+
export interface OutputSurfaceRuntimeErrorItem {
|
|
373
|
+
readonly text: string;
|
|
374
|
+
readonly count: number;
|
|
375
|
+
readonly source: 'console' | 'window.error' | 'unhandledrejection';
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
/** Bounded error summary the bridge pushes for the FE turn-completion gate. */
|
|
379
|
+
export interface OutputSurfaceRuntimeErrorSummary {
|
|
380
|
+
readonly type: typeof XEMA_RUNTIME_ERRORS;
|
|
381
|
+
readonly url: string;
|
|
382
|
+
/** Total error-level entries currently buffered. */
|
|
383
|
+
readonly total: number;
|
|
384
|
+
/** Top distinct errors (deduped, capped). */
|
|
385
|
+
readonly top: readonly OutputSurfaceRuntimeErrorItem[];
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
// ─── Realtime event ─────────────────────────────────────────────────────────
|
|
389
|
+
|
|
390
|
+
/** CloudEvent type carrying an inspect command from the broker to the FE relay. */
|
|
391
|
+
export const SESSION_OUTPUT_SURFACE_INSPECT_COMMAND_EVENT =
|
|
392
|
+
'session.output-surface.inspect.command' as const;
|
|
393
|
+
|
|
394
|
+
// ─── Limits (single source of truth; tunable) ───────────────────────────────
|
|
395
|
+
|
|
396
|
+
/** Max steps a single batch may carry. */
|
|
397
|
+
export const INSPECT_MAX_STEPS_PER_BATCH = 20;
|
|
398
|
+
/** Per-step deadline for a non-navigating step. */
|
|
399
|
+
export const INSPECT_STEP_TIMEOUT_MS = 15_000;
|
|
400
|
+
/** Deadline for a navigation barrier to re-arm the bridge on the new page. */
|
|
401
|
+
export const INSPECT_NAVIGATE_TIMEOUT_MS = 30_000;
|
|
402
|
+
/** An output surface tab is considered live this long after its last heartbeat. */
|
|
403
|
+
export const INSPECT_PRESENCE_TTL_MS = 30_000;
|
|
404
|
+
/** FE relay heartbeat cadence (must be < TTL). */
|
|
405
|
+
export const INSPECT_PRESENCE_HEARTBEAT_MS = 10_000;
|
|
406
|
+
|
|
407
|
+
/** Console/network ring-buffer caps inside the bridge. */
|
|
408
|
+
export const INSPECT_BUFFER_MAX_ENTRIES = 500;
|
|
409
|
+
export const INSPECT_BUFFER_MAX_BYTES = 256 * 1024;
|
|
410
|
+
/** Per-entry message/text truncation. */
|
|
411
|
+
export const INSPECT_ENTRY_MAX_BYTES = 2 * 1024;
|
|
412
|
+
/** `evaluate` result JSON truncation. */
|
|
413
|
+
export const INSPECT_EVAL_RESULT_MAX_BYTES = 8 * 1024;
|
|
414
|
+
/** Whole-batch result truncation guard. */
|
|
415
|
+
export const INSPECT_BATCH_RESULT_MAX_BYTES = 32 * 1024;
|
|
416
|
+
/** Windowed-read default/clamp. */
|
|
417
|
+
export const INSPECT_READ_DEFAULT_LIMIT = 50;
|
|
418
|
+
export const INSPECT_READ_MAX_LIMIT = 200;
|
|
419
|
+
|
|
420
|
+
/** True when the step is a navigation barrier (later steps run post-load). */
|
|
421
|
+
export function isInspectNavigationStep(kind: InspectStepKind): boolean {
|
|
422
|
+
return (
|
|
423
|
+
kind === InspectStepKind.Navigate ||
|
|
424
|
+
kind === InspectStepKind.Reload ||
|
|
425
|
+
kind === InspectStepKind.Back
|
|
426
|
+
);
|
|
427
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
2
|
+
// step-schema.ts — the runtime zod validator for the inspect step language.
|
|
3
|
+
//
|
|
4
|
+
// Kept SEPARATE from `output-surface-inspect.ts` on purpose: that module is zod-free
|
|
5
|
+
// so the browser-side Unified Output Surface Bridge can bundle the contract without
|
|
6
|
+
// pulling a validation library into every output surface page. Only agent-session-api
|
|
7
|
+
// (the broker) imports this file's `InspectStepSchema` at runtime.
|
|
8
|
+
//
|
|
9
|
+
// The `_assertStepContractInSync` constant below is a COMPILE-TIME guarantee
|
|
10
|
+
// that this schema and the hand-authored `InspectStep` union never drift — add
|
|
11
|
+
// a step kind to one without the other and the build fails.
|
|
12
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
13
|
+
|
|
14
|
+
import { z } from 'zod';
|
|
15
|
+
|
|
16
|
+
import { InspectConsoleLevel, InspectStepKind } from './output-surface-inspect';
|
|
17
|
+
import type { InspectStep } from './output-surface-inspect';
|
|
18
|
+
|
|
19
|
+
// An element target: either a `ref` from a prior `snapshot`, or a CSS selector.
|
|
20
|
+
const elementTargetShape = {
|
|
21
|
+
ref: z.string().min(1).max(200).optional(),
|
|
22
|
+
selector: z.string().min(1).max(2000).optional(),
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const windowedReadShape = {
|
|
26
|
+
/** Only entries from the last N ms (rolling observation window). */
|
|
27
|
+
sinceMs: z.number().int().positive().max(600_000).optional(),
|
|
28
|
+
/** Only entries newer than this cursor (from a prior read's result). */
|
|
29
|
+
sinceCursor: z.number().int().nonnegative().optional(),
|
|
30
|
+
/** Case-insensitive substring filter on the entry text/url. */
|
|
31
|
+
grep: z.string().min(1).max(400).optional(),
|
|
32
|
+
/** Max entries returned. Server clamps to INSPECT_READ_MAX_LIMIT. */
|
|
33
|
+
limit: z.number().int().positive().optional(),
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export const InspectStepSchema = z.discriminatedUnion('kind', [
|
|
37
|
+
z.object({
|
|
38
|
+
kind: z.literal(InspectStepKind.Navigate),
|
|
39
|
+
/** Path within the output surface app, e.g. `/checkout`. Not an absolute URL. */
|
|
40
|
+
path: z.string().min(1).max(2000),
|
|
41
|
+
}),
|
|
42
|
+
z.object({ kind: z.literal(InspectStepKind.Reload) }),
|
|
43
|
+
z.object({ kind: z.literal(InspectStepKind.Back) }),
|
|
44
|
+
z.object({ kind: z.literal(InspectStepKind.Click), ...elementTargetShape }),
|
|
45
|
+
z.object({
|
|
46
|
+
kind: z.literal(InspectStepKind.Fill),
|
|
47
|
+
...elementTargetShape,
|
|
48
|
+
/** Value written into the input/textarea (replaces existing content). */
|
|
49
|
+
value: z.string().max(20_000),
|
|
50
|
+
}),
|
|
51
|
+
z.object({
|
|
52
|
+
kind: z.literal(InspectStepKind.Type),
|
|
53
|
+
...elementTargetShape,
|
|
54
|
+
/** Text typed keystroke-by-keystroke into the focused/target element. */
|
|
55
|
+
text: z.string().max(20_000),
|
|
56
|
+
}),
|
|
57
|
+
z.object({
|
|
58
|
+
kind: z.literal(InspectStepKind.Select),
|
|
59
|
+
...elementTargetShape,
|
|
60
|
+
/** `<option>` value (or visible label) to select. */
|
|
61
|
+
value: z.string().max(2000),
|
|
62
|
+
}),
|
|
63
|
+
z.object({
|
|
64
|
+
kind: z.literal(InspectStepKind.Press),
|
|
65
|
+
...elementTargetShape,
|
|
66
|
+
/** Key name, e.g. `Enter`, `Tab`, `Escape`. */
|
|
67
|
+
key: z.string().min(1).max(40),
|
|
68
|
+
}),
|
|
69
|
+
z.object({ kind: z.literal(InspectStepKind.Hover), ...elementTargetShape }),
|
|
70
|
+
z.object({
|
|
71
|
+
kind: z.literal(InspectStepKind.Snapshot),
|
|
72
|
+
/** Optional CSS selector to scope the snapshot to a subtree. */
|
|
73
|
+
selector: z.string().min(1).max(2000).optional(),
|
|
74
|
+
}),
|
|
75
|
+
z.object({
|
|
76
|
+
kind: z.literal(InspectStepKind.Evaluate),
|
|
77
|
+
/** JavaScript expression evaluated in the page; result is JSON-serialized. */
|
|
78
|
+
expression: z.string().min(1).max(20_000),
|
|
79
|
+
}),
|
|
80
|
+
z.object({
|
|
81
|
+
kind: z.literal(InspectStepKind.Console),
|
|
82
|
+
...windowedReadShape,
|
|
83
|
+
levels: z.array(z.enum(InspectConsoleLevel)).min(1).optional(),
|
|
84
|
+
}),
|
|
85
|
+
z.object({
|
|
86
|
+
kind: z.literal(InspectStepKind.Network),
|
|
87
|
+
...windowedReadShape,
|
|
88
|
+
/** Only requests that failed or returned a >=400 status. */
|
|
89
|
+
failedOnly: z.boolean().optional(),
|
|
90
|
+
}),
|
|
91
|
+
z.object({ kind: z.literal(InspectStepKind.Page) }),
|
|
92
|
+
z.object({
|
|
93
|
+
kind: z.literal(InspectStepKind.Wait),
|
|
94
|
+
/** Milliseconds to wait before the next step (observation window control). */
|
|
95
|
+
ms: z.number().int().positive().max(60_000),
|
|
96
|
+
}),
|
|
97
|
+
]);
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Compile-time drift guard: the schema and the hand-authored `InspectStep`
|
|
101
|
+
* union MUST stay mutually assignable. Add a step kind (or change a field) on
|
|
102
|
+
* one side without the other and one of these casts fails the build.
|
|
103
|
+
*/
|
|
104
|
+
const _schemaToType = (s: z.infer<typeof InspectStepSchema>): InspectStep => s;
|
|
105
|
+
const _typeToSchema = (s: InspectStep): z.infer<typeof InspectStepSchema> => s;
|
|
106
|
+
void _schemaToType;
|
|
107
|
+
void _typeToSchema;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// Browser-safe (zod-free) subset of the output-surface-inspect contract.
|
|
2
|
+
//
|
|
3
|
+
// The inspector bridge (`output-surface-inspector/bridge`) runs INSIDE the
|
|
4
|
+
// inspected page, so it must import only pure types — never the zod
|
|
5
|
+
// `step-schema` validator that the main `output-surface-inspect` entry also
|
|
6
|
+
// re-exports. This `/runtime` subpath is that browser-safe surface.
|
|
7
|
+
export * from '../lib/output-surface-inspect';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
2
|
+
// ── Workspace Image Contracts — Barrel Export ──
|
|
3
|
+
//
|
|
4
|
+
// Kernel (Layer 1) contracts for per-org workspace image variants. Pure
|
|
5
|
+
// types, closed enums, zod schemas, plus the deterministic content-hash
|
|
6
|
+
// helper used to identify a variant from its declarative manifest +
|
|
7
|
+
// base-image digest. Zero NestJS, zero Prisma.
|
|
8
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
9
|
+
|
|
10
|
+
export * from './lib/enums';
|
|
11
|
+
export * from './lib/types';
|
|
12
|
+
export * from './lib/hash';
|
|
13
|
+
export * from './lib/schemas';
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
2
|
+
// ── Workspace image — closed-domain enums ──
|
|
3
|
+
//
|
|
4
|
+
// Closed sets backing the per-org workspace image variants described in
|
|
5
|
+
// the ImageLayerKind enumerates every layer recipe the kernel
|
|
6
|
+
// understands; VariantStatus enumerates the bake lifecycle.
|
|
7
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Closed set of layer-recipe kinds. Each kind has a strict TypeScript
|
|
11
|
+
* payload shape (see `ImageLayer` in `types.ts`).
|
|
12
|
+
*
|
|
13
|
+
* IMPORTANT: there is no `entrypoint` / `cmd` kind — the entrypoint is
|
|
14
|
+
* owned by the worker-runtime, never by an org-supplied recipe.
|
|
15
|
+
*/
|
|
16
|
+
export enum ImageLayerKind {
|
|
17
|
+
Apt = 'apt',
|
|
18
|
+
Dnf = 'dnf',
|
|
19
|
+
Apk = 'apk',
|
|
20
|
+
Pip = 'pip',
|
|
21
|
+
NpmGlobal = 'npm-global',
|
|
22
|
+
Env = 'env',
|
|
23
|
+
File = 'file',
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Lifecycle of a single image variant. `draft` is editable in the UI;
|
|
28
|
+
* `building` is the active bake; `ready` is mountable by workers;
|
|
29
|
+
* `failed` retains the build log for debugging; `archived` keeps the row
|
|
30
|
+
* for history but disallows new use.
|
|
31
|
+
*/
|
|
32
|
+
export enum VariantStatus {
|
|
33
|
+
Draft = 'draft',
|
|
34
|
+
Building = 'building',
|
|
35
|
+
Ready = 'ready',
|
|
36
|
+
Failed = 'failed',
|
|
37
|
+
Archived = 'archived',
|
|
38
|
+
}
|