-
-
Notifications
You must be signed in to change notification settings - Fork 211
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5bd8810
commit 74c9d0e
Showing
14 changed files
with
453 additions
and
1,149 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { cn } from '@/lib/utils' | ||
import { useTheme } from '@/services/ui/useTheme' | ||
|
||
import { Metrics } from './metrics' | ||
import { APP_REVISION } from '@/lib/core/constants' | ||
import { Tasks } from './tasks' | ||
|
||
export function BottomToolbar() { | ||
const theme = useTheme() | ||
|
||
return ( | ||
<div | ||
className={cn( | ||
`absolute bottom-0 flex flex-row`, | ||
`items-center justify-between`, | ||
`left-0 right-0 h-7`, | ||
`px-3`, | ||
`text-xs font-light text-stone-400` | ||
)} | ||
style={{ | ||
borderTop: 'solid 1px rgba(255,255,255,0.3)', | ||
backgroundColor: | ||
theme.editorMenuBgColor || theme.defaultBgColor || '#afafaf', | ||
// borderTopColor: theme.editorTextColor || theme.defaultBorderColor || "#bfbfbf", | ||
color: theme.editorTextColor || theme.defaultTextColor || '#ffffff', | ||
}} | ||
> | ||
<div className="flex flex-row space-x-3"> | ||
<div className="flex flex-row space-x-1"> | ||
<span className="text-stone-400/70">app version:</span> | ||
<span className="text-stone-300/70">{APP_REVISION}</span> | ||
</div> | ||
|
||
<Metrics /> | ||
</div> | ||
<div className="flex flex-row space-x-6"> | ||
<Tasks /> | ||
</div> | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import usePerformanceMeter from '@/lib/hooks/usePerformanceMeter' | ||
import { cn } from '@/lib/utils' | ||
|
||
export function Metrics() { | ||
const { isAvailable, isMeasuring, bytes, humanReadableString } = | ||
usePerformanceMeter({ | ||
delayBetweenMeasures: 20, | ||
}) | ||
console.log('debug:', { | ||
isAvailable, | ||
isMeasuring, | ||
bytes, | ||
humanReadableString, | ||
}) | ||
|
||
if (!isAvailable) { | ||
return null | ||
} | ||
|
||
return ( | ||
<div className="flex flex-row space-x-1"> | ||
<span className="text-stone-500">memory usage:</span> | ||
<span className="text-stone-400"> | ||
{!bytes ? 'waiting..' : humanReadableString || ''} | ||
</span> | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { TaskStatus, TaskVisibility } from '@aitube/clapper-services' | ||
|
||
import { | ||
Popover, | ||
PopoverContent, | ||
PopoverTrigger, | ||
} from '@/components/ui/popover' | ||
import { cn } from '@/lib/utils' | ||
import { useTasks } from '@/services' | ||
|
||
export function Tasks() { | ||
const { find, tasks } = useTasks() | ||
|
||
const runningBlockerTasks = find({ | ||
status: TaskStatus.RUNNING, | ||
visibility: TaskVisibility.BLOCKER, | ||
}) | ||
const runningBackgroundTasks = find({ | ||
status: TaskStatus.RUNNING, | ||
visibility: TaskVisibility.BACKGROUND, | ||
}) | ||
|
||
const nbRunningBackgroundTasks = runningBackgroundTasks.length | ||
const hasRunningBackgroundTasks = nbRunningBackgroundTasks > 0 | ||
const currentRunningBackgroundTaskProgress = | ||
runningBackgroundTasks[0]?.progress || 0 | ||
|
||
const nbRunningBlockerTasks = runningBlockerTasks.length | ||
const hasRunningBlockerTasks = nbRunningBlockerTasks > 0 | ||
const currentRunningBlockerTaskProgress = | ||
runningBlockerTasks[0]?.progress || 0 | ||
|
||
return ( | ||
<div className={cn(``)}> | ||
<Popover> | ||
<PopoverTrigger> | ||
{nbRunningBackgroundTasks || 'no'} pending tasks | ||
</PopoverTrigger> | ||
<PopoverContent> | ||
<div className={cn(`flex flex-col text-xs font-light`)}> | ||
{runningBackgroundTasks.map((task) => { | ||
return ( | ||
<div className="flex flex-row" key={task.id}> | ||
<div>{task.status}</div> | ||
<div>{task.priority}</div> | ||
<div>{task.category}</div> | ||
<div>{task.progress}%</div> | ||
</div> | ||
) | ||
})} | ||
</div> | ||
</PopoverContent> | ||
</Popover> | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { | ||
ClapProject, | ||
ClapSegment, | ||
ClapSegmentCategory, | ||
newClap, | ||
newSegment, | ||
} from '@aitube/clap' | ||
|
||
export async function getDemoGame() { | ||
const demo: ClapProject = newClap({ | ||
meta: { | ||
title: 'Demo Game', | ||
isInteractive: true, | ||
// isLoop: true, | ||
}, | ||
}) | ||
|
||
const startTimeInMs = 0 | ||
|
||
// 1 hour session | ||
const endTimeInMs = 60 * 60 * 1000 | ||
|
||
const defaultMessage: ClapSegment = newSegment({ | ||
track: 1, | ||
category: ClapSegmentCategory.INTERFACE, | ||
prompt: 'Hello world', | ||
label: 'Hello world', | ||
startTimeInMs, | ||
endTimeInMs, | ||
}) | ||
demo.segments.push(defaultMessage) | ||
|
||
const aiShouldRespondToMessage: ClapSegment = newSegment({ | ||
track: 2, | ||
category: ClapSegmentCategory.PHENOMENON, | ||
prompt: 'When the user asks a question, an assistant will answer', | ||
label: 'Assistant', | ||
startTimeInMs, | ||
endTimeInMs, | ||
}) | ||
demo.segments.push(aiShouldRespondToMessage) | ||
|
||
// TODO: experiment with a pong game too | ||
|
||
return demo | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { useState, useEffect, useCallback } from 'react' | ||
|
||
interface PerformanceMeterOptions { | ||
delayBetweenMeasures: number | ||
} | ||
|
||
interface PerformanceMeterResult { | ||
isAvailable: boolean | ||
isMeasuring: boolean | ||
bytes: number | null | ||
humanReadableString: string | null | ||
} | ||
|
||
const usePerformanceMeter = ({ | ||
delayBetweenMeasures, | ||
}: PerformanceMeterOptions): PerformanceMeterResult => { | ||
const [isAvailable, setIsAvailable] = useState<boolean>(false) | ||
const [isMeasuring, setIsMeasuring] = useState<boolean>(false) | ||
const [bytes, setBytes] = useState<number | null>(null) | ||
const [humanReadableString, setHumanReadableString] = useState<string | null>( | ||
null | ||
) | ||
|
||
const measureMemory = useCallback(async () => { | ||
if (!isAvailable) return | ||
|
||
setIsMeasuring(true) | ||
try { | ||
const result = await (performance as any).measureUserAgentSpecificMemory() | ||
setBytes(result.bytes) | ||
setHumanReadableString(formatBytes(result.bytes)) | ||
} catch (error) { | ||
console.error('Error measuring memory:', error) | ||
} finally { | ||
setIsMeasuring(false) | ||
} | ||
}, [isAvailable]) | ||
|
||
useEffect(() => { | ||
const checkAvailability = () => { | ||
const available = 'measureUserAgentSpecificMemory' in performance | ||
setIsAvailable(available) | ||
return available | ||
} | ||
|
||
if (checkAvailability()) { | ||
measureMemory() // Start measuring immediately | ||
const intervalId = setInterval(measureMemory, delayBetweenMeasures * 1000) | ||
return () => clearInterval(intervalId) | ||
} | ||
}, [delayBetweenMeasures, measureMemory]) | ||
|
||
const formatBytes = (bytes: number): string => { | ||
if (bytes === 0) return '0 Bytes' | ||
const k = 1024 | ||
const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'] | ||
const i = Math.floor(Math.log(bytes) / Math.log(k)) | ||
return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i] | ||
} | ||
|
||
return { isAvailable, isMeasuring, bytes, humanReadableString } | ||
} | ||
|
||
export default usePerformanceMeter |
Oops, something went wrong.