Repository navigation
feat(website): Cinematic Studio credit estimates and credit gating #18928
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
63f0825
fix(website): read a Router error bucket from the body when the heade…
benjcooley 72e4a05
feat(website): price a Router run from the size and references it ask…
benjcooley d68b7a7
feat(website): show a Cinematic Studio shot's estimated credits and g…
benjcooley d86439d
feat(website): give members their own credit copy and sum up unpaid t…
benjcooley 335e318
fix(website): split Cinematic Studio's Generate action, take strip an…
benjcooley 8e7111d
fix(website): offer skipped takes again whenever the balance rises, n…
benjcooley File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
57 changes: 57 additions & 0 deletions
57
apps/website/src/components/workshop/cinematic-studio/CinematicCostLabel.vue
This file contains hidden or 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,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> |
89 changes: 89 additions & 0 deletions
89
apps/website/src/components/workshop/cinematic-studio/CinematicCreditAction.vue
This file contains hidden or 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,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) | ||
| 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> | ||
57 changes: 57 additions & 0 deletions
57
apps/website/src/components/workshop/cinematic-studio/CinematicCreditSummary.vue
This file contains hidden or 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,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> |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.