@spotpatch/runtime 1.13.0 → 1.15.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.
Files changed (40) hide show
  1. package/dist/{chunk-2WA6XVA4.js → chunk-DCN6OMLH.js} +13 -3
  2. package/dist/{chunk-2WA6XVA4.js.map → chunk-DCN6OMLH.js.map} +1 -1
  3. package/dist/chunk-PXJKFEUJ.js +14 -0
  4. package/dist/chunk-PXJKFEUJ.js.map +1 -0
  5. package/dist/contextual-ask-panel.cjs +1727 -0
  6. package/dist/contextual-ask-panel.cjs.map +1 -0
  7. package/dist/contextual-ask-panel.d.cts +165 -0
  8. package/dist/contextual-ask-panel.d.ts +165 -0
  9. package/dist/contextual-ask-panel.js +1684 -0
  10. package/dist/contextual-ask-panel.js.map +1 -0
  11. package/dist/data-flow-panel.cjs +12 -2
  12. package/dist/data-flow-panel.cjs.map +1 -1
  13. package/dist/data-flow-panel.d.cts +1 -1
  14. package/dist/data-flow-panel.d.ts +1 -1
  15. package/dist/data-flow-panel.js +7 -1
  16. package/dist/data-flow-panel.js.map +1 -1
  17. package/dist/{data-flow-runtime-DMmV0d3E.d.cts → data-flow-runtime-CacBbxN0.d.cts} +2 -1
  18. package/dist/{data-flow-runtime-DMmV0d3E.d.ts → data-flow-runtime-CacBbxN0.d.ts} +2 -1
  19. package/dist/data-flow.cjs +13 -2
  20. package/dist/data-flow.cjs.map +1 -1
  21. package/dist/data-flow.d.cts +1 -1
  22. package/dist/data-flow.d.ts +1 -1
  23. package/dist/data-flow.js +3 -1
  24. package/dist/external-handoff-panel.cjs +22 -6
  25. package/dist/external-handoff-panel.cjs.map +1 -1
  26. package/dist/external-handoff-panel.d.cts +5 -2
  27. package/dist/external-handoff-panel.d.ts +5 -2
  28. package/dist/external-handoff-panel.js +21 -6
  29. package/dist/external-handoff-panel.js.map +1 -1
  30. package/dist/index.cjs +107 -10
  31. package/dist/index.cjs.map +1 -1
  32. package/dist/index.d.cts +5 -5
  33. package/dist/index.d.ts +5 -5
  34. package/dist/index.js +99 -9
  35. package/dist/index.js.map +1 -1
  36. package/dist/motion-extension-contract-B3m26CML.d.cts +72 -0
  37. package/dist/motion-extension-contract-B3m26CML.d.ts +72 -0
  38. package/dist/motion.d.cts +3 -71
  39. package/dist/motion.d.ts +3 -71
  40. package/package.json +15 -2
package/dist/index.d.cts CHANGED
@@ -1,23 +1,23 @@
1
1
  import { SpotPatchRuntimeConfig } from '@spotpatch/shared';
2
- export { D as DataFlowComponentRegistration, a as DataFlowInvocationToken, b as DataFlowRequestFrame, c as DataFlowRequestMetadata, d as DataFlowRuntime, e as DataFlowTriggerMetadata, f as createDataFlowRuntime, g as getDataFlowRuntime, i as installDataFlowPrelude } from './data-flow-runtime-DMmV0d3E.cjs';
2
+ export { D as DataFlowComponentRegistration, a as DataFlowInvocationToken, b as DataFlowRequestFrame, c as DataFlowRequestMetadata, d as DataFlowRuntime, e as DataFlowTriggerMetadata, f as createDataFlowRuntime, g as getDataFlowRuntime, i as installDataFlowPrelude } from './data-flow-runtime-CacBbxN0.cjs';
3
3
  export { mergeComponentDataFlowReport, mergePageDataFlowReport } from './data-flow.cjs';
4
4
  import '@spotpatch/shared/data-flow-runtime';
5
5
 
6
- type RuntimeConfig = SpotPatchRuntimeConfig;
7
-
8
- declare function bootstrapSpotPatch(config: RuntimeConfig): void;
9
-
10
6
  type RuntimeStatus = "idle" | "inspecting" | "selected" | "previewing";
11
7
  interface RuntimeState {
12
8
  readonly status: RuntimeStatus;
13
9
  }
14
10
 
11
+ type RuntimeConfig = SpotPatchRuntimeConfig;
12
+
15
13
  interface SpotPatchController {
16
14
  readonly dispose: () => void;
17
15
  readonly getState: () => RuntimeState;
18
16
  readonly mount: () => void;
19
17
  }
20
18
 
19
+ declare function bootstrapSpotPatch(config: RuntimeConfig): SpotPatchController;
20
+
21
21
  declare const UI_MARKER_ATTRIBUTE: "data-spotpatch-ui";
22
22
 
23
23
  export { type RuntimeConfig, type SpotPatchController, UI_MARKER_ATTRIBUTE, bootstrapSpotPatch };
package/dist/index.d.ts CHANGED
@@ -1,23 +1,23 @@
1
1
  import { SpotPatchRuntimeConfig } from '@spotpatch/shared';
2
- export { D as DataFlowComponentRegistration, a as DataFlowInvocationToken, b as DataFlowRequestFrame, c as DataFlowRequestMetadata, d as DataFlowRuntime, e as DataFlowTriggerMetadata, f as createDataFlowRuntime, g as getDataFlowRuntime, i as installDataFlowPrelude } from './data-flow-runtime-DMmV0d3E.js';
2
+ export { D as DataFlowComponentRegistration, a as DataFlowInvocationToken, b as DataFlowRequestFrame, c as DataFlowRequestMetadata, d as DataFlowRuntime, e as DataFlowTriggerMetadata, f as createDataFlowRuntime, g as getDataFlowRuntime, i as installDataFlowPrelude } from './data-flow-runtime-CacBbxN0.js';
3
3
  export { mergeComponentDataFlowReport, mergePageDataFlowReport } from './data-flow.js';
4
4
  import '@spotpatch/shared/data-flow-runtime';
5
5
 
6
- type RuntimeConfig = SpotPatchRuntimeConfig;
7
-
8
- declare function bootstrapSpotPatch(config: RuntimeConfig): void;
9
-
10
6
  type RuntimeStatus = "idle" | "inspecting" | "selected" | "previewing";
11
7
  interface RuntimeState {
12
8
  readonly status: RuntimeStatus;
13
9
  }
14
10
 
11
+ type RuntimeConfig = SpotPatchRuntimeConfig;
12
+
15
13
  interface SpotPatchController {
16
14
  readonly dispose: () => void;
17
15
  readonly getState: () => RuntimeState;
18
16
  readonly mount: () => void;
19
17
  }
20
18
 
19
+ declare function bootstrapSpotPatch(config: RuntimeConfig): SpotPatchController;
20
+
21
21
  declare const UI_MARKER_ATTRIBUTE: "data-spotpatch-ui";
22
22
 
23
23
  export { type RuntimeConfig, type SpotPatchController, UI_MARKER_ATTRIBUTE, bootstrapSpotPatch };
package/dist/index.js CHANGED
@@ -1,3 +1,6 @@
1
+ import {
2
+ getContextualAskExtension
3
+ } from "./chunk-PXJKFEUJ.js";
1
4
  import {
2
5
  getDataFlowExtension
3
6
  } from "./chunk-NII5OBAN.js";
@@ -7,7 +10,7 @@ import {
7
10
  installDataFlowPrelude,
8
11
  mergeComponentDataFlowReport,
9
12
  mergePageDataFlowReport
10
- } from "./chunk-2WA6XVA4.js";
13
+ } from "./chunk-DCN6OMLH.js";
11
14
  import {
12
15
  getExternalHandoffExtension
13
16
  } from "./chunk-ASRUAKA5.js";
@@ -304,7 +307,7 @@ function readSuccessData(value) {
304
307
  return value.data;
305
308
  }
306
309
  function isCodeContext(value) {
307
- return isRecord2(value) && typeof value.relativePath === "string" && (value.language === "tsx" || value.language === "jsx") && typeof value.startLine === "number" && typeof value.endLine === "number" && typeof value.excerpt === "string" && (value.boundary === "component" || value.boundary === "nearby-lines");
310
+ return isRecord2(value) && typeof value.relativePath === "string" && (value.language === "tsx" || value.language === "jsx" || value.language === "astro") && typeof value.startLine === "number" && typeof value.endLine === "number" && typeof value.excerpt === "string" && (value.boundary === "component" || value.boundary === "nearby-lines");
308
311
  }
309
312
  function deepFreezeUnknown(value) {
310
313
  if (!isRecord2(value) && !Array.isArray(value)) {
@@ -435,7 +438,7 @@ function omitBrowserCodeContext(request) {
435
438
  };
436
439
  }
437
440
  function runtimeApiErrorCode(error) {
438
- return error instanceof RuntimeApiError ? error.code : void 0;
441
+ return error instanceof RuntimeApiError && isAgentErrorCode(error.code) ? error.code : void 0;
439
442
  }
440
443
  function createRuntimeApi(options) {
441
444
  const pendingRequests = /* @__PURE__ */ new Set();
@@ -1719,7 +1722,11 @@ function createSourceResolver(options) {
1719
1722
  if (marker !== void 0) {
1720
1723
  return Object.freeze({
1721
1724
  react: react2,
1722
- source: markerSource(marker, "jsx-host", "exact")
1725
+ source: markerSource(
1726
+ marker,
1727
+ marker.kind === "astro" ? "astro-host" : "jsx-host",
1728
+ "exact"
1729
+ )
1723
1730
  });
1724
1731
  }
1725
1732
  if (react2.source !== void 0) {
@@ -4226,7 +4233,7 @@ function createUnavailableDataFlowPanel(document, changesRoot, diagnosticsRoot)
4226
4233
  resetView: () => void 0
4227
4234
  });
4228
4235
  }
4229
- function createRuntimeView(document, shortcut, ai = Object.freeze({ enabled: false }), localePreference = "auto", dataFlowEnabled = false, externalAgentEnabled = false, framework = "vite", sessionId = "") {
4236
+ function createRuntimeView(document, shortcut, ai = Object.freeze({ enabled: false }), localePreference = "auto", dataFlowEnabled = false, externalAgentEnabled = false, framework = "vite", sessionId = "", contextualAskEnabled = false) {
4230
4237
  const localizer = createUiLocalizer(document, localePreference);
4231
4238
  const associatedWindow = document.defaultView;
4232
4239
  if (associatedWindow === null) {
@@ -4240,6 +4247,9 @@ function createRuntimeView(document, shortcut, ai = Object.freeze({ enabled: fal
4240
4247
  );
4241
4248
  let messages = localizer.messages();
4242
4249
  let currentStatus = "idle";
4250
+ let contextualAskMode = "change";
4251
+ let contextualAskTitle = "";
4252
+ let contextualAskSubtitle = "";
4243
4253
  let plannerVisible = false;
4244
4254
  let executionSuppressed = false;
4245
4255
  let executionProjection;
@@ -4449,6 +4459,29 @@ function createRuntimeView(document, shortcut, ai = Object.freeze({ enabled: fal
4449
4459
  backButton
4450
4460
  );
4451
4461
  actions.append(editorFeedback, secondaryActions, primaryActions);
4462
+ const contextualAskPanel = contextualAskEnabled ? getContextualAskExtension()?.createPanel({
4463
+ document,
4464
+ locale: localizer.locale,
4465
+ subscribeLocale: localizer.subscribe,
4466
+ changeRoot: dataFlowPanel.root,
4467
+ changeActions: actions,
4468
+ announce,
4469
+ onModeChange(mode, askTitle, askSubtitle) {
4470
+ contextualAskMode = mode;
4471
+ contextualAskTitle = askTitle;
4472
+ contextualAskSubtitle = askSubtitle;
4473
+ if (host.isConnected) renderPanelStatus(currentStatus);
4474
+ },
4475
+ onExecutionChange(projection) {
4476
+ executionProjection = projection;
4477
+ executionSuppressed = false;
4478
+ renderFloatingSurfaceMotion();
4479
+ },
4480
+ onViewChange: requestFloatingSurfaceLayout
4481
+ }) : void 0;
4482
+ if (contextualAskPanel !== void 0) {
4483
+ selectionPanel.prepend(contextualAskPanel.root);
4484
+ }
4452
4485
  shell.append(header, body, actions);
4453
4486
  dialog.append(shell);
4454
4487
  const liveRegion = createMarkedElement(document, "div");
@@ -4459,6 +4492,7 @@ function createRuntimeView(document, shortcut, ai = Object.freeze({ enabled: fal
4459
4492
  createStyles(document),
4460
4493
  ...motionExtension === void 0 ? [] : [motionExtension.createStyles(document)],
4461
4494
  dataFlowPanel.styles,
4495
+ ...contextualAskPanel === void 0 ? [] : [contextualAskPanel.styles],
4462
4496
  ...externalHandoffPanel === void 0 ? [] : [externalHandoffPanel.styles]
4463
4497
  ];
4464
4498
  const styleNonce = resolveStyleNonce(document);
@@ -5011,6 +5045,11 @@ function createRuntimeView(document, shortcut, ai = Object.freeze({ enabled: fal
5011
5045
  previewButton.disabled = !canPreview;
5012
5046
  agentPanel.setContextReady(canPreview);
5013
5047
  externalHandoffPanel?.setContextReady(canPreview);
5048
+ contextualAskPanel?.setSelectionPreview({
5049
+ contextReady: currentTargets.every((target2) => target2.status !== "loading"),
5050
+ targetCount: currentTargets.length,
5051
+ sourceCount: currentTargets.filter((target2) => target2.canOpenEditor).length
5052
+ });
5014
5053
  updateContextOverview(summaryText);
5015
5054
  requestFloatingSurfaceLayout();
5016
5055
  }
@@ -5027,10 +5066,11 @@ function createRuntimeView(document, shortcut, ai = Object.freeze({ enabled: fal
5027
5066
  secondaryActions.hidden = !selected;
5028
5067
  agentPanel.setSelectionVisible(selected);
5029
5068
  externalHandoffPanel?.setSelectionVisible(selected);
5069
+ contextualAskPanel?.setSelectionVisible(selected);
5030
5070
  copyButton.hidden = !previewing;
5031
5071
  backButton.hidden = !previewing;
5032
- title.textContent = previewing ? messages.dialog.previewTitle : messages.dialog.editTitle;
5033
- subtitle.textContent = previewing ? messages.dialog.previewSubtitle : messages.dialog.editSubtitle;
5072
+ title.textContent = previewing ? messages.dialog.previewTitle : contextualAskMode === "ask" && contextualAskTitle.length > 0 ? contextualAskTitle : messages.dialog.editTitle;
5073
+ subtitle.textContent = previewing ? messages.dialog.previewSubtitle : contextualAskMode === "ask" && contextualAskSubtitle.length > 0 ? contextualAskSubtitle : messages.dialog.editSubtitle;
5034
5074
  renderFloatingSurfaceMotion();
5035
5075
  }
5036
5076
  function applyMessages() {
@@ -5165,6 +5205,7 @@ function createRuntimeView(document, shortcut, ai = Object.freeze({ enabled: fal
5165
5205
  agentRevertButton: agentPanel.revertButton,
5166
5206
  agentResetButton: agentPanel.resetButton,
5167
5207
  ...externalHandoffPanel === void 0 ? {} : { externalHandoffPanel },
5208
+ ...contextualAskPanel === void 0 ? {} : { contextualAskPanel },
5168
5209
  renderStatus(status) {
5169
5210
  const inspecting = status === "inspecting";
5170
5211
  if (status === "idle" || inspecting) {
@@ -5238,6 +5279,7 @@ function createRuntimeView(document, shortcut, ai = Object.freeze({ enabled: fal
5238
5279
  agentPanel.setSelectionVisible(false);
5239
5280
  externalHandoffPanel?.setContextReady(false);
5240
5281
  externalHandoffPanel?.setSelectionVisible(false);
5282
+ contextualAskPanel?.setSelectionVisible(false);
5241
5283
  agentPanel.setEditingEnabled(true);
5242
5284
  agentPanel.resetJob();
5243
5285
  dataFlowPanel.resetView();
@@ -5378,6 +5420,7 @@ function createRuntimeView(document, shortcut, ai = Object.freeze({ enabled: fal
5378
5420
  unsubscribeLocale();
5379
5421
  dataFlowPanel.dispose();
5380
5422
  externalHandoffPanel?.dispose();
5423
+ contextualAskPanel?.dispose();
5381
5424
  agentPanel.dispose();
5382
5425
  motionController?.dispose();
5383
5426
  executionIslandView.dispose();
@@ -5407,7 +5450,7 @@ function sourceLocation2(resolution, context, messages) {
5407
5450
  function createSelectionSummary(input, messages) {
5408
5451
  const lines = [
5409
5452
  `SpotPatch: ${input.spotPatchVersion}`,
5410
- `${input.framework === "next" ? "Next.js" : "Vite"}: ${input.frameworkVersion}`,
5453
+ `${{ next: "Next.js", vite: "Vite", astro: "Astro" }[input.framework]}: ${input.frameworkVersion}`,
5411
5454
  `${messages.source}: ${sourceLocation2(input.resolution, input.code, messages)}`,
5412
5455
  `${messages.confidence}: ${input.resolution.source.confidence} (${messages.confidenceLabels[input.resolution.source.confidence]})`,
5413
5456
  `${messages.origin}: ${input.resolution.source.origin}`
@@ -5898,7 +5941,8 @@ function createController(config, dependencies = {}) {
5898
5941
  config.dataFlow.enabled,
5899
5942
  config.externalAgent.enabled,
5900
5943
  config.framework,
5901
- config.sessionId
5944
+ config.sessionId,
5945
+ config.contextualAsk.enabled
5902
5946
  );
5903
5947
  const api = dependencies.api ?? createRuntimeApi({
5904
5948
  apiBase: config.apiBase,
@@ -6101,6 +6145,19 @@ function createController(config, dependencies = {}) {
6101
6145
  (target2) => target2.instruction.trim().length > 0 && target2.elementContext !== void 0 && target2.styles !== void 0 && target2.apiStatus !== "loading"
6102
6146
  );
6103
6147
  }
6148
+ function selectedAskSelection() {
6149
+ const snapshots = targets.flatMap((target2) => {
6150
+ const snapshot = snapshotTarget(target2);
6151
+ return snapshot === void 0 ? [] : [snapshot];
6152
+ });
6153
+ if (snapshots.length === 0 || snapshots.length !== targets.length) {
6154
+ return void 0;
6155
+ }
6156
+ return Object.freeze({
6157
+ locale: view.locale(),
6158
+ targets: snapshots
6159
+ });
6160
+ }
6104
6161
  function selectionSummary() {
6105
6162
  const messages = view.messages().summary;
6106
6163
  return targets.map((target2, index) => {
@@ -6222,6 +6279,7 @@ ${summary}`;
6222
6279
  api.cancelPending();
6223
6280
  agentWorkflow.disposeSelection();
6224
6281
  externalHandoffWorkflow?.cancelPending();
6282
+ contextualAskWorkflow?.cancelPending();
6225
6283
  clearCollectionTimers();
6226
6284
  resizeObserver?.disconnect();
6227
6285
  targets = [];
@@ -6347,6 +6405,27 @@ ${summary}`;
6347
6405
  config.sessionToken,
6348
6406
  browser.window
6349
6407
  ) : void 0;
6408
+ const contextualAskWorkflow = config.contextualAsk.enabled && view.contextualAskPanel !== void 0 ? getContextualAskExtension()?.createWorkflow({
6409
+ ...clipboard === void 0 ? {} : { clipboard },
6410
+ createId,
6411
+ fetch: browser.window.fetch.bind(browser.window),
6412
+ getSelection: selectedAskSelection,
6413
+ onBusyChange(busy) {
6414
+ view.setAgentEditingEnabled(!busy);
6415
+ },
6416
+ onConvert() {
6417
+ view.focusTargetInstruction(activeTargetId);
6418
+ },
6419
+ async onOpenSource(source2) {
6420
+ await api.openEditor({
6421
+ fileId: source2.fileId,
6422
+ line: source2.startLine,
6423
+ column: 1
6424
+ });
6425
+ },
6426
+ panel: view.contextualAskPanel,
6427
+ sessionToken: config.sessionToken
6428
+ }) : void 0;
6350
6429
  async function loadSourceContext(target2, revision) {
6351
6430
  const marker = target2.marker;
6352
6431
  if (marker === void 0) {
@@ -6460,6 +6539,7 @@ ${summary}`;
6460
6539
  previewPrompt = "";
6461
6540
  agentWorkflow.beginSelection();
6462
6541
  workflowSelectionActive = true;
6542
+ contextualAskWorkflow?.beginSelection();
6463
6543
  }
6464
6544
  targetSequence += 1;
6465
6545
  const target2 = {
@@ -6478,6 +6558,9 @@ ${summary}`;
6478
6558
  dataFlowStatus: "idle"
6479
6559
  };
6480
6560
  targets.push(target2);
6561
+ if (!initialSelection) {
6562
+ contextualAskWorkflow?.selectionChanged();
6563
+ }
6481
6564
  activeTargetId = target2.id;
6482
6565
  addingTarget = false;
6483
6566
  const revision = sessionRevision;
@@ -6594,10 +6677,12 @@ ${summary}`;
6594
6677
  pageDataFlowStatus = "idle";
6595
6678
  renderDataFlowView();
6596
6679
  selectionSession.clear();
6680
+ contextualAskWorkflow?.selectionChanged();
6597
6681
  view.announce(view.messages().announcements.allTargetsRemoved);
6598
6682
  return;
6599
6683
  }
6600
6684
  refreshSelectionView();
6685
+ contextualAskWorkflow?.selectionChanged();
6601
6686
  void loadDataFlowReports();
6602
6687
  persistSelection();
6603
6688
  view.announce(view.messages().announcements.targetRemoved);
@@ -6776,6 +6861,7 @@ ${summary}`;
6776
6861
  }
6777
6862
  mounted = true;
6778
6863
  externalHandoffWorkflow?.mount();
6864
+ contextualAskWorkflow?.mount();
6779
6865
  view.renderStatus(state.status);
6780
6866
  browser.document.addEventListener("pointermove", handlePointerMove, true);
6781
6867
  browser.document.addEventListener("click", handleClick, true);
@@ -6827,6 +6913,7 @@ ${summary}`;
6827
6913
  if (selectionOpen && targets.length > 0) {
6828
6914
  transition({ type: "RESTORE" });
6829
6915
  agentWorkflow.beginSelection();
6916
+ contextualAskWorkflow?.beginSelection();
6830
6917
  workflowSelectionActive = true;
6831
6918
  refreshSelectionView(true);
6832
6919
  }
@@ -6843,6 +6930,7 @@ ${summary}`;
6843
6930
  api.dispose();
6844
6931
  agentWorkflow.disposeSelection();
6845
6932
  externalHandoffWorkflow?.dispose();
6933
+ contextualAskWorkflow?.dispose();
6846
6934
  sourceResolver.dispose();
6847
6935
  return;
6848
6936
  }
@@ -6907,6 +6995,7 @@ ${summary}`;
6907
6995
  api.dispose();
6908
6996
  agentWorkflow.disposeSelection();
6909
6997
  externalHandoffWorkflow?.dispose();
6998
+ contextualAskWorkflow?.dispose();
6910
6999
  sourceResolver.dispose();
6911
7000
  view.dispose();
6912
7001
  state = INITIAL_RUNTIME_STATE;
@@ -6922,6 +7011,7 @@ function bootstrapSpotPatch(config) {
6922
7011
  const controller = createController(config);
6923
7012
  target2[RUNTIME_INSTANCE_KEY] = controller;
6924
7013
  controller.mount();
7014
+ return controller;
6925
7015
  }
6926
7016
  export {
6927
7017
  UI_MARKER_ATTRIBUTE,