@aglyn/plugins-ai 1.21.0 → 1.22.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +18 -18
- package/src/lib/jobs/ai-job-import-step.d.ts +8 -0
- package/src/lib/jobs/ai-job-import-step.js +19 -2
- package/src/lib/jobs/ai-job-import-step.js.map +1 -1
- package/src/lib/jobs/ai-job-page-language.d.ts +8 -0
- package/src/lib/jobs/ai-job-page-language.js +127 -26
- package/src/lib/jobs/ai-job-page-language.js.map +1 -1
- package/src/lib/jobs/ai-job-page-step.d.ts +10 -0
- package/src/lib/jobs/ai-job-page-step.js +23 -1
- package/src/lib/jobs/ai-job-page-step.js.map +1 -1
- package/src/lib/jobs/ai-site-import-actions.d.ts +12 -3
- package/src/lib/jobs/ai-site-import-actions.js +43 -18
- package/src/lib/jobs/ai-site-import-actions.js.map +1 -1
- package/src/lib/jobs/ai-site-import-improve.d.ts +170 -5
- package/src/lib/jobs/ai-site-import-improve.js +508 -46
- package/src/lib/jobs/ai-site-import-improve.js.map +1 -1
- package/src/lib/layout-language/ai-layout-compiler.d.ts +6 -0
- package/src/lib/layout-language/ai-layout-compiler.js +10 -4
- package/src/lib/layout-language/ai-layout-compiler.js.map +1 -1
- package/src/lib/layout-language/ai-layout-frame.js +11 -2
- package/src/lib/layout-language/ai-layout-frame.js.map +1 -1
- package/src/lib/layout-language/ai-layout-gaps.d.ts +27 -0
- package/src/lib/layout-language/ai-layout-gaps.js +124 -0
- package/src/lib/layout-language/ai-layout-gaps.js.map +1 -1
- package/src/lib/layout-language/ai-layout-language.d.ts +5 -0
- package/src/lib/layout-language/ai-layout-language.js +46 -1
- package/src/lib/layout-language/ai-layout-language.js.map +1 -1
- package/src/lib/model/ai-site-import-fidelity.d.ts +14 -1
- package/src/lib/model/ai-site-import-fidelity.js +25 -1
- package/src/lib/model/ai-site-import-fidelity.js.map +1 -1
- package/src/lib/runtime/ai-doctrine.d.ts +3 -1
- package/src/lib/runtime/ai-doctrine.js +4 -1
- package/src/lib/runtime/ai-doctrine.js.map +1 -1
- package/src/lib/site-import/fixtures/site-import-fidelity-replay.js +9 -8
- package/src/lib/site-import/fixtures/site-import-fidelity-replay.js.map +1 -1
- package/src/lib/site-import/site-import-page.d.ts +2 -2
- package/src/lib/site-import/site-import-page.js +42 -2
- package/src/lib/site-import/site-import-page.js.map +1 -1
|
@@ -30,6 +30,7 @@ import type { AiSystemBlock } from '../runtime/ai-runtime';
|
|
|
30
30
|
import { type AiSiteImportDocument } from './ai-site-import-document';
|
|
31
31
|
import { type AiSiteImportDesigned } from './ai-site-import-compile';
|
|
32
32
|
import { type AiSiteImportAddedSection, type AiSiteImportPagePictures, type AiSiteImportRedesign, type AiSiteImportWords } from '../model/ai-site-import';
|
|
33
|
+
import { type AiSiteImportImproved } from './ai-site-import-improve';
|
|
33
34
|
/**
|
|
34
35
|
* A page built in the compact layout language (AGL-3660): the page step's
|
|
35
36
|
* pass for a site's page units — a guided start's and a build's — in place of
|
|
@@ -468,6 +469,13 @@ export declare function aiSiteImportWordingMaxTokens(model: string): number;
|
|
|
468
469
|
* my wording on, and never a policy page, by its address or its title.
|
|
469
470
|
*/
|
|
470
471
|
export declare function aiImportedPageRewords(doc: Pick<AiSiteImportDocument, 'build' | 'finish' | 'wording' | 'title' | 'url'>, screen: Pick<AiBuildPlanScreen, 'slug' | 'title'>): boolean;
|
|
472
|
+
/**
|
|
473
|
+
* The one line a redesign that passed logs (AGL-4152): how many sections it
|
|
474
|
+
* drew, each block its read left out and why, what code mended (a section
|
|
475
|
+
* left a heading alone, a card row evened), and how many pictures asked for
|
|
476
|
+
* in words passed the page's cap. Never a word of the page beyond a heading.
|
|
477
|
+
*/
|
|
478
|
+
export declare function aiSiteImportRedesignPassed(value: Pick<AiSiteImportImproved<Pick<AiLayoutPageBuilt, 'settled'>>, 'built' | 'page' | 'read'>, credits?: number): Record<string, unknown>;
|
|
471
479
|
/**
|
|
472
480
|
* The ceiling a redesign is asked at on this model (AGL-4152): what the page
|
|
473
481
|
* step's time holds of a whole page's design and words, and its one re-ask.
|
|
@@ -27,8 +27,9 @@ import { aiLayoutPromisedCopyViolations, aiLayoutPromisedSections } from "../lay
|
|
|
27
27
|
import { aiLayoutStoredTree } from "../layout-language/ai-layout-store.js";
|
|
28
28
|
import { AI_GENERATION_MAX_ATTEMPTS } from "../runtime/ai-generation-bounds.js";
|
|
29
29
|
import { AI_STEP_TIERS } from "../providers/catalog.js";
|
|
30
|
+
import { AI_ROUTING_TABLE } from "../providers/routing.js";
|
|
30
31
|
import { aiCacheWriteHourSum } from "../providers/cache-write-hour.js";
|
|
31
|
-
import { aiDoctrineNeedsInputMessage, runValidatedGeneration } from "../runtime/ai-doctrine.js";
|
|
32
|
+
import { aiDoctrineNeedsInputMessage, aiDoctrineScopeFor, aiDoctrineSystemBlocks, runValidatedGeneration } from "../runtime/ai-doctrine.js";
|
|
32
33
|
import { aiSettleMechanicalRules, aiSettleUnrelatedScreenLinks, validateAiDoctrineTree } from "../runtime/ai-doctrine-validators.js";
|
|
33
34
|
import { aiSiteKindDesignLines, aiSiteKindOfInputs } from "../model/ai-site-kinds.js";
|
|
34
35
|
import { aiSiteSeed } from "../model/ai-site-look.js";
|
|
@@ -45,7 +46,7 @@ import { AI_SITE_IMPORT_DESIGN_MAX_CHARS, aiCompileImportedPage, aiSiteImportDes
|
|
|
45
46
|
import { aiSiteImportPageIsLegal, AI_SITE_IMPORT_LAYOUT_KEPT, AI_SITE_IMPORT_PROPOSED_NOT_WRITTEN } from "../model/ai-site-import.js";
|
|
46
47
|
import { siteImportFidelity } from "../model/ai-site-import-fidelity.js";
|
|
47
48
|
import { aiGenerationMaxTokensWithin, aiGenerationWorstCaseMs } from "./ai-job-budget.js";
|
|
48
|
-
import { AI_SITE_IMPORT_IMPROVE_KIND, AI_SITE_IMPORT_IMPROVE_MOST_TOKENS, AI_SITE_IMPORT_IMPROVE_TOOL, aiSiteImportImproveCheck, aiSiteImportImproveDestinations, aiSiteImportImproveDigest, aiSiteImportImproveInstructions, aiSiteImportImproveLedger, aiSiteImportImprovePrompt, aiSiteImportImproveScope, aiSiteImportImprovedMisses,
|
|
49
|
+
import { AI_SITE_IMPORT_IMPROVE_KIND, AI_SITE_IMPORT_IMPROVE_MOST_TOKENS, AI_SITE_IMPORT_IMPROVE_TOOL, aiSiteImportImproveCheck, aiSiteImportImproveDestinations, aiSiteImportImproveDigest, aiSiteImportImproveInstructions, aiSiteImportImproveLedger, aiSiteImportImprovePrompt, aiSiteImportImproveScope, aiSiteImportImprovedMisses, aiSiteImportImproveCredits, aiSiteImportImproveReaskNeeds, aiSiteImportImproveReaskTokens, aiSiteImportImproveRoleLines, aiSiteImportImproveRoom, aiSiteImportImproveSizeLines, aiSiteImportImproveOnlySoft, AI_SITE_IMPORT_IMPROVE_CUT_OFF_SMALLER, aiSiteImportNewSectionsWanted, aiSiteImportPageRoleOf, aiSiteImportMeaningShare, aiSiteImportRedesignWhy } from "./ai-site-import-improve.js";
|
|
49
50
|
import { AI_SITE_IMPORT_WORDING_INSTRUCTIONS, AI_SITE_IMPORT_WORDING_KIND, AI_SITE_IMPORT_WORDING_TOOL, aiSiteImportWordingCheck, aiSiteImportWordingPage, aiSiteImportWordingPrompt, aiSiteImportWordingTokens } from "./ai-site-import-wording.js";
|
|
50
51
|
/**
|
|
51
52
|
* A page built in the compact layout language (AGL-3660): the page step's
|
|
@@ -1295,6 +1296,24 @@ const NO_USAGE = {
|
|
|
1295
1296
|
})
|
|
1296
1297
|
});
|
|
1297
1298
|
}
|
|
1299
|
+
/** What a picture asked for in words past the page's cap is settled as, by the compiler (`ai-layout-compiler.ts`). */ const PAST_THE_CAP = /^a picture past the page's \d+; left out$/;
|
|
1300
|
+
/**
|
|
1301
|
+
* The one line a redesign that passed logs (AGL-4152): how many sections it
|
|
1302
|
+
* drew, each block its read left out and why, what code mended (a section
|
|
1303
|
+
* left a heading alone, a card row evened), and how many pictures asked for
|
|
1304
|
+
* in words passed the page's cap. Never a word of the page beyond a heading.
|
|
1305
|
+
*/ export function aiSiteImportRedesignPassed(value, credits) {
|
|
1306
|
+
var _value_read;
|
|
1307
|
+
const dropped = ((_value_read = value.read) != null ? _value_read : []).map((note)=>`${note.at}: ${note.what}`);
|
|
1308
|
+
return _extends({
|
|
1309
|
+
sections: value.page.given.sections.length,
|
|
1310
|
+
readDropped: dropped,
|
|
1311
|
+
mended: value.page.mended,
|
|
1312
|
+
pastCap: value.built.settled.filter((note)=>PAST_THE_CAP.test(note.what)).length
|
|
1313
|
+
}, credits !== undefined ? {
|
|
1314
|
+
credits
|
|
1315
|
+
} : {});
|
|
1316
|
+
}
|
|
1298
1317
|
/**
|
|
1299
1318
|
* The ceiling a redesign is asked at on this model (AGL-4152): what the page
|
|
1300
1319
|
* step's time holds of a whole page's design and words, and its one re-ask.
|
|
@@ -1346,26 +1365,55 @@ const NO_USAGE = {
|
|
|
1346
1365
|
kind: (_ref = (_doc_plan1 = doc.plan) == null ? void 0 : _doc_plan1.site.kind) != null ? _ref : null,
|
|
1347
1366
|
seed: aiSiteSeed(input.job.$id)
|
|
1348
1367
|
}));
|
|
1349
|
-
const
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1368
|
+
const promptOf = (sizeLines)=>aiSiteImportImprovePrompt({
|
|
1369
|
+
screen: input.screen,
|
|
1370
|
+
doc,
|
|
1371
|
+
ledger,
|
|
1372
|
+
destinations: aiSiteImportImproveDestinations(doc, ledger),
|
|
1373
|
+
kindLines: aiSiteKindDesignLines(input.job.inputs),
|
|
1374
|
+
seed: input.job.$id.slice(-6),
|
|
1375
|
+
roleLines,
|
|
1376
|
+
sizeLines
|
|
1377
|
+
});
|
|
1358
1378
|
// The page's ceiling holds in code: the answer asks no more than it buys, and a re-ask it cannot pay for is not asked.
|
|
1379
|
+
// Its input is priced from every byte the request sends, as the doctrine's loop sends it (AGL-4152).
|
|
1359
1380
|
const most = aiSiteImportImproveMaxTokens(input.model);
|
|
1360
|
-
const
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
input: aiSiteImportImproveInputUsage({
|
|
1364
|
-
systemChars: instructions.reduce((sum, block)=>sum + block.text.length, 0),
|
|
1365
|
-
promptChars: prompt.length
|
|
1366
|
-
}),
|
|
1367
|
-
most
|
|
1381
|
+
const system = aiDoctrineSystemBlocks(undefined, {
|
|
1382
|
+
instructions,
|
|
1383
|
+
scope: aiDoctrineScopeFor(AI_SITE_IMPORT_IMPROVE_KIND)
|
|
1368
1384
|
});
|
|
1385
|
+
const roomOf = (prompt)=>aiSiteImportImproveRoom({
|
|
1386
|
+
model: input.model,
|
|
1387
|
+
spent: spend.usage,
|
|
1388
|
+
system,
|
|
1389
|
+
toolChars: JSON.stringify(AI_SITE_IMPORT_IMPROVE_TOOL).length,
|
|
1390
|
+
promptChars: prompt.length,
|
|
1391
|
+
hour: AI_ROUTING_TABLE['job.page'].cacheTtl === '1h',
|
|
1392
|
+
most,
|
|
1393
|
+
ledger,
|
|
1394
|
+
proposed: !!doc.proposed
|
|
1395
|
+
});
|
|
1396
|
+
// The answer is told its room in sections and words, so it plans a page that fits rather than being cut off. The
|
|
1397
|
+
// lines are part of the request they size, so they are priced over it until they say what its room is.
|
|
1398
|
+
const groups = ledger.items.some((item)=>item.kind === 'group');
|
|
1399
|
+
let sizeLines = [];
|
|
1400
|
+
let prompt = promptOf(sizeLines);
|
|
1401
|
+
let room = roomOf(prompt);
|
|
1402
|
+
for(let pass = 0; pass < 3; pass += 1){
|
|
1403
|
+
const lines = aiSiteImportImproveSizeLines(room, {
|
|
1404
|
+
most,
|
|
1405
|
+
groups
|
|
1406
|
+
});
|
|
1407
|
+
if (lines.join('\n') === sizeLines.join('\n')) break;
|
|
1408
|
+
sizeLines = lines;
|
|
1409
|
+
prompt = promptOf(sizeLines);
|
|
1410
|
+
room = roomOf(prompt);
|
|
1411
|
+
}
|
|
1412
|
+
const first = room.first;
|
|
1413
|
+
// What each answer had and wrote, for the log a fallback leaves (AGL-4152).
|
|
1414
|
+
const track = {
|
|
1415
|
+
reask: null
|
|
1416
|
+
};
|
|
1369
1417
|
const checkOf = (lenient)=>{
|
|
1370
1418
|
var _ref, _input_context_framing, _doc_plan;
|
|
1371
1419
|
var _input_targets_forms_;
|
|
@@ -1436,15 +1484,25 @@ const NO_USAGE = {
|
|
|
1436
1484
|
tool: AI_SITE_IMPORT_IMPROVE_TOOL,
|
|
1437
1485
|
maxTokens: Math.max(1, first),
|
|
1438
1486
|
// Nothing is spent before it: a page brought in is compiled with no model first.
|
|
1439
|
-
reaskTokens: (spent, last)=>
|
|
1487
|
+
reaskTokens: (spent, last)=>{
|
|
1488
|
+
const tokens = aiSiteImportImproveReaskTokens({
|
|
1440
1489
|
model: input.model,
|
|
1441
1490
|
spent,
|
|
1442
1491
|
lastOutput: last.outputTokens,
|
|
1492
|
+
cutOff: last.cutOff,
|
|
1443
1493
|
most
|
|
1444
|
-
})
|
|
1494
|
+
});
|
|
1495
|
+
track.reask = {
|
|
1496
|
+
room: tokens,
|
|
1497
|
+
needs: aiSiteImportImproveReaskNeeds(last.outputTokens, last.cutOff),
|
|
1498
|
+
cutOff: last.cutOff,
|
|
1499
|
+
firstOutput: last.outputTokens
|
|
1500
|
+
};
|
|
1501
|
+
return tokens;
|
|
1502
|
+
},
|
|
1445
1503
|
cutOff: {
|
|
1446
1504
|
noun: 'page',
|
|
1447
|
-
smaller:
|
|
1505
|
+
smaller: AI_SITE_IMPORT_IMPROVE_CUT_OFF_SMALLER
|
|
1448
1506
|
}
|
|
1449
1507
|
}, AI_LAYOUT_LANGUAGE_THINKING, {
|
|
1450
1508
|
check: observe(checkOf(false))
|
|
@@ -1452,13 +1510,55 @@ const NO_USAGE = {
|
|
|
1452
1510
|
signal: input.signal
|
|
1453
1511
|
} : {}));
|
|
1454
1512
|
const spent = spentTogether(spend, answered);
|
|
1513
|
+
// Each answer's room and what it wrote, whether a re-ask ran, and its input priced before and as billed (AGL-4152):
|
|
1514
|
+
// what a later read of a fallback needs to tell a page cut off from one starved, never a word of the page.
|
|
1515
|
+
const asked = track.reask;
|
|
1516
|
+
const firstOutput = asked ? asked.firstOutput : answered.usage.outputTokens;
|
|
1517
|
+
const sizes = {
|
|
1518
|
+
answers: [
|
|
1519
|
+
{
|
|
1520
|
+
room: first,
|
|
1521
|
+
outputTokens: firstOutput
|
|
1522
|
+
},
|
|
1523
|
+
...answered.attempts > 1 && asked ? [
|
|
1524
|
+
{
|
|
1525
|
+
room: Math.min(first, asked.room),
|
|
1526
|
+
outputTokens: answered.usage.outputTokens - firstOutput
|
|
1527
|
+
}
|
|
1528
|
+
] : []
|
|
1529
|
+
],
|
|
1530
|
+
reask: asked ? {
|
|
1531
|
+
ran: answered.attempts > 1,
|
|
1532
|
+
room: asked.room,
|
|
1533
|
+
needs: asked.needs,
|
|
1534
|
+
cutOff: asked.cutOff
|
|
1535
|
+
} : {
|
|
1536
|
+
ran: false
|
|
1537
|
+
},
|
|
1538
|
+
planned: _extends({
|
|
1539
|
+
sections: room.sections,
|
|
1540
|
+
words: room.words,
|
|
1541
|
+
target: room.target
|
|
1542
|
+
}, room.thin !== null ? {
|
|
1543
|
+
thinWords: room.thin
|
|
1544
|
+
} : {}),
|
|
1545
|
+
inputCredits: {
|
|
1546
|
+
estimated: aiSiteImportImproveCredits(room.estimated, input.model),
|
|
1547
|
+
billed: aiSiteImportImproveCredits(_extends({}, answered.usage, {
|
|
1548
|
+
outputTokens: 0
|
|
1549
|
+
}), input.model)
|
|
1550
|
+
},
|
|
1551
|
+
credits: aiSiteImportImproveCredits(answered.usage, input.model)
|
|
1552
|
+
};
|
|
1455
1553
|
// Its last answer, where no re-ask was left and it missed only how it is planned or drawn: taken, its misses on its row (AGL-4152).
|
|
1456
1554
|
const taken = answered.status === 'needs_input' && answered.answer && aiSiteImportImproveOnlySoft(answered.violations) ? checkOf(true)(answered.answer) : null;
|
|
1457
1555
|
if (taken == null ? void 0 : taken.value) {
|
|
1458
1556
|
const { built, page, missed } = taken.value;
|
|
1459
|
-
console.info('ai imported page: its redesign taken with design lines missed', {
|
|
1557
|
+
console.info('ai imported page: its redesign taken with design lines missed', _extends({
|
|
1460
1558
|
codes: missed != null ? missed : []
|
|
1461
|
-
}
|
|
1559
|
+
}, sizes, {
|
|
1560
|
+
passed: aiSiteImportRedesignPassed(taken.value)
|
|
1561
|
+
}));
|
|
1462
1562
|
return _extends({}, spent, {
|
|
1463
1563
|
status: 'ok',
|
|
1464
1564
|
value: _extends({}, built, {
|
|
@@ -1482,11 +1582,11 @@ const NO_USAGE = {
|
|
|
1482
1582
|
];
|
|
1483
1583
|
// Logged with each miss's line, cut short (AGL-4152): the answer is not kept, so this is all a later read of the job has to go on.
|
|
1484
1584
|
const why = answered.status === 'needs_input' ? aiSiteImportRedesignWhy(answered.violations) : [];
|
|
1485
|
-
console.info('ai imported page: its redesign did not pass, its layout kept', {
|
|
1585
|
+
console.info('ai imported page: its redesign did not pass, its layout kept', _extends({
|
|
1486
1586
|
status: answered.status,
|
|
1487
1587
|
codes,
|
|
1488
1588
|
why
|
|
1489
|
-
});
|
|
1589
|
+
}, sizes));
|
|
1490
1590
|
// A new page has no words of its own to fall back on: it is left out, and its row says why.
|
|
1491
1591
|
if (doc.proposed) return _extends({}, spent, {
|
|
1492
1592
|
status: 'needs_input',
|
|
@@ -1518,6 +1618,7 @@ const NO_USAGE = {
|
|
|
1518
1618
|
});
|
|
1519
1619
|
}
|
|
1520
1620
|
const { built, page } = answered.value;
|
|
1621
|
+
console.info('ai imported page: its redesign passed', aiSiteImportRedesignPassed(answered.value, sizes.credits));
|
|
1521
1622
|
return _extends({}, spent, {
|
|
1522
1623
|
status: 'ok',
|
|
1523
1624
|
value: _extends({}, built, {
|