@aglyn/plugins-ai 1.27.0 → 1.29.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/package.json +17 -17
  2. package/src/lib/components/ai-credits-prompt.component.js +4 -1
  3. package/src/lib/components/ai-credits-prompt.component.js.map +1 -1
  4. package/src/lib/components/ai-site-import-job.component.js +5 -2
  5. package/src/lib/components/ai-site-import-job.component.js.map +1 -1
  6. package/src/lib/components/ai-site-start-card.component.js +6 -3
  7. package/src/lib/components/ai-site-start-card.component.js.map +1 -1
  8. package/src/lib/components/assist-build-card.component.js +4 -1
  9. package/src/lib/components/assist-build-card.component.js.map +1 -1
  10. package/src/lib/components/assist-edit-canvas.d.ts +12 -0
  11. package/src/lib/components/assist-edit-canvas.js +38 -7
  12. package/src/lib/components/assist-edit-canvas.js.map +1 -1
  13. package/src/lib/components/assist-jobs-drawer.component.js +4 -1
  14. package/src/lib/components/assist-jobs-drawer.component.js.map +1 -1
  15. package/src/lib/components/assist-panel.component.js +5 -2
  16. package/src/lib/components/assist-panel.component.js.map +1 -1
  17. package/src/lib/declarations.server.js +17 -0
  18. package/src/lib/declarations.server.js.map +1 -1
  19. package/src/lib/jobs/ai-job-drafts.d.ts +5 -11
  20. package/src/lib/jobs/ai-job-drafts.js +8 -25
  21. package/src/lib/jobs/ai-job-drafts.js.map +1 -1
  22. package/src/lib/jobs/ai-job-edit-step.d.ts +95 -5
  23. package/src/lib/jobs/ai-job-edit-step.js +88 -17
  24. package/src/lib/jobs/ai-job-edit-step.js.map +1 -1
  25. package/src/lib/model/ai-edit-job.d.ts +27 -0
  26. package/src/lib/model/ai-edit-job.js +45 -23
  27. package/src/lib/model/ai-edit-job.js.map +1 -1
  28. package/src/lib/model/ai-layout-menus.d.ts +10 -0
  29. package/src/lib/model/ai-layout-menus.js +23 -2
  30. package/src/lib/model/ai-layout-menus.js.map +1 -1
  31. package/src/lib/model/assist-edit.d.ts +2 -0
  32. package/src/lib/model/assist-edit.js.map +1 -1
  33. package/src/lib/runtime/ai-node-tree.d.ts +25 -1
  34. package/src/lib/runtime/ai-node-tree.js +39 -14
  35. package/src/lib/runtime/ai-node-tree.js.map +1 -1
  36. package/src/lib/runtime/ai-palette.generated.js +84 -2
  37. package/src/lib/runtime/ai-palette.generated.js.map +1 -1
  38. package/src/lib/server/ai-page-content.d.ts +83 -0
  39. package/src/lib/server/ai-page-content.js +765 -0
  40. package/src/lib/server/ai-page-content.js.map +1 -0
  41. package/src/lib/server/ai-usage.js +7 -1
  42. package/src/lib/server/ai-usage.js.map +1 -1
  43. package/src/lib/server/assist-edit.d.ts +136 -1
  44. package/src/lib/server/assist-edit.js +124 -47
  45. package/src/lib/server/assist-edit.js.map +1 -1
  46. package/src/lib/usage/ai-usage-wire.d.ts +15 -0
  47. package/src/lib/usage/ai-usage-wire.js +21 -0
  48. package/src/lib/usage/ai-usage-wire.js.map +1 -1
@@ -237,6 +237,7 @@ const strictObject = (properties)=>({
237
237
  [NODE_ANIMATION_STAGGER_PROP]: 'switch',
238
238
  [NODE_ANIMATION_REPEAT_PROP]: 'switch'
239
239
  };
240
+ /** The motion settings every element takes and what each holds, for a reader that lists them (AGL-4235). */ export const ASSIST_EDIT_MOTION_SETTINGS = MOTION_SETTINGS;
240
241
  /**
241
242
  * The line of the edit protocol that offers motion: a pure function of the
242
243
  * vocabulary, so it sits in the cached prefix with the rest of the block.
@@ -892,18 +893,22 @@ const DELAYED_STEPS = new Set([
892
893
  targets
893
894
  };
894
895
  }
896
+ /** The words each refusal is given in, after the change's label. */ export const ASSIST_EDIT_CLOSED_WORLD_REFUSALS = {
897
+ unknown: 'names an element that is not on the canvas described',
898
+ root: 'cannot act on the document root itself',
899
+ removed: 'acts on an element an earlier change removes'
900
+ };
895
901
  /**
896
- * The tool's input, held to the closed world: every element an op names is
897
- * one the request described, and an op the structure alone refuses is
898
- * dropped with its reason.
899
- */ function parseEditInput(input, context, kind) {
900
- var _input_summary;
902
+ * The closed world, for every door that turns a request into ops (AGL-4235):
903
+ * an op names only an element the request described, never the document root
904
+ * itself, and never one an earlier op removed. One implementation, for the
905
+ * model's tool call and for the public API's edits alike, so the two cannot
906
+ * disagree about what an edit may touch.
907
+ */ export function assistEditClosedWorld(context) {
901
908
  const byId = new Map(context.nodes.map((node)=>[
902
909
  node.id,
903
910
  node
904
911
  ]));
905
- const dropped = [];
906
- const pending = [];
907
912
  /** Ids removed by an earlier op; nothing later may act inside them. */ const removed = new Set();
908
913
  /**
909
914
  * Where an earlier move put an element: its new parent. The canvas applies
@@ -924,27 +929,57 @@ const DELAYED_STEPS = new Set([
924
929
  return ids;
925
930
  };
926
931
  const insideRemoved = (nodeId)=>lineage(nodeId).some((id)=>removed.has(id));
932
+ return {
933
+ byId,
934
+ element (nodeId) {
935
+ if (typeof nodeId !== 'string' || !byId.has(nodeId)) return 'unknown';
936
+ if (nodeId === CANVAS_ROOT_ELEMENT_ID) return 'root';
937
+ if (insideRemoved(nodeId)) return 'removed';
938
+ return byId.get(nodeId);
939
+ },
940
+ parent (parentId) {
941
+ if (typeof parentId !== 'string' || !byId.has(parentId) || insideRemoved(parentId)) return null;
942
+ return byId.get(parentId);
943
+ },
944
+ movesInsideItself: (nodeId, parentId)=>lineage(parentId).includes(nodeId),
945
+ remove: (nodeId)=>void removed.add(nodeId),
946
+ move: (nodeId, parentId)=>void movedTo.set(nodeId, parentId)
947
+ };
948
+ }
949
+ /** The longest layer name an element takes. */ export const ASSIST_EDIT_LAYER_NAME_CHARS = LAYER_NAME_CHARS;
950
+ /**
951
+ * Why a layer name written by a caller that is not a model is refused, or
952
+ * null (AGL-4235): the rule the model's rename is held to — no markup, not
953
+ * empty, at most {@link ASSIST_EDIT_LAYER_NAME_CHARS} characters — where the
954
+ * model's name is cleaned to fit, this one must already fit.
955
+ */ export function assistEditLayerNameRefusal(name) {
956
+ if (!name.trim()) return 'is empty';
957
+ if (MARKUP.test(name)) return 'carries markup';
958
+ if (cleanText(name, Number.MAX_SAFE_INTEGER) !== name) return 'carries line breaks, or spaces at its ends or in a row';
959
+ if (name.length > LAYER_NAME_CHARS) return `is longer than ${LAYER_NAME_CHARS} characters`;
960
+ return null;
961
+ }
962
+ /**
963
+ * The tool's input, held to the closed world: every element an op names is
964
+ * one the request described, and an op the structure alone refuses is
965
+ * dropped with its reason.
966
+ */ function parseEditInput(input, context, kind) {
967
+ var _input_summary;
968
+ const world = assistEditClosedWorld(context);
969
+ const dropped = [];
970
+ const pending = [];
927
971
  const described = (nodeId, label)=>{
928
- if (typeof nodeId !== 'string' || !byId.has(nodeId)) {
929
- dropped.push(`${label}: names an element that is not on the canvas described`);
972
+ const node = world.element(nodeId);
973
+ if (typeof node === 'string') {
974
+ dropped.push(`${label}: ${ASSIST_EDIT_CLOSED_WORLD_REFUSALS[node]}`);
930
975
  return null;
931
976
  }
932
- if (nodeId === CANVAS_ROOT_ELEMENT_ID) {
933
- dropped.push(`${label}: cannot act on the document root itself`);
934
- return null;
935
- }
936
- if (insideRemoved(nodeId)) {
937
- dropped.push(`${label}: acts on an element an earlier change removes`);
938
- return null;
939
- }
940
- return byId.get(nodeId);
977
+ return node;
941
978
  };
942
979
  const describedParent = (parentId, label, verb)=>{
943
- if (typeof parentId !== 'string' || !byId.has(parentId) || insideRemoved(parentId)) {
944
- dropped.push(`${label}: ${verb} an element that is not on the canvas described`);
945
- return null;
946
- }
947
- return byId.get(parentId);
980
+ const parent = world.parent(parentId);
981
+ if (!parent) dropped.push(`${label}: ${verb} an element that is not on the canvas described`);
982
+ return parent;
948
983
  };
949
984
  const rawOps = Array.isArray(input['ops']) ? input['ops'] : [];
950
985
  if (rawOps.length > ASSIST_EDIT_MAX_OPS) {
@@ -996,7 +1031,7 @@ const DELAYED_STEPS = new Set([
996
1031
  {
997
1032
  const node = described(raw['nodeId'], label);
998
1033
  if (!node) return;
999
- removed.add(node.id);
1034
+ world.remove(node.id);
1000
1035
  pending.push({
1001
1036
  op,
1002
1037
  nodeId: node.id,
@@ -1027,11 +1062,11 @@ const DELAYED_STEPS = new Set([
1027
1062
  if (!node) return;
1028
1063
  const parent = describedParent(raw['parentId'], label, 'moves into');
1029
1064
  if (!parent) return;
1030
- if (lineage(parent.id).includes(node.id)) {
1065
+ if (world.movesInsideItself(node.id, parent.id)) {
1031
1066
  dropped.push(`${label}: moves an element inside itself`);
1032
1067
  return;
1033
1068
  }
1034
- movedTo.set(node.id, parent.id);
1069
+ world.move(node.id, parent.id);
1035
1070
  pending.push({
1036
1071
  op,
1037
1072
  nodeId: node.id,
@@ -1117,7 +1152,10 @@ const DELAYED_STEPS = new Set([
1117
1152
  {
1118
1153
  const node = described(raw['nodeId'], label);
1119
1154
  if (!node) return;
1120
- const built = interactionOf(raw, label, (id)=>typeof id === 'string' && byId.has(id) && id !== CANVAS_ROOT_ELEMENT_ID && !insideRemoved(id) ? byId.get(id) : null);
1155
+ const built = interactionOf(raw, label, (id)=>{
1156
+ const target = world.element(id);
1157
+ return typeof target === 'string' ? null : target;
1158
+ });
1121
1159
  if (typeof built === 'string') {
1122
1160
  dropped.push(built);
1123
1161
  return;
@@ -1210,15 +1248,22 @@ const repeatOf = (props)=>{
1210
1248
  * `validateAiNodeTree`, inside the real ancestor chain; every prop and style
1211
1249
  * patch through `validateAiNodePatch`; every move through the palette's
1212
1250
  * lineage rule. A violation drops its op and says why.
1213
- */ function validatePendingEdit(output) {
1251
+ *
1252
+ * `strict` is a caller that is not a model (AGL-4235): the public API, whose
1253
+ * request says exactly what to write. Every repair the validators would make
1254
+ * for a model — a setting dropped, text cut to its limit, a value coerced or
1255
+ * normalized — is a violation instead, one per repair, and values are held to
1256
+ * their types as written. The same validators and the same rules otherwise.
1257
+ */ export function validatePendingEdit(output) {
1214
1258
  var _output_datasets, _scope_datasets, _scope_datasets1;
1215
- var _output_datasets1;
1259
+ var _output_references, _output_references1, _output_datasets1;
1216
1260
  const byId = new Map(output.context.nodes.map((node)=>[
1217
1261
  node.id,
1218
1262
  node
1219
1263
  ]));
1220
1264
  const ops = [];
1221
1265
  const violations = [];
1266
+ const strict = output.strict === true;
1222
1267
  const scope = (_output_datasets = output.datasets) != null ? _output_datasets : {};
1223
1268
  // The datasets a repeat may name (AGL-3616): the ones the door read, and
1224
1269
  // any the canvas already repeats over, which the site holds by definition.
@@ -1226,18 +1271,39 @@ const repeatOf = (props)=>{
1226
1271
  ...((_scope_datasets = scope.datasets) != null ? _scope_datasets : []).map((dataset)=>dataset.id),
1227
1272
  ...canvasRepeats(output.context.nodes)
1228
1273
  ]);
1229
- const treeContext = {
1274
+ const treeContext = _extends({
1230
1275
  datasetIds,
1231
1276
  // A record's photo binds whole as an Image's src, from a picture field alone.
1232
1277
  bindingTokens: ((_scope_datasets1 = scope.datasets) != null ? _scope_datasets1 : []).flatMap((dataset)=>dataset.imageField ? [
1233
1278
  `{{item.${dataset.imageField}}}`
1234
1279
  ] : [])
1235
- };
1280
+ }, ((_output_references = output.references) == null ? void 0 : _output_references.screenIds) ? {
1281
+ screenIds: output.references.screenIds
1282
+ } : {}, ((_output_references1 = output.references) == null ? void 0 : _output_references1.mediaScopes) ? {
1283
+ mediaScopes: output.references.mediaScopes
1284
+ } : {}, strict ? {
1285
+ exact: true
1286
+ } : {});
1287
+ // A patch is held to the same references as a new element; the chat door
1288
+ // names none, and its patches stay as they were.
1289
+ const patchContext = strict || output.references ? treeContext : undefined;
1236
1290
  // Tokens are judged only where the door read the site's datasets: a chat
1237
1291
  // canvas without them may be a record page this check cannot tell apart.
1238
1292
  const judgesTokens = ((_output_datasets1 = output.datasets) == null ? void 0 : _output_datasets1.datasets) !== undefined;
1239
1293
  output.pending.forEach((pending, position)=>{
1240
- const label = `edit change ${position + 1}`;
1294
+ /** The op is refused, with one reason. */ const refuse = (message)=>void violations.push({
1295
+ position,
1296
+ message
1297
+ });
1298
+ /** A strict caller refuses every repair, each named; true when there was one. */ const refusedRepairs = (repairs)=>{
1299
+ if (!strict || !repairs.length) return false;
1300
+ for (const repair of repairs)violations.push({
1301
+ position,
1302
+ message: repair,
1303
+ repair: true
1304
+ });
1305
+ return true;
1306
+ };
1241
1307
  switch(pending.op){
1242
1308
  case 'insertSubtree':
1243
1309
  {
@@ -1246,7 +1312,7 @@ const repeatOf = (props)=>{
1246
1312
  // against the element the subtree will actually sit in.
1247
1313
  const chain = chainTo(pending.parentId, byId);
1248
1314
  if (!chain) {
1249
- violations.push(`${label}: the element it adds into is not fully described`);
1315
+ refuse('the element it adds into is not fully described');
1250
1316
  return;
1251
1317
  }
1252
1318
  const wrapped = _extends({}, pending.tree.nodes);
@@ -1266,9 +1332,10 @@ const repeatOf = (props)=>{
1266
1332
  nodes: wrapped
1267
1333
  }, output.surface, treeContext);
1268
1334
  if (result.ok === false) {
1269
- violations.push(`${label}: ${result.error}`);
1335
+ refuse(result.error);
1270
1336
  return;
1271
1337
  }
1338
+ if (refusedRepairs(result.repairs)) return;
1272
1339
  // The chain is linear, so its minted copy is walked by first child
1273
1340
  // down to the subtree root.
1274
1341
  let rootId = result.rootId;
@@ -1282,9 +1349,13 @@ const repeatOf = (props)=>{
1282
1349
  ] : [];
1283
1350
  while(queue.length){
1284
1351
  var _node_nodes, _node_nodes1;
1352
+ var _pending_tree_nodes_result_sourceIds_id;
1285
1353
  const id = queue.shift();
1286
1354
  const node = result.nodes[id];
1287
1355
  if (!node) continue;
1356
+ // A layer name the request gave a new element: the validators keep
1357
+ // none, so it is carried from the element it was written on.
1358
+ const name = (_pending_tree_nodes_result_sourceIds_id = pending.tree.nodes[result.sourceIds[id]]) == null ? void 0 : _pending_tree_nodes_result_sourceIds_id['name'];
1288
1359
  nodes[id] = _extends({
1289
1360
  $id: id,
1290
1361
  componentId: node.componentId
@@ -1300,11 +1371,13 @@ const repeatOf = (props)=>{
1300
1371
  sx: node.sx
1301
1372
  } : {}, node.hidden ? {
1302
1373
  hidden: true
1374
+ } : {}, typeof name === 'string' && name ? {
1375
+ name
1303
1376
  } : {});
1304
1377
  queue.push(...(_node_nodes1 = node.nodes) != null ? _node_nodes1 : []);
1305
1378
  }
1306
1379
  if (!rootId || !Object.keys(nodes).length) {
1307
- violations.push(`${label}: nothing survived validation`);
1380
+ refuse('nothing survived validation');
1308
1381
  return;
1309
1382
  }
1310
1383
  if (judgesTokens) {
@@ -1323,7 +1396,7 @@ const repeatOf = (props)=>{
1323
1396
  ...above
1324
1397
  ] : null, scope);
1325
1398
  if (refusal) {
1326
- violations.push(`${label}: ${refusal}`);
1399
+ refuse(refusal);
1327
1400
  return;
1328
1401
  }
1329
1402
  }
@@ -1343,7 +1416,9 @@ const repeatOf = (props)=>{
1343
1416
  // Motion settings are held to the animation vocabulary, the rest to the palette (AGL-3838).
1344
1417
  const { motion, rest, refused } = assistEditMotionPatch(pending.props);
1345
1418
  if (refused.length) {
1346
- violations.push(`${label}: ${refused.join('; ')}`);
1419
+ // A strict caller is told each setting apart; the card reads one line.
1420
+ if (strict) refused.forEach(refuse);
1421
+ else refuse(refused.join('; '));
1347
1422
  return;
1348
1423
  }
1349
1424
  // A repeat's dataset is a reference, which the palette leaves off: it
@@ -1353,7 +1428,7 @@ const repeatOf = (props)=>{
1353
1428
  const named = typeof rest[AI_REPEAT_DATASET_PROP] === 'string' ? String(rest[AI_REPEAT_DATASET_PROP]).trim() : '';
1354
1429
  delete rest[AI_REPEAT_DATASET_PROP];
1355
1430
  if (!named || !datasetIds.has(named)) {
1356
- violations.push(`${label}: ${AI_REPEAT_DATASET_PROP} names a dataset this site does not have`);
1431
+ refuse(`${AI_REPEAT_DATASET_PROP} names a dataset this site does not have`);
1357
1432
  return;
1358
1433
  }
1359
1434
  repeat[AI_REPEAT_DATASET_PROP] = named;
@@ -1362,13 +1437,14 @@ const repeatOf = (props)=>{
1362
1437
  if (Object.keys(rest).length) {
1363
1438
  const result = validateAiNodePatch(pending.componentId, {
1364
1439
  props: rest
1365
- });
1440
+ }, patchContext);
1366
1441
  if (result.ok === false) {
1367
- violations.push(`${label}: ${result.error}`);
1442
+ refuse(result.error);
1368
1443
  return;
1369
1444
  }
1445
+ if (refusedRepairs(result.repairs)) return;
1370
1446
  if (!Object.keys(result.props).length && !Object.keys(repeat).length) {
1371
- violations.push(`${label}: ${result.repairs.length ? result.repairs.slice(0, 2).join('; ') : 'none of the settings named are ones this element takes'}`);
1447
+ refuse(result.repairs.length ? result.repairs.slice(0, 2).join('; ') : 'none of the settings named are ones this element takes');
1372
1448
  return;
1373
1449
  }
1374
1450
  props = _extends({}, result.props, props);
@@ -1383,7 +1459,7 @@ const repeatOf = (props)=>{
1383
1459
  ...above
1384
1460
  ] : null, scope);
1385
1461
  if (refusal) {
1386
- violations.push(`${label}: ${refusal}`);
1462
+ refuse(refusal);
1387
1463
  return;
1388
1464
  }
1389
1465
  }
@@ -1396,16 +1472,17 @@ const repeatOf = (props)=>{
1396
1472
  {
1397
1473
  const result = validateAiNodePatch(pending.componentId, {
1398
1474
  sx: pending.sx
1399
- });
1475
+ }, patchContext);
1400
1476
  if (result.ok === false) {
1401
- violations.push(`${label}: ${result.error}`);
1477
+ refuse(result.error);
1402
1478
  return;
1403
1479
  }
1480
+ if (refusedRepairs(result.repairs)) return;
1404
1481
  // The first repairs say why a patch came out empty — a style the
1405
1482
  // element does not take reads differently from one that carried
1406
1483
  // markup, and the reader of `dropped` needs to tell them apart.
1407
1484
  if (!result.sx) {
1408
- violations.push(`${label}: ${result.repairs.length ? result.repairs.slice(0, 2).join('; ') : 'none of the styles named are allowed'}`);
1485
+ refuse(result.repairs.length ? result.repairs.slice(0, 2).join('; ') : 'none of the styles named are allowed');
1409
1486
  return;
1410
1487
  }
1411
1488
  ops.push(_extends({}, pending, {
@@ -1421,7 +1498,7 @@ const repeatOf = (props)=>{
1421
1498
  const into = linealActorOf(parent.componentId);
1422
1499
  const accepts = parent.id === CANVAS_ROOT_ELEMENT_ID || ((_AI_PALETTE_parent_componentId = AI_PALETTE[parent.componentId]) == null ? void 0 : _AI_PALETTE_parent_componentId.acceptsChildren) === true;
1423
1500
  if (!child || !into || !accepts || !linealRelationshipPermits(child, into)) {
1424
- violations.push(`${label}: that element cannot be placed there`);
1501
+ refuse('that element cannot be placed there');
1425
1502
  return;
1426
1503
  }
1427
1504
  ops.push(pending);
@@ -1456,7 +1533,7 @@ const repeatOf = (props)=>{
1456
1533
  });
1457
1534
  const reasons = [
1458
1535
  ...parsed.dropped,
1459
- ...validated.violations
1536
+ ...validated.violations.map(({ position, message })=>`edit change ${position + 1}: ${message}`)
1460
1537
  ];
1461
1538
  const violations = reasons.map((message)=>({
1462
1539
  rule: null,