Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 7 additions & 20 deletions apps/website/src/components/workshop/ModelDetail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { sameFormValues } from '../../lib/workshop/form-values'
import { validateWorkshopMediaInputs } from '../../config/workshop-media-validation'
import { leaveForSignIn } from '../../config/workshop-return'
import { useSignInHref } from '../../composables/useSignInHref'
import { usePersonalWorkspaceSwitch } from '../../composables/usePersonalWorkspaceSwitch'
import { useTablist } from '../../composables/useTablist'
import type { WorkshopModelDetail } from '../../config/models-catalogue'
import type {
Expand Down Expand Up @@ -225,7 +226,7 @@ const attachments = computed(() =>
)
const revealed = ref(false)

const { user, session, sessionFailure, settled, ensureFresh, remint } =
const { user, session, sessionFailure, settled, ensureFresh } =
useWorkshopSession()
const { balance } = useWorkshopCredits()
const workshopEnabled = useWorkshopEnabled()
Expand Down Expand Up @@ -530,25 +531,11 @@ async function historyToken(): Promise<string> {
return result.session.token
}

const personalSwitchPending = ref(false)
const personalSwitchError = ref(false)

async function switchToPersonal() {
if (personalSwitchPending.value) return
personalSwitchPending.value = true
personalSwitchError.value = false
try {
const result = await remint(undefined, {
preserveCredentialOnTransientFailure: true
})
if (result?.status === 'ok') await refreshWorkshopCredits({ force: true })
else if (result?.status === 'error') personalSwitchError.value = true
} catch {
personalSwitchError.value = true
} finally {
personalSwitchPending.value = false
}
}
const {
pending: personalSwitchPending,
failed: personalSwitchError,
switchToPersonal
} = usePersonalWorkspaceSwitch()

onUnmounted(() => {
cancelRun()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import type {
Resolution
} from '../../../lib/workshop/cinematic-studio/catalog'
import { directionOption } from '../../../lib/workshop/cinematic-studio/catalog'
import type { ShotEstimate } from '../../../lib/workshop/cinematic-studio/estimate'
import type { StudioGate } from '../../../lib/workshop/cinematic-studio/gate'
import type { CinematicModel } from '../../../lib/workshop/cinematic-studio/models'
import type { Locale } from '../../../i18n/translations'
Expand All @@ -28,23 +29,25 @@ const {
direction,
aspect,
resolution,
takes,
references,
gate,
workspaceName,
rendering,
estimate,
credits,
openPopover,
locale = 'en'
} = defineProps<{
models: readonly CinematicModel[]
direction: Direction
aspect: AspectRatio
resolution: Resolution
takes: number
references: readonly File[]
gate: StudioGate
workspaceName?: string
rendering: boolean
estimate?: ShotEstimate
credits?: number
openPopover?: PopoverKey
locale?: Locale
}>()
Expand All @@ -57,6 +60,7 @@ const emit = defineEmits<{

const scene = defineModel<string>('scene', { required: true })
const modelSlug = defineModel<string>('model', { required: true })
const takes = defineModel<number>('takes', { required: true })

const modelOptions = computed(() =>
models.map((model) => ({
Expand Down Expand Up @@ -227,10 +231,13 @@ const chipClass = (key: PopoverKey) =>
:rendering
:can-generate="canGenerate"
:blocked-note="blockedNote"
:estimate
:credits
:locale
class="ml-auto"
@generate="emit('generate')"
@cancel="emit('cancel')"
@reduce-takes="takes = $event"
/>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<script setup lang="ts">
import { computed } from 'vue'

import { cn } from '@comfyorg/tailwind-utils'

import type { ShotEstimate } from '../../../lib/workshop/cinematic-studio/estimate'
import { formatCreditRange } from '../../../lib/workshop/cinematic-studio/estimate'
import type { Locale } from '../../../i18n/translations'
import { tc } from '../../../lib/workshop/cinematic-studio/copy'

const {
estimate,
wide = false,
locale = 'en'
} = defineProps<{
estimate?: ShotEstimate
wide?: boolean
locale?: Locale
}>()

function perTake(shot: ShotEstimate): string | undefined {
if (shot.takes === 1) return undefined
return tc('cinematic.credits.perTake', locale)
.replace('{takes}', String(shot.takes))
.replace('{credits}', formatCreditRange(shot.perTake, locale))
}

const cost = computed(() =>
estimate
? {
label: tc('cinematic.credits.estimate', locale).replace(
'{credits}',
formatCreditRange(estimate.total, locale)
),
detail: perTake(estimate)
}
: {
label: tc('cinematic.credits.varies', locale),
hint: tc('cinematic.credits.variesHint', locale)
}
)
</script>

<template>
<span
data-testid="cinematic-estimate"
:title="cost.hint"
:class="
cn('flex flex-col leading-tight', wide ? 'items-center' : 'items-end')
"
>
<span class="text-xs text-primary-warm-white">{{ cost.label }}</span>
<span v-if="cost.detail" class="text-[11px] text-primary-warm-gray">
{{ cost.detail }}
</span>
</span>
</template>
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<script setup lang="ts">
import { computed, ref, watch } from 'vue'

import Button from '@/components/ui/button/Button.vue'
import { usePersonalWorkspaceSwitch } from '../../../composables/usePersonalWorkspaceSwitch'
import { requestWorkshopBuyCredits } from '../../../config/workshop-buy-credits'
import {
useTopUpWatch,
useWorkshopCredits
} from '../../../config/workshop-credits'
import type { Locale } from '../../../i18n/translations'
import { t } from '../../../i18n/translations'

const {
member = false,
retryLabel,
locale = 'en'
} = defineProps<{
member?: boolean
retryLabel: string
locale?: Locale
}>()

const emit = defineEmits<{ retry: [] }>()

const topUp = useTopUpWatch()
const personal = usePersonalWorkspaceSwitch()
const { balance } = useWorkshopCredits()

const credits = computed(() =>
balance.value.status === 'ok' ? balance.value.credits : undefined
)
const creditsWhenSkipped = ref(credits.value)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TRIVIAL — the baseline is the balance when this component mounts, not when the takes were skipped. The take notice mounts only while its take is selected. So if the balance rises while another take is on screen (for example, after switching to personal from the Generate button), coming back to the skipped take sets the baseline to the new balance, and the notice offers "Add credits" instead of a retry. The summary usually stays mounted, so this is minor. Recording the balance on the take when the Router refuses it would make the comparison exact.

watch(credits, (value) => {
creditsWhenSkipped.value ??= value
})
const canRetry = computed(
() =>
topUp.value.status === 'landed' ||
(credits.value !== undefined &&
creditsWhenSkipped.value !== undefined &&
credits.value > creditsWhenSkipped.value)
)
</script>

<template>
<span class="inline-flex flex-col items-center gap-1.5">
<Button
v-if="canRetry"
size="sm"
class="rounded-full"
@click="emit('retry')"
>
{{ retryLabel }}
</Button>
<Button
v-else-if="member"
size="sm"
variant="outline"
class="rounded-full"
:disabled="personal.pending.value"
@click="personal.switchToPersonal"
>
{{
t(
personal.pending.value
? 'workshop.run.preparingSession'
: 'workshop.run.switchPersonal',
locale
)
}}
</Button>
<Button
v-else
size="sm"
class="rounded-full"
@click="requestWorkshopBuyCredits"
>
{{ t('workshop.run.buyCredits', locale) }}
</Button>
<span
v-if="personal.failed.value"
role="alert"
class="text-xs text-primary-comfy-red"
>
{{ t('nav.workspaceSwitchError', locale) }}
</span>
</span>
</template>
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<script setup lang="ts">
import { Coins } from '@lucide/vue'
import { computed } from 'vue'

import type { Take } from '../../../lib/workshop/cinematic-studio/reel'
import { isUnpaid } from '../../../lib/workshop/cinematic-studio/reel'
import type { Locale } from '../../../i18n/translations'
import { tc } from '../../../lib/workshop/cinematic-studio/copy'
import CinematicCreditAction from './CinematicCreditAction.vue'

const {
takes,
memberWorkspace,
locale = 'en'
} = defineProps<{
/** The takes of one shot. */
takes: readonly Take[]
memberWorkspace?: string
locale?: Locale
}>()

const emit = defineEmits<{ retry: [ids: string[]] }>()

const skipped = computed(() => takes.filter(isUnpaid))
</script>

<template>
<div
v-if="takes.length > 1 && skipped.length"
role="status"
data-testid="cinematic-credit-summary"
class="flex flex-wrap items-center justify-between gap-3 rounded-xl bg-primary-comfy-yellow/5 px-4 py-2.5 ring-1 ring-primary-comfy-yellow/25 ring-inset"
>
<span class="flex items-center gap-2 text-sm text-primary-warm-white">
<Coins
class="size-4 shrink-0 text-primary-comfy-yellow"
aria-hidden="true"
/>
{{
tc('cinematic.credits.skipped', locale)
.replace('{failed}', String(skipped.length))
.replace('{total}', String(takes.length))
}}
</span>
<CinematicCreditAction
:member="memberWorkspace !== undefined"
:retry-label="tc('cinematic.credits.retrySkipped', locale)"
:locale
@retry="
emit(
'retry',
skipped.map(({ id }) => id)
)
"
/>
</div>
</template>
Loading
Loading