@object-ui/app-shell 7.1.0 → 7.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +320 -0
- package/dist/components/ManagedByBadge.js +1 -1
- package/dist/console/AppContent.js +9 -15
- package/dist/console/ConsoleShell.d.ts +16 -0
- package/dist/console/ConsoleShell.js +43 -2
- package/dist/console/ai/AiChatPage.js +64 -14
- package/dist/console/ai/BuildDebugDrawer.d.ts +20 -0
- package/dist/console/ai/BuildDebugDrawer.js +75 -0
- package/dist/console/ai/buildDebugApi.d.ts +94 -0
- package/dist/console/ai/buildDebugApi.js +16 -0
- package/dist/console/home/HomeLayout.js +5 -7
- package/dist/console/home/HomePage.js +1 -9
- package/dist/console/organizations/CreateWorkspaceDialog.js +15 -1
- package/dist/console/organizations/OrganizationsPage.js +32 -4
- package/dist/console/organizations/manage/OrganizationLayout.js +1 -1
- package/dist/console/organizations/provisionEnvironment.d.ts +53 -0
- package/dist/console/organizations/provisionEnvironment.js +64 -0
- package/dist/environment/EnvironmentEntitlementDialog.d.ts +34 -0
- package/dist/environment/EnvironmentEntitlementDialog.js +37 -0
- package/dist/environment/EnvironmentListToolbar.d.ts +33 -0
- package/dist/environment/EnvironmentListToolbar.js +59 -0
- package/dist/environment/entitlements.d.ts +90 -0
- package/dist/environment/entitlements.js +91 -0
- package/dist/environment/useEnvironmentEntitlements.d.ts +32 -0
- package/dist/environment/useEnvironmentEntitlements.js +108 -0
- package/dist/hooks/useActionModal.js +15 -1
- package/dist/hooks/useAiSurface.d.ts +59 -0
- package/dist/hooks/useAiSurface.js +78 -0
- package/dist/hooks/useConsoleActionRuntime.d.ts +3 -0
- package/dist/hooks/useConsoleActionRuntime.js +36 -8
- package/dist/index.d.ts +3 -1
- package/dist/index.js +5 -1
- package/dist/layout/AppHeader.js +30 -5
- package/dist/layout/ConsoleFloatingChatbot.js +22 -4
- package/dist/layout/ConsoleLayout.js +5 -6
- package/dist/layout/ContextSelectors.js +0 -19
- package/dist/layout/WorkspaceSwitcher.d.ts +14 -0
- package/dist/layout/WorkspaceSwitcher.js +76 -0
- package/dist/preview/DraftPreviewBar.js +20 -7
- package/dist/providers/ExpressionProvider.js +9 -3
- package/dist/utils/index.d.ts +2 -2
- package/dist/utils/index.js +1 -1
- package/dist/utils/managedByEmptyState.d.ts +1 -1
- package/dist/utils/managedByEmptyState.js +20 -2
- package/dist/utils/recordFormNavigation.d.ts +60 -0
- package/dist/utils/recordFormNavigation.js +35 -0
- package/dist/utils/resolvePageVarTokens.d.ts +31 -0
- package/dist/utils/resolvePageVarTokens.js +72 -0
- package/dist/views/CreateViewDialog.js +14 -1
- package/dist/views/ObjectView.js +27 -13
- package/dist/views/metadata-admin/AssignedUsersSection.d.ts +28 -0
- package/dist/views/metadata-admin/AssignedUsersSection.js +151 -0
- package/dist/views/metadata-admin/PackagesPage.d.ts +5 -0
- package/dist/views/metadata-admin/PackagesPage.js +49 -4
- package/dist/views/metadata-admin/PermissionMatrixEditor.js +2 -1
- package/dist/views/metadata-admin/ResourceEditPage.js +36 -4
- package/dist/views/metadata-admin/ResourceListPage.js +25 -10
- package/dist/views/metadata-admin/StudioHomePage.js +1 -5
- package/dist/views/metadata-admin/createBody.d.ts +26 -0
- package/dist/views/metadata-admin/createBody.js +30 -0
- package/dist/views/metadata-admin/i18n.js +20 -2
- package/dist/views/metadata-admin/inspectors/DatasetDefaultInspector.d.ts +8 -0
- package/dist/views/metadata-admin/inspectors/DatasetDefaultInspector.js +17 -3
- package/dist/views/metadata-admin/inspectors/FlowEdgeInspector.js +16 -2
- package/dist/views/metadata-admin/inspectors/FlowExprIssue.d.ts +21 -0
- package/dist/views/metadata-admin/inspectors/FlowExprIssue.js +13 -0
- package/dist/views/metadata-admin/inspectors/FlowKeyValueField.d.ts +20 -2
- package/dist/views/metadata-admin/inspectors/FlowKeyValueField.js +71 -28
- package/dist/views/metadata-admin/inspectors/FlowNodeConfigField.d.ts +4 -1
- package/dist/views/metadata-admin/inspectors/FlowNodeConfigField.js +24 -9
- package/dist/views/metadata-admin/inspectors/FlowNodeInspector.js +15 -3
- package/dist/views/metadata-admin/inspectors/FlowObjectListField.d.ts +4 -1
- package/dist/views/metadata-admin/inspectors/FlowObjectListField.js +8 -3
- package/dist/views/metadata-admin/inspectors/VariableTextInput.d.ts +47 -0
- package/dist/views/metadata-admin/inspectors/VariableTextInput.js +95 -0
- package/dist/views/metadata-admin/inspectors/datasetFilterCondition.js +6 -1
- package/dist/views/metadata-admin/inspectors/flow-node-config.d.ts +16 -1
- package/dist/views/metadata-admin/inspectors/flow-node-config.js +21 -10
- package/dist/views/metadata-admin/inspectors/flow-ref-check.d.ts +39 -0
- package/dist/views/metadata-admin/inspectors/flow-ref-check.js +114 -0
- package/dist/views/metadata-admin/inspectors/flow-scope.d.ts +109 -0
- package/dist/views/metadata-admin/inspectors/flow-scope.js +199 -0
- package/dist/views/metadata-admin/inspectors/useDatasetFields.d.ts +14 -3
- package/dist/views/metadata-admin/inspectors/useDatasetFields.js +0 -0
- package/dist/views/metadata-admin/inspectors/useFlowScope.d.ts +23 -0
- package/dist/views/metadata-admin/inspectors/useFlowScope.js +45 -0
- package/dist/views/metadata-admin/package-scope.d.ts +9 -19
- package/dist/views/metadata-admin/package-scope.js +11 -25
- package/dist/views/metadata-admin/preview-registry.d.ts +12 -0
- package/dist/views/metadata-admin/previews/FlowCanvas.d.ts +22 -3
- package/dist/views/metadata-admin/previews/FlowCanvas.js +45 -6
- package/dist/views/metadata-admin/previews/FlowPreview.d.ts +1 -1
- package/dist/views/metadata-admin/previews/FlowPreview.js +42 -30
- package/dist/views/metadata-admin/previews/ObjectFormCanvas.js +9 -4
- package/dist/views/metadata-admin/previews/ProblemsPanel.d.ts +18 -0
- package/dist/views/metadata-admin/previews/ProblemsPanel.js +27 -0
- package/dist/views/metadata-admin/previews/ReportPreview.d.ts +9 -8
- package/dist/views/metadata-admin/previews/ReportPreview.js +33 -16
- package/dist/views/metadata-admin/previews/flow-canvas-parts.d.ts +9 -1
- package/dist/views/metadata-admin/previews/flow-canvas-parts.js +5 -3
- package/dist/views/metadata-admin/previews/flow-expr-problems.d.ts +19 -0
- package/dist/views/metadata-admin/previews/flow-expr-problems.js +97 -0
- package/dist/views/metadata-admin/previews/flow-problems.d.ts +84 -0
- package/dist/views/metadata-admin/previews/flow-problems.js +209 -0
- package/dist/views/metadata-admin/previews/simulator/flow-sim-types.d.ts +9 -0
- package/dist/views/metadata-admin/previews/simulator/flow-sim-validate.js +4 -2
- package/package.json +38 -38
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* provisionEnvironment
|
|
3
|
+
*
|
|
4
|
+
* Eagerly ensure a freshly created organization has its **production**
|
|
5
|
+
* environment so a self-service "create another workspace" lands the user in a
|
|
6
|
+
* ready console — no onboarding-wizard detour.
|
|
7
|
+
*
|
|
8
|
+
* ObjectStack runs a 1-production-environment-per-organization model: an org's
|
|
9
|
+
* FIRST environment is born as its production env (allowed on every plan,
|
|
10
|
+
* including free). The cloud control plane exposes this as
|
|
11
|
+
* `POST /api/v1/cloud/environments`, which only needs a `displayName`; the org
|
|
12
|
+
* is resolved from `organizationId` (preferred) → the better-auth active org →
|
|
13
|
+
* the actor's first membership.
|
|
14
|
+
*
|
|
15
|
+
* Idempotent + best-effort by contract:
|
|
16
|
+
* - Some control planes auto-provision the production env on org create (the
|
|
17
|
+
* `auto-default-environment` plugin). This call then races that plugin and
|
|
18
|
+
* the loser gets a 403 `PRODUCTION_ENV_LIMIT` / 409 — which is SUCCESS for
|
|
19
|
+
* us (the org is already born-with-env), not a failure.
|
|
20
|
+
* - On a genuine failure (5xx / network) the caller swallows the error and
|
|
21
|
+
* the onboarding gate provisions the env lazily on first navigation.
|
|
22
|
+
*
|
|
23
|
+
* @module
|
|
24
|
+
*/
|
|
25
|
+
import { createAuthenticatedFetch } from '@object-ui/auth';
|
|
26
|
+
import { getCloudBase } from '../../runtime-config';
|
|
27
|
+
/**
|
|
28
|
+
* Ensure the production environment exists for a just-created organization.
|
|
29
|
+
*
|
|
30
|
+
* Uses {@link createAuthenticatedFetch} so the request carries the Bearer token
|
|
31
|
+
* and the active-org `X-Tenant-ID` header; `organizationId` is also sent in the
|
|
32
|
+
* body so the target org is unambiguous even before the session active-org
|
|
33
|
+
* switch has propagated. The env is named `Production` to match the
|
|
34
|
+
* born-with-env convention used by the signup org.
|
|
35
|
+
*
|
|
36
|
+
* @throws on a genuine control-plane failure (5xx / network). A 403/409
|
|
37
|
+
* "already has its production env" is NOT an error — it resolves to
|
|
38
|
+
* `{ alreadyProvisioned: true }`.
|
|
39
|
+
*/
|
|
40
|
+
export async function provisionProductionEnvironment(opts) {
|
|
41
|
+
const authFetch = createAuthenticatedFetch();
|
|
42
|
+
const res = await authFetch(`${getCloudBase()}/api/v1/cloud/environments`, {
|
|
43
|
+
method: 'POST',
|
|
44
|
+
headers: { 'Content-Type': 'application/json' },
|
|
45
|
+
body: JSON.stringify({
|
|
46
|
+
displayName: opts.displayName ?? 'Production',
|
|
47
|
+
organizationId: opts.organizationId,
|
|
48
|
+
}),
|
|
49
|
+
});
|
|
50
|
+
if (!res.ok) {
|
|
51
|
+
// 403 PRODUCTION_ENV_LIMIT / 409 ⇒ the org already owns its (one) production
|
|
52
|
+
// env — born-with-env is satisfied, so this is success, not a failure.
|
|
53
|
+
if (res.status === 403 || res.status === 409) {
|
|
54
|
+
return { alreadyProvisioned: true };
|
|
55
|
+
}
|
|
56
|
+
throw new Error(`Failed to provision production environment (status ${res.status})`);
|
|
57
|
+
}
|
|
58
|
+
// The control plane wraps payloads as `{ success, data }`; tolerate both.
|
|
59
|
+
const body = (await res.json().catch(() => ({})));
|
|
60
|
+
if (body && typeof body === 'object' && 'data' in body && body.data) {
|
|
61
|
+
return body.data;
|
|
62
|
+
}
|
|
63
|
+
return body ?? {};
|
|
64
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* EnvironmentEntitlementDialog — a friendly upgrade / limit dialog shown instead
|
|
3
|
+
* of a raw red error toast when an environment-create is gated by plan or
|
|
4
|
+
* capacity (DEV_ENV_PLAN_LOCKED / DEV_ENV_LIMIT / PRODUCTION_ENV_LIMIT).
|
|
5
|
+
*
|
|
6
|
+
* Driven by a single {@link EntitlementDialogSpec}, opened from two places:
|
|
7
|
+
* • proactively, from the env-list toolbar (a free-plan org clicking
|
|
8
|
+
* "Add environment" — see EnvironmentListToolbar), and
|
|
9
|
+
* • reactively, from the action runtime's apiHandler when the create POST
|
|
10
|
+
* comes back with an entitlement 403 (the safety net).
|
|
11
|
+
*
|
|
12
|
+
* The CTA renders as an anchor (not an SPA navigation) so a control-plane URL
|
|
13
|
+
* like `/settings/billing` always lands on the real page regardless of the
|
|
14
|
+
* console's own router. Relative URLs resolve against the control-plane origin
|
|
15
|
+
* (`apiBase`); absolute / mailto URLs are used as-is.
|
|
16
|
+
*/
|
|
17
|
+
import type { EntitlementDialogSpec } from './entitlements';
|
|
18
|
+
export interface EntitlementDialogState {
|
|
19
|
+
open: boolean;
|
|
20
|
+
spec?: EntitlementDialogSpec;
|
|
21
|
+
}
|
|
22
|
+
/** Resolve a CTA URL to a concrete href + whether it should open in a new tab. */
|
|
23
|
+
export declare function resolveCtaHref(url: string, apiBase: string): {
|
|
24
|
+
href: string;
|
|
25
|
+
external: boolean;
|
|
26
|
+
};
|
|
27
|
+
interface Props {
|
|
28
|
+
state: EntitlementDialogState;
|
|
29
|
+
/** Control-plane origin used to resolve relative CTA URLs. */
|
|
30
|
+
apiBase: string;
|
|
31
|
+
onOpenChange: (open: boolean) => void;
|
|
32
|
+
}
|
|
33
|
+
export declare function EnvironmentEntitlementDialog({ state, apiBase, onOpenChange }: Props): import("react").JSX.Element;
|
|
34
|
+
export {};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* EnvironmentEntitlementDialog — a friendly upgrade / limit dialog shown instead
|
|
4
|
+
* of a raw red error toast when an environment-create is gated by plan or
|
|
5
|
+
* capacity (DEV_ENV_PLAN_LOCKED / DEV_ENV_LIMIT / PRODUCTION_ENV_LIMIT).
|
|
6
|
+
*
|
|
7
|
+
* Driven by a single {@link EntitlementDialogSpec}, opened from two places:
|
|
8
|
+
* • proactively, from the env-list toolbar (a free-plan org clicking
|
|
9
|
+
* "Add environment" — see EnvironmentListToolbar), and
|
|
10
|
+
* • reactively, from the action runtime's apiHandler when the create POST
|
|
11
|
+
* comes back with an entitlement 403 (the safety net).
|
|
12
|
+
*
|
|
13
|
+
* The CTA renders as an anchor (not an SPA navigation) so a control-plane URL
|
|
14
|
+
* like `/settings/billing` always lands on the real page regardless of the
|
|
15
|
+
* console's own router. Relative URLs resolve against the control-plane origin
|
|
16
|
+
* (`apiBase`); absolute / mailto URLs are used as-is.
|
|
17
|
+
*/
|
|
18
|
+
import { AlertDialog, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, AlertDialogCancel, Button, } from '@object-ui/components';
|
|
19
|
+
/** Resolve a CTA URL to a concrete href + whether it should open in a new tab. */
|
|
20
|
+
export function resolveCtaHref(url, apiBase) {
|
|
21
|
+
if (/^https?:\/\//i.test(url) || url.startsWith('mailto:')) {
|
|
22
|
+
return { href: url, external: !url.startsWith('mailto:') };
|
|
23
|
+
}
|
|
24
|
+
const base = (apiBase || '').replace(/\/+$/, '');
|
|
25
|
+
// A control-plane-relative path: prefix the API origin when we have one (dev:
|
|
26
|
+
// split SPA + backend). Empty base → same-origin relative (prod).
|
|
27
|
+
return { href: `${base}${url}`, external: Boolean(base) };
|
|
28
|
+
}
|
|
29
|
+
function CtaButton({ cta, apiBase, primary, onNavigate, }) {
|
|
30
|
+
const { href, external } = resolveCtaHref(cta.url, apiBase);
|
|
31
|
+
return (_jsx(Button, { asChild: true, variant: primary ? 'default' : 'outline', size: "sm", children: _jsx("a", { href: href, onClick: onNavigate, ...(external ? { target: '_blank', rel: 'noopener noreferrer' } : {}), "data-testid": `entitlement-cta-${primary ? 'primary' : 'secondary'}`, children: cta.label }) }));
|
|
32
|
+
}
|
|
33
|
+
export function EnvironmentEntitlementDialog({ state, apiBase, onOpenChange }) {
|
|
34
|
+
const spec = state.spec;
|
|
35
|
+
return (_jsx(AlertDialog, { open: state.open, onOpenChange: (open) => { if (!open)
|
|
36
|
+
onOpenChange(false); }, children: _jsxs(AlertDialogContent, { "data-testid": "environment-entitlement-dialog", children: [_jsxs(AlertDialogHeader, { children: [_jsx(AlertDialogTitle, { children: spec?.title }), _jsx(AlertDialogDescription, { children: spec?.message })] }), _jsxs(AlertDialogFooter, { children: [_jsx(AlertDialogCancel, { children: "Close" }), spec?.secondaryCta && (_jsx(CtaButton, { cta: spec.secondaryCta, apiBase: apiBase, primary: false, onNavigate: () => onOpenChange(false) })), spec?.cta && (_jsx(CtaButton, { cta: spec.cta, apiBase: apiBase, primary: true, onNavigate: () => onOpenChange(false) }))] })] }) }));
|
|
37
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* EnvironmentListToolbar — the state-aware replacement for the generic
|
|
3
|
+
* `list_toolbar` action bar on the `sys_environment` list.
|
|
4
|
+
*
|
|
5
|
+
* The cloud serves ONE `create_environment` action; born-with-env makes its
|
|
6
|
+
* meaning depend on org state (which the action metadata can't express). This
|
|
7
|
+
* component reads the resolved entitlement state and renders the right
|
|
8
|
+
* affordance:
|
|
9
|
+
* • no production env → "Set up your production environment" (primary);
|
|
10
|
+
* the create POST provisions the org's one
|
|
11
|
+
* production env — the historical-data path that
|
|
12
|
+
* must never error.
|
|
13
|
+
* • has prod + dev allowed → "Add development environment" (the create POST
|
|
14
|
+
* makes a dev env).
|
|
15
|
+
* • has prod + dev NOT allowed → "Add environment" that opens an UPGRADE prompt
|
|
16
|
+
* instead of POST-ing into a 403.
|
|
17
|
+
* • still resolving / unknown → the action's default label (neutral), with the
|
|
18
|
+
* apiHandler entitlement dialog as the safety net.
|
|
19
|
+
*
|
|
20
|
+
* Create flows reuse the standard `action:bar` runner (name modal → apiHandler),
|
|
21
|
+
* so only the label/variant changes — no duplicate POST logic here.
|
|
22
|
+
*/
|
|
23
|
+
import { type EntitlementDialogSpec, type EnvironmentEntitlementsState } from './entitlements';
|
|
24
|
+
interface Props {
|
|
25
|
+
/** Toolbar actions already localized by the caller (ObjectView). */
|
|
26
|
+
actions: any[];
|
|
27
|
+
/** Resolved entitlement state, or null while still loading. */
|
|
28
|
+
entitlements: EnvironmentEntitlementsState | null;
|
|
29
|
+
/** Open the shared entitlement dialog (proactive upgrade prompt). */
|
|
30
|
+
onUpgrade: (spec: EntitlementDialogSpec) => void;
|
|
31
|
+
}
|
|
32
|
+
export declare function EnvironmentListToolbar({ actions, entitlements, onUpgrade }: Props): import("react").JSX.Element | null;
|
|
33
|
+
export {};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* EnvironmentListToolbar — the state-aware replacement for the generic
|
|
4
|
+
* `list_toolbar` action bar on the `sys_environment` list.
|
|
5
|
+
*
|
|
6
|
+
* The cloud serves ONE `create_environment` action; born-with-env makes its
|
|
7
|
+
* meaning depend on org state (which the action metadata can't express). This
|
|
8
|
+
* component reads the resolved entitlement state and renders the right
|
|
9
|
+
* affordance:
|
|
10
|
+
* • no production env → "Set up your production environment" (primary);
|
|
11
|
+
* the create POST provisions the org's one
|
|
12
|
+
* production env — the historical-data path that
|
|
13
|
+
* must never error.
|
|
14
|
+
* • has prod + dev allowed → "Add development environment" (the create POST
|
|
15
|
+
* makes a dev env).
|
|
16
|
+
* • has prod + dev NOT allowed → "Add environment" that opens an UPGRADE prompt
|
|
17
|
+
* instead of POST-ing into a 403.
|
|
18
|
+
* • still resolving / unknown → the action's default label (neutral), with the
|
|
19
|
+
* apiHandler entitlement dialog as the safety net.
|
|
20
|
+
*
|
|
21
|
+
* Create flows reuse the standard `action:bar` runner (name modal → apiHandler),
|
|
22
|
+
* so only the label/variant changes — no duplicate POST logic here.
|
|
23
|
+
*/
|
|
24
|
+
import { SchemaRenderer } from '@object-ui/react';
|
|
25
|
+
import { Button } from '@object-ui/components';
|
|
26
|
+
import { Plus } from 'lucide-react';
|
|
27
|
+
import { decideEnvironmentCta, upgradeDialogSpec, } from './entitlements';
|
|
28
|
+
const CREATE_ACTION = 'create_environment';
|
|
29
|
+
export function EnvironmentListToolbar({ actions, entitlements, onUpgrade }) {
|
|
30
|
+
const toolbarActions = (actions || []).filter((a) => a?.locations?.includes('list_toolbar'));
|
|
31
|
+
if (toolbarActions.length === 0)
|
|
32
|
+
return null;
|
|
33
|
+
const ctaKind = entitlements?.ready ? decideEnvironmentCta(entitlements) : null;
|
|
34
|
+
// Upgrade state: a free-plan org clicking "create" must NOT POST-then-403.
|
|
35
|
+
// Render a primary button that opens the upgrade prompt, plus any other
|
|
36
|
+
// (non-create) toolbar actions through the normal bar.
|
|
37
|
+
if (ctaKind === 'upgrade_for_development') {
|
|
38
|
+
const others = toolbarActions.filter((a) => a?.name !== CREATE_ACTION);
|
|
39
|
+
return (_jsxs(_Fragment, { children: [others.length > 0 && (_jsx(SchemaRenderer, { schema: { type: 'action:bar', location: 'list_toolbar', actions: others, size: 'sm', variant: 'outline' } })), _jsxs(Button, { size: "sm", onClick: () => onUpgrade(upgradeDialogSpec(entitlements)), className: "shadow-none gap-1.5 sm:gap-2 h-8 sm:h-9", "data-testid": "environment-add-upgrade", children: [_jsx(Plus, { className: "h-4 w-4" }), _jsx("span", { children: "Add environment" })] })] }));
|
|
40
|
+
}
|
|
41
|
+
// setup_production / add_development / loading: render the bar, overriding only
|
|
42
|
+
// the create action's label (and promoting production setup to a primary CTA).
|
|
43
|
+
const renderedActions = toolbarActions.map((a) => {
|
|
44
|
+
if (a?.name !== CREATE_ACTION || ctaKind == null)
|
|
45
|
+
return a;
|
|
46
|
+
if (ctaKind === 'setup_production') {
|
|
47
|
+
return { ...a, label: 'Set up your production environment', variant: 'primary' };
|
|
48
|
+
}
|
|
49
|
+
// add_development
|
|
50
|
+
return { ...a, label: 'Add development environment' };
|
|
51
|
+
});
|
|
52
|
+
return (_jsx(SchemaRenderer, { schema: {
|
|
53
|
+
type: 'action:bar',
|
|
54
|
+
location: 'list_toolbar',
|
|
55
|
+
actions: renderedActions,
|
|
56
|
+
size: 'sm',
|
|
57
|
+
variant: 'outline',
|
|
58
|
+
} }));
|
|
59
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Environment entitlement logic — the React-free decision layer behind the
|
|
3
|
+
* state-aware "create environment" affordance and the entitlement-error dialog.
|
|
4
|
+
*
|
|
5
|
+
* The Console environment list (`sys_environment`) renders a single
|
|
6
|
+
* `create_environment` toolbar action. Whether that should read "Set up your
|
|
7
|
+
* production environment", "Add development environment", or open an upgrade
|
|
8
|
+
* prompt depends on org state the action metadata can't express (does the org
|
|
9
|
+
* already own its one production env? is its plan allowed development envs?).
|
|
10
|
+
* This module turns the org-scoped capacity summary
|
|
11
|
+
* (GET /cloud/environment-entitlements) — with a row-derived fallback — into
|
|
12
|
+
* that decision, and maps the cloud env-create 403 bodies to a friendly dialog
|
|
13
|
+
* so a confused user never sees a raw red error toast.
|
|
14
|
+
*
|
|
15
|
+
* Kept dependency-free so it is trivially unit-testable.
|
|
16
|
+
*/
|
|
17
|
+
export type EntitlementErrorCode = 'DEV_ENV_PLAN_LOCKED' | 'DEV_ENV_LIMIT' | 'PRODUCTION_ENV_LIMIT';
|
|
18
|
+
export declare function isEntitlementErrorCode(code: unknown): code is EntitlementErrorCode;
|
|
19
|
+
/** A CTA link rendered in the entitlement dialog. */
|
|
20
|
+
export interface EntitlementCta {
|
|
21
|
+
label: string;
|
|
22
|
+
/** Absolute (http/mailto) or a control-plane-relative path (e.g. `/settings/billing`). */
|
|
23
|
+
url: string;
|
|
24
|
+
}
|
|
25
|
+
/** Declarative spec the {@link EnvironmentEntitlementDialog} renders. */
|
|
26
|
+
export interface EntitlementDialogSpec {
|
|
27
|
+
code: string;
|
|
28
|
+
title: string;
|
|
29
|
+
message: string;
|
|
30
|
+
/** Primary CTA (e.g. Upgrade plan). */
|
|
31
|
+
cta?: EntitlementCta;
|
|
32
|
+
/** Secondary CTA (e.g. Contact sales). */
|
|
33
|
+
secondaryCta?: EntitlementCta;
|
|
34
|
+
}
|
|
35
|
+
export declare const DEFAULT_UPGRADE_URL = "/settings/billing";
|
|
36
|
+
/**
|
|
37
|
+
* Map a cloud env-create 403 body
|
|
38
|
+
* (`{ error, code, upgrade_url, contact_url, plan, current, limit }`) to a
|
|
39
|
+
* dialog spec. Returns `null` for any non-entitlement error so the caller falls
|
|
40
|
+
* back to its normal error handling (a red toast). This is the safety net: it
|
|
41
|
+
* fires regardless of whether the up-front state-aware presentation was right.
|
|
42
|
+
*/
|
|
43
|
+
export declare function entitlementDialogFromError(body: any): EntitlementDialogSpec | null;
|
|
44
|
+
/** Server summary shape (GET /cloud/environment-entitlements → `data`). */
|
|
45
|
+
export interface EnvironmentEntitlementsSummary {
|
|
46
|
+
plan?: string;
|
|
47
|
+
hasProductionEnv?: boolean;
|
|
48
|
+
production?: {
|
|
49
|
+
used: number;
|
|
50
|
+
limit: number;
|
|
51
|
+
canCreate: boolean;
|
|
52
|
+
};
|
|
53
|
+
development?: {
|
|
54
|
+
used: number;
|
|
55
|
+
limit: number;
|
|
56
|
+
canCreate: boolean;
|
|
57
|
+
};
|
|
58
|
+
seatCount?: number;
|
|
59
|
+
upgradeUrl?: string;
|
|
60
|
+
contactSalesUrl?: string;
|
|
61
|
+
}
|
|
62
|
+
/** Combined client state (authoritative summary, or a row-derived fallback). */
|
|
63
|
+
export interface EnvironmentEntitlementsState {
|
|
64
|
+
/** True once a usable signal exists (summary OR derived rows). */
|
|
65
|
+
ready: boolean;
|
|
66
|
+
hasProductionEnv: boolean;
|
|
67
|
+
/** Authoritative dev-create capability; `undefined` when unknown (no summary). */
|
|
68
|
+
canCreateDevelopmentEnv?: boolean;
|
|
69
|
+
plan?: string;
|
|
70
|
+
upgradeUrl: string;
|
|
71
|
+
contactSalesUrl?: string;
|
|
72
|
+
/** Where the signal came from — telemetry + degradation note + tests. */
|
|
73
|
+
source: 'summary' | 'derived' | 'unknown';
|
|
74
|
+
}
|
|
75
|
+
export type EnvironmentCtaKind = 'setup_production' | 'add_development' | 'upgrade_for_development';
|
|
76
|
+
/**
|
|
77
|
+
* Decide which toolbar affordance to present:
|
|
78
|
+
* • no production env → set up production (the create POST makes one;
|
|
79
|
+
* the critical historical-data path — never errors)
|
|
80
|
+
* • has prod + dev allowed → add development (POST makes a dev env)
|
|
81
|
+
* • has prod + dev NOT allowed → upgrade prompt (no POST)
|
|
82
|
+
* • has prod + dev unknown → add development (let the POST + dialog decide)
|
|
83
|
+
*/
|
|
84
|
+
export declare function decideEnvironmentCta(state: EnvironmentEntitlementsState): EnvironmentCtaKind;
|
|
85
|
+
/**
|
|
86
|
+
* The proactive (pre-POST) upgrade dialog shown when a free-plan org clicks
|
|
87
|
+
* "Add environment" but development envs aren't in its plan. Mirrors the copy
|
|
88
|
+
* of the reactive DEV_ENV_PLAN_LOCKED error so both paths read identically.
|
|
89
|
+
*/
|
|
90
|
+
export declare function upgradeDialogSpec(state: EnvironmentEntitlementsState): EntitlementDialogSpec;
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Environment entitlement logic — the React-free decision layer behind the
|
|
3
|
+
* state-aware "create environment" affordance and the entitlement-error dialog.
|
|
4
|
+
*
|
|
5
|
+
* The Console environment list (`sys_environment`) renders a single
|
|
6
|
+
* `create_environment` toolbar action. Whether that should read "Set up your
|
|
7
|
+
* production environment", "Add development environment", or open an upgrade
|
|
8
|
+
* prompt depends on org state the action metadata can't express (does the org
|
|
9
|
+
* already own its one production env? is its plan allowed development envs?).
|
|
10
|
+
* This module turns the org-scoped capacity summary
|
|
11
|
+
* (GET /cloud/environment-entitlements) — with a row-derived fallback — into
|
|
12
|
+
* that decision, and maps the cloud env-create 403 bodies to a friendly dialog
|
|
13
|
+
* so a confused user never sees a raw red error toast.
|
|
14
|
+
*
|
|
15
|
+
* Kept dependency-free so it is trivially unit-testable.
|
|
16
|
+
*/
|
|
17
|
+
const ENTITLEMENT_ERROR_CODES = new Set([
|
|
18
|
+
'DEV_ENV_PLAN_LOCKED',
|
|
19
|
+
'DEV_ENV_LIMIT',
|
|
20
|
+
'PRODUCTION_ENV_LIMIT',
|
|
21
|
+
]);
|
|
22
|
+
export function isEntitlementErrorCode(code) {
|
|
23
|
+
return typeof code === 'string' && ENTITLEMENT_ERROR_CODES.has(code);
|
|
24
|
+
}
|
|
25
|
+
export const DEFAULT_UPGRADE_URL = '/settings/billing';
|
|
26
|
+
/**
|
|
27
|
+
* Map a cloud env-create 403 body
|
|
28
|
+
* (`{ error, code, upgrade_url, contact_url, plan, current, limit }`) to a
|
|
29
|
+
* dialog spec. Returns `null` for any non-entitlement error so the caller falls
|
|
30
|
+
* back to its normal error handling (a red toast). This is the safety net: it
|
|
31
|
+
* fires regardless of whether the up-front state-aware presentation was right.
|
|
32
|
+
*/
|
|
33
|
+
export function entitlementDialogFromError(body) {
|
|
34
|
+
const code = body?.code;
|
|
35
|
+
if (!isEntitlementErrorCode(code))
|
|
36
|
+
return null;
|
|
37
|
+
const serverMessage = typeof body?.error === 'string' && body.error ? body.error
|
|
38
|
+
: typeof body?.message === 'string' ? body.message : '';
|
|
39
|
+
const upgradeUrl = typeof body?.upgrade_url === 'string' && body.upgrade_url ? body.upgrade_url : DEFAULT_UPGRADE_URL;
|
|
40
|
+
const contactUrl = typeof body?.contact_url === 'string' && body.contact_url ? body.contact_url : '';
|
|
41
|
+
if (code === 'PRODUCTION_ENV_LIMIT') {
|
|
42
|
+
return {
|
|
43
|
+
code,
|
|
44
|
+
title: 'You already have your production environment',
|
|
45
|
+
message: serverMessage ||
|
|
46
|
+
'Each organization includes exactly one production environment. Create a separate organization for another, or contact us about an Enterprise arrangement.',
|
|
47
|
+
cta: contactUrl ? { label: 'Contact sales', url: contactUrl } : undefined,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
// DEV_ENV_PLAN_LOCKED / DEV_ENV_LIMIT — both resolve via an upgrade CTA.
|
|
51
|
+
return {
|
|
52
|
+
code,
|
|
53
|
+
title: code === 'DEV_ENV_PLAN_LOCKED'
|
|
54
|
+
? 'Development environments are a paid feature'
|
|
55
|
+
: 'Development environment limit reached',
|
|
56
|
+
message: serverMessage ||
|
|
57
|
+
(code === 'DEV_ENV_PLAN_LOCKED'
|
|
58
|
+
? 'Your free plan includes one production environment. Upgrade to add development environments — build in dev, then publish to production.'
|
|
59
|
+
: 'Capacity scales with AI seats. Add an AI seat, or archive an unused development environment to free one up.'),
|
|
60
|
+
cta: { label: 'Upgrade plan', url: upgradeUrl },
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Decide which toolbar affordance to present:
|
|
65
|
+
* • no production env → set up production (the create POST makes one;
|
|
66
|
+
* the critical historical-data path — never errors)
|
|
67
|
+
* • has prod + dev allowed → add development (POST makes a dev env)
|
|
68
|
+
* • has prod + dev NOT allowed → upgrade prompt (no POST)
|
|
69
|
+
* • has prod + dev unknown → add development (let the POST + dialog decide)
|
|
70
|
+
*/
|
|
71
|
+
export function decideEnvironmentCta(state) {
|
|
72
|
+
if (!state.hasProductionEnv)
|
|
73
|
+
return 'setup_production';
|
|
74
|
+
if (state.canCreateDevelopmentEnv === false)
|
|
75
|
+
return 'upgrade_for_development';
|
|
76
|
+
return 'add_development';
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* The proactive (pre-POST) upgrade dialog shown when a free-plan org clicks
|
|
80
|
+
* "Add environment" but development envs aren't in its plan. Mirrors the copy
|
|
81
|
+
* of the reactive DEV_ENV_PLAN_LOCKED error so both paths read identically.
|
|
82
|
+
*/
|
|
83
|
+
export function upgradeDialogSpec(state) {
|
|
84
|
+
const planLabel = state.plan && state.plan !== 'free' ? `your ${state.plan} plan` : 'your free plan';
|
|
85
|
+
return {
|
|
86
|
+
code: 'DEV_ENV_PLAN_LOCKED',
|
|
87
|
+
title: 'Development environments are a paid feature',
|
|
88
|
+
message: `${planLabel} includes one production environment. Upgrade to add development environments — build in dev, then publish to production.`,
|
|
89
|
+
cta: { label: 'Upgrade plan', url: state.upgradeUrl || DEFAULT_UPGRADE_URL },
|
|
90
|
+
};
|
|
91
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* useEnvironmentEntitlements — resolve the org's environment-capacity state so
|
|
3
|
+
* the `sys_environment` list can present the right "create" affordance up front.
|
|
4
|
+
*
|
|
5
|
+
* Two signals, in priority order:
|
|
6
|
+
* 1. AUTHORITATIVE — GET /cloud/environment-entitlements (org-scoped, computed
|
|
7
|
+
* by the same helper the create guard uses). Gives plan + dev-create
|
|
8
|
+
* capability precisely, including the seat-scaled / subscription cases the
|
|
9
|
+
* client can't derive from rows.
|
|
10
|
+
* 2. FALLBACK — when that endpoint is unavailable (older control plane / error),
|
|
11
|
+
* derive `hasProductionEnv` from the org's env rows via the data API (which
|
|
12
|
+
* is org-scoped on the control plane). This keeps the critical
|
|
13
|
+
* "set up your production environment" path working without a backend deploy;
|
|
14
|
+
* free-vs-paid is left unknown, and a stray create POST is caught by the
|
|
15
|
+
* entitlement dialog safety net.
|
|
16
|
+
*
|
|
17
|
+
* Returns `null` when disabled (not the environment list) so callers can cheaply
|
|
18
|
+
* branch. Re-resolves when `refreshKey` changes (e.g. after a create).
|
|
19
|
+
*/
|
|
20
|
+
import { type EnvironmentEntitlementsState } from './entitlements';
|
|
21
|
+
export interface UseEnvironmentEntitlementsOptions {
|
|
22
|
+
/** Only fetch when this is the environment list (objectName === 'sys_environment'). */
|
|
23
|
+
enabled: boolean;
|
|
24
|
+
dataSource: any;
|
|
25
|
+
/** Authenticated fetch (Bearer + tenant + cookies) — from the action runtime. */
|
|
26
|
+
authFetch: (url: string, init?: any) => Promise<Response>;
|
|
27
|
+
/** Control-plane origin (VITE_SERVER_URL); '' in same-origin production. */
|
|
28
|
+
apiBase: string;
|
|
29
|
+
/** Bump to re-resolve (e.g. the list's refreshKey after a successful create). */
|
|
30
|
+
refreshKey?: unknown;
|
|
31
|
+
}
|
|
32
|
+
export declare function useEnvironmentEntitlements(opts: UseEnvironmentEntitlementsOptions): EnvironmentEntitlementsState | null;
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* useEnvironmentEntitlements — resolve the org's environment-capacity state so
|
|
3
|
+
* the `sys_environment` list can present the right "create" affordance up front.
|
|
4
|
+
*
|
|
5
|
+
* Two signals, in priority order:
|
|
6
|
+
* 1. AUTHORITATIVE — GET /cloud/environment-entitlements (org-scoped, computed
|
|
7
|
+
* by the same helper the create guard uses). Gives plan + dev-create
|
|
8
|
+
* capability precisely, including the seat-scaled / subscription cases the
|
|
9
|
+
* client can't derive from rows.
|
|
10
|
+
* 2. FALLBACK — when that endpoint is unavailable (older control plane / error),
|
|
11
|
+
* derive `hasProductionEnv` from the org's env rows via the data API (which
|
|
12
|
+
* is org-scoped on the control plane). This keeps the critical
|
|
13
|
+
* "set up your production environment" path working without a backend deploy;
|
|
14
|
+
* free-vs-paid is left unknown, and a stray create POST is caught by the
|
|
15
|
+
* entitlement dialog safety net.
|
|
16
|
+
*
|
|
17
|
+
* Returns `null` when disabled (not the environment list) so callers can cheaply
|
|
18
|
+
* branch. Re-resolves when `refreshKey` changes (e.g. after a create).
|
|
19
|
+
*/
|
|
20
|
+
import { useEffect, useState } from 'react';
|
|
21
|
+
import { useAuth } from '@object-ui/auth';
|
|
22
|
+
import { DEFAULT_UPGRADE_URL, } from './entitlements';
|
|
23
|
+
const TERMINAL_STATUSES = new Set(['archived', 'failed']);
|
|
24
|
+
/** Mirror of the server `classifyEnvironmentType`: explicit type, else default→prod. */
|
|
25
|
+
function classifyEnvironmentType(row) {
|
|
26
|
+
const t = String(row?.environment_type ?? '').trim().toLowerCase();
|
|
27
|
+
if (t === 'production' || t === 'prod')
|
|
28
|
+
return 'production';
|
|
29
|
+
if (t)
|
|
30
|
+
return 'development';
|
|
31
|
+
return row?.is_default === true || row?.is_default === 1 ? 'production' : 'development';
|
|
32
|
+
}
|
|
33
|
+
export function useEnvironmentEntitlements(opts) {
|
|
34
|
+
const { enabled, dataSource, authFetch, apiBase, refreshKey } = opts;
|
|
35
|
+
const { activeOrganization } = useAuth();
|
|
36
|
+
const orgId = activeOrganization?.id;
|
|
37
|
+
const [state, setState] = useState(null);
|
|
38
|
+
useEffect(() => {
|
|
39
|
+
if (!enabled) {
|
|
40
|
+
setState(null);
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
let cancelled = false;
|
|
44
|
+
const fromSummary = async () => {
|
|
45
|
+
try {
|
|
46
|
+
const base = (apiBase || '').replace(/\/+$/, '');
|
|
47
|
+
const qs = orgId ? `?organizationId=${encodeURIComponent(orgId)}` : '';
|
|
48
|
+
const res = await authFetch(`${base}/api/v1/cloud/environment-entitlements${qs}`, {
|
|
49
|
+
method: 'GET',
|
|
50
|
+
credentials: 'include',
|
|
51
|
+
});
|
|
52
|
+
if (!res.ok)
|
|
53
|
+
return null;
|
|
54
|
+
const json = await res.json().catch(() => null);
|
|
55
|
+
const data = (json?.data ?? json);
|
|
56
|
+
if (!data || typeof data !== 'object')
|
|
57
|
+
return null;
|
|
58
|
+
return {
|
|
59
|
+
ready: true,
|
|
60
|
+
hasProductionEnv: data.hasProductionEnv === true,
|
|
61
|
+
canCreateDevelopmentEnv: data.development?.canCreate,
|
|
62
|
+
plan: data.plan,
|
|
63
|
+
upgradeUrl: data.upgradeUrl || DEFAULT_UPGRADE_URL,
|
|
64
|
+
contactSalesUrl: data.contactSalesUrl,
|
|
65
|
+
source: 'summary',
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
catch {
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
const fromRows = async () => {
|
|
73
|
+
try {
|
|
74
|
+
const params = { $top: 200 };
|
|
75
|
+
if (orgId)
|
|
76
|
+
params.$filter = { organization_id: orgId };
|
|
77
|
+
const res = await dataSource.find('sys_environment', params);
|
|
78
|
+
const rows = Array.isArray(res) ? res : res?.data ?? [];
|
|
79
|
+
const active = rows.filter((r) => !TERMINAL_STATUSES.has(String(r?.status ?? '')));
|
|
80
|
+
const hasProductionEnv = active.some((r) => classifyEnvironmentType(r) === 'production');
|
|
81
|
+
return {
|
|
82
|
+
ready: true,
|
|
83
|
+
hasProductionEnv,
|
|
84
|
+
canCreateDevelopmentEnv: undefined,
|
|
85
|
+
upgradeUrl: DEFAULT_UPGRADE_URL,
|
|
86
|
+
source: 'derived',
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
catch {
|
|
90
|
+
return {
|
|
91
|
+
ready: false,
|
|
92
|
+
hasProductionEnv: false,
|
|
93
|
+
canCreateDevelopmentEnv: undefined,
|
|
94
|
+
upgradeUrl: DEFAULT_UPGRADE_URL,
|
|
95
|
+
source: 'unknown',
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
(async () => {
|
|
100
|
+
const summary = await fromSummary();
|
|
101
|
+
const next = summary ?? (await fromRows());
|
|
102
|
+
if (!cancelled)
|
|
103
|
+
setState(next);
|
|
104
|
+
})();
|
|
105
|
+
return () => { cancelled = true; };
|
|
106
|
+
}, [enabled, orgId, apiBase, authFetch, dataSource, refreshKey]);
|
|
107
|
+
return state;
|
|
108
|
+
}
|
|
@@ -23,8 +23,9 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
23
23
|
*/
|
|
24
24
|
import { useCallback, useState } from 'react';
|
|
25
25
|
import { Button, Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, Drawer, DrawerContent, DrawerDescription, DrawerHeader, DrawerTitle, Sheet, SheetContent, SheetDescription, SheetHeader, SheetTitle, cn, } from '@object-ui/components';
|
|
26
|
-
import { SchemaRenderer } from '@object-ui/react';
|
|
26
|
+
import { SchemaRenderer, useMetadata } from '@object-ui/react';
|
|
27
27
|
import { ModalForm } from '@object-ui/plugin-form';
|
|
28
|
+
import { resolveFormViewLayout } from '../utils/recordFormNavigation';
|
|
28
29
|
const SIZE_CLASS = {
|
|
29
30
|
sm: 'sm:max-w-sm',
|
|
30
31
|
default: 'sm:max-w-lg',
|
|
@@ -56,6 +57,10 @@ export function normalizeModalSchema(schema) {
|
|
|
56
57
|
}
|
|
57
58
|
export function useActionModal(dataSource) {
|
|
58
59
|
const [state, setState] = useState(null);
|
|
60
|
+
// Object metadata — degrades to an empty list outside a MetadataProvider
|
|
61
|
+
// (see useMetadata). Used to resolve the object's default form view so the
|
|
62
|
+
// create/edit modal honors its curated sections + field selection/order.
|
|
63
|
+
const { objects } = useMetadata();
|
|
59
64
|
const close = useCallback((r) => {
|
|
60
65
|
setState((s) => {
|
|
61
66
|
s?.resolve(r);
|
|
@@ -73,6 +78,14 @@ export function useActionModal(dataSource) {
|
|
|
73
78
|
close({ success: false });
|
|
74
79
|
};
|
|
75
80
|
if (d.objectName && !d.content) {
|
|
81
|
+
// Honor the object's default FORM VIEW (curated sections + field
|
|
82
|
+
// selection/order + master-detail subforms) unless the action descriptor
|
|
83
|
+
// passed an explicit field list. Without this the modal falls back to the
|
|
84
|
+
// raw object schema — every field, in schema order. Mirrors the global
|
|
85
|
+
// New/Edit modal in AppContent so action-opened forms stay consistent.
|
|
86
|
+
const viewLayout = (d.fields || d.sections)
|
|
87
|
+
? {}
|
|
88
|
+
: resolveFormViewLayout(objects.find((o) => o?.name === d.objectName));
|
|
76
89
|
modalElement = (_jsx(ModalForm, { schema: {
|
|
77
90
|
type: 'object-form',
|
|
78
91
|
formType: 'modal',
|
|
@@ -82,6 +95,7 @@ export function useActionModal(dataSource) {
|
|
|
82
95
|
title: d.title,
|
|
83
96
|
description: d.description,
|
|
84
97
|
fields: d.fields,
|
|
98
|
+
...viewLayout,
|
|
85
99
|
modalSize: d.size,
|
|
86
100
|
open: true,
|
|
87
101
|
onOpenChange,
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* useAiSurfaceEnabled
|
|
3
|
+
*
|
|
4
|
+
* Single source of truth for "should the in-UI AI surface be shown — for THIS
|
|
5
|
+
* user, on this deployment?". The console ships under MIT and is edition- and
|
|
6
|
+
* seat-agnostic at build time; it decides purely at runtime from what the
|
|
7
|
+
* server reports — no `VITE_EDITION` flag, no tree-shake.
|
|
8
|
+
*
|
|
9
|
+
* The signal is **the agent catalog** (`GET /api/v1/ai/agents`): the surface
|
|
10
|
+
* shows iff that returns >= 1 agent. The catalog is the right signal because it
|
|
11
|
+
* is the ONLY one that is BOTH edition- AND user-aware:
|
|
12
|
+
*
|
|
13
|
+
* • The route is access-filtered server-side (ADR-0049 / ADR-0068): it returns
|
|
14
|
+
* only the agents the CALLER may chat. A user WITHOUT the per-user AI seat
|
|
15
|
+
* (the `ai_seat` permission) gets an EMPTY catalog -> the whole AI surface
|
|
16
|
+
* hides for them, instead of showing a button that 403s on click. The
|
|
17
|
+
* deployment-wide discovery `services.ai` flag CANNOT express this — it is
|
|
18
|
+
* identical for every user — which is exactly why we do NOT gate on it.
|
|
19
|
+
* • It is ALSO the honest edition signal: a Community-Edition runtime that
|
|
20
|
+
* ships no `@objectstack/service-ai` registers no AI service and persists no
|
|
21
|
+
* agents -> empty catalog -> hidden. (The old "headless service reports
|
|
22
|
+
* available in CE" worry is moot: empty catalog hides the surface either way.)
|
|
23
|
+
*
|
|
24
|
+
* ⚠️ Do NOT "simplify" this back to `discovery.services.ai` (isAiEnabled): that
|
|
25
|
+
* reintroduces the per-user gap — seat-less users would see the FAB / links and
|
|
26
|
+
* hit 403 on click. The per-user AI-seat gate (ADR-0068) DEPENDS on this catalog
|
|
27
|
+
* signal. (This reverts objectui#1992, which dropped the per-user dimension.)
|
|
28
|
+
*
|
|
29
|
+
* The `VITE_AI_BASE_URL` opt-in flows through naturally: {@link resolveAiApiBase}
|
|
30
|
+
* points the catalog fetch at the configured server, so an external AI server
|
|
31
|
+
* with reachable agents lights the surface up and an agent-less one keeps it hidden.
|
|
32
|
+
*
|
|
33
|
+
* `isLoading` is surfaced so the `/ai` route guard can wait for the catalog to
|
|
34
|
+
* resolve before redirecting — otherwise a stale bookmark would flash a redirect
|
|
35
|
+
* to home before the fetch even starts. Entry-point buttons (FAB, top-bar link,
|
|
36
|
+
* designer "Ask AI") ignore it: staying hidden during the brief load is the
|
|
37
|
+
* correct, flash-free behaviour for a control that must not appear unless AI can
|
|
38
|
+
* actually answer.
|
|
39
|
+
*
|
|
40
|
+
* @module
|
|
41
|
+
*/
|
|
42
|
+
/**
|
|
43
|
+
* Resolve the AI service base URL, mirroring AiChatPage / the Home CTAs:
|
|
44
|
+
* an explicit `VITE_AI_BASE_URL` wins, otherwise `${VITE_SERVER_URL}/api/v1/ai`.
|
|
45
|
+
* Shared so every catalog fetch (route guard, layouts, Home) hits the same URL.
|
|
46
|
+
*/
|
|
47
|
+
export declare function resolveAiApiBase(): string;
|
|
48
|
+
export interface AiSurfaceState {
|
|
49
|
+
/** True when the AI UI should render — the CALLER can reach >= 1 agent (access-filtered). */
|
|
50
|
+
enabled: boolean;
|
|
51
|
+
/** True until the agent catalog has resolved; route guards wait on this. */
|
|
52
|
+
isLoading: boolean;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Whether the console's AI surface (FAB, `/ai` routes, "Ask AI" affordances)
|
|
56
|
+
* should be shown FOR THE CURRENT USER, driven off the access-filtered agent
|
|
57
|
+
* catalog (empty for seat-less users -> AI hidden; ADR-0068).
|
|
58
|
+
*/
|
|
59
|
+
export declare function useAiSurfaceEnabled(): AiSurfaceState;
|