@aglyn/plugins-ai 1.0.0-beta.218 → 1.0.0-beta.219
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 +2 -2
- package/package.json +17 -17
- package/src/index.d.ts +1 -0
- package/src/index.js.map +1 -1
- package/src/lib/activity/ai-activity-actions.js +8 -1
- package/src/lib/activity/ai-activity-actions.js.map +1 -1
- package/src/lib/components/ai-assist-provider.component.js +2 -2
- package/src/lib/components/ai-assist-provider.component.js.map +1 -1
- package/src/lib/components/ai-brief-dialog.component.js +3 -3
- package/src/lib/components/ai-brief-dialog.component.js.map +1 -1
- package/src/lib/components/ai-experiment-cards.component.js +1 -1
- package/src/lib/components/ai-experiment-cards.component.js.map +1 -1
- package/src/lib/components/ai-job-plan.component.d.ts +8 -0
- package/src/lib/components/ai-job-plan.component.js +21 -4
- package/src/lib/components/ai-job-plan.component.js.map +1 -1
- package/src/lib/components/ai-permissions-on-host.component.d.ts +12 -2
- package/src/lib/components/ai-permissions-on-host.component.js +12 -3
- package/src/lib/components/ai-permissions-on-host.component.js.map +1 -1
- package/src/lib/components/ai-product-copy-card.component.d.ts +1 -1
- package/src/lib/components/ai-product-copy-card.component.js.map +1 -1
- package/src/lib/components/ai-product-import-option.component.d.ts +1 -1
- package/src/lib/components/ai-product-import-option.component.js.map +1 -1
- package/src/lib/components/ai-product-zones.d.ts +124 -0
- package/src/lib/components/ai-product-zones.js +32 -0
- package/src/lib/components/ai-product-zones.js.map +1 -0
- package/src/lib/components/ai-products-hub-card.component.d.ts +1 -1
- package/src/lib/components/ai-products-hub-card.component.js.map +1 -1
- package/src/lib/components/ai-products-proposals.component.d.ts +1 -1
- package/src/lib/components/ai-products-proposals.component.js.map +1 -1
- package/src/lib/components/ai-seo-audit-card.component.js +35 -92
- package/src/lib/components/ai-seo-audit-card.component.js.map +1 -1
- package/src/lib/components/ai-seo-fields-card.component.js.map +1 -1
- package/src/lib/components/ai-theme-proposal-card.component.js.map +1 -1
- package/src/lib/components/assist-jobs-drawer.component.js +21 -15
- package/src/lib/components/assist-jobs-drawer.component.js.map +1 -1
- package/src/lib/components/assist-panel.component.js +2 -2
- package/src/lib/components/assist-panel.component.js.map +1 -1
- package/src/lib/components/assist-signals-page.component.js +2 -2
- package/src/lib/components/assist-signals-page.component.js.map +1 -1
- package/src/lib/jobs/ai-email-bindings.d.ts +28 -21
- package/src/lib/jobs/ai-email-bindings.js +75 -42
- package/src/lib/jobs/ai-email-bindings.js.map +1 -1
- package/src/lib/jobs/ai-job-campaign-step.d.ts +0 -2
- package/src/lib/jobs/ai-job-campaign-step.js +5 -10
- package/src/lib/jobs/ai-job-campaign-step.js.map +1 -1
- package/src/lib/jobs/ai-job-component-step.js +9 -3
- package/src/lib/jobs/ai-job-component-step.js.map +1 -1
- package/src/lib/jobs/ai-job-drafts.js +1 -1
- package/src/lib/jobs/ai-job-drafts.js.map +1 -1
- package/src/lib/jobs/ai-job-email-step.d.ts +0 -2
- package/src/lib/jobs/ai-job-email-step.js +1 -3
- package/src/lib/jobs/ai-job-email-step.js.map +1 -1
- package/src/lib/jobs/ai-job-experiment-step.d.ts +1 -1
- package/src/lib/jobs/ai-job-experiment-step.js +1 -1
- package/src/lib/jobs/ai-job-experiment-step.js.map +1 -1
- package/src/lib/jobs/ai-job-generation.d.ts +1 -1
- package/src/lib/jobs/ai-job-generation.js +10 -2
- package/src/lib/jobs/ai-job-generation.js.map +1 -1
- package/src/lib/jobs/ai-job-layout-step.js +1 -1
- package/src/lib/jobs/ai-job-layout-step.js.map +1 -1
- package/src/lib/jobs/ai-job-page-sections.d.ts +4 -2
- package/src/lib/jobs/ai-job-page-sections.js +7 -4
- package/src/lib/jobs/ai-job-page-sections.js.map +1 -1
- package/src/lib/jobs/ai-job-page-step.js +7 -2
- package/src/lib/jobs/ai-job-page-step.js.map +1 -1
- package/src/lib/jobs/ai-job-plan-conformance.js +33 -0
- package/src/lib/jobs/ai-job-plan-conformance.js.map +1 -1
- package/src/lib/jobs/ai-job-plan-step.d.ts +3 -0
- package/src/lib/jobs/ai-job-plan-step.js +29 -17
- package/src/lib/jobs/ai-job-plan-step.js.map +1 -1
- package/src/lib/jobs/ai-job-plugin-drafts.d.ts +14 -6
- package/src/lib/jobs/ai-job-plugin-drafts.js +12 -4
- package/src/lib/jobs/ai-job-plugin-drafts.js.map +1 -1
- package/src/lib/jobs/ai-job-products-step.d.ts +7 -0
- package/src/lib/jobs/ai-job-products-step.js +54 -32
- package/src/lib/jobs/ai-job-products-step.js.map +1 -1
- package/src/lib/jobs/ai-job-seo-step.d.ts +3 -24
- package/src/lib/jobs/ai-job-seo-step.js +35 -108
- package/src/lib/jobs/ai-job-seo-step.js.map +1 -1
- package/src/lib/jobs/ai-job-template-step.js +1 -0
- package/src/lib/jobs/ai-job-template-step.js.map +1 -1
- package/src/lib/jobs/ai-job-theme-step.d.ts +1 -1
- package/src/lib/jobs/ai-job-theme-step.js +1 -1
- package/src/lib/jobs/ai-job-theme-step.js.map +1 -1
- package/src/lib/jobs/ai-job-workflow-step.js +17 -9
- package/src/lib/jobs/ai-job-workflow-step.js.map +1 -1
- package/src/lib/jobs/ai-workflow-records.d.ts +19 -11
- package/src/lib/jobs/ai-workflow-records.js +60 -27
- package/src/lib/jobs/ai-workflow-records.js.map +1 -1
- package/src/lib/model/ai-allotments.d.ts +11 -3
- package/src/lib/model/ai-allotments.js +21 -4
- package/src/lib/model/ai-allotments.js.map +1 -1
- package/src/lib/model/ai-automation-outline.d.ts +21 -2
- package/src/lib/model/ai-automation-outline.js.map +1 -1
- package/src/lib/model/ai-build-plan.d.ts +57 -0
- package/src/lib/model/ai-build-plan.js +116 -7
- package/src/lib/model/ai-build-plan.js.map +1 -1
- package/src/lib/model/ai-seo.d.ts +11 -51
- package/src/lib/model/ai-seo.js +0 -17
- package/src/lib/model/ai-seo.js.map +1 -1
- package/src/lib/model/ai-site-inventory.js +1 -1
- package/src/lib/model/ai-site-inventory.js.map +1 -1
- package/src/lib/model/ai-template-subjects.js +2 -2
- package/src/lib/model/ai-template-subjects.js.map +1 -1
- package/src/lib/model/ai-theme-proposal.d.ts +1 -1
- package/src/lib/model/ai-theme-proposal.js +1 -1
- package/src/lib/model/ai-theme-proposal.js.map +1 -1
- package/src/lib/model/ai-workflow-job.d.ts +1 -3
- package/src/lib/model/ai-workflow-job.js +1 -2
- package/src/lib/model/ai-workflow-job.js.map +1 -1
- package/src/lib/plan-entitlements.d.ts +149 -0
- package/src/lib/plan-entitlements.js +168 -0
- package/src/lib/plan-entitlements.js.map +1 -0
- package/src/lib/plugin.js +1 -1
- package/src/lib/plugin.js.map +1 -1
- package/src/lib/runtime/ai-doctrine-validators.d.ts +25 -4
- package/src/lib/runtime/ai-doctrine-validators.js +178 -21
- package/src/lib/runtime/ai-doctrine-validators.js.map +1 -1
- package/src/lib/runtime/ai-doctrine.js +5 -5
- package/src/lib/runtime/ai-doctrine.js.map +1 -1
- package/src/lib/runtime/ai-eval-live.js +29 -14
- package/src/lib/runtime/ai-eval-live.js.map +1 -1
- package/src/lib/runtime/ai-eval.d.ts +8 -1
- package/src/lib/runtime/ai-eval.js +29 -2
- package/src/lib/runtime/ai-eval.js.map +1 -1
- package/src/lib/runtime/ai-node-tree.js +3 -3
- package/src/lib/runtime/ai-node-tree.js.map +1 -1
- package/src/lib/runtime/ai-palette.d.ts +6 -0
- package/src/lib/runtime/ai-palette.generated.js +15 -12
- package/src/lib/runtime/ai-palette.generated.js.map +1 -1
- package/src/lib/runtime/ai-palette.js +7 -1
- package/src/lib/runtime/ai-palette.js.map +1 -1
- package/src/lib/runtime/seo-audit.d.ts +13 -63
- package/src/lib/runtime/seo-audit.js +22 -207
- package/src/lib/runtime/seo-audit.js.map +1 -1
- package/src/lib/runtime/site-inventory.js +1 -1
- package/src/lib/runtime/site-inventory.js.map +1 -1
- package/src/lib/server/ai-assist-prompts.js +3 -3
- package/src/lib/server/ai-assist-prompts.js.map +1 -1
- package/src/lib/server/assist-chat.js +11 -10
- package/src/lib/server/assist-chat.js.map +1 -1
- package/src/lib/server/assist-view-context.js +23 -23
- package/src/lib/server/assist-view-context.js.map +1 -1
- package/src/lib/server.d.ts +1 -0
- package/src/lib/server.js.map +1 -1
- package/src/lib/testing/stand-in-automation-index.d.ts +20 -0
- package/src/lib/testing/stand-in-automation-index.js +102 -0
- package/src/lib/testing/stand-in-automation-index.js.map +1 -0
- package/src/lib/testing/stand-in-list-send-time.d.ts +4 -0
- package/src/lib/testing/stand-in-list-send-time.js +77 -0
- package/src/lib/testing/stand-in-list-send-time.js.map +1 -0
- package/src/lib/testing/stand-in-pipeline-index.d.ts +32 -0
- package/src/lib/testing/stand-in-pipeline-index.js +59 -0
- package/src/lib/testing/stand-in-pipeline-index.js.map +1 -0
- package/src/lib/testing/stand-in-product-index.d.ts +20 -0
- package/src/lib/testing/stand-in-product-index.js +105 -0
- package/src/lib/testing/stand-in-product-index.js.map +1 -0
- package/src/lib/tools/ai-component-tool.js +2 -2
- package/src/lib/tools/ai-component-tool.js.map +1 -1
- package/src/lib/tools/ai-duplicate-resource-tool.js +1 -1
- package/src/lib/tools/ai-duplicate-resource-tool.js.map +1 -1
- package/src/lib/tools/ai-seo-tool.d.ts +6 -18
- package/src/lib/tools/ai-seo-tool.js +7 -38
- package/src/lib/tools/ai-seo-tool.js.map +1 -1
- package/src/lib/tools/ai-workflow-tool.d.ts +1 -1
- package/src/lib/tools/ai-workflow-tool.js +1 -1
- package/src/lib/tools/ai-workflow-tool.js.map +1 -1
- package/src/lib/usage/ai-allotment-alerts.js +8 -1
- package/src/lib/usage/ai-allotment-alerts.js.map +1 -1
- package/src/lib/usage/assist-free-taste.js +2 -1
- package/src/lib/usage/assist-free-taste.js.map +1 -1
- package/src/lib/usage-axes.d.ts +39 -0
- package/src/lib/usage-axes.js +70 -0
- package/src/lib/usage-axes.js.map +1 -0
- package/src/lib/runtime/seo-page-facts.d.ts +0 -61
- package/src/lib/runtime/seo-page-facts.js +0 -150
- package/src/lib/runtime/seo-page-facts.js.map +0 -1
package/README.md
CHANGED
|
@@ -16,8 +16,8 @@ Peer dependencies: `react`, `next`, `@mui/material`, `@mui/x-data-grid`, `fireba
|
|
|
16
16
|
|
|
17
17
|
**Console** (`registerAiConsole`, the `console` and `staff` registrar in `plugins.config.json`). The plugin adds no nav item. Everything is mounted through zones the console shell and other plugins host, so no console page imports it:
|
|
18
18
|
|
|
19
|
-
- The assistant dock (`
|
|
20
|
-
- "Describe it" entry points and cards on
|
|
19
|
+
- The assistant, drawn in the console dock (`consoleDock`) and a provider the shell mounts around every console page for the Besigner copy assistant, with controls in the `besignerToolbar` and `besignerInspector` slots.
|
|
20
|
+
- "Describe it" entry points and cards on a site's pages list and its components, layouts, templates, forms, theme, SEO and automations pages (`hostScreens`, `hostComponents`, `hostLayouts`, `hostTemplates`, `hostForms`, `hostTheme`, `hostSeo`, `seoFields`, `hostAutomations`, `automationEditor`, `automationRun`, `hostFirstRun`, `orgSites`).
|
|
21
21
|
- Cards in zones other plugins host: product copy, import and the products hub (`productEditor`, `productImport`, `productsHub`), record insights, email drafts and import column matching (`recordInsights`, `recordEmail`, `importMapping`), and A/B test variants and results (`experimentVariants`, `experimentResult`).
|
|
22
22
|
- Usage and access: credit and usage cards on billing (`orgBillingUsage`), per-member cards and columns (`orgMember`, `orgMembersListColumn`, `hostMembers`), and staff cards, columns and one staff page (`staffOrg`, `staffUser`, `staffOrgsListColumn`, `staffOrgUsageColumn`).
|
|
23
23
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aglyn/plugins-ai",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.219",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"homepage": "https://aglyn.com",
|
|
6
6
|
"repository": {
|
|
@@ -25,22 +25,22 @@
|
|
|
25
25
|
"./package.json": "./package.json"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@aglyn/aglyn": "1.0.0-beta.
|
|
29
|
-
"@aglyn/shared-data-enums": "1.0.0-beta.
|
|
30
|
-
"@aglyn/shared-data-mdi": "1.0.0-beta.
|
|
31
|
-
"@aglyn/shared-data-types": "1.0.0-beta.
|
|
32
|
-
"@aglyn/shared-ui-email-campaigns": "1.0.0-beta.
|
|
33
|
-
"@aglyn/shared-ui-jsx": "1.0.0-beta.
|
|
34
|
-
"@aglyn/shared-ui-snackstack": "1.0.0-beta.
|
|
35
|
-
"@aglyn/shared-ui-theme": "1.0.0-beta.
|
|
36
|
-
"@aglyn/shared-util-email": "1.0.0-beta.
|
|
37
|
-
"@aglyn/shared-util-errors": "1.0.0-beta.
|
|
38
|
-
"@aglyn/shared-util-http": "1.0.0-beta.
|
|
39
|
-
"@aglyn/shared-util-timestamp": "1.0.0-beta.
|
|
40
|
-
"@aglyn/shared-util-tools": "1.0.0-beta.
|
|
41
|
-
"@aglyn/tenant-data-admin": "1.0.0-beta.
|
|
42
|
-
"@aglyn/tenant-feature-instance": "1.0.0-beta.
|
|
43
|
-
"@aglyn/tenant-runtime": "1.0.0-beta.
|
|
28
|
+
"@aglyn/aglyn": "1.0.0-beta.219",
|
|
29
|
+
"@aglyn/shared-data-enums": "1.0.0-beta.219",
|
|
30
|
+
"@aglyn/shared-data-mdi": "1.0.0-beta.219",
|
|
31
|
+
"@aglyn/shared-data-types": "1.0.0-beta.219",
|
|
32
|
+
"@aglyn/shared-ui-email-campaigns": "1.0.0-beta.219",
|
|
33
|
+
"@aglyn/shared-ui-jsx": "1.0.0-beta.219",
|
|
34
|
+
"@aglyn/shared-ui-snackstack": "1.0.0-beta.219",
|
|
35
|
+
"@aglyn/shared-ui-theme": "1.0.0-beta.219",
|
|
36
|
+
"@aglyn/shared-util-email": "1.0.0-beta.219",
|
|
37
|
+
"@aglyn/shared-util-errors": "1.0.0-beta.219",
|
|
38
|
+
"@aglyn/shared-util-http": "1.0.0-beta.219",
|
|
39
|
+
"@aglyn/shared-util-timestamp": "1.0.0-beta.219",
|
|
40
|
+
"@aglyn/shared-util-tools": "1.0.0-beta.219",
|
|
41
|
+
"@aglyn/tenant-data-admin": "1.0.0-beta.219",
|
|
42
|
+
"@aglyn/tenant-feature-instance": "1.0.0-beta.219",
|
|
43
|
+
"@aglyn/tenant-runtime": "1.0.0-beta.219",
|
|
44
44
|
"@swc/helpers": "0.5.23"
|
|
45
45
|
},
|
|
46
46
|
"peerDependencies": {
|
package/src/index.d.ts
CHANGED
|
@@ -19,3 +19,4 @@ export * from './lib/plugin';
|
|
|
19
19
|
export * from './lib/plugin-config';
|
|
20
20
|
export * from './lib/providers/catalog';
|
|
21
21
|
export { registerAiDeclarations, AI_PLUGIN_ENTITLEMENTS } from './lib/declarations';
|
|
22
|
+
export type { aiPlanEntitlements } from './lib/plan-entitlements';
|
package/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../libs/plugins/ai/src/index.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\nexport * from './lib/constants'\nexport * from './lib/plugin'\nexport * from './lib/plugin-config'\nexport * from './lib/providers/catalog'\nexport { registerAiDeclarations, AI_PLUGIN_ENTITLEMENTS } from './lib/declarations'\n"],"names":["registerAiDeclarations","AI_PLUGIN_ENTITLEMENTS"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED,cAAc,qBAAiB;AAC/B,cAAc,kBAAc;AAC5B,cAAc,yBAAqB;AACnC,cAAc,6BAAyB;AACvC,SAASA,sBAAsB,EAAEC,sBAAsB,QAAQ,wBAAoB"}
|
|
1
|
+
{"version":3,"sources":["../../../../../libs/plugins/ai/src/index.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\nexport * from './lib/constants'\nexport * from './lib/plugin'\nexport * from './lib/plugin-config'\nexport * from './lib/providers/catalog'\nexport { registerAiDeclarations, AI_PLUGIN_ENTITLEMENTS } from './lib/declarations'\n// Type-only (AGL-3080): the plugin's entitlement keys are declared by module\n// augmentation in this module, so every program that loads the package\n// type-checks them. The figures reach core through the manifest generator.\nexport type { aiPlanEntitlements } from './lib/plan-entitlements'\n"],"names":["registerAiDeclarations","AI_PLUGIN_ENTITLEMENTS"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED,cAAc,qBAAiB;AAC/B,cAAc,kBAAc;AAC5B,cAAc,yBAAqB;AACnC,cAAc,6BAAyB;AACvC,SAASA,sBAAsB,EAAEC,sBAAsB,QAAQ,wBAAoB"}
|
|
@@ -191,7 +191,14 @@ export function aiOutputTargetType(resource) {
|
|
|
191
191
|
key,
|
|
192
192
|
label: AI_ACTIVITY_ACTION_LABELS[key],
|
|
193
193
|
scope: AI_ACTIVITY_ACTION_SCOPES[key]
|
|
194
|
-
}))
|
|
194
|
+
})),
|
|
195
|
+
// A generation job (AGL-2904): the org feed names the job, and each of
|
|
196
|
+
// its outputs names the resource it produced. Filed as `aiJob` since
|
|
197
|
+
// before plugin target types were namespaced, so the noun is declared
|
|
198
|
+
// here rather than read off the type (AGL-3080).
|
|
199
|
+
targetTypes: {
|
|
200
|
+
aiJob: 'AI generation'
|
|
201
|
+
}
|
|
195
202
|
});
|
|
196
203
|
}
|
|
197
204
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../libs/plugins/ai/src/lib/activity/ai-activity-actions.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\n/**\n * The AI actions an activity log can carry (AGL-2929).\n *\n * Every other action in `orgs/{orgId}/activity` and `hosts/{hostId}/activity`\n * is a prose sentence written at the call site — \"Saved the screen\". The AI\n * rows are CODES instead, because they are read by more than a person: the\n * org feed's \"AI\" chip, the staff audit facet and the actor table all need\n * to recognize an AI row without parsing a sentence, and a sentence that\n * three writers phrase three ways is three rows that look unrelated.\n *\n * One list, so the writers in `ai-activity.ts`, the feed presenter and the\n * staff facet cannot disagree about what counts as AI. A code missing from\n * `AI_ACTIVITY_ACTION_LABELS` fails the type, not the reader.\n */\n\nimport type { AiJobOutputResource } from '../model/ai-jobs.types'\nimport {\n pluginStaffAuditActionGroup,\n pluginStaffAuditActionGroupLabel,\n registerPluginActivityActions,\n type PluginActivityScope,\n} from '@aglyn/aglyn/plugin-manager/plugin-activity-actions'\n\n/** The action code each AI writer stores. */\nexport const AI_ACTIVITY_ACTIONS = {\n jobCreated: 'ai.job.created',\n jobOutput: 'ai.job.output',\n jobCanceled: 'ai.job.canceled',\n jobNeedsInput: 'ai.job.needs_input',\n editApplied: 'ai.edit.applied',\n seoApplied: 'ai.seo.applied',\n assistSection: 'ai.assist.section',\n overageHardCap: 'ai.overage.hardCap',\n overageCap: 'ai.overage.cap',\n allotmentChanged: 'ai.allotment.changed',\n permissionChanged: 'ai.permission.changed',\n addonPurchased: 'ai.addon.purchased',\n addonRemoved: 'ai.addon.removed',\n} as const\n\nexport type AiActivityAction =\n (typeof AI_ACTIVITY_ACTIONS)[keyof typeof AI_ACTIVITY_ACTIONS]\n\n/** What a person reads for each code, in the feed and the actor table. */\nexport const AI_ACTIVITY_ACTION_LABELS: Record<AiActivityAction, string> = {\n 'ai.job.created': 'Started an AI generation',\n 'ai.job.output': 'AI generated',\n 'ai.job.canceled': 'Canceled an AI generation',\n 'ai.job.needs_input': 'AI generation paused for input',\n 'ai.edit.applied': 'Applied AI edits',\n 'ai.seo.applied': 'Applied AI SEO fixes as drafts',\n 'ai.assist.section': 'AI generated a section',\n 'ai.overage.hardCap': 'AI stop-at-band switch',\n 'ai.overage.cap': 'AI overage ceiling',\n 'ai.allotment.changed': 'AI allotment changed',\n 'ai.permission.changed': 'AI permission changed',\n 'ai.addon.purchased': 'Added the AI add-on',\n 'ai.addon.removed': 'Removed the AI add-on',\n}\n\n/** Every code, in catalog order — what a filter sends as `isAnyOf`. */\nexport const AI_ACTIVITY_ACTION_LIST: readonly AiActivityAction[] =\n Object.values(AI_ACTIVITY_ACTIONS)\n\n/** The feed's filter chip and the staff facet's group, by one name. */\nexport const AI_ACTIVITY_FILTER_LABEL = 'AI'\n\n/**\n * Why a generation stopped and asked for a person (AGL-2904): the plan's\n * band ran out, the org's own ceiling refused, the monthly message cap or\n * the job's own token budget did — or, on the Free taste (AGL-2925), one of\n * its own precautions: the account's credits, its daily request cap, a\n * pause after declined briefs, or the platform's day of free spend. Those\n * are the meter's `AssistRefusedBy` less its `null`, so a ceiling the meter\n * can name is one the feed can label. The last three are the job's own: its\n * plan is ready for review, or an answer broke a building rule on its re-ask\n * (AGL-2935), or the site is at an allowance its plan sets for what the job\n * writes (AGL-2909).\n */\nexport type AiJobNeedsInputReason =\n | 'band'\n | 'cap'\n | 'messages'\n | 'budget'\n | 'allotment'\n | 'account'\n | 'requests'\n | 'refusals'\n | 'platform'\n | 'plan'\n | 'doctrine'\n | 'limit'\n\nexport const AI_JOB_NEEDS_INPUT_REASON_LABELS: Record<\n AiJobNeedsInputReason,\n string\n> = {\n plan: 'its plan is ready for review',\n doctrine: 'its answer broke a building rule twice',\n limit: 'the site reached an allowance of its plan',\n band: 'the included AI band is used up',\n cap: 'the overage ceiling was reached',\n messages: 'the monthly message cap was reached',\n budget: 'the job budget was reached',\n allotment: 'the creator’s or the site’s AI allotment is used up',\n account: 'the account’s free AI credits are used up',\n requests: 'the daily free request cap was reached',\n refusals: 'free generation is paused for the day after declined briefs',\n platform: 'free AI generation is paused for the day',\n}\n\n/**\n * The feed target types a generation job's output can be filed under: the\n * kinds both activity logs know, so the org row and its host copy share a\n * shape.\n */\nexport type AiOutputTargetType =\n | 'screen'\n | 'layout'\n | 'component'\n | 'template'\n | 'workflow'\n | 'content'\n | 'theme'\n\n/**\n * Where the feed files each resource kind a job can write (AGL-2904).\n *\n * A job names its output by the resource it wrote, and the activity logs\n * know a narrower set of targets. The map is total, so a resource kind\n * added to the job document must say where the feed shows it before the\n * machine can log it. `reusableComponent` is the feed's `component`; a\n * `text` output is copy, which the feed files as `content`; a `theme`\n * proposal is filed under the site's theme, which the host feed links to the\n * Theme section (AGL-2938); the kinds whose runners have not shipped are\n * content of the site too, and are filed there until a target of their own\n * exists.\n */\nconst AI_OUTPUT_TARGET_TYPES: Record<AiJobOutputResource, AiOutputTargetType> = {\n screen: 'screen',\n reusableComponent: 'component',\n layout: 'layout',\n template: 'template',\n form: 'content',\n emailScreen: 'content',\n campaign: 'content',\n product: 'content',\n experiment: 'content',\n workflow: 'workflow',\n // An SEO proposal (AGL-2910) is about the site's content, and is filed there.\n seo: 'content',\n text: 'content',\n theme: 'theme',\n // An insight answer (AGL-2915) is about the site's figures; the feed row\n // names it and never what it says.\n insight: 'content',\n // A CRM proposal (AGL-2917) writes nothing; the feed files it with content.\n crm: 'content',\n}\n\nexport function aiOutputTargetType(resource: AiJobOutputResource): AiOutputTargetType {\n return AI_OUTPUT_TARGET_TYPES[resource]\n}\n\n/** Whether a stored action is one of the AI codes above. */\nexport function isAiActivityAction(action: unknown): action is AiActivityAction {\n return (\n typeof action === 'string' &&\n (AI_ACTIVITY_ACTION_LIST as readonly string[]).includes(action)\n )\n}\n\n/** The readable label for an AI code; `undefined` for any other action. */\nexport function aiActivityActionLabel(action: unknown): string | undefined {\n return isAiActivityAction(action)\n ? AI_ACTIVITY_ACTION_LABELS[action]\n : undefined\n}\n\n/**\n * Staff audit rows that are ABOUT AI without carrying an `ai.` code: the\n * customer's overage controls already write `billing.assistOverage.*`, and\n * the platform's free-spend auto-pause writes `platform.aiFreeSpend.*`\n * (AGL-2925). The audit page's facet folds them under the same group as the\n * codes, because \"what did we do about AI this week\" is one question.\n */\nexport const AI_STAFF_AUDIT_ACTION_PREFIXES: readonly string[] = [\n 'ai.',\n 'billing.assistOverage.',\n 'platform.aiFreeSpend.',\n]\n\n/** The facet group an `adminAudit` action belongs to. */\nexport const STAFF_AUDIT_AI_GROUP = 'ai'\n\n/**\n * Which log each code is written to. The job and edit codes land in both\n * the org feed and the host's copy; the billing and permission codes are\n * org-level facts and land in the org feed alone.\n */\nconst AI_ACTIVITY_ACTION_SCOPES: Record<\n AiActivityAction,\n PluginActivityScope | readonly PluginActivityScope[]\n> = {\n 'ai.job.created': ['org', 'host'],\n 'ai.job.output': ['org', 'host'],\n 'ai.job.canceled': ['org', 'host'],\n 'ai.job.needs_input': ['org', 'host'],\n 'ai.edit.applied': ['org', 'host'],\n 'ai.seo.applied': ['org', 'host'],\n 'ai.assist.section': ['org', 'host'],\n 'ai.overage.hardCap': 'org',\n 'ai.overage.cap': 'org',\n 'ai.allotment.changed': 'org',\n 'ai.permission.changed': 'org',\n 'ai.addon.purchased': 'org',\n 'ai.addon.removed': 'org',\n}\n\n/**\n * The catalog, declared through the generic activity-action seam\n * (AGL-2940) so the feed's chip, the actor table's filter and the staff\n * facet read it from the registry beside every other plugin's codes.\n * `registerAiDeclarations` calls it, in both apps and in the browser.\n */\nexport function registerAiActivityActions(): void {\n registerPluginActivityActions({\n pluginId: 'ai',\n group: {\n id: STAFF_AUDIT_AI_GROUP,\n label: AI_ACTIVITY_FILTER_LABEL,\n staffAuditPrefixes: AI_STAFF_AUDIT_ACTION_PREFIXES.filter(\n (prefix) => prefix !== 'ai.',\n ),\n // The staff cards opening on an org (AGL-2930) and on one account\n // (AGL-2928). Neither writes these any more; the rows already in the\n // log still classify as reads rather than changes.\n staffAuditAccessActions: ['org.ai-viewed', 'user.ai-usage-viewed'],\n },\n actions: AI_ACTIVITY_ACTION_LIST.map((key) => ({\n key,\n label: AI_ACTIVITY_ACTION_LABELS[key],\n scope: AI_ACTIVITY_ACTION_SCOPES[key],\n })),\n })\n}\n\n/**\n * The group the staff audit facet files an action under: `ai` for every\n * AI row, otherwise the action's leading namespace (`billing`, `org`,\n * `plugins`). Roughly seventy distinct actions write to `adminAudit`, so\n * the facet offers namespaces rather than a seventy-entry menu. Answered\n * by the registry, so every plugin's group is filed the same way.\n */\nexport function staffAuditActionGroup(action: unknown): string {\n return pluginStaffAuditActionGroup(action)\n}\n\n/** How a facet group reads in the menu: `ai` → `AI`, `billing` → `billing`. */\nexport function staffAuditActionGroupLabel(group: string): string {\n return pluginStaffAuditActionGroupLabel(group)\n}\n"],"names":["pluginStaffAuditActionGroup","pluginStaffAuditActionGroupLabel","registerPluginActivityActions","AI_ACTIVITY_ACTIONS","jobCreated","jobOutput","jobCanceled","jobNeedsInput","editApplied","seoApplied","assistSection","overageHardCap","overageCap","allotmentChanged","permissionChanged","addonPurchased","addonRemoved","AI_ACTIVITY_ACTION_LABELS","AI_ACTIVITY_ACTION_LIST","Object","values","AI_ACTIVITY_FILTER_LABEL","AI_JOB_NEEDS_INPUT_REASON_LABELS","plan","doctrine","limit","band","cap","messages","budget","allotment","account","requests","refusals","platform","AI_OUTPUT_TARGET_TYPES","screen","reusableComponent","layout","template","form","emailScreen","campaign","product","experiment","workflow","seo","text","theme","insight","crm","aiOutputTargetType","resource","isAiActivityAction","action","includes","aiActivityActionLabel","undefined","AI_STAFF_AUDIT_ACTION_PREFIXES","STAFF_AUDIT_AI_GROUP","AI_ACTIVITY_ACTION_SCOPES","registerAiActivityActions","pluginId","group","id","label","staffAuditPrefixes","filter","prefix","staffAuditAccessActions","actions","map","key","scope","staffAuditActionGroup","staffAuditActionGroupLabel"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED;;;;;;;;;;;;;CAaC,GAGD,SACEA,2BAA2B,EAC3BC,gCAAgC,EAChCC,6BAA6B,QAExB,sDAAqD;AAE5D,2CAA2C,GAC3C,OAAO,MAAMC,sBAAsB;IACjCC,YAAY;IACZC,WAAW;IACXC,aAAa;IACbC,eAAe;IACfC,aAAa;IACbC,YAAY;IACZC,eAAe;IACfC,gBAAgB;IAChBC,YAAY;IACZC,kBAAkB;IAClBC,mBAAmB;IACnBC,gBAAgB;IAChBC,cAAc;AAChB,EAAU;AAKV,wEAAwE,GACxE,OAAO,MAAMC,4BAA8D;IACzE,kBAAkB;IAClB,iBAAiB;IACjB,mBAAmB;IACnB,sBAAsB;IACtB,mBAAmB;IACnB,kBAAkB;IAClB,qBAAqB;IACrB,sBAAsB;IACtB,kBAAkB;IAClB,wBAAwB;IACxB,yBAAyB;IACzB,sBAAsB;IACtB,oBAAoB;AACtB,EAAC;AAED,qEAAqE,GACrE,OAAO,MAAMC,0BACXC,OAAOC,MAAM,CAACjB,qBAAoB;AAEpC,qEAAqE,GACrE,OAAO,MAAMkB,2BAA2B,KAAI;AA4B5C,OAAO,MAAMC,mCAGT;IACFC,MAAM;IACNC,UAAU;IACVC,OAAO;IACPC,MAAM;IACNC,KAAK;IACLC,UAAU;IACVC,QAAQ;IACRC,WAAW;IACXC,SAAS;IACTC,UAAU;IACVC,UAAU;IACVC,UAAU;AACZ,EAAC;AAgBD;;;;;;;;;;;;CAYC,GACD,MAAMC,yBAA0E;IAC9EC,QAAQ;IACRC,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AyB;gBAAC;gBAAiB;aAAuB;QACpE;QACAC,SAASpD,wBAAwBqD,GAAG,CAAC,CAACC,MAAS,CAAA;gBAC7CA;gBACAP,OAAOhD,yBAAyB,CAACuD,IAAI;gBACrCC,OAAOb,yBAAyB,CAACY,IAAI;YACvC,CAAA;IACF;AACF;AAEA;;;;;;CAMC,GACD,OAAO,SAASE,sBAAsBpB,MAAe;IACnD,OAAOtD,4BAA4BsD;AACrC;AAEA,6EAA6E,GAC7E,OAAO,SAASqB,2BAA2BZ,KAAa;IACtD,OAAO9D,iCAAiC8D;AAC1C"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/ai/src/lib/activity/ai-activity-actions.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\n/**\n * The AI actions an activity log can carry (AGL-2929).\n *\n * Every other action in `orgs/{orgId}/activity` and `hosts/{hostId}/activity`\n * is a prose sentence written at the call site — \"Saved the screen\". The AI\n * rows are CODES instead, because they are read by more than a person: the\n * org feed's \"AI\" chip, the staff audit facet and the actor table all need\n * to recognize an AI row without parsing a sentence, and a sentence that\n * three writers phrase three ways is three rows that look unrelated.\n *\n * One list, so the writers in `ai-activity.ts`, the feed presenter and the\n * staff facet cannot disagree about what counts as AI. A code missing from\n * `AI_ACTIVITY_ACTION_LABELS` fails the type, not the reader.\n */\n\nimport type { AiJobOutputResource } from '../model/ai-jobs.types'\nimport {\n pluginStaffAuditActionGroup,\n pluginStaffAuditActionGroupLabel,\n registerPluginActivityActions,\n type PluginActivityScope,\n} from '@aglyn/aglyn/plugin-manager/plugin-activity-actions'\n\n/** The action code each AI writer stores. */\nexport const AI_ACTIVITY_ACTIONS = {\n jobCreated: 'ai.job.created',\n jobOutput: 'ai.job.output',\n jobCanceled: 'ai.job.canceled',\n jobNeedsInput: 'ai.job.needs_input',\n editApplied: 'ai.edit.applied',\n seoApplied: 'ai.seo.applied',\n assistSection: 'ai.assist.section',\n overageHardCap: 'ai.overage.hardCap',\n overageCap: 'ai.overage.cap',\n allotmentChanged: 'ai.allotment.changed',\n permissionChanged: 'ai.permission.changed',\n addonPurchased: 'ai.addon.purchased',\n addonRemoved: 'ai.addon.removed',\n} as const\n\nexport type AiActivityAction =\n (typeof AI_ACTIVITY_ACTIONS)[keyof typeof AI_ACTIVITY_ACTIONS]\n\n/** What a person reads for each code, in the feed and the actor table. */\nexport const AI_ACTIVITY_ACTION_LABELS: Record<AiActivityAction, string> = {\n 'ai.job.created': 'Started an AI generation',\n 'ai.job.output': 'AI generated',\n 'ai.job.canceled': 'Canceled an AI generation',\n 'ai.job.needs_input': 'AI generation paused for input',\n 'ai.edit.applied': 'Applied AI edits',\n 'ai.seo.applied': 'Applied AI SEO fixes as drafts',\n 'ai.assist.section': 'AI generated a section',\n 'ai.overage.hardCap': 'AI stop-at-band switch',\n 'ai.overage.cap': 'AI overage ceiling',\n 'ai.allotment.changed': 'AI allotment changed',\n 'ai.permission.changed': 'AI permission changed',\n 'ai.addon.purchased': 'Added the AI add-on',\n 'ai.addon.removed': 'Removed the AI add-on',\n}\n\n/** Every code, in catalog order — what a filter sends as `isAnyOf`. */\nexport const AI_ACTIVITY_ACTION_LIST: readonly AiActivityAction[] =\n Object.values(AI_ACTIVITY_ACTIONS)\n\n/** The feed's filter chip and the staff facet's group, by one name. */\nexport const AI_ACTIVITY_FILTER_LABEL = 'AI'\n\n/**\n * Why a generation stopped and asked for a person (AGL-2904): the plan's\n * band ran out, the org's own ceiling refused, the monthly message cap or\n * the job's own token budget did — or, on the Free taste (AGL-2925), one of\n * its own precautions: the account's credits, its daily request cap, a\n * pause after declined briefs, or the platform's day of free spend. Those\n * are the meter's `AssistRefusedBy` less its `null`, so a ceiling the meter\n * can name is one the feed can label. The last three are the job's own: its\n * plan is ready for review, or an answer broke a building rule on its re-ask\n * (AGL-2935), or the site is at an allowance its plan sets for what the job\n * writes (AGL-2909).\n */\nexport type AiJobNeedsInputReason =\n | 'band'\n | 'cap'\n | 'messages'\n | 'budget'\n | 'allotment'\n | 'account'\n | 'requests'\n | 'refusals'\n | 'platform'\n | 'plan'\n | 'doctrine'\n | 'limit'\n\nexport const AI_JOB_NEEDS_INPUT_REASON_LABELS: Record<\n AiJobNeedsInputReason,\n string\n> = {\n plan: 'its plan is ready for review',\n doctrine: 'its answer broke a building rule twice',\n limit: 'the site reached an allowance of its plan',\n band: 'the included AI band is used up',\n cap: 'the overage ceiling was reached',\n messages: 'the monthly message cap was reached',\n budget: 'the job budget was reached',\n allotment: 'the creator’s or the site’s AI allotment is used up',\n account: 'the account’s free AI credits are used up',\n requests: 'the daily free request cap was reached',\n refusals: 'free generation is paused for the day after declined briefs',\n platform: 'free AI generation is paused for the day',\n}\n\n/**\n * The feed target types a generation job's output can be filed under: the\n * kinds both activity logs know, so the org row and its host copy share a\n * shape.\n */\nexport type AiOutputTargetType =\n | 'screen'\n | 'layout'\n | 'component'\n | 'template'\n | 'workflow'\n | 'content'\n | 'theme'\n\n/**\n * Where the feed files each resource kind a job can write (AGL-2904).\n *\n * A job names its output by the resource it wrote, and the activity logs\n * know a narrower set of targets. The map is total, so a resource kind\n * added to the job document must say where the feed shows it before the\n * machine can log it. `reusableComponent` is the feed's `component`; a\n * `text` output is copy, which the feed files as `content`; a `theme`\n * proposal is filed under the site's theme, which the host feed links to the\n * Theme section (AGL-2938); the kinds whose runners have not shipped are\n * content of the site too, and are filed there until a target of their own\n * exists.\n */\nconst AI_OUTPUT_TARGET_TYPES: Record<AiJobOutputResource, AiOutputTargetType> = {\n screen: 'screen',\n reusableComponent: 'component',\n layout: 'layout',\n template: 'template',\n form: 'content',\n emailScreen: 'content',\n campaign: 'content',\n product: 'content',\n experiment: 'content',\n workflow: 'workflow',\n // An SEO proposal (AGL-2910) is about the site's content, and is filed there.\n seo: 'content',\n text: 'content',\n theme: 'theme',\n // An insight answer (AGL-2915) is about the site's figures; the feed row\n // names it and never what it says.\n insight: 'content',\n // A CRM proposal (AGL-2917) writes nothing; the feed files it with content.\n crm: 'content',\n}\n\nexport function aiOutputTargetType(resource: AiJobOutputResource): AiOutputTargetType {\n return AI_OUTPUT_TARGET_TYPES[resource]\n}\n\n/** Whether a stored action is one of the AI codes above. */\nexport function isAiActivityAction(action: unknown): action is AiActivityAction {\n return (\n typeof action === 'string' &&\n (AI_ACTIVITY_ACTION_LIST as readonly string[]).includes(action)\n )\n}\n\n/** The readable label for an AI code; `undefined` for any other action. */\nexport function aiActivityActionLabel(action: unknown): string | undefined {\n return isAiActivityAction(action)\n ? AI_ACTIVITY_ACTION_LABELS[action]\n : undefined\n}\n\n/**\n * Staff audit rows that are ABOUT AI without carrying an `ai.` code: the\n * customer's overage controls already write `billing.assistOverage.*`, and\n * the platform's free-spend auto-pause writes `platform.aiFreeSpend.*`\n * (AGL-2925). The audit page's facet folds them under the same group as the\n * codes, because \"what did we do about AI this week\" is one question.\n */\nexport const AI_STAFF_AUDIT_ACTION_PREFIXES: readonly string[] = [\n 'ai.',\n 'billing.assistOverage.',\n 'platform.aiFreeSpend.',\n]\n\n/** The facet group an `adminAudit` action belongs to. */\nexport const STAFF_AUDIT_AI_GROUP = 'ai'\n\n/**\n * Which log each code is written to. The job and edit codes land in both\n * the org feed and the host's copy; the billing and permission codes are\n * org-level facts and land in the org feed alone.\n */\nconst AI_ACTIVITY_ACTION_SCOPES: Record<\n AiActivityAction,\n PluginActivityScope | readonly PluginActivityScope[]\n> = {\n 'ai.job.created': ['org', 'host'],\n 'ai.job.output': ['org', 'host'],\n 'ai.job.canceled': ['org', 'host'],\n 'ai.job.needs_input': ['org', 'host'],\n 'ai.edit.applied': ['org', 'host'],\n 'ai.seo.applied': ['org', 'host'],\n 'ai.assist.section': ['org', 'host'],\n 'ai.overage.hardCap': 'org',\n 'ai.overage.cap': 'org',\n 'ai.allotment.changed': 'org',\n 'ai.permission.changed': 'org',\n 'ai.addon.purchased': 'org',\n 'ai.addon.removed': 'org',\n}\n\n/**\n * The catalog, declared through the generic activity-action seam\n * (AGL-2940) so the feed's chip, the actor table's filter and the staff\n * facet read it from the registry beside every other plugin's codes.\n * `registerAiDeclarations` calls it, in both apps and in the browser.\n */\nexport function registerAiActivityActions(): void {\n registerPluginActivityActions({\n pluginId: 'ai',\n group: {\n id: STAFF_AUDIT_AI_GROUP,\n label: AI_ACTIVITY_FILTER_LABEL,\n staffAuditPrefixes: AI_STAFF_AUDIT_ACTION_PREFIXES.filter(\n (prefix) => prefix !== 'ai.',\n ),\n // The staff cards opening on an org (AGL-2930) and on one account\n // (AGL-2928). Neither writes these any more; the rows already in the\n // log still classify as reads rather than changes.\n staffAuditAccessActions: ['org.ai-viewed', 'user.ai-usage-viewed'],\n },\n actions: AI_ACTIVITY_ACTION_LIST.map((key) => ({\n key,\n label: AI_ACTIVITY_ACTION_LABELS[key],\n scope: AI_ACTIVITY_ACTION_SCOPES[key],\n })),\n // A generation job (AGL-2904): the org feed names the job, and each of\n // its outputs names the resource it produced. Filed as `aiJob` since\n // before plugin target types were namespaced, so the noun is declared\n // here rather than read off the type (AGL-3080).\n targetTypes: { aiJob: 'AI generation' },\n })\n}\n\n/**\n * The group the staff audit facet files an action under: `ai` for every\n * AI row, otherwise the action's leading namespace (`billing`, `org`,\n * `plugins`). Roughly seventy distinct actions write to `adminAudit`, so\n * the facet offers namespaces rather than a seventy-entry menu. Answered\n * by the registry, so every plugin's group is filed the same way.\n */\nexport function staffAuditActionGroup(action: unknown): string {\n return pluginStaffAuditActionGroup(action)\n}\n\n/** How a facet group reads in the menu: `ai` → `AI`, `billing` → `billing`. */\nexport function staffAuditActionGroupLabel(group: string): string {\n return pluginStaffAuditActionGroupLabel(group)\n}\n"],"names":["pluginStaffAuditActionGroup","pluginStaffAuditActionGroupLabel","registerPluginActivityActions","AI_ACTIVITY_ACTIONS","jobCreated","jobOutput","jobCanceled","jobNeedsInput","editApplied","seoApplied","assistSection","overageHardCap","overageCap","allotmentChanged","permissionChanged","addonPurchased","addonRemoved","AI_ACTIVITY_ACTION_LABELS","AI_ACTIVITY_ACTION_LIST","Object","values","AI_ACTIVITY_FILTER_LABEL","AI_JOB_NEEDS_INPUT_REASON_LABELS","plan","doctrine","limit","band","cap","messages","budget","allotment","account","requests","refusals","platform","AI_OUTPUT_TARGET_TYPES","screen","reusableComponent","layout","template","form","emailScreen","campaign","product","experiment","workflow","seo","text","theme","insight","crm","aiOutputTargetType","resource","isAiActivityAction","action","includes","aiActivityActionLabel","undefined","AI_STAFF_AUDIT_ACTION_PREFIXES","STAFF_AUDIT_AI_GROUP","AI_ACTIVITY_ACTION_SCOPES","registerAiActivityActions","pluginId","group","id","label","staffAuditPrefixes","filter","prefix","staffAuditAccessActions","actions","map","key","scope","targetTypes","aiJob","staffAuditActionGroup","staffAuditActionGroupLabel"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED;;;;;;;;;;;;;CAaC,GAGD,SACEA,2BAA2B,EAC3BC,gCAAgC,EAChCC,6BAA6B,QAExB,sDAAqD;AAE5D,2CAA2C,GAC3C,OAAO,MAAMC,sBAAsB;IACjCC,YAAY;IACZC,WAAW;IACXC,aAAa;IACbC,eAAe;IACfC,aAAa;IACbC,YAAY;IACZC,eAAe;IACfC,gBAAgB;IAChBC,YAAY;IACZC,kBAAkB;IAClBC,mBAAmB;IACnBC,gBAAgB;IAChBC,cAAc;AAChB,EAAU;AAKV,wEAAwE,GACxE,OAAO,MAAMC,4BAA8D;IACzE,kBAAkB;IAClB,iBAAiB;IACjB,mBAAmB;IACnB,sBAAsB;IACtB,mBAAmB;IACnB,kBAAkB;IAClB,qBAAqB;IACrB,sBAAsB;IACtB,kBAAkB;IAClB,wBAA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BAAsB;QAAC;QAAO;KAAO;IACrC,mBAAmB;QAAC;QAAO;KAAO;IAClC,kBAAkB;QAAC;QAAO;KAAO;IACjC,qBAAqB;QAAC;QAAO;KAAO;IACpC,sBAAsB;IACtB,kBAAkB;IAClB,wBAAwB;IACxB,yBAAyB;IACzB,sBAAsB;IACtB,oBAAoB;AACtB;AAEA;;;;;CAKC,GACD,OAAO,SAASC;IACd3D,8BAA8B;QAC5B4D,UAAU;QACVC,OAAO;YACLC,IAAIL;YACJM,OAAO5C;YACP6C,oBAAoBR,+BAA+BS,MAAM,CACvD,CAACC,SAAWA,WAAW;YAEzB,kEAAkE;YAClE,qEAAqE;YACrE,mDAAmD;YACnDC,yBAAyB;gBAAC;gBAAiB;aAAuB;QACpE;QACAC,SAASpD,wBAAwBqD,GAAG,CAAC,CAACC,MAAS,CAAA;gBAC7CA;gBACAP,OAAOhD,yBAAyB,CAACuD,IAAI;gBACrCC,OAAOb,yBAAyB,CAACY,IAAI;YACvC,CAAA;QACA,uEAAuE;QACvE,qEAAqE;QACrE,sEAAsE;QACtE,iDAAiD;QACjDE,aAAa;YAAEC,OAAO;QAAgB;IACxC;AACF;AAEA;;;;;;CAMC,GACD,OAAO,SAASC,sBAAsBtB,MAAe;IACnD,OAAOtD,4BAA4BsD;AACrC;AAEA,6EAA6E,GAC7E,OAAO,SAASuB,2BAA2Bd,KAAa;IACtD,OAAO9D,iCAAiC8D;AAC1C"}
|
|
@@ -18,7 +18,7 @@ import { _ as _extends } from "@swc/helpers/_/_extends";
|
|
|
18
18
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
19
19
|
import * as Aglyn from "@aglyn/aglyn";
|
|
20
20
|
import { checkEntitlement, lockdownRefusalText, parseLockdownRefusal } from "@aglyn/aglyn";
|
|
21
|
-
import {
|
|
21
|
+
import { portableDefinitionToNested } from "@aglyn/aglyn/app-utils/node-definition-sanitizer";
|
|
22
22
|
import { AiAssistActionsContext } from "./ai-assist-actions-context.js";
|
|
23
23
|
import { useSnackbar } from "@aglyn/shared-ui-snackstack";
|
|
24
24
|
import { Button, CircularProgress, Dialog, DialogActions, DialogContent, DialogTitle, MenuItem, TextField, Typography } from "@mui/material";
|
|
@@ -293,7 +293,7 @@ const AI_GENERATE_REFUSED = 'Your role does not include AI generation — ask an
|
|
|
293
293
|
allowDuplicate: true
|
|
294
294
|
});
|
|
295
295
|
}
|
|
296
|
-
const nested =
|
|
296
|
+
const nested = portableDefinitionToNested(payload.section.rootId, payload.section.nodes);
|
|
297
297
|
if (!nested) {
|
|
298
298
|
return void enqueueSnackbar('AI returned an empty section', {
|
|
299
299
|
variant: 'error',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../libs/plugins/ai/src/lib/components/ai-assist-provider.component.tsx"],"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'use client'\n\nimport * as Aglyn from '@aglyn/aglyn'\nimport {\n checkEntitlement,\n lockdownRefusalText,\n parseLockdownRefusal,\n} from '@aglyn/aglyn'\nimport { marketplaceDefinitionToNested } from '@aglyn/aglyn/app-utils/node-definition-sanitizer'\nimport { AiAssistActionsContext } from './ai-assist-actions-context'\nimport { useSnackbar } from '@aglyn/shared-ui-snackstack'\nimport {\n Button,\n CircularProgress,\n Dialog,\n DialogActions,\n DialogContent,\n DialogTitle,\n MenuItem,\n TextField,\n Typography,\n} from '@mui/material'\nimport { useCallback, useMemo, useState } from 'react'\nimport { useUser } from '@aglyn/tenant-feature-instance'\nimport { authorizedFetch } from '@aglyn/shared-util-http/authorized-token'\nimport { AiModelSelector } from './ai-model-selector.component'\nimport { AiUsageStrip } from './ai-usage-strip.component'\nimport { useAiModelChoice } from './use-ai-model-choice'\nimport { usePublishAiUsageMeter } from './use-ai-usage-meter'\n\n\nexport interface AiAssistProviderProps {\n /** Org billing doc for the entitlement gate (mounted by the shell). */\n org?: unknown\n /**\n * True once `org` is a trustworthy answer (AGL-1380). The shell mounts\n * this provider above the whole console route tree, so it cannot hold its\n * render until the billing doc settles the way the plugin-page route does\n * — and an undefined `org` is not \"unknown\" to `checkEntitlement`, it is\n * the free tier. Without this flag the gates below told a Pro org that AI\n * assist is not on its plan for as long as the read was in flight.\n */\n orgReady?: boolean\n /**\n * The org every assist call is metered against (AGL-2073). The route no\n * longer resolves it from the signed-in user — a user with one paid org was\n * getting assist on all of their free ones, and their spend was landing on\n * whichever org the server happened to resolve.\n */\n orgId?: string\n /**\n * The site the canvas belongs to (AGL-2927), sent with every assist call\n * so the door can decide a site collaborator's permission on THAT site.\n * Null off a host route, where there is no canvas to assist on.\n */\n hostId?: string | null\n /**\n * The reader's AI verdict, resolved by the shell (AGL-2927). The gates\n * below HOLD until `loaded` — a door opened on a pending answer would\n * spend the workspace's credits on a permission nobody has confirmed —\n * and a refused key removes its callback from the context, so the\n * designer draws no control for it. Omitted, the answer is pending.\n */\n aiPermissions?: { loaded: boolean; use: boolean; generate: boolean }\n children?: JSX.Children\n}\n\nconst PERMISSIONS_PENDING = 'Checking your permissions — try again in a moment'\nconst AI_USE_REFUSED =\n 'Your role does not include AI assistance — ask an organization admin'\nconst AI_GENERATE_REFUSED =\n 'Your role does not include AI generation — ask an organization admin'\n\n/**\n * Console-side AI copy assist (AGL-89): provides the designer's \"Rewrite\n * with AI\" callback, hosts the instruction dialog, and calls the assist API\n * (which 501-degrades when no AI provider is configured). The commit\n * spreads the node's current props — `updateNodeProps` REPLACES the props\n * object — and clears any stale rich-text `html` so the new text renders.\n */\nexport function AiAssistProvider(props: AiAssistProviderProps) {\n const org = props.org\n const orgReady = props.orgReady\n const orgId = props.orgId\n const hostId = props.hostId ?? null\n const aiPermissions = props.aiPermissions\n const { children } = props\n const { enqueueSnackbar } = useSnackbar()\n const { data: user } = useUser()\n const [node, setNode] = useState<Aglyn.NodeSchema<any> | null>(null)\n const [instruction, setInstruction] = useState('')\n // Rewrite target (AGL-130): 'children' for text-editable elements, or\n // any text attribute the element's schema declares (alt text, labels…).\n const [targetProp, setTargetProp] = useState('children')\n const [busy, setBusy] = useState(false)\n // Generate section (AGL-169).\n const [sectionOpen, setSectionOpen] = useState(false)\n const [sectionPrompt, setSectionPrompt] = useState('')\n // The model switch and the usage strip in both dialogs (AGL-2942). Each\n // dialog remembers its own pick; one envelope store serves both strips\n // and the assistant panel's.\n const copyModel = useAiModelChoice({ orgId, hostId, surface: 'copy', kind: 'copy.element' })\n const sectionModel = useAiModelChoice({\n orgId,\n hostId,\n surface: 'section',\n kind: 'copy.section',\n })\n const publishMeter = usePublishAiUsageMeter(orgId)\n\n const textTargets = useMemo(() => {\n const schema = node?.componentSchema\n const textEditable =\n ((schema?.flags?.textEditable ?? Aglyn.FEATURE_FLAG.DISABLED) &\n Aglyn.FEATURE_FLAG.ENABLED) !==\n 0\n const attributes = (schema?.attributes ?? [])\n .filter(\n (field: any) =>\n field.component === Aglyn.FieldComponentType.TEXT_FIELD ||\n field.component === Aglyn.FieldComponentType.TEXTAREA,\n )\n .map((field: any) => ({\n prop: String(field.name),\n label: String(field.label ?? field.name),\n }))\n return textEditable\n ? [{ prop: 'children', label: 'Element text' }, ...attributes]\n : attributes\n }, [node])\n\n const handleRewrite = useCallback(\n (target: Aglyn.NodeSchema<any>) => {\n // The permission first (AGL-2927): it is a fact about the reader, and\n // pending asserts nothing here either. The refusal is unreachable\n // through the designer — a refused key publishes no callback — and\n // stands for any other caller of the context.\n if (!aiPermissions?.loaded) {\n return void enqueueSnackbar(PERMISSIONS_PENDING, {\n variant: 'info',\n persist: false,\n })\n }\n if (!aiPermissions.use) {\n return void enqueueSnackbar(AI_USE_REFUSED, {\n variant: 'warning',\n persist: false,\n })\n }\n // AGL-1380: pending asserts nothing. See `orgReady` on the props.\n if (!orgReady) {\n return void enqueueSnackbar(\n 'Checking your plan — try again in a moment',\n { variant: 'info', persist: false },\n )\n }\n if (!checkEntitlement(org as never, 'aiAssist')) {\n return void enqueueSnackbar(\n 'AI assist requires a Pro plan — see Billing to upgrade',\n { variant: 'warning', persist: false },\n )\n }\n setInstruction('')\n setTargetProp('children')\n setNode(target)\n },\n [org, orgReady, aiPermissions, enqueueSnackbar],\n )\n\n // Keep the target valid for the selected element.\n const effectiveTarget = textTargets.some((item) => item.prop === targetProp)\n ? targetProp\n : (textTargets[0]?.prop ?? 'children')\n\n const handleConfirm = useCallback(async () => {\n if (!node || !instruction.trim() || busy) return\n setBusy(true)\n try {\n const current = (Aglyn.canvas.toJSON().nodes as Record<string, any>)[\n node.$id\n ]\n const text =\n typeof current?.props?.[effectiveTarget] === 'string'\n ? (current.props[effectiveTarget] as string)\n : ''\n const response = await authorizedFetch(user, '/api/ai/assist', {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({\n orgId,\n hostId,\n text,\n instruction: instruction.trim(),\n ...(copyModel.model ? { model: copyModel.model } : {}),\n }),\n })\n const payload = await response.json()\n publishMeter(payload?.meter)\n // An ai-assist feature lockdown (AGL-1510/1532) reads as a pause, not\n // as \"AI request failed\" — a provider incident or a cost runaway is\n // something WE turned off, and saying so keeps the user's content out\n // of the story.\n const locked = parseLockdownRefusal(response.status, payload)\n if (locked) {\n return void enqueueSnackbar(lockdownRefusalText(locked), {\n variant: 'warning',\n persist: true,\n })\n }\n if (response.status === 501) {\n return void enqueueSnackbar(\n 'AI assist is not configured on this deployment',\n { variant: 'info', persist: false },\n )\n }\n if (!response.ok || !payload?.text) {\n return void enqueueSnackbar(payload?.error ?? 'AI request failed', {\n variant: 'error',\n allowDuplicate: true,\n })\n }\n Aglyn.canvas.updateNodeProps(node, {\n ...current?.props,\n [effectiveTarget]: payload.text,\n // Rich-text elements render `html` over `children`; drop it so the\n // rewrite is what shows (the user can re-format inline afterwards).\n ...(effectiveTarget === 'children' ? { html: undefined } : {}),\n })\n setNode(null)\n enqueueSnackbar('Text rewritten — undo restores the original', {\n variant: 'success',\n persist: false,\n })\n } catch (error) {\n console.error(error)\n enqueueSnackbar('An error has occurred', {\n variant: 'error',\n allowDuplicate: true,\n })\n } finally {\n setBusy(false)\n }\n }, [\n node,\n instruction,\n busy,\n user,\n effectiveTarget,\n orgId,\n hostId,\n copyModel.model,\n publishMeter,\n enqueueSnackbar,\n ])\n\n const handleGenerateSection = useCallback(() => {\n // The permission first (AGL-2927) — a section is a generation, so this\n // door sells under `ai.generate`; see `handleRewrite`.\n if (!aiPermissions?.loaded) {\n return void enqueueSnackbar(PERMISSIONS_PENDING, {\n variant: 'info',\n persist: false,\n })\n }\n if (!aiPermissions.generate) {\n return void enqueueSnackbar(AI_GENERATE_REFUSED, {\n variant: 'warning',\n persist: false,\n })\n }\n // AGL-1380: same gate as `handleRewrite`.\n if (!orgReady) {\n return void enqueueSnackbar('Checking your plan — try again in a moment', {\n variant: 'info',\n persist: false,\n })\n }\n if (!checkEntitlement(org as never, 'aiAssist')) {\n return void enqueueSnackbar(\n 'AI assist requires a Pro plan — see Billing to upgrade',\n { variant: 'warning', persist: false },\n )\n }\n setSectionPrompt('')\n setSectionOpen(true)\n }, [org, orgReady, aiPermissions, enqueueSnackbar])\n\n const handleSectionConfirm = useCallback(async () => {\n if (!sectionPrompt.trim() || busy) return\n setBusy(true)\n try {\n const response = await authorizedFetch(user, '/api/ai/assist', {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({\n orgId,\n hostId,\n mode: 'section',\n instruction: sectionPrompt.trim(),\n ...(sectionModel.model ? { model: sectionModel.model } : {}),\n }),\n })\n const payload = await response.json()\n publishMeter(payload?.meter)\n // Same pause notice on the section-generation door (AGL-1532).\n const locked = parseLockdownRefusal(response.status, payload)\n if (locked) {\n return void enqueueSnackbar(lockdownRefusalText(locked), {\n variant: 'warning',\n persist: true,\n })\n }\n if (response.status === 501) {\n return void enqueueSnackbar(\n 'AI assist is not configured on this deployment',\n { variant: 'info', persist: false },\n )\n }\n if (!response.ok || !payload?.section?.rootId) {\n return void enqueueSnackbar(payload?.error ?? 'AI request failed', {\n variant: 'error',\n allowDuplicate: true,\n })\n }\n const nested = marketplaceDefinitionToNested(\n payload.section.rootId,\n payload.section.nodes,\n )\n if (!nested) {\n return void enqueueSnackbar('AI returned an empty section', {\n variant: 'error',\n allowDuplicate: true,\n })\n }\n // Graft through the preset path: ids regenerate, history is saved,\n // and the subtree lands at the end of the canvas root.\n const stamped = (function stamp(node: any): any {\n const schema = Aglyn.components.getSchema(node.componentId)\n return {\n ...node,\n ...(schema?.pluginId ? { pluginId: schema.pluginId } : {}),\n nodes: (node.nodes ?? []).map(stamp),\n }\n })(nested)\n Aglyn.canvas.addNodeFromPreset(\n { type: Aglyn.NodeType.PRESET, data: stamped } as any,\n Aglyn.canvas.rootNode as any,\n )\n setSectionOpen(false)\n enqueueSnackbar('Section added — undo removes it', {\n variant: 'success',\n persist: false,\n })\n } catch (error) {\n console.error(error)\n enqueueSnackbar('An error has occurred', {\n variant: 'error',\n allowDuplicate: true,\n })\n } finally {\n setBusy(false)\n }\n }, [\n sectionPrompt,\n busy,\n user,\n orgId,\n hostId,\n sectionModel.model,\n publishMeter,\n enqueueSnackbar,\n ])\n\n // A REFUSED key publishes no callback (AGL-2927): the besigner controls\n // render only when the callback exists, so the refusal removes\n // the button rather than dimming it. A PENDING answer keeps both\n // callbacks, and each holds with a notice when pressed — a control that\n // vanishes and reappears while the read lands is worse than one that is\n // briefly inert (the `useHostRole` argument, applied here).\n const refusedUse = aiPermissions?.loaded === true && !aiPermissions.use\n const refusedGenerate =\n aiPermissions?.loaded === true && !aiPermissions.generate\n const contextValue = useMemo(\n () => ({\n ...(refusedUse ? {} : { onRewrite: handleRewrite }),\n ...(refusedGenerate ? {} : { onGenerateSection: handleGenerateSection }),\n }),\n [handleRewrite, handleGenerateSection, refusedUse, refusedGenerate],\n )\n\n return (\n <AiAssistActionsContext.Provider value={contextValue}>\n {children}\n <Dialog\n open={Boolean(node)}\n onClose={() => (busy ? null : setNode(null))}\n maxWidth=\"xs\"\n fullWidth\n >\n <DialogTitle>{'Rewrite with AI'}</DialogTitle>\n <DialogContent\n sx={{ display: 'flex', flexDirection: 'column', gap: 2, pt: 1 }}\n >\n <Typography variant=\"body2\" color=\"text.secondary\">\n {'Describe how the text should change — tone, length, message.'}\n </Typography>\n {textTargets.length > 1 ? (\n <TextField\n select\n label=\"Field\"\n value={effectiveTarget}\n onChange={(event) => setTargetProp(event.target.value)}\n size=\"small\"\n disabled={busy}\n >\n {textTargets.map((item) => (\n <MenuItem key={item.prop} value={item.prop}>\n {item.label}\n </MenuItem>\n ))}\n </TextField>\n ) : null}\n <TextField\n label=\"Instruction\"\n placeholder=\"e.g. Make it punchier and half as long\"\n value={instruction}\n onChange={(event) => setInstruction(event.target.value)}\n size=\"small\"\n autoFocus\n multiline\n minRows={2}\n disabled={busy}\n onKeyDown={(event) => {\n if (event.key === 'Enter' && (event.metaKey || event.ctrlKey)) {\n event.preventDefault()\n handleConfirm()\n }\n }}\n />\n <AiModelSelector choice={copyModel} disabled={busy} />\n <AiUsageStrip orgId={orgId} />\n </DialogContent>\n <DialogActions>\n <Button disabled={busy} onClick={() => setNode(null)}>\n {'Cancel'}\n </Button>\n <Button\n variant=\"contained\"\n color=\"primary\"\n disabled={!instruction.trim() || busy}\n startIcon={busy ? <CircularProgress size={16} /> : undefined}\n onClick={handleConfirm}\n >\n {busy ? 'Rewriting…' : 'Rewrite'}\n </Button>\n </DialogActions>\n </Dialog>\n <Dialog\n open={sectionOpen}\n onClose={() => (busy ? null : setSectionOpen(false))}\n maxWidth=\"xs\"\n fullWidth\n >\n <DialogTitle>{'Generate a section with AI'}</DialogTitle>\n <DialogContent\n sx={{ display: 'flex', flexDirection: 'column', gap: 2, pt: 1 }}\n >\n <Typography variant=\"body2\" color=\"text.secondary\">\n {'Describe the section — e.g. \"hero with headline, subtext, ' +\n 'and a call-to-action button\" or \"three-column feature grid\".'}\n </Typography>\n <TextField\n label=\"Section\"\n value={sectionPrompt}\n onChange={(event) => setSectionPrompt(event.target.value)}\n size=\"small\"\n autoFocus\n multiline\n minRows={2}\n disabled={busy}\n onKeyDown={(event) => {\n if (event.key === 'Enter' && (event.metaKey || event.ctrlKey)) {\n event.preventDefault()\n handleSectionConfirm()\n }\n }}\n />\n <AiModelSelector choice={sectionModel} disabled={busy} />\n <AiUsageStrip orgId={orgId} />\n </DialogContent>\n <DialogActions>\n <Button disabled={busy} onClick={() => setSectionOpen(false)}>\n {'Cancel'}\n </Button>\n <Button\n variant=\"contained\"\n color=\"primary\"\n disabled={!sectionPrompt.trim() || busy}\n startIcon={busy ? <CircularProgress size={16} /> : undefined}\n onClick={handleSectionConfirm}\n >\n {busy ? 'Generating…' : 'Generate'}\n </Button>\n </DialogActions>\n </Dialog>\n </AiAssistActionsContext.Provider>\n )\n}\nAiAssistProvider.displayName = 'AiAssistProvider'\n\nexport default AiAssistProvider\n"],"names":["Aglyn","checkEntitlement","lockdownRefusalText","parseLockdownRefusal","marketplaceDefinitionToNested","AiAssistActionsContext","useSnackbar","Button","CircularProgress","Dialog","DialogActions","DialogContent","DialogTitle","MenuItem","TextField","Typography","useCallback","useMemo","useState","useUser","authorizedFetch","AiModelSelector","AiUsageStrip","useAiModelChoice","usePublishAiUsageMeter","PERMISSIONS_PENDING","AI_USE_REFUSED","AI_GENERATE_REFUSED","AiAssistProvider","props","textTargets","org","orgReady","orgId","hostId","aiPermissions","children","enqueueSnackbar","data","user","node","setNode","instruction","setInstruction","targetProp","setTargetProp","busy","setBusy","sectionOpen","setSectionOpen","sectionPrompt","setSectionPrompt","copyModel","surface","kind","sectionModel","publishMeter","schema","componentSchema","textEditable","flags","FEATURE_FLAG","DISABLED","ENABLED","attributes","filter","field","component","FieldComponentType","TEXT_FIELD","TEXTAREA","map","prop","String","name","label","handleRewrite","target","loaded","variant","persist","use","effectiveTarget","some","item","handleConfirm","trim","current","canvas","toJSON","nodes","$id","text","response","method","headers","body","JSON","stringify","model","payload","json","meter","locked","status","ok","error","allowDuplicate","updateNodeProps","html","undefined","console","handleGenerateSection","generate","handleSectionConfirm","mode","section","rootId","nested","stamped","stamp","components","getSchema","componentId","pluginId","addNodeFromPreset","type","NodeType","PRESET","rootNode","refusedUse","refusedGenerate","contextValue","onRewrite","onGenerateSection","Provider","value","open","Boolean","onClose","maxWidth","fullWidth","sx","display","flexDirection","gap","pt","color","length","select","onChange","event","size","disabled","placeholder","autoFocus","multiline","minRows","onKeyDown","key","metaKey","ctrlKey","preventDefault","choice","onClick","startIcon","displayName"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GACD;;;AAEA,YAAYA,WAAW,eAAc;AACrC,SACEC,gBAAgB,EAChBC,mBAAmB,EACnBC,oBAAoB,QACf,eAAc;AACrB,SAASC,6BAA6B,QAAQ,mDAAkD;AAChG,SAASC,sBAAsB,QAAQ,iCAA6B;AACpE,SAASC,WAAW,QAAQ,8BAA6B;AACzD,SACEC,MAAM,EACNC,gBAAgB,EAChBC,MAAM,EACNC,aAAa,EACbC,aAAa,EACbC,WAAW,EACXC,QAAQ,EACRC,SAAS,EACTC,UAAU,QACL,gBAAe;AACtB,SAASC,WAAW,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,QAAO;AACtD,SAASC,OAAO,QAAQ,iCAAgC;AACxD,SAASC,eAAe,QAAQ,2CAA0C;AAC1E,SAASC,eAAe,QAAQ,mCAA+B;AAC/D,SAASC,YAAY,QAAQ,gCAA4B;AACzD,SAASC,gBAAgB,QAAQ,2BAAuB;AACxD,SAASC,sBAAsB,QAAQ,0BAAsB;AAuC7D,MAAMC,sBAAsB;AAC5B,MAAMC,iBACJ;AACF,MAAMC,sBACJ;AAEF;;;;;;CAMC,GACD,OAAO,SAASC,iBAAiBC,KA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AO,KAACtC;oCAAiBgJ,MAAM;qCAAS1C;gCACnDsD,SAAS/E;0CAERvC,OAAO,eAAe;;;;;;0BAI7B,MAACrC;gBACCgI,MAAMzF;gBACN2F,SAAS,IAAO7F,OAAO,OAAOG,eAAe;gBAC7C2F,UAAS;gBACTC,SAAS;;kCAET,KAACjI;kCAAa;;kCACd,MAACD;wBACCmI,IAAI;4BAAEC,SAAS;4BAAQC,eAAe;4BAAUC,KAAK;4BAAGC,IAAI;wBAAE;;0CAE9D,KAACnI;gCAAWgE,SAAQ;gCAAQoE,OAAM;0CAC/B,+DACC;;0CAEJ,KAACrI;gCACC6D,OAAM;gCACN6D,OAAOtF;gCACPoG,UAAU,CAACC,QAAUpG,iBAAiBoG,MAAM1E,MAAM,CAAC2D,KAAK;gCACxDgB,MAAK;gCACLG,SAAS;gCACTC,SAAS;gCACTC,SAAS;gCACTJ,UAAU3G;gCACVgH,WAAW,CAACP;oCACV,IAAIA,MAAMQ,GAAG,KAAK,WAAYR,CAAAA,MAAMS,OAAO,IAAIT,MAAMU,OAAO,AAAD,GAAI;wCAC7DV,MAAMW,cAAc;wCACpBhD;oCACF;gCACF;;0CAEF,KAAC7F;gCAAgB8I,QAAQ5G;gCAAckG,UAAU3G;;0CACjD,KAACxB;gCAAaW,OAAOA;;;;kCAEvB,MAACvB;;0CACC,KAACH;gCAAOkJ,UAAU3G;gCAAMsH,SAAS,IAAMnH,eAAe;0CACnD;;0CAEH,KAAC1C;gCACCwE,SAAQ;gCACRoE,OAAM;gCACNM,UAAU,CAACvG,cAAcoC,IAAI,MAAMxC;gCACnCuH,WAAWvH,qBAAO,KAACtC;oCAAiBgJ,MAAM;qCAAS1C;gCACnDsD,SAASlD;0CAERpE,OAAO,gBAAgB;;;;;;;;AAMpC;AACAlB,iBAAiB0I,WAAW,GAAG;AAE/B,eAAe1I,iBAAgB"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/ai/src/lib/components/ai-assist-provider.component.tsx"],"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'use client'\n\nimport * as Aglyn from '@aglyn/aglyn'\nimport {\n checkEntitlement,\n lockdownRefusalText,\n parseLockdownRefusal,\n} from '@aglyn/aglyn'\nimport { portableDefinitionToNested } from '@aglyn/aglyn/app-utils/node-definition-sanitizer'\nimport { AiAssistActionsContext } from './ai-assist-actions-context'\nimport { useSnackbar } from '@aglyn/shared-ui-snackstack'\nimport {\n Button,\n CircularProgress,\n Dialog,\n DialogActions,\n DialogContent,\n DialogTitle,\n MenuItem,\n TextField,\n Typography,\n} from '@mui/material'\nimport { useCallback, useMemo, useState } from 'react'\nimport { useUser } from '@aglyn/tenant-feature-instance'\nimport { authorizedFetch } from '@aglyn/shared-util-http/authorized-token'\nimport { AiModelSelector } from './ai-model-selector.component'\nimport { AiUsageStrip } from './ai-usage-strip.component'\nimport { useAiModelChoice } from './use-ai-model-choice'\nimport { usePublishAiUsageMeter } from './use-ai-usage-meter'\n\n\nexport interface AiAssistProviderProps {\n /** Org billing doc for the entitlement gate (mounted by the shell). */\n org?: unknown\n /**\n * True once `org` is a trustworthy answer (AGL-1380). The shell mounts\n * this provider above the whole console route tree, so it cannot hold its\n * render until the billing doc settles the way the plugin-page route does\n * — and an undefined `org` is not \"unknown\" to `checkEntitlement`, it is\n * the free tier. Without this flag the gates below told a Pro org that AI\n * assist is not on its plan for as long as the read was in flight.\n */\n orgReady?: boolean\n /**\n * The org every assist call is metered against (AGL-2073). The route no\n * longer resolves it from the signed-in user — a user with one paid org was\n * getting assist on all of their free ones, and their spend was landing on\n * whichever org the server happened to resolve.\n */\n orgId?: string\n /**\n * The site the canvas belongs to (AGL-2927), sent with every assist call\n * so the door can decide a site collaborator's permission on THAT site.\n * Null off a host route, where there is no canvas to assist on.\n */\n hostId?: string | null\n /**\n * The reader's AI verdict, resolved by the shell (AGL-2927). The gates\n * below HOLD until `loaded` — a door opened on a pending answer would\n * spend the workspace's credits on a permission nobody has confirmed —\n * and a refused key removes its callback from the context, so the\n * designer draws no control for it. Omitted, the answer is pending.\n */\n aiPermissions?: { loaded: boolean; use: boolean; generate: boolean }\n children?: JSX.Children\n}\n\nconst PERMISSIONS_PENDING = 'Checking your permissions — try again in a moment'\nconst AI_USE_REFUSED =\n 'Your role does not include AI assistance — ask an organization admin'\nconst AI_GENERATE_REFUSED =\n 'Your role does not include AI generation — ask an organization admin'\n\n/**\n * Console-side AI copy assist (AGL-89): provides the designer's \"Rewrite\n * with AI\" callback, hosts the instruction dialog, and calls the assist API\n * (which 501-degrades when no AI provider is configured). The commit\n * spreads the node's current props — `updateNodeProps` REPLACES the props\n * object — and clears any stale rich-text `html` so the new text renders.\n */\nexport function AiAssistProvider(props: AiAssistProviderProps) {\n const org = props.org\n const orgReady = props.orgReady\n const orgId = props.orgId\n const hostId = props.hostId ?? null\n const aiPermissions = props.aiPermissions\n const { children } = props\n const { enqueueSnackbar } = useSnackbar()\n const { data: user } = useUser()\n const [node, setNode] = useState<Aglyn.NodeSchema<any> | null>(null)\n const [instruction, setInstruction] = useState('')\n // Rewrite target (AGL-130): 'children' for text-editable elements, or\n // any text attribute the element's schema declares (alt text, labels…).\n const [targetProp, setTargetProp] = useState('children')\n const [busy, setBusy] = useState(false)\n // Generate section (AGL-169).\n const [sectionOpen, setSectionOpen] = useState(false)\n const [sectionPrompt, setSectionPrompt] = useState('')\n // The model switch and the usage strip in both dialogs (AGL-2942). Each\n // dialog remembers its own pick; one envelope store serves both strips\n // and the assistant panel's.\n const copyModel = useAiModelChoice({ orgId, hostId, surface: 'copy', kind: 'copy.element' })\n const sectionModel = useAiModelChoice({\n orgId,\n hostId,\n surface: 'section',\n kind: 'copy.section',\n })\n const publishMeter = usePublishAiUsageMeter(orgId)\n\n const textTargets = useMemo(() => {\n const schema = node?.componentSchema\n const textEditable =\n ((schema?.flags?.textEditable ?? Aglyn.FEATURE_FLAG.DISABLED) &\n Aglyn.FEATURE_FLAG.ENABLED) !==\n 0\n const attributes = (schema?.attributes ?? [])\n .filter(\n (field: any) =>\n field.component === Aglyn.FieldComponentType.TEXT_FIELD ||\n field.component === Aglyn.FieldComponentType.TEXTAREA,\n )\n .map((field: any) => ({\n prop: String(field.name),\n label: String(field.label ?? field.name),\n }))\n return textEditable\n ? [{ prop: 'children', label: 'Element text' }, ...attributes]\n : attributes\n }, [node])\n\n const handleRewrite = useCallback(\n (target: Aglyn.NodeSchema<any>) => {\n // The permission first (AGL-2927): it is a fact about the reader, and\n // pending asserts nothing here either. The refusal is unreachable\n // through the designer — a refused key publishes no callback — and\n // stands for any other caller of the context.\n if (!aiPermissions?.loaded) {\n return void enqueueSnackbar(PERMISSIONS_PENDING, {\n variant: 'info',\n persist: false,\n })\n }\n if (!aiPermissions.use) {\n return void enqueueSnackbar(AI_USE_REFUSED, {\n variant: 'warning',\n persist: false,\n })\n }\n // AGL-1380: pending asserts nothing. See `orgReady` on the props.\n if (!orgReady) {\n return void enqueueSnackbar(\n 'Checking your plan — try again in a moment',\n { variant: 'info', persist: false },\n )\n }\n if (!checkEntitlement(org as never, 'aiAssist')) {\n return void enqueueSnackbar(\n 'AI assist requires a Pro plan — see Billing to upgrade',\n { variant: 'warning', persist: false },\n )\n }\n setInstruction('')\n setTargetProp('children')\n setNode(target)\n },\n [org, orgReady, aiPermissions, enqueueSnackbar],\n )\n\n // Keep the target valid for the selected element.\n const effectiveTarget = textTargets.some((item) => item.prop === targetProp)\n ? targetProp\n : (textTargets[0]?.prop ?? 'children')\n\n const handleConfirm = useCallback(async () => {\n if (!node || !instruction.trim() || busy) return\n setBusy(true)\n try {\n const current = (Aglyn.canvas.toJSON().nodes as Record<string, any>)[\n node.$id\n ]\n const text =\n typeof current?.props?.[effectiveTarget] === 'string'\n ? (current.props[effectiveTarget] as string)\n : ''\n const response = await authorizedFetch(user, '/api/ai/assist', {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({\n orgId,\n hostId,\n text,\n instruction: instruction.trim(),\n ...(copyModel.model ? { model: copyModel.model } : {}),\n }),\n })\n const payload = await response.json()\n publishMeter(payload?.meter)\n // An ai-assist feature lockdown (AGL-1510/1532) reads as a pause, not\n // as \"AI request failed\" — a provider incident or a cost runaway is\n // something WE turned off, and saying so keeps the user's content out\n // of the story.\n const locked = parseLockdownRefusal(response.status, payload)\n if (locked) {\n return void enqueueSnackbar(lockdownRefusalText(locked), {\n variant: 'warning',\n persist: true,\n })\n }\n if (response.status === 501) {\n return void enqueueSnackbar(\n 'AI assist is not configured on this deployment',\n { variant: 'info', persist: false },\n )\n }\n if (!response.ok || !payload?.text) {\n return void enqueueSnackbar(payload?.error ?? 'AI request failed', {\n variant: 'error',\n allowDuplicate: true,\n })\n }\n Aglyn.canvas.updateNodeProps(node, {\n ...current?.props,\n [effectiveTarget]: payload.text,\n // Rich-text elements render `html` over `children`; drop it so the\n // rewrite is what shows (the user can re-format inline afterwards).\n ...(effectiveTarget === 'children' ? { html: undefined } : {}),\n })\n setNode(null)\n enqueueSnackbar('Text rewritten — undo restores the original', {\n variant: 'success',\n persist: false,\n })\n } catch (error) {\n console.error(error)\n enqueueSnackbar('An error has occurred', {\n variant: 'error',\n allowDuplicate: true,\n })\n } finally {\n setBusy(false)\n }\n }, [\n node,\n instruction,\n busy,\n user,\n effectiveTarget,\n orgId,\n hostId,\n copyModel.model,\n publishMeter,\n enqueueSnackbar,\n ])\n\n const handleGenerateSection = useCallback(() => {\n // The permission first (AGL-2927) — a section is a generation, so this\n // door sells under `ai.generate`; see `handleRewrite`.\n if (!aiPermissions?.loaded) {\n return void enqueueSnackbar(PERMISSIONS_PENDING, {\n variant: 'info',\n persist: false,\n })\n }\n if (!aiPermissions.generate) {\n return void enqueueSnackbar(AI_GENERATE_REFUSED, {\n variant: 'warning',\n persist: false,\n })\n }\n // AGL-1380: same gate as `handleRewrite`.\n if (!orgReady) {\n return void enqueueSnackbar('Checking your plan — try again in a moment', {\n variant: 'info',\n persist: false,\n })\n }\n if (!checkEntitlement(org as never, 'aiAssist')) {\n return void enqueueSnackbar(\n 'AI assist requires a Pro plan — see Billing to upgrade',\n { variant: 'warning', persist: false },\n )\n }\n setSectionPrompt('')\n setSectionOpen(true)\n }, [org, orgReady, aiPermissions, enqueueSnackbar])\n\n const handleSectionConfirm = useCallback(async () => {\n if (!sectionPrompt.trim() || busy) return\n setBusy(true)\n try {\n const response = await authorizedFetch(user, '/api/ai/assist', {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({\n orgId,\n hostId,\n mode: 'section',\n instruction: sectionPrompt.trim(),\n ...(sectionModel.model ? { model: sectionModel.model } : {}),\n }),\n })\n const payload = await response.json()\n publishMeter(payload?.meter)\n // Same pause notice on the section-generation door (AGL-1532).\n const locked = parseLockdownRefusal(response.status, payload)\n if (locked) {\n return void enqueueSnackbar(lockdownRefusalText(locked), {\n variant: 'warning',\n persist: true,\n })\n }\n if (response.status === 501) {\n return void enqueueSnackbar(\n 'AI assist is not configured on this deployment',\n { variant: 'info', persist: false },\n )\n }\n if (!response.ok || !payload?.section?.rootId) {\n return void enqueueSnackbar(payload?.error ?? 'AI request failed', {\n variant: 'error',\n allowDuplicate: true,\n })\n }\n const nested = portableDefinitionToNested(\n payload.section.rootId,\n payload.section.nodes,\n )\n if (!nested) {\n return void enqueueSnackbar('AI returned an empty section', {\n variant: 'error',\n allowDuplicate: true,\n })\n }\n // Graft through the preset path: ids regenerate, history is saved,\n // and the subtree lands at the end of the canvas root.\n const stamped = (function stamp(node: any): any {\n const schema = Aglyn.components.getSchema(node.componentId)\n return {\n ...node,\n ...(schema?.pluginId ? { pluginId: schema.pluginId } : {}),\n nodes: (node.nodes ?? []).map(stamp),\n }\n })(nested)\n Aglyn.canvas.addNodeFromPreset(\n { type: Aglyn.NodeType.PRESET, data: stamped } as any,\n Aglyn.canvas.rootNode as any,\n )\n setSectionOpen(false)\n enqueueSnackbar('Section added — undo removes it', {\n variant: 'success',\n persist: false,\n })\n } catch (error) {\n console.error(error)\n enqueueSnackbar('An error has occurred', {\n variant: 'error',\n allowDuplicate: true,\n })\n } finally {\n setBusy(false)\n }\n }, [\n sectionPrompt,\n busy,\n user,\n orgId,\n hostId,\n sectionModel.model,\n publishMeter,\n enqueueSnackbar,\n ])\n\n // A REFUSED key publishes no callback (AGL-2927): the besigner controls\n // render only when the callback exists, so the refusal removes\n // the button rather than dimming it. A PENDING answer keeps both\n // callbacks, and each holds with a notice when pressed — a control that\n // vanishes and reappears while the read lands is worse than one that is\n // briefly inert (the `useHostRole` argument, applied here).\n const refusedUse = aiPermissions?.loaded === true && !aiPermissions.use\n const refusedGenerate =\n aiPermissions?.loaded === true && !aiPermissions.generate\n const contextValue = useMemo(\n () => ({\n ...(refusedUse ? {} : { onRewrite: handleRewrite }),\n ...(refusedGenerate ? {} : { onGenerateSection: handleGenerateSection }),\n }),\n [handleRewrite, handleGenerateSection, refusedUse, refusedGenerate],\n )\n\n return (\n <AiAssistActionsContext.Provider value={contextValue}>\n {children}\n <Dialog\n open={Boolean(node)}\n onClose={() => (busy ? null : setNode(null))}\n maxWidth=\"xs\"\n fullWidth\n >\n <DialogTitle>{'Rewrite with AI'}</DialogTitle>\n <DialogContent\n sx={{ display: 'flex', flexDirection: 'column', gap: 2, pt: 1 }}\n >\n <Typography variant=\"body2\" color=\"text.secondary\">\n {'Describe how the text should change — tone, length, message.'}\n </Typography>\n {textTargets.length > 1 ? (\n <TextField\n select\n label=\"Field\"\n value={effectiveTarget}\n onChange={(event) => setTargetProp(event.target.value)}\n size=\"small\"\n disabled={busy}\n >\n {textTargets.map((item) => (\n <MenuItem key={item.prop} value={item.prop}>\n {item.label}\n </MenuItem>\n ))}\n </TextField>\n ) : null}\n <TextField\n label=\"Instruction\"\n placeholder=\"e.g. Make it punchier and half as long\"\n value={instruction}\n onChange={(event) => setInstruction(event.target.value)}\n size=\"small\"\n autoFocus\n multiline\n minRows={2}\n disabled={busy}\n onKeyDown={(event) => {\n if (event.key === 'Enter' && (event.metaKey || event.ctrlKey)) {\n event.preventDefault()\n handleConfirm()\n }\n }}\n />\n <AiModelSelector choice={copyModel} disabled={busy} />\n <AiUsageStrip orgId={orgId} />\n </DialogContent>\n <DialogActions>\n <Button disabled={busy} onClick={() => setNode(null)}>\n {'Cancel'}\n </Button>\n <Button\n variant=\"contained\"\n color=\"primary\"\n disabled={!instruction.trim() || busy}\n startIcon={busy ? <CircularProgress size={16} /> : undefined}\n onClick={handleConfirm}\n >\n {busy ? 'Rewriting…' : 'Rewrite'}\n </Button>\n </DialogActions>\n </Dialog>\n <Dialog\n open={sectionOpen}\n onClose={() => (busy ? null : setSectionOpen(false))}\n maxWidth=\"xs\"\n fullWidth\n >\n <DialogTitle>{'Generate a section with AI'}</DialogTitle>\n <DialogContent\n sx={{ display: 'flex', flexDirection: 'column', gap: 2, pt: 1 }}\n >\n <Typography variant=\"body2\" color=\"text.secondary\">\n {'Describe the section — e.g. \"hero with headline, subtext, ' +\n 'and a call-to-action button\" or \"three-column feature grid\".'}\n </Typography>\n <TextField\n label=\"Section\"\n value={sectionPrompt}\n onChange={(event) => setSectionPrompt(event.target.value)}\n size=\"small\"\n autoFocus\n multiline\n minRows={2}\n disabled={busy}\n onKeyDown={(event) => {\n if (event.key === 'Enter' && (event.metaKey || event.ctrlKey)) {\n event.preventDefault()\n handleSectionConfirm()\n }\n }}\n />\n <AiModelSelector choice={sectionModel} disabled={busy} />\n <AiUsageStrip orgId={orgId} />\n </DialogContent>\n <DialogActions>\n <Button disabled={busy} onClick={() => setSectionOpen(false)}>\n {'Cancel'}\n </Button>\n <Button\n variant=\"contained\"\n color=\"primary\"\n disabled={!sectionPrompt.trim() || busy}\n startIcon={busy ? <CircularProgress size={16} /> : undefined}\n onClick={handleSectionConfirm}\n >\n {busy ? 'Generating…' : 'Generate'}\n </Button>\n </DialogActions>\n </Dialog>\n </AiAssistActionsContext.Provider>\n )\n}\nAiAssistProvider.displayName = 'AiAssistProvider'\n\nexport default AiAssistProvider\n"],"names":["Aglyn","checkEntitlement","lockdownRefusalText","parseLockdownRefusal","portableDefinitionToNested","AiAssistActionsContext","useSnackbar","Button","CircularProgress","Dialog","DialogActions","DialogContent","DialogTitle","MenuItem","TextField","Typography","useCallback","useMemo","useState","useUser","authorizedFetch","AiModelSelector","AiUsageStrip","useAiModelChoice","usePublishAiUsageMeter","PERMISSIONS_PENDING","AI_USE_REFUSED","AI_GENERATE_REFUSED","AiAssistProvider","props","textTargets","org","orgReady","orgId","hostId","aiPermissions","children","enqueueSnackbar","data","user","node","setNode","instruction","setInstruction","targetProp","setTargetProp","busy","setBusy","sectionOpen","setSectionOpen","sectionPrompt","setSectionPrompt","copyModel","surface","kind","sectionModel","publishMeter","schema","componentSchema","textEditable","flags","FEATURE_FLAG","DISABLED","ENABLED","attributes","filter","field","component","FieldComponentType","TEXT_FIELD","TEXTAREA","map","prop","String","name","label","handleRewrite","target","loaded","variant","persist","use","effectiveTarget","some","item","handleConfirm","trim","current","canvas","toJSON","nodes","$id","text","response","method","headers","body","JSON","stringify","model","payload","json","meter","locked","status","ok","error","allowDuplicate","updateNodeProps","html","undefined","console","handleGenerateSection","generate","handleSectionConfirm","mode","section","rootId","nested","stamped","stamp","components","getSchema","componentId","pluginId","addNodeFromPreset","type","NodeType","PRESET","rootNode","refusedUse","refusedGenerate","contextValue","onRewrite","onGenerateSection","Provider","value","open","Boolean","onClose","maxWidth","fullWidth","sx","display","flexDirection","gap","pt","color","length","select","onChange","event","size","disabled","placeholder","autoFocus","multiline","minRows","onKeyDown","key","metaKey","ctrlKey","preventDefault","choice","onClick","startIcon","displayName"],"mappings":"AAAA;;;;;;;;;;;;;;;CA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TC,SAAS;gCACTC,SAAS;gCACTJ,UAAU3G;gCACVgH,WAAW,CAACP;oCACV,IAAIA,MAAMQ,GAAG,KAAK,WAAYR,CAAAA,MAAMS,OAAO,IAAIT,MAAMU,OAAO,AAAD,GAAI;wCAC7DV,MAAMW,cAAc;wCACpBhD;oCACF;gCACF;;0CAEF,KAAC7F;gCAAgB8I,QAAQ5G;gCAAckG,UAAU3G;;0CACjD,KAACxB;gCAAaW,OAAOA;;;;kCAEvB,MAACvB;;0CACC,KAACH;gCAAOkJ,UAAU3G;gCAAMsH,SAAS,IAAMnH,eAAe;0CACnD;;0CAEH,KAAC1C;gCACCwE,SAAQ;gCACRoE,OAAM;gCACNM,UAAU,CAACvG,cAAcoC,IAAI,MAAMxC;gCACnCuH,WAAWvH,qBAAO,KAACtC;oCAAiBgJ,MAAM;qCAAS1C;gCACnDsD,SAASlD;0CAERpE,OAAO,gBAAgB;;;;;;;;AAMpC;AACAlB,iBAAiB0I,WAAW,GAAG;AAE/B,eAAe1I,iBAAgB"}
|
|
@@ -59,9 +59,9 @@ export const AI_BRIEF_COPY = {
|
|
|
59
59
|
title: 'Describe a layout',
|
|
60
60
|
briefLabel: 'What should the layout hold?',
|
|
61
61
|
placeholder: 'A header with our name and links to Services, About and Contact, and a footer with ' + 'our address and opening hours',
|
|
62
|
-
next: 'A plan comes first, and nothing is built until you confirm it. The layout links your ' + '
|
|
62
|
+
next: 'A plan comes first, and nothing is built until you confirm it. The layout links your ' + 'pages, and places your navigation or menu component when the site has one.',
|
|
63
63
|
submit: 'Plan the layout',
|
|
64
|
-
started: 'The layout is being planned. Open AI jobs in the Assist panel to review the plan and ' + 'confirm it. The layout is built as a draft, and no
|
|
64
|
+
started: 'The layout is being planned. Open AI jobs in the Assist panel to review the plan and ' + 'confirm it. The layout is built as a draft, and no page uses it until you assign it.',
|
|
65
65
|
failed: 'The layout could not be started. Try again.'
|
|
66
66
|
},
|
|
67
67
|
form: {
|
|
@@ -70,7 +70,7 @@ export const AI_BRIEF_COPY = {
|
|
|
70
70
|
placeholder: 'A quote request form for a roofing company, asking what needs fixing and the best ' + 'time to call',
|
|
71
71
|
next: 'A plan comes first, and nothing is built until you confirm it. The form’s fields, its ' + 'marketing consent and where each submission goes are planned together.',
|
|
72
72
|
submit: 'Plan the form',
|
|
73
|
-
started: 'The form is being planned. Open AI jobs in the Assist panel to review the plan and ' + 'confirm it. The form is built as a draft, and it collects nothing until you place it ' + 'on a
|
|
73
|
+
started: 'The form is being planned. Open AI jobs in the Assist panel to review the plan and ' + 'confirm it. The form is built as a draft, and it collects nothing until you place it ' + 'on a page.',
|
|
74
74
|
failed: 'The form could not be started. Try again.'
|
|
75
75
|
},
|
|
76
76
|
component: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../libs/plugins/ai/src/lib/components/ai-brief-dialog.component.tsx"],"sourcesContent":["'use client'\n\n/**\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 { lockdownRefusalText, parseLockdownRefusal } from '@aglyn/aglyn'\nimport { authorizedFetch } from '@aglyn/shared-util-http/authorized-token'\nimport {\n Alert,\n Button,\n Chip,\n Dialog,\n DialogActions,\n DialogContent,\n DialogTitle,\n Stack,\n TextField,\n Typography,\n} from '@mui/material'\nimport { useCallback, useEffect, useRef, useState } from 'react'\nimport type { AiJobKind } from '../model/ai-jobs.types'\nimport { AI_PAGE_TYPES, type AiPageType } from '../model/ai-page-job'\nimport {\n AI_TEMPLATE_SUBJECTS,\n parseAiTemplateJobInputs,\n type AiTemplateSubject,\n} from '../model/ai-template-subjects'\nimport { AiTemplateCollectionField } from './ai-template-collection-field.component'\n\n/**\n * The brief dialog every \"Describe it\" opens (AGL-2907, AGL-3043, AGL-3051):\n * a page from the Screens page and from the Assist panel's AI jobs, a page\n * template from Templates, a layout from Layouts, a form from Forms and a\n * reusable component from Components.\n *\n * One text box, and whatever the kind's door reads beside it, start one job of\n * that kind: a page's optional page type; a template's subject and, for a\n * collection entry's page, its collection. A layout, a form and a component\n * read nothing but the brief and the site. The job plans first and waits in\n * AI jobs, where the member confirms the plan and opens the draft once it is\n * built; nothing here builds or writes anything.\n */\n\n/** The longest brief a job admits. */\nconst BRIEF_MAX_CHARS = 4_000\n\n/** The job kinds a member describes from a console page. */\nexport type AiBriefKind = Extract<\n AiJobKind,\n 'page' | 'template' | 'layout' | 'form' | 'component'\n>\n\n/** What the dialog says for one kind. */\nexport interface AiBriefCopy {\n title: string\n /** The brief box's label. */\n briefLabel: string\n placeholder: string\n /** What happens after the member starts the job, under the fields. */\n next: string\n /** The action that starts the job. */\n submit: string\n /** What the dialog says once the job exists. */\n started: string\n /** What it says when the door gave no reason, or could not be reached. */\n failed: string\n}\n\nexport const AI_BRIEF_COPY: Readonly<Record<AiBriefKind, AiBriefCopy>> = {\n page: {\n title: 'Describe a page',\n briefLabel: 'What is the page for?',\n placeholder:\n 'A landing page for our spring roof inspection offer, with the quote request form',\n next:\n 'A plan comes first, and nothing is built until you confirm it. The page uses your ' +\n 'theme and what the site already has, and the plan lists anything the job builds first.',\n submit: 'Plan the page',\n started:\n 'The page is being planned. Open AI jobs in the Assist panel to review the plan and ' +\n 'confirm it. The page is built as an unpublished draft.',\n failed: 'The page could not be started. Try again.',\n },\n template: {\n title: 'Describe a page template',\n briefLabel: 'What should each page show?',\n placeholder:\n 'A page for each of our team members: their name and photo, their role, a short ' +\n 'biography and a way to get in touch',\n next:\n 'A plan comes first, and nothing is built until you confirm it. What changes from one ' +\n 'page to the next, such as a name or a photo, is filled in from each record rather ' +\n 'than typed.',\n submit: 'Plan the template',\n started:\n 'The template is being planned. Open AI jobs in the Assist panel to review the plan ' +\n 'and confirm it. The template is built as a draft in your library, and nothing on ' +\n 'your site uses it until you do.',\n failed: 'The template could not be started. Try again.',\n },\n layout: {\n title: 'Describe a layout',\n briefLabel: 'What should the layout hold?',\n placeholder:\n 'A header with our name and links to Services, About and Contact, and a footer with ' +\n 'our address and opening hours',\n next:\n 'A plan comes first, and nothing is built until you confirm it. The layout links your ' +\n 'screens, and places your navigation or menu component when the site has one.',\n submit: 'Plan the layout',\n started:\n 'The layout is being planned. Open AI jobs in the Assist panel to review the plan and ' +\n 'confirm it. The layout is built as a draft, and no screen uses it until you assign it.',\n failed: 'The layout could not be started. Try again.',\n },\n form: {\n title: 'Describe a form',\n briefLabel: 'What is the form for?',\n placeholder:\n 'A quote request form for a roofing company, asking what needs fixing and the best ' +\n 'time to call',\n next:\n 'A plan comes first, and nothing is built until you confirm it. The form’s fields, its ' +\n 'marketing consent and where each submission goes are planned together.',\n submit: 'Plan the form',\n started:\n 'The form is being planned. Open AI jobs in the Assist panel to review the plan and ' +\n 'confirm it. The form is built as a draft, and it collects nothing until you place it ' +\n 'on a screen.',\n failed: 'The form could not be started. Try again.',\n },\n component: {\n title: 'Describe a reusable component',\n briefLabel: 'What should the component show?',\n placeholder:\n 'A testimonial card with the customer’s name, their role, their quote and a photo',\n next:\n 'A plan comes first, and nothing is built until you confirm it. What each page can ' +\n 'change, such as a name or a photo, becomes a property of the component.',\n submit: 'Plan the component',\n started:\n 'The component is being planned. Open AI jobs in the Assist panel to review the plan ' +\n 'and confirm it. The component is built as a draft, and no page shows it until you ' +\n 'insert it.',\n failed: 'The component could not be started. Try again.',\n },\n}\n\n/** Each template subject as its chip names it: what one page is drawn for. */\nexport const AI_TEMPLATE_SUBJECT_LABELS: Readonly<Record<AiTemplateSubject, string>> = {\n entry: 'Collection entry',\n product: 'Product',\n author: 'Author',\n}\n\n/** What a member picked beside the brief; each kind reads only its own. */\nexport interface AiBriefChoice {\n /** A page's type, or `null` for none. */\n pageType: AiPageType | null\n /** What a template's pages are drawn for, or `null` until one is picked. */\n subject: AiTemplateSubject | null\n /** A collection entry template's collection, or `null` until one is picked. */\n collectionId: string | null\n}\n\nexport const AI_BRIEF_NO_CHOICE: AiBriefChoice = {\n pageType: null,\n subject: null,\n collectionId: null,\n}\n\n/**\n * The job's `inputs` for what the member picked, or `null` while the kind's\n * door would refuse them.\n *\n * A template's are read by the parser its door reads, so the dialog cannot\n * send a subject the door does not know or an entry page with no collection.\n * A page's type is optional. A layout, a form and a component read no inputs\n * at all (AGL-2909, AGL-2913, AGL-2908), so theirs are empty.\n */\nexport function aiBriefJobInputs(\n kind: AiBriefKind,\n choice: AiBriefChoice,\n): Record<string, string> | null {\n if (kind === 'page') return choice.pageType ? { pageType: choice.pageType } : {}\n if (kind === 'template') {\n const inputs = parseAiTemplateJobInputs({\n subject: choice.subject,\n collectionId: choice.collectionId,\n })\n if (typeof inputs === 'string') return null\n return inputs.collectionId\n ? { subject: inputs.subject, collectionId: inputs.collectionId }\n : { subject: inputs.subject }\n }\n return {}\n}\n\nexport interface AiBriefDialogProps {\n /** The job the brief starts. */\n kind: AiBriefKind\n open: boolean\n onClose: () => void\n orgId: string | undefined\n hostId: string\n /** Who is signed in, whose token the request carries. */\n user: Parameters<typeof authorizedFetch>[0]\n}\n\nexport function AiBriefDialog({ kind, open, onClose, orgId, hostId, user }: AiBriefDialogProps) {\n const copy = AI_BRIEF_COPY[kind]\n // Held in a ref so the request reads WHO is signed in, and nothing keys on\n // the identity of the object that says so.\n const userRef = useRef(user)\n userRef.current = user\n const [brief, setBrief] = useState('')\n const [choice, setChoice] = useState<AiBriefChoice>(AI_BRIEF_NO_CHOICE)\n const [busy, setBusy] = useState(false)\n const [notice, setNotice] = useState<string | null>(null)\n const [started, setStarted] = useState(false)\n\n useEffect(() => {\n if (!open) return\n setNotice(null)\n setStarted(false)\n }, [open])\n\n const pick = useCallback(\n (patch: Partial<AiBriefChoice>) => setChoice((current) => ({ ...current, ...patch })),\n [],\n )\n const ready = aiBriefJobInputs(kind, choice) !== null\n\n const start = useCallback(async () => {\n const inputs = aiBriefJobInputs(kind, choice)\n if (!orgId || !brief.trim() || !inputs) return\n setBusy(true)\n setNotice(null)\n try {\n const response = await authorizedFetch(userRef.current, '/api/ai/jobs', {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({ orgId, hostId, kind, brief: brief.trim(), inputs }),\n })\n const payload = await response.json().catch(() => null)\n if (!response.ok) {\n const locked = parseLockdownRefusal(response.status, payload)\n setNotice(locked ? lockdownRefusalText(locked) : String(payload?.error ?? copy.failed))\n return\n }\n setStarted(true)\n setBrief('')\n setChoice(AI_BRIEF_NO_CHOICE)\n } catch {\n setNotice(copy.failed)\n } finally {\n setBusy(false)\n }\n }, [orgId, hostId, kind, brief, choice, copy])\n\n return (\n <Dialog open={open} onClose={busy ? undefined : onClose} fullWidth maxWidth=\"sm\">\n <DialogTitle>{copy.title}</DialogTitle>\n <DialogContent>\n {started ? (\n <Alert severity=\"success\">{copy.started}</Alert>\n ) : (\n <Stack spacing={2} sx={{ pt: 1 }}>\n <TextField\n label={copy.briefLabel}\n placeholder={copy.placeholder}\n multiline\n minRows={4}\n value={brief}\n onChange={(event) => setBrief(event.target.value.slice(0, BRIEF_MAX_CHARS))}\n helperText={`${brief.length.toLocaleString('en-US')} / ${BRIEF_MAX_CHARS.toLocaleString('en-US')}`}\n disabled={busy}\n autoFocus\n />\n {kind === 'page' ? (\n <ChipGroup\n id=\"ai-page-type-label\"\n label=\"Page type (optional)\"\n options={AI_PAGE_TYPES.map((type) => ({ id: type.id, label: type.label }))}\n value={choice.pageType}\n // Optional: pressing the pressed type again sends none.\n onPress={(id) =>\n pick({ pageType: choice.pageType === id ? null : (id as AiPageType) })\n }\n disabled={busy}\n />\n ) : null}\n {kind === 'template' ? (\n <>\n <ChipGroup\n id=\"ai-template-subject-label\"\n // Marked required because it IS (AGL-3143 §12): \"Plan the\n // template\" stays disabled until one is picked, and the page\n // dialog's chip group beside it reads \"(optional)\" — so an\n // unmarked label here read as optional too, and a member who\n // wrote a brief and stopped had nothing telling them why the\n // button would not light.\n label=\"One page for each (required)\"\n options={AI_TEMPLATE_SUBJECTS.map((subject) => ({\n id: subject,\n label: AI_TEMPLATE_SUBJECT_LABELS[subject],\n }))}\n value={choice.subject}\n // Required, so a press picks and never clears.\n onPress={(id) => pick({ subject: id as AiTemplateSubject })}\n disabled={busy}\n />\n {choice.subject === 'entry' ? (\n <AiTemplateCollectionField\n hostId={hostId}\n value={choice.collectionId}\n onChange={(collectionId) => pick({ collectionId })}\n disabled={busy}\n />\n ) : null}\n </>\n ) : null}\n <Typography variant=\"body2\" color=\"text.secondary\">\n {copy.next}\n </Typography>\n {notice ? <Alert severity=\"warning\">{notice}</Alert> : null}\n </Stack>\n )}\n </DialogContent>\n <DialogActions>\n <Button onClick={onClose} disabled={busy}>\n {started ? 'Close' : 'Cancel'}\n </Button>\n {started ? null : (\n <Button\n variant=\"contained\"\n onClick={() => void start()}\n disabled={busy || !orgId || !brief.trim() || !ready}\n >\n {copy.submit}\n </Button>\n )}\n </DialogActions>\n </Dialog>\n )\n}\n\n/** A labeled row of chips, each a toggle button that says whether it is pressed. */\nfunction ChipGroup(props: {\n id: string\n label: string\n options: ReadonlyArray<{ id: string; label: string }>\n value: string | null\n onPress: (id: string) => void\n disabled: boolean\n}) {\n const { id, label, options, value, onPress, disabled } = props\n return (\n <Stack spacing={1}>\n <Typography variant=\"body2\" color=\"text.secondary\" id={id}>\n {label}\n </Typography>\n <Stack\n direction=\"row\"\n useFlexGap\n role=\"group\"\n aria-labelledby={id}\n sx={{ flexWrap: 'wrap', gap: 1 }}\n >\n {options.map((option) => (\n <Chip\n key={option.id}\n label={option.label}\n color={value === option.id ? 'primary' : 'default'}\n variant={value === option.id ? 'filled' : 'outlined'}\n onClick={() => onPress(option.id)}\n aria-pressed={value === option.id}\n disabled={disabled}\n />\n ))}\n </Stack>\n </Stack>\n )\n}\n\nexport default AiBriefDialog\n"],"names":["lockdownRefusalText","parseLockdownRefusal","authorizedFetch","Alert","Button","Chip","Dialog","DialogActions","DialogContent","DialogTitle","Stack","TextField","Typography","useCallback","useEffect","useRef","useState","AI_PAGE_TYPES","AI_TEMPLATE_SUBJECTS","parseAiTemplateJobInputs","AiTemplateCollectionField","BRIEF_MAX_CHARS","AI_BRIEF_COPY","page","title","briefLabel","placeholder","next","submit","started","failed","template","layout","form","component","AI_TEMPLATE_SUBJECT_LABELS","entry","product","author","AI_BRIEF_NO_CHOICE","pageType","subject","collectionId","aiBriefJobInputs","kind","choice","inputs","AiBriefDialog","open","onClose","orgId","hostId","user","copy","userRef","current","brief","setBrief","setChoice","busy","setBusy","notice","setNotice","setStarted","pick","patch","ready","start","trim","response","method","headers","body","JSON","stringify","payload","json","catch","ok","locked","status","String","error","undefined","fullWidth","maxWidth","severity","spacing","sx","pt","label","multiline","minRows","value","onChange","event","target","slice","helperText","length","toLocaleString","disabled","autoFocus","ChipGroup","id","options","map","type","onPress","variant","color","onClick","props","direction","useFlexGap","role","aria-labelledby","flexWrap","gap","option","aria-pressed"],"mappings":"AAAA;;;AAEA;;;;;;;;;;;;;;;CAeC,GAED,SAASA,mBAAmB,EAAEC,oBAAoB,QAAQ,eAAc;AACxE,SAASC,eAAe,QAAQ,2CAA0C;AAC1E,SACEC,KAAK,EACLC,MAAM,EACNC,IAAI,EACJC,MAAM,EACNC,aAAa,EACbC,aAAa,EACbC,WAAW,EACXC,KAAK,EACLC,SAAS,EACTC,UAAU,QACL,gBAAe;AACtB,SAASC,WAAW,EAAEC,SAAS,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,QAAO;AAEhE,SAASC,aAAa,QAAyB,0BAAsB;AACrE,SACEC,oBAAoB,EACpBC,wBAAwB,QAEnB,mCAA+B;AACtC,SAASC,yBAAyB,QAAQ,8CAA0C;AAEpF;;;;;;;;;;;;CAYC,GAED,oCAAoC,GACpC,MAAMC,kBAAkB;AAwBxB,OA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O,EAAEP,QAAQ,EAAE,GAAGW;IACzD,qBACE,MAACtG;QAAM6E,SAAS;;0BACd,KAAC3E;gBAAWiG,SAAQ;gBAAQC,OAAM;gBAAiBN,IAAIA;0BACpDd;;0BAEH,KAAChF;gBACCuG,WAAU;gBACVC,UAAU;gBACVC,MAAK;gBACLC,mBAAiBZ;gBACjBhB,IAAI;oBAAE6B,UAAU;oBAAQC,KAAK;gBAAE;0BAE9Bb,QAAQC,GAAG,CAAC,CAACa,uBACZ,KAAClH;wBAECqF,OAAO6B,OAAO7B,KAAK;wBACnBoB,OAAOjB,UAAU0B,OAAOf,EAAE,GAAG,YAAY;wBACzCK,SAAShB,UAAU0B,OAAOf,EAAE,GAAG,WAAW;wBAC1CO,SAAS,IAAMH,QAAQW,OAAOf,EAAE;wBAChCgB,gBAAc3B,UAAU0B,OAAOf,EAAE;wBACjCH,UAAUA;uBANLkB,OAAOf,EAAE;;;;AAY1B;AAEA,eAAezD,cAAa"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/ai/src/lib/components/ai-brief-dialog.component.tsx"],"sourcesContent":["'use client'\n\n/**\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 { lockdownRefusalText, parseLockdownRefusal } from '@aglyn/aglyn'\nimport { authorizedFetch } from '@aglyn/shared-util-http/authorized-token'\nimport {\n Alert,\n Button,\n Chip,\n Dialog,\n DialogActions,\n DialogContent,\n DialogTitle,\n Stack,\n TextField,\n Typography,\n} from '@mui/material'\nimport { useCallback, useEffect, useRef, useState } from 'react'\nimport type { AiJobKind } from '../model/ai-jobs.types'\nimport { AI_PAGE_TYPES, type AiPageType } from '../model/ai-page-job'\nimport {\n AI_TEMPLATE_SUBJECTS,\n parseAiTemplateJobInputs,\n type AiTemplateSubject,\n} from '../model/ai-template-subjects'\nimport { AiTemplateCollectionField } from './ai-template-collection-field.component'\n\n/**\n * The brief dialog every \"Describe it\" opens (AGL-2907, AGL-3043, AGL-3051):\n * a page from the Screens page and from the Assist panel's AI jobs, a page\n * template from Templates, a layout from Layouts, a form from Forms and a\n * reusable component from Components.\n *\n * One text box, and whatever the kind's door reads beside it, start one job of\n * that kind: a page's optional page type; a template's subject and, for a\n * collection entry's page, its collection. A layout, a form and a component\n * read nothing but the brief and the site. The job plans first and waits in\n * AI jobs, where the member confirms the plan and opens the draft once it is\n * built; nothing here builds or writes anything.\n */\n\n/** The longest brief a job admits. */\nconst BRIEF_MAX_CHARS = 4_000\n\n/** The job kinds a member describes from a console page. */\nexport type AiBriefKind = Extract<\n AiJobKind,\n 'page' | 'template' | 'layout' | 'form' | 'component'\n>\n\n/** What the dialog says for one kind. */\nexport interface AiBriefCopy {\n title: string\n /** The brief box's label. */\n briefLabel: string\n placeholder: string\n /** What happens after the member starts the job, under the fields. */\n next: string\n /** The action that starts the job. */\n submit: string\n /** What the dialog says once the job exists. */\n started: string\n /** What it says when the door gave no reason, or could not be reached. */\n failed: string\n}\n\nexport const AI_BRIEF_COPY: Readonly<Record<AiBriefKind, AiBriefCopy>> = {\n page: {\n title: 'Describe a page',\n briefLabel: 'What is the page for?',\n placeholder:\n 'A landing page for our spring roof inspection offer, with the quote request form',\n next:\n 'A plan comes first, and nothing is built until you confirm it. The page uses your ' +\n 'theme and what the site already has, and the plan lists anything the job builds first.',\n submit: 'Plan the page',\n started:\n 'The page is being planned. Open AI jobs in the Assist panel to review the plan and ' +\n 'confirm it. The page is built as an unpublished draft.',\n failed: 'The page could not be started. Try again.',\n },\n template: {\n title: 'Describe a page template',\n briefLabel: 'What should each page show?',\n placeholder:\n 'A page for each of our team members: their name and photo, their role, a short ' +\n 'biography and a way to get in touch',\n next:\n 'A plan comes first, and nothing is built until you confirm it. What changes from one ' +\n 'page to the next, such as a name or a photo, is filled in from each record rather ' +\n 'than typed.',\n submit: 'Plan the template',\n started:\n 'The template is being planned. Open AI jobs in the Assist panel to review the plan ' +\n 'and confirm it. The template is built as a draft in your library, and nothing on ' +\n 'your site uses it until you do.',\n failed: 'The template could not be started. Try again.',\n },\n layout: {\n title: 'Describe a layout',\n briefLabel: 'What should the layout hold?',\n placeholder:\n 'A header with our name and links to Services, About and Contact, and a footer with ' +\n 'our address and opening hours',\n next:\n 'A plan comes first, and nothing is built until you confirm it. The layout links your ' +\n 'pages, and places your navigation or menu component when the site has one.',\n submit: 'Plan the layout',\n started:\n 'The layout is being planned. Open AI jobs in the Assist panel to review the plan and ' +\n 'confirm it. The layout is built as a draft, and no page uses it until you assign it.',\n failed: 'The layout could not be started. Try again.',\n },\n form: {\n title: 'Describe a form',\n briefLabel: 'What is the form for?',\n placeholder:\n 'A quote request form for a roofing company, asking what needs fixing and the best ' +\n 'time to call',\n next:\n 'A plan comes first, and nothing is built until you confirm it. The form’s fields, its ' +\n 'marketing consent and where each submission goes are planned together.',\n submit: 'Plan the form',\n started:\n 'The form is being planned. Open AI jobs in the Assist panel to review the plan and ' +\n 'confirm it. The form is built as a draft, and it collects nothing until you place it ' +\n 'on a page.',\n failed: 'The form could not be started. Try again.',\n },\n component: {\n title: 'Describe a reusable component',\n briefLabel: 'What should the component show?',\n placeholder:\n 'A testimonial card with the customer’s name, their role, their quote and a photo',\n next:\n 'A plan comes first, and nothing is built until you confirm it. What each page can ' +\n 'change, such as a name or a photo, becomes a property of the component.',\n submit: 'Plan the component',\n started:\n 'The component is being planned. Open AI jobs in the Assist panel to review the plan ' +\n 'and confirm it. The component is built as a draft, and no page shows it until you ' +\n 'insert it.',\n failed: 'The component could not be started. Try again.',\n },\n}\n\n/** Each template subject as its chip names it: what one page is drawn for. */\nexport const AI_TEMPLATE_SUBJECT_LABELS: Readonly<Record<AiTemplateSubject, string>> = {\n entry: 'Collection entry',\n product: 'Product',\n author: 'Author',\n}\n\n/** What a member picked beside the brief; each kind reads only its own. */\nexport interface AiBriefChoice {\n /** A page's type, or `null` for none. */\n pageType: AiPageType | null\n /** What a template's pages are drawn for, or `null` until one is picked. */\n subject: AiTemplateSubject | null\n /** A collection entry template's collection, or `null` until one is picked. */\n collectionId: string | null\n}\n\nexport const AI_BRIEF_NO_CHOICE: AiBriefChoice = {\n pageType: null,\n subject: null,\n collectionId: null,\n}\n\n/**\n * The job's `inputs` for what the member picked, or `null` while the kind's\n * door would refuse them.\n *\n * A template's are read by the parser its door reads, so the dialog cannot\n * send a subject the door does not know or an entry page with no collection.\n * A page's type is optional. A layout, a form and a component read no inputs\n * at all (AGL-2909, AGL-2913, AGL-2908), so theirs are empty.\n */\nexport function aiBriefJobInputs(\n kind: AiBriefKind,\n choice: AiBriefChoice,\n): Record<string, string> | null {\n if (kind === 'page') return choice.pageType ? { pageType: choice.pageType } : {}\n if (kind === 'template') {\n const inputs = parseAiTemplateJobInputs({\n subject: choice.subject,\n collectionId: choice.collectionId,\n })\n if (typeof inputs === 'string') return null\n return inputs.collectionId\n ? { subject: inputs.subject, collectionId: inputs.collectionId }\n : { subject: inputs.subject }\n }\n return {}\n}\n\nexport interface AiBriefDialogProps {\n /** The job the brief starts. */\n kind: AiBriefKind\n open: boolean\n onClose: () => void\n orgId: string | undefined\n hostId: string\n /** Who is signed in, whose token the request carries. */\n user: Parameters<typeof authorizedFetch>[0]\n}\n\nexport function AiBriefDialog({ kind, open, onClose, orgId, hostId, user }: AiBriefDialogProps) {\n const copy = AI_BRIEF_COPY[kind]\n // Held in a ref so the request reads WHO is signed in, and nothing keys on\n // the identity of the object that says so.\n const userRef = useRef(user)\n userRef.current = user\n const [brief, setBrief] = useState('')\n const [choice, setChoice] = useState<AiBriefChoice>(AI_BRIEF_NO_CHOICE)\n const [busy, setBusy] = useState(false)\n const [notice, setNotice] = useState<string | null>(null)\n const [started, setStarted] = useState(false)\n\n useEffect(() => {\n if (!open) return\n setNotice(null)\n setStarted(false)\n }, [open])\n\n const pick = useCallback(\n (patch: Partial<AiBriefChoice>) => setChoice((current) => ({ ...current, ...patch })),\n [],\n )\n const ready = aiBriefJobInputs(kind, choice) !== null\n\n const start = useCallback(async () => {\n const inputs = aiBriefJobInputs(kind, choice)\n if (!orgId || !brief.trim() || !inputs) return\n setBusy(true)\n setNotice(null)\n try {\n const response = await authorizedFetch(userRef.current, '/api/ai/jobs', {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({ orgId, hostId, kind, brief: brief.trim(), inputs }),\n })\n const payload = await response.json().catch(() => null)\n if (!response.ok) {\n const locked = parseLockdownRefusal(response.status, payload)\n setNotice(locked ? lockdownRefusalText(locked) : String(payload?.error ?? copy.failed))\n return\n }\n setStarted(true)\n setBrief('')\n setChoice(AI_BRIEF_NO_CHOICE)\n } catch {\n setNotice(copy.failed)\n } finally {\n setBusy(false)\n }\n }, [orgId, hostId, kind, brief, choice, copy])\n\n return (\n <Dialog open={open} onClose={busy ? undefined : onClose} fullWidth maxWidth=\"sm\">\n <DialogTitle>{copy.title}</DialogTitle>\n <DialogContent>\n {started ? (\n <Alert severity=\"success\">{copy.started}</Alert>\n ) : (\n <Stack spacing={2} sx={{ pt: 1 }}>\n <TextField\n label={copy.briefLabel}\n placeholder={copy.placeholder}\n multiline\n minRows={4}\n value={brief}\n onChange={(event) => setBrief(event.target.value.slice(0, BRIEF_MAX_CHARS))}\n helperText={`${brief.length.toLocaleString('en-US')} / ${BRIEF_MAX_CHARS.toLocaleString('en-US')}`}\n disabled={busy}\n autoFocus\n />\n {kind === 'page' ? (\n <ChipGroup\n id=\"ai-page-type-label\"\n label=\"Page type (optional)\"\n options={AI_PAGE_TYPES.map((type) => ({ id: type.id, label: type.label }))}\n value={choice.pageType}\n // Optional: pressing the pressed type again sends none.\n onPress={(id) =>\n pick({ pageType: choice.pageType === id ? null : (id as AiPageType) })\n }\n disabled={busy}\n />\n ) : null}\n {kind === 'template' ? (\n <>\n <ChipGroup\n id=\"ai-template-subject-label\"\n // Marked required because it IS (AGL-3143 §12): \"Plan the\n // template\" stays disabled until one is picked, and the page\n // dialog's chip group beside it reads \"(optional)\" — so an\n // unmarked label here read as optional too, and a member who\n // wrote a brief and stopped had nothing telling them why the\n // button would not light.\n label=\"One page for each (required)\"\n options={AI_TEMPLATE_SUBJECTS.map((subject) => ({\n id: subject,\n label: AI_TEMPLATE_SUBJECT_LABELS[subject],\n }))}\n value={choice.subject}\n // Required, so a press picks and never clears.\n onPress={(id) => pick({ subject: id as AiTemplateSubject })}\n disabled={busy}\n />\n {choice.subject === 'entry' ? (\n <AiTemplateCollectionField\n hostId={hostId}\n value={choice.collectionId}\n onChange={(collectionId) => pick({ collectionId })}\n disabled={busy}\n />\n ) : null}\n </>\n ) : null}\n <Typography variant=\"body2\" color=\"text.secondary\">\n {copy.next}\n </Typography>\n {notice ? <Alert severity=\"warning\">{notice}</Alert> : null}\n </Stack>\n )}\n </DialogContent>\n <DialogActions>\n <Button onClick={onClose} disabled={busy}>\n {started ? 'Close' : 'Cancel'}\n </Button>\n {started ? null : (\n <Button\n variant=\"contained\"\n onClick={() => void start()}\n disabled={busy || !orgId || !brief.trim() || !ready}\n >\n {copy.submit}\n </Button>\n )}\n </DialogActions>\n </Dialog>\n )\n}\n\n/** A labeled row of chips, each a toggle button that says whether it is pressed. */\nfunction ChipGroup(props: {\n id: string\n label: string\n options: ReadonlyArray<{ id: string; label: string }>\n value: string | null\n onPress: (id: string) => void\n disabled: boolean\n}) {\n const { id, label, options, value, onPress, disabled } = props\n return (\n <Stack spacing={1}>\n <Typography variant=\"body2\" color=\"text.secondary\" id={id}>\n {label}\n </Typography>\n <Stack\n direction=\"row\"\n useFlexGap\n role=\"group\"\n aria-labelledby={id}\n sx={{ flexWrap: 'wrap', gap: 1 }}\n >\n {options.map((option) => (\n <Chip\n key={option.id}\n label={option.label}\n color={value === option.id ? 'primary' : 'default'}\n variant={value === option.id ? 'filled' : 'outlined'}\n onClick={() => onPress(option.id)}\n aria-pressed={value === option.id}\n disabled={disabled}\n />\n ))}\n </Stack>\n </Stack>\n )\n}\n\nexport default AiBriefDialog\n"],"names":["lockdownRefusalText","parseLockdownRefusal","authorizedFetch","Alert","Button","Chip","Dialog","DialogActions","DialogContent","DialogTitle","Stack","TextField","Typography","useCallback","useEffect","useRef","useState","AI_PAGE_TYPES","AI_TEMPLATE_SUBJECTS","parseAiTemplateJobInputs","AiTemplateCollectionField","BRIEF_MAX_CHARS","AI_BRIEF_COPY","page","title","briefLabel","placeholder","next","submit","started","failed","template","layout","form","component","AI_TEMPLATE_SUBJECT_LABELS","entry","product","author","AI_BRIEF_NO_CHOICE","pageType","subject","collectionId","aiBriefJobInputs","kind","choice","inputs","AiBriefDialog","open","onClose","orgId","hostId","user","copy","userRef","current","brief","setBrief","setChoice","busy","setBusy","notice","setNotice","setStarted","pick","patch","ready","start","trim","response","method","headers","body","JSON","stringify","payload","json","catch","ok","locked","status","String","error","undefined","fullWidth","maxWidth","severity","spacing","sx","pt","label","multiline","minRows","value","onChange","event","target","slice","helperText","length","toLocaleString","disabled","autoFocus","ChipGroup","id","options","map","type","onPress","variant","color","onClick","props","direction","useFlexGap","role","aria-labelledby","flexWrap","gap","option","aria-pressed"],"mappings":"AAAA;;;AAEA;;;;;;;;;;;;;;;CAeC,GAED,SAASA,mBAAmB,EAAEC,oBAAoB,QAAQ,eAAc;AACxE,SAASC,eAAe,QAAQ,2CAA0C;AAC1E,SACEC,KAAK,EACLC,MAAM,EACNC,IAAI,EACJC,MAAM,EACNC,aAAa,EACbC,aAAa,EACbC,WAAW,EACXC,KAAK,EACLC,SAAS,EACTC,UAAU,QACL,gBAAe;AACtB,SAASC,WAAW,EAAEC,SAAS,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,QAAO;AAEhE,SAASC,aAAa,QAAyB,0BAAsB;AACrE,SACEC,oBAAoB,EACp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AAM;;;;;;AAMxB;AAEA,kFAAkF,GAClF,SAAS2E,UAAUS,KAOlB;IACC,MAAM,EAAER,EAAE,EAAEd,KAAK,EAAEe,OAAO,EAAEZ,KAAK,EAAEe,OAAO,EAAEP,QAAQ,EAAE,GAAGW;IACzD,qBACE,MAACtG;QAAM6E,SAAS;;0BACd,KAAC3E;gBAAWiG,SAAQ;gBAAQC,OAAM;gBAAiBN,IAAIA;0BACpDd;;0BAEH,KAAChF;gBACCuG,WAAU;gBACVC,UAAU;gBACVC,MAAK;gBACLC,mBAAiBZ;gBACjBhB,IAAI;oBAAE6B,UAAU;oBAAQC,KAAK;gBAAE;0BAE9Bb,QAAQC,GAAG,CAAC,CAACa,uBACZ,KAAClH;wBAECqF,OAAO6B,OAAO7B,KAAK;wBACnBoB,OAAOjB,UAAU0B,OAAOf,EAAE,GAAG,YAAY;wBACzCK,SAAShB,UAAU0B,OAAOf,EAAE,GAAG,WAAW;wBAC1CO,SAAS,IAAMH,QAAQW,OAAOf,EAAE;wBAChCgB,gBAAc3B,UAAU0B,OAAOf,EAAE;wBACjCH,UAAUA;uBANLkB,OAAOf,EAAE;;;;AAY1B;AAEA,eAAezD,cAAa"}
|
|
@@ -97,7 +97,7 @@ const liftText = (value)=>value === null ? '—' : `${value >= 0 ? '+' : ''}${va
|
|
|
97
97
|
});
|
|
98
98
|
}
|
|
99
99
|
/** Where a proposed variant's copy lands, said before the person presses the button. */ export function aiExperimentApplyCopy(target) {
|
|
100
|
-
return target === 'email' ? 'Each variant above takes its name, subject and body. Nothing is saved until you save the experiment.' : 'Each variant above takes its name. The copy itself is a
|
|
100
|
+
return target === 'email' ? 'Each variant above takes its name, subject and body. Nothing is saved until you save the experiment.' : 'Each variant above takes its name. The copy itself is a page version — make one per variant in the editor and pin it above.';
|
|
101
101
|
}
|
|
102
102
|
/**
|
|
103
103
|
* "Write variants with AI", in the experiment editor beneath the variants it
|