@aglyn/plugins-ai 1.0.0-beta.293 → 1.0.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 (64) hide show
  1. package/package.json +17 -17
  2. package/src/lib/components/ai-job-links.d.ts +17 -3
  3. package/src/lib/components/ai-job-links.js +32 -5
  4. package/src/lib/components/ai-job-links.js.map +1 -1
  5. package/src/lib/components/ai-job-requests.d.ts +9 -0
  6. package/src/lib/components/ai-job-requests.js +34 -0
  7. package/src/lib/components/ai-job-requests.js.map +1 -1
  8. package/src/lib/components/ai-site-build-page.component.js +28 -2
  9. package/src/lib/components/ai-site-build-page.component.js.map +1 -1
  10. package/src/lib/components/assist-edit-canvas.d.ts +12 -6
  11. package/src/lib/components/assist-edit-canvas.js +86 -36
  12. package/src/lib/components/assist-edit-canvas.js.map +1 -1
  13. package/src/lib/components/assist-edit-card.component.js +9 -8
  14. package/src/lib/components/assist-edit-card.component.js.map +1 -1
  15. package/src/lib/components/assist-jobs-drawer.component.d.ts +7 -1
  16. package/src/lib/components/assist-jobs-drawer.component.js +20 -6
  17. package/src/lib/components/assist-jobs-drawer.component.js.map +1 -1
  18. package/src/lib/components/assist-page-change-card.component.d.ts +44 -0
  19. package/src/lib/components/assist-page-change-card.component.js +166 -0
  20. package/src/lib/components/assist-page-change-card.component.js.map +1 -0
  21. package/src/lib/components/assist-panel.component.d.ts +105 -1
  22. package/src/lib/components/assist-panel.component.js +242 -36
  23. package/src/lib/components/assist-panel.component.js.map +1 -1
  24. package/src/lib/jobs/ai-job-edit-step.d.ts +82 -16
  25. package/src/lib/jobs/ai-job-edit-step.js +209 -62
  26. package/src/lib/jobs/ai-job-edit-step.js.map +1 -1
  27. package/src/lib/jobs/ai-job-navigation-step.js +4 -2
  28. package/src/lib/jobs/ai-job-navigation-step.js.map +1 -1
  29. package/src/lib/model/ai-edit-job.d.ts +33 -16
  30. package/src/lib/model/ai-edit-job.js +50 -34
  31. package/src/lib/model/ai-edit-job.js.map +1 -1
  32. package/src/lib/model/ai-job-activity.d.ts +6 -11
  33. package/src/lib/model/ai-job-activity.js +8 -15
  34. package/src/lib/model/ai-job-activity.js.map +1 -1
  35. package/src/lib/model/ai-job-notice.js +3 -1
  36. package/src/lib/model/ai-job-notice.js.map +1 -1
  37. package/src/lib/model/ai-jobs.types.d.ts +6 -0
  38. package/src/lib/model/ai-jobs.types.js.map +1 -1
  39. package/src/lib/model/ai-site-inventory.d.ts +6 -0
  40. package/src/lib/model/ai-site-inventory.js.map +1 -1
  41. package/src/lib/model/assist-edit.d.ts +19 -1
  42. package/src/lib/model/assist-edit.js +7 -0
  43. package/src/lib/model/assist-edit.js.map +1 -1
  44. package/src/lib/model/assist-page-change.d.ts +100 -0
  45. package/src/lib/model/assist-page-change.js +107 -0
  46. package/src/lib/model/assist-page-change.js.map +1 -0
  47. package/src/lib/runtime/ai-eval.js +3 -1
  48. package/src/lib/runtime/ai-eval.js.map +1 -1
  49. package/src/lib/runtime/ai-node-tree.d.ts +5 -0
  50. package/src/lib/runtime/ai-node-tree.js +18 -3
  51. package/src/lib/runtime/ai-node-tree.js.map +1 -1
  52. package/src/lib/runtime/site-inventory.d.ts +8 -1
  53. package/src/lib/runtime/site-inventory.js +18 -0
  54. package/src/lib/runtime/site-inventory.js.map +1 -1
  55. package/src/lib/server/assist-build.js +2 -0
  56. package/src/lib/server/assist-build.js.map +1 -1
  57. package/src/lib/server/assist-chat.js +56 -3
  58. package/src/lib/server/assist-chat.js.map +1 -1
  59. package/src/lib/server/assist-edit.d.ts +61 -4
  60. package/src/lib/server/assist-edit.js +248 -38
  61. package/src/lib/server/assist-edit.js.map +1 -1
  62. package/src/lib/server/assist-page-change.d.ts +62 -0
  63. package/src/lib/server/assist-page-change.js +140 -0
  64. package/src/lib/server/assist-page-change.js.map +1 -0
@@ -23,6 +23,8 @@ import type { AiJob, AiJobOutput } from '../model/ai-jobs.types';
23
23
  import { type AssistEditCanvasContext, type AssistEditOp, type AssistEditProposal, type AssistEditTarget } from '../model/assist-edit';
24
24
  import { type AiCustomGenerationInput } from '../runtime/ai-doctrine';
25
25
  import type { AiSystemBlock } from '../runtime/ai-runtime';
26
+ import { readAiSiteDatasets } from '../runtime/site-inventory';
27
+ import { type AssistEditDataset, type AssistEditDatasetScope } from '../server/assist-edit';
26
28
  import { type AiJobAdmission } from './ai-job-admission';
27
29
  import { type AiJobStepRunner } from './ai-job-text-step';
28
30
  /**
@@ -39,13 +41,19 @@ import { type AiJobStepRunner } from './ai-job-text-step';
39
41
  *
40
42
  * ── Where the change lands, decided before anything is spent ────────────
41
43
  *
42
- * Never on a version a visitor sees. With version history, a NEW version
43
- * beside the one it started from — a copy of that version's stored fields with
44
- * the changed nodes — which becomes the page's current version only when the
45
- * page is not published; a published page's current version, and a layout's,
46
- * never move. Without it, in place, on a version no visitor reaches: an
47
- * unpublished page's, or one that is not the current version and no schedule
48
- * will publish. Anything else is refused as a plan limit, charged nothing.
44
+ * Never on a version a visitor sees. By default, on every plan, in the
45
+ * WORKING DRAFT of the version it started from (AGL-4116): the one document
46
+ * the Besigner saves to as an author works and offers with Open draft, which
47
+ * publishing moves into the version. The change is built on the draft the
48
+ * author already has, when the Besigner would still offer it, so their work
49
+ * in progress is never thrown away; otherwise on the version's own tree.
50
+ *
51
+ * Only when the request asks for a new version, and the plan keeps version
52
+ * history, a NEW version beside the one it started from — a copy of that
53
+ * version's stored fields with the changed nodes — which becomes the page's
54
+ * current version only when the page is not published; a published page's
55
+ * current version, and a layout's, never move. Asked for without version
56
+ * history, the change goes into the draft and the output says why.
49
57
  *
50
58
  * ── What a job cannot do that the editor can ────────────────────────────
51
59
  *
@@ -59,8 +67,8 @@ import { type AiJobStepRunner } from './ai-job-text-step';
59
67
  *
60
68
  * The new version is named by the job's id — a build's unit is named by its
61
69
  * plan item's id — so a run asked again finds what it wrote and spends
62
- * nothing. A change made in place stamps the version with the job's id for
63
- * the same reason.
70
+ * nothing. A draft the job writes is stamped with the job's id for the same
71
+ * reason.
64
72
  */
65
73
  /** The longest the step may take reading the page and writing it. */
66
74
  export declare const AI_EDIT_READS_MS = 2000;
@@ -76,11 +84,22 @@ export declare function aiJobEditModel(): string;
76
84
  export declare const AI_JOB_EDIT_RULES: AiSystemBlock;
77
85
  /** The system blocks for one kind of document. */
78
86
  export declare function aiJobEditInstructions(kind: AiEditTargetKind): AiSystemBlock[];
79
- /** What the change is asked from: the document's outline, then the request. */
87
+ /**
88
+ * What the change is asked from: the document's outline, the site's datasets
89
+ * an element may show the records of (AGL-3616), then the request.
90
+ */
80
91
  export declare function aiJobEditPrompt(input: {
81
92
  brief: string;
82
93
  context: AssistEditCanvasContext;
94
+ datasets?: readonly AssistEditDataset[];
83
95
  }): string;
96
+ /**
97
+ * The datasets an edit to this document knows (AGL-3616): every one the site
98
+ * holds, and the one whose record page the document is, if it is one.
99
+ */
100
+ export declare function aiEditDatasetScope(datasets: ReadonlyArray<AssistEditDataset & {
101
+ recordScreenId?: string;
102
+ }>, read: Pick<AiEditTargetRead, 'kind' | 'id'>): Required<AssistEditDatasetScope>;
84
103
  /** The edit as the doctrine's loop runs it: the rung's tool, held to the rung's check. */
85
104
  export declare function aiJobEditGeneration(request: {
86
105
  brief: string;
@@ -88,7 +107,7 @@ export declare function aiJobEditGeneration(request: {
88
107
  target: AssistEditTarget;
89
108
  model: string;
90
109
  signal?: AbortSignal;
91
- }): AiCustomGenerationInput<AssistEditProposal>;
110
+ } & AssistEditDatasetScope): AiCustomGenerationInput<AssistEditProposal>;
92
111
  /** A canvas over a stored node map, with the editor's own guarded mutators and no editor. */
93
112
  export declare function aiEditCanvas(nodes: NodesMap): CanvasManager;
94
113
  /**
@@ -115,7 +134,16 @@ export interface AiEditTargetRead {
115
134
  pointerVersionId: string | null;
116
135
  /** The version the change starts from. */
117
136
  sourceVersionId: string;
137
+ /** The version's own tree. */
118
138
  nodes: NodesMap;
139
+ /**
140
+ * The version's working draft, when it has one the Besigner would still
141
+ * offer: an author's saved work in progress, which a change to the draft
142
+ * is built on. Null when there is none, or the version was saved since.
143
+ */
144
+ draft: {
145
+ nodes: NodesMap;
146
+ } | null;
119
147
  /** Whether visitors see the document's current version: a published page, a collection template, any layout. */
120
148
  served: boolean;
121
149
  /** The version a pending publish schedule will make current, if any. */
@@ -152,14 +180,29 @@ export declare function aiEditPlacement(input: {
152
180
  sourceIsPointer: boolean;
153
181
  sourceScheduled: boolean;
154
182
  }): AiEditPlacement | 'refused';
183
+ /**
184
+ * Where an edit job's change lands (AGL-4116): the version's working draft,
185
+ * unless the request asked for a new version and the plan keeps version
186
+ * history — then where {@link aiEditPlacement} puts a new one. Never refused:
187
+ * a draft is on every plan, and no visitor sees it.
188
+ */
189
+ export declare function aiEditJobPlacement(input: {
190
+ newVersion: boolean;
191
+ versioning: boolean;
192
+ served: boolean;
193
+ sourceIsPointer: boolean;
194
+ sourceScheduled: boolean;
195
+ }): AiEditPlacement;
155
196
  export interface AiEditWriteInput {
156
197
  hostId: string;
157
198
  kind: AiEditTargetKind;
158
199
  id: string;
159
200
  sourceVersionId: string;
160
- /** The new version's id, which is the job's; also the stamp a change in place carries. */
201
+ /** The new version's id, which is the job's; also the stamp a draft it writes carries. */
161
202
  jobVersionId: string;
162
203
  versioning: boolean;
204
+ /** The request asked for a new version (see {@link aiEditJobPlacement}). */
205
+ newVersion: boolean;
163
206
  proposal: AssistEditProposal;
164
207
  /** Whether the page's search fields may be written: a page no visitor reaches. */
165
208
  writeSeo: boolean;
@@ -189,12 +232,35 @@ export declare function writeAiEdit(firestore: Firestore, input: AiEditWriteInpu
189
232
  export interface AiJobEditStepDeps {
190
233
  readTarget?: typeof readAiEditTarget;
191
234
  writeEdit?: typeof writeAiEdit;
235
+ readDatasets?: typeof readAiSiteDatasets;
236
+ clearMirror?: typeof clearAiEditMirror;
192
237
  }
238
+ /**
239
+ * Clears the co-edit mirror of the version whose draft a job just wrote
240
+ * (AGL-4116), as the Besigner's own Save draft does.
241
+ *
242
+ * The mirror holds unsaved canvas work and replays everything newer than the
243
+ * version's last save to whoever opens it. A draft write does not move the
244
+ * version's save, so without this the canvas of someone who had opened the
245
+ * older draft replays over the change the job just saved, and a room with
246
+ * replayed work offers no draft at all: the newer draft can only be reached by
247
+ * a Discard that deletes it. Best effort: a mirror that cannot be cleared
248
+ * leaves the draft saved, and the job reports what it wrote.
249
+ */
250
+ export declare function clearAiEditMirror(input: {
251
+ orgId: string;
252
+ hostId: string;
253
+ kind: AiEditTargetKind;
254
+ id: string;
255
+ versionId: string;
256
+ }): Promise<void>;
193
257
  /** What an edit wrote, as the job's output: a link into the Besigner on the version written. */
194
258
  export declare function aiEditOutput(read: Pick<AiEditTargetRead, 'kind' | 'id' | 'name' | 'hostSubdomain'>, hostId: string, written: {
195
259
  versionId: string;
196
260
  placement: AiEditPlacement;
197
- }, leftOut: readonly string[]): AiJobOutput;
261
+ }, leftOut: readonly string[], options?: {
262
+ versionsUnavailable?: boolean;
263
+ }): AiJobOutput;
198
264
  /** The new version's id: the job's own, which a build's unit takes from its plan item. */
199
265
  export declare function aiEditVersionId(job: Pick<AiJob, '$id'>): string;
200
266
  /**
@@ -214,9 +280,9 @@ export interface AiEditJobAdmissionDeps {
214
280
  ownerOf?: typeof resolveOrgIdForHost;
215
281
  }
216
282
  /**
217
- * An edit job is admitted for a page or layout of a site of its own org,
218
- * and only where the change has somewhere to land that no visitor sees on
219
- * this workspace's plan — refused in the plan's words before anything exists.
283
+ * An edit job is admitted for a page or layout of a site of its own org that
284
+ * has a version to start from. Every plan has somewhere to put the change
285
+ * that no visitor sees — the version's draft — so no plan is refused.
220
286
  */
221
287
  export declare function createAiEditJobAdmission(deps?: AiEditJobAdmissionDeps): AiJobAdmission;
222
288
  export declare const aiEditJobAdmission: AiJobAdmission;