@canvas-components/print-design-plugin 0.1.6 → 0.1.8

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/react.cjs CHANGED
@@ -998,13 +998,45 @@ function validateListTemplateData(element, data) {
998
998
  );
999
999
  }
1000
1000
 
1001
+ // src/plugins/list/interaction/commands.ts
1002
+ var listCommands = {
1003
+ execute(element, command, payload) {
1004
+ if (element.locked || !payload || typeof payload !== "object") return;
1005
+ const args = payload;
1006
+ const index = args.index;
1007
+ if (!Number.isInteger(index)) return;
1008
+ const at = index;
1009
+ const items = [...element.items];
1010
+ if (command === "remove-item") {
1011
+ if (at < 0 || at >= items.length) return;
1012
+ items.splice(at, 1);
1013
+ } else if (command === "insert-item") {
1014
+ if (at < 0 || at > items.length || typeof args.text !== "string") return;
1015
+ items.splice(at, 0, { text: args.text, checked: false });
1016
+ } else if (command === "update-item") {
1017
+ if (at < 0 || at >= items.length) return;
1018
+ if (args.text !== void 0 && typeof args.text !== "string") return;
1019
+ if (args.checked !== void 0 && typeof args.checked !== "boolean")
1020
+ return;
1021
+ items[at] = {
1022
+ ...items[at],
1023
+ ...args.text === void 0 ? {} : { text: args.text },
1024
+ ...args.checked === void 0 ? {} : { checked: args.checked }
1025
+ };
1026
+ } else return;
1027
+ const next = { ...element, items };
1028
+ return validateListElement(next) ? next : void 0;
1029
+ }
1030
+ };
1031
+
1001
1032
  // src/plugins/list/native.ts
1002
1033
  var listNativePlugin = defineNativePlugin(
1003
1034
  "list",
1004
- "0.1.8",
1035
+ "0.1.9",
1005
1036
  printDesign.definePrintDesignPluginRenderer({
1006
1037
  type: "list",
1007
1038
  validate: validateListElement,
1039
+ commands: listCommands,
1008
1040
  bindingInfo: listBindingInfo,
1009
1041
  validateTemplateData: validateListTemplateData,
1010
1042
  drawCanvas: drawListElement,
@@ -2652,16 +2684,51 @@ function pointToSegmentDistance(point, a, b) {
2652
2684
  return Math.hypot(point.x - a.x - t * dx, point.y - a.y - t * dy);
2653
2685
  }
2654
2686
 
2687
+ // src/plugins/shape/interaction/commands.ts
2688
+ var validPoints = (value) => Array.isArray(value) && value.every(
2689
+ (point) => point && typeof point === "object" && Number.isFinite(point.x) && Number.isFinite(point.y)
2690
+ );
2691
+ var shapeCommands = {
2692
+ execute(element, command, payload) {
2693
+ if (element.locked || !payload || typeof payload !== "object") return;
2694
+ const args = payload;
2695
+ if (!validPoints(args.points)) return;
2696
+ const points = args.points;
2697
+ let next;
2698
+ if (command === "set-polygon-points") {
2699
+ if (!["triangle", "polygon", "star"].includes(element.shape) || points.length < 3)
2700
+ return;
2701
+ next = { ...element, polygonPoints: points };
2702
+ } else if (command === "set-curve-points") {
2703
+ if (!["curve-quadratic", "curve-cubic", "curve-multi"].includes(
2704
+ element.shape
2705
+ ) || points.length < 2)
2706
+ return;
2707
+ next = { ...element, curvePoints: points };
2708
+ } else if (command === "set-path-points") {
2709
+ if (element.shape !== "curve-path") return;
2710
+ if (args.closed !== void 0 && typeof args.closed !== "boolean") return;
2711
+ next = {
2712
+ ...element,
2713
+ pathPoints: points,
2714
+ ...args.closed === void 0 ? {} : { pathClosed: args.closed }
2715
+ };
2716
+ } else return;
2717
+ return validateShapeElement(next) ? next : void 0;
2718
+ }
2719
+ };
2720
+
2655
2721
  // src/plugins/shape/native.ts
2656
2722
  var shapeNativePlugin = defineNativePlugin(
2657
2723
  "shape",
2658
- "0.1.20",
2724
+ "0.1.21",
2659
2725
  printDesign.definePrintDesignPluginRenderer({
2660
2726
  type: "shape",
2661
2727
  dataFields: shapeDataFields,
2662
2728
  bindingInfo: (element) => registeredFieldBindingInfo(element, shapeDataFields),
2663
2729
  validateTemplateData: (element, data) => validateRegisteredFieldBindings(element, shapeDataFields, data),
2664
2730
  validate: validateShapeElement,
2731
+ commands: shapeCommands,
2665
2732
  drawCanvas: drawShapeElement,
2666
2733
  renderHtml: (element, context) => renderShapeHtml(element, context.data),
2667
2734
  hitTest: hitShape,
@@ -3003,13 +3070,42 @@ var brushPointerStroke = {
3003
3070
  }
3004
3071
  };
3005
3072
 
3073
+ // src/plugins/brush/interaction/commands.ts
3074
+ var brushCommands = {
3075
+ execute(element, command, payload) {
3076
+ if (element.locked || !payload || typeof payload !== "object") return;
3077
+ const args = payload;
3078
+ if (command === "append-stroke") {
3079
+ if (!Array.isArray(args.points) || args.points.length < 2) return;
3080
+ const next2 = {
3081
+ ...element,
3082
+ strokes: [
3083
+ ...element.strokes,
3084
+ args.points
3085
+ ]
3086
+ };
3087
+ return validateBrushElement(next2) ? next2 : void 0;
3088
+ }
3089
+ if (command !== "remove-stroke" || !Number.isInteger(args.index)) return;
3090
+ const index = args.index;
3091
+ if (index < 0 || index >= element.strokes.length) return;
3092
+ const next = {
3093
+ ...element,
3094
+ strokes: element.strokes.filter((_, at) => at !== index),
3095
+ strokeStyles: element.strokeStyles?.filter((_, at) => at !== index)
3096
+ };
3097
+ return validateBrushElement(next) ? next : void 0;
3098
+ }
3099
+ };
3100
+
3006
3101
  // src/plugins/brush/native.ts
3007
3102
  var brushNativePlugin = defineNativePlugin(
3008
3103
  "brush",
3009
- "0.1.4",
3104
+ "0.1.5",
3010
3105
  printDesign.definePrintDesignPluginRenderer({
3011
3106
  type: "brush",
3012
3107
  validate: validateBrushElement,
3108
+ commands: brushCommands,
3013
3109
  drawCanvas: drawBrushElement,
3014
3110
  renderHtml: (element) => renderBrushHtml(element),
3015
3111
  hitTest: hitBrush,
@@ -4005,6 +4101,46 @@ function validateConnectorElement(value) {
4005
4101
  const validPoint = (point) => !!point && Number.isFinite(point.x) && Number.isFinite(point.y);
4006
4102
  return element.type === "connector" && (element.lineType === void 0 || ["straight", "curve", "polyline"].includes(element.lineType)) && (element.polylinePoints === void 0 || Array.isArray(element.polylinePoints) && element.polylinePoints.every(validPoint)) && (element.strokeWidth === void 0 || Number.isFinite(element.strokeWidth) && element.strokeWidth >= 0) && (element.textPosition === void 0 || Number.isFinite(element.textPosition) && element.textPosition >= 0 && element.textPosition <= 1);
4007
4103
  }
4104
+
4105
+ // src/plugins/connector/interaction/commands.ts
4106
+ var validEndpoint = (value) => {
4107
+ if (!value || typeof value !== "object" || Array.isArray(value)) return false;
4108
+ const endpoint3 = value;
4109
+ return (endpoint3.elementId === void 0 || typeof endpoint3.elementId === "string") && (endpoint3.anchor === void 0 || typeof endpoint3.anchor === "string" && ([
4110
+ "auto",
4111
+ "top",
4112
+ "right",
4113
+ "bottom",
4114
+ "left",
4115
+ "top-left",
4116
+ "top-right",
4117
+ "bottom-right",
4118
+ "bottom-left"
4119
+ ].includes(endpoint3.anchor) || /^(edge|vertex):\d+$/.test(endpoint3.anchor)));
4120
+ };
4121
+ var connectorCommands = {
4122
+ execute(element, command, payload) {
4123
+ if (element.locked || !payload || typeof payload !== "object") return;
4124
+ const args = payload;
4125
+ if (command === "set-endpoint") {
4126
+ if (args.side !== "start" && args.side !== "end") return;
4127
+ if (!validEndpoint(args.endpoint)) return;
4128
+ const next2 = { ...element, [args.side]: args.endpoint };
4129
+ return validateConnectorElement(next2) ? next2 : void 0;
4130
+ }
4131
+ if (command !== "set-waypoints" || element.lineType !== "polyline")
4132
+ return;
4133
+ if (!Array.isArray(args.points) || !args.points.every(
4134
+ (point) => point && typeof point === "object" && Number.isFinite(point.x) && Number.isFinite(point.y)
4135
+ ))
4136
+ return;
4137
+ const next = {
4138
+ ...element,
4139
+ polylinePoints: args.points
4140
+ };
4141
+ return validateConnectorElement(next) ? next : void 0;
4142
+ }
4143
+ };
4008
4144
  var CONNECTOR_EXPRESSION = /\{\{\s*([\w.[\]-]+)(?:\|(?:date|dateSlash))?\s*\}\}/g;
4009
4145
  function labelPaths(element) {
4010
4146
  return [...(element.text ?? "").matchAll(CONNECTOR_EXPRESSION)].map(
@@ -4025,10 +4161,11 @@ function validateConnectorTemplateData(element, data) {
4025
4161
  // src/plugins/connector/native.ts
4026
4162
  var connectorNativePlugin = defineNativePlugin(
4027
4163
  "connector",
4028
- "0.1.31",
4164
+ "0.1.32",
4029
4165
  printDesign.definePrintDesignPluginRenderer({
4030
4166
  type: "connector",
4031
4167
  validate: validateConnectorElement,
4168
+ commands: connectorCommands,
4032
4169
  bindingInfo: connectorBindingInfo,
4033
4170
  validateTemplateData: validateConnectorTemplateData,
4034
4171
  allowSignedSize: true,
@@ -4617,7 +4754,7 @@ function resolveGridCells(element, data = {}) {
4617
4754
  const background = color(element.backgroundColor) ?? "transparent";
4618
4755
  const selectedBackground = color(element.selectedBackgroundColor);
4619
4756
  const cache = /* @__PURE__ */ new Map();
4620
- const read = (path, index) => {
4757
+ const read2 = (path, index) => {
4621
4758
  if (!path?.trim()) return void 0;
4622
4759
  if (!cache.has(path))
4623
4760
  cache.set(path, printDesign.resolvePrintDesignDataPath(data, path));
@@ -4637,7 +4774,7 @@ function resolveGridCells(element, data = {}) {
4637
4774
  const cell = element.cells?.[index];
4638
4775
  const contentPath = cell?.contentPath?.trim() || element.contentPath;
4639
4776
  const content = (cell?.contentMode !== "static" && (cell?.contentMode === "binding" || !!element.contentPath) ? marker(
4640
- read(contentPath, index),
4777
+ read2(contentPath, index),
4641
4778
  cell?.content && cell.content !== "none" ? cell.content : element.paintMark ?? "x"
4642
4779
  ) : void 0) ?? cell?.content ?? "none";
4643
4780
  return {
@@ -4916,13 +5053,68 @@ function gridDebugRegions(element, context, hitElement = element) {
4916
5053
  return [...cells, ...loops, ...columnLoops];
4917
5054
  }
4918
5055
 
5056
+ // src/plugins/grid/interaction/commands.ts
5057
+ function executeGridCommand(element, command, payload, validate) {
5058
+ if (element.locked || !payload || typeof payload !== "object") return;
5059
+ const args = payload;
5060
+ if (command === "resize-grid") {
5061
+ const rows = args.rows;
5062
+ const columns = args.columns;
5063
+ if (!Number.isInteger(rows) || !Number.isInteger(columns)) return;
5064
+ if (rows < 1 || rows > 50 || columns < 1 || columns > 50)
5065
+ return;
5066
+ const cells2 = Array.from(
5067
+ { length: rows * columns },
5068
+ (_, index2) => {
5069
+ const row = Math.floor(index2 / columns);
5070
+ const column = index2 % columns;
5071
+ return element.cells?.[row * element.columns + column] ?? {};
5072
+ }
5073
+ );
5074
+ const next2 = {
5075
+ ...element,
5076
+ rows,
5077
+ columns,
5078
+ cells: cells2
5079
+ };
5080
+ return validate(next2) ? next2 : void 0;
5081
+ }
5082
+ if (command !== "set-cell") return;
5083
+ const rowIndex = args.rowIndex;
5084
+ const columnIndex = args.columnIndex;
5085
+ if (!Number.isInteger(rowIndex) || !Number.isInteger(columnIndex)) return;
5086
+ if (rowIndex < 0 || rowIndex >= element.rows || columnIndex < 0 || columnIndex >= element.columns)
5087
+ return;
5088
+ const cell = args.cell;
5089
+ if (!cell || typeof cell !== "object" || Array.isArray(cell)) return;
5090
+ const index = rowIndex * element.columns + columnIndex;
5091
+ const cells = Array.from(
5092
+ { length: element.rows * element.columns },
5093
+ (_, at) => ({ ...element.cells?.[at] })
5094
+ );
5095
+ cells[index] = { ...cells[index], ...cell };
5096
+ const next = { ...element, cells };
5097
+ return validate(next) ? next : void 0;
5098
+ }
5099
+ var gridCommands = {
5100
+ execute(element, command, payload) {
5101
+ return executeGridCommand(
5102
+ element,
5103
+ command,
5104
+ payload,
5105
+ (value) => !!value && typeof value === "object" && value.type === "grid" && validateGridSettings(value)
5106
+ );
5107
+ }
5108
+ };
5109
+
4919
5110
  // src/plugins/grid/native.ts
4920
5111
  var gridNativePlugin = defineNativePlugin(
4921
5112
  "grid",
4922
- "0.1.15",
5113
+ "0.1.16",
4923
5114
  printDesign.definePrintDesignPluginRenderer({
4924
5115
  type: "grid",
4925
5116
  validate: validateGridElement,
5117
+ commands: gridCommands,
4926
5118
  validateTemplateData: validateGridTemplateData,
4927
5119
  bindingInfo: getGridBindingInfo,
4928
5120
  drawCanvas: drawGridElement,
@@ -5233,10 +5425,18 @@ function coordinateDebugRegions(element, context) {
5233
5425
  // src/plugins/coordinate/native.ts
5234
5426
  var coordinateNativePlugin = defineNativePlugin(
5235
5427
  "coordinate",
5236
- "0.1.15",
5428
+ "0.1.16",
5237
5429
  printDesign.definePrintDesignPluginRenderer({
5238
5430
  type: "coordinate",
5239
5431
  validate: validateCoordinateElement,
5432
+ commands: {
5433
+ execute: (element, command, payload) => executeGridCommand(
5434
+ element,
5435
+ command,
5436
+ payload,
5437
+ validateCoordinateElement
5438
+ )
5439
+ },
5240
5440
  validateTemplateData: validateGridTemplateData,
5241
5441
  bindingInfo: getGridBindingInfo,
5242
5442
  drawCanvas: drawCoordinateElement,
@@ -5535,13 +5735,13 @@ function resolveFlowItems(element, data = {}) {
5535
5735
  if (typeof value !== "object" || Array.isArray(value))
5536
5736
  return [{ content: String(value) }];
5537
5737
  const row = value;
5538
- const read = (key) => printDesign.resolvePrintDesignDataPath(row, fields[key] || key);
5539
- const content = read("content");
5540
- const title = read("title");
5541
- const color2 = read("color");
5542
- const position = read("position");
5543
- const loading = read("loading");
5544
- const icon = read("icon");
5738
+ const read2 = (key) => printDesign.resolvePrintDesignDataPath(row, fields[key] || key);
5739
+ const content = read2("content");
5740
+ const title = read2("title");
5741
+ const color2 = read2("color");
5742
+ const position = read2("position");
5743
+ const loading = read2("loading");
5744
+ const icon = read2("icon");
5545
5745
  return [
5546
5746
  {
5547
5747
  content: content == null || typeof content === "object" ? "" : String(content),
@@ -5733,17 +5933,48 @@ function validateFlowTemplateData(element, data) {
5733
5933
  return [];
5734
5934
  }
5735
5935
 
5936
+ // src/plugins/flow/interaction/commands.ts
5937
+ var flowCommands = {
5938
+ execute(element, command, payload) {
5939
+ if (element.locked || element.dataMode === "binding" || !payload || typeof payload !== "object")
5940
+ return;
5941
+ const args = payload;
5942
+ const index = args.index;
5943
+ if (!Number.isInteger(index)) return;
5944
+ const at = index;
5945
+ if (command === "remove-item") {
5946
+ if (at < 0 || at >= element.items.length) return;
5947
+ return { ...element, items: element.items.filter((_, i) => i !== at) };
5948
+ }
5949
+ const item = args.item;
5950
+ if (!item || typeof item !== "object" || Array.isArray(item)) return;
5951
+ const items = [...element.items];
5952
+ if (command === "insert-item") {
5953
+ if (at < 0 || at > items.length) return;
5954
+ items.splice(at, 0, item);
5955
+ } else if (command === "update-item") {
5956
+ if (at < 0 || at >= items.length) return;
5957
+ items[at] = { ...items[at], ...item };
5958
+ } else return;
5959
+ const next = { ...element, items };
5960
+ return validateFlowElement(next) ? next : void 0;
5961
+ }
5962
+ };
5963
+
5736
5964
  // src/plugins/flow/native.ts
5737
5965
  var flowNativePlugin = defineNativePlugin(
5738
5966
  "flow",
5739
- "0.1.6",
5967
+ "0.1.7",
5740
5968
  printDesign.definePrintDesignPluginRenderer({
5741
5969
  type: "flow",
5742
5970
  validate: validateFlowElement,
5971
+ commands: flowCommands,
5743
5972
  validateTemplateData: validateFlowTemplateData,
5744
5973
  bindingInfo: (element) => ({
5745
5974
  bound: (element.dataMode ?? element.dataConfig?.mode) === "binding",
5746
- paths: (element.dataMode ?? element.dataConfig?.mode) === "binding" ? [element.dataPath ?? element.dataConfig?.bindings?.items ?? ""].filter(Boolean) : []
5975
+ paths: (element.dataMode ?? element.dataConfig?.mode) === "binding" ? [
5976
+ element.dataPath ?? element.dataConfig?.bindings?.items ?? ""
5977
+ ].filter(Boolean) : []
5747
5978
  }),
5748
5979
  drawCanvas: drawFlowElement,
5749
5980
  renderHtml: (element, context) => renderFlowHtml(element, context.data)
@@ -6459,6 +6690,19 @@ function fitImageToPage(image, page, current2) {
6459
6690
  return { x, y, width, height };
6460
6691
  }
6461
6692
 
6693
+ // src/plugins/image/interaction/commands.ts
6694
+ var imageCommands = {
6695
+ execute(element, command, payload) {
6696
+ if (element.locked) return;
6697
+ if (command === "clear-crop") return { ...element, crop: void 0 };
6698
+ if (command !== "set-crop" || !payload || typeof payload !== "object")
6699
+ return;
6700
+ const crop = payload;
6701
+ const next = { ...element, crop };
6702
+ return validateImageElement(next) ? next : void 0;
6703
+ }
6704
+ };
6705
+
6462
6706
  // src/plugins/image/native.ts
6463
6707
  var componentCropBehavior = {
6464
6708
  source: (element) => element.src,
@@ -6479,7 +6723,7 @@ var componentCropBehavior = {
6479
6723
  };
6480
6724
  var imageNativePlugin = defineNativePlugin(
6481
6725
  "image",
6482
- "0.1.16",
6726
+ "0.1.17",
6483
6727
  printDesign.definePrintDesignPluginRenderer({
6484
6728
  type: "image",
6485
6729
  dataFields: imageDataFields,
@@ -6488,6 +6732,7 @@ var imageNativePlugin = defineNativePlugin(
6488
6732
  replaceResourceUri: (element, uri, replacement) => element.src === uri ? { ...element, src: replacement } : element,
6489
6733
  validateTemplateData: validateImageTemplateData,
6490
6734
  validate: validateImageElement,
6735
+ commands: imageCommands,
6491
6736
  drawCanvas: drawImageElement,
6492
6737
  prepareCanvas: (element, { signal }) => prepareImage(element.src, signal),
6493
6738
  needsCanvasPreparation: (element) => Boolean(element.src && !getLoadedImageSize(element.src)),
@@ -6904,13 +7149,58 @@ function renderChartHtml(element, data) {
6904
7149
  });
6905
7150
  }
6906
7151
 
7152
+ // src/plugins/chart/interaction/commands.ts
7153
+ var chartCommands = {
7154
+ execute(element, command, payload) {
7155
+ if (element.locked || !payload || typeof payload !== "object") return;
7156
+ const args = payload;
7157
+ const chartData = readChartData(element);
7158
+ if (command === "set-categories") {
7159
+ if (!Array.isArray(args.categories) || !args.categories.every((item) => typeof item === "string"))
7160
+ return;
7161
+ const categories = args.categories;
7162
+ const next2 = {
7163
+ ...element,
7164
+ chartData: {
7165
+ ...chartData,
7166
+ categories,
7167
+ series: chartData.series.map((series2) => ({
7168
+ ...series2,
7169
+ values: categories.map((_, index2) => series2.values[index2] ?? 0)
7170
+ }))
7171
+ }
7172
+ };
7173
+ return validateChartElement(next2) ? next2 : void 0;
7174
+ }
7175
+ if (command !== "set-series") return;
7176
+ const index = args.index;
7177
+ if (!Number.isInteger(index) || index < 0 || index > chartData.series.length)
7178
+ return;
7179
+ if (typeof args.name !== "string" || !Array.isArray(args.values) || args.values.length !== chartData.categories.length || !args.values.every(
7180
+ (value) => typeof value === "number" && Number.isFinite(value)
7181
+ ))
7182
+ return;
7183
+ if (["pie", "gauge"].includes(element.chartType) && index > 0)
7184
+ return;
7185
+ const series = [...chartData.series];
7186
+ series[index] = {
7187
+ name: args.name,
7188
+ values: args.values,
7189
+ ...typeof args.field === "string" ? { field: args.field } : {}
7190
+ };
7191
+ const next = { ...element, chartData: { ...chartData, series } };
7192
+ return validateChartElement(next) ? next : void 0;
7193
+ }
7194
+ };
7195
+
6907
7196
  // src/plugins/chart/native.ts
6908
7197
  var chartNativePlugin = defineNativePlugin(
6909
7198
  "chart",
6910
- "0.1.8",
7199
+ "0.1.9",
6911
7200
  printDesign.definePrintDesignPluginRenderer({
6912
7201
  type: "chart",
6913
7202
  validate: validateChartElement,
7203
+ commands: chartCommands,
6914
7204
  validateTemplateData: validateChartTemplateData,
6915
7205
  bindingInfo: (element) => ({
6916
7206
  bound: element.chartData?.mode === "binding",
@@ -10755,7 +11045,7 @@ function validateTableTemplateData(element, data) {
10755
11045
  // src/plugins/table/native.ts
10756
11046
  var tableNativePlugin = defineNativePlugin(
10757
11047
  "table",
10758
- "0.1.68",
11048
+ "0.1.69",
10759
11049
  printDesign.definePrintDesignPluginRenderer({
10760
11050
  type: "table",
10761
11051
  validate: validateTableElement,
@@ -11088,6 +11378,41 @@ var pivotTableBoundaryResize = {
11088
11378
  }
11089
11379
  };
11090
11380
 
11381
+ // src/plugins/pivot-table/interaction/commands.ts
11382
+ var areas = ["filter", "column", "row", "value"];
11383
+ var pivotTableCommands = {
11384
+ execute(element, command, payload) {
11385
+ if (element.locked || !payload || typeof payload !== "object") return;
11386
+ const args = payload;
11387
+ const fieldKey = args.fieldKey;
11388
+ if (typeof fieldKey !== "string" || !element.fields.some((field) => field.key === fieldKey))
11389
+ return;
11390
+ if (command === "remove-field")
11391
+ return {
11392
+ ...element,
11393
+ layout: removePivotField(element.layout, fieldKey)
11394
+ };
11395
+ if (command !== "move-field" || !areas.includes(args.area))
11396
+ return;
11397
+ const index = args.index;
11398
+ if (index !== void 0 && (!Number.isInteger(index) || index < 0))
11399
+ return;
11400
+ const sourceArea = args.sourceArea;
11401
+ if (sourceArea !== void 0 && !areas.includes(sourceArea))
11402
+ return;
11403
+ return {
11404
+ ...element,
11405
+ layout: movePivotField(
11406
+ element.layout,
11407
+ fieldKey,
11408
+ args.area,
11409
+ index,
11410
+ sourceArea
11411
+ )
11412
+ };
11413
+ }
11414
+ };
11415
+
11091
11416
  // src/plugins/pivot-table/model.ts
11092
11417
  function validatePivotTableElement(value) {
11093
11418
  if (!value || typeof value !== "object") return false;
@@ -11101,11 +11426,12 @@ function validatePivotTableElement(value) {
11101
11426
  // src/plugins/pivot-table/native.ts
11102
11427
  var pivotTableNativePlugin = defineNativePlugin(
11103
11428
  "pivotTable",
11104
- "0.1.18",
11429
+ "0.1.19",
11105
11430
  printDesign.definePrintDesignPluginRenderer({
11106
11431
  type: "pivotTable",
11107
11432
  htmlCss: tableHtmlCss,
11108
11433
  validate: validatePivotTableElement,
11434
+ commands: pivotTableCommands,
11109
11435
  validateTemplateData: validatePivotTemplateData,
11110
11436
  bindingInfo: (element) => ({
11111
11437
  bound: element.dataMode === "binding",
@@ -11616,13 +11942,49 @@ function ganttMarkup(element, data, pageNumber) {
11616
11942
  return `<svg class="pd-media" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${width} ${height}" preserveAspectRatio="none"><rect width="${width}" height="${height}" fill="${printDesign.cssColor(theme.backgroundColor, "transparent")}"/>${header > 0 ? `<rect width="${width}" height="${header}" fill="${printDesign.cssColor(theme.headerBackgroundColor, "transparent")}"/>` : ""}${ticks}${taskSplit}${headerEdges}${headerTitle}${maskedDependencies}${bars}${frame}</svg>`;
11617
11943
  }
11618
11944
 
11945
+ // src/plugins/gantt/interaction/commands.ts
11946
+ var ganttCommands = {
11947
+ execute(element, command, payload) {
11948
+ if (element.locked || element.dataMode === "binding" || !payload || typeof payload !== "object")
11949
+ return;
11950
+ const args = payload;
11951
+ const tasks = [...element.tasks];
11952
+ if (command === "insert-task") {
11953
+ const index = args.index;
11954
+ if (!Number.isInteger(index) || index < 0 || index > tasks.length)
11955
+ return;
11956
+ if (!args.task || typeof args.task !== "object" || Array.isArray(args.task))
11957
+ return;
11958
+ const task = args.task;
11959
+ if (tasks.some((existing) => existing.id === task.id)) return;
11960
+ tasks.splice(index, 0, task);
11961
+ } else {
11962
+ const taskId = args.taskId;
11963
+ if (typeof taskId !== "string") return;
11964
+ const index = tasks.findIndex((task) => task.id === taskId);
11965
+ if (index < 0) return;
11966
+ if (command === "remove-task") tasks.splice(index, 1);
11967
+ else if (command === "update-task") {
11968
+ if (!args.patch || typeof args.patch !== "object" || Array.isArray(args.patch))
11969
+ return;
11970
+ const patch = args.patch;
11971
+ if (patch.id !== void 0 || patch.tasks !== void 0) return;
11972
+ tasks[index] = { ...tasks[index], ...patch };
11973
+ } else return;
11974
+ }
11975
+ const next = { ...element, tasks };
11976
+ return validateGanttElement(next) ? next : void 0;
11977
+ }
11978
+ };
11979
+
11619
11980
  // src/plugins/gantt/native.ts
11620
11981
  var ganttNativePlugin = defineNativePlugin(
11621
11982
  "gantt",
11622
- "0.1.6",
11983
+ "0.1.7",
11623
11984
  printDesign.definePrintDesignPluginRenderer({
11624
11985
  type: "gantt",
11625
11986
  validate: validateGanttElement,
11987
+ commands: ganttCommands,
11626
11988
  validateTemplateData: validateGanttTemplateData,
11627
11989
  bindingInfo: (element) => ({
11628
11990
  bound: element.dataMode === "binding",
@@ -11943,6 +12305,20 @@ var textPlugin = defineBuiltinReactPlugin(textNativePlugin, {
11943
12305
  var listFactory = {
11944
12306
  type: "list",
11945
12307
  label: "\u5217\u8868",
12308
+ agentCommands: [
12309
+ {
12310
+ name: "insert-item",
12311
+ description: "\u5728\u5217\u8868\u6307\u5B9A\u4F4D\u7F6E\u63D2\u5165\u9879\u3002payload: { index: 0 \u8D77\u59CB\u63D2\u5165\u4F4D\u7F6E, text: \u9879\u6587\u5B57 }\u3002"
12312
+ },
12313
+ {
12314
+ name: "update-item",
12315
+ description: "\u4FEE\u6539\u5217\u8868\u9879\u3002payload: { index: 0 \u8D77\u59CB\u9879\u4F4D\u7F6E, text?: \u9879\u6587\u5B57, checked?: \u662F\u5426\u9009\u4E2D }\u3002"
12316
+ },
12317
+ {
12318
+ name: "remove-item",
12319
+ description: "\u79FB\u9664\u5217\u8868\u9879\u3002payload: { index: 0 \u8D77\u59CB\u9879\u4F4D\u7F6E }\u3002"
12320
+ }
12321
+ ],
11946
12322
  showDataPanel: false,
11947
12323
  tourFields: () => [],
11948
12324
  acceptsPreset: (preset) => ["ordered", "unordered", "radio", "checkbox"].includes(preset),
@@ -12390,6 +12766,20 @@ var watermarkPlugin = defineBuiltinReactPlugin(watermarkNativePlugin, {
12390
12766
  var shapeFactory = {
12391
12767
  type: "shape",
12392
12768
  label: "\u56FE\u5F62",
12769
+ agentCommands: [
12770
+ {
12771
+ name: "set-polygon-points",
12772
+ description: "\u8BBE\u7F6E\u4E09\u89D2\u5F62\u3001\u591A\u8FB9\u5F62\u6216\u661F\u5F62\u9876\u70B9\u3002payload: { points: \u81F3\u5C11 3 \u4E2A { x, y } \u5F52\u4E00\u5316\u5750\u6807 }\u3002"
12773
+ },
12774
+ {
12775
+ name: "set-curve-points",
12776
+ description: "\u8BBE\u7F6E\u4E8C\u6B21\u3001\u4E09\u6B21\u6216\u591A\u6BB5\u66F2\u7EBF\u63A7\u5236\u70B9\u3002payload: { points: \u81F3\u5C11 2 \u4E2A { x, y } \u5F52\u4E00\u5316\u5750\u6807 }\u3002"
12777
+ },
12778
+ {
12779
+ name: "set-path-points",
12780
+ description: "\u8BBE\u7F6E\u81EA\u5B9A\u4E49\u8DEF\u5F84\u8282\u70B9\u3002payload: { points: { x, y } \u5F52\u4E00\u5316\u5750\u6807\u6570\u7EC4, closed?: \u662F\u5426\u95ED\u5408 }\u3002"
12781
+ }
12782
+ ],
12393
12783
  acceptsPreset: (preset) => [
12394
12784
  "triangle",
12395
12785
  "rect",
@@ -12946,6 +13336,16 @@ function BrushToolbarButton({
12946
13336
  var brushFactory = {
12947
13337
  type: "brush",
12948
13338
  label: "\u753B\u7B14",
13339
+ agentCommands: [
13340
+ {
13341
+ name: "append-stroke",
13342
+ description: "\u8FFD\u52A0\u4E00\u7B14\u3002payload: { points: \u81F3\u5C11\u4E24\u4E2A { x, y, pressure?: 0 \u5230 1 } \u5F52\u4E00\u5316\u5750\u6807 }\u3002"
13343
+ },
13344
+ {
13345
+ name: "remove-stroke",
13346
+ description: "\u5220\u9664\u6307\u5B9A\u7B14\u753B\u5E76\u540C\u6B65\u5BF9\u5E94\u6837\u5F0F\u3002payload: { index: 0 \u8D77\u59CB\u7B14\u753B\u4F4D\u7F6E }\u3002"
13347
+ }
13348
+ ],
12949
13349
  showDataPanel: false,
12950
13350
  tourFields: () => [],
12951
13351
  create: createBrushElement,
@@ -13045,6 +13445,16 @@ var brushPlugin = defineBuiltinReactPlugin(brushNativePlugin, {
13045
13445
  var connectorFactory = {
13046
13446
  type: "connector",
13047
13447
  label: "\u8FDE\u63A5\u7EBF",
13448
+ agentCommands: [
13449
+ {
13450
+ name: "set-endpoint",
13451
+ description: "\u5C06\u8FDE\u63A5\u7EBF\u8D77\u70B9\u6216\u7EC8\u70B9\u8FDE\u63A5\u5230\u5DF2\u6709\u5143\u7D20\u3002payload: { side: start|end, endpoint: { elementId?: \u76EE\u6807\u5143\u7D20 ID, anchor?: auto|top|right|bottom|left|top-left|top-right|bottom-right|bottom-left|edge:\u7D22\u5F15|vertex:\u7D22\u5F15 } }\u3002"
13452
+ },
13453
+ {
13454
+ name: "set-waypoints",
13455
+ description: "\u8BBE\u7F6E\u6298\u7EBF\u4E2D\u95F4\u8DEF\u5F84\u70B9\uFF0C\u4EC5\u9002\u7528\u4E8E lineType=polyline\u3002payload: { points: \u9875\u9762\u6BEB\u7C73\u5750\u6807\u6570\u7EC4 [{ x, y }] }\u3002"
13456
+ }
13457
+ ],
13048
13458
  create: (preset = "bar") => {
13049
13459
  const common = createCommonElementDefaults();
13050
13460
  const type = "connector";
@@ -13402,6 +13812,16 @@ var rulerPlugin = defineBuiltinReactPlugin(rulerNativePlugin, {
13402
13812
  var gridFactory = {
13403
13813
  type: "grid",
13404
13814
  label: "\u7F51\u683C",
13815
+ agentCommands: [
13816
+ {
13817
+ name: "resize-grid",
13818
+ description: "\u8C03\u6574\u7F51\u683C\u884C\u5217\u6570\uFF0C\u4FDD\u7559\u91CD\u53E0\u533A\u57DF\u7684\u5355\u5143\u683C\u3002payload: { rows: 1 \u5230 50 \u7684\u6574\u6570, columns: 1 \u5230 50 \u7684\u6574\u6570 }\u3002"
13819
+ },
13820
+ {
13821
+ name: "set-cell",
13822
+ description: "\u66F4\u65B0\u6307\u5B9A\u7F51\u683C\u5355\u5143\u683C\u3002payload: { rowIndex: 0 \u8D77\u59CB\u884C, columnIndex: 0 \u8D77\u59CB\u5217, cell: { content?: none|x|*, contentMode?: static|binding, contentPath?: \u5B57\u7B26\u4E32, backgroundColor?: \u5B57\u7B26\u4E32 } }\u3002"
13823
+ }
13824
+ ],
13405
13825
  showDataPanel: false,
13406
13826
  tourFields: (element) => element.type === "grid" ? [
13407
13827
  { key: "rows", label: "\u884C\u6570", value: element.rows },
@@ -13644,6 +14064,16 @@ var gridPlugin = defineBuiltinReactPlugin(gridNativePlugin, {
13644
14064
  var coordinateFactory = {
13645
14065
  type: "coordinate",
13646
14066
  label: "\u5750\u6807\u7F51\u683C",
14067
+ agentCommands: [
14068
+ {
14069
+ name: "resize-grid",
14070
+ description: "\u8C03\u6574\u5750\u6807\u7F51\u683C\u884C\u5217\u6570\uFF0C\u4FDD\u7559\u91CD\u53E0\u533A\u57DF\u5355\u5143\u683C\u3002payload: { rows: 1 \u5230 50 \u7684\u6574\u6570, columns: 1 \u5230 50 \u7684\u6574\u6570 }\u3002"
14071
+ },
14072
+ {
14073
+ name: "set-cell",
14074
+ description: "\u66F4\u65B0\u5750\u6807\u7F51\u683C\u5355\u5143\u683C\u3002payload: { rowIndex: 0 \u8D77\u59CB\u884C, columnIndex: 0 \u8D77\u59CB\u5217, cell: { content?: none|x|*, contentMode?: static|binding, contentPath?: \u5B57\u7B26\u4E32, backgroundColor?: \u5B57\u7B26\u4E32 } }\u3002"
14075
+ }
14076
+ ],
13647
14077
  showDataPanel: false,
13648
14078
  tourFields: (element) => element.type === "coordinate" ? [
13649
14079
  { key: "rows", label: "\u884C\u6570", value: element.rows },
@@ -14014,6 +14444,20 @@ var progressPlugin = defineBuiltinReactPlugin(progressNativePlugin, {
14014
14444
  var flowFactory = {
14015
14445
  type: "flow",
14016
14446
  label: "\u6D41\u7A0B\u56FE",
14447
+ agentCommands: [
14448
+ {
14449
+ name: "insert-item",
14450
+ description: "\u5728\u9759\u6001\u6D41\u7A0B\u6307\u5B9A\u4F4D\u7F6E\u63D2\u5165\u8282\u70B9\u3002payload: { index: 0 \u8D77\u59CB\u63D2\u5165\u4F4D\u7F6E, item: { content: \u5B57\u7B26\u4E32, title?: \u5B57\u7B26\u4E32, color?: \u5B57\u7B26\u4E32, position?: start|end, loading?: \u5E03\u5C14\u503C, icon?: circle|check|clock|cross } }\u3002"
14451
+ },
14452
+ {
14453
+ name: "update-item",
14454
+ description: "\u4FEE\u6539\u9759\u6001\u6D41\u7A0B\u8282\u70B9\u3002payload: { index: 0 \u8D77\u59CB\u8282\u70B9\u4F4D\u7F6E, item: \u9700\u4FEE\u6539\u7684\u8282\u70B9\u5B57\u6BB5 }\u3002"
14455
+ },
14456
+ {
14457
+ name: "remove-item",
14458
+ description: "\u79FB\u9664\u9759\u6001\u6D41\u7A0B\u8282\u70B9\u3002payload: { index: 0 \u8D77\u59CB\u8282\u70B9\u4F4D\u7F6E }\u3002"
14459
+ }
14460
+ ],
14017
14461
  showDataPanel: false,
14018
14462
  tourFields: () => [],
14019
14463
  create: (preset = "bar") => {
@@ -14396,6 +14840,16 @@ function placeExternalImage(image, point, page, index = 0) {
14396
14840
  var imageFactory = {
14397
14841
  type: "image",
14398
14842
  label: "\u56FE\u7247",
14843
+ agentCommands: [
14844
+ {
14845
+ name: "set-crop",
14846
+ description: "\u8BBE\u7F6E\u56FE\u7247\u88C1\u526A\u533A\u57DF\u3002payload: { x, y, width, height }\uFF0C\u5747\u4E3A\u539F\u56FE\u5BBD\u9AD8\u7684 0 \u5230 1 \u6BD4\u4F8B\uFF0C\u533A\u57DF\u5FC5\u987B\u5728\u539F\u56FE\u5185\uFF1B\u53EF\u9009 sourceWidth\u3001sourceHeight \u4E3A\u539F\u56FE\u50CF\u7D20\u5C3A\u5BF8\u3002"
14847
+ },
14848
+ {
14849
+ name: "clear-crop",
14850
+ description: "\u79FB\u9664\u56FE\u7247\u88C1\u526A\uFF0C\u663E\u793A\u5B8C\u6574\u56FE\u7247\uFF1Bpayload \u4F20\u7A7A\u5BF9\u8C61\u3002"
14851
+ }
14852
+ ],
14399
14853
  dataFields: imageDataFields,
14400
14854
  staticFieldPatch: (_element, key, value) => key === "src" ? { src: String(value), crop: void 0 } : { [key]: value },
14401
14855
  externalDrop: {
@@ -14836,6 +15290,16 @@ function createChartPreset(id) {
14836
15290
  var chartFactory = {
14837
15291
  type: "chart",
14838
15292
  label: "\u56FE\u8868",
15293
+ agentCommands: [
15294
+ {
15295
+ name: "set-categories",
15296
+ description: "\u8BBE\u7F6E\u56FE\u8868\u9759\u6001\u5206\u7C7B\u6216\u9ED8\u8BA4\u5206\u7C7B\uFF0C\u5E76\u4F7F\u5404\u7CFB\u5217\u6570\u503C\u957F\u5EA6\u5339\u914D\u3002payload: { categories: \u5B57\u7B26\u4E32\u6570\u7EC4 }\u3002"
15297
+ },
15298
+ {
15299
+ name: "set-series",
15300
+ description: "\u66F4\u65B0\u6307\u5B9A\u6570\u503C\u7CFB\u5217\uFF0C\u4E5F\u53EF\u5728\u672B\u5C3E\u65B0\u589E\u3002payload: { index: 0 \u8D77\u59CB\u7CFB\u5217\u4F4D\u7F6E, name: \u7CFB\u5217\u540D\u79F0, values: \u4E0E categories \u7B49\u957F\u7684\u6709\u9650\u6570\u5B57\u6570\u7EC4, field?: \u7ED1\u5B9A\u5B57\u6BB5\u8DEF\u5F84 }\uFF1B\u997C\u56FE\u548C\u4EEA\u8868\u76D8\u4EC5\u652F\u6301\u7D22\u5F15 0\u3002"
15301
+ }
15302
+ ],
14839
15303
  showDataPanel: false,
14840
15304
  acceptsPreset: (preset) => chartPresets.some((item) => item.id === preset),
14841
15305
  create: (preset = "bar") => {
@@ -15121,6 +15585,24 @@ var chartPlugin = defineBuiltinReactPlugin(chartNativePlugin, {
15121
15585
  var tableFactory = {
15122
15586
  type: "table",
15123
15587
  label: "\u8868\u683C",
15588
+ agentCommands: [
15589
+ {
15590
+ name: "insert-row",
15591
+ description: "\u5728\u9759\u6001\u8868\u683C\u7684 rowIndex \u884C\u524D\u63D2\u5165\u884C\uFF1Bafter=true \u65F6\u63D2\u5728\u884C\u540E\u3002"
15592
+ },
15593
+ {
15594
+ name: "insert-column",
15595
+ description: "\u5728 columnIndex \u5217\u524D\u63D2\u5165\u5217\uFF1Bafter=true \u65F6\u63D2\u5728\u5217\u540E\u3002"
15596
+ },
15597
+ {
15598
+ name: "merge-body",
15599
+ description: "\u5408\u5E76\u8868\u4F53\u5355\u5143\u683C\uFF1B\u4F20 rowIndex\u3001columnIndex\u3001rowSpan\u3001colSpan\u3002"
15600
+ },
15601
+ {
15602
+ name: "merge-header",
15603
+ description: "\u5408\u5E76\u8868\u5934\u5355\u5143\u683C\uFF1B\u4F20 rowIndex\u3001columnIndex\u3001rowSpan\u3001colSpan\u3002"
15604
+ }
15605
+ ],
15124
15606
  defaultOverflowPolicy: "split",
15125
15607
  showDataPanel: false,
15126
15608
  tourFields: (element) => {
@@ -19268,6 +19750,16 @@ var tablePlugin = defineBuiltinReactPlugin(tableNativePlugin, {
19268
19750
  var pivotTableFactory = {
19269
19751
  type: "pivotTable",
19270
19752
  label: "\u900F\u89C6\u8868",
19753
+ agentCommands: [
19754
+ {
19755
+ name: "move-field",
19756
+ description: "\u79FB\u52A8\u900F\u89C6\u5B57\u6BB5\u3002payload: { fieldKey: \u5DF2\u6709\u5B57\u6BB5 key, area: filter|column|row|value, index?: \u4ECE 0 \u5F00\u59CB\u7684\u76EE\u6807\u4F4D\u7F6E, sourceArea?: \u539F\u533A\u57DF }\u3002"
19757
+ },
19758
+ {
19759
+ name: "remove-field",
19760
+ description: "\u4ECE\u900F\u89C6\u5E03\u5C40\u7684\u6240\u6709\u533A\u57DF\u79FB\u9664\u5B57\u6BB5\uFF0C\u4E0D\u5220\u9664\u5B57\u6BB5\u5B9A\u4E49\u3002payload: { fieldKey: \u5DF2\u6709\u5B57\u6BB5 key }\u3002"
19761
+ }
19762
+ ],
19271
19763
  defaultOverflowPolicy: "split",
19272
19764
  showDataPanel: false,
19273
19765
  tourFields: (element) => {
@@ -20039,6 +20531,20 @@ var pivotTablePlugin = defineBuiltinReactPlugin(
20039
20531
  var ganttFactory = {
20040
20532
  type: "gantt",
20041
20533
  label: "\u7518\u7279\u56FE",
20534
+ agentCommands: [
20535
+ {
20536
+ name: "insert-task",
20537
+ description: "\u5728\u9759\u6001\u7518\u7279\u56FE\u9876\u5C42\u4EFB\u52A1\u5217\u8868\u63D2\u5165\u4EFB\u52A1\u3002payload: { index: 0 \u8D77\u59CB\u63D2\u5165\u4F4D\u7F6E, task: { id: \u552F\u4E00\u5B57\u7B26\u4E32, title: \u5B57\u7B26\u4E32, start?: \u65E5\u671F, end?: \u65E5\u671F, progress?: 0 \u5230 100, ... } }\u3002"
20538
+ },
20539
+ {
20540
+ name: "update-task",
20541
+ description: "\u4FEE\u6539\u9876\u5C42\u4EFB\u52A1\uFF0C\u4E0D\u80FD\u4FEE\u6539 id \u6216\u5D4C\u5957 tasks\u3002payload: { taskId: \u4EFB\u52A1 id, patch: { title?, start?, end?, progress?, color?, progressColor?, dependencies? } }\u3002"
20542
+ },
20543
+ {
20544
+ name: "remove-task",
20545
+ description: "\u79FB\u9664\u9759\u6001\u7518\u7279\u56FE\u9876\u5C42\u4EFB\u52A1\u3002payload: { taskId: \u4EFB\u52A1 id }\u3002"
20546
+ }
20547
+ ],
20042
20548
  showDataPanel: false,
20043
20549
  tourFields: (element) => {
20044
20550
  if (element.type !== "gantt") return [];
@@ -21877,6 +22383,1613 @@ var pluginmarketTool = {
21877
22383
  render: (context) => /* @__PURE__ */ jsxRuntime.jsx(reactPrintDesign.PluginMarketTool, { ...context })
21878
22384
  };
21879
22385
 
22386
+ // src/ai-chat/persistence/panel-widths.ts
22387
+ var WIDTHS_KEY = "canvas-components-print-design-ai-chat-widths";
22388
+ function normalizePrintDesignAiChatPanelWidths(value) {
22389
+ const min = Number.isFinite(value?.min) ? Math.max(240, Math.min(1e3, Math.round(value.min))) : 280;
22390
+ const max = Number.isFinite(value?.max) ? Math.max(min, Math.min(1600, Math.round(value.max))) : Math.max(min, 640);
22391
+ const current2 = Number.isFinite(value?.current) ? Math.max(min, Math.min(max, Math.round(value.current))) : Math.max(min, Math.min(max, 360));
22392
+ return { min, max, current: current2 };
22393
+ }
22394
+ function readPrintDesignAiChatPanelWidths() {
22395
+ try {
22396
+ const raw = globalThis.localStorage?.getItem(WIDTHS_KEY);
22397
+ return raw ? normalizePrintDesignAiChatPanelWidths(
22398
+ JSON.parse(raw)
22399
+ ) : null;
22400
+ } catch {
22401
+ return null;
22402
+ }
22403
+ }
22404
+ function savePrintDesignAiChatPanelWidths(value) {
22405
+ try {
22406
+ globalThis.localStorage?.setItem(
22407
+ WIDTHS_KEY,
22408
+ JSON.stringify(normalizePrintDesignAiChatPanelWidths(value))
22409
+ );
22410
+ } catch {
22411
+ }
22412
+ }
22413
+
22414
+ // src/ai-chat/model/reasoning-effort.ts
22415
+ var reasoningEffortOptions = [
22416
+ { label: "\u9ED8\u8BA4", value: "" },
22417
+ { label: "\u4F4E", value: "low" },
22418
+ { label: "\u4E2D", value: "medium" },
22419
+ { label: "\u9AD8", value: "high" }
22420
+ ];
22421
+ function parseReasoningEffort(value) {
22422
+ return value === "low" || value === "medium" || value === "high" ? value : void 0;
22423
+ }
22424
+
22425
+ // src/ai-chat/model/connection-profiles.ts
22426
+ function profileId() {
22427
+ return globalThis.crypto?.randomUUID?.() ?? `connection-${Date.now()}-${Math.random().toString(36).slice(2)}`;
22428
+ }
22429
+ function createPrintDesignAiChatProfile(defaults2 = {}) {
22430
+ return {
22431
+ id: profileId(),
22432
+ name: "",
22433
+ baseUrl: defaults2.baseUrl ?? "",
22434
+ key: defaults2.key ?? "",
22435
+ model: defaults2.model ?? "",
22436
+ reasoningEffort: parseReasoningEffort(defaults2.reasoningEffort)
22437
+ };
22438
+ }
22439
+ function createInitialPrintDesignAiChatSettings(defaults2 = {}) {
22440
+ const profile = createPrintDesignAiChatProfile(defaults2);
22441
+ return { profiles: [profile], activeProfileId: profile.id };
22442
+ }
22443
+ function activePrintDesignAiChatProfile(settings) {
22444
+ return settings.profiles.find(
22445
+ (profile) => profile.id === settings.activeProfileId
22446
+ ) ?? settings.profiles[0];
22447
+ }
22448
+ function parsePrintDesignAiChatSettings(value) {
22449
+ if (!value || typeof value !== "object") return null;
22450
+ const item = value;
22451
+ if (Array.isArray(item.profiles)) {
22452
+ const profiles = item.profiles.filter((entry) => {
22453
+ if (!entry || typeof entry !== "object") return false;
22454
+ const profile2 = entry;
22455
+ return ["id", "name", "baseUrl", "key", "model"].every(
22456
+ (key) => typeof profile2[key] === "string"
22457
+ ) && Boolean(profile2.id);
22458
+ }).map((profile2) => ({
22459
+ ...profile2,
22460
+ reasoningEffort: parseReasoningEffort(profile2.reasoningEffort),
22461
+ models: Array.isArray(profile2.models) ? [
22462
+ ...new Set(
22463
+ profile2.models.filter(
22464
+ (model) => typeof model === "string" && model.length > 0
22465
+ )
22466
+ )
22467
+ ] : []
22468
+ }));
22469
+ if (!profiles.length) return null;
22470
+ const unique = profiles.filter(
22471
+ (profile2, index) => profiles.findIndex((candidate) => candidate.id === profile2.id) === index
22472
+ );
22473
+ const activeProfileId = typeof item.activeProfileId === "string" && unique.some((profile2) => profile2.id === item.activeProfileId) ? item.activeProfileId : unique[0].id;
22474
+ return {
22475
+ profiles: unique,
22476
+ activeProfileId,
22477
+ ...item.panelWidths ? {
22478
+ panelWidths: normalizePrintDesignAiChatPanelWidths(
22479
+ item.panelWidths
22480
+ )
22481
+ } : {}
22482
+ };
22483
+ }
22484
+ if (typeof item.baseUrl !== "string" || typeof item.key !== "string" || typeof item.model !== "string")
22485
+ return null;
22486
+ const profile = {
22487
+ id: "legacy",
22488
+ name: "",
22489
+ baseUrl: item.baseUrl,
22490
+ key: item.key,
22491
+ model: item.model,
22492
+ reasoningEffort: parseReasoningEffort(item.reasoningEffort)
22493
+ };
22494
+ return {
22495
+ profiles: [profile],
22496
+ activeProfileId: profile.id,
22497
+ ...item.panelWidths ? {
22498
+ panelWidths: normalizePrintDesignAiChatPanelWidths(
22499
+ item.panelWidths
22500
+ )
22501
+ } : {}
22502
+ };
22503
+ }
22504
+
22505
+ // src/ai-chat/providers/stream-chat-completion.ts
22506
+ async function readChatCompletionStream(response, onDelta) {
22507
+ const toolCalls = /* @__PURE__ */ new Map();
22508
+ let content = "";
22509
+ let reasoning = "";
22510
+ let finished = false;
22511
+ const accept = (value) => {
22512
+ if (!value || typeof value !== "object") return;
22513
+ const choices = value.choices;
22514
+ if (!Array.isArray(choices) || !choices.length) return;
22515
+ const choice = choices[0];
22516
+ if (!choice || typeof choice !== "object") return;
22517
+ if (typeof choice.finish_reason === "string") finished = true;
22518
+ const delta = choice.delta ?? choice.message;
22519
+ if (!delta || typeof delta !== "object") return;
22520
+ if (typeof delta.content === "string" && delta.content) {
22521
+ content += delta.content;
22522
+ onDelta({ content: delta.content });
22523
+ }
22524
+ const thought = delta.reasoning_content ?? delta.reasoning;
22525
+ if (typeof thought === "string" && thought) {
22526
+ reasoning += thought;
22527
+ onDelta({ reasoning: thought });
22528
+ }
22529
+ if (!Array.isArray(delta.tool_calls)) return;
22530
+ for (const [position, piece] of delta.tool_calls.entries()) {
22531
+ if (!piece || typeof piece !== "object") continue;
22532
+ const index = typeof piece.index === "number" ? piece.index : position;
22533
+ const call = toolCalls.get(index) ?? {
22534
+ id: "",
22535
+ type: "function",
22536
+ function: { name: "", arguments: "" }
22537
+ };
22538
+ if (typeof piece.id === "string") call.id += piece.id;
22539
+ if (typeof piece.function?.name === "string")
22540
+ call.function.name += piece.function.name;
22541
+ if (typeof piece.function?.arguments === "string")
22542
+ call.function.arguments += piece.function.arguments;
22543
+ toolCalls.set(index, call);
22544
+ }
22545
+ };
22546
+ if (!response.body) {
22547
+ accept(await response.json());
22548
+ finished = true;
22549
+ } else {
22550
+ const reader = response.body.getReader();
22551
+ const decoder = new TextDecoder();
22552
+ let buffer = "";
22553
+ let pendingJson = "";
22554
+ let rawJsonAccepted = false;
22555
+ const consumeLine = (rawLine) => {
22556
+ const line = rawLine.replace(/\r$/, "").trimStart();
22557
+ if (!line || line.startsWith("event:") || line.startsWith(":")) return;
22558
+ const data = line.startsWith("data:") ? line.slice(5).trimStart() : line;
22559
+ if (data === "[DONE]") {
22560
+ if (pendingJson) throw new Error("\u6A21\u578B\u6D41\u5305\u542B\u672A\u5B8C\u6210\u7684\u6570\u636E\u3002");
22561
+ finished = true;
22562
+ return;
22563
+ }
22564
+ pendingJson += pendingJson ? `
22565
+ ${data}` : data;
22566
+ let parsed;
22567
+ try {
22568
+ parsed = JSON.parse(pendingJson);
22569
+ } catch (cause) {
22570
+ if (!(cause instanceof SyntaxError)) throw cause;
22571
+ if (pendingJson.length > 8e6)
22572
+ throw new Error("\u6A21\u578B\u6D41\u5355\u6761\u6570\u636E\u8FC7\u957F\u6216\u683C\u5F0F\u65E0\u6548\u3002");
22573
+ return;
22574
+ }
22575
+ pendingJson = "";
22576
+ accept(parsed);
22577
+ if (!line.startsWith("data:")) rawJsonAccepted = true;
22578
+ };
22579
+ try {
22580
+ while (true) {
22581
+ const { done, value } = await reader.read();
22582
+ if (done) break;
22583
+ buffer += decoder.decode(value, { stream: true });
22584
+ let lineEnd = buffer.indexOf("\n");
22585
+ while (lineEnd >= 0) {
22586
+ consumeLine(buffer.slice(0, lineEnd));
22587
+ buffer = buffer.slice(lineEnd + 1);
22588
+ if (finished) break;
22589
+ lineEnd = buffer.indexOf("\n");
22590
+ }
22591
+ if (finished) {
22592
+ await reader.cancel();
22593
+ break;
22594
+ }
22595
+ }
22596
+ buffer += decoder.decode();
22597
+ if (!finished && buffer.trim()) consumeLine(buffer);
22598
+ if (pendingJson) throw new Error("\u6A21\u578B\u6D41\u5305\u542B\u65E0\u6CD5\u89E3\u6790\u7684\u6570\u636E\u3002");
22599
+ if (!finished && rawJsonAccepted) finished = true;
22600
+ } finally {
22601
+ reader.releaseLock();
22602
+ }
22603
+ }
22604
+ if (!finished) throw new Error("\u6A21\u578B\u56DE\u590D\u5728\u5B8C\u6210\u524D\u4E2D\u65AD\u3002");
22605
+ return {
22606
+ content,
22607
+ reasoning,
22608
+ toolCalls: [...toolCalls.entries()].sort(([a], [b]) => a - b).map(([, call]) => call)
22609
+ };
22610
+ }
22611
+
22612
+ // src/ai-chat/providers/openai-compatible.ts
22613
+ function agentSystemContent(selection) {
22614
+ const base = "\u4F60\u662F\u6253\u5370\u8BBE\u8BA1\u5668\u52A9\u624B\u3002\u9875\u9762\u548C\u5143\u7D20\u5750\u6807\u5355\u4F4D\u4E3A\u6BEB\u7C73\u3002\u9700\u8981\u67E5\u770B\u6216\u4FEE\u6539\u753B\u5E03\u65F6\u8C03\u7528\u5DE5\u5177\uFF0C\u4E0D\u8981\u731C\u6D4B\u9875\u9762\u6216\u5143\u7D20 ID\u3002\u521B\u5EFA\u8868\u683C\u7B49\u63D2\u4EF6\u7EC4\u4EF6\u524D\u5148\u8C03\u7528 list_components \u548C get_component_template\uFF1B\u4FEE\u6539\u5DF2\u6709\u5143\u7D20\u5148\u8C03\u7528 get_element\uFF1B\u7EC4\u4EF6\u4E13\u7528\u64CD\u4F5C\u4F7F\u7528 execute_component_command\u3002";
22615
+ if (!selection) return base;
22616
+ if (!selection.elements.length)
22617
+ return `${base} \u672C\u6B21\u6D88\u606F\u6CA1\u6709\u9644\u5E26\u753B\u5E03\u5143\u7D20\u3002\u4E0D\u8981\u628A\u753B\u5E03\u4E2D\u4ECD\u7136\u9009\u4E2D\u7684\u5143\u7D20\u5F53\u4F5C\u804A\u5929\u4FEE\u6539\u76EE\u6807\uFF1B\u5982\u7528\u6237\u8981\u6C42\u4FEE\u6539\u9009\u4E2D\u5185\u5BB9\uFF0C\u8BF7\u5148\u8BF7\u7528\u6237\u91CD\u65B0\u9009\u62E9\u76EE\u6807\u3002`;
22618
+ const targets = selection.elements.map(({ id, type }) => ({ id, type }));
22619
+ return `${base} \u672C\u6B21\u7528\u6237\u53D1\u9001\u6D88\u606F\u65F6\u9009\u4E2D\u7684\u9875\u9762 ID \u4E3A ${JSON.stringify(selection.pageId)}\uFF0C\u5143\u7D20\u4E3A ${JSON.stringify(targets)}\u3002\u7528\u6237\u8981\u6C42\u4FEE\u6539\u9009\u4E2D\u5185\u5BB9\u65F6\uFF0C\u5148\u7528 get_element \u8BFB\u53D6\u8FD9\u4E9B\u5143\u7D20\uFF0C\u518D\u6839\u636E\u8BF7\u6C42\u4FEE\u6539\uFF1B\u9664\u975E\u7528\u6237\u660E\u786E\u8981\u6C42\uFF0C\u4E0D\u4FEE\u6539\u5176\u4ED6\u5143\u7D20\u3002`;
22620
+ }
22621
+ function endpoint2(baseUrl, path) {
22622
+ const base = baseUrl.trim().replace(/\/+$/, "");
22623
+ if (!/^https?:\/\//i.test(base))
22624
+ throw new Error("\u8BF7\u8F93\u5165\u6709\u6548\u7684 HTTP(S) Base URL\u3002");
22625
+ return `${base}${base.endsWith("/v1") ? "" : "/v1"}/${path}`;
22626
+ }
22627
+ async function requestJson(url, key, init = {}) {
22628
+ const response = await fetch(url, {
22629
+ ...init,
22630
+ headers: {
22631
+ ...key ? { Authorization: `Bearer ${key}` } : {},
22632
+ ...init.body ? { "Content-Type": "application/json" } : {}
22633
+ }
22634
+ });
22635
+ if (!response.ok) throw new Error(`\u6A21\u578B\u670D\u52A1\u8BF7\u6C42\u5931\u8D25\uFF08${response.status}\uFF09\u3002`);
22636
+ return response.json();
22637
+ }
22638
+ var defaultPrintDesignAiChatProvider = {
22639
+ async listModels(config, signal) {
22640
+ const value = await requestJson(
22641
+ endpoint2(config.baseUrl, "models"),
22642
+ config.key,
22643
+ { signal }
22644
+ );
22645
+ if (!value || typeof value !== "object" || !("data" in value) || !Array.isArray(value.data))
22646
+ throw new Error("\u6A21\u578B\u5217\u8868\u683C\u5F0F\u65E0\u6548\u3002");
22647
+ return value.data.map(
22648
+ (item) => item && typeof item === "object" && "id" in item ? item.id : null
22649
+ ).filter(
22650
+ (id) => typeof id === "string" && id.length > 0
22651
+ ).sort();
22652
+ },
22653
+ async complete(config, messages, signal, agentApi) {
22654
+ const history = [
22655
+ ...agentApi ? [
22656
+ {
22657
+ role: "system",
22658
+ content: agentSystemContent(config.selection)
22659
+ }
22660
+ ] : [],
22661
+ ...messages.map(({ role, content, reasoning }) => ({
22662
+ role,
22663
+ content,
22664
+ ...agentApi && role === "assistant" && reasoning ? { reasoning_content: reasoning } : {}
22665
+ }))
22666
+ ];
22667
+ for (let turn = 0; turn < 8; turn++) {
22668
+ const value = await requestJson(
22669
+ endpoint2(config.baseUrl, "chat/completions"),
22670
+ config.key,
22671
+ {
22672
+ method: "POST",
22673
+ signal,
22674
+ body: JSON.stringify({
22675
+ model: config.model,
22676
+ ...config.reasoningEffort ? { reasoning_effort: config.reasoningEffort } : {},
22677
+ messages: history,
22678
+ ...agentApi ? {
22679
+ tools: agentApi.tools.map((tool) => ({
22680
+ type: "function",
22681
+ function: tool
22682
+ })),
22683
+ tool_choice: "auto"
22684
+ } : {}
22685
+ })
22686
+ }
22687
+ );
22688
+ const message = value && typeof value === "object" && "choices" in value && Array.isArray(value.choices) ? value.choices[0]?.message : null;
22689
+ if (!message || typeof message !== "object")
22690
+ throw new Error("\u6A21\u578B\u6CA1\u6709\u8FD4\u56DE\u6709\u6548\u6D88\u606F\u3002");
22691
+ const calls = "tool_calls" in message && Array.isArray(message.tool_calls) ? message.tool_calls : [];
22692
+ if (!calls.length) {
22693
+ if (typeof message.content !== "string")
22694
+ throw new Error("\u6A21\u578B\u6CA1\u6709\u8FD4\u56DE\u6587\u672C\u5185\u5BB9\u3002");
22695
+ return message.content;
22696
+ }
22697
+ if (!agentApi) throw new Error("\u5F53\u524D\u6CA1\u6709\u53EF\u7528\u7684 Agent \u5DE5\u5177\u3002");
22698
+ history.push(message);
22699
+ for (const call of calls) {
22700
+ const id = typeof call?.id === "string" ? call.id : "";
22701
+ const name = call?.function?.name;
22702
+ let result;
22703
+ try {
22704
+ if (!id || typeof name !== "string")
22705
+ throw new TypeError("\u6A21\u578B\u5DE5\u5177\u8C03\u7528\u683C\u5F0F\u65E0\u6548\u3002");
22706
+ result = agentApi.call(
22707
+ name,
22708
+ JSON.parse(call.function.arguments ?? "{}")
22709
+ );
22710
+ } catch (cause) {
22711
+ result = {
22712
+ error: cause instanceof Error ? cause.message : "\u5DE5\u5177\u6267\u884C\u5931\u8D25\u3002"
22713
+ };
22714
+ }
22715
+ history.push({
22716
+ role: "tool",
22717
+ tool_call_id: id,
22718
+ content: JSON.stringify(result)
22719
+ });
22720
+ }
22721
+ }
22722
+ throw new Error("Agent \u5DE5\u5177\u8C03\u7528\u6B21\u6570\u8FC7\u591A\uFF0C\u8BF7\u7F29\u5C0F\u4EFB\u52A1\u8303\u56F4\u3002");
22723
+ },
22724
+ async stream(config, messages, onDelta, signal, agentApi) {
22725
+ const history = [
22726
+ ...agentApi ? [
22727
+ {
22728
+ role: "system",
22729
+ content: agentSystemContent(config.selection)
22730
+ }
22731
+ ] : [],
22732
+ ...messages.map(({ role, content: content2, reasoning: reasoning2 }) => ({
22733
+ role,
22734
+ content: content2,
22735
+ ...agentApi && role === "assistant" && reasoning2 ? { reasoning_content: reasoning2 } : {}
22736
+ }))
22737
+ ];
22738
+ let content = "";
22739
+ let reasoning = "";
22740
+ for (let turn = 0; turn < 8; turn++) {
22741
+ const response = await fetch(
22742
+ endpoint2(config.baseUrl, "chat/completions"),
22743
+ {
22744
+ method: "POST",
22745
+ signal,
22746
+ headers: {
22747
+ ...config.key ? { Authorization: `Bearer ${config.key}` } : {},
22748
+ "Content-Type": "application/json"
22749
+ },
22750
+ body: JSON.stringify({
22751
+ model: config.model,
22752
+ ...config.reasoningEffort ? { reasoning_effort: config.reasoningEffort } : {},
22753
+ messages: history,
22754
+ stream: true,
22755
+ ...agentApi ? {
22756
+ tools: agentApi.tools.map((tool) => ({
22757
+ type: "function",
22758
+ function: tool
22759
+ })),
22760
+ tool_choice: "auto"
22761
+ } : {}
22762
+ })
22763
+ }
22764
+ );
22765
+ if (!response.ok)
22766
+ throw new Error(`\u6A21\u578B\u670D\u52A1\u8BF7\u6C42\u5931\u8D25\uFF08${response.status}\uFF09\u3002`);
22767
+ const result = await readChatCompletionStream(response, onDelta);
22768
+ content += result.content;
22769
+ reasoning += result.reasoning;
22770
+ if (!result.toolCalls.length) {
22771
+ if (!content) throw new Error("\u6A21\u578B\u6CA1\u6709\u8FD4\u56DE\u6587\u672C\u5185\u5BB9\u3002");
22772
+ return { content, reasoning };
22773
+ }
22774
+ if (!agentApi) throw new Error("\u5F53\u524D\u6CA1\u6709\u53EF\u7528\u7684 Agent \u5DE5\u5177\u3002");
22775
+ history.push({
22776
+ role: "assistant",
22777
+ content: result.content || null,
22778
+ ...result.reasoning ? { reasoning_content: result.reasoning } : {},
22779
+ tool_calls: result.toolCalls
22780
+ });
22781
+ for (const call of result.toolCalls) {
22782
+ let output;
22783
+ try {
22784
+ if (!call.id || !call.function.name)
22785
+ throw new TypeError("\u6A21\u578B\u5DE5\u5177\u8C03\u7528\u683C\u5F0F\u65E0\u6548\u3002");
22786
+ output = agentApi.call(
22787
+ call.function.name,
22788
+ JSON.parse(call.function.arguments || "{}")
22789
+ );
22790
+ } catch (cause) {
22791
+ output = {
22792
+ error: cause instanceof Error ? cause.message : "\u5DE5\u5177\u6267\u884C\u5931\u8D25\u3002"
22793
+ };
22794
+ }
22795
+ history.push({
22796
+ role: "tool",
22797
+ tool_call_id: call.id,
22798
+ content: JSON.stringify(output)
22799
+ });
22800
+ }
22801
+ }
22802
+ throw new Error("Agent \u5DE5\u5177\u8C03\u7528\u6B21\u6570\u8FC7\u591A\uFF0C\u8BF7\u7F29\u5C0F\u4EFB\u52A1\u8303\u56F4\u3002");
22803
+ }
22804
+ };
22805
+
22806
+ // src/ai-chat/persistence/encrypted-config.ts
22807
+ var DATABASE = "canvas-components-print-design-ai-chat";
22808
+ var STORE = "private-config";
22809
+ function openDatabase() {
22810
+ return new Promise((resolve, reject) => {
22811
+ const request = indexedDB.open(DATABASE, 1);
22812
+ request.onupgradeneeded = () => request.result.createObjectStore(STORE);
22813
+ request.onsuccess = () => resolve(request.result);
22814
+ request.onerror = () => reject(request.error);
22815
+ });
22816
+ }
22817
+ function read(database, key) {
22818
+ return new Promise((resolve, reject) => {
22819
+ const request = database.transaction(STORE, "readonly").objectStore(STORE).get(key);
22820
+ request.onsuccess = () => resolve(request.result);
22821
+ request.onerror = () => reject(request.error);
22822
+ });
22823
+ }
22824
+ async function savePrintDesignAiChatSettings(settings) {
22825
+ if (!globalThis.crypto?.subtle || typeof indexedDB === "undefined")
22826
+ throw new Error("\u5F53\u524D\u6D4F\u89C8\u5668\u4E0D\u652F\u6301\u52A0\u5BC6\u4FDD\u5B58\u914D\u7F6E\u3002");
22827
+ const database = await openDatabase();
22828
+ try {
22829
+ const key = await read(database, "key") ?? await crypto.subtle.generateKey(
22830
+ { name: "AES-GCM", length: 256 },
22831
+ false,
22832
+ ["encrypt", "decrypt"]
22833
+ );
22834
+ const iv = crypto.getRandomValues(new Uint8Array(12));
22835
+ const bytes = new TextEncoder().encode(JSON.stringify(settings));
22836
+ const ciphertext = await crypto.subtle.encrypt(
22837
+ { name: "AES-GCM", iv },
22838
+ key,
22839
+ bytes
22840
+ );
22841
+ await new Promise((resolve, reject) => {
22842
+ const transaction = database.transaction(STORE, "readwrite");
22843
+ transaction.objectStore(STORE).put(key, "key");
22844
+ transaction.objectStore(STORE).put({ iv, ciphertext }, "config");
22845
+ transaction.oncomplete = () => resolve();
22846
+ transaction.onerror = () => reject(transaction.error);
22847
+ transaction.onabort = () => reject(transaction.error);
22848
+ });
22849
+ } finally {
22850
+ database.close();
22851
+ }
22852
+ }
22853
+ async function readPrintDesignAiChatSettings() {
22854
+ if (!globalThis.crypto?.subtle || typeof indexedDB === "undefined")
22855
+ return null;
22856
+ const database = await openDatabase();
22857
+ try {
22858
+ const key = await read(database, "key");
22859
+ const record2 = await read(
22860
+ database,
22861
+ "config"
22862
+ );
22863
+ if (!key || !record2) return null;
22864
+ const bytes = await crypto.subtle.decrypt(
22865
+ { name: "AES-GCM", iv: new Uint8Array(record2.iv) },
22866
+ key,
22867
+ record2.ciphertext
22868
+ );
22869
+ const value = JSON.parse(new TextDecoder().decode(bytes));
22870
+ return parsePrintDesignAiChatSettings(value);
22871
+ } finally {
22872
+ database.close();
22873
+ }
22874
+ }
22875
+
22876
+ // src/ai-chat/model/reasoning.ts
22877
+ var LIVE_REASONING_LIMIT = 8e3;
22878
+ var ESTIMATED_HEIGHT = 104;
22879
+ var OVERSCAN = 3;
22880
+ function VirtualMessages({
22881
+ messages,
22882
+ currentModel,
22883
+ busy = false,
22884
+ pendingModel,
22885
+ streaming
22886
+ }) {
22887
+ const viewport = react.useRef(null);
22888
+ const followTail = react.useRef(true);
22889
+ const [scrollTop, setScrollTop] = react.useState(0);
22890
+ const [viewportHeight, setViewportHeight] = react.useState(500);
22891
+ const [heights, setHeights] = react.useState({});
22892
+ const showThinking = busy && messages[messages.length - 1]?.role !== "assistant";
22893
+ const offsets = react.useMemo(() => {
22894
+ const next = [0];
22895
+ for (const message of messages)
22896
+ next.push(
22897
+ next[next.length - 1] + (heights[message.id] ?? ESTIMATED_HEIGHT)
22898
+ );
22899
+ return next;
22900
+ }, [messages, heights]);
22901
+ const total = offsets[offsets.length - 1] ?? 0;
22902
+ const first = Math.max(
22903
+ 0,
22904
+ offsets.findIndex(
22905
+ (offset, index) => index < messages.length && offsets[index + 1] >= scrollTop
22906
+ ) - OVERSCAN
22907
+ );
22908
+ const end = offsets.findIndex(
22909
+ (offset) => offset > scrollTop + viewportHeight
22910
+ );
22911
+ const last = end < 0 ? messages.length : Math.min(messages.length, Math.max(first, end + OVERSCAN));
22912
+ react.useEffect(() => {
22913
+ const element = viewport.current;
22914
+ if (!element) return;
22915
+ const observer = new ResizeObserver(
22916
+ () => setViewportHeight(element.clientHeight)
22917
+ );
22918
+ observer.observe(element);
22919
+ return () => observer.disconnect();
22920
+ }, []);
22921
+ react.useEffect(() => {
22922
+ const element = viewport.current;
22923
+ if (element && followTail.current) element.scrollTop = element.scrollHeight;
22924
+ }, [
22925
+ messages.length,
22926
+ showThinking,
22927
+ streaming?.content.length,
22928
+ streaming?.reasoningLength
22929
+ ]);
22930
+ react.useEffect(() => {
22931
+ if (!showThinking) return;
22932
+ followTail.current = true;
22933
+ const element = viewport.current;
22934
+ if (element) element.scrollTop = element.scrollHeight;
22935
+ }, [showThinking]);
22936
+ return /* @__PURE__ */ jsxRuntime.jsxs(
22937
+ "div",
22938
+ {
22939
+ ref: viewport,
22940
+ className: "cc-print-design-ai-messages",
22941
+ onScroll: (event) => {
22942
+ const element = event.currentTarget;
22943
+ setScrollTop(element.scrollTop);
22944
+ followTail.current = element.scrollHeight - element.scrollTop - element.clientHeight < 80;
22945
+ },
22946
+ children: [
22947
+ /* @__PURE__ */ jsxRuntime.jsx("div", { style: { height: total, position: "relative" }, children: messages.slice(first, last).map((message, index) => /* @__PURE__ */ jsxRuntime.jsx(
22948
+ MeasuredMessage,
22949
+ {
22950
+ message,
22951
+ currentModel,
22952
+ top: offsets[first + index],
22953
+ onHeight: (height) => setHeights(
22954
+ (current2) => current2[message.id] === height ? current2 : { ...current2, [message.id]: height }
22955
+ )
22956
+ },
22957
+ message.id
22958
+ )) }),
22959
+ showThinking && /* @__PURE__ */ jsxRuntime.jsxs(
22960
+ "div",
22961
+ {
22962
+ className: "cc-print-design-ai-message cc-print-design-ai-message-assistant cc-print-design-ai-message-thinking",
22963
+ role: "status",
22964
+ "aria-live": "polite",
22965
+ children: [
22966
+ /* @__PURE__ */ jsxRuntime.jsx("span", { children: pendingModel?.trim() || currentModel?.trim() || "AI" }),
22967
+ streaming?.reasoning && /* @__PURE__ */ jsxRuntime.jsx(
22968
+ ReasoningBlock,
22969
+ {
22970
+ text: streaming.reasoning,
22971
+ totalLength: streaming.reasoningLength,
22972
+ live: true
22973
+ }
22974
+ ),
22975
+ streaming?.content && /* @__PURE__ */ jsxRuntime.jsx("p", { children: streaming.content }),
22976
+ /* @__PURE__ */ jsxRuntime.jsxs("p", { className: "cc-print-design-ai-thinking-indicator", children: [
22977
+ /* @__PURE__ */ jsxRuntime.jsxs(
22978
+ "span",
22979
+ {
22980
+ className: "cc-print-design-ai-thinking-dots",
22981
+ "aria-hidden": "true",
22982
+ children: [
22983
+ /* @__PURE__ */ jsxRuntime.jsx("i", {}),
22984
+ /* @__PURE__ */ jsxRuntime.jsx("i", {}),
22985
+ /* @__PURE__ */ jsxRuntime.jsx("i", {})
22986
+ ]
22987
+ }
22988
+ ),
22989
+ streaming?.content ? "\u751F\u6210\u4E2D\u2026" : "\u601D\u8003\u4E2D\u2026"
22990
+ ] })
22991
+ ]
22992
+ }
22993
+ )
22994
+ ]
22995
+ }
22996
+ );
22997
+ }
22998
+ function MeasuredMessage({
22999
+ message,
23000
+ currentModel,
23001
+ top,
23002
+ onHeight
23003
+ }) {
23004
+ const ref = react.useRef(null);
23005
+ react.useEffect(() => {
23006
+ const element = ref.current;
23007
+ if (!element) return;
23008
+ const observer = new ResizeObserver(
23009
+ () => onHeight(Math.ceil(element.getBoundingClientRect().height))
23010
+ );
23011
+ observer.observe(element);
23012
+ return () => observer.disconnect();
23013
+ }, [onHeight]);
23014
+ return /* @__PURE__ */ jsxRuntime.jsxs(
23015
+ "div",
23016
+ {
23017
+ ref,
23018
+ className: `cc-print-design-ai-message cc-print-design-ai-message-${message.role}`,
23019
+ style: { position: "absolute", top, width: "100%" },
23020
+ children: [
23021
+ /* @__PURE__ */ jsxRuntime.jsx("span", { children: message.role === "user" ? "\u4F60" : message.model?.trim() || currentModel?.trim() || "AI" }),
23022
+ message.role === "assistant" && message.reasoning && /* @__PURE__ */ jsxRuntime.jsx(ReasoningBlock, { text: message.reasoning }),
23023
+ /* @__PURE__ */ jsxRuntime.jsx("p", { children: message.content })
23024
+ ]
23025
+ }
23026
+ );
23027
+ }
23028
+ function ReasoningBlock({
23029
+ text,
23030
+ totalLength = text.length,
23031
+ live = false
23032
+ }) {
23033
+ const viewport = react.useRef(null);
23034
+ const visible = live ? text.slice(-LIVE_REASONING_LIMIT) : text;
23035
+ const hidden = live ? Math.max(0, totalLength - visible.length) : 0;
23036
+ react.useEffect(() => {
23037
+ if (live && viewport.current)
23038
+ viewport.current.scrollTop = viewport.current.scrollHeight;
23039
+ }, [live, totalLength]);
23040
+ return /* @__PURE__ */ jsxRuntime.jsxs("details", { className: "cc-print-design-ai-reasoning", open: live || void 0, children: [
23041
+ /* @__PURE__ */ jsxRuntime.jsx("summary", { children: "\u601D\u8003\u8FC7\u7A0B" }),
23042
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { ref: viewport, children: [
23043
+ hidden ? `\u524D ${hidden} \u5B57\u6682\u4E0D\u663E\u793A\uFF0C\u56DE\u590D\u5B8C\u6210\u540E\u53EF\u5C55\u5F00\u5168\u6587\u3002
23044
+ ` : "",
23045
+ visible
23046
+ ] })
23047
+ ] });
23048
+ }
23049
+ function ChatSettings({
23050
+ settings,
23051
+ models,
23052
+ modelLoading,
23053
+ onSettingsChange,
23054
+ onLoadModels,
23055
+ onSave,
23056
+ onCancel
23057
+ }) {
23058
+ const profile = activePrintDesignAiChatProfile(settings);
23059
+ const updateProfile = (patch) => onSettingsChange({
23060
+ ...settings,
23061
+ profiles: settings.profiles.map(
23062
+ (item) => item.id === profile.id ? {
23063
+ ...item,
23064
+ ...patch,
23065
+ ...patch.baseUrl !== void 0 && patch.baseUrl !== item.baseUrl || patch.key !== void 0 && patch.key !== item.key ? { models: [] } : {}
23066
+ } : item
23067
+ )
23068
+ });
23069
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "cc-print-design-ai-settings", children: [
23070
+ /* @__PURE__ */ jsxRuntime.jsx("strong", { children: "\u8FDE\u63A5\u914D\u7F6E" }),
23071
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "cc-print-design-ai-profile-picker", children: [
23072
+ /* @__PURE__ */ jsxRuntime.jsxs("label", { children: [
23073
+ "\u5F53\u524D\u8FDE\u63A5",
23074
+ /* @__PURE__ */ jsxRuntime.jsx(
23075
+ reactComponents.ReactSelect,
23076
+ {
23077
+ "aria-label": "AI \u5F53\u524D\u8FDE\u63A5",
23078
+ value: profile.id,
23079
+ options: settings.profiles.map((item, index) => ({
23080
+ value: item.id,
23081
+ label: item.name.trim() || item.baseUrl.trim() || `\u8FDE\u63A5 ${index + 1}`
23082
+ })),
23083
+ allowClear: false,
23084
+ showSearch: false,
23085
+ popupZIndex: 1100,
23086
+ onChange: (value) => onSettingsChange({
23087
+ ...settings,
23088
+ activeProfileId: value
23089
+ })
23090
+ }
23091
+ )
23092
+ ] }),
23093
+ /* @__PURE__ */ jsxRuntime.jsx(
23094
+ reactComponents.ReactButton,
23095
+ {
23096
+ onClick: () => {
23097
+ const created = createPrintDesignAiChatProfile();
23098
+ onSettingsChange({
23099
+ profiles: [...settings.profiles, created],
23100
+ activeProfileId: created.id
23101
+ });
23102
+ },
23103
+ children: "\u65B0\u589E"
23104
+ }
23105
+ ),
23106
+ /* @__PURE__ */ jsxRuntime.jsx(
23107
+ reactComponents.ReactButton,
23108
+ {
23109
+ danger: true,
23110
+ disabled: settings.profiles.length <= 1,
23111
+ onClick: () => {
23112
+ const profiles = settings.profiles.filter(
23113
+ (item) => item.id !== profile.id
23114
+ );
23115
+ onSettingsChange({ profiles, activeProfileId: profiles[0].id });
23116
+ },
23117
+ children: "\u5220\u9664"
23118
+ }
23119
+ )
23120
+ ] }),
23121
+ /* @__PURE__ */ jsxRuntime.jsxs("label", { children: [
23122
+ "\u8FDE\u63A5\u540D\u79F0",
23123
+ /* @__PURE__ */ jsxRuntime.jsx(
23124
+ reactComponents.ReactInput,
23125
+ {
23126
+ "aria-label": "AI \u8FDE\u63A5\u540D\u79F0",
23127
+ value: profile.name,
23128
+ onChange: (event) => updateProfile({ name: event.target.value }),
23129
+ placeholder: "\u53EF\u9009\uFF0C\u7528\u4E8E\u533A\u5206\u591A\u4E2A\u8FDE\u63A5"
23130
+ }
23131
+ )
23132
+ ] }),
23133
+ /* @__PURE__ */ jsxRuntime.jsxs("label", { children: [
23134
+ "Base URL",
23135
+ /* @__PURE__ */ jsxRuntime.jsx(
23136
+ reactComponents.ReactInput,
23137
+ {
23138
+ "aria-label": "AI Base URL",
23139
+ value: profile.baseUrl,
23140
+ onChange: (event) => updateProfile({ baseUrl: event.target.value }),
23141
+ placeholder: "https://example.com/v1"
23142
+ }
23143
+ )
23144
+ ] }),
23145
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "cc-print-design-ai-key-row", children: [
23146
+ /* @__PURE__ */ jsxRuntime.jsxs("label", { children: [
23147
+ "API Key",
23148
+ /* @__PURE__ */ jsxRuntime.jsx(
23149
+ reactComponents.ReactInput,
23150
+ {
23151
+ "aria-label": "AI API Key",
23152
+ type: "password",
23153
+ autoComplete: "off",
23154
+ value: profile.key,
23155
+ onChange: (event) => updateProfile({ key: event.target.value })
23156
+ }
23157
+ )
23158
+ ] }),
23159
+ /* @__PURE__ */ jsxRuntime.jsx(reactComponents.ReactButton, { onClick: onLoadModels, disabled: modelLoading, children: modelLoading ? "\u8BFB\u53D6\u4E2D\u2026" : "\u83B7\u53D6\u6A21\u578B" })
23160
+ ] }),
23161
+ /* @__PURE__ */ jsxRuntime.jsxs("label", { children: [
23162
+ "\u6A21\u578B",
23163
+ /* @__PURE__ */ jsxRuntime.jsx(
23164
+ reactComponents.ReactSelect,
23165
+ {
23166
+ "aria-label": "AI \u6A21\u578B",
23167
+ value: profile.model,
23168
+ options: models.map((model) => ({ label: model, value: model })),
23169
+ showSearch: true,
23170
+ allowCustomValue: true,
23171
+ popupZIndex: 1100,
23172
+ onChange: (value) => updateProfile({ model: value }),
23173
+ onInputValueChange: (value) => updateProfile({ model: value }),
23174
+ placeholder: "\u9009\u62E9\u6216\u8F93\u5165\u6A21\u578B ID"
23175
+ }
23176
+ )
23177
+ ] }),
23178
+ /* @__PURE__ */ jsxRuntime.jsxs("label", { children: [
23179
+ "\u601D\u8003\u7A0B\u5EA6",
23180
+ /* @__PURE__ */ jsxRuntime.jsx(
23181
+ reactComponents.ReactSelect,
23182
+ {
23183
+ "aria-label": "AI \u601D\u8003\u7A0B\u5EA6",
23184
+ value: profile.reasoningEffort ?? "",
23185
+ options: reasoningEffortOptions,
23186
+ allowClear: false,
23187
+ showSearch: false,
23188
+ popupZIndex: 1100,
23189
+ onChange: (value) => updateProfile({ reasoningEffort: parseReasoningEffort(value) })
23190
+ }
23191
+ )
23192
+ ] }),
23193
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "cc-print-design-ai-settings-actions", children: [
23194
+ /* @__PURE__ */ jsxRuntime.jsx(reactComponents.ReactButton, { onClick: onCancel, children: "\u53D6\u6D88" }),
23195
+ /* @__PURE__ */ jsxRuntime.jsx(reactComponents.ReactButton, { type: "primary", onClick: onSave, children: "\u4FDD\u5B58" })
23196
+ ] })
23197
+ ] });
23198
+ }
23199
+ function ChatPanelWidthSettings({
23200
+ widths,
23201
+ onWidthsChange,
23202
+ onSave,
23203
+ onCancel
23204
+ }) {
23205
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "cc-print-design-ai-settings", children: [
23206
+ /* @__PURE__ */ jsxRuntime.jsx("strong", { children: "\u5BF9\u8BDD\u9762\u677F\u5BBD\u5EA6\uFF08px\uFF09" }),
23207
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "cc-print-design-ai-width-fields", children: ["min", "max", "current"].map((field) => {
23208
+ const label = { min: "\u6700\u5C0F", max: "\u6700\u5927", current: "\u5F53\u524D" }[field];
23209
+ return /* @__PURE__ */ jsxRuntime.jsxs("label", { children: [
23210
+ label,
23211
+ /* @__PURE__ */ jsxRuntime.jsx(
23212
+ reactComponents.ReactInputNumber,
23213
+ {
23214
+ "aria-label": `AI \u9762\u677F${label}\u5BBD\u5EA6`,
23215
+ min: field === "min" ? 240 : 0,
23216
+ max: field === "max" ? 1600 : void 0,
23217
+ value: widths[field],
23218
+ onChange: (value) => {
23219
+ if (value !== null)
23220
+ onWidthsChange({ ...widths, [field]: value });
23221
+ }
23222
+ }
23223
+ )
23224
+ ] }, field);
23225
+ }) }),
23226
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "cc-print-design-ai-settings-actions", children: [
23227
+ /* @__PURE__ */ jsxRuntime.jsx(reactComponents.ReactButton, { onClick: onCancel, children: "\u53D6\u6D88" }),
23228
+ /* @__PURE__ */ jsxRuntime.jsx(reactComponents.ReactButton, { type: "primary", onClick: onSave, children: "\u4FDD\u5B58" })
23229
+ ] })
23230
+ ] });
23231
+ }
23232
+ function ChatHistory({
23233
+ conversations,
23234
+ activeId,
23235
+ busy,
23236
+ onSelect,
23237
+ onDelete
23238
+ }) {
23239
+ const [deletingId, setDeletingId] = react.useState(null);
23240
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "cc-print-design-ai-history", children: [
23241
+ conversations.length === 0 && /* @__PURE__ */ jsxRuntime.jsx("p", { children: "\u6682\u65E0\u5386\u53F2\u5BF9\u8BDD" }),
23242
+ conversations.map((conversation) => /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "cc-print-design-ai-history-item", children: [
23243
+ /* @__PURE__ */ jsxRuntime.jsxs(
23244
+ reactComponents.ReactButton,
23245
+ {
23246
+ type: "text",
23247
+ className: activeId === conversation.id ? "active" : "",
23248
+ disabled: busy,
23249
+ onClick: () => onSelect(conversation.id),
23250
+ title: conversation.title,
23251
+ children: [
23252
+ /* @__PURE__ */ jsxRuntime.jsx("span", { children: conversation.title }),
23253
+ /* @__PURE__ */ jsxRuntime.jsx("small", { children: new Date(conversation.updatedAt).toLocaleString() })
23254
+ ]
23255
+ }
23256
+ ),
23257
+ /* @__PURE__ */ jsxRuntime.jsx(
23258
+ reactComponents.ReactButton,
23259
+ {
23260
+ type: "text",
23261
+ danger: true,
23262
+ className: "cc-print-design-ai-history-delete",
23263
+ disabled: busy,
23264
+ onClick: () => {
23265
+ if (deletingId === conversation.id) {
23266
+ onDelete(conversation.id);
23267
+ setDeletingId(null);
23268
+ } else setDeletingId(conversation.id);
23269
+ },
23270
+ "aria-label": `${deletingId === conversation.id ? "\u786E\u8BA4\u5220\u9664" : "\u5220\u9664"}\u5BF9\u8BDD ${conversation.title}`,
23271
+ children: deletingId === conversation.id ? "\u786E\u8BA4\u5220\u9664" : "\u5220\u9664"
23272
+ }
23273
+ )
23274
+ ] }, conversation.id))
23275
+ ] });
23276
+ }
23277
+ function ChatSettingsDialog(props) {
23278
+ const [tab, setTab] = react.useState("basic");
23279
+ react.useEffect(() => {
23280
+ if (props.open) setTab("basic");
23281
+ }, [props.open]);
23282
+ return /* @__PURE__ */ jsxRuntime.jsx(
23283
+ reactComponents.ReactModal,
23284
+ {
23285
+ open: props.open,
23286
+ title: "AI \u5BF9\u8BDD\u914D\u7F6E",
23287
+ width: 720,
23288
+ centered: true,
23289
+ fullscreenable: false,
23290
+ footer: false,
23291
+ style: { height: 576 },
23292
+ bodyStyle: {
23293
+ padding: 0,
23294
+ overflow: "hidden"
23295
+ },
23296
+ onCancel: props.onClose,
23297
+ className: "cc-print-design-ai-dialog",
23298
+ children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "cc-print-design-ai-dialog-layout", children: [
23299
+ /* @__PURE__ */ jsxRuntime.jsxs("nav", { className: "cc-print-design-ai-dialog-nav", "aria-label": "AI \u5BF9\u8BDD\u914D\u7F6E", children: [
23300
+ /* @__PURE__ */ jsxRuntime.jsx(
23301
+ reactComponents.ReactButton,
23302
+ {
23303
+ type: "text",
23304
+ "aria-current": tab === "basic" ? "page" : void 0,
23305
+ onClick: () => setTab("basic"),
23306
+ children: "\u57FA\u7840\u914D\u7F6E"
23307
+ }
23308
+ ),
23309
+ /* @__PURE__ */ jsxRuntime.jsx(
23310
+ reactComponents.ReactButton,
23311
+ {
23312
+ type: "text",
23313
+ "aria-current": tab === "width" ? "page" : void 0,
23314
+ onClick: () => setTab("width"),
23315
+ children: "\u5916\u89C2\u914D\u7F6E"
23316
+ }
23317
+ ),
23318
+ /* @__PURE__ */ jsxRuntime.jsx(
23319
+ reactComponents.ReactButton,
23320
+ {
23321
+ type: "text",
23322
+ "aria-current": tab === "history" ? "page" : void 0,
23323
+ onClick: () => setTab("history"),
23324
+ children: "\u5386\u53F2\u5BF9\u8BDD"
23325
+ }
23326
+ )
23327
+ ] }),
23328
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "cc-print-design-ai-dialog-content", children: tab === "basic" ? /* @__PURE__ */ jsxRuntime.jsx(
23329
+ ChatSettings,
23330
+ {
23331
+ settings: props.settings,
23332
+ models: props.models,
23333
+ modelLoading: props.modelLoading,
23334
+ onSettingsChange: props.onSettingsChange,
23335
+ onLoadModels: props.onLoadModels,
23336
+ onSave: props.onSave,
23337
+ onCancel: props.onClose
23338
+ }
23339
+ ) : tab === "width" ? /* @__PURE__ */ jsxRuntime.jsx(
23340
+ ChatPanelWidthSettings,
23341
+ {
23342
+ widths: props.widths,
23343
+ onWidthsChange: props.onWidthsChange,
23344
+ onSave: props.onSave,
23345
+ onCancel: props.onClose
23346
+ }
23347
+ ) : /* @__PURE__ */ jsxRuntime.jsx(
23348
+ ChatHistory,
23349
+ {
23350
+ conversations: props.conversations,
23351
+ activeId: props.activeId,
23352
+ busy: props.busy,
23353
+ onSelect: props.onSelectConversation,
23354
+ onDelete: props.onDeleteConversation
23355
+ }
23356
+ ) })
23357
+ ] })
23358
+ }
23359
+ );
23360
+ }
23361
+ function ChatComposer({
23362
+ input,
23363
+ model,
23364
+ models,
23365
+ reasoningEffort,
23366
+ selection,
23367
+ onInputChange,
23368
+ onModelChange,
23369
+ onReasoningEffortChange,
23370
+ onRemoveSelectedElement,
23371
+ onOpenSettings,
23372
+ onSend
23373
+ }) {
23374
+ const handleKeyDown = (event) => {
23375
+ if (event.key === "Enter" && !event.shiftKey) {
23376
+ event.preventDefault();
23377
+ event.currentTarget.form?.requestSubmit();
23378
+ }
23379
+ };
23380
+ return /* @__PURE__ */ jsxRuntime.jsxs("form", { className: "cc-print-design-ai-composer", onSubmit: onSend, children: [
23381
+ selection?.elements.length ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "cc-print-design-ai-selection", "aria-label": "\u5F53\u524D\u9009\u4E2D\u5185\u5BB9", children: [
23382
+ /* @__PURE__ */ jsxRuntime.jsxs("span", { children: [
23383
+ "\u5F53\u524D\u9009\u4E2D \xB7 ",
23384
+ selection.pageName || "\u5F53\u524D\u9875",
23385
+ " \xB7",
23386
+ " ",
23387
+ selection.elements.length
23388
+ ] }),
23389
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "cc-print-design-ai-selection-items", children: selection.elements.map((element) => /* @__PURE__ */ jsxRuntime.jsxs(
23390
+ reactComponents.ReactTag,
23391
+ {
23392
+ className: "cc-print-design-ai-selection-item",
23393
+ title: `${element.label} \xB7 ${element.type}${element.preview ? ` \xB7 ${element.preview}` : ""}`,
23394
+ closeLabel: `\u4ECE\u804A\u5929\u76EE\u6807\u4E2D\u79FB\u9664 ${element.label}`,
23395
+ onClose: () => onRemoveSelectedElement(element.id),
23396
+ children: [
23397
+ /* @__PURE__ */ jsxRuntime.jsx("strong", { children: element.label }),
23398
+ element.preview ? /* @__PURE__ */ jsxRuntime.jsx("small", { children: element.preview }) : null
23399
+ ]
23400
+ },
23401
+ element.id
23402
+ )) })
23403
+ ] }) : null,
23404
+ /* @__PURE__ */ jsxRuntime.jsx(
23405
+ "textarea",
23406
+ {
23407
+ "aria-label": "\u53D1\u9001\u7ED9 AI",
23408
+ value: input,
23409
+ onChange: (event) => onInputChange(event.target.value),
23410
+ onKeyDown: handleKeyDown,
23411
+ placeholder: "\u8F93\u5165\u6D88\u606F\uFF0CEnter \u53D1\u9001\uFF0CShift+Enter \u6362\u884C",
23412
+ rows: 3
23413
+ }
23414
+ ),
23415
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "cc-print-design-ai-composer-tools", children: [
23416
+ /* @__PURE__ */ jsxRuntime.jsx(
23417
+ "button",
23418
+ {
23419
+ type: "button",
23420
+ className: "cc-print-design-ai-composer-more",
23421
+ "aria-label": "\u66F4\u591A AI \u8BBE\u7F6E",
23422
+ title: "\u6A21\u578B\u914D\u7F6E",
23423
+ onClick: onOpenSettings,
23424
+ children: /* @__PURE__ */ jsxRuntime.jsx(reactComponents.ReactMoreOutlined, { "aria-hidden": "true" })
23425
+ }
23426
+ ),
23427
+ /* @__PURE__ */ jsxRuntime.jsx(
23428
+ reactComponents.ReactSelect,
23429
+ {
23430
+ "aria-label": "AI \u5F53\u524D\u6A21\u578B",
23431
+ value: model,
23432
+ options: models.map((item) => ({ label: item, value: item })),
23433
+ allowClear: false,
23434
+ allowCustomValue: true,
23435
+ placeholder: "\u9009\u62E9\u6A21\u578B",
23436
+ popupZIndex: 1100,
23437
+ onChange: onModelChange
23438
+ }
23439
+ ),
23440
+ /* @__PURE__ */ jsxRuntime.jsx(
23441
+ reactComponents.ReactSelect,
23442
+ {
23443
+ "aria-label": "AI \u5F53\u524D\u601D\u8003\u7A0B\u5EA6",
23444
+ value: reasoningEffort ?? "",
23445
+ options: reasoningEffortOptions,
23446
+ allowClear: false,
23447
+ showSearch: false,
23448
+ popupZIndex: 1100,
23449
+ onChange: (value) => onReasoningEffortChange(parseReasoningEffort(value))
23450
+ }
23451
+ )
23452
+ ] })
23453
+ ] });
23454
+ }
23455
+ function ChatNoticeDialog({ message, onClose }) {
23456
+ return /* @__PURE__ */ jsxRuntime.jsx(
23457
+ reactComponents.ReactModal,
23458
+ {
23459
+ open: Boolean(message),
23460
+ title: "AI \u5BF9\u8BDD\u63D0\u793A",
23461
+ width: 420,
23462
+ centered: true,
23463
+ fullscreenable: false,
23464
+ zIndex: 1200,
23465
+ onCancel: onClose,
23466
+ footer: /* @__PURE__ */ jsxRuntime.jsx(reactComponents.ReactButton, { type: "primary", onClick: onClose, children: "\u77E5\u9053\u4E86" }),
23467
+ children: /* @__PURE__ */ jsxRuntime.jsx("p", { role: "alert", children: message })
23468
+ }
23469
+ );
23470
+ }
23471
+
23472
+ // src/ai-chat/model/selection-agent-api.ts
23473
+ var changesSelection = /* @__PURE__ */ new Set([
23474
+ "set_active_page",
23475
+ "select_elements",
23476
+ "add_element",
23477
+ "remove_elements",
23478
+ "undo",
23479
+ "redo"
23480
+ ]);
23481
+ function createSelectionScopedAgentApi(agentApi, selection) {
23482
+ if (!selection) return agentApi;
23483
+ let useSnapshot = true;
23484
+ return {
23485
+ tools: agentApi.tools,
23486
+ call(name, input) {
23487
+ if (name === "get_selection" && useSnapshot)
23488
+ return {
23489
+ pageId: selection.pageId,
23490
+ elementIds: selection.elements.map((item) => item.id)
23491
+ };
23492
+ const result = agentApi.call(name, input);
23493
+ if (changesSelection.has(name)) useSnapshot = false;
23494
+ return result;
23495
+ }
23496
+ };
23497
+ }
23498
+
23499
+ // src/ai-chat/persistence/conversation-history.ts
23500
+ var DATABASE2 = "canvas-components-print-design-ai-chat-history";
23501
+ var STORE2 = "conversations";
23502
+ async function openDatabase2() {
23503
+ if (typeof indexedDB === "undefined") return null;
23504
+ return new Promise((resolve, reject) => {
23505
+ const request = indexedDB.open(DATABASE2, 1);
23506
+ request.onupgradeneeded = () => request.result.createObjectStore(STORE2, { keyPath: "id" });
23507
+ request.onsuccess = () => resolve(request.result);
23508
+ request.onerror = () => reject(request.error);
23509
+ });
23510
+ }
23511
+ async function access(mode, action, fallback) {
23512
+ const database = await openDatabase2();
23513
+ if (!database) return fallback;
23514
+ return new Promise((resolve, reject) => {
23515
+ const transaction = database.transaction(STORE2, mode);
23516
+ let result = fallback;
23517
+ action(transaction.objectStore(STORE2), (value) => {
23518
+ result = value;
23519
+ });
23520
+ transaction.oncomplete = () => {
23521
+ database.close();
23522
+ resolve(result);
23523
+ };
23524
+ transaction.onerror = () => {
23525
+ database.close();
23526
+ reject(transaction.error);
23527
+ };
23528
+ transaction.onabort = () => {
23529
+ database.close();
23530
+ reject(transaction.error);
23531
+ };
23532
+ });
23533
+ }
23534
+ async function listPrintDesignAiChatConversations() {
23535
+ const records = await access(
23536
+ "readonly",
23537
+ (store, setResult) => {
23538
+ const request = store.getAll();
23539
+ request.onsuccess = () => setResult(request.result);
23540
+ },
23541
+ []
23542
+ );
23543
+ return records.filter(
23544
+ (item) => item && typeof item.id === "string" && Array.isArray(item.messages)
23545
+ ).sort((a, b) => b.updatedAt - a.updatedAt);
23546
+ }
23547
+ function readPrintDesignAiChatConversation(id) {
23548
+ return access(
23549
+ "readonly",
23550
+ (store, setResult) => {
23551
+ const request = store.get(id);
23552
+ request.onsuccess = () => setResult(
23553
+ request.result ?? null
23554
+ );
23555
+ },
23556
+ null
23557
+ );
23558
+ }
23559
+ function savePrintDesignAiChatConversation(value) {
23560
+ return access(
23561
+ "readwrite",
23562
+ (store) => {
23563
+ store.put(value);
23564
+ },
23565
+ void 0
23566
+ );
23567
+ }
23568
+ function deletePrintDesignAiChatConversation(id) {
23569
+ return access(
23570
+ "readwrite",
23571
+ (store) => {
23572
+ store.delete(id);
23573
+ },
23574
+ void 0
23575
+ );
23576
+ }
23577
+
23578
+ // src/ai-chat/hooks/use-chat-session.ts
23579
+ function conversationId() {
23580
+ return globalThis.crypto?.randomUUID?.() ?? `chat-${Date.now()}-${Math.random().toString(36).slice(2)}`;
23581
+ }
23582
+ function useChatSession(provider, agentApi) {
23583
+ const [conversations, setConversations] = react.useState([]);
23584
+ const [activeId, setActiveId] = react.useState(null);
23585
+ const [messages, setMessages] = react.useState([]);
23586
+ const [busy, setBusy] = react.useState(false);
23587
+ const [pendingModel, setPendingModel] = react.useState("");
23588
+ const [streaming, setStreaming] = react.useState(null);
23589
+ const [error, setError] = react.useState("");
23590
+ const nextMessageId = react.useRef(1);
23591
+ const controller = react.useRef(null);
23592
+ const activeConversation = react.useRef(null);
23593
+ const pendingWrite = react.useRef(Promise.resolve());
23594
+ react.useEffect(() => {
23595
+ let alive = true;
23596
+ void listPrintDesignAiChatConversations().then((items) => {
23597
+ if (alive)
23598
+ setConversations(
23599
+ (current2) => [
23600
+ ...current2,
23601
+ ...items.filter(
23602
+ (item) => !current2.some((existing) => existing.id === item.id)
23603
+ )
23604
+ ].sort((a, b) => b.updatedAt - a.updatedAt)
23605
+ );
23606
+ }).catch(() => {
23607
+ if (alive) setError("\u5386\u53F2\u5BF9\u8BDD\u8BFB\u53D6\u5931\u8D25\u3002");
23608
+ });
23609
+ return () => {
23610
+ alive = false;
23611
+ controller.current?.abort();
23612
+ };
23613
+ }, []);
23614
+ const persist = async (conversation) => {
23615
+ activeConversation.current = conversation;
23616
+ setConversations((current2) => [
23617
+ conversation,
23618
+ ...current2.filter((item) => item.id !== conversation.id)
23619
+ ]);
23620
+ pendingWrite.current = pendingWrite.current.catch(() => void 0).then(() => savePrintDesignAiChatConversation(conversation));
23621
+ try {
23622
+ await pendingWrite.current;
23623
+ } catch {
23624
+ setError("\u5386\u53F2\u5BF9\u8BDD\u65E0\u6CD5\u4FDD\u5B58\u5230\u5F53\u524D\u6D4F\u89C8\u5668\u3002");
23625
+ }
23626
+ };
23627
+ const send = async (content, config) => {
23628
+ if (!content.trim() || busy) return;
23629
+ if (!config.baseUrl || !config.model) {
23630
+ setError("\u8BF7\u5148\u914D\u7F6E\u6A21\u578B\u3002");
23631
+ return;
23632
+ }
23633
+ const user = {
23634
+ id: nextMessageId.current++,
23635
+ role: "user",
23636
+ content: content.trim()
23637
+ };
23638
+ const now = Date.now();
23639
+ const previous = activeConversation.current;
23640
+ const conversation = {
23641
+ id: previous?.id ?? conversationId(),
23642
+ title: previous?.title ?? content.trim().slice(0, 36),
23643
+ createdAt: previous?.createdAt ?? now,
23644
+ updatedAt: now,
23645
+ messages: [...messages, user]
23646
+ };
23647
+ setActiveId(conversation.id);
23648
+ setMessages(conversation.messages);
23649
+ setBusy(true);
23650
+ setPendingModel(config.model);
23651
+ setStreaming({ content: "", reasoning: "", reasoningLength: 0 });
23652
+ setError("");
23653
+ void persist(conversation);
23654
+ const abort = new AbortController();
23655
+ controller.current = abort;
23656
+ try {
23657
+ const requestMessages = conversation.messages.map(
23658
+ ({ role, content: text, reasoning }) => ({
23659
+ role,
23660
+ content: text,
23661
+ ...reasoning ? { reasoning } : {}
23662
+ })
23663
+ );
23664
+ const requestAgentApi = createSelectionScopedAgentApi(
23665
+ agentApi,
23666
+ config.selection
23667
+ );
23668
+ const answer = provider.stream ? await provider.stream(
23669
+ config,
23670
+ requestMessages,
23671
+ (delta) => setStreaming(
23672
+ (current2) => current2 ? {
23673
+ content: current2.content + (delta.content ?? ""),
23674
+ reasoning: (current2.reasoning + (delta.reasoning ?? "")).slice(-LIVE_REASONING_LIMIT),
23675
+ reasoningLength: current2.reasoningLength + (delta.reasoning?.length ?? 0)
23676
+ } : current2
23677
+ ),
23678
+ abort.signal,
23679
+ requestAgentApi
23680
+ ) : {
23681
+ content: await provider.complete(
23682
+ config,
23683
+ requestMessages,
23684
+ abort.signal,
23685
+ requestAgentApi
23686
+ )
23687
+ };
23688
+ const completed = {
23689
+ ...conversation,
23690
+ updatedAt: Date.now(),
23691
+ messages: [
23692
+ ...conversation.messages,
23693
+ {
23694
+ id: nextMessageId.current++,
23695
+ role: "assistant",
23696
+ content: answer.content,
23697
+ model: config.model,
23698
+ ..."reasoning" in answer && answer.reasoning ? { reasoning: answer.reasoning } : {}
23699
+ }
23700
+ ]
23701
+ };
23702
+ setMessages(completed.messages);
23703
+ await persist(completed);
23704
+ } catch (cause) {
23705
+ if (!abort.signal.aborted)
23706
+ setError(cause instanceof Error ? cause.message : "\u5BF9\u8BDD\u5931\u8D25\u3002");
23707
+ } finally {
23708
+ controller.current = null;
23709
+ setBusy(false);
23710
+ setPendingModel("");
23711
+ setStreaming(null);
23712
+ }
23713
+ };
23714
+ const select = async (id) => {
23715
+ if (busy) return false;
23716
+ const conversation = conversations.find((item) => item.id === id) ?? await readPrintDesignAiChatConversation(id);
23717
+ if (!conversation) {
23718
+ setError("\u627E\u4E0D\u5230\u8FD9\u6BB5\u5386\u53F2\u5BF9\u8BDD\u3002");
23719
+ return false;
23720
+ }
23721
+ activeConversation.current = conversation;
23722
+ setActiveId(id);
23723
+ setMessages(conversation.messages);
23724
+ nextMessageId.current = Math.max(0, ...conversation.messages.map((item) => item.id)) + 1;
23725
+ setError("");
23726
+ return true;
23727
+ };
23728
+ const remove = async (id) => {
23729
+ if (busy) return;
23730
+ await pendingWrite.current.catch(() => void 0);
23731
+ await deletePrintDesignAiChatConversation(id);
23732
+ setConversations((current2) => current2.filter((item) => item.id !== id));
23733
+ if (activeConversation.current?.id === id) newConversation();
23734
+ };
23735
+ const newConversation = () => {
23736
+ if (busy) return;
23737
+ activeConversation.current = null;
23738
+ setActiveId(null);
23739
+ setMessages([]);
23740
+ nextMessageId.current = 1;
23741
+ setError("");
23742
+ };
23743
+ return {
23744
+ conversations,
23745
+ activeId,
23746
+ messages,
23747
+ busy,
23748
+ pendingModel,
23749
+ streaming,
23750
+ error,
23751
+ setError,
23752
+ send,
23753
+ select,
23754
+ remove,
23755
+ newConversation
23756
+ };
23757
+ }
23758
+ function PrintDesignAiChatPanel({
23759
+ options,
23760
+ onClose,
23761
+ panelWidths,
23762
+ onPanelWidthsChange,
23763
+ agentApi,
23764
+ selection
23765
+ }) {
23766
+ const provider = options.provider ?? defaultPrintDesignAiChatProvider;
23767
+ const [settings, setSettings] = react.useState(
23768
+ () => createInitialPrintDesignAiChatSettings(options.defaultConfig)
23769
+ );
23770
+ const [draftSettings, setDraftSettings] = react.useState(settings);
23771
+ const [draftWidths, setDraftWidths] = react.useState(panelWidths);
23772
+ const [storageReady, setStorageReady] = react.useState(false);
23773
+ const [settingsOpen, setSettingsOpen] = react.useState(false);
23774
+ const [modelLoading, setModelLoading] = react.useState(false);
23775
+ const [input, setInput] = react.useState("");
23776
+ const selectionKey = selection ? JSON.stringify([
23777
+ selection.pageId,
23778
+ ...selection.elements.map((item) => item.id)
23779
+ ]) : "";
23780
+ const [removedSelection, setRemovedSelection] = react.useState({ key: selectionKey, ids: [] });
23781
+ const removedIds = removedSelection.key === selectionKey ? removedSelection.ids : [];
23782
+ const attachedSelection = selection ? {
23783
+ ...selection,
23784
+ elements: selection.elements.filter(
23785
+ (item) => !removedIds.includes(item.id)
23786
+ )
23787
+ } : void 0;
23788
+ const session = useChatSession(provider, agentApi);
23789
+ const { messages, busy, error, setError } = session;
23790
+ const activeProfile = activePrintDesignAiChatProfile(settings);
23791
+ const draftProfile = activePrintDesignAiChatProfile(draftSettings);
23792
+ const modelsFor = (profile) => profile.models ?? [];
23793
+ react.useEffect(() => {
23794
+ setRemovedSelection({ key: selectionKey, ids: [] });
23795
+ }, [selectionKey]);
23796
+ react.useEffect(() => {
23797
+ let alive = true;
23798
+ const savedWidths = readPrintDesignAiChatPanelWidths();
23799
+ if (savedWidths) {
23800
+ onPanelWidthsChange(savedWidths);
23801
+ setDraftWidths(savedWidths);
23802
+ }
23803
+ void readPrintDesignAiChatSettings().then((saved) => {
23804
+ if (alive && saved) {
23805
+ setSettings(saved);
23806
+ setDraftSettings(saved);
23807
+ if (saved.panelWidths && !savedWidths) {
23808
+ onPanelWidthsChange(saved.panelWidths);
23809
+ setDraftWidths(saved.panelWidths);
23810
+ }
23811
+ } else if (alive && options.defaultConfig?.baseUrl && options.defaultConfig.key && options.defaultConfig.model) {
23812
+ void savePrintDesignAiChatSettings({
23813
+ ...settings,
23814
+ panelWidths
23815
+ }).catch(() => {
23816
+ });
23817
+ }
23818
+ }).catch(() => {
23819
+ if (alive) setError("\u5DF2\u4FDD\u5B58\u7684 AI \u914D\u7F6E\u65E0\u6CD5\u89E3\u5BC6\u3002");
23820
+ }).finally(() => {
23821
+ if (alive) setStorageReady(true);
23822
+ });
23823
+ return () => {
23824
+ alive = false;
23825
+ };
23826
+ }, []);
23827
+ react.useEffect(() => {
23828
+ if (!storageReady) return;
23829
+ const timer = window.setTimeout(() => {
23830
+ savePrintDesignAiChatPanelWidths(panelWidths);
23831
+ }, 400);
23832
+ return () => window.clearTimeout(timer);
23833
+ }, [panelWidths, storageReady]);
23834
+ const loadModels = async () => {
23835
+ setModelLoading(true);
23836
+ setError("");
23837
+ try {
23838
+ const selected = activePrintDesignAiChatProfile(draftSettings);
23839
+ const models = await provider.listModels(selected);
23840
+ setDraftSettings((current2) => ({
23841
+ ...current2,
23842
+ profiles: current2.profiles.map(
23843
+ (profile) => profile.id === selected.id && profile.baseUrl === selected.baseUrl && profile.key === selected.key ? { ...profile, models: [...new Set(models)] } : profile
23844
+ )
23845
+ }));
23846
+ } catch (cause) {
23847
+ setError(cause instanceof Error ? cause.message : "\u83B7\u53D6\u6A21\u578B\u5217\u8868\u5931\u8D25\u3002");
23848
+ } finally {
23849
+ setModelLoading(false);
23850
+ }
23851
+ };
23852
+ const saveConfig = async () => {
23853
+ const widths = normalizePrintDesignAiChatPanelWidths(draftWidths);
23854
+ const next = { ...draftSettings, panelWidths: widths };
23855
+ savePrintDesignAiChatPanelWidths(widths);
23856
+ onPanelWidthsChange(widths);
23857
+ setDraftWidths(widths);
23858
+ setSettings(next);
23859
+ setSettingsOpen(false);
23860
+ try {
23861
+ await savePrintDesignAiChatSettings(next);
23862
+ setError("");
23863
+ } catch {
23864
+ setError("\u6A21\u578B\u914D\u7F6E\u4EC5\u5728\u672C\u6B21\u4F1A\u8BDD\u53EF\u7528\uFF1B\u52A0\u5BC6\u4FDD\u5B58\u9700\u8981 HTTPS \u6216 localhost\u3002");
23865
+ }
23866
+ };
23867
+ const send = (event) => {
23868
+ event.preventDefault();
23869
+ const content = input.trim();
23870
+ if (!content || busy) return;
23871
+ const selected = activePrintDesignAiChatProfile(settings);
23872
+ if (!selected.baseUrl || !selected.model) {
23873
+ setSettingsOpen(true);
23874
+ setError("\u8BF7\u5148\u914D\u7F6E\u6A21\u578B\u3002");
23875
+ return;
23876
+ }
23877
+ setInput("");
23878
+ void session.send(content, {
23879
+ ...selected,
23880
+ ...attachedSelection ? { selection: attachedSelection } : {}
23881
+ });
23882
+ };
23883
+ const updateActiveProfile = (patch) => {
23884
+ const next = {
23885
+ ...settings,
23886
+ profiles: settings.profiles.map(
23887
+ (profile) => profile.id === activeProfile.id ? { ...profile, ...patch } : profile
23888
+ )
23889
+ };
23890
+ setSettings(next);
23891
+ setDraftSettings(next);
23892
+ void savePrintDesignAiChatSettings(next).catch(
23893
+ () => setError("\u6A21\u578B\u914D\u7F6E\u4EC5\u5728\u672C\u6B21\u4F1A\u8BDD\u53EF\u7528\uFF1B\u52A0\u5BC6\u4FDD\u5B58\u9700\u8981 HTTPS \u6216 localhost\u3002")
23894
+ );
23895
+ };
23896
+ return /* @__PURE__ */ jsxRuntime.jsxs("section", { className: "cc-print-design-ai-panel", "aria-label": "AI \u5BF9\u8BDD", children: [
23897
+ /* @__PURE__ */ jsxRuntime.jsxs("header", { className: "cc-print-design-ai-header", children: [
23898
+ /* @__PURE__ */ jsxRuntime.jsx("strong", { children: "AI \u5BF9\u8BDD" }),
23899
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
23900
+ /* @__PURE__ */ jsxRuntime.jsx(
23901
+ "button",
23902
+ {
23903
+ type: "button",
23904
+ disabled: busy,
23905
+ onClick: session.newConversation,
23906
+ children: "\u65B0\u5BF9\u8BDD"
23907
+ }
23908
+ ),
23909
+ /* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", "aria-label": "\u5173\u95ED AI \u5BF9\u8BDD", onClick: onClose, children: "\xD7" })
23910
+ ] })
23911
+ ] }),
23912
+ /* @__PURE__ */ jsxRuntime.jsx(
23913
+ VirtualMessages,
23914
+ {
23915
+ messages,
23916
+ currentModel: activeProfile.model,
23917
+ busy,
23918
+ pendingModel: session.pendingModel,
23919
+ streaming: session.streaming
23920
+ }
23921
+ ),
23922
+ /* @__PURE__ */ jsxRuntime.jsx(
23923
+ ChatSettingsDialog,
23924
+ {
23925
+ open: settingsOpen,
23926
+ settings: draftSettings,
23927
+ widths: draftWidths,
23928
+ models: modelsFor(draftProfile),
23929
+ modelLoading,
23930
+ conversations: session.conversations,
23931
+ activeId: session.activeId,
23932
+ busy,
23933
+ onSettingsChange: setDraftSettings,
23934
+ onWidthsChange: setDraftWidths,
23935
+ onLoadModels: () => void loadModels(),
23936
+ onSave: () => void saveConfig(),
23937
+ onClose: () => setSettingsOpen(false),
23938
+ onSelectConversation: (id) => {
23939
+ void session.select(id).then((selected) => {
23940
+ if (selected) setSettingsOpen(false);
23941
+ }).catch(
23942
+ (cause) => setError(
23943
+ cause instanceof Error ? cause.message : "\u5386\u53F2\u5BF9\u8BDD\u8BFB\u53D6\u5931\u8D25\u3002"
23944
+ )
23945
+ );
23946
+ },
23947
+ onDeleteConversation: (id) => {
23948
+ void session.remove(id).catch(
23949
+ (cause) => setError(
23950
+ cause instanceof Error ? cause.message : "\u5386\u53F2\u5BF9\u8BDD\u5220\u9664\u5931\u8D25\u3002"
23951
+ )
23952
+ );
23953
+ }
23954
+ }
23955
+ ),
23956
+ /* @__PURE__ */ jsxRuntime.jsx(ChatNoticeDialog, { message: error, onClose: () => setError("") }),
23957
+ /* @__PURE__ */ jsxRuntime.jsx(
23958
+ ChatComposer,
23959
+ {
23960
+ input,
23961
+ model: activeProfile.model,
23962
+ models: modelsFor(activeProfile),
23963
+ reasoningEffort: activeProfile.reasoningEffort,
23964
+ selection: attachedSelection,
23965
+ onRemoveSelectedElement: (id) => setRemovedSelection((current2) => ({
23966
+ key: selectionKey,
23967
+ ids: current2.key === selectionKey ? [.../* @__PURE__ */ new Set([...current2.ids, id])] : [id]
23968
+ })),
23969
+ onInputChange: setInput,
23970
+ onModelChange: (model) => updateActiveProfile({ model }),
23971
+ onReasoningEffortChange: (reasoningEffort) => updateActiveProfile({ reasoningEffort }),
23972
+ onOpenSettings: () => {
23973
+ setDraftSettings(settings);
23974
+ setDraftWidths(panelWidths);
23975
+ setSettingsOpen(true);
23976
+ },
23977
+ onSend: (event) => void send(event)
23978
+ }
23979
+ )
23980
+ ] });
23981
+ }
23982
+
23983
+ // src/ai-chat/index.ts
23984
+ function createPrintDesignAiChatPlugin(options = {}) {
23985
+ return {
23986
+ initialPanelWidths: normalizePrintDesignAiChatPanelWidths(
23987
+ options.panelWidths
23988
+ ),
23989
+ render: (context) => react.createElement(PrintDesignAiChatPanel, { options, ...context })
23990
+ };
23991
+ }
23992
+
21880
23993
  // src/react.ts
21881
23994
  var builtinReactTools = [
21882
23995
  debuggerTool,
@@ -21994,3 +24107,4 @@ var builtinPrintDesignPlugins = Object.freeze({
21994
24107
 
21995
24108
  exports.builtinPrintDesignPlugins = builtinPrintDesignPlugins;
21996
24109
  exports.builtinReactComponentPlugins = builtinReactComponentPlugins;
24110
+ exports.createPrintDesignAiChatPlugin = createPrintDesignAiChatPlugin;