nudge-ui 0.2.0 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/nudge-ui.mjs +3 -1
- package/dist/cli/agentCommand.d.ts +8 -0
- package/dist/cli/agentCommand.js +59 -0
- package/dist/client.mjs +878 -11
- package/dist/hosts/astro/astroRuntimeConfig.js +1 -1
- package/dist/hosts/astro/clientTransport.js +63 -11
- package/dist/hosts/astro/integration.d.ts +2 -2
- package/dist/hosts/astro/integration.js +4 -3
- package/dist/hosts/environment.d.ts +15 -0
- package/dist/hosts/environment.js +16 -0
- package/dist/hosts/next/sidecar.d.ts +4 -0
- package/dist/hosts/next/sidecar.js +56 -7
- package/dist/hosts/next/wrapper.d.ts +2 -0
- package/dist/hosts/next/wrapper.js +32 -3
- package/dist/hosts/projectBridge.d.ts +21 -0
- package/dist/hosts/projectBridge.js +98 -0
- package/dist/hosts/static/cli.d.ts +1 -1
- package/dist/hosts/static/cli.js +6 -1
- package/dist/hosts/static/manifest.d.ts +1 -1
- package/dist/hosts/static/manifest.js +3 -1
- package/dist/hosts/static/server.js +45 -3
- package/dist/hosts/vite/vite.d.ts +6 -1
- package/dist/hosts/vite/vite.js +82 -15
- package/dist/inspector/agent/McpConnectionDialog.d.ts +5 -4
- package/dist/inspector/agent/McpConnectionDialog.js +20 -37
- package/dist/inspector/agent/client.d.ts +16 -3
- package/dist/inspector/agent/client.js +114 -11
- package/dist/inspector/agent/connectionStatus.d.ts +3 -3
- package/dist/inspector/agent/connectionStatus.js +11 -4
- package/dist/inspector/agent/httpTransport.d.ts +8 -0
- package/dist/inspector/agent/httpTransport.js +78 -18
- package/dist/inspector/agent/protocol.d.ts +11 -3
- package/dist/inspector/agent/protocol.js +1 -1
- package/dist/inspector/agent/verification.d.ts +1 -1
- package/dist/inspector/agent/verification.js +69 -12
- package/dist/inspector/canvas/CanvasCard.d.ts +5 -3
- package/dist/inspector/canvas/CanvasCard.js +181 -91
- package/dist/inspector/canvas/CanvasElementOverlay.js +288 -52
- package/dist/inspector/canvas/CanvasToolbar.d.ts +12 -0
- package/dist/inspector/canvas/CanvasToolbar.js +24 -0
- package/dist/inspector/canvas/CanvasWorkspace.d.ts +4 -1
- package/dist/inspector/canvas/CanvasWorkspace.js +410 -72
- package/dist/inspector/canvas/activeCanvasDocument.d.ts +5 -0
- package/dist/inspector/canvas/activeCanvasDocument.js +23 -0
- package/dist/inspector/canvas/canvasResize.d.ts +30 -0
- package/dist/inspector/canvas/canvasResize.js +52 -0
- package/dist/inspector/canvas/canvasStore.d.ts +30 -6
- package/dist/inspector/canvas/canvasStore.js +128 -61
- package/dist/inspector/canvas/frameProtocol.d.ts +82 -5
- package/dist/inspector/canvas/frameProtocol.js +63 -2
- package/dist/inspector/canvas/keyboardShortcuts.d.ts +4 -0
- package/dist/inspector/canvas/keyboardShortcuts.js +16 -0
- package/dist/inspector/canvas/linkEligibility.d.ts +0 -5
- package/dist/inspector/canvas/linkEligibility.js +0 -29
- package/dist/inspector/canvas/projection.d.ts +7 -0
- package/dist/inspector/canvas/projection.js +118 -25
- package/dist/inspector/canvas/rendererBootstrap.js +42 -29
- package/dist/inspector/canvas/rendererElementSelector.d.ts +1 -1
- package/dist/inspector/canvas/rendererElementSelector.js +385 -58
- package/dist/inspector/canvas/rendererMessageRouter.d.ts +11 -0
- package/dist/inspector/canvas/rendererMessageRouter.js +43 -0
- package/dist/inspector/canvas/rendererSelectionProxy.js +6 -2
- package/dist/inspector/canvas/sessionStore.d.ts +1 -0
- package/dist/inspector/canvas/sessionStore.js +12 -4
- package/dist/inspector/canvas/staleChangeDetector.js +16 -14
- package/dist/inspector/changes/changesLog.js +31 -1
- package/dist/inspector/changes/managedStyleProjection.d.ts +1 -1
- package/dist/inspector/changes/managedStyleProjection.js +3 -3
- package/dist/inspector/changes/structuralTypes.d.ts +4 -0
- package/dist/inspector/changes/workspaceChanges.d.ts +4 -0
- package/dist/inspector/changes/workspaceChanges.js +29 -3
- package/dist/inspector/clientManifest.d.ts +7 -0
- package/dist/inspector/clientManifest.js +12 -0
- package/dist/inspector/componentSemantics/adapterRegistry.js +4 -3
- package/dist/inspector/componentSemantics/runtimeBridge.d.ts +2 -2
- package/dist/inspector/componentSemantics/runtimeBridge.js +16 -3
- package/dist/inspector/index.d.ts +2 -0
- package/dist/inspector/index.js +80 -32
- package/dist/inspector/inline-text/inlineTextDiagnostics.d.ts +10 -0
- package/dist/inspector/inline-text/inlineTextDiagnostics.js +65 -0
- package/dist/inspector/inline-text/inlineTextEditor.d.ts +3 -5
- package/dist/inspector/inline-text/inlineTextEditor.js +74 -206
- package/dist/inspector/inline-text/inlineTextFeedback.d.ts +5 -0
- package/dist/inspector/inline-text/inlineTextFeedback.js +27 -0
- package/dist/inspector/inline-text/inlineTextLifecycle.js +2 -0
- package/dist/inspector/inline-text/textEditChange.d.ts +14 -0
- package/dist/inspector/inline-text/textEditChange.js +165 -0
- package/dist/inspector/inspection/selectionProperty.d.ts +1 -0
- package/dist/inspector/inspection/selectionProperty.js +1 -0
- package/dist/inspector/overlay/DomNavigator.d.ts +10 -0
- package/dist/inspector/overlay/DomNavigator.js +40 -0
- package/dist/inspector/overlay/InspectorOverlay.js +6 -2
- package/dist/inspector/overlay/clickPolicy.d.ts +18 -2
- package/dist/inspector/overlay/clickPolicy.js +34 -3
- package/dist/inspector/overlay/elementSelector.d.ts +1 -1
- package/dist/inspector/overlay/elementSelector.js +18 -7
- package/dist/inspector/overlay/selectedGeometry.js +21 -2
- package/dist/inspector/overlay/spacingGestures.d.ts +45 -0
- package/dist/inspector/overlay/spacingGestures.js +351 -0
- package/dist/inspector/overlay/structuralGestures.d.ts +2 -2
- package/dist/inspector/overlay/structuralGestures.js +12 -10
- package/dist/inspector/projection/managedStylesheet.js +4 -1
- package/dist/inspector/projection/renderedInstance.d.ts +2 -0
- package/dist/inspector/projection/renderedInstance.js +5 -1
- package/dist/inspector/projection/structuralProjection.d.ts +2 -0
- package/dist/inspector/projection/structuralProjection.js +85 -1
- package/dist/inspector/projection/structuralProjectionBoundary.js +17 -1
- package/dist/inspector/projection/textProjection.d.ts +2 -0
- package/dist/inspector/projection/textProjection.js +10 -4
- package/dist/inspector/prompt/clipboardHandoff.d.ts +1 -1
- package/dist/inspector/prompt/clipboardHandoff.js +3 -3
- package/dist/inspector/prompt/generatePrompt.d.ts +2 -1
- package/dist/inspector/prompt/generatePrompt.js +19 -2
- package/dist/inspector/runtime/editorShell.d.ts +2 -0
- package/dist/inspector/runtime/editorShell.js +4 -0
- package/dist/inspector/runtime/runtimeConfig.d.ts +5 -1
- package/dist/inspector/runtime/runtimeConfig.js +4 -0
- package/dist/inspector/selection/hierarchy.d.ts +6 -0
- package/dist/inspector/selection/hierarchy.js +8 -0
- package/dist/inspector/selection/selectionStore.js +2 -0
- package/dist/inspector/settings/SettingsDialog.d.ts +1 -1
- package/dist/inspector/settings/SettingsDialog.js +12 -2
- package/dist/inspector/shell/AppShell.js +5 -1
- package/dist/inspector/shell/ChangesLog.js +26 -22
- package/dist/inspector/shell/CopyPromptButton.js +102 -19
- package/dist/inspector/shell/EmptyState.js +1 -1
- package/dist/inspector/shell/InspectorShell.d.ts +0 -1
- package/dist/inspector/shell/InspectorShell.js +38 -42
- package/dist/inspector/shell/PeekOriginalButton.d.ts +7 -0
- package/dist/inspector/shell/PeekOriginalButton.js +57 -0
- package/dist/inspector/shell/PeekOriginalIcon.d.ts +7 -0
- package/dist/inspector/shell/PeekOriginalIcon.js +9 -0
- package/dist/inspector/shell/originalPreview.d.ts +9 -0
- package/dist/inspector/shell/originalPreview.js +61 -0
- package/dist/inspector/shell/shortcuts.d.ts +3 -0
- package/dist/inspector/shell/shortcuts.js +15 -0
- package/dist/inspector/sketch/SketchChanges.d.ts +2 -0
- package/dist/inspector/sketch/SketchChanges.js +72 -0
- package/dist/inspector/sketch/SketchEditor.d.ts +21 -0
- package/dist/inspector/sketch/SketchEditor.js +402 -0
- package/dist/inspector/sketch/SketchEntryButton.d.ts +4 -0
- package/dist/inspector/sketch/SketchEntryButton.js +11 -0
- package/dist/inspector/sketch/SketchFrameOverlay.d.ts +11 -0
- package/dist/inspector/sketch/SketchFrameOverlay.js +119 -0
- package/dist/inspector/sketch/SketchLayersPanel.d.ts +2 -0
- package/dist/inspector/sketch/SketchLayersPanel.js +63 -0
- package/dist/inspector/sketch/SketchOverlay.d.ts +19 -0
- package/dist/inspector/sketch/SketchOverlay.js +420 -0
- package/dist/inspector/sketch/SketchPromptPanel.d.ts +15 -0
- package/dist/inspector/sketch/SketchPromptPanel.js +18 -0
- package/dist/inspector/sketch/SketchWorkspace.d.ts +13 -0
- package/dist/inspector/sketch/SketchWorkspace.js +152 -0
- package/dist/inspector/sketch/capture.d.ts +55 -0
- package/dist/inspector/sketch/capture.js +350 -0
- package/dist/inspector/sketch/freehand.d.ts +13 -0
- package/dist/inspector/sketch/freehand.js +64 -0
- package/dist/inspector/sketch/geometry.d.ts +17 -0
- package/dist/inspector/sketch/geometry.js +98 -0
- package/dist/inspector/sketch/handoff.d.ts +21 -0
- package/dist/inspector/sketch/handoff.js +72 -0
- package/dist/inspector/sketch/interaction.d.ts +21 -0
- package/dist/inspector/sketch/interaction.js +98 -0
- package/dist/inspector/sketch/model.d.ts +104 -0
- package/dist/inspector/sketch/model.js +282 -0
- package/dist/inspector/sketch/persistence.d.ts +21 -0
- package/dist/inspector/sketch/persistence.js +205 -0
- package/dist/inspector/sketch/raster.d.ts +22 -0
- package/dist/inspector/sketch/raster.js +203 -0
- package/dist/inspector/sketch/sketchNote.d.ts +10 -0
- package/dist/inspector/sketch/sketchNote.js +30 -0
- package/dist/inspector/sketch/store.d.ts +47 -0
- package/dist/inspector/sketch/store.js +434 -0
- package/dist/inspector/styleEditors/BorderEditor.js +15 -19
- package/dist/inspector/styleEditors/BorderRadiusEditor.js +6 -6
- package/dist/inspector/styleEditors/BoxShadowEditor.js +12 -1
- package/dist/inspector/styleEditors/ColorPicker.js +11 -36
- package/dist/inspector/styleEditors/GapField.d.ts +3 -2
- package/dist/inspector/styleEditors/GapField.js +2 -2
- package/dist/inspector/styleEditors/GridSection.js +1 -1
- package/dist/inspector/styleEditors/LayoutSection.js +11 -8
- package/dist/inspector/styleEditors/SpacingBox.js +31 -33
- package/dist/inspector/styleEditors/layoutPreviewState.d.ts +5 -0
- package/dist/inspector/styleEditors/layoutPreviewState.js +19 -0
- package/dist/inspector/styleEditors/layoutValue.js +3 -0
- package/dist/inspector/styleEditors/nudgeValue.d.ts +11 -0
- package/dist/inspector/styleEditors/nudgeValue.js +93 -5
- package/dist/inspector/styleEditors/stylePresence.d.ts +7 -0
- package/dist/inspector/styleEditors/stylePresence.js +22 -0
- package/dist/inspector/styleEditors/textRelevance.d.ts +3 -0
- package/dist/inspector/styleEditors/textRelevance.js +35 -0
- package/dist/inspector/styleEditors/useFieldVisibility.d.ts +6 -0
- package/dist/inspector/styleEditors/useFieldVisibility.js +26 -0
- package/dist/inspector/tokens/TokenField.js +130 -7
- package/dist/inspector/tokens/TokensPanel.js +2 -1
- package/dist/inspector/tokens/dragPointerLock.d.ts +8 -0
- package/dist/inspector/tokens/dragPointerLock.js +70 -0
- package/dist/inspector/tokens/editActions.d.ts +2 -0
- package/dist/inspector/tokens/editActions.js +2 -2
- package/dist/inspector/tokens/resolution/cssomCollector.d.ts +1 -1
- package/dist/inspector/tokens/resolution/cssomCollector.js +9 -5
- package/dist/inspector/tokens/resolution/ruleMatching.d.ts +40 -0
- package/dist/inspector/tokens/resolution/ruleMatching.js +423 -0
- package/dist/inspector/tokens/resolution/selectorSemantics.d.ts +19 -3
- package/dist/inspector/tokens/resolution/selectorSemantics.js +378 -4
- package/dist/inspector/tokens/resolution.d.ts +3 -26
- package/dist/inspector/tokens/resolution.js +44 -735
- package/dist/inspector/tokens/tokenAvailability.d.ts +18 -0
- package/dist/inspector/tokens/tokenAvailability.js +204 -0
- package/dist/inspector/ui/Button.d.ts +1 -1
- package/dist/inspector/ui/Disclosure.d.ts +22 -0
- package/dist/inspector/ui/Disclosure.js +13 -0
- package/dist/inspector/ui/SideValuesField.js +2 -2
- package/dist/inspector/ui/StatusCallout.d.ts +4 -1
- package/dist/inspector/ui/StatusCallout.js +2 -2
- package/dist/inspector/ui/dragCursor.d.ts +8 -0
- package/dist/inspector/ui/dragCursor.js +21 -0
- package/dist/inspector/ui/styles.js +21 -17
- package/dist/internal/agent-protocol.d.ts +65 -1
- package/dist/internal/agent-protocol.js +183 -3
- package/dist/nudge-ui.mjs +276 -58
- package/dist/transport/editor.d.ts +47 -0
- package/dist/transport/editor.js +163 -0
- package/dist/transport/index.d.ts +1 -0
- package/dist/transport/index.js +1 -0
- package/dist/transport/routes.d.ts +10 -0
- package/dist/transport/routes.js +10 -0
- package/package.json +3 -1
- package/dist/inspector/shell/DomNavigation.d.ts +0 -8
- package/dist/inspector/shell/DomNavigation.js +0 -30
- package/dist/inspector/shell/panelLayout.d.ts +0 -2
- package/dist/inspector/shell/panelLayout.js +0 -29
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* imports. Hosts can use the same validation and message shapes without
|
|
7
7
|
* pulling the companion into a browser bundle.
|
|
8
8
|
*/
|
|
9
|
-
export const AGENT_PROTOCOL_VERSION =
|
|
9
|
+
export const AGENT_PROTOCOL_VERSION = 2;
|
|
10
10
|
export const AGENT_PROTOCOL_LIMITS = {
|
|
11
11
|
projectId: 256,
|
|
12
12
|
workspaceRoot: 4096,
|
|
@@ -14,7 +14,21 @@ export const AGENT_PROTOCOL_LIMITS = {
|
|
|
14
14
|
sessionToken: 256,
|
|
15
15
|
requestId: 256,
|
|
16
16
|
commandId: 256,
|
|
17
|
+
clientDispatchId: 256,
|
|
17
18
|
prompt: 32_000,
|
|
19
|
+
sketchId: 256,
|
|
20
|
+
sketchRevision: 2_147_483_647,
|
|
21
|
+
sketchFilename: 256,
|
|
22
|
+
sketchDescription: 2_000,
|
|
23
|
+
sketchCount: 4,
|
|
24
|
+
sketchImageBytes: 2 * 1024 * 1024,
|
|
25
|
+
sketchTotalBytes: 8 * 1024 * 1024,
|
|
26
|
+
sketchEncodedBytes: 12 * 1024 * 1024,
|
|
27
|
+
sketchAnnotationCount: 50,
|
|
28
|
+
sketchUrl: 2_048,
|
|
29
|
+
sketchTitle: 512,
|
|
30
|
+
sketchFramework: 128,
|
|
31
|
+
sketchHost: 128,
|
|
18
32
|
groupId: 256,
|
|
19
33
|
label: 160,
|
|
20
34
|
routeUrl: 2048,
|
|
@@ -64,6 +78,25 @@ function optionalString(value, maximum) {
|
|
|
64
78
|
function optionalRevision(value) {
|
|
65
79
|
return value === undefined || (typeof value === "number" && Number.isSafeInteger(value) && value >= 0);
|
|
66
80
|
}
|
|
81
|
+
function boundedNumber(value, maximum) {
|
|
82
|
+
return typeof value === "number" && Number.isSafeInteger(value) && value >= 0 && value <= maximum;
|
|
83
|
+
}
|
|
84
|
+
function boundedFiniteNumber(value, maximum) {
|
|
85
|
+
return typeof value === "number" && Number.isFinite(value) && value >= 0 && value <= maximum;
|
|
86
|
+
}
|
|
87
|
+
function boundedString(value, maximum) {
|
|
88
|
+
return typeof value === "string" && value.length <= maximum;
|
|
89
|
+
}
|
|
90
|
+
function validBase64(value, maximum) {
|
|
91
|
+
return typeof value === "string"
|
|
92
|
+
&& value.length > 0
|
|
93
|
+
&& value.length <= maximum
|
|
94
|
+
&& /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(value);
|
|
95
|
+
}
|
|
96
|
+
function encodedByteLength(value) {
|
|
97
|
+
const padding = value.endsWith("==") ? 2 : value.endsWith("=") ? 1 : 0;
|
|
98
|
+
return Math.max(0, Math.floor(value.length * 3 / 4) - padding);
|
|
99
|
+
}
|
|
67
100
|
/**
|
|
68
101
|
* Returns a canonical origin or null. Credentials, paths, and fragments are
|
|
69
102
|
* rejected so the browser cannot broaden the pairing boundary accidentally.
|
|
@@ -157,13 +190,160 @@ export function isProjectIdentity(value) {
|
|
|
157
190
|
&& (value.origin === undefined || isCanonicalOrigin(value.origin))
|
|
158
191
|
&& optionalString(value.workspaceRoot, AGENT_PROTOCOL_LIMITS.workspaceRoot);
|
|
159
192
|
}
|
|
193
|
+
export function isAgentSketchCaptureMetadata(value) {
|
|
194
|
+
if (!isRecord(value) || !hasOnlyKeys(value, [
|
|
195
|
+
"url",
|
|
196
|
+
"title",
|
|
197
|
+
"timestamp",
|
|
198
|
+
"viewportWidth",
|
|
199
|
+
"viewportHeight",
|
|
200
|
+
"scrollX",
|
|
201
|
+
"scrollY",
|
|
202
|
+
"devicePixelRatio",
|
|
203
|
+
"host",
|
|
204
|
+
"framework",
|
|
205
|
+
]))
|
|
206
|
+
return false;
|
|
207
|
+
if (!nonEmptyString(value.url, AGENT_PROTOCOL_LIMITS.sketchUrl)
|
|
208
|
+
|| !boundedString(value.title, AGENT_PROTOCOL_LIMITS.sketchTitle)
|
|
209
|
+
|| !boundedNumber(value.timestamp, Number.MAX_SAFE_INTEGER)
|
|
210
|
+
|| !boundedNumber(value.viewportWidth, 100_000)
|
|
211
|
+
|| !boundedNumber(value.viewportHeight, 100_000)
|
|
212
|
+
|| !boundedFiniteNumber(value.scrollX, Number.MAX_SAFE_INTEGER)
|
|
213
|
+
|| !boundedFiniteNumber(value.scrollY, Number.MAX_SAFE_INTEGER)
|
|
214
|
+
|| !boundedFiniteNumber(value.devicePixelRatio, 100)
|
|
215
|
+
|| value.devicePixelRatio <= 0
|
|
216
|
+
|| !nonEmptyString(value.host, AGENT_PROTOCOL_LIMITS.sketchHost)
|
|
217
|
+
|| !nonEmptyString(value.framework, AGENT_PROTOCOL_LIMITS.sketchFramework)) {
|
|
218
|
+
return false;
|
|
219
|
+
}
|
|
220
|
+
try {
|
|
221
|
+
const url = new URL(value.url);
|
|
222
|
+
if (url.protocol !== "http:" && url.protocol !== "https:")
|
|
223
|
+
return false;
|
|
224
|
+
}
|
|
225
|
+
catch {
|
|
226
|
+
return false;
|
|
227
|
+
}
|
|
228
|
+
return true;
|
|
229
|
+
}
|
|
230
|
+
export function isAgentSketchAnnotation(value) {
|
|
231
|
+
if (!isRecord(value) || !hasOnlyKeys(value, ["number", "description"]))
|
|
232
|
+
return false;
|
|
233
|
+
return boundedNumber(value.number, AGENT_PROTOCOL_LIMITS.sketchAnnotationCount)
|
|
234
|
+
&& value.number >= 1
|
|
235
|
+
&& nonEmptyString(value.description, AGENT_PROTOCOL_LIMITS.sketchDescription);
|
|
236
|
+
}
|
|
237
|
+
function validSketchAnnotationList(value) {
|
|
238
|
+
if (!Array.isArray(value)
|
|
239
|
+
|| value.length > AGENT_PROTOCOL_LIMITS.sketchAnnotationCount
|
|
240
|
+
|| !value.every(isAgentSketchAnnotation))
|
|
241
|
+
return false;
|
|
242
|
+
return new Set(value.map((annotation) => annotation.number)).size === value.length;
|
|
243
|
+
}
|
|
244
|
+
export function isAgentSketchMetadata(value) {
|
|
245
|
+
if (!isRecord(value) || !hasOnlyKeys(value, [
|
|
246
|
+
"id",
|
|
247
|
+
"revision",
|
|
248
|
+
"filename",
|
|
249
|
+
"mimeType",
|
|
250
|
+
"width",
|
|
251
|
+
"height",
|
|
252
|
+
"byteSize",
|
|
253
|
+
"capture",
|
|
254
|
+
"description",
|
|
255
|
+
"annotations",
|
|
256
|
+
]))
|
|
257
|
+
return false;
|
|
258
|
+
return nonEmptyString(value.id, AGENT_PROTOCOL_LIMITS.sketchId)
|
|
259
|
+
&& boundedNumber(value.revision, AGENT_PROTOCOL_LIMITS.sketchRevision)
|
|
260
|
+
&& value.revision > 0
|
|
261
|
+
&& nonEmptyString(value.filename, AGENT_PROTOCOL_LIMITS.sketchFilename)
|
|
262
|
+
&& value.mimeType === "image/png"
|
|
263
|
+
&& boundedNumber(value.width, 2_048)
|
|
264
|
+
&& value.width > 0
|
|
265
|
+
&& boundedNumber(value.height, 2_048)
|
|
266
|
+
&& value.height > 0
|
|
267
|
+
&& boundedNumber(value.byteSize, AGENT_PROTOCOL_LIMITS.sketchImageBytes)
|
|
268
|
+
&& value.byteSize > 0
|
|
269
|
+
&& isAgentSketchCaptureMetadata(value.capture)
|
|
270
|
+
&& (value.description === undefined
|
|
271
|
+
|| boundedString(value.description, AGENT_PROTOCOL_LIMITS.sketchDescription))
|
|
272
|
+
&& (value.annotations === undefined || validSketchAnnotationList(value.annotations));
|
|
273
|
+
}
|
|
274
|
+
export function isAgentSketchAttachment(value) {
|
|
275
|
+
if (!isRecord(value) || !hasOnlyKeys(value, [
|
|
276
|
+
"id",
|
|
277
|
+
"revision",
|
|
278
|
+
"filename",
|
|
279
|
+
"mimeType",
|
|
280
|
+
"width",
|
|
281
|
+
"height",
|
|
282
|
+
"byteSize",
|
|
283
|
+
"capture",
|
|
284
|
+
"description",
|
|
285
|
+
"annotations",
|
|
286
|
+
"data",
|
|
287
|
+
]) || !isAgentSketchMetadata({
|
|
288
|
+
id: value.id,
|
|
289
|
+
revision: value.revision,
|
|
290
|
+
filename: value.filename,
|
|
291
|
+
mimeType: value.mimeType,
|
|
292
|
+
width: value.width,
|
|
293
|
+
height: value.height,
|
|
294
|
+
byteSize: value.byteSize,
|
|
295
|
+
capture: value.capture,
|
|
296
|
+
...(value.description === undefined ? {} : { description: value.description }),
|
|
297
|
+
...(value.annotations === undefined ? {} : { annotations: value.annotations }),
|
|
298
|
+
}))
|
|
299
|
+
return false;
|
|
300
|
+
return validBase64(value.data, AGENT_PROTOCOL_LIMITS.sketchEncodedBytes)
|
|
301
|
+
&& encodedByteLength(value.data) === value.byteSize;
|
|
302
|
+
}
|
|
303
|
+
export function validateSketchAttachments(value) {
|
|
304
|
+
if (value === undefined)
|
|
305
|
+
return [];
|
|
306
|
+
if (!Array.isArray(value) || value.length > AGENT_PROTOCOL_LIMITS.sketchCount) {
|
|
307
|
+
throw new TypeError(`attachments must contain at most ${AGENT_PROTOCOL_LIMITS.sketchCount} items`);
|
|
308
|
+
}
|
|
309
|
+
const attachments = value.map((candidate, index) => {
|
|
310
|
+
if (!isAgentSketchAttachment(candidate)) {
|
|
311
|
+
throw new TypeError(`attachments[${index}] is not a valid PNG attachment`);
|
|
312
|
+
}
|
|
313
|
+
return { ...candidate, capture: { ...candidate.capture } };
|
|
314
|
+
});
|
|
315
|
+
if (new Set(attachments.map((attachment) => `${attachment.id}\u0000${attachment.revision}`)).size
|
|
316
|
+
!== attachments.length) {
|
|
317
|
+
throw new TypeError("attachments must not contain duplicate sketch revisions");
|
|
318
|
+
}
|
|
319
|
+
const totalBytes = attachments.reduce((total, attachment) => total + attachment.byteSize, 0);
|
|
320
|
+
if (totalBytes > AGENT_PROTOCOL_LIMITS.sketchTotalBytes) {
|
|
321
|
+
throw new TypeError(`attachments must contain at most ${AGENT_PROTOCOL_LIMITS.sketchTotalBytes} decoded bytes`);
|
|
322
|
+
}
|
|
323
|
+
return attachments;
|
|
324
|
+
}
|
|
325
|
+
function validSketchMetadataList(value) {
|
|
326
|
+
if (!Array.isArray(value) || value.length > AGENT_PROTOCOL_LIMITS.sketchCount
|
|
327
|
+
|| !value.every(isAgentSketchMetadata))
|
|
328
|
+
return false;
|
|
329
|
+
return new Set(value.map((sketch) => `${sketch.id}\u0000${sketch.revision}`)).size === value.length;
|
|
330
|
+
}
|
|
160
331
|
export function isAgentPromptRequest(value) {
|
|
161
|
-
if (!isRecord(value) || !hasOnlyKeys(value, [
|
|
332
|
+
if (!isRecord(value) || !hasOnlyKeys(value, [
|
|
333
|
+
"requestId",
|
|
334
|
+
"projectId",
|
|
335
|
+
"prompt",
|
|
336
|
+
"changeRevision",
|
|
337
|
+
"clientDispatchId",
|
|
338
|
+
"sketches",
|
|
339
|
+
]))
|
|
162
340
|
return false;
|
|
163
341
|
return nonEmptyString(value.requestId, AGENT_PROTOCOL_LIMITS.requestId)
|
|
164
342
|
&& nonEmptyString(value.projectId, AGENT_PROTOCOL_LIMITS.projectId)
|
|
165
343
|
&& nonEmptyString(value.prompt, AGENT_PROTOCOL_LIMITS.prompt)
|
|
166
|
-
&& optionalRevision(value.changeRevision)
|
|
344
|
+
&& optionalRevision(value.changeRevision)
|
|
345
|
+
&& (value.clientDispatchId === undefined || nonEmptyString(value.clientDispatchId, AGENT_PROTOCOL_LIMITS.clientDispatchId))
|
|
346
|
+
&& (value.sketches === undefined || validSketchMetadataList(value.sketches));
|
|
167
347
|
}
|
|
168
348
|
export function isAgentStatusUpdate(value) {
|
|
169
349
|
if (!isRecord(value) || !hasOnlyKeys(value, ["requestId", "status", "summary", "error"]))
|