nudge-ui 0.2.0 → 0.2.1
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 +872 -12
- package/dist/hosts/astro/astroRuntimeConfig.js +1 -1
- package/dist/hosts/astro/clientTransport.js +60 -11
- package/dist/hosts/next/sidecar.d.ts +4 -0
- package/dist/hosts/next/sidecar.js +49 -6
- package/dist/hosts/next/wrapper.js +30 -2
- package/dist/hosts/projectBridge.d.ts +20 -0
- package/dist/hosts/projectBridge.js +97 -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 +1 -1
- package/dist/hosts/static/server.js +44 -3
- package/dist/hosts/vite/vite.d.ts +5 -1
- package/dist/hosts/vite/vite.js +78 -14
- package/dist/inspector/agent/McpConnectionDialog.d.ts +2 -2
- package/dist/inspector/agent/McpConnectionDialog.js +11 -35
- package/dist/inspector/agent/client.d.ts +10 -3
- package/dist/inspector/agent/client.js +80 -9
- package/dist/inspector/agent/connectionStatus.js +3 -3
- package/dist/inspector/agent/httpTransport.d.ts +2 -0
- package/dist/inspector/agent/httpTransport.js +37 -17
- package/dist/inspector/agent/protocol.d.ts +8 -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 +246 -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 +392 -73
- 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 +69 -5
- package/dist/inspector/canvas/frameProtocol.js +56 -2
- package/dist/inspector/canvas/keyboardShortcuts.d.ts +3 -0
- package/dist/inspector/canvas/keyboardShortcuts.js +14 -0
- package/dist/inspector/canvas/projection.d.ts +7 -0
- package/dist/inspector/canvas/projection.js +118 -25
- package/dist/inspector/canvas/rendererBootstrap.js +29 -29
- package/dist/inspector/canvas/rendererElementSelector.js +341 -30
- 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/clientManifest.d.ts +5 -0
- package/dist/inspector/clientManifest.js +11 -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 +74 -24
- 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/selectedGeometry.js +21 -2
- package/dist/inspector/overlay/spacingGestures.d.ts +45 -0
- package/dist/inspector/overlay/spacingGestures.js +353 -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 +4 -0
- package/dist/inspector/runtime/runtimeConfig.js +4 -0
- package/dist/inspector/selection/selectionStore.js +2 -0
- package/dist/inspector/settings/SettingsDialog.js +10 -0
- package/dist/inspector/shell/AppShell.js +5 -1
- package/dist/inspector/shell/ChangesLog.js +8 -4
- package/dist/inspector/shell/CopyPromptButton.js +95 -19
- package/dist/inspector/shell/EmptyState.js +1 -1
- package/dist/inspector/shell/InspectorShell.d.ts +0 -1
- package/dist/inspector/shell/InspectorShell.js +37 -38
- 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 +409 -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 +23 -30
- 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 +91 -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 +111 -7
- 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/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/styles.js +13 -11
- package/dist/internal/agent-protocol.d.ts +65 -1
- package/dist/internal/agent-protocol.js +183 -3
- package/dist/nudge-ui.mjs +261 -57
- package/dist/transport/editor.d.ts +28 -0
- package/dist/transport/editor.js +132 -0
- package/dist/transport/index.d.ts +1 -0
- package/dist/transport/index.js +1 -0
- package/dist/transport/routes.d.ts +7 -0
- package/dist/transport/routes.js +7 -0
- package/package.json +3 -1
- package/dist/inspector/shell/panelLayout.d.ts +0 -2
- package/dist/inspector/shell/panelLayout.js +0 -29
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { AGENT_PROTOCOL_VERSION, defaultBridgePort, } from "./protocol.js";
|
|
1
|
+
import { AGENT_PROTOCOL_VERSION, defaultBridgePort, isAgentPromptRequest, } from "./protocol.js";
|
|
2
|
+
import { getActiveCanvasDocument } from "../canvas/activeCanvasDocument.js";
|
|
2
3
|
function isRecord(value) {
|
|
3
4
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
4
5
|
}
|
|
@@ -17,21 +18,35 @@ function endpointValue(value) {
|
|
|
17
18
|
statusUrl: stringValue(value.statusUrl),
|
|
18
19
|
canvasAckUrl: stringValue(value.canvasAckUrl),
|
|
19
20
|
disconnectUrl: stringValue(value.disconnectUrl),
|
|
21
|
+
...(value.autoConnect === true ? { autoConnect: true } : {}),
|
|
20
22
|
};
|
|
21
23
|
return Object.values(config).some((entry) => entry !== undefined) ? config : undefined;
|
|
22
24
|
}
|
|
23
|
-
function
|
|
24
|
-
|
|
25
|
+
function configuredEndpointInDocument(doc) {
|
|
26
|
+
const target = doc.defaultView;
|
|
27
|
+
if (!target)
|
|
25
28
|
return undefined;
|
|
26
|
-
const target = window;
|
|
27
29
|
const globalConfig = endpointValue(target.__NUDGE_UI_AGENT_BRIDGE__)
|
|
28
30
|
?? endpointValue(target.__NUDGE_UI_AGENT__);
|
|
29
31
|
if (globalConfig)
|
|
30
32
|
return globalConfig;
|
|
31
|
-
const meta =
|
|
33
|
+
const meta = doc.querySelector('meta[name="nudge-ui-agent-bridge"]');
|
|
32
34
|
const content = meta?.content.trim();
|
|
33
35
|
return content ? { baseUrl: content } : undefined;
|
|
34
36
|
}
|
|
37
|
+
function configuredEndpoint() {
|
|
38
|
+
if (typeof document === "undefined")
|
|
39
|
+
return undefined;
|
|
40
|
+
const controllerConfig = configuredEndpointInDocument(document);
|
|
41
|
+
if (controllerConfig)
|
|
42
|
+
return controllerConfig;
|
|
43
|
+
const previewDocument = getActiveCanvasDocument();
|
|
44
|
+
return previewDocument ? configuredEndpointInDocument(previewDocument) : undefined;
|
|
45
|
+
}
|
|
46
|
+
/** Returns whether the dev host supplied a trusted project bridge endpoint. */
|
|
47
|
+
export function shouldAutoConnectAgentBridge() {
|
|
48
|
+
return configuredEndpoint()?.autoConnect === true;
|
|
49
|
+
}
|
|
35
50
|
function isLoopback(hostname) {
|
|
36
51
|
const normalized = hostname.toLowerCase();
|
|
37
52
|
return normalized === "localhost"
|
|
@@ -114,20 +129,24 @@ function statusPayload(value) {
|
|
|
114
129
|
let request = null;
|
|
115
130
|
if (rawRequest !== null && rawRequest !== undefined) {
|
|
116
131
|
if (!isRecord(rawRequest)
|
|
117
|
-
|| typeof rawRequest.requestId !== "string"
|
|
118
|
-
|| typeof rawRequest.projectId !== "string"
|
|
119
|
-
|| typeof rawRequest.prompt !== "string"
|
|
120
132
|
|| (rawRequest.status !== "working"
|
|
121
133
|
&& rawRequest.status !== "completed"
|
|
122
134
|
&& rawRequest.status !== "failed"
|
|
123
135
|
&& rawRequest.status !== "interrupted"))
|
|
124
136
|
return null;
|
|
125
|
-
|
|
137
|
+
const requestCandidate = {
|
|
126
138
|
requestId: rawRequest.requestId,
|
|
127
139
|
projectId: rawRequest.projectId,
|
|
128
140
|
prompt: rawRequest.prompt,
|
|
129
|
-
status: rawRequest.status,
|
|
130
141
|
...(typeof rawRequest.changeRevision === "number" ? { changeRevision: rawRequest.changeRevision } : {}),
|
|
142
|
+
...(rawRequest.clientDispatchId === undefined ? {} : { clientDispatchId: rawRequest.clientDispatchId }),
|
|
143
|
+
...(rawRequest.sketches === undefined ? {} : { sketches: rawRequest.sketches }),
|
|
144
|
+
};
|
|
145
|
+
if (!isAgentPromptRequest(requestCandidate))
|
|
146
|
+
return null;
|
|
147
|
+
request = {
|
|
148
|
+
...requestCandidate,
|
|
149
|
+
status: rawRequest.status,
|
|
131
150
|
...(typeof rawRequest.summary === "string" ? { summary: rawRequest.summary } : {}),
|
|
132
151
|
...(typeof rawRequest.error === "string" ? { error: rawRequest.error } : {}),
|
|
133
152
|
};
|
|
@@ -299,20 +318,21 @@ export class HttpAgentBridgeTransport {
|
|
|
299
318
|
signal,
|
|
300
319
|
});
|
|
301
320
|
const payload = await readJson(response);
|
|
302
|
-
if (!isRecord(payload.request)
|
|
303
|
-
|| typeof payload.request.requestId !== "string"
|
|
304
|
-
|| typeof payload.request.projectId !== "string"
|
|
305
|
-
|| typeof payload.request.prompt !== "string"
|
|
306
|
-
|| payload.status !== "working") {
|
|
321
|
+
if (!isRecord(payload.request) || payload.status !== "working") {
|
|
307
322
|
throw new Error("Agent bridge returned an invalid prompt response.");
|
|
308
323
|
}
|
|
309
|
-
const
|
|
324
|
+
const requestCandidate = {
|
|
310
325
|
requestId: payload.request.requestId,
|
|
311
326
|
projectId: payload.request.projectId,
|
|
312
327
|
prompt: payload.request.prompt,
|
|
313
328
|
...(typeof payload.request.changeRevision === "number" ? { changeRevision: payload.request.changeRevision } : {}),
|
|
329
|
+
...(payload.request.clientDispatchId === undefined ? {} : { clientDispatchId: payload.request.clientDispatchId }),
|
|
330
|
+
...(payload.request.sketches === undefined ? {} : { sketches: payload.request.sketches }),
|
|
314
331
|
};
|
|
315
|
-
|
|
332
|
+
if (!isAgentPromptRequest(requestCandidate) || requestCandidate.projectId !== request.projectId) {
|
|
333
|
+
throw new Error("Agent bridge returned an invalid prompt response.");
|
|
334
|
+
}
|
|
335
|
+
return { request: requestCandidate, status: "working" };
|
|
316
336
|
}
|
|
317
337
|
async disconnect(request, signal) {
|
|
318
338
|
const url = endpointUrl(this.config, request.projectId, "disconnectUrl", "/disconnect", pageOrigin());
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AgentStatusSnapshot, CanvasCommand, CanvasCommandAcknowledgement, CanvasCommandResult, PairingResponse, PromptDispatchResponse } from "../../internal/agent-protocol.js";
|
|
1
|
+
import type { AgentStatusSnapshot, CanvasCommand, CanvasCommandAcknowledgement, CanvasCommandResult, AgentSketchAttachment, PairingResponse, PromptDispatchResponse } from "../../internal/agent-protocol.js";
|
|
2
2
|
/**
|
|
3
3
|
* Browser transport port for the shared Nudge agent protocol.
|
|
4
4
|
*
|
|
@@ -7,8 +7,8 @@ import type { AgentStatusSnapshot, CanvasCommand, CanvasCommandAcknowledgement,
|
|
|
7
7
|
* boundary local lets inspector tests use a deterministic fake while the
|
|
8
8
|
* companion remains the owner of MCP and Node-specific code.
|
|
9
9
|
*/
|
|
10
|
-
export { AGENT_PROTOCOL_LIMITS, AGENT_PROTOCOL_VERSION, defaultBridgePort, CANVAS_COMMAND_TYPES, canonicalOrigin, isAgentPromptRequest, isAgentStatusUpdate, isAllowedOrigin, isCanvasCommand, isCanvasGroup, isCanvasState, isCanonicalOrigin, isProjectIdentity, isSameOriginRoute, protocolError, validateRoutes, } from "../../internal/agent-protocol.js";
|
|
11
|
-
export type { AgentConnectionState, AgentProjectIdentity, AgentPromptRequest, AgentRequestOutcome, AgentRequestStatus, AgentRoute, AgentStatusSnapshot, AgentStatusUpdate, BridgeCanvasCommandEvent, BridgeConnectedEvent, BridgeDisconnectedEvent, BridgeEnvelope, BridgeEvent, BridgeEventType, BridgeStatusEvent, CanvasCommand, CanvasCommandAcknowledgement, CanvasCommandError, CanvasCommandResult, CanvasGroup, CanvasGroupOwner, CanvasState, FitCanvasCommand, FocusCanvasGroupCommand, PairingRequest, PairingResponse, PresentRoutesCommand, PromptDispatchRequest, PromptDispatchResponse, ReadCanvasStateCommand, RemoveCanvasGroupCommand, StatusEventRequest, AgentProtocolVersion, } from "../../internal/agent-protocol.js";
|
|
10
|
+
export { AGENT_PROTOCOL_LIMITS, AGENT_PROTOCOL_VERSION, defaultBridgePort, CANVAS_COMMAND_TYPES, canonicalOrigin, isAgentPromptRequest, isAgentSketchAttachment, isAgentSketchAnnotation, isAgentSketchCaptureMetadata, isAgentSketchMetadata, isAgentStatusUpdate, isAllowedOrigin, isCanvasCommand, isCanvasGroup, isCanvasState, isCanonicalOrigin, isProjectIdentity, isSameOriginRoute, protocolError, validateSketchAttachments, validateRoutes, } from "../../internal/agent-protocol.js";
|
|
11
|
+
export type { AgentConnectionState, AgentProjectIdentity, AgentPromptRequest, AgentDeliveredPrompt, AgentSketchAttachment, AgentSketchAnnotation, AgentSketchCaptureMetadata, AgentSketchMetadata, AgentRequestOutcome, AgentRequestStatus, AgentRoute, AgentStatusSnapshot, AgentStatusUpdate, BridgeCanvasCommandEvent, BridgeConnectedEvent, BridgeDisconnectedEvent, BridgeEnvelope, BridgeEvent, BridgeEventType, BridgeStatusEvent, CanvasCommand, CanvasCommandAcknowledgement, CanvasCommandError, CanvasCommandResult, CanvasGroup, CanvasGroupOwner, CanvasState, FitCanvasCommand, FocusCanvasGroupCommand, PairingRequest, PairingResponse, PresentRoutesCommand, PromptDispatchRequest, PromptDispatchResponse, ReadCanvasStateCommand, RemoveCanvasGroupCommand, StatusEventRequest, AgentProtocolVersion, } from "../../internal/agent-protocol.js";
|
|
12
12
|
export interface AgentBridgeEndpointConfig {
|
|
13
13
|
readonly baseUrl?: string;
|
|
14
14
|
readonly healthUrl?: string;
|
|
@@ -18,6 +18,8 @@ export interface AgentBridgeEndpointConfig {
|
|
|
18
18
|
readonly statusUrl?: string;
|
|
19
19
|
readonly canvasAckUrl?: string;
|
|
20
20
|
readonly disconnectUrl?: string;
|
|
21
|
+
/** Pair automatically when this endpoint came from the trusted dev host. */
|
|
22
|
+
readonly autoConnect?: boolean;
|
|
21
23
|
}
|
|
22
24
|
export interface AgentDiscoveryRequest {
|
|
23
25
|
readonly projectId: string;
|
|
@@ -43,6 +45,8 @@ export interface AgentPromptDispatch {
|
|
|
43
45
|
readonly sessionToken: string;
|
|
44
46
|
readonly prompt: string;
|
|
45
47
|
readonly changeRevision?: number;
|
|
48
|
+
readonly clientDispatchId?: string;
|
|
49
|
+
readonly attachments?: readonly AgentSketchAttachment[];
|
|
46
50
|
}
|
|
47
51
|
export interface AgentDisconnectRequest {
|
|
48
52
|
readonly projectId: string;
|
|
@@ -90,6 +94,7 @@ export interface AgentClientOptions {
|
|
|
90
94
|
readonly origin?: string;
|
|
91
95
|
readonly transport?: AgentBridgeTransport;
|
|
92
96
|
readonly endpoint?: AgentBridgeEndpointConfig;
|
|
97
|
+
readonly autoConnect?: boolean;
|
|
93
98
|
readonly discoveryIntervalMs?: number;
|
|
94
99
|
readonly canvasCommandHandler?: (command: CanvasCommand) => CanvasCommandResult | Promise<CanvasCommandResult>;
|
|
95
100
|
}
|
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
* boundary local lets inspector tests use a deterministic fake while the
|
|
7
7
|
* companion remains the owner of MCP and Node-specific code.
|
|
8
8
|
*/
|
|
9
|
-
export { AGENT_PROTOCOL_LIMITS, AGENT_PROTOCOL_VERSION, defaultBridgePort, CANVAS_COMMAND_TYPES, canonicalOrigin, isAgentPromptRequest, isAgentStatusUpdate, isAllowedOrigin, isCanvasCommand, isCanvasGroup, isCanvasState, isCanonicalOrigin, isProjectIdentity, isSameOriginRoute, protocolError, validateRoutes, } from "../../internal/agent-protocol.js";
|
|
9
|
+
export { AGENT_PROTOCOL_LIMITS, AGENT_PROTOCOL_VERSION, defaultBridgePort, CANVAS_COMMAND_TYPES, canonicalOrigin, isAgentPromptRequest, isAgentSketchAttachment, isAgentSketchAnnotation, isAgentSketchCaptureMetadata, isAgentSketchMetadata, isAgentStatusUpdate, isAllowedOrigin, isCanvasCommand, isCanvasGroup, isCanvasState, isCanonicalOrigin, isProjectIdentity, isSameOriginRoute, protocolError, validateSketchAttachments, validateRoutes, } from "../../internal/agent-protocol.js";
|
|
@@ -32,7 +32,7 @@ export declare function getAgentDispatchSize(revision: number): number;
|
|
|
32
32
|
* observable after removing Nudge's own preview. Newer edits and ambiguous
|
|
33
33
|
* records are preserved.
|
|
34
34
|
*/
|
|
35
|
-
export declare function verifyAndReconcileHandoff(snapshot: HandoffSnapshot): Promise<number>;
|
|
35
|
+
export declare function verifyAndReconcileHandoff(snapshot: HandoffSnapshot, doc?: Document | null): Promise<number>;
|
|
36
36
|
/** Reconciles the captured records for one completed connected-agent request. */
|
|
37
37
|
export declare function verifyAndReconcileAgentDispatch(revision: number): Promise<number>;
|
|
38
38
|
/** Test/session reset for in-memory dispatch snapshots. */
|
|
@@ -4,9 +4,13 @@ import { getWorkspaceChanges } from "../changes/workspaceChanges.js";
|
|
|
4
4
|
import { getChangesList, isComponentChange, isTextContentChange, isTokenChange, reconcileVerifiedWorkspaceChanges, } from "../changes/changesLog.js";
|
|
5
5
|
import { verifyPreview } from "../projection/managedStylesheet.js";
|
|
6
6
|
import { resolveRenderedInstance } from "../projection/renderedInstance.js";
|
|
7
|
-
import { getStructuralChanges, } from "../projection/structuralProjection.js";
|
|
7
|
+
import { documentStateKey, getStructuralChanges, } from "../projection/structuralProjection.js";
|
|
8
8
|
import { resolveTextProjectionTarget, resolveTextProjectionTextNode, } from "../projection/textProjection.js";
|
|
9
9
|
import { applyHostWorkspaceProjection, compileWorkspaceProjection, } from "../projection/workspaceProjection.js";
|
|
10
|
+
import { isCanvasProjectionRevisionCurrent, projectWorkspaceSnapshotToDocument, } from "../canvas/projection.js";
|
|
11
|
+
import { getActiveCanvasDocument } from "../canvas/activeCanvasDocument.js";
|
|
12
|
+
import { getSelectedElement } from "../selection/selectionStore.js";
|
|
13
|
+
import { isEditorShellDocument } from "../runtime/editorShell.js";
|
|
10
14
|
const dispatches = new Map();
|
|
11
15
|
function stableJsonValue(value) {
|
|
12
16
|
if (Array.isArray(value))
|
|
@@ -72,7 +76,20 @@ function verifyText(change, doc) {
|
|
|
72
76
|
* verifies.
|
|
73
77
|
*/
|
|
74
78
|
function verifyStructuralDelete(change, doc) {
|
|
75
|
-
|
|
79
|
+
if (!change.route || !change.state || !doc.location)
|
|
80
|
+
return false;
|
|
81
|
+
let currentRoute;
|
|
82
|
+
try {
|
|
83
|
+
const url = new URL(doc.location.href);
|
|
84
|
+
url.hash = "";
|
|
85
|
+
currentRoute = url.href;
|
|
86
|
+
}
|
|
87
|
+
catch {
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
return currentRoute === change.route
|
|
91
|
+
&& documentStateKey(doc) === change.state
|
|
92
|
+
&& resolveRenderedInstance(doc, change.target).status === "missing";
|
|
76
93
|
}
|
|
77
94
|
/**
|
|
78
95
|
* A move verifies when the element sits at its recorded destination without
|
|
@@ -142,11 +159,26 @@ export function getAgentDispatchSize(revision) {
|
|
|
142
159
|
return 0;
|
|
143
160
|
return snapshot.changes.length + snapshot.structuralChanges.length;
|
|
144
161
|
}
|
|
145
|
-
function afterBrowserPaint() {
|
|
146
|
-
|
|
162
|
+
function afterBrowserPaint(doc) {
|
|
163
|
+
const ownerWindow = doc.defaultView;
|
|
164
|
+
const requestFrame = ownerWindow?.requestAnimationFrame.bind(ownerWindow);
|
|
165
|
+
if (!ownerWindow || !requestFrame)
|
|
147
166
|
return Promise.resolve();
|
|
148
167
|
return new Promise((resolve) => {
|
|
149
|
-
|
|
168
|
+
let settled = false;
|
|
169
|
+
const finish = () => {
|
|
170
|
+
if (settled)
|
|
171
|
+
return;
|
|
172
|
+
settled = true;
|
|
173
|
+
clearTimeout(timeout);
|
|
174
|
+
resolve();
|
|
175
|
+
};
|
|
176
|
+
const timeout = setTimeout(finish, 250);
|
|
177
|
+
requestFrame(() => {
|
|
178
|
+
if (doc.defaultView !== ownerWindow)
|
|
179
|
+
return finish();
|
|
180
|
+
requestFrame(finish);
|
|
181
|
+
});
|
|
150
182
|
});
|
|
151
183
|
}
|
|
152
184
|
/**
|
|
@@ -154,7 +186,18 @@ function afterBrowserPaint() {
|
|
|
154
186
|
* observable after removing Nudge's own preview. Newer edits and ambiguous
|
|
155
187
|
* records are preserved.
|
|
156
188
|
*/
|
|
157
|
-
export async function verifyAndReconcileHandoff(snapshot) {
|
|
189
|
+
export async function verifyAndReconcileHandoff(snapshot, doc = activeVerificationDocument()) {
|
|
190
|
+
if (!doc)
|
|
191
|
+
return 0;
|
|
192
|
+
const applyProjection = async (snapshot) => {
|
|
193
|
+
if (doc === document && !isEditorShellDocument(doc)) {
|
|
194
|
+
applyHostWorkspaceProjection(compileWorkspaceProjection(snapshot));
|
|
195
|
+
return "host";
|
|
196
|
+
}
|
|
197
|
+
if (doc === document)
|
|
198
|
+
return null;
|
|
199
|
+
return projectWorkspaceSnapshotToDocument(doc, snapshot);
|
|
200
|
+
};
|
|
158
201
|
const sentByKey = new Map(snapshot.changes.map((change) => [changeKey(change), handoffChangeFingerprint(change)]));
|
|
159
202
|
const current = getChangesList();
|
|
160
203
|
const eligible = current.filter((change) => sentByKey.get(changeKey(change)) === handoffChangeFingerprint(change));
|
|
@@ -169,14 +212,19 @@ export async function verifyAndReconcileHandoff(snapshot) {
|
|
|
169
212
|
const remainingStructural = currentStructural.filter((change) => !eligibleStructuralIds.has(change.id));
|
|
170
213
|
try {
|
|
171
214
|
const currentWorkspace = getWorkspaceChanges();
|
|
172
|
-
|
|
215
|
+
const previewRevision = await applyProjection({
|
|
173
216
|
revision: currentWorkspace.revision,
|
|
174
217
|
changes: remaining,
|
|
175
218
|
structuralChanges: remainingStructural,
|
|
176
|
-
})
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
219
|
+
});
|
|
220
|
+
if (previewRevision === null)
|
|
221
|
+
return 0;
|
|
222
|
+
await afterBrowserPaint(doc);
|
|
223
|
+
if (typeof previewRevision === "number"
|
|
224
|
+
&& !isCanvasProjectionRevisionCurrent(doc, previewRevision))
|
|
225
|
+
return 0;
|
|
226
|
+
const verified = verifiedChangeKeys(eligible, doc);
|
|
227
|
+
const verifiedStructural = verifiedStructuralChangeIds(eligibleStructural, doc);
|
|
180
228
|
// A user can make another inspector edit while the two-frame verification
|
|
181
229
|
// window is open. Recheck byte identity immediately before reconciliation
|
|
182
230
|
// so a newer value at the same key can never be removed.
|
|
@@ -184,15 +232,24 @@ export async function verifyAndReconcileHandoff(snapshot) {
|
|
|
184
232
|
const stillVerified = new Set([...verified].filter((key) => currentByKey.get(key) === sentByKey.get(key)));
|
|
185
233
|
const currentStructuralById = new Map(getStructuralChanges().map((change) => [change.id, handoffStructuralFingerprint(change)]));
|
|
186
234
|
const stillVerifiedStructural = new Set([...verifiedStructural].filter((id) => currentStructuralById.get(id) === sentStructural.get(id)));
|
|
235
|
+
if (typeof previewRevision === "number"
|
|
236
|
+
&& !isCanvasProjectionRevisionCurrent(doc, previewRevision))
|
|
237
|
+
return 0;
|
|
187
238
|
return reconcileVerifiedWorkspaceChanges(stillVerified, stillVerifiedStructural);
|
|
188
239
|
}
|
|
189
240
|
finally {
|
|
190
241
|
// Reconciliation reapplies the canonical set. If it was unable to write
|
|
191
242
|
// (for example, a read-only Canvas lease), restore the untouched set here.
|
|
192
243
|
const canonicalWorkspace = getWorkspaceChanges();
|
|
193
|
-
|
|
244
|
+
await applyProjection(canonicalWorkspace);
|
|
194
245
|
}
|
|
195
246
|
}
|
|
247
|
+
function activeVerificationDocument() {
|
|
248
|
+
const selectedDocument = getSelectedElement()?.domElement.ownerDocument;
|
|
249
|
+
if (selectedDocument && selectedDocument !== document)
|
|
250
|
+
return selectedDocument;
|
|
251
|
+
return getActiveCanvasDocument() ?? (isEditorShellDocument() ? null : document);
|
|
252
|
+
}
|
|
196
253
|
/** Reconciles the captured records for one completed connected-agent request. */
|
|
197
254
|
export async function verifyAndReconcileAgentDispatch(revision) {
|
|
198
255
|
const snapshot = dispatches.get(revision);
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { type ReactElement } from "react";
|
|
2
|
-
import { type CanvasCard } from "./canvasStore.js";
|
|
2
|
+
import { type CanvasCard, type CanvasPresentation } from "./canvasStore.js";
|
|
3
3
|
import type { InspectorSession } from "../session/sessionFactory.js";
|
|
4
4
|
interface CanvasCardProps {
|
|
5
5
|
card: CanvasCard;
|
|
6
|
-
|
|
6
|
+
presentation?: CanvasPresentation;
|
|
7
|
+
presentationCard?: boolean;
|
|
8
|
+
onShowFocus?: (cardId: string) => void;
|
|
7
9
|
documentOwner?: InspectorSession;
|
|
8
10
|
}
|
|
9
|
-
export declare function CanvasCard({ card,
|
|
11
|
+
export declare function CanvasCard({ card, presentation, presentationCard, onShowFocus, documentOwner }: CanvasCardProps): ReactElement;
|
|
10
12
|
export {};
|