@nodaro/shared 3.55.0 → 3.56.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/dist/{chunk-3CHOZ573.js → chunk-2AR3OXAA.js} +276 -17
- package/dist/chunk-2AR3OXAA.js.map +1 -0
- package/dist/{chunk-ZKHQSG76.js → chunk-2J6NTA5I.js} +4 -4
- package/dist/{chunk-ZKHQSG76.js.map → chunk-2J6NTA5I.js.map} +1 -1
- package/dist/{chunk-AGTCHDG5.cjs → chunk-33P5FI2U.cjs} +6 -6
- package/dist/{chunk-AGTCHDG5.cjs.map → chunk-33P5FI2U.cjs.map} +1 -1
- package/dist/{chunk-HG3KKCJJ.js → chunk-4JODLC2N.js} +3 -3
- package/dist/{chunk-HG3KKCJJ.js.map → chunk-4JODLC2N.js.map} +1 -1
- package/dist/{chunk-N3WL6IOJ.js → chunk-4O5STV7N.js} +55 -5
- package/dist/chunk-4O5STV7N.js.map +1 -0
- package/dist/chunk-4ONS6QRT.js +42 -0
- package/dist/chunk-4ONS6QRT.js.map +1 -0
- package/dist/{chunk-E4YES25K.js → chunk-55FQBILM.js} +4 -4
- package/dist/{chunk-E4YES25K.js.map → chunk-55FQBILM.js.map} +1 -1
- package/dist/{chunk-ZWB3NG4M.js → chunk-62ZQQA7L.js} +3 -3
- package/dist/{chunk-ZWB3NG4M.js.map → chunk-62ZQQA7L.js.map} +1 -1
- package/dist/{chunk-HEF4BIMA.js → chunk-6GGHM33Z.js} +4 -4
- package/dist/{chunk-HEF4BIMA.js.map → chunk-6GGHM33Z.js.map} +1 -1
- package/dist/{chunk-KMSEU6FK.js → chunk-7DGJDISO.js} +3 -3
- package/dist/{chunk-KMSEU6FK.js.map → chunk-7DGJDISO.js.map} +1 -1
- package/dist/{chunk-2OYV6K7D.cjs → chunk-7JM5EZF3.cjs} +13 -13
- package/dist/{chunk-2OYV6K7D.cjs.map → chunk-7JM5EZF3.cjs.map} +1 -1
- package/dist/chunk-AKDJKMAL.cjs +48 -0
- package/dist/chunk-AKDJKMAL.cjs.map +1 -0
- package/dist/{chunk-HZL7QMXK.js → chunk-AWS4BWEC.js} +7 -3
- package/dist/chunk-AWS4BWEC.js.map +1 -0
- package/dist/{chunk-5DVDHL7Y.js → chunk-AZDVL7IM.js} +20 -6
- package/dist/chunk-AZDVL7IM.js.map +1 -0
- package/dist/{chunk-2R74OU76.cjs → chunk-CGZLENU4.cjs} +276 -16
- package/dist/chunk-CGZLENU4.cjs.map +1 -0
- package/dist/{chunk-G7IUQKRU.cjs → chunk-CLKU3ZIU.cjs} +51 -51
- package/dist/{chunk-G7IUQKRU.cjs.map → chunk-CLKU3ZIU.cjs.map} +1 -1
- package/dist/{chunk-MCIBQ5BF.js → chunk-DURFRWAW.js} +9 -9
- package/dist/{chunk-MCIBQ5BF.js.map → chunk-DURFRWAW.js.map} +1 -1
- package/dist/{chunk-C5S75476.js → chunk-EAKO7PGC.js} +8 -4
- package/dist/{chunk-C5S75476.js.map → chunk-EAKO7PGC.js.map} +1 -1
- package/dist/{chunk-IPCWYKX5.cjs → chunk-EWARI452.cjs} +60 -46
- package/dist/chunk-EWARI452.cjs.map +1 -0
- package/dist/{chunk-C6IQCKJT.cjs → chunk-FCQYMPUQ.cjs} +4 -4
- package/dist/{chunk-C6IQCKJT.cjs.map → chunk-FCQYMPUQ.cjs.map} +1 -1
- package/dist/{chunk-WVACGZYV.cjs → chunk-H7VMJBNZ.cjs} +8 -8
- package/dist/{chunk-WVACGZYV.cjs.map → chunk-H7VMJBNZ.cjs.map} +1 -1
- package/dist/{chunk-SEEQ3H22.cjs → chunk-HWJE4FNS.cjs} +59 -6
- package/dist/chunk-HWJE4FNS.cjs.map +1 -0
- package/dist/{chunk-3633VD2M.cjs → chunk-IKP4GOWZ.cjs} +8 -8
- package/dist/{chunk-3633VD2M.cjs.map → chunk-IKP4GOWZ.cjs.map} +1 -1
- package/dist/{chunk-5R6LTKE5.cjs → chunk-ILMHITHK.cjs} +5 -5
- package/dist/{chunk-5R6LTKE5.cjs.map → chunk-ILMHITHK.cjs.map} +1 -1
- package/dist/chunk-IOET54EV.js +39 -0
- package/dist/chunk-IOET54EV.js.map +1 -0
- package/dist/{chunk-ZAK276QF.js → chunk-JHTYULY2.js} +4 -4
- package/dist/{chunk-ZAK276QF.js.map → chunk-JHTYULY2.js.map} +1 -1
- package/dist/{chunk-OVIIJVXH.cjs → chunk-JO3XSUO2.cjs} +21 -21
- package/dist/{chunk-OVIIJVXH.cjs.map → chunk-JO3XSUO2.cjs.map} +1 -1
- package/dist/{chunk-UWMXMLMV.js → chunk-MROKQP4U.js} +3 -3
- package/dist/{chunk-UWMXMLMV.js.map → chunk-MROKQP4U.js.map} +1 -1
- package/dist/{chunk-J4CVGAAV.cjs → chunk-NZRG5CXQ.cjs} +7 -2
- package/dist/chunk-NZRG5CXQ.cjs.map +1 -0
- package/dist/{chunk-KM35K2M5.cjs → chunk-O7DXNX5J.cjs} +92 -25
- package/dist/chunk-O7DXNX5J.cjs.map +1 -0
- package/dist/chunk-OWNPYQSH.cjs +283 -0
- package/dist/chunk-OWNPYQSH.cjs.map +1 -0
- package/dist/{chunk-FIYVKW7F.cjs → chunk-PFXPAWPQ.cjs} +12 -12
- package/dist/{chunk-FIYVKW7F.cjs.map → chunk-PFXPAWPQ.cjs.map} +1 -1
- package/dist/chunk-QSWUSXRL.cjs +53 -0
- package/dist/chunk-QSWUSXRL.cjs.map +1 -0
- package/dist/{chunk-MGJR5OXO.js → chunk-RX7WII6I.js} +5 -5
- package/dist/{chunk-MGJR5OXO.js.map → chunk-RX7WII6I.js.map} +1 -1
- package/dist/chunk-S7FCFQ6X.js +255 -0
- package/dist/chunk-S7FCFQ6X.js.map +1 -0
- package/dist/{chunk-YBZQXZ6A.js → chunk-ST4WQ6ND.js} +68 -8
- package/dist/chunk-ST4WQ6ND.js.map +1 -0
- package/dist/{chunk-LKCPFD5X.js → chunk-SWVGHAYO.js} +5 -3
- package/dist/chunk-SWVGHAYO.js.map +1 -0
- package/dist/{chunk-MTUNORQB.cjs → chunk-TSKYEREJ.cjs} +11 -11
- package/dist/{chunk-MTUNORQB.cjs.map → chunk-TSKYEREJ.cjs.map} +1 -1
- package/dist/{chunk-LYWJAXPT.js → chunk-UMPZR56R.js} +3 -3
- package/dist/{chunk-LYWJAXPT.js.map → chunk-UMPZR56R.js.map} +1 -1
- package/dist/{chunk-6HUWQLF2.cjs → chunk-WKCFTWLO.cjs} +6 -6
- package/dist/{chunk-6HUWQLF2.cjs.map → chunk-WKCFTWLO.cjs.map} +1 -1
- package/dist/chunk-XPUGMYAJ.cjs +27 -0
- package/dist/{chunk-HD45Y7QU.cjs.map → chunk-XPUGMYAJ.cjs.map} +1 -1
- package/dist/{chunk-G5NTNQ7W.cjs → chunk-XROE3CAS.cjs} +5 -3
- package/dist/chunk-XROE3CAS.cjs.map +1 -0
- package/dist/{chunk-SZUDEFX2.cjs → chunk-ZXDH3L3P.cjs} +43 -39
- package/dist/{chunk-SZUDEFX2.cjs.map → chunk-ZXDH3L3P.cjs.map} +1 -1
- package/dist/{chunk-25KAGSPT.js → chunk-ZYITB47P.js} +3 -3
- package/dist/{chunk-25KAGSPT.js.map → chunk-ZYITB47P.js.map} +1 -1
- package/dist/entries/apps.cjs +43 -42
- package/dist/entries/apps.js +8 -7
- package/dist/entries/credits.cjs +151 -150
- package/dist/entries/credits.d.cts +4 -1
- package/dist/entries/credits.d.ts +4 -1
- package/dist/entries/credits.js +8 -7
- package/dist/entries/entities.cjs +125 -125
- package/dist/entries/entities.d.cts +1 -1
- package/dist/entries/entities.d.ts +1 -1
- package/dist/entries/entities.js +1 -1
- package/dist/entries/llm-models.d.cts +1 -1
- package/dist/entries/llm-models.d.ts +1 -1
- package/dist/entries/model-catalog.cjs +127 -66
- package/dist/entries/model-catalog.d.cts +61 -9
- package/dist/entries/model-catalog.d.ts +61 -9
- package/dist/entries/model-catalog.js +5 -4
- package/dist/entries/models.cjs +304 -276
- package/dist/entries/models.d.cts +3 -3
- package/dist/entries/models.d.ts +3 -3
- package/dist/entries/models.js +4 -4
- package/dist/entries/nodes.cjs +208 -207
- package/dist/entries/nodes.d.cts +1 -1
- package/dist/entries/nodes.d.ts +1 -1
- package/dist/entries/nodes.js +10 -9
- package/dist/entries/pipeline.cjs +161 -149
- package/dist/entries/pipeline.d.cts +165 -26
- package/dist/entries/pipeline.d.ts +165 -26
- package/dist/entries/pipeline.js +3 -3
- package/dist/entries/runtime-config.cjs +116 -0
- package/dist/entries/runtime-config.cjs.map +1 -0
- package/dist/entries/runtime-config.d.cts +308 -0
- package/dist/entries/runtime-config.d.ts +308 -0
- package/dist/entries/runtime-config.js +3 -0
- package/dist/entries/runtime-config.js.map +1 -0
- package/dist/entries/ugc.cjs +71 -71
- package/dist/entries/ugc.js +4 -4
- package/dist/entries/video.cjs +117 -117
- package/dist/entries/video.js +4 -4
- package/dist/entries/workflow.cjs +150 -146
- package/dist/entries/workflow.d.cts +8 -1
- package/dist/entries/workflow.d.ts +8 -1
- package/dist/entries/workflow.js +2 -2
- package/dist/index.cjs +3156 -2942
- package/dist/index.d.cts +6 -5
- package/dist/index.d.ts +6 -5
- package/dist/index.js +23 -21
- package/dist/{model-catalog-Dm2UiwUe.d.ts → model-catalog-vQ3NWn24.d.cts} +33 -2
- package/dist/{model-catalog-Dm2UiwUe.d.cts → model-catalog-vQ3NWn24.d.ts} +33 -2
- package/dist/{model-constants-DZUGVDOw.d.ts → model-constants-QZVHZX25.d.cts} +35 -6
- package/dist/{model-constants-DZUGVDOw.d.cts → model-constants-QZVHZX25.d.ts} +35 -6
- package/package.json +6 -1
- package/src/__tests__/fixtures/root-exports.baseline.json +2 -0
- package/src/__tests__/gpt-image-2-6.test.ts +277 -0
- package/src/__tests__/image-model-roles.test.ts +28 -9
- package/src/__tests__/runtime-config.test.ts +398 -0
- package/src/__tests__/voice-library-values.test.ts +24 -0
- package/src/credit-identifiers.ts +42 -0
- package/src/entries/model-catalog.ts +17 -0
- package/src/entries/models.ts +9 -0
- package/src/entries/runtime-config.ts +51 -0
- package/src/entries/workflow.ts +1 -1
- package/src/gpt-image-2-6.ts +104 -0
- package/src/image-model-roles.ts +31 -10
- package/src/index.ts +1 -0
- package/src/model-catalog.ts +302 -14
- package/src/model-constants.ts +84 -3
- package/src/node-default-mappings.ts +4 -0
- package/src/node-refs.ts +11 -0
- package/src/pipeline-types.ts +2 -0
- package/src/reference-board-templates.ts +2 -0
- package/src/runtime-config/contract.ts +492 -0
- package/src/runtime-config/worlds.ts +77 -0
- package/src/voices.ts +175 -2
- package/dist/chunk-2R74OU76.cjs.map +0 -1
- package/dist/chunk-3CHOZ573.js.map +0 -1
- package/dist/chunk-5DVDHL7Y.js.map +0 -1
- package/dist/chunk-ATWLKUAI.cjs +0 -34
- package/dist/chunk-ATWLKUAI.cjs.map +0 -1
- package/dist/chunk-DUL5ZLTJ.js +0 -29
- package/dist/chunk-DUL5ZLTJ.js.map +0 -1
- package/dist/chunk-G5NTNQ7W.cjs.map +0 -1
- package/dist/chunk-HD45Y7QU.cjs +0 -27
- package/dist/chunk-HZL7QMXK.js.map +0 -1
- package/dist/chunk-IPCWYKX5.cjs.map +0 -1
- package/dist/chunk-J4CVGAAV.cjs.map +0 -1
- package/dist/chunk-KM35K2M5.cjs.map +0 -1
- package/dist/chunk-LKCPFD5X.js.map +0 -1
- package/dist/chunk-N3WL6IOJ.js.map +0 -1
- package/dist/chunk-SEEQ3H22.cjs.map +0 -1
- package/dist/chunk-YBZQXZ6A.js.map +0 -1
|
@@ -0,0 +1,492 @@
|
|
|
1
|
+
import { isWorldId, type SurfaceWorlds, type WorldId } from "./worlds.js"
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The deployment runtime config — the object a Nodaro platform container
|
|
5
|
+
* writes to `/config.js` at boot as `window.__NODARO_RUNTIME__`, and that every
|
|
6
|
+
* product served from the same site reads before its app starts. One published
|
|
7
|
+
* build then serves any deployment without a rebuild.
|
|
8
|
+
*
|
|
9
|
+
* This module is the contract between that writer and its readers: the key
|
|
10
|
+
* names, their shapes, and a lenient parser. Structural vocabulary only: no
|
|
11
|
+
* content, no prices, nothing about any one deployment. The platform's own
|
|
12
|
+
* schema stays the authority on what a deployment may set. What reaches the
|
|
13
|
+
* page has already been validated there and stripped of every server-only
|
|
14
|
+
* value; this parser only refuses to hand a reader a value of the wrong type.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/** The global `/config.js` assigns. */
|
|
18
|
+
export const RUNTIME_CONFIG_GLOBAL = "__NODARO_RUNTIME__"
|
|
19
|
+
|
|
20
|
+
/** Every top-level key `/config.js` can carry. */
|
|
21
|
+
export const RUNTIME_CONFIG_KEYS = Object.freeze([
|
|
22
|
+
"apiUrl",
|
|
23
|
+
"supabaseUrl",
|
|
24
|
+
"supabaseAnonKey",
|
|
25
|
+
"freecutUrl",
|
|
26
|
+
"audiomassUrl",
|
|
27
|
+
"defaultLocale",
|
|
28
|
+
"surface",
|
|
29
|
+
"moderation",
|
|
30
|
+
"previewStopRule",
|
|
31
|
+
"mediaOrigin",
|
|
32
|
+
] as const)
|
|
33
|
+
export type RuntimeConfigKey = (typeof RUNTIME_CONFIG_KEYS)[number]
|
|
34
|
+
|
|
35
|
+
export const SURFACE_HEADER_MODES = Object.freeze(["default", "white-label"] as const)
|
|
36
|
+
/** `white-label`: the deployment's own header, with no platform links or art. */
|
|
37
|
+
export type SurfaceHeaderMode = (typeof SURFACE_HEADER_MODES)[number]
|
|
38
|
+
|
|
39
|
+
export const SURFACE_CATALOG_IMAGES = Object.freeze(["default", "none", "own"] as const)
|
|
40
|
+
/** Pictures on picker options: the platform's (`default`), none, or the deployment's own (`own`). */
|
|
41
|
+
export type SurfaceCatalogImages = (typeof SURFACE_CATALOG_IMAGES)[number]
|
|
42
|
+
|
|
43
|
+
export interface RuntimeSurfaceSibling {
|
|
44
|
+
readonly label: string
|
|
45
|
+
readonly url: string
|
|
46
|
+
readonly urlByHost?: Readonly<Record<string, string>>
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export interface RuntimeSurfaceBrand {
|
|
50
|
+
readonly productName: string
|
|
51
|
+
readonly description?: string
|
|
52
|
+
readonly wordmark?: string
|
|
53
|
+
readonly platformLinks?: boolean
|
|
54
|
+
/** A same-site path (`/brand/logo.svg`) or an https URL. */
|
|
55
|
+
readonly logo?: string
|
|
56
|
+
/** The page's icons, each a path on this site (`/brand/favicon.svg`): see `isSameSitePath`. */
|
|
57
|
+
readonly favicon?: readonly string[]
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Overrides of a product's UI strings, `product → locale id → message key →
|
|
62
|
+
* text`. Each product reads only its own namespace (`UI_STRING_PRODUCTS`). The
|
|
63
|
+
* platform checks every entry against that product's dictionary before it
|
|
64
|
+
* reaches a page: the key exists, the locale is one the deployment offers, the
|
|
65
|
+
* text is plain and keeps the base string's `{placeholders}`.
|
|
66
|
+
*/
|
|
67
|
+
export type RuntimeSurfaceStrings = Readonly<Record<string, Readonly<Record<string, Readonly<Record<string, string>>>>>>
|
|
68
|
+
|
|
69
|
+
/** The display side of billing. The server-only billing keys never reach a page. */
|
|
70
|
+
export interface RuntimeSurfaceBilling {
|
|
71
|
+
readonly costTab: "inherit" | "hidden"
|
|
72
|
+
readonly sidebarCard: "inherit" | "hidden"
|
|
73
|
+
readonly selfServe: boolean
|
|
74
|
+
readonly unitLabel?: string
|
|
75
|
+
readonly unitRate?: number
|
|
76
|
+
readonly unitDecimals?: number
|
|
77
|
+
/**
|
|
78
|
+
* The unit's word per interface language, beside the single `unitLabel`: a
|
|
79
|
+
* language the deployment gives no word for uses `unitLabel`. Read with
|
|
80
|
+
* `surfaceUnitLabel`.
|
|
81
|
+
*/
|
|
82
|
+
readonly unitLabels?: Readonly<Record<string, string>>
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* The deployment's surface profile as a page receives it, with every default
|
|
87
|
+
* applied. Lists that are empty keep the product's own default, except
|
|
88
|
+
* `worlds.allow` (see `SurfaceWorlds`).
|
|
89
|
+
*/
|
|
90
|
+
export interface RuntimeSurface {
|
|
91
|
+
readonly nav: { readonly hide: readonly string[] }
|
|
92
|
+
readonly features: { readonly hide: readonly string[] }
|
|
93
|
+
readonly dashboard: { readonly tabs: readonly string[] }
|
|
94
|
+
readonly nodes: { readonly deny: readonly string[]; readonly allow: readonly string[] }
|
|
95
|
+
readonly models: { readonly deny: readonly string[]; readonly allow: readonly string[] }
|
|
96
|
+
/** `requireSignIn`: no guest visits. When the deployment does not say, true exactly when sign-in is SSO-only. */
|
|
97
|
+
readonly auth: { readonly methods: readonly string[]; readonly ssoLabel?: string; readonly requireSignIn: boolean }
|
|
98
|
+
readonly siblings: { readonly apps: readonly RuntimeSurfaceSibling[] }
|
|
99
|
+
readonly brand: RuntimeSurfaceBrand
|
|
100
|
+
/** `offered`: the languages a visitor may pick from; absent = every language the product ships. */
|
|
101
|
+
readonly locale: { readonly default?: string; readonly picker: boolean; readonly offered?: readonly string[] }
|
|
102
|
+
readonly outputs: { readonly allowPublic: boolean }
|
|
103
|
+
readonly voice: { readonly allowedGenders: readonly string[] }
|
|
104
|
+
readonly billing: RuntimeSurfaceBilling
|
|
105
|
+
readonly catalogs: { readonly required: boolean; readonly factoryPresets: boolean; readonly images: SurfaceCatalogImages }
|
|
106
|
+
/** `links`: whether media may be imported from a link to another site. */
|
|
107
|
+
readonly imports: { readonly links: boolean }
|
|
108
|
+
readonly header: SurfaceHeaderMode
|
|
109
|
+
readonly worlds: SurfaceWorlds
|
|
110
|
+
/** The deployment's own wording for UI strings; `{}` = none. Read with `surfaceStringOverride`. */
|
|
111
|
+
readonly strings: RuntimeSurfaceStrings
|
|
112
|
+
/** Carried as given; no reader acts on it. */
|
|
113
|
+
readonly catalogPolicy?: unknown
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export interface NodaroRuntimeConfig {
|
|
117
|
+
/** The API base. `"/"` means this page's own origin: see `resolveRuntimeApiBase`. */
|
|
118
|
+
readonly apiUrl?: string
|
|
119
|
+
/** The Supabase URL. `"/supabase"` means this page's own origin: see `resolveRuntimeSupabaseUrl`. */
|
|
120
|
+
readonly supabaseUrl?: string
|
|
121
|
+
readonly supabaseAnonKey?: string
|
|
122
|
+
/** The platform editor's embedded video editor. */
|
|
123
|
+
readonly freecutUrl?: string
|
|
124
|
+
/** The platform editor's embedded audio editor. */
|
|
125
|
+
readonly audiomassUrl?: string
|
|
126
|
+
/** The language a first-time visitor starts in. */
|
|
127
|
+
readonly defaultLocale?: string
|
|
128
|
+
/** Present only when the deployment configured a surface profile. */
|
|
129
|
+
readonly surface?: RuntimeSurface
|
|
130
|
+
/** The platform editor's upload-moderation capability. */
|
|
131
|
+
readonly moderation?: { readonly uploadImage?: boolean }
|
|
132
|
+
/** A platform editor rollout flag. */
|
|
133
|
+
readonly previewStopRule?: boolean
|
|
134
|
+
/**
|
|
135
|
+
* The https origin this deployment serves user media from
|
|
136
|
+
* (`https://media.example.com`). Present only on a white-label deployment
|
|
137
|
+
* whose public media URL is https; absent, a reader trusts no media host
|
|
138
|
+
* beyond its own site.
|
|
139
|
+
*/
|
|
140
|
+
readonly mediaOrigin?: string
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// ── Rules shared by the platform and its readers ─────────────────────────────
|
|
144
|
+
|
|
145
|
+
/** Sign-in is SSO-only when SSO is the one method offered. */
|
|
146
|
+
export function isSsoOnly(methods: readonly unknown[]): boolean {
|
|
147
|
+
return methods.length > 0 && methods.every((m) => m === "sso")
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/** An explicit `requireSignIn` wins; otherwise a deployment requires sign-in exactly when it is SSO-only. */
|
|
151
|
+
export function surfaceRequiresSignIn(auth: { readonly methods?: unknown; readonly requireSignIn?: unknown } | undefined): boolean {
|
|
152
|
+
if (typeof auth?.requireSignIn === "boolean") return auth.requireSignIn
|
|
153
|
+
return isSsoOnly(strings(auth?.methods))
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// Whitespace, control characters and backslashes never belong in a logo
|
|
157
|
+
// reference, and a browser reads `/\host` as `//host`: another site.
|
|
158
|
+
const UNSAFE_REF_CHARS = /[\s\u0000-\u001f\u007f\\]/
|
|
159
|
+
const PROBE_ORIGIN = "https://origin.invalid"
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* A brand logo reference a page may load: a path on the page's own site
|
|
163
|
+
* (`/brand/logo.svg`), or an https URL without credentials. A protocol-relative
|
|
164
|
+
* `//host/…`, any other scheme (`http:`, `data:`, `javascript:`) and anything
|
|
165
|
+
* with whitespace or a backslash is not one.
|
|
166
|
+
*/
|
|
167
|
+
export function isBrandLogoRef(value: unknown): value is string {
|
|
168
|
+
if (typeof value !== "string" || value.length === 0 || UNSAFE_REF_CHARS.test(value)) return false
|
|
169
|
+
try {
|
|
170
|
+
if (value.startsWith("/")) return !value.startsWith("//") && new URL(value, PROBE_ORIGIN).origin === PROBE_ORIGIN
|
|
171
|
+
const url = new URL(value)
|
|
172
|
+
return url.protocol === "https:" && url.hostname.length > 0 && !url.username && !url.password
|
|
173
|
+
} catch {
|
|
174
|
+
return false
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// Quotes, angle brackets and backticks would end an HTML attribute that holds
|
|
179
|
+
// the path, and none belongs in a path anyway.
|
|
180
|
+
const HTML_SPECIAL_CHARS = /["'<>`]/
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* A path on the page's own site (`/brand/favicon.svg`, `/icon.png?v=2`): what
|
|
184
|
+
* `brand.favicon` holds, written into the page's `<head>` as a link. Stricter
|
|
185
|
+
* than `isBrandLogoRef`: no URL to another site at all, and no character that
|
|
186
|
+
* could end an HTML attribute.
|
|
187
|
+
*/
|
|
188
|
+
export function isSameSitePath(value: unknown): value is string {
|
|
189
|
+
return typeof value === "string" && value.startsWith("/") && !HTML_SPECIAL_CHARS.test(value) && isBrandLogoRef(value)
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* The products whose UI strings a deployment may override, each keyed in
|
|
194
|
+
* `surface.strings` by its id and checked against that product's own
|
|
195
|
+
* dictionary. `flow`: the platform's workflow editor; `tools`: the tools app;
|
|
196
|
+
* `voice`: the voice app. One profile words them all. A product adopts the
|
|
197
|
+
* overrides by adding its id here and giving the platform its key manifest
|
|
198
|
+
* (`uiStringManifestFile`), which a deployment composing the app into one
|
|
199
|
+
* image copies next to Flow's own.
|
|
200
|
+
*/
|
|
201
|
+
export const UI_STRING_PRODUCTS = Object.freeze(["flow", "tools", "voice"] as const)
|
|
202
|
+
export type UiStringProduct = (typeof UI_STRING_PRODUCTS)[number]
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* What a product's build emits beside its output so the platform can check a
|
|
206
|
+
* deployment's overrides at boot: every key of its base (English) dictionary
|
|
207
|
+
* with the placeholder names that key's text uses, and the locales the product
|
|
208
|
+
* offers. Keys and names only, never the text.
|
|
209
|
+
*/
|
|
210
|
+
export interface UiStringManifest {
|
|
211
|
+
/** The `surface.strings` namespace the dictionary answers to (`UI_STRING_PRODUCTS`). */
|
|
212
|
+
readonly product: string
|
|
213
|
+
/** The locales overrides may target when the deployment sets no `locale.offered`. */
|
|
214
|
+
readonly locales: readonly string[]
|
|
215
|
+
/** Every key a deployment may override → the placeholder names its base text uses, sorted. */
|
|
216
|
+
readonly keys: Readonly<Record<string, readonly string[]>>
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/** The manifest's file name, at the root of the product's build output. */
|
|
220
|
+
export function uiStringManifestFile(product: string): string {
|
|
221
|
+
return `ui-strings-manifest.${product}.json`
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
// `{name}`: anything else in braces (`{{now}}`, `{image:1}`, `{ variables`) is
|
|
225
|
+
// text, the same way the dictionaries' interpolation reads it.
|
|
226
|
+
const UI_STRING_PLACEHOLDER = /\{(\w+)\}/g
|
|
227
|
+
|
|
228
|
+
/** The placeholder names `text` uses, each once, sorted. */
|
|
229
|
+
export function uiStringPlaceholders(text: string): string[] {
|
|
230
|
+
return [...new Set(Array.from(text.matchAll(UI_STRING_PLACEHOLDER), (m) => m[1]))].sort()
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* The manifest of a base dictionary. A key whose base text is blank is left
|
|
235
|
+
* out: it is grammar data (a word's grammatical gender, the gap between two
|
|
236
|
+
* joined fragments), not wording, and overriding it would only break the
|
|
237
|
+
* sentences built from it.
|
|
238
|
+
*/
|
|
239
|
+
export function buildUiStringManifest(product: string, dict: Readonly<Record<string, string>>, locales: readonly string[]): UiStringManifest {
|
|
240
|
+
const keys = Object.entries(dict)
|
|
241
|
+
.filter(([, text]) => text.trim() !== "")
|
|
242
|
+
.map(([key, text]): [string, string[]] => [key, uiStringPlaceholders(text)])
|
|
243
|
+
return { product, locales: [...locales], keys: Object.fromEntries(keys) }
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/** The deployment's text for `key` in `locale` of `product`, or undefined. */
|
|
247
|
+
export function surfaceStringOverride(strings: RuntimeSurfaceStrings | undefined, product: string, locale: string, key: string): string | undefined {
|
|
248
|
+
const byLocale = strings && Object.hasOwn(strings, product) ? strings[product] : undefined
|
|
249
|
+
const texts = byLocale && Object.hasOwn(byLocale, locale) ? byLocale[locale] : undefined
|
|
250
|
+
const text = texts && Object.hasOwn(texts, key) ? texts[key] : undefined
|
|
251
|
+
return typeof text === "string" ? text : undefined
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* The deployment's word for its unit in `locale`: the `billing.unitLabels`
|
|
256
|
+
* entry for that language, else its single `unitLabel` (`single`). `labels` is
|
|
257
|
+
* the map as it arrives, on the surface or on a `display` object beside its
|
|
258
|
+
* `unit`.
|
|
259
|
+
*/
|
|
260
|
+
export function surfaceUnitLabel(labels: Readonly<Record<string, string>> | undefined, locale: string | undefined, single: string): string {
|
|
261
|
+
const word = labels && locale !== undefined && Object.hasOwn(labels, locale) ? labels[locale] : undefined
|
|
262
|
+
return typeof word === "string" && word.length > 0 ? word : single
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* An https origin, spelled exactly as a browser spells one
|
|
267
|
+
* (`https://media.example.com`, a port only when it is not 443): what
|
|
268
|
+
* `new URL(src).origin` is compared with, so a path, a trailing slash,
|
|
269
|
+
* credentials, another letter case or any other scheme could never match, and
|
|
270
|
+
* is not one.
|
|
271
|
+
*/
|
|
272
|
+
export function isHttpsOrigin(value: unknown): value is string {
|
|
273
|
+
if (typeof value !== "string") return false
|
|
274
|
+
try {
|
|
275
|
+
const url = new URL(value)
|
|
276
|
+
return url.protocol === "https:" && url.origin === value
|
|
277
|
+
} catch {
|
|
278
|
+
return false
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
/**
|
|
283
|
+
* The base a client builds API URLs on. `"/"` is the same-origin sentinel (a
|
|
284
|
+
* site answering on more than one hostname cannot name one) and resolves to
|
|
285
|
+
* `""`: build every URL relative to the page. `undefined` when the config names
|
|
286
|
+
* none, so the app keeps its own build-time value. It never makes up a URL.
|
|
287
|
+
*/
|
|
288
|
+
export function resolveRuntimeApiBase(cfg: Pick<NodaroRuntimeConfig, "apiUrl"> | undefined): string | undefined {
|
|
289
|
+
const value = typeof cfg?.apiUrl === "string" ? cfg.apiUrl.trim() : ""
|
|
290
|
+
if (!value) return undefined
|
|
291
|
+
return value === "/" ? "" : value
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
/**
|
|
295
|
+
* The Supabase URL a browser client uses. supabase-js needs an absolute URL, so
|
|
296
|
+
* the same-origin sentinel `"/supabase"` resolves against `origin`, the page's
|
|
297
|
+
* own (`location.origin`). `undefined` when the config names none.
|
|
298
|
+
*/
|
|
299
|
+
export function resolveRuntimeSupabaseUrl(cfg: Pick<NodaroRuntimeConfig, "supabaseUrl"> | undefined, origin: string): string | undefined {
|
|
300
|
+
const value = typeof cfg?.supabaseUrl === "string" ? cfg.supabaseUrl.trim() : ""
|
|
301
|
+
if (!value) return undefined
|
|
302
|
+
return value === "/supabase" ? `${origin.replace(/\/+$/, "")}/supabase` : value
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
// ── The parser ───────────────────────────────────────────────────────────────
|
|
306
|
+
|
|
307
|
+
type Rec = Readonly<Record<string, unknown>>
|
|
308
|
+
|
|
309
|
+
function isRecord(value: unknown): value is Rec {
|
|
310
|
+
return typeof value === "object" && value !== null && !Array.isArray(value)
|
|
311
|
+
}
|
|
312
|
+
const record = (value: unknown): Rec => (isRecord(value) ? value : {})
|
|
313
|
+
function strings(value: unknown): string[] {
|
|
314
|
+
return Array.isArray(value) ? value.filter((x): x is string => typeof x === "string") : []
|
|
315
|
+
}
|
|
316
|
+
const optional = <K extends string, V>(key: K, value: V | undefined): { [P in K]?: V } =>
|
|
317
|
+
(value === undefined ? {} : { [key]: value }) as { [P in K]?: V }
|
|
318
|
+
const asString = (value: unknown): string | undefined => (typeof value === "string" ? value : undefined)
|
|
319
|
+
const asBoolean = (value: unknown): boolean | undefined => (typeof value === "boolean" ? value : undefined)
|
|
320
|
+
|
|
321
|
+
function siblingApps(value: unknown): RuntimeSurfaceSibling[] {
|
|
322
|
+
if (!Array.isArray(value)) return []
|
|
323
|
+
return value.flatMap((raw) => {
|
|
324
|
+
if (!isRecord(raw) || typeof raw.label !== "string" || typeof raw.url !== "string") return []
|
|
325
|
+
const byHost = isRecord(raw.urlByHost)
|
|
326
|
+
? Object.fromEntries(Object.entries(raw.urlByHost).filter((e): e is [string, string] => typeof e[1] === "string"))
|
|
327
|
+
: {}
|
|
328
|
+
return [{ label: raw.label, url: raw.url, ...optional("urlByHost", Object.keys(byHost).length ? byHost : undefined) }]
|
|
329
|
+
})
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
function faviconsOf(value: unknown): string[] | undefined {
|
|
333
|
+
const paths = (Array.isArray(value) ? value : [value]).filter(isSameSitePath)
|
|
334
|
+
return paths.length ? [...new Set(paths)] : undefined
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
function brandOf(value: unknown): RuntimeSurfaceBrand {
|
|
338
|
+
const b = record(value)
|
|
339
|
+
return {
|
|
340
|
+
productName: typeof b.productName === "string" && b.productName ? b.productName : "Nodaro",
|
|
341
|
+
...optional("description", asString(b.description)),
|
|
342
|
+
...optional("wordmark", asString(b.wordmark)),
|
|
343
|
+
...optional("platformLinks", asBoolean(b.platformLinks)),
|
|
344
|
+
...optional("logo", isBrandLogoRef(b.logo) ? b.logo : undefined),
|
|
345
|
+
...optional("favicon", faviconsOf(b.favicon)),
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
/**
|
|
350
|
+
* `surface.strings`, keeping only text: a product, locale or key whose value
|
|
351
|
+
* has the wrong type is left out, and an emptied level with it. Built from
|
|
352
|
+
* entries, so a `"__proto__"` key stays an ordinary key. Never throws.
|
|
353
|
+
*/
|
|
354
|
+
export function parseRuntimeStrings(raw: unknown): RuntimeSurfaceStrings {
|
|
355
|
+
const products: [string, Record<string, Record<string, string>>][] = []
|
|
356
|
+
for (const [product, byLocale] of Object.entries(record(raw))) {
|
|
357
|
+
const locales: [string, Record<string, string>][] = []
|
|
358
|
+
for (const [locale, texts] of Object.entries(record(byLocale))) {
|
|
359
|
+
const kept = Object.entries(record(texts)).filter((e): e is [string, string] => typeof e[1] === "string")
|
|
360
|
+
if (kept.length) locales.push([locale, Object.fromEntries(kept)])
|
|
361
|
+
}
|
|
362
|
+
if (locales.length) products.push([product, Object.fromEntries(locales)])
|
|
363
|
+
}
|
|
364
|
+
return Object.fromEntries(products)
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
function localeOf(value: unknown): RuntimeSurface["locale"] {
|
|
368
|
+
const l = record(value)
|
|
369
|
+
return {
|
|
370
|
+
...optional("default", asString(l.default)),
|
|
371
|
+
picker: l.picker !== false,
|
|
372
|
+
...optional("offered", Array.isArray(l.offered) ? strings(l.offered) : undefined),
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
/** Text words only, built from entries so a `"__proto__"` key stays an ordinary key; nothing usable leaves the key out. */
|
|
377
|
+
function unitLabelsOf(value: unknown): Readonly<Record<string, string>> | undefined {
|
|
378
|
+
const words = Object.entries(record(value)).filter((e): e is [string, string] => typeof e[1] === "string" && e[1].length > 0)
|
|
379
|
+
return words.length ? Object.fromEntries(words) : undefined
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
function billingOf(value: unknown): RuntimeSurfaceBilling {
|
|
383
|
+
const b = record(value)
|
|
384
|
+
// Both or neither: a label without a rate (or the reverse) would put one
|
|
385
|
+
// unit's name on another unit's numbers. The per-language words stand beside
|
|
386
|
+
// the label, so they live and fall with it.
|
|
387
|
+
const coherent = typeof b.unitLabel === "string" && b.unitLabel.length > 0 && typeof b.unitRate === "number" && Number.isFinite(b.unitRate) && b.unitRate > 0
|
|
388
|
+
const decimals = typeof b.unitDecimals === "number" && Number.isInteger(b.unitDecimals) && b.unitDecimals >= 0 && b.unitDecimals <= 4 ? b.unitDecimals : undefined
|
|
389
|
+
return {
|
|
390
|
+
costTab: b.costTab === "hidden" ? "hidden" : "inherit",
|
|
391
|
+
sidebarCard: b.sidebarCard === "hidden" ? "hidden" : "inherit",
|
|
392
|
+
selfServe: b.selfServe !== false,
|
|
393
|
+
...(coherent
|
|
394
|
+
? { unitLabel: b.unitLabel as string, unitRate: b.unitRate as number, ...optional("unitDecimals", decimals), ...optional("unitLabels", unitLabelsOf(b.unitLabels)) }
|
|
395
|
+
: {}),
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
/** A value outside the known set reads as the restrictive one: a reader older than its platform must not show more. */
|
|
400
|
+
function catalogImagesOf(value: unknown): SurfaceCatalogImages {
|
|
401
|
+
if (value === undefined) return "default"
|
|
402
|
+
return (SURFACE_CATALOG_IMAGES as readonly unknown[]).includes(value) ? (value as SurfaceCatalogImages) : "none"
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
function linksAllowed(value: unknown): boolean {
|
|
406
|
+
if (value === undefined) return true
|
|
407
|
+
if (!isRecord(value)) return false
|
|
408
|
+
return value.links === undefined ? true : value.links === true
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
function headerModeOf(value: unknown): SurfaceHeaderMode {
|
|
412
|
+
return value === undefined || value === "default" ? "default" : "white-label"
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
function worldsOf(value: unknown): SurfaceWorlds {
|
|
416
|
+
if (value === undefined) return {}
|
|
417
|
+
// Present but not an object: offer none rather than everything.
|
|
418
|
+
if (!isRecord(value)) return { allow: [] }
|
|
419
|
+
const allow = value.allow === undefined ? undefined : strings(value.allow)
|
|
420
|
+
const order = Array.isArray(value.order) ? [...new Set(value.order.filter(isWorldId))] : []
|
|
421
|
+
const home: WorldId | undefined = isWorldId(value.home) && (allow === undefined || allow.includes(value.home)) ? value.home : undefined
|
|
422
|
+
return { ...optional("allow", allow), ...optional("home", home), ...optional("order", order.length ? order : undefined) }
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
/** The surface block of `/config.js`, every default applied. Never throws. */
|
|
426
|
+
export function parseRuntimeSurface(raw: unknown): RuntimeSurface {
|
|
427
|
+
const s = record(raw)
|
|
428
|
+
const auth = record(s.auth)
|
|
429
|
+
const methods = strings(auth.methods)
|
|
430
|
+
const allowDeny = (v: unknown) => ({ deny: strings(record(v).deny), allow: strings(record(v).allow) })
|
|
431
|
+
const catalogs = record(s.catalogs)
|
|
432
|
+
return {
|
|
433
|
+
nav: { hide: strings(record(s.nav).hide) },
|
|
434
|
+
features: { hide: strings(record(s.features).hide) },
|
|
435
|
+
dashboard: { tabs: strings(record(s.dashboard).tabs) },
|
|
436
|
+
nodes: allowDeny(s.nodes),
|
|
437
|
+
models: allowDeny(s.models),
|
|
438
|
+
auth: { methods, ...optional("ssoLabel", asString(auth.ssoLabel)), requireSignIn: surfaceRequiresSignIn({ methods, requireSignIn: auth.requireSignIn }) },
|
|
439
|
+
siblings: { apps: siblingApps(record(s.siblings).apps) },
|
|
440
|
+
brand: brandOf(s.brand),
|
|
441
|
+
locale: localeOf(s.locale),
|
|
442
|
+
outputs: { allowPublic: record(s.outputs).allowPublic !== false },
|
|
443
|
+
voice: { allowedGenders: strings(record(s.voice).allowedGenders) },
|
|
444
|
+
billing: billingOf(s.billing),
|
|
445
|
+
catalogs: { required: catalogs.required === true, factoryPresets: catalogs.factoryPresets !== false, images: catalogImagesOf(catalogs.images) },
|
|
446
|
+
imports: { links: linksAllowed(s.imports) },
|
|
447
|
+
header: headerModeOf(s.header),
|
|
448
|
+
worlds: worldsOf(s.worlds),
|
|
449
|
+
strings: parseRuntimeStrings(s.strings),
|
|
450
|
+
...optional("catalogPolicy", s.catalogPolicy),
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
function deepFreeze<T>(value: T): T {
|
|
455
|
+
if (typeof value === "object" && value !== null) {
|
|
456
|
+
for (const child of Object.values(value)) deepFreeze(child)
|
|
457
|
+
Object.freeze(value)
|
|
458
|
+
}
|
|
459
|
+
return value
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
/** The surface a deployment that configured none renders. */
|
|
463
|
+
export const RUNTIME_SURFACE_DEFAULT: RuntimeSurface = deepFreeze(parseRuntimeSurface(undefined))
|
|
464
|
+
|
|
465
|
+
const STRING_KEYS = ["apiUrl", "supabaseUrl", "supabaseAnonKey", "freecutUrl", "audiomassUrl", "defaultLocale"] as const
|
|
466
|
+
|
|
467
|
+
/**
|
|
468
|
+
* `/config.js`'s object, typed. Keeps each key only when it has the expected
|
|
469
|
+
* type; a blank string is no value. Never throws.
|
|
470
|
+
*/
|
|
471
|
+
export function parseRuntimeConfig(raw: unknown): NodaroRuntimeConfig {
|
|
472
|
+
if (!isRecord(raw)) return {}
|
|
473
|
+
const out: { -readonly [K in keyof NodaroRuntimeConfig]: NodaroRuntimeConfig[K] } = {}
|
|
474
|
+
for (const key of STRING_KEYS) {
|
|
475
|
+
const value = raw[key]
|
|
476
|
+
if (typeof value === "string" && value.trim()) out[key] = value.trim()
|
|
477
|
+
}
|
|
478
|
+
if (isRecord(raw.surface)) out.surface = parseRuntimeSurface(raw.surface)
|
|
479
|
+
if (isRecord(raw.moderation) && raw.moderation.uploadImage === true) out.moderation = { uploadImage: true }
|
|
480
|
+
if (raw.previewStopRule === true) out.previewStopRule = true
|
|
481
|
+
if (isHttpsOrigin(raw.mediaOrigin)) out.mediaOrigin = raw.mediaOrigin
|
|
482
|
+
return out
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
/** Read and parse the runtime config `/config.js` set on `scope` (default: the global object). */
|
|
486
|
+
export function readRuntimeConfig(scope: unknown = globalThis): NodaroRuntimeConfig {
|
|
487
|
+
try {
|
|
488
|
+
return parseRuntimeConfig(isRecord(scope) || typeof scope === "function" ? (scope as Rec)[RUNTIME_CONFIG_GLOBAL] : undefined)
|
|
489
|
+
} catch {
|
|
490
|
+
return {}
|
|
491
|
+
}
|
|
492
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The worlds a Nodaro deployment can offer — the tabs of the shared site
|
|
3
|
+
* header, in its canonical display order — and the node types each one runs.
|
|
4
|
+
*
|
|
5
|
+
* A world is offered to a viewer when the deployment's profile allows it
|
|
6
|
+
* (`surface.worlds.allow`, when set) AND every node type it runs is available
|
|
7
|
+
* to that viewer. The platform's `GET /v1/surface/availability` answers both
|
|
8
|
+
* per viewer; this table is the one copy that answer and every client read,
|
|
9
|
+
* so a world is never shown where its runs would be refused.
|
|
10
|
+
*
|
|
11
|
+
* Structural vocabulary only (ids and node-type names), no content.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
export const WORLD_IDS = Object.freeze(["explore", "image", "video", "music", "trends", "motion", "voice", "app", "studio"] as const)
|
|
15
|
+
|
|
16
|
+
export type WorldId = (typeof WORLD_IDS)[number]
|
|
17
|
+
|
|
18
|
+
const WORLD_ID_SET: ReadonlySet<string> = new Set(WORLD_IDS)
|
|
19
|
+
|
|
20
|
+
export function isWorldId(value: unknown): value is WorldId {
|
|
21
|
+
return typeof value === "string" && WORLD_ID_SET.has(value)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* The node types each world runs: a world is offered only while every one of
|
|
26
|
+
* them is available to the viewer. A world with none runs no node of its own
|
|
27
|
+
* and is gated by the allowlist alone: Explore is a showcase, App is the
|
|
28
|
+
* workflow editor (whose nodes are gated one by one inside it), Studio is its
|
|
29
|
+
* own product.
|
|
30
|
+
*
|
|
31
|
+
* - `image`: Generate Image (`POST /v1/generate-image`).
|
|
32
|
+
* - `video`: Generate Video and Text to Video — the world's two routes
|
|
33
|
+
* (`/v1/generate-video` from a start frame, `/v1/text-to-video` from a
|
|
34
|
+
* prompt). The canvas's Image to Video node is not one of them.
|
|
35
|
+
* - `music`: Suno Create Music (`/v1/suno/generate`).
|
|
36
|
+
* - `trends`, `motion`: Cast Swap (`/v1/cast-swap`), the run both worlds start.
|
|
37
|
+
* - `voice`: Voice Changer Pro (`/v1/voice-changer-pro`).
|
|
38
|
+
*/
|
|
39
|
+
export const WORLD_REQUIRED_NODE_TYPES: Readonly<Record<WorldId, readonly string[]>> = Object.freeze({
|
|
40
|
+
explore: Object.freeze([]),
|
|
41
|
+
image: Object.freeze(["generate-image"]),
|
|
42
|
+
video: Object.freeze(["generate-video", "text-to-video"]),
|
|
43
|
+
music: Object.freeze(["suno-generate"]),
|
|
44
|
+
trends: Object.freeze(["cast-swap"]),
|
|
45
|
+
motion: Object.freeze(["cast-swap"]),
|
|
46
|
+
voice: Object.freeze(["voice-changer-pro"]),
|
|
47
|
+
app: Object.freeze([]),
|
|
48
|
+
studio: Object.freeze([]),
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
/** The worlds part of a deployment's surface profile. */
|
|
52
|
+
export interface SurfaceWorlds {
|
|
53
|
+
/**
|
|
54
|
+
* When PRESENT, exactly these worlds are offered (`[]` offers none). Absent:
|
|
55
|
+
* every world is, subject to its node types. Unlike the profile's other
|
|
56
|
+
* lists, presence is what narrows, so a list whose ids are all unknown
|
|
57
|
+
* offers nothing instead of everything.
|
|
58
|
+
*/
|
|
59
|
+
readonly allow?: readonly string[]
|
|
60
|
+
/** The world a visit to the site's root lands on. Always one `allow` lets through. */
|
|
61
|
+
readonly home?: WorldId
|
|
62
|
+
/** Display order; worlds it leaves out follow in canonical order. */
|
|
63
|
+
readonly order?: readonly WorldId[]
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** Does the profile's allowlist let this world through? (Node availability is checked separately.) */
|
|
67
|
+
export function worldAllowed(worlds: SurfaceWorlds | undefined, id: string): boolean {
|
|
68
|
+
return worlds?.allow === undefined || worlds.allow.includes(id)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** Every world, `order`'s known ids first (each once), then the rest in canonical order. */
|
|
72
|
+
export function orderWorlds(order?: readonly string[]): WorldId[] {
|
|
73
|
+
const out: WorldId[] = []
|
|
74
|
+
for (const id of order ?? []) if (isWorldId(id) && !out.includes(id)) out.push(id)
|
|
75
|
+
for (const id of WORLD_IDS) if (!out.includes(id)) out.push(id)
|
|
76
|
+
return out
|
|
77
|
+
}
|