@@ -19,6 +19,7 @@ import {
1919import { Link } from '@void/react' ;
2020import { useEffect , useState } from 'react' ;
2121import { useRequest , useView } from 'react-fate' ;
22+ import type { AiLoggingMode , PlanAiLoggingSettings } from '../../../ai-logging-policy.ts' ;
2223import { PlansView , plansRequest } from '../../fate/views.ts' ;
2324import type { AdminPlanPreview , AdminPlanProgress } from '../../plans.ts' ;
2425import type { AdminPageProps } from '../page-utils.ts' ;
@@ -65,6 +66,15 @@ function limit(value: number, key?: EditablePlanLimit) {
6566 : 'Unlimited'
6667 : value . toLocaleString ( 'en-US' ) ;
6768}
69+ const aiLoggingLabels : Record < AiLoggingMode , string > = {
70+ inherit : 'Inherit (AI Gateway setting)' ,
71+ off : 'Off' ,
72+ metadata : 'Metadata only' ,
73+ full : 'Full (prompts and responses)' ,
74+ } ;
75+ function aiLoggingMode ( modes : PlanAiLoggingSettings [ 'modes' ] , planId : string ) : AiLoggingMode {
76+ return Object . hasOwn ( modes , planId ) ? modes [ planId ] ! : 'inherit' ;
77+ }
6878function usePlans ( path : string ) {
6979 const { plans : ref } = useRequest ( plansRequest ( path ) , { mode : 'stale-while-revalidate' } ) ;
7080 const data = useView ( PlansView , ref ) ;
@@ -122,8 +132,9 @@ function PlanAction({
122132
123133export function PlansPage ( { path, platformName, username } : AdminPageProps ) {
124134 usePlanConfirmation ( path ) ;
125- const { catalog, accounts } = usePlans ( path ) ;
135+ const { catalog, accounts, aiLogging } = usePlans ( path ) ;
126136 const pending = catalog . reconciliation && ! catalog . reconciliation . complete ;
137+ const publishPending = aiLogging . publish && ! aiLogging . publish . complete ;
127138 return (
128139 < Layout platformName = { platformName } username = { username } title = "Plans" >
129140 < SectionStack >
@@ -153,6 +164,20 @@ export function PlansPage({ path, platformName, username }: AdminPageProps) {
153164 </ form >
154165 </ SectionStack >
155166 ) }
167+ { ! pending && publishPending && (
168+ < SectionStack aria-label = "Pending AI logging publish" >
169+ < h2 > AI logging publish pending</ h2 >
170+ < p >
171+ { aiLogging . remaining } projects still use their previous AI Gateway logging setting.
172+ Updates continue every hour, or continue them now.
173+ </ p >
174+ { aiLogging . publish ?. error && < p role = "alert" > { aiLogging . publish . error } </ p > }
175+ < form method = "post" action = { `${ HOME } /resume` } >
176+ < input type = "hidden" name = "revision" defaultValue = { catalog . revision } />
177+ < Button type = "submit" label = "Continue AI logging publish" />
178+ </ form >
179+ </ SectionStack >
180+ ) }
156181 < Table >
157182 < TableHeader >
158183 < TableRow >
@@ -161,6 +186,7 @@ export function PlansPage({ path, platformName, username }: AdminPageProps) {
161186 < TableHeaderCell > Accounts</ TableHeaderCell >
162187 < TableHeaderCell > Monthly requests</ TableHeaderCell >
163188 < TableHeaderCell > Build size</ TableHeaderCell >
189+ < TableHeaderCell > AI Gateway logging</ TableHeaderCell >
164190 < TableHeaderCell > Actions</ TableHeaderCell >
165191 </ TableRow >
166192 </ TableHeader >
@@ -187,6 +213,7 @@ export function PlansPage({ path, platformName, username }: AdminPageProps) {
187213 < TableCell >
188214 { plan . buildInstanceType === 'standard-3' ? 'Standard' : 'Large' }
189215 </ TableCell >
216+ < TableCell > { aiLoggingLabels [ aiLoggingMode ( aiLogging . modes , plan . id ) ] } </ TableCell >
190217 < TableCell >
191218 < Button
192219 href = { `${ HOME } /${ plan . id } /edit` }
@@ -205,7 +232,7 @@ export function PlansPage({ path, platformName, username }: AdminPageProps) {
205232
206233export function PlanEditPage ( { path, platformName, username } : AdminPageProps ) {
207234 usePlanConfirmation ( path ) ;
208- const { catalog, accounts, selectedPlanId } = usePlans ( path ) ;
235+ const { catalog, accounts, aiLogging , selectedPlanId } = usePlans ( path ) ;
209236 const plan = catalog . plans . find ( ( p ) => p . id === selectedPlanId ) ;
210237 const pending = catalog . reconciliation && ! catalog . reconciliation . complete ;
211238 const count = accounts . find ( ( a ) => a . planId === plan ?. id ) ?. count ?? 0 ;
@@ -300,6 +327,25 @@ export function PlanEditPage({ path, platformName, username }: AdminPageProps) {
300327 submitValue = "true"
301328 initialValue = { plan . allowShortSlugs }
302329 />
330+ { /* The page value can come from a cached read; only a changed selector is sent. */ }
331+ < input
332+ type = "hidden"
333+ name = "aiLoggingInitial"
334+ defaultValue = { aiLoggingMode ( aiLogging . modes , plan . id ) }
335+ />
336+ < FormSelector
337+ label = "AI Gateway logging default"
338+ name = "aiLogging"
339+ initialValue = { aiLoggingMode ( aiLogging . modes , plan . id ) }
340+ options = { Object . entries ( aiLoggingLabels ) . map ( ( [ value , label ] ) => ( {
341+ value,
342+ label,
343+ } ) ) }
344+ />
345+ < p >
346+ Applies to projects on this plan that have no project setting. Accounts on a
347+ plan missing from the catalog follow the signup default plan.
348+ </ p >
303349 < p >
304350 Existing URLs remain available. Storage figures are informational; static
305351 deployment retention is unchanged.
@@ -390,6 +436,7 @@ export function PlanEditPage({ path, platformName, username }: AdminPageProps) {
390436function differences (
391437 before : PlatformPlanDefinition | undefined ,
392438 after : PlatformPlanDefinition | undefined ,
439+ aiLogging : Readonly < { before : AiLoggingMode | undefined ; after : AiLoggingMode } > ,
393440) {
394441 if ( ! after ) {
395442 return [ { label : 'Plan' , before : before ! . name , after : 'Removed' } ] ;
@@ -411,6 +458,11 @@ function differences(
411458 before : before ? ( before . allowShortSlugs ? 'Allowed' : 'Not allowed' ) : '—' ,
412459 after : after . allowShortSlugs ? 'Allowed' : 'Not allowed' ,
413460 } ,
461+ {
462+ label : 'AI Gateway logging default' ,
463+ before : aiLogging . before ? aiLoggingLabels [ aiLogging . before ] : '—' ,
464+ after : aiLoggingLabels [ aiLogging . after ] ,
465+ } ,
414466 ...PLAN_EDITABLE_LIMIT_KEYS . map ( ( key ) => ( {
415467 label : labels [ key ] ,
416468 before : before ? limit ( before . limits [ key ] , key ) : '—' ,
@@ -429,9 +481,14 @@ export function PlanPreviewPage({
429481 username ?: string ;
430482} ) {
431483 const { before, after, target } = preview ;
484+ const beforePlan = before . plans . find ( ( p ) => p . id === target ) ;
432485 const changes = differences (
433- before . plans . find ( ( p ) => p . id === target ) ,
486+ beforePlan ,
434487 after . plans . find ( ( p ) => p . id === target ) ,
488+ {
489+ before : beforePlan ? aiLoggingMode ( preview . aiLoggingBefore , target ) : undefined ,
490+ after : aiLoggingMode ( preview . aiLoggingAfter , target ) ,
491+ } ,
435492 ) ;
436493 if ( before . defaultPlanId !== after . defaultPlanId ) {
437494 changes . push ( {
@@ -449,10 +506,10 @@ export function PlanPreviewPage({
449506 const replacement = after . plans . find ( ( p ) => p . id === preview . body . replacementPlanId ) ;
450507 if ( replacement ) {
451508 changes . push (
452- ...differences (
453- before . plans . find ( ( p ) => p . id === target ) ,
454- replacement ,
455- ) . filter ( ( row ) => row . label !== 'Display name' ) ,
509+ ...differences ( beforePlan , replacement , {
510+ before : aiLoggingMode ( preview . aiLoggingBefore , target ) ,
511+ after : aiLoggingMode ( preview . aiLoggingAfter , replacement . id ) ,
512+ } ) . filter ( ( row ) => row . label !== 'Display name' ) ,
456513 ) ;
457514 }
458515 }
@@ -542,11 +599,11 @@ export function PlanProgressPage({
542599 username ?: string ;
543600} ) {
544601 const [ state , setState ] = useState ( initial ) ;
545- const [ processed , setProcessed ] = useState ( initial . processed ) ;
602+ const [ counts , setCounts ] = useState ( { accounts : initial . accounts , projects : initial . projects } ) ;
546603 const [ running , setRunning ] = useState ( false ) ;
547604 useEffect ( ( ) => {
548605 setState ( initial ) ;
549- setProcessed ( initial . processed ) ;
606+ setCounts ( { accounts : initial . accounts , projects : initial . projects } ) ;
550607 setRunning ( ! initial . complete && ! initial . error ) ;
551608 const controller = new AbortController ( ) ;
552609 let timer : ReturnType < typeof setTimeout > ;
@@ -581,7 +638,10 @@ export function PlanProgressPage({
581638 return ;
582639 }
583640 setState ( next ) ;
584- setProcessed ( ( count ) => count + next . processed ) ;
641+ setCounts ( ( count ) => ( {
642+ accounts : count . accounts + ( next . accounts ?? 0 ) ,
643+ projects : count . projects + ( next . projects ?? 0 ) ,
644+ } ) ) ;
585645 previous = next ;
586646 if ( next . complete || next . error ) {
587647 setRunning ( false ) ;
@@ -622,7 +682,9 @@ export function PlanProgressPage({
622682 : state . error
623683 ? 'Account updates paused.'
624684 : 'Updating accounts…' } { ' ' }
625- { processed } accounts updated in this session.
685+ { counts . accounts } accounts updated
686+ { counts . projects ? `, AI logging published to ${ counts . projects } projects` : '' } in this
687+ session.
626688 </ p >
627689 { state . error && < p role = "alert" > { state . error } </ p > }
628690 { ! state . complete && (
0 commit comments