@aglyn/plugins-ai 1.0.0-beta.228 → 1.0.0-beta.230
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/README.md +3 -3
- package/package.json +17 -17
- package/src/lib/activity/ai-activity-actions.js +7 -1
- package/src/lib/activity/ai-activity-actions.js.map +1 -1
- package/src/lib/components/ai-automation-zones.d.ts +38 -0
- package/src/lib/components/ai-automation-zones.js +5 -1
- package/src/lib/components/ai-automation-zones.js.map +1 -1
- package/src/lib/components/ai-brief-dialog.component.d.ts +20 -2
- package/src/lib/components/ai-brief-dialog.component.js +87 -8
- package/src/lib/components/ai-brief-dialog.component.js.map +1 -1
- package/src/lib/components/ai-campaign-create.component.d.ts +54 -0
- package/src/lib/components/ai-campaign-create.component.js +270 -0
- package/src/lib/components/ai-campaign-create.component.js.map +1 -0
- package/src/lib/components/ai-describe-automation.component.d.ts +8 -3
- package/src/lib/components/ai-describe-automation.component.js +15 -6
- package/src/lib/components/ai-describe-automation.component.js.map +1 -1
- package/src/lib/components/ai-describe-button.component.d.ts +20 -8
- package/src/lib/components/ai-describe-button.component.js +19 -36
- package/src/lib/components/ai-describe-button.component.js.map +1 -1
- package/src/lib/components/ai-describe-email.component.d.ts +31 -0
- package/src/lib/components/ai-describe-email.component.js +22 -0
- package/src/lib/components/ai-describe-email.component.js.map +1 -0
- package/src/lib/components/ai-describe-org-automation.component.d.ts +36 -0
- package/src/lib/components/ai-describe-org-automation.component.js +238 -0
- package/src/lib/components/ai-describe-org-automation.component.js.map +1 -0
- package/src/lib/components/ai-experiment-cards.component.d.ts +9 -1
- package/src/lib/components/ai-experiment-cards.component.js +104 -18
- package/src/lib/components/ai-experiment-cards.component.js.map +1 -1
- package/src/lib/components/ai-explain-automation.component.js +1 -5
- package/src/lib/components/ai-explain-automation.component.js.map +1 -1
- package/src/lib/components/ai-funnel-zones.component.d.ts +61 -0
- package/src/lib/components/ai-funnel-zones.component.js +178 -0
- package/src/lib/components/ai-funnel-zones.component.js.map +1 -0
- package/src/lib/components/ai-insight-card.component.d.ts +42 -0
- package/src/lib/components/ai-insight-card.component.js +137 -0
- package/src/lib/components/ai-insight-card.component.js.map +1 -0
- package/src/lib/components/ai-insight-dialog.component.d.ts +6 -0
- package/src/lib/components/ai-insight-dialog.component.js +9 -3
- package/src/lib/components/ai-insight-dialog.component.js.map +1 -1
- package/src/lib/components/ai-job-plan.component.d.ts +7 -2
- package/src/lib/components/ai-job-plan.component.js +35 -5
- package/src/lib/components/ai-job-plan.component.js.map +1 -1
- package/src/lib/components/ai-job-requests.d.ts +17 -1
- package/src/lib/components/ai-job-requests.js +39 -3
- package/src/lib/components/ai-job-requests.js.map +1 -1
- package/src/lib/components/ai-jobs-list-page.component.js +12 -1
- package/src/lib/components/ai-jobs-list-page.component.js.map +1 -1
- package/src/lib/components/ai-logic-zones.d.ts +64 -0
- package/src/lib/components/ai-logic-zones.js +18 -0
- package/src/lib/components/ai-logic-zones.js.map +1 -0
- package/src/lib/components/ai-logic.component.d.ts +77 -0
- package/src/lib/components/ai-logic.component.js +553 -0
- package/src/lib/components/ai-logic.component.js.map +1 -0
- package/src/lib/components/ai-marketing-insight.component.d.ts +30 -0
- package/src/lib/components/ai-marketing-insight.component.js +80 -0
- package/src/lib/components/ai-marketing-insight.component.js.map +1 -0
- package/src/lib/components/ai-media-create.component.d.ts +55 -0
- package/src/lib/components/ai-media-create.component.js +433 -0
- package/src/lib/components/ai-media-create.component.js.map +1 -0
- package/src/lib/components/ai-overlay-cards.component.d.ts +83 -0
- package/src/lib/components/ai-overlay-cards.component.js +505 -0
- package/src/lib/components/ai-overlay-cards.component.js.map +1 -0
- package/src/lib/components/ai-product-zones.d.ts +5 -0
- package/src/lib/components/ai-product-zones.js +1 -1
- package/src/lib/components/ai-product-zones.js.map +1 -1
- package/src/lib/components/ai-products-create-button.component.d.ts +42 -0
- package/src/lib/components/ai-products-create-button.component.js +67 -0
- package/src/lib/components/ai-products-create-button.component.js.map +1 -0
- package/src/lib/components/ai-products-hub-card.component.js +100 -81
- package/src/lib/components/ai-products-hub-card.component.js.map +1 -1
- package/src/lib/components/ai-revise-automation.component.d.ts +16 -0
- package/src/lib/components/ai-revise-automation.component.js +207 -0
- package/src/lib/components/ai-revise-automation.component.js.map +1 -0
- package/src/lib/components/ai-site-build-page.component.d.ts +1 -1
- package/src/lib/components/ai-site-build-page.component.js +177 -20
- package/src/lib/components/ai-site-build-page.component.js.map +1 -1
- package/src/lib/components/ai-site-start-card.component.d.ts +10 -1
- package/src/lib/components/ai-site-start-card.component.js +7 -4
- package/src/lib/components/ai-site-start-card.component.js.map +1 -1
- package/src/lib/components/ai-upsell-dialog.component.d.ts +53 -0
- package/src/lib/components/ai-upsell-dialog.component.js +177 -0
- package/src/lib/components/ai-upsell-dialog.component.js.map +1 -0
- package/src/lib/components/assist-build-card.component.d.ts +42 -0
- package/src/lib/components/assist-build-card.component.js +183 -0
- package/src/lib/components/assist-build-card.component.js.map +1 -0
- package/src/lib/components/assist-edit-canvas.d.ts +2 -0
- package/src/lib/components/assist-edit-canvas.js +56 -1
- package/src/lib/components/assist-edit-canvas.js.map +1 -1
- package/src/lib/components/assist-jobs-drawer.component.d.ts +11 -0
- package/src/lib/components/assist-jobs-drawer.component.js +85 -4
- package/src/lib/components/assist-jobs-drawer.component.js.map +1 -1
- package/src/lib/components/assist-panel.component.js +51 -2
- package/src/lib/components/assist-panel.component.js.map +1 -1
- package/src/lib/components/use-ai-job-run.d.ts +3 -14
- package/src/lib/components/use-ai-job-run.js +0 -50
- package/src/lib/components/use-ai-job-run.js.map +1 -1
- package/src/lib/jobs/ai-build-capabilities.d.ts +58 -0
- package/src/lib/jobs/ai-build-capabilities.js +256 -0
- package/src/lib/jobs/ai-build-capabilities.js.map +1 -0
- package/src/lib/jobs/ai-build-unit-outcome.d.ts +52 -0
- package/src/lib/jobs/ai-build-unit-outcome.js +138 -0
- package/src/lib/jobs/ai-build-unit-outcome.js.map +1 -0
- package/src/lib/jobs/ai-job-build-step.d.ts +144 -0
- package/src/lib/jobs/ai-job-build-step.js +657 -0
- package/src/lib/jobs/ai-job-build-step.js.map +1 -0
- package/src/lib/jobs/ai-job-draft-ids.js +9 -1
- package/src/lib/jobs/ai-job-draft-ids.js.map +1 -1
- package/src/lib/jobs/ai-job-drafts.d.ts +14 -4
- package/src/lib/jobs/ai-job-drafts.js +25 -4
- package/src/lib/jobs/ai-job-drafts.js.map +1 -1
- package/src/lib/jobs/ai-job-layout-site-pages.d.ts +70 -0
- package/src/lib/jobs/ai-job-layout-site-pages.js +216 -0
- package/src/lib/jobs/ai-job-layout-site-pages.js.map +1 -0
- package/src/lib/jobs/ai-job-layout-step.d.ts +2 -2
- package/src/lib/jobs/ai-job-layout-step.js +19 -1
- package/src/lib/jobs/ai-job-layout-step.js.map +1 -1
- package/src/lib/jobs/ai-job-logic-step.d.ts +107 -0
- package/src/lib/jobs/ai-job-logic-step.js +395 -0
- package/src/lib/jobs/ai-job-logic-step.js.map +1 -0
- package/src/lib/jobs/ai-job-overlay-copy.d.ts +70 -0
- package/src/lib/jobs/ai-job-overlay-copy.js +178 -0
- package/src/lib/jobs/ai-job-overlay-copy.js.map +1 -0
- package/src/lib/jobs/ai-job-page-step.js +6 -6
- package/src/lib/jobs/ai-job-page-step.js.map +1 -1
- package/src/lib/jobs/ai-job-plan-step.d.ts +26 -1
- package/src/lib/jobs/ai-job-plan-step.js +79 -11
- package/src/lib/jobs/ai-job-plan-step.js.map +1 -1
- package/src/lib/jobs/ai-job-site-step.d.ts +15 -1
- package/src/lib/jobs/ai-job-site-step.js +207 -58
- package/src/lib/jobs/ai-job-site-step.js.map +1 -1
- package/src/lib/jobs/ai-job-text-step.d.ts +22 -1
- package/src/lib/jobs/ai-job-text-step.js +12 -0
- package/src/lib/jobs/ai-job-text-step.js.map +1 -1
- package/src/lib/jobs/ai-job-workflow-step.d.ts +54 -4
- package/src/lib/jobs/ai-job-workflow-step.js +318 -13
- package/src/lib/jobs/ai-job-workflow-step.js.map +1 -1
- package/src/lib/jobs/ai-jobs.d.ts +90 -2
- package/src/lib/jobs/ai-jobs.js +495 -61
- package/src/lib/jobs/ai-jobs.js.map +1 -1
- package/src/lib/jobs/ai-logic-records.d.ts +40 -0
- package/src/lib/jobs/ai-logic-records.js +55 -0
- package/src/lib/jobs/ai-logic-records.js.map +1 -0
- package/src/lib/jobs/ai-site-publish.d.ts +7 -0
- package/src/lib/jobs/ai-site-publish.js +9 -0
- package/src/lib/jobs/ai-site-publish.js.map +1 -1
- package/src/lib/jobs/ai-workflow-records.d.ts +4 -0
- package/src/lib/jobs/ai-workflow-records.js +40 -1
- package/src/lib/jobs/ai-workflow-records.js.map +1 -1
- package/src/lib/model/ai-automation-draft.d.ts +18 -0
- package/src/lib/model/ai-automation-draft.js +86 -0
- package/src/lib/model/ai-automation-draft.js.map +1 -1
- package/src/lib/model/ai-build-job.d.ts +201 -0
- package/src/lib/model/ai-build-job.js +471 -0
- package/src/lib/model/ai-build-job.js.map +1 -0
- package/src/lib/model/ai-build-plan.d.ts +61 -0
- package/src/lib/model/ai-build-plan.js +154 -9
- package/src/lib/model/ai-build-plan.js.map +1 -1
- package/src/lib/model/ai-build-progress.d.ts +56 -0
- package/src/lib/model/ai-build-progress.js +128 -0
- package/src/lib/model/ai-build-progress.js.map +1 -0
- package/src/lib/model/ai-insight.d.ts +20 -10
- package/src/lib/model/ai-insight.js +72 -9
- package/src/lib/model/ai-insight.js.map +1 -1
- package/src/lib/model/ai-job-activity.js +3 -1
- package/src/lib/model/ai-job-activity.js.map +1 -1
- package/src/lib/model/ai-job-failure-copy.d.ts +20 -1
- package/src/lib/model/ai-job-failure-copy.js +28 -1
- package/src/lib/model/ai-job-failure-copy.js.map +1 -1
- package/src/lib/model/ai-job-notice.d.ts +3 -0
- package/src/lib/model/ai-job-notice.js +11 -2
- package/src/lib/model/ai-job-notice.js.map +1 -1
- package/src/lib/model/ai-jobs.types.d.ts +87 -2
- package/src/lib/model/ai-jobs.types.js +3 -1
- package/src/lib/model/ai-jobs.types.js.map +1 -1
- package/src/lib/model/ai-logic-job.d.ts +108 -0
- package/src/lib/model/ai-logic-job.js +327 -0
- package/src/lib/model/ai-logic-job.js.map +1 -0
- package/src/lib/model/ai-media-credits.d.ts +52 -0
- package/src/lib/model/ai-media-credits.js +61 -0
- package/src/lib/model/ai-media-credits.js.map +1 -0
- package/src/lib/model/ai-overlay-copy.d.ts +114 -0
- package/src/lib/model/ai-overlay-copy.js +175 -0
- package/src/lib/model/ai-overlay-copy.js.map +1 -0
- package/src/lib/model/ai-site-build-progress.d.ts +28 -3
- package/src/lib/model/ai-site-build-progress.js +231 -17
- package/src/lib/model/ai-site-build-progress.js.map +1 -1
- package/src/lib/model/ai-site-start-seo.d.ts +16 -0
- package/src/lib/model/ai-site-start-seo.js +54 -4
- package/src/lib/model/ai-site-start-seo.js.map +1 -1
- package/src/lib/model/ai-site-start.d.ts +14 -0
- package/src/lib/model/ai-site-start.js +43 -0
- package/src/lib/model/ai-site-start.js.map +1 -1
- package/src/lib/model/ai-svg.d.ts +69 -0
- package/src/lib/model/ai-svg.js +265 -0
- package/src/lib/model/ai-svg.js.map +1 -0
- package/src/lib/model/ai-usage-by-user.d.ts +3 -2
- package/src/lib/model/ai-usage-by-user.js.map +1 -1
- package/src/lib/model/ai-workflow-job.d.ts +92 -4
- package/src/lib/model/ai-workflow-job.js +124 -7
- package/src/lib/model/ai-workflow-job.js.map +1 -1
- package/src/lib/model/assist-build.d.ts +58 -0
- package/src/lib/model/assist-build.js +52 -0
- package/src/lib/model/assist-build.js.map +1 -0
- package/src/lib/model/assist-edit.d.ts +48 -3
- package/src/lib/model/assist-edit.js +48 -4
- package/src/lib/model/assist-edit.js.map +1 -1
- package/src/lib/plugin-config.js +2 -0
- package/src/lib/plugin-config.js.map +1 -1
- package/src/lib/plugin.js +240 -11
- package/src/lib/plugin.js.map +1 -1
- package/src/lib/providers/catalog.d.ts +81 -4
- package/src/lib/providers/catalog.js +80 -9
- package/src/lib/providers/catalog.js.map +1 -1
- package/src/lib/providers/image-contract.d.ts +116 -0
- package/src/lib/providers/image-contract.js +74 -0
- package/src/lib/providers/image-contract.js.map +1 -0
- package/src/lib/providers/model-choice.js +11 -0
- package/src/lib/providers/model-choice.js.map +1 -1
- package/src/lib/providers/routing.js +18 -0
- package/src/lib/providers/routing.js.map +1 -1
- package/src/lib/providers/vertex-image.d.ts +121 -0
- package/src/lib/providers/vertex-image.js +312 -0
- package/src/lib/providers/vertex-image.js.map +1 -0
- package/src/lib/runtime/ai-doctrine-validators.d.ts +19 -0
- package/src/lib/runtime/ai-doctrine-validators.js +89 -0
- package/src/lib/runtime/ai-doctrine-validators.js.map +1 -1
- package/src/lib/runtime/ai-doctrine.d.ts +6 -0
- package/src/lib/runtime/ai-doctrine.js +16 -6
- package/src/lib/runtime/ai-doctrine.js.map +1 -1
- package/src/lib/runtime/ai-eval-live.js +4 -0
- package/src/lib/runtime/ai-eval-live.js.map +1 -1
- package/src/lib/runtime/ai-eval.d.ts +15 -1
- package/src/lib/runtime/ai-eval.js +52 -1
- package/src/lib/runtime/ai-eval.js.map +1 -1
- package/src/lib/runtime/experiment-variant-copy.d.ts +34 -0
- package/src/lib/runtime/experiment-variant-copy.js +102 -0
- package/src/lib/runtime/experiment-variant-copy.js.map +1 -0
- package/src/lib/server/ai-experiment-versions.d.ts +51 -0
- package/src/lib/server/ai-experiment-versions.js +270 -0
- package/src/lib/server/ai-experiment-versions.js.map +1 -0
- package/src/lib/server/ai-jobs-resume.js +74 -4
- package/src/lib/server/ai-jobs-resume.js.map +1 -1
- package/src/lib/server/ai-media-image.d.ts +66 -0
- package/src/lib/server/ai-media-image.js +521 -0
- package/src/lib/server/ai-media-image.js.map +1 -0
- package/src/lib/server/ai-media-svg.d.ts +91 -0
- package/src/lib/server/ai-media-svg.js +186 -0
- package/src/lib/server/ai-media-svg.js.map +1 -0
- package/src/lib/server/assist-build.d.ts +54 -0
- package/src/lib/server/assist-build.js +121 -0
- package/src/lib/server/assist-build.js.map +1 -0
- package/src/lib/server/assist-chat.js +108 -12
- package/src/lib/server/assist-chat.js.map +1 -1
- package/src/lib/server/assist-edit.js +213 -3
- package/src/lib/server/assist-edit.js.map +1 -1
- package/src/lib/server/assist-view-context.js +242 -4
- package/src/lib/server/assist-view-context.js.map +1 -1
- package/src/lib/server.js +26 -0
- package/src/lib/server.js.map +1 -1
- package/src/lib/tools/ai-logic-tool.d.ts +27 -0
- package/src/lib/tools/ai-logic-tool.js +207 -0
- package/src/lib/tools/ai-logic-tool.js.map +1 -0
- package/src/lib/tools/ai-overlay-tool.d.ts +35 -0
- package/src/lib/tools/ai-overlay-tool.js +107 -0
- package/src/lib/tools/ai-overlay-tool.js.map +1 -0
- package/src/lib/tools/ai-workflow-tool.d.ts +11 -0
- package/src/lib/tools/ai-workflow-tool.js +31 -0
- package/src/lib/tools/ai-workflow-tool.js.map +1 -1
- package/src/lib/usage/assist-job-refund.d.ts +31 -3
- package/src/lib/usage/assist-job-refund.js +46 -10
- package/src/lib/usage/assist-job-refund.js.map +1 -1
- package/src/lib/usage/assist-usage.d.ts +5 -0
- package/src/lib/usage/assist-usage.js +2 -0
- package/src/lib/usage/assist-usage.js.map +1 -1
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
* See the License for the specific language governing permissions and
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
|
-
import type { AiJobKind, AiJobSummary } from './ai-jobs.types';
|
|
17
|
+
import type { AiJobKind, AiJobStatus, AiJobSummary } from './ai-jobs.types';
|
|
18
18
|
/**
|
|
19
19
|
* What a member reads when a plan could not be made (AGL-3594): one plain
|
|
20
20
|
* sentence and one thing to do, never a rule number or a validator's words.
|
|
@@ -57,6 +57,25 @@ export declare function aiPlanRetryRefusal(input: {
|
|
|
57
57
|
creditsLeft: number;
|
|
58
58
|
planCredits: number;
|
|
59
59
|
}): string | null;
|
|
60
|
+
/**
|
|
61
|
+
* What a guided site start that failed on our side says (AGL-3596): one plain
|
|
62
|
+
* sentence, never a rule. Whether its credits came back is said beside it, from
|
|
63
|
+
* the job's own record (`aiJobRefundCopy`).
|
|
64
|
+
*/
|
|
65
|
+
export declare const AI_SITE_GUIDED_BUILD_FAILED_COPY = "Something went wrong building your site, and it was not built.";
|
|
66
|
+
/** What a person's own cancel says about its credits: they paid for what ran until then. */
|
|
67
|
+
export declare const AI_JOB_CANCELED_CREDITS_COPY = "You paid for what was spent up to then.";
|
|
68
|
+
/**
|
|
69
|
+
* What every surface that shows a stopped job says about its credits
|
|
70
|
+
* (AGL-3596), read off the job's RECORDED give-back (`refundedCredits`),
|
|
71
|
+
* never worked out again: a failure on our side that gave its credits back
|
|
72
|
+
* says so plainly, and a person's own cancel says they paid for what ran.
|
|
73
|
+
* `null` where there is nothing to say — a job still working, done, or one
|
|
74
|
+
* that stopped without a give-back.
|
|
75
|
+
*/
|
|
76
|
+
export declare function aiJobRefundCopy(job: {
|
|
77
|
+
status: AiJobStatus;
|
|
78
|
+
} & Partial<Pick<AiJobSummary, 'refundedCredits' | 'creditsSpent'>>): string | null;
|
|
60
79
|
/** The guided start's way back to the starter (AGL-3594). */
|
|
61
80
|
export declare const AI_SITE_STARTER_FALLBACK_LABEL = "Use the starter site instead";
|
|
62
81
|
/**
|
|
@@ -60,6 +60,32 @@
|
|
|
60
60
|
if (left >= input.planCredits) return null;
|
|
61
61
|
return `You have ${left} AI ${left === 1 ? 'credit' : 'credits'} left this month, and a plan needs up to ${input.planCredits}. Your credits refresh next month, or upgrade for more.`;
|
|
62
62
|
}
|
|
63
|
+
/**
|
|
64
|
+
* What a guided site start that failed on our side says (AGL-3596): one plain
|
|
65
|
+
* sentence, never a rule. Whether its credits came back is said beside it, from
|
|
66
|
+
* the job's own record (`aiJobRefundCopy`).
|
|
67
|
+
*/ export const AI_SITE_GUIDED_BUILD_FAILED_COPY = 'Something went wrong building your site, and it was not built.';
|
|
68
|
+
/** What a person's own cancel says about its credits: they paid for what ran until then. */ export const AI_JOB_CANCELED_CREDITS_COPY = 'You paid for what was spent up to then.';
|
|
69
|
+
/**
|
|
70
|
+
* What every surface that shows a stopped job says about its credits
|
|
71
|
+
* (AGL-3596), read off the job's RECORDED give-back (`refundedCredits`),
|
|
72
|
+
* never worked out again: a failure on our side that gave its credits back
|
|
73
|
+
* says so plainly, and a person's own cancel says they paid for what ran.
|
|
74
|
+
* `null` where there is nothing to say — a job still working, done, or one
|
|
75
|
+
* that stopped without a give-back.
|
|
76
|
+
*/ export function aiJobRefundCopy(job) {
|
|
77
|
+
var _job_refundedCredits, _job_creditsSpent;
|
|
78
|
+
const refunded = Math.max(0, Math.floor((_job_refundedCredits = job.refundedCredits) != null ? _job_refundedCredits : 0));
|
|
79
|
+
if (refunded > 0) {
|
|
80
|
+
var _job_creditsSpent1;
|
|
81
|
+
const credits = `${refunded} ${refunded === 1 ? 'credit' : 'credits'}`;
|
|
82
|
+
const back = refunded === 1 ? 'is' : 'are';
|
|
83
|
+
const whole = refunded >= Math.floor((_job_creditsSpent1 = job.creditsSpent) != null ? _job_creditsSpent1 : 0);
|
|
84
|
+
return whole ? `This one’s on us — you weren’t charged. The ${credits} it used ${back} back in your AI credits.` : `This one’s on us — you weren’t charged for the part that failed. The ${credits} it used ${back} back in your AI credits.`;
|
|
85
|
+
}
|
|
86
|
+
if (job.status === 'canceled' && ((_job_creditsSpent = job.creditsSpent) != null ? _job_creditsSpent : 0) > 0) return AI_JOB_CANCELED_CREDITS_COPY;
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
63
89
|
/** The guided start's way back to the starter (AGL-3594). */ export const AI_SITE_STARTER_FALLBACK_LABEL = 'Use the starter site instead';
|
|
64
90
|
/**
|
|
65
91
|
* Whether a job is a guided start that did not work out and can still be
|
|
@@ -70,7 +96,8 @@
|
|
|
70
96
|
*/ export function aiSiteStarterFallbackOffered(job) {
|
|
71
97
|
var _job_review;
|
|
72
98
|
if (job.kind !== 'site' || !job.hostId) return false;
|
|
73
|
-
|
|
99
|
+
// The site's listing proposal rides out with the first unit and builds nothing (AGL-3596).
|
|
100
|
+
if (job.outputs.some((output)=>output.resource !== 'seo')) return false;
|
|
74
101
|
if (job.status === 'failed' || job.status === 'canceled') return true;
|
|
75
102
|
return job.status === 'needs_review' && ((_job_review = job.review) == null ? void 0 : _job_review.reason) === 'doctrine';
|
|
76
103
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../libs/plugins/ai/src/lib/model/ai-job-failure-copy.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { AiJobKind, AiJobSummary } from './ai-jobs.types'\n\n/**\n * What a member reads when a plan could not be made (AGL-3594): one plain\n * sentence and one thing to do, never a rule number or a validator's words.\n *\n * The plan step's own checks refuse an answer in the doctrine's vocabulary —\n * \"Rule 10 (Navigation and SEO travel with a page): A page reuses an\n * address…\" — which is what the one re-ask is told and what staff read to\n * tell a rule that should bend from a model that ignored it. Shown to the\n * person who asked for a site, the same words read as the product breaking.\n * So the review a refused plan stops for carries this sentence as its\n * `message`, and the doctrine's sentence and findings ride beside it as\n * `detail` and `findings`, which the job document keeps and only staff are\n * shown.\n *\n * Pure: no React, no Admin SDK. The drawer's plan card and the plan step read\n * the same words.\n */\n\n/** The violation code the Free wall refuses a plan with. */\nexport const AI_PLAN_FREE_WALL_CODE = 'plan-over-free-wall'\n\n/** What the plan was for, as the sentence names it. */\nfunction planningWhat(kind: AiJobKind | string): string {\n switch (kind) {\n case 'site':\n return 'your site'\n case 'page':\n return 'this page'\n default:\n return 'this'\n }\n}\n\nexport interface AiPlanFailureCopyInput {\n /** The job kind whose plan was refused. */\n kind: AiJobKind | string\n /** The codes of the violations its last answer broke. */\n codes: readonly string[]\n /** The step's credits went back to the Free allowance (AGL-3594). */\n refunded: boolean\n}\n\n/**\n * The sentence a refused plan stops its job with. Over the Free wall, the way\n * out is fewer pages or a paid plan; anything else is ours to have got wrong,\n * and the way out is trying again — said to cost nothing only when it did.\n */\nexport function aiPlanFailureCopy(input: AiPlanFailureCopyInput): string {\n const spent = input.refunded ? ', and it did not use any of your AI credits' : ''\n if (input.codes.includes(AI_PLAN_FREE_WALL_CODE)) {\n return `We couldn't fit this plan into your Free AI credits${spent}. Try fewer pages, or upgrade for more.`\n }\n return `Something went wrong planning ${planningWhat(input.kind)}${spent}. Try again.`\n}\n\n/**\n * Why trying a refused plan again cannot work yet, or `null` when it can: the\n * Free allowance left this month is less than a plan of this kind can cost at\n * its worst. Said with the figures, and with the two ways out.\n */\nexport function aiPlanRetryRefusal(input: { creditsLeft: number; planCredits: number }): string | null {\n const left = Math.max(0, Math.floor(input.creditsLeft))\n if (left >= input.planCredits) return null\n return `You have ${left} AI ${left === 1 ? 'credit' : 'credits'} left this month, and a plan needs up to ${input.planCredits}. Your credits refresh next month, or upgrade for more.`\n}\n\n/** The guided start's way back to the starter (AGL-3594). */\nexport const AI_SITE_STARTER_FALLBACK_LABEL = 'Use the starter site instead'\n\n/**\n * Whether a job is a guided start that did not work out and can still be\n * traded for the starter (AGL-3594): a site job that failed, was canceled, or\n * stopped for a person on a refused step — never one waiting on its plan,\n * which is a plan to confirm — and that has built nothing, since the starter\n * is written only to a site with no page or layout.\n */\nexport function aiSiteStarterFallbackOffered(\n job: Pick<AiJobSummary, 'kind' | 'status' | 'hostId' | 'outputs' | 'review'>,\n): boolean {\n if (job.kind !== 'site' || !job.hostId) return false\n if (job.outputs.
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/ai/src/lib/model/ai-job-failure-copy.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { AiJobKind, AiJobStatus, AiJobSummary } from './ai-jobs.types'\n\n/**\n * What a member reads when a plan could not be made (AGL-3594): one plain\n * sentence and one thing to do, never a rule number or a validator's words.\n *\n * The plan step's own checks refuse an answer in the doctrine's vocabulary —\n * \"Rule 10 (Navigation and SEO travel with a page): A page reuses an\n * address…\" — which is what the one re-ask is told and what staff read to\n * tell a rule that should bend from a model that ignored it. Shown to the\n * person who asked for a site, the same words read as the product breaking.\n * So the review a refused plan stops for carries this sentence as its\n * `message`, and the doctrine's sentence and findings ride beside it as\n * `detail` and `findings`, which the job document keeps and only staff are\n * shown.\n *\n * Pure: no React, no Admin SDK. The drawer's plan card and the plan step read\n * the same words.\n */\n\n/** The violation code the Free wall refuses a plan with. */\nexport const AI_PLAN_FREE_WALL_CODE = 'plan-over-free-wall'\n\n/** What the plan was for, as the sentence names it. */\nfunction planningWhat(kind: AiJobKind | string): string {\n switch (kind) {\n case 'site':\n return 'your site'\n case 'page':\n return 'this page'\n default:\n return 'this'\n }\n}\n\nexport interface AiPlanFailureCopyInput {\n /** The job kind whose plan was refused. */\n kind: AiJobKind | string\n /** The codes of the violations its last answer broke. */\n codes: readonly string[]\n /** The step's credits went back to the Free allowance (AGL-3594). */\n refunded: boolean\n}\n\n/**\n * The sentence a refused plan stops its job with. Over the Free wall, the way\n * out is fewer pages or a paid plan; anything else is ours to have got wrong,\n * and the way out is trying again — said to cost nothing only when it did.\n */\nexport function aiPlanFailureCopy(input: AiPlanFailureCopyInput): string {\n const spent = input.refunded ? ', and it did not use any of your AI credits' : ''\n if (input.codes.includes(AI_PLAN_FREE_WALL_CODE)) {\n return `We couldn't fit this plan into your Free AI credits${spent}. Try fewer pages, or upgrade for more.`\n }\n return `Something went wrong planning ${planningWhat(input.kind)}${spent}. Try again.`\n}\n\n/**\n * Why trying a refused plan again cannot work yet, or `null` when it can: the\n * Free allowance left this month is less than a plan of this kind can cost at\n * its worst. Said with the figures, and with the two ways out.\n */\nexport function aiPlanRetryRefusal(input: { creditsLeft: number; planCredits: number }): string | null {\n const left = Math.max(0, Math.floor(input.creditsLeft))\n if (left >= input.planCredits) return null\n return `You have ${left} AI ${left === 1 ? 'credit' : 'credits'} left this month, and a plan needs up to ${input.planCredits}. Your credits refresh next month, or upgrade for more.`\n}\n\n/**\n * What a guided site start that failed on our side says (AGL-3596): one plain\n * sentence, never a rule. Whether its credits came back is said beside it, from\n * the job's own record (`aiJobRefundCopy`).\n */\nexport const AI_SITE_GUIDED_BUILD_FAILED_COPY = 'Something went wrong building your site, and it was not built.'\n\n/** What a person's own cancel says about its credits: they paid for what ran until then. */\nexport const AI_JOB_CANCELED_CREDITS_COPY = 'You paid for what was spent up to then.'\n\n/**\n * What every surface that shows a stopped job says about its credits\n * (AGL-3596), read off the job's RECORDED give-back (`refundedCredits`),\n * never worked out again: a failure on our side that gave its credits back\n * says so plainly, and a person's own cancel says they paid for what ran.\n * `null` where there is nothing to say — a job still working, done, or one\n * that stopped without a give-back.\n */\nexport function aiJobRefundCopy(\n job: { status: AiJobStatus } & Partial<Pick<AiJobSummary, 'refundedCredits' | 'creditsSpent'>>,\n): string | null {\n const refunded = Math.max(0, Math.floor(job.refundedCredits ?? 0))\n if (refunded > 0) {\n const credits = `${refunded} ${refunded === 1 ? 'credit' : 'credits'}`\n const back = refunded === 1 ? 'is' : 'are'\n const whole = refunded >= Math.floor(job.creditsSpent ?? 0)\n return whole\n ? `This one’s on us — you weren’t charged. The ${credits} it used ${back} back in your AI credits.`\n : `This one’s on us — you weren’t charged for the part that failed. The ${credits} it used ${back} back in your AI credits.`\n }\n if (job.status === 'canceled' && (job.creditsSpent ?? 0) > 0) return AI_JOB_CANCELED_CREDITS_COPY\n return null\n}\n\n/** The guided start's way back to the starter (AGL-3594). */\nexport const AI_SITE_STARTER_FALLBACK_LABEL = 'Use the starter site instead'\n\n/**\n * Whether a job is a guided start that did not work out and can still be\n * traded for the starter (AGL-3594): a site job that failed, was canceled, or\n * stopped for a person on a refused step — never one waiting on its plan,\n * which is a plan to confirm — and that has built nothing, since the starter\n * is written only to a site with no page or layout.\n */\nexport function aiSiteStarterFallbackOffered(\n job: Pick<AiJobSummary, 'kind' | 'status' | 'hostId' | 'outputs' | 'review'>,\n): boolean {\n if (job.kind !== 'site' || !job.hostId) return false\n // The site's listing proposal rides out with the first unit and builds nothing (AGL-3596).\n if (job.outputs.some((output) => output.resource !== 'seo')) return false\n if (job.status === 'failed' || job.status === 'canceled') return true\n return job.status === 'needs_review' && job.review?.reason === 'doctrine'\n}\n"],"names":["AI_PLAN_FREE_WALL_CODE","planningWhat","kind","aiPlanFailureCopy","input","spent","refunded","codes","includes","aiPlanRetryRefusal","left","Math","max","floor","creditsLeft","planCredits","AI_SITE_GUIDED_BUILD_FAILED_COPY","AI_JOB_CANCELED_CREDITS_COPY","aiJobRefundCopy","job","refundedCredits","credits","back","whole","creditsSpent","status","AI_SITE_STARTER_FALLBACK_LABEL","aiSiteStarterFallbackOffered","hostId","outputs","some","output","resource","review","reason"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAID;;;;;;;;;;;;;;;;CAgBC,GAED,0DAA0D,GAC1D,OAAO,MAAMA,yBAAyB,sBAAqB;AAE3D,qDAAqD,GACrD,SAASC,aAAaC,IAAwB;IAC5C,OAAQA;QACN,KAAK;YACH,OAAO;QACT,KAAK;YACH,OAAO;QACT;YACE,OAAO;IACX;AACF;AAWA;;;;CAIC,GACD,OAAO,SAASC,kBAAkBC,KAA6B;IAC7D,MAAMC,QAAQD,MAAME,QAAQ,GAAG,gDAAgD;IAC/E,IAAIF,MAAMG,KAAK,CAACC,QAAQ,CAACR,yBAAyB;QAChD,OAAO,CAAC,mDAAmD,EAAEK,MAAM,uCAAuC,CAAC;IAC7G;IACA,OAAO,CAAC,8BAA8B,EAAEJ,aAAaG,MAAMF,IAAI,IAAIG,MAAM,YAAY,CAAC;AACxF;AAEA;;;;CAIC,GACD,OAAO,SAASI,mBAAmBL,KAAmD;IACpF,MAAMM,OAAOC,KAAKC,GAAG,CAAC,GAAGD,KAAKE,KAAK,CAACT,MAAMU,WAAW;IACrD,IAAIJ,QAAQN,MAAMW,WAAW,EAAE,OAAO;IACtC,OAAO,CAAC,SAAS,EAAEL,KAAK,IAAI,EAAEA,SAAS,IAAI,WAAW,UAAU,yCAAyC,EAAEN,MAAMW,WAAW,CAAC,uDAAuD,CAAC;AACvL;AAEA;;;;CAIC,GACD,OAAO,MAAMC,mCAAmC,iEAAgE;AAEhH,0FAA0F,GAC1F,OAAO,MAAMC,+BAA+B,0CAAyC;AAErF;;;;;;;CAOC,GACD,OAAO,SAASC,gBACdC,GAA8F;QAEtDA,sBASNA;IATlC,MAAMb,WAAWK,KAAKC,GAAG,CAAC,GAAGD,KAAKE,KAAK,EAACM,uBAAAA,IAAIC,eAAe,YAAnBD,uBAAuB;IAC/D,IAAIb,WAAW,GAAG;YAGqBa;QAFrC,MAAME,UAAU,GAAGf,SAAS,CAAC,EAAEA,aAAa,IAAI,WAAW,WAAW;QACtE,MAAMgB,OAAOhB,aAAa,IAAI,OAAO;QACrC,MAAMiB,QAAQjB,YAAYK,KAAKE,KAAK,EAACM,qBAAAA,IAAIK,YAAY,YAAhBL,qBAAoB;QACzD,OAAOI,QACH,CAAC,4CAA4C,EAAEF,QAAQ,SAAS,EAAEC,KAAK,yBAAyB,CAAC,GACjG,CAAC,qEAAqE,EAAED,QAAQ,SAAS,EAAEC,KAAK,yBAAyB,CAAC;IAChI;IACA,IAAIH,IAAIM,MAAM,KAAK,cAAc,EAACN,oBAAAA,IAAIK,YAAY,YAAhBL,oBAAoB,KAAK,GAAG,OAAOF;IACrE,OAAO;AACT;AAEA,2DAA2D,GAC3D,OAAO,MAAMS,iCAAiC,+BAA8B;AAE5E;;;;;;CAMC,GACD,OAAO,SAASC,6BACdR,GAA4E;QAMpCA;IAJxC,IAAIA,IAAIjB,IAAI,KAAK,UAAU,CAACiB,IAAIS,MAAM,EAAE,OAAO;IAC/C,2FAA2F;IAC3F,IAAIT,IAAIU,OAAO,CAACC,IAAI,CAAC,CAACC,SAAWA,OAAOC,QAAQ,KAAK,QAAQ,OAAO;IACpE,IAAIb,IAAIM,MAAM,KAAK,YAAYN,IAAIM,MAAM,KAAK,YAAY,OAAO;IACjE,OAAON,IAAIM,MAAM,KAAK,kBAAkBN,EAAAA,cAAAA,IAAIc,MAAM,qBAAVd,YAAYe,MAAM,MAAK;AACjE"}
|
|
@@ -41,6 +41,9 @@ export interface AiJobNoticeSource {
|
|
|
41
41
|
error?: string | null;
|
|
42
42
|
/** What a guided site start put live (AGL-3596); absent on every other job. */
|
|
43
43
|
sitePublish?: Pick<AiJobSitePublish, 'published' | 'drafts'> | null;
|
|
44
|
+
/** What the job spent, and gave back for a failure on our side (AGL-3596). */
|
|
45
|
+
creditsSpent?: number;
|
|
46
|
+
refundedCredits?: number;
|
|
44
47
|
}
|
|
45
48
|
export type AiJobNotice = Pick<AglynNotification, 'type' | 'title' | 'body' | 'link' | 'orgId' | 'hostId' | 'level'>;
|
|
46
49
|
/**
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/ import { _ as _extends } from "@swc/helpers/_/_extends";
|
|
17
17
|
import { aiJobKindNoun } from "./ai-job-activity.js";
|
|
18
|
+
import { aiJobRefundCopy } from "./ai-job-failure-copy.js";
|
|
18
19
|
/** The besigner segment each versioned resource lives under. */ export const AI_JOB_BESIGNER_SEGMENT = {
|
|
19
20
|
screen: 'screens',
|
|
20
21
|
reusableComponent: 'components',
|
|
@@ -29,6 +30,14 @@ import { aiJobKindNoun } from "./ai-job-activity.js";
|
|
|
29
30
|
* (AGL-3593): the Assist panel reads it on arrival.
|
|
30
31
|
*/ export const AI_JOB_LINK_PARAM = 'aiJob';
|
|
31
32
|
/** Where a site's "Building your site" page lives, under the site (AGL-3594). */ export const AI_SITE_BUILD_HREF = '/ai-jobs';
|
|
33
|
+
/** A stopped job's sentence with what became of its credits, from the job's recorded give-back (AGL-3596). */ function withRefund(job, text, status) {
|
|
34
|
+
const refund = aiJobRefundCopy({
|
|
35
|
+
status,
|
|
36
|
+
refundedCredits: job.refundedCredits,
|
|
37
|
+
creditsSpent: job.creditsSpent
|
|
38
|
+
});
|
|
39
|
+
return refund ? `${text} ${refund}` : text;
|
|
40
|
+
}
|
|
32
41
|
/**
|
|
33
42
|
* Where a notice's link goes, in the stored form the console rewrites when it
|
|
34
43
|
* is followed (`normalizeNotificationLink`): `/{hostId}/…` for the job's site,
|
|
@@ -84,7 +93,7 @@ import { aiJobKindNoun } from "./ai-job-activity.js";
|
|
|
84
93
|
type: 'content.aiJobNeedsYou',
|
|
85
94
|
level: 'warning',
|
|
86
95
|
title: `Your ${noun === 'AI job' ? 'AI job' : `${noun} job`} needs you`,
|
|
87
|
-
body: ((_job_review1 = job.review) == null ? void 0 : _job_review1.message) || job.error || 'It stopped for your decision. It waits in AI jobs.',
|
|
96
|
+
body: withRefund(job, ((_job_review1 = job.review) == null ? void 0 : _job_review1.message) || job.error || 'It stopped for your decision. It waits in AI jobs.', 'needs_review'),
|
|
88
97
|
link
|
|
89
98
|
}, scope);
|
|
90
99
|
}
|
|
@@ -121,7 +130,7 @@ import { aiJobKindNoun } from "./ai-job-activity.js";
|
|
|
121
130
|
type: 'content.aiJobFailed',
|
|
122
131
|
level: 'warning',
|
|
123
132
|
title: `Your ${noun === 'AI job' ? 'AI job' : `${noun} job`} stopped`,
|
|
124
|
-
body: job.error || 'It stopped before it finished.',
|
|
133
|
+
body: withRefund(job, job.error || 'It stopped before it finished.', 'failed'),
|
|
125
134
|
link
|
|
126
135
|
}, scope);
|
|
127
136
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../libs/plugins/ai/src/lib/model/ai-job-notice.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { AglynNotification } from '@aglyn/aglyn/app-utils/notifications'\nimport { aiJobKindNoun } from './ai-job-activity'\nimport type { AiJobKind, AiJobOutput, AiJobReviewReason, AiJobSitePublish } from './ai-jobs.types'\n\n/** The besigner segment each versioned resource lives under. */\nexport const AI_JOB_BESIGNER_SEGMENT: Partial<Record<AiJobOutput['resource'], string>> = {\n screen: 'screens',\n reusableComponent: 'components',\n layout: 'layouts',\n template: 'templates',\n // An email design is a screen: it opens in the screen besigner, as the\n // Emails page's own Edit design does.\n emailScreen: 'screens',\n}\n\n/**\n * The query parameter a console address carries to open AI jobs on one job\n * (AGL-3593): the Assist panel reads it on arrival.\n */\nexport const AI_JOB_LINK_PARAM = 'aiJob'\n\n/** Where a site's \"Building your site\" page lives, under the site (AGL-3594). */\nexport const AI_SITE_BUILD_HREF = '/ai-jobs'\n\n/** A change the person who started a job is told about. */\nexport type AiJobNoticeTransition = 'needs-review' | 'done' | 'failed'\n\n/** The fields of a stored job a notice is written from. */\nexport interface AiJobNoticeSource {\n $id: string\n orgId: string\n hostId?: string | null\n kind: AiJobKind\n review?: { reason: AiJobReviewReason; message?: string | null } | null\n outputs?: readonly AiJobOutput[] | null\n error?: string | null\n /** What a guided site start put live (AGL-3596); absent on every other job. */\n sitePublish?: Pick<AiJobSitePublish, 'published' | 'drafts'> | null\n}\n\nexport type AiJobNotice = Pick<\n AglynNotification,\n 'type' | 'title' | 'body' | 'link' | 'orgId' | 'hostId' | 'level'\n>\n\n/**\n * Where a notice's link goes, in the stored form the console rewrites when it\n * is followed (`normalizeNotificationLink`): `/{hostId}/…` for the job's site,\n * `/org…` for a job of the workspace's.\n *\n * A job that is done leads to what it built (AGL-3593): several pages of the\n * job's site open that site's Pages list, one versioned output opens in the\n * editor on the version the job wrote. Everything else — a plan to confirm, a\n * job that stopped, a done job with nothing of its own to open — opens AI\n * jobs on the job.\n */\nexport function aiJobNoticeLink(job: AiJobNoticeSource, to: AiJobNoticeTransition): string {\n const base = job.hostId ? `/${job.hostId}` : '/org'\n // A site job's every notice opens its \"Building your site\" page (AGL-3594),\n // which leads with the next step whatever the job's state.\n if (job.kind === 'site' && job.hostId) return `${base}${AI_SITE_BUILD_HREF}/${encodeURIComponent(job.$id)}`\n if (to === 'done' && job.hostId) {\n const own = (job.outputs ?? []).filter((output) => output.hostId === job.hostId)\n const screens = own.filter((output) => output.resource === 'screen')\n if (screens.length > 1) return `${base}/screens`\n const versioned = own.find(\n (output) => AI_JOB_BESIGNER_SEGMENT[output.resource] && output.versionId,\n )\n if (own.length === 1 && versioned) {\n const segment = AI_JOB_BESIGNER_SEGMENT[versioned.resource]\n return `${base}/${segment}/${versioned.id}/versions/${versioned.versionId}/besigner`\n }\n }\n return `${base}?${AI_JOB_LINK_PARAM}=${encodeURIComponent(job.$id)}`\n}\n\n/**\n * The in-app notification for one change of one job (AGL-3593), for the\n * person who created it. Customer-safe throughout: a stopped job's sentence is\n * the job's own `error`, which the machine writes as a fixed sentence.\n */\nexport function aiJobNotice(job: AiJobNoticeSource, to: AiJobNoticeTransition): AiJobNotice {\n const noun = aiJobKindNoun(job.kind)\n const scope = { orgId: job.orgId, ...(job.hostId ? { hostId: job.hostId } : {}) }\n const link = aiJobNoticeLink(job, to)\n if (to === 'needs-review') {\n if (job.review?.reason === 'plan') {\n return {\n type: 'content.aiJobNeedsYou',\n level: 'warning',\n title:\n noun === 'AI job'\n ? 'Your plan is ready: confirm it to build'\n : `Your ${noun} plan is ready: confirm it to build`,\n body: 'Nothing is built until you confirm the plan. It waits in AI jobs.',\n link,\n ...scope,\n }\n }\n return {\n type: 'content.aiJobNeedsYou',\n level: 'warning',\n title: `Your ${noun === 'AI job' ? 'AI job' : `${noun} job`} needs you`,\n body: job.review?.message || job.error || 'It stopped for your decision. It waits in AI jobs.',\n link,\n ...scope,\n }\n }\n if (to === 'done') {\n // A guided site start publishes its pages when it finishes (AGL-3596):\n // with one live, the site is, and the build page lists any that stayed\n // drafts with the reason for each.\n const live = job.kind === 'site' ? (job.sitePublish?.published.length ?? 0) : 0\n if (live > 0) {\n const drafts = job.sitePublish?.drafts.length ?? 0\n return {\n type: 'content.aiJobDone',\n level: 'success',\n title: 'Your site is live',\n body:\n drafts > 0\n ? `Your pages are published, except ${drafts === 1 ? 'one that stayed a draft' : `${drafts} that stayed drafts`}. Open it to see why.`\n : 'Your pages are published. Open it to view your site or edit your pages.',\n link,\n ...scope,\n }\n }\n const pages = (job.outputs ?? []).filter((output) => output.resource === 'screen').length\n const title =\n job.kind === 'site' || pages > 1\n ? 'Your site’s draft pages are ready'\n : job.kind === 'page'\n ? 'Your draft page is ready'\n : noun === 'AI job'\n ? 'Your AI job finished'\n : `Your ${noun} is ready`\n return {\n type: 'content.aiJobDone',\n level: 'success',\n title,\n body:\n job.kind === 'insight' || job.kind === 'text'\n ? 'Open AI jobs to read it.'\n : 'Everything it built is an unpublished draft until you publish it.',\n link,\n ...scope,\n }\n }\n return {\n type: 'content.aiJobFailed',\n level: 'warning',\n title: `Your ${noun === 'AI job' ? 'AI job' : `${noun} job`} stopped`,\n body: job.error || 'It stopped before it finished.',\n link,\n ...scope,\n }\n}\n"],"names":["aiJobKindNoun","AI_JOB_BESIGNER_SEGMENT","screen","reusableComponent","layout","template","emailScreen","AI_JOB_LINK_PARAM","AI_SITE_BUILD_HREF","aiJobNoticeLink","job","to","base","hostId","kind","encodeURIComponent","$id","own","outputs","filter","output","screens","resource","length","versioned","find","versionId","segment","id","aiJobNotice","noun","scope","orgId","link","review","reason","type","level","title","body","message","error","live","sitePublish","published","drafts","pages"],"mappings":"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"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/ai/src/lib/model/ai-job-notice.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { AglynNotification } from '@aglyn/aglyn/app-utils/notifications'\nimport { aiJobKindNoun } from './ai-job-activity'\nimport { aiJobRefundCopy } from './ai-job-failure-copy'\nimport type { AiJobKind, AiJobOutput, AiJobReviewReason, AiJobSitePublish } from './ai-jobs.types'\n\n/** The besigner segment each versioned resource lives under. */\nexport const AI_JOB_BESIGNER_SEGMENT: Partial<Record<AiJobOutput['resource'], string>> = {\n screen: 'screens',\n reusableComponent: 'components',\n layout: 'layouts',\n template: 'templates',\n // An email design is a screen: it opens in the screen besigner, as the\n // Emails page's own Edit design does.\n emailScreen: 'screens',\n}\n\n/**\n * The query parameter a console address carries to open AI jobs on one job\n * (AGL-3593): the Assist panel reads it on arrival.\n */\nexport const AI_JOB_LINK_PARAM = 'aiJob'\n\n/** Where a site's \"Building your site\" page lives, under the site (AGL-3594). */\nexport const AI_SITE_BUILD_HREF = '/ai-jobs'\n\n/** A change the person who started a job is told about. */\nexport type AiJobNoticeTransition = 'needs-review' | 'done' | 'failed'\n\n/** The fields of a stored job a notice is written from. */\nexport interface AiJobNoticeSource {\n $id: string\n orgId: string\n hostId?: string | null\n kind: AiJobKind\n review?: { reason: AiJobReviewReason; message?: string | null } | null\n outputs?: readonly AiJobOutput[] | null\n error?: string | null\n /** What a guided site start put live (AGL-3596); absent on every other job. */\n sitePublish?: Pick<AiJobSitePublish, 'published' | 'drafts'> | null\n /** What the job spent, and gave back for a failure on our side (AGL-3596). */\n creditsSpent?: number\n refundedCredits?: number\n}\n\n/** A stopped job's sentence with what became of its credits, from the job's recorded give-back (AGL-3596). */\nfunction withRefund(job: AiJobNoticeSource, text: string, status: 'failed' | 'needs_review'): string {\n const refund = aiJobRefundCopy({ status, refundedCredits: job.refundedCredits, creditsSpent: job.creditsSpent })\n return refund ? `${text} ${refund}` : text\n}\n\nexport type AiJobNotice = Pick<\n AglynNotification,\n 'type' | 'title' | 'body' | 'link' | 'orgId' | 'hostId' | 'level'\n>\n\n/**\n * Where a notice's link goes, in the stored form the console rewrites when it\n * is followed (`normalizeNotificationLink`): `/{hostId}/…` for the job's site,\n * `/org…` for a job of the workspace's.\n *\n * A job that is done leads to what it built (AGL-3593): several pages of the\n * job's site open that site's Pages list, one versioned output opens in the\n * editor on the version the job wrote. Everything else — a plan to confirm, a\n * job that stopped, a done job with nothing of its own to open — opens AI\n * jobs on the job.\n */\nexport function aiJobNoticeLink(job: AiJobNoticeSource, to: AiJobNoticeTransition): string {\n const base = job.hostId ? `/${job.hostId}` : '/org'\n // A site job's every notice opens its \"Building your site\" page (AGL-3594),\n // which leads with the next step whatever the job's state.\n if (job.kind === 'site' && job.hostId) return `${base}${AI_SITE_BUILD_HREF}/${encodeURIComponent(job.$id)}`\n if (to === 'done' && job.hostId) {\n const own = (job.outputs ?? []).filter((output) => output.hostId === job.hostId)\n const screens = own.filter((output) => output.resource === 'screen')\n if (screens.length > 1) return `${base}/screens`\n const versioned = own.find(\n (output) => AI_JOB_BESIGNER_SEGMENT[output.resource] && output.versionId,\n )\n if (own.length === 1 && versioned) {\n const segment = AI_JOB_BESIGNER_SEGMENT[versioned.resource]\n return `${base}/${segment}/${versioned.id}/versions/${versioned.versionId}/besigner`\n }\n }\n return `${base}?${AI_JOB_LINK_PARAM}=${encodeURIComponent(job.$id)}`\n}\n\n/**\n * The in-app notification for one change of one job (AGL-3593), for the\n * person who created it. Customer-safe throughout: a stopped job's sentence is\n * the job's own `error`, which the machine writes as a fixed sentence.\n */\nexport function aiJobNotice(job: AiJobNoticeSource, to: AiJobNoticeTransition): AiJobNotice {\n const noun = aiJobKindNoun(job.kind)\n const scope = { orgId: job.orgId, ...(job.hostId ? { hostId: job.hostId } : {}) }\n const link = aiJobNoticeLink(job, to)\n if (to === 'needs-review') {\n if (job.review?.reason === 'plan') {\n return {\n type: 'content.aiJobNeedsYou',\n level: 'warning',\n title:\n noun === 'AI job'\n ? 'Your plan is ready: confirm it to build'\n : `Your ${noun} plan is ready: confirm it to build`,\n body: 'Nothing is built until you confirm the plan. It waits in AI jobs.',\n link,\n ...scope,\n }\n }\n return {\n type: 'content.aiJobNeedsYou',\n level: 'warning',\n title: `Your ${noun === 'AI job' ? 'AI job' : `${noun} job`} needs you`,\n body: withRefund(job, job.review?.message || job.error || 'It stopped for your decision. It waits in AI jobs.', 'needs_review'),\n link,\n ...scope,\n }\n }\n if (to === 'done') {\n // A guided site start publishes its pages when it finishes (AGL-3596):\n // with one live, the site is, and the build page lists any that stayed\n // drafts with the reason for each.\n const live = job.kind === 'site' ? (job.sitePublish?.published.length ?? 0) : 0\n if (live > 0) {\n const drafts = job.sitePublish?.drafts.length ?? 0\n return {\n type: 'content.aiJobDone',\n level: 'success',\n title: 'Your site is live',\n body:\n drafts > 0\n ? `Your pages are published, except ${drafts === 1 ? 'one that stayed a draft' : `${drafts} that stayed drafts`}. Open it to see why.`\n : 'Your pages are published. Open it to view your site or edit your pages.',\n link,\n ...scope,\n }\n }\n const pages = (job.outputs ?? []).filter((output) => output.resource === 'screen').length\n const title =\n job.kind === 'site' || pages > 1\n ? 'Your site’s draft pages are ready'\n : job.kind === 'page'\n ? 'Your draft page is ready'\n : noun === 'AI job'\n ? 'Your AI job finished'\n : `Your ${noun} is ready`\n return {\n type: 'content.aiJobDone',\n level: 'success',\n title,\n body:\n job.kind === 'insight' || job.kind === 'text'\n ? 'Open AI jobs to read it.'\n : 'Everything it built is an unpublished draft until you publish it.',\n link,\n ...scope,\n }\n }\n return {\n type: 'content.aiJobFailed',\n level: 'warning',\n title: `Your ${noun === 'AI job' ? 'AI job' : `${noun} job`} stopped`,\n body: withRefund(job, job.error || 'It stopped before it finished.', 'failed'),\n link,\n ...scope,\n }\n}\n"],"names":["aiJobKindNoun","aiJobRefundCopy","AI_JOB_BESIGNER_SEGMENT","screen","reusableComponent","layout","template","emailScreen","AI_JOB_LINK_PARAM","AI_SITE_BUILD_HREF","withRefund","job","text","status","refund","refundedCredits","creditsSpent","aiJobNoticeLink","to","base","hostId","kind","encodeURIComponent","$id","own","outputs","filter","output","screens","resource","length","versioned","find","versionId","segment","id","aiJobNotice","noun","scope","orgId","link","review","reason","type","level","title","body","message","error","live","sitePublish","published","drafts","pages"],"mappings":"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"}
|
|
@@ -53,7 +53,7 @@ import type { AiBuildPlan } from './ai-build-plan';
|
|
|
53
53
|
* so a kind's presence in the union says the job model accepts it, not that
|
|
54
54
|
* a runner exists.
|
|
55
55
|
*/
|
|
56
|
-
export type AiJobKind = 'page' | 'component' | 'layout' | 'template' | 'edit' | 'seo' | 'site' | 'email' | 'campaign' | 'form' | 'experiment' | 'insight' | 'products' | 'crm' | 'onboarding' | 'workflow' | 'text' | 'theme';
|
|
56
|
+
export type AiJobKind = 'page' | 'component' | 'layout' | 'template' | 'edit' | 'seo' | 'site' | 'email' | 'campaign' | 'form' | 'experiment' | 'insight' | 'products' | 'crm' | 'onboarding' | 'workflow' | 'logic' | 'text' | 'theme' | 'build';
|
|
57
57
|
/** The union as a value, so a route can validate a body against it. */
|
|
58
58
|
export declare const AI_JOB_KINDS: readonly AiJobKind[];
|
|
59
59
|
/**
|
|
@@ -152,7 +152,9 @@ export interface AiJobStepRunStop {
|
|
|
152
152
|
/** Tokens the run generated, over every model call it made. */
|
|
153
153
|
output: number;
|
|
154
154
|
}
|
|
155
|
-
export type AiJobOutputResource = 'screen' | 'reusableComponent' | 'layout' | 'template' | 'form' | 'emailScreen' | 'campaign' | 'product' | 'experiment' | 'workflow' | 'text' | 'theme' | 'seo' | 'insight' | 'crm'
|
|
155
|
+
export type AiJobOutputResource = 'screen' | 'reusableComponent' | 'layout' | 'template' | 'form' | 'emailScreen' | 'campaign' | 'product' | 'experiment' | 'workflow' | 'text' | 'theme' | 'seo' | 'insight' | 'crm'
|
|
156
|
+
/** A draft another plugin wrote for a build (AGL-3616), named by `draftResource`. */
|
|
157
|
+
| 'draft' | 'logic' | 'orgAutomation';
|
|
156
158
|
/**
|
|
157
159
|
* One thing a job wrote. Addressed by resource and id so the console can
|
|
158
160
|
* build the "open draft" link without knowing what the runner did; `text`
|
|
@@ -175,6 +177,14 @@ export type AiJobOutputResource = 'screen' | 'reusableComponent' | 'layout' | 't
|
|
|
175
177
|
* step, an email draft, or an import's column matches. The CRM's own task
|
|
176
178
|
* form, stage route, composer and import drawer are the writes, and a person
|
|
177
179
|
* makes each of them, or does not.
|
|
180
|
+
*
|
|
181
|
+
* A `logic` output is a proposal too (AGL-3603): a site function or variable
|
|
182
|
+
* the Functions & Variables editor opens unsaved. Saving it is the editor's
|
|
183
|
+
* write, which a person makes, or does not.
|
|
184
|
+
*
|
|
185
|
+
* An `orgAutomation` output is a proposal too (AGL-3603): one of the
|
|
186
|
+
* workspace's automations, which the Org automations editor opens unsaved and
|
|
187
|
+
* switched off. `hostId` is `null`: it belongs to no one site.
|
|
178
188
|
*/
|
|
179
189
|
export interface AiJobOutput {
|
|
180
190
|
resource: AiJobOutputResource;
|
|
@@ -209,6 +219,11 @@ export interface AiJobOutput {
|
|
|
209
219
|
* anything is applied. Absent where the output is not a page's document.
|
|
210
220
|
*/
|
|
211
221
|
load?: AiLoadEstimate | null;
|
|
222
|
+
/**
|
|
223
|
+
* For a `draft` output (AGL-3616): the resource whose owner wrote it, as
|
|
224
|
+
* its writer is registered on the resource-draft seam.
|
|
225
|
+
*/
|
|
226
|
+
draftResource?: string;
|
|
212
227
|
}
|
|
213
228
|
export interface AiJobLease {
|
|
214
229
|
/** The process that holds the step: a route request id or a beat id. */
|
|
@@ -311,6 +326,56 @@ export interface AiJobPlan extends AiBuildPlan {
|
|
|
311
326
|
/** The job this plan was reused from, when it was not asked for again. */
|
|
312
327
|
reusedFrom?: string;
|
|
313
328
|
}
|
|
329
|
+
/**
|
|
330
|
+
* Where one item of a `build` job stands (AGL-3616). A build settles item by
|
|
331
|
+
* item: a failed item gives back its own spend and the rest of the plan still
|
|
332
|
+
* runs, so the job keeps one row per item, written only by the machine's
|
|
333
|
+
* `recordStep` — in the same transaction as the spend it accounts for — and
|
|
334
|
+
* by the resume door's retry.
|
|
335
|
+
*/
|
|
336
|
+
export type AiJobItemStatus = 'pending' | 'running' | 'succeeded' | 'degraded' | 'failed' | 'skipped';
|
|
337
|
+
/** Why an item failed: a give-back reason when it was ours, else the model's refusal or a review. */
|
|
338
|
+
export type AiJobItemFailureReason = 'plan-refused' | 'doctrine-refused' | 'provider' | 'timeout' | 'step-failure' | 'unavailable' | 'refused' | 'review';
|
|
339
|
+
export interface AiJobItemFailure {
|
|
340
|
+
/** Whether the failure was on our side: only then is the item's spend given back. */
|
|
341
|
+
ours: boolean;
|
|
342
|
+
reason: AiJobItemFailureReason;
|
|
343
|
+
/** Customer-safe. */
|
|
344
|
+
message: string;
|
|
345
|
+
}
|
|
346
|
+
export interface AiJobItemLedger {
|
|
347
|
+
/** The unit's slot within the plan: `c0` a creation, `p0` a page, `i0` an item. */
|
|
348
|
+
slot: string;
|
|
349
|
+
/** The capability operation that builds it: `page`, `form`, or an owner's op. */
|
|
350
|
+
op: string;
|
|
351
|
+
/** What a person reads: the page's title, the creation's or item's name. */
|
|
352
|
+
label: string;
|
|
353
|
+
status: AiJobItemStatus;
|
|
354
|
+
/** Bumped by Try again; the refund key names it, so each attempt gives back once. */
|
|
355
|
+
attempt: number;
|
|
356
|
+
/** What this item's passes cost, every attempt. */
|
|
357
|
+
creditsSpent: number;
|
|
358
|
+
/** What this attempt's passes cost so far: what a failure of this attempt gives back. */
|
|
359
|
+
attemptCredits?: number;
|
|
360
|
+
/** What was given back for this item's failures. */
|
|
361
|
+
creditsRefunded: number;
|
|
362
|
+
/** The key the latest give-back for this item was made under. */
|
|
363
|
+
refundKey?: string;
|
|
364
|
+
failure?: AiJobItemFailure | null;
|
|
365
|
+
/** The ids of the outputs this item produced. */
|
|
366
|
+
outputs: string[];
|
|
367
|
+
/** The slots whose failure changed how this item was built. */
|
|
368
|
+
degradedBy?: string[];
|
|
369
|
+
/** Customer-safe: what the person should know about this item. */
|
|
370
|
+
note?: string | null;
|
|
371
|
+
}
|
|
372
|
+
/** Whether a build's own planning was charged or given back (AGL-3616). */
|
|
373
|
+
export interface AiJobOrchestration {
|
|
374
|
+
/** What the plan step spent. */
|
|
375
|
+
creditsSpent: number;
|
|
376
|
+
/** `charged` once anything was delivered; `refunded` when nothing was. */
|
|
377
|
+
settled: 'pending' | 'charged' | 'refunded';
|
|
378
|
+
}
|
|
314
379
|
export interface AiJob {
|
|
315
380
|
$id: string;
|
|
316
381
|
orgId: string;
|
|
@@ -370,6 +435,10 @@ export interface AiJob {
|
|
|
370
435
|
* other job, which leaves its pages as drafts.
|
|
371
436
|
*/
|
|
372
437
|
sitePublish?: AiJobSitePublish | null;
|
|
438
|
+
/** A `build` job's items, one row each (AGL-3616); absent on every other kind. */
|
|
439
|
+
items?: AiJobItemLedger[] | null;
|
|
440
|
+
/** A `build` job's planning spend and how it settled (AGL-3616). */
|
|
441
|
+
orchestration?: AiJobOrchestration | null;
|
|
373
442
|
}
|
|
374
443
|
/**
|
|
375
444
|
* A guided site start's publish (AGL-3596): the pages that went live, with
|
|
@@ -462,4 +531,20 @@ export interface AiJobSummary {
|
|
|
462
531
|
} | null;
|
|
463
532
|
/** What a guided site start put live (AGL-3596); absent on every other job. */
|
|
464
533
|
sitePublish?: AiJobSitePublish | null;
|
|
534
|
+
/**
|
|
535
|
+
* A site job's answers (AGL-3596): the guided start's questions as the person
|
|
536
|
+
* answered them, so a failed start's Try again reopens them filled in. The
|
|
537
|
+
* scalar site inputs only, never anything else a job's inputs carry; absent
|
|
538
|
+
* on every other kind.
|
|
539
|
+
*/
|
|
540
|
+
siteInputs?: Record<string, unknown> | null;
|
|
541
|
+
/** A `build` job's items (AGL-3616); absent on every other job. */
|
|
542
|
+
items?: AiJobItemLedger[];
|
|
543
|
+
/**
|
|
544
|
+
* Whether a build's request asked to publish (AGL-3616), so its plan card
|
|
545
|
+
* offers the box that confirms it. Absent on every other job.
|
|
546
|
+
*/
|
|
547
|
+
publishAsked?: boolean;
|
|
548
|
+
/** A `build` job's planning spend and how it settled (AGL-3616). */
|
|
549
|
+
orchestration?: AiJobOrchestration;
|
|
465
550
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../libs/plugins/ai/src/lib/model/ai-jobs.types.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { ITimestamp } from '@aglyn/shared-util-timestamp'\nimport type { AiEffort } from '../providers/contract'\nimport type { AiLoadEstimate } from '../runtime/ai-palette'\nimport type { AiBuildPlan } from './ai-build-plan'\n\n/**\n * AI generation jobs (AGL-2904).\n *\n * A job is one customer brief carried through one or more model steps by a\n * Firestore state machine, so that work longer than a request can survive\n * the request: the console route runs what it can inline, and the platform\n * job beat resumes whatever is left. The document is the whole state — no\n * process holds anything the next beat cannot read back.\n *\n * ── Outputs are drafts, never a publish ──────────────────────────────────\n *\n * Every output a job produces is a NEW draft or a new unpublished version of\n * an existing resource. A job never flips a version pointer, never registers\n * a route and never sends anything; a person opens the draft the job names\n * and publishes it through the door that already exists for that resource.\n * That is what lets a job run with no visitor, no session and no confirm\n * gate — the thing it writes cannot be seen by anyone but the workspace\n * until a member chooses otherwise.\n *\n * ── The lease ────────────────────────────────────────────────────────────\n *\n * A step runs under a lease: an owner id and an `until` instant. Two beats\n * fire a minute apart against a 120 s function timeout, and a console route\n * may still be running the first step when the first beat looks, so the\n * lease is what stops the same step being run — and metered — twice. A\n * claim is a transaction that refuses while another owner's lease is live;\n * an expired lease is simply claimable, which is also how a step abandoned\n * by a frozen process is recovered.\n */\n\n/**\n * What a job produces. `text` and `theme` have runners; every other kind is\n * registered and refuses with \"not available yet\" until its own issue lands,\n * so a kind's presence in the union says the job model accepts it, not that\n * a runner exists.\n */\nexport type AiJobKind =\n | 'page'\n | 'component'\n | 'layout'\n | 'template'\n | 'edit'\n | 'seo'\n | 'site'\n | 'email'\n | 'campaign'\n | 'form'\n | 'experiment'\n | 'insight'\n | 'products'\n | 'crm'\n | 'onboarding'\n | 'workflow'\n | 'text'\n | 'theme'\n\n/** The union as a value, so a route can validate a body against it. */\nexport const AI_JOB_KINDS: readonly AiJobKind[] = [\n 'page',\n 'component',\n 'layout',\n 'template',\n 'edit',\n 'seo',\n 'site',\n 'email',\n 'campaign',\n 'form',\n 'experiment',\n 'insight',\n 'products',\n 'crm',\n 'onboarding',\n 'workflow',\n 'text',\n 'theme',\n]\n\n/**\n * `queued` — waiting for a runner; `running` — a step holds the lease;\n * `needs_input` — the job stopped for something only the workspace can\n * change (credits, a cap, a switch), and the beat tries it again once that\n * may have changed; `needs_review` — the job stopped for a person's decision\n * (AGL-2935): its plan is ready to confirm, or an answer broke a building\n * rule on its re-ask. No timer can make that decision, so neither the beat\n * nor anything but that person resumes it. The last three are terminal.\n */\nexport type AiJobStatus =\n | 'queued'\n | 'running'\n | 'needs_input'\n | 'needs_review'\n | 'done'\n | 'failed'\n | 'canceled'\n\nexport const AI_JOB_TERMINAL_STATUSES: readonly AiJobStatus[] = [\n 'done',\n 'failed',\n 'canceled',\n]\n\nexport type AiJobStepStatus = 'pending' | 'running' | 'done' | 'failed'\n\n/** The step a planned kind runs first (AGL-2935): its plan, before anything is built. */\nexport const AI_JOB_PLAN_STEP = 'plan'\n\nexport interface AiJobStep {\n /** Stable within the job (`plan`, `draft`, `generate`), unique per job. */\n name: string\n status: AiJobStepStatus\n startedAt?: ITimestamp | null\n endedAt?: ITimestamp | null\n /** Credits this step has actually cost, at the plan's credit rate. */\n creditsSpent: number\n /** Customer-safe only; provider detail goes to the server log. */\n error?: string | null\n /**\n * How many times a runner has been handed this step. A retryable provider\n * failure hands the step back as `pending`; the count is what stops a\n * provider outage re-running a step forever.\n */\n attempts?: number\n /**\n * Passes of a step that works through a list (AGL-2910): each one a\n * recorded, metered exchange that asked to continue. Attempts count again\n * from zero after a pass; this count is what bounds the step.\n */\n passes?: number\n /**\n * What the step's model calls cost in tokens and time (AGL-2937), summed\n * over every run that reached the provider. Absent on a step none has.\n */\n tokens?: AiJobStepTokens\n /**\n * The ids the step writes its drafts under, by draft (AGL-3079): minted\n * when the job is created, so every run of the step names the same drafts.\n * Absent on a step that writes none; a step that records none names its\n * drafts by the job's own id.\n */\n draftIds?: Partial<Record<AiJobDraftSlot, string>>\n}\n\n/**\n * A draft a job's kind always writes (AGL-3079): a screen, layout, template,\n * form or component; an email design; a campaign; an automation.\n */\nexport type AiJobDraftSlot =\n | 'screen'\n | 'layout'\n | 'template'\n | 'form'\n | 'component'\n | 'email'\n | 'campaign'\n | 'workflow'\n\n/**\n * A step's measure (AGL-2937): the four token counts the meter prices, the\n * time spent in the runner, and the model and thinking effort of the last\n * run. The machine writes it beside `creditsSpent`, so what a kind of step\n * costs in tokens is read off the job rather than inferred from the month.\n */\nexport interface AiJobStepTokens {\n /** Prompt tokens sent uncached. */\n input: number\n /** Prompt tokens read from the prompt cache. */\n cachedRead: number\n /** Prompt tokens written to the prompt cache. */\n cacheWrite: number\n /** Tokens generated, thinking included. */\n output: number\n /** The model the last run was served by. */\n model: string | null\n /** The thinking effort the last run asked for; `null` when it named none. */\n effort: AiEffort | null\n /** Milliseconds spent in the runner, summed over runs. */\n latencyMs: number\n /** Runs that reached the provider. */\n runs: number\n /**\n * Why the step's latest runs stopped (AGL-3042), oldest first and the last\n * run last: each run's stop reason and the tokens it generated, so a pass\n * cut off at its ceiling reads off the job rather than out of the sums. At\n * most `AI_JOB_STEP_LAST_RUNS` are kept; absent on a step measured before.\n */\n lastRuns?: AiJobStepRunStop[]\n}\n\n/** One run of a step, by why it stopped (AGL-3042). */\nexport interface AiJobStepRunStop {\n /**\n * The stop reason of the run's last model call — `tool_use` or `end_turn`\n * for an answer, `max_tokens` for one cut off at its ceiling, `refusal` —\n * and `null` when the provider named none.\n */\n stopReason: string | null\n /** Tokens the run generated, over every model call it made. */\n output: number\n}\n\nexport type AiJobOutputResource =\n | 'screen'\n | 'reusableComponent'\n | 'layout'\n | 'template'\n | 'form'\n | 'emailScreen'\n | 'campaign'\n | 'product'\n | 'experiment'\n | 'workflow'\n | 'text'\n | 'theme'\n | 'seo'\n | 'insight'\n | 'crm'\n\n/**\n * One thing a job wrote. Addressed by resource and id so the console can\n * build the \"open draft\" link without knowing what the runner did; `text`\n * has no document of its own, so its body rides on the output itself.\n *\n * A `theme` output is a proposal rather than a document (AGL-2938). A site's\n * theme is fields on its host document, and writing those fields is the save\n * the Theme section's editor performs, which a job never does. So the change\n * set rides on the output as `proposal`, and a person puts it in the editor\n * and saves it there, or does not.\n *\n * An `seo` output is a proposal rather than a document (AGL-2910): search\n * listing values for a page or a product, or a site audit's findings and\n * fixes. A screen's listing is served from the screen document itself, so a\n * job never writes it; the values ride on the output as `proposal`, a person\n * puts them in the editor and saves them there, and an audit's content fixes\n * become new versions only when a person applies them.\n *\n * A `crm` output is a proposal too (AGL-2917): a record's summary and next\n * step, an email draft, or an import's column matches. The CRM's own task\n * form, stage route, composer and import drawer are the writes, and a person\n * makes each of them, or does not.\n */\nexport interface AiJobOutput {\n resource: AiJobOutputResource\n id: string\n /** The unpublished version the job created, where the resource has versions. */\n versionId?: string | null\n /** `null` for an output that belongs to the org rather than one site. */\n hostId: string | null\n /**\n * The site's subdomain, which is what a console URL names a site by: the\n * `[host]` segment resolves by subdomain, so a link built from `hostId`\n * names no site the console can open.\n */\n hostSubdomain?: string | null\n label: string\n /** The body of a `text` output. Absent on every other resource. */\n text?: string\n /**\n * The change set of an output a person applies rather than opens — a\n * `theme` or `seo` proposal — in the shape its job kind's runner defines.\n */\n proposal?: Record<string, unknown>\n /**\n * What the person decides next about this output, in customer-safe words:\n * a routing the draft could not store, or part of the brief it could not\n * build. Absent when there is nothing to decide.\n */\n note?: string | null\n /**\n * What a first visit is estimated to transfer, as the doctrine measured\n * the generated document (AGL-2935) — the weight the proposal shows before\n * anything is applied. Absent where the output is not a page's document.\n */\n load?: AiLoadEstimate | null\n}\n\nexport interface AiJobLease {\n /** The process that holds the step: a route request id or a beat id. */\n owner: string\n until: ITimestamp\n}\n\n/** Why a job stopped for a person (AGL-2935). */\nexport type AiJobReviewReason =\n /** The plan step proposed a plan; generation waits for it to be confirmed. */\n | 'plan'\n /** An answer broke a building rule, and so did the answer to the re-ask. */\n | 'doctrine'\n /**\n * The site is at an allowance its plan sets for what the step writes, such\n * as its shared layouts or its templates (AGL-2909). Freeing one, or a plan\n * that holds more, is the member's decision; trying again runs the step\n * again.\n */\n | 'limit'\n\n/**\n * A building rule an answer broke, as the job keeps it: the number, the code,\n * the sentence, and where in the answer it was broken (AGL-3078).\n */\nexport interface AiJobRuleFinding {\n rule: number | null\n code: string\n /** Customer-safe. */\n message: string\n /** The nodes the finding names, by the ids the refused answer gave them. Absent when it names none. */\n nodeIds?: string[]\n /** The plan entries or answer fields it names, as `screens[0].sections[2]`. Absent when it names none. */\n paths?: string[]\n}\n\n/**\n * One node of the parts of a refused answer its findings name (AGL-3078), as\n * the review keeps it: the node's place, its element and the names of what it\n * sets, and never its copy. A Grid keeps the values of its layout props as\n * they were written, so a review can tell a shape the rules refuse from one\n * the model was asked to mend and did not.\n */\nexport interface AiJobReviewOutlineNode {\n /** The node's id, as the refused answer wrote it. */\n id: string\n /** How far below a node a finding names it sits: 0 for that node. */\n depth: number\n componentId: string\n /** The props it sets, by name only. */\n props: string[]\n /** The `sx` keys it sets, by name only; absent when it sets none. */\n sx?: string[]\n /** A Grid's layout props, `container`, `size`, `direction`, `spacing` and the rest, as written. */\n grid?: Record<string, string | number | boolean | null>\n /** Its children's element ids, in order. */\n children: string[]\n}\n\nexport interface AiJobReview {\n reason: AiJobReviewReason\n /** Customer-safe: what the person is asked to decide. */\n message: string\n /** The rules the last answer broke; empty for a plan. */\n findings: AiJobRuleFinding[]\n /**\n * The parts of the refused answer its findings name, each node with the\n * nodes below it (AGL-3078); absent when they name none. Kept with the job\n * for diagnosis, and shown to staff.\n */\n outline?: AiJobReviewOutlineNode[]\n /**\n * The checks' own sentence, where `message` was written for the member\n * instead (AGL-3594): rule numbers and all, for staff. Its presence is what\n * tells the drawer the findings are staff reading too.\n */\n detail?: string\n /**\n * Why trying again cannot work yet (AGL-3594) — the Free allowance left is\n * less than the step can cost — or absent when it can. The button is drawn\n * disabled with this beside it.\n */\n retryRefusal?: string\n}\n\nexport type AiJobPlanStatus = 'proposed' | 'confirmed'\n\n/** The plan a job builds from, as the job keeps it once its plan step proposed it. */\nexport interface AiJobPlan extends AiBuildPlan {\n status: AiJobPlanStatus\n /** Names for the inventory ids the plan references, read when it was made. */\n labels: Record<string, string>\n proposedAt: ITimestamp\n confirmedAt: ITimestamp | null\n /** The member who confirmed it. */\n confirmedBy: string | null\n /**\n * A digest of the whole request that produced this plan (AGL-2937): the\n * job's kind, site, brief and scalar inputs, the model that answered, and\n * the prompt as it was rendered — the site inventory included. A later job\n * whose request hashes the same reuses this plan rather than paying for the\n * same answer again. A hash of the request, never of the answer, and no\n * part of the brief is recoverable from it.\n */\n key?: string\n /** The job this plan was reused from, when it was not asked for again. */\n reusedFrom?: string\n}\n\nexport interface AiJob {\n $id: string\n orgId: string\n hostId?: string | null\n kind: AiJobKind\n status: AiJobStatus\n /** The customer's brief, verbatim. Expires with the document. */\n brief: string\n /** Kind-specific inputs the runner reads (a screen id to edit, a tone). */\n inputs: Record<string, unknown>\n /**\n * The model the creator picked for the job's steps (AGL-2942), or `null`\n * for Auto. Each step honors it only where the plan and the allotment\n * allowlists allow it, and runs on the routing table otherwise.\n */\n model?: string | null\n steps: AiJobStep[]\n outputs: AiJobOutput[]\n /**\n * The nominal credit figure held against the job while steps are\n * outstanding. The meter's real bound is the per-step message reservation\n * and the org's monthly ceiling; this is the number the console shows so\n * a running job is not read as free.\n */\n creditsReserved: number\n creditsSpent: number\n /**\n * Credits the job gave back because it failed on our side (AGL-3594),\n * summed over its give-backs; absent when it gave none. `creditsSpent`\n * stays what ran, so what the job cost is the one less the other.\n */\n refundedCredits?: number\n /** Why the latest give-back was made (`AiJobRefundReason`). */\n refundReason?: string\n /** How many give-backs the job has had: the next one's key. */\n refunds?: number\n createdBy: string\n createdAt: ITimestamp\n updatedAt: ITimestamp\n /** TTL — the brief is verbatim customer text and expires like an exchange. */\n expiresAt: ITimestamp\n /** Customer-safe only. */\n error?: string | null\n lease?: AiJobLease | null\n /** The plan the job builds from, once its plan step proposed one. */\n plan?: AiJobPlan | null\n /** What the person is asked to decide while the job is `needs_review`. */\n review?: AiJobReview | null\n /**\n * What a person applied from the job's outputs (AGL-2910). Written by the\n * door that applied them, never by a step runner, and absent until then.\n */\n applied?: AiJobApplied | null\n /**\n * What a guided site start put live when it finished (AGL-3596): written\n * once by the site step's last pass, never by a person. Absent on every\n * other job, which leaves its pages as drafts.\n */\n sitePublish?: AiJobSitePublish | null\n}\n\n/**\n * A guided site start's publish (AGL-3596): the pages that went live, with\n * the address each answers, and the pages that stayed drafts, each with the\n * plain sentence for why. A page that stayed a draft never fails the job.\n */\nexport interface AiJobSitePublish {\n /** The site's live address, `https://<subdomain>.aglyn.app/`; `null` when the site has no subdomain. */\n liveUrl: string | null\n published: Array<{ id: string; label: string; path: string }>\n drafts: Array<{ id: string; label: string; reason: string }>\n}\n\n/**\n * The record of an apply (AGL-2910): what became a new unpublished version,\n * and what waits in its editor for a person to save.\n */\nexport interface AiJobApplied {\n at: ITimestamp\n /** The member who applied. */\n by: string\n /** The new version opened for each resource, by resource id. */\n versions: Record<string, string>\n /** Resource ids whose proposed values wait in their editor, unsaved. */\n staged: string[]\n}\n\n/** The plan on the wire: every instant an ISO string. */\nexport interface AiJobPlanSummary extends AiBuildPlan {\n status: AiJobPlanStatus\n labels: Record<string, string>\n proposedAt: string | null\n confirmedAt: string | null\n confirmedBy: string | null\n key?: string\n reusedFrom?: string\n}\n\n/**\n * The wire form the console reads: every instant an ISO string, the lease\n * reduced to whether a runner holds the job. The brief and the outputs\n * travel as they are — the reader is a member of the org that wrote them.\n */\nexport interface AiJobSummary {\n id: string\n orgId: string\n hostId: string | null\n kind: AiJobKind\n status: AiJobStatus\n brief: string\n /**\n * The batch a door created this job as one of (AGL-2911), read off the\n * job's inputs; `null` for a job created on its own. The console groups a\n * run of jobs by it, which is the one thing it cannot do from a list whose\n * rows carry no inputs — and the only input the wire form carries, because\n * a batch id names nothing the member wrote.\n */\n batch: string | null\n steps: Array<{\n name: string\n status: AiJobStepStatus\n startedAt: string | null\n endedAt: string | null\n creditsSpent: number\n error: string | null\n }>\n outputs: AiJobOutput[]\n creditsReserved: number\n creditsSpent: number\n /** Credits given back for a failure on our side (AGL-3594); 0 when none. */\n refundedCredits?: number\n createdBy: string\n createdAt: string\n updatedAt: string\n error: string | null\n running: boolean\n plan: AiJobPlanSummary | null\n review: AiJobReview | null\n /** What a person applied from the outputs (AGL-2910); instants as ISO strings. */\n applied?: {\n at: string | null\n by: string\n versions: Record<string, string>\n staged: string[]\n } | null\n /** What a guided site start put live (AGL-3596); absent on every other job. */\n sitePublish?: AiJobSitePublish | null\n}\n"],"names":["AI_JOB_KINDS","AI_JOB_TERMINAL_STATUSES","AI_JOB_PLAN_STEP"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GA+DD,qEAAqE,GACrE,OAAO,MAAMA,eAAqC;IAChD;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;CACD,CAAA;AAoBD,OAAO,MAAMC,2BAAmD;IAC9D;IACA;IACA;CACD,CAAA;AAID,uFAAuF,GACvF,OAAO,MAAMC,mBAAmB,OAAM"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/ai/src/lib/model/ai-jobs.types.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { ITimestamp } from '@aglyn/shared-util-timestamp'\nimport type { AiEffort } from '../providers/contract'\nimport type { AiLoadEstimate } from '../runtime/ai-palette'\nimport type { AiBuildPlan } from './ai-build-plan'\n\n/**\n * AI generation jobs (AGL-2904).\n *\n * A job is one customer brief carried through one or more model steps by a\n * Firestore state machine, so that work longer than a request can survive\n * the request: the console route runs what it can inline, and the platform\n * job beat resumes whatever is left. The document is the whole state — no\n * process holds anything the next beat cannot read back.\n *\n * ── Outputs are drafts, never a publish ──────────────────────────────────\n *\n * Every output a job produces is a NEW draft or a new unpublished version of\n * an existing resource. A job never flips a version pointer, never registers\n * a route and never sends anything; a person opens the draft the job names\n * and publishes it through the door that already exists for that resource.\n * That is what lets a job run with no visitor, no session and no confirm\n * gate — the thing it writes cannot be seen by anyone but the workspace\n * until a member chooses otherwise.\n *\n * ── The lease ────────────────────────────────────────────────────────────\n *\n * A step runs under a lease: an owner id and an `until` instant. Two beats\n * fire a minute apart against a 120 s function timeout, and a console route\n * may still be running the first step when the first beat looks, so the\n * lease is what stops the same step being run — and metered — twice. A\n * claim is a transaction that refuses while another owner's lease is live;\n * an expired lease is simply claimable, which is also how a step abandoned\n * by a frozen process is recovered.\n */\n\n/**\n * What a job produces. `text` and `theme` have runners; every other kind is\n * registered and refuses with \"not available yet\" until its own issue lands,\n * so a kind's presence in the union says the job model accepts it, not that\n * a runner exists.\n */\nexport type AiJobKind =\n | 'page'\n | 'component'\n | 'layout'\n | 'template'\n | 'edit'\n | 'seo'\n | 'site'\n | 'email'\n | 'campaign'\n | 'form'\n | 'experiment'\n | 'insight'\n | 'products'\n | 'crm'\n | 'onboarding'\n | 'workflow'\n | 'logic'\n | 'text'\n | 'theme'\n | 'build'\n\n/** The union as a value, so a route can validate a body against it. */\nexport const AI_JOB_KINDS: readonly AiJobKind[] = [\n 'page',\n 'component',\n 'layout',\n 'template',\n 'edit',\n 'seo',\n 'site',\n 'email',\n 'campaign',\n 'form',\n 'experiment',\n 'insight',\n 'products',\n 'crm',\n 'onboarding',\n 'workflow',\n 'logic',\n 'text',\n 'theme',\n 'build',\n]\n\n/**\n * `queued` — waiting for a runner; `running` — a step holds the lease;\n * `needs_input` — the job stopped for something only the workspace can\n * change (credits, a cap, a switch), and the beat tries it again once that\n * may have changed; `needs_review` — the job stopped for a person's decision\n * (AGL-2935): its plan is ready to confirm, or an answer broke a building\n * rule on its re-ask. No timer can make that decision, so neither the beat\n * nor anything but that person resumes it. The last three are terminal.\n */\nexport type AiJobStatus =\n | 'queued'\n | 'running'\n | 'needs_input'\n | 'needs_review'\n | 'done'\n | 'failed'\n | 'canceled'\n\nexport const AI_JOB_TERMINAL_STATUSES: readonly AiJobStatus[] = [\n 'done',\n 'failed',\n 'canceled',\n]\n\nexport type AiJobStepStatus = 'pending' | 'running' | 'done' | 'failed'\n\n/** The step a planned kind runs first (AGL-2935): its plan, before anything is built. */\nexport const AI_JOB_PLAN_STEP = 'plan'\n\nexport interface AiJobStep {\n /** Stable within the job (`plan`, `draft`, `generate`), unique per job. */\n name: string\n status: AiJobStepStatus\n startedAt?: ITimestamp | null\n endedAt?: ITimestamp | null\n /** Credits this step has actually cost, at the plan's credit rate. */\n creditsSpent: number\n /** Customer-safe only; provider detail goes to the server log. */\n error?: string | null\n /**\n * How many times a runner has been handed this step. A retryable provider\n * failure hands the step back as `pending`; the count is what stops a\n * provider outage re-running a step forever.\n */\n attempts?: number\n /**\n * Passes of a step that works through a list (AGL-2910): each one a\n * recorded, metered exchange that asked to continue. Attempts count again\n * from zero after a pass; this count is what bounds the step.\n */\n passes?: number\n /**\n * What the step's model calls cost in tokens and time (AGL-2937), summed\n * over every run that reached the provider. Absent on a step none has.\n */\n tokens?: AiJobStepTokens\n /**\n * The ids the step writes its drafts under, by draft (AGL-3079): minted\n * when the job is created, so every run of the step names the same drafts.\n * Absent on a step that writes none; a step that records none names its\n * drafts by the job's own id.\n */\n draftIds?: Partial<Record<AiJobDraftSlot, string>>\n}\n\n/**\n * A draft a job's kind always writes (AGL-3079): a screen, layout, template,\n * form or component; an email design; a campaign; an automation.\n */\nexport type AiJobDraftSlot =\n | 'screen'\n | 'layout'\n | 'template'\n | 'form'\n | 'component'\n | 'email'\n | 'campaign'\n | 'workflow'\n\n/**\n * A step's measure (AGL-2937): the four token counts the meter prices, the\n * time spent in the runner, and the model and thinking effort of the last\n * run. The machine writes it beside `creditsSpent`, so what a kind of step\n * costs in tokens is read off the job rather than inferred from the month.\n */\nexport interface AiJobStepTokens {\n /** Prompt tokens sent uncached. */\n input: number\n /** Prompt tokens read from the prompt cache. */\n cachedRead: number\n /** Prompt tokens written to the prompt cache. */\n cacheWrite: number\n /** Tokens generated, thinking included. */\n output: number\n /** The model the last run was served by. */\n model: string | null\n /** The thinking effort the last run asked for; `null` when it named none. */\n effort: AiEffort | null\n /** Milliseconds spent in the runner, summed over runs. */\n latencyMs: number\n /** Runs that reached the provider. */\n runs: number\n /**\n * Why the step's latest runs stopped (AGL-3042), oldest first and the last\n * run last: each run's stop reason and the tokens it generated, so a pass\n * cut off at its ceiling reads off the job rather than out of the sums. At\n * most `AI_JOB_STEP_LAST_RUNS` are kept; absent on a step measured before.\n */\n lastRuns?: AiJobStepRunStop[]\n}\n\n/** One run of a step, by why it stopped (AGL-3042). */\nexport interface AiJobStepRunStop {\n /**\n * The stop reason of the run's last model call — `tool_use` or `end_turn`\n * for an answer, `max_tokens` for one cut off at its ceiling, `refusal` —\n * and `null` when the provider named none.\n */\n stopReason: string | null\n /** Tokens the run generated, over every model call it made. */\n output: number\n}\n\nexport type AiJobOutputResource =\n | 'screen'\n | 'reusableComponent'\n | 'layout'\n | 'template'\n | 'form'\n | 'emailScreen'\n | 'campaign'\n | 'product'\n | 'experiment'\n | 'workflow'\n | 'text'\n | 'theme'\n | 'seo'\n | 'insight'\n | 'crm'\n /** A draft another plugin wrote for a build (AGL-3616), named by `draftResource`. */\n | 'draft'\n | 'logic'\n | 'orgAutomation'\n\n/**\n * One thing a job wrote. Addressed by resource and id so the console can\n * build the \"open draft\" link without knowing what the runner did; `text`\n * has no document of its own, so its body rides on the output itself.\n *\n * A `theme` output is a proposal rather than a document (AGL-2938). A site's\n * theme is fields on its host document, and writing those fields is the save\n * the Theme section's editor performs, which a job never does. So the change\n * set rides on the output as `proposal`, and a person puts it in the editor\n * and saves it there, or does not.\n *\n * An `seo` output is a proposal rather than a document (AGL-2910): search\n * listing values for a page or a product, or a site audit's findings and\n * fixes. A screen's listing is served from the screen document itself, so a\n * job never writes it; the values ride on the output as `proposal`, a person\n * puts them in the editor and saves them there, and an audit's content fixes\n * become new versions only when a person applies them.\n *\n * A `crm` output is a proposal too (AGL-2917): a record's summary and next\n * step, an email draft, or an import's column matches. The CRM's own task\n * form, stage route, composer and import drawer are the writes, and a person\n * makes each of them, or does not.\n *\n * A `logic` output is a proposal too (AGL-3603): a site function or variable\n * the Functions & Variables editor opens unsaved. Saving it is the editor's\n * write, which a person makes, or does not.\n *\n * An `orgAutomation` output is a proposal too (AGL-3603): one of the\n * workspace's automations, which the Org automations editor opens unsaved and\n * switched off. `hostId` is `null`: it belongs to no one site.\n */\nexport interface AiJobOutput {\n resource: AiJobOutputResource\n id: string\n /** The unpublished version the job created, where the resource has versions. */\n versionId?: string | null\n /** `null` for an output that belongs to the org rather than one site. */\n hostId: string | null\n /**\n * The site's subdomain, which is what a console URL names a site by: the\n * `[host]` segment resolves by subdomain, so a link built from `hostId`\n * names no site the console can open.\n */\n hostSubdomain?: string | null\n label: string\n /** The body of a `text` output. Absent on every other resource. */\n text?: string\n /**\n * The change set of an output a person applies rather than opens — a\n * `theme` or `seo` proposal — in the shape its job kind's runner defines.\n */\n proposal?: Record<string, unknown>\n /**\n * What the person decides next about this output, in customer-safe words:\n * a routing the draft could not store, or part of the brief it could not\n * build. Absent when there is nothing to decide.\n */\n note?: string | null\n /**\n * What a first visit is estimated to transfer, as the doctrine measured\n * the generated document (AGL-2935) — the weight the proposal shows before\n * anything is applied. Absent where the output is not a page's document.\n */\n load?: AiLoadEstimate | null\n /**\n * For a `draft` output (AGL-3616): the resource whose owner wrote it, as\n * its writer is registered on the resource-draft seam.\n */\n draftResource?: string\n}\n\nexport interface AiJobLease {\n /** The process that holds the step: a route request id or a beat id. */\n owner: string\n until: ITimestamp\n}\n\n/** Why a job stopped for a person (AGL-2935). */\nexport type AiJobReviewReason =\n /** The plan step proposed a plan; generation waits for it to be confirmed. */\n | 'plan'\n /** An answer broke a building rule, and so did the answer to the re-ask. */\n | 'doctrine'\n /**\n * The site is at an allowance its plan sets for what the step writes, such\n * as its shared layouts or its templates (AGL-2909). Freeing one, or a plan\n * that holds more, is the member's decision; trying again runs the step\n * again.\n */\n | 'limit'\n\n/**\n * A building rule an answer broke, as the job keeps it: the number, the code,\n * the sentence, and where in the answer it was broken (AGL-3078).\n */\nexport interface AiJobRuleFinding {\n rule: number | null\n code: string\n /** Customer-safe. */\n message: string\n /** The nodes the finding names, by the ids the refused answer gave them. Absent when it names none. */\n nodeIds?: string[]\n /** The plan entries or answer fields it names, as `screens[0].sections[2]`. Absent when it names none. */\n paths?: string[]\n}\n\n/**\n * One node of the parts of a refused answer its findings name (AGL-3078), as\n * the review keeps it: the node's place, its element and the names of what it\n * sets, and never its copy. A Grid keeps the values of its layout props as\n * they were written, so a review can tell a shape the rules refuse from one\n * the model was asked to mend and did not.\n */\nexport interface AiJobReviewOutlineNode {\n /** The node's id, as the refused answer wrote it. */\n id: string\n /** How far below a node a finding names it sits: 0 for that node. */\n depth: number\n componentId: string\n /** The props it sets, by name only. */\n props: string[]\n /** The `sx` keys it sets, by name only; absent when it sets none. */\n sx?: string[]\n /** A Grid's layout props, `container`, `size`, `direction`, `spacing` and the rest, as written. */\n grid?: Record<string, string | number | boolean | null>\n /** Its children's element ids, in order. */\n children: string[]\n}\n\nexport interface AiJobReview {\n reason: AiJobReviewReason\n /** Customer-safe: what the person is asked to decide. */\n message: string\n /** The rules the last answer broke; empty for a plan. */\n findings: AiJobRuleFinding[]\n /**\n * The parts of the refused answer its findings name, each node with the\n * nodes below it (AGL-3078); absent when they name none. Kept with the job\n * for diagnosis, and shown to staff.\n */\n outline?: AiJobReviewOutlineNode[]\n /**\n * The checks' own sentence, where `message` was written for the member\n * instead (AGL-3594): rule numbers and all, for staff. Its presence is what\n * tells the drawer the findings are staff reading too.\n */\n detail?: string\n /**\n * Why trying again cannot work yet (AGL-3594) — the Free allowance left is\n * less than the step can cost — or absent when it can. The button is drawn\n * disabled with this beside it.\n */\n retryRefusal?: string\n}\n\nexport type AiJobPlanStatus = 'proposed' | 'confirmed'\n\n/** The plan a job builds from, as the job keeps it once its plan step proposed it. */\nexport interface AiJobPlan extends AiBuildPlan {\n status: AiJobPlanStatus\n /** Names for the inventory ids the plan references, read when it was made. */\n labels: Record<string, string>\n proposedAt: ITimestamp\n confirmedAt: ITimestamp | null\n /** The member who confirmed it. */\n confirmedBy: string | null\n /**\n * A digest of the whole request that produced this plan (AGL-2937): the\n * job's kind, site, brief and scalar inputs, the model that answered, and\n * the prompt as it was rendered — the site inventory included. A later job\n * whose request hashes the same reuses this plan rather than paying for the\n * same answer again. A hash of the request, never of the answer, and no\n * part of the brief is recoverable from it.\n */\n key?: string\n /** The job this plan was reused from, when it was not asked for again. */\n reusedFrom?: string\n}\n\n/**\n * Where one item of a `build` job stands (AGL-3616). A build settles item by\n * item: a failed item gives back its own spend and the rest of the plan still\n * runs, so the job keeps one row per item, written only by the machine's\n * `recordStep` — in the same transaction as the spend it accounts for — and\n * by the resume door's retry.\n */\nexport type AiJobItemStatus = 'pending' | 'running' | 'succeeded' | 'degraded' | 'failed' | 'skipped'\n\n/** Why an item failed: a give-back reason when it was ours, else the model's refusal or a review. */\nexport type AiJobItemFailureReason =\n | 'plan-refused'\n | 'doctrine-refused'\n | 'provider'\n | 'timeout'\n | 'step-failure'\n | 'unavailable'\n | 'refused'\n | 'review'\n\nexport interface AiJobItemFailure {\n /** Whether the failure was on our side: only then is the item's spend given back. */\n ours: boolean\n reason: AiJobItemFailureReason\n /** Customer-safe. */\n message: string\n}\n\nexport interface AiJobItemLedger {\n /** The unit's slot within the plan: `c0` a creation, `p0` a page, `i0` an item. */\n slot: string\n /** The capability operation that builds it: `page`, `form`, or an owner's op. */\n op: string\n /** What a person reads: the page's title, the creation's or item's name. */\n label: string\n status: AiJobItemStatus\n /** Bumped by Try again; the refund key names it, so each attempt gives back once. */\n attempt: number\n /** What this item's passes cost, every attempt. */\n creditsSpent: number\n /** What this attempt's passes cost so far: what a failure of this attempt gives back. */\n attemptCredits?: number\n /** What was given back for this item's failures. */\n creditsRefunded: number\n /** The key the latest give-back for this item was made under. */\n refundKey?: string\n failure?: AiJobItemFailure | null\n /** The ids of the outputs this item produced. */\n outputs: string[]\n /** The slots whose failure changed how this item was built. */\n degradedBy?: string[]\n /** Customer-safe: what the person should know about this item. */\n note?: string | null\n}\n\n/** Whether a build's own planning was charged or given back (AGL-3616). */\nexport interface AiJobOrchestration {\n /** What the plan step spent. */\n creditsSpent: number\n /** `charged` once anything was delivered; `refunded` when nothing was. */\n settled: 'pending' | 'charged' | 'refunded'\n}\n\nexport interface AiJob {\n $id: string\n orgId: string\n hostId?: string | null\n kind: AiJobKind\n status: AiJobStatus\n /** The customer's brief, verbatim. Expires with the document. */\n brief: string\n /** Kind-specific inputs the runner reads (a screen id to edit, a tone). */\n inputs: Record<string, unknown>\n /**\n * The model the creator picked for the job's steps (AGL-2942), or `null`\n * for Auto. Each step honors it only where the plan and the allotment\n * allowlists allow it, and runs on the routing table otherwise.\n */\n model?: string | null\n steps: AiJobStep[]\n outputs: AiJobOutput[]\n /**\n * The nominal credit figure held against the job while steps are\n * outstanding. The meter's real bound is the per-step message reservation\n * and the org's monthly ceiling; this is the number the console shows so\n * a running job is not read as free.\n */\n creditsReserved: number\n creditsSpent: number\n /**\n * Credits the job gave back because it failed on our side (AGL-3594),\n * summed over its give-backs; absent when it gave none. `creditsSpent`\n * stays what ran, so what the job cost is the one less the other.\n */\n refundedCredits?: number\n /** Why the latest give-back was made (`AiJobRefundReason`). */\n refundReason?: string\n /** How many give-backs the job has had: the next one's key. */\n refunds?: number\n createdBy: string\n createdAt: ITimestamp\n updatedAt: ITimestamp\n /** TTL — the brief is verbatim customer text and expires like an exchange. */\n expiresAt: ITimestamp\n /** Customer-safe only. */\n error?: string | null\n lease?: AiJobLease | null\n /** The plan the job builds from, once its plan step proposed one. */\n plan?: AiJobPlan | null\n /** What the person is asked to decide while the job is `needs_review`. */\n review?: AiJobReview | null\n /**\n * What a person applied from the job's outputs (AGL-2910). Written by the\n * door that applied them, never by a step runner, and absent until then.\n */\n applied?: AiJobApplied | null\n /**\n * What a guided site start put live when it finished (AGL-3596): written\n * once by the site step's last pass, never by a person. Absent on every\n * other job, which leaves its pages as drafts.\n */\n sitePublish?: AiJobSitePublish | null\n /** A `build` job's items, one row each (AGL-3616); absent on every other kind. */\n items?: AiJobItemLedger[] | null\n /** A `build` job's planning spend and how it settled (AGL-3616). */\n orchestration?: AiJobOrchestration | null\n}\n\n/**\n * A guided site start's publish (AGL-3596): the pages that went live, with\n * the address each answers, and the pages that stayed drafts, each with the\n * plain sentence for why. A page that stayed a draft never fails the job.\n */\nexport interface AiJobSitePublish {\n /** The site's live address, `https://<subdomain>.aglyn.app/`; `null` when the site has no subdomain. */\n liveUrl: string | null\n published: Array<{ id: string; label: string; path: string }>\n drafts: Array<{ id: string; label: string; reason: string }>\n}\n\n/**\n * The record of an apply (AGL-2910): what became a new unpublished version,\n * and what waits in its editor for a person to save.\n */\nexport interface AiJobApplied {\n at: ITimestamp\n /** The member who applied. */\n by: string\n /** The new version opened for each resource, by resource id. */\n versions: Record<string, string>\n /** Resource ids whose proposed values wait in their editor, unsaved. */\n staged: string[]\n}\n\n/** The plan on the wire: every instant an ISO string. */\nexport interface AiJobPlanSummary extends AiBuildPlan {\n status: AiJobPlanStatus\n labels: Record<string, string>\n proposedAt: string | null\n confirmedAt: string | null\n confirmedBy: string | null\n key?: string\n reusedFrom?: string\n}\n\n/**\n * The wire form the console reads: every instant an ISO string, the lease\n * reduced to whether a runner holds the job. The brief and the outputs\n * travel as they are — the reader is a member of the org that wrote them.\n */\nexport interface AiJobSummary {\n id: string\n orgId: string\n hostId: string | null\n kind: AiJobKind\n status: AiJobStatus\n brief: string\n /**\n * The batch a door created this job as one of (AGL-2911), read off the\n * job's inputs; `null` for a job created on its own. The console groups a\n * run of jobs by it, which is the one thing it cannot do from a list whose\n * rows carry no inputs — and the only input the wire form carries, because\n * a batch id names nothing the member wrote.\n */\n batch: string | null\n steps: Array<{\n name: string\n status: AiJobStepStatus\n startedAt: string | null\n endedAt: string | null\n creditsSpent: number\n error: string | null\n }>\n outputs: AiJobOutput[]\n creditsReserved: number\n creditsSpent: number\n /** Credits given back for a failure on our side (AGL-3594); 0 when none. */\n refundedCredits?: number\n createdBy: string\n createdAt: string\n updatedAt: string\n error: string | null\n running: boolean\n plan: AiJobPlanSummary | null\n review: AiJobReview | null\n /** What a person applied from the outputs (AGL-2910); instants as ISO strings. */\n applied?: {\n at: string | null\n by: string\n versions: Record<string, string>\n staged: string[]\n } | null\n /** What a guided site start put live (AGL-3596); absent on every other job. */\n sitePublish?: AiJobSitePublish | null\n /**\n * A site job's answers (AGL-3596): the guided start's questions as the person\n * answered them, so a failed start's Try again reopens them filled in. The\n * scalar site inputs only, never anything else a job's inputs carry; absent\n * on every other kind.\n */\n siteInputs?: Record<string, unknown> | null\n /** A `build` job's items (AGL-3616); absent on every other job. */\n items?: AiJobItemLedger[]\n /**\n * Whether a build's request asked to publish (AGL-3616), so its plan card\n * offers the box that confirms it. Absent on every other job.\n */\n publishAsked?: boolean\n /** A `build` job's planning spend and how it settled (AGL-3616). */\n orchestration?: AiJobOrchestration\n}\n"],"names":["AI_JOB_KINDS","AI_JOB_TERMINAL_STATUSES","AI_JOB_PLAN_STEP"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAiED,qEAAqE,GACrE,OAAO,MAAMA,eAAqC;IAChD;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;CACD,CAAA;AAoBD,OAAO,MAAMC,2BAAmD;IAC9D;IACA;IACA;CACD,CAAA;AAID,uFAAuF,GACvF,OAAO,MAAMC,mBAAmB,OAAM"}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Aglyn LLC
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
import { type FunctionComparator, type FunctionValueType, type HostFunction } from '@aglyn/aglyn/app-utils/functions';
|
|
18
|
+
import { type HostVariable, type HostVariableType } from '@aglyn/aglyn/app-utils/variables';
|
|
19
|
+
import type { AiDoctrineViolation } from '../runtime/ai-doctrine-validators';
|
|
20
|
+
/**
|
|
21
|
+
* A `logic` job (AGL-3603): a site's Functions & Variables, by AI.
|
|
22
|
+
*
|
|
23
|
+
* - `function` proposes a function — parameters, locals, the numbered
|
|
24
|
+
* if/then/otherwise operations and the value it returns — from a
|
|
25
|
+
* description, or, naming a saved function, a changed or fixed copy of
|
|
26
|
+
* it. Every expression is held to the evaluator's own grammar
|
|
27
|
+
* (`expressionSyntaxError`), every name it reads to the function's own
|
|
28
|
+
* names and the site's variables, and the whole definition is run once
|
|
29
|
+
* with each parameter at its starting value before anyone sees it.
|
|
30
|
+
* - `variable` proposes one site variable: a name, a type and a value in
|
|
31
|
+
* that type's stored form.
|
|
32
|
+
* - `explain` reads a saved function and answers in plain words what it
|
|
33
|
+
* computes, and anything in it worth checking.
|
|
34
|
+
*
|
|
35
|
+
* Nothing is written: a proposal rides on the job's output, and the logic
|
|
36
|
+
* editor is where a person saves it, or does not.
|
|
37
|
+
*/
|
|
38
|
+
export declare const AI_LOGIC_JOB_MODES: readonly ["function", "variable", "explain"];
|
|
39
|
+
export type AiLogicJobMode = (typeof AI_LOGIC_JOB_MODES)[number];
|
|
40
|
+
export type AiLogicJobInputs = {
|
|
41
|
+
mode: 'function';
|
|
42
|
+
functionId: string | null;
|
|
43
|
+
} | {
|
|
44
|
+
mode: 'variable';
|
|
45
|
+
} | {
|
|
46
|
+
mode: 'explain';
|
|
47
|
+
functionId: string;
|
|
48
|
+
};
|
|
49
|
+
export declare const AI_LOGIC_PICK_FUNCTION_COPY = "Pick the function to explain";
|
|
50
|
+
/** A job's inputs read into its mode, or the sentence that says what is wrong with them. */
|
|
51
|
+
export declare function parseAiLogicJobInputs(inputs: Readonly<Record<string, unknown>> | null | undefined): AiLogicJobInputs | string;
|
|
52
|
+
export declare const AI_LOGIC_MAX_PARAMETERS = 12;
|
|
53
|
+
export declare const AI_LOGIC_MAX_LOCALS = 20;
|
|
54
|
+
export declare const AI_LOGIC_MAX_OPERATIONS = 24;
|
|
55
|
+
export declare const AI_LOGIC_MAX_SETS = 12;
|
|
56
|
+
export declare const AI_LOGIC_EXPRESSION_MAX_CHARS = 400;
|
|
57
|
+
export declare const AI_LOGIC_LABEL_MAX_CHARS = 80;
|
|
58
|
+
export declare const AI_LOGIC_VARIABLE_VALUE_MAX_CHARS = 2000;
|
|
59
|
+
export declare const AI_LOGIC_VALUE_TYPES: readonly FunctionValueType[];
|
|
60
|
+
export declare const AI_LOGIC_COMPARATORS: readonly FunctionComparator[];
|
|
61
|
+
/** The variable types a proposal may use: every type the Variables editor offers. */
|
|
62
|
+
export declare const AI_LOGIC_VARIABLE_TYPES: readonly HostVariableType[];
|
|
63
|
+
/** A site variable as a proposal is checked against: its name, type and value. */
|
|
64
|
+
export type AiLogicSiteVariable = Pick<HostVariable, 'name' | 'type' | 'value'>;
|
|
65
|
+
/** What a proposal's names are checked against: the site's variables and functions. */
|
|
66
|
+
export interface AiLogicContext {
|
|
67
|
+
variables: readonly AiLogicSiteVariable[];
|
|
68
|
+
/** The site's function names, which a new function's name must not repeat. */
|
|
69
|
+
functions: readonly string[];
|
|
70
|
+
/** The saved function a change starts from; its own name is free to keep. */
|
|
71
|
+
editing?: string | null;
|
|
72
|
+
}
|
|
73
|
+
export interface AiLogicCheckResult<T> {
|
|
74
|
+
value: T | null;
|
|
75
|
+
violations: AiDoctrineViolation[];
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* A `submit_function` answer read into a definition the function editor
|
|
79
|
+
* opens, or the violations a re-ask names. Only what the evaluator can run
|
|
80
|
+
* is kept: an expression it cannot parse, a name it cannot find, a SET on a
|
|
81
|
+
* site variable, or a run that fails on starting values is refused.
|
|
82
|
+
*/
|
|
83
|
+
export declare function checkAiLogicFunction(answer: Record<string, unknown>, context: AiLogicContext): AiLogicCheckResult<HostFunction>;
|
|
84
|
+
/** A `submit_variable` answer read into the variable the Variables editor opens. */
|
|
85
|
+
export declare function checkAiLogicVariable(answer: Record<string, unknown>, context: Pick<AiLogicContext, 'variables'>): AiLogicCheckResult<AiLogicSiteVariable>;
|
|
86
|
+
/** The output resource a logic proposal rides on. */
|
|
87
|
+
export declare const AI_LOGIC_RESOURCE = "logic";
|
|
88
|
+
/** A logic output's proposal: a function to open in the editor, or a variable. */
|
|
89
|
+
export type AiLogicProposal = {
|
|
90
|
+
kind: 'function';
|
|
91
|
+
functionId: string | null;
|
|
92
|
+
definition: HostFunction;
|
|
93
|
+
} | {
|
|
94
|
+
kind: 'variable';
|
|
95
|
+
variable: AiLogicSiteVariable;
|
|
96
|
+
};
|
|
97
|
+
/**
|
|
98
|
+
* A proposal read back from a job's output, in the browser, before the
|
|
99
|
+
* editor is handed it; `null` for anything that is not one. The server held
|
|
100
|
+
* the definition to the grammar; this only refuses a shape that is not one.
|
|
101
|
+
*/
|
|
102
|
+
export declare function readAiLogicProposal(value: unknown): AiLogicProposal | null;
|
|
103
|
+
export declare const AI_LOGIC_NO_SITE_COPY = "This logic job names a site this workspace does not have.";
|
|
104
|
+
export declare const AI_LOGIC_UNAVAILABLE_COPY = "Turn on Logic for this site before starting the job.";
|
|
105
|
+
export declare const AI_LOGIC_GONE_COPY = "That function no longer exists.";
|
|
106
|
+
export declare const AI_LOGIC_NO_FUNCTION_COPY = "The AI could not write a function the site can run from this description. Try describing what goes in, and what should come out.";
|
|
107
|
+
export declare const AI_LOGIC_NO_VARIABLE_COPY = "The AI could not write a variable from this description. Try naming what it holds, and its value.";
|
|
108
|
+
export declare const AI_LOGIC_NO_EXPLANATION_COPY = "The AI could not explain this function. Try again.";
|